@jupyterlite/ai 0.15.0 → 0.17.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 (45) hide show
  1. package/lib/agent.d.ts +12 -2
  2. package/lib/agent.js +112 -17
  3. package/lib/chat-commands/clear.js +1 -1
  4. package/lib/chat-model-handler.js +4 -1
  5. package/lib/chat-model.d.ts +25 -24
  6. package/lib/chat-model.js +262 -132
  7. package/lib/components/clear-button.d.ts +1 -1
  8. package/lib/components/clear-button.js +1 -1
  9. package/lib/components/index.d.ts +1 -1
  10. package/lib/components/index.js +1 -1
  11. package/lib/components/{token-usage-display.d.ts → usage-display.d.ts} +11 -11
  12. package/lib/components/usage-display.js +109 -0
  13. package/lib/index.js +205 -20
  14. package/lib/models/settings-model.js +1 -0
  15. package/lib/providers/built-in-providers.js +5 -0
  16. package/lib/providers/generated-context-windows.d.ts +8 -0
  17. package/lib/providers/generated-context-windows.js +96 -0
  18. package/lib/providers/model-info.d.ts +3 -0
  19. package/lib/providers/model-info.js +58 -0
  20. package/lib/tokens.d.ts +34 -3
  21. package/lib/tokens.js +8 -7
  22. package/lib/widgets/ai-settings.js +9 -0
  23. package/lib/widgets/main-area-chat.d.ts +1 -0
  24. package/lib/widgets/main-area-chat.js +10 -4
  25. package/lib/widgets/provider-config-dialog.js +18 -5
  26. package/package.json +3 -2
  27. package/schema/settings-model.json +11 -0
  28. package/src/agent.ts +151 -21
  29. package/src/chat-commands/clear.ts +1 -1
  30. package/src/chat-model-handler.ts +6 -1
  31. package/src/chat-model.ts +350 -175
  32. package/src/components/clear-button.tsx +3 -3
  33. package/src/components/index.ts +1 -1
  34. package/src/components/usage-display.tsx +208 -0
  35. package/src/index.ts +250 -26
  36. package/src/models/settings-model.ts +1 -0
  37. package/src/providers/built-in-providers.ts +5 -0
  38. package/src/providers/generated-context-windows.ts +102 -0
  39. package/src/providers/model-info.ts +88 -0
  40. package/src/tokens.ts +46 -10
  41. package/src/widgets/ai-settings.tsx +42 -0
  42. package/src/widgets/main-area-chat.ts +12 -4
  43. package/src/widgets/provider-config-dialog.tsx +45 -5
  44. package/lib/components/token-usage-display.js +0 -72
  45. package/src/components/token-usage-display.tsx +0 -137
@@ -1,137 +0,0 @@
1
- import { ReactWidget, UseSignal } from '@jupyterlab/ui-components';
2
- import type { TranslationBundle } from '@jupyterlab/translation';
3
- import React from 'react';
4
- import { ISignal } from '@lumino/signaling';
5
- import type { IAISettingsModel, ITokenUsage } from '../tokens';
6
-
7
- /**
8
- * Props for the TokenUsageDisplay component.
9
- */
10
- export interface ITokenUsageDisplayProps {
11
- /**
12
- * The token usage changed signal
13
- */
14
- tokenUsageChanged: ISignal<any, ITokenUsage>;
15
-
16
- /**
17
- * The settings model instance for configuration options
18
- */
19
- settingsModel: IAISettingsModel;
20
-
21
- /**
22
- * Initial token usage.
23
- */
24
- initialTokenUsage?: ITokenUsage;
25
-
26
- /**
27
- * The application language translator.
28
- */
29
- translator: TranslationBundle;
30
- }
31
-
32
- /**
33
- * React component that displays token usage information.
34
- * Shows input/output token counts with up/down arrows.
35
- * Only renders when token usage display is enabled in settings.
36
- */
37
- export const TokenUsageDisplay: React.FC<ITokenUsageDisplayProps> = ({
38
- tokenUsageChanged,
39
- settingsModel,
40
- initialTokenUsage,
41
- translator: trans
42
- }) => {
43
- return (
44
- <UseSignal signal={settingsModel.stateChanged} initialArgs={undefined}>
45
- {() => {
46
- const config = settingsModel.config;
47
- if (!config.showTokenUsage) {
48
- return null;
49
- }
50
-
51
- return (
52
- <UseSignal signal={tokenUsageChanged} initialArgs={initialTokenUsage}>
53
- {(_, tokenUsage: ITokenUsage | null | undefined) => {
54
- if (!tokenUsage) {
55
- return null;
56
- }
57
-
58
- const total = tokenUsage.inputTokens + tokenUsage.outputTokens;
59
- if (total === 0) {
60
- return null;
61
- }
62
-
63
- return (
64
- <div
65
- style={{
66
- display: 'flex',
67
- alignItems: 'center',
68
- gap: '6px',
69
- fontSize: '12px',
70
- color: 'var(--jp-ui-font-color2)',
71
- padding: '4px 8px',
72
- backgroundColor: 'var(--jp-layout-color1)',
73
- border: '1px solid var(--jp-border-color1)',
74
- borderRadius: '4px',
75
- whiteSpace: 'nowrap'
76
- }}
77
- title={trans.__(
78
- 'Token Usage - Sent: %1, Received: %2, Total: %3',
79
- tokenUsage.inputTokens.toLocaleString(),
80
- tokenUsage.outputTokens.toLocaleString(),
81
- total.toLocaleString()
82
- )}
83
- >
84
- <span
85
- style={{
86
- display: 'flex',
87
- alignItems: 'center',
88
- gap: '2px'
89
- }}
90
- >
91
- <span>↑</span>
92
- <span>{tokenUsage.inputTokens.toLocaleString()}</span>
93
- </span>
94
- <span
95
- style={{
96
- display: 'flex',
97
- alignItems: 'center',
98
- gap: '2px'
99
- }}
100
- >
101
- <span>↓</span>
102
- <span>{tokenUsage.outputTokens.toLocaleString()}</span>
103
- </span>
104
- </div>
105
- );
106
- }}
107
- </UseSignal>
108
- );
109
- }}
110
- </UseSignal>
111
- );
112
- };
113
-
114
- /**
115
- * JupyterLab widget wrapper for the TokenUsageDisplay component.
116
- * Extends ReactWidget to integrate with the JupyterLab widget system.
117
- */
118
- export class TokenUsageWidget extends ReactWidget {
119
- /**
120
- * Creates a new TokenUsageWidget instance.
121
- * @param options - Configuration options containing required models
122
- */
123
- constructor(options: ITokenUsageDisplayProps) {
124
- super();
125
- this._options = options;
126
- }
127
-
128
- /**
129
- * Renders the React component within the widget.
130
- * @returns The TokenUsageDisplay React element
131
- */
132
- protected render(): React.ReactElement {
133
- return <TokenUsageDisplay {...this._options} />;
134
- }
135
-
136
- private _options: ITokenUsageDisplayProps;
137
- }