@datalayer/core 0.0.19 → 0.0.21

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.
Files changed (129) hide show
  1. package/lib/App.js +0 -5
  2. package/lib/api/iam/datasources.d.ts +86 -0
  3. package/lib/api/iam/datasources.js +185 -0
  4. package/lib/api/iam/index.d.ts +2 -0
  5. package/lib/api/iam/index.js +2 -0
  6. package/lib/api/iam/secrets.d.ts +85 -0
  7. package/lib/api/iam/secrets.js +196 -0
  8. package/lib/client/auth/storage.js +17 -62
  9. package/lib/client/base.d.ts +3 -0
  10. package/lib/client/base.js +2 -2
  11. package/lib/client/index.d.ts +82 -3
  12. package/lib/client/index.js +5 -1
  13. package/lib/client/mixins/IAMMixin.d.ts +62 -0
  14. package/lib/client/mixins/IAMMixin.js +116 -0
  15. package/lib/collaboration/DatalayerCollaboration.d.ts +1 -2
  16. package/lib/collaboration/DatalayerCollaborationProvider.d.ts +1 -1
  17. package/lib/collaboration/DatalayerCollaborationProvider.js +1 -1
  18. package/lib/components/auth/Login.js +0 -5
  19. package/lib/components/auth/index.js +1 -6
  20. package/lib/components/index.d.ts +0 -1
  21. package/lib/components/index.js +0 -1
  22. package/lib/components/toolbars/AssignmentEditorToolbar.js +9 -7
  23. package/lib/examples/CellExample.js +4 -3
  24. package/lib/examples/NotebookExample.js +2 -7
  25. package/lib/hooks/index.d.ts +0 -2
  26. package/lib/hooks/index.js +0 -2
  27. package/lib/hooks/useBackdrop.d.ts +2 -3
  28. package/lib/hooks/useBackdropJupyterLab.d.ts +2 -2
  29. package/lib/hooks/useCache.d.ts +18 -4
  30. package/lib/hooks/useCache.js +87 -69
  31. package/lib/hooks/useScreenshot.d.ts +2 -3
  32. package/lib/hooks/useWindowSize.d.ts +1 -2
  33. package/lib/index.d.ts +2 -1
  34. package/lib/index.js +6 -2
  35. package/lib/main.js +4 -1
  36. package/lib/models/Datasource.d.ts +170 -0
  37. package/lib/models/Datasource.js +140 -0
  38. package/lib/models/Runtime.d.ts +1 -1
  39. package/lib/models/RuntimeSnapshotDTO.d.ts +1 -1
  40. package/lib/models/RuntimeSnapshotDTO.js +1 -1
  41. package/lib/models/Secret.d.ts +159 -0
  42. package/lib/models/Secret.js +135 -0
  43. package/lib/models/SpaceDTO.d.ts +0 -11
  44. package/lib/models/index.d.ts +0 -1
  45. package/lib/models/index.js +0 -1
  46. package/lib/state/substates/IAMState.d.ts +1 -1
  47. package/lib/state/substates/LayoutState.d.ts +2 -2
  48. package/lib/state/substates/NbformatState.d.ts +1 -1
  49. package/lib/state/substates/index.d.ts +0 -1
  50. package/lib/state/substates/index.js +0 -1
  51. package/lib/utils/File.d.ts +1 -1
  52. package/lib/utils/File.js +1 -1
  53. package/lib/utils/Notebook.d.ts +5 -3
  54. package/lib/utils/Notebook.js +5 -3
  55. package/lib/utils/cli/index.js +0 -5
  56. package/lib/utils/cli/query.js +0 -5
  57. package/lib/views/datasources/DatasourceDetail.d.ts +2 -0
  58. package/lib/views/datasources/DatasourceDetail.js +91 -0
  59. package/lib/views/datasources/DatasourceNew.d.ts +2 -0
  60. package/lib/views/datasources/DatasourceNew.js +118 -0
  61. package/lib/views/datasources/Datasources.d.ts +2 -0
  62. package/lib/views/datasources/Datasources.js +49 -0
  63. package/lib/views/datasources/index.d.ts +3 -0
  64. package/lib/views/datasources/index.js +7 -0
  65. package/lib/views/iam-tokens/IAMTokenEdit.d.ts +2 -0
  66. package/lib/views/iam-tokens/IAMTokenEdit.js +86 -0
  67. package/lib/views/iam-tokens/IAMTokenNew.d.ts +2 -0
  68. package/lib/views/iam-tokens/IAMTokenNew.js +118 -0
  69. package/lib/views/iam-tokens/IAMTokens.d.ts +2 -0
  70. package/lib/views/iam-tokens/IAMTokens.js +53 -0
  71. package/lib/views/iam-tokens/Tokens.d.ts +2 -0
  72. package/lib/views/iam-tokens/Tokens.js +53 -0
  73. package/lib/views/iam-tokens/index.d.ts +3 -0
  74. package/lib/views/iam-tokens/index.js +7 -0
  75. package/lib/views/index.d.ts +1 -0
  76. package/lib/views/secrets/SecretEdit.d.ts +2 -0
  77. package/lib/views/secrets/SecretEdit.js +149 -0
  78. package/lib/views/secrets/SecretNew.d.ts +2 -0
  79. package/lib/views/secrets/SecretNew.js +99 -0
  80. package/lib/views/secrets/Secrets.d.ts +2 -0
  81. package/lib/views/secrets/Secrets.js +48 -0
  82. package/lib/views/secrets/index.d.ts +3 -0
  83. package/lib/views/secrets/index.js +7 -0
  84. package/package.json +15 -16
  85. package/patches/.gitkeep +1 -0
  86. package/patches/@datalayer+jupyter-lexical+1.0.7.patch +5491 -0
  87. package/patches/@datalayer+jupyter-react+2.0.1.patch +2674 -0
  88. package/scripts/apply-patches.sh +44 -0
  89. package/scripts/create-patches.sh +40 -0
  90. package/scripts/fix-esm-imports.cjs +124 -0
  91. package/scripts/sync-jupyter.sh +121 -0
  92. package/lib/components/chat/ChatComponent.d.ts +0 -4
  93. package/lib/components/chat/ChatComponent.js +0 -143
  94. package/lib/components/chat/MessagePart.d.ts +0 -11
  95. package/lib/components/chat/MessagePart.js +0 -23
  96. package/lib/components/chat/display/DynamicToolPart.d.ts +0 -6
  97. package/lib/components/chat/display/DynamicToolPart.js +0 -5
  98. package/lib/components/chat/display/ReasoningPart.d.ts +0 -6
  99. package/lib/components/chat/display/ReasoningPart.js +0 -58
  100. package/lib/components/chat/display/TextPart.d.ts +0 -9
  101. package/lib/components/chat/display/TextPart.js +0 -93
  102. package/lib/components/chat/display/ToolPart.d.ts +0 -6
  103. package/lib/components/chat/display/ToolPart.js +0 -148
  104. package/lib/components/chat/display/index.d.ts +0 -4
  105. package/lib/components/chat/display/index.js +0 -13
  106. package/lib/components/chat/handler.d.ts +0 -8
  107. package/lib/components/chat/handler.js +0 -43
  108. package/lib/components/chat/index.d.ts +0 -4
  109. package/lib/components/chat/index.js +0 -13
  110. package/lib/hooks/useAIAgents.d.ts +0 -13
  111. package/lib/hooks/useAIAgents.js +0 -72
  112. package/lib/hooks/useAIJupyterChat.d.ts +0 -36
  113. package/lib/hooks/useAIJupyterChat.js +0 -53
  114. package/lib/hooks/useNotebookAIAgent.d.ts +0 -8
  115. package/lib/hooks/useNotebookAIAgent.js +0 -56
  116. package/lib/models/AIAgent.d.ts +0 -17
  117. package/lib/state/substates/AIAgentState.d.ts +0 -11
  118. package/lib/state/substates/AIAgentState.js +0 -42
  119. package/lib/tools/adapters/agui/AgUIToolAdapter.d.ts +0 -75
  120. package/lib/tools/adapters/agui/AgUIToolAdapter.js +0 -244
  121. package/lib/tools/adapters/agui/index.d.ts +0 -10
  122. package/lib/tools/adapters/agui/index.js +0 -19
  123. package/lib/tools/adapters/agui/lexicalHooks.d.ts +0 -27
  124. package/lib/tools/adapters/agui/lexicalHooks.js +0 -64
  125. package/lib/tools/adapters/agui/notebookHooks.d.ts +0 -27
  126. package/lib/tools/adapters/agui/notebookHooks.js +0 -61
  127. package/lib/tools/index.d.ts +0 -6
  128. package/lib/tools/index.js +0 -18
  129. package/lib/{models/AIAgent.js → views/index.js} +1 -1
