@marimo-team/islands 0.23.7-dev9 → 0.23.7-dev90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ConnectedDataExplorerComponent-DnRhpPMJ.js → ConnectedDataExplorerComponent-2lBNiUv6.js} +13 -13
- package/dist/{ErrorBoundary-Da4UeYxT.js → ErrorBoundary-D3wrPNma.js} +1 -1
- package/dist/{any-language-editor-DDubl8YH.js → any-language-editor-VWs_7v27.js} +5 -5
- package/dist/assets/__vite-browser-external-CAdMKBac.js +1 -0
- package/dist/assets/worker-CpBbwbQo.js +73 -0
- package/dist/{button-CA5pI2YF.js → button-Dj4BTre0.js} +5 -0
- package/dist/{capabilities-6laDasij.js → capabilities-C9rrYCzf.js} +1 -1
- package/dist/{chat-ui-BmWZZ3mE.js → chat-ui-D3XBept8.js} +625 -233
- package/dist/{check-CFM2mVDr.js → check-BcUIXnUT.js} +1 -1
- package/dist/{code-visibility-CRHzv49w.js → code-visibility-C5NrPsUC.js} +11480 -1992
- package/dist/{copy-TGGAUEWp.js → copy-DLf4aN7I.js} +2 -2
- package/dist/{dist-ESg7xyoD.js → dist-D3ZI9nhS.js} +2 -2
- package/dist/{error-banner-DnBPzEWg.js → error-banner-CVkfBUT3.js} +2 -2
- package/dist/{esm-Dd1z1auZ.js → esm-CWp0KQeK.js} +1 -1
- package/dist/{extends-CzJgxo2J.js → extends-vAi97cpa.js} +4 -4
- package/dist/{formats-CgaK7Gmx.js → formats-Dsy9kkZu.js} +3 -3
- package/dist/{glide-data-editor-B-3A3G02.js → glide-data-editor-DucgdjRo.js} +9 -9
- package/dist/{html-to-image-BwZL1Pkk.js → html-to-image-CpggM7u1.js} +2667 -2408
- package/dist/{input-BAOe64zx.js → input-D4kjoQUB.js} +8 -6
- package/dist/{label-BCWi-Oqu.js → label-BLqV33b1.js} +2 -2
- package/dist/{loader-BvW0-YWZ.js → loader-Dr8Qem8p.js} +1 -1
- package/dist/main.js +1697 -10282
- package/dist/{mermaid-cXSZ1pfD.js → mermaid-DO-Daq7u.js} +5 -5
- package/dist/{process-output-lpVrk7d5.js → process-output-X8TR20AK.js} +3 -3
- package/dist/reveal-component-kMIwe09M.js +7447 -0
- package/dist/{spec-DSIuqd3f.js → spec-hVaaZsY5.js} +4 -4
- package/dist/{strings-B_FOH6eV.js → strings-BiIhGaI8.js} +4 -4
- package/dist/style.css +1 -1
- package/dist/{swiper-component-BHs0PWwp.js → swiper-component-DlD2GU2g.js} +2 -2
- package/dist/{toDate-CHtl9vts.js → toDate-CIpC_34u.js} +33 -20
- package/dist/{tooltip-B0mtKTXm.js → tooltip-DRaMBu06.js} +3 -3
- package/dist/{types-DBtDeUKD.js → types-Dzuoc3LN.js} +1 -1
- package/dist/{useAsyncData-B6hCGywC.js → useAsyncData-C56Khv_R.js} +1 -1
- package/dist/{useDateFormatter-B3mCQMP3.js → useDateFormatter-B_9k85Ex.js} +2 -2
- package/dist/{useDeepCompareMemoize-CmwDuYUH.js → useDeepCompareMemoize-Dt98v2ua.js} +1 -1
- package/dist/{useIframeCapabilities-DbdLoEDm.js → useIframeCapabilities-BkYHTrss.js} +1 -1
- package/dist/{useLifecycle-CjMjllqy.js → useLifecycle-BF6-z62y.js} +3 -3
- package/dist/{useTheme-CByZUW0p.js → useTheme-DykuNHR2.js} +2 -2
- package/dist/{vega-component-C2BYPkfd.js → vega-component-cSdqoAxe.js} +10 -10
- package/dist/{zod-BxdsqRPd.js → zod-BWkcDORu.js} +1 -1
- package/package.json +3 -3
- package/src/components/chat/chat-components.tsx +47 -0
- package/src/components/chat/chat-display.tsx +41 -7
- package/src/components/chat/chat-panel.tsx +37 -10
- package/src/components/chat/chat-utils.ts +42 -20
- package/src/components/chat/reasoning-accordion.tsx +14 -3
- package/src/components/chat/tool-call/shared.ts +13 -0
- package/src/components/chat/tool-call/tool-approval-card.tsx +62 -0
- package/src/components/chat/tool-call/tool-args.tsx +26 -0
- package/src/components/chat/tool-call/tool-call-view.tsx +99 -0
- package/src/components/chat/tool-call/tool-error-card.tsx +81 -0
- package/src/components/chat/tool-call/tool-history-row.tsx +153 -0
- package/src/components/chat/tool-call/tool-result.tsx +101 -0
- package/src/components/data-table/__tests__/column-header.test.ts +3 -1
- package/src/components/data-table/__tests__/column-header.test.tsx +308 -0
- package/src/components/data-table/__tests__/filter-by-values-picker.test.tsx +112 -0
- package/src/components/data-table/__tests__/filter-pill-editor.test.tsx +261 -0
- package/src/components/data-table/__tests__/filters.test.ts +196 -49
- package/src/components/data-table/charts/components/form-fields.tsx +1 -0
- package/src/components/data-table/column-header.tsx +349 -170
- package/src/components/data-table/date-filter-inputs.tsx +325 -0
- package/src/components/data-table/filter-by-values-picker.tsx +70 -9
- package/src/components/data-table/filter-pill-editor.tsx +410 -156
- package/src/components/data-table/filter-pills.tsx +69 -54
- package/src/components/data-table/filters.ts +218 -101
- package/src/components/data-table/header-items.tsx +8 -1
- package/src/components/data-table/operator-labels.ts +25 -0
- package/src/components/data-table/regex-input.tsx +61 -0
- package/src/components/dependency-graph/minimap-content.tsx +14 -3
- package/src/components/editor/actions/pair-with-agent-modal.tsx +140 -49
- package/src/components/editor/actions/useNotebookActions.tsx +3 -1
- package/src/components/editor/app-container.tsx +7 -1
- package/src/components/editor/chrome/panels/context-aware-panel/context-aware-panel.tsx +10 -2
- package/src/components/editor/chrome/wrapper/app-chrome.tsx +1 -0
- package/src/components/editor/chrome/wrapper/footer-items/backend-status.tsx +1 -1
- package/src/components/editor/chrome/wrapper/footer.tsx +4 -1
- package/src/components/editor/chrome/wrapper/panels.tsx +4 -1
- package/src/components/editor/chrome/wrapper/sidebar.tsx +4 -1
- package/src/components/editor/controls/Controls.tsx +11 -3
- package/src/components/editor/file-tree/file-explorer.tsx +12 -2
- package/src/components/editor/header/__tests__/status.test.tsx +108 -0
- package/src/components/editor/header/status.tsx +44 -10
- package/src/components/editor/navigation/__tests__/clipboard.test.ts +106 -0
- package/src/components/editor/navigation/__tests__/navigation.test.ts +70 -0
- package/src/components/editor/navigation/clipboard.ts +99 -25
- package/src/components/editor/navigation/navigation.ts +15 -1
- package/src/components/editor/notebook-cell.tsx +5 -0
- package/src/components/editor/output/console/ConsoleOutput.tsx +23 -5
- package/src/components/editor/output/console/__tests__/ConsoleOutput.test.tsx +114 -0
- package/src/components/editor/renderers/slides-layout/__tests__/compute-slide-cells.test.ts +5 -4
- package/src/components/editor/renderers/slides-layout/__tests__/plugin.test.ts +55 -15
- package/src/components/editor/renderers/slides-layout/plugin.tsx +8 -25
- package/src/components/editor/renderers/slides-layout/slides-layout.tsx +19 -6
- package/src/components/editor/renderers/slides-layout/types.ts +40 -31
- package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +1 -0
- package/src/components/home/components.tsx +6 -0
- package/src/components/pages/run-page.tsx +4 -1
- package/src/components/scratchpad/scratchpad.tsx +1 -0
- package/src/components/slides/__tests__/slide-notes.test.ts +131 -0
- package/src/components/slides/reveal-component.tsx +252 -147
- package/src/components/slides/slide-notes-editor.tsx +127 -0
- package/src/components/slides/slide-notes.ts +64 -0
- package/src/components/slides/slides.css +14 -0
- package/src/components/ui/combobox.tsx +24 -5
- package/src/components/ui/number-field.tsx +2 -0
- package/src/core/ai/tools/__tests__/registry.test.ts +10 -12
- package/src/core/ai/tools/registry.ts +9 -5
- package/src/core/cells/__tests__/cells.test.ts +187 -0
- package/src/core/cells/__tests__/pending-cut-service.test.tsx +123 -0
- package/src/core/cells/cells.ts +102 -17
- package/src/core/cells/document-changes.ts +6 -1
- package/src/core/cells/pending-cut-service.ts +55 -0
- package/src/core/cells/utils.ts +11 -0
- package/src/core/codemirror/cells/extensions.ts +10 -0
- package/src/core/codemirror/go-to-definition/__tests__/commands.test.ts +152 -0
- package/src/core/codemirror/go-to-definition/__tests__/utils.test.ts +99 -0
- package/src/core/codemirror/go-to-definition/commands.ts +382 -22
- package/src/core/codemirror/go-to-definition/utils.ts +23 -5
- package/src/core/edit-app.tsx +3 -2
- package/src/core/hotkeys/hotkeys.ts +5 -0
- package/src/core/islands/worker/worker.tsx +3 -2
- package/src/core/run-app.tsx +2 -1
- package/src/core/runtime/__tests__/runtime.test.ts +38 -17
- package/src/core/runtime/runtime.ts +57 -34
- package/src/core/wasm/__tests__/utils.test.ts +34 -0
- package/src/core/wasm/utils.ts +14 -0
- package/src/core/wasm/worker/bootstrap.ts +3 -2
- package/src/core/wasm/worker/worker.ts +3 -2
- package/src/core/websocket/__tests__/useMarimoKernelConnection.hook.test.tsx +156 -0
- package/src/core/websocket/__tests__/useMarimoKernelConnection.test.ts +101 -0
- package/src/core/websocket/transports/__tests__/ws.test.ts +125 -0
- package/src/core/websocket/transports/basic.ts +1 -1
- package/src/core/websocket/transports/ws.ts +96 -0
- package/src/core/websocket/useMarimoKernelConnection.tsx +133 -54
- package/src/core/websocket/useWebSocket.tsx +3 -15
- package/src/css/app/Cell.css +10 -0
- package/src/plugins/core/__test__/sanitize.test.ts +30 -0
- package/src/plugins/impl/DropdownPlugin.tsx +12 -1
- package/src/plugins/impl/MultiselectPlugin.tsx +4 -0
- package/src/plugins/impl/SearchableSelect.tsx +11 -1
- package/src/plugins/impl/TabsPlugin.tsx +35 -7
- package/src/plugins/impl/__tests__/DropdownPlugin.test.tsx +56 -0
- package/src/plugins/impl/__tests__/TabsPlugin.test.tsx +154 -0
- package/src/plugins/impl/data-frames/forms/__tests__/__snapshots__/form.test.tsx.snap +48 -36
- package/src/plugins/impl/data-frames/schema.ts +4 -1
- package/src/plugins/layout/DownloadPlugin.tsx +9 -7
- package/src/utils/__tests__/id-tree.test.ts +71 -0
- package/src/utils/download.ts +4 -2
- package/src/utils/id-tree.tsx +89 -0
- package/dist/assets/__vite-browser-external-rrUYDKRl.js +0 -1
- package/dist/assets/worker-Bfy15ViQ.js +0 -73
- package/dist/reveal-component-C97Ceb7e.js +0 -4863
- package/src/components/chat/tool-call-accordion.tsx +0 -247
|
@@ -275,14 +275,14 @@ describe("RuntimeManager", () => {
|
|
|
275
275
|
});
|
|
276
276
|
});
|
|
277
277
|
|
|
278
|
-
describe("
|
|
278
|
+
describe("probeHealth", () => {
|
|
279
279
|
it("should return true for successful health check", async () => {
|
|
280
280
|
global.fetch = vi.fn().mockResolvedValue({
|
|
281
281
|
ok: true,
|
|
282
282
|
});
|
|
283
283
|
|
|
284
284
|
const runtime = new RuntimeManager(mockConfig);
|
|
285
|
-
const result = await runtime.
|
|
285
|
+
const result = await runtime.probeHealth();
|
|
286
286
|
|
|
287
287
|
expect(result).toBe(true);
|
|
288
288
|
expect(fetch).toHaveBeenCalledWith("https://example.com/health");
|
|
@@ -294,7 +294,7 @@ describe("RuntimeManager", () => {
|
|
|
294
294
|
});
|
|
295
295
|
|
|
296
296
|
const runtime = new RuntimeManager(mockConfig);
|
|
297
|
-
const result = await runtime.
|
|
297
|
+
const result = await runtime.probeHealth();
|
|
298
298
|
|
|
299
299
|
expect(result).toBe(false);
|
|
300
300
|
});
|
|
@@ -304,11 +304,32 @@ describe("RuntimeManager", () => {
|
|
|
304
304
|
global.fetch = vi.fn().mockRejectedValue(error);
|
|
305
305
|
|
|
306
306
|
const runtime = new RuntimeManager(mockConfig);
|
|
307
|
-
const result = await runtime.
|
|
307
|
+
const result = await runtime.probeHealth();
|
|
308
308
|
|
|
309
309
|
expect(result).toBe(false);
|
|
310
310
|
});
|
|
311
311
|
|
|
312
|
+
it("should not mutate config.url on redirect", async () => {
|
|
313
|
+
global.fetch = vi.fn().mockResolvedValue({
|
|
314
|
+
ok: true,
|
|
315
|
+
redirected: true,
|
|
316
|
+
url: "https://sandbox.example.com/health?some_value=abc123",
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
const runtime = new RuntimeManager(
|
|
320
|
+
{
|
|
321
|
+
...mockConfig,
|
|
322
|
+
url: "https://backend.example.com/lazy?some_value=abc123",
|
|
323
|
+
},
|
|
324
|
+
true,
|
|
325
|
+
);
|
|
326
|
+
const result = await runtime.probeHealth();
|
|
327
|
+
expect(result).toBe(true);
|
|
328
|
+
expect(runtime.httpURL.hostname).toBe("backend.example.com");
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
describe("reconcileFromHealth", () => {
|
|
312
333
|
it("should update config.url on redirect, stripping /health from pathname", async () => {
|
|
313
334
|
global.fetch = vi.fn().mockResolvedValue({
|
|
314
335
|
ok: true,
|
|
@@ -323,7 +344,7 @@ describe("RuntimeManager", () => {
|
|
|
323
344
|
},
|
|
324
345
|
true, // lazy — don't call init() in constructor
|
|
325
346
|
);
|
|
326
|
-
const result = await runtime.
|
|
347
|
+
const result = await runtime.reconcileFromHealth();
|
|
327
348
|
|
|
328
349
|
expect(result).toBe(true);
|
|
329
350
|
// Should strip /health from pathname but preserve query params
|
|
@@ -342,7 +363,7 @@ describe("RuntimeManager", () => {
|
|
|
342
363
|
it("should resolve immediately if healthy", async () => {
|
|
343
364
|
const runtime = new RuntimeManager(mockConfig, true);
|
|
344
365
|
|
|
345
|
-
vi.spyOn(runtime, "
|
|
366
|
+
vi.spyOn(runtime, "reconcileFromHealth").mockResolvedValue(true);
|
|
346
367
|
runtime.init();
|
|
347
368
|
|
|
348
369
|
await expect(runtime.waitForHealthy()).resolves.toBeUndefined();
|
|
@@ -351,7 +372,7 @@ describe("RuntimeManager", () => {
|
|
|
351
372
|
it("should retry and eventually succeed", async () => {
|
|
352
373
|
const runtime = new RuntimeManager(mockConfig, true);
|
|
353
374
|
const healthySpy = vi
|
|
354
|
-
.spyOn(runtime, "
|
|
375
|
+
.spyOn(runtime, "reconcileFromHealth")
|
|
355
376
|
.mockResolvedValueOnce(false)
|
|
356
377
|
.mockResolvedValueOnce(false)
|
|
357
378
|
.mockResolvedValueOnce(true);
|
|
@@ -364,7 +385,7 @@ describe("RuntimeManager", () => {
|
|
|
364
385
|
|
|
365
386
|
it("should throw after max retries", async () => {
|
|
366
387
|
const runtime = new RuntimeManager(mockConfig, true);
|
|
367
|
-
vi.spyOn(runtime, "
|
|
388
|
+
vi.spyOn(runtime, "reconcileFromHealth").mockResolvedValue(false);
|
|
368
389
|
runtime.init({ disableRetryDelay: true });
|
|
369
390
|
|
|
370
391
|
await expect(runtime.waitForHealthy()).rejects.toThrow(
|
|
@@ -431,7 +452,7 @@ describe("RuntimeManager", () => {
|
|
|
431
452
|
// Mock failed health check
|
|
432
453
|
global.fetch = vi.fn().mockResolvedValue({ ok: false });
|
|
433
454
|
|
|
434
|
-
await runtime.
|
|
455
|
+
await runtime.reconcileFromHealth();
|
|
435
456
|
|
|
436
457
|
baseElement = document.querySelector("base");
|
|
437
458
|
expect(baseElement).toBeNull();
|
|
@@ -443,7 +464,7 @@ describe("RuntimeManager", () => {
|
|
|
443
464
|
// Mock successful health check
|
|
444
465
|
global.fetch = vi.fn().mockResolvedValue({ ok: true });
|
|
445
466
|
|
|
446
|
-
await runtime.
|
|
467
|
+
await runtime.reconcileFromHealth();
|
|
447
468
|
|
|
448
469
|
const baseElement = document.querySelector("base");
|
|
449
470
|
expect(baseElement).toBeTruthy();
|
|
@@ -461,7 +482,7 @@ describe("RuntimeManager", () => {
|
|
|
461
482
|
// Mock successful health check
|
|
462
483
|
global.fetch = vi.fn().mockResolvedValue({ ok: true });
|
|
463
484
|
|
|
464
|
-
await runtime.
|
|
485
|
+
await runtime.reconcileFromHealth();
|
|
465
486
|
|
|
466
487
|
const baseElement = document.querySelector("base");
|
|
467
488
|
expect(baseElement).toBe(existingBase); // Should be the same element
|
|
@@ -483,7 +504,7 @@ describe("RuntimeManager", () => {
|
|
|
483
504
|
// Mock successful health check
|
|
484
505
|
global.fetch = vi.fn().mockResolvedValue({ ok: true });
|
|
485
506
|
|
|
486
|
-
await runtime.
|
|
507
|
+
await runtime.reconcileFromHealth();
|
|
487
508
|
|
|
488
509
|
const baseElement = document.querySelector("base");
|
|
489
510
|
expect(baseElement).toBeTruthy();
|
|
@@ -524,11 +545,11 @@ describe("RuntimeManager", () => {
|
|
|
524
545
|
});
|
|
525
546
|
|
|
526
547
|
const wsUrl = runtime.getWsURL("test" as SessionId);
|
|
527
|
-
const httpUrl = runtime.formatHttpURL(
|
|
528
|
-
"api/test",
|
|
529
|
-
new URLSearchParams(),
|
|
530
|
-
false,
|
|
531
|
-
);
|
|
548
|
+
const httpUrl = runtime.formatHttpURL({
|
|
549
|
+
path: "api/test",
|
|
550
|
+
searchParams: new URLSearchParams(),
|
|
551
|
+
restrictToKnownQueryParams: false,
|
|
552
|
+
});
|
|
532
553
|
|
|
533
554
|
// Should preserve base URL query params
|
|
534
555
|
expect(wsUrl.searchParams.get("base_param")).toBe("existing");
|
|
@@ -44,17 +44,22 @@ export class RuntimeManager {
|
|
|
44
44
|
return this.httpURL.origin === window.location.origin;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
private get isServerless(): boolean {
|
|
48
|
+
return isWasm() || isIslands() || isStaticNotebook();
|
|
49
|
+
}
|
|
50
|
+
|
|
47
51
|
/**
|
|
48
52
|
* The base URL of the runtime.
|
|
49
53
|
*/
|
|
50
|
-
formatHttpURL(
|
|
51
|
-
path
|
|
52
|
-
searchParams
|
|
54
|
+
formatHttpURL({
|
|
55
|
+
path = "",
|
|
56
|
+
searchParams,
|
|
53
57
|
restrictToKnownQueryParams = true,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
}: {
|
|
59
|
+
path?: string;
|
|
60
|
+
searchParams?: URLSearchParams;
|
|
61
|
+
restrictToKnownQueryParams?: boolean;
|
|
62
|
+
}): URL {
|
|
58
63
|
// URL may be something like "http://localhost:8000?auth=123"
|
|
59
64
|
const baseUrl = this.httpURL;
|
|
60
65
|
const currentParams = new URLSearchParams(window.location.search);
|
|
@@ -84,11 +89,11 @@ export class RuntimeManager {
|
|
|
84
89
|
formatWsURL(path: string, searchParams?: URLSearchParams): URL {
|
|
85
90
|
// We don't restrict to known query parameters, since mo.query_params()
|
|
86
91
|
// can accept arbitrary parameters.
|
|
87
|
-
const url = this.formatHttpURL(
|
|
92
|
+
const url = this.formatHttpURL({
|
|
88
93
|
path,
|
|
89
94
|
searchParams,
|
|
90
|
-
|
|
91
|
-
);
|
|
95
|
+
restrictToKnownQueryParams: false,
|
|
96
|
+
});
|
|
92
97
|
|
|
93
98
|
// For cross-origin runtimes, pass the auth token as a query parameter.
|
|
94
99
|
// WebSocket connections cannot send custom headers (no Authorization
|
|
@@ -168,45 +173,63 @@ export class RuntimeManager {
|
|
|
168
173
|
}
|
|
169
174
|
|
|
170
175
|
getAiURL(path: "completion" | "chat"): URL {
|
|
171
|
-
return this.formatHttpURL(`/api/ai/${path}`);
|
|
176
|
+
return this.formatHttpURL({ path: `/api/ai/${path}` });
|
|
172
177
|
}
|
|
173
178
|
|
|
174
179
|
/**
|
|
175
180
|
* The URL of the health check endpoint.
|
|
176
181
|
*/
|
|
177
182
|
healthURL(): URL {
|
|
178
|
-
return this.formatHttpURL("/health");
|
|
183
|
+
return this.formatHttpURL({ path: "/health" });
|
|
179
184
|
}
|
|
180
185
|
|
|
181
|
-
async
|
|
182
|
-
// Always healthy if WASM, Islands, or a static notebook (no server)
|
|
183
|
-
if (isWasm() || isIslands() || isStaticNotebook()) {
|
|
184
|
-
return true;
|
|
185
|
-
}
|
|
186
|
-
|
|
186
|
+
private async fetchHealth(): Promise<Response | null> {
|
|
187
187
|
try {
|
|
188
|
-
|
|
189
|
-
// If there is a redirect, update the URL in the config
|
|
190
|
-
if (response.redirected) {
|
|
191
|
-
Logger.debug(`Runtime redirected to ${response.url}`);
|
|
192
|
-
// strip /health from the URL, using URL parsing to handle query params
|
|
193
|
-
const redirected = new URL(response.url);
|
|
194
|
-
redirected.pathname = redirected.pathname.replace(/\/health$/, "");
|
|
195
|
-
this.config.url = redirected.toString();
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const success = response.ok;
|
|
199
|
-
if (success) {
|
|
200
|
-
this.setDOMBaseUri(this.config.url);
|
|
201
|
-
}
|
|
202
|
-
return success;
|
|
188
|
+
return await fetch(this.healthURL().toString());
|
|
203
189
|
} catch (error) {
|
|
204
190
|
Logger.error(
|
|
205
191
|
`Failed to check health: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
206
192
|
{ cause: error },
|
|
207
193
|
);
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async reconcileFromHealth(): Promise<boolean> {
|
|
199
|
+
// Always healthy if WASM, Islands, or a static notebook (no server)
|
|
200
|
+
if (this.isServerless) {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const response = await this.fetchHealth();
|
|
205
|
+
|
|
206
|
+
if (!response) {
|
|
208
207
|
return false;
|
|
209
208
|
}
|
|
209
|
+
|
|
210
|
+
if (response.redirected) {
|
|
211
|
+
Logger.debug(`Runtime redirected to ${response.url}`);
|
|
212
|
+
// strip /health from the URL, using URL parsing to handle query params
|
|
213
|
+
const redirected = new URL(response.url);
|
|
214
|
+
redirected.pathname = redirected.pathname.replace(/\/health$/, "");
|
|
215
|
+
this.config.url = redirected.toString();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (response.ok) {
|
|
219
|
+
this.setDOMBaseUri(this.config.url);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return response.ok;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async probeHealth(): Promise<boolean> {
|
|
226
|
+
// Always healthy if WASM, Islands, or a static notebook (no server)
|
|
227
|
+
if (this.isServerless) {
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const response = await this.fetchHealth();
|
|
232
|
+
return response?.ok ?? false;
|
|
210
233
|
}
|
|
211
234
|
|
|
212
235
|
/**
|
|
@@ -251,7 +274,7 @@ export class RuntimeManager {
|
|
|
251
274
|
const growthFactor = 1.2;
|
|
252
275
|
const maxDelay = 2000;
|
|
253
276
|
|
|
254
|
-
while (!(await this.
|
|
277
|
+
while (!(await this.reconcileFromHealth())) {
|
|
255
278
|
if (retries >= maxRetries) {
|
|
256
279
|
Logger.error(`Failed to connect after ${maxRetries} retries`);
|
|
257
280
|
this.initialHealthyCheck.reject(
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { shouldLoadDuckDBPackages } from "../utils";
|
|
5
|
+
|
|
6
|
+
describe("shouldLoadDuckDBPackages", () => {
|
|
7
|
+
it("loads for mo.sql", () => {
|
|
8
|
+
expect(shouldLoadDuckDBPackages('df = mo.sql("SELECT 1")')).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("loads for duckdb imports and usage", () => {
|
|
12
|
+
expect(shouldLoadDuckDBPackages("import duckdb")).toBe(true);
|
|
13
|
+
expect(shouldLoadDuckDBPackages("from duckdb import sql")).toBe(true);
|
|
14
|
+
expect(shouldLoadDuckDBPackages("import pandas, duckdb")).toBe(true);
|
|
15
|
+
expect(shouldLoadDuckDBPackages("rows = duckdb.sql('SELECT 1')")).toBe(
|
|
16
|
+
true,
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("loads when package discovery found duckdb", () => {
|
|
21
|
+
expect(
|
|
22
|
+
shouldLoadDuckDBPackages("print('hello')", new Set(["duckdb"])),
|
|
23
|
+
).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("does not load for incidental duckdb text", () => {
|
|
27
|
+
expect(shouldLoadDuckDBPackages("name = 'duckdb'")).toBe(false);
|
|
28
|
+
expect(shouldLoadDuckDBPackages("# import duckdb")).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("does not load without mo.sql, duckdb usage, or discovery", () => {
|
|
32
|
+
expect(shouldLoadDuckDBPackages("print('hello')")).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
});
|
package/src/core/wasm/utils.ts
CHANGED
|
@@ -10,3 +10,17 @@ export function isWasm(): boolean {
|
|
|
10
10
|
document.querySelector("marimo-wasm") !== null
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
|
+
|
|
14
|
+
const DUCKDB_USAGE_PATTERN =
|
|
15
|
+
/(^|\n)\s*(?:import\s+[^\n#]*\bduckdb\b|from\s+duckdb\b|[^\n#]*\bduckdb\s*\.)/;
|
|
16
|
+
|
|
17
|
+
export function shouldLoadDuckDBPackages(
|
|
18
|
+
code: string,
|
|
19
|
+
foundPackages?: ReadonlySet<string>,
|
|
20
|
+
): boolean {
|
|
21
|
+
return (
|
|
22
|
+
code.includes("mo.sql") ||
|
|
23
|
+
DUCKDB_USAGE_PATTERN.test(code) ||
|
|
24
|
+
foundPackages?.has("duckdb") === true
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -9,6 +9,7 @@ import { WasmFileSystem } from "./fs";
|
|
|
9
9
|
import { getMarimoWheel } from "./getMarimoWheel";
|
|
10
10
|
import { t } from "./tracer";
|
|
11
11
|
import type { SerializedBridge, WasmController } from "./types";
|
|
12
|
+
import { shouldLoadDuckDBPackages } from "../utils";
|
|
12
13
|
|
|
13
14
|
const MAKE_SNAPSHOT = false;
|
|
14
15
|
|
|
@@ -163,8 +164,8 @@ export class DefaultWasmController implements WasmController {
|
|
|
163
164
|
private async loadNotebookDeps(code: string, foundPackages: Set<string>) {
|
|
164
165
|
const pyodide = this.requirePyodide;
|
|
165
166
|
|
|
166
|
-
if (code
|
|
167
|
-
// We need pandas and duckdb for mo.sql
|
|
167
|
+
if (shouldLoadDuckDBPackages(code, foundPackages)) {
|
|
168
|
+
// We need pandas and duckdb for mo.sql and for remote duckdb sources
|
|
168
169
|
code = `import pandas\n${code}`;
|
|
169
170
|
code = `import duckdb\n${code}`;
|
|
170
171
|
code = `import sqlglot\n${code}`;
|
|
@@ -34,6 +34,7 @@ import type {
|
|
|
34
34
|
SerializedBridge,
|
|
35
35
|
WasmController,
|
|
36
36
|
} from "./types";
|
|
37
|
+
import { shouldLoadDuckDBPackages } from "../utils";
|
|
37
38
|
|
|
38
39
|
/**
|
|
39
40
|
* Web worker responsible for running the notebook.
|
|
@@ -141,8 +142,8 @@ const requestHandler = createRPCRequestHandler({
|
|
|
141
142
|
const span = t.startSpan("loadPackages");
|
|
142
143
|
await pyodideReadyPromise; // Make sure loading is done
|
|
143
144
|
|
|
144
|
-
if (code
|
|
145
|
-
// Add pandas and duckdb to the code
|
|
145
|
+
if (shouldLoadDuckDBPackages(code)) {
|
|
146
|
+
// Add pandas and duckdb to the code for mo.sql and for remote duckdb sources
|
|
146
147
|
code = `import pandas\n${code}`;
|
|
147
148
|
code = `import duckdb\n${code}`;
|
|
148
149
|
code = `import sqlglot\n${code}`;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
// @vitest-environment jsdom
|
|
3
|
+
|
|
4
|
+
import { act, renderHook } from "@testing-library/react";
|
|
5
|
+
import { createStore, Provider as JotaiProvider } from "jotai";
|
|
6
|
+
import type React from "react";
|
|
7
|
+
import { ErrorBoundary } from "react-error-boundary";
|
|
8
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
9
|
+
|
|
10
|
+
vi.mock("@/core/websocket/useWebSocket", async () => {
|
|
11
|
+
const actual =
|
|
12
|
+
await vi.importActual<typeof import("../useWebSocket")>("../useWebSocket");
|
|
13
|
+
return {
|
|
14
|
+
...actual,
|
|
15
|
+
useConnectionTransport: vi.fn(),
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
vi.mock("@/core/runtime/config", async () => {
|
|
20
|
+
const actual = await vi.importActual<typeof import("@/core/runtime/config")>(
|
|
21
|
+
"@/core/runtime/config",
|
|
22
|
+
);
|
|
23
|
+
return {
|
|
24
|
+
...actual,
|
|
25
|
+
useRuntimeManager: vi.fn(),
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
import { useRuntimeManager } from "@/core/runtime/config";
|
|
30
|
+
import { connectionAtom } from "../../network/connection";
|
|
31
|
+
import type { SessionId } from "../../kernel/session";
|
|
32
|
+
import { WebSocketClosedReason, WebSocketState } from "../types";
|
|
33
|
+
import { useMarimoKernelConnection } from "../useMarimoKernelConnection";
|
|
34
|
+
import { useConnectionTransport } from "../useWebSocket";
|
|
35
|
+
|
|
36
|
+
interface MockTransport {
|
|
37
|
+
readyState: 0 | 1 | 2 | 3;
|
|
38
|
+
reconnect: ReturnType<typeof vi.fn>;
|
|
39
|
+
close: ReturnType<typeof vi.fn>;
|
|
40
|
+
send: ReturnType<typeof vi.fn>;
|
|
41
|
+
addEventListener: ReturnType<typeof vi.fn>;
|
|
42
|
+
removeEventListener: ReturnType<typeof vi.fn>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function makeTransport(
|
|
46
|
+
readyState: 0 | 1 | 2 | 3 = WebSocket.CLOSED,
|
|
47
|
+
): MockTransport {
|
|
48
|
+
return {
|
|
49
|
+
readyState,
|
|
50
|
+
reconnect: vi.fn(),
|
|
51
|
+
close: vi.fn(),
|
|
52
|
+
send: vi.fn(),
|
|
53
|
+
addEventListener: vi.fn(),
|
|
54
|
+
removeEventListener: vi.fn(),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function makeRuntimeManager(
|
|
59
|
+
reconcileFromHealth = vi.fn().mockResolvedValue(true),
|
|
60
|
+
) {
|
|
61
|
+
return {
|
|
62
|
+
reconcileFromHealth,
|
|
63
|
+
probeHealth: vi.fn().mockResolvedValue(true),
|
|
64
|
+
getWsURL: () => new URL("ws://localhost/ws"),
|
|
65
|
+
waitForHealthy: vi.fn().mockResolvedValue(undefined),
|
|
66
|
+
isSameOrigin: true,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
describe("useMarimoKernelConnection.reconnect()", () => {
|
|
71
|
+
let transport: MockTransport;
|
|
72
|
+
let isHealthy: ReturnType<typeof vi.fn>;
|
|
73
|
+
let store: ReturnType<typeof createStore>;
|
|
74
|
+
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
transport = makeTransport(WebSocket.CLOSED);
|
|
77
|
+
isHealthy = vi.fn().mockResolvedValue(true);
|
|
78
|
+
store = createStore();
|
|
79
|
+
store.set(connectionAtom, {
|
|
80
|
+
state: WebSocketState.CLOSED,
|
|
81
|
+
code: WebSocketClosedReason.KERNEL_DISCONNECTED,
|
|
82
|
+
reason: "kernel not found",
|
|
83
|
+
});
|
|
84
|
+
vi.mocked(useConnectionTransport).mockReturnValue(transport);
|
|
85
|
+
vi.mocked(useRuntimeManager).mockReturnValue(
|
|
86
|
+
makeRuntimeManager(isHealthy) as unknown as ReturnType<
|
|
87
|
+
typeof useRuntimeManager
|
|
88
|
+
>,
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
function renderUseHook() {
|
|
93
|
+
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
|
|
94
|
+
<JotaiProvider store={store}>
|
|
95
|
+
<ErrorBoundary fallback={null}>{children}</ErrorBoundary>
|
|
96
|
+
</JotaiProvider>
|
|
97
|
+
);
|
|
98
|
+
return renderHook(
|
|
99
|
+
() =>
|
|
100
|
+
useMarimoKernelConnection({
|
|
101
|
+
sessionId: "test-session" as SessionId,
|
|
102
|
+
autoInstantiate: false,
|
|
103
|
+
setCells: () => {},
|
|
104
|
+
}),
|
|
105
|
+
{ wrapper },
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
it("is a no-op when the transport is already OPEN", async () => {
|
|
110
|
+
transport.readyState = WebSocket.OPEN;
|
|
111
|
+
const { result } = renderUseHook();
|
|
112
|
+
await act(async () => {
|
|
113
|
+
await result.current.reconnect();
|
|
114
|
+
});
|
|
115
|
+
expect(isHealthy).not.toHaveBeenCalled();
|
|
116
|
+
expect(transport.reconnect).not.toHaveBeenCalled();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("is a no-op when the transport is already CONNECTING", async () => {
|
|
120
|
+
transport.readyState = WebSocket.CONNECTING;
|
|
121
|
+
const { result } = renderUseHook();
|
|
122
|
+
await act(async () => {
|
|
123
|
+
await result.current.reconnect();
|
|
124
|
+
});
|
|
125
|
+
expect(isHealthy).not.toHaveBeenCalled();
|
|
126
|
+
expect(transport.reconnect).not.toHaveBeenCalled();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("probes /health and reconnects when the runtime is healthy", async () => {
|
|
130
|
+
isHealthy.mockResolvedValue(true);
|
|
131
|
+
const { result } = renderUseHook();
|
|
132
|
+
await act(async () => {
|
|
133
|
+
await result.current.reconnect();
|
|
134
|
+
});
|
|
135
|
+
expect(isHealthy).toHaveBeenCalledOnce();
|
|
136
|
+
expect(transport.reconnect).toHaveBeenCalledOnce();
|
|
137
|
+
expect(store.get(connectionAtom)).toEqual({
|
|
138
|
+
state: WebSocketState.CONNECTING,
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("transitions to CLOSED and does not call ws.reconnect when the probe fails", async () => {
|
|
143
|
+
isHealthy.mockResolvedValue(false);
|
|
144
|
+
const { result } = renderUseHook();
|
|
145
|
+
await act(async () => {
|
|
146
|
+
await result.current.reconnect();
|
|
147
|
+
});
|
|
148
|
+
expect(isHealthy).toHaveBeenCalledOnce();
|
|
149
|
+
expect(transport.reconnect).not.toHaveBeenCalled();
|
|
150
|
+
expect(store.get(connectionAtom)).toEqual({
|
|
151
|
+
state: WebSocketState.CLOSED,
|
|
152
|
+
code: WebSocketClosedReason.KERNEL_DISCONNECTED,
|
|
153
|
+
reason: "kernel not found",
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { Logger } from "@/utils/Logger";
|
|
5
|
+
import { WebSocketClosedReason, WebSocketState } from "../types";
|
|
6
|
+
import { classifyCloseEvent } from "../useMarimoKernelConnection";
|
|
7
|
+
|
|
8
|
+
function classify(reason: string | undefined) {
|
|
9
|
+
return classifyCloseEvent({ reason });
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe("classifyCloseEvent", () => {
|
|
13
|
+
describe("transient closes (default branch)", () => {
|
|
14
|
+
it("retries on empty/undefined reason", () => {
|
|
15
|
+
const decision = classify(undefined);
|
|
16
|
+
expect(decision.kind).toBe("retry");
|
|
17
|
+
expect(decision.status).toEqual({ state: WebSocketState.CONNECTING });
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("treats unknown reason strings as transient and logs a warning", () => {
|
|
21
|
+
const logger = vi.spyOn(Logger, "warn").mockImplementation(() => {});
|
|
22
|
+
const decision = classify("something-else");
|
|
23
|
+
expect(decision.kind).toBe("retry");
|
|
24
|
+
expect(logger).toHaveBeenCalled();
|
|
25
|
+
logger.mockRestore();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
vi.restoreAllMocks();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe("terminal closes (server-initiated)", () => {
|
|
34
|
+
it("MARIMO_ALREADY_CONNECTED → terminal + closeTransport, with takeover", () => {
|
|
35
|
+
const decision = classify("MARIMO_ALREADY_CONNECTED");
|
|
36
|
+
expect(decision.kind).toBe("terminal");
|
|
37
|
+
expect(decision.status).toMatchObject({
|
|
38
|
+
state: WebSocketState.CLOSED,
|
|
39
|
+
code: WebSocketClosedReason.ALREADY_RUNNING,
|
|
40
|
+
canTakeover: true,
|
|
41
|
+
});
|
|
42
|
+
if (decision.kind === "terminal") {
|
|
43
|
+
expect(decision.closeTransport).toBe(true);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it.each([
|
|
48
|
+
"MARIMO_WRONG_KERNEL_ID",
|
|
49
|
+
"MARIMO_NO_FILE_KEY",
|
|
50
|
+
"MARIMO_NO_SESSION_ID",
|
|
51
|
+
"MARIMO_NO_SESSION",
|
|
52
|
+
"MARIMO_SHUTDOWN",
|
|
53
|
+
])("%s → terminal with KERNEL_DISCONNECTED, closes transport", (reason) => {
|
|
54
|
+
const decision = classify(reason);
|
|
55
|
+
expect(decision.kind).toBe("terminal");
|
|
56
|
+
expect(decision.status).toMatchObject({
|
|
57
|
+
state: WebSocketState.CLOSED,
|
|
58
|
+
code: WebSocketClosedReason.KERNEL_DISCONNECTED,
|
|
59
|
+
});
|
|
60
|
+
if (decision.kind === "terminal") {
|
|
61
|
+
expect(decision.closeTransport).toBe(true);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("MARIMO_MALFORMED_QUERY → terminal but does NOT close transport", () => {
|
|
66
|
+
const decision = classify("MARIMO_MALFORMED_QUERY");
|
|
67
|
+
expect(decision.kind).toBe("terminal");
|
|
68
|
+
expect(decision.status).toMatchObject({
|
|
69
|
+
state: WebSocketState.CLOSED,
|
|
70
|
+
code: WebSocketClosedReason.MALFORMED_QUERY,
|
|
71
|
+
});
|
|
72
|
+
if (decision.kind === "terminal") {
|
|
73
|
+
expect(decision.closeTransport).toBe(false);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("MARIMO_KERNEL_STARTUP_ERROR → terminal + closeTransport", () => {
|
|
78
|
+
const decision = classify("MARIMO_KERNEL_STARTUP_ERROR");
|
|
79
|
+
expect(decision.kind).toBe("terminal");
|
|
80
|
+
expect(decision.status).toMatchObject({
|
|
81
|
+
state: WebSocketState.CLOSED,
|
|
82
|
+
code: WebSocketClosedReason.KERNEL_STARTUP_ERROR,
|
|
83
|
+
});
|
|
84
|
+
if (decision.kind === "terminal") {
|
|
85
|
+
expect(decision.closeTransport).toBe(true);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe("transport exhaustion", () => {
|
|
91
|
+
it("MARIMO_TRANSPORT_EXHAUSTED → gave-up with KERNEL_DISCONNECTED", () => {
|
|
92
|
+
const decision = classify("MARIMO_TRANSPORT_EXHAUSTED");
|
|
93
|
+
expect(decision.kind).toBe("gave-up");
|
|
94
|
+
expect(decision.status).toEqual({
|
|
95
|
+
state: WebSocketState.CLOSED,
|
|
96
|
+
code: WebSocketClosedReason.KERNEL_DISCONNECTED,
|
|
97
|
+
reason: "kernel not found",
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|