@theia/ai-chat 1.56.0 → 1.57.0-next.136
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 +2 -1
- package/lib/browser/ai-chat-frontend-module.d.ts.map +1 -1
- package/lib/browser/ai-chat-frontend-module.js +14 -17
- package/lib/browser/ai-chat-frontend-module.js.map +1 -1
- package/lib/browser/change-set-file-element.d.ts +44 -0
- package/lib/browser/change-set-file-element.d.ts.map +1 -0
- package/lib/browser/change-set-file-element.js +113 -0
- package/lib/browser/change-set-file-element.js.map +1 -0
- package/lib/browser/change-set-file-resource.d.ts +13 -0
- package/lib/browser/change-set-file-resource.d.ts.map +1 -0
- package/lib/browser/change-set-file-resource.js +73 -0
- package/lib/browser/change-set-file-resource.js.map +1 -0
- package/lib/browser/change-set-file-service.d.ts +26 -0
- package/lib/browser/change-set-file-service.d.ts.map +1 -0
- package/lib/browser/change-set-file-service.js +139 -0
- package/lib/browser/change-set-file-service.js.map +1 -0
- package/lib/browser/frontend-chat-service.d.ts +3 -0
- package/lib/browser/frontend-chat-service.d.ts.map +1 -1
- package/lib/browser/frontend-chat-service.js +8 -20
- package/lib/browser/frontend-chat-service.js.map +1 -1
- package/lib/common/chat-agents.d.ts +4 -5
- package/lib/common/chat-agents.d.ts.map +1 -1
- package/lib/common/chat-agents.js +14 -21
- package/lib/common/chat-agents.js.map +1 -1
- package/lib/common/chat-model.d.ts +117 -7
- package/lib/common/chat-model.d.ts.map +1 -1
- package/lib/common/chat-model.js +124 -8
- package/lib/common/chat-model.js.map +1 -1
- package/lib/common/chat-service.d.ts +17 -0
- package/lib/common/chat-service.d.ts.map +1 -1
- package/lib/common/chat-service.js +34 -2
- package/lib/common/chat-service.js.map +1 -1
- package/lib/common/chat-tool-request-service.d.ts +17 -0
- package/lib/common/chat-tool-request-service.d.ts.map +1 -0
- package/lib/common/chat-tool-request-service.js +52 -0
- package/lib/common/chat-tool-request-service.js.map +1 -0
- package/lib/common/index.d.ts +0 -3
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +0 -3
- package/lib/common/index.js.map +1 -1
- package/package.json +10 -8
- package/src/browser/ai-chat-frontend-module.ts +17 -23
- package/src/browser/change-set-file-element.ts +137 -0
- package/src/browser/change-set-file-resource.ts +74 -0
- package/src/browser/change-set-file-service.ts +136 -0
- package/src/browser/frontend-chat-service.ts +8 -24
- package/src/common/chat-agents.ts +12 -24
- package/src/common/chat-model.ts +236 -14
- package/src/common/chat-service.ts +40 -1
- package/src/common/chat-tool-request-service.ts +59 -0
- package/src/common/index.ts +0 -3
- package/lib/common/command-chat-agents.d.ts +0 -33
- package/lib/common/command-chat-agents.d.ts.map +0 -1
- package/lib/common/command-chat-agents.js +0 -329
- package/lib/common/command-chat-agents.js.map +0 -1
- package/lib/common/o1-chat-agent.d.ts +0 -13
- package/lib/common/o1-chat-agent.d.ts.map +0 -1
- package/lib/common/o1-chat-agent.js +0 -45
- package/lib/common/o1-chat-agent.js.map +0 -1
- package/lib/common/orchestrator-chat-agent.d.ts +0 -22
- package/lib/common/orchestrator-chat-agent.d.ts.map +0 -1
- package/lib/common/orchestrator-chat-agent.js +0 -167
- package/lib/common/orchestrator-chat-agent.js.map +0 -1
- package/lib/common/universal-chat-agent.d.ts +0 -16
- package/lib/common/universal-chat-agent.d.ts.map +0 -1
- package/lib/common/universal-chat-agent.js +0 -109
- package/lib/common/universal-chat-agent.js.map +0 -1
- package/src/common/command-chat-agents.ts +0 -354
- package/src/common/o1-chat-agent.ts +0 -51
- package/src/common/orchestrator-chat-agent.ts +0 -179
- package/src/common/universal-chat-agent.ts +0 -117
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { AgentSpecificVariables, getJsonOfText, getTextOfResponse, LanguageModelResponse } from '@theia/ai-core';
|
|
18
|
-
import {
|
|
19
|
-
PromptTemplate
|
|
20
|
-
} from '@theia/ai-core/lib/common';
|
|
21
|
-
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
22
|
-
import { ChatAgentService } from './chat-agent-service';
|
|
23
|
-
import { AbstractStreamParsingChatAgent, ChatAgent, SystemMessageDescription } from './chat-agents';
|
|
24
|
-
import { ChatRequestModelImpl, InformationalChatResponseContentImpl } from './chat-model';
|
|
25
|
-
import { generateUuid } from '@theia/core';
|
|
26
|
-
import { ChatHistoryEntry } from './chat-history-entry';
|
|
27
|
-
|
|
28
|
-
export const orchestratorTemplate: PromptTemplate = {
|
|
29
|
-
id: 'orchestrator-system',
|
|
30
|
-
template: `{{!-- Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
|
|
31
|
-
https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
|
|
32
|
-
# Instructions
|
|
33
|
-
|
|
34
|
-
Your task is to identify which Chat Agent(s) should best reply a given user's message.
|
|
35
|
-
You consider all messages of the conversation to ensure consistency and avoid agent switches without a clear context change.
|
|
36
|
-
You should select the best Chat Agent based on the name and description of the agents, matching them to the user message.
|
|
37
|
-
|
|
38
|
-
## Constraints
|
|
39
|
-
|
|
40
|
-
Your response must be a JSON array containing the id(s) of the selected Chat Agent(s).
|
|
41
|
-
|
|
42
|
-
* Do not use ids that are not provided in the list below.
|
|
43
|
-
* Do not include any additional information, explanations, or questions for the user.
|
|
44
|
-
* If there is no suitable choice, pick \`Universal\`.
|
|
45
|
-
* If there are multiple good choices, return all of them.
|
|
46
|
-
|
|
47
|
-
Unless there is a more specific agent available, select \`Universal\`, especially for general programming-related questions.
|
|
48
|
-
You must only use the \`id\` attribute of the agent, never the name.
|
|
49
|
-
|
|
50
|
-
### Example Results
|
|
51
|
-
|
|
52
|
-
\`\`\`json
|
|
53
|
-
["Universal"]
|
|
54
|
-
\`\`\`
|
|
55
|
-
|
|
56
|
-
\`\`\`json
|
|
57
|
-
["AnotherChatAgent", "Universal"]
|
|
58
|
-
\`\`\`
|
|
59
|
-
|
|
60
|
-
## List of Currently Available Chat Agents
|
|
61
|
-
|
|
62
|
-
{{chatAgents}}
|
|
63
|
-
`};
|
|
64
|
-
|
|
65
|
-
export const OrchestratorChatAgentId = 'Orchestrator';
|
|
66
|
-
const OrchestratorRequestIdKey = 'orchestatorRequestIdKey';
|
|
67
|
-
|
|
68
|
-
@injectable()
|
|
69
|
-
export class OrchestratorChatAgent extends AbstractStreamParsingChatAgent implements ChatAgent {
|
|
70
|
-
name: string;
|
|
71
|
-
description: string;
|
|
72
|
-
readonly variables: string[];
|
|
73
|
-
promptTemplates: PromptTemplate[];
|
|
74
|
-
fallBackChatAgentId: string;
|
|
75
|
-
readonly functions: string[] = [];
|
|
76
|
-
readonly agentSpecificVariables: AgentSpecificVariables[] = [];
|
|
77
|
-
|
|
78
|
-
constructor() {
|
|
79
|
-
super(OrchestratorChatAgentId, [{
|
|
80
|
-
purpose: 'agent-selection',
|
|
81
|
-
identifier: 'openai/gpt-4o',
|
|
82
|
-
}], 'agent-selection', 'codicon codicon-symbol-boolean', undefined, undefined, false);
|
|
83
|
-
this.name = OrchestratorChatAgentId;
|
|
84
|
-
this.description = 'This agent analyzes the user request against the description of all available chat agents and selects the best fitting agent to answer the request \
|
|
85
|
-
(by using AI).The user\'s request will be directly delegated to the selected agent without further confirmation.';
|
|
86
|
-
this.variables = ['chatAgents'];
|
|
87
|
-
this.promptTemplates = [orchestratorTemplate];
|
|
88
|
-
this.fallBackChatAgentId = 'Universal';
|
|
89
|
-
this.functions = [];
|
|
90
|
-
this.agentSpecificVariables = [];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
@inject(ChatAgentService)
|
|
94
|
-
protected chatAgentService: ChatAgentService;
|
|
95
|
-
|
|
96
|
-
override async invoke(request: ChatRequestModelImpl): Promise<void> {
|
|
97
|
-
request.response.addProgressMessage({ content: 'Determining the most appropriate agent', status: 'inProgress' });
|
|
98
|
-
// We generate a dedicated ID for recording the orchestrator request/response, as we will forward the original request to another agent
|
|
99
|
-
const orchestratorRequestId = generateUuid();
|
|
100
|
-
request.addData(OrchestratorRequestIdKey, orchestratorRequestId);
|
|
101
|
-
const messages = await this.getMessages(request.session);
|
|
102
|
-
const systemMessage = (await this.getSystemMessageDescription())?.text;
|
|
103
|
-
this.recordingService.recordRequest(
|
|
104
|
-
ChatHistoryEntry.fromRequest(this.id, request, {
|
|
105
|
-
requestId: orchestratorRequestId,
|
|
106
|
-
messages,
|
|
107
|
-
systemMessage
|
|
108
|
-
})
|
|
109
|
-
);
|
|
110
|
-
return super.invoke(request);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
protected async getSystemMessageDescription(): Promise<SystemMessageDescription | undefined> {
|
|
114
|
-
const resolvedPrompt = await this.promptService.getPrompt(orchestratorTemplate.id);
|
|
115
|
-
return resolvedPrompt ? SystemMessageDescription.fromResolvedPromptTemplate(resolvedPrompt) : undefined;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
protected override async addContentsToResponse(response: LanguageModelResponse, request: ChatRequestModelImpl): Promise<void> {
|
|
119
|
-
let agentIds: string[] = [];
|
|
120
|
-
const responseText = await getTextOfResponse(response);
|
|
121
|
-
// We use the previously generated, dedicated ID to log the orchestrator response before we forward the original request
|
|
122
|
-
const orchestratorRequestId = request.getDataByKey(OrchestratorRequestIdKey);
|
|
123
|
-
if (typeof orchestratorRequestId === 'string') {
|
|
124
|
-
this.recordingService.recordResponse({
|
|
125
|
-
agentId: this.id,
|
|
126
|
-
sessionId: request.session.id,
|
|
127
|
-
requestId: orchestratorRequestId,
|
|
128
|
-
response: responseText,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
try {
|
|
132
|
-
const jsonResponse = await getJsonOfText(responseText);
|
|
133
|
-
if (Array.isArray(jsonResponse)) {
|
|
134
|
-
agentIds = jsonResponse.filter((id: string) => id !== this.id);
|
|
135
|
-
}
|
|
136
|
-
} catch (error: unknown) {
|
|
137
|
-
// The llm sometimes does not return a parseable result
|
|
138
|
-
this.logger.error('Failed to parse JSON response', error);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (agentIds.length < 1) {
|
|
142
|
-
this.logger.error('No agent was selected, delegating to fallback chat agent');
|
|
143
|
-
request.response.progressMessages.forEach(progressMessage =>
|
|
144
|
-
request.response.updateProgressMessage({ ...progressMessage, status: 'failed' })
|
|
145
|
-
);
|
|
146
|
-
agentIds = [this.fallBackChatAgentId];
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// check if selected (or fallback) agent exists
|
|
150
|
-
if (!this.chatAgentService.getAgent(agentIds[0])) {
|
|
151
|
-
this.logger.error(`Chat agent ${agentIds[0]} not found. Falling back to first registered agent.`);
|
|
152
|
-
const firstRegisteredAgent = this.chatAgentService.getAgents().filter(a => a.id !== this.id)[0]?.id;
|
|
153
|
-
if (firstRegisteredAgent) {
|
|
154
|
-
agentIds = [firstRegisteredAgent];
|
|
155
|
-
} else {
|
|
156
|
-
throw new Error('No chat agent available to handle request. Please check your configuration whether any are enabled.');
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// TODO support delegating to more than one agent
|
|
161
|
-
const delegatedToAgent = agentIds[0];
|
|
162
|
-
request.response.response.addContent(new InformationalChatResponseContentImpl(
|
|
163
|
-
`*Orchestrator*: Delegating to \`@${delegatedToAgent}\`
|
|
164
|
-
|
|
165
|
-
---
|
|
166
|
-
|
|
167
|
-
`
|
|
168
|
-
));
|
|
169
|
-
request.response.overrideAgentId(delegatedToAgent);
|
|
170
|
-
request.response.progressMessages.forEach(progressMessage =>
|
|
171
|
-
request.response.updateProgressMessage({ ...progressMessage, status: 'completed' })
|
|
172
|
-
);
|
|
173
|
-
const agent = this.chatAgentService.getAgent(delegatedToAgent);
|
|
174
|
-
if (!agent) {
|
|
175
|
-
throw new Error(`Chat agent ${delegatedToAgent} not found.`);
|
|
176
|
-
}
|
|
177
|
-
await agent.invoke(request);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { AgentSpecificVariables } from '@theia/ai-core';
|
|
18
|
-
import {
|
|
19
|
-
PromptTemplate
|
|
20
|
-
} from '@theia/ai-core/lib/common';
|
|
21
|
-
import { injectable } from '@theia/core/shared/inversify';
|
|
22
|
-
import { AbstractStreamParsingChatAgent, ChatAgent, SystemMessageDescription } from './chat-agents';
|
|
23
|
-
|
|
24
|
-
export const universalTemplate: PromptTemplate = {
|
|
25
|
-
id: 'universal-system',
|
|
26
|
-
template: `{{!-- Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
|
|
27
|
-
https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
|
|
28
|
-
# Instructions
|
|
29
|
-
|
|
30
|
-
You are an AI assistant integrated into the Theia IDE, specifically designed to help software developers by
|
|
31
|
-
providing concise and accurate answers to programming-related questions. Your role is to enhance the
|
|
32
|
-
developer's productivity by offering quick solutions, explanations, and best practices.
|
|
33
|
-
Keep responses short and to the point, focusing on delivering valuable insights, best practices and
|
|
34
|
-
simple solutions.
|
|
35
|
-
|
|
36
|
-
### Guidelines
|
|
37
|
-
|
|
38
|
-
1. **Understand Context:**
|
|
39
|
-
- Assess the context of the code or issue when available.
|
|
40
|
-
- Tailor responses to be relevant to the programming language, framework, or tools like Eclipse Theia.
|
|
41
|
-
- Ask clarifying questions if necessary to provide accurate assistance.
|
|
42
|
-
|
|
43
|
-
2. **Provide Clear Solutions:**
|
|
44
|
-
- Offer direct answers or code snippets that solve the problem or clarify the concept.
|
|
45
|
-
- Avoid lengthy explanations unless necessary for understanding.
|
|
46
|
-
|
|
47
|
-
3. **Promote Best Practices:**
|
|
48
|
-
- Suggest best practices and common patterns relevant to the question.
|
|
49
|
-
- Provide links to official documentation for further reading when applicable.
|
|
50
|
-
|
|
51
|
-
4. **Support Multiple Languages and Tools:**
|
|
52
|
-
- Be familiar with popular programming languages, frameworks, IDEs like Eclipse Theia, and command-line tools.
|
|
53
|
-
- Adapt advice based on the language, environment, or tools specified by the developer.
|
|
54
|
-
|
|
55
|
-
5. **Facilitate Learning:**
|
|
56
|
-
- Encourage learning by explaining why a solution works or why a particular approach is recommended.
|
|
57
|
-
- Keep explanations concise and educational.
|
|
58
|
-
|
|
59
|
-
6. **Maintain Professional Tone:**
|
|
60
|
-
- Communicate in a friendly, professional manner.
|
|
61
|
-
- Use technical jargon appropriately, ensuring clarity for the target audience.
|
|
62
|
-
|
|
63
|
-
7. **Stay on Topic:**
|
|
64
|
-
- Limit responses strictly to topics related to software development, frameworks, Eclipse Theia, terminal usage, and relevant technologies.
|
|
65
|
-
- Politely decline to answer questions unrelated to these areas by saying, "I'm here to assist with programming-related questions.
|
|
66
|
-
For other topics, please refer to a specialized source."
|
|
67
|
-
|
|
68
|
-
### Example Interactions
|
|
69
|
-
|
|
70
|
-
- **Question:** "What's the difference between \`let\` and \`var\` in JavaScript?"
|
|
71
|
-
**Answer:** "\`let\` is block-scoped, while \`var\` is function-scoped. Prefer \`let\` to avoid scope-related bugs."
|
|
72
|
-
|
|
73
|
-
- **Question:** "How do I handle exceptions in Java?"
|
|
74
|
-
**Answer:** "Use try-catch blocks: \`\`\`java try { /* code */ } catch (ExceptionType e) { /* handle exception */ }\`\`\`."
|
|
75
|
-
|
|
76
|
-
- **Question:** "What is the capital of France?"
|
|
77
|
-
**Answer:** "I'm here to assist with programming-related queries. For other topics, please refer to a specialized source."
|
|
78
|
-
`
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export const universalTemplateVariant: PromptTemplate = {
|
|
82
|
-
id: 'universal-system-empty',
|
|
83
|
-
template: '',
|
|
84
|
-
variantOf: universalTemplate.id,
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
@injectable()
|
|
88
|
-
export class UniversalChatAgent extends AbstractStreamParsingChatAgent implements ChatAgent {
|
|
89
|
-
name: string;
|
|
90
|
-
description: string;
|
|
91
|
-
variables: string[];
|
|
92
|
-
promptTemplates: PromptTemplate[];
|
|
93
|
-
readonly functions: string[];
|
|
94
|
-
readonly agentSpecificVariables: AgentSpecificVariables[];
|
|
95
|
-
|
|
96
|
-
constructor() {
|
|
97
|
-
super('Universal', [{
|
|
98
|
-
purpose: 'chat',
|
|
99
|
-
identifier: 'openai/gpt-4o',
|
|
100
|
-
}], 'chat');
|
|
101
|
-
this.name = 'Universal';
|
|
102
|
-
this.description = 'This agent is designed to help software developers by providing concise and accurate '
|
|
103
|
-
+ 'answers to general programming and software development questions. It is also the fall-back for any generic '
|
|
104
|
-
+ 'questions the user might ask. The universal agent currently does not have any context by default, i.e. it cannot '
|
|
105
|
-
+ 'access the current user context or the workspace.';
|
|
106
|
-
this.variables = [];
|
|
107
|
-
this.promptTemplates = [universalTemplate, universalTemplateVariant];
|
|
108
|
-
this.functions = [];
|
|
109
|
-
this.agentSpecificVariables = [];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
protected override async getSystemMessageDescription(): Promise<SystemMessageDescription | undefined> {
|
|
113
|
-
const resolvedPrompt = await this.promptService.getPrompt(universalTemplate.id);
|
|
114
|
-
return resolvedPrompt ? SystemMessageDescription.fromResolvedPromptTemplate(resolvedPrompt) : undefined;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
}
|