@theia/ai-core 1.58.3 → 1.59.0-next.62

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 (111) hide show
  1. package/lib/browser/ai-activation-service.d.ts +4 -4
  2. package/lib/browser/ai-activation-service.d.ts.map +1 -1
  3. package/lib/browser/ai-activation-service.js +10 -10
  4. package/lib/browser/ai-activation-service.js.map +1 -1
  5. package/lib/browser/ai-core-frontend-module.d.ts.map +1 -1
  6. package/lib/browser/ai-core-frontend-module.js +6 -32
  7. package/lib/browser/ai-core-frontend-module.js.map +1 -1
  8. package/lib/browser/ai-core-preferences.d.ts +3 -3
  9. package/lib/browser/ai-core-preferences.d.ts.map +1 -1
  10. package/lib/browser/ai-core-preferences.js +14 -13
  11. package/lib/browser/ai-core-preferences.js.map +1 -1
  12. package/lib/browser/ai-view-contribution.d.ts.map +1 -1
  13. package/lib/browser/ai-view-contribution.js +3 -3
  14. package/lib/browser/ai-view-contribution.js.map +1 -1
  15. package/lib/browser/file-variable-contribution.d.ts +17 -0
  16. package/lib/browser/file-variable-contribution.d.ts.map +1 -0
  17. package/lib/browser/file-variable-contribution.js +96 -0
  18. package/lib/browser/file-variable-contribution.js.map +1 -0
  19. package/lib/browser/frontend-variable-service.d.ts +21 -2
  20. package/lib/browser/frontend-variable-service.d.ts.map +1 -1
  21. package/lib/browser/frontend-variable-service.js +33 -5
  22. package/lib/browser/frontend-variable-service.js.map +1 -1
  23. package/lib/browser/index.d.ts +1 -0
  24. package/lib/browser/index.d.ts.map +1 -1
  25. package/lib/browser/index.js +1 -0
  26. package/lib/browser/index.js.map +1 -1
  27. package/lib/browser/prompttemplate-contribution.d.ts.map +1 -1
  28. package/lib/browser/prompttemplate-contribution.js +1 -1
  29. package/lib/browser/prompttemplate-contribution.js.map +1 -1
  30. package/lib/browser/theia-variable-contribution.d.ts +4 -0
  31. package/lib/browser/theia-variable-contribution.d.ts.map +1 -1
  32. package/lib/browser/theia-variable-contribution.js +15 -1
  33. package/lib/browser/theia-variable-contribution.js.map +1 -1
  34. package/lib/common/agents-variable-contribution.d.ts.map +1 -1
  35. package/lib/common/agents-variable-contribution.js +2 -1
  36. package/lib/common/agents-variable-contribution.js.map +1 -1
  37. package/lib/common/index.d.ts +1 -1
  38. package/lib/common/index.d.ts.map +1 -1
  39. package/lib/common/index.js +1 -1
  40. package/lib/common/index.js.map +1 -1
  41. package/lib/common/language-model-util.d.ts.map +1 -1
  42. package/lib/common/language-model-util.js +1 -18
  43. package/lib/common/language-model-util.js.map +1 -1
  44. package/lib/common/prompt-text.d.ts +7 -0
  45. package/lib/common/prompt-text.d.ts.map +1 -0
  46. package/lib/common/prompt-text.js +26 -0
  47. package/lib/common/prompt-text.js.map +1 -0
  48. package/lib/common/today-variable-contribution.d.ts.map +1 -1
  49. package/lib/common/today-variable-contribution.js +23 -3
  50. package/lib/common/today-variable-contribution.js.map +1 -1
  51. package/lib/common/variable-service.d.ts +64 -1
  52. package/lib/common/variable-service.d.ts.map +1 -1
  53. package/lib/common/variable-service.js +87 -2
  54. package/lib/common/variable-service.js.map +1 -1
  55. package/package.json +10 -10
  56. package/src/browser/ai-activation-service.ts +11 -11
  57. package/src/browser/ai-core-frontend-module.ts +11 -37
  58. package/src/browser/ai-core-preferences.ts +16 -13
  59. package/src/browser/ai-view-contribution.ts +4 -4
  60. package/src/browser/file-variable-contribution.ts +102 -0
  61. package/src/browser/frontend-variable-service.ts +48 -3
  62. package/src/browser/index.ts +1 -0
  63. package/src/browser/prompttemplate-contribution.ts +2 -2
  64. package/src/browser/theia-variable-contribution.ts +14 -1
  65. package/src/common/agents-variable-contribution.ts +2 -2
  66. package/src/common/index.ts +1 -1
  67. package/src/common/language-model-util.ts +1 -18
  68. package/src/common/prompt-text.ts +22 -0
  69. package/src/common/today-variable-contribution.ts +8 -4
  70. package/src/common/variable-service.ts +130 -2
  71. package/lib/browser/ai-configuration/agent-configuration-widget.d.ts +0 -28
  72. package/lib/browser/ai-configuration/agent-configuration-widget.d.ts.map +0 -1
  73. package/lib/browser/ai-configuration/agent-configuration-widget.js +0 -242
  74. package/lib/browser/ai-configuration/agent-configuration-widget.js.map +0 -1
  75. package/lib/browser/ai-configuration/ai-configuration-service.d.ts +0 -13
  76. package/lib/browser/ai-configuration/ai-configuration-service.d.ts.map +0 -1
  77. package/lib/browser/ai-configuration/ai-configuration-service.js +0 -44
  78. package/lib/browser/ai-configuration/ai-configuration-service.js.map +0 -1
  79. package/lib/browser/ai-configuration/ai-configuration-view-contribution.d.ts +0 -12
  80. package/lib/browser/ai-configuration/ai-configuration-view-contribution.d.ts.map +0 -1
  81. package/lib/browser/ai-configuration/ai-configuration-view-contribution.js +0 -41
  82. package/lib/browser/ai-configuration/ai-configuration-view-contribution.js.map +0 -1
  83. package/lib/browser/ai-configuration/ai-configuration-widget.d.ts +0 -20
  84. package/lib/browser/ai-configuration/ai-configuration-widget.d.ts.map +0 -1
  85. package/lib/browser/ai-configuration/ai-configuration-widget.js +0 -88
  86. package/lib/browser/ai-configuration/ai-configuration-widget.js.map +0 -1
  87. package/lib/browser/ai-configuration/language-model-renderer.d.ts +0 -13
  88. package/lib/browser/ai-configuration/language-model-renderer.d.ts.map +0 -1
  89. package/lib/browser/ai-configuration/language-model-renderer.js +0 -104
  90. package/lib/browser/ai-configuration/language-model-renderer.js.map +0 -1
  91. package/lib/browser/ai-configuration/template-settings-renderer.d.ts +0 -13
  92. package/lib/browser/ai-configuration/template-settings-renderer.d.ts.map +0 -1
  93. package/lib/browser/ai-configuration/template-settings-renderer.js +0 -71
  94. package/lib/browser/ai-configuration/template-settings-renderer.js.map +0 -1
  95. package/lib/browser/ai-configuration/variable-configuration-widget.d.ts +0 -20
  96. package/lib/browser/ai-configuration/variable-configuration-widget.d.ts.map +0 -1
  97. package/lib/browser/ai-configuration/variable-configuration-widget.js +0 -99
  98. package/lib/browser/ai-configuration/variable-configuration-widget.js.map +0 -1
  99. package/lib/common/tomorrow-variable-contribution.d.ts +0 -17
  100. package/lib/common/tomorrow-variable-contribution.d.ts.map +0 -1
  101. package/lib/common/tomorrow-variable-contribution.js +0 -48
  102. package/lib/common/tomorrow-variable-contribution.js.map +0 -1
  103. package/src/browser/ai-configuration/agent-configuration-widget.tsx +0 -324
  104. package/src/browser/ai-configuration/ai-configuration-service.ts +0 -43
  105. package/src/browser/ai-configuration/ai-configuration-view-contribution.ts +0 -54
  106. package/src/browser/ai-configuration/ai-configuration-widget.tsx +0 -80
  107. package/src/browser/ai-configuration/language-model-renderer.tsx +0 -113
  108. package/src/browser/ai-configuration/template-settings-renderer.tsx +0 -128
  109. package/src/browser/ai-configuration/variable-configuration-widget.tsx +0 -110
  110. package/src/browser/style/index.css +0 -127
  111. package/src/common/tomorrow-variable-contribution.ts +0 -66
