@marimo-team/islands 0.26.1-dev83 → 0.26.1-dev85
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-yQVBQBUW.js → ConnectedDataExplorerComponent-BJBdnd0O.js} +21 -21
- package/dist/{ErrorBoundary-DqCVIA2k.js → ErrorBoundary-BbX80BeS.js} +18 -18
- package/dist/{abnfDiagram-VCTEODGH-Ck_lXwQR.js → abnfDiagram-VCTEODGH-Ba0MYVW8.js} +2 -2
- package/dist/{any-language-editor-Cx4idbgX.js → any-language-editor-BNe8do3C.js} +2 -2
- package/dist/{architectureDiagram-5GKGNRK7-XeVhic7Z.js → architectureDiagram-5GKGNRK7-7MqAehef.js} +1 -1
- package/dist/{assertNever-473SFxLt.js → assertNever-5vhHGKOK.js} +2 -2
- package/dist/{chat-ui-D1mRz9h6.js → chat-ui-BbJTFtyC.js} +531 -530
- package/dist/{check-DmTIavbZ.js → check-DUIc04aK.js} +1 -1
- package/dist/{chunk-IMKFNOWR-DdQni67K.js → chunk-IMKFNOWR-CAWA0HGB.js} +1 -1
- package/dist/{chunk-SHT3W25Y-BdK-vMct.js → chunk-SHT3W25Y-BIwVQjG5.js} +1 -1
- package/dist/{chunk-SVP7TREG-cpFZk4Ca.js → chunk-SVP7TREG-Cux251TB.js} +1 -1
- package/dist/{chunk-TICWLB2K-DDgQFRgT.js → chunk-TICWLB2K-DJVQ6khO.js} +1 -1
- package/dist/circle-question-mark-evCnVIut.js +19 -0
- package/dist/{classDiagram-ZZMXUADV-DeojX9X4.js → classDiagram-ZZMXUADV-Cwve77ev.js} +2 -2
- package/dist/{classDiagram-v2-VYDZK3BY-DPfTAiQ6.js → classDiagram-v2-VYDZK3BY-BAeHKXmD.js} +2 -2
- package/dist/{code-visibility-Bg6LdTgJ.js → code-visibility-SiV7swyv.js} +18 -18
- package/dist/{common-BXohsH8R.js → common-CaZHHn2u.js} +3442 -3433
- package/dist/{copy-icon-DuxRkh7T.js → copy-icon-CmNLxT5_.js} +2 -2
- package/dist/{createReducer-D3pBhIVD.js → createReducer-BUQhgLOI.js} +5 -5
- package/dist/{cynefinDiagram-5FMLGOSQ-DyY9TvuI.js → cynefinDiagram-5FMLGOSQ-t4eEkPJh.js} +1 -1
- package/dist/{dagre-GXQ25YYZ-BPCOgtKg.js → dagre-GXQ25YYZ-IuZuI28B.js} +1 -1
- package/dist/{data-grid-overlay-editor-A_0tSQlT.js → data-grid-overlay-editor-B_CloII8.js} +1 -1
- package/dist/{diagram-S7CK7UJ4-KaF-C6kd.js → diagram-S7CK7UJ4-D8R5Q_ok.js} +1 -1
- package/dist/{diagram-UQ7AKVKN-DkeqoSvK.js → diagram-UQ7AKVKN-BGuMPsr-.js} +1 -1
- package/dist/{diagram-VX7I27RA-DExolTAf.js → diagram-VX7I27RA-BkTtpO8P.js} +1 -1
- package/dist/{diagram-Z3DM3KII-BioFuBF3.js → diagram-Z3DM3KII-C0__Mxfm.js} +1 -1
- package/dist/{dialog-CvyFEwby.js → dialog-BvjfalZ9.js} +30 -30
- package/dist/{dropdown-menu-BiXHfje7.js → dropdown-menu-D0DeN-aL.js} +637 -637
- package/dist/{ebnfDiagram-PWID7BFC-BSb9k1ed.js → ebnfDiagram-PWID7BFC-CSESPZoz.js} +2 -2
- package/dist/{erDiagram-RLTQ6QDP-PWA30a_r.js → erDiagram-RLTQ6QDP-DsDTtabH.js} +1 -1
- package/dist/{error-banner-B9HQMSaH.js → error-banner-CXLjTW24.js} +60 -65
- package/dist/{error-entries-P6Qpq6wP.js → error-entries-DhZotdzQ.js} +113 -112
- package/dist/{config-D-lhQq-h.js → export-context-CkgZeARR.js} +54 -42
- package/dist/{feedback-button-DSC9SNgL.js → feedback-button-Dcyqig9t.js} +7 -7
- package/dist/{flowDiagram-HODETNUW-BPtD__Zz.js → flowDiagram-HODETNUW-qxDPYbfV.js} +2 -2
- package/dist/{formats-BF95BoCT.js → formats-CcQrzFo8.js} +2 -2
- package/dist/{glide-data-editor-NVoO9114.js → glide-data-editor-axxUUflO.js} +11 -11
- package/dist/{glide-utils-iHKKQPJ8.js → glide-utils-CD8BaFTm.js} +2 -2
- package/dist/{globals-L7tZEIcx.js → globals-IsQZV-Pn.js} +3 -3
- package/dist/{html-to-image-DhrFZL7t.js → html-to-image-B8erjaaD.js} +4288 -4311
- package/dist/{infoDiagram-27XIBGKW-SJuilBEE.js → infoDiagram-27XIBGKW-B5hq8RM_.js} +1 -1
- package/dist/{ishikawaDiagram-5VMMS53U-DjzyxMr8.js → ishikawaDiagram-5VMMS53U-DkHc_9ET.js} +1 -1
- package/dist/{kanban-definition-UXKFOSKX-D2_qopGt.js → kanban-definition-UXKFOSKX-CqkTFXmU.js} +1 -1
- package/dist/{loader-qPmiRXZd.js → loader-CGrYn73j.js} +421 -373
- package/dist/main.js +6444 -6454
- package/dist/{mermaid-DcowNmCx.js → mermaid-pmVHDUQA.js} +34 -34
- package/dist/{mindmap-definition-YA3MSWOX-pEra10M0.js → mindmap-definition-YA3MSWOX-D6cNa__z.js} +1 -1
- package/dist/{number-overlay-editor-CjeU_gt8.js → number-overlay-editor-CNaE6yaF.js} +1 -1
- package/dist/{pegDiagram-XKGWAZYB-CHOPKVOf.js → pegDiagram-XKGWAZYB-CmWJX_s1.js} +2 -2
- package/dist/{pencil-FAv6JUvp.js → pencil-CxMgOe04.js} +1 -1
- package/dist/{pieDiagram-E7YTZNPT-yGDhsyEN.js → pieDiagram-E7YTZNPT-CAQAxHah.js} +1 -1
- package/dist/{process-output-CBPqVQBu.js → process-output-C-2_O5Ry.js} +4 -4
- package/dist/{railroadDiagram-O6MQD6OU-CeKEPdyc.js → railroadDiagram-O6MQD6OU-jlSsiQg3.js} +2 -2
- package/dist/{requirementDiagram-BXWQKSXE-DSAbAzKe.js → requirementDiagram-BXWQKSXE-DkDjfPhn.js} +1 -1
- package/dist/{reveal-component-D8H5fBkv.js → reveal-component-CA2JlAJ6.js} +11 -11
- package/dist/{select-BszV-bbI.js → select-CEnB18uc.js} +350 -350
- package/dist/{sequenceDiagram-WJ2MYXX4-DVhWj_9H.js → sequenceDiagram-WJ2MYXX4-DLywsGCW.js} +1 -1
- package/dist/{spec-CRfw-lOm.js → spec-Dz-Avv1m.js} +4 -4
- package/dist/{stateDiagram-D77RDMKH-CDQ2MltG.js → stateDiagram-D77RDMKH-DUmlKwYU.js} +2 -2
- package/dist/{stateDiagram-v2-MP3YSRHH-BQmvwBaz.js → stateDiagram-v2-MP3YSRHH-D646KiXs.js} +2 -2
- package/dist/{static-state-BtDNJuc2.js → static-state-iw0PrHK4.js} +24 -35
- package/dist/{swimlanes-42K2YHIH-DLOUTCEL.js → swimlanes-42K2YHIH-L7B1GphF.js} +1 -1
- package/dist/{swimlanesDiagram-VR7AAH4N-BVKrkNJ6.js → swimlanesDiagram-VR7AAH4N-DEu2wxtC.js} +2 -2
- package/dist/{timeline-definition-24CTP7MA-Cb2JoCSd.js → timeline-definition-24CTP7MA-DDPyx1yG.js} +1 -1
- package/dist/toDate-BZg-byuO.js +13 -0
- package/dist/{toast-QsOAIPfq.js → toast-BTjH6fIf.js} +187 -187
- package/dist/{tooltip-BQZ-Bm6h.js → tooltip-DyLdBIM4.js} +73 -73
- package/dist/{use-restore-focus-DT1TZACX.js → use-restore-focus-DJ_-uSn_.js} +1340 -1339
- package/dist/{useDateFormatter-D3gyMY-g.js → useDateFormatter-HpKD0jEC.js} +2 -2
- package/dist/{useDeepCompareMemoize-CO6rO5Mq.js → useDeepCompareMemoize-CHx-NxMl.js} +1 -1
- package/dist/{useLifecycle-C9UTzCY8.js → useLifecycle-tPpAt-OE.js} +1 -1
- package/dist/{vega-component-i5lZ23n7.js → vega-component-BzNDFvQf.js} +209 -205
- package/dist/{vennDiagram-4TSXK5OY-Cm3EcCcP.js → vennDiagram-4TSXK5OY-CRwWeb7g.js} +1 -1
- package/dist/{wardleyDiagram-VM6X3IG4-DjlUs2CC.js → wardleyDiagram-VM6X3IG4-DVlG9eoq.js} +1 -1
- package/dist/{xychartDiagram-S5SC5T6Z-DxNDul9l.js → xychartDiagram-S5SC5T6Z-CM32AISp.js} +1 -1
- package/package.json +1 -1
- package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +240 -93
- package/src/components/editor/errors/send-error-report-button.tsx +139 -41
- package/src/core/notebook/replica/__tests__/fixtures.ts +1 -0
- package/src/core/notebook/replica/backend.ts +4 -1
- package/src/core/session/active-notebook.ts +6 -0
- package/src/core/transports/__tests__/static.test.ts +21 -18
- package/src/core/transports/static.ts +1 -0
- package/src/plugins/core/__test__/trusted-url.test.ts +53 -1
- package/src/plugins/core/trusted-url.ts +59 -1
- package/src/plugins/impl/vega/__tests__/resolve-data.test.ts +147 -2
- package/src/plugins/impl/vega/loader.ts +49 -2
- package/src/plugins/impl/vega/vega-component.tsx +3 -0
|
@@ -1,15 +1,82 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import type { JsonValue } from "@marimo-team/client/protocol";
|
|
4
|
+
import { type ExtractAtomValue, useAtomValue } from "jotai";
|
|
5
|
+
import { ChevronDownIcon, SendIcon } from "lucide-react";
|
|
5
6
|
import { useState } from "react";
|
|
6
|
-
import { Button } from "@/components/ui/button";
|
|
7
|
-
import { attachmentLabel, useNotebookAttachments } from "@/core/notebook";
|
|
8
7
|
import { agentToast } from "@/components/editor/agent-toast";
|
|
8
|
+
import { Button } from "@/components/ui/button";
|
|
9
|
+
import {
|
|
10
|
+
DropdownMenu,
|
|
11
|
+
DropdownMenuContent,
|
|
12
|
+
DropdownMenuItem,
|
|
13
|
+
DropdownMenuSeparator,
|
|
14
|
+
DropdownMenuTrigger,
|
|
15
|
+
} from "@/components/ui/dropdown-menu";
|
|
9
16
|
import { pairConfigAtom } from "@/core/config/pair";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
17
|
+
import { attachmentLabel, useNotebookAttachments } from "@/core/notebook";
|
|
18
|
+
import {
|
|
19
|
+
activeNotebookAtom,
|
|
20
|
+
activeNotebookBackendAtom,
|
|
21
|
+
} from "@/core/session/active-notebook";
|
|
22
|
+
import { uniqueBy } from "@/utils/arrays";
|
|
23
|
+
import { prettyError } from "@/utils/errors";
|
|
24
|
+
|
|
25
|
+
const MAX_MESSAGE_BYTES = 65_536;
|
|
26
|
+
|
|
27
|
+
type NotebookBackend = NonNullable<
|
|
28
|
+
ExtractAtomValue<typeof activeNotebookBackendAtom>
|
|
29
|
+
>;
|
|
30
|
+
|
|
31
|
+
function encodeReport(content: unknown): JsonValue {
|
|
32
|
+
const encoded = JSON.stringify(content);
|
|
33
|
+
if (encoded === undefined) {
|
|
34
|
+
throw new Error("The report must be a JSON value.");
|
|
35
|
+
}
|
|
36
|
+
if (new TextEncoder().encode(encoded).byteLength > MAX_MESSAGE_BYTES) {
|
|
37
|
+
throw new Error("The report exceeds 65,536 bytes as JSON.");
|
|
38
|
+
}
|
|
39
|
+
return JSON.parse(encoded) as JsonValue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Sends the report and shows the outcome as a toast. Never rejects. */
|
|
43
|
+
async function sendErrorReport({
|
|
44
|
+
backend,
|
|
45
|
+
notebookId,
|
|
46
|
+
content,
|
|
47
|
+
to,
|
|
48
|
+
setSending,
|
|
49
|
+
}: {
|
|
50
|
+
backend: NotebookBackend;
|
|
51
|
+
notebookId: string;
|
|
52
|
+
content: () => unknown;
|
|
53
|
+
to: string | null;
|
|
54
|
+
setSending: (sending: boolean) => void;
|
|
55
|
+
}): Promise<void> {
|
|
56
|
+
setSending(true);
|
|
57
|
+
try {
|
|
58
|
+
const result = await backend.notebook(notebookId).emit({
|
|
59
|
+
type: "marimo.agents.message.v1",
|
|
60
|
+
data: {
|
|
61
|
+
message: encodeReport(content()),
|
|
62
|
+
to,
|
|
63
|
+
sender: "marimo error report",
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
if (!result.ok) {
|
|
67
|
+
throw new Error(result.problem.detail ?? result.problem.title);
|
|
68
|
+
}
|
|
69
|
+
agentToast({ title: "Sent" });
|
|
70
|
+
} catch (error) {
|
|
71
|
+
agentToast({
|
|
72
|
+
variant: "danger",
|
|
73
|
+
title: "Could not send error",
|
|
74
|
+
description: prettyError(error),
|
|
75
|
+
});
|
|
76
|
+
} finally {
|
|
77
|
+
setSending(false);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
13
80
|
|
|
14
81
|
export function SendErrorReportButton({
|
|
15
82
|
getContent,
|
|
@@ -17,50 +84,81 @@ export function SendErrorReportButton({
|
|
|
17
84
|
getContent: () => unknown;
|
|
18
85
|
}) {
|
|
19
86
|
const hostEnabled = useAtomValue(pairConfigAtom)?.hostEnabled;
|
|
20
|
-
const
|
|
21
|
-
const
|
|
87
|
+
const attachments = useNotebookAttachments("agent");
|
|
88
|
+
const notebook = useAtomValue(activeNotebookAtom);
|
|
89
|
+
const backend = useAtomValue(activeNotebookBackendAtom);
|
|
22
90
|
const [sending, setSending] = useState(false);
|
|
91
|
+
const agents = uniqueBy(
|
|
92
|
+
attachments.flatMap((attachment) =>
|
|
93
|
+
attachment.identity
|
|
94
|
+
? [{ id: attachment.identity, name: attachmentLabel(attachment) }]
|
|
95
|
+
: [],
|
|
96
|
+
),
|
|
97
|
+
(agent) => agent.id,
|
|
98
|
+
);
|
|
23
99
|
|
|
24
|
-
if (
|
|
100
|
+
if (
|
|
101
|
+
!hostEnabled ||
|
|
102
|
+
!notebook?.operations.includes("notebook.emit") ||
|
|
103
|
+
!backend ||
|
|
104
|
+
agents.length === 0
|
|
105
|
+
) {
|
|
25
106
|
return null;
|
|
26
107
|
}
|
|
27
108
|
|
|
28
|
-
const send = async () => {
|
|
29
|
-
if (sending
|
|
109
|
+
const send = async (to: string | null) => {
|
|
110
|
+
if (sending) {
|
|
30
111
|
return;
|
|
31
112
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
title: `Sent to ${agents.map(attachmentLabel).join(", ")}`,
|
|
40
|
-
});
|
|
41
|
-
} catch (error) {
|
|
42
|
-
agentToast({
|
|
43
|
-
variant: "danger",
|
|
44
|
-
title:
|
|
45
|
-
error instanceof HTTPError && error.status === 409
|
|
46
|
-
? "No agent attached"
|
|
47
|
-
: "Could not send error",
|
|
48
|
-
description: prettyError(error),
|
|
49
|
-
});
|
|
50
|
-
} finally {
|
|
51
|
-
setSending(false);
|
|
52
|
-
}
|
|
113
|
+
await sendErrorReport({
|
|
114
|
+
backend,
|
|
115
|
+
notebookId: notebook.id,
|
|
116
|
+
content: getContent,
|
|
117
|
+
to,
|
|
118
|
+
setSending,
|
|
119
|
+
});
|
|
53
120
|
};
|
|
54
121
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
size="xs"
|
|
58
|
-
variant="outline"
|
|
59
|
-
disabled={sending || agents.length === 0 || !stableSessionId}
|
|
60
|
-
onClick={send}
|
|
61
|
-
>
|
|
122
|
+
const label = (
|
|
123
|
+
<>
|
|
62
124
|
<SendIcon className="h-3 w-3 mr-2" />
|
|
63
125
|
Send error to agent
|
|
64
|
-
|
|
126
|
+
</>
|
|
127
|
+
);
|
|
128
|
+
if (agents.length === 1) {
|
|
129
|
+
return (
|
|
130
|
+
<Button
|
|
131
|
+
size="xs"
|
|
132
|
+
variant="outline"
|
|
133
|
+
disabled={sending}
|
|
134
|
+
onClick={() => send(agents[0].id)}
|
|
135
|
+
>
|
|
136
|
+
{label}
|
|
137
|
+
</Button>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<DropdownMenu>
|
|
143
|
+
<DropdownMenuTrigger asChild={true}>
|
|
144
|
+
<Button size="xs" variant="outline" disabled={sending}>
|
|
145
|
+
{label}
|
|
146
|
+
<ChevronDownIcon className="h-3 w-3 ml-2" />
|
|
147
|
+
</Button>
|
|
148
|
+
</DropdownMenuTrigger>
|
|
149
|
+
<DropdownMenuContent align="start">
|
|
150
|
+
{agents.map(({ id, name }) => (
|
|
151
|
+
<DropdownMenuItem key={id} onSelect={() => send(id)}>
|
|
152
|
+
{agents.some((other) => other.id !== id && other.name === name)
|
|
153
|
+
? `${name} (${id})`
|
|
154
|
+
: name}
|
|
155
|
+
</DropdownMenuItem>
|
|
156
|
+
))}
|
|
157
|
+
<DropdownMenuSeparator />
|
|
158
|
+
<DropdownMenuItem onSelect={() => send(null)}>
|
|
159
|
+
Send to all agents
|
|
160
|
+
</DropdownMenuItem>
|
|
161
|
+
</DropdownMenuContent>
|
|
162
|
+
</DropdownMenu>
|
|
65
163
|
);
|
|
66
164
|
}
|
|
@@ -57,6 +57,7 @@ export function fakeBackend({
|
|
|
57
57
|
transport,
|
|
58
58
|
notebook: (notebookId) => ({
|
|
59
59
|
edit: (...args) => edit(notebookId, ...args),
|
|
60
|
+
emit: vi.fn<Commands["emit"]>(),
|
|
60
61
|
save: (...args) => save(notebookId, ...args),
|
|
61
62
|
run: (...args) => run(notebookId, ...args),
|
|
62
63
|
input: (...args) => input(notebookId, ...args),
|
|
@@ -15,7 +15,10 @@ export interface NotebookBackend {
|
|
|
15
15
|
*/
|
|
16
16
|
notebook(
|
|
17
17
|
id: NotebookId,
|
|
18
|
-
): Pick<
|
|
18
|
+
): Pick<
|
|
19
|
+
NotebookClient,
|
|
20
|
+
"edit" | "emit" | "save" | "run" | "input" | "interrupt"
|
|
21
|
+
>;
|
|
19
22
|
/** Whether the host is reachable before an explicit reconnect. Absent means always. */
|
|
20
23
|
checkHealth?(): Promise<boolean>;
|
|
21
24
|
}
|
|
@@ -10,6 +10,12 @@ export const activeNotebookReplicaAtom = atom<NotebookReplica | null>(null);
|
|
|
10
10
|
/** Display state published once per frame by the mounted session. */
|
|
11
11
|
export const activeNotebookFrameAtom = atom<ReplicaFrame | null>(null);
|
|
12
12
|
|
|
13
|
+
/** The identity and operations advertised by the ready notebook. */
|
|
14
|
+
export const activeNotebookAtom = atom((get) => {
|
|
15
|
+
const replica = get(activeNotebookReplicaAtom);
|
|
16
|
+
return replica === null ? null : get(replica.notebookAtom);
|
|
17
|
+
});
|
|
18
|
+
|
|
13
19
|
/** The last analysis, kept while the host analyzes a newer revision. */
|
|
14
20
|
export const notebookAnalysisAtom = atom((get) => {
|
|
15
21
|
const replica = get(activeNotebookReplicaAtom);
|
|
@@ -206,25 +206,28 @@ describe("static notebook backend", () => {
|
|
|
206
206
|
expect(events.at(-1)).toEqual({ event: "ready", id: "static", data: {} });
|
|
207
207
|
});
|
|
208
208
|
|
|
209
|
-
it.each([
|
|
210
|
-
"
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
209
|
+
it.each([
|
|
210
|
+
["edit", (client) => client.edit([])],
|
|
211
|
+
["emit", (client) => client.emit({ type: "example.message", data: null })],
|
|
212
|
+
["save", (client) => client.save()],
|
|
213
|
+
] satisfies [
|
|
214
|
+
string,
|
|
215
|
+
(client: ReturnType<NotebookBackend["notebook"]>) => Promise<unknown>,
|
|
216
|
+
][])("rejects direct %s commands", async (_operation, send) => {
|
|
217
|
+
const backend = createStaticNotebookBackend(snapshot());
|
|
218
|
+
const client = backend.notebook(snapshot().notebook.id);
|
|
219
|
+
const result = await send(client);
|
|
220
|
+
expect(result).toEqual({
|
|
221
|
+
ok: false,
|
|
222
|
+
status: 501,
|
|
223
|
+
problem: {
|
|
224
|
+
type: "urn:marimo:problem:unsupported-operation",
|
|
225
|
+
title: "Unsupported operation",
|
|
218
226
|
status: 501,
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
detail: "Static notebooks do not support mutations",
|
|
224
|
-
},
|
|
225
|
-
});
|
|
226
|
-
},
|
|
227
|
-
);
|
|
227
|
+
detail: "Static notebooks do not support mutations",
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
});
|
|
228
231
|
|
|
229
232
|
it("respects cancellation before opening, during delivery, and for commands", async () => {
|
|
230
233
|
const backend = createStaticNotebookBackend(snapshot());
|
|
@@ -178,6 +178,7 @@ export function createStaticNotebookBackend(
|
|
|
178
178
|
};
|
|
179
179
|
return {
|
|
180
180
|
edit: (_changes, options) => unsupported(options),
|
|
181
|
+
emit: (_event, options) => unsupported(options),
|
|
181
182
|
save: unsupported,
|
|
182
183
|
run: unsupported,
|
|
183
184
|
input: (_inputId, _reply, options) => unsupported(options),
|
|
@@ -5,7 +5,10 @@ import { userConfigAtom } from "@/core/config/config";
|
|
|
5
5
|
import { parseUserConfig } from "@/core/config/config-schema";
|
|
6
6
|
import { initialModeAtom } from "@/core/mode";
|
|
7
7
|
import { store } from "@/core/state/jotai";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
isTrustedVirtualFileUrl,
|
|
10
|
+
resolveTrustedDataFetchUrl,
|
|
11
|
+
} from "../trusted-url";
|
|
9
12
|
|
|
10
13
|
type ExportContextWindow = Window & {
|
|
11
14
|
__MARIMO_EXPORT_CONTEXT__?: {
|
|
@@ -202,3 +205,52 @@ describe("isTrustedVirtualFileUrl", () => {
|
|
|
202
205
|
});
|
|
203
206
|
});
|
|
204
207
|
});
|
|
208
|
+
|
|
209
|
+
describe("resolveTrustedDataFetchUrl", () => {
|
|
210
|
+
let trustStateSnapshot: ReturnType<typeof snapshotTrustState>;
|
|
211
|
+
|
|
212
|
+
beforeEach(() => {
|
|
213
|
+
trustStateSnapshot = snapshotTrustState();
|
|
214
|
+
clearTrustSignals();
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
afterEach(() => {
|
|
218
|
+
restoreTrustState(trustStateSnapshot);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it.each([
|
|
222
|
+
"./@file/123-data.csv",
|
|
223
|
+
"@file/123-data.arrow",
|
|
224
|
+
`${window.location.origin}/@file/123-data.json`,
|
|
225
|
+
"https://cdn.jsdelivr.net/npm/vega-datasets@2/data/cars.json",
|
|
226
|
+
"data:text/csv;base64,YQox",
|
|
227
|
+
])("accepts %s before the notebook is trusted", (url) => {
|
|
228
|
+
expect(resolveTrustedDataFetchUrl(url)).toBe(
|
|
229
|
+
new URL(url, document.baseURI).href,
|
|
230
|
+
);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it.each([
|
|
234
|
+
"/api/files/download?path=/etc/passwd",
|
|
235
|
+
"api/files/download?path=/etc/passwd",
|
|
236
|
+
`${window.location.origin}/api/files/download?path=/etc/passwd`,
|
|
237
|
+
"./@file/../api/files/download?path=/etc/passwd",
|
|
238
|
+
"./@file/%2e%2e/api/files/download?path=/etc/passwd",
|
|
239
|
+
"data.csv",
|
|
240
|
+
"file:///etc/passwd",
|
|
241
|
+
// `fetch` resolves these against the page, so they reach the server
|
|
242
|
+
"http:/api/files/download?path=/etc/passwd",
|
|
243
|
+
"http:api/files/download?path=/etc/passwd",
|
|
244
|
+
"HTTP:/api/files/download?path=/etc/passwd",
|
|
245
|
+
`//${window.location.host}/api/files/download?path=/etc/passwd`,
|
|
246
|
+
])("rejects %s before the notebook is trusted", (url) => {
|
|
247
|
+
expect(resolveTrustedDataFetchUrl(url)).toBeNull();
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("returns same-origin URLs unchanged once the user has run a cell", () => {
|
|
251
|
+
store.set(hasRunAnyCellAtom, true);
|
|
252
|
+
expect(resolveTrustedDataFetchUrl("public/data.csv")).toBe(
|
|
253
|
+
"public/data.csv",
|
|
254
|
+
);
|
|
255
|
+
});
|
|
256
|
+
});
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
3
|
import { hasRunAnyCellAtom } from "@/components/editor/cell/useRunCells";
|
|
4
|
-
import {
|
|
4
|
+
import { getRuntimeManager } from "@/core/runtime/config";
|
|
5
|
+
import {
|
|
6
|
+
hasTrustedExportContext,
|
|
7
|
+
hasTrustedNotebookContext,
|
|
8
|
+
} from "@/core/static/export-context";
|
|
5
9
|
import { store } from "@/core/state/jotai";
|
|
6
10
|
|
|
7
11
|
/**
|
|
@@ -37,6 +41,60 @@ export function isTrustedVirtualFileUrl(url: unknown): url is string {
|
|
|
37
41
|
return false;
|
|
38
42
|
}
|
|
39
43
|
|
|
44
|
+
/**
|
|
45
|
+
* The URL a plugin may fetch data (e.g. a Vega `data.url`) from, or `null` if
|
|
46
|
+
* it may not. Callers must fetch the returned URL, not the original string.
|
|
47
|
+
*
|
|
48
|
+
* Before the notebook is trusted, outputs on screen may come from a session
|
|
49
|
+
* cache, and the HTML sanitizer lets `<marimo-*>` elements through, so their
|
|
50
|
+
* URLs are untrusted. A same-origin URL could read marimo's authenticated API
|
|
51
|
+
* (e.g. `/api/files/download`), so until then the only marimo server URLs
|
|
52
|
+
* allowed are virtual files. Other origins and inline `data:`/`blob:` URLs
|
|
53
|
+
* cannot reach the server. The check compares origins, so loopback aliases of
|
|
54
|
+
* the server (`127.0.0.1` vs `localhost`, `[::1]`) count as other origins;
|
|
55
|
+
* the browser sends no cookies with those requests, so they are
|
|
56
|
+
* unauthenticated.
|
|
57
|
+
*
|
|
58
|
+
* Before trust, the result is the absolute `href` of `url` resolved against
|
|
59
|
+
* the runtime URL, so the URL that is checked is the URL that is fetched
|
|
60
|
+
* (e.g. `http:/api/...` resolves against the server, not to host `api`).
|
|
61
|
+
*/
|
|
62
|
+
export function resolveTrustedDataFetchUrl(url: string): string | null {
|
|
63
|
+
if (hasTrustedNotebookContext()) {
|
|
64
|
+
return url;
|
|
65
|
+
}
|
|
66
|
+
let resolved: URL;
|
|
67
|
+
try {
|
|
68
|
+
resolved = resolveAgainstRuntime(url);
|
|
69
|
+
} catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
if (resolved.protocol === "data:" || resolved.protocol === "blob:") {
|
|
73
|
+
return resolved.href;
|
|
74
|
+
}
|
|
75
|
+
if (resolved.protocol !== "http:" && resolved.protocol !== "https:") {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
const virtualFileRoot = resolveAgainstRuntime("./@file/");
|
|
79
|
+
if (resolved.origin === virtualFileRoot.origin) {
|
|
80
|
+
return resolved.pathname.startsWith(virtualFileRoot.pathname)
|
|
81
|
+
? resolved.href
|
|
82
|
+
: null;
|
|
83
|
+
}
|
|
84
|
+
return resolved.origin === window.location.origin ? null : resolved.href;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Unlike `asRemoteURL`, always resolves with the runtime URL as the base, the
|
|
89
|
+
* way `fetch` resolves with the page URL as the base.
|
|
90
|
+
*/
|
|
91
|
+
function resolveAgainstRuntime(url: string): URL {
|
|
92
|
+
const base = getRuntimeManager()
|
|
93
|
+
.httpURL.toString()
|
|
94
|
+
.replace(/^blob:/, "");
|
|
95
|
+
return new URL(url, base);
|
|
96
|
+
}
|
|
97
|
+
|
|
40
98
|
/**
|
|
41
99
|
* Intentionally narrower than `hasTrustedNotebookContext` in
|
|
42
100
|
* `@/core/static/export-context`: `auto_instantiate` and `read` mode are
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import {
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { hasRunAnyCellAtom } from "@/components/editor/cell/useRunCells";
|
|
4
|
+
import { userConfigAtom } from "@/core/config/config";
|
|
5
|
+
import { parseUserConfig } from "@/core/config/config-schema";
|
|
6
|
+
import { initialModeAtom } from "@/core/mode";
|
|
7
|
+
import { store } from "@/core/state/jotai";
|
|
8
|
+
import { createEmbedLoader, vegaLoadData, vegaLoader } from "../loader";
|
|
4
9
|
import { resolveVegaSpecData } from "../resolve-data";
|
|
5
10
|
import type { VegaLiteSpec } from "../types";
|
|
6
11
|
|
|
@@ -234,3 +239,143 @@ describe("resolveVegaSpecData", () => {
|
|
|
234
239
|
expect(result).not.toHaveProperty("datasets");
|
|
235
240
|
});
|
|
236
241
|
});
|
|
242
|
+
|
|
243
|
+
describe("data URLs before the notebook is trusted", () => {
|
|
244
|
+
const download = "/api/files/download?path=/etc/passwd";
|
|
245
|
+
const snapshotTrustState = () => ({
|
|
246
|
+
userConfig: store.get(userConfigAtom),
|
|
247
|
+
hasRunAnyCell: store.get(hasRunAnyCellAtom),
|
|
248
|
+
initialMode: store.get(initialModeAtom),
|
|
249
|
+
});
|
|
250
|
+
let snapshot: ReturnType<typeof snapshotTrustState>;
|
|
251
|
+
|
|
252
|
+
beforeEach(() => {
|
|
253
|
+
snapshot = snapshotTrustState();
|
|
254
|
+
const config = parseUserConfig({});
|
|
255
|
+
store.set(userConfigAtom, {
|
|
256
|
+
...config,
|
|
257
|
+
runtime: { ...config.runtime, auto_instantiate: false },
|
|
258
|
+
});
|
|
259
|
+
store.set(hasRunAnyCellAtom, false);
|
|
260
|
+
store.set(initialModeAtom, "edit");
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
afterEach(() => {
|
|
264
|
+
store.set(userConfigAtom, snapshot.userConfig);
|
|
265
|
+
store.set(hasRunAnyCellAtom, snapshot.hasRunAnyCell);
|
|
266
|
+
store.set(initialModeAtom, snapshot.initialMode);
|
|
267
|
+
vi.resetAllMocks();
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it.each([download, `${window.location.origin}${download}`])(
|
|
271
|
+
"refuses to load %s",
|
|
272
|
+
async (url) => {
|
|
273
|
+
const load = vi.spyOn(vegaLoader, "load");
|
|
274
|
+
await expect(
|
|
275
|
+
resolveVegaSpecData(asSpec({ data: { url, format: { type: "csv" } } })),
|
|
276
|
+
).rejects.toThrow("Run the notebook to load data");
|
|
277
|
+
expect(load).not.toHaveBeenCalled();
|
|
278
|
+
},
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
it.each([
|
|
282
|
+
"./@file/123-data.csv",
|
|
283
|
+
"https://cdn.jsdelivr.net/npm/vega-datasets@2/data/cars.csv",
|
|
284
|
+
])("loads %s", async (url) => {
|
|
285
|
+
const load = vi.spyOn(vegaLoader, "load").mockResolvedValue("a\n1");
|
|
286
|
+
const result = await resolveVegaSpecData(
|
|
287
|
+
asSpec({ data: { url, format: { type: "csv" } } }),
|
|
288
|
+
);
|
|
289
|
+
expect(load).toHaveBeenCalledOnce();
|
|
290
|
+
expect(Object.values(result.datasets ?? {})).toEqual([[{ a: 1 }]]);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
// `fetch` resolves these against the page, so they reach the server
|
|
294
|
+
const serverUrls = [
|
|
295
|
+
download,
|
|
296
|
+
"http:/api/files/download?path=/etc/passwd",
|
|
297
|
+
"http:api/files/download?path=/etc/passwd",
|
|
298
|
+
"HTTP:/api/files/download?path=/etc/passwd",
|
|
299
|
+
`//${window.location.host}/api/files/download?path=/etc/passwd`,
|
|
300
|
+
];
|
|
301
|
+
const virtualFile = "./@file/123-data.csv";
|
|
302
|
+
const virtualFileHref = new URL(virtualFile, document.baseURI).href;
|
|
303
|
+
const dataflow = { context: "dataflow", response: "csv" } as const;
|
|
304
|
+
|
|
305
|
+
it.each(serverUrls)("vegaLoadData refuses %s", async (url) => {
|
|
306
|
+
const load = vi.spyOn(vegaLoader, "load");
|
|
307
|
+
const fetch = vi.spyOn(globalThis, "fetch");
|
|
308
|
+
await expect(vegaLoadData(url, { type: "csv" })).rejects.toThrow(
|
|
309
|
+
"Run the notebook to load data",
|
|
310
|
+
);
|
|
311
|
+
await expect(vegaLoadData(url, { type: "arrow" })).rejects.toThrow(
|
|
312
|
+
"Run the notebook to load data",
|
|
313
|
+
);
|
|
314
|
+
expect(load).not.toHaveBeenCalled();
|
|
315
|
+
expect(fetch).not.toHaveBeenCalled();
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it("vegaLoadData fetches the URL it checked", async () => {
|
|
319
|
+
const load = vi.spyOn(vegaLoader, "load").mockResolvedValue("a\n1");
|
|
320
|
+
await expect(vegaLoadData(virtualFile, { type: "csv" })).resolves.toEqual([
|
|
321
|
+
{ a: 1 },
|
|
322
|
+
]);
|
|
323
|
+
expect(load).toHaveBeenCalledWith(virtualFileHref);
|
|
324
|
+
|
|
325
|
+
const fetch = vi
|
|
326
|
+
.spyOn(globalThis, "fetch")
|
|
327
|
+
.mockRejectedValue(new Error("offline"));
|
|
328
|
+
const arrowFile = "./@file/123-data.arrow";
|
|
329
|
+
await expect(vegaLoadData(arrowFile, { type: "arrow" })).rejects.toThrow(
|
|
330
|
+
"offline",
|
|
331
|
+
);
|
|
332
|
+
expect(fetch).toHaveBeenCalledWith(
|
|
333
|
+
new URL(arrowFile, document.baseURI).href,
|
|
334
|
+
);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it.each(serverUrls)("the embed loader refuses %s", async (url) => {
|
|
338
|
+
const embedLoader = createEmbedLoader({});
|
|
339
|
+
const http = vi.spyOn(embedLoader, "http").mockResolvedValue("a\n1");
|
|
340
|
+
const file = vi.spyOn(embedLoader, "file").mockResolvedValue("a\n1");
|
|
341
|
+
|
|
342
|
+
await expect(embedLoader.load(url)).rejects.toThrow(
|
|
343
|
+
"Run the notebook to load data",
|
|
344
|
+
);
|
|
345
|
+
expect(http).not.toHaveBeenCalled();
|
|
346
|
+
expect(file).not.toHaveBeenCalled();
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// Vega fetches the `href` that `sanitize` returns
|
|
350
|
+
it("the embed loader returns the URL it checked", async () => {
|
|
351
|
+
const embedLoader = createEmbedLoader({});
|
|
352
|
+
await expect(
|
|
353
|
+
embedLoader.sanitize(virtualFile, dataflow),
|
|
354
|
+
).resolves.toMatchObject({
|
|
355
|
+
href: virtualFileHref,
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("the embed loader keeps the chart's loader options", async () => {
|
|
360
|
+
const embedLoader = createEmbedLoader({
|
|
361
|
+
usermeta: {
|
|
362
|
+
embedOptions: { loader: { baseURL: "https://example.com/data/" } },
|
|
363
|
+
},
|
|
364
|
+
});
|
|
365
|
+
await expect(
|
|
366
|
+
embedLoader.sanitize("cars.csv", dataflow),
|
|
367
|
+
).resolves.toMatchObject({
|
|
368
|
+
href: "https://example.com/data/cars.csv",
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it("the embed loader leaves link URLs to Vega", async () => {
|
|
373
|
+
const embedLoader = createEmbedLoader({});
|
|
374
|
+
await expect(
|
|
375
|
+
embedLoader.sanitize("#details", { context: "href" }),
|
|
376
|
+
).resolves.toMatchObject({ href: "#details" });
|
|
377
|
+
await expect(embedLoader.sanitize(download, dataflow)).rejects.toThrow(
|
|
378
|
+
"Run the notebook to load data",
|
|
379
|
+
);
|
|
380
|
+
});
|
|
381
|
+
});
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
3
|
import { tableFromIPC } from "@uwdata/flechette";
|
|
4
|
+
import type { Loader as VegaLoader } from "vega";
|
|
5
|
+
// @ts-expect-error vega-loader has no types
|
|
6
|
+
import { loader as createVegaLoader } from "vega-loader";
|
|
7
|
+
import { resolveTrustedDataFetchUrl } from "@/plugins/core/trusted-url";
|
|
4
8
|
import { Logger } from "@/utils/Logger";
|
|
5
9
|
import { Objects } from "@/utils/objects";
|
|
6
10
|
import { batchedArrowLoader, createBatchedLoader } from "./batched";
|
|
@@ -145,6 +149,48 @@ typeParsers.boolean = customBooleanParser;
|
|
|
145
149
|
|
|
146
150
|
export const vegaLoader = createBatchedLoader();
|
|
147
151
|
|
|
152
|
+
function trustedDataUrl(url: string): string {
|
|
153
|
+
const href = resolveTrustedDataFetchUrl(url);
|
|
154
|
+
if (href === null) {
|
|
155
|
+
throw new Error(`Run the notebook to load data from ${url}`);
|
|
156
|
+
}
|
|
157
|
+
return href;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Vega fetches some URLs itself (e.g. lookup transforms, Vega specs, image
|
|
162
|
+
* marks), so its loader must apply the same check as `vegaLoadData`.
|
|
163
|
+
* Link URLs (`context: "href"`) are navigated to, not fetched, so they are
|
|
164
|
+
* left to the wrapped loader.
|
|
165
|
+
*/
|
|
166
|
+
function withTrustedDataUrls(loader: VegaLoader): VegaLoader {
|
|
167
|
+
return {
|
|
168
|
+
...loader,
|
|
169
|
+
async sanitize(uri, options) {
|
|
170
|
+
const result = await loader.sanitize(uri, options);
|
|
171
|
+
if (options?.context !== "href") {
|
|
172
|
+
result.href = trustedDataUrl(result.href);
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The loader for vega-embed. vega-embed ignores the spec's
|
|
181
|
+
* `usermeta.embedOptions.loader` options when it is given a loader, so the
|
|
182
|
+
* loader is built from those options.
|
|
183
|
+
*/
|
|
184
|
+
export function createEmbedLoader(spec: { usermeta?: unknown }): VegaLoader {
|
|
185
|
+
const usermeta = spec.usermeta as
|
|
186
|
+
| { embedOptions?: { loader?: unknown } }
|
|
187
|
+
| undefined;
|
|
188
|
+
const options = usermeta?.embedOptions?.loader;
|
|
189
|
+
return withTrustedDataUrls(
|
|
190
|
+
createVegaLoader(typeof options === "object" ? options : undefined),
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
148
194
|
/**
|
|
149
195
|
* Load data from a URL and parse it according to the given format.
|
|
150
196
|
*
|
|
@@ -165,10 +211,11 @@ export async function vegaLoadData<T = object>(
|
|
|
165
211
|
} = {},
|
|
166
212
|
): Promise<T[]> {
|
|
167
213
|
const { handleBigIntAndNumberLike = false, replacePeriod = false } = opts;
|
|
214
|
+
const href = trustedDataUrl(url);
|
|
168
215
|
|
|
169
216
|
// Handle arrow data
|
|
170
217
|
if (url.endsWith(".arrow") || format?.type === "arrow") {
|
|
171
|
-
const arrow = await batchedArrowLoader(
|
|
218
|
+
const arrow = await batchedArrowLoader(href);
|
|
172
219
|
return tableFromIPC(arrow, {
|
|
173
220
|
useProxy: true,
|
|
174
221
|
useDate: true,
|
|
@@ -187,7 +234,7 @@ export async function vegaLoadData<T = object>(
|
|
|
187
234
|
|
|
188
235
|
// Load the data
|
|
189
236
|
try {
|
|
190
|
-
let csvOrJsonData = await vegaLoader.load(
|
|
237
|
+
let csvOrJsonData = await vegaLoader.load(href);
|
|
191
238
|
if (!format) {
|
|
192
239
|
// Infer by trying to parse
|
|
193
240
|
if (typeof csvOrJsonData === "string") {
|