@a2a-js/sdk 0.2.3 → 0.2.5
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 +1 -1
- package/dist/client/index.cjs +400 -0
- package/dist/client/index.d.cts +124 -0
- package/dist/client/index.d.ts +124 -0
- package/dist/client/index.js +374 -0
- package/dist/index.cjs +17 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +0 -0
- package/dist/server/index.cjs +887 -0
- package/dist/server/index.d.cts +231 -0
- package/dist/server/index.d.ts +231 -0
- package/dist/server/index.js +842 -0
- package/dist/types-CcBgkR2G.d.cts +2048 -0
- package/dist/types-CcBgkR2G.d.ts +2048 -0
- package/package.json +5 -2
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { a as Message, T as Task, b as TaskStatusUpdateEvent, c as TaskArtifactUpdateEvent, A as AgentCard, M as MessageSendParams, g as TaskQueryParams, f as TaskIdParams, d as TaskPushNotificationConfig, j as JSONRPCError } from '../types-CcBgkR2G.cjs';
|
|
3
|
+
import { A2AResponse } from '../index.cjs';
|
|
4
|
+
import { Express, RequestHandler, ErrorRequestHandler } from 'express';
|
|
5
|
+
|
|
6
|
+
type AgentExecutionEvent = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
|
|
7
|
+
interface ExecutionEventBus {
|
|
8
|
+
publish(event: AgentExecutionEvent): void;
|
|
9
|
+
on(eventName: 'event' | 'finished', listener: (event: AgentExecutionEvent) => void): this;
|
|
10
|
+
off(eventName: 'event' | 'finished', listener: (event: AgentExecutionEvent) => void): this;
|
|
11
|
+
once(eventName: 'event' | 'finished', listener: (event: AgentExecutionEvent) => void): this;
|
|
12
|
+
removeAllListeners(eventName?: 'event' | 'finished'): this;
|
|
13
|
+
finished(): void;
|
|
14
|
+
}
|
|
15
|
+
declare class DefaultExecutionEventBus extends EventEmitter implements ExecutionEventBus {
|
|
16
|
+
constructor();
|
|
17
|
+
publish(event: AgentExecutionEvent): void;
|
|
18
|
+
finished(): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare class RequestContext {
|
|
22
|
+
readonly userMessage: Message;
|
|
23
|
+
readonly task?: Task;
|
|
24
|
+
readonly referenceTasks?: Task[];
|
|
25
|
+
readonly taskId: string;
|
|
26
|
+
readonly contextId: string;
|
|
27
|
+
constructor(userMessage: Message, taskId: string, contextId: string, task?: Task, referenceTasks?: Task[]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface AgentExecutor {
|
|
31
|
+
/**
|
|
32
|
+
* Executes the agent logic based on the request context and publishes events.
|
|
33
|
+
* @param requestContext The context of the current request.
|
|
34
|
+
* @param eventBus The bus to publish execution events to.
|
|
35
|
+
*/
|
|
36
|
+
execute: (requestContext: RequestContext, eventBus: ExecutionEventBus) => Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Method to explicitly cancel a running task.
|
|
39
|
+
* The implementation should handle the logic of stopping the execution
|
|
40
|
+
* and publishing the final 'canceled' status event on the provided event bus.
|
|
41
|
+
* @param taskId The ID of the task to cancel.
|
|
42
|
+
* @param eventBus The event bus associated with the task's execution.
|
|
43
|
+
*/
|
|
44
|
+
cancelTask: (taskId: string, eventBus: ExecutionEventBus) => Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface ExecutionEventBusManager {
|
|
48
|
+
createOrGetByTaskId(taskId: string): ExecutionEventBus;
|
|
49
|
+
getByTaskId(taskId: string): ExecutionEventBus | undefined;
|
|
50
|
+
cleanupByTaskId(taskId: string): void;
|
|
51
|
+
}
|
|
52
|
+
declare class DefaultExecutionEventBusManager implements ExecutionEventBusManager {
|
|
53
|
+
private taskIdToBus;
|
|
54
|
+
/**
|
|
55
|
+
* Creates or retrieves an existing ExecutionEventBus based on the taskId.
|
|
56
|
+
* @param taskId The ID of the task.
|
|
57
|
+
* @returns An instance of IExecutionEventBus.
|
|
58
|
+
*/
|
|
59
|
+
createOrGetByTaskId(taskId: string): ExecutionEventBus;
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves an existing ExecutionEventBus based on the taskId.
|
|
62
|
+
* @param taskId The ID of the task.
|
|
63
|
+
* @returns An instance of IExecutionEventBus or undefined if not found.
|
|
64
|
+
*/
|
|
65
|
+
getByTaskId(taskId: string): ExecutionEventBus | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Removes the event bus for a given taskId.
|
|
68
|
+
* This should be called when an execution flow is complete to free resources.
|
|
69
|
+
* @param taskId The ID of the task.
|
|
70
|
+
*/
|
|
71
|
+
cleanupByTaskId(taskId: string): void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* An async queue that subscribes to an ExecutionEventBus for events
|
|
76
|
+
* and provides an async generator to consume them.
|
|
77
|
+
*/
|
|
78
|
+
declare class ExecutionEventQueue {
|
|
79
|
+
private eventBus;
|
|
80
|
+
private eventQueue;
|
|
81
|
+
private resolvePromise?;
|
|
82
|
+
private stopped;
|
|
83
|
+
private boundHandleEvent;
|
|
84
|
+
constructor(eventBus: ExecutionEventBus);
|
|
85
|
+
private handleEvent;
|
|
86
|
+
private handleFinished;
|
|
87
|
+
/**
|
|
88
|
+
* Provides an async generator that yields events from the event bus.
|
|
89
|
+
* Stops when a Message event is received or a TaskStatusUpdateEvent with final=true is received.
|
|
90
|
+
*/
|
|
91
|
+
events(): AsyncGenerator<AgentExecutionEvent, void, undefined>;
|
|
92
|
+
/**
|
|
93
|
+
* Stops the event queue from processing further events.
|
|
94
|
+
*/
|
|
95
|
+
stop(): void;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface A2ARequestHandler {
|
|
99
|
+
getAgentCard(): Promise<AgentCard>;
|
|
100
|
+
sendMessage(params: MessageSendParams): Promise<Message | Task>;
|
|
101
|
+
sendMessageStream(params: MessageSendParams): AsyncGenerator<Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
|
|
102
|
+
getTask(params: TaskQueryParams): Promise<Task>;
|
|
103
|
+
cancelTask(params: TaskIdParams): Promise<Task>;
|
|
104
|
+
setTaskPushNotificationConfig(params: TaskPushNotificationConfig): Promise<TaskPushNotificationConfig>;
|
|
105
|
+
getTaskPushNotificationConfig(params: TaskIdParams): Promise<TaskPushNotificationConfig>;
|
|
106
|
+
resubscribe(params: TaskIdParams): AsyncGenerator<Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Simplified interface for task storage providers.
|
|
111
|
+
* Stores and retrieves the task.
|
|
112
|
+
*/
|
|
113
|
+
interface TaskStore {
|
|
114
|
+
/**
|
|
115
|
+
* Saves a task.
|
|
116
|
+
* Overwrites existing data if the task ID exists.
|
|
117
|
+
* @param data An object containing the task.
|
|
118
|
+
* @returns A promise resolving when the save operation is complete.
|
|
119
|
+
*/
|
|
120
|
+
save(task: Task): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Loads a task by task ID.
|
|
123
|
+
* @param taskId The ID of the task to load.
|
|
124
|
+
* @returns A promise resolving to an object containing the Task, or undefined if not found.
|
|
125
|
+
*/
|
|
126
|
+
load(taskId: string): Promise<Task | undefined>;
|
|
127
|
+
}
|
|
128
|
+
declare class InMemoryTaskStore implements TaskStore {
|
|
129
|
+
private store;
|
|
130
|
+
load(taskId: string): Promise<Task | undefined>;
|
|
131
|
+
save(task: Task): Promise<void>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
declare class DefaultRequestHandler implements A2ARequestHandler {
|
|
135
|
+
private readonly agentCard;
|
|
136
|
+
private readonly taskStore;
|
|
137
|
+
private readonly agentExecutor;
|
|
138
|
+
private readonly eventBusManager;
|
|
139
|
+
private readonly pushNotificationConfigs;
|
|
140
|
+
constructor(agentCard: AgentCard, taskStore: TaskStore, agentExecutor: AgentExecutor, eventBusManager?: ExecutionEventBusManager);
|
|
141
|
+
getAgentCard(): Promise<AgentCard>;
|
|
142
|
+
private _createRequestContext;
|
|
143
|
+
private _processEvents;
|
|
144
|
+
sendMessage(params: MessageSendParams): Promise<Message | Task>;
|
|
145
|
+
sendMessageStream(params: MessageSendParams): AsyncGenerator<Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
|
|
146
|
+
getTask(params: TaskQueryParams): Promise<Task>;
|
|
147
|
+
cancelTask(params: TaskIdParams): Promise<Task>;
|
|
148
|
+
setTaskPushNotificationConfig(params: TaskPushNotificationConfig): Promise<TaskPushNotificationConfig>;
|
|
149
|
+
getTaskPushNotificationConfig(params: TaskIdParams): Promise<TaskPushNotificationConfig>;
|
|
150
|
+
resubscribe(params: TaskIdParams): AsyncGenerator<Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
declare class ResultManager {
|
|
154
|
+
private taskStore;
|
|
155
|
+
private currentTask?;
|
|
156
|
+
private latestUserMessage?;
|
|
157
|
+
private finalMessageResult?;
|
|
158
|
+
constructor(taskStore: TaskStore);
|
|
159
|
+
setContext(latestUserMessage: Message): void;
|
|
160
|
+
/**
|
|
161
|
+
* Processes an agent execution event and updates the task store.
|
|
162
|
+
* @param event The agent execution event.
|
|
163
|
+
*/
|
|
164
|
+
processEvent(event: AgentExecutionEvent): Promise<void>;
|
|
165
|
+
private saveCurrentTask;
|
|
166
|
+
/**
|
|
167
|
+
* Gets the final result, which could be a Message or a Task.
|
|
168
|
+
* This should be called after the event stream has been fully processed.
|
|
169
|
+
* @returns The final Message or the current Task.
|
|
170
|
+
*/
|
|
171
|
+
getFinalResult(): Message | Task | undefined;
|
|
172
|
+
/**
|
|
173
|
+
* Gets the task currently being managed by this ResultManager instance.
|
|
174
|
+
* This task could be one that was started with or one created during agent execution.
|
|
175
|
+
* @returns The current Task or undefined if no task is active.
|
|
176
|
+
*/
|
|
177
|
+
getCurrentTask(): Task | undefined;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Handles JSON-RPC transport layer, routing requests to A2ARequestHandler.
|
|
182
|
+
*/
|
|
183
|
+
declare class JsonRpcTransportHandler {
|
|
184
|
+
private requestHandler;
|
|
185
|
+
constructor(requestHandler: A2ARequestHandler);
|
|
186
|
+
/**
|
|
187
|
+
* Handles an incoming JSON-RPC request.
|
|
188
|
+
* For streaming methods, it returns an AsyncGenerator of JSONRPCResult.
|
|
189
|
+
* For non-streaming methods, it returns a Promise of a single JSONRPCMessage (Result or ErrorResponse).
|
|
190
|
+
*/
|
|
191
|
+
handle(requestBody: any): Promise<A2AResponse | AsyncGenerator<A2AResponse, void, undefined>>;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
declare class A2AExpressApp {
|
|
195
|
+
private requestHandler;
|
|
196
|
+
private jsonRpcTransportHandler;
|
|
197
|
+
constructor(requestHandler: A2ARequestHandler);
|
|
198
|
+
/**
|
|
199
|
+
* Adds A2A routes to an existing Express app.
|
|
200
|
+
* @param app Optional existing Express app.
|
|
201
|
+
* @param baseUrl The base URL for A2A endpoints (e.g., "/a2a/api").
|
|
202
|
+
* @param middlewares Optional array of Express middlewares to apply to the A2A routes.
|
|
203
|
+
* @returns The Express app with A2A routes.
|
|
204
|
+
*/
|
|
205
|
+
setupRoutes(app: Express, baseUrl?: string, middlewares?: Array<RequestHandler | ErrorRequestHandler>): Express;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Custom error class for A2A server operations, incorporating JSON-RPC error codes.
|
|
210
|
+
*/
|
|
211
|
+
declare class A2AError extends Error {
|
|
212
|
+
code: number;
|
|
213
|
+
data?: Record<string, unknown>;
|
|
214
|
+
taskId?: string;
|
|
215
|
+
constructor(code: number, message: string, data?: Record<string, unknown>, taskId?: string);
|
|
216
|
+
/**
|
|
217
|
+
* Formats the error into a standard JSON-RPC error object structure.
|
|
218
|
+
*/
|
|
219
|
+
toJSONRPCError(): JSONRPCError;
|
|
220
|
+
static parseError(message: string, data?: Record<string, unknown>): A2AError;
|
|
221
|
+
static invalidRequest(message: string, data?: Record<string, unknown>): A2AError;
|
|
222
|
+
static methodNotFound(method: string): A2AError;
|
|
223
|
+
static invalidParams(message: string, data?: Record<string, unknown>): A2AError;
|
|
224
|
+
static internalError(message: string, data?: Record<string, unknown>): A2AError;
|
|
225
|
+
static taskNotFound(taskId: string): A2AError;
|
|
226
|
+
static taskNotCancelable(taskId: string): A2AError;
|
|
227
|
+
static pushNotificationNotSupported(): A2AError;
|
|
228
|
+
static unsupportedOperation(operation: string): A2AError;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export { A2AError, A2AExpressApp, type A2ARequestHandler, type AgentExecutionEvent, type AgentExecutor, DefaultExecutionEventBus, DefaultExecutionEventBusManager, DefaultRequestHandler, type ExecutionEventBus, type ExecutionEventBusManager, ExecutionEventQueue, InMemoryTaskStore, JsonRpcTransportHandler, RequestContext, ResultManager, type TaskStore };
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { a as Message, T as Task, b as TaskStatusUpdateEvent, c as TaskArtifactUpdateEvent, A as AgentCard, M as MessageSendParams, g as TaskQueryParams, f as TaskIdParams, d as TaskPushNotificationConfig, j as JSONRPCError } from '../types-CcBgkR2G.js';
|
|
3
|
+
import { A2AResponse } from '../index.js';
|
|
4
|
+
import { Express, RequestHandler, ErrorRequestHandler } from 'express';
|
|
5
|
+
|
|
6
|
+
type AgentExecutionEvent = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
|
|
7
|
+
interface ExecutionEventBus {
|
|
8
|
+
publish(event: AgentExecutionEvent): void;
|
|
9
|
+
on(eventName: 'event' | 'finished', listener: (event: AgentExecutionEvent) => void): this;
|
|
10
|
+
off(eventName: 'event' | 'finished', listener: (event: AgentExecutionEvent) => void): this;
|
|
11
|
+
once(eventName: 'event' | 'finished', listener: (event: AgentExecutionEvent) => void): this;
|
|
12
|
+
removeAllListeners(eventName?: 'event' | 'finished'): this;
|
|
13
|
+
finished(): void;
|
|
14
|
+
}
|
|
15
|
+
declare class DefaultExecutionEventBus extends EventEmitter implements ExecutionEventBus {
|
|
16
|
+
constructor();
|
|
17
|
+
publish(event: AgentExecutionEvent): void;
|
|
18
|
+
finished(): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare class RequestContext {
|
|
22
|
+
readonly userMessage: Message;
|
|
23
|
+
readonly task?: Task;
|
|
24
|
+
readonly referenceTasks?: Task[];
|
|
25
|
+
readonly taskId: string;
|
|
26
|
+
readonly contextId: string;
|
|
27
|
+
constructor(userMessage: Message, taskId: string, contextId: string, task?: Task, referenceTasks?: Task[]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface AgentExecutor {
|
|
31
|
+
/**
|
|
32
|
+
* Executes the agent logic based on the request context and publishes events.
|
|
33
|
+
* @param requestContext The context of the current request.
|
|
34
|
+
* @param eventBus The bus to publish execution events to.
|
|
35
|
+
*/
|
|
36
|
+
execute: (requestContext: RequestContext, eventBus: ExecutionEventBus) => Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Method to explicitly cancel a running task.
|
|
39
|
+
* The implementation should handle the logic of stopping the execution
|
|
40
|
+
* and publishing the final 'canceled' status event on the provided event bus.
|
|
41
|
+
* @param taskId The ID of the task to cancel.
|
|
42
|
+
* @param eventBus The event bus associated with the task's execution.
|
|
43
|
+
*/
|
|
44
|
+
cancelTask: (taskId: string, eventBus: ExecutionEventBus) => Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface ExecutionEventBusManager {
|
|
48
|
+
createOrGetByTaskId(taskId: string): ExecutionEventBus;
|
|
49
|
+
getByTaskId(taskId: string): ExecutionEventBus | undefined;
|
|
50
|
+
cleanupByTaskId(taskId: string): void;
|
|
51
|
+
}
|
|
52
|
+
declare class DefaultExecutionEventBusManager implements ExecutionEventBusManager {
|
|
53
|
+
private taskIdToBus;
|
|
54
|
+
/**
|
|
55
|
+
* Creates or retrieves an existing ExecutionEventBus based on the taskId.
|
|
56
|
+
* @param taskId The ID of the task.
|
|
57
|
+
* @returns An instance of IExecutionEventBus.
|
|
58
|
+
*/
|
|
59
|
+
createOrGetByTaskId(taskId: string): ExecutionEventBus;
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves an existing ExecutionEventBus based on the taskId.
|
|
62
|
+
* @param taskId The ID of the task.
|
|
63
|
+
* @returns An instance of IExecutionEventBus or undefined if not found.
|
|
64
|
+
*/
|
|
65
|
+
getByTaskId(taskId: string): ExecutionEventBus | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Removes the event bus for a given taskId.
|
|
68
|
+
* This should be called when an execution flow is complete to free resources.
|
|
69
|
+
* @param taskId The ID of the task.
|
|
70
|
+
*/
|
|
71
|
+
cleanupByTaskId(taskId: string): void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* An async queue that subscribes to an ExecutionEventBus for events
|
|
76
|
+
* and provides an async generator to consume them.
|
|
77
|
+
*/
|
|
78
|
+
declare class ExecutionEventQueue {
|
|
79
|
+
private eventBus;
|
|
80
|
+
private eventQueue;
|
|
81
|
+
private resolvePromise?;
|
|
82
|
+
private stopped;
|
|
83
|
+
private boundHandleEvent;
|
|
84
|
+
constructor(eventBus: ExecutionEventBus);
|
|
85
|
+
private handleEvent;
|
|
86
|
+
private handleFinished;
|
|
87
|
+
/**
|
|
88
|
+
* Provides an async generator that yields events from the event bus.
|
|
89
|
+
* Stops when a Message event is received or a TaskStatusUpdateEvent with final=true is received.
|
|
90
|
+
*/
|
|
91
|
+
events(): AsyncGenerator<AgentExecutionEvent, void, undefined>;
|
|
92
|
+
/**
|
|
93
|
+
* Stops the event queue from processing further events.
|
|
94
|
+
*/
|
|
95
|
+
stop(): void;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface A2ARequestHandler {
|
|
99
|
+
getAgentCard(): Promise<AgentCard>;
|
|
100
|
+
sendMessage(params: MessageSendParams): Promise<Message | Task>;
|
|
101
|
+
sendMessageStream(params: MessageSendParams): AsyncGenerator<Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
|
|
102
|
+
getTask(params: TaskQueryParams): Promise<Task>;
|
|
103
|
+
cancelTask(params: TaskIdParams): Promise<Task>;
|
|
104
|
+
setTaskPushNotificationConfig(params: TaskPushNotificationConfig): Promise<TaskPushNotificationConfig>;
|
|
105
|
+
getTaskPushNotificationConfig(params: TaskIdParams): Promise<TaskPushNotificationConfig>;
|
|
106
|
+
resubscribe(params: TaskIdParams): AsyncGenerator<Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Simplified interface for task storage providers.
|
|
111
|
+
* Stores and retrieves the task.
|
|
112
|
+
*/
|
|
113
|
+
interface TaskStore {
|
|
114
|
+
/**
|
|
115
|
+
* Saves a task.
|
|
116
|
+
* Overwrites existing data if the task ID exists.
|
|
117
|
+
* @param data An object containing the task.
|
|
118
|
+
* @returns A promise resolving when the save operation is complete.
|
|
119
|
+
*/
|
|
120
|
+
save(task: Task): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Loads a task by task ID.
|
|
123
|
+
* @param taskId The ID of the task to load.
|
|
124
|
+
* @returns A promise resolving to an object containing the Task, or undefined if not found.
|
|
125
|
+
*/
|
|
126
|
+
load(taskId: string): Promise<Task | undefined>;
|
|
127
|
+
}
|
|
128
|
+
declare class InMemoryTaskStore implements TaskStore {
|
|
129
|
+
private store;
|
|
130
|
+
load(taskId: string): Promise<Task | undefined>;
|
|
131
|
+
save(task: Task): Promise<void>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
declare class DefaultRequestHandler implements A2ARequestHandler {
|
|
135
|
+
private readonly agentCard;
|
|
136
|
+
private readonly taskStore;
|
|
137
|
+
private readonly agentExecutor;
|
|
138
|
+
private readonly eventBusManager;
|
|
139
|
+
private readonly pushNotificationConfigs;
|
|
140
|
+
constructor(agentCard: AgentCard, taskStore: TaskStore, agentExecutor: AgentExecutor, eventBusManager?: ExecutionEventBusManager);
|
|
141
|
+
getAgentCard(): Promise<AgentCard>;
|
|
142
|
+
private _createRequestContext;
|
|
143
|
+
private _processEvents;
|
|
144
|
+
sendMessage(params: MessageSendParams): Promise<Message | Task>;
|
|
145
|
+
sendMessageStream(params: MessageSendParams): AsyncGenerator<Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
|
|
146
|
+
getTask(params: TaskQueryParams): Promise<Task>;
|
|
147
|
+
cancelTask(params: TaskIdParams): Promise<Task>;
|
|
148
|
+
setTaskPushNotificationConfig(params: TaskPushNotificationConfig): Promise<TaskPushNotificationConfig>;
|
|
149
|
+
getTaskPushNotificationConfig(params: TaskIdParams): Promise<TaskPushNotificationConfig>;
|
|
150
|
+
resubscribe(params: TaskIdParams): AsyncGenerator<Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
declare class ResultManager {
|
|
154
|
+
private taskStore;
|
|
155
|
+
private currentTask?;
|
|
156
|
+
private latestUserMessage?;
|
|
157
|
+
private finalMessageResult?;
|
|
158
|
+
constructor(taskStore: TaskStore);
|
|
159
|
+
setContext(latestUserMessage: Message): void;
|
|
160
|
+
/**
|
|
161
|
+
* Processes an agent execution event and updates the task store.
|
|
162
|
+
* @param event The agent execution event.
|
|
163
|
+
*/
|
|
164
|
+
processEvent(event: AgentExecutionEvent): Promise<void>;
|
|
165
|
+
private saveCurrentTask;
|
|
166
|
+
/**
|
|
167
|
+
* Gets the final result, which could be a Message or a Task.
|
|
168
|
+
* This should be called after the event stream has been fully processed.
|
|
169
|
+
* @returns The final Message or the current Task.
|
|
170
|
+
*/
|
|
171
|
+
getFinalResult(): Message | Task | undefined;
|
|
172
|
+
/**
|
|
173
|
+
* Gets the task currently being managed by this ResultManager instance.
|
|
174
|
+
* This task could be one that was started with or one created during agent execution.
|
|
175
|
+
* @returns The current Task or undefined if no task is active.
|
|
176
|
+
*/
|
|
177
|
+
getCurrentTask(): Task | undefined;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Handles JSON-RPC transport layer, routing requests to A2ARequestHandler.
|
|
182
|
+
*/
|
|
183
|
+
declare class JsonRpcTransportHandler {
|
|
184
|
+
private requestHandler;
|
|
185
|
+
constructor(requestHandler: A2ARequestHandler);
|
|
186
|
+
/**
|
|
187
|
+
* Handles an incoming JSON-RPC request.
|
|
188
|
+
* For streaming methods, it returns an AsyncGenerator of JSONRPCResult.
|
|
189
|
+
* For non-streaming methods, it returns a Promise of a single JSONRPCMessage (Result or ErrorResponse).
|
|
190
|
+
*/
|
|
191
|
+
handle(requestBody: any): Promise<A2AResponse | AsyncGenerator<A2AResponse, void, undefined>>;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
declare class A2AExpressApp {
|
|
195
|
+
private requestHandler;
|
|
196
|
+
private jsonRpcTransportHandler;
|
|
197
|
+
constructor(requestHandler: A2ARequestHandler);
|
|
198
|
+
/**
|
|
199
|
+
* Adds A2A routes to an existing Express app.
|
|
200
|
+
* @param app Optional existing Express app.
|
|
201
|
+
* @param baseUrl The base URL for A2A endpoints (e.g., "/a2a/api").
|
|
202
|
+
* @param middlewares Optional array of Express middlewares to apply to the A2A routes.
|
|
203
|
+
* @returns The Express app with A2A routes.
|
|
204
|
+
*/
|
|
205
|
+
setupRoutes(app: Express, baseUrl?: string, middlewares?: Array<RequestHandler | ErrorRequestHandler>): Express;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Custom error class for A2A server operations, incorporating JSON-RPC error codes.
|
|
210
|
+
*/
|
|
211
|
+
declare class A2AError extends Error {
|
|
212
|
+
code: number;
|
|
213
|
+
data?: Record<string, unknown>;
|
|
214
|
+
taskId?: string;
|
|
215
|
+
constructor(code: number, message: string, data?: Record<string, unknown>, taskId?: string);
|
|
216
|
+
/**
|
|
217
|
+
* Formats the error into a standard JSON-RPC error object structure.
|
|
218
|
+
*/
|
|
219
|
+
toJSONRPCError(): JSONRPCError;
|
|
220
|
+
static parseError(message: string, data?: Record<string, unknown>): A2AError;
|
|
221
|
+
static invalidRequest(message: string, data?: Record<string, unknown>): A2AError;
|
|
222
|
+
static methodNotFound(method: string): A2AError;
|
|
223
|
+
static invalidParams(message: string, data?: Record<string, unknown>): A2AError;
|
|
224
|
+
static internalError(message: string, data?: Record<string, unknown>): A2AError;
|
|
225
|
+
static taskNotFound(taskId: string): A2AError;
|
|
226
|
+
static taskNotCancelable(taskId: string): A2AError;
|
|
227
|
+
static pushNotificationNotSupported(): A2AError;
|
|
228
|
+
static unsupportedOperation(operation: string): A2AError;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export { A2AError, A2AExpressApp, type A2ARequestHandler, type AgentExecutionEvent, type AgentExecutor, DefaultExecutionEventBus, DefaultExecutionEventBusManager, DefaultRequestHandler, type ExecutionEventBus, type ExecutionEventBusManager, ExecutionEventQueue, InMemoryTaskStore, JsonRpcTransportHandler, RequestContext, ResultManager, type TaskStore };
|