@a2a-js/sdk 0.3.0 → 0.3.2
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/README.md +2 -1
- package/dist/a2a_request_handler-B5t-IxgA.d.ts +17 -0
- package/dist/a2a_request_handler-DUvKWfix.d.cts +17 -0
- package/dist/chunk-67JNQ6TZ.js +6 -0
- package/dist/chunk-JA52GYRU.js +207 -0
- package/dist/client/index.cjs +90 -40
- package/dist/client/index.d.cts +88 -8
- package/dist/client/index.d.ts +88 -8
- package/dist/client/index.js +89 -39
- package/dist/index.cjs +14 -0
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +6 -0
- package/dist/server/express/index.cjs +342 -0
- package/dist/server/express/index.d.cts +20 -0
- package/dist/server/express/index.d.ts +20 -0
- package/dist/server/express/index.js +106 -0
- package/dist/server/index.d.cts +2 -15
- package/dist/server/index.d.ts +2 -15
- package/dist/server/index.js +5 -203
- package/package.json +5 -2
package/dist/server/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
A2AError,
|
|
3
|
+
JsonRpcTransportHandler
|
|
4
|
+
} from "../chunk-JA52GYRU.js";
|
|
5
|
+
|
|
1
6
|
// src/server/agent_execution/request_context.ts
|
|
2
7
|
var RequestContext = class {
|
|
3
8
|
userMessage;
|
|
@@ -124,87 +129,6 @@ var ExecutionEventQueue = class {
|
|
|
124
129
|
// src/server/request_handler/default_request_handler.ts
|
|
125
130
|
import { v4 as uuidv4 } from "uuid";
|
|
126
131
|
|
|
127
|
-
// src/server/error.ts
|
|
128
|
-
var A2AError = class _A2AError extends Error {
|
|
129
|
-
code;
|
|
130
|
-
data;
|
|
131
|
-
taskId;
|
|
132
|
-
// Optional task ID context
|
|
133
|
-
constructor(code, message, data, taskId) {
|
|
134
|
-
super(message);
|
|
135
|
-
this.name = "A2AError";
|
|
136
|
-
this.code = code;
|
|
137
|
-
this.data = data;
|
|
138
|
-
this.taskId = taskId;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Formats the error into a standard JSON-RPC error object structure.
|
|
142
|
-
*/
|
|
143
|
-
toJSONRPCError() {
|
|
144
|
-
const errorObject = {
|
|
145
|
-
code: this.code,
|
|
146
|
-
message: this.message
|
|
147
|
-
};
|
|
148
|
-
if (this.data !== void 0) {
|
|
149
|
-
errorObject.data = this.data;
|
|
150
|
-
}
|
|
151
|
-
return errorObject;
|
|
152
|
-
}
|
|
153
|
-
// Static factory methods for common errors
|
|
154
|
-
static parseError(message, data) {
|
|
155
|
-
return new _A2AError(-32700, message, data);
|
|
156
|
-
}
|
|
157
|
-
static invalidRequest(message, data) {
|
|
158
|
-
return new _A2AError(-32600, message, data);
|
|
159
|
-
}
|
|
160
|
-
static methodNotFound(method) {
|
|
161
|
-
return new _A2AError(
|
|
162
|
-
-32601,
|
|
163
|
-
`Method not found: ${method}`
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
static invalidParams(message, data) {
|
|
167
|
-
return new _A2AError(-32602, message, data);
|
|
168
|
-
}
|
|
169
|
-
static internalError(message, data) {
|
|
170
|
-
return new _A2AError(-32603, message, data);
|
|
171
|
-
}
|
|
172
|
-
static taskNotFound(taskId) {
|
|
173
|
-
return new _A2AError(
|
|
174
|
-
-32001,
|
|
175
|
-
`Task not found: ${taskId}`,
|
|
176
|
-
void 0,
|
|
177
|
-
taskId
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
static taskNotCancelable(taskId) {
|
|
181
|
-
return new _A2AError(
|
|
182
|
-
-32002,
|
|
183
|
-
`Task not cancelable: ${taskId}`,
|
|
184
|
-
void 0,
|
|
185
|
-
taskId
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
static pushNotificationNotSupported() {
|
|
189
|
-
return new _A2AError(
|
|
190
|
-
-32003,
|
|
191
|
-
"Push Notification is not supported"
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
static unsupportedOperation(operation) {
|
|
195
|
-
return new _A2AError(
|
|
196
|
-
-32004,
|
|
197
|
-
`Unsupported operation: ${operation}`
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
static authenticatedExtendedCardNotConfigured() {
|
|
201
|
-
return new _A2AError(
|
|
202
|
-
-32007,
|
|
203
|
-
`Extended card not configured.`
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
|
|
208
132
|
// src/server/result_manager.ts
|
|
209
133
|
var ResultManager = class {
|
|
210
134
|
taskStore;
|
|
@@ -699,128 +623,6 @@ var InMemoryTaskStore = class {
|
|
|
699
623
|
this.store.set(task.id, { ...task });
|
|
700
624
|
}
|
|
701
625
|
};
|
|
702
|
-
|
|
703
|
-
// src/server/transports/jsonrpc_transport_handler.ts
|
|
704
|
-
var JsonRpcTransportHandler = class {
|
|
705
|
-
requestHandler;
|
|
706
|
-
constructor(requestHandler) {
|
|
707
|
-
this.requestHandler = requestHandler;
|
|
708
|
-
}
|
|
709
|
-
/**
|
|
710
|
-
* Handles an incoming JSON-RPC request.
|
|
711
|
-
* For streaming methods, it returns an AsyncGenerator of JSONRPCResult.
|
|
712
|
-
* For non-streaming methods, it returns a Promise of a single JSONRPCMessage (Result or ErrorResponse).
|
|
713
|
-
*/
|
|
714
|
-
async handle(requestBody) {
|
|
715
|
-
let rpcRequest;
|
|
716
|
-
try {
|
|
717
|
-
if (typeof requestBody === "string") {
|
|
718
|
-
rpcRequest = JSON.parse(requestBody);
|
|
719
|
-
} else if (typeof requestBody === "object" && requestBody !== null) {
|
|
720
|
-
rpcRequest = requestBody;
|
|
721
|
-
} else {
|
|
722
|
-
throw A2AError.parseError("Invalid request body type.");
|
|
723
|
-
}
|
|
724
|
-
if (rpcRequest.jsonrpc !== "2.0" || !rpcRequest.method || typeof rpcRequest.method !== "string") {
|
|
725
|
-
throw A2AError.invalidRequest(
|
|
726
|
-
"Invalid JSON-RPC request structure."
|
|
727
|
-
);
|
|
728
|
-
}
|
|
729
|
-
} catch (error) {
|
|
730
|
-
const a2aError = error instanceof A2AError ? error : A2AError.parseError(error.message || "Failed to parse JSON request.");
|
|
731
|
-
return {
|
|
732
|
-
jsonrpc: "2.0",
|
|
733
|
-
id: typeof rpcRequest?.id !== "undefined" ? rpcRequest.id : null,
|
|
734
|
-
error: a2aError.toJSONRPCError()
|
|
735
|
-
};
|
|
736
|
-
}
|
|
737
|
-
const { method, id: requestId = null } = rpcRequest;
|
|
738
|
-
try {
|
|
739
|
-
if (method === "agent/getAuthenticatedExtendedCard") {
|
|
740
|
-
const result = await this.requestHandler.getAuthenticatedExtendedAgentCard();
|
|
741
|
-
return {
|
|
742
|
-
jsonrpc: "2.0",
|
|
743
|
-
id: requestId,
|
|
744
|
-
result
|
|
745
|
-
};
|
|
746
|
-
}
|
|
747
|
-
if (!rpcRequest.params) {
|
|
748
|
-
throw A2AError.invalidParams(`'params' is required for '${method}'`);
|
|
749
|
-
}
|
|
750
|
-
if (method === "message/stream" || method === "tasks/resubscribe") {
|
|
751
|
-
const params = rpcRequest.params;
|
|
752
|
-
const agentCard = await this.requestHandler.getAgentCard();
|
|
753
|
-
if (!agentCard.capabilities.streaming) {
|
|
754
|
-
throw A2AError.unsupportedOperation(`Method ${method} requires streaming capability.`);
|
|
755
|
-
}
|
|
756
|
-
const agentEventStream = method === "message/stream" ? this.requestHandler.sendMessageStream(params) : this.requestHandler.resubscribe(params);
|
|
757
|
-
return async function* jsonRpcEventStream() {
|
|
758
|
-
try {
|
|
759
|
-
for await (const event of agentEventStream) {
|
|
760
|
-
yield {
|
|
761
|
-
jsonrpc: "2.0",
|
|
762
|
-
id: requestId,
|
|
763
|
-
// Use the original request ID for all streamed responses
|
|
764
|
-
result: event
|
|
765
|
-
};
|
|
766
|
-
}
|
|
767
|
-
} catch (streamError) {
|
|
768
|
-
console.error(`Error in agent event stream for ${method} (request ${requestId}):`, streamError);
|
|
769
|
-
throw streamError;
|
|
770
|
-
}
|
|
771
|
-
}();
|
|
772
|
-
} else {
|
|
773
|
-
let result;
|
|
774
|
-
switch (method) {
|
|
775
|
-
case "message/send":
|
|
776
|
-
result = await this.requestHandler.sendMessage(rpcRequest.params);
|
|
777
|
-
break;
|
|
778
|
-
case "tasks/get":
|
|
779
|
-
result = await this.requestHandler.getTask(rpcRequest.params);
|
|
780
|
-
break;
|
|
781
|
-
case "tasks/cancel":
|
|
782
|
-
result = await this.requestHandler.cancelTask(rpcRequest.params);
|
|
783
|
-
break;
|
|
784
|
-
case "tasks/pushNotificationConfig/set":
|
|
785
|
-
result = await this.requestHandler.setTaskPushNotificationConfig(
|
|
786
|
-
rpcRequest.params
|
|
787
|
-
);
|
|
788
|
-
break;
|
|
789
|
-
case "tasks/pushNotificationConfig/get":
|
|
790
|
-
result = await this.requestHandler.getTaskPushNotificationConfig(
|
|
791
|
-
rpcRequest.params
|
|
792
|
-
);
|
|
793
|
-
break;
|
|
794
|
-
case "tasks/pushNotificationConfig/delete":
|
|
795
|
-
await this.requestHandler.deleteTaskPushNotificationConfig(
|
|
796
|
-
rpcRequest.params
|
|
797
|
-
);
|
|
798
|
-
result = null;
|
|
799
|
-
break;
|
|
800
|
-
case "tasks/pushNotificationConfig/list":
|
|
801
|
-
result = await this.requestHandler.listTaskPushNotificationConfigs(
|
|
802
|
-
rpcRequest.params
|
|
803
|
-
);
|
|
804
|
-
break;
|
|
805
|
-
default:
|
|
806
|
-
throw A2AError.methodNotFound(method);
|
|
807
|
-
}
|
|
808
|
-
return {
|
|
809
|
-
jsonrpc: "2.0",
|
|
810
|
-
id: requestId,
|
|
811
|
-
result
|
|
812
|
-
};
|
|
813
|
-
}
|
|
814
|
-
} catch (error) {
|
|
815
|
-
const a2aError = error instanceof A2AError ? error : A2AError.internalError(error.message || "An unexpected error occurred.");
|
|
816
|
-
return {
|
|
817
|
-
jsonrpc: "2.0",
|
|
818
|
-
id: requestId,
|
|
819
|
-
error: a2aError.toJSONRPCError()
|
|
820
|
-
};
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
};
|
|
824
626
|
export {
|
|
825
627
|
A2AError,
|
|
826
628
|
DefaultExecutionEventBus,
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@a2a-js/sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Server & Client SDK for Agent2Agent protocol",
|
|
5
|
-
"repository":
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/a2aproject/a2a-js.git"
|
|
8
|
+
},
|
|
6
9
|
"engines": {
|
|
7
10
|
"node": ">=18"
|
|
8
11
|
},
|