@assistant-ui/react 0.15.14 → 0.15.16
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/assistant-transport.d.ts +32 -0
- package/dist/assistant-transport.d.ts.map +1 -0
- package/dist/assistant-transport.js +27 -0
- package/dist/assistant-transport.js.map +1 -0
- package/dist/context/providers/MessageProvider.js +1 -1
- package/dist/devtools/DevToolsHooks.d.ts +0 -2
- package/dist/devtools/DevToolsHooks.d.ts.map +1 -1
- package/dist/devtools/DevToolsHooks.js +10 -12
- package/dist/devtools/DevToolsHooks.js.map +1 -1
- package/dist/hooks/useMessageQuote.js +1 -1
- package/dist/hooks/useToolCallElapsed.js +1 -1
- package/dist/index.d.ts +4 -7
- package/dist/index.js +6 -8
- package/dist/legacy-runtime/AssistantRuntimeProvider.js +1 -1
- package/dist/mcp-apps/McpAppRenderer.js +1 -1
- package/dist/mcp-apps/McpAppsRemoteHost.d.ts.map +1 -1
- package/dist/mcp-apps/McpAppsRemoteHost.js +18 -2
- package/dist/mcp-apps/McpAppsRemoteHost.js.map +1 -1
- package/dist/mcp-apps/bridge.d.ts.map +1 -1
- package/dist/mcp-apps/bridge.js +33 -24
- package/dist/mcp-apps/bridge.js.map +1 -1
- package/dist/model-context/makeAssistantVisible.js +1 -1
- package/dist/primitives/actionBar/ActionBarCopy.js +1 -1
- package/dist/primitives/actionBar/ActionBarExportMarkdown.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarExportMarkdown.js +5 -2
- package/dist/primitives/actionBar/ActionBarExportMarkdown.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackNegative.js +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackPositive.js +1 -1
- package/dist/primitives/actionBar/ActionBarStopSpeaking.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarStopSpeaking.js +24 -37
- package/dist/primitives/actionBar/ActionBarStopSpeaking.js.map +1 -1
- package/dist/primitives/actionBar/useActionBarFloatStatus.js +1 -1
- package/dist/primitives/assistantModal/AssistantModalRoot.js +1 -1
- package/dist/primitives/attachment/AttachmentName.js +1 -1
- package/dist/primitives/attachment/AttachmentRemove.js +1 -1
- package/dist/primitives/attachment/AttachmentThumb.js +1 -1
- package/dist/primitives/branchPicker/BranchPickerCount.js +1 -1
- package/dist/primitives/branchPicker/BranchPickerNumber.js +1 -1
- package/dist/primitives/branchPicker/BranchPickerRoot.d.ts.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerRoot.js +20 -15
- package/dist/primitives/branchPicker/BranchPickerRoot.js.map +1 -1
- package/dist/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.js +1 -1
- package/dist/primitives/composer/ComposerAddAttachment.js +1 -1
- package/dist/primitives/composer/ComposerAttachmentDropzone.js +1 -1
- package/dist/primitives/composer/ComposerDictationTranscript.d.ts +2 -2
- package/dist/primitives/composer/ComposerDictationTranscript.js +3 -3
- package/dist/primitives/composer/ComposerDictationTranscript.js.map +1 -1
- package/dist/primitives/composer/ComposerInput.js +2 -2
- package/dist/primitives/composer/ComposerInput.js.map +1 -1
- package/dist/primitives/composer/ComposerQuote.js +1 -1
- package/dist/primitives/composer/ComposerRoot.js +1 -1
- package/dist/primitives/composer/ComposerStopDictation.js +1 -1
- package/dist/primitives/composer/trigger/TriggerPopover.js +1 -1
- package/dist/primitives/composer/trigger/triggerSelectionResource.d.ts.map +1 -1
- package/dist/primitives/composer/trigger/triggerSelectionResource.js +24 -20
- package/dist/primitives/composer/trigger/triggerSelectionResource.js.map +1 -1
- package/dist/primitives/composer/useComposerInputState.js +1 -1
- package/dist/primitives/message/MessageIf.js +1 -1
- package/dist/primitives/message/MessagePartsGrouped.js +1 -1
- package/dist/primitives/message/MessageRoot.js +1 -1
- package/dist/primitives/message.js +1 -1
- package/dist/primitives/queueItem/QueueItemRemove.js +1 -1
- package/dist/primitives/queueItem/QueueItemSteer.js +1 -1
- package/dist/primitives/queueItem/QueueItemText.js +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarQuote.js +1 -1
- package/dist/primitives/suggestion/SuggestionDescription.js +1 -1
- package/dist/primitives/suggestion/SuggestionTitle.js +1 -1
- package/dist/primitives/suggestion/SuggestionTrigger.js +1 -1
- package/dist/primitives/thread/ThreadIf.js +1 -1
- package/dist/primitives/thread/ThreadRoot.d.ts +3 -0
- package/dist/primitives/thread/ThreadRoot.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadRoot.js +44 -9
- package/dist/primitives/thread/ThreadRoot.js.map +1 -1
- package/dist/primitives/thread/ThreadViewport.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadViewport.js +2 -13
- package/dist/primitives/thread/ThreadViewport.js.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.d.ts.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.js +23 -8
- package/dist/primitives/thread/useThreadViewportAutoScroll.js.map +1 -1
- package/dist/primitives/threadList/ThreadListNew.js +1 -1
- package/dist/sandbox-host/SandboxHost.d.ts.map +1 -1
- package/dist/sandbox-host/SandboxHost.js +6 -1
- package/dist/sandbox-host/SandboxHost.js.map +1 -1
- package/dist/unstable/useComposerInput.d.ts +2 -2
- package/dist/unstable/useComposerInput.js +1 -1
- package/dist/unstable/useComposerInput.js.map +1 -1
- package/dist/unstable/useComposerInputHistory.js +2 -2
- package/dist/unstable/useComposerInputHistory.js.map +1 -1
- package/dist/unstable/useLiveCompletionAdapter.d.ts +5 -0
- package/dist/unstable/useLiveCompletionAdapter.d.ts.map +1 -1
- package/dist/unstable/useLiveCompletionAdapter.js +16 -3
- package/dist/unstable/useLiveCompletionAdapter.js.map +1 -1
- package/dist/unstable/useMentionAdapter.d.ts +1 -1
- package/dist/utils/invokeCallbackSafely.d.ts +5 -0
- package/dist/utils/invokeCallbackSafely.d.ts.map +1 -0
- package/dist/utils/invokeCallbackSafely.js +15 -0
- package/dist/utils/invokeCallbackSafely.js.map +1 -0
- package/dist/utils/smooth/SmoothContext.d.ts +6 -6
- package/dist/utils/smooth/SmoothContext.js +1 -1
- package/dist/utils/smooth/useSmooth.d.ts +3 -0
- package/dist/utils/smooth/useSmooth.d.ts.map +1 -1
- package/dist/utils/smooth/useSmooth.js +16 -1
- package/dist/utils/smooth/useSmooth.js.map +1 -1
- package/dist/utils/useToolArgsFieldStatus.js +1 -1
- package/package.json +10 -10
- package/src/assistant-transport.ts +94 -0
- package/src/devtools/DevToolsHooks.test.ts +40 -0
- package/src/devtools/DevToolsHooks.ts +10 -15
- package/src/index.ts +8 -4
- package/src/mcp-apps/McpAppsRemoteHost.test.ts +29 -3
- package/src/mcp-apps/McpAppsRemoteHost.ts +42 -7
- package/src/mcp-apps/bridge.test.ts +153 -0
- package/src/mcp-apps/bridge.ts +42 -30
- package/src/model-context/frame/SPEC_AssistantFrame.md +1 -1
- package/src/primitives/actionBar/ActionBarExportMarkdown.test.tsx +67 -0
- package/src/primitives/actionBar/ActionBarExportMarkdown.tsx +3 -1
- package/src/primitives/actionBar/ActionBarStopSpeaking.tsx +0 -9
- package/src/primitives/branchPicker/BranchPickerRoot.tsx +5 -3
- package/src/primitives/composer/ComposerDictationTranscript.tsx +2 -2
- package/src/primitives/composer/ComposerInput.tsx +1 -1
- package/src/primitives/composer/trigger/triggerSelectionResource.test.ts +135 -0
- package/src/primitives/composer/trigger/triggerSelectionResource.ts +2 -0
- package/src/primitives/thread/ThreadRoot.test.tsx +251 -0
- package/src/primitives/thread/ThreadRoot.tsx +33 -0
- package/src/primitives/thread/ThreadViewport.tsx +1 -8
- package/src/primitives/thread/useThreadViewportAutoScroll.test.tsx +152 -0
- package/src/primitives/thread/useThreadViewportAutoScroll.ts +26 -19
- package/src/sandbox-host/SandboxHost.test.tsx +90 -0
- package/src/sandbox-host/SandboxHost.tsx +8 -2
- package/src/tests/RemoteThreadListRuntime.adapterProvider.test.tsx +24 -3
- package/src/tests/RemoteThreadListRuntime.reloadMainThread.test.tsx +1 -2
- package/src/tests/augmentations.test.ts +49 -0
- package/src/tests/in-memory-thread-list.test.tsx +1 -1
- package/src/tests/threadMessageById.test.tsx +61 -1
- package/src/unstable/useComposerInput.ts +2 -2
- package/src/unstable/useComposerInputHistory.test.tsx +4 -4
- package/src/unstable/useComposerInputHistory.ts +1 -1
- package/src/unstable/useLiveCompletionAdapter.test.tsx +157 -0
- package/src/unstable/useLiveCompletionAdapter.ts +41 -17
- package/src/utils/invokeCallbackSafely.ts +11 -0
- package/src/utils/smooth/useSmooth.test.tsx +110 -0
- package/src/utils/smooth/useSmooth.ts +20 -6
- package/dist/client/InMemoryThreadList.d.ts +0 -12
- package/dist/client/InMemoryThreadList.d.ts.map +0 -1
- package/dist/client/InMemoryThreadList.js +0 -374
- package/dist/client/InMemoryThreadList.js.map +0 -1
- package/dist/context/react/utils/ensureBinding.d.ts +0 -5
- package/dist/context/react/utils/ensureBinding.d.ts.map +0 -1
- package/dist/context/react/utils/ensureBinding.js +0 -24
- package/dist/context/react/utils/ensureBinding.js.map +0 -1
- package/dist/context/react/utils/useRuntimeState.d.ts +0 -13
- package/dist/context/react/utils/useRuntimeState.d.ts.map +0 -1
- package/dist/context/react/utils/useRuntimeState.js +0 -33
- package/dist/context/react/utils/useRuntimeState.js.map +0 -1
- package/dist/legacy-runtime/cloud/auiV0.d.ts +0 -119
- package/dist/legacy-runtime/cloud/auiV0.d.ts.map +0 -1
- package/dist/legacy-runtime/cloud/auiV0.js +0 -137
- package/dist/legacy-runtime/cloud/auiV0.js.map +0 -1
- package/dist/legacy-runtime/cloud/useCloudThreadListRuntime.d.ts +0 -16
- package/dist/legacy-runtime/cloud/useCloudThreadListRuntime.d.ts.map +0 -1
- package/dist/legacy-runtime/cloud/useCloudThreadListRuntime.js +0 -36
- package/dist/legacy-runtime/cloud/useCloudThreadListRuntime.js.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/commandQueue.d.ts +0 -17
- package/dist/legacy-runtime/runtime-cores/assistant-transport/commandQueue.d.ts.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/commandQueue.js +0 -55
- package/dist/legacy-runtime/runtime-cores/assistant-transport/commandQueue.js.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/replayBoundaryStream.d.ts +0 -11
- package/dist/legacy-runtime/runtime-cores/assistant-transport/replayBoundaryStream.d.ts.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/replayBoundaryStream.js +0 -165
- package/dist/legacy-runtime/runtime-cores/assistant-transport/replayBoundaryStream.js.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.d.ts +0 -15
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.d.ts.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.js +0 -81
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.js.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts +0 -126
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.js +0 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts +0 -14
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +0 -290
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.d.ts +0 -7
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.d.ts.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.js +0 -25
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.js.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useLatestRef.d.ts +0 -7
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useLatestRef.d.ts.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useLatestRef.js +0 -27
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useLatestRef.js.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/utils.d.ts +0 -2
- package/dist/legacy-runtime/runtime-cores/assistant-transport/utils.js +0 -2
- package/src/client/InMemoryThreadList.ts +0 -247
- package/src/context/react/utils/ensureBinding.ts +0 -46
- package/src/context/react/utils/useRuntimeState.ts +0 -46
- package/src/legacy-runtime/cloud/auiV0.ts +0 -331
- package/src/legacy-runtime/cloud/useCloudThreadListRuntime.ts +0 -31
- package/src/legacy-runtime/runtime-cores/assistant-transport/commandQueue.ts +0 -68
- package/src/legacy-runtime/runtime-cores/assistant-transport/replayBoundaryStream.test.ts +0 -455
- package/src/legacy-runtime/runtime-cores/assistant-transport/replayBoundaryStream.ts +0 -172
- package/src/legacy-runtime/runtime-cores/assistant-transport/runManager.ts +0 -113
- package/src/legacy-runtime/runtime-cores/assistant-transport/transport-delivery.test.tsx +0 -79
- package/src/legacy-runtime/runtime-cores/assistant-transport/transport-parentid.test.tsx +0 -97
- package/src/legacy-runtime/runtime-cores/assistant-transport/transport-scheduling.test.ts +0 -307
- package/src/legacy-runtime/runtime-cores/assistant-transport/types.ts +0 -170
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransport.spec.md +0 -141
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.test.tsx +0 -585
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.ts +0 -476
- package/src/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.ts +0 -20
- package/src/legacy-runtime/runtime-cores/assistant-transport/useLatestRef.ts +0 -9
- package/src/legacy-runtime/runtime-cores/assistant-transport/utils.ts +0 -1
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import type { ToolModelContentPart } from "assistant-stream";
|
|
2
|
-
import type { ThreadMessage } from "@assistant-ui/core";
|
|
3
|
-
import type { ReadonlyJSONValue } from "assistant-stream/utils";
|
|
4
|
-
import type {
|
|
5
|
-
AttachmentAdapter,
|
|
6
|
-
ThreadHistoryAdapter,
|
|
7
|
-
LanguageModelV1CallSettings,
|
|
8
|
-
LanguageModelConfig,
|
|
9
|
-
} from "@assistant-ui/core";
|
|
10
|
-
import type { UserCommands } from "../../../augmentations";
|
|
11
|
-
import type { ToolExecutionStatus } from "@assistant-ui/core";
|
|
12
|
-
|
|
13
|
-
// Message part types
|
|
14
|
-
export type TextPart = {
|
|
15
|
-
readonly type: "text";
|
|
16
|
-
readonly text: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type ImagePart = {
|
|
20
|
-
readonly type: "image";
|
|
21
|
-
readonly image: string;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export type UserMessagePart = TextPart | ImagePart;
|
|
25
|
-
|
|
26
|
-
export type UserMessage = {
|
|
27
|
-
readonly role: "user";
|
|
28
|
-
readonly parts: readonly UserMessagePart[];
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type AssistantMessage = {
|
|
32
|
-
readonly role: "assistant";
|
|
33
|
-
readonly parts: readonly TextPart[];
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
// Command types
|
|
37
|
-
export type AddMessageCommand = {
|
|
38
|
-
readonly type: "add-message";
|
|
39
|
-
readonly message: UserMessage | AssistantMessage;
|
|
40
|
-
readonly parentId: string | null;
|
|
41
|
-
readonly sourceId: string | null;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export type AddToolResultCommand = {
|
|
45
|
-
readonly type: "add-tool-result";
|
|
46
|
-
readonly toolCallId: string;
|
|
47
|
-
readonly toolName: string;
|
|
48
|
-
readonly result: ReadonlyJSONValue;
|
|
49
|
-
readonly isError: boolean;
|
|
50
|
-
readonly artifact?: ReadonlyJSONValue;
|
|
51
|
-
readonly modelContent?: readonly ToolModelContentPart[];
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export type AssistantTransportCommand =
|
|
55
|
-
| AddMessageCommand
|
|
56
|
-
| AddToolResultCommand
|
|
57
|
-
| UserCommands;
|
|
58
|
-
|
|
59
|
-
// State types
|
|
60
|
-
export type AssistantTransportState = {
|
|
61
|
-
readonly messages: readonly ThreadMessage[];
|
|
62
|
-
readonly state?: ReadonlyJSONValue;
|
|
63
|
-
readonly isRunning: boolean;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export type AssistantTransportConnectionMetadata = {
|
|
67
|
-
pendingCommands: AssistantTransportCommand[];
|
|
68
|
-
isSending: boolean;
|
|
69
|
-
toolStatuses: Record<string, ToolExecutionStatus>;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export type AssistantTransportStateConverter<T> = (
|
|
73
|
-
state: T,
|
|
74
|
-
connectionMetadata: AssistantTransportConnectionMetadata,
|
|
75
|
-
) => AssistantTransportState;
|
|
76
|
-
|
|
77
|
-
// Queue types
|
|
78
|
-
export type CommandQueueState = {
|
|
79
|
-
queued: AssistantTransportCommand[];
|
|
80
|
-
inTransit: AssistantTransportCommand[];
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// For now, queued items are plain commands (runConfig not supported)
|
|
84
|
-
export type QueuedCommand = AssistantTransportCommand;
|
|
85
|
-
|
|
86
|
-
// Task types
|
|
87
|
-
|
|
88
|
-
// Options types
|
|
89
|
-
export type HeadersValue = Record<string, string> | Headers;
|
|
90
|
-
|
|
91
|
-
export type AssistantTransportProtocol = "data-stream" | "assistant-transport";
|
|
92
|
-
|
|
93
|
-
export type SendCommandsRequestBody = {
|
|
94
|
-
commands: QueuedCommand[];
|
|
95
|
-
/** Absent on a resume with `resumeStateApi`; the server replays from its retained snapshot. */
|
|
96
|
-
state?: unknown;
|
|
97
|
-
runId?: string;
|
|
98
|
-
system: string | undefined;
|
|
99
|
-
tools: Record<string, unknown> | undefined;
|
|
100
|
-
callSettings: LanguageModelV1CallSettings | undefined;
|
|
101
|
-
config: LanguageModelConfig | undefined;
|
|
102
|
-
threadId: string | null;
|
|
103
|
-
parentId?: string | null;
|
|
104
|
-
// `callSettings` and `config` fields are also spread at the top level for
|
|
105
|
-
// backward compatibility (e.g. `body.modelName`). Use the nested objects
|
|
106
|
-
// instead. The top-level fields will be removed in a future version.
|
|
107
|
-
[key: string]: unknown;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export type AssistantTransportOptions<T> = {
|
|
111
|
-
initialState: T;
|
|
112
|
-
api: string;
|
|
113
|
-
resumeApi?: string;
|
|
114
|
-
/** Endpoint that returns the retained initial state and run ID for a resume stream. A 204 response means no run is active and the resume is skipped. */
|
|
115
|
-
resumeStateApi?: string;
|
|
116
|
-
protocol?: AssistantTransportProtocol;
|
|
117
|
-
/**
|
|
118
|
-
* When `false`, stream decoding and state reconciliation tolerate malformed
|
|
119
|
-
* input (invalid chunks are dropped with a console log) instead of throwing.
|
|
120
|
-
* Resume runs always decode leniently. Defaults to `true`.
|
|
121
|
-
*/
|
|
122
|
-
strict?: boolean;
|
|
123
|
-
converter: AssistantTransportStateConverter<T>;
|
|
124
|
-
headers: HeadersValue | (() => Promise<HeadersValue>);
|
|
125
|
-
body?: object | (() => Promise<object | undefined>);
|
|
126
|
-
/**
|
|
127
|
-
* Transform the request body before it is sent to the API.
|
|
128
|
-
* Receives the fully assembled body and returns the (potentially transformed) body.
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* ```ts
|
|
132
|
-
* prepareSendCommandsRequest: (body) => ({
|
|
133
|
-
* ...body,
|
|
134
|
-
* trackingId: crypto.randomUUID(),
|
|
135
|
-
* })
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
prepareSendCommandsRequest?: (
|
|
139
|
-
body: SendCommandsRequestBody,
|
|
140
|
-
) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
141
|
-
onResponse?: (response: Response) => void;
|
|
142
|
-
onFinish?: () => void;
|
|
143
|
-
onError?: (
|
|
144
|
-
error: Error,
|
|
145
|
-
params: {
|
|
146
|
-
commands: AssistantTransportCommand[];
|
|
147
|
-
updateState: (updater: (state: T) => T) => void;
|
|
148
|
-
},
|
|
149
|
-
) => void | Promise<void>;
|
|
150
|
-
/**
|
|
151
|
-
* Called when commands are cancelled.
|
|
152
|
-
*
|
|
153
|
-
* When an error occurs, queued commands are automatically cancelled after `onError` settles.
|
|
154
|
-
* In this case, the `error` parameter contains the error that caused the cancellation.
|
|
155
|
-
*/
|
|
156
|
-
onCancel?: (params: {
|
|
157
|
-
commands: AssistantTransportCommand[];
|
|
158
|
-
updateState: (updater: (state: T) => T) => void;
|
|
159
|
-
error?: Error;
|
|
160
|
-
}) => void;
|
|
161
|
-
capabilities?: {
|
|
162
|
-
edit?: boolean;
|
|
163
|
-
};
|
|
164
|
-
adapters?: {
|
|
165
|
-
attachments?: AttachmentAdapter | undefined;
|
|
166
|
-
history?: ThreadHistoryAdapter | undefined;
|
|
167
|
-
};
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
// (no task or stream-specific types needed in this module)
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
useAssistantTransport
|
|
2
|
-
|
|
3
|
-
Overview
|
|
4
|
-
|
|
5
|
-
- Similar API as `useDataStreamRuntime`.
|
|
6
|
-
- Built on an external-store runtime; the external store issues "commands".
|
|
7
|
-
- Exactly one run is active at a time (single-flight).
|
|
8
|
-
- Runs take queued commands as input and consume an assistant stream that yields state snapshots.
|
|
9
|
-
- Every run flushes the entire command queue; a single run processes all pending commands.
|
|
10
|
-
|
|
11
|
-
Command Scheduling
|
|
12
|
-
|
|
13
|
-
- When commands are enqueued:
|
|
14
|
-
- If a run is in progress: do not start another; mark that a follow-up run is pending.
|
|
15
|
-
- When the current run ends: if commands were scheduled during the run, start a new run and publish them.
|
|
16
|
-
- If no run is in progress: start a run immediately and flush commands to the server.
|
|
17
|
-
- A follow-up run that finds an empty queue is a no-op: no request is sent and no error is surfaced.
|
|
18
|
-
- A resume run sends no commands; commands enqueued while it is pending or active are flushed in a follow-up run after it settles.
|
|
19
|
-
|
|
20
|
-
Resume State
|
|
21
|
-
|
|
22
|
-
- With `resumeStateApi` configured, a resume first posts `{ threadId }` there; the endpoint returns `{ runId, state }`, the state that started the active run.
|
|
23
|
-
- The resume request carries `runId` and no `state`: the server replays from the snapshot it retained for that run, so neither `body` overrides nor a `prepareSendCommandsRequest` rebuild can substitute a different base. `runId` takes precedence over `body` fields and is re-attached after `prepareSendCommandsRequest` so a rebuilt body cannot drop it. The local base is replaced by the snapshot only after the resume stream responds OK, so a rejected resume keeps the local state.
|
|
24
|
-
- A 204 response means no active run: the resume is skipped without error, and queued commands are flushed in a follow-up run.
|
|
25
|
-
- A malformed snapshot response fails the resume before the replay request is sent.
|
|
26
|
-
- If a pending resume is dropped by an error or cancellation, later commands start normal runs.
|
|
27
|
-
- Runs execute on a `queueMicrotask`, so multiple synchronous enqueues coalesce into a single request: the first run's flush takes all of them, and the coalesced follow-up run no-ops.
|
|
28
|
-
|
|
29
|
-
Command Queue
|
|
30
|
-
|
|
31
|
-
`useCommandQueue({ onQueue() { runManager.schedule(); } })`
|
|
32
|
-
|
|
33
|
-
- `enqueue(cmd, { schedule? })`: Adds a command to the queue. Calls `onQueue` unless `schedule: false`.
|
|
34
|
-
- `flush(): Command[]`: Returns all queued commands, moves them into `inTransit`, and clears the queue.
|
|
35
|
-
- Internal state tracks `inTransit: Command[]` and `queued: Command[]`.
|
|
36
|
-
|
|
37
|
-
Run Manager
|
|
38
|
-
|
|
39
|
-
`useRunManager({
|
|
40
|
-
async onRun(signal) {
|
|
41
|
-
const commands = commandQueue.flush();
|
|
42
|
-
setInTransitCommands(commands);
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
const response = await fetch(backendUrl, { signal });
|
|
46
|
-
const stream = response.body
|
|
47
|
-
.pipeThrough(new DataStreamDecoder())
|
|
48
|
-
.pipeThrough(
|
|
49
|
-
new AssistantMessageAccumulator({
|
|
50
|
-
initialMessage: createInitialMessage({
|
|
51
|
-
unstable_state: (state.state as ReadonlyJSONValue) ?? null,
|
|
52
|
-
}),
|
|
53
|
-
}),
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
for await (const snapshot of stream) {
|
|
57
|
-
// Clear in-transit commands after the first response chunk.
|
|
58
|
-
// Use a stable empty array to avoid unnecessary re-renders.
|
|
59
|
-
setInTransitCommands(EMPTY_ARRAY);
|
|
60
|
-
setSnapshot(snapshot);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// A run that completes successfully confirms delivery even when no
|
|
64
|
-
// state-changing chunk was observed — clear in-transit commands here
|
|
65
|
-
// as well.
|
|
66
|
-
setInTransitCommands(EMPTY_ARRAY);
|
|
67
|
-
} catch (error) {
|
|
68
|
-
// Do not restore commands. Surface error to onError for state update.
|
|
69
|
-
callbacks.onError?.({
|
|
70
|
-
error,
|
|
71
|
-
commands: getCurrentInTransitCommands(),
|
|
72
|
-
updateState(updater) {
|
|
73
|
-
setSnapshot((prev) => updater(prev));
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
},
|
|
79
|
-
})`
|
|
80
|
-
|
|
81
|
-
- `schedule()`: Starts immediately if idle, or schedules at most one follow-up run to start right after the current run.
|
|
82
|
-
- `cancel()`: Aborts the active run via `signal` and clears any scheduled follow-up run. Does not restore commands.
|
|
83
|
-
- Unmount aborts the active run via `signal`; no callbacks (`onCancel`, `onError`, `onFinish`) are invoked. StrictMode's setup/cleanup/setup effect cycle re-arms the manager.
|
|
84
|
-
- `isRunning: boolean`: Indicates whether a run is currently active (internal to scheduling).
|
|
85
|
-
UI-facing `isRunning` is controlled by the converter output (see Converter).
|
|
86
|
-
- On cancellation, invoke `callbacks.onCancel?.({ commands, updateState })` where `commands` contains all pending work at the time of cancel: `[...inTransitCommands, ...queuedCommands]`. Note: after the first snapshot arrives, `inTransitCommands` are cleared to `[]`, so cancels after first byte will not include them.
|
|
87
|
-
- RunConfig is not supported for now; any provided run configuration is ignored.
|
|
88
|
-
|
|
89
|
-
Converter
|
|
90
|
-
|
|
91
|
-
`useConverter({
|
|
92
|
-
converter,
|
|
93
|
-
agentState,
|
|
94
|
-
queuedCommands,
|
|
95
|
-
inTransitCommands,
|
|
96
|
-
})`
|
|
97
|
-
|
|
98
|
-
- Reactive pattern: do not imperatively set converted state. Maintain an `agentState` snapshot variable (updated via stream), and compute the converted UI state with a memoized converter.
|
|
99
|
-
- Example: `const pending = [...inTransitCommands, ...queuedCommands]; const converted = useMemo(() => converter(agentState, { pendingCommands: pending, isSending }), [agentState, pending, isSending])`
|
|
100
|
-
- `isSending` should be sourced from the run manager’s `isRunning` flag.
|
|
101
|
-
- Returns `AssistantTransportState` with `{ messages, isRunning }` derived from inputs via `converter`.
|
|
102
|
-
- The converter controls UI `isRunning`. Typical mapping: `isRunning = isSending`. Advanced policies are allowed (e.g., extend running while reconciling, or suppress during background tool results).
|
|
103
|
-
- Assistant stream deltas are applied by `AssistantMessageAccumulator`, which emits immutable full-state snapshots; no additional delta handling is required in the converter.
|
|
104
|
-
|
|
105
|
-
Tool Invocations
|
|
106
|
-
|
|
107
|
-
`useToolInvocations({
|
|
108
|
-
messages,
|
|
109
|
-
onResult(result) { commandQueue.enqueue(result); },
|
|
110
|
-
})`
|
|
111
|
-
|
|
112
|
-
- Uses a ToolCall differ to diff tool calls across successive snapshots (e.g., ToolCallDiffer).
|
|
113
|
-
- When a tool call’s argsText transitions from incomplete → complete and `result` is undefined, synthesize a tool-execution event and enqueue an `add-tool-result` command via `onResult`.
|
|
114
|
-
- `onResult` is for frontend function calling (client-side tool calls producing results to enqueue).
|
|
115
|
-
- No return value.
|
|
116
|
-
|
|
117
|
-
External Store Runtime Bridge
|
|
118
|
-
|
|
119
|
-
`useExternalStoreRuntime({
|
|
120
|
-
isRunning,
|
|
121
|
-
messages,
|
|
122
|
-
onNew(command) { commandQueue.enqueue(command); },
|
|
123
|
-
onCancel() { runManager.cancel(); },
|
|
124
|
-
onAddToolResult(result) { commandQueue.enqueue(result); },
|
|
125
|
-
})`
|
|
126
|
-
|
|
127
|
-
- `onAddToolResult` typically reflects userland-triggered results (e.g., human/tool calling) coming from the external store runtime.
|
|
128
|
-
|
|
129
|
-
Notes
|
|
130
|
-
|
|
131
|
-
- Use a stable `EMPTY_ARRAY` when clearing in-transit commands to minimize re-renders via referential equality.
|
|
132
|
-
- "Assistant stream" refers to the incremental response stream that yields state snapshots.
|
|
133
|
-
|
|
134
|
-
Callbacks
|
|
135
|
-
|
|
136
|
-
- `onError({ error, commands, updateState })`: invoked on network/stream errors. Commands are not restored; use `updateState(state => newState)` to reflect the error in state and/or messages. `commands` reflects the current in-transit commands at the moment of error (often `[]` after the first snapshot).
|
|
137
|
-
- `onCancel({ commands, updateState })`: invoked after a cancellation. Commands are not restored. `commands` contains all pending work at cancel time (`inTransitCommands` plus queued). Use `updateState` to reflect cancellation in state and/or messages. The last received snapshot remains committed.
|
|
138
|
-
|
|
139
|
-
Return Value
|
|
140
|
-
|
|
141
|
-
- `useAssistantTransport` returns the runtime object from `useExternalStoreRuntime` (e.g., `{ isRunning, messages, ... }`), rather than a custom wrapper shape.
|