@marimo-team/islands 0.25.3-dev460 → 0.25.3-dev461

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 (54) hide show
  1. package/dist/{ErrorBoundary-D2YXxE_x.js → ErrorBoundary-CgQcF2Y8.js} +1 -1
  2. package/dist/assets/__vite-browser-external-DxDOnHRB.js +1 -0
  3. package/dist/assets/{worker-DLJ9P24O.js → worker-D70Lo75A.js} +2 -2
  4. package/dist/{chat-ui-wWHUzOrx.js → chat-ui-Ci-OmyBN.js} +3 -3
  5. package/dist/{code-visibility-BPWgfZVa.js → code-visibility-Bfy5Xs7h.js} +2 -2
  6. package/dist/{common-_2RH91nQ.js → common-B1BHI8OU.js} +3 -3
  7. package/dist/{data-grid-overlay-editor-yh1wqygW.js → data-grid-overlay-editor-D1ZL_HM6.js} +1 -1
  8. package/dist/{error-entries-3nytC8-z.js → error-entries-DMWlemUn.js} +471 -447
  9. package/dist/{feedback-button-Ctc_u2JY.js → feedback-button-Dk6liQGD.js} +3 -3
  10. package/dist/{glide-data-editor-DJikF-sp.js → glide-data-editor-BITFrcq_.js} +3 -3
  11. package/dist/{globals-D8_0qvIC.js → globals-BT6bOWG8.js} +1 -1
  12. package/dist/{html-to-image-C3Nb90uM.js → html-to-image-CDlYnllr.js} +1 -1
  13. package/dist/main.js +8527 -8499
  14. package/dist/{number-overlay-editor-BUXorcPD.js → number-overlay-editor-BoH3EMeN.js} +1 -1
  15. package/dist/{process-output-BiLaCBoX.js → process-output-89n_C_pU.js} +2 -2
  16. package/dist/{reveal-component-B54ZJYk8.js → reveal-component-DTAvChaV.js} +2 -2
  17. package/package.json +1 -1
  18. package/src/__mocks__/executions.ts +61 -30
  19. package/src/components/editor/__tests__/output-persistence.test.tsx +1 -1
  20. package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +5 -1
  21. package/src/components/editor/renderers/grid-layout/grid-layout.tsx +1 -1
  22. package/src/core/cells/__tests__/clear-outputs.test.ts +18 -19
  23. package/src/core/cells/__tests__/harness.ts +4 -1
  24. package/src/core/cells/__tests__/layout.test.ts +4 -1
  25. package/src/core/cells/__tests__/runs.test.ts +2 -2
  26. package/src/core/cells/__tests__/session.test.ts +52 -45
  27. package/src/core/cells/__tests__/utils.test.ts +3 -3
  28. package/src/core/cells/execution-console.ts +7 -2
  29. package/src/core/cells/runs.ts +1 -1
  30. package/src/core/cells/session.ts +28 -18
  31. package/src/core/executions/__tests__/freshness.test.ts +11 -9
  32. package/src/core/executions/__tests__/hooks.test.tsx +8 -9
  33. package/src/core/executions/__tests__/output-lifecycle.test.ts +34 -35
  34. package/src/core/executions/__tests__/output.test.ts +28 -53
  35. package/src/core/executions/__tests__/select.test.ts +7 -7
  36. package/src/core/executions/atoms.ts +5 -5
  37. package/src/core/executions/output.ts +25 -28
  38. package/src/core/executions/select.ts +3 -11
  39. package/src/core/export/__tests__/hooks.test.ts +7 -9
  40. package/src/core/notebook/replica/__tests__/replica.test.ts +3 -3
  41. package/src/core/notebook/replica/__tests__/results.test.ts +2 -2
  42. package/src/core/notebook/replica/execution-state.ts +20 -12
  43. package/src/core/notebook/replica/index.ts +2 -1
  44. package/src/core/notebook/replica/replica.ts +25 -5
  45. package/src/core/notebook/replica/resources/executions.ts +41 -17
  46. package/src/core/notebook/replica/resources/results.ts +11 -9
  47. package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +5 -9
  48. package/src/core/static/virtual-file-tracker.ts +5 -8
  49. package/src/core/transports/__tests__/server.test.ts +1 -1
  50. package/src/core/transports/__tests__/static.test.ts +17 -10
  51. package/src/core/transports/static.ts +14 -6
  52. package/src/stories/cell.stories.tsx +14 -14
  53. package/src/stories/layout/vertical/one-column.stories.tsx +2 -1
  54. package/dist/assets/__vite-browser-external-D2z_TiUO.js +0 -1
