11/*
2- * Copyright (c) 2021-2025 Datalayer, Inc.
2+ * Copyright (c) 2021-2023 Datalayer, Inc.
33 *
44 * MIT License
55 */
66
77/**
8- * Core interfaces for platform-agnostic tool operations.
9- * These interfaces enable the 3-tier architecture by abstracting
10- * document access and tool execution from specific platforms.
8+ * Core interfaces for Lexical tool operations.
9+ * These interfaces enable platform-agnostic tool execution.
1110 *
1211 * @module tools/core/interfaces
1312 */
1413
15- import type {
16- CellData ,
17- NotebookMetadata ,
18- ExecutionResult ,
19- RuntimeInfo ,
20- } from './types' ;
21-
22- // Re-export types for platform adapters
23- export type { CellData , NotebookMetadata , ExecutionResult , RuntimeInfo } ;
24-
25- // Import Lexical types
2614import type {
2715 LexicalBlock ,
2816 LexicalMetadata ,
2917 RegisteredNodeInfo ,
3018} from './types' ;
31- export type { LexicalBlock , LexicalMetadata , RegisteredNodeInfo } ;
32-
33- /**
34- * Base document handle - common operations for all document types.
35- */
36- export interface DocumentHandle {
37- /**
38- * Get document metadata
39- */
40- getMetadata ( ) : Promise < NotebookMetadata | LexicalMetadata > ;
41-
42- /**
43- * Save the document (optional)
44- */
45- save ?( ) : Promise < void > ;
46-
47- /**
48- * Close the document (optional)
49- */
50- close ?( ) : Promise < void > ;
51- }
52-
53- /**
54- * Notebook document handle - for Jupyter notebooks.
55- *
56- * Platform implementations:
57- * - VS Code: VSCodeDocumentHandle (webview messages)
58- * - SaaS: SaaSDocumentHandle (JupyterLab APIs)
59- */
60- export interface NotebookHandle extends DocumentHandle {
61- /**
62- * Get notebook metadata (narrowed type)
63- */
64- getMetadata ( ) : Promise < NotebookMetadata > ;
65-
66- /**
67- * Get total number of cells in the notebook
68- */
69- getCellCount ( ) : Promise < number > ;
70-
71- /**
72- * Get a specific cell by index
73- */
74- getCell ( index : number ) : Promise < CellData > ;
75-
76- /**
77- * Get all cells from the notebook
78- */
79- getAllCells ( ) : Promise < CellData [ ] > ;
80-
81- /**
82- * Insert a cell at the specified index
83- */
84- insertCell ( index : number , cell : CellData ) : Promise < void > ;
85-
86- /**
87- * Delete a cell at the specified index
88- */
89- deleteCell ( index : number ) : Promise < void > ;
9019
91- /**
92- * Update a cell's source code
93- */
94- updateCell ( index : number , source : string ) : Promise < void > ;
95-
96- /**
97- * Execute a code cell
98- */
99- executeCell ( index : number ) : Promise < ExecutionResult > ;
100- }
101-
102- /**
103- * Lexical document handle - for Lexical rich text documents.
104- *
105- * Platform implementations:
106- * - VS Code: VSCodeLexicalHandle (webview messages)
107- * - SaaS: SaaSLexicalHandle (direct DOM)
108- */
109- export interface LexicalHandle extends DocumentHandle {
110- /**
111- * Get Lexical metadata (narrowed type)
112- */
113- getMetadata ( ) : Promise < LexicalMetadata > ;
114-
115- /**
116- * Get all blocks with their block_id values
117- */
118- getBlocks ( ) : Promise < LexicalBlock [ ] > ;
119-
120- /**
121- * Insert a block after a specific block ID
122- * @param block - Block to insert (block_id will be generated)
123- * @param afterBlockId - Block ID to insert after ('TOP', 'BOTTOM', or actual block_id)
124- */
125- insertBlock ( block : LexicalBlock , afterBlockId : string ) : Promise < void > ;
126-
127- /**
128- * Insert multiple blocks sequentially
129- * @param blocks - Array of blocks to insert
130- * @param afterBlockId - Block ID to insert first block after ('TOP', 'BOTTOM', or actual block_id)
131- */
132- insertBlocks ( blocks : LexicalBlock [ ] , afterBlockId : string ) : Promise < void > ;
133-
134- /**
135- * Delete a block by its ID
136- * @param blockId - ID of the block to delete
137- */
138- deleteBlock ( blockId : string ) : Promise < void > ;
139-
140- /**
141- * Update a block by its ID
142- * @param blockId - ID of the block to update
143- * @param block - New block data
144- */
145- updateBlock ( blockId : string , block : LexicalBlock ) : Promise < void > ;
146-
147- /**
148- * Get registered node types from editor
149- */
150- getAvailableBlockTypes ( ) : Promise < RegisteredNodeInfo [ ] > ;
151- }
152-
153- /**
154- * Type guard for NotebookHandle
155- */
156- export function isNotebookHandle (
157- handle : DocumentHandle | undefined ,
158- ) : handle is NotebookHandle {
159- return handle !== undefined && 'getCellCount' in handle ;
160- }
161-
162- /**
163- * Type guard for LexicalHandle
164- */
165- export function isLexicalHandle (
166- handle : DocumentHandle | undefined ,
167- ) : handle is LexicalHandle {
168- return handle !== undefined && 'getBlocks' in handle ;
169- }
20+ // Re-export types for convenience
21+ export type { LexicalBlock , LexicalMetadata , RegisteredNodeInfo } ;
17022
17123/**
17224 * Base tool execution context - common to all operations
@@ -211,21 +63,6 @@ export interface BaseExecutionContext {
21163 extras ?: Record < string , unknown > ;
21264}
21365
214- /**
215- * Notebook-specific execution context
216- * Used by all notebook cell operations (insert, delete, update, execute, read)
217- */
218- export interface NotebookExecutionContext extends BaseExecutionContext {
219- /**
220- * Notebook ID - universal identifier for both local and remote notebooks
221- * - Local notebooks: Same as file URI (e.g., "file:///path/to/notebook.ipynb")
222- * - Remote notebooks: Datalayer document UID (e.g., "01KAJ42KE2XKM7NBNZV568KXQX")
223- *
224- * This is the same ID used by Notebook2 component: `id={documentId || notebookId}`
225- */
226- notebookId : string ;
227- }
228-
22966/**
23067 * Lexical-specific execution context
23168 * Used by all Lexical block operations (insertBlock, deleteBlock, readBlocks)
@@ -239,33 +76,6 @@ export interface LexicalExecutionContext extends BaseExecutionContext {
23976 lexicalId : string ;
24077}
24178
242- /**
243- * Generic execution context (for operations that don't need documents)
244- * Used by creation tools (createNotebook, startRuntime, etc.)
245- */
246- export interface ToolExecutionContext extends BaseExecutionContext {
247- /**
248- * Optional notebook ID (for notebook-specific operations)
249- * - Local notebooks: Same as file URI (e.g., "file:///path/to/notebook.ipynb")
250- * - Remote notebooks: Datalayer document UID (e.g., "01KAJ42KE2XKM7NBNZV568KXQX")
251- */
252- notebookId ?: string ;
253-
254- /**
255- * Optional lexical document ID (for lexical-specific operations)
256- * - Local documents: Same as file URI (e.g., "file:///path/to/document.lexical")
257- * - Remote documents: Datalayer document UID (e.g., "01KAJ42KE2XKM7NBNZV568KXQX")
258- */
259- lexicalId ?: string ;
260-
261- /**
262- * Optional generic document ID (backwards compatibility)
263- * - For notebooks: Same as notebookId
264- * - For Lexical: Same as lexicalId
265- */
266- documentId ?: string ;
267- }
268-
26979/**
27080 * Core tool operation interface - platform agnostic.
27181 *
@@ -289,11 +99,11 @@ export interface ToolOperation<TParams, TResult> {
28999 * ToolDefinition (schema), not here. Operations are pure implementation.
290100 *
291101 * @param params - Tool-specific parameters
292- * @param context - Execution context (document , SDK, auth)
102+ * @param context - Execution context (lexicalId , SDK, auth)
293103 * @returns Operation result
294104 * @throws Error if operation fails
295105 */
296- execute ( params : TParams , context : ToolExecutionContext ) : Promise < TResult > ;
106+ execute ( params : TParams , context : LexicalExecutionContext ) : Promise < TResult > ;
297107}
298108
299109/**
0 commit comments