Skip to content

Commit 3ba4e47

Browse files
committed
test
1 parent 1a084e8 commit 3ba4e47

31 files changed

+52
-460
lines changed

packages/lexical/scripts/validate-tools-sync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22
/*
3-
* Copyright (c) 2021-2025 Datalayer, Inc.
3+
* Copyright (c) 2021-2023 Datalayer, Inc.
44
*
55
* MIT License
66
*/

packages/lexical/src/state/LexicalAdapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021-2025 Datalayer, Inc.
2+
* Copyright (c) 2021-2023 Datalayer, Inc.
33
*
44
* MIT License
55
*/

packages/lexical/src/state/LexicalState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021-2025 Datalayer, Inc.
2+
* Copyright (c) 2021-2023 Datalayer, Inc.
33
*
44
* MIT License
55
*/

packages/lexical/src/state/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021-2025 Datalayer, Inc.
2+
* Copyright (c) 2021-2023 Datalayer, Inc.
33
*
44
* MIT License
55
*/

packages/lexical/src/tools/core/executor.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
* @module tools/core/executor
1212
*/
1313

14-
// NOTE: This executor is designed for notebooks, not lexical documents
15-
// Commenting out for now as this import doesn't exist in lexical package
16-
// import type { Notebook2State } from '../../components/notebook/Notebook2State';
14+
import type { LexicalState } from '../../state/LexicalState';
1715

1816
/**
1917
* Tool executor interface - abstracts how operations are executed.
@@ -23,39 +21,36 @@ export interface ToolExecutor {
2321
/**
2422
* Execute a tool operation
2523
*
26-
* @param operationName - Name of the operation (e.g., "insertCell", "runCell")
24+
* @param operationName - Name of the operation (e.g., "insertBlock", "runBlock")
2725
* @param args - Operation arguments
2826
* @returns Result from execution
2927
*/
3028
execute(operationName: string, args: unknown): Promise<unknown>;
3129
}
3230

3331
/**
34-
* Default executor - directly calls Notebook2State store methods.
32+
* Default executor - directly calls LexicalState store methods.
3533
* Uses 1:1 mapping between operation names and store methods with no transformation.
3634
*
37-
* NOTE: This class is designed for notebooks, not lexical documents.
38-
* It's kept here for reference but may need adaptation for lexical use.
39-
*
4035
* @example
4136
* ```typescript
42-
* const executor = new DefaultExecutor(notebookId, notebookStore);
43-
* await executor.execute("insertCell", { type: "code", source: "print('hi')" });
37+
* const executor = new DefaultExecutor(lexicalId, lexicalStore);
38+
* await executor.execute("insertBlock", { type: "paragraph", source: "Hello world" });
4439
* ```
4540
*/
4641
export class DefaultExecutor implements ToolExecutor {
4742
constructor(
48-
private notebookId: string,
49-
private store: any, // Notebook2State - commented out as it doesn't exist in lexical package
43+
private lexicalId: string,
44+
private store: LexicalState,
5045
) {}
5146

5247
/**
53-
* Execute an operation by directly calling the corresponding Notebook2State method.
48+
* Execute an operation by directly calling the corresponding LexicalState method.
5449
*
55-
* Operation names map 1:1 to Notebook2State method names (e.g., "insertCell" → store.insertCell).
56-
* All args are passed directly to the store method with notebookId injected.
50+
* Operation names map 1:1 to LexicalState method names (e.g., "insertBlock" → store.insertBlock).
51+
* All args are passed directly to the store method with lexicalId injected.
5752
*
58-
* @param operationName - Name of the operation (e.g., "insertCell", "runCell")
53+
* @param operationName - Name of the operation (e.g., "insertBlock", "runBlock")
5954
* @param args - Operation arguments (passed directly to store method)
6055
* @returns Result from store method
6156
*/
@@ -71,11 +66,11 @@ export class DefaultExecutor implements ToolExecutor {
7166
);
7267
}
7368

74-
// Inject notebookId into args and call store method
69+
// Inject lexicalId into args and call store method
7570
const payload =
7671
typeof args === 'object' && args !== null
77-
? { id: this.notebookId, ...args }
78-
: { id: this.notebookId };
72+
? { id: this.lexicalId, ...args }
73+
: { id: this.lexicalId };
7974

8075
return await (method as (args: unknown) => Promise<unknown>).call(
8176
this.store,

packages/lexical/src/tools/core/formatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021-2025 Datalayer, Inc.
2+
* Copyright (c) 2021-2023 Datalayer, Inc.
33
*
44
* MIT License
55
*/

packages/lexical/src/tools/core/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021-2025 Datalayer, Inc.
2+
* Copyright (c) 2021-2023 Datalayer, Inc.
33
*
44
* MIT License
55
*/

packages/lexical/src/tools/core/interfaces.ts

Lines changed: 7 additions & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -1,172 +1,24 @@
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
2614
import 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

Comments
 (0)