@artinet/sdk 0.6.0-preview.3 → 0.6.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 (153) hide show
  1. package/README.md +100 -50
  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 +5 -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 +280 -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 +4 -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/task-builder.js +5 -1
  35. package/dist/index.d.ts +3 -3
  36. package/dist/index.js +3 -3
  37. package/dist/messenger/index.d.ts +1 -0
  38. package/dist/messenger/index.js +1 -0
  39. package/dist/messenger/messenger.d.ts +119 -0
  40. package/dist/messenger/messenger.js +288 -0
  41. package/dist/server/adapters/a2a_request_handler.d.ts +889 -0
  42. package/dist/server/adapters/a2a_request_handler.js +241 -0
  43. package/dist/server/adapters/loadable.d.ts +7 -0
  44. package/dist/server/adapters/loadable.js +73 -0
  45. package/dist/server/adapters/notifications.d.ts +26 -0
  46. package/dist/server/adapters/notifications.js +77 -0
  47. package/dist/server/express/server.d.ts +11 -19
  48. package/dist/server/express/server.js +29 -64
  49. package/dist/server/express/utils.d.ts +14 -0
  50. package/dist/server/express/{errors.js → utils.js} +22 -0
  51. package/dist/server/index.d.ts +4 -1
  52. package/dist/server/index.js +4 -1
  53. package/dist/server/params.d.ts +115 -0
  54. package/dist/server/params.js +21 -0
  55. package/dist/services/a2a/factory/context.d.ts +2 -1
  56. package/dist/services/a2a/factory/context.js +4 -3
  57. package/dist/services/a2a/factory/handler.d.ts +1 -1
  58. package/dist/services/a2a/factory/handler.js +7 -6
  59. package/dist/services/a2a/factory/service.d.ts +1 -1
  60. package/dist/services/a2a/factory/service.js +2 -2
  61. package/dist/services/a2a/factory/state-machine.js +9 -6
  62. package/dist/services/a2a/handlers/cancel-task.d.ts +1 -1
  63. package/dist/services/a2a/handlers/get-task.d.ts +1 -1
  64. package/dist/services/a2a/handlers/resubscribe-task.d.ts +2 -2
  65. package/dist/services/a2a/handlers/send-message.d.ts +1 -1
  66. package/dist/services/a2a/handlers/stream-message.d.ts +2 -2
  67. package/dist/services/a2a/handlers/update.js +2 -2
  68. package/dist/services/a2a/index.d.ts +0 -1
  69. package/dist/services/a2a/index.js +0 -1
  70. package/dist/services/a2a/managers.js +2 -1
  71. package/dist/services/a2a/messenger.d.ts +1 -1
  72. package/dist/services/a2a/messenger.js +1 -1
  73. package/dist/services/a2a/service.d.ts +26 -21
  74. package/dist/services/a2a/service.js +163 -95
  75. package/dist/services/a2a/state-machine.d.ts +1 -1
  76. package/dist/services/a2a/state-machine.js +2 -1
  77. package/dist/services/a2a/streams.js +1 -1
  78. package/dist/services/core/manager.d.ts +5 -0
  79. package/dist/services/core/manager.js +6 -0
  80. package/dist/services/mcp/service.js +1 -1
  81. package/dist/{utils/storage → storage}/file.d.ts +4 -2
  82. package/dist/{utils/storage → storage}/file.js +5 -4
  83. package/dist/storage/index.d.ts +1 -0
  84. package/dist/storage/index.js +2 -0
  85. package/dist/storage/sqlite.d.ts +353 -0
  86. package/dist/storage/sqlite.js +85 -0
  87. package/dist/transport/trpc/a2a/factory/router.d.ts +16 -16
  88. package/dist/transport/trpc/a2a/routes/info.d.ts +2 -2
  89. package/dist/transport/trpc/a2a/routes/message/route.d.ts +3 -3
  90. package/dist/transport/trpc/a2a/routes/message/route.js +2 -2
  91. package/dist/transport/trpc/a2a/routes/tasks/route.d.ts +4 -4
  92. package/dist/transport/trpc/a2a/routes/tasks/route.js +3 -3
  93. package/dist/types/a2a/a2a.d.ts +38 -20
  94. package/dist/types/a2a/a2a.js +0 -1
  95. package/dist/types/core/core.d.ts +4 -2
  96. package/dist/types/index.d.ts +0 -1
  97. package/dist/types/index.js +0 -1
  98. package/dist/types/storage.d.ts +2 -14
  99. package/dist/types/storage.js +0 -4
  100. package/dist/utils/{common/constants.d.ts → constants.d.ts} +1 -1
  101. package/dist/{browser/utils/common → utils}/constants.js +1 -1
  102. package/dist/utils/{common/errors.d.ts → errors.d.ts} +17 -36
  103. package/dist/utils/errors.js +80 -0
  104. package/dist/utils/index.d.ts +6 -10
  105. package/dist/utils/index.js +6 -10
  106. package/dist/utils/parse.d.ts +7 -0
  107. package/dist/utils/parse.js +17 -0
  108. package/dist/utils/schema-validation.d.ts +2 -0
  109. package/dist/utils/schema-validation.js +12 -0
  110. package/package.json +35 -22
  111. package/dist/browser/client/a2a-client.d.ts +0 -127
  112. package/dist/browser/client/a2a-client.js +0 -233
  113. package/dist/browser/client/index.d.ts +0 -1
  114. package/dist/browser/client/index.js +0 -1
  115. package/dist/browser/transport/rpc/parser.d.ts +0 -15
  116. package/dist/browser/transport/rpc/parser.js +0 -49
  117. package/dist/browser/transport/rpc/rpc-client.d.ts +0 -80
  118. package/dist/browser/transport/rpc/rpc-client.js +0 -189
  119. package/dist/browser/transport/streaming/event-stream.d.ts +0 -25
  120. package/dist/browser/transport/streaming/event-stream.js +0 -100
  121. package/dist/browser/types/client.d.ts +0 -133
  122. package/dist/browser/types/client.js +0 -5
  123. package/dist/browser/utils/common/errors.js +0 -95
  124. package/dist/client/a2a-client.d.ts +0 -127
  125. package/dist/client/a2a-client.js +0 -237
  126. package/dist/client/index.d.ts +0 -1
  127. package/dist/client/index.js +0 -1
  128. package/dist/server/express/errors.d.ts +0 -9
  129. package/dist/server/express/index.d.ts +0 -3
  130. package/dist/server/express/index.js +0 -3
  131. package/dist/server/express/middeware.d.ts +0 -7
  132. package/dist/server/express/middeware.js +0 -121
  133. package/dist/transport/index.d.ts +0 -3
  134. package/dist/transport/index.js +0 -4
  135. package/dist/transport/rpc/parser.d.ts +0 -15
  136. package/dist/transport/rpc/parser.js +0 -49
  137. package/dist/transport/rpc/rpc-client.d.ts +0 -80
  138. package/dist/transport/rpc/rpc-client.js +0 -189
  139. package/dist/transport/streaming/event-stream.d.ts +0 -25
  140. package/dist/transport/streaming/event-stream.js +0 -100
  141. package/dist/types/client.d.ts +0 -133
  142. package/dist/types/client.js +0 -5
  143. package/dist/utils/common/errors.js +0 -98
  144. /package/dist/{utils/common → browser/utils}/parse.d.ts +0 -0
  145. /package/dist/{utils/common → browser/utils}/schema-validation.d.ts +0 -0
  146. /package/dist/browser/utils/{common/utils.d.ts → utils.d.ts} +0 -0
  147. /package/dist/browser/utils/{common/utils.js → utils.js} +0 -0
  148. /package/dist/utils/{common/utils.d.ts → utils.d.ts} +0 -0
  149. /package/dist/utils/{common/utils.js → utils.js} +0 -0
  150. /package/dist/utils/{common/zAsyncIterable-v3.d.ts → zAsyncIterable-v3.d.ts} +0 -0
  151. /package/dist/utils/{common/zAsyncIterable-v3.js → zAsyncIterable-v3.js} +0 -0
  152. /package/dist/utils/{common/zAsyncIterable.d.ts → zAsyncIterable.d.ts} +0 -0
  153. /package/dist/utils/{common/zAsyncIterable.js → zAsyncIterable.js} +0 -0
