@theia/ai-core 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/data/prompttemplate.tmLanguage.json +107 -0
- package/lib/browser/ai-activation-service.d.ts +17 -0
- package/lib/browser/ai-activation-service.d.ts.map +1 -0
- package/lib/browser/ai-activation-service.js +63 -0
- package/lib/browser/ai-activation-service.js.map +1 -0
- package/lib/browser/ai-command-handler-factory.d.ts +4 -0
- package/lib/browser/ai-command-handler-factory.d.ts.map +1 -0
- package/lib/browser/ai-command-handler-factory.js +20 -0
- package/lib/browser/ai-command-handler-factory.js.map +1 -0
- package/lib/browser/ai-configuration/agent-configuration-widget.d.ts +28 -0
- package/lib/browser/ai-configuration/agent-configuration-widget.d.ts.map +1 -0
- package/lib/browser/ai-configuration/agent-configuration-widget.js +242 -0
- package/lib/browser/ai-configuration/agent-configuration-widget.js.map +1 -0
- package/lib/browser/ai-configuration/ai-configuration-service.d.ts +13 -0
- package/lib/browser/ai-configuration/ai-configuration-service.d.ts.map +1 -0
- package/lib/browser/ai-configuration/ai-configuration-service.js +44 -0
- package/lib/browser/ai-configuration/ai-configuration-service.js.map +1 -0
- package/lib/browser/ai-configuration/ai-configuration-view-contribution.d.ts +12 -0
- package/lib/browser/ai-configuration/ai-configuration-view-contribution.d.ts.map +1 -0
- package/lib/browser/ai-configuration/ai-configuration-view-contribution.js +41 -0
- package/lib/browser/ai-configuration/ai-configuration-view-contribution.js.map +1 -0
- package/lib/browser/ai-configuration/ai-configuration-widget.d.ts +20 -0
- package/lib/browser/ai-configuration/ai-configuration-widget.d.ts.map +1 -0
- package/lib/browser/ai-configuration/ai-configuration-widget.js +88 -0
- package/lib/browser/ai-configuration/ai-configuration-widget.js.map +1 -0
- package/lib/browser/ai-configuration/language-model-renderer.d.ts +13 -0
- package/lib/browser/ai-configuration/language-model-renderer.d.ts.map +1 -0
- package/lib/browser/ai-configuration/language-model-renderer.js +104 -0
- package/lib/browser/ai-configuration/language-model-renderer.js.map +1 -0
- package/lib/browser/ai-configuration/template-settings-renderer.d.ts +13 -0
- package/lib/browser/ai-configuration/template-settings-renderer.d.ts.map +1 -0
- package/lib/browser/ai-configuration/template-settings-renderer.js +71 -0
- package/lib/browser/ai-configuration/template-settings-renderer.js.map +1 -0
- package/lib/browser/ai-configuration/variable-configuration-widget.d.ts +20 -0
- package/lib/browser/ai-configuration/variable-configuration-widget.d.ts.map +1 -0
- package/lib/browser/ai-configuration/variable-configuration-widget.js +99 -0
- package/lib/browser/ai-configuration/variable-configuration-widget.js.map +1 -0
- package/lib/browser/ai-core-frontend-application-contribution.d.ts +10 -0
- package/lib/browser/ai-core-frontend-application-contribution.d.ts.map +1 -0
- package/lib/browser/ai-core-frontend-application-contribution.js +46 -0
- package/lib/browser/ai-core-frontend-application-contribution.js.map +1 -0
- package/lib/browser/ai-core-frontend-module.d.ts +4 -0
- package/lib/browser/ai-core-frontend-module.d.ts.map +1 -0
- package/lib/browser/ai-core-frontend-module.js +122 -0
- package/lib/browser/ai-core-frontend-module.js.map +1 -0
- package/lib/browser/ai-core-preferences.d.ts +29 -0
- package/lib/browser/ai-core-preferences.d.ts.map +1 -0
- package/lib/browser/ai-core-preferences.js +98 -0
- package/lib/browser/ai-core-preferences.js.map +1 -0
- package/lib/browser/ai-settings-service.d.ts +14 -0
- package/lib/browser/ai-settings-service.d.ts.map +1 -0
- package/lib/browser/ai-settings-service.js +56 -0
- package/lib/browser/ai-settings-service.js.map +1 -0
- package/lib/browser/ai-view-contribution.d.ts +14 -0
- package/lib/browser/ai-view-contribution.d.ts.map +1 -0
- package/lib/browser/ai-view-contribution.js +71 -0
- package/lib/browser/ai-view-contribution.js.map +1 -0
- package/lib/browser/frontend-language-model-registry.d.ts +39 -0
- package/lib/browser/frontend-language-model-registry.d.ts.map +1 -0
- package/lib/browser/frontend-language-model-registry.js +321 -0
- package/lib/browser/frontend-language-model-registry.js.map +1 -0
- package/lib/browser/frontend-prompt-customization-service.d.ts +33 -0
- package/lib/browser/frontend-prompt-customization-service.d.ts.map +1 -0
- package/lib/browser/frontend-prompt-customization-service.js +237 -0
- package/lib/browser/frontend-prompt-customization-service.js.map +1 -0
- package/lib/browser/frontend-variable-service.d.ts +6 -0
- package/lib/browser/frontend-variable-service.d.ts.map +1 -0
- package/lib/browser/frontend-variable-service.js +31 -0
- package/lib/browser/frontend-variable-service.js.map +1 -0
- package/lib/browser/index.d.ts +11 -0
- package/lib/browser/index.d.ts.map +1 -0
- package/lib/browser/index.js +29 -0
- package/lib/browser/index.js.map +1 -0
- package/lib/browser/prompttemplate-contribution.d.ts +29 -0
- package/lib/browser/prompttemplate-contribution.d.ts.map +1 -0
- package/lib/browser/prompttemplate-contribution.js +208 -0
- package/lib/browser/prompttemplate-contribution.js.map +1 -0
- package/lib/browser/theia-variable-contribution.d.ts +13 -0
- package/lib/browser/theia-variable-contribution.d.ts.map +1 -0
- package/lib/browser/theia-variable-contribution.js +64 -0
- package/lib/browser/theia-variable-contribution.js.map +1 -0
- package/lib/common/agent-service.d.ts +66 -0
- package/lib/common/agent-service.d.ts.map +1 -0
- package/lib/common/agent-service.js +92 -0
- package/lib/common/agent-service.js.map +1 -0
- package/lib/common/agent.d.ts +45 -0
- package/lib/common/agent.d.ts.map +1 -0
- package/lib/common/agent.js +20 -0
- package/lib/common/agent.js.map +1 -0
- package/lib/common/agents-variable-contribution.d.ts +19 -0
- package/lib/common/agents-variable-contribution.d.ts.map +1 -0
- package/lib/common/agents-variable-contribution.js +56 -0
- package/lib/common/agents-variable-contribution.js.map +1 -0
- package/lib/common/communication-recording-service.d.ts +29 -0
- package/lib/common/communication-recording-service.d.ts.map +1 -0
- package/lib/common/communication-recording-service.js +20 -0
- package/lib/common/communication-recording-service.js.map +1 -0
- package/lib/common/index.d.ts +16 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +34 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/language-model-delegate.d.ts +24 -0
- package/lib/common/language-model-delegate.d.ts.map +1 -0
- package/lib/common/language-model-delegate.js +26 -0
- package/lib/common/language-model-delegate.js.map +1 -0
- package/lib/common/language-model-util.d.ts +16 -0
- package/lib/common/language-model-util.d.ts.map +1 -0
- package/lib/common/language-model-util.js +92 -0
- package/lib/common/language-model-util.js.map +1 -0
- package/lib/common/language-model.d.ts +144 -0
- package/lib/common/language-model.d.ts.map +1 -0
- package/lib/common/language-model.js +142 -0
- package/lib/common/language-model.js.map +1 -0
- package/lib/common/language-model.spec.d.ts +2 -0
- package/lib/common/language-model.spec.d.ts.map +1 -0
- package/lib/common/language-model.spec.js +62 -0
- package/lib/common/language-model.spec.js.map +1 -0
- package/lib/common/prompt-service-util.d.ts +8 -0
- package/lib/common/prompt-service-util.d.ts.map +1 -0
- package/lib/common/prompt-service-util.js +34 -0
- package/lib/common/prompt-service-util.js.map +1 -0
- package/lib/common/prompt-service.d.ts +161 -0
- package/lib/common/prompt-service.d.ts.map +1 -0
- package/lib/common/prompt-service.js +204 -0
- package/lib/common/prompt-service.js.map +1 -0
- package/lib/common/prompt-service.spec.d.ts +2 -0
- package/lib/common/prompt-service.spec.d.ts.map +1 -0
- package/lib/common/prompt-service.spec.js +254 -0
- package/lib/common/prompt-service.spec.js.map +1 -0
- package/lib/common/protocol.d.ts +7 -0
- package/lib/common/protocol.d.ts.map +1 -0
- package/lib/common/protocol.js +20 -0
- package/lib/common/protocol.js.map +1 -0
- package/lib/common/settings-service.d.ts +23 -0
- package/lib/common/settings-service.d.ts.map +1 -0
- package/lib/common/settings-service.js +5 -0
- package/lib/common/settings-service.js.map +1 -0
- package/lib/common/today-variable-contribution.d.ts +17 -0
- package/lib/common/today-variable-contribution.d.ts.map +1 -0
- package/lib/common/today-variable-contribution.js +48 -0
- package/lib/common/today-variable-contribution.js.map +1 -0
- package/lib/common/tomorrow-variable-contribution.d.ts +17 -0
- package/lib/common/tomorrow-variable-contribution.d.ts.map +1 -0
- package/lib/common/tomorrow-variable-contribution.js +48 -0
- package/lib/common/tomorrow-variable-contribution.js.map +1 -0
- package/lib/common/tool-invocation-registry.d.ts +23 -0
- package/lib/common/tool-invocation-registry.d.ts.map +1 -0
- package/lib/common/tool-invocation-registry.js +72 -0
- package/lib/common/tool-invocation-registry.js.map +1 -0
- package/lib/common/variable-service.d.ts +70 -0
- package/lib/common/variable-service.d.ts.map +1 -0
- package/lib/common/variable-service.js +122 -0
- package/lib/common/variable-service.js.map +1 -0
- package/lib/node/ai-core-backend-module.d.ts +4 -0
- package/lib/node/ai-core-backend-module.d.ts.map +1 -0
- package/lib/node/ai-core-backend-module.js +47 -0
- package/lib/node/ai-core-backend-module.js.map +1 -0
- package/lib/node/backend-language-model-registry.d.ts +12 -0
- package/lib/node/backend-language-model-registry.d.ts.map +1 -0
- package/lib/node/backend-language-model-registry.js +61 -0
- package/lib/node/backend-language-model-registry.js.map +1 -0
- package/lib/node/language-model-frontend-delegate.d.ts +18 -0
- package/lib/node/language-model-frontend-delegate.d.ts.map +1 -0
- package/lib/node/language-model-frontend-delegate.js +100 -0
- package/lib/node/language-model-frontend-delegate.js.map +1 -0
- package/package.json +61 -0
- package/src/browser/ai-activation-service.ts +56 -0
- package/src/browser/ai-command-handler-factory.ts +20 -0
- package/src/browser/ai-configuration/agent-configuration-widget.tsx +324 -0
- package/src/browser/ai-configuration/ai-configuration-service.ts +43 -0
- package/src/browser/ai-configuration/ai-configuration-view-contribution.ts +54 -0
- package/src/browser/ai-configuration/ai-configuration-widget.tsx +80 -0
- package/src/browser/ai-configuration/language-model-renderer.tsx +113 -0
- package/src/browser/ai-configuration/template-settings-renderer.tsx +128 -0
- package/src/browser/ai-configuration/variable-configuration-widget.tsx +110 -0
- package/src/browser/ai-core-frontend-application-contribution.ts +39 -0
- package/src/browser/ai-core-frontend-module.ts +161 -0
- package/src/browser/ai-core-preferences.ts +115 -0
- package/src/browser/ai-settings-service.ts +50 -0
- package/src/browser/ai-view-contribution.ts +77 -0
- package/src/browser/frontend-language-model-registry.ts +405 -0
- package/src/browser/frontend-prompt-customization-service.ts +243 -0
- package/src/browser/frontend-variable-service.ts +26 -0
- package/src/browser/index.ts +26 -0
- package/src/browser/prompttemplate-contribution.ts +252 -0
- package/src/browser/style/index.css +127 -0
- package/src/browser/theia-variable-contribution.ts +58 -0
- package/src/common/agent-service.ts +137 -0
- package/src/common/agent.ts +70 -0
- package/src/common/agents-variable-contribution.ts +64 -0
- package/src/common/communication-recording-service.ts +53 -0
- package/src/common/index.ts +30 -0
- package/src/common/language-model-delegate.ts +45 -0
- package/src/common/language-model-util.ts +84 -0
- package/src/common/language-model.spec.ts +86 -0
- package/src/common/language-model.ts +242 -0
- package/src/common/prompt-service-util.ts +31 -0
- package/src/common/prompt-service.spec.ts +301 -0
- package/src/common/prompt-service.ts +334 -0
- package/src/common/protocol.ts +23 -0
- package/src/common/settings-service.ts +38 -0
- package/src/common/today-variable-contribution.ts +67 -0
- package/src/common/tomorrow-variable-contribution.ts +66 -0
- package/src/common/tool-invocation-registry.ts +79 -0
- package/src/common/variable-service.ts +177 -0
- package/src/node/ai-core-backend-module.ts +83 -0
- package/src/node/backend-language-model-registry.ts +59 -0
- package/src/node/language-model-frontend-delegate.ts +116 -0
|
@@ -0,0 +1,142 @@
|
|
|
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.isModelMatching = exports.DefaultLanguageModelRegistryImpl = exports.LanguageModelRegistry = exports.LanguageModel = exports.LanguageModelMetaData = exports.LanguageModelProvider = exports.isLanguageModelParsedResponse = exports.isLanguageModelStreamResponse = exports.isLanguageModelTextResponse = exports.isLanguageModelRequestMessage = void 0;
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
const core_1 = require("@theia/core");
|
|
21
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
22
|
+
const isLanguageModelRequestMessage = (obj) => !!(obj && typeof obj === 'object' &&
|
|
23
|
+
'type' in obj &&
|
|
24
|
+
typeof obj.type === 'string' &&
|
|
25
|
+
obj.type === 'text' &&
|
|
26
|
+
'query' in obj &&
|
|
27
|
+
typeof obj.query === 'string');
|
|
28
|
+
exports.isLanguageModelRequestMessage = isLanguageModelRequestMessage;
|
|
29
|
+
const isLanguageModelTextResponse = (obj) => !!(obj && typeof obj === 'object' && 'text' in obj && typeof obj.text === 'string');
|
|
30
|
+
exports.isLanguageModelTextResponse = isLanguageModelTextResponse;
|
|
31
|
+
const isLanguageModelStreamResponse = (obj) => !!(obj && typeof obj === 'object' && 'stream' in obj);
|
|
32
|
+
exports.isLanguageModelStreamResponse = isLanguageModelStreamResponse;
|
|
33
|
+
const isLanguageModelParsedResponse = (obj) => !!(obj && typeof obj === 'object' && 'parsed' in obj && 'content' in obj);
|
|
34
|
+
exports.isLanguageModelParsedResponse = isLanguageModelParsedResponse;
|
|
35
|
+
///////////////////////////////////////////
|
|
36
|
+
// Language Model Provider
|
|
37
|
+
///////////////////////////////////////////
|
|
38
|
+
exports.LanguageModelProvider = Symbol('LanguageModelProvider');
|
|
39
|
+
var LanguageModelMetaData;
|
|
40
|
+
(function (LanguageModelMetaData) {
|
|
41
|
+
function is(arg) {
|
|
42
|
+
return (0, core_1.isObject)(arg) && 'id' in arg;
|
|
43
|
+
}
|
|
44
|
+
LanguageModelMetaData.is = is;
|
|
45
|
+
})(LanguageModelMetaData || (exports.LanguageModelMetaData = LanguageModelMetaData = {}));
|
|
46
|
+
var LanguageModel;
|
|
47
|
+
(function (LanguageModel) {
|
|
48
|
+
function is(arg) {
|
|
49
|
+
return (0, core_1.isObject)(arg) && 'id' in arg && (0, core_1.isFunction)(arg.request);
|
|
50
|
+
}
|
|
51
|
+
LanguageModel.is = is;
|
|
52
|
+
})(LanguageModel || (exports.LanguageModel = LanguageModel = {}));
|
|
53
|
+
exports.LanguageModelRegistry = Symbol('LanguageModelRegistry');
|
|
54
|
+
let DefaultLanguageModelRegistryImpl = class DefaultLanguageModelRegistryImpl {
|
|
55
|
+
constructor() {
|
|
56
|
+
this.languageModels = [];
|
|
57
|
+
this.initialized = new Promise(resolve => { this.markInitialized = resolve; });
|
|
58
|
+
this.changeEmitter = new core_1.Emitter();
|
|
59
|
+
this.onChange = this.changeEmitter.event;
|
|
60
|
+
}
|
|
61
|
+
init() {
|
|
62
|
+
const contributions = this.languageModelContributions.getContributions();
|
|
63
|
+
const promises = contributions.map(provider => provider());
|
|
64
|
+
Promise.allSettled(promises).then(results => {
|
|
65
|
+
for (const result of results) {
|
|
66
|
+
if (result.status === 'fulfilled') {
|
|
67
|
+
this.languageModels.push(...result.value);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.logger.error('Failed to add some language models:', result.reason);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
this.markInitialized();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
addLanguageModels(models) {
|
|
77
|
+
models.forEach(model => {
|
|
78
|
+
if (this.languageModels.find(lm => lm.id === model.id)) {
|
|
79
|
+
console.warn(`Tried to add already existing language model with id ${model.id}. The new model will be ignored.`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
this.languageModels.push(model);
|
|
83
|
+
this.changeEmitter.fire({ models: this.languageModels });
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async getLanguageModels() {
|
|
87
|
+
await this.initialized;
|
|
88
|
+
return this.languageModels;
|
|
89
|
+
}
|
|
90
|
+
async getLanguageModel(id) {
|
|
91
|
+
await this.initialized;
|
|
92
|
+
return this.languageModels.find(model => model.id === id);
|
|
93
|
+
}
|
|
94
|
+
removeLanguageModels(ids) {
|
|
95
|
+
ids.forEach(id => {
|
|
96
|
+
const index = this.languageModels.findIndex(model => model.id === id);
|
|
97
|
+
if (index !== -1) {
|
|
98
|
+
this.languageModels.splice(index, 1);
|
|
99
|
+
this.changeEmitter.fire({ models: this.languageModels });
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
console.warn(`Language model with id ${id} was requested to be removed, however it does not exist`);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async selectLanguageModels(request) {
|
|
107
|
+
await this.initialized;
|
|
108
|
+
// TODO check for actor and purpose against settings
|
|
109
|
+
return this.languageModels.filter(model => isModelMatching(request, model));
|
|
110
|
+
}
|
|
111
|
+
async selectLanguageModel(request) {
|
|
112
|
+
return (await this.selectLanguageModels(request))[0];
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
exports.DefaultLanguageModelRegistryImpl = DefaultLanguageModelRegistryImpl;
|
|
116
|
+
tslib_1.__decorate([
|
|
117
|
+
(0, inversify_1.inject)(core_1.ILogger),
|
|
118
|
+
tslib_1.__metadata("design:type", Object)
|
|
119
|
+
], DefaultLanguageModelRegistryImpl.prototype, "logger", void 0);
|
|
120
|
+
tslib_1.__decorate([
|
|
121
|
+
(0, inversify_1.inject)(core_1.ContributionProvider),
|
|
122
|
+
(0, inversify_1.named)(exports.LanguageModelProvider),
|
|
123
|
+
tslib_1.__metadata("design:type", Object)
|
|
124
|
+
], DefaultLanguageModelRegistryImpl.prototype, "languageModelContributions", void 0);
|
|
125
|
+
tslib_1.__decorate([
|
|
126
|
+
(0, inversify_1.postConstruct)(),
|
|
127
|
+
tslib_1.__metadata("design:type", Function),
|
|
128
|
+
tslib_1.__metadata("design:paramtypes", []),
|
|
129
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
130
|
+
], DefaultLanguageModelRegistryImpl.prototype, "init", null);
|
|
131
|
+
exports.DefaultLanguageModelRegistryImpl = DefaultLanguageModelRegistryImpl = tslib_1.__decorate([
|
|
132
|
+
(0, inversify_1.injectable)()
|
|
133
|
+
], DefaultLanguageModelRegistryImpl);
|
|
134
|
+
function isModelMatching(request, model) {
|
|
135
|
+
return (!request.identifier || model.id === request.identifier) &&
|
|
136
|
+
(!request.name || model.name === request.name) &&
|
|
137
|
+
(!request.vendor || model.vendor === request.vendor) &&
|
|
138
|
+
(!request.version || model.version === request.version) &&
|
|
139
|
+
(!request.family || model.family === request.family);
|
|
140
|
+
}
|
|
141
|
+
exports.isModelMatching = isModelMatching;
|
|
142
|
+
//# sourceMappingURL=language-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-model.js","sourceRoot":"","sources":["../../src/common/language-model.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;;;;AAEhF,sCAAqH;AACrH,4DAAwF;AASjF,MAAM,6BAA6B,GAAG,CAAC,GAAY,EAAsC,EAAE,CAC9F,CAAC,CAAC,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;IAC7B,MAAM,IAAI,GAAG;IACb,OAAQ,GAAyB,CAAC,IAAI,KAAK,QAAQ;IAClD,GAAyB,CAAC,IAAI,KAAK,MAAM;IAC1C,OAAO,IAAI,GAAG;IACd,OAAQ,GAA0B,CAA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
|
|
|
1
|
+
{"version":3,"file":"language-model.spec.d.ts","sourceRoot":"","sources":["../../src/common/language-model.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
const language_model_1 = require("./language-model");
|
|
19
|
+
const chai_1 = require("chai");
|
|
20
|
+
describe('isModelMatching', () => {
|
|
21
|
+
it('returns false with one of two parameter mismatches', () => {
|
|
22
|
+
(0, chai_1.expect)((0, language_model_1.isModelMatching)({
|
|
23
|
+
name: 'XXX',
|
|
24
|
+
family: 'YYY',
|
|
25
|
+
}, {
|
|
26
|
+
name: 'gpt-4o',
|
|
27
|
+
family: 'YYY',
|
|
28
|
+
})).eql(false);
|
|
29
|
+
});
|
|
30
|
+
it('returns false with two parameter mismatches', () => {
|
|
31
|
+
(0, chai_1.expect)((0, language_model_1.isModelMatching)({
|
|
32
|
+
name: 'XXX',
|
|
33
|
+
family: 'YYY',
|
|
34
|
+
}, {
|
|
35
|
+
name: 'gpt-4o',
|
|
36
|
+
family: 'ZZZ',
|
|
37
|
+
})).eql(false);
|
|
38
|
+
});
|
|
39
|
+
it('returns true with one parameter match', () => {
|
|
40
|
+
(0, chai_1.expect)((0, language_model_1.isModelMatching)({
|
|
41
|
+
name: 'gpt-4o',
|
|
42
|
+
}, {
|
|
43
|
+
name: 'gpt-4o',
|
|
44
|
+
})).eql(true);
|
|
45
|
+
});
|
|
46
|
+
it('returns true with two parameter matches', () => {
|
|
47
|
+
(0, chai_1.expect)((0, language_model_1.isModelMatching)({
|
|
48
|
+
name: 'gpt-4o',
|
|
49
|
+
family: 'YYY',
|
|
50
|
+
}, {
|
|
51
|
+
name: 'gpt-4o',
|
|
52
|
+
family: 'YYY',
|
|
53
|
+
})).eql(true);
|
|
54
|
+
});
|
|
55
|
+
it('returns true if there are no parameters in selector', () => {
|
|
56
|
+
(0, chai_1.expect)((0, language_model_1.isModelMatching)({}, {
|
|
57
|
+
name: 'gpt-4o',
|
|
58
|
+
family: 'YYY',
|
|
59
|
+
})).eql(true);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=language-model.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-model.spec.js","sourceRoot":"","sources":["../../src/common/language-model.spec.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;;AAEhF,qDAAyF;AACzF,+BAA8B;AAE9B,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;QAC1D,IAAA,aAAM,EACF,IAAA,gCAAe,EACY;YACnB,IAAI,EAAE,KAAK;YACX,MAAM,EAAE,KAAK;SAChB,EACc;YACX,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,KAAK;SAChB,CACJ,CACJ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACnD,IAAA,aAAM,EACF,IAAA,gCAAe,EACY;YACnB,IAAI,EAAE,KAAK;YACX,MAAM,EAAE,KAAK;SAChB,EACc;YACX,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,KAAK;SAChB,CACJ,CACJ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC7C,IAAA,aAAM,EACF,IAAA,gCAAe,EACY;YACnB,IAAI,EAAE,QAAQ;SACjB,EACc;YACX,IAAI,EAAE,QAAQ;SACjB,CACJ,CACJ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;QAC/C,IAAA,aAAM,EACF,IAAA,gCAAe,EACY;YACnB,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,KAAK;SAChB,EACc;YACX,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,KAAK;SAChB,CACJ,CACJ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAC3D,IAAA,aAAM,EACF,IAAA,gCAAe,EACY,EAAE,EACV;YACX,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,KAAK;SAChB,CACJ,CACJ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Should match the one from VariableResolverService. The format is `{{variableName:arg}}`. We allow {{}} and {{{}}} but no mixtures */
|
|
2
|
+
export declare const PROMPT_VARIABLE_TWO_BRACES_REGEX: RegExp;
|
|
3
|
+
export declare const PROMPT_VARIABLE_THREE_BRACES_REGEX: RegExp;
|
|
4
|
+
export declare function matchVariablesRegEx(template: string): RegExpMatchArray[];
|
|
5
|
+
/** Match function/tool references in the prompt. The format is `~{functionId}`. */
|
|
6
|
+
export declare const PROMPT_FUNCTION_REGEX: RegExp;
|
|
7
|
+
export declare function matchFunctionsRegEx(template: string): RegExpMatchArray[];
|
|
8
|
+
//# sourceMappingURL=prompt-service-util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-service-util.d.ts","sourceRoot":"","sources":["../../src/common/prompt-service-util.ts"],"names":[],"mappings":"AAgBA,wIAAwI;AACxI,eAAO,MAAM,gCAAgC,QAA0C,CAAC;AACxF,eAAO,MAAM,kCAAkC,QAA8C,CAAC;AAC9F,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAIxE;AAED,mFAAmF;AACnF,eAAO,MAAM,qBAAqB,QAAuB,CAAC;AAE1D,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAExE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
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.matchFunctionsRegEx = exports.PROMPT_FUNCTION_REGEX = exports.matchVariablesRegEx = exports.PROMPT_VARIABLE_THREE_BRACES_REGEX = exports.PROMPT_VARIABLE_TWO_BRACES_REGEX = void 0;
|
|
19
|
+
/** Should match the one from VariableResolverService. The format is `{{variableName:arg}}`. We allow {{}} and {{{}}} but no mixtures */
|
|
20
|
+
exports.PROMPT_VARIABLE_TWO_BRACES_REGEX = /(?<!\{)\{\{\s*([^{}]+?)\s*\}\}(?!\})/g;
|
|
21
|
+
exports.PROMPT_VARIABLE_THREE_BRACES_REGEX = /(?<!\{)\{\{\{\s*([^{}]+?)\s*\}\}\}(?!\})/g;
|
|
22
|
+
function matchVariablesRegEx(template) {
|
|
23
|
+
const twoBraceMatches = [...template.matchAll(exports.PROMPT_VARIABLE_TWO_BRACES_REGEX)];
|
|
24
|
+
const threeBraceMatches = [...template.matchAll(exports.PROMPT_VARIABLE_THREE_BRACES_REGEX)];
|
|
25
|
+
return twoBraceMatches.concat(threeBraceMatches);
|
|
26
|
+
}
|
|
27
|
+
exports.matchVariablesRegEx = matchVariablesRegEx;
|
|
28
|
+
/** Match function/tool references in the prompt. The format is `~{functionId}`. */
|
|
29
|
+
exports.PROMPT_FUNCTION_REGEX = /\~\{\s*(.*?)\s*\}/g;
|
|
30
|
+
function matchFunctionsRegEx(template) {
|
|
31
|
+
return [...template.matchAll(exports.PROMPT_FUNCTION_REGEX)];
|
|
32
|
+
}
|
|
33
|
+
exports.matchFunctionsRegEx = matchFunctionsRegEx;
|
|
34
|
+
//# sourceMappingURL=prompt-service-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-service-util.js","sourceRoot":"","sources":["../../src/common/prompt-service-util.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;;;AAEhF,wIAAwI;AAC3H,QAAA,gCAAgC,GAAG,uCAAuC,CAAC;AAC3E,QAAA,kCAAkC,GAAG,2CAA2C,CAAC;AAC9F,SAAgB,mBAAmB,CAAC,QAAgB;IAChD,MAAM,eAAe,GAAG,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,wCAAgC,CAAC,CAAC,CAAC;IACjF,MAAM,iBAAiB,GAAG,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,0CAAkC,CAAC,CAAC,CAAC;IACrF,OAAO,eAAe,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;AACrD,CAAC;AAJD,kDAIC;AAED,mFAAmF;AACtE,QAAA,qBAAqB,GAAG,oBAAoB,CAAC;AAE1D,SAAgB,mBAAmB,CAAC,QAAgB;IAChD,OAAO,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,6BAAqB,CAAC,CAAC,CAAC;AACzD,CAAC;AAFD,kDAEC"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { URI, Event } from '@theia/core';
|
|
2
|
+
import { AIVariableService } from './variable-service';
|
|
3
|
+
import { ToolInvocationRegistry } from './tool-invocation-registry';
|
|
4
|
+
import { ToolRequest } from './language-model';
|
|
5
|
+
import { AISettingsService } from './settings-service';
|
|
6
|
+
export interface PromptTemplate {
|
|
7
|
+
id: string;
|
|
8
|
+
template: string;
|
|
9
|
+
/**
|
|
10
|
+
* (Optional) The ID of the main template for which this template is a variant.
|
|
11
|
+
* If present, this indicates that the current template represents an alternative version of the specified main template.
|
|
12
|
+
*/
|
|
13
|
+
variantOf?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface PromptMap {
|
|
16
|
+
[id: string]: PromptTemplate;
|
|
17
|
+
}
|
|
18
|
+
export interface ResolvedPromptTemplate {
|
|
19
|
+
id: string;
|
|
20
|
+
/** The resolved prompt text with variables and function requests being replaced. */
|
|
21
|
+
text: string;
|
|
22
|
+
/** All functions referenced in the prompt template. */
|
|
23
|
+
functionDescriptions?: Map<string, ToolRequest>;
|
|
24
|
+
}
|
|
25
|
+
export declare const PromptService: unique symbol;
|
|
26
|
+
export interface PromptService {
|
|
27
|
+
/**
|
|
28
|
+
* Retrieve the raw {@link PromptTemplate} object (unresolved variables, functions and including comments).
|
|
29
|
+
* @param id the id of the {@link PromptTemplate}
|
|
30
|
+
*/
|
|
31
|
+
getRawPrompt(id: string): PromptTemplate | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Retrieve the unresolved {@link PromptTemplate} object (unresolved variables, functions, excluding comments)
|
|
34
|
+
* @param id the id of the {@link PromptTemplate}
|
|
35
|
+
*/
|
|
36
|
+
getUnresolvedPrompt(id: string): PromptTemplate | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Retrieve the default raw {@link PromptTemplate} object.
|
|
39
|
+
* @param id the id of the {@link PromptTemplate}
|
|
40
|
+
*/
|
|
41
|
+
getDefaultRawPrompt(id: string): PromptTemplate | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Allows to directly replace placeholders in the prompt. The supported format is 'Hi {{name}}!'.
|
|
44
|
+
* The placeholder is then searched inside the args object and replaced.
|
|
45
|
+
* Function references are also supported via format '~{functionId}'.
|
|
46
|
+
* @param id the id of the prompt
|
|
47
|
+
* @param args the object with placeholders, mapping the placeholder key to the value
|
|
48
|
+
*/
|
|
49
|
+
getPrompt(id: string, args?: {
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
}): Promise<ResolvedPromptTemplate | undefined>;
|
|
52
|
+
/**
|
|
53
|
+
* Adds a {@link PromptTemplate} to the list of prompts.
|
|
54
|
+
* @param promptTemplate the prompt template to store
|
|
55
|
+
*/
|
|
56
|
+
storePromptTemplate(promptTemplate: PromptTemplate): void;
|
|
57
|
+
/**
|
|
58
|
+
* Removes a prompt from the list of prompts.
|
|
59
|
+
* @param id the id of the prompt
|
|
60
|
+
*/
|
|
61
|
+
removePrompt(id: string): void;
|
|
62
|
+
/**
|
|
63
|
+
* Return all known prompts as a {@link PromptMap map}.
|
|
64
|
+
*/
|
|
65
|
+
getAllPrompts(): PromptMap;
|
|
66
|
+
/**
|
|
67
|
+
* Retrieve all variant IDs of a given {@link PromptTemplate}.
|
|
68
|
+
* @param id the id of the main {@link PromptTemplate}
|
|
69
|
+
* @returns an array of string IDs representing the variants of the given template
|
|
70
|
+
*/
|
|
71
|
+
getVariantIds(id: string): string[];
|
|
72
|
+
/**
|
|
73
|
+
* Retrieve the currently selected variant ID for a given main prompt ID.
|
|
74
|
+
* If a variant is selected for the main prompt, it will be returned.
|
|
75
|
+
* Otherwise, the main prompt ID will be returned.
|
|
76
|
+
* @param id the id of the main prompt
|
|
77
|
+
* @returns the variant ID if one is selected, or the main prompt ID otherwise
|
|
78
|
+
*/
|
|
79
|
+
getVariantId(id: string): Promise<string>;
|
|
80
|
+
}
|
|
81
|
+
export interface CustomAgentDescription {
|
|
82
|
+
id: string;
|
|
83
|
+
name: string;
|
|
84
|
+
description: string;
|
|
85
|
+
prompt: string;
|
|
86
|
+
defaultLLM: string;
|
|
87
|
+
}
|
|
88
|
+
export declare namespace CustomAgentDescription {
|
|
89
|
+
function is(entry: unknown): entry is CustomAgentDescription;
|
|
90
|
+
function equals(a: CustomAgentDescription, b: CustomAgentDescription): boolean;
|
|
91
|
+
}
|
|
92
|
+
export declare const PromptCustomizationService: unique symbol;
|
|
93
|
+
export interface PromptCustomizationService {
|
|
94
|
+
/**
|
|
95
|
+
* Whether there is a customization for a {@link PromptTemplate} object
|
|
96
|
+
* @param id the id of the {@link PromptTemplate} to check
|
|
97
|
+
*/
|
|
98
|
+
isPromptTemplateCustomized(id: string): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Returns the customization of {@link PromptTemplate} object or undefined if there is none
|
|
101
|
+
* @param id the id of the {@link PromptTemplate} to check
|
|
102
|
+
*/
|
|
103
|
+
getCustomizedPromptTemplate(id: string): string | undefined;
|
|
104
|
+
getCustomPromptTemplateIDs(): string[];
|
|
105
|
+
/**
|
|
106
|
+
* Edit the template. If the content is specified, is will be
|
|
107
|
+
* used to customize the template. Otherwise, the behavior depends
|
|
108
|
+
* on the implementation. Implementation may for example decide to
|
|
109
|
+
* open an editor, or request more information from the user, ...
|
|
110
|
+
* @param id the template id.
|
|
111
|
+
* @param content optional default content to initialize the template
|
|
112
|
+
*/
|
|
113
|
+
editTemplate(id: string, defaultContent?: string): void;
|
|
114
|
+
/**
|
|
115
|
+
* Reset the template to its default value.
|
|
116
|
+
* @param id the template id.
|
|
117
|
+
*/
|
|
118
|
+
resetTemplate(id: string): void;
|
|
119
|
+
/**
|
|
120
|
+
* Return the template id for a given template file.
|
|
121
|
+
* @param uri the uri of the template file
|
|
122
|
+
*/
|
|
123
|
+
getTemplateIDFromURI(uri: URI): string | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* Event which is fired when the prompt template is changed.
|
|
126
|
+
*/
|
|
127
|
+
readonly onDidChangePrompt: Event<string>;
|
|
128
|
+
/**
|
|
129
|
+
* Return all custom agents.
|
|
130
|
+
* @returns all custom agents
|
|
131
|
+
*/
|
|
132
|
+
getCustomAgents(): Promise<CustomAgentDescription[]>;
|
|
133
|
+
/**
|
|
134
|
+
* Event which is fired when custom agents are modified.
|
|
135
|
+
*/
|
|
136
|
+
readonly onDidChangeCustomAgents: Event<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Open the custom agent yaml file.
|
|
139
|
+
*/
|
|
140
|
+
openCustomAgentYaml(): void;
|
|
141
|
+
}
|
|
142
|
+
export declare class PromptServiceImpl implements PromptService {
|
|
143
|
+
protected readonly settingsService: AISettingsService | undefined;
|
|
144
|
+
protected readonly customizationService: PromptCustomizationService | undefined;
|
|
145
|
+
protected readonly variableService: AIVariableService | undefined;
|
|
146
|
+
protected readonly toolInvocationRegistry: ToolInvocationRegistry | undefined;
|
|
147
|
+
protected _prompts: PromptMap;
|
|
148
|
+
getRawPrompt(id: string): PromptTemplate | undefined;
|
|
149
|
+
getDefaultRawPrompt(id: string): PromptTemplate | undefined;
|
|
150
|
+
getUnresolvedPrompt(id: string): PromptTemplate | undefined;
|
|
151
|
+
protected stripComments(template: string): string;
|
|
152
|
+
getVariantId(id: string): Promise<string>;
|
|
153
|
+
getPrompt(id: string, args?: {
|
|
154
|
+
[key: string]: unknown;
|
|
155
|
+
}): Promise<ResolvedPromptTemplate | undefined>;
|
|
156
|
+
getAllPrompts(): PromptMap;
|
|
157
|
+
removePrompt(id: string): void;
|
|
158
|
+
getVariantIds(id: string): string[];
|
|
159
|
+
storePromptTemplate(promptTemplate: PromptTemplate): void;
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=prompt-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-service.d.ts","sourceRoot":"","sources":["../../src/common/prompt-service.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,WAAW,cAAc;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,SAAS;IAAG,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc,CAAA;CAAE;AAE3D,MAAM,WAAW,sBAAsB;IACnC,EAAE,EAAE,MAAM,CAAC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E9E,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAM;IAEnC,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IASpD,mBAAmB,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAI3D,mBAAmB,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAW3D,SAAS,CAAC,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAK3C,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAazC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,sBAAsB,GAAG,SAAS,CAAC;IAmD3G,aAAa,IAAI,SAAS;IAqB1B,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAG9B,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE;IAcnC,mBAAmB,CAAC,cAAc,EAAE,cAAc,GAAG,IAAI;CAG5D"}
|
|
@@ -0,0 +1,204 @@
|
|
|
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.PromptServiceImpl = exports.PromptCustomizationService = exports.CustomAgentDescription = exports.PromptService = void 0;
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
21
|
+
const variable_service_1 = require("./variable-service");
|
|
22
|
+
const tool_invocation_registry_1 = require("./tool-invocation-registry");
|
|
23
|
+
const language_model_util_1 = require("./language-model-util");
|
|
24
|
+
const prompt_service_util_1 = require("./prompt-service-util");
|
|
25
|
+
const settings_service_1 = require("./settings-service");
|
|
26
|
+
exports.PromptService = Symbol('PromptService');
|
|
27
|
+
var CustomAgentDescription;
|
|
28
|
+
(function (CustomAgentDescription) {
|
|
29
|
+
function is(entry) {
|
|
30
|
+
// eslint-disable-next-line no-null/no-null
|
|
31
|
+
return typeof entry === 'object' && entry !== null
|
|
32
|
+
&& 'id' in entry && typeof entry.id === 'string'
|
|
33
|
+
&& 'name' in entry && typeof entry.name === 'string'
|
|
34
|
+
&& 'description' in entry && typeof entry.description === 'string'
|
|
35
|
+
&& 'prompt' in entry
|
|
36
|
+
&& typeof entry.prompt === 'string'
|
|
37
|
+
&& 'defaultLLM' in entry
|
|
38
|
+
&& typeof entry.defaultLLM === 'string';
|
|
39
|
+
}
|
|
40
|
+
CustomAgentDescription.is = is;
|
|
41
|
+
function equals(a, b) {
|
|
42
|
+
return a.id === b.id && a.name === b.name && a.description === b.description && a.prompt === b.prompt && a.defaultLLM === b.defaultLLM;
|
|
43
|
+
}
|
|
44
|
+
CustomAgentDescription.equals = equals;
|
|
45
|
+
})(CustomAgentDescription || (exports.CustomAgentDescription = CustomAgentDescription = {}));
|
|
46
|
+
exports.PromptCustomizationService = Symbol('PromptCustomizationService');
|
|
47
|
+
let PromptServiceImpl = class PromptServiceImpl {
|
|
48
|
+
constructor() {
|
|
49
|
+
this._prompts = {};
|
|
50
|
+
}
|
|
51
|
+
getRawPrompt(id) {
|
|
52
|
+
if (this.customizationService !== undefined && this.customizationService.isPromptTemplateCustomized(id)) {
|
|
53
|
+
const template = this.customizationService.getCustomizedPromptTemplate(id);
|
|
54
|
+
if (template !== undefined) {
|
|
55
|
+
return { id, template };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return this.getDefaultRawPrompt(id);
|
|
59
|
+
}
|
|
60
|
+
getDefaultRawPrompt(id) {
|
|
61
|
+
return this._prompts[id];
|
|
62
|
+
}
|
|
63
|
+
getUnresolvedPrompt(id) {
|
|
64
|
+
const rawPrompt = this.getRawPrompt(id);
|
|
65
|
+
if (!rawPrompt) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
id: rawPrompt.id,
|
|
70
|
+
template: this.stripComments(rawPrompt.template)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
stripComments(template) {
|
|
74
|
+
const commentRegex = /^\s*{{!--[\s\S]*?--}}\s*\n?/;
|
|
75
|
+
return commentRegex.test(template) ? template.replace(commentRegex, '').trimStart() : template;
|
|
76
|
+
}
|
|
77
|
+
async getVariantId(id) {
|
|
78
|
+
if (this.settingsService !== undefined) {
|
|
79
|
+
const agentSettingsMap = await this.settingsService.getSettings();
|
|
80
|
+
for (const agentSettings of Object.values(agentSettingsMap)) {
|
|
81
|
+
if (agentSettings.selectedVariants && agentSettings.selectedVariants[id]) {
|
|
82
|
+
return agentSettings.selectedVariants[id];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return id;
|
|
87
|
+
}
|
|
88
|
+
async getPrompt(id, args) {
|
|
89
|
+
const variantId = await this.getVariantId(id);
|
|
90
|
+
const prompt = this.getUnresolvedPrompt(variantId);
|
|
91
|
+
if (prompt === undefined) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
const matches = (0, prompt_service_util_1.matchVariablesRegEx)(prompt.template);
|
|
95
|
+
const variableAndArgReplacements = await Promise.all(matches.map(async (match) => {
|
|
96
|
+
var _a, _b, _c, _d;
|
|
97
|
+
const completeText = match[0];
|
|
98
|
+
const variableAndArg = match[1];
|
|
99
|
+
let variableName = variableAndArg;
|
|
100
|
+
let argument;
|
|
101
|
+
const parts = variableAndArg.split(':', 2);
|
|
102
|
+
if (parts.length > 1) {
|
|
103
|
+
variableName = parts[0];
|
|
104
|
+
argument = parts[1];
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
placeholder: completeText,
|
|
108
|
+
value: String((_d = (_a = args === null || args === void 0 ? void 0 : args[variableAndArg]) !== null && _a !== void 0 ? _a : (_c = (await ((_b = this.variableService) === null || _b === void 0 ? void 0 : _b.resolveVariable({
|
|
109
|
+
variable: variableName,
|
|
110
|
+
arg: argument
|
|
111
|
+
}, {})))) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : completeText)
|
|
112
|
+
};
|
|
113
|
+
}));
|
|
114
|
+
const functionMatches = (0, prompt_service_util_1.matchFunctionsRegEx)(prompt.template);
|
|
115
|
+
const functions = new Map();
|
|
116
|
+
const functionReplacements = functionMatches.map(match => {
|
|
117
|
+
var _a;
|
|
118
|
+
const completeText = match[0];
|
|
119
|
+
const functionId = match[1];
|
|
120
|
+
const toolRequest = (_a = this.toolInvocationRegistry) === null || _a === void 0 ? void 0 : _a.getFunction(functionId);
|
|
121
|
+
if (toolRequest) {
|
|
122
|
+
functions.set(toolRequest.id, toolRequest);
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
placeholder: completeText,
|
|
126
|
+
value: toolRequest ? (0, language_model_util_1.toolRequestToPromptText)(toolRequest) : completeText
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
let resolvedTemplate = prompt.template;
|
|
130
|
+
const replacements = [...variableAndArgReplacements, ...functionReplacements];
|
|
131
|
+
replacements.forEach(replacement => resolvedTemplate = resolvedTemplate.replace(replacement.placeholder, replacement.value));
|
|
132
|
+
return {
|
|
133
|
+
id,
|
|
134
|
+
text: resolvedTemplate,
|
|
135
|
+
functionDescriptions: functions.size > 0 ? functions : undefined
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
getAllPrompts() {
|
|
139
|
+
if (this.customizationService !== undefined) {
|
|
140
|
+
const myCustomization = this.customizationService;
|
|
141
|
+
const result = {};
|
|
142
|
+
Object.keys(this._prompts).forEach(id => {
|
|
143
|
+
if (myCustomization.isPromptTemplateCustomized(id)) {
|
|
144
|
+
const template = myCustomization.getCustomizedPromptTemplate(id);
|
|
145
|
+
if (template !== undefined) {
|
|
146
|
+
result[id] = { id, template };
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
result[id] = { ...this._prompts[id] };
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
result[id] = { ...this._prompts[id] };
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
return { ...this._prompts };
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
removePrompt(id) {
|
|
163
|
+
delete this._prompts[id];
|
|
164
|
+
}
|
|
165
|
+
getVariantIds(id) {
|
|
166
|
+
var _a;
|
|
167
|
+
const allCustomPromptTemplateIds = ((_a = this.customizationService) === null || _a === void 0 ? void 0 : _a.getCustomPromptTemplateIDs()) || [];
|
|
168
|
+
const knownPromptIds = Object.keys(this._prompts);
|
|
169
|
+
// We filter out known IDs from the custom prompt template IDs, these are no variants, but customizations. Then we retain IDs that start with the main ID
|
|
170
|
+
const customVariantIds = allCustomPromptTemplateIds.filter(customId => !knownPromptIds.includes(customId) && customId.startsWith(id));
|
|
171
|
+
const variantIds = Object.values(this._prompts)
|
|
172
|
+
.filter(prompt => prompt.variantOf === id)
|
|
173
|
+
.map(variant => variant.id);
|
|
174
|
+
return [...variantIds, ...customVariantIds];
|
|
175
|
+
}
|
|
176
|
+
storePromptTemplate(promptTemplate) {
|
|
177
|
+
this._prompts[promptTemplate.id] = promptTemplate;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
exports.PromptServiceImpl = PromptServiceImpl;
|
|
181
|
+
tslib_1.__decorate([
|
|
182
|
+
(0, inversify_1.inject)(settings_service_1.AISettingsService),
|
|
183
|
+
(0, inversify_1.optional)(),
|
|
184
|
+
tslib_1.__metadata("design:type", Object)
|
|
185
|
+
], PromptServiceImpl.prototype, "settingsService", void 0);
|
|
186
|
+
tslib_1.__decorate([
|
|
187
|
+
(0, inversify_1.inject)(exports.PromptCustomizationService),
|
|
188
|
+
(0, inversify_1.optional)(),
|
|
189
|
+
tslib_1.__metadata("design:type", Object)
|
|
190
|
+
], PromptServiceImpl.prototype, "customizationService", void 0);
|
|
191
|
+
tslib_1.__decorate([
|
|
192
|
+
(0, inversify_1.inject)(variable_service_1.AIVariableService),
|
|
193
|
+
(0, inversify_1.optional)(),
|
|
194
|
+
tslib_1.__metadata("design:type", Object)
|
|
195
|
+
], PromptServiceImpl.prototype, "variableService", void 0);
|
|
196
|
+
tslib_1.__decorate([
|
|
197
|
+
(0, inversify_1.inject)(tool_invocation_registry_1.ToolInvocationRegistry),
|
|
198
|
+
(0, inversify_1.optional)(),
|
|
199
|
+
tslib_1.__metadata("design:type", Object)
|
|
200
|
+
], PromptServiceImpl.prototype, "toolInvocationRegistry", void 0);
|
|
201
|
+
exports.PromptServiceImpl = PromptServiceImpl = tslib_1.__decorate([
|
|
202
|
+
(0, inversify_1.injectable)()
|
|
203
|
+
], PromptServiceImpl);
|
|
204
|
+
//# sourceMappingURL=prompt-service.js.map
|