@a2a-js/sdk 0.2.2 → 0.2.3

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.
Files changed (48) hide show
  1. package/README.md +106 -89
  2. package/package.json +25 -7
  3. package/build/src/a2a_response.d.ts +0 -5
  4. package/build/src/a2a_response.js +0 -2
  5. package/build/src/client/client.d.ts +0 -118
  6. package/build/src/client/client.js +0 -409
  7. package/build/src/index.d.ts +0 -21
  8. package/build/src/index.js +0 -18
  9. package/build/src/samples/agents/movie-agent/genkit.d.ts +0 -2
  10. package/build/src/samples/agents/movie-agent/genkit.js +0 -11
  11. package/build/src/samples/agents/movie-agent/index.d.ts +0 -1
  12. package/build/src/samples/agents/movie-agent/index.js +0 -252
  13. package/build/src/samples/agents/movie-agent/tmdb.d.ts +0 -7
  14. package/build/src/samples/agents/movie-agent/tmdb.js +0 -32
  15. package/build/src/samples/agents/movie-agent/tools.d.ts +0 -15
  16. package/build/src/samples/agents/movie-agent/tools.js +0 -74
  17. package/build/src/samples/cli.d.ts +0 -2
  18. package/build/src/samples/cli.js +0 -289
  19. package/build/src/server/a2a_express_app.d.ts +0 -14
  20. package/build/src/server/a2a_express_app.js +0 -98
  21. package/build/src/server/agent_execution/agent_executor.d.ts +0 -18
  22. package/build/src/server/agent_execution/agent_executor.js +0 -2
  23. package/build/src/server/agent_execution/request_context.d.ts +0 -9
  24. package/build/src/server/agent_execution/request_context.js +0 -15
  25. package/build/src/server/error.d.ts +0 -23
  26. package/build/src/server/error.js +0 -57
  27. package/build/src/server/events/execution_event_bus.d.ts +0 -16
  28. package/build/src/server/events/execution_event_bus.js +0 -13
  29. package/build/src/server/events/execution_event_bus_manager.d.ts +0 -27
  30. package/build/src/server/events/execution_event_bus_manager.js +0 -36
  31. package/build/src/server/events/execution_event_queue.d.ts +0 -24
  32. package/build/src/server/events/execution_event_queue.js +0 -63
  33. package/build/src/server/request_handler/a2a_request_handler.d.ts +0 -11
  34. package/build/src/server/request_handler/a2a_request_handler.js +0 -2
  35. package/build/src/server/request_handler/default_request_handler.d.ts +0 -23
  36. package/build/src/server/request_handler/default_request_handler.js +0 -340
  37. package/build/src/server/result_manager.d.ts +0 -29
  38. package/build/src/server/result_manager.js +0 -149
  39. package/build/src/server/store.d.ts +0 -25
  40. package/build/src/server/store.js +0 -17
  41. package/build/src/server/transports/jsonrpc_transport_handler.d.ts +0 -15
  42. package/build/src/server/transports/jsonrpc_transport_handler.js +0 -114
  43. package/build/src/server/utils.d.ts +0 -22
  44. package/build/src/server/utils.js +0 -34
  45. package/build/src/types-old.d.ts +0 -832
  46. package/build/src/types-old.js +0 -20
  47. package/build/src/types.d.ts +0 -2046
  48. package/build/src/types.js +0 -8
