@marimo-team/islands 0.19.8-dev5 → 0.19.8-dev50

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 (147) hide show
  1. package/dist/{Combination-Bg-xN8JV.js → Combination-BTMrlhzT.js} +11 -10
  2. package/dist/{ConnectedDataExplorerComponent-DewsKLl2.js → ConnectedDataExplorerComponent-BAeQ8DWw.js} +11 -11
  3. package/dist/{ImageComparisonComponent-Bijp8beW.js → ImageComparisonComponent-DkEXPki_.js} +2 -2
  4. package/dist/{any-language-editor-DZc6NCTp.js → any-language-editor-D0UQItkS.js} +6 -6
  5. package/dist/{architectureDiagram-VXUJARFQ--NkyBn9Y.js → architectureDiagram-VXUJARFQ-DPPYVq8H.js} +4 -4
  6. package/dist/assets/__vite-browser-external-WSlCcXn_.js +1 -0
  7. package/dist/assets/worker-DUYMdbtA.js +73 -0
  8. package/dist/{blockDiagram-VD42YOAC-DEZZaTW0.js → blockDiagram-VD42YOAC-BA5N05Y9.js} +4 -4
  9. package/dist/{button-BWvsJ2Wr.js → button-Cy0ElmIm.js} +2 -2
  10. package/dist/{c4Diagram-YG6GDRKO-Bj7hwWCO.js → c4Diagram-YG6GDRKO-DJLzuGJJ.js} +3 -3
  11. package/dist/{channel-B_QrFrGg.js → channel-Dob5kWXR.js} +1 -1
  12. package/dist/{check-CM_kewwn.js → check-DkNR52Mm.js} +1 -1
  13. package/dist/{chunk-5FQGJX7Z-D5VFKHmt.js → chunk-5FQGJX7Z-BEb20Lzt.js} +3 -3
  14. package/dist/{chunk-ABZYJK2D-SZPYmRzN.js → chunk-ABZYJK2D-BXTC53mt.js} +1 -1
  15. package/dist/{chunk-ATLVNIR6-BI_WwH1o.js → chunk-ATLVNIR6-BJDjUR_c.js} +1 -1
  16. package/dist/{chunk-B4BG7PRW-BlI9Gm1l.js → chunk-B4BG7PRW-DzmUUpfH.js} +4 -4
  17. package/dist/{chunk-DI55MBZ5-BXxemMn5.js → chunk-DI55MBZ5-gTd3J8Tu.js} +4 -4
  18. package/dist/{chunk-EXTU4WIE-CzWtDV99.js → chunk-EXTU4WIE-DyoOs5QX.js} +1 -1
  19. package/dist/{chunk-JA3XYJ7Z-DQ-2ARfa.js → chunk-JA3XYJ7Z-BGnAIbOP.js} +2 -2
  20. package/dist/{chunk-JZLCHNYA-CVfjf2vv.js → chunk-JZLCHNYA-CIRgweVQ.js} +4 -4
  21. package/dist/{chunk-N4CR4FBY-BCZvQ7Jq.js → chunk-N4CR4FBY-DKSvXAIS.js} +5 -5
  22. package/dist/{chunk-QN33PNHL-DY_2Q2zl.js → chunk-QN33PNHL-B6zC8BTi.js} +1 -1
  23. package/dist/{chunk-QXUST7PY-BMCjAVR_.js → chunk-QXUST7PY-C7750n_u.js} +5 -5
  24. package/dist/{chunk-S3R3BYOJ-Ddu0H4Qa.js → chunk-S3R3BYOJ-CBkH6JZZ.js} +1 -1
  25. package/dist/{chunk-TZMSLE5B-C2wVlbMl.js → chunk-TZMSLE5B-DObGL7xi.js} +1 -1
  26. package/dist/{classDiagram-2ON5EDUG-D-g7zbyO.js → classDiagram-2ON5EDUG-B9pkKjjc.js} +9 -9
  27. package/dist/{classDiagram-v2-WZHVMYZB-C7v5zNRD.js → classDiagram-v2-WZHVMYZB-CRhhA0tV.js} +9 -9
  28. package/dist/{click-outside-container-BCN5BtVO.js → click-outside-container-DNfggvIW.js} +1 -1
  29. package/dist/{code-block-37QAKDTI-eUgXqGNG.js → code-block-37QAKDTI-u5kgjqmr.js} +2 -2
  30. package/dist/{compiler-runtime-DHFVbq0b.js → compiler-runtime-B_OLMU9S.js} +1 -1
  31. package/dist/{copy-B59Bw3-w.js → copy-DRaXIb_a.js} +3 -3
  32. package/dist/{dagre-6UL2VRFP-DKIPL74O.js → dagre-6UL2VRFP-C2C2XxsB.js} +6 -6
  33. package/dist/{data-grid-overlay-editor-COyFwFmE.js → data-grid-overlay-editor-BXqtz1ia.js} +4 -4
  34. package/dist/{diagram-PSM6KHXK-CVTrAZaP.js → diagram-PSM6KHXK-DHBY-94p.js} +5 -5
  35. package/dist/{diagram-QEK2KX5R-BqHBzu3x.js → diagram-QEK2KX5R-CgMshOwn.js} +3 -3
  36. package/dist/{diagram-S2PKOQOG-CJD6owcg.js → diagram-S2PKOQOG-F1KPva3Y.js} +3 -3
  37. package/dist/{dist-Co5PD8Fb.js → dist-BBYTEAvO.js} +1 -1
  38. package/dist/{erDiagram-Q2GNP2WA-CqOceSf9.js → erDiagram-Q2GNP2WA-18gGng8V.js} +9 -9
  39. package/dist/{error-banner-C7KLpECd.js → error-banner-D2zjeN_a.js} +5 -5
  40. package/dist/{esm-D4WO8J3G.js → esm-CgRNPmz8.js} +6 -6
  41. package/dist/{flowDiagram-NV44I4VS-K7-DUifo.js → flowDiagram-NV44I4VS-iHFiHYe0.js} +9 -9
  42. package/dist/{ganttDiagram-JELNMOA3-BwUFY9Nu.js → ganttDiagram-JELNMOA3-D7GixxiF.js} +2 -2
  43. package/dist/{gitGraphDiagram-NY62KEGX-CjGRtLb1.js → gitGraphDiagram-NY62KEGX-CJFHytRK.js} +2 -2
  44. package/dist/{glide-data-editor-C3T7HsLi.js → glide-data-editor-BYwb17Bf.js} +13 -13
  45. package/dist/{infoDiagram-WHAUD3N6-DNhmDn-6.js → infoDiagram-WHAUD3N6-B5Lkh3A9.js} +2 -2
  46. package/dist/{journeyDiagram-XKPGCS4Q-BOdK47P8.js → journeyDiagram-XKPGCS4Q-CV_9R9iP.js} +2 -2
  47. package/dist/{kanban-definition-3W4ZIXB7-A0JC9d0g.js → kanban-definition-3W4ZIXB7-Dp21D5Ym.js} +6 -6
  48. package/dist/{katex-DJyOeQ91.js → katex-CX2BKujk.js} +1 -1
  49. package/dist/{katex-Dm9nZf6A.js → katex-Db0k5oV_.js} +1 -1
  50. package/dist/{label-C4PtQcza.js → label-CxU5JNBW.js} +6 -6
  51. package/dist/main.js +2000 -1887
  52. package/dist/mermaid-4DMBBIKO-BhDCqnO1.js +6 -0
  53. package/dist/{mermaid-Bqp2Xw99.js → mermaid-B__BZSXU.js} +39 -39
  54. package/dist/{mhchem-BqdXeZVX.js → mhchem-w1tkUnWr.js} +1 -1
  55. package/dist/{mindmap-definition-VGOIOE7T-CS6nKN_L.js → mindmap-definition-VGOIOE7T-B_5mfdYp.js} +8 -8
  56. package/dist/{number-overlay-editor-Bz_bDJQb.js → number-overlay-editor-D-4WQAGX.js} +2 -2
  57. package/dist/{pieDiagram-ADFJNKIX-DSa60Grk.js → pieDiagram-ADFJNKIX-B-DGEopK.js} +3 -3
  58. package/dist/{quadrantDiagram-AYHSOK5B-CFnMbP2J.js → quadrantDiagram-AYHSOK5B-M_yRSIZn.js} +1 -1
  59. package/dist/{react-DdA8EBol.js → react-Bs6Z0kvn.js} +1 -1
  60. package/dist/{react-dom-DJW8xUDg.js → react-dom-CqtLRVZP.js} +2 -2
  61. package/dist/{react-plotly-jVjTu07w.js → react-plotly-BuRa9xtI.js} +1 -1
  62. package/dist/{react-vega-DgHpnZ04.js → react-vega-3WcLHYC7.js} +2 -2
  63. package/dist/{react-vega-CjiPWyw0.js → react-vega-DLFvGrpJ.js} +1 -1
  64. package/dist/{requirementDiagram-UZGBJVZJ-ytLQrFTk.js → requirementDiagram-UZGBJVZJ-9Wt82hOZ.js} +8 -8
  65. package/dist/{sankeyDiagram-TZEHDZUN-KQqXDoky.js → sankeyDiagram-TZEHDZUN-x_aTXZeN.js} +1 -1
  66. package/dist/{sequenceDiagram-WL72ISMW-ByLI04T5.js → sequenceDiagram-WL72ISMW-CXXmJqiQ.js} +3 -3
  67. package/dist/{slides-component-BVjvNo92.js → slides-component-Dp-y50K9.js} +4 -4
  68. package/dist/{spec-Dmb1KfK3.js → spec-HoYHAQo2.js} +6 -6
  69. package/dist/{stateDiagram-FKZM4ZOC-Dfz8vBbP.js → stateDiagram-FKZM4ZOC-CiSKS_Mx.js} +9 -9
  70. package/dist/{stateDiagram-v2-4FDKWEC3-DRYoLdT5.js → stateDiagram-v2-4FDKWEC3-A43Itnjp.js} +9 -9
  71. package/dist/style.css +1 -1
  72. package/dist/{timeline-definition-IT6M3QCI-CO48XU1B.js → timeline-definition-IT6M3QCI-DR26eWb4.js} +1 -1
  73. package/dist/{types-CzEZ3EWT.js → types-Bb-6p8hv.js} +8 -8
  74. package/dist/{useAsyncData-BjNwqCfS.js → useAsyncData-Dyq3DyOF.js} +3 -3
  75. package/dist/{useDeepCompareMemoize-CfoxVor3.js → useDeepCompareMemoize-BhZZsis0.js} +12 -8
  76. package/dist/{useIframeCapabilities-BBO_R0ww.js → useIframeCapabilities-DurI5SJh.js} +2 -2
  77. package/dist/{useTheme-BYG2SH8J.js → useTheme-SlKl8MlS.js} +5 -6
  78. package/dist/{vega-component-rDX7xwxH.js → vega-component-DCxUyPnb.js} +10 -10
  79. package/dist/{xychartDiagram-PRI3JC2R-CUIfjNVD.js → xychartDiagram-PRI3JC2R-BcVxCRox.js} +4 -4
  80. package/dist/{zod-DITCj31F.js → zod-bjADtMKr.js} +3 -3
  81. package/package.json +18 -18
  82. package/src/components/app-config/ai-config.tsx +11 -2
  83. package/src/components/app-config/optional-features.tsx +1 -1
  84. package/src/components/app-config/user-config-form.tsx +0 -54
  85. package/src/components/chat/__tests__/useFileState.test.tsx +93 -0
  86. package/src/components/chat/acp/__tests__/state.test.ts +69 -0
  87. package/src/components/chat/acp/agent-panel.tsx +26 -77
  88. package/src/components/chat/acp/state.ts +6 -6
  89. package/src/components/chat/chat-components.tsx +114 -1
  90. package/src/components/chat/chat-panel.tsx +79 -134
  91. package/src/components/chat/chat-utils.ts +42 -0
  92. package/src/components/data-table/__tests__/data-table.test.tsx +94 -2
  93. package/src/components/editor/actions/useCellActionButton.tsx +14 -1
  94. package/src/components/editor/ai/add-cell-with-ai.tsx +85 -53
  95. package/src/components/editor/ai/ai-completion-editor.tsx +15 -38
  96. package/src/components/editor/cell/CreateCellButton.tsx +2 -1
  97. package/src/components/editor/cell/code/cell-editor.tsx +12 -0
  98. package/src/components/editor/chrome/panels/packages-panel.tsx +12 -9
  99. package/src/components/editor/database/__tests__/__snapshots__/as-code.test.ts.snap +15 -0
  100. package/src/components/editor/database/__tests__/as-code.test.ts +8 -0
  101. package/src/components/editor/database/as-code.ts +3 -0
  102. package/src/components/editor/database/schemas.ts +9 -0
  103. package/src/components/editor/renderers/cell-array.tsx +2 -1
  104. package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +12 -0
  105. package/src/components/pages/gallery-page.tsx +37 -6
  106. package/src/core/MarimoApp.tsx +12 -8
  107. package/src/core/ai/context/providers/file.ts +1 -1
  108. package/src/core/cells/__tests__/cells.test.ts +120 -0
  109. package/src/core/cells/__tests__/session.test.ts +37 -1
  110. package/src/core/cells/cells.ts +14 -0
  111. package/src/core/cells/session.ts +20 -8
  112. package/src/core/codemirror/language/languages/markdown.ts +7 -0
  113. package/src/core/config/feature-flag.tsx +0 -4
  114. package/src/core/dom/uiregistry.ts +4 -1
  115. package/src/core/islands/__tests__/bridge.test.ts +7 -2
  116. package/src/core/islands/bridge.ts +1 -1
  117. package/src/core/islands/main.ts +7 -0
  118. package/src/core/network/types.ts +2 -2
  119. package/src/core/run-app.tsx +11 -4
  120. package/src/core/static/__tests__/files.test.ts +195 -1
  121. package/src/core/static/files.ts +39 -9
  122. package/src/core/wasm/bridge.ts +1 -1
  123. package/src/core/websocket/useMarimoKernelConnection.tsx +5 -15
  124. package/src/plugins/core/registerReactComponent.tsx +9 -1
  125. package/src/plugins/impl/__tests__/DataTablePlugin.test.tsx +164 -0
  126. package/src/plugins/impl/anywidget/AnyWidgetPlugin.tsx +93 -168
  127. package/src/plugins/impl/anywidget/__tests__/AnyWidgetPlugin.test.tsx +37 -123
  128. package/src/plugins/impl/anywidget/__tests__/model.test.ts +128 -122
  129. package/src/{utils/__tests__/data-views.test.ts → plugins/impl/anywidget/__tests__/serialization.test.ts} +42 -96
  130. package/src/plugins/impl/anywidget/model.ts +348 -223
  131. package/src/plugins/impl/anywidget/schemas.ts +32 -0
  132. package/src/{utils/data-views.ts → plugins/impl/anywidget/serialization.ts} +13 -36
  133. package/src/plugins/impl/anywidget/types.ts +27 -0
  134. package/src/plugins/impl/chat/chat-ui.tsx +22 -20
  135. package/src/utils/Deferred.ts +21 -0
  136. package/src/utils/__tests__/blob.test.ts +3 -3
  137. package/src/utils/__tests__/id-tree.test.ts +22 -7
  138. package/src/utils/__tests__/mime-types.test.ts +8 -10
  139. package/src/utils/__tests__/url-parser.test.ts +22 -0
  140. package/src/utils/blob.ts +14 -27
  141. package/src/utils/id-tree.tsx +11 -19
  142. package/src/utils/json/base64.ts +38 -8
  143. package/src/utils/mime-types.ts +5 -5
  144. package/src/utils/url-parser.ts +1 -1
  145. package/dist/assets/__vite-browser-external-DRa9CT_O.js +0 -1
  146. package/dist/assets/worker-SqntmiwV.js +0 -73
  147. package/dist/mermaid-4DMBBIKO-o3xNphpD.js +0 -6
