@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,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
/** //todo move to @artinet/sdk from core v0.1
|
|
6
|
+
* @fileoverview Zero-dependency observability interfaces for the Artinet ecosystem.
|
|
7
|
+
*
|
|
8
|
+
* Provides minimal interfaces for logging and tracing that consumers can implement
|
|
9
|
+
* with their preferred tools (Pino, Winston, OpenTelemetry, etc.).
|
|
10
|
+
*
|
|
11
|
+
* Design principles:
|
|
12
|
+
* - Zero runtime dependencies
|
|
13
|
+
* - No-op defaults for zero overhead when not configured
|
|
14
|
+
* - Environment agnostic (Node, Deno, Bun, edge, browser)
|
|
15
|
+
* - Consumer brings their own implementation
|
|
16
|
+
*
|
|
17
|
+
* @module utils/observability
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Minimal logger interface.
|
|
21
|
+
*
|
|
22
|
+
* Consumers provide their own implementation using their preferred
|
|
23
|
+
* logging library (Pino, Winston, console, etc.).
|
|
24
|
+
*
|
|
25
|
+
* Uses spread args for maximum compatibility - works naturally with
|
|
26
|
+
* console.log, Pino, Winston, and most logging libraries.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* // Console implementation (just works)
|
|
31
|
+
* const logger: ILogger = console;
|
|
32
|
+
*
|
|
33
|
+
* // Pino implementation
|
|
34
|
+
* import pino from 'pino';
|
|
35
|
+
* const pinoLogger = pino();
|
|
36
|
+
*
|
|
37
|
+
* const logger: ILogger = {
|
|
38
|
+
* debug: (msg, ...args) => pinoLogger.debug(Object.assign({}, ...args), msg),
|
|
39
|
+
* info: (msg, ...args) => pinoLogger.info(Object.assign({}, ...args), msg),
|
|
40
|
+
* warn: (msg, ...args) => pinoLogger.warn(Object.assign({}, ...args), msg),
|
|
41
|
+
* error: (msg, ...args) => pinoLogger.error(Object.assign({}, ...args), msg),
|
|
42
|
+
* };
|
|
43
|
+
*
|
|
44
|
+
* // Winston implementation
|
|
45
|
+
* import winston from 'winston';
|
|
46
|
+
* const winstonLogger = winston.createLogger({ ... });
|
|
47
|
+
*
|
|
48
|
+
* const logger: ILogger = {
|
|
49
|
+
* debug: (msg, ...args) => winstonLogger.debug(msg, ...args),
|
|
50
|
+
* info: (msg, ...args) => winstonLogger.info(msg, ...args),
|
|
51
|
+
* warn: (msg, ...args) => winstonLogger.warn(msg, ...args),
|
|
52
|
+
* error: (msg, ...args) => winstonLogger.error(msg, ...args),
|
|
53
|
+
* };
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export interface ILogger {
|
|
57
|
+
/**
|
|
58
|
+
* Log level.
|
|
59
|
+
* @default "info"
|
|
60
|
+
*/
|
|
61
|
+
level?: "trace" | "verbose" | "debug" | "info" | "warn" | "error" | "silent";
|
|
62
|
+
/**
|
|
63
|
+
* Log debug-level message.
|
|
64
|
+
* @param msg - Log message
|
|
65
|
+
* @param args - Optional additional arguments (context, data, etc.)
|
|
66
|
+
*/
|
|
67
|
+
debug(msg: string, ...args: unknown[]): void;
|
|
68
|
+
/**
|
|
69
|
+
* Log info-level message.
|
|
70
|
+
* @param msg - Log message
|
|
71
|
+
* @param args - Optional additional arguments (context, data, etc.)
|
|
72
|
+
*/
|
|
73
|
+
info(msg: string, ...args: unknown[]): void;
|
|
74
|
+
/**
|
|
75
|
+
* Log warn-level message.
|
|
76
|
+
* @param msg - Log message
|
|
77
|
+
* @param args - Optional additional arguments (context, data, etc.)
|
|
78
|
+
*/
|
|
79
|
+
warn(msg: string, ...args: unknown[]): void;
|
|
80
|
+
/**
|
|
81
|
+
* Log error-level message.
|
|
82
|
+
* @param msg - Log message
|
|
83
|
+
* @param err - Error to log
|
|
84
|
+
*/
|
|
85
|
+
error(msg: string, err: unknown): void;
|
|
86
|
+
/**
|
|
87
|
+
* Set log level.
|
|
88
|
+
* @param level - Log level
|
|
89
|
+
*/
|
|
90
|
+
setLevel?(level: "trace" | "verbose" | "debug" | "info" | "warn" | "error" | "silent"): void;
|
|
91
|
+
/**
|
|
92
|
+
* Get log level.
|
|
93
|
+
* @returns Current log level or undefined if not set
|
|
94
|
+
*/
|
|
95
|
+
getLevel?(): "trace" | "verbose" | "debug" | "info" | "warn" | "error" | "silent";
|
|
96
|
+
/**
|
|
97
|
+
* Create child logger with bound context.
|
|
98
|
+
* @param context - Context to bind to the child logger
|
|
99
|
+
* @returns Child logger or undefined if not implemented
|
|
100
|
+
*/
|
|
101
|
+
child?(context: Record<string, unknown>): ILogger;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Format error for logging.
|
|
105
|
+
* @param err - Error to format
|
|
106
|
+
* @returns Formatted error
|
|
107
|
+
*/
|
|
108
|
+
export declare function formatError(err: unknown): Record<string, unknown>;
|
|
109
|
+
/**
|
|
110
|
+
* No-op logger implementation.
|
|
111
|
+
* Used when no logger is configured - zero overhead.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const logger = config.logger ?? noopLogger;
|
|
116
|
+
* logger.info('This does nothing if no logger configured');
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare const noopLogger: ILogger;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Format error for logging.
|
|
7
|
+
* @param err - Error to format
|
|
8
|
+
* @returns Formatted error
|
|
9
|
+
*/
|
|
10
|
+
export function formatError(err) {
|
|
11
|
+
if (err instanceof Error) {
|
|
12
|
+
return {
|
|
13
|
+
message: err.message,
|
|
14
|
+
stack: err.stack,
|
|
15
|
+
name: err.name,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return { error: String(err) };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* No-op logger implementation.
|
|
22
|
+
* Used when no logger is configured - zero overhead.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const logger = config.logger ?? noopLogger;
|
|
27
|
+
* logger.info('This does nothing if no logger configured');
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export const noopLogger = {
|
|
31
|
+
debug: () => { },
|
|
32
|
+
info: () => { },
|
|
33
|
+
warn: () => { },
|
|
34
|
+
error: () => { },
|
|
35
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
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 class MessageBuilder {
|
|
7
|
+
message: A2A.Message;
|
|
8
|
+
constructor(message?: Partial<A2A.Message>);
|
|
9
|
+
valueOf(): A2A.Message;
|
|
10
|
+
}
|
|
11
|
+
export declare const MESSAGE: (message?: Partial<A2A.Message>) => A2A.Message;
|
|
12
|
+
export declare class MessageSendConfigurationBuilder {
|
|
13
|
+
configuration: A2A.MessageSendConfiguration;
|
|
14
|
+
constructor(configuration?: Partial<A2A.MessageSendConfiguration> | null);
|
|
15
|
+
valueOf(): A2A.MessageSendConfiguration;
|
|
16
|
+
}
|
|
17
|
+
export declare const createMessageSendParams: (messageSendParams: Partial<A2A.MessageSendParams> | string) => A2A.MessageSendParams;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { v4 as uuidv4 } from "uuid";
|
|
6
|
+
export class MessageBuilder {
|
|
7
|
+
constructor(message = {}) {
|
|
8
|
+
this.message = {
|
|
9
|
+
role: "user",
|
|
10
|
+
parts: [],
|
|
11
|
+
metadata: undefined,
|
|
12
|
+
extensions: undefined,
|
|
13
|
+
referenceTaskIds: undefined,
|
|
14
|
+
messageId: uuidv4(),
|
|
15
|
+
taskId: undefined,
|
|
16
|
+
contextId: undefined,
|
|
17
|
+
kind: "message",
|
|
18
|
+
};
|
|
19
|
+
this.message.role = message.role ?? this.message.role;
|
|
20
|
+
this.message.parts = message.parts ?? this.message.parts;
|
|
21
|
+
this.message.metadata = message.metadata ?? this.message.metadata;
|
|
22
|
+
this.message.extensions = message.extensions ?? this.message.extensions;
|
|
23
|
+
this.message.referenceTaskIds =
|
|
24
|
+
message.referenceTaskIds ?? this.message.referenceTaskIds;
|
|
25
|
+
this.message.messageId = message.messageId ?? this.message.messageId;
|
|
26
|
+
this.message.taskId = message.taskId ?? this.message.taskId;
|
|
27
|
+
this.message.contextId = message.contextId ?? this.message.contextId;
|
|
28
|
+
}
|
|
29
|
+
valueOf() {
|
|
30
|
+
return this.message;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export const MESSAGE = (message = {}) => new MessageBuilder(message).message;
|
|
34
|
+
export class MessageSendConfigurationBuilder {
|
|
35
|
+
constructor(configuration = {}) {
|
|
36
|
+
this.configuration = {
|
|
37
|
+
acceptedOutputModes: undefined,
|
|
38
|
+
historyLength: undefined,
|
|
39
|
+
pushNotificationConfig: undefined,
|
|
40
|
+
blocking: undefined,
|
|
41
|
+
};
|
|
42
|
+
this.configuration.acceptedOutputModes =
|
|
43
|
+
configuration?.acceptedOutputModes ??
|
|
44
|
+
this.configuration.acceptedOutputModes;
|
|
45
|
+
this.configuration.historyLength =
|
|
46
|
+
configuration?.historyLength ?? this.configuration.historyLength;
|
|
47
|
+
this.configuration.pushNotificationConfig =
|
|
48
|
+
configuration?.pushNotificationConfig ??
|
|
49
|
+
this.configuration.pushNotificationConfig;
|
|
50
|
+
this.configuration.blocking =
|
|
51
|
+
configuration?.blocking ?? this.configuration.blocking;
|
|
52
|
+
}
|
|
53
|
+
valueOf() {
|
|
54
|
+
return this.configuration;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export const createMessageSendParams = (messageSendParams) => {
|
|
58
|
+
const isString = typeof messageSendParams === "string";
|
|
59
|
+
return {
|
|
60
|
+
message: new MessageBuilder(isString
|
|
61
|
+
? { parts: [{ text: messageSendParams, kind: "text" }] }
|
|
62
|
+
: messageSendParams.message).valueOf(),
|
|
63
|
+
configuration: new MessageSendConfigurationBuilder(isString ? undefined : messageSendParams.configuration).valueOf(),
|
|
64
|
+
metadata: isString ? undefined : messageSendParams.metadata,
|
|
65
|
+
};
|
|
66
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { MCP } from "../../types/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Parses a JSON-RPC response string and validates its structure.
|
|
8
|
+
* If the response contains an error, it is thrown as an A2AError.
|
|
9
|
+
* If the response contains neither a result nor an error, a validation error is thrown.
|
|
10
|
+
*
|
|
11
|
+
* @param data Response data as string
|
|
12
|
+
* @returns The parsed and validated response object
|
|
13
|
+
* @throws A2AError if the response contains an error or is invalid
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseResponse<Res extends MCP.JSONRPCResponse | MCP.JSONRPCError>(data: string): Res;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { MCP } from "../../types/index.js";
|
|
6
|
+
import { SystemError, PARSE_ERROR } from "../../utils/common/errors.js";
|
|
7
|
+
import { logger } from "../../config/index.js";
|
|
8
|
+
/**
|
|
9
|
+
* Parses a JSON-RPC response string and validates its structure.
|
|
10
|
+
* If the response contains an error, it is thrown as an A2AError.
|
|
11
|
+
* If the response contains neither a result nor an error, a validation error is thrown.
|
|
12
|
+
*
|
|
13
|
+
* @param data Response data as string
|
|
14
|
+
* @returns The parsed and validated response object
|
|
15
|
+
* @throws A2AError if the response contains an error or is invalid
|
|
16
|
+
*/
|
|
17
|
+
export function parseResponse(data) {
|
|
18
|
+
if (!data) {
|
|
19
|
+
throw PARSE_ERROR("Invalid response data");
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const parsed = JSON.parse(data); //todo: leverage safe parse
|
|
23
|
+
if (parsed.error) {
|
|
24
|
+
const parsedError = MCP.JSONRPCErrorSchema.safeParse(parsed);
|
|
25
|
+
if (!parsedError.success) {
|
|
26
|
+
throw PARSE_ERROR(parsedError.error);
|
|
27
|
+
}
|
|
28
|
+
throw new SystemError(parsedError.data.error.message, parsedError.data.error.code, parsedError.data.error.data);
|
|
29
|
+
}
|
|
30
|
+
if (typeof parsed !== "object" ||
|
|
31
|
+
parsed === null ||
|
|
32
|
+
parsed.jsonrpc !== "2.0") {
|
|
33
|
+
throw PARSE_ERROR("invalid jsonrpc");
|
|
34
|
+
}
|
|
35
|
+
if (parsed.result === undefined) {
|
|
36
|
+
throw PARSE_ERROR("result is undefined");
|
|
37
|
+
}
|
|
38
|
+
return parsed;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (error instanceof SystemError) {
|
|
42
|
+
logger.error("parseResponse: SystemError:", error);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
logger.error("parseResponse: Error parsing response:", error);
|
|
46
|
+
throw PARSE_ERROR(error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import type { A2A, MCP } from "../../types/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Creates a JSON-RPC request body with the specified method and parameters.
|
|
8
|
+
*, ErrorCodeParseError
|
|
9
|
+
* @param method The JSON-RPC method name
|
|
10
|
+
* @param params The parameters for the method
|
|
11
|
+
* @param requestId Optional request ID (generates a UUID v4 if not provided)
|
|
12
|
+
* @returns A properly formatted JSON-RPC request object
|
|
13
|
+
*/
|
|
14
|
+
export declare function createJsonRpcRequest<Req extends A2A.A2ARequest>(method: Req["method"], params: Req["params"], requestId?: string | number): MCP.JSONRPCRequest;
|
|
15
|
+
/**
|
|
16
|
+
* Sends a JSON-RPC request to the specified endpoint.
|
|
17
|
+
*
|
|
18
|
+
* @param baseUrl The API endpoint URL
|
|
19
|
+
* @param method The JSON-RPC method name
|
|
20
|
+
* @param params The parameters for the method
|
|
21
|
+
* @param headers Custom headers to include in the request
|
|
22
|
+
* @param acceptHeader The desired Accept header ('application/json' or 'text/event-stream')
|
|
23
|
+
* @returns A Promise resolving to the fetch Response object
|
|
24
|
+
* @throws RpcError if there's a network error
|
|
25
|
+
*/
|
|
26
|
+
export declare function sendJsonRpcRequest<Req extends A2A.A2ARequest>(baseUrl: URL, method: Req["method"], params: Req["params"], headers?: Record<string, string>, acceptHeader?: "application/json" | "text/event-stream"): Promise<Response>;
|
|
27
|
+
/**
|
|
28
|
+
* Sends a GET request to the specified endpoint.
|
|
29
|
+
* This is used for non-JSON-RPC calls like agent card retrieval.
|
|
30
|
+
*
|
|
31
|
+
* @param url The endpoint URL
|
|
32
|
+
* @param headers Custom headers to include in the request
|
|
33
|
+
* @returns A Promise resolving to the fetch Response object
|
|
34
|
+
* @throws RpcError if there's a network error
|
|
35
|
+
*/
|
|
36
|
+
export declare function sendGetRequest(url: URL, headers?: Record<string, string>): Promise<Response>;
|
|
37
|
+
/**
|
|
38
|
+
* Processes a standard JSON-RPC response (non-streaming).
|
|
39
|
+
* Parses the response, validates it, and returns the result payload.
|
|
40
|
+
*
|
|
41
|
+
* @param response The fetch Response object
|
|
42
|
+
* @param expectedMethod Optional method name for logging purposes
|
|
43
|
+
* @returns A promise resolving to the result payload
|
|
44
|
+
* @throws RpcError if there's an error in the response
|
|
45
|
+
*/
|
|
46
|
+
export declare function handleJsonRpcResponse<Res extends MCP.JSONRPCResultResponse>(response: Response, expectedMethod?: string): Promise<NonNullable<Res["result"]>>;
|
|
47
|
+
/**
|
|
48
|
+
* Processes a JSON response from a regular GET request.
|
|
49
|
+
* Handles error checking and returns the parsed JSON.
|
|
50
|
+
*
|
|
51
|
+
* @param response The fetch Response object
|
|
52
|
+
* @param endpoint Optional endpoint description for logging purposes
|
|
53
|
+
* @returns A promise resolving to the parsed JSON
|
|
54
|
+
* @throws RpcError if there's a response error
|
|
55
|
+
*/
|
|
56
|
+
export declare function handleJsonResponse<T>(response: Response, endpoint?: string): Promise<T>;
|
|
57
|
+
/**
|
|
58
|
+
* Sends a JSON-RPC request and processes the response in a single operation.
|
|
59
|
+
* This combines sendJsonRpcRequest and handleJsonRpcResponse into one call.
|
|
60
|
+
*
|
|
61
|
+
* @param baseUrl The API endpoint URL
|
|
62
|
+
* @param method The JSON-RPC method name
|
|
63
|
+
* @param params The parameters for the method
|
|
64
|
+
* @param headers Custom headers to include in the request
|
|
65
|
+
* @param acceptHeader The desired Accept header ('application/json' or 'text/event-stream')
|
|
66
|
+
* @returns A Promise resolving to the result payload
|
|
67
|
+
* @throws RpcError if there's a network error or error in the response
|
|
68
|
+
*/
|
|
69
|
+
export declare function executeJsonRpcRequest<Req extends A2A.A2ARequest, Res extends MCP.JSONRPCResultResponse>(baseUrl: URL, method: Req["method"], params: Req["params"], headers?: Record<string, string>, acceptHeader?: "application/json" | "text/event-stream"): Promise<NonNullable<Res["result"]>>;
|
|
70
|
+
/**
|
|
71
|
+
* Sends a GET request and processes the JSON response.
|
|
72
|
+
* Helper for non-RPC REST endpoints.
|
|
73
|
+
*
|
|
74
|
+
* @param url The endpoint URL
|
|
75
|
+
* @param headers Custom headers to include in the request
|
|
76
|
+
* @param endpoint Optional endpoint description for logging
|
|
77
|
+
* @returns A Promise resolving to the parsed JSON
|
|
78
|
+
* @throws RpcError if there's a network error or error in the response
|
|
79
|
+
*/
|
|
80
|
+
export declare function executeGetRequest<T>(url: URL, headers?: Record<string, string>, endpoint?: string): Promise<T>;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* HTTP JSON-RPC client utilities.
|
|
7
|
+
* Handles the common pattern of sending JSON-RPC requests and processing responses.
|
|
8
|
+
*/
|
|
9
|
+
import { v4 as uuidv4 } from "uuid";
|
|
10
|
+
import { SystemError, INTERNAL_ERROR, PARSE_ERROR, } from "../../utils/common/errors.js";
|
|
11
|
+
import { parseResponse } from "./parser.js";
|
|
12
|
+
import { logger } from "../../config/index.js";
|
|
13
|
+
/**
|
|
14
|
+
* Creates a JSON-RPC request body with the specified method and parameters.
|
|
15
|
+
*, ErrorCodeParseError
|
|
16
|
+
* @param method The JSON-RPC method name
|
|
17
|
+
* @param params The parameters for the method
|
|
18
|
+
* @param requestId Optional request ID (generates a UUID v4 if not provided)
|
|
19
|
+
* @returns A properly formatted JSON-RPC request object
|
|
20
|
+
*/
|
|
21
|
+
export function createJsonRpcRequest(method, params, requestId = uuidv4()) {
|
|
22
|
+
return {
|
|
23
|
+
jsonrpc: "2.0",
|
|
24
|
+
id: requestId,
|
|
25
|
+
method,
|
|
26
|
+
params,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Sends a JSON-RPC request to the specified endpoint.
|
|
31
|
+
*
|
|
32
|
+
* @param baseUrl The API endpoint URL
|
|
33
|
+
* @param method The JSON-RPC method name
|
|
34
|
+
* @param params The parameters for the method
|
|
35
|
+
* @param headers Custom headers to include in the request
|
|
36
|
+
* @param acceptHeader The desired Accept header ('application/json' or 'text/event-stream')
|
|
37
|
+
* @returns A Promise resolving to the fetch Response object
|
|
38
|
+
* @throws RpcError if there's a network error
|
|
39
|
+
*/
|
|
40
|
+
export async function sendJsonRpcRequest(baseUrl, method, params, headers = {}, acceptHeader = "application/json") {
|
|
41
|
+
const requestBody = createJsonRpcRequest(method, params);
|
|
42
|
+
try {
|
|
43
|
+
return await fetch(baseUrl, {
|
|
44
|
+
method: "POST",
|
|
45
|
+
headers: {
|
|
46
|
+
"Content-Type": "application/json",
|
|
47
|
+
"Access-Control-Allow-Origin": "*",
|
|
48
|
+
Accept: acceptHeader,
|
|
49
|
+
...headers,
|
|
50
|
+
},
|
|
51
|
+
priority: "high",
|
|
52
|
+
mode: "cors",
|
|
53
|
+
keepalive: true,
|
|
54
|
+
body: JSON.stringify(requestBody),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch (networkError) {
|
|
58
|
+
logger.error("SendJsonRpcRequest: Network error during RPC call:", networkError);
|
|
59
|
+
// Wrap network errors into a standard error format
|
|
60
|
+
throw INTERNAL_ERROR(networkError);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Sends a GET request to the specified endpoint.
|
|
65
|
+
* This is used for non-JSON-RPC calls like agent card retrieval.
|
|
66
|
+
*
|
|
67
|
+
* @param url The endpoint URL
|
|
68
|
+
* @param headers Custom headers to include in the request
|
|
69
|
+
* @returns A Promise resolving to the fetch Response object
|
|
70
|
+
* @throws RpcError if there's a network error
|
|
71
|
+
*/
|
|
72
|
+
export async function sendGetRequest(url, headers = {}) {
|
|
73
|
+
try {
|
|
74
|
+
return await fetch(url, {
|
|
75
|
+
method: "GET",
|
|
76
|
+
headers: {
|
|
77
|
+
Accept: "application/json",
|
|
78
|
+
...headers,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch (networkError) {
|
|
83
|
+
logger.error("SendGetRequest: Network error during GET request:", networkError);
|
|
84
|
+
throw INTERNAL_ERROR(networkError);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Processes a standard JSON-RPC response (non-streaming).
|
|
89
|
+
* Parses the response, validates it, and returns the result payload.
|
|
90
|
+
*
|
|
91
|
+
* @param response The fetch Response object
|
|
92
|
+
* @param expectedMethod Optional method name for logging purposes
|
|
93
|
+
* @returns A promise resolving to the result payload
|
|
94
|
+
* @throws RpcError if there's an error in the response
|
|
95
|
+
*/
|
|
96
|
+
export async function handleJsonRpcResponse(response, expectedMethod) {
|
|
97
|
+
let responseBody = null;
|
|
98
|
+
try {
|
|
99
|
+
responseBody = await response.text();
|
|
100
|
+
if (!response.ok) {
|
|
101
|
+
try {
|
|
102
|
+
// Try to parse error as JSON-RPC
|
|
103
|
+
parseResponse(responseBody);
|
|
104
|
+
// If we get here, it means there was no error in the response
|
|
105
|
+
// But the HTTP status was not OK, so we throw a generic error
|
|
106
|
+
}
|
|
107
|
+
catch (parseError) {
|
|
108
|
+
logger.warn("handleJsonRpcResponse", "Error parsing JSON-RPC response:", parseError);
|
|
109
|
+
}
|
|
110
|
+
// Throw a generic HTTP error if we couldn't extract an RPC error
|
|
111
|
+
throw new Error(`HTTP error ${response.status}: ${response.statusText}${responseBody ? ` - ${responseBody}` : ""}`);
|
|
112
|
+
}
|
|
113
|
+
// Parse and validate the response
|
|
114
|
+
// If it has an error, parseResponse will throw
|
|
115
|
+
// If it doesn't have a result, parseResponse will also throw
|
|
116
|
+
const jsonResponse = parseResponse(responseBody);
|
|
117
|
+
// At this point, we know we have a valid result
|
|
118
|
+
// NonNullable is used in the return type to ensure TypeScript knows this
|
|
119
|
+
return jsonResponse.result;
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
logger.error(`handleJsonRpcResponse: Error processing response [${expectedMethod}]:`, error);
|
|
123
|
+
// Re-throw RpcError instances directly, wrap others
|
|
124
|
+
if (error instanceof SystemError) {
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
throw INTERNAL_ERROR(error);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Processes a JSON response from a regular GET request.
|
|
134
|
+
* Handles error checking and returns the parsed JSON.
|
|
135
|
+
*
|
|
136
|
+
* @param response The fetch Response object
|
|
137
|
+
* @param endpoint Optional endpoint description for logging purposes
|
|
138
|
+
* @returns A promise resolving to the parsed JSON
|
|
139
|
+
* @throws RpcError if there's a response error
|
|
140
|
+
*/
|
|
141
|
+
export async function handleJsonResponse(response, endpoint) {
|
|
142
|
+
let responseBody = null;
|
|
143
|
+
try {
|
|
144
|
+
responseBody = await response.text();
|
|
145
|
+
if (!response.ok) {
|
|
146
|
+
throw new Error(`HTTP error ${response.status}: ${response.statusText}${responseBody ? ` - ${responseBody}` : ""}`);
|
|
147
|
+
}
|
|
148
|
+
return JSON.parse(responseBody);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
logger.error(`handleJsonResponse: Error processing response for ${endpoint || "unknown endpoint"}:`, error);
|
|
152
|
+
if (error instanceof SystemError) {
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
throw PARSE_ERROR(error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Sends a JSON-RPC request and processes the response in a single operation.
|
|
162
|
+
* This combines sendJsonRpcRequest and handleJsonRpcResponse into one call.
|
|
163
|
+
*
|
|
164
|
+
* @param baseUrl The API endpoint URL
|
|
165
|
+
* @param method The JSON-RPC method name
|
|
166
|
+
* @param params The parameters for the method
|
|
167
|
+
* @param headers Custom headers to include in the request
|
|
168
|
+
* @param acceptHeader The desired Accept header ('application/json' or 'text/event-stream')
|
|
169
|
+
* @returns A Promise resolving to the result payload
|
|
170
|
+
* @throws RpcError if there's a network error or error in the response
|
|
171
|
+
*/
|
|
172
|
+
export async function executeJsonRpcRequest(baseUrl, method, params, headers = {}, acceptHeader = "application/json") {
|
|
173
|
+
const response = await sendJsonRpcRequest(baseUrl, method, params, headers, acceptHeader);
|
|
174
|
+
return handleJsonRpcResponse(response, method);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Sends a GET request and processes the JSON response.
|
|
178
|
+
* Helper for non-RPC REST endpoints.
|
|
179
|
+
*
|
|
180
|
+
* @param url The endpoint URL
|
|
181
|
+
* @param headers Custom headers to include in the request
|
|
182
|
+
* @param endpoint Optional endpoint description for logging
|
|
183
|
+
* @returns A Promise resolving to the parsed JSON
|
|
184
|
+
* @throws RpcError if there's a network error or error in the response
|
|
185
|
+
*/
|
|
186
|
+
export async function executeGetRequest(url, headers = {}, endpoint) {
|
|
187
|
+
const response = await sendGetRequest(url, headers);
|
|
188
|
+
return handleJsonResponse(response, endpoint);
|
|
189
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { A2A, MCP } from "../../types/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Creates an async generator for processing task events from an SSE stream
|
|
8
|
+
*
|
|
9
|
+
* @template T The type of task event to process (TaskStatusUpdateEvent or TaskArtifactUpdateEvent)
|
|
10
|
+
* @param response The fetch Response object containing the event stream
|
|
11
|
+
* @returns An async generator yielding the specified type of task events from StreamingResponse
|
|
12
|
+
*/
|
|
13
|
+
export declare function handleEventStream<StreamRes extends MCP.JSONRPCResultResponse>(response: Response): AsyncGenerator<NonNullable<StreamRes["result"]>>;
|
|
14
|
+
/**
|
|
15
|
+
* Executes a streaming JSON-RPC request and yields events as they arrive
|
|
16
|
+
*
|
|
17
|
+
* @template Req The type of request being made
|
|
18
|
+
* @template StreamRes The type of streaming response expected
|
|
19
|
+
* @param baseUrl The base URL for the API
|
|
20
|
+
* @param method The JSON-RPC method to call
|
|
21
|
+
* @param params The parameters for the method
|
|
22
|
+
* @param customHeaders Any custom headers to include in the request
|
|
23
|
+
* @returns An AsyncIterable yielding events from the stream
|
|
24
|
+
*/
|
|
25
|
+
export declare function executeStreamEvents<Req extends A2A.A2ARequest, StreamRes extends MCP.JSONRPCResultResponse>(baseUrl: URL, method: Req["method"], params: Req["params"], customHeaders: Record<string, string>): AsyncIterable<NonNullable<StreamRes["result"]>>;
|