@theia/ai-chat 1.58.2 → 1.59.0-next.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/ai-chat-frontend-module.d.ts.map +1 -1
- package/lib/browser/ai-chat-frontend-module.js +10 -13
- package/lib/browser/ai-chat-frontend-module.js.map +1 -1
- package/lib/browser/ai-chat-preferences.d.ts +1 -0
- package/lib/browser/ai-chat-preferences.d.ts.map +1 -1
- package/lib/browser/ai-chat-preferences.js +12 -3
- package/lib/browser/ai-chat-preferences.js.map +1 -1
- package/lib/browser/change-set-file-element.d.ts +24 -6
- package/lib/browser/change-set-file-element.d.ts.map +1 -1
- package/lib/browser/change-set-file-element.js +105 -15
- package/lib/browser/change-set-file-element.js.map +1 -1
- package/lib/browser/change-set-file-resource.d.ts +40 -8
- package/lib/browser/change-set-file-resource.d.ts.map +1 -1
- package/lib/browser/change-set-file-resource.js +123 -37
- package/lib/browser/change-set-file-resource.js.map +1 -1
- package/lib/browser/change-set-file-service.d.ts +9 -3
- package/lib/browser/change-set-file-service.d.ts.map +1 -1
- package/lib/browser/change-set-file-service.js +35 -13
- package/lib/browser/change-set-file-service.js.map +1 -1
- package/lib/browser/context-file-variable-label-provider.d.ts +14 -0
- package/lib/browser/context-file-variable-label-provider.d.ts.map +1 -0
- package/lib/browser/context-file-variable-label-provider.js +63 -0
- package/lib/browser/context-file-variable-label-provider.js.map +1 -0
- package/lib/browser/context-variable-label-provider.d.ts +9 -0
- package/lib/browser/context-variable-label-provider.d.ts.map +1 -0
- package/lib/browser/context-variable-label-provider.js +55 -0
- package/lib/browser/context-variable-label-provider.js.map +1 -0
- package/lib/browser/file-chat-variable-contribution.d.ts +18 -0
- package/lib/browser/file-chat-variable-contribution.d.ts.map +1 -0
- package/lib/browser/file-chat-variable-contribution.js +135 -0
- package/lib/browser/file-chat-variable-contribution.js.map +1 -0
- package/lib/browser/frontend-chat-service.d.ts +10 -3
- package/lib/browser/frontend-chat-service.d.ts.map +1 -1
- package/lib/browser/frontend-chat-service.js +39 -19
- package/lib/browser/frontend-chat-service.js.map +1 -1
- package/lib/common/chat-agents.d.ts +47 -24
- package/lib/common/chat-agents.d.ts.map +1 -1
- package/lib/common/chat-agents.js +50 -19
- package/lib/common/chat-agents.js.map +1 -1
- package/lib/common/chat-history-entry.js +1 -1
- package/lib/common/chat-history-entry.js.map +1 -1
- package/lib/common/chat-model.d.ts +58 -35
- package/lib/common/chat-model.d.ts.map +1 -1
- package/lib/common/chat-model.js +96 -53
- package/lib/common/chat-model.js.map +1 -1
- package/lib/common/chat-service.d.ts +32 -12
- package/lib/common/chat-service.d.ts.map +1 -1
- package/lib/common/chat-service.js +77 -19
- package/lib/common/chat-service.js.map +1 -1
- package/lib/common/chat-tool-request-service.d.ts +5 -5
- package/lib/common/chat-tool-request-service.d.ts.map +1 -1
- package/lib/common/chat-tool-request-service.js.map +1 -1
- package/lib/common/custom-chat-agent.d.ts +7 -10
- package/lib/common/custom-chat-agent.d.ts.map +1 -1
- package/lib/common/custom-chat-agent.js +7 -11
- package/lib/common/custom-chat-agent.js.map +1 -1
- 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/lib/common/parse-contents.d.ts +2 -2
- package/lib/common/parse-contents.d.ts.map +1 -1
- package/lib/common/parse-contents.js.map +1 -1
- package/lib/common/parse-contents.spec.d.ts.map +1 -1
- package/lib/common/parse-contents.spec.js.map +1 -1
- package/lib/common/response-content-matcher.d.ts +3 -3
- package/lib/common/response-content-matcher.d.ts.map +1 -1
- package/lib/common/response-content-matcher.js.map +1 -1
- package/package.json +12 -10
- package/src/browser/ai-chat-frontend-module.ts +14 -18
- package/src/browser/ai-chat-preferences.ts +13 -2
- package/src/browser/change-set-file-element.ts +99 -20
- package/src/browser/change-set-file-resource.ts +125 -39
- package/src/browser/change-set-file-service.ts +38 -16
- package/src/browser/context-file-variable-label-provider.ts +62 -0
- package/src/browser/context-variable-label-provider.ts +56 -0
- package/src/browser/file-chat-variable-contribution.ts +143 -0
- package/src/browser/frontend-chat-service.ts +40 -26
- package/src/common/chat-agents.ts +72 -27
- package/src/common/chat-history-entry.ts +1 -1
- package/src/common/chat-model.ts +138 -74
- package/src/common/chat-service.ts +96 -23
- package/src/common/chat-tool-request-service.ts +5 -5
- package/src/common/custom-chat-agent.ts +8 -20
- package/src/common/index.ts +0 -3
- package/src/common/parse-contents.spec.ts +2 -2
- package/src/common/parse-contents.ts +2 -2
- package/src/common/response-content-matcher.ts +3 -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/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/orchestrator-chat-agent.ts +0 -179
- package/src/common/universal-chat-agent.ts +0 -117
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2024 EclipseSource GmbH.
|
|
4
|
-
//
|
|
5
|
-
// This program and the accompanying materials are made available under the
|
|
6
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
//
|
|
9
|
-
// This Source Code may also be made available under the following Secondary
|
|
10
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
// with the GNU Classpath Exception which is available at
|
|
13
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
//
|
|
15
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
-
// *****************************************************************************
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.UniversalChatAgent = exports.universalTemplateVariant = exports.universalTemplate = void 0;
|
|
19
|
-
const tslib_1 = require("tslib");
|
|
20
|
-
const inversify_1 = require("@theia/core/shared/inversify");
|
|
21
|
-
const chat_agents_1 = require("./chat-agents");
|
|
22
|
-
exports.universalTemplate = {
|
|
23
|
-
id: 'universal-system',
|
|
24
|
-
template: `{{!-- Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
|
|
25
|
-
https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
|
|
26
|
-
# Instructions
|
|
27
|
-
|
|
28
|
-
You are an AI assistant integrated into the Theia IDE, specifically designed to help software developers by
|
|
29
|
-
providing concise and accurate answers to programming-related questions. Your role is to enhance the
|
|
30
|
-
developer's productivity by offering quick solutions, explanations, and best practices.
|
|
31
|
-
Keep responses short and to the point, focusing on delivering valuable insights, best practices and
|
|
32
|
-
simple solutions.
|
|
33
|
-
|
|
34
|
-
### Guidelines
|
|
35
|
-
|
|
36
|
-
1. **Understand Context:**
|
|
37
|
-
- Assess the context of the code or issue when available.
|
|
38
|
-
- Tailor responses to be relevant to the programming language, framework, or tools like Eclipse Theia.
|
|
39
|
-
- Ask clarifying questions if necessary to provide accurate assistance.
|
|
40
|
-
|
|
41
|
-
2. **Provide Clear Solutions:**
|
|
42
|
-
- Offer direct answers or code snippets that solve the problem or clarify the concept.
|
|
43
|
-
- Avoid lengthy explanations unless necessary for understanding.
|
|
44
|
-
|
|
45
|
-
3. **Promote Best Practices:**
|
|
46
|
-
- Suggest best practices and common patterns relevant to the question.
|
|
47
|
-
- Provide links to official documentation for further reading when applicable.
|
|
48
|
-
|
|
49
|
-
4. **Support Multiple Languages and Tools:**
|
|
50
|
-
- Be familiar with popular programming languages, frameworks, IDEs like Eclipse Theia, and command-line tools.
|
|
51
|
-
- Adapt advice based on the language, environment, or tools specified by the developer.
|
|
52
|
-
|
|
53
|
-
5. **Facilitate Learning:**
|
|
54
|
-
- Encourage learning by explaining why a solution works or why a particular approach is recommended.
|
|
55
|
-
- Keep explanations concise and educational.
|
|
56
|
-
|
|
57
|
-
6. **Maintain Professional Tone:**
|
|
58
|
-
- Communicate in a friendly, professional manner.
|
|
59
|
-
- Use technical jargon appropriately, ensuring clarity for the target audience.
|
|
60
|
-
|
|
61
|
-
7. **Stay on Topic:**
|
|
62
|
-
- Limit responses strictly to topics related to software development, frameworks, Eclipse Theia, terminal usage, and relevant technologies.
|
|
63
|
-
- Politely decline to answer questions unrelated to these areas by saying, "I'm here to assist with programming-related questions.
|
|
64
|
-
For other topics, please refer to a specialized source."
|
|
65
|
-
|
|
66
|
-
### Example Interactions
|
|
67
|
-
|
|
68
|
-
- **Question:** "What's the difference between \`let\` and \`var\` in JavaScript?"
|
|
69
|
-
**Answer:** "\`let\` is block-scoped, while \`var\` is function-scoped. Prefer \`let\` to avoid scope-related bugs."
|
|
70
|
-
|
|
71
|
-
- **Question:** "How do I handle exceptions in Java?"
|
|
72
|
-
**Answer:** "Use try-catch blocks: \`\`\`java try { /* code */ } catch (ExceptionType e) { /* handle exception */ }\`\`\`."
|
|
73
|
-
|
|
74
|
-
- **Question:** "What is the capital of France?"
|
|
75
|
-
**Answer:** "I'm here to assist with programming-related queries. For other topics, please refer to a specialized source."
|
|
76
|
-
`
|
|
77
|
-
};
|
|
78
|
-
exports.universalTemplateVariant = {
|
|
79
|
-
id: 'universal-system-empty',
|
|
80
|
-
template: '',
|
|
81
|
-
variantOf: exports.universalTemplate.id,
|
|
82
|
-
};
|
|
83
|
-
let UniversalChatAgent = class UniversalChatAgent extends chat_agents_1.AbstractStreamParsingChatAgent {
|
|
84
|
-
constructor() {
|
|
85
|
-
super('Universal', [{
|
|
86
|
-
purpose: 'chat',
|
|
87
|
-
identifier: 'openai/gpt-4o',
|
|
88
|
-
}], 'chat');
|
|
89
|
-
this.name = 'Universal';
|
|
90
|
-
this.description = 'This agent is designed to help software developers by providing concise and accurate '
|
|
91
|
-
+ 'answers to general programming and software development questions. It is also the fall-back for any generic '
|
|
92
|
-
+ 'questions the user might ask. The universal agent currently does not have any context by default, i.e. it cannot '
|
|
93
|
-
+ 'access the current user context or the workspace.';
|
|
94
|
-
this.variables = [];
|
|
95
|
-
this.promptTemplates = [exports.universalTemplate, exports.universalTemplateVariant];
|
|
96
|
-
this.functions = [];
|
|
97
|
-
this.agentSpecificVariables = [];
|
|
98
|
-
}
|
|
99
|
-
async getSystemMessageDescription() {
|
|
100
|
-
const resolvedPrompt = await this.promptService.getPrompt(exports.universalTemplate.id);
|
|
101
|
-
return resolvedPrompt ? chat_agents_1.SystemMessageDescription.fromResolvedPromptTemplate(resolvedPrompt) : undefined;
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
exports.UniversalChatAgent = UniversalChatAgent;
|
|
105
|
-
exports.UniversalChatAgent = UniversalChatAgent = tslib_1.__decorate([
|
|
106
|
-
(0, inversify_1.injectable)(),
|
|
107
|
-
tslib_1.__metadata("design:paramtypes", [])
|
|
108
|
-
], UniversalChatAgent);
|
|
109
|
-
//# sourceMappingURL=universal-chat-agent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"universal-chat-agent.js","sourceRoot":"","sources":["../../src/common/universal-chat-agent.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAMhF,4DAA0D;AAC1D,+CAAoG;AAEvF,QAAA,iBAAiB,GAAmB;IAC9C,EAAE,EAAE,kBAAkB;IACtB,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoDZ;CACA,CAAC;AAEW,QAAA,wBAAwB,GAAmB;IACrD,EAAE,EAAE,wBAAwB;IAC5B,QAAQ,EAAE,EAAE;IACZ,SAAS,EAAE,yBAAiB,CAAC,EAAE;CACjC,CAAC;AAGK,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,4CAA8B;IAQnE;QACG,KAAK,CAAC,WAAW,EAAE,CAAC;gBACjB,OAAO,EAAE,MAAM;gBACf,UAAU,EAAE,eAAe;aAC7B,CAAC,EAAE,MAAM,CAAC,CAAC;QACZ,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,uFAAuF;cACrG,8GAA8G;cAC9G,mHAAmH;cACnH,mDAAmD,CAAC;QACzD,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,IAAI,CAAC,eAAe,GAAG,CAAC,yBAAiB,EAAE,gCAAwB,CAAC,CAAC;QACrE,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,IAAI,CAAC,sBAAsB,GAAG,EAAE,CAAC;IACpC,CAAC;IAEkB,KAAK,CAAC,2BAA2B;QACjD,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,yBAAiB,CAAC,EAAE,CAAC,CAAC;QAChF,OAAO,cAAc,CAAC,CAAC,CAAC,sCAAwB,CAAC,0BAA0B,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3G,CAAC;CAEH,CAAA;AA7BY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,sBAAU,GAAE;;GACA,kBAAkB,CA6B9B"}
|
|
@@ -1,354 +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 { inject, injectable } from '@theia/core/shared/inversify';
|
|
18
|
-
import { AbstractTextToModelParsingChatAgent, ChatAgent, SystemMessageDescription } from './chat-agents';
|
|
19
|
-
import {
|
|
20
|
-
PromptTemplate,
|
|
21
|
-
AgentSpecificVariables
|
|
22
|
-
} from '@theia/ai-core';
|
|
23
|
-
import {
|
|
24
|
-
ChatRequestModelImpl,
|
|
25
|
-
ChatResponseContent,
|
|
26
|
-
CommandChatResponseContentImpl,
|
|
27
|
-
CustomCallback,
|
|
28
|
-
HorizontalLayoutChatResponseContentImpl,
|
|
29
|
-
MarkdownChatResponseContentImpl,
|
|
30
|
-
} from './chat-model';
|
|
31
|
-
import {
|
|
32
|
-
CommandRegistry,
|
|
33
|
-
MessageService,
|
|
34
|
-
generateUuid,
|
|
35
|
-
} from '@theia/core';
|
|
36
|
-
|
|
37
|
-
export const commandTemplate: PromptTemplate = {
|
|
38
|
-
id: 'command-system',
|
|
39
|
-
template: `{{!-- Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
|
|
40
|
-
https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
|
|
41
|
-
# System Prompt
|
|
42
|
-
|
|
43
|
-
You are a service that helps users find commands to execute in an IDE.
|
|
44
|
-
You reply with stringified JSON Objects that tell the user which command to execute and its arguments, if any.
|
|
45
|
-
|
|
46
|
-
# Examples
|
|
47
|
-
|
|
48
|
-
The examples start with a short explanation of the return object.
|
|
49
|
-
The response can be found within the markdown \`\`\`json and \`\`\` markers.
|
|
50
|
-
Please include these markers in the reply.
|
|
51
|
-
|
|
52
|
-
Never under any circumstances may you reply with just the command-id!
|
|
53
|
-
|
|
54
|
-
## Example 1
|
|
55
|
-
|
|
56
|
-
This reply is to tell the user to execute the \`theia-ai-prompt-template:show-prompts-command\` command that is available in the Theia command registry.
|
|
57
|
-
|
|
58
|
-
\`\`\`json
|
|
59
|
-
{
|
|
60
|
-
"type": "theia-command",
|
|
61
|
-
"commandId": "theia-ai-prompt-template:show-prompts-command"
|
|
62
|
-
}
|
|
63
|
-
\`\`\`
|
|
64
|
-
|
|
65
|
-
## Example 2
|
|
66
|
-
|
|
67
|
-
This reply is to tell the user to execute the \`theia-ai-prompt-template:show-prompts-command\` command that is available in the theia command registry,
|
|
68
|
-
when the user want to pass arguments to the command.
|
|
69
|
-
|
|
70
|
-
\`\`\`json
|
|
71
|
-
{
|
|
72
|
-
"type": "theia-command",
|
|
73
|
-
"commandId": "theia-ai-prompt-template:show-prompts-command",
|
|
74
|
-
"arguments": ["foo"]
|
|
75
|
-
}
|
|
76
|
-
\`\`\`
|
|
77
|
-
|
|
78
|
-
## Example 3
|
|
79
|
-
|
|
80
|
-
This reply is for custom commands that are not registered in the Theia command registry.
|
|
81
|
-
These commands always have the command id \`ai-chat.command-chat-response.generic\`.
|
|
82
|
-
The arguments are an array and may differ, depending on the user's instructions.
|
|
83
|
-
|
|
84
|
-
\`\`\`json
|
|
85
|
-
{
|
|
86
|
-
"type": "custom-handler",
|
|
87
|
-
"commandId": "ai-chat.command-chat-response.generic",
|
|
88
|
-
"arguments": ["foo", "bar"]
|
|
89
|
-
}
|
|
90
|
-
\`\`\`
|
|
91
|
-
|
|
92
|
-
## Example 4
|
|
93
|
-
|
|
94
|
-
This reply of type no-command is for cases where you can't find a proper command.
|
|
95
|
-
You may use the message to explain the situation to the user.
|
|
96
|
-
|
|
97
|
-
\`\`\`json
|
|
98
|
-
{
|
|
99
|
-
"type": "no-command",
|
|
100
|
-
"message": "a message explaining what is wrong"
|
|
101
|
-
}
|
|
102
|
-
\`\`\`
|
|
103
|
-
|
|
104
|
-
# Rules
|
|
105
|
-
|
|
106
|
-
## Theia Commands
|
|
107
|
-
|
|
108
|
-
If a user asks for a Theia command, or the context implies it is about a command in Theia, return a response with \`"type": "theia-command"\`.
|
|
109
|
-
You need to exchange the "commandId".
|
|
110
|
-
The available command ids in Theia are in the list below. The list of commands is formatted like this:
|
|
111
|
-
|
|
112
|
-
command-id1: Label1
|
|
113
|
-
command-id2: Label2
|
|
114
|
-
command-id3:
|
|
115
|
-
command-id4: Label4
|
|
116
|
-
|
|
117
|
-
The Labels may be empty, but there is always a command-id.
|
|
118
|
-
|
|
119
|
-
Suggest a command that probably fits the user's message based on the label and the command ids you know.
|
|
120
|
-
If you have multiple commands that fit, return the one that fits best. We only want a single command in the reply.
|
|
121
|
-
If the user says that the last command was not right, try to return the next best fit based on the conversation history with the user.
|
|
122
|
-
|
|
123
|
-
If there are no more command ids that seem to fit, return a response of \`"type": "no-command"\` explaining the situation.
|
|
124
|
-
|
|
125
|
-
Here are the known Theia commands:
|
|
126
|
-
|
|
127
|
-
Begin List:
|
|
128
|
-
{{command-ids}}
|
|
129
|
-
End List
|
|
130
|
-
|
|
131
|
-
You may only use commands from this list when responding with \`"type": "theia-command"\`.
|
|
132
|
-
Do not come up with command ids that are not in this list.
|
|
133
|
-
If you need to do this, use the \`"type": "no-command"\`. instead
|
|
134
|
-
|
|
135
|
-
## Custom Handlers
|
|
136
|
-
|
|
137
|
-
If the user asks for a command that is not a Theia command, return a response with \`"type": "custom-handler"\`.
|
|
138
|
-
|
|
139
|
-
## Other Cases
|
|
140
|
-
|
|
141
|
-
In all other cases, return a reply of \`"type": "no-command"\`.
|
|
142
|
-
|
|
143
|
-
# Examples of Invalid Responses
|
|
144
|
-
|
|
145
|
-
## Invalid Response Example 1
|
|
146
|
-
|
|
147
|
-
This example is invalid because it returns text and two commands.
|
|
148
|
-
Only one command should be replied, and it must be parseable JSON.
|
|
149
|
-
|
|
150
|
-
### The Example
|
|
151
|
-
|
|
152
|
-
Yes, there are a few more theme-related commands. Here is another one:
|
|
153
|
-
|
|
154
|
-
\`\`\`json
|
|
155
|
-
{
|
|
156
|
-
"type": "theia-command",
|
|
157
|
-
"commandId": "workbench.action.selectIconTheme"
|
|
158
|
-
}
|
|
159
|
-
\`\`\`
|
|
160
|
-
|
|
161
|
-
And another one:
|
|
162
|
-
|
|
163
|
-
\`\`\`json
|
|
164
|
-
{
|
|
165
|
-
"type": "theia-command",
|
|
166
|
-
"commandId": "core.close.right.tabs"
|
|
167
|
-
}
|
|
168
|
-
\`\`\`
|
|
169
|
-
|
|
170
|
-
## Invalid Response Example 2
|
|
171
|
-
|
|
172
|
-
The following example is invalid because it only returns the command id and is not parseable JSON:
|
|
173
|
-
|
|
174
|
-
### The Example
|
|
175
|
-
|
|
176
|
-
workbench.action.selectIconTheme
|
|
177
|
-
|
|
178
|
-
## Invalid Response Example 3
|
|
179
|
-
|
|
180
|
-
The following example is invalid because it returns a message with the command id. We need JSON objects based on the above rules.
|
|
181
|
-
Do not respond like this in any case! We need a command of \`"type": "theia-command"\`.
|
|
182
|
-
|
|
183
|
-
The expected response would be:
|
|
184
|
-
\`\`\`json
|
|
185
|
-
{
|
|
186
|
-
"type": "theia-command",
|
|
187
|
-
"commandId": "core.close.right.tabs"
|
|
188
|
-
}
|
|
189
|
-
\`\`\`
|
|
190
|
-
|
|
191
|
-
### The Example
|
|
192
|
-
|
|
193
|
-
I found this command that might help you: core.close.right.tabs
|
|
194
|
-
|
|
195
|
-
## Invalid Response Example 4
|
|
196
|
-
|
|
197
|
-
The following example is invalid because it has an explanation string before the JSON.
|
|
198
|
-
We only want the JSON!
|
|
199
|
-
|
|
200
|
-
### The Example
|
|
201
|
-
|
|
202
|
-
You can toggle high contrast mode with this command:
|
|
203
|
-
|
|
204
|
-
\`\`\`json
|
|
205
|
-
{
|
|
206
|
-
"type": "theia-command",
|
|
207
|
-
"commandId": "editor.action.toggleHighContrast"
|
|
208
|
-
}
|
|
209
|
-
\`\`\`
|
|
210
|
-
|
|
211
|
-
## Invalid Response Example 5
|
|
212
|
-
|
|
213
|
-
The following example is invalid because it explains that no command was found.
|
|
214
|
-
We want a response of \`"type": "no-command"\` and have the message there.
|
|
215
|
-
|
|
216
|
-
### The Example
|
|
217
|
-
|
|
218
|
-
There is no specific command available to "open the windows" in the provided Theia command list.
|
|
219
|
-
|
|
220
|
-
## Invalid Response Example 6
|
|
221
|
-
|
|
222
|
-
In this example we were using the following theia id command list:
|
|
223
|
-
|
|
224
|
-
Begin List:
|
|
225
|
-
container--theia-open-editors-widget: Hello
|
|
226
|
-
foo:toggle-visibility-explorer-view-container--files: Label 1
|
|
227
|
-
foo:toggle-visibility-explorer-view-container--plugin-view: Label 2
|
|
228
|
-
End List
|
|
229
|
-
|
|
230
|
-
The problem is that workbench.action.toggleHighContrast is not in this list.
|
|
231
|
-
theia-command types may only use commandIds from this list.
|
|
232
|
-
This should have been of \`"type": "no-command"\`.
|
|
233
|
-
|
|
234
|
-
### The Example
|
|
235
|
-
|
|
236
|
-
\`\`\`json
|
|
237
|
-
{
|
|
238
|
-
"type": "theia-command",
|
|
239
|
-
"commandId": "workbench.action.toggleHighContrast"
|
|
240
|
-
}
|
|
241
|
-
\`\`\`
|
|
242
|
-
|
|
243
|
-
`};
|
|
244
|
-
|
|
245
|
-
interface ParsedCommand {
|
|
246
|
-
type: 'theia-command' | 'custom-handler' | 'no-command'
|
|
247
|
-
commandId: string;
|
|
248
|
-
arguments?: string[];
|
|
249
|
-
message?: string;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
@injectable()
|
|
253
|
-
export class CommandChatAgent extends AbstractTextToModelParsingChatAgent<ParsedCommand> implements ChatAgent {
|
|
254
|
-
@inject(CommandRegistry)
|
|
255
|
-
protected commandRegistry: CommandRegistry;
|
|
256
|
-
@inject(MessageService)
|
|
257
|
-
protected messageService: MessageService;
|
|
258
|
-
readonly name: string;
|
|
259
|
-
readonly description: string;
|
|
260
|
-
readonly variables: string[];
|
|
261
|
-
readonly promptTemplates: PromptTemplate[];
|
|
262
|
-
readonly functions: string[];
|
|
263
|
-
readonly agentSpecificVariables: AgentSpecificVariables[];
|
|
264
|
-
|
|
265
|
-
constructor(
|
|
266
|
-
) {
|
|
267
|
-
super('Command', [{
|
|
268
|
-
purpose: 'command',
|
|
269
|
-
identifier: 'openai/gpt-4o',
|
|
270
|
-
}], 'command');
|
|
271
|
-
this.name = 'Command';
|
|
272
|
-
this.description = 'This agent is aware of all commands that the user can execute within the Theia IDE, the tool that the user is currently working with. \
|
|
273
|
-
Based on the user request, it can find the right command and then let the user execute it.';
|
|
274
|
-
this.variables = [];
|
|
275
|
-
this.promptTemplates = [commandTemplate];
|
|
276
|
-
this.functions = [];
|
|
277
|
-
this.agentSpecificVariables = [{
|
|
278
|
-
name: 'command-ids',
|
|
279
|
-
description: 'The list of available commands in Theia.',
|
|
280
|
-
usedInPrompt: true
|
|
281
|
-
}];
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
protected async getSystemMessageDescription(): Promise<SystemMessageDescription | undefined> {
|
|
285
|
-
const knownCommands: string[] = [];
|
|
286
|
-
for (const command of this.commandRegistry.getAllCommands()) {
|
|
287
|
-
knownCommands.push(`${command.id}: ${command.label}`);
|
|
288
|
-
}
|
|
289
|
-
const systemPrompt = await this.promptService.getPrompt(commandTemplate.id, {
|
|
290
|
-
'command-ids': knownCommands.join('\n')
|
|
291
|
-
});
|
|
292
|
-
if (systemPrompt === undefined) {
|
|
293
|
-
throw new Error('Couldn\'t get system prompt ');
|
|
294
|
-
}
|
|
295
|
-
return SystemMessageDescription.fromResolvedPromptTemplate(systemPrompt);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* @param text the text received from the language model
|
|
300
|
-
* @returns the parsed command if the text contained a valid command.
|
|
301
|
-
* If there was no json in the text, return a no-command response.
|
|
302
|
-
*/
|
|
303
|
-
protected async parseTextResponse(text: string): Promise<ParsedCommand> {
|
|
304
|
-
const jsonMatch = text.match(/(\{[\s\S]*\})/);
|
|
305
|
-
const jsonString = jsonMatch ? jsonMatch[1] : `{
|
|
306
|
-
"type": "no-command",
|
|
307
|
-
"message": "Please try again."
|
|
308
|
-
}`;
|
|
309
|
-
const parsedCommand = JSON.parse(jsonString) as ParsedCommand;
|
|
310
|
-
return parsedCommand;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
protected createResponseContent(parsedCommand: ParsedCommand, request: ChatRequestModelImpl): ChatResponseContent {
|
|
314
|
-
if (parsedCommand.type === 'theia-command') {
|
|
315
|
-
const theiaCommand = this.commandRegistry.getCommand(parsedCommand.commandId);
|
|
316
|
-
if (theiaCommand === undefined) {
|
|
317
|
-
console.error(`No Theia Command with id ${parsedCommand.commandId}`);
|
|
318
|
-
request.cancel();
|
|
319
|
-
}
|
|
320
|
-
const args = parsedCommand.arguments !== undefined &&
|
|
321
|
-
parsedCommand.arguments.length > 0
|
|
322
|
-
? parsedCommand.arguments
|
|
323
|
-
: undefined;
|
|
324
|
-
|
|
325
|
-
return new HorizontalLayoutChatResponseContentImpl([
|
|
326
|
-
new MarkdownChatResponseContentImpl(
|
|
327
|
-
'I found this command that might help you:'
|
|
328
|
-
),
|
|
329
|
-
new CommandChatResponseContentImpl(theiaCommand, undefined, args),
|
|
330
|
-
]);
|
|
331
|
-
} else if (parsedCommand.type === 'custom-handler') {
|
|
332
|
-
const id = `ai-command-${generateUuid()}`;
|
|
333
|
-
const commandArgs = parsedCommand.arguments !== undefined && parsedCommand.arguments.length > 0 ? parsedCommand.arguments : [];
|
|
334
|
-
const args = [id, ...commandArgs];
|
|
335
|
-
const customCallback: CustomCallback = {
|
|
336
|
-
label: 'AI command',
|
|
337
|
-
callback: () => this.commandCallback(...args),
|
|
338
|
-
};
|
|
339
|
-
return new HorizontalLayoutChatResponseContentImpl([
|
|
340
|
-
new MarkdownChatResponseContentImpl(
|
|
341
|
-
'Try executing this:'
|
|
342
|
-
),
|
|
343
|
-
new CommandChatResponseContentImpl(undefined, customCallback, args),
|
|
344
|
-
]);
|
|
345
|
-
} else {
|
|
346
|
-
return new MarkdownChatResponseContentImpl(parsedCommand.message ?? 'Sorry, I can\'t find such a command');
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
protected async commandCallback(...commandArgs: unknown[]): Promise<void> {
|
|
351
|
-
this.messageService.info(`Executing callback with args ${commandArgs.join(', ')}. The first arg is the command id registered for the dynamically registered command.
|
|
352
|
-
The other args are the actual args for the handler.`, 'Got it');
|
|
353
|
-
}
|
|
354
|
-
}
|
|
@@ -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
|
-
}
|