@assistant-ui/react-statewire 0.4.3 → 0.5.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.
Files changed (49) hide show
  1. package/dist/AssistantTransportThread.d.ts +193 -4
  2. package/dist/AssistantTransportThread.d.ts.map +1 -1
  3. package/dist/AssistantTransportThread.js +12 -16
  4. package/dist/AssistantTransportThread.js.map +1 -1
  5. package/dist/StatewireThread.d.ts +92 -11
  6. package/dist/StatewireThread.d.ts.map +1 -1
  7. package/dist/StatewireThread.js +74 -45
  8. package/dist/StatewireThread.js.map +1 -1
  9. package/dist/hooks.d.ts +8 -3
  10. package/dist/hooks.d.ts.map +1 -1
  11. package/dist/hooks.js +10 -1
  12. package/dist/hooks.js.map +1 -1
  13. package/dist/host.d.ts +5 -5
  14. package/dist/host.d.ts.map +1 -1
  15. package/dist/host.js.map +1 -1
  16. package/dist/index.d.ts +3 -38
  17. package/dist/index.js +2 -2
  18. package/dist/inputRequests.d.ts +4 -4
  19. package/dist/inputRequests.d.ts.map +1 -1
  20. package/dist/inputRequests.js.map +1 -1
  21. package/dist/runCommands.d.ts +8 -7
  22. package/dist/runCommands.d.ts.map +1 -1
  23. package/dist/runCommands.js +25 -11
  24. package/dist/runCommands.js.map +1 -1
  25. package/dist/runsOptimistic.d.ts +7 -0
  26. package/dist/runsOptimistic.d.ts.map +1 -0
  27. package/dist/runsOptimistic.js +92 -0
  28. package/dist/runsOptimistic.js.map +1 -0
  29. package/package.json +3 -3
  30. package/src/AssistantTransportThread.ts +267 -24
  31. package/src/StatewireThread.runs.test.tsx +405 -0
  32. package/src/StatewireThread.test.tsx +180 -3
  33. package/src/StatewireThread.ts +223 -80
  34. package/src/__tests__/testHelpers.tsx +11 -17
  35. package/src/athena.e2e.test.tsx +15 -19
  36. package/src/hooks.ts +19 -2
  37. package/src/host.ts +11 -13
  38. package/src/index.ts +2 -36
  39. package/src/inputRequests.ts +8 -6
  40. package/src/legacy-diff.test.tsx +4 -7
  41. package/src/runCommands.ts +42 -28
  42. package/src/runsOptimistic.test.ts +225 -0
  43. package/src/runsOptimistic.ts +164 -0
  44. package/src/transport.test.tsx +12 -16
  45. package/dist/index.d.ts.map +0 -1
  46. package/dist/types.d.ts +0 -189
  47. package/dist/types.d.ts.map +0 -1
  48. package/dist/types.js +0 -0
  49. package/src/types.ts +0 -255
