@marimo-team/islands 0.25.3-dev388 → 0.25.3-dev391

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.
Files changed (101) hide show
  1. package/dist/{ErrorBoundary-_mFP3LkM.js → ErrorBoundary-DNRG0xHi.js} +1 -1
  2. package/dist/{chat-ui-BKSYhGMh.js → chat-ui-CWVNPm2l.js} +769 -769
  3. package/dist/{code-visibility-DkMNjdNe.js → code-visibility-Ca8sDptK.js} +10 -10
  4. package/dist/{common-Ces9ooG_.js → common-B3NYpak4.js} +4910 -4902
  5. package/dist/{data-grid-overlay-editor-uNMslVKY.js → data-grid-overlay-editor-Cz7uMmtm.js} +1 -1
  6. package/dist/{error-entries-rtPWQkJk.js → error-entries-CnXf4kpP.js} +821 -686
  7. package/dist/{feedback-button-i960qUnq.js → feedback-button-BQbnZsf5.js} +7 -7
  8. package/dist/{glide-data-editor-_EEhlGzS.js → glide-data-editor-Bxc30klU.js} +3 -3
  9. package/dist/{globals-DKkjIolp.js → globals-CDatnx0Y.js} +1 -1
  10. package/dist/{html-to-image-B5nTOeMI.js → html-to-image-Bu_-vH_Y.js} +4782 -4765
  11. package/dist/main.js +6233 -6172
  12. package/dist/{number-overlay-editor-D5U7jbrh.js → number-overlay-editor-ChGu5C-s.js} +1 -1
  13. package/dist/{process-output-DNxpsd4n.js → process-output-Rbqr1aYD.js} +2 -2
  14. package/dist/{reveal-component-BM9TozVQ.js → reveal-component-CSxWJFAP.js} +32 -32
  15. package/dist/style.css +1 -1
  16. package/package.json +1 -1
  17. package/src/__mocks__/executions.ts +48 -8
  18. package/src/__mocks__/notebook.ts +20 -42
  19. package/src/components/app-config/__tests__/add-model-discovery.test.tsx +255 -0
  20. package/src/components/app-config/__tests__/model-discovery.test.tsx +183 -0
  21. package/src/components/app-config/ai-config.tsx +20 -24
  22. package/src/components/app-config/model-discovery.tsx +118 -184
  23. package/src/components/app-config/model-provider-config.ts +25 -0
  24. package/src/components/editor/Output.tsx +5 -4
  25. package/src/components/editor/__tests__/data-attributes.test.tsx +1 -6
  26. package/src/components/editor/__tests__/dynamic-favicon.test.tsx +11 -16
  27. package/src/components/editor/__tests__/output-persistence.test.tsx +6 -24
  28. package/src/components/editor/actions/__tests__/useSetOutputsExpanded.test.ts +6 -8
  29. package/src/components/editor/actions/useSetOutputsExpanded.ts +12 -4
  30. package/src/components/editor/cell/cell-context-menu.tsx +3 -2
  31. package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +89 -72
  32. package/src/components/editor/notebook-cell.tsx +15 -10
  33. package/src/components/editor/output/console/process-output.ts +4 -2
  34. package/src/components/editor/renderers/cells-renderer.tsx +3 -1
  35. package/src/components/editor/renderers/grid-layout/__tests__/grid-layout.test.tsx +5 -11
  36. package/src/components/editor/renderers/grid-layout/grid-layout.tsx +9 -8
  37. package/src/components/editor/renderers/types.ts +2 -2
  38. package/src/components/editor/renderers/vertical-layout/utils.ts +4 -4
  39. package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +5 -8
  40. package/src/components/scratchpad/scratchpad.tsx +6 -2
  41. package/src/components/slides/__tests__/cell-output-block.test.tsx +7 -8
  42. package/src/components/slides/__tests__/minimap-actions.test.tsx +3 -3
  43. package/src/components/slides/__tests__/slide-cell-view.test.tsx +1 -0
  44. package/src/components/slides/slide-cell-view.tsx +1 -3
  45. package/src/components/slides/slide.tsx +3 -3
  46. package/src/core/ai/context/__tests__/registry.test.ts +7 -11
  47. package/src/core/ai/context/providers/__tests__/cell-output.test.ts +113 -35
  48. package/src/core/ai/context/providers/__tests__/error.test.ts +74 -191
  49. package/src/core/ai/context/providers/cell-output.ts +11 -6
  50. package/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap +8 -103
  51. package/src/core/cells/__tests__/cells.test.ts +40 -292
  52. package/src/core/cells/__tests__/clear-outputs.test.ts +151 -0
  53. package/src/core/cells/__tests__/harness.ts +14 -12
  54. package/src/core/cells/__tests__/layout.test.ts +20 -26
  55. package/src/core/cells/__tests__/notebook-outline.test.ts +49 -43
  56. package/src/core/cells/__tests__/session.test.ts +26 -146
  57. package/src/core/cells/actions.ts +49 -9
  58. package/src/core/cells/cell.ts +0 -13
  59. package/src/core/cells/cells.ts +53 -62
  60. package/src/core/cells/focus.ts +6 -1
  61. package/src/core/cells/layout.ts +2 -3
  62. package/src/core/cells/outputs.ts +2 -2
  63. package/src/core/cells/session.ts +3 -38
  64. package/src/core/cells/types.ts +6 -8
  65. package/src/core/cells/utils.ts +4 -3
  66. package/src/core/codemirror/ai/__tests__/resources.test.ts +7 -11
  67. package/src/core/errors/__tests__/error-entries.test.ts +52 -18
  68. package/src/core/errors/error-entries.ts +21 -11
  69. package/src/core/executions/__tests__/freshness.test.ts +7 -4
  70. package/src/core/executions/__tests__/hooks.test.tsx +5 -1
  71. package/src/core/executions/__tests__/interrupt.test.ts +2 -0
  72. package/src/core/executions/__tests__/output-lifecycle.test.ts +201 -0
  73. package/src/core/executions/__tests__/output.test.ts +87 -3
  74. package/src/core/executions/__tests__/select.test.ts +17 -10
  75. package/src/core/executions/atoms.ts +73 -15
  76. package/src/core/executions/freshness.ts +1 -1
  77. package/src/core/executions/hooks.ts +18 -8
  78. package/src/core/executions/index.ts +6 -0
  79. package/src/core/executions/output.ts +122 -38
  80. package/src/core/executions/select.ts +2 -2
  81. package/src/core/export/__tests__/hooks.test.ts +20 -29
  82. package/src/core/export/hooks.ts +7 -9
  83. package/src/core/islands/__tests__/iframe-resizer.test.ts +91 -0
  84. package/src/core/islands/__tests__/main.test.ts +17 -0
  85. package/src/core/islands/components/__tests__/web-components.test.tsx +13 -15
  86. package/src/core/islands/components/output-wrapper.tsx +15 -20
  87. package/src/core/islands/iframe-resizer.ts +38 -0
  88. package/src/core/islands/main.ts +3 -0
  89. package/src/core/lifecycle/render-policy.ts +7 -4
  90. package/src/core/network/__tests__/ai.test.ts +41 -0
  91. package/src/core/network/ai.ts +12 -0
  92. package/src/core/notebook/document/__tests__/codemirror.test.ts +2 -0
  93. package/src/core/notebook/replica/__tests__/replica.test.ts +19 -0
  94. package/src/core/notebook/replica/__tests__/results.test.ts +45 -16
  95. package/src/core/notebook/replica/index.ts +1 -1
  96. package/src/core/notebook/replica/replica.ts +19 -4
  97. package/src/core/notebook/replica/resources/executions.ts +100 -9
  98. package/src/core/notebook/replica/resources/results.ts +46 -31
  99. package/src/core/transports/__tests__/static.test.ts +5 -3
  100. package/src/stories/cell.stories.tsx +40 -30
  101. package/src/stories/layout/vertical/one-column.stories.tsx +15 -7
