@jupyterlite/ai 0.8.0 → 0.9.0-a0
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 +233 -0
- package/lib/agent.js +604 -0
- package/lib/chat-model.d.ts +195 -0
- package/lib/chat-model.js +590 -0
- package/lib/completion/completion-provider.d.ts +83 -0
- package/lib/completion/completion-provider.js +209 -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 +4 -5
- package/lib/index.js +322 -167
- package/lib/mcp/browser.d.ts +68 -0
- package/lib/mcp/browser.js +132 -0
- package/lib/models/settings-model.d.ts +69 -0
- package/lib/models/settings-model.js +295 -0
- package/lib/providers/built-in-providers.d.ts +9 -0
- package/lib/providers/built-in-providers.js +192 -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 +157 -86
- package/lib/tokens.js +16 -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 +40 -0
- package/lib/tools/notebook.js +762 -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 +39 -0
- package/lib/widgets/ai-settings.js +506 -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 +13 -0
- package/lib/widgets/provider-config-dialog.js +104 -0
- package/package.json +150 -41
- package/schema/settings-model.json +153 -0
- package/src/agent.ts +800 -0
- package/src/chat-model.ts +770 -0
- package/src/completion/completion-provider.ts +308 -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 +468 -238
- package/src/mcp/browser.ts +213 -0
- package/src/models/settings-model.ts +409 -0
- package/src/providers/built-in-providers.ts +216 -0
- package/src/providers/models.ts +79 -0
- package/src/providers/provider-registry.ts +189 -0
- package/src/tokens.ts +203 -90
- package/src/tools/commands.ts +151 -0
- package/src/tools/file.ts +307 -0
- package/src/tools/notebook.ts +964 -0
- package/src/tools/tool-registry.ts +63 -0
- package/src/types.d.ts +4 -0
- package/src/widgets/ai-settings.tsx +1100 -0
- package/src/widgets/chat-wrapper.tsx +543 -0
- package/src/widgets/provider-config-dialog.tsx +256 -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,126 @@
|
|
|
1
|
+
import { tool } from '@openai/agents';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* Create a tool to discover all available commands and their metadata
|
|
5
|
+
*/
|
|
6
|
+
export function createDiscoverCommandsTool(commands) {
|
|
7
|
+
return tool({
|
|
8
|
+
name: 'discover_commands',
|
|
9
|
+
description: 'Discover all available JupyterLab commands with their metadata, arguments, and descriptions',
|
|
10
|
+
parameters: z.object({
|
|
11
|
+
// currently unused, but could be used to filter commands by a search term
|
|
12
|
+
query: z
|
|
13
|
+
.string()
|
|
14
|
+
.optional()
|
|
15
|
+
.nullable()
|
|
16
|
+
.describe('Optional search query to filter commands')
|
|
17
|
+
}),
|
|
18
|
+
execute: async () => {
|
|
19
|
+
try {
|
|
20
|
+
const commandList = [];
|
|
21
|
+
// Get all command IDs
|
|
22
|
+
const commandIds = commands.listCommands();
|
|
23
|
+
for (const id of commandIds) {
|
|
24
|
+
try {
|
|
25
|
+
// Get command metadata using various CommandRegistry methods
|
|
26
|
+
const description = await commands.describedBy(id);
|
|
27
|
+
const label = commands.label(id);
|
|
28
|
+
const caption = commands.caption(id);
|
|
29
|
+
const usage = commands.usage(id);
|
|
30
|
+
commandList.push({
|
|
31
|
+
id,
|
|
32
|
+
label: label || undefined,
|
|
33
|
+
caption: caption || undefined,
|
|
34
|
+
description: usage || undefined,
|
|
35
|
+
args: description?.args || undefined
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
// Some commands might not have descriptions, skip them
|
|
40
|
+
commandList.push({ id });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
success: true,
|
|
45
|
+
commandCount: commandList.length,
|
|
46
|
+
commands: commandList
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
return {
|
|
51
|
+
success: false,
|
|
52
|
+
error: `Failed to discover commands: ${error instanceof Error ? error.message : String(error)}`
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create a tool to execute a specific JupyterLab command
|
|
60
|
+
*/
|
|
61
|
+
export function createExecuteCommandTool(commands, settingsModel) {
|
|
62
|
+
return tool({
|
|
63
|
+
name: 'execute_command',
|
|
64
|
+
description: 'Execute a specific JupyterLab command with optional arguments',
|
|
65
|
+
parameters: z.object({
|
|
66
|
+
commandId: z.string().describe('The ID of the command to execute'),
|
|
67
|
+
args: z
|
|
68
|
+
.any()
|
|
69
|
+
.optional()
|
|
70
|
+
.describe('Optional arguments to pass to the command')
|
|
71
|
+
}),
|
|
72
|
+
needsApproval: async (_context, { commandId }) => {
|
|
73
|
+
// Use configurable list of commands requiring approval
|
|
74
|
+
const commandsRequiringApproval = settingsModel.config.commandsRequiringApproval;
|
|
75
|
+
return commandsRequiringApproval.some(cmd => commandId.includes(cmd) || cmd.includes(commandId));
|
|
76
|
+
},
|
|
77
|
+
execute: async (input) => {
|
|
78
|
+
const { commandId, args } = input;
|
|
79
|
+
// Check if command exists
|
|
80
|
+
if (!commands.hasCommand(commandId)) {
|
|
81
|
+
return {
|
|
82
|
+
success: false,
|
|
83
|
+
error: `Command '${commandId}' does not exist. Use 'discover_commands' to see available commands.`
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
// Execute the command
|
|
88
|
+
const result = await commands.execute(commandId, args);
|
|
89
|
+
// Handle Widget objects specially (including subclasses like DocumentWidget)
|
|
90
|
+
let serializedResult;
|
|
91
|
+
if (result &&
|
|
92
|
+
typeof result === 'object' &&
|
|
93
|
+
(result.constructor?.name?.includes('Widget') || result.id)) {
|
|
94
|
+
serializedResult = {
|
|
95
|
+
type: result.constructor?.name || 'Widget',
|
|
96
|
+
id: result.id,
|
|
97
|
+
title: result.title?.label || result.title,
|
|
98
|
+
className: result.className
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// For other objects, try JSON serialization with fallback
|
|
103
|
+
try {
|
|
104
|
+
serializedResult = JSON.parse(JSON.stringify(result));
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
serializedResult = result
|
|
108
|
+
? '[Complex object - cannot serialize]'
|
|
109
|
+
: 'Command executed successfully';
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
success: true,
|
|
114
|
+
commandId,
|
|
115
|
+
result: serializedResult
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
return {
|
|
120
|
+
success: false,
|
|
121
|
+
error: `Failed to execute command '${commandId}': ${error instanceof Error ? error.message : String(error)}`
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CommandRegistry } from '@lumino/commands';
|
|
2
|
+
import { IDocumentManager } from '@jupyterlab/docmanager';
|
|
3
|
+
import { ITool } from '../tokens';
|
|
4
|
+
/**
|
|
5
|
+
* Create a tool for creating new files of various types
|
|
6
|
+
*/
|
|
7
|
+
export declare function createNewFileTool(docManager: IDocumentManager): ITool;
|
|
8
|
+
/**
|
|
9
|
+
* Create a tool for opening files
|
|
10
|
+
*/
|
|
11
|
+
export declare function createOpenFileTool(docManager: IDocumentManager): ITool;
|
|
12
|
+
/**
|
|
13
|
+
* Create a tool for deleting files
|
|
14
|
+
*/
|
|
15
|
+
export declare function createDeleteFileTool(docManager: IDocumentManager): ITool;
|
|
16
|
+
/**
|
|
17
|
+
* Create a tool for renaming files
|
|
18
|
+
*/
|
|
19
|
+
export declare function createRenameFileTool(docManager: IDocumentManager): ITool;
|
|
20
|
+
/**
|
|
21
|
+
* Create a tool for copying files
|
|
22
|
+
*/
|
|
23
|
+
export declare function createCopyFileTool(docManager: IDocumentManager): ITool;
|
|
24
|
+
/**
|
|
25
|
+
* Create a tool for navigating to directories in the file browser
|
|
26
|
+
*/
|
|
27
|
+
export declare function createNavigateToDirectoryTool(commands: CommandRegistry): ITool;
|
|
@@ -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,40 @@
|
|
|
1
|
+
import { IDocumentManager } from '@jupyterlab/docmanager';
|
|
2
|
+
import { INotebookTracker } from '@jupyterlab/notebook';
|
|
3
|
+
import { KernelSpec } from '@jupyterlab/services';
|
|
4
|
+
import { 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): 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;
|