@marimo-team/islands 0.25.3-dev40 → 0.25.3-dev44
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/{ErrorBoundary-C7__jAZL.js → ErrorBoundary-C0Oq0jHx.js} +1 -1
- package/dist/{chat-ui-DGpBSln7.js → chat-ui-DlUp75HS.js} +4 -4
- package/dist/{code-visibility-DO4MlViW.js → code-visibility-B1eNzkOg.js} +3 -3
- package/dist/{common-Ci7TC3e0.js → common-pqD_dOGD.js} +70 -71
- package/dist/{data-grid-overlay-editor-DpH_AKdC.js → data-grid-overlay-editor-pTWEP43w.js} +1 -1
- package/dist/{error-entries-D576fzV9.js → error-entries-D3ouOLDe.js} +1 -1
- package/dist/{feedback-button-BV5AJ3nl.js → feedback-button-dWEWzzD4.js} +3 -3
- package/dist/{formats-DIVMVjeV.js → formats-C24TvExI.js} +1 -1
- package/dist/{glide-data-editor-CRK-O0KE.js → glide-data-editor-DBnOUonk.js} +3 -3
- package/dist/{globals-H_ILLmr7.js → globals-DYaD1Xz7.js} +1 -1
- package/dist/{html-to-image-D3m5Ob5H.js → html-to-image-VZvb968z.js} +2 -2
- package/dist/main.js +13 -13
- package/dist/{number-overlay-editor-BQ2UqdED.js → number-overlay-editor-BURiB1Nu.js} +1 -1
- package/dist/{process-output-C6qc7hPS.js → process-output-CCPgTShO.js} +2 -2
- package/dist/{reveal-component-Cs-0GwxY.js → reveal-component-s74n77kc.js} +4 -4
- package/dist/style.css +1 -1
- package/dist/{toDate-CSY-j1Fi.js → toDate-C0jaysq2.js} +93 -94
- package/dist/{vega-component-Df45z17m.js → vega-component-CF9IzE2r.js} +2 -2
- package/package.json +2 -4
- package/src/__tests__/host-imports.test.ts +1 -0
- package/src/components/data-table/__tests__/export-actions.test.tsx +88 -0
- package/src/components/data-table/export-actions.tsx +71 -45
- package/src/core/attachments/state.ts +2 -2
- package/src/core/host/AGENTS.md +6 -2
- package/src/core/host/__tests__/attachments.test.ts +9 -10
- package/src/core/host/__tests__/document.test.ts +18 -16
- package/src/core/host/__tests__/events.test.ts +5 -2
- package/src/core/host/__tests__/fixtures.ts +6 -4
- package/src/core/host/events.ts +18 -2
- package/src/core/host/notebook-client.ts +46 -13
- package/src/core/host/resources/attachments.ts +3 -3
- package/src/core/host/resources/document.ts +3 -3
- package/src/core/websocket/__tests__/useNotebookSession.hook.test.tsx +1 -1
- package/src/core/host/__tests__/protocol.test.ts +0 -229
- package/src/core/host/__tests__/stream.test.ts +0 -209
- package/src/core/host/protocol.ts +0 -1948
- package/src/core/host/resources/resource.ts +0 -47
- package/src/core/host/stream.ts +0 -211
|
@@ -761,7 +761,10 @@ export const ExportActions: React.FC<ExportActionProps> = (props) => {
|
|
|
761
761
|
const expanded =
|
|
762
762
|
configurableFormat !== null &&
|
|
763
763
|
expandedFormat === configurableFormat;
|
|
764
|
+
const FormatHeader = configurableFormat ? "button" : "div";
|
|
764
765
|
const panelId = `export-options-${option.format}`;
|
|
766
|
+
const descriptionId = `${panelId}-description`;
|
|
767
|
+
const summaryId = `${panelId}-summary`;
|
|
765
768
|
const rowFailure =
|
|
766
769
|
failure?.action.format === option.format ? failure : null;
|
|
767
770
|
const summary =
|
|
@@ -802,55 +805,78 @@ export const ExportActions: React.FC<ExportActionProps> = (props) => {
|
|
|
802
805
|
data-testid={`export-row-${option.format}`}
|
|
803
806
|
className={cn(expanded && "bg-muted/40")}
|
|
804
807
|
>
|
|
805
|
-
<div className="grid
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
808
|
+
<div className="grid grid-cols-[minmax(0,1fr)_auto] items-center hover:bg-accent/50">
|
|
809
|
+
<FormatHeader
|
|
810
|
+
type={configurableFormat ? "button" : undefined}
|
|
811
|
+
className={cn(
|
|
812
|
+
"grid min-h-[60px] min-w-0 grid-cols-[28px_minmax(0,1fr)] items-center gap-x-1 py-2 pl-2.5 pr-1 text-left",
|
|
813
|
+
configurableFormat &&
|
|
814
|
+
"cursor-pointer focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring",
|
|
815
|
+
)}
|
|
816
|
+
aria-label={
|
|
817
|
+
configurableFormat ? `${optionLabel} options` : undefined
|
|
818
|
+
}
|
|
819
|
+
aria-describedby={
|
|
820
|
+
configurableFormat
|
|
821
|
+
? [descriptionId, summary && summaryId]
|
|
822
|
+
.filter(Boolean)
|
|
823
|
+
.join(" ")
|
|
824
|
+
: undefined
|
|
825
|
+
}
|
|
826
|
+
aria-expanded={configurableFormat ? expanded : undefined}
|
|
827
|
+
aria-controls={configurableFormat ? panelId : undefined}
|
|
828
|
+
onClick={
|
|
829
|
+
configurableFormat
|
|
830
|
+
? () => toggleExpanded(option.format)
|
|
831
|
+
: undefined
|
|
832
|
+
}
|
|
833
|
+
>
|
|
834
|
+
<span
|
|
835
|
+
aria-hidden={true}
|
|
836
|
+
className="inline-flex h-6 w-6 items-center justify-center"
|
|
815
837
|
>
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
838
|
+
{configurableFormat && (
|
|
839
|
+
<ChevronRightIcon
|
|
840
|
+
className={cn(
|
|
841
|
+
"h-4 w-4 text-muted-foreground transition-transform",
|
|
842
|
+
expanded && "rotate-90",
|
|
843
|
+
)}
|
|
844
|
+
/>
|
|
845
|
+
)}
|
|
846
|
+
</span>
|
|
847
|
+
<span className="flex min-w-0 items-center gap-3 pl-1">
|
|
848
|
+
<option.icon
|
|
849
|
+
aria-hidden={true}
|
|
850
|
+
data-testid={`export-format-icon-${option.format}`}
|
|
851
|
+
className="h-4 w-4 shrink-0 text-muted-foreground"
|
|
821
852
|
/>
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
<div className="flex min-w-0 items-center gap-3 pl-1">
|
|
827
|
-
<option.icon
|
|
828
|
-
aria-hidden={true}
|
|
829
|
-
data-testid={`export-format-icon-${option.format}`}
|
|
830
|
-
className="h-4 w-4 shrink-0 text-muted-foreground"
|
|
831
|
-
/>
|
|
832
|
-
<div className="grid min-w-0 gap-1">
|
|
833
|
-
<span className="flex min-w-0 items-baseline gap-x-2">
|
|
834
|
-
<span className="text-sm font-medium leading-tight">
|
|
835
|
-
{optionLabel}
|
|
836
|
-
</span>
|
|
837
|
-
{summary && (
|
|
838
|
-
<span
|
|
839
|
-
data-testid={`export-summary-${option.format}`}
|
|
840
|
-
className="min-w-0 truncate text-xs text-muted-foreground"
|
|
841
|
-
>
|
|
842
|
-
{summary}
|
|
853
|
+
<span className="grid min-w-0 gap-1">
|
|
854
|
+
<span className="flex min-w-0 items-baseline gap-x-2">
|
|
855
|
+
<span className="text-sm font-medium leading-tight">
|
|
856
|
+
{optionLabel}
|
|
843
857
|
</span>
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
858
|
+
{summary && (
|
|
859
|
+
<span
|
|
860
|
+
id={summaryId}
|
|
861
|
+
data-testid={`export-summary-${option.format}`}
|
|
862
|
+
className="min-w-0 truncate text-xs text-muted-foreground"
|
|
863
|
+
>
|
|
864
|
+
{summary}
|
|
865
|
+
</span>
|
|
866
|
+
)}
|
|
867
|
+
</span>
|
|
868
|
+
<span
|
|
869
|
+
id={descriptionId}
|
|
870
|
+
className="text-xs text-muted-foreground leading-tight"
|
|
871
|
+
>
|
|
872
|
+
{option.format === "parquet" && hasGeometry
|
|
873
|
+
? "Parquet with geometry and CRS metadata"
|
|
874
|
+
: option.description}
|
|
875
|
+
</span>
|
|
850
876
|
</span>
|
|
851
|
-
</
|
|
852
|
-
</
|
|
853
|
-
<div className="flex items-center gap-0.5">
|
|
877
|
+
</span>
|
|
878
|
+
</FormatHeader>
|
|
879
|
+
<div className="flex items-center gap-0.5 pr-2.5">
|
|
854
880
|
<Tooltip
|
|
855
881
|
content={
|
|
856
882
|
option.canDownload
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
3
|
import { atom } from "jotai";
|
|
4
|
-
import type { Attachment } from "
|
|
4
|
+
import type { Attachment } from "@marimo-team/client/protocol";
|
|
5
5
|
import { notebookClientAtom } from "@/core/websocket/state";
|
|
6
6
|
|
|
7
|
-
export type { Attachment } from "
|
|
7
|
+
export type { Attachment } from "@marimo-team/client/protocol";
|
|
8
8
|
|
|
9
9
|
export const agentAttachmentsAtom = atom((get) => {
|
|
10
10
|
const notebook = get(notebookClientAtom);
|
package/src/core/host/AGENTS.md
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
# Host core
|
|
2
2
|
|
|
3
|
-
Production code may import host modules,
|
|
4
|
-
`@/utils/Logger`. Enforced by
|
|
3
|
+
Production code may import host modules, `@marimo-team/client`,
|
|
4
|
+
`jotai/vanilla`, `zod`, and `@/utils/Logger`. Enforced by
|
|
5
|
+
`marimo/host-imports`. Tests are exempt.
|
|
6
|
+
|
|
7
|
+
The protocol schemas and types live in `@marimo-team/client/protocol`.
|
|
8
|
+
The native `marimo` event is a marimo extension and is defined in `events.ts`.
|
|
5
9
|
|
|
6
10
|
Define interfaces here and inject application behavior through adapters.
|
|
7
11
|
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
4
|
import { attachments } from "../resources/attachments";
|
|
5
|
-
import {
|
|
5
|
+
import { createReducer } from "@marimo-team/client/reducer";
|
|
6
6
|
import { fixtureEvents } from "./fixtures";
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const reducer = createReducer({ attachments });
|
|
9
9
|
const snapshot = fixtureEvents("notebook-events.sse");
|
|
10
10
|
const records = snapshot.flatMap((event) =>
|
|
11
11
|
event.event === "attachment" ? [event.data.attachment] : [],
|
|
12
12
|
);
|
|
13
|
-
const confirmed = () => snapshot.reduce(
|
|
13
|
+
const confirmed = () => snapshot.reduce(reducer.reduce, reducer.initial);
|
|
14
14
|
|
|
15
15
|
describe("attachment resource", () => {
|
|
16
16
|
it("collects snapshot records, replaces by id, and removes attachments", () => {
|
|
@@ -18,7 +18,7 @@ describe("attachment resource", () => {
|
|
|
18
18
|
expect(state.resources.attachments).toEqual(records);
|
|
19
19
|
const [browser, agent] = records;
|
|
20
20
|
const renamed = { ...agent, name: "Renamed agent" };
|
|
21
|
-
const updated =
|
|
21
|
+
const updated = reducer.reduce(state, {
|
|
22
22
|
event: "attachment",
|
|
23
23
|
id: "98",
|
|
24
24
|
data: { attachment: renamed },
|
|
@@ -26,13 +26,13 @@ describe("attachment resource", () => {
|
|
|
26
26
|
expect(updated.resources.attachments).toEqual([browser, renamed]);
|
|
27
27
|
expect(state.resources.attachments).toEqual(records);
|
|
28
28
|
|
|
29
|
-
const removed =
|
|
29
|
+
const removed = reducer.reduce(updated, {
|
|
30
30
|
event: "attachment.removed",
|
|
31
31
|
id: "99",
|
|
32
32
|
data: { id: browser.id, time: "2026-10-01T09:30:00Z" },
|
|
33
33
|
});
|
|
34
34
|
expect(removed.resources.attachments).toEqual([renamed]);
|
|
35
|
-
const repeated =
|
|
35
|
+
const repeated = reducer.reduce(removed, {
|
|
36
36
|
event: "attachment.removed",
|
|
37
37
|
id: "100",
|
|
38
38
|
data: { id: browser.id, time: "2026-10-01T09:30:00Z" },
|
|
@@ -40,10 +40,9 @@ describe("attachment resource", () => {
|
|
|
40
40
|
expect(repeated.resources.attachments).toBe(removed.resources.attachments);
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
it("
|
|
43
|
+
it("rebuilds records after reset", () => {
|
|
44
44
|
const state = confirmed();
|
|
45
|
-
|
|
46
|
-
const reset = stream.reduce(state, { event: "reset", data: {} });
|
|
45
|
+
const reset = reducer.reduce(state, { event: "reset", data: {} });
|
|
47
46
|
expect(reset.resources.attachments).toEqual([]);
|
|
48
47
|
const replacement = snapshot
|
|
49
48
|
.filter(
|
|
@@ -51,7 +50,7 @@ describe("attachment resource", () => {
|
|
|
51
50
|
event.event !== "attachment" ||
|
|
52
51
|
event.data.attachment.id === records[0].id,
|
|
53
52
|
)
|
|
54
|
-
.reduce(
|
|
53
|
+
.reduce(reducer.reduce, reset);
|
|
55
54
|
expect(replacement.resources.attachments).toEqual([records[0]]);
|
|
56
55
|
});
|
|
57
56
|
});
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
|
-
import type
|
|
4
|
+
import type * as Protocol from "@marimo-team/client/protocol";
|
|
5
5
|
import { document } from "../resources/document";
|
|
6
|
-
import {
|
|
6
|
+
import { createReducer } from "@marimo-team/client/reducer";
|
|
7
7
|
import { fixtureEvents } from "./fixtures";
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const reducer = createReducer({ document });
|
|
10
10
|
const snapshot = fixtureEvents("notebook-events.sse");
|
|
11
11
|
const edits = fixtureEvents("edits.sse");
|
|
12
12
|
|
|
13
|
-
function replay(
|
|
14
|
-
|
|
13
|
+
function replay(
|
|
14
|
+
events: readonly Protocol.EventOutput[],
|
|
15
|
+
from = reducer.initial,
|
|
16
|
+
) {
|
|
17
|
+
return events.reduce((state, event) => reducer.reduce(state, event), from);
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
const confirmed = () => replay(snapshot);
|
|
@@ -33,12 +36,12 @@ describe("document resource", () => {
|
|
|
33
36
|
confirmed(),
|
|
34
37
|
);
|
|
35
38
|
expect(current(pending)).toEqual(first);
|
|
36
|
-
const changed =
|
|
39
|
+
const changed = reducer.reduce(pending, edit);
|
|
37
40
|
expect(current(changed)?.revision).toEqual(edit.data.document);
|
|
38
41
|
expect([...current(changed)!.cells.keys()].toSorted()).toEqual(
|
|
39
42
|
edit.data.document.order.toSorted(),
|
|
40
43
|
);
|
|
41
|
-
const saved = current(
|
|
44
|
+
const saved = current(reducer.reduce(changed, save));
|
|
42
45
|
expect(saved?.revision).toEqual(save.data.document);
|
|
43
46
|
expect(saved?.cells.get("c3")?.code).toBe("x = 22");
|
|
44
47
|
expect(saved?.cells.has("k7f2")).toBe(false);
|
|
@@ -55,7 +58,7 @@ describe("document resource", () => {
|
|
|
55
58
|
order: revision.order.toReversed(),
|
|
56
59
|
version: revision.version + 1,
|
|
57
60
|
};
|
|
58
|
-
const changed =
|
|
61
|
+
const changed = reducer.reduce(state, {
|
|
59
62
|
event: "document",
|
|
60
63
|
data: { document: reordered },
|
|
61
64
|
id: "200",
|
|
@@ -66,17 +69,17 @@ describe("document resource", () => {
|
|
|
66
69
|
});
|
|
67
70
|
|
|
68
71
|
const empty = { ...revision, order: [] };
|
|
69
|
-
const opening =
|
|
72
|
+
const opening = reducer.reduce(reducer.initial, {
|
|
70
73
|
event: "document",
|
|
71
74
|
data: { document: empty },
|
|
72
75
|
});
|
|
73
76
|
expect(current(opening)).toBeNull();
|
|
74
77
|
expect(
|
|
75
|
-
current(
|
|
78
|
+
current(reducer.reduce(opening, { event: "ready", data: {}, id: "0" })),
|
|
76
79
|
).toEqual({ revision: empty, cells: new Map() });
|
|
77
80
|
expect(
|
|
78
81
|
current(
|
|
79
|
-
|
|
82
|
+
reducer.reduce(reducer.initial, { event: "ready", data: {}, id: "0" }),
|
|
80
83
|
),
|
|
81
84
|
).toBeNull();
|
|
82
85
|
});
|
|
@@ -89,7 +92,6 @@ describe("document resource", () => {
|
|
|
89
92
|
}
|
|
90
93
|
const partial = replay([cell, removed], state);
|
|
91
94
|
expect(current(partial)).toBe(current(state));
|
|
92
|
-
expect(stream.resume(partial)).toBe(partial);
|
|
93
95
|
const completed = replay(
|
|
94
96
|
[published, { event: "ready", data: {}, id: "113" }],
|
|
95
97
|
partial,
|
|
@@ -98,7 +100,7 @@ describe("document resource", () => {
|
|
|
98
100
|
});
|
|
99
101
|
|
|
100
102
|
it("removes a notebook without waiting for individual cell removals", () => {
|
|
101
|
-
const removed =
|
|
103
|
+
const removed = reducer.reduce(confirmed(), {
|
|
102
104
|
event: "notebook.removed",
|
|
103
105
|
data: { id: "n1", time: "2026-10-01T09:30:00Z" },
|
|
104
106
|
id: "200",
|
|
@@ -110,15 +112,15 @@ describe("document resource", () => {
|
|
|
110
112
|
const state = confirmed();
|
|
111
113
|
const revision = current(state)!.revision;
|
|
112
114
|
expect(() =>
|
|
113
|
-
|
|
115
|
+
reducer.reduce(state, {
|
|
114
116
|
event: "document",
|
|
115
117
|
data: { document: { ...revision, order: ["missing"] } },
|
|
116
118
|
id: "200",
|
|
117
119
|
}),
|
|
118
120
|
).toThrow("Document records do not match");
|
|
119
|
-
const partial =
|
|
121
|
+
const partial = reducer.reduce(state, edits[0]);
|
|
120
122
|
expect(() =>
|
|
121
|
-
|
|
123
|
+
reducer.reduce(partial, { event: "ready", data: {}, id: "200" }),
|
|
122
124
|
).toThrow("incomplete document update");
|
|
123
125
|
});
|
|
124
126
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { describe, expect, expectTypeOf, it } from "vitest";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
import { parseNotebookEvent } from "../events";
|
|
5
|
+
import { type NotebookEvent, parseNotebookEvent } from "../events";
|
|
6
6
|
|
|
7
7
|
describe("notebook messages", () => {
|
|
8
8
|
it("normalizes session and host envelopes for native marimo messages", () => {
|
|
@@ -10,6 +10,9 @@ describe("notebook messages", () => {
|
|
|
10
10
|
op: "variables",
|
|
11
11
|
variables: [{ name: "x", value: Number.NaN }],
|
|
12
12
|
};
|
|
13
|
+
expectTypeOf<
|
|
14
|
+
Extract<NotebookEvent, { event: "marimo" }>["data"]["marimo"]
|
|
15
|
+
>().toBeUnknown();
|
|
13
16
|
const host = { event: "marimo", data: { marimo: notification } };
|
|
14
17
|
expect(parseNotebookEvent({ data: notification })).toEqual(host);
|
|
15
18
|
expect(parseNotebookEvent({ ...host, id: "42" })).toEqual({
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import NodeFs from "node:fs";
|
|
4
4
|
import NodeUrl from "node:url";
|
|
5
|
-
import
|
|
5
|
+
import * as Protocol from "@marimo-team/client/protocol";
|
|
6
6
|
|
|
7
7
|
/** Read the protocol's portable examples as transport messages. */
|
|
8
8
|
export function fixtureMessages(name: string) {
|
|
@@ -33,7 +33,9 @@ export function fixtureMessages(name: string) {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
/** Read the protocol's portable examples as decoded
|
|
37
|
-
export function fixtureEvents(name: string):
|
|
38
|
-
return fixtureMessages(name).map(
|
|
36
|
+
/** Read the protocol's portable examples as decoded protocol events. */
|
|
37
|
+
export function fixtureEvents(name: string): Protocol.EventOutput[] {
|
|
38
|
+
return fixtureMessages(name).map(({ id, ...message }) =>
|
|
39
|
+
Protocol.Event.parse(id === undefined ? message : { ...message, id }),
|
|
40
|
+
);
|
|
39
41
|
}
|
package/src/core/host/events.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import * as Protocol from "
|
|
4
|
+
import * as Protocol from "@marimo-team/client/protocol";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Notebook stream events, including native marimo notifications.
|
|
@@ -29,16 +29,29 @@ const knownNames = new Set<string>(
|
|
|
29
29
|
Protocol.Event.options.flatMap((schema) => schema.shape.event.options),
|
|
30
30
|
);
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* A native marimo message carried by a host stream.
|
|
34
|
+
*
|
|
35
|
+
* The protocol leaves extension events to their producer. The payload is
|
|
36
|
+
* passed through for the session handler to interpret.
|
|
37
|
+
*/
|
|
38
|
+
const MarimoEvent = z.object({
|
|
39
|
+
event: z.literal("marimo"),
|
|
40
|
+
id: z.string().min(1).optional(),
|
|
41
|
+
data: z.object({ marimo: z.unknown() }),
|
|
42
|
+
});
|
|
43
|
+
|
|
32
44
|
/** A decoded event, or the name and cursor of an unrecognized event. */
|
|
33
45
|
export type NotebookEvent =
|
|
34
46
|
| Protocol.EventOutput
|
|
47
|
+
| z.output<typeof MarimoEvent>
|
|
35
48
|
| {
|
|
36
49
|
readonly event: "unknown";
|
|
37
50
|
readonly name: string;
|
|
38
51
|
readonly id?: string;
|
|
39
52
|
};
|
|
40
53
|
|
|
41
|
-
const sessionEnvelope = z.object({ data:
|
|
54
|
+
const sessionEnvelope = z.object({ data: z.unknown() });
|
|
42
55
|
|
|
43
56
|
/**
|
|
44
57
|
* Decode a host event or a legacy `{ data: notification }` session message.
|
|
@@ -54,6 +67,9 @@ export function parseNotebookEvent(value: unknown): NotebookEvent {
|
|
|
54
67
|
};
|
|
55
68
|
}
|
|
56
69
|
const parsed = envelope.parse(value);
|
|
70
|
+
if (parsed.event === "marimo") {
|
|
71
|
+
return MarimoEvent.parse(parsed);
|
|
72
|
+
}
|
|
57
73
|
if (knownNames.has(parsed.event)) {
|
|
58
74
|
return Protocol.Event.parse(parsed);
|
|
59
75
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
3
|
import { Logger } from "@/utils/Logger";
|
|
4
|
+
import type { Attachment } from "@marimo-team/client/protocol";
|
|
5
|
+
import { createReducer } from "@marimo-team/client/reducer";
|
|
4
6
|
import { type Atom, atom, type createStore } from "jotai/vanilla";
|
|
5
7
|
import {
|
|
6
8
|
type ConnectionStatus,
|
|
@@ -10,11 +12,16 @@ import {
|
|
|
10
12
|
type NotebookTransport,
|
|
11
13
|
TransportReadyState,
|
|
12
14
|
} from "./connection";
|
|
13
|
-
import { parseNotebookEvent } from "./events";
|
|
14
|
-
import type { Attachment } from "./protocol";
|
|
15
|
+
import { type NotebookEvent, parseNotebookEvent } from "./events";
|
|
15
16
|
import { attachments } from "./resources/attachments";
|
|
16
17
|
import { type Document, document } from "./resources/document";
|
|
17
|
-
|
|
18
|
+
|
|
19
|
+
/** Events that may arrive without a cursor after `ready`. */
|
|
20
|
+
const UNCURSORED = new Set<NotebookEvent["event"]>([
|
|
21
|
+
"reset",
|
|
22
|
+
"marimo",
|
|
23
|
+
"unknown",
|
|
24
|
+
]);
|
|
18
25
|
|
|
19
26
|
/** A connection to a notebook on a marimo host. */
|
|
20
27
|
export interface NotebookClient {
|
|
@@ -64,8 +71,8 @@ export function createNotebookClient(store: ReturnType<typeof createStore>) {
|
|
|
64
71
|
state: ConnectionState.NOT_STARTED,
|
|
65
72
|
});
|
|
66
73
|
// One atom holds the whole stream, which resource atoms derive from.
|
|
67
|
-
const
|
|
68
|
-
const streamAtom = atom(
|
|
74
|
+
const reducer = createReducer({ document, attachments });
|
|
75
|
+
const streamAtom = atom(reducer.initial);
|
|
69
76
|
// A resumed stream is live, but presence waits for this connection's ready.
|
|
70
77
|
const readyAtom = atom(false);
|
|
71
78
|
const documentAtom = atom(
|
|
@@ -103,6 +110,8 @@ export function createNotebookClient(store: ReturnType<typeof createStore>) {
|
|
|
103
110
|
let terminal = false;
|
|
104
111
|
let checkingHealth = false;
|
|
105
112
|
let streamKey: string | undefined;
|
|
113
|
+
// The id of the last live event. Null before `ready` and after `reset`.
|
|
114
|
+
let cursor: string | null = null;
|
|
106
115
|
const transport = createTransport(() => {
|
|
107
116
|
if (messageFormat === "session") {
|
|
108
117
|
return url();
|
|
@@ -118,15 +127,23 @@ export function createNotebookClient(store: ReturnType<typeof createStore>) {
|
|
|
118
127
|
identity.searchParams.delete("access_token");
|
|
119
128
|
identity.searchParams.sort();
|
|
120
129
|
const key = identity.toString();
|
|
130
|
+
const current = store.get(streamAtom);
|
|
131
|
+
// A live stream keeps its state and resumes from the cursor. An
|
|
132
|
+
// incomplete snapshot starts over.
|
|
121
133
|
const state =
|
|
122
|
-
key
|
|
123
|
-
?
|
|
124
|
-
:
|
|
134
|
+
key !== streamKey
|
|
135
|
+
? reducer.initial
|
|
136
|
+
: current.phase === "snapshot"
|
|
137
|
+
? { ...reducer.initial, notebookId: current.notebookId }
|
|
138
|
+
: current;
|
|
139
|
+
if (state.phase === "snapshot") {
|
|
140
|
+
cursor = null;
|
|
141
|
+
}
|
|
125
142
|
streamKey = key;
|
|
126
143
|
store.set(readyAtom, false);
|
|
127
144
|
store.set(streamAtom, state);
|
|
128
|
-
if (
|
|
129
|
-
next.searchParams.set("cursor",
|
|
145
|
+
if (cursor !== null) {
|
|
146
|
+
next.searchParams.set("cursor", cursor);
|
|
130
147
|
}
|
|
131
148
|
return next.toString();
|
|
132
149
|
});
|
|
@@ -188,7 +205,22 @@ export function createNotebookClient(store: ReturnType<typeof createStore>) {
|
|
|
188
205
|
let event;
|
|
189
206
|
try {
|
|
190
207
|
event = parseNotebookEvent(decodeJson(message.data));
|
|
191
|
-
|
|
208
|
+
const state = store.get(streamAtom);
|
|
209
|
+
if (
|
|
210
|
+
state.phase === "live" &&
|
|
211
|
+
event.id === undefined &&
|
|
212
|
+
!UNCURSORED.has(event.event)
|
|
213
|
+
) {
|
|
214
|
+
throw new Error("Live notebook event is missing its cursor");
|
|
215
|
+
}
|
|
216
|
+
if (event.event !== "marimo" && event.event !== "unknown") {
|
|
217
|
+
store.set(streamAtom, reducer.reduce(state, event));
|
|
218
|
+
}
|
|
219
|
+
if (event.event === "reset") {
|
|
220
|
+
cursor = null;
|
|
221
|
+
} else if (event.event === "ready" || state.phase === "live") {
|
|
222
|
+
cursor = event.id ?? cursor;
|
|
223
|
+
}
|
|
192
224
|
if (event.event === "ready" || event.event === "reset") {
|
|
193
225
|
store.set(readyAtom, event.event === "ready");
|
|
194
226
|
}
|
|
@@ -198,7 +230,8 @@ export function createNotebookClient(store: ReturnType<typeof createStore>) {
|
|
|
198
230
|
onMessageError(error);
|
|
199
231
|
return;
|
|
200
232
|
}
|
|
201
|
-
store.set(streamAtom,
|
|
233
|
+
store.set(streamAtom, reducer.initial);
|
|
234
|
+
cursor = null;
|
|
202
235
|
terminal = true;
|
|
203
236
|
setStatus({
|
|
204
237
|
...disconnected,
|
|
@@ -256,7 +289,7 @@ export function createNotebookClient(store: ReturnType<typeof createStore>) {
|
|
|
256
289
|
transport.removeEventListener("message", onMessage);
|
|
257
290
|
transport.close();
|
|
258
291
|
reconnect = undefined;
|
|
259
|
-
store.set(streamAtom,
|
|
292
|
+
store.set(streamAtom, reducer.initial);
|
|
260
293
|
setStatus({ state: ConnectionState.NOT_STARTED });
|
|
261
294
|
},
|
|
262
295
|
{ once: true },
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import type { Attachment } from "
|
|
4
|
-
import type { Resource } from "
|
|
3
|
+
import type { Attachment } from "@marimo-team/client/protocol";
|
|
4
|
+
import type { Resource } from "@marimo-team/client/reducer";
|
|
5
5
|
|
|
6
6
|
/** Attachment records retained with the stream's resume cursor. */
|
|
7
|
-
export const attachments: Resource<readonly Attachment[]> = {
|
|
7
|
+
export const attachments: Resource<readonly Attachment[], "attachment"> = {
|
|
8
8
|
initial: [],
|
|
9
9
|
on: {
|
|
10
10
|
attachment: (state, { data: { attachment } }) =>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import type * as Protocol from "
|
|
4
|
-
import type { Resource } from "
|
|
3
|
+
import type * as Protocol from "@marimo-team/client/protocol";
|
|
4
|
+
import type { Resource } from "@marimo-team/client/reducer";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* The notebook's content at one revision.
|
|
@@ -58,7 +58,7 @@ function publish(
|
|
|
58
58
|
return { current: { revision, cells }, pending: null };
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
export const document: Resource<DocumentState> = {
|
|
61
|
+
export const document: Resource<DocumentState, "cell" | "document"> = {
|
|
62
62
|
initial: { current: null, pending: null },
|
|
63
63
|
on: {
|
|
64
64
|
cell: (state, { data }) => {
|
|
@@ -45,7 +45,7 @@ import { notebookAtom } from "@/core/cells/cells";
|
|
|
45
45
|
import { AppConfigSchema } from "@/core/config/config-schema";
|
|
46
46
|
import { ConnectionNotice } from "@/components/editor/alerts/connection-notice";
|
|
47
47
|
import { kernelStartupErrorAtom } from "@/core/errors/state";
|
|
48
|
-
import type { RunEvent } from "
|
|
48
|
+
import type { RunEvent } from "@marimo-team/client/protocol";
|
|
49
49
|
import type { NotificationPayload } from "@/core/kernel/messages";
|
|
50
50
|
import { useRuntimeManager } from "@/core/runtime/config";
|
|
51
51
|
import { initialRunCompletedAtom } from "../../kernel/state";
|