@theia/ai-core 1.67.0-next.3 → 1.67.0-next.56
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 +1 -0
- package/data/prompttemplate.tmLanguage.json +3 -0
- package/package.json +9 -9
- package/src/browser/frontend-language-model-alias-registry.ts +11 -11
- package/src/common/agent-service.ts +6 -6
- package/src/common/prompt-service.ts +6 -2
- package/lib/browser/agent-completion-notification-service.d.ts +0 -69
- package/lib/browser/agent-completion-notification-service.d.ts.map +0 -1
- package/lib/browser/agent-completion-notification-service.js +0 -187
- package/lib/browser/agent-completion-notification-service.js.map +0 -1
- package/lib/browser/ai-activation-service.d.ts +0 -31
- package/lib/browser/ai-activation-service.d.ts.map +0 -1
- package/lib/browser/ai-activation-service.js +0 -56
- package/lib/browser/ai-activation-service.js.map +0 -1
- package/lib/browser/ai-command-handler-factory.d.ts +0 -4
- package/lib/browser/ai-command-handler-factory.d.ts.map +0 -1
- package/lib/browser/ai-command-handler-factory.js +0 -20
- package/lib/browser/ai-command-handler-factory.js.map +0 -1
- package/lib/browser/ai-core-command-contribution.d.ts +0 -8
- package/lib/browser/ai-core-command-contribution.d.ts.map +0 -1
- package/lib/browser/ai-core-command-contribution.js +0 -44
- package/lib/browser/ai-core-command-contribution.js.map +0 -1
- package/lib/browser/ai-core-frontend-application-contribution.d.ts +0 -10
- package/lib/browser/ai-core-frontend-application-contribution.d.ts.map +0 -1
- package/lib/browser/ai-core-frontend-application-contribution.js +0 -46
- package/lib/browser/ai-core-frontend-application-contribution.js.map +0 -1
- package/lib/browser/ai-core-frontend-module.d.ts +0 -4
- package/lib/browser/ai-core-frontend-module.d.ts.map +0 -1
- package/lib/browser/ai-core-frontend-module.js +0 -137
- package/lib/browser/ai-core-frontend-module.js.map +0 -1
- package/lib/browser/ai-settings-service.d.ts +0 -16
- package/lib/browser/ai-settings-service.d.ts.map +0 -1
- package/lib/browser/ai-settings-service.js +0 -78
- package/lib/browser/ai-settings-service.js.map +0 -1
- package/lib/browser/ai-variable-uri-label-provider.d.ts +0 -17
- package/lib/browser/ai-variable-uri-label-provider.d.ts.map +0 -1
- package/lib/browser/ai-variable-uri-label-provider.js +0 -85
- package/lib/browser/ai-variable-uri-label-provider.js.map +0 -1
- package/lib/browser/ai-view-contribution.d.ts +0 -14
- package/lib/browser/ai-view-contribution.d.ts.map +0 -1
- package/lib/browser/ai-view-contribution.js +0 -87
- package/lib/browser/ai-view-contribution.js.map +0 -1
- package/lib/browser/file-variable-contribution.d.ts +0 -23
- package/lib/browser/file-variable-contribution.d.ts.map +0 -1
- package/lib/browser/file-variable-contribution.js +0 -114
- package/lib/browser/file-variable-contribution.js.map +0 -1
- package/lib/browser/frontend-language-model-alias-registry.d.ts +0 -31
- package/lib/browser/frontend-language-model-alias-registry.d.ts.map +0 -1
- package/lib/browser/frontend-language-model-alias-registry.js +0 -170
- package/lib/browser/frontend-language-model-alias-registry.js.map +0 -1
- package/lib/browser/frontend-language-model-registry.d.ts +0 -49
- package/lib/browser/frontend-language-model-registry.d.ts.map +0 -1
- package/lib/browser/frontend-language-model-registry.js +0 -387
- package/lib/browser/frontend-language-model-registry.js.map +0 -1
- package/lib/browser/frontend-language-model-registry.spec.d.ts +0 -2
- package/lib/browser/frontend-language-model-registry.spec.d.ts.map +0 -1
- package/lib/browser/frontend-language-model-registry.spec.js +0 -248
- package/lib/browser/frontend-language-model-registry.spec.js.map +0 -1
- package/lib/browser/frontend-language-model-service.d.ts +0 -10
- package/lib/browser/frontend-language-model-service.d.ts.map +0 -1
- package/lib/browser/frontend-language-model-service.js +0 -66
- package/lib/browser/frontend-language-model-service.js.map +0 -1
- package/lib/browser/frontend-prompt-customization-service.d.ts +0 -271
- package/lib/browser/frontend-prompt-customization-service.d.ts.map +0 -1
- package/lib/browser/frontend-prompt-customization-service.js +0 -869
- package/lib/browser/frontend-prompt-customization-service.js.map +0 -1
- package/lib/browser/frontend-prompt-customization-service.spec.d.ts +0 -2
- package/lib/browser/frontend-prompt-customization-service.spec.d.ts.map +0 -1
- package/lib/browser/frontend-prompt-customization-service.spec.js +0 -127
- package/lib/browser/frontend-prompt-customization-service.spec.js.map +0 -1
- package/lib/browser/frontend-variable-service.d.ts +0 -61
- package/lib/browser/frontend-variable-service.d.ts.map +0 -1
- package/lib/browser/frontend-variable-service.js +0 -165
- package/lib/browser/frontend-variable-service.js.map +0 -1
- package/lib/browser/index.d.ts +0 -20
- package/lib/browser/index.d.ts.map +0 -1
- package/lib/browser/index.js +0 -38
- package/lib/browser/index.js.map +0 -1
- package/lib/browser/open-editors-variable-contribution.d.ts +0 -17
- package/lib/browser/open-editors-variable-contribution.d.ts.map +0 -1
- package/lib/browser/open-editors-variable-contribution.js +0 -84
- package/lib/browser/open-editors-variable-contribution.js.map +0 -1
- package/lib/browser/os-notification-service.d.ts +0 -96
- package/lib/browser/os-notification-service.d.ts.map +0 -1
- package/lib/browser/os-notification-service.js +0 -222
- package/lib/browser/os-notification-service.js.map +0 -1
- package/lib/browser/prompttemplate-contribution.d.ts +0 -29
- package/lib/browser/prompttemplate-contribution.d.ts.map +0 -1
- package/lib/browser/prompttemplate-contribution.js +0 -243
- package/lib/browser/prompttemplate-contribution.js.map +0 -1
- package/lib/browser/prompttemplate-parser.d.ts +0 -36
- package/lib/browser/prompttemplate-parser.d.ts.map +0 -1
- package/lib/browser/prompttemplate-parser.js +0 -94
- package/lib/browser/prompttemplate-parser.js.map +0 -1
- package/lib/browser/theia-variable-contribution.d.ts +0 -26
- package/lib/browser/theia-variable-contribution.d.ts.map +0 -1
- package/lib/browser/theia-variable-contribution.js +0 -146
- package/lib/browser/theia-variable-contribution.js.map +0 -1
- package/lib/browser/token-usage-frontend-service-impl.d.ts +0 -25
- package/lib/browser/token-usage-frontend-service-impl.d.ts.map +0 -1
- package/lib/browser/token-usage-frontend-service-impl.js +0 -138
- package/lib/browser/token-usage-frontend-service-impl.js.map +0 -1
- package/lib/browser/token-usage-frontend-service.d.ts +0 -33
- package/lib/browser/token-usage-frontend-service.d.ts.map +0 -1
- package/lib/browser/token-usage-frontend-service.js +0 -23
- package/lib/browser/token-usage-frontend-service.js.map +0 -1
- package/lib/browser/window-blink-service.d.ts +0 -41
- package/lib/browser/window-blink-service.d.ts.map +0 -1
- package/lib/browser/window-blink-service.js +0 -174
- package/lib/browser/window-blink-service.js.map +0 -1
- package/lib/common/agent-preferences.d.ts +0 -4
- package/lib/common/agent-preferences.d.ts.map +0 -1
- package/lib/common/agent-preferences.js +0 -84
- package/lib/common/agent-preferences.js.map +0 -1
- package/lib/common/agent-service.d.ts +0 -66
- package/lib/common/agent-service.d.ts.map +0 -1
- package/lib/common/agent-service.js +0 -104
- package/lib/common/agent-service.js.map +0 -1
- package/lib/common/agent.d.ts +0 -72
- package/lib/common/agent.d.ts.map +0 -1
- package/lib/common/agent.js +0 -20
- package/lib/common/agent.js.map +0 -1
- package/lib/common/agents-variable-contribution.d.ts +0 -19
- package/lib/common/agents-variable-contribution.d.ts.map +0 -1
- package/lib/common/agents-variable-contribution.js +0 -57
- package/lib/common/agents-variable-contribution.js.map +0 -1
- package/lib/common/ai-core-preferences.d.ts +0 -48
- package/lib/common/ai-core-preferences.d.ts.map +0 -1
- package/lib/common/ai-core-preferences.js +0 -204
- package/lib/common/ai-core-preferences.js.map +0 -1
- package/lib/common/ai-variable-resource.d.ts +0 -18
- package/lib/common/ai-variable-resource.d.ts.map +0 -1
- package/lib/common/ai-variable-resource.js +0 -103
- package/lib/common/ai-variable-resource.js.map +0 -1
- package/lib/common/configurable-in-memory-resources.d.ts +0 -47
- package/lib/common/configurable-in-memory-resources.d.ts.map +0 -1
- package/lib/common/configurable-in-memory-resources.js +0 -154
- package/lib/common/configurable-in-memory-resources.js.map +0 -1
- package/lib/common/index.d.ts +0 -22
- package/lib/common/index.d.ts.map +0 -1
- package/lib/common/index.js +0 -40
- package/lib/common/index.js.map +0 -1
- package/lib/common/language-model-alias.d.ts +0 -58
- package/lib/common/language-model-alias.d.ts.map +0 -1
- package/lib/common/language-model-alias.js +0 -20
- package/lib/common/language-model-alias.js.map +0 -1
- package/lib/common/language-model-delegate.d.ts +0 -25
- package/lib/common/language-model-delegate.d.ts.map +0 -1
- package/lib/common/language-model-delegate.js +0 -26
- package/lib/common/language-model-delegate.js.map +0 -1
- package/lib/common/language-model-interaction-model.d.ts +0 -74
- package/lib/common/language-model-interaction-model.d.ts.map +0 -1
- package/lib/common/language-model-interaction-model.js +0 -3
- package/lib/common/language-model-interaction-model.js.map +0 -1
- package/lib/common/language-model-service.d.ts +0 -38
- package/lib/common/language-model-service.d.ts.map +0 -1
- package/lib/common/language-model-service.js +0 -128
- package/lib/common/language-model-service.js.map +0 -1
- package/lib/common/language-model-util.d.ts +0 -17
- package/lib/common/language-model-util.d.ts.map +0 -1
- package/lib/common/language-model-util.js +0 -82
- package/lib/common/language-model-util.js.map +0 -1
- package/lib/common/language-model.d.ts +0 -285
- package/lib/common/language-model.d.ts.map +0 -1
- package/lib/common/language-model.js +0 -248
- package/lib/common/language-model.js.map +0 -1
- package/lib/common/language-model.spec.d.ts +0 -2
- package/lib/common/language-model.spec.d.ts.map +0 -1
- package/lib/common/language-model.spec.js +0 -62
- package/lib/common/language-model.spec.js.map +0 -1
- package/lib/common/notification-types.d.ts +0 -7
- package/lib/common/notification-types.d.ts.map +0 -1
- package/lib/common/notification-types.js +0 -29
- package/lib/common/notification-types.js.map +0 -1
- package/lib/common/prompt-service-util.d.ts +0 -8
- package/lib/common/prompt-service-util.d.ts.map +0 -1
- package/lib/common/prompt-service-util.js +0 -34
- package/lib/common/prompt-service-util.js.map +0 -1
- package/lib/common/prompt-service.d.ts +0 -466
- package/lib/common/prompt-service.d.ts.map +0 -1
- package/lib/common/prompt-service.js +0 -653
- package/lib/common/prompt-service.js.map +0 -1
- package/lib/common/prompt-service.spec.d.ts +0 -2
- package/lib/common/prompt-service.spec.d.ts.map +0 -1
- package/lib/common/prompt-service.spec.js +0 -431
- package/lib/common/prompt-service.spec.js.map +0 -1
- package/lib/common/prompt-text.d.ts +0 -8
- package/lib/common/prompt-text.d.ts.map +0 -1
- package/lib/common/prompt-text.js +0 -27
- package/lib/common/prompt-text.js.map +0 -1
- package/lib/common/prompt-variable-contribution.d.ts +0 -18
- package/lib/common/prompt-variable-contribution.d.ts.map +0 -1
- package/lib/common/prompt-variable-contribution.js +0 -207
- package/lib/common/prompt-variable-contribution.js.map +0 -1
- package/lib/common/prompt-variable-contribution.spec.d.ts +0 -2
- package/lib/common/prompt-variable-contribution.spec.d.ts.map +0 -1
- package/lib/common/prompt-variable-contribution.spec.js +0 -163
- package/lib/common/prompt-variable-contribution.spec.js.map +0 -1
- package/lib/common/protocol.d.ts +0 -25
- package/lib/common/protocol.d.ts.map +0 -1
- package/lib/common/protocol.js +0 -22
- package/lib/common/protocol.js.map +0 -1
- package/lib/common/settings-service.d.ts +0 -29
- package/lib/common/settings-service.d.ts.map +0 -1
- package/lib/common/settings-service.js +0 -5
- package/lib/common/settings-service.js.map +0 -1
- package/lib/common/today-variable-contribution.d.ts +0 -17
- package/lib/common/today-variable-contribution.d.ts.map +0 -1
- package/lib/common/today-variable-contribution.js +0 -68
- package/lib/common/today-variable-contribution.js.map +0 -1
- package/lib/common/token-usage-service.d.ts +0 -43
- package/lib/common/token-usage-service.d.ts.map +0 -1
- package/lib/common/token-usage-service.js +0 -20
- package/lib/common/token-usage-service.js.map +0 -1
- package/lib/common/tool-invocation-registry.d.ts +0 -66
- package/lib/common/tool-invocation-registry.d.ts.map +0 -1
- package/lib/common/tool-invocation-registry.js +0 -101
- package/lib/common/tool-invocation-registry.js.map +0 -1
- package/lib/common/variable-service.d.ts +0 -172
- package/lib/common/variable-service.d.ts.map +0 -1
- package/lib/common/variable-service.js +0 -287
- package/lib/common/variable-service.js.map +0 -1
- package/lib/common/variable-service.spec.d.ts +0 -2
- package/lib/common/variable-service.spec.d.ts.map +0 -1
- package/lib/common/variable-service.spec.js +0 -237
- package/lib/common/variable-service.spec.js.map +0 -1
- package/lib/node/ai-core-backend-module.d.ts +0 -4
- package/lib/node/ai-core-backend-module.d.ts.map +0 -1
- package/lib/node/ai-core-backend-module.js +0 -65
- package/lib/node/ai-core-backend-module.js.map +0 -1
- package/lib/node/backend-language-model-registry.d.ts +0 -13
- package/lib/node/backend-language-model-registry.d.ts.map +0 -1
- package/lib/node/backend-language-model-registry.js +0 -68
- package/lib/node/backend-language-model-registry.js.map +0 -1
- package/lib/node/language-model-frontend-delegate.d.ts +0 -18
- package/lib/node/language-model-frontend-delegate.d.ts.map +0 -1
- package/lib/node/language-model-frontend-delegate.js +0 -109
- package/lib/node/language-model-frontend-delegate.js.map +0 -1
- package/lib/node/token-usage-service-impl.d.ts +0 -23
- package/lib/node/token-usage-service-impl.d.ts.map +0 -1
- package/lib/node/token-usage-service-impl.js +0 -78
- package/lib/node/token-usage-service-impl.js.map +0 -1
- package/lib/node/tool-request-parameters.spec.d.ts +0 -2
- package/lib/node/tool-request-parameters.spec.d.ts.map +0 -1
- package/lib/node/tool-request-parameters.spec.js +0 -116
- package/lib/node/tool-request-parameters.spec.js.map +0 -1
|
@@ -1,653 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2024 EclipseSource GmbH.
|
|
4
|
-
//
|
|
5
|
-
// This program and the accompanying materials are made available under the
|
|
6
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
//
|
|
9
|
-
// This Source Code may also be made available under the following Secondary
|
|
10
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
// with the GNU Classpath Exception which is available at
|
|
13
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
//
|
|
15
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
-
// *****************************************************************************
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.PromptServiceImpl = exports.PromptService = exports.PromptFragmentCustomizationService = exports.CustomAgentDescription = exports.isCustomizedPromptFragment = exports.isBasePromptFragment = 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 variable_service_1 = require("./variable-service");
|
|
23
|
-
const tool_invocation_registry_1 = require("./tool-invocation-registry");
|
|
24
|
-
const language_model_util_1 = require("./language-model-util");
|
|
25
|
-
const prompt_service_util_1 = require("./prompt-service-util");
|
|
26
|
-
const settings_service_1 = require("./settings-service");
|
|
27
|
-
/**
|
|
28
|
-
* Type guard to check if a PromptFragment is a built-in fragment (not customized)
|
|
29
|
-
* @param fragment The fragment to check
|
|
30
|
-
* @returns True if the fragment is a basic BasePromptFragment (not customized)
|
|
31
|
-
*/
|
|
32
|
-
function isBasePromptFragment(fragment) {
|
|
33
|
-
return !('customizationId' in fragment && 'priority' in fragment);
|
|
34
|
-
}
|
|
35
|
-
exports.isBasePromptFragment = isBasePromptFragment;
|
|
36
|
-
/**
|
|
37
|
-
* Type guard to check if a PromptFragment is a CustomizedPromptFragment
|
|
38
|
-
* @param fragment The fragment to check
|
|
39
|
-
* @returns True if the fragment is a CustomizedPromptFragment
|
|
40
|
-
*/
|
|
41
|
-
function isCustomizedPromptFragment(fragment) {
|
|
42
|
-
return 'customizationId' in fragment && 'priority' in fragment;
|
|
43
|
-
}
|
|
44
|
-
exports.isCustomizedPromptFragment = isCustomizedPromptFragment;
|
|
45
|
-
var CustomAgentDescription;
|
|
46
|
-
(function (CustomAgentDescription) {
|
|
47
|
-
/**
|
|
48
|
-
* Type guard to check if an object is a CustomAgentDescription
|
|
49
|
-
*/
|
|
50
|
-
function is(entry) {
|
|
51
|
-
// eslint-disable-next-line no-null/no-null
|
|
52
|
-
return typeof entry === 'object' && entry !== null
|
|
53
|
-
&& 'id' in entry && typeof entry.id === 'string'
|
|
54
|
-
&& 'name' in entry && typeof entry.name === 'string'
|
|
55
|
-
&& 'description' in entry && typeof entry.description === 'string'
|
|
56
|
-
&& 'prompt' in entry && typeof entry.prompt === 'string'
|
|
57
|
-
&& 'defaultLLM' in entry && typeof entry.defaultLLM === 'string';
|
|
58
|
-
}
|
|
59
|
-
CustomAgentDescription.is = is;
|
|
60
|
-
/**
|
|
61
|
-
* Compares two CustomAgentDescription objects for equality
|
|
62
|
-
*/
|
|
63
|
-
function equals(a, b) {
|
|
64
|
-
return a.id === b.id && a.name === b.name && a.description === b.description && a.prompt === b.prompt && a.defaultLLM === b.defaultLLM;
|
|
65
|
-
}
|
|
66
|
-
CustomAgentDescription.equals = equals;
|
|
67
|
-
})(CustomAgentDescription || (exports.CustomAgentDescription = CustomAgentDescription = {}));
|
|
68
|
-
/**
|
|
69
|
-
* Service responsible for customizing prompt fragments
|
|
70
|
-
*/
|
|
71
|
-
exports.PromptFragmentCustomizationService = Symbol('PromptFragmentCustomizationService');
|
|
72
|
-
/**
|
|
73
|
-
* Service for managing and resolving prompt fragments
|
|
74
|
-
*/
|
|
75
|
-
exports.PromptService = Symbol('PromptService');
|
|
76
|
-
let PromptServiceImpl = class PromptServiceImpl {
|
|
77
|
-
constructor() {
|
|
78
|
-
// Map to store selected variant for each prompt variant set (key: promptVariantSetId, value: variantId)
|
|
79
|
-
this._selectedVariantsMap = new Map();
|
|
80
|
-
// Collection of built-in prompt fragments
|
|
81
|
-
this._builtInFragments = [];
|
|
82
|
-
// Map to store prompt variants sets (key: promptVariantSetId, value: array of variantIds)
|
|
83
|
-
this._promptVariantSetsMap = new Map();
|
|
84
|
-
// Map to store default variant for each prompt variant set (key: promptVariantSetId, value: variantId)
|
|
85
|
-
this._defaultVariantsMap = new Map();
|
|
86
|
-
// Event emitter for prompt changes
|
|
87
|
-
this._onPromptsChangeEmitter = new core_1.Emitter();
|
|
88
|
-
this.onPromptsChange = this._onPromptsChangeEmitter.event;
|
|
89
|
-
// Event emitter for selected variant changes
|
|
90
|
-
this._onSelectedVariantChangeEmitter = new core_1.Emitter();
|
|
91
|
-
this.onSelectedVariantChange = this._onSelectedVariantChangeEmitter.event;
|
|
92
|
-
this.toDispose = new core_1.DisposableCollection();
|
|
93
|
-
}
|
|
94
|
-
fireOnPromptsChangeDebounced() {
|
|
95
|
-
if (this.promptChangeDebounceTimer) {
|
|
96
|
-
clearTimeout(this.promptChangeDebounceTimer);
|
|
97
|
-
}
|
|
98
|
-
this.promptChangeDebounceTimer = setTimeout(() => {
|
|
99
|
-
this._onPromptsChangeEmitter.fire();
|
|
100
|
-
}, 300);
|
|
101
|
-
}
|
|
102
|
-
init() {
|
|
103
|
-
if (this.customizationService) {
|
|
104
|
-
this.toDispose.pushAll([
|
|
105
|
-
this.customizationService.onDidChangePromptFragmentCustomization(() => {
|
|
106
|
-
this.fireOnPromptsChangeDebounced();
|
|
107
|
-
}),
|
|
108
|
-
this.customizationService.onDidChangeCustomAgents(() => {
|
|
109
|
-
this.fireOnPromptsChangeDebounced();
|
|
110
|
-
})
|
|
111
|
-
]);
|
|
112
|
-
}
|
|
113
|
-
if (this.settingsService) {
|
|
114
|
-
this.recalculateSelectedVariantsMap();
|
|
115
|
-
this.toDispose.push(this.settingsService.onDidChange(async () => {
|
|
116
|
-
await this.recalculateSelectedVariantsMap();
|
|
117
|
-
}));
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Recalculates the selected variants map for all variant sets and fires the onSelectedVariantChangeEmitter
|
|
122
|
-
* if the selectedVariants field has changed.
|
|
123
|
-
*/
|
|
124
|
-
async recalculateSelectedVariantsMap() {
|
|
125
|
-
if (!this.settingsService) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const agentSettingsMap = await this.settingsService.getSettings();
|
|
129
|
-
const newSelectedVariants = new Map();
|
|
130
|
-
for (const agentSettings of Object.values(agentSettingsMap)) {
|
|
131
|
-
if (agentSettings.selectedVariants) {
|
|
132
|
-
for (const [variantSetId, variantId] of Object.entries(agentSettings.selectedVariants)) {
|
|
133
|
-
if (!newSelectedVariants.has(variantSetId)) {
|
|
134
|
-
newSelectedVariants.set(variantSetId, variantId);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
// Compare with the old map and fire events for changes and removed variant sets
|
|
140
|
-
for (const [variantSetId, newVariantId] of newSelectedVariants.entries()) {
|
|
141
|
-
const oldVariantId = this._selectedVariantsMap.get(variantSetId);
|
|
142
|
-
if (oldVariantId !== newVariantId) {
|
|
143
|
-
this._onSelectedVariantChangeEmitter.fire({ promptVariantSetId: variantSetId, variantId: newVariantId });
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
for (const oldVariantSetId of this._selectedVariantsMap.keys()) {
|
|
147
|
-
if (!newSelectedVariants.has(oldVariantSetId)) {
|
|
148
|
-
this._onSelectedVariantChangeEmitter.fire({ promptVariantSetId: oldVariantSetId, variantId: undefined });
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
this._selectedVariantsMap = newSelectedVariants;
|
|
152
|
-
// Also fire a full prompts change, because other fields (like effectiveVariantId) might have changed
|
|
153
|
-
this.fireOnPromptsChangeDebounced();
|
|
154
|
-
}
|
|
155
|
-
// ===== Fragment Retrieval Methods =====
|
|
156
|
-
/**
|
|
157
|
-
* Finds a built-in fragment by its ID
|
|
158
|
-
* @param fragmentId The ID of the fragment to find
|
|
159
|
-
* @returns The built-in fragment or undefined if not found
|
|
160
|
-
*/
|
|
161
|
-
findBuiltInFragmentById(fragmentId) {
|
|
162
|
-
return this._builtInFragments.find(fragment => fragment.id === fragmentId);
|
|
163
|
-
}
|
|
164
|
-
getRawPromptFragment(fragmentId) {
|
|
165
|
-
var _a;
|
|
166
|
-
if ((_a = this.customizationService) === null || _a === void 0 ? void 0 : _a.isPromptFragmentCustomized(fragmentId)) {
|
|
167
|
-
const customizedFragment = this.customizationService.getActivePromptFragmentCustomization(fragmentId);
|
|
168
|
-
if (customizedFragment !== undefined) {
|
|
169
|
-
return customizedFragment;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return this.getBuiltInRawPrompt(fragmentId);
|
|
173
|
-
}
|
|
174
|
-
getBuiltInRawPrompt(fragmentId) {
|
|
175
|
-
return this.findBuiltInFragmentById(fragmentId);
|
|
176
|
-
}
|
|
177
|
-
getPromptFragment(fragmentId) {
|
|
178
|
-
const rawFragment = this.getRawPromptFragment(fragmentId);
|
|
179
|
-
if (!rawFragment) {
|
|
180
|
-
return undefined;
|
|
181
|
-
}
|
|
182
|
-
return {
|
|
183
|
-
...rawFragment,
|
|
184
|
-
template: this.stripComments(rawFragment.template)
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
getPromptFragmentByCommandName(commandName) {
|
|
188
|
-
// First check customized fragments
|
|
189
|
-
if (this.customizationService) {
|
|
190
|
-
const customizedIds = this.customizationService.getCustomizedPromptFragmentIds();
|
|
191
|
-
for (const fragmentId of customizedIds) {
|
|
192
|
-
const fragment = this.customizationService.getActivePromptFragmentCustomization(fragmentId);
|
|
193
|
-
if ((fragment === null || fragment === void 0 ? void 0 : fragment.isCommand) && fragment.commandName === commandName) {
|
|
194
|
-
return fragment;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
// Then check built-in fragments
|
|
199
|
-
return this._builtInFragments.find(fragment => fragment.isCommand && fragment.commandName === commandName);
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Strips comments from a template string
|
|
203
|
-
* @param templateText The template text to process
|
|
204
|
-
* @returns Template text with comments removed
|
|
205
|
-
*/
|
|
206
|
-
stripComments(templateText) {
|
|
207
|
-
const commentRegex = /^\s*{{!--[\s\S]*?--}}\s*\n?/;
|
|
208
|
-
return commentRegex.test(templateText) ? templateText.replace(commentRegex, '').trimStart() : templateText;
|
|
209
|
-
}
|
|
210
|
-
getSelectedVariantId(variantSetId) {
|
|
211
|
-
return this._selectedVariantsMap.get(variantSetId);
|
|
212
|
-
}
|
|
213
|
-
getEffectiveVariantId(variantSetId) {
|
|
214
|
-
const selectedVariantId = this.getSelectedVariantId(variantSetId);
|
|
215
|
-
// Check if the selected variant actually exists
|
|
216
|
-
if (selectedVariantId) {
|
|
217
|
-
const variantIds = this.getVariantIds(variantSetId);
|
|
218
|
-
if (!variantIds.includes(selectedVariantId)) {
|
|
219
|
-
this.logger.warn(`Selected variant '${selectedVariantId}' for prompt set '${variantSetId}' does not exist. Falling back to default variant.`);
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
return selectedVariantId;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
// Fall back to default variant
|
|
226
|
-
const defaultVariantId = this.getDefaultVariantId(variantSetId);
|
|
227
|
-
if (defaultVariantId) {
|
|
228
|
-
const variantIds = this.getVariantIds(variantSetId);
|
|
229
|
-
if (!variantIds.includes(defaultVariantId)) {
|
|
230
|
-
this.logger.error(`Default variant '${defaultVariantId}' for prompt set '${variantSetId}' does not exist.`);
|
|
231
|
-
return undefined;
|
|
232
|
-
}
|
|
233
|
-
return defaultVariantId;
|
|
234
|
-
}
|
|
235
|
-
// No valid selected or default variant
|
|
236
|
-
if (this.getVariantIds(variantSetId).length > 0) {
|
|
237
|
-
this.logger.error(`No valid selected or default variant found for prompt set '${variantSetId}'.`);
|
|
238
|
-
}
|
|
239
|
-
return undefined;
|
|
240
|
-
}
|
|
241
|
-
resolvePotentialSystemPrompt(promptFragmentId) {
|
|
242
|
-
if (this._promptVariantSetsMap.has(promptFragmentId)) {
|
|
243
|
-
// This is a systemPrompt find the effective variant
|
|
244
|
-
const effectiveVariantId = this.getEffectiveVariantId(promptFragmentId);
|
|
245
|
-
if (effectiveVariantId === undefined) {
|
|
246
|
-
return undefined;
|
|
247
|
-
}
|
|
248
|
-
return this.getPromptFragment(effectiveVariantId);
|
|
249
|
-
}
|
|
250
|
-
return this.getPromptFragment(promptFragmentId);
|
|
251
|
-
}
|
|
252
|
-
// ===== Fragment Resolution Methods =====
|
|
253
|
-
async getResolvedPromptFragment(systemOrFragmentId, args, context) {
|
|
254
|
-
const promptFragment = this.resolvePotentialSystemPrompt(systemOrFragmentId);
|
|
255
|
-
if (promptFragment === undefined) {
|
|
256
|
-
return undefined;
|
|
257
|
-
}
|
|
258
|
-
// First resolve variables and arguments
|
|
259
|
-
let resolvedTemplate = promptFragment.template;
|
|
260
|
-
const variableAndArgResolutions = await this.resolveVariablesAndArgs(promptFragment.template, args, context);
|
|
261
|
-
variableAndArgResolutions.replacements.forEach(replacement => resolvedTemplate = resolvedTemplate.replace(replacement.placeholder, replacement.value));
|
|
262
|
-
// Then resolve function references with already resolved variables and arguments
|
|
263
|
-
// This allows to resolve function references contained in resolved variables (e.g. prompt fragments)
|
|
264
|
-
const functionMatches = (0, prompt_service_util_1.matchFunctionsRegEx)(resolvedTemplate);
|
|
265
|
-
const functionMap = new Map();
|
|
266
|
-
const functionReplacements = functionMatches.map(match => {
|
|
267
|
-
var _a;
|
|
268
|
-
const completeText = match[0];
|
|
269
|
-
const functionId = match[1];
|
|
270
|
-
const toolRequest = (_a = this.toolInvocationRegistry) === null || _a === void 0 ? void 0 : _a.getFunction(functionId);
|
|
271
|
-
if (toolRequest) {
|
|
272
|
-
functionMap.set(toolRequest.id, toolRequest);
|
|
273
|
-
}
|
|
274
|
-
return {
|
|
275
|
-
placeholder: completeText,
|
|
276
|
-
value: toolRequest ? (0, language_model_util_1.toolRequestToPromptText)(toolRequest) : completeText
|
|
277
|
-
};
|
|
278
|
-
});
|
|
279
|
-
functionReplacements.forEach(replacement => resolvedTemplate = resolvedTemplate.replace(replacement.placeholder, replacement.value));
|
|
280
|
-
return {
|
|
281
|
-
id: systemOrFragmentId,
|
|
282
|
-
text: resolvedTemplate,
|
|
283
|
-
functionDescriptions: functionMap.size > 0 ? functionMap : undefined,
|
|
284
|
-
variables: variableAndArgResolutions.resolvedVariables
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
async getResolvedPromptFragmentWithoutFunctions(systemOrFragmentId, args, context, resolveVariable) {
|
|
288
|
-
const promptFragment = this.resolvePotentialSystemPrompt(systemOrFragmentId);
|
|
289
|
-
if (promptFragment === undefined) {
|
|
290
|
-
return undefined;
|
|
291
|
-
}
|
|
292
|
-
const resolutions = await this.resolveVariablesAndArgs(promptFragment.template, args, context, resolveVariable);
|
|
293
|
-
let resolvedTemplate = promptFragment.template;
|
|
294
|
-
resolutions.replacements.forEach(replacement => resolvedTemplate = resolvedTemplate.replace(replacement.placeholder, replacement.value));
|
|
295
|
-
return {
|
|
296
|
-
id: systemOrFragmentId,
|
|
297
|
-
text: resolvedTemplate,
|
|
298
|
-
variables: resolutions.resolvedVariables
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Calculates all variable and argument replacements for an unresolved template.
|
|
303
|
-
*
|
|
304
|
-
* @param templateText the unresolved template text
|
|
305
|
-
* @param args the object with placeholders, mapping the placeholder key to the value
|
|
306
|
-
* @param context the {@link AIVariableContext} to use during variable resolution
|
|
307
|
-
* @param resolveVariable the variable resolving method. Fall back to using the {@link AIVariableService} if not given.
|
|
308
|
-
* @returns Object containing replacements and resolved variables
|
|
309
|
-
*/
|
|
310
|
-
async resolveVariablesAndArgs(templateText, args, context, resolveVariable) {
|
|
311
|
-
var _a, _b, _c;
|
|
312
|
-
const variableMatches = (0, prompt_service_util_1.matchVariablesRegEx)(templateText);
|
|
313
|
-
const variableCache = (0, variable_service_1.createAIResolveVariableCache)();
|
|
314
|
-
const replacementsList = [];
|
|
315
|
-
const resolvedVariablesSet = new Set();
|
|
316
|
-
for (const match of variableMatches) {
|
|
317
|
-
const placeholderText = match[0];
|
|
318
|
-
const variableAndArg = match[1];
|
|
319
|
-
let variableName = variableAndArg;
|
|
320
|
-
let argument;
|
|
321
|
-
const parts = variableAndArg.split(':', 2);
|
|
322
|
-
if (parts.length > 1) {
|
|
323
|
-
variableName = parts[0];
|
|
324
|
-
argument = parts[1];
|
|
325
|
-
}
|
|
326
|
-
let replacementValue;
|
|
327
|
-
if (args && args[variableAndArg] !== undefined) {
|
|
328
|
-
replacementValue = String(args[variableAndArg]);
|
|
329
|
-
}
|
|
330
|
-
else {
|
|
331
|
-
const variableToResolve = { variable: variableName, arg: argument };
|
|
332
|
-
const resolvedVariable = resolveVariable
|
|
333
|
-
? await resolveVariable(variableToResolve)
|
|
334
|
-
: await ((_a = this.variableService) === null || _a === void 0 ? void 0 : _a.resolveVariable(variableToResolve, context !== null && context !== void 0 ? context : {}, variableCache));
|
|
335
|
-
// Track resolved variable and its dependencies in all resolved variables
|
|
336
|
-
if (resolvedVariable) {
|
|
337
|
-
resolvedVariablesSet.add(resolvedVariable);
|
|
338
|
-
(_b = resolvedVariable.allResolvedDependencies) === null || _b === void 0 ? void 0 : _b.forEach(v => resolvedVariablesSet.add(v));
|
|
339
|
-
}
|
|
340
|
-
replacementValue = String((_c = resolvedVariable === null || resolvedVariable === void 0 ? void 0 : resolvedVariable.value) !== null && _c !== void 0 ? _c : placeholderText);
|
|
341
|
-
}
|
|
342
|
-
replacementsList.push({ placeholder: placeholderText, value: replacementValue });
|
|
343
|
-
}
|
|
344
|
-
return {
|
|
345
|
-
replacements: replacementsList,
|
|
346
|
-
resolvedVariables: Array.from(resolvedVariablesSet)
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
// ===== Fragment Collection Management Methods =====
|
|
350
|
-
getAllPromptFragments() {
|
|
351
|
-
const fragmentsMap = new Map();
|
|
352
|
-
if (this.customizationService) {
|
|
353
|
-
const customizationIds = this.customizationService.getCustomizedPromptFragmentIds();
|
|
354
|
-
customizationIds.forEach(fragmentId => {
|
|
355
|
-
const customizations = this.customizationService.getAllCustomizations(fragmentId);
|
|
356
|
-
if (customizations.length > 0) {
|
|
357
|
-
fragmentsMap.set(fragmentId, customizations);
|
|
358
|
-
}
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
// Add all built-in fragments
|
|
362
|
-
for (const fragment of this._builtInFragments) {
|
|
363
|
-
if (fragmentsMap.has(fragment.id)) {
|
|
364
|
-
fragmentsMap.get(fragment.id).push(fragment);
|
|
365
|
-
}
|
|
366
|
-
else {
|
|
367
|
-
fragmentsMap.set(fragment.id, [fragment]);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
return fragmentsMap;
|
|
371
|
-
}
|
|
372
|
-
getActivePromptFragments() {
|
|
373
|
-
var _a;
|
|
374
|
-
const activeFragments = [...this._builtInFragments];
|
|
375
|
-
if (this.customizationService) {
|
|
376
|
-
// Fetch all customized fragment IDs once
|
|
377
|
-
const customizedIds = this.customizationService.getCustomizedPromptFragmentIds();
|
|
378
|
-
// For each customized ID, get the active customization
|
|
379
|
-
for (const fragmentId of customizedIds) {
|
|
380
|
-
const customFragment = (_a = this.customizationService) === null || _a === void 0 ? void 0 : _a.getActivePromptFragmentCustomization(fragmentId);
|
|
381
|
-
if (customFragment) {
|
|
382
|
-
// Find and replace existing entry with the same ID instead of just adding
|
|
383
|
-
const existingIndex = activeFragments.findIndex(fragment => fragment.id === fragmentId);
|
|
384
|
-
if (existingIndex !== -1) {
|
|
385
|
-
// Replace existing fragment
|
|
386
|
-
activeFragments[existingIndex] = customFragment;
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
// Add new fragment if no existing one found
|
|
390
|
-
activeFragments.push(customFragment);
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
return activeFragments;
|
|
396
|
-
}
|
|
397
|
-
removePromptFragment(fragmentId) {
|
|
398
|
-
const index = this._builtInFragments.findIndex(fragment => fragment.id === fragmentId);
|
|
399
|
-
if (index !== -1) {
|
|
400
|
-
this._builtInFragments.splice(index, 1);
|
|
401
|
-
}
|
|
402
|
-
// Remove any variant references
|
|
403
|
-
for (const [promptVariantSetId, variants] of this._promptVariantSetsMap.entries()) {
|
|
404
|
-
if (variants.includes(fragmentId)) {
|
|
405
|
-
this.removeFragmentVariant(promptVariantSetId, fragmentId);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
// Clean up default variants map if needed
|
|
409
|
-
if (this._defaultVariantsMap.has(fragmentId)) {
|
|
410
|
-
this._defaultVariantsMap.delete(fragmentId);
|
|
411
|
-
}
|
|
412
|
-
// Look for this fragmentId as a variant in default variants and remove if found
|
|
413
|
-
for (const [promptVariantSetId, defaultVariantId] of this._defaultVariantsMap.entries()) {
|
|
414
|
-
if (defaultVariantId === fragmentId) {
|
|
415
|
-
this._defaultVariantsMap.delete(promptVariantSetId);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
this.fireOnPromptsChangeDebounced();
|
|
419
|
-
}
|
|
420
|
-
getVariantIds(variantSetId) {
|
|
421
|
-
const builtInVariants = this._promptVariantSetsMap.get(variantSetId) || [];
|
|
422
|
-
// Check for custom variants from customization service
|
|
423
|
-
if (this.customizationService) {
|
|
424
|
-
const allCustomizedIds = this.customizationService.getCustomizedPromptFragmentIds();
|
|
425
|
-
// Find customizations that start with the variant set ID
|
|
426
|
-
// These are considered variants of this variant set
|
|
427
|
-
// Only include IDs that are not the variant set ID itself, start with the variant set ID,
|
|
428
|
-
// and are not customizations of existing variants in this set
|
|
429
|
-
const customVariants = allCustomizedIds.filter(id => id !== variantSetId &&
|
|
430
|
-
id.startsWith(variantSetId) &&
|
|
431
|
-
!builtInVariants.includes(id));
|
|
432
|
-
if (customVariants.length > 0) {
|
|
433
|
-
// Combine built-in variants with custom variants, without modifying the internal state
|
|
434
|
-
return [...builtInVariants, ...customVariants];
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
return builtInVariants;
|
|
438
|
-
}
|
|
439
|
-
getDefaultVariantId(promptVariantSetId) {
|
|
440
|
-
return this._defaultVariantsMap.get(promptVariantSetId);
|
|
441
|
-
}
|
|
442
|
-
getPromptVariantSets() {
|
|
443
|
-
const result = new Map(this._promptVariantSetsMap);
|
|
444
|
-
// Check for custom variants from customization service
|
|
445
|
-
if (this.customizationService) {
|
|
446
|
-
const allCustomizedIds = this.customizationService.getCustomizedPromptFragmentIds();
|
|
447
|
-
// Add custom variants to existing variant sets
|
|
448
|
-
for (const [variantSetId, variants] of result.entries()) {
|
|
449
|
-
// Filter out customized fragments that are just customizations of existing variants
|
|
450
|
-
// so we don't treat them as separate variants themselves
|
|
451
|
-
// Only include IDs that are not the variant set ID itself, start with the variant set ID,
|
|
452
|
-
// and are not customizations of existing variants in this set
|
|
453
|
-
const customVariants = allCustomizedIds.filter(id => id !== variantSetId &&
|
|
454
|
-
id.startsWith(variantSetId) &&
|
|
455
|
-
!variants.includes(id));
|
|
456
|
-
if (customVariants.length > 0) {
|
|
457
|
-
// Create a new array without modifying the original
|
|
458
|
-
result.set(variantSetId, [...variants, ...customVariants]);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
return result;
|
|
463
|
-
}
|
|
464
|
-
addBuiltInPromptFragment(promptFragment, promptVariantSetId, isDefault = false) {
|
|
465
|
-
const existingIndex = this._builtInFragments.findIndex(fragment => fragment.id === promptFragment.id);
|
|
466
|
-
if (existingIndex !== -1) {
|
|
467
|
-
// Replace existing fragment with the same ID
|
|
468
|
-
this._builtInFragments[existingIndex] = promptFragment;
|
|
469
|
-
}
|
|
470
|
-
else {
|
|
471
|
-
// Add new fragment
|
|
472
|
-
this._builtInFragments.push(promptFragment);
|
|
473
|
-
}
|
|
474
|
-
// Validate command name uniqueness if this is a command
|
|
475
|
-
if (promptFragment.isCommand && promptFragment.commandName) {
|
|
476
|
-
const commandName = promptFragment.commandName;
|
|
477
|
-
const duplicates = this._builtInFragments.filter(f => f.isCommand && f.commandName === commandName && f.id !== promptFragment.id);
|
|
478
|
-
if (duplicates.length > 0) {
|
|
479
|
-
this.logger.warn(`Command name '${commandName}' is used by multiple fragments: ${promptFragment.id} and ${duplicates.map(d => d.id).join(', ')}`);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
// If this is a variant of a prompt variant set, record it in the variants map
|
|
483
|
-
if (promptVariantSetId) {
|
|
484
|
-
this.addFragmentVariant(promptVariantSetId, promptFragment.id, isDefault);
|
|
485
|
-
}
|
|
486
|
-
this.fireOnPromptsChangeDebounced();
|
|
487
|
-
}
|
|
488
|
-
// ===== Variant Management Methods =====
|
|
489
|
-
/**
|
|
490
|
-
* Adds a variant ID to the fragment variants map
|
|
491
|
-
* @param promptVariantSetId The prompt variant set id
|
|
492
|
-
* @param variantId The variant ID to add
|
|
493
|
-
* @param isDefault Whether this variant should be the default for the prompt variant set (defaults to false)
|
|
494
|
-
*/
|
|
495
|
-
addFragmentVariant(promptVariantSetId, variantId, isDefault = false) {
|
|
496
|
-
if (!this._promptVariantSetsMap.has(promptVariantSetId)) {
|
|
497
|
-
this._promptVariantSetsMap.set(promptVariantSetId, []);
|
|
498
|
-
}
|
|
499
|
-
const variants = this._promptVariantSetsMap.get(promptVariantSetId);
|
|
500
|
-
if (!variants.includes(variantId)) {
|
|
501
|
-
variants.push(variantId);
|
|
502
|
-
}
|
|
503
|
-
if (isDefault) {
|
|
504
|
-
this._defaultVariantsMap.set(promptVariantSetId, variantId);
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
/**
|
|
508
|
-
* Removes a variant ID from the fragment variants map
|
|
509
|
-
* @param promptVariantSetId The prompt variant set id
|
|
510
|
-
* @param variantId The variant ID to remove
|
|
511
|
-
*/
|
|
512
|
-
removeFragmentVariant(promptVariantSetId, variantId) {
|
|
513
|
-
if (!this._promptVariantSetsMap.has(promptVariantSetId)) {
|
|
514
|
-
return;
|
|
515
|
-
}
|
|
516
|
-
const variants = this._promptVariantSetsMap.get(promptVariantSetId);
|
|
517
|
-
const index = variants.indexOf(variantId);
|
|
518
|
-
if (index !== -1) {
|
|
519
|
-
variants.splice(index, 1);
|
|
520
|
-
// Remove the key if no variants left
|
|
521
|
-
if (variants.length === 0) {
|
|
522
|
-
this._promptVariantSetsMap.delete(promptVariantSetId);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
async updateSelectedVariantId(agentId, promptVariantSetId, newVariant) {
|
|
527
|
-
if (!this.settingsService) {
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
const defaultVariantId = this.getDefaultVariantId(promptVariantSetId);
|
|
531
|
-
const agentSettings = await this.settingsService.getAgentSettings(agentId);
|
|
532
|
-
const selectedVariants = (agentSettings === null || agentSettings === void 0 ? void 0 : agentSettings.selectedVariants) || {};
|
|
533
|
-
const updatedVariants = { ...selectedVariants };
|
|
534
|
-
if (newVariant === defaultVariantId) {
|
|
535
|
-
delete updatedVariants[promptVariantSetId];
|
|
536
|
-
}
|
|
537
|
-
else {
|
|
538
|
-
updatedVariants[promptVariantSetId] = newVariant;
|
|
539
|
-
}
|
|
540
|
-
await this.settingsService.updateAgentSettings(agentId, {
|
|
541
|
-
selectedVariants: updatedVariants,
|
|
542
|
-
});
|
|
543
|
-
// Emit the selected variant change event
|
|
544
|
-
this._onSelectedVariantChangeEmitter.fire({ promptVariantSetId, variantId: newVariant });
|
|
545
|
-
}
|
|
546
|
-
// ===== Customization Service Delegation Methods =====
|
|
547
|
-
async createCustomization(fragmentId) {
|
|
548
|
-
if (this.customizationService) {
|
|
549
|
-
await this.customizationService.createPromptFragmentCustomization(fragmentId);
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
async createBuiltInCustomization(fragmentId) {
|
|
553
|
-
if (this.customizationService) {
|
|
554
|
-
const builtInTemplate = this.findBuiltInFragmentById(fragmentId);
|
|
555
|
-
await this.customizationService.createBuiltInPromptFragmentCustomization(fragmentId, builtInTemplate === null || builtInTemplate === void 0 ? void 0 : builtInTemplate.template);
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
async editCustomization(fragmentId, customizationId) {
|
|
559
|
-
if (this.customizationService) {
|
|
560
|
-
await this.customizationService.editPromptFragmentCustomization(fragmentId, customizationId);
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
async removeCustomization(fragmentId, customizationId) {
|
|
564
|
-
if (this.customizationService) {
|
|
565
|
-
await this.customizationService.removePromptFragmentCustomization(fragmentId, customizationId);
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
async resetAllToBuiltIn() {
|
|
569
|
-
if (this.customizationService) {
|
|
570
|
-
for (const fragment of this._builtInFragments) {
|
|
571
|
-
await this.customizationService.removeAllPromptFragmentCustomizations(fragment.id);
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
async resetToBuiltIn(fragmentId) {
|
|
576
|
-
const builtIn = this._builtInFragments.find(b => b.id === fragmentId);
|
|
577
|
-
// Only reset this if it has a built-in, otherwise a delete would be the correct operation
|
|
578
|
-
if (this.customizationService && builtIn) {
|
|
579
|
-
await this.customizationService.removeAllPromptFragmentCustomizations(fragmentId);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
async resetToCustomization(fragmentId, customizationId) {
|
|
583
|
-
if (this.customizationService) {
|
|
584
|
-
await this.customizationService.resetToCustomization(fragmentId, customizationId);
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
async getCustomizationDescription(fragmentId, customizationId) {
|
|
588
|
-
if (!this.customizationService) {
|
|
589
|
-
return undefined;
|
|
590
|
-
}
|
|
591
|
-
return await this.customizationService.getPromptFragmentCustomizationDescription(fragmentId, customizationId);
|
|
592
|
-
}
|
|
593
|
-
async getCustomizationType(fragmentId, customizationId) {
|
|
594
|
-
if (!this.customizationService) {
|
|
595
|
-
return undefined;
|
|
596
|
-
}
|
|
597
|
-
return await this.customizationService.getPromptFragmentCustomizationType(fragmentId, customizationId);
|
|
598
|
-
}
|
|
599
|
-
getTemplateIDFromResource(resourceId) {
|
|
600
|
-
if (this.customizationService) {
|
|
601
|
-
return this.customizationService.getPromptFragmentIDFromResource(resourceId);
|
|
602
|
-
}
|
|
603
|
-
return undefined;
|
|
604
|
-
}
|
|
605
|
-
async editBuiltInCustomization(fragmentId) {
|
|
606
|
-
if (this.customizationService) {
|
|
607
|
-
const builtInTemplate = this.findBuiltInFragmentById(fragmentId);
|
|
608
|
-
await this.customizationService.editBuiltInPromptFragmentCustomization(fragmentId, builtInTemplate === null || builtInTemplate === void 0 ? void 0 : builtInTemplate.template);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
getCommands(agentId) {
|
|
612
|
-
const allCommands = this.getActivePromptFragments().filter(fragment => fragment.isCommand === true);
|
|
613
|
-
if (!agentId) {
|
|
614
|
-
return allCommands;
|
|
615
|
-
}
|
|
616
|
-
return allCommands.filter(fragment => !fragment.commandAgents || fragment.commandAgents.includes(agentId));
|
|
617
|
-
}
|
|
618
|
-
};
|
|
619
|
-
exports.PromptServiceImpl = PromptServiceImpl;
|
|
620
|
-
tslib_1.__decorate([
|
|
621
|
-
(0, inversify_1.inject)(core_1.ILogger),
|
|
622
|
-
tslib_1.__metadata("design:type", Object)
|
|
623
|
-
], PromptServiceImpl.prototype, "logger", void 0);
|
|
624
|
-
tslib_1.__decorate([
|
|
625
|
-
(0, inversify_1.inject)(settings_service_1.AISettingsService),
|
|
626
|
-
(0, inversify_1.optional)(),
|
|
627
|
-
tslib_1.__metadata("design:type", Object)
|
|
628
|
-
], PromptServiceImpl.prototype, "settingsService", void 0);
|
|
629
|
-
tslib_1.__decorate([
|
|
630
|
-
(0, inversify_1.inject)(exports.PromptFragmentCustomizationService),
|
|
631
|
-
(0, inversify_1.optional)(),
|
|
632
|
-
tslib_1.__metadata("design:type", Object)
|
|
633
|
-
], PromptServiceImpl.prototype, "customizationService", void 0);
|
|
634
|
-
tslib_1.__decorate([
|
|
635
|
-
(0, inversify_1.inject)(variable_service_1.AIVariableService),
|
|
636
|
-
(0, inversify_1.optional)(),
|
|
637
|
-
tslib_1.__metadata("design:type", Object)
|
|
638
|
-
], PromptServiceImpl.prototype, "variableService", void 0);
|
|
639
|
-
tslib_1.__decorate([
|
|
640
|
-
(0, inversify_1.inject)(tool_invocation_registry_1.ToolInvocationRegistry),
|
|
641
|
-
(0, inversify_1.optional)(),
|
|
642
|
-
tslib_1.__metadata("design:type", Object)
|
|
643
|
-
], PromptServiceImpl.prototype, "toolInvocationRegistry", void 0);
|
|
644
|
-
tslib_1.__decorate([
|
|
645
|
-
(0, inversify_1.postConstruct)(),
|
|
646
|
-
tslib_1.__metadata("design:type", Function),
|
|
647
|
-
tslib_1.__metadata("design:paramtypes", []),
|
|
648
|
-
tslib_1.__metadata("design:returntype", void 0)
|
|
649
|
-
], PromptServiceImpl.prototype, "init", null);
|
|
650
|
-
exports.PromptServiceImpl = PromptServiceImpl = tslib_1.__decorate([
|
|
651
|
-
(0, inversify_1.injectable)()
|
|
652
|
-
], PromptServiceImpl);
|
|
653
|
-
//# sourceMappingURL=prompt-service.js.map
|