@datalayer/jupyter-react 1.1.7 → 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/Kernelndicator.js +17 -13
- package/lib/components/kernel/Kernelndicator.js.map +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 +2 -8
- package/lib/components/lumino/Lumino.js +1 -6
- package/lib/components/lumino/Lumino.js.map +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 -27
- package/lib/components/notebook/Notebook.js.map +1 -1
- package/lib/components/notebook/Notebook2.d.ts +7 -0
- package/lib/components/notebook/Notebook2.js +13 -2
- package/lib/components/notebook/Notebook2.js.map +1 -1
- package/lib/components/notebook/Notebook2Adapter.d.ts +197 -0
- package/lib/components/notebook/Notebook2Adapter.js +563 -9
- package/lib/components/notebook/Notebook2Adapter.js.map +1 -1
- package/lib/components/notebook/Notebook2Base.d.ts +15 -6
- package/lib/components/notebook/Notebook2Base.js +183 -15
- package/lib/components/notebook/Notebook2Base.js.map +1 -1
- package/lib/components/notebook/Notebook2State.d.ts +36 -8
- package/lib/components/notebook/Notebook2State.js +75 -21
- package/lib/components/notebook/Notebook2State.js.map +1 -1
- package/lib/components/notebook/NotebookAdapter.js +6 -87
- 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 +43 -35
- package/lib/components/output/Output.js.map +1 -1
- package/lib/components/output/OutputAdapter.d.ts +1 -0
- package/lib/components/output/OutputAdapter.js +6 -0
- package/lib/components/output/OutputAdapter.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 +11 -1
- package/lib/components/output/OutputRenderer.js.map +1 -1
- package/lib/components/output/ipywidgets/IPyWidgetsViewManager.js +1 -3
- package/lib/components/output/ipywidgets/IPyWidgetsViewManager.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/JupyterLabAppHeadless.js +1 -1
- package/lib/examples/JupyterLabAppHeadless.js.map +1 -1
- package/lib/examples/JupyterLabAppHeadlessServerless.js +1 -1
- package/lib/examples/JupyterLabAppHeadlessServerless.js.map +1 -1
- package/lib/examples/Notebook2Actions.js +2 -2
- package/lib/examples/Notebook2Actions.js.map +1 -1
- package/lib/examples/RunningSessions.js +1 -1
- package/lib/examples/RunningSessions.js.map +1 -1
- package/lib/examples/extensions/celltoolbar/CellToolbarComponent.js +1 -1
- package/lib/index.d.ts +4 -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.d.ts +6 -0
- package/lib/jupyter/JupyterConfig.js +10 -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 +25 -16
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool executor interface and implementations.
|
|
3
|
+
* Provides platform-agnostic execution abstraction.
|
|
4
|
+
*
|
|
5
|
+
* @module tools/core/executor
|
|
6
|
+
*/
|
|
7
|
+
import type { Notebook2State } from '../../components/notebook/Notebook2State';
|
|
8
|
+
/**
|
|
9
|
+
* Tool executor interface - abstracts how operations are executed.
|
|
10
|
+
* Platforms can implement this interface to provide custom execution logic.
|
|
11
|
+
*/
|
|
12
|
+
export interface ToolExecutor {
|
|
13
|
+
/**
|
|
14
|
+
* Execute a tool operation
|
|
15
|
+
*
|
|
16
|
+
* @param operationName - Name of the operation (e.g., "insertCell", "runCell")
|
|
17
|
+
* @param args - Operation arguments
|
|
18
|
+
* @returns Result from execution
|
|
19
|
+
*/
|
|
20
|
+
execute(operationName: string, args: unknown): Promise<unknown>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Default executor - directly calls Notebook2State store methods.
|
|
24
|
+
* Calls methods with individual parameters by spreading the payload object.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const executor = new DefaultExecutor(documentId, notebookStore);
|
|
29
|
+
* await executor.execute("insertCell", { type: "code", index: 0, source: "print('hi')" });
|
|
30
|
+
* // Calls: store.insertCell(documentId, "code", 0, "print('hi')")
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare class DefaultExecutor implements ToolExecutor {
|
|
34
|
+
private documentId;
|
|
35
|
+
private store;
|
|
36
|
+
constructor(documentId: string, store: Notebook2State);
|
|
37
|
+
/**
|
|
38
|
+
* Execute an operation by calling the corresponding Notebook2State method.
|
|
39
|
+
* Builds payload with documentId and spreads values as individual parameters.
|
|
40
|
+
*
|
|
41
|
+
* @param operationName - Name of the operation (e.g., "insertCell", "deleteCell")
|
|
42
|
+
* @param args - Operation arguments as an object
|
|
43
|
+
* @returns Result from store method
|
|
44
|
+
*/
|
|
45
|
+
execute(operationName: string, args: unknown): Promise<unknown>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021-2023 Datalayer, Inc.
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Default executor - directly calls Notebook2State store methods.
|
|
8
|
+
* Calls methods with individual parameters by spreading the payload object.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const executor = new DefaultExecutor(documentId, notebookStore);
|
|
13
|
+
* await executor.execute("insertCell", { type: "code", index: 0, source: "print('hi')" });
|
|
14
|
+
* // Calls: store.insertCell(documentId, "code", 0, "print('hi')")
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export class DefaultExecutor {
|
|
18
|
+
documentId;
|
|
19
|
+
store;
|
|
20
|
+
constructor(documentId, store) {
|
|
21
|
+
this.documentId = documentId;
|
|
22
|
+
this.store = store;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Execute an operation by calling the corresponding Notebook2State method.
|
|
26
|
+
* Builds payload with documentId and spreads values as individual parameters.
|
|
27
|
+
*
|
|
28
|
+
* @param operationName - Name of the operation (e.g., "insertCell", "deleteCell")
|
|
29
|
+
* @param args - Operation arguments as an object
|
|
30
|
+
* @returns Result from store method
|
|
31
|
+
*/
|
|
32
|
+
async execute(operationName, args) {
|
|
33
|
+
console.log(`[DefaultExecutor] Executing: ${operationName} for document: ${this.documentId}`);
|
|
34
|
+
console.log(`[DefaultExecutor] Args:`, args);
|
|
35
|
+
// Get the store method directly (1:1 mapping, no transformation)
|
|
36
|
+
const method = this.store[operationName];
|
|
37
|
+
if (typeof method !== 'function') {
|
|
38
|
+
console.error(`[DefaultExecutor] Method '${operationName}' not found in store!`);
|
|
39
|
+
console.error(`[DefaultExecutor] Available methods:`, Object.keys(this.store).filter(k => typeof this.store[k] === 'function'));
|
|
40
|
+
throw new Error(`Store method '${operationName}' not found or not a function`);
|
|
41
|
+
}
|
|
42
|
+
// Build payload: { id, ...args } - pass as single object parameter
|
|
43
|
+
const payload = typeof args === 'object' && args !== null
|
|
44
|
+
? { id: this.documentId, ...args }
|
|
45
|
+
: { id: this.documentId };
|
|
46
|
+
console.log(`[DefaultExecutor] Calling method with payload:`, payload);
|
|
47
|
+
// Call method with payload object as first parameter
|
|
48
|
+
// Methods will check if first param is object and destructure accordingly
|
|
49
|
+
const methodFn = method;
|
|
50
|
+
const result = await methodFn.call(this.store, payload);
|
|
51
|
+
console.log(`[DefaultExecutor] Result:`, result);
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../src/tools/core/executor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA0BH;;;;;;;;;;GAUG;AACH,MAAM,OAAO,eAAe;IAEhB;IACA;IAFV,YACU,UAAkB,EAClB,KAAqB;QADrB,eAAU,GAAV,UAAU,CAAQ;QAClB,UAAK,GAAL,KAAK,CAAgB;IAC5B,CAAC;IAEJ;;;;;;;OAOG;IACH,KAAK,CAAC,OAAO,CAAC,aAAqB,EAAE,IAAa;QAChD,OAAO,CAAC,GAAG,CACT,gCAAgC,aAAa,kBAAkB,IAAI,CAAC,UAAU,EAAE,CACjF,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,IAAI,CAAC,CAAC;QAE7C,iEAAiE;QACjE,MAAM,MAAM,GAAI,IAAI,CAAC,KAA4C,CAC/D,aAAa,CACd,CAAC;QAEF,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;YACjC,OAAO,CAAC,KAAK,CACX,6BAA6B,aAAa,uBAAuB,CAClE,CAAC;YACF,OAAO,CAAC,KAAK,CACX,sCAAsC,EACtC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAC5B,CAAC,CAAC,EAAE,CAAC,OAAQ,IAAI,CAAC,KAAa,CAAC,CAAC,CAAC,KAAK,UAAU,CAClD,CACF,CAAC;YACF,MAAM,IAAI,KAAK,CACb,iBAAiB,aAAa,+BAA+B,CAC9D,CAAC;QACJ,CAAC;QAED,mEAAmE;QACnE,MAAM,OAAO,GACX,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI;YACvC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,GAAG,IAAI,EAAE;YAClC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC;QAE9B,OAAO,CAAC,GAAG,CAAC,gDAAgD,EAAE,OAAO,CAAC,CAAC;QAEvE,qDAAqD;QACrD,0EAA0E;QAC1E,MAAM,QAAQ,GAAG,MAAuC,CAAC;QACzD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAExD,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,MAAM,CAAC,CAAC;QACjD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format tool response based on requested format.
|
|
3
|
+
*
|
|
4
|
+
* @template T - Type of the data being formatted
|
|
5
|
+
* @param data - Tool result to format
|
|
6
|
+
* @param format - Desired output format ("toon" default, or "json")
|
|
7
|
+
* @returns Formatted response (string for TOON, object for JSON)
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // TOON format (default) - returns human-readable string
|
|
12
|
+
* const toonResult = formatResponse({ success: true, cells: [...] });
|
|
13
|
+
* // Returns: "success: true\ncells:\n - type: code\n source: print('hello')\n..."
|
|
14
|
+
*
|
|
15
|
+
* // JSON format - returns structured object
|
|
16
|
+
* const jsonResult = formatResponse({ success: true, cells: [...] }, "json");
|
|
17
|
+
* // Returns: { success: true, cells: [...] }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatResponse<T>(data: T, format?: 'json' | 'toon'): T | string;
|
|
@@ -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;
|