@assistant-ui/react-a2a 0.2.5 → 0.2.7

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.
Files changed (60) hide show
  1. package/README.md +47 -1
  2. package/dist/A2AClient.d.ts +43 -0
  3. package/dist/A2AClient.d.ts.map +1 -0
  4. package/dist/A2AClient.js +358 -0
  5. package/dist/A2AClient.js.map +1 -0
  6. package/dist/A2AThreadRuntimeCore.d.ts +75 -0
  7. package/dist/A2AThreadRuntimeCore.d.ts.map +1 -0
  8. package/dist/A2AThreadRuntimeCore.js +483 -0
  9. package/dist/A2AThreadRuntimeCore.js.map +1 -0
  10. package/dist/conversions.d.ts +14 -0
  11. package/dist/conversions.d.ts.map +1 -0
  12. package/dist/conversions.js +92 -0
  13. package/dist/conversions.js.map +1 -0
  14. package/dist/index.d.ts +7 -6
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +7 -6
  17. package/dist/index.js.map +1 -1
  18. package/dist/types.d.ts +228 -84
  19. package/dist/types.d.ts.map +1 -1
  20. package/dist/types.js +4 -9
  21. package/dist/types.js.map +1 -1
  22. package/dist/useA2ARuntime.d.ts +35 -48
  23. package/dist/useA2ARuntime.d.ts.map +1 -1
  24. package/dist/useA2ARuntime.js +126 -172
  25. package/dist/useA2ARuntime.js.map +1 -1
  26. package/package.json +9 -9
  27. package/src/A2AClient.test.ts +773 -0
  28. package/src/A2AClient.ts +519 -0
  29. package/src/A2AThreadRuntimeCore.test.ts +692 -0
  30. package/src/A2AThreadRuntimeCore.ts +633 -0
  31. package/src/conversions.test.ts +276 -0
  32. package/src/conversions.ts +115 -0
  33. package/src/index.ts +66 -6
  34. package/src/types.ts +276 -95
  35. package/src/useA2ARuntime.ts +204 -296
  36. package/dist/A2AMessageAccumulator.d.ts +0 -16
  37. package/dist/A2AMessageAccumulator.d.ts.map +0 -1
  38. package/dist/A2AMessageAccumulator.js +0 -29
  39. package/dist/A2AMessageAccumulator.js.map +0 -1
  40. package/dist/appendA2AChunk.d.ts +0 -3
  41. package/dist/appendA2AChunk.d.ts.map +0 -1
  42. package/dist/appendA2AChunk.js +0 -110
  43. package/dist/appendA2AChunk.js.map +0 -1
  44. package/dist/convertA2AMessages.d.ts +0 -64
  45. package/dist/convertA2AMessages.d.ts.map +0 -1
  46. package/dist/convertA2AMessages.js +0 -90
  47. package/dist/convertA2AMessages.js.map +0 -1
  48. package/dist/testUtils.d.ts +0 -4
  49. package/dist/testUtils.d.ts.map +0 -1
  50. package/dist/testUtils.js +0 -6
  51. package/dist/testUtils.js.map +0 -1
  52. package/dist/useA2AMessages.d.ts +0 -25
  53. package/dist/useA2AMessages.d.ts.map +0 -1
  54. package/dist/useA2AMessages.js +0 -122
  55. package/dist/useA2AMessages.js.map +0 -1
  56. package/src/A2AMessageAccumulator.ts +0 -48
  57. package/src/appendA2AChunk.ts +0 -121
  58. package/src/convertA2AMessages.ts +0 -108
  59. package/src/testUtils.ts +0 -11
  60. package/src/useA2AMessages.ts +0 -180
package/src/types.ts CHANGED
@@ -1,114 +1,295 @@
1
- import { MessageStatus } from "@assistant-ui/react";
2
- import { ReadonlyJSONObject } from "assistant-stream/utils";
1
+ // A2A v1.0 Protocol Types
2
+ // Enum values use lowercase internally; normalized from ProtoJSON SCREAMING_SNAKE_CASE on read.
3
+ // Wire format uses ROLE_USER/ROLE_AGENT and TASK_STATE_* per ADR-001.
3
4
 
