@jupyterlite/ai 0.9.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +5 -214
  2. package/lib/agent.d.ts +58 -66
  3. package/lib/agent.js +291 -310
  4. package/lib/approval-buttons.d.ts +19 -82
  5. package/lib/approval-buttons.js +36 -289
  6. package/lib/chat-model-registry.d.ts +6 -0
  7. package/lib/chat-model-registry.js +4 -1
  8. package/lib/chat-model.d.ts +26 -54
  9. package/lib/chat-model.js +277 -303
  10. package/lib/components/clear-button.d.ts +6 -1
  11. package/lib/components/clear-button.js +10 -6
  12. package/lib/components/completion-status.d.ts +5 -0
  13. package/lib/components/completion-status.js +5 -4
  14. package/lib/components/model-select.d.ts +6 -1
  15. package/lib/components/model-select.js +13 -16
  16. package/lib/components/stop-button.d.ts +6 -1
  17. package/lib/components/stop-button.js +12 -8
  18. package/lib/components/token-usage-display.d.ts +5 -0
  19. package/lib/components/token-usage-display.js +2 -2
  20. package/lib/components/tool-select.d.ts +6 -1
  21. package/lib/components/tool-select.js +10 -9
  22. package/lib/index.d.ts +1 -0
  23. package/lib/index.js +61 -81
  24. package/lib/models/settings-model.d.ts +1 -1
  25. package/lib/models/settings-model.js +40 -26
  26. package/lib/providers/built-in-providers.js +38 -19
  27. package/lib/providers/models.d.ts +3 -3
  28. package/lib/providers/provider-registry.d.ts +3 -4
  29. package/lib/providers/provider-registry.js +1 -4
  30. package/lib/tokens.d.ts +5 -6
  31. package/lib/tools/commands.d.ts +2 -1
  32. package/lib/tools/commands.js +36 -49
  33. package/lib/widgets/ai-settings.d.ts +6 -0
  34. package/lib/widgets/ai-settings.js +72 -71
  35. package/lib/widgets/main-area-chat.d.ts +2 -0
  36. package/lib/widgets/main-area-chat.js +5 -2
  37. package/lib/widgets/provider-config-dialog.d.ts +2 -0
  38. package/lib/widgets/provider-config-dialog.js +34 -34
  39. package/package.json +13 -13
  40. package/schema/settings-model.json +3 -2
  41. package/src/agent.ts +360 -372
  42. package/src/approval-buttons.ts +43 -389
  43. package/src/chat-model-registry.ts +9 -1
  44. package/src/chat-model.ts +399 -370
  45. package/src/completion/completion-provider.ts +2 -3
  46. package/src/components/clear-button.tsx +18 -6
  47. package/src/components/completion-status.tsx +18 -4
  48. package/src/components/model-select.tsx +25 -16
  49. package/src/components/stop-button.tsx +22 -9
  50. package/src/components/token-usage-display.tsx +14 -2
  51. package/src/components/tool-select.tsx +27 -9
  52. package/src/index.ts +78 -134
  53. package/src/models/settings-model.ts +41 -27
  54. package/src/providers/built-in-providers.ts +38 -19
  55. package/src/providers/models.ts +3 -3
  56. package/src/providers/provider-registry.ts +4 -8
  57. package/src/tokens.ts +5 -6
  58. package/src/tools/commands.ts +40 -53
  59. package/src/widgets/ai-settings.tsx +153 -84
  60. package/src/widgets/main-area-chat.ts +8 -2
  61. package/src/widgets/provider-config-dialog.tsx +54 -41
  62. package/style/base.css +24 -73
  63. package/lib/mcp/browser.d.ts +0 -68
  64. package/lib/mcp/browser.js +0 -138
  65. package/lib/tools/file.d.ts +0 -36
  66. package/lib/tools/file.js +0 -351
  67. package/lib/tools/notebook.d.ts +0 -40
  68. package/lib/tools/notebook.js +0 -779
  69. package/src/mcp/browser.ts +0 -220
  70. package/src/tools/file.ts +0 -438
  71. package/src/tools/notebook.ts +0 -986
