@assistant-ui/react-a2a 0.2.20 → 0.2.22

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.
@@ -9,116 +9,13 @@ import {
9
9
  import type {
10
10
  AssistantRuntime,
11
11
  AppendMessage,
12
- AttachmentAdapter,
13
- DictationAdapter,
14
12
  ExternalStoreAdapter,
15
- ExternalStoreSharedOptions,
16
- FeedbackAdapter,
17
- RealtimeVoiceAdapter,
18
- SpeechSynthesisAdapter,
19
- ThreadHistoryAdapter,
20
13
  ThreadMessage,
21
14
  } from "@assistant-ui/core";
22
- import { useAuiState } from "@assistant-ui/store";
23
15
  import { A2AClient } from "./A2AClient";
24
- import type { A2AClientOptions } from "./A2AClient";
25
16
  import { A2AThreadRuntimeCore } from "./A2AThreadRuntimeCore";
26
- import type {
27
- A2AArtifact,
28
- A2AAgentCard,
29
- A2ASendMessageConfiguration,
30
- A2ATask,
31
- } from "./types";
32
-
33
- // --- Extras symbol for A2A-specific state ---
34
-
35
- const symbolA2AExtras = Symbol("a2a-extras");
36
-
37
- type A2AExtras = {
38
- [symbolA2AExtras]: true;
39
- task: A2ATask | undefined;
40
- artifacts: readonly A2AArtifact[];
41
- agentCard: A2AAgentCard | undefined;
42
- };
43
-
44
- const asA2AExtras = (extras: unknown): A2AExtras => {
45
- if (
46
- typeof extras !== "object" ||
47
- extras == null ||
48
- !(symbolA2AExtras in extras)
49
- )
50
- throw new Error(
51
- "This hook can only be used inside a useA2ARuntime provider",
52
- );
53
- return extras as A2AExtras;
54
- };
55
-
56
- // --- Public hooks for A2A state ---
57
-
58
- export const useA2ATask = () => {
59
- return useAuiState((s) => asA2AExtras(s.thread.extras).task);
60
- };
61
-
62
- export const useA2AArtifacts = () => {
63
- return useAuiState((s) => asA2AExtras(s.thread.extras).artifacts);
64
- };
65
-
66
- export const useA2AAgentCard = () => {
67
- return useAuiState((s) => asA2AExtras(s.thread.extras).agentCard);
68
- };
69
-
70
- // --- Thread list adapter type ---
71
-
72
- export type UseA2AThreadListAdapter = {
73
- threadId?: string;
74
- onSwitchToNewThread?: () => Promise<void> | void;
75
- onSwitchToThread?: (threadId: string) => Promise<{
76
- messages: readonly ThreadMessage[];
77
- }>;
78
- };
79
-
80
- // --- Options ---
81
-
82
- export type UseA2ARuntimeOptions = ExternalStoreSharedOptions & {
83
- /** Pre-built A2A client instance. Provide this OR baseUrl. */
84
- client?: A2AClient;
85
- /** Base URL of the A2A server. Used to create a client if `client` is not provided. */
86
- baseUrl?: string;
87
- /** Optional path prefix for all API endpoints (e.g. "/v1"). Does not affect agent card discovery. Only used with baseUrl. */
88
- basePath?: string;
89
- /** Optional tenant ID for multi-tenant servers. Only used with baseUrl. */
90
- tenant?: string;
91
- /** Headers for the A2A client (only used with baseUrl). */
92
- headers?: A2AClientOptions["headers"];
93
- /** A2A extension URIs to negotiate. Only used with baseUrl. */
94
- extensions?: string[];
95
- /** Extra fetch options (e.g. `{ credentials: 'include' }`). Only used with `baseUrl`. */
96
- fetchOptions?: A2AClientOptions["fetchOptions"];
97
-
98
- /** Initial context ID for the conversation. */
99
- contextId?: string;
100
- /** Default send message configuration. */
101
- configuration?: A2ASendMessageConfiguration;
102
-
103
- /** Called when an error occurs. */
104
- onError?: (error: Error) => void;
105
- /** Called when a run is cancelled. */
106
- onCancel?: () => void;
107
- /** Called when an artifact is fully received (lastChunk). */
108
- onArtifactComplete?: (artifact: import("./types").A2AArtifact) => void;
109
-
110
- adapters?: {
111
- attachments?: AttachmentAdapter;
112
- speech?: SpeechSynthesisAdapter;
113
- dictation?: DictationAdapter;
114
- voice?: RealtimeVoiceAdapter;
115
- feedback?: FeedbackAdapter;
116
- history?: ThreadHistoryAdapter;
117
- threadList?: UseA2AThreadListAdapter;
118
- };
119
- };
120
-
121
- // --- Main hook ---
17
+ import { a2aExtras } from "./a2aExtras";
18
+ import type { UseA2ARuntimeOptions } from "./types";
122
19
 
123
20
  export function useA2ARuntime(options: UseA2ARuntimeOptions): AssistantRuntime {
124
21
  const [_version, setVersion] = useState(0);
@@ -224,12 +121,11 @@ export function useA2ARuntime(options: UseA2ARuntimeOptions): AssistantRuntime {
224
121
  isLoading: core.isLoading,
225
122
  messages: core.getMessages(),
226
123
  isRunning: core.isRunning(),
227
- extras: {
228
- [symbolA2AExtras]: true,
124
+ extras: a2aExtras.provide({
229
125
  task: core.getTask(),
230
126
  artifacts: core.getArtifacts(),
231
127
  agentCard: core.getAgentCard(),
232
- } satisfies A2AExtras,
128
+ }),
233
129
  onNew: (message: AppendMessage) => core.append(message),
234
130
  onEdit: (message: AppendMessage) => core.edit(message),
235
131
  onReload: (parentId: string | null) => core.reload(parentId),