@@ -0,0 +1,32 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import { z } from "zod";
3
+
4
+ const BufferPathSchema = z.array(z.array(z.union([z.string(), z.number()])));
5
+ const StateSchema = z.record(z.string(), z.any());
6
+
7
+ export const AnyWidgetMessageSchema = z.discriminatedUnion("method", [
8
+ z.object({
9
+ method: z.literal("open"),
10
+ state: StateSchema,
11
+ buffer_paths: BufferPathSchema.optional(),
12
+ }),
13
+ z.object({
14
+ method: z.literal("update"),
15
+ state: StateSchema,
16
+ buffer_paths: BufferPathSchema.optional(),
17
+ }),
18
+ z.object({
19
+ method: z.literal("custom"),
20
+ content: z.any(),
21
+ }),
22
+ z.object({
23
+ method: z.literal("echo_update"),
24
+ buffer_paths: BufferPathSchema,
25
+ state: StateSchema,
26
+ }),
27
+ z.object({
28
+ method: z.literal("close"),
29
+ }),
30
+ ]);
31
+
32
+ export type AnyWidgetMessage = z.infer<typeof AnyWidgetMessageSchema>;
@@ -1,23 +1,23 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
  import { get, set } from "lodash-es";
3
- import { invariant } from "./invariant";
3
+ import { invariant } from "../../../utils/invariant";
4
4
  import {
5
5
  type Base64String,
6
6
  base64ToDataView,
7
7
  dataViewToBase64,
8
- } from "./json/base64";
9
- import { Logger } from "./Logger";
8
+ } from "../../../utils/json/base64";
9
+ import { Logger } from "../../../utils/Logger";
10
+ import type { WireFormat } from "./types";
11
+
12
+ type Path = (string | number)[];
10
13
 
