@artinet/sdk 0.5.16 → 0.5.18
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 +108 -58
- package/dist/browser/browser.d.ts +9 -0
- package/dist/browser/browser.js +10 -0
- package/dist/browser/client/a2a-client.d.ts +126 -0
- package/dist/browser/client/a2a-client.js +221 -0
- package/dist/browser/client/index.d.ts +1 -0
- package/dist/browser/client/index.js +1 -0
- package/dist/browser/services/a2a/helpers/message-builder.d.ts +12 -0
- package/dist/browser/services/a2a/helpers/message-builder.js +61 -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 +99 -0
- package/dist/browser/types/ext.d.ts +13 -0
- package/dist/browser/types/ext.js +10 -0
- package/dist/browser/types/index.d.ts +4 -0
- package/dist/browser/types/index.js +4 -0
- package/dist/browser/types/interfaces/client.d.ts +135 -0
- package/dist/browser/types/interfaces/client.js +5 -0
- package/dist/browser/types/interfaces/index.d.ts +3 -0
- package/dist/browser/types/interfaces/index.js +3 -0
- package/dist/browser/types/interfaces/services/a2a/builder.d.ts +37 -0
- package/dist/browser/types/interfaces/services/a2a/builder.js +5 -0
- package/dist/browser/types/interfaces/services/a2a/context.d.ts +162 -0
- package/dist/browser/types/interfaces/services/a2a/context.js +5 -0
- package/dist/browser/types/interfaces/services/a2a/engine.d.ts +7 -0
- package/dist/browser/types/interfaces/services/a2a/engine.js +5 -0
- package/dist/browser/types/interfaces/services/a2a/index.d.ts +5 -0
- package/dist/browser/types/interfaces/services/a2a/index.js +5 -0
- package/dist/browser/types/interfaces/services/a2a/legacy.d.ts +93 -0
- package/dist/browser/types/interfaces/services/a2a/legacy.js +5 -0
- package/dist/browser/types/interfaces/services/a2a/service.d.ts +413 -0
- package/dist/browser/types/interfaces/services/a2a/service.js +5 -0
- package/dist/browser/types/interfaces/services/core/context/command.d.ts +25 -0
- package/dist/browser/types/interfaces/services/core/context/command.js +5 -0
- package/dist/browser/types/interfaces/services/core/context/context.d.ts +207 -0
- package/dist/browser/types/interfaces/services/core/context/context.js +5 -0
- package/dist/browser/types/interfaces/services/core/context/index.d.ts +3 -0
- package/dist/browser/types/interfaces/services/core/context/index.js +3 -0
- package/dist/browser/types/interfaces/services/core/context/types.d.ts +11 -0
- package/dist/browser/types/interfaces/services/core/context/types.js +5 -0
- package/dist/browser/types/interfaces/services/core/execution/engine.d.ts +106 -0
- package/dist/browser/types/interfaces/services/core/execution/engine.js +5 -0
- package/dist/browser/types/interfaces/services/core/execution/environment.d.ts +11 -0
- package/dist/browser/types/interfaces/services/core/execution/environment.js +5 -0
- package/dist/browser/types/interfaces/services/core/execution/execute.d.ts +7 -0
- package/dist/browser/types/interfaces/services/core/execution/execute.js +5 -0
- package/dist/browser/types/interfaces/services/core/execution/index.d.ts +3 -0
- package/dist/browser/types/interfaces/services/core/execution/index.js +3 -0
- package/dist/browser/types/interfaces/services/core/index.d.ts +4 -0
- package/dist/browser/types/interfaces/services/core/index.js +4 -0
- package/dist/browser/types/interfaces/services/core/managers/cancellation.d.ts +9 -0
- package/dist/browser/types/interfaces/services/core/managers/cancellation.js +5 -0
- package/dist/browser/types/interfaces/services/core/managers/connection.d.ts +9 -0
- package/dist/browser/types/interfaces/services/core/managers/connection.js +5 -0
- package/dist/browser/types/interfaces/services/core/managers/context.d.ts +17 -0
- package/dist/browser/types/interfaces/services/core/managers/context.js +5 -0
- package/dist/browser/types/interfaces/services/core/managers/event.d.ts +328 -0
- package/dist/browser/types/interfaces/services/core/managers/event.js +5 -0
- package/dist/browser/types/interfaces/services/core/managers/index.d.ts +6 -0
- package/dist/browser/types/interfaces/services/core/managers/index.js +6 -0
- package/dist/browser/types/interfaces/services/core/managers/stream.d.ts +217 -0
- package/dist/browser/types/interfaces/services/core/managers/stream.js +5 -0
- package/dist/browser/types/interfaces/services/core/managers/task.d.ts +9 -0
- package/dist/browser/types/interfaces/services/core/managers/task.js +1 -0
- package/dist/browser/types/interfaces/services/core/service.d.ts +115 -0
- package/dist/browser/types/interfaces/services/core/service.js +5 -0
- package/dist/browser/types/interfaces/services/index.d.ts +4 -0
- package/dist/browser/types/interfaces/services/index.js +4 -0
- package/dist/browser/types/interfaces/services/mcp/index.d.ts +1 -0
- package/dist/browser/types/interfaces/services/mcp/index.js +1 -0
- package/dist/browser/types/interfaces/services/mcp/service.d.ts +49 -0
- package/dist/browser/types/interfaces/services/mcp/service.js +5 -0
- package/dist/browser/types/interfaces/services/protocol.d.ts +33 -0
- package/dist/browser/types/interfaces/services/protocol.js +34 -0
- package/dist/browser/types/interfaces/storage.d.ts +8 -0
- package/dist/browser/types/interfaces/storage.js +5 -0
- package/dist/browser/types/schemas/a2a/agent.d.ts +2583 -0
- package/dist/browser/types/schemas/a2a/agent.js +323 -0
- package/dist/browser/types/schemas/a2a/auth.d.ts +908 -0
- package/dist/browser/types/schemas/a2a/auth.js +283 -0
- package/dist/browser/types/schemas/a2a/error.d.ts +396 -0
- package/dist/browser/types/schemas/a2a/error.js +163 -0
- package/dist/browser/types/schemas/a2a/index.d.ts +11 -0
- package/dist/browser/types/schemas/a2a/index.js +11 -0
- package/dist/browser/types/schemas/a2a/kind.d.ts +11 -0
- package/dist/browser/types/schemas/a2a/kind.js +20 -0
- package/dist/browser/types/schemas/a2a/message.d.ts +10343 -0
- package/dist/browser/types/schemas/a2a/message.js +130 -0
- package/dist/browser/types/schemas/a2a/notification.d.ts +1517 -0
- package/dist/browser/types/schemas/a2a/notification.js +203 -0
- package/dist/browser/types/schemas/a2a/parameters.d.ts +956 -0
- package/dist/browser/types/schemas/a2a/parameters.js +241 -0
- package/dist/browser/types/schemas/a2a/protocol.d.ts +14363 -0
- package/dist/browser/types/schemas/a2a/protocol.js +59 -0
- package/dist/browser/types/schemas/a2a/rpc.d.ts +182 -0
- package/dist/browser/types/schemas/a2a/rpc.js +126 -0
- package/dist/browser/types/schemas/a2a/task.d.ts +5886 -0
- package/dist/browser/types/schemas/a2a/task.js +134 -0
- package/dist/browser/types/schemas/a2a/transport.d.ts +31 -0
- package/dist/browser/types/schemas/a2a/transport.js +28 -0
- package/dist/browser/types/schemas/index.d.ts +1 -0
- package/dist/browser/types/schemas/index.js +1 -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 +9 -0
- package/dist/browser/utils/common/utils.js +11 -0
- package/dist/browser/utils/logging/index.d.ts +2 -0
- package/dist/browser/utils/logging/index.js +2 -0
- package/dist/browser/utils/logging/log.d.ts +33 -0
- package/dist/browser/utils/logging/log.js +75 -0
- package/dist/browser/utils/logging/logger.d.ts +18 -0
- package/dist/browser/utils/logging/logger.js +18 -0
- package/dist/client/a2a-client.d.ts +2 -1
- package/dist/client/a2a-client.js +13 -4
- package/dist/server/express/errors.js +1 -1
- package/dist/server/express/middeware.d.ts +2 -2
- package/dist/server/express/middeware.js +26 -6
- package/dist/server/express/server.d.ts +26 -25
- package/dist/server/express/server.js +32 -6
- package/dist/services/a2a/factory/builder.d.ts +24 -24
- package/dist/services/a2a/factory/builder.js +6 -1
- package/dist/services/a2a/factory/service.js +2 -1
- package/dist/services/a2a/helpers/agentcard-builder.d.ts +7 -0
- package/dist/services/a2a/helpers/agentcard-builder.js +23 -0
- package/dist/services/a2a/helpers/history.d.ts +2 -0
- package/dist/services/a2a/helpers/history.js +3 -0
- package/dist/services/a2a/helpers/index.d.ts +3 -0
- package/dist/services/a2a/helpers/index.js +3 -0
- package/dist/services/a2a/methods/get-task.d.ts +46 -46
- package/dist/services/a2a/methods/get-task.js +2 -0
- package/dist/services/a2a/methods/send-message.js +18 -1
- package/dist/services/a2a/service.d.ts +154 -153
- package/dist/services/a2a/service.js +20 -6
- package/dist/services/mcp/service.js +0 -1
- package/dist/transport/rpc/parser.js +2 -2
- package/dist/transport/rpc/rpc-client.js +2 -2
- package/dist/transport/trpc/a2a/factory/router.d.ts +1084 -1084
- package/dist/transport/trpc/a2a/routes/info.d.ts +36 -36
- package/dist/transport/trpc/a2a/routes/message/route.d.ts +225 -225
- package/dist/transport/trpc/a2a/routes/tasks/route.d.ts +257 -257
- package/dist/transport/trpc/a2a/trpc.d.ts +120 -120
- package/dist/types/interfaces/services/a2a/service.d.ts +6 -1
- package/dist/types/schemas/a2a/agent.d.ts +818 -818
- package/dist/types/schemas/a2a/agent.js +1 -23
- package/dist/types/schemas/a2a/auth.d.ts +197 -197
- package/dist/types/schemas/a2a/auth.js +4 -19
- package/dist/types/schemas/a2a/error.d.ts +24 -24
- package/dist/types/schemas/a2a/message.d.ts +4499 -4499
- package/dist/types/schemas/a2a/message.js +2 -10
- package/dist/types/schemas/a2a/notification.d.ts +403 -403
- package/dist/types/schemas/a2a/notification.js +3 -7
- package/dist/types/schemas/a2a/parameters.d.ts +264 -264
- package/dist/types/schemas/a2a/parameters.js +1 -14
- package/dist/types/schemas/a2a/protocol.d.ts +5988 -5988
- package/dist/types/schemas/a2a/rpc.d.ts +20 -20
- package/dist/types/schemas/a2a/rpc.js +0 -5
- package/dist/types/schemas/a2a/task.d.ts +2513 -2513
- package/dist/types/schemas/a2a/task.js +10 -11
- package/dist/utils/common/constants.js +1 -1
- package/dist/utils/common/errors.d.ts +2 -1
- package/dist/utils/common/errors.js +2 -1
- package/dist/utils/common/schema-validation.d.ts +2 -0
- package/dist/utils/common/schema-validation.js +12 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/package.json +20 -17
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { TaskPushNotificationConfig, TaskIdParams, Task } from "../schemas/a2a/index.js";
|
|
6
|
+
import type { AgentCard, TaskQueryParams, MessageSendParams, Message } from "../schemas/a2a/index.js";
|
|
7
|
+
import { UpdateEvent } from "./services/a2a/index.js";
|
|
8
|
+
/**
|
|
9
|
+
* @interface Client
|
|
10
|
+
* @description Defines the standard contract for an A2A (Agent-to-Agent) client implementation.
|
|
11
|
+
* This interface allows consumers to create custom client solutions while ensuring
|
|
12
|
+
* compatibility with the A2A protocol. It outlines the core functionalities
|
|
13
|
+
* required for interacting with an A2A agent server, including task management,
|
|
14
|
+
* capability discovery, and communication configuration.
|
|
15
|
+
*/
|
|
16
|
+
export interface Client {
|
|
17
|
+
/**
|
|
18
|
+
* @description Fetches the agent's metadata (AgentCard) from a well-known path or a fallback path.
|
|
19
|
+
* The AgentCard contains essential information about the agent, such as its capabilities and endpoints.
|
|
20
|
+
* @param {string} wellKnownPath The standard path (e.g., "/.well-known/a2a") to look for the AgentCard.
|
|
21
|
+
* @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.
|
|
23
|
+
* @async
|
|
24
|
+
*/
|
|
25
|
+
agentCard(): Promise<AgentCard>;
|
|
26
|
+
/**
|
|
27
|
+
* @description Refreshes the cached AgentCard information by re-fetching it from the server.
|
|
28
|
+
* Useful when the agent's capabilities or configuration might have changed.
|
|
29
|
+
* @returns {Promise<AgentCard>} A promise that resolves with the updated AgentCard object.
|
|
30
|
+
* @async
|
|
31
|
+
*/
|
|
32
|
+
refreshAgentCard(): Promise<AgentCard>;
|
|
33
|
+
/**
|
|
34
|
+
* @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.
|
|
37
|
+
* @async
|
|
38
|
+
*/
|
|
39
|
+
sendMessage(params: MessageSendParams): Promise<Message | Task | null>;
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated Will be removed in v6.Use sendMessage instead.
|
|
42
|
+
* @description Sends a task request to the agent server.
|
|
43
|
+
* @param {MessageSendParams} params Parameters required to send the task, including the task definition and metadata.
|
|
44
|
+
* @returns {Promise<Task | null>} A promise that resolves with the initial Task object representing the submitted task, or null if the submission failed.
|
|
45
|
+
* @async
|
|
46
|
+
*/
|
|
47
|
+
sendTask(params: MessageSendParams): Promise<Message | Task | null>;
|
|
48
|
+
/**
|
|
49
|
+
* @description Sends a task request and subscribes to real-time updates (status changes, artifact updates) for that task.
|
|
50
|
+
* This uses a streaming connection if available.
|
|
51
|
+
* @param {MessageSendParams} params Parameters required to send the task.
|
|
52
|
+
* @returns {AsyncIterable<UpdateEvent>} An async iterable that yields task status and artifact updates.
|
|
53
|
+
* @async
|
|
54
|
+
*/
|
|
55
|
+
sendStreamingMessage(params: MessageSendParams): AsyncIterable<UpdateEvent>;
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated Will be removed in v6Use sendStreamingMessage instead.
|
|
58
|
+
* @description Sends a task request and subscribes to real-time updates (status changes, artifact updates) for that task.
|
|
59
|
+
* This uses a streaming connection if available.
|
|
60
|
+
* @param {MessageSendParams} params Parameters required to send the task.
|
|
61
|
+
* @returns {AsyncIterable<UpdateEvent>} An async iterable that yields task status and artifact updates.
|
|
62
|
+
* @async
|
|
63
|
+
*/
|
|
64
|
+
sendTaskSubscribe(params: MessageSendParams): AsyncIterable<UpdateEvent>;
|
|
65
|
+
/**
|
|
66
|
+
* @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.
|
|
69
|
+
* @async
|
|
70
|
+
*/
|
|
71
|
+
getTask(params: TaskQueryParams): Promise<Task | null>;
|
|
72
|
+
/**
|
|
73
|
+
* @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.
|
|
76
|
+
* @async
|
|
77
|
+
*/
|
|
78
|
+
cancelTask(params: TaskIdParams): Promise<Task | null>;
|
|
79
|
+
/**
|
|
80
|
+
* @description Configures push notifications for a specific task. This allows the client
|
|
81
|
+
* to receive updates asynchronously via a specified webhook URL.
|
|
82
|
+
* 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.
|
|
85
|
+
* @async
|
|
86
|
+
*/
|
|
87
|
+
setTaskPushNotification(params: TaskPushNotificationConfig): Promise<TaskPushNotificationConfig | null>;
|
|
88
|
+
/**
|
|
89
|
+
* @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.
|
|
92
|
+
* @async
|
|
93
|
+
*/
|
|
94
|
+
getTaskPushNotification(params: TaskIdParams): Promise<TaskPushNotificationConfig | null>;
|
|
95
|
+
/**
|
|
96
|
+
* @description Resubscribes to updates for an existing task, potentially after a connection drop or client restart.
|
|
97
|
+
* This allows resuming the stream of status and artifact updates.
|
|
98
|
+
* @param {TaskQueryParams} params Parameters containing the task ID to resubscribe to.
|
|
99
|
+
* @returns {AsyncIterable<UpdateEvent>} An async iterable that yields task status and artifact updates.
|
|
100
|
+
* @async
|
|
101
|
+
*/
|
|
102
|
+
resubscribeTask(params: TaskQueryParams): AsyncIterable<UpdateEvent>;
|
|
103
|
+
/**
|
|
104
|
+
* @description Checks if the agent server supports a specific capability.
|
|
105
|
+
* @param {"streaming" | "pushNotifications" | "stateTransitionHistory"} capability The capability to check for.
|
|
106
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the capability is supported, false otherwise.
|
|
107
|
+
* @async
|
|
108
|
+
*/
|
|
109
|
+
supports(capability: "streaming" | "pushNotifications" | "stateTransitionHistory"): Promise<boolean>;
|
|
110
|
+
/**
|
|
111
|
+
* @description Sets multiple HTTP headers to be included in all subsequent requests made by the client instance.
|
|
112
|
+
* Replaces any previously set headers.
|
|
113
|
+
* @param {Record<string, string>} headers An object containing header names and values.
|
|
114
|
+
* @returns {void}
|
|
115
|
+
*/
|
|
116
|
+
setHeaders(headers: Record<string, string>): void;
|
|
117
|
+
/**
|
|
118
|
+
* @description Adds or updates a single HTTP header for subsequent requests.
|
|
119
|
+
* @param {string} name The name of the header.
|
|
120
|
+
* @param {string} value The value of the header.
|
|
121
|
+
* @returns {void}
|
|
122
|
+
*/
|
|
123
|
+
addHeader(name: string, value: string): void;
|
|
124
|
+
/**
|
|
125
|
+
* @description Removes a specific HTTP header from subsequent requests.
|
|
126
|
+
* @param {string} name The name of the header to remove.
|
|
127
|
+
* @returns {void}
|
|
128
|
+
*/
|
|
129
|
+
removeHeader(name: string): void;
|
|
130
|
+
/**
|
|
131
|
+
* @description Clears all custom HTTP headers previously set on the client instance.
|
|
132
|
+
* @returns {void}
|
|
133
|
+
*/
|
|
134
|
+
clearHeaders(): void;
|
|
135
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { Context, Command, TextPart, DataPart, FilePart } from "../../../index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Restricting to command for now, but could be extended to other types of commands in the future.
|
|
8
|
+
* When we shift to CoreCommand, move this into core.
|
|
9
|
+
*/
|
|
10
|
+
export interface StepArgs<TCommand extends Command = Command> {
|
|
11
|
+
command: TCommand;
|
|
12
|
+
context: Context;
|
|
13
|
+
}
|
|
14
|
+
export type StepParams<TCommand extends Command = Command, TInboundArgs extends readonly unknown[] = []> = StepArgs<TCommand> & Partial<{
|
|
15
|
+
content: string;
|
|
16
|
+
args: TInboundArgs;
|
|
17
|
+
}>;
|
|
18
|
+
export type StepOutput<TPart extends DataPart["data"] | FilePart["file"] | TextPart["text"]> = {
|
|
19
|
+
parts: Array<TPart> | TPart;
|
|
20
|
+
};
|
|
21
|
+
export type StepOutputWithForwardArgs<TPart extends DataPart["data"] | FilePart["file"] | TextPart["text"], TForwardArgs extends readonly unknown[] = []> = StepOutput<TPart> & {
|
|
22
|
+
args: TForwardArgs;
|
|
23
|
+
};
|
|
24
|
+
export type Step<TCommand extends Command = Command, TPart extends DataPart["data"] | FilePart["file"] | TextPart["text"] = TextPart["text"], TInboundArgs extends readonly unknown[] = [], TForwardArgs extends readonly unknown[] = [], TOutput extends StepOutput<TPart> | StepOutputWithForwardArgs<TPart, TForwardArgs> | Array<TPart> | TPart = StepOutput<TPart>> = (params: StepParams<TCommand, TInboundArgs>) => Promise<TOutput> | TOutput;
|
|
25
|
+
export type StepWithKind<TCommand extends Command = Command, TPart extends DataPart["data"] | FilePart["file"] | TextPart["text"] = TextPart["text"], TInboundArgs extends readonly unknown[] = [], TForwardArgs extends readonly unknown[] = [], TOutput extends StepOutput<TPart> | StepOutputWithForwardArgs<TPart, TForwardArgs> | Array<TPart> | TPart = StepOutput<TPart>, TKind extends "text" | "file" | "data" = "text"> = {
|
|
26
|
+
step: Step<TCommand, TPart, TInboundArgs, TForwardArgs, TOutput>;
|
|
27
|
+
kind: TKind;
|
|
28
|
+
};
|
|
29
|
+
export type OutArgsOf<O> = O extends StepOutputWithForwardArgs<any, infer A> ? A : [];
|
|
30
|
+
export interface StepBuilder<TCommand extends Command = Command, TInboundArgs extends readonly unknown[] = []> {
|
|
31
|
+
/**
|
|
32
|
+
* Add a step to the builder.
|
|
33
|
+
* @param step - The step to add.
|
|
34
|
+
* @returns A new builder with the step added.
|
|
35
|
+
*/
|
|
36
|
+
addStep<TPart extends DataPart["data"] | FilePart["file"] | TextPart["text"] = TextPart["text"], TForwardArgs extends readonly unknown[] = [], TOutput extends StepOutput<TPart> | StepOutputWithForwardArgs<TPart, TForwardArgs> | Array<TPart> | TPart = StepOutput<TPart>, TKind extends "text" | "file" | "data" = "text">(step: StepWithKind<TCommand, TPart, TInboundArgs, TForwardArgs, TOutput, TKind>): StepBuilder<TCommand, OutArgsOf<TOutput>>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview A2A (Agent-to-Agent) Context Type Definitions
|
|
7
|
+
*
|
|
8
|
+
* This module provides type definitions for the Agent-to-Agent communication context,
|
|
9
|
+
* extending the core context types with A2A-specific functionality for task handling,
|
|
10
|
+
* message processing, and event management.
|
|
11
|
+
*
|
|
12
|
+
* @module A2AContext
|
|
13
|
+
* @version 0.5.7
|
|
14
|
+
* @since 0.5.6
|
|
15
|
+
* @author The Artinet Project
|
|
16
|
+
*/
|
|
17
|
+
import { type TaskStatusUpdateEvent, type TaskArtifactUpdateEvent, type Task, type Message, A2ARequest, MessageSendParams } from "../../../schemas/a2a/index.js";
|
|
18
|
+
import { CoreCommand, CoreState, CoreUpdate } from "../core/context/types.js";
|
|
19
|
+
import { CoreContext } from "../core/context/context.js";
|
|
20
|
+
import { TaskAndHistory } from "./legacy.js";
|
|
21
|
+
/**
|
|
22
|
+
* Represents the possible types of updates that can be yielded by a TaskHandler.
|
|
23
|
+
*
|
|
24
|
+
* This union type encompasses all event types that can be emitted during A2A
|
|
25
|
+
* task processing, providing a type-safe way to handle different update scenarios.
|
|
26
|
+
*
|
|
27
|
+
* @description Either a Message, Task, TaskStatusUpdateEvent, or TaskArtifactUpdateEvent.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
* @since 0.5.6
|
|
31
|
+
*/
|
|
32
|
+
export type UpdateEvent = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
|
|
33
|
+
/**
|
|
34
|
+
* A2A Command type that extends CoreCommand with A2A-specific parameter constraints.
|
|
35
|
+
*
|
|
36
|
+
* This generic type provides type-safe command handling for A2A operations,
|
|
37
|
+
* ensuring that command parameters conform to the expected A2A request structure.
|
|
38
|
+
*
|
|
39
|
+
* @template TParams - The parameter type for the command, must extend A2ARequest params
|
|
40
|
+
* @default MessageSendParams - Default parameter type for message sending operations
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* // Using default MessageSendParams
|
|
45
|
+
* const messageCommand: Command = {
|
|
46
|
+
* type: 'send_message',
|
|
47
|
+
* params: { content: 'Hello', recipient: 'agent123' }
|
|
48
|
+
* };
|
|
49
|
+
*
|
|
50
|
+
* // Using custom parameter type
|
|
51
|
+
* interface CustomParams extends NonNullable<A2ARequest["params"]> {
|
|
52
|
+
* customField: string;
|
|
53
|
+
* }
|
|
54
|
+
* const customCommand: Command<CustomParams> = {
|
|
55
|
+
* type: 'custom_action',
|
|
56
|
+
* params: { customField: 'value' }
|
|
57
|
+
* };
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @public
|
|
61
|
+
* @since 0.5.6
|
|
62
|
+
*/
|
|
63
|
+
export type Command<TParams extends NonNullable<A2ARequest["params"]> = MessageSendParams> = CoreCommand<TParams>;
|
|
64
|
+
/**
|
|
65
|
+
* A2A State type that extends CoreState with task and history management.
|
|
66
|
+
*
|
|
67
|
+
* This type represents the state container for A2A operations, including
|
|
68
|
+
* task tracking and historical data management capabilities.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const state: State = {
|
|
73
|
+
* data: {
|
|
74
|
+
* currentTask: taskInstance,
|
|
75
|
+
* history: [...previousTasks]
|
|
76
|
+
* },
|
|
77
|
+
* metadata: {
|
|
78
|
+
* lastUpdated: new Date(),
|
|
79
|
+
* version: '1.0.0'
|
|
80
|
+
* }
|
|
81
|
+
* };
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @public
|
|
85
|
+
* @since 0.5.6
|
|
86
|
+
*/
|
|
87
|
+
export type State = CoreState<TaskAndHistory>;
|
|
88
|
+
/**
|
|
89
|
+
* A2A Update type that extends CoreUpdate with A2A-specific update events.
|
|
90
|
+
*
|
|
91
|
+
* This generic type provides type-safe update handling for A2A operations,
|
|
92
|
+
* ensuring that updates conform to the expected UpdateEvent structure.
|
|
93
|
+
*
|
|
94
|
+
* @template TUpdate - The update event type, must extend UpdateEvent
|
|
95
|
+
* @default UpdateEvent - Default update event type
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* // Using default UpdateEvent
|
|
100
|
+
* const update: Update = {
|
|
101
|
+
* type: 'task_status_update',
|
|
102
|
+
* payload: statusUpdateEvent
|
|
103
|
+
* };
|
|
104
|
+
*
|
|
105
|
+
* // Using specific update type
|
|
106
|
+
* const messageUpdate: Update<Message> = {
|
|
107
|
+
* type: 'message',
|
|
108
|
+
* payload: messageEvent
|
|
109
|
+
* };
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* @public
|
|
113
|
+
* @since 0.5.6
|
|
114
|
+
*/
|
|
115
|
+
export type Update<TUpdate extends UpdateEvent = UpdateEvent> = CoreUpdate<TUpdate>;
|
|
116
|
+
/**
|
|
117
|
+
* A2A Context type that combines Command, State, and Update types for complete context management.
|
|
118
|
+
*
|
|
119
|
+
* This is the main context type for A2A operations, providing a comprehensive
|
|
120
|
+
* type-safe interface for handling commands, managing state, and processing updates
|
|
121
|
+
* within the Agent-to-Agent communication framework.
|
|
122
|
+
*
|
|
123
|
+
* @template TCommand - The command type, must extend Command
|
|
124
|
+
* @template TState - The state type, must extend State
|
|
125
|
+
* @template TUpdate - The update type, must extend Update<UpdateEvent>
|
|
126
|
+
*
|
|
127
|
+
* @default TCommand - Command<MessageSendParams>
|
|
128
|
+
* @default TState - State
|
|
129
|
+
* @default TUpdate - Update<UpdateEvent>
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* // Using default types
|
|
134
|
+
* const context: Context = {
|
|
135
|
+
* command: messageCommand,
|
|
136
|
+
* state: currentState,
|
|
137
|
+
* update: latestUpdate,
|
|
138
|
+
* // ... other context properties
|
|
139
|
+
* };
|
|
140
|
+
*
|
|
141
|
+
* // Using custom types
|
|
142
|
+
* interface CustomCommand extends Command<CustomParams> {
|
|
143
|
+
* priority: number;
|
|
144
|
+
* }
|
|
145
|
+
*
|
|
146
|
+
* const customContext: Context<CustomCommand, State, Update<Task>> = {
|
|
147
|
+
* command: customCommand,
|
|
148
|
+
* state: currentState,
|
|
149
|
+
* update: taskUpdate,
|
|
150
|
+
* // ... other context properties
|
|
151
|
+
* };
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @remarks
|
|
155
|
+
* This context type is designed to be the primary interface for A2A service
|
|
156
|
+
* implementations, providing type safety and ensuring proper handling of
|
|
157
|
+
* agent-to-agent communication patterns.
|
|
158
|
+
*
|
|
159
|
+
* @public
|
|
160
|
+
* @since 0.5.6
|
|
161
|
+
*/
|
|
162
|
+
export type Context<TCommand extends Command = Command<MessageSendParams>, TState extends State = State, TUpdate extends Update<UpdateEvent> = Update<UpdateEvent>> = CoreContext<TCommand, TState, TUpdate>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { ExecutionEngine } from "../core/execution/index.js";
|
|
6
|
+
import { Command, State, Update } from "./context.js";
|
|
7
|
+
export type A2AEngine = ExecutionEngine<Command, State, Update>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { type Task, type Message, type MessageSendConfiguration } from "../../../schemas/a2a/index.js";
|
|
6
|
+
import { A2AEngine } from "./engine.js";
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Task now has a history property.
|
|
9
|
+
* Represents a task and its associated message history.
|
|
10
|
+
*/
|
|
11
|
+
export interface TaskAndHistory {
|
|
12
|
+
/** The task object */
|
|
13
|
+
task: Task;
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated This property is no longer being updated. Use the task.history property instead.
|
|
16
|
+
* The complete message history associated with the task
|
|
17
|
+
*/
|
|
18
|
+
history: Message[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use the Store interface instead.
|
|
22
|
+
* @description Interface for task storage providers.
|
|
23
|
+
* Abstracts the storage mechanism for tasks and their message history.
|
|
24
|
+
*/
|
|
25
|
+
export interface TaskStore {
|
|
26
|
+
/**
|
|
27
|
+
* Saves a task and its associated message history.
|
|
28
|
+
* Overwrites existing data if the task ID exists.
|
|
29
|
+
* @param data An object containing the task and its history.
|
|
30
|
+
* @returns A promise resolving when the save operation is complete.
|
|
31
|
+
*/
|
|
32
|
+
save(data: TaskAndHistory): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Loads a task and its history by task ID.
|
|
35
|
+
* @param taskId The ID of the task to load.
|
|
36
|
+
* @returns A promise resolving to an object containing the Task and its history, or null if not found.
|
|
37
|
+
*/
|
|
38
|
+
load(taskId: string): Promise<TaskAndHistory | null>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated This interface will be removed in the future. Use ExecutionContext instead.
|
|
42
|
+
* Context object provided to the TaskHandler.
|
|
43
|
+
* Contains the information needed for the handler to process the task.
|
|
44
|
+
*/
|
|
45
|
+
export interface TaskContext {
|
|
46
|
+
/**
|
|
47
|
+
* The context ID of the task.
|
|
48
|
+
*/
|
|
49
|
+
contextId: string;
|
|
50
|
+
/**
|
|
51
|
+
* The current state of the task when the handler is invoked or resumed.
|
|
52
|
+
* This is a snapshot - the latest state may need to be reloaded during async operations.
|
|
53
|
+
*/
|
|
54
|
+
task: Task;
|
|
55
|
+
/**
|
|
56
|
+
* The specific user message that triggered this handler invocation or resumption.
|
|
57
|
+
*/
|
|
58
|
+
userMessage: Message;
|
|
59
|
+
/**
|
|
60
|
+
* Function to check if cancellation has been requested for this task.
|
|
61
|
+
* Handlers should check this periodically during long-running operations.
|
|
62
|
+
* @returns True if cancellation has been requested, false otherwise.
|
|
63
|
+
*/
|
|
64
|
+
isCancelled(): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* The message history associated with the task up to the point the handler is invoked.
|
|
67
|
+
*/
|
|
68
|
+
history: Message[];
|
|
69
|
+
/**
|
|
70
|
+
* @description The latest user message that triggered this handler invocation or resumption.
|
|
71
|
+
* @note It's unclear whether this is necessary as userMessage already exists
|
|
72
|
+
*/
|
|
73
|
+
latestUserMessage?: Message;
|
|
74
|
+
/**
|
|
75
|
+
* The configuration for the task.
|
|
76
|
+
*/
|
|
77
|
+
configuration?: MessageSendConfiguration;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Defines the signature for a task handler function.
|
|
81
|
+
*
|
|
82
|
+
* Handlers are implemented as async generators. They receive context about the
|
|
83
|
+
* task and the triggering message. They perform work and yield status
|
|
84
|
+
* or artifact updates (TaskYieldUpdate). The server consumes these yields,
|
|
85
|
+
* updates the task state in the store, and streams events if applicable.
|
|
86
|
+
*
|
|
87
|
+
* @deprecated Use A2AEngine instead.
|
|
88
|
+
* @param context The TaskContext object containing task details and state.
|
|
89
|
+
* @yields Updates to the task's status or artifacts.
|
|
90
|
+
* @returns Optionally returns the final complete Task object (needed for non-streaming 'message/send').
|
|
91
|
+
* If void is returned, the server uses the last known state after processing all yields.
|
|
92
|
+
*/
|
|
93
|
+
export type TaskHandler = A2AEngine;
|