package/README.md CHANGED
@@ -1,23 +1,34 @@
1
- [![Website](https://img.shields.io/badge/website-artinet.io-black)](https://artinet.io/)
2
- [![npm version](https://img.shields.io/npm/v/@artinet/sdk.svg?logoColor=black)](https://www.npmjs.com/package/@artinet/sdk)
3
- [![npm downloads](https://img.shields.io/npm/dt/@artinet/sdk.svg)](https://www.npmjs.com/package/@artinet/sdk)
4
- [![Apache License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
5
- [![Known Vulnerabilities](https://snyk.io/test/npm/@artinet/sdk/badge.svg)](https://snyk.io/test/npm/@artinet/sdk)
6
- [![GitHub stars](https://img.shields.io/github/stars/the-artinet-project/artinet-sdk?style=social)](https://github.com/the-artinet-project/artinet-sdk/stargazers)
7
- [![Discord](https://dcbadge.limes.pink/api/server/DaxzSchmmX?style=flat)](https://discord.gg/DaxzSchmmX)
8
-
9
- # artinet-sdk
1
+ <p align="center">
2
+ <a href="https://artinet.io"><img src="https://img.shields.io/badge/website-artinet.io-black" alt="Website"></a>
3
+ <a href="https://www.npmjs.com/package/@artinet/sdk"><img src="https://img.shields.io/npm/v/@artinet/sdk?color=black" alt="Version"></a>
4
+ <a href="https://www.npmjs.com/package/@artinet/sdk"><img src="https://img.shields.io/npm/dt/@artinet/sdk?color=black" alt="Downloads"></a>
5
+ <a><img src="https://img.shields.io/badge/License-Apache_2.0-black.svg" alt="License"></a>
6
+ <a href="https://reddit.com/r/theartinet"><img src="https://img.shields.io/reddit/subreddit-subscribers/theartinet?label=reddit&style=flat&color=black" alt="Subreddit"></a>
7
+ <a><img src="https://img.shields.io/github/stars/the-artinet-project/artinet-sdk?style=social&color=black" alt="Github"></a>
8
+ <a href="https://snyk.io/test/npm/@artinet/sdk"><img src="https://snyk.io/test/npm/@artinet/sdk/badge.svg" alt="Known Vulnerabilities"></a>
9
+ </p>
10
+
11
+ <h1 align="center"><em>artinet-sdk</em></h1>
10
12
 
11
13
  Create agents that communicate across frameworks.
12
14
 
13
- The artinet-sdk is a TypeScript library that adds a standardized, interoperable communication layer to your agents using the [Agent2Agent (A2A) Protocol](https://github.com/google-a2a/A2A).
15
+ The <em><u>@artinet/sdk</u></em> is a universal, robust and production ready <code>AgentExecutor</code> library that adds a standardized, interoperable communication layer to any agent.
16
+
17
+ > Runs on the <a href="https://github.com/google-a2a/A2A">Agent2Agent (A2A) Protocol</a> from the <a href="https://aaif.io/">Agentic AI Foundation</a>.
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install @artinet/sdk express @a2a-js/sdk @modelcontextprotocol/sdk
23
+ ```
14
24
 
15
25
  ## Features
16
26
 
17
- - **Hassle Free:** Use the AgentBuilder to quickly setup an AgentServer.
18
- - **No Vendor Lock-In:** Let your agents communicate with other agents across frameworks and ecosystems.
27
+ - **Hassle Free:** Use [**`cr8`**](./docs/create.md) to quickly spin-up an A2A compatible agent.
28
+ - **No Vendor Lock-In:** Let your agents communicate with other agents no matter the framework and across ecosystems.
19
29
  - **Flexible Design:** Everything you need to build collaborative agents while remaining modular enough for advanced configuration.
20
- - **Pluggable Observability:** Bring your own logger (Pino, Winston) and tracer (OpenTelemetry) with zero-config defaults.
30
+ - **Pluggable Observability:** Bring your own logger ([Pino](https://www.npmjs.com/package/pino), [Winston](https://www.npmjs.com/package/winston)) and/or tracer ([OpenTelemetry](https://www.npmjs.com/package/@opentelemetry/sdk-node)).
31
+ - **Persistent Storage:** Roll your own `Task` storage or use our built-in [`SQLiteStore`](./docs/storage.md#sqlite-store) (backed by [`drizzle-orm`](https://www.npmjs.com/package/drizzle-orm)).
21
32
 
22
33
  ## Quick Start
23
34
 
@@ -27,9 +38,9 @@ The artinet-sdk is a TypeScript library that adds a standardized, interoperable
27
38
  npx @artinet/create-agent@latest
28
39
  ```
29
40
 
30
- It has [several template projects](https://github.com/the-artinet-project/create-agent/tree/main/templates) to jump right into agent building.
41
+ It has [several template projects](https://github.com/the-artinet-project/artinet/tree/main/create-agent) to jump right into agent building.
31
42
 
32
- **Or use [`easy-a2a`](https://github.com/the-artinet-project/easy-a2a):**
43
+ **Or use [`easy-a2a`](https://github.com/the-artinet-project/artinet/tree/main/easy):**
33
44
 
34
45
  ```typescript
35
46
  const agent = a2a({
@@ -46,63 +57,99 @@ const agent = a2a({
46
57
  npm install easy-a2a
47
58
  ```
48
59
 
49
- ## Installation
60
+ ## Examples
50
61
 
51
- ```bash
52
- npm install @artinet/sdk
53
- ```
62
+ **Create an A2A Server**
54
63
 
55
- **Peer dependencies (required):**
64
+ Turn your agent into an express server so it can receive messages from anywhere:
56
65
 
57
- ```bash
58
- npm install @a2a-js/sdk @modelcontextprotocol/sdk @trpc/server
66
+ ```typescript
67
+ import { cr8 } from "@artinet/sdk";
68
+
69
+ cr8("QuickStart Agent")
70
+ .text(async ({ content }) => `The user said: ${content}`)
71
+ //starts an express a2a server on port 3000
72
+ .server.start(3000);
59
73
  ```
60
74
 
61
- ## Requirements
75
+ - _ensure that the url/path of your AgentCard matches the server._
62
76
 
63
- - [Node.js](https://nodejs.org/en/download) 18.9.1 (Recommended: 20 or ≥ 22)
77
+ > 🚧 Coming Soon: Support for Hono.
64
78
 
65
- ## Example
79
+ **No Servers Needed**
66
80
 
67
- **Server:**
81
+ Embed agents directly into your app:
68
82
 
69
83
  ```typescript
70
- import { cr8 } from "@artinet/sdk";
84
+ import { cr8, A2A } from "@artinet/sdk";
71
85
 
72
- const { app } = cr8("QuickStart Agent")
73
- .text(async ({ content }) => {
74
- return `You said: ${content}`;
75
- }) //start an a2a server on port 3000
76
- .server.start(3000);
86
+ const agent = cr8("Local Agent").text(
87
+ ({ content }) => `The user said: ${content}`
88
+ ).agent;
89
+
90
+ const response: A2A.Task | A2A.Message = await agent.sendMessage("Hello");
77
91
  ```
78
92
 
79
- **Client:**
93
+ - _See [**`cr8`**](./docs/create.md) for more information_
94
+
95
+ **Connect to Remote Agents**
96
+
97
+ [`AgentMessenger`](./docs/messenger.md#agentmessenger) provides a streamlined `Client` interface for communicating with remote A2A Servers:
80
98
 
81
99
  ```typescript
82
- import { A2AClient } from "@artinet/sdk";
100
+ import { AgentMessenger, createMessenger } from "@artinet/sdk";
83
101
 
84
- const client = new A2AClient("http://localhost:3000/a2a");
102
+ const messenger: AgentMessenger = await createMessenger({
103
+ baseUrl: "http://localhost:3000/a2a",
104
+ headers: {
105
+ Bearer: "xxxx",
106
+ },
107
+ });
85
108
 
86
- const stream = client.sendStreamingMessage("Hello World!");
109
+ const stream = messenger.sendMessageStream("Hello World!");
87
110
 
88
111
  for await (const update of stream) {
89
112
  console.log(update);
90
113
  }
91
114
  ```
92
115
 
116
+ - _See [**messenger**](./docs/messenger.md#agentmessenger) for more information._
117
+
118
+ **Simple Multi-Agent Orchestration**
119
+
120
+ [**`cr8`**](./docs/create.md#agent-orchestration) provides easy to use tools for orchestrating multiple agents:
121
+
122
+ ```typescript
123
+ import { cr8 } from "@artinet/sdk";
124
+ import { localAgent } from "./local.ts";
125
+ import { remoteAgentMessenger as remoteAgent } from "./remote.ts";
126
+
127
+ const orchestrator = cr8("Director")
128
+ .text("Request Received")
129
+ .sendMessage({ agent: localAgent, message: "initiate billing" })
130
+ .text("Billing Started")
131
+ .sendMessage({ agent: remoteAgent, message: "Retrieve Secrets" }).agent;
132
+ ```
133
+
134
+ > _For more robust multi-agent support, checkout [**orc8**](https://github.com/the-artinet-project/artinet), our dynamic agent orchestration library that can be used with any openai compatible API._
135
+
93
136
  ## Documentation
94
137
 
95
- | Topic | Description |
96
- | ------------------------------------------- | ----------------------------------------------------- |
97
- | [**API Reference**](docs/api-reference.md) | Complete reference of SDK objects, types, and methods |
98
- | [**Configuration**](docs/configuration.md) | Logging (Pino, Winston) and OpenTelemetry setup |
99
- | [**Client Usage**](docs/client.md) | A2AClient methods, streaming, browser support |
100
- | [**Server Implementation**](docs/server.md) | AgentBuilder, AgentEngine, and AgentCard |
101
- | [**Event Handling**](docs/events.md) | Event subscriptions and custom handlers |
102
- | [**Storage**](docs/storage.md) | FileStore and custom storage backends |
103
- | [**Customization**](docs/customization.md) | Middleware, tRPC, custom transports |
104
- | [**MCP Integration**](docs/mcp.md) | Model Context Protocol compatibility |
105
- | [**Migration Guide**](docs/migration.md) | Upgrading from v0.5.x to v0.6.0 |
138
+ | Topic | Description |
139
+ | ------------------------------------------ | ----------------------------------------------------- |
140
+ | [**Agent Creation**](docs/create.md) | Scaffolding agents with `cr8` |
141
+ | [**API Reference**](docs/api-reference.md) | Complete reference of SDK objects, types, and methods |
142
+ | [**Execution**](docs/execution.md) | Subscriptions and custom event handlers |
143
+ | [**Messenger**](docs/messenger.md) | `Messenger` methods, streaming, browser support |
144
+ | [**Storage**](docs/storage.md) | `FileStore`, `SQLiteStore`, custom storage backends |
145
+ | [**Configuration**](docs/configuration.md) | Logging (Pino, Winston) and OpenTelemetry setup |
146
+ | [**Customization**](docs/customization.md) | `native`, tRPC, and `AgentEngine`s |
147
+ | [**MCP Integration**](docs/mcp.md) | Model Context Protocol compatibility |
148
+ | [**Migration Guide**](docs/migration.md) | Upgrading from v0.5.x to v0.6.0 |
149
+
150
+ ## Requirements
151
+
152
+ - [Node.js](https://nodejs.org/en/download) ≥ 18.9.1 (Recommended: 20 or ≥ 22)
106
153
 
107
154
  ## Running Tests
108
155
 
@@ -118,8 +165,11 @@ Ensure code adheres to the project style and passes linting (`npm run lint`) and
118
165
 
119
166
  ## License
120
167
 
121
- This project is licensed under the Apache License 2.0 - see the `LICENSE` file for details.
168
+ This project is licensed under Apache License 2.0.
169
+
170
+ See the [`LICENSE`](./LICENSE) for details.
122
171
 
123
- ## Acknowledgements
172
+ ## Join the Community
124
173
 
125
- This SDK builds upon the concepts and specifications of the [Agent2Agent (A2A) Protocol](https://github.com/google-a2a/A2A).
174
+ - **Reddit:** [r/theartinet](https://www.reddit.com/r/theartinet/)
175
+ - **Discord:** [the artinet channel](https://discord.gg/DaxzSchmmX)
@@ -1,9 +1,4 @@
1
1
  export * from "./types/index.js";
2
- export * from "./client/index.js";
3
- export { executeJsonRpcRequest, executeGetRequest, createJsonRpcRequest, sendJsonRpcRequest, } from "./transport/rpc/rpc-client.js";
4
- export { executeStreamEvents } from "./transport/streaming/event-stream.js";
5
- export * from "./utils/common/constants.js";
6
- export * from "./utils/common/errors.js";
7
- export * from "./utils/common/utils.js";
2
+ export * from "./messenger/index.js";
3
+ export * from "./utils/index.js";
8
4
  export * from "./config/index.js";
9
- export { A2AClient } from "./client/a2a-client.js";
@@ -1,10 +1,5 @@
1
1
  //browser only entry point
2
2
  export * from "./types/index.js";
3
- export * from "./client/index.js";
4
- export { executeJsonRpcRequest, executeGetRequest, createJsonRpcRequest, sendJsonRpcRequest, } from "./transport/rpc/rpc-client.js";
5
- export { executeStreamEvents } from "./transport/streaming/event-stream.js";
6
- export * from "./utils/common/constants.js";
7
- export * from "./utils/common/errors.js";
8
- export * from "./utils/common/utils.js";
3
+ export * from "./messenger/index.js";
4
+ export * from "./utils/index.js";
9
5
  export * from "./config/index.js";
10
- export { A2AClient } from "./client/a2a-client.js";
@@ -2,7 +2,7 @@
2
2
  * Copyright 2025 The Artinet Project
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- /** //todo move to @artinet/sdk from core v0.1
5
+ /**
6
6
  * @fileoverview Zero-dependency observability interfaces for the Artinet ecosystem.
7
7
  *
8
8
  * Provides minimal interfaces for logging and tracing that consumers can implement
@@ -54,7 +54,7 @@ export type MessageSendParamsParams = Partial<Kindless<A2A.MessageSendParams>> |
54
54
  * @returns New {@link A2A.MessageSendParams} with default parameters
55
55
  * @defaults {
56
56
  * message: {
57
- * role: "agent",
57
+ * role: "user",
58
58
  * parts: [],
59
59
  * messageId: uuidv4(),
60
60
  * kind: "message",
@@ -7,8 +7,6 @@ import { v4 as uuidv4 } from "uuid";
7
7
  export class Message {
8
8
  constructor(params = {}) {
9
9
  const messageId = params.messageId ?? uuidv4();
10
- // TODO: Consider whether default role should be "user" when used in messageSendParams context.
11
- // Currently defaults to "agent" which may be incorrect for MessageSendParams.
12
10
  this._message = {
13
11
  ...params,
14
12
  role: params.role ?? "agent",
@@ -77,7 +75,7 @@ export const MessageSendConfigurationBuilder = MessageSendConfiguration;
77
75
  * @returns New {@link A2A.MessageSendParams} with default parameters
78
76
  * @defaults {
79
77
  * message: {
80
- * role: "agent",
78
+ * role: "user",
81
79
  * parts: [],
82
80
  * messageId: uuidv4(),
83
81
  * kind: "message",
@@ -94,11 +92,25 @@ export const MessageSendConfigurationBuilder = MessageSendConfiguration;
94
92
  * @since 0.6.0
95
93
  */
96
94
  export function messageSendParams(params) {
97
- const _isMessageParams = isMessageParams(params);
95
+ if (!isMessageParams(params)) {
96
+ return {
97
+ message: message(params.message),
98
+ configuration: new MessageSendConfiguration(params.configuration)
99
+ .configuration,
100
+ metadata: params.metadata,
101
+ };
102
+ }
103
+ if (typeof params === "string") {
104
+ return {
105
+ message: message({
106
+ role: "user",
107
+ parts: [{ text: params, kind: "text" }],
108
+ }),
109
+ };
110
+ }
111
+ params.role = params.role ?? "user";
98
112
  return {
99
- message: message(_isMessageParams ? params : params.message),
100
- configuration: new MessageSendConfiguration(_isMessageParams ? undefined : params.configuration).configuration,
101
- metadata: _isMessageParams ? undefined : params.metadata,
113
+ message: message(params),
102
114
  };
103
115
  }
104
116
  /**
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { A2A } from "../types/index.js";
6
6
  import { v4 as uuidv4 } from "uuid";
7
- import { getCurrentTimestamp } from "../utils/common/utils.js";
7
+ import { getCurrentTimestamp } from "../utils/utils.js";
8
8
  import { isMessageParams, Message,
9
9
  // type BuilderMessageParams,
10
10
  } from "./message-builder.js";
@@ -177,6 +177,10 @@ const strict_update = (params) => {
177
177
  return TaskStatusUpdateEvent.create(params);
178
178
  };
179
179
  function _buildUpdate(state, params, final) {
180
+ if (params.message) {
181
+ params.message.contextId = params.contextId;
182
+ params.message.taskId = params.taskId;
183
+ }
180
184
  return strict_update({
181
185
  taskId: params.taskId,
182
186
  contextId: params.contextId,
@@ -0,0 +1 @@
1
+ export { createMessenger, A2AClient, AgentMessenger, type MessengerParams, } from "./messenger.js";
@@ -0,0 +1 @@
1
+ export { createMessenger, A2AClient, AgentMessenger, } from "./messenger.js";
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { A2A } from "../types/index.js";
6
+ import * as describe from "../create/describe.js";
7
+ import { ClientFactoryOptions, ClientConfig, Client, Transport, RequestOptions } from "@a2a-js/sdk/client";
8
+ export interface MessengerParams {
9
+ baseUrl: URL | string;
10
+ headers?: Record<string, string>;
11
+ fallbackPath?: string;
12
+ factory?: Partial<ClientFactoryOptions>;
13
+ config?: ClientConfig;
14
+ }
15
+ /**
16
+ * Messenger is the main communication client for interacting with remote A2A-compatible services.
17
+ * It provides methods for sending messages, retrieving tasks, canceling operations, and handling streaming responses.
18
+ */
19
+ declare class Messenger implements Omit<Transport, "getAuthenticatedExtendedAgentCard" | "getExtendedAgentCard"> {
20
+ private _headers;
21
+ private _fallbackPath?;
22
+ private _baseUrl;
23
+ private _factory;
24
+ private clientPromise;
25
+ constructor(baseUrl: URL | string, _headers?: Record<string, string>, _fallbackPath?: string | undefined, factory?: ClientFactoryOptions, config?: ClientConfig);
26
+ reset(baseUrl?: URL | string, fallbackPath?: string | undefined): Promise<Client>;
27
+ get baseUrl(): string;
28
+ get headers(): Record<string, string>;
29
+ set headers(headers: Record<string, string>);
30
+ protected get _client(): Promise<Client>;
31
+ /**
32
+ * Retrieves the AgentCard from the A2A server.
33
+ * @returns A promise resolving to the AgentCard.
34
+ */
35
+ getAgentCard(requestOptions?: RequestOptions): Promise<A2A.AgentCard>;
36
+ sendMessage(params: A2A.MessageSendParams, options?: RequestOptions): Promise<A2A.SendMessageSuccessResult>;
37
+ sendMessage(params: describe.MessageParams, options?: RequestOptions): Promise<A2A.SendMessageSuccessResult>;
38
+ sendMessage(params: describe.MessageSendParamsParams, options?: RequestOptions): Promise<A2A.SendMessageSuccessResult>;
39
+ sendMessageStream(params: A2A.MessageSendParams, options?: RequestOptions): AsyncGenerator<A2A.Update, void, undefined>;
40
+ sendMessageStream(params: describe.MessageSendParamsParams, options?: RequestOptions): AsyncGenerator<A2A.Update, void, undefined>;
41
+ sendMessageStream(params: describe.MessageParams, options?: RequestOptions): AsyncGenerator<A2A.Update, void, undefined>;
42
+ /**
43
+ * Retrieves the current state of a task.
44
+ * @param params The parameters for the tasks/get method.
45
+ * @returns A promise resolving to the Task object or null.
46
+ */
47
+ getTask(params: A2A.TaskQueryParams, options?: RequestOptions): Promise<A2A.Task>;
48
+ /**
49
+ * Cancels a currently running task.
50
+ * @param params The parameters for the tasks/cancel method.
51
+ * @returns A promise resolving to the updated Task object (usually canceled state) or null.
52
+ */
53
+ cancelTask(params: A2A.TaskIdParams, options?: RequestOptions): Promise<A2A.Task>;
54
+ /**
55
+ * Sets or updates the push notification config for a task.
56
+ * @param params The parameters for the tasks/pushNotificationConfig/set method (which is TaskPushNotificationConfig).
57
+ * @returns A promise resolving to the confirmed TaskPushNotificationConfig or null.
58
+ */
59
+ setTaskPushNotificationConfig(params: A2A.TaskPushNotificationConfig, options?: RequestOptions): Promise<A2A.TaskPushNotificationConfig>;
60
+ /**
61
+ * Retrieves the currently configured push notification config for a task.
62
+ * @param params The parameters for the tasks/pushNotificationConfig/get method.
63
+ * @returns A promise resolving to the TaskPushNotificationConfig or null.
64
+ */
65
+ getTaskPushNotificationConfig(params: A2A.TaskIdParams, options?: RequestOptions): Promise<A2A.TaskPushNotificationConfig>;
66
+ listTaskPushNotificationConfig(params: A2A.ListTaskPushNotificationConfigParams, options?: RequestOptions): Promise<A2A.ListTaskPushNotificationConfigResult>;
67
+ deleteTaskPushNotificationConfig(params: A2A.DeleteTaskPushNotificationConfigParams, options?: RequestOptions): Promise<void>;
68
+ /**
69
+ * Resubscribes to an existing task's update stream.
70
+ * @param params Parameters identifying the task to resubscribe to
71
+ * @returns An AsyncIterable that yields TaskStatusUpdateEvent or TaskArtifactUpdateEvent payloads.
72
+ */
73
+ resubscribeTask(params: A2A.TaskQueryParams, options?: RequestOptions): AsyncGenerator<A2A.Update>;
74
+ /**
75
+ * Checks if the server supports a specific capability based on the agent card.
76
+ * @param capability The capability to check (e.g., 'streaming', 'pushNotifications').
77
+ * @returns A promise resolving to true if the capability is supported.
78
+ */
79
+ supports(capability: "streaming" | "pushNotifications" | "stateTransitionHistory" | "extensions"): Promise<boolean>;
80
+ /**
81
+ * Adds a single header to be included in all requests.
82
+ * @param name The header name.
83
+ * @param value The header value.
84
+ */
85
+ addHeader(name: string, value: string): void;
86
+ /**
87
+ * Removes a header.
88
+ * @param name The header name to remove.
89
+ */
90
+ removeHeader(name: string): void;
91
+ static create({ baseUrl, headers, fallbackPath, factory, config, }: MessengerParams): Promise<Messenger>;
92
+ }
93
+ /**
94
+ * Creates a new Messenger instance.
95
+ * @param baseUrl The base URL for the A2A server.
96
+ * @param headers Optional custom headers to include in all requests.
97
+ * @param fallbackPath Optional fallback path to use if the agent card is not found at the base URL.
98
+ * @example
99
+ * const messenger = createMessenger({
100
+ * baseUrl: "http://localhost:4000/a2a",
101
+ * });
102
+ * const card = await messenger.getAgentCard();
103
+ * console.log(card);
104
+ * @example
105
+ * const messenger = createMessenger({
106
+ * baseUrl: "http://localhost:4000/a2a",
107
+ * fallbackPath: "/agent-card",
108
+ * });
109
+ * const card = await messenger.getAgentCard();
110
+ * console.log(card);
111
+ */
112
+ export declare const createMessenger: typeof Messenger.create;
113
+ export declare const AgentMessenger: typeof Messenger;
114
+ export type AgentMessenger = Messenger;
115
+ /**
116
+ * @deprecated Use {@link createMessenger} instead.
117
+ */
118
+ export declare const A2AClient: typeof Messenger;
119
+ export {};