@artinet/sdk 0.6.0-preview.2 → 0.6.0

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 (160) hide show
  1. package/README.md +100 -59
  2. package/dist/browser/browser.d.ts +2 -7
  3. package/dist/browser/browser.js +2 -7
  4. package/dist/browser/config/observability.d.ts +1 -1
  5. package/dist/browser/create/message-builder.d.ts +1 -1
  6. package/dist/browser/create/message-builder.js +19 -7
  7. package/dist/browser/create/task-builder.js +1 -1
  8. package/dist/browser/messenger/index.d.ts +1 -0
  9. package/dist/browser/messenger/index.js +1 -0
  10. package/dist/browser/messenger/messenger.d.ts +119 -0
  11. package/dist/browser/messenger/messenger.js +245 -0
  12. package/dist/browser/types/a2a/a2a.d.ts +38 -20
  13. package/dist/browser/types/a2a/a2a.js +0 -1
  14. package/dist/browser/types/core/core.d.ts +4 -2
  15. package/dist/browser/types/index.d.ts +0 -1
  16. package/dist/browser/types/index.js +0 -1
  17. package/dist/browser/types/storage.d.ts +2 -14
  18. package/dist/browser/types/storage.js +0 -4
  19. package/dist/browser/utils/{common/constants.d.ts → constants.d.ts} +1 -1
  20. package/dist/{utils/common → browser/utils}/constants.js +1 -1
  21. package/dist/browser/utils/{common/errors.d.ts → errors.d.ts} +17 -36
  22. package/dist/browser/utils/errors.js +76 -0
  23. package/dist/browser/utils/index.d.ts +6 -0
  24. package/dist/browser/utils/index.js +6 -0
  25. package/dist/{utils/common → browser/utils}/parse.js +1 -1
  26. package/dist/{utils/common → browser/utils}/schema-validation.js +2 -2
  27. package/dist/config/index.d.ts +1 -1
  28. package/dist/config/observability.d.ts +1 -1
  29. package/dist/create/agent-builder.d.ts +1 -1
  30. package/dist/create/create.d.ts +19 -20
  31. package/dist/create/create.js +33 -101
  32. package/dist/create/message-builder.d.ts +1 -1
  33. package/dist/create/message-builder.js +19 -7
  34. package/dist/create/status-builder.d.ts +4 -0
  35. package/dist/create/task-builder.js +1 -1
  36. package/dist/extensions/otel.d.ts +3 -0
  37. package/dist/extensions/otel.js +3 -0
  38. package/dist/extensions/pino.d.ts +3 -0
  39. package/dist/extensions/pino.js +3 -0
  40. package/dist/extensions/winston.d.ts +3 -0
  41. package/dist/extensions/winston.js +3 -0
  42. package/dist/index.d.ts +3 -3
  43. package/dist/index.js +3 -3
  44. package/dist/messenger/index.d.ts +1 -0
  45. package/dist/messenger/index.js +1 -0
  46. package/dist/messenger/messenger.d.ts +119 -0
  47. package/dist/messenger/messenger.js +251 -0
  48. package/dist/server/adapters/a2a_request_handler.d.ts +889 -0
  49. package/dist/server/adapters/a2a_request_handler.js +241 -0
  50. package/dist/server/adapters/loadable.d.ts +7 -0
  51. package/dist/server/adapters/loadable.js +73 -0
  52. package/dist/server/adapters/notifications.d.ts +26 -0
  53. package/dist/server/adapters/notifications.js +77 -0
  54. package/dist/server/express/server.d.ts +24 -18
  55. package/dist/server/express/server.js +41 -62
  56. package/dist/server/express/utils.d.ts +14 -0
  57. package/dist/server/express/{errors.js → utils.js} +22 -0
  58. package/dist/server/index.d.ts +4 -1
  59. package/dist/server/index.js +4 -1
  60. package/dist/server/params.d.ts +115 -0
  61. package/dist/server/params.js +21 -0
  62. package/dist/services/a2a/factory/context.d.ts +2 -1
  63. package/dist/services/a2a/factory/context.js +4 -3
  64. package/dist/services/a2a/factory/handler.d.ts +1 -1
  65. package/dist/services/a2a/factory/handler.js +7 -6
  66. package/dist/services/a2a/factory/service.d.ts +1 -1
  67. package/dist/services/a2a/factory/service.js +2 -2
  68. package/dist/services/a2a/factory/state-machine.js +9 -6
  69. package/dist/services/a2a/handlers/cancel-task.d.ts +1 -1
  70. package/dist/services/a2a/handlers/get-task.d.ts +1 -1
  71. package/dist/services/a2a/handlers/resubscribe-task.d.ts +2 -2
  72. package/dist/services/a2a/handlers/send-message.d.ts +1 -1
  73. package/dist/services/a2a/handlers/stream-message.d.ts +2 -2
  74. package/dist/services/a2a/handlers/update.js +7 -9
  75. package/dist/services/a2a/index.d.ts +0 -1
  76. package/dist/services/a2a/index.js +0 -1
  77. package/dist/services/a2a/managers.js +2 -1
  78. package/dist/services/a2a/messenger.d.ts +1 -1
  79. package/dist/services/a2a/messenger.js +1 -1
  80. package/dist/services/a2a/service.d.ts +26 -21
  81. package/dist/services/a2a/service.js +161 -93
  82. package/dist/services/a2a/state-machine.d.ts +1 -1
  83. package/dist/services/a2a/state-machine.js +2 -1
  84. package/dist/services/a2a/streams.js +1 -1
  85. package/dist/services/core/manager.d.ts +5 -0
  86. package/dist/services/core/manager.js +6 -0
  87. package/dist/services/mcp/service.js +1 -1
  88. package/dist/{utils/storage → storage}/file.d.ts +4 -2
  89. package/dist/{utils/storage → storage}/file.js +5 -4
  90. package/dist/storage/index.d.ts +1 -0
  91. package/dist/storage/index.js +2 -0
  92. package/dist/storage/sqlite.d.ts +353 -0
  93. package/dist/storage/sqlite.js +85 -0
  94. package/dist/transport/trpc/a2a/factory/router.d.ts +16 -16
  95. package/dist/transport/trpc/a2a/routes/info.d.ts +2 -2
  96. package/dist/transport/trpc/a2a/routes/message/route.d.ts +3 -3
  97. package/dist/transport/trpc/a2a/routes/message/route.js +2 -1
  98. package/dist/transport/trpc/a2a/routes/tasks/route.d.ts +4 -4
  99. package/dist/transport/trpc/a2a/routes/tasks/route.js +3 -2
  100. package/dist/types/a2a/a2a.d.ts +38 -20
  101. package/dist/types/a2a/a2a.js +0 -1
  102. package/dist/types/core/core.d.ts +4 -2
  103. package/dist/types/index.d.ts +0 -1
  104. package/dist/types/index.js +0 -1
  105. package/dist/types/storage.d.ts +2 -14
  106. package/dist/types/storage.js +0 -4
  107. package/dist/utils/{common/constants.d.ts → constants.d.ts} +1 -1
  108. package/dist/{browser/utils/common → utils}/constants.js +1 -1
  109. package/dist/utils/{common/errors.d.ts → errors.d.ts} +17 -36
  110. package/dist/utils/errors.js +80 -0
  111. package/dist/utils/index.d.ts +6 -11
  112. package/dist/utils/index.js +6 -11
  113. package/dist/utils/parse.d.ts +7 -0
  114. package/dist/utils/parse.js +14 -0
  115. package/dist/utils/schema-validation.d.ts +2 -0
  116. package/dist/utils/schema-validation.js +12 -0
  117. package/package.json +35 -22
  118. package/dist/browser/client/a2a-client.d.ts +0 -127
  119. package/dist/browser/client/a2a-client.js +0 -233
  120. package/dist/browser/client/index.d.ts +0 -1
  121. package/dist/browser/client/index.js +0 -1
  122. package/dist/browser/transport/rpc/parser.d.ts +0 -15
  123. package/dist/browser/transport/rpc/parser.js +0 -49
  124. package/dist/browser/transport/rpc/rpc-client.d.ts +0 -80
  125. package/dist/browser/transport/rpc/rpc-client.js +0 -189
  126. package/dist/browser/transport/streaming/event-stream.d.ts +0 -25
  127. package/dist/browser/transport/streaming/event-stream.js +0 -100
  128. package/dist/browser/types/client.d.ts +0 -133
  129. package/dist/browser/types/client.js +0 -5
  130. package/dist/browser/utils/common/errors.js +0 -95
  131. package/dist/client/a2a-client.d.ts +0 -127
  132. package/dist/client/a2a-client.js +0 -237
  133. package/dist/client/index.d.ts +0 -1
  134. package/dist/client/index.js +0 -1
  135. package/dist/server/express/errors.d.ts +0 -9
  136. package/dist/server/express/index.d.ts +0 -3
  137. package/dist/server/express/index.js +0 -3
  138. package/dist/server/express/middeware.d.ts +0 -7
  139. package/dist/server/express/middeware.js +0 -121
  140. package/dist/transport/index.d.ts +0 -3
  141. package/dist/transport/index.js +0 -4
  142. package/dist/transport/rpc/parser.d.ts +0 -15
  143. package/dist/transport/rpc/parser.js +0 -49
  144. package/dist/transport/rpc/rpc-client.d.ts +0 -80
  145. package/dist/transport/rpc/rpc-client.js +0 -189
  146. package/dist/transport/streaming/event-stream.d.ts +0 -25
  147. package/dist/transport/streaming/event-stream.js +0 -100
  148. package/dist/types/client.d.ts +0 -133
  149. package/dist/types/client.js +0 -5
  150. package/dist/utils/common/errors.js +0 -98
  151. /package/dist/{utils/common → browser/utils}/parse.d.ts +0 -0
  152. /package/dist/{utils/common → browser/utils}/schema-validation.d.ts +0 -0
  153. /package/dist/browser/utils/{common/utils.d.ts → utils.d.ts} +0 -0
  154. /package/dist/browser/utils/{common/utils.js → utils.js} +0 -0
  155. /package/dist/utils/{common/utils.d.ts → utils.d.ts} +0 -0
  156. /package/dist/utils/{common/utils.js → utils.js} +0 -0
  157. /package/dist/utils/{common/zAsyncIterable-v3.d.ts → zAsyncIterable-v3.d.ts} +0 -0
  158. /package/dist/utils/{common/zAsyncIterable-v3.js → zAsyncIterable-v3.js} +0 -0
  159. /package/dist/utils/{common/zAsyncIterable.d.ts → zAsyncIterable.d.ts} +0 -0
  160. /package/dist/utils/{common/zAsyncIterable.js → zAsyncIterable.js} +0 -0
