@jupyterlite/ai 0.14.0 → 0.16.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/agent.d.ts +33 -115
- package/lib/agent.js +192 -106
- package/lib/chat-model-handler.d.ts +9 -11
- package/lib/chat-model-handler.js +9 -4
- package/lib/chat-model.d.ts +84 -13
- package/lib/chat-model.js +214 -136
- package/lib/completion/completion-provider.d.ts +2 -3
- package/lib/components/completion-status.d.ts +2 -2
- package/lib/components/index.d.ts +1 -1
- package/lib/components/index.js +1 -1
- package/lib/components/model-select.d.ts +3 -3
- package/lib/components/save-button.d.ts +31 -0
- package/lib/components/save-button.js +41 -0
- package/lib/components/tool-select.d.ts +3 -4
- package/lib/components/{token-usage-display.d.ts → usage-display.d.ts} +13 -14
- package/lib/components/usage-display.js +109 -0
- package/lib/diff-manager.d.ts +2 -3
- package/lib/index.d.ts +2 -4
- package/lib/index.js +186 -28
- package/lib/models/settings-model.d.ts +11 -53
- package/lib/models/settings-model.js +38 -22
- package/lib/providers/built-in-providers.js +22 -36
- package/lib/providers/generated-context-windows.d.ts +8 -0
- package/lib/providers/generated-context-windows.js +96 -0
- package/lib/providers/model-info.d.ts +3 -0
- package/lib/providers/model-info.js +58 -0
- package/lib/tokens.d.ts +361 -36
- package/lib/tokens.js +18 -13
- package/lib/tools/commands.d.ts +2 -3
- package/lib/widgets/ai-settings.d.ts +3 -5
- package/lib/widgets/ai-settings.js +12 -0
- package/lib/widgets/main-area-chat.d.ts +2 -3
- package/lib/widgets/main-area-chat.js +12 -12
- package/lib/widgets/provider-config-dialog.d.ts +1 -2
- package/lib/widgets/provider-config-dialog.js +34 -34
- package/package.json +17 -10
- package/schema/settings-model.json +18 -1
- package/src/agent.ts +275 -248
- package/src/chat-model-handler.ts +25 -21
- package/src/chat-model.ts +307 -196
- package/src/completion/completion-provider.ts +7 -4
- package/src/components/completion-status.tsx +3 -3
- package/src/components/index.ts +1 -1
- package/src/components/model-select.tsx +4 -3
- package/src/components/save-button.tsx +84 -0
- package/src/components/tool-select.tsx +10 -4
- package/src/components/usage-display.tsx +208 -0
- package/src/diff-manager.ts +4 -4
- package/src/index.ts +250 -58
- package/src/models/settings-model.ts +46 -88
- package/src/providers/built-in-providers.ts +22 -36
- package/src/providers/generated-context-windows.ts +102 -0
- package/src/providers/model-info.ts +88 -0
- package/src/tokens.ts +438 -58
- package/src/tools/commands.ts +2 -3
- package/src/widgets/ai-settings.tsx +69 -15
- package/src/widgets/main-area-chat.ts +18 -15
- package/src/widgets/provider-config-dialog.tsx +96 -61
- package/style/base.css +17 -195
- package/lib/approval-buttons.d.ts +0 -49
- package/lib/approval-buttons.js +0 -79
- package/lib/components/token-usage-display.js +0 -72
- package/src/approval-buttons.ts +0 -115
- package/src/components/token-usage-display.tsx +0 -138
package/src/index.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
import {
|
|
24
24
|
ICommandPalette,
|
|
25
25
|
IThemeManager,
|
|
26
|
+
showDialog,
|
|
26
27
|
showErrorMessage,
|
|
27
28
|
WidgetTracker
|
|
28
29
|
} from '@jupyterlab/apputils';
|
|
@@ -31,6 +32,8 @@ import { ICompletionProviderManager } from '@jupyterlab/completer';
|
|
|
31
32
|
|
|
32
33
|
import { IDocumentManager } from '@jupyterlab/docmanager';
|
|
33
34
|
|
|
35
|
+
import { FileDialog } from '@jupyterlab/filebrowser';
|
|
36
|
+
|
|
34
37
|
import { INotebookTracker } from '@jupyterlab/notebook';
|
|
35
38
|
|
|
36
39
|
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
|
@@ -48,28 +51,36 @@ import {
|
|
|
48
51
|
} from '@jupyterlab/translation';
|
|
49
52
|
|
|
50
53
|
import {
|
|
54
|
+
fileUploadIcon,
|
|
55
|
+
saveIcon,
|
|
51
56
|
settingsIcon,
|
|
52
57
|
Toolbar,
|
|
53
58
|
ToolbarButton
|
|
54
59
|
} from '@jupyterlab/ui-components';
|
|
55
60
|
|
|
56
|
-
import { ISecretsManager, SecretsManager } from 'jupyter-secrets-manager';
|
|
57
|
-
|
|
58
61
|
import { PromiseDelegate, UUID } from '@lumino/coreutils';
|
|
62
|
+
|
|
59
63
|
import { DisposableSet } from '@lumino/disposable';
|
|
64
|
+
|
|
60
65
|
import { CommandRegistry } from '@lumino/commands';
|
|
61
66
|
|
|
67
|
+
import { IComponentsRendererFactory } from 'jupyter-chat-components';
|
|
68
|
+
|
|
69
|
+
import { ISecretsManager, SecretsManager } from 'jupyter-secrets-manager';
|
|
70
|
+
|
|
62
71
|
import { AgentManagerFactory } from './agent';
|
|
63
72
|
|
|
64
73
|
import { AIChatModel } from './chat-model';
|
|
74
|
+
|
|
65
75
|
import { RenderedMessageOutputAreaCompat } from './rendered-message-outputarea';
|
|
66
76
|
|
|
67
77
|
import { ClearCommandProvider } from './chat-commands/clear';
|
|
78
|
+
|
|
68
79
|
import { SkillsCommandProvider } from './chat-commands/skills';
|
|
69
80
|
|
|
70
81
|
import { ProviderRegistry } from './providers/provider-registry';
|
|
71
82
|
|
|
72
|
-
import {
|
|
83
|
+
import { SaveComponentWidget } from './components/save-button';
|
|
73
84
|
|
|
74
85
|
import { ChatModelHandler } from './chat-model-handler';
|
|
75
86
|
|
|
@@ -77,13 +88,14 @@ import {
|
|
|
77
88
|
CommandIds,
|
|
78
89
|
IAgentManagerFactory,
|
|
79
90
|
type IAISecretsAccess,
|
|
91
|
+
IAISettingsModel,
|
|
92
|
+
IChatModelHandler,
|
|
93
|
+
IDiffManager,
|
|
94
|
+
type IProviderConfig,
|
|
80
95
|
IProviderRegistry,
|
|
81
96
|
IToolRegistry,
|
|
82
97
|
ISkillRegistry,
|
|
83
|
-
SECRETS_NAMESPACE
|
|
84
|
-
IAISettingsModel,
|
|
85
|
-
IChatModelHandler,
|
|
86
|
-
IDiffManager
|
|
98
|
+
SECRETS_NAMESPACE
|
|
87
99
|
} from './tokens';
|
|
88
100
|
|
|
89
101
|
import {
|
|
@@ -102,10 +114,10 @@ import {
|
|
|
102
114
|
createToolSelectItem,
|
|
103
115
|
stopItem,
|
|
104
116
|
CompletionStatusWidget,
|
|
105
|
-
|
|
117
|
+
UsageWidget
|
|
106
118
|
} from './components';
|
|
107
119
|
|
|
108
|
-
import { AISettingsModel
|
|
120
|
+
import { AISettingsModel } from './models/settings-model';
|
|
109
121
|
|
|
110
122
|
import { loadSkillsFromPaths, SkillRegistry } from './skills';
|
|
111
123
|
|
|
@@ -117,7 +129,9 @@ import {
|
|
|
117
129
|
createDiscoverCommandsTool,
|
|
118
130
|
createExecuteCommandTool
|
|
119
131
|
} from './tools/commands';
|
|
132
|
+
|
|
120
133
|
import { createDiscoverSkillsTool, createLoadSkillTool } from './tools/skills';
|
|
134
|
+
|
|
121
135
|
import { createBrowserFetchTool } from './tools/web';
|
|
122
136
|
|
|
123
137
|
import { AISettingsWidget } from './widgets/ai-settings';
|
|
@@ -320,17 +334,16 @@ const chatModelHandler: JupyterFrontEndPlugin<IChatModelHandler> = {
|
|
|
320
334
|
],
|
|
321
335
|
optional: [IProviderRegistry, IToolRegistry, ITranslator],
|
|
322
336
|
provides: IChatModelHandler,
|
|
323
|
-
activate: (
|
|
337
|
+
activate: async (
|
|
324
338
|
app: JupyterFrontEnd,
|
|
325
|
-
settingsModel:
|
|
326
|
-
agentManagerFactory:
|
|
339
|
+
settingsModel: IAISettingsModel,
|
|
340
|
+
agentManagerFactory: IAgentManagerFactory,
|
|
327
341
|
docManager: IDocumentManager,
|
|
328
342
|
rmRegistry: IRenderMimeRegistry,
|
|
329
343
|
providerRegistry?: IProviderRegistry,
|
|
330
|
-
toolRegistry?: IToolRegistry
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const trans = (translator ?? nullTranslator).load('jupyterlite_ai');
|
|
344
|
+
toolRegistry?: IToolRegistry
|
|
345
|
+
): Promise<IChatModelHandler> => {
|
|
346
|
+
await app.serviceManager.ready;
|
|
334
347
|
|
|
335
348
|
return new ChatModelHandler({
|
|
336
349
|
settingsModel,
|
|
@@ -339,7 +352,7 @@ const chatModelHandler: JupyterFrontEndPlugin<IChatModelHandler> = {
|
|
|
339
352
|
rmRegistry,
|
|
340
353
|
providerRegistry,
|
|
341
354
|
toolRegistry,
|
|
342
|
-
|
|
355
|
+
contentsManager: app.serviceManager.contents
|
|
343
356
|
});
|
|
344
357
|
}
|
|
345
358
|
};
|
|
@@ -364,22 +377,29 @@ const plugin: JupyterFrontEndPlugin<IChatTracker> = {
|
|
|
364
377
|
ILayoutRestorer,
|
|
365
378
|
ILabShell,
|
|
366
379
|
INotebookTracker,
|
|
367
|
-
ITranslator
|
|
380
|
+
ITranslator,
|
|
381
|
+
IComponentsRendererFactory,
|
|
382
|
+
ICommandPalette,
|
|
383
|
+
IDocumentManager
|
|
368
384
|
],
|
|
369
385
|
activate: (
|
|
370
386
|
app: JupyterFrontEnd,
|
|
371
387
|
rmRegistry: IRenderMimeRegistry,
|
|
372
388
|
inputToolbarFactory: IInputToolbarRegistryFactory,
|
|
373
389
|
modelHandler: IChatModelHandler,
|
|
374
|
-
settingsModel:
|
|
390
|
+
settingsModel: IAISettingsModel,
|
|
375
391
|
chatCommandRegistry: IChatCommandRegistry,
|
|
376
392
|
themeManager?: IThemeManager,
|
|
377
393
|
restorer?: ILayoutRestorer,
|
|
378
394
|
labShell?: ILabShell,
|
|
379
395
|
notebookTracker?: INotebookTracker,
|
|
380
|
-
translator?: ITranslator
|
|
396
|
+
translator?: ITranslator,
|
|
397
|
+
chatComponentsFactory?: IComponentsRendererFactory,
|
|
398
|
+
palette?: ICommandPalette,
|
|
399
|
+
documentManager?: IDocumentManager
|
|
381
400
|
): IChatTracker => {
|
|
382
401
|
const trans = (translator ?? nullTranslator).load('jupyterlite_ai');
|
|
402
|
+
|
|
383
403
|
// Create attachment opener registry to handle file attachments
|
|
384
404
|
const attachmentOpenerRegistry = new AttachmentOpenerRegistry();
|
|
385
405
|
attachmentOpenerRegistry.set('file', attachment => {
|
|
@@ -436,7 +456,10 @@ const plugin: JupyterFrontEndPlugin<IChatTracker> = {
|
|
|
436
456
|
name = `${modelName}-${i}`;
|
|
437
457
|
i += 1;
|
|
438
458
|
}
|
|
439
|
-
const model = modelHandler.createModel(
|
|
459
|
+
const model = modelHandler.createModel({
|
|
460
|
+
name,
|
|
461
|
+
activeProvider: provider
|
|
462
|
+
});
|
|
440
463
|
return { model };
|
|
441
464
|
},
|
|
442
465
|
getChatNames: async () => {
|
|
@@ -493,7 +516,7 @@ const plugin: JupyterFrontEndPlugin<IChatTracker> = {
|
|
|
493
516
|
chatPanel.disposed.connect(disconnectSettingsButtonListener);
|
|
494
517
|
}
|
|
495
518
|
|
|
496
|
-
let
|
|
519
|
+
let usageWidget: UsageWidget | null = null;
|
|
497
520
|
chatPanel.chatOpened.connect((_, widget) => {
|
|
498
521
|
const model = widget.model as AIChatModel;
|
|
499
522
|
|
|
@@ -511,19 +534,28 @@ const plugin: JupyterFrontEndPlugin<IChatTracker> = {
|
|
|
511
534
|
model.agentManager.activeProviderChanged.connect(saveTracker);
|
|
512
535
|
|
|
513
536
|
// Update the token usage widget.
|
|
514
|
-
|
|
537
|
+
usageWidget?.dispose();
|
|
515
538
|
|
|
516
|
-
|
|
539
|
+
usageWidget = new UsageWidget({
|
|
517
540
|
tokenUsageChanged: model.tokenUsageChanged,
|
|
518
541
|
settingsModel,
|
|
519
542
|
initialTokenUsage: model.agentManager.tokenUsage,
|
|
520
543
|
translator: trans
|
|
521
544
|
});
|
|
522
|
-
chatPanel.current?.toolbar.insertBefore(
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
545
|
+
chatPanel.current?.toolbar.insertBefore('markRead', 'usage', usageWidget);
|
|
546
|
+
|
|
547
|
+
if (model.saveAvailable) {
|
|
548
|
+
const saveChatButton = new SaveComponentWidget({
|
|
549
|
+
model,
|
|
550
|
+
translator: trans
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
chatPanel.current?.toolbar.insertAfter(
|
|
554
|
+
'markRead',
|
|
555
|
+
'saveChat',
|
|
556
|
+
saveChatButton
|
|
557
|
+
);
|
|
558
|
+
}
|
|
527
559
|
|
|
528
560
|
// Listen for writers change to display the stop button.
|
|
529
561
|
function writersChanged(_: IChatModel, writers: IChatModel.IWriter[]) {
|
|
@@ -543,11 +575,6 @@ const plugin: JupyterFrontEndPlugin<IChatTracker> = {
|
|
|
543
575
|
|
|
544
576
|
model.writersChanged?.connect(writersChanged);
|
|
545
577
|
|
|
546
|
-
// Associate an approval buttons object to the chat.
|
|
547
|
-
const approvalButton = new ApprovalButtons({
|
|
548
|
-
chatPanel: widget,
|
|
549
|
-
agentManager: model.agentManager
|
|
550
|
-
});
|
|
551
578
|
// Temporary compat: keep output-area CSS context for MIME renderers
|
|
552
579
|
// until jupyter-chat provides it natively.
|
|
553
580
|
const outputAreaCompat = new RenderedMessageOutputAreaCompat({
|
|
@@ -560,11 +587,17 @@ const plugin: JupyterFrontEndPlugin<IChatTracker> = {
|
|
|
560
587
|
model.writersChanged?.disconnect(writersChanged);
|
|
561
588
|
|
|
562
589
|
// Dispose of the approval buttons widget when the chat is disposed.
|
|
563
|
-
approvalButton.dispose();
|
|
564
590
|
outputAreaCompat.dispose();
|
|
565
591
|
});
|
|
566
592
|
});
|
|
567
593
|
|
|
594
|
+
/**
|
|
595
|
+
* Update the available chat list when settings config changed.
|
|
596
|
+
*/
|
|
597
|
+
settingsModel.stateChanged.connect(() => {
|
|
598
|
+
chatPanel.updateChatList();
|
|
599
|
+
});
|
|
600
|
+
|
|
568
601
|
app.shell.add(chatPanel, 'left', { rank: 1000 });
|
|
569
602
|
|
|
570
603
|
if (restorer) {
|
|
@@ -602,9 +635,32 @@ const plugin: JupyterFrontEndPlugin<IChatTracker> = {
|
|
|
602
635
|
modelHandler,
|
|
603
636
|
trans,
|
|
604
637
|
themeManager,
|
|
605
|
-
labShell
|
|
638
|
+
labShell,
|
|
639
|
+
palette,
|
|
640
|
+
documentManager
|
|
606
641
|
);
|
|
607
642
|
|
|
643
|
+
/**
|
|
644
|
+
* The callback to approve or reject a tool.
|
|
645
|
+
*/
|
|
646
|
+
function toolCallApproval(
|
|
647
|
+
targetId: string,
|
|
648
|
+
approvalId: string,
|
|
649
|
+
isApproved: boolean
|
|
650
|
+
) {
|
|
651
|
+
const model = tracker.find(chat => chat.model.name === targetId)?.model;
|
|
652
|
+
if (!model) {
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
isApproved
|
|
656
|
+
? (model as AIChatModel).agentManager.approveToolCall(approvalId)
|
|
657
|
+
: (model as AIChatModel).agentManager.rejectToolCall(approvalId);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
if (chatComponentsFactory) {
|
|
661
|
+
chatComponentsFactory.toolCallApproval = toolCallApproval;
|
|
662
|
+
}
|
|
663
|
+
|
|
608
664
|
return tracker;
|
|
609
665
|
}
|
|
610
666
|
};
|
|
@@ -615,13 +671,15 @@ function registerCommands(
|
|
|
615
671
|
chatPanel: MultiChatPanel,
|
|
616
672
|
attachmentOpenerRegistry: IAttachmentOpenerRegistry,
|
|
617
673
|
inputToolbarFactory: IInputToolbarRegistryFactory,
|
|
618
|
-
settingsModel:
|
|
674
|
+
settingsModel: IAISettingsModel,
|
|
619
675
|
chatCommandRegistry: IChatCommandRegistry,
|
|
620
676
|
tracker: WidgetTracker<MainAreaChat | ChatWidget>,
|
|
621
677
|
modelRegistry: IChatModelHandler,
|
|
622
678
|
trans: TranslationBundle,
|
|
623
679
|
themeManager?: IThemeManager,
|
|
624
|
-
labShell?: ILabShell
|
|
680
|
+
labShell?: ILabShell,
|
|
681
|
+
palette?: ICommandPalette,
|
|
682
|
+
documentManager?: IDocumentManager
|
|
625
683
|
) {
|
|
626
684
|
const { commands } = app;
|
|
627
685
|
|
|
@@ -735,7 +793,10 @@ function registerCommands(
|
|
|
735
793
|
name = providerConfig.name;
|
|
736
794
|
}
|
|
737
795
|
|
|
738
|
-
const model = modelRegistry.createModel(
|
|
796
|
+
const model = modelRegistry.createModel({
|
|
797
|
+
name,
|
|
798
|
+
activeProvider: provider
|
|
799
|
+
});
|
|
739
800
|
if (!model) {
|
|
740
801
|
return false;
|
|
741
802
|
}
|
|
@@ -817,13 +878,12 @@ function registerCommands(
|
|
|
817
878
|
previousModel.name = UUID.uuid4();
|
|
818
879
|
|
|
819
880
|
// Create a new model by duplicating the previous model attributes.
|
|
820
|
-
const model = modelRegistry.createModel(
|
|
821
|
-
args.name as string,
|
|
822
|
-
previousModel.agentManager.activeProvider,
|
|
823
|
-
previousModel.agentManager.tokenUsage
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
model?.messageAdded({ ...message.content });
|
|
881
|
+
const model = modelRegistry.createModel({
|
|
882
|
+
name: args.name as string,
|
|
883
|
+
activeProvider: previousModel.agentManager.activeProvider,
|
|
884
|
+
tokenUsage: previousModel.agentManager.tokenUsage,
|
|
885
|
+
messages: previousModel.messages,
|
|
886
|
+
autosave: previousModel.autosave
|
|
827
887
|
});
|
|
828
888
|
|
|
829
889
|
// Wait (with timeout) for the tracker to have updated the previous widget.
|
|
@@ -869,6 +929,135 @@ function registerCommands(
|
|
|
869
929
|
}
|
|
870
930
|
}
|
|
871
931
|
});
|
|
932
|
+
|
|
933
|
+
commands.addCommand(CommandIds.saveChat, {
|
|
934
|
+
label: args => (args.isPalette ? trans.__('Save chat') : ''),
|
|
935
|
+
caption: trans.__('Save the chat as local file'),
|
|
936
|
+
icon: saveIcon,
|
|
937
|
+
execute: async (args): Promise<boolean> => {
|
|
938
|
+
let model: AIChatModel | null = null;
|
|
939
|
+
if (args.name) {
|
|
940
|
+
tracker.forEach(widget => {
|
|
941
|
+
if (widget.model.name === args.name) {
|
|
942
|
+
model = widget.model as AIChatModel;
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
} else {
|
|
946
|
+
model = (tracker.currentWidget?.model as AIChatModel) ?? null;
|
|
947
|
+
}
|
|
948
|
+
if (model === null) {
|
|
949
|
+
console.log('No chat to save');
|
|
950
|
+
return false;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
model.save();
|
|
954
|
+
return true;
|
|
955
|
+
},
|
|
956
|
+
describedBy: {
|
|
957
|
+
args: {
|
|
958
|
+
type: 'object',
|
|
959
|
+
properties: {
|
|
960
|
+
isPalette: {
|
|
961
|
+
type: 'boolean',
|
|
962
|
+
description: trans.__('Whether the command is in palette')
|
|
963
|
+
},
|
|
964
|
+
name: {
|
|
965
|
+
type: 'string',
|
|
966
|
+
description: trans.__('The name of the chat to save')
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
});
|
|
972
|
+
|
|
973
|
+
commands.addCommand(CommandIds.restoreChat, {
|
|
974
|
+
label: args => (args.isPalette ? trans.__('Restore chat') : ''),
|
|
975
|
+
caption: trans.__('Restore the chat from a local file'),
|
|
976
|
+
icon: fileUploadIcon,
|
|
977
|
+
isVisible: () => !!documentManager,
|
|
978
|
+
execute: async (args): Promise<boolean> => {
|
|
979
|
+
if (!documentManager) {
|
|
980
|
+
console.warn('The restoration is not possible');
|
|
981
|
+
return false;
|
|
982
|
+
}
|
|
983
|
+
let model: AIChatModel | null = null;
|
|
984
|
+
if (args.name) {
|
|
985
|
+
tracker.forEach(widget => {
|
|
986
|
+
if (widget.model.name === args.name) {
|
|
987
|
+
model = widget.model as AIChatModel;
|
|
988
|
+
}
|
|
989
|
+
});
|
|
990
|
+
} else {
|
|
991
|
+
model = (tracker.currentWidget?.model as AIChatModel) ?? null;
|
|
992
|
+
}
|
|
993
|
+
if (model === null) {
|
|
994
|
+
console.warn('There is no chat to restore');
|
|
995
|
+
return false;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
let backupDirExists = false;
|
|
999
|
+
await app.serviceManager.contents
|
|
1000
|
+
.get(settingsModel.config.chatBackupDirectory, { content: false })
|
|
1001
|
+
.then(() => (backupDirExists = true))
|
|
1002
|
+
.catch(() => (backupDirExists = false));
|
|
1003
|
+
|
|
1004
|
+
const selection = await FileDialog.getOpenFiles({
|
|
1005
|
+
title: trans.__('Select files to attach'),
|
|
1006
|
+
manager: documentManager,
|
|
1007
|
+
defaultPath: backupDirExists
|
|
1008
|
+
? settingsModel.config.chatBackupDirectory
|
|
1009
|
+
: ''
|
|
1010
|
+
});
|
|
1011
|
+
|
|
1012
|
+
const filepath = selection.value?.[0].path;
|
|
1013
|
+
|
|
1014
|
+
if (!filepath) {
|
|
1015
|
+
return false;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
if (model.messages.length) {
|
|
1019
|
+
const result = await showDialog({
|
|
1020
|
+
body: trans.__('All the message will be deleted')
|
|
1021
|
+
});
|
|
1022
|
+
if (!result.button.accept) {
|
|
1023
|
+
return false;
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
return model.restore(filepath);
|
|
1027
|
+
},
|
|
1028
|
+
describedBy: {
|
|
1029
|
+
args: {
|
|
1030
|
+
type: 'object',
|
|
1031
|
+
properties: {
|
|
1032
|
+
isPalette: {
|
|
1033
|
+
type: 'boolean',
|
|
1034
|
+
description: trans.__('Whether the command is in palette')
|
|
1035
|
+
},
|
|
1036
|
+
name: {
|
|
1037
|
+
type: 'string',
|
|
1038
|
+
description: trans.__('The name of the chat to save')
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
});
|
|
1044
|
+
|
|
1045
|
+
if (palette) {
|
|
1046
|
+
palette.addItem({
|
|
1047
|
+
category: trans.__('AI Assistant'),
|
|
1048
|
+
command: CommandIds.saveChat,
|
|
1049
|
+
args: {
|
|
1050
|
+
isPalette: true
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
palette.addItem({
|
|
1054
|
+
category: trans.__('AI Assistant'),
|
|
1055
|
+
command: CommandIds.restoreChat,
|
|
1056
|
+
args: {
|
|
1057
|
+
isPalette: true
|
|
1058
|
+
}
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
872
1061
|
}
|
|
873
1062
|
}
|
|
874
1063
|
|
|
@@ -876,7 +1065,7 @@ function registerCommands(
|
|
|
876
1065
|
* A plugin to provide the agent manager factory and completion provider.
|
|
877
1066
|
* These objects require the secrets manager token with the same namespace.
|
|
878
1067
|
*/
|
|
879
|
-
const agentManagerFactory: JupyterFrontEndPlugin<
|
|
1068
|
+
const agentManagerFactory: JupyterFrontEndPlugin<IAgentManagerFactory> =
|
|
880
1069
|
SecretsManager.sign(SECRETS_NAMESPACE, token => {
|
|
881
1070
|
Private.setAISecretsToken(token);
|
|
882
1071
|
|
|
@@ -889,12 +1078,12 @@ const agentManagerFactory: JupyterFrontEndPlugin<AgentManagerFactory> =
|
|
|
889
1078
|
optional: [ISkillRegistry, ICompletionProviderManager, ISecretsManager],
|
|
890
1079
|
activate: (
|
|
891
1080
|
app: JupyterFrontEnd,
|
|
892
|
-
settingsModel:
|
|
1081
|
+
settingsModel: IAISettingsModel,
|
|
893
1082
|
providerRegistry: IProviderRegistry,
|
|
894
1083
|
skillRegistry?: ISkillRegistry,
|
|
895
1084
|
completionManager?: ICompletionProviderManager,
|
|
896
1085
|
secretsManager?: ISecretsManager
|
|
897
|
-
):
|
|
1086
|
+
): IAgentManagerFactory => {
|
|
898
1087
|
const agentManagerFactory = new AgentManagerFactory({
|
|
899
1088
|
settingsModel,
|
|
900
1089
|
skillRegistry,
|
|
@@ -940,8 +1129,8 @@ const settingsPanelPlugin: JupyterFrontEndPlugin<void> = {
|
|
|
940
1129
|
],
|
|
941
1130
|
activate: (
|
|
942
1131
|
app: JupyterFrontEnd,
|
|
943
|
-
settingsModel:
|
|
944
|
-
agentManagerFactory:
|
|
1132
|
+
settingsModel: IAISettingsModel,
|
|
1133
|
+
agentManagerFactory: IAgentManagerFactory,
|
|
945
1134
|
providerRegistry: IProviderRegistry,
|
|
946
1135
|
palette?: ICommandPalette,
|
|
947
1136
|
restorer?: ILayoutRestorer,
|
|
@@ -1005,13 +1194,16 @@ const settingsPanelPlugin: JupyterFrontEndPlugin<void> = {
|
|
|
1005
1194
|
/**
|
|
1006
1195
|
* Built-in completion providers plugin
|
|
1007
1196
|
*/
|
|
1008
|
-
const settingsModel: JupyterFrontEndPlugin<
|
|
1197
|
+
const settingsModel: JupyterFrontEndPlugin<IAISettingsModel> = {
|
|
1009
1198
|
id: '@jupyterlite/ai:settings-model',
|
|
1010
1199
|
description: 'Provide the AI settings model',
|
|
1011
1200
|
autoStart: true,
|
|
1012
1201
|
provides: IAISettingsModel,
|
|
1013
1202
|
requires: [ISettingRegistry],
|
|
1014
|
-
activate: (
|
|
1203
|
+
activate: (
|
|
1204
|
+
app: JupyterFrontEnd,
|
|
1205
|
+
settingRegistry: ISettingRegistry
|
|
1206
|
+
): IAISettingsModel => {
|
|
1015
1207
|
return new AISettingsModel({ settingRegistry });
|
|
1016
1208
|
}
|
|
1017
1209
|
};
|
|
@@ -1027,7 +1219,7 @@ const diffManager: JupyterFrontEndPlugin<IDiffManager> = {
|
|
|
1027
1219
|
requires: [IAISettingsModel],
|
|
1028
1220
|
activate: (
|
|
1029
1221
|
app: JupyterFrontEnd,
|
|
1030
|
-
settingsModel:
|
|
1222
|
+
settingsModel: IAISettingsModel
|
|
1031
1223
|
): IDiffManager => {
|
|
1032
1224
|
return new DiffManager({
|
|
1033
1225
|
commands: app.commands,
|
|
@@ -1058,7 +1250,7 @@ const toolRegistry: JupyterFrontEndPlugin<IToolRegistry> = {
|
|
|
1058
1250
|
provides: IToolRegistry,
|
|
1059
1251
|
activate: (
|
|
1060
1252
|
app: JupyterFrontEnd,
|
|
1061
|
-
settingsModel:
|
|
1253
|
+
settingsModel: IAISettingsModel,
|
|
1062
1254
|
skillRegistry?: ISkillRegistry
|
|
1063
1255
|
) => {
|
|
1064
1256
|
const toolRegistry = new ToolRegistry();
|
|
@@ -1098,7 +1290,7 @@ const inputToolbarFactory: JupyterFrontEndPlugin<IInputToolbarRegistryFactory> =
|
|
|
1098
1290
|
optional: [ITranslator],
|
|
1099
1291
|
activate: (
|
|
1100
1292
|
app: JupyterFrontEnd,
|
|
1101
|
-
settingsModel:
|
|
1293
|
+
settingsModel: IAISettingsModel,
|
|
1102
1294
|
toolRegistry: IToolRegistry,
|
|
1103
1295
|
providerRegistry: IProviderRegistry,
|
|
1104
1296
|
translator?: ITranslator
|
|
@@ -1148,7 +1340,7 @@ const completionStatus: JupyterFrontEndPlugin<void> = {
|
|
|
1148
1340
|
optional: [IStatusBar, ITranslator],
|
|
1149
1341
|
activate: (
|
|
1150
1342
|
app: JupyterFrontEnd,
|
|
1151
|
-
settingsModel:
|
|
1343
|
+
settingsModel: IAISettingsModel,
|
|
1152
1344
|
statusBar: IStatusBar | null,
|
|
1153
1345
|
translator?: ITranslator
|
|
1154
1346
|
) => {
|
|
@@ -1179,7 +1371,7 @@ const skillsPlugin: JupyterFrontEndPlugin<void> = {
|
|
|
1179
1371
|
optional: [ICommandPalette, ITranslator],
|
|
1180
1372
|
activate: async (
|
|
1181
1373
|
app: JupyterFrontEnd,
|
|
1182
|
-
settingsModel:
|
|
1374
|
+
settingsModel: IAISettingsModel,
|
|
1183
1375
|
docManager: IDocumentManager,
|
|
1184
1376
|
skillRegistry: ISkillRegistry,
|
|
1185
1377
|
palette?: ICommandPalette,
|