@jupyterlite/ai 0.8.1 → 0.9.0-a1
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/agent.d.ts +243 -0
- package/lib/agent.js +627 -0
- package/lib/chat-model.d.ts +195 -0
- package/lib/chat-model.js +591 -0
- package/lib/completion/completion-provider.d.ts +93 -0
- package/lib/completion/completion-provider.js +235 -0
- package/lib/completion/index.d.ts +1 -0
- package/lib/completion/index.js +1 -0
- package/lib/components/clear-button.d.ts +18 -0
- package/lib/components/clear-button.js +31 -0
- package/lib/components/index.d.ts +3 -0
- package/lib/components/index.js +3 -0
- package/lib/components/model-select.d.ts +19 -0
- package/lib/components/model-select.js +154 -0
- package/lib/components/stop-button.d.ts +3 -3
- package/lib/components/stop-button.js +8 -9
- package/lib/components/token-usage-display.d.ts +45 -0
- package/lib/components/token-usage-display.js +74 -0
- package/lib/components/tool-select.d.ts +27 -0
- package/lib/components/tool-select.js +130 -0
- package/lib/icons.d.ts +3 -1
- package/lib/icons.js +10 -13
- package/lib/index.d.ts +5 -5
- package/lib/index.js +341 -169
- package/lib/mcp/browser.d.ts +68 -0
- package/lib/mcp/browser.js +132 -0
- package/lib/models/settings-model.d.ts +70 -0
- package/lib/models/settings-model.js +296 -0
- package/lib/providers/built-in-providers.d.ts +9 -0
- package/lib/providers/built-in-providers.js +266 -0
- package/lib/providers/models.d.ts +37 -0
- package/lib/providers/models.js +28 -0
- package/lib/providers/provider-registry.d.ts +94 -0
- package/lib/providers/provider-registry.js +155 -0
- package/lib/tokens.d.ts +167 -86
- package/lib/tokens.js +25 -12
- package/lib/tools/commands.d.ts +11 -0
- package/lib/tools/commands.js +126 -0
- package/lib/tools/file.d.ts +27 -0
- package/lib/tools/file.js +262 -0
- package/lib/tools/notebook.d.ts +41 -0
- package/lib/tools/notebook.js +779 -0
- package/lib/tools/tool-registry.d.ts +35 -0
- package/lib/tools/tool-registry.js +55 -0
- package/lib/widgets/ai-settings.d.ts +49 -0
- package/lib/widgets/ai-settings.js +580 -0
- package/lib/widgets/chat-wrapper.d.ts +144 -0
- package/lib/widgets/chat-wrapper.js +390 -0
- package/lib/widgets/provider-config-dialog.d.ts +14 -0
- package/lib/widgets/provider-config-dialog.js +112 -0
- package/package.json +151 -40
- package/schema/settings-model.json +159 -0
- package/src/agent.ts +836 -0
- package/src/chat-model.ts +771 -0
- package/src/completion/completion-provider.ts +346 -0
- package/src/completion/index.ts +1 -0
- package/src/components/clear-button.tsx +56 -0
- package/src/components/index.ts +3 -0
- package/src/components/model-select.tsx +245 -0
- package/src/components/stop-button.tsx +11 -11
- package/src/components/token-usage-display.tsx +130 -0
- package/src/components/tool-select.tsx +218 -0
- package/src/icons.ts +12 -14
- package/src/index.ts +485 -232
- package/src/mcp/browser.ts +213 -0
- package/src/models/settings-model.ts +413 -0
- package/src/providers/built-in-providers.ts +294 -0
- package/src/providers/models.ts +79 -0
- package/src/providers/provider-registry.ts +189 -0
- package/src/tokens.ts +217 -90
- package/src/tools/commands.ts +151 -0
- package/src/tools/file.ts +307 -0
- package/src/tools/notebook.ts +987 -0
- package/src/tools/tool-registry.ts +63 -0
- package/src/types.d.ts +4 -0
- package/src/widgets/ai-settings.tsx +1233 -0
- package/src/widgets/chat-wrapper.tsx +543 -0
- package/src/widgets/provider-config-dialog.tsx +272 -0
- package/style/base.css +335 -14
- package/style/icons/jupyternaut-lite.svg +1 -1
- package/lib/base-completer.d.ts +0 -49
- package/lib/base-completer.js +0 -14
- package/lib/chat-handler.d.ts +0 -56
- package/lib/chat-handler.js +0 -201
- package/lib/completion-provider.d.ts +0 -34
- package/lib/completion-provider.js +0 -32
- package/lib/default-prompts.d.ts +0 -2
- package/lib/default-prompts.js +0 -31
- package/lib/default-providers/Anthropic/completer.d.ts +0 -12
- package/lib/default-providers/Anthropic/completer.js +0 -46
- package/lib/default-providers/Anthropic/settings-schema.json +0 -70
- package/lib/default-providers/ChromeAI/completer.d.ts +0 -12
- package/lib/default-providers/ChromeAI/completer.js +0 -56
- package/lib/default-providers/ChromeAI/instructions.d.ts +0 -6
- package/lib/default-providers/ChromeAI/instructions.js +0 -42
- package/lib/default-providers/ChromeAI/settings-schema.json +0 -18
- package/lib/default-providers/Gemini/completer.d.ts +0 -12
- package/lib/default-providers/Gemini/completer.js +0 -48
- package/lib/default-providers/Gemini/instructions.d.ts +0 -2
- package/lib/default-providers/Gemini/instructions.js +0 -9
- package/lib/default-providers/Gemini/settings-schema.json +0 -64
- package/lib/default-providers/MistralAI/completer.d.ts +0 -13
- package/lib/default-providers/MistralAI/completer.js +0 -52
- package/lib/default-providers/MistralAI/instructions.d.ts +0 -2
- package/lib/default-providers/MistralAI/instructions.js +0 -18
- package/lib/default-providers/MistralAI/settings-schema.json +0 -75
- package/lib/default-providers/Ollama/completer.d.ts +0 -12
- package/lib/default-providers/Ollama/completer.js +0 -43
- package/lib/default-providers/Ollama/instructions.d.ts +0 -2
- package/lib/default-providers/Ollama/instructions.js +0 -70
- package/lib/default-providers/Ollama/settings-schema.json +0 -143
- package/lib/default-providers/OpenAI/completer.d.ts +0 -12
- package/lib/default-providers/OpenAI/completer.js +0 -43
- package/lib/default-providers/OpenAI/settings-schema.json +0 -628
- package/lib/default-providers/WebLLM/completer.d.ts +0 -21
- package/lib/default-providers/WebLLM/completer.js +0 -127
- package/lib/default-providers/WebLLM/instructions.d.ts +0 -6
- package/lib/default-providers/WebLLM/instructions.js +0 -32
- package/lib/default-providers/WebLLM/settings-schema.json +0 -19
- package/lib/default-providers/index.d.ts +0 -2
- package/lib/default-providers/index.js +0 -179
- package/lib/provider.d.ts +0 -144
- package/lib/provider.js +0 -412
- package/lib/settings/base.json +0 -7
- package/lib/settings/index.d.ts +0 -3
- package/lib/settings/index.js +0 -3
- package/lib/settings/panel.d.ts +0 -226
- package/lib/settings/panel.js +0 -510
- package/lib/settings/textarea.d.ts +0 -2
- package/lib/settings/textarea.js +0 -18
- package/lib/settings/utils.d.ts +0 -2
- package/lib/settings/utils.js +0 -4
- package/lib/types/ai-model.d.ts +0 -24
- package/lib/types/ai-model.js +0 -5
- package/schema/chat.json +0 -28
- package/schema/provider-registry.json +0 -29
- package/schema/system-prompts.json +0 -22
- package/src/base-completer.ts +0 -75
- package/src/chat-handler.ts +0 -262
- package/src/completion-provider.ts +0 -64
- package/src/default-prompts.ts +0 -33
- package/src/default-providers/Anthropic/completer.ts +0 -59
- package/src/default-providers/ChromeAI/completer.ts +0 -73
- package/src/default-providers/ChromeAI/instructions.ts +0 -45
- package/src/default-providers/Gemini/completer.ts +0 -61
- package/src/default-providers/Gemini/instructions.ts +0 -9
- package/src/default-providers/MistralAI/completer.ts +0 -69
- package/src/default-providers/MistralAI/instructions.ts +0 -18
- package/src/default-providers/Ollama/completer.ts +0 -54
- package/src/default-providers/Ollama/instructions.ts +0 -70
- package/src/default-providers/OpenAI/completer.ts +0 -54
- package/src/default-providers/WebLLM/completer.ts +0 -151
- package/src/default-providers/WebLLM/instructions.ts +0 -33
- package/src/default-providers/index.ts +0 -211
- package/src/global.d.ts +0 -9
- package/src/provider.ts +0 -514
- package/src/settings/index.ts +0 -3
- package/src/settings/panel.tsx +0 -773
- package/src/settings/textarea.tsx +0 -33
- package/src/settings/utils.ts +0 -5
- package/src/types/ai-model.ts +0 -37
- package/src/types/service-worker.d.ts +0 -6
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { tool } from '@openai/agents';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* Create a tool for creating new files of various types
|
|
5
|
+
*/
|
|
6
|
+
export function createNewFileTool(docManager) {
|
|
7
|
+
return tool({
|
|
8
|
+
name: 'create_file',
|
|
9
|
+
description: 'Create a new file of specified type (text, python, markdown, json, etc.)',
|
|
10
|
+
parameters: z.object({
|
|
11
|
+
fileName: z.string().describe('Name of the file to create'),
|
|
12
|
+
fileType: z
|
|
13
|
+
.enum([
|
|
14
|
+
'text',
|
|
15
|
+
'python',
|
|
16
|
+
'markdown',
|
|
17
|
+
'json',
|
|
18
|
+
'javascript',
|
|
19
|
+
'typescript'
|
|
20
|
+
])
|
|
21
|
+
.default('text')
|
|
22
|
+
.describe('Type of file to create'),
|
|
23
|
+
content: z
|
|
24
|
+
.string()
|
|
25
|
+
.optional()
|
|
26
|
+
.nullable()
|
|
27
|
+
.describe('Initial content for the file (optional)'),
|
|
28
|
+
cwd: z
|
|
29
|
+
.string()
|
|
30
|
+
.optional()
|
|
31
|
+
.nullable()
|
|
32
|
+
.describe('Directory where to create the file (optional)')
|
|
33
|
+
}),
|
|
34
|
+
execute: async (input) => {
|
|
35
|
+
const { fileName, content = '', cwd, fileType = 'text' } = input;
|
|
36
|
+
try {
|
|
37
|
+
// Determine file extension based on type
|
|
38
|
+
const extensions = {
|
|
39
|
+
python: 'py',
|
|
40
|
+
markdown: 'md',
|
|
41
|
+
json: 'json',
|
|
42
|
+
text: 'txt',
|
|
43
|
+
javascript: 'js',
|
|
44
|
+
typescript: 'ts'
|
|
45
|
+
};
|
|
46
|
+
const ext = extensions[fileType] || 'txt';
|
|
47
|
+
// If fileName already has an extension, use it as-is, otherwise add the extension
|
|
48
|
+
const fullFileName = fileName.includes('.')
|
|
49
|
+
? fileName
|
|
50
|
+
: `${fileName}.${ext}`;
|
|
51
|
+
// For Python files, ensure .py extension if fileType is python
|
|
52
|
+
const finalFileName = fileType === 'python' &&
|
|
53
|
+
!fileName.endsWith('.py') &&
|
|
54
|
+
!fileName.includes('.')
|
|
55
|
+
? `${fileName}.py`
|
|
56
|
+
: fullFileName;
|
|
57
|
+
const fullPath = cwd ? `${cwd}/${finalFileName}` : finalFileName;
|
|
58
|
+
// Create file with content using document manager
|
|
59
|
+
const model = await docManager.services.contents.newUntitled({
|
|
60
|
+
path: cwd || '',
|
|
61
|
+
type: 'file',
|
|
62
|
+
ext
|
|
63
|
+
});
|
|
64
|
+
// Rename to desired name if needed
|
|
65
|
+
let finalPath = model.path;
|
|
66
|
+
if (model.name !== finalFileName) {
|
|
67
|
+
const renamed = await docManager.services.contents.rename(model.path, fullPath);
|
|
68
|
+
finalPath = renamed.path;
|
|
69
|
+
}
|
|
70
|
+
// Set content if provided
|
|
71
|
+
if (content) {
|
|
72
|
+
await docManager.services.contents.save(finalPath, {
|
|
73
|
+
type: 'file',
|
|
74
|
+
format: 'text',
|
|
75
|
+
content
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
// Open the newly created file
|
|
79
|
+
let opened = false;
|
|
80
|
+
if (!docManager.findWidget(finalPath)) {
|
|
81
|
+
docManager.openOrReveal(finalPath);
|
|
82
|
+
opened = true;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
success: true,
|
|
86
|
+
message: `${fileType} file '${finalFileName}' created and opened successfully`,
|
|
87
|
+
fileName: finalFileName,
|
|
88
|
+
filePath: finalPath,
|
|
89
|
+
fileType,
|
|
90
|
+
hasContent: !!content,
|
|
91
|
+
opened
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
return {
|
|
96
|
+
success: false,
|
|
97
|
+
error: `Failed to create file: ${error.message}`
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create a tool for opening files
|
|
105
|
+
*/
|
|
106
|
+
export function createOpenFileTool(docManager) {
|
|
107
|
+
return tool({
|
|
108
|
+
name: 'open_file',
|
|
109
|
+
description: 'Open a file in the editor',
|
|
110
|
+
parameters: z.object({
|
|
111
|
+
filePath: z.string().describe('Path to the file to open')
|
|
112
|
+
}),
|
|
113
|
+
execute: async (input) => {
|
|
114
|
+
const { filePath } = input;
|
|
115
|
+
try {
|
|
116
|
+
const widget = docManager.openOrReveal(filePath);
|
|
117
|
+
if (!widget) {
|
|
118
|
+
return {
|
|
119
|
+
success: false,
|
|
120
|
+
error: `Failed to open file: ${filePath}`
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
success: true,
|
|
125
|
+
message: `File '${filePath}' opened successfully`,
|
|
126
|
+
filePath,
|
|
127
|
+
widgetId: widget.id
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
return {
|
|
132
|
+
success: false,
|
|
133
|
+
error: `Failed to open file: ${error.message}`
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Create a tool for deleting files
|
|
141
|
+
*/
|
|
142
|
+
export function createDeleteFileTool(docManager) {
|
|
143
|
+
return tool({
|
|
144
|
+
name: 'delete_file',
|
|
145
|
+
description: 'Delete a file from the file system',
|
|
146
|
+
parameters: z.object({
|
|
147
|
+
filePath: z.string().describe('Path to the file to delete')
|
|
148
|
+
}),
|
|
149
|
+
execute: async (input) => {
|
|
150
|
+
const { filePath } = input;
|
|
151
|
+
try {
|
|
152
|
+
await docManager.services.contents.delete(filePath);
|
|
153
|
+
return {
|
|
154
|
+
success: true,
|
|
155
|
+
message: `File '${filePath}' deleted successfully`,
|
|
156
|
+
filePath
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
return {
|
|
161
|
+
success: false,
|
|
162
|
+
error: `Failed to delete file: ${error.message}`
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Create a tool for renaming files
|
|
170
|
+
*/
|
|
171
|
+
export function createRenameFileTool(docManager) {
|
|
172
|
+
return tool({
|
|
173
|
+
name: 'rename_file',
|
|
174
|
+
description: 'Rename a file or move it to a different location',
|
|
175
|
+
parameters: z.object({
|
|
176
|
+
oldPath: z.string().describe('Current path of the file'),
|
|
177
|
+
newPath: z.string().describe('New path/name for the file')
|
|
178
|
+
}),
|
|
179
|
+
execute: async (input) => {
|
|
180
|
+
const { oldPath, newPath } = input;
|
|
181
|
+
try {
|
|
182
|
+
await docManager.services.contents.rename(oldPath, newPath);
|
|
183
|
+
return {
|
|
184
|
+
success: true,
|
|
185
|
+
message: `File renamed from '${oldPath}' to '${newPath}' successfully`,
|
|
186
|
+
oldPath,
|
|
187
|
+
newPath
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
return {
|
|
192
|
+
success: false,
|
|
193
|
+
error: `Failed to rename file: ${error.message}`
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Create a tool for copying files
|
|
201
|
+
*/
|
|
202
|
+
export function createCopyFileTool(docManager) {
|
|
203
|
+
return tool({
|
|
204
|
+
name: 'copy_file',
|
|
205
|
+
description: 'Copy a file to a new location',
|
|
206
|
+
parameters: z.object({
|
|
207
|
+
sourcePath: z.string().describe('Path of the file to copy'),
|
|
208
|
+
destinationPath: z
|
|
209
|
+
.string()
|
|
210
|
+
.describe('Destination path for the copied file')
|
|
211
|
+
}),
|
|
212
|
+
execute: async (input) => {
|
|
213
|
+
const { sourcePath, destinationPath } = input;
|
|
214
|
+
try {
|
|
215
|
+
await docManager.services.contents.copy(sourcePath, destinationPath);
|
|
216
|
+
return {
|
|
217
|
+
success: true,
|
|
218
|
+
message: `File copied from '${sourcePath}' to '${destinationPath}' successfully`,
|
|
219
|
+
sourcePath,
|
|
220
|
+
destinationPath
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
return {
|
|
225
|
+
success: false,
|
|
226
|
+
error: `Failed to copy file: ${error.message}`
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Create a tool for navigating to directories in the file browser
|
|
234
|
+
*/
|
|
235
|
+
export function createNavigateToDirectoryTool(commands) {
|
|
236
|
+
return tool({
|
|
237
|
+
name: 'navigate_to_directory',
|
|
238
|
+
description: 'Navigate to a specific directory in the file browser',
|
|
239
|
+
parameters: z.object({
|
|
240
|
+
directoryPath: z.string().describe('Path to the directory to navigate to')
|
|
241
|
+
}),
|
|
242
|
+
execute: async (input) => {
|
|
243
|
+
const { directoryPath } = input;
|
|
244
|
+
try {
|
|
245
|
+
await commands.execute('filebrowser:go-to-path', {
|
|
246
|
+
path: directoryPath
|
|
247
|
+
});
|
|
248
|
+
return {
|
|
249
|
+
success: true,
|
|
250
|
+
message: `Navigated to directory '${directoryPath}' successfully`,
|
|
251
|
+
directoryPath
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
return {
|
|
256
|
+
success: false,
|
|
257
|
+
error: `Failed to navigate to directory: ${error.message}`
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { IDocumentManager } from '@jupyterlab/docmanager';
|
|
2
|
+
import { INotebookTracker } from '@jupyterlab/notebook';
|
|
3
|
+
import { KernelSpec } from '@jupyterlab/services';
|
|
4
|
+
import { CommandRegistry } from '@lumino/commands';
|
|
5
|
+
import { ITool } from '../tokens';
|
|
6
|
+
/**
|
|
7
|
+
* Create a notebook creation tool
|
|
8
|
+
*/
|
|
9
|
+
export declare function createNotebookCreationTool(docManager: IDocumentManager, kernelSpecManager: KernelSpec.IManager): ITool;
|
|
10
|
+
/**
|
|
11
|
+
* Create a tool for adding cells to a specific notebook
|
|
12
|
+
*/
|
|
13
|
+
export declare function createAddCellTool(docManager: IDocumentManager, notebookTracker?: INotebookTracker): ITool;
|
|
14
|
+
/**
|
|
15
|
+
* Create a tool for getting notebook information
|
|
16
|
+
*/
|
|
17
|
+
export declare function createGetNotebookInfoTool(docManager: IDocumentManager, notebookTracker?: INotebookTracker): ITool;
|
|
18
|
+
/**
|
|
19
|
+
* Create a tool for getting cell information by index
|
|
20
|
+
*/
|
|
21
|
+
export declare function createGetCellInfoTool(docManager: IDocumentManager, notebookTracker?: INotebookTracker): ITool;
|
|
22
|
+
/**
|
|
23
|
+
* Create a tool for setting cell content and type
|
|
24
|
+
*/
|
|
25
|
+
export declare function createSetCellContentTool(docManager: IDocumentManager, commands: CommandRegistry, notebookTracker?: INotebookTracker): ITool;
|
|
26
|
+
/**
|
|
27
|
+
* Create a tool for running a specific cell
|
|
28
|
+
*/
|
|
29
|
+
export declare function createRunCellTool(docManager: IDocumentManager, notebookTracker?: INotebookTracker): ITool;
|
|
30
|
+
/**
|
|
31
|
+
* Create a tool for deleting a specific cell
|
|
32
|
+
*/
|
|
33
|
+
export declare function createDeleteCellTool(docManager: IDocumentManager, notebookTracker?: INotebookTracker): ITool;
|
|
34
|
+
/**
|
|
35
|
+
* Create a tool for executing code in the active cell (non-disruptive alternative to mcp__ide__executeCode)
|
|
36
|
+
*/
|
|
37
|
+
export declare function createExecuteActiveCellTool(docManager: IDocumentManager, notebookTracker?: INotebookTracker): ITool;
|
|
38
|
+
/**
|
|
39
|
+
* Create a tool for saving a specific notebook
|
|
40
|
+
*/
|
|
41
|
+
export declare function createSaveNotebookTool(docManager: IDocumentManager, notebookTracker?: INotebookTracker): ITool;
|