@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
package/lib/tokens.d.ts
CHANGED
|
@@ -1,145 +1,226 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ReadonlyPartialJSONObject, Token } from '@lumino/coreutils';
|
|
1
|
+
import { Token } from '@lumino/coreutils';
|
|
3
2
|
import { ISignal } from '@lumino/signaling';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export interface
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
3
|
+
import { FunctionTool } from '@openai/agents';
|
|
4
|
+
import { LanguageModel } from 'ai';
|
|
5
|
+
import { AgentManager } from './agent';
|
|
6
|
+
import type { AISettingsModel } from './models/settings-model';
|
|
7
|
+
import type { IModelOptions } from './providers/models';
|
|
8
|
+
/**
|
|
9
|
+
* Type definition for a tool
|
|
10
|
+
*/
|
|
11
|
+
export type ITool = FunctionTool<any, any, any>;
|
|
12
|
+
/**
|
|
13
|
+
* Interface for token usage statistics from AI model interactions
|
|
14
|
+
*/
|
|
15
|
+
export interface ITokenUsage {
|
|
16
|
+
/**
|
|
17
|
+
* Number of input tokens consumed (prompt tokens)
|
|
18
|
+
*/
|
|
19
|
+
inputTokens: number;
|
|
20
|
+
/**
|
|
21
|
+
* Number of output tokens generated (completion tokens)
|
|
22
|
+
*/
|
|
23
|
+
outputTokens: number;
|
|
21
24
|
}
|
|
22
25
|
/**
|
|
23
|
-
*
|
|
26
|
+
* Interface for a named tool (tool with a name identifier)
|
|
24
27
|
*/
|
|
25
|
-
export interface
|
|
28
|
+
export interface INamedTool {
|
|
26
29
|
/**
|
|
27
|
-
* The name of the
|
|
30
|
+
* The unique name of the tool
|
|
28
31
|
*/
|
|
29
32
|
name: string;
|
|
30
33
|
/**
|
|
31
|
-
* The
|
|
34
|
+
* The tool instance
|
|
32
35
|
*/
|
|
33
|
-
|
|
36
|
+
tool: ITool;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The tool registry interface for managing AI tools
|
|
40
|
+
*/
|
|
41
|
+
export interface IToolRegistry {
|
|
34
42
|
/**
|
|
35
|
-
* The
|
|
43
|
+
* The registered tools as a record (name -> tool mapping).
|
|
36
44
|
*/
|
|
37
|
-
|
|
45
|
+
readonly tools: Record<string, ITool>;
|
|
38
46
|
/**
|
|
39
|
-
*
|
|
47
|
+
* The registered named tools array.
|
|
40
48
|
*/
|
|
41
|
-
|
|
49
|
+
readonly namedTools: INamedTool[];
|
|
42
50
|
/**
|
|
43
|
-
*
|
|
44
|
-
* A markdown renderer is used to render the instructions.
|
|
51
|
+
* A signal triggered when the tools have changed.
|
|
45
52
|
*/
|
|
46
|
-
|
|
53
|
+
readonly toolsChanged: ISignal<IToolRegistry, void>;
|
|
47
54
|
/**
|
|
48
|
-
*
|
|
49
|
-
* Default to `(error) => error.message`.
|
|
55
|
+
* Add a new tool to the registry.
|
|
50
56
|
*/
|
|
51
|
-
|
|
57
|
+
add(name: string, tool: ITool): void;
|
|
52
58
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
59
|
+
* Get a tool for a given name.
|
|
60
|
+
* Return null if the name is not provided or if there is no registered tool with the
|
|
61
|
+
* given name.
|
|
55
62
|
*/
|
|
56
|
-
|
|
63
|
+
get(name: string | null): ITool | null;
|
|
57
64
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* ### CAUTION
|
|
61
|
-
* This flag will expose the whole chat model API, which may contain private keys.
|
|
62
|
-
* Be sure to use it with a model that does not expose sensitive information in the
|
|
63
|
-
* API.
|
|
65
|
+
* Remove a tool from the registry by name.
|
|
64
66
|
*/
|
|
65
|
-
|
|
67
|
+
remove(name: string): boolean;
|
|
66
68
|
}
|
|
67
69
|
/**
|
|
68
|
-
* The
|
|
70
|
+
* The tool registry token.
|
|
69
71
|
*/
|
|
70
|
-
export
|
|
72
|
+
export declare const IToolRegistry: Token<IToolRegistry>;
|
|
73
|
+
/**
|
|
74
|
+
* Token for the chat provider registry.
|
|
75
|
+
*/
|
|
76
|
+
export declare const IChatProviderRegistry: Token<IChatProviderRegistry>;
|
|
77
|
+
/**
|
|
78
|
+
* Token for the completion provider registry.
|
|
79
|
+
*/
|
|
80
|
+
export declare const ICompletionProviderRegistry: Token<ICompletionProviderRegistry>;
|
|
81
|
+
/**
|
|
82
|
+
* Interface for a provider factory function that creates chat models
|
|
83
|
+
*/
|
|
84
|
+
export interface IChatProviderFactory {
|
|
85
|
+
(options: IModelOptions): any;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Interface for a provider factory function that creates completion models
|
|
89
|
+
*/
|
|
90
|
+
export interface ICompletionProviderFactory {
|
|
91
|
+
(options: IModelOptions): LanguageModel;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Base information about a registered provider
|
|
95
|
+
*/
|
|
96
|
+
export interface IBaseProviderInfo {
|
|
71
97
|
/**
|
|
72
|
-
*
|
|
98
|
+
* Unique identifier for the provider
|
|
73
99
|
*/
|
|
74
|
-
|
|
100
|
+
id: string;
|
|
75
101
|
/**
|
|
76
|
-
*
|
|
102
|
+
* Display name for the provider
|
|
77
103
|
*/
|
|
78
|
-
|
|
104
|
+
name: string;
|
|
79
105
|
/**
|
|
80
|
-
*
|
|
106
|
+
* Whether this provider requires an API key
|
|
81
107
|
*/
|
|
82
|
-
|
|
108
|
+
requiresApiKey: boolean;
|
|
83
109
|
/**
|
|
84
|
-
*
|
|
110
|
+
* Default model names for this provider
|
|
85
111
|
*/
|
|
86
|
-
|
|
112
|
+
defaultModels: string[];
|
|
87
113
|
/**
|
|
88
|
-
*
|
|
114
|
+
* Whether this provider supports custom base URLs
|
|
89
115
|
*/
|
|
90
|
-
|
|
116
|
+
supportsBaseURL?: boolean;
|
|
91
117
|
/**
|
|
92
|
-
*
|
|
118
|
+
* Whether this provider supports custom headers
|
|
93
119
|
*/
|
|
94
|
-
|
|
120
|
+
supportsHeaders?: boolean;
|
|
95
121
|
/**
|
|
96
|
-
*
|
|
122
|
+
* Whether this provider supports tool calling
|
|
97
123
|
*/
|
|
98
|
-
|
|
124
|
+
supportsToolCalling?: boolean;
|
|
99
125
|
/**
|
|
100
|
-
*
|
|
126
|
+
* Additional provider-specific configuration schema
|
|
101
127
|
*/
|
|
102
|
-
|
|
128
|
+
customSettings?: Record<string, any>;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Information about a chat provider
|
|
132
|
+
*/
|
|
133
|
+
export interface IChatProviderInfo extends IBaseProviderInfo {
|
|
103
134
|
/**
|
|
104
|
-
*
|
|
135
|
+
* Factory function for creating chat models
|
|
105
136
|
*/
|
|
106
|
-
|
|
137
|
+
factory: IChatProviderFactory;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Information about a completion provider
|
|
141
|
+
*/
|
|
142
|
+
export interface ICompletionProviderInfo extends IBaseProviderInfo {
|
|
143
|
+
/**
|
|
144
|
+
* Factory function for creating completion models
|
|
145
|
+
*/
|
|
146
|
+
factory: ICompletionProviderFactory;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Registry for chat AI providers
|
|
150
|
+
*/
|
|
151
|
+
export interface IChatProviderRegistry {
|
|
152
|
+
/**
|
|
153
|
+
* The registered providers as a record (id -> info mapping).
|
|
154
|
+
*/
|
|
155
|
+
readonly providers: Record<string, IChatProviderInfo>;
|
|
156
|
+
/**
|
|
157
|
+
* A signal triggered when providers have changed.
|
|
158
|
+
*/
|
|
159
|
+
readonly providersChanged: ISignal<IChatProviderRegistry, void>;
|
|
160
|
+
/**
|
|
161
|
+
* Register a new chat provider.
|
|
162
|
+
*/
|
|
163
|
+
registerProvider(info: IChatProviderInfo): void;
|
|
164
|
+
/**
|
|
165
|
+
* Unregister a chat provider.
|
|
166
|
+
*/
|
|
167
|
+
unregisterProvider(id: string): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Get provider info by id.
|
|
170
|
+
*/
|
|
171
|
+
getProviderInfo(id: string): IChatProviderInfo | null;
|
|
172
|
+
/**
|
|
173
|
+
* Create a chat model instance for the given provider.
|
|
174
|
+
*/
|
|
175
|
+
createChatModel(id: string, options: IModelOptions): any | null;
|
|
176
|
+
/**
|
|
177
|
+
* Get all available provider IDs.
|
|
178
|
+
*/
|
|
179
|
+
getAvailableProviders(): string[];
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Registry for completion providers
|
|
183
|
+
*/
|
|
184
|
+
export interface ICompletionProviderRegistry {
|
|
107
185
|
/**
|
|
108
|
-
*
|
|
186
|
+
* The registered providers as a record (id -> info mapping).
|
|
109
187
|
*/
|
|
110
|
-
|
|
188
|
+
readonly providers: Record<string, ICompletionProviderInfo>;
|
|
111
189
|
/**
|
|
112
|
-
*
|
|
190
|
+
* A signal triggered when providers have changed.
|
|
113
191
|
*/
|
|
114
|
-
|
|
192
|
+
readonly providersChanged: ISignal<ICompletionProviderRegistry, void>;
|
|
115
193
|
/**
|
|
116
|
-
*
|
|
117
|
-
* Creates the provider if the name has changed, otherwise only updates its config.
|
|
118
|
-
*
|
|
119
|
-
* @param options - An object with the name and the settings of the provider to use.
|
|
194
|
+
* Register a new completion provider.
|
|
120
195
|
*/
|
|
121
|
-
|
|
196
|
+
registerProvider(info: ICompletionProviderInfo): void;
|
|
122
197
|
/**
|
|
123
|
-
*
|
|
124
|
-
* Creates the provider if the name has changed, otherwise only updates its config.
|
|
125
|
-
*
|
|
126
|
-
* @param options - An object with the name and the settings of the provider to use.
|
|
198
|
+
* Unregister a completion provider.
|
|
127
199
|
*/
|
|
128
|
-
|
|
200
|
+
unregisterProvider(id: string): boolean;
|
|
129
201
|
/**
|
|
130
|
-
*
|
|
202
|
+
* Get provider info by id.
|
|
131
203
|
*/
|
|
132
|
-
|
|
204
|
+
getProviderInfo(id: string): ICompletionProviderInfo | null;
|
|
133
205
|
/**
|
|
134
|
-
*
|
|
206
|
+
* Create a completion model instance for the given provider.
|
|
135
207
|
*/
|
|
136
|
-
|
|
208
|
+
createCompletionModel(id: string, options: IModelOptions): LanguageModel | null;
|
|
137
209
|
/**
|
|
138
|
-
*
|
|
210
|
+
* Get all available provider IDs.
|
|
139
211
|
*/
|
|
140
|
-
|
|
212
|
+
getAvailableProviders(): string[];
|
|
141
213
|
}
|
|
142
214
|
/**
|
|
143
|
-
*
|
|
215
|
+
* Token for the AI settings model.
|
|
216
|
+
*/
|
|
217
|
+
export declare const IAISettingsModel: Token<AISettingsModel>;
|
|
218
|
+
/**
|
|
219
|
+
* Token for the agent manager.
|
|
220
|
+
*/
|
|
221
|
+
export declare const IAgentManager: Token<AgentManager>;
|
|
222
|
+
/**
|
|
223
|
+
* The string that replaces a secret key in settings.
|
|
144
224
|
*/
|
|
145
|
-
export declare const
|
|
225
|
+
export declare const SECRETS_NAMESPACE = "@jupyterlite/ai:providers";
|
|
226
|
+
export declare const SECRETS_REPLACEMENT = "***";
|
package/lib/tokens.js
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import { Token } from '@lumino/coreutils';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
export const
|
|
2
|
+
/**
|
|
3
|
+
* The tool registry token.
|
|
4
|
+
*/
|
|
5
|
+
export const IToolRegistry = new Token('@jupyterlite/ai:tool-registry', 'Tool registry for AI agent functionality');
|
|
6
|
+
/**
|
|
7
|
+
* Token for the chat provider registry.
|
|
8
|
+
*/
|
|
9
|
+
export const IChatProviderRegistry = new Token('@jupyterlite/ai:chat-provider-registry', 'Registry for chat AI providers');
|
|
10
|
+
/**
|
|
11
|
+
* Token for the completion provider registry.
|
|
12
|
+
*/
|
|
13
|
+
export const ICompletionProviderRegistry = new Token('@jupyterlite/ai:completion-provider-registry', 'Registry for completion providers');
|
|
14
|
+
/**
|
|
15
|
+
* Token for the AI settings model.
|
|
16
|
+
*/
|
|
17
|
+
export const IAISettingsModel = new Token('@jupyterlite/ai:IAISettingsModel');
|
|
18
|
+
/**
|
|
19
|
+
* Token for the agent manager.
|
|
20
|
+
*/
|
|
21
|
+
export const IAgentManager = new Token('@jupyterlite/ai:agent-manager');
|
|
22
|
+
/**
|
|
23
|
+
* The string that replaces a secret key in settings.
|
|
24
|
+
*/
|
|
25
|
+
export const SECRETS_NAMESPACE = '@jupyterlite/ai:providers';
|
|
26
|
+
export const SECRETS_REPLACEMENT = '***';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CommandRegistry } from '@lumino/commands';
|
|
2
|
+
import { ITool } from '../tokens';
|
|
3
|
+
import { AISettingsModel } from '../models/settings-model';
|
|
4
|
+
/**
|
|
5
|
+
* Create a tool to discover all available commands and their metadata
|
|
6
|
+
*/
|
|
7
|
+
export declare function createDiscoverCommandsTool(commands: CommandRegistry): ITool;
|
|
8
|
+
/**
|
|
9
|
+
* Create a tool to execute a specific JupyterLab command
|
|
10
|
+
*/
|
|
11
|
+
export declare function createExecuteCommandTool(commands: CommandRegistry, settingsModel: AISettingsModel): ITool;
|
|
@@ -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;
|