(
agentUrl: string,
apiKey?: string,
options: { signal?: AbortSignal } = {}
)
| 192 | * request is cancelled. |
| 193 | */ |
| 194 | export async function createA2AClient( |
| 195 | agentUrl: string, |
| 196 | apiKey?: string, |
| 197 | options: { signal?: AbortSignal } = {} |
| 198 | ): Promise<Client> { |
| 199 | const validation = await validateUrlWithDNS(agentUrl, 'agentUrl') |
| 200 | if (!validation.isValid || !validation.resolvedIP) { |
| 201 | throw new Error(validation.error || 'Agent URL validation failed') |
| 202 | } |
| 203 | const { resolvedIP } = validation |
| 204 | |
| 205 | const card = await resolveAgentCard(agentUrl, resolvedIP, options.signal) |
| 206 | |
| 207 | const pinnedFetch = createPinnedFetch(resolvedIP, { |
| 208 | timeout: RPC_TIMEOUT_MS, |
| 209 | signal: options.signal, |
| 210 | }) |
| 211 | const factory = new ClientFactory( |
| 212 | ClientFactoryOptions.createFrom(ClientFactoryOptions.default, { |
| 213 | transports: [ |
| 214 | new JsonRpcTransportFactory({ fetchImpl: pinnedFetch }), |
| 215 | new RestTransportFactory({ fetchImpl: pinnedFetch }), |
| 216 | ], |
| 217 | ...(apiKey ? { clientConfig: { interceptors: [new ApiKeyInterceptor(apiKey)] } } : {}), |
| 218 | }) |
| 219 | ) |
| 220 | |
| 221 | return factory.createFromAgentCard(card) |
| 222 | } |
| 223 | |
| 224 | /** A file to attach to an outgoing message, resolved to raw bytes from Sim storage. */ |
| 225 | export interface A2AFileInput { |
no test coverage detected