@assistant-ui/react-statewire 0.1.1 → 0.2.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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AddMessageCommand, AddToolResultCommand, AssistantMessage, AssistantTransportCommand, AssistantTransportConnectionMetadata, AssistantTransportOptions, AssistantTransportProtocol, AssistantTransportState, AssistantTransportStateConverter, ClearQueueCommand, EnqueueMessageCommand, HeadersValue, ImagePart, RemoveQueueItemCommand, SendCommandsRequestBody, SteerQueueItemCommand, TextPart, UserMessage, UserMessagePart } from "./types.js";
1
+ import { AssistantMessage, AssistantTransportCommand, AssistantTransportConnectionMetadata, AssistantTransportOptions, AssistantTransportProtocol, AssistantTransportState, AssistantTransportStateConverter, HeadersValue, ImagePart, MessageAddCommand, SendCommandsRequestBody, TextPart, ToolResultAddCommand, UserMessage, UserMessagePart } from "./types.js";
2
2
  import { AssistantTransportThread } from "./AssistantTransportThread.js";
3
3
  import { StatewireThread } from "./StatewireThread.js";
4
4
  import { useAssistantTransportSendCommand, useAssistantTransportState } from "./hooks.js";
@@ -10,12 +10,8 @@ declare namespace AssistantTransportThread {
10
10
  type State = AssistantTransportState;
11
11
  type ConnectionMetadata = AssistantTransportConnectionMetadata;
12
12
  type StateConverter<T> = AssistantTransportStateConverter<T>;
13
- type AddMessageCommand = AddMessageCommand;
14
- type AddToolResultCommand = AddToolResultCommand;
15
- type EnqueueMessageCommand = EnqueueMessageCommand;
16
- type SteerQueueItemCommand = SteerQueueItemCommand;
17
- type RemoveQueueItemCommand = RemoveQueueItemCommand;
18
- type ClearQueueCommand = ClearQueueCommand;
13
+ type MessageAddCommand = MessageAddCommand;
14
+ type ToolResultAddCommand = ToolResultAddCommand;
19
15
  type SendCommandsRequestBody = SendCommandsRequestBody;
20
16
  type UserMessage = UserMessage;
21
17
  type AssistantMessage = AssistantMessage;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;kBAUiB;OACH,QAAQ,KAAK,0BAAgC;OAC7C,UAAU;OACV,WAAW;OACX,QAAQ;OACR,qBAAqB;OACrB,eAAe,KAAK,iCAAuC;OAC3D,oBAAoB;OACpB,uBAAuB;OACvB,wBAAwB;OACxB,wBAAwB;OACxB,yBAAyB;OACzB,oBAAoB;OACpB,0BAA0B;OAC1B,cAAc;OACd,mBAAmB;OACnB,kBAAkB;OAClB,WAAW;OACX,YAAY;OACZ,eAAe"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;kBAUiB;OACH,QAAQ,KAAK,0BAAgC;OAC7C,UAAU;OACV,WAAW;OACX,QAAQ;OACR,qBAAqB;OACrB,eAAe,KAAK,iCAAuC;OAC3D,oBAAoB;OACpB,uBAAuB;OACvB,0BAA0B;OAC1B,cAAc;OACd,mBAAmB;OACnB,kBAAkB;OAClB,WAAW;OACX,YAAY;OACZ,eAAe"}
package/dist/types.d.ts CHANGED
@@ -22,14 +22,20 @@ type AssistantMessage = {
22
22
  readonly role: "assistant";
23
23
  readonly parts: readonly TextPart[];
24
24
  };
