@jupyterlite/ai 0.17.0 → 0.19.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.
- package/lib/chat-commands/clear.d.ts +1 -0
- package/lib/chat-commands/index.d.ts +1 -0
- package/lib/chat-commands/skills.d.ts +2 -1
- package/lib/chat-model-handler.d.ts +4 -3
- package/lib/chat-model-handler.js +2 -1
- package/lib/chat-model.d.ts +148 -8
- package/lib/chat-model.js +368 -79
- package/lib/completion/completion-provider.d.ts +3 -1
- package/lib/completion/completion-provider.js +1 -2
- package/lib/completion/index.d.ts +1 -0
- package/lib/components/clear-button.d.ts +1 -0
- package/lib/components/clear-button.js +3 -4
- package/lib/components/completion-status.d.ts +1 -0
- package/lib/components/completion-status.js +5 -4
- package/lib/components/index.d.ts +1 -0
- package/lib/components/model-select.d.ts +1 -0
- package/lib/components/model-select.js +62 -67
- package/lib/components/save-button.d.ts +3 -2
- package/lib/components/save-button.js +4 -5
- package/lib/components/stop-button.d.ts +1 -0
- package/lib/components/stop-button.js +3 -4
- package/lib/components/tool-select.d.ts +3 -1
- package/lib/components/tool-select.js +47 -60
- package/lib/components/usage-display.d.ts +4 -2
- package/lib/components/usage-display.js +50 -61
- package/lib/diff-manager.d.ts +3 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.js +50 -59
- package/lib/models/settings-model.d.ts +3 -1
- package/lib/models/settings-model.js +1 -0
- package/lib/rendered-message-outputarea.d.ts +1 -0
- package/lib/tokens.d.ts +48 -597
- package/lib/tokens.js +2 -31
- package/lib/widgets/ai-settings.d.ts +3 -1
- package/lib/widgets/ai-settings.js +185 -344
- package/lib/widgets/main-area-chat.d.ts +3 -3
- package/lib/widgets/main-area-chat.js +2 -4
- package/lib/widgets/provider-config-dialog.d.ts +2 -1
- package/lib/widgets/provider-config-dialog.js +102 -167
- package/package.json +111 -258
- package/schema/settings-model.json +6 -0
- package/src/chat-commands/skills.ts +2 -2
- package/src/chat-model-handler.ts +10 -6
- package/src/chat-model.ts +488 -96
- package/src/completion/completion-provider.ts +6 -6
- package/src/components/clear-button.tsx +0 -2
- package/src/components/completion-status.tsx +2 -2
- package/src/components/model-select.tsx +1 -1
- package/src/components/save-button.tsx +3 -3
- package/src/components/stop-button.tsx +0 -2
- package/src/components/tool-select.tsx +10 -9
- package/src/components/usage-display.tsx +4 -2
- package/src/diff-manager.ts +4 -3
- package/src/index.ts +103 -107
- package/src/models/settings-model.ts +7 -6
- package/src/tokens.ts +54 -744
- package/src/widgets/ai-settings.tsx +40 -11
- package/src/widgets/main-area-chat.ts +5 -8
- package/src/widgets/provider-config-dialog.tsx +8 -8
- package/LICENSE +0 -30
- package/README.md +0 -49
- package/lib/agent.d.ts +0 -277
- package/lib/agent.js +0 -1116
- package/lib/icons.d.ts +0 -3
- package/lib/icons.js +0 -8
- package/lib/providers/built-in-providers.d.ts +0 -21
- package/lib/providers/built-in-providers.js +0 -233
- package/lib/providers/generated-context-windows.d.ts +0 -8
- package/lib/providers/generated-context-windows.js +0 -96
- package/lib/providers/model-info.d.ts +0 -3
- package/lib/providers/model-info.js +0 -58
- package/lib/providers/models.d.ts +0 -37
- package/lib/providers/models.js +0 -28
- package/lib/providers/provider-registry.d.ts +0 -49
- package/lib/providers/provider-registry.js +0 -72
- package/lib/providers/provider-tools.d.ts +0 -36
- package/lib/providers/provider-tools.js +0 -93
- package/lib/skills/index.d.ts +0 -4
- package/lib/skills/index.js +0 -7
- package/lib/skills/parse-skill.d.ts +0 -25
- package/lib/skills/parse-skill.js +0 -69
- package/lib/skills/skill-loader.d.ts +0 -25
- package/lib/skills/skill-loader.js +0 -133
- package/lib/skills/skill-registry.d.ts +0 -31
- package/lib/skills/skill-registry.js +0 -100
- package/lib/skills/types.d.ts +0 -29
- package/lib/skills/types.js +0 -5
- package/lib/tools/commands.d.ts +0 -11
- package/lib/tools/commands.js +0 -154
- package/lib/tools/skills.d.ts +0 -9
- package/lib/tools/skills.js +0 -73
- package/lib/tools/tool-registry.d.ts +0 -35
- package/lib/tools/tool-registry.js +0 -55
- package/lib/tools/web.d.ts +0 -8
- package/lib/tools/web.js +0 -196
- package/src/agent.ts +0 -1441
- package/src/icons.ts +0 -11
- package/src/providers/built-in-providers.ts +0 -241
- package/src/providers/generated-context-windows.ts +0 -102
- package/src/providers/model-info.ts +0 -88
- package/src/providers/models.ts +0 -76
- package/src/providers/provider-registry.ts +0 -88
- package/src/providers/provider-tools.ts +0 -179
- package/src/skills/index.ts +0 -14
- package/src/skills/parse-skill.ts +0 -91
- package/src/skills/skill-loader.ts +0 -175
- package/src/skills/skill-registry.ts +0 -137
- package/src/skills/types.ts +0 -37
- package/src/tools/commands.ts +0 -210
- package/src/tools/skills.ts +0 -84
- package/src/tools/tool-registry.ts +0 -63
- package/src/tools/web.ts +0 -238
- package/src/types.d.ts +0 -4
- package/style/icons/jupyternaut-lite.svg +0 -7
package/src/tokens.ts
CHANGED
|
@@ -1,27 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type {
|
|
2
|
+
IAISettingsModel as IBaseAISettingsModel,
|
|
3
|
+
IAgentManager,
|
|
4
|
+
ITokenUsage
|
|
5
|
+
} from '@jupyternaut/agent';
|
|
6
|
+
import { ActiveCellManager, IChatModel, IMessage } from '@jupyter/chat';
|
|
4
7
|
import { Token } from '@lumino/coreutils';
|
|
5
|
-
import type { IDisposable } from '@lumino/disposable';
|
|
6
8
|
import { ISignal } from '@lumino/signaling';
|
|
7
|
-
import type { Tool, LanguageModel, UserContent, ModelMessage } from 'ai';
|
|
8
|
-
import { ISecretsManager } from 'jupyter-secrets-manager';
|
|
9
|
-
|
|
10
|
-
import type { IModelOptions } from './providers/models';
|
|
11
|
-
import { AIChatModel } from './chat-model';
|
|
12
|
-
import type {
|
|
13
|
-
ISkillDefinition,
|
|
14
|
-
ISkillRegistration,
|
|
15
|
-
ISkillResourceResult,
|
|
16
|
-
ISkillSummary
|
|
17
|
-
} from './skills/types';
|
|
18
|
-
|
|
19
|
-
export type {
|
|
20
|
-
ISkillDefinition,
|
|
21
|
-
ISkillRegistration,
|
|
22
|
-
ISkillResourceResult,
|
|
23
|
-
ISkillSummary
|
|
24
|
-
} from './skills/types';
|
|
25
9
|
|
|
26
10
|
/**
|
|
27
11
|
* Command IDs namespace
|
|
@@ -37,635 +21,82 @@ export namespace CommandIds {
|
|
|
37
21
|
export const restoreChat = '@jupyterlite/ai:restore-chat';
|
|
38
22
|
}
|
|
39
23
|
|
|
40
|
-
/* THE
|
|
41
|
-
/**
|
|
42
|
-
* Type definition for a tool
|
|
43
|
-
*/
|
|
44
|
-
export type ITool = Tool;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* A map containing tools.
|
|
48
|
-
*/
|
|
49
|
-
export type ToolMap = Record<string, ITool>;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Interface for a named tool (tool with a name identifier)
|
|
53
|
-
*/
|
|
54
|
-
export interface INamedTool {
|
|
55
|
-
/**
|
|
56
|
-
* The unique name of the tool
|
|
57
|
-
*/
|
|
58
|
-
name: string;
|
|
59
|
-
/**
|
|
60
|
-
* The tool instance
|
|
61
|
-
*/
|
|
62
|
-
tool: ITool;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* The tool registry interface for managing AI tools
|
|
67
|
-
*/
|
|
68
|
-
export interface IToolRegistry {
|
|
69
|
-
/**
|
|
70
|
-
* The registered tools as a record (name -> tool mapping).
|
|
71
|
-
*/
|
|
72
|
-
readonly tools: Record<string, ITool>;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* The registered named tools array.
|
|
76
|
-
*/
|
|
77
|
-
readonly namedTools: INamedTool[];
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* A signal triggered when the tools have changed.
|
|
81
|
-
*/
|
|
82
|
-
readonly toolsChanged: ISignal<IToolRegistry, void>;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Add a new tool to the registry.
|
|
86
|
-
*/
|
|
87
|
-
add(name: string, tool: ITool): void;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Get a tool for a given name.
|
|
91
|
-
* Return null if the name is not provided or if there is no registered tool with the
|
|
92
|
-
* given name.
|
|
93
|
-
*/
|
|
94
|
-
get(name: string | null): ITool | null;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Remove a tool from the registry by name.
|
|
98
|
-
*/
|
|
99
|
-
remove(name: string): boolean;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* The tool registry token.
|
|
104
|
-
*/
|
|
105
|
-
export const IToolRegistry = new Token<IToolRegistry>(
|
|
106
|
-
'@jupyterlite/ai:IToolRegistry',
|
|
107
|
-
'Tool registry for AI agent functionality'
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
/* THE SKILL REGISTRY */
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Registry for skills available to the AI agent.
|
|
114
|
-
*/
|
|
115
|
-
export interface ISkillRegistry {
|
|
116
|
-
/**
|
|
117
|
-
* Signal emitted when skills change.
|
|
118
|
-
*/
|
|
119
|
-
readonly skillsChanged: ISignal<ISkillRegistry, void>;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Register a single skill.
|
|
123
|
-
*/
|
|
124
|
-
registerSkill(skill: ISkillRegistration): IDisposable;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* List all skills with summary info, optionally filtered by a search query.
|
|
128
|
-
*/
|
|
129
|
-
listSkills(query?: string): ISkillSummary[];
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Get a full skill definition by name.
|
|
133
|
-
*/
|
|
134
|
-
getSkill(name: string): ISkillDefinition | null;
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Load a resource for a skill.
|
|
138
|
-
*/
|
|
139
|
-
getSkillResource(
|
|
140
|
-
name: string,
|
|
141
|
-
resource: string
|
|
142
|
-
): Promise<ISkillResourceResult>;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* The skill registry token.
|
|
147
|
-
*/
|
|
148
|
-
export const ISkillRegistry = new Token<ISkillRegistry>(
|
|
149
|
-
'@jupyterlite/ai:ISkillRegistry',
|
|
150
|
-
'Skill registry for AI agent functionality'
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
/* THE LLM PROVIDER REGISTRY */
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Interface for a provider factory function that creates language models
|
|
157
|
-
*/
|
|
158
|
-
export interface IProviderFactory {
|
|
159
|
-
(options: IModelOptions): LanguageModel;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Built-in web search integration families supported by provider tools.
|
|
164
|
-
*/
|
|
165
|
-
export type IProviderWebSearchImplementation = 'openai' | 'anthropic';
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Built-in web fetch integration families supported by provider tools.
|
|
169
|
-
*/
|
|
170
|
-
export type IProviderWebFetchImplementation = 'anthropic';
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Capability descriptor for provider-hosted web search.
|
|
174
|
-
*/
|
|
175
|
-
export interface IProviderWebSearchCapability {
|
|
176
|
-
/**
|
|
177
|
-
* Which built-in integration family to use.
|
|
178
|
-
*/
|
|
179
|
-
implementation: IProviderWebSearchImplementation;
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* If true, skip provider-hosted web search when function tools are enabled.
|
|
183
|
-
*/
|
|
184
|
-
requiresNoFunctionTools?: boolean;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Capability descriptor for provider-hosted web fetch.
|
|
189
|
-
*/
|
|
190
|
-
export interface IProviderWebFetchCapability {
|
|
191
|
-
/**
|
|
192
|
-
* Which built-in integration family to use.
|
|
193
|
-
*/
|
|
194
|
-
implementation: IProviderWebFetchImplementation;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Provider-hosted tool capabilities exposed by a provider.
|
|
199
|
-
*/
|
|
200
|
-
export interface IProviderToolCapabilities {
|
|
201
|
-
webSearch?: IProviderWebSearchCapability;
|
|
202
|
-
webFetch?: IProviderWebFetchCapability;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Provider information
|
|
207
|
-
*/
|
|
208
|
-
export interface IProviderModelInfo {
|
|
209
|
-
/**
|
|
210
|
-
* Default context window for the model in tokens.
|
|
211
|
-
*/
|
|
212
|
-
contextWindow?: number;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
export interface IProviderInfo {
|
|
216
|
-
/**
|
|
217
|
-
* Unique identifier for the provider
|
|
218
|
-
*/
|
|
219
|
-
id: string;
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Display name for the provider
|
|
223
|
-
*/
|
|
224
|
-
name: string;
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* API key requirement policy for this provider
|
|
228
|
-
* - 'required': API key is mandatory
|
|
229
|
-
* - 'optional': API key is optional
|
|
230
|
-
* - 'none': API key is not needed and field will be hidden
|
|
231
|
-
*/
|
|
232
|
-
apiKeyRequirement: 'required' | 'optional' | 'none';
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Default model names for this provider
|
|
236
|
-
*/
|
|
237
|
-
defaultModels: string[];
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Optional per-model metadata keyed by model ID.
|
|
241
|
-
*/
|
|
242
|
-
modelInfo?: Record<string, IProviderModelInfo>;
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Whether this provider supports custom base URLs
|
|
246
|
-
*/
|
|
247
|
-
supportsBaseURL?: boolean;
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Whether this provider supports custom headers
|
|
251
|
-
*/
|
|
252
|
-
supportsHeaders?: boolean;
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Whether this provider supports tool calling
|
|
256
|
-
*/
|
|
257
|
-
supportsToolCalling?: boolean;
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Optional description shown in the UI
|
|
261
|
-
*/
|
|
262
|
-
description?: string;
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Optional URL suggestions
|
|
266
|
-
*/
|
|
267
|
-
baseUrls?: { url: string; description?: string }[];
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Optional provider-hosted tool capabilities for web retrieval.
|
|
271
|
-
*/
|
|
272
|
-
providerToolCapabilities?: IProviderToolCapabilities;
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Factory function for creating language models
|
|
276
|
-
*/
|
|
277
|
-
factory: IProviderFactory;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Registry for AI providers
|
|
282
|
-
*/
|
|
283
|
-
export interface IProviderRegistry {
|
|
284
|
-
/**
|
|
285
|
-
* The registered providers as a record (id -> info mapping).
|
|
286
|
-
*/
|
|
287
|
-
readonly providers: Record<string, IProviderInfo>;
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* A signal triggered when providers have changed.
|
|
291
|
-
*/
|
|
292
|
-
readonly providersChanged: ISignal<IProviderRegistry, void>;
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Register a new provider.
|
|
296
|
-
*/
|
|
297
|
-
registerProvider(info: IProviderInfo): void;
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Get provider info by id.
|
|
301
|
-
*/
|
|
302
|
-
getProviderInfo(id: string): IProviderInfo | null;
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Create a chat model instance for the given provider.
|
|
306
|
-
*/
|
|
307
|
-
createChatModel(id: string, options: IModelOptions): LanguageModel | null;
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Create a completion model instance for the given provider.
|
|
311
|
-
*/
|
|
312
|
-
createCompletionModel(
|
|
313
|
-
id: string,
|
|
314
|
-
options: IModelOptions
|
|
315
|
-
): LanguageModel | null;
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Get all available provider IDs.
|
|
319
|
-
*/
|
|
320
|
-
getAvailableProviders(): string[];
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* Token for the provider registry.
|
|
325
|
-
*/
|
|
326
|
-
export const IProviderRegistry = new Token<IProviderRegistry>(
|
|
327
|
-
'@jupyterlite/ai:IProviderRegistry',
|
|
328
|
-
'Registry for AI providers'
|
|
329
|
-
);
|
|
330
|
-
|
|
331
|
-
/* THE SETTINGS MODEL */
|
|
332
|
-
|
|
333
|
-
export interface IProviderParameters {
|
|
334
|
-
temperature?: number;
|
|
335
|
-
maxOutputTokens?: number;
|
|
336
|
-
maxTurns?: number;
|
|
337
|
-
contextWindow?: number;
|
|
338
|
-
supportsFillInMiddle?: boolean;
|
|
339
|
-
useFilterText?: boolean;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
export interface IProviderConfig {
|
|
343
|
-
id: string;
|
|
344
|
-
name: string;
|
|
345
|
-
provider: string;
|
|
346
|
-
model: string;
|
|
347
|
-
apiKey?: string;
|
|
348
|
-
baseURL?: string;
|
|
349
|
-
headers?: Record<string, string>;
|
|
350
|
-
parameters?: IProviderParameters;
|
|
351
|
-
customSettings?: Record<string, any>;
|
|
352
|
-
[key: string]: any; // Index signature for JupyterLab settings compatibility
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
export interface IMCPServerConfig {
|
|
356
|
-
id: string;
|
|
357
|
-
name: string;
|
|
358
|
-
url: string;
|
|
359
|
-
enabled: boolean;
|
|
360
|
-
[key: string]: any; // Index signature for JupyterLab settings compatibility
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
export interface IAIConfig {
|
|
364
|
-
// Whether to use the secrets manager
|
|
365
|
-
useSecretsManager: boolean;
|
|
366
|
-
// List of configured providers
|
|
367
|
-
providers: IProviderConfig[];
|
|
368
|
-
// Active provider IDs for different use cases
|
|
369
|
-
defaultProvider: string; // Default provider for chat
|
|
370
|
-
activeCompleterProvider?: string; // Provider for completions (if different)
|
|
371
|
-
// When true, use the same provider for chat and completions
|
|
372
|
-
useSameProviderForChatAndCompleter: boolean;
|
|
373
|
-
// MCP servers configuration
|
|
374
|
-
mcpServers: IMCPServerConfig[];
|
|
375
|
-
// Global settings
|
|
376
|
-
contextAwareness: boolean;
|
|
377
|
-
codeExecution: boolean;
|
|
378
|
-
systemPrompt: string;
|
|
379
|
-
completionSystemPrompt: string;
|
|
380
|
-
toolsEnabled: boolean;
|
|
381
|
-
// Chat behavior settings
|
|
382
|
-
sendWithShiftEnter: boolean;
|
|
383
|
-
// Token usage display setting
|
|
384
|
-
showTokenUsage: boolean;
|
|
385
|
-
// Context usage display setting
|
|
386
|
-
showContextUsage: boolean;
|
|
387
|
-
// Commands that require approval before execution
|
|
388
|
-
commandsRequiringApproval: string[];
|
|
389
|
-
// Commands whose execute_command outputs may auto-render MIME bundles in chat
|
|
390
|
-
commandsAutoRenderMimeBundles: string[];
|
|
391
|
-
// MIME types that are trusted when auto-rendering execute_command outputs
|
|
392
|
-
trustedMimeTypesForAutoRender: string[];
|
|
393
|
-
// Diff display settings
|
|
394
|
-
showCellDiff: boolean;
|
|
395
|
-
showFileDiff: boolean;
|
|
396
|
-
diffDisplayMode: 'split' | 'unified';
|
|
397
|
-
// Paths to directories containing agent skills
|
|
398
|
-
skillsPaths: string[];
|
|
399
|
-
// Directory where chat backups are saved
|
|
400
|
-
chatBackupDirectory: string;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
export interface IAISettingsModel extends VDomRenderer.IModel {
|
|
404
|
-
readonly config: IAIConfig;
|
|
405
|
-
updateConfig(updates: Partial<IAIConfig>): Promise<void>;
|
|
406
|
-
readonly providers: IProviderConfig[];
|
|
407
|
-
getProvider(id: string): IProviderConfig | undefined;
|
|
408
|
-
getDefaultProvider(): IProviderConfig | undefined;
|
|
409
|
-
getCompleterProvider(): IProviderConfig | undefined;
|
|
410
|
-
addProvider(providerConfig: Omit<IProviderConfig, 'id'>): Promise<string>;
|
|
411
|
-
removeProvider(id: string): Promise<void>;
|
|
412
|
-
updateProvider(id: string, updates: Partial<IProviderConfig>): Promise<void>;
|
|
413
|
-
setActiveProvider(id: string): Promise<void>;
|
|
414
|
-
setActiveCompleterProvider(id: string | undefined): Promise<void>;
|
|
415
|
-
readonly mcpServers: IMCPServerConfig[];
|
|
416
|
-
getMCPServer(id: string): IMCPServerConfig | undefined;
|
|
417
|
-
addMCPServer(serverConfig: Omit<IMCPServerConfig, 'id'>): Promise<string>;
|
|
418
|
-
removeMCPServer(id: string): Promise<void>;
|
|
419
|
-
updateMCPServer(
|
|
420
|
-
id: string,
|
|
421
|
-
updates: Partial<IMCPServerConfig>
|
|
422
|
-
): Promise<void>;
|
|
423
|
-
/**
|
|
424
|
-
* Get the API key saved in the settings file for a given provider.
|
|
425
|
-
*
|
|
426
|
-
* @param id - the id of the provider.
|
|
427
|
-
*/
|
|
428
|
-
getApiKey(id: string): string;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
/**
|
|
432
|
-
* Token for the AI settings model.
|
|
433
|
-
*/
|
|
434
|
-
export const IAISettingsModel = new Token<IAISettingsModel>(
|
|
435
|
-
'@jupyterlite/ai:IAISettingsModel'
|
|
436
|
-
);
|
|
437
|
-
|
|
438
|
-
/* THE AGENT MANAGER */
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* A namespace for agent manager.
|
|
442
|
-
*/
|
|
443
|
-
export namespace IAgentManager {
|
|
444
|
-
/**
|
|
445
|
-
* Configuration options for the AgentManager
|
|
446
|
-
*/
|
|
447
|
-
export interface IOptions {
|
|
448
|
-
/**
|
|
449
|
-
* AI settings model for configuration
|
|
450
|
-
*/
|
|
451
|
-
settingsModel: IAISettingsModel;
|
|
452
|
-
|
|
453
|
-
/**
|
|
454
|
-
* Optional tool registry for managing available tools
|
|
455
|
-
*/
|
|
456
|
-
toolRegistry?: IToolRegistry;
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Optional provider registry for model creation
|
|
460
|
-
*/
|
|
461
|
-
providerRegistry?: IProviderRegistry;
|
|
462
|
-
|
|
463
|
-
/**
|
|
464
|
-
* The skill registry for discovering skills.
|
|
465
|
-
*/
|
|
466
|
-
skillRegistry?: ISkillRegistry;
|
|
467
|
-
|
|
468
|
-
/**
|
|
469
|
-
* The secrets manager.
|
|
470
|
-
*/
|
|
471
|
-
secretsManager?: ISecretsManager;
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* The active provider to use with this agent.
|
|
475
|
-
*/
|
|
476
|
-
activeProvider?: string;
|
|
477
|
-
|
|
478
|
-
/**
|
|
479
|
-
* Initial token usage.
|
|
480
|
-
*/
|
|
481
|
-
tokenUsage?: ITokenUsage;
|
|
482
|
-
|
|
483
|
-
/**
|
|
484
|
-
* JupyterLab render mime registry for discovering supported MIME types.
|
|
485
|
-
*/
|
|
486
|
-
renderMimeRegistry?: IRenderMimeRegistry;
|
|
487
|
-
}
|
|
24
|
+
/* THE CHAT MODELS HANDLER */
|
|
488
25
|
|
|
26
|
+
export interface IAIChatModel extends IChatModel {
|
|
489
27
|
/**
|
|
490
|
-
*
|
|
28
|
+
* A signal emitting when the chat name has changed.
|
|
491
29
|
*/
|
|
492
|
-
|
|
493
|
-
message_start: {
|
|
494
|
-
messageId: string;
|
|
495
|
-
};
|
|
496
|
-
message_chunk: {
|
|
497
|
-
messageId: string;
|
|
498
|
-
chunk: string;
|
|
499
|
-
fullContent: string;
|
|
500
|
-
};
|
|
501
|
-
message_complete: {
|
|
502
|
-
messageId: string;
|
|
503
|
-
content: string;
|
|
504
|
-
};
|
|
505
|
-
tool_call_start: {
|
|
506
|
-
callId: string;
|
|
507
|
-
toolName: string;
|
|
508
|
-
input: string;
|
|
509
|
-
};
|
|
510
|
-
tool_call_complete: {
|
|
511
|
-
callId: string;
|
|
512
|
-
toolName: string;
|
|
513
|
-
outputData: unknown;
|
|
514
|
-
isError: boolean;
|
|
515
|
-
};
|
|
516
|
-
tool_approval_request: {
|
|
517
|
-
approvalId: string;
|
|
518
|
-
toolCallId: string;
|
|
519
|
-
toolName: string;
|
|
520
|
-
args: unknown;
|
|
521
|
-
};
|
|
522
|
-
tool_approval_resolved: {
|
|
523
|
-
approvalId: string;
|
|
524
|
-
approved: boolean;
|
|
525
|
-
};
|
|
526
|
-
error: {
|
|
527
|
-
error: Error;
|
|
528
|
-
};
|
|
529
|
-
}
|
|
530
|
-
|
|
30
|
+
readonly nameChanged: ISignal<IAIChatModel, string>;
|
|
531
31
|
/**
|
|
532
|
-
*
|
|
32
|
+
* The title of the chat.
|
|
533
33
|
*/
|
|
534
|
-
|
|
535
|
-
T extends keyof IAgentEventTypeMap = keyof IAgentEventTypeMap
|
|
536
|
-
> = T extends keyof IAgentEventTypeMap
|
|
537
|
-
? {
|
|
538
|
-
type: T;
|
|
539
|
-
data: IAgentEventTypeMap[T];
|
|
540
|
-
}
|
|
541
|
-
: never;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
export interface IAgentManager {
|
|
34
|
+
title: string | null;
|
|
545
35
|
/**
|
|
546
|
-
*
|
|
36
|
+
* A signal emitting when the chat title has changed.
|
|
547
37
|
*/
|
|
548
|
-
|
|
38
|
+
readonly titleChanged: ISignal<IAIChatModel, string | null>;
|
|
549
39
|
/**
|
|
550
|
-
*
|
|
40
|
+
* Whether to save the chat automatically.
|
|
551
41
|
*/
|
|
552
|
-
|
|
42
|
+
autosave: boolean;
|
|
553
43
|
/**
|
|
554
|
-
*
|
|
44
|
+
* A signal emitting when the autosave flag changed.
|
|
555
45
|
*/
|
|
556
|
-
readonly
|
|
46
|
+
readonly autosaveChanged: ISignal<IAIChatModel, boolean>;
|
|
557
47
|
/**
|
|
558
|
-
*
|
|
48
|
+
* Whether save/restore is available.
|
|
559
49
|
*/
|
|
560
|
-
readonly
|
|
50
|
+
readonly saveAvailable: boolean;
|
|
561
51
|
/**
|
|
562
|
-
*
|
|
52
|
+
* A signal emitting when the token usage changed.
|
|
563
53
|
*/
|
|
564
54
|
readonly tokenUsageChanged: ISignal<IAgentManager, ITokenUsage>;
|
|
565
55
|
/**
|
|
566
|
-
*
|
|
567
|
-
*/
|
|
568
|
-
refreshSkills(): void;
|
|
569
|
-
/**
|
|
570
|
-
* Sets the selected tools by name and reinitializes the agent.
|
|
571
|
-
* @param toolNames Array of tool names to select
|
|
56
|
+
* The agent manager used in the model.
|
|
572
57
|
*/
|
|
573
|
-
|
|
58
|
+
readonly agentManager: IAgentManager;
|
|
574
59
|
/**
|
|
575
|
-
*
|
|
576
|
-
* @returns Record of selected tools
|
|
60
|
+
* Save the chat as json file.
|
|
577
61
|
*/
|
|
578
|
-
|
|
62
|
+
save(): Promise<void>;
|
|
579
63
|
/**
|
|
580
|
-
*
|
|
581
|
-
*
|
|
582
|
-
* @
|
|
583
|
-
|
|
584
|
-
hasValidConfig(): boolean;
|
|
585
|
-
/**
|
|
586
|
-
* Clears conversation history and resets agent state.
|
|
587
|
-
*/
|
|
588
|
-
clearHistory(): Promise<void>;
|
|
589
|
-
/**
|
|
590
|
-
* Sets the conversation history with a list of messages from the chat.
|
|
591
|
-
* @param messages The chat messages to set as history
|
|
64
|
+
* Restore the chat from a json file.
|
|
65
|
+
*
|
|
66
|
+
* @param silent - Whether a log should be displayed in the console if the
|
|
67
|
+
* restoration is not possible.
|
|
592
68
|
*/
|
|
593
|
-
|
|
69
|
+
restore(filepath: string, silent?: boolean): Promise<boolean>;
|
|
594
70
|
/**
|
|
595
|
-
*
|
|
71
|
+
* Request a title to this chat, regarding the message history.
|
|
596
72
|
*/
|
|
597
|
-
|
|
73
|
+
requestTitle(): Promise<string>;
|
|
598
74
|
/**
|
|
599
|
-
*
|
|
600
|
-
* @param
|
|
601
|
-
* @param reason Optional reason for approval
|
|
75
|
+
* Removes a queued message by its ID.
|
|
76
|
+
* @param messageId The ID of the queued message to remove
|
|
602
77
|
*/
|
|
603
|
-
|
|
78
|
+
removeQueuedMessage(messageId: string): void;
|
|
604
79
|
/**
|
|
605
|
-
*
|
|
606
|
-
* @param
|
|
607
|
-
* @param reason Optional reason for rejection
|
|
80
|
+
* Reorders queued messages by their IDs.
|
|
81
|
+
* @param messageIds Array of message IDs in the desired order
|
|
608
82
|
*/
|
|
609
|
-
|
|
83
|
+
reorderQueuedMessages(messageIds: string[]): void;
|
|
610
84
|
/**
|
|
611
|
-
*
|
|
612
|
-
*
|
|
613
|
-
* @param
|
|
85
|
+
* Edits a queued message by its ID.
|
|
86
|
+
* @param messageId The ID of the queued message to edit
|
|
87
|
+
* @param newBody The new body of the message
|
|
614
88
|
*/
|
|
615
|
-
|
|
89
|
+
editQueuedMessage(messageId: string, newBody: string): void;
|
|
616
90
|
/**
|
|
617
|
-
*
|
|
618
|
-
* @param messages - the messages sequence to send to the model.
|
|
91
|
+
* The current message queue
|
|
619
92
|
*/
|
|
620
|
-
|
|
93
|
+
messageQueue: any[];
|
|
621
94
|
/**
|
|
622
|
-
*
|
|
623
|
-
* Sets up the agent with model configuration, tools, and MCP tools.
|
|
95
|
+
* Whether the chat is currently busy processing a message
|
|
624
96
|
*/
|
|
625
|
-
|
|
97
|
+
isBusy: boolean;
|
|
626
98
|
}
|
|
627
99
|
|
|
628
|
-
/**
|
|
629
|
-
* Token for the agent manager.
|
|
630
|
-
*/
|
|
631
|
-
export const IAgentManager = new Token<IAgentManager>(
|
|
632
|
-
'@jupyterlite/ai:IAgentManager'
|
|
633
|
-
);
|
|
634
|
-
|
|
635
|
-
/* The AGENT MANAGER FACTORY */
|
|
636
|
-
/**
|
|
637
|
-
* The interface for a agent manager factory.
|
|
638
|
-
*/
|
|
639
|
-
export interface IAgentManagerFactory {
|
|
640
|
-
/**
|
|
641
|
-
* Create a new agent.
|
|
642
|
-
*/
|
|
643
|
-
createAgent(options: IAgentManager.IOptions): IAgentManager;
|
|
644
|
-
/**
|
|
645
|
-
* Signal emitted when MCP connection status changes
|
|
646
|
-
*/
|
|
647
|
-
readonly mcpConnectionChanged: ISignal<IAgentManagerFactory, boolean>;
|
|
648
|
-
/**
|
|
649
|
-
* Checks whether a specific MCP server is connected.
|
|
650
|
-
* @param serverName The name of the MCP server to check
|
|
651
|
-
* @returns True if the server is connected, false otherwise
|
|
652
|
-
*/
|
|
653
|
-
isMCPServerConnected(serverName: string): boolean;
|
|
654
|
-
/**
|
|
655
|
-
* Gets the MCP tools from connected servers
|
|
656
|
-
*/
|
|
657
|
-
getMCPTools(): Promise<ToolMap>;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
/*
|
|
661
|
-
* Token for the agent manager factory.
|
|
662
|
-
*/
|
|
663
|
-
export const IAgentManagerFactory = new Token<IAgentManagerFactory>(
|
|
664
|
-
'@jupyterlite/ai:IAgentManagerFactory'
|
|
665
|
-
);
|
|
666
|
-
|
|
667
|
-
/* THE CHAT MODELS HANDLER */
|
|
668
|
-
|
|
669
100
|
/**
|
|
670
101
|
* The interface for the chat model handler.
|
|
671
102
|
*/
|
|
@@ -673,7 +104,7 @@ export interface IChatModelHandler {
|
|
|
673
104
|
/**
|
|
674
105
|
* The function to create a new model.
|
|
675
106
|
*/
|
|
676
|
-
createModel(options: ICreateChatOptions):
|
|
107
|
+
createModel(options: ICreateChatOptions): IAIChatModel;
|
|
677
108
|
/**
|
|
678
109
|
* The active cell manager (to copy code from chat to cell).
|
|
679
110
|
*/
|
|
@@ -713,138 +144,17 @@ export const IChatModelHandler = new Token<IChatModelHandler>(
|
|
|
713
144
|
'@jupyterlite/ai:IChatModelHandler'
|
|
714
145
|
);
|
|
715
146
|
|
|
716
|
-
/* THE DIFF MANAGER */
|
|
717
|
-
|
|
718
|
-
/**
|
|
719
|
-
* Parameters for showing cell diff
|
|
720
|
-
*/
|
|
721
|
-
export interface IShowCellDiffParams {
|
|
722
|
-
/**
|
|
723
|
-
* Original cell content
|
|
724
|
-
*/
|
|
725
|
-
original: string;
|
|
726
|
-
/**
|
|
727
|
-
* Modified cell content
|
|
728
|
-
*/
|
|
729
|
-
modified: string;
|
|
730
|
-
/**
|
|
731
|
-
* Optional cell ID
|
|
732
|
-
*/
|
|
733
|
-
cellId?: string;
|
|
734
|
-
/**
|
|
735
|
-
* Whether to show action buttons in the diff view
|
|
736
|
-
*/
|
|
737
|
-
showActionButtons?: boolean;
|
|
738
|
-
/**
|
|
739
|
-
* Whether to open the diff view
|
|
740
|
-
*/
|
|
741
|
-
openDiff?: boolean;
|
|
742
|
-
/**
|
|
743
|
-
* Optional path to the notebook
|
|
744
|
-
*/
|
|
745
|
-
notebookPath?: string;
|
|
746
|
-
}
|
|
747
|
-
|
|
748
147
|
/**
|
|
749
|
-
*
|
|
148
|
+
* Interface for the AI settings model with JupyterLab-specific features.
|
|
149
|
+
* Extends the base IAISettingsModel from @jupyternaut/agent which already includes VDomRenderer.IModel.
|
|
750
150
|
*/
|
|
751
|
-
export interface
|
|
752
|
-
|
|
753
|
-
* Original file content
|
|
754
|
-
*/
|
|
755
|
-
original: string;
|
|
756
|
-
/**
|
|
757
|
-
* Modified file content
|
|
758
|
-
*/
|
|
759
|
-
modified: string;
|
|
760
|
-
/**
|
|
761
|
-
* Optional file path
|
|
762
|
-
*/
|
|
763
|
-
filePath?: string;
|
|
764
|
-
/**
|
|
765
|
-
* Whether to show action buttons in the diff view
|
|
766
|
-
*/
|
|
767
|
-
showActionButtons?: boolean;
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
/**
|
|
771
|
-
* Interface for managing diff operations
|
|
772
|
-
*/
|
|
773
|
-
export interface IDiffManager {
|
|
774
|
-
/**
|
|
775
|
-
* Show diff between original and modified cell content
|
|
776
|
-
*/
|
|
777
|
-
showCellDiff(params: IShowCellDiffParams): Promise<void>;
|
|
778
|
-
/**
|
|
779
|
-
* Show diff between original and modified file content
|
|
780
|
-
*/
|
|
781
|
-
showFileDiff(params: IShowFileDiffParams): Promise<void>;
|
|
151
|
+
export interface IAISettingsModel extends IBaseAISettingsModel {
|
|
152
|
+
// Extends the base IAISettingsModel with JupyterLab-specific features
|
|
782
153
|
}
|
|
783
154
|
|
|
784
155
|
/**
|
|
785
|
-
* Token for the
|
|
156
|
+
* Token for the AI settings model.
|
|
786
157
|
*/
|
|
787
|
-
export const
|
|
788
|
-
'@jupyterlite/ai:
|
|
158
|
+
export const IAISettingsModel = new Token<IAISettingsModel>(
|
|
159
|
+
'@jupyterlite/ai:IAISettingsModel'
|
|
789
160
|
);
|
|
790
|
-
|
|
791
|
-
/**
|
|
792
|
-
* Interface for token usage statistics from AI model interactions
|
|
793
|
-
*/
|
|
794
|
-
export interface ITokenUsage {
|
|
795
|
-
/**
|
|
796
|
-
* Number of input tokens consumed (prompt tokens)
|
|
797
|
-
*/
|
|
798
|
-
inputTokens: number;
|
|
799
|
-
|
|
800
|
-
/**
|
|
801
|
-
* Number of output tokens generated (completion tokens)
|
|
802
|
-
*/
|
|
803
|
-
outputTokens: number;
|
|
804
|
-
|
|
805
|
-
/**
|
|
806
|
-
* Estimated prompt tokens used by the most recent model request.
|
|
807
|
-
* This is based on the final step of the latest request.
|
|
808
|
-
*/
|
|
809
|
-
lastRequestInputTokens?: number;
|
|
810
|
-
|
|
811
|
-
/**
|
|
812
|
-
* Configured context window size for the active provider/model.
|
|
813
|
-
*/
|
|
814
|
-
contextWindow?: number;
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
/**
|
|
818
|
-
* The string that replaces a secret key in settings.
|
|
819
|
-
*/
|
|
820
|
-
export const SECRETS_NAMESPACE = '@jupyterlite/ai:providers';
|
|
821
|
-
export const SECRETS_REPLACEMENT = '***';
|
|
822
|
-
|
|
823
|
-
/**
|
|
824
|
-
* Internal interface for AI provider secret access within the shared namespace.
|
|
825
|
-
*/
|
|
826
|
-
export interface IAISecretsAccess {
|
|
827
|
-
/**
|
|
828
|
-
* Whether secrets access is currently available.
|
|
829
|
-
*/
|
|
830
|
-
readonly isAvailable: boolean;
|
|
831
|
-
|
|
832
|
-
/**
|
|
833
|
-
* Get a secret value by ID.
|
|
834
|
-
*/
|
|
835
|
-
get(id: string): Promise<string | undefined>;
|
|
836
|
-
|
|
837
|
-
/**
|
|
838
|
-
* Set a secret value by ID.
|
|
839
|
-
*/
|
|
840
|
-
set(id: string, value: string): Promise<void>;
|
|
841
|
-
|
|
842
|
-
/**
|
|
843
|
-
* Attach an input field to a secret ID.
|
|
844
|
-
*/
|
|
845
|
-
attach(
|
|
846
|
-
id: string,
|
|
847
|
-
input: HTMLInputElement,
|
|
848
|
-
callback?: (value: string) => void
|
|
849
|
-
): Promise<void>;
|
|
850
|
-
}
|