@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,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Event stream utilities for handling Server-Sent Events (SSE).
|
|
7
|
+
*/
|
|
8
|
+
import { parseResponse } from "../rpc/parser.js";
|
|
9
|
+
import { createParser, } from "eventsource-parser";
|
|
10
|
+
import { sendJsonRpcRequest } from "../rpc/rpc-client.js";
|
|
11
|
+
import { logger } from "../../config/index.js";
|
|
12
|
+
/**
|
|
13
|
+
* Creates an async generator for processing task events from an SSE stream
|
|
14
|
+
*
|
|
15
|
+
* @template T The type of task event to process (TaskStatusUpdateEvent or TaskArtifactUpdateEvent)
|
|
16
|
+
* @param response The fetch Response object containing the event stream
|
|
17
|
+
* @returns An async generator yielding the specified type of task events from StreamingResponse
|
|
18
|
+
*/
|
|
19
|
+
export async function* handleEventStream(response) {
|
|
20
|
+
if (!response.ok || !response.body) {
|
|
21
|
+
let errorText = null;
|
|
22
|
+
try {
|
|
23
|
+
errorText = await response.text();
|
|
24
|
+
}
|
|
25
|
+
catch (_) { }
|
|
26
|
+
const err = new Error(`HTTP error [${response.status}:${response.statusText}] - ${errorText}`);
|
|
27
|
+
logger.error(`handleEventStream: HTTP error [${response.status}:${response.statusText}] - ${errorText}`, err);
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
30
|
+
// Use eventsource-parser to process the SSE stream
|
|
31
|
+
const reader = response.body.getReader();
|
|
32
|
+
const decoder = new TextDecoder();
|
|
33
|
+
const events = [];
|
|
34
|
+
const parser = createParser({
|
|
35
|
+
onEvent: (event) => {
|
|
36
|
+
if (event.data) {
|
|
37
|
+
if (event.event === "close") {
|
|
38
|
+
logger.debug("handleEventStream", "Stream closed");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const parsedData = parseResponse(event.data);
|
|
43
|
+
const eventResult = parsedData.result;
|
|
44
|
+
if (eventResult) {
|
|
45
|
+
events.push(eventResult);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
logger.warn("handleEventStream", "Failed to parse SSE data", parsedData);
|
|
49
|
+
}
|
|
50
|
+
// if (parsedData.final && parsedData.final === true) {
|
|
51
|
+
// logDebug("handleEventStream", "Stream completed");
|
|
52
|
+
// return;
|
|
53
|
+
// }
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
logger.warn("handleEventStream", "Failed to parse SSE data", e);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
onError: (error) => {
|
|
61
|
+
logger.error("handleEventStream: Error parsing SSE data", error);
|
|
62
|
+
},
|
|
63
|
+
onRetry: (retry) => {
|
|
64
|
+
logger.warn("handleEventStream", "Retrying SSE connection", retry);
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
try {
|
|
68
|
+
while (true) {
|
|
69
|
+
const { done, value } = await reader.read();
|
|
70
|
+
if (done)
|
|
71
|
+
break;
|
|
72
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
73
|
+
parser.feed(chunk);
|
|
74
|
+
while (events.length > 0) {
|
|
75
|
+
yield events.shift();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
reader.releaseLock();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Executes a streaming JSON-RPC request and yields events as they arrive
|
|
85
|
+
*
|
|
86
|
+
* @template Req The type of request being made
|
|
87
|
+
* @template StreamRes The type of streaming response expected
|
|
88
|
+
* @param baseUrl The base URL for the API
|
|
89
|
+
* @param method The JSON-RPC method to call
|
|
90
|
+
* @param params The parameters for the method
|
|
91
|
+
* @param customHeaders Any custom headers to include in the request
|
|
92
|
+
* @returns An AsyncIterable yielding events from the stream
|
|
93
|
+
*/
|
|
94
|
+
export async function* executeStreamEvents(baseUrl, method, params, customHeaders) {
|
|
95
|
+
logger.debug("executeStreamEvents", `Sending streaming request to: ${baseUrl.toString()}, method: ${method}`);
|
|
96
|
+
const responsePromise = sendJsonRpcRequest(baseUrl, method, params, customHeaders, "text/event-stream");
|
|
97
|
+
const response = await responsePromise;
|
|
98
|
+
logger.debug("executeStreamEvents", "Response", response);
|
|
99
|
+
yield* handleEventStream(response);
|
|
100
|
+
}
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { AgentCard, Message, Task, AgentExtension, TaskQueryParams, TaskIdParams, MessageSendParams, SendMessageSuccessResult } from "@artinet/types/a2a";
|
|
6
|
+
import { core } from "../core/index.js";
|
|
7
|
+
import { z } from "zod/v4";
|
|
8
|
+
export type AgentCardParams = (Partial<AgentCard> & Required<Pick<AgentCard, "name">>) | string;
|
|
9
|
+
export declare const UpdateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
10
|
+
role: z.ZodEnum<{
|
|
11
|
+
user: "user";
|
|
12
|
+
agent: "agent";
|
|
13
|
+
}>;
|
|
14
|
+
parts: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
15
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
16
|
+
kind: z.ZodLiteral<"text">;
|
|
17
|
+
text: z.ZodString;
|
|
18
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
19
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
20
|
+
kind: z.ZodLiteral<"file">;
|
|
21
|
+
file: z.ZodUnion<readonly [z.ZodObject<{
|
|
22
|
+
name: z.ZodOptional<z.ZodString>;
|
|
23
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
24
|
+
bytes: z.ZodString;
|
|
25
|
+
uri: z.ZodOptional<z.ZodNever>;
|
|
26
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
27
|
+
name: z.ZodOptional<z.ZodString>;
|
|
28
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
29
|
+
uri: z.ZodString;
|
|
30
|
+
bytes: z.ZodOptional<z.ZodNever>;
|
|
31
|
+
}, z.core.$strip>]>;
|
|
32
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
33
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
34
|
+
kind: z.ZodLiteral<"data">;
|
|
35
|
+
data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
36
|
+
}, z.core.$strip>]>>;
|
|
37
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
38
|
+
extensions: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
39
|
+
referenceTaskIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
40
|
+
messageId: z.ZodString;
|
|
41
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
42
|
+
contextId: z.ZodOptional<z.ZodString>;
|
|
43
|
+
kind: z.ZodLiteral<"message">;
|
|
44
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
45
|
+
id: z.ZodString;
|
|
46
|
+
contextId: z.ZodString;
|
|
47
|
+
status: z.ZodObject<{
|
|
48
|
+
state: z.ZodEnum<{
|
|
49
|
+
failed: "failed";
|
|
50
|
+
unknown: "unknown";
|
|
51
|
+
completed: "completed";
|
|
52
|
+
canceled: "canceled";
|
|
53
|
+
rejected: "rejected";
|
|
54
|
+
working: "working";
|
|
55
|
+
submitted: "submitted";
|
|
56
|
+
"input-required": "input-required";
|
|
57
|
+
"auth-required": "auth-required";
|
|
58
|
+
}>;
|
|
59
|
+
message: z.ZodOptional<z.ZodObject<{
|
|
60
|
+
role: z.ZodEnum<{
|
|
61
|
+
user: "user";
|
|
62
|
+
agent: "agent";
|
|
63
|
+
}>;
|
|
64
|
+
parts: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
65
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
66
|
+
kind: z.ZodLiteral<"text">;
|
|
67
|
+
text: z.ZodString;
|
|
68
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
69
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
70
|
+
kind: z.ZodLiteral<"file">;
|
|
71
|
+
file: z.ZodUnion<readonly [z.ZodObject<{
|
|
72
|
+
name: z.ZodOptional<z.ZodString>;
|
|
73
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
74
|
+
bytes: z.ZodString;
|
|
75
|
+
uri: z.ZodOptional<z.ZodNever>;
|
|
76
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
77
|
+
name: z.ZodOptional<z.ZodString>;
|
|
78
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
79
|
+
uri: z.ZodString;
|
|
80
|
+
bytes: z.ZodOptional<z.ZodNever>;
|
|
81
|
+
}, z.core.$strip>]>;
|
|
82
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
83
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
84
|
+
kind: z.ZodLiteral<"data">;
|
|
85
|
+
data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
86
|
+
}, z.core.$strip>]>>;
|
|
87
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
88
|
+
extensions: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
89
|
+
referenceTaskIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
90
|
+
messageId: z.ZodString;
|
|
91
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
92
|
+
contextId: z.ZodOptional<z.ZodString>;
|
|
93
|
+
kind: z.ZodLiteral<"message">;
|
|
94
|
+
}, z.core.$strip>>;
|
|
95
|
+
timestamp: z.ZodOptional<z.ZodISODateTime>;
|
|
96
|
+
}, z.core.$strip>;
|
|
97
|
+
history: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
98
|
+
role: z.ZodEnum<{
|
|
99
|
+
user: "user";
|
|
100
|
+
agent: "agent";
|
|
101
|
+
}>;
|
|
102
|
+
parts: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
103
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
104
|
+
kind: z.ZodLiteral<"text">;
|
|
105
|
+
text: z.ZodString;
|
|
106
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
107
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
108
|
+
kind: z.ZodLiteral<"file">;
|
|
109
|
+
file: z.ZodUnion<readonly [z.ZodObject<{
|
|
110
|
+
name: z.ZodOptional<z.ZodString>;
|
|
111
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
112
|
+
bytes: z.ZodString;
|
|
113
|
+
uri: z.ZodOptional<z.ZodNever>;
|
|
114
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
115
|
+
name: z.ZodOptional<z.ZodString>;
|
|
116
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
117
|
+
uri: z.ZodString;
|
|
118
|
+
bytes: z.ZodOptional<z.ZodNever>;
|
|
119
|
+
}, z.core.$strip>]>;
|
|
120
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
121
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
122
|
+
kind: z.ZodLiteral<"data">;
|
|
123
|
+
data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
124
|
+
}, z.core.$strip>]>>;
|
|
125
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
126
|
+
extensions: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
127
|
+
referenceTaskIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
128
|
+
messageId: z.ZodString;
|
|
129
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
130
|
+
contextId: z.ZodOptional<z.ZodString>;
|
|
131
|
+
kind: z.ZodLiteral<"message">;
|
|
132
|
+
}, z.core.$strip>>>;
|
|
133
|
+
artifacts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
134
|
+
artifactId: z.ZodString;
|
|
135
|
+
name: z.ZodOptional<z.ZodString>;
|
|
136
|
+
description: z.ZodOptional<z.ZodString>;
|
|
137
|
+
parts: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
138
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
139
|
+
kind: z.ZodLiteral<"text">;
|
|
140
|
+
text: z.ZodString;
|
|
141
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
142
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
143
|
+
kind: z.ZodLiteral<"file">;
|
|
144
|
+
file: z.ZodUnion<readonly [z.ZodObject<{
|
|
145
|
+
name: z.ZodOptional<z.ZodString>;
|
|
146
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
147
|
+
bytes: z.ZodString;
|
|
148
|
+
uri: z.ZodOptional<z.ZodNever>;
|
|
149
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
150
|
+
name: z.ZodOptional<z.ZodString>;
|
|
151
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
152
|
+
uri: z.ZodString;
|
|
153
|
+
bytes: z.ZodOptional<z.ZodNever>;
|
|
154
|
+
}, z.core.$strip>]>;
|
|
155
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
156
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
157
|
+
kind: z.ZodLiteral<"data">;
|
|
158
|
+
data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
159
|
+
}, z.core.$strip>]>>;
|
|
160
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
161
|
+
extension: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
162
|
+
}, z.core.$strip>>>;
|
|
163
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
164
|
+
kind: z.ZodLiteral<"task">;
|
|
165
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
166
|
+
taskId: z.ZodString;
|
|
167
|
+
contextId: z.ZodString;
|
|
168
|
+
kind: z.ZodLiteral<"status-update">;
|
|
169
|
+
status: z.ZodObject<{
|
|
170
|
+
state: z.ZodEnum<{
|
|
171
|
+
failed: "failed";
|
|
172
|
+
unknown: "unknown";
|
|
173
|
+
completed: "completed";
|
|
174
|
+
canceled: "canceled";
|
|
175
|
+
rejected: "rejected";
|
|
176
|
+
working: "working";
|
|
177
|
+
submitted: "submitted";
|
|
178
|
+
"input-required": "input-required";
|
|
179
|
+
"auth-required": "auth-required";
|
|
180
|
+
}>;
|
|
181
|
+
message: z.ZodOptional<z.ZodObject<{
|
|
182
|
+
role: z.ZodEnum<{
|
|
183
|
+
user: "user";
|
|
184
|
+
agent: "agent";
|
|
185
|
+
}>;
|
|
186
|
+
parts: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
187
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
188
|
+
kind: z.ZodLiteral<"text">;
|
|
189
|
+
text: z.ZodString;
|
|
190
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
191
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
192
|
+
kind: z.ZodLiteral<"file">;
|
|
193
|
+
file: z.ZodUnion<readonly [z.ZodObject<{
|
|
194
|
+
name: z.ZodOptional<z.ZodString>;
|
|
195
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
196
|
+
bytes: z.ZodString;
|
|
197
|
+
uri: z.ZodOptional<z.ZodNever>;
|
|
198
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
199
|
+
name: z.ZodOptional<z.ZodString>;
|
|
200
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
201
|
+
uri: z.ZodString;
|
|
202
|
+
bytes: z.ZodOptional<z.ZodNever>;
|
|
203
|
+
}, z.core.$strip>]>;
|
|
204
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
205
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
206
|
+
kind: z.ZodLiteral<"data">;
|
|
207
|
+
data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
208
|
+
}, z.core.$strip>]>>;
|
|
209
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
210
|
+
extensions: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
211
|
+
referenceTaskIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
212
|
+
messageId: z.ZodString;
|
|
213
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
214
|
+
contextId: z.ZodOptional<z.ZodString>;
|
|
215
|
+
kind: z.ZodLiteral<"message">;
|
|
216
|
+
}, z.core.$strip>>;
|
|
217
|
+
timestamp: z.ZodOptional<z.ZodISODateTime>;
|
|
218
|
+
}, z.core.$strip>;
|
|
219
|
+
final: z.ZodBoolean;
|
|
220
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
221
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
222
|
+
taskId: z.ZodString;
|
|
223
|
+
contextId: z.ZodString;
|
|
224
|
+
kind: z.ZodLiteral<"artifact-update">;
|
|
225
|
+
artifact: z.ZodObject<{
|
|
226
|
+
artifactId: z.ZodString;
|
|
227
|
+
name: z.ZodOptional<z.ZodString>;
|
|
228
|
+
description: z.ZodOptional<z.ZodString>;
|
|
229
|
+
parts: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
230
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
231
|
+
kind: z.ZodLiteral<"text">;
|
|
232
|
+
text: z.ZodString;
|
|
233
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
234
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
235
|
+
kind: z.ZodLiteral<"file">;
|
|
236
|
+
file: z.ZodUnion<readonly [z.ZodObject<{
|
|
237
|
+
name: z.ZodOptional<z.ZodString>;
|
|
238
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
239
|
+
bytes: z.ZodString;
|
|
240
|
+
uri: z.ZodOptional<z.ZodNever>;
|
|
241
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
242
|
+
name: z.ZodOptional<z.ZodString>;
|
|
243
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
244
|
+
uri: z.ZodString;
|
|
245
|
+
bytes: z.ZodOptional<z.ZodNever>;
|
|
246
|
+
}, z.core.$strip>]>;
|
|
247
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
248
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
249
|
+
kind: z.ZodLiteral<"data">;
|
|
250
|
+
data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
251
|
+
}, z.core.$strip>]>>;
|
|
252
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
253
|
+
extension: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
254
|
+
}, z.core.$strip>;
|
|
255
|
+
append: z.ZodOptional<z.ZodBoolean>;
|
|
256
|
+
lastChunk: z.ZodOptional<z.ZodBoolean>;
|
|
257
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
258
|
+
}, z.core.$strip>]>;
|
|
259
|
+
export type Update = z.infer<typeof UpdateSchema>;
|
|
260
|
+
export type Engine = (context: Context) => AsyncGenerator<Update, void, unknown>;
|
|
261
|
+
export interface BaseContext extends core.Context<Task> {
|
|
262
|
+
readonly service: Service;
|
|
263
|
+
readonly publisher: EventPublisher;
|
|
264
|
+
}
|
|
265
|
+
export interface Context extends BaseContext {
|
|
266
|
+
readonly taskId: string;
|
|
267
|
+
readonly userMessage: Message;
|
|
268
|
+
readonly messages: MessageConsumerProxy;
|
|
269
|
+
extensions?: AgentExtension[];
|
|
270
|
+
references?: Task[];
|
|
271
|
+
getTask: () => Promise<Task>;
|
|
272
|
+
}
|
|
273
|
+
export type ContextParams = Omit<BaseContext, "publisher" | "isCancelled" | "getState" | "abortSignal"> & Omit<Partial<Context>, "userMessage"> & {
|
|
274
|
+
messenger: MessageConsumerProxy;
|
|
275
|
+
task?: Task;
|
|
276
|
+
overrides?: Partial<Omit<EventConsumer, "contextId">>;
|
|
277
|
+
abortSignal?: AbortSignal;
|
|
278
|
+
};
|
|
279
|
+
export interface Contexts extends core.Contexts<Context> {
|
|
280
|
+
create: (params: ContextParams) => Promise<Context>;
|
|
281
|
+
list: () => Promise<Context[]>;
|
|
282
|
+
}
|
|
283
|
+
export interface Tasks extends core.Manager<Task> {
|
|
284
|
+
update: (context: Context, update: Update) => Promise<Task>;
|
|
285
|
+
create: (params: Partial<Task>) => Promise<Task>;
|
|
286
|
+
has: (id: string) => Promise<boolean>;
|
|
287
|
+
}
|
|
288
|
+
export interface Cancellations extends Omit<core.Manager<void>, "get"> {
|
|
289
|
+
has: (id: string) => Promise<boolean>;
|
|
290
|
+
}
|
|
291
|
+
export interface Connections extends Omit<core.Manager<void>, "get"> {
|
|
292
|
+
}
|
|
293
|
+
export interface ServiceOptions {
|
|
294
|
+
abortSignal?: AbortSignal;
|
|
295
|
+
}
|
|
296
|
+
export interface RequestHandler {
|
|
297
|
+
getTask: (input: TaskQueryParams, context?: Context, options?: ServiceOptions) => Promise<Task>;
|
|
298
|
+
cancelTask: (input: TaskIdParams, context?: Context, options?: ServiceOptions) => Promise<Task>;
|
|
299
|
+
sendMessage: (message: MessageSendParams, context?: Context, options?: ServiceOptions) => Promise<SendMessageSuccessResult>;
|
|
300
|
+
streamMessage: (message: MessageSendParams, context?: Context, options?: ServiceOptions) => AsyncGenerator<Update>;
|
|
301
|
+
resubscribe: (input: TaskIdParams, context?: Context, options?: ServiceOptions) => AsyncGenerator<Update>;
|
|
302
|
+
getAgentCard: () => Promise<AgentCard>;
|
|
303
|
+
}
|
|
304
|
+
export interface ExtendedHandler extends RequestHandler {
|
|
305
|
+
getAuthenticatedExtendedCard: () => Promise<AgentCard>;
|
|
306
|
+
}
|
|
307
|
+
export interface Stream {
|
|
308
|
+
readonly contextId: string;
|
|
309
|
+
isAlive: boolean;
|
|
310
|
+
kill: () => Promise<void>;
|
|
311
|
+
updates: Update[];
|
|
312
|
+
context: Context;
|
|
313
|
+
run: (params: {
|
|
314
|
+
service: Service;
|
|
315
|
+
}) => AsyncGenerator<Update>;
|
|
316
|
+
subscribe: () => AsyncGenerator<Update>;
|
|
317
|
+
}
|
|
318
|
+
export interface Streams extends Omit<core.Manager<Stream>, "set"> {
|
|
319
|
+
create: (params: core.Optional<Stream> & {
|
|
320
|
+
context: Context;
|
|
321
|
+
}) => Promise<Stream>;
|
|
322
|
+
has: (id: string) => Promise<boolean>;
|
|
323
|
+
}
|
|
324
|
+
export interface Service extends core.Service<{
|
|
325
|
+
engine: Engine;
|
|
326
|
+
context: Context;
|
|
327
|
+
}>, RequestHandler {
|
|
328
|
+
readonly events?: Events;
|
|
329
|
+
readonly connections: Connections;
|
|
330
|
+
readonly cancellations: Cancellations;
|
|
331
|
+
readonly tasks: Tasks;
|
|
332
|
+
readonly contexts: Contexts;
|
|
333
|
+
readonly streams: Streams;
|
|
334
|
+
engine: Engine;
|
|
335
|
+
agentCard: AgentCard;
|
|
336
|
+
}
|
|
337
|
+
export interface MessageProducer {
|
|
338
|
+
isOpen: boolean;
|
|
339
|
+
send: (message: MessageSendParams) => Promise<void>;
|
|
340
|
+
}
|
|
341
|
+
export type MessageMap = {
|
|
342
|
+
message: [MessageSendParams];
|
|
343
|
+
close: [];
|
|
344
|
+
};
|
|
345
|
+
export interface MessageConsumer extends core.Consumer<MessageSendParams, MessageMap> {
|
|
346
|
+
message: MessageSendParams;
|
|
347
|
+
messages: MessageSendParams[];
|
|
348
|
+
close: () => Promise<void>;
|
|
349
|
+
next: () => Promise<IteratorResult<MessageSendParams>>;
|
|
350
|
+
return: (value: MessageSendParams) => Promise<IteratorResult<MessageSendParams>>;
|
|
351
|
+
}
|
|
352
|
+
export type MessageConsumerProxy = MessageConsumer & MessageSendParams;
|
|
353
|
+
export interface EventConsumer {
|
|
354
|
+
readonly contextId: string;
|
|
355
|
+
readonly onStart?: (context: Context) => Promise<Task>;
|
|
356
|
+
readonly onCancel: (update: Update, current: Task) => Promise<void>;
|
|
357
|
+
readonly onUpdate: (update: Update, current: Task) => Promise<Task>;
|
|
358
|
+
readonly onError: (error: any, current: Task) => Promise<void>;
|
|
359
|
+
onComplete: (current: Task) => Promise<void>;
|
|
360
|
+
}
|
|
361
|
+
export type Emissions = {
|
|
362
|
+
start: [MessageSendParams, Task];
|
|
363
|
+
cancel: [Update];
|
|
364
|
+
update: [Task, Update];
|
|
365
|
+
error: [any, Task];
|
|
366
|
+
complete: [Task];
|
|
367
|
+
};
|
|
368
|
+
export interface EventPublisher extends Omit<EventConsumer, "onComplete" | "onCancel" | "onError" | "onUpdate">, core.Publisher<Emissions> {
|
|
369
|
+
readonly onStart?: (context: Context) => Promise<Task>;
|
|
370
|
+
readonly onCancel: (update: Update) => Promise<void>;
|
|
371
|
+
readonly onUpdate: (update: Update) => Promise<Task>;
|
|
372
|
+
readonly onError: (error: any) => Promise<void>;
|
|
373
|
+
onComplete: () => Promise<void>;
|
|
374
|
+
}
|
|
375
|
+
export interface Events extends core.Manager<EventPublisher> {
|
|
376
|
+
create: (params: core.Optional<EventPublisher>) => Promise<EventPublisher>;
|
|
377
|
+
}
|
|
378
|
+
export * from "@artinet/types/a2a";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
//lets stay really granular with the imports
|
|
6
|
+
import { TaskArtifactUpdateEventSchema, MessageSchema, TaskSchema, TaskStatusUpdateEventSchema, } from "@artinet/types/a2a";
|
|
7
|
+
import { z } from "zod/v4";
|
|
8
|
+
export const UpdateSchema = z.discriminatedUnion("kind", [
|
|
9
|
+
MessageSchema,
|
|
10
|
+
TaskSchema,
|
|
11
|
+
TaskStatusUpdateEventSchema,
|
|
12
|
+
TaskArtifactUpdateEventSchema,
|
|
13
|
+
]);
|
|
14
|
+
export * from "@artinet/types/a2a";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { MessageSendParams, DataPart, FilePart, TextPart } from "@artinet/types/a2a";
|
|
6
|
+
import { Context } from "./a2a.js";
|
|
7
|
+
/**
|
|
8
|
+
* Restricting to command for now, but could be extended to other types of commands in the future.
|
|
9
|
+
* When we shift to CoreCommand, move this into core.
|
|
10
|
+
*/
|
|
11
|
+
export interface StepArgs {
|
|
12
|
+
message: MessageSendParams;
|
|
13
|
+
context: Context;
|
|
14
|
+
skip: () => Promise<void> | void;
|
|
15
|
+
}
|
|
16
|
+
export type BaseArgs = Record<string, unknown>;
|
|
17
|
+
export type EmptyArgs = Record<string, never>;
|
|
18
|
+
export type StepParams<TInboundArgs extends BaseArgs = EmptyArgs> = StepArgs & Partial<{
|
|
19
|
+
content: string;
|
|
20
|
+
args: TInboundArgs;
|
|
21
|
+
}>;
|
|
22
|
+
export type PartContent = DataPart["data"] | FilePart["file"] | TextPart["text"];
|
|
23
|
+
export type StepOutput<TPart extends PartContent> = {
|
|
24
|
+
parts: Array<TPart> | TPart;
|
|
25
|
+
};
|
|
26
|
+
export type StepOutputWithForwardArgs<TPart extends PartContent, TForwardArgs extends BaseArgs = EmptyArgs> = StepOutput<TPart> & {
|
|
27
|
+
args: TForwardArgs;
|
|
28
|
+
};
|
|
29
|
+
export type OutputType<TPart extends PartContent, TForwardArgs extends BaseArgs = EmptyArgs> = StepOutput<TPart> | StepOutputWithForwardArgs<TPart, TForwardArgs> | Array<TPart> | TPart;
|
|
30
|
+
export type Step<TPart extends PartContent = TextPart["text"], TInboundArgs extends BaseArgs = EmptyArgs, TForwardArgs extends BaseArgs = EmptyArgs, TOutput extends OutputType<TPart, TForwardArgs> = OutputType<TPart, TForwardArgs>> = (params: StepParams<TInboundArgs>) => Promise<TOutput> | TOutput;
|
|
31
|
+
export type StepWithKind<TPart extends PartContent = TextPart["text"], TInboundArgs extends BaseArgs = EmptyArgs, TForwardArgs extends BaseArgs = EmptyArgs, TOutput extends OutputType<TPart, TForwardArgs> = OutputType<TPart, TForwardArgs>, TKind extends "text" | "file" | "data" = "text"> = {
|
|
32
|
+
step: Step<TPart, TInboundArgs, TForwardArgs, TOutput>;
|
|
33
|
+
kind: TKind;
|
|
34
|
+
};
|
|
35
|
+
export type OutArgsOf<O> = O extends StepOutputWithForwardArgs<any, infer A> ? A : EmptyArgs;
|
|
36
|
+
export interface StepBuilder<TInboundArgs extends BaseArgs = EmptyArgs> {
|
|
37
|
+
/**
|
|
38
|
+
* Add a step to the builder.
|
|
39
|
+
* @param step - The step to add.
|
|
40
|
+
* @returns A new builder with the step added.
|
|
41
|
+
*/
|
|
42
|
+
addStep<TPart extends PartContent = TextPart["text"], TForwardArgs extends BaseArgs = EmptyArgs, TOutput extends OutputType<TPart, TForwardArgs> = OutputType<TPart, TForwardArgs>, TKind extends "text" | "file" | "data" = "text">(step: StepWithKind<TPart, TInboundArgs, TForwardArgs, TOutput, TKind>): StepBuilder<OutArgsOf<TOutput>>;
|
|
43
|
+
}
|
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
* Copyright 2025 The Artinet Project
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
import type { AgentCard, TaskQueryParams, MessageSendParams, Message } from "../schemas/a2a/index.js";
|
|
7
|
-
import { UpdateEvent } from "./services/a2a/index.js";
|
|
5
|
+
import { A2A } from "./a2a/index.js";
|
|
8
6
|
/**
|
|
9
7
|
* @interface Client
|
|
10
8
|
* @description Defines the standard contract for an A2A (Agent-to-Agent) client implementation.
|
|
@@ -19,24 +17,24 @@ export interface Client {
|
|
|
19
17
|
* The AgentCard contains essential information about the agent, such as its capabilities and endpoints.
|
|
20
18
|
* @param {string} wellKnownPath The standard path (e.g., "/.well-known/a2a") to look for the AgentCard.
|
|
21
19
|
* @param {string} fallbackPath An alternative path to check if the well-known path fails.
|
|
22
|
-
* @returns {Promise<AgentCard>} A promise that resolves with the AgentCard object.
|
|
20
|
+
* @returns {Promise<A2A.AgentCard>} A promise that resolves with the AgentCard object.
|
|
23
21
|
* @async
|
|
24
22
|
*/
|
|
25
|
-
agentCard(): Promise<AgentCard>;
|
|
23
|
+
agentCard(): Promise<A2A.AgentCard>;
|
|
26
24
|
/**
|
|
27
25
|
* @description Refreshes the cached AgentCard information by re-fetching it from the server.
|
|
28
26
|
* Useful when the agent's capabilities or configuration might have changed.
|
|
29
|
-
* @returns {Promise<AgentCard>} A promise that resolves with the updated AgentCard object.
|
|
27
|
+
* @returns {Promise<A2A.AgentCard>} A promise that resolves with the updated AgentCard object.
|
|
30
28
|
* @async
|
|
31
29
|
*/
|
|
32
|
-
refreshAgentCard(): Promise<AgentCard>;
|
|
30
|
+
refreshAgentCard(): Promise<A2A.AgentCard>;
|
|
33
31
|
/**
|
|
34
32
|
* @description Sends a task request to the agent server.
|
|
35
|
-
* @param {MessageSendParams} params Parameters required to send the task, including the task definition and metadata.
|
|
36
|
-
* @returns {Promise<Task | null>} A promise that resolves with the initial Task object representing the submitted task, or null if the submission failed.
|
|
33
|
+
* @param {A2A.MessageSendParams} params Parameters required to send the task, including the task definition and metadata.
|
|
34
|
+
* @returns {Promise<A2A.Task | null>} A promise that resolves with the initial Task object representing the submitted task, or null if the submission failed.
|
|
37
35
|
* @async
|
|
38
36
|
*/
|
|
39
|
-
sendMessage(params: MessageSendParams): Promise<Message | Task | null>;
|
|
37
|
+
sendMessage(params: A2A.MessageSendParams): Promise<A2A.Message | A2A.Task | null>;
|
|
40
38
|
/**
|
|
41
39
|
* @deprecated Will be removed in v6.Use sendMessage instead.
|
|
42
40
|
* @description Sends a task request to the agent server.
|
|
@@ -44,7 +42,7 @@ export interface Client {
|
|
|
44
42
|
* @returns {Promise<Task | null>} A promise that resolves with the initial Task object representing the submitted task, or null if the submission failed.
|
|
45
43
|
* @async
|
|
46
44
|
*/
|
|
47
|
-
sendTask(params: MessageSendParams): Promise<Message | Task | null>;
|
|
45
|
+
sendTask(params: A2A.MessageSendParams): Promise<A2A.Message | A2A.Task | null>;
|
|
48
46
|
/**
|
|
49
47
|
* @description Sends a task request and subscribes to real-time updates (status changes, artifact updates) for that task.
|
|
50
48
|
* This uses a streaming connection if available.
|
|
@@ -52,7 +50,7 @@ export interface Client {
|
|
|
52
50
|
* @returns {AsyncIterable<UpdateEvent>} An async iterable that yields task status and artifact updates.
|
|
53
51
|
* @async
|
|
54
52
|
*/
|
|
55
|
-
sendStreamingMessage(params: MessageSendParams): AsyncIterable<
|
|
53
|
+
sendStreamingMessage(params: A2A.MessageSendParams): AsyncIterable<A2A.Update>;
|
|
56
54
|
/**
|
|
57
55
|
* @deprecated Will be removed in v6Use sendStreamingMessage instead.
|
|
58
56
|
* @description Sends a task request and subscribes to real-time updates (status changes, artifact updates) for that task.
|
|
@@ -61,45 +59,45 @@ export interface Client {
|
|
|
61
59
|
* @returns {AsyncIterable<UpdateEvent>} An async iterable that yields task status and artifact updates.
|
|
62
60
|
* @async
|
|
63
61
|
*/
|
|
64
|
-
sendTaskSubscribe(params: MessageSendParams): AsyncIterable<
|
|
62
|
+
sendTaskSubscribe(params: A2A.MessageSendParams): AsyncIterable<A2A.Update>;
|
|
65
63
|
/**
|
|
66
64
|
* @description Retrieves the current state of a specific task by its ID.
|
|
67
|
-
* @param {TaskQueryParams} params Parameters containing the task ID to query.
|
|
68
|
-
* @returns {Promise<Task | null>} A promise that resolves with the Task object, or null if the task is not found.
|
|
65
|
+
* @param {A2A.TaskQueryParams} params Parameters containing the task ID to query.
|
|
66
|
+
* @returns {Promise<A2A.Task | null>} A promise that resolves with the Task object, or null if the task is not found.
|
|
69
67
|
* @async
|
|
70
68
|
*/
|
|
71
|
-
getTask(params: TaskQueryParams): Promise<Task | null>;
|
|
69
|
+
getTask(params: A2A.TaskQueryParams): Promise<A2A.Task | null>;
|
|
72
70
|
/**
|
|
73
71
|
* @description Sends a request to cancel an ongoing task.
|
|
74
|
-
* @param {TaskIdParams} params Parameters containing the ID of the task to cancel.
|
|
75
|
-
* @returns {Promise<Task | null>} A promise that resolves with the final state of the cancelled Task object, or null if cancellation failed or the task wasn't found.
|
|
72
|
+
* @param {A2A.TaskIdParams} params Parameters containing the ID of the task to cancel.
|
|
73
|
+
* @returns {Promise<A2A.Task | null>} A promise that resolves with the final state of the cancelled Task object, or null if cancellation failed or the task wasn't found.
|
|
76
74
|
* @async
|
|
77
75
|
*/
|
|
78
|
-
cancelTask(params: TaskIdParams): Promise<Task | null>;
|
|
76
|
+
cancelTask(params: A2A.TaskIdParams): Promise<A2A.Task | null>;
|
|
79
77
|
/**
|
|
80
78
|
* @description Configures push notifications for a specific task. This allows the client
|
|
81
79
|
* to receive updates asynchronously via a specified webhook URL.
|
|
82
80
|
* Requires the agent to support the 'pushNotifications' capability.
|
|
83
|
-
* @param {TaskPushNotificationConfig} params The configuration details for the push notification, including the task ID and webhook URL.
|
|
84
|
-
* @returns {Promise<TaskPushNotificationConfig | null>} A promise that resolves with the applied configuration, or null if the configuration failed.
|
|
81
|
+
* @param {A2A.TaskPushNotificationConfig} params The configuration details for the push notification, including the task ID and webhook URL.
|
|
82
|
+
* @returns {Promise<A2A.TaskPushNotificationConfig | null>} A promise that resolves with the applied configuration, or null if the configuration failed.
|
|
85
83
|
* @async
|
|
86
84
|
*/
|
|
87
|
-
setTaskPushNotification(params: TaskPushNotificationConfig): Promise<TaskPushNotificationConfig | null>;
|
|
85
|
+
setTaskPushNotification(params: A2A.TaskPushNotificationConfig): Promise<A2A.TaskPushNotificationConfig | null>;
|
|
88
86
|
/**
|
|
89
87
|
* @description Retrieves the current push notification configuration for a specific task.
|
|
90
|
-
* @param {TaskIdParams} params Parameters containing the task ID.
|
|
91
|
-
* @returns {Promise<TaskPushNotificationConfig | null>} A promise that resolves with the push notification configuration, or null if not configured or not found.
|
|
88
|
+
* @param {A2A.TaskIdParams} params Parameters containing the task ID.
|
|
89
|
+
* @returns {Promise<A2A.TaskPushNotificationConfig | null>} A promise that resolves with the push notification configuration, or null if not configured or not found.
|
|
92
90
|
* @async
|
|
93
91
|
*/
|
|
94
|
-
getTaskPushNotification(params: TaskIdParams): Promise<TaskPushNotificationConfig | null>;
|
|
92
|
+
getTaskPushNotification(params: A2A.TaskIdParams): Promise<A2A.TaskPushNotificationConfig | null>;
|
|
95
93
|
/**
|
|
96
94
|
* @description Resubscribes to updates for an existing task, potentially after a connection drop or client restart.
|
|
97
95
|
* This allows resuming the stream of status and artifact updates.
|
|
98
|
-
* @param {TaskQueryParams} params Parameters containing the task ID to resubscribe to.
|
|
96
|
+
* @param {A2A.TaskQueryParams} params Parameters containing the task ID to resubscribe to.
|
|
99
97
|
* @returns {AsyncIterable<UpdateEvent>} An async iterable that yields task status and artifact updates.
|
|
100
98
|
* @async
|
|
101
99
|
*/
|
|
102
|
-
resubscribeTask(params: TaskQueryParams): AsyncIterable<
|
|
100
|
+
resubscribeTask(params: A2A.TaskQueryParams): AsyncIterable<A2A.Update>;
|
|
103
101
|
/**
|
|
104
102
|
* @description Checks if the agent server supports a specific capability.
|
|
105
103
|
* @param {"streaming" | "pushNotifications" | "stateTransitionHistory"} capability The capability to check for.
|