25
- type AddMessageCommand = {
26
- readonly type: "add-message";
25
+ type MessageAddCommand = {
26
+ readonly type: "message/add";
27
27
  readonly message: UserMessage | AssistantMessage;
28
28
  readonly parentId: string | null;
29
29
  readonly sourceId: string | null;
30
+ /**
31
+ * How the host handles the message while a run is active: `"queue"`
32
+ * appends to the queue, `"steer"` moves it to the front and interrupts
33
+ * the run. Absent, the host decides. Ignored when the host is idle.
34
+ */
35
+ readonly behavior?: "queue" | "steer";
30
36
  };
31
- type AddToolResultCommand = {
32
- readonly type: "add-tool-result";
37
+ type ToolResultAddCommand = {
38
+ readonly type: "tool-result/add";
33
39
  readonly toolCallId: string;
34
40
  readonly toolName: string;
35
41
  readonly result: ReadonlyJSONValue;
@@ -37,26 +43,7 @@ type AddToolResultCommand = {
37
43
  readonly artifact?: ReadonlyJSONValue;
38
44
  readonly modelContent?: readonly ToolModelContentPart[];
39
45
  };
40
- type EnqueueMessageCommand = {
41
- readonly type: "enqueue-message";
42
- readonly message: UserMessage | AssistantMessage;
43
- readonly parentId: string | null;
44
- readonly sourceId: string | null;
45
- readonly steer: boolean;
46
- };
47
- type SteerQueueItemCommand = {
48
- readonly type: "steer-queue-item";
49
- readonly queueItemId: string;
50
- };
51
- type RemoveQueueItemCommand = {
52
- readonly type: "remove-queue-item";
53
- readonly queueItemId: string;
54
- };
55
- type ClearQueueCommand = {
56
- readonly type: "clear-queue";
57
- readonly reason: "edit" | "reload" | "cancel-run";
58
- };
59
- type AssistantTransportCommand = AddMessageCommand | AddToolResultCommand | EnqueueMessageCommand | SteerQueueItemCommand | RemoveQueueItemCommand | ClearQueueCommand | UserCommands;
46
+ type AssistantTransportCommand = MessageAddCommand | ToolResultAddCommand | UserCommands;
60
47
  type AssistantTransportState = {
61
48
  readonly messages: readonly ThreadMessage[];
62
49
  readonly state?: ReadonlyJSONValue;
@@ -119,5 +106,5 @@ type AssistantTransportOptions<T> = {
119
106
  } | undefined;
120
107
  };
121
108
  //#endregion
122
- export { AddMessageCommand, AddToolResultCommand, AssistantMessage, AssistantTransportCommand, AssistantTransportConnectionMetadata, AssistantTransportOptions, AssistantTransportProtocol, AssistantTransportState, AssistantTransportStateConverter, ClearQueueCommand, EnqueueMessageCommand, HeadersValue, ImagePart, RemoveQueueItemCommand, SendCommandsRequestBody, SteerQueueItemCommand, TextPart, UserCommands, UserExternalState, UserMessage, UserMessagePart };
109
+ export { AssistantMessage, AssistantTransportCommand, AssistantTransportConnectionMetadata, AssistantTransportOptions, AssistantTransportProtocol, AssistantTransportState, AssistantTransportStateConverter, HeadersValue, ImagePart, MessageAddCommand, SendCommandsRequestBody, TextPart, ToolResultAddCommand, UserCommands, UserExternalState, UserMessage, UserMessagePart };
123
110
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;KAWY,eAAe,UAAU,eAAe,UAAU;KAClD,0BAA0B,UAAU,8BAC5C,0BACA,UAAU,oBAAoB,UAAU;KAEhC;WACD;WACA;;KAGC;WACD;WACA;;KAGC,kBAAkB,WAAW;KAE7B;WACD;WACA,gBAAgB;;KAGf;WACD;WACA,gBAAgB;;KAGf;WACD;WACA,SAAS,cAAc;WACvB;WACA;;KAGC;WACD;WACA;WACA;WACA,QAAQ;WACR;WACA,WAAW;WACX,wBAAwB;;KAGvB;WACD;WACA,SAAS,cAAc;WACvB;WACA;WACA;;KAGC;WACD;WACA;;KAGC;WACD;WACA;;KAGC;WACD;WACA;;KAGC,4BACR,oBACA,uBACA,wBACA,wBACA,yBACA,oBACA;KAEQ;WACD,mBAAmB;WACnB,QAAQ;WACR;;KAGC;EACV,iBAAiB;EACjB;EACA,cAAc,eAAe;;KAGnB,iCAAiC,MAC3C,OAAO,GACP,oBAAoB,yCACjB;KAEO,eAAe,yBAAyB;KAExC;KAEA;EACV,UAAU;EACV;EACA;EACA,OAAO;EACP,cAAc;EACd,QAAQ;EACR;EACA;GACC;;KAGS,0BAA0B;EACpC,cAAc;EACd,WAAW,iCAAiC;EAC5C;EACA;EACA,WAAW;EACX,SAAS,sBAAsB,QAAQ;EACvC,uBAAuB;;EAEvB,+BAEM,MAAM,4BACH,0BAA0B,QAAQ;EAE3C,eAAe,UAAU;EACzB;EACA,YAEM,OAAO,OACP;IACE,UAAU;IACV,cAAc,UAAU,OAAO,MAAM;eAE7B;;;;;EAMhB,aACM;IACA,UAAU;IACV,cAAc,UAAU,OAAO,MAAM;IACrC,QAAQ;;EAGd;IAEM;;;;;IAKA;;EAGN;IAEM,cAAc"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;KAWY,eAAe,UAAU,eAAe,UAAU;KAClD,0BAA0B,UAAU,8BAC5C,0BACA,UAAU,oBAAoB,UAAU;KAEhC;WACD;WACA;;KAGC;WACD;WACA;;KAGC,kBAAkB,WAAW;KAE7B;WACD;WACA,gBAAgB;;KAGf;WACD;WACA,gBAAgB;;KAGf;WACD;WACA,SAAS,cAAc;WACvB;WACA;;;;;;WAMA;;KAGC;WACD;WACA;WACA;WACA,QAAQ;WACR;WACA,WAAW;WACX,wBAAwB;;KAGvB,4BACR,oBACA,uBACA;KAEQ;WACD,mBAAmB;WACnB,QAAQ;WACR;;KAGC;EACV,iBAAiB;EACjB;EACA,cAAc,eAAe;;KAGnB,iCAAiC,MAC3C,OAAO,GACP,oBAAoB,yCACjB;KAEO,eAAe,yBAAyB;KAExC;KAEA;EACV,UAAU;EACV;EACA;EACA,OAAO;EACP,cAAc;EACd,QAAQ;EACR;EACA;GACC;;KAGS,0BAA0B;EACpC,cAAc;EACd,WAAW,iCAAiC;EAC5C;EACA;EACA,WAAW;EACX,SAAS,sBAAsB,QAAQ;EACvC,uBAAuB;;EAEvB,+BAEM,MAAM,4BACH,0BAA0B,QAAQ;EAE3C,eAAe,UAAU;EACzB;EACA,YAEM,OAAO,OACP;IACE,UAAU;IACV,cAAc,UAAU,OAAO,MAAM;eAE7B;;;;;EAMhB,aACM;IACA,UAAU;IACV,cAAc,UAAU,OAAO,MAAM;IACrC,QAAQ;;EAGd;IAEM;;;;;IAKA;;EAGN;IAEM,cAAc"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assistant-ui/react-statewire",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "assistant-ui thread binding for statewire backends",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -30,14 +30,14 @@
30
30
  "test": "vitest run"
31
31
  },
32
32
  "dependencies": {
33
- "@assistant-ui/core": "^0.3.0",
33
+ "@assistant-ui/core": "^0.3.7",
34
34
  "@assistant-ui/store": "^0.3.0",
35
35
  "@assistant-ui/tap": "^0.9.7",
36
36
  "assistant-stream": "^0.3.33",
37
- "statewire": "^0.0.4"
37
+ "statewire": "^0.0.5"
38
38
  },
39
39
  "peerDependencies": {
40
- "@assistant-ui/react": ">=0.14.0",
40
+ "@assistant-ui/react": ">=0.15.6",
41
41
  "react": "^18 || ^19"
42
42
  },
43
43
  "devDependencies": {
@@ -37,8 +37,8 @@ import type {
37
37
  SendOptions,
38
38
  } from "./host";
39
39
  import type {
40
- AddMessageCommand,
41
- AddToolResultCommand,
40
+ MessageAddCommand,
41
+ ToolResultAddCommand,
42
42
  AssistantTransportCommand,
43
43
  AssistantTransportOptions,
44
44
  UserMessagePart,
@@ -76,7 +76,7 @@ export const asAssistantTransportExtras = (
76
76
 
77
77
  export const convertAppendMessageToCommand = (
78
78
  message: AppendMessage,
79
- ): AddMessageCommand | null => {
79
+ ): MessageAddCommand | null => {
80
80
  if (message.role !== "user")
81
81
  throw new Error("Only user messages are supported");
82
82
 
@@ -96,7 +96,7 @@ export const convertAppendMessageToCommand = (
96
96
  if (parts.length === 0) return null;
97
97
 
98
98
  return {
99
- type: "add-message",
99
+ type: "message/add",
100
100
  message: {
101
101
  role: "user",
102
102
  parts,
@@ -184,7 +184,7 @@ const useAssistantTransportThread = (
184
184
  const messages = convertedRef.current
185
185
  .messages as readonly ThreadMessage[];
186
186
  if (!messagesContainToolCall(messages, command.toolCallId)) return;
187
- dispatch(command);
187
+ dispatch({ ...command, type: "tool-result/add" });
188
188
  },
189
189
  onStatusesChange: (statuses) => {
190
190
  setToolStatuses(
@@ -266,7 +266,7 @@ const useAssistantTransportThread = (
266
266
  cancel: () => driverRef.current.cancel(),
267
267
  });
268
268
  } else if (!enableQueue && queueRef.current) {
269
- queueRef.current.adapter.clear("cancel-run");
269
+ queueRef.current.clear();
270
270
  queueRef.current = null;
271
271
  }
272
272
  const messageQueue = queueRef.current;
@@ -278,6 +278,11 @@ const useAssistantTransportThread = (
278
278
  () => messageQueue?.adapter.items ?? EMPTY_QUEUE_ITEMS,
279
279
  () => EMPTY_QUEUE_ITEMS,
280
280
  );
281
+ const steerQueueItems = useSyncExternalStore(
282
+ messageQueue?.subscribe ?? subscribeNoop,
283
+ () => messageQueue?.adapter.steerItems ?? EMPTY_QUEUE_ITEMS,
284
+ () => EMPTY_QUEUE_ITEMS,
285
+ );
281
286
 
282
287
  // settled edge: the queue only advances once the host run loop has fully
283
288
  // released (isSending), the converted state agrees, and no client tool from
@@ -302,7 +307,11 @@ const useAssistantTransportThread = (
302
307
  attachmentAdapter: options.adapters?.attachments,
303
308
  onNew: handleAppend,
304
309
  ...(messageQueue && {
305
- queue: { ...messageQueue.adapter, items: queueItems },
310
+ queue: {
311
+ ...messageQueue.adapter,
312
+ items: queueItems,
313
+ steerItems: steerQueueItems,
314
+ },
306
315
  }),
307
316
  ...(options.capabilities?.edit && { onEdit: handleAppend }),
308
317
  onReload: (parentId: string | null) => {
@@ -310,15 +319,19 @@ const useAssistantTransportThread = (
310
319
  void commands.reload(parentId).catch(() => {});
311
320
  });
312
321
  },
313
- onCancel: handleCancel,
322
+ onCancel: () => {
323
+ // user cancel drops pending lanes; a steer interrupt (driver.cancel) keeps them
324
+ messageQueue?.clear();
325
+ handleCancel();
326
+ },
314
327
  onResume: () => {
315
328
  if (!options.resumeApi)
316
329
  throw new Error("Must pass resumeApi to options to resume runs");
317
330
  void commands.resume().catch(() => {});
318
331
  },
319
332
  onAddToolResult: (toolOptions: AddToolResultOptions) => {
320
- const command: AddToolResultCommand = {
321
- type: "add-tool-result",
333
+ const command: ToolResultAddCommand = {
334
+ type: "tool-result/add",
322
335
  toolCallId: toolOptions.toolCallId,
323
336
  result: toolOptions.result as ReadonlyJSONObject,
324
337
  toolName: toolOptions.toolName,