@jupyterlite/ai 0.9.1 → 0.11.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 (71) hide show
  1. package/README.md +5 -214
  2. package/lib/agent.d.ts +58 -66
  3. package/lib/agent.js +291 -310
  4. package/lib/approval-buttons.d.ts +19 -82
  5. package/lib/approval-buttons.js +36 -289
  6. package/lib/chat-model-registry.d.ts +6 -0
  7. package/lib/chat-model-registry.js +4 -1
  8. package/lib/chat-model.d.ts +26 -54
  9. package/lib/chat-model.js +277 -303
  10. package/lib/components/clear-button.d.ts +6 -1
  11. package/lib/components/clear-button.js +10 -6
  12. package/lib/components/completion-status.d.ts +5 -0
  13. package/lib/components/completion-status.js +5 -4
  14. package/lib/components/model-select.d.ts +6 -1
  15. package/lib/components/model-select.js +13 -16
  16. package/lib/components/stop-button.d.ts +6 -1
  17. package/lib/components/stop-button.js +12 -8
  18. package/lib/components/token-usage-display.d.ts +5 -0
  19. package/lib/components/token-usage-display.js +2 -2
  20. package/lib/components/tool-select.d.ts +6 -1
  21. package/lib/components/tool-select.js +10 -9
  22. package/lib/index.d.ts +1 -0
  23. package/lib/index.js +61 -81
  24. package/lib/models/settings-model.d.ts +1 -1
  25. package/lib/models/settings-model.js +40 -26
  26. package/lib/providers/built-in-providers.js +38 -19
  27. package/lib/providers/models.d.ts +3 -3
  28. package/lib/providers/provider-registry.d.ts +3 -4
  29. package/lib/providers/provider-registry.js +1 -4
  30. package/lib/tokens.d.ts +5 -6
  31. package/lib/tools/commands.d.ts +2 -1
  32. package/lib/tools/commands.js +36 -49
  33. package/lib/widgets/ai-settings.d.ts +6 -0
  34. package/lib/widgets/ai-settings.js +72 -71
  35. package/lib/widgets/main-area-chat.d.ts +2 -0
  36. package/lib/widgets/main-area-chat.js +5 -2
  37. package/lib/widgets/provider-config-dialog.d.ts +2 -0
  38. package/lib/widgets/provider-config-dialog.js +34 -34
  39. package/package.json +13 -13
  40. package/schema/settings-model.json +3 -2
  41. package/src/agent.ts +360 -372
  42. package/src/approval-buttons.ts +43 -389
  43. package/src/chat-model-registry.ts +9 -1
  44. package/src/chat-model.ts +399 -370
  45. package/src/completion/completion-provider.ts +2 -3
  46. package/src/components/clear-button.tsx +18 -6
  47. package/src/components/completion-status.tsx +18 -4
  48. package/src/components/model-select.tsx +25 -16
  49. package/src/components/stop-button.tsx +22 -9
  50. package/src/components/token-usage-display.tsx +14 -2
  51. package/src/components/tool-select.tsx +27 -9
  52. package/src/index.ts +78 -134
  53. package/src/models/settings-model.ts +41 -27
  54. package/src/providers/built-in-providers.ts +38 -19
  55. package/src/providers/models.ts +3 -3
  56. package/src/providers/provider-registry.ts +4 -8
  57. package/src/tokens.ts +5 -6
  58. package/src/tools/commands.ts +40 -53
  59. package/src/widgets/ai-settings.tsx +153 -84
  60. package/src/widgets/main-area-chat.ts +8 -2
  61. package/src/widgets/provider-config-dialog.tsx +54 -41
  62. package/style/base.css +24 -73
  63. package/lib/mcp/browser.d.ts +0 -68
  64. package/lib/mcp/browser.js +0 -138
  65. package/lib/tools/file.d.ts +0 -36
  66. package/lib/tools/file.js +0 -351
  67. package/lib/tools/notebook.d.ts +0 -40
  68. package/lib/tools/notebook.js +0 -779
  69. package/src/mcp/browser.ts +0 -220
  70. package/src/tools/file.ts +0 -438
  71. package/src/tools/notebook.ts +0 -986