@@ -1,237 +0,0 @@
1
- /**
2
- * Copyright 2025 The Artinet Project
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- import { executeJsonRpcRequest, executeGetRequest, } from "../transport/rpc/rpc-client.js";
6
- import { executeStreamEvents } from "../transport/streaming/event-stream.js";
7
- import { INTERNAL_ERROR } from "../utils/common/errors.js";
8
- import { logger } from "../config/index.js";
9
- import * as describe from "../create/describe.js";
10
- /**
11
- * A2AClient is the main client class for interacting with Agent2Agent (A2A) protocol-compliant services.
12
- * It provides methods for sending tasks, retrieving statuses, canceling operations, and handling streaming responses.
13
- */
14
- export class A2AClient {
15
- baseUrl;
16
- cachedAgentCard = null;
17
- customHeaders = {};
18
- fallbackPath;
19
- agentUrl;
20
- mergePath;
21
- /**
22
- * Creates a new A2AClient instance.
23
- * @param baseUrl The base URL for the A2A server.
24
- * @param headers Optional custom headers to include in all requests.
25
- * @param fallbackPath Optional fallback path to use if the agent card is not found at the base URL.
26
- * @example
27
- * const client = new A2AClient("http://localhost:4000/a2a");
28
- * const card = await client.agentCard();
29
- * console.log(card);
30
- * @example
31
- * const client = new A2AClient("http://localhost:4000/a2a", {}, "/agent-card");
32
- * const card = await client.agentCard();
33
- * console.log(card);
34
- */
35
- constructor(baseUrl, headers = {}, fallbackPath, mergePath = false) {
36
- this.baseUrl = typeof baseUrl === "string" ? new URL(baseUrl) : baseUrl;
37
- this.customHeaders = headers;
38
- this.fallbackPath = fallbackPath ?? "/agent-card";
39
- this.agentUrl = this.baseUrl;
40
- this.mergePath = mergePath;
41
- }
42
- /**
43
- * Retrieves the AgentCard from the A2A server.
44
- * Caches the result after the first successful fetch.
45
- * @returns A promise resolving to the AgentCard.
46
- */
47
- async agentCard() {
48
- if (this.cachedAgentCard) {
49
- return this.cachedAgentCard;
50
- }
51
- // Standard location for agent cards
52
- const wellKnownUrl = new URL("/.well-known/agent-card.json", this.baseUrl);
53
- if (this.mergePath) {
54
- wellKnownUrl.pathname = this.baseUrl.pathname + wellKnownUrl.pathname;
55
- }
56
- try {
57
- try {
58
- if (!URL.canParse(wellKnownUrl)) {
59
- throw new Error("Invalid well-known URL");
60
- }
61
- const card = await executeGetRequest(wellKnownUrl, this.customHeaders, "agent card (well-known)");
62
- if (!card.name || card.name === null || card.name === undefined) {
63
- throw new Error("No agent card found");
64
- }
65
- this.cachedAgentCard = card;
66
- }
67
- catch (error) {
68
- logger.error("A2AClient:agentCard: Failed to fetch agent card (well-known):", error);
69
- const fallbackUrl = new URL(this.fallbackPath, this.baseUrl);
70
- if (this.mergePath) {
71
- fallbackUrl.pathname = this.baseUrl.pathname + fallbackUrl.pathname;
72
- }
73
- const fallbackCard = await executeGetRequest(fallbackUrl, this.customHeaders, "agent card (fallback)");
74
- if (!fallbackCard.name ||
75
- fallbackCard.name === null ||
76
- fallbackCard.name === undefined) {
77
- throw new Error("No fallback agent card found" + error);
78
- }
79
- this.cachedAgentCard = fallbackCard;
80
- }
81
- }
82
- catch (error) {
83
- logger.error("A2AClient:agentCard: Failed to fetch or parse agent card:", error);
84
- throw INTERNAL_ERROR(error);
85
- }
86
- this.agentUrl = new URL(this.cachedAgentCard.url, this.baseUrl);
87
- return this.cachedAgentCard;
88
- }
89
- /**
90
- * Retrieves the AgentCard from the A2A server.
91
- * @returns A promise resolving to the AgentCard.
92
- */
93
- getAgentCard() {
94
- return this.agentCard();
95
- }
96
- /**
97
- * Refreshes the cached AgentCard by fetching it again from the server.
98
- * @returns A promise resolving to the updated AgentCard.
99
- */
100
- async refreshAgentCard() {
101
- this.cachedAgentCard = null;
102
- return this.agentCard();
103
- }
104
- /**
105
- * Sends a Message to an agent server.
106
- * @param params The parameters for the message/send method.
107
- * @returns A promise resolving to Message/Task response from the agent server or null.
108
- */
109
- async sendMessage(params) {
110
- return await executeJsonRpcRequest(this.agentUrl, "message/send", typeof params === "string"
111
- ? describe.messageSendParams(params)
112
- : typeof params === "object" && "message" in params
113
- ? params
114
- : describe.messageSendParams({ message: params }), this.customHeaders);
115
- }
116
- /**
117
- * @deprecated Use sendMessage instead.
118
- * Sends a task request to the agent (non-streaming).
119
- * @param params The parameters for the message/send method.
120
- * @returns A promise resolving to the Task object or null.
121
- */
122
- async sendTask(params) {
123
- return await this.sendMessage(params);
124
- }
125
- /**
126
- * Sends a Message and returns a stream of status and artifact updates.
127
- * @param params Task parameters for the request
128
- * @returns An AsyncIterable that yields TaskStatusUpdateEvent/TaskArtifactUpdateEvent/Task/Message payloads.
129
- */
130
- sendStreamingMessage(params) {
131
- return executeStreamEvents(this.agentUrl, "message/stream", describe.messageSendParams(params), this.customHeaders);
132
- }
133
- /**
134
- * @deprecated Use sendStreamingMessage instead.
135
- * Sends a task and returns a subscription to status and artifact updates.
136
- * @param params Task parameters for the request
137
- * @returns An AsyncIterable that yields TaskStatusUpdateEvent or TaskArtifactUpdateEvent payloads.
138
- */
139
- sendTaskSubscribe(params) {
140
- return this.sendStreamingMessage(params);
141
- }
142
- /**
143
- * Retrieves the current state of a task.
144
- * @param params The parameters for the tasks/get method.
145
- * @returns A promise resolving to the Task object or null.
146
- */
147
- async getTask(params) {
148
- return await executeJsonRpcRequest(this.agentUrl, "tasks/get", params, this.customHeaders);
149
- }
150
- /**
151
- * Cancels a currently running task.
152
- * @param params The parameters for the tasks/cancel method.
153
- * @returns A promise resolving to the updated Task object (usually canceled state) or null.
154
- */
155
- async cancelTask(params) {
156
- return await executeJsonRpcRequest(this.agentUrl, "tasks/cancel", params, this.customHeaders);
157
- }
158
- /**
159
- * Sets or updates the push notification config for a task.
160
- * @param params The parameters for the tasks/pushNotificationConfig/set method (which is TaskPushNotificationConfig).
161
- * @returns A promise resolving to the confirmed TaskPushNotificationConfig or null.
162
- */
163
- async setTaskPushNotification(params) {
164
- return await executeJsonRpcRequest(this.agentUrl, "tasks/pushNotificationConfig/set", params, this.customHeaders);
165
- }
166
- /**
167
- * Retrieves the currently configured push notification config for a task.
168
- * @param params The parameters for the tasks/pushNotificationConfig/get method.
169
- * @returns A promise resolving to the TaskPushNotificationConfig or null.
170
- */
171
- async getTaskPushNotification(params) {
172
- return await executeJsonRpcRequest(this.agentUrl, "tasks/pushNotificationConfig/get", params, this.customHeaders);
173
- }
174
- /**
175
- * Resubscribes to an existing task's update stream.
176
- * @param params Parameters identifying the task to resubscribe to
177
- * @returns An AsyncIterable that yields TaskStatusUpdateEvent or TaskArtifactUpdateEvent payloads.
178
- */
179
- resubscribeTask(params) {
180
- return executeStreamEvents(this.agentUrl, "tasks/resubscribe", params, this.customHeaders);
181
- }
182
- /**
183
- * Checks if the server supports a specific capability based on the agent card.
184
- * @param capability The capability to check (e.g., 'streaming', 'pushNotifications').
185
- * @returns A promise resolving to true if the capability is supported.
186
- */
187
- async supports(capability) {
188
- try {
189
- const card = await this.agentCard();
190
- if (!card.capabilities) {
191
- return false;
192
- }
193
- switch (capability) {
194
- case "streaming":
195
- return !!card.capabilities.streaming;
196
- case "pushNotifications":
197
- return !!card.capabilities.pushNotifications;
198
- case "stateTransitionHistory":
199
- return !!card.capabilities.stateTransitionHistory;
200
- default:
201
- return false;
202
- }
203
- }
204
- catch (error) {
205
- logger.error(`A2AClient:supports: Failed to determine support for capability '${capability}':`, error);
206
- return false; // Assume not supported if card fetch fails
207
- }
208
- }
209
- /**
210
- * Sets custom headers to be included in all requests.
211
- * @param headers A record of header name/value pairs.
212
- */
213
- setHeaders(headers) {
214
- this.customHeaders = { ...headers };
215
- }
216
- /**
217
- * Adds a single custom header to be included in all requests.
218
- * @param name The header name.
219
- * @param value The header value.
220
- */
221
- addHeader(name, value) {
222
- this.customHeaders[name] = value;
223
- }
224
- /**
225
- * Removes a custom header.
226
- * @param name The header name to remove.
227
- */
228
- removeHeader(name) {
229
- delete this.customHeaders[name];
230
- }
231
- /**
232
- * Clears all custom headers.
233
- */
234
- clearHeaders() {
235
- this.customHeaders = {};
236
- }
237
- }
@@ -1 +0,0 @@
1
- export * from "./a2a-client.js";
@@ -1 +0,0 @@
1
- export * from "./a2a-client.js";
@@ -1,9 +0,0 @@
1
- /**
2
- * Copyright 2025 The Artinet Project
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- import { type ErrorRequestHandler } from "express";
6
- /**
7
- * Express error handler middleware.
8
- */
9
- export declare const errorHandler: ErrorRequestHandler;
@@ -1,3 +0,0 @@
1
- export * from "./server.js";
2
- export * from "./middeware.js";
3
- export * from "./errors.js";
@@ -1,3 +0,0 @@
1
- export * from "./server.js";
2
- export * from "./middeware.js";
3
- export * from "./errors.js";
@@ -1,7 +0,0 @@
1
- /**
2
- * Copyright 2025 The Artinet Project
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- import { NextFunction, Request, Response } from "express";
6
- import { A2A } from "../../types/index.js";
7
- export declare function jsonRPCMiddleware(service: A2A.Service, req: Request, res: Response, next: NextFunction, extendedAgentCard?: A2A.AgentCard): Promise<void>;
@@ -1,121 +0,0 @@
1
- /**
2
- * Copyright 2025 The Artinet Project
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- import { logger } from "../../config/index.js";
6
- import { formatJson } from "../../utils/common/utils.js";
7
- import { A2AError } from "@a2a-js/sdk/server";
8
- const isValidMethod = (method) => {
9
- return (method &&
10
- method !== "" &&
11
- method !== null &&
12
- method !== undefined &&
13
- typeof method === "string");
14
- };
15
- const checkParams = (params, method) => {
16
- if (!params || (typeof params !== "object" && !Array.isArray(params))) {
17
- throw A2AError.invalidParams("Invalid Parameters", {
18
- params,
19
- method,
20
- });
21
- }
22
- else if (typeof params === "object" && Object.keys(params).length === 0) {
23
- throw A2AError.invalidParams("Params Required", {
24
- params,
25
- method,
26
- });
27
- }
28
- };
29
- export async function jsonRPCMiddleware(service, req, res, next, extendedAgentCard) {
30
- const { method, params, id, jsonrpc } = req.body;
31
- if (jsonrpc !== "2.0" ||
32
- (typeof id !== "string" &&
33
- typeof id === "number" &&
34
- !Number.isInteger(id) &&
35
- id !== null)) {
36
- res.json({
37
- jsonrpc: "2.0",
38
- id: id || null,
39
- error: A2AError.invalidRequest(`Invalid JSONRPC info: ${formatJson({ method, params, id, jsonrpc })}`).toJSONRPCError(),
40
- });
41
- return;
42
- }
43
- try {
44
- if (!isValidMethod(method)) {
45
- throw A2AError.invalidRequest("No method provided");
46
- }
47
- let result;
48
- switch (method) {
49
- case "message/send": {
50
- checkParams(params, method);
51
- result = await service.sendMessage(params);
52
- break;
53
- }
54
- case "message/stream": {
55
- checkParams(params, method);
56
- res.writeHead(200, {
57
- "Content-Type": "text/event-stream",
58
- "Cache-Control": "no-cache",
59
- Connection: "keep-alive",
60
- });
61
- const stream = service.streamMessage(params);
62
- for await (const data of stream) {
63
- res.write(`data: ${JSON.stringify({ jsonrpc: "2.0", id, result: data })}\n\n`);
64
- }
65
- res.end();
66
- return;
67
- }
68
- case "tasks/resubscribe": {
69
- checkParams(params, method);
70
- const stream = service.resubscribe(params);
71
- res.writeHead(200, {
72
- "Content-Type": "text/event-stream",
73
- "Cache-Control": "no-cache",
74
- Connection: "keep-alive",
75
- });
76
- for await (const data of stream) {
77
- res.write(`data: ${JSON.stringify({ jsonrpc: "2.0", id, result: data })}\n\n`);
78
- }
79
- res.end();
80
- return;
81
- }
82
- case "tasks/get": {
83
- checkParams(params, method);
84
- result = await service.getTask(params);
85
- break;
86
- }
87
- case "tasks/cancel": {
88
- checkParams(params, method);
89
- result = await service.cancelTask(params);
90
- break;
91
- }
92
- //todo: Implement push notifications
93
- //todo: Implement Tasks List
94
- case "tasks/pushNotificationConfig/set":
95
- case "tasks/pushNotificationConfig/get":
96
- case "tasks/pushNotificationConfig/delete":
97
- case "task/pushNotificationConfig/list": {
98
- throw A2AError.pushNotificationNotSupported();
99
- }
100
- case "agent/getAuthenticatedExtendedCard": {
101
- if (!extendedAgentCard ||
102
- (await service.getAgentCard()).supportsAuthenticatedExtendedCard !==
103
- true) {
104
- throw A2AError.authenticatedExtendedCardNotConfigured();
105
- }
106
- result = extendedAgentCard;
107
- break;
108
- }
109
- default:
110
- throw A2AError.methodNotFound(method);
111
- }
112
- res.json({ jsonrpc: "2.0", id, result });
113
- }
114
- catch (error) {
115
- logger.error("jsonRPCMiddleware[Error]:", error);
116
- logger.warn("jsonRPCMiddleware[Error]: Request body", {
117
- request: req.body,
118
- });
119
- return next(error);
120
- }
121
- }
@@ -1,3 +0,0 @@
1
- export * from "./rpc/rpc-client.js";
2
- export * from "./streaming/event-stream.js";
3
- export * from "./rpc/parser.js";
@@ -1,4 +0,0 @@
1
- export * from "./rpc/rpc-client.js";
2
- export * from "./streaming/event-stream.js";
3
- export * from "./rpc/parser.js";
4
- // export * from "./trpc/index.js";
@@ -1,15 +0,0 @@
1
- /**
2
- * Copyright 2025 The Artinet Project
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- import { MCP } from "../../types/index.js";
6
- /**
7
- * Parses a JSON-RPC response string and validates its structure.
8
- * If the response contains an error, it is thrown as an A2AError.
9
- * If the response contains neither a result nor an error, a validation error is thrown.
10
- *
11
- * @param data Response data as string
12
- * @returns The parsed and validated response object
13
- * @throws A2AError if the response contains an error or is invalid
14
- */
15
- export declare function parseResponse<Res extends MCP.JSONRPCResponse | MCP.JSONRPCErrorResponse>(data: string): Res;
@@ -1,49 +0,0 @@
1
- /**
2
- * Copyright 2025 The Artinet Project
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- import { MCP } from "../../types/index.js";
6
- import { SystemError, PARSE_ERROR } from "../../utils/common/errors.js";
7
- import { logger } from "../../config/index.js";
8
- /**
9
- * Parses a JSON-RPC response string and validates its structure.
10
- * If the response contains an error, it is thrown as an A2AError.
11
- * If the response contains neither a result nor an error, a validation error is thrown.
12
- *
13
- * @param data Response data as string
14
- * @returns The parsed and validated response object
15
- * @throws A2AError if the response contains an error or is invalid
16
- */
17
- export function parseResponse(data) {
18
- if (!data) {
19
- throw PARSE_ERROR("Invalid response data");
20
- }
21
- try {
22
- const parsed = JSON.parse(data); //todo: leverage safe parse
23
- if (parsed.error) {
24
- //MCP Error defs may be a wee bit restrictive
25
- const parsedError = MCP.JSONRPCErrorResponseSchema.safeParse(parsed);
26
- if (!parsedError.success) {
27
- throw PARSE_ERROR(parsedError.error);
28
- }
29
- throw new SystemError(parsedError.data.error.message, parsedError.data.error.code, parsedError.data.error.data);
30
- }
31
- if (typeof parsed !== "object" ||
32
- parsed === null ||
33
- parsed.jsonrpc !== "2.0") {
34
- throw PARSE_ERROR("invalid jsonrpc");
35
- }
36
- if (parsed.result === undefined) {
37
- throw PARSE_ERROR("result is undefined");
38
- }
39
- return parsed;
40
- }
41
- catch (error) {
42
- if (error instanceof SystemError) {
43
- logger.error("parseResponse: SystemError:", error);
44
- throw error;
45
- }
46
- logger.error("parseResponse: Error parsing response:", error);
47
- throw PARSE_ERROR(error);
48
- }
49
- }
@@ -1,80 +0,0 @@
1
- /**
2
- * Copyright 2025 The Artinet Project
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- import type { A2A, MCP } from "../../types/index.js";
6
- /**
7
- * Creates a JSON-RPC request body with the specified method and parameters.
8
- *, ErrorCodeParseError
9
- * @param method The JSON-RPC method name
10
- * @param params The parameters for the method
11
- * @param requestId Optional request ID (generates a UUID v4 if not provided)
12
- * @returns A properly formatted JSON-RPC request object
13
- */
14
- export declare function createJsonRpcRequest<Req extends A2A.A2ARequest>(method: Req["method"], params: Req["params"], requestId?: string | number): MCP.JSONRPCRequest;
15
- /**
16
- * Sends a JSON-RPC request to the specified endpoint.
17
- *
18
- * @param baseUrl The API endpoint URL
19
- * @param method The JSON-RPC method name
20
- * @param params The parameters for the method
21
- * @param headers Custom headers to include in the request
22
- * @param acceptHeader The desired Accept header ('application/json' or 'text/event-stream')
23
- * @returns A Promise resolving to the fetch Response object
24
- * @throws RpcError if there's a network error
25
- */
26
- export declare function sendJsonRpcRequest<Req extends A2A.A2ARequest>(baseUrl: URL, method: Req["method"], params: Req["params"], headers?: Record<string, string>, acceptHeader?: "application/json" | "text/event-stream"): Promise<Response>;
27
- /**
28
- * Sends a GET request to the specified endpoint.
29
- * This is used for non-JSON-RPC calls like agent card retrieval.
30
- *
31
- * @param url The endpoint URL
32
- * @param headers Custom headers to include in the request
33
- * @returns A Promise resolving to the fetch Response object
34
- * @throws RpcError if there's a network error
35
- */
36
- export declare function sendGetRequest(url: URL, headers?: Record<string, string>): Promise<Response>;
37
- /**
38
- * Processes a standard JSON-RPC response (non-streaming).
39
- * Parses the response, validates it, and returns the result payload.
40
- *
41
- * @param response The fetch Response object
42
- * @param expectedMethod Optional method name for logging purposes
43
- * @returns A promise resolving to the result payload
44
- * @throws RpcError if there's an error in the response
45
- */
46
- export declare function handleJsonRpcResponse<Res extends MCP.JSONRPCResultResponse>(response: Response, expectedMethod?: string): Promise<NonNullable<Res["result"]>>;
47
- /**
48
- * Processes a JSON response from a regular GET request.
49
- * Handles error checking and returns the parsed JSON.
50
- *
51
- * @param response The fetch Response object
52
- * @param endpoint Optional endpoint description for logging purposes
53
- * @returns A promise resolving to the parsed JSON
54
- * @throws RpcError if there's a response error
55
- */
56
- export declare function handleJsonResponse<T>(response: Response, endpoint?: string): Promise<T>;
57
- /**
58
- * Sends a JSON-RPC request and processes the response in a single operation.
59
- * This combines sendJsonRpcRequest and handleJsonRpcResponse into one call.
60
- *
61
- * @param baseUrl The API endpoint URL
62
- * @param method The JSON-RPC method name
63
- * @param params The parameters for the method
64
- * @param headers Custom headers to include in the request
65
- * @param acceptHeader The desired Accept header ('application/json' or 'text/event-stream')
66
- * @returns A Promise resolving to the result payload
67
- * @throws RpcError if there's a network error or error in the response
68
- */
69
- export declare function executeJsonRpcRequest<Req extends A2A.A2ARequest, Res extends MCP.JSONRPCResultResponse>(baseUrl: URL, method: Req["method"], params: Req["params"], headers?: Record<string, string>, acceptHeader?: "application/json" | "text/event-stream"): Promise<NonNullable<Res["result"]>>;
70
- /**
71
- * Sends a GET request and processes the JSON response.
72
- * Helper for non-RPC REST endpoints.
73
- *
74
- * @param url The endpoint URL
75
- * @param headers Custom headers to include in the request
76
- * @param endpoint Optional endpoint description for logging
77
- * @returns A Promise resolving to the parsed JSON
78
- * @throws RpcError if there's a network error or error in the response
79
- */
80
- export declare function executeGetRequest<T>(url: URL, headers?: Record<string, string>, endpoint?: string): Promise<T>;