@jupyterlite/ai 0.14.0 → 0.15.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 (52) hide show
  1. package/lib/agent.d.ts +28 -114
  2. package/lib/agent.js +140 -100
  3. package/lib/chat-model-handler.d.ts +9 -11
  4. package/lib/chat-model-handler.js +9 -4
  5. package/lib/chat-model.d.ts +84 -13
  6. package/lib/chat-model.js +208 -136
  7. package/lib/completion/completion-provider.d.ts +2 -3
  8. package/lib/components/completion-status.d.ts +2 -2
  9. package/lib/components/model-select.d.ts +3 -3
  10. package/lib/components/save-button.d.ts +31 -0
  11. package/lib/components/save-button.js +41 -0
  12. package/lib/components/token-usage-display.d.ts +2 -3
  13. package/lib/components/tool-select.d.ts +3 -4
  14. package/lib/diff-manager.d.ts +2 -3
  15. package/lib/index.d.ts +2 -4
  16. package/lib/index.js +181 -23
  17. package/lib/models/settings-model.d.ts +11 -53
  18. package/lib/models/settings-model.js +37 -22
  19. package/lib/providers/built-in-providers.js +17 -36
  20. package/lib/tokens.d.ts +340 -36
  21. package/lib/tokens.js +11 -6
  22. package/lib/tools/commands.d.ts +2 -3
  23. package/lib/widgets/ai-settings.d.ts +3 -5
  24. package/lib/widgets/ai-settings.js +3 -0
  25. package/lib/widgets/main-area-chat.d.ts +2 -3
  26. package/lib/widgets/main-area-chat.js +9 -9
  27. package/lib/widgets/provider-config-dialog.d.ts +1 -2
  28. package/lib/widgets/provider-config-dialog.js +16 -29
  29. package/package.json +15 -9
  30. package/schema/settings-model.json +7 -1
  31. package/src/agent.ts +197 -242
  32. package/src/chat-model-handler.ts +25 -21
  33. package/src/chat-model.ts +304 -196
  34. package/src/completion/completion-provider.ts +7 -4
  35. package/src/components/completion-status.tsx +3 -3
  36. package/src/components/model-select.tsx +4 -3
  37. package/src/components/save-button.tsx +84 -0
  38. package/src/components/token-usage-display.tsx +2 -3
  39. package/src/components/tool-select.tsx +10 -4
  40. package/src/diff-manager.ts +4 -4
  41. package/src/index.ts +245 -49
  42. package/src/models/settings-model.ts +45 -88
  43. package/src/providers/built-in-providers.ts +17 -36
  44. package/src/tokens.ts +406 -52
  45. package/src/tools/commands.ts +2 -3
  46. package/src/widgets/ai-settings.tsx +27 -15
  47. package/src/widgets/main-area-chat.ts +15 -12
  48. package/src/widgets/provider-config-dialog.tsx +51 -56
  49. package/style/base.css +17 -195
  50. package/lib/approval-buttons.d.ts +0 -49
  51. package/lib/approval-buttons.js +0 -79
  52. package/src/approval-buttons.ts +0 -115
@@ -1,8 +1,8 @@
1
1
  import React, { useEffect, useState } from 'react';
2
- import { AISettingsModel } from '../models/settings-model';
3
2
  import { ReactWidget } from '@jupyterlab/ui-components';
4
3
  import type { TranslationBundle } from '@jupyterlab/translation';
5
4
  import { jupyternautIcon } from '../icons';
5
+ import type { IAISettingsModel } from '../tokens';
6
6
 
7
7
  const COMPLETION_STATUS_CLASS = 'jp-ai-completion-status';
8
8
  const COMPLETION_DISABLED_CLASS = 'jp-ai-completion-disabled';
