@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
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
export interface Service<Params extends object = object, Result extends unknown = void> {
|
|
3
|
+
execute: (params: Params) => Promise<Result>;
|
|
4
|
+
stop: () => Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export interface Context<State extends object = object> {
|
|
7
|
+
readonly contextId: string;
|
|
8
|
+
readonly isCancelled: () => Promise<boolean>;
|
|
9
|
+
readonly abortSignal: AbortSignal;
|
|
10
|
+
readonly messages?: AsyncIterable<unknown>;
|
|
11
|
+
readonly publisher?: Publisher;
|
|
12
|
+
readonly getState: (args?: string) => Promise<State | undefined>;
|
|
13
|
+
metadata?: Record<string, unknown>;
|
|
14
|
+
readonly hooks?: Record<string, (...args: unknown[]) => Promise<unknown>>;
|
|
15
|
+
}
|
|
16
|
+
export interface Manager<T = object> {
|
|
17
|
+
get: (id: string) => Promise<T | undefined>;
|
|
18
|
+
set: (id: string, data?: T) => Promise<void>;
|
|
19
|
+
delete: (id: string) => Promise<void>;
|
|
20
|
+
has?: (id: string) => Promise<boolean>;
|
|
21
|
+
list?: () => Promise<T[]>;
|
|
22
|
+
}
|
|
23
|
+
export type Optional<T extends object = object> = Partial<T> & {
|
|
24
|
+
contextId: string;
|
|
25
|
+
};
|
|
26
|
+
export interface Contexts<T extends Context = Context> extends Manager<T> {
|
|
27
|
+
}
|
|
28
|
+
export interface Publisher<EventMap extends Record<string, any[]> = Record<string, any[]>> extends EventEmitter<EventMap> {
|
|
29
|
+
}
|
|
30
|
+
export interface Consumer<Received extends unknown, EventMap extends Record<string, any[]> = Record<string, any[]>> extends AsyncIterable<Received, Received, Received | undefined>, Publisher<EventMap> {
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as core from "./core.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as core from "./core.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as MCP from "./mcp.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as MCP from "./mcp.js";
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
* managing service lifecycle.
|
|
11
11
|
*
|
|
12
12
|
* @module MCPService
|
|
13
|
-
* @version 0.
|
|
13
|
+
* @version 0.6.0-preview
|
|
14
14
|
* @since 0.5.7
|
|
15
15
|
* @author The Artinet Project
|
|
16
16
|
*/
|
|
17
|
-
import {
|
|
17
|
+
import { core } from "../core/index.js";
|
|
18
18
|
/**
|
|
19
19
|
* Main interface for MCP service implementations.
|
|
20
20
|
*
|
|
@@ -40,10 +40,11 @@ import { ServiceInterface } from "../core/index.js";
|
|
|
40
40
|
* @public
|
|
41
41
|
* @since 0.5.7
|
|
42
42
|
*/
|
|
43
|
-
export interface
|
|
43
|
+
export interface Service extends Omit<core.Service, "execute"> {
|
|
44
44
|
/**
|
|
45
45
|
* Registers tools for the MCP service.
|
|
46
46
|
* @param uri - The URI of the agent card resource.
|
|
47
47
|
*/
|
|
48
48
|
registerTools?: (uri: string) => void;
|
|
49
49
|
}
|
|
50
|
+
export * from "@artinet/types/mcp";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Interface for a store of data.
|
|
7
|
+
* @deprecated Use IStore instead
|
|
8
|
+
* @template T - The type of data to store
|
|
9
|
+
*/
|
|
10
|
+
export interface Store<T> {
|
|
11
|
+
set(data: T, id?: string): Promise<void>;
|
|
12
|
+
get(id: string): Promise<T | undefined>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Interface for a store of data.
|
|
16
|
+
* @template T - The type of data to store
|
|
17
|
+
*/
|
|
18
|
+
export interface IStore<T> {
|
|
19
|
+
set(id: string, data: T): Promise<void>;
|
|
20
|
+
get(id: string): Promise<T | undefined>;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./transform.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./transform.js";
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Type-safe object key transformation utilities using built-in TypeScript utility types
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Forces TypeScript to evaluate and flatten intersection types into a single object type
|
|
10
|
+
* This makes IDE tooltips and type displays much cleaner
|
|
11
|
+
*/
|
|
12
|
+
type Simplify<T> = {
|
|
13
|
+
[K in keyof T]: T[K];
|
|
14
|
+
} & {};
|
|
15
|
+
/**
|
|
16
|
+
* Configuration for renaming keys - maps old key names to new key names
|
|
17
|
+
* For best results, use `as const` to preserve literal string types
|
|
18
|
+
*/
|
|
19
|
+
export type RenameConfig<T extends object> = {
|
|
20
|
+
readonly [K in keyof T]?: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Transform object type by renaming specified keys using built-in utility types
|
|
24
|
+
* This combines Pick/Omit patterns with Record to achieve key renaming
|
|
25
|
+
* Uses Simplify to flatten the final type for cleaner IDE display
|
|
26
|
+
*/
|
|
27
|
+
export type TransformKeys<T extends object, Config extends RenameConfig<T>> = Simplify<Omit<T, keyof Config> & {
|
|
28
|
+
[OriginalKey in keyof Config & keyof T as Config[OriginalKey] extends string ? Config[OriginalKey] : OriginalKey]: T[OriginalKey];
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Runtime function to transform object keys based on configuration
|
|
32
|
+
* Uses the TransformKeys utility type for return type inference
|
|
33
|
+
*/
|
|
34
|
+
export declare function transformKeys<T extends object, Config extends RenameConfig<T>>(obj: T, config: Config): TransformKeys<T, Config>;
|
|
35
|
+
/**
|
|
36
|
+
* Helper type to extract the transformed type for a given object and config
|
|
37
|
+
* Useful for declaring variables with the expected transformed type
|
|
38
|
+
* Uses Simplify to show clean, flattened types in IDE
|
|
39
|
+
*/
|
|
40
|
+
export type Transformed<T extends object, Config extends RenameConfig<T>> = Simplify<TransformKeys<T, Config>>;
|
|
41
|
+
/**
|
|
42
|
+
* Utility to create a type-safe rename configuration with better intellisense
|
|
43
|
+
* The returned function preserves literal string types
|
|
44
|
+
*/
|
|
45
|
+
export declare function createRenameConfig<T extends object>(): <Config extends RenameConfig<T>>(config: Config) => Config;
|
|
46
|
+
/**
|
|
47
|
+
* Common transformation patterns using built-in utility types
|
|
48
|
+
*/
|
|
49
|
+
export declare namespace TransformPatterns {
|
|
50
|
+
/**
|
|
51
|
+
* Convert snake_case keys to camelCase
|
|
52
|
+
* This is a type-level template but would need runtime implementation
|
|
53
|
+
*/
|
|
54
|
+
type SnakeToCamel<T extends string> = T extends `${infer First}_${infer Rest}` ? `${First}${Capitalize<SnakeToCamel<Rest>>}` : T;
|
|
55
|
+
/**
|
|
56
|
+
* Pick specific keys and optionally rename them
|
|
57
|
+
*/
|
|
58
|
+
type PickAndRename<T extends object, Keys extends keyof T, Config extends Partial<Record<Keys, string>>> = Simplify<TransformKeys<Pick<T, Keys>, Config>>;
|
|
59
|
+
/**
|
|
60
|
+
* Omit specific keys and optionally rename remaining ones
|
|
61
|
+
*/
|
|
62
|
+
type OmitAndRename<T extends object, OmitKeys extends keyof T, Config extends RenameConfig<Omit<T, OmitKeys>>> = Simplify<TransformKeys<Omit<T, OmitKeys>, Config>>;
|
|
63
|
+
}
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Runtime function to transform object keys based on configuration
|
|
7
|
+
* Uses the TransformKeys utility type for return type inference
|
|
8
|
+
*/
|
|
9
|
+
export function transformKeys(obj, config) {
|
|
10
|
+
const result = {};
|
|
11
|
+
// Process each property in the original object
|
|
12
|
+
for (const key in obj) {
|
|
13
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
14
|
+
const newKeyName = config[key];
|
|
15
|
+
if (typeof newKeyName === "string") {
|
|
16
|
+
// Rename the key
|
|
17
|
+
result[newKeyName] = obj[key];
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
// Keep original key
|
|
21
|
+
result[key] = obj[key];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Utility to create a type-safe rename configuration with better intellisense
|
|
29
|
+
* The returned function preserves literal string types
|
|
30
|
+
*/
|
|
31
|
+
export function createRenameConfig() {
|
|
32
|
+
return function (config) {
|
|
33
|
+
return config;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { A2A } from "../../types/index.js";
|
|
6
|
+
export declare const STATUS_UPDATE: (taskId: string, contextId: string, status: A2A.TaskState, message?: A2A.Message, timestamp?: string, final?: boolean) => A2A.TaskStatusUpdateEvent;
|
|
7
|
+
export declare const WORKING_UPDATE: (taskId: string, contextId: string, message?: A2A.Message, timestamp?: string) => A2A.TaskStatusUpdateEvent;
|
|
8
|
+
export declare const CANCEL_UPDATE: (taskId: string, contextId: string, message?: A2A.Message, timestamp?: string) => A2A.TaskStatusUpdateEvent;
|
|
9
|
+
export declare const SUBMITTED_UPDATE: (taskId: string, contextId: string, message?: A2A.Message, timestamp?: string) => A2A.TaskStatusUpdateEvent;
|
|
10
|
+
export declare const FAILED_UPDATE_EVENT: (taskId: string, contextId: string, message?: A2A.Message, timestamp?: string) => A2A.TaskStatusUpdateEvent;
|
|
11
|
+
export declare const FINAL_STATES: A2A.TaskState[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { A2A } from "../../types/index.js";
|
|
6
|
+
import { getCurrentTimestamp } from "./utils.js";
|
|
7
|
+
//todo: protocol specific so move to a2a folder
|
|
8
|
+
export const STATUS_UPDATE = (taskId, contextId, status, message, timestamp = getCurrentTimestamp(), final = false) => {
|
|
9
|
+
return {
|
|
10
|
+
taskId: taskId,
|
|
11
|
+
contextId: contextId,
|
|
12
|
+
kind: "status-update",
|
|
13
|
+
status: {
|
|
14
|
+
state: status,
|
|
15
|
+
message: message,
|
|
16
|
+
timestamp: timestamp,
|
|
17
|
+
},
|
|
18
|
+
final: final,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export const WORKING_UPDATE = (taskId, contextId, message, timestamp) => {
|
|
22
|
+
return STATUS_UPDATE(taskId, contextId, A2A.TaskState.working, message, timestamp);
|
|
23
|
+
};
|
|
24
|
+
export const CANCEL_UPDATE = (taskId, contextId, message, timestamp) => {
|
|
25
|
+
return STATUS_UPDATE(taskId, contextId, A2A.TaskState.canceled, message, timestamp, true);
|
|
26
|
+
};
|
|
27
|
+
export const SUBMITTED_UPDATE = (taskId, contextId, message, timestamp) => {
|
|
28
|
+
return STATUS_UPDATE(taskId, contextId, A2A.TaskState.submitted, message, timestamp);
|
|
29
|
+
};
|
|
30
|
+
export const FAILED_UPDATE_EVENT = (taskId, contextId, message, timestamp) => {
|
|
31
|
+
return STATUS_UPDATE(taskId, contextId, A2A.TaskState.failed, message, timestamp, true);
|
|
32
|
+
};
|
|
33
|
+
export const FINAL_STATES = [
|
|
34
|
+
A2A.TaskState.completed,
|
|
35
|
+
A2A.TaskState.failed,
|
|
36
|
+
A2A.TaskState.canceled,
|
|
37
|
+
A2A.TaskState.rejected,
|
|
38
|
+
];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { A2A, MCP } from "../../types/index.js";
|
|
6
|
+
export declare class SystemError<T extends MCP.JSONRPCError> extends Error {
|
|
7
|
+
message: string;
|
|
8
|
+
code: T["error"]["code"];
|
|
9
|
+
data: T["error"]["data"];
|
|
10
|
+
constructor(message: string, code: T["error"]["code"], data: T["error"]["data"]);
|
|
11
|
+
}
|
|
12
|
+
export declare const PARSE_ERROR: <T extends A2A.JSONParseError>(data: T["error"]["data"]) => SystemError<T>;
|
|
13
|
+
export declare const INVALID_REQUEST: <T extends A2A.InvalidRequestError>(data: T["error"]["data"]) => SystemError<T>;
|
|
14
|
+
export declare const METHOD_NOT_FOUND: <T extends A2A.MethodNotFoundError>(data: T["error"]["data"]) => SystemError<T>;
|
|
15
|
+
export declare const INVALID_PARAMS: <T extends A2A.InvalidParamsError>(data: T["error"]["data"]) => SystemError<T>;
|
|
16
|
+
export declare const INTERNAL_ERROR: <T extends A2A.InternalError>(data: T["error"]["data"]) => SystemError<T>;
|
|
17
|
+
export declare const TASK_NOT_FOUND: <T extends A2A.TaskNotFoundError>(data: T["error"]["data"]) => SystemError<T>;
|
|
18
|
+
export declare const TASK_NOT_CANCELABLE: <T extends A2A.TaskNotCancelableError>(data: T["error"]["data"]) => SystemError<T>;
|
|
19
|
+
export declare const PUSH_NOTIFICATION_NOT_SUPPORTED: <T extends A2A.A2AError>(data: T["error"]["data"]) => SystemError<T>;
|
|
20
|
+
export declare const AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED: <T extends A2A.AuthenticatedExtendedCardNotConfiguredError>(data: T["error"]["data"]) => SystemError<T>;
|
|
21
|
+
export declare const UNSUPPORTED_OPERATION: <T extends A2A.A2AError>(data: T["error"]["data"]) => SystemError<T>;
|
|
22
|
+
export declare const CONTENT_TYPE_NOT_SUPPORTED: <T extends A2A.ContentTypeNotSupportedError>(data: T["error"]["data"]) => SystemError<T>;
|
|
23
|
+
export declare const INVALID_AGENT_RESPONSE: <T extends A2A.InvalidAgentResponseError>(data: T["error"]["data"]) => SystemError<T>;
|
|
24
|
+
export declare const FAILED_UPDATE: (taskId: string, contextId: string, messageId: string | undefined, errMessage: string) => A2A.TaskStatusUpdateEvent;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { A2A } from "../../types/index.js";
|
|
6
|
+
export class SystemError extends Error {
|
|
7
|
+
constructor(message, code, data) {
|
|
8
|
+
super(message);
|
|
9
|
+
// this.name = "RpcError";
|
|
10
|
+
this.message = message;
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.data = data;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
// Factory methods for common errors
|
|
16
|
+
export const PARSE_ERROR = (data) => new SystemError("Invalid JSON payload", A2A.ErrorCodeParseError, data);
|
|
17
|
+
export const INVALID_REQUEST = (data) => new SystemError("Request payload validation error", A2A.ErrorCodeInvalidRequest, data);
|
|
18
|
+
export const METHOD_NOT_FOUND = (data) => new SystemError("Method not found", A2A.ErrorCodeMethodNotFound, data);
|
|
19
|
+
export const INVALID_PARAMS = (data) => new SystemError("Invalid parameters", A2A.ErrorCodeInvalidParams, data);
|
|
20
|
+
export const INTERNAL_ERROR = (data) => new SystemError("Internal error", A2A.ErrorCodeInternalError, data);
|
|
21
|
+
export const TASK_NOT_FOUND = (data) => new SystemError("Task not found", A2A.ErrorCodeTaskNotFound, data);
|
|
22
|
+
export const TASK_NOT_CANCELABLE = (data) => new SystemError("Task cannot be canceled", A2A.ErrorCodeTaskNotCancelable, data);
|
|
23
|
+
export const PUSH_NOTIFICATION_NOT_SUPPORTED = (data) => new SystemError("Push Notifications is not supported", A2A.ErrorCodePushNotificationNotSupported, data);
|
|
24
|
+
export const AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED = (data) => new SystemError("Authenticated Extended Card is not configured", A2A.ErrorCodeAuthenticatedExtendedCardNotConfigured, data);
|
|
25
|
+
export const UNSUPPORTED_OPERATION = (data) => new SystemError("This operation is not supported", A2A.ErrorCodeUnsupportedOperation, data);
|
|
26
|
+
export const CONTENT_TYPE_NOT_SUPPORTED = (data) => new SystemError("Content type not supported", A2A.ErrorCodeContentTypeNotSupported, data);
|
|
27
|
+
export const INVALID_AGENT_RESPONSE = (data) => new SystemError("Invalid agent response", A2A.ErrorCodeInvalidAgentResponse, data);
|
|
28
|
+
export const FAILED_UPDATE = (taskId, contextId, messageId = "failed-update", errMessage) => ({
|
|
29
|
+
taskId,
|
|
30
|
+
contextId,
|
|
31
|
+
kind: "status-update",
|
|
32
|
+
final: true,
|
|
33
|
+
status: {
|
|
34
|
+
state: A2A.TaskState.failed,
|
|
35
|
+
message: {
|
|
36
|
+
messageId,
|
|
37
|
+
role: "agent",
|
|
38
|
+
parts: [{ kind: "text", text: errMessage }],
|
|
39
|
+
kind: "message",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Generates a timestamp in ISO 8601 format.
|
|
7
|
+
* @returns The current timestamp as a string.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getCurrentTimestamp(): string;
|
|
10
|
+
/**
|
|
11
|
+
* Sleeps for a given number of milliseconds.
|
|
12
|
+
* @param ms - The number of milliseconds to sleep.
|
|
13
|
+
* @returns A promise that resolves when the sleep is complete.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* await sleep(1000);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Formats a JSON object into a string with indentation.
|
|
23
|
+
* @param json - The JSON object to format.
|
|
24
|
+
* @returns A string representation of the JSON object.
|
|
25
|
+
*/
|
|
26
|
+
export declare function formatJson(json: object): string;
|
|
27
|
+
/**
|
|
28
|
+
* Formats an error into a standard error object for logging.
|
|
29
|
+
* @param error - The error to format.
|
|
30
|
+
* @returns A standard error object.
|
|
31
|
+
*/
|
|
32
|
+
export declare function formatError(error: unknown): Error;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Generates a timestamp in ISO 8601 format.
|
|
7
|
+
* @returns The current timestamp as a string.
|
|
8
|
+
*/
|
|
9
|
+
export function getCurrentTimestamp() {
|
|
10
|
+
return new Date().toISOString();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Sleeps for a given number of milliseconds.
|
|
14
|
+
* @param ms - The number of milliseconds to sleep.
|
|
15
|
+
* @returns A promise that resolves when the sleep is complete.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* await sleep(1000);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function sleep(ms) {
|
|
23
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Formats a JSON object into a string with indentation.
|
|
27
|
+
* @param json - The JSON object to format.
|
|
28
|
+
* @returns A string representation of the JSON object.
|
|
29
|
+
*/
|
|
30
|
+
export function formatJson(json) {
|
|
31
|
+
return JSON.stringify(json, null, 2);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Formats an error into a standard error object for logging.
|
|
35
|
+
* @param error - The error to format.
|
|
36
|
+
* @returns A standard error object.
|
|
37
|
+
*/
|
|
38
|
+
export function formatError(error) {
|
|
39
|
+
if (error instanceof Error) {
|
|
40
|
+
return error;
|
|
41
|
+
}
|
|
42
|
+
return new Error(String(error));
|
|
43
|
+
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Copyright 2025 The Artinet Project
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
6
|
-
import type { Client } from "../types/
|
|
5
|
+
import { A2A } from "../types/index.js";
|
|
6
|
+
import type { Client } from "../types/client.js";
|
|
7
7
|
/**
|
|
8
8
|
* A2AClient is the main client class for interacting with Agent2Agent (A2A) protocol-compliant services.
|
|
9
9
|
* It provides methods for sending tasks, retrieving statuses, canceling operations, and handling streaming responses.
|
|
@@ -14,6 +14,7 @@ export declare class A2AClient implements Client {
|
|
|
14
14
|
private customHeaders;
|
|
15
15
|
private fallbackPath;
|
|
16
16
|
private agentUrl;
|
|
17
|
+
private mergePath;
|
|
17
18
|
/**
|
|
18
19
|
* Creates a new A2AClient instance.
|
|
19
20
|
* @param baseUrl The base URL for the A2A server.
|
|
@@ -28,74 +29,75 @@ export declare class A2AClient implements Client {
|
|
|
28
29
|
* const card = await client.agentCard();
|
|
29
30
|
* console.log(card);
|
|
30
31
|
*/
|
|
31
|
-
constructor(baseUrl: URL | string, headers?: Record<string, string>, fallbackPath?: string);
|
|
32
|
+
constructor(baseUrl: URL | string, headers?: Record<string, string>, fallbackPath?: string, mergePath?: boolean);
|
|
32
33
|
/**
|
|
33
34
|
* Retrieves the AgentCard from the A2A server.
|
|
34
35
|
* Caches the result after the first successful fetch.
|
|
35
36
|
* @returns A promise resolving to the AgentCard.
|
|
36
37
|
*/
|
|
37
|
-
agentCard(): Promise<AgentCard>;
|
|
38
|
+
agentCard(): Promise<A2A.AgentCard>;
|
|
38
39
|
/**
|
|
39
|
-
*
|
|
40
|
-
* @returns A promise resolving to the
|
|
40
|
+
* Retrieves the AgentCard from the A2A server.
|
|
41
|
+
* @returns A promise resolving to the AgentCard.
|
|
41
42
|
*/
|
|
42
|
-
|
|
43
|
+
getAgentCard(): Promise<A2A.AgentCard>;
|
|
43
44
|
/**
|
|
44
|
-
*
|
|
45
|
-
* @
|
|
46
|
-
* @returns A promise resolving to Message/Task response from the agent server or null.
|
|
45
|
+
* Refreshes the cached AgentCard by fetching it again from the server.
|
|
46
|
+
* @returns A promise resolving to the updated AgentCard.
|
|
47
47
|
*/
|
|
48
|
-
|
|
48
|
+
refreshAgentCard(): Promise<A2A.AgentCard>;
|
|
49
|
+
sendMessage(params: A2A.MessageSendParams): Promise<A2A.Message | A2A.Task | null>;
|
|
50
|
+
sendMessage(params: string | A2A.MessageSendParams["message"]): Promise<A2A.Message | A2A.Task | null>;
|
|
49
51
|
/**
|
|
50
52
|
* @deprecated Use sendMessage instead.
|
|
51
53
|
* Sends a task request to the agent (non-streaming).
|
|
52
54
|
* @param params The parameters for the message/send method.
|
|
53
55
|
* @returns A promise resolving to the Task object or null.
|
|
54
56
|
*/
|
|
55
|
-
sendTask(params: MessageSendParams): Promise<Message | Task | null>;
|
|
57
|
+
sendTask(params: A2A.MessageSendParams): Promise<A2A.Message | A2A.Task | null>;
|
|
56
58
|
/**
|
|
57
59
|
* Sends a Message and returns a stream of status and artifact updates.
|
|
58
60
|
* @param params Task parameters for the request
|
|
59
61
|
* @returns An AsyncIterable that yields TaskStatusUpdateEvent/TaskArtifactUpdateEvent/Task/Message payloads.
|
|
60
62
|
*/
|
|
61
|
-
sendStreamingMessage(params: MessageSendParams | string): AsyncIterable<
|
|
63
|
+
sendStreamingMessage(params: A2A.MessageSendParams | string): AsyncIterable<A2A.Update>;
|
|
62
64
|
/**
|
|
63
65
|
* @deprecated Use sendStreamingMessage instead.
|
|
64
66
|
* Sends a task and returns a subscription to status and artifact updates.
|
|
65
67
|
* @param params Task parameters for the request
|
|
66
68
|
* @returns An AsyncIterable that yields TaskStatusUpdateEvent or TaskArtifactUpdateEvent payloads.
|
|
67
69
|
*/
|
|
68
|
-
sendTaskSubscribe(params: MessageSendParams): AsyncIterable<
|
|
70
|
+
sendTaskSubscribe(params: A2A.MessageSendParams): AsyncIterable<A2A.Update>;
|
|
69
71
|
/**
|
|
70
72
|
* Retrieves the current state of a task.
|
|
71
73
|
* @param params The parameters for the tasks/get method.
|
|
72
74
|
* @returns A promise resolving to the Task object or null.
|
|
73
75
|
*/
|
|
74
|
-
getTask(params: TaskQueryParams): Promise<Task | null>;
|
|
76
|
+
getTask(params: A2A.TaskQueryParams): Promise<A2A.Task | null>;
|
|
75
77
|
/**
|
|
76
78
|
* Cancels a currently running task.
|
|
77
79
|
* @param params The parameters for the tasks/cancel method.
|
|
78
80
|
* @returns A promise resolving to the updated Task object (usually canceled state) or null.
|
|
79
81
|
*/
|
|
80
|
-
cancelTask(params: TaskIdParams): Promise<Task | null>;
|
|
82
|
+
cancelTask(params: A2A.TaskIdParams): Promise<A2A.Task | null>;
|
|
81
83
|
/**
|
|
82
84
|
* Sets or updates the push notification config for a task.
|
|
83
85
|
* @param params The parameters for the tasks/pushNotificationConfig/set method (which is TaskPushNotificationConfig).
|
|
84
86
|
* @returns A promise resolving to the confirmed TaskPushNotificationConfig or null.
|
|
85
87
|
*/
|
|
86
|
-
setTaskPushNotification(params: TaskPushNotificationConfig): Promise<TaskPushNotificationConfig | null>;
|
|
88
|
+
setTaskPushNotification(params: A2A.TaskPushNotificationConfig): Promise<A2A.TaskPushNotificationConfig | null>;
|
|
87
89
|
/**
|
|
88
90
|
* Retrieves the currently configured push notification config for a task.
|
|
89
91
|
* @param params The parameters for the tasks/pushNotificationConfig/get method.
|
|
90
92
|
* @returns A promise resolving to the TaskPushNotificationConfig or null.
|
|
91
93
|
*/
|
|
92
|
-
getTaskPushNotification(params: TaskIdParams): Promise<TaskPushNotificationConfig | null>;
|
|
94
|
+
getTaskPushNotification(params: A2A.TaskIdParams): Promise<A2A.TaskPushNotificationConfig | null>;
|
|
93
95
|
/**
|
|
94
96
|
* Resubscribes to an existing task's update stream.
|
|
95
97
|
* @param params Parameters identifying the task to resubscribe to
|
|
96
98
|
* @returns An AsyncIterable that yields TaskStatusUpdateEvent or TaskArtifactUpdateEvent payloads.
|
|
97
99
|
*/
|
|
98
|
-
resubscribeTask(params: TaskQueryParams): AsyncIterable<
|
|
100
|
+
resubscribeTask(params: A2A.TaskQueryParams): AsyncIterable<A2A.Update>;
|
|
99
101
|
/**
|
|
100
102
|
* Checks if the server supports a specific capability based on the agent card.
|
|
101
103
|
* @param capability The capability to check (e.g., 'streaming', 'pushNotifications').
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* Copyright 2025 The Artinet Project
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import { executeJsonRpcRequest, executeGetRequest,
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { executeJsonRpcRequest, executeGetRequest, } from "../transport/rpc/rpc-client.js";
|
|
6
|
+
import { executeStreamEvents } from "../transport/streaming/event-stream.js";
|
|
7
|
+
import { INTERNAL_ERROR } from "../utils/common/errors.js";
|
|
8
|
+
import { logger } from "../config/index.js";
|
|
8
9
|
import { createMessageSendParams } from "../services/a2a/helpers/message-builder.js";
|
|
9
10
|
/**
|
|
10
11
|
* A2AClient is the main client class for interacting with Agent2Agent (A2A) protocol-compliant services.
|
|
@@ -16,6 +17,7 @@ export class A2AClient {
|
|
|
16
17
|
customHeaders = {};
|
|
17
18
|
fallbackPath;
|
|
18
19
|
agentUrl;
|
|
20
|
+
mergePath;
|
|
19
21
|
/**
|
|
20
22
|
* Creates a new A2AClient instance.
|
|
21
23
|
* @param baseUrl The base URL for the A2A server.
|
|
@@ -30,11 +32,12 @@ export class A2AClient {
|
|
|
30
32
|
* const card = await client.agentCard();
|
|
31
33
|
* console.log(card);
|
|
32
34
|
*/
|
|
33
|
-
constructor(baseUrl, headers = {}, fallbackPath) {
|
|
35
|
+
constructor(baseUrl, headers = {}, fallbackPath, mergePath = false) {
|
|
34
36
|
this.baseUrl = typeof baseUrl === "string" ? new URL(baseUrl) : baseUrl;
|
|
35
37
|
this.customHeaders = headers;
|
|
36
38
|
this.fallbackPath = fallbackPath ?? "/agent-card";
|
|
37
39
|
this.agentUrl = this.baseUrl;
|
|
40
|
+
this.mergePath = mergePath;
|
|
38
41
|
}
|
|
39
42
|
/**
|
|
40
43
|
* Retrieves the AgentCard from the A2A server.
|
|
@@ -47,6 +50,9 @@ export class A2AClient {
|
|
|
47
50
|
}
|
|
48
51
|
// Standard location for agent cards
|
|
49
52
|
const wellKnownUrl = new URL("/.well-known/agent-card.json", this.baseUrl);
|
|
53
|
+
if (this.mergePath) {
|
|
54
|
+
wellKnownUrl.pathname = this.baseUrl.pathname + wellKnownUrl.pathname;
|
|
55
|
+
}
|
|
50
56
|
try {
|
|
51
57
|
try {
|
|
52
58
|
if (!URL.canParse(wellKnownUrl)) {
|
|
@@ -59,23 +65,34 @@ export class A2AClient {
|
|
|
59
65
|
this.cachedAgentCard = card;
|
|
60
66
|
}
|
|
61
67
|
catch (error) {
|
|
68
|
+
logger.error("A2AClient:agentCard: Failed to fetch agent card (well-known):", error);
|
|
62
69
|
const fallbackUrl = new URL(this.fallbackPath, this.baseUrl);
|
|
70
|
+
if (this.mergePath) {
|
|
71
|
+
fallbackUrl.pathname = this.baseUrl.pathname + fallbackUrl.pathname;
|
|
72
|
+
}
|
|
63
73
|
const fallbackCard = await executeGetRequest(fallbackUrl, this.customHeaders, "agent card (fallback)");
|
|
64
74
|
if (!fallbackCard.name ||
|
|
65
75
|
fallbackCard.name === null ||
|
|
66
76
|
fallbackCard.name === undefined) {
|
|
67
|
-
throw new Error("No fallback agent card found");
|
|
77
|
+
throw new Error("No fallback agent card found" + error);
|
|
68
78
|
}
|
|
69
79
|
this.cachedAgentCard = fallbackCard;
|
|
70
80
|
}
|
|
71
81
|
}
|
|
72
82
|
catch (error) {
|
|
73
|
-
|
|
74
|
-
throw INTERNAL_ERROR(
|
|
83
|
+
logger.error("A2AClient:agentCard: Failed to fetch or parse agent card:", error);
|
|
84
|
+
throw INTERNAL_ERROR(error);
|
|
75
85
|
}
|
|
76
86
|
this.agentUrl = new URL(this.cachedAgentCard.url, this.baseUrl);
|
|
77
87
|
return this.cachedAgentCard;
|
|
78
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Retrieves the AgentCard from the A2A server.
|
|
91
|
+
* @returns A promise resolving to the AgentCard.
|
|
92
|
+
*/
|
|
93
|
+
getAgentCard() {
|
|
94
|
+
return this.agentCard();
|
|
95
|
+
}
|
|
79
96
|
/**
|
|
80
97
|
* Refreshes the cached AgentCard by fetching it again from the server.
|
|
81
98
|
* @returns A promise resolving to the updated AgentCard.
|
|
@@ -90,7 +107,11 @@ export class A2AClient {
|
|
|
90
107
|
* @returns A promise resolving to Message/Task response from the agent server or null.
|
|
91
108
|
*/
|
|
92
109
|
async sendMessage(params) {
|
|
93
|
-
return await executeJsonRpcRequest(this.agentUrl, "message/send",
|
|
110
|
+
return await executeJsonRpcRequest(this.agentUrl, "message/send", typeof params === "string"
|
|
111
|
+
? createMessageSendParams(params)
|
|
112
|
+
: typeof params === "object" && "message" in params
|
|
113
|
+
? params
|
|
114
|
+
: createMessageSendParams({ message: params }), this.customHeaders);
|
|
94
115
|
}
|
|
95
116
|
/**
|
|
96
117
|
* @deprecated Use sendMessage instead.
|
|
@@ -181,7 +202,7 @@ export class A2AClient {
|
|
|
181
202
|
}
|
|
182
203
|
}
|
|
183
204
|
catch (error) {
|
|
184
|
-
|
|
205
|
+
logger.error(`A2AClient:supports: Failed to determine support for capability '${capability}':`, error);
|
|
185
206
|
return false; // Assume not supported if card fetch fails
|
|
186
207
|
}
|
|
187
208
|
}
|