@@ -5,7 +5,6 @@ import type {
5
5
  CellRunStatus,
6
6
  } from "@/core/executions";
7
7
  import { extractAllTracebackInfo, type TracebackInfo } from "@/utils/traceback";
8
- import { parseOutline } from "../dom/outline";
9
8
  import type { CellMessage, OutputMessage } from "../kernel/messages";
10
9
  import { collapseConsoleOutputs } from "./collapseConsoleOutputs";
11
10
  import type { CellRuntimeState, ConsoleOutputMessage } from "./types";
@@ -35,16 +34,6 @@ export function transitionCell(
35
34
  if (message.status === "queued") {
36
35
  nextCell.debuggerActive = false;
37
36
  }
38
- // A skipped cell's output is the notice that an ancestor stopped it, which
39
- // has nothing to do with the run that is starting.
40
- if (
41
- message.status === "running" &&
42
- errorTypes(cell.output).some((type) => type.includes("ancestor"))
43
- ) {
44
- nextCell.output = null;
45
- }
46
-
47
- nextCell.output = message.output ?? nextCell.output;
48
37
  // Tri-state partial update: an omitted field (undefined) leaves the hint
49
38
  // unchanged; null explicitly clears it; a string sets it.
50
39
  if (message.serialization !== undefined) {
@@ -95,8 +84,6 @@ export function transitionCell(
95
84
  ]);
96
85
  }