@@ -1,324 +0,0 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2024 EclipseSource GmbH.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { codicon, ReactWidget } from '@theia/core/lib/browser';
18
- import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
19
- import * as React from '@theia/core/shared/react';
20
- import {
21
- Agent,
22
- AISettingsService,
23
- AIVariableService,
24
- LanguageModel,
25
- LanguageModelRegistry,
26
- matchVariablesRegEx,
27
- PROMPT_FUNCTION_REGEX,
28
- PromptCustomizationService,
29
- PromptService,
30
- } from '../../common';
31
- import { LanguageModelRenderer } from './language-model-renderer';
32
- import { TemplateRenderer } from './template-settings-renderer';
33
- import { AIConfigurationSelectionService } from './ai-configuration-service';
34
- import { AIVariableConfigurationWidget } from './variable-configuration-widget';
35
- import { AgentService } from '../../common/agent-service';
36
-
37
- interface ParsedPrompt {
38
- functions: string[];
39
- globalVariables: string[];
40
- agentSpecificVariables: string[];
41
- };
42
-
43
- @injectable()
44
- export class AIAgentConfigurationWidget extends ReactWidget {
45
-
46
- static readonly ID = 'ai-agent-configuration-container-widget';
47
- static readonly LABEL = 'Agents';
48
-
49
- @inject(AgentService)
50
- protected readonly agentService: AgentService;
51
-
52
- @inject(LanguageModelRegistry)
53
- protected readonly languageModelRegistry: LanguageModelRegistry;
54
-
55
- @inject(PromptCustomizationService)
56
- protected readonly promptCustomizationService: PromptCustomizationService;
57
-
58
- @inject(AISettingsService)
59
- protected readonly aiSettingsService: AISettingsService;
60
-
61
- @inject(AIConfigurationSelectionService)
62
- protected readonly aiConfigurationSelectionService: AIConfigurationSelectionService;
63
-
64
- @inject(AIVariableService)
65
- protected readonly variableService: AIVariableService;
66
-
67
- @inject(PromptService)
68
- protected promptService: PromptService;
69
-
70
- protected languageModels: LanguageModel[] | undefined;
71
-
72
- @postConstruct()
73
- protected init(): void {
74
- this.id = AIAgentConfigurationWidget.ID;
75
- this.title.label = AIAgentConfigurationWidget.LABEL;
76
- this.title.closable = false;
77
-
78
- this.languageModelRegistry.getLanguageModels().then(models => {
79
- this.languageModels = models ?? [];
80
- this.update();
81
- });
82
- this.toDispose.push(this.languageModelRegistry.onChange(({ models }) => {
83
- this.languageModels = models;
84
- this.update();
85
- }));
86
- this.toDispose.push(this.promptCustomizationService.onDidChangePrompt(() => this.update()));
87
-
88
- this.aiSettingsService.onDidChange(() => this.update());
89
- this.aiConfigurationSelectionService.onDidAgentChange(() => this.update());
90
- this.agentService.onDidChangeAgents(() => this.update());
91
- this.update();
92
- }
93
-
94
- protected render(): React.ReactNode {
95
- return <div className='ai-agent-configuration-main'>
96
- <div className='configuration-agents-list preferences-tree-widget theia-TreeContainer' style={{ width: '25%' }}>
97
- <ul>
98
- {this.agentService.getAllAgents().map(agent =>
99
- <li key={agent.id} className='theia-TreeNode theia-CompositeTreeNode theia-ExpandableTreeNode' onClick={() => this.setActiveAgent(agent)}>
100
- {this.renderAgentName(agent)}
101
- </li>
102
- )}
103
- </ul>
104
- <div className='configuration-agents-add'>
105
- <button style={{ marginLeft: 0 }} className='theia-button main' onClick={() => this.addCustomAgent()}>Add Custom Agent</button>
106
- </div>
107
- </div>
108
- <div className='configuration-agent-panel preferences-editor-widget'>
109
- {this.renderAgentDetails()}
110
- </div>
111
- </div>;
112
- }
113
-
114
- private renderAgentName(agent: Agent): React.ReactNode {
115
- const tagsSuffix = agent.tags?.length ? <span>{agent.tags.map(tag => <span key={tag} className='agent-tag'>{tag}</span>)}</span> : '';
116
- return <span>{agent.name} {tagsSuffix}</span>;
117
- }
118
-
119
- private renderAgentDetails(): React.ReactNode {
120
- const agent = this.aiConfigurationSelectionService.getActiveAgent();
121
- if (!agent) {
122
- return <div>Please select an Agent first!</div>;
123
- }
124
-
125
- const enabled = this.agentService.isEnabled(agent.id);
126
-
127
- const parsedPromptParts = this.parsePromptTemplatesForVariableAndFunction(agent);
128
- const globalVariables = Array.from(new Set([...parsedPromptParts.globalVariables, ...agent.variables]));
129
- const functions = Array.from(new Set([...parsedPromptParts.functions, ...agent.functions]));
130
-
131
- return <div key={agent.id} style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start' }}>
132
- <div className='settings-section-title settings-section-category-title' style={{ paddingLeft: 0, paddingBottom: 10 }}>{this.renderAgentName(agent)}</div>
133
- <div style={{ paddingBottom: 10 }}>{agent.description}</div>
134
- <div style={{ paddingBottom: 10 }}>
135
- <label>
136
- <input type="checkbox" checked={enabled} onChange={this.toggleAgentEnabled} />
137
- Enable Agent
138
- </label>
139
- </div>
140
- <div className="settings-section-subcategory-title ai-settings-section-subcategory-title">
141
- Prompt Templates
142
- </div>
143
- <div className="ai-templates">
144
- {(() => {
145
- const defaultTemplates = agent.promptTemplates?.filter(template => !template.variantOf) || [];
146
- return defaultTemplates.length > 0 ? (
147
- defaultTemplates.map(template => (
148
- <div key={agent.id + '.' + template.id}>
149
- <TemplateRenderer
150
- key={agent.id + '.' + template.id}
151
- agentId={agent.id}
152
- template={template}
153
- promptService={this.promptService}
154
- aiSettingsService={this.aiSettingsService}
155
- promptCustomizationService={this.promptCustomizationService}
156
- />
157
- </div>
158
- ))
159
- ) : (
160
- <div>No default template available</div>
161
- );
162
- })()}
163
- </div>
164
-
165
- <div className='ai-lm-requirements'>
166
- <LanguageModelRenderer
167
- agent={agent}
168
- languageModels={this.languageModels}
169
- aiSettingsService={this.aiSettingsService}
170
- languageModelRegistry={this.languageModelRegistry} />
171
- </div>
172
- <div>
173
- <span>Used Global Variables:</span>
174
- <ul className='variable-references'>
175
- <AgentGlobalVariables variables={globalVariables} showVariableConfigurationTab={this.showVariableConfigurationTab.bind(this)} />
176
- </ul>
177
- </div>
178
- <div>
179
- <span>Used agent-specific Variables:</span>
180
- <ul className='variable-references'>
181
- <AgentSpecificVariables
182
- promptVariables={parsedPromptParts.agentSpecificVariables}
183
- agent={agent}
184
- />
185
- </ul>
186
- </div>
187
- <div>
188
- <span>Used Functions:</span>
189
- <ul className='function-references'>
190
- <AgentFunctions functions={functions} />
191
- </ul>
192
- </div>
193
- </div>;
194
- }
195
-
196
- private parsePromptTemplatesForVariableAndFunction(agent: Agent): ParsedPrompt {
197
- const promptTemplates = agent.promptTemplates;
198
- const result: ParsedPrompt = { functions: [], globalVariables: [], agentSpecificVariables: [] };
199
- promptTemplates.forEach(template => {
200
- const storedPrompt = this.promptService.getUnresolvedPrompt(template.id);
201
- const prompt = storedPrompt?.template ?? template.template;
202
- const variableMatches = matchVariablesRegEx(prompt);
203
-
204
- variableMatches.forEach(match => {
205
- const variableId = match[1];
206
- // if the variable is part of the variable service and not part of the agent specific variables then it is a global variable
207
- if (this.variableService.hasVariable(variableId) &&
208
- agent.agentSpecificVariables.find(v => v.name === variableId) === undefined) {
209
- result.globalVariables.push(variableId);
210
- } else {
211
- result.agentSpecificVariables.push(variableId);
212
- }
213
- });
214
-
215
- const functionMatches = [...prompt.matchAll(PROMPT_FUNCTION_REGEX)];
216
- functionMatches.forEach(match => {
217
- const functionId = match[1];
218
- result.functions.push(functionId);
219
- });
220
-
221
- });
222
- return result;
223
- }
224
-
225
- protected showVariableConfigurationTab(): void {
226
- this.aiConfigurationSelectionService.selectConfigurationTab(AIVariableConfigurationWidget.ID);
227
- }
228
-
229
- protected addCustomAgent(): void {
230
- this.promptCustomizationService.openCustomAgentYaml();
231
- }
232
-
233
- protected setActiveAgent(agent: Agent): void {
234
- this.aiConfigurationSelectionService.setActiveAgent(agent);
235
- this.update();
236
- }
237
-
238
- private toggleAgentEnabled = () => {
239
- const agent = this.aiConfigurationSelectionService.getActiveAgent();
240
- if (!agent) {
241
- return false;
242
- }
243
- const enabled = this.agentService.isEnabled(agent.id);
244
- if (enabled) {
245
- this.agentService.disableAgent(agent.id);
246
- } else {
247
- this.agentService.enableAgent(agent.id);
248
- }
249
- this.update();
250
- };
251
-
252
- }
253
- interface AgentGlobalVariablesProps {
254
- variables: string[];
255
- showVariableConfigurationTab: () => void;
256
- }
257
- const AgentGlobalVariables = ({ variables: globalVariables, showVariableConfigurationTab }: AgentGlobalVariablesProps) => {
258
- if (globalVariables.length === 0) {
259
- return <>None</>;
260
- }
261
- return <>
262
- {globalVariables.map(variableId => <li key={variableId} className='theia-TreeNode theia-CompositeTreeNode theia-ExpandableTreeNode theia-mod-selected'>
263
- <div key={variableId} onClick={() => { showVariableConfigurationTab(); }} className='variable-reference'>
264
- <span>{variableId}</span>
265
- <i className={codicon('chevron-right')}></i>
266
- </div></li>)}
267
-
268
- </>;
269
- };
270
-
271
- interface AgentFunctionsProps {
272
- functions: string[];
273
- }
274
- const AgentFunctions = ({ functions }: AgentFunctionsProps) => {
275
- if (functions.length === 0) {
276
- return <>None</>;
277
- }
278
- return <>
279
- {functions.map(functionId => <li key={functionId} className='variable-reference'>
280
- <span>{functionId}</span>
281
- </li>)}
282
- </>;
283
- };
284
-
285
- interface AgentSpecificVariablesProps {
286
- promptVariables: string[];
287
- agent: Agent;
288
- }
289
- const AgentSpecificVariables = ({ promptVariables, agent }: AgentSpecificVariablesProps) => {
290
- const agentDefinedVariablesName = agent.agentSpecificVariables.map(v => v.name);
291
- const variables = Array.from(new Set([...promptVariables, ...agentDefinedVariablesName]));
292
- if (variables.length === 0) {
293
- return <>None</>;
294
- }
295
- return <>
296
- {variables.map(variableId =>
297
- <AgentSpecifcVariable
298
- key={variableId}
299
- variableId={variableId}
300
- agent={agent}
301
- promptVariables={promptVariables} />
302
-
303
- )}
304
- </>;
305
- };
306
- interface AgentSpecifcVariableProps {
307
- variableId: string;
308
- agent: Agent;
309
- promptVariables: string[];
310
- }
311
- const AgentSpecifcVariable = ({ variableId, agent, promptVariables }: AgentSpecifcVariableProps) => {
312
- const agentDefinedVariable = agent.agentSpecificVariables.find(v => v.name === variableId);
313
- const undeclared = agentDefinedVariable === undefined;
314
- const notUsed = !promptVariables.includes(variableId) && agentDefinedVariable?.usedInPrompt === true;
315
- return <li key={variableId}>
316
- <div><span>Name:</span> <span>{variableId}</span></div>
317
- {undeclared ? <div><span>Undeclared</span></div> :
318
- (<>
319
- <div><span>Description:</span> <span>{agentDefinedVariable.description}</span></div>
320
- {notUsed && <div>Not used in prompt</div>}
321
- </>)}
322
- <hr />
323
- </li>;
324
- };
@@ -1,43 +0,0 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2024 EclipseSource GmbH.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { Emitter } from '@theia/core';
18
- import { injectable } from '@theia/core/shared/inversify';
19
- import { Agent } from '../../common';
20
-
21
- @injectable()
22
- export class AIConfigurationSelectionService {
23
- protected activeAgent?: Agent;
24
-
25
- protected readonly onDidSelectConfigurationEmitter = new Emitter<string>();
26
- onDidSelectConfiguration = this.onDidSelectConfigurationEmitter.event;
27
-
28
- protected readonly onDidAgentChangeEmitter = new Emitter<Agent | undefined>();
29
- onDidAgentChange = this.onDidSelectConfigurationEmitter.event;
30
-
31
- public getActiveAgent(): Agent | undefined {
32
- return this.activeAgent;
33
- }
34
-
35
- public setActiveAgent(agent?: Agent): void {
36
- this.activeAgent = agent;
37
- this.onDidAgentChangeEmitter.fire(agent);
38
- }
39
-
40
- public selectConfigurationTab(widgetId: string): void {
41
- this.onDidSelectConfigurationEmitter.fire(widgetId);
42
- }
43
- }
@@ -1,54 +0,0 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2024 EclipseSource GmbH.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
- import { FrontendApplication } from '@theia/core/lib/browser';
17
- import { injectable } from '@theia/core/shared/inversify';
18
- import { AIViewContribution } from '../ai-view-contribution';
19
- import { AIConfigurationContainerWidget } from './ai-configuration-widget';
20
- import { Command, CommandRegistry } from '@theia/core';
21
-
22
- export const AI_CONFIGURATION_TOGGLE_COMMAND_ID = 'aiConfiguration:toggle';
23
- export const OPEN_AI_CONFIG_VIEW = Command.toLocalizedCommand({
24
- id: 'aiConfiguration:open',
25
- label: 'Open AI Configuration view',
26
- });
27
-
28
- @injectable()
29
- export class AIAgentConfigurationViewContribution extends AIViewContribution<AIConfigurationContainerWidget> {
30
-
31
- constructor() {
32
- super({
33
- widgetId: AIConfigurationContainerWidget.ID,
34
- widgetName: AIConfigurationContainerWidget.LABEL,
35
- defaultWidgetOptions: {
36
- area: 'main',
37
- rank: 100
38
- },
39
- toggleCommandId: AI_CONFIGURATION_TOGGLE_COMMAND_ID
40
- });
41
- }
42
-
43
- async initializeLayout(_app: FrontendApplication): Promise<void> {
44
- await this.openView();
45
- }
46
-
47
- override registerCommands(commands: CommandRegistry): void {
48
- super.registerCommands(commands);
49
- commands.registerCommand(OPEN_AI_CONFIG_VIEW, {
50
- execute: () => this.openView({ activate: true }),
51
- });
52
- }
53
- }
54
-
@@ -1,80 +0,0 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2024 EclipseSource GmbH.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { BaseWidget, BoxLayout, codicon, DockPanel, WidgetManager } from '@theia/core/lib/browser';
18
- import { TheiaDockPanel } from '@theia/core/lib/browser/shell/theia-dock-panel';
19
- import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
20
- import '../../../src/browser/style/index.css';
21
- import { AIAgentConfigurationWidget } from './agent-configuration-widget';
22
- import { AIVariableConfigurationWidget } from './variable-configuration-widget';
23
- import { AIConfigurationSelectionService } from './ai-configuration-service';
24
-
25
- @injectable()
26
- export class AIConfigurationContainerWidget extends BaseWidget {
27
-
28
- static readonly ID = 'ai-configuration';
29
- static readonly LABEL = '✨ AI Configuration [Experimental]';
30
- protected dockpanel: DockPanel;
31
-
32
- @inject(TheiaDockPanel.Factory)
33
- protected readonly dockPanelFactory: TheiaDockPanel.Factory;
34
- @inject(WidgetManager)
35
- protected readonly widgetManager: WidgetManager;
36
- @inject(AIConfigurationSelectionService)
37
- protected readonly aiConfigurationSelectionService: AIConfigurationSelectionService;
38
-
39
- protected agentsWidget: AIAgentConfigurationWidget;
40
- protected variablesWidget: AIVariableConfigurationWidget;
41
-
42
- @postConstruct()
43
- protected init(): void {
44
- this.id = AIConfigurationContainerWidget.ID;
45
- this.title.label = AIConfigurationContainerWidget.LABEL;
46
- this.title.closable = true;
47
- this.addClass('theia-settings-container');
48
- this.title.iconClass = codicon('hubot');
49
- this.initUI();
50
- this.initListeners();
51
- }
52
-
53
- protected async initUI(): Promise<void> {
54
- const layout = (this.layout = new BoxLayout({ direction: 'top-to-bottom', spacing: 0 }));
55
- this.dockpanel = this.dockPanelFactory({
56
- mode: 'multiple-document',
57
- spacing: 0
58
- });
59
- BoxLayout.setStretch(this.dockpanel, 1);
60
- layout.addWidget(this.dockpanel);
61
- this.dockpanel.addClass('ai-configuration-widget');
62
-
63
- this.agentsWidget = await this.widgetManager.getOrCreateWidget(AIAgentConfigurationWidget.ID);
64
- this.variablesWidget = await this.widgetManager.getOrCreateWidget(AIVariableConfigurationWidget.ID);
65
- this.dockpanel.addWidget(this.agentsWidget);
66
- this.dockpanel.addWidget(this.variablesWidget);
67
-
68
- this.update();
69
- }
70
-
71
- protected initListeners(): void {
72
- this.aiConfigurationSelectionService.onDidSelectConfiguration(widgetId => {
73
- if (widgetId === AIAgentConfigurationWidget.ID) {
74
- this.dockpanel.activateWidget(this.agentsWidget);
75
- } else if (widgetId === AIVariableConfigurationWidget.ID) {
76
- this.dockpanel.activateWidget(this.variablesWidget);
77
- }
78
- });
79
- }
80
- }
@@ -1,113 +0,0 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2024 EclipseSource GmbH.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
- import * as React from '@theia/core/shared/react';
17
- import { Agent, LanguageModelRequirement } from '../../common';
18
- import { LanguageModel, LanguageModelRegistry } from '../../common/language-model';
19
- import { AISettingsService } from '../../common/settings-service';
20
- import { Mutable } from '@theia/core';
21
-
22
- export interface LanguageModelSettingsProps {
23
- agent: Agent;
24
- languageModels?: LanguageModel[];
25
- aiSettingsService: AISettingsService;
26
- languageModelRegistry: LanguageModelRegistry;
27
- }
28
-
29
- export const LanguageModelRenderer: React.FC<LanguageModelSettingsProps> = (
30
- { agent, languageModels, aiSettingsService, languageModelRegistry }) => {
31
-
32
- const findLanguageModelRequirement = async (purpose: string): Promise<LanguageModelRequirement | undefined> => {
33
- const requirementSetting = await aiSettingsService.getAgentSettings(agent.id);
34
- return requirementSetting?.languageModelRequirements?.find(e => e.purpose === purpose);
35
- };
36
-
37
- const [lmRequirementMap, setLmRequirementMap] = React.useState<Record<string, LanguageModelRequirement>>({});
38
-
39
- React.useEffect(() => {
40
- const computeLmRequirementMap = async () => {
41
- const map = await agent.languageModelRequirements.reduce(async (accPromise, curr) => {
42
- const acc = await accPromise;
43
- // take the agents requirements and override them with the user settings if present
44
- const lmRequirement = await findLanguageModelRequirement(curr.purpose) ?? curr;
45
- // if no llm is selected through the identifier, see what would be the default
46
- if (!lmRequirement.identifier) {
47
- const llm = await languageModelRegistry.selectLanguageModel({ agent: agent.id, ...lmRequirement });
48
- (lmRequirement as Mutable<LanguageModelRequirement>).identifier = llm?.id;
49
- }
50
- acc[curr.purpose] = lmRequirement;
51
- return acc;
52
- }, Promise.resolve({} as Record<string, LanguageModelRequirement>));
53
- setLmRequirementMap(map);
54
- };
55
- computeLmRequirementMap();
56
- }, []);
57
-
58
- const renderLanguageModelMetadata = (requirement: LanguageModelRequirement, index: number) => {
59
- const languageModel = languageModels?.find(model => model.id === requirement.identifier);
60
- if (!languageModel) {
61
- return <div></div>;
62
- }
63
-
64
- return <>
65
- <div>{requirement.purpose}</div>
66
- <div key={index}>
67
- {languageModel.id && <p><strong>Identifier: </strong> {languageModel.id}</p>}
68
- {languageModel.name && <p><strong>Name: </strong> {languageModel.name}</p>}
69
- {languageModel.vendor && <p><strong>Vendor: </strong> {languageModel.vendor}</p>}
70
- {languageModel.version && <p><strong>Version: </strong> {languageModel.version}</p>}
71
- {languageModel.family && <p><strong>Family: </strong> {languageModel.family}</p>}
72
- {languageModel.maxInputTokens && <p><strong>Min Input Tokens: </strong> {languageModel.maxInputTokens}</p>}
73
- {languageModel.maxOutputTokens && <p><strong>Max Output Tokens: </strong> {languageModel.maxOutputTokens}</p>}
74
- </div>
75
- </>;
76
-
77
- };
78
-
79
- const onSelectedModelChange = (purpose: string, event: React.ChangeEvent<HTMLSelectElement>): void => {
80
- const newLmRequirementMap = { ...lmRequirementMap, [purpose]: { purpose, identifier: event.target.value } };
81
- aiSettingsService.updateAgentSettings(agent.id, { languageModelRequirements: Object.values(newLmRequirementMap) });
82
- setLmRequirementMap(newLmRequirementMap);
83
- };
84
-
85
- return <div className='language-model-container'>
86
- {Object.values(lmRequirementMap).map((requirements, index) => (
87
- <React.Fragment key={index}>
88
- <div><strong>Purpose:</strong></div>
89
- <div>
90
- {/* language model metadata */}
91
- {renderLanguageModelMetadata(requirements, index)}
92
- {/* language model selector */}
93
- <>
94
- <label className="theia-header no-select" htmlFor={`model-select-${agent.id}`}>Language Model:</label>
95
- <select
96
- className="theia-select"
97
- id={`model-select-${agent.id}`}
98
- value={requirements.identifier}
99
- onChange={event => onSelectedModelChange(requirements.purpose, event)}
100
- >
101
- <option value=""></option>
102
- {languageModels?.sort((a, b) => (a.name ?? a.id).localeCompare(b.name ?? b.id)).map(model => (
103
- <option key={model.id} value={model.id}>{model.name ?? model.id}</option>
104
- ))}
105
- </select>
106
- </>
107
- <hr />
108
- </div>
109
- </React.Fragment>
110
- ))}
111
-
112
- </div>;
113
- };