4
- // A2A Message Types
5
+ export const A2A_PROTOCOL_VERSION = "1.0";
6
+
7
+ // === Roles ===
8
+ export type A2ARole = "unspecified" | "user" | "agent";
9
+
10
+ // === Part (content unit) ===
11
+ export type A2APart = {
12
+ text?: string | undefined;
13
+ raw?: string | undefined; // base64 encoded bytes
14
+ url?: string | undefined;
15
+ data?: unknown; // google.protobuf.Value
16
+
17
+ metadata?: Record<string, unknown> | undefined;
18
+ filename?: string | undefined;
19
+ mediaType?: string | undefined; // MIME type
20
+ };
21
+
22
+ // === Message ===
5
23
  export type A2AMessage = {
6
- id?: string;
7
- role: "user" | "assistant" | "system" | "tool";
8
- content: string | A2AMessageContent[];
9
- tool_calls?: A2AToolCall[];
10
- tool_call_id?: string;
11
- artifacts?: A2AArtifact[];
12
- status?: MessageStatus;
24
+ messageId: string;
25
+ contextId?: string | undefined;
26
+ taskId?: string | undefined;
27
+ role: A2ARole;
28
+ parts: A2APart[];
29
+ metadata?: Record<string, unknown> | undefined;
30
+ extensions?: string[] | undefined;
31
+ referenceTaskIds?: string[] | undefined;
13
32
  };
14
33
 
15
- export type A2AMessageContent =
16
- | { type: "text"; text: string }
17
- | { type: "image_url"; image_url: string | { url: string } }
18
- | { type: "data"; data: any };
34
+ // === Task State ===
35
+ export type A2ATaskState =
36
+ | "unspecified"
37
+ | "submitted"
38
+ | "working"
39
+ | "completed"
40
+ | "failed"
41
+ | "canceled"
42
+ | "input_required"
43
+ | "rejected"
44
+ | "auth_required";
19
45
 
