fix(a2a): simplify card resolution and fix redundant fetching

This commit is contained in:
Alisa Novikova
2026-03-11 09:13:46 -07:00
parent ec8bf97e69
commit 54b8c2843b
2 changed files with 12 additions and 3 deletions

View File

@@ -60,8 +60,8 @@ describe('A2AClientManager', () => {
beforeEach(() => {
vi.clearAllMocks();
A2AClientManager.resetInstanceForTesting();
manager = A2AClientManager.getInstance();
manager.clearCache();
// Re-create the instances as plain objects that can be spied on
const factoryInstance = {

View File

@@ -72,10 +72,19 @@ export class A2AClientManager {
return A2AClientManager.instance;
}
/**
* Resets the singleton instance. Only for testing purposes.
* @internal
*/
static resetInstanceForTesting() {
// @ts-expect-error - Resetting singleton for testing
A2AClientManager.instance = undefined;
}
/**
* Loads an agent by fetching its AgentCard and caches the client.
* @param name The name to assign to the agent.
* @param agentCardUrl {string} The full URL to the agent's card.
* @param agentCardUrl The full URL to the agent's card.
* @param authHandler Optional authentication handler to use for this agent.
* @returns The loaded AgentCard.
*/
@@ -185,7 +194,7 @@ export class A2AClientManager {
try {
yield* client.sendMessageStream(messageParams, {
signal: options?.signal,
}) as AsyncIterable<SendMessageResult>;
});
} catch (error: unknown) {
const prefix = `[A2AClientManager] sendMessageStream Error [${agentName}]`;
if (error instanceof Error) {