@mlightcad/cad-llm-plugin 0.0.0-stage → 1.8.0-preview.4
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/LICENSE +21 -0
- package/README.md +71 -3
- package/dist/cad-llm-plugin-register.js +613 -0
- package/dist/cad-llm-plugin-register.umd.cjs +1 -0
- package/dist/cad-llm-plugin.js +21481 -0
- package/dist/cad-llm-plugin.umd.cjs +514 -0
- package/lib/AcApLlmPlugin.d.ts +39 -0
- package/lib/AcApLlmPlugin.d.ts.map +1 -0
- package/lib/AcApLlmPlugin.js +119 -0
- package/lib/AcApLlmPlugin.js.map +1 -0
- package/lib/AcApLlmTextRecognizer.d.ts +43 -0
- package/lib/AcApLlmTextRecognizer.d.ts.map +1 -0
- package/lib/AcApLlmTextRecognizer.js +303 -0
- package/lib/AcApLlmTextRecognizer.js.map +1 -0
- package/lib/command/AcApLlmSettingsCmd.d.ts +16 -0
- package/lib/command/AcApLlmSettingsCmd.d.ts.map +1 -0
- package/lib/command/AcApLlmSettingsCmd.js +114 -0
- package/lib/command/AcApLlmSettingsCmd.js.map +1 -0
- package/lib/constants.d.ts +7 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +7 -0
- package/lib/constants.js.map +1 -0
- package/lib/i18n/ar.d.ts +77 -0
- package/lib/i18n/ar.d.ts.map +1 -0
- package/lib/i18n/ar.js +77 -0
- package/lib/i18n/ar.js.map +1 -0
- package/lib/i18n/command.d.ts +30 -0
- package/lib/i18n/command.d.ts.map +1 -0
- package/lib/i18n/command.js +30 -0
- package/lib/i18n/command.js.map +1 -0
- package/lib/i18n/cs.d.ts +77 -0
- package/lib/i18n/cs.d.ts.map +1 -0
- package/lib/i18n/cs.js +77 -0
- package/lib/i18n/cs.js.map +1 -0
- package/lib/i18n/en.d.ts +82 -0
- package/lib/i18n/en.d.ts.map +1 -0
- package/lib/i18n/en.js +82 -0
- package/lib/i18n/en.js.map +1 -0
- package/lib/i18n/index.d.ts +29 -0
- package/lib/i18n/index.d.ts.map +1 -0
- package/lib/i18n/index.js +142 -0
- package/lib/i18n/index.js.map +1 -0
- package/lib/i18n/ja.d.ts +77 -0
- package/lib/i18n/ja.d.ts.map +1 -0
- package/lib/i18n/ja.js +77 -0
- package/lib/i18n/ja.js.map +1 -0
- package/lib/i18n/ko.d.ts +77 -0
- package/lib/i18n/ko.d.ts.map +1 -0
- package/lib/i18n/ko.js +77 -0
- package/lib/i18n/ko.js.map +1 -0
- package/lib/i18n/tr.d.ts +77 -0
- package/lib/i18n/tr.d.ts.map +1 -0
- package/lib/i18n/tr.js +77 -0
- package/lib/i18n/tr.js.map +1 -0
- package/lib/i18n/zh.d.ts +77 -0
- package/lib/i18n/zh.d.ts.map +1 -0
- package/lib/i18n/zh.js +77 -0
- package/lib/i18n/zh.js.map +1 -0
- package/lib/index.d.ts +25 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +25 -0
- package/lib/index.js.map +1 -0
- package/lib/model/AcApLlmModelFactory.d.ts +14 -0
- package/lib/model/AcApLlmModelFactory.d.ts.map +1 -0
- package/lib/model/AcApLlmModelFactory.js +46 -0
- package/lib/model/AcApLlmModelFactory.js.map +1 -0
- package/lib/model/AcApLlmModelListing.d.ts +67 -0
- package/lib/model/AcApLlmModelListing.d.ts.map +1 -0
- package/lib/model/AcApLlmModelListing.js +275 -0
- package/lib/model/AcApLlmModelListing.js.map +1 -0
- package/lib/model/anthropicBrowserAccess.d.ts +8 -0
- package/lib/model/anthropicBrowserAccess.d.ts.map +1 -0
- package/lib/model/anthropicBrowserAccess.js +8 -0
- package/lib/model/anthropicBrowserAccess.js.map +1 -0
- package/lib/model/normalizeLlmBaseUrl.d.ts +17 -0
- package/lib/model/normalizeLlmBaseUrl.d.ts.map +1 -0
- package/lib/model/normalizeLlmBaseUrl.js +31 -0
- package/lib/model/normalizeLlmBaseUrl.js.map +1 -0
- package/lib/model/openAiCompatibleFetch.d.ts +11 -0
- package/lib/model/openAiCompatibleFetch.d.ts.map +1 -0
- package/lib/model/openAiCompatibleFetch.js +122 -0
- package/lib/model/openAiCompatibleFetch.js.map +1 -0
- package/lib/model/skipDataUrlDownload.d.ts +12 -0
- package/lib/model/skipDataUrlDownload.d.ts.map +1 -0
- package/lib/model/skipDataUrlDownload.js +58 -0
- package/lib/model/skipDataUrlDownload.js.map +1 -0
- package/lib/register.d.ts +20 -0
- package/lib/register.d.ts.map +1 -0
- package/lib/register.js +139 -0
- package/lib/register.js.map +1 -0
- package/lib/storage/AcApLlmConfigStore.d.ts +218 -0
- package/lib/storage/AcApLlmConfigStore.d.ts.map +1 -0
- package/lib/storage/AcApLlmConfigStore.js +637 -0
- package/lib/storage/AcApLlmConfigStore.js.map +1 -0
- package/lib/storage/AcApLlmModelCatalog.d.ts +68 -0
- package/lib/storage/AcApLlmModelCatalog.d.ts.map +1 -0
- package/lib/storage/AcApLlmModelCatalog.js +141 -0
- package/lib/storage/AcApLlmModelCatalog.js.map +1 -0
- package/lib/storage/apiKeyCrypto.d.ts +28 -0
- package/lib/storage/apiKeyCrypto.d.ts.map +1 -0
- package/lib/storage/apiKeyCrypto.js +214 -0
- package/lib/storage/apiKeyCrypto.js.map +1 -0
- package/lib/storage/settingsEquality.d.ts +10 -0
- package/lib/storage/settingsEquality.d.ts.map +1 -0
- package/lib/storage/settingsEquality.js +36 -0
- package/lib/storage/settingsEquality.js.map +1 -0
- package/lib/ui/AcApLlmModelChoices.d.ts +31 -0
- package/lib/ui/AcApLlmModelChoices.d.ts.map +1 -0
- package/lib/ui/AcApLlmModelChoices.js +68 -0
- package/lib/ui/AcApLlmModelChoices.js.map +1 -0
- package/lib/ui/AcApLlmProviderLabels.d.ts +19 -0
- package/lib/ui/AcApLlmProviderLabels.d.ts.map +1 -0
- package/lib/ui/AcApLlmProviderLabels.js +34 -0
- package/lib/ui/AcApLlmProviderLabels.js.map +1 -0
- package/lib/ui/AcUiLlmSettingsDialog.d.ts +125 -0
- package/lib/ui/AcUiLlmSettingsDialog.d.ts.map +1 -0
- package/lib/ui/AcUiLlmSettingsDialog.js +1218 -0
- package/lib/ui/AcUiLlmSettingsDialog.js.map +1 -0
- package/lib/ui/llmSettingsStyles.d.ts +6 -0
- package/lib/ui/llmSettingsStyles.d.ts.map +1 -0
- package/lib/ui/llmSettingsStyles.js +6 -0
- package/lib/ui/llmSettingsStyles.js.map +1 -0
- package/package.json +54 -3
|
@@ -0,0 +1,1218 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var __assign = (this && this.__assign) || function () {
|
|
17
|
+
__assign = Object.assign || function(t) {
|
|
18
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
+
s = arguments[i];
|
|
20
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
+
t[p] = s[p];
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
};
|
|
25
|
+
return __assign.apply(this, arguments);
|
|
26
|
+
};
|
|
27
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
28
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
29
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
30
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
31
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
32
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
33
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
37
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
38
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
39
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
40
|
+
function step(op) {
|
|
41
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
42
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
43
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
44
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
45
|
+
switch (op[0]) {
|
|
46
|
+
case 0: case 1: t = op; break;
|
|
47
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
48
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
49
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
50
|
+
default:
|
|
51
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
52
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
53
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
54
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
55
|
+
if (t[2]) _.ops.pop();
|
|
56
|
+
_.trys.pop(); continue;
|
|
57
|
+
}
|
|
58
|
+
op = body.call(thisArg, _);
|
|
59
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
60
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var __values = (this && this.__values) || function(o) {
|
|
64
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
65
|
+
if (m) return m.call(o);
|
|
66
|
+
if (o && typeof o.length === "number") return {
|
|
67
|
+
next: function () {
|
|
68
|
+
if (o && i >= o.length) o = void 0;
|
|
69
|
+
return { value: o && o[i++], done: !o };
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
73
|
+
};
|
|
74
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
75
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
76
|
+
if (!m) return o;
|
|
77
|
+
var i = m.call(o), r, ar = [], e;
|
|
78
|
+
try {
|
|
79
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
80
|
+
}
|
|
81
|
+
catch (error) { e = { error: error }; }
|
|
82
|
+
finally {
|
|
83
|
+
try {
|
|
84
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
85
|
+
}
|
|
86
|
+
finally { if (e) throw e.error; }
|
|
87
|
+
}
|
|
88
|
+
return ar;
|
|
89
|
+
};
|
|
90
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
91
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
92
|
+
if (ar || !(i in from)) {
|
|
93
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
94
|
+
ar[i] = from[i];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
98
|
+
};
|
|
99
|
+
import { AcUiDialog } from '@mlightcad/cad-simple-viewer';
|
|
100
|
+
import { llmT } from '../i18n';
|
|
101
|
+
import { acapLlmFetchAvailableModels, AcApLlmModelListingError } from '../model/AcApLlmModelListing';
|
|
102
|
+
import { ACAP_LLM_CUSTOM_PROVIDER_ID_PATTERN, acapLlmCreateBuiltinProvider, acapLlmCreateCustomProvider, acapLlmEffectiveBaseUrl, acapLlmEffectiveModels, acapLlmLoadConfig, acapLlmRemoveProvider, acapLlmResolveVisionSettings, acapLlmSaveConfig, acapLlmUpsertProvider } from '../storage/AcApLlmConfigStore';
|
|
103
|
+
import { ACAP_LLM_API_PROTOCOLS, ACAP_LLM_BUILTIN_PROVIDER_IDS, ACAP_LLM_BUILTIN_PROVIDERS, acapLlmGuessModelVision, acapLlmIsBuiltinProviderId, acapLlmVisionAfterIdEdit } from '../storage/AcApLlmModelCatalog';
|
|
104
|
+
import { acapLlmAreProvidersEqual } from '../storage/settingsEquality';
|
|
105
|
+
import { acapLlmModelChoices } from './AcApLlmModelChoices';
|
|
106
|
+
import { acapLlmBuiltinProviderLabel, acapLlmProviderLabel } from './AcApLlmProviderLabels';
|
|
107
|
+
import { LLM_SETTINGS_STYLES } from './llmSettingsStyles';
|
|
108
|
+
var PROTOCOL_LABEL_KEYS = {
|
|
109
|
+
'openai-chat': 'protocolOpenaiChat',
|
|
110
|
+
'openai-responses': 'protocolOpenaiResponses',
|
|
111
|
+
'anthropic-messages': 'protocolAnthropicMessages'
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Separates provider id and model id in model `<option>` values. A newline
|
|
115
|
+
* cannot be typed into the single-line inputs ids come from.
|
|
116
|
+
*/
|
|
117
|
+
var MODEL_VALUE_SEPARATOR = '\n';
|
|
118
|
+
var ICON_CHEVRON = 'M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6z';
|
|
119
|
+
var ICON_CLOSE = 'M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z';
|
|
120
|
+
var ICON_PLUS = 'M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z';
|
|
121
|
+
/** Deep copy so draft edits never reach the saved config. */
|
|
122
|
+
function cloneProvider(provider) {
|
|
123
|
+
return __assign(__assign({}, provider), { models: provider.models
|
|
124
|
+
? provider.models.map(function (model) { return (__assign({}, model)); })
|
|
125
|
+
: null });
|
|
126
|
+
}
|
|
127
|
+
/** Catalog with blank rows dropped and ids trimmed and de-duplicated. */
|
|
128
|
+
function cleanModels(models) {
|
|
129
|
+
var e_1, _a;
|
|
130
|
+
var _b;
|
|
131
|
+
var seen = new Set();
|
|
132
|
+
var result = [];
|
|
133
|
+
try {
|
|
134
|
+
for (var models_1 = __values(models), models_1_1 = models_1.next(); !models_1_1.done; models_1_1 = models_1.next()) {
|
|
135
|
+
var model = models_1_1.value;
|
|
136
|
+
var id = model.id.trim();
|
|
137
|
+
if (!id || seen.has(id))
|
|
138
|
+
continue;
|
|
139
|
+
seen.add(id);
|
|
140
|
+
var name_1 = (_b = model.name) === null || _b === void 0 ? void 0 : _b.trim();
|
|
141
|
+
result.push(__assign(__assign({ id: id }, (name_1 ? { name: name_1 } : {})), { vision: model.vision }));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
145
|
+
finally {
|
|
146
|
+
try {
|
|
147
|
+
if (models_1_1 && !models_1_1.done && (_a = models_1.return)) _a.call(models_1);
|
|
148
|
+
}
|
|
149
|
+
finally { if (e_1) throw e_1.error; }
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
function isHttpUrl(value) {
|
|
154
|
+
try {
|
|
155
|
+
var protocol = new URL(value).protocol;
|
|
156
|
+
return protocol === 'http:' || protocol === 'https:';
|
|
157
|
+
}
|
|
158
|
+
catch (_a) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** Creates an element with a class name and optional text. */
|
|
163
|
+
function h(tag, className, text) {
|
|
164
|
+
if (className === void 0) { className = ''; }
|
|
165
|
+
var element = document.createElement(tag);
|
|
166
|
+
if (className)
|
|
167
|
+
element.className = className;
|
|
168
|
+
if (text !== undefined)
|
|
169
|
+
element.textContent = text;
|
|
170
|
+
return element;
|
|
171
|
+
}
|
|
172
|
+
function svgIcon(path, className) {
|
|
173
|
+
if (className === void 0) { className = ''; }
|
|
174
|
+
var ns = 'http://www.w3.org/2000/svg';
|
|
175
|
+
var svg = document.createElementNS(ns, 'svg');
|
|
176
|
+
svg.setAttribute('viewBox', '0 0 24 24');
|
|
177
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
178
|
+
if (className)
|
|
179
|
+
svg.setAttribute('class', className);
|
|
180
|
+
var shape = document.createElementNS(ns, 'path');
|
|
181
|
+
shape.setAttribute('fill', 'currentColor');
|
|
182
|
+
shape.setAttribute('d', path);
|
|
183
|
+
svg.appendChild(shape);
|
|
184
|
+
return svg;
|
|
185
|
+
}
|
|
186
|
+
function button(className, text, onClick) {
|
|
187
|
+
var element = h('button', className, text);
|
|
188
|
+
element.type = 'button';
|
|
189
|
+
element.addEventListener('click', onClick);
|
|
190
|
+
return element;
|
|
191
|
+
}
|
|
192
|
+
function textInput(value, onInput, options) {
|
|
193
|
+
var _a;
|
|
194
|
+
if (options === void 0) { options = {}; }
|
|
195
|
+
var input = h('input');
|
|
196
|
+
input.type = (_a = options.type) !== null && _a !== void 0 ? _a : 'text';
|
|
197
|
+
input.value = value;
|
|
198
|
+
input.spellcheck = false;
|
|
199
|
+
if (options.secret)
|
|
200
|
+
input.autocomplete = 'off';
|
|
201
|
+
if (options.placeholder)
|
|
202
|
+
input.placeholder = options.placeholder;
|
|
203
|
+
input.addEventListener('input', function () { return onInput(input.value); });
|
|
204
|
+
return input;
|
|
205
|
+
}
|
|
206
|
+
/** Wraps a control with a field label. */
|
|
207
|
+
function field(label, control) {
|
|
208
|
+
var wrapper = h('label', 'ml-llm-field');
|
|
209
|
+
wrapper.append(h('span', 'ml-llm-field-label', label), control);
|
|
210
|
+
return wrapper;
|
|
211
|
+
}
|
|
212
|
+
/** Lays out two fields side by side. */
|
|
213
|
+
function fieldRow() {
|
|
214
|
+
var fields = [];
|
|
215
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
216
|
+
fields[_i] = arguments[_i];
|
|
217
|
+
}
|
|
218
|
+
var row = h('div', 'ml-llm-field-row');
|
|
219
|
+
row.append.apply(row, __spreadArray([], __read(fields), false));
|
|
220
|
+
return row;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Framework-free dialog for the shared AI model settings.
|
|
224
|
+
*
|
|
225
|
+
* The top section picks the model in use (chat and, when it accepts images,
|
|
226
|
+
* text recognition). Below it, a provider editor offers two modes: a built-in
|
|
227
|
+
* provider that only needs an API key (with an optional base URL override),
|
|
228
|
+
* and a custom OpenAI / Anthropic compatible API declared by the user. Both
|
|
229
|
+
* edit the provider's model catalog, which can be filled from the provider's
|
|
230
|
+
* own model listing.
|
|
231
|
+
*
|
|
232
|
+
* Changes are written with {@link acapLlmSaveConfig}, which notifies every
|
|
233
|
+
* other view of the config (for example the agent panel).
|
|
234
|
+
*/
|
|
235
|
+
var AcUiLlmSettingsDialog = /** @class */ (function (_super) {
|
|
236
|
+
__extends(AcUiLlmSettingsDialog, _super);
|
|
237
|
+
function AcUiLlmSettingsDialog(config, options) {
|
|
238
|
+
var _a, _b, _c;
|
|
239
|
+
var _this = _super.call(this, {
|
|
240
|
+
host: options.host,
|
|
241
|
+
title: llmT('title'),
|
|
242
|
+
closeLabel: llmT('close'),
|
|
243
|
+
dialogClassName: 'ml-llm-settings-dialog'
|
|
244
|
+
}) || this;
|
|
245
|
+
_this.fetching = false;
|
|
246
|
+
_this.fetchError = '';
|
|
247
|
+
_this.candidates = null;
|
|
248
|
+
/** Candidate ids whose checkbox the user flipped from its default. */
|
|
249
|
+
_this.flipped = new Set();
|
|
250
|
+
_this.candidateQuery = '';
|
|
251
|
+
_this.statusMessage = '';
|
|
252
|
+
/** Refreshes text and state that depend on the drafts, without rebuilding. */
|
|
253
|
+
_this.updaters = [];
|
|
254
|
+
AcUiLlmSettingsDialog.ensureSettingsStyles();
|
|
255
|
+
_this.config = config;
|
|
256
|
+
var activeId = config.activeProviderId;
|
|
257
|
+
_this.mode = acapLlmIsBuiltinProviderId(activeId) ? 'builtin' : 'custom';
|
|
258
|
+
_this.builtinId = acapLlmIsBuiltinProviderId(activeId)
|
|
259
|
+
? activeId
|
|
260
|
+
: 'deepseek';
|
|
261
|
+
_this.customId =
|
|
262
|
+
((_a = _this.storedProvider(activeId)) === null || _a === void 0 ? void 0 : _a.kind) === 'custom'
|
|
263
|
+
? activeId
|
|
264
|
+
: ((_c = (_b = _this.customProviders()[0]) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : '');
|
|
265
|
+
_this.builtinDraft = _this.loadBuiltin(_this.builtinId);
|
|
266
|
+
_this.customDraft = _this.loadCustom(_this.customId);
|
|
267
|
+
_this.showAdvanced = _this.builtinDraft.baseUrl.trim().length > 0;
|
|
268
|
+
_this.render();
|
|
269
|
+
// Start on the model picker so keyboard users land inside the dialog.
|
|
270
|
+
var first = _this.bodyEl.querySelector('select, input');
|
|
271
|
+
if (first)
|
|
272
|
+
_this.focusAfterOpen(first);
|
|
273
|
+
return _this;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Opens the dialog, or returns the promise of the one already open.
|
|
277
|
+
*
|
|
278
|
+
* @param options - Host element.
|
|
279
|
+
* @returns Promise that resolves when the dialog is closed.
|
|
280
|
+
*/
|
|
281
|
+
AcUiLlmSettingsDialog.open = function () {
|
|
282
|
+
return __awaiter(this, arguments, void 0, function (options) {
|
|
283
|
+
var config, dialog;
|
|
284
|
+
if (options === void 0) { options = {}; }
|
|
285
|
+
return __generator(this, function (_a) {
|
|
286
|
+
switch (_a.label) {
|
|
287
|
+
case 0:
|
|
288
|
+
if (AcUiLlmSettingsDialog.openInstance) {
|
|
289
|
+
return [2 /*return*/, AcUiLlmSettingsDialog.openInstance.show()];
|
|
290
|
+
}
|
|
291
|
+
return [4 /*yield*/, acapLlmLoadConfig()];
|
|
292
|
+
case 1:
|
|
293
|
+
config = _a.sent();
|
|
294
|
+
dialog = new AcUiLlmSettingsDialog(config, options);
|
|
295
|
+
AcUiLlmSettingsDialog.openInstance = dialog;
|
|
296
|
+
return [2 /*return*/, dialog.show()];
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* Closes the dialog. Asks first when the provider editor holds unsaved
|
|
303
|
+
* edits.
|
|
304
|
+
*/
|
|
305
|
+
AcUiLlmSettingsDialog.prototype.close = function () {
|
|
306
|
+
var _a;
|
|
307
|
+
if (AcUiLlmSettingsDialog.openInstance === this &&
|
|
308
|
+
this.isDirty() &&
|
|
309
|
+
!window.confirm(llmT('discardChangesConfirm'))) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (AcUiLlmSettingsDialog.openInstance === this) {
|
|
313
|
+
AcUiLlmSettingsDialog.openInstance = null;
|
|
314
|
+
}
|
|
315
|
+
(_a = this.fetchAbort) === null || _a === void 0 ? void 0 : _a.abort();
|
|
316
|
+
_super.prototype.close.call(this);
|
|
317
|
+
};
|
|
318
|
+
// --- Draft state ----------------------------------------------------------
|
|
319
|
+
AcUiLlmSettingsDialog.prototype.storedProvider = function (id) {
|
|
320
|
+
return this.config.providers.find(function (provider) { return provider.id === id; });
|
|
321
|
+
};
|
|
322
|
+
AcUiLlmSettingsDialog.prototype.customProviders = function () {
|
|
323
|
+
return this.config.providers.filter(function (provider) { return provider.kind === 'custom'; });
|
|
324
|
+
};
|
|
325
|
+
AcUiLlmSettingsDialog.prototype.loadBuiltin = function (id) {
|
|
326
|
+
var _a;
|
|
327
|
+
return cloneProvider((_a = this.storedProvider(id)) !== null && _a !== void 0 ? _a : acapLlmCreateBuiltinProvider(id));
|
|
328
|
+
};
|
|
329
|
+
AcUiLlmSettingsDialog.prototype.loadCustom = function (id) {
|
|
330
|
+
var stored = id ? this.storedProvider(id) : undefined;
|
|
331
|
+
return cloneProvider(stored !== null && stored !== void 0 ? stored : acapLlmCreateCustomProvider());
|
|
332
|
+
};
|
|
333
|
+
Object.defineProperty(AcUiLlmSettingsDialog.prototype, "draft", {
|
|
334
|
+
get: function () {
|
|
335
|
+
return this.mode === 'builtin' ? this.builtinDraft : this.customDraft;
|
|
336
|
+
},
|
|
337
|
+
enumerable: false,
|
|
338
|
+
configurable: true
|
|
339
|
+
});
|
|
340
|
+
AcUiLlmSettingsDialog.prototype.isNewCustom = function () {
|
|
341
|
+
return this.mode === 'custom' && !this.storedProvider(this.customId);
|
|
342
|
+
};
|
|
343
|
+
/** Whether the provider being edited differs from its saved copy. */
|
|
344
|
+
AcUiLlmSettingsDialog.prototype.isDirty = function () {
|
|
345
|
+
var _a, _b;
|
|
346
|
+
var saved = this.mode === 'builtin'
|
|
347
|
+
? ((_a = this.storedProvider(this.builtinId)) !== null && _a !== void 0 ? _a : acapLlmCreateBuiltinProvider(this.builtinId))
|
|
348
|
+
: ((_b = this.storedProvider(this.customId)) !== null && _b !== void 0 ? _b : acapLlmCreateCustomProvider());
|
|
349
|
+
return !acapLlmAreProvidersEqual(this.draft, saved);
|
|
350
|
+
};
|
|
351
|
+
AcUiLlmSettingsDialog.prototype.displayModels = function () {
|
|
352
|
+
return acapLlmEffectiveModels(this.draft);
|
|
353
|
+
};
|
|
354
|
+
/** Writes a new catalog, turning inherited defaults into an override. */
|
|
355
|
+
AcUiLlmSettingsDialog.prototype.setModels = function (models) {
|
|
356
|
+
this.draft.models = models;
|
|
357
|
+
};
|
|
358
|
+
AcUiLlmSettingsDialog.prototype.fetchBlockedReason = function () {
|
|
359
|
+
if (!acapLlmEffectiveBaseUrl(this.draft))
|
|
360
|
+
return llmT('fetchNeedsBaseUrl');
|
|
361
|
+
if (!this.draft.apiKey.trim())
|
|
362
|
+
return llmT('fetchNeedsKey');
|
|
363
|
+
return '';
|
|
364
|
+
};
|
|
365
|
+
AcUiLlmSettingsDialog.prototype.providerIdError = function () {
|
|
366
|
+
if (!this.isNewCustom())
|
|
367
|
+
return '';
|
|
368
|
+
var id = this.customDraft.id;
|
|
369
|
+
if (!id)
|
|
370
|
+
return '';
|
|
371
|
+
if (!ACAP_LLM_CUSTOM_PROVIDER_ID_PATTERN.test(id)) {
|
|
372
|
+
return llmT('providerIdInvalid');
|
|
373
|
+
}
|
|
374
|
+
if (acapLlmIsBuiltinProviderId(id) || this.storedProvider(id)) {
|
|
375
|
+
return llmT('providerIdTaken');
|
|
376
|
+
}
|
|
377
|
+
return '';
|
|
378
|
+
};
|
|
379
|
+
AcUiLlmSettingsDialog.prototype.baseUrlError = function () {
|
|
380
|
+
var url = this.draft.baseUrl.trim();
|
|
381
|
+
return url && !isHttpUrl(url) ? llmT('baseUrlInvalid') : '';
|
|
382
|
+
};
|
|
383
|
+
/** First unmet requirement, shown above the footer; empty when savable. */
|
|
384
|
+
AcUiLlmSettingsDialog.prototype.validationMessage = function () {
|
|
385
|
+
if (this.providerIdError() || this.baseUrlError())
|
|
386
|
+
return '';
|
|
387
|
+
if (this.mode === 'custom') {
|
|
388
|
+
if (!this.customDraft.id)
|
|
389
|
+
return llmT('needsProviderId');
|
|
390
|
+
if (!this.customDraft.baseUrl.trim())
|
|
391
|
+
return llmT('needsBaseUrl');
|
|
392
|
+
}
|
|
393
|
+
if (!cleanModels(this.displayModels()).length)
|
|
394
|
+
return llmT('needsModels');
|
|
395
|
+
return '';
|
|
396
|
+
};
|
|
397
|
+
AcUiLlmSettingsDialog.prototype.canSave = function () {
|
|
398
|
+
return (!this.fetching &&
|
|
399
|
+
!this.candidates &&
|
|
400
|
+
!this.providerIdError() &&
|
|
401
|
+
!this.baseUrlError() &&
|
|
402
|
+
!this.validationMessage());
|
|
403
|
+
};
|
|
404
|
+
// --- Rendering ------------------------------------------------------------
|
|
405
|
+
/** Rebuilds the whole dialog content from the current state. */
|
|
406
|
+
AcUiLlmSettingsDialog.prototype.render = function () {
|
|
407
|
+
var _a;
|
|
408
|
+
this.updaters = [];
|
|
409
|
+
// Provider fields and the model catalog sit side by side (stacked on
|
|
410
|
+
// narrow screens) so the dialog fits without scrolling.
|
|
411
|
+
var provider = h('div', 'ml-llm-column');
|
|
412
|
+
provider.append.apply(provider, __spreadArray([h('div', 'ml-llm-section-title', llmT('providerSettings'))], __read(this.renderEditor()), false));
|
|
413
|
+
var catalog = h('div', 'ml-llm-column');
|
|
414
|
+
catalog.appendChild(this.renderCatalog());
|
|
415
|
+
var columns = h('div', 'ml-llm-columns');
|
|
416
|
+
columns.append(provider, catalog);
|
|
417
|
+
this.bodyEl.replaceChildren(this.renderActiveModel(), h('div', 'ml-llm-divider'), columns);
|
|
418
|
+
(_a = this.footerEl).replaceChildren.apply(_a, __spreadArray([], __read(this.renderFooter()), false));
|
|
419
|
+
this.refresh();
|
|
420
|
+
};
|
|
421
|
+
/** Re-runs every updater registered by the last {@link render}. */
|
|
422
|
+
AcUiLlmSettingsDialog.prototype.refresh = function () {
|
|
423
|
+
var e_2, _a;
|
|
424
|
+
try {
|
|
425
|
+
for (var _b = __values(this.updaters), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
426
|
+
var update = _c.value;
|
|
427
|
+
update();
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
431
|
+
finally {
|
|
432
|
+
try {
|
|
433
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
434
|
+
}
|
|
435
|
+
finally { if (e_2) throw e_2.error; }
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
/** Called after every draft edit: clears the saved notice and refreshes. */
|
|
439
|
+
AcUiLlmSettingsDialog.prototype.onDraftEdited = function () {
|
|
440
|
+
this.statusMessage = '';
|
|
441
|
+
this.refresh();
|
|
442
|
+
};
|
|
443
|
+
/** Creates an element whose text follows `text`, hidden while empty. */
|
|
444
|
+
AcUiLlmSettingsDialog.prototype.watchedText = function (tag, className, text) {
|
|
445
|
+
var element = h(tag, className);
|
|
446
|
+
this.updaters.push(function () {
|
|
447
|
+
var value = text();
|
|
448
|
+
element.textContent = value;
|
|
449
|
+
element.hidden = !value;
|
|
450
|
+
});
|
|
451
|
+
return element;
|
|
452
|
+
};
|
|
453
|
+
/**
|
|
454
|
+
* Creates an error line that replaces a hint while `error` is non-empty.
|
|
455
|
+
*/
|
|
456
|
+
AcUiLlmSettingsDialog.prototype.errorOrHint = function (error, hint) {
|
|
457
|
+
var errorEl = this.watchedText('p', 'ml-llm-error', error);
|
|
458
|
+
var hintEl = h('p', 'ml-llm-hint', hint);
|
|
459
|
+
this.updaters.push(function () {
|
|
460
|
+
hintEl.hidden = !!error();
|
|
461
|
+
});
|
|
462
|
+
return [errorEl, hintEl];
|
|
463
|
+
};
|
|
464
|
+
AcUiLlmSettingsDialog.prototype.renderActiveModel = function () {
|
|
465
|
+
var e_3, _a, e_4, _b;
|
|
466
|
+
var _this = this;
|
|
467
|
+
var section = h('section', 'ml-llm-section');
|
|
468
|
+
var select = h('select');
|
|
469
|
+
var groups = acapLlmModelChoices(this.config);
|
|
470
|
+
try {
|
|
471
|
+
for (var groups_1 = __values(groups), groups_1_1 = groups_1.next(); !groups_1_1.done; groups_1_1 = groups_1.next()) {
|
|
472
|
+
var group = groups_1_1.value;
|
|
473
|
+
var optgroup = h('optgroup');
|
|
474
|
+
optgroup.label = group.label;
|
|
475
|
+
try {
|
|
476
|
+
for (var _c = (e_4 = void 0, __values(group.options)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
477
|
+
var choice = _d.value;
|
|
478
|
+
var option = h('option', '', choice.label);
|
|
479
|
+
option.value = "".concat(choice.providerId).concat(MODEL_VALUE_SEPARATOR).concat(choice.modelId);
|
|
480
|
+
optgroup.appendChild(option);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
484
|
+
finally {
|
|
485
|
+
try {
|
|
486
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
487
|
+
}
|
|
488
|
+
finally { if (e_4) throw e_4.error; }
|
|
489
|
+
}
|
|
490
|
+
select.appendChild(optgroup);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
494
|
+
finally {
|
|
495
|
+
try {
|
|
496
|
+
if (groups_1_1 && !groups_1_1.done && (_a = groups_1.return)) _a.call(groups_1);
|
|
497
|
+
}
|
|
498
|
+
finally { if (e_3) throw e_3.error; }
|
|
499
|
+
}
|
|
500
|
+
select.value = "".concat(this.config.activeProviderId).concat(MODEL_VALUE_SEPARATOR).concat(this.config.activeModel);
|
|
501
|
+
select.addEventListener('change', function () {
|
|
502
|
+
void _this.selectActiveModel(select.value);
|
|
503
|
+
});
|
|
504
|
+
section.appendChild(field(llmT('activeModel'), select));
|
|
505
|
+
var hasKey = this.config.providers.some(function (provider) {
|
|
506
|
+
return provider.apiKey.trim();
|
|
507
|
+
});
|
|
508
|
+
if (!hasKey) {
|
|
509
|
+
section.appendChild(h('p', 'ml-llm-warning', llmT('activeModelNone')));
|
|
510
|
+
}
|
|
511
|
+
else if (!acapLlmResolveVisionSettings(this.config)) {
|
|
512
|
+
section.appendChild(h('p', 'ml-llm-warning', llmT('visionMissing')));
|
|
513
|
+
}
|
|
514
|
+
section.appendChild(h('p', 'ml-llm-hint', llmT('activeModelHint')));
|
|
515
|
+
return section;
|
|
516
|
+
};
|
|
517
|
+
AcUiLlmSettingsDialog.prototype.renderEditor = function () {
|
|
518
|
+
var e_5, _a;
|
|
519
|
+
var _this = this;
|
|
520
|
+
var tabs = h('div', 'ml-llm-segmented');
|
|
521
|
+
tabs.setAttribute('role', 'tablist');
|
|
522
|
+
var _loop_1 = function (mode, key) {
|
|
523
|
+
var tab = button('ml-llm-segmented-item', llmT(key), function () {
|
|
524
|
+
return _this.switchMode(mode);
|
|
525
|
+
});
|
|
526
|
+
tab.setAttribute('role', 'tab');
|
|
527
|
+
tab.setAttribute('aria-selected', String(this_1.mode === mode));
|
|
528
|
+
if (this_1.mode === mode)
|
|
529
|
+
tab.classList.add('is-active');
|
|
530
|
+
tabs.appendChild(tab);
|
|
531
|
+
};
|
|
532
|
+
var this_1 = this;
|
|
533
|
+
try {
|
|
534
|
+
for (var _b = __values([
|
|
535
|
+
['builtin', 'tabBuiltin'],
|
|
536
|
+
['custom', 'tabCustom']
|
|
537
|
+
]), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
538
|
+
var _d = __read(_c.value, 2), mode = _d[0], key = _d[1];
|
|
539
|
+
_loop_1(mode, key);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
543
|
+
finally {
|
|
544
|
+
try {
|
|
545
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
546
|
+
}
|
|
547
|
+
finally { if (e_5) throw e_5.error; }
|
|
548
|
+
}
|
|
549
|
+
var intro = h('p', 'ml-llm-hint', llmT(this.mode === 'builtin' ? 'builtinIntro' : 'customIntro'));
|
|
550
|
+
return __spreadArray([
|
|
551
|
+
tabs,
|
|
552
|
+
intro
|
|
553
|
+
], __read((this.mode === 'builtin'
|
|
554
|
+
? this.renderBuiltinFields()
|
|
555
|
+
: this.renderCustomFields())), false);
|
|
556
|
+
};
|
|
557
|
+
AcUiLlmSettingsDialog.prototype.renderBuiltinFields = function () {
|
|
558
|
+
var e_6, _a;
|
|
559
|
+
var _this = this;
|
|
560
|
+
var _b;
|
|
561
|
+
var draft = this.builtinDraft;
|
|
562
|
+
var providerSelect = h('select');
|
|
563
|
+
try {
|
|
564
|
+
for (var ACAP_LLM_BUILTIN_PROVIDER_IDS_1 = __values(ACAP_LLM_BUILTIN_PROVIDER_IDS), ACAP_LLM_BUILTIN_PROVIDER_IDS_1_1 = ACAP_LLM_BUILTIN_PROVIDER_IDS_1.next(); !ACAP_LLM_BUILTIN_PROVIDER_IDS_1_1.done; ACAP_LLM_BUILTIN_PROVIDER_IDS_1_1 = ACAP_LLM_BUILTIN_PROVIDER_IDS_1.next()) {
|
|
565
|
+
var id = ACAP_LLM_BUILTIN_PROVIDER_IDS_1_1.value;
|
|
566
|
+
var label = acapLlmBuiltinProviderLabel(id);
|
|
567
|
+
var option = h('option', '', ((_b = this.storedProvider(id)) === null || _b === void 0 ? void 0 : _b.apiKey.trim())
|
|
568
|
+
? "".concat(label, " \u00B7 ").concat(llmT('providerConfigured'))
|
|
569
|
+
: label);
|
|
570
|
+
option.value = id;
|
|
571
|
+
providerSelect.appendChild(option);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
575
|
+
finally {
|
|
576
|
+
try {
|
|
577
|
+
if (ACAP_LLM_BUILTIN_PROVIDER_IDS_1_1 && !ACAP_LLM_BUILTIN_PROVIDER_IDS_1_1.done && (_a = ACAP_LLM_BUILTIN_PROVIDER_IDS_1.return)) _a.call(ACAP_LLM_BUILTIN_PROVIDER_IDS_1);
|
|
578
|
+
}
|
|
579
|
+
finally { if (e_6) throw e_6.error; }
|
|
580
|
+
}
|
|
581
|
+
providerSelect.value = this.builtinId;
|
|
582
|
+
providerSelect.addEventListener('change', function () {
|
|
583
|
+
var id = providerSelect.value;
|
|
584
|
+
if (!acapLlmIsBuiltinProviderId(id))
|
|
585
|
+
return;
|
|
586
|
+
_this.resetFetch();
|
|
587
|
+
_this.builtinId = id;
|
|
588
|
+
_this.builtinDraft = _this.loadBuiltin(id);
|
|
589
|
+
_this.showAdvanced = _this.builtinDraft.baseUrl.trim().length > 0;
|
|
590
|
+
_this.statusMessage = '';
|
|
591
|
+
_this.render();
|
|
592
|
+
});
|
|
593
|
+
var apiKey = textInput(draft.apiKey, function (value) {
|
|
594
|
+
draft.apiKey = value;
|
|
595
|
+
_this.onDraftEdited();
|
|
596
|
+
}, {
|
|
597
|
+
type: 'password',
|
|
598
|
+
secret: true,
|
|
599
|
+
placeholder: llmT('apiKeyPlaceholder')
|
|
600
|
+
});
|
|
601
|
+
var keyWarning = this.watchedText('p', 'ml-llm-warning', function () {
|
|
602
|
+
return draft.apiKey.trim() ? '' : llmT('apiKeyRequired');
|
|
603
|
+
});
|
|
604
|
+
var disclosure = button('ml-llm-disclosure', '', function () {
|
|
605
|
+
_this.showAdvanced = !_this.showAdvanced;
|
|
606
|
+
_this.render();
|
|
607
|
+
});
|
|
608
|
+
disclosure.setAttribute('aria-expanded', String(this.showAdvanced));
|
|
609
|
+
disclosure.append(svgIcon(ICON_CHEVRON, "ml-llm-disclosure-icon".concat(this.showAdvanced ? ' is-open' : '')), document.createTextNode(llmT('advancedSettings')));
|
|
610
|
+
var elements = [
|
|
611
|
+
field(llmT('provider'), providerSelect),
|
|
612
|
+
field(llmT('apiKey'), apiKey),
|
|
613
|
+
keyWarning,
|
|
614
|
+
disclosure
|
|
615
|
+
];
|
|
616
|
+
if (this.showAdvanced) {
|
|
617
|
+
var defaultUrl = ACAP_LLM_BUILTIN_PROVIDERS[this.builtinId].baseUrl;
|
|
618
|
+
var group = h('div', 'ml-llm-group');
|
|
619
|
+
group.append.apply(group, __spreadArray([field(llmT('baseUrl'), textInput(draft.baseUrl, function (value) {
|
|
620
|
+
draft.baseUrl = value;
|
|
621
|
+
_this.onDraftEdited();
|
|
622
|
+
}, { placeholder: defaultUrl }))], __read(this.errorOrHint(function () { return _this.baseUrlError(); }, llmT('baseUrlDefault', { url: defaultUrl }))), false));
|
|
623
|
+
if (this.builtinId === 'deepseek-vl') {
|
|
624
|
+
group.appendChild(h('p', 'ml-llm-hint', llmT('providerDeepseekVlHint')));
|
|
625
|
+
}
|
|
626
|
+
elements.push(group);
|
|
627
|
+
}
|
|
628
|
+
return elements;
|
|
629
|
+
};
|
|
630
|
+
AcUiLlmSettingsDialog.prototype.renderCustomFields = function () {
|
|
631
|
+
var e_7, _a, e_8, _b;
|
|
632
|
+
var _this = this;
|
|
633
|
+
var _c;
|
|
634
|
+
var draft = this.customDraft;
|
|
635
|
+
var elements = [];
|
|
636
|
+
var customProviders = this.customProviders();
|
|
637
|
+
if (customProviders.length) {
|
|
638
|
+
var select_1 = h('select');
|
|
639
|
+
try {
|
|
640
|
+
for (var customProviders_1 = __values(customProviders), customProviders_1_1 = customProviders_1.next(); !customProviders_1_1.done; customProviders_1_1 = customProviders_1.next()) {
|
|
641
|
+
var provider = customProviders_1_1.value;
|
|
642
|
+
var option = h('option', '', acapLlmProviderLabel(provider));
|
|
643
|
+
option.value = provider.id;
|
|
644
|
+
select_1.appendChild(option);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
648
|
+
finally {
|
|
649
|
+
try {
|
|
650
|
+
if (customProviders_1_1 && !customProviders_1_1.done && (_a = customProviders_1.return)) _a.call(customProviders_1);
|
|
651
|
+
}
|
|
652
|
+
finally { if (e_7) throw e_7.error; }
|
|
653
|
+
}
|
|
654
|
+
var newOption = h('option', '', llmT('newCustomProvider'));
|
|
655
|
+
newOption.value = '';
|
|
656
|
+
select_1.appendChild(newOption);
|
|
657
|
+
select_1.value = this.customId;
|
|
658
|
+
select_1.addEventListener('change', function () {
|
|
659
|
+
_this.resetFetch();
|
|
660
|
+
_this.customId = select_1.value;
|
|
661
|
+
_this.customDraft = _this.loadCustom(_this.customId);
|
|
662
|
+
_this.statusMessage = '';
|
|
663
|
+
_this.render();
|
|
664
|
+
});
|
|
665
|
+
elements.push(field(llmT('customProvider'), select_1));
|
|
666
|
+
}
|
|
667
|
+
var idInput = textInput(draft.id, function (value) {
|
|
668
|
+
draft.id = value.trim();
|
|
669
|
+
_this.onDraftEdited();
|
|
670
|
+
}, { placeholder: 'acme-gateway', secret: true });
|
|
671
|
+
idInput.disabled = !this.isNewCustom();
|
|
672
|
+
var displayName = textInput((_c = draft.displayName) !== null && _c !== void 0 ? _c : '', function (value) {
|
|
673
|
+
draft.displayName = value;
|
|
674
|
+
_this.onDraftEdited();
|
|
675
|
+
}, { placeholder: llmT('displayName') });
|
|
676
|
+
var protocol = h('select');
|
|
677
|
+
try {
|
|
678
|
+
for (var ACAP_LLM_API_PROTOCOLS_1 = __values(ACAP_LLM_API_PROTOCOLS), ACAP_LLM_API_PROTOCOLS_1_1 = ACAP_LLM_API_PROTOCOLS_1.next(); !ACAP_LLM_API_PROTOCOLS_1_1.done; ACAP_LLM_API_PROTOCOLS_1_1 = ACAP_LLM_API_PROTOCOLS_1.next()) {
|
|
679
|
+
var value = ACAP_LLM_API_PROTOCOLS_1_1.value;
|
|
680
|
+
var option = h('option', '', llmT(PROTOCOL_LABEL_KEYS[value]));
|
|
681
|
+
option.value = value;
|
|
682
|
+
protocol.appendChild(option);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
686
|
+
finally {
|
|
687
|
+
try {
|
|
688
|
+
if (ACAP_LLM_API_PROTOCOLS_1_1 && !ACAP_LLM_API_PROTOCOLS_1_1.done && (_b = ACAP_LLM_API_PROTOCOLS_1.return)) _b.call(ACAP_LLM_API_PROTOCOLS_1);
|
|
689
|
+
}
|
|
690
|
+
finally { if (e_8) throw e_8.error; }
|
|
691
|
+
}
|
|
692
|
+
protocol.value = draft.protocol;
|
|
693
|
+
protocol.addEventListener('change', function () {
|
|
694
|
+
draft.protocol = protocol.value;
|
|
695
|
+
_this.onDraftEdited();
|
|
696
|
+
});
|
|
697
|
+
var apiKey = textInput(draft.apiKey, function (value) {
|
|
698
|
+
draft.apiKey = value;
|
|
699
|
+
_this.onDraftEdited();
|
|
700
|
+
}, {
|
|
701
|
+
type: 'password',
|
|
702
|
+
secret: true,
|
|
703
|
+
placeholder: llmT('apiKeyPlaceholder')
|
|
704
|
+
});
|
|
705
|
+
// Short fields share a row to keep the dialog within the screen height.
|
|
706
|
+
elements.push.apply(elements, __spreadArray(__spreadArray(__spreadArray(__spreadArray([fieldRow(field(llmT('providerId'), idInput), field(llmT('displayName'), displayName))], __read(this.errorOrHint(function () { return _this.providerIdError(); }, llmT('providerIdHint'))), false), [field(llmT('baseUrl'), textInput(draft.baseUrl, function (value) {
|
|
707
|
+
draft.baseUrl = value;
|
|
708
|
+
_this.onDraftEdited();
|
|
709
|
+
}, { placeholder: 'https://gateway.example/v1' }))], false), __read(this.errorOrHint(function () { return _this.baseUrlError(); }, llmT('baseUrlHint'))), false), [fieldRow(field(llmT('protocol'), protocol), field(llmT('apiKey'), apiKey))], false));
|
|
710
|
+
return elements;
|
|
711
|
+
};
|
|
712
|
+
AcUiLlmSettingsDialog.prototype.renderCatalog = function () {
|
|
713
|
+
var _this = this;
|
|
714
|
+
var section = h('section', 'ml-llm-catalog');
|
|
715
|
+
section.setAttribute('aria-label', llmT('models'));
|
|
716
|
+
var head = h('div', 'ml-llm-catalog-head');
|
|
717
|
+
var heading = h('div', 'ml-llm-catalog-heading');
|
|
718
|
+
heading.appendChild(h('span', 'ml-llm-field-label', llmT('models')));
|
|
719
|
+
if (this.mode === 'builtin') {
|
|
720
|
+
heading.appendChild(this.watchedText('span', 'ml-llm-meta', function () {
|
|
721
|
+
return llmT(_this.builtinDraft.models === null
|
|
722
|
+
? 'modelsDefault'
|
|
723
|
+
: 'modelsCustomized');
|
|
724
|
+
}));
|
|
725
|
+
}
|
|
726
|
+
var actions = h('div', 'ml-llm-catalog-actions');
|
|
727
|
+
if (this.mode === 'builtin') {
|
|
728
|
+
var reset_1 = button('ml-llm-link-btn', llmT('resetModels'), function () {
|
|
729
|
+
_this.closePicker();
|
|
730
|
+
_this.builtinDraft.models = null;
|
|
731
|
+
_this.statusMessage = '';
|
|
732
|
+
_this.render();
|
|
733
|
+
});
|
|
734
|
+
this.updaters.push(function () {
|
|
735
|
+
reset_1.hidden = _this.builtinDraft.models === null;
|
|
736
|
+
reset_1.disabled = _this.fetching;
|
|
737
|
+
});
|
|
738
|
+
actions.appendChild(reset_1);
|
|
739
|
+
}
|
|
740
|
+
var fetchButton = button('ml-llm-link-btn', '', function () {
|
|
741
|
+
void _this.fetchModels();
|
|
742
|
+
});
|
|
743
|
+
this.updaters.push(function () {
|
|
744
|
+
var blocked = _this.fetchBlockedReason();
|
|
745
|
+
fetchButton.textContent = llmT(_this.fetching ? 'fetching' : 'fetchModels');
|
|
746
|
+
fetchButton.disabled = _this.fetching || !!blocked || !!_this.candidates;
|
|
747
|
+
fetchButton.title = blocked;
|
|
748
|
+
});
|
|
749
|
+
actions.appendChild(fetchButton);
|
|
750
|
+
head.append(heading, actions);
|
|
751
|
+
section.appendChild(head);
|
|
752
|
+
section.append.apply(section, __spreadArray(__spreadArray([], __read((this.candidates ? this.renderPicker() : this.renderModelRows())), false), [this.watchedText('p', 'ml-llm-error', function () { return _this.fetchError; })], false));
|
|
753
|
+
return section;
|
|
754
|
+
};
|
|
755
|
+
AcUiLlmSettingsDialog.prototype.renderModelRows = function () {
|
|
756
|
+
var _this = this;
|
|
757
|
+
var models = this.displayModels();
|
|
758
|
+
if (!models.length) {
|
|
759
|
+
return [h('div', 'ml-llm-empty', llmT('modelsEmpty'))];
|
|
760
|
+
}
|
|
761
|
+
var list = h('ul', 'ml-llm-model-rows');
|
|
762
|
+
models.forEach(function (model, index) {
|
|
763
|
+
var _a;
|
|
764
|
+
var row = h('li', 'ml-llm-model-row');
|
|
765
|
+
var vision = h('input');
|
|
766
|
+
vision.type = 'checkbox';
|
|
767
|
+
vision.checked = model.vision;
|
|
768
|
+
var id = textInput(model.id, function (value) {
|
|
769
|
+
var previous = _this.displayModels()[index];
|
|
770
|
+
var nextVision = acapLlmVisionAfterIdEdit(previous, value);
|
|
771
|
+
vision.checked = nextVision;
|
|
772
|
+
_this.updateModel(index, { id: value, vision: nextVision });
|
|
773
|
+
});
|
|
774
|
+
id.className = 'ml-llm-model-id';
|
|
775
|
+
id.title = (_a = model.name) !== null && _a !== void 0 ? _a : model.id;
|
|
776
|
+
id.placeholder = llmT('modelId');
|
|
777
|
+
id.setAttribute('aria-label', "".concat(llmT('modelId'), " ").concat(index + 1));
|
|
778
|
+
vision.addEventListener('change', function () {
|
|
779
|
+
return _this.updateModel(index, { vision: vision.checked });
|
|
780
|
+
});
|
|
781
|
+
var visionLabel = h('label', 'ml-llm-model-vision');
|
|
782
|
+
visionLabel.title = llmT('modelVisionHint');
|
|
783
|
+
visionLabel.append(vision, document.createTextNode(llmT('modelVision')));
|
|
784
|
+
var remove = button('ml-llm-model-remove', '', function () {
|
|
785
|
+
_this.setModels(_this.displayModels()
|
|
786
|
+
.filter(function (_, at) { return at !== index; })
|
|
787
|
+
.map(function (entry) { return (__assign({}, entry)); }));
|
|
788
|
+
_this.statusMessage = '';
|
|
789
|
+
_this.render();
|
|
790
|
+
});
|
|
791
|
+
remove.title = llmT('removeModel');
|
|
792
|
+
remove.setAttribute('aria-label', "".concat(llmT('removeModel'), " ").concat(index + 1));
|
|
793
|
+
remove.appendChild(svgIcon(ICON_CLOSE));
|
|
794
|
+
row.append(id, visionLabel, remove);
|
|
795
|
+
list.appendChild(row);
|
|
796
|
+
});
|
|
797
|
+
return [list, this.renderAddModelButton()];
|
|
798
|
+
};
|
|
799
|
+
AcUiLlmSettingsDialog.prototype.renderAddModelButton = function () {
|
|
800
|
+
var _this = this;
|
|
801
|
+
var add = button('ml-ui-dialog-btn ml-ui-dialog-btn-secondary ml-llm-add-model', '', function () {
|
|
802
|
+
var _a;
|
|
803
|
+
_this.setModels(__spreadArray(__spreadArray([], __read(_this.displayModels().map(function (model) { return (__assign({}, model)); })), false), [
|
|
804
|
+
{ id: '', vision: false }
|
|
805
|
+
], false));
|
|
806
|
+
_this.statusMessage = '';
|
|
807
|
+
_this.render();
|
|
808
|
+
var inputs = _this.bodyEl.querySelectorAll('.ml-llm-model-id');
|
|
809
|
+
(_a = inputs[inputs.length - 1]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
810
|
+
});
|
|
811
|
+
add.append(svgIcon(ICON_PLUS), document.createTextNode(llmT('addModel')));
|
|
812
|
+
return add;
|
|
813
|
+
};
|
|
814
|
+
AcUiLlmSettingsDialog.prototype.updateModel = function (index, patch) {
|
|
815
|
+
this.setModels(this.displayModels().map(function (model, at) {
|
|
816
|
+
return at === index ? __assign(__assign({}, model), patch) : __assign({}, model);
|
|
817
|
+
}));
|
|
818
|
+
this.onDraftEdited();
|
|
819
|
+
};
|
|
820
|
+
// --- Model listing picker ------------------------------------------------
|
|
821
|
+
AcUiLlmSettingsDialog.prototype.renderPicker = function () {
|
|
822
|
+
var _this = this;
|
|
823
|
+
var picker = h('div', 'ml-llm-picker');
|
|
824
|
+
var title = h('div', 'ml-llm-picker-title', llmT('fetchTitle'));
|
|
825
|
+
title.appendChild(this.watchedText('span', 'ml-llm-meta', function () { return _this.pickedSummary(); }));
|
|
826
|
+
var toolbar = h('div', 'ml-llm-picker-toolbar');
|
|
827
|
+
var list = h('div');
|
|
828
|
+
var search = textInput(this.candidateQuery, function (value) {
|
|
829
|
+
_this.candidateQuery = value;
|
|
830
|
+
_this.renderPickerList(list);
|
|
831
|
+
_this.refresh();
|
|
832
|
+
}, { type: 'search', placeholder: llmT('fetchSearch') });
|
|
833
|
+
search.setAttribute('aria-label', llmT('fetchSearch'));
|
|
834
|
+
var toggleAll = button('ml-llm-link-btn', '', function () {
|
|
835
|
+
_this.toggleVisibleCandidates();
|
|
836
|
+
_this.renderPickerList(list);
|
|
837
|
+
_this.refresh();
|
|
838
|
+
});
|
|
839
|
+
this.updaters.push(function () {
|
|
840
|
+
toggleAll.textContent = llmT(_this.allVisiblePicked() ? 'fetchDeselectAll' : 'fetchSelectAll');
|
|
841
|
+
toggleAll.disabled = !_this.visibleCandidates().length;
|
|
842
|
+
});
|
|
843
|
+
toolbar.append(search, toggleAll);
|
|
844
|
+
this.renderPickerList(list);
|
|
845
|
+
var footer = h('div', 'ml-llm-picker-footer');
|
|
846
|
+
var adopt = button('ml-ui-dialog-btn', llmT('fetchAdopt'), function () {
|
|
847
|
+
var picked = _this.pickedModels();
|
|
848
|
+
if (!picked.length)
|
|
849
|
+
return;
|
|
850
|
+
_this.setModels(picked);
|
|
851
|
+
_this.closePicker();
|
|
852
|
+
_this.statusMessage = '';
|
|
853
|
+
_this.render();
|
|
854
|
+
});
|
|
855
|
+
this.updaters.push(function () {
|
|
856
|
+
var empty = !_this.pickedModels().length;
|
|
857
|
+
adopt.disabled = empty;
|
|
858
|
+
adopt.title = empty ? llmT('fetchKeepOne') : '';
|
|
859
|
+
});
|
|
860
|
+
footer.append(button('ml-ui-dialog-btn ml-ui-dialog-btn-secondary', llmT('cancel'), function () {
|
|
861
|
+
_this.closePicker();
|
|
862
|
+
_this.render();
|
|
863
|
+
}), adopt);
|
|
864
|
+
picker.append(title, toolbar, list, footer);
|
|
865
|
+
return [picker];
|
|
866
|
+
};
|
|
867
|
+
AcUiLlmSettingsDialog.prototype.renderPickerList = function (container) {
|
|
868
|
+
var e_9, _a;
|
|
869
|
+
var _this = this;
|
|
870
|
+
var _b;
|
|
871
|
+
var visible = this.visibleCandidates();
|
|
872
|
+
if (!visible.length) {
|
|
873
|
+
container.replaceChildren(h('p', 'ml-llm-empty', llmT('fetchNoMatches')));
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
var list = h('ul', 'ml-llm-picker-list');
|
|
877
|
+
var _loop_2 = function (candidate) {
|
|
878
|
+
var item = h('li');
|
|
879
|
+
var label = h('label', 'ml-llm-picker-item');
|
|
880
|
+
var checkbox = h('input');
|
|
881
|
+
checkbox.type = 'checkbox';
|
|
882
|
+
checkbox.checked = this_2.isPicked(candidate.id);
|
|
883
|
+
checkbox.addEventListener('change', function () {
|
|
884
|
+
if (!_this.flipped.delete(candidate.id))
|
|
885
|
+
_this.flipped.add(candidate.id);
|
|
886
|
+
_this.refresh();
|
|
887
|
+
});
|
|
888
|
+
var id = h('span', 'ml-llm-picker-id', candidate.id);
|
|
889
|
+
id.title = (_b = candidate.name) !== null && _b !== void 0 ? _b : candidate.id;
|
|
890
|
+
label.append(checkbox, id);
|
|
891
|
+
item.appendChild(label);
|
|
892
|
+
list.appendChild(item);
|
|
893
|
+
};
|
|
894
|
+
var this_2 = this;
|
|
895
|
+
try {
|
|
896
|
+
for (var visible_1 = __values(visible), visible_1_1 = visible_1.next(); !visible_1_1.done; visible_1_1 = visible_1.next()) {
|
|
897
|
+
var candidate = visible_1_1.value;
|
|
898
|
+
_loop_2(candidate);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
902
|
+
finally {
|
|
903
|
+
try {
|
|
904
|
+
if (visible_1_1 && !visible_1_1.done && (_a = visible_1.return)) _a.call(visible_1);
|
|
905
|
+
}
|
|
906
|
+
finally { if (e_9) throw e_9.error; }
|
|
907
|
+
}
|
|
908
|
+
container.replaceChildren(list);
|
|
909
|
+
};
|
|
910
|
+
AcUiLlmSettingsDialog.prototype.configuredIds = function () {
|
|
911
|
+
return new Set(this.displayModels()
|
|
912
|
+
.map(function (model) { return model.id; })
|
|
913
|
+
.filter(Boolean));
|
|
914
|
+
};
|
|
915
|
+
// The picker opens with the current catalog checked, so confirming adds the
|
|
916
|
+
// newly checked candidates and drops the unchecked ones in one step. With an
|
|
917
|
+
// empty catalog every candidate starts checked.
|
|
918
|
+
AcUiLlmSettingsDialog.prototype.pickedByDefault = function (id, configured) {
|
|
919
|
+
if (configured === void 0) { configured = this.configuredIds(); }
|
|
920
|
+
return configured.size === 0 || configured.has(id);
|
|
921
|
+
};
|
|
922
|
+
AcUiLlmSettingsDialog.prototype.isPicked = function (id, configured) {
|
|
923
|
+
if (configured === void 0) { configured = this.configuredIds(); }
|
|
924
|
+
return this.pickedByDefault(id, configured) !== this.flipped.has(id);
|
|
925
|
+
};
|
|
926
|
+
AcUiLlmSettingsDialog.prototype.visibleCandidates = function () {
|
|
927
|
+
var _a;
|
|
928
|
+
var query = this.candidateQuery.trim().toLowerCase();
|
|
929
|
+
var all = (_a = this.candidates) !== null && _a !== void 0 ? _a : [];
|
|
930
|
+
if (!query)
|
|
931
|
+
return all;
|
|
932
|
+
return all.filter(function (candidate) {
|
|
933
|
+
var _a;
|
|
934
|
+
return candidate.id.toLowerCase().includes(query) ||
|
|
935
|
+
!!((_a = candidate.name) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(query));
|
|
936
|
+
});
|
|
937
|
+
};
|
|
938
|
+
AcUiLlmSettingsDialog.prototype.allVisiblePicked = function () {
|
|
939
|
+
var _this = this;
|
|
940
|
+
var visible = this.visibleCandidates();
|
|
941
|
+
var configured = this.configuredIds();
|
|
942
|
+
return (visible.length > 0 &&
|
|
943
|
+
visible.every(function (candidate) { return _this.isPicked(candidate.id, configured); }));
|
|
944
|
+
};
|
|
945
|
+
/** "checked / listed" counter shown next to the picker title. */
|
|
946
|
+
AcUiLlmSettingsDialog.prototype.pickedSummary = function () {
|
|
947
|
+
var _this = this;
|
|
948
|
+
var _a;
|
|
949
|
+
var all = (_a = this.candidates) !== null && _a !== void 0 ? _a : [];
|
|
950
|
+
var configured = this.configuredIds();
|
|
951
|
+
var picked = all.filter(function (candidate) {
|
|
952
|
+
return _this.isPicked(candidate.id, configured);
|
|
953
|
+
}).length;
|
|
954
|
+
return "".concat(picked, " / ").concat(all.length);
|
|
955
|
+
};
|
|
956
|
+
/** Checks or clears only the visible candidates, never hidden ones. */
|
|
957
|
+
AcUiLlmSettingsDialog.prototype.toggleVisibleCandidates = function () {
|
|
958
|
+
var e_10, _a;
|
|
959
|
+
var target = !this.allVisiblePicked();
|
|
960
|
+
var configured = this.configuredIds();
|
|
961
|
+
try {
|
|
962
|
+
for (var _b = __values(this.visibleCandidates()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
963
|
+
var candidate = _c.value;
|
|
964
|
+
if (this.pickedByDefault(candidate.id, configured) === target) {
|
|
965
|
+
this.flipped.delete(candidate.id);
|
|
966
|
+
}
|
|
967
|
+
else {
|
|
968
|
+
this.flipped.add(candidate.id);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
973
|
+
finally {
|
|
974
|
+
try {
|
|
975
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
976
|
+
}
|
|
977
|
+
finally { if (e_10) throw e_10.error; }
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
/** Catalog that confirming the picker would produce. */
|
|
981
|
+
AcUiLlmSettingsDialog.prototype.pickedModels = function () {
|
|
982
|
+
var _this = this;
|
|
983
|
+
var _a;
|
|
984
|
+
var candidates = (_a = this.candidates) !== null && _a !== void 0 ? _a : [];
|
|
985
|
+
var configured = this.configuredIds();
|
|
986
|
+
var listed = new Set(candidates.map(function (candidate) { return candidate.id; }));
|
|
987
|
+
// Rows the listing does not name (typed by hand) are outside the picker and stay.
|
|
988
|
+
var kept = this.displayModels()
|
|
989
|
+
.filter(function (model) { return !listed.has(model.id) || _this.isPicked(model.id, configured); })
|
|
990
|
+
.map(function (model) { return (__assign({}, model)); });
|
|
991
|
+
var keptIds = new Set(kept.map(function (model) { return model.id; }));
|
|
992
|
+
var added = candidates
|
|
993
|
+
.filter(function (candidate) {
|
|
994
|
+
return _this.isPicked(candidate.id, configured) && !keptIds.has(candidate.id);
|
|
995
|
+
})
|
|
996
|
+
.map(function (candidate) { return (__assign(__assign({ id: candidate.id }, (candidate.name ? { name: candidate.name } : {})), { vision: acapLlmGuessModelVision(candidate.id) })); });
|
|
997
|
+
return __spreadArray(__spreadArray([], __read(kept), false), __read(added), false);
|
|
998
|
+
};
|
|
999
|
+
AcUiLlmSettingsDialog.prototype.closePicker = function () {
|
|
1000
|
+
this.candidates = null;
|
|
1001
|
+
this.flipped = new Set();
|
|
1002
|
+
this.candidateQuery = '';
|
|
1003
|
+
};
|
|
1004
|
+
/**
|
|
1005
|
+
* Drops an in-flight fetch, its error and the picker, so a listing requested
|
|
1006
|
+
* for one provider never lands in another provider's catalog.
|
|
1007
|
+
*/
|
|
1008
|
+
AcUiLlmSettingsDialog.prototype.resetFetch = function () {
|
|
1009
|
+
var _a;
|
|
1010
|
+
(_a = this.fetchAbort) === null || _a === void 0 ? void 0 : _a.abort();
|
|
1011
|
+
this.fetchAbort = undefined;
|
|
1012
|
+
this.fetching = false;
|
|
1013
|
+
this.fetchError = '';
|
|
1014
|
+
this.closePicker();
|
|
1015
|
+
};
|
|
1016
|
+
AcUiLlmSettingsDialog.prototype.listingErrorMessage = function (error) {
|
|
1017
|
+
var _a;
|
|
1018
|
+
if (!(error instanceof AcApLlmModelListingError)) {
|
|
1019
|
+
return llmT('fetchFailedFormat');
|
|
1020
|
+
}
|
|
1021
|
+
if (error.code === 'network') {
|
|
1022
|
+
return llmT('fetchFailedNetwork', { url: error.url });
|
|
1023
|
+
}
|
|
1024
|
+
if (error.code === 'http') {
|
|
1025
|
+
return llmT('fetchFailedHttp', { status: String((_a = error.status) !== null && _a !== void 0 ? _a : '') });
|
|
1026
|
+
}
|
|
1027
|
+
return llmT('fetchFailedFormat');
|
|
1028
|
+
};
|
|
1029
|
+
AcUiLlmSettingsDialog.prototype.fetchModels = function () {
|
|
1030
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1031
|
+
var abort, found, error_1;
|
|
1032
|
+
var _a;
|
|
1033
|
+
return __generator(this, function (_b) {
|
|
1034
|
+
switch (_b.label) {
|
|
1035
|
+
case 0:
|
|
1036
|
+
if (this.fetching || this.fetchBlockedReason())
|
|
1037
|
+
return [2 /*return*/];
|
|
1038
|
+
(_a = this.fetchAbort) === null || _a === void 0 ? void 0 : _a.abort();
|
|
1039
|
+
abort = new AbortController();
|
|
1040
|
+
this.fetchAbort = abort;
|
|
1041
|
+
this.fetching = true;
|
|
1042
|
+
this.fetchError = '';
|
|
1043
|
+
this.refresh();
|
|
1044
|
+
_b.label = 1;
|
|
1045
|
+
case 1:
|
|
1046
|
+
_b.trys.push([1, 3, 4, 5]);
|
|
1047
|
+
return [4 /*yield*/, acapLlmFetchAvailableModels({
|
|
1048
|
+
protocol: this.draft.protocol,
|
|
1049
|
+
baseUrl: acapLlmEffectiveBaseUrl(this.draft),
|
|
1050
|
+
apiKey: this.draft.apiKey
|
|
1051
|
+
}, undefined, abort.signal)];
|
|
1052
|
+
case 2:
|
|
1053
|
+
found = _b.sent();
|
|
1054
|
+
if (abort.signal.aborted)
|
|
1055
|
+
return [2 /*return*/];
|
|
1056
|
+
if (!found.length) {
|
|
1057
|
+
this.fetchError = llmT('fetchEmpty');
|
|
1058
|
+
return [2 /*return*/];
|
|
1059
|
+
}
|
|
1060
|
+
this.flipped = new Set();
|
|
1061
|
+
this.candidateQuery = '';
|
|
1062
|
+
this.candidates = found;
|
|
1063
|
+
return [3 /*break*/, 5];
|
|
1064
|
+
case 3:
|
|
1065
|
+
error_1 = _b.sent();
|
|
1066
|
+
if (!abort.signal.aborted)
|
|
1067
|
+
this.fetchError = this.listingErrorMessage(error_1);
|
|
1068
|
+
return [3 /*break*/, 5];
|
|
1069
|
+
case 4:
|
|
1070
|
+
if (this.fetchAbort === abort) {
|
|
1071
|
+
this.fetching = false;
|
|
1072
|
+
this.fetchAbort = undefined;
|
|
1073
|
+
this.render();
|
|
1074
|
+
}
|
|
1075
|
+
return [7 /*endfinally*/];
|
|
1076
|
+
case 5: return [2 /*return*/];
|
|
1077
|
+
}
|
|
1078
|
+
});
|
|
1079
|
+
});
|
|
1080
|
+
};
|
|
1081
|
+
// --- Mode, save and delete -----------------------------------------------
|
|
1082
|
+
AcUiLlmSettingsDialog.prototype.switchMode = function (next) {
|
|
1083
|
+
if (next === this.mode)
|
|
1084
|
+
return;
|
|
1085
|
+
this.resetFetch();
|
|
1086
|
+
this.mode = next;
|
|
1087
|
+
this.statusMessage = '';
|
|
1088
|
+
this.render();
|
|
1089
|
+
};
|
|
1090
|
+
AcUiLlmSettingsDialog.prototype.renderFooter = function () {
|
|
1091
|
+
var _this = this;
|
|
1092
|
+
var elements = [];
|
|
1093
|
+
if (this.mode === 'custom' && !this.isNewCustom()) {
|
|
1094
|
+
elements.push(button('ml-ui-dialog-btn ml-ui-dialog-btn-secondary ml-llm-danger', llmT('deleteProvider'), function () { return void _this.deleteProvider(); }));
|
|
1095
|
+
}
|
|
1096
|
+
// Validation and "saved" notices share the footer row with the buttons.
|
|
1097
|
+
var message = h('div', 'ml-llm-footer-message');
|
|
1098
|
+
message.append(this.watchedText('span', 'ml-llm-validation', function () {
|
|
1099
|
+
return _this.validationMessage();
|
|
1100
|
+
}), this.watchedText('span', 'ml-llm-status', function () { return _this.statusMessage; }));
|
|
1101
|
+
elements.push(message);
|
|
1102
|
+
elements.push(button('ml-ui-dialog-btn ml-ui-dialog-btn-secondary', llmT('close'), function () {
|
|
1103
|
+
return _this.close();
|
|
1104
|
+
}));
|
|
1105
|
+
var save = button('ml-ui-dialog-btn', llmT(this.isNewCustom() ? 'createProvider' : 'save'), function () { return void _this.save(); });
|
|
1106
|
+
this.updaters.push(function () {
|
|
1107
|
+
save.disabled = !_this.canSave();
|
|
1108
|
+
});
|
|
1109
|
+
elements.push(save);
|
|
1110
|
+
return elements;
|
|
1111
|
+
};
|
|
1112
|
+
/** Persists a new config, reloads the drafts from it and re-renders. */
|
|
1113
|
+
AcUiLlmSettingsDialog.prototype.commit = function (next) {
|
|
1114
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1115
|
+
return __generator(this, function (_a) {
|
|
1116
|
+
switch (_a.label) {
|
|
1117
|
+
case 0:
|
|
1118
|
+
this.config = next;
|
|
1119
|
+
return [4 /*yield*/, acapLlmSaveConfig(next)];
|
|
1120
|
+
case 1:
|
|
1121
|
+
_a.sent();
|
|
1122
|
+
this.builtinDraft = this.loadBuiltin(this.builtinId);
|
|
1123
|
+
this.customDraft = this.loadCustom(this.customId);
|
|
1124
|
+
this.statusMessage = llmT('saved');
|
|
1125
|
+
this.render();
|
|
1126
|
+
return [2 /*return*/];
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
});
|
|
1130
|
+
};
|
|
1131
|
+
AcUiLlmSettingsDialog.prototype.save = function () {
|
|
1132
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1133
|
+
var draft, provider;
|
|
1134
|
+
var _a;
|
|
1135
|
+
return __generator(this, function (_b) {
|
|
1136
|
+
switch (_b.label) {
|
|
1137
|
+
case 0:
|
|
1138
|
+
if (!this.canSave())
|
|
1139
|
+
return [2 /*return*/];
|
|
1140
|
+
draft = this.draft;
|
|
1141
|
+
provider = __assign(__assign({}, draft), { id: draft.id.trim(), displayName: (_a = draft.displayName) === null || _a === void 0 ? void 0 : _a.trim(), baseUrl: draft.baseUrl.trim(), apiKey: draft.apiKey.trim(), models: draft.models ? cleanModels(draft.models) : null });
|
|
1142
|
+
if (provider.kind === 'builtin')
|
|
1143
|
+
delete provider.displayName;
|
|
1144
|
+
if (provider.kind === 'custom')
|
|
1145
|
+
this.customId = provider.id;
|
|
1146
|
+
return [4 /*yield*/, this.commit(acapLlmUpsertProvider(this.config, provider))];
|
|
1147
|
+
case 1:
|
|
1148
|
+
_b.sent();
|
|
1149
|
+
return [2 /*return*/];
|
|
1150
|
+
}
|
|
1151
|
+
});
|
|
1152
|
+
});
|
|
1153
|
+
};
|
|
1154
|
+
AcUiLlmSettingsDialog.prototype.deleteProvider = function () {
|
|
1155
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1156
|
+
var id, next;
|
|
1157
|
+
var _a, _b;
|
|
1158
|
+
return __generator(this, function (_c) {
|
|
1159
|
+
switch (_c.label) {
|
|
1160
|
+
case 0:
|
|
1161
|
+
id = this.customId;
|
|
1162
|
+
if (!this.storedProvider(id))
|
|
1163
|
+
return [2 /*return*/];
|
|
1164
|
+
if (!window.confirm(llmT('deleteProviderConfirm', { id: id })))
|
|
1165
|
+
return [2 /*return*/];
|
|
1166
|
+
next = acapLlmRemoveProvider(this.config, id);
|
|
1167
|
+
this.customId =
|
|
1168
|
+
(_b = (_a = next.providers.find(function (provider) { return provider.kind === 'custom'; })) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '';
|
|
1169
|
+
return [4 /*yield*/, this.commit(next)];
|
|
1170
|
+
case 1:
|
|
1171
|
+
_c.sent();
|
|
1172
|
+
return [2 /*return*/];
|
|
1173
|
+
}
|
|
1174
|
+
});
|
|
1175
|
+
});
|
|
1176
|
+
};
|
|
1177
|
+
AcUiLlmSettingsDialog.prototype.selectActiveModel = function (value) {
|
|
1178
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1179
|
+
var separator, activeProviderId, activeModel;
|
|
1180
|
+
return __generator(this, function (_a) {
|
|
1181
|
+
switch (_a.label) {
|
|
1182
|
+
case 0:
|
|
1183
|
+
separator = value.indexOf(MODEL_VALUE_SEPARATOR);
|
|
1184
|
+
if (separator < 0)
|
|
1185
|
+
return [2 /*return*/];
|
|
1186
|
+
activeProviderId = value.slice(0, separator);
|
|
1187
|
+
activeModel = value.slice(separator + MODEL_VALUE_SEPARATOR.length);
|
|
1188
|
+
if (activeProviderId === this.config.activeProviderId &&
|
|
1189
|
+
activeModel === this.config.activeModel) {
|
|
1190
|
+
return [2 /*return*/];
|
|
1191
|
+
}
|
|
1192
|
+
this.config = __assign(__assign({}, this.config), { activeProviderId: activeProviderId, activeModel: activeModel });
|
|
1193
|
+
return [4 /*yield*/, acapLlmSaveConfig(this.config)];
|
|
1194
|
+
case 1:
|
|
1195
|
+
_a.sent();
|
|
1196
|
+
this.statusMessage = llmT('saved');
|
|
1197
|
+
this.render();
|
|
1198
|
+
return [2 /*return*/];
|
|
1199
|
+
}
|
|
1200
|
+
});
|
|
1201
|
+
});
|
|
1202
|
+
};
|
|
1203
|
+
/** Injects the dialog styles once per document. */
|
|
1204
|
+
AcUiLlmSettingsDialog.ensureSettingsStyles = function () {
|
|
1205
|
+
if (document.getElementById(AcUiLlmSettingsDialog.settingsStyleId))
|
|
1206
|
+
return;
|
|
1207
|
+
var style = document.createElement('style');
|
|
1208
|
+
style.id = AcUiLlmSettingsDialog.settingsStyleId;
|
|
1209
|
+
style.textContent = LLM_SETTINGS_STYLES;
|
|
1210
|
+
document.head.appendChild(style);
|
|
1211
|
+
};
|
|
1212
|
+
/** ID of the dialog-specific style element. */
|
|
1213
|
+
AcUiLlmSettingsDialog.settingsStyleId = 'ml-llm-settings-styles';
|
|
1214
|
+
AcUiLlmSettingsDialog.openInstance = null;
|
|
1215
|
+
return AcUiLlmSettingsDialog;
|
|
1216
|
+
}(AcUiDialog));
|
|
1217
|
+
export { AcUiLlmSettingsDialog };
|
|
1218
|
+
//# sourceMappingURL=AcUiLlmSettingsDialog.js.map
|