feat(agents): add support for remote agents (#16013)

This commit is contained in:
Adam Weidman
2026-01-06 18:45:05 -05:00
committed by GitHub
parent 1e31427da8
commit 96b9be3ec4
8 changed files with 980 additions and 41 deletions
@@ -8,6 +8,7 @@ import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest';
import {
A2AClientManager,
type SendMessageResult,
createAdapterFetch,
} from './a2a-client-manager.js';
import type { AgentCard, Task } from '@a2a-js/sdk';
import type { AuthenticationHandler, Client } from '@a2a-js/sdk/client';
@@ -302,4 +303,42 @@ describe('A2AClientManager', () => {
).rejects.toThrow("Agent 'NonExistentAgent' not found.");
});
});
describe('createAdapterFetch', () => {
it('normalizes TASK_STATE_ enums to lower-case', async () => {
const baseFetch = vi
.fn()
.mockResolvedValue(
new Response(
JSON.stringify({ status: { state: 'TASK_STATE_WORKING' } }),
),
);
const adapter = createAdapterFetch(baseFetch as typeof fetch);
const response = await adapter('http://example.com', {
method: 'POST',
body: '{}',
});
const data = await response.json();
expect(data.status.state).toBe('working');
});
it('lowercases non-prefixed task states', async () => {
const baseFetch = vi
.fn()
.mockResolvedValue(
new Response(JSON.stringify({ status: { state: 'WORKING' } })),
);
const adapter = createAdapterFetch(baseFetch as typeof fetch);
const response = await adapter('http://example.com', {
method: 'POST',
body: '{}',
});
const data = await response.json();
expect(data.status.state).toBe('working');
});
});
});