@@ -1,75 +0,0 @@
1
- /**
2
- * ag-ui/CopilotKit Tool Adapter
3
- *
4
- * Converts unified tool definitions to CopilotKit's useCopilotAction format.
5
- *
6
- * @see https://docs.copilotkit.ai/langgraph/frontend-actions
7
- * @module tools/adapters/agui/AgUIToolAdapter
8
- */
9
- import type { ToolDefinition, ToolOperation, ToolExecutionContext } from '@datalayer/jupyter-react';
10
- /**
11
- * Type signature for CopilotKit's useFrontendTool hook
12
- * This is shared across both notebook and lexical adapters
13
- */
14
- export type UseFrontendToolFn = (tool: {
15
- name: string;
16
- description: string;
17
- parameters: any;
18
- handler: (params: any) => Promise<string>;
19
- render?: (props: any) => any;
20
- }, dependencies?: any[]) => void;
21
- /**
22
- * Component to register a single action with CopilotKit
23
- * Must be used inside CopilotKit context
24
- */
25
- export declare function ActionRegistrar({ action, useFrontendTool, }: {
26
- action: any;
27
- useFrontendTool: UseFrontendToolFn;
28
- }): null;
29
- /**
30
- * CopilotKit parameter definition (array format, not JSON Schema)
31
- */
32
- export interface CopilotKitParameter {
33
- name: string;
34
- type?: 'string' | 'number' | 'boolean' | 'object' | 'object[]';
35
- description?: string;
36
- required?: boolean;
37
- attributes?: CopilotKitParameter[];
38
- }
39
- /**
40
- * CopilotKit action definition (matches useCopilotAction interface)
41
- */
42
- export interface CopilotKitAction {
43
- /** Action name */
44
- name: string;
45
- /** Description for AI model */
46
- description: string;
47
- /** Parameters array (NOT JSON Schema) */
48
- parameters: CopilotKitParameter[];
49
- /** Handler function */
50
- handler: (params: unknown) => Promise<string>;
51
- /** Optional custom UI renderer */
52
- render?: (props: {
53
- status: string;
54
- args: unknown;
55
- result: unknown;
56
- }) => React.ReactNode;
57
- }
58
- /**
59
- * Converts unified tool definition to CopilotKit action format
60
- *
61
- * @param definition - Tool definition
62
- * @param operation - Core operation
63
- * @param context - Execution context (documentId + executor)
64
- * @returns CopilotKit action
65
- */
66
- export declare function createCopilotKitAction(definition: ToolDefinition, operation: ToolOperation<unknown, unknown>, context: ToolExecutionContext): CopilotKitAction;
67
- /**
68
- * Creates CopilotKit actions from all tool definitions
69
- *
70
- * @param definitions - Tool definitions
71
- * @param operations - Core operations registry
72
- * @param context - Execution context (documentId + executor)
73
- * @returns CopilotKit actions
74
- */
75
- export declare function createAllCopilotKitActions(definitions: ToolDefinition[], operations: Record<string, ToolOperation<unknown, unknown>>, context: ToolExecutionContext): CopilotKitAction[];
@@ -1,244 +0,0 @@
1
- /*
2
- * Copyright (c) 2023-2025 Datalayer, Inc.
3
- * Distributed under the terms of the Modified BSD License.
4
- */
5
- import { OperationRunner } from '@datalayer/jupyter-react';
6
- /**
7
- * Component to register a single action with CopilotKit
8
- * Must be used inside CopilotKit context
9
- */
10
- export function ActionRegistrar({ action, useFrontendTool, }) {
11
- useFrontendTool(action, [action]);
12
- return null;
13
- }
14
- /**
15
- * Deduplication cache to prevent executing the same operation multiple times
16
- * Maps operation signature (hash of tool + params) to timestamp
17
- */
18
- const executionCache = new Map();
19
- const CACHE_TTL_MS = 2000; // 2 seconds - operations within this window are considered duplicates
20
- /**
21
- * Generate a unique signature for an operation call
22
- */
23
- function getOperationSignature(toolName, params) {
24
- return `${toolName}:${JSON.stringify(params)}`;
25
- }
26
- /**
27
- * Check if this operation was recently executed
28
- */
29
- function isRecentDuplicate(toolName, params) {
30
- const signature = getOperationSignature(toolName, params);
31
- const lastExecution = executionCache.get(signature);
32
- if (lastExecution) {
33
- const timeSinceExecution = Date.now() - lastExecution;
34
- if (timeSinceExecution < CACHE_TTL_MS) {
35
- console.log(`[ag-ui] 🚫 DUPLICATE DETECTED - Skipping execution (${timeSinceExecution}ms since last call)`);
36
- return true;
37
- }
38
- }
39
- // Clean up old entries while we're here
40
- for (const [key, timestamp] of executionCache.entries()) {
41
- if (Date.now() - timestamp > CACHE_TTL_MS * 2) {
42
- executionCache.delete(key);
43
- }
44
- }
45
- // Mark this execution
46
- executionCache.set(signature, Date.now());
47
- return false;
48
- }
49
- /**
50
- * Parses array parameters from CopilotKit's string format to actual arrays.
51
- *
52
- * CopilotKit doesn't have native support for primitive arrays, so it sends them
53
- * as JSON strings (e.g., "[1, 2, 3]"). This function parses those strings back
54
- * into actual arrays based on the schema definition.
55
- *
56
- * @param params - Raw parameters from CopilotKit
57
- * @param jsonSchema - JSON Schema definition to identify array parameters
58
- * @returns Parsed parameters with arrays converted from strings
59
- */
60
- function parseArrayParameters(params, jsonSchema) {
61
- if (typeof params !== 'object' || params === null) {
62
- return params;
63
- }
64
- const parsedParams = { ...params };
65
- // Iterate through schema properties to find array types
66
- for (const [name, schema] of Object.entries(jsonSchema.properties || {})) {
67
- const propSchema = schema;
68
- // If this property is an array type and the value is a string, parse it
69
- if (propSchema.type === 'array' && typeof parsedParams[name] === 'string') {
70
- try {
71
- const parsed = JSON.parse(parsedParams[name]);
72
- // Validate it's actually an array after parsing
73
- if (Array.isArray(parsed)) {
74
- parsedParams[name] = parsed;
75
- }
76
- }
77
- catch (error) {
78
- // If parsing fails, log warning but keep original value
79
- console.warn(`[ag-ui] Failed to parse array parameter "${name}":`, error);
80
- }
81
- }
82
- }
83
- return parsedParams;
84
- }
85
- /**
86
- * Converts JSON Schema to CopilotKit parameter array format
87
- *
88
- * @param jsonSchema - JSON Schema parameters object
89
- * @returns CopilotKit parameters array
90
- */
91
- function jsonSchemaToParameters(jsonSchema) {
92
- const parameters = [];
93
- const required = jsonSchema.required || [];
94
- for (const [name, schema] of Object.entries(jsonSchema.properties || {})) {
95
- const propSchema = schema;
96
- // Map JSON Schema type to CopilotKit type
97
- let copilotType = 'string';
98
- if (propSchema.type === 'array') {
99
- // Handle array types based on items type
100
- const itemsType = propSchema.items?.type;
101
- if (itemsType === 'object') {
102
- copilotType = 'object[]';
103
- }
104
- else {
105
- // For primitive arrays (number[], string[], etc.)
106
- // CopilotKit doesn't have explicit support, but we can use the description
107
- // to clarify and handle parsing in the handler
108
- copilotType = 'string'; // Will be parsed as JSON array string
109
- // Enhance description to clarify it's an array
110
- propSchema.description =
111
- `${propSchema.description || ''} (JSON array of ${itemsType || 'values'})`.trim();
112
- }
113
- }
114
- else {
115
- // Original logic for non-array types
116
- copilotType =
117
- propSchema.type || 'string';
118
- }
119
- const param = {
120
- name,
121
- type: copilotType,
122
- description: propSchema.description,
123
- required: required.includes(name),
124
- };
125
- // Handle nested object properties (for object types)
126
- if (propSchema.type === 'object' && propSchema.properties) {
127
- // Cast to proper type for recursive call
128
- param.attributes = jsonSchemaToParameters({
129
- type: 'object',
130
- properties: propSchema.properties, // eslint-disable-line @typescript-eslint/no-explicit-any
131
- required: propSchema.required || [],
132
- });
133
- }
134
- parameters.push(param);
135
- }
136
- console.log('[ag-ui] Converted parameters:', JSON.stringify(parameters, null, 2));
137
- return parameters;
138
- }
139
- /**
140
- * Converts unified tool definition to CopilotKit action format
141
- *
142
- * @param definition - Tool definition
143
- * @param operation - Core operation
144
- * @param context - Execution context (documentId + executor)
145
- * @returns CopilotKit action
146
- */
147
- export function createCopilotKitAction(definition, operation, context) {
148
- // Create runner instance for this action
149
- const runner = new OperationRunner();
150
- const action = {
151
- name: definition.toolReferenceName || definition.name,
152
- description: definition.description,
153
- parameters: jsonSchemaToParameters(definition.parameters),
154
- // CRITICAL FIX: Set to true to enable CopilotKit's deduplication mechanism
155
- // See https://github.com/CopilotKit/CopilotKit/issues/2310
156
- // Without this, actions get re-executed cumulatively (A → A,B → A,B,C)
157
- _isRenderAndWait: true,
158
- handler: async (params) => {
159
- console.log(`[ag-ui] ========== HANDLER CALLED ==========`);
160
- console.log(`[ag-ui] Tool: ${definition.name}`);
161
- console.log(`[ag-ui] Operation: ${definition.operation}`);
162
- console.log(`[ag-ui] Params:`, params);
163
- console.log(`[ag-ui] Context:`, context);
164
- // Check for duplicate execution
165
- const signature = `${definition.name}:${JSON.stringify(params)}`;
166
- console.log(`[ag-ui] 🔍 Signature:`, signature.substring(0, 150));
167
- if (isRecentDuplicate(definition.name, params)) {
168
- console.log(`[ag-ui] 🚫 DUPLICATE DETECTED - Returning early`);
169
- return 'Operation already executed recently (duplicate detected and skipped)';
170
- }
171
- console.log(`[ag-ui] ✅ NOT a duplicate - Proceeding with execution`);
172
- try {
173
- // Parse array parameters that CopilotKit sends as JSON strings
174
- // CopilotKit doesn't have native support for primitive arrays, so they're sent as strings
175
- const parsedParams = parseArrayParameters(params, definition.parameters);
176
- console.log(`[ag-ui] Calling runner.execute with TOON format...`);
177
- console.log(`[ag-ui] Operation name:`, operation);
178
- console.log(`[ag-ui] Parsed params being passed:`, JSON.stringify(parsedParams, null, 2));
179
- console.log(`[ag-ui] Context being passed:`, JSON.stringify(context, null, 2));
180
- // Use OperationRunner to execute operation with TOON format
181
- // TOON format returns human/LLM-readable string (default)
182
- const result = await runner.execute(operation, parsedParams, {
183
- ...context,
184
- format: 'toon', // CopilotKit expects string responses
185
- });
186
- console.log(`[ag-ui] Operation result:`, result);
187
- // Result is already a string (TOON format)
188
- if (typeof result === 'string') {
189
- return result;
190
- }
191
- // Fallback: if somehow we got an object (shouldn't happen with format='toon')
192
- if (typeof result === 'object' && result !== null) {
193
- const resultObj = result;
194
- // Return success message if available
195
- if (resultObj.message) {
196
- return resultObj.message;
197
- }
198
- // Return error if failed
199
- if (resultObj.success === false && resultObj.error) {
200
- return `❌ Error: ${resultObj.error}`;
201
- }
202
- // Otherwise format as JSON
203
- return JSON.stringify(result, null, 2);
204
- }
205
- return String(result);
206
- }
207
- catch (error) {
208
- console.error(`[ag-ui] ❌ ERROR in handler:`, error);
209
- console.error(`[ag-ui] Error stack:`, error instanceof Error ? error.stack : 'N/A');
210
- const errorMessage = error instanceof Error ? error.message : String(error);
211
- return `❌ Error: ${errorMessage}`;
212
- }
213
- },
214
- // Optional: Custom render function for ag-ui
215
- // Note: config supports platform-specific extensions, cast to any for flexibility
216
- render: definition.config?.agui?.renderingHints?.customRender
217
- ? definition.config.agui.renderingHints
218
- .customRender
219
- : undefined,
220
- };
221
- return action;
222
- }
223
- /**
224
- * Creates CopilotKit actions from all tool definitions
225
- *
226
- * @param definitions - Tool definitions
227
- * @param operations - Core operations registry
228
- * @param context - Execution context (documentId + executor)
229
- * @returns CopilotKit actions
230
- */
231
- export function createAllCopilotKitActions(definitions, operations, context) {
232
- const actions = [];
233
- for (const definition of definitions) {
234
- const operation = operations[definition.operation];
235
- if (!operation) {
236
- console.warn(`[ag-ui Tools] No operation found for ${definition.name} (operation: ${definition.operation})`);
237
- continue;
238
- }
239
- const action = createCopilotKitAction(definition, operation, context);
240
- actions.push(action);
241
- }
242
- console.log(`[ag-ui Tools] Created ${actions.length} CopilotKit actions`);
243
- return actions;
244
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * ag-ui/CopilotKit adapter module.
3
- * Exports: CopilotKit adapters, hooks (useNotebookToolActions, useLexicalToolActions).
4
- * Note: DefaultExecutor is imported from datalayer-react/tools/core/executor
5
- *
6
- * @module tools/adapters/agui
7
- */
8
- export * from './AgUIToolAdapter';
9
- export * from './notebookHooks';
10
- export * from './lexicalHooks';
@@ -1,19 +0,0 @@
1
- /*
2
- * Copyright (c) 2023-2025 Datalayer, Inc.
3
- * Distributed under the terms of the Modified BSD License.
4
- */
5
- /*
6
- * Copyright (c) 2021-2025 Datalayer, Inc.
7
- *
8
- * MIT License
9
- */
10
- /**
11
- * ag-ui/CopilotKit adapter module.
12
- * Exports: CopilotKit adapters, hooks (useNotebookToolActions, useLexicalToolActions).
13
- * Note: DefaultExecutor is imported from datalayer-react/tools/core/executor
14
- *
15
- * @module tools/adapters/agui
16
- */
17
- export * from './AgUIToolAdapter';
18
- export * from './notebookHooks';
19
- export * from './lexicalHooks';
@@ -1,27 +0,0 @@
1
- import { createAllCopilotKitActions, ActionRegistrar, type UseFrontendToolFn } from './AgUIToolAdapter';
2
- type ToolExecutionContext = any;
3
- export { ActionRegistrar, type UseFrontendToolFn };
4
- /**
5
- * Hook that creates CopilotKit actions for lexical tools.
6
- * Returns stable actions array that won't cause re-renders.
7
- *
8
- * @param documentId - Document ID (lexical document identifier)
9
- * @param contextOverrides - Optional context overrides (format, extras, etc.)
10
- * @returns CopilotKit actions
11
- *
12
- * @example
13
- * ```typescript
14
- * // Default context (toon format for AI)
15
- * const actions = useLexicalToolActions("doc-123");
16
- *
17
- * // Custom format
18
- * const actions = useLexicalToolActions("doc-123", { format: 'json' });
19
- *
20
- * // With extras
21
- * const actions = useLexicalToolActions("doc-123", {
22
- * format: 'toon',
23
- * extras: { userId: '123', theme: 'dark' }
24
- * });
25
- * ```
26
- */
27
- export declare function useLexicalToolActions(documentId: string, contextOverrides?: Partial<Omit<ToolExecutionContext, 'executor' | 'documentId'>>): ReturnType<typeof createAllCopilotKitActions>;
@@ -1,64 +0,0 @@
1
- /*
2
- * Copyright (c) 2023-2025 Datalayer, Inc.
3
- * Distributed under the terms of the Modified BSD License.
4
- */
5
- /**
6
- * React hooks and components for ag-ui (CopilotKit) lexical tool registration.
7
- * Provides: useLexicalToolActions, ActionRegistrar, UseFrontendToolFn.
8
- *
9
- * @module tools/adapters/agui/lexicalHooks
10
- */
11
- import { useMemo } from 'react';
12
- // TODO: Re-enable when @datalayer/jupyter-react exports these
13
- // import type { ToolExecutionContext } from '@datalayer/jupyter-react';
14
- import { createAllCopilotKitActions, ActionRegistrar, } from './AgUIToolAdapter';
15
- // TODO: Re-enable when @datalayer/jupyter-react exports these
16
- // import type { ToolExecutionContext } from '@datalayer/jupyter-react';
17
- // Import from patched @datalayer/jupyter-lexical package
18
- import { useLexicalStore, DefaultExecutor as LexicalDefaultExecutor, lexicalToolDefinitions, lexicalToolOperations, } from '@datalayer/jupyter-lexical';
19
- // Re-export shared types and components for convenience
20
- export { ActionRegistrar };
21
- /**
22
- * Hook that creates CopilotKit actions for lexical tools.
23
- * Returns stable actions array that won't cause re-renders.
24
- *
25
- * @param documentId - Document ID (lexical document identifier)
26
- * @param contextOverrides - Optional context overrides (format, extras, etc.)
27
- * @returns CopilotKit actions
28
- *
29
- * @example
30
- * ```typescript
31
- * // Default context (toon format for AI)
32
- * const actions = useLexicalToolActions("doc-123");
33
- *
34
- * // Custom format
35
- * const actions = useLexicalToolActions("doc-123", { format: 'json' });
36
- *
37
- * // With extras
38
- * const actions = useLexicalToolActions("doc-123", {
39
- * format: 'toon',
40
- * extras: { userId: '123', theme: 'dark' }
41
- * });
42
- * ```
43
- */
44
- export function useLexicalToolActions(documentId, contextOverrides) {
45
- // Call useLexicalStore() with no selector to get state object (matches notebook pattern)
46
- const lexicalStoreState = useLexicalStore();
47
- // Create LexicalDefaultExecutor (stable reference)
48
- // Only recreate when documentId changes, not on every state update
49
- // The executor holds a reference to the store which is always current
50
- const executor = useMemo(() => new LexicalDefaultExecutor(documentId, lexicalStoreState), [documentId]);
51
- // Create stable context object with useMemo
52
- // Defaults: format='toon' for conversational AI responses
53
- // Can be overridden with contextOverrides parameter
54
- const context = useMemo(() => ({
55
- documentId,
56
- executor,
57
- format: 'toon', // Default format
58
- ...contextOverrides, // Override with user-provided values
59
- }), [documentId, executor, contextOverrides]);
60
- // Create and return CopilotKit actions (stable reference)
61
- // Only re-create when context changes (i.e., when documentId or contextOverrides change)
62
- const actions = useMemo(() => createAllCopilotKitActions(lexicalToolDefinitions, lexicalToolOperations, context), [context]);
63
- return actions;
64
- }
@@ -1,27 +0,0 @@
1
- import { createAllCopilotKitActions, ActionRegistrar, type UseFrontendToolFn } from './AgUIToolAdapter';
2
- type ToolExecutionContext = any;
3
- export { ActionRegistrar, type UseFrontendToolFn };
4
- /**
5
- * Hook that creates CopilotKit actions for notebook tools.
6
- * Returns stable actions array that won't cause re-renders.
7
- *
8
- * @param documentId - Document ID (notebook identifier)
9
- * @param contextOverrides - Optional context overrides (format, extras, etc.)
10
- * @returns CopilotKit actions
11
- *
12
- * @example
13
- * ```typescript
14
- * // Default context (toon format for AI)
15
- * const actions = useNotebookToolActions("my-notebook-id");
16
- *
17
- * // Custom format
18
- * const actions = useNotebookToolActions("my-notebook-id", { format: 'json' });
19
- *
20
- * // With extras
21
- * const actions = useNotebookToolActions("my-notebook-id", {
22
- * format: 'toon',
23
- * extras: { userId: '123', theme: 'dark' }
24
- * });
25
- * ```
26
- */
27
- export declare function useNotebookToolActions(documentId: string, contextOverrides?: Partial<Omit<ToolExecutionContext, 'executor' | 'documentId'>>): ReturnType<typeof createAllCopilotKitActions>;
@@ -1,61 +0,0 @@
1
- /*
2
- * Copyright (c) 2023-2025 Datalayer, Inc.
3
- * Distributed under the terms of the Modified BSD License.
4
- */
5
- /**
6
- * React hooks and components for ag-ui (CopilotKit) notebook tool registration.
7
- * Provides: useNotebookToolActions, ActionRegistrar, UseFrontendToolFn.
8
- *
9
- * @module tools/adapters/agui/notebookHooks
10
- */
11
- import { useMemo } from 'react';
12
- // TODO: Re-enable when @datalayer/jupyter-react exports these
13
- // import type { ToolExecutionContext } from '@datalayer/jupyter-react';
14
- import { createAllCopilotKitActions, ActionRegistrar, } from './AgUIToolAdapter';
15
- // Import from patched @datalayer/jupyter-react package
16
- import { notebookStore2, DefaultExecutor, notebookToolDefinitions, notebookToolOperations, } from '@datalayer/jupyter-react';
17
- // Hook wrapper to get notebook store state
18
- const useNotebookStore2 = () => notebookStore2.getState();
19
- // Re-export shared types and components for convenience
20
- export { ActionRegistrar };
21
- /**
22
- * Hook that creates CopilotKit actions for notebook tools.
23
- * Returns stable actions array that won't cause re-renders.
24
- *
25
- * @param documentId - Document ID (notebook identifier)
26
- * @param contextOverrides - Optional context overrides (format, extras, etc.)
27
- * @returns CopilotKit actions
28
- *
29
- * @example
30
- * ```typescript
31
- * // Default context (toon format for AI)
32
- * const actions = useNotebookToolActions("my-notebook-id");
33
- *
34
- * // Custom format
35
- * const actions = useNotebookToolActions("my-notebook-id", { format: 'json' });
36
- *
37
- * // With extras
38
- * const actions = useNotebookToolActions("my-notebook-id", {
39
- * format: 'toon',
40
- * extras: { userId: '123', theme: 'dark' }
41
- * });
42
- * ```
43
- */
44
- export function useNotebookToolActions(documentId, contextOverrides) {
45
- const notebookStore = useNotebookStore2();
46
- // Create DefaultExecutor (stable reference)
47
- // Only recreate when documentId changes, not on every state update
48
- // The executor holds a reference to the store which is always current
49
- const executor = useMemo(() => new DefaultExecutor(documentId, notebookStore), [documentId]);
50
- // Create stable context object with useMemo
51
- // Defaults: format='toon' for conversational AI responses
52
- // Can be overridden with contextOverrides parameter
53
- const context = useMemo(() => ({
54
- documentId,
55
- executor,
56
- format: 'toon', // Default format
57
- ...contextOverrides, // Override with user-provided values
58
- }), [documentId, executor, contextOverrides]);
59
- // Create and return CopilotKit actions (stable reference)
60
- return useMemo(() => createAllCopilotKitActions(notebookToolDefinitions, notebookToolOperations, context), [context]);
61
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * Platform-agnostic tools for notebook and lexical integration with AI frameworks
3
- *
4
- * @module tools
5
- */
6
- export * from './adapters/agui';
@@ -1,18 +0,0 @@
1
- /*
2
- * Copyright (c) 2023-2025 Datalayer, Inc.
3
- * Distributed under the terms of the Modified BSD License.
4
- */
5
- /**
6
- * Platform-agnostic tools for notebook and lexical integration with AI frameworks
7
- *
8
- * @module tools
9
- */
10
- // Export adapters
11
- export * from './adapters/agui';
12
- // TODO: Re-export tool types from jupyter-react when available
13
- // export type {
14
- // ToolDefinition,
15
- // ToolConfig,
16
- // ToolOperation,
17
- // ToolExecutionContext,
18
- // } from '@datalayer/jupyter-react';
@@ -1,5 +1,5 @@
1
+ export {};
1
2
  /*
2
3
  * Copyright (c) 2023-2025 Datalayer, Inc.
3
4
  * Distributed under the terms of the Modified BSD License.
4
5
  */
5
- export {};