@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
@@ -1,330 +1,238 @@
1
- import { useEffect, useRef, useState } from "react";
1
+ /// <reference types="@assistant-ui/core/store" />
2
+ "use client";
3
+
4
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2
5
  import {
3
- A2AMessage,
4
- A2AToolCall,
6
+ useExternalStoreRuntime,
7
+ useRuntimeAdapters,
8
+ } from "@assistant-ui/core/react";
9
+ import type {
10
+ AssistantRuntime,
11
+ AppendMessage,
12
+ AttachmentAdapter,
13
+ ExternalStoreAdapter,
14
+ FeedbackAdapter,
15
+ SpeechSynthesisAdapter,
16
+ ThreadHistoryAdapter,
17
+ ThreadMessage,
18
+ } from "@assistant-ui/core";
19
+ import { useAuiState } from "@assistant-ui/store";
20
+ import { A2AClient } from "./A2AClient";
21
+ import type { A2AClientOptions } from "./A2AClient";
22
+ import { A2AThreadRuntimeCore } from "./A2AThreadRuntimeCore";
23
+ import type {
5
24
  A2AArtifact,
6
- A2ATaskState,
7
- A2ASendMessageConfig,
8
- A2AStreamCallback,
9
- OnTaskUpdateEventCallback,
10
- OnArtifactsEventCallback,
11
- OnErrorEventCallback,
12
- OnStateUpdateEventCallback,
13
- OnCustomEventCallback,
25
+ A2AAgentCard,
26
+ A2ASendMessageConfiguration,
27
+ A2ATask,
14
28
  } from "./types";
15
- import {
16
- useExternalMessageConverter,
17
- useExternalStoreRuntime,
18
- useThread,
19
- useThreadListItemRuntime,
20
- } from "@assistant-ui/react";
21
- import { convertA2AMessage } from "./convertA2AMessages";
22
- import { useA2AMessages } from "./useA2AMessages";
23
- import { AttachmentAdapter } from "@assistant-ui/react";
24
- import { AppendMessage } from "@assistant-ui/react";
25
- import { ExternalStoreAdapter } from "@assistant-ui/react";
26
- import { FeedbackAdapter } from "@assistant-ui/react";
27
- import { SpeechSynthesisAdapter } from "@assistant-ui/react";
28
- import { appendA2AChunk } from "./appendA2AChunk";
29
-
30
- const getPendingToolCalls = (messages: A2AMessage[]) => {
31
- const pendingToolCalls = new Map<string, A2AToolCall>();
32
- for (const message of messages) {
33
- if (message.role === "assistant") {
34
- for (const toolCall of message.tool_calls ?? []) {
35
- pendingToolCalls.set(toolCall.id, toolCall);
36
- }
37
- }
38
- if (message.role === "tool") {
39
- pendingToolCalls.delete(message.tool_call_id!);
40
- }
41
- }
42
-
43
- return [...pendingToolCalls.values()];
44
- };
45
29
 