@@ -14,7 +14,7 @@ interface ICompletionStatusProps {
14
14
  /**
15
15
  * The settings model.
16
16
  */
17
- settingsModel: AISettingsModel;
17
+ settingsModel: IAISettingsModel;
18
18
  /**
19
19
  * The application language translator.
20
20
  */
@@ -33,7 +33,7 @@ function CompletionStatus(props: ICompletionStatusProps): JSX.Element {
33
33
  * Handle changes in the settings.
34
34
  */
35
35
  useEffect(() => {
36
- const stateChanged = (model: AISettingsModel) => {
36
+ const stateChanged = (model: IAISettingsModel) => {
37
37
  if (model.config.useSameProviderForChatAndCompleter) {
38
38
  setDisabled(false);
39
39
  setTitle(
@@ -4,7 +4,8 @@ import CheckIcon from '@mui/icons-material/Check';
4
4
  import { Menu, MenuItem, Typography } from '@mui/material';
5
5
  import React, { useCallback, useEffect, useState } from 'react';
6
6
  import { AIChatModel } from '../chat-model';
7
- import { AISettingsModel } from '../models/settings-model';
7
+ import type { IAISettingsModel } from '../tokens';
8
+
8
9
  /**
9
10
  * Properties for the model select component.
10
11
  */
@@ -13,7 +14,7 @@ export interface IModelSelectProps
13
14
  /**
14
15
  * The settings model to get available models and current selection from.
15
16
  */
16
- settingsModel: AISettingsModel;
17
+ settingsModel: IAISettingsModel;
17
18
  /**
18
19
  * The application language translator.
19
20
  */
@@ -243,7 +244,7 @@ export function ModelSelect(props: IModelSelectProps): JSX.Element {
243
244
  * Factory function returning the toolbar item for model selection.
244
245
  */
245
246
  export function createModelSelectItem(
246
- settingsModel: AISettingsModel,
247
+ settingsModel: IAISettingsModel,
247
248
  translator: TranslationBundle
248
249
  ): InputToolbarRegistry.IToolbarItem {
249
250
  return {
@@ -0,0 +1,84 @@
1
+ import {
2
+ historyIcon,
3
+ ReactWidget,
4
+ saveIcon,
5
+ ToolbarButtonComponent
6
+ } from '@jupyterlab/ui-components';
7
+ import type { TranslationBundle } from '@jupyterlab/translation';
8
+ import React, { useEffect, useState } from 'react';
9
+
10
+ import { AIChatModel } from '../chat-model';
11
+
12
+ const COMPONENT_CLASS = 'jp-ai-SaveButton';
13
+ const AUTOSAVE_BUTTON_CLASS = 'jp-ai-AutoSaveButton';
14
+
15
+ /**
16
+ * Properties for the SaveButton component.
17
+ */
18
+ export interface ISaveButtonProps {
19
+ /**
20
+ * The chat model, used to listen for message changes for auto-save.
21
+ */
22
+ model: AIChatModel;
23
+ /**
24
+ * The application language translator.
25
+ */
26
+ translator: TranslationBundle;
27
+ }
28
+
29
+ /**
30
+ * A split button for saving the chat, with a button to toggle auto-save.
31
+ * When auto-save is active, the save button displays the JupyterLab
32
+ * toggled-on appearance (inset box-shadow all around).
33
+ */
34
+ export function SaveComponent(props: ISaveButtonProps): JSX.Element {
35
+ const { model, translator: trans } = props;
36
+
37
+ const [autosave, setAutosave] = useState(model.autosave);
38
+
39
+ /**
40
+ * Effect that update the autosave state when it is updated on the model.
41
+ */
42
+ useEffect(() => {
43
+ const updateAutosave = (_: AIChatModel, value: boolean) => {
44
+ setAutosave(value);
45
+ };
46
+
47
+ model.autosaveChanged.connect(updateAutosave);
48
+ return () => {
49
+ model.autosaveChanged.disconnect(updateAutosave);
50
+ };
51
+ }, [model]);
52
+
53
+ return (
54
+ <div className={`${COMPONENT_CLASS}${autosave ? ' lm-mod-toggled' : ''}`}>
55
+ <ToolbarButtonComponent
56
+ icon={saveIcon}
57
+ onClick={() => model.save()}
58
+ tooltip={trans.__('Save chat')}
59
+ />
60
+ <ToolbarButtonComponent
61
+ className={AUTOSAVE_BUTTON_CLASS}
62
+ icon={historyIcon}
63
+ onClick={() => (model.autosave = !model.autosave)}
64
+ tooltip={trans.__('Auto-save')}
65
+ />
66
+ </div>
67
+ );
68
+ }
69
+
70
+ /**
71
+ * A Lumino widget wrapping the SaveButton React component.
72
+ */
73
+ export class SaveComponentWidget extends ReactWidget {
74
+ constructor(options: ISaveButtonProps) {
75
+ super();
76
+ this._options = options;
77
+ }
78
+
79
+ protected render(): React.ReactElement {
80
+ return <SaveComponent {...this._options} />;
81
+ }
82
+
83
+ private _options: ISaveButtonProps;
84
+ }
@@ -2,8 +2,7 @@ import { ReactWidget, UseSignal } from '@jupyterlab/ui-components';
2
2
  import type { TranslationBundle } from '@jupyterlab/translation';
3
3
  import React from 'react';
4
4
  import { ISignal } from '@lumino/signaling';
5
- import { AISettingsModel } from '../models/settings-model';
6
- import { ITokenUsage } from '../tokens';
5
+ import type { IAISettingsModel, ITokenUsage } from '../tokens';
7
6
 
8
7
  /**
9
8
  * Props for the TokenUsageDisplay component.
@@ -17,7 +16,7 @@ export interface ITokenUsageDisplayProps {
17
16
  /**
18
17
  * The settings model instance for configuration options
19
18
  */
20
- settingsModel: AISettingsModel;
19
+ settingsModel: IAISettingsModel;
21
20
 
22
21
  /**
23
22
  * Initial token usage.
@@ -10,11 +10,17 @@ import { Divider, Menu, MenuItem, Tooltip, Typography } from '@mui/material';
10
10
 
11
11
  import React, { useCallback, useEffect, useState } from 'react';
12
12
 
13
- import { INamedTool, IProviderRegistry, IToolRegistry } from '../tokens';
14
13
  import { AIChatModel } from '../chat-model';
15
- import { AISettingsModel } from '../models/settings-model';
14
+
16
15
  import { createProviderTools } from '../providers/provider-tools';
17
16
 
17
+ import type {
18
+ IAISettingsModel,
19
+ INamedTool,
20
+ IProviderRegistry,
21
+ IToolRegistry
22
+ } from '../tokens';
23
+
18
24
  const SELECT_ITEM_CLASS = 'jp-AIToolSelect-item';
19
25
 
20
26
  /**
@@ -40,7 +46,7 @@ export interface IToolSelectProps
40
46
  /**
41
47
  * The settings model to compute provider-level web tools.
42
48
  */
43
- settingsModel: AISettingsModel;
49
+ settingsModel: IAISettingsModel;
44
50
 
45
51
  /**
46
52
  * Registry for provider metadata used to resolve provider tool capabilities.
@@ -307,7 +313,7 @@ export function ToolSelect(props: IToolSelectProps): JSX.Element {
307
313
  */
308
314
  export function createToolSelectItem(
309
315
  toolRegistry: IToolRegistry,
310
- settingsModel: AISettingsModel,
316
+ settingsModel: IAISettingsModel,
311
317
  providerRegistry: IProviderRegistry,
312
318
  toolsEnabled: boolean = true,
313
319
  translator: TranslationBundle
@@ -1,6 +1,6 @@
1
1
  import { CommandRegistry } from '@lumino/commands';
2
- import { AISettingsModel } from './models/settings-model';
3
- import {
2
+ import type {
3
+ IAISettingsModel,
4
4
  IDiffManager,
5
5
  IShowCellDiffParams,
6
6
  IShowFileDiffParams
@@ -30,7 +30,7 @@ export class DiffManager implements IDiffManager {
30
30
  */
31
31
  constructor(options: {
32
32
  commands: CommandRegistry;
33
- settingsModel: AISettingsModel;
33
+ settingsModel: IAISettingsModel;
34
34
  }) {
35
35
  this._commands = options.commands;
36
36
  this._settingsModel = options.settingsModel;
@@ -77,5 +77,5 @@ export class DiffManager implements IDiffManager {
77
77
  }
78
78
 
79
79
  private _commands: CommandRegistry;
80
- private _settingsModel: AISettingsModel;
80
+ private _settingsModel: IAISettingsModel;
81
81
  }