@marimo-team/islands 0.25.3-dev20 → 0.25.3-dev21
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-CNMliVzw.js → ConnectedDataExplorerComponent-DfG3PRaJ.js} +9 -9
- package/dist/{ErrorBoundary-DAPIRYqd.js → ErrorBoundary-ttSr7_91.js} +8 -8
- package/dist/{abnfDiagram-VCTEODGH-D-Ez91gV.js → abnfDiagram-VCTEODGH-B3w-XWX8.js} +2 -2
- package/dist/{any-language-editor-DZ_YTVus.js → any-language-editor-D4q-IFcM.js} +2 -2
- package/dist/{architectureDiagram-5GKGNRK7-CTpcNtO8.js → architectureDiagram-5GKGNRK7-C18U9A6k.js} +1 -1
- package/dist/{chat-ui-DaHynk8g.js → chat-ui-w8SVynkn.js} +1096 -1096
- package/dist/{check-EDwSwP89.js → check-BMKBBrdc.js} +1 -1
- package/dist/{chunk-IMKFNOWR-DGxi-zeo.js → chunk-IMKFNOWR-CrS5bzqW.js} +1 -1
- package/dist/{chunk-SHT3W25Y-CV9J3rAB.js → chunk-SHT3W25Y-StpvPvUG.js} +1 -1
- package/dist/{chunk-SVP7TREG-BL-9Fqgg.js → chunk-SVP7TREG-CBXjbYZC.js} +1 -1
- package/dist/{chunk-TICWLB2K-Cu_XMjDM.js → chunk-TICWLB2K-Dp6bIb-q.js} +1 -1
- package/dist/{classDiagram-ZZMXUADV-BXXV13Hq.js → classDiagram-ZZMXUADV-BFYuxV5g.js} +2 -2
- package/dist/{classDiagram-v2-VYDZK3BY-B7FXJ1Cp.js → classDiagram-v2-VYDZK3BY-D_tjXVMl.js} +2 -2
- package/dist/{code-visibility-DkCqn-PO.js → code-visibility-DPm4oWK1.js} +5 -5
- package/dist/{common-DsUPhkD6.js → common-CeebhhhO.js} +6265 -6262
- package/dist/{copy-icon-Ft7t9bqz.js → copy-icon-BgUO8jsi.js} +2 -2
- package/dist/{cynefinDiagram-5FMLGOSQ-CH96rwba.js → cynefinDiagram-5FMLGOSQ-DSgYrHB2.js} +1 -1
- package/dist/{dagre-GXQ25YYZ-BD3PmpFY.js → dagre-GXQ25YYZ-GYlruCBf.js} +1 -1
- package/dist/{data-grid-overlay-editor-D7UuVsgB.js → data-grid-overlay-editor-vxQ4E6k1.js} +1 -1
- package/dist/{diagram-S7CK7UJ4-BsSJJldB.js → diagram-S7CK7UJ4-DRu5LX5_.js} +1 -1
- package/dist/{diagram-UQ7AKVKN-muQtNZc4.js → diagram-UQ7AKVKN-DD7uiejP.js} +1 -1
- package/dist/{diagram-VX7I27RA-CdhuZAqR.js → diagram-VX7I27RA-ByH9KAJJ.js} +1 -1
- package/dist/{diagram-Z3DM3KII-BD8mXjOj.js → diagram-Z3DM3KII-BsQHPRke.js} +1 -1
- package/dist/{dialog-CEBFZNyc.js → dialog-Cc479ZEH.js} +24 -24
- package/dist/{dropdown-menu-CP_qCYHC.js → dropdown-menu-DHP9P4VE.js} +790 -790
- package/dist/{ebnfDiagram-PWID7BFC-BIN1sweE.js → ebnfDiagram-PWID7BFC-CQRK5_eT.js} +2 -2
- package/dist/{erDiagram-RLTQ6QDP-Ctp5cfoN.js → erDiagram-RLTQ6QDP-BKtWrDVh.js} +1 -1
- package/dist/{error-banner-D-WCIiMt.js → error-banner-CFPHFw4h.js} +16 -16
- package/dist/{error-entries-Bv6bZPF3.js → error-entries-Damuuclv.js} +983 -985
- package/dist/{feedback-button-wnAMXOGA.js → feedback-button-DVgw4Y7F.js} +28 -28
- package/dist/{flowDiagram-HODETNUW-3EfLrlFb.js → flowDiagram-HODETNUW-1IN-ih2E.js} +2 -2
- package/dist/{formats-27CW_UP4.js → formats-X4mMQWzX.js} +1 -1
- package/dist/{glide-data-editor-KvS90MGh.js → glide-data-editor-CSYHMRDu.js} +10 -10
- package/dist/{glide-utils-DJyqh0EM.js → glide-utils-DM9zBO4W.js} +2 -2
- package/dist/{globals-yruoELTW.js → globals-Fpiwkv4D.js} +3 -3
- package/dist/{html-to-image-Bf8QMGi4.js → html-to-image-BdA59IUD.js} +60 -60
- package/dist/{infoDiagram-27XIBGKW-DipQoHxl.js → infoDiagram-27XIBGKW-CkB-zr4p.js} +1 -1
- package/dist/{ishikawaDiagram-5VMMS53U-DgFMjSGz.js → ishikawaDiagram-5VMMS53U-wlyLjBmM.js} +1 -1
- package/dist/{kanban-definition-UXKFOSKX-w1ACVjgl.js → kanban-definition-UXKFOSKX-C2usY0i-.js} +1 -1
- package/dist/{label-BDKF3Afc.js → label-DoysmLMW.js} +1 -1
- package/dist/main.js +722 -723
- package/dist/{mermaid-CHo49Yv-.js → mermaid-BA-Z6wGL.js} +35 -35
- package/dist/{mindmap-definition-YA3MSWOX-CrT0KSfX.js → mindmap-definition-YA3MSWOX-nKOWS8RR.js} +1 -1
- package/dist/{number-overlay-editor-R2i0FdxV.js → number-overlay-editor-BOjqsq7D.js} +1 -1
- package/dist/{pegDiagram-XKGWAZYB-BqvywNJA.js → pegDiagram-XKGWAZYB-Dac9EIKD.js} +2 -2
- package/dist/{pieDiagram-E7YTZNPT-BfxJ_XCc.js → pieDiagram-E7YTZNPT-B7S-DsW_.js} +1 -1
- package/dist/{process-output-BZg56CCb.js → process-output-CTPTtxXB.js} +4 -4
- package/dist/{railroadDiagram-O6MQD6OU-8vFLVTPu.js → railroadDiagram-O6MQD6OU-Cfa5Q-hr.js} +2 -2
- package/dist/{requirementDiagram-BXWQKSXE-a_MxGvxe.js → requirementDiagram-BXWQKSXE-d8zXCJIk.js} +1 -1
- package/dist/{reveal-component-C42-YBfQ.js → reveal-component-Brpo7CP8.js} +9 -9
- package/dist/{select-BButFi-d.js → select-DemoKT4G.js} +199 -199
- package/dist/{sequenceDiagram-WJ2MYXX4-CXFMnxGh.js → sequenceDiagram-WJ2MYXX4-b6pei3lJ.js} +1 -1
- package/dist/{spec-BwarBpUJ.js → spec-BJzgmvVa.js} +4 -4
- package/dist/{stateDiagram-D77RDMKH-DQeA_CwI.js → stateDiagram-D77RDMKH-Be-xSpaZ.js} +2 -2
- package/dist/{stateDiagram-v2-MP3YSRHH-BxxQucm1.js → stateDiagram-v2-MP3YSRHH-5Y-FxesJ.js} +2 -2
- package/dist/{swimlanes-42K2YHIH-Do6L-cYg.js → swimlanes-42K2YHIH-nRRl4NU0.js} +1 -1
- package/dist/{swimlanesDiagram-VR7AAH4N-DUzPvSVU.js → swimlanesDiagram-VR7AAH4N-BS79510V.js} +2 -2
- package/dist/{timeline-definition-24CTP7MA-D3c46WM5.js → timeline-definition-24CTP7MA-Cfzf8WPf.js} +1 -1
- package/dist/toDate-B5mIgxwZ.js +1185 -0
- package/dist/{toast-B9UMEi8u.js → toast-PkdZraM8.js} +221 -221
- package/dist/{tooltip-BO1REbqs.js → tooltip-CtBZ5q8p.js} +51 -51
- package/dist/{use-restore-focus-BEM7sFWl.js → use-restore-focus-CKjfFjLM.js} +1 -1
- package/dist/{useAsyncData-Deh5kszT.js → useAsyncData-BD534XmW.js} +1 -1
- package/dist/{useDateFormatter-D8XruNGG.js → useDateFormatter-DkajGwwd.js} +2 -2
- package/dist/{useDeepCompareMemoize-DXwzRINI.js → useDeepCompareMemoize-C72_RNsu.js} +1 -1
- package/dist/{useLifecycle-j7D9uD1o.js → useLifecycle-BGWzTwHK.js} +2 -2
- package/dist/{useTheme-CRnjkku0.js → useTheme-BhQvec43.js} +83 -83
- package/dist/{vega-component-BeF9dfyO.js → vega-component-DfcYgj-Y.js} +7 -7
- package/dist/{vennDiagram-4TSXK5OY-BSZD8JcZ.js → vennDiagram-4TSXK5OY-CeY6Z1xZ.js} +1 -1
- package/dist/{wardleyDiagram-VM6X3IG4-48cUWkfA.js → wardleyDiagram-VM6X3IG4-Cxs9NtVi.js} +1 -1
- package/dist/{xychartDiagram-S5SC5T6Z-CswYgYeu.js → xychartDiagram-S5SC5T6Z-DNWbvPK7.js} +1 -1
- package/package.json +1 -1
- package/src/components/editor/chrome/wrapper/__tests__/attachment-status.test.tsx +12 -18
- package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +12 -23
- package/src/core/attachments/state.ts +5 -8
- package/src/core/host/__tests__/attachments.test.ts +57 -0
- package/src/core/host/__tests__/notebook-client.test.ts +131 -1
- package/src/core/host/events.ts +1 -0
- package/src/core/host/notebook-client.ts +20 -2
- package/src/core/host/resources/attachments.ts +19 -0
- package/src/core/islands/__tests__/bootstrap.test.ts +0 -26
- package/src/core/islands/bootstrap.ts +0 -1
- package/src/core/runtime/__tests__/runtime.test.ts +1 -1
- package/src/core/runtime/runtime.ts +4 -3
- package/src/core/websocket/__tests__/useNotebookClient.hook.test.tsx +30 -0
- package/src/core/websocket/__tests__/useNotebookSession.hook.test.tsx +0 -171
- package/src/core/websocket/state.ts +7 -0
- package/src/core/websocket/useNotebookClient.ts +9 -1
- package/src/core/websocket/useNotebookSession.tsx +0 -8
- package/dist/toDate-UtiwmnH2.js +0 -705
|
@@ -8,13 +8,13 @@ import {
|
|
|
8
8
|
screen,
|
|
9
9
|
waitFor,
|
|
10
10
|
} from "@testing-library/react";
|
|
11
|
-
import { createStore, Provider } from "jotai";
|
|
11
|
+
import { atom, createStore, Provider } from "jotai";
|
|
12
12
|
import { userEvent } from "storybook/test";
|
|
13
13
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
14
14
|
import { PAIR_CONFIG } from "@/__tests__/fixtures/pair-config";
|
|
15
15
|
import { TooltipProvider } from "@/components/ui/tooltip";
|
|
16
16
|
import { toast } from "@/components/ui/use-toast";
|
|
17
|
-
import {
|
|
17
|
+
import type { Attachment } from "@/core/attachments/state";
|
|
18
18
|
import { pairConfigAtom } from "@/core/config/pair";
|
|
19
19
|
import {
|
|
20
20
|
type StableSessionId,
|
|
@@ -22,13 +22,16 @@ import {
|
|
|
22
22
|
} from "@/core/kernel/session";
|
|
23
23
|
import { API } from "@/core/network/api";
|
|
24
24
|
import { connectionAtom } from "@/core/network/connection";
|
|
25
|
-
import {
|
|
25
|
+
import { notebookClientAtom } from "@/core/websocket/state";
|
|
26
|
+
import { ConnectionState } from "@/core/websocket/types";
|
|
26
27
|
import { Deferred } from "@/utils/Deferred";
|
|
27
28
|
import { AttachmentStatus } from "../footer-items/attachment-status";
|
|
28
29
|
|
|
29
30
|
vi.mock("@/components/ui/use-toast", () => ({ toast: vi.fn() }));
|
|
30
31
|
vi.mock("@/core/network/api", () => ({ API: { post: vi.fn() } }));
|
|
31
32
|
|
|
33
|
+
const attachmentsAtom = atom<Attachment[]>([]);
|
|
34
|
+
|
|
32
35
|
const AGENT: Attachment = {
|
|
33
36
|
id: "a1",
|
|
34
37
|
kind: "agent",
|
|
@@ -41,6 +44,12 @@ function renderStatus(attachments: Attachment[] = [AGENT], preview = true) {
|
|
|
41
44
|
const store = createStore();
|
|
42
45
|
store.set(connectionAtom, { state: ConnectionState.OPEN });
|
|
43
46
|
store.set(pairConfigAtom, { ...PAIR_CONFIG, hostEnabled: preview });
|
|
47
|
+
store.set(notebookClientAtom, {
|
|
48
|
+
connectionAtom: atom({ state: ConnectionState.OPEN }),
|
|
49
|
+
documentAtom: atom(null),
|
|
50
|
+
attachmentsAtom,
|
|
51
|
+
reconnect: async () => undefined,
|
|
52
|
+
});
|
|
44
53
|
store.set(attachmentsAtom, attachments);
|
|
45
54
|
store.set(stableSessionIdAtom, "stable/test" as StableSessionId);
|
|
46
55
|
return {
|
|
@@ -342,21 +351,6 @@ describe("AttachmentStatus", () => {
|
|
|
342
351
|
).toBeDisabled();
|
|
343
352
|
});
|
|
344
353
|
|
|
345
|
-
it.each([
|
|
346
|
-
{ state: ConnectionState.CONNECTING },
|
|
347
|
-
{ state: ConnectionState.CLOSING },
|
|
348
|
-
{ state: ConnectionState.NOT_STARTED },
|
|
349
|
-
{
|
|
350
|
-
state: ConnectionState.CLOSED,
|
|
351
|
-
code: WebSocketClosedReason.KERNEL_DISCONNECTED,
|
|
352
|
-
reason: "offline",
|
|
353
|
-
},
|
|
354
|
-
])("hides connected claims while the browser is %j", (connection) => {
|
|
355
|
-
const { store, container } = renderStatus();
|
|
356
|
-
act(() => store.set(connectionAtom, connection));
|
|
357
|
-
expect(container).toBeEmptyDOMElement();
|
|
358
|
-
});
|
|
359
|
-
|
|
360
354
|
it("removes detached agents when the list is replaced", () => {
|
|
361
355
|
const { store, container } = renderStatus([
|
|
362
356
|
AGENT,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
screen,
|
|
9
9
|
waitFor,
|
|
10
10
|
} from "@testing-library/react";
|
|
11
|
-
import { createStore, Provider, useAtomValue } from "jotai";
|
|
11
|
+
import { atom, createStore, Provider, useAtomValue } from "jotai";
|
|
12
12
|
import type React from "react";
|
|
13
13
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
14
14
|
import { MockNotebook } from "@/__mocks__/notebook";
|
|
@@ -16,7 +16,7 @@ import { cellId } from "@/__tests__/branded";
|
|
|
16
16
|
import { PAIR_CONFIG } from "@/__tests__/fixtures/pair-config";
|
|
17
17
|
import { TooltipProvider } from "@/components/ui/tooltip";
|
|
18
18
|
import { toast } from "@/components/ui/use-toast";
|
|
19
|
-
import {
|
|
19
|
+
import type { Attachment } from "@/core/attachments/state";
|
|
20
20
|
import { exportedForTesting, notebookAtom } from "@/core/cells/cells";
|
|
21
21
|
import {
|
|
22
22
|
type CellOutputMessage,
|
|
@@ -32,7 +32,8 @@ import {
|
|
|
32
32
|
} from "@/core/kernel/session";
|
|
33
33
|
import { API } from "@/core/network/api";
|
|
34
34
|
import { connectionAtom } from "@/core/network/connection";
|
|
35
|
-
import {
|
|
35
|
+
import { notebookClientAtom } from "@/core/websocket/state";
|
|
36
|
+
import { ConnectionState } from "@/core/websocket/types";
|
|
36
37
|
import { Deferred } from "@/utils/Deferred";
|
|
37
38
|
import { HTTPError } from "@/utils/errors";
|
|
38
39
|
import { MarimoErrorOutput } from "../../output/MarimoErrorOutput";
|
|
@@ -48,6 +49,8 @@ vi.mock("@/components/editor/chrome/wrapper/useOpenAiAssistant", () => ({
|
|
|
48
49
|
|
|
49
50
|
const CELL_ID = cellId("test-cell");
|
|
50
51
|
const STABLE_ID = "stable/test" as StableSessionId;
|
|
52
|
+
const attachmentsAtom = atom<Attachment[]>([]);
|
|
53
|
+
|
|
51
54
|
const AGENT: Attachment = {
|
|
52
55
|
id: "a1",
|
|
53
56
|
kind: "agent",
|
|
@@ -93,6 +96,12 @@ function renderButton({
|
|
|
93
96
|
const store = createStore();
|
|
94
97
|
store.set(connectionAtom, { state: ConnectionState.OPEN });
|
|
95
98
|
store.set(pairConfigAtom, { ...PAIR_CONFIG, hostEnabled: preview });
|
|
99
|
+
store.set(notebookClientAtom, {
|
|
100
|
+
connectionAtom: atom({ state: ConnectionState.OPEN }),
|
|
101
|
+
documentAtom: atom(null),
|
|
102
|
+
attachmentsAtom,
|
|
103
|
+
reconnect: async () => undefined,
|
|
104
|
+
});
|
|
96
105
|
store.set(attachmentsAtom, attachments);
|
|
97
106
|
store.set(stableSessionIdAtom, stableId);
|
|
98
107
|
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
@@ -177,26 +186,6 @@ describe("SendErrorReportButton", () => {
|
|
|
177
186
|
expect(screen.getByRole("button")).toBeDisabled();
|
|
178
187
|
});
|
|
179
188
|
|
|
180
|
-
it.each([
|
|
181
|
-
{ state: ConnectionState.CONNECTING },
|
|
182
|
-
{ state: ConnectionState.CLOSING },
|
|
183
|
-
{ state: ConnectionState.NOT_STARTED },
|
|
184
|
-
{
|
|
185
|
-
state: ConnectionState.CLOSED,
|
|
186
|
-
code: WebSocketClosedReason.KERNEL_DISCONNECTED,
|
|
187
|
-
reason: "offline",
|
|
188
|
-
},
|
|
189
|
-
])(
|
|
190
|
-
"does not send from a stale snapshot while the browser is %j",
|
|
191
|
-
(connection) => {
|
|
192
|
-
const { store } = renderButton();
|
|
193
|
-
act(() => store.set(connectionAtom, connection));
|
|
194
|
-
expect(screen.getByRole("button")).toBeDisabled();
|
|
195
|
-
send();
|
|
196
|
-
expect(API.post).not.toHaveBeenCalled();
|
|
197
|
-
},
|
|
198
|
-
);
|
|
199
|
-
|
|
200
189
|
it.each([
|
|
201
190
|
[new HTTPError(409, "Conflict"), "No agent attached"],
|
|
202
191
|
[new HTTPError(500, "Server error"), "Could not send error"],
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import type { components } from "@marimo-team/marimo-api";
|
|
4
3
|
import { atom } from "jotai";
|
|
5
|
-
import {
|
|
4
|
+
import type { Attachment } from "@/core/host/protocol";
|
|
5
|
+
import { notebookClientAtom } from "@/core/websocket/state";
|
|
6
6
|
|
|
7
|
-
export type Attachment
|
|
7
|
+
export type { Attachment } from "@/core/host/protocol";
|
|
8
8
|
|
|
9
|
-
export const attachmentsAtom = atom<Attachment[]>([]);
|
|
10
9
|
export const agentAttachmentsAtom = atom((get) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
return get(attachmentsAtom).filter(
|
|
10
|
+
const notebook = get(notebookClientAtom);
|
|
11
|
+
return (notebook ? get(notebook.attachmentsAtom) : []).filter(
|
|
15
12
|
(attachment) => attachment.kind === "agent",
|
|
16
13
|
);
|
|
17
14
|
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { attachments } from "../resources/attachments";
|
|
5
|
+
import { createStream } from "../stream";
|
|
6
|
+
import { fixtureEvents } from "./fixtures";
|
|
7
|
+
|
|
8
|
+
const stream = createStream({ attachments });
|
|
9
|
+
const snapshot = fixtureEvents("notebook-events.sse");
|
|
10
|
+
const records = snapshot.flatMap((event) =>
|
|
11
|
+
event.event === "attachment" ? [event.data.attachment] : [],
|
|
12
|
+
);
|
|
13
|
+
const confirmed = () => snapshot.reduce(stream.reduce, stream.initial);
|
|
14
|
+
|
|
15
|
+
describe("attachment resource", () => {
|
|
16
|
+
it("collects snapshot records, replaces by id, and removes attachments", () => {
|
|
17
|
+
const state = confirmed();
|
|
18
|
+
expect(state.resources.attachments).toEqual(records);
|
|
19
|
+
const [browser, agent] = records;
|
|
20
|
+
const renamed = { ...agent, name: "Renamed agent" };
|
|
21
|
+
const updated = stream.reduce(state, {
|
|
22
|
+
event: "attachment",
|
|
23
|
+
id: "98",
|
|
24
|
+
data: { attachment: renamed },
|
|
25
|
+
});
|
|
26
|
+
expect(updated.resources.attachments).toEqual([browser, renamed]);
|
|
27
|
+
expect(state.resources.attachments).toEqual(records);
|
|
28
|
+
|
|
29
|
+
const removed = stream.reduce(updated, {
|
|
30
|
+
event: "attachment.removed",
|
|
31
|
+
id: "99",
|
|
32
|
+
data: { id: browser.id, time: "2026-10-01T09:30:00Z" },
|
|
33
|
+
});
|
|
34
|
+
expect(removed.resources.attachments).toEqual([renamed]);
|
|
35
|
+
const repeated = stream.reduce(removed, {
|
|
36
|
+
event: "attachment.removed",
|
|
37
|
+
id: "100",
|
|
38
|
+
data: { id: browser.id, time: "2026-10-01T09:30:00Z" },
|
|
39
|
+
});
|
|
40
|
+
expect(repeated.resources.attachments).toBe(removed.resources.attachments);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("retains records for replay and rebuilds them after reset", () => {
|
|
44
|
+
const state = confirmed();
|
|
45
|
+
expect(stream.resume(state)).toBe(state);
|
|
46
|
+
const reset = stream.reduce(state, { event: "reset", data: {} });
|
|
47
|
+
expect(reset.resources.attachments).toEqual([]);
|
|
48
|
+
const replacement = snapshot
|
|
49
|
+
.filter(
|
|
50
|
+
(event) =>
|
|
51
|
+
event.event !== "attachment" ||
|
|
52
|
+
event.data.attachment.id === records[0].id,
|
|
53
|
+
)
|
|
54
|
+
.reduce(stream.reduce, reset);
|
|
55
|
+
expect(replacement.resources.attachments).toEqual([records[0]]);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -8,7 +8,7 @@ import { Deferred } from "@/utils/Deferred";
|
|
|
8
8
|
import { jsonParseWithSpecialChar } from "@/utils/json/json-parser";
|
|
9
9
|
import { classifyCloseEvent } from "../../websocket/connection-state";
|
|
10
10
|
import { createNotebookClient } from "../notebook-client";
|
|
11
|
-
import { fixtureMessages } from "./fixtures";
|
|
11
|
+
import { fixtureEvents, fixtureMessages } from "./fixtures";
|
|
12
12
|
|
|
13
13
|
function notebookMessage(id: string) {
|
|
14
14
|
const notebook = {
|
|
@@ -301,3 +301,133 @@ describe("NotebookClient lifetime", () => {
|
|
|
301
301
|
second.abort();
|
|
302
302
|
});
|
|
303
303
|
});
|
|
304
|
+
|
|
305
|
+
async function open() {
|
|
306
|
+
const url = vi.fn(() => "ws://localhost/ws?session_id=first&cursor=999");
|
|
307
|
+
const setupResult = setup(url);
|
|
308
|
+
const lifetime = new AbortController();
|
|
309
|
+
setupResult.connect(lifetime.signal);
|
|
310
|
+
setupResult.healthy.resolve();
|
|
311
|
+
await setupResult.healthy.promise;
|
|
312
|
+
setupResult.events.dispatchEvent(new Event("open"));
|
|
313
|
+
return { ...setupResult, lifetime, url };
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
describe("NotebookClient attachments", () => {
|
|
317
|
+
const [browser, agent] = fixtureEvents("notebook-events.sse").flatMap(
|
|
318
|
+
(event) => (event.event === "attachment" ? [event.data.attachment] : []),
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
it("publishes a complete snapshot and applies live changes independently of kernel readiness", async () => {
|
|
322
|
+
const { client, store, receive, lifetime } = await open();
|
|
323
|
+
const snapshot = fixtureMessages("notebook-events.sse");
|
|
324
|
+
const readyIndex = snapshot.findIndex((event) => event.event === "ready");
|
|
325
|
+
snapshot.slice(0, readyIndex).forEach(receive);
|
|
326
|
+
expect(store.get(client.attachmentsAtom)).toEqual([]);
|
|
327
|
+
snapshot.slice(readyIndex).forEach(receive);
|
|
328
|
+
expect(store.get(client.attachmentsAtom)).toEqual([browser, agent]);
|
|
329
|
+
const renamed = { ...agent, name: "Renamed agent" };
|
|
330
|
+
receive({ event: "attachment", id: "98", data: { attachment: renamed } });
|
|
331
|
+
receive({
|
|
332
|
+
event: "attachment.removed",
|
|
333
|
+
id: "99",
|
|
334
|
+
data: { id: browser.id },
|
|
335
|
+
});
|
|
336
|
+
expect(store.get(client.attachmentsAtom)).toEqual([renamed]);
|
|
337
|
+
receive({ data: { op: "kernel-ready", resumed: false } });
|
|
338
|
+
expect(store.get(client.attachmentsAtom)).toEqual([renamed]);
|
|
339
|
+
receive({ event: "attachment.removed", id: "100", data: { id: agent.id } });
|
|
340
|
+
expect(store.get(client.attachmentsAtom)).toEqual([]);
|
|
341
|
+
lifetime.abort();
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it("resumes attachments alongside an incomplete document and waits for replay ready", async () => {
|
|
345
|
+
const { client, store, receive, events, urls, lifetime } = await open();
|
|
346
|
+
expect(urls[0].searchParams.has("cursor")).toBe(false);
|
|
347
|
+
fixtureMessages("notebook-events.sse").forEach(receive);
|
|
348
|
+
const confirmed = store.get(client.documentAtom);
|
|
349
|
+
const edits = fixtureMessages("edits.sse");
|
|
350
|
+
edits.slice(0, 3).forEach(receive);
|
|
351
|
+
const renamed = { ...agent, name: "Renamed agent" };
|
|
352
|
+
receive({ event: "attachment", id: "112a", data: { attachment: renamed } });
|
|
353
|
+
expect(store.get(client.attachmentsAtom)).toEqual([browser, renamed]);
|
|
354
|
+
events.dispatchEvent(new CloseEvent("close"));
|
|
355
|
+
expect(store.get(client.attachmentsAtom)).toEqual([]);
|
|
356
|
+
expect(urls.at(-1)!.searchParams.get("cursor")).toBe("112a");
|
|
357
|
+
events.dispatchEvent(new Event("open"));
|
|
358
|
+
expect(store.get(client.attachmentsAtom)).toEqual([]);
|
|
359
|
+
expect(store.get(client.documentAtom)).toBe(confirmed);
|
|
360
|
+
edits.slice(3).forEach(receive);
|
|
361
|
+
receive({
|
|
362
|
+
event: "attachment.removed",
|
|
363
|
+
id: "115",
|
|
364
|
+
data: { id: browser.id },
|
|
365
|
+
});
|
|
366
|
+
expect(store.get(client.attachmentsAtom)).toEqual([]);
|
|
367
|
+
receive({ event: "ready", id: "116", data: {} });
|
|
368
|
+
expect(store.get(client.attachmentsAtom)).toEqual([renamed]);
|
|
369
|
+
const revisions = fixtureEvents("edits.sse").flatMap((event) =>
|
|
370
|
+
event.event === "document" ? [event.data.document] : [],
|
|
371
|
+
);
|
|
372
|
+
expect(store.get(client.documentAtom)?.revision).toEqual(revisions.at(-1));
|
|
373
|
+
lifetime.abort();
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
it("replaces stale attachments with an empty snapshot after reset", async () => {
|
|
377
|
+
const { client, store, receive, lifetime } = await open();
|
|
378
|
+
fixtureMessages("notebook-events.sse").forEach(receive);
|
|
379
|
+
receive({ event: "reset", data: {} });
|
|
380
|
+
expect(store.get(client.attachmentsAtom)).toEqual([]);
|
|
381
|
+
fixtureMessages("notebook-events.sse")
|
|
382
|
+
.filter((event) => event.event !== "attachment")
|
|
383
|
+
.forEach(receive);
|
|
384
|
+
expect(store.get(client.attachmentsAtom)).toEqual([]);
|
|
385
|
+
lifetime.abort();
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it.each(["close", "error", "malformed", "removed", "abort", "identity"])(
|
|
389
|
+
"clears presence on %s and ignores messages after disposal",
|
|
390
|
+
async (reason) => {
|
|
391
|
+
const { client, store, receive, events, url, lifetime } = await open();
|
|
392
|
+
fixtureMessages("notebook-events.sse").forEach(receive);
|
|
393
|
+
expect(store.get(client.attachmentsAtom)).toEqual([browser, agent]);
|
|
394
|
+
switch (reason) {
|
|
395
|
+
case "close":
|
|
396
|
+
events.dispatchEvent(
|
|
397
|
+
new CloseEvent("close", { reason: "MARIMO_UNAUTHORIZED" }),
|
|
398
|
+
);
|
|
399
|
+
break;
|
|
400
|
+
case "error":
|
|
401
|
+
events.dispatchEvent(new Event("error"));
|
|
402
|
+
break;
|
|
403
|
+
case "malformed":
|
|
404
|
+
receive({ event: "attachment", id: "98", data: {} });
|
|
405
|
+
break;
|
|
406
|
+
case "removed":
|
|
407
|
+
receive({ event: "notebook.removed", id: "98", data: { id: "n1" } });
|
|
408
|
+
break;
|
|
409
|
+
case "identity":
|
|
410
|
+
url.mockReturnValue(
|
|
411
|
+
"ws://localhost/api/marimo/v1/notebooks/n2/events/ws",
|
|
412
|
+
);
|
|
413
|
+
events.dispatchEvent(new CloseEvent("close"));
|
|
414
|
+
receive({ event: "ready", id: "98", data: {} });
|
|
415
|
+
break;
|
|
416
|
+
default:
|
|
417
|
+
lifetime.abort();
|
|
418
|
+
}
|
|
419
|
+
expect(store.get(client.attachmentsAtom)).toEqual([]);
|
|
420
|
+
lifetime.abort();
|
|
421
|
+
fixtureMessages("notebook-events.sse").forEach(receive);
|
|
422
|
+
expect(store.get(client.attachmentsAtom)).toEqual([]);
|
|
423
|
+
},
|
|
424
|
+
);
|
|
425
|
+
|
|
426
|
+
it("keeps legacy sessions empty", async () => {
|
|
427
|
+
const { client, store, receive, lifetime } = await open();
|
|
428
|
+
receive({ data: { op: "kernel-ready" } });
|
|
429
|
+
receive({ data: { op: "reconnected" } });
|
|
430
|
+
expect(store.get(client.attachmentsAtom)).toEqual([]);
|
|
431
|
+
lifetime.abort();
|
|
432
|
+
});
|
|
433
|
+
});
|
package/src/core/host/events.ts
CHANGED
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
TransportReadyState,
|
|
12
12
|
} from "./connection";
|
|
13
13
|
import { parseNotebookEvent } from "./events";
|
|
14
|
+
import type { Attachment } from "./protocol";
|
|
15
|
+
import { attachments } from "./resources/attachments";
|
|
14
16
|
import { type Document, document } from "./resources/document";
|
|
15
17
|
import { createStream } from "./stream";
|
|
16
18
|
|
|
@@ -26,6 +28,8 @@ export interface NotebookClient {
|
|
|
26
28
|
* retains the last document. Partial updates are not exposed.
|
|
27
29
|
*/
|
|
28
30
|
readonly documentAtom: Atom<Document | null>;
|
|
31
|
+
/** Live attachments, empty until the stream is ready or while disconnected. */
|
|
32
|
+
readonly attachmentsAtom: Atom<readonly Attachment[]>;
|
|
29
33
|
/** Attempt to restore a closed connection after checking host health. */
|
|
30
34
|
reconnect(): Promise<void>;
|
|
31
35
|
}
|
|
@@ -60,15 +64,23 @@ export function createNotebookClient(store: ReturnType<typeof createStore>) {
|
|
|
60
64
|
state: ConnectionState.NOT_STARTED,
|
|
61
65
|
});
|
|
62
66
|
// One atom holds the whole stream, which resource atoms derive from.
|
|
63
|
-
const stream = createStream({ document });
|
|
67
|
+
const stream = createStream({ document, attachments });
|
|
64
68
|
const streamAtom = atom(stream.initial);
|
|
69
|
+
// A resumed stream is live, but presence waits for this connection's ready.
|
|
70
|
+
const readyAtom = atom(false);
|
|
65
71
|
const documentAtom = atom(
|
|
66
72
|
(get) => get(streamAtom).resources.document.current,
|
|
67
73
|
);
|
|
74
|
+
const attachmentsAtom = atom((get) =>
|
|
75
|
+
get(readyAtom) && get(connectionAtom).state === ConnectionState.OPEN
|
|
76
|
+
? get(streamAtom).resources.attachments
|
|
77
|
+
: attachments.initial,
|
|
78
|
+
);
|
|
68
79
|
let reconnect: (() => Promise<void>) | undefined;
|
|
69
80
|
const client: NotebookClient = {
|
|
70
81
|
connectionAtom,
|
|
71
82
|
documentAtom,
|
|
83
|
+
attachmentsAtom,
|
|
72
84
|
reconnect: async () => reconnect?.(),
|
|
73
85
|
};
|
|
74
86
|
|
|
@@ -111,14 +123,17 @@ export function createNotebookClient(store: ReturnType<typeof createStore>) {
|
|
|
111
123
|
? stream.resume(store.get(streamAtom))
|
|
112
124
|
: stream.initial;
|
|
113
125
|
streamKey = key;
|
|
126
|
+
store.set(readyAtom, false);
|
|
114
127
|
store.set(streamAtom, state);
|
|
115
128
|
if (state.cursor !== null) {
|
|
116
129
|
next.searchParams.set("cursor", state.cursor);
|
|
117
130
|
}
|
|
118
131
|
return next.toString();
|
|
119
132
|
});
|
|
120
|
-
const setStatus = (status: ConnectionStatus) =>
|
|
133
|
+
const setStatus = (status: ConnectionStatus) => {
|
|
134
|
+
store.set(readyAtom, false);
|
|
121
135
|
store.set(connectionAtom, status);
|
|
136
|
+
};
|
|
122
137
|
const disconnected = {
|
|
123
138
|
state: ConnectionState.CLOSED,
|
|
124
139
|
code: ConnectionClosedReason.KERNEL_DISCONNECTED,
|
|
@@ -174,6 +189,9 @@ export function createNotebookClient(store: ReturnType<typeof createStore>) {
|
|
|
174
189
|
try {
|
|
175
190
|
event = parseNotebookEvent(decodeJson(message.data));
|
|
176
191
|
store.set(streamAtom, stream.reduce(store.get(streamAtom), event));
|
|
192
|
+
if (event.event === "ready" || event.event === "reset") {
|
|
193
|
+
store.set(readyAtom, event.event === "ready");
|
|
194
|
+
}
|
|
177
195
|
} catch (error) {
|
|
178
196
|
Logger.error("Failed to decode notebook message", error);
|
|
179
197
|
if (messageFormat === "session") {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import type { Attachment } from "../protocol";
|
|
4
|
+
import type { Resource } from "./resource";
|
|
5
|
+
|
|
6
|
+
/** Attachment records retained with the stream's resume cursor. */
|
|
7
|
+
export const attachments: Resource<readonly Attachment[]> = {
|
|
8
|
+
initial: [],
|
|
9
|
+
on: {
|
|
10
|
+
attachment: (state, { data: { attachment } }) =>
|
|
11
|
+
state.some((item) => item.id === attachment.id)
|
|
12
|
+
? state.map((item) => (item.id === attachment.id ? attachment : item))
|
|
13
|
+
: [...state, attachment],
|
|
14
|
+
"attachment.removed": (state, { data }) =>
|
|
15
|
+
state.some((item) => item.id === data.id)
|
|
16
|
+
? state.filter((item) => item.id !== data.id)
|
|
17
|
+
: state,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
import { createStore } from "jotai";
|
|
4
4
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
5
5
|
import { RuntimeState } from "@/core/kernel/RuntimeState";
|
|
6
|
-
import { attachmentsAtom } from "@/core/attachments/state";
|
|
7
|
-
import { Logger } from "@/utils/Logger";
|
|
8
6
|
import { initializeIslands } from "../bootstrap";
|
|
9
7
|
import type { IslandsPyodideBridge } from "../bridge";
|
|
10
8
|
import { islandsHydratedAtom, islandsPendingInitialRunsAtom } from "../state";
|
|
@@ -50,30 +48,6 @@ describe("initializeIslands", () => {
|
|
|
50
48
|
expect(store.get(islandsHydratedAtom)).toBe(false);
|
|
51
49
|
store.set(islandsPendingInitialRunsAtom, new Set([1, 2]));
|
|
52
50
|
|
|
53
|
-
const errors = vi.spyOn(Logger, "error");
|
|
54
|
-
consumeMessage?.({
|
|
55
|
-
sessionGeneration: 1,
|
|
56
|
-
message: JSON.stringify({
|
|
57
|
-
op: "attachments",
|
|
58
|
-
data: {
|
|
59
|
-
op: "attachments",
|
|
60
|
-
attachments: [
|
|
61
|
-
{
|
|
62
|
-
id: "a1",
|
|
63
|
-
kind: "agent",
|
|
64
|
-
name: "Pi",
|
|
65
|
-
since: "2026-10-14T00:00:00Z",
|
|
66
|
-
notebook_id: "nb-test",
|
|
67
|
-
identity: "pi-thread",
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
},
|
|
71
|
-
}) as IslandsKernelMessage["message"],
|
|
72
|
-
});
|
|
73
|
-
expect(errors).not.toHaveBeenCalled();
|
|
74
|
-
expect(store.get(attachmentsAtom)).toEqual([]);
|
|
75
|
-
expect(store.get(islandsPendingInitialRunsAtom)).toEqual(new Set([1, 2]));
|
|
76
|
-
|
|
77
51
|
consumeMessage?.(completedRun(1));
|
|
78
52
|
expect(store.get(islandsHydratedAtom)).toBe(false);
|
|
79
53
|
|
|
@@ -78,7 +78,7 @@ describe("RuntimeManager", () => {
|
|
|
78
78
|
"wss://example.com/nested/api/marimo/v1/notebooks/nb_123/events/ws",
|
|
79
79
|
params: {
|
|
80
80
|
file: "notebook.py",
|
|
81
|
-
types: "marimo",
|
|
81
|
+
types: "notebook,document,cell,attachment,marimo",
|
|
82
82
|
session_id: sessionId,
|
|
83
83
|
access_token: "test-token",
|
|
84
84
|
},
|
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
import { Deferred } from "@/utils/Deferred";
|
|
4
4
|
import { Logger } from "@/utils/Logger";
|
|
5
5
|
import { KnownQueryParams } from "../constants";
|
|
6
|
+
import { NOTEBOOK_EVENT_TYPES } from "../host/events";
|
|
6
7
|
import { isIslands } from "../islands/utils";
|
|
7
8
|
import { getSessionId, type SessionId } from "../kernel/session";
|
|
8
9
|
import { isStaticNotebook } from "../static/static-state";
|
|
9
10
|
import { isWasm } from "../wasm/utils";
|
|
10
11
|
import type { RuntimeConfig } from "./types";
|
|
11
12
|
|
|
12
|
-
const HOST_EVENT_TYPES = ["marimo"];
|
|
13
|
-
|
|
14
13
|
export class RuntimeManager {
|
|
15
14
|
private initialHealthyCheck = new Deferred<void>();
|
|
16
15
|
private config: RuntimeConfig;
|
|
@@ -165,7 +164,7 @@ export class RuntimeManager {
|
|
|
165
164
|
const url = this.formatWsURL(path, searchParams);
|
|
166
165
|
if (notebookId) {
|
|
167
166
|
// TODO(MO-8034): Separate host options from notebook query params.
|
|
168
|
-
url.searchParams.set("types",
|
|
167
|
+
url.searchParams.set("types", NOTEBOOK_EVENT_TYPES.join(","));
|
|
169
168
|
}
|
|
170
169
|
return url;
|
|
171
170
|
}
|
|
@@ -177,6 +176,8 @@ export class RuntimeManager {
|
|
|
177
176
|
* (see `headers()`) instead of the URL.
|
|
178
177
|
*/
|
|
179
178
|
public getSseURL(sessionId: SessionId): URL {
|
|
179
|
+
// TODO: Migrate editor SSE to the host event stream. Until then, host
|
|
180
|
+
// state such as attachments is unavailable on this legacy connection.
|
|
180
181
|
const url = this.formatHttpURL({
|
|
181
182
|
path: "/sse",
|
|
182
183
|
searchParams: this.getSessionSearchParams(sessionId),
|
|
@@ -9,6 +9,9 @@ import { ConnectionState } from "../types";
|
|
|
9
9
|
import { createConnectionTransport } from "../transports/create";
|
|
10
10
|
import type { IConnectionTransport } from "../transports/transport";
|
|
11
11
|
import { useNotebookClient } from "../useNotebookClient";
|
|
12
|
+
import { fixtureMessages } from "../../host/__tests__/fixtures";
|
|
13
|
+
import { agentAttachmentsAtom } from "../../attachments/state";
|
|
14
|
+
import { notebookClientAtom } from "../state";
|
|
12
15
|
|
|
13
16
|
vi.mock("../transports/create", () => ({ createConnectionTransport: vi.fn() }));
|
|
14
17
|
|
|
@@ -30,6 +33,10 @@ function makeTransport() {
|
|
|
30
33
|
};
|
|
31
34
|
return {
|
|
32
35
|
transport,
|
|
36
|
+
receive: (message: unknown) =>
|
|
37
|
+
events.dispatchEvent(
|
|
38
|
+
new MessageEvent("message", { data: JSON.stringify(message) }),
|
|
39
|
+
),
|
|
33
40
|
notify: () =>
|
|
34
41
|
events.dispatchEvent(
|
|
35
42
|
new MessageEvent("message", {
|
|
@@ -72,6 +79,29 @@ beforeEach(() => {
|
|
|
72
79
|
});
|
|
73
80
|
|
|
74
81
|
describe("useNotebookClient", () => {
|
|
82
|
+
it("exposes host presence to the UI without waiting for kernel-ready", async () => {
|
|
83
|
+
const transport = makeTransport();
|
|
84
|
+
vi.mocked(createConnectionTransport).mockReturnValue(transport.transport);
|
|
85
|
+
const { result, store, unmount } = setup();
|
|
86
|
+
await act(async () => Promise.resolve());
|
|
87
|
+
expect(store.get(notebookClientAtom)).toBe(result.current);
|
|
88
|
+
act(() =>
|
|
89
|
+
fixtureMessages("notebook-events.sse").forEach(transport.receive),
|
|
90
|
+
);
|
|
91
|
+
expect(store.get(agentAttachmentsAtom)).toEqual([
|
|
92
|
+
{
|
|
93
|
+
id: "a2",
|
|
94
|
+
notebook_id: "n1",
|
|
95
|
+
kind: "agent",
|
|
96
|
+
name: "Notebook CLI",
|
|
97
|
+
since: "2026-10-01T09:20:03Z",
|
|
98
|
+
},
|
|
99
|
+
]);
|
|
100
|
+
unmount();
|
|
101
|
+
expect(store.get(notebookClientAtom)).toBeNull();
|
|
102
|
+
expect(store.get(agentAttachmentsAtom)).toEqual([]);
|
|
103
|
+
});
|
|
104
|
+
|
|
75
105
|
it("uses current callbacks and URL providers without reconnecting on a rerender", async () => {
|
|
76
106
|
const first = makeTransport();
|
|
77
107
|
vi.mocked(createConnectionTransport).mockReturnValue(first.transport);
|