@theia/ai-chat 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.
Files changed (77) hide show
  1. package/README.md +30 -0
  2. package/lib/browser/ai-chat-frontend-module.d.ts +4 -0
  3. package/lib/browser/ai-chat-frontend-module.d.ts.map +1 -0
  4. package/lib/browser/ai-chat-frontend-module.js +51 -0
  5. package/lib/browser/ai-chat-frontend-module.js.map +1 -0
  6. package/lib/browser/ai-chat-preferences.d.ts +4 -0
  7. package/lib/browser/ai-chat-preferences.d.ts.map +1 -0
  8. package/lib/browser/ai-chat-preferences.js +32 -0
  9. package/lib/browser/ai-chat-preferences.js.map +1 -0
  10. package/lib/browser/frontend-chat-service.d.ts +8 -0
  11. package/lib/browser/frontend-chat-service.d.ts.map +1 -0
  12. package/lib/browser/frontend-chat-service.js +67 -0
  13. package/lib/browser/frontend-chat-service.js.map +1 -0
  14. package/lib/common/chat-agent-service.d.ts +34 -0
  15. package/lib/common/chat-agent-service.d.ts.map +1 -0
  16. package/lib/common/chat-agent-service.js +75 -0
  17. package/lib/common/chat-agent-service.js.map +1 -0
  18. package/lib/common/chat-agents-variable-contribution.d.ts +17 -0
  19. package/lib/common/chat-agents-variable-contribution.d.ts.map +1 -0
  20. package/lib/common/chat-agents-variable-contribution.js +51 -0
  21. package/lib/common/chat-agents-variable-contribution.js.map +1 -0
  22. package/lib/common/chat-agents.d.ts +86 -0
  23. package/lib/common/chat-agents.d.ts.map +1 -0
  24. package/lib/common/chat-agents.js +307 -0
  25. package/lib/common/chat-agents.js.map +1 -0
  26. package/lib/common/chat-model.d.ts +319 -0
  27. package/lib/common/chat-model.d.ts.map +1 -0
  28. package/lib/common/chat-model.js +527 -0
  29. package/lib/common/chat-model.js.map +1 -0
  30. package/lib/common/chat-request-parser.d.ts +20 -0
  31. package/lib/common/chat-request-parser.d.ts.map +1 -0
  32. package/lib/common/chat-request-parser.js +158 -0
  33. package/lib/common/chat-request-parser.js.map +1 -0
  34. package/lib/common/chat-request-parser.spec.d.ts +2 -0
  35. package/lib/common/chat-request-parser.spec.d.ts.map +1 -0
  36. package/lib/common/chat-request-parser.spec.js +108 -0
  37. package/lib/common/chat-request-parser.spec.js.map +1 -0
  38. package/lib/common/chat-service.d.ts +72 -0
  39. package/lib/common/chat-service.d.ts.map +1 -0
  40. package/lib/common/chat-service.js +170 -0
  41. package/lib/common/chat-service.js.map +1 -0
  42. package/lib/common/command-chat-agents.d.ts +33 -0
  43. package/lib/common/command-chat-agents.d.ts.map +1 -0
  44. package/lib/common/command-chat-agents.js +327 -0
  45. package/lib/common/command-chat-agents.js.map +1 -0
  46. package/lib/common/index.d.ts +10 -0
  47. package/lib/common/index.d.ts.map +1 -0
  48. package/lib/common/index.js +28 -0
  49. package/lib/common/index.js.map +1 -0
  50. package/lib/common/orchestrator-chat-agent.d.ts +22 -0
  51. package/lib/common/orchestrator-chat-agent.d.ts.map +1 -0
  52. package/lib/common/orchestrator-chat-agent.js +140 -0
  53. package/lib/common/orchestrator-chat-agent.js.map +1 -0
  54. package/lib/common/parsed-chat-request.d.ts +66 -0
  55. package/lib/common/parsed-chat-request.d.ts.map +1 -0
  56. package/lib/common/parsed-chat-request.js +83 -0
  57. package/lib/common/parsed-chat-request.js.map +1 -0
  58. package/lib/common/universal-chat-agent.d.ts +15 -0
  59. package/lib/common/universal-chat-agent.d.ts.map +1 -0
  60. package/lib/common/universal-chat-agent.js +102 -0
  61. package/lib/common/universal-chat-agent.js.map +1 -0
  62. package/package.json +54 -0
  63. package/src/browser/ai-chat-frontend-module.ts +66 -0
  64. package/src/browser/ai-chat-preferences.ts +32 -0
  65. package/src/browser/frontend-chat-service.ts +66 -0
  66. package/src/common/chat-agent-service.ts +85 -0
  67. package/src/common/chat-agents-variable-contribution.ts +81 -0
  68. package/src/common/chat-agents.ts +384 -0
  69. package/src/common/chat-model.ts +776 -0
  70. package/src/common/chat-request-parser.spec.ts +120 -0
  71. package/src/common/chat-request-parser.ts +220 -0
  72. package/src/common/chat-service.ts +236 -0
  73. package/src/common/command-chat-agents.ts +352 -0
  74. package/src/common/index.ts +24 -0
  75. package/src/common/orchestrator-chat-agent.ts +151 -0
  76. package/src/common/parsed-chat-request.ts +112 -0
  77. package/src/common/universal-chat-agent.ts +109 -0