46
- const getMessageContent = (msg: AppendMessage) => {
47
- const allContent = [
48
- ...msg.content,
49
- ...(msg.attachments?.flatMap((a) => a.content) ?? []),
50
- ];
51
- const content = allContent.map((part) => {
52
- const type = part.type;
53
- switch (type) {
54
- case "text":
55
- return { type: "text" as const, text: part.text };
56
- case "image":
57
- return { type: "image_url" as const, image_url: { url: part.image } };
30
+ // --- Extras symbol for A2A-specific state ---
58
31
 
59
- case "tool-call":
60
- throw new Error("Tool call appends are not supported.");
32
+ const symbolA2AExtras = Symbol("a2a-extras");
61
33
 
62
- default:
63
- const _exhaustiveCheck:
64
- | "reasoning"
65
- | "source"
66
- | "file"
67
- | "audio"
68
- | "data" = type;
69
- throw new Error(
70
- `Unsupported append message part type: ${_exhaustiveCheck}`,
71
- );
72
- }
73
- });
74
-
75
- if (content.length === 1 && content[0]?.type === "text") {
76
- return content[0].text ?? "";
77
- }
78
-
79
- return content;
34
+ type A2AExtras = {
35
+ [symbolA2AExtras]: true;
36
+ task: A2ATask | undefined;
37
+ artifacts: readonly A2AArtifact[];
38
+ agentCard: A2AAgentCard | undefined;
80
39
  };
81
40
 
82
- const symbolA2ARuntimeExtras = Symbol("a2a-runtime-extras");
83
- type A2ARuntimeExtras = {
84
- [symbolA2ARuntimeExtras]: true;
85
- send: (messages: A2AMessage[], config: A2ASendMessageConfig) => Promise<void>;
86
- taskState: A2ATaskState | undefined;
87
- artifacts: A2AArtifact[];
88
- };
89
-
90
- const asA2ARuntimeExtras = (extras: unknown): A2ARuntimeExtras => {
41
+ const asA2AExtras = (extras: unknown): A2AExtras => {
91
42
  if (
92
43
  typeof extras !== "object" ||
93
44
  extras == null ||
94
- !(symbolA2ARuntimeExtras in extras)
45
+ !(symbolA2AExtras in extras)
95
46
  )
96
47
  throw new Error(
97
- "This method can only be called when you are using useA2ARuntime",
48
+ "This hook can only be used inside a useA2ARuntime provider",
98
49
  );
99
-
100
- return extras as A2ARuntimeExtras;
50
+ return extras as A2AExtras;
101
51
  };
102
52
 
103
- export const useA2ATaskState = () => {
104
- const { taskState } = useThread((t) => asA2ARuntimeExtras(t.extras));
105
- return taskState;
53
+ // --- Public hooks for A2A state ---
54
+
55
+ export const useA2ATask = () => {
56
+ return useAuiState((s) => asA2AExtras(s.thread.extras).task);
106
57
  };
107
58
 
108
59
  export const useA2AArtifacts = () => {
109
- const { artifacts } = useThread((t) => asA2ARuntimeExtras(t.extras));
110
- return artifacts;
60
+ return useAuiState((s) => asA2AExtras(s.thread.extras).artifacts);
111
61
  };
112
62
 
113
- export const useA2ASend = () => {
114
- const { send } = useThread((t) => asA2ARuntimeExtras(t.extras));
115
- return send;
63
+ export const useA2AAgentCard = () => {
64
+ return useAuiState((s) => asA2AExtras(s.thread.extras).agentCard);
116
65
  };
117
66
 
118
- export const useA2ARuntime = ({
119
- autoCancelPendingToolCalls,
120
- adapters: { attachments, feedback, speech } = {},
121
- unstable_allowCancellation,
122
- stream,
123
- contextId,
124
- onSwitchToNewThread,
125
- onSwitchToThread,
126
- eventHandlers,
127
- }: {
128
- /**
129
- * @deprecated For thread management use `useCloudThreadListRuntime` instead. This option will be removed in a future version.
130
- */
131
- contextId?: string | undefined;
132
- autoCancelPendingToolCalls?: boolean | undefined;
133
- unstable_allowCancellation?: boolean | undefined;
134
- stream: A2AStreamCallback<A2AMessage>;
135
- /**
136
- * @deprecated For thread management use `useCloudThreadListRuntime` instead. This option will be removed in a future version.
137
- */
67
+ // --- Thread list adapter type ---
68
+
69
+ export type UseA2AThreadListAdapter = {
70
+ threadId?: string;
138
71
  onSwitchToNewThread?: () => Promise<void> | void;
139
- onSwitchToThread?: (contextId: string) => Promise<{
140
- messages: A2AMessage[];
141
- artifacts?: A2AArtifact[];
72
+ onSwitchToThread?: (threadId: string) => Promise<{
73
+ messages: readonly ThreadMessage[];
142
74
  }>;
143
- adapters?:
144
- | {
145
- attachments?: AttachmentAdapter;
146
- speech?: SpeechSynthesisAdapter;
147
- feedback?: FeedbackAdapter;
148
- }
149
- | undefined;
150
- /**
151
- * Event handlers for various A2A stream events
152
- */
153
- eventHandlers?:
154
- | {
155
- /**
156
- * Called when task updates are received from the A2A stream
157
- */
158
- onTaskUpdate?: OnTaskUpdateEventCallback;
159
- /**
160
- * Called when artifacts are received from the A2A stream
161
- */
162
- onArtifacts?: OnArtifactsEventCallback;
163
- /**
164
- * Called when errors occur during A2A stream processing
165
- */
166
- onError?: OnErrorEventCallback;
167
- /**
168
- * Called when state updates are received from the A2A stream
169
- */
170
- onStateUpdate?: OnStateUpdateEventCallback;
171
- /**
172
- * Called when custom events are received from the A2A stream
173
- */
174
- onCustomEvent?: OnCustomEventCallback;
175
- }
176
- | undefined;
177
- }) => {
178
- const {
179
- taskState,
180
- artifacts,
181
- setArtifacts,
182
- messages,
183
- sendMessage,
184
- cancel,
185
- setMessages,
186
- } = useA2AMessages({
187
- appendMessage: appendA2AChunk,
188
- stream,
189
- ...(eventHandlers && { eventHandlers }),
190
- });
75
+ };
191
76
 
192
- const [isRunning, setIsRunning] = useState(false);
193
- const handleSendMessage = async (
194
- messages: A2AMessage[],
195
- config: A2ASendMessageConfig,
196
- ) => {
197
- try {
198
- setIsRunning(true);
199
- await sendMessage(messages, config);
200
- } catch (error) {
201
- console.error("Error streaming A2A messages:", error);
202
- } finally {
203
- setIsRunning(false);
204
- }
77
+ // --- Options ---
78
+
79
+ export type UseA2ARuntimeOptions = {
80
+ /** Pre-built A2A client instance. Provide this OR baseUrl. */
81
+ client?: A2AClient;
82
+ /** Base URL of the A2A server. Used to create a client if `client` is not provided. */
83
+ baseUrl?: string;
84
+ /** Headers for the A2A client (only used with baseUrl). */
85
+ headers?: A2AClientOptions["headers"];
86
+
87
+ /** Initial context ID for the conversation. */
88
+ contextId?: string;
89
+ /** Default send message configuration. */
90
+ configuration?: A2ASendMessageConfiguration;
91
+
92
+ /** Called when an error occurs. */
93
+ onError?: (error: Error) => void;
94
+ /** Called when a run is cancelled. */
95
+ onCancel?: () => void;
96
+ /** Called when an artifact is fully received (lastChunk). */
97
+ onArtifactComplete?: (artifact: import("./types").A2AArtifact) => void;
98
+
99
+ adapters?: {
100
+ attachments?: AttachmentAdapter;
101
+ speech?: SpeechSynthesisAdapter;
102
+ feedback?: FeedbackAdapter;
103
+ history?: ThreadHistoryAdapter;
104
+ threadList?: UseA2AThreadListAdapter;
205
105
  };
106
+ };
206
107
 
207
- const threadMessages = useExternalMessageConverter({
208
- callback: convertA2AMessage,
209
- messages,
210
- isRunning,
211
- });
108
+ // --- Main hook ---
109
+
110
+ export function useA2ARuntime(options: UseA2ARuntimeOptions): AssistantRuntime {
111
+ const [_version, setVersion] = useState(0);
112
+ const notifyUpdate = useCallback(() => setVersion((v) => v + 1), []);
113
+ const runtimeAdapters = useRuntimeAdapters();
114
+ const historyAdapter = options.adapters?.history ?? runtimeAdapters?.history;
115
+ const threadListAdapter = options.adapters?.threadList;
116
+
117
+ // Create or reuse client
118
+ const clientRef = useRef<A2AClient | null>(null);
119
+ if (!clientRef.current) {
120
+ if (options.client) {
121
+ clientRef.current = options.client;
122
+ } else if (options.baseUrl) {
123
+ clientRef.current = new A2AClient({
124
+ baseUrl: options.baseUrl,
125
+ headers: options.headers,
126
+ });
127
+ } else {
128
+ throw new Error("useA2ARuntime requires either `client` or `baseUrl`");
129
+ }
130
+ }
131
+ const client = clientRef.current;
132
+
133
+ // Create or reuse core
134
+ const coreRef = useRef<A2AThreadRuntimeCore | null>(null);
135
+ if (!coreRef.current) {
136
+ coreRef.current = new A2AThreadRuntimeCore({
137
+ client,
138
+ contextId: options.contextId,
139
+ configuration: options.configuration,
140
+ ...(options.onError && { onError: options.onError }),
141
+ ...(options.onCancel && { onCancel: options.onCancel }),
142
+ ...(options.onArtifactComplete && {
143
+ onArtifactComplete: options.onArtifactComplete,
144
+ }),
145
+ ...(historyAdapter && { history: historyAdapter }),
146
+ notifyUpdate,
147
+ });
148
+ }
212
149
 
213
- const switchToThread = !onSwitchToThread
214
- ? undefined
215
- : async (externalId: string) => {
216
- const { messages, artifacts } = await onSwitchToThread(externalId);
217
- setMessages(messages);
218
- if (artifacts) {
219
- setArtifacts(artifacts);
220
- }
221
- };
150
+ const core = coreRef.current;
151
+ core.updateOptions({
152
+ client,
153
+ contextId: options.contextId,
154
+ configuration: options.configuration,
155
+ ...(options.onError && { onError: options.onError }),
156
+ ...(options.onCancel && { onCancel: options.onCancel }),
157
+ ...(options.onArtifactComplete && {
158
+ onArtifactComplete: options.onArtifactComplete,
159
+ }),
160
+ ...(historyAdapter && { history: historyAdapter }),
161
+ });
222
162
 
223
- const threadList: NonNullable<
224
- ExternalStoreAdapter["adapters"]
225
- >["threadList"] = {
226
- threadId: contextId,
227
- onSwitchToNewThread: !onSwitchToNewThread
228
- ? undefined
229
- : async () => {
230
- await onSwitchToNewThread();
231
- setMessages([]);
232
- setArtifacts([]);
233
- },
234
- onSwitchToThread: switchToThread,
235
- };
163
+ // Thread list
164
+ const threadList = useMemo(() => {
165
+ if (!threadListAdapter) return undefined;
166
+
167
+ const { onSwitchToNewThread, onSwitchToThread } = threadListAdapter;
168
+
169
+ return {
170
+ threadId: threadListAdapter.threadId,
171
+ onSwitchToNewThread: onSwitchToNewThread
172
+ ? async () => {
173
+ await onSwitchToNewThread();
174
+ core.applyExternalMessages([]);
175
+ }
176
+ : undefined,
177
+ onSwitchToThread: onSwitchToThread
178
+ ? async (threadId: string) => {
179
+ const result = await onSwitchToThread(threadId);
180
+ core.applyExternalMessages(result.messages);
181
+ }
182
+ : undefined,
183
+ };
184
+ }, [threadListAdapter, core]);
185
+
186
+ // Adapters
187
+ const adapters = options.adapters;
188
+ const adapterAdapters = useMemo(
189
+ () => ({
190
+ attachments: adapters?.attachments ?? runtimeAdapters?.attachments,
191
+ speech: adapters?.speech,
192
+ feedback: adapters?.feedback,
193
+ threadList,
194
+ }),
195
+ [adapters, runtimeAdapters, threadList],
196
+ );
197
+
198
+ // Build store adapter
199
+ const store = useMemo(() => {
200
+ void _version;
201
+
202
+ return {
203
+ isLoading: core.isLoading,
204
+ messages: core.getMessages(),
205
+ isRunning: core.isRunning(),
206
+ extras: {
207
+ [symbolA2AExtras]: true,
208
+ task: core.getTask(),
209
+ artifacts: core.getArtifacts(),
210
+ agentCard: core.getAgentCard(),
211
+ } satisfies A2AExtras,
212
+ onNew: (message: AppendMessage) => core.append(message),
213
+ onEdit: (message: AppendMessage) => core.edit(message),
214
+ onReload: (parentId: string | null) => core.reload(parentId),
215
+ onCancel: () => core.cancel(),
216
+ setMessages: (messages: readonly ThreadMessage[]) =>
217
+ core.applyExternalMessages(messages),
218
+ onImport: (messages: readonly ThreadMessage[]) =>
219
+ core.applyExternalMessages(messages),
220
+ adapters: adapterAdapters,
221
+ } satisfies ExternalStoreAdapter<ThreadMessage>;
222
+ }, [adapterAdapters, core, _version]);
223
+
224
+ const runtime = useExternalStoreRuntime(store);
236
225
 
237
- const loadingRef = useRef(false);
238
- const threadListItemRuntime = useThreadListItemRuntime({ optional: true });
239
226
  useEffect(() => {
240
- if (!threadListItemRuntime || !switchToThread || loadingRef.current) return;
241
-
242
- const externalId = threadListItemRuntime.getState().externalId;
243
- if (externalId) {
244
- loadingRef.current = true;
245
- switchToThread(externalId).finally(() => {
246
- loadingRef.current = false;
247
- });
248
- }
249
- }, [switchToThread, threadListItemRuntime]);
227
+ core.attachRuntime(runtime);
228
+ return () => {
229
+ core.detachRuntime();
230
+ };
231
+ }, [core, runtime]);
250
232
 
251
- return useExternalStoreRuntime({
252
- isRunning,
253
- messages: threadMessages,
254
- adapters: {
255
- attachments,
256
- feedback,
257
- speech,
258
- threadList,
259
- },
260
- extras: {
261
- [symbolA2ARuntimeExtras]: true,
262
- taskState,
263
- artifacts,
264
- send: handleSendMessage,
265
- } satisfies A2ARuntimeExtras,
266
- onNew: (msg) => {
267
- const cancellations =
268
- autoCancelPendingToolCalls !== false
269
- ? getPendingToolCalls(messages).map(
270
- (t) =>
271
- ({
272
- role: "tool",
273
- tool_call_id: t.id,
274
- content: JSON.stringify({ cancelled: true }),
275
- status: {
276
- type: "incomplete",
277
- reason: "cancelled",
278
- },
279
- }) satisfies A2AMessage & { role: "tool" },
280
- )
281
- : [];
233
+ useEffect(() => {
234
+ core.__internal_load();
235
+ }, [core]);
282
236
 
283
- const config: A2ASendMessageConfig = {};
284
- if (contextId !== undefined) config.contextId = contextId;
285
- if (msg.runConfig !== undefined) config.runConfig = msg.runConfig;
286
- return handleSendMessage(
287
- [
288
- ...cancellations,
289
- {
290
- role: "user",
291
- content: getMessageContent(msg),
292
- },
293
- ],
294
- config,
295
- );
296
- },
297
- onAddToolResult: async ({
298
- toolCallId,
299
- toolName: _toolName,
300
- result,
301
- isError,
302
- artifact,
303
- }) => {
304
- // TODO parallel human in the loop calls
305
- const message: A2AMessage = {
306
- role: "tool",
307
- tool_call_id: toolCallId,
308
- content: JSON.stringify(result),
309
- status: isError
310
- ? { type: "incomplete", reason: "error" }
311
- : { type: "complete", reason: "stop" },
312
- };
313
- if (artifact) {
314
- message.artifacts = [artifact] as A2AArtifact[];
315
- }
316
- const config: A2ASendMessageConfig = {};
317
- if (contextId !== undefined) config.contextId = contextId;
318
- await handleSendMessage(
319
- [message],
320
- // TODO reuse runconfig here!
321
- config,
322
- );
323
- },
324
- onCancel: unstable_allowCancellation
325
- ? async () => {
326
- cancel();
327
- }
328
- : undefined,
329
- });
330
- };
237
+ return runtime;
238
+ }
@@ -1,16 +0,0 @@
1
- export type A2AStateAccumulatorConfig<TMessage> = {
2
- initialMessages?: TMessage[];
3
- appendMessage?: (prev: TMessage | undefined, curr: TMessage) => TMessage;
4
- };
5
- export declare class A2AMessageAccumulator<TMessage extends {
6
- id?: string;
7
- }> {
8
- private messagesMap;
9
- private appendMessage;
10
- constructor({ initialMessages, appendMessage, }?: A2AStateAccumulatorConfig<TMessage>);
11
- private ensureMessageId;
12
- addMessages(newMessages: TMessage[]): TMessage[];
13
- getMessages(): TMessage[];
14
- clear(): void;
15
- }
16
- //# sourceMappingURL=A2AMessageAccumulator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"A2AMessageAccumulator.d.ts","sourceRoot":"","sources":["../src/A2AMessageAccumulator.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,yBAAyB,CAAC,QAAQ,IAAI;IAChD,eAAe,CAAC,EAAE,QAAQ,EAAE,CAAC;IAC7B,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,EAAE,IAAI,EAAE,QAAQ,KAAK,QAAQ,CAAC;CAC1E,CAAC;AAEF,qBAAa,qBAAqB,CAAC,QAAQ,SAAS;IAAE,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE;IACjE,OAAO,CAAC,WAAW,CAA+B;IAClD,OAAO,CAAC,aAAa,CAGP;gBAEF,EACV,eAAoB,EACpB,aAGa,GACd,GAAE,yBAAyB,CAAC,QAAQ,CAAM;IAK3C,OAAO,CAAC,eAAe;IAIhB,WAAW,CAAC,WAAW,EAAE,QAAQ,EAAE;IAWnC,WAAW,IAAI,QAAQ,EAAE;IAIzB,KAAK;CAGb"}
@@ -1,29 +0,0 @@
1
- import { v4 as uuidv4 } from "uuid";
2
- export class A2AMessageAccumulator {
3
- messagesMap = new Map();
4
- appendMessage;
5
- constructor({ initialMessages = [], appendMessage = ((_, curr) => curr), } = {}) {
6
- this.appendMessage = appendMessage;
7
- this.addMessages(initialMessages);
8
- }
9
- ensureMessageId(message) {
10
- return message.id ? message : { ...message, id: uuidv4() };
11
- }
12
- addMessages(newMessages) {
13
- if (newMessages.length === 0)
14
- return this.getMessages();
15
- for (const message of newMessages.map(this.ensureMessageId)) {
16
- const messageId = message.id; // ensureMessageId guarantees id exists
17
- const previous = this.messagesMap.get(messageId);
18
- this.messagesMap.set(messageId, this.appendMessage(previous, message));
19
- }
20
- return this.getMessages();
21
- }
22
- getMessages() {
23
- return [...this.messagesMap.values()];
24
- }
25
- clear() {
26
- this.messagesMap.clear();
27
- }
28
- }
29
- //# sourceMappingURL=A2AMessageAccumulator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"A2AMessageAccumulator.js","sourceRoot":"","sources":["../src/A2AMessageAccumulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAOpC,MAAM,OAAO,qBAAqB;IACxB,WAAW,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC1C,aAAa,CAGP;IAEd,YAAY,EACV,eAAe,GAAG,EAAE,EACpB,aAAa,GAAG,CAAC,CAAC,CAAuB,EAAE,IAAc,EAAE,EAAE,CAAC,IAAI,CAGrD,MAC0B,EAAE;QACzC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;IACpC,CAAC;IAEO,eAAe,CAAC,OAAiB;QACvC,OAAO,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC;IAC7D,CAAC;IAEM,WAAW,CAAC,WAAuB;QACxC,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;QAExD,KAAK,MAAM,OAAO,IAAI,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC;YAC5D,MAAM,SAAS,GAAG,OAAO,CAAC,EAAG,CAAC,CAAC,uCAAuC;YACtE,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YACjD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;QACzE,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAEM,WAAW;QAChB,OAAO,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;IACxC,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;CACF"}
@@ -1,3 +0,0 @@
1
- import { A2AMessage } from "./types.js";
2
- export declare const appendA2AChunk: (prev: A2AMessage | undefined, curr: A2AMessage) => A2AMessage;
3
- //# sourceMappingURL=appendA2AChunk.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"appendA2AChunk.d.ts","sourceRoot":"","sources":["../src/appendA2AChunk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,mBAAgB;AAGrC,eAAO,MAAM,cAAc,GACzB,MAAM,UAAU,GAAG,SAAS,EAC5B,MAAM,UAAU,KACf,UAkHF,CAAC"}