@assistant-ui/react 0.15.4 → 0.15.5
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/client/ExternalThread.d.ts.map +1 -1
- package/dist/client/ExternalThread.js +383 -368
- package/dist/client/ExternalThread.js.map +1 -1
- package/dist/context/providers/MessageProvider.js +15 -34
- package/dist/context/providers/MessageProvider.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/legacy-runtime/AssistantRuntimeProvider.d.ts +6 -1
- package/dist/legacy-runtime/AssistantRuntimeProvider.d.ts.map +1 -1
- package/dist/legacy-runtime/AssistantRuntimeProvider.js +10 -8
- package/dist/legacy-runtime/AssistantRuntimeProvider.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.js +8 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts +5 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +44 -3
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarExportMarkdown.js +1 -1
- package/dist/primitives/actionBar/ActionBarExportMarkdown.js.map +1 -1
- package/dist/primitives/attachment/AttachmentThumb.d.ts.map +1 -1
- package/dist/primitives/attachment/AttachmentThumb.js +17 -14
- package/dist/primitives/attachment/AttachmentThumb.js.map +1 -1
- package/dist/primitives/composer/ComposerInput.js +1 -0
- package/dist/primitives/composer/ComposerInput.js.map +1 -1
- package/dist/primitives/queueItem/QueueItemText.d.ts.map +1 -1
- package/dist/primitives/queueItem/QueueItemText.js +10 -4
- package/dist/primitives/queueItem/QueueItemText.js.map +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarRoot.d.ts.map +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarRoot.js +5 -4
- package/dist/primitives/selectionToolbar/SelectionToolbarRoot.js.map +1 -1
- package/dist/utils/createActionButton.js +1 -1
- package/dist/utils/createActionButton.js.map +1 -1
- package/dist/utils/useToolArgsFieldStatus.d.ts +2 -2
- package/package.json +6 -6
- package/src/client/ExternalThread.ts +28 -16
- package/src/context/providers/MessageProvider.tsx +8 -6
- package/src/index.ts +5 -1
- package/src/legacy-runtime/AssistantRuntimeProvider.tsx +13 -3
- package/src/legacy-runtime/runtime-cores/assistant-transport/runManager.ts +14 -1
- package/src/legacy-runtime/runtime-cores/assistant-transport/transport-scheduling.test.ts +38 -0
- package/src/legacy-runtime/runtime-cores/assistant-transport/types.ts +5 -1
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransport.spec.md +7 -0
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.test.tsx +290 -0
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.ts +62 -1
- package/src/primitives/actionBar/ActionBarExportMarkdown.tsx +1 -1
- package/src/primitives/attachment/AttachmentThumb.test.tsx +70 -0
- package/src/primitives/attachment/AttachmentThumb.tsx +8 -4
- package/src/primitives/composer/ComposerInput.test.tsx +53 -2
- package/src/primitives/composer/ComposerInput.tsx +3 -0
- package/src/primitives/queueItem/QueueItemText.tsx +8 -2
- package/src/primitives/selectionToolbar/SelectionToolbarRoot.test.tsx +74 -0
- package/src/primitives/selectionToolbar/SelectionToolbarRoot.tsx +3 -3
- package/src/tests/external-thread-parity.test.tsx +9 -4
- package/src/tests/local-runtime-queue.test.tsx +199 -6
- package/src/utils/createActionButton.test.tsx +18 -0
- package/src/utils/createActionButton.tsx +1 -1
|
@@ -2,6 +2,9 @@ import { useLatestRef } from "./useLatestRef.js";
|
|
|
2
2
|
import { useCallback, useEffect, useRef, useState } from "@assistant-ui/tap/react-shim";
|
|
3
3
|
//#region src/legacy-runtime/runtime-cores/assistant-transport/runManager.ts
|
|
4
4
|
const disposeReason = Symbol("assistant-transport-dispose");
|
|
5
|
+
const reportFinishError = (error) => {
|
|
6
|
+
console.error("[assistant-ui] Assistant transport onFinish callback threw an error", error);
|
|
7
|
+
};
|
|
5
8
|
function useRunManager(config) {
|
|
6
9
|
const [isRunning, setIsRunning] = useState(false);
|
|
7
10
|
const stateRef = useRef({
|
|
@@ -29,7 +32,11 @@ function useRunManager(config) {
|
|
|
29
32
|
else await onErrorRef.current?.(error);
|
|
30
33
|
}
|
|
31
34
|
} finally {
|
|
32
|
-
if (!disposeAborted() && !stateRef.current.disposed)
|
|
35
|
+
if (!disposeAborted() && !stateRef.current.disposed) try {
|
|
36
|
+
Promise.resolve(onFinishRef.current?.()).catch(reportFinishError);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
reportFinishError(error);
|
|
39
|
+
}
|
|
33
40
|
if (!stateRef.current.disposed && stateRef.current.pending) startRun();
|
|
34
41
|
else {
|
|
35
42
|
setIsRunning(false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runManager.js","names":["useCallback","useEffect","useRef","useState","useLatestRef","RunManager","Readonly","isRunning","schedule","cancel","disposeReason","Symbol","useRunManager","config","onRun","signal","AbortSignal","Promise","onFinish","onCancel","onError","
|
|
1
|
+
{"version":3,"file":"runManager.js","names":["useCallback","useEffect","useRef","useState","useLatestRef","RunManager","Readonly","isRunning","schedule","cancel","disposeReason","Symbol","reportFinishError","error","console","useRunManager","config","onRun","signal","AbortSignal","Promise","onFinish","onCancel","onError","Error","setIsRunning","stateRef","pending","disposed","abortController","AbortController","onRunRef","onFinishRef","onCancelRef","onErrorRef","startRun","current","ac","disposeAborted","reason","queueMicrotask","aborted","resolve","catch","abort"],"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/runManager.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useLatestRef } from \"./useLatestRef\";\n\nexport type RunManager = Readonly<{\n isRunning: boolean;\n schedule: () => void;\n cancel: () => void;\n}>;\n\nconst disposeReason = Symbol(\"assistant-transport-dispose\");\n\nconst reportFinishError = (error: unknown) => {\n console.error(\n \"[assistant-ui] Assistant transport onFinish callback threw an error\",\n error,\n );\n};\n\nexport function useRunManager(config: {\n onRun: (signal: AbortSignal) => Promise<void>;\n onFinish?: (() => void) | undefined;\n onCancel?: (() => void) | undefined;\n onError?: ((error: Error) => void | Promise<void>) | undefined;\n}): RunManager {\n const [isRunning, setIsRunning] = useState(false);\n const stateRef = useRef({\n pending: false,\n disposed: false,\n abortController: null as AbortController | null,\n });\n const onRunRef = useLatestRef(config.onRun);\n const onFinishRef = useLatestRef(config.onFinish);\n const onCancelRef = useLatestRef(config.onCancel);\n const onErrorRef = useLatestRef(config.onError);\n\n const startRun = useCallback(() => {\n setIsRunning(true);\n stateRef.current.pending = false;\n const ac = new AbortController();\n stateRef.current.abortController = ac;\n\n // The dispose marker rides on the abort reason so a settling run detects\n // its own disposal even after an effect cycle re-arms the manager.\n const disposeAborted = () => ac.signal.reason === disposeReason;\n\n queueMicrotask(async () => {\n try {\n if (!disposeAborted()) {\n await onRunRef.current(ac.signal);\n }\n } catch (error) {\n if (!disposeAborted() && !stateRef.current.disposed) {\n stateRef.current.pending = false;\n if (ac.signal.aborted) {\n onCancelRef.current?.();\n } else {\n await onErrorRef.current?.(error as Error);\n }\n }\n } finally {\n if (!disposeAborted() && !stateRef.current.disposed) {\n try {\n void Promise.resolve(onFinishRef.current?.()).catch(\n reportFinishError,\n );\n } catch (error) {\n reportFinishError(error);\n }\n }\n if (!stateRef.current.disposed && stateRef.current.pending) {\n startRun();\n } else {\n setIsRunning(false);\n if (stateRef.current.abortController === ac) {\n stateRef.current.abortController = null;\n }\n }\n }\n });\n }, [onRunRef, onFinishRef, onErrorRef, onCancelRef]);\n\n const schedule = useCallback(() => {\n if (stateRef.current.disposed) return;\n if (stateRef.current.abortController) {\n // Coalesce multiple schedules while running into a single follow-up run.\n stateRef.current.pending = true;\n return;\n }\n startRun();\n }, [startRun]);\n\n // Strict-mode effects run setup / cleanup / setup on the same instance;\n // arming on setup undoes the cleanup's dispose.\n useEffect(() => {\n stateRef.current.disposed = false;\n return () => {\n stateRef.current.disposed = true;\n stateRef.current.pending = false;\n stateRef.current.abortController?.abort(disposeReason);\n };\n }, []);\n\n const cancel = useCallback(() => {\n stateRef.current.pending = false;\n stateRef.current.abortController?.abort();\n }, []);\n\n return {\n isRunning,\n schedule,\n cancel,\n };\n}\n"],"mappings":";;;AASA,MAAMU,gBAAgBC,OAAO,6BAA6B;AAE1D,MAAMC,qBAAqBC,UAAmB;CAC5CC,QAAQD,MACN,uEACAA,KACF;AACF;AAEA,SAAgBE,cAAcC,QAKf;CACb,MAAM,CAACT,WAAWkB,gBAAgBtB,SAAS,KAAK;CAChD,MAAMuB,WAAWxB,OAAO;EACtByB,SAAS;EACTC,UAAU;EACVC,iBAAiB;CACnB,CAAC;CACD,MAAME,WAAW3B,aAAaY,OAAOC,KAAK;CAC1C,MAAMe,cAAc5B,aAAaY,OAAOK,QAAQ;CAChD,MAAMY,cAAc7B,aAAaY,OAAOM,QAAQ;CAChD,MAAMY,aAAa9B,aAAaY,OAAOO,OAAO;CAE9C,MAAMY,WAAWnC,kBAAkB;EACjCyB,aAAa,IAAI;EACjBC,SAASU,QAAQT,UAAU;EAC3B,MAAMU,KAAK,IAAIP,gBAAgB;EAC/BJ,SAASU,QAAQP,kBAAkBQ;EAInC,MAAMC,uBAAuBD,GAAGnB,OAAOqB,WAAW7B;EAElD8B,eAAe,YAAY;GACzB,IAAI;IACF,IAAI,CAACF,eAAe,GAClB,MAAMP,SAASK,QAAQC,GAAGnB,MAAM;GAEpC,SAASL,OAAO;IACd,IAAI,CAACyB,eAAe,KAAK,CAACZ,SAASU,QAAQR,UAAU;KACnDF,SAASU,QAAQT,UAAU;KAC3B,IAAIU,GAAGnB,OAAOuB,SACZR,YAAYG,UAAU;UAEtB,MAAMF,WAAWE,UAAUvB,KAAc;IAE7C;GACF,UAAU;IACR,IAAI,CAACyB,eAAe,KAAK,CAACZ,SAASU,QAAQR,UACzC,IAAI;KACF,QAAac,QAAQV,YAAYI,UAAU,CAAC,CAAC,CAACO,MAC5C/B,iBACF;IACF,SAASC,OAAO;KACdD,kBAAkBC,KAAK;IACzB;IAEF,IAAI,CAACa,SAASU,QAAQR,YAAYF,SAASU,QAAQT,SACjDQ,SAAS;SACJ;KACLV,aAAa,KAAK;KAClB,IAAIC,SAASU,QAAQP,oBAAoBQ,IACvCX,SAASU,QAAQP,kBAAkB;IAEvC;GACF;EACF,CAAC;CACH,GAAG;EAACE;EAAUC;EAAaE;EAAYD;CAAW,CAAC;CAEnD,MAAMzB,WAAWR,kBAAkB;EACjC,IAAI0B,SAASU,QAAQR,UAAU;EAC/B,IAAIF,SAASU,QAAQP,iBAAiB;GAEpCH,SAASU,QAAQT,UAAU;GAC3B;EACF;EACAQ,SAAS;CACX,GAAG,CAACA,QAAQ,CAAC;CAIblC,gBAAgB;EACdyB,SAASU,QAAQR,WAAW;EAC5B,aAAa;GACXF,SAASU,QAAQR,WAAW;GAC5BF,SAASU,QAAQT,UAAU;GAC3BD,SAASU,QAAQP,iBAAiBe,MAAMlC,aAAa;EACvD;CACF,GAAG,CAAA,CAAE;CAOL,OAAO;EACLH;EACAC;EACAC,QARaT,kBAAkB;GAC/B0B,SAASU,QAAQT,UAAU;GAC3BD,SAASU,QAAQP,iBAAiBe,MAAM;EAC1C,GAAG,CAAA,CAKDnC;CACF;AACF"}
|
|
@@ -56,7 +56,9 @@ type HeadersValue = Record<string, string> | Headers;
|
|
|
56
56
|
type AssistantTransportProtocol = "data-stream" | "assistant-transport";
|
|
57
57
|
type SendCommandsRequestBody = {
|
|
58
58
|
commands: QueuedCommand[];
|
|
59
|
-
|
|
59
|
+
/** Absent on a resume with `resumeStateApi`; the server replays from its retained snapshot. */
|
|
60
|
+
state?: unknown;
|
|
61
|
+
runId?: string;
|
|
60
62
|
system: string | undefined;
|
|
61
63
|
tools: Record<string, unknown> | undefined;
|
|
62
64
|
callSettings: LanguageModelV1CallSettings | undefined;
|
|
@@ -69,6 +71,8 @@ type AssistantTransportOptions<T> = {
|
|
|
69
71
|
initialState: T;
|
|
70
72
|
api: string;
|
|
71
73
|
resumeApi?: string;
|
|
74
|
+
/** 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. */
|
|
75
|
+
resumeStateApi?: string;
|
|
72
76
|
protocol?: AssistantTransportProtocol;
|
|
73
77
|
/**
|
|
74
78
|
* When `false`, stream decoding and state reconciliation tolerate malformed
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/types.ts"],"mappings":";;;;;KAaY;WACD;WACA;;KAGC;WACD;WACA;;KAGC,kBAAkB,WAAW;KAE7B;WACD;WACA,gBAAgB;;KAGf;WACD;WACA,gBAAgB;;KAIf;WACD;WACA,SAAS,cAAc;WACvB;WACA;;KAGC;WACD;WACA;WACA;WACA,QAAQ;WACR;WACA,WAAW;WACX,wBAAwB;;KAGvB,4BACR,oBACA,uBACA;KAGQ;WACD,mBAAmB;WACnB,QAAQ;WACR;;KAGC;EACV,iBAAiB;EACjB;EACA,cAAc,eAAe;;KAGnB,iCAAiC,MAC3C,OAAO,GACP,oBAAoB,yCACjB;KAGO;EACV,QAAQ;EACR,WAAW;;KAID,gBAAgB;KAKhB,eAAe,yBAAyB;KAExC;KAEA;EACV,UAAU;
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/types.ts"],"mappings":";;;;;KAaY;WACD;WACA;;KAGC;WACD;WACA;;KAGC,kBAAkB,WAAW;KAE7B;WACD;WACA,gBAAgB;;KAGf;WACD;WACA,gBAAgB;;KAIf;WACD;WACA,SAAS,cAAc;WACvB;WACA;;KAGC;WACD;WACA;WACA;WACA,QAAQ;WACR;WACA,WAAW;WACX,wBAAwB;;KAGvB,4BACR,oBACA,uBACA;KAGQ;WACD,mBAAmB;WACnB,QAAQ;WACR;;KAGC;EACV,iBAAiB;EACjB;EACA,cAAc,eAAe;;KAGnB,iCAAiC,MAC3C,OAAO,GACP,oBAAoB,yCACjB;KAGO;EACV,QAAQ;EACR,WAAW;;KAID,gBAAgB;KAKhB,eAAe,yBAAyB;KAExC;KAEA;EACV,UAAU;;EAEV;EACA;EACA;EACA,OAAO;EACP,cAAc;EACd,QAAQ;EACR;EACA;GAIC;;KAGS,0BAA0B;EACpC,cAAc;EACd;EACA;;EAEA;EACA,WAAW;;;;;;EAMX;EACA,WAAW,iCAAiC;EAC5C,SAAS,sBAAsB,QAAQ;EACvC,uBAAuB;;;;;;;;;;;;;EAavB,8BACE,MAAM,4BACH,0BAA0B,QAAQ;EACvC,cAAc,UAAU;EACxB;EACA,WACE,OAAO,OACP;IACE,UAAU;IACV,cAAc,UAAU,OAAO,MAAM;eAE7B;;;;;;;EAOZ,YAAY;IACV,UAAU;IACV,cAAc,UAAU,OAAO,MAAM;IACrC,QAAQ;;EAEV;IACE;;EAEF;IACE,cAAc;IACd,UAAU"}
|
package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAssistantTransportRuntime.d.ts","names":[],"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"useAssistantTransportRuntime.d.ts","names":[],"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.ts"],"mappings":";;;;cA8Ha,yCAGH,SAAS;iBAOH,8BAA8B;iBAC9B,2BAA2B,GACzC,WAAW,OAAO,sBAAsB,IACvC;;;;cAmUU,+BAAgC,GAC3C,SAAS,0BAA0B,OAClC"}
|
package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js
CHANGED
|
@@ -35,6 +35,21 @@ const convertAppendMessageToCommand = (message) => {
|
|
|
35
35
|
sourceId: message.sourceId
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
|
+
const readResumeState = async (response) => {
|
|
39
|
+
if (response.status === 204) return null;
|
|
40
|
+
if (!response.ok) throw new Error(`Resume state request failed with status ${response.status}: ${await response.text()}`);
|
|
41
|
+
let value;
|
|
42
|
+
try {
|
|
43
|
+
value = await response.json();
|
|
44
|
+
} catch {
|
|
45
|
+
throw new Error("Resume state response was not valid JSON");
|
|
46
|
+
}
|
|
47
|
+
if (typeof value !== "object" || value === null || !("state" in value) || !("runId" in value) || typeof value.runId !== "string") throw new Error("Resume state response must contain state and runId");
|
|
48
|
+
return {
|
|
49
|
+
runId: value.runId,
|
|
50
|
+
state: value.state
|
|
51
|
+
};
|
|
52
|
+
};
|
|
38
53
|
const symbolAssistantTransportExtras = Symbol("assistant-transport-extras");
|
|
39
54
|
const asAssistantTransportExtras = (extras) => {
|
|
40
55
|
if (typeof extras !== "object" || extras == null || !(symbolAssistantTransportExtras in extras)) throw new Error("This method can only be called when you are using useAssistantTransportRuntime");
|
|
@@ -85,11 +100,26 @@ const useAssistantTransportThreadRuntime = (options) => {
|
|
|
85
100
|
const parentId = isResume ? void 0 : parentIdRef.current;
|
|
86
101
|
if (!isResume) parentIdRef.current = void 0;
|
|
87
102
|
const headers = await createRequestHeaders(options.headers);
|
|
103
|
+
let resumeState;
|
|
104
|
+
if (isResume && options.resumeStateApi) {
|
|
105
|
+
const resumeStateResponse = await fetch(options.resumeStateApi, {
|
|
106
|
+
method: "POST",
|
|
107
|
+
headers,
|
|
108
|
+
body: JSON.stringify({ threadId }),
|
|
109
|
+
signal
|
|
110
|
+
});
|
|
111
|
+
const retained = await readResumeState(resumeStateResponse);
|
|
112
|
+
if (retained === null) {
|
|
113
|
+
if (commandQueue.state.queued.length > 0) runManager.schedule();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
resumeState = retained;
|
|
117
|
+
}
|
|
88
118
|
const bodyValue = typeof options.body === "function" ? await options.body() : options.body;
|
|
89
119
|
const context = runtime.thread.getModelContext();
|
|
90
120
|
let requestBody = {
|
|
91
121
|
commands,
|
|
92
|
-
state: agentStateRef.current,
|
|
122
|
+
...resumeState === void 0 && { state: agentStateRef.current },
|
|
93
123
|
system: context.system,
|
|
94
124
|
tools: context.tools ? toToolsJSONSchema(context.tools) : void 0,
|
|
95
125
|
threadId,
|
|
@@ -101,6 +131,13 @@ const useAssistantTransportThreadRuntime = (options) => {
|
|
|
101
131
|
...bodyValue ?? {}
|
|
102
132
|
};
|
|
103
133
|
if (options.prepareSendCommandsRequest) requestBody = await options.prepareSendCommandsRequest(requestBody);
|
|
134
|
+
if (resumeState !== void 0) {
|
|
135
|
+
requestBody = {
|
|
136
|
+
...requestBody,
|
|
137
|
+
runId: resumeState.runId
|
|
138
|
+
};
|
|
139
|
+
delete requestBody["state"];
|
|
140
|
+
}
|
|
104
141
|
const response = await fetch(isResume ? options.resumeApi : options.api, {
|
|
105
142
|
method: "POST",
|
|
106
143
|
headers,
|
|
@@ -110,6 +147,10 @@ const useAssistantTransportThreadRuntime = (options) => {
|
|
|
110
147
|
options.onResponse?.(response);
|
|
111
148
|
if (!response.ok) throw new Error(`Status ${response.status}: ${await response.text()}`);
|
|
112
149
|
if (!response.body) throw new Error("Response body is null");
|
|
150
|
+
if (resumeState !== void 0) {
|
|
151
|
+
agentStateRef.current = resumeState.state;
|
|
152
|
+
rerender((prev) => prev + 1);
|
|
153
|
+
}
|
|
113
154
|
const body = await createReplayBoundaryStream(response, {
|
|
114
155
|
setReplaying: setIsReplaying,
|
|
115
156
|
waitForRender: waitForReplayRender
|
|
@@ -149,7 +190,7 @@ const useAssistantTransportThreadRuntime = (options) => {
|
|
|
149
190
|
commands: cmds,
|
|
150
191
|
updateState: (updater) => {
|
|
151
192
|
agentStateRef.current = updater(agentStateRef.current);
|
|
152
|
-
rerender((
|
|
193
|
+
rerender((prev_0) => prev_0 + 1);
|
|
153
194
|
}
|
|
154
195
|
});
|
|
155
196
|
},
|
|
@@ -224,7 +265,7 @@ const useAssistantTransportThreadRuntime = (options) => {
|
|
|
224
265
|
},
|
|
225
266
|
onLoadExternalState: async (state) => {
|
|
226
267
|
agentStateRef.current = state;
|
|
227
|
-
rerender((
|
|
268
|
+
rerender((prev_1) => prev_1 + 1);
|
|
228
269
|
}
|
|
229
270
|
});
|
|
230
271
|
return runtime;
|
package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAssistantTransportRuntime.js","names":["c","_c","AppendMessage","ReadonlyJSONObject","ReadonlyJSONValue","asAsyncIterableStream","useExternalStoreRuntime","AssistantRuntime","AddToolResultOptions","useMemo","useRef","useState","AssistantMessageAccumulator","DataStreamDecoder","AssistantTransportDecoder","unstable_createInitialMessage","createInitialMessage","toToolsJSONSchema","AssistantTransportOptions","AddMessageCommand","AddToolResultCommand","UserMessagePart","QueuedCommand","AssistantTransportCommand","SendCommandsRequestBody","useCommandQueue","createReplayBoundaryStream","useReplayRenderWait","useRunManager","useConvertedState","ToolExecutionStatus","createRequestHeaders","useRemoteThreadListRuntime","InMemoryThreadListAdapter","useAui","useAuiState","UserExternalState","convertAppendMessageToCommand","message","role","Error","parts","content","attachments","flatMap","a","contentPart","type","push","text","image","length","parentId","sourceId","symbolAssistantTransportExtras","Symbol","AssistantTransportExtras","sendCommand","command","state","asAssistantTransportExtras","extras","useAssistantTransportSendCommand","$","aui","t0","thread","getState","transportExtras","useAssistantTransportState","selector","T","t","s","useAssistantTransportThreadRuntime","options","agentStateRef","initialState","rerender","resumeFlagRef","isReplaying","setIsReplaying","waitForReplayRender","parentIdRef","undefined","commandQueue","onQueue","runManager","schedule","enqueueAppendMessage","console","warn","current","enqueue","startRun","threadId","threadListItem","remoteId","onRun","signal","AbortSignal","isResume","commands","flush","headers","bodyValue","body","context","runtime","getModelContext","requestBody","Record","system","tools","callSettings","config","prepareSendCommandsRequest","response","fetch","resumeApi","api","method","JSON","stringify","onResponse","ok","status","setReplaying","waitForRender","protocol","strict","decoder","err","stream","pipeThrough","initialMessage","unstable_state","throttle","onError","error","markedDelivered","chunk","metadata","markDelivered","prev","queued","onFinish","onCancel","cmds","inTransit","reset","updateState","updater","inTransitCmds","queuedCmds","toolStatuses","setToolStatuses","pendingCommands","converted","converter","isRunning","messages","isLoading","adapters","unstable_enableToolInvocations","onNew","Promise","capabilities","edit","onEdit","onReload","cancel","onResume","onAddToolResult","toolOptions","toolCallId","result","toolName","isError","artifact","modelContent","onLoadExternalState","useAssistantTransportRuntime","runtimeHook","RuntimeHook","adapter","allowNesting"],"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.ts"],"sourcesContent":["\"use client\";\n\nimport type { AppendMessage } from \"@assistant-ui/core\";\nimport {\n type ReadonlyJSONObject,\n type ReadonlyJSONValue,\n asAsyncIterableStream,\n} from \"assistant-stream/utils\";\nimport { useExternalStoreRuntime } from \"../external-store/useExternalStoreRuntime\";\nimport type { AssistantRuntime } from \"../../runtime/AssistantRuntime\";\nimport type { AddToolResultOptions } from \"@assistant-ui/core\";\nimport { useMemo, useRef, useState } from \"react\";\nimport {\n AssistantMessageAccumulator,\n DataStreamDecoder,\n AssistantTransportDecoder,\n unstable_createInitialMessage as createInitialMessage,\n toToolsJSONSchema,\n} from \"assistant-stream\";\nimport type {\n AssistantTransportOptions,\n AddMessageCommand,\n AddToolResultCommand,\n UserMessagePart,\n QueuedCommand,\n AssistantTransportCommand,\n SendCommandsRequestBody,\n} from \"./types\";\nimport { useCommandQueue } from \"./commandQueue\";\nimport {\n createReplayBoundaryStream,\n useReplayRenderWait,\n} from \"./replayBoundaryStream\";\nimport { useRunManager } from \"./runManager\";\nimport { useConvertedState } from \"./useConvertedState\";\nimport type { ToolExecutionStatus } from \"@assistant-ui/core\";\nimport { createRequestHeaders } from \"@assistant-ui/core\";\nimport { useRemoteThreadListRuntime } from \"../remote-thread-list/useRemoteThreadListRuntime\";\nimport { InMemoryThreadListAdapter } from \"@assistant-ui/core\";\nimport { useAui, useAuiState } from \"@assistant-ui/store\";\nimport type { UserExternalState } from \"../../../augmentations\";\n\nconst convertAppendMessageToCommand = (\n message: AppendMessage,\n): AddMessageCommand | null => {\n if (message.role !== \"user\")\n throw new Error(\"Only user messages are supported\");\n\n const parts: UserMessagePart[] = [];\n const content = [\n ...message.content,\n ...(message.attachments?.flatMap((a) => a.content) ?? []),\n ];\n for (const contentPart of content) {\n if (contentPart.type === \"text\") {\n parts.push({ type: \"text\", text: contentPart.text });\n } else if (contentPart.type === \"image\") {\n parts.push({ type: \"image\", image: contentPart.image });\n }\n }\n\n if (parts.length === 0) return null;\n\n return {\n type: \"add-message\",\n message: {\n role: \"user\",\n parts,\n },\n parentId: message.parentId,\n sourceId: message.sourceId,\n };\n};\n\nconst symbolAssistantTransportExtras = Symbol(\"assistant-transport-extras\");\ntype AssistantTransportExtras = {\n [symbolAssistantTransportExtras]: true;\n sendCommand: (command: AssistantTransportCommand) => void;\n state: UserExternalState;\n};\n\nconst asAssistantTransportExtras = (\n extras: unknown,\n): AssistantTransportExtras => {\n if (\n typeof extras !== \"object\" ||\n extras == null ||\n !(symbolAssistantTransportExtras in extras)\n )\n throw new Error(\n \"This method can only be called when you are using useAssistantTransportRuntime\",\n );\n\n return extras as AssistantTransportExtras;\n};\n\nexport const useAssistantTransportSendCommand = () => {\n const aui = useAui();\n\n return (command: AssistantTransportCommand) => {\n const extras = aui.thread.getState().extras;\n const transportExtras = asAssistantTransportExtras(extras);\n transportExtras.sendCommand(command);\n };\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(asAssistantTransportExtras(s.thread.extras).state),\n );\n}\n\nconst useAssistantTransportThreadRuntime = <T>(\n options: AssistantTransportOptions<T>,\n): AssistantRuntime => {\n const agentStateRef = useRef(options.initialState);\n const [, rerender] = useState(0);\n const resumeFlagRef = useRef(false);\n const [isReplaying, setIsReplaying] = useState(false);\n const waitForReplayRender = useReplayRenderWait();\n const parentIdRef = useRef<string | null | undefined>(undefined);\n const commandQueue = useCommandQueue({\n onQueue: () => runManager.schedule(),\n });\n\n const enqueueAppendMessage = (message: AppendMessage) => {\n const command = convertAppendMessageToCommand(message);\n if (!command) {\n console.warn(\n \"[assistant-ui] Skipped add-message command with no supported parts\",\n );\n return;\n }\n parentIdRef.current = message.parentId;\n commandQueue.enqueue(command, {\n schedule: message.startRun ?? message.role === \"user\",\n });\n };\n\n const threadId = useAuiState((s) => s.threadListItem.remoteId);\n\n const runManager = useRunManager({\n onRun: async (signal: AbortSignal) => {\n const isResume = resumeFlagRef.current;\n resumeFlagRef.current = false;\n setIsReplaying(false);\n const commands: QueuedCommand[] = isResume ? [] : commandQueue.flush();\n if (commands.length === 0 && !isResume) return;\n\n // The flushed batch consumes the parentId; read it alongside the flush\n // (before any awaits) so a mid-run append keeps its own value. Resume\n // runs send no commands, so they neither send nor consume it.\n const parentId = isResume ? undefined : parentIdRef.current;\n if (!isResume) parentIdRef.current = undefined;\n\n const headers = await createRequestHeaders(options.headers);\n const bodyValue =\n typeof options.body === \"function\"\n ? await options.body()\n : options.body;\n const context = runtime.thread.getModelContext();\n\n let requestBody: Record<string, unknown> = {\n commands,\n state: agentStateRef.current,\n system: context.system,\n tools: context.tools ? toToolsJSONSchema(context.tools) : undefined,\n threadId,\n ...(parentId !== undefined && {\n parentId,\n }),\n // nested (new format, aligned with AssistantChatTransport)\n callSettings: context.callSettings,\n config: context.config,\n // @deprecated spread at top level — use nested `callSettings`/`config` instead. Will be removed in a future version.\n ...context.callSettings,\n ...context.config,\n ...(bodyValue ?? {}),\n };\n\n if (options.prepareSendCommandsRequest) {\n requestBody = await options.prepareSendCommandsRequest(\n requestBody as SendCommandsRequestBody,\n );\n }\n\n const response = await fetch(\n isResume ? options.resumeApi! : options.api,\n {\n method: \"POST\",\n headers,\n body: JSON.stringify(requestBody),\n signal,\n },\n );\n\n options.onResponse?.(response);\n\n if (!response.ok) {\n throw new Error(`Status ${response.status}: ${await response.text()}`);\n }\n\n if (!response.body) {\n throw new Error(\"Response body is null\");\n }\n\n const body = await createReplayBoundaryStream(response, {\n setReplaying: setIsReplaying,\n waitForRender: waitForReplayRender,\n });\n\n // Select decoder based on protocol option\n const protocol = options.protocol ?? \"data-stream\";\n // Resume replays a best-effort buffer; always reconcile leniently.\n const strict = isResume ? false : (options.strict ?? true);\n const decoder =\n protocol === \"assistant-transport\"\n ? new AssistantTransportDecoder({ strict })\n : new DataStreamDecoder({ strict });\n\n let err: string | undefined;\n const stream = body.pipeThrough(decoder).pipeThrough(\n new AssistantMessageAccumulator({\n initialMessage: createInitialMessage({\n unstable_state:\n (agentStateRef.current as ReadonlyJSONValue) ?? null,\n }),\n throttle: isResume,\n strict,\n onError: (error) => {\n err = error;\n },\n }),\n );\n\n let markedDelivered = false;\n\n for await (const chunk of asAsyncIterableStream(stream)) {\n if (chunk.metadata.unstable_state === agentStateRef.current) continue;\n\n if (!markedDelivered) {\n commandQueue.markDelivered();\n markedDelivered = true;\n }\n\n agentStateRef.current = chunk.metadata.unstable_state as T;\n rerender((prev) => prev + 1);\n }\n\n if (err) {\n throw new Error(err);\n }\n\n // A successful run confirms delivery even when no state-changing\n // chunk was observed.\n if (!markedDelivered) {\n commandQueue.markDelivered();\n }\n\n // commands that coalesced into this resume run must not starve\n if (isResume && commandQueue.state.queued.length > 0) {\n runManager.schedule();\n }\n },\n onFinish: options.onFinish,\n onCancel: () => {\n setIsReplaying(false);\n const cmds = [\n ...commandQueue.state.inTransit,\n ...commandQueue.state.queued,\n ];\n\n commandQueue.reset();\n\n options.onCancel?.({\n commands: cmds,\n updateState: (updater) => {\n agentStateRef.current = updater(agentStateRef.current);\n rerender((prev) => prev + 1);\n },\n });\n },\n onError: async (error) => {\n setIsReplaying(false);\n const inTransitCmds = [...commandQueue.state.inTransit];\n const queuedCmds = [...commandQueue.state.queued];\n\n commandQueue.reset();\n\n try {\n await options.onError?.(error as Error, {\n commands: inTransitCmds,\n updateState: (updater) => {\n agentStateRef.current = updater(agentStateRef.current);\n rerender((prev) => prev + 1);\n },\n });\n } finally {\n options.onCancel?.({\n commands: queuedCmds,\n updateState: (updater) => {\n agentStateRef.current = updater(agentStateRef.current);\n rerender((prev) => prev + 1);\n },\n error: error as Error,\n });\n }\n },\n });\n\n // Tool execution status state\n const [toolStatuses, setToolStatuses] = useState<\n Record<string, ToolExecutionStatus>\n >({});\n\n // Reactive conversion of agent state + connection metadata → UI state\n const pendingCommands = useMemo(\n () => [...commandQueue.state.inTransit, ...commandQueue.state.queued],\n [commandQueue.state],\n );\n const converted = useConvertedState(\n options.converter,\n agentStateRef.current,\n pendingCommands,\n runManager.isRunning,\n toolStatuses,\n );\n\n // Create runtime\n const runtime = useExternalStoreRuntime({\n messages: converted.messages,\n state: converted.state,\n isRunning: converted.isRunning,\n isLoading: isReplaying,\n adapters: options.adapters,\n unstable_enableToolInvocations: true,\n setToolStatuses,\n extras: {\n [symbolAssistantTransportExtras]: true,\n sendCommand: (command: AssistantTransportCommand) => {\n commandQueue.enqueue(command);\n },\n state: agentStateRef.current as UserExternalState,\n } satisfies AssistantTransportExtras,\n onNew: async (message: AppendMessage): Promise<void> =>\n enqueueAppendMessage(message),\n ...(options.capabilities?.edit && {\n onEdit: async (message: AppendMessage): Promise<void> =>\n enqueueAppendMessage(message),\n }),\n ...(commandQueue.state.queued.length > 0 && {\n onReload: async (parentId: string | null) => {\n parentIdRef.current = parentId;\n runManager.schedule();\n },\n }),\n onCancel: async () => {\n runManager.cancel();\n },\n onResume: async () => {\n if (!options.resumeApi)\n throw new Error(\"Must pass resumeApi to options to resume runs\");\n\n resumeFlagRef.current = true;\n runManager.schedule();\n },\n onAddToolResult: async (\n toolOptions: AddToolResultOptions,\n ): Promise<void> => {\n const command: AddToolResultCommand = {\n type: \"add-tool-result\",\n toolCallId: toolOptions.toolCallId,\n result: toolOptions.result as ReadonlyJSONObject,\n toolName: toolOptions.toolName,\n isError: toolOptions.isError,\n ...(toolOptions.artifact && { artifact: toolOptions.artifact }),\n ...(toolOptions.modelContent !== undefined && {\n modelContent: toolOptions.modelContent,\n }),\n };\n\n commandQueue.enqueue(command);\n },\n onLoadExternalState: async (state) => {\n agentStateRef.current = state as T;\n rerender((prev) => prev + 1);\n },\n });\n\n return runtime;\n};\n\n/**\n * @alpha This is an experimental API that is subject to change.\n */\nexport const useAssistantTransportRuntime = <T>(\n options: AssistantTransportOptions<T>,\n): AssistantRuntime => {\n const runtime = useRemoteThreadListRuntime({\n runtimeHook: function RuntimeHook() {\n return useAssistantTransportThreadRuntime(options);\n },\n adapter: new InMemoryThreadListAdapter(),\n allowNesting: true,\n });\n return runtime;\n};\n"],"mappings":";;;;;;;;;;;;;;AA0CA,MAAMqC,iCACJC,YAC6B;CAC7B,IAAIA,QAAQC,SAAS,QACnB,MAAM,IAAIC,MAAM,kCAAkC;CAEpD,MAAMC,QAA2B,CAAA;CACjC,MAAMC,UAAU,CACd,GAAGJ,QAAQI,SACX,GAAIJ,QAAQK,aAAaC,SAASC,MAAMA,EAAEH,OAAO,KAAK,CAAA,CAAG;CAE3D,KAAK,MAAMI,eAAeJ,SACxB,IAAII,YAAYC,SAAS,QACvBN,MAAMO,KAAK;EAAED,MAAM;EAAQE,MAAMH,YAAYG;CAAK,CAAC;MAC9C,IAAIH,YAAYC,SAAS,SAC9BN,MAAMO,KAAK;EAAED,MAAM;EAASG,OAAOJ,YAAYI;CAAM,CAAC;CAI1D,IAAIT,MAAMU,WAAW,GAAG,OAAO;CAE/B,OAAO;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C,cAAc;GAClC,OAAO9G,mCAAmCC,OAAO;EACnD;EACA8G,SAAS,IAAIxJ,0BAA0B;EACvCyJ,cAAc;CAChB,CACO9E;AACT"}
|
|
1
|
+
{"version":3,"file":"useAssistantTransportRuntime.js","names":["c","_c","AppendMessage","ReadonlyJSONObject","ReadonlyJSONValue","asAsyncIterableStream","useExternalStoreRuntime","AssistantRuntime","AddToolResultOptions","useMemo","useRef","useState","AssistantMessageAccumulator","DataStreamDecoder","AssistantTransportDecoder","unstable_createInitialMessage","createInitialMessage","toToolsJSONSchema","AssistantTransportOptions","AddMessageCommand","AddToolResultCommand","UserMessagePart","QueuedCommand","AssistantTransportCommand","SendCommandsRequestBody","useCommandQueue","createReplayBoundaryStream","useReplayRenderWait","useRunManager","useConvertedState","ToolExecutionStatus","createRequestHeaders","useRemoteThreadListRuntime","InMemoryThreadListAdapter","useAui","useAuiState","UserExternalState","convertAppendMessageToCommand","message","role","Error","parts","content","attachments","flatMap","a","contentPart","type","push","text","image","length","parentId","sourceId","readResumeState","response","Response","Promise","runId","state","T","status","ok","value","json","symbolAssistantTransportExtras","Symbol","AssistantTransportExtras","sendCommand","command","asAssistantTransportExtras","extras","useAssistantTransportSendCommand","$","aui","t0","thread","getState","transportExtras","useAssistantTransportState","selector","t","s","useAssistantTransportThreadRuntime","options","agentStateRef","initialState","rerender","resumeFlagRef","isReplaying","setIsReplaying","waitForReplayRender","parentIdRef","undefined","commandQueue","onQueue","runManager","schedule","enqueueAppendMessage","console","warn","current","enqueue","startRun","threadId","threadListItem","remoteId","onRun","signal","AbortSignal","isResume","commands","flush","headers","resumeState","resumeStateApi","resumeStateResponse","fetch","method","body","JSON","stringify","retained","queued","bodyValue","context","runtime","getModelContext","requestBody","Record","system","tools","callSettings","config","prepareSendCommandsRequest","resumeApi","api","onResponse","prev","setReplaying","waitForRender","protocol","strict","decoder","err","stream","pipeThrough","initialMessage","unstable_state","throttle","onError","error","markedDelivered","chunk","metadata","markDelivered","onFinish","onCancel","cmds","inTransit","reset","updateState","updater","inTransitCmds","queuedCmds","toolStatuses","setToolStatuses","pendingCommands","converted","converter","isRunning","messages","isLoading","adapters","unstable_enableToolInvocations","onNew","capabilities","edit","onEdit","onReload","cancel","onResume","onAddToolResult","toolOptions","toolCallId","result","toolName","isError","artifact","modelContent","onLoadExternalState","useAssistantTransportRuntime","runtimeHook","RuntimeHook","adapter","allowNesting"],"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.ts"],"sourcesContent":["\"use client\";\n\nimport type { AppendMessage } from \"@assistant-ui/core\";\nimport {\n type ReadonlyJSONObject,\n type ReadonlyJSONValue,\n asAsyncIterableStream,\n} from \"assistant-stream/utils\";\nimport { useExternalStoreRuntime } from \"../external-store/useExternalStoreRuntime\";\nimport type { AssistantRuntime } from \"../../runtime/AssistantRuntime\";\nimport type { AddToolResultOptions } from \"@assistant-ui/core\";\nimport { useMemo, useRef, useState } from \"react\";\nimport {\n AssistantMessageAccumulator,\n DataStreamDecoder,\n AssistantTransportDecoder,\n unstable_createInitialMessage as createInitialMessage,\n toToolsJSONSchema,\n} from \"assistant-stream\";\nimport type {\n AssistantTransportOptions,\n AddMessageCommand,\n AddToolResultCommand,\n UserMessagePart,\n QueuedCommand,\n AssistantTransportCommand,\n SendCommandsRequestBody,\n} from \"./types\";\nimport { useCommandQueue } from \"./commandQueue\";\nimport {\n createReplayBoundaryStream,\n useReplayRenderWait,\n} from \"./replayBoundaryStream\";\nimport { useRunManager } from \"./runManager\";\nimport { useConvertedState } from \"./useConvertedState\";\nimport type { ToolExecutionStatus } from \"@assistant-ui/core\";\nimport { createRequestHeaders } from \"@assistant-ui/core\";\nimport { useRemoteThreadListRuntime } from \"../remote-thread-list/useRemoteThreadListRuntime\";\nimport { InMemoryThreadListAdapter } from \"@assistant-ui/core\";\nimport { useAui, useAuiState } from \"@assistant-ui/store\";\nimport type { UserExternalState } from \"../../../augmentations\";\n\nconst convertAppendMessageToCommand = (\n message: AppendMessage,\n): AddMessageCommand | null => {\n if (message.role !== \"user\")\n throw new Error(\"Only user messages are supported\");\n\n const parts: UserMessagePart[] = [];\n const content = [\n ...message.content,\n ...(message.attachments?.flatMap((a) => a.content) ?? []),\n ];\n for (const contentPart of content) {\n if (contentPart.type === \"text\") {\n parts.push({ type: \"text\", text: contentPart.text });\n } else if (contentPart.type === \"image\") {\n parts.push({ type: \"image\", image: contentPart.image });\n }\n }\n\n if (parts.length === 0) return null;\n\n return {\n type: \"add-message\",\n message: {\n role: \"user\",\n parts,\n },\n parentId: message.parentId,\n sourceId: message.sourceId,\n };\n};\n\nconst readResumeState = async <T>(\n response: Response,\n): Promise<{ runId: string; state: T } | null> => {\n if (response.status === 204) return null;\n if (!response.ok) {\n throw new Error(\n `Resume state request failed with status ${response.status}: ${await response.text()}`,\n );\n }\n\n let value: unknown;\n try {\n value = await response.json();\n } catch {\n throw new Error(\"Resume state response was not valid JSON\");\n }\n\n if (\n typeof value !== \"object\" ||\n value === null ||\n !(\"state\" in value) ||\n !(\"runId\" in value) ||\n typeof value.runId !== \"string\"\n ) {\n throw new Error(\"Resume state response must contain state and runId\");\n }\n\n return { runId: value.runId, state: value.state as T };\n};\n\nconst symbolAssistantTransportExtras = Symbol(\"assistant-transport-extras\");\ntype AssistantTransportExtras = {\n [symbolAssistantTransportExtras]: true;\n sendCommand: (command: AssistantTransportCommand) => void;\n state: UserExternalState;\n};\n\nconst asAssistantTransportExtras = (\n extras: unknown,\n): AssistantTransportExtras => {\n if (\n typeof extras !== \"object\" ||\n extras == null ||\n !(symbolAssistantTransportExtras in extras)\n )\n throw new Error(\n \"This method can only be called when you are using useAssistantTransportRuntime\",\n );\n\n return extras as AssistantTransportExtras;\n};\n\nexport const useAssistantTransportSendCommand = () => {\n const aui = useAui();\n\n return (command: AssistantTransportCommand) => {\n const extras = aui.thread.getState().extras;\n const transportExtras = asAssistantTransportExtras(extras);\n transportExtras.sendCommand(command);\n };\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(asAssistantTransportExtras(s.thread.extras).state),\n );\n}\n\nconst useAssistantTransportThreadRuntime = <T>(\n options: AssistantTransportOptions<T>,\n): AssistantRuntime => {\n const agentStateRef = useRef(options.initialState);\n const [, rerender] = useState(0);\n const resumeFlagRef = useRef(false);\n const [isReplaying, setIsReplaying] = useState(false);\n const waitForReplayRender = useReplayRenderWait();\n const parentIdRef = useRef<string | null | undefined>(undefined);\n const commandQueue = useCommandQueue({\n onQueue: () => runManager.schedule(),\n });\n\n const enqueueAppendMessage = (message: AppendMessage) => {\n const command = convertAppendMessageToCommand(message);\n if (!command) {\n console.warn(\n \"[assistant-ui] Skipped add-message command with no supported parts\",\n );\n return;\n }\n parentIdRef.current = message.parentId;\n commandQueue.enqueue(command, {\n schedule: message.startRun ?? message.role === \"user\",\n });\n };\n\n const threadId = useAuiState((s) => s.threadListItem.remoteId);\n\n const runManager = useRunManager({\n onRun: async (signal: AbortSignal) => {\n const isResume = resumeFlagRef.current;\n resumeFlagRef.current = false;\n setIsReplaying(false);\n const commands: QueuedCommand[] = isResume ? [] : commandQueue.flush();\n if (commands.length === 0 && !isResume) return;\n\n // The flushed batch consumes the parentId; read it alongside the flush\n // (before any awaits) so a mid-run append keeps its own value. Resume\n // runs send no commands, so they neither send nor consume it.\n const parentId = isResume ? undefined : parentIdRef.current;\n if (!isResume) parentIdRef.current = undefined;\n\n const headers = await createRequestHeaders(options.headers);\n let resumeState: { runId: string; state: T } | undefined;\n if (isResume && options.resumeStateApi) {\n const resumeStateResponse = await fetch(options.resumeStateApi, {\n method: \"POST\",\n headers,\n body: JSON.stringify({ threadId }),\n signal,\n });\n const retained = await readResumeState<T>(resumeStateResponse);\n if (retained === null) {\n if (commandQueue.state.queued.length > 0) {\n runManager.schedule();\n }\n return;\n }\n resumeState = retained;\n }\n\n const bodyValue =\n typeof options.body === \"function\"\n ? await options.body()\n : options.body;\n const context = runtime.thread.getModelContext();\n\n let requestBody: Record<string, unknown> = {\n commands,\n ...(resumeState === undefined && { state: agentStateRef.current }),\n system: context.system,\n tools: context.tools ? toToolsJSONSchema(context.tools) : undefined,\n threadId,\n ...(parentId !== undefined && {\n parentId,\n }),\n // nested (new format, aligned with AssistantChatTransport)\n callSettings: context.callSettings,\n config: context.config,\n // @deprecated spread at top level — use nested `callSettings`/`config` instead. Will be removed in a future version.\n ...context.callSettings,\n ...context.config,\n ...(bodyValue ?? {}),\n };\n\n if (options.prepareSendCommandsRequest) {\n requestBody = await options.prepareSendCommandsRequest(\n requestBody as SendCommandsRequestBody,\n );\n }\n\n if (resumeState !== undefined) {\n // The server replays a resume from the snapshot it retained for this\n // runId. Body overrides and prepare hooks can neither substitute a\n // state nor drop the ID the server validates against.\n requestBody = { ...requestBody, runId: resumeState.runId };\n delete requestBody[\"state\"];\n }\n\n const response = await fetch(\n isResume ? options.resumeApi! : options.api,\n {\n method: \"POST\",\n headers,\n body: JSON.stringify(requestBody),\n signal,\n },\n );\n\n options.onResponse?.(response);\n\n if (!response.ok) {\n throw new Error(`Status ${response.status}: ${await response.text()}`);\n }\n\n if (!response.body) {\n throw new Error(\"Response body is null\");\n }\n\n if (resumeState !== undefined) {\n agentStateRef.current = resumeState.state;\n rerender((prev) => prev + 1);\n }\n\n const body = await createReplayBoundaryStream(response, {\n setReplaying: setIsReplaying,\n waitForRender: waitForReplayRender,\n });\n\n // Select decoder based on protocol option\n const protocol = options.protocol ?? \"data-stream\";\n // Resume replays a best-effort buffer; always reconcile leniently.\n const strict = isResume ? false : (options.strict ?? true);\n const decoder =\n protocol === \"assistant-transport\"\n ? new AssistantTransportDecoder({ strict })\n : new DataStreamDecoder({ strict });\n\n let err: string | undefined;\n const stream = body.pipeThrough(decoder).pipeThrough(\n new AssistantMessageAccumulator({\n initialMessage: createInitialMessage({\n unstable_state:\n (agentStateRef.current as ReadonlyJSONValue) ?? null,\n }),\n throttle: isResume,\n strict,\n onError: (error) => {\n err = error;\n },\n }),\n );\n\n let markedDelivered = false;\n\n for await (const chunk of asAsyncIterableStream(stream)) {\n if (chunk.metadata.unstable_state === agentStateRef.current) continue;\n\n if (!markedDelivered) {\n commandQueue.markDelivered();\n markedDelivered = true;\n }\n\n agentStateRef.current = chunk.metadata.unstable_state as T;\n rerender((prev) => prev + 1);\n }\n\n if (err) {\n throw new Error(err);\n }\n\n // A successful run confirms delivery even when no state-changing\n // chunk was observed.\n if (!markedDelivered) {\n commandQueue.markDelivered();\n }\n\n // commands that coalesced into this resume run must not starve\n if (isResume && commandQueue.state.queued.length > 0) {\n runManager.schedule();\n }\n },\n onFinish: options.onFinish,\n onCancel: () => {\n setIsReplaying(false);\n const cmds = [\n ...commandQueue.state.inTransit,\n ...commandQueue.state.queued,\n ];\n\n commandQueue.reset();\n\n options.onCancel?.({\n commands: cmds,\n updateState: (updater) => {\n agentStateRef.current = updater(agentStateRef.current);\n rerender((prev) => prev + 1);\n },\n });\n },\n onError: async (error) => {\n setIsReplaying(false);\n const inTransitCmds = [...commandQueue.state.inTransit];\n const queuedCmds = [...commandQueue.state.queued];\n\n commandQueue.reset();\n\n try {\n await options.onError?.(error as Error, {\n commands: inTransitCmds,\n updateState: (updater) => {\n agentStateRef.current = updater(agentStateRef.current);\n rerender((prev) => prev + 1);\n },\n });\n } finally {\n options.onCancel?.({\n commands: queuedCmds,\n updateState: (updater) => {\n agentStateRef.current = updater(agentStateRef.current);\n rerender((prev) => prev + 1);\n },\n error: error as Error,\n });\n }\n },\n });\n\n // Tool execution status state\n const [toolStatuses, setToolStatuses] = useState<\n Record<string, ToolExecutionStatus>\n >({});\n\n // Reactive conversion of agent state + connection metadata → UI state\n const pendingCommands = useMemo(\n () => [...commandQueue.state.inTransit, ...commandQueue.state.queued],\n [commandQueue.state],\n );\n const converted = useConvertedState(\n options.converter,\n agentStateRef.current,\n pendingCommands,\n runManager.isRunning,\n toolStatuses,\n );\n\n // Create runtime\n const runtime = useExternalStoreRuntime({\n messages: converted.messages,\n state: converted.state,\n isRunning: converted.isRunning,\n isLoading: isReplaying,\n adapters: options.adapters,\n unstable_enableToolInvocations: true,\n setToolStatuses,\n extras: {\n [symbolAssistantTransportExtras]: true,\n sendCommand: (command: AssistantTransportCommand) => {\n commandQueue.enqueue(command);\n },\n state: agentStateRef.current as UserExternalState,\n } satisfies AssistantTransportExtras,\n onNew: async (message: AppendMessage): Promise<void> =>\n enqueueAppendMessage(message),\n ...(options.capabilities?.edit && {\n onEdit: async (message: AppendMessage): Promise<void> =>\n enqueueAppendMessage(message),\n }),\n ...(commandQueue.state.queued.length > 0 && {\n onReload: async (parentId: string | null) => {\n parentIdRef.current = parentId;\n runManager.schedule();\n },\n }),\n onCancel: async () => {\n runManager.cancel();\n },\n onResume: async () => {\n if (!options.resumeApi)\n throw new Error(\"Must pass resumeApi to options to resume runs\");\n\n resumeFlagRef.current = true;\n runManager.schedule();\n },\n onAddToolResult: async (\n toolOptions: AddToolResultOptions,\n ): Promise<void> => {\n const command: AddToolResultCommand = {\n type: \"add-tool-result\",\n toolCallId: toolOptions.toolCallId,\n result: toolOptions.result as ReadonlyJSONObject,\n toolName: toolOptions.toolName,\n isError: toolOptions.isError,\n ...(toolOptions.artifact && { artifact: toolOptions.artifact }),\n ...(toolOptions.modelContent !== undefined && {\n modelContent: toolOptions.modelContent,\n }),\n };\n\n commandQueue.enqueue(command);\n },\n onLoadExternalState: async (state) => {\n agentStateRef.current = state as T;\n rerender((prev) => prev + 1);\n },\n });\n\n return runtime;\n};\n\n/**\n * @alpha This is an experimental API that is subject to change.\n */\nexport const useAssistantTransportRuntime = <T>(\n options: AssistantTransportOptions<T>,\n): AssistantRuntime => {\n const runtime = useRemoteThreadListRuntime({\n runtimeHook: function RuntimeHook() {\n return useAssistantTransportThreadRuntime(options);\n },\n adapter: new InMemoryThreadListAdapter(),\n allowNesting: true,\n });\n return runtime;\n};\n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AYG;IACtBC,SAASJ,YAAYI;IACrB,GAAIJ,YAAYK,YAAY,EAAEA,UAAUL,YAAYK,SAAS;IAC7D,GAAIL,YAAYM,iBAAiBhG,KAAAA,KAAa,EAC5CgG,cAAcN,YAAYM,aAC5B;GACF;GAEA/F,aAAaQ,QAAQjC,SAAO;EAC9B;EACAyH,qBAAqB,OAAOnI,UAAU;GACpC0B,cAAcgB,UAAU1C;GACxB4B,UAAUmD,WAASA,SAAO,CAAC;EAC7B;CACF,CAAC;CAED,OAAOZ;AACT;;;;AAKA,MAAaiE,gCACX3G,YACqB;CAQrB,OAPgBpD,2BAA2B;EACzCgK,aAAa,SAASC,cAAc;GAClC,OAAO9G,mCAAmCC,OAAO;EACnD;EACA8G,SAAS,IAAIjK,0BAA0B;EACvCkK,cAAc;CAChB,CACOrE;AACT"}
|
|
@@ -32,7 +32,7 @@ const useActionBarExportMarkdown = (t0) => {
|
|
|
32
32
|
a.href = url;
|
|
33
33
|
a.download = filename ?? `message-${Date.now()}.md`;
|
|
34
34
|
a.click();
|
|
35
|
-
URL.revokeObjectURL(url);
|
|
35
|
+
setTimeout(() => URL.revokeObjectURL(url), 4e4);
|
|
36
36
|
};
|
|
37
37
|
$[2] = aui.message;
|
|
38
38
|
$[3] = filename;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionBarExportMarkdown.js","names":["c","_c","forwardRef","useCallback","ActionButtonProps","composeEventHandlers","Primitive","useAuiState","useAui","useActionBarExportMarkdown","t0","$","t1","undefined","filename","onExport","aui","hasExportableContent","_temp2","t2","message","content","getCopyText","blob","Blob","type","url","URL","createObjectURL","a","document","createElement","href","download","Date","now","click","revokeObjectURL","callback","ActionBarPrimitiveExportMarkdown","Element","HTMLButtonElement","Props","forwardedRef","disabled","onClick","props","t3","t4","t5","displayName","_temp","text","length","s","role","status","parts","some"],"sources":["../../../src/primitives/actionBar/ActionBarExportMarkdown.tsx"],"sourcesContent":["\"use client\";\n\nimport { forwardRef, useCallback } from \"react\";\nimport type { ActionButtonProps } from \"../../utils/createActionButton\";\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { Primitive } from \"../../utils/Primitive\";\nimport { useAuiState, useAui } from \"@assistant-ui/store\";\n\nconst useActionBarExportMarkdown = ({\n filename,\n onExport,\n}: {\n filename?: string | undefined;\n onExport?: ((content: string) => void | Promise<void>) | undefined;\n} = {}) => {\n const aui = useAui();\n const hasExportableContent = useAuiState((s) => {\n return (\n (s.message.role !== \"assistant\" ||\n s.message.status?.type !== \"running\") &&\n s.message.parts.some((c) => c.type === \"text\" && c.text.length > 0)\n );\n });\n\n const callback = useCallback(async () => {\n const content = aui.message.getCopyText();\n if (!content) return;\n\n if (onExport) {\n await onExport(content);\n return;\n }\n\n const blob = new Blob([content], { type: \"text/markdown\" });\n const url = URL.createObjectURL(blob);\n const a = document.createElement(\"a\");\n a.href = url;\n a.download = filename ?? `message-${Date.now()}.md`;\n a.click();\n URL.revokeObjectURL(url);\n }, [aui, filename, onExport]);\n\n if (!hasExportableContent) return null;\n return callback;\n};\n\nexport namespace ActionBarPrimitiveExportMarkdown {\n export type Element = HTMLButtonElement;\n export type Props = ActionButtonProps<typeof useActionBarExportMarkdown>;\n}\n\nexport const ActionBarPrimitiveExportMarkdown = forwardRef<\n ActionBarPrimitiveExportMarkdown.Element,\n ActionBarPrimitiveExportMarkdown.Props\n>(({ filename, onExport, onClick, disabled, ...props }, forwardedRef) => {\n const callback = useActionBarExportMarkdown({ filename, onExport });\n return (\n <Primitive.button\n type=\"button\"\n {...props}\n ref={forwardedRef}\n disabled={disabled || !callback}\n onClick={composeEventHandlers(onClick, () => {\n callback?.();\n })}\n />\n );\n});\n\nActionBarPrimitiveExportMarkdown.displayName =\n \"ActionBarPrimitive.ExportMarkdown\";\n"],"mappings":";;;;;;;;AAQA,MAAMS,8BAA6BC,OAAA;CAAA,MAAAC,IAAAV,EAAA,CAAA;CAAA,IAAAW;CAAA,IAAAD,EAAA,OAAAD,IAAA;EAACE,KAAAF,OAAAG,KAAAA,IAAA,CAM/B,IAN+BH;EAM9BC,EAAA,KAAAD;EAAAC,EAAA,KAAAC;CAAA,OAAAA,KAAAD,EAAA;CAN8B,MAAA,EAAAG,UAAAC,aAAAH;CAOlC,MAAAI,MAAYR,OAAO;CACnB,MAAAS,uBAA6BV,YAAYW,MAMxC;CAAE,IAAAC;CAAA,IAAAR,EAAA,OAAAK,IAAAI,WAAAT,EAAA,OAAAG,YAAAH,EAAA,OAAAI,UAAA;EAE0BI,KAAA,YAAA;GAC3B,MAAAE,UAAgBL,IAAGI,QAAQE,YAAa;GACxC,IAAI,CAACD,SAAO;GAEZ,IAAIN,UAAQ;IACV,MAAMA,SAASM,OAAO;IAAC;GAAA;GAIzB,MAAAE,OAAa,IAAIC,KAAK,CAACH,OAAO,GAAG,EAAAI,MAAQ,gBAAgB,CAAC;GAC1D,MAAAC,MAAYC,IAAGC,gBAAiBL,IAAI;GACpC,MAAAM,IAAUC,SAAQC,cAAe,GAAG;GACpCF,EAACG,OAAQN;GACTG,EAACI,WAAYnB,YAAA,WAAuBoB,KAAIC,IAAK,EAAC;GAC9CN,EAACO,MAAO;
|
|
1
|
+
{"version":3,"file":"ActionBarExportMarkdown.js","names":["c","_c","forwardRef","useCallback","ActionButtonProps","composeEventHandlers","Primitive","useAuiState","useAui","useActionBarExportMarkdown","t0","$","t1","undefined","filename","onExport","aui","hasExportableContent","_temp2","t2","message","content","getCopyText","blob","Blob","type","url","URL","createObjectURL","a","document","createElement","href","download","Date","now","click","setTimeout","revokeObjectURL","callback","ActionBarPrimitiveExportMarkdown","Element","HTMLButtonElement","Props","forwardedRef","disabled","onClick","props","t3","t4","t5","displayName","_temp","text","length","s","role","status","parts","some"],"sources":["../../../src/primitives/actionBar/ActionBarExportMarkdown.tsx"],"sourcesContent":["\"use client\";\n\nimport { forwardRef, useCallback } from \"react\";\nimport type { ActionButtonProps } from \"../../utils/createActionButton\";\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { Primitive } from \"../../utils/Primitive\";\nimport { useAuiState, useAui } from \"@assistant-ui/store\";\n\nconst useActionBarExportMarkdown = ({\n filename,\n onExport,\n}: {\n filename?: string | undefined;\n onExport?: ((content: string) => void | Promise<void>) | undefined;\n} = {}) => {\n const aui = useAui();\n const hasExportableContent = useAuiState((s) => {\n return (\n (s.message.role !== \"assistant\" ||\n s.message.status?.type !== \"running\") &&\n s.message.parts.some((c) => c.type === \"text\" && c.text.length > 0)\n );\n });\n\n const callback = useCallback(async () => {\n const content = aui.message.getCopyText();\n if (!content) return;\n\n if (onExport) {\n await onExport(content);\n return;\n }\n\n const blob = new Blob([content], { type: \"text/markdown\" });\n const url = URL.createObjectURL(blob);\n const a = document.createElement(\"a\");\n a.href = url;\n a.download = filename ?? `message-${Date.now()}.md`;\n a.click();\n setTimeout(() => URL.revokeObjectURL(url), 40_000);\n }, [aui, filename, onExport]);\n\n if (!hasExportableContent) return null;\n return callback;\n};\n\nexport namespace ActionBarPrimitiveExportMarkdown {\n export type Element = HTMLButtonElement;\n export type Props = ActionButtonProps<typeof useActionBarExportMarkdown>;\n}\n\nexport const ActionBarPrimitiveExportMarkdown = forwardRef<\n ActionBarPrimitiveExportMarkdown.Element,\n ActionBarPrimitiveExportMarkdown.Props\n>(({ filename, onExport, onClick, disabled, ...props }, forwardedRef) => {\n const callback = useActionBarExportMarkdown({ filename, onExport });\n return (\n <Primitive.button\n type=\"button\"\n {...props}\n ref={forwardedRef}\n disabled={disabled || !callback}\n onClick={composeEventHandlers(onClick, () => {\n callback?.();\n })}\n />\n );\n});\n\nActionBarPrimitiveExportMarkdown.displayName =\n \"ActionBarPrimitive.ExportMarkdown\";\n"],"mappings":";;;;;;;;AAQA,MAAMS,8BAA6BC,OAAA;CAAA,MAAAC,IAAAV,EAAA,CAAA;CAAA,IAAAW;CAAA,IAAAD,EAAA,OAAAD,IAAA;EAACE,KAAAF,OAAAG,KAAAA,IAAA,CAM/B,IAN+BH;EAM9BC,EAAA,KAAAD;E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GAAA;CAAA,OAYDA,EAACyB,SAAU,UAAUzB,EAACqD,KAAKC,SAAU;AAAC;AAZrC,SAAApC,OAAAqC,GAAA;CAAA,QAU5BA,EAACnC,QAAQoC,SAAU,eAClBD,EAACnC,QAAQqC,QAAahC,SAAK,cAC7B8B,EAACnC,QAAQsC,MAAMC,KAAMP,KAA6C;AAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttachmentThumb.d.ts","names":[],"sources":["../../../src/primitives/attachment/AttachmentThumb.tsx"],"mappings":";;;KAUK,oBAAoB,gCAAgC,UAAU;kBAElD;OACH,UAAU,oBAAoB,UAAU;OACxC,QAAQ;;cAGT,0CAAwB,0BAAA,KAAA,qBAAA,gBAAA,kCAAA,eAAA;;;;
|
|
1
|
+
{"version":3,"file":"AttachmentThumb.d.ts","names":[],"sources":["../../../src/primitives/attachment/AttachmentThumb.tsx"],"mappings":";;;KAUK,oBAAoB,gCAAgC,UAAU;kBAElD;OACH,UAAU,oBAAoB,UAAU;OACxC,QAAQ;;cAGT,0CAAwB,0BAAA,KAAA,qBAAA,gBAAA,kCAAA,eAAA;;;;oBAiBnC,cAAA,0CAAA,cAAA"}
|
|
@@ -3,29 +3,32 @@ import { Primitive } from "../../utils/Primitive.js";
|
|
|
3
3
|
import { useAuiState } from "@assistant-ui/store";
|
|
4
4
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
5
5
|
import { forwardRef } from "@assistant-ui/tap/react-shim";
|
|
6
|
-
import {
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
//#region src/primitives/attachment/AttachmentThumb.tsx
|
|
8
8
|
const AttachmentPrimitiveThumb = forwardRef((props, ref) => {
|
|
9
9
|
const $ = c(4);
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const label = useAuiState(_temp);
|
|
11
|
+
const t0 = props.children ?? label;
|
|
12
|
+
let t1;
|
|
13
|
+
if ($[0] !== props || $[1] !== ref || $[2] !== t0) {
|
|
14
|
+
t1 = /* @__PURE__ */ jsx(Primitive.div, {
|
|
14
15
|
...props,
|
|
15
16
|
ref,
|
|
16
|
-
children:
|
|
17
|
+
children: t0
|
|
17
18
|
});
|
|
18
|
-
$[0] =
|
|
19
|
-
$[1] =
|
|
20
|
-
$[2] =
|
|
21
|
-
$[3] =
|
|
22
|
-
} else
|
|
23
|
-
return
|
|
19
|
+
$[0] = props;
|
|
20
|
+
$[1] = ref;
|
|
21
|
+
$[2] = t0;
|
|
22
|
+
$[3] = t1;
|
|
23
|
+
} else t1 = $[3];
|
|
24
|
+
return t1;
|
|
24
25
|
});
|
|
25
26
|
AttachmentPrimitiveThumb.displayName = "AttachmentPrimitive.unstable_Thumb";
|
|
26
27
|
function _temp(s) {
|
|
27
|
-
const
|
|
28
|
-
|
|
28
|
+
const name = s.attachment.name;
|
|
29
|
+
const dot = name.lastIndexOf(".");
|
|
30
|
+
if (dot > 0 && dot < name.length - 1) return `.${name.slice(dot + 1)}`;
|
|
31
|
+
return s.attachment.type;
|
|
29
32
|
}
|
|
30
33
|
//#endregion
|
|
31
34
|
export { AttachmentPrimitiveThumb };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttachmentThumb.js","names":["c","_c","ComponentPropsWithoutRef","forwardRef","ComponentRef","useAuiState","Primitive","PrimitiveDivProps","div","AttachmentPrimitiveThumb","Element","Props","props","ref","$","
|
|
1
|
+
{"version":3,"file":"AttachmentThumb.js","names":["c","_c","ComponentPropsWithoutRef","forwardRef","ComponentRef","useAuiState","Primitive","PrimitiveDivProps","div","AttachmentPrimitiveThumb","Element","Props","props","ref","$","label","_temp","t0","children","t1","displayName","s","name","attachment","dot","lastIndexOf","length","slice","type"],"sources":["../../../src/primitives/attachment/AttachmentThumb.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ComponentPropsWithoutRef,\n forwardRef,\n type ComponentRef,\n} from \"react\";\nimport { useAuiState } from \"@assistant-ui/store\";\nimport { Primitive } from \"../../utils/Primitive\";\n\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\nexport namespace AttachmentPrimitiveThumb {\n export type Element = ComponentRef<typeof Primitive.div>;\n export type Props = PrimitiveDivProps;\n}\n\nexport const AttachmentPrimitiveThumb = forwardRef<\n AttachmentPrimitiveThumb.Element,\n AttachmentPrimitiveThumb.Props\n>((props, ref) => {\n const label = useAuiState((s) => {\n const name = s.attachment.name;\n const dot = name.lastIndexOf(\".\");\n if (dot > 0 && dot < name.length - 1) {\n return `.${name.slice(dot + 1)}`;\n }\n return s.attachment.type;\n });\n return (\n <Primitive.div {...props} ref={ref}>\n {props.children ?? label}\n </Primitive.div>\n );\n});\n\nAttachmentPrimitiveThumb.displayName = \"AttachmentPrimitive.unstable_Thumb\";\n"],"mappings":";;;;;;;AAiBA,MAAaS,2BAA2BN,YAGtCS,OAAAC,QAAA;CAAA,MAAAC,IAAAb,EAAA,CAAA;CACA,MAAAc,QAAcV,YAAYW,KAOzB;CAGI,MAAAC,KAAAL,MAAKM,YAALH;CAAuB,IAAAI;CAAA,IAAAL,EAAA,OAAAF,SAAAE,EAAA,OAAAD,OAAAC,EAAA,OAAAG,IAAA;EAD1BE,KAAA,oBAAA,UAAA,KAAA;GAAA,GAAmBP;GAAYC;GAC5BI,UAAAA;EACH,CAAA;EAAgBH,EAAA,KAAAF;EAAAE,EAAA,KAAAD;EAAAC,EAAA,KAAAG;EAAAH,EAAA,KAAAK;CAAA,OAAAA,KAAAL,EAAA;CAAA,OAFhBK;AAEgB,CAEnB;AAEDV,yBAAyBW,cAAc;AAhBrC,SAAAJ,MAAAK,GAAA;CAEE,MAAAC,OAAaD,EAACE,WAAWD;CACzB,MAAAE,MAAYF,KAAIG,YAAa,GAAG;CAChC,IAAID,MAAM,KAAKA,MAAMF,KAAII,SAAU,GAAC,OAC3B,IAAIJ,KAAIK,MAAOH,MAAM,CAAC;CAC9B,OACMH,EAACE,WAAWK;AAAK"}
|
|
@@ -63,6 +63,7 @@ const ComposerPrimitiveInput = forwardRef(({ autoFocus = false, asChild, render,
|
|
|
63
63
|
const compositionRef = useRef(false);
|
|
64
64
|
useEscapeKeydown((e) => {
|
|
65
65
|
if (!textareaRef.current?.contains(e.target)) return;
|
|
66
|
+
if (e.isComposing) return;
|
|
66
67
|
if (pluginRegistry) {
|
|
67
68
|
for (const plugin of pluginRegistry.getPlugins()) if (plugin.handleKeyDown(e)) return;
|
|
68
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposerInput.js","names":["composeEventHandlers","useComposedRefs","Slot","ClipboardEvent","KeyboardEvent","ReactElement","ReactNode","forwardRef","useCallback","useEffect","useRef","cloneElement","isValidElement","TextareaAutosize","TextareaAutosizeProps","TextareaHeightChangeMeta","useEscapeKeydown","useOnScrollToBottom","useMediaQuery","useAui","flushTapSync","useComposerInputPluginRegistryOptional","useComposerCompactContextOptional","useComposerInputDisabled","useComposerInputValue","useTriggerPopoverAriaProps","TOUCH_PRIMARY_QUERY","ComposerPrimitiveInput","Element","HTMLTextAreaElement","BaseProps","asChild","render","cancelOnEscape","unstable_focusOnRunStart","unstable_focusOnScrollToBottom","unstable_focusOnThreadSwitched","unstable_insertNewlineOnTouchEnter","addAttachmentOnPaste","SubmitModeProps","submitMode","submitOnEnter","Props","autoFocus","disabled","disabledProp","onChange","onKeyDown","onPaste","onSelect","onHeightChange","rest","forwardedRef","aui","pluginRegistry","compactContext","declaredSubmitMode","isTouchPrimary","effectiveSubmitMode","value","isDisabled","textareaRef","ref","compositionRef","e","current","contains","target","Node","plugin","getPlugins","handleKeyDown","composer","getState","canCancel","cancel","preventDefault","handleKeyPress","nativeEvent","isComposing","key","threadState","thread","hasQueue","capabilities","queue","shiftKey","ctrlKey","metaKey","canSend","send","steer","isRunning","shouldSubmit","closest","requestSubmit","handlePaste","threadCapabilities","files","Array","from","clipboardData","attachments","length","Promise","all","map","file","addAttachment","handleHeightChange","height","meta","el","cs","getComputedStyle","contentHeight","boxSizing","parseFloat","paddingTop","paddingBottom","borderTopWidth","borderBottomWidth","Math","round","rowHeight","setMultiline","autoFocusEnabled","focus","textarea","preventScroll","setSelectionRange","type","undefined","on","ariaComboboxProps","inputProps","name","const","React","ForwardedRef","ChangeEvent","isEditing","nativeIsComposing","setText","pos","selectionStart","setCursorPosition","onCompositionStart","CompositionEventHandler","onCompositionEnd","CompositionEvent","SyntheticEvent","renderChildren","children","props","Record","Component","Root","displayName"],"sources":["../../../src/primitives/composer/ComposerInput.tsx"],"sourcesContent":["\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { Slot } from \"radix-ui\";\nimport {\n type ClipboardEvent,\n type KeyboardEvent,\n type ReactElement,\n type ReactNode,\n forwardRef,\n useCallback,\n useEffect,\n useRef,\n cloneElement,\n isValidElement,\n} from \"react\";\nimport TextareaAutosize, {\n type TextareaAutosizeProps,\n type TextareaHeightChangeMeta,\n} from \"react-textarea-autosize\";\nimport { useEscapeKeydown } from \"@radix-ui/react-use-escape-keydown\";\nimport { useOnScrollToBottom } from \"../../utils/hooks/useOnScrollToBottom\";\nimport { useMediaQuery } from \"../../utils/hooks/useMediaQuery\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { flushTapSync } from \"@assistant-ui/tap\";\nimport { useComposerInputPluginRegistryOptional } from \"./ComposerInputPluginContext\";\nimport { useComposerCompactContextOptional } from \"./ComposerCompactContext\";\nimport {\n useComposerInputDisabled,\n useComposerInputValue,\n useTriggerPopoverAriaProps,\n} from \"./useComposerInputState\";\n\nconst TOUCH_PRIMARY_QUERY = \"(pointer: coarse) and (not (any-pointer: fine))\";\n\nexport namespace ComposerPrimitiveInput {\n export type Element = HTMLTextAreaElement;\n\n type BaseProps = {\n /**\n * Whether to render as a child component using Slot.\n * When true, the component will merge its props with its child.\n */\n asChild?: boolean | undefined;\n /**\n * A React element to use as the input container, with props merged in.\n */\n render?: ReactElement | undefined;\n /**\n * Whether to cancel message composition when Escape is pressed.\n * @default true\n */\n cancelOnEscape?: boolean | undefined;\n /**\n * Whether to automatically focus the input when a new run starts.\n * @default true\n */\n unstable_focusOnRunStart?: boolean | undefined;\n /**\n * Whether to automatically focus the input when scrolling to bottom.\n * @default true\n */\n unstable_focusOnScrollToBottom?: boolean | undefined;\n /**\n * Whether to automatically focus the input when switching threads.\n * @default true\n */\n unstable_focusOnThreadSwitched?: boolean | undefined;\n /**\n * Whether plain Enter on a touch-primary device should insert a newline\n * instead of submitting, detected via\n * `(pointer: coarse) and (not (any-pointer: fine))`. Only takes effect\n * when `submitMode` resolves to `\"enter\"`.\n * @default false\n */\n unstable_insertNewlineOnTouchEnter?: boolean | undefined;\n /**\n * Whether to automatically add pasted files as attachments.\n * @default true\n */\n addAttachmentOnPaste?: boolean | undefined;\n };\n\n type SubmitModeProps =\n | {\n /**\n * Controls how the Enter key submits messages.\n * - \"enter\": Plain Enter submits (Shift+Enter for newline)\n * - \"ctrlEnter\": Ctrl/Cmd+Enter submits (plain Enter for newline)\n * - \"none\": Keyboard submission disabled\n * @default \"enter\"\n */\n submitMode?: \"enter\" | \"ctrlEnter\" | \"none\" | undefined;\n /**\n * @deprecated Use `submitMode` instead\n * @ignore\n */\n submitOnEnter?: never;\n }\n | {\n submitMode?: never;\n /**\n * Whether to submit the message when Enter is pressed (without Shift).\n * @default true\n * @deprecated Use `submitMode` instead. Will be removed in a future version.\n */\n submitOnEnter?: boolean | undefined;\n };\n\n export type Props = TextareaAutosizeProps & BaseProps & SubmitModeProps;\n}\n\n/**\n * A text input component for composing messages.\n *\n * This component provides a rich text input experience with automatic resizing,\n * keyboard shortcuts, file paste support, and intelligent focus management.\n * It integrates with the composer context to manage message state and submission.\n *\n * When rendered inside `Unstable_TriggerPopoverRoot` and a popover is open, the\n * underlying `<textarea>` automatically receives `aria-controls`,\n * `aria-expanded`, `aria-haspopup`, and `aria-activedescendant` for the\n * combobox relationship. These computed attributes override user-provided\n * values for those four ARIA props while the popover is open.\n *\n * @example\n * ```tsx\n * // Ctrl/Cmd+Enter to submit (plain Enter inserts newline)\n * <ComposerPrimitive.Input\n * placeholder=\"Type your message...\"\n * submitMode=\"ctrlEnter\"\n * />\n *\n * // Insert a newline on Enter on touch-primary devices.\n * <ComposerPrimitive.Input\n * placeholder=\"Type your message...\"\n * unstable_insertNewlineOnTouchEnter\n * />\n *\n * // Old API (deprecated, still supported)\n * <ComposerPrimitive.Input\n * placeholder=\"Type your message...\"\n * submitOnEnter={true}\n * />\n * ```\n */\nexport const ComposerPrimitiveInput = forwardRef<\n ComposerPrimitiveInput.Element,\n ComposerPrimitiveInput.Props\n>(\n (\n {\n autoFocus = false,\n asChild,\n render,\n disabled: disabledProp,\n onChange,\n onKeyDown,\n onPaste,\n onSelect,\n submitOnEnter,\n submitMode,\n cancelOnEscape = true,\n unstable_focusOnRunStart = true,\n unstable_focusOnScrollToBottom = true,\n unstable_focusOnThreadSwitched = true,\n unstable_insertNewlineOnTouchEnter = false,\n addAttachmentOnPaste = true,\n onHeightChange,\n ...rest\n },\n forwardedRef,\n ) => {\n const aui = useAui();\n const pluginRegistry = useComposerInputPluginRegistryOptional();\n const compactContext = useComposerCompactContextOptional();\n\n const declaredSubmitMode =\n submitMode ?? (submitOnEnter === false ? \"none\" : \"enter\");\n const isTouchPrimary = useMediaQuery(\n unstable_insertNewlineOnTouchEnter ? TOUCH_PRIMARY_QUERY : null,\n );\n const effectiveSubmitMode =\n unstable_insertNewlineOnTouchEnter &&\n isTouchPrimary &&\n declaredSubmitMode === \"enter\"\n ? \"none\"\n : declaredSubmitMode;\n\n const value = useComposerInputValue();\n const isDisabled = useComposerInputDisabled(disabledProp);\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const ref = useComposedRefs(forwardedRef, textareaRef);\n // suppress text/cursor broadcasts during IME composition\n const compositionRef = useRef(false);\n\n useEscapeKeydown((e) => {\n // Only handle ESC if it originated from within this input\n if (!textareaRef.current?.contains(e.target as Node)) return;\n\n // Let registered plugins (mention, slash command, etc.) handle Escape first\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n if (plugin.handleKeyDown(e)) return;\n }\n }\n\n if (!cancelOnEscape) return;\n\n const composer = aui.composer;\n if (composer.getState().canCancel) {\n composer.cancel();\n e.preventDefault();\n }\n });\n\n const handleKeyPress = (e: KeyboardEvent) => {\n if (isDisabled) return;\n\n // ignore IME composition events\n if (e.nativeEvent.isComposing) return;\n\n // Let registered plugins (mention, slash command, etc.) handle keyboard events first\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n if (plugin.handleKeyDown(e)) return;\n }\n }\n\n if (e.key === \"Enter\") {\n const threadState = aui.thread.getState();\n const hasQueue = threadState.capabilities.queue;\n\n // Steer hotkey: Cmd/Ctrl+Shift+Enter (respects submitMode=\"none\" and canSend)\n if (\n e.shiftKey &&\n (e.ctrlKey || e.metaKey) &&\n hasQueue &&\n declaredSubmitMode !== \"none\" &&\n aui.composer.getState().canSend\n ) {\n e.preventDefault();\n aui.composer.send({ steer: true });\n return;\n }\n\n // Regular newline: Shift+Enter\n if (e.shiftKey) return;\n\n // Block submission when running unless queue is supported\n if (threadState.isRunning && !hasQueue) return;\n\n let shouldSubmit = false;\n if (effectiveSubmitMode === \"ctrlEnter\") {\n shouldSubmit = e.ctrlKey || e.metaKey;\n } else if (effectiveSubmitMode === \"enter\") {\n shouldSubmit = true;\n }\n\n if (shouldSubmit) {\n e.preventDefault();\n textareaRef.current?.closest(\"form\")?.requestSubmit();\n }\n }\n };\n\n const handlePaste = async (e: ClipboardEvent<HTMLTextAreaElement>) => {\n if (!addAttachmentOnPaste) return;\n const threadCapabilities = aui.thread.getState().capabilities;\n const files = Array.from(e.clipboardData?.files || []);\n\n if (threadCapabilities.attachments && files.length > 0) {\n e.preventDefault();\n await Promise.all(\n files.map(async (file) => {\n try {\n await aui.composer.addAttachment(file);\n } catch {\n // The composer runtime emits composer.attachmentAddError before rejecting.\n }\n }),\n );\n }\n };\n\n const handleHeightChange = (\n height: number,\n meta: TextareaHeightChangeMeta,\n ) => {\n onHeightChange?.(height, meta);\n if (!compactContext) return;\n const el = textareaRef.current;\n if (!el || el.value === \"\") return;\n const cs = getComputedStyle(el);\n const contentHeight =\n cs.boxSizing === \"border-box\"\n ? height -\n parseFloat(cs.paddingTop) -\n parseFloat(cs.paddingBottom) -\n parseFloat(cs.borderTopWidth) -\n parseFloat(cs.borderBottomWidth)\n : height;\n if (Math.round(contentHeight / meta.rowHeight) > 1) {\n compactContext.setMultiline(true);\n }\n };\n\n const autoFocusEnabled = autoFocus && !isDisabled;\n const focus = useCallback(() => {\n const textarea = textareaRef.current;\n if (!textarea || !autoFocusEnabled) return;\n\n textarea.focus({ preventScroll: true });\n textarea.setSelectionRange(textarea.value.length, textarea.value.length);\n }, [autoFocusEnabled]);\n\n useEffect(() => focus(), [focus]);\n\n useOnScrollToBottom(() => {\n if (\n aui.composer.getState().type === \"thread\" &&\n unstable_focusOnScrollToBottom\n ) {\n focus();\n }\n });\n\n useEffect(() => {\n if (\n aui.composer.getState().type !== \"thread\" ||\n !unstable_focusOnRunStart\n )\n return undefined;\n\n return aui.on(\"thread.runStart\", focus);\n }, [unstable_focusOnRunStart, focus, aui]);\n\n useEffect(() => {\n if (\n aui.composer.getState().type !== \"thread\" ||\n !unstable_focusOnThreadSwitched\n )\n return undefined;\n\n return aui.on(\"threadListItem.switchedTo\", focus);\n }, [unstable_focusOnThreadSwitched, focus, aui]);\n\n useEffect(() => {\n if (value === \"\") compactContext?.setMultiline(false);\n }, [value, compactContext]);\n\n const ariaComboboxProps = useTriggerPopoverAriaProps();\n\n const inputProps = {\n name: \"input\" as const,\n value,\n ...rest,\n ...ariaComboboxProps,\n ref: ref as React.ForwardedRef<HTMLTextAreaElement>,\n disabled: isDisabled,\n onChange: composeEventHandlers(\n onChange,\n (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n if (!aui.composer.getState().isEditing) return;\n const nativeIsComposing =\n (e.nativeEvent as { isComposing?: boolean }).isComposing === true;\n // recover stuck compositionRef when the browser drops compositionend\n if (compositionRef.current && !nativeIsComposing) {\n compositionRef.current = false;\n }\n const isComposing = nativeIsComposing || compositionRef.current;\n // keep controlled value in sync mid-IME so react does not reset the textarea to a stale value\n flushTapSync(() => {\n aui.composer.setText(e.target.value);\n });\n if (isComposing) return;\n const pos = e.target.selectionStart ?? e.target.value.length;\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n plugin.setCursorPosition(pos);\n }\n }\n },\n ),\n onKeyDown: composeEventHandlers(onKeyDown, handleKeyPress),\n onCompositionStart: composeEventHandlers(\n (rest as { onCompositionStart?: React.CompositionEventHandler })\n .onCompositionStart,\n () => {\n compositionRef.current = true;\n },\n ),\n onCompositionEnd: composeEventHandlers(\n (rest as { onCompositionEnd?: React.CompositionEventHandler })\n .onCompositionEnd,\n (e: React.CompositionEvent<HTMLTextAreaElement>) => {\n compositionRef.current = false;\n if (!aui.composer.getState().isEditing) return;\n const target = e.target as HTMLTextAreaElement;\n flushTapSync(() => {\n aui.composer.setText(target.value);\n });\n const pos = target.selectionStart ?? target.value.length;\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n plugin.setCursorPosition(pos);\n }\n }\n },\n ),\n onSelect: composeEventHandlers(\n onSelect,\n (e: React.SyntheticEvent<HTMLTextAreaElement>) => {\n if (compositionRef.current) return;\n const target = e.target as HTMLTextAreaElement;\n const pos = target.selectionStart ?? target.value.length;\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n plugin.setCursorPosition(pos);\n }\n }\n },\n ),\n onPaste: composeEventHandlers(onPaste, handlePaste),\n ...(compactContext\n ? { onHeightChange: handleHeightChange }\n : onHeightChange !== undefined\n ? { onHeightChange }\n : {}),\n };\n\n if (render && isValidElement(render)) {\n const renderChildren =\n (rest as any).children !== undefined\n ? ((rest as any).children as ReactNode)\n : ((render.props as Record<string, unknown>).children as ReactNode);\n return (\n <Slot.Root {...inputProps}>\n {cloneElement(render, undefined, renderChildren)}\n </Slot.Root>\n );\n }\n\n const Component = asChild ? Slot.Root : TextareaAutosize;\n return <Component {...inputProps} />;\n },\n);\n\nComposerPrimitiveInput.displayName = \"ComposerPrimitive.Input\";\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,MAAM0B,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiH5B,MAAaC,yBAAyBpB,YAKlC,EACEoC,YAAY,OACZZ,SACAC,QACAY,UAAUC,cACVC,UACAC,WACAC,SACAC,UACAR,eACAD,YACAP,iBAAiB,MACjBC,2BAA2B,MAC3BC,iCAAiC,MACjCC,iCAAiC,MACjCC,qCAAqC,OACrCC,uBAAuB,MACvBY,gBACA,GAAGC,QAELC,iBACG;CACH,MAAMC,MAAMlC,OAAO;CACnB,MAAMmC,iBAAiBjC,uCAAuC;CAC9D,MAAMkC,iBAAiBjC,kCAAkC;CAEzD,MAAMkC,qBACJhB,eAAeC,kBAAkB,QAAQ,SAAS;CACpD,MAAMgB,iBAAiBvC,cACrBmB,qCAAqCX,sBAAsB,IAC7D;CACA,MAAMgC,sBACJrB,sCACAoB,kBACAD,uBAAuB,UACnB,SACAA;CAEN,MAAMG,QAAQnC,sBAAsB;CACpC,MAAMoC,aAAarC,yBAAyBsB,YAAY;CACxD,MAAMgB,cAAcnD,OAA4B,IAAI;CACpD,MAAMoD,MAAM7D,gBAAgBmD,cAAcS,WAAW;CAErD,MAAME,iBAAiBrD,OAAO,KAAK;CAEnCM,kBAAkBgD,MAAM;EAEtB,IAAI,CAACH,YAAYI,SAASC,SAASF,EAAEG,MAAc,GAAG;EAGtD,IAAIb,gBACG;QAAA,MAAMe,UAAUf,eAAegB,WAAW,GAC7C,IAAID,OAAOE,cAAcP,CAAC,GAAG;EAAA;EAIjC,IAAI,CAAC/B,gBAAgB;EAErB,MAAMuC,WAAWnB,IAAImB;EACrB,IAAIA,SAASC,SAAS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K;GACnC,CAAC;GACD,MAAMqF,QAAM7E,OAAO8E,kBAAkB9E,OAAOR,MAAM4C;GAClD,IAAIjD,gBACF,KAAK,MAAMe,YAAUf,eAAegB,WAAW,GAC7CD,SAAO6E,kBAAkBF,KAAG;EAGlC,CACF;EACA/F,UAAUjD,qBACRiD,WACCe,QAAiD;GAChD,IAAID,eAAeE,SAAS;GAC5B,MAAME,WAASH,IAAEG;GACjB,MAAM6E,QAAM7E,SAAO8E,kBAAkB9E,SAAOR,MAAM4C;GAClD,IAAIjD,gBACF,KAAK,MAAMe,YAAUf,eAAegB,WAAW,GAC7CD,SAAO6E,kBAAkBF,KAAG;EAGlC,CACF;EACAhG,SAAShD,qBAAqBgD,SAASgD,WAAW;EAClD,GAAIzC,iBACA,EAAEL,gBAAgB2D,mBAAmB,IACrC3D,mBAAmBkF,KAAAA,IACjB,EAAElF,eAAe,IACjB,CAAC;CACT;CAEA,IAAIlB,UAAUpB,eAAeoB,MAAM,GAAG;EACpC,MAAMwH,iBACHrG,KAAasG,aAAarB,KAAAA,IACrBjF,KAAasG,WACbzH,OAAO0H,MAAkCD;EACjD,OACE,oBAAC,KAAK,MAAN;GAAW,GAAIlB;GACZ5H,UAAAA,aAAaqB,QAAQoG,KAAAA,GAAWoB,cAAc;EACtC,CAAA;CAEf;CAGA,OAAO,oBADWzH,UAAU7B,KAAK2J,OAAOhJ,kBACjC,EAAW,GAAI0H,WAAW,CAAA;AACnC,CACF;AAEA5G,uBAAuBmI,cAAc"}
|
|
1
|
+
{"version":3,"file":"ComposerInput.js","names":["composeEventHandlers","useComposedRefs","Slot","ClipboardEvent","KeyboardEvent","ReactElement","ReactNode","forwardRef","useCallback","useEffect","useRef","cloneElement","isValidElement","TextareaAutosize","TextareaAutosizeProps","TextareaHeightChangeMeta","useEscapeKeydown","useOnScrollToBottom","useMediaQuery","useAui","flushTapSync","useComposerInputPluginRegistryOptional","useComposerCompactContextOptional","useComposerInputDisabled","useComposerInputValue","useTriggerPopoverAriaProps","TOUCH_PRIMARY_QUERY","ComposerPrimitiveInput","Element","HTMLTextAreaElement","BaseProps","asChild","render","cancelOnEscape","unstable_focusOnRunStart","unstable_focusOnScrollToBottom","unstable_focusOnThreadSwitched","unstable_insertNewlineOnTouchEnter","addAttachmentOnPaste","SubmitModeProps","submitMode","submitOnEnter","Props","autoFocus","disabled","disabledProp","onChange","onKeyDown","onPaste","onSelect","onHeightChange","rest","forwardedRef","aui","pluginRegistry","compactContext","declaredSubmitMode","isTouchPrimary","effectiveSubmitMode","value","isDisabled","textareaRef","ref","compositionRef","e","current","contains","target","Node","isComposing","plugin","getPlugins","handleKeyDown","composer","getState","canCancel","cancel","preventDefault","handleKeyPress","nativeEvent","key","threadState","thread","hasQueue","capabilities","queue","shiftKey","ctrlKey","metaKey","canSend","send","steer","isRunning","shouldSubmit","closest","requestSubmit","handlePaste","threadCapabilities","files","Array","from","clipboardData","attachments","length","Promise","all","map","file","addAttachment","handleHeightChange","height","meta","el","cs","getComputedStyle","contentHeight","boxSizing","parseFloat","paddingTop","paddingBottom","borderTopWidth","borderBottomWidth","Math","round","rowHeight","setMultiline","autoFocusEnabled","focus","textarea","preventScroll","setSelectionRange","type","undefined","on","ariaComboboxProps","inputProps","name","const","React","ForwardedRef","ChangeEvent","isEditing","nativeIsComposing","setText","pos","selectionStart","setCursorPosition","onCompositionStart","CompositionEventHandler","onCompositionEnd","CompositionEvent","SyntheticEvent","renderChildren","children","props","Record","Component","Root","displayName"],"sources":["../../../src/primitives/composer/ComposerInput.tsx"],"sourcesContent":["\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { Slot } from \"radix-ui\";\nimport {\n type ClipboardEvent,\n type KeyboardEvent,\n type ReactElement,\n type ReactNode,\n forwardRef,\n useCallback,\n useEffect,\n useRef,\n cloneElement,\n isValidElement,\n} from \"react\";\nimport TextareaAutosize, {\n type TextareaAutosizeProps,\n type TextareaHeightChangeMeta,\n} from \"react-textarea-autosize\";\nimport { useEscapeKeydown } from \"@radix-ui/react-use-escape-keydown\";\nimport { useOnScrollToBottom } from \"../../utils/hooks/useOnScrollToBottom\";\nimport { useMediaQuery } from \"../../utils/hooks/useMediaQuery\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { flushTapSync } from \"@assistant-ui/tap\";\nimport { useComposerInputPluginRegistryOptional } from \"./ComposerInputPluginContext\";\nimport { useComposerCompactContextOptional } from \"./ComposerCompactContext\";\nimport {\n useComposerInputDisabled,\n useComposerInputValue,\n useTriggerPopoverAriaProps,\n} from \"./useComposerInputState\";\n\nconst TOUCH_PRIMARY_QUERY = \"(pointer: coarse) and (not (any-pointer: fine))\";\n\nexport namespace ComposerPrimitiveInput {\n export type Element = HTMLTextAreaElement;\n\n type BaseProps = {\n /**\n * Whether to render as a child component using Slot.\n * When true, the component will merge its props with its child.\n */\n asChild?: boolean | undefined;\n /**\n * A React element to use as the input container, with props merged in.\n */\n render?: ReactElement | undefined;\n /**\n * Whether to cancel message composition when Escape is pressed.\n * @default true\n */\n cancelOnEscape?: boolean | undefined;\n /**\n * Whether to automatically focus the input when a new run starts.\n * @default true\n */\n unstable_focusOnRunStart?: boolean | undefined;\n /**\n * Whether to automatically focus the input when scrolling to bottom.\n * @default true\n */\n unstable_focusOnScrollToBottom?: boolean | undefined;\n /**\n * Whether to automatically focus the input when switching threads.\n * @default true\n */\n unstable_focusOnThreadSwitched?: boolean | undefined;\n /**\n * Whether plain Enter on a touch-primary device should insert a newline\n * instead of submitting, detected via\n * `(pointer: coarse) and (not (any-pointer: fine))`. Only takes effect\n * when `submitMode` resolves to `\"enter\"`.\n * @default false\n */\n unstable_insertNewlineOnTouchEnter?: boolean | undefined;\n /**\n * Whether to automatically add pasted files as attachments.\n * @default true\n */\n addAttachmentOnPaste?: boolean | undefined;\n };\n\n type SubmitModeProps =\n | {\n /**\n * Controls how the Enter key submits messages.\n * - \"enter\": Plain Enter submits (Shift+Enter for newline)\n * - \"ctrlEnter\": Ctrl/Cmd+Enter submits (plain Enter for newline)\n * - \"none\": Keyboard submission disabled\n * @default \"enter\"\n */\n submitMode?: \"enter\" | \"ctrlEnter\" | \"none\" | undefined;\n /**\n * @deprecated Use `submitMode` instead\n * @ignore\n */\n submitOnEnter?: never;\n }\n | {\n submitMode?: never;\n /**\n * Whether to submit the message when Enter is pressed (without Shift).\n * @default true\n * @deprecated Use `submitMode` instead. Will be removed in a future version.\n */\n submitOnEnter?: boolean | undefined;\n };\n\n export type Props = TextareaAutosizeProps & BaseProps & SubmitModeProps;\n}\n\n/**\n * A text input component for composing messages.\n *\n * This component provides a rich text input experience with automatic resizing,\n * keyboard shortcuts, file paste support, and intelligent focus management.\n * It integrates with the composer context to manage message state and submission.\n *\n * When rendered inside `Unstable_TriggerPopoverRoot` and a popover is open, the\n * underlying `<textarea>` automatically receives `aria-controls`,\n * `aria-expanded`, `aria-haspopup`, and `aria-activedescendant` for the\n * combobox relationship. These computed attributes override user-provided\n * values for those four ARIA props while the popover is open.\n *\n * @example\n * ```tsx\n * // Ctrl/Cmd+Enter to submit (plain Enter inserts newline)\n * <ComposerPrimitive.Input\n * placeholder=\"Type your message...\"\n * submitMode=\"ctrlEnter\"\n * />\n *\n * // Insert a newline on Enter on touch-primary devices.\n * <ComposerPrimitive.Input\n * placeholder=\"Type your message...\"\n * unstable_insertNewlineOnTouchEnter\n * />\n *\n * // Old API (deprecated, still supported)\n * <ComposerPrimitive.Input\n * placeholder=\"Type your message...\"\n * submitOnEnter={true}\n * />\n * ```\n */\nexport const ComposerPrimitiveInput = forwardRef<\n ComposerPrimitiveInput.Element,\n ComposerPrimitiveInput.Props\n>(\n (\n {\n autoFocus = false,\n asChild,\n render,\n disabled: disabledProp,\n onChange,\n onKeyDown,\n onPaste,\n onSelect,\n submitOnEnter,\n submitMode,\n cancelOnEscape = true,\n unstable_focusOnRunStart = true,\n unstable_focusOnScrollToBottom = true,\n unstable_focusOnThreadSwitched = true,\n unstable_insertNewlineOnTouchEnter = false,\n addAttachmentOnPaste = true,\n onHeightChange,\n ...rest\n },\n forwardedRef,\n ) => {\n const aui = useAui();\n const pluginRegistry = useComposerInputPluginRegistryOptional();\n const compactContext = useComposerCompactContextOptional();\n\n const declaredSubmitMode =\n submitMode ?? (submitOnEnter === false ? \"none\" : \"enter\");\n const isTouchPrimary = useMediaQuery(\n unstable_insertNewlineOnTouchEnter ? TOUCH_PRIMARY_QUERY : null,\n );\n const effectiveSubmitMode =\n unstable_insertNewlineOnTouchEnter &&\n isTouchPrimary &&\n declaredSubmitMode === \"enter\"\n ? \"none\"\n : declaredSubmitMode;\n\n const value = useComposerInputValue();\n const isDisabled = useComposerInputDisabled(disabledProp);\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const ref = useComposedRefs(forwardedRef, textareaRef);\n // suppress text/cursor broadcasts during IME composition\n const compositionRef = useRef(false);\n\n useEscapeKeydown((e) => {\n // Only handle ESC if it originated from within this input\n if (!textareaRef.current?.contains(e.target as Node)) return;\n\n // ignore IME composition events\n if (e.isComposing) return;\n\n // Let registered plugins (mention, slash command, etc.) handle Escape first\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n if (plugin.handleKeyDown(e)) return;\n }\n }\n\n if (!cancelOnEscape) return;\n\n const composer = aui.composer;\n if (composer.getState().canCancel) {\n composer.cancel();\n e.preventDefault();\n }\n });\n\n const handleKeyPress = (e: KeyboardEvent) => {\n if (isDisabled) return;\n\n // ignore IME composition events\n if (e.nativeEvent.isComposing) return;\n\n // Let registered plugins (mention, slash command, etc.) handle keyboard events first\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n if (plugin.handleKeyDown(e)) return;\n }\n }\n\n if (e.key === \"Enter\") {\n const threadState = aui.thread.getState();\n const hasQueue = threadState.capabilities.queue;\n\n // Steer hotkey: Cmd/Ctrl+Shift+Enter (respects submitMode=\"none\" and canSend)\n if (\n e.shiftKey &&\n (e.ctrlKey || e.metaKey) &&\n hasQueue &&\n declaredSubmitMode !== \"none\" &&\n aui.composer.getState().canSend\n ) {\n e.preventDefault();\n aui.composer.send({ steer: true });\n return;\n }\n\n // Regular newline: Shift+Enter\n if (e.shiftKey) return;\n\n // Block submission when running unless queue is supported\n if (threadState.isRunning && !hasQueue) return;\n\n let shouldSubmit = false;\n if (effectiveSubmitMode === \"ctrlEnter\") {\n shouldSubmit = e.ctrlKey || e.metaKey;\n } else if (effectiveSubmitMode === \"enter\") {\n shouldSubmit = true;\n }\n\n if (shouldSubmit) {\n e.preventDefault();\n textareaRef.current?.closest(\"form\")?.requestSubmit();\n }\n }\n };\n\n const handlePaste = async (e: ClipboardEvent<HTMLTextAreaElement>) => {\n if (!addAttachmentOnPaste) return;\n const threadCapabilities = aui.thread.getState().capabilities;\n const files = Array.from(e.clipboardData?.files || []);\n\n if (threadCapabilities.attachments && files.length > 0) {\n e.preventDefault();\n await Promise.all(\n files.map(async (file) => {\n try {\n await aui.composer.addAttachment(file);\n } catch {\n // The composer runtime emits composer.attachmentAddError before rejecting.\n }\n }),\n );\n }\n };\n\n const handleHeightChange = (\n height: number,\n meta: TextareaHeightChangeMeta,\n ) => {\n onHeightChange?.(height, meta);\n if (!compactContext) return;\n const el = textareaRef.current;\n if (!el || el.value === \"\") return;\n const cs = getComputedStyle(el);\n const contentHeight =\n cs.boxSizing === \"border-box\"\n ? height -\n parseFloat(cs.paddingTop) -\n parseFloat(cs.paddingBottom) -\n parseFloat(cs.borderTopWidth) -\n parseFloat(cs.borderBottomWidth)\n : height;\n if (Math.round(contentHeight / meta.rowHeight) > 1) {\n compactContext.setMultiline(true);\n }\n };\n\n const autoFocusEnabled = autoFocus && !isDisabled;\n const focus = useCallback(() => {\n const textarea = textareaRef.current;\n if (!textarea || !autoFocusEnabled) return;\n\n textarea.focus({ preventScroll: true });\n textarea.setSelectionRange(textarea.value.length, textarea.value.length);\n }, [autoFocusEnabled]);\n\n useEffect(() => focus(), [focus]);\n\n useOnScrollToBottom(() => {\n if (\n aui.composer.getState().type === \"thread\" &&\n unstable_focusOnScrollToBottom\n ) {\n focus();\n }\n });\n\n useEffect(() => {\n if (\n aui.composer.getState().type !== \"thread\" ||\n !unstable_focusOnRunStart\n )\n return undefined;\n\n return aui.on(\"thread.runStart\", focus);\n }, [unstable_focusOnRunStart, focus, aui]);\n\n useEffect(() => {\n if (\n aui.composer.getState().type !== \"thread\" ||\n !unstable_focusOnThreadSwitched\n )\n return undefined;\n\n return aui.on(\"threadListItem.switchedTo\", focus);\n }, [unstable_focusOnThreadSwitched, focus, aui]);\n\n useEffect(() => {\n if (value === \"\") compactContext?.setMultiline(false);\n }, [value, compactContext]);\n\n const ariaComboboxProps = useTriggerPopoverAriaProps();\n\n const inputProps = {\n name: \"input\" as const,\n value,\n ...rest,\n ...ariaComboboxProps,\n ref: ref as React.ForwardedRef<HTMLTextAreaElement>,\n disabled: isDisabled,\n onChange: composeEventHandlers(\n onChange,\n (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n if (!aui.composer.getState().isEditing) return;\n const nativeIsComposing =\n (e.nativeEvent as { isComposing?: boolean }).isComposing === true;\n // recover stuck compositionRef when the browser drops compositionend\n if (compositionRef.current && !nativeIsComposing) {\n compositionRef.current = false;\n }\n const isComposing = nativeIsComposing || compositionRef.current;\n // keep controlled value in sync mid-IME so react does not reset the textarea to a stale value\n flushTapSync(() => {\n aui.composer.setText(e.target.value);\n });\n if (isComposing) return;\n const pos = e.target.selectionStart ?? e.target.value.length;\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n plugin.setCursorPosition(pos);\n }\n }\n },\n ),\n onKeyDown: composeEventHandlers(onKeyDown, handleKeyPress),\n onCompositionStart: composeEventHandlers(\n (rest as { onCompositionStart?: React.CompositionEventHandler })\n .onCompositionStart,\n () => {\n compositionRef.current = true;\n },\n ),\n onCompositionEnd: composeEventHandlers(\n (rest as { onCompositionEnd?: React.CompositionEventHandler })\n .onCompositionEnd,\n (e: React.CompositionEvent<HTMLTextAreaElement>) => {\n compositionRef.current = false;\n if (!aui.composer.getState().isEditing) return;\n const target = e.target as HTMLTextAreaElement;\n flushTapSync(() => {\n aui.composer.setText(target.value);\n });\n const pos = target.selectionStart ?? target.value.length;\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n plugin.setCursorPosition(pos);\n }\n }\n },\n ),\n onSelect: composeEventHandlers(\n onSelect,\n (e: React.SyntheticEvent<HTMLTextAreaElement>) => {\n if (compositionRef.current) return;\n const target = e.target as HTMLTextAreaElement;\n const pos = target.selectionStart ?? target.value.length;\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n plugin.setCursorPosition(pos);\n }\n }\n },\n ),\n onPaste: composeEventHandlers(onPaste, handlePaste),\n ...(compactContext\n ? { onHeightChange: handleHeightChange }\n : onHeightChange !== undefined\n ? { onHeightChange }\n : {}),\n };\n\n if (render && isValidElement(render)) {\n const renderChildren =\n (rest as any).children !== undefined\n ? ((rest as any).children as ReactNode)\n : ((render.props as Record<string, unknown>).children as ReactNode);\n return (\n <Slot.Root {...inputProps}>\n {cloneElement(render, undefined, renderChildren)}\n </Slot.Root>\n );\n }\n\n const Component = asChild ? Slot.Root : TextareaAutosize;\n return <Component {...inputProps} />;\n },\n);\n\nComposerPrimitiveInput.displayName = \"ComposerPrimitive.Input\";\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,MAAM0B,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiH5B,MAAaC,yBAAyBpB,YAKlC,EACEoC,YAAY,OACZZ,SACAC,QACAY,UAAUC,cACVC,UACAC,WACAC,SACAC,UACAR,eACAD,YACAP,iBAAiB,MACjBC,2BAA2B,MAC3BC,iCAAiC,MACjCC,iCAAiC,MACjCC,qCAAqC,OACrCC,uBAAuB,MACvBY,gBACA,GAAGC,QAELC,iBACG;CACH,MAAMC,MAAMlC,OAAO;CACnB,MAAMmC,iBAAiBjC,uCAAuC;CAC9D,MAAMkC,iBAAiBj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,IACjB,CAAC;CACT;CAEA,IAAIlB,UAAUpB,eAAeoB,MAAM,GAAG;EACpC,MAAMwH,iBACHrG,KAAasG,aAAarB,KAAAA,IACrBjF,KAAasG,WACbzH,OAAO0H,MAAkCD;EACjD,OACE,oBAAC,KAAK,MAAN;GAAW,GAAIlB;GACZ5H,UAAAA,aAAaqB,QAAQoG,KAAAA,GAAWoB,cAAc;EACtC,CAAA;CAEf;CAGA,OAAO,oBADWzH,UAAU7B,KAAK2J,OAAOhJ,kBACjC,EAAW,GAAI0H,WAAW,CAAA;AACnC,CACF;AAEA5G,uBAAuBmI,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueueItemText.d.ts","names":[],"sources":["../../../src/primitives/queueItem/QueueItemText.tsx"],"mappings":";;;kBAUiB;OACH,UAAU,oBAAoB,UAAU;OACxC,QAAQ,gCAAgC,UAAU;;;;;;;;;;cAWnD,wCAAsB,0BAAA,KAAA,qBAAA,gBAAA,mCAAA,eAAA;;;;
|
|
1
|
+
{"version":3,"file":"QueueItemText.d.ts","names":[],"sources":["../../../src/primitives/queueItem/QueueItemText.tsx"],"mappings":";;;kBAUiB;OACH,UAAU,oBAAoB,UAAU;OACxC,QAAQ,gCAAgC,UAAU;;;;;;;;;;cAWnD,wCAAsB,0BAAA,KAAA,qBAAA,gBAAA,mCAAA,eAAA;;;;oBAiBjC,cAAA,2CAAA,cAAA"}
|
|
@@ -15,8 +15,8 @@ import { jsx } from "react/jsx-runtime";
|
|
|
15
15
|
*/
|
|
16
16
|
const QueueItemPrimitiveText = forwardRef((props, ref) => {
|
|
17
17
|
const $ = c(4);
|
|
18
|
-
const
|
|
19
|
-
const t0 = props.children ??
|
|
18
|
+
const text = useAuiState(_temp3);
|
|
19
|
+
const t0 = props.children ?? text;
|
|
20
20
|
let t1;
|
|
21
21
|
if ($[0] !== props || $[1] !== ref || $[2] !== t0) {
|
|
22
22
|
t1 = /* @__PURE__ */ jsx(Primitive.span, {
|
|
@@ -32,8 +32,14 @@ const QueueItemPrimitiveText = forwardRef((props, ref) => {
|
|
|
32
32
|
return t1;
|
|
33
33
|
});
|
|
34
34
|
QueueItemPrimitiveText.displayName = "QueueItemPrimitive.Text";
|
|
35
|
-
function _temp(
|
|
36
|
-
return
|
|
35
|
+
function _temp(part) {
|
|
36
|
+
return part.type === "text";
|
|
37
|
+
}
|
|
38
|
+
function _temp2(part_0) {
|
|
39
|
+
return part_0.text;
|
|
40
|
+
}
|
|
41
|
+
function _temp3(s) {
|
|
42
|
+
return (s.queueItem.parts ?? []).filter(_temp).map(_temp2).join("\n\n");
|
|
37
43
|
}
|
|
38
44
|
//#endregion
|
|
39
45
|
export { QueueItemPrimitiveText };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueueItemText.js","names":["c","_c","Primitive","ComponentRef","ComponentPropsWithoutRef","forwardRef","useAuiState","QueueItemPrimitiveText","Element","span","Props","props","ref","$","
|
|
1
|
+
{"version":3,"file":"QueueItemText.js","names":["c","_c","Primitive","ComponentRef","ComponentPropsWithoutRef","forwardRef","useAuiState","QueueItemPrimitiveText","Element","span","Props","props","ref","$","text","_temp3","t0","children","t1","displayName","_temp","part","type","_temp2","part_0","s","queueItem","parts","filter","map","join"],"sources":["../../../src/primitives/queueItem/QueueItemText.tsx"],"sourcesContent":["\"use client\";\n\nimport { Primitive } from \"../../utils/Primitive\";\nimport {\n type ComponentRef,\n type ComponentPropsWithoutRef,\n forwardRef,\n} from \"react\";\nimport { useAuiState } from \"@assistant-ui/store\";\n\nexport namespace QueueItemPrimitiveText {\n export type Element = ComponentRef<typeof Primitive.span>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.span>;\n}\n\n/**\n * Renders the prompt text of a queue item.\n *\n * @example\n * ```tsx\n * <QueueItemPrimitive.Text />\n * ```\n */\nexport const QueueItemPrimitiveText = forwardRef<\n QueueItemPrimitiveText.Element,\n QueueItemPrimitiveText.Props\n>((props, ref) => {\n const text = useAuiState((s) =>\n // hosts on the pre-parts adapter shape may omit the field at runtime\n (s.queueItem.parts ?? [])\n .filter((part) => part.type === \"text\")\n .map((part) => part.text)\n .join(\"\\n\\n\"),\n );\n\n return (\n <Primitive.span {...props} ref={ref}>\n {props.children ?? text}\n </Primitive.span>\n );\n});\n\nQueueItemPrimitiveText.displayName = \"QueueItemPrimitive.Text\";\n"],"mappings":";;;;;;;;;;;;;;;AAuBA,MAAaO,yBAAyBF,YAGpCM,OAAAC,QAAA;CAAA,MAAAC,IAAAZ,EAAA,CAAA;CACA,MAAAa,OAAaR,YAAYS,MAMzB;CAIK,MAAAC,KAAAL,MAAKM,YAALH;CAAsB,IAAAI;CAAA,IAAAL,EAAA,OAAAF,SAAAE,EAAA,OAAAD,OAAAC,EAAA,OAAAG,IAAA;EADzBE,KAAA,oBAAA,UAAA,MAAA;GAAA,GAAoBP;GAAYC;GAC7BI,UAAAA;EACH,CAAA;EAAiBH,EAAA,KAAAF;EAAAE,EAAA,KAAAD;EAAAC,EAAA,KAAAG;EAAAH,EAAA,KAAAK;CAAA,OAAAA,KAAAL,EAAA;CAAA,OAFjBK;AAEiB,CAEpB;AAEDX,uBAAuBY,cAAc;AAhBnC,SAAAC,MAAAC,MAAA;CAAA,OAIsBA,KAAIC,SAAU;AAAM;AAJ1C,SAAAC,OAAAC,QAAA;CAAA,OAKmBH,OAAIP;AAAK;AAL5B,SAAAC,OAAAU,GAAA;CAAA,QAGGA,EAACC,UAAUC,SAAX,CAAA,EAAA,CAAuBC,OACdR,KAA8B,CAAC,CAAAS,IAClCN,MAAmB,CAAC,CAAAO,KACnB,MAAM;AAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionToolbarRoot.d.ts","names":[],"sources":["../../../src/primitives/selectionToolbar/SelectionToolbarRoot.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"SelectionToolbarRoot.d.ts","names":[],"sources":["../../../src/primitives/selectionToolbar/SelectionToolbarRoot.tsx"],"mappings":";;;KAgBK;EACH;EACA;EACA,MAAM;;cAKK,+BAAuB;kBAGnB;OACH,UAAU,oBAAoB,UAAU;OACxC,QAAQ,gCAAgC,UAAU;;;;;;;;;;;;;;;;cAiBnD,+CAA6B,0BAAA,KAAA,qBAAA,gBAAA,kCAAA,eAAA;;;;oBAkFxC,cAAA,0CAAA,cAAA"}
|