@assistant-ui/react-statewire 0.1.1 → 0.3.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/AssistantTransportThread.d.ts +4 -4
- package/dist/AssistantTransportThread.d.ts.map +1 -1
- package/dist/AssistantTransportThread.js +65 -45
- package/dist/AssistantTransportThread.js.map +1 -1
- package/dist/StatewireThread.d.ts +122 -10
- package/dist/StatewireThread.d.ts.map +1 -1
- package/dist/StatewireThread.js +90 -38
- package/dist/StatewireThread.js.map +1 -1
- package/dist/host.d.ts +0 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +20 -12
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +21 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/inputRequests.d.ts +14 -0
- package/dist/inputRequests.d.ts.map +1 -0
- package/dist/inputRequests.js +35 -0
- package/dist/inputRequests.js.map +1 -0
- package/dist/runCommands.d.ts +22 -0
- package/dist/runCommands.d.ts.map +1 -0
- package/dist/runCommands.js +105 -0
- package/dist/runCommands.js.map +1 -0
- package/dist/types.d.ts +114 -17
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/AssistantTransportThread.ts +120 -50
- package/src/StatewireThread.test.tsx +587 -61
- package/src/StatewireThread.ts +310 -47
- package/src/__tests__/testHelpers.tsx +1 -1
- package/src/athena.e2e.test.tsx +34 -25
- package/src/host.ts +23 -11
- package/src/index.ts +20 -4
- package/src/inputRequests.ts +57 -0
- package/src/legacy-diff.test.tsx +32 -8
- package/src/runCommands.ts +146 -0
- package/src/transport.test.tsx +581 -57
- package/src/types.ts +133 -19
package/src/types.ts
CHANGED
|
@@ -41,6 +41,12 @@ export type AddMessageCommand = {
|
|
|
41
41
|
readonly message: UserMessage | AssistantMessage;
|
|
42
42
|
readonly parentId: string | null;
|
|
43
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";
|
|
44
50
|
};
|
|
45
51
|
|
|
46
52
|
export type AddToolResultCommand = {
|
|
@@ -53,42 +59,147 @@ export type AddToolResultCommand = {
|
|
|
53
59
|
readonly modelContent?: readonly ToolModelContentPart[];
|
|
54
60
|
};
|
|
55
61
|
|
|
56
|
-
export type
|
|
57
|
-
readonly type: "
|
|
58
|
-
readonly
|
|
59
|
-
readonly
|
|
60
|
-
readonly
|
|
61
|
-
|
|
62
|
+
export type FilePart = {
|
|
63
|
+
readonly type: "file";
|
|
64
|
+
readonly mediaType: string;
|
|
65
|
+
readonly url: string;
|
|
66
|
+
readonly filename?: string;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export type RunUserMessage = {
|
|
70
|
+
readonly id: string;
|
|
71
|
+
readonly role: "user";
|
|
72
|
+
readonly parts: readonly (TextPart | FilePart)[];
|
|
73
|
+
readonly metadata?: Record<string, unknown>;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/** Queue placement fields, flat on the command. Absent is load-bearing: it means default placement; `null` names a queue boundary. */
|
|
77
|
+
export type RunPlacement = {
|
|
78
|
+
readonly insertAfter?: string | null;
|
|
79
|
+
readonly insertBefore?: string | null;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export type RunEnqueueCommand = {
|
|
83
|
+
readonly type: "run/enqueue";
|
|
84
|
+
} & ({ readonly message: RunUserMessage } | { readonly messageId: string }) &
|
|
85
|
+
RunPlacement;
|
|
86
|
+
|
|
87
|
+
export type RunSteerCommand = {
|
|
88
|
+
readonly type: "run/steer";
|
|
89
|
+
} & ({ readonly message: RunUserMessage } | { readonly messageId: string }) &
|
|
90
|
+
RunPlacement;
|
|
91
|
+
|
|
92
|
+
export type RunDequeueCommand = {
|
|
93
|
+
readonly type: "run/dequeue";
|
|
94
|
+
readonly messageId: string;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export type RunEditCommand = {
|
|
98
|
+
readonly type: "run/edit";
|
|
99
|
+
readonly message: RunUserMessage;
|
|
100
|
+
readonly sourceId: string;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export type RunContinueCommand = {
|
|
104
|
+
readonly type: "run/continue";
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export type ToolCallInputRequest = {
|
|
108
|
+
readonly type: "tool-call";
|
|
109
|
+
readonly id: string;
|
|
110
|
+
readonly toolCallId: string;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export type ToolApprovalInputRequest = {
|
|
114
|
+
readonly type: "tool-approval";
|
|
115
|
+
readonly id: string;
|
|
116
|
+
readonly toolCallId: string;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export type CustomInputRequest = {
|
|
120
|
+
readonly type: string;
|
|
121
|
+
readonly id: string;
|
|
122
|
+
readonly [key: string]: ReadonlyJSONValue | undefined;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/** A host request parking the run until answered; open union for custom types. */
|
|
126
|
+
export type InputRequest =
|
|
127
|
+
| ToolCallInputRequest
|
|
128
|
+
| ToolApprovalInputRequest
|
|
129
|
+
| CustomInputRequest;
|
|
130
|
+
|
|
131
|
+
export type ToolCallInputResponse = {
|
|
132
|
+
readonly output: ReadonlyJSONValue;
|
|
133
|
+
/** Default false; when true, `output` carries the error payload. */
|
|
134
|
+
readonly isError?: boolean;
|
|
135
|
+
readonly artifact?: ReadonlyJSONValue;
|
|
62
136
|
};
|
|
63
137
|
|
|
64
|
-
export type
|
|
65
|
-
readonly
|
|
66
|
-
readonly
|
|
138
|
+
export type ToolApprovalInputResponse = {
|
|
139
|
+
readonly decision: "approve" | "reject" | "edit" | "respond";
|
|
140
|
+
readonly editedArgs?: ReadonlyJSONValue;
|
|
141
|
+
readonly message?: string;
|
|
67
142
|
};
|
|
68
143
|
|
|
69
|
-
export type
|
|
70
|
-
|
|
71
|
-
|
|
144
|
+
export type InputResponse = ReadonlyJSONValue;
|
|
145
|
+
|
|
146
|
+
export type RunInputCommand = {
|
|
147
|
+
readonly type: "run/input";
|
|
148
|
+
readonly requestId: string;
|
|
149
|
+
readonly response: InputResponse;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/** An input request projected out of the host state with its response echo. */
|
|
153
|
+
export type InputRequestState = InputRequest & {
|
|
154
|
+
readonly response: InputResponse | null;
|
|
72
155
|
};
|
|
73
156
|
|
|
74
|
-
export type
|
|
75
|
-
readonly type: "
|
|
76
|
-
readonly
|
|
157
|
+
export type RunReloadCommand = {
|
|
158
|
+
readonly type: "run/reload";
|
|
159
|
+
readonly sourceId: string;
|
|
77
160
|
};
|
|
78
161
|
|
|
162
|
+
export type RunCommand =
|
|
163
|
+
| RunEnqueueCommand
|
|
164
|
+
| RunSteerCommand
|
|
165
|
+
| RunDequeueCommand
|
|
166
|
+
| RunEditCommand
|
|
167
|
+
| RunContinueCommand
|
|
168
|
+
| RunReloadCommand
|
|
169
|
+
| RunInputCommand;
|
|
170
|
+
|
|
79
171
|
export type AssistantTransportCommand =
|
|
80
172
|
| AddMessageCommand
|
|
81
173
|
| AddToolResultCommand
|
|
82
|
-
|
|
|
83
|
-
| SteerQueueItemCommand
|
|
84
|
-
| RemoveQueueItemCommand
|
|
85
|
-
| ClearQueueCommand
|
|
174
|
+
| RunCommand
|
|
86
175
|
| UserCommands;
|
|
87
176
|
|
|
177
|
+
/** A queued message projected out of the host state, wire shape. */
|
|
178
|
+
export type RunQueueItem = {
|
|
179
|
+
readonly id: string;
|
|
180
|
+
readonly parts: readonly (TextPart | FilePart)[];
|
|
181
|
+
};
|
|
182
|
+
|
|
88
183
|
export type AssistantTransportState = {
|
|
89
184
|
readonly messages: readonly ThreadMessage[];
|
|
90
185
|
readonly state?: ReadonlyJSONValue;
|
|
91
186
|
readonly isRunning: boolean;
|
|
187
|
+
/**
|
|
188
|
+
* The host's regular queue lane projected out of the state. Returning it
|
|
189
|
+
* (even empty) turns on the server-side queue: sends become `run/enqueue`
|
|
190
|
+
* / `run/steer` commands and item controls send the `run/*` queue
|
|
191
|
+
* commands. Presence must be stable across conversions and excludes the
|
|
192
|
+
* client-local `capabilities.queue` buffer.
|
|
193
|
+
*/
|
|
194
|
+
readonly queue?: readonly RunQueueItem[];
|
|
195
|
+
/** The host's steer lane; requires `queue`. Absent means empty. */
|
|
196
|
+
readonly steerQueue?: readonly RunQueueItem[];
|
|
197
|
+
/**
|
|
198
|
+
* The host's parked input requests projected out of the state. Returning it
|
|
199
|
+
* (even empty) routes tool results and approvals with a matching pending
|
|
200
|
+
* request through `run/input`. Presence must be stable across conversions.
|
|
201
|
+
*/
|
|
202
|
+
readonly inputRequests?: readonly InputRequestState[];
|
|
92
203
|
};
|
|
93
204
|
|
|
94
205
|
export type AssistantTransportConnectionMetadata = {
|
|
@@ -160,8 +271,11 @@ export type AssistantTransportOptions<T> = {
|
|
|
160
271
|
/**
|
|
161
272
|
* Buffer messages sent during a run in an in-memory queue and dispatch
|
|
162
273
|
* them once the run settles. Steering interrupts the active run.
|
|
274
|
+
* Mutually exclusive with the converter's `queue` projection.
|
|
163
275
|
*/
|
|
164
276
|
queue?: boolean | undefined;
|
|
277
|
+
/** The host supports `run/continue` (a continue affordance on aborted runs). */
|
|
278
|
+
continue?: boolean | undefined;
|
|
165
279
|
}
|
|
166
280
|
| undefined;
|
|
167
281
|
adapters?:
|