@jupyterlite/ai 0.9.1 → 0.11.0

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 (71) hide show
  1. package/README.md +5 -214
  2. package/lib/agent.d.ts +58 -66
  3. package/lib/agent.js +291 -310
  4. package/lib/approval-buttons.d.ts +19 -82
  5. package/lib/approval-buttons.js +36 -289
  6. package/lib/chat-model-registry.d.ts +6 -0
  7. package/lib/chat-model-registry.js +4 -1
  8. package/lib/chat-model.d.ts +26 -54
  9. package/lib/chat-model.js +277 -303
  10. package/lib/components/clear-button.d.ts +6 -1
  11. package/lib/components/clear-button.js +10 -6
  12. package/lib/components/completion-status.d.ts +5 -0
  13. package/lib/components/completion-status.js +5 -4
  14. package/lib/components/model-select.d.ts +6 -1
  15. package/lib/components/model-select.js +13 -16
  16. package/lib/components/stop-button.d.ts +6 -1
  17. package/lib/components/stop-button.js +12 -8
  18. package/lib/components/token-usage-display.d.ts +5 -0
  19. package/lib/components/token-usage-display.js +2 -2
  20. package/lib/components/tool-select.d.ts +6 -1
  21. package/lib/components/tool-select.js +10 -9
  22. package/lib/index.d.ts +1 -0
  23. package/lib/index.js +61 -81
  24. package/lib/models/settings-model.d.ts +1 -1
  25. package/lib/models/settings-model.js +40 -26
  26. package/lib/providers/built-in-providers.js +38 -19
  27. package/lib/providers/models.d.ts +3 -3
  28. package/lib/providers/provider-registry.d.ts +3 -4
  29. package/lib/providers/provider-registry.js +1 -4
  30. package/lib/tokens.d.ts +5 -6
  31. package/lib/tools/commands.d.ts +2 -1
  32. package/lib/tools/commands.js +36 -49
  33. package/lib/widgets/ai-settings.d.ts +6 -0
  34. package/lib/widgets/ai-settings.js +72 -71
  35. package/lib/widgets/main-area-chat.d.ts +2 -0
  36. package/lib/widgets/main-area-chat.js +5 -2
  37. package/lib/widgets/provider-config-dialog.d.ts +2 -0
  38. package/lib/widgets/provider-config-dialog.js +34 -34
  39. package/package.json +13 -13
  40. package/schema/settings-model.json +3 -2
  41. package/src/agent.ts +360 -372
  42. package/src/approval-buttons.ts +43 -389
  43. package/src/chat-model-registry.ts +9 -1
  44. package/src/chat-model.ts +399 -370
  45. package/src/completion/completion-provider.ts +2 -3
  46. package/src/components/clear-button.tsx +18 -6
  47. package/src/components/completion-status.tsx +18 -4
  48. package/src/components/model-select.tsx +25 -16
  49. package/src/components/stop-button.tsx +22 -9
  50. package/src/components/token-usage-display.tsx +14 -2
  51. package/src/components/tool-select.tsx +27 -9
  52. package/src/index.ts +78 -134
  53. package/src/models/settings-model.ts +41 -27
  54. package/src/providers/built-in-providers.ts +38 -19
  55. package/src/providers/models.ts +3 -3
  56. package/src/providers/provider-registry.ts +4 -8
  57. package/src/tokens.ts +5 -6
  58. package/src/tools/commands.ts +40 -53
  59. package/src/widgets/ai-settings.tsx +153 -84
  60. package/src/widgets/main-area-chat.ts +8 -2
  61. package/src/widgets/provider-config-dialog.tsx +54 -41
  62. package/style/base.css +24 -73
  63. package/lib/mcp/browser.d.ts +0 -68
  64. package/lib/mcp/browser.js +0 -138
  65. package/lib/tools/file.d.ts +0 -36
  66. package/lib/tools/file.js +0 -351
  67. package/lib/tools/notebook.d.ts +0 -40
  68. package/lib/tools/notebook.js +0 -779
  69. package/src/mcp/browser.ts +0 -220
  70. package/src/tools/file.ts +0 -438
  71. package/src/tools/notebook.ts +0 -986
