@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.
- package/README.md +100 -50
- 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 +5 -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 +280 -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 +4 -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/task-builder.js +5 -1
- 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 +288 -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 +11 -19
- package/dist/server/express/server.js +29 -64
- 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 +2 -2
- 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 +163 -95
- 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 -2
- package/dist/transport/trpc/a2a/routes/tasks/route.d.ts +4 -4
- package/dist/transport/trpc/a2a/routes/tasks/route.js +3 -3
- 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 -10
- package/dist/utils/index.js +6 -10
- package/dist/utils/parse.d.ts +7 -0
- package/dist/utils/parse.js +17 -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
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { A2A } from "../types/index.js";
|
|
6
|
+
import { validateSchema } from "../utils/schema-validation.js";
|
|
7
|
+
import { logger } from "../config/index.js";
|
|
8
|
+
import * as describe from "../create/describe.js";
|
|
9
|
+
import { ClientFactory, ClientFactoryOptions, AgentCardResolver, } from "@a2a-js/sdk/client";
|
|
10
|
+
class HeaderInterceptor {
|
|
11
|
+
constructor(_getCustomHeaders) {
|
|
12
|
+
this._getCustomHeaders = _getCustomHeaders;
|
|
13
|
+
}
|
|
14
|
+
before(args) {
|
|
15
|
+
const options = args.options ?? { serviceParameters: {} };
|
|
16
|
+
const serviceParameters = options.serviceParameters;
|
|
17
|
+
options.serviceParameters = {
|
|
18
|
+
...serviceParameters,
|
|
19
|
+
...this._getCustomHeaders(),
|
|
20
|
+
};
|
|
21
|
+
args.options = options;
|
|
22
|
+
return Promise.resolve();
|
|
23
|
+
}
|
|
24
|
+
after() {
|
|
25
|
+
return Promise.resolve();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
class NestedAgentCardResolver {
|
|
29
|
+
constructor(_options) {
|
|
30
|
+
this._options = _options;
|
|
31
|
+
this._fetchImpl = _options.fetchImpl ?? fetch;
|
|
32
|
+
}
|
|
33
|
+
get options() {
|
|
34
|
+
return this._options;
|
|
35
|
+
}
|
|
36
|
+
async resolve(baseUrl, _path) {
|
|
37
|
+
const path = _path ?? this._options?.path;
|
|
38
|
+
const agentCard = await AgentCardResolver.default
|
|
39
|
+
.resolve(baseUrl, path)
|
|
40
|
+
.catch((error) => {
|
|
41
|
+
logger.error("Failed to fetch agent card", { error });
|
|
42
|
+
return undefined;
|
|
43
|
+
});
|
|
44
|
+
if (agentCard) {
|
|
45
|
+
return agentCard;
|
|
46
|
+
}
|
|
47
|
+
logger.warn("Fetching agent card from", { baseUrl });
|
|
48
|
+
const response = await this._fetchImpl(baseUrl + (path ?? "/well-known/agent-card.json"));
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
throw new Error(`Failed to fetch Agent Card from ${baseUrl}: ${response.status}`);
|
|
51
|
+
}
|
|
52
|
+
return await validateSchema(A2A.AgentCardSchema, await response.json());
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Messenger is the main communication client for interacting with remote A2A-compatible services.
|
|
57
|
+
* It provides methods for sending messages, retrieving tasks, canceling operations, and handling streaming responses.
|
|
58
|
+
*/
|
|
59
|
+
class Messenger {
|
|
60
|
+
constructor(baseUrl, _headers = {}, _fallbackPath, factory = ClientFactoryOptions.default, config) {
|
|
61
|
+
this._headers = _headers;
|
|
62
|
+
this._fallbackPath = _fallbackPath;
|
|
63
|
+
this._baseUrl = typeof baseUrl === "string" ? baseUrl : baseUrl.toString();
|
|
64
|
+
this._fallbackPath = _fallbackPath ?? "/agent.json";
|
|
65
|
+
this._factory = new ClientFactory(ClientFactoryOptions.createFrom(factory, {
|
|
66
|
+
clientConfig: {
|
|
67
|
+
...config,
|
|
68
|
+
interceptors: [
|
|
69
|
+
...(config?.interceptors ?? []),
|
|
70
|
+
new HeaderInterceptor(() => this.headers),
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
}));
|
|
74
|
+
//RAII
|
|
75
|
+
this.clientPromise = this.reset(this._baseUrl, this._fallbackPath);
|
|
76
|
+
}
|
|
77
|
+
async reset(baseUrl = this._baseUrl, fallbackPath = this._fallbackPath) {
|
|
78
|
+
this._baseUrl = typeof baseUrl === "string" ? baseUrl : baseUrl.toString();
|
|
79
|
+
this._fallbackPath = fallbackPath ?? "/agent.json";
|
|
80
|
+
this.clientPromise = this._factory
|
|
81
|
+
.createFromUrl(this._baseUrl)
|
|
82
|
+
.catch(async (error) => {
|
|
83
|
+
if (!this._fallbackPath) {
|
|
84
|
+
logger.error("Messenger: Failed to create client, no fallback path provided", { error });
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
logger.warn("Messenger: Failed to create client, falling back to fallback path: ", { error, fallbackPath: this._fallbackPath });
|
|
88
|
+
return await this._factory
|
|
89
|
+
.createFromUrl(this._baseUrl, this._fallbackPath)
|
|
90
|
+
.catch(async (error) => {
|
|
91
|
+
logger.error("Messenger: Failed to create client, at fallback path: ", { error, fallbackPath: this._fallbackPath });
|
|
92
|
+
throw error;
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
return this.clientPromise;
|
|
96
|
+
}
|
|
97
|
+
get baseUrl() {
|
|
98
|
+
return this._baseUrl;
|
|
99
|
+
}
|
|
100
|
+
get headers() {
|
|
101
|
+
return this._headers;
|
|
102
|
+
}
|
|
103
|
+
set headers(headers) {
|
|
104
|
+
this._headers = headers;
|
|
105
|
+
}
|
|
106
|
+
get _client() {
|
|
107
|
+
return this.clientPromise;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Retrieves the AgentCard from the A2A server.
|
|
111
|
+
* @returns A promise resolving to the AgentCard.
|
|
112
|
+
*/
|
|
113
|
+
async getAgentCard(requestOptions) {
|
|
114
|
+
const client = await this._client;
|
|
115
|
+
return await client.getAgentCard(requestOptions);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Sends a Message to an agent server.
|
|
119
|
+
* @param params The {@link A2A.MessageSendParams} for the message/send method.
|
|
120
|
+
* @param options The {@link RequestOptions} for the request.
|
|
121
|
+
* @returns A promise resolving to {@link A2A.SendMessageSuccessResult} from the agent server.
|
|
122
|
+
*/
|
|
123
|
+
async sendMessage(params, options) {
|
|
124
|
+
const client = await this._client;
|
|
125
|
+
return await validateSchema(A2A.SendMessageSuccessResultSchema, await client.sendMessage(describe.messageSendParams(params), options));
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Sends a Message and returns a stream of status and artifact updates.
|
|
129
|
+
* @param params Task parameters for the request
|
|
130
|
+
* @returns An AsyncIterable that yields TaskStatusUpdateEvent/TaskArtifactUpdateEvent/Task/Message payloads.
|
|
131
|
+
*/
|
|
132
|
+
async *sendMessageStream(params, options) {
|
|
133
|
+
try {
|
|
134
|
+
const client = await this._client;
|
|
135
|
+
yield* client.sendMessageStream(describe.messageSendParams(params), options);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
logger.error("Messenger: Failed to send message stream", { error });
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Retrieves the current state of a task.
|
|
144
|
+
* @param params The parameters for the tasks/get method.
|
|
145
|
+
* @returns A promise resolving to the Task object or null.
|
|
146
|
+
*/
|
|
147
|
+
async getTask(params, options) {
|
|
148
|
+
const client = await this._client;
|
|
149
|
+
return await validateSchema(A2A.TaskSchema, await client.getTask(params, options));
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Cancels a currently running task.
|
|
153
|
+
* @param params The parameters for the tasks/cancel method.
|
|
154
|
+
* @returns A promise resolving to the updated Task object (usually canceled state) or null.
|
|
155
|
+
*/
|
|
156
|
+
async cancelTask(params, options) {
|
|
157
|
+
const client = await this._client;
|
|
158
|
+
return await validateSchema(A2A.TaskSchema, await client.cancelTask(params, options));
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Sets or updates the push notification config for a task.
|
|
162
|
+
* @param params The parameters for the tasks/pushNotificationConfig/set method (which is TaskPushNotificationConfig).
|
|
163
|
+
* @returns A promise resolving to the confirmed TaskPushNotificationConfig or null.
|
|
164
|
+
*/
|
|
165
|
+
async setTaskPushNotificationConfig(params, options) {
|
|
166
|
+
const client = await this._client;
|
|
167
|
+
return await validateSchema(A2A.TaskPushNotificationConfigSchema, await client.setTaskPushNotificationConfig(params, options));
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Retrieves the currently configured push notification config for a task.
|
|
171
|
+
* @param params The parameters for the tasks/pushNotificationConfig/get method.
|
|
172
|
+
* @returns A promise resolving to the TaskPushNotificationConfig or null.
|
|
173
|
+
*/
|
|
174
|
+
async getTaskPushNotificationConfig(params, options) {
|
|
175
|
+
const client = await this._client;
|
|
176
|
+
return await validateSchema(A2A.TaskPushNotificationConfigSchema, await client.getTaskPushNotificationConfig(params, options));
|
|
177
|
+
}
|
|
178
|
+
async listTaskPushNotificationConfig(params, options) {
|
|
179
|
+
const client = await this._client;
|
|
180
|
+
return await validateSchema(A2A.ListTaskPushNotificationConfigResultSchema, await client.listTaskPushNotificationConfig(params, options));
|
|
181
|
+
}
|
|
182
|
+
async deleteTaskPushNotificationConfig(params, options) {
|
|
183
|
+
const client = await this._client;
|
|
184
|
+
return client.deleteTaskPushNotificationConfig(params, options);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Resubscribes to an existing task's update stream.
|
|
188
|
+
* @param params Parameters identifying the task to resubscribe to
|
|
189
|
+
* @returns An AsyncIterable that yields TaskStatusUpdateEvent or TaskArtifactUpdateEvent payloads.
|
|
190
|
+
*/
|
|
191
|
+
async *resubscribeTask(params, options) {
|
|
192
|
+
try {
|
|
193
|
+
const client = await this._client;
|
|
194
|
+
yield* client.resubscribeTask(params, options);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
logger.error("Messenger: Failed to resubscribe task", { error });
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Checks if the server supports a specific capability based on the agent card.
|
|
203
|
+
* @param capability The capability to check (e.g., 'streaming', 'pushNotifications').
|
|
204
|
+
* @returns A promise resolving to true if the capability is supported.
|
|
205
|
+
*/
|
|
206
|
+
async supports(capability) {
|
|
207
|
+
const card = await this.getAgentCard();
|
|
208
|
+
if (!card.capabilities) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
switch (capability) {
|
|
212
|
+
case "streaming":
|
|
213
|
+
return !!card.capabilities.streaming;
|
|
214
|
+
case "pushNotifications":
|
|
215
|
+
return !!card.capabilities.pushNotifications;
|
|
216
|
+
case "stateTransitionHistory":
|
|
217
|
+
return !!card.capabilities.stateTransitionHistory;
|
|
218
|
+
case "extensions":
|
|
219
|
+
return !!card.capabilities.extensions;
|
|
220
|
+
default:
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Adds a single header to be included in all requests.
|
|
226
|
+
* @param name The header name.
|
|
227
|
+
* @param value The header value.
|
|
228
|
+
*/
|
|
229
|
+
addHeader(name, value) {
|
|
230
|
+
this.headers[name] = value;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Removes a header.
|
|
234
|
+
* @param name The header name to remove.
|
|
235
|
+
*/
|
|
236
|
+
removeHeader(name) {
|
|
237
|
+
delete this.headers[name];
|
|
238
|
+
}
|
|
239
|
+
static async create({ baseUrl, headers, fallbackPath, factory, config, }) {
|
|
240
|
+
const _factory = {
|
|
241
|
+
...ClientFactoryOptions.default,
|
|
242
|
+
cardResolver: new NestedAgentCardResolver({
|
|
243
|
+
path: "/.well-known/agent-card.json",
|
|
244
|
+
}),
|
|
245
|
+
...factory,
|
|
246
|
+
};
|
|
247
|
+
const messenger = new Messenger(baseUrl, headers, fallbackPath, _factory, config);
|
|
248
|
+
const card = await messenger.getAgentCard();
|
|
249
|
+
/**Validate the agent card to ensure the target conforms to the A2A specification */
|
|
250
|
+
await validateSchema(A2A.AgentCardSchema, card).catch((error) => {
|
|
251
|
+
logger.warn("Messenger: Invalid agent card detected", { error });
|
|
252
|
+
});
|
|
253
|
+
return messenger;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Creates a new Messenger instance.
|
|
258
|
+
* @param baseUrl The base URL for the A2A server.
|
|
259
|
+
* @param headers Optional custom headers to include in all requests.
|
|
260
|
+
* @param fallbackPath Optional fallback path to use if the agent card is not found at the base URL.
|
|
261
|
+
* @example
|
|
262
|
+
* const messenger = createMessenger({
|
|
263
|
+
* baseUrl: "http://localhost:4000/a2a",
|
|
264
|
+
* });
|
|
265
|
+
* const card = await messenger.getAgentCard();
|
|
266
|
+
* console.log(card);
|
|
267
|
+
* @example
|
|
268
|
+
* const messenger = createMessenger({
|
|
269
|
+
* baseUrl: "http://localhost:4000/a2a",
|
|
270
|
+
* fallbackPath: "/agent-card",
|
|
271
|
+
* });
|
|
272
|
+
* const card = await messenger.getAgentCard();
|
|
273
|
+
* console.log(card);
|
|
274
|
+
*/
|
|
275
|
+
export const createMessenger = Messenger.create;
|
|
276
|
+
export const AgentMessenger = Messenger;
|
|
277
|
+
/**
|
|
278
|
+
* @deprecated Use {@link createMessenger} instead.
|
|
279
|
+
*/
|
|
280
|
+
export const A2AClient = Messenger;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright 2025 The Artinet Project
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import { AgentCard, Message, Task, AgentExtension, TaskQueryParams, TaskIdParams, MessageSendParams, SendMessageSuccessResult } from "@artinet/types/a2a";
|
|
5
|
+
import { AgentCard, Message, Task, AgentExtension, TaskQueryParams, TaskIdParams, MessageSendParams, SendMessageSuccessResult, PushNotificationConfig } from "@artinet/types/a2a";
|
|
6
6
|
import { core } from "../core/index.js";
|
|
7
7
|
import { z } from "zod/v4";
|
|
8
8
|
export type AgentCardParams = (Partial<AgentCard> & Required<Pick<AgentCard, "name">>) | string;
|
|
@@ -46,14 +46,14 @@ export declare const UpdateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
46
46
|
contextId: z.ZodString;
|
|
47
47
|
status: z.ZodObject<{
|
|
48
48
|
state: z.ZodEnum<{
|
|
49
|
-
failed: "failed";
|
|
50
49
|
unknown: "unknown";
|
|
50
|
+
submitted: "submitted";
|
|
51
|
+
working: "working";
|
|
52
|
+
"input-required": "input-required";
|
|
51
53
|
completed: "completed";
|
|
52
54
|
canceled: "canceled";
|
|
55
|
+
failed: "failed";
|
|
53
56
|
rejected: "rejected";
|
|
54
|
-
working: "working";
|
|
55
|
-
submitted: "submitted";
|
|
56
|
-
"input-required": "input-required";
|
|
57
57
|
"auth-required": "auth-required";
|
|
58
58
|
}>;
|
|
59
59
|
message: z.ZodOptional<z.ZodObject<{
|
|
@@ -168,14 +168,14 @@ export declare const UpdateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
168
168
|
kind: z.ZodLiteral<"status-update">;
|
|
169
169
|
status: z.ZodObject<{
|
|
170
170
|
state: z.ZodEnum<{
|
|
171
|
-
failed: "failed";
|
|
172
171
|
unknown: "unknown";
|
|
172
|
+
submitted: "submitted";
|
|
173
|
+
working: "working";
|
|
174
|
+
"input-required": "input-required";
|
|
173
175
|
completed: "completed";
|
|
174
176
|
canceled: "canceled";
|
|
177
|
+
failed: "failed";
|
|
175
178
|
rejected: "rejected";
|
|
176
|
-
working: "working";
|
|
177
|
-
submitted: "submitted";
|
|
178
|
-
"input-required": "input-required";
|
|
179
179
|
"auth-required": "auth-required";
|
|
180
180
|
}>;
|
|
181
181
|
message: z.ZodOptional<z.ZodObject<{
|
|
@@ -272,13 +272,13 @@ export interface Context extends BaseContext {
|
|
|
272
272
|
readonly messages: MessageConsumerProxy;
|
|
273
273
|
extensions?: AgentExtension[];
|
|
274
274
|
references?: Task[];
|
|
275
|
+
userId?: string;
|
|
275
276
|
getTask: () => Promise<Task>;
|
|
276
277
|
}
|
|
277
278
|
export type ContextParams = Omit<BaseContext, "publisher" | "isCancelled" | "getState" | "abortSignal"> & Omit<Partial<Context>, "userMessage" | "taskId"> & {
|
|
278
279
|
messenger: MessageConsumerProxy;
|
|
279
280
|
task: Task;
|
|
280
281
|
overrides?: Partial<Omit<EventConsumer, "contextId">>;
|
|
281
|
-
abortSignal?: AbortSignal;
|
|
282
282
|
};
|
|
283
283
|
export interface Contexts extends core.Contexts<Context> {
|
|
284
284
|
create: (params: ContextParams) => Promise<Context>;
|
|
@@ -294,20 +294,38 @@ export interface Cancellations extends Omit<core.Manager<void>, "get"> {
|
|
|
294
294
|
}
|
|
295
295
|
export interface Connections extends Omit<core.Manager<void>, "get"> {
|
|
296
296
|
}
|
|
297
|
-
export interface
|
|
298
|
-
|
|
297
|
+
export interface Notifier {
|
|
298
|
+
notify: (task: Task, update: Update, context?: Context) => Promise<void>;
|
|
299
|
+
register: (taskId: string, config: PushNotificationConfig) => Promise<void>;
|
|
300
|
+
}
|
|
301
|
+
export type ServiceOptions = Pick<ContextParams, "userId" | "extensions"> & {
|
|
302
|
+
task?: Task;
|
|
303
|
+
signal?: AbortSignal;
|
|
304
|
+
notifier?: Notifier;
|
|
305
|
+
};
|
|
306
|
+
export interface Handles {
|
|
307
|
+
getTask: (input: TaskQueryParams, context: Context) => Promise<Task>;
|
|
308
|
+
cancelTask: (input: TaskIdParams, context: Context) => Promise<Task>;
|
|
309
|
+
sendMessage: (message: MessageSendParams, context: Context) => Promise<SendMessageSuccessResult>;
|
|
310
|
+
/**
|
|
311
|
+
* @deprecated Use sendMessageStream instead
|
|
312
|
+
*/
|
|
313
|
+
streamMessage: (message: MessageSendParams, context: Context) => AsyncGenerator<Update>;
|
|
314
|
+
sendMessageStream: (message: MessageSendParams, context: Context) => AsyncGenerator<Update>;
|
|
315
|
+
resubscribe: (input: TaskIdParams, context: Context) => AsyncGenerator<Update>;
|
|
299
316
|
}
|
|
300
317
|
export interface RequestHandler {
|
|
301
|
-
getTask: (input: TaskQueryParams,
|
|
302
|
-
cancelTask: (input: TaskIdParams,
|
|
303
|
-
sendMessage: (message: MessageSendParams,
|
|
304
|
-
|
|
305
|
-
|
|
318
|
+
getTask: (input: TaskQueryParams, options?: ServiceOptions) => Promise<Task>;
|
|
319
|
+
cancelTask: (input: TaskIdParams, options?: ServiceOptions) => Promise<Task>;
|
|
320
|
+
sendMessage: (message: MessageSendParams, options?: ServiceOptions) => Promise<SendMessageSuccessResult>;
|
|
321
|
+
/**
|
|
322
|
+
* @deprecated Use sendMessageStream instead
|
|
323
|
+
*/
|
|
324
|
+
streamMessage: (message: MessageSendParams, options?: ServiceOptions) => AsyncGenerator<Update>;
|
|
325
|
+
sendMessageStream: (message: MessageSendParams, options?: ServiceOptions) => AsyncGenerator<Update>;
|
|
326
|
+
resubscribe: (input: TaskIdParams, options?: ServiceOptions) => AsyncGenerator<Update>;
|
|
306
327
|
getAgentCard: () => Promise<AgentCard>;
|
|
307
328
|
}
|
|
308
|
-
export interface ExtendedHandler extends RequestHandler {
|
|
309
|
-
getAuthenticatedExtendedCard: () => Promise<AgentCard>;
|
|
310
|
-
}
|
|
311
329
|
export interface Stream {
|
|
312
330
|
readonly contextId: string;
|
|
313
331
|
isAlive: boolean;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* Copyright 2025 The Artinet Project
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
//lets stay really granular with the imports
|
|
6
5
|
import { TaskArtifactUpdateEventSchema, MessageSchema, TaskSchema, TaskStatusUpdateEventSchema, } from "@artinet/types/a2a";
|
|
7
6
|
import { z } from "zod/v4";
|
|
8
7
|
export const UpdateSchema = z.discriminatedUnion("kind", [
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { EventEmitter } from "
|
|
1
|
+
import { EventEmitter } from "eventemitter3";
|
|
2
|
+
import { IStore } from "../storage.js";
|
|
2
3
|
export interface Service<Params extends object = object, Result extends unknown = void> {
|
|
3
4
|
execute: (params: Params) => Promise<Result>;
|
|
4
5
|
stop: () => Promise<void>;
|
|
@@ -11,9 +12,10 @@ export interface Context<State extends object = object> {
|
|
|
11
12
|
readonly publisher?: Publisher;
|
|
12
13
|
readonly getState: (args?: string) => Promise<State | undefined>;
|
|
13
14
|
metadata?: Record<string, unknown>;
|
|
15
|
+
/**hooks allow consumers to modify context on the fly*/
|
|
14
16
|
readonly hooks?: Record<string, (...args: unknown[]) => Promise<unknown>>;
|
|
15
17
|
}
|
|
16
|
-
export interface Manager<T = object> {
|
|
18
|
+
export interface Manager<T = object> extends IStore<T> {
|
|
17
19
|
get: (id: string) => Promise<T | undefined>;
|
|
18
20
|
set: (id: string, data?: T) => Promise<void>;
|
|
19
21
|
delete: (id: string) => Promise<void>;
|
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Interface for a store of data.
|
|
7
|
-
* @deprecated Use IStore instead
|
|
8
|
-
* @template T - The type of data to store
|
|
9
|
-
*/
|
|
10
|
-
export interface Store<T> {
|
|
11
|
-
set(data: T, id?: string): Promise<void>;
|
|
12
|
-
get(id: string): Promise<T | undefined>;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Interface for a store of data.
|
|
2
|
+
* @note prefer implementing `Manager` instead of `IStore` as it provides a more robust interface.
|
|
3
|
+
* Interface for a store of data.
|
|
16
4
|
* @template T - The type of data to store
|
|
17
5
|
*/
|
|
18
6
|
export interface IStore<T> {
|
|
@@ -2,77 +2,58 @@
|
|
|
2
2
|
* Copyright 2025 The Artinet Project
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import { A2A, MCP } from "
|
|
5
|
+
import { A2A, MCP } from "../types/index.js";
|
|
6
6
|
/**
|
|
7
|
-
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
8
7
|
* @since 0.6.0
|
|
9
8
|
*/
|
|
10
9
|
export declare class SystemError<T extends MCP.JSONRPCErrorResponse> extends Error {
|
|
11
|
-
message: string;
|
|
12
10
|
code: T["error"]["code"];
|
|
13
|
-
data
|
|
14
|
-
|
|
11
|
+
data?: T["error"]["data"];
|
|
12
|
+
taskId?: string;
|
|
13
|
+
message: string;
|
|
14
|
+
constructor(message: string, code: T["error"]["code"], data?: T["error"]["data"], taskId?: string);
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
18
|
-
* @since 0.6.0
|
|
19
|
-
*/
|
|
20
|
-
export declare const PARSE_ERROR: <T extends A2A.JSONParseError>(data: T["error"]["data"]) => SystemError<T>;
|
|
21
|
-
/**
|
|
22
|
-
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
23
|
-
* @since 0.6.0
|
|
24
|
-
*/
|
|
25
|
-
export declare const INVALID_REQUEST: <T extends A2A.InvalidRequestError>(data: T["error"]["data"]) => SystemError<T>;
|
|
26
|
-
/**
|
|
27
|
-
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
28
|
-
* @since 0.6.0
|
|
29
|
-
*/
|
|
30
|
-
export declare const METHOD_NOT_FOUND: <T extends A2A.MethodNotFoundError>(data: T["error"]["data"]) => SystemError<T>;
|
|
31
|
-
/**
|
|
32
|
-
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
33
17
|
* @since 0.6.0
|
|
34
18
|
*/
|
|
35
|
-
export declare const
|
|
19
|
+
export declare const PARSE_ERROR: <T extends A2A.JSONParseError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
36
20
|
/**
|
|
37
|
-
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
38
21
|
* @since 0.6.0
|
|
39
22
|
*/
|
|
40
|
-
export declare const
|
|
23
|
+
export declare const INVALID_REQUEST: <T extends A2A.InvalidRequestError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
41
24
|
/**
|
|
42
|
-
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
43
|
-
* @since 0.6.0
|
|
44
|
-
*/
|
|
45
|
-
export declare const TASK_NOT_FOUND: <T extends A2A.TaskNotFoundError>(data: T["error"]["data"]) => SystemError<T>;
|
|
46
|
-
/**
|
|
47
|
-
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
48
25
|
* @since 0.6.0
|
|
49
26
|
*/
|
|
50
|
-
export declare const
|
|
27
|
+
export declare const METHOD_NOT_FOUND: <T extends A2A.MethodNotFoundError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
28
|
+
export declare const INVALID_PARAMS: <T extends A2A.InvalidParamsError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
29
|
+
export declare const INTERNAL_ERROR: <T extends A2A.InternalError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
30
|
+
export declare const TASK_NOT_FOUND: <T extends A2A.TaskNotFoundError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
31
|
+
export declare const TASK_NOT_CANCELABLE: <T extends A2A.TaskNotCancelableError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
51
32
|
/**
|
|
52
33
|
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
53
34
|
* @since 0.6.0
|
|
54
35
|
*/
|
|
55
|
-
export declare const PUSH_NOTIFICATION_NOT_SUPPORTED: <T extends A2A.
|
|
36
|
+
export declare const PUSH_NOTIFICATION_NOT_SUPPORTED: <T extends A2A.PushNotificationNotSupportedError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
56
37
|
/**
|
|
57
38
|
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
58
39
|
* @since 0.6.0
|
|
59
40
|
*/
|
|
60
|
-
export declare const AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED: <T extends A2A.AuthenticatedExtendedCardNotConfiguredError>(data: T["error"]["data"]) => SystemError<T>;
|
|
41
|
+
export declare const AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED: <T extends A2A.AuthenticatedExtendedCardNotConfiguredError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
61
42
|
/**
|
|
62
43
|
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
63
44
|
* @since 0.6.0
|
|
64
45
|
*/
|
|
65
|
-
export declare const UNSUPPORTED_OPERATION: <T extends A2A.A2AError>(data: T["error"]["data"]) => SystemError<T>;
|
|
46
|
+
export declare const UNSUPPORTED_OPERATION: <T extends A2A.A2AError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
66
47
|
/**
|
|
67
48
|
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
68
49
|
* @since 0.6.0
|
|
69
50
|
*/
|
|
70
|
-
export declare const CONTENT_TYPE_NOT_SUPPORTED: <T extends A2A.ContentTypeNotSupportedError>(data: T["error"]["data"]) => SystemError<T>;
|
|
51
|
+
export declare const CONTENT_TYPE_NOT_SUPPORTED: <T extends A2A.ContentTypeNotSupportedError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
71
52
|
/**
|
|
72
53
|
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
73
54
|
* @since 0.6.0
|
|
74
55
|
*/
|
|
75
|
-
export declare const INVALID_AGENT_RESPONSE: <T extends A2A.InvalidAgentResponseError>(data: T["error"]["data"]) => SystemError<T>;
|
|
56
|
+
export declare const INVALID_AGENT_RESPONSE: <T extends A2A.InvalidAgentResponseError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
76
57
|
/**
|
|
77
58
|
* @deprecated Use {@link describe.update.failed} instead
|
|
78
59
|
* @since 0.6.0
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* @since 0.6.0
|
|
9
|
+
*/
|
|
10
|
+
export class SystemError extends Error {
|
|
11
|
+
constructor(message, code, data, taskId) {
|
|
12
|
+
super(message);
|
|
13
|
+
// this.name = "RpcError";
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.data = data;
|
|
16
|
+
this.taskId = taskId;
|
|
17
|
+
this.message = message;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @since 0.6.0
|
|
22
|
+
*/
|
|
23
|
+
export const PARSE_ERROR = (data, taskId) => new SystemError("Invalid JSON payload", A2A.ErrorCodeParseError, data, taskId);
|
|
24
|
+
/**
|
|
25
|
+
* @since 0.6.0
|
|
26
|
+
*/
|
|
27
|
+
export const INVALID_REQUEST = (data, taskId) => new SystemError("Request payload validation error", A2A.ErrorCodeInvalidRequest, data, taskId);
|
|
28
|
+
/**
|
|
29
|
+
* @since 0.6.0
|
|
30
|
+
*/
|
|
31
|
+
export const METHOD_NOT_FOUND = (data, taskId) => new SystemError("Method not found", A2A.ErrorCodeMethodNotFound, data, taskId);
|
|
32
|
+
export const INVALID_PARAMS = (data, taskId) => new SystemError("Invalid parameters", A2A.ErrorCodeInvalidParams, data, taskId);
|
|
33
|
+
export const INTERNAL_ERROR = (data, taskId) => new SystemError("Internal error", A2A.ErrorCodeInternalError, data, taskId);
|
|
34
|
+
export const TASK_NOT_FOUND = (data, taskId) => new SystemError("Task not found", A2A.ErrorCodeTaskNotFound, data, taskId);
|
|
35
|
+
export const TASK_NOT_CANCELABLE = (data, taskId) => new SystemError("Task cannot be canceled", A2A.ErrorCodeTaskNotCancelable, data, taskId);
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
38
|
+
* @since 0.6.0
|
|
39
|
+
*/
|
|
40
|
+
export const PUSH_NOTIFICATION_NOT_SUPPORTED = (data, taskId) => new SystemError("Push Notifications is not supported", A2A.ErrorCodePushNotificationNotSupported, data, taskId);
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
43
|
+
* @since 0.6.0
|
|
44
|
+
*/
|
|
45
|
+
export const AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED = (data, taskId) => new SystemError("Authenticated Extended Card is not configured", A2A.ErrorCodeAuthenticatedExtendedCardNotConfigured, data, taskId);
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
48
|
+
* @since 0.6.0
|
|
49
|
+
*/
|
|
50
|
+
export const UNSUPPORTED_OPERATION = (data, taskId) => new SystemError("This operation is not supported", A2A.ErrorCodeUnsupportedOperation, data, taskId);
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
53
|
+
* @since 0.6.0
|
|
54
|
+
*/
|
|
55
|
+
export const CONTENT_TYPE_NOT_SUPPORTED = (data, taskId) => new SystemError("Content type not supported", A2A.ErrorCodeContentTypeNotSupported, data, taskId);
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
58
|
+
* @since 0.6.0
|
|
59
|
+
*/
|
|
60
|
+
export const INVALID_AGENT_RESPONSE = (data, taskId) => new SystemError("Invalid agent response", A2A.ErrorCodeInvalidAgentResponse, data, taskId);
|
|
61
|
+
/**
|
|
62
|
+
* @deprecated Use {@link describe.update.failed} instead
|
|
63
|
+
* @since 0.6.0
|
|
64
|
+
*/
|
|
65
|
+
export const FAILED_UPDATE = (taskId, contextId, messageId = "failed-update", errMessage) => {
|
|
66
|
+
return describe.update.failed({
|
|
67
|
+
taskId,
|
|
68
|
+
contextId,
|
|
69
|
+
final: true,
|
|
70
|
+
message: describe.message({
|
|
71
|
+
role: "agent",
|
|
72
|
+
messageId,
|
|
73
|
+
parts: [{ kind: "text", text: errMessage }],
|
|
74
|
+
}),
|
|
75
|
+
});
|
|
76
|
+
};
|