97
86
  nextCell.consoleOutputs = consoleOutputs;
98
- // Derive outline from output
99
- nextCell.outline = parseOutline(nextCell.output);
100
87
 
101
88
  // Transition PDB
102
89
  const newConsoleOutputs = [message.console].flat().filter(Boolean);
@@ -7,9 +7,13 @@ import { createRef, type ReducerWithoutAction } from "react";
7
7
  import type { CellHandle } from "@/components/editor/notebook-cell";
8
8
  import type { EditableDocument, Placement } from "@/core/notebook/document";
9
9
  import {
10
+ type CellOutput,
10
11
  cellExecutionInputsAtom,
11
12
  cellExecutionView,
12
13
  cellFreshnessAtom,
14
+ cellOutlineAtom,
15
+ cellOutputAtom,
16
+ releaseCellOutputAtoms,
13
17
  } from "@/core/executions";
14
18
  import type { CellColumnId } from "./layout";
15
19
  import { invariant } from "@/utils/invariant";
@@ -37,6 +41,7 @@ import {
37
41
  type CellRuntimeState,
38
42
  createCell,
39
43
  createCellRuntimeState,
44
+ type RuntimeCell,
40
45
  } from "./types";
41
46
  import {
42
47
  canUndoDeletes,
@@ -230,8 +235,8 @@ const {
230
235
  });
231
236
  },
232
237
  /**
233
- * Start each cell's runtime over for a new kernel. WASM keeps the outputs
234
- * its mount-time snapshot gave it.
238
+ * Start each cell's runtime over for a new kernel. WASM keeps the console
239
+ * output its mount-time snapshot gave it.
235
240
  */
236
241
  resetCellRuntimes: (state) => {
237
242
  const preserveSnapshot = isWasm();
@@ -241,7 +246,7 @@ const {
241
246
  const hasSnapshot =
242
247
  preserveSnapshot &&
243
248
  previous !== undefined &&
244
- (previous.output != null || previous.consoleOutputs.length > 0);
249
+ previous.consoleOutputs.length > 0;
245
250
  cellRuntime[cellId] = hasSnapshot ? previous : createCellRuntimeState();
246
251
  }
247
252
  return { ...state, cellRuntime };
@@ -291,48 +296,35 @@ const {
291
296
  cellLogs: [],
292
297
  };
293
298
  },
294
- clearCellOutput: (state, action: { cellId: CellId }) => {
295
- const { cellId } = action;
296
- return updateCellRuntimeState({
297
- state,
298
- cellId,
299
- cellReducer: (cell) => ({
300
- ...cell,
301
- output: null,
302
- consoleOutputs: [],
303
- }),
304
- });
305
- },
306
299
  clearCellConsoleOutput: (state, action: { cellId: CellId }) => {
307
- const { cellId } = action;
308
- return updateCellRuntimeState({
309
- state,
310
- cellId,
311
- cellReducer: (cell) => ({
312
- ...cell,
313
- // Remove everything except unresponsed stdin
314
- consoleOutputs: cell.consoleOutputs.filter(
315
- (output) => output.channel === "stdin" && output.response == null,
316
- ),
317
- }),
318
- });
300
+ return clearConsoleOutputs(state, [action.cellId]);
319
301
  },