package/lib/tools/file.js DELETED
@@ -1,351 +0,0 @@
1
- import { PathExt } from '@jupyterlab/coreutils';
2
- import { tool } from '@openai/agents';
3
- import { z } from 'zod';
4
- /**
5
- * Create a tool for creating new files of various types
6
- */
7
- export function createNewFileTool(docManager) {
8
- return tool({
9
- name: 'create_file',
10
- description: 'Create a new file of specified type (text, python, markdown, json, etc.)',
11
- parameters: z.object({
12
- fileName: z.string().describe('Name of the file to create'),
13
- fileType: z
14
- .string()
15
- .default('text')
16
- .describe('Type of file to create. Common examples: text, python, markdown, json, javascript, typescript, yaml, julia, r, csv'),
17
- content: z
18
- .string()
19
- .optional()
20
- .nullable()
21
- .describe('Initial content for the file (optional)'),
22
- cwd: z
23
- .string()
24
- .optional()
25
- .nullable()
26
- .describe('Directory where to create the file (optional)')
27
- }),
28
- errorFunction: (context, error) => {
29
- return JSON.stringify({
30
- success: false,
31
- error: `Failed to create file: ${error instanceof Error ? error.message : String(error)}`
32
- });
33
- },
34
- execute: async (input) => {
35
- const { fileName, content = '', cwd, fileType = 'text' } = input;
36
- const registeredFileType = docManager.registry.getFileType(fileType);
37
- const ext = registeredFileType?.extensions[0] || '.txt';
38
- const existingExt = PathExt.extname(fileName);
39
- const fullFileName = existingExt ? fileName : `${fileName}${ext}`;
40
- const fullPath = cwd ? `${cwd}/${fullFileName}` : fullFileName;
41
- const model = await docManager.services.contents.newUntitled({
42
- path: cwd || '',
43
- type: 'file',
44
- ext
45
- });
46
- let finalPath = model.path;
47
- if (model.name !== fullFileName) {
48
- const renamed = await docManager.services.contents.rename(model.path, fullPath);
49
- finalPath = renamed.path;
50
- }
51
- if (content) {
52
- await docManager.services.contents.save(finalPath, {
53
- type: 'file',
54
- format: 'text',
55
- content
56
- });
57
- }
58
- let opened = false;
59
- if (!docManager.findWidget(finalPath)) {
60
- docManager.openOrReveal(finalPath);
61
- opened = true;
62
- }
63
- return {
64
- success: true,
65
- message: `${fileType} file '${fullFileName}' created and opened successfully`,
66
- fileName: fullFileName,
67
- filePath: finalPath,
68
- fileType,
69
- hasContent: !!content,
70
- opened
71
- };
72
- }
73
- });
74
- }
75
- /**
76
- * Create a tool for opening files
77
- */
78
- export function createOpenFileTool(docManager) {
79
- return tool({
80
- name: 'open_file',
81
- description: 'Open a file in the editor',
82
- parameters: z.object({
83
- filePath: z.string().describe('Path to the file to open')
84
- }),
85
- errorFunction: (context, error) => {
86
- return JSON.stringify({
87
- success: false,
88
- error: `Failed to open file: ${error instanceof Error ? error.message : String(error)}`
89
- });
90
- },
91
- execute: async (input) => {
92
- const { filePath } = input;
93
- const widget = docManager.openOrReveal(filePath);
94
- if (!widget) {
95
- throw new Error(`Could not open file: ${filePath}`);
96
- }
97
- return {
98
- success: true,
99
- message: `File '${filePath}' opened successfully`,
100
- filePath,
101
- widgetId: widget.id
102
- };
103
- }
104
- });
105
- }
106
- /**
107
- * Create a tool for deleting files
108
- */
109
- export function createDeleteFileTool(docManager) {
110
- return tool({
111
- name: 'delete_file',
112
- description: 'Delete a file from the file system',
113
- parameters: z.object({
114
- filePath: z.string().describe('Path to the file to delete')
115
- }),
116
- errorFunction: (context, error) => {
117
- return JSON.stringify({
118
- success: false,
119
- error: `Failed to delete file: ${error instanceof Error ? error.message : String(error)}`
120
- });
121
- },
122
- execute: async (input) => {
123
- const { filePath } = input;
124
- await docManager.services.contents.delete(filePath);
125
- return {
126
- success: true,
127
- message: `File '${filePath}' deleted successfully`,
128
- filePath
129
- };
130
- }
131
- });
132
- }
133
- /**
134
- * Create a tool for renaming files
135
- */
136
- export function createRenameFileTool(docManager) {
137
- return tool({
138
- name: 'rename_file',
139
- description: 'Rename a file or move it to a different location',
140
- parameters: z.object({
141
- oldPath: z.string().describe('Current path of the file'),
142
- newPath: z.string().describe('New path/name for the file')
143
- }),
144
- errorFunction: (context, error) => {
145
- return JSON.stringify({
146
- success: false,
147
- error: `Failed to rename file: ${error instanceof Error ? error.message : String(error)}`
148
- });
149
- },
150
- execute: async (input) => {
151
- const { oldPath, newPath } = input;
152
- await docManager.services.contents.rename(oldPath, newPath);
153
- return {
154
- success: true,
155
- message: `File renamed from '${oldPath}' to '${newPath}' successfully`,
156
- oldPath,
157
- newPath
158
- };
159
- }
160
- });
161
- }
162
- /**
163
- * Create a tool for copying files
164
- */
165
- export function createCopyFileTool(docManager) {
166
- return tool({
167
- name: 'copy_file',
168
- description: 'Copy a file to a new location',
169
- parameters: z.object({
170
- sourcePath: z.string().describe('Path of the file to copy'),
171
- destinationPath: z
172
- .string()
173
- .describe('Destination path for the copied file')
174
- }),
175
- errorFunction: (context, error) => {
176
- return JSON.stringify({
177
- success: false,
178
- error: `Failed to copy file: ${error instanceof Error ? error.message : String(error)}`
179
- });
180
- },
181
- execute: async (input) => {
182
- const { sourcePath, destinationPath } = input;
183
- await docManager.services.contents.copy(sourcePath, destinationPath);
184
- return {
185
- success: true,
186
- message: `File copied from '${sourcePath}' to '${destinationPath}' successfully`,
187
- sourcePath,
188
- destinationPath
189
- };
190
- }
191
- });
192
- }
193
- /**
194
- * Create a tool for navigating to directories in the file browser
195
- */
196
- export function createNavigateToDirectoryTool(commands) {
197
- return tool({
198
- name: 'navigate_to_directory',
199
- description: 'Navigate to a specific directory in the file browser',
200
- parameters: z.object({
201
- directoryPath: z.string().describe('Path to the directory to navigate to')
202
- }),
203
- errorFunction: (context, error) => {
204
- return JSON.stringify({
205
- success: false,
206
- error: `Failed to navigate to directory: ${error instanceof Error ? error.message : String(error)}`
207
- });
208
- },
209
- execute: async (input) => {
210
- const { directoryPath } = input;
211
- await commands.execute('filebrowser:go-to-path', {
212
- path: directoryPath
213
- });
214
- return {
215
- success: true,
216
- message: `Navigated to directory '${directoryPath}' successfully`,
217
- directoryPath
218
- };
219
- }
220
- });
221
- }
222
- /**
223
- * Create a tool for getting file information and content
224
- */
225
- export function createGetFileInfoTool(docManager, editorTracker) {
226
- return tool({
227
- name: 'get_file_info',
228
- description: 'Get information about a file including its path, name, extension, and content. Works with text-based files like Python files, markdown, JSON, etc. For Jupyter notebooks, use dedicated notebook tools instead. If no file path is provided, returns information about the currently active file in the editor.',
229
- parameters: z.object({
230
- filePath: z
231
- .string()
232
- .optional()
233
- .nullable()
234
- .describe('Path to the file to read (e.g., "script.py", "README.md", "config.json"). If not provided, uses the currently active file in the editor.')
235
- }),
236
- errorFunction: (context, error) => {
237
- return JSON.stringify({
238
- success: false,
239
- error: `Failed to get file info: ${error instanceof Error ? error.message : String(error)}`
240
- });
241
- },
242
- execute: async (input) => {
243
- const { filePath } = input;
244
- let widget = null;
245
- if (filePath) {
246
- widget =
247
- docManager.findWidget(filePath) ??
248
- docManager.openOrReveal(filePath) ??
249
- null;
250
- if (!widget) {
251
- throw new Error(`Failed to open file at path: ${filePath}`);
252
- }
253
- }
254
- else {
255
- widget = editorTracker?.currentWidget ?? null;
256
- if (!widget) {
257
- throw new Error('No active file in the editor and no file path provided');
258
- }
259
- }
260
- if (!widget.context) {
261
- throw new Error('Widget is not a document');
262
- }
263
- await widget.context.ready;
264
- const model = widget.context.model;
265
- if (!model) {
266
- throw new Error('File model not available');
267
- }
268
- const sharedModel = model.sharedModel;
269
- const content = sharedModel.getSource();
270
- const resolvedFilePath = widget.context.path;
271
- const fileName = widget.title.label;
272
- const fileExtension = PathExt.extname(resolvedFilePath) || 'unknown';
273
- return JSON.stringify({
274
- success: true,
275
- filePath: resolvedFilePath,
276
- fileName,
277
- fileExtension,
278
- content,
279
- isDirty: model.dirty,
280
- readOnly: model.readOnly,
281
- widgetType: widget.constructor.name
282
- });
283
- }
284
- });
285
- }
286
- /**
287
- * Create a tool for setting the content of a file
288
- */
289
- export function createSetFileContentTool(docManager, diffManager) {
290
- return tool({
291
- name: 'set_file_content',
292
- description: 'Set or update the content of an existing file. This will replace the entire content of the file. For Jupyter notebooks, use dedicated notebook tools instead.',
293
- parameters: z.object({
294
- filePath: z
295
- .string()
296
- .describe('Path to the file to update (e.g., "script.py", "README.md", "config.json")'),
297
- content: z.string().describe('The new content to set for the file'),
298
- save: z
299
- .boolean()
300
- .optional()
301
- .default(true)
302
- .describe('Whether to save the file after updating (default: true)')
303
- }),
304
- errorFunction: (context, error) => {
305
- return JSON.stringify({
306
- success: false,
307
- error: `Failed to set file content: ${error instanceof Error ? error.message : String(error)}`
308
- });
309
- },
310
- execute: async (input) => {
311
- const { filePath, content, save = true } = input;
312
- let widget = docManager.findWidget(filePath);
313
- if (!widget) {
314
- widget = docManager.openOrReveal(filePath);
315
- }
316
- if (!widget) {
317
- throw new Error(`Failed to open file at path: ${filePath}`);
318
- }
319
- await widget.context.ready;
320
- const model = widget.context.model;
321
- if (!model) {
322
- throw new Error('File model not available');
323
- }
324
- if (model.readOnly) {
325
- throw new Error('File is read-only and cannot be modified');
326
- }
327
- const sharedModel = model.sharedModel;
328
- const originalContent = sharedModel.getSource();
329
- sharedModel.setSource(content);
330
- // Show the file diff using the diff manager if available
331
- if (diffManager) {
332
- await diffManager.showFileDiff({
333
- original: String(originalContent),
334
- modified: content,
335
- filePath
336
- });
337
- }
338
- if (save) {
339
- await widget.context.save();
340
- }
341
- return JSON.stringify({
342
- success: true,
343
- filePath,
344
- fileName: widget.title.label,
345
- contentLength: content.length,
346
- saved: save,
347
- isDirty: model.dirty
348
- });
349
- }
350
- });
351
- }
@@ -1,40 +0,0 @@
1
- import { IDocumentManager } from '@jupyterlab/docmanager';
2
- import { INotebookTracker } from '@jupyterlab/notebook';
3
- import { KernelSpec } from '@jupyterlab/services';
4
- import { IDiffManager, ITool } from '../tokens';
5
- /**
6
- * Create a notebook creation tool
7
- */
8
- export declare function createNotebookCreationTool(docManager: IDocumentManager, kernelSpecManager: KernelSpec.IManager): ITool;
9
- /**
10
- * Create a tool for adding cells to a specific notebook
11
- */
12
- export declare function createAddCellTool(docManager: IDocumentManager, notebookTracker?: INotebookTracker): ITool;
13
- /**
14
- * Create a tool for getting notebook information
15
- */
16
- export declare function createGetNotebookInfoTool(docManager: IDocumentManager, notebookTracker?: INotebookTracker): ITool;
17
- /**
18
- * Create a tool for getting cell information by index
19
- */
20
- export declare function createGetCellInfoTool(docManager: IDocumentManager, notebookTracker?: INotebookTracker): ITool;
21
- /**
22
- * Create a tool for setting cell content and type
23
- */
24
- export declare function createSetCellContentTool(docManager: IDocumentManager, notebookTracker?: INotebookTracker, diffManager?: IDiffManager): ITool;
25
- /**
26
- * Create a tool for running a specific cell
27
- */
28
- export declare function createRunCellTool(docManager: IDocumentManager, notebookTracker?: INotebookTracker): ITool;
29
- /**
30
- * Create a tool for deleting a specific cell
31
- */
32
- export declare function createDeleteCellTool(docManager: IDocumentManager, notebookTracker?: INotebookTracker): ITool;
33
- /**
34
- * Create a tool for executing code in the active cell (non-disruptive alternative to mcp__ide__executeCode)
35
- */
36
- export declare function createExecuteActiveCellTool(docManager: IDocumentManager, notebookTracker?: INotebookTracker): ITool;
37
- /**
38
- * Create a tool for saving a specific notebook
39
- */
40
- export declare function createSaveNotebookTool(docManager: IDocumentManager, notebookTracker?: INotebookTracker): ITool;