@theia/ai-chat 1.46.0-next.241
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/lib/browser/ai-chat-frontend-module.d.ts +4 -0
- package/lib/browser/ai-chat-frontend-module.d.ts.map +1 -0
- package/lib/browser/ai-chat-frontend-module.js +79 -0
- package/lib/browser/ai-chat-frontend-module.js.map +1 -0
- package/lib/browser/ai-chat-preferences.d.ts +4 -0
- package/lib/browser/ai-chat-preferences.d.ts.map +1 -0
- package/lib/browser/ai-chat-preferences.js +32 -0
- package/lib/browser/ai-chat-preferences.js.map +1 -0
- package/lib/browser/custom-agent-factory.d.ts +4 -0
- package/lib/browser/custom-agent-factory.d.ts.map +1 -0
- package/lib/browser/custom-agent-factory.js +20 -0
- package/lib/browser/custom-agent-factory.js.map +1 -0
- package/lib/browser/custom-agent-frontend-application-contribution.d.ts +13 -0
- package/lib/browser/custom-agent-frontend-application-contribution.d.ts.map +1 -0
- package/lib/browser/custom-agent-frontend-application-contribution.js +82 -0
- package/lib/browser/custom-agent-frontend-application-contribution.js.map +1 -0
- package/lib/browser/frontend-chat-service.d.ts +8 -0
- package/lib/browser/frontend-chat-service.d.ts.map +1 -0
- package/lib/browser/frontend-chat-service.js +67 -0
- package/lib/browser/frontend-chat-service.js.map +1 -0
- package/lib/common/chat-agent-service.d.ts +45 -0
- package/lib/common/chat-agent-service.d.ts.map +1 -0
- package/lib/common/chat-agent-service.js +78 -0
- package/lib/common/chat-agent-service.js.map +1 -0
- package/lib/common/chat-agents-variable-contribution.d.ts +17 -0
- package/lib/common/chat-agents-variable-contribution.d.ts.map +1 -0
- package/lib/common/chat-agents-variable-contribution.js +51 -0
- package/lib/common/chat-agents-variable-contribution.js.map +1 -0
- package/lib/common/chat-agents.d.ts +108 -0
- package/lib/common/chat-agents.d.ts.map +1 -0
- package/lib/common/chat-agents.js +321 -0
- package/lib/common/chat-agents.js.map +1 -0
- package/lib/common/chat-history-entry.d.ts +7 -0
- package/lib/common/chat-history-entry.d.ts.map +1 -0
- package/lib/common/chat-history-entry.js +42 -0
- package/lib/common/chat-history-entry.js.map +1 -0
- package/lib/common/chat-model-util.d.ts +7 -0
- package/lib/common/chat-model-util.d.ts.map +1 -0
- package/lib/common/chat-model-util.js +50 -0
- package/lib/common/chat-model-util.js.map +1 -0
- package/lib/common/chat-model.d.ts +393 -0
- package/lib/common/chat-model.d.ts.map +1 -0
- package/lib/common/chat-model.js +612 -0
- package/lib/common/chat-model.js.map +1 -0
- package/lib/common/chat-request-parser.d.ts +20 -0
- package/lib/common/chat-request-parser.d.ts.map +1 -0
- package/lib/common/chat-request-parser.js +158 -0
- package/lib/common/chat-request-parser.js.map +1 -0
- package/lib/common/chat-request-parser.spec.d.ts +2 -0
- package/lib/common/chat-request-parser.spec.d.ts.map +1 -0
- package/lib/common/chat-request-parser.spec.js +108 -0
- package/lib/common/chat-request-parser.spec.js.map +1 -0
- package/lib/common/chat-service.d.ts +72 -0
- package/lib/common/chat-service.d.ts.map +1 -0
- package/lib/common/chat-service.js +170 -0
- package/lib/common/chat-service.js.map +1 -0
- package/lib/common/command-chat-agents.d.ts +33 -0
- package/lib/common/command-chat-agents.d.ts.map +1 -0
- package/lib/common/command-chat-agents.js +329 -0
- package/lib/common/command-chat-agents.js.map +1 -0
- package/lib/common/custom-chat-agent.d.ts +14 -0
- package/lib/common/custom-chat-agent.d.ts.map +1 -0
- package/lib/common/custom-chat-agent.js +43 -0
- package/lib/common/custom-chat-agent.js.map +1 -0
- package/lib/common/index.d.ts +12 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +30 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/o1-chat-agent.d.ts +13 -0
- package/lib/common/o1-chat-agent.d.ts.map +1 -0
- package/lib/common/o1-chat-agent.js +45 -0
- package/lib/common/o1-chat-agent.js.map +1 -0
- package/lib/common/orchestrator-chat-agent.d.ts +22 -0
- package/lib/common/orchestrator-chat-agent.d.ts.map +1 -0
- package/lib/common/orchestrator-chat-agent.js +167 -0
- package/lib/common/orchestrator-chat-agent.js.map +1 -0
- package/lib/common/parse-contents.d.ts +11 -0
- package/lib/common/parse-contents.d.ts.map +1 -0
- package/lib/common/parse-contents.js +67 -0
- package/lib/common/parse-contents.js.map +1 -0
- package/lib/common/parse-contents.spec.d.ts +9 -0
- package/lib/common/parse-contents.spec.d.ts.map +1 -0
- package/lib/common/parse-contents.spec.js +134 -0
- package/lib/common/parse-contents.spec.js.map +1 -0
- package/lib/common/parsed-chat-request.d.ts +66 -0
- package/lib/common/parsed-chat-request.d.ts.map +1 -0
- package/lib/common/parsed-chat-request.js +83 -0
- package/lib/common/parsed-chat-request.js.map +1 -0
- package/lib/common/response-content-matcher.d.ts +63 -0
- package/lib/common/response-content-matcher.d.ts.map +1 -0
- package/lib/common/response-content-matcher.js +86 -0
- package/lib/common/response-content-matcher.js.map +1 -0
- package/lib/common/universal-chat-agent.d.ts +16 -0
- package/lib/common/universal-chat-agent.d.ts.map +1 -0
- package/lib/common/universal-chat-agent.js +109 -0
- package/lib/common/universal-chat-agent.js.map +1 -0
- package/package.json +54 -0
- package/src/browser/ai-chat-frontend-module.ts +98 -0
- package/src/browser/ai-chat-preferences.ts +32 -0
- package/src/browser/custom-agent-factory.ts +20 -0
- package/src/browser/custom-agent-frontend-application-contribution.ts +73 -0
- package/src/browser/frontend-chat-service.ts +66 -0
- package/src/common/chat-agent-service.ts +100 -0
- package/src/common/chat-agents-variable-contribution.ts +81 -0
- package/src/common/chat-agents.ts +392 -0
- package/src/common/chat-history-entry.ts +47 -0
- package/src/common/chat-model-util.ts +44 -0
- package/src/common/chat-model.ts +889 -0
- package/src/common/chat-request-parser.spec.ts +120 -0
- package/src/common/chat-request-parser.ts +220 -0
- package/src/common/chat-service.ts +236 -0
- package/src/common/command-chat-agents.ts +354 -0
- package/src/common/custom-chat-agent.ts +44 -0
- package/src/common/index.ts +26 -0
- package/src/common/o1-chat-agent.ts +51 -0
- package/src/common/orchestrator-chat-agent.ts +179 -0
- package/src/common/parse-contents.spec.ts +144 -0
- package/src/common/parse-contents.ts +93 -0
- package/src/common/parsed-chat-request.ts +112 -0
- package/src/common/response-content-matcher.ts +103 -0
- package/src/common/universal-chat-agent.ts +117 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ChatRequestModelImpl, ChatResponseContent } from './chat-model';
|
|
2
|
+
export type ResponseContentFactory = (content: string, request: ChatRequestModelImpl) => ChatResponseContent;
|
|
3
|
+
export declare const MarkdownContentFactory: ResponseContentFactory;
|
|
4
|
+
/**
|
|
5
|
+
* Default response content factory used if no other `ResponseContentMatcher` applies.
|
|
6
|
+
* By default, this factory creates a markdown content object.
|
|
7
|
+
*
|
|
8
|
+
* @see MarkdownChatResponseContentImpl
|
|
9
|
+
*/
|
|
10
|
+
export declare class DefaultResponseContentFactory {
|
|
11
|
+
create(content: string, request: ChatRequestModelImpl): ChatResponseContent;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Clients can contribute response content matchers to parse a chat response into specific
|
|
15
|
+
* `ChatResponseContent` instances.
|
|
16
|
+
*/
|
|
17
|
+
export interface ResponseContentMatcher {
|
|
18
|
+
/** Regular expression for finding the start delimiter. */
|
|
19
|
+
start: RegExp;
|
|
20
|
+
/** Regular expression for finding the start delimiter. */
|
|
21
|
+
end: RegExp;
|
|
22
|
+
/**
|
|
23
|
+
* The factory creating a response content from the matching content,
|
|
24
|
+
* from start index to end index of the match (including delimiters).
|
|
25
|
+
*/
|
|
26
|
+
contentFactory: ResponseContentFactory;
|
|
27
|
+
}
|
|
28
|
+
export declare const CodeContentMatcher: ResponseContentMatcher;
|
|
29
|
+
/**
|
|
30
|
+
* Clients can contribute response content matchers to parse the response content.
|
|
31
|
+
*
|
|
32
|
+
* The default chat user interface will collect all contributed matchers and use them
|
|
33
|
+
* to parse the response into structured content parts (e.g. code blocks, markdown blocks),
|
|
34
|
+
* which are then rendered with a `ChatResponsePartRenderer` registered for the respective
|
|
35
|
+
* content part type.
|
|
36
|
+
*
|
|
37
|
+
* ### Example
|
|
38
|
+
* ```ts
|
|
39
|
+
* bind(ResponseContentMatcherProvider).to(MyResponseContentMatcherProvider);
|
|
40
|
+
* ...
|
|
41
|
+
* @injectable()
|
|
42
|
+
* export class MyResponseContentMatcherProvider implements ResponseContentMatcherProvider {
|
|
43
|
+
* readonly matchers: ResponseContentMatcher[] = [{
|
|
44
|
+
* start: /^<command>$/m,
|
|
45
|
+
* end: /^</command>$/m,
|
|
46
|
+
* contentFactory: (content: string) => {
|
|
47
|
+
* const command = content.replace(/^<command>\n|<\/command>$/g, '');
|
|
48
|
+
* return new MyChatResponseContentImpl(command.trim());
|
|
49
|
+
* }
|
|
50
|
+
* }];
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @see ResponseContentMatcher
|
|
55
|
+
*/
|
|
56
|
+
export declare const ResponseContentMatcherProvider: unique symbol;
|
|
57
|
+
export interface ResponseContentMatcherProvider {
|
|
58
|
+
readonly matchers: ResponseContentMatcher[];
|
|
59
|
+
}
|
|
60
|
+
export declare class DefaultResponseContentMatcherProvider implements ResponseContentMatcherProvider {
|
|
61
|
+
readonly matchers: ResponseContentMatcher[];
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=response-content-matcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-content-matcher.d.ts","sourceRoot":"","sources":["../../src/common/response-content-matcher.ts"],"names":[],"mappings":"AAeA,OAAO,EACH,oBAAoB,EACpB,mBAAmB,EAGtB,MAAM,cAAc,CAAC;AAGtB,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,KAAK,mBAAmB,CAAC;AAE7G,eAAO,MAAM,sBAAsB,EAAE,sBACW,CAAC;AAEjD;;;;;GAKG;AACH,qBACa,6BAA6B;IACtC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,mBAAmB;CAG9E;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACnC,0DAA0D;IAC1D,KAAK,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,cAAc,EAAE,sBAAsB,CAAC;CAC1C;AAED,eAAO,MAAM,kBAAkB,EAAE,sBAQhC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,8BAA8B,eAA2C,CAAC;AACvF,MAAM,WAAW,8BAA8B;IAC3C,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,EAAE,CAAC;CAC/C;AAED,qBACa,qCAAsC,YAAW,8BAA8B;IACxF,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,EAAE,CAAwB;CACtE"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultResponseContentMatcherProvider = exports.ResponseContentMatcherProvider = exports.CodeContentMatcher = exports.DefaultResponseContentFactory = exports.MarkdownContentFactory = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
/*
|
|
6
|
+
* Copyright (C) 2024 EclipseSource GmbH.
|
|
7
|
+
*
|
|
8
|
+
* This program and the accompanying materials are made available under the
|
|
9
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
10
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
11
|
+
*
|
|
12
|
+
* This Source Code may also be made available under the following Secondary
|
|
13
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
14
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
15
|
+
* with the GNU Classpath Exception which is available at
|
|
16
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
17
|
+
*
|
|
18
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
19
|
+
*/
|
|
20
|
+
const chat_model_1 = require("./chat-model");
|
|
21
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
22
|
+
const MarkdownContentFactory = (content) => new chat_model_1.MarkdownChatResponseContentImpl(content);
|
|
23
|
+
exports.MarkdownContentFactory = MarkdownContentFactory;
|
|
24
|
+
/**
|
|
25
|
+
* Default response content factory used if no other `ResponseContentMatcher` applies.
|
|
26
|
+
* By default, this factory creates a markdown content object.
|
|
27
|
+
*
|
|
28
|
+
* @see MarkdownChatResponseContentImpl
|
|
29
|
+
*/
|
|
30
|
+
let DefaultResponseContentFactory = class DefaultResponseContentFactory {
|
|
31
|
+
create(content, request) {
|
|
32
|
+
return (0, exports.MarkdownContentFactory)(content, request);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.DefaultResponseContentFactory = DefaultResponseContentFactory;
|
|
36
|
+
exports.DefaultResponseContentFactory = DefaultResponseContentFactory = tslib_1.__decorate([
|
|
37
|
+
(0, inversify_1.injectable)()
|
|
38
|
+
], DefaultResponseContentFactory);
|
|
39
|
+
exports.CodeContentMatcher = {
|
|
40
|
+
start: /^```.*?$/m,
|
|
41
|
+
end: /^```$/m,
|
|
42
|
+
contentFactory: (content) => {
|
|
43
|
+
var _a;
|
|
44
|
+
const language = ((_a = content.match(/^```(\w+)/)) === null || _a === void 0 ? void 0 : _a[1]) || '';
|
|
45
|
+
const code = content.replace(/^```(\w+)\n|```$/g, '');
|
|
46
|
+
return new chat_model_1.CodeChatResponseContentImpl(code.trim(), language);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Clients can contribute response content matchers to parse the response content.
|
|
51
|
+
*
|
|
52
|
+
* The default chat user interface will collect all contributed matchers and use them
|
|
53
|
+
* to parse the response into structured content parts (e.g. code blocks, markdown blocks),
|
|
54
|
+
* which are then rendered with a `ChatResponsePartRenderer` registered for the respective
|
|
55
|
+
* content part type.
|
|
56
|
+
*
|
|
57
|
+
* ### Example
|
|
58
|
+
* ```ts
|
|
59
|
+
* bind(ResponseContentMatcherProvider).to(MyResponseContentMatcherProvider);
|
|
60
|
+
* ...
|
|
61
|
+
* @injectable()
|
|
62
|
+
* export class MyResponseContentMatcherProvider implements ResponseContentMatcherProvider {
|
|
63
|
+
* readonly matchers: ResponseContentMatcher[] = [{
|
|
64
|
+
* start: /^<command>$/m,
|
|
65
|
+
* end: /^</command>$/m,
|
|
66
|
+
* contentFactory: (content: string) => {
|
|
67
|
+
* const command = content.replace(/^<command>\n|<\/command>$/g, '');
|
|
68
|
+
* return new MyChatResponseContentImpl(command.trim());
|
|
69
|
+
* }
|
|
70
|
+
* }];
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @see ResponseContentMatcher
|
|
75
|
+
*/
|
|
76
|
+
exports.ResponseContentMatcherProvider = Symbol('ResponseContentMatcherProvider');
|
|
77
|
+
let DefaultResponseContentMatcherProvider = class DefaultResponseContentMatcherProvider {
|
|
78
|
+
constructor() {
|
|
79
|
+
this.matchers = [exports.CodeContentMatcher];
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
exports.DefaultResponseContentMatcherProvider = DefaultResponseContentMatcherProvider;
|
|
83
|
+
exports.DefaultResponseContentMatcherProvider = DefaultResponseContentMatcherProvider = tslib_1.__decorate([
|
|
84
|
+
(0, inversify_1.injectable)()
|
|
85
|
+
], DefaultResponseContentMatcherProvider);
|
|
86
|
+
//# sourceMappingURL=response-content-matcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-content-matcher.js","sourceRoot":"","sources":["../../src/common/response-content-matcher.ts"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,6CAKsB;AACtB,4DAA0D;AAInD,MAAM,sBAAsB,GAA2B,CAAC,OAAe,EAAE,EAAE,CAC9E,IAAI,4CAA+B,CAAC,OAAO,CAAC,CAAC;AADpC,QAAA,sBAAsB,0BACc;AAEjD;;;;;GAKG;AAEI,IAAM,6BAA6B,GAAnC,MAAM,6BAA6B;IACtC,MAAM,CAAC,OAAe,EAAE,OAA6B;QACjD,OAAO,IAAA,8BAAsB,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;CACJ,CAAA;AAJY,sEAA6B;wCAA7B,6BAA6B;IADzC,IAAA,sBAAU,GAAE;GACA,6BAA6B,CAIzC;AAkBY,QAAA,kBAAkB,GAA2B;IACtD,KAAK,EAAE,WAAW;IAClB,GAAG,EAAE,QAAQ;IACb,cAAc,EAAE,CAAC,OAAe,EAAE,EAAE;;QAChC,MAAM,QAAQ,GAAG,CAAA,MAAA,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,0CAAG,CAAC,CAAC,KAAI,EAAE,CAAC;QACvD,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;QACtD,OAAO,IAAI,wCAA2B,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAC;IAClE,CAAC;CACJ,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACU,QAAA,8BAA8B,GAAG,MAAM,CAAC,gCAAgC,CAAC,CAAC;AAMhF,IAAM,qCAAqC,GAA3C,MAAM,qCAAqC;IAA3C;QACM,aAAQ,GAA6B,CAAC,0BAAkB,CAAC,CAAC;IACvE,CAAC;CAAA,CAAA;AAFY,sFAAqC;gDAArC,qCAAqC;IADjD,IAAA,sBAAU,GAAE;GACA,qCAAqC,CAEjD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
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 const universalTemplateVariant: PromptTemplate;
|
|
6
|
+
export declare class UniversalChatAgent extends AbstractStreamParsingChatAgent implements ChatAgent {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
variables: string[];
|
|
10
|
+
promptTemplates: PromptTemplate[];
|
|
11
|
+
readonly functions: string[];
|
|
12
|
+
readonly agentSpecificVariables: AgentSpecificVariables[];
|
|
13
|
+
constructor();
|
|
14
|
+
protected getSystemMessageDescription(): Promise<SystemMessageDescription | undefined>;
|
|
15
|
+
}
|
|
16
|
+
//# 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,cAuD/B,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,cAItC,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,109 @@
|
|
|
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
|
|
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@theia/ai-chat",
|
|
3
|
+
"version": "1.46.0-next.241+4295c1a8c",
|
|
4
|
+
"description": "Theia - AI Chat Extension",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@theia/ai-core": "1.46.0-next.241+4295c1a8c",
|
|
7
|
+
"@theia/ai-history": "1.46.0-next.241+4295c1a8c",
|
|
8
|
+
"@theia/core": "1.46.0-next.241+4295c1a8c",
|
|
9
|
+
"@theia/filesystem": "1.46.0-next.241+4295c1a8c",
|
|
10
|
+
"@theia/workspace": "1.46.0-next.241+4295c1a8c",
|
|
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.56.0"
|
|
49
|
+
},
|
|
50
|
+
"nyc": {
|
|
51
|
+
"extends": "../../configs/nyc.json"
|
|
52
|
+
},
|
|
53
|
+
"gitHead": "4295c1a8c8b5d23471f274265c798bac9e6baecc"
|
|
54
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
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, AgentService, AIVariableContribution } from '@theia/ai-core/lib/common';
|
|
18
|
+
import { bindContributionProvider } from '@theia/core';
|
|
19
|
+
import { FrontendApplicationContribution, 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 { ChatAgentsVariableContribution } from '../common/chat-agents-variable-contribution';
|
|
31
|
+
import { CommandChatAgent } from '../common/command-chat-agents';
|
|
32
|
+
import { CustomChatAgent } from '../common/custom-chat-agent';
|
|
33
|
+
import { OrchestratorChatAgent, OrchestratorChatAgentId } from '../common/orchestrator-chat-agent';
|
|
34
|
+
import { DefaultResponseContentFactory, DefaultResponseContentMatcherProvider, ResponseContentMatcherProvider } from '../common/response-content-matcher';
|
|
35
|
+
import { UniversalChatAgent } from '../common/universal-chat-agent';
|
|
36
|
+
import { aiChatPreferences } from './ai-chat-preferences';
|
|
37
|
+
import { AICustomAgentsFrontendApplicationContribution } from './custom-agent-frontend-application-contribution';
|
|
38
|
+
import { FrontendChatServiceImpl } from './frontend-chat-service';
|
|
39
|
+
import { CustomAgentFactory } from './custom-agent-factory';
|
|
40
|
+
import { O1ChatAgent } from '../common/o1-chat-agent';
|
|
41
|
+
|
|
42
|
+
export default new ContainerModule(bind => {
|
|
43
|
+
bindContributionProvider(bind, Agent);
|
|
44
|
+
bindContributionProvider(bind, ChatAgent);
|
|
45
|
+
|
|
46
|
+
bind(ChatAgentServiceImpl).toSelf().inSingletonScope();
|
|
47
|
+
bind(ChatAgentService).toService(ChatAgentServiceImpl);
|
|
48
|
+
bind(DefaultChatAgentId).toConstantValue({ id: OrchestratorChatAgentId });
|
|
49
|
+
|
|
50
|
+
bindContributionProvider(bind, ResponseContentMatcherProvider);
|
|
51
|
+
bind(DefaultResponseContentMatcherProvider).toSelf().inSingletonScope();
|
|
52
|
+
bind(ResponseContentMatcherProvider).toService(DefaultResponseContentMatcherProvider);
|
|
53
|
+
bind(DefaultResponseContentFactory).toSelf().inSingletonScope();
|
|
54
|
+
|
|
55
|
+
bind(AIVariableContribution).to(ChatAgentsVariableContribution).inSingletonScope();
|
|
56
|
+
|
|
57
|
+
bind(ChatRequestParserImpl).toSelf().inSingletonScope();
|
|
58
|
+
bind(ChatRequestParser).toService(ChatRequestParserImpl);
|
|
59
|
+
|
|
60
|
+
bind(FrontendChatServiceImpl).toSelf().inSingletonScope();
|
|
61
|
+
bind(ChatService).toService(FrontendChatServiceImpl);
|
|
62
|
+
|
|
63
|
+
bind(OrchestratorChatAgent).toSelf().inSingletonScope();
|
|
64
|
+
bind(Agent).toService(OrchestratorChatAgent);
|
|
65
|
+
bind(ChatAgent).toService(OrchestratorChatAgent);
|
|
66
|
+
|
|
67
|
+
bind(O1ChatAgent).toSelf().inSingletonScope();
|
|
68
|
+
bind(Agent).toService(O1ChatAgent);
|
|
69
|
+
bind(ChatAgent).toService(O1ChatAgent);
|
|
70
|
+
|
|
71
|
+
bind(UniversalChatAgent).toSelf().inSingletonScope();
|
|
72
|
+
bind(Agent).toService(UniversalChatAgent);
|
|
73
|
+
bind(ChatAgent).toService(UniversalChatAgent);
|
|
74
|
+
|
|
75
|
+
bind(CommandChatAgent).toSelf().inSingletonScope();
|
|
76
|
+
bind(Agent).toService(CommandChatAgent);
|
|
77
|
+
bind(ChatAgent).toService(CommandChatAgent);
|
|
78
|
+
|
|
79
|
+
bind(PreferenceContribution).toConstantValue({ schema: aiChatPreferences });
|
|
80
|
+
|
|
81
|
+
bind(CustomChatAgent).toSelf();
|
|
82
|
+
bind(CustomAgentFactory).toFactory<CustomChatAgent, [string, string, string, string, string]>(
|
|
83
|
+
ctx => (id: string, name: string, description: string, prompt: string, defaultLLM: string) => {
|
|
84
|
+
const agent = ctx.container.get<CustomChatAgent>(CustomChatAgent);
|
|
85
|
+
agent.id = id;
|
|
86
|
+
agent.name = name;
|
|
87
|
+
agent.description = description;
|
|
88
|
+
agent.prompt = prompt;
|
|
89
|
+
agent.languageModelRequirements = [{
|
|
90
|
+
purpose: 'chat',
|
|
91
|
+
identifier: defaultLLM,
|
|
92
|
+
}];
|
|
93
|
+
ctx.container.get<ChatAgentService>(ChatAgentService).registerChatAgent(agent);
|
|
94
|
+
ctx.container.get<AgentService>(AgentService).registerAgent(agent);
|
|
95
|
+
return agent;
|
|
96
|
+
});
|
|
97
|
+
bind(FrontendApplicationContribution).to(AICustomAgentsFrontendApplicationContribution).inSingletonScope();
|
|
98
|
+
});
|
|
@@ -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,20 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { CustomChatAgent } from '../common';
|
|
18
|
+
|
|
19
|
+
export const CustomAgentFactory = Symbol('CustomAgentFactory');
|
|
20
|
+
export type CustomAgentFactory = (id: string, name: string, description: string, prompt: string, defaultLLM: string) => CustomChatAgent;
|
|
@@ -0,0 +1,73 @@
|
|
|
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 { AgentService, CustomAgentDescription, PromptCustomizationService } from '@theia/ai-core';
|
|
18
|
+
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
|
|
19
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
20
|
+
import { ChatAgentService } from '../common';
|
|
21
|
+
import { CustomAgentFactory } from './custom-agent-factory';
|
|
22
|
+
|
|
23
|
+
@injectable()
|
|
24
|
+
export class AICustomAgentsFrontendApplicationContribution implements FrontendApplicationContribution {
|
|
25
|
+
@inject(CustomAgentFactory)
|
|
26
|
+
protected readonly customAgentFactory: CustomAgentFactory;
|
|
27
|
+
|
|
28
|
+
@inject(PromptCustomizationService)
|
|
29
|
+
protected readonly customizationService: PromptCustomizationService;
|
|
30
|
+
|
|
31
|
+
@inject(AgentService)
|
|
32
|
+
private readonly agentService: AgentService;
|
|
33
|
+
|
|
34
|
+
@inject(ChatAgentService)
|
|
35
|
+
private readonly chatAgentService: ChatAgentService;
|
|
36
|
+
|
|
37
|
+
private knownCustomAgents: Map<string, CustomAgentDescription> = new Map();
|
|
38
|
+
onStart(): void {
|
|
39
|
+
this.customizationService?.getCustomAgents().then(customAgents => {
|
|
40
|
+
customAgents.forEach(agent => {
|
|
41
|
+
this.customAgentFactory(agent.id, agent.name, agent.description, agent.prompt, agent.defaultLLM);
|
|
42
|
+
this.knownCustomAgents.set(agent.id, agent);
|
|
43
|
+
});
|
|
44
|
+
}).catch(e => {
|
|
45
|
+
console.error('Failed to load custom agents', e);
|
|
46
|
+
});
|
|
47
|
+
this.customizationService?.onDidChangeCustomAgents(() => {
|
|
48
|
+
this.customizationService?.getCustomAgents().then(customAgents => {
|
|
49
|
+
const customAgentsToAdd = customAgents.filter(agent =>
|
|
50
|
+
!this.knownCustomAgents.has(agent.id) || !CustomAgentDescription.equals(this.knownCustomAgents.get(agent.id)!, agent));
|
|
51
|
+
const customAgentIdsToRemove = [...this.knownCustomAgents.values()].filter(agent =>
|
|
52
|
+
!customAgents.find(a => CustomAgentDescription.equals(a, agent))).map(a => a.id);
|
|
53
|
+
|
|
54
|
+
// delete first so we don't have to deal with the case where we add and remove the same agentId
|
|
55
|
+
customAgentIdsToRemove.forEach(id => {
|
|
56
|
+
this.chatAgentService.unregisterChatAgent(id);
|
|
57
|
+
this.agentService.unregisterAgent(id);
|
|
58
|
+
this.knownCustomAgents.delete(id);
|
|
59
|
+
});
|
|
60
|
+
customAgentsToAdd
|
|
61
|
+
.forEach(agent => {
|
|
62
|
+
this.customAgentFactory(agent.id, agent.name, agent.description, agent.prompt, agent.defaultLLM);
|
|
63
|
+
this.knownCustomAgents.set(agent.id, agent);
|
|
64
|
+
});
|
|
65
|
+
}).catch(e => {
|
|
66
|
+
console.error('Failed to load custom agents', e);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
onStop(): void {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -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
|
+
}
|