@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
|
@@ -3,21 +3,25 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { A2A } from "../../types/index.js";
|
|
6
|
-
import { validateSchema } from "../../utils/
|
|
6
|
+
import { validateSchema } from "../../utils/schema-validation.js";
|
|
7
7
|
import * as describe from "../../create/describe.js";
|
|
8
|
-
import { INVALID_REQUEST, TASK_NOT_FOUND } from "../../utils/
|
|
8
|
+
import { INVALID_REQUEST, TASK_NOT_FOUND } from "../../utils/errors.js";
|
|
9
9
|
import { Messenger } from "./messenger.js";
|
|
10
10
|
import { execute } from "./execute.js";
|
|
11
11
|
import { createService } from "./factory/service.js";
|
|
12
12
|
import { getReferences } from "./helpers/references.js";
|
|
13
13
|
import { logger } from "../../config/index.js";
|
|
14
|
-
const
|
|
15
|
-
const latestUserMessage = task.history
|
|
16
|
-
|
|
17
|
-
?.
|
|
14
|
+
const taskToMessageParams = (task) => {
|
|
15
|
+
const latestUserMessage = task.history?.filter((msg) => msg.role === "user")?.pop() ??
|
|
16
|
+
/**fallback to the first message if no user message is found */
|
|
17
|
+
task.history?.[0];
|
|
18
18
|
if (!latestUserMessage) {
|
|
19
19
|
throw INVALID_REQUEST("No user message found");
|
|
20
20
|
}
|
|
21
|
+
if (latestUserMessage.contextId &&
|
|
22
|
+
latestUserMessage.contextId !== task.contextId) {
|
|
23
|
+
throw INVALID_REQUEST("User message context ID does not match task context ID");
|
|
24
|
+
}
|
|
21
25
|
const messageParams = {
|
|
22
26
|
message: {
|
|
23
27
|
...latestUserMessage,
|
|
@@ -31,10 +35,29 @@ const createMessageParams = (task) => {
|
|
|
31
35
|
/**
|
|
32
36
|
* @note Comprehensive Extension system coming in a future release
|
|
33
37
|
*/
|
|
34
|
-
const getExtensions = async (_extensions) => {
|
|
38
|
+
const getExtensions = async (_extensions, _forwardExtensions) => {
|
|
35
39
|
// logger.warn("getExtensions: not implemented", { extensions });
|
|
36
40
|
return [];
|
|
37
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Binds a notifier to a context
|
|
44
|
+
* @param notifier - The notifier to bind
|
|
45
|
+
* @param context - The context to bind the notifier to
|
|
46
|
+
* @returns A new notifier that is bound to the context
|
|
47
|
+
*/
|
|
48
|
+
const bindNotifier = async (context, taskId, config, notifier) => {
|
|
49
|
+
if (!notifier || !config) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
context.publisher.on("update", async (task, update) => {
|
|
53
|
+
await notifier.notify(task, update, context).catch((error) => {
|
|
54
|
+
logger.error("Error sending push notification: ", { error });
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
await notifier.register(taskId, config).catch((error) => {
|
|
58
|
+
logger.error("Error registering push notification: ", { error });
|
|
59
|
+
});
|
|
60
|
+
};
|
|
38
61
|
/**
|
|
39
62
|
* @note We endeavor to remove all optional parameters from below this class.
|
|
40
63
|
* This will allow the service to act as the boundary to our Hexagonal Architecture.
|
|
@@ -47,9 +70,9 @@ export class Service {
|
|
|
47
70
|
_tasks;
|
|
48
71
|
_contexts;
|
|
49
72
|
_streams;
|
|
50
|
-
|
|
73
|
+
_handles;
|
|
51
74
|
_overrides;
|
|
52
|
-
constructor(_agentCard, _engine, _connections, _cancellations, _tasks, _contexts, _streams,
|
|
75
|
+
constructor(_agentCard, _engine, _connections, _cancellations, _tasks, _contexts, _streams, _handles, _overrides) {
|
|
53
76
|
this._agentCard = _agentCard;
|
|
54
77
|
this._engine = _engine;
|
|
55
78
|
this._connections = _connections;
|
|
@@ -57,16 +80,16 @@ export class Service {
|
|
|
57
80
|
this._tasks = _tasks;
|
|
58
81
|
this._contexts = _contexts;
|
|
59
82
|
this._streams = _streams;
|
|
60
|
-
this.
|
|
83
|
+
this._handles = _handles;
|
|
61
84
|
this._overrides = _overrides;
|
|
62
85
|
}
|
|
63
|
-
get
|
|
64
|
-
return this.
|
|
86
|
+
get handles() {
|
|
87
|
+
return this._handles;
|
|
65
88
|
}
|
|
66
|
-
set
|
|
67
|
-
this.
|
|
68
|
-
...this.
|
|
69
|
-
...
|
|
89
|
+
set handles(handles) {
|
|
90
|
+
this._handles = {
|
|
91
|
+
...this._handles,
|
|
92
|
+
...handles,
|
|
70
93
|
};
|
|
71
94
|
}
|
|
72
95
|
get agentCard() {
|
|
@@ -125,45 +148,52 @@ export class Service {
|
|
|
125
148
|
}
|
|
126
149
|
return;
|
|
127
150
|
}
|
|
128
|
-
async getTask(params,
|
|
151
|
+
async getTask(params, options) {
|
|
129
152
|
const taskParams = await validateSchema(A2A.TaskQueryParamsSchema, params);
|
|
130
153
|
logger.info(`Service[getTask]:`, { taskId: taskParams.id });
|
|
131
|
-
const task = await this.tasks.get(taskParams.id);
|
|
154
|
+
const task = options?.task ?? (await this.tasks.get(taskParams.id));
|
|
132
155
|
if (!task) {
|
|
133
156
|
throw TASK_NOT_FOUND({ taskId: taskParams.id });
|
|
134
157
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
158
|
+
const userId = options?.userId;
|
|
159
|
+
const messageParams = taskToMessageParams(task);
|
|
160
|
+
const context = await this.contexts.create({
|
|
161
|
+
contextId: task.contextId,
|
|
162
|
+
service: this,
|
|
163
|
+
abortSignal: options?.signal,
|
|
164
|
+
task: task,
|
|
165
|
+
overrides: this.overrides,
|
|
166
|
+
messenger: Messenger.create(messageParams),
|
|
167
|
+
userId: userId,
|
|
168
|
+
});
|
|
169
|
+
return await this.handles.getTask(taskParams, context);
|
|
170
|
+
}
|
|
171
|
+
async cancelTask(params, options) {
|
|
146
172
|
const taskParams = await validateSchema(A2A.TaskIdParamsSchema, params);
|
|
147
173
|
logger.info(`Service[cancelTask]:`, { taskId: taskParams.id });
|
|
148
|
-
const task = await this.tasks.get(taskParams.id);
|
|
174
|
+
const task = options?.task ?? (await this.tasks.get(taskParams.id));
|
|
149
175
|
if (!task) {
|
|
150
176
|
throw TASK_NOT_FOUND({ taskId: taskParams.id });
|
|
151
177
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
178
|
+
const userId = options?.userId;
|
|
179
|
+
const messageParams = taskToMessageParams(task);
|
|
180
|
+
const context = await this.contexts.create({
|
|
181
|
+
contextId: task.contextId,
|
|
182
|
+
service: this,
|
|
183
|
+
abortSignal: options?.signal,
|
|
184
|
+
task: task,
|
|
185
|
+
overrides: this.overrides,
|
|
186
|
+
messenger: Messenger.create(messageParams),
|
|
187
|
+
userId: userId,
|
|
188
|
+
references: await getReferences(this.tasks, messageParams.message.referenceTaskIds),
|
|
189
|
+
});
|
|
190
|
+
return await this.handles.cancelTask(taskParams, context);
|
|
191
|
+
}
|
|
192
|
+
async sendMessage(paramsOrMessage, options) {
|
|
163
193
|
const params = describe.messageSendParams(paramsOrMessage);
|
|
164
|
-
return await this._sendMessage(params,
|
|
194
|
+
return await this._sendMessage(params, options);
|
|
165
195
|
}
|
|
166
|
-
async _sendMessage(params,
|
|
196
|
+
async _sendMessage(params, options) {
|
|
167
197
|
const messageParams = await validateSchema(A2A.MessageSendParamsSchema, params);
|
|
168
198
|
logger.info(`Service[sendMessage]:`, {
|
|
169
199
|
messageId: messageParams.message.messageId,
|
|
@@ -174,61 +204,90 @@ export class Service {
|
|
|
174
204
|
logger.debug(`Service[sendMessage]:`, {
|
|
175
205
|
contextId: messageParams.message.contextId,
|
|
176
206
|
});
|
|
177
|
-
const task =
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
207
|
+
const task = options?.task ??
|
|
208
|
+
(await this.tasks.create({
|
|
209
|
+
id: messageParams.message.taskId,
|
|
210
|
+
contextId: messageParams.message.contextId,
|
|
211
|
+
history: [messageParams.message],
|
|
212
|
+
metadata: {
|
|
213
|
+
...messageParams.metadata,
|
|
214
|
+
},
|
|
215
|
+
}));
|
|
216
|
+
const userId = options?.userId;
|
|
217
|
+
const extensions = await getExtensions(messageParams.message.extensions, options?.extensions);
|
|
218
|
+
const context = await this.contexts.create({
|
|
219
|
+
contextId: task.contextId,
|
|
220
|
+
service: this,
|
|
221
|
+
abortSignal: options?.signal,
|
|
222
|
+
task: task,
|
|
223
|
+
overrides: this.overrides,
|
|
224
|
+
messenger: Messenger.create(messageParams),
|
|
225
|
+
references: await getReferences(this.tasks, messageParams.message.referenceTaskIds),
|
|
226
|
+
extensions: extensions,
|
|
227
|
+
userId: userId,
|
|
184
228
|
});
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
229
|
+
if (options?.notifier) {
|
|
230
|
+
await bindNotifier(context, task.id, messageParams.configuration?.pushNotificationConfig, options.notifier);
|
|
231
|
+
}
|
|
232
|
+
return await this.handles.sendMessage(messageParams, context);
|
|
233
|
+
}
|
|
234
|
+
async *sendMessageStream(_params, options) {
|
|
235
|
+
let params;
|
|
236
|
+
if (typeof _params === "string" ||
|
|
237
|
+
(typeof _params === "object" && "parts" in _params)) {
|
|
238
|
+
params = describe.messageSendParams(_params);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
params = _params;
|
|
242
|
+
}
|
|
243
|
+
const messageParams = await validateSchema(A2A.MessageSendParamsSchema, params);
|
|
244
|
+
yield* this._sendMessageStream(messageParams, options);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* @deprecated Use sendMessageStream instead
|
|
248
|
+
*/
|
|
249
|
+
async *streamMessage(paramsOrMessage, options) {
|
|
198
250
|
const params = describe.messageSendParams(paramsOrMessage);
|
|
199
|
-
yield* this.sendMessageStream(params,
|
|
251
|
+
yield* this.sendMessageStream(params, options);
|
|
200
252
|
}
|
|
201
|
-
async *
|
|
253
|
+
async *_sendMessageStream(params, options) {
|
|
202
254
|
const messageParams = await validateSchema(A2A.MessageSendParamsSchema, params);
|
|
203
255
|
logger.info("Service[streamMessage]:", {
|
|
204
256
|
taskId: messageParams.message.taskId,
|
|
205
257
|
contextId: messageParams.message.contextId,
|
|
206
258
|
});
|
|
207
|
-
const task =
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
259
|
+
const task = options?.task ??
|
|
260
|
+
(await this.tasks.create({
|
|
261
|
+
id: messageParams.message.taskId,
|
|
262
|
+
contextId: messageParams.message.contextId,
|
|
263
|
+
history: [messageParams.message],
|
|
264
|
+
metadata: {
|
|
265
|
+
...messageParams.metadata,
|
|
266
|
+
},
|
|
267
|
+
}));
|
|
215
268
|
logger.debug("Service[streamMessage]: task created", {
|
|
216
269
|
taskId: task.id,
|
|
217
270
|
contextId: task.contextId,
|
|
218
271
|
});
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
272
|
+
const userId = options?.userId;
|
|
273
|
+
const extensions = await getExtensions(messageParams.message.extensions, options?.extensions);
|
|
274
|
+
const context = await this.contexts.create({
|
|
275
|
+
contextId: task.contextId,
|
|
276
|
+
service: this,
|
|
277
|
+
abortSignal: options?.signal,
|
|
278
|
+
task: task,
|
|
279
|
+
overrides: this.overrides,
|
|
280
|
+
messenger: Messenger.create(messageParams),
|
|
281
|
+
references: await getReferences(this.tasks, messageParams.message.referenceTaskIds),
|
|
282
|
+
extensions: extensions,
|
|
283
|
+
userId: userId,
|
|
284
|
+
});
|
|
285
|
+
if (options?.notifier) {
|
|
286
|
+
await bindNotifier(context, task.id, messageParams.configuration?.pushNotificationConfig, options.notifier);
|
|
287
|
+
}
|
|
288
|
+
yield* this.handles.streamMessage(messageParams, context);
|
|
289
|
+
}
|
|
290
|
+
async *resubscribe(params, options) {
|
|
232
291
|
const taskParams = await validateSchema(A2A.TaskIdParamsSchema, params);
|
|
233
292
|
logger.info(`Service[resubscribe]:`, { taskId: taskParams.id });
|
|
234
293
|
const task = await this.tasks.get(taskParams.id);
|
|
@@ -239,15 +298,24 @@ export class Service {
|
|
|
239
298
|
taskId: task.id,
|
|
240
299
|
contextId: task.contextId,
|
|
241
300
|
});
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
301
|
+
const messageParams = taskToMessageParams(task);
|
|
302
|
+
const userId = options?.userId;
|
|
303
|
+
const extensions = await getExtensions(messageParams.message.extensions, options?.extensions);
|
|
304
|
+
const context = await this.contexts.create({
|
|
305
|
+
contextId: task.contextId,
|
|
306
|
+
service: this,
|
|
307
|
+
abortSignal: options?.signal,
|
|
308
|
+
task: task,
|
|
309
|
+
overrides: this.overrides,
|
|
310
|
+
references: await getReferences(this.tasks, messageParams.message.referenceTaskIds),
|
|
311
|
+
messenger: Messenger.create(messageParams),
|
|
312
|
+
extensions: extensions,
|
|
313
|
+
userId: userId,
|
|
314
|
+
});
|
|
315
|
+
if (options?.notifier) {
|
|
316
|
+
await bindNotifier(context, task.id, messageParams.configuration?.pushNotificationConfig, options.notifier);
|
|
317
|
+
}
|
|
318
|
+
yield* this.handles.resubscribe(taskParams, context);
|
|
251
319
|
}
|
|
252
320
|
static create(params) {
|
|
253
321
|
return createService(params);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventEmitter } from "
|
|
1
|
+
import { EventEmitter } from "eventemitter3";
|
|
2
2
|
import { INTERNAL_ERROR } from "../../utils/index.js";
|
|
3
3
|
import { logger } from "../../config/index.js";
|
|
4
4
|
import { createStateMachine } from "./factory/state-machine.js";
|
|
@@ -34,6 +34,7 @@ export class StateMachine extends EventEmitter {
|
|
|
34
34
|
if (this.consumer.onError) {
|
|
35
35
|
await this.consumer.onError(error, this.currentTask);
|
|
36
36
|
}
|
|
37
|
+
//TODO: no longer necessary with eventemitter3
|
|
37
38
|
if (!this.listenerCount("error"))
|
|
38
39
|
return;
|
|
39
40
|
this.emit("error", error, this.currentTask);
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* Copyright 2025 The Artinet Project
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
+
/**
|
|
6
|
+
* Manager should optionally take a persistent storage object as a constructor parameter,
|
|
7
|
+
* That way we don't need to re-implement the same caching logic for each derived manager.
|
|
8
|
+
*/
|
|
5
9
|
export declare abstract class Manager<T> {
|
|
6
10
|
private _data;
|
|
7
11
|
private throwOnSet;
|
|
@@ -13,3 +17,4 @@ export declare abstract class Manager<T> {
|
|
|
13
17
|
has(id: string): Promise<boolean>;
|
|
14
18
|
list(): Promise<T[]>;
|
|
15
19
|
}
|
|
20
|
+
export declare const ResourceManager: typeof Manager;
|
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { logger } from "../../config/index.js";
|
|
6
|
+
//TODO: Add persistence layer plugin support and turn Manager into an LRU cache.
|
|
7
|
+
/**
|
|
8
|
+
* Manager should optionally take a persistent storage object as a constructor parameter,
|
|
9
|
+
* That way we don't need to re-implement the same caching logic for each derived manager.
|
|
10
|
+
*/
|
|
6
11
|
export class Manager {
|
|
7
12
|
_data;
|
|
8
13
|
throwOnSet;
|
|
@@ -40,3 +45,4 @@ export class Manager {
|
|
|
40
45
|
return Array.from(this.data.values());
|
|
41
46
|
}
|
|
42
47
|
}
|
|
48
|
+
export const ResourceManager = Manager;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
6
|
import { A2A } from "../../types/index.js";
|
|
7
|
-
import { formatJson } from "../../utils/
|
|
7
|
+
import { formatJson } from "../../utils/utils.js";
|
|
8
8
|
export class BaseMCPService extends McpServer {
|
|
9
9
|
agent;
|
|
10
10
|
_registerBaseTools(uri = "agent://card") {
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Copyright 2025 The Artinet Project
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import { A2A } from "
|
|
6
|
-
import { Tasks } from "
|
|
5
|
+
import { A2A } from "../types/index.js";
|
|
6
|
+
import { Tasks } from "../services/a2a/managers.js";
|
|
7
7
|
/**
|
|
8
8
|
* File-based implementation of the TaskStore interface.
|
|
9
9
|
* Stores tasks and their history as JSON files on disk.
|
|
@@ -55,3 +55,5 @@ export declare class Files extends Tasks {
|
|
|
55
55
|
has(taskId: string): Promise<boolean>;
|
|
56
56
|
list(): Promise<A2A.Task[]>;
|
|
57
57
|
}
|
|
58
|
+
export declare const FileStore: typeof Files;
|
|
59
|
+
export type FileStore = typeof FileStore;
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* Copyright 2025 The Artinet Project
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import { A2A } from "
|
|
5
|
+
import { A2A } from "../types/index.js";
|
|
6
6
|
import fs from "fs/promises";
|
|
7
7
|
import path from "path";
|
|
8
|
-
import { logger } from "
|
|
9
|
-
import { Tasks } from "
|
|
10
|
-
import { formatJson, safeParseSchema } from "../index.js";
|
|
8
|
+
import { logger } from "../config/index.js";
|
|
9
|
+
import { Tasks } from "../services/a2a/managers.js";
|
|
10
|
+
import { formatJson, safeParseSchema } from "../utils/index.js";
|
|
11
11
|
/**
|
|
12
12
|
* File-based implementation of the TaskStore interface.
|
|
13
13
|
* Stores tasks and their history as JSON files on disk.
|
|
@@ -129,3 +129,4 @@ export class Files extends Tasks {
|
|
|
129
129
|
return Promise.all(taskIds.map((taskId) => this.get(taskId).catch(() => undefined))).then((tasks) => tasks.filter((task) => task !== undefined));
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
+
export const FileStore = Files;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./file.js";
|