@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artinet/sdk",
3
- "version": "0.6.0-preview.2",
3
+ "version": "0.6.0",
4
4
  "description": "A TypeScript SDK for building collaborative AI agents.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -17,6 +17,16 @@
17
17
  "import": "./dist/index.js",
18
18
  "default": "./dist/index.js"
19
19
  },
20
+ "./sqlite": {
21
+ "types": "./dist/storage/sqlite.d.ts",
22
+ "import": "./dist/storage/sqlite.js",
23
+ "default": "./dist/storage/sqlite.js"
24
+ },
25
+ "./express": {
26
+ "types": "./dist/server/express/server.d.ts",
27
+ "import": "./dist/server/express/server.js",
28
+ "default": "./dist/server/express/server.js"
29
+ },
20
30
  "./trpc": {
21
31
  "types": "./dist/transport/trpc/index.d.ts",
22
32
  "import": "./dist/transport/trpc/index.js",
@@ -64,7 +74,8 @@
64
74
  "clean": "rimraf dist",
65
75
  "rebuild": "rimraf dist node_modules/ package-lock.json && npm i && npm run build:all",
66
76
  "lint": "eslint src --ext .ts",
67
- "prepublishOnly": "npm run rebuild && npm run lint && npm test",
77
+ "package-test": "npm run build && npm pack && docker build -f ./deployment/test.dockerfile -t sdk-test . && docker run --rm sdk-test && rm artinet-sdk-*.tgz",
78
+ "prepublishOnly": "npm run package-test && npm run rebuild && npm run lint && npm test",
68
79
  "test": "NODE_OPTIONS=--experimental-vm-modules jest",
69
80
  "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch",
70
81
  "test:coverage": "NODE_OPTIONS=--experimental-vm-modules jest --coverage",
@@ -84,56 +95,59 @@
84
95
  "license": "Apache-2.0",
85
96
  "repository": {
86
97
  "type": "git",
87
- "url": "https://github.com/the-artinet-project/artinet-sdk"
98
+ "url": "https://github.com/the-artinet-project/artinet"
88
99
  },
89
100
  "bugs": {
90
- "url": "https://github.com/the-artinet-project/artinet-sdk/issues"
101
+ "url": "https://github.com/the-artinet-project/artinet/issues"
91
102
  },
92
103
  "homepage": "https://github.com/the-artinet-project/artinet-sdk#readme",
93
104
  "dependencies": {
94
- "@artinet/types": "^0.0.9-alpha.3",
105
+ "@artinet/types": "^0.0.9",
106
+ "@opentelemetry/api": "^1.9.0",
95
107
  "cors": "^2.8.5",
96
- "escape-html": "^1.0.3",
97
- "eventsource-parser": "^3.0.1",
98
- "express": "^5.1.0",
108
+ "eventemitter3": "^5.0.1",
99
109
  "uuid": "^13.0.0",
100
110
  "zod": "^3.25"
101
111
  },
102
112
  "peerDependencies": {
113
+ "express": "^5.1.0",
103
114
  "@a2a-js/sdk": "^0.3.7",
104
115
  "@modelcontextprotocol/sdk": "^1.24.3",
105
116
  "@trpc/server": "^11.4.3",
106
- "@opentelemetry/api": "^1.9.0"
107
- },
108
- "optionalDependencies": {
109
- "pino": "^10.1.0",
110
- "winston": "^3.19.0"
117
+ "drizzle-orm": "^0.45.1"
111
118
  },
112
119
  "peerDependenciesMeta": {
113
- "@modelcontextprotocol/sdk": {
120
+ "express": {
114
121
  "optional": false
115
122
  },
116
- "@trpc/server": {
117
- "optional": true
123
+ "@modelcontextprotocol/sdk": {
124
+ "optional": false
118
125
  },
119
126
  "@a2a-js/sdk": {
120
- "optional": true
121
- },
122
- "@opentelemetry/api": {
123
127
  "optional": false
124
128
  },
129
+ "@trpc/server": {
130
+ "optional": true
131
+ },
125
132
  "pino": {
126
133
  "optional": true
127
134
  },
128
135
  "winston": {
129
136
  "optional": true
137
+ },
138
+ "drizzle-orm": {
139
+ "optional": true
130
140
  }
131
141
  },
132
142
  "devDependencies": {
143
+ "better-sqlite3": "^12.5.0",
144
+ "drizzle-orm": "^0.45.1",
133
145
  "@a2a-js/sdk": "^0.3.7",
134
146
  "@cfworker/json-schema": "^4.1.1",
135
147
  "@eslint/js": "^9.25.1",
148
+ "@modelcontextprotocol/sdk": "^1.24.3",
136
149
  "@opentelemetry/api": "^1.9.0",
150
+ "@trpc/server": "^11.4.3",
137
151
  "@types/cors": "^2.8.17",
138
152
  "@types/escape-html": "^1.0.4",
139
153
  "@types/express": "^5.0.1",
@@ -144,13 +158,11 @@
144
158
  "globals": "^16.0.0",
145
159
  "jest": "^30.2.0",
146
160
  "msw": "^2.7.5",
147
- "@modelcontextprotocol/sdk": "^1.24.3",
148
161
  "pino": "^10.1.0",
149
162
  "pino-caller": "^4.0.0",
150
163
  "pino-pretty": "^13.1.3",
151
164
  "rimraf": "^6.1.2",
152
165
  "supertest": "latest",
153
- "@trpc/server": "^11.4.3",
154
166
  "ts-jest": "^29.3.2",
155
167
  "ts-node": "^10.9.1",
156
168
  "ts-patch": "^3.3.0",
@@ -158,7 +170,8 @@
158
170
  "typescript": "^5.2.2",
159
171
  "typescript-eslint": "^8.31.0",
160
172
  "typescript-transform-paths": "^3.5.5",
161
- "winston": "^3.19.0"
173
+ "winston": "^3.19.0",
174
+ "nock": "^14.0.10"
162
175
  },
163
176
  "engines": {
164
177
  "node": ">=18.9.1"
@@ -1,127 +0,0 @@
1
- /**
2
- * Copyright 2025 The Artinet Project
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- import { A2A } from "../types/index.js";
6
- import type { Client } from "../types/client.js";
7
- /**
8
- * A2AClient is the main client class for interacting with Agent2Agent (A2A) protocol-compliant services.
9
- * It provides methods for sending tasks, retrieving statuses, canceling operations, and handling streaming responses.
10
- */
11
- export declare class A2AClient implements Client {
12
- private baseUrl;
13
- private cachedAgentCard;
14
- private customHeaders;
15
- private fallbackPath;
16
- private agentUrl;
17
- private mergePath;
18
- /**
19
- * Creates a new A2AClient instance.
20
- * @param baseUrl The base URL for the A2A server.
21
- * @param headers Optional custom headers to include in all requests.
22
- * @param fallbackPath Optional fallback path to use if the agent card is not found at the base URL.
23
- * @example
24
- * const client = new A2AClient("http://localhost:4000/a2a");
25
- * const card = await client.agentCard();
26
- * console.log(card);
27
- * @example
28
- * const client = new A2AClient("http://localhost:4000/a2a", {}, "/agent-card");
29
- * const card = await client.agentCard();
30
- * console.log(card);
31
- */
32
- constructor(baseUrl: URL | string, headers?: Record<string, string>, fallbackPath?: string, mergePath?: boolean);
33
- /**
34
- * Retrieves the AgentCard from the A2A server.
35
- * Caches the result after the first successful fetch.
36
- * @returns A promise resolving to the AgentCard.
37
- */
38
- agentCard(): Promise<A2A.AgentCard>;
39
- /**
40
- * Retrieves the AgentCard from the A2A server.
41
- * @returns A promise resolving to the AgentCard.
42
- */
43
- getAgentCard(): Promise<A2A.AgentCard>;
44
- /**
45
- * Refreshes the cached AgentCard by fetching it again from the server.
46
- * @returns A promise resolving to the updated AgentCard.
47
- */
48
- refreshAgentCard(): Promise<A2A.AgentCard>;
49
- sendMessage(params: A2A.MessageSendParams): Promise<A2A.Message | A2A.Task | null>;
50
- sendMessage(params: string | A2A.MessageSendParams["message"]): Promise<A2A.Message | A2A.Task | null>;
51
- /**
52
- * @deprecated Use sendMessage instead.
53
- * Sends a task request to the agent (non-streaming).
54
- * @param params The parameters for the message/send method.
55
- * @returns A promise resolving to the Task object or null.
56
- */
57
- sendTask(params: A2A.MessageSendParams): Promise<A2A.Message | A2A.Task | null>;
58
- /**
59
- * Sends a Message and returns a stream of status and artifact updates.
60
- * @param params Task parameters for the request
61
- * @returns An AsyncIterable that yields TaskStatusUpdateEvent/TaskArtifactUpdateEvent/Task/Message payloads.
62
- */
63
- sendStreamingMessage(params: A2A.MessageSendParams | string): AsyncIterable<A2A.Update>;
64
- /**
65
- * @deprecated Use sendStreamingMessage instead.
66
- * Sends a task and returns a subscription to status and artifact updates.
67
- * @param params Task parameters for the request
68
- * @returns An AsyncIterable that yields TaskStatusUpdateEvent or TaskArtifactUpdateEvent payloads.
69
- */
70
- sendTaskSubscribe(params: A2A.MessageSendParams): AsyncIterable<A2A.Update>;
71
- /**
72
- * Retrieves the current state of a task.
73
- * @param params The parameters for the tasks/get method.
74
- * @returns A promise resolving to the Task object or null.
75
- */
76
- getTask(params: A2A.TaskQueryParams): Promise<A2A.Task | null>;
77
- /**
78
- * Cancels a currently running task.
79
- * @param params The parameters for the tasks/cancel method.
80
- * @returns A promise resolving to the updated Task object (usually canceled state) or null.
81
- */
82
- cancelTask(params: A2A.TaskIdParams): Promise<A2A.Task | null>;
83
- /**
84
- * Sets or updates the push notification config for a task.
85
- * @param params The parameters for the tasks/pushNotificationConfig/set method (which is TaskPushNotificationConfig).
86
- * @returns A promise resolving to the confirmed TaskPushNotificationConfig or null.
87
- */
88
- setTaskPushNotification(params: A2A.TaskPushNotificationConfig): Promise<A2A.TaskPushNotificationConfig | null>;
89
- /**
90
- * Retrieves the currently configured push notification config for a task.
91
- * @param params The parameters for the tasks/pushNotificationConfig/get method.
92
- * @returns A promise resolving to the TaskPushNotificationConfig or null.
93
- */
94
- getTaskPushNotification(params: A2A.TaskIdParams): Promise<A2A.TaskPushNotificationConfig | null>;
95
- /**
96
- * Resubscribes to an existing task's update stream.
97
- * @param params Parameters identifying the task to resubscribe to
98
- * @returns An AsyncIterable that yields TaskStatusUpdateEvent or TaskArtifactUpdateEvent payloads.
99
- */
100
- resubscribeTask(params: A2A.TaskQueryParams): AsyncIterable<A2A.Update>;
101
- /**
102
- * Checks if the server supports a specific capability based on the agent card.
103
- * @param capability The capability to check (e.g., 'streaming', 'pushNotifications').
104
- * @returns A promise resolving to true if the capability is supported.
105
- */
106
- supports(capability: "streaming" | "pushNotifications" | "stateTransitionHistory"): Promise<boolean>;
107
- /**
108
- * Sets custom headers to be included in all requests.
109
- * @param headers A record of header name/value pairs.
110
- */
111
- setHeaders(headers: Record<string, string>): void;
112
- /**
113
- * Adds a single custom header to be included in all requests.
114
- * @param name The header name.
115
- * @param value The header value.
116
- */
117
- addHeader(name: string, value: string): void;
118
- /**
119
- * Removes a custom header.
120
- * @param name The header name to remove.
121
- */
122
- removeHeader(name: string): void;
123
- /**
124
- * Clears all custom headers.
125
- */
126
- clearHeaders(): void;
127
- }
@@ -1,233 +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
- /**
16
- * Creates a new A2AClient instance.
17
- * @param baseUrl The base URL for the A2A server.
18
- * @param headers Optional custom headers to include in all requests.
19
- * @param fallbackPath Optional fallback path to use if the agent card is not found at the base URL.
20
- * @example
21
- * const client = new A2AClient("http://localhost:4000/a2a");
22
- * const card = await client.agentCard();
23
- * console.log(card);
24
- * @example
25
- * const client = new A2AClient("http://localhost:4000/a2a", {}, "/agent-card");
26
- * const card = await client.agentCard();
27
- * console.log(card);
28
- */
29
- constructor(baseUrl, headers = {}, fallbackPath, mergePath = false) {
30
- this.cachedAgentCard = null;
31
- this.customHeaders = {};
32
- this.baseUrl = typeof baseUrl === "string" ? new URL(baseUrl) : baseUrl;
33
- this.customHeaders = headers;
34
- this.fallbackPath = fallbackPath ?? "/agent-card";
35
- this.agentUrl = this.baseUrl;
36
- this.mergePath = mergePath;
37
- }
38
- /**
39
- * Retrieves the AgentCard from the A2A server.
40
- * Caches the result after the first successful fetch.
41
- * @returns A promise resolving to the AgentCard.
42
- */
43
- async agentCard() {
44
- if (this.cachedAgentCard) {
45
- return this.cachedAgentCard;
46
- }
47
- // Standard location for agent cards
48
- const wellKnownUrl = new URL("/.well-known/agent-card.json", this.baseUrl);
49
- if (this.mergePath) {
50
- wellKnownUrl.pathname = this.baseUrl.pathname + wellKnownUrl.pathname;
51
- }
52
- try {
53
- try {
54
- if (!URL.canParse(wellKnownUrl)) {
55
- throw new Error("Invalid well-known URL");
56
- }
57
- const card = await executeGetRequest(wellKnownUrl, this.customHeaders, "agent card (well-known)");
58
- if (!card.name || card.name === null || card.name === undefined) {
59
- throw new Error("No agent card found");
60
- }
61
- this.cachedAgentCard = card;
62
- }
63
- catch (error) {
64
- logger.error("A2AClient:agentCard: Failed to fetch agent card (well-known):", error);
65
- const fallbackUrl = new URL(this.fallbackPath, this.baseUrl);
66
- if (this.mergePath) {
67
- fallbackUrl.pathname = this.baseUrl.pathname + fallbackUrl.pathname;
68
- }
69
- const fallbackCard = await executeGetRequest(fallbackUrl, this.customHeaders, "agent card (fallback)");
70
- if (!fallbackCard.name ||
71
- fallbackCard.name === null ||
72
- fallbackCard.name === undefined) {
73
- throw new Error("No fallback agent card found" + error);
74
- }
75
- this.cachedAgentCard = fallbackCard;
76
- }
77
- }
78
- catch (error) {
79
- logger.error("A2AClient:agentCard: Failed to fetch or parse agent card:", error);
80
- throw INTERNAL_ERROR(error);
81
- }
82
- this.agentUrl = new URL(this.cachedAgentCard.url, this.baseUrl);
83
- return this.cachedAgentCard;
84
- }
85
- /**
86
- * Retrieves the AgentCard from the A2A server.
87
- * @returns A promise resolving to the AgentCard.
88
- */
89
- getAgentCard() {
90
- return this.agentCard();
91
- }
92
- /**
93
- * Refreshes the cached AgentCard by fetching it again from the server.
94
- * @returns A promise resolving to the updated AgentCard.
95
- */
96
- async refreshAgentCard() {
97
- this.cachedAgentCard = null;
98
- return this.agentCard();
99
- }
100
- /**
101
- * Sends a Message to an agent server.
102
- * @param params The parameters for the message/send method.
103
- * @returns A promise resolving to Message/Task response from the agent server or null.
104
- */
105
- async sendMessage(params) {
106
- return await executeJsonRpcRequest(this.agentUrl, "message/send", typeof params === "string"
107
- ? describe.messageSendParams(params)
108
- : typeof params === "object" && "message" in params
109
- ? params
110
- : describe.messageSendParams({ message: params }), this.customHeaders);
111
- }
112
- /**
113
- * @deprecated Use sendMessage instead.
114
- * Sends a task request to the agent (non-streaming).
115
- * @param params The parameters for the message/send method.
116
- * @returns A promise resolving to the Task object or null.
117
- */
118
- async sendTask(params) {
119
- return await this.sendMessage(params);
120
- }
121
- /**
122
- * Sends a Message and returns a stream of status and artifact updates.
123
- * @param params Task parameters for the request
124
- * @returns An AsyncIterable that yields TaskStatusUpdateEvent/TaskArtifactUpdateEvent/Task/Message payloads.
125
- */
126
- sendStreamingMessage(params) {
127
- return executeStreamEvents(this.agentUrl, "message/stream", describe.messageSendParams(params), this.customHeaders);
128
- }
129
- /**
130
- * @deprecated Use sendStreamingMessage instead.
131
- * Sends a task and returns a subscription to status and artifact updates.
132
- * @param params Task parameters for the request
133
- * @returns An AsyncIterable that yields TaskStatusUpdateEvent or TaskArtifactUpdateEvent payloads.
134
- */
135
- sendTaskSubscribe(params) {
136
- return this.sendStreamingMessage(params);
137
- }
138
- /**
139
- * Retrieves the current state of a task.
140
- * @param params The parameters for the tasks/get method.
141
- * @returns A promise resolving to the Task object or null.
142
- */
143
- async getTask(params) {
144
- return await executeJsonRpcRequest(this.agentUrl, "tasks/get", params, this.customHeaders);
145
- }
146
- /**
147
- * Cancels a currently running task.
148
- * @param params The parameters for the tasks/cancel method.
149
- * @returns A promise resolving to the updated Task object (usually canceled state) or null.
150
- */
151
- async cancelTask(params) {
152
- return await executeJsonRpcRequest(this.agentUrl, "tasks/cancel", params, this.customHeaders);
153
- }
154
- /**
155
- * Sets or updates the push notification config for a task.
156
- * @param params The parameters for the tasks/pushNotificationConfig/set method (which is TaskPushNotificationConfig).
157
- * @returns A promise resolving to the confirmed TaskPushNotificationConfig or null.
158
- */
159
- async setTaskPushNotification(params) {
160
- return await executeJsonRpcRequest(this.agentUrl, "tasks/pushNotificationConfig/set", params, this.customHeaders);
161
- }
162
- /**
163
- * Retrieves the currently configured push notification config for a task.
164
- * @param params The parameters for the tasks/pushNotificationConfig/get method.
165
- * @returns A promise resolving to the TaskPushNotificationConfig or null.
166
- */
167
- async getTaskPushNotification(params) {
168
- return await executeJsonRpcRequest(this.agentUrl, "tasks/pushNotificationConfig/get", params, this.customHeaders);
169
- }
170
- /**
171
- * Resubscribes to an existing task's update stream.
172
- * @param params Parameters identifying the task to resubscribe to
173
- * @returns An AsyncIterable that yields TaskStatusUpdateEvent or TaskArtifactUpdateEvent payloads.
174
- */
175
- resubscribeTask(params) {
176
- return executeStreamEvents(this.agentUrl, "tasks/resubscribe", params, this.customHeaders);
177
- }
178
- /**
179
- * Checks if the server supports a specific capability based on the agent card.
180
- * @param capability The capability to check (e.g., 'streaming', 'pushNotifications').
181
- * @returns A promise resolving to true if the capability is supported.
182
- */
183
- async supports(capability) {
184
- try {
185
- const card = await this.agentCard();
186
- if (!card.capabilities) {
187
- return false;
188
- }
189
- switch (capability) {
190
- case "streaming":
191
- return !!card.capabilities.streaming;
192
- case "pushNotifications":
193
- return !!card.capabilities.pushNotifications;
194
- case "stateTransitionHistory":
195
- return !!card.capabilities.stateTransitionHistory;
196
- default:
197
- return false;
198
- }
199
- }
200
- catch (error) {
201
- logger.error(`A2AClient:supports: Failed to determine support for capability '${capability}':`, error);
202
- return false; // Assume not supported if card fetch fails
203
- }
204
- }
205
- /**
206
- * Sets custom headers to be included in all requests.
207
- * @param headers A record of header name/value pairs.
208
- */
209
- setHeaders(headers) {
210
- this.customHeaders = { ...headers };
211
- }
212
- /**
213
- * Adds a single custom header to be included in all requests.
214
- * @param name The header name.
215
- * @param value The header value.
216
- */
217
- addHeader(name, value) {
218
- this.customHeaders[name] = value;
219
- }
220
- /**
221
- * Removes a custom header.
222
- * @param name The header name to remove.
223
- */
224
- removeHeader(name) {
225
- delete this.customHeaders[name];
226
- }
227
- /**
228
- * Clears all custom headers.
229
- */
230
- clearHeaders() {
231
- this.customHeaders = {};
232
- }
233
- }
@@ -1 +0,0 @@
1
- export * from "./a2a-client.js";
@@ -1 +0,0 @@
1
- export * from "./a2a-client.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>;