@datalayer/jupyter-react 2.0.2 → 2.0.3
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/lib/components/cell/Cell.js +1 -1
- package/lib/components/cell/Cell.js.map +1 -1
- package/lib/components/kernel/KernelActionMenu.d.ts +1 -0
- package/lib/components/kernel/KernelActionMenu.js +21 -8
- package/lib/components/kernel/KernelActionMenu.js.map +1 -1
- package/lib/components/notebook/Notebook.d.ts +8 -1
- package/lib/components/notebook/Notebook.js +2 -2
- package/lib/components/notebook/Notebook.js.map +1 -1
- package/lib/components/notebook/NotebookAdapter.d.ts +5 -8
- package/lib/components/notebook/NotebookAdapter.js +15 -32
- package/lib/components/notebook/NotebookAdapter.js.map +1 -1
- package/lib/components/notebook/NotebookBase.d.ts +8 -1
- package/lib/components/notebook/NotebookBase.js +25 -5
- package/lib/components/notebook/NotebookBase.js.map +1 -1
- package/lib/components/notebook/NotebookState.d.ts +1 -0
- package/lib/components/notebook/NotebookState.js +15 -2
- package/lib/components/notebook/NotebookState.js.map +1 -1
- package/lib/components/output/Output.js +102 -23
- package/lib/components/output/Output.js.map +1 -1
- package/lib/jupyter/ipywidgets/classic/manager.js +1 -11
- package/lib/jupyter/ipywidgets/classic/manager.js.map +1 -1
- package/lib/jupyter/ipywidgets/libembed.js +1 -0
- package/lib/jupyter/ipywidgets/libembed.js.map +1 -1
- package/lib/state/JupyterReactState.js +31 -8
- package/lib/state/JupyterReactState.js.map +1 -1
- package/lib/tools/__tests__/operationRunner.test.js +3 -3
- package/lib/tools/__tests__/operationRunner.test.js.map +1 -1
- package/lib/tools/core/index.d.ts +1 -1
- package/lib/tools/core/index.js +1 -1
- package/lib/tools/core/index.js.map +1 -1
- package/lib/tools/core/operationRunner.js +10 -1
- package/lib/tools/core/operationRunner.js.map +1 -1
- package/lib/tools/core/zodUtils.js +49 -5
- package/lib/tools/core/zodUtils.js.map +1 -1
- package/lib/tools/definitions/deleteCells.d.ts +7 -0
- package/lib/tools/definitions/{deleteCell.js → deleteCells.js} +7 -7
- package/lib/tools/definitions/deleteCells.js.map +1 -0
- package/lib/tools/definitions/index.d.ts +1 -1
- package/lib/tools/definitions/index.js +1 -1
- package/lib/tools/definitions/index.js.map +1 -1
- package/lib/tools/definitions/insertCell.js +2 -2
- package/lib/tools/definitions/insertCell.js.map +1 -1
- package/lib/tools/index.js +4 -4
- package/lib/tools/index.js.map +1 -1
- package/lib/tools/operations/deleteCells.d.ts +38 -0
- package/lib/tools/operations/deleteCells.js +65 -0
- package/lib/tools/operations/deleteCells.js.map +1 -0
- package/lib/tools/schemas/deleteCells.d.ts +21 -0
- package/lib/tools/schemas/deleteCells.js +25 -0
- package/lib/tools/schemas/deleteCells.js.map +1 -0
- package/lib/tools/schemas/index.d.ts +1 -1
- package/lib/tools/schemas/index.js +1 -1
- package/lib/tools/schemas/index.js.map +1 -1
- package/lib/tools/schemas/readCell.d.ts +2 -1
- package/lib/tools/schemas/readCell.js +2 -1
- package/lib/tools/schemas/readCell.js.map +1 -1
- package/lib/tools/schemas/updateCell.d.ts +2 -1
- package/lib/tools/schemas/updateCell.js +2 -1
- package/lib/tools/schemas/updateCell.js.map +1 -1
- package/package.json +2 -1
- package/lib/tools/definitions/deleteCell.d.ts +0 -7
- package/lib/tools/definitions/deleteCell.js.map +0 -1
- package/lib/tools/operations/deleteCell.d.ts +0 -49
- package/lib/tools/operations/deleteCell.js +0 -103
- package/lib/tools/operations/deleteCell.js.map +0 -1
- package/lib/tools/schemas/deleteCell.d.ts +0 -20
- package/lib/tools/schemas/deleteCell.js +0 -24
- package/lib/tools/schemas/deleteCell.js.map +0 -1
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2021-2023 Datalayer, Inc.
|
|
3
|
-
*
|
|
4
|
-
* MIT License
|
|
5
|
-
*/
|
|
6
|
-
import { readAllCellsOperation } from './readAllCells.js';
|
|
7
|
-
import { validateWithZod } from '../core/zodUtils.js';
|
|
8
|
-
import { deleteCellParamsSchema, } from '../schemas/deleteCell.js';
|
|
9
|
-
/**
|
|
10
|
-
* Deletes one or more cells from a notebook at the specified indices.
|
|
11
|
-
*
|
|
12
|
-
* Cells are deleted in reverse order (highest index first) to prevent
|
|
13
|
-
* index shifting issues during multi-cell deletion. This matches the
|
|
14
|
-
* behavior of the Jupyter MCP Server.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* // Delete single cell
|
|
19
|
-
* await deleteCellOperation.execute(
|
|
20
|
-
* { indices: [2] },
|
|
21
|
-
* { documentId: "file:///path/to/notebook.ipynb", executor }
|
|
22
|
-
* );
|
|
23
|
-
*
|
|
24
|
-
* // Delete multiple cells
|
|
25
|
-
* await deleteCellOperation.execute(
|
|
26
|
-
* { indices: [1, 3, 5] },
|
|
27
|
-
* { documentId: "file:///path/to/notebook.ipynb", executor }
|
|
28
|
-
* );
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export const deleteCellOperation = {
|
|
32
|
-
name: 'deleteCell',
|
|
33
|
-
async execute(params, context) {
|
|
34
|
-
// Validate params using Zod schema
|
|
35
|
-
const { indices } = validateWithZod(deleteCellParamsSchema, params, this.name);
|
|
36
|
-
const { documentId } = context;
|
|
37
|
-
if (!documentId) {
|
|
38
|
-
throw new Error('Document ID is required for deleteCell operation. ' +
|
|
39
|
-
'Ensure the tool execution context includes a valid documentId.');
|
|
40
|
-
}
|
|
41
|
-
// Ensure executor is available
|
|
42
|
-
if (!context.executor) {
|
|
43
|
-
throw new Error('Executor is required for deleteCell operation. ' +
|
|
44
|
-
'This should be provided by the platform (DefaultExecutor, BridgeExecutor, etc.)');
|
|
45
|
-
}
|
|
46
|
-
try {
|
|
47
|
-
// First, read all cells to get current state and validate indices
|
|
48
|
-
// Request detailed format to get full source for deletion confirmation
|
|
49
|
-
const cellsResult = await readAllCellsOperation.execute({ format: 'detailed' }, context);
|
|
50
|
-
if (!cellsResult.success || !cellsResult.cells) {
|
|
51
|
-
throw new Error('Failed to read cells for bounds validation');
|
|
52
|
-
}
|
|
53
|
-
const cellCount = cellsResult.cellCount || cellsResult.cells.length;
|
|
54
|
-
const cells = cellsResult.cells;
|
|
55
|
-
// Validate ALL indices are in range (match Jupyter MCP Server error format)
|
|
56
|
-
for (const index of indices) {
|
|
57
|
-
if (index < 0 || index >= cellCount) {
|
|
58
|
-
throw new Error(`Cell index ${index} is out of range. Notebook has ${cellCount} cells.`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// Sort indices in REVERSE order (highest to lowest) to prevent index shifting
|
|
62
|
-
// This matches the Jupyter MCP Server behavior
|
|
63
|
-
const sortedIndices = [...indices].sort((a, b) => b - a);
|
|
64
|
-
// Store information about cells before deletion
|
|
65
|
-
const deletedCells = [];
|
|
66
|
-
// Delete each cell in reverse order
|
|
67
|
-
for (const index of sortedIndices) {
|
|
68
|
-
// Store cell info before deletion (from original read)
|
|
69
|
-
const cell = cells[index];
|
|
70
|
-
// Execute deletion via executor
|
|
71
|
-
await context.executor.execute(this.name, {
|
|
72
|
-
index,
|
|
73
|
-
});
|
|
74
|
-
// Track deletion with original index
|
|
75
|
-
deletedCells.push({
|
|
76
|
-
index,
|
|
77
|
-
type: cell.type,
|
|
78
|
-
source: cell.source,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
// Format message similar to Jupyter MCP Server
|
|
82
|
-
const message = deletedCells
|
|
83
|
-
.map(cell => {
|
|
84
|
-
return (`Deleted cell at index ${cell.index}:\n` +
|
|
85
|
-
`Type: ${cell.type}\n` +
|
|
86
|
-
`----------------------------------------`);
|
|
87
|
-
})
|
|
88
|
-
.join('\n\n');
|
|
89
|
-
// Return success result
|
|
90
|
-
return {
|
|
91
|
-
success: true,
|
|
92
|
-
deletedCells: deletedCells.reverse(), // Reverse to show in original order
|
|
93
|
-
message,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
// Convert error to descriptive error
|
|
98
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
99
|
-
throw new Error(`Failed to delete cell(s): ${errorMessage}`);
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
//# sourceMappingURL=deleteCell.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deleteCell.js","sourceRoot":"","sources":["../../../src/tools/operations/deleteCell.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EACL,sBAAsB,GAEvB,MAAM,uBAAuB,CAAC;AAuB/B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAG5B;IACF,IAAI,EAAE,YAAY;IAElB,KAAK,CAAC,OAAO,CACX,MAAe,EACf,OAA6B;QAE7B,mCAAmC;QACnC,MAAM,EAAE,OAAO,EAAE,GAAG,eAAe,CACjC,sBAAsB,EACtB,MAAM,EACN,IAAI,CAAC,IAAI,CACV,CAAC;QACF,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;QAE/B,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CACb,oDAAoD;gBAClD,gEAAgE,CACnE,CAAC;QACJ,CAAC;QAED,+BAA+B;QAC/B,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CACb,iDAAiD;gBAC/C,iFAAiF,CACpF,CAAC;QACJ,CAAC;QAED,IAAI,CAAC;YACH,kEAAkE;YAClE,uEAAuE;YACvE,MAAM,WAAW,GAAG,MAAM,qBAAqB,CAAC,OAAO,CACrD,EAAE,MAAM,EAAE,UAAU,EAAE,EACtB,OAAO,CACR,CAAC;YAEF,IAAI,CAAC,WAAW,CAAC,OAAO,IAA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K,KAAK;oBACxC,SAAS,IAAI,CAAC,IAAI,IAAI;oBACtB,0CAA0C,CAC3C,CAAC;YACJ,CAAC,CAAC;iBACD,IAAI,CAAC,MAAM,CAAC,CAAC;YAEhB,wBAAwB;YACxB,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,YAAY,EAAE,YAAY,CAAC,OAAO,EAAE,EAAE,oCAAoC;gBAC1E,OAAO;aACR,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,qCAAqC;YACrC,MAAM,YAAY,GAChB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACzD,MAAM,IAAI,KAAK,CAAC,6BAA6B,YAAY,EAAE,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Zod schema for deleteCell operation parameters
|
|
3
|
-
*
|
|
4
|
-
* @module tools/schemas/deleteCell
|
|
5
|
-
*/
|
|
6
|
-
import { z } from 'zod';
|
|
7
|
-
/**
|
|
8
|
-
* Schema for deleteCell parameters
|
|
9
|
-
*
|
|
10
|
-
* Validates that indices is a non-empty array of non-negative integers.
|
|
11
|
-
*/
|
|
12
|
-
export declare const deleteCellParamsSchema: z.ZodObject<{
|
|
13
|
-
indices: z.ZodArray<z.ZodNumber>;
|
|
14
|
-
}, z.core.$strip>;
|
|
15
|
-
/**
|
|
16
|
-
* TypeScript type inferred from Zod schema.
|
|
17
|
-
*
|
|
18
|
-
* This replaces the manual interface definition and is guaranteed to stay in sync with the schema.
|
|
19
|
-
*/
|
|
20
|
-
export type DeleteCellParams = z.infer<typeof deleteCellParamsSchema>;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2021-2023 Datalayer, Inc.
|
|
3
|
-
*
|
|
4
|
-
* MIT License
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Zod schema for deleteCell operation parameters
|
|
8
|
-
*
|
|
9
|
-
* @module tools/schemas/deleteCell
|
|
10
|
-
*/
|
|
11
|
-
import { z } from 'zod';
|
|
12
|
-
/**
|
|
13
|
-
* Schema for deleteCell parameters
|
|
14
|
-
*
|
|
15
|
-
* Validates that indices is a non-empty array of non-negative integers.
|
|
16
|
-
*/
|
|
17
|
-
export const deleteCellParamsSchema = z.object({
|
|
18
|
-
indices: z
|
|
19
|
-
.array(z.number().int().nonnegative())
|
|
20
|
-
.min(1)
|
|
21
|
-
.describe('Array of cell indices (0-based) to delete. ' +
|
|
22
|
-
'Cells will be deleted in reverse order (highest index first) to prevent index shifting.'),
|
|
23
|
-
});
|
|
24
|
-
//# sourceMappingURL=deleteCell.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deleteCell.js","sourceRoot":"","sources":["../../../src/tools/schemas/deleteCell.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,OAAO,EAAE,CAAC;SACP,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC;SACrC,GAAG,CAAC,CAAC,CAAC;SACN,QAAQ,CACP,6CAA6C;QAC3C,yFAAyF,CAC5F;CACJ,CAAC,CAAC"}
|