@marimo-team/islands 0.26.1-dev48 → 0.26.1-dev50
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-uU7o1PeJ.js → ErrorBoundary-BdYsPski.js} +1 -1
- package/dist/{chat-ui-6qTQeEIx.js → chat-ui-D1mRz9h6.js} +3 -3
- package/dist/{code-visibility-C18rxvVq.js → code-visibility-X1_4FgQX.js} +2 -2
- package/dist/{common-B8iC72ed.js → common-DDvXjhVg.js} +3 -3
- package/dist/{data-grid-overlay-editor-BvBZ8bVF.js → data-grid-overlay-editor-YyEjFilq.js} +1 -1
- package/dist/{error-entries-8CPw0aYH.js → error-entries-P6Qpq6wP.js} +802 -752
- package/dist/{feedback-button-CARoMOjw.js → feedback-button-Bn9KZxUy.js} +3 -3
- package/dist/{glide-data-editor-Bk1B4gCx.js → glide-data-editor-Ga_xcJhU.js} +3 -3
- package/dist/{globals-DZHyDz_N.js → globals-woEyLnQv.js} +1 -1
- package/dist/{html-to-image-BIom70fW.js → html-to-image-DhrFZL7t.js} +1 -1
- package/dist/main.js +12 -12
- package/dist/{number-overlay-editor-D3SvrEmR.js → number-overlay-editor-7ECMDqhI.js} +1 -1
- package/dist/{process-output-ns7N5ovS.js → process-output-CBPqVQBu.js} +2 -2
- package/dist/{reveal-component-CFMbs41f.js → reveal-component-9s1jkku0.js} +2 -2
- package/package.json +1 -1
- package/src/__mocks__/executions.ts +1 -1
- package/src/core/executions/__tests__/output-lifecycle.test.ts +73 -2
- package/src/core/executions/select.ts +3 -3
- package/src/core/islands/bridge.ts +1 -1
- package/src/core/notebook/replica/__tests__/executions.test.ts +62 -0
- package/src/core/notebook/replica/__tests__/replica.test.ts +39 -0
- package/src/core/notebook/replica/__tests__/results.test.ts +1 -1
- package/src/core/notebook/replica/replica.ts +14 -2
- package/src/core/notebook/replica/resources/executions.ts +169 -57
- package/src/core/notebook/replica/resources/results.ts +6 -12
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
3
|
import type * as Protocol from "@marimo-team/client/protocol";
|
|
4
|
-
import type { NotebookResource } from "@marimo-team/client";
|
|
4
|
+
import type { HandlerContext, NotebookResource } from "@marimo-team/client";
|
|
5
5
|
import {
|
|
6
6
|
type Result,
|
|
7
7
|
type Results,
|
|
@@ -18,6 +18,8 @@ type ProducedItem =
|
|
|
18
18
|
/** Time the host published the item, when included in a live event. */
|
|
19
19
|
export type Item = ProducedItem & { readonly time?: string };
|
|
20
20
|
|
|
21
|
+
type ExecutionItem = Protocol.Output | Protocol.Variable | Item;
|
|
22
|
+
|
|
21
23
|
/** An execution on the stream, with the items it has produced. */
|
|
22
24
|
export interface Execution extends Result {
|
|
23
25
|
/** Items by id. `itemsInOrder` sorts them by `seq`. */
|
|
@@ -37,13 +39,18 @@ export interface Executions {
|
|
|
37
39
|
readonly runs: ReadonlyMap<Protocol.RunId, Protocol.RunOutput>;
|
|
38
40
|
/** Every execution on the stream, scratch included. */
|
|
39
41
|
readonly executions: ReadonlyMap<Protocol.ExecutionId, Execution>;
|
|
40
|
-
/** The execution
|
|
42
|
+
/** The unfinished execution for each cell, or its latest completed one. */
|
|
41
43
|
readonly latest: ReadonlyMap<Protocol.CellId, Protocol.ExecutionId>;
|
|
42
44
|
/** Bindings by defining cell and item id, shared across unrelated stream updates. */
|
|
43
45
|
readonly variables: ReadonlyMap<
|
|
44
46
|
Protocol.CellId,
|
|
45
47
|
ReadonlyMap<Protocol.ItemId, Protocol.Variable>
|
|
46
48
|
>;
|
|
49
|
+
/** Items received during snapshot or replay before their owning execution. */
|
|
50
|
+
readonly pendingItems?: ReadonlyMap<
|
|
51
|
+
Protocol.ExecutionId,
|
|
52
|
+
readonly ExecutionItem[]
|
|
53
|
+
>;
|
|
47
54
|
readonly results: Results;
|
|
48
55
|
readonly scratch: Result | null;
|
|
49
56
|
/** The latest scratch execution to start, including one that printed nothing. */
|
|
@@ -118,56 +125,60 @@ function retainScratchConsole(
|
|
|
118
125
|
: current;
|
|
119
126
|
}
|
|
120
127
|
|
|
121
|
-
/** Replace an execution
|
|
128
|
+
/** Replace an execution without changing which execution its cell is running. */
|
|
122
129
|
function set(state: Executions, execution: Execution): Executions {
|
|
123
|
-
const { id
|
|
130
|
+
const { id } = execution.record;
|
|
124
131
|
return {
|
|
125
132
|
...state,
|
|
126
133
|
executions: new Map(state.executions).set(id, execution),
|
|
127
134
|
scratchConsole: retainScratchConsole(state, execution),
|
|
128
|
-
latest:
|
|
129
|
-
cellId === null || state.latest.get(cellId) === id
|
|
130
|
-
? state.latest
|
|
131
|
-
: new Map(state.latest).set(cellId, id),
|
|
132
135
|
};
|
|
133
136
|
}
|
|
134
137
|
|
|
135
138
|
function remove(state: Executions, id: Protocol.ExecutionId): Executions {
|
|
136
139
|
const execution = state.executions.get(id);
|
|
137
140
|
if (execution === undefined) {
|
|
138
|
-
return state
|
|
141
|
+
return state.pendingItems?.has(id)
|
|
142
|
+
? { ...state, pendingItems: without(state.pendingItems, id) }
|
|
143
|
+
: state;
|
|
139
144
|
}
|
|
140
145
|
const cellId = execution.record.cell_id;
|
|
141
146
|
const isLatest = cellId !== null && state.latest.get(cellId) === id;
|
|
147
|
+
const executions = without(state.executions, id);
|
|
148
|
+
let latest = state.latest;
|
|
149
|
+
if (isLatest) {
|
|
150
|
+
const retained = state.results.get(cellId);
|
|
151
|
+
latest =
|
|
152
|
+
retained && executions.has(retained.record.id)
|
|
153
|
+
? new Map(latest).set(cellId, retained.record.id)
|
|
154
|
+
: without(latest, cellId);
|
|
155
|
+
}
|
|
142
156
|
return {
|
|
143
157
|
...state,
|
|
144
|
-
executions
|
|
158
|
+
executions,
|
|
159
|
+
latest,
|
|
145
160
|
variables: isLatest ? without(state.variables, cellId) : state.variables,
|
|
146
161
|
scratchConsole:
|
|
147
162
|
state.scratchConsole?.record.id === id ? undefined : state.scratchConsole,
|
|
148
|
-
latest: isLatest ? without(state.latest, cellId) : state.latest,
|
|
149
163
|
};
|
|
150
164
|
}
|
|
151
165
|
|
|
152
|
-
function
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
166
|
+
function withRows(execution: Execution, entries: readonly Item[]): Execution {
|
|
167
|
+
const items = new Map(execution.items);
|
|
168
|
+
let lastSeq = execution.lastSeq ?? -1;
|
|
169
|
+
let append: Execution["append"];
|
|
170
|
+
for (let item of entries) {
|
|
171
|
+
const original = items.get(item.id);
|
|
172
|
+
if (original) {
|
|
173
|
+
// An input keeps the position and time of its first prompt.
|
|
174
|
+
item = { ...item, time: original.time };
|
|
175
|
+
} else if (entries.length === 1 && item.seq > lastSeq) {
|
|
176
|
+
append = { before: new WeakRef(execution.items), item };
|
|
177
|
+
}
|
|
178
|
+
items.set(item.id, item);
|
|
179
|
+
lastSeq = Math.max(lastSeq, item.seq);
|
|
161
180
|
}
|
|
162
|
-
return
|
|
163
|
-
...execution,
|
|
164
|
-
append:
|
|
165
|
-
!original && item.seq > (execution.lastSeq ?? -1)
|
|
166
|
-
? { before: new WeakRef(execution.items), item }
|
|
167
|
-
: undefined,
|
|
168
|
-
lastSeq: Math.max(execution.lastSeq ?? -1, item.seq),
|
|
169
|
-
items: new Map(execution.items).set(item.id, item),
|
|
170
|
-
});
|
|
181
|
+
return { ...execution, append, lastSeq, items };
|
|
171
182
|
}
|
|
172
183
|
|
|
173
184
|
function detach(state: Executions, itemId: Protocol.ItemId): Executions {
|
|
@@ -180,12 +191,16 @@ function detach(state: Executions, itemId: Protocol.ItemId): Executions {
|
|
|
180
191
|
});
|
|
181
192
|
}
|
|
182
193
|
}
|
|
183
|
-
return state;
|
|
194
|
+
return removePendingItem(state, itemId);
|
|
184
195
|
}
|
|
185
196
|
|
|
186
|
-
function bind(
|
|
187
|
-
|
|
188
|
-
|
|
197
|
+
function bind(
|
|
198
|
+
state: Executions,
|
|
199
|
+
execution: Execution,
|
|
200
|
+
variable: Protocol.Variable,
|
|
201
|
+
): Executions {
|
|
202
|
+
const cellId = execution.record.cell_id;
|
|
203
|
+
if (cellId === null) {
|
|
189
204
|
return state;
|
|
190
205
|
}
|
|
191
206
|
const bindings = new Map(state.variables.get(cellId)).set(
|
|
@@ -210,6 +225,25 @@ function unbind(state: Executions, itemId: Protocol.ItemId): Executions {
|
|
|
210
225
|
return { ...state, variables };
|
|
211
226
|
}
|
|
212
227
|
}
|
|
228
|
+
return removePendingItem(state, itemId);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function removePendingItem(
|
|
232
|
+
state: Executions,
|
|
233
|
+
itemId: Protocol.ItemId,
|
|
234
|
+
): Executions {
|
|
235
|
+
for (const [id, items] of state.pendingItems ?? []) {
|
|
236
|
+
if (items.some((item) => item.id === itemId)) {
|
|
237
|
+
const remaining = items.filter((item) => item.id !== itemId);
|
|
238
|
+
const pendingItems = new Map(state.pendingItems);
|
|
239
|
+
if (remaining.length === 0) {
|
|
240
|
+
pendingItems.delete(id);
|
|
241
|
+
} else {
|
|
242
|
+
pendingItems.set(id, remaining);
|
|
243
|
+
}
|
|
244
|
+
return { ...state, pendingItems };
|
|
245
|
+
}
|
|
246
|
+
}
|
|
213
247
|
return state;
|
|
214
248
|
}
|
|
215
249
|
|
|
@@ -229,6 +263,37 @@ function update(state: Executions, execution: Execution): Executions {
|
|
|
229
263
|
};
|
|
230
264
|
}
|
|
231
265
|
|
|
266
|
+
function receiveItem(
|
|
267
|
+
state: Executions,
|
|
268
|
+
item: ExecutionItem,
|
|
269
|
+
phase: HandlerContext["phase"],
|
|
270
|
+
): Executions {
|
|
271
|
+
const id = item.execution_id;
|
|
272
|
+
const execution = state.executions.get(id);
|
|
273
|
+
if (execution === undefined) {
|
|
274
|
+
if (phase === "live") {
|
|
275
|
+
return state;
|
|
276
|
+
}
|
|
277
|
+
const items = state.pendingItems?.get(id) ?? [];
|
|
278
|
+
return {
|
|
279
|
+
...state,
|
|
280
|
+
pendingItems: new Map(state.pendingItems).set(id, [...items, item]),
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
if ("kind" in item) {
|
|
284
|
+
return set(state, withRows(execution, [item]));
|
|
285
|
+
}
|
|
286
|
+
if ("revision" in item) {
|
|
287
|
+
return bind(state, execution, item);
|
|
288
|
+
}
|
|
289
|
+
const next = { ...execution, output: item };
|
|
290
|
+
return update(state, {
|
|
291
|
+
...next,
|
|
292
|
+
outputVersion:
|
|
293
|
+
execution.outputVersion + (sameShown(execution, next) ? 0 : 1),
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
232
297
|
/** Carry displayed results and their revisions through a replacement snapshot. */
|
|
233
298
|
export function resumeResults(
|
|
234
299
|
next: Executions,
|
|
@@ -296,10 +361,20 @@ export const executions: NotebookResource<Executions, Kind> = {
|
|
|
296
361
|
scratch: null,
|
|
297
362
|
},
|
|
298
363
|
on: {
|
|
299
|
-
cell: (state, { data }) =>
|
|
300
|
-
state.results.has(
|
|
301
|
-
|
|
302
|
-
|
|
364
|
+
cell: (state, { data: { cell } }, { phase }) => {
|
|
365
|
+
if (state.results.has(cell.id)) {
|
|
366
|
+
return state;
|
|
367
|
+
}
|
|
368
|
+
let results: Results = new Map(state.results).set(cell.id, null);
|
|
369
|
+
if (phase !== "live" && state.latest.has(cell.id)) {
|
|
370
|
+
for (const execution of state.executions.values()) {
|
|
371
|
+
if (execution.record.cell_id === cell.id) {
|
|
372
|
+
results = retainResult(results, execution);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return { ...state, results };
|
|
377
|
+
},
|
|
303
378
|
"cell.removed": (state, { data }) => ({
|
|
304
379
|
...state,
|
|
305
380
|
results: without(state.results, data.id),
|
|
@@ -317,10 +392,10 @@ export const executions: NotebookResource<Executions, Kind> = {
|
|
|
317
392
|
state.runs.has(data.id)
|
|
318
393
|
? { ...state, runs: without(state.runs, data.id) }
|
|
319
394
|
: state,
|
|
320
|
-
execution: (state, { data: { execution: record } }) => {
|
|
395
|
+
execution: (state, { data: { execution: record } }, { phase }) => {
|
|
321
396
|
const previous = state.executions.get(record.id);
|
|
322
397
|
const next = { record, output: previous?.output ?? null };
|
|
323
|
-
|
|
398
|
+
const execution: Execution = {
|
|
324
399
|
...next,
|
|
325
400
|
outputVersion:
|
|
326
401
|
previous === undefined
|
|
@@ -329,27 +404,64 @@ export const executions: NotebookResource<Executions, Kind> = {
|
|
|
329
404
|
append: previous?.append,
|
|
330
405
|
lastSeq: previous?.lastSeq,
|
|
331
406
|
items: previous?.items ?? new Map(),
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
407
|
+
};
|
|
408
|
+
const items = state.pendingItems?.get(record.id);
|
|
409
|
+
// All buffered console rows and prompts appear in this single update.
|
|
410
|
+
const rows = items?.filter((item) => "kind" in item);
|
|
411
|
+
let updated = update(
|
|
412
|
+
state,
|
|
413
|
+
rows?.length ? withRows(execution, rows) : execution,
|
|
414
|
+
);
|
|
415
|
+
if (items && state.pendingItems) {
|
|
416
|
+
updated = {
|
|
417
|
+
...updated,
|
|
418
|
+
pendingItems: without(state.pendingItems, record.id),
|
|
419
|
+
};
|
|
420
|
+
for (const item of items) {
|
|
421
|
+
if (!("kind" in item)) {
|
|
422
|
+
updated = receiveItem(updated, item, phase);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
339
425
|
}
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
426
|
+
const cellId = record.cell_id;
|
|
427
|
+
if (cellId === null || previous !== undefined) {
|
|
428
|
+
return updated;
|
|
429
|
+
}
|
|
430
|
+
const latest = state.latest.get(cellId);
|
|
431
|
+
// A snapshot can deliver the completed predecessor after its successor.
|
|
432
|
+
if (
|
|
433
|
+
phase === "snapshot" &&
|
|
434
|
+
latest !== undefined &&
|
|
435
|
+
record.state.status === "completed" &&
|
|
436
|
+
state.executions.get(latest)?.record.state.status !== "completed"
|
|
437
|
+
) {
|
|
438
|
+
return updated;
|
|
439
|
+
}
|
|
440
|
+
return {
|
|
441
|
+
...updated,
|
|
442
|
+
latest: new Map(state.latest).set(cellId, record.id),
|
|
443
|
+
};
|
|
346
444
|
},
|
|
347
|
-
|
|
348
|
-
|
|
445
|
+
"execution.removed": (state, { data }) => remove(state, data.id),
|
|
446
|
+
output: (state, { data }, { phase }) =>
|
|
447
|
+
receiveItem(state, data.output, phase),
|
|
448
|
+
console: (state, { data }, { phase }) =>
|
|
449
|
+
receiveItem(
|
|
450
|
+
state,
|
|
451
|
+
{ ...data.console, kind: "console", time: data.time },
|
|
452
|
+
phase,
|
|
453
|
+
),
|
|
349
454
|
"console.removed": (state, { data }) => detach(state, data.id),
|
|
350
|
-
input: (state, { data }) =>
|
|
351
|
-
|
|
352
|
-
|
|
455
|
+
input: (state, { data }, { phase }) =>
|
|
456
|
+
receiveItem(
|
|
457
|
+
state,
|
|
458
|
+
{ ...data.input, kind: "input", time: data.time },
|
|
459
|
+
phase,
|
|
460
|
+
),
|
|
461
|
+
variable: (state, { data }, { phase }) =>
|
|
462
|
+
receiveItem(state, data.variable, phase),
|
|
353
463
|
"variable.removed": (state, { data }) => unbind(state, data.id),
|
|
464
|
+
ready: (state) =>
|
|
465
|
+
state.pendingItems ? { ...state, pendingItems: undefined } : state,
|
|
354
466
|
},
|
|
355
467
|
};
|
|
@@ -13,21 +13,15 @@ export interface Result {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* Each document cell's last completed execution
|
|
16
|
+
* Each document cell's last completed execution that was not superseded.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
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.
|
|
18
|
+
* A superseded attempt leaves the previous result visible while its replacement
|
|
19
|
+
* is queued or running. The result holds the record, its output, and the
|
|
20
|
+
* output revision. Other items stay with the stream's copy of the execution.
|
|
23
21
|
*
|
|
24
22
|
* A cell has an entry from its `cell` event until its removal, null until
|
|
25
|
-
* it
|
|
26
|
-
*
|
|
27
|
-
* no longer has.
|
|
28
|
-
*
|
|
29
|
-
* An execution the host skipped as superseded never ran, and a newer one
|
|
30
|
-
* for the same cell is on its way, so it does not replace the result.
|
|
23
|
+
* it has a result. If the cell arrives after its execution during catch-up,
|
|
24
|
+
* the replica fills its entry from the execution it has already received.
|
|
31
25
|
*/
|
|
32
26
|
export type Results = ReadonlyMap<Protocol.CellId, Result | null>;
|
|
33
27
|
|