@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,92 +2,261 @@
|
|
|
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 { createMessageSendParams } from "./helpers/message-builder.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
this.tasks = tasks;
|
|
23
|
-
this.methods = methods;
|
|
24
|
-
this.eventOverrides = eventOverrides;
|
|
25
|
-
}
|
|
26
|
-
async execute(engine, context) {
|
|
27
|
-
await coreExecute(engine ?? this.engine, context);
|
|
7
|
+
import { validateSchema } from "../../utils/common/schema-validation.js";
|
|
8
|
+
import { CANCEL_UPDATE } from "../../utils/common/constants.js";
|
|
9
|
+
import { INVALID_REQUEST, TASK_NOT_FOUND } from "../../utils/common/errors.js";
|
|
10
|
+
import { v4 as uuidv4 } from "uuid";
|
|
11
|
+
import { Messenger } from "./messenger.js";
|
|
12
|
+
import { execute } from "./execute.js";
|
|
13
|
+
import { createService } from "./factory/service.js";
|
|
14
|
+
import { getReferences } from "./helpers/references.js";
|
|
15
|
+
import { logger } from "../../config/index.js";
|
|
16
|
+
const createMessageParams = (task) => {
|
|
17
|
+
const latestUserMessage = task.history
|
|
18
|
+
?.filter((msg) => msg.role === "user")
|
|
19
|
+
?.pop();
|
|
20
|
+
if (!latestUserMessage) {
|
|
21
|
+
throw INVALID_REQUEST("No user message found");
|
|
28
22
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
const messageParams = {
|
|
24
|
+
message: {
|
|
25
|
+
...latestUserMessage,
|
|
26
|
+
taskId: task.id,
|
|
27
|
+
contextId: latestUserMessage.contextId ?? task.contextId,
|
|
28
|
+
},
|
|
29
|
+
metadata: task.metadata,
|
|
30
|
+
};
|
|
31
|
+
return messageParams;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* @note Comprehensive Extension system coming in a future release
|
|
35
|
+
*/
|
|
36
|
+
const getExtensions = async (extensions) => {
|
|
37
|
+
logger.warn("getExtensions: not implemented", { extensions });
|
|
38
|
+
return [];
|
|
39
|
+
};
|
|
40
|
+
export class Service {
|
|
41
|
+
_agentCard;
|
|
42
|
+
_engine;
|
|
43
|
+
_connections;
|
|
44
|
+
_cancellations;
|
|
45
|
+
_tasks;
|
|
46
|
+
_contexts;
|
|
47
|
+
_streams;
|
|
48
|
+
_methods;
|
|
49
|
+
_overrides;
|
|
50
|
+
constructor(_agentCard, _engine, _connections, _cancellations, _tasks, _contexts, _streams, _methods, _overrides) {
|
|
51
|
+
this._agentCard = _agentCard;
|
|
52
|
+
this._engine = _engine;
|
|
53
|
+
this._connections = _connections;
|
|
54
|
+
this._cancellations = _cancellations;
|
|
55
|
+
this._tasks = _tasks;
|
|
56
|
+
this._contexts = _contexts;
|
|
57
|
+
this._streams = _streams;
|
|
58
|
+
this._methods = _methods;
|
|
59
|
+
this._overrides = _overrides;
|
|
35
60
|
}
|
|
36
|
-
|
|
37
|
-
this.
|
|
61
|
+
get methods() {
|
|
62
|
+
return this._methods;
|
|
38
63
|
}
|
|
39
|
-
|
|
40
|
-
this.
|
|
64
|
+
set methods(methods) {
|
|
65
|
+
this._methods = {
|
|
66
|
+
...this._methods,
|
|
67
|
+
...methods,
|
|
68
|
+
};
|
|
41
69
|
}
|
|
42
|
-
|
|
43
|
-
return this.
|
|
70
|
+
get agentCard() {
|
|
71
|
+
return this._agentCard;
|
|
44
72
|
}
|
|
45
|
-
|
|
46
|
-
this.
|
|
73
|
+
get engine() {
|
|
74
|
+
return this._engine;
|
|
47
75
|
}
|
|
48
|
-
|
|
49
|
-
this.
|
|
76
|
+
set engine(engine) {
|
|
77
|
+
this._engine = engine;
|
|
50
78
|
}
|
|
51
|
-
|
|
52
|
-
return
|
|
79
|
+
get connections() {
|
|
80
|
+
return this._connections;
|
|
53
81
|
}
|
|
54
|
-
|
|
55
|
-
|
|
82
|
+
get cancellations() {
|
|
83
|
+
return this._cancellations;
|
|
56
84
|
}
|
|
57
|
-
|
|
58
|
-
return
|
|
85
|
+
get tasks() {
|
|
86
|
+
return this._tasks;
|
|
59
87
|
}
|
|
60
|
-
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
88
|
+
get contexts() {
|
|
89
|
+
return this._contexts;
|
|
90
|
+
}
|
|
91
|
+
set contexts(contexts) {
|
|
92
|
+
this._contexts = {
|
|
93
|
+
...this._contexts,
|
|
94
|
+
...contexts,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
get streams() {
|
|
98
|
+
return this._streams;
|
|
99
|
+
}
|
|
100
|
+
get overrides() {
|
|
101
|
+
return this._overrides;
|
|
102
|
+
}
|
|
103
|
+
set overrides(overrides) {
|
|
104
|
+
this._overrides = {
|
|
105
|
+
...this._overrides,
|
|
106
|
+
...overrides,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
async execute({ engine, context, }) {
|
|
110
|
+
await execute(engine, context);
|
|
111
|
+
}
|
|
112
|
+
async getAgentCard() {
|
|
113
|
+
return this.agentCard;
|
|
114
|
+
}
|
|
115
|
+
async stop() {
|
|
116
|
+
logger.info(`Service[stop]`);
|
|
117
|
+
for (const context of await this.contexts.list()) {
|
|
118
|
+
await context.publisher.onCancel(CANCEL_UPDATE(context.taskId, context.contextId, {
|
|
119
|
+
role: "agent",
|
|
120
|
+
parts: [
|
|
121
|
+
{
|
|
122
|
+
kind: "text",
|
|
123
|
+
text: "service stopped",
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
messageId: uuidv4(),
|
|
127
|
+
kind: "message",
|
|
128
|
+
taskId: context.taskId,
|
|
129
|
+
contextId: context.contextId,
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
async getTask(params, context, options) {
|
|
135
|
+
logger.info(`Service[getTask]:`, { taskId: params.id });
|
|
136
|
+
const task = await this.tasks.get(params.id);
|
|
137
|
+
if (!task) {
|
|
138
|
+
throw TASK_NOT_FOUND({ taskId: params.id });
|
|
139
|
+
}
|
|
140
|
+
return await this.methods.getTask(await validateSchema(A2A.TaskQueryParamsSchema, params), context ??
|
|
141
|
+
(await this.contexts.create({
|
|
142
|
+
contextId: task.contextId,
|
|
143
|
+
service: this,
|
|
144
|
+
abortSignal: options?.abortSignal,
|
|
145
|
+
task: task,
|
|
146
|
+
overrides: this.overrides,
|
|
147
|
+
messenger: Messenger.create(createMessageParams(task)),
|
|
148
|
+
})));
|
|
149
|
+
}
|
|
150
|
+
async cancelTask(params, context, options) {
|
|
151
|
+
logger.info(`Service[cancelTask]:`, { taskId: params.id });
|
|
152
|
+
const task = await this.tasks.get(params.id);
|
|
153
|
+
if (!task) {
|
|
154
|
+
throw TASK_NOT_FOUND({ taskId: params.id });
|
|
155
|
+
}
|
|
156
|
+
return await this.methods.cancelTask(await validateSchema(A2A.TaskIdParamsSchema, params), context ??
|
|
157
|
+
(await this.contexts.create({
|
|
158
|
+
contextId: task.contextId,
|
|
159
|
+
service: this,
|
|
160
|
+
abortSignal: options?.abortSignal,
|
|
161
|
+
task: task,
|
|
162
|
+
overrides: this.overrides,
|
|
163
|
+
messenger: Messenger.create(createMessageParams(task)),
|
|
164
|
+
})));
|
|
165
|
+
}
|
|
166
|
+
async sendMessage(paramsOrMessage, context, options) {
|
|
167
|
+
const params = typeof paramsOrMessage === "string"
|
|
168
|
+
? createMessageSendParams(paramsOrMessage)
|
|
169
|
+
: typeof paramsOrMessage === "object" && "message" in paramsOrMessage
|
|
170
|
+
? paramsOrMessage
|
|
171
|
+
: createMessageSendParams({
|
|
172
|
+
message: paramsOrMessage,
|
|
173
|
+
});
|
|
174
|
+
return await this._sendMessage(params, context, options);
|
|
65
175
|
}
|
|
66
|
-
async
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
service: this,
|
|
70
|
-
engine: params?.engine ?? this.engine,
|
|
71
|
-
contextManager: this.contexts,
|
|
72
|
-
signal: params?.signal ?? new AbortController().signal,
|
|
176
|
+
async _sendMessage(params, context, options) {
|
|
177
|
+
logger.info(`Service[sendMessage]:`, {
|
|
178
|
+
messageId: params.message.messageId,
|
|
73
179
|
});
|
|
180
|
+
logger.debug(`Service[sendMessage]:`, { taskId: params.message.taskId });
|
|
181
|
+
logger.debug(`Service[sendMessage]:`, {
|
|
182
|
+
contextId: params.message.contextId,
|
|
183
|
+
});
|
|
184
|
+
const task = await this.tasks.create({
|
|
185
|
+
id: params.message.taskId,
|
|
186
|
+
contextId: params.message.contextId,
|
|
187
|
+
history: [params.message],
|
|
188
|
+
metadata: {
|
|
189
|
+
...params.metadata,
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
return await this.methods.sendMessage(await validateSchema(A2A.MessageSendParamsSchema, params), context ??
|
|
193
|
+
(await this.contexts.create({
|
|
194
|
+
contextId: task.contextId,
|
|
195
|
+
service: this,
|
|
196
|
+
abortSignal: options?.abortSignal,
|
|
197
|
+
task: task,
|
|
198
|
+
overrides: this.overrides,
|
|
199
|
+
messenger: Messenger.create(params),
|
|
200
|
+
references: await getReferences(this.tasks, params.message.referenceTaskIds),
|
|
201
|
+
extensions: await getExtensions(params.message.extensions),
|
|
202
|
+
})));
|
|
74
203
|
}
|
|
75
|
-
async *streamMessage(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
204
|
+
async *streamMessage(paramsOrMessage, context, options) {
|
|
205
|
+
const params = typeof paramsOrMessage === "string"
|
|
206
|
+
? createMessageSendParams(paramsOrMessage)
|
|
207
|
+
: paramsOrMessage;
|
|
208
|
+
yield* this._streamMessage(params, context, options);
|
|
209
|
+
}
|
|
210
|
+
async *_streamMessage(params, context, options) {
|
|
211
|
+
logger.info("Service[streamMessage]:", {
|
|
212
|
+
taskId: params.message.taskId,
|
|
213
|
+
contextId: params.message.contextId,
|
|
214
|
+
});
|
|
215
|
+
const task = await this.tasks.create({
|
|
216
|
+
id: params.message.taskId,
|
|
217
|
+
contextId: params.message.contextId,
|
|
218
|
+
history: [params.message],
|
|
219
|
+
metadata: {
|
|
220
|
+
...params.metadata,
|
|
221
|
+
},
|
|
82
222
|
});
|
|
223
|
+
logger.debug("Service[streamMessage]: task created", {
|
|
224
|
+
taskId: task.id,
|
|
225
|
+
contextId: task.contextId,
|
|
226
|
+
});
|
|
227
|
+
yield* this.methods.streamMessage(await validateSchema(A2A.MessageSendParamsSchema, params), context ??
|
|
228
|
+
(await this.contexts.create({
|
|
229
|
+
contextId: task.contextId,
|
|
230
|
+
service: this,
|
|
231
|
+
abortSignal: options?.abortSignal,
|
|
232
|
+
task: task,
|
|
233
|
+
overrides: this.overrides,
|
|
234
|
+
messenger: Messenger.create(params),
|
|
235
|
+
references: await getReferences(this.tasks, params.message.referenceTaskIds),
|
|
236
|
+
extensions: await getExtensions(params.message.extensions),
|
|
237
|
+
})));
|
|
83
238
|
}
|
|
84
|
-
async *resubscribe(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
239
|
+
async *resubscribe(params, context, options) {
|
|
240
|
+
logger.info(`Service[resubscribe]:`, { taskId: params.id });
|
|
241
|
+
const task = await this.tasks.get(params.id);
|
|
242
|
+
if (!task) {
|
|
243
|
+
throw TASK_NOT_FOUND({ taskId: params.id });
|
|
244
|
+
}
|
|
245
|
+
logger.debug("Service[resubscribe]:", {
|
|
246
|
+
taskId: task.id,
|
|
247
|
+
contextId: task.contextId,
|
|
91
248
|
});
|
|
249
|
+
yield* this.methods.resubscribe(await validateSchema(A2A.TaskIdParamsSchema, params), context ??
|
|
250
|
+
(await this.contexts.create({
|
|
251
|
+
contextId: task.contextId,
|
|
252
|
+
service: this,
|
|
253
|
+
abortSignal: options?.abortSignal,
|
|
254
|
+
task: task,
|
|
255
|
+
overrides: this.overrides,
|
|
256
|
+
messenger: Messenger.create(createMessageParams(task)),
|
|
257
|
+
})));
|
|
258
|
+
}
|
|
259
|
+
static create(params) {
|
|
260
|
+
return createService(params);
|
|
92
261
|
}
|
|
93
262
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import { A2A } from "../../types/index.js";
|
|
3
|
+
export declare class StateMachine extends EventEmitter<A2A.Emissions> implements A2A.EventPublisher {
|
|
4
|
+
readonly _contextId: string;
|
|
5
|
+
private readonly _consumer;
|
|
6
|
+
private _currentTask?;
|
|
7
|
+
onStart: (context: A2A.Context) => Promise<A2A.Task>;
|
|
8
|
+
onCancel: (update: A2A.Update) => Promise<void>;
|
|
9
|
+
onUpdate: (update: A2A.Update) => Promise<A2A.Task>;
|
|
10
|
+
onError: (error: any) => Promise<void>;
|
|
11
|
+
onComplete: () => Promise<void>;
|
|
12
|
+
constructor(_contextId: string, _consumer: A2A.EventConsumer, _currentTask?: A2A.Task | undefined);
|
|
13
|
+
get currentTask(): A2A.Task;
|
|
14
|
+
private set currentTask(value);
|
|
15
|
+
get consumer(): A2A.EventConsumer;
|
|
16
|
+
get contextId(): string;
|
|
17
|
+
static create(contextId: string, service: A2A.Service, task?: A2A.Task, overrides?: Partial<Omit<A2A.EventConsumer, "contextId">>): StateMachine;
|
|
18
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import { INTERNAL_ERROR } from "../../utils/index.js";
|
|
3
|
+
import { logger } from "../../config/index.js";
|
|
4
|
+
import { createStateMachine } from "./factory/state-machine.js";
|
|
5
|
+
export class StateMachine extends EventEmitter {
|
|
6
|
+
_contextId;
|
|
7
|
+
_consumer;
|
|
8
|
+
_currentTask;
|
|
9
|
+
onStart = async (context) => {
|
|
10
|
+
if (this.consumer.onStart) {
|
|
11
|
+
this.currentTask = await this.consumer.onStart(context);
|
|
12
|
+
}
|
|
13
|
+
this.emit("start", context.messages, this.currentTask);
|
|
14
|
+
return this.currentTask;
|
|
15
|
+
};
|
|
16
|
+
onCancel = async (update) => {
|
|
17
|
+
if (this.consumer.onCancel) {
|
|
18
|
+
await this.consumer.onCancel(update, this.currentTask);
|
|
19
|
+
}
|
|
20
|
+
this.emit("cancel", update);
|
|
21
|
+
};
|
|
22
|
+
onUpdate = async (update) => {
|
|
23
|
+
if (this.consumer.onUpdate) {
|
|
24
|
+
this.currentTask = await this.consumer.onUpdate(update, this.currentTask);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
logger.warn(`onUpdate[${this.contextId}]:`, "onUpdate callback not found");
|
|
28
|
+
this.currentTask = update;
|
|
29
|
+
}
|
|
30
|
+
this.emit("update", this.currentTask, update);
|
|
31
|
+
return this.currentTask;
|
|
32
|
+
};
|
|
33
|
+
onError = async (error) => {
|
|
34
|
+
if (this.consumer.onError) {
|
|
35
|
+
await this.consumer.onError(error, this.currentTask);
|
|
36
|
+
}
|
|
37
|
+
this.emit("error", error, this.currentTask);
|
|
38
|
+
};
|
|
39
|
+
onComplete = async () => {
|
|
40
|
+
if (this.consumer.onComplete) {
|
|
41
|
+
await this.consumer.onComplete(this.currentTask);
|
|
42
|
+
}
|
|
43
|
+
this.emit("complete", this.currentTask);
|
|
44
|
+
};
|
|
45
|
+
constructor(_contextId, _consumer, _currentTask) {
|
|
46
|
+
super();
|
|
47
|
+
this._contextId = _contextId;
|
|
48
|
+
this._consumer = _consumer;
|
|
49
|
+
this._currentTask = _currentTask;
|
|
50
|
+
}
|
|
51
|
+
get currentTask() {
|
|
52
|
+
if (!this._currentTask) {
|
|
53
|
+
throw INTERNAL_ERROR({
|
|
54
|
+
error: { message: "state machine is not initialized" },
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return this._currentTask;
|
|
58
|
+
}
|
|
59
|
+
set currentTask(task) {
|
|
60
|
+
this._currentTask = task;
|
|
61
|
+
}
|
|
62
|
+
get consumer() {
|
|
63
|
+
return this._consumer;
|
|
64
|
+
}
|
|
65
|
+
get contextId() {
|
|
66
|
+
return this._contextId;
|
|
67
|
+
}
|
|
68
|
+
static create(contextId, service, task, overrides) {
|
|
69
|
+
return createStateMachine({
|
|
70
|
+
contextId,
|
|
71
|
+
service,
|
|
72
|
+
task,
|
|
73
|
+
overrides,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { A2A } from "../../types/index.js";
|
|
2
|
+
export declare class Stream implements A2A.Stream {
|
|
3
|
+
private _contextId;
|
|
4
|
+
private _context;
|
|
5
|
+
private _updates;
|
|
6
|
+
private _completed;
|
|
7
|
+
protected running: AsyncGenerator<A2A.Update> | null;
|
|
8
|
+
constructor(_contextId: string, _context: A2A.Context, _updates?: A2A.Update[], _completed?: boolean);
|
|
9
|
+
get contextId(): string;
|
|
10
|
+
get isAlive(): boolean;
|
|
11
|
+
kill(): Promise<void>;
|
|
12
|
+
get context(): A2A.Context;
|
|
13
|
+
set context(context: A2A.Context);
|
|
14
|
+
get updates(): A2A.Update[];
|
|
15
|
+
run({ service, }: {
|
|
16
|
+
service: A2A.Service;
|
|
17
|
+
}): AsyncGenerator<A2A.Update>;
|
|
18
|
+
subscribe(): AsyncGenerator<A2A.Update>;
|
|
19
|
+
_run({ service, }: {
|
|
20
|
+
service: A2A.Service;
|
|
21
|
+
}): AsyncGenerator<A2A.Update>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { sleep } from "../../utils/common/utils.js";
|
|
2
|
+
import { logger } from "../../config/index.js";
|
|
3
|
+
const STREAM_INTERVAL = 5;
|
|
4
|
+
export class Stream {
|
|
5
|
+
_contextId;
|
|
6
|
+
_context;
|
|
7
|
+
_updates;
|
|
8
|
+
_completed;
|
|
9
|
+
running = null;
|
|
10
|
+
constructor(_contextId, _context, _updates = [], _completed = false) {
|
|
11
|
+
this._contextId = _contextId;
|
|
12
|
+
this._context = _context;
|
|
13
|
+
this._updates = _updates;
|
|
14
|
+
this._completed = _completed;
|
|
15
|
+
}
|
|
16
|
+
get contextId() {
|
|
17
|
+
return this._contextId;
|
|
18
|
+
}
|
|
19
|
+
get isAlive() {
|
|
20
|
+
return !this._completed;
|
|
21
|
+
}
|
|
22
|
+
async kill() {
|
|
23
|
+
this._completed = true;
|
|
24
|
+
}
|
|
25
|
+
get context() {
|
|
26
|
+
return this._context;
|
|
27
|
+
}
|
|
28
|
+
set context(context) {
|
|
29
|
+
this._context = context;
|
|
30
|
+
this._contextId = context.contextId;
|
|
31
|
+
}
|
|
32
|
+
get updates() {
|
|
33
|
+
return this._updates;
|
|
34
|
+
}
|
|
35
|
+
async *run({ service, }) {
|
|
36
|
+
this.context.publisher.on("complete", async () => {
|
|
37
|
+
logger.debug(`Stream[run:${this.contextId}]: complete`);
|
|
38
|
+
await this.kill();
|
|
39
|
+
this.running = null;
|
|
40
|
+
});
|
|
41
|
+
this.context.publisher.on("error", async (err) => {
|
|
42
|
+
logger.error(`Stream[run:${this.contextId}]: error`, err);
|
|
43
|
+
await this.context.publisher.onComplete();
|
|
44
|
+
});
|
|
45
|
+
if (!this.running) {
|
|
46
|
+
this.running = this._run({ service });
|
|
47
|
+
yield* this.running;
|
|
48
|
+
}
|
|
49
|
+
yield* this.subscribe();
|
|
50
|
+
}
|
|
51
|
+
async *subscribe() {
|
|
52
|
+
const subscription = this.updates;
|
|
53
|
+
this.context.publisher.on("update", async (_, update) => {
|
|
54
|
+
subscription.push(update);
|
|
55
|
+
});
|
|
56
|
+
let updatesRead = 0;
|
|
57
|
+
while (!this._completed || updatesRead < subscription.length) {
|
|
58
|
+
if (updatesRead < subscription.length) {
|
|
59
|
+
yield subscription[updatesRead++];
|
|
60
|
+
}
|
|
61
|
+
await sleep(STREAM_INTERVAL);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async *_run({ service, }) {
|
|
65
|
+
let executionError = null;
|
|
66
|
+
const context = this.context;
|
|
67
|
+
// NOTE: isCancelled() returns a Promise, so must be awaited.
|
|
68
|
+
// Without async/await here, updates would never be pushed due to
|
|
69
|
+
// Promise being truthy (making !Promise always false).
|
|
70
|
+
context.publisher.on("update", async (_, update) => {
|
|
71
|
+
if (!(await context.isCancelled())) {
|
|
72
|
+
this.updates.push(update);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const executePromise = service
|
|
76
|
+
.execute({ engine: service.engine, context })
|
|
77
|
+
.catch((error) => {
|
|
78
|
+
executionError = error;
|
|
79
|
+
})
|
|
80
|
+
.finally(() => {
|
|
81
|
+
this._completed = true;
|
|
82
|
+
});
|
|
83
|
+
while (!this._completed || this.updates.length > 0) {
|
|
84
|
+
if (executionError) {
|
|
85
|
+
throw executionError;
|
|
86
|
+
}
|
|
87
|
+
if (this.updates.length > 0) {
|
|
88
|
+
yield this.updates.shift();
|
|
89
|
+
}
|
|
90
|
+
await sleep(STREAM_INTERVAL);
|
|
91
|
+
}
|
|
92
|
+
await executePromise;
|
|
93
|
+
this._completed = true;
|
|
94
|
+
if (executionError) {
|
|
95
|
+
throw executionError;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./managers/index.js";
|
|
1
|
+
export * from "./manager.js";
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./managers/index.js";
|
|
1
|
+
export * from "./manager.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
export declare abstract class Manager<T> {
|
|
6
|
+
private _data;
|
|
7
|
+
private throwOnSet;
|
|
8
|
+
constructor(_data?: Map<string, T>, throwOnSet?: boolean);
|
|
9
|
+
get data(): Map<string, T>;
|
|
10
|
+
set(id: string, data?: T): Promise<void>;
|
|
11
|
+
get(id: string): Promise<T | undefined>;
|
|
12
|
+
delete(id: string): Promise<void>;
|
|
13
|
+
has(id: string): Promise<boolean>;
|
|
14
|
+
list(): Promise<T[]>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { logger } from "../../config/index.js";
|
|
6
|
+
export class Manager {
|
|
7
|
+
_data;
|
|
8
|
+
throwOnSet;
|
|
9
|
+
constructor(_data = new Map(), throwOnSet = true) {
|
|
10
|
+
this._data = _data;
|
|
11
|
+
this.throwOnSet = throwOnSet;
|
|
12
|
+
}
|
|
13
|
+
get data() {
|
|
14
|
+
return this._data;
|
|
15
|
+
}
|
|
16
|
+
async set(id, data) {
|
|
17
|
+
logger.debug(`${this.constructor.name}[set]:`, { id });
|
|
18
|
+
if (!data && this.throwOnSet) {
|
|
19
|
+
throw new Error("Data is required");
|
|
20
|
+
}
|
|
21
|
+
else if (!data) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
this.data.set(id, data);
|
|
25
|
+
}
|
|
26
|
+
async get(id) {
|
|
27
|
+
// logger.debug(`${this.constructor.name}[get]:`, { id });
|
|
28
|
+
return this.data.get(id);
|
|
29
|
+
}
|
|
30
|
+
async delete(id) {
|
|
31
|
+
logger.debug(`${this.constructor.name}[delete]:`, { id });
|
|
32
|
+
this.data.delete(id);
|
|
33
|
+
}
|
|
34
|
+
async has(id) {
|
|
35
|
+
// logger.debug(`${this.constructor.name}[has]:`, { id });
|
|
36
|
+
return this.data.has(id);
|
|
37
|
+
}
|
|
38
|
+
async list() {
|
|
39
|
+
// logger.debug(`${this.constructor.name}[list]:`);
|
|
40
|
+
return Array.from(this.data.values());
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -3,26 +3,22 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
|
-
import {
|
|
6
|
+
import { MCP } from "../../types/index.js";
|
|
7
7
|
import { Implementation } from "@modelcontextprotocol/sdk/types.js";
|
|
8
8
|
import { ServerOptions } from "@modelcontextprotocol/sdk/server/index.js";
|
|
9
|
-
import { Agent } from "
|
|
10
|
-
export
|
|
9
|
+
import { Agent } from "../a2a/index.js";
|
|
10
|
+
export interface MCPServiceParams {
|
|
11
|
+
serverInfo: Implementation;
|
|
12
|
+
agent: Agent;
|
|
13
|
+
options?: ServerOptions;
|
|
14
|
+
agentCardUri?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare class BaseMCPService extends McpServer implements MCP.Service {
|
|
11
17
|
readonly agent: Agent;
|
|
12
18
|
private _registerBaseTools;
|
|
13
|
-
constructor({ serverInfo, agent, options, agentCardUri, }:
|
|
14
|
-
serverInfo: Implementation;
|
|
15
|
-
agent: Agent;
|
|
16
|
-
options?: ServerOptions;
|
|
17
|
-
agentCardUri?: string;
|
|
18
|
-
});
|
|
19
|
+
constructor({ serverInfo, agent, options, agentCardUri, }: MCPServiceParams);
|
|
19
20
|
stop(): Promise<void>;
|
|
20
|
-
static create({ serverInfo, agent, options, agentCardUri, }:
|
|
21
|
-
serverInfo: Implementation;
|
|
22
|
-
agent: Agent;
|
|
23
|
-
options?: ServerOptions;
|
|
24
|
-
agentCardUri?: string;
|
|
25
|
-
}): BaseMCPService & Agent;
|
|
21
|
+
static create({ serverInfo, agent, options, agentCardUri, }: MCPServiceParams): BaseMCPService & Agent;
|
|
26
22
|
}
|
|
27
23
|
export type MCPService = ReturnType<typeof BaseMCPService.create>;
|
|
28
24
|
export type MCPAgent = MCPService;
|