@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,413 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview A2A Service Interface Definitions
|
|
7
|
+
*
|
|
8
|
+
* This module defines interfaces for Agent-to-Agent (A2A) service implementations,
|
|
9
|
+
* including factory parameters, method options, and the main service interface.
|
|
10
|
+
* It extends the core service framework with A2A-specific functionality for
|
|
11
|
+
* agent communication, task management, and message handling.
|
|
12
|
+
*
|
|
13
|
+
* @module A2AService
|
|
14
|
+
* @version 0.5.7
|
|
15
|
+
* @since 0.5.6
|
|
16
|
+
* @author The Artinet Project
|
|
17
|
+
*/
|
|
18
|
+
import { ConnectionManagerInterface, CancellationManagerInterface, ContextManagerInterface, ServiceInterface, TaskManagerInterface, EventManagerOptions } from "../core/index.js";
|
|
19
|
+
import { AgentCard, MessageSendParams, SendMessageSuccessResult, Task, TaskIdParams, TaskQueryParams } from "../../../schemas/a2a/index.js";
|
|
20
|
+
import { UpdateEvent, Command, State, Update } from "./context.js";
|
|
21
|
+
import { A2AEngine } from "./engine.js";
|
|
22
|
+
export type AgentCardParams = (Partial<AgentCard> & Required<Pick<AgentCard, "name">>) | string;
|
|
23
|
+
/**
|
|
24
|
+
* Configuration parameters for creating A2A service instances.
|
|
25
|
+
*
|
|
26
|
+
* This interface defines the required and optional components needed to
|
|
27
|
+
* instantiate an A2A service, including the agent identity, execution engine,
|
|
28
|
+
* and various manager interfaces for handling different aspects of A2A operations.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const factoryParams: FactoryParams = {
|
|
33
|
+
* agentCard: {
|
|
34
|
+
* id: 'agent-123',
|
|
35
|
+
* name: 'MyAgent',
|
|
36
|
+
* capabilities: ['messaging', 'task-processing']
|
|
37
|
+
* },
|
|
38
|
+
* engine: createA2AEngine(),
|
|
39
|
+
* contexts: createContextManager(),
|
|
40
|
+
* connections: createConnectionManager(),
|
|
41
|
+
* methods: {
|
|
42
|
+
* sendMessage: customSendMessage,
|
|
43
|
+
* getTask: customGetTask
|
|
44
|
+
* }
|
|
45
|
+
* };
|
|
46
|
+
*
|
|
47
|
+
* const service = createA2AService(factoryParams);
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
* @since 0.5.6
|
|
52
|
+
*/
|
|
53
|
+
export interface FactoryParams {
|
|
54
|
+
/** Agent identity and capabilities information */
|
|
55
|
+
agentCard: AgentCardParams;
|
|
56
|
+
/** Execution engine for processing A2A commands */
|
|
57
|
+
engine: A2AEngine;
|
|
58
|
+
/** Optional context manager for execution state management */
|
|
59
|
+
contexts?: ContextManagerInterface<Command, State, Update>;
|
|
60
|
+
/** Optional connection manager for agent connections */
|
|
61
|
+
connections?: ConnectionManagerInterface;
|
|
62
|
+
/** Optional cancellation manager for handling operation cancellations */
|
|
63
|
+
cancellations?: CancellationManagerInterface;
|
|
64
|
+
/** Optional task manager for task lifecycle management */
|
|
65
|
+
tasks?: TaskManagerInterface<State>;
|
|
66
|
+
/** Optional custom method implementations */
|
|
67
|
+
methods?: Partial<MethodOptions>;
|
|
68
|
+
/** Optional event manager configuration overrides */
|
|
69
|
+
events?: EventManagerOptions<Command, State, Update>;
|
|
70
|
+
/** Enforce parameter validation */
|
|
71
|
+
enforceParamValidation?: boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Parameters passed to A2A method implementations.
|
|
75
|
+
*
|
|
76
|
+
* This interface defines the dependencies and context information that
|
|
77
|
+
* method implementations receive when they are invoked. It provides access
|
|
78
|
+
* to the service instance, execution engine, context management, and
|
|
79
|
+
* cancellation mechanisms.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const customSendMessage = async (
|
|
84
|
+
* message: MessageSendParams,
|
|
85
|
+
* params: MethodParams
|
|
86
|
+
* ): Promise<SendMessageSuccessResult> => {
|
|
87
|
+
* const { service, engine, contextManager, signal } = params;
|
|
88
|
+
*
|
|
89
|
+
* // Create execution context
|
|
90
|
+
* const context = contextManager.createContext(message);
|
|
91
|
+
*
|
|
92
|
+
* // Check for cancellation
|
|
93
|
+
* if (signal.aborted) {
|
|
94
|
+
* throw new Error('Operation cancelled');
|
|
95
|
+
* }
|
|
96
|
+
*
|
|
97
|
+
* // Execute message sending
|
|
98
|
+
* return await service.execute(engine, context);
|
|
99
|
+
* };
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @public
|
|
103
|
+
* @since 0.5.6
|
|
104
|
+
*/
|
|
105
|
+
export interface MethodParams {
|
|
106
|
+
/** The A2A service instance */
|
|
107
|
+
service: A2AServiceInterface<Command, State, Update>;
|
|
108
|
+
/** The execution engine for processing */
|
|
109
|
+
engine: A2AEngine;
|
|
110
|
+
/** Context manager for execution state */
|
|
111
|
+
contextManager: ContextManagerInterface<Command, State, Update>;
|
|
112
|
+
/** Abort signal for cancellation handling */
|
|
113
|
+
signal: AbortSignal;
|
|
114
|
+
/** Enforce input validation */
|
|
115
|
+
enforceValidation?: boolean;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Custom method implementation options for A2A services.
|
|
119
|
+
*
|
|
120
|
+
* This interface allows customization of core A2A operations by providing
|
|
121
|
+
* alternative implementations for task management, message handling, and
|
|
122
|
+
* streaming operations. Each method can be individually overridden to
|
|
123
|
+
* provide custom behavior while maintaining the standard interface.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const customMethods: MethodOptions = {
|
|
128
|
+
* sendMessage: async (message, params) => {
|
|
129
|
+
* // Custom message sending logic
|
|
130
|
+
* console.log(`Sending message to: ${message.recipient}`);
|
|
131
|
+
* const result = await defaultSendMessage(message, params);
|
|
132
|
+
* console.log(`Message sent with ID: ${result.messageId}`);
|
|
133
|
+
* return result;
|
|
134
|
+
* },
|
|
135
|
+
*
|
|
136
|
+
* getTask: async (input, params) => {
|
|
137
|
+
* // Custom task retrieval with caching
|
|
138
|
+
* const cached = taskCache.get(input.taskId);
|
|
139
|
+
* if (cached) return cached;
|
|
140
|
+
*
|
|
141
|
+
* const task = await defaultGetTask(input, params);
|
|
142
|
+
* taskCache.set(input.taskId, task);
|
|
143
|
+
* return task;
|
|
144
|
+
* }
|
|
145
|
+
* };
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* @public
|
|
149
|
+
* @since 0.5.6
|
|
150
|
+
*/
|
|
151
|
+
export interface MethodOptions {
|
|
152
|
+
/**
|
|
153
|
+
* Custom task retrieval implementation.
|
|
154
|
+
*
|
|
155
|
+
* @param input - Task query parameters
|
|
156
|
+
* @param params - Method execution parameters (without engine, contextManager, signal)
|
|
157
|
+
* @returns Promise resolving to the requested task
|
|
158
|
+
*/
|
|
159
|
+
getTask: (input: TaskQueryParams, params: Omit<MethodParams, "engine" | "contextManager" | "signal">) => Promise<Task>;
|
|
160
|
+
/**
|
|
161
|
+
* Task cancellation.
|
|
162
|
+
*
|
|
163
|
+
* @param input - Task identification parameters
|
|
164
|
+
* @param params - Method execution parameters (without engine, signal)
|
|
165
|
+
* @returns Promise resolving to the cancelled task
|
|
166
|
+
*/
|
|
167
|
+
cancelTask: (input: TaskIdParams, params: Omit<MethodParams, "engine" | "signal">) => Promise<Task>;
|
|
168
|
+
/**
|
|
169
|
+
* Message sending.
|
|
170
|
+
*
|
|
171
|
+
* @param message - Message parameters to send
|
|
172
|
+
* @param params - Full method execution parameters
|
|
173
|
+
* @returns Promise resolving to send operation result
|
|
174
|
+
*/
|
|
175
|
+
sendMessage: (message: MessageSendParams, params: MethodParams) => Promise<SendMessageSuccessResult>;
|
|
176
|
+
/**
|
|
177
|
+
* Streaming messages.
|
|
178
|
+
*
|
|
179
|
+
* @param message - Message parameters to send
|
|
180
|
+
* @param params - Full method execution parameters
|
|
181
|
+
* @returns AsyncGenerator yielding update events
|
|
182
|
+
*/
|
|
183
|
+
streamMessage: (message: MessageSendParams, params: MethodParams) => AsyncGenerator<UpdateEvent>;
|
|
184
|
+
/**
|
|
185
|
+
* Resubscription.
|
|
186
|
+
*
|
|
187
|
+
* @param input - Task identification parameters
|
|
188
|
+
* @param params - Full method execution parameters
|
|
189
|
+
* @returns AsyncGenerator yielding update events
|
|
190
|
+
*/
|
|
191
|
+
resubscribe: (input: TaskIdParams, params: MethodParams) => AsyncGenerator<UpdateEvent>;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Public interface for A2A service methods.
|
|
195
|
+
*
|
|
196
|
+
* This interface defines the public API that consumers of A2A services
|
|
197
|
+
* can use to interact with agents. It provides simplified method signatures
|
|
198
|
+
* that hide internal complexity while exposing the essential functionality
|
|
199
|
+
* for agent-to-agent communication.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* // Using the methods interface
|
|
204
|
+
* const service: MethodsInterface = createA2AService(params);
|
|
205
|
+
*
|
|
206
|
+
* // Get a task
|
|
207
|
+
* const task = await service.getTask({ taskId: 'task-123' });
|
|
208
|
+
*
|
|
209
|
+
* // Send a message
|
|
210
|
+
* const result = await service.sendMessage({
|
|
211
|
+
* recipient: 'agent-456',
|
|
212
|
+
* content: 'Hello, how are you?'
|
|
213
|
+
* });
|
|
214
|
+
*
|
|
215
|
+
* // Stream messages for real-time updates
|
|
216
|
+
* for await (const update of service.streamMessage({
|
|
217
|
+
* recipient: 'agent-456',
|
|
218
|
+
* content: 'Processing your request...'
|
|
219
|
+
* })) {
|
|
220
|
+
* console.log('Update:', update);
|
|
221
|
+
* }
|
|
222
|
+
* ```
|
|
223
|
+
*
|
|
224
|
+
* @public
|
|
225
|
+
* @since 0.5.6
|
|
226
|
+
*/
|
|
227
|
+
export interface MethodsInterface {
|
|
228
|
+
/**
|
|
229
|
+
* Retrieves a task by its ID.
|
|
230
|
+
*
|
|
231
|
+
* @param input - Task identification parameters
|
|
232
|
+
* @returns Promise resolving to the requested task
|
|
233
|
+
*/
|
|
234
|
+
getTask: (input: TaskQueryParams) => Promise<Task>;
|
|
235
|
+
/**
|
|
236
|
+
* Cancels a task by its ID.
|
|
237
|
+
*
|
|
238
|
+
* @param input - Task identification parameters
|
|
239
|
+
* @returns Promise resolving to the cancelled task
|
|
240
|
+
*/
|
|
241
|
+
cancelTask: (input: TaskIdParams) => Promise<Task>;
|
|
242
|
+
/**
|
|
243
|
+
* Sends a message to another agent.
|
|
244
|
+
*
|
|
245
|
+
* @param message - Message parameters to send
|
|
246
|
+
* @param params - Optional execution parameters
|
|
247
|
+
* @returns Promise resolving to send operation result
|
|
248
|
+
*/
|
|
249
|
+
sendMessage: (message: MessageSendParams, params?: Partial<Omit<MethodParams, "service" | "contextManager">>) => Promise<SendMessageSuccessResult>;
|
|
250
|
+
/**
|
|
251
|
+
* Sends a message with streaming updates.
|
|
252
|
+
*
|
|
253
|
+
* @param message - Message parameters to send
|
|
254
|
+
* @param params - Optional execution parameters
|
|
255
|
+
* @returns AsyncGenerator yielding update events
|
|
256
|
+
*/
|
|
257
|
+
streamMessage: (message: MessageSendParams, params?: Partial<Omit<MethodParams, "service" | "contextManager">>) => AsyncGenerator<UpdateEvent>;
|
|
258
|
+
/**
|
|
259
|
+
* Resubscribes to updates for a specific task.
|
|
260
|
+
*
|
|
261
|
+
* @param input - Task identification parameters
|
|
262
|
+
* @param params - Optional execution parameters
|
|
263
|
+
* @returns AsyncGenerator yielding update events
|
|
264
|
+
*/
|
|
265
|
+
resubscribe: (input: TaskIdParams, params?: Partial<Omit<MethodParams, "service" | "contextManager">>) => AsyncGenerator<UpdateEvent>;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Main interface for A2A service implementations.
|
|
269
|
+
*
|
|
270
|
+
* This interface extends the core ServiceInterface and MethodsInterface to provide
|
|
271
|
+
* a complete A2A service implementation. It includes agent identity management,
|
|
272
|
+
* connection tracking, cancellation handling, and state management capabilities
|
|
273
|
+
* specific to agent-to-agent communication scenarios.
|
|
274
|
+
*
|
|
275
|
+
* @template TCommand - The command type, must extend Command
|
|
276
|
+
* @template TState - The state type, must extend State
|
|
277
|
+
* @template TUpdate - The update type, must extend Update
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```typescript
|
|
281
|
+
* class MyA2AService implements A2AServiceInterface {
|
|
282
|
+
* constructor(
|
|
283
|
+
* public agentCard: AgentCard,
|
|
284
|
+
* private engine: A2AEngine
|
|
285
|
+
* ) {}
|
|
286
|
+
*
|
|
287
|
+
* async execute(engine, context) {
|
|
288
|
+
* // Handle execution
|
|
289
|
+
* }
|
|
290
|
+
*
|
|
291
|
+
* async sendMessage(message, params) {
|
|
292
|
+
* // Handle message sending
|
|
293
|
+
* }
|
|
294
|
+
*
|
|
295
|
+
* addConnection(id: string) {
|
|
296
|
+
* this.connections.add(id);
|
|
297
|
+
* console.log(`Added connection: ${id}`);
|
|
298
|
+
* }
|
|
299
|
+
*
|
|
300
|
+
* // ... implement other methods
|
|
301
|
+
* }
|
|
302
|
+
* ```
|
|
303
|
+
*
|
|
304
|
+
* @public
|
|
305
|
+
* @since 0.5.6
|
|
306
|
+
*/
|
|
307
|
+
export interface A2AServiceInterface<TCommand extends Command = Command, TState extends State = State, TUpdate extends Update = Update> extends ServiceInterface<TCommand, TState, TUpdate>, MethodsInterface {
|
|
308
|
+
/**
|
|
309
|
+
* Optional event manager configuration overrides.
|
|
310
|
+
*
|
|
311
|
+
* When present, these overrides customize the default event handling
|
|
312
|
+
* behavior for this service instance.
|
|
313
|
+
*/
|
|
314
|
+
readonly eventOverrides: EventManagerOptions<TCommand, TState, TUpdate> | undefined;
|
|
315
|
+
/**
|
|
316
|
+
* Agent identity and capabilities information.
|
|
317
|
+
*
|
|
318
|
+
* This card identifies the agent and describes its capabilities,
|
|
319
|
+
* which is used for agent discovery and capability matching.
|
|
320
|
+
*/
|
|
321
|
+
agentCard: AgentCard;
|
|
322
|
+
/**
|
|
323
|
+
* Adds a connection to the active connections registry.
|
|
324
|
+
*
|
|
325
|
+
* @param id - Unique identifier for the connection
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* ```typescript
|
|
329
|
+
* service.addConnection('connection-123');
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
addConnection: (id: string) => void;
|
|
333
|
+
/**
|
|
334
|
+
* Removes a connection from the active connections registry.
|
|
335
|
+
*
|
|
336
|
+
* @param id - Unique identifier for the connection
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```typescript
|
|
340
|
+
* service.removeConnection('connection-123');
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
removeConnection: (id: string) => void;
|
|
344
|
+
/**
|
|
345
|
+
* Checks if a specific execution context has been cancelled.
|
|
346
|
+
*
|
|
347
|
+
* @param id - Context or execution identifier
|
|
348
|
+
* @returns True if cancelled, false otherwise
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```typescript
|
|
352
|
+
* if (service.isCancelled('context-123')) {
|
|
353
|
+
* console.log('Execution was cancelled');
|
|
354
|
+
* return;
|
|
355
|
+
* }
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
isCancelled: (id: string) => boolean;
|
|
359
|
+
/**
|
|
360
|
+
* Adds a cancellation marker for a specific execution context.
|
|
361
|
+
*
|
|
362
|
+
* @param id - Context or execution identifier to cancel
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```typescript
|
|
366
|
+
* service.addCancellation('context-123');
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
addCancellation: (id: string) => void;
|
|
370
|
+
/**
|
|
371
|
+
* Removes a cancellation marker for a specific execution context.
|
|
372
|
+
*
|
|
373
|
+
* @param id - Context or execution identifier
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* ```typescript
|
|
377
|
+
* service.removeCancellation('context-123');
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
380
|
+
removeCancellation: (id: string) => void;
|
|
381
|
+
/**
|
|
382
|
+
* Retrieves the current state for a specific Task.
|
|
383
|
+
*
|
|
384
|
+
* @param id - Task identifier
|
|
385
|
+
* @returns Promise resolving to the state, or undefined if not found
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```typescript
|
|
389
|
+
* const state = await service.getState('task-123');
|
|
390
|
+
* if (state) {
|
|
391
|
+
* console.log('Current progress:', state.progress);
|
|
392
|
+
* }
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
getState: (id: string) => Promise<TState | undefined>;
|
|
396
|
+
/**
|
|
397
|
+
* Sets the state for a specific Task.
|
|
398
|
+
*
|
|
399
|
+
* @param id - Task identifier
|
|
400
|
+
* @param data - The state data to store
|
|
401
|
+
* @returns Promise that resolves when state is saved
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```typescript
|
|
405
|
+
* await service.setState('task-123', {
|
|
406
|
+
* progress: 0.75,
|
|
407
|
+
* status: 'processing',
|
|
408
|
+
* data: processedResults
|
|
409
|
+
* });
|
|
410
|
+
* ```
|
|
411
|
+
*/
|
|
412
|
+
setState: (id: string, data: TState) => Promise<void>;
|
|
413
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { CoreCommand } from "./types.js";
|
|
6
|
+
import { EventEmitter } from "events";
|
|
7
|
+
export interface CommandChannelMap<TCommand extends CoreCommand = CoreCommand> {
|
|
8
|
+
send: [TCommand];
|
|
9
|
+
close: [];
|
|
10
|
+
}
|
|
11
|
+
export interface SendCommandInterface<TCommand extends CoreCommand = CoreCommand> {
|
|
12
|
+
isOpen: boolean;
|
|
13
|
+
send(command: TCommand): void;
|
|
14
|
+
}
|
|
15
|
+
export interface ReceiveCommandInterface<TCommand extends CoreCommand = CoreCommand> extends AsyncIterable<TCommand, TCommand, TCommand | undefined>, EventEmitter<CommandChannelMap<TCommand>> {
|
|
16
|
+
command: TCommand;
|
|
17
|
+
commandList: TCommand[];
|
|
18
|
+
close(): void;
|
|
19
|
+
next(): Promise<IteratorResult<TCommand>>;
|
|
20
|
+
return(value: TCommand): Promise<IteratorResult<TCommand>>;
|
|
21
|
+
}
|
|
22
|
+
export type ReceiveCommandProxyInterface<TCommand extends CoreCommand = CoreCommand> = ReceiveCommandInterface<TCommand> & TCommand;
|
|
23
|
+
export interface CommandChannelInterface<TCommand extends CoreCommand = CoreCommand> extends ReceiveCommandInterface<TCommand>, SendCommandInterface<TCommand> {
|
|
24
|
+
}
|
|
25
|
+
export type CommandChannelProxyInterface<TCommand extends CoreCommand = CoreCommand> = CommandChannelInterface<TCommand> & TCommand;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview Core Context Interface Definition
|
|
7
|
+
*
|
|
8
|
+
* This module defines the CoreContext interface, which serves as the central
|
|
9
|
+
* execution environment for all command processing. The context encapsulates
|
|
10
|
+
* the command, state management, event handling, and cancellation mechanisms
|
|
11
|
+
* required for execution engine operations.
|
|
12
|
+
*
|
|
13
|
+
* @module CoreContext
|
|
14
|
+
* @version 0.5.7
|
|
15
|
+
* @since 0.5.6
|
|
16
|
+
* @author The Artinet Project
|
|
17
|
+
*/
|
|
18
|
+
import { EventManagerInterface } from "../managers/event.js";
|
|
19
|
+
import { CoreCommand, CoreState, CoreUpdate } from "./types.js";
|
|
20
|
+
import { ReceiveCommandProxyInterface } from "./command.js";
|
|
21
|
+
/**
|
|
22
|
+
* Core execution context interface that provide the complete environment for command execution.
|
|
23
|
+
*
|
|
24
|
+
* The CoreContext serves as the primary execution environment passed to execution engines.
|
|
25
|
+
* It encapsulates all the necessary components for command processing, including the command
|
|
26
|
+
* itself, state management, event handling, and cancellation signals. This design enables
|
|
27
|
+
* execution engines to be stateless functions that receive everything they need through
|
|
28
|
+
* the context parameter.
|
|
29
|
+
*
|
|
30
|
+
* The context is designed to support "Context Engineering" - the practice of carefully
|
|
31
|
+
* constructing execution environments that contain all necessary information and capabilities
|
|
32
|
+
* for effective command processing. As the system evolves, the context becomes increasingly
|
|
33
|
+
* important for enabling sophisticated execution patterns.
|
|
34
|
+
*
|
|
35
|
+
* @template TCommand - The command type, must extend CoreCommand
|
|
36
|
+
* @template TState - The state type, must extend CoreState
|
|
37
|
+
* @template TUpdate - The update type, must extend CoreUpdate
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* // Using context in an execution engine
|
|
42
|
+
* const myEngine: ExecutionEngine<MyCommand, MyState, MyUpdate> = async function* (context) {
|
|
43
|
+
* const { command, State, events, signal, isCancelled } = context;
|
|
44
|
+
*
|
|
45
|
+
* // Get current state
|
|
46
|
+
* const currentState = State();
|
|
47
|
+
*
|
|
48
|
+
* // Check for cancellation
|
|
49
|
+
* if (isCancelled() || signal.aborted) {
|
|
50
|
+
* yield { type: 'cancelled' };
|
|
51
|
+
* return;
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* // Process command
|
|
55
|
+
* const result = await processCommand(command);
|
|
56
|
+
*
|
|
57
|
+
* // Emit events and yield updates
|
|
58
|
+
* events.emit('progress', { progress: 0.5 });
|
|
59
|
+
* yield { type: 'progress', progress: 0.5, data: result };
|
|
60
|
+
* };
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* // Creating and using a context
|
|
66
|
+
* const context: CoreContext<MyCommand, MyState, MyUpdate> = {
|
|
67
|
+
* contextId: 'execution-123',
|
|
68
|
+
* command: createCommandProxy(myCommand),
|
|
69
|
+
* events: createEventManager(),
|
|
70
|
+
* signal: abortController.signal,
|
|
71
|
+
* isCancelled: () => abortController.signal.aborted,
|
|
72
|
+
* State: () => getCurrentState()
|
|
73
|
+
* };
|
|
74
|
+
*
|
|
75
|
+
* // Execute with context
|
|
76
|
+
* for await (const update of myEngine(context)) {
|
|
77
|
+
* console.log('Update:', update);
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* **Design Philosophy:**
|
|
83
|
+
* The context represents a shift toward functional execution patterns where execution
|
|
84
|
+
* engines are pure functions that receive all necessary dependencies through the
|
|
85
|
+
* context parameter. This approach enables:
|
|
86
|
+
*
|
|
87
|
+
* - **Testability**: Easy to mock and test individual components
|
|
88
|
+
* - **Composability**: Different engines can work with the same context interface
|
|
89
|
+
* - **Flexibility**: Context can be enhanced without changing engine signatures
|
|
90
|
+
* - **Debugging**: Complete execution environment is visible and traceable
|
|
91
|
+
*
|
|
92
|
+
* **Context Engineering:**
|
|
93
|
+
* As mentioned in the original note, Context Engineering is becoming increasingly
|
|
94
|
+
* important. This involves carefully designing contexts that provide the right
|
|
95
|
+
* level of abstraction and capability for specific execution scenarios.
|
|
96
|
+
*
|
|
97
|
+
* @public
|
|
98
|
+
* @since 0.5.6
|
|
99
|
+
*/
|
|
100
|
+
export interface CoreContext<TCommand extends CoreCommand = CoreCommand, TState extends CoreState = CoreState, TUpdate extends CoreUpdate = CoreUpdate> {
|
|
101
|
+
/**
|
|
102
|
+
* Unique identifier for this execution context.
|
|
103
|
+
*
|
|
104
|
+
* This ID is used throughout the system to track and correlate execution
|
|
105
|
+
* activities, logs, and state updates with specific command executions.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* console.log(`Starting execution: ${context.contextId}`);
|
|
110
|
+
* loggerService.info(`[${context.contextId}] Processing command`);
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
readonly contextId: string;
|
|
114
|
+
/**
|
|
115
|
+
* Command proxy interface providing access to the command being executed.
|
|
116
|
+
*
|
|
117
|
+
* The command proxy wraps the original command and may provide additional
|
|
118
|
+
* functionality such as validation, logging, or transformation. It allows
|
|
119
|
+
* execution engines to access command data in a controlled manner.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const { command } = context;
|
|
124
|
+
*
|
|
125
|
+
* // Access command properties
|
|
126
|
+
* const userId = command.metadata?.userId;
|
|
127
|
+
* const taskType = command.type;
|
|
128
|
+
* const parameters = command.params;
|
|
129
|
+
*
|
|
130
|
+
* // Use command data in processing
|
|
131
|
+
* const result = await processTask(taskType, parameters, userId);
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
command: ReceiveCommandProxyInterface<TCommand>;
|
|
135
|
+
/**
|
|
136
|
+
* Function to check if the execution has been cancelled.
|
|
137
|
+
*
|
|
138
|
+
* This function provides a convenient way to check cancellation status
|
|
139
|
+
* throughout execution. It may aggregate multiple cancellation sources
|
|
140
|
+
* including abort signals, service-level cancellation, and timeout conditions.
|
|
141
|
+
*
|
|
142
|
+
* @returns True if the execution should be cancelled, false otherwise
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* // Check before expensive operations
|
|
147
|
+
* if (context.isCancelled()) {
|
|
148
|
+
* yield { type: 'cancelled', reason: 'User cancellation' };
|
|
149
|
+
* return;
|
|
150
|
+
* }
|
|
151
|
+
*
|
|
152
|
+
* // Check in processing loops
|
|
153
|
+
* for (const item of largeDataSet) {
|
|
154
|
+
* if (context.isCancelled()) break;
|
|
155
|
+
* await processItem(item);
|
|
156
|
+
* }
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
readonly isCancelled: () => boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Abort signal for cancellation handling.
|
|
162
|
+
*
|
|
163
|
+
* This standard AbortSignal provides a way to handle cancellation in a
|
|
164
|
+
* platform-standard manner. It can be passed to fetch requests, timeouts,
|
|
165
|
+
* and other async operations that support cancellation.
|
|
166
|
+
*/
|
|
167
|
+
readonly signal: AbortSignal;
|
|
168
|
+
/**
|
|
169
|
+
* Event manager for handling execution lifecycle events.
|
|
170
|
+
*
|
|
171
|
+
* The event manager provides event emission and subscription capabilities
|
|
172
|
+
* for execution lifecycle events. It handles state transitions, error
|
|
173
|
+
* scenarios, and completion notifications.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const { events } = context;
|
|
178
|
+
*
|
|
179
|
+
* // Listen for events
|
|
180
|
+
* events.on('update', (state, update) => {
|
|
181
|
+
* console.log('State updated:', state);
|
|
182
|
+
* });
|
|
183
|
+
*
|
|
184
|
+
* // Handle errors
|
|
185
|
+
* events.on('error', (error, state) => {
|
|
186
|
+
* console.error('Execution error:', error);
|
|
187
|
+
* });
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
readonly events: EventManagerInterface<TCommand, TState, TUpdate>;
|
|
191
|
+
/**
|
|
192
|
+
* Function to get the current execution state.
|
|
193
|
+
*
|
|
194
|
+
* This function provides access to the current state of the execution.
|
|
195
|
+
* The state represents the accumulated result of all updates processed
|
|
196
|
+
* so far and serves as the foundation for decision-making in execution engines.
|
|
197
|
+
*
|
|
198
|
+
* @returns The current execution state
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* // Get current state for decision making
|
|
203
|
+
* const currentState = context.State();
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
readonly State: () => TState;
|
|
207
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* We're starting with simple base types for the core context.
|
|
7
|
+
* The base types will expand as we determine what is common across all services.
|
|
8
|
+
*/
|
|
9
|
+
export type CoreCommand<TCommand extends object = object> = TCommand;
|
|
10
|
+
export type CoreState<TState extends {} = {}> = TState;
|
|
11
|
+
export type CoreUpdate<TUpdate = unknown> = TUpdate;
|