@marimo-team/islands 0.25.3-dev447 → 0.25.3-dev453
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-DVbdKroW.js → ErrorBoundary-CIYMOu2p.js} +1 -1
- package/dist/assets/__vite-browser-external-D2z_TiUO.js +1 -0
- package/dist/assets/{worker-BUqfWMtI.js → worker-DLJ9P24O.js} +2 -2
- package/dist/{chat-ui-9oyUBL6M.js → chat-ui-DEHpKH2l.js} +17 -19
- package/dist/{code-visibility-DmsDqWUx.js → code-visibility-BQE60zOk.js} +7 -7
- package/dist/{common-BDo_Jwoz.js → common-DfUux6zJ.js} +4902 -4893
- package/dist/{data-grid-overlay-editor-CpHB_knU.js → data-grid-overlay-editor-B9zW4oN1.js} +1 -1
- package/dist/{error-entries-CWdDf7iZ.js → error-entries-BG7ifiDg.js} +1368 -996
- package/dist/{feedback-button-B_Wmi4to.js → feedback-button-BEUh4iQQ.js} +129 -129
- package/dist/{glide-data-editor-CMiIW5WP.js → glide-data-editor-CbdIXPTZ.js} +3 -3
- package/dist/{globals-DaC3pk9F.js → globals-BkxG-Y8L.js} +1 -1
- package/dist/{html-to-image-CexRSGAZ.js → html-to-image-9HLBGrIx.js} +4115 -4103
- package/dist/main.js +6562 -6671
- package/dist/{number-overlay-editor-Dd4cOJ5I.js → number-overlay-editor-BFzdth50.js} +1 -1
- package/dist/{process-output-hcyVRJCC.js → process-output-B8HPq5iZ.js} +2 -2
- package/dist/{reveal-component-CTmvBdvu.js → reveal-component-DK_-9fAX.js} +166 -167
- package/package.json +1 -1
- package/src/__mocks__/executions.ts +7 -4
- package/src/__mocks__/notebook.ts +20 -4
- package/src/components/editor/cell/DeleteButton.tsx +2 -2
- package/src/components/editor/cell/StopButton.tsx +2 -2
- package/src/components/editor/cell/useRunCells.ts +0 -3
- package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +1 -1
- package/src/components/editor/notebook-cell.tsx +4 -35
- package/src/components/editor/output/ansi-reduce.ts +124 -61
- package/src/components/editor/output/console/ConsoleOutput.tsx +7 -25
- package/src/components/editor/output/console/__tests__/ConsoleOutput.test.tsx +15 -44
- package/src/components/editor/renderers/cells-renderer.tsx +2 -5
- package/src/components/editor/renderers/grid-layout/__tests__/grid-layout.test.tsx +1 -1
- package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +3 -6
- package/src/components/editor/stdin-blocking-alert.tsx +14 -18
- package/src/components/scratchpad/scratchpad.test.tsx +1 -1
- package/src/components/scratchpad/scratchpad.tsx +5 -6
- package/src/components/slides/__tests__/cell-output-block.test.tsx +2 -2
- package/src/components/slides/__tests__/slide-cell-view.test.tsx +2 -2
- package/src/components/tracing/tracing-spec.ts +11 -1
- package/src/components/tracing/tracing.tsx +4 -0
- package/src/core/ai/context/providers/__tests__/cell-output.test.ts +10 -20
- package/src/core/ai/context/providers/__tests__/error.test.ts +5 -27
- package/src/core/ai/context/providers/cell-output.ts +4 -12
- package/src/core/cells/__tests__/cell.test.ts +1 -169
- package/src/core/cells/__tests__/cells.test.ts +32 -709
- package/src/core/cells/__tests__/clear-outputs.test.ts +21 -14
- package/src/core/cells/__tests__/collapseConsoleOutputs.test.ts +71 -2
- package/src/core/cells/__tests__/logs.test.ts +18 -29
- package/src/core/cells/__tests__/runs.test.ts +128 -431
- package/src/core/cells/__tests__/session.test.ts +9 -9
- package/src/core/cells/actions.ts +29 -7
- package/src/core/cells/cell.ts +1 -96
- package/src/core/cells/cells.ts +147 -117
- package/src/core/cells/collapseConsoleOutputs.tsx +71 -40
- package/src/core/cells/command-console.ts +46 -0
- package/src/core/cells/execution-console.ts +230 -0
- package/src/core/cells/focus.ts +9 -29
- package/src/core/cells/logs.ts +10 -2
- package/src/core/cells/runs.ts +62 -118
- package/src/core/cells/session.ts +2 -2
- package/src/core/cells/types.ts +30 -23
- package/src/core/cells/useAnswerPrompt.ts +29 -0
- package/src/core/errors/error-entries.ts +3 -4
- package/src/core/executions/__tests__/atoms.test.ts +6 -20
- package/src/core/executions/__tests__/input.test.ts +3 -3
- package/src/core/executions/__tests__/output-lifecycle.test.ts +2 -8
- package/src/core/executions/atoms.ts +2 -21
- package/src/core/executions/index.ts +2 -1
- package/src/core/executions/input.ts +4 -3
- package/src/core/executions/output.ts +3 -3
- package/src/core/islands/__tests__/bridge.test.ts +59 -0
- package/src/core/islands/bootstrap.ts +29 -12
- package/src/core/islands/bridge.ts +67 -13
- package/src/core/kernel/handlers.ts +2 -21
- package/src/core/kernel/messages.ts +0 -1
- package/src/core/network/types.ts +0 -1
- package/src/core/notebook/document/__tests__/codemirror.test.ts +1 -0
- package/src/core/notebook/replica/__tests__/executions.test.ts +1 -0
- package/src/core/notebook/replica/__tests__/replica.test.ts +113 -0
- package/src/core/notebook/replica/replica.ts +106 -12
- package/src/core/notebook/replica/resources/executions.ts +57 -4
- package/src/core/session/__tests__/backend.test.ts +2 -4
- package/src/core/session/__tests__/useNotebookReplica.hook.test.tsx +1 -0
- package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +601 -35
- package/src/core/session/useNotebookReplica.ts +20 -6
- package/src/core/session/useNotebookSession.tsx +63 -33
- package/src/core/static/virtual-file-tracker.ts +26 -8
- package/src/stories/layout/vertical/one-column.stories.tsx +18 -12
- package/dist/assets/__vite-browser-external-CpRgw4M_.js +0 -1
- package/src/components/editor/alerts/stdin-blocking-alert.tsx +0 -68
- package/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap +0 -703
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import type { NotificationMessage, OutputMessage } from "../kernel/messages";
|
|
4
|
+
|
|
5
|
+
export type CommandOutputMessage = Extract<
|
|
6
|
+
NotificationMessage,
|
|
7
|
+
{ op: "pdb-output" | "callback-output" }
|
|
8
|
+
>;
|
|
9
|
+
|
|
10
|
+
/** Each producer can replace its own entries when the editor reconnects. */
|
|
11
|
+
export interface CommandConsole {
|
|
12
|
+
/** Keep the original chunks so a replay can interleave both producers before merging text. */
|
|
13
|
+
entries: (OutputMessage & {
|
|
14
|
+
source: CommandOutputMessage["op"];
|
|
15
|
+
afterSeq?: number;
|
|
16
|
+
})[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Merge a producer's snapshot or append its latest writes to the cell console. */
|
|
20
|
+
export function updateCommandConsole(
|
|
21
|
+
previous: CommandConsole | undefined,
|
|
22
|
+
{ op, entries, replace, after_seq }: CommandOutputMessage,
|
|
23
|
+
clearedId?: string,
|
|
24
|
+
): CommandConsole {
|
|
25
|
+
if (op === "callback-output" && !replace && entries.length === 0) {
|
|
26
|
+
// A live callback's clear_console() clears the entire cell transcript.
|
|
27
|
+
return { entries: [] };
|
|
28
|
+
}
|
|
29
|
+
const reset = replace || entries.length === 0;
|
|
30
|
+
const retained = previous?.entries ?? [];
|
|
31
|
+
const clearedIndex =
|
|
32
|
+
replace && clearedId !== undefined
|
|
33
|
+
? entries.findIndex((entry) => entry.command_id === clearedId)
|
|
34
|
+
: -1;
|
|
35
|
+
const incoming = entries.slice(clearedIndex + 1).map((entry, index) => ({
|
|
36
|
+
...entry,
|
|
37
|
+
source: op,
|
|
38
|
+
afterSeq: after_seq?.[clearedIndex + 1 + index],
|
|
39
|
+
}));
|
|
40
|
+
return {
|
|
41
|
+
entries: [
|
|
42
|
+
...(reset ? retained.filter((entry) => entry.source !== op) : retained),
|
|
43
|
+
...incoming,
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import type { Execution } from "@marimo-team/client/protocol";
|
|
4
|
+
import type { Getter } from "jotai";
|
|
5
|
+
import type { ReducerCellActions } from "./cells";
|
|
6
|
+
import {
|
|
7
|
+
itemsInOrder,
|
|
8
|
+
type NotebookReplica,
|
|
9
|
+
type Execution as ReplicaExecution,
|
|
10
|
+
type Item,
|
|
11
|
+
} from "../notebook/replica";
|
|
12
|
+
import { VirtualFileTracker } from "../static/virtual-file-tracker";
|
|
13
|
+
import { activeNotebookReplicaAtom } from "../session/active-notebook";
|
|
14
|
+
import type { OutputMessage } from "../kernel/messages";
|
|
15
|
+
import {
|
|
16
|
+
collapseConsoleBatch,
|
|
17
|
+
collapseConsoleOutputs,
|
|
18
|
+
} from "./collapseConsoleOutputs";
|
|
19
|
+
import { getCellLogsForMessage } from "./logs";
|
|
20
|
+
import { EMBEDDED } from "./session";
|
|
21
|
+
import { SCRATCH_CELL_ID, type CellId } from "./ids";
|
|
22
|
+
import type {
|
|
23
|
+
CellRuntimeState,
|
|
24
|
+
CellRuntimeView,
|
|
25
|
+
ConsoleOutputMessage,
|
|
26
|
+
} from "./types";
|
|
27
|
+
|
|
28
|
+
function consoleEntry(
|
|
29
|
+
item: Item,
|
|
30
|
+
fallback: number,
|
|
31
|
+
code?: string,
|
|
32
|
+
): ConsoleOutputMessage {
|
|
33
|
+
const timestamp =
|
|
34
|
+
item.time === undefined ? fallback : Date.parse(item.time) / 1000;
|
|
35
|
+
const id = item.seq + 1;
|
|
36
|
+
switch (item.kind) {
|
|
37
|
+
case "console":
|
|
38
|
+
return {
|
|
39
|
+
id,
|
|
40
|
+
channel: item.name,
|
|
41
|
+
data: item.text,
|
|
42
|
+
mimetype: "text/plain",
|
|
43
|
+
timestamp,
|
|
44
|
+
};
|
|
45
|
+
case "display":
|
|
46
|
+
return {
|
|
47
|
+
id,
|
|
48
|
+
channel:
|
|
49
|
+
item.content.mimetype === "application/vnd.marimo+traceback"
|
|
50
|
+
? "stderr"
|
|
51
|
+
: "media",
|
|
52
|
+
mimetype: item.content.mimetype as OutputMessage["mimetype"],
|
|
53
|
+
data: item.content.data,
|
|
54
|
+
code:
|
|
55
|
+
item.content.mimetype === "application/vnd.marimo+traceback"
|
|
56
|
+
? code
|
|
57
|
+
: undefined,
|
|
58
|
+
timestamp,
|
|
59
|
+
};
|
|
60
|
+
case "input":
|
|
61
|
+
return {
|
|
62
|
+
id,
|
|
63
|
+
channel: "stdin",
|
|
64
|
+
mimetype: item.password ? "text/password" : "text/plain",
|
|
65
|
+
input_id: item.id,
|
|
66
|
+
data: item.prompt,
|
|
67
|
+
timestamp,
|
|
68
|
+
response: item.status === "pending" ? undefined : null,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Side effects of notebook events shared by the editor and islands. */
|
|
74
|
+
export function consoleObservers(
|
|
75
|
+
actions: Pick<ReducerCellActions, "addLogs" | "startCellConsole">,
|
|
76
|
+
onExecution?: (record: Execution) => void,
|
|
77
|
+
): Pick<Parameters<NotebookReplica["connect"]>[1], "onExecution" | "onItem"> {
|
|
78
|
+
return {
|
|
79
|
+
onExecution(record, changed) {
|
|
80
|
+
VirtualFileTracker.INSTANCE.trackExecution(record);
|
|
81
|
+
if (changed) {
|
|
82
|
+
if (record.status === "running") {
|
|
83
|
+
actions.startCellConsole({
|
|
84
|
+
cellId: (record.cell_id ?? SCRATCH_CELL_ID) as CellId,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
onExecution?.(record);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
onItem(record, item, live) {
|
|
91
|
+
const cellId = (record.cell_id ?? SCRATCH_CELL_ID) as CellId;
|
|
92
|
+
const output = consoleEntry(
|
|
93
|
+
item,
|
|
94
|
+
record.started_at ? Date.parse(record.started_at) / 1000 : 0,
|
|
95
|
+
);
|
|
96
|
+
if (output.channel === "media") {
|
|
97
|
+
VirtualFileTracker.INSTANCE.track({ cell_id: cellId, output });
|
|
98
|
+
}
|
|
99
|
+
if (live && (item.kind === "console" || output.channel === "stderr")) {
|
|
100
|
+
actions.addLogs({
|
|
101
|
+
logs: getCellLogsForMessage({ cell_id: cellId, console: output }),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function consoleExecution(get: Getter, cellId: CellId) {
|
|
109
|
+
const replica = get(activeNotebookReplicaAtom);
|
|
110
|
+
if (!replica) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const state = get(replica.executionsAtom);
|
|
114
|
+
if (cellId === SCRATCH_CELL_ID) {
|
|
115
|
+
return state.scratchConsole;
|
|
116
|
+
}
|
|
117
|
+
const id = state.latest.get(cellId);
|
|
118
|
+
return id === undefined ? undefined : state.executions.get(id);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
interface ConsoleInputs {
|
|
122
|
+
local: CellRuntimeState;
|
|
123
|
+
execution: ReplicaExecution | undefined;
|
|
124
|
+
code: string | undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
interface ConsoleView extends ConsoleInputs {
|
|
128
|
+
rendered: CellRuntimeView;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Project the retained items and the editor's local transcript onto visible rows. */
|
|
132
|
+
export function consoleView(
|
|
133
|
+
inputs: ConsoleInputs,
|
|
134
|
+
previous?: ConsoleView,
|
|
135
|
+
): ConsoleView {
|
|
136
|
+
const { local, execution, code } = inputs;
|
|
137
|
+
if (
|
|
138
|
+
previous &&
|
|
139
|
+
previous.local === local &&
|
|
140
|
+
previous.code === code &&
|
|
141
|
+
previous.execution?.items === execution?.items
|
|
142
|
+
) {
|
|
143
|
+
return previous;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const record = execution?.record;
|
|
147
|
+
const cleared = local.clearedConsole;
|
|
148
|
+
const hidden = local.clearedConsoleInputs;
|
|
149
|
+
const fallback = record?.started_at
|
|
150
|
+
? Date.parse(record.started_at) / 1000
|
|
151
|
+
: 0;
|
|
152
|
+
const project = (item: Item) => {
|
|
153
|
+
if (
|
|
154
|
+
cleared &&
|
|
155
|
+
cleared.executionId === record?.id &&
|
|
156
|
+
item.seq <= cleared.seq &&
|
|
157
|
+
!(item.kind === "input" && cleared.prompts.has(item.id))
|
|
158
|
+
) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (
|
|
162
|
+
item.kind === "input" &&
|
|
163
|
+
hidden?.executionId === item.execution_id &&
|
|
164
|
+
hidden.ids.has(item.id)
|
|
165
|
+
) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const entry = consoleEntry(item, fallback, code);
|
|
169
|
+
if (
|
|
170
|
+
item.kind === "input" &&
|
|
171
|
+
!item.password &&
|
|
172
|
+
local.answers?.has(item.id)
|
|
173
|
+
) {
|
|
174
|
+
entry.response = local.answers.get(item.id);
|
|
175
|
+
}
|
|
176
|
+
return entry;
|
|
177
|
+
};
|
|
178
|
+
const commands = local.commandConsole?.entries;
|
|
179
|
+
const append = execution?.append;
|
|
180
|
+
if (
|
|
181
|
+
previous &&
|
|
182
|
+
previous.local === local &&
|
|
183
|
+
previous.code === code &&
|
|
184
|
+
previous.execution &&
|
|
185
|
+
append &&
|
|
186
|
+
append.before.deref() === previous.execution.items &&
|
|
187
|
+
(!commands?.length ||
|
|
188
|
+
commands.every(
|
|
189
|
+
(entry) =>
|
|
190
|
+
entry.afterSeq !== undefined && entry.afterSeq < append.item.seq,
|
|
191
|
+
))
|
|
192
|
+
) {
|
|
193
|
+
const added = project(append.item);
|
|
194
|
+
const rows = previous.rendered.consoleOutputs;
|
|
195
|
+
return {
|
|
196
|
+
...inputs,
|
|
197
|
+
rendered: {
|
|
198
|
+
serialization: local.serialization,
|
|
199
|
+
consoleOutputs: added ? collapseConsoleOutputs([...rows, added]) : rows,
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
let entries =
|
|
205
|
+
!execution || (record?.runtime_id === EMBEDDED && !execution.items.size)
|
|
206
|
+
? local.embeddedConsole
|
|
207
|
+
: itemsInOrder(execution).flatMap((item) => project(item) ?? []);
|
|
208
|
+
if (commands?.length) {
|
|
209
|
+
const anchored =
|
|
210
|
+
commands.every((entry) => entry.afterSeq !== undefined) &&
|
|
211
|
+
entries.every((entry) => entry.id !== undefined);
|
|
212
|
+
const position = (entry: ConsoleOutputMessage & { afterSeq?: number }) =>
|
|
213
|
+
entry.afterSeq === undefined ? (entry.id ?? 0) : entry.afterSeq + 1.5;
|
|
214
|
+
entries = [
|
|
215
|
+
...entries,
|
|
216
|
+
...commands.map((entry, index) => ({ ...entry, id: -1 - index })),
|
|
217
|
+
].toSorted(
|
|
218
|
+
(a, b) =>
|
|
219
|
+
(anchored ? position(a) - position(b) : 0) ||
|
|
220
|
+
(a.timestamp ?? 0) - (b.timestamp ?? 0),
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
...inputs,
|
|
225
|
+
rendered: {
|
|
226
|
+
serialization: local.serialization,
|
|
227
|
+
consoleOutputs: collapseConsoleBatch(entries),
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
}
|
package/src/core/cells/focus.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
3
|
import type { EditorView } from "@codemirror/view";
|
|
4
|
-
import { atom, useAtomValue } from "jotai";
|
|
4
|
+
import { atom, useAtomValue, type Getter } from "jotai";
|
|
5
5
|
import { createReducerAndAtoms } from "@/utils/createReducer";
|
|
6
6
|
import {
|
|
7
|
-
type CellExecutionInputs,
|
|
8
|
-
type CellOutput,
|
|
9
7
|
type CellRunStatus,
|
|
10
8
|
cellExecutionInputsAtom,
|
|
11
9
|
cellExecutionView,
|
|
12
10
|
cellOutputAtom,
|
|
13
11
|
} from "@/core/executions";
|
|
14
12
|
import type { CellConfig } from "../network/types";
|
|
15
|
-
import {
|
|
13
|
+
import { cellRuntimeAtom, notebookAtom } from "./cells";
|
|
16
14
|
import type { CellId } from "./ids";
|
|
17
15
|
import { SCRATCH_CELL_ID } from "./ids";
|
|
18
16
|
export interface CellFocusState {
|
|
@@ -98,40 +96,22 @@ export const lastFocusedCellAtom = atom<{
|
|
|
98
96
|
return null;
|
|
99
97
|
}
|
|
100
98
|
|
|
101
|
-
return cellFocusDetails(
|
|
102
|
-
cellId,
|
|
103
|
-
get(notebookAtom),
|
|
104
|
-
get(cellExecutionInputsAtom),
|
|
105
|
-
get(cellOutputAtom(cellId)),
|
|
106
|
-
);
|
|
99
|
+
return cellFocusDetails(get, cellId);
|
|
107
100
|
});
|
|
108
101
|
|
|
109
102
|
export function cellFocusDetailsAtom(cellId: CellId) {
|
|
110
|
-
return atom((get) =>
|
|
111
|
-
return cellFocusDetails(
|
|
112
|
-
cellId,
|
|
113
|
-
get(notebookAtom),
|
|
114
|
-
get(cellExecutionInputsAtom),
|
|
115
|
-
get(cellOutputAtom(cellId)),
|
|
116
|
-
);
|
|
117
|
-
});
|
|
103
|
+
return atom((get) => cellFocusDetails(get, cellId));
|
|
118
104
|
}
|
|
119
105
|
|
|
120
|
-
function cellFocusDetails(
|
|
121
|
-
|
|
122
|
-
notebookState: NotebookState,
|
|
123
|
-
executions: CellExecutionInputs,
|
|
124
|
-
output: CellOutput | null,
|
|
125
|
-
) {
|
|
126
|
-
const { cellData, cellHandles, cellRuntime } = notebookState;
|
|
106
|
+
function cellFocusDetails(get: Getter, cellId: CellId) {
|
|
107
|
+
const { cellData, cellHandles } = get(notebookAtom);
|
|
127
108
|
const data = cellData[cellId];
|
|
128
|
-
const runtime = cellRuntime[cellId];
|
|
129
109
|
const handle = cellHandles[cellId]?.current;
|
|
130
110
|
if (!data || !handle) {
|
|
131
111
|
return null;
|
|
132
112
|
}
|
|
133
113
|
const getEditorView = () => handle.editorViewOrNull;
|
|
134
|
-
const execution = cellExecutionView(
|
|
114
|
+
const execution = cellExecutionView(get(cellExecutionInputsAtom), cellId);
|
|
135
115
|
|
|
136
116
|
return {
|
|
137
117
|
cellId,
|
|
@@ -140,8 +120,8 @@ function cellFocusDetails(
|
|
|
140
120
|
status: execution.status,
|
|
141
121
|
blocked: execution.blocked,
|
|
142
122
|
getEditorView: getEditorView,
|
|
143
|
-
hasOutput:
|
|
144
|
-
hasConsoleOutput:
|
|
123
|
+
hasOutput: get(cellOutputAtom(cellId)) !== null,
|
|
124
|
+
hasConsoleOutput: get(cellRuntimeAtom(cellId)).consoleOutputs.length > 0,
|
|
145
125
|
};
|
|
146
126
|
}
|
|
147
127
|
|
package/src/core/cells/logs.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { fromUnixTime } from "date-fns";
|
|
|
4
4
|
import { toast } from "@/components/ui/use-toast";
|
|
5
5
|
import { parseHtmlContent } from "@/utils/dom";
|
|
6
6
|
import { Strings } from "@/utils/strings";
|
|
7
|
-
import type {
|
|
7
|
+
import type { OutputMessage } from "../kernel/messages";
|
|
8
|
+
import type { CellOutput } from "../executions";
|
|
8
9
|
import { isErrorMime } from "../mime";
|
|
9
10
|
import type { CellId } from "./ids";
|
|
10
11
|
import { initialModeAtom } from "../mode";
|
|
@@ -32,7 +33,14 @@ export function logSourceLabel(source: LogSource): string {
|
|
|
32
33
|
|
|
33
34
|
let didAlreadyToastError = false;
|
|
34
35
|
|
|
35
|
-
export
|
|
36
|
+
export interface CellLogMessage {
|
|
37
|
+
cell_id: CellId;
|
|
38
|
+
console?: OutputMessage | OutputMessage[] | null;
|
|
39
|
+
output?: CellOutput | null;
|
|
40
|
+
timestamp?: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getCellLogsForMessage(cell: CellLogMessage): CellLog[] {
|
|
36
44
|
const logs: CellLog[] = [];
|
|
37
45
|
const consoleOutputs: OutputMessage[] = [cell.console].filter(Boolean).flat();
|
|
38
46
|
|
package/src/core/cells/runs.ts
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
import { createReducerAndAtoms } from "@/utils/createReducer";
|
|
3
3
|
import type { TypedString } from "@/utils/typed";
|
|
4
|
-
import type {
|
|
4
|
+
import type { Execution } from "@marimo-team/client/protocol";
|
|
5
5
|
import type { CellId } from "./ids";
|
|
6
6
|
export type RunId = TypedString<"RunId">;
|
|
7
7
|
|
|
8
8
|
export interface CellRun {
|
|
9
9
|
cellId: CellId;
|
|
10
|
+
executionId: Execution["id"];
|
|
10
11
|
code: string;
|
|
11
12
|
elapsedTime?: number;
|
|
12
13
|
startTime: number;
|
|
13
|
-
status:
|
|
14
|
+
status:
|
|
15
|
+
| "queued"
|
|
16
|
+
| "running"
|
|
17
|
+
| "success"
|
|
18
|
+
| "error"
|
|
19
|
+
| "skipped"
|
|
20
|
+
| "interrupted";
|
|
14
21
|
}
|
|
15
22
|
|
|
16
23
|
export interface Run {
|
|
@@ -34,136 +41,73 @@ function initialState(): RunsState {
|
|
|
34
41
|
export const MAX_RUNS = 50;
|
|
35
42
|
export const MAX_CODE_LENGTH = 200;
|
|
36
43
|
|
|
44
|
+
function traceStatus(record: Execution): CellRun["status"] {
|
|
45
|
+
if (record.status !== "completed") {
|
|
46
|
+
return record.status;
|
|
47
|
+
}
|
|
48
|
+
const outcome = record.outcome?.kind;
|
|
49
|
+
return outcome === "value" ? "success" : (outcome ?? "error");
|
|
50
|
+
}
|
|
51
|
+
|
|
37
52
|
const {
|
|
38
53
|
reducer,
|
|
39
54
|
createActions,
|
|
40
55
|
valueAtom: runsAtom,
|
|
41
56
|
useActions: useRunsActions,
|
|
42
57
|
} = createReducerAndAtoms(initialState, {
|
|
43
|
-
|
|
58
|
+
addExecution: (
|
|
44
59
|
state: RunsState,
|
|
45
|
-
|
|
60
|
+
{
|
|
61
|
+
record,
|
|
62
|
+
code,
|
|
63
|
+
receivedAt,
|
|
64
|
+
}: { record: Execution; code: string | undefined; receivedAt: number },
|
|
46
65
|
): RunsState => {
|
|
47
|
-
|
|
48
|
-
const timestamp = cellNotification.timestamp ?? 0;
|
|
49
|
-
const runId = cellNotification.run_id as RunId | undefined;
|
|
50
|
-
if (!runId) {
|
|
66
|
+
if (record.run_id === null || record.cell_id === null) {
|
|
51
67
|
return state;
|
|
52
68
|
}
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// This spams the tracing because we re-render pure markdown on keystrokes.
|
|
58
|
-
if (!existingRun && isPureMarkdown(code)) {
|
|
69
|
+
const runId = record.run_id as RunId;
|
|
70
|
+
const cellId = record.cell_id as CellId;
|
|
71
|
+
const previous = state.runMap.get(runId);
|
|
72
|
+
if (previous === undefined && code !== undefined && isPureMarkdown(code)) {
|
|
59
73
|
return state;
|
|
60
74
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
startTime: timestamp,
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
]),
|
|
92
|
-
runStartTime: timestamp,
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
// Manage run history size
|
|
96
|
-
const runIds = [runId, ...state.runIds];
|
|
97
|
-
const nextRunMap = new Map(state.runMap);
|
|
98
|
-
if (runIds.length > MAX_RUNS) {
|
|
99
|
-
const oldestRunId = runIds.pop();
|
|
100
|
-
if (oldestRunId) {
|
|
101
|
-
nextRunMap.delete(oldestRunId);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
nextRunMap.set(runId, newRun);
|
|
106
|
-
return {
|
|
107
|
-
runIds,
|
|
108
|
-
runMap: nextRunMap,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Update existing run
|
|
113
|
-
const nextCellRuns = new Map(existingRun.cellRuns);
|
|
114
|
-
const existingCellRun = nextCellRuns.get(cellNotification.cell_id);
|
|
115
|
-
|
|
116
|
-
// Early return if nothing changed
|
|
117
|
-
if (
|
|
118
|
-
existingCellRun &&
|
|
119
|
-
!erroredOutput &&
|
|
120
|
-
cellNotification.status === "queued"
|
|
121
|
-
) {
|
|
122
|
-
return state;
|
|
75
|
+
const cellRuns = new Map(previous?.cellRuns);
|
|
76
|
+
const prior = cellRuns.get(cellId);
|
|
77
|
+
const sameExecution = prior?.executionId === record.id ? prior : undefined;
|
|
78
|
+
const ended =
|
|
79
|
+
record.completed_at === null
|
|
80
|
+
? undefined
|
|
81
|
+
: Date.parse(record.completed_at) / 1000;
|
|
82
|
+
const startTime =
|
|
83
|
+
record.started_at === null
|
|
84
|
+
? (sameExecution?.startTime ?? ended ?? receivedAt)
|
|
85
|
+
: Date.parse(record.started_at) / 1000;
|
|
86
|
+
cellRuns.set(cellId, {
|
|
87
|
+
cellId,
|
|
88
|
+
executionId: record.id,
|
|
89
|
+
code: code?.slice(0, MAX_CODE_LENGTH) ?? sameExecution?.code ?? "",
|
|
90
|
+
startTime,
|
|
91
|
+
status: traceStatus(record),
|
|
92
|
+
elapsedTime: ended === undefined ? undefined : ended - startTime,
|
|
93
|
+
});
|
|
94
|
+
const runMap = new Map(state.runMap);
|
|
95
|
+
runMap.set(runId, {
|
|
96
|
+
runId,
|
|
97
|
+
cellRuns,
|
|
98
|
+
runStartTime: previous?.runStartTime ?? startTime,
|
|
99
|
+
});
|
|
100
|
+
if (previous !== undefined) {
|
|
101
|
+
return { ...state, runMap };
|
|
123
102
|
}
|
|
124
|
-
|
|
125
|
-
if (
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const startTime =
|
|
132
|
-
cellNotification.status === "running"
|
|
133
|
-
? timestamp
|
|
134
|
-
: existingCellRun.startTime;
|
|
135
|
-
|
|
136
|
-
const elapsedTime =
|
|
137
|
-
status === "success" || status === "error"
|
|
138
|
-
? timestamp - existingCellRun.startTime
|
|
139
|
-
: undefined;
|
|
140
|
-
|
|
141
|
-
nextCellRuns.set(cellNotification.cell_id, {
|
|
142
|
-
...existingCellRun,
|
|
143
|
-
startTime,
|
|
144
|
-
elapsedTime,
|
|
145
|
-
status,
|
|
146
|
-
});
|
|
147
|
-
} else {
|
|
148
|
-
nextCellRuns.set(cellNotification.cell_id, {
|
|
149
|
-
cellId: cellNotification.cell_id,
|
|
150
|
-
code: code.slice(0, MAX_CODE_LENGTH),
|
|
151
|
-
elapsedTime: 0,
|
|
152
|
-
status: status,
|
|
153
|
-
startTime: timestamp,
|
|
154
|
-
});
|
|
103
|
+
const runIds = [runId, ...state.runIds];
|
|
104
|
+
if (runIds.length > MAX_RUNS) {
|
|
105
|
+
const oldest = runIds.pop();
|
|
106
|
+
if (oldest !== undefined) {
|
|
107
|
+
runMap.delete(oldest);
|
|
108
|
+
}
|
|
155
109
|
}
|
|
156
|
-
|
|
157
|
-
const nextRunMap = new Map(state.runMap);
|
|
158
|
-
nextRunMap.set(runId, {
|
|
159
|
-
...existingRun,
|
|
160
|
-
cellRuns: nextCellRuns,
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
return {
|
|
164
|
-
...state,
|
|
165
|
-
runMap: nextRunMap,
|
|
166
|
-
};
|
|
110
|
+
return { runIds, runMap };
|
|
167
111
|
},
|
|
168
112
|
clearRuns: (state: RunsState): RunsState => ({
|
|
169
113
|
...state,
|
|
@@ -12,7 +12,7 @@ import { DEFAULT_CELL_NAME } from "./names";
|
|
|
12
12
|
import { type CellRuntimeState, createCellRuntimeState } from "./types";
|
|
13
13
|
|
|
14
14
|
/** The identity of a snapshot the page carries. A host's own stream replaces it. */
|
|
15
|
-
const EMBEDDED = "embedded";
|
|
15
|
+
export const EMBEDDED = "embedded";
|
|
16
16
|
|
|
17
17
|
// Constants
|
|
18
18
|
const DEFAULT_TIMESTAMP = 0;
|
|
@@ -280,7 +280,7 @@ function createCellRuntimeFromSession(
|
|
|
280
280
|
|
|
281
281
|
return {
|
|
282
282
|
...runtimeState,
|
|
283
|
-
|
|
283
|
+
embeddedConsole: consoleOutputs.map((consoleOutput) => {
|
|
284
284
|
// Handle StreamMediaOutput (type: "streamMedia")
|
|
285
285
|
if (consoleOutput.type === "streamMedia") {
|
|
286
286
|
return {
|