@assistant-ui/react 0.15.3 → 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.
Files changed (58) hide show
  1. package/dist/client/ExternalThread.d.ts.map +1 -1
  2. package/dist/client/ExternalThread.js +383 -368
  3. package/dist/client/ExternalThread.js.map +1 -1
  4. package/dist/context/providers/MessageProvider.js +15 -34
  5. package/dist/context/providers/MessageProvider.js.map +1 -1
  6. package/dist/index.d.ts +3 -3
  7. package/dist/index.js +2 -2
  8. package/dist/legacy-runtime/AssistantRuntimeProvider.d.ts +6 -1
  9. package/dist/legacy-runtime/AssistantRuntimeProvider.d.ts.map +1 -1
  10. package/dist/legacy-runtime/AssistantRuntimeProvider.js +10 -8
  11. package/dist/legacy-runtime/AssistantRuntimeProvider.js.map +1 -1
  12. package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.d.ts.map +1 -1
  13. package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.js +8 -1
  14. package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.js.map +1 -1
  15. package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts +11 -1
  16. package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts.map +1 -1
  17. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -1
  18. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +64 -18
  19. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
  20. package/dist/primitives/actionBar/ActionBarExportMarkdown.js +1 -1
  21. package/dist/primitives/actionBar/ActionBarExportMarkdown.js.map +1 -1
  22. package/dist/primitives/attachment/AttachmentThumb.d.ts.map +1 -1
  23. package/dist/primitives/attachment/AttachmentThumb.js +17 -14
  24. package/dist/primitives/attachment/AttachmentThumb.js.map +1 -1
  25. package/dist/primitives/composer/ComposerInput.js +1 -0
  26. package/dist/primitives/composer/ComposerInput.js.map +1 -1
  27. package/dist/primitives/queueItem/QueueItemText.d.ts.map +1 -1
  28. package/dist/primitives/queueItem/QueueItemText.js +10 -4
  29. package/dist/primitives/queueItem/QueueItemText.js.map +1 -1
  30. package/dist/primitives/selectionToolbar/SelectionToolbarRoot.d.ts.map +1 -1
  31. package/dist/primitives/selectionToolbar/SelectionToolbarRoot.js +5 -4
  32. package/dist/primitives/selectionToolbar/SelectionToolbarRoot.js.map +1 -1
  33. package/dist/utils/createActionButton.js +1 -1
  34. package/dist/utils/createActionButton.js.map +1 -1
  35. package/dist/utils/useToolArgsFieldStatus.d.ts +2 -2
  36. package/package.json +7 -7
  37. package/src/client/ExternalThread.ts +28 -16
  38. package/src/context/providers/MessageProvider.tsx +8 -6
  39. package/src/index.ts +5 -1
  40. package/src/legacy-runtime/AssistantRuntimeProvider.tsx +13 -3
  41. package/src/legacy-runtime/runtime-cores/assistant-transport/runManager.ts +14 -1
  42. package/src/legacy-runtime/runtime-cores/assistant-transport/transport-scheduling.test.ts +38 -0
  43. package/src/legacy-runtime/runtime-cores/assistant-transport/types.ts +11 -1
  44. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransport.spec.md +7 -0
  45. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.test.tsx +321 -0
  46. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.ts +88 -18
  47. package/src/primitives/actionBar/ActionBarExportMarkdown.tsx +1 -1
  48. package/src/primitives/attachment/AttachmentThumb.test.tsx +70 -0
  49. package/src/primitives/attachment/AttachmentThumb.tsx +8 -4
  50. package/src/primitives/composer/ComposerInput.test.tsx +53 -2
  51. package/src/primitives/composer/ComposerInput.tsx +3 -0
  52. package/src/primitives/queueItem/QueueItemText.tsx +8 -2
  53. package/src/primitives/selectionToolbar/SelectionToolbarRoot.test.tsx +74 -0
  54. package/src/primitives/selectionToolbar/SelectionToolbarRoot.tsx +3 -3
  55. package/src/tests/external-thread-parity.test.tsx +9 -4
  56. package/src/tests/local-runtime-queue.test.tsx +199 -6
  57. package/src/utils/createActionButton.test.tsx +18 -0
  58. 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) onFinishRef.current?.();
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","error","Error","setIsRunning","stateRef","pending","disposed","abortController","AbortController","onRunRef","onFinishRef","onCancelRef","onErrorRef","startRun","current","ac","disposeAborted","reason","queueMicrotask","aborted","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\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 onFinishRef.current?.();\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,SAAgBC,cAAcC,QAKf;CACb,MAAM,CAACN,WAAWgB,gBAAgBpB,SAAS,KAAK;CAChD,MAAMqB,WAAWtB,OAAO;EACtBuB,SAAS;EACTC,UAAU;EACVC,iBAAiB;CACnB,CAAC;CACD,MAAME,WAAWzB,aAAaS,OAAOC,KAAK;CAC1C,MAAMgB,cAAc1B,aAAaS,OAAOK,QAAQ;CAChD,MAAMa,cAAc3B,aAAaS,OAAOM,QAAQ;CAChD,MAAMa,aAAa5B,aAAaS,OAAOO,OAAO;CAE9C,MAAMa,WAAWjC,kBAAkB;EACjCuB,aAAa,IAAI;EACjBC,SAASU,QAAQT,UAAU;EAC3B,MAAMU,KAAK,IAAIP,gBAAgB;EAC/BJ,SAASU,QAAQP,kBAAkBQ;EAInC,MAAMC,uBAAuBD,GAAGpB,OAAOsB,WAAW3B;EAElD4B,eAAe,YAAY;GACzB,IAAI;IACF,IAAI,CAACF,eAAe,GAClB,MAAMP,SAASK,QAAQC,GAAGpB,MAAM;GAEpC,SAASM,OAAO;IACd,IAAI,CAACe,eAAe,KAAK,CAACZ,SAASU,QAAQR,UAAU;KACnDF,SAASU,QAAQT,UAAU;KAC3B,IAAIU,GAAGpB,OAAOwB,SACZR,YAAYG,UAAU;UAEtB,MAAMF,WAAWE,UAAUb,KAAc;IAE7C;GACF,UAAU;IACR,IAAI,CAACe,eAAe,KAAK,CAACZ,SAASU,QAAQR,UACzCI,YAAYI,UAAU;IAExB,IAAI,CAACV,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,MAAMvB,WAAWR,kBAAkB;EACjC,IAAIwB,SAASU,QAAQR,UAAU;EAC/B,IAAIF,SAASU,QAAQP,iBAAiB;GAEpCH,SAASU,QAAQT,UAAU;GAC3B;EACF;EACAQ,SAAS;CACX,GAAG,CAACA,QAAQ,CAAC;CAIbhC,gBAAgB;EACduB,SAASU,QAAQR,WAAW;EAC5B,aAAa;GACXF,SAASU,QAAQR,WAAW;GAC5BF,SAASU,QAAQT,UAAU;GAC3BD,SAASU,QAAQP,iBAAiBa,MAAM9B,aAAa;EACvD;CACF,GAAG,CAAA,CAAE;CAOL,OAAO;EACLH;EACAC;EACAC,QARaT,kBAAkB;GAC/BwB,SAASU,QAAQT,UAAU;GAC3BD,SAASU,QAAQP,iBAAiBa,MAAM;EAC1C,GAAG,CAAA,CAKD/B;CACF;AACF"}
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.ab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AS;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
- state: unknown;
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,7 +71,15 @@ 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;
77
+ /**
78
+ * When `false`, stream decoding and state reconciliation tolerate malformed
79
+ * input (invalid chunks are dropped with a console log) instead of throwing.
80
+ * Resume runs always decode leniently. Defaults to `true`.
81
+ */
82
+ strict?: boolean;
73
83
  converter: AssistantTransportStateConverter<T>;
