@@ -21,18 +21,18 @@ import {
2121} from '@jupyterlab/settingregistry' ;
2222import { IFormRendererRegistry } from '@jupyterlab/ui-components' ;
2323import { ReadonlyPartialJSONObject } from '@lumino/coreutils' ;
24- import { ISecretsManager } from 'jupyter-secrets-manager' ;
24+ import { ISecretsManager , SecretsManager } from 'jupyter-secrets-manager' ;
2525
2626import { ChatHandler } from './chat-handler' ;
2727import { CompletionProvider } from './completion-provider' ;
2828import { defaultProviderPlugins } from './default-providers' ;
2929import { AIProviderRegistry } from './provider' ;
3030import { aiSettingsRenderer , SettingConnector } from './settings' ;
31- import { IAIProviderRegistry } from './tokens' ;
31+ import { IAIProviderRegistry , PLUGIN_IDS } from './tokens' ;
3232import { stopItem } from './components/stop-button' ;
3333
3434const chatCommandRegistryPlugin : JupyterFrontEndPlugin < IChatCommandRegistry > = {
35- id : '@jupyterlite/ai:autocompletion-registry' ,
35+ id : PLUGIN_IDS . chatCommandRegistry ,
3636 description : 'Autocompletion registry' ,
3737 autoStart : true ,
3838 provides : IChatCommandRegistry ,
@@ -44,7 +44,7 @@ const chatCommandRegistryPlugin: JupyterFrontEndPlugin<IChatCommandRegistry> = {
4444} ;
4545
4646const chatPlugin : JupyterFrontEndPlugin < void > = {
47- id : '@jupyterlite/ai: chat' ,
47+ id : PLUGIN_IDS . chat ,
4848 description : 'LLM chat extension' ,
4949 autoStart : true ,
5050 requires : [ IAIProviderRegistry , IRenderMimeRegistry , IChatCommandRegistry ] ,
@@ -141,7 +141,7 @@ const chatPlugin: JupyterFrontEndPlugin<void> = {
141141} ;
142142
143143const completerPlugin : JupyterFrontEndPlugin < void > = {
144- id : '@jupyterlite/ai: completer' ,
144+ id : PLUGIN_IDS . completer ,
145145 autoStart : true ,
146146 requires : [ IAIProviderRegistry , ICompletionProviderManager ] ,
147147 activate : (
@@ -157,67 +157,72 @@ const completerPlugin: JupyterFrontEndPlugin<void> = {
157157 }
158158} ;
159159
160- const providerRegistryPlugin : JupyterFrontEndPlugin < IAIProviderRegistry > = {
161- id : '@jupyterlite/ai:provider-registry' ,
162- autoStart : true ,
163- requires : [ IFormRendererRegistry , ISettingRegistry ] ,
164- optional : [ IRenderMimeRegistry , ISecretsManager , ISettingConnector ] ,
165- provides : IAIProviderRegistry ,
166- activate : (
167- app : JupyterFrontEnd ,
168- editorRegistry : IFormRendererRegistry ,
169- settingRegistry : ISettingRegistry ,
170- rmRegistry ?: IRenderMimeRegistry ,
171- secretsManager ?: ISecretsManager ,
172- settingConnector ?: ISettingConnector
173- ) : IAIProviderRegistry => {
174- const providerRegistry = new AIProviderRegistry ( { secretsManager } ) ;
175-
176- editorRegistry . addRenderer (
177- '@jupyterlite/ai:provider-registry.AIprovider' ,
178- aiSettingsRenderer ( {
179- providerRegistry,
180- rmRegistry,
181- secretsManager,
182- settingConnector
183- } )
184- ) ;
185-
186- settingRegistry
187- . load ( providerRegistryPlugin . id )
188- . then ( settings => {
189- const updateProvider = ( ) => {
190- // Update the settings to the AI providers.
191- const providerSettings = ( settings . get ( 'AIprovider' ) . composite ?? {
192- provider : 'None'
193- } ) as ReadonlyPartialJSONObject ;
194- providerRegistry . setProvider ( {
195- name : providerSettings . provider as string ,
196- settings : providerSettings
197- } ) ;
198- } ;
199-
200- settings . changed . connect ( ( ) => updateProvider ( ) ) ;
201- updateProvider ( ) ;
202- } )
203- . catch ( reason => {
204- console . error (
205- `Failed to load settings for ${ providerRegistryPlugin . id } ` ,
206- reason
207- ) ;
160+ const providerRegistryPlugin : JupyterFrontEndPlugin < IAIProviderRegistry > =
161+ SecretsManager . sign ( PLUGIN_IDS . providerRegistry , token => ( {
162+ id : PLUGIN_IDS . providerRegistry ,
163+ autoStart : true ,
164+ requires : [ IFormRendererRegistry , ISettingRegistry ] ,
165+ optional : [ IRenderMimeRegistry , ISecretsManager , ISettingConnector ] ,
166+ provides : IAIProviderRegistry ,
167+ activate : (
168+ app : JupyterFrontEnd ,
169+ editorRegistry : IFormRendererRegistry ,
170+ settingRegistry : ISettingRegistry ,
171+ rmRegistry ?: IRenderMimeRegistry ,
172+ secretsManager ?: ISecretsManager ,
173+ settingConnector ?: ISettingConnector
174+ ) : IAIProviderRegistry => {
175+ const providerRegistry = new AIProviderRegistry ( {
176+ token,
177+ secretsManager
208178 } ) ;
209179
210- return providerRegistry ;
211- }
212- } ;
180+ editorRegistry . addRenderer (
181+ `${ PLUGIN_IDS . providerRegistry } .AIprovider` ,
182+ aiSettingsRenderer ( {
183+ providerRegistry,
184+ secretsToken : token ,
185+ rmRegistry,
186+ secretsManager,
187+ settingConnector
188+ } )
189+ ) ;
190+
191+ settingRegistry
192+ . load ( providerRegistryPlugin . id )
193+ . then ( settings => {
194+ const updateProvider = ( ) => {
195+ // Update the settings to the AI providers.
196+ const providerSettings = ( settings . get ( 'AIprovider' ) . composite ?? {
197+ provider : 'None'
198+ } ) as ReadonlyPartialJSONObject ;
199+ providerRegistry . setProvider ( {
200+ name : providerSettings . provider as string ,
201+ settings : providerSettings
202+ } ) ;
203+ } ;
204+
205+ settings . changed . connect ( ( ) => updateProvider ( ) ) ;
206+ updateProvider ( ) ;
207+ } )
208+ . catch ( reason => {
209+ console . error (
210+ `Failed to load settings for ${ providerRegistryPlugin . id } ` ,
211+ reason
212+ ) ;
213+ } ) ;
214+
215+ return providerRegistry ;
216+ }
217+ } ) ) ;
213218
214219/**
215220 * Provides the settings connector as a separate plugin to allow for alternative
216221 * implementations that may want to fetch settings from a different source or
217222 * endpoint.
218223 */
219224const settingsConnector : JupyterFrontEndPlugin < ISettingConnector > = {
220- id : '@jupyterlite/ai:settings-connector' ,
225+ id : PLUGIN_IDS . settingsConnector ,
221226 description : 'Provides a settings connector which does not save passwords.' ,
222227 autoStart : true ,
223228 provides : ISettingConnector ,
0 commit comments