@artinet/sdk 0.5.17 → 0.6.0-preview.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 +51 -557
- package/dist/browser/browser.d.ts +9 -0
- package/dist/browser/browser.js +10 -0
- package/dist/browser/client/a2a-client.d.ts +127 -0
- package/dist/browser/client/a2a-client.js +233 -0
- package/dist/browser/client/index.d.ts +1 -0
- package/dist/browser/client/index.js +1 -0
- package/dist/browser/config/index.d.ts +158 -0
- package/dist/browser/config/index.js +155 -0
- package/dist/browser/config/observability.d.ts +119 -0
- package/dist/browser/config/observability.js +35 -0
- package/dist/browser/services/a2a/helpers/message-builder.d.ts +17 -0
- package/dist/browser/services/a2a/helpers/message-builder.js +66 -0
- package/dist/browser/transport/rpc/parser.d.ts +15 -0
- package/dist/browser/transport/rpc/parser.js +48 -0
- package/dist/browser/transport/rpc/rpc-client.d.ts +80 -0
- package/dist/browser/transport/rpc/rpc-client.js +189 -0
- package/dist/browser/transport/streaming/event-stream.d.ts +25 -0
- package/dist/browser/transport/streaming/event-stream.js +100 -0
- package/dist/browser/types/a2a/a2a.d.ts +378 -0
- package/dist/browser/types/a2a/a2a.js +14 -0
- package/dist/browser/types/a2a/builder.d.ts +43 -0
- package/dist/browser/types/a2a/index.d.ts +3 -0
- package/dist/browser/types/a2a/index.js +2 -0
- package/dist/{types/interfaces → browser/types}/client.d.ts +25 -27
- package/dist/browser/types/core/core.d.ts +31 -0
- package/dist/browser/types/core/index.d.ts +1 -0
- package/dist/browser/types/core/index.js +1 -0
- package/dist/{types/interfaces/services → browser/types}/index.d.ts +3 -0
- package/dist/{types/interfaces/services → browser/types}/index.js +3 -0
- package/dist/browser/types/mcp/index.d.ts +1 -0
- package/dist/browser/types/mcp/index.js +1 -0
- package/dist/{types/interfaces/services/mcp/service.d.ts → browser/types/mcp/mcp.d.ts} +4 -3
- package/dist/browser/types/mcp/mcp.js +5 -0
- package/dist/browser/types/storage.d.ts +21 -0
- package/dist/browser/types/utils/index.d.ts +1 -0
- package/dist/browser/types/utils/index.js +1 -0
- package/dist/browser/types/utils/transform.d.ts +64 -0
- package/dist/browser/types/utils/transform.js +35 -0
- package/dist/browser/utils/common/constants.d.ts +11 -0
- package/dist/browser/utils/common/constants.js +38 -0
- package/dist/browser/utils/common/errors.d.ts +24 -0
- package/dist/browser/utils/common/errors.js +42 -0
- package/dist/browser/utils/common/utils.d.ts +32 -0
- package/dist/browser/utils/common/utils.js +43 -0
- package/dist/client/a2a-client.d.ts +21 -19
- package/dist/client/a2a-client.js +30 -9
- package/dist/config/default.d.ts +50 -0
- package/dist/config/default.js +62 -0
- package/dist/config/index.d.ts +158 -0
- package/dist/config/index.js +155 -0
- package/dist/config/observability.d.ts +119 -0
- package/dist/config/observability.js +35 -0
- package/dist/extensions/otel.d.ts +98 -0
- package/dist/extensions/otel.js +190 -0
- package/dist/extensions/pino.d.ts +44 -0
- package/dist/extensions/pino.js +107 -0
- package/dist/extensions/winston.d.ts +47 -0
- package/dist/extensions/winston.js +114 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/server/express/errors.js +3 -3
- package/dist/server/express/middeware.d.ts +2 -2
- package/dist/server/express/middeware.js +36 -9
- package/dist/server/express/server.d.ts +9 -55
- package/dist/server/express/server.js +51 -32
- package/dist/services/a2a/execute.d.ts +6 -0
- package/dist/services/a2a/execute.js +25 -0
- package/dist/services/a2a/factory/builder.d.ts +21 -80
- package/dist/services/a2a/factory/builder.js +23 -13
- package/dist/services/a2a/factory/context.d.ts +15 -128
- package/dist/services/a2a/factory/context.js +31 -136
- package/dist/services/a2a/factory/handler.d.ts +6 -0
- package/dist/services/a2a/factory/{method.js → handler.js} +2 -2
- package/dist/services/a2a/factory/index.d.ts +1 -2
- package/dist/services/a2a/factory/index.js +1 -2
- package/dist/services/a2a/factory/service.d.ts +20 -7
- package/dist/services/a2a/factory/service.js +4 -4
- package/dist/services/a2a/factory/state-machine.d.ts +11 -0
- package/dist/services/a2a/factory/state-machine.js +66 -0
- package/dist/services/a2a/{state/update → handlers}/artifact.d.ts +4 -4
- package/dist/services/a2a/handlers/cancel-task.d.ts +11 -0
- package/dist/services/a2a/handlers/cancel-task.js +33 -0
- package/dist/services/a2a/handlers/get-task.d.ts +11 -0
- package/dist/services/a2a/handlers/get-task.js +13 -0
- package/dist/services/a2a/handlers/resubscribe-task.d.ts +11 -0
- package/dist/services/a2a/handlers/resubscribe-task.js +56 -0
- package/dist/services/a2a/handlers/send-message.d.ts +11 -0
- package/dist/services/a2a/handlers/send-message.js +35 -0
- package/dist/services/a2a/handlers/stream-message.d.ts +11 -0
- package/dist/services/a2a/handlers/stream-message.js +19 -0
- package/dist/services/a2a/handlers/update.d.ts +17 -0
- package/dist/services/a2a/handlers/update.js +114 -0
- package/dist/services/a2a/helpers/agentcard-builder.d.ts +9 -5
- package/dist/services/a2a/helpers/agentcard-builder.js +5 -0
- package/dist/services/a2a/helpers/content.d.ts +2 -2
- package/dist/services/a2a/helpers/content.js +4 -0
- package/dist/services/a2a/helpers/history.d.ts +6 -0
- package/dist/services/a2a/helpers/history.js +7 -0
- package/dist/services/a2a/helpers/index.d.ts +3 -1
- package/dist/services/a2a/helpers/index.js +3 -1
- package/dist/services/a2a/helpers/message-builder.d.ts +13 -8
- package/dist/services/a2a/helpers/message-builder.js +5 -0
- package/dist/services/a2a/helpers/part.d.ts +9 -9
- package/dist/services/a2a/helpers/references.d.ts +6 -0
- package/dist/services/a2a/helpers/references.js +22 -0
- package/dist/services/a2a/index.d.ts +9 -5
- package/dist/services/a2a/index.js +8 -5
- package/dist/services/a2a/managers.d.ts +23 -0
- package/dist/services/a2a/managers.js +95 -0
- package/dist/services/a2a/messenger.d.ts +35 -0
- package/dist/services/{core/managers/command.js → a2a/messenger.js} +27 -31
- package/dist/services/a2a/service.d.ts +41 -371
- package/dist/services/a2a/service.js +239 -70
- package/dist/services/a2a/state-machine.d.ts +18 -0
- package/dist/services/a2a/state-machine.js +76 -0
- package/dist/services/a2a/streams.d.ts +22 -0
- package/dist/services/a2a/streams.js +98 -0
- package/dist/services/core/index.d.ts +1 -2
- package/dist/services/core/index.js +1 -2
- package/dist/services/core/manager.d.ts +15 -0
- package/dist/services/core/manager.js +42 -0
- package/dist/services/mcp/service.d.ts +11 -15
- package/dist/services/mcp/service.js +16 -16
- package/dist/transport/index.d.ts +0 -1
- package/dist/transport/index.js +1 -1
- package/dist/transport/rpc/parser.d.ts +2 -2
- package/dist/transport/rpc/parser.js +7 -7
- package/dist/transport/rpc/rpc-client.d.ts +5 -5
- package/dist/transport/rpc/rpc-client.js +7 -7
- package/dist/transport/streaming/event-stream.d.ts +3 -3
- package/dist/transport/streaming/event-stream.js +11 -10
- package/dist/transport/trpc/a2a/factory/router.d.ts +479 -871
- package/dist/transport/trpc/a2a/factory/router.js +2 -2
- package/dist/transport/trpc/a2a/routes/info.d.ts +108 -8
- package/dist/transport/trpc/a2a/routes/info.js +6 -2
- package/dist/transport/trpc/a2a/routes/message/route.d.ts +113 -162
- package/dist/transport/trpc/a2a/routes/message/route.js +7 -13
- package/dist/transport/trpc/a2a/routes/tasks/route.d.ts +114 -212
- package/dist/transport/trpc/a2a/routes/tasks/route.js +16 -19
- package/dist/transport/trpc/a2a/trpc.d.ts +9 -253
- package/dist/types/a2a/a2a.d.ts +378 -0
- package/dist/types/a2a/a2a.js +14 -0
- package/dist/types/a2a/builder.d.ts +43 -0
- package/dist/types/a2a/index.d.ts +3 -0
- package/dist/types/a2a/index.js +2 -0
- package/dist/types/client.d.ts +133 -0
- package/dist/types/core/core.d.ts +31 -0
- package/dist/types/core/core.js +1 -0
- package/dist/types/core/index.d.ts +1 -0
- package/dist/types/core/index.js +1 -0
- package/dist/types/index.d.ts +6 -3
- package/dist/types/index.js +6 -3
- package/dist/types/mcp/index.d.ts +1 -0
- package/dist/types/mcp/index.js +1 -0
- package/dist/types/mcp/mcp.d.ts +50 -0
- package/dist/types/mcp/mcp.js +5 -0
- package/dist/types/protocol.d.ts +33 -0
- package/dist/types/protocol.js +34 -0
- package/dist/types/storage.d.ts +21 -0
- package/dist/utils/common/constants.d.ts +7 -7
- package/dist/utils/common/constants.js +10 -10
- package/dist/utils/common/errors.d.ts +18 -17
- package/dist/utils/common/errors.js +14 -13
- package/dist/utils/common/parse.d.ts +7 -0
- package/dist/utils/common/parse.js +14 -0
- package/dist/utils/common/schema-validation.d.ts +2 -0
- package/dist/utils/common/schema-validation.js +12 -0
- package/dist/utils/common/utils.d.ts +23 -0
- package/dist/utils/common/utils.js +32 -0
- package/dist/utils/common/zAsyncIterable-v3.d.ts +1 -1
- package/dist/utils/common/zAsyncIterable-v3.js +2 -1
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +3 -3
- package/dist/utils/storage/file.d.ts +8 -17
- package/dist/utils/storage/file.js +44 -73
- package/package.json +86 -23
- package/dist/services/a2a/factory/event.d.ts +0 -58
- package/dist/services/a2a/factory/event.js +0 -177
- package/dist/services/a2a/factory/method.d.ts +0 -6
- package/dist/services/a2a/managers/cancellation.d.ts +0 -11
- package/dist/services/a2a/managers/cancellation.js +0 -16
- package/dist/services/a2a/managers/connection.d.ts +0 -11
- package/dist/services/a2a/managers/connection.js +0 -16
- package/dist/services/a2a/managers/context.d.ts +0 -11
- package/dist/services/a2a/managers/context.js +0 -16
- package/dist/services/a2a/managers/index.d.ts +0 -5
- package/dist/services/a2a/managers/index.js +0 -5
- package/dist/services/a2a/managers/task.d.ts +0 -11
- package/dist/services/a2a/managers/task.js +0 -16
- package/dist/services/a2a/methods/cancel-task.d.ts +0 -7
- package/dist/services/a2a/methods/cancel-task.js +0 -43
- package/dist/services/a2a/methods/get-task.d.ts +0 -112
- package/dist/services/a2a/methods/get-task.js +0 -14
- package/dist/services/a2a/methods/resubscribe-task.d.ts +0 -7
- package/dist/services/a2a/methods/resubscribe-task.js +0 -80
- package/dist/services/a2a/methods/send-message.d.ts +0 -7
- package/dist/services/a2a/methods/send-message.js +0 -19
- package/dist/services/a2a/methods/stream-message.d.ts +0 -8
- package/dist/services/a2a/methods/stream-message.js +0 -21
- package/dist/services/a2a/state/index.d.ts +0 -3
- package/dist/services/a2a/state/index.js +0 -3
- package/dist/services/a2a/state/load.d.ts +0 -14
- package/dist/services/a2a/state/load.js +0 -71
- package/dist/services/a2a/state/process.d.ts +0 -7
- package/dist/services/a2a/state/process.js +0 -13
- package/dist/services/a2a/state/update/index.d.ts +0 -2
- package/dist/services/a2a/state/update/index.js +0 -2
- package/dist/services/a2a/state/update/update.d.ts +0 -23
- package/dist/services/a2a/state/update/update.js +0 -123
- package/dist/services/core/execution/execute.d.ts +0 -6
- package/dist/services/core/execution/execute.js +0 -25
- package/dist/services/core/execution/index.d.ts +0 -1
- package/dist/services/core/execution/index.js +0 -1
- package/dist/services/core/managers/command.d.ts +0 -39
- package/dist/services/core/managers/event.d.ts +0 -18
- package/dist/services/core/managers/event.js +0 -56
- package/dist/services/core/managers/index.d.ts +0 -3
- package/dist/services/core/managers/index.js +0 -3
- package/dist/services/core/managers/stream.d.ts +0 -20
- package/dist/services/core/managers/stream.js +0 -77
- package/dist/types/ext.d.ts +0 -13
- package/dist/types/ext.js +0 -10
- package/dist/types/interfaces/index.d.ts +0 -3
- package/dist/types/interfaces/index.js +0 -3
- package/dist/types/interfaces/services/a2a/builder.d.ts +0 -37
- package/dist/types/interfaces/services/a2a/context.d.ts +0 -162
- package/dist/types/interfaces/services/a2a/engine.d.ts +0 -7
- package/dist/types/interfaces/services/a2a/index.d.ts +0 -5
- package/dist/types/interfaces/services/a2a/index.js +0 -5
- package/dist/types/interfaces/services/a2a/legacy.d.ts +0 -93
- package/dist/types/interfaces/services/a2a/service.d.ts +0 -409
- package/dist/types/interfaces/services/a2a/service.js +0 -5
- package/dist/types/interfaces/services/core/context/command.d.ts +0 -25
- package/dist/types/interfaces/services/core/context/command.js +0 -5
- package/dist/types/interfaces/services/core/context/context.d.ts +0 -207
- package/dist/types/interfaces/services/core/context/context.js +0 -5
- package/dist/types/interfaces/services/core/context/index.d.ts +0 -3
- package/dist/types/interfaces/services/core/context/index.js +0 -3
- package/dist/types/interfaces/services/core/context/types.d.ts +0 -11
- package/dist/types/interfaces/services/core/context/types.js +0 -5
- package/dist/types/interfaces/services/core/execution/engine.d.ts +0 -106
- package/dist/types/interfaces/services/core/execution/engine.js +0 -5
- package/dist/types/interfaces/services/core/execution/environment.d.ts +0 -11
- package/dist/types/interfaces/services/core/execution/environment.js +0 -5
- package/dist/types/interfaces/services/core/execution/execute.d.ts +0 -7
- package/dist/types/interfaces/services/core/execution/execute.js +0 -5
- package/dist/types/interfaces/services/core/execution/index.d.ts +0 -3
- package/dist/types/interfaces/services/core/execution/index.js +0 -3
- package/dist/types/interfaces/services/core/index.d.ts +0 -4
- package/dist/types/interfaces/services/core/index.js +0 -4
- package/dist/types/interfaces/services/core/managers/cancellation.d.ts +0 -9
- package/dist/types/interfaces/services/core/managers/cancellation.js +0 -5
- package/dist/types/interfaces/services/core/managers/connection.d.ts +0 -9
- package/dist/types/interfaces/services/core/managers/connection.js +0 -5
- package/dist/types/interfaces/services/core/managers/context.d.ts +0 -17
- package/dist/types/interfaces/services/core/managers/context.js +0 -5
- package/dist/types/interfaces/services/core/managers/event.d.ts +0 -328
- package/dist/types/interfaces/services/core/managers/event.js +0 -5
- package/dist/types/interfaces/services/core/managers/index.d.ts +0 -6
- package/dist/types/interfaces/services/core/managers/index.js +0 -6
- package/dist/types/interfaces/services/core/managers/stream.d.ts +0 -217
- package/dist/types/interfaces/services/core/managers/stream.js +0 -5
- package/dist/types/interfaces/services/core/managers/task.d.ts +0 -9
- package/dist/types/interfaces/services/core/service.d.ts +0 -115
- package/dist/types/interfaces/services/core/service.js +0 -5
- package/dist/types/interfaces/services/mcp/index.d.ts +0 -1
- package/dist/types/interfaces/services/mcp/index.js +0 -1
- package/dist/types/interfaces/services/mcp/service.js +0 -5
- package/dist/types/interfaces/storage.d.ts +0 -8
- package/dist/types/schemas/a2a/agent.d.ts +0 -2583
- package/dist/types/schemas/a2a/agent.js +0 -323
- package/dist/types/schemas/a2a/auth.d.ts +0 -908
- package/dist/types/schemas/a2a/auth.js +0 -283
- package/dist/types/schemas/a2a/error.d.ts +0 -396
- package/dist/types/schemas/a2a/error.js +0 -163
- package/dist/types/schemas/a2a/index.d.ts +0 -11
- package/dist/types/schemas/a2a/index.js +0 -11
- package/dist/types/schemas/a2a/kind.d.ts +0 -11
- package/dist/types/schemas/a2a/kind.js +0 -20
- package/dist/types/schemas/a2a/message.d.ts +0 -10343
- package/dist/types/schemas/a2a/message.js +0 -130
- package/dist/types/schemas/a2a/notification.d.ts +0 -1517
- package/dist/types/schemas/a2a/notification.js +0 -203
- package/dist/types/schemas/a2a/parameters.d.ts +0 -956
- package/dist/types/schemas/a2a/parameters.js +0 -241
- package/dist/types/schemas/a2a/protocol.d.ts +0 -14363
- package/dist/types/schemas/a2a/protocol.js +0 -59
- package/dist/types/schemas/a2a/rpc.d.ts +0 -182
- package/dist/types/schemas/a2a/rpc.js +0 -126
- package/dist/types/schemas/a2a/task.d.ts +0 -5886
- package/dist/types/schemas/a2a/task.js +0 -134
- package/dist/types/schemas/a2a/transport.d.ts +0 -31
- package/dist/types/schemas/a2a/transport.js +0 -28
- package/dist/types/schemas/index.d.ts +0 -1
- package/dist/types/schemas/index.js +0 -1
- package/dist/utils/logging/index.d.ts +0 -2
- package/dist/utils/logging/index.js +0 -2
- package/dist/utils/logging/log.d.ts +0 -33
- package/dist/utils/logging/log.js +0 -75
- package/dist/utils/logging/logger.d.ts +0 -18
- package/dist/utils/logging/logger.js +0 -18
- package/dist/utils/storage/memory.d.ts +0 -25
- package/dist/utils/storage/memory.js +0 -47
- /package/dist/{types/interfaces/services → browser/types}/a2a/builder.js +0 -0
- /package/dist/{types/interfaces → browser/types}/client.js +0 -0
- /package/dist/{types/interfaces/services/core/managers/task.js → browser/types/core/core.js} +0 -0
- /package/dist/{types/interfaces/services → browser/types}/protocol.d.ts +0 -0
- /package/dist/{types/interfaces/services → browser/types}/protocol.js +0 -0
- /package/dist/{types/interfaces → browser/types}/storage.js +0 -0
- /package/dist/services/a2a/{state/update → handlers}/artifact.js +0 -0
- /package/dist/services/a2a/{methods → handlers}/index.d.ts +0 -0
- /package/dist/services/a2a/{methods → handlers}/index.js +0 -0
- /package/dist/types/{interfaces/services/a2a/context.js → a2a/builder.js} +0 -0
- /package/dist/types/{interfaces/services/a2a/engine.js → client.js} +0 -0
- /package/dist/types/{interfaces/services/a2a/legacy.js → storage.js} +0 -0
|
@@ -2,21 +2,26 @@
|
|
|
2
2
|
* Copyright 2025 The Artinet Project
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { A2A } from "../../types/index.js";
|
|
6
6
|
import fs from "fs/promises";
|
|
7
7
|
import path from "path";
|
|
8
|
+
import { logger } from "../../config/index.js";
|
|
9
|
+
import { Tasks } from "../../services/a2a/managers.js";
|
|
10
|
+
import { formatJson, safeParseSchema } from "../index.js";
|
|
8
11
|
/**
|
|
9
12
|
* File-based implementation of the TaskStore interface.
|
|
10
13
|
* Stores tasks and their history as JSON files on disk.
|
|
11
14
|
*/
|
|
12
|
-
export class
|
|
15
|
+
export class Files extends Tasks {
|
|
13
16
|
baseDir;
|
|
14
17
|
/**
|
|
15
18
|
* Creates a new FileStore.
|
|
16
19
|
* @param baseDir The base directory to store task files in.
|
|
17
20
|
*/
|
|
18
21
|
constructor(baseDir) {
|
|
22
|
+
super(new Map());
|
|
19
23
|
this.baseDir = baseDir;
|
|
24
|
+
logger.info(`FileStore[init]: baseDir`, { baseDir });
|
|
20
25
|
}
|
|
21
26
|
/**
|
|
22
27
|
* Constructs the file path for a task.
|
|
@@ -26,14 +31,6 @@ export class FileStore {
|
|
|
26
31
|
getTaskFilePath(taskId) {
|
|
27
32
|
return path.join(this.baseDir, `${taskId}.task.json`);
|
|
28
33
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Constructs the file path for a task's history.
|
|
31
|
-
* @param taskId The task ID
|
|
32
|
-
* @returns The full file path for the history JSON file
|
|
33
|
-
*/
|
|
34
|
-
getHistoryFilePath(taskId) {
|
|
35
|
-
return path.join(this.baseDir, `${taskId}.history.json`);
|
|
36
|
-
}
|
|
37
34
|
/**
|
|
38
35
|
* Ensures the base directory exists.
|
|
39
36
|
* @returns A promise that resolves when the directory exists.
|
|
@@ -43,7 +40,7 @@ export class FileStore {
|
|
|
43
40
|
await fs.mkdir(this.baseDir, { recursive: true });
|
|
44
41
|
}
|
|
45
42
|
catch (error) {
|
|
46
|
-
|
|
43
|
+
logger.warn(`FileStore[ensureBaseDir]: ${this.baseDir}`, error);
|
|
47
44
|
throw error;
|
|
48
45
|
}
|
|
49
46
|
}
|
|
@@ -53,15 +50,15 @@ export class FileStore {
|
|
|
53
50
|
* @param data The data to write
|
|
54
51
|
* @returns A promise that resolves when the write is complete
|
|
55
52
|
*/
|
|
56
|
-
async writeJsonFile(filePath,
|
|
53
|
+
async writeJsonFile(filePath, task) {
|
|
57
54
|
try {
|
|
58
55
|
await this.ensureBaseDir();
|
|
59
|
-
await fs.writeFile(filePath,
|
|
56
|
+
await fs.writeFile(filePath, formatJson(task), {
|
|
60
57
|
encoding: "utf8",
|
|
61
58
|
});
|
|
62
59
|
}
|
|
63
60
|
catch (error) {
|
|
64
|
-
|
|
61
|
+
logger.warn(`FileStore[writeJsonFile]: ${filePath}`, error);
|
|
65
62
|
throw error;
|
|
66
63
|
}
|
|
67
64
|
}
|
|
@@ -73,88 +70,62 @@ export class FileStore {
|
|
|
73
70
|
async readJsonFile(filePath) {
|
|
74
71
|
try {
|
|
75
72
|
const content = await fs.readFile(filePath, { encoding: "utf8" });
|
|
76
|
-
return
|
|
73
|
+
return await safeParseSchema(content, A2A.TaskSchema);
|
|
77
74
|
}
|
|
78
75
|
catch (error) {
|
|
79
76
|
if (error.code === "ENOENT") {
|
|
80
|
-
|
|
77
|
+
logger.warn(`FileStore[readJsonFile]: ${filePath} not found`);
|
|
81
78
|
return null;
|
|
82
79
|
}
|
|
83
|
-
logError("FileStore", `Failed to read file: ${filePath}`, error);
|
|
84
80
|
throw error;
|
|
85
81
|
}
|
|
86
82
|
}
|
|
87
|
-
/**
|
|
88
|
-
* Type guard to validate the structure of history file content.
|
|
89
|
-
* @param content The content to check
|
|
90
|
-
* @returns True if the content is a valid history file content
|
|
91
|
-
*/
|
|
92
|
-
isHistoryFileContent(content) {
|
|
93
|
-
return (content !== undefined &&
|
|
94
|
-
typeof content === "object" &&
|
|
95
|
-
content !== null &&
|
|
96
|
-
"messageHistory" in content &&
|
|
97
|
-
Array.isArray(content.messageHistory));
|
|
98
|
-
}
|
|
99
83
|
/**
|
|
100
84
|
* Loads a task and its history by task ID.
|
|
101
85
|
* @param taskId The ID of the task to load.
|
|
102
86
|
* @returns A promise resolving to the task and history, or null if not found.
|
|
103
87
|
*/
|
|
104
|
-
async
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
// Read task file first - if it doesn't exist, the task doesn't exist.
|
|
109
|
-
const task = await this.readJsonFile(taskFilePath).catch(() => undefined);
|
|
110
|
-
if (!task) {
|
|
111
|
-
return undefined; // Task not found
|
|
112
|
-
}
|
|
113
|
-
// Task exists, now try to read history. It might not exist yet.
|
|
114
|
-
let history = [];
|
|
115
|
-
try {
|
|
116
|
-
const historyContent = await this.readJsonFile(historyFilePath).catch(() => undefined);
|
|
117
|
-
// Validate the structure
|
|
118
|
-
if (this.isHistoryFileContent(historyContent)) {
|
|
119
|
-
history = historyContent.messageHistory;
|
|
120
|
-
}
|
|
121
|
-
else if (historyContent !== null) {
|
|
122
|
-
// Log a warning if the history file exists but is malformed
|
|
123
|
-
logError("FileStore", `Malformed history file found for task ${taskId}`, new Error("Invalid history file format"), { path: historyFilePath });
|
|
124
|
-
// Proceed with empty history
|
|
125
|
-
}
|
|
126
|
-
// If historyContent is null (file not found), history remains []
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
// Log error reading history but proceed with empty history
|
|
130
|
-
logError("FileStore", `Error reading history file for task ${taskId}`, error, { path: historyFilePath });
|
|
131
|
-
// Proceed with empty history
|
|
132
|
-
}
|
|
133
|
-
return { task, history };
|
|
88
|
+
async get(taskId) {
|
|
89
|
+
const task = (await super.get(taskId)) ??
|
|
90
|
+
(await this.readJsonFile(this.getTaskFilePath(taskId)).catch(() => undefined));
|
|
91
|
+
return task ?? undefined;
|
|
134
92
|
}
|
|
135
93
|
/**
|
|
136
94
|
* Saves a task and its history.
|
|
137
95
|
* @param data The task and history to save.
|
|
138
96
|
* @returns A promise that resolves when the save is complete.
|
|
139
97
|
*/
|
|
140
|
-
async
|
|
141
|
-
|
|
142
|
-
if (
|
|
98
|
+
async set(taskId, task) {
|
|
99
|
+
logger.debug(`FileStore[set]: ${taskId}`);
|
|
100
|
+
if (!task) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (task && taskId !== task.id) {
|
|
104
|
+
logger.warn("FileStore", `Task ID mismatch: ${taskId} !== ${task.id}`);
|
|
143
105
|
throw new Error("Task ID mismatch");
|
|
144
106
|
}
|
|
145
107
|
const taskFilePath = this.getTaskFilePath(taskId);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
await
|
|
153
|
-
|
|
154
|
-
|
|
108
|
+
await this.writeJsonFile(taskFilePath, task);
|
|
109
|
+
await super.set(taskId, task);
|
|
110
|
+
}
|
|
111
|
+
async delete(taskId) {
|
|
112
|
+
logger.debug(`FileStore[delete]: ${taskId}`);
|
|
113
|
+
const taskFilePath = this.getTaskFilePath(taskId);
|
|
114
|
+
await fs.unlink(taskFilePath);
|
|
115
|
+
await super.delete(taskId);
|
|
116
|
+
}
|
|
117
|
+
async has(taskId) {
|
|
118
|
+
if (await super.has(taskId)) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
const taskFilePath = this.getTaskFilePath(taskId);
|
|
122
|
+
return fs
|
|
123
|
+
.access(taskFilePath)
|
|
124
|
+
.then(() => true)
|
|
125
|
+
.catch(() => false);
|
|
155
126
|
}
|
|
156
|
-
async
|
|
127
|
+
async list() {
|
|
157
128
|
const taskIds = await fs.readdir(this.baseDir);
|
|
158
|
-
return taskIds.map((taskId) => taskId.
|
|
129
|
+
return Promise.all(taskIds.map((taskId) => this.get(taskId).catch(() => undefined))).then((tasks) => tasks.filter((task) => task !== undefined));
|
|
159
130
|
}
|
|
160
131
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artinet/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-preview.1",
|
|
4
4
|
"description": "A TypeScript SDK for building collaborative AI agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -8,14 +8,45 @@
|
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
+
"browser": {
|
|
12
|
+
"types": "./dist/browser.d.ts",
|
|
13
|
+
"import": "./dist/browser/browser.js",
|
|
14
|
+
"default": "./dist/browser/browser.js"
|
|
15
|
+
},
|
|
11
16
|
"types": "./dist/index.d.ts",
|
|
12
17
|
"import": "./dist/index.js",
|
|
13
18
|
"default": "./dist/index.js"
|
|
14
19
|
},
|
|
20
|
+
"./trpc": {
|
|
21
|
+
"types": "./dist/transport/trpc/index.d.ts",
|
|
22
|
+
"import": "./dist/transport/trpc/index.js",
|
|
23
|
+
"default": "./dist/transport/trpc/index.js"
|
|
24
|
+
},
|
|
15
25
|
"./types": {
|
|
16
26
|
"types": "./dist/types/index.d.ts",
|
|
17
27
|
"import": "./dist/types/index.js",
|
|
18
28
|
"default": "./dist/types/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./pino": {
|
|
31
|
+
"node": {
|
|
32
|
+
"types": "./dist/extensions/pino.d.ts",
|
|
33
|
+
"import": "./dist/extensions/pino.js",
|
|
34
|
+
"default": "./dist/extensions/pino.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"./winston": {
|
|
38
|
+
"node": {
|
|
39
|
+
"types": "./dist/extensions/winston.d.ts",
|
|
40
|
+
"import": "./dist/extensions/winston.js",
|
|
41
|
+
"default": "./dist/extensions/winston.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"./otel": {
|
|
45
|
+
"node": {
|
|
46
|
+
"types": "./dist/extensions/opentelemetry.d.ts",
|
|
47
|
+
"import": "./dist/extensions/opentelemetry.js",
|
|
48
|
+
"default": "./dist/extensions/opentelemetry.js"
|
|
49
|
+
}
|
|
19
50
|
}
|
|
20
51
|
},
|
|
21
52
|
"rootDir": ".",
|
|
@@ -28,15 +59,16 @@
|
|
|
28
59
|
"scripts": {
|
|
29
60
|
"prepare": "ts-patch install -s",
|
|
30
61
|
"build": "tsc --project tsconfig.json",
|
|
62
|
+
"build:browser": "tsc --project tsconfig.browser.json",
|
|
63
|
+
"build:all": "npm run build && npm run build:browser",
|
|
31
64
|
"clean": "rimraf dist",
|
|
32
|
-
"rebuild": "rimraf dist node_modules/ package-lock.json && npm i && npm run build",
|
|
65
|
+
"rebuild": "rimraf dist node_modules/ package-lock.json && npm i && npm run build:all",
|
|
33
66
|
"lint": "eslint src --ext .ts",
|
|
34
|
-
"prepublishOnly": "npm run
|
|
67
|
+
"prepublishOnly": "npm run rebuild && npm run lint && npm test",
|
|
35
68
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
36
69
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch",
|
|
37
70
|
"test:coverage": "NODE_OPTIONS=--experimental-vm-modules jest --coverage",
|
|
38
|
-
"dev:quickstart": "tsx watch quickstart/quick-server.ts"
|
|
39
|
-
"dev-pack": "rimraf dist node_modules/ && npm i && npm run build && npm pack"
|
|
71
|
+
"dev:quickstart": "tsx watch quickstart/quick-server.ts"
|
|
40
72
|
},
|
|
41
73
|
"keywords": [
|
|
42
74
|
"agent2agent",
|
|
@@ -44,13 +76,9 @@
|
|
|
44
76
|
"artinet",
|
|
45
77
|
"ai",
|
|
46
78
|
"agent",
|
|
47
|
-
"sdk",
|
|
48
79
|
"artificial intelligence",
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"multi-agent system",
|
|
52
|
-
"orchestration",
|
|
53
|
-
"swarms"
|
|
80
|
+
"mcp",
|
|
81
|
+
"modelcontextprotocol"
|
|
54
82
|
],
|
|
55
83
|
"author": "artinet",
|
|
56
84
|
"license": "Apache-2.0",
|
|
@@ -63,28 +91,62 @@
|
|
|
63
91
|
},
|
|
64
92
|
"homepage": "https://github.com/the-artinet-project/artinet-sdk#readme",
|
|
65
93
|
"dependencies": {
|
|
66
|
-
"@
|
|
67
|
-
"@trpc/server": "^11.4.3",
|
|
94
|
+
"@artinet/types": "^0.0.9-alpha.3",
|
|
68
95
|
"cors": "^2.8.5",
|
|
69
96
|
"escape-html": "^1.0.3",
|
|
70
97
|
"eventsource-parser": "^3.0.1",
|
|
71
98
|
"express": "^5.1.0",
|
|
72
|
-
"uuid": "^
|
|
73
|
-
"zod": "^3.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"@
|
|
99
|
+
"uuid": "^13.0.0",
|
|
100
|
+
"zod": "^3.25"
|
|
101
|
+
},
|
|
102
|
+
"peerDependencies": {
|
|
103
|
+
"@a2a-js/sdk": "^0.3.7",
|
|
104
|
+
"@modelcontextprotocol/sdk": "^1.24.3",
|
|
105
|
+
"@trpc/server": "^11.4.3",
|
|
106
|
+
"@opentelemetry/api": "^1.9.0"
|
|
107
|
+
},
|
|
108
|
+
"optionalDependencies": {
|
|
109
|
+
"pino": "^10.1.0",
|
|
110
|
+
"winston": "^3.19.0"
|
|
111
|
+
},
|
|
112
|
+
"peerDependenciesMeta": {
|
|
113
|
+
"@modelcontextprotocol/sdk": {
|
|
114
|
+
"optional": false
|
|
115
|
+
},
|
|
116
|
+
"@trpc/server": {
|
|
117
|
+
"optional": true
|
|
118
|
+
},
|
|
119
|
+
"@a2a-js/sdk": {
|
|
120
|
+
"optional": true
|
|
121
|
+
},
|
|
122
|
+
"@opentelemetry/api": {
|
|
123
|
+
"optional": false
|
|
124
|
+
},
|
|
125
|
+
"pino": {
|
|
126
|
+
"optional": true
|
|
127
|
+
},
|
|
128
|
+
"winston": {
|
|
129
|
+
"optional": true
|
|
130
|
+
}
|
|
77
131
|
},
|
|
78
132
|
"devDependencies": {
|
|
79
|
-
"@
|
|
133
|
+
"@cfworker/json-schema": "^4.1.1",
|
|
80
134
|
"@eslint/js": "^9.25.1",
|
|
81
|
-
"@
|
|
135
|
+
"@opentelemetry/api": "^1.9.0",
|
|
136
|
+
"@types/cors": "^2.8.17",
|
|
137
|
+
"@types/escape-html": "^1.0.4",
|
|
138
|
+
"@types/express": "^5.0.1",
|
|
139
|
+
"@types/jest": "^30.0.0",
|
|
140
|
+
"@types/node": "^25.0.3",
|
|
82
141
|
"@types/supertest": "latest",
|
|
83
142
|
"eslint": "^9.25.1",
|
|
84
143
|
"globals": "^16.0.0",
|
|
85
|
-
"jest": "^
|
|
144
|
+
"jest": "^30.2.0",
|
|
86
145
|
"msw": "^2.7.5",
|
|
87
|
-
"
|
|
146
|
+
"pino": "^10.1.0",
|
|
147
|
+
"pino-caller": "^4.0.0",
|
|
148
|
+
"pino-pretty": "^13.1.3",
|
|
149
|
+
"rimraf": "^6.1.2",
|
|
88
150
|
"supertest": "latest",
|
|
89
151
|
"ts-jest": "^29.3.2",
|
|
90
152
|
"ts-node": "^10.9.1",
|
|
@@ -92,7 +154,8 @@
|
|
|
92
154
|
"tsx": "^4.20.4",
|
|
93
155
|
"typescript": "^5.2.2",
|
|
94
156
|
"typescript-eslint": "^8.31.0",
|
|
95
|
-
"typescript-transform-paths": "^3.5.5"
|
|
157
|
+
"typescript-transform-paths": "^3.5.5",
|
|
158
|
+
"winston": "^3.19.0"
|
|
96
159
|
},
|
|
97
160
|
"engines": {
|
|
98
161
|
"node": ">=18.9.1"
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2025 The Artinet Project
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @fileoverview A2A Event Manager Factory
|
|
7
|
-
*
|
|
8
|
-
* This module provides factory functions for creating A2A-specific event managers
|
|
9
|
-
* that handle the complete lifecycle of agent-to-agent communication tasks.
|
|
10
|
-
* It integrates with the core event management system while providing A2A-specific
|
|
11
|
-
* behavior for state management, task tracking, and error handling.
|
|
12
|
-
*
|
|
13
|
-
* @module A2AEventFactory
|
|
14
|
-
* @version 0.5.7
|
|
15
|
-
* @since 0.5.6
|
|
16
|
-
* @author The Artinet Project
|
|
17
|
-
*/
|
|
18
|
-
import { EventManager } from "../../core/managers/event.js";
|
|
19
|
-
import { Command, State, Update, A2AServiceInterface, EventManagerOptions } from "../../../types/index.js";
|
|
20
|
-
/**
|
|
21
|
-
* Creates an A2A-specific event manager with integrated task and state management.
|
|
22
|
-
*
|
|
23
|
-
* This factory function creates an event manager tailored for A2A operations,
|
|
24
|
-
* providing comprehensive lifecycle management for agent-to-agent communication
|
|
25
|
-
* tasks. It handles state persistence, task tracking, error scenarios, and
|
|
26
|
-
* cancellation while integrating with the broader A2A service framework.
|
|
27
|
-
*
|
|
28
|
-
* @template TCommand - The command type, must extend Command
|
|
29
|
-
* @template TState - The state type, must extend State
|
|
30
|
-
* @template TUpdate - The update type, must extend Update
|
|
31
|
-
*
|
|
32
|
-
* @param service - The A2A service instance for state and connection management
|
|
33
|
-
* @param id - Optional context ID (generates UUID if not provided)
|
|
34
|
-
* @param eventOverrides - Optional event handling overrides
|
|
35
|
-
* @returns Configured EventManager instance for A2A operations
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
* const eventManager = createEventManager(
|
|
40
|
-
* a2aService,
|
|
41
|
-
* 'context-123',
|
|
42
|
-
* {
|
|
43
|
-
* onStart: async (context) => {
|
|
44
|
-
* console.log('A2A task starting');
|
|
45
|
-
* return await initializeA2AState(context);
|
|
46
|
-
* },
|
|
47
|
-
* onComplete: async (finalState) => {
|
|
48
|
-
* console.log('A2A task completed');
|
|
49
|
-
* await notifyCompletion(finalState);
|
|
50
|
-
* }
|
|
51
|
-
* }
|
|
52
|
-
* );
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* @public
|
|
56
|
-
* @since 0.5.6
|
|
57
|
-
*/
|
|
58
|
-
export declare function createEventManager<TCommand extends Command = Command, TState extends State = State, TUpdate extends Update = Update>(service: A2AServiceInterface<TCommand, TState, TUpdate>, id?: string, eventOverrides?: EventManagerOptions<TCommand, TState, TUpdate>): EventManager<TCommand, TState, TUpdate>;
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2025 The Artinet Project
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @fileoverview A2A Event Manager Factory
|
|
7
|
-
*
|
|
8
|
-
* This module provides factory functions for creating A2A-specific event managers
|
|
9
|
-
* that handle the complete lifecycle of agent-to-agent communication tasks.
|
|
10
|
-
* It integrates with the core event management system while providing A2A-specific
|
|
11
|
-
* behavior for state management, task tracking, and error handling.
|
|
12
|
-
*
|
|
13
|
-
* @module A2AEventFactory
|
|
14
|
-
* @version 0.5.7
|
|
15
|
-
* @since 0.5.6
|
|
16
|
-
* @author The Artinet Project
|
|
17
|
-
*/
|
|
18
|
-
import { EventManager } from "../../core/managers/event.js";
|
|
19
|
-
import { TaskState, } from "../../../types/index.js";
|
|
20
|
-
import { INTERNAL_ERROR, INVALID_PARAMS, CANCEL_UPDATE, FAILED_UPDATE, logError, } from "../../../utils/index.js";
|
|
21
|
-
import { loadState, processUpdate } from "../state/index.js";
|
|
22
|
-
import { v4 as uuidv4 } from "uuid";
|
|
23
|
-
/**
|
|
24
|
-
* Creates an A2A-specific event manager with integrated task and state management.
|
|
25
|
-
*
|
|
26
|
-
* This factory function creates an event manager tailored for A2A operations,
|
|
27
|
-
* providing comprehensive lifecycle management for agent-to-agent communication
|
|
28
|
-
* tasks. It handles state persistence, task tracking, error scenarios, and
|
|
29
|
-
* cancellation while integrating with the broader A2A service framework.
|
|
30
|
-
*
|
|
31
|
-
* @template TCommand - The command type, must extend Command
|
|
32
|
-
* @template TState - The state type, must extend State
|
|
33
|
-
* @template TUpdate - The update type, must extend Update
|
|
34
|
-
*
|
|
35
|
-
* @param service - The A2A service instance for state and connection management
|
|
36
|
-
* @param id - Optional context ID (generates UUID if not provided)
|
|
37
|
-
* @param eventOverrides - Optional event handling overrides
|
|
38
|
-
* @returns Configured EventManager instance for A2A operations
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```typescript
|
|
42
|
-
* const eventManager = createEventManager(
|
|
43
|
-
* a2aService,
|
|
44
|
-
* 'context-123',
|
|
45
|
-
* {
|
|
46
|
-
* onStart: async (context) => {
|
|
47
|
-
* console.log('A2A task starting');
|
|
48
|
-
* return await initializeA2AState(context);
|
|
49
|
-
* },
|
|
50
|
-
* onComplete: async (finalState) => {
|
|
51
|
-
* console.log('A2A task completed');
|
|
52
|
-
* await notifyCompletion(finalState);
|
|
53
|
-
* }
|
|
54
|
-
* }
|
|
55
|
-
* );
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* @public
|
|
59
|
-
* @since 0.5.6
|
|
60
|
-
*/
|
|
61
|
-
export function createEventManager(service, id, eventOverrides) {
|
|
62
|
-
const contextId = id ?? uuidv4();
|
|
63
|
-
/**
|
|
64
|
-
* Task store implementation that bridges between event management and A2A service state management.
|
|
65
|
-
*
|
|
66
|
-
* This store provides the interface needed by the legacy update processing logic
|
|
67
|
-
* while integrating with the A2A service's state management capabilities.
|
|
68
|
-
*/
|
|
69
|
-
const taskStore = {
|
|
70
|
-
save: async (data) => {
|
|
71
|
-
if (!data.task?.id) {
|
|
72
|
-
throw INTERNAL_ERROR({
|
|
73
|
-
data: {
|
|
74
|
-
message: "Task ID is required",
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
service.setState(data.task.id, data);
|
|
79
|
-
},
|
|
80
|
-
load: async (taskId) => {
|
|
81
|
-
return (await service.getState(taskId).catch(() => null)) ?? null;
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
// Configure A2A-specific event handling options
|
|
85
|
-
const options = {
|
|
86
|
-
onStart: async (context) => {
|
|
87
|
-
const request = context.command;
|
|
88
|
-
if (!request || (!request.message && !("message" in request))) {
|
|
89
|
-
throw INVALID_PARAMS("No request detected");
|
|
90
|
-
}
|
|
91
|
-
let currentContextId = contextId;
|
|
92
|
-
if (request.message.contextId) {
|
|
93
|
-
currentContextId = request.message.contextId;
|
|
94
|
-
}
|
|
95
|
-
service.addConnection(currentContextId);
|
|
96
|
-
const currentState = await loadState(taskStore, request.message, request.metadata, request.message.taskId, currentContextId);
|
|
97
|
-
return currentState;
|
|
98
|
-
},
|
|
99
|
-
onCancel: async (current, update) => {
|
|
100
|
-
const localContextId = update.contextId ?? contextId;
|
|
101
|
-
const localTaskId = update.taskId ?? update.id;
|
|
102
|
-
service.addCancellation(localContextId);
|
|
103
|
-
const cancellation = CANCEL_UPDATE(localTaskId, localContextId);
|
|
104
|
-
const cancelUpdate = {
|
|
105
|
-
...update,
|
|
106
|
-
...cancellation,
|
|
107
|
-
status: {
|
|
108
|
-
...update.status,
|
|
109
|
-
...cancellation.status,
|
|
110
|
-
state: TaskState.canceled,
|
|
111
|
-
},
|
|
112
|
-
final: true,
|
|
113
|
-
};
|
|
114
|
-
await processUpdate(taskStore, {
|
|
115
|
-
context: {
|
|
116
|
-
contextId: localContextId,
|
|
117
|
-
task: current.task,
|
|
118
|
-
userMessage: current.task?.status?.message ?? {},
|
|
119
|
-
isCancelled: () => service.isCancelled(localContextId),
|
|
120
|
-
history: [], //deprecating history
|
|
121
|
-
},
|
|
122
|
-
current: current,
|
|
123
|
-
update: cancelUpdate,
|
|
124
|
-
});
|
|
125
|
-
},
|
|
126
|
-
onUpdate: async (current, update) => {
|
|
127
|
-
if (service.isCancelled(contextId)) {
|
|
128
|
-
return current;
|
|
129
|
-
}
|
|
130
|
-
try {
|
|
131
|
-
const currentState = (await processUpdate(taskStore, {
|
|
132
|
-
context: {
|
|
133
|
-
contextId: contextId,
|
|
134
|
-
task: current.task,
|
|
135
|
-
userMessage: current.task?.status?.message ?? {},
|
|
136
|
-
isCancelled: () => service.isCancelled(contextId),
|
|
137
|
-
history: [], //deprecating history
|
|
138
|
-
},
|
|
139
|
-
current: current,
|
|
140
|
-
update: update,
|
|
141
|
-
}));
|
|
142
|
-
return currentState;
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
logError(`onUpdate[${contextId}]:`, "error detected", error, update);
|
|
146
|
-
throw error;
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
onError: async (current, error) => {
|
|
150
|
-
logError(`onError[${contextId}]`, "error detected", error, current);
|
|
151
|
-
if (!current ||
|
|
152
|
-
(!current.task?.contextId && !current?.contextId)) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
const failedUpdate = FAILED_UPDATE(current.task?.id, current.task?.contextId ?? contextId, "failed-update", error instanceof Error ? error.message : String(error));
|
|
156
|
-
await processUpdate(taskStore, {
|
|
157
|
-
context: {
|
|
158
|
-
contextId: current.task?.contextId ?? contextId,
|
|
159
|
-
task: current.task,
|
|
160
|
-
userMessage: current.task?.status?.message ?? {},
|
|
161
|
-
isCancelled: () => service.isCancelled(contextId),
|
|
162
|
-
history: [], //deprecating history
|
|
163
|
-
},
|
|
164
|
-
current: current,
|
|
165
|
-
update: failedUpdate,
|
|
166
|
-
});
|
|
167
|
-
},
|
|
168
|
-
onComplete: async () => {
|
|
169
|
-
service.removeCancellation(contextId);
|
|
170
|
-
service.removeConnection(contextId);
|
|
171
|
-
},
|
|
172
|
-
};
|
|
173
|
-
return new EventManager(contextId, {
|
|
174
|
-
...options,
|
|
175
|
-
...eventOverrides, // Override options take precedence over defaults
|
|
176
|
-
});
|
|
177
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2025 The Artinet Project
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
import { CancellationManagerInterface } from "../../../types/index.js";
|
|
6
|
-
export declare class CancellationManager implements CancellationManagerInterface {
|
|
7
|
-
private cancellations;
|
|
8
|
-
addCancellation(id: string): void;
|
|
9
|
-
removeCancellation(id: string): void;
|
|
10
|
-
isCancelled(id: string): boolean;
|
|
11
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2025 The Artinet Project
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
export class CancellationManager {
|
|
6
|
-
cancellations = new Set();
|
|
7
|
-
addCancellation(id) {
|
|
8
|
-
this.cancellations.add(id);
|
|
9
|
-
}
|
|
10
|
-
removeCancellation(id) {
|
|
11
|
-
this.cancellations.delete(id);
|
|
12
|
-
}
|
|
13
|
-
isCancelled(id) {
|
|
14
|
-
return this.cancellations.has(id);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2025 The Artinet Project
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
import { ConnectionManagerInterface } from "../../../types/index.js";
|
|
6
|
-
export declare class ConnectionManager implements ConnectionManagerInterface {
|
|
7
|
-
private connections;
|
|
8
|
-
addConnection(id: string): void;
|
|
9
|
-
removeConnection(id: string): void;
|
|
10
|
-
isConnected(id: string): boolean;
|
|
11
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2025 The Artinet Project
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
export class ConnectionManager {
|
|
6
|
-
connections = new Set();
|
|
7
|
-
addConnection(id) {
|
|
8
|
-
this.connections.add(id);
|
|
9
|
-
}
|
|
10
|
-
removeConnection(id) {
|
|
11
|
-
this.connections.delete(id);
|
|
12
|
-
}
|
|
13
|
-
isConnected(id) {
|
|
14
|
-
return this.connections.has(id);
|
|
15
|
-
}
|
|
16
|
-
}
|