@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.
- package/README.md +100 -59
- package/dist/browser/browser.d.ts +2 -7
- package/dist/browser/browser.js +2 -7
- package/dist/browser/config/observability.d.ts +1 -1
- package/dist/browser/create/message-builder.d.ts +1 -1
- package/dist/browser/create/message-builder.js +19 -7
- package/dist/browser/create/task-builder.js +1 -1
- package/dist/browser/messenger/index.d.ts +1 -0
- package/dist/browser/messenger/index.js +1 -0
- package/dist/browser/messenger/messenger.d.ts +119 -0
- package/dist/browser/messenger/messenger.js +245 -0
- package/dist/browser/types/a2a/a2a.d.ts +38 -20
- package/dist/browser/types/a2a/a2a.js +0 -1
- package/dist/browser/types/core/core.d.ts +4 -2
- package/dist/browser/types/index.d.ts +0 -1
- package/dist/browser/types/index.js +0 -1
- package/dist/browser/types/storage.d.ts +2 -14
- package/dist/browser/types/storage.js +0 -4
- package/dist/browser/utils/{common/constants.d.ts → constants.d.ts} +1 -1
- package/dist/{utils/common → browser/utils}/constants.js +1 -1
- package/dist/browser/utils/{common/errors.d.ts → errors.d.ts} +17 -36
- package/dist/browser/utils/errors.js +76 -0
- package/dist/browser/utils/index.d.ts +6 -0
- package/dist/browser/utils/index.js +6 -0
- package/dist/{utils/common → browser/utils}/parse.js +1 -1
- package/dist/{utils/common → browser/utils}/schema-validation.js +2 -2
- package/dist/config/index.d.ts +1 -1
- package/dist/config/observability.d.ts +1 -1
- package/dist/create/agent-builder.d.ts +1 -1
- package/dist/create/create.d.ts +19 -20
- package/dist/create/create.js +33 -101
- package/dist/create/message-builder.d.ts +1 -1
- package/dist/create/message-builder.js +19 -7
- package/dist/create/status-builder.d.ts +4 -0
- package/dist/create/task-builder.js +1 -1
- package/dist/extensions/otel.d.ts +3 -0
- package/dist/extensions/otel.js +3 -0
- package/dist/extensions/pino.d.ts +3 -0
- package/dist/extensions/pino.js +3 -0
- package/dist/extensions/winston.d.ts +3 -0
- package/dist/extensions/winston.js +3 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/messenger/index.d.ts +1 -0
- package/dist/messenger/index.js +1 -0
- package/dist/messenger/messenger.d.ts +119 -0
- package/dist/messenger/messenger.js +251 -0
- package/dist/server/adapters/a2a_request_handler.d.ts +889 -0
- package/dist/server/adapters/a2a_request_handler.js +241 -0
- package/dist/server/adapters/loadable.d.ts +7 -0
- package/dist/server/adapters/loadable.js +73 -0
- package/dist/server/adapters/notifications.d.ts +26 -0
- package/dist/server/adapters/notifications.js +77 -0
- package/dist/server/express/server.d.ts +24 -18
- package/dist/server/express/server.js +41 -62
- package/dist/server/express/utils.d.ts +14 -0
- package/dist/server/express/{errors.js → utils.js} +22 -0
- package/dist/server/index.d.ts +4 -1
- package/dist/server/index.js +4 -1
- package/dist/server/params.d.ts +115 -0
- package/dist/server/params.js +21 -0
- package/dist/services/a2a/factory/context.d.ts +2 -1
- package/dist/services/a2a/factory/context.js +4 -3
- package/dist/services/a2a/factory/handler.d.ts +1 -1
- package/dist/services/a2a/factory/handler.js +7 -6
- package/dist/services/a2a/factory/service.d.ts +1 -1
- package/dist/services/a2a/factory/service.js +2 -2
- package/dist/services/a2a/factory/state-machine.js +9 -6
- package/dist/services/a2a/handlers/cancel-task.d.ts +1 -1
- package/dist/services/a2a/handlers/get-task.d.ts +1 -1
- package/dist/services/a2a/handlers/resubscribe-task.d.ts +2 -2
- package/dist/services/a2a/handlers/send-message.d.ts +1 -1
- package/dist/services/a2a/handlers/stream-message.d.ts +2 -2
- package/dist/services/a2a/handlers/update.js +7 -9
- package/dist/services/a2a/index.d.ts +0 -1
- package/dist/services/a2a/index.js +0 -1
- package/dist/services/a2a/managers.js +2 -1
- package/dist/services/a2a/messenger.d.ts +1 -1
- package/dist/services/a2a/messenger.js +1 -1
- package/dist/services/a2a/service.d.ts +26 -21
- package/dist/services/a2a/service.js +161 -93
- package/dist/services/a2a/state-machine.d.ts +1 -1
- package/dist/services/a2a/state-machine.js +2 -1
- package/dist/services/a2a/streams.js +1 -1
- package/dist/services/core/manager.d.ts +5 -0
- package/dist/services/core/manager.js +6 -0
- package/dist/services/mcp/service.js +1 -1
- package/dist/{utils/storage → storage}/file.d.ts +4 -2
- package/dist/{utils/storage → storage}/file.js +5 -4
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/sqlite.d.ts +353 -0
- package/dist/storage/sqlite.js +85 -0
- package/dist/transport/trpc/a2a/factory/router.d.ts +16 -16
- package/dist/transport/trpc/a2a/routes/info.d.ts +2 -2
- package/dist/transport/trpc/a2a/routes/message/route.d.ts +3 -3
- package/dist/transport/trpc/a2a/routes/message/route.js +2 -1
- package/dist/transport/trpc/a2a/routes/tasks/route.d.ts +4 -4
- package/dist/transport/trpc/a2a/routes/tasks/route.js +3 -2
- package/dist/types/a2a/a2a.d.ts +38 -20
- package/dist/types/a2a/a2a.js +0 -1
- package/dist/types/core/core.d.ts +4 -2
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +0 -1
- package/dist/types/storage.d.ts +2 -14
- package/dist/types/storage.js +0 -4
- package/dist/utils/{common/constants.d.ts → constants.d.ts} +1 -1
- package/dist/{browser/utils/common → utils}/constants.js +1 -1
- package/dist/utils/{common/errors.d.ts → errors.d.ts} +17 -36
- package/dist/utils/errors.js +80 -0
- package/dist/utils/index.d.ts +6 -11
- package/dist/utils/index.js +6 -11
- package/dist/utils/parse.d.ts +7 -0
- package/dist/utils/parse.js +14 -0
- package/dist/utils/schema-validation.d.ts +2 -0
- package/dist/utils/schema-validation.js +12 -0
- package/package.json +35 -22
- package/dist/browser/client/a2a-client.d.ts +0 -127
- package/dist/browser/client/a2a-client.js +0 -233
- package/dist/browser/client/index.d.ts +0 -1
- package/dist/browser/client/index.js +0 -1
- package/dist/browser/transport/rpc/parser.d.ts +0 -15
- package/dist/browser/transport/rpc/parser.js +0 -49
- package/dist/browser/transport/rpc/rpc-client.d.ts +0 -80
- package/dist/browser/transport/rpc/rpc-client.js +0 -189
- package/dist/browser/transport/streaming/event-stream.d.ts +0 -25
- package/dist/browser/transport/streaming/event-stream.js +0 -100
- package/dist/browser/types/client.d.ts +0 -133
- package/dist/browser/types/client.js +0 -5
- package/dist/browser/utils/common/errors.js +0 -95
- package/dist/client/a2a-client.d.ts +0 -127
- package/dist/client/a2a-client.js +0 -237
- package/dist/client/index.d.ts +0 -1
- package/dist/client/index.js +0 -1
- package/dist/server/express/errors.d.ts +0 -9
- package/dist/server/express/index.d.ts +0 -3
- package/dist/server/express/index.js +0 -3
- package/dist/server/express/middeware.d.ts +0 -7
- package/dist/server/express/middeware.js +0 -121
- package/dist/transport/index.d.ts +0 -3
- package/dist/transport/index.js +0 -4
- package/dist/transport/rpc/parser.d.ts +0 -15
- package/dist/transport/rpc/parser.js +0 -49
- package/dist/transport/rpc/rpc-client.d.ts +0 -80
- package/dist/transport/rpc/rpc-client.js +0 -189
- package/dist/transport/streaming/event-stream.d.ts +0 -25
- package/dist/transport/streaming/event-stream.js +0 -100
- package/dist/types/client.d.ts +0 -133
- package/dist/types/client.js +0 -5
- package/dist/utils/common/errors.js +0 -98
- /package/dist/{utils/common → browser/utils}/parse.d.ts +0 -0
- /package/dist/{utils/common → browser/utils}/schema-validation.d.ts +0 -0
- /package/dist/browser/utils/{common/utils.d.ts → utils.d.ts} +0 -0
- /package/dist/browser/utils/{common/utils.js → utils.js} +0 -0
- /package/dist/utils/{common/utils.d.ts → utils.d.ts} +0 -0
- /package/dist/utils/{common/utils.js → utils.js} +0 -0
- /package/dist/utils/{common/zAsyncIterable-v3.d.ts → zAsyncIterable-v3.d.ts} +0 -0
- /package/dist/utils/{common/zAsyncIterable-v3.js → zAsyncIterable-v3.js} +0 -0
- /package/dist/utils/{common/zAsyncIterable.d.ts → zAsyncIterable.d.ts} +0 -0
- /package/dist/utils/{common/zAsyncIterable.js → zAsyncIterable.js} +0 -0
package/README.md
CHANGED
|
@@ -1,23 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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/artinet"><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
|
|
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
|
|
18
|
-
- **No Vendor Lock-In:** Let your agents communicate with other agents
|
|
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)
|
|
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/
|
|
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
|
|
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,72 +57,99 @@ const agent = a2a({
|
|
|
46
57
|
npm install easy-a2a
|
|
47
58
|
```
|
|
48
59
|
|
|
49
|
-
##
|
|
60
|
+
## Examples
|
|
50
61
|
|
|
51
|
-
|
|
52
|
-
npm install @artinet/sdk
|
|
53
|
-
```
|
|
62
|
+
**Create an A2A Server**
|
|
54
63
|
|
|
55
|
-
|
|
64
|
+
Turn your agent into an express server so it can receive messages from anywhere:
|
|
56
65
|
|
|
57
|
-
```
|
|
58
|
-
|
|
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
|
-
|
|
75
|
+
- _ensure that the url/path of your AgentCard matches the server._
|
|
62
76
|
|
|
63
|
-
|
|
77
|
+
> 🚧 Coming Soon: Support for Hono.
|
|
64
78
|
|
|
65
|
-
|
|
79
|
+
**No Servers Needed**
|
|
66
80
|
|
|
67
|
-
|
|
81
|
+
Embed agents directly into your app:
|
|
68
82
|
|
|
69
83
|
```typescript
|
|
70
|
-
import {
|
|
71
|
-
|
|
72
|
-
const { app } = createAgentServer({
|
|
73
|
-
agent: AgentBuilder()
|
|
74
|
-
.text(async ({ content }) => {
|
|
75
|
-
return `You said: ${content}`;
|
|
76
|
-
})
|
|
77
|
-
.createAgent({
|
|
78
|
-
agentCard: "QuickStart Agent",
|
|
79
|
-
}),
|
|
80
|
-
basePath: "/a2a",
|
|
81
|
-
});
|
|
84
|
+
import { cr8, A2A } from "@artinet/sdk";
|
|
82
85
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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");
|
|
86
91
|
```
|
|
87
92
|
|
|
88
|
-
|
|
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:
|
|
89
98
|
|
|
90
99
|
```typescript
|
|
91
|
-
import {
|
|
100
|
+
import { AgentMessenger, createMessenger } from "@artinet/sdk";
|
|
92
101
|
|
|
93
|
-
const
|
|
102
|
+
const messenger: AgentMessenger = await createMessenger({
|
|
103
|
+
baseUrl: "http://localhost:3000/a2a",
|
|
104
|
+
headers: {
|
|
105
|
+
Bearer: "xxxx",
|
|
106
|
+
},
|
|
107
|
+
});
|
|
94
108
|
|
|
95
|
-
const stream =
|
|
109
|
+
const stream = messenger.sendMessageStream("Hello World!");
|
|
96
110
|
|
|
97
111
|
for await (const update of stream) {
|
|
98
112
|
console.log(update);
|
|
99
113
|
}
|
|
100
114
|
```
|
|
101
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
|
+
|
|
102
136
|
## Documentation
|
|
103
137
|
|
|
104
|
-
| Topic
|
|
105
|
-
|
|
|
106
|
-
| [**
|
|
107
|
-
| [**
|
|
108
|
-
| [**
|
|
109
|
-
| [**
|
|
110
|
-
| [**
|
|
111
|
-
| [**
|
|
112
|
-
| [**Customization**](docs/customization.md)
|
|
113
|
-
| [**MCP Integration**](docs/mcp.md)
|
|
114
|
-
| [**Migration Guide**](docs/migration.md)
|
|
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)
|
|
115
153
|
|
|
116
154
|
## Running Tests
|
|
117
155
|
|
|
@@ -127,8 +165,11 @@ Ensure code adheres to the project style and passes linting (`npm run lint`) and
|
|
|
127
165
|
|
|
128
166
|
## License
|
|
129
167
|
|
|
130
|
-
This project is licensed under
|
|
168
|
+
This project is licensed under Apache License 2.0.
|
|
169
|
+
|
|
170
|
+
See the [`LICENSE`](./LICENSE) for details.
|
|
131
171
|
|
|
132
|
-
##
|
|
172
|
+
## Join the Community
|
|
133
173
|
|
|
134
|
-
|
|
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 "./
|
|
3
|
-
export
|
|
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";
|
package/dist/browser/browser.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
//browser only entry point
|
|
2
2
|
export * from "./types/index.js";
|
|
3
|
-
export * from "./
|
|
4
|
-
export
|
|
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
|
-
/**
|
|
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: "
|
|
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: "
|
|
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
|
-
|
|
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(
|
|
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/
|
|
7
|
+
import { getCurrentTimestamp } from "../utils/utils.js";
|
|
8
8
|
import { isMessageParams, Message,
|
|
9
9
|
// type BuilderMessageParams,
|
|
10
10
|
} from "./message-builder.js";
|
|
@@ -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?: 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" | "extentions"): 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 {};
|