@@ -0,0 +1,83 @@
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
+ /*---------------------------------------------------------------------------------------------
18
+ * Copyright (c) Microsoft Corporation. All rights reserved.
19
+ * Licensed under the MIT License. See License.txt in the project root for license information.
20
+ *--------------------------------------------------------------------------------------------*/
21
+ // Partially copied from https://github.com/microsoft/vscode/blob/a2cab7255c0df424027be05d58e1b7b941f4ea60/src/vs/workbench/contrib/chat/common/chatParserTypes.ts
22
+ // Partially copied from https://github.com/microsoft/vscode/blob/a2cab7255c0df424027be05d58e1b7b941f4ea60/src/vs/editor/common/core/offsetRange.ts
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.ParsedChatRequestAgentPart = exports.ParsedChatRequestFunctionPart = exports.ParsedChatRequestVariablePart = exports.ParsedChatRequestTextPart = exports.chatSubcommandLeader = exports.chatFunctionLeader = exports.chatAgentLeader = exports.chatVariableLeader = void 0;
25
+ const ai_core_1 = require("@theia/ai-core");
26
+ exports.chatVariableLeader = '#';
27
+ exports.chatAgentLeader = '@';
28
+ exports.chatFunctionLeader = '~';
29
+ exports.chatSubcommandLeader = '/';
30
+ class ParsedChatRequestTextPart {
31
+ constructor(range, text) {
32
+ this.range = range;
33
+ this.text = text;
34
+ }
35
+ get promptText() {
36
+ return this.text;
37
+ }
38
+ }
39
+ exports.ParsedChatRequestTextPart = ParsedChatRequestTextPart;
40
+ class ParsedChatRequestVariablePart {
41
+ constructor(range, variableName, variableArg) {
42
+ this.range = range;
43
+ this.variableName = variableName;
44
+ this.variableArg = variableArg;
45
+ }
46
+ get text() {
47
+ const argPart = this.variableArg ? `:${this.variableArg}` : '';
48
+ return `${exports.chatVariableLeader}${this.variableName}${argPart}`;
49
+ }
50
+ get promptText() {
51
+ var _a, _b;
52
+ return (_b = (_a = this.resolution) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : this.text;
53
+ }
54
+ }
55
+ exports.ParsedChatRequestVariablePart = ParsedChatRequestVariablePart;
56
+ class ParsedChatRequestFunctionPart {
57
+ constructor(range, toolRequest) {
58
+ this.range = range;
59
+ this.toolRequest = toolRequest;
60
+ }
61
+ get text() {
62
+ return `${exports.chatFunctionLeader}${this.toolRequest.id}`;
63
+ }
64
+ get promptText() {
65
+ return (0, ai_core_1.toolRequestToPromptText)(this.toolRequest);
66
+ }
67
+ }
68
+ exports.ParsedChatRequestFunctionPart = ParsedChatRequestFunctionPart;
69
+ class ParsedChatRequestAgentPart {
70
+ constructor(range, agentId, agentName) {
71
+ this.range = range;
72
+ this.agentId = agentId;
73
+ this.agentName = agentName;
74
+ }
75
+ get text() {
76
+ return `${exports.chatAgentLeader}${this.agentName}`;
77
+ }
78
+ get promptText() {
79
+ return '';
80
+ }
81
+ }
82
+ exports.ParsedChatRequestAgentPart = ParsedChatRequestAgentPart;
83
+ //# sourceMappingURL=parsed-chat-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parsed-chat-request.js","sourceRoot":"","sources":["../../src/common/parsed-chat-request.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;AAChF;;;gGAGgG;AAChG,kKAAkK;AAClK,mJAAmJ;;;AAEnJ,4CAAsG;AAGzF,QAAA,kBAAkB,GAAG,GAAG,CAAC;AACzB,QAAA,eAAe,GAAG,GAAG,CAAC;AACtB,QAAA,kBAAkB,GAAG,GAAG,CAAC;AACzB,QAAA,oBAAoB,GAAG,GAAG,CAAC;AAgCxC,MAAa,yBAAyB;IAGlC,YAAqB,KAAkB,EAAW,IAAY;QAAzC,UAAK,GAAL,KAAK,CAAa;QAAW,SAAI,GAAJ,IAAI,CAAQ;IAAI,CAAC;IAEnE,IAAI,UAAU;QACV,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;CACJ;AARD,8DAQC;AAED,MAAa,6BAA6B;IAKtC,YAAqB,KAAkB,EAAW,YAAoB,EAAW,WAA+B;QAA3F,UAAK,GAAL,KAAK,CAAa;QAAW,iBAAY,GAAZ,YAAY,CAAQ;QAAW,gBAAW,GAAX,WAAW,CAAoB;IAAI,CAAC;IAErH,IAAI,IAAI;QACJ,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/D,OAAO,GAAG,0BAAkB,GAAG,IAAI,CAAC,YAAY,GAAG,OAAO,EAAE,CAAC;IACjE,CAAC;IAED,IAAI,UAAU;;QACV,OAAO,MAAA,MAAA,IAAI,CAAC,UAAU,0CAAE,KAAK,mCAAI,IAAI,CAAC,IAAI,CAAC;IAC/C,CAAC;CACJ;AAfD,sEAeC;AAED,MAAa,6BAA6B;IAEtC,YAAqB,KAAkB,EAAW,WAAwB;QAArD,UAAK,GAAL,KAAK,CAAa;QAAW,gBAAW,GAAX,WAAW,CAAa;IAAI,CAAC;IAE/E,IAAI,IAAI;QACJ,OAAO,GAAG,0BAAkB,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC;IACzD,CAAC;IAED,IAAI,UAAU;QACV,OAAO,IAAA,iCAAuB,EAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACrD,CAAC;CACJ;AAXD,sEAWC;AAED,MAAa,0BAA0B;IAEnC,YAAqB,KAAkB,EAAW,OAAe,EAAW,SAAiB;QAAxE,UAAK,GAAL,KAAK,CAAa;QAAW,YAAO,GAAP,OAAO,CAAQ;QAAW,cAAS,GAAT,SAAS,CAAQ;IAAI,CAAC;IAElG,IAAI,IAAI;QACJ,OAAO,GAAG,uBAAe,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IACjD,CAAC;IAED,IAAI,UAAU;QACV,OAAO,EAAE,CAAC;IACd,CAAC;CACJ;AAXD,gEAWC"}
@@ -0,0 +1,15 @@
1
+ import { AgentSpecificVariables } from '@theia/ai-core';
2
+ import { PromptTemplate } from '@theia/ai-core/lib/common';
3
+ import { AbstractStreamParsingChatAgent, ChatAgent, SystemMessageDescription } from './chat-agents';
4
+ export declare const universalTemplate: PromptTemplate;
5
+ export declare class UniversalChatAgent extends AbstractStreamParsingChatAgent implements ChatAgent {
6
+ name: string;
7
+ description: string;
8
+ variables: string[];
9
+ promptTemplates: PromptTemplate[];
10
+ readonly functions: string[];
11
+ readonly agentSpecificVariables: AgentSpecificVariables[];
12
+ constructor();
13
+ protected getSystemMessageDescription(): Promise<SystemMessageDescription | undefined>;
14
+ }
15
+ //# sourceMappingURL=universal-chat-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"universal-chat-agent.d.ts","sourceRoot":"","sources":["../../src/common/universal-chat-agent.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EACJ,cAAc,EAChB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,8BAA8B,EAAE,SAAS,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEpG,eAAO,MAAM,iBAAiB,EAAE,cAqD/B,CAAC;AAEF,qBACa,kBAAmB,SAAQ,8BAA+B,YAAW,SAAS;IACxF,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,eAAe,EAAE,cAAc,EAAE,CAAC;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;IAC7B,QAAQ,CAAC,sBAAsB,EAAE,sBAAsB,EAAE,CAAC;;cAkBjC,2BAA2B,IAAI,OAAO,CAAC,wBAAwB,GAAG,SAAS,CAAC;CAKvG"}
@@ -0,0 +1,102 @@
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.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: `# Instructions
25
+
26
+ You are an AI assistant integrated into the Theia IDE, specifically designed to help software developers by
27
+ providing concise and accurate answers to programming-related questions. Your role is to enhance the
28
+ developer's productivity by offering quick solutions, explanations, and best practices.
29
+ Keep responses short and to the point, focusing on delivering valuable insights, best practices and
30
+ simple solutions.
31
+
32
+ ### Guidelines
33
+
34
+ 1. **Understand Context:**
35
+ - Assess the context of the code or issue when available.
36
+ - Tailor responses to be relevant to the programming language, framework, or tools like Eclipse Theia.
37
+ - Ask clarifying questions if necessary to provide accurate assistance.
38
+
39
+ 2. **Provide Clear Solutions:**
40
+ - Offer direct answers or code snippets that solve the problem or clarify the concept.
41
+ - Avoid lengthy explanations unless necessary for understanding.
42
+
43
+ 3. **Promote Best Practices:**
44
+ - Suggest best practices and common patterns relevant to the question.
45
+ - Provide links to official documentation for further reading when applicable.
46
+
47
+ 4. **Support Multiple Languages and Tools:**
48
+ - Be familiar with popular programming languages, frameworks, IDEs like Eclipse Theia, and command-line tools.
49
+ - Adapt advice based on the language, environment, or tools specified by the developer.
50
+
51
+ 5. **Facilitate Learning:**
52
+ - Encourage learning by explaining why a solution works or why a particular approach is recommended.
53
+ - Keep explanations concise and educational.
54
+
55
+ 6. **Maintain Professional Tone:**
56
+ - Communicate in a friendly, professional manner.
57
+ - Use technical jargon appropriately, ensuring clarity for the target audience.
58
+
59
+ 7. **Stay on Topic:**
60
+ - Limit responses strictly to topics related to software development, frameworks, Eclipse Theia, terminal usage, and relevant technologies.
61
+ - Politely decline to answer questions unrelated to these areas by saying, "I'm here to assist with programming-related questions.
62
+ For other topics, please refer to a specialized source."
63
+
64
+ ### Example Interactions
65
+
66
+ - **Question:** "What's the difference between \`let\` and \`var\` in JavaScript?"
67
+ **Answer:** "\`let\` is block-scoped, while \`var\` is function-scoped. Prefer \`let\` to avoid scope-related bugs."
68
+
69
+ - **Question:** "How do I handle exceptions in Java?"
70
+ **Answer:** "Use try-catch blocks: \`\`\`java try { /* code */ } catch (ExceptionType e) { /* handle exception */ }\`\`\`."
71
+
72
+ - **Question:** "What is the capital of France?"
73
+ **Answer:** "I'm here to assist with programming-related queries. For other topics, please refer to a specialized source."
74
+ `
75
+ };
76
+ let UniversalChatAgent = class UniversalChatAgent extends chat_agents_1.AbstractStreamParsingChatAgent {
77
+ constructor() {
78
+ super('Universal', [{
79
+ purpose: 'chat',
80
+ identifier: 'openai/gpt-4o',
81
+ }], 'chat');
82
+ this.name = 'Universal';
83
+ this.description = 'This agent is designed to help software developers by providing concise and accurate '
84
+ + 'answers to general programming and software development questions. It is also the fall-back for any generic '
85
+ + 'questions the user might ask. The universal agent currently does not have any context by default, i.e. it cannot '
86
+ + 'access the current user context or the workspace.';
87
+ this.variables = [];
88
+ this.promptTemplates = [exports.universalTemplate];
89
+ this.functions = [];
90
+ this.agentSpecificVariables = [];
91
+ }
92
+ async getSystemMessageDescription() {
93
+ const resolvedPrompt = await this.promptService.getPrompt(exports.universalTemplate.id);
94
+ return resolvedPrompt ? chat_agents_1.SystemMessageDescription.fromResolvedPromptTemplate(resolvedPrompt) : undefined;
95
+ }
96
+ };
97
+ exports.UniversalChatAgent = UniversalChatAgent;
98
+ exports.UniversalChatAgent = UniversalChatAgent = tslib_1.__decorate([
99
+ (0, inversify_1.injectable)(),
100
+ tslib_1.__metadata("design:paramtypes", [])
101
+ ], UniversalChatAgent);
102
+ //# sourceMappingURL=universal-chat-agent.js.map
@@ -0,0 +1 @@
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkDZ;CACA,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,CAAC,CAAC;QAC3C,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"}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@theia/ai-chat",
3
+ "version": "1.54.0",
4
+ "description": "Theia - AI Chat Extension",
5
+ "dependencies": {
6
+ "@theia/ai-core": "1.54.0",
7
+ "@theia/ai-history": "1.54.0",
8
+ "@theia/core": "1.54.0",
9
+ "@theia/filesystem": "1.54.0",
10
+ "@theia/workspace": "1.54.0",
11
+ "minimatch": "^5.1.0",
12
+ "tslib": "^2.6.2"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "main": "lib/common",
18
+ "theiaExtensions": [
19
+ {
20
+ "frontend": "lib/browser/ai-chat-frontend-module"
21
+ }
22
+ ],
23
+ "keywords": [
24
+ "theia-extension"
25
+ ],
26
+ "license": "EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/eclipse-theia/theia.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/eclipse-theia/theia/issues"
33
+ },
34
+ "homepage": "https://github.com/eclipse-theia/theia",
35
+ "files": [
36
+ "lib",
37
+ "src"
38
+ ],
39
+ "scripts": {
40
+ "build": "theiaext build",
41
+ "clean": "theiaext clean",
42
+ "compile": "theiaext compile",
43
+ "lint": "theiaext lint",
44
+ "test": "theiaext test",
45
+ "watch": "theiaext watch"
46
+ },
47
+ "devDependencies": {
48
+ "@theia/ext-scripts": "1.54.0"
49
+ },
50
+ "nyc": {
51
+ "extends": "../../configs/nyc.json"
52
+ },
53
+ "gitHead": "8fb36a237db744cff6e78eaff1481e1f36bb7a69"
54
+ }
@@ -0,0 +1,66 @@
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 { Agent, AIVariableContribution } from '@theia/ai-core/lib/common';
18
+ import { bindContributionProvider } from '@theia/core';
19
+ import { PreferenceContribution } from '@theia/core/lib/browser';
20
+ import { ContainerModule } from '@theia/core/shared/inversify';
21
+ import {
22
+ ChatAgent,
23
+ ChatAgentService,
24
+ ChatAgentServiceImpl,
25
+ ChatRequestParser,
26
+ ChatRequestParserImpl,
27
+ ChatService,
28
+ DefaultChatAgentId
29
+ } from '../common';
30
+ import { CommandChatAgent } from '../common/command-chat-agents';
31
+ import { OrchestratorChatAgent, OrchestratorChatAgentId } from '../common/orchestrator-chat-agent';
32
+ import { UniversalChatAgent } from '../common/universal-chat-agent';
33
+ import { aiChatPreferences } from './ai-chat-preferences';
34
+ import { ChatAgentsVariableContribution } from '../common/chat-agents-variable-contribution';
35
+ import { FrontendChatServiceImpl } from './frontend-chat-service';
36
+
37
+ export default new ContainerModule(bind => {
38
+ bindContributionProvider(bind, Agent);
39
+ bindContributionProvider(bind, ChatAgent);
40
+
41
+ bind(ChatAgentServiceImpl).toSelf().inSingletonScope();
42
+ bind(ChatAgentService).toService(ChatAgentServiceImpl);
43
+ bind(DefaultChatAgentId).toConstantValue({ id: OrchestratorChatAgentId });
44
+
45
+ bind(AIVariableContribution).to(ChatAgentsVariableContribution).inSingletonScope();
46
+
47
+ bind(ChatRequestParserImpl).toSelf().inSingletonScope();
48
+ bind(ChatRequestParser).toService(ChatRequestParserImpl);
49
+
50
+ bind(FrontendChatServiceImpl).toSelf().inSingletonScope();
51
+ bind(ChatService).toService(FrontendChatServiceImpl);
52
+
53
+ bind(OrchestratorChatAgent).toSelf().inSingletonScope();
54
+ bind(Agent).toService(OrchestratorChatAgent);
55
+ bind(ChatAgent).toService(OrchestratorChatAgent);
56
+
57
+ bind(UniversalChatAgent).toSelf().inSingletonScope();
58
+ bind(Agent).toService(UniversalChatAgent);
59
+ bind(ChatAgent).toService(UniversalChatAgent);
60
+
61
+ bind(CommandChatAgent).toSelf().inSingletonScope();
62
+ bind(Agent).toService(CommandChatAgent);
63
+ bind(ChatAgent).toService(CommandChatAgent);
64
+
65
+ bind(PreferenceContribution).toConstantValue({ schema: aiChatPreferences });
66
+ });
@@ -0,0 +1,32 @@
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 { AI_CORE_PREFERENCES_TITLE } from '@theia/ai-core/lib/browser/ai-core-preferences';
18
+ import { PreferenceSchema } from '@theia/core/lib/browser/preferences/preference-contribution';
19
+
20
+ export const DEFAULT_CHAT_AGENT_PREF = 'ai-features.chat.defaultChatAgent';
21
+
22
+ export const aiChatPreferences: PreferenceSchema = {
23
+ type: 'object',
24
+ properties: {
25
+ [DEFAULT_CHAT_AGENT_PREF]: {
26
+ type: 'string',
27
+ description: 'Optional: <agent-name> of the Chat Agent that shall be invoked, if no agent is explicitly mentioned with @<agent-name> in the user query.\
28
+ If no Default Agent is configured, Theia´s defaults will be applied.',
29
+ title: AI_CORE_PREFERENCES_TITLE,
30
+ }
31
+ }
32
+ };
@@ -0,0 +1,66 @@
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 { ChatAgent, ChatServiceImpl, ParsedChatRequest } from '../common';
19
+ import { PreferenceService } from '@theia/core/lib/browser';
20
+ import { DEFAULT_CHAT_AGENT_PREF } from './ai-chat-preferences';
21
+
22
+ @injectable()
23
+ export class FrontendChatServiceImpl extends ChatServiceImpl {
24
+
25
+ @inject(PreferenceService)
26
+ protected preferenceService: PreferenceService;
27
+
28
+ protected override getAgent(parsedRequest: ParsedChatRequest): ChatAgent | undefined {
29
+ const agentPart = this.getMentionedAgent(parsedRequest);
30
+ if (agentPart) {
31
+ return this.chatAgentService.getAgent(agentPart.agentId);
32
+ }
33
+
34
+ const configuredDefaultChatAgent = this.getConfiguredDefaultChatAgent();
35
+ if (configuredDefaultChatAgent) {
36
+ return configuredDefaultChatAgent;
37
+ }
38
+
39
+ if (this.defaultChatAgentId) {
40
+ const defaultAgent = this.chatAgentService.getAgent(this.defaultChatAgentId.id);
41
+ // the default agent could be disabled
42
+ if (defaultAgent) {
43
+ return defaultAgent;
44
+ }
45
+ }
46
+
47
+ // check whether "Universal" is available
48
+ const universalAgent = this.chatAgentService.getAgent('Universal');
49
+ if (universalAgent) {
50
+ return universalAgent;
51
+ }
52
+
53
+ this.logger.warn('No default chat agent is configured or available and the "Universal" Chat Agent is unavailable too. Falling back to first registered agent.');
54
+
55
+ return this.chatAgentService.getAgents()[0] ?? undefined;
56
+ }
57
+
58
+ protected getConfiguredDefaultChatAgent(): ChatAgent | undefined {
59
+ const configuredDefaultChatAgentId = this.preferenceService.get<string>(DEFAULT_CHAT_AGENT_PREF, undefined);
60
+ const configuredDefaultChatAgent = configuredDefaultChatAgentId ? this.chatAgentService.getAgent(configuredDefaultChatAgentId) : undefined;
61
+ if (configuredDefaultChatAgentId && !configuredDefaultChatAgent) {
62
+ this.logger.warn(`The configured default chat agent with id '${configuredDefaultChatAgentId}' does not exist.`);
63
+ }
64
+ return configuredDefaultChatAgent;
65
+ }
66
+ }
@@ -0,0 +1,85 @@
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
+ * Copyright (c) Microsoft Corporation. All rights reserved.
18
+ * Licensed under the MIT License. See License.txt in the project root for license information.
19
+ *--------------------------------------------------------------------------------------------*/
20
+ // Partially copied from https://github.com/microsoft/vscode/blob/a2cab7255c0df424027be05d58e1b7b941f4ea60/src/vs/workbench/contrib/chat/common/chatAgents.ts
21
+
22
+ import { ContributionProvider, ILogger } from '@theia/core';
23
+ import { inject, injectable, named } from '@theia/core/shared/inversify';
24
+ import { ChatAgent } from './chat-agents';
25
+ import { AgentService } from '@theia/ai-core';
26
+
27
+ export const ChatAgentService = Symbol('ChatAgentService');
28
+ /**
29
+ * The ChatAgentService provides access to the available chat agents.
30
+ */
31
+ export interface ChatAgentService {
32
+ /**
33
+ * Returns all available agents.
34
+ */
35
+ getAgents(): ChatAgent[];
36
+ /**
37
+ * Returns the specified agent, if available
38
+ */
39
+ getAgent(id: string): ChatAgent | undefined;
40
+ /**
41
+ * Returns all agents, including disabled ones.
42
+ */
43
+ getAllAgents(): ChatAgent[];
44
+ }
45
+ @injectable()
46
+ export class ChatAgentServiceImpl implements ChatAgentService {
47
+
48
+ @inject(ContributionProvider) @named(ChatAgent)
49
+ protected readonly agentContributions: ContributionProvider<ChatAgent>;
50
+
51
+ @inject(ILogger)
52
+ protected logger: ILogger;
53
+
54
+ @inject(AgentService)
55
+ protected agentService: AgentService;
56
+
57
+ protected _agents: ChatAgent[] = [];
58
+
59
+ protected get agents(): ChatAgent[] {
60
+ // We can't collect the contributions at @postConstruct because this will lead to a circular dependency
61
+ // with chat agents reusing the chat agent service (e.g. orchestrator)
62
+ return [...this.agentContributions.getContributions(), ...this._agents];
63
+ }
64
+
65
+ registerChatAgent(agent: ChatAgent): void {
66
+ this._agents.push(agent);
67
+ }
68
+
69
+ getAgent(id: string): ChatAgent | undefined {
70
+ if (!this._agentIsEnabled(id)) {
71
+ return undefined;
72
+ }
73
+ return this.getAgents().find(agent => agent.id === id);
74
+ }
75
+ getAgents(): ChatAgent[] {
76
+ return this.agents.filter(a => this._agentIsEnabled(a.id));
77
+ }
78
+ getAllAgents(): ChatAgent[] {
79
+ return this.agents;
80
+ }
81
+
82
+ private _agentIsEnabled(id: string): boolean {
83
+ return this.agentService.isEnabled(id);
84
+ }
85
+ }
@@ -0,0 +1,81 @@
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 { MaybePromise } from '@theia/core';
17
+ import { inject, injectable } from '@theia/core/shared/inversify';
18
+ import {
19
+ AIVariable,
20
+ AIVariableContext,
21
+ AIVariableContribution,
22
+ AIVariableResolutionRequest,
23
+ AIVariableResolver,
24
+ AIVariableService,
25
+ ResolvedAIVariable
26
+ } from '../../../ai-core/src/common/variable-service';
27
+ import { ChatAgentService } from './chat-agent-service';
28
+
29
+ export const CHAT_AGENTS_VARIABLE: AIVariable = {
30
+ id: 'chatAgents',
31
+ name: 'chatAgents',
32
+ description: 'Returns the list of chat agents available in the system'
33
+ };
34
+
35
+ export interface ChatAgentDescriptor {
36
+ id: string;
37
+ name: string;
38
+ description: string;
39
+ }
40
+
41
+ @injectable()
42
+ export class ChatAgentsVariableContribution implements AIVariableContribution, AIVariableResolver {
43
+
44
+ @inject(ChatAgentService)
45
+ protected readonly agents: ChatAgentService;
46
+
47
+ registerVariables(service: AIVariableService): void {
48
+ service.registerResolver(CHAT_AGENTS_VARIABLE, this);
49
+ }
50
+
51
+ canResolve(request: AIVariableResolutionRequest, _context: AIVariableContext): MaybePromise<number> {
52
+ if (request.variable.name === CHAT_AGENTS_VARIABLE.name) {
53
+ return 1;
54
+ }
55
+ return -1;
56
+ }
57
+
58
+ async resolve(request: AIVariableResolutionRequest, context: AIVariableContext): Promise<ResolvedAIVariable | undefined> {
59
+ if (request.variable.name === CHAT_AGENTS_VARIABLE.name) {
60
+ return this.resolveAgentsVariable(request);
61
+ }
62
+ }
63
+
64
+ resolveAgentsVariable(_request: AIVariableResolutionRequest): ResolvedAIVariable {
65
+ const agents = this.agents.getAgents().map(agent => ({
66
+ id: agent.id,
67
+ name: agent.name,
68
+ description: agent.description
69
+ }));
70
+ const value = agents.map(agent => prettyPrintInMd(agent)).join('\n');
71
+ return { variable: CHAT_AGENTS_VARIABLE, value };
72
+ }
73
+ }
74
+
75
+ function prettyPrintInMd(agent: { id: string; name: string; description: string; }): string {
76
+ return `- ${agent.id}
77
+ - *ID*: ${agent.id}
78
+ - *Name*: ${agent.name}
79
+ - *Description*: ${agent.description.replace(/\n/g, ' ')}`;
80
+ }
81
+