@@ -1,4 +1,5 @@
1
1
  import { InputToolbarRegistry } from '@jupyter/chat';
2
+ import type { TranslationBundle } from '@jupyterlab/translation';
2
3
  /**
3
4
  * Properties of the clear button.
4
5
  */
@@ -7,6 +8,10 @@ export interface IClearButtonProps extends InputToolbarRegistry.IToolbarItemProp
7
8
  * The function to clear messages.
8
9
  */
9
10
  clearMessages: () => void;
11
+ /**
12
+ * The application language translator.
13
+ */
14
+ translator: TranslationBundle;
10
15
  }
11
16
  /**
12
17
  * The clear button component.
@@ -15,4 +20,4 @@ export declare function ClearButton(props: IClearButtonProps): JSX.Element;
15
20
  /**
16
21
  * Factory returning the clear button toolbar item.
17
22
  */
18
- export declare function clearItem(): InputToolbarRegistry.IToolbarItem;
23
+ export declare function clearItem(translator: TranslationBundle): InputToolbarRegistry.IToolbarItem;
@@ -5,24 +5,28 @@ import React from 'react';
5
5
  * The clear button component.
6
6
  */
7
7
  export function ClearButton(props) {
8
- const tooltip = 'Clear chat';
8
+ const { translator: trans } = props;
9
+ const tooltip = trans.__('Clear chat');
9
10
  return (React.createElement(TooltippedButton, { onClick: props.clearMessages, tooltip: tooltip, buttonProps: {
10
- size: 'small',
11
+ title: tooltip,
11
12
  variant: 'outlined',
12
- color: 'secondary',
13
- title: tooltip
13
+ color: 'secondary'
14
14
  } },
15
15
  React.createElement(ClearIcon, null)));
16
16
  }
17
17
  /**
18
18
  * Factory returning the clear button toolbar item.
19
19
  */