74
84
  headers: HeadersValue | (() => Promise<HeadersValue>);
75
85
  body?: object | (() => Promise<object | undefined>);
@@ -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;EACV;EACA;EACA,OAAO;EACP,cAAc;EACd,QAAQ;EACR;EACA;GAIC;;KAGS,0BAA0B;EACpC,cAAc;EACd;EACA;EACA,WAAW;EACX,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"}
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"}
@@ -1 +1 @@
1
- {"version":3,"file":"useAssistantTransportRuntime.d.ts","names":[],"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.ts"],"mappings":";;;;cA8Fa,yCAGH,SAAS;iBAOH,8BAA8B;iBAC9B,2BAA2B,GACzC,WAAW,OAAO,sBAAsB,IACvC;;;;cA6RU,+BAAgC,GAC3C,SAAS,0BAA0B,OAClC"}
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"}
@@ -24,6 +24,7 @@ const convertAppendMessageToCommand = (message) => {
24
24
  type: "image",
25
25
  image: contentPart.image
26
26
  });
27
+ if (parts.length === 0) return null;
27
28
  return {
28
29
  type: "add-message",
29
30
  message: {
@@ -34,6 +35,21 @@ const convertAppendMessageToCommand = (message) => {
34
35
  sourceId: message.sourceId
35
36
  };
36
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
+ };
37
53
  const symbolAssistantTransportExtras = Symbol("assistant-transport-extras");
38
54
  const asAssistantTransportExtras = (extras) => {
39
55
  if (typeof extras !== "object" || extras == null || !(symbolAssistantTransportExtras in extras)) throw new Error("This method can only be called when you are using useAssistantTransportRuntime");
@@ -64,6 +80,15 @@ const useAssistantTransportThreadRuntime = (options) => {
64
80
  const waitForReplayRender = useReplayRenderWait();
65
81
  const parentIdRef = useRef(void 0);
66
82
  const commandQueue = useCommandQueue({ onQueue: () => runManager.schedule() });
83
+ const enqueueAppendMessage = (message) => {
84
+ const command = convertAppendMessageToCommand(message);
85
+ if (!command) {
86
+ console.warn("[assistant-ui] Skipped add-message command with no supported parts");
87
+ return;
88
+ }
89
+ parentIdRef.current = message.parentId;
90
+ commandQueue.enqueue(command, { schedule: message.startRun ?? message.role === "user" });
91
+ };
67
92
  const threadId = useAuiState((s) => s.threadListItem.remoteId);
68
93
  const runManager = useRunManager({
69
94
  onRun: async (signal) => {
@@ -75,11 +100,26 @@ const useAssistantTransportThreadRuntime = (options) => {
75
100
  const parentId = isResume ? void 0 : parentIdRef.current;
76
101
  if (!isResume) parentIdRef.current = void 0;
77
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
+ }
78
118
  const bodyValue = typeof options.body === "function" ? await options.body() : options.body;
79
119
  const context = runtime.thread.getModelContext();
80
120
  let requestBody = {
81
121
  commands,
82
- state: agentStateRef.current,
122
+ ...resumeState === void 0 && { state: agentStateRef.current },
83
123
  system: context.system,
84
124
  tools: context.tools ? toToolsJSONSchema(context.tools) : void 0,
85
125
  threadId,
@@ -91,6 +131,13 @@ const useAssistantTransportThreadRuntime = (options) => {
91
131
  ...bodyValue ?? {}
92
132
  };
93
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
+ }
94
141
  const response = await fetch(isResume ? options.resumeApi : options.api, {
95
142
  method: "POST",
96
143
  headers,
@@ -100,15 +147,22 @@ const useAssistantTransportThreadRuntime = (options) => {
100
147
  options.onResponse?.(response);
101
148
  if (!response.ok) throw new Error(`Status ${response.status}: ${await response.text()}`);
102
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
+ }
103
154
  const body = await createReplayBoundaryStream(response, {
104
155
  setReplaying: setIsReplaying,
105
156
  waitForRender: waitForReplayRender
106
157
  });
107
- const decoder = (options.protocol ?? "data-stream") === "assistant-transport" ? new AssistantTransportDecoder() : new DataStreamDecoder();
158
+ const protocol = options.protocol ?? "data-stream";
159
+ const strict = isResume ? false : options.strict ?? true;
160
+ const decoder = protocol === "assistant-transport" ? new AssistantTransportDecoder({ strict }) : new DataStreamDecoder({ strict });
108
161
  let err;
109
162
  const stream = body.pipeThrough(decoder).pipeThrough(new AssistantMessageAccumulator({
110
163
  initialMessage: unstable_createInitialMessage({ unstable_state: agentStateRef.current ?? null }),
111
164
  throttle: isResume,
165
+ strict,
112
166
  onError: (error) => {
113
167
  err = error;
114
168
  }
@@ -136,7 +190,7 @@ const useAssistantTransportThreadRuntime = (options) => {
136
190
  commands: cmds,
137
191
  updateState: (updater) => {
138
192
  agentStateRef.current = updater(agentStateRef.current);
139
- rerender((prev) => prev + 1);
193
+ rerender((prev_0) => prev_0 + 1);
140
194
  }
141
195
  });
142
196
  },
@@ -178,21 +232,13 @@ const useAssistantTransportThreadRuntime = (options) => {
178
232
  setToolStatuses,
179
233
  extras: {
180
234
  [symbolAssistantTransportExtras]: true,
181
- sendCommand: (command) => {
182
- commandQueue.enqueue(command);
235
+ sendCommand: (command_0) => {
236
+ commandQueue.enqueue(command_0);
183
237
  },
184
238
  state: agentStateRef.current
185
239
  },
186
- onNew: async (message) => {
187
- parentIdRef.current = message.parentId;
188
- const command_0 = convertAppendMessageToCommand(message);
189
- commandQueue.enqueue(command_0, { schedule: message.startRun ?? message.role === "user" });
190
- },
191
- ...options.capabilities?.edit && { onEdit: async (message_0) => {
192
- parentIdRef.current = message_0.parentId;
193
- const command_1 = convertAppendMessageToCommand(message_0);
194
- commandQueue.enqueue(command_1, { schedule: message_0.startRun ?? message_0.role === "user" });
195
- } },
240
+ onNew: async (message_0) => enqueueAppendMessage(message_0),
241
+ ...options.capabilities?.edit && { onEdit: async (message_1) => enqueueAppendMessage(message_1) },
196
242
  ...commandQueue.state.queued.length > 0 && { onReload: async (parentId_0) => {
197
243
  parentIdRef.current = parentId_0;
198
244
  runManager.schedule();
@@ -206,7 +252,7 @@ const useAssistantTransportThreadRuntime = (options) => {
206
252
  runManager.schedule();
207
253
  },
208
254
  onAddToolResult: async (toolOptions) => {
209
- const command_2 = {
255
+ const command_1 = {
210
256
  type: "add-tool-result",
211
257
  toolCallId: toolOptions.toolCallId,
212
258
  result: toolOptions.result,
@@ -215,11 +261,11 @@ const useAssistantTransportThreadRuntime = (options) => {
215
261
  ...toolOptions.artifact && { artifact: toolOptions.artifact },
216
262
  ...toolOptions.modelContent !== void 0 && { modelContent: toolOptions.modelContent }
217
263
  };
218
- commandQueue.enqueue(command_2);
264
+ commandQueue.enqueue(command_1);
219
265
  },
220
266
  onLoadExternalState: async (state) => {
221
267
  agentStateRef.current = state;
222
- rerender((prev_0) => prev_0 + 1);
268
+ rerender((prev_1) => prev_1 + 1);
223
269
  }
224
270
  });
225
271
  return runtime;
@@ -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","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","threadId","threadListItem","remoteId","onRun","signal","AbortSignal","isResume","current","commands","flush","length","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","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","enqueue","onNew","Promise","startRun","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 => {\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 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 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 const decoder =\n protocol === \"assistant-transport\"\n ? new AssistantTransportDecoder()\n : new DataStreamDecoder();\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 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 parentIdRef.current = message.parentId;\n const command = convertAppendMessageToCommand(message);\n commandQueue.enqueue(command, {\n schedule: message.startRun ?? message.role === \"user\",\n });\n },\n ...(options.capabilities?.edit && {\n onEdit: async (message: AppendMessage): Promise<void> => {\n parentIdRef.current = message.parentId;\n const command = convertAppendMessageToCommand(message);\n commandQueue.enqueue(command, {\n schedule: message.startRun ?? message.role === \"user\",\n });\n },\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,YACsB;CACtB,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,OAAO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CqJ,cAAc;CAChB,CACO/E;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"],"mappings":";;;;;;;;;;;;;;AA0CA,MAAMqC,iCACJC,YAC6B;CAC7B,IAAIA,QAAQC,SAAS,QACn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D,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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AAClC,QAAQmC,SAAU,eAClBD,EAAClC,QAAQoC,QAAa/B,SAAK,cAC7B6B,EAAClC,QAAQqC,MAAMC,KAAMP,KAA6C;AAAC"}
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;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,KA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AA,IAAAtC,EAAA,QAAAmC,WAAAnC,EAAA,QAAAqC,IAAA;EAFQC,KAAA5C,qBAAqByC,SAASE,EAEtC;EAACrC,EAAA,MAAAmC;EAAAnC,EAAA,MAAAqC;EAAArC,EAAA,MAAAsC;CAAA,OAAAA,KAAAtC,EAAA;CAAA,IAAAuC;CAAA,IAAAvC,EAAA,QAAAiC,gBAAAjC,EAAA,QAAAoC,SAAApC,EAAA,QAAAQ,MAAAR,EAAA,QAAAsC,IAAA;EAPJC,KAAA,oBAAA,UAAA,QAAA;GACO,MAAA;GAAQ,GACTH;GACCH,KAAAA;GACK,UAAAzB;GACD,SAAA8B;EAEP,CAAA;EACFtC,EAAA,MAAAiC;EAAAjC,EAAA,MAAAoC;EAAApC,EAAA,MAAAQ;EAAAR,EAAA,MAAAsC;EAAAtC,EAAA,MAAAuC;CAAA,OAAAA,KAAAvC,EAAA;CAAA,OARFuC;AAQE,CAEL;AAEDV,iCAAiCW,cAC/B;AA9DiC,SAAAC,MAAApD,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;;;;oBAanC,cAAA,0CAAA,cAAA"}
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 { jsxs } from "react/jsx-runtime";
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 ext = useAuiState(_temp);
11
- let t0;
12
- if ($[0] !== ext || $[1] !== props || $[2] !== ref) {
13
- t0 = /* @__PURE__ */ jsxs(Primitive.div, {
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: [".", ext]
17
+ children: t0
17
18
  });
18
- $[0] = ext;
19
- $[1] = props;
20
- $[2] = ref;
21
- $[3] = t0;
22
- } else t0 = $[3];
23
- return t0;
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 parts = s.attachment.name.split(".");
28
- return parts.length > 1 ? parts.pop() : "";
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","$","ext","_temp","t0","displayName","s","parts","attachment","name","split","length","pop"],"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 ext = useAuiState((s) => {\n const parts = s.attachment.name.split(\".\");\n return parts.length > 1 ? parts.pop()! : \"\";\n });\n return (\n <Primitive.div {...props} ref={ref}>\n .{ext}\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,MAAYV,YAAYW,KAGvB;CAAE,IAAAC;CAAA,IAAAH,EAAA,OAAAC,OAAAD,EAAA,OAAAF,SAAAE,EAAA,OAAAD,KAAA;EAEDI,KAAA,qBAAA,UAAA,KAAA;GAAA,GAAmBL;GAAYC;GAA/B,UAAA,CAAoC,KAChCE,GACJ;;EAAgBD,EAAA,KAAAC;EAAAD,EAAA,KAAAF;EAAAE,EAAA,KAAAD;EAAAC,EAAA,KAAAG;CAAA,OAAAA,KAAAH,EAAA;CAAA,OAFhBG;AAEgB,CAEnB;AAEDR,yBAAyBS,cAAc;AAZrC,SAAAF,MAAAG,GAAA;CAEE,MAAAC,QAAcD,EAACE,WAAWC,KAAKC,MAAO,GAAG;CAAE,OACpCH,MAAKI,SAAU,IAAIJ,MAAKK,IAAW,IAAnC;AAAoC"}
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
  }