11
14
  /**
12
15
  * Recursively find all DataViews in an object and return their paths.
13
16
  *
14
17
  * This mirrors ipywidgets' _separate_buffers logic.
15
18
  */
16
- function findDataViewPaths(
17
- obj: unknown,
18
- currentPath: (string | number)[] = [],
19
- ): (string | number)[][] {
20
- const paths: (string | number)[][] = [];
19
+ function findDataViewPaths(obj: unknown, currentPath: Path = []): Path[] {
20
+ const paths: Path[] = [];
21
21
 
22
22
  if (obj instanceof DataView) {
23
23
  paths.push(currentPath);
@@ -51,7 +51,7 @@ export function serializeBuffersToBase64<T extends Record<string, unknown>>(
51
51
 
52
52
  const state = structuredClone(inputObject);
53
53
  const buffers: Base64String[] = [];
54
- const bufferPaths: (string | number)[][] = [];
54
+ const bufferPaths: Path[] = [];
55
55
 
56
56
  for (const bufferPath of dataViewPaths) {
57
57
  const dataView = get(inputObject, bufferPath);
@@ -66,31 +66,6 @@ export function serializeBuffersToBase64<T extends Record<string, unknown>>(
66
66
  return { state, buffers, bufferPaths };
67
67
  }
68
68
 
69
- /**
70
- * Wire format for anywidget state with binary data.
71
- * Buffers can be either base64 strings (from network) or DataViews (in-memory).
72
- */
73
- export interface WireFormat<T = Record<string, unknown>> {
74
- state: T;
75
- bufferPaths: (string | number)[][];
76
- buffers: Base64String[];
77
- }
78
-
79
- /**
80
- * Check if an object is in wire format.
81
- */
82
- export function isWireFormat<T = Record<string, unknown>>(
83
- obj: unknown,
84
- ): obj is WireFormat<T> {
85
- return (
86
- obj !== null &&
87
- typeof obj === "object" &&
88
- "state" in obj &&
89
- "bufferPaths" in obj &&
90
- "buffers" in obj
91
- );
92
- }
93
-
94
69
  /**
95
70
  * Decode wire format or insert DataViews at specified paths.
96
71
  *
@@ -103,7 +78,7 @@ export function isWireFormat<T = Record<string, unknown>>(
103
78
  */
104
79
  export function decodeFromWire<T extends Record<string, unknown>>(input: {
105
80
  state: T;
106
- bufferPaths?: (string | number)[][];
81
+ bufferPaths?: Path[];
107
82
  buffers?: readonly (DataView | Base64String)[];
108
83
  }): T {
109
84
  const { state, bufferPaths, buffers } = input;
@@ -121,7 +96,9 @@ export function decodeFromWire<T extends Record<string, unknown>>(input: {
121
96
  );
122
97
  }
123
98
 
124
- const out = structuredClone(state);
99
+ // We should avoid using structuredClone if possible since
100
+ // it can be very slow. If mutability is a concern, we should use a different approach.
101
+ const out = state;
125
102
 
126
103
  for (const [i, bufferPath] of bufferPaths.entries()) {
127
104
  const buffer = buffers?.[i];
@@ -0,0 +1,27 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import type { Base64String } from "@/utils/json/base64";
3
+ import type { TypedString } from "@/utils/typed";
4
+
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
+ export type EventHandler = (...args: any[]) => void;
7
+
8
+ /**
9
+ * Type-safe widget model id.
10
+ */
11
+ export type WidgetModelId = TypedString<"WidgetModelId">;
12
+
13
+ /**
14
+ * AnyWidget model state with buffers.
15
+ */
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ export type ModelState = Record<string | number, any>;
18
+
19
+ /**
20
+ * Wire format for anywidget state with binary data.
21
+ * Buffers can be either base64 strings (from network) or DataViews (in-memory).
22
+ */
23
+ export interface WireFormat<T = Record<string, unknown>> {
24
+ state: T;
25
+ bufferPaths: (string | number)[][];
26
+ buffers: Base64String[];
27
+ }
@@ -16,12 +16,13 @@ import {
16
16
  HelpCircleIcon,
17
17
  PaperclipIcon,
18
18
  RotateCwIcon,
19
- SendIcon,
19
+ SendHorizontalIcon,
20
20
  SettingsIcon,
21
21
  Trash2Icon,
22
22
  X,
23
23
  } from "lucide-react";
24
24
  import React, { useEffect, useRef, useState } from "react";
25
+ import { z } from "zod";
25
26
  import { renderUIMessage } from "@/components/chat/chat-display";
26
27
  import { convertToFileUIPart } from "@/components/chat/chat-utils";
27
28
  import {
@@ -71,6 +72,16 @@ interface Props extends PluginFunctions {
71
72
  host: HTMLElement;
72
73
  }
73
74
 
75
+ const ChatMessageIncomingSchema = z.object({
76
+ type: z.literal("stream_chunk"),
77
+ message_id: z.string(),
78
+ content: z
79
+ .any()
80
+ .nullable()
81
+ .transform((val) => val as UIMessageChunk | null),
82
+ is_final: z.boolean().optional(),
83
+ });
84
+
74
85
  export const Chatbot: React.FC<Props> = (props) => {
75
86
  const [input, setInput] = useState("");
76
87
  const [config, setConfig] = useState<ChatConfig>(props.config);
@@ -252,15 +263,13 @@ export const Chatbot: React.FC<Props> = (props) => {
252
263
  props.host as HTMLElementNotDerivedFromRef,
253
264
  MarimoIncomingMessageEvent.TYPE,
254
265
  (e) => {
255
- const message = e.detail.message;
256
- if (
257
- typeof message !== "object" ||
258
- message === null ||
259
- !("type" in message) ||
260
- message.type !== "stream_chunk"
261
- ) {
266
+ const parsedMessage = ChatMessageIncomingSchema.safeParse(
267
+ e.detail.message,
268
+ );
269
+ if (!parsedMessage.success) {
262
270
  return;
263
271
  }
272
+ const message = parsedMessage.data;
264
273
 
265
274
  // Push to the stream for useChat to process
266
275
  const controller = frontendStreamControllerRef.current;
@@ -268,17 +277,10 @@ export const Chatbot: React.FC<Props> = (props) => {
268
277
  return;
269
278
  }
270
279
 
271
- const frontendMessage = message as {
272
- type: string;
273
- message_id: string;
274
- content?: UIMessageChunk;
275
- is_final?: boolean;
276
- };
277
-
278
- if (frontendMessage.content) {
279
- controller.enqueue(frontendMessage.content);
280
+ if (message.content) {
281
+ controller.enqueue(message.content);
280
282
  }
281
- if (frontendMessage.is_final) {
283
+ if (message.is_final) {
282
284
  controller.close();
283
285
  frontendStreamControllerRef.current = null;
284
286
  }
@@ -559,10 +561,10 @@ export const Chatbot: React.FC<Props> = (props) => {
559
561
  type="submit"
560
562
  disabled={isLoading || !input}
561
563
  variant="outline"
562
- size="sm"
564
+ size="xs"
563
565
  className="text-(--slate-11)"
564
566
  >
565
- <SendIcon className="h-5 w-5" />
567
+ <SendHorizontalIcon className="h-4 w-4" />
566
568
  </Button>
567
569
  </form>
568
570
  </div>
@@ -1,9 +1,17 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ /**
4
+ * A deferred promise that can be resolved or rejected externally.
5
+ *
6
+ * Provides synchronous access to status and resolved value, useful for
7
+ * cases where you need to check if a promise has settled without awaiting it.
8
+ */
2
9
  export class Deferred<T> {
3
10
  promise: Promise<T>;
4
11
  resolve!: (value: T | PromiseLike<T>) => void;
5
12
  reject!: (reason?: unknown) => void;
6
13
  status: "pending" | "resolved" | "rejected" = "pending";
14
+ value: T | undefined = undefined;
7
15
 
8
16
  constructor() {
9
17
  this.promise = new Promise<T>((resolve, reject) => {
@@ -13,8 +21,21 @@ export class Deferred<T> {
13
21
  };
14
22
  this.resolve = (value) => {
15
23
  this.status = "resolved";
24
+ // Store the value for synchronous access
25
+ if (!isPromiseLike(value)) {
26
+ this.value = value;
27
+ }
16
28
  resolve(value);
17
29
  };
18
30
  });
19
31
  }
20
32
  }
33
+
34
+ function isPromiseLike(value: unknown): value is PromiseLike<unknown> {
35
+ return (
36
+ typeof value === "object" &&
37
+ value !== null &&
38
+ "then" in value &&
39
+ typeof value.then === "function"
40
+ );
41
+ }
@@ -20,7 +20,7 @@ describe("Blob serialization and deserialization", () => {
20
20
 
21
21
  test("deserializeBlob should deserialize a base64 string to a Blob", async () => {
22
22
  const serialized = await serializeBlob(testBlob);
23
- const deserialized = await deserializeBlob(serialized);
23
+ const deserialized = deserializeBlob(serialized);
24
24
  expect(deserialized).toBeDefined();
25
25
  expect(deserialized.size).toBe(testBlob.size);
26
26
  expect(deserialized.type).toBe(testBlob.type);
@@ -28,7 +28,7 @@ describe("Blob serialization and deserialization", () => {
28
28
 
29
29
  test("deserialized Blob should contain the original content", async () => {
30
30
  const serialized = await serializeBlob(testBlob);
31
- const deserialized = await deserializeBlob(serialized);
31
+ const deserialized = deserializeBlob(serialized);
32
32
  const reader = new FileReader();
33
33
  // eslint-disable-next-line unicorn/prefer-blob-reading-methods
34
34
  reader.readAsText(deserialized);
@@ -45,7 +45,7 @@ describe("Blob serialization and deserialization", () => {
45
45
  type: "image/png",
46
46
  });
47
47
  const serialized = await serializeBlob(imageBlob);
48
- const deserialized = await deserializeBlob(serialized);
48
+ const deserialized = deserializeBlob(serialized);
49
49
  expect(deserialized).toBeDefined();
50
50
  expect(deserialized.size).toBe(imageBlob.size);
51
51
  expect(deserialized.type).toBe(imageBlob.type);
@@ -214,16 +214,19 @@ describe("CollapsibleTree", () => {
214
214
  `);
215
215
  });
216
216
 
217
- it("fails to expand", () => {
217
+ it("fails to expand when node not found", () => {
218
218
  expect(() => tree.expand("five")).toThrowErrorMatchingInlineSnapshot(
219
219
  "[Error: Node five not found in tree. Valid ids: one,two,three,four]",
220
220
  );
221
- expect(() => {
222
- tree.expand("one");
223
- tree.expand("one");
224
- }).toThrowErrorMatchingInlineSnapshot(
225
- "[Error: Node one is already expanded]",
226
- );
221
+ });
222
+
223
+ it("expand on already expanded node is a no-op", () => {
224
+ // Expanding an already expanded node should return the same tree (no-op)
225
+ const result = tree.expand("one");
226
+ expect(result).toBe(tree);
227
+ // Can call multiple times without error
228
+ const result2 = tree.expand("one");
229
+ expect(result2).toBe(tree);
227
230
  });
228
231
 
229
232
  it("moves nodes correctly", () => {
@@ -378,6 +381,18 @@ describe("CollapsibleTree", () => {
378
381
  `);
379
382
  });
380
383
 
384
+ it("can delete non-collapsed nodes without throwing", () => {
385
+ // Deleting a non-collapsed node should not throw
386
+ // (previously this would throw "Node is already expanded" internally)
387
+ const result = tree.deleteAtIndex(1);
388
+ expect(result.toString()).toMatchInlineSnapshot(`
389
+ "one
390
+ three
391
+ four
392
+ "
393
+ `);
394
+ });
395
+
381
396
  it("fails to delete nodes", () => {
382
397
  expect(() => tree.deleteAtIndex(5)).toThrowErrorMatchingInlineSnapshot(
383
398
  "[Error: Node at index 5 not found in tree]",
@@ -132,7 +132,7 @@ describe("mime-types", () => {
132
132
 
133
133
  describe("sortByPrecedence", () => {
134
134
  it("should sort entries by precedence order", () => {
135
- const entries: Array<[MimeType, string]> = [
135
+ const entries: [MimeType, string][] = [
136
136
  ["text/plain", "plain"],
137
137
  ["text/html", "html"],
138
138
  ["image/png", "png"],
@@ -151,7 +151,7 @@ describe("mime-types", () => {
151
151
  });
152
152
 
153
153
  it("should place unknown mime types at the end", () => {
154
- const entries: Array<[MimeType, string]> = [
154
+ const entries: [MimeType, string][] = [
155
155
  ["text/plain", "plain"],
156
156
  ["text/html", "html"],
157
157
  ["application/json", "json"],
@@ -173,7 +173,7 @@ describe("mime-types", () => {
173
173
  });
174
174
 
175
175
  it("should handle empty precedence", () => {
176
- const entries: Array<[MimeType, string]> = [
176
+ const entries: [MimeType, string][] = [
177
177
  ["text/plain", "plain"],
178
178
  ["text/html", "html"],
179
179
  ];
@@ -184,7 +184,7 @@ describe("mime-types", () => {
184
184
  });
185
185
 
186
186
  it("should not mutate original array", () => {
187
- const entries: Array<[MimeType, string]> = [
187
+ const entries: [MimeType, string][] = [
188
188
  ["text/plain", "plain"],
189
189
  ["text/html", "html"],
190
190
  ];
@@ -198,7 +198,7 @@ describe("mime-types", () => {
198
198
 
199
199
  describe("processMimeBundle", () => {
200
200
  it("should filter and sort mime entries", () => {
201
- const entries: Array<[MimeType, string]> = [
201
+ const entries: [MimeType, string][] = [
202
202
  ["text/plain", "plain"],
203
203
  ["text/html", "html"],
204
204
  ["image/png", "png"],
@@ -226,7 +226,7 @@ describe("mime-types", () => {
226
226
  });
227
227
 
228
228
  it("should use default config when not provided", () => {
229
- const entries: Array<[MimeType, string]> = [
229
+ const entries: [MimeType, string][] = [
230
230
  ["text/html", "html"],
231
231
  ["image/png", "png"],
232
232
  ["text/markdown", "md"],
@@ -240,9 +240,7 @@ describe("mime-types", () => {
240
240
 
241
241
  it("should preserve data associated with mime types", () => {
242
242
  const htmlData = { content: "<h1>Hello</h1>" };
243
- const entries: Array<[MimeType, typeof htmlData]> = [
244
- ["text/html", htmlData],
245
- ];
243
+ const entries: [MimeType, typeof htmlData][] = [["text/html", htmlData]];
246
244
 
247
245
  const result = processMimeBundle(entries);
248
246
 
@@ -250,7 +248,7 @@ describe("mime-types", () => {
250
248
  });
251
249
 
252
250
  it("should sort by precedence after filtering", () => {
253
- const entries: Array<[MimeType, string]> = [
251
+ const entries: [MimeType, string][] = [
254
252
  ["text/plain", "plain"],
255
253
  ["text/markdown", "md"],
256
254
  ["text/html", "html"],
@@ -76,4 +76,26 @@ describe("parseContent", () => {
76
76
  url: "https://avatars.githubusercontent.com/u/123",
77
77
  });
78
78
  });
79
+
80
+ it("preserves newlines between URLs", () => {
81
+ const parts = parseContent("https://marimo.io\nhttps://github.com\n");
82
+ expect(parts).toEqual([
83
+ { type: "url", url: "https://marimo.io" },
84
+ { type: "text", value: "\n" },
85
+ { type: "url", url: "https://github.com" },
86
+ { type: "text", value: "\n" },
87
+ ]);
88
+ });
89
+
90
+ it("preserves whitespace in mixed content", () => {
91
+ const parts = parseContent(
92
+ "Line 1: https://marimo.io\nLine 2: https://github.com",
93
+ );
94
+ expect(parts).toEqual([
95
+ { type: "text", value: "Line 1: " },
96
+ { type: "url", url: "https://marimo.io" },
97
+ { type: "text", value: "\nLine 2: " },
98
+ { type: "url", url: "https://github.com" },
99
+ ]);
100
+ });
79
101
  });
package/src/utils/blob.ts CHANGED
@@ -14,32 +14,19 @@ export function serializeBlob<T>(blob: Blob): Promise<DataURLString> {
14
14
  });
15
15
  }
16
16
 
17
- export function deserializeBlob(serializedBlob: DataURLString): Promise<Blob> {
18
- return new Promise((resolve, reject) => {
19
- try {
20
- // Extract the base64 data from the data URL
21
- const [prefix, base64Data] = serializedBlob.split(",", 2);
22
- const mimeType = /^data:(.+);base64$/.exec(prefix)?.[1];
23
- // Decode the base64 string
24
- const binaryString = atob(base64Data);
25
- // Convert the binary string to an array buffer
26
- const len = binaryString.length;
27
- const bytes = new Uint8Array(len);
28
- for (let i = 0; i < len; i++) {
29
- bytes[i] = binaryString.charCodeAt(i);
30
- }
31
- // Create a new Blob from the array buffer
32
- const blob = new Blob([bytes], { type: mimeType });
33
- resolve(blob);
34
- } catch (error) {
35
- reject(ensureError(error));
36
- }
37
- });
38
- }
39
-
40
- function ensureError(error: unknown): Error {
41
- if (error instanceof Error) {
42
- return error;
17
+ export function deserializeBlob(serializedBlob: DataURLString): Blob {
18
+ // Extract the base64 data from the data URL
19
+ const [prefix, base64Data] = serializedBlob.split(",", 2);
20
+ const mimeType = /^data:(.+);base64$/.exec(prefix)?.[1];
21
+ // Decode the base64 string
22
+ const binaryString = atob(base64Data);
23
+ // Convert the binary string to an array buffer
24
+ const len = binaryString.length;
25
+ const bytes = new Uint8Array(len);
26
+ for (let i = 0; i < len; i++) {
27
+ bytes[i] = binaryString.charCodeAt(i);
43
28
  }
44
- return new Error(`${error}`);
29
+ // Create a new Blob from the array buffer
30
+ const blob = new Blob([bytes], { type: mimeType });
31
+ return blob;
45
32
  }
@@ -360,7 +360,8 @@ export class CollapsibleTree<T> {
360
360
  }
361
361
 
362
362
  /**
363
- * Expand a node and all of its children
363
+ * Expand a node and all of its children.
364
+ * If the node is already expanded, returns the same tree (no-op).
364
365
  */
365
366
  expand(id: T): CollapsibleTree<T> {
366
367
  const nodeIndex = this.nodes.findIndex((n) => n.value === id);
@@ -373,7 +374,8 @@ export class CollapsibleTree<T> {
373
374
  let nodes = [...this.nodes];
374
375
  const node = nodes[nodeIndex];
375
376
  if (!node.isCollapsed) {
376
- throw new Error(`Node ${id} is already expanded`);
377
+ // Already expanded, no-op
378
+ return this;
377
379
  }
378
380
 
379
381
  nodes[nodeIndex] = new TreeNode(node.value, false, []);
@@ -495,13 +497,9 @@ export class CollapsibleTree<T> {
495
497
  */
496
498
  deleteAtIndex(idx: number): CollapsibleTree<T> {
497
499
  const id = this.atOrThrow(idx);
498
- let tree = this.withNodes(this.nodes);
499
- try {
500
- tree = tree.expand(id);
501
- } catch {
502
- // Don't care if its not expanded
503
- }
504
- return this.withNodes(arrayDelete(tree.nodes, idx));
500
+ // Expand the node first (if collapsed) to bring children back to top level
501
+ const tree = this.expand(id);
502
+ return tree.withNodes(arrayDelete(tree.nodes, idx));
505
503
  }
506
504
 
507
505
  delete(id: T): CollapsibleTree<T> {
@@ -524,16 +522,10 @@ export class CollapsibleTree<T> {
524
522
  if (found.length === 0) {
525
523
  return this;
526
524
  }
527
- let result = this.withNodes(this.nodes);
528
- for (const node of found) {
529
- try {
530
- result = result.expand(node);
531
- } catch {
532
- // Don't care if its the last node and its not expanded
533
- }
534
- }
535
-
536
- return result;
525
+ return found.reduce<CollapsibleTree<T>>(
526
+ (acc, node) => acc.expand(node),
527
+ this,
528
+ );
537
529
  }
538
530
 
539
531
  /**
@@ -52,13 +52,27 @@ export function extractBase64FromDataURL(str: DataURLString): Base64String {
52
52
  }
53
53
 
54
54
  /**
55
- * Convert a base64 string to a Uint8Array.
55
+ * Convert a base64 string to a Uint8Array (fallback implementation).
56
+ * See benchmarks/base64-conversion.bench.ts for why we use a manual loop.
56
57
  */
57
- export function base64ToUint8Array(bytes: Base64String): Uint8Array {
58
- const binary = window.atob(bytes);
59
- return Uint8Array.from(binary, (c) => c.charCodeAt(0));
58
+ function base64ToUint8ArrayFallback(bytes: string): Uint8Array {
59
+ const binary = globalThis.atob(bytes);
60
+ const len = binary.length;
61
+ const uint8Array = new Uint8Array(len);
62
+ for (let i = 0; i < len; i++) {
63
+ uint8Array[i] = binary.charCodeAt(i);
64
+ }
65
+ return uint8Array;
60
66
  }
61
67
 
68
+ /**
69
+ * Convert a base64 string to a Uint8Array.
70
+ * Uses native Uint8Array.fromBase64 if available, otherwise falls back to manual implementation.
71
+ */
72
+ export const base64ToUint8Array: (bytes: Base64String) => Uint8Array =
73
+ // @ts-expect-error - Uint8Array.fromBase64 types coming in TypeScript 5.10+
74
+ Uint8Array.fromBase64 ?? base64ToUint8ArrayFallback;
75
+
62
76
  /**
63
77
  * Convert a base64 string to a DataView.
64
78
  */
@@ -68,13 +82,29 @@ export function base64ToDataView(bytes: Base64String): DataView {
68
82
  }
69
83
 
70
84
  /**
71
- * Convert a Uint8Array to a base64 string.
85
+ * Convert a Uint8Array to a base64 string (fallback implementation).
86
+ * See benchmarks/uint8array-to-base64.bench.ts for why we use a manual loop.
72
87
  */
73
- export function uint8ArrayToBase64(binary: Uint8Array): Base64String {
74
- const chars = Array.from(binary, (byte) => String.fromCharCode(byte));
75
- return window.btoa(chars.join("")) as Base64String;
88
+ function uint8ArrayToBase64Fallback(binary: Uint8Array): Base64String {
89
+ let binaryString = "";
90
+ const len = binary.length;
91
+ for (let i = 0; i < len; i++) {
92
+ binaryString += String.fromCharCode(binary[i]);
93
+ }
94
+ return globalThis.btoa(binaryString) as Base64String;
76
95
  }
77
96
 
97
+ /**
98
+ * Convert a Uint8Array to a base64 string.
99
+ * Uses native Uint8Array.prototype.toBase64 if available, otherwise falls back to manual implementation.
100
+ */
101
+ export const uint8ArrayToBase64: (binary: Uint8Array) => Base64String =
102
+ // @ts-expect-error - Uint8Array.prototype.toBase64 types coming in TypeScript 5.10+
103
+ Uint8Array.prototype.toBase64
104
+ ? // @ts-expect-error - Uint8Array.prototype.toBase64 types coming in TypeScript 5.10+
105
+ (binary) => binary.toBase64()
106
+ : uint8ArrayToBase64Fallback;
107
+
78
108
  /**
79
109
  * Convert a DataView to a base64 string.
80
110
  */
@@ -26,7 +26,7 @@ export interface MimeTypeConfig {
26
26
  */
27
27
  export interface ProcessedMimeTypes<T> {
28
28
  /** The filtered and sorted mime entries */
29
- entries: Array<[MimeType, T]>;
29
+ entries: [MimeType, T][];
30
30
  /** Mime types that were hidden by rules */
31
31
  hidden: MimeType[];
32
32
  }
@@ -146,9 +146,9 @@ export function applyHidingRules(
146
146
  * Mime types not in the map are placed at the end, preserving their original order.
147
147
  */
148
148
  export function sortByPrecedence<T>(
149
- entries: Array<[MimeType, T]>,
149
+ entries: [MimeType, T][],
150
150
  precedence: ReadonlyMap<MimeType, number>,
151
- ): Array<[MimeType, T]> {
151
+ ): [MimeType, T][] {
152
152
  const unknownPrecedence = precedence.size;
153
153
 
154
154
  return [...entries].sort((a, b) => {
@@ -162,7 +162,7 @@ export function sortByPrecedence<T>(
162
162
  * Main entry point: processes mime entries by applying hiding rules and sorting.
163
163
  */
164
164
  export function processMimeBundle<T>(
165
- entries: Array<[MimeType, T]>,
165
+ entries: [MimeType, T][],
166
166
  config: MimeTypeConfig = getDefaultMimeConfig(),
167
167
  ): ProcessedMimeTypes<T> {
168
168
  if (entries.length === 0) {
@@ -176,6 +176,6 @@ export function processMimeBundle<T>(
176
176
 
177
177
  return {
178
178
  entries: sortedEntries,
179
- hidden: Array.from(hidden),
179
+ hidden: [...hidden],
180
180
  };
181
181
  }
@@ -19,7 +19,7 @@ export function parseContent(text: string): ContentPart[] {
19
19
  return [{ type: "image", url: text }];
20
20
  }
21
21
 
22
- const parts = text.split(urlRegex).filter((part) => part.trim() !== "");
22
+ const parts = text.split(urlRegex).filter((part) => part !== "");
23
23
  return parts.map((part) => {
24
24
  const isUrl = urlRegex.test(part);
25
25
  if (isUrl) {