@assistant-ui/react-statewire 0.4.2 → 0.4.4

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.
@@ -15,10 +15,12 @@ import {
15
15
  useStatewireState,
16
16
  } from "statewire/host";
17
17
  import { createMockTransport } from "statewire/testing";
18
+ import type { Statewire } from "statewire";
18
19
  import { StatewireThread } from "./StatewireThread";
19
20
  import { asAssistantTransportExtras } from "./AssistantTransportThread";
21
+ import type { AssistantTransportThread } from "./AssistantTransportThread";
20
22
  import { useAssistantTransportState } from "./hooks";
21
- import type { AssistantTransportCommand } from "./types";
23
+
22
24
  import {
23
25
  sendCommand,
24
26
  threadTexts,
@@ -394,13 +396,50 @@ describe("StatewireThread", () => {
394
396
  );
395
397
  sendCommand(aui, {
396
398
  type: "reject-me",
397
- } as unknown as AssistantTransportCommand);
399
+ } as unknown as AssistantTransportThread.Command);
398
400
 
399
401
  await waitFor(() => expect(errors).toHaveLength(1));
400
402
  expect(errors[0]!.message).toContain("nope");
401
403
  await waitFor(() => expect(metas.at(-1)!.pendingCommands).toEqual([]));
402
404
  });
403
405
 
