@assistant-ui/react-statewire 0.11.2 → 0.13.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 +19 -6
- package/dist/AssistantTransportThread.d.ts.map +1 -1
- package/dist/AssistantTransportThread.js +22 -15
- package/dist/AssistantTransportThread.js.map +1 -1
- package/dist/StatewireThread.d.ts +27 -15
- package/dist/StatewireThread.d.ts.map +1 -1
- package/dist/StatewireThread.js +37 -37
- package/dist/StatewireThread.js.map +1 -1
- package/dist/hooks.d.ts +3 -1
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +11 -2
- package/dist/hooks.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/inputRequests.d.ts +2 -2
- package/dist/inputRequests.d.ts.map +1 -1
- package/dist/inputRequests.js +4 -2
- package/dist/inputRequests.js.map +1 -1
- package/dist/runCommands.d.ts +15 -4
- package/dist/runCommands.d.ts.map +1 -1
- package/dist/runCommands.js +27 -11
- package/dist/runCommands.js.map +1 -1
- package/dist/runsOptimistic.d.ts.map +1 -1
- package/dist/runsOptimistic.js +6 -6
- package/dist/runsOptimistic.js.map +1 -1
- package/package.json +1 -1
- package/src/AssistantTransportThread.ts +53 -16
- package/src/StatewireThread.runs.test.tsx +69 -55
- package/src/StatewireThread.test.tsx +40 -53
- package/src/StatewireThread.ts +89 -78
- package/src/athena.e2e.test.tsx +4 -2
- package/src/hooks.ts +11 -0
- package/src/index.ts +1 -0
- package/src/inputRequests.ts +4 -0
- package/src/legacy-diff.test.tsx +2 -1
- package/src/runCommands.ts +48 -10
- package/src/runsOptimistic.test.ts +64 -26
- package/src/runsOptimistic.ts +10 -7
- package/src/transport.test.tsx +46 -9
package/dist/StatewireThread.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createRunQueueAdapter, resolveEditCommand, resolveReloadCommand,
|
|
1
|
+
import { createRunQueueAdapter, resolveEditCommand, resolveReloadCommand, sendFields, toWireMessage } from "./runCommands.js";
|
|
2
2
|
import { runsOptimistic } from "./runsOptimistic.js";
|
|
3
3
|
import { resolveToolApprovalInput, resolveToolResultInput } from "./inputRequests.js";
|
|
4
4
|
import { symbolAssistantTransportExtras } from "./AssistantTransportThread.js";
|
|
@@ -9,12 +9,7 @@ import { forwardTransformScopes, useAssistantClientRef } from "@assistant-ui/sto
|
|
|
9
9
|
import { useStatewire } from "statewire";
|
|
10
10
|
import { toToolsJSONSchema } from "assistant-stream";
|
|
11
11
|
//#region src/StatewireThread.ts
|
|
12
|
-
const
|
|
13
|
-
messages: [],
|
|
14
|
-
isRunning: false
|
|
15
|
-
};
|
|
16
|
-
const READY_RUNS = {
|
|
17
|
-
status: "ready",
|
|
12
|
+
const RESTING_RUNS = {
|
|
18
13
|
runId: null,
|
|
19
14
|
queue: [],
|
|
20
15
|
steerQueue: [],
|
|
@@ -97,18 +92,20 @@ const useStatewireThread = (options) => {
|
|
|
97
92
|
setText((prev_1) => prev_1 === "" ? text : prev_1);
|
|
98
93
|
});
|
|
99
94
|
}, [dispatch]);
|
|
100
|
-
const runs = useMemo(() => {
|
|
101
|
-
if (runsOption === void 0) return
|
|
102
|
-
|
|
103
|
-
const entry =
|
|
104
|
-
return
|
|
105
|
-
status: entry
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
95
|
+
const { status, runs } = useMemo(() => {
|
|
96
|
+
if (runsOption === void 0) return { status: "ready" };
|
|
97
|
+
const entries = (runsOption === true ? state_0 : runsOption(state_0))?.runs;
|
|
98
|
+
const entry = entries?.[0];
|
|
99
|
+
return {
|
|
100
|
+
status: entries === void 0 ? "loading" : entry?.status ?? "ready",
|
|
101
|
+
runs: entry === void 0 ? RESTING_RUNS : {
|
|
102
|
+
runId: entry.runId,
|
|
103
|
+
queue: entry.queue,
|
|
104
|
+
steerQueue: entry.steerQueue,
|
|
105
|
+
dispatching: entry.dispatching,
|
|
106
|
+
...entry.inputRequests !== void 0 && { inputRequests: entry.inputRequests },
|
|
107
|
+
error: entry.error
|
|
108
|
+
}
|
|
112
109
|
};
|
|
113
110
|
}, [runsOption, state_0]);
|
|
114
111
|
const { converter } = options;
|
|
@@ -122,60 +119,60 @@ const useStatewireThread = (options) => {
|
|
|
122
119
|
connection_0,
|
|
123
120
|
runs
|
|
124
121
|
]);
|
|
125
|
-
const converted = useMemo(() =>
|
|
122
|
+
const converted = useMemo(() => converter(state_0, metadata), [
|
|
126
123
|
converter,
|
|
127
124
|
state_0,
|
|
128
125
|
metadata
|
|
129
126
|
]);
|
|
130
127
|
const messages = converted.messages;
|
|
128
|
+
const liveRunId = runs !== void 0 ? runs.runId : converted.runId ?? null;
|
|
131
129
|
const queueItems = runs !== void 0 ? runs.queue : converted.queue;
|
|
132
130
|
const steerQueueItems = runs !== void 0 ? runs.steerQueue : converted.steerQueue;
|
|
133
131
|
if (steerQueueItems !== void 0 && queueItems === void 0) throw new Error("statewire: the converter's steerQueue projection requires the queue projection");
|
|
134
|
-
const [queueSeam] = useState(() => ({ present: void 0 }));
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
const queue = useMemo(() => queueItems ? createRunQueueAdapter(messages, queueItems, steerQueueItems, dispatch, dispatchSend) : void 0, [
|
|
132
|
+
const [queueSeam] = useState(() => ({ present: queueItems !== void 0 }));
|
|
133
|
+
if (queueSeam.present !== (queueItems !== void 0)) throw new Error("statewire: the converter's queue projection must be stable — it was " + (queueSeam.present ? "defined" : "undefined") + " on first convert and changed since");
|
|
134
|
+
const queue = useMemo(() => queueItems ? createRunQueueAdapter(messages, liveRunId, queueItems, steerQueueItems, dispatch, dispatchSend) : void 0, [
|
|
138
135
|
messages,
|
|
136
|
+
liveRunId,
|
|
139
137
|
queueItems,
|
|
140
138
|
steerQueueItems,
|
|
141
139
|
dispatch,
|
|
142
140
|
dispatchSend
|
|
143
141
|
]);
|
|
144
142
|
const inputRequests = runs !== void 0 ? runs.inputRequests ?? [] : converted.inputRequests;
|
|
145
|
-
const [inputSeam] = useState(() => ({ present: void 0 }));
|
|
146
|
-
if (
|
|
147
|
-
if (inputSeam.present !== void 0 && inputSeam.present !== (inputRequests !== void 0)) throw new Error("statewire: the converter's inputRequests projection must be stable — it was " + (inputSeam.present ? "defined" : "undefined") + " on first convert and changed since");
|
|
143
|
+
const [inputSeam] = useState(() => ({ present: inputRequests !== void 0 }));
|
|
144
|
+
if (inputSeam.present !== (inputRequests !== void 0)) throw new Error("statewire: the converter's inputRequests projection must be stable — it was " + (inputSeam.present ? "defined" : "undefined") + " on first convert and changed since");
|
|
148
145
|
const extras = useMemo(() => ({
|
|
149
146
|
[symbolAssistantTransportExtras]: true,
|
|
150
147
|
sendCommand: dispatch,
|
|
151
148
|
reconnect: connection_0.reconnect,
|
|
152
149
|
state: state_0,
|
|
150
|
+
status,
|
|
153
151
|
...inputRequests !== void 0 && { inputRequests },
|
|
154
152
|
...runs !== void 0 && { runs }
|
|
155
153
|
}), [
|
|
156
154
|
dispatch,
|
|
157
155
|
connection_0.reconnect,
|
|
158
156
|
state_0,
|
|
157
|
+
status,
|
|
159
158
|
inputRequests,
|
|
160
159
|
runs
|
|
161
160
|
]);
|
|
162
161
|
const handleAppend = (message_0) => {
|
|
163
|
-
dispatchSend(message_0.sourceId != null ? resolveEditCommand(messages, message_0) : {
|
|
162
|
+
dispatchSend(message_0.sourceId != null ? resolveEditCommand(messages, message_0, liveRunId) : {
|
|
164
163
|
type: "run/steer",
|
|
165
|
-
|
|
166
|
-
anchorMessageId: viewedLeafId(messages)
|
|
164
|
+
...sendFields(messages, liveRunId, toWireMessage(message_0, crypto.randomUUID()))
|
|
167
165
|
}, message_0);
|
|
168
166
|
};
|
|
169
167
|
const handleReload = (parentId) => {
|
|
170
|
-
dispatch(resolveReloadCommand(messages, parentId));
|
|
168
|
+
dispatch(resolveReloadCommand(messages, parentId, liveRunId));
|
|
171
169
|
};
|
|
172
170
|
const handleEdit = (message_1) => {
|
|
173
|
-
dispatch(resolveEditCommand(messages, message_1));
|
|
171
|
+
dispatch(resolveEditCommand(messages, message_1, liveRunId));
|
|
174
172
|
};
|
|
175
173
|
const thread = useResource(ExternalThread({
|
|
176
174
|
messages,
|
|
177
|
-
isRunning: runs !== void 0 ?
|
|
178
|
-
isLoading: state_0 === void 0,
|
|
175
|
+
isRunning: runs !== void 0 ? status === "running" : converted.isRunning,
|
|
179
176
|
state: converted.state,
|
|
180
177
|
extras,
|
|
181
178
|
attachmentAdapter: options.adapters?.attachments,
|
|
@@ -184,11 +181,14 @@ const useStatewireThread = (options) => {
|
|
|
184
181
|
onNew: handleAppend,
|
|
185
182
|
...queue && { queue },
|
|
186
183
|
...options.capabilities?.edit && { onEdit: handleEdit },
|
|
187
|
-
...options.capabilities?.continue && { onResume: () => dispatch({
|
|
184
|
+
...options.capabilities?.continue && { onResume: () => dispatch({
|
|
185
|
+
type: "run/continue",
|
|
186
|
+
...liveRunId !== null && { runId: liveRunId }
|
|
187
|
+
}) },
|
|
188
188
|
...options.capabilities?.reload && { onReload: handleReload },
|
|
189
189
|
...inputRequests !== void 0 && {
|
|
190
|
-
onAddToolResult: (toolOptions) => dispatch(resolveToolResultInput(inputRequests, toolOptions)),
|
|
191
|
-
onRespondToToolApproval: (approval) => dispatch(resolveToolApprovalInput(inputRequests, approval))
|
|
190
|
+
onAddToolResult: (toolOptions) => dispatch(resolveToolResultInput(inputRequests, toolOptions, liveRunId)),
|
|
191
|
+
onRespondToToolApproval: (approval) => dispatch(resolveToolApprovalInput(inputRequests, approval, liveRunId))
|
|
192
192
|
},
|
|
193
193
|
onCancel: () => {
|
|
194
194
|
const payload = latest.current.stopPayload?.();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatewireThread.js","names":["useCallback","useEffect","useMemo","useRef","useState","resource","useResource","ResourceElement","ExternalThread","ExternalThreadMessage","forwardTransformScopes","useAssistantClientRef","ClientOutput","AddToolResultOptions","AppendMessage","AttachmentAdapter","ExternalThreadQueueAdapter","FeedbackAdapter","ModelContext","RespondToToolApprovalOptions","SpeechSynthesisAdapter","ThreadMessage","toToolsJSONSchema","ReadonlyJSONValue","useStatewire","Statewire","StatewireClient","symbolAssistantTransportExtras","AssistantTransportExtras","AssistantTransportThread","createRunQueueAdapter","resolveEditCommand","resolveReloadCommand","toWireMessage","viewedLeafId","resolveToolApprovalInput","resolveToolResultInput","runsOptimistic","AnyCommands","Record","args","AnyOptions","StatewireThread","Options","RunsOptions","LOADING_STATE","State","messages","isRunning","READY_RUNS","Runs","status","runId","queue","steerQueue","dispatching","error","ambientContextOf","context","system","undefined","tools","callSettings","config","useStatewireThread","options","latest","current","pending","setPending","Command","retire","command","prev","includes","filter","c","runsOption","runs","runsSeam","Error","materializeOption","materialize","materializeSeam","state","commands","connection","setContext","transport","initialState","optimistic","draft","ctx","runsOpt","onCommandChange","update","params","onStateChange","onConnectionChange","clientRef","setContextRef","syncState","lastSent","contextSync","modelContext","parent","send","value","getModelContext","key","JSON","stringify","catch","onError","subscribe","dispatch","settled","type","threadRef","dispatchSend","message","sourceId","text","content","flatMap","part","join","setText","composer","next","mount","RunsState","entry","inputRequests","converter","metadata","ConnectionMetadata","pendingCommands","isSending","length","converted","queueItems","steerQueueItems","queueSeam","present","inputSeam","extras","sendCommand","reconnect","handleAppend","crypto","randomUUID","anchorMessageId","handleReload","parentId","handleEdit","thread","isLoading","attachmentAdapter","adapters","attachments","speechAdapter","speech","feedbackAdapter","feedback","onNew","capabilities","edit","onEdit","continue","onResume","reload","onReload","onAddToolResult","toolOptions","onRespondToToolApproval","approval","onCancel","payload","stopPayload","Array","isArray","T","Transport","TextPart","FilePart","mediaType","url","filename","UserMessage","id","role","parts","Placement","insertAfter","insertBefore","RunEnqueueCommand","messageId","RunSteerCommand","RunDequeueCommand","RunEditCommand","rollbackTo","RunContinueCommand","ToolCallInputRequest","toolCallId","ToolApprovalInputRequest","CustomInputRequest","InputRequest","ToolCallInputResponse","output","isError","artifact","ToolApprovalInputResponse","decision","editedArgs","InputResponse","RunInputCommand","requestId","response","InputRequestState","RunReloadCommand","RunCommand","QueueItem","RunStatus","RunsQueueEntry","meta","RunsInputOutcome","request","RunsDispatch","trigger","inputOutcomes","RunsError","RunState","Exclude","MaterializeEffects","append","rollback","to","ConnectionState","StateConverter","connectionMetadata","RunsConverterState","RunsStateConverter","StopPayload","reason","CommandUpdate","NonNullable","changes","Changes","Connection","Omit","Optimistic","Materialize","Assistant","Commands","runEnqueue","runSteer","runDequeue","runEdit","runContinue","runReload","runInput","hook"],"sources":["../src/StatewireThread.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { resource, useResource } from \"@assistant-ui/tap\";\nimport type { ResourceElement } from \"@assistant-ui/tap\";\nimport { ExternalThread } from \"@assistant-ui/react\";\nimport type { ExternalThreadMessage } from \"@assistant-ui/react\";\nimport {\n forwardTransformScopes,\n useAssistantClientRef,\n} from \"@assistant-ui/store\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport type {\n AddToolResultOptions,\n AppendMessage,\n AttachmentAdapter,\n ExternalThreadQueueAdapter,\n FeedbackAdapter,\n ModelContext,\n RespondToToolApprovalOptions,\n SpeechSynthesisAdapter,\n ThreadMessage,\n} from \"@assistant-ui/core\";\nimport { toToolsJSONSchema } from \"assistant-stream\";\nimport type { ReadonlyJSONValue } from \"assistant-stream/utils\";\nimport { useStatewire } from \"statewire\";\nimport type { Statewire, StatewireClient } from \"statewire\";\nimport { symbolAssistantTransportExtras } from \"./AssistantTransportThread\";\nimport type {\n AssistantTransportExtras,\n AssistantTransportThread,\n} from \"./AssistantTransportThread\";\nimport {\n createRunQueueAdapter,\n resolveEditCommand,\n resolveReloadCommand,\n toWireMessage,\n viewedLeafId,\n} from \"./runCommands\";\nimport {\n resolveToolApprovalInput,\n resolveToolResultInput,\n} from \"./inputRequests\";\nimport { runsOptimistic } from \"./runsOptimistic\";\n\ntype AnyCommands = Record<string, (...args: any[]) => unknown>;\n\ntype AnyOptions =\n | StatewireThread.Options<any>\n | StatewireThread.RunsOptions<any>;\n\nconst LOADING_STATE: StatewireThread.State = { messages: [], isRunning: false };\n\nconst READY_RUNS: StatewireThread.Runs = {\n status: \"ready\",\n runId: null,\n queue: [],\n steerQueue: [],\n dispatching: null,\n error: null,\n};\n\nconst ambientContextOf = (context: ModelContext): Record<string, unknown> => ({\n ...(context.system !== undefined && { system: context.system }),\n ...(context.tools !== undefined && {\n tools: toToolsJSONSchema(context.tools),\n }),\n ...(context.callSettings !== undefined && {\n callSettings: context.callSettings,\n }),\n ...(context.config !== undefined && { config: context.config }),\n});\n\nconst useStatewireThread = (options: AnyOptions): ClientOutput<\"thread\"> => {\n const latest = useRef(options);\n latest.current = options;\n\n const [pending, setPending] = useState<readonly StatewireThread.Command[]>(\n [],\n );\n const [retire] = useState(\n () => (command: unknown) =>\n setPending((prev) =>\n prev.includes(command as StatewireThread.Command)\n ? prev.filter((c) => c !== command)\n : prev,\n ),\n );\n\n const runsOption = options.runs;\n const [runsSeam] = useState(() => runsOption !== undefined);\n if (runsSeam !== (runsOption !== undefined))\n throw new Error(\n \"statewire: the runs option must be stable — it was \" +\n (runsSeam ? \"set\" : \"unset\") +\n \" on first render and changed since\",\n );\n\n const materializeOption = (options as StatewireThread.RunsOptions<unknown>)\n .materialize;\n const [materializeSeam] = useState(() => materializeOption !== undefined);\n if (materializeSeam !== (materializeOption !== undefined))\n throw new Error(\n \"statewire: the materialize option must be stable — it was \" +\n (materializeSeam ? \"set\" : \"unset\") +\n \" on first render and changed since\",\n );\n\n const { state, commands, connection, setContext } = useStatewire<\n unknown,\n AnyCommands\n >({\n transport: options.transport,\n initialState: options.initialState,\n ...(runsSeam && {\n optimistic: (draft, command, ctx) => {\n const runsOpt = latest.current.runs!;\n runsOptimistic(runsOpt === true ? draft : runsOpt(draft), command, ctx);\n (latest.current as StatewireThread.RunsOptions<unknown>).optimistic?.(\n draft,\n command,\n ctx,\n );\n },\n }),\n ...(materializeSeam && {\n materialize: (draft: {}) =>\n (latest.current as StatewireThread.RunsOptions<unknown>).materialize!(\n draft,\n ),\n }),\n onCommandChange: (update, ctx) => {\n if (update.status === \"acked\" || update.status === \"settled\")\n retire(update.params[0]);\n latest.current.onCommandChange?.(update, ctx);\n },\n onStateChange: (state, ctx) => latest.current.onStateChange?.(state, ctx),\n onConnectionChange: (connection) =>\n latest.current.onConnectionChange?.(connection),\n });\n\n const clientRef = useAssistantClientRef();\n const setContextRef = useRef(setContext);\n setContextRef.current = setContext;\n const [syncState] = useState(() => ({ lastSent: undefined as unknown }));\n const { contextSync } = options;\n useEffect(() => {\n if (contextSync === undefined) return;\n const modelContext = (clientRef.current ?? clientRef.parent).modelContext();\n const send = () => {\n const value = ambientContextOf(modelContext.getModelContext());\n const key = JSON.stringify(value);\n if (key === syncState.lastSent) return;\n syncState.lastSent = key;\n void setContextRef.current(value).catch((error: Error) => {\n latest.current.onError?.(error);\n });\n };\n send();\n if (!modelContext.subscribe) {\n throw new Error(\n \"statewire: contextSync requires a subscribable model context\",\n );\n }\n return modelContext.subscribe(send);\n }, [contextSync, clientRef, syncState]);\n\n const dispatch = useCallback(\n (command: StatewireThread.Command) => {\n setPending((prev) => [...prev, command]);\n const settled = commands[command.type]!(command);\n settled.catch((error: Error) => {\n retire(command);\n latest.current.onError?.(error);\n });\n return settled;\n },\n [commands, retire],\n );\n\n const threadRef = useRef<ClientOutput<\"thread\"> | null>(null);\n const dispatchSend = useCallback(\n (command: StatewireThread.Command, message: AppendMessage) => {\n if (message.sourceId != null) return void dispatch(command);\n const text = message.content\n .flatMap((part) => (part.type === \"text\" ? [part.text] : []))\n .join(\"\\n\\n\");\n void dispatch(command).catch(() => {\n // Rejected send: put the text back unless the user typed since.\n // ExternalThread's setText is live-ref-backed and takes an updater.\n const setText = threadRef.current!.composer().setText as (\n next: string | ((prev: string) => string),\n ) => void;\n setText((prev) => (prev === \"\" ? text : prev));\n });\n },\n [dispatch],\n );\n\n const runs = useMemo((): StatewireThread.Runs | undefined => {\n if (runsOption === undefined) return undefined;\n if (state === undefined) return READY_RUNS;\n const mount = (runsOption === true ? state : runsOption(state)) as\n | StatewireThread.RunsState\n | undefined;\n const entry = mount?.runs?.[0];\n return entry === undefined\n ? READY_RUNS\n : {\n status: entry.status,\n runId: entry.runId,\n queue: entry.queue,\n steerQueue: entry.steerQueue,\n dispatching: entry.dispatching,\n ...(entry.inputRequests !== undefined && {\n inputRequests: entry.inputRequests,\n }),\n error: entry.error,\n };\n }, [runsOption, state]);\n\n const { converter } = options;\n const metadata = useMemo(\n (): StatewireThread.ConnectionMetadata => ({\n pendingCommands: [...pending],\n isSending: pending.length > 0,\n connection,\n ...(runs !== undefined && { runs }),\n }),\n [pending, connection, runs],\n );\n const converted = useMemo(\n (): StatewireThread.State =>\n state === undefined\n ? LOADING_STATE\n : (converter(\n state,\n metadata as StatewireThread.ConnectionMetadata & {\n runs: StatewireThread.Runs;\n },\n ) as StatewireThread.State),\n [converter, state, metadata],\n );\n // Dispatch limbo is a materialize concern: the fold makes the record\n // concrete in state before conversion.\n const messages = converted.messages;\n const queueItems = runs !== undefined ? runs.queue : converted.queue;\n const steerQueueItems =\n runs !== undefined ? runs.steerQueue : converted.steerQueue;\n if (steerQueueItems !== undefined && queueItems === undefined)\n throw new Error(\n \"statewire: the converter's steerQueue projection requires the queue projection\",\n );\n // Seams anchor at the first real convert; the loading placeholder projects nothing.\n const [queueSeam] = useState(() => ({\n present: undefined as boolean | undefined,\n }));\n if (state !== undefined && queueSeam.present === undefined)\n queueSeam.present = queueItems !== undefined;\n if (\n queueSeam.present !== undefined &&\n queueSeam.present !== (queueItems !== undefined)\n )\n throw new Error(\n \"statewire: the converter's queue projection must be stable — it was \" +\n (queueSeam.present ? \"defined\" : \"undefined\") +\n \" on first convert and changed since\",\n );\n\n const queue = useMemo(\n (): ExternalThreadQueueAdapter | undefined =>\n queueItems\n ? createRunQueueAdapter(\n messages,\n queueItems,\n steerQueueItems,\n dispatch,\n dispatchSend,\n )\n : undefined,\n [messages, queueItems, steerQueueItems, dispatch, dispatchSend],\n );\n\n const inputRequests =\n runs !== undefined ? (runs.inputRequests ?? []) : converted.inputRequests;\n const [inputSeam] = useState(() => ({\n present: undefined as boolean | undefined,\n }));\n if (state !== undefined && inputSeam.present === undefined)\n inputSeam.present = inputRequests !== undefined;\n if (\n inputSeam.present !== undefined &&\n inputSeam.present !== (inputRequests !== undefined)\n )\n throw new Error(\n \"statewire: the converter's inputRequests projection must be stable — it was \" +\n (inputSeam.present ? \"defined\" : \"undefined\") +\n \" on first convert and changed since\",\n );\n\n const extras = useMemo(\n (): AssistantTransportExtras => ({\n [symbolAssistantTransportExtras]: true,\n sendCommand: dispatch,\n reconnect: connection.reconnect,\n state,\n ...(inputRequests !== undefined && { inputRequests }),\n ...(runs !== undefined && { runs }),\n }),\n [dispatch, connection.reconnect, state, inputRequests, runs],\n );\n\n const handleAppend = (message: AppendMessage) => {\n dispatchSend(\n message.sourceId != null\n ? resolveEditCommand(messages, message)\n : {\n type: \"run/steer\",\n message: toWireMessage(message, crypto.randomUUID()),\n anchorMessageId: viewedLeafId(messages),\n },\n message,\n );\n };\n\n const handleReload = (parentId: string | null) => {\n dispatch(resolveReloadCommand(messages, parentId));\n };\n\n const handleEdit = (message: AppendMessage) => {\n dispatch(resolveEditCommand(messages, message));\n };\n\n const thread = useResource(\n ExternalThread({\n messages: messages as readonly ExternalThreadMessage[],\n isRunning:\n runs !== undefined ? runs.status === \"running\" : converted.isRunning,\n isLoading: state === undefined,\n state: converted.state,\n extras,\n attachmentAdapter: options.adapters?.attachments,\n speechAdapter: options.adapters?.speech,\n feedbackAdapter: options.adapters?.feedback,\n onNew: handleAppend,\n ...(queue && { queue }),\n ...(options.capabilities?.edit && { onEdit: handleEdit }),\n ...(options.capabilities?.continue && {\n onResume: () => dispatch({ type: \"run/continue\" }),\n }),\n ...(options.capabilities?.reload && { onReload: handleReload }),\n ...(inputRequests !== undefined && {\n onAddToolResult: (toolOptions: AddToolResultOptions) =>\n dispatch(resolveToolResultInput(inputRequests, toolOptions)),\n onRespondToToolApproval: (approval: RespondToToolApprovalOptions) =>\n dispatch(resolveToolApprovalInput(inputRequests, approval)),\n }),\n onCancel: () => {\n const payload = latest.current.stopPayload?.();\n if (\n payload !== undefined &&\n (typeof payload !== \"object\" ||\n payload === null ||\n Array.isArray(payload))\n )\n throw new Error(\"statewire: stopPayload must return a plain object\");\n const runId = runs !== undefined ? runs.runId : converted.runId;\n const args =\n runId === undefined\n ? payload === undefined\n ? []\n : [payload]\n : [{ ...payload, runId }];\n void commands[\"run/stop\"]!(...args).catch((error: Error) => {\n latest.current.onError?.(error);\n });\n },\n }),\n );\n threadRef.current = thread;\n return thread;\n};\n\nexport const StatewireThread: {\n <T>(\n options: StatewireThread.RunsOptions<T>,\n ): ResourceElement<ClientOutput<\"thread\">>;\n <T>(\n options: StatewireThread.Options<T>,\n ): ResourceElement<ClientOutput<\"thread\">>;\n} = (options: AnyOptions): ResourceElement<ClientOutput<\"thread\">> =>\n resource(useStatewireThread)(options);\n\nexport namespace StatewireThread {\n export type Transport<T> = ResourceElement<Statewire<T | undefined, any>>;\n\n export type TextPart = {\n readonly type: \"text\";\n readonly text: string;\n };\n\n export type FilePart = {\n readonly type: \"file\";\n readonly mediaType: string;\n readonly url: string;\n readonly filename?: string;\n };\n\n export type UserMessage = {\n readonly id: string;\n readonly role: \"user\";\n readonly parts: readonly (TextPart | FilePart)[];\n readonly metadata?: Record<string, unknown>;\n };\n\n /** Queue placement fields, flat on the command. Absent is load-bearing: it means default placement; `null` names a queue boundary. */\n export type Placement = {\n readonly insertAfter?: string | null;\n readonly insertBefore?: string | null;\n };\n\n export type RunEnqueueCommand = {\n readonly type: \"run/enqueue\";\n } & (\n | {\n readonly message: UserMessage;\n /** 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. */\n readonly anchorMessageId?: string | null;\n }\n | { readonly messageId: string }\n ) &\n Placement;\n\n export type RunSteerCommand = {\n readonly type: \"run/steer\";\n } & (\n | {\n readonly message: UserMessage;\n /** 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. */\n readonly anchorMessageId?: string | null;\n }\n | { readonly messageId: string }\n ) &\n Placement;\n\n export type RunDequeueCommand = {\n readonly type: \"run/dequeue\";\n readonly messageId: string;\n };\n\n export type RunEditCommand = {\n readonly type: \"run/edit\";\n readonly message: UserMessage;\n readonly sourceId: string;\n /** Asserts `sourceId`'s parent — the rewind target; null names the root. */\n readonly rollbackTo: string | null;\n };\n\n export type RunContinueCommand = {\n readonly type: \"run/continue\";\n };\n\n export type ToolCallInputRequest = {\n readonly type: \"tool-call\";\n readonly id: string;\n readonly toolCallId: string;\n };\n\n export type ToolApprovalInputRequest = {\n readonly type: \"tool-approval\";\n readonly id: string;\n readonly toolCallId: string;\n };\n\n export type CustomInputRequest = {\n readonly type: string;\n readonly id: string;\n readonly [key: string]: ReadonlyJSONValue | undefined;\n };\n\n /** A host request parking the run until answered; open union for custom types. */\n export type InputRequest =\n | ToolCallInputRequest\n | ToolApprovalInputRequest\n | CustomInputRequest;\n\n export type ToolCallInputResponse = {\n readonly output: ReadonlyJSONValue;\n /** Default false; when true, `output` carries the error payload. */\n readonly isError?: boolean;\n readonly artifact?: ReadonlyJSONValue;\n };\n\n export type ToolApprovalInputResponse = {\n readonly decision: \"approve\" | \"reject\" | \"edit\" | \"respond\";\n readonly editedArgs?: ReadonlyJSONValue;\n readonly message?: string;\n };\n\n export type InputResponse = ReadonlyJSONValue;\n\n export type RunInputCommand = {\n readonly type: \"run/input\";\n readonly requestId: string;\n readonly response: InputResponse;\n };\n\n /** An input request projected out of the host state with its response echo. */\n export type InputRequestState = InputRequest & {\n readonly response: InputResponse | null;\n };\n\n export type RunReloadCommand = {\n readonly type: \"run/reload\";\n readonly sourceId: string;\n /** Asserts `sourceId`'s parent — the rewind target; null names the root. */\n readonly rollbackTo: string | null;\n };\n\n export type RunCommand =\n | RunEnqueueCommand\n | RunSteerCommand\n | RunDequeueCommand\n | RunEditCommand\n | RunContinueCommand\n | RunReloadCommand\n | RunInputCommand;\n\n export type Command = AssistantTransportThread.Command | RunCommand;\n\n /** A queued message projected out of the host state, wire shape. */\n export type QueueItem = {\n readonly id: string;\n readonly parts: readonly (TextPart | FilePart)[];\n };\n\n export type State = {\n readonly messages: readonly ThreadMessage[];\n readonly state?: ReadonlyJSONValue;\n readonly isRunning: boolean;\n /** The live run's id projected out of the host state; stamped onto `run/stop`. */\n readonly runId?: string | null;\n /**\n * The host's regular queue lane projected out of the state. Returning it\n * (even empty) turns on the queue capability: sends become `run/enqueue`\n * / `run/steer` commands and item controls send the `run/*` queue\n * commands. Presence must be stable across conversions.\n */\n readonly queue?: readonly QueueItem[];\n /** The host's steer lane; requires `queue`. Absent means empty. */\n readonly steerQueue?: readonly QueueItem[];\n /**\n * The host's parked input requests projected out of the state. Returning\n * it (even empty) routes tool results and approvals with a matching\n * pending request through `run/input`. Presence must be stable across\n * conversions.\n */\n readonly inputRequests?: readonly InputRequestState[];\n };\n\n /** Run subsystem status replicated by the host. */\n export type RunStatus =\n | \"ready\"\n | \"running\"\n | \"stopped\"\n | \"error\"\n | \"input-required\";\n\n /** A queue-lane entry as replicated: the user message plus host-stamped `meta`. */\n export type RunsQueueEntry = UserMessage & {\n /** Host-stamped opaque per-entry metadata. */\n readonly meta?: ReadonlyJSONValue;\n };\n\n /** An input outcome riding a dispatch record: the request with its response (null = abandoned) and `run/input` meta. */\n export type RunsInputOutcome = {\n readonly request: InputRequest;\n readonly response: InputResponse | null;\n readonly meta: ReadonlyJSONValue | null;\n };\n\n /** The dispatch record — the unacked batch handed to the run; null between the ack and the next dispatch or take. */\n export type RunsDispatch = {\n readonly trigger:\n | \"message-send\"\n | \"message-edit\"\n | \"message-reload\"\n | \"input-resume\"\n | \"error-continue\"\n | \"stop-continue\"\n | \"steer\";\n readonly messages: readonly RunsQueueEntry[];\n /** Present on rewind dispatches: truncate the thread at this id first; null names the root. */\n readonly rollbackTo?: string | null;\n /** Present when input outcomes ride the dispatch; visible until the ack. */\n readonly inputOutcomes?: readonly RunsInputOutcome[];\n };\n\n /** The replicated run error — set on an unhandled failure, cleared by the next user-initiated run. */\n export type RunsError = {\n readonly message: string;\n readonly [key: string]: ReadonlyJSONValue | undefined;\n };\n\n /** A replicated run entry — one element of the mount's `runs` array. */\n export type RunState = {\n /** The run's identity — minted at dispatch, persists through input-required, null in error/stop. */\n readonly runId: string | null;\n readonly status: Exclude<RunStatus, \"ready\">;\n readonly queue: readonly RunsQueueEntry[];\n readonly steerQueue: readonly RunsQueueEntry[];\n /** The dispatch record — the unacked batch handed to the run, cleared at the ack. */\n readonly dispatching: RunsDispatch | null;\n /** The parked pending set; present only in input-required. */\n readonly inputRequests?: readonly InputRequestState[];\n readonly error: RunsError | null;\n };\n\n /** App-shaped effects `runsMaterialize` applies for the dispatch record. */\n export type MaterializeEffects = {\n /** Append one dispatched message to the app's committed message state. */\n append: (message: RunsQueueEntry) => void;\n /** Truncate to the rolled-back view first (null names the root); required for hosts that dispatch edits/reloads. */\n rollback?: (to: string | null) => void;\n };\n\n /** The runs mount as replicated: the run entries plus the top-level status projection. */\n export type RunsState = {\n /** Projection of `runs[0]?.status ?? \"ready\"`. */\n readonly status: RunStatus;\n /** At most one entry; empty while resting. */\n readonly runs: readonly RunState[];\n };\n\n /** The run subsystem's typed read — `runs[0]` of the selected mount with unsettled commands folded in, ready defaults while resting. */\n export type Runs = {\n readonly status: RunStatus;\n /** The live run's id — non-null in running and input-required; stamped onto `run/stop`. */\n readonly runId: string | null;\n readonly queue: readonly RunsQueueEntry[];\n readonly steerQueue: readonly RunsQueueEntry[];\n /** The dispatch record — the unacked batch handed to the run, cleared at the ack. */\n readonly dispatching: RunsDispatch | null;\n /** The parked pending set; present only in input-required. */\n readonly inputRequests?: readonly InputRequestState[];\n readonly error: RunsError | null;\n };\n\n export type ConnectionMetadata = {\n pendingCommands: Command[];\n isSending: boolean;\n /** Statewire connection status; local transports are always `live`. */\n connection: StatewireClient.ConnectionState;\n /** The typed runs read; present iff the `runs` option is set. */\n runs?: Runs;\n };\n\n export type StateConverter<T> = (\n state: T,\n connectionMetadata: ConnectionMetadata,\n ) => State;\n\n /** Converter output in runs mode: app-owned keys only — the lib projects the run mounts itself. */\n export type RunsConverterState = {\n readonly messages: readonly ThreadMessage[];\n readonly state?: ReadonlyJSONValue;\n };\n\n export type RunsStateConverter<T> = (\n state: T,\n connectionMetadata: ConnectionMetadata & { runs: Runs },\n ) => RunsConverterState;\n\n /**\n * Payload of the built-in `run/stop` command. `reason` is the one well-known\n * field; apps extend it with their own JSON-serializable fields.\n */\n export type StopPayload = {\n readonly reason?: string | undefined;\n readonly [key: string]: ReadonlyJSONValue | undefined;\n };\n\n export type Options<T> = {\n transport: Transport<T>;\n /** Preloads the thread: published and interactive from the first render, replaced by the attach snapshot. Omitted, the thread stays loading until attach. */\n initialState?: T | undefined;\n converter: StateConverter<T>;\n runs?: undefined;\n /**\n * \"command-send\" mirrors the client's ambient model context (system,\n * tools, callSettings, config) to the server over the command channel —\n * on connect and whenever it changes. Requires a remote transport.\n */\n contextSync?: \"command-send\" | undefined;\n /** Supplies the `run/stop` command's payload; omitted, stop sends no payload. */\n stopPayload?: (() => StopPayload) | undefined;\n /** Observes each command's lifecycle (queued, posted, acked, settled); runs after the built-in pending-command retirement. */\n onCommandChange?:\n | ((\n update: Statewire.CommandUpdate<\n Record<string, (...args: any[]) => unknown>\n >,\n ctx: { state: NonNullable<T> },\n ) => void)\n | undefined;\n /** Observes the transport state: fires with the attach snapshot, then once per change. */\n onStateChange?:\n | ((state: NonNullable<T>, ctx: { changes: Statewire.Changes }) => void)\n | undefined;\n /** Observes connection status transitions, starting with the initial status. */\n onConnectionChange?:\n | ((connection: StatewireClient.Connection) => void)\n | undefined;\n onError?: ((error: Error) => void) | undefined;\n capabilities?:\n | {\n edit?: boolean | undefined;\n /** The host supports `run/continue` (a continue affordance on aborted runs). */\n continue?: boolean | undefined;\n /** The host supports `run/reload` (regenerating an assistant message). */\n reload?: boolean | undefined;\n }\n | undefined;\n adapters?:\n | {\n attachments?: AttachmentAdapter | undefined;\n speech?: SpeechSynthesisAdapter | undefined;\n feedback?: FeedbackAdapter | undefined;\n }\n | undefined;\n };\n\n /** Options with the runs read enabled: the lib types the run mounts and the converter returns app-owned keys only. */\n export type RunsOptions<T> = Omit<Options<T>, \"converter\" | \"runs\"> & {\n /** `true` reads the run mounts off the state root; a selector picks a nested mount. */\n runs: true | ((state: T) => unknown);\n converter: RunsStateConverter<T>;\n /** Folds app-owned keys for an unsettled command into the draft; runs after the lib's run-dialect reducer. */\n optimistic?:\n | StatewireClient.Optimistic<\n T,\n Record<string, (...args: any[]) => unknown>\n >\n | undefined;\n /** Makes dispatch records concrete in the draft (runs after the optimistic folds); without it, dispatch limbo stays out of `messages`. */\n materialize?: StatewireClient.Materialize<NonNullable<T>> | undefined;\n };\n}\n\ndeclare module \"@assistant-ui/react\" {\n namespace Assistant {\n interface Commands {\n runEnqueue: StatewireThread.RunEnqueueCommand;\n runSteer: StatewireThread.RunSteerCommand;\n runDequeue: StatewireThread.RunDequeueCommand;\n runEdit: StatewireThread.RunEditCommand;\n runContinue: StatewireThread.RunContinueCommand;\n runReload: StatewireThread.RunReloadCommand;\n runInput: StatewireThread.RunInputCommand;\n }\n }\n}\n\n// Scope transforms are keyed by the underlying hook, not the resource wrapper.\nforwardTransformScopes(\n useStatewireThread,\n ExternalThread(undefined as never).hook,\n);\n"],"mappings":";;;;;;;;;;;AAiDA,MAAM6C,gBAAuC;CAAEE,UAAU,CAAA;CAAIC,WAAW;AAAM;AAE9E,MAAMC,aAAmC;CACvCE,QAAQ;CACRC,OAAO;CACPC,OAAO,CAAA;CACPC,YAAY,CAAA;CACZC,aAAa;CACbC,OAAO;AACT;AAEA,MAAMC,oBAAoBC,aAAoD;CAC5E,GAAIA,QAAQC,WAAWC,KAAAA,KAAa,EAAED,QAAQD,Q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EAAEC,QAAQb,WAAW;EACvD,GAAI1F,QAAQqG,cAAcG,YAAY,EACpCC,gBAAgBvD,SAAS,EAAEE,MAAM,eAAe,CAAC,EACnD;EACA,GAAIpD,QAAQqG,cAAcK,UAAU,EAAEC,UAAUnB,aAAa;EAC7D,GAAIpB,kBAAkBzE,KAAAA,KAAa;GACjCiH,kBAAkBC,gBAChB3D,SAAS/E,uBAAuBiG,eAAeyC,WAAW,CAAC;GAC7DC,0BAA0BC,aACxB7D,SAAShF,yBAAyBkG,eAAe2C,QAAQ,CAAC;EAC9D;EACAC,gBAAgB;GACd,MAAMC,UAAUhH,OAAOC,QAAQgH,cAAc;GAC7C,IACED,YAAYtH,KAAAA,MACX,OAAOsH,YAAY,YAClBA,YAAY,QACZE,MAAMC,QAAQH,OAAO,IAEvB,MAAM,IAAIlG,MAAM,mDAAmD;GACrE,MAAM5B,QAAQ0B,SAASlB,KAAAA,IAAYkB,KAAK1B,QAAQwF,UAAUxF;GAC1D,MAAMZ,OACJY,UAAUQ,KAAAA,IACNsH,YAAYtH,KAAAA,IACV,CAAA,IACA,CAACsH,OAAO,IACV,CAAC;IAAE,GAAGA;IAAS9H;GAAM,CAAC;GAC5B,SAAc,WAAW,CAAE,GAAGZ,IAAI,CAAC,CAACwE,OAAOxD,YAAiB;IAC1DU,OAAOC,QAAQ8C,UAAUzD,OAAK;GAChC,CAAC;EACH;CACF,CAAC,CACH;CACA8D,UAAUnD,UAAUyF;CACpB,OAAOA;AACT;AAEA,MAAalH,mBAORuB,YACH5D,SAAS2D,kBAAkB,CAAC,CAACC,OAAO;AAqXtCvD,uBACEsD,oBACAxD,eAAeoD,KAAAA,CAAkB,CAAC,CAAC0M,IACrC"}
|
|
1
|
+
{"version":3,"file":"StatewireThread.js","names":["useCallback","useEffect","useMemo","useRef","useState","resource","useResource","ResourceElement","ExternalThread","ExternalThreadMessage","forwardTransformScopes","useAssistantClientRef","ClientOutput","AddToolResultOptions","AppendMessage","AttachmentAdapter","ExternalThreadQueueAdapter","FeedbackAdapter","ModelContext","RespondToToolApprovalOptions","SpeechSynthesisAdapter","ThreadMessage","toToolsJSONSchema","ReadonlyJSONValue","useStatewire","Statewire","StatewireClient","symbolAssistantTransportExtras","AssistantTransportExtras","AssistantTransportThread","createRunQueueAdapter","resolveEditCommand","resolveReloadCommand","sendFields","toWireMessage","resolveToolApprovalInput","resolveToolResultInput","runsOptimistic","AnyCommands","Record","args","AnyOptions","StatewireThread","Options","RunsOptions","RESTING_RUNS","Runs","runId","queue","steerQueue","dispatching","error","ambientContextOf","context","system","undefined","tools","callSettings","config","useStatewireThread","options","latest","current","pending","setPending","Command","retire","command","prev","includes","filter","c","runsOption","runs","runsSeam","Error","materializeOption","materialize","materializeSeam","state","commands","connection","setContext","transport","initialState","optimistic","draft","ctx","runsOpt","onCommandChange","update","status","params","onStateChange","onConnectionChange","clientRef","setContextRef","syncState","lastSent","contextSync","modelContext","parent","send","value","getModelContext","key","JSON","stringify","catch","onError","subscribe","dispatch","settled","type","threadRef","dispatchSend","message","sourceId","text","content","flatMap","part","join","setText","composer","next","ThreadStatus","mount","RunState","entries","entry","inputRequests","converter","metadata","ConnectionMetadata","pendingCommands","isSending","length","converted","State","messages","liveRunId","queueItems","steerQueueItems","queueSeam","present","inputSeam","extras","sendCommand","reconnect","handleAppend","crypto","randomUUID","handleReload","parentId","handleEdit","thread","isRunning","attachmentAdapter","adapters","attachments","speechAdapter","speech","feedbackAdapter","feedback","onNew","capabilities","edit","onEdit","continue","onResume","reload","onReload","onAddToolResult","toolOptions","onRespondToToolApproval","approval","onCancel","payload","stopPayload","Array","isArray","T","Transport","TextPart","FilePart","mediaType","url","filename","UserMessage","id","role","parts","Placement","insertAfter","insertBefore","RunEnqueueCommand","runAnchorMessageId","messageId","RunSteerCommand","RunDequeueCommand","RunEditCommand","RunContinueCommand","ToolCallInputRequest","toolCallId","ToolApprovalInputRequest","CustomInputRequest","InputRequest","ToolCallInputResponse","output","isError","artifact","ToolApprovalInputResponse","decision","editedArgs","InputResponse","RunInputCommand","requestId","response","InputRequestState","RunReloadCommand","RunCommand","QueueItem","RunStatus","RunsQueueEntry","meta","RunsInputOutcome","request","RunsDispatch","trigger","rollbackTo","inputOutcomes","RunsError","MaterializeEffects","append","rollback","to","RunsState","Exclude","ConnectionState","StateConverter","connectionMetadata","RunsConverterState","RunsStateConverter","StopPayload","reason","CommandUpdate","NonNullable","changes","Changes","Connection","Omit","Optimistic","Materialize","Assistant","Commands","runEnqueue","runSteer","runDequeue","runEdit","runContinue","runReload","runInput","hook"],"sources":["../src/StatewireThread.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { resource, useResource } from \"@assistant-ui/tap\";\nimport type { ResourceElement } from \"@assistant-ui/tap\";\nimport { ExternalThread } from \"@assistant-ui/react\";\nimport type { ExternalThreadMessage } from \"@assistant-ui/react\";\nimport {\n forwardTransformScopes,\n useAssistantClientRef,\n} from \"@assistant-ui/store\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport type {\n AddToolResultOptions,\n AppendMessage,\n AttachmentAdapter,\n ExternalThreadQueueAdapter,\n FeedbackAdapter,\n ModelContext,\n RespondToToolApprovalOptions,\n SpeechSynthesisAdapter,\n ThreadMessage,\n} from \"@assistant-ui/core\";\nimport { toToolsJSONSchema } from \"assistant-stream\";\nimport type { ReadonlyJSONValue } from \"assistant-stream/utils\";\nimport { useStatewire } from \"statewire\";\nimport type { Statewire, StatewireClient } from \"statewire\";\nimport { symbolAssistantTransportExtras } from \"./AssistantTransportThread\";\nimport type {\n AssistantTransportExtras,\n AssistantTransportThread,\n} from \"./AssistantTransportThread\";\nimport {\n createRunQueueAdapter,\n resolveEditCommand,\n resolveReloadCommand,\n sendFields,\n toWireMessage,\n} from \"./runCommands\";\nimport {\n resolveToolApprovalInput,\n resolveToolResultInput,\n} from \"./inputRequests\";\nimport { runsOptimistic } from \"./runsOptimistic\";\n\ntype AnyCommands = Record<string, (...args: any[]) => unknown>;\n\ntype AnyOptions =\n | StatewireThread.Options<any>\n | StatewireThread.RunsOptions<any>;\n\nconst RESTING_RUNS: StatewireThread.Runs = {\n runId: null,\n queue: [],\n steerQueue: [],\n dispatching: null,\n error: null,\n};\n\nconst ambientContextOf = (context: ModelContext): Record<string, unknown> => ({\n ...(context.system !== undefined && { system: context.system }),\n ...(context.tools !== undefined && {\n tools: toToolsJSONSchema(context.tools),\n }),\n ...(context.callSettings !== undefined && {\n callSettings: context.callSettings,\n }),\n ...(context.config !== undefined && { config: context.config }),\n});\n\nconst useStatewireThread = (options: AnyOptions): ClientOutput<\"thread\"> => {\n const latest = useRef(options);\n latest.current = options;\n\n const [pending, setPending] = useState<readonly StatewireThread.Command[]>(\n [],\n );\n const [retire] = useState(\n () => (command: unknown) =>\n setPending((prev) =>\n prev.includes(command as StatewireThread.Command)\n ? prev.filter((c) => c !== command)\n : prev,\n ),\n );\n\n const runsOption = options.runs;\n const [runsSeam] = useState(() => runsOption !== undefined);\n if (runsSeam !== (runsOption !== undefined))\n throw new Error(\n \"statewire: the runs option must be stable — it was \" +\n (runsSeam ? \"set\" : \"unset\") +\n \" on first render and changed since\",\n );\n\n const materializeOption = (options as StatewireThread.RunsOptions<unknown>)\n .materialize;\n const [materializeSeam] = useState(() => materializeOption !== undefined);\n if (materializeSeam !== (materializeOption !== undefined))\n throw new Error(\n \"statewire: the materialize option must be stable — it was \" +\n (materializeSeam ? \"set\" : \"unset\") +\n \" on first render and changed since\",\n );\n\n const { state, commands, connection, setContext } = useStatewire<\n unknown,\n AnyCommands\n >({\n transport: options.transport,\n initialState: options.initialState,\n ...(runsSeam && {\n optimistic: (draft, command, ctx) => {\n const runsOpt = latest.current.runs!;\n runsOptimistic(runsOpt === true ? draft : runsOpt(draft), command, ctx);\n (latest.current as StatewireThread.RunsOptions<unknown>).optimistic?.(\n draft,\n command,\n ctx,\n );\n },\n }),\n ...(materializeSeam && {\n materialize: (draft: {}) =>\n (latest.current as StatewireThread.RunsOptions<unknown>).materialize!(\n draft,\n ),\n }),\n onCommandChange: (update, ctx) => {\n if (update.status === \"acked\" || update.status === \"settled\")\n retire(update.params[0]);\n latest.current.onCommandChange?.(update, ctx);\n },\n onStateChange: (state, ctx) => latest.current.onStateChange?.(state, ctx),\n onConnectionChange: (connection) =>\n latest.current.onConnectionChange?.(connection),\n });\n\n const clientRef = useAssistantClientRef();\n const setContextRef = useRef(setContext);\n setContextRef.current = setContext;\n const [syncState] = useState(() => ({ lastSent: undefined as unknown }));\n const { contextSync } = options;\n useEffect(() => {\n if (contextSync === undefined) return;\n const modelContext = (clientRef.current ?? clientRef.parent).modelContext();\n const send = () => {\n const value = ambientContextOf(modelContext.getModelContext());\n const key = JSON.stringify(value);\n if (key === syncState.lastSent) return;\n syncState.lastSent = key;\n void setContextRef.current(value).catch((error: Error) => {\n latest.current.onError?.(error);\n });\n };\n send();\n if (!modelContext.subscribe) {\n throw new Error(\n \"statewire: contextSync requires a subscribable model context\",\n );\n }\n return modelContext.subscribe(send);\n }, [contextSync, clientRef, syncState]);\n\n const dispatch = useCallback(\n (command: StatewireThread.Command) => {\n setPending((prev) => [...prev, command]);\n const settled = commands[command.type]!(command);\n settled.catch((error: Error) => {\n retire(command);\n latest.current.onError?.(error);\n });\n return settled;\n },\n [commands, retire],\n );\n\n const threadRef = useRef<ClientOutput<\"thread\"> | null>(null);\n const dispatchSend = useCallback(\n (command: StatewireThread.Command, message: AppendMessage) => {\n if (message.sourceId != null) return void dispatch(command);\n const text = message.content\n .flatMap((part) => (part.type === \"text\" ? [part.text] : []))\n .join(\"\\n\\n\");\n void dispatch(command).catch(() => {\n // Rejected send: put the text back unless the user typed since.\n // ExternalThread's setText is live-ref-backed and takes an updater.\n const setText = threadRef.current!.composer().setText as (\n next: string | ((prev: string) => string),\n ) => void;\n setText((prev) => (prev === \"\" ? text : prev));\n });\n },\n [dispatch],\n );\n\n const { status, runs } = useMemo((): {\n status: StatewireThread.ThreadStatus;\n runs?: StatewireThread.Runs;\n } => {\n if (runsOption === undefined) return { status: \"ready\" };\n const mount = (runsOption === true ? state : runsOption(state)) as\n | { runs?: readonly StatewireThread.RunState[] }\n | undefined;\n const entries = mount?.runs;\n const entry = entries?.[0];\n return {\n status: entries === undefined ? \"loading\" : (entry?.status ?? \"ready\"),\n runs:\n entry === undefined\n ? RESTING_RUNS\n : {\n runId: entry.runId,\n queue: entry.queue,\n steerQueue: entry.steerQueue,\n dispatching: entry.dispatching,\n ...(entry.inputRequests !== undefined && {\n inputRequests: entry.inputRequests,\n }),\n error: entry.error,\n },\n };\n }, [runsOption, state]);\n\n const { converter } = options;\n const metadata = useMemo(\n (): StatewireThread.ConnectionMetadata => ({\n pendingCommands: [...pending],\n isSending: pending.length > 0,\n connection,\n ...(runs !== undefined && { runs }),\n }),\n [pending, connection, runs],\n );\n const converted = useMemo(\n (): StatewireThread.State =>\n converter(\n state,\n metadata as StatewireThread.ConnectionMetadata & {\n runs: StatewireThread.Runs;\n },\n ) as StatewireThread.State,\n [converter, state, metadata],\n );\n // Dispatch limbo is a materialize concern: the fold makes the record\n // concrete in state before conversion.\n const messages = converted.messages;\n const liveRunId = runs !== undefined ? runs.runId : (converted.runId ?? null);\n const queueItems = runs !== undefined ? runs.queue : converted.queue;\n const steerQueueItems =\n runs !== undefined ? runs.steerQueue : converted.steerQueue;\n if (steerQueueItems !== undefined && queueItems === undefined)\n throw new Error(\n \"statewire: the converter's steerQueue projection requires the queue projection\",\n );\n const [queueSeam] = useState(() => ({\n present: queueItems !== undefined,\n }));\n if (queueSeam.present !== (queueItems !== undefined))\n throw new Error(\n \"statewire: the converter's queue projection must be stable — it was \" +\n (queueSeam.present ? \"defined\" : \"undefined\") +\n \" on first convert and changed since\",\n );\n\n const queue = useMemo(\n (): ExternalThreadQueueAdapter | undefined =>\n queueItems\n ? createRunQueueAdapter(\n messages,\n liveRunId,\n queueItems,\n steerQueueItems,\n dispatch,\n dispatchSend,\n )\n : undefined,\n [messages, liveRunId, queueItems, steerQueueItems, dispatch, dispatchSend],\n );\n\n const inputRequests =\n runs !== undefined ? (runs.inputRequests ?? []) : converted.inputRequests;\n const [inputSeam] = useState(() => ({\n present: inputRequests !== undefined,\n }));\n if (inputSeam.present !== (inputRequests !== undefined))\n throw new Error(\n \"statewire: the converter's inputRequests projection must be stable — it was \" +\n (inputSeam.present ? \"defined\" : \"undefined\") +\n \" on first convert and changed since\",\n );\n\n const extras = useMemo(\n (): AssistantTransportExtras => ({\n [symbolAssistantTransportExtras]: true,\n sendCommand: dispatch,\n reconnect: connection.reconnect,\n state,\n status,\n ...(inputRequests !== undefined && { inputRequests }),\n ...(runs !== undefined && { runs }),\n }),\n [dispatch, connection.reconnect, state, status, inputRequests, runs],\n );\n\n const handleAppend = (message: AppendMessage) => {\n dispatchSend(\n message.sourceId != null\n ? resolveEditCommand(messages, message, liveRunId)\n : {\n type: \"run/steer\",\n ...sendFields(\n messages,\n liveRunId,\n toWireMessage(message, crypto.randomUUID()),\n ),\n },\n message,\n );\n };\n\n const handleReload = (parentId: string | null) => {\n dispatch(resolveReloadCommand(messages, parentId, liveRunId));\n };\n\n const handleEdit = (message: AppendMessage) => {\n dispatch(resolveEditCommand(messages, message, liveRunId));\n };\n\n const thread = useResource(\n ExternalThread({\n messages: messages as readonly ExternalThreadMessage[],\n isRunning:\n runs !== undefined ? status === \"running\" : converted.isRunning,\n state: converted.state,\n extras,\n attachmentAdapter: options.adapters?.attachments,\n speechAdapter: options.adapters?.speech,\n feedbackAdapter: options.adapters?.feedback,\n onNew: handleAppend,\n ...(queue && { queue }),\n ...(options.capabilities?.edit && { onEdit: handleEdit }),\n ...(options.capabilities?.continue && {\n onResume: () =>\n dispatch({\n type: \"run/continue\",\n ...(liveRunId !== null && { runId: liveRunId }),\n }),\n }),\n ...(options.capabilities?.reload && { onReload: handleReload }),\n ...(inputRequests !== undefined && {\n onAddToolResult: (toolOptions: AddToolResultOptions) =>\n dispatch(\n resolveToolResultInput(inputRequests, toolOptions, liveRunId),\n ),\n onRespondToToolApproval: (approval: RespondToToolApprovalOptions) =>\n dispatch(\n resolveToolApprovalInput(inputRequests, approval, liveRunId),\n ),\n }),\n onCancel: () => {\n const payload = latest.current.stopPayload?.();\n if (\n payload !== undefined &&\n (typeof payload !== \"object\" ||\n payload === null ||\n Array.isArray(payload))\n )\n throw new Error(\"statewire: stopPayload must return a plain object\");\n const runId = runs !== undefined ? runs.runId : converted.runId;\n const args =\n runId === undefined\n ? payload === undefined\n ? []\n : [payload]\n : [{ ...payload, runId }];\n void commands[\"run/stop\"]!(...args).catch((error: Error) => {\n latest.current.onError?.(error);\n });\n },\n }),\n );\n threadRef.current = thread;\n return thread;\n};\n\nexport const StatewireThread: {\n <T>(\n options: StatewireThread.RunsOptions<T>,\n ): ResourceElement<ClientOutput<\"thread\">>;\n <T>(\n options: StatewireThread.Options<T>,\n ): ResourceElement<ClientOutput<\"thread\">>;\n} = (options: AnyOptions): ResourceElement<ClientOutput<\"thread\">> =>\n resource(useStatewireThread)(options);\n\nexport namespace StatewireThread {\n export type Transport<T> = ResourceElement<Statewire<T | undefined, any>>;\n\n export type TextPart = {\n readonly type: \"text\";\n readonly text: string;\n };\n\n export type FilePart = {\n readonly type: \"file\";\n readonly mediaType: string;\n readonly url: string;\n readonly filename?: string;\n };\n\n export type UserMessage = {\n readonly id: string;\n readonly role: \"user\";\n readonly parts: readonly (TextPart | FilePart)[];\n readonly metadata?: Record<string, unknown>;\n };\n\n /** Queue placement fields, flat on the command. Absent is load-bearing: it means default placement; `null` names a queue boundary. */\n export type Placement = {\n readonly insertAfter?: string | null;\n readonly insertBefore?: string | null;\n };\n\n export type RunEnqueueCommand = {\n readonly type: \"run/enqueue\";\n /** The run this command targets — the live run's id, or a fresh client-minted uuid on run-creating sends. */\n readonly runId: string;\n } & (\n | {\n readonly message: UserMessage;\n /** Run anchor: the message the new content grows after, null asserting an empty thread. Present on run-creating sends; absent when targeting the live run. */\n readonly runAnchorMessageId?: string | null;\n }\n | { readonly messageId: string }\n ) &\n Placement;\n\n export type RunSteerCommand = {\n readonly type: \"run/steer\";\n /** The run this command targets — the live run's id, or a fresh client-minted uuid on run-creating sends. */\n readonly runId: string;\n } & (\n | {\n readonly message: UserMessage;\n /** Run anchor: the message the new content grows after, null asserting an empty thread. Present on run-creating sends; absent when targeting the live run. */\n readonly runAnchorMessageId?: string | null;\n }\n | { readonly messageId: string }\n ) &\n Placement;\n\n export type RunDequeueCommand = {\n readonly type: \"run/dequeue\";\n readonly runId: string;\n readonly messageId: string;\n };\n\n export type RunEditCommand = {\n readonly type: \"run/edit\";\n /** The live run's id when redirecting it, or a fresh client-minted uuid when idle. */\n readonly runId: string;\n readonly message: UserMessage;\n readonly sourceId: string;\n /** Asserts `sourceId`'s parent — the rewind target; null names the root. */\n readonly runAnchorMessageId: string | null;\n };\n\n export type RunContinueCommand = {\n readonly type: \"run/continue\";\n readonly runId?: string;\n };\n\n export type ToolCallInputRequest = {\n readonly type: \"tool-call\";\n readonly id: string;\n readonly toolCallId: string;\n };\n\n export type ToolApprovalInputRequest = {\n readonly type: \"tool-approval\";\n readonly id: string;\n readonly toolCallId: string;\n };\n\n export type CustomInputRequest = {\n readonly type: string;\n readonly id: string;\n readonly [key: string]: ReadonlyJSONValue | undefined;\n };\n\n /** A host request parking the run until answered; open union for custom types. */\n export type InputRequest =\n | ToolCallInputRequest\n | ToolApprovalInputRequest\n | CustomInputRequest;\n\n export type ToolCallInputResponse = {\n readonly output: ReadonlyJSONValue;\n /** Default false; when true, `output` carries the error payload. */\n readonly isError?: boolean;\n readonly artifact?: ReadonlyJSONValue;\n };\n\n export type ToolApprovalInputResponse = {\n readonly decision: \"approve\" | \"reject\" | \"edit\" | \"respond\";\n readonly editedArgs?: ReadonlyJSONValue;\n readonly message?: string;\n };\n\n export type InputResponse = ReadonlyJSONValue;\n\n export type RunInputCommand = {\n readonly type: \"run/input\";\n readonly runId?: string;\n readonly requestId: string;\n readonly response: InputResponse;\n };\n\n /** An input request projected out of the host state with its response echo. */\n export type InputRequestState = InputRequest & {\n readonly response: InputResponse | null;\n };\n\n export type RunReloadCommand = {\n readonly type: \"run/reload\";\n /** The live run's id when redirecting it, or a fresh client-minted uuid when idle. */\n readonly runId: string;\n readonly sourceId: string;\n /** Asserts `sourceId`'s parent — the rewind target; null names the root. */\n readonly runAnchorMessageId: string | null;\n };\n\n export type RunCommand =\n | RunEnqueueCommand\n | RunSteerCommand\n | RunDequeueCommand\n | RunEditCommand\n | RunContinueCommand\n | RunReloadCommand\n | RunInputCommand;\n\n export type Command = AssistantTransportThread.Command | RunCommand;\n\n /** A queued message projected out of the host state, wire shape. */\n export type QueueItem = {\n readonly id: string;\n readonly parts: readonly (TextPart | FilePart)[];\n };\n\n export type State = {\n readonly messages: readonly ThreadMessage[];\n readonly state?: ReadonlyJSONValue;\n readonly isRunning: boolean;\n /** The live run's id projected out of the host state; stamped onto `run/stop`. */\n readonly runId?: string | null;\n /**\n * The host's regular queue lane projected out of the state. Returning it\n * (even empty) turns on the queue capability: sends become `run/enqueue`\n * / `run/steer` commands and item controls send the `run/*` queue\n * commands. Presence must be stable across conversions.\n */\n readonly queue?: readonly QueueItem[];\n /** The host's steer lane; requires `queue`. Absent means empty. */\n readonly steerQueue?: readonly QueueItem[];\n /**\n * The host's parked input requests projected out of the state. Returning\n * it (even empty) routes tool results and approvals with a matching\n * pending request through `run/input`. Presence must be stable across\n * conversions.\n */\n readonly inputRequests?: readonly InputRequestState[];\n };\n\n /** Run subsystem status replicated by the host. */\n export type RunStatus = \"running\" | \"stopped\" | \"error\" | \"input-required\";\n\n /** The thread's status, derived from the state: `\"loading\"` while the runs mount is absent, `\"ready\"` while resting, otherwise the run's status. */\n export type ThreadStatus = \"loading\" | \"ready\" | RunStatus;\n\n /** A queue-lane entry as replicated: the user message plus host-stamped `meta`. */\n export type RunsQueueEntry = UserMessage & {\n /** Host-stamped opaque per-entry metadata. */\n readonly meta?: ReadonlyJSONValue;\n };\n\n /** An input outcome riding a dispatch record: the request with its response (null = abandoned) and `run/input` meta. */\n export type RunsInputOutcome = {\n readonly request: InputRequest;\n readonly response: InputResponse | null;\n readonly meta: ReadonlyJSONValue | null;\n };\n\n /** The dispatch record — the unacked batch handed to the run; null between the ack and the next dispatch or take. */\n export type RunsDispatch = {\n readonly trigger:\n | \"message-send\"\n | \"message-edit\"\n | \"message-reload\"\n | \"input-resume\"\n | \"error-continue\"\n | \"stop-continue\"\n | \"steer\";\n readonly messages: readonly RunsQueueEntry[];\n /** Present on rewind dispatches: truncate the thread at this id first; null names the root. */\n readonly rollbackTo?: string | null;\n /** Present when input outcomes ride the dispatch; visible until the ack. */\n readonly inputOutcomes?: readonly RunsInputOutcome[];\n };\n\n /** The replicated run error — set on an unhandled failure, cleared by the next user-initiated run. */\n export type RunsError = {\n readonly message: string;\n readonly [key: string]: ReadonlyJSONValue | undefined;\n };\n\n /** A replicated run entry — one element of the mount's `runs` array. */\n export type RunState = {\n /** The run's identity — client-minted, adopted by the host at run creation; persists through steers, input-required, and error/stop, retiring only when the queue drains and the run completes. */\n readonly runId: string | null;\n readonly status: RunStatus;\n readonly queue: readonly RunsQueueEntry[];\n readonly steerQueue: readonly RunsQueueEntry[];\n /** The dispatch record — the unacked batch handed to the run, cleared at the ack. */\n readonly dispatching: RunsDispatch | null;\n /** The parked pending set; present only in input-required. */\n readonly inputRequests?: readonly InputRequestState[];\n readonly error: RunsError | null;\n };\n\n /** App-shaped effects `runsMaterialize` applies for the dispatch record. */\n export type MaterializeEffects = {\n /** Append one dispatched message to the app's committed message state. */\n append: (message: RunsQueueEntry) => void;\n /** Truncate to the rolled-back view first (null names the root); required for hosts that dispatch edits/reloads. */\n rollback?: (to: string | null) => void;\n };\n\n /** The runs mount as replicated: the run entries plus the top-level status projection. */\n export type RunsState = {\n /** Projection of `runs[0]?.status ?? \"ready\"`. */\n readonly status: Exclude<ThreadStatus, \"loading\">;\n /** At most one entry; empty while resting. */\n readonly runs: readonly RunState[];\n };\n\n /** The run subsystem's typed read — `runs[0]` of the selected mount with unsettled commands folded in, resting defaults while no entry is live. */\n export type Runs = {\n /** The live run's id — non-null whenever a run entry is live (running, input-required, error/stop); the target for `run/*` sends. */\n readonly runId: string | null;\n readonly queue: readonly RunsQueueEntry[];\n readonly steerQueue: readonly RunsQueueEntry[];\n /** The dispatch record — the unacked batch handed to the run, cleared at the ack. */\n readonly dispatching: RunsDispatch | null;\n /** The parked pending set; present only in input-required. */\n readonly inputRequests?: readonly InputRequestState[];\n readonly error: RunsError | null;\n };\n\n export type ConnectionMetadata = {\n pendingCommands: Command[];\n isSending: boolean;\n /** Statewire connection status; local transports are always `live`. */\n connection: StatewireClient.ConnectionState;\n /** The typed runs read; present iff the `runs` option is set. */\n runs?: Runs;\n };\n\n export type StateConverter<T> = (\n state: T,\n connectionMetadata: ConnectionMetadata,\n ) => State;\n\n /** Converter output in runs mode: app-owned keys only — the lib projects the run mounts itself. */\n export type RunsConverterState = {\n readonly messages: readonly ThreadMessage[];\n readonly state?: ReadonlyJSONValue;\n };\n\n export type RunsStateConverter<T> = (\n state: T,\n connectionMetadata: ConnectionMetadata & { runs: Runs },\n ) => RunsConverterState;\n\n /**\n * Payload of the built-in `run/stop` command. `reason` is the one well-known\n * field; apps extend it with their own JSON-serializable fields.\n */\n export type StopPayload = {\n readonly reason?: string | undefined;\n readonly [key: string]: ReadonlyJSONValue | undefined;\n };\n\n export type Options<T> = {\n transport: Transport<T>;\n /** The pre-attach state, replaced by the attach snapshot. With runs, `runs: []` projects ready (interactive from the first render); an absent runs mount projects loading until attach. */\n initialState: T;\n converter: StateConverter<T>;\n runs?: undefined;\n /**\n * \"command-send\" mirrors the client's ambient model context (system,\n * tools, callSettings, config) to the server over the command channel —\n * on connect and whenever it changes. Requires a remote transport.\n */\n contextSync?: \"command-send\" | undefined;\n /** Supplies the `run/stop` command's payload; omitted, stop sends no payload. */\n stopPayload?: (() => StopPayload) | undefined;\n /** Observes each command's lifecycle (queued, posted, acked, settled); runs after the built-in pending-command retirement. */\n onCommandChange?:\n | ((\n update: Statewire.CommandUpdate<\n Record<string, (...args: any[]) => unknown>\n >,\n ctx: { state: NonNullable<T> },\n ) => void)\n | undefined;\n /** Observes the transport state: fires with the attach snapshot, then once per change. */\n onStateChange?:\n | ((state: NonNullable<T>, ctx: { changes: Statewire.Changes }) => void)\n | undefined;\n /** Observes connection status transitions, starting with the initial status. */\n onConnectionChange?:\n | ((connection: StatewireClient.Connection) => void)\n | undefined;\n onError?: ((error: Error) => void) | undefined;\n capabilities?:\n | {\n edit?: boolean | undefined;\n /** The host supports `run/continue` (a continue affordance on aborted runs). */\n continue?: boolean | undefined;\n /** The host supports `run/reload` (regenerating an assistant message). */\n reload?: boolean | undefined;\n }\n | undefined;\n adapters?:\n | {\n attachments?: AttachmentAdapter | undefined;\n speech?: SpeechSynthesisAdapter | undefined;\n feedback?: FeedbackAdapter | undefined;\n }\n | undefined;\n };\n\n /** Options with the runs read enabled: the lib types the run mounts and the converter returns app-owned keys only. */\n export type RunsOptions<T> = Omit<Options<T>, \"converter\" | \"runs\"> & {\n /** `true` reads the run mounts off the state root; a selector picks a nested mount. */\n runs: true | ((state: T) => unknown);\n converter: RunsStateConverter<T>;\n /** Folds app-owned keys for an unsettled command into the draft; runs after the lib's run-dialect reducer. */\n optimistic?:\n | StatewireClient.Optimistic<\n T,\n Record<string, (...args: any[]) => unknown>\n >\n | undefined;\n /** Makes dispatch records concrete in the draft (runs after the optimistic folds); without it, dispatch limbo stays out of `messages`. */\n materialize?: StatewireClient.Materialize<NonNullable<T>> | undefined;\n };\n}\n\ndeclare module \"@assistant-ui/react\" {\n namespace Assistant {\n interface Commands {\n runEnqueue: StatewireThread.RunEnqueueCommand;\n runSteer: StatewireThread.RunSteerCommand;\n runDequeue: StatewireThread.RunDequeueCommand;\n runEdit: StatewireThread.RunEditCommand;\n runContinue: StatewireThread.RunContinueCommand;\n runReload: StatewireThread.RunReloadCommand;\n runInput: StatewireThread.RunInputCommand;\n }\n }\n}\n\n// Scope transforms are keyed by the underlying hook, not the resource wrapper.\nforwardTransformScopes(\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
@@ -4,10 +4,12 @@ import { Assistant } from "@assistant-ui/react";
|
|
|
4
4
|
//#region src/hooks.d.ts
|
|
5
5
|
type UserExternalState = keyof Assistant.ExternalState extends never ? Record<string, unknown> : Assistant.ExternalState[keyof Assistant.ExternalState];
|
|
6
6
|
declare const useAssistantTransportSendCommand: () => (command: AssistantTransportThread.Command) => void;
|
|
7
|
+
/** The thread status; requires StatewireThread. */
|
|
8
|
+
declare const useStatewireThreadStatus: () => StatewireThread.ThreadStatus;
|
|
7
9
|
/** The typed runs read; requires StatewireThread with the `runs` option. */
|
|
8
10
|
declare const useStatewireRuns: () => StatewireThread.Runs;
|
|
9
11
|
declare function useAssistantTransportState(): UserExternalState;
|
|
10
12
|
declare function useAssistantTransportState<T>(selector: (state: UserExternalState) => T): T;
|
|
11
13
|
//#endregion
|
|
12
|
-
export { useAssistantTransportSendCommand, useAssistantTransportState, useStatewireRuns };
|
|
14
|
+
export { useAssistantTransportSendCommand, useAssistantTransportState, useStatewireRuns, useStatewireThreadStatus };
|
|
13
15
|
//# sourceMappingURL=hooks.d.ts.map
|
package/dist/hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","names":[],"sources":["../src/hooks.ts"],"mappings":";;;;KAQK,0BAA0B,UAAU,8BACrC,0BACA,UAAU,oBAAoB,UAAU;cAE/B,yCAGH,SAAS,yBAAyB;;cAO/B,wBAAuB,gBAAgB;iBAUpC,8BAA8B;iBAC9B,2BAA2B,GACzC,WAAW,OAAO,sBAAsB,IACvC"}
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","names":[],"sources":["../src/hooks.ts"],"mappings":";;;;KAQK,0BAA0B,UAAU,8BACrC,0BACA,UAAU,oBAAoB,UAAU;cAE/B,yCAGH,SAAS,yBAAyB;;cAO/B,gCAA+B,gBAAgB;;cAW/C,wBAAuB,gBAAgB;iBAUpC,8BAA8B;iBAC9B,2BAA2B,GACzC,WAAW,OAAO,sBAAsB,IACvC"}
|
package/dist/hooks.js
CHANGED
|
@@ -17,19 +17,28 @@ const useAssistantTransportSendCommand = () => {
|
|
|
17
17
|
} else t0 = $[1];
|
|
18
18
|
return t0;
|
|
19
19
|
};
|
|
20
|
+
/** The thread status; requires StatewireThread. */
|
|
21
|
+
const useStatewireThreadStatus = () => {
|
|
22
|
+
return useAuiState(_temp);
|
|
23
|
+
};
|
|
20
24
|
/** The typed runs read; requires StatewireThread with the `runs` option. */
|
|
21
25
|
const useStatewireRuns = () => {
|
|
22
|
-
return useAuiState(
|
|
26
|
+
return useAuiState(_temp2);
|
|
23
27
|
};
|
|
24
28
|
function useAssistantTransportState(selector = (t) => t) {
|
|
25
29
|
return useAuiState((s) => selector(asAssistantTransportExtras(s.thread.extras).state));
|
|
26
30
|
}
|
|
27
31
|
function _temp(s) {
|
|
32
|
+
const { status } = asAssistantTransportExtras(s.thread.extras);
|
|
33
|
+
if (status === void 0) throw new Error("statewire: useStatewireThreadStatus requires StatewireThread");
|
|
34
|
+
return status;
|
|
35
|
+
}
|
|
36
|
+
function _temp2(s) {
|
|
28
37
|
const { runs } = asAssistantTransportExtras(s.thread.extras);
|
|
29
38
|
if (runs === void 0) throw new Error("statewire: useStatewireRuns requires StatewireThread with the runs option enabled");
|
|
30
39
|
return runs;
|
|
31
40
|
}
|
|
32
41
|
//#endregion
|
|
33
|
-
export { useAssistantTransportSendCommand, useAssistantTransportState, useStatewireRuns };
|
|
42
|
+
export { useAssistantTransportSendCommand, useAssistantTransportState, useStatewireRuns, useStatewireThreadStatus };
|
|
34
43
|
|
|
35
44
|
//# sourceMappingURL=hooks.js.map
|
package/dist/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","names":["c","_c","useAui","useAuiState","asAssistantTransportExtras","Assistant","AssistantTransportThread","StatewireThread","UserExternalState","ExternalState","Record","useAssistantTransportSendCommand","$","aui","t0","command","extras","thread","getState","sendCommand","
|
|
1
|
+
{"version":3,"file":"hooks.js","names":["c","_c","useAui","useAuiState","asAssistantTransportExtras","Assistant","AssistantTransportThread","StatewireThread","UserExternalState","ExternalState","Record","useAssistantTransportSendCommand","$","aui","t0","command","extras","thread","getState","sendCommand","useStatewireThreadStatus","_temp","useStatewireRuns","_temp2","useAssistantTransportState","selector","state","T","t","s","status","undefined","Error","runs"],"sources":["../src/hooks.ts"],"sourcesContent":["\"use client\";\n\nimport { useAui, useAuiState } from \"@assistant-ui/store\";\nimport { asAssistantTransportExtras } from \"./AssistantTransportThread\";\nimport type { Assistant } from \"@assistant-ui/react\";\nimport type { AssistantTransportThread } from \"./AssistantTransportThread\";\nimport type { StatewireThread } from \"./StatewireThread\";\n\ntype UserExternalState = keyof Assistant.ExternalState extends never\n ? Record<string, unknown>\n : Assistant.ExternalState[keyof Assistant.ExternalState];\n\nexport const useAssistantTransportSendCommand = () => {\n const aui = useAui();\n\n return (command: AssistantTransportThread.Command) => {\n const extras = aui.thread().getState().extras;\n asAssistantTransportExtras(extras).sendCommand(command);\n };\n};\n\n/** The thread status; requires StatewireThread. */\nexport const useStatewireThreadStatus = (): StatewireThread.ThreadStatus =>\n useAuiState((s) => {\n const { status } = asAssistantTransportExtras(s.thread.extras);\n if (status === undefined)\n throw new Error(\n \"statewire: useStatewireThreadStatus requires StatewireThread\",\n );\n return status;\n });\n\n/** The typed runs read; requires StatewireThread with the `runs` option. */\nexport const useStatewireRuns = (): StatewireThread.Runs =>\n useAuiState((s) => {\n const { runs } = asAssistantTransportExtras(s.thread.extras);\n if (runs === undefined)\n throw new Error(\n \"statewire: useStatewireRuns requires StatewireThread with the runs option enabled\",\n );\n return runs;\n });\n\nexport function useAssistantTransportState(): UserExternalState;\nexport function useAssistantTransportState<T>(\n selector: (state: UserExternalState) => T,\n): T;\nexport function useAssistantTransportState<T>(\n selector: (state: UserExternalState) => T = (t) => t as T,\n): T | UserExternalState {\n return useAuiState((s) =>\n selector(\n asAssistantTransportExtras(s.thread.extras).state as UserExternalState,\n ),\n );\n}\n"],"mappings":";;;;;AAYA,MAAaW,yCAAmC;CAAA,MAAAC,IAAAX,EAAA,CAAA;CAC9C,MAAAY,MAAYX,OAAO;CAAE,IAAAY;CAAA,IAAAF,EAAA,OAAAC,KAAA;EAEdC,MAAAC,YAAA;GACL,MAAAC,SAAeH,IAAGI,OAAQ,CAAC,CAAAC,SAAU,CAAC,CAAAF;GACtCZ,2BAA2BY,MAAM,CAAC,CAAAG,YAAaJ,OAAO;EAAC;EACxDH,EAAA,KAAAC;EAAAD,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAAA,OAHME;AAGN;;AAIH,MAAaM,iCAA2B;CAAA,OACtCjB,YAAYkB,KAOX;AAAC;;AAGJ,MAAaC,yBAAmB;CAAA,OAC9BnB,YAAYoB,MAOX;AAAC;AAMJ,SAAgBC,2BACdC,YAA6CG,MAAMA,GAC5B;CACvB,OAAOzB,aAAa0B,MAClBJ,SACErB,2BAA2ByB,EAAEZ,OAAOD,MAAM,CAAC,CAACU,KAC9C,CACF;AACF;AAjCwC,SAAAL,MAAAQ,GAAA;CAEpC,MAAA,EAAAC,WAAmB1B,2BAA2ByB,EAACZ,OAAOD,MAAO;CAC7D,IAAIc,WAAWC,KAAAA,GACb,MAAM,IAAIC,MACR,8DACF;CAAE,OACGF;AAAM;AAIe,SAAAP,OAAAM,GAAA;CAE5B,MAAA,EAAAI,SAAiB7B,2BAA2ByB,EAACZ,OAAOD,MAAO;CAC3D,IAAIiB,SAASF,KAAAA,GACX,MAAM,IAAIC,MACR,mFACF;CAAE,OACGC;AAAI"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StatewireThread } from "./StatewireThread.js";
|
|
2
2
|
import { AssistantTransportThread } from "./AssistantTransportThread.js";
|
|
3
|
-
import { useAssistantTransportSendCommand, useAssistantTransportState, useStatewireRuns } from "./hooks.js";
|
|
3
|
+
import { useAssistantTransportSendCommand, useAssistantTransportState, useStatewireRuns, useStatewireThreadStatus } from "./hooks.js";
|
|
4
4
|
import { runsMaterialize } from "./runsMaterialize.js";
|
|
5
|
-
export { AssistantTransportThread, StatewireThread, runsMaterialize, useAssistantTransportSendCommand, useAssistantTransportState, useStatewireRuns };
|
|
5
|
+
export { AssistantTransportThread, StatewireThread, runsMaterialize, useAssistantTransportSendCommand, useAssistantTransportState, useStatewireRuns, useStatewireThreadStatus };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AssistantTransportThread } from "./AssistantTransportThread.js";
|
|
2
2
|
import { StatewireThread } from "./StatewireThread.js";
|
|
3
|
-
import { useAssistantTransportSendCommand, useAssistantTransportState, useStatewireRuns } from "./hooks.js";
|
|
3
|
+
import { useAssistantTransportSendCommand, useAssistantTransportState, useStatewireRuns, useStatewireThreadStatus } from "./hooks.js";
|
|
4
4
|
import { runsMaterialize } from "./runsMaterialize.js";
|
|
5
|
-
export { AssistantTransportThread, StatewireThread, runsMaterialize, useAssistantTransportSendCommand, useAssistantTransportState, useStatewireRuns };
|
|
5
|
+
export { AssistantTransportThread, StatewireThread, runsMaterialize, useAssistantTransportSendCommand, useAssistantTransportState, useStatewireRuns, useStatewireThreadStatus };
|
package/dist/inputRequests.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ declare const resolveToolResultInput: (inputRequests: readonly AssistantTranspor
|
|
|
7
7
|
result: ReadonlyJSONValue;
|
|
8
8
|
isError: boolean;
|
|
9
9
|
artifact?: ReadonlyJSONValue | undefined;
|
|
10
|
-
}) => AssistantTransportThread.RunInputCommand;
|
|
11
|
-
declare const resolveToolApprovalInput: (inputRequests: readonly AssistantTransportThread.InputRequestState[], options: RespondToToolApprovalOptions) => AssistantTransportThread.RunInputCommand;
|
|
10
|
+
}, runId: string | null) => AssistantTransportThread.RunInputCommand;
|
|
11
|
+
declare const resolveToolApprovalInput: (inputRequests: readonly AssistantTransportThread.InputRequestState[], options: RespondToToolApprovalOptions, runId: string | null) => AssistantTransportThread.RunInputCommand;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { resolveToolApprovalInput, resolveToolResultInput };
|
|
14
14
|
//# sourceMappingURL=inputRequests.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputRequests.d.ts","names":[],"sources":["../src/inputRequests.ts"],"mappings":";;;;cAaa,yBACX,wBAAwB,yBAAyB,qBACjD;EACE;EACA,QAAQ;EACR;EACA,WAAW;
|
|
1
|
+
{"version":3,"file":"inputRequests.d.ts","names":[],"sources":["../src/inputRequests.ts"],"mappings":";;;;cAaa,yBACX,wBAAwB,yBAAyB,qBACjD;EACE;EACA,QAAQ;EACR;EACA,WAAW;GAEb,yBACC,yBAAyB;cAqBf,2BACX,wBAAwB,yBAAyB,qBACjD,SAAS,8BACT,yBACC,yBAAyB"}
|
package/dist/inputRequests.js
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
const assertUnanswered = (request) => {
|
|
3
3
|
if (request.response !== null) throw new Error(`statewire: input request "${request.id}" is already answered`);
|
|
4
4
|
};
|
|
5
|
-
const resolveToolResultInput = (inputRequests, options) => {
|
|
5
|
+
const resolveToolResultInput = (inputRequests, options, runId) => {
|
|
6
6
|
const request = inputRequests.find((r) => r.type === "tool-call" && r.toolCallId === options.toolCallId);
|
|
7
7
|
if (request === void 0) throw new Error(`statewire: no tool-call input request for tool call "${options.toolCallId}"`);
|
|
8
8
|
assertUnanswered(request);
|
|
9
9
|
return {
|
|
10
10
|
type: "run/input",
|
|
11
|
+
...runId !== null && { runId },
|
|
11
12
|
requestId: request.id,
|
|
12
13
|
response: {
|
|
13
14
|
output: options.result,
|
|
@@ -16,12 +17,13 @@ const resolveToolResultInput = (inputRequests, options) => {
|
|
|
16
17
|
}
|
|
17
18
|
};
|
|
18
19
|
};
|
|
19
|
-
const resolveToolApprovalInput = (inputRequests, options) => {
|
|
20
|
+
const resolveToolApprovalInput = (inputRequests, options, runId) => {
|
|
20
21
|
const request = inputRequests.find((r) => r.type === "tool-approval" && r.id === options.approvalId);
|
|
21
22
|
if (request === void 0) throw new Error(`statewire: no tool-approval input request "${options.approvalId}"`);
|
|
22
23
|
assertUnanswered(request);
|
|
23
24
|
return {
|
|
24
25
|
type: "run/input",
|
|
26
|
+
...runId !== null && { runId },
|
|
25
27
|
requestId: request.id,
|
|
26
28
|
response: {
|
|
27
29
|
decision: options.approved ? "approve" : "reject",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputRequests.js","names":["RespondToToolApprovalOptions","ReadonlyJSONValue","AssistantTransportThread","assertUnanswered","request","InputRequestState","response","Error","id","resolveToolResultInput","inputRequests","options","toolCallId","result","isError","artifact","RunInputCommand","find","r","type","undefined","requestId","output","resolveToolApprovalInput","approvalId","decision","approved","reason","message"],"sources":["../src/inputRequests.ts"],"sourcesContent":["import type { RespondToToolApprovalOptions } from \"@assistant-ui/core\";\nimport type { ReadonlyJSONValue } from \"assistant-stream/utils\";\nimport type { AssistantTransportThread } from \"./AssistantTransportThread\";\n\nconst assertUnanswered = (\n request: AssistantTransportThread.InputRequestState,\n) => {\n if (request.response !== null)\n throw new Error(\n `statewire: input request \"${request.id}\" is already answered`,\n );\n};\n\nexport const resolveToolResultInput = (\n inputRequests: readonly AssistantTransportThread.InputRequestState[],\n options: {\n toolCallId: string;\n result: ReadonlyJSONValue;\n isError: boolean;\n artifact?: ReadonlyJSONValue | undefined;\n },\n): AssistantTransportThread.RunInputCommand => {\n const request = inputRequests.find(\n (r) => r.type === \"tool-call\" && r.toolCallId === options.toolCallId,\n );\n if (request === undefined)\n throw new Error(\n `statewire: no tool-call input request for tool call \"${options.toolCallId}\"`,\n );\n assertUnanswered(request);\n return {\n type: \"run/input\",\n requestId: request.id,\n response: {\n output: options.result,\n ...(options.isError && { isError: true }),\n ...(options.artifact !== undefined && { artifact: options.artifact }),\n },\n };\n};\n\nexport const resolveToolApprovalInput = (\n inputRequests: readonly AssistantTransportThread.InputRequestState[],\n options: RespondToToolApprovalOptions,\n): AssistantTransportThread.RunInputCommand => {\n const request = inputRequests.find(\n (r) => r.type === \"tool-approval\" && r.id === options.approvalId,\n );\n if (request === undefined)\n throw new Error(\n `statewire: no tool-approval input request \"${options.approvalId}\"`,\n );\n assertUnanswered(request);\n return {\n type: \"run/input\",\n requestId: request.id,\n response: {\n decision: options.approved ? \"approve\" : \"reject\",\n ...(options.reason !== undefined && { message: options.reason }),\n },\n };\n};\n"],"mappings":";AAIA,MAAMG,oBACJC,YACG;CACH,IAAIA,QAAQE,aAAa,MACvB,MAAM,IAAIC,MACR,6BAA6BH,QAAQI,GAAE,sBACzC;AACJ;AAEA,MAAaC,0BACXC,eACAC,
|
|
1
|
+
{"version":3,"file":"inputRequests.js","names":["RespondToToolApprovalOptions","ReadonlyJSONValue","AssistantTransportThread","assertUnanswered","request","InputRequestState","response","Error","id","resolveToolResultInput","inputRequests","options","toolCallId","result","isError","artifact","runId","RunInputCommand","find","r","type","undefined","requestId","output","resolveToolApprovalInput","approvalId","decision","approved","reason","message"],"sources":["../src/inputRequests.ts"],"sourcesContent":["import type { RespondToToolApprovalOptions } from \"@assistant-ui/core\";\nimport type { ReadonlyJSONValue } from \"assistant-stream/utils\";\nimport type { AssistantTransportThread } from \"./AssistantTransportThread\";\n\nconst assertUnanswered = (\n request: AssistantTransportThread.InputRequestState,\n) => {\n if (request.response !== null)\n throw new Error(\n `statewire: input request \"${request.id}\" is already answered`,\n );\n};\n\nexport const resolveToolResultInput = (\n inputRequests: readonly AssistantTransportThread.InputRequestState[],\n options: {\n toolCallId: string;\n result: ReadonlyJSONValue;\n isError: boolean;\n artifact?: ReadonlyJSONValue | undefined;\n },\n runId: string | null,\n): AssistantTransportThread.RunInputCommand => {\n const request = inputRequests.find(\n (r) => r.type === \"tool-call\" && r.toolCallId === options.toolCallId,\n );\n if (request === undefined)\n throw new Error(\n `statewire: no tool-call input request for tool call \"${options.toolCallId}\"`,\n );\n assertUnanswered(request);\n return {\n type: \"run/input\",\n ...(runId !== null && { runId }),\n requestId: request.id,\n response: {\n output: options.result,\n ...(options.isError && { isError: true }),\n ...(options.artifact !== undefined && { artifact: options.artifact }),\n },\n };\n};\n\nexport const resolveToolApprovalInput = (\n inputRequests: readonly AssistantTransportThread.InputRequestState[],\n options: RespondToToolApprovalOptions,\n runId: string | null,\n): AssistantTransportThread.RunInputCommand => {\n const request = inputRequests.find(\n (r) => r.type === \"tool-approval\" && r.id === options.approvalId,\n );\n if (request === undefined)\n throw new Error(\n `statewire: no tool-approval input request \"${options.approvalId}\"`,\n );\n assertUnanswered(request);\n return {\n type: \"run/input\",\n ...(runId !== null && { runId }),\n requestId: request.id,\n response: {\n decision: options.approved ? \"approve\" : \"reject\",\n ...(options.reason !== undefined && { message: options.reason }),\n },\n };\n};\n"],"mappings":";AAIA,MAAMG,oBACJC,YACG;CACH,IAAIA,QAAQE,aAAa,MACvB,MAAM,IAAIC,MACR,6BAA6BH,QAAQI,GAAE,sBACzC;AACJ;AAEA,MAAaC,0BACXC,eACAC,SAMAK,UAC6C;CAC7C,MAAMZ,UAAUM,cAAcQ,MAC3BC,MAAMA,EAAEC,SAAS,eAAeD,EAAEP,eAAeD,QAAQC,UAC5D;CACA,IAAIR,YAAYiB,KAAAA,GACd,MAAM,IAAId,MACR,wDAAwDI,QAAQC,WAAU,EAC5E;CACFT,iBAAiBC,OAAO;CACxB,OAAO;EACLgB,MAAM;EACN,GAAIJ,UAAU,QAAQ,EAAEA,MAAM;EAC9BM,WAAWlB,QAAQI;EACnBF,UAAU;GACRiB,QAAQZ,QAAQE;GAChB,GAAIF,QAAQG,WAAW,EAAEA,SAAS,KAAK;GACvC,GAAIH,QAAQI,aAAaM,KAAAA,KAAa,EAAEN,UAAUJ,QAAQI,SAAS;EACrE;CACF;AACF;AAEA,MAAaS,4BACXd,eACAC,SACAK,UAC6C;CAC7C,MAAMZ,UAAUM,cAAcQ,MAC3BC,MAAMA,EAAEC,SAAS,mBAAmBD,EAAEX,OAAOG,QAAQc,UACxD;CACA,IAAIrB,YAAYiB,KAAAA,GACd,MAAM,IAAId,MACR,8CAA8CI,QAAQc,WAAU,EAClE;CACFtB,iBAAiBC,OAAO;CACxB,OAAO;EACLgB,MAAM;EACN,GAAIJ,UAAU,QAAQ,EAAEA,MAAM;EAC9BM,WAAWlB,QAAQI;EACnBF,UAAU;GACRoB,UAAUf,QAAQgB,WAAW,YAAY;GACzC,GAAIhB,QAAQiB,WAAWP,KAAAA,KAAa,EAAEQ,SAASlB,QAAQiB,OAAO;EAChE;CACF;AACF"}
|
package/dist/runCommands.d.ts
CHANGED
|
@@ -20,14 +20,25 @@ declare const viewedLeafId: (messages: readonly {
|
|
|
20
20
|
}[]) => string | null;
|
|
21
21
|
declare const resolveEditCommand: (messages: readonly {
|
|
22
22
|
id: string;
|
|
23
|
-
}[], message: AppendMessage) => AssistantTransportThread.RunEditCommand;
|
|
23
|
+
}[], message: AppendMessage, runId: string | null) => AssistantTransportThread.RunEditCommand;
|
|
24
|
+
/** The send fields for a run-creating or run-targeting enqueue/steer: target the live run, or mint a fresh one anchored at the viewed leaf. */
|
|
25
|
+
declare const sendFields: (messages: readonly {
|
|
26
|
+
id: string;
|
|
27
|
+
status?: {
|
|
28
|
+
type: string;
|
|
29
|
+
};
|
|
30
|
+
}[], runId: string | null, message: AssistantTransportThread.RunUserMessage) => {
|
|
31
|
+
runId: string;
|
|
32
|
+
message: AssistantTransportThread.RunUserMessage;
|
|
33
|
+
runAnchorMessageId?: string | null;
|
|
34
|
+
};
|
|
24
35
|
declare const createRunQueueAdapter: (messages: readonly {
|
|
25
36
|
id: string;
|
|
26
|
-
}[], queueItems: readonly AssistantTransportThread.RunQueueItem[], steerQueueItems: readonly AssistantTransportThread.RunQueueItem[] | undefined, dispatch: (command: AssistantTransportThread.RunCommand) => void, dispatchSend: (command: AssistantTransportThread.RunCommand, message: AppendMessage) => void) => ExternalThreadQueueAdapter;
|
|
37
|
+
}[], runId: string | null, queueItems: readonly AssistantTransportThread.RunQueueItem[], steerQueueItems: readonly AssistantTransportThread.RunQueueItem[] | undefined, dispatch: (command: AssistantTransportThread.RunCommand) => void, dispatchSend: (command: AssistantTransportThread.RunCommand, message: AppendMessage) => void) => ExternalThreadQueueAdapter;
|
|
27
38
|
declare const resolveReloadCommand: (messages: readonly {
|
|
28
39
|
id: string;
|
|
29
40
|
role: string;
|
|
30
|
-
}[], parentId: string | null) => AssistantTransportThread.RunReloadCommand;
|
|
41
|
+
}[], parentId: string | null, runId: string | null) => AssistantTransportThread.RunReloadCommand;
|
|
31
42
|
//#endregion
|
|
32
|
-
export { createRunQueueAdapter, resolveEditCommand, resolveReloadCommand, toQueueItemState, toWireMessage, viewedLeafId };
|
|
43
|
+
export { createRunQueueAdapter, resolveEditCommand, resolveReloadCommand, sendFields, toQueueItemState, toWireMessage, viewedLeafId };
|
|
33
44
|
//# sourceMappingURL=runCommands.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runCommands.d.ts","names":[],"sources":["../src/runCommands.ts"],"mappings":";;;cAOa,gBACX,SAAS,eACT,eACC,yBAAyB;cAwCf,mBACX,MAAM,yBAAyB;;;UAAA,yBAAA;;;;;;;cA2BpB,eACX;EAAqB;EAAY;IAAW;;;cASjC,qBACX;EAAqB;KACrB,SAAS,
|
|
1
|
+
{"version":3,"file":"runCommands.d.ts","names":[],"sources":["../src/runCommands.ts"],"mappings":";;;cAOa,gBACX,SAAS,eACT,eACC,yBAAyB;cAwCf,mBACX,MAAM,yBAAyB;;;UAAA,yBAAA;;;;;;;cA2BpB,eACX;EAAqB;EAAY;IAAW;;;cASjC,qBACX;EAAqB;KACrB,SAAS,eACT,yBACC,yBAAyB;;cAkBf,aACX;EAAqB;EAAY;IAAW;;KAC5C,sBACA,SAAS,yBAAyB;EAElC;EACA,SAAS,yBAAyB;EAClC;;cAUW,wBACX;EAAqB;KACrB,sBACA,qBAAqB,yBAAyB,gBAC9C,0BAA0B,yBAAyB,4BACnD,WAAW,SAAS,yBAAyB,qBAC7C,eACE,SAAS,yBAAyB,YAClC,SAAS,2BAEV;cA8DU,uBACX;EAAqB;EAAY;KACjC,yBACA,yBACC,yBAAyB"}
|