@datalayer/jupyter-react 1.1.8 → 1.1.9
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.d.ts +3 -6
- package/lib/components/cell/Cell.js +2 -11
- package/lib/components/cell/Cell.js.map +1 -1
- package/lib/components/cell/CellAdapter.d.ts +1 -1
- package/lib/components/codemirror/CodeMirrorOutputToolbar.d.ts +2 -2
- package/lib/components/codemirror/CodeMirrorOutputToolbar.js.map +1 -1
- package/lib/components/console/ConsoleAdapter.d.ts +1 -1
- package/lib/components/console/ConsoleAdapter.js +1 -1
- package/lib/components/console/ConsoleAdapter.js.map +1 -1
- package/lib/components/jupyterlab/JupyterLabApp.d.ts +16 -19
- package/lib/components/jupyterlab/JupyterLabApp.js +21 -21
- package/lib/components/jupyterlab/JupyterLabApp.js.map +1 -1
- package/lib/components/jupyterlab/JupyterLabAppAdapter.d.ts +4 -4
- package/lib/components/jupyterlab/JupyterLabAppAdapter.js +1 -1
- package/lib/components/jupyterlab/JupyterLabAppAdapter.js.map +1 -1
- package/lib/components/jupyterlab/JupyterLabAppCss.d.ts +1 -4
- package/lib/components/jupyterlab/JupyterLabAppCss.js +1 -5
- package/lib/components/jupyterlab/JupyterLabAppCss.js.map +1 -1
- package/lib/components/kernel/KernelActionMenu.d.ts +2 -2
- package/lib/components/kernel/KernelActionMenu.js.map +1 -1
- package/lib/components/kernel/KernelDetective.d.ts +1 -1
- package/lib/components/kernel/KernelInspector.d.ts +2 -2
- package/lib/components/kernel/KernelInspector.js.map +1 -1
- package/lib/components/kernel/KernelSelector.d.ts +2 -2
- package/lib/components/kernel/KernelSelector.js.map +1 -1
- package/lib/components/kernel/KernelUsage.d.ts +2 -2
- package/lib/components/kernel/KernelUsage.js.map +1 -1
- package/lib/components/kernel/KernelVariables.d.ts +2 -2
- package/lib/components/kernel/KernelVariables.js.map +1 -1
- package/lib/components/kernel/Kernelndicator.d.ts +1 -1
- package/lib/components/kernel/variables/kernelconnector.d.ts +2 -2
- package/lib/components/kernel/variables/kernelconnector.js +2 -2
- package/lib/components/kernel/variables/widget.d.ts +4 -2
- package/lib/components/kernel/variables/widget.js.map +1 -1
- package/lib/components/lumino/Lumino.d.ts +1 -1
- package/lib/components/lumino/LuminoBox.d.ts +3 -9
- package/lib/components/lumino/LuminoBox.js +1 -6
- package/lib/components/lumino/LuminoBox.js.map +1 -1
- package/lib/components/lumino/ReactPortalWidget.d.ts +1 -2
- package/lib/components/notebook/Notebook.d.ts +4 -6
- package/lib/components/notebook/Notebook.js +11 -26
- package/lib/components/notebook/Notebook.js.map +1 -1
- package/lib/components/notebook/Notebook2Adapter.d.ts +179 -0
- package/lib/components/notebook/Notebook2Adapter.js +542 -10
- package/lib/components/notebook/Notebook2Adapter.js.map +1 -1
- package/lib/components/notebook/Notebook2Base.d.ts +8 -6
- package/lib/components/notebook/Notebook2Base.js +12 -3
- package/lib/components/notebook/Notebook2Base.js.map +1 -1
- package/lib/components/notebook/Notebook2State.d.ts +34 -8
- package/lib/components/notebook/Notebook2State.js +71 -45
- package/lib/components/notebook/Notebook2State.js.map +1 -1
- package/lib/components/notebook/NotebookAdapter.js +6 -5
- package/lib/components/notebook/NotebookAdapter.js.map +1 -1
- package/lib/components/notebook/NotebookState.d.ts +11 -11
- package/lib/components/notebook/cell/sidebar/CellSidebarButton.js +1 -1
- package/lib/components/notebook/cell/sidebar/CellSidebarExtension.d.ts +2 -4
- package/lib/components/notebook/cell/sidebar/CellSidebarExtension.js +1 -3
- package/lib/components/notebook/cell/sidebar/CellSidebarExtension.js.map +1 -1
- package/lib/components/notebook/index.d.ts +1 -0
- package/lib/components/notebook/index.js +1 -0
- package/lib/components/notebook/index.js.map +1 -1
- package/lib/components/notebook/model/JupyterReactNotebookModelFactory.d.ts +28 -1
- package/lib/components/notebook/model/JupyterReactNotebookModelFactory.js +15 -1
- package/lib/components/notebook/model/JupyterReactNotebookModelFactory.js.map +1 -1
- package/lib/components/output/Output.d.ts +11 -13
- package/lib/components/output/Output.js +19 -30
- package/lib/components/output/Output.js.map +1 -1
- package/lib/components/output/OutputIPyWidgets.d.ts +2 -2
- package/lib/components/output/OutputIPyWidgets.js.map +1 -1
- package/lib/components/output/OutputRenderer.d.ts +2 -2
- package/lib/components/output/OutputRenderer.js.map +1 -1
- package/lib/components/terminal/Terminal.d.ts +1 -4
- package/lib/components/terminal/Terminal.js +4 -7
- package/lib/components/terminal/Terminal.js.map +1 -1
- package/lib/components/viewer/Viewer.d.ts +1 -1
- package/lib/components/viewer/output/OutputViewer.d.ts +3 -6
- package/lib/components/viewer/output/OutputViewer.js +1 -5
- package/lib/components/viewer/output/OutputViewer.js.map +1 -1
- package/lib/examples/Notebook2Actions.js +1 -1
- package/lib/examples/Notebook2Actions.js.map +1 -1
- package/lib/examples/extensions/celltoolbar/CellToolbarComponent.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/jupyter/Jupyter.d.ts +1 -74
- package/lib/jupyter/Jupyter.js +2 -9
- package/lib/jupyter/Jupyter.js.map +1 -1
- package/lib/jupyter/JupyterConfig.js +2 -2
- package/lib/jupyter/JupyterConfig.js.map +1 -1
- package/lib/jupyter/JupyterContext.d.ts +2 -2
- package/lib/jupyter/ipywidgets/classic/htmlmanager.d.ts +6 -0
- package/lib/jupyter/ipywidgets/classic/htmlmanager.js +8 -0
- package/lib/jupyter/ipywidgets/classic/htmlmanager.js.map +1 -1
- package/lib/jupyter/ipywidgets/lab/manager.d.ts +6 -0
- package/lib/jupyter/ipywidgets/lab/manager.js +8 -0
- package/lib/jupyter/ipywidgets/lab/manager.js.map +1 -1
- package/lib/jupyter/ipywidgets/libembed-amd.d.ts +1 -1
- package/lib/jupyter/ipywidgets/libembed-amd.js +1 -1
- package/lib/jupyter/lite/LiteServer.d.ts +1 -1
- package/lib/jupyter/lite/LiteServer.js +1 -1
- package/lib/theme/JupyterLabCss.d.ts +1 -1
- package/lib/theme/JupyterReactTheme.d.ts +1 -1
- package/lib/tools/__tests__/operationRunner.test.d.ts +1 -0
- package/lib/tools/__tests__/operationRunner.test.js +193 -0
- package/lib/tools/__tests__/operationRunner.test.js.map +1 -0
- package/lib/tools/core/executor.d.ts +46 -0
- package/lib/tools/core/executor.js +55 -0
- package/lib/tools/core/executor.js.map +1 -0
- package/lib/tools/core/formatter.d.ts +20 -0
- package/lib/tools/core/formatter.js +41 -0
- package/lib/tools/core/formatter.js.map +1 -0
- package/lib/tools/core/index.d.ts +18 -0
- package/lib/tools/core/index.js +24 -0
- package/lib/tools/core/index.js.map +1 -0
- package/lib/tools/core/interfaces.d.ts +38 -0
- package/lib/tools/core/interfaces.js +7 -0
- package/lib/tools/core/interfaces.js.map +1 -0
- package/lib/tools/core/operationRunner.d.ts +27 -0
- package/lib/tools/core/operationRunner.js +33 -0
- package/lib/tools/core/operationRunner.js.map +1 -0
- package/lib/tools/core/schema.d.ts +47 -0
- package/lib/tools/core/schema.js +7 -0
- package/lib/tools/core/schema.js.map +1 -0
- package/lib/tools/core/types.d.ts +36 -0
- package/lib/tools/core/types.js +7 -0
- package/lib/tools/core/types.js.map +1 -0
- package/lib/tools/core/zodUtils.d.ts +56 -0
- package/lib/tools/core/zodUtils.js +179 -0
- package/lib/tools/core/zodUtils.js.map +1 -0
- package/lib/tools/definitions/deleteCell.d.ts +7 -0
- package/lib/tools/definitions/deleteCell.js +25 -0
- package/lib/tools/definitions/deleteCell.js.map +1 -0
- package/lib/tools/definitions/executeCode.d.ts +7 -0
- package/lib/tools/definitions/executeCode.js +33 -0
- package/lib/tools/definitions/executeCode.js.map +1 -0
- package/lib/tools/definitions/index.d.ts +12 -0
- package/lib/tools/definitions/index.js +18 -0
- package/lib/tools/definitions/index.js.map +1 -0
- package/lib/tools/definitions/insertCell.d.ts +7 -0
- package/lib/tools/definitions/insertCell.js +24 -0
- package/lib/tools/definitions/insertCell.js.map +1 -0
- package/lib/tools/definitions/readAllCells.d.ts +7 -0
- package/lib/tools/definitions/readAllCells.js +24 -0
- package/lib/tools/definitions/readAllCells.js.map +1 -0
- package/lib/tools/definitions/readCell.d.ts +7 -0
- package/lib/tools/definitions/readCell.js +24 -0
- package/lib/tools/definitions/readCell.js.map +1 -0
- package/lib/tools/definitions/runCell.d.ts +7 -0
- package/lib/tools/definitions/runCell.js +31 -0
- package/lib/tools/definitions/runCell.js.map +1 -0
- package/lib/tools/definitions/updateCell.d.ts +7 -0
- package/lib/tools/definitions/updateCell.js +24 -0
- package/lib/tools/definitions/updateCell.js.map +1 -0
- package/lib/tools/index.d.ts +20 -0
- package/lib/tools/index.js +62 -0
- package/lib/tools/index.js.map +1 -0
- package/lib/tools/operations/deleteCell.d.ts +49 -0
- package/lib/tools/operations/deleteCell.js +103 -0
- package/lib/tools/operations/deleteCell.js.map +1 -0
- package/lib/tools/operations/executeCode.d.ts +33 -0
- package/lib/tools/operations/executeCode.js +45 -0
- package/lib/tools/operations/executeCode.js.map +1 -0
- package/lib/tools/operations/insertCell.d.ts +27 -0
- package/lib/tools/operations/insertCell.js +56 -0
- package/lib/tools/operations/insertCell.js.map +1 -0
- package/lib/tools/operations/readAllCells.d.ts +21 -0
- package/lib/tools/operations/readAllCells.js +45 -0
- package/lib/tools/operations/readAllCells.js.map +1 -0
- package/lib/tools/operations/readCell.d.ts +39 -0
- package/lib/tools/operations/readCell.js +90 -0
- package/lib/tools/operations/readCell.js.map +1 -0
- package/lib/tools/operations/runCell.d.ts +24 -0
- package/lib/tools/operations/runCell.js +124 -0
- package/lib/tools/operations/runCell.js.map +1 -0
- package/lib/tools/operations/updateCell.d.ts +27 -0
- package/lib/tools/operations/updateCell.js +53 -0
- package/lib/tools/operations/updateCell.js.map +1 -0
- package/lib/tools/schemas/deleteCell.d.ts +20 -0
- package/lib/tools/schemas/deleteCell.js +24 -0
- package/lib/tools/schemas/deleteCell.js.map +1 -0
- package/lib/tools/schemas/executeCode.d.ts +19 -0
- package/lib/tools/schemas/executeCode.js +28 -0
- package/lib/tools/schemas/executeCode.js.map +1 -0
- package/lib/tools/schemas/index.d.ts +12 -0
- package/lib/tools/schemas/index.js +18 -0
- package/lib/tools/schemas/index.js.map +1 -0
- package/lib/tools/schemas/insertCell.d.ts +24 -0
- package/lib/tools/schemas/insertCell.js +29 -0
- package/lib/tools/schemas/insertCell.js.map +1 -0
- package/lib/tools/schemas/readAllCells.d.ts +19 -0
- package/lib/tools/schemas/readAllCells.js +18 -0
- package/lib/tools/schemas/readAllCells.js.map +1 -0
- package/lib/tools/schemas/readCell.d.ts +19 -0
- package/lib/tools/schemas/readCell.js +24 -0
- package/lib/tools/schemas/readCell.js.map +1 -0
- package/lib/tools/schemas/runCell.d.ts +21 -0
- package/lib/tools/schemas/runCell.js +39 -0
- package/lib/tools/schemas/runCell.js.map +1 -0
- package/lib/tools/schemas/updateCell.d.ts +19 -0
- package/lib/tools/schemas/updateCell.js +21 -0
- package/lib/tools/schemas/updateCell.js.map +1 -0
- package/package.json +19 -14
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021-2023 Datalayer, Inc.
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Response formatting utilities for tool operations.
|
|
8
|
+
* Supports JSON (default, structured) and TOON (human/LLM-readable).
|
|
9
|
+
*
|
|
10
|
+
* @module tools/core/formatter
|
|
11
|
+
*/
|
|
12
|
+
import { encode } from '@toon-format/toon';
|
|
13
|
+
/**
|
|
14
|
+
* Format tool response based on requested format.
|
|
15
|
+
*
|
|
16
|
+
* @template T - Type of the data being formatted
|
|
17
|
+
* @param data - Tool result to format
|
|
18
|
+
* @param format - Desired output format ("toon" default, or "json")
|
|
19
|
+
* @returns Formatted response (string for TOON, object for JSON)
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // TOON format (default) - returns human-readable string
|
|
24
|
+
* const toonResult = formatResponse({ success: true, cells: [...] });
|
|
25
|
+
* // Returns: "success: true\ncells:\n - type: code\n source: print('hello')\n..."
|
|
26
|
+
*
|
|
27
|
+
* // JSON format - returns structured object
|
|
28
|
+
* const jsonResult = formatResponse({ success: true, cells: [...] }, "json");
|
|
29
|
+
* // Returns: { success: true, cells: [...] }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export function formatResponse(data, format) {
|
|
33
|
+
// Return JSON (structured object) if explicitly requested
|
|
34
|
+
if (format === 'json') {
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
// Default to TOON format - encode as human/LLM-readable string
|
|
38
|
+
// This is the default because most tool operations are called by LLMs
|
|
39
|
+
return encode(data);
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../../src/tools/core/formatter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,cAAc,CAC5B,IAAO,EACP,MAAwB;IAExB,0DAA0D;IAC1D,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,+DAA+D;IAC/D,sEAAsE;IACtE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core tool operations, interfaces, and utilities.
|
|
3
|
+
*
|
|
4
|
+
* @module tools/core
|
|
5
|
+
*/
|
|
6
|
+
export * from '../operations/insertCell';
|
|
7
|
+
export * from '../operations/deleteCell';
|
|
8
|
+
export * from '../operations/updateCell';
|
|
9
|
+
export * from '../operations/readCell';
|
|
10
|
+
export * from '../operations/readAllCells';
|
|
11
|
+
export * from '../operations/runCell';
|
|
12
|
+
export * from '../operations/executeCode';
|
|
13
|
+
export * from './interfaces';
|
|
14
|
+
export * from './formatter';
|
|
15
|
+
export * from './executor';
|
|
16
|
+
export * from './operationRunner';
|
|
17
|
+
export * from './schema';
|
|
18
|
+
export * from './types';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021-2023 Datalayer, Inc.
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Core tool operations, interfaces, and utilities.
|
|
8
|
+
*
|
|
9
|
+
* @module tools/core
|
|
10
|
+
*/
|
|
11
|
+
export * from '../operations/insertCell';
|
|
12
|
+
export * from '../operations/deleteCell';
|
|
13
|
+
export * from '../operations/updateCell';
|
|
14
|
+
export * from '../operations/readCell';
|
|
15
|
+
export * from '../operations/readAllCells';
|
|
16
|
+
export * from '../operations/runCell';
|
|
17
|
+
export * from '../operations/executeCode';
|
|
18
|
+
export * from './interfaces';
|
|
19
|
+
export * from './formatter';
|
|
20
|
+
export * from './executor';
|
|
21
|
+
export * from './operationRunner';
|
|
22
|
+
export * from './schema';
|
|
23
|
+
export * from './types';
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/core/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AAEH,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAE1C,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core interfaces for platform-agnostic tool operations.
|
|
3
|
+
*
|
|
4
|
+
* @module tools/core/interfaces
|
|
5
|
+
*/
|
|
6
|
+
import type { ToolExecutor } from './executor';
|
|
7
|
+
/**
|
|
8
|
+
* Execution context for tool operations.
|
|
9
|
+
*/
|
|
10
|
+
export interface ToolExecutionContext {
|
|
11
|
+
/** Tool executor (DefaultExecutor, BridgeExecutor, etc.) */
|
|
12
|
+
executor: ToolExecutor;
|
|
13
|
+
/** Document identifier - universal for notebooks, lexicals, etc. (file URI or document UID) */
|
|
14
|
+
documentId?: string;
|
|
15
|
+
/** Response format: "json" (default) or "toon" */
|
|
16
|
+
format?: 'json' | 'toon';
|
|
17
|
+
/** Platform-specific additional context */
|
|
18
|
+
extras?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Platform-agnostic tool operation interface.
|
|
22
|
+
*
|
|
23
|
+
* @template TParams - Tool parameter type
|
|
24
|
+
* @template TResult - Tool result type
|
|
25
|
+
*/
|
|
26
|
+
export interface ToolOperation<TParams, TResult> {
|
|
27
|
+
/** Operation name (matches ToolDefinition.operation field) */
|
|
28
|
+
name: string;
|
|
29
|
+
/**
|
|
30
|
+
* Execute the operation.
|
|
31
|
+
*
|
|
32
|
+
* @param params - Tool parameters
|
|
33
|
+
* @param context - Execution context
|
|
34
|
+
* @returns Operation result
|
|
35
|
+
*/
|
|
36
|
+
execute(params: TParams, context: ToolExecutionContext): Promise<TResult>;
|
|
37
|
+
}
|
|
38
|
+
export type { ToolExecutor };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/tools/core/interfaces.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operation runner that executes operations and applies formatting.
|
|
3
|
+
*
|
|
4
|
+
* @module tools/core/operationRunner
|
|
5
|
+
*/
|
|
6
|
+
import type { ToolOperation, ToolExecutionContext } from './interfaces';
|
|
7
|
+
/**
|
|
8
|
+
* Executes tool operations and applies formatting to results.
|
|
9
|
+
*
|
|
10
|
+
* Operations return pure typed data. The runner applies formatting
|
|
11
|
+
* based on context.format:
|
|
12
|
+
* - 'json' → Returns structured object (TResult)
|
|
13
|
+
* - 'toon' → Returns TOON-encoded string
|
|
14
|
+
*/
|
|
15
|
+
export declare class OperationRunner {
|
|
16
|
+
/**
|
|
17
|
+
* Execute an operation and format its result.
|
|
18
|
+
*
|
|
19
|
+
* @template TParams - Operation parameter type
|
|
20
|
+
* @template TResult - Operation result type
|
|
21
|
+
* @param operation - Tool operation to execute
|
|
22
|
+
* @param params - Operation parameters
|
|
23
|
+
* @param context - Execution context
|
|
24
|
+
* @returns Formatted result (object or string based on context.format)
|
|
25
|
+
*/
|
|
26
|
+
execute<TParams, TResult>(operation: ToolOperation<TParams, TResult>, params: TParams, context: ToolExecutionContext): Promise<TResult | string>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021-2023 Datalayer, Inc.
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import { formatResponse } from './formatter';
|
|
7
|
+
/**
|
|
8
|
+
* Executes tool operations and applies formatting to results.
|
|
9
|
+
*
|
|
10
|
+
* Operations return pure typed data. The runner applies formatting
|
|
11
|
+
* based on context.format:
|
|
12
|
+
* - 'json' → Returns structured object (TResult)
|
|
13
|
+
* - 'toon' → Returns TOON-encoded string
|
|
14
|
+
*/
|
|
15
|
+
export class OperationRunner {
|
|
16
|
+
/**
|
|
17
|
+
* Execute an operation and format its result.
|
|
18
|
+
*
|
|
19
|
+
* @template TParams - Operation parameter type
|
|
20
|
+
* @template TResult - Operation result type
|
|
21
|
+
* @param operation - Tool operation to execute
|
|
22
|
+
* @param params - Operation parameters
|
|
23
|
+
* @param context - Execution context
|
|
24
|
+
* @returns Formatted result (object or string based on context.format)
|
|
25
|
+
*/
|
|
26
|
+
async execute(operation, params, context) {
|
|
27
|
+
// Execute operation (returns pure typed data)
|
|
28
|
+
const result = await operation.execute(params, context);
|
|
29
|
+
// Apply formatting based on context.format
|
|
30
|
+
return formatResponse(result, context.format);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=operationRunner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operationRunner.js","sourceRoot":"","sources":["../../../src/tools/core/operationRunner.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;;;GAOG;AACH,MAAM,OAAO,eAAe;IAC1B;;;;;;;;;OASG;IACH,KAAK,CAAC,OAAO,CACX,SAA0C,EAC1C,MAAe,EACf,OAA6B;QAE7B,8CAA8C;QAC9C,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAExD,2CAA2C;QAC3C,OAAO,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;CACF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform-agnostic tool configuration and definition schemas.
|
|
3
|
+
*
|
|
4
|
+
* @module tools/core/schema
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Tool configuration interface.
|
|
8
|
+
*/
|
|
9
|
+
export interface ToolConfig<TParams = unknown> {
|
|
10
|
+
/** Confirmation message from parameters */
|
|
11
|
+
confirmationMessage?: (params: TParams) => string;
|
|
12
|
+
/** Invocation message from parameters */
|
|
13
|
+
invocationMessage?: (params: TParams) => string;
|
|
14
|
+
/** Require user confirmation */
|
|
15
|
+
requiresConfirmation?: boolean;
|
|
16
|
+
/** Can be referenced in prompts */
|
|
17
|
+
canBeReferencedInPrompt?: boolean;
|
|
18
|
+
/** Priority for suggestion ranking */
|
|
19
|
+
priority?: 'low' | 'medium' | 'high';
|
|
20
|
+
/** Platform-specific config extensions */
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Tool definition interface.
|
|
25
|
+
*/
|
|
26
|
+
export interface ToolDefinition<TParams = unknown> {
|
|
27
|
+
/** Vendor-prefixed tool name (e.g., "datalayer_insertCell") */
|
|
28
|
+
name: string;
|
|
29
|
+
/** Display name */
|
|
30
|
+
displayName: string;
|
|
31
|
+
/** User-facing reference name (e.g., "insertCell") */
|
|
32
|
+
toolReferenceName: string;
|
|
33
|
+
/** Tool description */
|
|
34
|
+
description: string;
|
|
35
|
+
/** JSON Schema for parameters */
|
|
36
|
+
parameters: {
|
|
37
|
+
type: 'object';
|
|
38
|
+
properties: Record<string, unknown>;
|
|
39
|
+
required?: string[];
|
|
40
|
+
};
|
|
41
|
+
/** Operation handler name */
|
|
42
|
+
operation: string;
|
|
43
|
+
/** Tool configuration */
|
|
44
|
+
config?: ToolConfig<TParams>;
|
|
45
|
+
/** Categorization tags */
|
|
46
|
+
tags?: string[];
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/tools/core/schema.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for notebook tool operations.
|
|
3
|
+
*
|
|
4
|
+
* @module tools/core/types
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Cell format for controlling response detail level
|
|
8
|
+
*/
|
|
9
|
+
export type CellFormat = 'brief' | 'detailed';
|
|
10
|
+
/**
|
|
11
|
+
* Brief cell representation for structure queries
|
|
12
|
+
* Includes index, type, and a 40-char content preview
|
|
13
|
+
*/
|
|
14
|
+
export interface BriefCell {
|
|
15
|
+
/** Cell index in notebook */
|
|
16
|
+
index: number;
|
|
17
|
+
/** Cell type (code, markdown, raw) */
|
|
18
|
+
type: string;
|
|
19
|
+
/** 40-character preview of cell source */
|
|
20
|
+
preview: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Detailed cell representation with full content
|
|
24
|
+
*/
|
|
25
|
+
export interface DetailedCell {
|
|
26
|
+
/** Cell index in notebook */
|
|
27
|
+
index: number;
|
|
28
|
+
/** Cell type (code, markdown, raw) */
|
|
29
|
+
type: string;
|
|
30
|
+
/** Full cell source code */
|
|
31
|
+
source: string;
|
|
32
|
+
/** Execution count for code cells */
|
|
33
|
+
execution_count?: number | null;
|
|
34
|
+
/** Cell outputs (for code cells) */
|
|
35
|
+
outputs?: string[];
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/tools/core/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod utility functions for tool parameter validation
|
|
3
|
+
*
|
|
4
|
+
* @module tools/core/zodUtils
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import type { ToolDefinition } from './schema';
|
|
8
|
+
/**
|
|
9
|
+
* Converts a Zod schema to ToolDefinition parameters (JSON Schema format).
|
|
10
|
+
*
|
|
11
|
+
* This enables a single source of truth: define the schema once with Zod,
|
|
12
|
+
* and automatically generate the JSON Schema for LLM tool calling.
|
|
13
|
+
*
|
|
14
|
+
* @param schema - Zod schema defining the tool's input parameters
|
|
15
|
+
* @returns JSON Schema object compatible with ToolDefinition.parameters
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const schema = z.object({
|
|
20
|
+
* index: z.number().int().describe('Cell index'),
|
|
21
|
+
* source: z.string().describe('Cell content')
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* const parameters = zodToToolParameters(schema);
|
|
25
|
+
* // Returns: { type: 'object', properties: {...}, required: [...] }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function zodToToolParameters(schema: any): ToolDefinition['parameters'];
|
|
29
|
+
/**
|
|
30
|
+
* Validates parameters using a Zod schema with user-friendly error messages.
|
|
31
|
+
*
|
|
32
|
+
* This replaces manual type guard functions with automatic runtime validation.
|
|
33
|
+
* On validation failure, throws a descriptive error that helps both developers
|
|
34
|
+
* and LLMs understand what went wrong.
|
|
35
|
+
*
|
|
36
|
+
* @param schema - Zod schema to validate against
|
|
37
|
+
* @param params - Unknown parameters to validate
|
|
38
|
+
* @param operationName - Name of the operation (for error messages)
|
|
39
|
+
* @returns Validated parameters with proper TypeScript type
|
|
40
|
+
* @throws Error with detailed validation failure information
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const schema = z.object({ index: z.number().int() });
|
|
45
|
+
*
|
|
46
|
+
* // Valid params
|
|
47
|
+
* const validated = validateWithZod(schema, { index: 5 }, 'readCell');
|
|
48
|
+
* // Returns: { index: 5 } with type { index: number }
|
|
49
|
+
*
|
|
50
|
+
* // Invalid params
|
|
51
|
+
* validateWithZod(schema, { index: 'invalid' }, 'readCell');
|
|
52
|
+
* // Throws: Error: Invalid parameters for readCell:
|
|
53
|
+
* // - index: Expected number, received string
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function validateWithZod<T>(schema: z.ZodType<T>, params: unknown, operationName: string): T;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021-2023 Datalayer, Inc.
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Zod utility functions for tool parameter validation
|
|
8
|
+
*
|
|
9
|
+
* @module tools/core/zodUtils
|
|
10
|
+
*/
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
13
|
+
/**
|
|
14
|
+
* Converts a Zod schema to ToolDefinition parameters (JSON Schema format).
|
|
15
|
+
*
|
|
16
|
+
* This enables a single source of truth: define the schema once with Zod,
|
|
17
|
+
* and automatically generate the JSON Schema for LLM tool calling.
|
|
18
|
+
*
|
|
19
|
+
* @param schema - Zod schema defining the tool's input parameters
|
|
20
|
+
* @returns JSON Schema object compatible with ToolDefinition.parameters
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const schema = z.object({
|
|
25
|
+
* index: z.number().int().describe('Cell index'),
|
|
26
|
+
* source: z.string().describe('Cell content')
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* const parameters = zodToToolParameters(schema);
|
|
30
|
+
* // Returns: { type: 'object', properties: {...}, required: [...] }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function zodToToolParameters(
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
+
schema) {
|
|
36
|
+
// Manual conversion for Zod v3/v4 compatibility
|
|
37
|
+
// zod-to-json-schema@3.x doesn't fully support Zod v4
|
|
38
|
+
// Handle both Zod v3 (_def.type === 'object') and Zod v4 (_def.typeName === 'ZodObject')
|
|
39
|
+
const isZodObject = schema?._def?.typeName === 'ZodObject' || schema?._def?.type === 'object';
|
|
40
|
+
if (isZodObject && schema._def?.shape) {
|
|
41
|
+
// Get shape object - handle both Zod v3 (shape is object) and Zod v4 (shape is function)
|
|
42
|
+
const shape = typeof schema._def.shape === 'function'
|
|
43
|
+
? schema._def.shape()
|
|
44
|
+
: schema._def.shape;
|
|
45
|
+
const properties = {};
|
|
46
|
+
const required = [];
|
|
47
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
48
|
+
let zodField = value;
|
|
49
|
+
// Build property schema
|
|
50
|
+
const prop = {};
|
|
51
|
+
// Unwrap optional/default modifiers to get to the base type
|
|
52
|
+
// Support both Zod v3 (def/def) and Zod v4 (_def)
|
|
53
|
+
let isOptional = false;
|
|
54
|
+
while (zodField._def?.typeName === 'ZodOptional' ||
|
|
55
|
+
zodField._def?.typeName === 'ZodDefault' ||
|
|
56
|
+
zodField._def?.type === 'optional' ||
|
|
57
|
+
zodField._def?.type === 'default' ||
|
|
58
|
+
zodField.def?.type === 'optional' ||
|
|
59
|
+
zodField.def?.type === 'default') {
|
|
60
|
+
if (zodField._def?.typeName === 'ZodOptional' ||
|
|
61
|
+
zodField._def?.type === 'optional' ||
|
|
62
|
+
zodField.def?.type === 'optional') {
|
|
63
|
+
isOptional = true;
|
|
64
|
+
}
|
|
65
|
+
// Unwrap to get the inner type - try all possible paths
|
|
66
|
+
zodField =
|
|
67
|
+
zodField._def?.innerType || zodField.def?.innerType || zodField;
|
|
68
|
+
}
|
|
69
|
+
// Extract description (check at each level)
|
|
70
|
+
// Support both Zod v3 (def.description) and Zod v4 (_def.description)
|
|
71
|
+
const description = value._def?.description ||
|
|
72
|
+
value.def?.description ||
|
|
73
|
+
value.description;
|
|
74
|
+
if (description) {
|
|
75
|
+
prop.description = description;
|
|
76
|
+
}
|
|
77
|
+
// Handle type based on unwrapped field
|
|
78
|
+
// Support both Zod v3 (def.type) and Zod v4 (_def.typeName or _def.type)
|
|
79
|
+
const typeName = zodField._def?.typeName || zodField._def?.type || zodField.def?.type;
|
|
80
|
+
if (typeName === 'ZodString' || typeName === 'string') {
|
|
81
|
+
prop.type = 'string';
|
|
82
|
+
}
|
|
83
|
+
else if (typeName === 'ZodNumber' || typeName === 'number') {
|
|
84
|
+
prop.type = 'number';
|
|
85
|
+
}
|
|
86
|
+
else if (typeName === 'ZodBoolean' || typeName === 'boolean') {
|
|
87
|
+
prop.type = 'boolean';
|
|
88
|
+
}
|
|
89
|
+
else if (typeName === 'ZodEnum' || typeName === 'enum') {
|
|
90
|
+
prop.type = 'string';
|
|
91
|
+
// Enum values can be in different places depending on Zod version:
|
|
92
|
+
// - Zod v4: _def.values (array)
|
|
93
|
+
// - Zod v3: def.entries (object), options (array), or enum (object)
|
|
94
|
+
const enumValues = zodField._def?.values ||
|
|
95
|
+
zodField.def?.values ||
|
|
96
|
+
zodField.options ||
|
|
97
|
+
(zodField.def?.entries ? Object.keys(zodField.def.entries) : null) ||
|
|
98
|
+
(zodField.enum ? Object.keys(zodField.enum) : null) ||
|
|
99
|
+
[];
|
|
100
|
+
prop.enum = Array.isArray(enumValues)
|
|
101
|
+
? enumValues
|
|
102
|
+
: Object.keys(enumValues || {});
|
|
103
|
+
}
|
|
104
|
+
properties[key] = prop;
|
|
105
|
+
// Mark as required if not optional
|
|
106
|
+
if (!isOptional) {
|
|
107
|
+
required.push(key);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
type: 'object',
|
|
112
|
+
properties,
|
|
113
|
+
required,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
// Fallback to zod-to-json-schema for other schema types
|
|
117
|
+
// Note: This may not work correctly with Zod v4
|
|
118
|
+
const jsonSchema = zodToJsonSchema(schema, {
|
|
119
|
+
target: 'openApi3',
|
|
120
|
+
$refStrategy: 'none',
|
|
121
|
+
});
|
|
122
|
+
const schemaProperties = jsonSchema.properties || {};
|
|
123
|
+
const requiredFields = jsonSchema.required || [];
|
|
124
|
+
return {
|
|
125
|
+
type: 'object',
|
|
126
|
+
properties: schemaProperties,
|
|
127
|
+
required: requiredFields,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Validates parameters using a Zod schema with user-friendly error messages.
|
|
132
|
+
*
|
|
133
|
+
* This replaces manual type guard functions with automatic runtime validation.
|
|
134
|
+
* On validation failure, throws a descriptive error that helps both developers
|
|
135
|
+
* and LLMs understand what went wrong.
|
|
136
|
+
*
|
|
137
|
+
* @param schema - Zod schema to validate against
|
|
138
|
+
* @param params - Unknown parameters to validate
|
|
139
|
+
* @param operationName - Name of the operation (for error messages)
|
|
140
|
+
* @returns Validated parameters with proper TypeScript type
|
|
141
|
+
* @throws Error with detailed validation failure information
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const schema = z.object({ index: z.number().int() });
|
|
146
|
+
*
|
|
147
|
+
* // Valid params
|
|
148
|
+
* const validated = validateWithZod(schema, { index: 5 }, 'readCell');
|
|
149
|
+
* // Returns: { index: 5 } with type { index: number }
|
|
150
|
+
*
|
|
151
|
+
* // Invalid params
|
|
152
|
+
* validateWithZod(schema, { index: 'invalid' }, 'readCell');
|
|
153
|
+
* // Throws: Error: Invalid parameters for readCell:
|
|
154
|
+
* // - index: Expected number, received string
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export function validateWithZod(schema, params, operationName) {
|
|
158
|
+
try {
|
|
159
|
+
// Parse and validate parameters
|
|
160
|
+
return schema.parse(params);
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
if (error instanceof z.ZodError) {
|
|
164
|
+
// Convert Zod validation errors to user-friendly format
|
|
165
|
+
const issues = error.issues
|
|
166
|
+
.map(issue => {
|
|
167
|
+
// Build path string (e.g., "cells[0].type" for nested errors)
|
|
168
|
+
const path = issue.path.length > 0 ? issue.path.join('.') : 'root';
|
|
169
|
+
return ` - ${path}: ${issue.message}`;
|
|
170
|
+
})
|
|
171
|
+
.join('\n');
|
|
172
|
+
throw new Error(`Invalid parameters for ${operationName}:\n${issues}\n\n` +
|
|
173
|
+
`Received: ${JSON.stringify(params)}`);
|
|
174
|
+
}
|
|
175
|
+
// Re-throw non-Zod errors
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=zodUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zodUtils.js","sourceRoot":"","sources":["../../../src/tools/core/zodUtils.ts"],"names":[],"mappings":"AAAA;;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,EAAE,CAAC;IAEjD,OAAO;QACL,IAAI,EAAE,QAAiB;QACvB,UAAU,EAAE,gBAAgB;QAC5B,QAAQ,EAAE,cAAc;KACzB,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAoB,EACpB,MAAe,EACf,aAAqB;IAErB,IAAI,CAAC;QACH,gCAAgC;QAChC,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAChC,wDAAwD;YACxD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM;iBACxB,GAAG,CAAC,KAAK,CAAC,EAAE;gBACX,8DAA8D;gBAC9D,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;gBAEnE,OAAO,OAAO,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;YACzC,CAAC,CAAC;iBACD,IAAI,CAAC,IAAI,CAAC,CAAC;YAEd,MAAM,IAAI,KAAK,CACb,0BAA0B,aAAa,MAAM,MAAM,MAAM;gBACvD,aAAa,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CACxC,CAAC;QACJ,CAAC;QAED,0BAA0B;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021-2023 Datalayer, Inc.
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import { zodToToolParameters } from '../core/zodUtils';
|
|
7
|
+
import { deleteCellParamsSchema } from '../schemas/deleteCell';
|
|
8
|
+
export const deleteCellTool = {
|
|
9
|
+
name: 'datalayer_deleteCell',
|
|
10
|
+
displayName: 'Delete Notebook Cell(s)',
|
|
11
|
+
toolReferenceName: 'deleteCell',
|
|
12
|
+
description: 'Deletes one or more cells from a Jupyter notebook at the specified indices. Cells are deleted in reverse order to prevent index shifting.',
|
|
13
|
+
// Generate parameters from Zod schema (single source of truth)
|
|
14
|
+
parameters: zodToToolParameters(deleteCellParamsSchema),
|
|
15
|
+
operation: 'deleteCell',
|
|
16
|
+
config: {
|
|
17
|
+
confirmationMessage: (params) => `Delete ${params.indices.length} cell${params.indices.length !== 1 ? 's' : ''} at ${params.indices.length === 1 ? `index ${params.indices[0]}` : `indices ${params.indices.join(', ')}`}?`,
|
|
18
|
+
invocationMessage: (params) => `Deleting ${params.indices.length} cell${params.indices.length !== 1 ? 's' : ''}`,
|
|
19
|
+
requiresConfirmation: true,
|
|
20
|
+
canBeReferencedInPrompt: true,
|
|
21
|
+
priority: 'medium',
|
|
22
|
+
},
|
|
23
|
+
tags: ['cell', 'notebook', 'manipulation', 'delete'],
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=deleteCell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteCell.js","sourceRoot":"","sources":["../../../src/tools/definitions/deleteCell.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,MAAM,CAAC,MAAM,cAAc,GAAmB;IAC5C,IAAI,EAAE,sBAAsB;IAC5B,WAAW,EAAE,yBAAyB;IACtC,iBAAiB,EAAE,YAAY;IAC/B,WAAW,EACT,2IAA2I;IAE7I,+DAA+D;IAC/D,UAAU,EAAE,mBAAmB,CAAC,sBAAsB,CAAC;IAEvD,SAAS,EAAE,YAAY;IAEvB,MAAM,EAAE;QACN,mBAAmB,EAAE,CAAC,MAA6B,EAAE,EAAE,CACrD,UAAU,MAAM,CAAC,OAAO,CAAC,MAAM,QAAQ,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG;QAC5L,iBAAiB,EAAE,CAAC,MAA6B,EAAE,EAAE,CACnD,YAAY,MAAM,CAAC,OAAO,CAAC,MAAM,QAAQ,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACnF,oBAAoB,EAAE,IAAI;QAC1B,uBAAuB,EAAE,IAAI;QAC7B,QAAQ,EAAE,QAAQ;KACnB;IAED,IAAI,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,CAAC;CACrD,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021-2023 Datalayer, Inc.
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import { zodToToolParameters } from '../core/zodUtils';
|
|
7
|
+
import { executeCodeParamsSchema } from '../schemas/executeCode';
|
|
8
|
+
export const executeCodeTool = {
|
|
9
|
+
name: 'datalayer_executeCode',
|
|
10
|
+
displayName: 'Execute Code in Kernel',
|
|
11
|
+
toolReferenceName: 'executeCode',
|
|
12
|
+
description: 'Execute code directly in the kernel (not saved to notebook) on the current activated notebook.\n\n' +
|
|
13
|
+
'Recommended to use in following cases:\n' +
|
|
14
|
+
'1. Execute Jupyter magic commands (e.g., %timeit, %pip install xxx)\n' +
|
|
15
|
+
'2. Performance profiling and debugging\n' +
|
|
16
|
+
'3. View intermediate variable values (e.g., print(xxx), df.head())\n' +
|
|
17
|
+
"4. Temporary calculations and quick tests (e.g., np.mean(df['xxx']))\n" +
|
|
18
|
+
'5. Execute Shell commands in Jupyter server (e.g., !git xxx)\n\n' +
|
|
19
|
+
'Under no circumstances should you use this tool to:\n' +
|
|
20
|
+
'1. Import new modules or perform variable assignments that affect subsequent Notebook execution\n' +
|
|
21
|
+
"2. Execute dangerous code that may harm the Jupyter server or the user's data without permission",
|
|
22
|
+
parameters: zodToToolParameters(executeCodeParamsSchema),
|
|
23
|
+
operation: 'executeCode',
|
|
24
|
+
config: {
|
|
25
|
+
confirmationMessage: (params) => `Execute code: ${params.code.substring(0, 50)}${params.code.length > 50 ? '...' : ''}?`,
|
|
26
|
+
invocationMessage: () => 'Executing code in kernel',
|
|
27
|
+
requiresConfirmation: false,
|
|
28
|
+
canBeReferencedInPrompt: true,
|
|
29
|
+
priority: 'high',
|
|
30
|
+
},
|
|
31
|
+
tags: ['kernel', 'notebook', 'execute', 'code', 'inspection', 'magic'],
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=executeCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executeCode.js","sourceRoot":"","sources":["../../../src/tools/definitions/executeCode.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,MAAM,CAAC,MAAM,eAAe,GAAmB;IAC7C,IAAI,EAAE,uBAAuB;IAC7B,WAAW,EAAE,wBAAwB;IACrC,iBAAiB,EAAE,aAAa;IAChC,WAAW,EACT,oGAAoG;QACpG,0CAA0C;QAC1C,uEAAuE;QACvE,0CAA0C;QAC1C,sEAAsE;QACtE,wEAAwE;QACxE,kEAAkE;QAClE,uDAAuD;QACvD,mGAAmG;QACnG,kGAAkG;IAEpG,UAAU,EAAE,mBAAmB,CAAC,uBAAuB,CAAC;IAExD,SAAS,EAAE,aAAa;IAExB,MAAM,EAAE;QACN,mBAAmB,EAAE,CAAC,MAAwB,EAAE,EAAE,CAChD,iBAAiB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG;QACzF,iBAAiB,EAAE,GAAG,EAAE,CAAC,0BAA0B;QACnD,oBAAoB,EAAE,KAAK;QAC3B,uBAAuB,EAAE,IAAI;QAC7B,QAAQ,EAAE,MAAM;KACjB;IAED,IAAI,EAAE,CAAC,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC;CACvE,CAAC"}
|