@jupyterlite/ai 0.6.2 → 0.7.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 (65) hide show
  1. package/README.md +1 -1
  2. package/lib/base-completer.d.ts +0 -5
  3. package/lib/chat-handler.d.ts +19 -5
  4. package/lib/chat-handler.js +47 -26
  5. package/lib/completion-provider.d.ts +2 -2
  6. package/lib/completion-provider.js +4 -3
  7. package/lib/components/stop-button.d.ts +0 -1
  8. package/lib/default-providers/Anthropic/completer.d.ts +0 -2
  9. package/lib/default-providers/Anthropic/completer.js +2 -4
  10. package/lib/default-providers/ChromeAI/completer.d.ts +0 -2
  11. package/lib/default-providers/ChromeAI/completer.js +2 -4
  12. package/lib/default-providers/ChromeAI/instructions.d.ts +4 -0
  13. package/lib/default-providers/ChromeAI/instructions.js +18 -0
  14. package/lib/default-providers/MistralAI/completer.d.ts +0 -2
  15. package/lib/default-providers/MistralAI/completer.js +3 -4
  16. package/lib/default-providers/Ollama/completer.d.ts +17 -0
  17. package/lib/default-providers/Ollama/completer.js +49 -0
  18. package/lib/default-providers/Ollama/instructions.d.ts +2 -0
  19. package/lib/default-providers/Ollama/instructions.js +70 -0
  20. package/lib/default-providers/Ollama/settings-schema.json +146 -0
  21. package/lib/default-providers/OpenAI/completer.d.ts +0 -2
  22. package/lib/default-providers/OpenAI/completer.js +2 -4
  23. package/lib/default-providers/WebLLM/completer.d.ts +27 -0
  24. package/lib/default-providers/WebLLM/completer.js +136 -0
  25. package/lib/default-providers/WebLLM/instructions.d.ts +6 -0
  26. package/lib/default-providers/WebLLM/instructions.js +32 -0
  27. package/lib/default-providers/WebLLM/settings-schema.json +21 -0
  28. package/lib/default-providers/index.js +119 -4
  29. package/lib/index.d.ts +2 -2
  30. package/lib/index.js +16 -26
  31. package/lib/provider.d.ts +11 -13
  32. package/lib/provider.js +120 -52
  33. package/lib/settings/index.d.ts +0 -1
  34. package/lib/settings/index.js +0 -1
  35. package/lib/settings/panel.d.ts +37 -8
  36. package/lib/settings/panel.js +225 -131
  37. package/lib/tokens.d.ts +21 -2
  38. package/lib/types/ai-model.d.ts +24 -0
  39. package/lib/types/ai-model.js +5 -0
  40. package/package.json +14 -11
  41. package/schema/provider-registry.json +0 -6
  42. package/src/base-completer.ts +0 -6
  43. package/src/chat-handler.ts +40 -7
  44. package/src/completion-provider.ts +2 -2
  45. package/src/default-providers/Anthropic/completer.ts +0 -5
  46. package/src/default-providers/ChromeAI/completer.ts +0 -5
  47. package/src/default-providers/ChromeAI/instructions.ts +21 -0
  48. package/src/default-providers/MistralAI/completer.ts +0 -5
  49. package/src/default-providers/Ollama/completer.ts +62 -0
  50. package/src/default-providers/Ollama/instructions.ts +70 -0
  51. package/src/default-providers/OpenAI/completer.ts +0 -5
  52. package/src/default-providers/WebLLM/completer.ts +162 -0
  53. package/src/default-providers/WebLLM/instructions.ts +33 -0
  54. package/src/default-providers/index.ts +151 -14
  55. package/src/index.ts +17 -29
  56. package/src/provider.ts +132 -45
  57. package/src/settings/index.ts +0 -1
  58. package/src/settings/panel.tsx +207 -73
  59. package/src/tokens.ts +23 -2
  60. package/src/types/ai-model.ts +37 -0
  61. package/src/types/service-worker.d.ts +6 -0
  62. package/style/base.css +5 -0
  63. package/lib/settings/settings-connector.d.ts +0 -31
  64. package/lib/settings/settings-connector.js +0 -61
  65. package/src/settings/settings-connector.ts +0 -88