20
- export type A2AToolCall = {
21
- id: string;
22
- name: string;
23
- args: ReadonlyJSONObject;
24
- argsText?: string;
46
+ // === Task Status ===
47
+ export type A2ATaskStatus = {
48
+ state: A2ATaskState;
49
+ message?: A2AMessage | undefined;
50
+ timestamp?: string | undefined; // ISO 8601
25
51
  };
26
52
 
53
+ // === Artifact ===
27
54
  export type A2AArtifact = {
55
+ artifactId: string;
56
+ name?: string | undefined;
57
+ description?: string | undefined;
58
+ parts: A2APart[];
59
+ metadata?: Record<string, unknown> | undefined;
60
+ extensions?: string[] | undefined;
61
+ };
62
+
63
+ // === Task ===
64
+ export type A2ATask = {
65
+ id: string;
66
+ contextId?: string | undefined;
67
+ status: A2ATaskStatus;
68
+ artifacts?: A2AArtifact[] | undefined;
69
+ history?: A2AMessage[] | undefined;
70
+ metadata?: Record<string, unknown> | undefined;
71
+ };
72
+
73
+ // === Streaming Events ===
74
+ export type A2ATaskStatusUpdateEvent = {
75
+ taskId: string;
76
+ contextId: string; // REQUIRED per proto
77
+ status: A2ATaskStatus;
78
+ metadata?: Record<string, unknown> | undefined;
79
+ };
80
+
81
+ export type A2ATaskArtifactUpdateEvent = {
82
+ taskId: string;
83
+ contextId: string; // REQUIRED per proto
84
+ artifact: A2AArtifact;
85
+ append?: boolean | undefined;
86
+ lastChunk?: boolean | undefined;
87
+ metadata?: Record<string, unknown> | undefined;
88
+ };
89
+
90
+ export type A2AStreamEvent =
91
+ | { type: "task"; task: A2ATask }
92
+ | { type: "message"; message: A2AMessage }
93
+ | { type: "statusUpdate"; event: A2ATaskStatusUpdateEvent }
94
+ | { type: "artifactUpdate"; event: A2ATaskArtifactUpdateEvent };
95
+
96
+ // === Authentication ===
97
+ export type A2AAuthenticationInfo = {
98
+ scheme: string;
99
+ credentials?: string | undefined;
100
+ };
101
+
102
+ // === Push Notification Config ===
103
+ export type A2ATaskPushNotificationConfig = {
104
+ tenant?: string | undefined;
105
+ id?: string | undefined;
106
+ taskId?: string | undefined;
107
+ url: string;
108
+ token?: string | undefined;
109
+ authentication?: A2AAuthenticationInfo | undefined;
110
+ };
111
+
112
+ export type A2AListTaskPushNotificationConfigsResponse = {
113
+ configs: A2ATaskPushNotificationConfig[];
114
+ nextPageToken?: string | undefined;
115
+ };
116
+
117
+ // === Request/Response Types ===
118
+ export type A2ASendMessageConfiguration = {
119
+ acceptedOutputModes?: string[] | undefined;
120
+ taskPushNotificationConfig?: A2ATaskPushNotificationConfig | undefined;
121
+ historyLength?: number | undefined;
122
+ returnImmediately?: boolean | undefined;
123
+ };
124
+
125
+ export type A2AListTasksRequest = {
126
+ contextId?: string | undefined;
127
+ status?: A2ATaskState | undefined;
128
+ pageSize?: number | undefined;
129
+ pageToken?: string | undefined;
130
+ historyLength?: number | undefined;
131
+ statusTimestampAfter?: string | undefined; // ISO 8601
132
+ includeArtifacts?: boolean | undefined;
133
+ };
134
+
135
+ export type A2AListTasksResponse = {
136
+ tasks: A2ATask[];
137
+ nextPageToken: string;
138
+ pageSize: number;
139
+ totalSize: number;
140
+ };
141
+
142
+ // === Structured Error (google.rpc.Status) ===
143
+ export type A2AErrorInfo = {
144
+ code: number;
145
+ status: string;
146
+ message: string;
147
+ details?: unknown[] | undefined;
148
+ };
149
+
150
+ // === Security Schemes ===
151
+ export type A2AApiKeySecurityScheme = {
152
+ description?: string | undefined;
153
+ location: string; // "query" | "header" | "cookie"
28
154
  name: string;
29
- parts: A2AArtifactPart[];
30
155
  };
31
156
 
32
- export type A2AArtifactPart = {
33
- kind: "text" | "data" | "file";
34
- data?: any;
35
- text?: string;
36
- metadata?: Record<string, any>;
157
+ export type A2AHttpAuthSecurityScheme = {
158
+ description?: string | undefined;
159
+ scheme: string; // e.g. "Bearer"
160
+ bearerFormat?: string | undefined;
37
161
  };
38
162
 
39
- // A2A Events (similar to LangGraph events)
40
- export type A2AEvent = {
41
- event: A2AKnownEventTypes | string;
42
- data: any;
163
+ export type A2AAuthorizationCodeOAuthFlow = {
164
+ authorizationUrl: string;
165
+ tokenUrl: string;
166
+ refreshUrl?: string | undefined;
167
+ scopes: Record<string, string>;
168
+ pkceRequired?: boolean | undefined;
43
169
  };
44
170
 
45
- export enum A2AKnownEventTypes {
46
- TaskUpdate = "task-update",
47
- TaskComplete = "task-complete",
48
- TaskFailed = "task-failed",
49
- Artifacts = "artifacts",
50
- StateUpdate = "state-update",
51
- Error = "error",
52
- }
171
+ export type A2AClientCredentialsOAuthFlow = {
172
+ tokenUrl: string;
173
+ refreshUrl?: string | undefined;
174
+ scopes: Record<string, string>;
175
+ };
53
176
 
54
- // A2A Task State
55
- export type A2ATaskState = {
56
- id: string;
57
- state: "pending" | "working" | "completed" | "failed";
58
- progress?: number;
59
- message?: string;
177
+ export type A2ADeviceCodeOAuthFlow = {
178
+ deviceAuthorizationUrl: string;
179
+ tokenUrl: string;
180
+ refreshUrl?: string | undefined;
181
+ scopes: Record<string, string>;
182
+ };
183
+
184
+ /** @deprecated Use Authorization Code + PKCE instead. */
185
+ export type A2AImplicitOAuthFlow = {
186
+ authorizationUrl?: string | undefined;
187
+ refreshUrl?: string | undefined;
188
+ scopes?: Record<string, string> | undefined;
189
+ };
190
+
191
+ /** @deprecated Use Authorization Code + PKCE or Device Code. */
192
+ export type A2APasswordOAuthFlow = {
193
+ tokenUrl?: string | undefined;
194
+ refreshUrl?: string | undefined;
195
+ scopes?: Record<string, string> | undefined;
196
+ };
197
+
198
+ export type A2AOAuthFlows = {
199
+ authorizationCode?: A2AAuthorizationCodeOAuthFlow | undefined;
200
+ clientCredentials?: A2AClientCredentialsOAuthFlow | undefined;
201
+ /** @deprecated */
202
+ implicit?: A2AImplicitOAuthFlow | undefined;
203
+ /** @deprecated */
204
+ password?: A2APasswordOAuthFlow | undefined;
205
+ deviceCode?: A2ADeviceCodeOAuthFlow | undefined;
206
+ };
207
+
208
+ export type A2AOAuth2SecurityScheme = {
209
+ description?: string | undefined;
210
+ flows: A2AOAuthFlows;
211
+ oauth2MetadataUrl?: string | undefined;
212
+ };
213
+
214
+ export type A2AOpenIdConnectSecurityScheme = {
215
+ description?: string | undefined;
216
+ openIdConnectUrl: string;
217
+ };
218
+
219
+ export type A2AMutualTlsSecurityScheme = {
220
+ description?: string | undefined;
60
221
  };
61
222
 
62
- // A2A Task Result
63
- export type A2ATaskResult = {
223
+ export type A2ASecurityScheme = {
224
+ apiKeySecurityScheme?: A2AApiKeySecurityScheme | undefined;
225
+ httpAuthSecurityScheme?: A2AHttpAuthSecurityScheme | undefined;
226
+ oauth2SecurityScheme?: A2AOAuth2SecurityScheme | undefined;
227
+ openIdConnectSecurityScheme?: A2AOpenIdConnectSecurityScheme | undefined;
228
+ mtlsSecurityScheme?: A2AMutualTlsSecurityScheme | undefined;
229
+ };
230
+
231
+ export type A2ASecurityRequirement = {
232
+ schemes: Record<string, { list: string[] }>;
233
+ };
234
+
235
+ // === Agent Card Signature (JWS) ===
236
+ export type A2AAgentCardSignature = {
237
+ protected: string; // base64url-encoded JWS header
238
+ signature: string; // base64url-encoded signature
239
+ header?: Record<string, unknown> | undefined;
240
+ };
241
+
242
+ // === Agent Card ===
243
+ export type A2AAgentSkill = {
64
244
  id: string;
65
- status: {
66
- state: "pending" | "working" | "completed" | "failed";
67
- message?: string;
68
- };
69
- artifacts?: A2AArtifact[];
70
- history?: Array<{
71
- messageId: string;
72
- role: string;
73
- parts?: Array<{ kind: string; text?: string; data?: any }>;
74
- }>;
75
- };
76
-
77
- // A2A Configuration
78
- export type A2AConfig = {
79
- contextId?: string;
80
- runConfig?: Record<string, any>;
81
- };
82
-
83
- // A2A Send Message Configuration
84
- export type A2ASendMessageConfig = A2AConfig & {
85
- command?: A2ACommand;
86
- };
87
-
88
- // A2A Commands (for interrupts/resume)
89
- export type A2ACommand = {
90
- resume?: string;
91
- interrupt?: string;
92
- };
93
-
94
- // A2A Stream Callback
95
- export type A2AStreamCallback<TMessage> = (
96
- messages: TMessage[],
97
- config: A2ASendMessageConfig & { abortSignal: AbortSignal },
98
- ) => Promise<AsyncGenerator<A2AEvent>> | AsyncGenerator<A2AEvent>;
99
-
100
- // Event handler callback types
101
- export type OnTaskUpdateEventCallback = (
102
- data: A2ATaskState,
103
- ) => void | Promise<void>;
104
- export type OnArtifactsEventCallback = (
105
- artifacts: A2AArtifact[],
106
- ) => void | Promise<void>;
107
- export type OnErrorEventCallback = (error: unknown) => void | Promise<void>;
108
- export type OnStateUpdateEventCallback = (
109
- state: unknown,
110
- ) => void | Promise<void>;
111
- export type OnCustomEventCallback = (
112
- type: string,
113
- data: unknown,
114
- ) => void | Promise<void>;
245
+ name: string;
246
+ description: string;
247
+ tags: string[];
248
+ examples?: string[] | undefined;
249
+ inputModes?: string[] | undefined;
250
+ outputModes?: string[] | undefined;
251
+ securityRequirements?: A2ASecurityRequirement[] | undefined;
252
+ };
253
+
254
+ export type A2AAgentCapabilities = {
255
+ streaming?: boolean | undefined;
256
+ pushNotifications?: boolean | undefined;
257
+ extensions?:
258
+ | Array<{
259
+ uri: string;
260
+ description?: string | undefined;
261
+ required?: boolean | undefined;
262
+ params?: Record<string, unknown> | undefined;
263
+ }>
264
+ | undefined;
265
+ extendedAgentCard?: boolean | undefined;
266
+ };
267
+
268
+ export type A2AAgentInterface = {
269
+ url: string;
270
+ protocolBinding: string;
271
+ protocolVersion: string;
272
+ tenant?: string | undefined;
273
+ };
274
+
275
+ export type A2AAgentCard = {
276
+ name: string;
277
+ description: string;
278
+ supportedInterfaces: A2AAgentInterface[]; // REQUIRED per proto
279
+ provider?:
280
+ | {
281
+ organization: string;
282
+ url: string;
283
+ }
284
+ | undefined;
285
+ version: string;
286
+ documentationUrl?: string | undefined;
287
+ capabilities: A2AAgentCapabilities;
288
+ securitySchemes?: Record<string, A2ASecurityScheme> | undefined;
289
+ securityRequirements?: A2ASecurityRequirement[] | undefined;
290
+ defaultInputModes: string[];
291
+ defaultOutputModes: string[];
292
+ skills: A2AAgentSkill[];
293
+ signatures?: A2AAgentCardSignature[] | undefined;
294
+ iconUrl?: string | undefined;
295
+ };