@@ -1,114 +0,0 @@
1
- import { A2AError } from "../error.js";
2
- /**
3
- * Handles JSON-RPC transport layer, routing requests to A2ARequestHandler.
4
- */
5
- export class JsonRpcTransportHandler {
6
- requestHandler;
7
- constructor(requestHandler) {
8
- this.requestHandler = requestHandler;
9
- }
10
- /**
11
- * Handles an incoming JSON-RPC request.
12
- * For streaming methods, it returns an AsyncGenerator of JSONRPCResult.
13
- * For non-streaming methods, it returns a Promise of a single JSONRPCMessage (Result or ErrorResponse).
14
- */
15
- async handle(requestBody) {
16
- let rpcRequest;
17
- try {
18
- if (typeof requestBody === 'string') {
19
- rpcRequest = JSON.parse(requestBody);
20
- }
21
- else if (typeof requestBody === 'object' && requestBody !== null) {
22
- rpcRequest = requestBody;
23
- }
24
- else {
25
- throw A2AError.parseError('Invalid request body type.');
26
- }
27
- if (rpcRequest.jsonrpc !== '2.0' ||
28
- !rpcRequest.method ||
29
- typeof rpcRequest.method !== 'string') {
30
- throw A2AError.invalidRequest('Invalid JSON-RPC request structure.');
31
- }
32
- }
33
- catch (error) {
34
- const a2aError = error instanceof A2AError ? error : A2AError.parseError(error.message || 'Failed to parse JSON request.');
35
- return {
36
- jsonrpc: '2.0',
37
- id: (typeof rpcRequest?.id !== 'undefined' ? rpcRequest.id : null),
38
- error: a2aError.toJSONRPCError(),
39
- };
40
- }
41
- const { method, params = {}, id: requestId = null } = rpcRequest;
42
- try {
43
- if (method === 'message/stream' || method === 'tasks/resubscribe') {
44
- const agentCard = await this.requestHandler.getAgentCard();
45
- if (!agentCard.capabilities.streaming) {
46
- throw A2AError.unsupportedOperation(`Method ${method} requires streaming capability.`);
47
- }
48
- const agentEventStream = method === 'message/stream'
49
- ? this.requestHandler.sendMessageStream(params)
50
- : this.requestHandler.resubscribe(params);
51
- // Wrap the agent event stream into a JSON-RPC result stream
52
- return (async function* jsonRpcEventStream() {
53
- try {
54
- for await (const event of agentEventStream) {
55
- yield {
56
- jsonrpc: '2.0',
57
- id: requestId, // Use the original request ID for all streamed responses
58
- result: event,
59
- };
60
- }
61
- }
62
- catch (streamError) {
63
- // If the underlying agent stream throws an error, we need to yield a JSONRPCErrorResponse.
64
- // However, an AsyncGenerator is expected to yield JSONRPCResult.
65
- // This indicates an issue with how errors from the agent's stream are propagated.
66
- // For now, log it. The Express layer will handle the generator ending.
67
- console.error(`Error in agent event stream for ${method} (request ${requestId}):`, streamError);
68
- // Ideally, the Express layer should catch this and send a final error to the client if the stream breaks.
69
- // Or, the agentEventStream itself should yield a final error event that gets wrapped.
70
- // For now, we re-throw so it can be caught by A2AExpressApp's stream handling.
71
- throw streamError;
72
- }
73
- })();
74
- }
75
- else {
76
- // Handle non-streaming methods
77
- let result;
78
- switch (method) {
79
- case 'message/send':
80
- result = await this.requestHandler.sendMessage(params);
81
- break;
82
- case 'tasks/get':
83
- result = await this.requestHandler.getTask(params);
84
- break;
85
- case 'tasks/cancel':
86
- result = await this.requestHandler.cancelTask(params);
87
- break;
88
- case 'tasks/pushNotificationConfig/set':
89
- result = await this.requestHandler.setTaskPushNotificationConfig(params);
90
- break;
91
- case 'tasks/pushNotificationConfig/get':
92
- result = await this.requestHandler.getTaskPushNotificationConfig(params);
93
- break;
94
- default:
95
- throw A2AError.methodNotFound(method);
96
- }
97
- return {
98
- jsonrpc: '2.0',
99
- id: requestId,
100
- result: result,
101
- };
102
- }
103
- }
104
- catch (error) {
105
- const a2aError = error instanceof A2AError ? error : A2AError.internalError(error.message || 'An unexpected error occurred.');
106
- return {
107
- jsonrpc: '2.0',
108
- id: requestId,
109
- error: a2aError.toJSONRPCError(),
110
- };
111
- }
112
- }
113
- }
114
- //# sourceMappingURL=jsonrpc_transport_handler.js.map
@@ -1,22 +0,0 @@
1
- import { TaskStatus, Artifact } from "../types.js";
2
- /**
3
- * Generates a timestamp in ISO 8601 format.
4
- * @returns The current timestamp as a string.
5
- */
6
- export declare function getCurrentTimestamp(): string;
7
- /**
8
- * Checks if a value is a plain object (excluding arrays and null).
9
- * @param value The value to check.
10
- * @returns True if the value is a plain object, false otherwise.
11
- */
12
- export declare function isObject(value: unknown): value is Record<string, any>;
13
- /**
14
- * Type guard to check if an object is a TaskStatus update (lacks 'parts').
15
- * Used to differentiate yielded updates from the handler.
16
- */
17
- export declare function isTaskStatusUpdate(update: any): update is Omit<TaskStatus, "timestamp">;
18
- /**
19
- * Type guard to check if an object is an Artifact update (has 'parts').
20
- * Used to differentiate yielded updates from the handler.
21
- */
22
- export declare function isArtifactUpdate(update: any): update is Artifact;
@@ -1,34 +0,0 @@
1
- /**
2
- * Generates a timestamp in ISO 8601 format.
3
- * @returns The current timestamp as a string.
4
- */
5
- export function getCurrentTimestamp() {
6
- return new Date().toISOString();
7
- }
8
- /**
9
- * Checks if a value is a plain object (excluding arrays and null).
10
- * @param value The value to check.
11
- * @returns True if the value is a plain object, false otherwise.
12
- */
13
- export function isObject(value) {
14
- return typeof value === "object" && value !== null && !Array.isArray(value);
15
- }
16
- /**
17
- * Type guard to check if an object is a TaskStatus update (lacks 'parts').
18
- * Used to differentiate yielded updates from the handler.
19
- */
20
- export function isTaskStatusUpdate(update // eslint-disable-line @typescript-eslint/no-explicit-any
21
- ) {
22
- // Check if it has 'state' and NOT 'parts' (which Artifacts have)
23
- return isObject(update) && "state" in update && !("parts" in update);
24
- }
25
- /**
26
- * Type guard to check if an object is an Artifact update (has 'parts').
27
- * Used to differentiate yielded updates from the handler.
28
- */
29
- export function isArtifactUpdate(update // eslint-disable-line @typescript-eslint/no-explicit-any
30
- ) {
31
- // Check if it has 'parts'
32
- return isObject(update) && "parts" in update;
33
- }
34
- //# sourceMappingURL=utils.js.map