@a2a-js/sdk 0.3.10 → 0.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{a2a_request_handler-BuP9LgXH.d.ts → a2a_request_handler-BiphzMH4.d.cts} +2 -2
- package/dist/{a2a_request_handler-B3LxMq3P.d.cts → a2a_request_handler-C9bZITjN.d.ts} +2 -2
- package/dist/{chunk-U3QAVT4H.js → chunk-2TNRJNPO.js} +694 -694
- package/dist/client/index.cjs +1327 -1288
- package/dist/client/index.d.cts +7 -3
- package/dist/client/index.d.ts +7 -3
- package/dist/client/index.js +79 -40
- package/dist/client/transports/grpc/index.d.cts +2 -2
- package/dist/client/transports/grpc/index.d.ts +2 -2
- package/dist/client/transports/grpc/index.js +1 -1
- package/dist/{core-BAzQJfA2.d.ts → core-BHroNzI0.d.cts} +2 -2
- package/dist/{core-Ci-lR0jz.d.cts → core-NwQicv77.d.ts} +2 -2
- package/dist/{extensions-DvruCIzw.d.cts → extensions-APfrw8gz.d.cts} +1 -1
- package/dist/{extensions-DvruCIzw.d.ts → extensions-APfrw8gz.d.ts} +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/server/express/index.cjs +24 -113
- package/dist/server/express/index.d.cts +2 -2
- package/dist/server/express/index.d.ts +2 -2
- package/dist/server/express/index.js +25 -114
- package/dist/server/grpc/index.d.cts +2 -2
- package/dist/server/grpc/index.d.ts +2 -2
- package/dist/server/grpc/index.js +1 -1
- package/dist/server/index.cjs +0 -1
- package/dist/server/index.d.cts +3 -4
- package/dist/server/index.d.ts +3 -4
- package/dist/server/index.js +0 -1
- package/package.json +5 -3
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
Task,
|
|
31
31
|
TaskPushNotificationConfig,
|
|
32
32
|
ToProto
|
|
33
|
-
} from "../../chunk-
|
|
33
|
+
} from "../../chunk-2TNRJNPO.js";
|
|
34
34
|
import {
|
|
35
35
|
A2AError
|
|
36
36
|
} from "../../chunk-UHZEIZLS.js";
|
|
@@ -245,23 +245,32 @@ var RestTransportHandler = class _RestTransportHandler {
|
|
|
245
245
|
async getAuthenticatedExtendedAgentCard(context) {
|
|
246
246
|
return this.requestHandler.getAuthenticatedExtendedAgentCard(context);
|
|
247
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Validate MessageSendParams.
|
|
250
|
+
*/
|
|
251
|
+
validateMessageSendParams(params) {
|
|
252
|
+
if (!params.message) {
|
|
253
|
+
throw A2AError.invalidParams("message is required");
|
|
254
|
+
}
|
|
255
|
+
if (!params.message.messageId) {
|
|
256
|
+
throw A2AError.invalidParams("message.messageId is required");
|
|
257
|
+
}
|
|
258
|
+
}
|
|
248
259
|
/**
|
|
249
260
|
* Sends a message to the agent.
|
|
250
|
-
* Accepts both snake_case and camelCase input, returns camelCase.
|
|
251
261
|
*/
|
|
252
262
|
async sendMessage(params, context) {
|
|
253
|
-
|
|
254
|
-
return this.requestHandler.sendMessage(
|
|
263
|
+
this.validateMessageSendParams(params);
|
|
264
|
+
return this.requestHandler.sendMessage(params, context);
|
|
255
265
|
}
|
|
256
266
|
/**
|
|
257
267
|
* Sends a message with streaming response.
|
|
258
|
-
* Accepts both snake_case and camelCase input, returns camelCase stream.
|
|
259
268
|
* @throws {A2AError} UnsupportedOperation if streaming not supported
|
|
260
269
|
*/
|
|
261
270
|
async sendMessageStream(params, context) {
|
|
262
271
|
await this.requireCapability("streaming");
|
|
263
|
-
|
|
264
|
-
return this.requestHandler.sendMessageStream(
|
|
272
|
+
this.validateMessageSendParams(params);
|
|
273
|
+
return this.requestHandler.sendMessageStream(params, context);
|
|
265
274
|
}
|
|
266
275
|
/**
|
|
267
276
|
* Gets a task by ID.
|
|
@@ -293,13 +302,17 @@ var RestTransportHandler = class _RestTransportHandler {
|
|
|
293
302
|
}
|
|
294
303
|
/**
|
|
295
304
|
* Sets a push notification configuration.
|
|
296
|
-
* Accepts both snake_case and camelCase input, returns camelCase.
|
|
297
305
|
* @throws {A2AError} PushNotificationNotSupported if push notifications not supported
|
|
298
306
|
*/
|
|
299
307
|
async setTaskPushNotificationConfig(config, context) {
|
|
300
308
|
await this.requireCapability("pushNotifications");
|
|
301
|
-
|
|
302
|
-
|
|
309
|
+
if (!config.taskId) {
|
|
310
|
+
throw A2AError.invalidParams("taskId is required");
|
|
311
|
+
}
|
|
312
|
+
if (!config.pushNotificationConfig) {
|
|
313
|
+
throw A2AError.invalidParams("pushNotificationConfig is required");
|
|
314
|
+
}
|
|
315
|
+
return this.requestHandler.setTaskPushNotificationConfig(config, context);
|
|
303
316
|
}
|
|
304
317
|
/**
|
|
305
318
|
* Lists all push notification configurations for a task.
|
|
@@ -325,28 +338,6 @@ var RestTransportHandler = class _RestTransportHandler {
|
|
|
325
338
|
context
|
|
326
339
|
);
|
|
327
340
|
}
|
|
328
|
-
// ==========================================================================
|
|
329
|
-
// Private Transformation Methods
|
|
330
|
-
// ==========================================================================
|
|
331
|
-
// All type conversion between REST (snake_case) and internal (camelCase) formats
|
|
332
|
-
/**
|
|
333
|
-
* Validates and normalizes message parameters.
|
|
334
|
-
* Accepts both snake_case and camelCase input.
|
|
335
|
-
* @throws {A2AError} InvalidParams if message is missing or conversion fails
|
|
336
|
-
*/
|
|
337
|
-
normalizeMessageParams(input) {
|
|
338
|
-
if (!input.message) {
|
|
339
|
-
throw A2AError.invalidParams("message is required");
|
|
340
|
-
}
|
|
341
|
-
try {
|
|
342
|
-
return this.normalizeMessageSendParams(input);
|
|
343
|
-
} catch (error) {
|
|
344
|
-
if (error instanceof A2AError) throw error;
|
|
345
|
-
throw A2AError.invalidParams(
|
|
346
|
-
error instanceof Error ? error.message : "Invalid message parameters"
|
|
347
|
-
);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
341
|
/**
|
|
351
342
|
* Static map of capability to error for missing capabilities.
|
|
352
343
|
*/
|
|
@@ -380,86 +371,6 @@ var RestTransportHandler = class _RestTransportHandler {
|
|
|
380
371
|
}
|
|
381
372
|
return parsed;
|
|
382
373
|
}
|
|
383
|
-
/**
|
|
384
|
-
* Normalizes Part input - accepts both snake_case and camelCase for file mimeType.
|
|
385
|
-
*/
|
|
386
|
-
normalizePart(part) {
|
|
387
|
-
if (part.kind === "text") return { kind: "text", text: part.text };
|
|
388
|
-
if (part.kind === "file") {
|
|
389
|
-
const file = this.normalizeFile(part.file);
|
|
390
|
-
return { kind: "file", file, metadata: part.metadata };
|
|
391
|
-
}
|
|
392
|
-
return { kind: "data", data: part.data, metadata: part.metadata };
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Normalizes File input - accepts both snake_case (mime_type) and camelCase (mimeType).
|
|
396
|
-
*/
|
|
397
|
-
normalizeFile(f) {
|
|
398
|
-
const file = f;
|
|
399
|
-
const mimeType = file.mimeType ?? file.mime_type;
|
|
400
|
-
if ("bytes" in file) {
|
|
401
|
-
return { bytes: file.bytes, mimeType, name: file.name };
|
|
402
|
-
}
|
|
403
|
-
return { uri: file.uri, mimeType, name: file.name };
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Normalizes Message input - accepts both snake_case and camelCase.
|
|
407
|
-
*/
|
|
408
|
-
normalizeMessage(input) {
|
|
409
|
-
const m = input;
|
|
410
|
-
const messageId = m.messageId ?? m.message_id;
|
|
411
|
-
if (!messageId) {
|
|
412
|
-
throw A2AError.invalidParams("message.messageId is required");
|
|
413
|
-
}
|
|
414
|
-
if (!m.parts || !Array.isArray(m.parts)) {
|
|
415
|
-
throw A2AError.invalidParams("message.parts must be an array");
|
|
416
|
-
}
|
|
417
|
-
return {
|
|
418
|
-
contextId: m.contextId ?? m.context_id,
|
|
419
|
-
extensions: m.extensions,
|
|
420
|
-
kind: "message",
|
|
421
|
-
messageId,
|
|
422
|
-
metadata: m.metadata,
|
|
423
|
-
parts: m.parts.map((p) => this.normalizePart(p)),
|
|
424
|
-
referenceTaskIds: m.referenceTaskIds ?? m.reference_task_ids,
|
|
425
|
-
role: m.role,
|
|
426
|
-
taskId: m.taskId ?? m.task_id
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* Normalizes MessageSendParams - accepts both snake_case and camelCase.
|
|
431
|
-
*/
|
|
432
|
-
normalizeMessageSendParams(input) {
|
|
433
|
-
const p = input;
|
|
434
|
-
const config = p.configuration;
|
|
435
|
-
return {
|
|
436
|
-
configuration: config ? {
|
|
437
|
-
acceptedOutputModes: config.acceptedOutputModes ?? config.accepted_output_modes,
|
|
438
|
-
blocking: config.blocking,
|
|
439
|
-
historyLength: config.historyLength ?? config.history_length
|
|
440
|
-
} : void 0,
|
|
441
|
-
message: this.normalizeMessage(p.message),
|
|
442
|
-
metadata: p.metadata
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* Normalizes TaskPushNotificationConfig - accepts both snake_case and camelCase.
|
|
447
|
-
*/
|
|
448
|
-
normalizeTaskPushNotificationConfig(input) {
|
|
449
|
-
const c = input;
|
|
450
|
-
const taskId = c.taskId ?? c.task_id;
|
|
451
|
-
if (!taskId) {
|
|
452
|
-
throw A2AError.invalidParams("taskId is required");
|
|
453
|
-
}
|
|
454
|
-
const pnConfig = c.pushNotificationConfig ?? c.push_notification_config;
|
|
455
|
-
if (!pnConfig) {
|
|
456
|
-
throw A2AError.invalidParams("pushNotificationConfig is required");
|
|
457
|
-
}
|
|
458
|
-
return {
|
|
459
|
-
pushNotificationConfig: pnConfig,
|
|
460
|
-
taskId
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
374
|
};
|
|
464
375
|
|
|
465
376
|
// src/server/express/rest_handler.ts
|
|
@@ -492,8 +403,8 @@ function restHandler(options) {
|
|
|
492
403
|
if (statusCode === HTTP_STATUS.NO_CONTENT) {
|
|
493
404
|
res.end();
|
|
494
405
|
} else {
|
|
495
|
-
if (!responseType) {
|
|
496
|
-
throw new Error("Bug: toJson serializer must be provided for non-204 responses.");
|
|
406
|
+
if (!responseType || body === void 0) {
|
|
407
|
+
throw new Error("Bug: toJson serializer and body must be provided for non-204 responses.");
|
|
497
408
|
}
|
|
498
409
|
res.json(responseType.toJSON(body));
|
|
499
410
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
|
|
2
2
|
import * as grpc from '@grpc/grpc-js';
|
|
3
3
|
import { UntypedServiceImplementation, handleUnaryCall, handleServerStreamingCall } from '@grpc/grpc-js';
|
|
4
|
-
import {
|
|
5
|
-
import '../../extensions-
|
|
4
|
+
import { a as User, U as UnauthenticatedUser, A as A2ARequestHandler } from '../../a2a_request_handler-BiphzMH4.cjs';
|
|
5
|
+
import '../../extensions-APfrw8gz.cjs';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A generic empty message that you can re-use to avoid defining duplicated
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
|
|
2
2
|
import * as grpc from '@grpc/grpc-js';
|
|
3
3
|
import { UntypedServiceImplementation, handleUnaryCall, handleServerStreamingCall } from '@grpc/grpc-js';
|
|
4
|
-
import {
|
|
5
|
-
import '../../extensions-
|
|
4
|
+
import { a as User, U as UnauthenticatedUser, A as A2ARequestHandler } from '../../a2a_request_handler-C9bZITjN.js';
|
|
5
|
+
import '../../extensions-APfrw8gz.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A generic empty message that you can re-use to avoid defining duplicated
|
package/dist/server/index.cjs
CHANGED
package/dist/server/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { S as ServerCallContext, A as A2ARequestHandler } from '../a2a_request_handler-
|
|
3
|
-
export {
|
|
1
|
+
import { ae as Message, aL as Task, b3 as TaskStatusUpdateEvent, aO as TaskArtifactUpdateEvent, az as PushNotificationConfig, i as AgentCard, aj as MessageSendParams, aY as TaskQueryParams, aP as TaskIdParams, aU as TaskPushNotificationConfig, U as GetTaskPushNotificationConfigParams, aa as ListTaskPushNotificationConfigParams, E as DeleteTaskPushNotificationConfigParams, a8 as JSONRPCResponse, a5 as JSONRPCError } from '../extensions-APfrw8gz.cjs';
|
|
2
|
+
import { S as ServerCallContext, A as A2ARequestHandler } from '../a2a_request_handler-BiphzMH4.cjs';
|
|
3
|
+
export { U as UnauthenticatedUser, a as User } from '../a2a_request_handler-BiphzMH4.cjs';
|
|
4
4
|
|
|
5
5
|
type AgentExecutionEvent = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
|
|
6
6
|
/**
|
|
@@ -141,7 +141,6 @@ declare class ExecutionEventQueue {
|
|
|
141
141
|
private eventQueue;
|
|
142
142
|
private resolvePromise?;
|
|
143
143
|
private stopped;
|
|
144
|
-
private boundHandleEvent;
|
|
145
144
|
constructor(eventBus: ExecutionEventBus);
|
|
146
145
|
private handleEvent;
|
|
147
146
|
private handleFinished;
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { S as ServerCallContext, A as A2ARequestHandler } from '../a2a_request_handler-
|
|
3
|
-
export {
|
|
1
|
+
import { ae as Message, aL as Task, b3 as TaskStatusUpdateEvent, aO as TaskArtifactUpdateEvent, az as PushNotificationConfig, i as AgentCard, aj as MessageSendParams, aY as TaskQueryParams, aP as TaskIdParams, aU as TaskPushNotificationConfig, U as GetTaskPushNotificationConfigParams, aa as ListTaskPushNotificationConfigParams, E as DeleteTaskPushNotificationConfigParams, a8 as JSONRPCResponse, a5 as JSONRPCError } from '../extensions-APfrw8gz.js';
|
|
2
|
+
import { S as ServerCallContext, A as A2ARequestHandler } from '../a2a_request_handler-C9bZITjN.js';
|
|
3
|
+
export { U as UnauthenticatedUser, a as User } from '../a2a_request_handler-C9bZITjN.js';
|
|
4
4
|
|
|
5
5
|
type AgentExecutionEvent = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
|
|
6
6
|
/**
|
|
@@ -141,7 +141,6 @@ declare class ExecutionEventQueue {
|
|
|
141
141
|
private eventQueue;
|
|
142
142
|
private resolvePromise?;
|
|
143
143
|
private stopped;
|
|
144
|
-
private boundHandleEvent;
|
|
145
144
|
constructor(eventBus: ExecutionEventBus);
|
|
146
145
|
private handleEvent;
|
|
147
146
|
private handleFinished;
|
package/dist/server/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@a2a-js/sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.12",
|
|
4
4
|
"description": "Server & Client SDK for Agent2Agent protocol",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -70,6 +70,8 @@
|
|
|
70
70
|
"README.md"
|
|
71
71
|
],
|
|
72
72
|
"devDependencies": {
|
|
73
|
+
"@betterer/cli": "^6.0.0-alpha.1",
|
|
74
|
+
"@betterer/typescript": "^6.0.0-alpha.1",
|
|
73
75
|
"@bufbuild/buf": "^1.61.0",
|
|
74
76
|
"@bufbuild/protobuf": "^2.10.2",
|
|
75
77
|
"@cloudflare/vitest-pool-workers": "^0.12.5",
|
|
@@ -97,9 +99,9 @@
|
|
|
97
99
|
"build": "tsup",
|
|
98
100
|
"test": "vitest run",
|
|
99
101
|
"test:edge": "vitest run --config vitest.edge.config.ts",
|
|
100
|
-
"lint": "tsc --noEmit && npx eslint .",
|
|
102
|
+
"lint": "tsc --noEmit && npx eslint . --fix && betterer precommit",
|
|
103
|
+
"lint:ci": "tsc --noEmit && npx eslint . && betterer ci",
|
|
101
104
|
"format:readme": "prettier --write ./README.md",
|
|
102
|
-
"lint:fix": "npx eslint . --fix",
|
|
103
105
|
"coverage": "vitest run --coverage",
|
|
104
106
|
"generate": "curl https://raw.githubusercontent.com/google-a2a/A2A/refs/heads/main/specification/json/a2a.json > spec.json && node scripts/generateTypes.js && rm spec.json",
|
|
105
107
|
"test-build": "esbuild ./dist/client/index.js ./dist/server/index.js ./dist/index.js --bundle --platform=neutral --outdir=dist/tmp-checks --outbase=./dist"
|