@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
|
@@ -0,0 +1,251 @@
|
|
|
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, } from "@a2a-js/sdk/client";
|
|
10
|
+
class HeaderInterceptor {
|
|
11
|
+
_getCustomHeaders;
|
|
12
|
+
constructor(_getCustomHeaders) {
|
|
13
|
+
this._getCustomHeaders = _getCustomHeaders;
|
|
14
|
+
}
|
|
15
|
+
before(args) {
|
|
16
|
+
const options = args.options ?? { serviceParameters: {} };
|
|
17
|
+
const serviceParameters = options.serviceParameters;
|
|
18
|
+
options.serviceParameters = {
|
|
19
|
+
...serviceParameters,
|
|
20
|
+
...this._getCustomHeaders(),
|
|
21
|
+
};
|
|
22
|
+
args.options = options;
|
|
23
|
+
return Promise.resolve();
|
|
24
|
+
}
|
|
25
|
+
after() {
|
|
26
|
+
return Promise.resolve();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Messenger is the main communication client for interacting with remote A2A-compatible services.
|
|
31
|
+
* It provides methods for sending messages, retrieving tasks, canceling operations, and handling streaming responses.
|
|
32
|
+
*/
|
|
33
|
+
class Messenger {
|
|
34
|
+
_headers;
|
|
35
|
+
_fallbackPath;
|
|
36
|
+
_baseUrl;
|
|
37
|
+
_factory;
|
|
38
|
+
clientPromise;
|
|
39
|
+
constructor(baseUrl, _headers = {}, _fallbackPath, factory = ClientFactoryOptions.default, config) {
|
|
40
|
+
this._headers = _headers;
|
|
41
|
+
this._fallbackPath = _fallbackPath;
|
|
42
|
+
this._baseUrl = typeof baseUrl === "string" ? baseUrl : baseUrl.toString();
|
|
43
|
+
this._fallbackPath = _fallbackPath ?? "/agent.json";
|
|
44
|
+
this._factory = new ClientFactory(ClientFactoryOptions.createFrom(factory, {
|
|
45
|
+
clientConfig: {
|
|
46
|
+
...config,
|
|
47
|
+
interceptors: [
|
|
48
|
+
...(config?.interceptors ?? []),
|
|
49
|
+
new HeaderInterceptor(() => this.headers),
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
}));
|
|
53
|
+
this.clientPromise = this.reset(this._baseUrl, this._fallbackPath);
|
|
54
|
+
}
|
|
55
|
+
async reset(baseUrl = this._baseUrl, fallbackPath = this._fallbackPath) {
|
|
56
|
+
this._baseUrl = typeof baseUrl === "string" ? baseUrl : baseUrl.toString();
|
|
57
|
+
this._fallbackPath = fallbackPath ?? "/agent.json";
|
|
58
|
+
this.clientPromise = this._factory
|
|
59
|
+
.createFromUrl(this._baseUrl)
|
|
60
|
+
.catch(async (error) => {
|
|
61
|
+
if (!this._fallbackPath) {
|
|
62
|
+
logger.error("Messenger: Failed to create client, no fallback path provided", { error });
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
logger.warn("Messenger: Failed to create client, falling back to fallback path: ", { error, fallbackPath: this._fallbackPath });
|
|
66
|
+
return await this._factory
|
|
67
|
+
.createFromUrl(this._baseUrl, this._fallbackPath)
|
|
68
|
+
.catch(async (error) => {
|
|
69
|
+
logger.error("Messenger: Failed to create client, at fallback path: ", { error, fallbackPath: this._fallbackPath });
|
|
70
|
+
throw error;
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
return this.clientPromise;
|
|
74
|
+
}
|
|
75
|
+
get baseUrl() {
|
|
76
|
+
return this._baseUrl;
|
|
77
|
+
}
|
|
78
|
+
get headers() {
|
|
79
|
+
return this._headers;
|
|
80
|
+
}
|
|
81
|
+
set headers(headers) {
|
|
82
|
+
this._headers = headers;
|
|
83
|
+
}
|
|
84
|
+
get _client() {
|
|
85
|
+
return this.clientPromise;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Retrieves the AgentCard from the A2A server.
|
|
89
|
+
* @returns A promise resolving to the AgentCard.
|
|
90
|
+
*/
|
|
91
|
+
async getAgentCard(requestOptions) {
|
|
92
|
+
const client = await this._client;
|
|
93
|
+
return await client.getAgentCard(requestOptions);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Sends a Message to an agent server.
|
|
97
|
+
* @param params The {@link A2A.MessageSendParams} for the message/send method.
|
|
98
|
+
* @param options The {@link RequestOptions} for the request.
|
|
99
|
+
* @returns A promise resolving to {@link A2A.SendMessageSuccessResult} from the agent server.
|
|
100
|
+
*/
|
|
101
|
+
async sendMessage(params, options) {
|
|
102
|
+
const client = await this._client;
|
|
103
|
+
return await validateSchema(A2A.SendMessageSuccessResultSchema, await client.sendMessage(describe.messageSendParams(params), options));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Sends a Message and returns a stream of status and artifact updates.
|
|
107
|
+
* @param params Task parameters for the request
|
|
108
|
+
* @returns An AsyncIterable that yields TaskStatusUpdateEvent/TaskArtifactUpdateEvent/Task/Message payloads.
|
|
109
|
+
*/
|
|
110
|
+
async *sendMessageStream(params, options) {
|
|
111
|
+
try {
|
|
112
|
+
const client = await this._client;
|
|
113
|
+
yield* client.sendMessageStream(describe.messageSendParams(params), options);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
logger.error("Messenger: Failed to send message stream", { error });
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Retrieves the current state of a task.
|
|
122
|
+
* @param params The parameters for the tasks/get method.
|
|
123
|
+
* @returns A promise resolving to the Task object or null.
|
|
124
|
+
*/
|
|
125
|
+
async getTask(params, options) {
|
|
126
|
+
const client = await this._client;
|
|
127
|
+
return await validateSchema(A2A.TaskSchema, await client.getTask(params, options));
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Cancels a currently running task.
|
|
131
|
+
* @param params The parameters for the tasks/cancel method.
|
|
132
|
+
* @returns A promise resolving to the updated Task object (usually canceled state) or null.
|
|
133
|
+
*/
|
|
134
|
+
async cancelTask(params, options) {
|
|
135
|
+
const client = await this._client;
|
|
136
|
+
return await validateSchema(A2A.TaskSchema, await client.cancelTask(params, options));
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Sets or updates the push notification config for a task.
|
|
140
|
+
* @param params The parameters for the tasks/pushNotificationConfig/set method (which is TaskPushNotificationConfig).
|
|
141
|
+
* @returns A promise resolving to the confirmed TaskPushNotificationConfig or null.
|
|
142
|
+
*/
|
|
143
|
+
async setTaskPushNotificationConfig(params, options) {
|
|
144
|
+
const client = await this._client;
|
|
145
|
+
return await validateSchema(A2A.TaskPushNotificationConfigSchema, await client.setTaskPushNotificationConfig(params, options));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Retrieves the currently configured push notification config for a task.
|
|
149
|
+
* @param params The parameters for the tasks/pushNotificationConfig/get method.
|
|
150
|
+
* @returns A promise resolving to the TaskPushNotificationConfig or null.
|
|
151
|
+
*/
|
|
152
|
+
async getTaskPushNotificationConfig(params, options) {
|
|
153
|
+
const client = await this._client;
|
|
154
|
+
return await validateSchema(A2A.TaskPushNotificationConfigSchema, await client.getTaskPushNotificationConfig(params, options));
|
|
155
|
+
}
|
|
156
|
+
async listTaskPushNotificationConfig(params, options) {
|
|
157
|
+
const client = await this._client;
|
|
158
|
+
return await validateSchema(A2A.ListTaskPushNotificationConfigResultSchema, await client.listTaskPushNotificationConfig(params, options));
|
|
159
|
+
}
|
|
160
|
+
async deleteTaskPushNotificationConfig(params, options) {
|
|
161
|
+
const client = await this._client;
|
|
162
|
+
return client.deleteTaskPushNotificationConfig(params, options);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Resubscribes to an existing task's update stream.
|
|
166
|
+
* @param params Parameters identifying the task to resubscribe to
|
|
167
|
+
* @returns An AsyncIterable that yields TaskStatusUpdateEvent or TaskArtifactUpdateEvent payloads.
|
|
168
|
+
*/
|
|
169
|
+
async *resubscribeTask(params, options) {
|
|
170
|
+
try {
|
|
171
|
+
const client = await this._client;
|
|
172
|
+
yield* client.resubscribeTask(params, options);
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
logger.error("Messenger: Failed to resubscribe task", { error });
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Checks if the server supports a specific capability based on the agent card.
|
|
181
|
+
* @param capability The capability to check (e.g., 'streaming', 'pushNotifications').
|
|
182
|
+
* @returns A promise resolving to true if the capability is supported.
|
|
183
|
+
*/
|
|
184
|
+
async supports(capability) {
|
|
185
|
+
const card = await this.getAgentCard();
|
|
186
|
+
if (!card.capabilities) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
switch (capability) {
|
|
190
|
+
case "streaming":
|
|
191
|
+
return !!card.capabilities.streaming;
|
|
192
|
+
case "pushNotifications":
|
|
193
|
+
return !!card.capabilities.pushNotifications;
|
|
194
|
+
case "stateTransitionHistory":
|
|
195
|
+
return !!card.capabilities.stateTransitionHistory;
|
|
196
|
+
case "extentions":
|
|
197
|
+
return !!card.capabilities.extensions;
|
|
198
|
+
default:
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Adds a single header to be included in all requests.
|
|
204
|
+
* @param name The header name.
|
|
205
|
+
* @param value The header value.
|
|
206
|
+
*/
|
|
207
|
+
addHeader(name, value) {
|
|
208
|
+
this.headers[name] = value;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Removes a header.
|
|
212
|
+
* @param name The header name to remove.
|
|
213
|
+
*/
|
|
214
|
+
removeHeader(name) {
|
|
215
|
+
delete this.headers[name];
|
|
216
|
+
}
|
|
217
|
+
static async create({ baseUrl, headers, fallbackPath, factory, config, }) {
|
|
218
|
+
const messenger = new Messenger(baseUrl, headers, fallbackPath, factory, config);
|
|
219
|
+
const card = await messenger.getAgentCard();
|
|
220
|
+
/**Validate the agent card to ensure the target conforms to the A2A specification */
|
|
221
|
+
await validateSchema(A2A.AgentCardSchema, card).catch((error) => {
|
|
222
|
+
logger.warn("Messenger: Invalid agent card detected", { error });
|
|
223
|
+
});
|
|
224
|
+
return messenger;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Creates a new Messenger instance.
|
|
229
|
+
* @param baseUrl The base URL for the A2A server.
|
|
230
|
+
* @param headers Optional custom headers to include in all requests.
|
|
231
|
+
* @param fallbackPath Optional fallback path to use if the agent card is not found at the base URL.
|
|
232
|
+
* @example
|
|
233
|
+
* const messenger = createMessenger({
|
|
234
|
+
* baseUrl: "http://localhost:4000/a2a",
|
|
235
|
+
* });
|
|
236
|
+
* const card = await messenger.getAgentCard();
|
|
237
|
+
* console.log(card);
|
|
238
|
+
* @example
|
|
239
|
+
* const messenger = createMessenger({
|
|
240
|
+
* baseUrl: "http://localhost:4000/a2a",
|
|
241
|
+
* fallbackPath: "/agent-card",
|
|
242
|
+
* });
|
|
243
|
+
* const card = await messenger.getAgentCard();
|
|
244
|
+
* console.log(card);
|
|
245
|
+
*/
|
|
246
|
+
export const createMessenger = Messenger.create;
|
|
247
|
+
export const AgentMessenger = Messenger;
|
|
248
|
+
/**
|
|
249
|
+
* @deprecated Use {@link createMessenger} instead.
|
|
250
|
+
*/
|
|
251
|
+
export const A2AClient = Messenger;
|