pi-a2a-adaptor 1.0.0
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/LICENSE +21 -0
- package/README.md +158 -0
- package/package.json +29 -0
- package/pi-extension/index.ts +523 -0
- package/pi-extension/pi-types.d.ts +8 -0
- package/src/client.ts +365 -0
- package/src/errors.ts +38 -0
- package/src/index.ts +5 -0
- package/src/registry.ts +37 -0
- package/src/task-manager.ts +101 -0
- package/src/types.ts +360 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════════════════════
|
|
2
|
+
// A2A Protocol Types — based on fasta2a v0.6.1 wire format
|
|
3
|
+
// ═══════════════════════════════════════════════════════════
|
|
4
|
+
|
|
5
|
+
// ─── Part (discriminated union with kind) ───
|
|
6
|
+
|
|
7
|
+
export type Part = TextPart | FilePart | DataPart;
|
|
8
|
+
|
|
9
|
+
export interface TextPart {
|
|
10
|
+
kind: "text";
|
|
11
|
+
text: string;
|
|
12
|
+
metadata?: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface FilePart {
|
|
16
|
+
kind: "file";
|
|
17
|
+
file: FileWithBytes | FileWithUri;
|
|
18
|
+
metadata?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface FileWithBytes {
|
|
22
|
+
bytes: string; // base64
|
|
23
|
+
mimeType?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface FileWithUri {
|
|
27
|
+
uri: string;
|
|
28
|
+
mimeType?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface DataPart {
|
|
32
|
+
kind: "data";
|
|
33
|
+
data: Record<string, unknown>;
|
|
34
|
+
metadata?: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ─── Message ───
|
|
38
|
+
|
|
39
|
+
export interface Message {
|
|
40
|
+
role: "user" | "agent";
|
|
41
|
+
parts: Part[];
|
|
42
|
+
kind?: "message";
|
|
43
|
+
metadata?: Record<string, unknown>;
|
|
44
|
+
messageId: string;
|
|
45
|
+
contextId?: string;
|
|
46
|
+
taskId?: string;
|
|
47
|
+
referenceTaskIds?: string[];
|
|
48
|
+
extensions?: string[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ─── Task ───
|
|
52
|
+
|
|
53
|
+
export type TaskState =
|
|
54
|
+
| "submitted"
|
|
55
|
+
| "working"
|
|
56
|
+
| "inputRequired"
|
|
57
|
+
| "authRequired"
|
|
58
|
+
| "completed"
|
|
59
|
+
| "failed"
|
|
60
|
+
| "canceled"
|
|
61
|
+
| "rejected";
|
|
62
|
+
|
|
63
|
+
export interface TaskStatus {
|
|
64
|
+
state: TaskState;
|
|
65
|
+
message?: Message;
|
|
66
|
+
timestamp?: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface Artifact {
|
|
70
|
+
artifactId: string;
|
|
71
|
+
name?: string;
|
|
72
|
+
description?: string;
|
|
73
|
+
parts: Part[];
|
|
74
|
+
metadata?: Record<string, unknown>;
|
|
75
|
+
extensions?: string[];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface A2ATask {
|
|
79
|
+
id: string;
|
|
80
|
+
contextId: string;
|
|
81
|
+
kind: "task";
|
|
82
|
+
status: TaskStatus;
|
|
83
|
+
history?: Message[];
|
|
84
|
+
artifacts?: Artifact[];
|
|
85
|
+
metadata?: Record<string, unknown>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ─── SSE Stream Response (JSON-RPC envelope + kind discriminated union) ───
|
|
89
|
+
|
|
90
|
+
export interface JSONRPCResponse {
|
|
91
|
+
jsonrpc: "2.0";
|
|
92
|
+
id: string | number;
|
|
93
|
+
result?: StreamResult;
|
|
94
|
+
error?: {
|
|
95
|
+
code: number;
|
|
96
|
+
message: string;
|
|
97
|
+
data?: unknown;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type StreamResult =
|
|
102
|
+
| { kind: "task"; task: A2ATask }
|
|
103
|
+
| { kind: "message"; message: Message }
|
|
104
|
+
| { kind: "status-update"; taskId: string; contextId: string; status: TaskStatus; final: boolean; metadata?: Record<string, unknown> }
|
|
105
|
+
| { kind: "artifact-update"; taskId: string; contextId: string; artifact: Artifact; append?: boolean; lastChunk?: boolean; metadata?: Record<string, unknown> };
|
|
106
|
+
|
|
107
|
+
// ─── JSON-RPC Request ───
|
|
108
|
+
|
|
109
|
+
export interface JSONRPCRequest {
|
|
110
|
+
jsonrpc: "2.0";
|
|
111
|
+
id: string | number;
|
|
112
|
+
method: string;
|
|
113
|
+
params?: Record<string, unknown>;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ─── Push Notification ───
|
|
117
|
+
|
|
118
|
+
export interface PushNotificationConfig {
|
|
119
|
+
id?: string;
|
|
120
|
+
url: string;
|
|
121
|
+
token?: string;
|
|
122
|
+
authentication?: {
|
|
123
|
+
scheme: string;
|
|
124
|
+
credentials?: string;
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ─── MessageSendConfiguration ───
|
|
129
|
+
|
|
130
|
+
export interface MessageSendConfiguration {
|
|
131
|
+
acceptedOutputModes: string[];
|
|
132
|
+
blocking?: boolean;
|
|
133
|
+
historyLength?: number;
|
|
134
|
+
pushNotificationConfig?: PushNotificationConfig;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// ─── Request Params ───
|
|
138
|
+
|
|
139
|
+
export interface MessageSendParams {
|
|
140
|
+
message: Message;
|
|
141
|
+
configuration?: MessageSendConfiguration;
|
|
142
|
+
tenant?: string;
|
|
143
|
+
metadata?: Record<string, unknown>;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface TaskQueryParams {
|
|
147
|
+
id: string;
|
|
148
|
+
historyLength?: number;
|
|
149
|
+
tenant?: string;
|
|
150
|
+
metadata?: Record<string, unknown>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface TaskIdParams {
|
|
154
|
+
id: string;
|
|
155
|
+
tenant?: string;
|
|
156
|
+
metadata?: Record<string, unknown>;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface ListTasksParams {
|
|
160
|
+
contextId?: string;
|
|
161
|
+
status?: TaskState;
|
|
162
|
+
statusTimestampAfter?: string;
|
|
163
|
+
historyLength?: number;
|
|
164
|
+
includeArtifacts?: boolean;
|
|
165
|
+
pageSize?: number;
|
|
166
|
+
pageToken?: string;
|
|
167
|
+
tenant?: string;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface ListTasksResult {
|
|
171
|
+
tasks: A2ATask[];
|
|
172
|
+
nextPageToken?: string;
|
|
173
|
+
pageSize?: number;
|
|
174
|
+
totalSize?: number;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ─── AgentCard ───
|
|
178
|
+
|
|
179
|
+
export interface AgentInterface {
|
|
180
|
+
protocolBinding: "JSONRPC" | "GRPC" | "HTTP+JSON" | string;
|
|
181
|
+
url: string;
|
|
182
|
+
protocolVersion?: string;
|
|
183
|
+
tenant?: string;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export interface AgentCapabilities {
|
|
187
|
+
streaming?: boolean;
|
|
188
|
+
pushNotifications?: boolean;
|
|
189
|
+
extendedAgentCard?: boolean;
|
|
190
|
+
extensions?: AgentExtension[];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export interface AgentExtension {
|
|
194
|
+
uri: string;
|
|
195
|
+
description?: string;
|
|
196
|
+
required?: boolean;
|
|
197
|
+
params?: Record<string, unknown>;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface AgentProvider {
|
|
201
|
+
organization: string;
|
|
202
|
+
url?: string;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface AgentSkill {
|
|
206
|
+
id: string;
|
|
207
|
+
name: string;
|
|
208
|
+
description: string;
|
|
209
|
+
tags: string[];
|
|
210
|
+
examples?: string[];
|
|
211
|
+
inputModes?: string[];
|
|
212
|
+
outputModes?: string[];
|
|
213
|
+
securityRequirements?: SecurityRequirement[];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface AgentCardSignature {
|
|
217
|
+
protected: string;
|
|
218
|
+
signature: string;
|
|
219
|
+
header?: Record<string, unknown>;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export interface AgentCard {
|
|
223
|
+
name: string;
|
|
224
|
+
description: string;
|
|
225
|
+
version: string;
|
|
226
|
+
url?: string;
|
|
227
|
+
provider?: AgentProvider;
|
|
228
|
+
documentationUrl?: string;
|
|
229
|
+
iconUrl?: string;
|
|
230
|
+
supportedInterfaces?: AgentInterface[];
|
|
231
|
+
capabilities: AgentCapabilities;
|
|
232
|
+
securitySchemes?: Record<string, SecurityScheme>;
|
|
233
|
+
securityRequirements?: SecurityRequirement[];
|
|
234
|
+
defaultInputModes: string[];
|
|
235
|
+
defaultOutputModes: string[];
|
|
236
|
+
skills: AgentSkill[];
|
|
237
|
+
signatures?: AgentCardSignature[];
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export interface SecurityScheme {
|
|
241
|
+
httpAuthSecurityScheme?: { scheme: string; bearerFormat?: string; description?: string };
|
|
242
|
+
apiKeySecurityScheme?: { name: string; location: string; description?: string };
|
|
243
|
+
oauth2SecurityScheme?: { flows: Record<string, unknown>; oauth2MetadataUrl?: string; description?: string };
|
|
244
|
+
openIdConnectSecurityScheme?: { openIdConnectUrl: string; description?: string };
|
|
245
|
+
mtlsSecurityScheme?: { description?: string };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export interface SecurityRequirement {
|
|
249
|
+
schemes: Record<string, string[]>;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// ─── Configuration & Agent ───
|
|
253
|
+
|
|
254
|
+
export interface A2AClientOptions {
|
|
255
|
+
protocol?: "a2a-v1" | "pi-legacy";
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export interface A2AConfig {
|
|
259
|
+
client: ClientConfig;
|
|
260
|
+
server: ServerConfig;
|
|
261
|
+
discovery: DiscoveryConfig;
|
|
262
|
+
security: SecurityConfig;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export interface ServerConfig {
|
|
266
|
+
enabled: boolean;
|
|
267
|
+
port: number;
|
|
268
|
+
host: string;
|
|
269
|
+
basePath: string;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export interface ClientConfig {
|
|
273
|
+
timeout: number;
|
|
274
|
+
retryAttempts: number;
|
|
275
|
+
retryDelay: number;
|
|
276
|
+
maxConcurrentTasks: number;
|
|
277
|
+
streamingEnabled: boolean;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export interface DiscoveryConfig {
|
|
281
|
+
cacheEnabled: boolean;
|
|
282
|
+
cacheTtl: number;
|
|
283
|
+
agentCardPath: string;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export interface A2AConfig {
|
|
287
|
+
client: ClientConfig;
|
|
288
|
+
server: ServerConfig;
|
|
289
|
+
discovery: DiscoveryConfig;
|
|
290
|
+
security: SecurityConfig;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export interface SecurityConfig {
|
|
294
|
+
defaultScheme: "bearer" | "apiKey" | "oauth2" | "mtls" | "none";
|
|
295
|
+
verifySsl: boolean;
|
|
296
|
+
apiKey?: string;
|
|
297
|
+
bearerToken?: string;
|
|
298
|
+
oauth2Config?: {
|
|
299
|
+
clientId: string;
|
|
300
|
+
clientSecret: string;
|
|
301
|
+
tokenUrl: string;
|
|
302
|
+
scopes: string[];
|
|
303
|
+
};
|
|
304
|
+
mtlsConfig?: { cert: string; key: string; ca?: string };
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export interface PollingOptions {
|
|
308
|
+
intervalMs: number;
|
|
309
|
+
maxAttempts: number;
|
|
310
|
+
timeoutMs: number;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export interface TaskOptions {
|
|
314
|
+
streaming?: boolean;
|
|
315
|
+
timeout?: number;
|
|
316
|
+
signal?: AbortSignal;
|
|
317
|
+
historyLength?: number;
|
|
318
|
+
blocking?: boolean;
|
|
319
|
+
acceptedOutputModes?: string[];
|
|
320
|
+
pushNotificationConfig?: PushNotificationConfig;
|
|
321
|
+
polling?: PollingOptions;
|
|
322
|
+
metadata?: Record<string, unknown>;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export interface RemoteAgent {
|
|
326
|
+
name: string;
|
|
327
|
+
description: string;
|
|
328
|
+
url: string;
|
|
329
|
+
version: string;
|
|
330
|
+
supportedInterfaces?: AgentInterface[];
|
|
331
|
+
capabilities: AgentCapabilities;
|
|
332
|
+
skills: AgentSkill[];
|
|
333
|
+
defaultInputModes: string[];
|
|
334
|
+
defaultOutputModes: string[];
|
|
335
|
+
discoveredAt: number;
|
|
336
|
+
lastUsedAt?: number;
|
|
337
|
+
healthStatus?: "healthy" | "unhealthy" | "unknown";
|
|
338
|
+
healthCheckedAt?: number;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// ─── Callbacks ───
|
|
342
|
+
|
|
343
|
+
export type TaskUpdateCallback = (update: Partial<A2ATask>) => void;
|
|
344
|
+
|
|
345
|
+
// ─── JSON-RPC Error Codes ───
|
|
346
|
+
|
|
347
|
+
export enum JSONRPCErrorCode {
|
|
348
|
+
ParseError = -32700,
|
|
349
|
+
InvalidRequest = -32600,
|
|
350
|
+
MethodNotFound = -32601,
|
|
351
|
+
InvalidParams = -32602,
|
|
352
|
+
InternalError = -32603,
|
|
353
|
+
TaskNotFound = -32001,
|
|
354
|
+
TaskNotCancelable = -32002,
|
|
355
|
+
PushNotificationNotSupported = -32003,
|
|
356
|
+
UnsupportedOperation = -32004,
|
|
357
|
+
ContentTypeNotSupported = -32005,
|
|
358
|
+
InvalidAgentResponse = -32006,
|
|
359
|
+
TaskTimeout = -32007,
|
|
360
|
+
}
|