406
+ it("reports the command lifecycle through onCommandChange after retiring the pending command", async () => {
407
+ const server = createServer();
408
+ const updates: Statewire.CommandUpdate<
409
+ Record<string, (...args: any[]) => unknown>
410
+ >[] = [];
411
+ const states: ServerState[] = [];
412
+ const metas: StatewireThread.ConnectionMetadata[] = [];
413
+ const { aui } = mountThread({
414
+ transport: server.transport,
415
+ converter: (state, meta) => {
416
+ metas.push(meta);
417
+ return converter(state, meta);
418
+ },
419
+ onCommandChange: (update, ctx) => {
420
+ updates.push(update);
421
+ states.push(ctx.state);
422
+ },
423
+ });
424
+
425
+ aui().thread().append("hello");
426
+
427
+ await waitFor(() =>
428
+ expect(updates.map((u) => u.status)).toEqual([
429
+ "queued",
430
+ "posted",
431
+ "acked",
432
+ "settled",
433
+ ]),
434
+ );
435
+ expect(updates.at(-1)).toMatchObject({
436
+ method: "run/steer",
437
+ params: [{ type: "run/steer" }],
438
+ });
439
+ expect(states.at(-1)!.messages.map((m) => m.text)).toEqual(["hello"]);
440
+ await waitFor(() => expect(metas.at(-1)!.pendingCommands).toEqual([]));
441
+ });
442
+
404
443
  describe("contextSync: command-send", () => {
405
444
  const contextValueOf = (command: { context?: unknown }) => {
406
445
  const ops = command.context as [
@@ -22,7 +22,10 @@ import type { ReadonlyJSONValue } from "assistant-stream/utils";
22
22
  import { useStatewire } from "statewire";
23
23
  import type { Statewire, StatewireClient } from "statewire";
24
24
  import { symbolAssistantTransportExtras } from "./AssistantTransportThread";
25
- import type { AssistantTransportExtras } from "./AssistantTransportThread";
25
+ import type {
26
+ AssistantTransportExtras,
27
+ AssistantTransportThread,
28
+ } from "./AssistantTransportThread";
26
29
  import {
27
30
  createRunQueueAdapter,
28
31
  resolveReloadCommand,
@@ -33,7 +36,6 @@ import {
33
36
  resolveToolApprovalInput,
34
37
  resolveToolResultInput,
35
38
  } from "./inputRequests";
36
- import type { AssistantTransportCommand } from "./types";
37
39
 
38
40
  type AnyCommands = Record<string, (...args: any[]) => unknown>;
39
41
 
@@ -111,9 +113,10 @@ const useStatewireThread = (
111
113
  options.onCommandSessionLost === undefined
112
114
  ? options.transport
113
115
  : withSessionLostFallback(options.transport, latest),
114
- onCommandChange: (update) => {
116
+ onCommandChange: (update, ctx) => {
115
117
  if (update.status === "acked" || update.status === "settled")
116
118
  retire(update.params[0]);
119
+ latest.current.onCommandChange?.(update, ctx);
117
120
  },
118
121
  });
119
122
  const attached = transportState !== undefined;
@@ -418,7 +421,7 @@ export namespace StatewireThread {
418
421
  | RunReloadCommand
419
422
  | RunInputCommand;
420
423
 
421
- export type Command = AssistantTransportCommand | RunCommand;
424
+ export type Command = AssistantTransportThread.Command | RunCommand;
422
425
 
423
426
  /** A queued message projected out of the host state, wire shape. */
424
427
  export type QueueItem = {
@@ -490,6 +493,15 @@ export namespace StatewireThread {
490
493
  onCommandSessionLost?:
491
494
  | ((command: StatewireClient.SessionLostCommand) => "replay" | void)
492
495
  | undefined;
496
+ /** Observes each command's lifecycle (queued, posted, acked, settled); runs after the built-in pending-command retirement. */
497
+ onCommandChange?:
498
+ | ((
499
+ update: Statewire.CommandUpdate<
500
+ Record<string, (...args: any[]) => unknown>
501
+ >,
502
+ ctx: { state: NonNullable<T> },
503
+ ) => void)
504
+ | undefined;
493
505
  onError?: ((error: Error) => void) | undefined;
494
506
  capabilities?:
495
507
  | {
@@ -7,13 +7,6 @@ import {
7
7
  asAssistantTransportExtras,
8
8
  AssistantTransportThread,
9
9
  } from "../AssistantTransportThread";
10
- import type {
11
- AssistantTransportCommand,
12
- AssistantTransportConnectionMetadata,
13
- AssistantTransportOptions,
14
- AssistantTransportStateConverter,
15
- InputRequestState,
16
- } from "../types";
17
10
 
18
11
  export type TestState = {
19
12
  messages: { id: string; role: "user" | "assistant"; text: string }[];
@@ -39,10 +32,9 @@ export const toThreadMessage = (m: {
39
32
  }),
40
33
  }) as unknown as ExternalThreadMessage;
41
34
 
42
- export const defaultConverter: AssistantTransportStateConverter<TestState> = (
43
- state,
44
- meta,
45
- ) => ({
35
+ export const defaultConverter: AssistantTransportThread.StateConverter<
36
+ TestState
37
+ > = (state, meta) => ({
46
38
  messages: [
47
39
  ...state.messages.map(toThreadMessage),
48
40
  ...meta.pendingCommands.flatMap((c, i) =>
@@ -139,7 +131,7 @@ export const abortableStream = (init: RequestInit) => {
139
131
  };
140
132
 
141
133
  export const mountThread = (
142
- options?: Partial<AssistantTransportOptions<TestState>>,
134
+ options?: Partial<AssistantTransportThread.Options<TestState>>,
143
135
  mountOpts?: {
144
136
  wrap?: (node: ReactElement) => ReactElement;
145
137
  children?: ReactNode;
@@ -175,7 +167,7 @@ export const mountThread = (
175
167
 
176
168
  export const sendCommand = (
177
169
  aui: () => ReturnType<typeof useAui>,
178
- command: AssistantTransportCommand,
170
+ command: AssistantTransportThread.Command,
179
171
  ) =>
180
172
  asAssistantTransportExtras(aui().thread().getState().extras).sendCommand(
181
173
  command,
@@ -190,11 +182,11 @@ export const threadTexts = (aui: () => ReturnType<typeof useAui>) =>
190
182
  );
191
183
 
192
184
  export const toolCallConverter = (
193
- metas: AssistantTransportConnectionMetadata[],
194
- ): AssistantTransportStateConverter<TestState> => {
185
+ metas: AssistantTransportThread.ConnectionMetadata[],
186
+ ): AssistantTransportThread.StateConverter<TestState> => {
195
187
  type ToolCallState = TestState & {
196
188
  toolCall?: { id: string; name: string; argsText: string };
197
- inputRequests?: InputRequestState[];
189
+ inputRequests?: AssistantTransportThread.InputRequestState[];
198
190
  };
199
191
  return (state, meta) => {
200
192
  metas.push(meta);
@@ -257,4 +249,6 @@ export const emitToolCall = (server: StreamResponse) => {
257
249
  };
258
250
 
259
251
  export const allCommands = (requests: RecordedRequest[]) =>
260
- requests.flatMap((r) => r.body.commands as AssistantTransportCommand[]);
252
+ requests.flatMap(
253
+ (r) => r.body.commands as AssistantTransportThread.Command[],
254
+ );
@@ -12,15 +12,7 @@ import { AuiProvider, useAui } from "@assistant-ui/store";
12
12
  import type { ExternalThreadMessage } from "@assistant-ui/react";
13
13
  import { AssistantTransportThread } from "./AssistantTransportThread";
14
14
  import { useAssistantTransportSendCommand } from "./hooks";
15
- import type {
16
- InputRequestState,
17
- RunEditCommand,
18
- RunSteerCommand,
19
- RunUserMessage,
20
- AssistantTransportCommand,
21
- AssistantTransportOptions,
22
- AssistantTransportStateConverter,
23
- } from "./types";
15
+
24
16
  import {
25
17
  createStreamResponse,
26
18
  installFetch,
@@ -40,7 +32,7 @@ type LangGraphMessage =
40
32
  type LangGraphState = {
41
33
  messages: LangGraphMessage[];
42
34
  todos: string[];
43
- inputRequests?: InputRequestState[];
35
+ inputRequests?: AssistantTransportThread.InputRequestState[];
44
36
  };
45
37
 
46
38
  const INITIAL_STATE: LangGraphState = { messages: [], todos: [] };
@@ -48,12 +40,15 @@ const INITIAL_STATE: LangGraphState = { messages: [], todos: [] };
48
40
  // Athena's optimistic dedup: each user-message command gets a stable
49
41
  // trackingId; the server echoes it on the human message, which retires the
50
42
  // optimistic copy without a flicker frame or a phantom duplicate.
51
- type UserMessageCommand = (RunSteerCommand | RunEditCommand) & {
52
- message: RunUserMessage;
43
+ type UserMessageCommand = (
44
+ | AssistantTransportThread.RunSteerCommand
45
+ | AssistantTransportThread.RunEditCommand
46
+ ) & {
47
+ message: AssistantTransportThread.RunUserMessage;
53
48
  };
54
49
 
55
50
  const isUserMessageCommand = (
56
- c: AssistantTransportCommand,
51
+ c: AssistantTransportThread.Command,
57
52
  ): c is UserMessageCommand =>
58
53
  (c.type === "run/steer" || c.type === "run/edit") && "message" in c;
59
54
 
@@ -69,7 +64,7 @@ const createConverter = () => {
69
64
  return id;
70
65
  };
71
66
 
72
- const converter: AssistantTransportStateConverter<LangGraphState> = (
67
+ const converter: AssistantTransportThread.StateConverter<LangGraphState> = (
73
68
  state,
74
69
  meta,
75
70
  ) => {
@@ -152,14 +147,14 @@ const createConverter = () => {
152
147
 
153
148
  const mountDeepAgent = () => {
154
149
  const { converter, trackingIdOf } = createConverter();
155
- const cancelled: AssistantTransportCommand[][] = [];
156
- const errored: AssistantTransportCommand[][] = [];
150
+ const cancelled: AssistantTransportThread.Command[][] = [];
151
+ const errored: AssistantTransportThread.Command[][] = [];
157
152
  const responses: (string | null)[] = [];
158
153
  let finishCount = 0;
159
154
 
160
155
  const captured: {
161
156
  aui?: ReturnType<typeof useAui>;
162
- sendCommand?: (command: AssistantTransportCommand) => void;
157
+ sendCommand?: (command: AssistantTransportThread.Command) => void;
163
158
  } = {};
164
159
  const Capture: FC = () => {
165
160
  captured.aui = useAui();
@@ -167,7 +162,7 @@ const mountDeepAgent = () => {
167
162
  return null;
168
163
  };
169
164
 
170
- const options: AssistantTransportOptions<LangGraphState> = {
165
+ const options: AssistantTransportThread.Options<LangGraphState> = {
171
166
  initialState: INITIAL_STATE,
172
167
  api: "https://sync.example.com/api/chat",
173
168
  resumeApi: "https://sync.example.com/api/resume",
@@ -243,7 +238,8 @@ const mountDeepAgent = () => {
243
238
  const utils = render(<App />);
244
239
  return {
245
240
  aui: () => captured.aui!,
246
- sendCommand: (c: AssistantTransportCommand) => captured.sendCommand!(c),
241
+ sendCommand: (c: AssistantTransportThread.Command) =>
242
+ captured.sendCommand!(c),
247
243
  cancelled,
248
244
  errored,
249
245
  responses,
package/src/hooks.ts CHANGED
@@ -2,12 +2,17 @@
2
2
 
3
3
  import { useAui, useAuiState } from "@assistant-ui/store";
4
4
  import { asAssistantTransportExtras } from "./AssistantTransportThread";
5
- import type { AssistantTransportCommand, UserExternalState } from "./types";
5
+ import type { Assistant } from "@assistant-ui/react";
6
+ import type { AssistantTransportThread } from "./AssistantTransportThread";
7
+
8
+ type UserExternalState = keyof Assistant.ExternalState extends never
9
+ ? Record<string, unknown>
10
+ : Assistant.ExternalState[keyof Assistant.ExternalState];
6
11
 
7
12
  export const useAssistantTransportSendCommand = () => {
8
13
  const aui = useAui();
9
14
 
10
- return (command: AssistantTransportCommand) => {
15
+ return (command: AssistantTransportThread.Command) => {
11
16
  const extras = aui.thread().getState().extras;
12
17
  asAssistantTransportExtras(extras).sendCommand(command);
13
18
  };
package/src/host.ts CHANGED
@@ -18,11 +18,7 @@ import {
18
18
  import type { StatewireHost } from "statewire/host";
19
19
  import { createReplayBoundaryStream } from "./replayBoundaryStream";
20
20
  import { translateStateOp } from "./stateOps";
21
- import type {
22
- AssistantTransportCommand,
23
- AssistantTransportOptions,
24
- SendCommandsRequestBody,
25
- } from "./types";
21
+ import type { AssistantTransportThread } from "./AssistantTransportThread";
26
22
 
27
23
  export type SendOptions = {
28
24
  schedule?: boolean;
@@ -34,8 +30,8 @@ export type HostRunContext = {
34
30
  };
35
31
 
36
32
  export type HostQueue = {
37
- queued: AssistantTransportCommand[];
38
- inTransit: AssistantTransportCommand[];
33
+ queued: AssistantTransportThread.Command[];
34
+ inTransit: AssistantTransportThread.Command[];
39
35
  };
40
36
 
41
37
  // Statewire state sanitizes values on apply; command objects must keep their
@@ -43,7 +39,7 @@ export type HostQueue = {
43
39
  // cell and bumps queueVersion in state to signal the change.
44
40
  export type HostQueueCell = { current: HostQueue };
45
41
 
46
- export type HostOptions = AssistantTransportOptions<unknown> & {
42
+ export type HostOptions = AssistantTransportThread.Options<unknown> & {
47
43
  getRunContext: () => HostRunContext;
48
44
  queueCell: HostQueueCell;
49
45
  };
@@ -56,7 +52,7 @@ export type AssistantTransportHostState = {
56
52
  };
57
53
 
58
54
  export type AssistantTransportHostCommands = {
59
- send(command: AssistantTransportCommand, opts?: SendOptions): void;
55
+ send(command: AssistantTransportThread.Command, opts?: SendOptions): void;
60
56
  setParentId(parentId: string | null): void;
61
57
  cancel(): void;
62
58
  resume(): void;
@@ -70,7 +66,7 @@ type EntrySettlement = {
70
66
  };
71
67
 
72
68
  type QueueEntry = {
73
- command: AssistantTransportCommand;
69
+ command: AssistantTransportThread.Command;
74
70
  execution: EntrySettlement;
75
71
  };
76
72
 
@@ -176,7 +172,7 @@ const useHostLoop = (
176
172
 
177
173
  const buildRequestBody = async (
178
174
  o: HostOptions,
179
- commands: AssistantTransportCommand[],
175
+ commands: AssistantTransportThread.Command[],
180
176
  runParentId: string | null | undefined,
181
177
  ) => {
182
178
  const bodyValue = typeof o.body === "function" ? await o.body() : o.body;
@@ -200,7 +196,9 @@ const useHostLoop = (
200
196
  };
201
197
 
202
198
  if (!o.prepareSendCommandsRequest) return requestBody;
203
- return o.prepareSendCommandsRequest(requestBody as SendCommandsRequestBody);
199
+ return o.prepareSendCommandsRequest(
200
+ requestBody as AssistantTransportThread.SendCommandsRequestBody,
201
+ );
204
202
  };
205
203
 
206
204
  const run = async (signal: AbortSignal) => {
@@ -373,7 +371,7 @@ const useHostLoop = (
373
371
  return {
374
372
  send: function (
375
373
  this: StatewireHost.Ctx,
376
- command: AssistantTransportCommand,
374
+ command: AssistantTransportThread.Command,
377
375
  opts?: SendOptions,
378
376
  ) {
379
377
  let resolve!: () => void;
package/src/index.ts CHANGED
@@ -1,41 +1,6 @@
1
- import type * as types from "./types";
2
- import { AssistantTransportThread } from "./AssistantTransportThread";
3
-
4
- export { AssistantTransportThread };
1
+ export { AssistantTransportThread } from "./AssistantTransportThread";
5
2
  export { StatewireThread } from "./StatewireThread";
6
3
  export {
7
4
  useAssistantTransportSendCommand,
8
5
  useAssistantTransportState,
9
6
  } from "./hooks";
10
-
11
- export namespace AssistantTransportThread {
12
- export type Options<T> = types.AssistantTransportOptions<T>;
13
- export type Command = types.AssistantTransportCommand;
14
- export type Protocol = types.AssistantTransportProtocol;
15
- export type State = types.AssistantTransportState;
16
- export type ConnectionMetadata = types.AssistantTransportConnectionMetadata;
17
- export type StateConverter<T> = types.AssistantTransportStateConverter<T>;
18
- export type RunCommand = types.RunCommand;
19
- export type RunEnqueueCommand = types.RunEnqueueCommand;
20
- export type RunSteerCommand = types.RunSteerCommand;
21
- export type RunDequeueCommand = types.RunDequeueCommand;
22
- export type RunEditCommand = types.RunEditCommand;
23
- export type RunContinueCommand = types.RunContinueCommand;
24
- export type RunReloadCommand = types.RunReloadCommand;
25
- export type RunInputCommand = types.RunInputCommand;
26
- export type InputRequest = types.InputRequest;
27
- export type ToolCallInputRequest = types.ToolCallInputRequest;
28
- export type ToolApprovalInputRequest = types.ToolApprovalInputRequest;
29
- export type CustomInputRequest = types.CustomInputRequest;
30
- export type InputRequestState = types.InputRequestState;
31
- export type InputResponse = types.InputResponse;
32
- export type ToolCallInputResponse = types.ToolCallInputResponse;
33
- export type ToolApprovalInputResponse = types.ToolApprovalInputResponse;
34
- export type RunUserMessage = types.RunUserMessage;
35
- export type RunQueueItem = types.RunQueueItem;
36
- export type RunPlacement = types.RunPlacement;
37
- export type SendCommandsRequestBody = types.SendCommandsRequestBody;
38
- export type TextPart = types.TextPart;
39
- export type FilePart = types.FilePart;
40
- export type HeadersValue = types.HeadersValue;
41
- }
@@ -1,8 +1,10 @@
1
1
  import type { RespondToToolApprovalOptions } from "@assistant-ui/core";
2
2
  import type { ReadonlyJSONValue } from "assistant-stream/utils";
3
- import type { InputRequestState, RunInputCommand } from "./types";
3
+ import type { AssistantTransportThread } from "./AssistantTransportThread";
4
4
 
5
- const assertUnanswered = (request: InputRequestState) => {
5
+ const assertUnanswered = (
6
+ request: AssistantTransportThread.InputRequestState,
7
+ ) => {
6
8
  if (request.response !== null)
7
9
  throw new Error(
8
10
  `statewire: input request "${request.id}" is already answered`,
@@ -10,14 +12,14 @@ const assertUnanswered = (request: InputRequestState) => {
10
12
  };
11
13
 
12
14
  export const resolveToolResultInput = (
13
- inputRequests: readonly InputRequestState[],
15
+ inputRequests: readonly AssistantTransportThread.InputRequestState[],
14
16
  options: {
15
17
  toolCallId: string;
16
18
  result: ReadonlyJSONValue;
17
19
  isError: boolean;
18
20
  artifact?: ReadonlyJSONValue | undefined;
19
21
  },
20
- ): RunInputCommand => {
22
+ ): AssistantTransportThread.RunInputCommand => {
21
23
  const request = inputRequests.find(
22
24
  (r) => r.type === "tool-call" && r.toolCallId === options.toolCallId,
23
25
  );
@@ -38,9 +40,9 @@ export const resolveToolResultInput = (
38
40
  };
39
41
 
40
42
  export const resolveToolApprovalInput = (
41
- inputRequests: readonly InputRequestState[],
43
+ inputRequests: readonly AssistantTransportThread.InputRequestState[],
42
44
  options: RespondToToolApprovalOptions,
43
- ): RunInputCommand => {
45
+ ): AssistantTransportThread.RunInputCommand => {
44
46
  const request = inputRequests.find(
45
47
  (r) => r.type === "tool-approval" && r.id === options.approvalId,
46
48
  );
@@ -14,10 +14,7 @@ import {
14
14
  } from "@assistant-ui/react";
15
15
  import type { ExternalThreadMessage } from "@assistant-ui/react";
16
16
  import { AssistantTransportThread } from "./AssistantTransportThread";
17
- import type {
18
- AssistantTransportOptions,
19
- AssistantTransportStateConverter,
20
- } from "./types";
17
+
21
18
  import { sseEvent } from "./__tests__/testHelpers";
22
19
 
23
20
  type TestState = {
@@ -26,7 +23,7 @@ type TestState = {
26
23
 
27
24
  const INITIAL_STATE: TestState = { messages: [] };
28
25
 
29
- const converter: AssistantTransportStateConverter<TestState> = (
26
+ const converter: AssistantTransportThread.StateConverter<TestState> = (
30
27
  state,
31
28
  meta,
32
29
  ) => ({
@@ -232,7 +229,7 @@ const observeNew = async (): Promise<{
232
229
  captured.aui = useAui();
233
230
  return null;
234
231
  };
235
- const options: AssistantTransportOptions<TestState> = {
232
+ const options: AssistantTransportThread.Options<TestState> = {
236
233
  initialState: INITIAL_STATE,
237
234
  api: "https://example.com/api",
238
235
  protocol: "assistant-transport",
@@ -288,7 +285,7 @@ type ToolState = TestState & {
288
285
  note?: string;
289
286
  };
290
287
 
291
- const toolConverter: AssistantTransportStateConverter<ToolState> = (
288
+ const toolConverter: AssistantTransportThread.StateConverter<ToolState> = (
292
289
  state,
293
290
  meta,
294
291
  ) => {
@@ -3,22 +3,15 @@ import type {
3
3
  ExternalThreadQueueAdapter,
4
4
  QueuePlacement,
5
5
  } from "@assistant-ui/core";
6
- import type {
7
- FilePart,
8
- RunCommand,
9
- RunQueueItem,
10
- RunReloadCommand,
11
- RunUserMessage,
12
- TextPart,
13
- } from "./types";
6
+ import type { AssistantTransportThread } from "./AssistantTransportThread";
14
7
 
15
8
  export const toWireMessage = (
16
9
  message: AppendMessage,
17
10
  id: string,
18
- ): RunUserMessage => {
11
+ ): AssistantTransportThread.RunUserMessage => {
19
12
  if (message.role !== "user")
20
13
  throw new Error("statewire: only user messages are supported");
21
- const files: FilePart[] = [];
14
+ const files: AssistantTransportThread.FilePart[] = [];
22
15
  const texts: string[] = [];
23
16
  const source = [
24
17
  ...message.content,
@@ -41,7 +34,10 @@ export const toWireMessage = (
41
34
  }
42
35
  }
43
36
  // default-safe against host capabilities: files first, one merged text part
44
- const parts: (TextPart | FilePart)[] = [
37
+ const parts: (
38
+ | AssistantTransportThread.TextPart
39
+ | AssistantTransportThread.FilePart
40
+ )[] = [
45
41
  ...files,
46
42
  ...(texts.length > 0
47
43
  ? [{ type: "text" as const, text: texts.join("\n\n") }]
@@ -52,7 +48,9 @@ export const toWireMessage = (
52
48
  return { id, role: "user", parts };
53
49
  };
54
50
 
55
- export const toQueueItemState = (item: RunQueueItem) => ({
51
+ export const toQueueItemState = (
52
+ item: AssistantTransportThread.RunQueueItem,
53
+ ) => ({
56
54
  id: item.id,
57
55
  prompt: item.parts
58
56
  .flatMap((part) => (part.type === "text" ? [part.text] : []))
@@ -84,9 +82,9 @@ export const viewedLeafId = (
84
82
 
85
83
  export const createRunQueueAdapter = (
86
84
  messages: readonly { id: string }[],
87
- queueItems: readonly RunQueueItem[],
88
- steerQueueItems: readonly RunQueueItem[] | undefined,
89
- dispatch: (command: RunCommand) => void,
85
+ queueItems: readonly AssistantTransportThread.RunQueueItem[],
86
+ steerQueueItems: readonly AssistantTransportThread.RunQueueItem[] | undefined,
87
+ dispatch: (command: AssistantTransportThread.RunCommand) => void,
90
88
  ): ExternalThreadQueueAdapter => {
91
89
  const laneOf = (queueItemId: string): "queue" | "steer" => {
92
90
  if (steerQueueItems?.some((item) => item.id === queueItemId))
@@ -137,7 +135,7 @@ export const createRunQueueAdapter = (
137
135
  export const resolveReloadCommand = (
138
136
  messages: readonly { id: string; role: string }[],
139
137
  parentId: string | null,
140
- ): RunReloadCommand => {
138
+ ): AssistantTransportThread.RunReloadCommand => {
141
139
  const index =
142
140
  parentId === null
143
141
  ? 0
@@ -20,11 +20,7 @@ import {
20
20
  useAssistantTransportSendCommand,
21
21
  useAssistantTransportState,
22
22
  } from "./hooks";
23
- import type {
24
- AssistantTransportCommand,
25
- AssistantTransportConnectionMetadata,
26
- InputRequestState,
27
- } from "./types";
23
+
28
24
  import {
29
25
  INITIAL_STATE,
30
26
  abortableStream,
@@ -142,7 +138,7 @@ describe("AssistantTransportThread", () => {
142
138
  return server.response;
143
139
  });
144
140
 
145
- const metas: AssistantTransportConnectionMetadata[] = [];
141
+ const metas: AssistantTransportThread.ConnectionMetadata[] = [];
146
142
  const converter: typeof defaultConverter = (state, meta) => {
147
143
  metas.push(meta);
148
144
  return defaultConverter(state, meta);
@@ -328,7 +324,7 @@ describe("AssistantTransportThread", () => {
328
324
  return server.response;
329
325
  });
330
326
 
331
- const errored: AssistantTransportCommand[][] = [];
327
+ const errored: AssistantTransportThread.Command[][] = [];
332
328
  const { aui } = mountThread({
333
329
  onError: (_error, { commands }) => {
334
330
  errored.push(commands);
@@ -401,7 +397,7 @@ describe("AssistantTransportThread", () => {
401
397
  const fetchMock = installFetch();
402
398
  fetchMock.setHandler(({ init }) => abortableStream(init).response);
403
399
 
404
- const cancelled: AssistantTransportCommand[][] = [];
400
+ const cancelled: AssistantTransportThread.Command[][] = [];
405
401
  const errors: string[] = [];
406
402
  const { aui } = mountThread({
407
403
  onCancel: ({ commands, error }) => {
@@ -1087,7 +1083,7 @@ describe("AssistantTransportThread", () => {
1087
1083
  return server.response;
1088
1084
  });
1089
1085
 
1090
- const metas: AssistantTransportConnectionMetadata[] = [];
1086
+ const metas: AssistantTransportThread.ConnectionMetadata[] = [];
1091
1087
  const { aui } = mountThread({ converter: toolCallConverter(metas) });
1092
1088
  aui()
1093
1089
  .modelContext()
@@ -1322,7 +1318,7 @@ describe("AssistantTransportThread", () => {
1322
1318
  resolveExecute = resolve;
1323
1319
  });
1324
1320
 
1325
- const metas: AssistantTransportConnectionMetadata[] = [];
1321
+ const metas: AssistantTransportThread.ConnectionMetadata[] = [];
1326
1322
  const { aui } = mountThread({ converter: toolCallConverter(metas) });
1327
1323
  aui()
1328
1324
  .modelContext()
@@ -1374,7 +1370,7 @@ describe("AssistantTransportThread", () => {
1374
1370
  return server.response;
1375
1371
  });
1376
1372
 
1377
- const metas: AssistantTransportConnectionMetadata[] = [];
1373
+ const metas: AssistantTransportThread.ConnectionMetadata[] = [];
1378
1374
  const { aui } = mountThread({ converter: toolCallConverter(metas) });
1379
1375
  aui()
1380
1376
  .modelContext()
@@ -1432,7 +1428,7 @@ describe("AssistantTransportThread", () => {
1432
1428
  return server.response;
1433
1429
  });
1434
1430
 
1435
- const metas: AssistantTransportConnectionMetadata[] = [];
1431
+ const metas: AssistantTransportThread.ConnectionMetadata[] = [];
1436
1432
  const { aui } = mountThread({ converter: toolCallConverter(metas) });
1437
1433
  aui()
1438
1434
  .modelContext()
@@ -1481,7 +1477,7 @@ describe("AssistantTransportThread", () => {
1481
1477
  return server.response;
1482
1478
  });
1483
1479
 
1484
- const metas: AssistantTransportConnectionMetadata[] = [];
1480
+ const metas: AssistantTransportThread.ConnectionMetadata[] = [];
1485
1481
  const { aui } = mountThread({ converter: toolCallConverter(metas) });
1486
1482
  aui()
1487
1483
  .modelContext()
@@ -1824,7 +1820,7 @@ describe("AssistantTransportThread", () => {
1824
1820
 
1825
1821
  const captured: {
1826
1822
  state?: TestState;
1827
- send?: (command: AssistantTransportCommand) => void;
1823
+ send?: (command: AssistantTransportThread.Command) => void;
1828
1824
  } = {};
1829
1825
  const HookCapture: FC = () => {
1830
1826
  captured.state = useAssistantTransportState() as TestState;
@@ -1846,7 +1842,7 @@ describe("AssistantTransportThread", () => {
1846
1842
  type S = TestState & { toolCall?: { id: string; result?: string } };
1847
1843
  const converter = (
1848
1844
  state: S,
1849
- meta: AssistantTransportConnectionMetadata,
1845
+ meta: AssistantTransportThread.ConnectionMetadata,
1850
1846
  ) => {
1851
1847
  const tc = state.toolCall;
1852
1848
  return {
@@ -2350,7 +2346,7 @@ describe("server queue projection", () => {
2350
2346
  describe("input requests", () => {
2351
2347
  type InputState = TestState & {
2352
2348
  toolCall?: { id: string; name: string; argsText: string };
2353
- inputRequests?: InputRequestState[];
2349
+ inputRequests?: AssistantTransportThread.InputRequestState[];
2354
2350
  };
2355
2351
 
2356
2352
  const requestConverter = (approval?: {