@@ -13,7 +13,7 @@ import type * as Protocol from "@marimo-team/client/protocol";
13
13
  import type { CellId } from "@/core/cells/ids";
14
14
  import type { MarimoError, OutputMessage } from "@/core/kernel/messages";
15
15
  import type { Executions, Result, Results } from "@/core/notebook/replica";
16
- import { completedAt, shownOutcome, startedAt } from "@/core/notebook/replica";
16
+ import { completedAt, shown, startedAt } from "@/core/notebook/replica";
17
17
 
18
18
  /** A host error shown as its message and the cells involved. */
19
19
  export interface HostDiagnostic {
@@ -200,34 +200,33 @@ export function executionSource(
200
200
  }
201
201
 
202
202
  /**
203
- * What an execution's outcome shows, or null for an empty value, with the
204
- * source it ran when `cells` still holds it.
203
+ * What a result shows, or null for an empty output, with the source it ran
204
+ * when `cells` still holds it.
205
205
  */
206
- export function outcomeOutput(
207
- record: Protocol.Execution,
206
+ export function resultOutput(
207
+ result: Result,
208
208
  cells: ReadonlyMap<Protocol.CellId, Protocol.Cell> = NO_CELLS,
209
209
  ): CellOutput | null {
210
- const output = outcomeDisplay(record);
211
- const code = executionSource(record, cells);
210
+ const output = resultDisplay(result);
211
+ const code = executionSource(result.record, cells);
212
212
  return output === null || code === undefined ? output : { ...output, code };
213
213
  }
214
214
 
215
- function outcomeDisplay(record: Protocol.Execution): CellOutput | null {
216
- const outcome = shownOutcome(record);
217
- if (outcome === null) {
215
+ function resultDisplay(result: Result): CellOutput | null {
216
+ const { record } = result;
217
+ const showing = shown(result);
218
+ if (showing === null) {
218
219
  return null;
219
220
  }
220
- switch (outcome.kind) {
221
- case "value":
222
- return outcome.display === null
223
- ? null
224
- : valueOutput(record, outcome.display);
221
+ switch (showing.kind) {
222
+ case "output":
223
+ return showing.media === null ? null : valueOutput(record, showing.media);
225
224
  case "error":
226
- return errorOutput(record, [cellError(outcome.error)]);
225
+ return errorOutput(record, [cellError(showing.error)]);
227
226
  case "interrupted":
228
227
  return errorOutput(record, [{ type: "interruption" }]);
229
228
  case "skipped":
230
- return skippedOutput(record, outcome);
229
+ return skippedOutput(record, showing);
231
230
  }
232
231
  }
233
232
 
@@ -235,9 +234,9 @@ function outcomeDisplay(record: Protocol.Execution): CellOutput | null {
235
234
  * The execution whose outcome a cell shows: its running one once that has
236
235
  * shown something, else its result.
237
236
  *
238
- * A running execution's outcome is null until it shows something, so the
239
- * result stays up until then. Once it has shown, an empty display means
240
- * the cell cleared its output, and nothing shows. A result that says the
237
+ * A running execution has no output until it sets one, so the result stays
238
+ * up until then. Once it has, an empty output means the cell cleared it,
239
+ * and nothing shows. A result that says the
241
240
  * cell did not run comes down as soon as it does run.
242
241
  */
243
242
  export function shownExecution(
@@ -251,7 +250,7 @@ export function shownExecution(
251
250
  : inputs.executions.executions.get(latestId);
252
251
  if (
253
252
  latest !== undefined &&
254
- shownOutcome(latest.record) !== null &&
253
+ shown(latest) !== null &&
255
254
  latest.record.state.status !== "completed"
256
255
  ) {
257
256
  return latest;
@@ -260,7 +259,7 @@ export function shownExecution(
260
259
  if (
261
260
  latest?.record.state.status === "running" &&
262
261
  result !== null &&
263
- shownOutcome(result.record)?.kind === "skipped"
262
+ shown(result)?.kind === "skipped"
264
263
  ) {
265
264
  return null;
266
265
  }
@@ -288,11 +287,11 @@ export function cellOutputView(
288
287
  inputs: CellOutputInputs,
289
288
  id: Protocol.CellId,
290
289
  ): CellOutput | null {
291
- const shown = shownExecution(inputs, id);
292
- if (shown === null || stillCleared(inputs.cleared.get(id), shown)) {
290
+ const showing = shownExecution(inputs, id);
291
+ if (showing === null || stillCleared(inputs.cleared.get(id), showing)) {
293
292
  return null;
294
293
  }
295
- return outcomeOutput(shown.record, inputs.cells);
294
+ return resultOutput(showing, inputs.cells);
296
295
  }
297
296
 
298
297
  /**
@@ -322,7 +321,5 @@ export function cellOutputsView(
322
321
  * The latest scratch display, retained until a newer execution shows one.
323
322
  */
324
323
  export function scratchOutputView(executions: Executions): CellOutput | null {
325
- return executions.scratch === null
326
- ? null
327
- : outcomeOutput(executions.scratch.record);
324
+ return executions.scratch === null ? null : resultOutput(executions.scratch);
328
325
  }
@@ -5,17 +5,13 @@
5
5
  import type * as Protocol from "@marimo-team/client/protocol";
6
6
  import type { Execution, Executions, Results } from "@/core/notebook/replica";
7
7
  import { type Milliseconds, Time } from "@/utils/time";
8
- import {
9
- completedAt,
10
- shownOutcome,
11
- startedAt as startedAtOf,
12
- } from "@/core/notebook/replica";
8
+ import { completedAt, startedAt as startedAtOf } from "@/core/notebook/replica";
13
9
 
14
10
  /** Where a cell is in its run. */
15
11
  export type CellRunStatus = "idle" | "queued" | "running";
16
12
 
17
13
  /** How a cell's last completed execution ended. */
18
- export type CellOutcome = "value" | "error" | "interrupted" | "skipped";
14
+ export type CellOutcome = Protocol.Outcome["kind"];
19
15
 
20
16
  export interface CellExecutionView {
21
17
  readonly status: CellRunStatus;
@@ -59,11 +55,7 @@ export interface CellExecutionInputs {
59
55
  }
60
56
 
61
57
  export function outcomeOf(record: Protocol.Execution): CellOutcome | null {
62
- const outcome = shownOutcome(record);
63
- if (outcome === null) {
64
- return null;
65
- }
66
- return outcome.kind;
58
+ return record.state.status === "completed" ? record.state.outcome.kind : null;
67
59
  }
68
60
 
69
61
  function millis(iso: string | null): Milliseconds | null {
@@ -7,7 +7,7 @@ import type { ReactNode } from "react";
7
7
  import * as React from "react";
8
8
  import { beforeEach, describe, expect, it, vi } from "vitest";
9
9
  import { MockModules, Mocks } from "@/__mocks__/common";
10
- import { MockExecutions } from "@/__mocks__/executions";
10
+ import { type ExecutionEntries, MockExecutions } from "@/__mocks__/executions";
11
11
  import { cellId } from "@/__tests__/branded";
12
12
  import { CellOutputId } from "@/core/cells/ids";
13
13
  import type { CellOutput } from "@/core/executions";
@@ -46,23 +46,21 @@ describe("useEnrichCellOutputs", () => {
46
46
  React.createElement(Provider, { store }, children);
47
47
 
48
48
  /** Make the host report `records` as the cells' results. */
49
- const setCellsRuntime = (records: Protocol.Execution[]) => {
49
+ const setCellsRuntime = (records: ExecutionEntries) => {
50
50
  MockExecutions.seed(store, records);
51
51
  };
52
52
 
53
53
  /** A completed execution per cell that shows its `output`. */
54
54
  const createMockCellRuntimes = (
55
55
  cells: Record<string, { output: CellOutput | null }>,
56
- ): Protocol.Execution[] =>
56
+ ): Array<Protocol.Execution | Protocol.Output> =>
57
57
  Object.entries(cells).flatMap(([cellId, { output }]) =>
58
58
  output === null
59
59
  ? []
60
- : [
61
- MockExecutions.shown(cellId, {
62
- mimetype: output.mimetype,
63
- data: String(output.data),
64
- }),
65
- ],
60
+ : MockExecutions.shown(cellId, {
61
+ mimetype: output.mimetype,
62
+ data: String(output.data),
63
+ }),
66
64
  );
67
65
 
68
66
  it("should return empty object when no cells need screenshots", async () => {
@@ -193,7 +193,7 @@ describe("NotebookReplica lifetime", () => {
193
193
  expect(store.get(client.documentAtom)?.revision.notebook_id).toBe("n1");
194
194
  expect(store.get(client.notebookAtom)).toBeNull();
195
195
  const second = await opened();
196
- expect(second.cursor).toBe("97");
196
+ expect(second.cursor).toBe("98");
197
197
  second.receive({ event: "reset", data: {} });
198
198
  // What was on show stays until the snapshot that replaces it is ready.
199
199
  const replacement = fixtureMessages("notebook-events.sse").map((event) =>
@@ -306,10 +306,10 @@ describe("NotebookReplica lifetime", () => {
306
306
  connect(current.signal);
307
307
  const attempt = await opened();
308
308
  const snapshot = fixtureMessages("notebook-events.sse");
309
- snapshot.slice(0, -3).forEach(attempt.receive);
309
+ snapshot.slice(0, -4).forEach(attempt.receive);
310
310
  expect(store.get(client.documentAtom)).toBeNull();
311
311
  expect(store.get(client.runtimeAtom)).toBeNull();
312
- snapshot.slice(-3).forEach(attempt.receive);
312
+ snapshot.slice(-4).forEach(attempt.receive);
313
313
  expect(store.get(client.documentAtom)?.revision.order).toEqual([
314
314
  "c1",
315
315
  "c3",
@@ -44,7 +44,7 @@ const restored = {
44
44
  status: "completed",
45
45
  started_at: "2026-09-30T09:20:01Z",
46
46
  completed_at: "2026-09-30T09:20:02Z",
47
- outcome: { kind: "value", display: null },
47
+ outcome: { kind: "succeeded" },
48
48
  depends_on: {},
49
49
  },
50
50
  };
@@ -147,7 +147,7 @@ describe("retained results", () => {
147
147
  status: "completed",
148
148
  started_at: time,
149
149
  completed_at: time,
150
- outcome: { kind: "value", display: null },
150
+ outcome: { kind: "succeeded" },
151
151
  depends_on: {},
152
152
  },
153
153
  },
@@ -4,19 +4,27 @@
4
4
 
5
5
  import type * as Protocol from "@marimo-team/client/protocol";
6
6
 
7
- /** The final outcome once completed, or the value so far while running. */
8
- export function shownOutcome(
9
- record: Protocol.Execution,
10
- ): Protocol.Outcome | null {
11
- const state = record.state;
12
- switch (state.status) {
13
- case "queued":
14
- return null;
15
- case "running":
16
- return state.value;
17
- case "completed":
18
- return state.outcome;
7
+ /** What an execution shows in place of a cell's output. */
8
+ export type Shown =
9
+ | { readonly kind: "output"; readonly media: Protocol.DisplayData | null }
10
+ | Exclude<Protocol.Outcome, { kind: "succeeded" }>;
11
+
12
+ /**
13
+ * How an execution ended when it did not succeed, else its output. Null
14
+ * until a queued or running execution sets its output.
15
+ */
16
+ export function shown(result: {
17
+ readonly record: Protocol.Execution;
18
+ readonly output: Protocol.Output | null;
19
+ }): Shown | null {
20
+ const { state } = result.record;
21
+ if (state.status === "completed" && state.outcome.kind !== "succeeded") {
22
+ return state.outcome;
23
+ }
24
+ if (result.output !== null) {
25
+ return { kind: "output", media: result.output.media };
19
26
  }
27
+ return state.status === "completed" ? { kind: "output", media: null } : null;
20
28
  }
21
29
 
22
30
  export function startedAt(record: Protocol.Execution): string | null {
@@ -25,6 +25,7 @@ export type { Result, Results } from "./resources/results";
25
25
  export {
26
26
  completedAt,
27
27
  dependsOn,
28
- shownOutcome,
28
+ type Shown,
29
+ shown,
29
30
  startedAt,
30
31
  } from "./execution-state";
@@ -12,6 +12,7 @@ import {
12
12
  import type {
13
13
  Attachment,
14
14
  Execution as HostExecution,
15
+ Output as HostOutput,
15
16
  NotebookOutput,
16
17
  Runtime,
17
18
  } from "@marimo-team/client/protocol";
@@ -50,6 +51,7 @@ export const EDITOR_EVENT_TYPES = [
50
51
  "console",
51
52
  "display",
52
53
  "input",
54
+ "output",
53
55
  "variable",
54
56
  "marimo",
55
57
  ] as const;
@@ -121,12 +123,10 @@ export interface NotebookReplica {
121
123
  onNotification: (notification: unknown) => void;
122
124
  /** Observe an item for live logs and virtual files in an export. */
123
125
  onItem?: (record: HostExecution, item: Item, live: boolean) => void;
124
- /**
125
- * Export tracks file references from each execution as it arrives, including
126
- * restored results and updates to completed values. Execution history uses
127
- * `lifecycleChanged` to record restored executions and live status changes.
128
- */
126
+ /** Observe restored executions and live status changes for execution history. */
129
127
  onExecution?: (record: HostExecution, lifecycleChanged: boolean) => void;
128
+ /** Observe outputs as they arrive, including retained ones on reconnect. */
129
+ onOutput?: (output: HostOutput, execution: HostExecution) => void;
130
130
  },
131
131
  ): () => void;
132
132
  /** Restore the current connection after its stream closed, if the host is healthy. */
@@ -291,6 +291,7 @@ export function createNotebookReplica(
291
291
  onNotification,
292
292
  onExecution,
293
293
  onItem,
294
+ onOutput,
294
295
  }: Parameters<NotebookReplica["connect"]>[1],
295
296
  ) {
296
297
  current?.end();
@@ -359,6 +360,14 @@ export function createNotebookReplica(
359
360
  }
360
361
  }
361
362
 
363
+ function observeOutput(output: HostOutput, record: HostExecution) {
364
+ try {
365
+ onOutput?.(output, record);
366
+ } catch (error) {
367
+ Logger.error("Failed to handle output update", error);
368
+ }
369
+ }
370
+
362
371
  function apply(source: NotebookEvents<string>, event: EditorEvent) {
363
372
  if (event.event === "marimo") {
364
373
  const message = MarimoMessage.safeParse(event.data);
@@ -398,6 +407,9 @@ export function createNotebookReplica(
398
407
  if (event.event === "ready" && before.phase === "snapshot") {
399
408
  for (const execution of after.resources.executions.executions.values()) {
400
409
  observeExecution(execution.record, true);
410
+ if (execution.output) {
411
+ observeOutput(execution.output, execution.record);
412
+ }
401
413
  if (onItem) {
402
414
  for (const item of execution.items.values()) {
403
415
  if (item.kind === "display") {
@@ -433,6 +445,14 @@ export function createNotebookReplica(
433
445
  observeExecution(record, changed);
434
446
  return;
435
447
  }
448
+ case "output": {
449
+ const { output } = event.data;
450
+ const execution = executions.get(output.execution_id);
451
+ if (execution) {
452
+ observeOutput(output, execution.record);
453
+ }
454
+ return;
455
+ }
436
456
  case "console":
437
457
  case "display":
438
458
  case "input": {
@@ -8,7 +8,7 @@ import {
8
8
  retainResult,
9
9
  retainScratchResult,
10
10
  } from "./results";
11
- import { shownOutcome, startedAt } from "../execution-state";
11
+ import { shown, startedAt } from "../execution-state";
12
12
 
13
13
  /** A console line, display, or input an execution produced, tagged by kind. */
14
14
  type ProducedItem =
@@ -52,6 +52,7 @@ type Kind =
52
52
  | "cell"
53
53
  | "run"
54
54
  | "execution"
55
+ | "output"
55
56
  | "console"
56
57
  | "display"
57
58
  | "input"
@@ -183,9 +184,20 @@ function unbind(state: Executions, itemId: Protocol.ItemId): Executions {
183
184
  return state;
184
185
  }
185
186
 
186
- function sameOutcome(a: Protocol.Execution, b: Protocol.Execution): boolean {
187
- const [x, y] = [shownOutcome(a), shownOutcome(b)];
188
- return x === y || JSON.stringify(x) === JSON.stringify(y);
187
+ function sameShown(
188
+ a: Pick<Result, "record" | "output">,
189
+ b: Pick<Result, "record" | "output">,
190
+ ): boolean {
191
+ return JSON.stringify(shown(a)) === JSON.stringify(shown(b));
192
+ }
193
+
194
+ /** Replace an execution and keep its retained copies in step. */
195
+ function update(state: Executions, execution: Execution): Executions {
196
+ return {
197
+ ...set(state, execution),
198
+ results: retainResult(state.results, execution),
199
+ scratch: retainScratchResult(state.scratch, execution),
200
+ };
189
201
  }
190
202
 
191
203
  /** Carry displayed results and their revisions through a replacement snapshot. */
@@ -207,8 +219,7 @@ export function resumeResults(
207
219
  resumed.set(id, {
208
220
  ...execution,
209
221
  outputVersion:
210
- before.outputVersion +
211
- (sameOutcome(before.record, execution.record) ? 0 : 1),
222
+ before.outputVersion + (sameShown(before, execution) ? 0 : 1),
212
223
  });
213
224
  }
214
225
  }
@@ -220,7 +231,11 @@ export function resumeResults(
220
231
  cellId,
221
232
  execution === undefined
222
233
  ? (previous.results.get(cellId) ?? null)
223
- : { record: execution.record, outputVersion: execution.outputVersion },
234
+ : {
235
+ record: execution.record,
236
+ output: execution.output,
237
+ outputVersion: execution.outputVersion,
238
+ },
224
239
  );
225
240
  }
226
241
  const scratch =
@@ -269,25 +284,34 @@ export const executions: NotebookResource<Executions, Kind> = {
269
284
  : state,
270
285
  execution: (state, { data: { execution: record } }) => {
271
286
  const previous = state.executions.get(record.id);
272
- const execution: Execution = {
273
- record,
287
+ const next = { record, output: previous?.output ?? null };
288
+ return update(state, {
289
+ ...next,
274
290
  outputVersion:
275
291
  previous === undefined
276
292
  ? 0
277
- : previous.outputVersion +
278
- (sameOutcome(previous.record, record) ? 0 : 1),
293
+ : previous.outputVersion + (sameShown(previous, next) ? 0 : 1),
279
294
  append: previous?.append,
280
295
  lastSeq: previous?.lastSeq,
281
296
  items: previous?.items ?? new Map(),
282
297
  variables: previous?.variables ?? new Map(),
283
- };
284
- return {
285
- ...set(state, execution),
286
- results: retainResult(state.results, execution),
287
- scratch: retainScratchResult(state.scratch, execution),
288
- };
298
+ });
289
299
  },
290
300
  "execution.removed": (state, { data }) => remove(state, data.id),
301
+ output: (state, { data: { output } }) => {
302
+ const execution = state.executions.get(output.execution_id);
303
+ if (execution === undefined) {
304
+ return state;
305
+ }
306
+ const next = { ...execution, output };
307
+ return update(state, {
308
+ ...next,
309
+ outputVersion:
310
+ execution.outputVersion + (sameShown(execution, next) ? 0 : 1),
311
+ });
312
+ },
313
+ // The output leaves with its execution, and a retained result keeps its copy.
314
+ "output.removed": (state) => state,
291
315
  console: (state, { data }) =>
292
316
  attach(state, { ...data.console, kind: "console", time: data.time }),
293
317
  "console.removed": (state, { data }) => detach(state, data.id),
@@ -1,11 +1,13 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
3
  import type * as Protocol from "@marimo-team/client/protocol";
4
- import { completedAt, shownOutcome, startedAt } from "../execution-state";
4
+ import { completedAt, shown, startedAt } from "../execution-state";
5
5
 
6
- /** An execution record paired with the local revision of its outcome. */
6
+ /** An execution record and its output, with the local revision of what it shows. */
7
7
  export interface Result {
8
8
  readonly record: Protocol.Execution;
9
+ /** The execution's output item, null until it sets one. */
10
+ readonly output: Protocol.Output | null;
9
11
  /** Unchanged by lifecycle-only events. */
10
12
  readonly outputVersion: number;
11
13
  }
@@ -16,8 +18,8 @@ export interface Result {
16
18
  * The host removes a cell's previous execution before it publishes the
17
19
  * next one. A result stays until a newer execution for the cell completes
18
20
  * or the cell leaves the document, so a cell can show its last outcome
19
- * while it runs again. The record and its output revision are kept; the
20
- * items and variables stay with the stream's copy of the execution.
21
+ * while it runs again. The record, its output, and the output revision are
22
+ * kept; the items and variables stay with the stream's copy of the execution.
21
23
  *
22
24
  * A cell has an entry from its `cell` event until its removal, null until
23
25
  * it completes once. Cells precede their executions on the stream, so a
@@ -30,7 +32,7 @@ export interface Result {
30
32
  export type Results = ReadonlyMap<Protocol.CellId, Result | null>;
31
33
 
32
34
  export function retainResult(state: Results, result: Result): Results {
33
- const { record, outputVersion } = result;
35
+ const { record, output, outputVersion } = result;
34
36
  const cellId = record.cell_id;
35
37
  if (
36
38
  cellId === null ||
@@ -41,7 +43,7 @@ export function retainResult(state: Results, result: Result): Results {
41
43
  ) {
42
44
  return state;
43
45
  }
44
- return new Map(state).set(cellId, { record, outputVersion });
46
+ return new Map(state).set(cellId, { record, output, outputVersion });
45
47
  }
46
48
 
47
49
  /** Keep just the latest scratch display, independently of execution history. */
@@ -49,8 +51,8 @@ export function retainScratchResult(
49
51
  previous: Result | null,
50
52
  result: Result,
51
53
  ): Result | null {
52
- const { record, outputVersion } = result;
53
- if (record.cell_id !== null || shownOutcome(record) === null) {
54
+ const { record, output, outputVersion } = result;
55
+ if (record.cell_id !== null || shown(result) === null) {
54
56
  return previous;
55
57
  }
56
58
  const time = (execution: Protocol.Execution) =>
@@ -60,5 +62,5 @@ export function retainScratchResult(
60
62
  if (previous !== null && time(previous.record) > time(record)) {
61
63
  return previous;
62
64
  }
63
- return { record, outputVersion };
65
+ return { record, output, outputVersion };
64
66
  }
@@ -490,7 +490,7 @@ it.each(["", "latest"])(
490
490
  ...MockExecutions.execution(null, {
491
491
  status: "completed",
492
492
  depends_on: {},
493
- outcome: { kind: "value", display: null },
493
+ outcome: { kind: "succeeded" },
494
494
  started_at: "2026-10-01T09:21:01Z",
495
495
  completed_at: "2026-10-01T09:21:02Z",
496
496
  }),
@@ -505,7 +505,6 @@ it.each(["", "latest"])(
505
505
  state: {
506
506
  status: "running",
507
507
  started_at: "2026-10-01T09:21:01Z",
508
- value: null,
509
508
  },
510
509
  },
511
510
  },
@@ -1044,7 +1043,7 @@ it("clears the private debugger prompt and transcript when editing moves to anot
1044
1043
  expect(store.get(pendingPdbInputAtom)).toBeNull();
1045
1044
  });
1046
1045
 
1047
- it("collects exported files from execution values and public callback media", async () => {
1046
+ it("collects exported files from execution outputs and public callback media", async () => {
1048
1047
  const store = createStore();
1049
1048
  const fake = withTransport();
1050
1049
  vi.mocked(useRuntimeManager).mockReturnValue(makeRuntimeManager());
@@ -1058,16 +1057,13 @@ it("collects exported files from execution values and public callback media", as
1058
1057
  const callbackFile = "/@file/callback-image.png";
1059
1058
  const previousFile = "/@file/previous-callback.png";
1060
1059
  const debuggerFile = "/@file/debugger-image.png";
1061
- const record = MockExecutions.shown(id, {
1060
+ const [execution, output] = MockExecutions.shown(id, {
1062
1061
  mimetype: "text/html",
1063
1062
  data: `<img src="${file}">`,
1064
1063
  });
1065
1064
  act(() => {
1066
- conn.receive({
1067
- event: "execution",
1068
- id: "updated",
1069
- data: { execution: record },
1070
- });
1065
+ conn.receive({ event: "execution", id: "planned", data: { execution } });
1066
+ conn.receive({ event: "output", id: "updated", data: { output } });
1071
1067
  const media = (path: string) => ({
1072
1068
  channel: "media",
1073
1069
  mimetype: "text/html",
@@ -1,12 +1,11 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
- import type { Execution } from "@marimo-team/client/protocol";
3
+ import type { Execution, Output } from "@marimo-team/client/protocol";
4
4
  import { type CellId, SCRATCH_CELL_ID } from "../cells/ids";
5
5
  import type {
6
6
  OutputMessage,
7
7
  NotificationMessageData,
8
8
  } from "../kernel/messages";
9
- import { shownOutcome } from "@/core/notebook/replica";
10
9
 
11
10
  // Virtual files are of the form /@file/<file-name>.<extension>
12
11
  const VIRTUAL_FILE_REGEX = /\/@file\/([^\s"&'/]+)\.([\dA-Za-z]+)/g;
@@ -37,13 +36,11 @@ export class VirtualFileTracker {
37
36
  this.trackValue(message.cell_id, message.output);
38
37
  }
39
38
 
40
- public trackExecution(record: Execution): void {
41
- const outcome = shownOutcome(record);
42
- const value = outcome?.kind === "value" ? outcome.display : null;
43
- if (value) {
39
+ public trackOutput(output: Output, execution: Execution): void {
40
+ if (output.media) {
44
41
  this.trackValue(
45
- (record.cell_id as CellId | null) ?? SCRATCH_CELL_ID,
46
- value,
42
+ (execution.cell_id as CellId | null) ?? SCRATCH_CELL_ID,
43
+ output.media,
47
44
  );
48
45
  }
49
46
  }
@@ -381,7 +381,7 @@ describe.each(["websocket", "sse"] as const)(
381
381
  first.drop();
382
382
  await vi.advanceTimersByTimeAsync(2000);
383
383
  const second = await connection.opened();
384
- expect(second.cursor).toBe("97");
384
+ expect(second.cursor).toBe("98");
385
385
  expect(store.get(client.documentAtom)).toBe(document);
386
386
  second.receive({ event: "ready", id: "100", data: {} });
387
387
  await vi.waitFor(() =>