@jupyterlite/ai 0.17.0 → 0.18.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/src/tokens.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ActiveCellManager, IMessage, IMessageContent } from '@jupyter/chat';
1
+ import { ActiveCellManager, IChatModel, IMessage } from '@jupyter/chat';
2
2
  import { VDomRenderer } from '@jupyterlab/apputils';
3
3
  import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
4
4
  import { Token } from '@lumino/coreutils';
@@ -8,7 +8,6 @@ import type { Tool, LanguageModel, UserContent, ModelMessage } from 'ai';
8
8
  import { ISecretsManager } from 'jupyter-secrets-manager';
9
9
 
10
10
  import type { IModelOptions } from './providers/models';
11
- import { AIChatModel } from './chat-model';
12
11
  import type {
13
12
  ISkillDefinition,
14
13
  ISkillRegistration,
@@ -210,6 +209,18 @@ export interface IProviderModelInfo {
210
209
  * Default context window for the model in tokens.
211
210
  */
212
211
  contextWindow?: number;
212
+ /**
213
+ * Whether the model supports image inputs.
214
+ */
215
+ supportsImages?: boolean;
216
+ /**
217
+ * Whether the model supports PDF inputs.
218
+ */
219
+ supportsPdf?: boolean;
220
+ /**
221
+ * Whether the model supports audio inputs.
222
+ */
223
+ supportsAudio?: boolean;
213
224
  }
214
225
 
215
226
  export interface IProviderInfo {
@@ -398,6 +409,8 @@ export interface IAIConfig {
398
409
  skillsPaths: string[];
399
410
  // Directory where chat backups are saved
400
411
  chatBackupDirectory: string;
412
+ // Automatically request a title from the model for every message until there are 5 messages
413
+ autoTitle: boolean;
401
414
  }
402
415
 
403
416
  export interface IAISettingsModel extends VDomRenderer.IModel {
@@ -514,13 +527,12 @@ export namespace IAgentManager {
514
527
  isError: boolean;
515
528
  };
516
529
  tool_approval_request: {
517
- approvalId: string;
518
530
  toolCallId: string;
519
531
  toolName: string;
520
532
  args: unknown;
521
533
  };
522
534
  tool_approval_resolved: {
523
- approvalId: string;
535
+ toolCallId: string;
524
536
  approved: boolean;
525
537
  };
526
538
  error: {
@@ -587,26 +599,26 @@ export interface IAgentManager {
587
599
  */
588
600
  clearHistory(): Promise<void>;
589
601
  /**
590
- * Sets the conversation history with a list of messages from the chat.
591
- * @param messages The chat messages to set as history
602
+ * Sets the history from already-processed model messages.
603
+ * @param messages Pre-built model messages (may include binary content)
592
604
  */
593
- setHistory(messages: IMessageContent[]): void;
605
+ setHistory(messages: ModelMessage[]): void;
594
606
  /**
595
607
  * Stops the current streaming response by aborting the request.
596
608
  */
597
609
  stopStreaming(): void;
598
610
  /**
599
611
  * Approves a pending tool call.
600
- * @param approvalId The approval ID to approve
612
+ * @param toolCallId The tool call ID to approve
601
613
  * @param reason Optional reason for approval
602
614
  */
603
- approveToolCall(approvalId: string, reason?: string): void;
615
+ approveToolCall(toolCallId: string, reason?: string): void;
604
616
  /**
605
617
  * Rejects a pending tool call.
606
- * @param approvalId The approval ID to reject
618
+ * @param toolCallId The tool call ID to reject
607
619
  * @param reason Optional reason for rejection
608
620
  */
609
- rejectToolCall(approvalId: string, reason?: string): void;
621
+ rejectToolCall(toolCallId: string, reason?: string): void;
610
622
  /**
611
623
  * Generates AI response to user message using the agent.
612
624
  * Handles the complete execution cycle including tool calls.
@@ -666,6 +678,69 @@ export const IAgentManagerFactory = new Token<IAgentManagerFactory>(
666
678
 
667
679
  /* THE CHAT MODELS HANDLER */
668
680
 
681
+ export interface IAIChatModel extends IChatModel {
682
+ /**
683
+ * A signal emitting when the chat name has changed.
684
+ */
685
+ readonly nameChanged: ISignal<IAIChatModel, string>;
686
+ /**
687
+ * The title of the chat.
688
+ */
689
+ title: string | null;
690
+ /**
691
+ * A signal emitting when the chat title has changed.
692
+ */
693
+ readonly titleChanged: ISignal<IAIChatModel, string | null>;
694
+ /**
695
+ * Whether to save the chat automatically.
696
+ */
697
+ autosave: boolean;
698
+ /**
699
+ * A signal emitting when the autosave flag changed.
700
+ */
701
+ readonly autosaveChanged: ISignal<IAIChatModel, boolean>;
702
+ /**
703
+ * Whether save/restore is available.
704
+ */
705
+ readonly saveAvailable: boolean;
706
+ /**
707
+ * A signal emitting when the token usage changed.
708
+ */
709
+ readonly tokenUsageChanged: ISignal<IAgentManager, ITokenUsage>;
710
+ /**
711
+ * The agent manager used in the model.
712
+ */
713
+ readonly agentManager: IAgentManager;
714
+ /**
715
+ * Save the chat as json file.
716
+ */
717
+ save(): Promise<void>;
718
+ /**
719
+ * Restore the chat from a json file.
720
+ *
721
+ * @param silent - Whether a log should be displayed in the console if the
722
+ * restoration is not possible.
723
+ */
724
+ restore(filepath: string, silent?: boolean): Promise<boolean>;
725
+ /**
726
+ * Request a title to this chat, regarding the message history.
727
+ */
728
+ requestTitle(): Promise<string>;
729
+ /**
730
+ * Removes a queued message by its ID.
731
+ * @param messageId The ID of the queued message to remove
732
+ */
733
+ removeQueuedMessage(messageId: string): void;
734
+ /**
735
+ * The current message queue
736
+ */
737
+ messageQueue: any[];
738
+ /**
739
+ * Whether the chat is currently busy processing a message
740
+ */
741
+ isBusy: boolean;
742
+ }
743
+
669
744
  /**
670
745
  * The interface for the chat model handler.
671
746
  */
@@ -673,7 +748,7 @@ export interface IChatModelHandler {
673
748
  /**
674
749
  * The function to create a new model.
675
750
  */
676
- createModel(options: ICreateChatOptions): AIChatModel;
751
+ createModel(options: ICreateChatOptions): IAIChatModel;
677
752
  /**
678
753
  * The active cell manager (to copy code from chat to cell).
679
754
  */
@@ -925,6 +925,32 @@ const AISettingsComponent: React.FC<IAISettingsComponentProps> = ({
925
925
  }
926
926
  />
927
927
 
928
+ <FormControlLabel
929
+ control={
930
+ <Switch
931
+ checked={config.autoTitle}
932
+ onChange={e =>
933
+ handleConfigUpdate({
934
+ autoTitle: e.target.checked
935
+ })
936
+ }
937
+ color="primary"
938
+ />
939
+ }
940
+ label={
941
+ <Box>
942
+ <Typography variant="body1">
943
+ {trans.__('Auto Title')}
944
+ </Typography>
945
+ <Typography variant="caption" color="text.secondary">
946
+ {trans.__(
947
+ 'Automatically generate a chat title from the model for every message until there are 5 messages'
948
+ )}
949
+ </Typography>
950
+ </Box>
951
+ }
952
+ />
953
+
928
954
  <FormControlLabel
929
955
  control={
930
956
  <Switch
@@ -4,11 +4,10 @@ import { launchIcon } from '@jupyterlab/ui-components';
4
4
  import type { TranslationBundle } from '@jupyterlab/translation';
5
5
  import { CommandRegistry } from '@lumino/commands';
6
6
 
7
- import { AIChatModel } from '../chat-model';
8
7
  import { SaveComponentWidget } from '../components/save-button';
9
8
  import { UsageWidget } from '../components/usage-display';
10
9
  import { RenderedMessageOutputAreaCompat } from '../rendered-message-outputarea';
11
- import { CommandIds, type IAISettingsModel } from '../tokens';
10
+ import { CommandIds, IAIChatModel, type IAISettingsModel } from '../tokens';
12
11
 
13
12
  export namespace MainAreaChat {
14
13
  export interface IOptions extends MainAreaWidget.IOptions<ChatWidget> {
@@ -69,7 +68,7 @@ export class MainAreaChat extends MainAreaWidget<ChatWidget> {
69
68
  chatPanel: this.content
70
69
  });
71
70
 
72
- this.model.writersChanged.connect(this._writersChanged);
71
+ this.model.writersChanged?.connect(this._writersChanged);
73
72
 
74
73
  this.model.titleChanged.connect(this._titleChanged);
75
74
  }
@@ -78,15 +77,15 @@ export class MainAreaChat extends MainAreaWidget<ChatWidget> {
78
77
  super.dispose();
79
78
  // Dispose of the approval buttons widget when the chat is disposed.
80
79
  this._outputAreaCompat.dispose();
81
- this.model.writersChanged.disconnect(this._writersChanged);
80
+ this.model.writersChanged?.disconnect(this._writersChanged);
82
81
  this.model.titleChanged.disconnect(this._titleChanged);
83
82
  }
84
83
 
85
84
  /**
86
85
  * Get the model of the chat.
87
86
  */
88
- get model(): AIChatModel {
89
- return this.content.model as AIChatModel;
87
+ get model(): IAIChatModel {
88
+ return this.content.model as IAIChatModel;
90
89
  }
91
90
 
92
91
  /**
@@ -103,11 +102,9 @@ export class MainAreaChat extends MainAreaWidget<ChatWidget> {
103
102
  );
104
103
 
105
104
  if (aiWriting) {
106
- this.content.inputToolbarRegistry?.hide('send');
107
105
  this.content.inputToolbarRegistry?.show('stop');
108
106
  } else {
109
107
  this.content.inputToolbarRegistry?.hide('stop');
110
- this.content.inputToolbarRegistry?.show('send');
111
108
  }
112
109
  };
113
110
 
@@ -1,96 +0,0 @@
1
- /**
2
- * This file is generated by `jlpm sync:model-context-windows`.
3
- * Source: https://models.dev/api.json
4
- * Backed by: https://github.com/anomalyco/models.dev
5
- * Generated: 2026-04-08T16:23:34.080Z
6
- */
7
- export const BUILT_IN_PROVIDER_MODEL_INFO = {
8
- anthropic: {
9
- 'claude-opus-4-6': { contextWindow: 1000000 },
10
- 'claude-sonnet-4-6': { contextWindow: 1000000 },
11
- 'claude-opus-4-5': { contextWindow: 200000 },
12
- 'claude-opus-4-5-20251101': { contextWindow: 200000 },
13
- 'claude-sonnet-4-5': { contextWindow: 200000 },
14
- 'claude-sonnet-4-5-20250929': { contextWindow: 200000 },
15
- 'claude-haiku-4-5': { contextWindow: 200000 },
16
- 'claude-haiku-4-5-20251001': { contextWindow: 200000 },
17
- 'claude-opus-4-1': { contextWindow: 200000 },
18
- 'claude-opus-4-1-20250805': { contextWindow: 200000 },
19
- 'claude-opus-4-0': { contextWindow: 200000 },
20
- 'claude-opus-4-20250514': { contextWindow: 200000 },
21
- 'claude-sonnet-4-0': { contextWindow: 200000 },
22
- 'claude-sonnet-4-20250514': { contextWindow: 200000 }
23
- },
24
- google: {
25
- 'gemini-3.1-pro-preview': { contextWindow: 1048576 },
26
- 'gemini-3.1-pro-preview-customtools': { contextWindow: 1048576 },
27
- 'gemini-3.1-flash-image-preview': { contextWindow: 131072 },
28
- 'gemini-3.1-flash-lite-preview': { contextWindow: 1048576 },
29
- 'gemini-3-flash-preview': { contextWindow: 1048576 },
30
- 'gemini-2.5-pro': { contextWindow: 1048576 },
31
- 'gemini-2.5-flash': { contextWindow: 1048576 },
32
- 'gemini-2.5-flash-image': { contextWindow: 32768 },
33
- 'gemini-2.5-flash-lite': { contextWindow: 1048576 },
34
- 'gemini-flash-latest': { contextWindow: 1048576 },
35
- 'gemini-flash-lite-latest': { contextWindow: 1048576 }
36
- },
37
- mistral: {
38
- 'mistral-large-latest': { contextWindow: 262144 },
39
- 'mistral-medium-latest': { contextWindow: 128000 },
40
- 'mistral-medium-2508': { contextWindow: 262144 },
41
- 'mistral-small-latest': { contextWindow: 256000 },
42
- 'mistral-small-2506': { contextWindow: 128000 },
43
- 'ministral-3b-latest': { contextWindow: 128000 },
44
- 'ministral-8b-latest': { contextWindow: 128000 },
45
- 'magistral-small-latest': { contextWindow: 128000 },
46
- 'magistral-medium-latest': { contextWindow: 128000 },
47
- 'pixtral-large-latest': { contextWindow: 128000 },
48
- 'codestral-latest': { contextWindow: 256000 },
49
- 'devstral-latest': { contextWindow: 262144 },
50
- 'devstral-2512': { contextWindow: 262144 }
51
- },
52
- openai: {
53
- 'gpt-5.4': { contextWindow: 1050000 },
54
- 'gpt-5.4-mini': { contextWindow: 400000 },
55
- 'gpt-5.4-nano': { contextWindow: 400000 },
56
- 'gpt-5.2': { contextWindow: 400000 },
57
- 'gpt-5.2-2025-12-11': { contextWindow: 400000 },
58
- 'gpt-5.2-chat-latest': { contextWindow: 128000 },
59
- 'gpt-5.2-pro': { contextWindow: 400000 },
60
- 'gpt-5.2-pro-2025-12-11': { contextWindow: 400000 },
61
- 'gpt-5.2-codex': { contextWindow: 400000 },
62
- 'gpt-5.1': { contextWindow: 400000 },
63
- 'gpt-5.1-2025-11-13': { contextWindow: 400000 },
64
- 'gpt-5.1-chat-latest': { contextWindow: 128000 },
65
- 'gpt-5': { contextWindow: 400000 },
66
- 'gpt-5-2025-08-07': { contextWindow: 400000 },
67
- 'gpt-5-chat-latest': { contextWindow: 400000 },
68
- 'gpt-5-mini': { contextWindow: 400000 },
69
- 'gpt-5-mini-2025-08-07': { contextWindow: 400000 },
70
- 'gpt-5-nano': { contextWindow: 400000 },
71
- 'gpt-5-nano-2025-08-07': { contextWindow: 400000 },
72
- 'o4-mini': { contextWindow: 200000 },
73
- 'o4-mini-2025-04-16': { contextWindow: 200000 },
74
- 'o3-pro': { contextWindow: 200000 },
75
- o3: { contextWindow: 200000 },
76
- 'o3-2025-04-16': { contextWindow: 200000 },
77
- 'o3-mini': { contextWindow: 200000 },
78
- 'o3-mini-2025-01-31': { contextWindow: 200000 },
79
- o1: { contextWindow: 200000 },
80
- 'o1-2024-12-17': { contextWindow: 200000 },
81
- 'gpt-4.1': { contextWindow: 1047576 },
82
- 'gpt-4.1-2025-04-14': { contextWindow: 1047576 },
83
- 'gpt-4.1-mini': { contextWindow: 1047576 },
84
- 'gpt-4.1-mini-2025-04-14': { contextWindow: 1047576 },
85
- 'gpt-4.1-nano': { contextWindow: 1047576 },
86
- 'gpt-4.1-nano-2025-04-14': { contextWindow: 1047576 },
87
- 'gpt-4o': { contextWindow: 128000 },
88
- 'gpt-4o-2024-05-13': { contextWindow: 128000 },
89
- 'gpt-4o-2024-08-06': { contextWindow: 128000 },
90
- 'gpt-4o-2024-11-20': { contextWindow: 128000 },
91
- 'gpt-4o-mini': { contextWindow: 128000 },
92
- 'gpt-4o-mini-2024-07-18': { contextWindow: 128000 },
93
- 'gpt-3.5-turbo': { contextWindow: 16385 },
94
- 'gpt-3.5-turbo-0125': { contextWindow: 16385 }
95
- }
96
- };
@@ -1,102 +0,0 @@
1
- /**
2
- * This file is generated by `jlpm sync:model-context-windows`.
3
- * Source: https://models.dev/api.json
4
- * Backed by: https://github.com/anomalyco/models.dev
5
- * Generated: 2026-04-08T16:23:34.080Z
6
- */
7
-
8
- import type { IProviderModelInfo } from '../tokens';
9
-
10
- export const BUILT_IN_PROVIDER_MODEL_INFO: Record<
11
- string,
12
- Record<string, IProviderModelInfo>
13
- > = {
14
- anthropic: {
15
- 'claude-opus-4-6': { contextWindow: 1000000 },
16
- 'claude-sonnet-4-6': { contextWindow: 1000000 },
17
- 'claude-opus-4-5': { contextWindow: 200000 },
18
- 'claude-opus-4-5-20251101': { contextWindow: 200000 },
19
- 'claude-sonnet-4-5': { contextWindow: 200000 },
20
- 'claude-sonnet-4-5-20250929': { contextWindow: 200000 },
21
- 'claude-haiku-4-5': { contextWindow: 200000 },
22
- 'claude-haiku-4-5-20251001': { contextWindow: 200000 },
23
- 'claude-opus-4-1': { contextWindow: 200000 },
24
- 'claude-opus-4-1-20250805': { contextWindow: 200000 },
25
- 'claude-opus-4-0': { contextWindow: 200000 },
26
- 'claude-opus-4-20250514': { contextWindow: 200000 },
27
- 'claude-sonnet-4-0': { contextWindow: 200000 },
28
- 'claude-sonnet-4-20250514': { contextWindow: 200000 }
29
- },
30
- google: {
31
- 'gemini-3.1-pro-preview': { contextWindow: 1048576 },
32
- 'gemini-3.1-pro-preview-customtools': { contextWindow: 1048576 },
33
- 'gemini-3.1-flash-image-preview': { contextWindow: 131072 },
34
- 'gemini-3.1-flash-lite-preview': { contextWindow: 1048576 },
35
- 'gemini-3-flash-preview': { contextWindow: 1048576 },
36
- 'gemini-2.5-pro': { contextWindow: 1048576 },
37
- 'gemini-2.5-flash': { contextWindow: 1048576 },
38
- 'gemini-2.5-flash-image': { contextWindow: 32768 },
39
- 'gemini-2.5-flash-lite': { contextWindow: 1048576 },
40
- 'gemini-flash-latest': { contextWindow: 1048576 },
41
- 'gemini-flash-lite-latest': { contextWindow: 1048576 }
42
- },
43
- mistral: {
44
- 'mistral-large-latest': { contextWindow: 262144 },
45
- 'mistral-medium-latest': { contextWindow: 128000 },
46
- 'mistral-medium-2508': { contextWindow: 262144 },
47
- 'mistral-small-latest': { contextWindow: 256000 },
48
- 'mistral-small-2506': { contextWindow: 128000 },
49
- 'ministral-3b-latest': { contextWindow: 128000 },
50
- 'ministral-8b-latest': { contextWindow: 128000 },
51
- 'magistral-small-latest': { contextWindow: 128000 },
52
- 'magistral-medium-latest': { contextWindow: 128000 },
53
- 'pixtral-large-latest': { contextWindow: 128000 },
54
- 'codestral-latest': { contextWindow: 256000 },
55
- 'devstral-latest': { contextWindow: 262144 },
56
- 'devstral-2512': { contextWindow: 262144 }
57
- },
58
- openai: {
59
- 'gpt-5.4': { contextWindow: 1050000 },
60
- 'gpt-5.4-mini': { contextWindow: 400000 },
61
- 'gpt-5.4-nano': { contextWindow: 400000 },
62
- 'gpt-5.2': { contextWindow: 400000 },
63
- 'gpt-5.2-2025-12-11': { contextWindow: 400000 },
64
- 'gpt-5.2-chat-latest': { contextWindow: 128000 },
65
- 'gpt-5.2-pro': { contextWindow: 400000 },
66
- 'gpt-5.2-pro-2025-12-11': { contextWindow: 400000 },
67
- 'gpt-5.2-codex': { contextWindow: 400000 },
68
- 'gpt-5.1': { contextWindow: 400000 },
69
- 'gpt-5.1-2025-11-13': { contextWindow: 400000 },
70
- 'gpt-5.1-chat-latest': { contextWindow: 128000 },
71
- 'gpt-5': { contextWindow: 400000 },
72
- 'gpt-5-2025-08-07': { contextWindow: 400000 },
73
- 'gpt-5-chat-latest': { contextWindow: 400000 },
74
- 'gpt-5-mini': { contextWindow: 400000 },
75
- 'gpt-5-mini-2025-08-07': { contextWindow: 400000 },
76
- 'gpt-5-nano': { contextWindow: 400000 },
77
- 'gpt-5-nano-2025-08-07': { contextWindow: 400000 },
78
- 'o4-mini': { contextWindow: 200000 },
79
- 'o4-mini-2025-04-16': { contextWindow: 200000 },
80
- 'o3-pro': { contextWindow: 200000 },
81
- o3: { contextWindow: 200000 },
82
- 'o3-2025-04-16': { contextWindow: 200000 },
83
- 'o3-mini': { contextWindow: 200000 },
84
- 'o3-mini-2025-01-31': { contextWindow: 200000 },
85
- o1: { contextWindow: 200000 },
86
- 'o1-2024-12-17': { contextWindow: 200000 },
87
- 'gpt-4.1': { contextWindow: 1047576 },
88
- 'gpt-4.1-2025-04-14': { contextWindow: 1047576 },
89
- 'gpt-4.1-mini': { contextWindow: 1047576 },
90
- 'gpt-4.1-mini-2025-04-14': { contextWindow: 1047576 },
91
- 'gpt-4.1-nano': { contextWindow: 1047576 },
92
- 'gpt-4.1-nano-2025-04-14': { contextWindow: 1047576 },
93
- 'gpt-4o': { contextWindow: 128000 },
94
- 'gpt-4o-2024-05-13': { contextWindow: 128000 },
95
- 'gpt-4o-2024-08-06': { contextWindow: 128000 },
96
- 'gpt-4o-2024-11-20': { contextWindow: 128000 },
97
- 'gpt-4o-mini': { contextWindow: 128000 },
98
- 'gpt-4o-mini-2024-07-18': { contextWindow: 128000 },
99
- 'gpt-3.5-turbo': { contextWindow: 16385 },
100
- 'gpt-3.5-turbo-0125': { contextWindow: 16385 }
101
- }
102
- };