320
- clearAllCellOutputs: (state) => {
321
- const newCellRuntime = { ...state.cellRuntime };
322
- for (const cellId of state.cellIds) {
323
- newCellRuntime[cellId] = {
324
- ...newCellRuntime[cellId],
325
- output: null,
326
- consoleOutputs: [],
327
- };
328
- }
329
- return {
330
- ...state,
331
- cellRuntime: newCellRuntime,
332
- };
302
+ clearCellConsoleOutputs: (state, action: { cellIds: readonly CellId[] }) => {
303
+ return clearConsoleOutputs(state, action.cellIds);
333
304
  },
334
305
  });
335
306
 
307
+ function clearConsoleOutputs(
308
+ state: NotebookState,
309
+ cellIds: readonly CellId[],
310
+ ): NotebookState {
311
+ const cellRuntime = { ...state.cellRuntime };
312
+ for (const cellId of cellIds) {
313
+ const cell = cellRuntime[cellId];
314
+ if (cell === undefined) {
315
+ Logger.warn(`Cell ${cellId} not found in state`);
316
+ continue;
317
+ }
318
+ cellRuntime[cellId] = {
319
+ ...cell,
320
+ consoleOutputs: cell.consoleOutputs.filter(
321
+ (output) => output.channel === "stdin" && output.response == null,
322
+ ),
323
+ };
324
+ }
325
+ return { ...state, cellRuntime };
326
+ }
327
+
336
328
  // Helper function to update a cell in the array
