@assistant-ui/react-statewire 0.2.0 → 0.4.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/src/types.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { ToolModelContentPart } from "assistant-stream";
2
1
  import type { ReadonlyJSONValue } from "assistant-stream/utils";
3
2
  import type {
4
3
  AttachmentAdapter,
@@ -19,55 +18,159 @@ export type TextPart = {
19
18
  readonly text: string;
20
19
  };
21
20
 
22
- export type ImagePart = {
23
- readonly type: "image";
24
- readonly image: string;
21
+ export type FilePart = {
22
+ readonly type: "file";
23
+ readonly mediaType: string;
24
+ readonly url: string;
25
+ readonly filename?: string;
25
26
  };
26
27
 
27
- export type UserMessagePart = TextPart | ImagePart;
28
-
29
- export type UserMessage = {
28
+ export type RunUserMessage = {
29
+ readonly id: string;
30
30
  readonly role: "user";
31
- readonly parts: readonly UserMessagePart[];
31
+ readonly parts: readonly (TextPart | FilePart)[];
32
+ readonly metadata?: Record<string, unknown>;
32
33
  };
33
34
 
34
- export type AssistantMessage = {
35
- readonly role: "assistant";
36
- readonly parts: readonly TextPart[];
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;
37
39
  };
38
40
 
39
- export type MessageAddCommand = {
40
- readonly type: "message/add";
41
- readonly message: UserMessage | AssistantMessage;
42
- readonly parentId: string | null;
43
- readonly sourceId: string | null;
44
- /**
45
- * How the host handles the message while a run is active: `"queue"`
46
- * appends to the queue, `"steer"` moves it to the front and interrupts
47
- * the run. Absent, the host decides. Ignored when the host is idle.
48
- */
49
- readonly behavior?: "queue" | "steer";
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";
50
78
  };
51
79
 
52
- export type ToolResultAddCommand = {
53
- readonly type: "tool-result/add";
80
+ export type ToolCallInputRequest = {
81
+ readonly type: "tool-call";
82
+ readonly id: string;
54
83
  readonly toolCallId: string;
55
- readonly toolName: string;
56
- readonly result: ReadonlyJSONValue;
57
- readonly isError: boolean;
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;
58
108
  readonly artifact?: ReadonlyJSONValue;
59
- readonly modelContent?: readonly ToolModelContentPart[];
60
109
  };
61
110
 
62
- export type AssistantTransportCommand =
63
- | MessageAddCommand
64
- | ToolResultAddCommand
65
- | UserCommands;
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
+ /** Client-generated id of the regenerated assistant message. */
134
+ readonly messageId: string;
135
+ };
136
+
137
+ export type RunCommand =
138
+ | RunEnqueueCommand
139
+ | RunSteerCommand
140
+ | RunDequeueCommand
141
+ | RunEditCommand
142
+ | RunContinueCommand
143
+ | RunReloadCommand
144
+ | RunInputCommand;
145
+
146
+ export type AssistantTransportCommand = RunCommand | UserCommands;
147
+
148
+ /** A queued message projected out of the host state, wire shape. */
149
+ export type RunQueueItem = {
150
+ readonly id: string;
151
+ readonly parts: readonly (TextPart | FilePart)[];
152
+ };
66
153
 
67
154
  export type AssistantTransportState = {
68
155
  readonly messages: readonly ThreadMessage[];
69
156
  readonly state?: ReadonlyJSONValue;
70
157
  readonly isRunning: boolean;
158
+ /**
159
+ * The host's regular queue lane projected out of the state. Returning it
160
+ * (even empty) turns on the server-side queue: sends become `run/enqueue`
161
+ * / `run/steer` commands and item controls send the `run/*` queue
162
+ * commands. Presence must be stable across conversions and excludes the
163
+ * client-local `capabilities.queue` buffer.
164
+ */
165
+ readonly queue?: readonly RunQueueItem[];
166
+ /** The host's steer lane; requires `queue`. Absent means empty. */
167
+ readonly steerQueue?: readonly RunQueueItem[];
168
+ /**
169
+ * The host's parked input requests projected out of the state. Returning it
170
+ * (even empty) routes tool results and approvals with a matching pending
171
+ * request through `run/input`. Presence must be stable across conversions.
172
+ */
173
+ readonly inputRequests?: readonly InputRequestState[];
71
174
  };
72
175
 
73
176
  export type AssistantTransportConnectionMetadata = {
@@ -139,8 +242,11 @@ export type AssistantTransportOptions<T> = {
139
242
  /**
140
243
  * Buffer messages sent during a run in an in-memory queue and dispatch
141
244
  * them once the run settles. Steering interrupts the active run.
245
+ * Mutually exclusive with the converter's `queue` projection.
142
246
  */
143
247
  queue?: boolean | undefined;
248
+ /** The host supports `run/continue` (a continue affordance on aborted runs). */
249
+ continue?: boolean | undefined;
144
250
  }
145
251
  | undefined;
146
252
  adapters?: