@theia/ai-core 1.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/data/prompttemplate.tmLanguage.json +52 -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 +27 -0
- package/lib/browser/ai-configuration/agent-configuration-widget.d.ts.map +1 -0
- package/lib/browser/ai-configuration/agent-configuration-widget.js +231 -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 +11 -0
- package/lib/browser/ai-configuration/template-settings-renderer.d.ts.map +1 -0
- package/lib/browser/ai-configuration/template-settings-renderer.js +33 -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 +8 -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 +14 -0
- package/lib/browser/ai-core-preferences.d.ts.map +1 -0
- package/lib/browser/ai-core-preferences.js +69 -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 +31 -0
- package/lib/browser/frontend-prompt-customization-service.d.ts.map +1 -0
- package/lib/browser/frontend-prompt-customization-service.js +194 -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 +28 -0
- package/lib/browser/prompttemplate-contribution.d.ts.map +1 -0
- package/lib/browser/prompttemplate-contribution.js +207 -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 +48 -0
- package/lib/common/agent-service.d.ts.map +1 -0
- package/lib/common/agent-service.js +88 -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 +23 -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 +5 -0
- package/lib/common/language-model-util.d.ts.map +1 -0
- package/lib/common/language-model-util.js +75 -0
- package/lib/common/language-model-util.js.map +1 -0
- package/lib/common/language-model.d.ts +137 -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 +5 -0
- package/lib/common/prompt-service-util.d.ts.map +1 -0
- package/lib/common/prompt-service-util.js +23 -0
- package/lib/common/prompt-service-util.js.map +1 -0
- package/lib/common/prompt-service.d.ts +101 -0
- package/lib/common/prompt-service.d.ts.map +1 -0
- package/lib/common/prompt-service.js +139 -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 +86 -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 +18 -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 +59 -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 +299 -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 +39 -0
- package/src/browser/ai-configuration/variable-configuration-widget.tsx +110 -0
- package/src/browser/ai-core-frontend-application-contribution.ts +40 -0
- package/src/browser/ai-core-frontend-module.ts +161 -0
- package/src/browser/ai-core-preferences.ts +76 -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 +197 -0
- package/src/browser/frontend-variable-service.ts +26 -0
- package/src/browser/index.ts +26 -0
- package/src/browser/prompttemplate-contribution.ts +250 -0
- package/src/browser/style/index.css +90 -0
- package/src/browser/theia-variable-contribution.ts +58 -0
- package/src/common/agent-service.ts +108 -0
- package/src/common/agent.ts +70 -0
- package/src/common/agents-variable-contribution.ts +64 -0
- package/src/common/communication-recording-service.ts +44 -0
- package/src/common/index.ts +30 -0
- package/src/common/language-model-delegate.ts +45 -0
- package/src/common/language-model-util.ts +67 -0
- package/src/common/language-model.spec.ts +86 -0
- package/src/common/language-model.ts +237 -0
- package/src/common/prompt-service-util.ts +21 -0
- package/src/common/prompt-service.spec.ts +98 -0
- package/src/common/prompt-service.ts +213 -0
- package/src/common/protocol.ts +23 -0
- package/src/common/settings-service.ts +33 -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,108 @@
|
|
|
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, named, optional, postConstruct } from '@theia/core/shared/inversify';
|
|
17
|
+
import { ContributionProvider } from '@theia/core';
|
|
18
|
+
import { Agent } from './agent';
|
|
19
|
+
import { AISettingsService } from './settings-service';
|
|
20
|
+
|
|
21
|
+
export const AgentService = Symbol('AgentService');
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Service to access the list of known Agents.
|
|
25
|
+
*/
|
|
26
|
+
export interface AgentService {
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves a list of all available agents, i.e. agents which are not disabled
|
|
29
|
+
*/
|
|
30
|
+
getAgents(): Agent[];
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves a list of all agents, including disabled ones.
|
|
33
|
+
*/
|
|
34
|
+
getAllAgents(): Agent[];
|
|
35
|
+
/**
|
|
36
|
+
* Enable the agent with the specified id.
|
|
37
|
+
* @param agentId the agent id.
|
|
38
|
+
*/
|
|
39
|
+
enableAgent(agentId: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* disable the agent with the specified id.
|
|
42
|
+
* @param agentId the agent id.
|
|
43
|
+
*/
|
|
44
|
+
disableAgent(agentId: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* query whether this agent is currently enabled or disabled.
|
|
47
|
+
* @param agentId the agent id.
|
|
48
|
+
* @return true if the agent is enabled, false otherwise.
|
|
49
|
+
*/
|
|
50
|
+
isEnabled(agentId: string): boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@injectable()
|
|
54
|
+
export class AgentServiceImpl implements AgentService {
|
|
55
|
+
|
|
56
|
+
@inject(ContributionProvider) @named(Agent)
|
|
57
|
+
protected readonly agentsProvider: ContributionProvider<Agent>;
|
|
58
|
+
|
|
59
|
+
@inject(AISettingsService) @optional()
|
|
60
|
+
protected readonly aiSettingsService: AISettingsService | undefined;
|
|
61
|
+
|
|
62
|
+
protected disabledAgents = new Set<string>();
|
|
63
|
+
|
|
64
|
+
protected _agents: Agent[] = [];
|
|
65
|
+
|
|
66
|
+
@postConstruct()
|
|
67
|
+
protected init(): void {
|
|
68
|
+
this.aiSettingsService?.getSettings().then(settings => {
|
|
69
|
+
Object.entries(settings).forEach(([agentId, agentSettings]) => {
|
|
70
|
+
if (agentSettings.enable === false) {
|
|
71
|
+
this.disabledAgents.add(agentId);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private get agents(): Agent[] {
|
|
78
|
+
// We can't collect the contributions at @postConstruct because this will lead to a circular dependency
|
|
79
|
+
// with agents reusing the chat agent service (e.g. orchestrator) which in turn injects the agent service
|
|
80
|
+
return [...this.agentsProvider.getContributions(), ...this._agents];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
registerAgent(agent: Agent): void {
|
|
84
|
+
this._agents.push(agent);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
getAgents(): Agent[] {
|
|
88
|
+
return this.agents.filter(agent => this.isEnabled(agent.id));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
getAllAgents(): Agent[] {
|
|
92
|
+
return this.agents;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
enableAgent(agentId: string): void {
|
|
96
|
+
this.disabledAgents.delete(agentId);
|
|
97
|
+
this.aiSettingsService?.updateAgentSettings(agentId, { enable: true });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
disableAgent(agentId: string): void {
|
|
101
|
+
this.disabledAgents.add(agentId);
|
|
102
|
+
this.aiSettingsService?.updateAgentSettings(agentId, { enable: false });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
isEnabled(agentId: string): boolean {
|
|
106
|
+
return !this.disabledAgents.has(agentId);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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 { LanguageModelRequirement } from './language-model';
|
|
18
|
+
import { PromptTemplate } from './prompt-service';
|
|
19
|
+
|
|
20
|
+
export interface AgentSpecificVariables {
|
|
21
|
+
name: string;
|
|
22
|
+
description: string;
|
|
23
|
+
usedInPrompt: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const Agent = Symbol('Agent');
|
|
27
|
+
/**
|
|
28
|
+
* Agents represent the main functionality of the AI system. They are responsible for processing user input, collecting information from the environment,
|
|
29
|
+
* invoking and processing LLM responses, and providing the final response to the user while recording their actions in the AI history.
|
|
30
|
+
*
|
|
31
|
+
* Agents are meant to cover all use cases, from specialized scenarios to general purpose chat bots.
|
|
32
|
+
*
|
|
33
|
+
* Agents are encouraged to provide a detailed description of their functionality and their processed inputs.
|
|
34
|
+
* They can also declare their used prompt templates, which makes them configurable for the user.
|
|
35
|
+
*/
|
|
36
|
+
export interface Agent {
|
|
37
|
+
/**
|
|
38
|
+
* Used to identify an agent, e.g. when it is requesting language models, etc.
|
|
39
|
+
*
|
|
40
|
+
* @note This parameter might be removed in favor of `name`. Therefore, it is recommended to set `id` to the same value as `name` for now.
|
|
41
|
+
*/
|
|
42
|
+
readonly id: string;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Human-readable name shown to users to identify the agent. Must be unique.
|
|
46
|
+
* Use short names without "Agent" or "Chat" (see `tags` for adding further properties).
|
|
47
|
+
*/
|
|
48
|
+
readonly name: string;
|
|
49
|
+
|
|
50
|
+
/** A markdown description of its functionality and its privacy-relevant requirements, including function call handlers that access some data autonomously. */
|
|
51
|
+
readonly description: string;
|
|
52
|
+
|
|
53
|
+
/** The list of global variable identifiers this agent needs to clarify its context requirements. See #39. */
|
|
54
|
+
readonly variables: string[];
|
|
55
|
+
|
|
56
|
+
/** The prompt templates introduced and used by this agent. */
|
|
57
|
+
readonly promptTemplates: PromptTemplate[];
|
|
58
|
+
|
|
59
|
+
/** Required language models. This includes the purpose and optional language model selector arguments. See #47. */
|
|
60
|
+
readonly languageModelRequirements: LanguageModelRequirement[];
|
|
61
|
+
|
|
62
|
+
/** A list of tags to filter agents and to display capabilities in the UI */
|
|
63
|
+
readonly tags?: String[];
|
|
64
|
+
|
|
65
|
+
/** The list of local variable identifiers this agent needs to clarify its context requirements. */
|
|
66
|
+
readonly agentSpecificVariables: AgentSpecificVariables[];
|
|
67
|
+
|
|
68
|
+
/** The list of global function identifiers this agent needs to clarify its context requirements. */
|
|
69
|
+
readonly functions: string[];
|
|
70
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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 { AIVariable, AIVariableContext, AIVariableContribution, AIVariableResolutionRequest, AIVariableResolver, AIVariableService, ResolvedAIVariable } from './variable-service';
|
|
18
|
+
import { MaybePromise } from '@theia/core';
|
|
19
|
+
import { AgentService } from './agent-service';
|
|
20
|
+
|
|
21
|
+
export const AGENTS_VARIABLE: AIVariable = {
|
|
22
|
+
id: 'agents',
|
|
23
|
+
name: 'agents',
|
|
24
|
+
description: 'Returns the list of agents available in the system'
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export interface ResolvedAgentsVariable extends ResolvedAIVariable {
|
|
28
|
+
agents: AgentDescriptor[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface AgentDescriptor {
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
description: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@injectable()
|
|
38
|
+
export class AgentsVariableContribution implements AIVariableContribution, AIVariableResolver {
|
|
39
|
+
|
|
40
|
+
@inject(AgentService)
|
|
41
|
+
protected readonly agentService: AgentService;
|
|
42
|
+
|
|
43
|
+
registerVariables(service: AIVariableService): void {
|
|
44
|
+
service.registerResolver(AGENTS_VARIABLE, this);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
canResolve(request: AIVariableResolutionRequest, _context: AIVariableContext): MaybePromise<number> {
|
|
48
|
+
if (request.variable.name === AGENTS_VARIABLE.name) {
|
|
49
|
+
return 1;
|
|
50
|
+
}
|
|
51
|
+
return -1;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async resolve(request: AIVariableResolutionRequest, context: AIVariableContext): Promise<ResolvedAgentsVariable | undefined> {
|
|
55
|
+
if (request.variable.name === AGENTS_VARIABLE.name) {
|
|
56
|
+
const agents = this.agentService.getAgents().map(agent => ({
|
|
57
|
+
id: agent.id,
|
|
58
|
+
name: agent.name,
|
|
59
|
+
description: agent.description
|
|
60
|
+
}));
|
|
61
|
+
return { variable: AGENTS_VARIABLE, agents, value: JSON.stringify(agents) };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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 { Event } from '@theia/core';
|
|
18
|
+
|
|
19
|
+
export type CommunicationHistory = CommunicationHistoryEntry[];
|
|
20
|
+
|
|
21
|
+
export interface CommunicationHistoryEntry {
|
|
22
|
+
agentId: string;
|
|
23
|
+
sessionId: string;
|
|
24
|
+
timestamp: number;
|
|
25
|
+
requestId: string;
|
|
26
|
+
request?: string;
|
|
27
|
+
response?: string;
|
|
28
|
+
responseTime?: number;
|
|
29
|
+
messages?: unknown[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type CommunicationRequestEntry = Omit<CommunicationHistoryEntry, 'response' | 'responseTime'>;
|
|
33
|
+
export type CommunicationResponseEntry = Omit<CommunicationHistoryEntry, 'request'>;
|
|
34
|
+
|
|
35
|
+
export const CommunicationRecordingService = Symbol('CommunicationRecordingService');
|
|
36
|
+
export interface CommunicationRecordingService {
|
|
37
|
+
recordRequest(requestEntry: CommunicationRequestEntry): void;
|
|
38
|
+
readonly onDidRecordRequest: Event<CommunicationRequestEntry>;
|
|
39
|
+
|
|
40
|
+
recordResponse(responseEntry: CommunicationResponseEntry): void;
|
|
41
|
+
readonly onDidRecordResponse: Event<CommunicationResponseEntry>;
|
|
42
|
+
|
|
43
|
+
getHistory(agentId: string): CommunicationHistory;
|
|
44
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
export * from './agent-service';
|
|
17
|
+
export * from './agent';
|
|
18
|
+
export * from './agents-variable-contribution';
|
|
19
|
+
export * from './communication-recording-service';
|
|
20
|
+
export * from './tool-invocation-registry';
|
|
21
|
+
export * from './language-model-delegate';
|
|
22
|
+
export * from './language-model-util';
|
|
23
|
+
export * from './language-model';
|
|
24
|
+
export * from './prompt-service';
|
|
25
|
+
export * from './prompt-service-util';
|
|
26
|
+
export * from './protocol';
|
|
27
|
+
export * from './today-variable-contribution';
|
|
28
|
+
export * from './tomorrow-variable-contribution';
|
|
29
|
+
export * from './variable-service';
|
|
30
|
+
export * from './settings-service';
|
|
@@ -0,0 +1,45 @@
|
|
|
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 { CancellationToken } from '@theia/core';
|
|
18
|
+
import { LanguageModelMetaData, LanguageModelParsedResponse, LanguageModelRequest, LanguageModelStreamResponsePart, LanguageModelTextResponse } from './language-model';
|
|
19
|
+
|
|
20
|
+
export const LanguageModelDelegateClient = Symbol('LanguageModelDelegateClient');
|
|
21
|
+
export interface LanguageModelDelegateClient {
|
|
22
|
+
toolCall(requestId: string, toolId: string, args_string: string): Promise<unknown>;
|
|
23
|
+
send(id: string, token: LanguageModelStreamResponsePart | undefined): void;
|
|
24
|
+
}
|
|
25
|
+
export const LanguageModelRegistryFrontendDelegate = Symbol('LanguageModelRegistryFrontendDelegate');
|
|
26
|
+
export interface LanguageModelRegistryFrontendDelegate {
|
|
27
|
+
getLanguageModelDescriptions(): Promise<LanguageModelMetaData[]>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface LanguageModelStreamResponseDelegate {
|
|
31
|
+
streamId: string;
|
|
32
|
+
}
|
|
33
|
+
export const isLanguageModelStreamResponseDelegate = (obj: unknown): obj is LanguageModelStreamResponseDelegate =>
|
|
34
|
+
!!(obj && typeof obj === 'object' && 'streamId' in obj && typeof (obj as { streamId: unknown }).streamId === 'string');
|
|
35
|
+
|
|
36
|
+
export type LanguageModelResponseDelegate = LanguageModelTextResponse | LanguageModelParsedResponse | LanguageModelStreamResponseDelegate;
|
|
37
|
+
|
|
38
|
+
export const LanguageModelFrontendDelegate = Symbol('LanguageModelFrontendDelegate');
|
|
39
|
+
export interface LanguageModelFrontendDelegate {
|
|
40
|
+
cancel(requestId: string): void;
|
|
41
|
+
request(modelId: string, request: LanguageModelRequest, requestId: string, cancellationToken?: CancellationToken): Promise<LanguageModelResponseDelegate>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const languageModelRegistryDelegatePath = '/services/languageModelRegistryDelegatePath';
|
|
45
|
+
export const languageModelDelegatePath = '/services/languageModelDelegatePath';
|
|
@@ -0,0 +1,67 @@
|
|
|
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 { isLanguageModelStreamResponse, isLanguageModelTextResponse, LanguageModelResponse, ToolRequest } from './language-model';
|
|
18
|
+
|
|
19
|
+
export const getTextOfResponse = async (response: LanguageModelResponse): Promise<string> => {
|
|
20
|
+
if (isLanguageModelTextResponse(response)) {
|
|
21
|
+
return response.text;
|
|
22
|
+
} else if (isLanguageModelStreamResponse(response)) {
|
|
23
|
+
let result = '';
|
|
24
|
+
for await (const chunk of response.stream) {
|
|
25
|
+
result += chunk.content ?? '';
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
throw new Error(`Invalid response type ${response}`);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const getJsonOfResponse = async (response: LanguageModelResponse): Promise<unknown> => {
|
|
33
|
+
const text = await getTextOfResponse(response);
|
|
34
|
+
if (text.startsWith('```json')) {
|
|
35
|
+
const regex = /```json\s*([\s\S]*?)\s*```/g;
|
|
36
|
+
let match;
|
|
37
|
+
// eslint-disable-next-line no-null/no-null
|
|
38
|
+
while ((match = regex.exec(text)) !== null) {
|
|
39
|
+
try {
|
|
40
|
+
return JSON.parse(match[1]);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.error('Failed to parse JSON:', error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} else if (text.startsWith('{') || text.startsWith('[')) {
|
|
46
|
+
return JSON.parse(text);
|
|
47
|
+
}
|
|
48
|
+
throw new Error('Invalid response format');
|
|
49
|
+
};
|
|
50
|
+
export const toolRequestToPromptText = (toolRequest: ToolRequest): string => {
|
|
51
|
+
const parameters = toolRequest.parameters;
|
|
52
|
+
let paramsText = '';
|
|
53
|
+
// parameters are supposed to be as a JSON schema. Thus, derive the parameters from its properties definition
|
|
54
|
+
if (parameters) {
|
|
55
|
+
const properties = parameters.properties;
|
|
56
|
+
paramsText = Object.keys(properties)
|
|
57
|
+
.map(key => {
|
|
58
|
+
const param = properties[key];
|
|
59
|
+
return `${key}: ${param.type}`;
|
|
60
|
+
})
|
|
61
|
+
.join(', ');
|
|
62
|
+
}
|
|
63
|
+
const descriptionText = toolRequest.description
|
|
64
|
+
? `: ${toolRequest.description}`
|
|
65
|
+
: '';
|
|
66
|
+
return `You can call function: ${toolRequest.id}(${paramsText})${descriptionText}`;
|
|
67
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
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 { isModelMatching, LanguageModel, LanguageModelSelector } from './language-model';
|
|
18
|
+
import { expect } from 'chai';
|
|
19
|
+
|
|
20
|
+
describe('isModelMatching', () => {
|
|
21
|
+
it('returns false with one of two parameter mismatches', () => {
|
|
22
|
+
expect(
|
|
23
|
+
isModelMatching(
|
|
24
|
+
<LanguageModelSelector>{
|
|
25
|
+
name: 'XXX',
|
|
26
|
+
family: 'YYY',
|
|
27
|
+
},
|
|
28
|
+
<LanguageModel>{
|
|
29
|
+
name: 'gpt-4o',
|
|
30
|
+
family: 'YYY',
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
).eql(false);
|
|
34
|
+
});
|
|
35
|
+
it('returns false with two parameter mismatches', () => {
|
|
36
|
+
expect(
|
|
37
|
+
isModelMatching(
|
|
38
|
+
<LanguageModelSelector>{
|
|
39
|
+
name: 'XXX',
|
|
40
|
+
family: 'YYY',
|
|
41
|
+
},
|
|
42
|
+
<LanguageModel>{
|
|
43
|
+
name: 'gpt-4o',
|
|
44
|
+
family: 'ZZZ',
|
|
45
|
+
}
|
|
46
|
+
)
|
|
47
|
+
).eql(false);
|
|
48
|
+
});
|
|
49
|
+
it('returns true with one parameter match', () => {
|
|
50
|
+
expect(
|
|
51
|
+
isModelMatching(
|
|
52
|
+
<LanguageModelSelector>{
|
|
53
|
+
name: 'gpt-4o',
|
|
54
|
+
},
|
|
55
|
+
<LanguageModel>{
|
|
56
|
+
name: 'gpt-4o',
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
).eql(true);
|
|
60
|
+
});
|
|
61
|
+
it('returns true with two parameter matches', () => {
|
|
62
|
+
expect(
|
|
63
|
+
isModelMatching(
|
|
64
|
+
<LanguageModelSelector>{
|
|
65
|
+
name: 'gpt-4o',
|
|
66
|
+
family: 'YYY',
|
|
67
|
+
},
|
|
68
|
+
<LanguageModel>{
|
|
69
|
+
name: 'gpt-4o',
|
|
70
|
+
family: 'YYY',
|
|
71
|
+
}
|
|
72
|
+
)
|
|
73
|
+
).eql(true);
|
|
74
|
+
});
|
|
75
|
+
it('returns true if there are no parameters in selector', () => {
|
|
76
|
+
expect(
|
|
77
|
+
isModelMatching(
|
|
78
|
+
<LanguageModelSelector>{},
|
|
79
|
+
<LanguageModel>{
|
|
80
|
+
name: 'gpt-4o',
|
|
81
|
+
family: 'YYY',
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
).eql(true);
|
|
85
|
+
});
|
|
86
|
+
});
|