@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/dist/AssistantTransportThread.d.ts +4 -4
- package/dist/AssistantTransportThread.d.ts.map +1 -1
- package/dist/AssistantTransportThread.js +52 -54
- package/dist/AssistantTransportThread.js.map +1 -1
- package/dist/StatewireThread.d.ts +62 -5
- package/dist/StatewireThread.d.ts.map +1 -1
- package/dist/StatewireThread.js +33 -106
- package/dist/StatewireThread.js.map +1 -1
- package/dist/host.d.ts +1 -3
- 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 -7
- 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 +27 -0
- package/dist/runCommands.d.ts.map +1 -0
- package/dist/runCommands.js +109 -0
- package/dist/runCommands.js.map +1 -0
- package/dist/types.d.ts +110 -29
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/AssistantTransportThread.ts +117 -69
- package/src/StatewireThread.test.tsx +294 -40
- package/src/StatewireThread.ts +146 -133
- package/src/__tests__/testHelpers.tsx +19 -2
- package/src/athena.e2e.test.tsx +55 -31
- package/src/host.ts +23 -11
- package/src/index.ts +20 -6
- package/src/inputRequests.ts +60 -0
- package/src/legacy-diff.test.tsx +56 -13
- package/src/runCommands.ts +157 -0
- package/src/transport.test.tsx +609 -86
- package/src/types.ts +138 -32
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
|
|
23
|
-
readonly type: "
|
|
24
|
-
readonly
|
|
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
|
|
28
|
-
|
|
29
|
-
export type UserMessage = {
|
|
28
|
+
export type RunUserMessage = {
|
|
29
|
+
readonly id: string;
|
|
30
30
|
readonly role: "user";
|
|
31
|
-
readonly parts: readonly
|
|
31
|
+
readonly parts: readonly (TextPart | FilePart)[];
|
|
32
|
+
readonly metadata?: Record<string, unknown>;
|
|
32
33
|
};
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
readonly
|
|
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
|
|
40
|
-
readonly type: "
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
|
53
|
-
readonly type: "tool-
|
|
80
|
+
export type ToolCallInputRequest = {
|
|
81
|
+
readonly type: "tool-call";
|
|
82
|
+
readonly id: string;
|
|
54
83
|
readonly toolCallId: string;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
|
63
|
-
|
|
|
64
|
-
|
|
65
|
-
|
|
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?:
|