package/lib/index.js CHANGED
@@ -3,14 +3,14 @@ import { IThemeManager } from '@jupyterlab/apputils';
3
3
  import { ICompletionProviderManager } from '@jupyterlab/completer';
4
4
  import { INotebookTracker } from '@jupyterlab/notebook';
5
5
  import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
6
- import { ISettingConnector, ISettingRegistry } from '@jupyterlab/settingregistry';
6
+ import { ISettingRegistry } from '@jupyterlab/settingregistry';
7
7
  import { IFormRendererRegistry } from '@jupyterlab/ui-components';
8
8
  import { ISecretsManager, SecretsManager } from 'jupyter-secrets-manager';
9
- import { ChatHandler } from './chat-handler';
9
+ import { ChatHandler, welcomeMessage } from './chat-handler';
10
10
  import { CompletionProvider } from './completion-provider';
11
11
  import { defaultProviderPlugins } from './default-providers';
12
12
  import { AIProviderRegistry } from './provider';
13
- import { aiSettingsRenderer, SettingConnector } from './settings';
13
+ import { aiSettingsRenderer } from './settings';
14
14
  import { IAIProviderRegistry, PLUGIN_IDS } from './tokens';
15
15
  import { stopItem } from './components/stop-button';
16
16
  const chatCommandRegistryPlugin = {
@@ -54,7 +54,7 @@ const chatPlugin = {
54
54
  chatHandler.config = { sendWithShiftEnter, enableCodeToolbar };
55
55
  chatHandler.personaName = personaName;
56
56
  }
57
- Promise.all([app.restored, settingsRegistry === null || settingsRegistry === void 0 ? void 0 : settingsRegistry.load(chatPlugin.id)])
57
+ Promise.all([app.restored, settingsRegistry?.load(chatPlugin.id)])
58
58
  .then(([, settings]) => {
59
59
  if (!settings) {
60
60
  console.warn('The SettingsRegistry is not loaded for the chat extension');
@@ -70,8 +70,8 @@ const chatPlugin = {
70
70
  const inputToolbarRegistry = InputToolbarRegistry.defaultToolbarRegistry();
71
71
  const stopButton = stopItem(() => chatHandler.stopStreaming());
72
72
  inputToolbarRegistry.addItem('stop', stopButton);
73
- chatHandler.writersChanged.connect((_, users) => {
74
- if (users.filter(user => user.username === chatHandler.personaName).length) {
73
+ chatHandler.writersChanged.connect((_, writers) => {
74
+ if (writers.filter(writer => writer.user.username === chatHandler.personaName).length) {
75
75
  inputToolbarRegistry.hide('send');
76
76
  inputToolbarRegistry.show('stop');
77
77
  }
@@ -86,7 +86,8 @@ const chatPlugin = {
86
86
  themeManager,
87
87
  rmRegistry,
88
88
  chatCommandRegistry,
89
- inputToolbarRegistry
89
+ inputToolbarRegistry,
90
+ welcomeMessage: welcomeMessage(providerRegistry.providers)
90
91
  });
91
92
  chatWidget.title.caption = 'Jupyterlite AI Chat';
92
93
  }
@@ -113,9 +114,9 @@ const providerRegistryPlugin = SecretsManager.sign(PLUGIN_IDS.providerRegistry,
113
114
  id: PLUGIN_IDS.providerRegistry,
114
115
  autoStart: true,
115
116
  requires: [IFormRendererRegistry, ISettingRegistry],
116
- optional: [IRenderMimeRegistry, ISecretsManager, ISettingConnector],
117
+ optional: [IRenderMimeRegistry, ISecretsManager],
117
118
  provides: IAIProviderRegistry,
118
- activate: (app, editorRegistry, settingRegistry, rmRegistry, secretsManager, settingConnector) => {
119
+ activate: (app, editorRegistry, settingRegistry, rmRegistry, secretsManager) => {
119
120
  const providerRegistry = new AIProviderRegistry({
120
121
  token,
121
122
  secretsManager
@@ -124,16 +125,17 @@ const providerRegistryPlugin = SecretsManager.sign(PLUGIN_IDS.providerRegistry,
124
125
  providerRegistry,
125
126
  secretsToken: token,
126
127
  rmRegistry,
127
- secretsManager,
128
- settingConnector
128
+ secretsManager
129
129
  }));
130
130
  settingRegistry
131
131
  .load(providerRegistryPlugin.id)
132
132
  .then(settings => {
133
+ if (!secretsManager) {
134
+ delete settings.schema.properties?.['UseSecretsManager'];
135
+ }
133
136
  const updateProvider = () => {
134
- var _a;
135
137
  // Update the settings to the AI providers.
136
- const providerSettings = ((_a = settings.get('AIprovider').composite) !== null && _a !== void 0 ? _a : {
138
+ const providerSettings = (settings.get('AIprovider').composite ?? {
137
139
  provider: 'None'
138
140
  });
139
141
  providerRegistry.setProvider({
@@ -150,23 +152,11 @@ const providerRegistryPlugin = SecretsManager.sign(PLUGIN_IDS.providerRegistry,
150
152
  return providerRegistry;
151
153
  }
152
154
  }));
153
- /**
154
- * Provides the settings connector as a separate plugin to allow for alternative
155
- * implementations that may want to fetch settings from a different source or
156
- * endpoint.
157
- */
158
- const settingsConnector = {
159
- id: PLUGIN_IDS.settingsConnector,
160
- description: 'Provides a settings connector which does not save passwords.',
161
- autoStart: true,
162
- provides: ISettingConnector,
163
- activate: (app) => new SettingConnector(app.serviceManager.settings)
164
- };
165
155
  export default [
166
156
  providerRegistryPlugin,
167
157
  chatCommandRegistryPlugin,
168
158
  chatPlugin,
169
159
  completerPlugin,
170
- settingsConnector,
171
160
  ...defaultProviderPlugins
172
161
  ];
162
+ export { IAIProviderRegistry } from './tokens';
package/lib/provider.d.ts CHANGED
@@ -1,13 +1,12 @@
1
1
  import { BaseLanguageModel } from '@langchain/core/language_models/base';
2
- import { BaseChatModel } from '@langchain/core/language_models/chat_models';
3
2
  import { ISignal } from '@lumino/signaling';
4
3
  import { ReadonlyPartialJSONObject } from '@lumino/coreutils';
5
4
  import { JSONSchema7 } from 'json-schema';
6
5
  import { ISecretsManager } from 'jupyter-secrets-manager';
7
- import { IBaseCompleter } from './base-completer';
8
6
  import { IAIProvider, IAIProviderRegistry, ISetProviderOptions } from './tokens';
7
+ import { AIChatModel, AICompleter } from './types/ai-model';
9
8
  export declare const chatSystemPrompt: (options: AIProviderRegistry.IPromptOptions) => string;
10
- export declare const COMPLETION_SYSTEM_PROMPT = "\nYou are an application built to provide helpful code completion suggestions.\nYou should only produce code. Keep comments to minimum, use the\nprogramming language comment syntax. Produce clean code.\nThe code is written in JupyterLab, a data analysis and code development\nenvironment which can execute code extended with additional syntax for\ninteractive features, such as magics.\nOnly give raw strings back, do not format the response using backticks.\nThe output should be a single string, and should correspond to what a human users\nwould write.\nDo not include the prompt in the output, only the string that should be appended to the current input.\n";
9
+ export declare const COMPLETION_SYSTEM_PROMPT = "\nYou are an application built to provide helpful code completion suggestions.\nYou should only produce code. Keep comments to minimum, use the\nprogramming language comment syntax. Produce clean code.\nThe code is written in JupyterLab, a data analysis and code development\nenvironment which can execute code extended with additional syntax for\ninteractive features, such as magics.\nOnly give raw strings back, do not format the response using backticks.\nThe output should be a single string, and should only contain the code that will complete the\ngive code passed as input, no explanation whatsoever.\nDo not include the prompt in the output, only the string that should be appended to the current input.\nHere is the code to complete:\n";
11
10
  export declare class AIProviderRegistry implements IAIProviderRegistry {
12
11
  /**
13
12
  * The constructor of the provider registry.
@@ -26,13 +25,13 @@ export declare class AIProviderRegistry implements IAIProviderRegistry {
26
25
  */
27
26
  get currentName(): string;
28
27
  /**
29
- * Get the current completer of the completion provider.
28
+ * Get the current AICompleter.
30
29
  */
31
- get currentCompleter(): IBaseCompleter | null;
30
+ get currentCompleter(): AICompleter | null;
32
31
  /**
33
- * Get the current llm chat model.
32
+ * Get the current AIChatModel.
34
33
  */
35
- get currentChatModel(): BaseChatModel | null;
34
+ get currentChatModel(): AIChatModel | null;
36
35
  /**
37
36
  * Get the settings schema of a given provider.
38
37
  */
@@ -41,6 +40,10 @@ export declare class AIProviderRegistry implements IAIProviderRegistry {
41
40
  * Get the instructions of a given provider.
42
41
  */
43
42
  getInstructions(provider: string): string | undefined;
43
+ /**
44
+ * Get the compatibility check function of a given provider.
45
+ */
46
+ getCompatibilityCheck(provider: string): (() => Promise<string | null>) | undefined;
44
47
  /**
45
48
  * Format an error message from the current provider.
46
49
  */
@@ -50,7 +53,7 @@ export declare class AIProviderRegistry implements IAIProviderRegistry {
50
53
  */
51
54
  get chatError(): string;
52
55
  /**
53
- * get the current completer error.
56
+ * Get the current completer error.
54
57
  */
55
58
  get completerError(): string;
56
59
  /**
@@ -65,14 +68,9 @@ export declare class AIProviderRegistry implements IAIProviderRegistry {
65
68
  */
66
69
  get providerChanged(): ISignal<IAIProviderRegistry, void>;
67
70
  private _secretsManager;
68
- private _currentProvider;
69
- private _completer;
70
- private _chatModel;
71
- private _name;
72
71
  private _providerChanged;
73
72
  private _chatError;
74
73
  private _completerError;
75
- private _providers;
76
74
  private _deferredProvider;
77
75
  }
78
76
  export declare namespace AIProviderRegistry {
package/lib/provider.js CHANGED
@@ -24,24 +24,16 @@ The code is written in JupyterLab, a data analysis and code development
24
24
  environment which can execute code extended with additional syntax for
25
25
  interactive features, such as magics.
26
26
  Only give raw strings back, do not format the response using backticks.
27
- The output should be a single string, and should correspond to what a human users
28
- would write.
27
+ The output should be a single string, and should only contain the code that will complete the
28
+ give code passed as input, no explanation whatsoever.
29
29
  Do not include the prompt in the output, only the string that should be appended to the current input.
30
+ Here is the code to complete:
30
31
  `;
31
32
  export class AIProviderRegistry {
32
33
  /**
33
34
  * The constructor of the provider registry.
34
35
  */
35
36
  constructor(options) {
36
- this._currentProvider = null;
37
- this._completer = null;
38
- this._chatModel = null;
39
- this._name = 'None';
40
- this._providerChanged = new Signal(this);
41
- this._chatError = '';
42
- this._completerError = '';
43
- this._providers = new Map();
44
- this._deferredProvider = null;
45
37
  this._secretsManager = options.secretsManager || null;
46
38
  Private.setToken(options.token);
47
39
  }
@@ -49,19 +41,18 @@ export class AIProviderRegistry {
49
41
  * Get the list of provider names.
50
42
  */
51
43
  get providers() {
52
- return Array.from(this._providers.keys());
44
+ return Array.from(Private.providers.keys());
53
45
  }
54
46
  /**
55
47
  * Add a new provider.
56
48
  */
57
49
  add(provider) {
58
- var _a;
59
- if (this._providers.has(provider.name)) {
50
+ if (Private.providers.has(provider.name)) {
60
51
  throw new Error(`A AI provider named '${provider.name}' is already registered`);
61
52
  }
62
- this._providers.set(provider.name, provider);
53
+ Private.providers.set(provider.name, provider);
63
54
  // Set the provider if the loading has been deferred.
64
- if (provider.name === ((_a = this._deferredProvider) === null || _a === void 0 ? void 0 : _a.name)) {
55
+ if (provider.name === this._deferredProvider?.name) {
65
56
  this.setProvider(this._deferredProvider);
66
57
  }
67
58
  }
@@ -69,48 +60,70 @@ export class AIProviderRegistry {
69
60
  * Get the current provider name.
70
61
  */
71
62
  get currentName() {
72
- return this._name;
63
+ return Private.getName();
73
64
  }
74
65
  /**
75
- * Get the current completer of the completion provider.
66
+ * Get the current AICompleter.
76
67
  */
77
68
  get currentCompleter() {
78
- if (this._name === 'None') {
69
+ if (Private.getName() === 'None') {
79
70
  return null;
80
71
  }
81
- return this._completer;
72
+ const completer = Private.getCompleter();
73
+ if (completer === null) {
74
+ return null;
75
+ }
76
+ return {
77
+ fetch: (request, context) => completer.fetch(request, context)
78
+ };
82
79
  }
83
80
  /**
84
- * Get the current llm chat model.
81
+ * Get the current AIChatModel.
85
82
  */
86
83
  get currentChatModel() {
87
- if (this._name === 'None') {
84
+ if (Private.getName() === 'None') {
85
+ return null;
86
+ }
87
+ const currentProvider = Private.providers.get(Private.getName()) ?? null;
88
+ const chatModel = Private.getChatModel();
89
+ if (chatModel === null) {
88
90
  return null;
89
91
  }
90
- return this._chatModel;
92
+ if (currentProvider?.exposeChatModel ?? false) {
93
+ // Expose the full chat model if expected.
94
+ return chatModel;
95
+ }
96
+ // Otherwise, we create a reduced AIChatModel interface.
97
+ return {
98
+ stream: (input, options) => chatModel.stream(input, options)
99
+ };
91
100
  }
92
101
  /**
93
102
  * Get the settings schema of a given provider.
94
103
  */
95
104
  getSettingsSchema(provider) {
96
- var _a, _b;
97
- return (((_b = (_a = this._providers.get(provider)) === null || _a === void 0 ? void 0 : _a.settingsSchema) === null || _b === void 0 ? void 0 : _b.properties) ||
105
+ return (Private.providers.get(provider)?.settingsSchema?.properties ||
98
106
  {});
99
107
  }
100
108
  /**
101
109
  * Get the instructions of a given provider.
102
110
  */
103
111
  getInstructions(provider) {
104
- var _a;
105
- return (_a = this._providers.get(provider)) === null || _a === void 0 ? void 0 : _a.instructions;
112
+ return Private.providers.get(provider)?.instructions;
113
+ }
114
+ /**
115
+ * Get the compatibility check function of a given provider.
116
+ */
117
+ getCompatibilityCheck(provider) {
118
+ return Private.providers.get(provider)?.compatibilityCheck;
106
119
  }
107
120
  /**
108
121
  * Format an error message from the current provider.
109
122
  */
110
123
  formatErrorMessage(error) {
111
- var _a, _b;
112
- if ((_a = this._currentProvider) === null || _a === void 0 ? void 0 : _a.errorMessage) {
113
- return (_b = this._currentProvider) === null || _b === void 0 ? void 0 : _b.errorMessage(error);
124
+ const currentProvider = Private.providers.get(Private.getName()) ?? null;
125
+ if (currentProvider?.errorMessage) {
126
+ return currentProvider?.errorMessage(error);
114
127
  }
115
128
  if (error.message) {
116
129
  return error.message;
@@ -124,7 +137,7 @@ export class AIProviderRegistry {
124
137
  return this._chatError;
125
138
  }
126
139
  /**
127
- * get the current completer error.
140
+ * Get the current completer error.
128
141
  */
129
142
  get completerError() {
130
143
  return this._completerError;
@@ -136,10 +149,9 @@ export class AIProviderRegistry {
136
149
  * @param options - An object with the name and the settings of the provider to use.
137
150
  */
138
151
  async setProvider(options) {
139
- var _a, _b, _c, _d;
140
152
  const { name, settings } = options;
141
- this._currentProvider = (_a = this._providers.get(name)) !== null && _a !== void 0 ? _a : null;
142
- if (this._currentProvider === null) {
153
+ const currentProvider = Private.providers.get(name) ?? null;
154
+ if (currentProvider === null) {
143
155
  // The current provider may not be loaded when the settings are first loaded.
144
156
  // Let's defer the provider loading.
145
157
  this._deferredProvider = options;
@@ -147,12 +159,27 @@ export class AIProviderRegistry {
147
159
  else {
148
160
  this._deferredProvider = null;
149
161
  }
162
+ const compatibilityCheck = this.getCompatibilityCheck(name);
163
+ if (compatibilityCheck !== undefined) {
164
+ const error = await compatibilityCheck();
165
+ if (error !== null) {
166
+ this._chatError = error.trim();
167
+ this._completerError = error.trim();
168
+ Private.setName('None');
169
+ this._providerChanged.emit();
170
+ return;
171
+ }
172
+ }
173
+ if (name === 'None') {
174
+ this._chatError = '';
175
+ this._completerError = '';
176
+ }
150
177
  // Build a new settings object containing the secrets.
151
178
  const fullSettings = {};
152
179
  for (const key of Object.keys(settings)) {
153
180
  if (settings[key] === SECRETS_REPLACEMENT) {
154
181
  const id = getSecretId(name, key);
155
- const secrets = await ((_b = this._secretsManager) === null || _b === void 0 ? void 0 : _b.get(Private.getToken(), SECRETS_NAMESPACE, id));
182
+ const secrets = await this._secretsManager?.get(Private.getToken(), SECRETS_NAMESPACE, id);
156
183
  if (secrets !== undefined) {
157
184
  fullSettings[key] = secrets.value;
158
185
  }
@@ -160,11 +187,11 @@ export class AIProviderRegistry {
160
187
  }
161
188
  fullSettings[key] = settings[key];
162
189
  }
163
- if (((_c = this._currentProvider) === null || _c === void 0 ? void 0 : _c.completer) !== undefined) {
190
+ if (currentProvider?.completer !== undefined) {
164
191
  try {
165
- this._completer = new this._currentProvider.completer({
192
+ Private.setCompleter(new currentProvider.completer({
166
193
  settings: fullSettings
167
- });
194
+ }));
168
195
  this._completerError = '';
169
196
  }
170
197
  catch (e) {
@@ -172,24 +199,24 @@ export class AIProviderRegistry {
172
199
  }
173
200
  }
174
201
  else {
175
- this._completer = null;
202
+ Private.setCompleter(null);
176
203
  }
177
- if (((_d = this._currentProvider) === null || _d === void 0 ? void 0 : _d.chatModel) !== undefined) {
204
+ if (currentProvider?.chatModel !== undefined) {
178
205
  try {
179
- this._chatModel = new this._currentProvider.chatModel({
206
+ Private.setChatModel(new currentProvider.chatModel({
180
207
  ...fullSettings
181
- });
208
+ }));
182
209
  this._chatError = '';
183
210
  }
184
211
  catch (e) {
185
212
  this._chatError = e.message;
186
- this._chatModel = null;
213
+ Private.setChatModel(null);
187
214
  }
188
215
  }
189
216
  else {
190
- this._chatModel = null;
217
+ Private.setChatModel(null);
191
218
  }
192
- this._name = name;
219
+ Private.setName(name);
193
220
  this._providerChanged.emit();
194
221
  }
195
222
  /**
@@ -198,6 +225,11 @@ export class AIProviderRegistry {
198
225
  get providerChanged() {
199
226
  return this._providerChanged;
200
227
  }
228
+ _secretsManager;
229
+ _providerChanged = new Signal(this);
230
+ _chatError = '';
231
+ _completerError = '';
232
+ _deferredProvider = null;
201
233
  }
202
234
  (function (AIProviderRegistry) {
203
235
  /**
@@ -239,21 +271,57 @@ export class AIProviderRegistry {
239
271
  var Private;
240
272
  (function (Private) {
241
273
  /**
242
- * The token to use with the secrets manager.
274
+ * The token to use with the secrets manager, setter and getter.
243
275
  */
244
276
  let secretsToken;
245
- /**
246
- * Set of the token.
247
- */
248
277
  function setToken(value) {
249
278
  secretsToken = value;
250
279
  }
251
280
  Private.setToken = setToken;
252
- /**
253
- * get the token.
254
- */
255
281
  function getToken() {
256
282
  return secretsToken;
257
283
  }
258
284
  Private.getToken = getToken;
285
+ /**
286
+ * The providers map, in private namespace to prevent updating the 'exposeChatModel'
287
+ * flag.
288
+ */
289
+ Private.providers = new Map();
290
+ /**
291
+ * The name of the current provider, setter and getter.
292
+ * It is in a private namespace to prevent updating it without updating the models.
293
+ */
294
+ let name = 'None';
295
+ function setName(value) {
296
+ name = value;
297
+ }
298
+ Private.setName = setName;
299
+ function getName() {
300
+ return name;
301
+ }
302
+ Private.getName = getName;
303
+ /**
304
+ * The chat model setter and getter.
305
+ */
306
+ let chatModel = null;
307
+ function setChatModel(model) {
308
+ chatModel = model;
309
+ }
310
+ Private.setChatModel = setChatModel;
311
+ function getChatModel() {
312
+ return chatModel;
313
+ }
314
+ Private.getChatModel = getChatModel;
315
+ /**
316
+ * The completer setter and getter.
317
+ */
318
+ let completer = null;
319
+ function setCompleter(model) {
320
+ completer = model;
321
+ }
322
+ Private.setCompleter = setCompleter;
323
+ function getCompleter() {
324
+ return completer;
325
+ }
326
+ Private.getCompleter = getCompleter;
259
327
  })(Private || (Private = {}));
@@ -1,3 +1,2 @@
1
1
  export * from './panel';
2
- export * from './settings-connector';
3
2
  export * from './utils';
@@ -1,3 +1,2 @@
1
1
  export * from './panel';
2
- export * from './settings-connector';
3
2
  export * from './utils';
@@ -1,5 +1,4 @@
1
1
  import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
2
- import { ISettingConnector } from '@jupyterlab/settingregistry';
3
2
  import { IFormRenderer } from '@jupyterlab/ui-components';
4
3
  import type { FieldProps } from '@rjsf/utils';
5
4
  import { JSONSchema7 } from 'json-schema';
@@ -11,11 +10,12 @@ export declare const aiSettingsRenderer: (options: {
11
10
  secretsToken?: symbol;
12
11
  rmRegistry?: IRenderMimeRegistry;
13
12
  secretsManager?: ISecretsManager;
14
- settingConnector?: ISettingConnector;
15
13
  }) => IFormRenderer;
16
14
  export interface ISettingsFormStates {
17
15
  schema: JSONSchema7;
18
16
  instruction: HTMLElement | null;
17
+ compatibilityError: string | null;
18
+ isModified?: boolean;
19
19
  }
20
20
  export declare class AiSettings extends React.Component<FieldProps, ISettingsFormStates> {
21
21
  constructor(props: FieldProps);
@@ -32,11 +32,23 @@ export declare class AiSettings extends React.Component<FieldProps, ISettingsFor
32
32
  /**
33
33
  * Get settings from local storage for a given provider.
34
34
  */
35
- getSettings(): IDict<any>;
35
+ getSettingsFromLocalStorage(): IDict<any>;
36
36
  /**
37
37
  * Save settings in local storage for a given provider.
38
38
  */
39
- saveSettings(value: IDict<any>): void;
39
+ saveSettingsToLocalStorage(): void;
40
+ /**
41
+ * Save the settings to the setting registry.
42
+ */
43
+ saveSettingsToRegistry(): void;
44
+ /**
45
+ * Triggered when the settings has changed.
46
+ */
47
+ private _settingsChanged;
48
+ /**
49
+ * Triggered when the secret fields visibility has changed.
50
+ */
51
+ private _fieldVisibilityChanged;
40
52
  /**
41
53
  * Update the settings whether the secrets manager is used or not.
42
54
  *
@@ -57,7 +69,12 @@ export declare class AiSettings extends React.Component<FieldProps, ISettingsFor
57
69
  */
58
70
  private _renderInstruction;
59
71
  /**
60
- * Triggered when the provider hes changed, to update the schema and values.
72
+ * Check for compatibility of the provider with the current environment.
73
+ * If the provider is not compatible, display an error message.
74
+ */
75
+ private _checkProviderCompatibility;
76
+ /**
77
+ * Triggered when the provider has changed, to update the schema and values.
61
78
  * Update the Jupyterlab settings accordingly.
62
79
  */
63
80
  private _onProviderChanged;
@@ -66,24 +83,36 @@ export declare class AiSettings extends React.Component<FieldProps, ISettingsFor
66
83
  * with the secret manager.
67
84
  */
68
85
  private _onPasswordUpdated;
86
+ /**
87
+ * Update the current settings with the new values from the form.
88
+ *
89
+ * @param data - The form data to update.
90
+ * @returns - Boolean whether the form is not the default one.
91
+ */
92
+ private _updatedFormData;
69
93
  /**
70
94
  * Triggered when the form value has changed, to update the current settings and save
71
95
  * it in local storage.
72
96
  * Update the Jupyterlab settings accordingly.
73
97
  */
74
- private _onFormChange;
98
+ private _onFormChanged;
99
+ /**
100
+ * Handler for the "Restore to defaults" button - clears all
101
+ * modified settings then calls `setFormData` to restore the
102
+ * values.
103
+ */
104
+ private _reset;
75
105
  render(): JSX.Element;
76
106
  private _providerRegistry;
77
107
  private _provider;
78
108
  private _providerSchema;
79
109
  private _useSecretsManager;
80
- private _hideSecretFields;
81
110
  private _rmRegistry;
82
111
  private _secretsManager;
83
- private _settingConnector;
84
112
  private _currentSettings;
85
113
  private _uiSchema;
86
114
  private _settings;
87
115
  private _formRef;
88
116
  private _secretFields;
117
+ private _defaultFormData;
89
118
  }