package/src/types.ts DELETED
@@ -1,255 +0,0 @@
1
- import type { ReadonlyJSONValue } from "assistant-stream/utils";
2
- import type {
3
- AttachmentAdapter,
4
- ThreadMessage,
5
- ToolExecutionStatus,
6
- LanguageModelV1CallSettings,
7
- LanguageModelConfig,
8
- } from "@assistant-ui/core";
9
- import type { Assistant } from "@assistant-ui/react";
10
-
11
- export type UserCommands = Assistant.Commands[keyof Assistant.Commands];
12
- export type UserExternalState = keyof Assistant.ExternalState extends never
13
- ? Record<string, unknown>
14
- : Assistant.ExternalState[keyof Assistant.ExternalState];
15
-
16
- export type TextPart = {
17
- readonly type: "text";
18
- readonly text: string;
19
- };
20
-
21
- export type FilePart = {
22
- readonly type: "file";
23
- readonly mediaType: string;
24
- readonly url: string;
25
- readonly filename?: string;
26
- };
27
-
28
- export type RunUserMessage = {
29
- readonly id: string;
30
- readonly role: "user";
31
- readonly parts: readonly (TextPart | FilePart)[];
32
- readonly metadata?: Record<string, unknown>;
33
- };
34
-
35
- /** Queue placement fields, flat on the command. Absent is load-bearing: it means default placement; `null` names a queue boundary. */
36
- export type RunPlacement = {
37
- readonly insertAfter?: string | null;
38
- readonly insertBefore?: string | null;
39
- };
40
-
41
- export type RunEnqueueCommand = {
42
- readonly type: "run/enqueue";
43
- } & (
44
- | {
45
- readonly message: RunUserMessage;
46
- /** Branch anchor: the newest message the client knows on its intended branch, null asserting an empty thread. Required on adds; optional on edits of queued items. */
47
- readonly anchorMessageId?: string | null;
48
- }
49
- | { readonly messageId: string }
50
- ) &
51
- RunPlacement;
52
-
53
- export type RunSteerCommand = {
54
- readonly type: "run/steer";
55
- } & (
56
- | {
57
- readonly message: RunUserMessage;
58
- /** Branch anchor: the newest message the client knows on its intended branch, null asserting an empty thread. Required on adds; optional on edits of queued items. */
59
- readonly anchorMessageId?: string | null;
60
- }
61
- | { readonly messageId: string }
62
- ) &
63
- RunPlacement;
64
-
65
- export type RunDequeueCommand = {
66
- readonly type: "run/dequeue";
67
- readonly messageId: string;
68
- };
69
-
70
- export type RunEditCommand = {
71
- readonly type: "run/edit";
72
- readonly message: RunUserMessage;
73
- readonly sourceId: string;
74
- };
75
-
76
- export type RunContinueCommand = {
77
- readonly type: "run/continue";
78
- };
79
-
80
- export type ToolCallInputRequest = {
81
- readonly type: "tool-call";
82
- readonly id: string;
83
- readonly toolCallId: string;
84
- };
85
-
86
- export type ToolApprovalInputRequest = {
87
- readonly type: "tool-approval";
88
- readonly id: string;
89
- readonly toolCallId: string;
90
- };
91
-
92
- export type CustomInputRequest = {
93
- readonly type: string;
94
- readonly id: string;
95
- readonly [key: string]: ReadonlyJSONValue | undefined;
96
- };
97
-
98
- /** A host request parking the run until answered; open union for custom types. */
99
- export type InputRequest =
100
- | ToolCallInputRequest
101
- | ToolApprovalInputRequest
102
- | CustomInputRequest;
103
-
104
- export type ToolCallInputResponse = {
105
- readonly output: ReadonlyJSONValue;
106
- /** Default false; when true, `output` carries the error payload. */
107
- readonly isError?: boolean;
108
- readonly artifact?: ReadonlyJSONValue;
109
- };
110
-
111
- export type ToolApprovalInputResponse = {
112
- readonly decision: "approve" | "reject" | "edit" | "respond";
113
- readonly editedArgs?: ReadonlyJSONValue;
114
- readonly message?: string;
115
- };
116
-
117
- export type InputResponse = ReadonlyJSONValue;
118
-
119
- export type RunInputCommand = {
120
- readonly type: "run/input";
121
- readonly requestId: string;
122
- readonly response: InputResponse;
123
- };
124
-
125
- /** An input request projected out of the host state with its response echo. */
126
- export type InputRequestState = InputRequest & {
127
- readonly response: InputResponse | null;
128
- };
129
-
130
- export type RunReloadCommand = {
131
- readonly type: "run/reload";
132
- readonly sourceId: string;
133
- };
134
-
135
- export type RunCommand =
136
- | RunEnqueueCommand
137
- | RunSteerCommand
138
- | RunDequeueCommand
139
- | RunEditCommand
140
- | RunContinueCommand
141
- | RunReloadCommand
142
- | RunInputCommand;
143
-
144
- export type AssistantTransportCommand = RunCommand | UserCommands;
145
-
146
- /** A queued message projected out of the host state, wire shape. */
147
- export type RunQueueItem = {
148
- readonly id: string;
149
- readonly parts: readonly (TextPart | FilePart)[];
150
- };
151
-
152
- export type AssistantTransportState = {
153
- readonly messages: readonly ThreadMessage[];
154
- readonly state?: ReadonlyJSONValue;
155
- readonly isRunning: boolean;
156
- /**
157
- * The host's regular queue lane projected out of the state. Returning it
158
- * (even empty) turns on the server-side queue: sends become `run/enqueue`
159
- * / `run/steer` commands and item controls send the `run/*` queue
160
- * commands. Presence must be stable across conversions and excludes the
161
- * client-local `capabilities.queue` buffer.
162
- */
163
- readonly queue?: readonly RunQueueItem[];
164
- /** The host's steer lane; requires `queue`. Absent means empty. */
165
- readonly steerQueue?: readonly RunQueueItem[];
166
- /**
167
- * The host's parked input requests projected out of the state. Returning it
168
- * (even empty) routes tool results and approvals with a matching pending
169
- * request through `run/input`. Presence must be stable across conversions.
170
- */
171
- readonly inputRequests?: readonly InputRequestState[];
172
- };
173
-
174
- export type AssistantTransportConnectionMetadata = {
175
- pendingCommands: AssistantTransportCommand[];
176
- isSending: boolean;
177
- toolStatuses: Record<string, ToolExecutionStatus>;
178
- };
179
-
180
- export type AssistantTransportStateConverter<T> = (
181
- state: T,
182
- connectionMetadata: AssistantTransportConnectionMetadata,
183
- ) => AssistantTransportState;
184
-
185
- export type HeadersValue = Record<string, string> | Headers;
186
-
187
- export type AssistantTransportProtocol = "data-stream" | "assistant-transport";
188
-
189
- export type SendCommandsRequestBody = {
190
- commands: AssistantTransportCommand[];
191
- state: unknown;
192
- system: string | undefined;
193
- tools: Record<string, unknown> | undefined;
194
- callSettings: LanguageModelV1CallSettings | undefined;
195
- config: LanguageModelConfig | undefined;
196
- threadId: string | null;
197
- parentId?: string | null;
198
- [key: string]: unknown;
199
- };
200
-
201
- export type AssistantTransportOptions<T> = {
202
- initialState: T;
203
- converter: AssistantTransportStateConverter<T>;
204
- api: string;
205
- resumeApi?: string | undefined;
206
- protocol?: AssistantTransportProtocol | undefined;
207
- headers: HeadersValue | (() => Promise<HeadersValue>);
208
- body?: object | (() => Promise<object | undefined>) | undefined;
209
- /** Transform the fully assembled request body before it is sent. */
210
- prepareSendCommandsRequest?:
211
- | ((
212
- body: SendCommandsRequestBody,
213
- ) => Record<string, unknown> | Promise<Record<string, unknown>>)
214
- | undefined;
215
- onResponse?: ((response: Response) => void) | undefined;
216
- onFinish?: (() => void) | undefined;
217
- onError?:
218
- | ((
219
- error: Error,
220
- params: {
221
- commands: AssistantTransportCommand[];
222
- updateState: (updater: (state: T) => T) => void;
223
- },
224
- ) => void | Promise<void>)
225
- | undefined;
226
- /**
227
- * Called when commands are cancelled. After an error, queued commands are
228
- * cancelled once `onError` settles; `error` then carries the cause.
229
- */
230
- onCancel?:
231
- | ((params: {
232
- commands: AssistantTransportCommand[];
233
- updateState: (updater: (state: T) => T) => void;
234
- error?: Error;
235
- }) => void)
236
- | undefined;
237
- capabilities?:
238
- | {
239
- edit?: boolean | undefined;
240
- /**
241
- * Buffer messages sent during a run in an in-memory queue and dispatch
242
- * them once the run settles. Steering interrupts the active run.
243
- * Mutually exclusive with the converter's `queue` projection.
244
- */
245
- queue?: boolean | undefined;
246
- /** The host supports `run/continue` (a continue affordance on aborted runs). */
247
- continue?: boolean | undefined;
248
- }
249
- | undefined;
250
- adapters?:
251
- | {
252
- attachments?: AttachmentAdapter | undefined;
253
- }
254
- | undefined;
255
- };