@@ -15,15 +15,17 @@ export const anthropicProvider: IProviderInfo = {
15
15
  name: 'Anthropic Claude',
16
16
  apiKeyRequirement: 'required',
17
17
  defaultModels: [
18
+ 'claude-opus-4-5',
19
+ 'claude-opus-4-5-20251101',
18
20
  'claude-sonnet-4-5',
19
21
  'claude-sonnet-4-5-20250929',
20
22
  'claude-haiku-4-5',
21
23
  'claude-haiku-4-5-20251001',
22
24
  'claude-opus-4-1',
23
- 'claude-opus-4-0',
24
- 'claude-sonnet-4-0',
25
25
  'claude-opus-4-1-20250805',
26
+ 'claude-opus-4-0',
26
27
  'claude-opus-4-20250514',
28
+ 'claude-sonnet-4-0',
27
29
  'claude-sonnet-4-20250514',
28
30
  'claude-3-7-sonnet-latest',
29
31
  'claude-3-7-sonnet-20250219',
@@ -58,8 +60,11 @@ export const googleProvider: IProviderInfo = {
58
60
  name: 'Google Generative AI',
59
61
  apiKeyRequirement: 'required',
60
62
  defaultModels: [
61
- 'gemini-2.5-flash',
63
+ 'gemini-3-pro-preview',
64
+ 'gemini-3-pro-image-preview',
65
+ 'gemini-3-flash-preview',
62
66
  'gemini-2.5-pro',
67
+ 'gemini-2.5-flash',
63
68
  'gemini-2.5-flash-image-preview',
64
69
  'gemini-2.5-flash-lite',
65
70
  'gemini-2.5-flash-lite-preview-09-2025',
@@ -84,6 +89,9 @@ export const googleProvider: IProviderInfo = {
84
89
  'gemini-1.5-pro-latest',
85
90
  'gemini-1.5-pro-001',
86
91
  'gemini-1.5-pro-002',
92
+ 'gemini-pro-latest',
93
+ 'gemini-flash-latest',
94
+ 'gemini-flash-lite-latest',
87
95
  'gemini-exp-1206',
88
96
  'gemma-3-12b-it',
89
97
  'gemma-3-27b-it'
@@ -150,12 +158,32 @@ export const openaiProvider: IProviderInfo = {
150
158
  name: 'OpenAI',
151
159
  apiKeyRequirement: 'required',
152
160
  defaultModels: [
153
- 'o1',
154
- 'o1-2024-12-17',
155
- 'o3-mini',
156
- 'o3-mini-2025-01-31',
161
+ 'gpt-5.2',
162
+ 'gpt-5.2-chat-latest',
163
+ 'gpt-5.2-pro',
164
+ 'gpt-5.1',
165
+ 'gpt-5.1-chat-latest',
166
+ 'gpt-5.1-codex',
167
+ 'gpt-5.1-codex-mini',
168
+ 'gpt-5.1-codex-max',
169
+ 'gpt-5',
170
+ 'gpt-5-2025-08-07',
171
+ 'gpt-5-chat-latest',
172
+ 'gpt-5-codex',
173
+ 'gpt-5-pro',
174
+ 'gpt-5-pro-2025-10-06',
175
+ 'gpt-5-mini',
176
+ 'gpt-5-mini-2025-08-07',
177
+ 'gpt-5-nano',
178
+ 'gpt-5-nano-2025-08-07',
157
179
  'o3',
158
180
  'o3-2025-04-16',
181
+ 'o3-mini',
182
+ 'o3-mini-2025-01-31',
183
+ 'o1',
184
+ 'o1-2024-12-17',
185
+ 'gpt-4.5-preview',
186
+ 'gpt-4.5-preview-2025-02-27',
159
187
  'gpt-4.1',
160
188
  'gpt-4.1-2025-04-14',
161
189
  'gpt-4.1-mini',
@@ -168,23 +196,14 @@ export const openaiProvider: IProviderInfo = {
168
196
  'gpt-4o-2024-11-20',
169
197
  'gpt-4o-mini',
170
198
  'gpt-4o-mini-2024-07-18',
199
+ 'chatgpt-4o-latest',
171
200
  'gpt-4-turbo',
172
201
  'gpt-4-turbo-2024-04-09',
173
202
  'gpt-4',
174
203
  'gpt-4-0613',
175
- 'gpt-4.5-preview',
176
- 'gpt-4.5-preview-2025-02-27',
177
- 'gpt-3.5-turbo-0125',
178
204
  'gpt-3.5-turbo',
179
- 'gpt-3.5-turbo-1106',
180
- 'chatgpt-4o-latest',
181
- 'gpt-5',
182
- 'gpt-5-2025-08-07',
183
- 'gpt-5-mini',
184
- 'gpt-5-mini-2025-08-07',
185
- 'gpt-5-nano',
186
- 'gpt-5-nano-2025-08-07',
187
- 'gpt-5-chat-latest'
205
+ 'gpt-3.5-turbo-0125',
206
+ 'gpt-3.5-turbo-1106'
188
207
  ],
189
208
  supportsBaseURL: true,
190
209
  supportsHeaders: true,
@@ -1,4 +1,4 @@
1
- import type { LanguageModelV2 } from '@ai-sdk/provider';
1
+ import type { LanguageModel } from 'ai';
2
2
  import type { IProviderRegistry } from '../tokens';
3
3
 
4
4
  /**
@@ -38,7 +38,7 @@ export interface IModelOptions {
38
38
  export function createCompletionModel(
39
39
  options: IModelOptions,
40
40
  registry?: IProviderRegistry
41
- ): LanguageModelV2 {
41
+ ): LanguageModel {
42
42
  if (!registry) {
43
43
  throw new Error('Provider registry not available');
44
44
  }
@@ -60,7 +60,7 @@ export function createCompletionModel(
60
60
  export function createModel(
61
61
  options: IModelOptions,
62
62
  registry?: IProviderRegistry
63
- ) {
63
+ ): LanguageModel {
64
64
  if (!registry) {
65
65
  throw new Error('Provider registry not available');
66
66
  }
@@ -1,7 +1,5 @@
1
1
  import { ISignal, Signal } from '@lumino/signaling';
2
- import type { LanguageModelV2 } from '@ai-sdk/provider';
3
- import type { Model } from '@openai/agents';
4
- import { aisdk } from '@openai/agents-extensions';
2
+ import type { LanguageModel } from 'ai';
5
3
  import type { IModelOptions } from './models';
6
4
  import { IProviderInfo, IProviderRegistry } from '../tokens';
7
5
 
@@ -50,15 +48,13 @@ export class ProviderRegistry implements IProviderRegistry {
50
48
  * @param options Model configuration options
51
49
  * @returns Chat model instance or null if creation fails
52
50
  */
53
- createChatModel(id: string, options: IModelOptions): Model | null {
51
+ createChatModel(id: string, options: IModelOptions): LanguageModel | null {
54
52
  const provider = this._providers[id];
55
53
  if (!provider) {
56
54
  return null;
57
55
  }
58
56
 
59
- const languageModel = provider.factory(options);
60
- // wrap with aisdk for compatibility with the agent framework
61
- return aisdk(languageModel);
57
+ return provider.factory(options);
62
58
  }
63
59
 
64
60
  /**
@@ -70,7 +66,7 @@ export class ProviderRegistry implements IProviderRegistry {
70
66
  createCompletionModel(
71
67
  id: string,
72
68
  options: IModelOptions
73
- ): LanguageModelV2 | null {
69
+ ): LanguageModel | null {
74
70
  const provider = this._providers[id];
75
71
  if (!provider) {
76
72
  return null;
package/src/tokens.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { Token } from '@lumino/coreutils';
2
2
  import { ISignal } from '@lumino/signaling';
3
- import { FunctionTool, Model } from '@openai/agents';
4
- import { LanguageModelV2 } from '@ai-sdk/provider';
3
+ import type { Tool, LanguageModel } from 'ai';
5
4
  import { AgentManager } from './agent';
6
5
  import type { AISettingsModel } from './models/settings-model';
7
6
  import type { IModelOptions } from './providers/models';
@@ -21,7 +20,7 @@ export namespace CommandIds {
21
20
  /**
22
21
  * Type definition for a tool
23
22
  */
24
- export type ITool = FunctionTool<any, any, any>;
23
+ export type ITool = Tool;
25
24
 
26
25
  /**
27
26
  * Interface for token usage statistics from AI model interactions
@@ -109,7 +108,7 @@ export const IProviderRegistry = new Token<IProviderRegistry>(
109
108
  * Interface for a provider factory function that creates language models
110
109
  */
111
110
  export interface IProviderFactory {
112
- (options: IModelOptions): LanguageModelV2;
111
+ (options: IModelOptions): LanguageModel;
113
112
  }
114
113
 
115
114
  /**
@@ -197,7 +196,7 @@ export interface IProviderRegistry {
197
196
  /**
198
197
  * Create a chat model instance for the given provider.
199
198
  */
200
- createChatModel(id: string, options: IModelOptions): Model | null;
199
+ createChatModel(id: string, options: IModelOptions): LanguageModel | null;
201
200
 
202
201
  /**
203
202
  * Create a completion model instance for the given provider.
@@ -205,7 +204,7 @@ export interface IProviderRegistry {
205
204
  createCompletionModel(
206
205
  id: string,
207
206
  options: IModelOptions
208
- ): LanguageModelV2 | null;
207
+ ): LanguageModel | null;
209
208
 
210
209
  /**
211
210
  * Get all available provider IDs.
@@ -1,5 +1,5 @@
1
1
  import { CommandRegistry } from '@lumino/commands';
2
- import { tool } from '@openai/agents';
2
+ import { tool } from 'ai';
3
3
  import { z } from 'zod';
4
4
  import { ITool } from '../tokens';
5
5
  import { AISettingsModel } from '../models/settings-model';
@@ -9,16 +9,17 @@ import { AISettingsModel } from '../models/settings-model';
9
9
  */
10
10
  export function createDiscoverCommandsTool(commands: CommandRegistry): ITool {
11
11
  return tool({
12
- name: 'discover_commands',
12
+ title: 'Discover Commands',
13
13
  description:
14
14
  'Discover all available JupyterLab commands with their metadata, arguments, and descriptions',
15
- parameters: z.object({
16
- // currently unused, but could be used to filter commands by a search term
15
+ inputSchema: z.object({
17
16
  query: z
18
17
  .string()
19
18
  .optional()
20
19
  .nullable()
21
- .describe('Optional search query to filter commands')
20
+ .describe(
21
+ "Optional search query to filter commands. It doesn't need to be provided to list all commands"
22
+ )
22
23
  }),
23
24
  execute: async (input: { query?: string | null }) => {
24
25
  const { query } = input;
@@ -75,31 +76,30 @@ export function createDiscoverCommandsTool(commands: CommandRegistry): ITool {
75
76
  }
76
77
 
77
78
  /**
78
- * Create a tool to execute a specific JupyterLab command
79
+ * Create a tool to execute a specific JupyterLab command.
80
+ * Commands in the settings' commandsRequiringApproval list will need approval.
79
81
  */
80
82
  export function createExecuteCommandTool(
81
83
  commands: CommandRegistry,
82
84
  settingsModel: AISettingsModel
83
85
  ): ITool {
84
86
  return tool({
85
- name: 'execute_command',
87
+ title: 'Execute Command',
86
88
  description:
87
89
  'Execute a specific JupyterLab command with optional arguments',
88
- parameters: z.object({
90
+ inputSchema: z.object({
89
91
  commandId: z.string().describe('The ID of the command to execute'),
90
92
  args: z
91
- .any()
93
+ .record(z.string(), z.unknown())
92
94
  .optional()
93
- .describe('Optional arguments to pass to the command')
95
+ .describe(
96
+ 'Optional arguments object to pass to the command (must be an object, not a string)'
97
+ )
94
98
  }),
95
- needsApproval: async (context, { commandId }) => {
96
- // Use configurable list of commands requiring approval
99
+ needsApproval: (input: { commandId: string; args?: any }) => {
97
100
  const commandsRequiringApproval =
98
- settingsModel.config.commandsRequiringApproval;
99
-
100
- return commandsRequiringApproval.some(
101
- cmd => commandId.includes(cmd) || cmd.includes(commandId)
102
- );
101
+ settingsModel.config.commandsRequiringApproval || [];
102
+ return commandsRequiringApproval.includes(input.commandId);
103
103
  },
104
104
  execute: async (input: { commandId: string; args?: any }) => {
105
105
  const { commandId, args } = input;
@@ -112,45 +112,32 @@ export function createExecuteCommandTool(
112
112
  };
113
113
  }
114
114
 
115
- try {
116
- // Execute the command
117
- const result = await commands.execute(commandId, args);
115
+ // Execute the command
116
+ const result = await commands.execute(commandId, args);
118
117
 
119
- // Handle Widget objects specially (including subclasses like DocumentWidget)
120
- let serializedResult;
121
- if (
122
- result &&
123
- typeof result === 'object' &&
124
- (result.constructor?.name?.includes('Widget') || result.id)
125
- ) {
126
- serializedResult = {
127
- type: result.constructor?.name || 'Widget',
128
- id: result.id,
129
- title: result.title?.label || result.title,
130
- className: result.className
131
- };
132
- } else {
133
- // For other objects, try JSON serialization with fallback
134
- try {
135
- serializedResult = JSON.parse(JSON.stringify(result));
136
- } catch {
137
- serializedResult = result
138
- ? '[Complex object - cannot serialize]'
139
- : 'Command executed successfully';
140
- }
141
- }
142
-
143
- return {
144
- success: true,
145
- commandId,
146
- result: serializedResult
147
- };
148
- } catch (error) {
149
- return {
150
- success: false,
151
- error: `Failed to execute command '${commandId}': ${error instanceof Error ? error.message : String(error)}`
118
+ // Handle Widget objects specially by extracting id and title
119
+ let serializedResult;
120
+ if (result && typeof result === 'object' && result.id) {
121
+ serializedResult = {
122
+ id: result.id,
123
+ title: result.title?.label || result.title
152
124
  };
125
+ } else {
126
+ // For other objects, try JSON serialization with fallback
127
+ try {
128
+ serializedResult = JSON.parse(JSON.stringify(result));
129
+ } catch {
130
+ serializedResult = result
131
+ ? '[Complex object - cannot serialize]'
132
+ : 'Command executed successfully';
133
+ }
153
134
  }
135
+
136
+ return {
137
+ success: true,
138
+ commandId,
139
+ result: serializedResult
140
+ };
154
141
  }
155
142
  });
156
143
  }