@theia/ai-core 1.58.3 → 1.59.0-next.72
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/lib/browser/ai-activation-service.d.ts +4 -4
- package/lib/browser/ai-activation-service.d.ts.map +1 -1
- package/lib/browser/ai-activation-service.js +10 -10
- package/lib/browser/ai-activation-service.js.map +1 -1
- package/lib/browser/ai-core-frontend-module.d.ts.map +1 -1
- package/lib/browser/ai-core-frontend-module.js +6 -32
- package/lib/browser/ai-core-frontend-module.js.map +1 -1
- package/lib/browser/ai-core-preferences.d.ts +3 -3
- package/lib/browser/ai-core-preferences.d.ts.map +1 -1
- package/lib/browser/ai-core-preferences.js +14 -13
- package/lib/browser/ai-core-preferences.js.map +1 -1
- package/lib/browser/ai-view-contribution.d.ts.map +1 -1
- package/lib/browser/ai-view-contribution.js +3 -3
- package/lib/browser/ai-view-contribution.js.map +1 -1
- package/lib/browser/file-variable-contribution.d.ts +17 -0
- package/lib/browser/file-variable-contribution.d.ts.map +1 -0
- package/lib/browser/file-variable-contribution.js +96 -0
- package/lib/browser/file-variable-contribution.js.map +1 -0
- package/lib/browser/frontend-variable-service.d.ts +21 -2
- package/lib/browser/frontend-variable-service.d.ts.map +1 -1
- package/lib/browser/frontend-variable-service.js +33 -5
- package/lib/browser/frontend-variable-service.js.map +1 -1
- package/lib/browser/index.d.ts +1 -0
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +1 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/prompttemplate-contribution.d.ts.map +1 -1
- package/lib/browser/prompttemplate-contribution.js +1 -1
- package/lib/browser/prompttemplate-contribution.js.map +1 -1
- package/lib/browser/theia-variable-contribution.d.ts +4 -0
- package/lib/browser/theia-variable-contribution.d.ts.map +1 -1
- package/lib/browser/theia-variable-contribution.js +15 -1
- package/lib/browser/theia-variable-contribution.js.map +1 -1
- package/lib/common/agents-variable-contribution.d.ts.map +1 -1
- package/lib/common/agents-variable-contribution.js +2 -1
- package/lib/common/agents-variable-contribution.js.map +1 -1
- package/lib/common/index.d.ts +1 -1
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +1 -1
- package/lib/common/index.js.map +1 -1
- package/lib/common/language-model-util.d.ts.map +1 -1
- package/lib/common/language-model-util.js +1 -18
- package/lib/common/language-model-util.js.map +1 -1
- package/lib/common/prompt-service.d.ts +3 -3
- package/lib/common/prompt-service.d.ts.map +1 -1
- package/lib/common/prompt-service.js +2 -2
- package/lib/common/prompt-service.js.map +1 -1
- package/lib/common/prompt-text.d.ts +7 -0
- package/lib/common/prompt-text.d.ts.map +1 -0
- package/lib/common/prompt-text.js +26 -0
- package/lib/common/prompt-text.js.map +1 -0
- package/lib/common/today-variable-contribution.d.ts.map +1 -1
- package/lib/common/today-variable-contribution.js +23 -3
- package/lib/common/today-variable-contribution.js.map +1 -1
- package/lib/common/variable-service.d.ts +64 -1
- package/lib/common/variable-service.d.ts.map +1 -1
- package/lib/common/variable-service.js +87 -2
- package/lib/common/variable-service.js.map +1 -1
- package/package.json +10 -10
- package/src/browser/ai-activation-service.ts +11 -11
- package/src/browser/ai-core-frontend-module.ts +11 -37
- package/src/browser/ai-core-preferences.ts +16 -13
- package/src/browser/ai-view-contribution.ts +4 -4
- package/src/browser/file-variable-contribution.ts +102 -0
- package/src/browser/frontend-variable-service.ts +48 -3
- package/src/browser/index.ts +1 -0
- package/src/browser/prompttemplate-contribution.ts +2 -2
- package/src/browser/theia-variable-contribution.ts +14 -1
- package/src/common/agents-variable-contribution.ts +2 -2
- package/src/common/index.ts +1 -1
- package/src/common/language-model-util.ts +1 -18
- package/src/common/prompt-service.ts +4 -4
- package/src/common/prompt-text.ts +22 -0
- package/src/common/today-variable-contribution.ts +8 -4
- package/src/common/variable-service.ts +130 -2
- package/lib/browser/ai-configuration/agent-configuration-widget.d.ts +0 -28
- package/lib/browser/ai-configuration/agent-configuration-widget.d.ts.map +0 -1
- package/lib/browser/ai-configuration/agent-configuration-widget.js +0 -242
- package/lib/browser/ai-configuration/agent-configuration-widget.js.map +0 -1
- package/lib/browser/ai-configuration/ai-configuration-service.d.ts +0 -13
- package/lib/browser/ai-configuration/ai-configuration-service.d.ts.map +0 -1
- package/lib/browser/ai-configuration/ai-configuration-service.js +0 -44
- package/lib/browser/ai-configuration/ai-configuration-service.js.map +0 -1
- package/lib/browser/ai-configuration/ai-configuration-view-contribution.d.ts +0 -12
- package/lib/browser/ai-configuration/ai-configuration-view-contribution.d.ts.map +0 -1
- package/lib/browser/ai-configuration/ai-configuration-view-contribution.js +0 -41
- package/lib/browser/ai-configuration/ai-configuration-view-contribution.js.map +0 -1
- package/lib/browser/ai-configuration/ai-configuration-widget.d.ts +0 -20
- package/lib/browser/ai-configuration/ai-configuration-widget.d.ts.map +0 -1
- package/lib/browser/ai-configuration/ai-configuration-widget.js +0 -88
- package/lib/browser/ai-configuration/ai-configuration-widget.js.map +0 -1
- package/lib/browser/ai-configuration/language-model-renderer.d.ts +0 -13
- package/lib/browser/ai-configuration/language-model-renderer.d.ts.map +0 -1
- package/lib/browser/ai-configuration/language-model-renderer.js +0 -104
- package/lib/browser/ai-configuration/language-model-renderer.js.map +0 -1
- package/lib/browser/ai-configuration/template-settings-renderer.d.ts +0 -13
- package/lib/browser/ai-configuration/template-settings-renderer.d.ts.map +0 -1
- package/lib/browser/ai-configuration/template-settings-renderer.js +0 -71
- package/lib/browser/ai-configuration/template-settings-renderer.js.map +0 -1
- package/lib/browser/ai-configuration/variable-configuration-widget.d.ts +0 -20
- package/lib/browser/ai-configuration/variable-configuration-widget.d.ts.map +0 -1
- package/lib/browser/ai-configuration/variable-configuration-widget.js +0 -99
- package/lib/browser/ai-configuration/variable-configuration-widget.js.map +0 -1
- package/lib/common/tomorrow-variable-contribution.d.ts +0 -17
- package/lib/common/tomorrow-variable-contribution.d.ts.map +0 -1
- package/lib/common/tomorrow-variable-contribution.js +0 -48
- package/lib/common/tomorrow-variable-contribution.js.map +0 -1
- package/src/browser/ai-configuration/agent-configuration-widget.tsx +0 -324
- package/src/browser/ai-configuration/ai-configuration-service.ts +0 -43
- package/src/browser/ai-configuration/ai-configuration-view-contribution.ts +0 -54
- package/src/browser/ai-configuration/ai-configuration-widget.tsx +0 -80
- package/src/browser/ai-configuration/language-model-renderer.tsx +0 -113
- package/src/browser/ai-configuration/template-settings-renderer.tsx +0 -128
- package/src/browser/ai-configuration/variable-configuration-widget.tsx +0 -110
- package/src/browser/style/index.css +0 -127
- package/src/common/tomorrow-variable-contribution.ts +0 -66
|
@@ -14,10 +14,14 @@
|
|
|
14
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
|
|
17
|
+
import { nls } from '@theia/core/lib/common/nls';
|
|
17
18
|
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
18
19
|
import { VariableRegistry, VariableResolverService } from '@theia/variable-resolver/lib/browser';
|
|
19
20
|
import { AIVariableContribution, AIVariableResolver, AIVariableService, AIVariableResolutionRequest, AIVariableContext, ResolvedAIVariable } from '../common';
|
|
20
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Integrates the Theia VariableRegistry with the Theia AI VariableService
|
|
24
|
+
*/
|
|
21
25
|
@injectable()
|
|
22
26
|
export class TheiaVariableContribution implements AIVariableContribution, AIVariableResolver {
|
|
23
27
|
@inject(VariableResolverService)
|
|
@@ -29,12 +33,21 @@ export class TheiaVariableContribution implements AIVariableContribution, AIVari
|
|
|
29
33
|
@inject(FrontendApplicationStateService)
|
|
30
34
|
protected readonly stateService: FrontendApplicationStateService;
|
|
31
35
|
|
|
36
|
+
protected variableRenameMap: Map<string, string> = new Map([
|
|
37
|
+
['file', 'currentFilePath'],
|
|
38
|
+
]);
|
|
39
|
+
|
|
32
40
|
registerVariables(service: AIVariableService): void {
|
|
33
41
|
this.stateService.reachedState('initialized_layout').then(() => {
|
|
34
42
|
// some variable contributions in Theia are done as part of the onStart, same as our AI variable contributions
|
|
35
43
|
// we therefore wait for all of them to be registered before we register we map them to our own
|
|
36
44
|
this.variableRegistry.getVariables().forEach(variable => {
|
|
37
|
-
|
|
45
|
+
const variableName = this.variableRenameMap.has(variable.name) ? this.variableRenameMap.get(variable.name)! : variable.name;
|
|
46
|
+
service.registerResolver({
|
|
47
|
+
id: `theia-${variable.name}`,
|
|
48
|
+
name: variableName,
|
|
49
|
+
description: variable.description ?? nls.localize('theia/ai/core/variable-contribution/builtInVariable', 'Theia Built-in Variable')
|
|
50
|
+
}, this);
|
|
38
51
|
});
|
|
39
52
|
});
|
|
40
53
|
}
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
17
17
|
import { AIVariable, AIVariableContext, AIVariableContribution, AIVariableResolutionRequest, AIVariableResolver, AIVariableService, ResolvedAIVariable } from './variable-service';
|
|
18
|
-
import { MaybePromise } from '@theia/core';
|
|
18
|
+
import { MaybePromise, nls } from '@theia/core';
|
|
19
19
|
import { AgentService } from './agent-service';
|
|
20
20
|
|
|
21
21
|
export const AGENTS_VARIABLE: AIVariable = {
|
|
22
22
|
id: 'agents',
|
|
23
23
|
name: 'agents',
|
|
24
|
-
description: 'Returns the list of agents available in the system'
|
|
24
|
+
description: nls.localize('theia/ai/core/agentsVariable/description', 'Returns the list of agents available in the system')
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
export interface ResolvedAgentsVariable extends ResolvedAIVariable {
|
package/src/common/index.ts
CHANGED
|
@@ -23,8 +23,8 @@ export * from './language-model-util';
|
|
|
23
23
|
export * from './language-model';
|
|
24
24
|
export * from './prompt-service';
|
|
25
25
|
export * from './prompt-service-util';
|
|
26
|
+
export * from './prompt-text';
|
|
26
27
|
export * from './protocol';
|
|
27
28
|
export * from './today-variable-contribution';
|
|
28
|
-
export * from './tomorrow-variable-contribution';
|
|
29
29
|
export * from './variable-service';
|
|
30
30
|
export * from './settings-service';
|
|
@@ -64,21 +64,4 @@ export const getJsonOfText = (text: string): unknown => {
|
|
|
64
64
|
throw new Error('Invalid response format');
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
export const toolRequestToPromptText = (toolRequest: ToolRequest): string => {
|
|
68
|
-
const parameters = toolRequest.parameters;
|
|
69
|
-
let paramsText = '';
|
|
70
|
-
// parameters are supposed to be as a JSON schema. Thus, derive the parameters from its properties definition
|
|
71
|
-
if (parameters) {
|
|
72
|
-
const properties = parameters.properties;
|
|
73
|
-
paramsText = Object.keys(properties)
|
|
74
|
-
.map(key => {
|
|
75
|
-
const param = properties[key];
|
|
76
|
-
return `${key}: ${param.type}`;
|
|
77
|
-
})
|
|
78
|
-
.join(', ');
|
|
79
|
-
}
|
|
80
|
-
const descriptionText = toolRequest.description
|
|
81
|
-
? `: ${toolRequest.description}`
|
|
82
|
-
: '';
|
|
83
|
-
return `You can call function: ${toolRequest.id}(${paramsText})${descriptionText}`;
|
|
84
|
-
};
|
|
67
|
+
export const toolRequestToPromptText = (toolRequest: ToolRequest): string => `${toolRequest.id}`;
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import { URI, Event } from '@theia/core';
|
|
18
18
|
import { inject, injectable, optional } from '@theia/core/shared/inversify';
|
|
19
|
-
import { AIVariableService } from './variable-service';
|
|
19
|
+
import { AIVariableContext, AIVariableService } from './variable-service';
|
|
20
20
|
import { ToolInvocationRegistry } from './tool-invocation-registry';
|
|
21
21
|
import { toolRequestToPromptText } from './language-model-util';
|
|
22
22
|
import { ToolRequest } from './language-model';
|
|
@@ -67,7 +67,7 @@ export interface PromptService {
|
|
|
67
67
|
* @param id the id of the prompt
|
|
68
68
|
* @param args the object with placeholders, mapping the placeholder key to the value
|
|
69
69
|
*/
|
|
70
|
-
getPrompt(id: string, args?: { [key: string]: unknown }): Promise<ResolvedPromptTemplate | undefined>;
|
|
70
|
+
getPrompt(id: string, args?: { [key: string]: unknown }, context?: AIVariableContext): Promise<ResolvedPromptTemplate | undefined>;
|
|
71
71
|
/**
|
|
72
72
|
* Adds a {@link PromptTemplate} to the list of prompts.
|
|
73
73
|
* @param promptTemplate the prompt template to store
|
|
@@ -239,7 +239,7 @@ export class PromptServiceImpl implements PromptService {
|
|
|
239
239
|
return id;
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
async getPrompt(id: string, args?: { [key: string]: unknown }): Promise<ResolvedPromptTemplate | undefined> {
|
|
242
|
+
async getPrompt(id: string, args?: { [key: string]: unknown }, context?: AIVariableContext): Promise<ResolvedPromptTemplate | undefined> {
|
|
243
243
|
const variantId = await this.getVariantId(id);
|
|
244
244
|
const prompt = this.getUnresolvedPrompt(variantId);
|
|
245
245
|
if (prompt === undefined) {
|
|
@@ -262,7 +262,7 @@ export class PromptServiceImpl implements PromptService {
|
|
|
262
262
|
value: String(args?.[variableAndArg] ?? (await this.variableService?.resolveVariable({
|
|
263
263
|
variable: variableName,
|
|
264
264
|
arg: argument
|
|
265
|
-
}, {}))?.value ?? completeText)
|
|
265
|
+
}, context ?? {}))?.value ?? completeText)
|
|
266
266
|
};
|
|
267
267
|
}));
|
|
268
268
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2025 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
|
+
export namespace PromptText {
|
|
18
|
+
export const AGENT_CHAR = '@';
|
|
19
|
+
export const VARIABLE_CHAR = '#';
|
|
20
|
+
export const FUNCTION_CHAR = '~';
|
|
21
|
+
export const VARIABLE_SEPARATOR_CHAR = ':';
|
|
22
|
+
}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
//
|
|
14
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
15
|
// *****************************************************************************
|
|
16
|
-
import { MaybePromise } from '@theia/core';
|
|
16
|
+
import { MaybePromise, nls } from '@theia/core';
|
|
17
17
|
import { injectable } from '@theia/core/shared/inversify';
|
|
18
18
|
import { AIVariable, ResolvedAIVariable, AIVariableContribution, AIVariableResolver, AIVariableService, AIVariableResolutionRequest, AIVariableContext } from './variable-service';
|
|
19
19
|
|
|
@@ -24,11 +24,15 @@ export namespace TodayVariableArgs {
|
|
|
24
24
|
|
|
25
25
|
export const TODAY_VARIABLE: AIVariable = {
|
|
26
26
|
id: 'today-provider',
|
|
27
|
-
description: 'Does something for today',
|
|
27
|
+
description: nls.localize('theia/ai/core/todayVariable/description', 'Does something for today'),
|
|
28
28
|
name: 'today',
|
|
29
29
|
args: [
|
|
30
|
-
{
|
|
31
|
-
|
|
30
|
+
{
|
|
31
|
+
name: 'Format',
|
|
32
|
+
description: nls.localize('theia/ai/core/todayVariable/format/description', 'The format of the date'),
|
|
33
|
+
enum: [TodayVariableArgs.IN_ISO_8601, TodayVariableArgs.IN_UNIX_SECONDS],
|
|
34
|
+
isOptional: true
|
|
35
|
+
}
|
|
32
36
|
]
|
|
33
37
|
};
|
|
34
38
|
|
|
@@ -21,37 +21,112 @@
|
|
|
21
21
|
|
|
22
22
|
import { ContributionProvider, Disposable, Emitter, ILogger, MaybePromise, Prioritizeable, Event } from '@theia/core';
|
|
23
23
|
import { inject, injectable, named } from '@theia/core/shared/inversify';
|
|
24
|
+
import * as monaco from '@theia/monaco-editor-core';
|
|
24
25
|
|
|
26
|
+
/**
|
|
27
|
+
* A variable is a short string that is used to reference a value that is resolved and replaced in the user prompt at request-time.
|
|
28
|
+
*/
|
|
25
29
|
export interface AIVariable {
|
|
26
30
|
/** provider id */
|
|
27
31
|
id: string;
|
|
28
|
-
/** variable name */
|
|
32
|
+
/** variable name, used for referencing variables in the chat */
|
|
29
33
|
name: string;
|
|
30
34
|
/** variable description */
|
|
31
35
|
description: string;
|
|
36
|
+
/** optional label, used for showing the variable in the UI. If not provided, the variable name is used */
|
|
37
|
+
label?: string;
|
|
38
|
+
/** optional icon classes, used for showing the variable in the UI. */
|
|
39
|
+
iconClasses?: string[];
|
|
40
|
+
/** specifies whether this variable contributes to the context -- @see ResolvedAIContextVariable */
|
|
41
|
+
isContextVariable?: boolean;
|
|
42
|
+
/** optional arguments for resolving the variable into a value */
|
|
32
43
|
args?: AIVariableDescription[];
|
|
33
44
|
}
|
|
34
45
|
|
|
46
|
+
export namespace AIVariable {
|
|
47
|
+
export function is(arg: unknown): arg is AIVariable {
|
|
48
|
+
return !!arg && typeof arg === 'object' &&
|
|
49
|
+
'id' in arg &&
|
|
50
|
+
'name' in arg &&
|
|
51
|
+
'description' in arg;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface AIContextVariable extends AIVariable {
|
|
56
|
+
label: string;
|
|
57
|
+
isContextVariable: true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export namespace AIContextVariable {
|
|
61
|
+
export function is(arg: unknown): arg is AIContextVariable {
|
|
62
|
+
return AIVariable.is(arg) && 'isContextVariable' in arg && arg.isContextVariable === true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
35
66
|
export interface AIVariableDescription {
|
|
36
67
|
name: string;
|
|
37
68
|
description: string;
|
|
69
|
+
enum?: string[];
|
|
70
|
+
isOptional?: boolean;
|
|
38
71
|
}
|
|
39
72
|
|
|
40
73
|
export interface ResolvedAIVariable {
|
|
41
74
|
variable: AIVariable;
|
|
75
|
+
arg?: string;
|
|
76
|
+
/** value that is inserted into the prompt at the position of the variable usage */
|
|
42
77
|
value: string;
|
|
43
78
|
}
|
|
44
79
|
|
|
80
|
+
export namespace ResolvedAIVariable {
|
|
81
|
+
export function is(arg: unknown): arg is ResolvedAIVariable {
|
|
82
|
+
return !!arg && typeof arg === 'object' &&
|
|
83
|
+
'variable' in arg &&
|
|
84
|
+
'value' in arg &&
|
|
85
|
+
typeof (arg as { variable: unknown }).variable === 'object' &&
|
|
86
|
+
typeof (arg as { value: unknown }).value === 'string';
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* A context variable is a variable that also contributes to the context of a chat request.
|
|
92
|
+
*
|
|
93
|
+
* In contrast to a plain variable, it can also be attached to a request and is resolved into a context value.
|
|
94
|
+
* The context value is put into the `ChatRequestModel.context`, available to the processing chat agent for further
|
|
95
|
+
* processing by the chat agent, or invoked tool functions.
|
|
96
|
+
*/
|
|
97
|
+
export interface ResolvedAIContextVariable extends ResolvedAIVariable {
|
|
98
|
+
contextValue: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export namespace ResolvedAIContextVariable {
|
|
102
|
+
export function is(arg: unknown): arg is ResolvedAIContextVariable {
|
|
103
|
+
return ResolvedAIVariable.is(arg) &&
|
|
104
|
+
'contextValue' in arg &&
|
|
105
|
+
typeof (arg as { contextValue: unknown }).contextValue === 'string';
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
45
109
|
export interface AIVariableResolutionRequest {
|
|
46
110
|
variable: AIVariable;
|
|
47
111
|
arg?: string;
|
|
48
112
|
}
|
|
49
113
|
|
|
114
|
+
export namespace AIVariableResolutionRequest {
|
|
115
|
+
export function is(arg: unknown): arg is AIVariableResolutionRequest {
|
|
116
|
+
return !!arg && typeof arg === 'object' &&
|
|
117
|
+
'variable' in arg &&
|
|
118
|
+
typeof (arg as { variable: { name: unknown } }).variable.name === 'string';
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
50
122
|
export interface AIVariableContext {
|
|
51
123
|
}
|
|
52
124
|
|
|
53
125
|
export type AIVariableArg = string | { variable: string, arg?: string } | AIVariableResolutionRequest;
|
|
54
126
|
|
|
127
|
+
export type AIVariableArgPicker = (context: AIVariableContext) => MaybePromise<string | undefined>;
|
|
128
|
+
export type AIVariableArgCompletionProvider = (model: monaco.editor.ITextModel, position: monaco.Position) => MaybePromise<monaco.languages.CompletionItem[] | undefined>;
|
|
129
|
+
|
|
55
130
|
export interface AIVariableResolver {
|
|
56
131
|
canResolve(request: AIVariableResolutionRequest, context: AIVariableContext): MaybePromise<number>,
|
|
57
132
|
resolve(request: AIVariableResolutionRequest, context: AIVariableContext): Promise<ResolvedAIVariable | undefined>;
|
|
@@ -62,6 +137,7 @@ export interface AIVariableService {
|
|
|
62
137
|
hasVariable(name: string): boolean;
|
|
63
138
|
getVariable(name: string): Readonly<AIVariable> | undefined;
|
|
64
139
|
getVariables(): Readonly<AIVariable>[];
|
|
140
|
+
getContextVariables(): Readonly<AIContextVariable>[];
|
|
65
141
|
unregisterVariable(name: string): void;
|
|
66
142
|
readonly onDidChangeVariables: Event<void>;
|
|
67
143
|
|
|
@@ -69,9 +145,18 @@ export interface AIVariableService {
|
|
|
69
145
|
unregisterResolver(variable: AIVariable, resolver: AIVariableResolver): void;
|
|
70
146
|
getResolver(name: string, arg: string | undefined, context: AIVariableContext): Promise<AIVariableResolver | undefined>;
|
|
71
147
|
|
|
148
|
+
registerArgumentPicker(variable: AIVariable, argPicker: AIVariableArgPicker): Disposable;
|
|
149
|
+
unregisterArgumentPicker(variable: AIVariable, argPicker: AIVariableArgPicker): void;
|
|
150
|
+
getArgumentPicker(name: string, context: AIVariableContext): Promise<AIVariableArgPicker | undefined>;
|
|
151
|
+
|
|
152
|
+
registerArgumentCompletionProvider(variable: AIVariable, argPicker: AIVariableArgCompletionProvider): Disposable;
|
|
153
|
+
unregisterArgumentCompletionProvider(variable: AIVariable, argPicker: AIVariableArgCompletionProvider): void;
|
|
154
|
+
getArgumentCompletionProvider(name: string): Promise<AIVariableArgCompletionProvider | undefined>;
|
|
155
|
+
|
|
72
156
|
resolveVariable(variable: AIVariableArg, context: AIVariableContext): Promise<ResolvedAIVariable | undefined>;
|
|
73
157
|
}
|
|
74
158
|
|
|
159
|
+
/** Contributions on the frontend can optionally implement `FrontendVariableContribution`. */
|
|
75
160
|
export const AIVariableContribution = Symbol('AIVariableContribution');
|
|
76
161
|
export interface AIVariableContribution {
|
|
77
162
|
registerVariables(service: AIVariableService): void;
|
|
@@ -81,6 +166,8 @@ export interface AIVariableContribution {
|
|
|
81
166
|
export class DefaultAIVariableService implements AIVariableService {
|
|
82
167
|
protected variables = new Map<string, AIVariable>();
|
|
83
168
|
protected resolvers = new Map<string, AIVariableResolver[]>();
|
|
169
|
+
protected argPickers = new Map<string, AIVariableArgPicker>();
|
|
170
|
+
protected argCompletionProviders = new Map<string, AIVariableArgCompletionProvider>();
|
|
84
171
|
|
|
85
172
|
protected readonly onDidChangeVariablesEmitter = new Emitter<void>();
|
|
86
173
|
readonly onDidChangeVariables: Event<void> = this.onDidChangeVariablesEmitter.event;
|
|
@@ -137,6 +224,10 @@ export class DefaultAIVariableService implements AIVariableService {
|
|
|
137
224
|
return [...this.variables.values()];
|
|
138
225
|
}
|
|
139
226
|
|
|
227
|
+
getContextVariables(): Readonly<AIContextVariable>[] {
|
|
228
|
+
return this.getVariables().filter(AIContextVariable.is);
|
|
229
|
+
}
|
|
230
|
+
|
|
140
231
|
registerResolver(variable: AIVariable, resolver: AIVariableResolver): Disposable {
|
|
141
232
|
const key = this.getKey(variable.name);
|
|
142
233
|
if (!this.variables.get(key)) {
|
|
@@ -164,6 +255,42 @@ export class DefaultAIVariableService implements AIVariableService {
|
|
|
164
255
|
this.onDidChangeVariablesEmitter.fire();
|
|
165
256
|
}
|
|
166
257
|
|
|
258
|
+
registerArgumentPicker(variable: AIVariable, argPicker: AIVariableArgPicker): Disposable {
|
|
259
|
+
const key = this.getKey(variable.name);
|
|
260
|
+
this.argPickers.set(key, argPicker);
|
|
261
|
+
return Disposable.create(() => this.unregisterArgumentPicker(variable, argPicker));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
unregisterArgumentPicker(variable: AIVariable, argPicker: AIVariableArgPicker): void {
|
|
265
|
+
const key = this.getKey(variable.name);
|
|
266
|
+
const registeredArgPicker = this.argPickers.get(key);
|
|
267
|
+
if (registeredArgPicker === argPicker) {
|
|
268
|
+
this.argPickers.delete(key);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async getArgumentPicker(name: string): Promise<AIVariableArgPicker | undefined> {
|
|
273
|
+
return this.argPickers.get(this.getKey(name)) ?? undefined;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
registerArgumentCompletionProvider(variable: AIVariable, completionProvider: AIVariableArgCompletionProvider): Disposable {
|
|
277
|
+
const key = this.getKey(variable.name);
|
|
278
|
+
this.argCompletionProviders.set(key, completionProvider);
|
|
279
|
+
return Disposable.create(() => this.unregisterArgumentCompletionProvider(variable, completionProvider));
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
unregisterArgumentCompletionProvider(variable: AIVariable, completionProvider: AIVariableArgCompletionProvider): void {
|
|
283
|
+
const key = this.getKey(variable.name);
|
|
284
|
+
const registeredCompletionProvider = this.argCompletionProviders.get(key);
|
|
285
|
+
if (registeredCompletionProvider === completionProvider) {
|
|
286
|
+
this.argCompletionProviders.delete(key);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async getArgumentCompletionProvider(name: string): Promise<AIVariableArgCompletionProvider | undefined> {
|
|
291
|
+
return this.argCompletionProviders.get(this.getKey(name)) ?? undefined;
|
|
292
|
+
}
|
|
293
|
+
|
|
167
294
|
async resolveVariable(request: AIVariableArg, context: AIVariableContext): Promise<ResolvedAIVariable | undefined> {
|
|
168
295
|
const variableName = typeof request === 'string' ? request : typeof request.variable === 'string' ? request.variable : request.variable.name;
|
|
169
296
|
const variable = this.getVariable(variableName);
|
|
@@ -172,6 +299,7 @@ export class DefaultAIVariableService implements AIVariableService {
|
|
|
172
299
|
}
|
|
173
300
|
const arg = typeof request === 'string' ? undefined : request.arg;
|
|
174
301
|
const resolver = await this.getResolver(variableName, arg, context);
|
|
175
|
-
|
|
302
|
+
const resolved = await resolver?.resolve({ variable, arg }, context);
|
|
303
|
+
return resolved ? { ...resolved, arg } : undefined;
|
|
176
304
|
}
|
|
177
305
|
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { ReactWidget } from '@theia/core/lib/browser';
|
|
3
|
-
import * as React from '@theia/core/shared/react';
|
|
4
|
-
import { Agent, AISettingsService, AIVariableService, LanguageModel, LanguageModelRegistry, PromptCustomizationService, PromptService } from '../../common';
|
|
5
|
-
import { AIConfigurationSelectionService } from './ai-configuration-service';
|
|
6
|
-
import { AgentService } from '../../common/agent-service';
|
|
7
|
-
export declare class AIAgentConfigurationWidget extends ReactWidget {
|
|
8
|
-
static readonly ID = "ai-agent-configuration-container-widget";
|
|
9
|
-
static readonly LABEL = "Agents";
|
|
10
|
-
protected readonly agentService: AgentService;
|
|
11
|
-
protected readonly languageModelRegistry: LanguageModelRegistry;
|
|
12
|
-
protected readonly promptCustomizationService: PromptCustomizationService;
|
|
13
|
-
protected readonly aiSettingsService: AISettingsService;
|
|
14
|
-
protected readonly aiConfigurationSelectionService: AIConfigurationSelectionService;
|
|
15
|
-
protected readonly variableService: AIVariableService;
|
|
16
|
-
protected promptService: PromptService;
|
|
17
|
-
protected languageModels: LanguageModel[] | undefined;
|
|
18
|
-
protected init(): void;
|
|
19
|
-
protected render(): React.ReactNode;
|
|
20
|
-
private renderAgentName;
|
|
21
|
-
private renderAgentDetails;
|
|
22
|
-
private parsePromptTemplatesForVariableAndFunction;
|
|
23
|
-
protected showVariableConfigurationTab(): void;
|
|
24
|
-
protected addCustomAgent(): void;
|
|
25
|
-
protected setActiveAgent(agent: Agent): void;
|
|
26
|
-
private toggleAgentEnabled;
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=agent-configuration-widget.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agent-configuration-widget.d.ts","sourceRoot":"","sources":["../../../src/browser/ai-configuration/agent-configuration-widget.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAW,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,KAAK,KAAK,MAAM,0BAA0B,CAAC;AAClD,OAAO,EACH,KAAK,EACL,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EAGrB,0BAA0B,EAC1B,aAAa,EAChB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,+BAA+B,EAAE,MAAM,4BAA4B,CAAC;AAE7E,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAQ1D,qBACa,0BAA2B,SAAQ,WAAW;IAEvD,MAAM,CAAC,QAAQ,CAAC,EAAE,6CAA6C;IAC/D,MAAM,CAAC,QAAQ,CAAC,KAAK,YAAY;IAGjC,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IAG9C,SAAS,CAAC,QAAQ,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;IAGhE,SAAS,CAAC,QAAQ,CAAC,0BAA0B,EAAE,0BAA0B,CAAC;IAG1E,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAGxD,SAAS,CAAC,QAAQ,CAAC,+BAA+B,EAAE,+BAA+B,CAAC;IAGpF,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,iBAAiB,CAAC;IAGtD,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;IAEvC,SAAS,CAAC,cAAc,EAAE,aAAa,EAAE,GAAG,SAAS,CAAC;IAGtD,SAAS,CAAC,IAAI,IAAI,IAAI;IAqBtB,SAAS,CAAC,MAAM,IAAI,KAAK,CAAC,SAAS;IAoBnC,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,kBAAkB;IA6E1B,OAAO,CAAC,0CAA0C;IA6BlD,SAAS,CAAC,4BAA4B,IAAI,IAAI;IAI9C,SAAS,CAAC,cAAc,IAAI,IAAI;IAIhC,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAK5C,OAAO,CAAC,kBAAkB,CAYxB;CAEL"}
|