@artinet/sdk 0.5.17 → 0.6.0-preview.1

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 (316) hide show
  1. package/README.md +51 -557
  2. package/dist/browser/browser.d.ts +9 -0
  3. package/dist/browser/browser.js +10 -0
  4. package/dist/browser/client/a2a-client.d.ts +127 -0
  5. package/dist/browser/client/a2a-client.js +233 -0
  6. package/dist/browser/client/index.d.ts +1 -0
  7. package/dist/browser/client/index.js +1 -0
  8. package/dist/browser/config/index.d.ts +158 -0
  9. package/dist/browser/config/index.js +155 -0
  10. package/dist/browser/config/observability.d.ts +119 -0
  11. package/dist/browser/config/observability.js +35 -0
  12. package/dist/browser/services/a2a/helpers/message-builder.d.ts +17 -0
  13. package/dist/browser/services/a2a/helpers/message-builder.js +66 -0
  14. package/dist/browser/transport/rpc/parser.d.ts +15 -0
  15. package/dist/browser/transport/rpc/parser.js +48 -0
  16. package/dist/browser/transport/rpc/rpc-client.d.ts +80 -0
  17. package/dist/browser/transport/rpc/rpc-client.js +189 -0
  18. package/dist/browser/transport/streaming/event-stream.d.ts +25 -0
  19. package/dist/browser/transport/streaming/event-stream.js +100 -0
  20. package/dist/browser/types/a2a/a2a.d.ts +378 -0
  21. package/dist/browser/types/a2a/a2a.js +14 -0
  22. package/dist/browser/types/a2a/builder.d.ts +43 -0
  23. package/dist/browser/types/a2a/index.d.ts +3 -0
  24. package/dist/browser/types/a2a/index.js +2 -0
  25. package/dist/{types/interfaces → browser/types}/client.d.ts +25 -27
  26. package/dist/browser/types/core/core.d.ts +31 -0
  27. package/dist/browser/types/core/index.d.ts +1 -0
  28. package/dist/browser/types/core/index.js +1 -0
  29. package/dist/{types/interfaces/services → browser/types}/index.d.ts +3 -0
  30. package/dist/{types/interfaces/services → browser/types}/index.js +3 -0
  31. package/dist/browser/types/mcp/index.d.ts +1 -0
  32. package/dist/browser/types/mcp/index.js +1 -0
  33. package/dist/{types/interfaces/services/mcp/service.d.ts → browser/types/mcp/mcp.d.ts} +4 -3
  34. package/dist/browser/types/mcp/mcp.js +5 -0
  35. package/dist/browser/types/storage.d.ts +21 -0
  36. package/dist/browser/types/utils/index.d.ts +1 -0
  37. package/dist/browser/types/utils/index.js +1 -0
  38. package/dist/browser/types/utils/transform.d.ts +64 -0
  39. package/dist/browser/types/utils/transform.js +35 -0
  40. package/dist/browser/utils/common/constants.d.ts +11 -0
  41. package/dist/browser/utils/common/constants.js +38 -0
  42. package/dist/browser/utils/common/errors.d.ts +24 -0
  43. package/dist/browser/utils/common/errors.js +42 -0
  44. package/dist/browser/utils/common/utils.d.ts +32 -0
  45. package/dist/browser/utils/common/utils.js +43 -0
  46. package/dist/client/a2a-client.d.ts +21 -19
  47. package/dist/client/a2a-client.js +30 -9
  48. package/dist/config/default.d.ts +50 -0
  49. package/dist/config/default.js +62 -0
  50. package/dist/config/index.d.ts +158 -0
  51. package/dist/config/index.js +155 -0
  52. package/dist/config/observability.d.ts +119 -0
  53. package/dist/config/observability.js +35 -0
  54. package/dist/extensions/otel.d.ts +98 -0
  55. package/dist/extensions/otel.js +190 -0
  56. package/dist/extensions/pino.d.ts +44 -0
  57. package/dist/extensions/pino.js +107 -0
  58. package/dist/extensions/winston.d.ts +47 -0
  59. package/dist/extensions/winston.js +114 -0
  60. package/dist/index.d.ts +2 -0
  61. package/dist/index.js +2 -0
  62. package/dist/server/express/errors.js +3 -3
  63. package/dist/server/express/middeware.d.ts +2 -2
  64. package/dist/server/express/middeware.js +36 -9
  65. package/dist/server/express/server.d.ts +9 -55
  66. package/dist/server/express/server.js +51 -32
  67. package/dist/services/a2a/execute.d.ts +6 -0
  68. package/dist/services/a2a/execute.js +25 -0
  69. package/dist/services/a2a/factory/builder.d.ts +21 -80
  70. package/dist/services/a2a/factory/builder.js +23 -13
  71. package/dist/services/a2a/factory/context.d.ts +15 -128
  72. package/dist/services/a2a/factory/context.js +31 -136
  73. package/dist/services/a2a/factory/handler.d.ts +6 -0
  74. package/dist/services/a2a/factory/{method.js → handler.js} +2 -2
  75. package/dist/services/a2a/factory/index.d.ts +1 -2
  76. package/dist/services/a2a/factory/index.js +1 -2
  77. package/dist/services/a2a/factory/service.d.ts +20 -7
  78. package/dist/services/a2a/factory/service.js +4 -4
  79. package/dist/services/a2a/factory/state-machine.d.ts +11 -0
  80. package/dist/services/a2a/factory/state-machine.js +66 -0
  81. package/dist/services/a2a/{state/update → handlers}/artifact.d.ts +4 -4
  82. package/dist/services/a2a/handlers/cancel-task.d.ts +11 -0
  83. package/dist/services/a2a/handlers/cancel-task.js +33 -0
  84. package/dist/services/a2a/handlers/get-task.d.ts +11 -0
  85. package/dist/services/a2a/handlers/get-task.js +13 -0
  86. package/dist/services/a2a/handlers/resubscribe-task.d.ts +11 -0
  87. package/dist/services/a2a/handlers/resubscribe-task.js +56 -0
  88. package/dist/services/a2a/handlers/send-message.d.ts +11 -0
  89. package/dist/services/a2a/handlers/send-message.js +35 -0
  90. package/dist/services/a2a/handlers/stream-message.d.ts +11 -0
  91. package/dist/services/a2a/handlers/stream-message.js +19 -0
  92. package/dist/services/a2a/handlers/update.d.ts +17 -0
  93. package/dist/services/a2a/handlers/update.js +114 -0
  94. package/dist/services/a2a/helpers/agentcard-builder.d.ts +9 -5
  95. package/dist/services/a2a/helpers/agentcard-builder.js +5 -0
  96. package/dist/services/a2a/helpers/content.d.ts +2 -2
  97. package/dist/services/a2a/helpers/content.js +4 -0
  98. package/dist/services/a2a/helpers/history.d.ts +6 -0
  99. package/dist/services/a2a/helpers/history.js +7 -0
  100. package/dist/services/a2a/helpers/index.d.ts +3 -1
  101. package/dist/services/a2a/helpers/index.js +3 -1
  102. package/dist/services/a2a/helpers/message-builder.d.ts +13 -8
  103. package/dist/services/a2a/helpers/message-builder.js +5 -0
  104. package/dist/services/a2a/helpers/part.d.ts +9 -9
  105. package/dist/services/a2a/helpers/references.d.ts +6 -0
  106. package/dist/services/a2a/helpers/references.js +22 -0
  107. package/dist/services/a2a/index.d.ts +9 -5
  108. package/dist/services/a2a/index.js +8 -5
  109. package/dist/services/a2a/managers.d.ts +23 -0
  110. package/dist/services/a2a/managers.js +95 -0
  111. package/dist/services/a2a/messenger.d.ts +35 -0
  112. package/dist/services/{core/managers/command.js → a2a/messenger.js} +27 -31
  113. package/dist/services/a2a/service.d.ts +41 -371
  114. package/dist/services/a2a/service.js +239 -70
  115. package/dist/services/a2a/state-machine.d.ts +18 -0
  116. package/dist/services/a2a/state-machine.js +76 -0
  117. package/dist/services/a2a/streams.d.ts +22 -0
  118. package/dist/services/a2a/streams.js +98 -0
  119. package/dist/services/core/index.d.ts +1 -2
  120. package/dist/services/core/index.js +1 -2
  121. package/dist/services/core/manager.d.ts +15 -0
  122. package/dist/services/core/manager.js +42 -0
  123. package/dist/services/mcp/service.d.ts +11 -15
  124. package/dist/services/mcp/service.js +16 -16
  125. package/dist/transport/index.d.ts +0 -1
  126. package/dist/transport/index.js +1 -1
  127. package/dist/transport/rpc/parser.d.ts +2 -2
  128. package/dist/transport/rpc/parser.js +7 -7
  129. package/dist/transport/rpc/rpc-client.d.ts +5 -5
  130. package/dist/transport/rpc/rpc-client.js +7 -7
  131. package/dist/transport/streaming/event-stream.d.ts +3 -3
  132. package/dist/transport/streaming/event-stream.js +11 -10
  133. package/dist/transport/trpc/a2a/factory/router.d.ts +479 -871
  134. package/dist/transport/trpc/a2a/factory/router.js +2 -2
  135. package/dist/transport/trpc/a2a/routes/info.d.ts +108 -8
  136. package/dist/transport/trpc/a2a/routes/info.js +6 -2
  137. package/dist/transport/trpc/a2a/routes/message/route.d.ts +113 -162
  138. package/dist/transport/trpc/a2a/routes/message/route.js +7 -13
  139. package/dist/transport/trpc/a2a/routes/tasks/route.d.ts +114 -212
  140. package/dist/transport/trpc/a2a/routes/tasks/route.js +16 -19
  141. package/dist/transport/trpc/a2a/trpc.d.ts +9 -253
  142. package/dist/types/a2a/a2a.d.ts +378 -0
  143. package/dist/types/a2a/a2a.js +14 -0
  144. package/dist/types/a2a/builder.d.ts +43 -0
  145. package/dist/types/a2a/index.d.ts +3 -0
  146. package/dist/types/a2a/index.js +2 -0
  147. package/dist/types/client.d.ts +133 -0
  148. package/dist/types/core/core.d.ts +31 -0
  149. package/dist/types/core/core.js +1 -0
  150. package/dist/types/core/index.d.ts +1 -0
  151. package/dist/types/core/index.js +1 -0
  152. package/dist/types/index.d.ts +6 -3
  153. package/dist/types/index.js +6 -3
  154. package/dist/types/mcp/index.d.ts +1 -0
  155. package/dist/types/mcp/index.js +1 -0
  156. package/dist/types/mcp/mcp.d.ts +50 -0
  157. package/dist/types/mcp/mcp.js +5 -0
  158. package/dist/types/protocol.d.ts +33 -0
  159. package/dist/types/protocol.js +34 -0
  160. package/dist/types/storage.d.ts +21 -0
  161. package/dist/utils/common/constants.d.ts +7 -7
  162. package/dist/utils/common/constants.js +10 -10
  163. package/dist/utils/common/errors.d.ts +18 -17
  164. package/dist/utils/common/errors.js +14 -13
  165. package/dist/utils/common/parse.d.ts +7 -0
  166. package/dist/utils/common/parse.js +14 -0
  167. package/dist/utils/common/schema-validation.d.ts +2 -0
  168. package/dist/utils/common/schema-validation.js +12 -0
  169. package/dist/utils/common/utils.d.ts +23 -0
  170. package/dist/utils/common/utils.js +32 -0
  171. package/dist/utils/common/zAsyncIterable-v3.d.ts +1 -1
  172. package/dist/utils/common/zAsyncIterable-v3.js +2 -1
  173. package/dist/utils/index.d.ts +3 -3
  174. package/dist/utils/index.js +3 -3
  175. package/dist/utils/storage/file.d.ts +8 -17
  176. package/dist/utils/storage/file.js +44 -73
  177. package/package.json +86 -23
  178. package/dist/services/a2a/factory/event.d.ts +0 -58
  179. package/dist/services/a2a/factory/event.js +0 -177
  180. package/dist/services/a2a/factory/method.d.ts +0 -6
  181. package/dist/services/a2a/managers/cancellation.d.ts +0 -11
  182. package/dist/services/a2a/managers/cancellation.js +0 -16
  183. package/dist/services/a2a/managers/connection.d.ts +0 -11
  184. package/dist/services/a2a/managers/connection.js +0 -16
  185. package/dist/services/a2a/managers/context.d.ts +0 -11
  186. package/dist/services/a2a/managers/context.js +0 -16
  187. package/dist/services/a2a/managers/index.d.ts +0 -5
  188. package/dist/services/a2a/managers/index.js +0 -5
  189. package/dist/services/a2a/managers/task.d.ts +0 -11
  190. package/dist/services/a2a/managers/task.js +0 -16
  191. package/dist/services/a2a/methods/cancel-task.d.ts +0 -7
  192. package/dist/services/a2a/methods/cancel-task.js +0 -43
  193. package/dist/services/a2a/methods/get-task.d.ts +0 -112
  194. package/dist/services/a2a/methods/get-task.js +0 -14
  195. package/dist/services/a2a/methods/resubscribe-task.d.ts +0 -7
  196. package/dist/services/a2a/methods/resubscribe-task.js +0 -80
  197. package/dist/services/a2a/methods/send-message.d.ts +0 -7
  198. package/dist/services/a2a/methods/send-message.js +0 -19
  199. package/dist/services/a2a/methods/stream-message.d.ts +0 -8
  200. package/dist/services/a2a/methods/stream-message.js +0 -21
  201. package/dist/services/a2a/state/index.d.ts +0 -3
  202. package/dist/services/a2a/state/index.js +0 -3
  203. package/dist/services/a2a/state/load.d.ts +0 -14
  204. package/dist/services/a2a/state/load.js +0 -71
  205. package/dist/services/a2a/state/process.d.ts +0 -7
  206. package/dist/services/a2a/state/process.js +0 -13
  207. package/dist/services/a2a/state/update/index.d.ts +0 -2
  208. package/dist/services/a2a/state/update/index.js +0 -2
  209. package/dist/services/a2a/state/update/update.d.ts +0 -23
  210. package/dist/services/a2a/state/update/update.js +0 -123
  211. package/dist/services/core/execution/execute.d.ts +0 -6
  212. package/dist/services/core/execution/execute.js +0 -25
  213. package/dist/services/core/execution/index.d.ts +0 -1
  214. package/dist/services/core/execution/index.js +0 -1
  215. package/dist/services/core/managers/command.d.ts +0 -39
  216. package/dist/services/core/managers/event.d.ts +0 -18
  217. package/dist/services/core/managers/event.js +0 -56
  218. package/dist/services/core/managers/index.d.ts +0 -3
  219. package/dist/services/core/managers/index.js +0 -3
  220. package/dist/services/core/managers/stream.d.ts +0 -20
  221. package/dist/services/core/managers/stream.js +0 -77
  222. package/dist/types/ext.d.ts +0 -13
  223. package/dist/types/ext.js +0 -10
  224. package/dist/types/interfaces/index.d.ts +0 -3
  225. package/dist/types/interfaces/index.js +0 -3
  226. package/dist/types/interfaces/services/a2a/builder.d.ts +0 -37
  227. package/dist/types/interfaces/services/a2a/context.d.ts +0 -162
  228. package/dist/types/interfaces/services/a2a/engine.d.ts +0 -7
  229. package/dist/types/interfaces/services/a2a/index.d.ts +0 -5
  230. package/dist/types/interfaces/services/a2a/index.js +0 -5
  231. package/dist/types/interfaces/services/a2a/legacy.d.ts +0 -93
  232. package/dist/types/interfaces/services/a2a/service.d.ts +0 -409
  233. package/dist/types/interfaces/services/a2a/service.js +0 -5
  234. package/dist/types/interfaces/services/core/context/command.d.ts +0 -25
  235. package/dist/types/interfaces/services/core/context/command.js +0 -5
  236. package/dist/types/interfaces/services/core/context/context.d.ts +0 -207
  237. package/dist/types/interfaces/services/core/context/context.js +0 -5
  238. package/dist/types/interfaces/services/core/context/index.d.ts +0 -3
  239. package/dist/types/interfaces/services/core/context/index.js +0 -3
  240. package/dist/types/interfaces/services/core/context/types.d.ts +0 -11
  241. package/dist/types/interfaces/services/core/context/types.js +0 -5
  242. package/dist/types/interfaces/services/core/execution/engine.d.ts +0 -106
  243. package/dist/types/interfaces/services/core/execution/engine.js +0 -5
  244. package/dist/types/interfaces/services/core/execution/environment.d.ts +0 -11
  245. package/dist/types/interfaces/services/core/execution/environment.js +0 -5
  246. package/dist/types/interfaces/services/core/execution/execute.d.ts +0 -7
  247. package/dist/types/interfaces/services/core/execution/execute.js +0 -5
  248. package/dist/types/interfaces/services/core/execution/index.d.ts +0 -3
  249. package/dist/types/interfaces/services/core/execution/index.js +0 -3
  250. package/dist/types/interfaces/services/core/index.d.ts +0 -4
  251. package/dist/types/interfaces/services/core/index.js +0 -4
  252. package/dist/types/interfaces/services/core/managers/cancellation.d.ts +0 -9
  253. package/dist/types/interfaces/services/core/managers/cancellation.js +0 -5
  254. package/dist/types/interfaces/services/core/managers/connection.d.ts +0 -9
  255. package/dist/types/interfaces/services/core/managers/connection.js +0 -5
  256. package/dist/types/interfaces/services/core/managers/context.d.ts +0 -17
  257. package/dist/types/interfaces/services/core/managers/context.js +0 -5
  258. package/dist/types/interfaces/services/core/managers/event.d.ts +0 -328
  259. package/dist/types/interfaces/services/core/managers/event.js +0 -5
  260. package/dist/types/interfaces/services/core/managers/index.d.ts +0 -6
  261. package/dist/types/interfaces/services/core/managers/index.js +0 -6
  262. package/dist/types/interfaces/services/core/managers/stream.d.ts +0 -217
  263. package/dist/types/interfaces/services/core/managers/stream.js +0 -5
  264. package/dist/types/interfaces/services/core/managers/task.d.ts +0 -9
  265. package/dist/types/interfaces/services/core/service.d.ts +0 -115
  266. package/dist/types/interfaces/services/core/service.js +0 -5
  267. package/dist/types/interfaces/services/mcp/index.d.ts +0 -1
  268. package/dist/types/interfaces/services/mcp/index.js +0 -1
  269. package/dist/types/interfaces/services/mcp/service.js +0 -5
  270. package/dist/types/interfaces/storage.d.ts +0 -8
  271. package/dist/types/schemas/a2a/agent.d.ts +0 -2583
  272. package/dist/types/schemas/a2a/agent.js +0 -323
  273. package/dist/types/schemas/a2a/auth.d.ts +0 -908
  274. package/dist/types/schemas/a2a/auth.js +0 -283
  275. package/dist/types/schemas/a2a/error.d.ts +0 -396
  276. package/dist/types/schemas/a2a/error.js +0 -163
  277. package/dist/types/schemas/a2a/index.d.ts +0 -11
  278. package/dist/types/schemas/a2a/index.js +0 -11
  279. package/dist/types/schemas/a2a/kind.d.ts +0 -11
  280. package/dist/types/schemas/a2a/kind.js +0 -20
  281. package/dist/types/schemas/a2a/message.d.ts +0 -10343
  282. package/dist/types/schemas/a2a/message.js +0 -130
  283. package/dist/types/schemas/a2a/notification.d.ts +0 -1517
  284. package/dist/types/schemas/a2a/notification.js +0 -203
  285. package/dist/types/schemas/a2a/parameters.d.ts +0 -956
  286. package/dist/types/schemas/a2a/parameters.js +0 -241
  287. package/dist/types/schemas/a2a/protocol.d.ts +0 -14363
  288. package/dist/types/schemas/a2a/protocol.js +0 -59
  289. package/dist/types/schemas/a2a/rpc.d.ts +0 -182
  290. package/dist/types/schemas/a2a/rpc.js +0 -126
  291. package/dist/types/schemas/a2a/task.d.ts +0 -5886
  292. package/dist/types/schemas/a2a/task.js +0 -134
  293. package/dist/types/schemas/a2a/transport.d.ts +0 -31
  294. package/dist/types/schemas/a2a/transport.js +0 -28
  295. package/dist/types/schemas/index.d.ts +0 -1
  296. package/dist/types/schemas/index.js +0 -1
  297. package/dist/utils/logging/index.d.ts +0 -2
  298. package/dist/utils/logging/index.js +0 -2
  299. package/dist/utils/logging/log.d.ts +0 -33
  300. package/dist/utils/logging/log.js +0 -75
  301. package/dist/utils/logging/logger.d.ts +0 -18
  302. package/dist/utils/logging/logger.js +0 -18
  303. package/dist/utils/storage/memory.d.ts +0 -25
  304. package/dist/utils/storage/memory.js +0 -47
  305. /package/dist/{types/interfaces/services → browser/types}/a2a/builder.js +0 -0
  306. /package/dist/{types/interfaces → browser/types}/client.js +0 -0
  307. /package/dist/{types/interfaces/services/core/managers/task.js → browser/types/core/core.js} +0 -0
  308. /package/dist/{types/interfaces/services → browser/types}/protocol.d.ts +0 -0
  309. /package/dist/{types/interfaces/services → browser/types}/protocol.js +0 -0
  310. /package/dist/{types/interfaces → browser/types}/storage.js +0 -0
  311. /package/dist/services/a2a/{state/update → handlers}/artifact.js +0 -0
  312. /package/dist/services/a2a/{methods → handlers}/index.d.ts +0 -0
  313. /package/dist/services/a2a/{methods → handlers}/index.js +0 -0
  314. /package/dist/types/{interfaces/services/a2a/context.js → a2a/builder.js} +0 -0
  315. /package/dist/types/{interfaces/services/a2a/engine.js → client.js} +0 -0
  316. /package/dist/types/{interfaces/services/a2a/legacy.js → storage.js} +0 -0
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * Event stream utilities for handling Server-Sent Events (SSE).
7
+ */
8
+ import { parseResponse } from "../rpc/parser.js";
9
+ import { createParser, } from "eventsource-parser";
10
+ import { sendJsonRpcRequest } from "../rpc/rpc-client.js";
11
+ import { logger } from "../../config/index.js";
12
+ /**
13
+ * Creates an async generator for processing task events from an SSE stream
14
+ *
15
+ * @template T The type of task event to process (TaskStatusUpdateEvent or TaskArtifactUpdateEvent)
16
+ * @param response The fetch Response object containing the event stream
17
+ * @returns An async generator yielding the specified type of task events from StreamingResponse
18
+ */
19
+ export async function* handleEventStream(response) {
20
+ if (!response.ok || !response.body) {
21
+ let errorText = null;
22
+ try {
23
+ errorText = await response.text();
24
+ }
25
+ catch (_) { }
26
+ const err = new Error(`HTTP error [${response.status}:${response.statusText}] - ${errorText}`);
27
+ logger.error(`handleEventStream: HTTP error [${response.status}:${response.statusText}] - ${errorText}`, err);
28
+ throw err;
29
+ }
30
+ // Use eventsource-parser to process the SSE stream
31
+ const reader = response.body.getReader();
32
+ const decoder = new TextDecoder();
33
+ const events = [];
34
+ const parser = createParser({
35
+ onEvent: (event) => {
36
+ if (event.data) {
37
+ if (event.event === "close") {
38
+ logger.debug("handleEventStream", "Stream closed");
39
+ return;
40
+ }
41
+ try {
42
+ const parsedData = parseResponse(event.data);
43
+ const eventResult = parsedData.result;
44
+ if (eventResult) {
45
+ events.push(eventResult);
46
+ }
47
+ else {
48
+ logger.warn("handleEventStream", "Failed to parse SSE data", parsedData);
49
+ }
50
+ // if (parsedData.final && parsedData.final === true) {
51
+ // logDebug("handleEventStream", "Stream completed");
52
+ // return;
53
+ // }
54
+ }
55
+ catch (e) {
56
+ logger.warn("handleEventStream", "Failed to parse SSE data", e);
57
+ }
58
+ }
59
+ },
60
+ onError: (error) => {
61
+ logger.error("handleEventStream: Error parsing SSE data", error);
62
+ },
63
+ onRetry: (retry) => {
64
+ logger.warn("handleEventStream", "Retrying SSE connection", retry);
65
+ },
66
+ });
67
+ try {
68
+ while (true) {
69
+ const { done, value } = await reader.read();
70
+ if (done)
71
+ break;
72
+ const chunk = decoder.decode(value, { stream: true });
73
+ parser.feed(chunk);
74
+ while (events.length > 0) {
75
+ yield events.shift();
76
+ }
77
+ }
78
+ }
79
+ finally {
80
+ reader.releaseLock();
81
+ }
82
+ }
83
+ /**
84
+ * Executes a streaming JSON-RPC request and yields events as they arrive
85
+ *
86
+ * @template Req The type of request being made
87
+ * @template StreamRes The type of streaming response expected
88
+ * @param baseUrl The base URL for the API
89
+ * @param method The JSON-RPC method to call
90
+ * @param params The parameters for the method
91
+ * @param customHeaders Any custom headers to include in the request
92
+ * @returns An AsyncIterable yielding events from the stream
93
+ */
94
+ export async function* executeStreamEvents(baseUrl, method, params, customHeaders) {
95
+ logger.debug("executeStreamEvents", `Sending streaming request to: ${baseUrl.toString()}, method: ${method}`);
96
+ const responsePromise = sendJsonRpcRequest(baseUrl, method, params, customHeaders, "text/event-stream");
97
+ const response = await responsePromise;
98
+ logger.debug("executeStreamEvents", "Response", response);
99
+ yield* handleEventStream(response);
100
+ }
@@ -0,0 +1,378 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { AgentCard, Message, Task, AgentExtension, TaskQueryParams, TaskIdParams, MessageSendParams, SendMessageSuccessResult } from "@artinet/types/a2a";
6
+ import { core } from "../core/index.js";
7
+ import { z } from "zod/v4";
8
+ export type AgentCardParams = (Partial<AgentCard> & Required<Pick<AgentCard, "name">>) | string;
9
+ export declare const UpdateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
10
+ role: z.ZodEnum<{
11
+ user: "user";
12
+ agent: "agent";
13
+ }>;
14
+ parts: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
15
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
16
+ kind: z.ZodLiteral<"text">;
17
+ text: z.ZodString;
18
+ }, z.core.$strip>, z.ZodObject<{
19
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
20
+ kind: z.ZodLiteral<"file">;
21
+ file: z.ZodUnion<readonly [z.ZodObject<{
22
+ name: z.ZodOptional<z.ZodString>;
23
+ mimeType: z.ZodOptional<z.ZodString>;
24
+ bytes: z.ZodString;
25
+ uri: z.ZodOptional<z.ZodNever>;
26
+ }, z.core.$strip>, z.ZodObject<{
27
+ name: z.ZodOptional<z.ZodString>;
28
+ mimeType: z.ZodOptional<z.ZodString>;
29
+ uri: z.ZodString;
30
+ bytes: z.ZodOptional<z.ZodNever>;
31
+ }, z.core.$strip>]>;
32
+ }, z.core.$strip>, z.ZodObject<{
33
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
34
+ kind: z.ZodLiteral<"data">;
35
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
36
+ }, z.core.$strip>]>>;
37
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
38
+ extensions: z.ZodOptional<z.ZodArray<z.ZodString>>;
39
+ referenceTaskIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
40
+ messageId: z.ZodString;
41
+ taskId: z.ZodOptional<z.ZodString>;
42
+ contextId: z.ZodOptional<z.ZodString>;
43
+ kind: z.ZodLiteral<"message">;
44
+ }, z.core.$strip>, z.ZodObject<{
45
+ id: z.ZodString;
46
+ contextId: z.ZodString;
47
+ status: z.ZodObject<{
48
+ state: z.ZodEnum<{
49
+ failed: "failed";
50
+ unknown: "unknown";
51
+ completed: "completed";
52
+ canceled: "canceled";
53
+ rejected: "rejected";
54
+ working: "working";
55
+ submitted: "submitted";
56
+ "input-required": "input-required";
57
+ "auth-required": "auth-required";
58
+ }>;
59
+ message: z.ZodOptional<z.ZodObject<{
60
+ role: z.ZodEnum<{
61
+ user: "user";
62
+ agent: "agent";
63
+ }>;
64
+ parts: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
65
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
66
+ kind: z.ZodLiteral<"text">;
67
+ text: z.ZodString;
68
+ }, z.core.$strip>, z.ZodObject<{
69
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
70
+ kind: z.ZodLiteral<"file">;
71
+ file: z.ZodUnion<readonly [z.ZodObject<{
72
+ name: z.ZodOptional<z.ZodString>;
73
+ mimeType: z.ZodOptional<z.ZodString>;
74
+ bytes: z.ZodString;
75
+ uri: z.ZodOptional<z.ZodNever>;
76
+ }, z.core.$strip>, z.ZodObject<{
77
+ name: z.ZodOptional<z.ZodString>;
78
+ mimeType: z.ZodOptional<z.ZodString>;
79
+ uri: z.ZodString;
80
+ bytes: z.ZodOptional<z.ZodNever>;
81
+ }, z.core.$strip>]>;
82
+ }, z.core.$strip>, z.ZodObject<{
83
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
84
+ kind: z.ZodLiteral<"data">;
85
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
86
+ }, z.core.$strip>]>>;
87
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
88
+ extensions: z.ZodOptional<z.ZodArray<z.ZodString>>;
89
+ referenceTaskIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
90
+ messageId: z.ZodString;
91
+ taskId: z.ZodOptional<z.ZodString>;
92
+ contextId: z.ZodOptional<z.ZodString>;
93
+ kind: z.ZodLiteral<"message">;
94
+ }, z.core.$strip>>;
95
+ timestamp: z.ZodOptional<z.ZodISODateTime>;
96
+ }, z.core.$strip>;
97
+ history: z.ZodOptional<z.ZodArray<z.ZodObject<{
98
+ role: z.ZodEnum<{
99
+ user: "user";
100
+ agent: "agent";
101
+ }>;
102
+ parts: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
103
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
104
+ kind: z.ZodLiteral<"text">;
105
+ text: z.ZodString;
106
+ }, z.core.$strip>, z.ZodObject<{
107
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
108
+ kind: z.ZodLiteral<"file">;
109
+ file: z.ZodUnion<readonly [z.ZodObject<{
110
+ name: z.ZodOptional<z.ZodString>;
111
+ mimeType: z.ZodOptional<z.ZodString>;
112
+ bytes: z.ZodString;
113
+ uri: z.ZodOptional<z.ZodNever>;
114
+ }, z.core.$strip>, z.ZodObject<{
115
+ name: z.ZodOptional<z.ZodString>;
116
+ mimeType: z.ZodOptional<z.ZodString>;
117
+ uri: z.ZodString;
118
+ bytes: z.ZodOptional<z.ZodNever>;
119
+ }, z.core.$strip>]>;
120
+ }, z.core.$strip>, z.ZodObject<{
121
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
122
+ kind: z.ZodLiteral<"data">;
123
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
124
+ }, z.core.$strip>]>>;
125
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
126
+ extensions: z.ZodOptional<z.ZodArray<z.ZodString>>;
127
+ referenceTaskIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
128
+ messageId: z.ZodString;
129
+ taskId: z.ZodOptional<z.ZodString>;
130
+ contextId: z.ZodOptional<z.ZodString>;
131
+ kind: z.ZodLiteral<"message">;
132
+ }, z.core.$strip>>>;
133
+ artifacts: z.ZodOptional<z.ZodArray<z.ZodObject<{
134
+ artifactId: z.ZodString;
135
+ name: z.ZodOptional<z.ZodString>;
136
+ description: z.ZodOptional<z.ZodString>;
137
+ parts: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
138
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
139
+ kind: z.ZodLiteral<"text">;
140
+ text: z.ZodString;
141
+ }, z.core.$strip>, z.ZodObject<{
142
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
143
+ kind: z.ZodLiteral<"file">;
144
+ file: z.ZodUnion<readonly [z.ZodObject<{
145
+ name: z.ZodOptional<z.ZodString>;
146
+ mimeType: z.ZodOptional<z.ZodString>;
147
+ bytes: z.ZodString;
148
+ uri: z.ZodOptional<z.ZodNever>;
149
+ }, z.core.$strip>, z.ZodObject<{
150
+ name: z.ZodOptional<z.ZodString>;
151
+ mimeType: z.ZodOptional<z.ZodString>;
152
+ uri: z.ZodString;
153
+ bytes: z.ZodOptional<z.ZodNever>;
154
+ }, z.core.$strip>]>;
155
+ }, z.core.$strip>, z.ZodObject<{
156
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
157
+ kind: z.ZodLiteral<"data">;
158
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
159
+ }, z.core.$strip>]>>;
160
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
161
+ extension: z.ZodOptional<z.ZodArray<z.ZodString>>;
162
+ }, z.core.$strip>>>;
163
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
164
+ kind: z.ZodLiteral<"task">;
165
+ }, z.core.$strip>, z.ZodObject<{
166
+ taskId: z.ZodString;
167
+ contextId: z.ZodString;
168
+ kind: z.ZodLiteral<"status-update">;
169
+ status: z.ZodObject<{
170
+ state: z.ZodEnum<{
171
+ failed: "failed";
172
+ unknown: "unknown";
173
+ completed: "completed";
174
+ canceled: "canceled";
175
+ rejected: "rejected";
176
+ working: "working";
177
+ submitted: "submitted";
178
+ "input-required": "input-required";
179
+ "auth-required": "auth-required";
180
+ }>;
181
+ message: z.ZodOptional<z.ZodObject<{
182
+ role: z.ZodEnum<{
183
+ user: "user";
184
+ agent: "agent";
185
+ }>;
186
+ parts: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
187
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
188
+ kind: z.ZodLiteral<"text">;
189
+ text: z.ZodString;
190
+ }, z.core.$strip>, z.ZodObject<{
191
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
192
+ kind: z.ZodLiteral<"file">;
193
+ file: z.ZodUnion<readonly [z.ZodObject<{
194
+ name: z.ZodOptional<z.ZodString>;
195
+ mimeType: z.ZodOptional<z.ZodString>;
196
+ bytes: z.ZodString;
197
+ uri: z.ZodOptional<z.ZodNever>;
198
+ }, z.core.$strip>, z.ZodObject<{
199
+ name: z.ZodOptional<z.ZodString>;
200
+ mimeType: z.ZodOptional<z.ZodString>;
201
+ uri: z.ZodString;
202
+ bytes: z.ZodOptional<z.ZodNever>;
203
+ }, z.core.$strip>]>;
204
+ }, z.core.$strip>, z.ZodObject<{
205
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
206
+ kind: z.ZodLiteral<"data">;
207
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
208
+ }, z.core.$strip>]>>;
209
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
210
+ extensions: z.ZodOptional<z.ZodArray<z.ZodString>>;
211
+ referenceTaskIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
212
+ messageId: z.ZodString;
213
+ taskId: z.ZodOptional<z.ZodString>;
214
+ contextId: z.ZodOptional<z.ZodString>;
215
+ kind: z.ZodLiteral<"message">;
216
+ }, z.core.$strip>>;
217
+ timestamp: z.ZodOptional<z.ZodISODateTime>;
218
+ }, z.core.$strip>;
219
+ final: z.ZodBoolean;
220
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
221
+ }, z.core.$strip>, z.ZodObject<{
222
+ taskId: z.ZodString;
223
+ contextId: z.ZodString;
224
+ kind: z.ZodLiteral<"artifact-update">;
225
+ artifact: z.ZodObject<{
226
+ artifactId: z.ZodString;
227
+ name: z.ZodOptional<z.ZodString>;
228
+ description: z.ZodOptional<z.ZodString>;
229
+ parts: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
230
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
231
+ kind: z.ZodLiteral<"text">;
232
+ text: z.ZodString;
233
+ }, z.core.$strip>, z.ZodObject<{
234
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
235
+ kind: z.ZodLiteral<"file">;
236
+ file: z.ZodUnion<readonly [z.ZodObject<{
237
+ name: z.ZodOptional<z.ZodString>;
238
+ mimeType: z.ZodOptional<z.ZodString>;
239
+ bytes: z.ZodString;
240
+ uri: z.ZodOptional<z.ZodNever>;
241
+ }, z.core.$strip>, z.ZodObject<{
242
+ name: z.ZodOptional<z.ZodString>;
243
+ mimeType: z.ZodOptional<z.ZodString>;
244
+ uri: z.ZodString;
245
+ bytes: z.ZodOptional<z.ZodNever>;
246
+ }, z.core.$strip>]>;
247
+ }, z.core.$strip>, z.ZodObject<{
248
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
249
+ kind: z.ZodLiteral<"data">;
250
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
251
+ }, z.core.$strip>]>>;
252
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
253
+ extension: z.ZodOptional<z.ZodArray<z.ZodString>>;
254
+ }, z.core.$strip>;
255
+ append: z.ZodOptional<z.ZodBoolean>;
256
+ lastChunk: z.ZodOptional<z.ZodBoolean>;
257
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
258
+ }, z.core.$strip>]>;
259
+ export type Update = z.infer<typeof UpdateSchema>;
260
+ export type Engine = (context: Context) => AsyncGenerator<Update, void, unknown>;
261
+ export interface BaseContext extends core.Context<Task> {
262
+ readonly service: Service;
263
+ readonly publisher: EventPublisher;
264
+ }
265
+ export interface Context extends BaseContext {
266
+ readonly taskId: string;
267
+ readonly userMessage: Message;
268
+ readonly messages: MessageConsumerProxy;
269
+ extensions?: AgentExtension[];
270
+ references?: Task[];
271
+ getTask: () => Promise<Task>;
272
+ }
273
+ export type ContextParams = Omit<BaseContext, "publisher" | "isCancelled" | "getState" | "abortSignal"> & Omit<Partial<Context>, "userMessage"> & {
274
+ messenger: MessageConsumerProxy;
275
+ task?: Task;
276
+ overrides?: Partial<Omit<EventConsumer, "contextId">>;
277
+ abortSignal?: AbortSignal;
278
+ };
279
+ export interface Contexts extends core.Contexts<Context> {
280
+ create: (params: ContextParams) => Promise<Context>;
281
+ list: () => Promise<Context[]>;
282
+ }
283
+ export interface Tasks extends core.Manager<Task> {
284
+ update: (context: Context, update: Update) => Promise<Task>;
285
+ create: (params: Partial<Task>) => Promise<Task>;
286
+ has: (id: string) => Promise<boolean>;
287
+ }
288
+ export interface Cancellations extends Omit<core.Manager<void>, "get"> {
289
+ has: (id: string) => Promise<boolean>;
290
+ }
291
+ export interface Connections extends Omit<core.Manager<void>, "get"> {
292
+ }
293
+ export interface ServiceOptions {
294
+ abortSignal?: AbortSignal;
295
+ }
296
+ export interface RequestHandler {
297
+ getTask: (input: TaskQueryParams, context?: Context, options?: ServiceOptions) => Promise<Task>;
298
+ cancelTask: (input: TaskIdParams, context?: Context, options?: ServiceOptions) => Promise<Task>;
299
+ sendMessage: (message: MessageSendParams, context?: Context, options?: ServiceOptions) => Promise<SendMessageSuccessResult>;
300
+ streamMessage: (message: MessageSendParams, context?: Context, options?: ServiceOptions) => AsyncGenerator<Update>;
301
+ resubscribe: (input: TaskIdParams, context?: Context, options?: ServiceOptions) => AsyncGenerator<Update>;
302
+ getAgentCard: () => Promise<AgentCard>;
303
+ }
304
+ export interface ExtendedHandler extends RequestHandler {
305
+ getAuthenticatedExtendedCard: () => Promise<AgentCard>;
306
+ }
307
+ export interface Stream {
308
+ readonly contextId: string;
309
+ isAlive: boolean;
310
+ kill: () => Promise<void>;
311
+ updates: Update[];
312
+ context: Context;
313
+ run: (params: {
314
+ service: Service;
315
+ }) => AsyncGenerator<Update>;
316
+ subscribe: () => AsyncGenerator<Update>;
317
+ }
318
+ export interface Streams extends Omit<core.Manager<Stream>, "set"> {
319
+ create: (params: core.Optional<Stream> & {
320
+ context: Context;
321
+ }) => Promise<Stream>;
322
+ has: (id: string) => Promise<boolean>;
323
+ }
324
+ export interface Service extends core.Service<{
325
+ engine: Engine;
326
+ context: Context;
327
+ }>, RequestHandler {
328
+ readonly events?: Events;
329
+ readonly connections: Connections;
330
+ readonly cancellations: Cancellations;
331
+ readonly tasks: Tasks;
332
+ readonly contexts: Contexts;
333
+ readonly streams: Streams;
334
+ engine: Engine;
335
+ agentCard: AgentCard;
336
+ }
337
+ export interface MessageProducer {
338
+ isOpen: boolean;
339
+ send: (message: MessageSendParams) => Promise<void>;
340
+ }
341
+ export type MessageMap = {
342
+ message: [MessageSendParams];
343
+ close: [];
344
+ };
345
+ export interface MessageConsumer extends core.Consumer<MessageSendParams, MessageMap> {
346
+ message: MessageSendParams;
347
+ messages: MessageSendParams[];
348
+ close: () => Promise<void>;
349
+ next: () => Promise<IteratorResult<MessageSendParams>>;
350
+ return: (value: MessageSendParams) => Promise<IteratorResult<MessageSendParams>>;
351
+ }
352
+ export type MessageConsumerProxy = MessageConsumer & MessageSendParams;
353
+ export interface EventConsumer {
354
+ readonly contextId: string;
355
+ readonly onStart?: (context: Context) => Promise<Task>;
356
+ readonly onCancel: (update: Update, current: Task) => Promise<void>;
357
+ readonly onUpdate: (update: Update, current: Task) => Promise<Task>;
358
+ readonly onError: (error: any, current: Task) => Promise<void>;
359
+ onComplete: (current: Task) => Promise<void>;
360
+ }
361
+ export type Emissions = {
362
+ start: [MessageSendParams, Task];
363
+ cancel: [Update];
364
+ update: [Task, Update];
365
+ error: [any, Task];
366
+ complete: [Task];
367
+ };
368
+ export interface EventPublisher extends Omit<EventConsumer, "onComplete" | "onCancel" | "onError" | "onUpdate">, core.Publisher<Emissions> {
369
+ readonly onStart?: (context: Context) => Promise<Task>;
370
+ readonly onCancel: (update: Update) => Promise<void>;
371
+ readonly onUpdate: (update: Update) => Promise<Task>;
372
+ readonly onError: (error: any) => Promise<void>;
373
+ onComplete: () => Promise<void>;
374
+ }
375
+ export interface Events extends core.Manager<EventPublisher> {
376
+ create: (params: core.Optional<EventPublisher>) => Promise<EventPublisher>;
377
+ }
378
+ export * from "@artinet/types/a2a";
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ //lets stay really granular with the imports
6
+ import { TaskArtifactUpdateEventSchema, MessageSchema, TaskSchema, TaskStatusUpdateEventSchema, } from "@artinet/types/a2a";
7
+ import { z } from "zod/v4";
8
+ export const UpdateSchema = z.discriminatedUnion("kind", [
9
+ MessageSchema,
10
+ TaskSchema,
11
+ TaskStatusUpdateEventSchema,
12
+ TaskArtifactUpdateEventSchema,
13
+ ]);
14
+ export * from "@artinet/types/a2a";
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { MessageSendParams, DataPart, FilePart, TextPart } from "@artinet/types/a2a";
6
+ import { Context } from "./a2a.js";
7
+ /**
8
+ * Restricting to command for now, but could be extended to other types of commands in the future.
9
+ * When we shift to CoreCommand, move this into core.
10
+ */
11
+ export interface StepArgs {
12
+ message: MessageSendParams;
13
+ context: Context;
14
+ skip: () => Promise<void> | void;
15
+ }
16
+ export type BaseArgs = Record<string, unknown>;
17
+ export type EmptyArgs = Record<string, never>;
18
+ export type StepParams<TInboundArgs extends BaseArgs = EmptyArgs> = StepArgs & Partial<{
19
+ content: string;
20
+ args: TInboundArgs;
21
+ }>;
22
+ export type PartContent = DataPart["data"] | FilePart["file"] | TextPart["text"];
23
+ export type StepOutput<TPart extends PartContent> = {
24
+ parts: Array<TPart> | TPart;
25
+ };
26
+ export type StepOutputWithForwardArgs<TPart extends PartContent, TForwardArgs extends BaseArgs = EmptyArgs> = StepOutput<TPart> & {
27
+ args: TForwardArgs;
28
+ };
29
+ export type OutputType<TPart extends PartContent, TForwardArgs extends BaseArgs = EmptyArgs> = StepOutput<TPart> | StepOutputWithForwardArgs<TPart, TForwardArgs> | Array<TPart> | TPart;
30
+ export type Step<TPart extends PartContent = TextPart["text"], TInboundArgs extends BaseArgs = EmptyArgs, TForwardArgs extends BaseArgs = EmptyArgs, TOutput extends OutputType<TPart, TForwardArgs> = OutputType<TPart, TForwardArgs>> = (params: StepParams<TInboundArgs>) => Promise<TOutput> | TOutput;
31
+ export type StepWithKind<TPart extends PartContent = TextPart["text"], TInboundArgs extends BaseArgs = EmptyArgs, TForwardArgs extends BaseArgs = EmptyArgs, TOutput extends OutputType<TPart, TForwardArgs> = OutputType<TPart, TForwardArgs>, TKind extends "text" | "file" | "data" = "text"> = {
32
+ step: Step<TPart, TInboundArgs, TForwardArgs, TOutput>;
33
+ kind: TKind;
34
+ };
35
+ export type OutArgsOf<O> = O extends StepOutputWithForwardArgs<any, infer A> ? A : EmptyArgs;
36
+ export interface StepBuilder<TInboundArgs extends BaseArgs = EmptyArgs> {
37
+ /**
38
+ * Add a step to the builder.
39
+ * @param step - The step to add.
40
+ * @returns A new builder with the step added.
41
+ */
42
+ addStep<TPart extends PartContent = TextPart["text"], TForwardArgs extends BaseArgs = EmptyArgs, TOutput extends OutputType<TPart, TForwardArgs> = OutputType<TPart, TForwardArgs>, TKind extends "text" | "file" | "data" = "text">(step: StepWithKind<TPart, TInboundArgs, TForwardArgs, TOutput, TKind>): StepBuilder<OutArgsOf<TOutput>>;
43
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./builder.js";
2
+ export * as A2A from "./a2a.js";
3
+ export type { Engine as AgentEngine } from "./a2a.js";
@@ -0,0 +1,2 @@
1
+ export * from "./builder.js";
2
+ export * as A2A from "./a2a.js";
@@ -2,9 +2,7 @@
2
2
  * Copyright 2025 The Artinet Project
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { TaskPushNotificationConfig, TaskIdParams, Task } from "../schemas/a2a/index.js";
6
- import type { AgentCard, TaskQueryParams, MessageSendParams, Message } from "../schemas/a2a/index.js";
7
- import { UpdateEvent } from "./services/a2a/index.js";
5
+ import { A2A } from "./a2a/index.js";
8
6
  /**
9
7
  * @interface Client
10
8
  * @description Defines the standard contract for an A2A (Agent-to-Agent) client implementation.
@@ -19,24 +17,24 @@ export interface Client {
19
17
  * The AgentCard contains essential information about the agent, such as its capabilities and endpoints.
20
18
  * @param {string} wellKnownPath The standard path (e.g., "/.well-known/a2a") to look for the AgentCard.
21
19
  * @param {string} fallbackPath An alternative path to check if the well-known path fails.
22
- * @returns {Promise<AgentCard>} A promise that resolves with the AgentCard object.
20
+ * @returns {Promise<A2A.AgentCard>} A promise that resolves with the AgentCard object.
23
21
  * @async
24
22
  */
25
- agentCard(): Promise<AgentCard>;
23
+ agentCard(): Promise<A2A.AgentCard>;
26
24
  /**
27
25
  * @description Refreshes the cached AgentCard information by re-fetching it from the server.
28
26
  * Useful when the agent's capabilities or configuration might have changed.
29
- * @returns {Promise<AgentCard>} A promise that resolves with the updated AgentCard object.
27
+ * @returns {Promise<A2A.AgentCard>} A promise that resolves with the updated AgentCard object.
30
28
  * @async
31
29
  */
32
- refreshAgentCard(): Promise<AgentCard>;
30
+ refreshAgentCard(): Promise<A2A.AgentCard>;
33
31
  /**
34
32
  * @description Sends a task request to the agent server.
35
- * @param {MessageSendParams} params Parameters required to send the task, including the task definition and metadata.
36
- * @returns {Promise<Task | null>} A promise that resolves with the initial Task object representing the submitted task, or null if the submission failed.
33
+ * @param {A2A.MessageSendParams} params Parameters required to send the task, including the task definition and metadata.
34
+ * @returns {Promise<A2A.Task | null>} A promise that resolves with the initial Task object representing the submitted task, or null if the submission failed.
37
35
  * @async
38
36
  */
39
- sendMessage(params: MessageSendParams): Promise<Message | Task | null>;
37
+ sendMessage(params: A2A.MessageSendParams): Promise<A2A.Message | A2A.Task | null>;
40
38
  /**
41
39
  * @deprecated Will be removed in v6.Use sendMessage instead.
42
40
  * @description Sends a task request to the agent server.
@@ -44,7 +42,7 @@ export interface Client {
44
42
  * @returns {Promise<Task | null>} A promise that resolves with the initial Task object representing the submitted task, or null if the submission failed.
45
43
  * @async
46
44
  */
47
- sendTask(params: MessageSendParams): Promise<Message | Task | null>;
45
+ sendTask(params: A2A.MessageSendParams): Promise<A2A.Message | A2A.Task | null>;
48
46
  /**
49
47
  * @description Sends a task request and subscribes to real-time updates (status changes, artifact updates) for that task.
50
48
  * This uses a streaming connection if available.
@@ -52,7 +50,7 @@ export interface Client {
52
50
  * @returns {AsyncIterable<UpdateEvent>} An async iterable that yields task status and artifact updates.
53
51
  * @async
54
52
  */
55
- sendStreamingMessage(params: MessageSendParams): AsyncIterable<UpdateEvent>;
53
+ sendStreamingMessage(params: A2A.MessageSendParams): AsyncIterable<A2A.Update>;
56
54
  /**
57
55
  * @deprecated Will be removed in v6Use sendStreamingMessage instead.
58
56
  * @description Sends a task request and subscribes to real-time updates (status changes, artifact updates) for that task.
@@ -61,45 +59,45 @@ export interface Client {
61
59
  * @returns {AsyncIterable<UpdateEvent>} An async iterable that yields task status and artifact updates.
62
60
  * @async
63
61
  */
64
- sendTaskSubscribe(params: MessageSendParams): AsyncIterable<UpdateEvent>;
62
+ sendTaskSubscribe(params: A2A.MessageSendParams): AsyncIterable<A2A.Update>;
65
63
  /**
66
64
  * @description Retrieves the current state of a specific task by its ID.
67
- * @param {TaskQueryParams} params Parameters containing the task ID to query.
68
- * @returns {Promise<Task | null>} A promise that resolves with the Task object, or null if the task is not found.
65
+ * @param {A2A.TaskQueryParams} params Parameters containing the task ID to query.
66
+ * @returns {Promise<A2A.Task | null>} A promise that resolves with the Task object, or null if the task is not found.
69
67
  * @async
70
68
  */
71
- getTask(params: TaskQueryParams): Promise<Task | null>;
69
+ getTask(params: A2A.TaskQueryParams): Promise<A2A.Task | null>;
72
70
  /**
73
71
  * @description Sends a request to cancel an ongoing task.
74
- * @param {TaskIdParams} params Parameters containing the ID of the task to cancel.
75
- * @returns {Promise<Task | null>} A promise that resolves with the final state of the cancelled Task object, or null if cancellation failed or the task wasn't found.
72
+ * @param {A2A.TaskIdParams} params Parameters containing the ID of the task to cancel.
73
+ * @returns {Promise<A2A.Task | null>} A promise that resolves with the final state of the cancelled Task object, or null if cancellation failed or the task wasn't found.
76
74
  * @async
77
75
  */
78
- cancelTask(params: TaskIdParams): Promise<Task | null>;
76
+ cancelTask(params: A2A.TaskIdParams): Promise<A2A.Task | null>;
79
77
  /**
80
78
  * @description Configures push notifications for a specific task. This allows the client
81
79
  * to receive updates asynchronously via a specified webhook URL.
82
80
  * Requires the agent to support the 'pushNotifications' capability.
83
- * @param {TaskPushNotificationConfig} params The configuration details for the push notification, including the task ID and webhook URL.
84
- * @returns {Promise<TaskPushNotificationConfig | null>} A promise that resolves with the applied configuration, or null if the configuration failed.
81
+ * @param {A2A.TaskPushNotificationConfig} params The configuration details for the push notification, including the task ID and webhook URL.
82
+ * @returns {Promise<A2A.TaskPushNotificationConfig | null>} A promise that resolves with the applied configuration, or null if the configuration failed.
85
83
  * @async
86
84
  */
87
- setTaskPushNotification(params: TaskPushNotificationConfig): Promise<TaskPushNotificationConfig | null>;
85
+ setTaskPushNotification(params: A2A.TaskPushNotificationConfig): Promise<A2A.TaskPushNotificationConfig | null>;
88
86
  /**
89
87
  * @description Retrieves the current push notification configuration for a specific task.
90
- * @param {TaskIdParams} params Parameters containing the task ID.
91
- * @returns {Promise<TaskPushNotificationConfig | null>} A promise that resolves with the push notification configuration, or null if not configured or not found.
88
+ * @param {A2A.TaskIdParams} params Parameters containing the task ID.
89
+ * @returns {Promise<A2A.TaskPushNotificationConfig | null>} A promise that resolves with the push notification configuration, or null if not configured or not found.
92
90
  * @async
93
91
  */
94
- getTaskPushNotification(params: TaskIdParams): Promise<TaskPushNotificationConfig | null>;
92
+ getTaskPushNotification(params: A2A.TaskIdParams): Promise<A2A.TaskPushNotificationConfig | null>;
95
93
  /**
96
94
  * @description Resubscribes to updates for an existing task, potentially after a connection drop or client restart.
97
95
  * This allows resuming the stream of status and artifact updates.
98
- * @param {TaskQueryParams} params Parameters containing the task ID to resubscribe to.
96
+ * @param {A2A.TaskQueryParams} params Parameters containing the task ID to resubscribe to.
99
97
  * @returns {AsyncIterable<UpdateEvent>} An async iterable that yields task status and artifact updates.
100
98
  * @async
101
99
  */
102
- resubscribeTask(params: TaskQueryParams): AsyncIterable<UpdateEvent>;
100
+ resubscribeTask(params: A2A.TaskQueryParams): AsyncIterable<A2A.Update>;
103
101
  /**
104
102
  * @description Checks if the agent server supports a specific capability.
105
103
  * @param {"streaming" | "pushNotifications" | "stateTransitionHistory"} capability The capability to check for.