@marimo-team/islands 0.25.3-dev173 → 0.25.3-dev175
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-wT3f3iJ1.js → ErrorBoundary-DNvcAIsP.js} +1 -1
- package/dist/{any-language-editor-B92WMzoC.js → any-language-editor-BVFHDDQ3.js} +2 -2
- package/dist/{chat-ui-CuORr6fL.js → chat-ui-X-cWrL9u.js} +1222 -1222
- package/dist/{code-visibility-ZReaeMaF.js → code-visibility-CH1lmM1h.js} +2 -2
- package/dist/{common-DCevHg1m.js → common-DIrS1UR9.js} +1074 -1078
- package/dist/{data-grid-overlay-editor-CTC-bJus.js → data-grid-overlay-editor-DFLZvFK0.js} +1 -1
- package/dist/{dist-F8Ep36rk.js → dist-B1M0bGO3.js} +1 -1
- package/dist/{dist-D6d86eNJ.js → dist-BA13RJj5.js} +1 -1
- package/dist/{dist-Bvs24R_E.js → dist-BJtmSgcE.js} +48 -48
- package/dist/{dist-CN_BeG2I.js → dist-Ba2VIn1K.js} +53 -53
- package/dist/{dist-PXYI_yuP.js → dist-Bj4bmwUm.js} +12 -12
- package/dist/{dist-DoE4XJBC.js → dist-BmS-ZGjl.js} +8626 -8626
- package/dist/{dist-BorMD-uX.js → dist-Bzogh7CW.js} +87 -87
- package/dist/{dist-CN8zI-XC.js → dist-CThPVKaP.js} +1385 -1382
- package/dist/{dist-DiDibOYr.js → dist-CTi5FTiV.js} +87 -87
- package/dist/{dist-diIx5qJW.js → dist-Ck_C32ye.js} +2 -2
- package/dist/{dist-BLfKmR-l.js → dist-D1fnFp1J.js} +1 -1
- package/dist/{dist-OR1OnN-y.js → dist-D3x9__Fu.js} +46 -46
- package/dist/{dist-BMQf5zIS.js → dist-D7mrh5sO.js} +36 -36
- package/dist/{dist-CSJ0MDRw.js → dist-D9Q3xjiP.js} +1 -1
- package/dist/{dist-BuaRHxOc.js → dist-DP60Ubh8.js} +2 -2
- package/dist/{dist-CSbh1PNP.js → dist-DTv9KkpW.js} +12 -12
- package/dist/{dist-D-wwqlzJ.js → dist-DVVwOfrD.js} +109 -109
- package/dist/{dist-C8fAKSH1.js → dist-DYXM73-k.js} +36 -36
- package/dist/{dist-DBtSl3sf.js → dist-DjeybPOb.js} +1 -1
- package/dist/{dist-CrSP_H1M.js → dist-DtGn9N4h.js} +197 -197
- package/dist/{dist-CLdpGQVr.js → dist-KN80qWCP.js} +2 -2
- package/dist/{dist-Cg7gzw-a.js → dist-O0qFpEJh.js} +56 -56
- package/dist/{dist-CkTTIdBe.js → dist-OUle2RT7.js} +207 -207
- package/dist/{dist-BK4Oj99o.js → dist-T5rh6JvL.js} +1 -1
- package/dist/{error-entries-CmWMEsY_.js → error-entries-mpoD5t79.js} +4939 -4983
- package/dist/{esm-D2gTsXEV.js → esm-Bbw_Njjx.js} +575 -575
- package/dist/{esm-AMFssoNp.js → esm-mDQNEFe_.js} +354 -354
- package/dist/{feedback-button-DwXkmewo.js → feedback-button-DL0DJ-LB.js} +21 -21
- package/dist/{glide-data-editor-BlmcP-lw.js → glide-data-editor-n4wnx19S.js} +3 -3
- package/dist/{globals-BdRitZ4p.js → globals-NCsYyjpB.js} +1 -1
- package/dist/{html-to-image-bpiQh7ND.js → html-to-image-BoZthB4P.js} +454 -445
- package/dist/main.js +3587 -3587
- package/dist/{number-overlay-editor-DQG-hFHT.js → number-overlay-editor-rlvo4mo3.js} +1 -1
- package/dist/{process-output-BzloOI7F.js → process-output-DLS4Mqg_.js} +2 -2
- package/dist/{reveal-component-D3r3vSTK.js → reveal-component-BJfmRUzb.js} +3 -3
- package/package.json +1 -1
- package/src/__mocks__/document.tsx +54 -0
- package/src/__mocks__/notebook.ts +2 -1
- package/src/__mocks__/requests.ts +0 -2
- package/src/components/chat/chat-panel.tsx +3 -3
- package/src/components/datasources/__tests__/column-preview.test.tsx +6 -8
- package/src/components/datasources/column-preview.tsx +4 -8
- package/src/components/datasources/datasources.tsx +4 -3
- package/src/components/dependency-graph/minimap-content.tsx +2 -6
- package/src/components/dependency-graph/panels.tsx +2 -1
- package/src/components/editor/__tests__/Output.test.tsx +50 -32
- package/src/components/editor/__tests__/data-attributes.test.tsx +22 -11
- package/src/components/editor/__tests__/output-persistence.test.tsx +6 -1
- package/src/components/editor/actions/__tests__/name-cell-input.test.tsx +69 -0
- package/src/components/editor/actions/name-cell-input.tsx +4 -3
- package/src/components/editor/actions/useCellActionButton.tsx +20 -26
- package/src/components/editor/actions/useNotebookActions.tsx +13 -18
- package/src/components/editor/actions/useSetCodeVisibility.ts +10 -11
- package/src/components/editor/actions/useSetOutputsExpanded.ts +13 -18
- package/src/components/editor/cell/CreateCellButton.tsx +5 -9
- package/src/components/editor/cell/__tests__/StagedAICell.test.tsx +3 -1
- package/src/components/editor/cell/code/cell-editor.tsx +13 -20
- package/src/components/editor/cell/useAddCell.ts +4 -8
- package/src/components/editor/cell/useDeleteCell.tsx +10 -36
- package/src/components/editor/cell/useRunCells.ts +2 -5
- package/src/components/editor/cell/useSplitCell.tsx +2 -1
- package/src/components/editor/chrome/panels/logs-panel.tsx +2 -1
- package/src/components/editor/chrome/panels/snippets-panel.tsx +5 -11
- package/src/components/editor/chrome/wrapper/__tests__/pending-ai-cells.test.tsx +3 -1
- package/src/components/editor/columns/sortable-column.tsx +1 -1
- package/src/components/editor/connections/components.tsx +4 -9
- package/src/components/editor/controls/Controls.tsx +1 -1
- package/src/components/editor/controls/__tests__/notebook-menu-dropdown.test.tsx +9 -3
- package/src/components/editor/documentation.css +34 -11
- package/src/components/editor/errors/auto-fix.tsx +4 -8
- package/src/components/editor/file-tree/file-explorer.tsx +3 -7
- package/src/components/editor/links/__tests__/cell-link.test.tsx +3 -1
- package/src/components/editor/links/cell-link.tsx +2 -1
- package/src/components/editor/navigation/__tests__/clipboard.test.ts +60 -38
- package/src/components/editor/navigation/__tests__/navigation.test.ts +73 -64
- package/src/components/editor/navigation/clipboard.ts +12 -11
- package/src/components/editor/navigation/multi-cell-action-toolbar.tsx +11 -20
- package/src/components/editor/navigation/navigation.ts +20 -28
- package/src/components/editor/notebook-cell.tsx +7 -10
- package/src/components/editor/output/console/__tests__/ConsoleOutput.test.tsx +125 -69
- package/src/components/editor/renderers/cell-array.tsx +10 -17
- package/src/components/markdown/markdown-renderer.tsx +4 -8
- package/src/components/pages/edit-page.tsx +32 -17
- package/src/components/scratchpad/scratchpad.test.tsx +3 -1
- package/src/components/scratchpad/scratchpad.tsx +4 -7
- package/src/components/slides/__tests__/minimap-actions.test.tsx +9 -25
- package/src/components/slides/minimap.tsx +7 -3
- package/src/components/slides/slide-cell-view.tsx +3 -3
- package/src/components/sort/SortableCellsProvider.tsx +2 -1
- package/src/core/ai/__tests__/staged-cells.test.ts +18 -20
- package/src/core/ai/staged-cells.ts +8 -16
- package/src/core/ai/tools/__tests__/edit-notebook-tool.test.ts +2 -2
- package/src/core/ai/tools/__tests__/run-cells-tool.test.ts +2 -2
- package/src/core/ai/tools/base.ts +2 -2
- package/src/core/ai/tools/edit-notebook-tool.ts +13 -21
- package/src/core/cells/__tests__/actions.test.ts +474 -34
- package/src/core/cells/__tests__/add-missing-import.test.ts +7 -8
- package/src/core/cells/__tests__/cells.test.ts +171 -813
- package/src/core/cells/__tests__/document.test.ts +5 -35
- package/src/core/cells/__tests__/notebook-outline.test.ts +7 -1
- package/src/core/cells/__tests__/outputs.test.tsx +71 -53
- package/src/core/cells/actions.ts +391 -3
- package/src/core/cells/add-missing-import.ts +46 -42
- package/src/core/cells/cells.ts +38 -413
- package/src/core/cells/document.ts +7 -4
- package/src/core/cells/outputs.ts +12 -28
- package/src/core/codemirror/cells/extensions.ts +6 -6
- package/src/core/codemirror/cells/state.ts +1 -1
- package/src/core/codemirror/keymaps/vim.ts +2 -2
- package/src/core/edit-app.tsx +19 -27
- package/src/core/islands/bridge.ts +0 -2
- package/src/core/kernel/handlers.ts +3 -3
- package/src/core/network/__tests__/requests-lazy.test.ts +1 -3
- package/src/core/network/requests-lazy.ts +0 -2
- package/src/core/network/requests-network.ts +0 -16
- package/src/core/network/requests-static.ts +0 -2
- package/src/core/network/requests-toasting.tsx +0 -2
- package/src/core/network/types.ts +0 -7
- package/src/core/notebook/document/__tests__/codemirror.test.ts +5 -0
- package/src/core/notebook/document/__tests__/draft.test.ts +41 -0
- package/src/core/notebook/document/__tests__/state.test.ts +21 -0
- package/src/core/notebook/document/draft.ts +35 -5
- package/src/core/notebook/document/index.ts +1 -0
- package/src/core/notebook/document/state.ts +6 -2
- package/src/core/session/useNotebookSession.tsx +6 -2
- package/src/core/wasm/bridge.ts +0 -16
- package/src/css/globals.css +56 -22
- package/src/stories/runtime-story.tsx +22 -15
|
@@ -21,7 +21,7 @@ const { stagedGenerationAtom, createActions, reducer, initialState } =
|
|
|
21
21
|
visibleForTesting;
|
|
22
22
|
|
|
23
23
|
// Mock the dependencies
|
|
24
|
-
const
|
|
24
|
+
const mockCreateCell = vi.fn();
|
|
25
25
|
const mockUpdateCellCode = vi.fn();
|
|
26
26
|
const mockDeleteCellCallback = vi.fn();
|
|
27
27
|
|
|
@@ -34,14 +34,16 @@ const mockCellHandle = {
|
|
|
34
34
|
},
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
vi.mock("../../cells/actions", () => ({
|
|
38
|
+
useCellActions: () => ({
|
|
39
|
+
createCell: mockCreateCell,
|
|
40
|
+
updateCellCode: mockUpdateCellCode,
|
|
41
|
+
}),
|
|
42
|
+
}));
|
|
37
43
|
vi.mock("../../cells/cells", async () => {
|
|
38
44
|
const { atom } = await import("jotai");
|
|
39
45
|
return {
|
|
40
46
|
notebookAtom: atom({ cellData: {}, cellIds: { inOrderIds: [] } }),
|
|
41
|
-
useCellActions: () => ({
|
|
42
|
-
createNewCell: mockCreateNewCell,
|
|
43
|
-
updateCellCode: mockUpdateCellCode,
|
|
44
|
-
}),
|
|
45
47
|
cellHandleAtom: vi.fn(() => ({
|
|
46
48
|
read: vi.fn(() => mockCellHandle),
|
|
47
49
|
})),
|
|
@@ -261,11 +263,9 @@ describe("staged-cells", () => {
|
|
|
261
263
|
const returnedCellId = result.current.createStagedCell(testCode);
|
|
262
264
|
|
|
263
265
|
expect(returnedCellId).toBe(mockCellId);
|
|
264
|
-
expect(
|
|
265
|
-
cellId: "__end__",
|
|
266
|
+
expect(mockCreateCell).toHaveBeenCalledWith({
|
|
266
267
|
code: testCode,
|
|
267
|
-
|
|
268
|
-
newCellId: mockCellId,
|
|
268
|
+
id: mockCellId,
|
|
269
269
|
});
|
|
270
270
|
});
|
|
271
271
|
|
|
@@ -330,7 +330,7 @@ describe("staged-cells", () => {
|
|
|
330
330
|
|
|
331
331
|
// Verify it was created and added
|
|
332
332
|
expect(createdCellId).toBe(mockCellId);
|
|
333
|
-
expect(
|
|
333
|
+
expect(mockCreateCell).toHaveBeenCalled();
|
|
334
334
|
|
|
335
335
|
let state = store.get(stagedAICellsAtom);
|
|
336
336
|
expect(state.has(mockCellId)).toBe(true);
|
|
@@ -401,7 +401,7 @@ describe("staged cell generation", () => {
|
|
|
401
401
|
result.current.beginStagedCellGeneration();
|
|
402
402
|
|
|
403
403
|
// No cell or cell update should have been called
|
|
404
|
-
expect(
|
|
404
|
+
expect(mockCreateCell).not.toHaveBeenCalled();
|
|
405
405
|
expect(prepareCellCodeUpdate).not.toHaveBeenCalled();
|
|
406
406
|
expect(store.get(stagedGenerationInProgressAtom)).toBe(true);
|
|
407
407
|
});
|
|
@@ -610,11 +610,9 @@ describe("staged cell generation", () => {
|
|
|
610
610
|
},
|
|
611
611
|
});
|
|
612
612
|
|
|
613
|
-
expect(
|
|
614
|
-
cellId: "__end__",
|
|
613
|
+
expect(mockCreateCell).toHaveBeenCalledWith({
|
|
615
614
|
code: "print('```')",
|
|
616
|
-
|
|
617
|
-
newCellId: "mock-cell-id",
|
|
615
|
+
id: "mock-cell-id",
|
|
618
616
|
});
|
|
619
617
|
});
|
|
620
618
|
|
|
@@ -636,16 +634,16 @@ describe("staged cell generation", () => {
|
|
|
636
634
|
},
|
|
637
635
|
});
|
|
638
636
|
|
|
639
|
-
expect(
|
|
637
|
+
expect(mockCreateCell).toHaveBeenCalledWith(
|
|
640
638
|
expect.objectContaining({
|
|
641
639
|
code: "value = 1",
|
|
642
|
-
|
|
640
|
+
id: "first-cell",
|
|
643
641
|
}),
|
|
644
642
|
);
|
|
645
|
-
expect(
|
|
643
|
+
expect(mockCreateCell).toHaveBeenCalledWith(
|
|
646
644
|
expect.objectContaining({
|
|
647
645
|
code: "value",
|
|
648
|
-
|
|
646
|
+
id: "second-cell",
|
|
649
647
|
}),
|
|
650
648
|
);
|
|
651
649
|
});
|
|
@@ -683,7 +681,7 @@ describe("staged cell generation", () => {
|
|
|
683
681
|
},
|
|
684
682
|
});
|
|
685
683
|
|
|
686
|
-
expect(
|
|
684
|
+
expect(mockCreateCell).toHaveBeenCalledTimes(2);
|
|
687
685
|
expect(store.get(stagedAICellsAtom).has(cellId("first-cell"))).toBe(true);
|
|
688
686
|
expect(store.get(stagedAICellsAtom).has(cellId("second-cell"))).toBe(true);
|
|
689
687
|
expect(prepareCellCodeUpdate).toHaveBeenCalledTimes(2);
|
|
@@ -14,11 +14,8 @@ import {
|
|
|
14
14
|
notebookCellsCompletionSchema,
|
|
15
15
|
} from "./completion-output";
|
|
16
16
|
import { maybeAddMarimoImport } from "../cells/add-missing-import";
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
getCellEditorView,
|
|
20
|
-
useCellActions,
|
|
21
|
-
} from "../cells/cells";
|
|
17
|
+
import { getCellEditorView } from "../cells/cells";
|
|
18
|
+
import { type CreateCell, useCellActions } from "../cells/actions";
|
|
22
19
|
import { prepareCellCodeUpdate } from "../codemirror/language/cell-code";
|
|
23
20
|
import type { JotaiStore } from "../state/jotai";
|
|
24
21
|
import type { EditType } from "./tools/edit-notebook-tool";
|
|
@@ -98,18 +95,13 @@ interface UpdateStagedCellAction {
|
|
|
98
95
|
/** Manage staged cells without assuming which AI workflow owns them. */
|
|
99
96
|
export function useStagedCells(store: JotaiStore) {
|
|
100
97
|
const { addStagedCell, removeStagedCell } = useStagedAICellsActions();
|
|
101
|
-
const {
|
|
98
|
+
const { updateCellCode, createCell } = useCellActions();
|
|
102
99
|
const deleteCellCallback = useDeleteCellCallback();
|
|
103
100
|
|
|
104
101
|
const createStagedCell = (code: string): CellId => {
|
|
105
102
|
const newCellId = CellId.create();
|
|
106
103
|
addStagedCell({ cellId: newCellId, edit: { type: "add_cell" } });
|
|
107
|
-
|
|
108
|
-
cellId: "__end__",
|
|
109
|
-
code,
|
|
110
|
-
before: false,
|
|
111
|
-
newCellId: newCellId,
|
|
112
|
-
});
|
|
104
|
+
createCell({ code, id: newCellId });
|
|
113
105
|
return newCellId;
|
|
114
106
|
};
|
|
115
107
|
|
|
@@ -152,7 +144,7 @@ export function useStagedCells(store: JotaiStore) {
|
|
|
152
144
|
/** Owns the lifecycle of cells created by one structured completion flow. */
|
|
153
145
|
export function useStagedCellGeneration(store: JotaiStore) {
|
|
154
146
|
const stagedCellActions = useStagedCells(store);
|
|
155
|
-
const {
|
|
147
|
+
const { createCell } = useCellActions();
|
|
156
148
|
const ownedGeneration = useRef<OwnedStagedGeneration | null>(null);
|
|
157
149
|
// Ownership lives in a ref, so subscribe to its backing atoms to rerender
|
|
158
150
|
// consumers when completion or per-cell acceptance changes.
|
|
@@ -180,7 +172,7 @@ export function useStagedCellGeneration(store: JotaiStore) {
|
|
|
180
172
|
status: "in_progress",
|
|
181
173
|
reconciler: new StagedCellReconciler({
|
|
182
174
|
...stagedCellActions,
|
|
183
|
-
|
|
175
|
+
createCell,
|
|
184
176
|
}),
|
|
185
177
|
};
|
|
186
178
|
store.set(stagedGenerationAtom, {
|
|
@@ -302,7 +294,7 @@ interface StagedCellReconcilerActions {
|
|
|
302
294
|
deleteStagedCell: (cellId: CellId) => void;
|
|
303
295
|
removeStagedCell: (cellId: CellId) => void;
|
|
304
296
|
addStagedCell: (payload: { cellId: CellId; edit: Edit }) => void;
|
|
305
|
-
|
|
297
|
+
createCell: CreateCell;
|
|
306
298
|
}
|
|
307
299
|
|
|
308
300
|
class StagedCellReconciler {
|
|
@@ -391,7 +383,7 @@ class StagedCellReconciler {
|
|
|
391
383
|
|
|
392
384
|
const cellId = maybeAddMarimoImport({
|
|
393
385
|
autoInstantiate: false,
|
|
394
|
-
|
|
386
|
+
createCell: this.actions.createCell,
|
|
395
387
|
fromCellId: this.createdCells[0]?.cellId,
|
|
396
388
|
before: true,
|
|
397
389
|
});
|
|
@@ -64,7 +64,7 @@ describe("EditNotebookTool", () => {
|
|
|
64
64
|
let cellId3: CellId;
|
|
65
65
|
let toolContext: {
|
|
66
66
|
addStagedCell: ReturnType<typeof vi.fn>;
|
|
67
|
-
|
|
67
|
+
createCell: ReturnType<typeof vi.fn>;
|
|
68
68
|
prepareForRun: ReturnType<typeof vi.fn>;
|
|
69
69
|
sendRun: ReturnType<typeof vi.fn>;
|
|
70
70
|
store: ReturnType<typeof getDefaultStore>;
|
|
@@ -81,7 +81,7 @@ describe("EditNotebookTool", () => {
|
|
|
81
81
|
const current = store.get(stagedAICellsAtom);
|
|
82
82
|
store.set(stagedAICellsAtom, new Map(current).set(cellId, edit));
|
|
83
83
|
}),
|
|
84
|
-
|
|
84
|
+
createCell: vi.fn(),
|
|
85
85
|
prepareForRun: vi.fn(),
|
|
86
86
|
sendRun: vi.fn().mockResolvedValue(null),
|
|
87
87
|
store,
|
|
@@ -29,7 +29,7 @@ describe("RunStaleCellsTool", () => {
|
|
|
29
29
|
let cellId3: CellId;
|
|
30
30
|
let toolContext: {
|
|
31
31
|
addStagedCell: ReturnType<typeof vi.fn>;
|
|
32
|
-
|
|
32
|
+
createCell: ReturnType<typeof vi.fn>;
|
|
33
33
|
prepareForRun: ReturnType<typeof vi.fn>;
|
|
34
34
|
sendRun: ReturnType<typeof vi.fn>;
|
|
35
35
|
store: ReturnType<typeof getDefaultStore>;
|
|
@@ -39,7 +39,7 @@ describe("RunStaleCellsTool", () => {
|
|
|
39
39
|
store = getDefaultStore();
|
|
40
40
|
toolContext = {
|
|
41
41
|
addStagedCell: vi.fn(),
|
|
42
|
-
|
|
42
|
+
createCell: vi.fn(),
|
|
43
43
|
prepareForRun: vi.fn(),
|
|
44
44
|
sendRun: vi.fn().mockResolvedValue(null),
|
|
45
45
|
store,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import type {
|
|
4
|
+
import type { CreateCell } from "@/core/cells/actions";
|
|
5
5
|
import type { CellId } from "@/core/cells/ids";
|
|
6
6
|
import type { ExecuteCellsRequest } from "@/core/network/types";
|
|
7
7
|
import type { JotaiStore } from "@/core/state/jotai";
|
|
@@ -113,7 +113,7 @@ export interface ToolDescription {
|
|
|
113
113
|
export interface ToolNotebookContext {
|
|
114
114
|
store: JotaiStore;
|
|
115
115
|
addStagedCell: (payload: { cellId: CellId; edit: Edit }) => void;
|
|
116
|
-
|
|
116
|
+
createCell: CreateCell;
|
|
117
117
|
prepareForRun: (payload: { cellId: CellId }) => void;
|
|
118
118
|
sendRun: (request: ExecuteCellsRequest) => Promise<null>;
|
|
119
119
|
}
|
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
import type { EditorView } from "@codemirror/view";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { scrollAndHighlightCell } from "@/components/editor/links/cell-link";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
type NotebookState,
|
|
9
|
-
notebookAtom,
|
|
10
|
-
} from "@/core/cells/cells";
|
|
6
|
+
import { type NotebookState, notebookAtom } from "@/core/cells/cells";
|
|
7
|
+
import type { CreateCellOptions } from "@/core/cells/actions";
|
|
11
8
|
import { CellId } from "@/core/cells/ids";
|
|
12
9
|
import { prepareCellCodeUpdate } from "@/core/codemirror/language/cell-code";
|
|
13
10
|
import type { CellColumnId } from "@/utils/id-tree";
|
|
@@ -86,7 +83,7 @@ export class EditNotebookTool implements AiTool<
|
|
|
86
83
|
{ edit }: EditNotebookInput,
|
|
87
84
|
toolContext: ToolNotebookContext,
|
|
88
85
|
): Promise<ToolOutputBase> => {
|
|
89
|
-
const { addStagedCell,
|
|
86
|
+
const { addStagedCell, createCell, store } = toolContext;
|
|
90
87
|
|
|
91
88
|
switch (edit.type) {
|
|
92
89
|
case "update_cell": {
|
|
@@ -155,8 +152,7 @@ export class EditNotebookTool implements AiTool<
|
|
|
155
152
|
case "add_cell": {
|
|
156
153
|
const { position, code } = edit;
|
|
157
154
|
|
|
158
|
-
let
|
|
159
|
-
let before = false;
|
|
155
|
+
let placement: CreateCellOptions = {};
|
|
160
156
|
const newCellId = CellId.create();
|
|
161
157
|
const notebook = store.get(notebookAtom);
|
|
162
158
|
|
|
@@ -186,11 +182,12 @@ export class EditNotebookTool implements AiTool<
|
|
|
186
182
|
}
|
|
187
183
|
|
|
188
184
|
this.validateCellIdExists(cellId, notebook);
|
|
189
|
-
|
|
190
|
-
|
|
185
|
+
placement = position.before
|
|
186
|
+
? { before: cellId }
|
|
187
|
+
: { after: cellId };
|
|
191
188
|
break;
|
|
192
189
|
}
|
|
193
|
-
case "column_end":
|
|
190
|
+
case "column_end":
|
|
194
191
|
if (!position.columnIndex) {
|
|
195
192
|
throw new ToolExecutionError(
|
|
196
193
|
"Column index is required for add_cell with column_end position",
|
|
@@ -203,21 +200,16 @@ export class EditNotebookTool implements AiTool<
|
|
|
203
200
|
);
|
|
204
201
|
}
|
|
205
202
|
|
|
206
|
-
|
|
207
|
-
|
|
203
|
+
placement = {
|
|
204
|
+
endOf: this.getColumnId(position.columnIndex, notebook),
|
|
205
|
+
};
|
|
208
206
|
break;
|
|
209
|
-
|
|
207
|
+
|
|
210
208
|
case "notebook_end":
|
|
211
|
-
// Use default: notebookPosition = "__end__"
|
|
212
209
|
break;
|
|
213
210
|
}
|
|
214
211
|
|
|
215
|
-
|
|
216
|
-
cellId: notebookPosition,
|
|
217
|
-
before,
|
|
218
|
-
code,
|
|
219
|
-
newCellId,
|
|
220
|
-
});
|
|
212
|
+
createCell({ ...placement, code, id: newCellId });
|
|
221
213
|
|
|
222
214
|
addStagedCell({
|
|
223
215
|
cellId: newCellId,
|