337
329
  function updateCellRuntimeState({
338
330
  state,
@@ -397,23 +389,23 @@ export const needsRunAtom = atom((get) =>
397
389
  );
398
390
 
399
391
  export const cellErrorsAtom = atom((get) => {
400
- const { cellIds, cellRuntime, cellData } = get(notebookAtom);
392
+ const { cellIds, cellData } = get(notebookAtom);
401
393
  const errors = cellIds
402
394
  .map((cellId) => {
403
- const cell = cellRuntime[cellId];
395
+ const output = get(cellOutputAtom(cellId));
404
396
  const { name } = cellData[cellId];
405
- if (isErrorMime(cell.output?.mimetype)) {
397
+ if (output !== null && isErrorMime(output.mimetype)) {
406
398
  // Filter out ancestor-stopped errors
407
399
  // These are errors that are caused by a cell that was stopped,
408
400
  // but nothing the user can take action on.
409
- invariant(Array.isArray(cell.output.data), "Expected array data");
410
- const nonAncestorErrors = cell.output.data.filter(
401
+ invariant(Array.isArray(output.data), "Expected array data");
402
+ const nonAncestorErrors = output.data.filter(
411
403
  (error) => !error.type.includes("ancestor"),
412
404
  );
413
405
 
414
406
  if (nonAncestorErrors.length > 0) {
415
407
  return {
416
- output: { ...cell.output, data: nonAncestorErrors },
408
+ output: { ...output, data: nonAncestorErrors },
417
409
  cellId: cellId,
418
410
  cellName: name,
419
411
  };
@@ -428,28 +420,25 @@ export const cellErrorsAtom = atom((get) => {
428
420
 
429
421
  /**
430
422
  * The outline of each cell whose output has a heading. Compared by value, so
431
- * readers are left alone by the runtime messages that change no heading.
423
+ * readers are left alone by the runs that change no heading.
432
424
  */
433
425
  export const cellOutlinesAtom = createDeepEqualAtom(
434
426
  atom((get) => {
435
427
  const outlines: Partial<Record<CellId, Outline>> = {};
436
- for (const [id, runtime] of Objects.entries(
437
- get(notebookAtom).cellRuntime,
438
- )) {
439
- if (runtime.outline !== null && runtime.outline.items.length > 0) {
440
- outlines[id] = runtime.outline;
428
+ for (const cellId of get(cellIdsAtom)) {
429
+ const outline = get(cellOutlineAtom(cellId));
430
+ if (outline !== null && outline.items.length > 0) {
431
+ outlines[cellId] = outline;
441
432
  }
442
433
  }
443
434
  return outlines;
444
435
  }),
445
436
  );
446
437
 
447
- export const notebookOutline = atom((get) => {
448
- const cellIds = get(cellIdsAtom);
449
- const cellRuntime = get(cellsRuntimeAtom);
450
- const outlines = cellIds.map((cellId) => cellRuntime[cellId].outline);
451
- return mergeOutlines(outlines);
452
- });
438
+ /** The notebook's table of contents, in document order. */
439
+ export const notebookOutline = atom((get) =>
440
+ mergeOutlines(get(cellIdsAtom).map((cellId) => get(cellOutlineAtom(cellId)))),
441
+ );
453
442
 
454
443
  export const cellErrorCount = atom((get) => get(cellErrorsAtom).length);
455
444
 
@@ -524,8 +513,6 @@ const cellDataAtoms = splitAtom(
524
513
  );
525
514
  export const useCellDataAtoms = () => useAtom(cellDataAtoms);
526
515
 
527
- export const cellsRuntimeAtom = atom((get) => get(notebookAtom).cellRuntime);
528
-
529
516
  export const hasCellsAtom = atom((get) => get(notebookAtom).cellIds.length > 0);
530
517
  export const cellDataAtom = atomFamily((cellId: CellId) =>
531
518
  atom((get) => get(notebookAtom).cellData[cellId]),
@@ -550,6 +537,7 @@ export function releaseCellAtoms(cellId: CellId) {
550
537
  cellDataAtom.remove(cellId);
551
538
  cellRuntimeAtom.remove(cellId);
552
539
  cellHandleAtom.remove(cellId);
540
+ releaseCellOutputAtoms(cellId);
553
541
  }
554
542
 
555
543
  /** Subscribes to reactive updates of the cell's data. */
@@ -587,13 +575,16 @@ export const ensureCellEditorView = (cellId: CellId) => {
587
575
  return getCellEditorView(cellId);
588
576
  };
589
577
 
578
+ /** The document's cells with their runtime state and what each shows. */
590
579
  export function flattenTopLevelNotebookCells(
591
580
  state: NotebookState,
592
- ): (CellData & CellRuntimeState)[] {
581
+ outputs: ReadonlyMap<CellId, CellOutput>,
582
+ ): RuntimeCell[] {
593
583
  const { cellIds, cellData, cellRuntime } = state;
594
584
  return cellIds.map((cellId) => ({
595
585
  ...cellData[cellId],
596
586
  ...cellRuntime[cellId],
587
+ output: outputs.get(cellId) ?? null,
597
588
  }));
598
589
  }
599
590
 
@@ -630,7 +621,7 @@ export function createTracebackInfoAtom(
630
621
  }
631
622
 
632
623
  // Syntax errors
633
- const output = data.output;
624
+ const output = get(cellOutputAtom(cellId));
634
625
  if (output?.mimetype === "application/vnd.marimo+error") {
635
626
  const errors = output.data;
636
627
  if (Array.isArray(errors)) {
@@ -5,9 +5,11 @@ import { atom, useAtomValue } from "jotai";
5
5
  import { createReducerAndAtoms } from "@/utils/createReducer";
6
6
  import {
7
7
  type CellExecutionInputs,
8
+ type CellOutput,
8
9
  type CellRunStatus,
9
10
  cellExecutionInputsAtom,
10
11
  cellExecutionView,
12
+ cellOutputAtom,
11
13
  } from "@/core/executions";
12
14
  import type { CellConfig } from "../network/types";
13
15
  import { type NotebookState, notebookAtom } from "./cells";
@@ -100,6 +102,7 @@ export const lastFocusedCellAtom = atom<{
100
102
  cellId,
101
103
  get(notebookAtom),
102
104
  get(cellExecutionInputsAtom),
105
+ get(cellOutputAtom(cellId)),
103
106
  );
104
107
  });
105
108
 
@@ -109,6 +112,7 @@ export function cellFocusDetailsAtom(cellId: CellId) {
109
112
  cellId,
110
113
  get(notebookAtom),
111
114
  get(cellExecutionInputsAtom),
115
+ get(cellOutputAtom(cellId)),
112
116
  );
113
117
  });
114
118
  }
@@ -117,6 +121,7 @@ function cellFocusDetails(
117
121
  cellId: CellId,
118
122
  notebookState: NotebookState,
119
123
  executions: CellExecutionInputs,
124
+ output: CellOutput | null,
120
125
  ) {
121
126
  const { cellData, cellHandles, cellRuntime } = notebookState;
122
127
  const data = cellData[cellId];
@@ -135,7 +140,7 @@ function cellFocusDetails(
135
140
  status: execution.status,
136
141
  blocked: execution.blocked,
137
142
  getEditorView: getEditorView,
138
- hasOutput: runtime?.output != null,
143
+ hasOutput: output !== null,
139
144
  hasConsoleOutput: runtime?.consoleOutputs != null,
140
145
  };
141
146
  }
@@ -138,9 +138,8 @@ export function deriveLayout(
138
138
 
139
139
  /**
140
140
  * The layout of the notebook's cells: the document's order and columns,
141
- * this browser's column ids and folds, and the kernel's outlines.
142
- *
143
- * TODO(MO-8404): Outlines come from the host.
141
+ * this browser's column ids and folds, and the headings in each cell's
142
+ * output.
144
143
  */
145
144
  export const layoutAtom = atom((get): Layout => {
146
145
  const model = get(activeDocumentModelAtom);
@@ -7,7 +7,7 @@ import {
7
7
  useNotebookCellConfig,
8
8
  useNotebookDocumentEdit,
9
9
  } from "../notebook/document";
10
- import type { OutputMessage } from "../kernel/messages";
10
+ import type { CellOutput } from "../executions";
11
11
  import { viewStateAtom } from "../mode";
12
12
  import { type CellId, SCRATCH_CELL_ID } from "./ids";
13
13
 
@@ -73,7 +73,7 @@ export function useExpandedConsoleOutput(cellId: CellId) {
73
73
  }
74
74
 
75
75
  export function isOutputEmpty(
76
- output: OutputMessage | undefined | null,
76
+ output: Pick<CellOutput, "data"> | undefined | null,
77
77
  ): boolean {
78
78
  if (output == null) {
79
79
  return true;
@@ -6,7 +6,6 @@ import type * as Protocol from "@marimo-team/client/protocol";
6
6
  import type * as api from "@marimo-team/marimo-api";
7
7
  import { mergeArray } from "@/utils/edit-distance";
8
8
  import { Logger } from "@/utils/Logger";
9
- import { parseOutline } from "../dom/outline";
10
9
  import type { StaticNotebookSnapshot } from "../transports/static";
11
10
  import { CellId, SETUP_CELL_ID } from "./ids";
12
11
  import { DEFAULT_CELL_NAME } from "./names";
@@ -277,44 +276,10 @@ function createCellRuntimeFromSession(
277
276
  return runtimeState;
278
277
  }
279
278
 
280
- const primaryOutput = primaryOutputOf(sessionCell);
281
-
282
- if (primaryOutput) {
283
- if (primaryOutput.type === "error") {
284
- runtimeState.output = {
285
- channel: "marimo-error",
286
- data: [
287
- {
288
- type: "exception",
289
- exception_type: primaryOutput.ename,
290
- msg: primaryOutput.evalue,
291
- raising_cell: null,
292
- traceback: normalizeTraceback(primaryOutput.traceback),
293
- },
294
- ],
295
- mimetype: "application/vnd.marimo+error",
296
- timestamp: DEFAULT_TIMESTAMP,
297
- };
298
- } else if (primaryOutput.type === "data") {
299
- const mimeType = Object.keys(primaryOutput.data)[0];
300
- const data = Object.values(primaryOutput.data)[0];
301
- runtimeState.output = {
302
- channel: "output",
303
- data: data as {},
304
- mimetype: mimeType as "application/json",
305
- timestamp: DEFAULT_TIMESTAMP,
306
- };
307
- }
308
- if (runtimeState.output && primaryOutput.code !== undefined) {
309
- runtimeState.output.code = primaryOutput.code;
310
- }
311
- }
312
-
313
279
  const consoleOutputs = sessionCell.console || [];
314
280
 
315
281
  return {
316
282
  ...runtimeState,
317
- outline: runtimeState.output ? parseOutline(runtimeState.output) : null,
318
283
  consoleOutputs: consoleOutputs.map((consoleOutput) => {
319
284
  // Handle StreamMediaOutput (type: "streamMedia")
320
285
  if (consoleOutput.type === "streamMedia") {
@@ -351,9 +316,9 @@ function createCellRuntimeFromSession(
351
316
  /**
352
317
  * Read the session and notebook a page embeds.
353
318
  *
354
- * The cells become a host snapshot the replica starts from, and the session's
355
- * outputs seed each cell's runtime until the kernel speaks. Null when the page
356
- * carries no cells.
319
+ * The cells become a host snapshot the replica starts from, with the
320
+ * session's outputs as its results. Its console output seeds each cell's
321
+ * runtime until the kernel speaks. Null when the page carries no cells.
357
322
  */
358
323
  export function readExport({
359
324
  session,
@@ -1,10 +1,10 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
+ import type { CellOutput } from "../executions";
3
4
  import type { OutputMessage } from "../kernel/messages";
4
5
  import type { CellConfig } from "../network/types";
5
6
  import type { CellId } from "./ids";
6
7
  import { DEFAULT_CELL_NAME } from "./names";
7
- import type { Outline } from "./outline";
8
8
 
9
9
  /**
10
10
  * Create a new cell with default state.
@@ -42,8 +42,6 @@ export function createCellRuntimeState(
42
42
  state?: Partial<CellRuntimeState>,
43
43
  ): CellRuntimeState {
44
44
  return {
45
- outline: null,
46
- output: null,
47
45
  consoleOutputs: [],
48
46
  debuggerActive: false,
49
47
  ...state,
@@ -70,10 +68,6 @@ export interface CellData {
70
68
  * TODO(MO-8407): Delete.
71
69
  */
72
70
  export interface CellRuntimeState {
73
- /** a message encoding the cell's output. TODO(MO-8404) */
74
- output: OutputMessage | null;
75
- /** TOC outline. TODO(MO-8404) */
76
- outline: Outline | null;
77
71
  /** messages encoding the cell's console outputs. TODO(MO-8405) */
78
72
  consoleOutputs: ConsoleOutputMessage[];
79
73
  /** debugger active */
@@ -82,7 +76,11 @@ export interface CellRuntimeState {
82
76
  serialization?: string | null;
83
77
  }
84
78
 
85
- export type RuntimeCell = CellRuntimeState & CellData;
79
+ /** A cell as the layout renderers take it, with what it shows from the host. */
80
+ export type RuntimeCell = CellData &
81
+ CellRuntimeState & {
82
+ output: CellOutput | null;
83
+ };
86
84
 
87
85
  export type WithResponse<T> = T & {
88
86
  /**
@@ -2,15 +2,16 @@
2
2
 
3
3
  import type { EditorView } from "@codemirror/view";
4
4
  import {
5
+ type CellError,
5
6
  type CellExecutionInputs,
6
7
  type CellExecutionView,
7
8
  type CellFreshness,
8
9
  type CellFreshnessLookup,
10
+ type CellOutput,
9
11
  cellExecutionView,
10
12
  } from "@/core/executions";
11
13
  import type { Executions } from "@/core/notebook/replica";
12
14
  import { Objects } from "@/utils/objects";
13
- import type { MarimoError, OutputMessage } from "../kernel/messages";
14
15
  import { isErrorMime } from "../mime";
15
16
  import type { NotebookState } from "./cells";
16
17
  import type { CellId } from "./ids";
@@ -231,7 +232,7 @@ export function shouldHidePublishedCell({
231
232
  errored: boolean;
232
233
  interrupted: boolean;
233
234
  stopped: boolean;
234
- output: OutputMessage | null;
235
+ output: CellOutput | null;
235
236
  showErrorTracebacks: boolean;
236
237
  }): boolean {
237
238
  const outputIsError = isErrorMime(output?.mimetype);
@@ -240,7 +241,7 @@ export function shouldHidePublishedCell({
240
241
  outputIsError &&
241
242
  Array.isArray(output?.data) &&
242
243
  output.data.some(
243
- (e: MarimoError) =>
244
+ (e: CellError) =>
244
245
  e.type === "exception" && "traceback" in e && e.traceback,
245
246
  );
246
247
  return (errored || interrupted || stopped || outputIsError) && !hasTraceback;
@@ -8,7 +8,6 @@ import { MockNotebook } from "@/__mocks__/notebook";
8
8
  import { getAIContextRegistry } from "@/core/ai/context/context";
9
9
  import { ErrorContextProvider } from "@/core/ai/context/providers/error";
10
10
  import { AIContextRegistry } from "@/core/ai/context/registry";
11
- import { notebookAtom } from "@/core/cells/cells";
12
11
  import { CellId } from "@/core/cells/ids";
13
12
  import { resourceExtension } from "../resources";
14
13
 
@@ -29,16 +28,13 @@ describe("resource tooltips", () => {
29
28
  beforeEach(() => {
30
29
  vi.clearAllMocks();
31
30
  const store = createStore();
32
- store.set(
33
- notebookAtom,
34
- MockNotebook.notebookStateWithErrors([
35
- {
36
- cellId: CellId.create(),
37
- cellName: "Cell 1",
38
- errorData: [MockNotebook.errors.exception(message)],
39
- },
40
- ]),
41
- );
31
+ MockNotebook.withErrors(store, [
32
+ {
33
+ cellId: CellId.create(),
34
+ cellName: "Cell 1",
35
+ error: { kind: "exception", name: "RuntimeError", message },
36
+ },
37
+ ]);
42
38
  provider = new ErrorContextProvider(store);
43
39
  resource = provider.getItems()[1];
44
40
  vi.mocked(getAIContextRegistry).mockReturnValue(
@@ -2,9 +2,15 @@
2
2
 
3
3
  import { createStore } from "jotai";
4
4
  import { describe, expect, it } from "vitest";
5
+ import { MockExecutions } from "@/__mocks__/executions";
5
6
  import { MockNotebook } from "@/__mocks__/notebook";
6
7
  import { cellId } from "@/__tests__/branded";
7
8
  import { notebookAtom } from "@/core/cells/cells";
9
+ import {
10
+ cell,
11
+ document as documentOf,
12
+ withCells,
13
+ } from "@/core/notebook/document/__tests__/fixtures";
8
14
  import {
9
15
  type CellErrorEntry,
10
16
  formatCellError,
@@ -32,33 +38,61 @@ describe("formatCellError", () => {
32
38
  });
33
39
 
34
40
  describe("getCellErrorEntries", () => {
35
- it("pairs an error with the source that raised it, not a later edit", () => {
41
+ it("pairs an error with the source that raised it, not a later draft", () => {
36
42
  const id = cellId("c1");
37
43
  const store = createStore();
38
44
  store.set(
39
45
  notebookAtom,
40
46
  MockNotebook.notebookState({
41
47
  cellData: { [id]: { code: "print('fixed')" } },
42
- cellRuntime: {
43
- [id]: {
44
- output: {
45
- channel: "marimo-error",
46
- mimetype: "application/vnd.marimo+error",
47
- data: [
48
- {
49
- type: "exception",
50
- exception_type: "ZeroDivisionError",
51
- msg: "division by zero",
52
- },
53
- ],
54
- timestamp: 0,
55
- code: "1 / 0",
56
- },
57
- },
58
- },
59
48
  }),
60
49
  );
50
+ MockExecutions.seed(
51
+ store,
52
+ [MockExecutions.failed(id, {}, { code_fingerprint: "ran" })],
53
+ null,
54
+ withCells(
55
+ documentOf(),
56
+ {
57
+ c1: null,
58
+ c2: null,
59
+ [id]: cell(id, "1 / 0", { code_fingerprint: "ran" }),
60
+ },
61
+ [id],
62
+ ),
63
+ );
61
64
 
62
65
  expect(getCellErrorEntries(store)[0]?.cellCode).toBe("1 / 0");
63
66
  });
67
+
68
+ it("falls back to the cell's current source once an edit is confirmed", () => {
69
+ const id = cellId("c1");
70
+ const store = createStore();
71
+ MockNotebook.withErrors(store, [
72
+ {
73
+ cellId: id,
74
+ cellName: "c1",
75
+ code: "1 / 0",
76
+ error: {
77
+ kind: "exception",
78
+ name: "ZeroDivisionError",
79
+ message: "division by zero",
80
+ },
81
+ },
82
+ ]);
83
+
84
+ expect(getCellErrorEntries(store)).toEqual([
85
+ expect.objectContaining({
86
+ cellId: id,
87
+ cellCode: "1 / 0",
88
+ errorData: [
89
+ expect.objectContaining({
90
+ type: "exception",
91
+ exception_type: "ZeroDivisionError",
92
+ msg: "division by zero",
93
+ }),
94
+ ],
95
+ }),
96
+ ]);
97
+ });
64
98
  });