@theia/ai-core 1.46.0-next.241
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/README.md +31 -0
- package/data/prompttemplate.tmLanguage.json +107 -0
- package/lib/browser/ai-activation-service.d.ts +17 -0
- package/lib/browser/ai-activation-service.d.ts.map +1 -0
- package/lib/browser/ai-activation-service.js +63 -0
- package/lib/browser/ai-activation-service.js.map +1 -0
- package/lib/browser/ai-command-handler-factory.d.ts +4 -0
- package/lib/browser/ai-command-handler-factory.d.ts.map +1 -0
- package/lib/browser/ai-command-handler-factory.js +20 -0
- package/lib/browser/ai-command-handler-factory.js.map +1 -0
- package/lib/browser/ai-configuration/agent-configuration-widget.d.ts +28 -0
- package/lib/browser/ai-configuration/agent-configuration-widget.d.ts.map +1 -0
- package/lib/browser/ai-configuration/agent-configuration-widget.js +242 -0
- package/lib/browser/ai-configuration/agent-configuration-widget.js.map +1 -0
- package/lib/browser/ai-configuration/ai-configuration-service.d.ts +13 -0
- package/lib/browser/ai-configuration/ai-configuration-service.d.ts.map +1 -0
- package/lib/browser/ai-configuration/ai-configuration-service.js +44 -0
- package/lib/browser/ai-configuration/ai-configuration-service.js.map +1 -0
- package/lib/browser/ai-configuration/ai-configuration-view-contribution.d.ts +12 -0
- package/lib/browser/ai-configuration/ai-configuration-view-contribution.d.ts.map +1 -0
- package/lib/browser/ai-configuration/ai-configuration-view-contribution.js +41 -0
- package/lib/browser/ai-configuration/ai-configuration-view-contribution.js.map +1 -0
- package/lib/browser/ai-configuration/ai-configuration-widget.d.ts +20 -0
- package/lib/browser/ai-configuration/ai-configuration-widget.d.ts.map +1 -0
- package/lib/browser/ai-configuration/ai-configuration-widget.js +88 -0
- package/lib/browser/ai-configuration/ai-configuration-widget.js.map +1 -0
- package/lib/browser/ai-configuration/language-model-renderer.d.ts +13 -0
- package/lib/browser/ai-configuration/language-model-renderer.d.ts.map +1 -0
- package/lib/browser/ai-configuration/language-model-renderer.js +104 -0
- package/lib/browser/ai-configuration/language-model-renderer.js.map +1 -0
- package/lib/browser/ai-configuration/template-settings-renderer.d.ts +13 -0
- package/lib/browser/ai-configuration/template-settings-renderer.d.ts.map +1 -0
- package/lib/browser/ai-configuration/template-settings-renderer.js +71 -0
- package/lib/browser/ai-configuration/template-settings-renderer.js.map +1 -0
- package/lib/browser/ai-configuration/variable-configuration-widget.d.ts +20 -0
- package/lib/browser/ai-configuration/variable-configuration-widget.d.ts.map +1 -0
- package/lib/browser/ai-configuration/variable-configuration-widget.js +99 -0
- package/lib/browser/ai-configuration/variable-configuration-widget.js.map +1 -0
- package/lib/browser/ai-core-frontend-application-contribution.d.ts +10 -0
- package/lib/browser/ai-core-frontend-application-contribution.d.ts.map +1 -0
- package/lib/browser/ai-core-frontend-application-contribution.js +46 -0
- package/lib/browser/ai-core-frontend-application-contribution.js.map +1 -0
- package/lib/browser/ai-core-frontend-module.d.ts +4 -0
- package/lib/browser/ai-core-frontend-module.d.ts.map +1 -0
- package/lib/browser/ai-core-frontend-module.js +122 -0
- package/lib/browser/ai-core-frontend-module.js.map +1 -0
- package/lib/browser/ai-core-preferences.d.ts +29 -0
- package/lib/browser/ai-core-preferences.d.ts.map +1 -0
- package/lib/browser/ai-core-preferences.js +98 -0
- package/lib/browser/ai-core-preferences.js.map +1 -0
- package/lib/browser/ai-settings-service.d.ts +14 -0
- package/lib/browser/ai-settings-service.d.ts.map +1 -0
- package/lib/browser/ai-settings-service.js +56 -0
- package/lib/browser/ai-settings-service.js.map +1 -0
- package/lib/browser/ai-view-contribution.d.ts +14 -0
- package/lib/browser/ai-view-contribution.d.ts.map +1 -0
- package/lib/browser/ai-view-contribution.js +71 -0
- package/lib/browser/ai-view-contribution.js.map +1 -0
- package/lib/browser/frontend-language-model-registry.d.ts +39 -0
- package/lib/browser/frontend-language-model-registry.d.ts.map +1 -0
- package/lib/browser/frontend-language-model-registry.js +321 -0
- package/lib/browser/frontend-language-model-registry.js.map +1 -0
- package/lib/browser/frontend-prompt-customization-service.d.ts +33 -0
- package/lib/browser/frontend-prompt-customization-service.d.ts.map +1 -0
- package/lib/browser/frontend-prompt-customization-service.js +237 -0
- package/lib/browser/frontend-prompt-customization-service.js.map +1 -0
- package/lib/browser/frontend-variable-service.d.ts +6 -0
- package/lib/browser/frontend-variable-service.d.ts.map +1 -0
- package/lib/browser/frontend-variable-service.js +31 -0
- package/lib/browser/frontend-variable-service.js.map +1 -0
- package/lib/browser/index.d.ts +11 -0
- package/lib/browser/index.d.ts.map +1 -0
- package/lib/browser/index.js +29 -0
- package/lib/browser/index.js.map +1 -0
- package/lib/browser/prompttemplate-contribution.d.ts +29 -0
- package/lib/browser/prompttemplate-contribution.d.ts.map +1 -0
- package/lib/browser/prompttemplate-contribution.js +208 -0
- package/lib/browser/prompttemplate-contribution.js.map +1 -0
- package/lib/browser/theia-variable-contribution.d.ts +13 -0
- package/lib/browser/theia-variable-contribution.d.ts.map +1 -0
- package/lib/browser/theia-variable-contribution.js +64 -0
- package/lib/browser/theia-variable-contribution.js.map +1 -0
- package/lib/common/agent-service.d.ts +66 -0
- package/lib/common/agent-service.d.ts.map +1 -0
- package/lib/common/agent-service.js +92 -0
- package/lib/common/agent-service.js.map +1 -0
- package/lib/common/agent.d.ts +45 -0
- package/lib/common/agent.d.ts.map +1 -0
- package/lib/common/agent.js +20 -0
- package/lib/common/agent.js.map +1 -0
- package/lib/common/agents-variable-contribution.d.ts +19 -0
- package/lib/common/agents-variable-contribution.d.ts.map +1 -0
- package/lib/common/agents-variable-contribution.js +56 -0
- package/lib/common/agents-variable-contribution.js.map +1 -0
- package/lib/common/communication-recording-service.d.ts +29 -0
- package/lib/common/communication-recording-service.d.ts.map +1 -0
- package/lib/common/communication-recording-service.js +20 -0
- package/lib/common/communication-recording-service.js.map +1 -0
- package/lib/common/index.d.ts +16 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +34 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/language-model-delegate.d.ts +24 -0
- package/lib/common/language-model-delegate.d.ts.map +1 -0
- package/lib/common/language-model-delegate.js +26 -0
- package/lib/common/language-model-delegate.js.map +1 -0
- package/lib/common/language-model-util.d.ts +16 -0
- package/lib/common/language-model-util.d.ts.map +1 -0
- package/lib/common/language-model-util.js +92 -0
- package/lib/common/language-model-util.js.map +1 -0
- package/lib/common/language-model.d.ts +144 -0
- package/lib/common/language-model.d.ts.map +1 -0
- package/lib/common/language-model.js +142 -0
- package/lib/common/language-model.js.map +1 -0
- package/lib/common/language-model.spec.d.ts +2 -0
- package/lib/common/language-model.spec.d.ts.map +1 -0
- package/lib/common/language-model.spec.js +62 -0
- package/lib/common/language-model.spec.js.map +1 -0
- package/lib/common/prompt-service-util.d.ts +8 -0
- package/lib/common/prompt-service-util.d.ts.map +1 -0
- package/lib/common/prompt-service-util.js +34 -0
- package/lib/common/prompt-service-util.js.map +1 -0
- package/lib/common/prompt-service.d.ts +161 -0
- package/lib/common/prompt-service.d.ts.map +1 -0
- package/lib/common/prompt-service.js +204 -0
- package/lib/common/prompt-service.js.map +1 -0
- package/lib/common/prompt-service.spec.d.ts +2 -0
- package/lib/common/prompt-service.spec.d.ts.map +1 -0
- package/lib/common/prompt-service.spec.js +254 -0
- package/lib/common/prompt-service.spec.js.map +1 -0
- package/lib/common/protocol.d.ts +7 -0
- package/lib/common/protocol.d.ts.map +1 -0
- package/lib/common/protocol.js +20 -0
- package/lib/common/protocol.js.map +1 -0
- package/lib/common/settings-service.d.ts +23 -0
- package/lib/common/settings-service.d.ts.map +1 -0
- package/lib/common/settings-service.js +5 -0
- package/lib/common/settings-service.js.map +1 -0
- package/lib/common/today-variable-contribution.d.ts +17 -0
- package/lib/common/today-variable-contribution.d.ts.map +1 -0
- package/lib/common/today-variable-contribution.js +48 -0
- package/lib/common/today-variable-contribution.js.map +1 -0
- package/lib/common/tomorrow-variable-contribution.d.ts +17 -0
- package/lib/common/tomorrow-variable-contribution.d.ts.map +1 -0
- package/lib/common/tomorrow-variable-contribution.js +48 -0
- package/lib/common/tomorrow-variable-contribution.js.map +1 -0
- package/lib/common/tool-invocation-registry.d.ts +23 -0
- package/lib/common/tool-invocation-registry.d.ts.map +1 -0
- package/lib/common/tool-invocation-registry.js +72 -0
- package/lib/common/tool-invocation-registry.js.map +1 -0
- package/lib/common/variable-service.d.ts +70 -0
- package/lib/common/variable-service.d.ts.map +1 -0
- package/lib/common/variable-service.js +122 -0
- package/lib/common/variable-service.js.map +1 -0
- package/lib/node/ai-core-backend-module.d.ts +4 -0
- package/lib/node/ai-core-backend-module.d.ts.map +1 -0
- package/lib/node/ai-core-backend-module.js +47 -0
- package/lib/node/ai-core-backend-module.js.map +1 -0
- package/lib/node/backend-language-model-registry.d.ts +12 -0
- package/lib/node/backend-language-model-registry.d.ts.map +1 -0
- package/lib/node/backend-language-model-registry.js +61 -0
- package/lib/node/backend-language-model-registry.js.map +1 -0
- package/lib/node/language-model-frontend-delegate.d.ts +18 -0
- package/lib/node/language-model-frontend-delegate.d.ts.map +1 -0
- package/lib/node/language-model-frontend-delegate.js +100 -0
- package/lib/node/language-model-frontend-delegate.js.map +1 -0
- package/package.json +61 -0
- package/src/browser/ai-activation-service.ts +56 -0
- package/src/browser/ai-command-handler-factory.ts +20 -0
- package/src/browser/ai-configuration/agent-configuration-widget.tsx +324 -0
- package/src/browser/ai-configuration/ai-configuration-service.ts +43 -0
- package/src/browser/ai-configuration/ai-configuration-view-contribution.ts +54 -0
- package/src/browser/ai-configuration/ai-configuration-widget.tsx +80 -0
- package/src/browser/ai-configuration/language-model-renderer.tsx +113 -0
- package/src/browser/ai-configuration/template-settings-renderer.tsx +128 -0
- package/src/browser/ai-configuration/variable-configuration-widget.tsx +110 -0
- package/src/browser/ai-core-frontend-application-contribution.ts +39 -0
- package/src/browser/ai-core-frontend-module.ts +161 -0
- package/src/browser/ai-core-preferences.ts +115 -0
- package/src/browser/ai-settings-service.ts +50 -0
- package/src/browser/ai-view-contribution.ts +77 -0
- package/src/browser/frontend-language-model-registry.ts +405 -0
- package/src/browser/frontend-prompt-customization-service.ts +243 -0
- package/src/browser/frontend-variable-service.ts +26 -0
- package/src/browser/index.ts +26 -0
- package/src/browser/prompttemplate-contribution.ts +252 -0
- package/src/browser/style/index.css +127 -0
- package/src/browser/theia-variable-contribution.ts +58 -0
- package/src/common/agent-service.ts +137 -0
- package/src/common/agent.ts +70 -0
- package/src/common/agents-variable-contribution.ts +64 -0
- package/src/common/communication-recording-service.ts +53 -0
- package/src/common/index.ts +30 -0
- package/src/common/language-model-delegate.ts +45 -0
- package/src/common/language-model-util.ts +84 -0
- package/src/common/language-model.spec.ts +86 -0
- package/src/common/language-model.ts +242 -0
- package/src/common/prompt-service-util.ts +31 -0
- package/src/common/prompt-service.spec.ts +301 -0
- package/src/common/prompt-service.ts +334 -0
- package/src/common/protocol.ts +23 -0
- package/src/common/settings-service.ts +38 -0
- package/src/common/today-variable-contribution.ts +67 -0
- package/src/common/tomorrow-variable-contribution.ts +66 -0
- package/src/common/tool-invocation-registry.ts +79 -0
- package/src/common/variable-service.ts +177 -0
- package/src/node/ai-core-backend-module.ts +83 -0
- package/src/node/backend-language-model-registry.ts +59 -0
- package/src/node/language-model-frontend-delegate.ts +116 -0
|
@@ -0,0 +1,56 @@
|
|
|
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 { inject, injectable } from '@theia/core/shared/inversify';
|
|
17
|
+
import { FrontendApplicationContribution, PreferenceService } from '@theia/core/lib/browser';
|
|
18
|
+
import { Emitter, MaybePromise, Event, } from '@theia/core';
|
|
19
|
+
import { ContextKeyService, ContextKey } from '@theia/core/lib/browser/context-key-service';
|
|
20
|
+
import { PREFERENCE_NAME_ENABLE_EXPERIMENTAL } from './ai-core-preferences';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Context key for the experimental AI feature. It is set to `true` if the feature is enabled.
|
|
24
|
+
*/
|
|
25
|
+
// We reuse the enablement preference for the context key
|
|
26
|
+
export const EXPERIMENTAL_AI_CONTEXT_KEY = PREFERENCE_NAME_ENABLE_EXPERIMENTAL;
|
|
27
|
+
|
|
28
|
+
@injectable()
|
|
29
|
+
export class AIActivationService implements FrontendApplicationContribution {
|
|
30
|
+
@inject(ContextKeyService)
|
|
31
|
+
protected readonly contextKeyService: ContextKeyService;
|
|
32
|
+
|
|
33
|
+
@inject(PreferenceService)
|
|
34
|
+
protected preferenceService: PreferenceService;
|
|
35
|
+
|
|
36
|
+
protected isExperimentalEnabledKey: ContextKey<boolean>;
|
|
37
|
+
|
|
38
|
+
protected onDidChangeExperimental = new Emitter<boolean>();
|
|
39
|
+
get onDidChangeActiveStatus(): Event<boolean> {
|
|
40
|
+
return this.onDidChangeExperimental.event;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
get isActive(): boolean {
|
|
44
|
+
return this.isExperimentalEnabledKey.get() ?? false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
initialize(): MaybePromise<void> {
|
|
48
|
+
this.isExperimentalEnabledKey = this.contextKeyService.createKey(EXPERIMENTAL_AI_CONTEXT_KEY, false);
|
|
49
|
+
this.preferenceService.onPreferenceChanged(e => {
|
|
50
|
+
if (e.preferenceName === PREFERENCE_NAME_ENABLE_EXPERIMENTAL) {
|
|
51
|
+
this.isExperimentalEnabledKey.set(e.newValue);
|
|
52
|
+
this.onDidChangeExperimental.fire(e.newValue);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 { CommandHandler } from '@theia/core';
|
|
18
|
+
|
|
19
|
+
export type AICommandHandlerFactory = (handler: CommandHandler) => CommandHandler;
|
|
20
|
+
export const AICommandHandlerFactory = Symbol('AICommandHandlerFactory');
|
|
@@ -0,0 +1,324 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
}
|