20
- export function clearItem() {
20
+ export function clearItem(translator) {
21
21
  return {
22
22
  element: (props) => {
23
23
  const { model } = props;
24
24
  const clearMessages = () => model.chatContext.clearMessages();
25
- const clearProps = { ...props, clearMessages };
25
+ const clearProps = {
26
+ ...props,
27
+ clearMessages,
28
+ translator
29
+ };
26
30
  return ClearButton(clearProps);
27
31
  },
28
32
  position: 0,
@@ -1,5 +1,6 @@
1
1
  import { AISettingsModel } from '../models/settings-model';
2
2
  import { ReactWidget } from '@jupyterlab/ui-components';
3
+ import type { TranslationBundle } from '@jupyterlab/translation';
3
4
  /**
4
5
  * The completion status props.
5
6
  */
@@ -8,6 +9,10 @@ interface ICompletionStatusProps {
8
9
  * The settings model.
9
10
  */
10
11
  settingsModel: AISettingsModel;
12
+ /**
13
+ * The application language translator.
14
+ */
15
+ translator: TranslationBundle;
11
16
  }
12
17
  /**
13
18
  * The completion status widget that will be added to the status bar.
@@ -7,6 +7,7 @@ const COMPLETION_DISABLED_CLASS = 'jp-ai-completion-disabled';
7
7
  * The completion status component.
8
8
  */
9
9
  function CompletionStatus(props) {
10
+ const { translator: trans } = props;
10
11
  const [disabled, setDisabled] = useState(true);
11
12
  const [title, setTitle] = useState('');
12
13
  /**
@@ -16,15 +17,15 @@ function CompletionStatus(props) {
16
17
  const stateChanged = (model) => {
17
18
  if (model.config.useSameProviderForChatAndCompleter) {
18
19
  setDisabled(false);
19
- setTitle(`Completion using ${model.getDefaultProvider()?.model}`);
20
+ setTitle(trans.__('Completion using %1', model.getDefaultProvider()?.model ?? ''));
20
21
  }
21
22
  else if (model.config.activeCompleterProvider) {
22
23
  setDisabled(false);
23
- setTitle(`Completion using ${model.getProvider(model.config.activeCompleterProvider)?.model}`);
24
+ setTitle(trans.__('Completion using %1', model.getProvider(model.config.activeCompleterProvider)?.model ?? ''));
24
25
  }
25
26
  else {
26
27
  setDisabled(true);
27
- setTitle('No completion');
28
+ setTitle(trans.__('No completion'));
28
29
  }
29
30
  };
30
31
  props.settingsModel.stateChanged.connect(stateChanged);
@@ -32,7 +33,7 @@ function CompletionStatus(props) {
32
33
  return () => {
33
34
  props.settingsModel.stateChanged.disconnect(stateChanged);
34
35
  };
35
- }, [props.settingsModel]);
36
+ }, [props.settingsModel, trans]);
36
37
  return (React.createElement(jupyternautIcon.react, { className: disabled ? COMPLETION_DISABLED_CLASS : '', top: '2px', width: '16px', stylesheet: 'statusBar', title: title }));
37
38
  }
38
39
  /**
@@ -1,4 +1,5 @@
1
1
  import { InputToolbarRegistry } from '@jupyter/chat';
2
+ import type { TranslationBundle } from '@jupyterlab/translation';
2
3
  import { AISettingsModel } from '../models/settings-model';
3
4
  /**
4
5
  * Properties for the model select component.
@@ -8,6 +9,10 @@ export interface IModelSelectProps extends InputToolbarRegistry.IToolbarItemProp
8
9
  * The settings model to get available models and current selection from.
9
10
  */
10
11
  settingsModel: AISettingsModel;
12
+ /**
13
+ * The application language translator.
14
+ */
15
+ translator: TranslationBundle;
11
16
  }
12
17
  /**
13
18
  * The model select component for choosing AI models.
@@ -16,4 +21,4 @@ export declare function ModelSelect(props: IModelSelectProps): JSX.Element;
16
21
  /**
17
22
  * Factory function returning the toolbar item for model selection.
18
23
  */
19
- export declare function createModelSelectItem(settingsModel: AISettingsModel): InputToolbarRegistry.IToolbarItem;
24
+ export declare function createModelSelectItem(settingsModel: AISettingsModel, translator: TranslationBundle): InputToolbarRegistry.IToolbarItem;
@@ -6,7 +6,7 @@ import React, { useCallback, useEffect, useState } from 'react';
6
6
  * The model select component for choosing AI models.
7
7
  */
8
8
  export function ModelSelect(props) {
9
- const { settingsModel, model } = props;
9
+ const { settingsModel, model, translator: trans } = props;
10
10
  const agentManager = model.chatContext
11
11
  .agentManager;
12
12
  const [currentProvider, setCurrentProvider] = useState(agentManager.activeProvider ?? '');
@@ -60,28 +60,24 @@ export function ModelSelect(props) {
60
60
  }));
61
61
  // Show a message if no providers are configured
62
62
  if (availableModels.length === 0) {
63
- return (React.createElement(TooltippedButton, { onClick: () => { }, tooltip: "No providers configured. Please go to AI Settings to add a provider.", buttonProps: {
64
- size: 'small',
63
+ return (React.createElement(TooltippedButton, { onClick: () => { }, tooltip: trans.__('No providers configured. Please go to AI Settings to add a provider.'), buttonProps: {
65
64
  variant: 'outlined',
66
65
  color: 'warning',
67
66
  disabled: true,
68
- title: 'No Providers Available'
67
+ title: trans.__('No Providers Available')
69
68
  }, sx: {
70
69
  minWidth: 'auto',
70
+ width: 'unset',
71
71
  display: 'flex',
72
- alignItems: 'center',
73
- height: '29px'
72
+ alignItems: 'center'
74
73
  } },
75
- React.createElement(Typography, { variant: "caption", sx: { fontSize: '0.7rem', fontWeight: 500 } }, "No Providers")));
74
+ React.createElement(Typography, { variant: "caption", sx: { fontSize: '0.7rem', fontWeight: 500 } }, trans.__('No Providers'))));
76
75
  }
77
76
  return (React.createElement(React.Fragment, null,
78
77
  React.createElement(TooltippedButton, { onClick: e => {
79
78
  openMenu(e.currentTarget);
80
- }, tooltip: `Current Model: ${currentProviderLabel} - ${currentModel}`, buttonProps: {
81
- size: 'small',
82
- variant: 'contained',
83
- color: 'primary',
84
- title: 'Select AI Model',
79
+ }, tooltip: trans.__('Current Model: %1 - %2', currentProviderLabel, currentModel), buttonProps: {
80
+ title: trans.__('Select AI Model'),
85
81
  onKeyDown: e => {
86
82
  if (e.key !== 'Enter' && e.key !== ' ') {
87
83
  return;
@@ -92,9 +88,9 @@ export function ModelSelect(props) {
92
88
  }
93
89
  }, sx: {
94
90
  minWidth: 'auto',
91
+ width: 'unset',
95
92
  display: 'flex',
96
- alignItems: 'center',
97
- height: '29px'
93
+ alignItems: 'center'
98
94
  } },
99
95
  React.createElement(Typography, { variant: "caption", sx: { fontSize: '0.7rem', fontWeight: 500, textTransform: 'none' } }, currentProviderLabel)),
100
96
  React.createElement(Menu, { open: menuOpen, onClose: closeMenu, anchorEl: menuAnchorEl, anchorOrigin: {
@@ -144,7 +140,7 @@ export function ModelSelect(props) {
144
140
  /**
145
141
  * Factory function returning the toolbar item for model selection.
146
142
  */
147
- export function createModelSelectItem(settingsModel) {
143
+ export function createModelSelectItem(settingsModel, translator) {
148
144
  return {
149
145
  element: (props) => {
150
146
  const chatContext = props.model.chatContext;
@@ -153,7 +149,8 @@ export function createModelSelectItem(settingsModel) {
153
149
  }
154
150
  const modelSelectProps = {
155
151
  ...props,
156
- settingsModel
152
+ settingsModel,
153
+ translator
157
154
  };
158
155
  return React.createElement(ModelSelect, { ...modelSelectProps });
159
156
  },
@@ -1,4 +1,5 @@
1
1
  import { InputToolbarRegistry } from '@jupyter/chat';
2
+ import type { TranslationBundle } from '@jupyterlab/translation';
2
3
  /**
3
4
  * Properties of the stop button.
4
5
  */
@@ -7,6 +8,10 @@ export interface IStopButtonProps extends InputToolbarRegistry.IToolbarItemProps
7
8
  * The function to stop streaming.
8
9
  */
9
10
  stopStreaming: () => void;
11
+ /**
12
+ * The application language translator.
13
+ */
14
+ translator: TranslationBundle;
10
15
  }
11
16
  /**
12
17
  * The stop button component.
@@ -15,4 +20,4 @@ export declare function StopButton(props: IStopButtonProps): JSX.Element;
15
20
  /**
16
21
  * Factory returning the stop button toolbar item.
17
22
  */
18
- export declare function stopItem(): InputToolbarRegistry.IToolbarItem;
23
+ export declare function stopItem(translator: TranslationBundle): InputToolbarRegistry.IToolbarItem;
@@ -1,28 +1,32 @@
1
- import { TooltippedButton } from '@jupyter/chat';
1
+ import { TooltippedIconButton } from '@jupyter/chat';
2
2
  import StopIcon from '@mui/icons-material/Stop';
3
3
  import React from 'react';
4
4
  /**
5
5
  * The stop button component.
6
6
  */
7
7
  export function StopButton(props) {
8
- const tooltip = 'Stop streaming';
9
- return (React.createElement(TooltippedButton, { onClick: props.stopStreaming, tooltip: tooltip, buttonProps: {
10
- size: 'small',
11
- variant: 'contained',
12
- color: 'error',
8
+ const { translator: trans } = props;
9
+ const tooltip = trans.__('Stop streaming');
10
+ return (React.createElement(TooltippedIconButton, { onClick: props.stopStreaming, tooltip: tooltip, buttonProps: {
13
11
  title: tooltip
12
+ }, sx: {
13
+ backgroundColor: 'var(--mui-palette-error-main, #d32f2f);'
14
14
  } },
15
15
  React.createElement(StopIcon, null)));
16
16
  }
17
17
  /**
18
18
  * Factory returning the stop button toolbar item.
19
19
  */
20
- export function stopItem() {
20
+ export function stopItem(translator) {
21
21
  return {
22
22
  element: (props) => {
23
23
  const { model } = props;
24
24
  const stopStreaming = () => model.chatContext.stopStreaming();
25
- const stopProps = { ...props, stopStreaming };
25
+ const stopProps = {
26
+ ...props,
27
+ stopStreaming,
28
+ translator
29
+ };
26
30
  return StopButton(stopProps);
27
31
  },
28
32
  position: 50,
@@ -1,4 +1,5 @@
1
1
  import { ReactWidget } from '@jupyterlab/ui-components';
2
+ import type { TranslationBundle } from '@jupyterlab/translation';
2
3
  import React from 'react';
3
4
  import { ISignal } from '@lumino/signaling';
4
5
  import { AISettingsModel } from '../models/settings-model';
@@ -19,6 +20,10 @@ export interface ITokenUsageDisplayProps {
19
20
  * Initial token usage.
20
21
  */
21
22
  initialTokenUsage?: ITokenUsage;
23
+ /**
24
+ * The application language translator.
25
+ */
26
+ translator: TranslationBundle;
22
27
  }
23
28
  /**
24
29
  * React component that displays token usage information.
@@ -5,7 +5,7 @@ import React from 'react';
5
5
  * Shows input/output token counts with up/down arrows.
6
6
  * Only renders when token usage display is enabled in settings.
7
7
  */
8
- export const TokenUsageDisplay = ({ tokenUsageChanged, settingsModel, initialTokenUsage }) => {
8
+ export const TokenUsageDisplay = ({ tokenUsageChanged, settingsModel, initialTokenUsage, translator: trans }) => {
9
9
  return (React.createElement(UseSignal, { signal: settingsModel.stateChanged, initialArgs: undefined }, () => {
10
10
  const config = settingsModel.config;
11
11
  if (!config.showTokenUsage) {
@@ -30,7 +30,7 @@ export const TokenUsageDisplay = ({ tokenUsageChanged, settingsModel, initialTok
30
30
  border: '1px solid var(--jp-border-color1)',
31
31
  borderRadius: '4px',
32
32
  whiteSpace: 'nowrap'
33
- }, title: `Token Usage - Sent: ${tokenUsage.inputTokens.toLocaleString()}, Received: ${tokenUsage.outputTokens.toLocaleString()}, Total: ${total.toLocaleString()}` },
33
+ }, title: trans.__('Token Usage - Sent: %1, Received: %2, Total: %3', tokenUsage.inputTokens.toLocaleString(), tokenUsage.outputTokens.toLocaleString(), total.toLocaleString()) },
34
34
  React.createElement("span", { style: {
35
35
  display: 'flex',
36
36
  alignItems: 'center',
@@ -1,4 +1,5 @@
1
1
  import { InputToolbarRegistry } from '@jupyter/chat';
2
+ import type { TranslationBundle } from '@jupyterlab/translation';
2
3
  import { IToolRegistry } from '../tokens';
3
4
  /**
4
5
  * Properties for the tool select component.
@@ -16,6 +17,10 @@ export interface IToolSelectProps extends InputToolbarRegistry.IToolbarItemProps
16
17
  * Function to handle tool selection changes.
17
18
  */
18
19
  onToolSelectionChange: (selectedToolNames: string[]) => void;
20
+ /**
21
+ * The application language translator.
22
+ */
23
+ translator: TranslationBundle;
19
24
  }
20
25
  /**
21
26
  * The tool select component for choosing AI tools.
@@ -24,4 +29,4 @@ export declare function ToolSelect(props: IToolSelectProps): JSX.Element;
24
29
  /**
25
30
  * Factory function returning the toolbar item for tool selection.
26
31
  */
27
- export declare function createToolSelectItem(toolRegistry: IToolRegistry, toolsEnabled?: boolean): InputToolbarRegistry.IToolbarItem;
32
+ export declare function createToolSelectItem(toolRegistry: IToolRegistry, toolsEnabled: boolean | undefined, translator: TranslationBundle): InputToolbarRegistry.IToolbarItem;
@@ -8,7 +8,7 @@ const SELECT_ITEM_CLASS = 'jp-AIToolSelect-item';
8
8
  * The tool select component for choosing AI tools.
9
9
  */
10
10
  export function ToolSelect(props) {
11
- const { toolRegistry, onToolSelectionChange, toolsEnabled } = props;
11
+ const { toolRegistry, onToolSelectionChange, toolsEnabled, translator: trans } = props;
12
12
  const [selectedToolNames, setSelectedToolNames] = useState([]);
13
13
  const [tools, setTools] = useState(toolRegistry?.namedTools || []);
14
14
  const [menuAnchorEl, setMenuAnchorEl] = useState(null);
@@ -63,11 +63,11 @@ export function ToolSelect(props) {
63
63
  return (React.createElement(React.Fragment, null,
64
64
  React.createElement(TooltippedButton, { onClick: e => {
65
65
  openMenu(e.currentTarget);
66
- }, tooltip: `Tools (${selectedToolNames.length}/${tools.length} selected)`, buttonProps: {
67
- size: 'small',
68
- variant: selectedToolNames.length > 0 ? 'contained' : 'outlined',
69
- color: 'primary',
70
- title: 'Select AI Tools',
66
+ }, tooltip: trans.__('Tools (%1/%2 selected)', selectedToolNames.length.toString(), tools.length.toString()), buttonProps: {
67
+ ...(selectedToolNames.length === 0 && {
68
+ variant: 'outlined'
69
+ }),
70
+ title: trans.__('Select AI Tools'),
71
71
  onKeyDown: e => {
72
72
  if (e.key !== 'Enter' && e.key !== ' ') {
73
73
  return;
@@ -79,7 +79,7 @@ export function ToolSelect(props) {
79
79
  }, sx: selectedToolNames.length === 0
80
80
  ? { backgroundColor: 'var(--jp-layout-color3)' }
81
81
  : {} },
82
- React.createElement(BuildIcon, null)),
82
+ React.createElement(BuildIcon, { sx: { fontSize: 'small' } })),
83
83
  React.createElement(Menu, { open: menuOpen, onClose: closeMenu, anchorEl: menuAnchorEl, anchorOrigin: {
84
84
  vertical: 'top',
85
85
  horizontal: 'right'
@@ -106,7 +106,7 @@ export function ToolSelect(props) {
106
106
  /**
107
107
  * Factory function returning the toolbar item for tool selection.
108
108
  */
109
- export function createToolSelectItem(toolRegistry, toolsEnabled = true) {
109
+ export function createToolSelectItem(toolRegistry, toolsEnabled = true, translator) {
110
110
  return {
111
111
  element: (props) => {
112
112
  const onToolSelectionChange = (tools) => {
@@ -121,7 +121,8 @@ export function createToolSelectItem(toolRegistry, toolsEnabled = true) {
121
121
  ...props,
122
122
  toolRegistry,
123
123
  onToolSelectionChange,
124
- toolsEnabled
124
+ toolsEnabled,
125
+ translator
125
126
  };
126
127
  return React.createElement(ToolSelect, { ...toolSelectProps });
127
128
  },
package/lib/index.d.ts CHANGED
@@ -6,3 +6,4 @@ import { AISettingsModel } from './models/settings-model';
6
6
  declare const _default: (JupyterFrontEndPlugin<IProviderRegistry> | JupyterFrontEndPlugin<void> | JupyterFrontEndPlugin<IChatModelRegistry> | JupyterFrontEndPlugin<AgentManagerFactory> | JupyterFrontEndPlugin<AISettingsModel> | JupyterFrontEndPlugin<IDiffManager> | JupyterFrontEndPlugin<IToolRegistry> | JupyterFrontEndPlugin<IInputToolbarRegistryFactory>)[];
7
7
  export default _default;
8
8
  export * from './tokens';
9
+ export * from './icons';