@prompt-optimizer/mcp-server 0.1.0 → 0.1.1
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 +9 -7
- package/dist/browser.js +10 -4200
- package/dist/chunk-2AOVKKBT.js +7 -0
- package/dist/chunk-5QROM7SH.js +3 -0
- package/dist/chunk-7FYOSVIN.js +3 -0
- package/dist/chunk-AKXNS3YY.js +4 -0
- package/dist/chunk-BBXFEEUH.js +43 -0
- package/dist/chunk-CHINCAF5.js +33 -0
- package/dist/chunk-EJ2IIPFF.js +3 -0
- package/dist/chunk-FLQML3XF.js +64 -0
- package/dist/chunk-GA7S5A7R.js +3 -0
- package/dist/chunk-IABPRAPS.js +3 -0
- package/dist/chunk-JE2EBI2C.js +3 -0
- package/dist/chunk-JL6XIA4S.js +4 -0
- package/dist/chunk-JXWLV6TC.js +12 -0
- package/dist/chunk-MUXGFCOV.js +7012 -0
- package/dist/chunk-NT2DBZVA.js +3 -0
- package/dist/chunk-NVZFDKDX.js +3 -0
- package/dist/chunk-PKJ2PK6J.js +106 -0
- package/dist/chunk-SDHFVY4F.js +6 -0
- package/dist/chunk-TWLLFRFQ.js +6 -0
- package/dist/desktop-business.js +4 -1225
- package/dist/desktop-comparison-UIIN3WK4.js +3 -0
- package/dist/desktop-storage-KJWV2A3P.js +3 -0
- package/dist/desktop.js +1 -24
- package/dist/dist-OM6QMJNC.js +10 -0
- package/dist/dist-YR425RV6.js +3 -0
- package/dist/index.js +1 -10
- package/dist/legacy.js +97 -26634
- package/dist/multipart-parser-XGXMMB2Z.js +4 -0
- package/dist/node-2SMUH4FH.js +3 -0
- package/dist/node-NX6BPYD5.js +3 -0
- package/dist/node-U7LDATXE.js +17 -0
- package/dist/registry-H5F4DGAM-2GPEVJMD.js +3 -0
- package/dist/src-3F22P42W.js +5 -0
- package/dist/start.js +2 -13
- package/package.json +10 -1
- package/preload-env.cjs +3 -352
- package/dist/chunk-3FYJ3FRD.js +0 -57
- package/dist/chunk-E7Z4Y3F4.js +0 -36402
- package/dist/chunk-GBDJTSRW.js +0 -298
- package/dist/chunk-HLCN3DLS.js +0 -19745
- package/dist/chunk-HYVN7FZZ.js +0 -4787
- package/dist/chunk-MEUCFQGU.js +0 -537
- package/dist/chunk-N6AUTPPS.js +0 -10647
- package/dist/chunk-Q52SACHI.js +0 -304
- package/dist/chunk-Q5B3KFB3.js +0 -31
- package/dist/chunk-QSPNNVX3.js +0 -49017
- package/dist/chunk-SO4YJHYW.js +0 -13450
- package/dist/chunk-SV2GETJH.js +0 -65
- package/dist/chunk-TFH2LO2H.js +0 -58
- package/dist/chunk-TFJEYQ3G.js +0 -786
- package/dist/chunk-TLOFCHZI.js +0 -70
- package/dist/chunk-TQGHULC7.js +0 -188
- package/dist/chunk-UTOMPKTK.js +0 -2209
- package/dist/chunk-XXALDAL7.js +0 -1838
- package/dist/chunk-YT3U6B54.js +0 -21
- package/dist/desktop-comparison-HDIQ6K45.js +0 -22
- package/dist/desktop-storage-YRABQCLF.js +0 -14
- package/dist/dist-O5VNBF5I.js +0 -622
- package/dist/dist-UMX52UME.js +0 -481
- package/dist/multipart-parser-XE6WGDAU.js +0 -373
- package/dist/node-2RBNZOSK.js +0 -2225
- package/dist/node-4Z3USCHW.js +0 -21
- package/dist/node-QHGLD5ST.js +0 -25
- package/dist/registry-H5F4DGAM-UHR4F6LL.js +0 -13
- package/dist/src-7PBMYCGI.js +0 -1398
package/dist/chunk-UTOMPKTK.js
DELETED
|
@@ -1,2209 +0,0 @@
|
|
|
1
|
-
import { createRequire as __mcpCreateRequire } from "node:module";
|
|
2
|
-
const require = __mcpCreateRequire(import.meta.url);
|
|
3
|
-
import {
|
|
4
|
-
MODEL_ERROR_CODES,
|
|
5
|
-
__publicField
|
|
6
|
-
} from "./chunk-TQGHULC7.js";
|
|
7
|
-
|
|
8
|
-
// ../../node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/_u64.js
|
|
9
|
-
var fromNumH = (n) => n / 2 ** 32 | 0;
|
|
10
|
-
var fromNumL = (n) => n >>> 0;
|
|
11
|
-
function setU64FromNum(view, byteOffset, n, isLE) {
|
|
12
|
-
const h = fromNumH(n);
|
|
13
|
-
const l = fromNumL(n);
|
|
14
|
-
view.setUint32(byteOffset, isLE ? l : h, isLE);
|
|
15
|
-
view.setUint32(byteOffset + 4, isLE ? h : l, isLE);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// ../../node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/utils.js
|
|
19
|
-
function isBytes(a) {
|
|
20
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
21
|
-
}
|
|
22
|
-
var atitle = (title) => title ? `"${title}" ` : "";
|
|
23
|
-
function anumber(n, title = "") {
|
|
24
|
-
if (typeof n !== "number")
|
|
25
|
-
throw new TypeError(atitle(title) + "expected number, got " + typeof n);
|
|
26
|
-
if (!Number.isSafeInteger(n) || n < 0)
|
|
27
|
-
throw new RangeError(atitle(title) + "expected integer >= 0, got " + n);
|
|
28
|
-
return n;
|
|
29
|
-
}
|
|
30
|
-
function abytes(value, length, title = "") {
|
|
31
|
-
if (isBytes(value) && (length === void 0 || value.length === length))
|
|
32
|
-
return value;
|
|
33
|
-
if (length !== void 0)
|
|
34
|
-
anumber(length, "length");
|
|
35
|
-
const bytes = isBytes(value);
|
|
36
|
-
const ofLen = length !== void 0 ? ` of length ${length}` : "";
|
|
37
|
-
const got = bytes ? `length=${value.length}` : `type=${typeof value}`;
|
|
38
|
-
const message = atitle(title) + "expected Uint8Array" + ofLen + ", got " + got;
|
|
39
|
-
if (!bytes)
|
|
40
|
-
throw new TypeError(message);
|
|
41
|
-
throw new RangeError(message);
|
|
42
|
-
}
|
|
43
|
-
function ahash(h) {
|
|
44
|
-
if (typeof h !== "function" || typeof h.create !== "function")
|
|
45
|
-
throw new TypeError("expected hash wrapped by utils.createHasher");
|
|
46
|
-
anumber(h.outputLen);
|
|
47
|
-
anumber(h.blockLen);
|
|
48
|
-
if (h.outputLen < 1 || h.blockLen < 1)
|
|
49
|
-
throw new Error("hash blockLen / outputLen must be >= 1");
|
|
50
|
-
}
|
|
51
|
-
var aobject = (value, label) => {
|
|
52
|
-
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
53
|
-
throw new TypeError((label === "object" ? "" : `"${label}" `) + "expected object, got type=" + typeof value);
|
|
54
|
-
};
|
|
55
|
-
var aopts = (value, label) => {
|
|
56
|
-
aobject(value, label);
|
|
57
|
-
const proto = Object.getPrototypeOf(value);
|
|
58
|
-
if (proto !== Object.prototype && proto !== null)
|
|
59
|
-
throw new TypeError(`"${label}" expected plain object`);
|
|
60
|
-
if (Object.hasOwn(value, "__proto__"))
|
|
61
|
-
throw new TypeError(`"${label}.__proto__" is not allowed`);
|
|
62
|
-
};
|
|
63
|
-
function aexists(instance, checkFinished = true) {
|
|
64
|
-
if (instance.destroyed)
|
|
65
|
-
throw new Error("hash was destroyed");
|
|
66
|
-
if (checkFinished && instance.finished)
|
|
67
|
-
throw new Error("digest() was already called");
|
|
68
|
-
}
|
|
69
|
-
function aoutput(out, instance) {
|
|
70
|
-
abytes(out, void 0, "output");
|
|
71
|
-
const min = instance.outputLen;
|
|
72
|
-
if (!(out.length >= min)) {
|
|
73
|
-
throw new RangeError('"output" expected length >= ' + min);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function clean(...arrays) {
|
|
77
|
-
for (let i = 0; i < arrays.length; i++) {
|
|
78
|
-
arrays[i].fill(0);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function createView(arr) {
|
|
82
|
-
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
83
|
-
}
|
|
84
|
-
function rotr(word, shift) {
|
|
85
|
-
return word << 32 - shift | word >>> shift;
|
|
86
|
-
}
|
|
87
|
-
function checkOpts(defaults, opts, title = "opts") {
|
|
88
|
-
aopts(defaults, "defaults");
|
|
89
|
-
if (opts !== void 0)
|
|
90
|
-
aopts(opts, title);
|
|
91
|
-
const merged = Object.assign(/* @__PURE__ */ Object.create(null), defaults, opts);
|
|
92
|
-
return merged;
|
|
93
|
-
}
|
|
94
|
-
function createHasher(hashCons, info = {}) {
|
|
95
|
-
if (typeof hashCons !== "function")
|
|
96
|
-
throw new TypeError('"hashCons" expected function, got type=' + typeof hashCons);
|
|
97
|
-
info = checkOpts({}, info, "info");
|
|
98
|
-
const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
|
|
99
|
-
const tmp = hashCons(void 0);
|
|
100
|
-
hashC.outputLen = tmp.outputLen;
|
|
101
|
-
hashC.blockLen = tmp.blockLen;
|
|
102
|
-
hashC.canXOF = tmp.canXOF;
|
|
103
|
-
hashC.create = (opts) => hashCons(opts);
|
|
104
|
-
Object.assign(hashC, info);
|
|
105
|
-
return Object.freeze(hashC);
|
|
106
|
-
}
|
|
107
|
-
var oidNist = (suffix) => ({
|
|
108
|
-
// Current NIST hashAlgs suffixes used here fit in one DER subidentifier octet.
|
|
109
|
-
// Larger suffix values would need base-128 OID encoding and a different length byte.
|
|
110
|
-
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// ../../node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/_md.js
|
|
114
|
-
function Chi(a, b, c) {
|
|
115
|
-
return a & b ^ ~a & c;
|
|
116
|
-
}
|
|
117
|
-
function Maj(a, b, c) {
|
|
118
|
-
return a & b ^ a & c ^ b & c;
|
|
119
|
-
}
|
|
120
|
-
var HashMD = class {
|
|
121
|
-
blockLen;
|
|
122
|
-
outputLen;
|
|
123
|
-
canXOF = false;
|
|
124
|
-
padOffset;
|
|
125
|
-
isLE;
|
|
126
|
-
// For partial updates less than block size
|
|
127
|
-
buffer;
|
|
128
|
-
view;
|
|
129
|
-
finished = false;
|
|
130
|
-
length = 0;
|
|
131
|
-
pos = 0;
|
|
132
|
-
destroyed = false;
|
|
133
|
-
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
134
|
-
this.blockLen = blockLen;
|
|
135
|
-
this.outputLen = outputLen;
|
|
136
|
-
this.padOffset = padOffset;
|
|
137
|
-
this.isLE = isLE;
|
|
138
|
-
this.buffer = new Uint8Array(blockLen);
|
|
139
|
-
this.view = createView(this.buffer);
|
|
140
|
-
}
|
|
141
|
-
update(data) {
|
|
142
|
-
aexists(this);
|
|
143
|
-
abytes(data);
|
|
144
|
-
const { view, buffer, blockLen } = this;
|
|
145
|
-
const len = data.length;
|
|
146
|
-
let processed = false;
|
|
147
|
-
for (let pos = 0; pos < len; ) {
|
|
148
|
-
const take = Math.min(blockLen - this.pos, len - pos);
|
|
149
|
-
if (take === blockLen) {
|
|
150
|
-
const dataView = createView(data);
|
|
151
|
-
for (; blockLen <= len - pos; pos += blockLen)
|
|
152
|
-
this.process(dataView, pos);
|
|
153
|
-
processed = true;
|
|
154
|
-
continue;
|
|
155
|
-
}
|
|
156
|
-
buffer.set(pos === 0 && take === len ? data : data.subarray(pos, pos + take), this.pos);
|
|
157
|
-
this.pos += take;
|
|
158
|
-
pos += take;
|
|
159
|
-
if (this.pos === blockLen) {
|
|
160
|
-
this.process(view, 0);
|
|
161
|
-
this.pos = 0;
|
|
162
|
-
processed = true;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
this.length += data.length;
|
|
166
|
-
if (processed)
|
|
167
|
-
this.roundClean();
|
|
168
|
-
return this;
|
|
169
|
-
}
|
|
170
|
-
digestInto(out) {
|
|
171
|
-
aexists(this);
|
|
172
|
-
aoutput(out, this);
|
|
173
|
-
this.finished = true;
|
|
174
|
-
const { buffer, view, blockLen, isLE } = this;
|
|
175
|
-
let { pos } = this;
|
|
176
|
-
buffer[pos++] = 128;
|
|
177
|
-
buffer.fill(0, pos);
|
|
178
|
-
if (this.padOffset > blockLen - pos) {
|
|
179
|
-
this.process(view, 0);
|
|
180
|
-
buffer.fill(0);
|
|
181
|
-
}
|
|
182
|
-
setU64FromNum(view, blockLen - 8, this.length * 8, isLE);
|
|
183
|
-
this.process(view, 0);
|
|
184
|
-
this.roundClean();
|
|
185
|
-
const oview = out === buffer ? view : createView(out);
|
|
186
|
-
const len = this.outputLen;
|
|
187
|
-
const outLen = len / 4;
|
|
188
|
-
const state = this.get();
|
|
189
|
-
if (len % 4 || outLen > state.length)
|
|
190
|
-
throw new Error("invalid outputLen");
|
|
191
|
-
for (let i = 0; i < outLen; i++)
|
|
192
|
-
oview.setUint32(4 * i, state[i], isLE);
|
|
193
|
-
}
|
|
194
|
-
digest() {
|
|
195
|
-
const { buffer, outputLen } = this;
|
|
196
|
-
this.digestInto(buffer);
|
|
197
|
-
const res = buffer.slice(0, outputLen);
|
|
198
|
-
this.destroy();
|
|
199
|
-
return res;
|
|
200
|
-
}
|
|
201
|
-
_cloneIntoMeta(to) {
|
|
202
|
-
const { buffer, length, finished, destroyed, pos } = this;
|
|
203
|
-
to.destroyed = destroyed;
|
|
204
|
-
to.finished = finished;
|
|
205
|
-
to.length = length;
|
|
206
|
-
to.pos = pos;
|
|
207
|
-
if (pos)
|
|
208
|
-
to.buffer.set(buffer);
|
|
209
|
-
return to;
|
|
210
|
-
}
|
|
211
|
-
clone() {
|
|
212
|
-
return this._cloneInto();
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
216
|
-
1779033703,
|
|
217
|
-
3144134277,
|
|
218
|
-
1013904242,
|
|
219
|
-
2773480762,
|
|
220
|
-
1359893119,
|
|
221
|
-
2600822924,
|
|
222
|
-
528734635,
|
|
223
|
-
1541459225
|
|
224
|
-
]);
|
|
225
|
-
|
|
226
|
-
// ../../node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/sha2.js
|
|
227
|
-
var SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
228
|
-
1116352408,
|
|
229
|
-
1899447441,
|
|
230
|
-
3049323471,
|
|
231
|
-
3921009573,
|
|
232
|
-
961987163,
|
|
233
|
-
1508970993,
|
|
234
|
-
2453635748,
|
|
235
|
-
2870763221,
|
|
236
|
-
3624381080,
|
|
237
|
-
310598401,
|
|
238
|
-
607225278,
|
|
239
|
-
1426881987,
|
|
240
|
-
1925078388,
|
|
241
|
-
2162078206,
|
|
242
|
-
2614888103,
|
|
243
|
-
3248222580,
|
|
244
|
-
3835390401,
|
|
245
|
-
4022224774,
|
|
246
|
-
264347078,
|
|
247
|
-
604807628,
|
|
248
|
-
770255983,
|
|
249
|
-
1249150122,
|
|
250
|
-
1555081692,
|
|
251
|
-
1996064986,
|
|
252
|
-
2554220882,
|
|
253
|
-
2821834349,
|
|
254
|
-
2952996808,
|
|
255
|
-
3210313671,
|
|
256
|
-
3336571891,
|
|
257
|
-
3584528711,
|
|
258
|
-
113926993,
|
|
259
|
-
338241895,
|
|
260
|
-
666307205,
|
|
261
|
-
773529912,
|
|
262
|
-
1294757372,
|
|
263
|
-
1396182291,
|
|
264
|
-
1695183700,
|
|
265
|
-
1986661051,
|
|
266
|
-
2177026350,
|
|
267
|
-
2456956037,
|
|
268
|
-
2730485921,
|
|
269
|
-
2820302411,
|
|
270
|
-
3259730800,
|
|
271
|
-
3345764771,
|
|
272
|
-
3516065817,
|
|
273
|
-
3600352804,
|
|
274
|
-
4094571909,
|
|
275
|
-
275423344,
|
|
276
|
-
430227734,
|
|
277
|
-
506948616,
|
|
278
|
-
659060556,
|
|
279
|
-
883997877,
|
|
280
|
-
958139571,
|
|
281
|
-
1322822218,
|
|
282
|
-
1537002063,
|
|
283
|
-
1747873779,
|
|
284
|
-
1955562222,
|
|
285
|
-
2024104815,
|
|
286
|
-
2227730452,
|
|
287
|
-
2361852424,
|
|
288
|
-
2428436474,
|
|
289
|
-
2756734187,
|
|
290
|
-
3204031479,
|
|
291
|
-
3329325298
|
|
292
|
-
]);
|
|
293
|
-
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
294
|
-
var SHA2_32B = class extends HashMD {
|
|
295
|
-
// We cannot use array here since array allows indexing by variable
|
|
296
|
-
// which means optimizer/compiler cannot use registers.
|
|
297
|
-
// Numeric initializers matter: starting the fields as `undefined` changes
|
|
298
|
-
// V8's field representation and makes sha256 3x slower (measured).
|
|
299
|
-
A = 0;
|
|
300
|
-
B = 0;
|
|
301
|
-
C = 0;
|
|
302
|
-
D = 0;
|
|
303
|
-
E = 0;
|
|
304
|
-
F = 0;
|
|
305
|
-
G = 0;
|
|
306
|
-
H = 0;
|
|
307
|
-
constructor(outputLen, IV) {
|
|
308
|
-
super(64, outputLen, 8, false);
|
|
309
|
-
this.A = IV[0] | 0;
|
|
310
|
-
this.B = IV[1] | 0;
|
|
311
|
-
this.C = IV[2] | 0;
|
|
312
|
-
this.D = IV[3] | 0;
|
|
313
|
-
this.E = IV[4] | 0;
|
|
314
|
-
this.F = IV[5] | 0;
|
|
315
|
-
this.G = IV[6] | 0;
|
|
316
|
-
this.H = IV[7] | 0;
|
|
317
|
-
}
|
|
318
|
-
get() {
|
|
319
|
-
const { A, B, C, D, E, F, G, H } = this;
|
|
320
|
-
return [A, B, C, D, E, F, G, H];
|
|
321
|
-
}
|
|
322
|
-
// prettier-ignore
|
|
323
|
-
set(A, B, C, D, E, F, G, H) {
|
|
324
|
-
this.A = A | 0;
|
|
325
|
-
this.B = B | 0;
|
|
326
|
-
this.C = C | 0;
|
|
327
|
-
this.D = D | 0;
|
|
328
|
-
this.E = E | 0;
|
|
329
|
-
this.F = F | 0;
|
|
330
|
-
this.G = G | 0;
|
|
331
|
-
this.H = H | 0;
|
|
332
|
-
}
|
|
333
|
-
_cloneInto(to) {
|
|
334
|
-
(to ||= new this.constructor()).set(...this.get());
|
|
335
|
-
return this._cloneIntoMeta(to);
|
|
336
|
-
}
|
|
337
|
-
process(view, offset) {
|
|
338
|
-
for (let i = 0; i < 16; i++, offset += 4)
|
|
339
|
-
SHA256_W[i] = view.getUint32(offset, false);
|
|
340
|
-
for (let i = 16; i < 64; i++) {
|
|
341
|
-
const W15 = SHA256_W[i - 15];
|
|
342
|
-
const W2 = SHA256_W[i - 2];
|
|
343
|
-
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
344
|
-
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
345
|
-
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
346
|
-
}
|
|
347
|
-
let { A, B, C, D, E, F, G, H } = this;
|
|
348
|
-
for (let i = 0; i < 64; i++) {
|
|
349
|
-
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
350
|
-
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
351
|
-
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
352
|
-
const T2 = sigma0 + Maj(A, B, C) | 0;
|
|
353
|
-
H = G;
|
|
354
|
-
G = F;
|
|
355
|
-
F = E;
|
|
356
|
-
E = D + T1 | 0;
|
|
357
|
-
D = C;
|
|
358
|
-
C = B;
|
|
359
|
-
B = A;
|
|
360
|
-
A = T1 + T2 | 0;
|
|
361
|
-
}
|
|
362
|
-
A = A + this.A | 0;
|
|
363
|
-
B = B + this.B | 0;
|
|
364
|
-
C = C + this.C | 0;
|
|
365
|
-
D = D + this.D | 0;
|
|
366
|
-
E = E + this.E | 0;
|
|
367
|
-
F = F + this.F | 0;
|
|
368
|
-
G = G + this.G | 0;
|
|
369
|
-
H = H + this.H | 0;
|
|
370
|
-
this.set(A, B, C, D, E, F, G, H);
|
|
371
|
-
}
|
|
372
|
-
roundClean() {
|
|
373
|
-
clean(SHA256_W);
|
|
374
|
-
}
|
|
375
|
-
destroy() {
|
|
376
|
-
this.destroyed = true;
|
|
377
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
378
|
-
clean(this.buffer);
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
var _SHA256 = class extends SHA2_32B {
|
|
382
|
-
constructor() {
|
|
383
|
-
super(32, SHA256_IV);
|
|
384
|
-
}
|
|
385
|
-
};
|
|
386
|
-
var sha256 = /* @__PURE__ */ createHasher(
|
|
387
|
-
() => new _SHA256(),
|
|
388
|
-
/* @__PURE__ */ oidNist(1)
|
|
389
|
-
);
|
|
390
|
-
|
|
391
|
-
// ../../node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/hmac.js
|
|
392
|
-
var _HMAC = class {
|
|
393
|
-
oHash;
|
|
394
|
-
iHash;
|
|
395
|
-
blockLen;
|
|
396
|
-
outputLen;
|
|
397
|
-
canXOF = false;
|
|
398
|
-
finished = false;
|
|
399
|
-
destroyed = false;
|
|
400
|
-
constructor(hash, key) {
|
|
401
|
-
ahash(hash);
|
|
402
|
-
abytes(key, void 0, "key");
|
|
403
|
-
this.iHash = hash.create();
|
|
404
|
-
if (typeof this.iHash.update !== "function")
|
|
405
|
-
throw new Error("expected Hash instance");
|
|
406
|
-
this.blockLen = this.iHash.blockLen;
|
|
407
|
-
this.outputLen = this.iHash.outputLen;
|
|
408
|
-
const blockLen = this.blockLen;
|
|
409
|
-
const pad = new Uint8Array(blockLen);
|
|
410
|
-
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
|
|
411
|
-
for (let i = 0; i < pad.length; i++)
|
|
412
|
-
pad[i] ^= 54;
|
|
413
|
-
this.iHash.update(pad);
|
|
414
|
-
this.oHash = hash.create();
|
|
415
|
-
for (let i = 0; i < pad.length; i++)
|
|
416
|
-
pad[i] ^= 54 ^ 92;
|
|
417
|
-
this.oHash.update(pad);
|
|
418
|
-
clean(pad);
|
|
419
|
-
}
|
|
420
|
-
update(buf) {
|
|
421
|
-
aexists(this);
|
|
422
|
-
this.iHash.update(buf);
|
|
423
|
-
return this;
|
|
424
|
-
}
|
|
425
|
-
digestInto(out) {
|
|
426
|
-
aexists(this);
|
|
427
|
-
aoutput(out, this);
|
|
428
|
-
this.finished = true;
|
|
429
|
-
const buf = out.subarray(0, this.outputLen);
|
|
430
|
-
this.iHash.digestInto(buf);
|
|
431
|
-
this.oHash.update(buf);
|
|
432
|
-
this.oHash.digestInto(buf);
|
|
433
|
-
this.destroy();
|
|
434
|
-
}
|
|
435
|
-
digest() {
|
|
436
|
-
const out = new Uint8Array(this.oHash.outputLen);
|
|
437
|
-
this.digestInto(out);
|
|
438
|
-
return out;
|
|
439
|
-
}
|
|
440
|
-
_cloneInto(to) {
|
|
441
|
-
to ||= Object.create(Object.getPrototypeOf(this), {});
|
|
442
|
-
const { oHash, iHash, finished, destroyed, blockLen, outputLen, canXOF } = this;
|
|
443
|
-
to = to;
|
|
444
|
-
to.finished = finished;
|
|
445
|
-
to.destroyed = destroyed;
|
|
446
|
-
to.blockLen = blockLen;
|
|
447
|
-
to.outputLen = outputLen;
|
|
448
|
-
to.canXOF = canXOF;
|
|
449
|
-
to.oHash = oHash._cloneInto(to.oHash);
|
|
450
|
-
to.iHash = iHash._cloneInto(to.iHash);
|
|
451
|
-
return to;
|
|
452
|
-
}
|
|
453
|
-
clone() {
|
|
454
|
-
return this._cloneInto();
|
|
455
|
-
}
|
|
456
|
-
destroy() {
|
|
457
|
-
this.destroyed = true;
|
|
458
|
-
this.oHash.destroy();
|
|
459
|
-
this.iHash.destroy();
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
|
-
var hmac = /* @__PURE__ */ (() => {
|
|
463
|
-
const hmac_ = ((hash, key, message) => new _HMAC(hash, key).update(message).digest());
|
|
464
|
-
hmac_.create = (hash, key) => new _HMAC(hash, key);
|
|
465
|
-
return hmac_;
|
|
466
|
-
})();
|
|
467
|
-
|
|
468
|
-
// ../core/dist/chunk-SSQ2UNCC.js
|
|
469
|
-
var CORE_SERVICE_KEYS = {
|
|
470
|
-
MODELS: "models",
|
|
471
|
-
// 模型配置存储键
|
|
472
|
-
IMAGE_MODELS: "image-models",
|
|
473
|
-
// 图像模型配置存储键
|
|
474
|
-
USER_TEMPLATES: "user-templates",
|
|
475
|
-
// 用户模板存储键
|
|
476
|
-
PROMPT_HISTORY: "prompt_history"
|
|
477
|
-
// 提示词历史记录存储键
|
|
478
|
-
};
|
|
479
|
-
var UI_SETTINGS_KEYS = {
|
|
480
|
-
THEME_ID: "app:settings:ui:theme-id",
|
|
481
|
-
PREFERRED_LANGUAGE: "app:settings:ui:preferred-language",
|
|
482
|
-
BUILTIN_TEMPLATE_LANGUAGE: "app:settings:ui:builtin-template-language",
|
|
483
|
-
FUNCTION_MODE: "app:settings:ui:function-mode",
|
|
484
|
-
// 子模式持久化(三种功能模式独立存储)
|
|
485
|
-
BASIC_SUB_MODE: "app:settings:ui:basic-sub-mode",
|
|
486
|
-
// 基础模式的子模式(system/user)
|
|
487
|
-
PRO_SUB_MODE: "app:settings:ui:pro-sub-mode",
|
|
488
|
-
// Pro 模式的子模式(multi/variable)
|
|
489
|
-
IMAGE_SUB_MODE: "app:settings:ui:image-sub-mode"
|
|
490
|
-
// 图像模式的子模式(text2image/image2image)
|
|
491
|
-
};
|
|
492
|
-
var TEMPLATE_SELECTION_KEYS = {
|
|
493
|
-
SYSTEM_OPTIMIZE_TEMPLATE: "app:selected-optimize-template",
|
|
494
|
-
// 系统优化模板(兼容旧版本)
|
|
495
|
-
USER_OPTIMIZE_TEMPLATE: "app:selected-user-optimize-template",
|
|
496
|
-
// 用户优化模板
|
|
497
|
-
ITERATE_TEMPLATE: "app:selected-iterate-template",
|
|
498
|
-
// 迭代模板
|
|
499
|
-
CONTEXT_SYSTEM_OPTIMIZE_TEMPLATE: "app:selected-context-system-optimize-template",
|
|
500
|
-
CONTEXT_USER_OPTIMIZE_TEMPLATE: "app:selected-context-user-optimize-template",
|
|
501
|
-
CONTEXT_ITERATE_TEMPLATE: "app:selected-context-iterate-template"
|
|
502
|
-
};
|
|
503
|
-
var IMAGE_MODE_KEYS = {
|
|
504
|
-
SELECTED_TEXT_MODEL: "app:image-mode:selected-text-model",
|
|
505
|
-
SELECTED_IMAGE_MODEL: "app:image-mode:selected-image-model",
|
|
506
|
-
// 按模式分别存储模板选择
|
|
507
|
-
SELECTED_TEMPLATE_TEXT2IMAGE: "app:image-mode:selected-template:text2image",
|
|
508
|
-
SELECTED_TEMPLATE_IMAGE2IMAGE: "app:image-mode:selected-template:image2image",
|
|
509
|
-
SELECTED_ITERATE_TEMPLATE: "app:image-mode:selected-iterate-template",
|
|
510
|
-
COMPARE_MODE_ENABLED: "app:image-mode:compare-mode-enabled"
|
|
511
|
-
};
|
|
512
|
-
var FUNCTION_MODEL_KEYS = {
|
|
513
|
-
// 全局评估模型
|
|
514
|
-
EVALUATION_MODEL: "app:function-model:evaluation-model",
|
|
515
|
-
// 全局图片识别模型
|
|
516
|
-
IMAGE_RECOGNITION_MODEL: "app:function-model:image-recognition-model"
|
|
517
|
-
};
|
|
518
|
-
function getModeModelKey(type, functionMode, subMode) {
|
|
519
|
-
return `app:function-model:${type}:${functionMode}:${subMode}`;
|
|
520
|
-
}
|
|
521
|
-
var ALL_STORAGE_KEYS = {
|
|
522
|
-
...CORE_SERVICE_KEYS,
|
|
523
|
-
...UI_SETTINGS_KEYS,
|
|
524
|
-
...TEMPLATE_SELECTION_KEYS,
|
|
525
|
-
...IMAGE_MODE_KEYS,
|
|
526
|
-
...FUNCTION_MODEL_KEYS
|
|
527
|
-
};
|
|
528
|
-
var ALL_STORAGE_KEYS_ARRAY = Object.values(ALL_STORAGE_KEYS);
|
|
529
|
-
var PROMPT_MODE_KEYS = [
|
|
530
|
-
"arena",
|
|
531
|
-
"basic-system",
|
|
532
|
-
"basic-user",
|
|
533
|
-
"pro-variable",
|
|
534
|
-
"pro-conversation",
|
|
535
|
-
"image-text2image",
|
|
536
|
-
"image-image2image",
|
|
537
|
-
"image-multiimage"
|
|
538
|
-
];
|
|
539
|
-
var isPromptModeKey = (value) => typeof value === "string" && PROMPT_MODE_KEYS.includes(value);
|
|
540
|
-
var normalizeString = (value) => typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
541
|
-
var normalizeImageSubMode = (value) => {
|
|
542
|
-
if (value === "image2image") return "image2image";
|
|
543
|
-
if (value === "multiimage") return "multiimage";
|
|
544
|
-
return "text2image";
|
|
545
|
-
};
|
|
546
|
-
var resolvePromptModeKey = (input) => {
|
|
547
|
-
const functionMode = normalizeString(input.functionMode);
|
|
548
|
-
const optimizationMode = normalizeString(input.optimizationMode);
|
|
549
|
-
const proSubMode = normalizeString(input.proSubMode ?? input.subMode);
|
|
550
|
-
if (functionMode === "arena") return "arena";
|
|
551
|
-
if (functionMode === "image") {
|
|
552
|
-
return `image-${normalizeImageSubMode(input.imageSubMode)}`;
|
|
553
|
-
}
|
|
554
|
-
if (functionMode === "context") {
|
|
555
|
-
return optimizationMode === "user" ? "pro-variable" : "pro-conversation";
|
|
556
|
-
}
|
|
557
|
-
if (functionMode === "pro") {
|
|
558
|
-
return proSubMode === "variable" ? "pro-variable" : "pro-conversation";
|
|
559
|
-
}
|
|
560
|
-
return optimizationMode === "user" ? "basic-user" : "basic-system";
|
|
561
|
-
};
|
|
562
|
-
var promptModeKeyToFavoriteMode = (modeKey) => {
|
|
563
|
-
switch (modeKey) {
|
|
564
|
-
case "basic-user":
|
|
565
|
-
return { functionMode: "basic", optimizationMode: "user" };
|
|
566
|
-
case "pro-variable":
|
|
567
|
-
return { functionMode: "context", optimizationMode: "user" };
|
|
568
|
-
case "pro-conversation":
|
|
569
|
-
return { functionMode: "context", optimizationMode: "system" };
|
|
570
|
-
case "image-text2image":
|
|
571
|
-
return { functionMode: "image", imageSubMode: "text2image" };
|
|
572
|
-
case "image-image2image":
|
|
573
|
-
return { functionMode: "image", imageSubMode: "image2image" };
|
|
574
|
-
case "image-multiimage":
|
|
575
|
-
return { functionMode: "image", imageSubMode: "multiimage" };
|
|
576
|
-
case "basic-system":
|
|
577
|
-
default:
|
|
578
|
-
return { functionMode: "basic", optimizationMode: "system" };
|
|
579
|
-
}
|
|
580
|
-
};
|
|
581
|
-
var createPromptContract = (modeKey, options = {}) => {
|
|
582
|
-
const base = {
|
|
583
|
-
modeKey,
|
|
584
|
-
variables: options.variables ?? [],
|
|
585
|
-
inputs: options.inputs,
|
|
586
|
-
outputs: options.outputs,
|
|
587
|
-
metadata: options.metadata
|
|
588
|
-
};
|
|
589
|
-
switch (modeKey) {
|
|
590
|
-
case "arena":
|
|
591
|
-
return { ...base, family: "arena", modeKey };
|
|
592
|
-
case "basic-user":
|
|
593
|
-
return {
|
|
594
|
-
...base,
|
|
595
|
-
family: "basic",
|
|
596
|
-
subMode: "user",
|
|
597
|
-
modeKey
|
|
598
|
-
};
|
|
599
|
-
case "pro-variable":
|
|
600
|
-
return {
|
|
601
|
-
...base,
|
|
602
|
-
family: "pro",
|
|
603
|
-
subMode: "variable",
|
|
604
|
-
modeKey
|
|
605
|
-
};
|
|
606
|
-
case "pro-conversation":
|
|
607
|
-
return {
|
|
608
|
-
...base,
|
|
609
|
-
family: "pro",
|
|
610
|
-
subMode: "conversation",
|
|
611
|
-
modeKey
|
|
612
|
-
};
|
|
613
|
-
case "image-text2image":
|
|
614
|
-
return {
|
|
615
|
-
...base,
|
|
616
|
-
family: "image",
|
|
617
|
-
subMode: "text2image",
|
|
618
|
-
modeKey
|
|
619
|
-
};
|
|
620
|
-
case "image-image2image":
|
|
621
|
-
return {
|
|
622
|
-
...base,
|
|
623
|
-
family: "image",
|
|
624
|
-
subMode: "image2image",
|
|
625
|
-
modeKey
|
|
626
|
-
};
|
|
627
|
-
case "image-multiimage":
|
|
628
|
-
return {
|
|
629
|
-
...base,
|
|
630
|
-
family: "image",
|
|
631
|
-
subMode: "multiimage",
|
|
632
|
-
modeKey
|
|
633
|
-
};
|
|
634
|
-
case "basic-system":
|
|
635
|
-
default:
|
|
636
|
-
return {
|
|
637
|
-
...base,
|
|
638
|
-
family: "basic",
|
|
639
|
-
subMode: "system",
|
|
640
|
-
modeKey: "basic-system"
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
};
|
|
644
|
-
function getTextModelConfigIdentity(config) {
|
|
645
|
-
const providerId = config.providerId || config.providerMeta?.id || config.modelMeta?.providerId;
|
|
646
|
-
const modelId = config.modelId || config.modelMeta?.id;
|
|
647
|
-
if (!providerId || !modelId) {
|
|
648
|
-
return null;
|
|
649
|
-
}
|
|
650
|
-
return { providerId, modelId };
|
|
651
|
-
}
|
|
652
|
-
function resolveTextModelMetadata({
|
|
653
|
-
providerId,
|
|
654
|
-
modelId,
|
|
655
|
-
registry,
|
|
656
|
-
existingProviderMeta,
|
|
657
|
-
existingModelMeta
|
|
658
|
-
}) {
|
|
659
|
-
const adapter = registry.getAdapter(providerId);
|
|
660
|
-
const providerMeta = existingProviderMeta?.id === providerId ? existingProviderMeta : adapter.getProvider();
|
|
661
|
-
const modelMeta = existingModelMeta?.id === modelId && existingModelMeta.providerId === providerId ? existingModelMeta : adapter.getModels().find((model) => model.id === modelId) || adapter.buildDefaultModel(modelId);
|
|
662
|
-
return {
|
|
663
|
-
providerMeta,
|
|
664
|
-
modelMeta
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
function hasTextModelMetadataIdentityMismatch(providerMeta, modelMeta) {
|
|
668
|
-
return !!providerMeta?.id && !!modelMeta?.providerId && providerMeta.id !== modelMeta.providerId;
|
|
669
|
-
}
|
|
670
|
-
function hasExplicitTextModelIdentity(config) {
|
|
671
|
-
return !!config.providerId || !!config.modelId;
|
|
672
|
-
}
|
|
673
|
-
function resolveTextModelParameterDefinitions({
|
|
674
|
-
providerId,
|
|
675
|
-
modelId,
|
|
676
|
-
connectionConfig,
|
|
677
|
-
savedDefinitions,
|
|
678
|
-
registry
|
|
679
|
-
}) {
|
|
680
|
-
try {
|
|
681
|
-
const adapter = registry.getAdapter(providerId);
|
|
682
|
-
const provider = adapter.getProvider();
|
|
683
|
-
if (provider.id === "openai-compatible") return savedDefinitions;
|
|
684
|
-
const normalizeEndpoint = (endpoint2) => endpoint2.trim().replace(/\{(\w+)\}/g, (placeholder, field) => String(connectionConfig[field] ?? placeholder)).replace(/\/+$/, "");
|
|
685
|
-
const endpoint = connectionConfig.baseURL || provider.defaultBaseURL;
|
|
686
|
-
if (typeof endpoint !== "string" || !endpoint) return savedDefinitions;
|
|
687
|
-
const declaredEndpoints = [
|
|
688
|
-
provider.defaultBaseURL,
|
|
689
|
-
...(provider.regionalEndpoints ?? []).flatMap((region) => [region.openaiBaseURL, region.anthropicBaseURL])
|
|
690
|
-
];
|
|
691
|
-
if (!declaredEndpoints.some((url) => url && normalizeEndpoint(url) === normalizeEndpoint(endpoint))) {
|
|
692
|
-
return savedDefinitions;
|
|
693
|
-
}
|
|
694
|
-
const model = adapter.getModels().find((model2) => model2.id === modelId && model2.providerId === providerId);
|
|
695
|
-
if (!model) return savedDefinitions;
|
|
696
|
-
const currentNames = new Set(model.parameterDefinitions.map((definition) => definition.name));
|
|
697
|
-
return [
|
|
698
|
-
...model.parameterDefinitions,
|
|
699
|
-
...savedDefinitions.filter((definition) => !currentNames.has(definition.name))
|
|
700
|
-
];
|
|
701
|
-
} catch {
|
|
702
|
-
return savedDefinitions;
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
var DANGEROUS_PARAM_KEY_PATTERNS = [
|
|
706
|
-
"__proto__",
|
|
707
|
-
"constructor",
|
|
708
|
-
"prototype",
|
|
709
|
-
"eval",
|
|
710
|
-
"exec",
|
|
711
|
-
"script",
|
|
712
|
-
"process",
|
|
713
|
-
"child_process",
|
|
714
|
-
"function",
|
|
715
|
-
"code",
|
|
716
|
-
"apikey",
|
|
717
|
-
"api_key",
|
|
718
|
-
"secret",
|
|
719
|
-
"password",
|
|
720
|
-
"credential",
|
|
721
|
-
"authorization",
|
|
722
|
-
"bearer",
|
|
723
|
-
"token",
|
|
724
|
-
"baseurl",
|
|
725
|
-
"base_url",
|
|
726
|
-
"endpoint",
|
|
727
|
-
"url"
|
|
728
|
-
];
|
|
729
|
-
function isValueEmpty(value) {
|
|
730
|
-
if (value === void 0 || value === null) {
|
|
731
|
-
return true;
|
|
732
|
-
}
|
|
733
|
-
if (typeof value === "string") {
|
|
734
|
-
return value.trim().length === 0;
|
|
735
|
-
}
|
|
736
|
-
if (Array.isArray(value)) {
|
|
737
|
-
return value.length === 0;
|
|
738
|
-
}
|
|
739
|
-
return false;
|
|
740
|
-
}
|
|
741
|
-
function normalizeDefaultValue(value) {
|
|
742
|
-
if (isValueEmpty(value)) {
|
|
743
|
-
return void 0;
|
|
744
|
-
}
|
|
745
|
-
return value;
|
|
746
|
-
}
|
|
747
|
-
function isSafeCustomKey(key) {
|
|
748
|
-
if (!key) return false;
|
|
749
|
-
const trimmed = key.trim();
|
|
750
|
-
if (!trimmed) return false;
|
|
751
|
-
const allowedPattern = /^[A-Za-z0-9._\-:/]+$/;
|
|
752
|
-
if (!allowedPattern.test(trimmed)) {
|
|
753
|
-
return false;
|
|
754
|
-
}
|
|
755
|
-
const lower = trimmed.toLowerCase();
|
|
756
|
-
return !DANGEROUS_PARAM_KEY_PATTERNS.some((pattern) => lower.includes(pattern));
|
|
757
|
-
}
|
|
758
|
-
var PYTHON_LITERAL_REPLACEMENTS = [
|
|
759
|
-
["True", "true"],
|
|
760
|
-
["False", "false"],
|
|
761
|
-
["None", "null"]
|
|
762
|
-
];
|
|
763
|
-
function isIdentifierChar(char) {
|
|
764
|
-
return char !== void 0 && /[A-Za-z0-9_]/.test(char);
|
|
765
|
-
}
|
|
766
|
-
function normalizePythonLiterals(input) {
|
|
767
|
-
let result = "";
|
|
768
|
-
let inString = false;
|
|
769
|
-
let escaped = false;
|
|
770
|
-
for (let index = 0; index < input.length; index++) {
|
|
771
|
-
const char = input[index];
|
|
772
|
-
if (inString) {
|
|
773
|
-
result += char;
|
|
774
|
-
if (escaped) {
|
|
775
|
-
escaped = false;
|
|
776
|
-
} else if (char === "\\") {
|
|
777
|
-
escaped = true;
|
|
778
|
-
} else if (char === '"') {
|
|
779
|
-
inString = false;
|
|
780
|
-
}
|
|
781
|
-
continue;
|
|
782
|
-
}
|
|
783
|
-
if (char === '"') {
|
|
784
|
-
inString = true;
|
|
785
|
-
result += char;
|
|
786
|
-
continue;
|
|
787
|
-
}
|
|
788
|
-
const replacement = PYTHON_LITERAL_REPLACEMENTS.find(
|
|
789
|
-
([token]) => input.startsWith(token, index) && !isIdentifierChar(input[index - 1]) && !isIdentifierChar(input[index + token.length])
|
|
790
|
-
);
|
|
791
|
-
if (replacement) {
|
|
792
|
-
result += replacement[1];
|
|
793
|
-
index += replacement[0].length - 1;
|
|
794
|
-
} else {
|
|
795
|
-
result += char;
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
return result;
|
|
799
|
-
}
|
|
800
|
-
function parseCustomValue(value) {
|
|
801
|
-
const trimmed = value.trim();
|
|
802
|
-
const lower = trimmed.toLowerCase();
|
|
803
|
-
if (lower === "true") return true;
|
|
804
|
-
if (lower === "false") return false;
|
|
805
|
-
if (lower === "null") return null;
|
|
806
|
-
if (/^-?\d+$/.test(trimmed)) {
|
|
807
|
-
const num = parseInt(trimmed, 10);
|
|
808
|
-
if (Number.isSafeInteger(num)) return num;
|
|
809
|
-
}
|
|
810
|
-
if (/^-?\d+\.\d+$/.test(trimmed)) {
|
|
811
|
-
const num = parseFloat(trimmed);
|
|
812
|
-
if (Number.isFinite(num)) return num;
|
|
813
|
-
}
|
|
814
|
-
if (trimmed.startsWith("{") && trimmed.endsWith("}") || trimmed.startsWith("[") && trimmed.endsWith("]")) {
|
|
815
|
-
try {
|
|
816
|
-
return JSON.parse(trimmed);
|
|
817
|
-
} catch {
|
|
818
|
-
}
|
|
819
|
-
try {
|
|
820
|
-
return JSON.parse(normalizePythonLiterals(trimmed));
|
|
821
|
-
} catch {
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
return trimmed;
|
|
825
|
-
}
|
|
826
|
-
function splitOverridesBySchema(schema, overrides) {
|
|
827
|
-
const builtIn = {};
|
|
828
|
-
const custom = {};
|
|
829
|
-
if (!overrides) {
|
|
830
|
-
return { builtIn, custom };
|
|
831
|
-
}
|
|
832
|
-
const schemaMap = new Map(schema.map((def) => [def.name, def]));
|
|
833
|
-
for (const [key, value] of Object.entries(overrides)) {
|
|
834
|
-
if (schemaMap.has(key)) {
|
|
835
|
-
builtIn[key] = value;
|
|
836
|
-
} else {
|
|
837
|
-
custom[key] = value;
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
return { builtIn, custom };
|
|
841
|
-
}
|
|
842
|
-
function mergeOverrides({
|
|
843
|
-
schema,
|
|
844
|
-
includeDefaults = false,
|
|
845
|
-
builtInOverrides,
|
|
846
|
-
customOverrides,
|
|
847
|
-
requestOverrides
|
|
848
|
-
}) {
|
|
849
|
-
const result = {};
|
|
850
|
-
const schemaMap = new Map(schema.map((def) => [def.name, def]));
|
|
851
|
-
if (includeDefaults) {
|
|
852
|
-
for (const def of schema) {
|
|
853
|
-
const defaultVal = def.defaultValue ?? def.default;
|
|
854
|
-
if (defaultVal !== void 0 && shouldEmitValue(def, defaultVal)) {
|
|
855
|
-
result[def.name] = defaultVal;
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
if (customOverrides) {
|
|
860
|
-
for (const [key, value] of Object.entries(customOverrides)) {
|
|
861
|
-
if (!isSafeCustomKey(key) || isValueEmpty(value)) {
|
|
862
|
-
continue;
|
|
863
|
-
}
|
|
864
|
-
result[key] = value;
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
if (builtInOverrides) {
|
|
868
|
-
for (const [key, value] of Object.entries(builtInOverrides)) {
|
|
869
|
-
const def = schemaMap.get(key);
|
|
870
|
-
if (!def) continue;
|
|
871
|
-
if (!shouldEmitValue(def, value)) continue;
|
|
872
|
-
result[key] = value;
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
if (requestOverrides) {
|
|
876
|
-
for (const [key, value] of Object.entries(requestOverrides)) {
|
|
877
|
-
const def = schemaMap.get(key);
|
|
878
|
-
if (def) {
|
|
879
|
-
if (!shouldEmitValue(def, value)) continue;
|
|
880
|
-
} else {
|
|
881
|
-
if (!isSafeCustomKey(key) || isValueEmpty(value)) continue;
|
|
882
|
-
}
|
|
883
|
-
result[key] = value;
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
return result;
|
|
887
|
-
}
|
|
888
|
-
function validateOverrides({
|
|
889
|
-
schema,
|
|
890
|
-
overrides,
|
|
891
|
-
customOverrides,
|
|
892
|
-
allowUnknown = true
|
|
893
|
-
}) {
|
|
894
|
-
const errors = [];
|
|
895
|
-
const warnings = [];
|
|
896
|
-
const schemaMap = new Map(schema.map((def) => [def.name, def]));
|
|
897
|
-
if (overrides) {
|
|
898
|
-
for (const [key, value] of Object.entries(overrides)) {
|
|
899
|
-
const def = schemaMap.get(key);
|
|
900
|
-
if (!def) {
|
|
901
|
-
if (!allowUnknown) {
|
|
902
|
-
errors.push({
|
|
903
|
-
parameterName: key,
|
|
904
|
-
parameterValue: value,
|
|
905
|
-
message: `Parameter '${key}' is not defined in schema.`
|
|
906
|
-
});
|
|
907
|
-
} else {
|
|
908
|
-
if (!isSafeCustomKey(key)) {
|
|
909
|
-
errors.push({
|
|
910
|
-
parameterName: key,
|
|
911
|
-
parameterValue: value,
|
|
912
|
-
message: `Parameter '${key}' is potentially dangerous and not allowed.`
|
|
913
|
-
});
|
|
914
|
-
} else {
|
|
915
|
-
warnings.push({
|
|
916
|
-
parameterName: key,
|
|
917
|
-
parameterValue: value,
|
|
918
|
-
message: `Parameter '${key}' is not defined in schema and will be passed through as-is.`
|
|
919
|
-
});
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
continue;
|
|
923
|
-
}
|
|
924
|
-
const validationError = validateValueAgainstDefinition(value, def);
|
|
925
|
-
if (validationError) {
|
|
926
|
-
errors.push(validationError);
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
if (customOverrides) {
|
|
931
|
-
for (const [key, value] of Object.entries(customOverrides)) {
|
|
932
|
-
if (!isSafeCustomKey(key)) {
|
|
933
|
-
errors.push({
|
|
934
|
-
parameterName: key,
|
|
935
|
-
parameterValue: value,
|
|
936
|
-
message: `Custom parameter '${key}' is potentially dangerous and not allowed.`
|
|
937
|
-
});
|
|
938
|
-
continue;
|
|
939
|
-
}
|
|
940
|
-
if (isValueEmpty(value)) {
|
|
941
|
-
warnings.push({
|
|
942
|
-
parameterName: key,
|
|
943
|
-
parameterValue: value,
|
|
944
|
-
message: `Custom parameter '${key}' is empty and will be ignored.`
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
return { errors, warnings };
|
|
950
|
-
}
|
|
951
|
-
function shouldEmitValue(def, value) {
|
|
952
|
-
if (value === void 0 || value === null) {
|
|
953
|
-
return false;
|
|
954
|
-
}
|
|
955
|
-
if (typeof value === "string") {
|
|
956
|
-
if (value === "") {
|
|
957
|
-
return !!def.sendEmptyString;
|
|
958
|
-
}
|
|
959
|
-
return true;
|
|
960
|
-
}
|
|
961
|
-
if (Array.isArray(value)) {
|
|
962
|
-
return value.length > 0;
|
|
963
|
-
}
|
|
964
|
-
return true;
|
|
965
|
-
}
|
|
966
|
-
function validateValueAgainstDefinition(value, def) {
|
|
967
|
-
if (def.tags?.includes("string-array")) {
|
|
968
|
-
if (!Array.isArray(value)) {
|
|
969
|
-
return {
|
|
970
|
-
parameterName: def.name,
|
|
971
|
-
parameterValue: value,
|
|
972
|
-
message: `Parameter '${def.name}' should be a string array, but received ${typeof value}.`,
|
|
973
|
-
expectedType: "string"
|
|
974
|
-
};
|
|
975
|
-
}
|
|
976
|
-
if (value.length === 0) {
|
|
977
|
-
return {
|
|
978
|
-
parameterName: def.name,
|
|
979
|
-
parameterValue: value,
|
|
980
|
-
message: `Parameter '${def.name}' cannot be an empty array.`,
|
|
981
|
-
expectedType: "string"
|
|
982
|
-
};
|
|
983
|
-
}
|
|
984
|
-
const allStrings = value.every((item) => typeof item === "string");
|
|
985
|
-
if (!allStrings) {
|
|
986
|
-
return {
|
|
987
|
-
parameterName: def.name,
|
|
988
|
-
parameterValue: value,
|
|
989
|
-
message: `Parameter '${def.name}' array entries must all be strings.`,
|
|
990
|
-
expectedType: "string"
|
|
991
|
-
};
|
|
992
|
-
}
|
|
993
|
-
return null;
|
|
994
|
-
}
|
|
995
|
-
if (!shouldEmitValue(def, value)) {
|
|
996
|
-
return {
|
|
997
|
-
parameterName: def.name,
|
|
998
|
-
parameterValue: value,
|
|
999
|
-
message: `Parameter '${def.name}' is empty and will be ignored. Provide a value to override.`,
|
|
1000
|
-
expectedType: def.type
|
|
1001
|
-
};
|
|
1002
|
-
}
|
|
1003
|
-
if (!validateType(value, def.type)) {
|
|
1004
|
-
return {
|
|
1005
|
-
parameterName: def.name,
|
|
1006
|
-
parameterValue: value,
|
|
1007
|
-
message: `Parameter '${def.name}' should be of type ${def.type}, but received ${typeof value}.`,
|
|
1008
|
-
expectedType: def.type
|
|
1009
|
-
};
|
|
1010
|
-
}
|
|
1011
|
-
if ((def.type === "number" || def.type === "integer") && typeof value === "number") {
|
|
1012
|
-
const min = def.minValue ?? def.min;
|
|
1013
|
-
const max = def.maxValue ?? def.max;
|
|
1014
|
-
if (min !== void 0 && value < min) {
|
|
1015
|
-
return {
|
|
1016
|
-
parameterName: def.name,
|
|
1017
|
-
parameterValue: value,
|
|
1018
|
-
message: `Parameter '${def.name}' value ${value} is less than minimum value ${min}.`,
|
|
1019
|
-
expectedType: def.type,
|
|
1020
|
-
expectedRange: buildExpectedRange(def)
|
|
1021
|
-
};
|
|
1022
|
-
}
|
|
1023
|
-
if (max !== void 0 && value > max) {
|
|
1024
|
-
return {
|
|
1025
|
-
parameterName: def.name,
|
|
1026
|
-
parameterValue: value,
|
|
1027
|
-
message: `Parameter '${def.name}' value ${value} is greater than maximum value ${max}.`,
|
|
1028
|
-
expectedType: def.type,
|
|
1029
|
-
expectedRange: buildExpectedRange(def)
|
|
1030
|
-
};
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
if (def.allowedValues && def.allowedValues.length > 0) {
|
|
1034
|
-
if (typeof value !== "string" || !def.allowedValues.includes(value)) {
|
|
1035
|
-
return {
|
|
1036
|
-
parameterName: def.name,
|
|
1037
|
-
parameterValue: value,
|
|
1038
|
-
message: `Parameter '${def.name}' must be one of: ${def.allowedValues.join(", ")}.`,
|
|
1039
|
-
expectedType: def.type
|
|
1040
|
-
};
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
return null;
|
|
1044
|
-
}
|
|
1045
|
-
function validateType(value, expectedType) {
|
|
1046
|
-
switch (expectedType) {
|
|
1047
|
-
case "number":
|
|
1048
|
-
return typeof value === "number" && Number.isFinite(value);
|
|
1049
|
-
case "integer":
|
|
1050
|
-
return typeof value === "number" && Number.isInteger(value);
|
|
1051
|
-
case "boolean":
|
|
1052
|
-
return typeof value === "boolean";
|
|
1053
|
-
case "string":
|
|
1054
|
-
default:
|
|
1055
|
-
return typeof value === "string";
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
function buildExpectedRange(def) {
|
|
1059
|
-
const min = def.minValue ?? def.min;
|
|
1060
|
-
const max = def.maxValue ?? def.max;
|
|
1061
|
-
if (min !== void 0 && max !== void 0) {
|
|
1062
|
-
return `${min} - ${max}`;
|
|
1063
|
-
}
|
|
1064
|
-
if (min !== void 0) {
|
|
1065
|
-
return `>= ${min}`;
|
|
1066
|
-
}
|
|
1067
|
-
if (max !== void 0) {
|
|
1068
|
-
return `<= ${max}`;
|
|
1069
|
-
}
|
|
1070
|
-
return void 0;
|
|
1071
|
-
}
|
|
1072
|
-
var PROMPT_MODEL_SCHEMA_VERSION = "prompt-model/v1";
|
|
1073
|
-
var promptContentFromText = (text2, modeKey = "basic-system") => {
|
|
1074
|
-
if (modeKey.startsWith("image-")) {
|
|
1075
|
-
return { kind: "image-prompt", text: text2 };
|
|
1076
|
-
}
|
|
1077
|
-
return { kind: "text", text: text2 };
|
|
1078
|
-
};
|
|
1079
|
-
var isPlainObject = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1080
|
-
var asTrimmedString = (value) => {
|
|
1081
|
-
if (typeof value !== "string") return void 0;
|
|
1082
|
-
const trimmed = value.trim();
|
|
1083
|
-
return trimmed ? trimmed : void 0;
|
|
1084
|
-
};
|
|
1085
|
-
var asStringArray = (value) => {
|
|
1086
|
-
if (!Array.isArray(value)) return [];
|
|
1087
|
-
return value.map((item) => asTrimmedString(item)).filter((item) => Boolean(item));
|
|
1088
|
-
};
|
|
1089
|
-
var dedupeStrings = (items) => {
|
|
1090
|
-
const out = [];
|
|
1091
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1092
|
-
for (const item of items) {
|
|
1093
|
-
const normalized = item.trim();
|
|
1094
|
-
if (!normalized || seen.has(normalized)) continue;
|
|
1095
|
-
seen.add(normalized);
|
|
1096
|
-
out.push(normalized);
|
|
1097
|
-
}
|
|
1098
|
-
return out;
|
|
1099
|
-
};
|
|
1100
|
-
var normalizeVariableType = (value) => {
|
|
1101
|
-
if (value === "string" || value === "number" || value === "boolean" || value === "enum") {
|
|
1102
|
-
return value;
|
|
1103
|
-
}
|
|
1104
|
-
return void 0;
|
|
1105
|
-
};
|
|
1106
|
-
var parseVariable = (value) => {
|
|
1107
|
-
if (!isPlainObject(value)) return null;
|
|
1108
|
-
const name = asTrimmedString(value.name);
|
|
1109
|
-
if (!name) return null;
|
|
1110
|
-
return {
|
|
1111
|
-
name,
|
|
1112
|
-
description: asTrimmedString(value.description),
|
|
1113
|
-
type: normalizeVariableType(value.type),
|
|
1114
|
-
required: value.required === true,
|
|
1115
|
-
defaultValue: asTrimmedString(value.defaultValue ?? value.default ?? value.value),
|
|
1116
|
-
options: dedupeStrings(asStringArray(value.options)),
|
|
1117
|
-
source: asTrimmedString(value.source)
|
|
1118
|
-
};
|
|
1119
|
-
};
|
|
1120
|
-
var parseVariables = (value) => {
|
|
1121
|
-
if (Array.isArray(value)) {
|
|
1122
|
-
return value.map((item) => parseVariable(item)).filter((item) => Boolean(item));
|
|
1123
|
-
}
|
|
1124
|
-
if (!isPlainObject(value)) return [];
|
|
1125
|
-
return Object.entries(value).map(([name, raw]) => {
|
|
1126
|
-
const normalizedName = name.trim();
|
|
1127
|
-
if (!normalizedName) return null;
|
|
1128
|
-
return {
|
|
1129
|
-
name: normalizedName,
|
|
1130
|
-
required: false,
|
|
1131
|
-
defaultValue: raw === void 0 || raw === null ? void 0 : String(raw),
|
|
1132
|
-
options: []
|
|
1133
|
-
};
|
|
1134
|
-
}).filter((item) => Boolean(item));
|
|
1135
|
-
};
|
|
1136
|
-
var parseParameters = (value) => {
|
|
1137
|
-
if (!isPlainObject(value)) return {};
|
|
1138
|
-
const out = {};
|
|
1139
|
-
for (const [key, raw] of Object.entries(value)) {
|
|
1140
|
-
const normalizedKey = key.trim();
|
|
1141
|
-
if (!normalizedKey || raw === void 0 || raw === null) continue;
|
|
1142
|
-
out[normalizedKey] = String(raw);
|
|
1143
|
-
}
|
|
1144
|
-
return out;
|
|
1145
|
-
};
|
|
1146
|
-
var parseMessages = (value) => {
|
|
1147
|
-
if (!Array.isArray(value)) return [];
|
|
1148
|
-
return value.map((item) => {
|
|
1149
|
-
if (!isPlainObject(item)) return null;
|
|
1150
|
-
if (item.role !== "system" && item.role !== "user" && item.role !== "assistant" && item.role !== "tool") {
|
|
1151
|
-
return null;
|
|
1152
|
-
}
|
|
1153
|
-
const content = typeof item.content === "string" ? item.content : "";
|
|
1154
|
-
return {
|
|
1155
|
-
...asTrimmedString(item.id) ? { id: asTrimmedString(item.id) } : {},
|
|
1156
|
-
role: item.role,
|
|
1157
|
-
content,
|
|
1158
|
-
...asTrimmedString(item.originalContent) ? { originalContent: asTrimmedString(item.originalContent) } : {},
|
|
1159
|
-
...asTrimmedString(item.name) ? { name: asTrimmedString(item.name) } : {},
|
|
1160
|
-
...Array.isArray(item.tool_calls) ? { tool_calls: item.tool_calls } : {},
|
|
1161
|
-
...asTrimmedString(item.tool_call_id) ? { tool_call_id: asTrimmedString(item.tool_call_id) } : {}
|
|
1162
|
-
};
|
|
1163
|
-
}).filter((item) => Boolean(item));
|
|
1164
|
-
};
|
|
1165
|
-
var imageRefsFromParts = (urls, assetIds) => [
|
|
1166
|
-
...dedupeStrings(asStringArray(urls)).map((url) => ({ kind: "url", url })),
|
|
1167
|
-
...dedupeStrings(asStringArray(assetIds)).map((assetId) => ({
|
|
1168
|
-
kind: "asset",
|
|
1169
|
-
assetId
|
|
1170
|
-
}))
|
|
1171
|
-
];
|
|
1172
|
-
var parseSourceRef = (value) => {
|
|
1173
|
-
if (!isPlainObject(value)) return void 0;
|
|
1174
|
-
const kind = asTrimmedString(value.kind);
|
|
1175
|
-
if (kind !== "workspace" && kind !== "favorite" && kind !== "garden" && kind !== "history" && kind !== "external" && kind !== "unknown") {
|
|
1176
|
-
return void 0;
|
|
1177
|
-
}
|
|
1178
|
-
return {
|
|
1179
|
-
kind,
|
|
1180
|
-
...asTrimmedString(value.id) ? { id: asTrimmedString(value.id) } : {},
|
|
1181
|
-
...asTrimmedString(value.label) ? { label: asTrimmedString(value.label) } : {},
|
|
1182
|
-
...asTrimmedString(value.url) ? { url: asTrimmedString(value.url) } : {},
|
|
1183
|
-
...isPlainObject(value.metadata) ? { metadata: { ...value.metadata } } : {}
|
|
1184
|
-
};
|
|
1185
|
-
};
|
|
1186
|
-
var parseExample = (value, favorite, index, basedOnVersionId) => {
|
|
1187
|
-
if (!isPlainObject(value)) return null;
|
|
1188
|
-
const text2 = asTrimmedString(value.text);
|
|
1189
|
-
const description = asTrimmedString(value.description);
|
|
1190
|
-
const outputText = asTrimmedString(value.outputText);
|
|
1191
|
-
const messages = parseMessages(value.messages);
|
|
1192
|
-
const parameters = parseParameters(value.parameters);
|
|
1193
|
-
const inputImages = imageRefsFromParts(value.inputImages, value.inputImageAssetIds);
|
|
1194
|
-
const outputImages = imageRefsFromParts(
|
|
1195
|
-
value.url ? [value.url] : value.images,
|
|
1196
|
-
value.imageAssetIds
|
|
1197
|
-
);
|
|
1198
|
-
const exampleBasedOnVersionId = asTrimmedString(value.basedOnVersionId) ?? basedOnVersionId;
|
|
1199
|
-
const input = {};
|
|
1200
|
-
if (text2) input.text = text2;
|
|
1201
|
-
if (messages.length > 0) input.messages = messages;
|
|
1202
|
-
if (Object.keys(parameters).length > 0) input.parameters = parameters;
|
|
1203
|
-
if (inputImages.length > 0) input.images = inputImages;
|
|
1204
|
-
const output = {};
|
|
1205
|
-
if (outputText) output.text = outputText;
|
|
1206
|
-
if (outputImages.length > 0) output.images = outputImages;
|
|
1207
|
-
const hasInputData = Boolean(input.text || input.messages || input.parameters || input.images);
|
|
1208
|
-
const hasOutputData = Boolean(output.text || output.images);
|
|
1209
|
-
if (!hasInputData && !hasOutputData && !description) return null;
|
|
1210
|
-
return {
|
|
1211
|
-
id: asTrimmedString(value.id) ?? `favorite:${favorite.id}:example:${index + 1}`,
|
|
1212
|
-
basedOnVersionId: exampleBasedOnVersionId,
|
|
1213
|
-
description,
|
|
1214
|
-
input,
|
|
1215
|
-
output: hasOutputData ? output : void 0,
|
|
1216
|
-
source: parseSourceRef(value.source) ?? { kind: "favorite", id: favorite.id },
|
|
1217
|
-
metadata: isPlainObject(value.metadata) ? { ...value.metadata } : void 0
|
|
1218
|
-
};
|
|
1219
|
-
};
|
|
1220
|
-
var parseExamples = (value, favorite, basedOnVersionId) => {
|
|
1221
|
-
if (!Array.isArray(value)) return [];
|
|
1222
|
-
return value.map((item, index) => parseExample(item, favorite, index, basedOnVersionId)).filter((item) => Boolean(item));
|
|
1223
|
-
};
|
|
1224
|
-
var readReproducibility = (metadata, favorite, basedOnVersionId) => {
|
|
1225
|
-
if (!metadata) {
|
|
1226
|
-
return { variables: [], examples: [] };
|
|
1227
|
-
}
|
|
1228
|
-
const reproducibility = isPlainObject(metadata.reproducibility) ? metadata.reproducibility : null;
|
|
1229
|
-
if (reproducibility) {
|
|
1230
|
-
return {
|
|
1231
|
-
variables: parseVariables(reproducibility.variables),
|
|
1232
|
-
examples: parseExamples(reproducibility.examples, favorite, basedOnVersionId),
|
|
1233
|
-
sourceKind: "favorite"
|
|
1234
|
-
};
|
|
1235
|
-
}
|
|
1236
|
-
const gardenSnapshot = isPlainObject(metadata.gardenSnapshot) ? metadata.gardenSnapshot : null;
|
|
1237
|
-
if (gardenSnapshot) {
|
|
1238
|
-
const assets = isPlainObject(gardenSnapshot.assets) ? gardenSnapshot.assets : {};
|
|
1239
|
-
return {
|
|
1240
|
-
variables: parseVariables(gardenSnapshot.variables),
|
|
1241
|
-
examples: parseExamples(assets.examples, favorite, basedOnVersionId),
|
|
1242
|
-
sourceKind: "garden"
|
|
1243
|
-
};
|
|
1244
|
-
}
|
|
1245
|
-
return {
|
|
1246
|
-
variables: parseVariables(metadata.variables),
|
|
1247
|
-
examples: parseExamples(metadata.examples, favorite, basedOnVersionId),
|
|
1248
|
-
sourceKind: "favorite"
|
|
1249
|
-
};
|
|
1250
|
-
};
|
|
1251
|
-
var stripWorkspaceDraftReproducibility = (reproducibility) => ({
|
|
1252
|
-
...reproducibility,
|
|
1253
|
-
variables: reproducibility.variables.map((variable) => {
|
|
1254
|
-
if (variable.source !== "workspace") return variable;
|
|
1255
|
-
const next = {
|
|
1256
|
-
name: variable.name,
|
|
1257
|
-
required: variable.required,
|
|
1258
|
-
options: variable.options
|
|
1259
|
-
};
|
|
1260
|
-
if (variable.description !== void 0) next.description = variable.description;
|
|
1261
|
-
if (variable.type !== void 0) next.type = variable.type;
|
|
1262
|
-
if (variable.source !== void 0) next.source = variable.source;
|
|
1263
|
-
return next;
|
|
1264
|
-
}),
|
|
1265
|
-
examples: reproducibility.examples.filter((example) => example.id !== "workspace-current")
|
|
1266
|
-
});
|
|
1267
|
-
var isPromptAsset = (value) => {
|
|
1268
|
-
if (!isPlainObject(value)) return false;
|
|
1269
|
-
if (value.schemaVersion !== PROMPT_MODEL_SCHEMA_VERSION) return false;
|
|
1270
|
-
if (!asTrimmedString(value.id) || !asTrimmedString(value.title)) return false;
|
|
1271
|
-
if (!isPlainObject(value.contract) || !isPromptModeKey(value.contract.modeKey)) return false;
|
|
1272
|
-
if (!asTrimmedString(value.currentVersionId) || !Array.isArray(value.versions)) return false;
|
|
1273
|
-
if (!Array.isArray(value.examples)) return false;
|
|
1274
|
-
return typeof value.createdAt === "number" && typeof value.updatedAt === "number";
|
|
1275
|
-
};
|
|
1276
|
-
var clonePromptSource = (source) => source ? {
|
|
1277
|
-
...source,
|
|
1278
|
-
...source.metadata ? { metadata: { ...source.metadata } } : {}
|
|
1279
|
-
} : void 0;
|
|
1280
|
-
var clonePromptContent = (content) => {
|
|
1281
|
-
if (content.kind === "messages") {
|
|
1282
|
-
return {
|
|
1283
|
-
kind: "messages",
|
|
1284
|
-
messages: content.messages.map((message) => ({ ...message }))
|
|
1285
|
-
};
|
|
1286
|
-
}
|
|
1287
|
-
if (content.kind === "image-prompt") {
|
|
1288
|
-
return {
|
|
1289
|
-
kind: "image-prompt",
|
|
1290
|
-
text: content.text,
|
|
1291
|
-
...content.images ? { images: content.images.map((image) => ({ ...image })) } : {}
|
|
1292
|
-
};
|
|
1293
|
-
}
|
|
1294
|
-
return { kind: "text", text: content.text };
|
|
1295
|
-
};
|
|
1296
|
-
var clonePromptAssetVersions = (asset) => asset.versions.map((version) => ({
|
|
1297
|
-
...version,
|
|
1298
|
-
content: clonePromptContent(version.content),
|
|
1299
|
-
source: clonePromptSource(version.source),
|
|
1300
|
-
metadata: version.metadata ? { ...version.metadata } : void 0
|
|
1301
|
-
}));
|
|
1302
|
-
var clonePromptExamples = (examples) => examples.map((example) => ({
|
|
1303
|
-
...example,
|
|
1304
|
-
input: {
|
|
1305
|
-
...example.input,
|
|
1306
|
-
messages: example.input.messages?.map((message) => ({ ...message })),
|
|
1307
|
-
parameters: example.input.parameters ? { ...example.input.parameters } : void 0,
|
|
1308
|
-
images: example.input.images?.map((image) => ({ ...image })),
|
|
1309
|
-
metadata: example.input.metadata ? { ...example.input.metadata } : void 0
|
|
1310
|
-
},
|
|
1311
|
-
output: example.output ? {
|
|
1312
|
-
...example.output,
|
|
1313
|
-
images: example.output.images?.map((image) => ({ ...image })),
|
|
1314
|
-
metadata: example.output.metadata ? { ...example.output.metadata } : void 0
|
|
1315
|
-
} : void 0,
|
|
1316
|
-
source: clonePromptSource(example.source),
|
|
1317
|
-
metadata: example.metadata ? { ...example.metadata } : void 0
|
|
1318
|
-
}));
|
|
1319
|
-
var messagesToComparableText = (messages) => messages.map((message) => ({
|
|
1320
|
-
role: message.role,
|
|
1321
|
-
content: typeof message.content === "string" ? message.content.trim() : ""
|
|
1322
|
-
})).filter((message) => message.content).map((message) => `[${message.role}]
|
|
1323
|
-
${message.content}`).join("\n\n");
|
|
1324
|
-
var promptContentToFavoriteContent = (content) => {
|
|
1325
|
-
if (content.kind === "text" || content.kind === "image-prompt") {
|
|
1326
|
-
return content.text;
|
|
1327
|
-
}
|
|
1328
|
-
return messagesToComparableText(content.messages);
|
|
1329
|
-
};
|
|
1330
|
-
var promptContentEquals = (left, right) => {
|
|
1331
|
-
if (left.kind === "text" && right.kind === "text") {
|
|
1332
|
-
return left.text === right.text;
|
|
1333
|
-
}
|
|
1334
|
-
if (left.kind === "image-prompt" && right.kind === "image-prompt") {
|
|
1335
|
-
return left.text === right.text;
|
|
1336
|
-
}
|
|
1337
|
-
if (left.kind === "messages" && right.kind === "messages") {
|
|
1338
|
-
return JSON.stringify(left.messages) === JSON.stringify(right.messages);
|
|
1339
|
-
}
|
|
1340
|
-
if (left.kind === "messages" && right.kind === "text") {
|
|
1341
|
-
return messagesToComparableText(left.messages) === right.text;
|
|
1342
|
-
}
|
|
1343
|
-
if (left.kind === "text" && right.kind === "messages") {
|
|
1344
|
-
return left.text === messagesToComparableText(right.messages);
|
|
1345
|
-
}
|
|
1346
|
-
return false;
|
|
1347
|
-
};
|
|
1348
|
-
var hasReproducibilitySource = (metadata) => {
|
|
1349
|
-
if (!metadata) return false;
|
|
1350
|
-
return Object.prototype.hasOwnProperty.call(metadata, "reproducibility") || Object.prototype.hasOwnProperty.call(metadata, "gardenSnapshot") || Object.prototype.hasOwnProperty.call(metadata, "variables") || Object.prototype.hasOwnProperty.call(metadata, "examples");
|
|
1351
|
-
};
|
|
1352
|
-
var nextContentVersionNumber = (versions) => versions.reduce((max, version) => Math.max(max, Number.isFinite(version.version) ? version.version : 0), 0) + 1;
|
|
1353
|
-
var createContentVersionId = (favorite, versionNumber) => `favorite:${favorite.id}:version:${versionNumber}`;
|
|
1354
|
-
var rebaseDefaultExampleVersionIds = (examples, defaultVersionId, currentVersionId) => clonePromptExamples(examples).map((example) => example.basedOnVersionId === defaultVersionId ? { ...example, basedOnVersionId: currentVersionId } : example);
|
|
1355
|
-
var switchPromptAssetCurrentVersion = (asset, versionId, updatedAt) => {
|
|
1356
|
-
const targetVersion = asset.versions.find((version) => version.id === versionId);
|
|
1357
|
-
if (!targetVersion) return null;
|
|
1358
|
-
return {
|
|
1359
|
-
promptAsset: {
|
|
1360
|
-
...asset,
|
|
1361
|
-
currentVersionId: targetVersion.id,
|
|
1362
|
-
versions: clonePromptAssetVersions(asset),
|
|
1363
|
-
examples: clonePromptExamples(asset.examples),
|
|
1364
|
-
source: clonePromptSource(asset.source),
|
|
1365
|
-
metadata: asset.metadata ? { ...asset.metadata } : void 0,
|
|
1366
|
-
updatedAt
|
|
1367
|
-
},
|
|
1368
|
-
content: promptContentToFavoriteContent(targetVersion.content)
|
|
1369
|
-
};
|
|
1370
|
-
};
|
|
1371
|
-
var deletePromptAssetVersion = (asset, versionId, updatedAt) => {
|
|
1372
|
-
if (asset.currentVersionId === versionId || asset.versions.length <= 1) return null;
|
|
1373
|
-
if (!asset.versions.some((version) => version.id === versionId)) return null;
|
|
1374
|
-
return {
|
|
1375
|
-
...asset,
|
|
1376
|
-
versions: clonePromptAssetVersions(asset).filter((version) => version.id !== versionId),
|
|
1377
|
-
examples: clonePromptExamples(asset.examples),
|
|
1378
|
-
source: clonePromptSource(asset.source),
|
|
1379
|
-
metadata: asset.metadata ? { ...asset.metadata } : void 0,
|
|
1380
|
-
updatedAt
|
|
1381
|
-
};
|
|
1382
|
-
};
|
|
1383
|
-
var promptAssetFromFavorite = (favorite, options = {}) => {
|
|
1384
|
-
const metadata = isPlainObject(favorite.metadata) ? favorite.metadata : void 0;
|
|
1385
|
-
if (!options.ignoreEmbeddedAsset && isPromptAsset(metadata?.promptAsset)) {
|
|
1386
|
-
return metadata.promptAsset;
|
|
1387
|
-
}
|
|
1388
|
-
const modeKey = resolvePromptModeKey({
|
|
1389
|
-
functionMode: favorite.functionMode,
|
|
1390
|
-
optimizationMode: favorite.optimizationMode,
|
|
1391
|
-
imageSubMode: favorite.imageSubMode
|
|
1392
|
-
});
|
|
1393
|
-
const versionId = `favorite:${favorite.id}:current`;
|
|
1394
|
-
const rawReproducibility = readReproducibility(metadata, favorite, versionId);
|
|
1395
|
-
const reproducibility = options.stripWorkspaceDraft ? stripWorkspaceDraftReproducibility(rawReproducibility) : rawReproducibility;
|
|
1396
|
-
const sourceKind = reproducibility.sourceKind ?? "favorite";
|
|
1397
|
-
const contentMetadata = {};
|
|
1398
|
-
if (metadata?.originalContent !== void 0) contentMetadata.originalContent = metadata.originalContent;
|
|
1399
|
-
if (metadata?.sourceHistoryId !== void 0) contentMetadata.sourceHistoryId = metadata.sourceHistoryId;
|
|
1400
|
-
if (metadata?.modelKey !== void 0) contentMetadata.modelKey = metadata.modelKey;
|
|
1401
|
-
if (metadata?.modelName !== void 0) contentMetadata.modelName = metadata.modelName;
|
|
1402
|
-
if (metadata?.templateId !== void 0) contentMetadata.templateId = metadata.templateId;
|
|
1403
|
-
return {
|
|
1404
|
-
schemaVersion: PROMPT_MODEL_SCHEMA_VERSION,
|
|
1405
|
-
id: `favorite:${favorite.id}`,
|
|
1406
|
-
title: favorite.title,
|
|
1407
|
-
description: favorite.description,
|
|
1408
|
-
tags: [...favorite.tags],
|
|
1409
|
-
category: favorite.category,
|
|
1410
|
-
contract: createPromptContract(modeKey, {
|
|
1411
|
-
variables: reproducibility.variables
|
|
1412
|
-
}),
|
|
1413
|
-
currentVersionId: versionId,
|
|
1414
|
-
versions: [
|
|
1415
|
-
{
|
|
1416
|
-
id: versionId,
|
|
1417
|
-
version: 1,
|
|
1418
|
-
title: favorite.title,
|
|
1419
|
-
content: promptContentFromText(favorite.content, modeKey),
|
|
1420
|
-
createdAt: favorite.createdAt,
|
|
1421
|
-
updatedAt: favorite.updatedAt,
|
|
1422
|
-
source: { kind: "favorite", id: favorite.id },
|
|
1423
|
-
metadata: Object.keys(contentMetadata).length > 0 ? contentMetadata : void 0
|
|
1424
|
-
}
|
|
1425
|
-
],
|
|
1426
|
-
examples: reproducibility.examples,
|
|
1427
|
-
source: { kind: sourceKind, id: favorite.id },
|
|
1428
|
-
createdAt: favorite.createdAt,
|
|
1429
|
-
updatedAt: favorite.updatedAt
|
|
1430
|
-
};
|
|
1431
|
-
};
|
|
1432
|
-
var refreshPromptAssetFromFavorite = (favorite, options = {}) => {
|
|
1433
|
-
const metadata = isPlainObject(favorite.metadata) ? favorite.metadata : void 0;
|
|
1434
|
-
const embeddedAsset = isPromptAsset(metadata?.promptAsset) ? metadata.promptAsset : null;
|
|
1435
|
-
const metadataForProjection = metadata ? { ...metadata } : {};
|
|
1436
|
-
delete metadataForProjection.promptAsset;
|
|
1437
|
-
const projected = promptAssetFromFavorite(
|
|
1438
|
-
{
|
|
1439
|
-
...favorite,
|
|
1440
|
-
metadata: metadataForProjection
|
|
1441
|
-
},
|
|
1442
|
-
{
|
|
1443
|
-
...options,
|
|
1444
|
-
ignoreEmbeddedAsset: true
|
|
1445
|
-
}
|
|
1446
|
-
);
|
|
1447
|
-
if (!embeddedAsset) {
|
|
1448
|
-
return projected;
|
|
1449
|
-
}
|
|
1450
|
-
const versions = clonePromptAssetVersions(embeddedAsset);
|
|
1451
|
-
const currentVersion = versions.find((version) => version.id === embeddedAsset.currentVersionId);
|
|
1452
|
-
const projectedVersion = projected.versions[0];
|
|
1453
|
-
let currentVersionId = embeddedAsset.currentVersionId;
|
|
1454
|
-
if (!currentVersion || !promptContentEquals(currentVersion.content, projectedVersion.content)) {
|
|
1455
|
-
const versionNumber = nextContentVersionNumber(versions);
|
|
1456
|
-
const nextVersion = {
|
|
1457
|
-
...projectedVersion,
|
|
1458
|
-
id: createContentVersionId(favorite, versionNumber),
|
|
1459
|
-
version: versionNumber,
|
|
1460
|
-
createdAt: favorite.updatedAt,
|
|
1461
|
-
updatedAt: favorite.updatedAt,
|
|
1462
|
-
content: clonePromptContent(projectedVersion.content),
|
|
1463
|
-
source: clonePromptSource(projectedVersion.source),
|
|
1464
|
-
metadata: projectedVersion.metadata ? { ...projectedVersion.metadata } : void 0
|
|
1465
|
-
};
|
|
1466
|
-
versions.push(nextVersion);
|
|
1467
|
-
currentVersionId = nextVersion.id;
|
|
1468
|
-
}
|
|
1469
|
-
const shouldUseProjectedReproducibility = hasReproducibilitySource(metadataForProjection);
|
|
1470
|
-
const contract = shouldUseProjectedReproducibility ? projected.contract : createPromptContract(projected.contract.modeKey, {
|
|
1471
|
-
variables: embeddedAsset.contract.variables
|
|
1472
|
-
});
|
|
1473
|
-
return {
|
|
1474
|
-
...projected,
|
|
1475
|
-
id: embeddedAsset.id,
|
|
1476
|
-
contract,
|
|
1477
|
-
currentVersionId,
|
|
1478
|
-
versions,
|
|
1479
|
-
examples: shouldUseProjectedReproducibility ? rebaseDefaultExampleVersionIds(projected.examples, projectedVersion.id, currentVersionId) : clonePromptExamples(embeddedAsset.examples),
|
|
1480
|
-
createdAt: embeddedAsset.createdAt,
|
|
1481
|
-
updatedAt: favorite.updatedAt,
|
|
1482
|
-
metadata: embeddedAsset.metadata ? { ...embeddedAsset.metadata } : void 0
|
|
1483
|
-
};
|
|
1484
|
-
};
|
|
1485
|
-
var ModelError = class extends Error {
|
|
1486
|
-
constructor(code, message, params) {
|
|
1487
|
-
super(message ? `[${code}] ${message}` : `[${code}]`);
|
|
1488
|
-
__publicField(this, "code");
|
|
1489
|
-
__publicField(this, "params");
|
|
1490
|
-
this.name = "ModelError";
|
|
1491
|
-
this.code = code;
|
|
1492
|
-
this.params = params ?? (message ? { details: message } : void 0);
|
|
1493
|
-
}
|
|
1494
|
-
};
|
|
1495
|
-
async function convertLegacyToTextModelConfigWithRegistry(key, legacy, registry) {
|
|
1496
|
-
let providerId;
|
|
1497
|
-
switch (legacy.provider) {
|
|
1498
|
-
case "gemini":
|
|
1499
|
-
providerId = "gemini";
|
|
1500
|
-
break;
|
|
1501
|
-
case "anthropic":
|
|
1502
|
-
providerId = "anthropic";
|
|
1503
|
-
break;
|
|
1504
|
-
case "deepseek":
|
|
1505
|
-
providerId = "deepseek";
|
|
1506
|
-
break;
|
|
1507
|
-
case "siliconflow":
|
|
1508
|
-
providerId = "siliconflow";
|
|
1509
|
-
break;
|
|
1510
|
-
case "zhipu":
|
|
1511
|
-
providerId = "zhipu";
|
|
1512
|
-
break;
|
|
1513
|
-
case "openai":
|
|
1514
|
-
providerId = "openai";
|
|
1515
|
-
break;
|
|
1516
|
-
case "grok":
|
|
1517
|
-
providerId = "grok";
|
|
1518
|
-
break;
|
|
1519
|
-
case "custom":
|
|
1520
|
-
providerId = "openai-compatible";
|
|
1521
|
-
break;
|
|
1522
|
-
default:
|
|
1523
|
-
providerId = "openai";
|
|
1524
|
-
break;
|
|
1525
|
-
}
|
|
1526
|
-
try {
|
|
1527
|
-
const adapter = registry.getAdapter(providerId);
|
|
1528
|
-
const providerMeta = adapter.getProvider();
|
|
1529
|
-
let modelMeta;
|
|
1530
|
-
const staticModels = adapter.getModels();
|
|
1531
|
-
modelMeta = staticModels.find((m) => m.id === legacy.defaultModel);
|
|
1532
|
-
if (!modelMeta) {
|
|
1533
|
-
console.warn(`[Converter] Model ${legacy.defaultModel} not found in static models, building default`);
|
|
1534
|
-
modelMeta = adapter.buildDefaultModel(legacy.defaultModel);
|
|
1535
|
-
}
|
|
1536
|
-
const schema = modelMeta.parameterDefinitions ?? [];
|
|
1537
|
-
const legacyParams = legacy.llmParams || {};
|
|
1538
|
-
const { builtIn, custom } = splitOverridesBySchema(schema, legacyParams);
|
|
1539
|
-
const textModelConfig = {
|
|
1540
|
-
id: key,
|
|
1541
|
-
name: legacy.name,
|
|
1542
|
-
enabled: legacy.enabled,
|
|
1543
|
-
providerId,
|
|
1544
|
-
modelId: modelMeta.id,
|
|
1545
|
-
providerMeta,
|
|
1546
|
-
modelMeta,
|
|
1547
|
-
connectionConfig: {
|
|
1548
|
-
apiKey: legacy.apiKey,
|
|
1549
|
-
baseURL: legacy.baseURL,
|
|
1550
|
-
requestStyle: providerId === "openai-compatible" ? "chat_completions" : void 0
|
|
1551
|
-
},
|
|
1552
|
-
paramOverrides: builtIn,
|
|
1553
|
-
customParamOverrides: custom
|
|
1554
|
-
};
|
|
1555
|
-
return textModelConfig;
|
|
1556
|
-
} catch (error) {
|
|
1557
|
-
console.error(`[Converter] Failed to convert legacy config for ${key}:`, error);
|
|
1558
|
-
try {
|
|
1559
|
-
const openaiAdapter = registry.getAdapter("openai");
|
|
1560
|
-
const providerMeta = openaiAdapter.getProvider();
|
|
1561
|
-
const modelMeta = openaiAdapter.buildDefaultModel(legacy.defaultModel);
|
|
1562
|
-
return {
|
|
1563
|
-
id: key,
|
|
1564
|
-
name: legacy.name,
|
|
1565
|
-
enabled: false,
|
|
1566
|
-
// 转换失败,禁用配置
|
|
1567
|
-
providerId: providerMeta.id,
|
|
1568
|
-
modelId: modelMeta.id,
|
|
1569
|
-
providerMeta,
|
|
1570
|
-
modelMeta,
|
|
1571
|
-
connectionConfig: {
|
|
1572
|
-
apiKey: legacy.apiKey,
|
|
1573
|
-
baseURL: legacy.baseURL
|
|
1574
|
-
},
|
|
1575
|
-
paramOverrides: legacy.llmParams || {}
|
|
1576
|
-
};
|
|
1577
|
-
} catch (fallbackError) {
|
|
1578
|
-
console.error(`[Converter] Fallback to OpenAI also failed for ${key}:`, fallbackError);
|
|
1579
|
-
const details = error instanceof Error ? error.message : String(error);
|
|
1580
|
-
throw new ModelError(MODEL_ERROR_CODES.CONFIG_ERROR, `Failed to convert config ${key}: ${details}`);
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
|
-
function convertLegacyToTextModelConfig(key, legacy) {
|
|
1585
|
-
let providerId;
|
|
1586
|
-
switch (legacy.provider) {
|
|
1587
|
-
case "gemini":
|
|
1588
|
-
providerId = "gemini";
|
|
1589
|
-
break;
|
|
1590
|
-
case "anthropic":
|
|
1591
|
-
providerId = "anthropic";
|
|
1592
|
-
break;
|
|
1593
|
-
case "deepseek":
|
|
1594
|
-
providerId = "deepseek";
|
|
1595
|
-
break;
|
|
1596
|
-
case "siliconflow":
|
|
1597
|
-
providerId = "siliconflow";
|
|
1598
|
-
break;
|
|
1599
|
-
case "zhipu":
|
|
1600
|
-
providerId = "zhipu";
|
|
1601
|
-
break;
|
|
1602
|
-
case "openai":
|
|
1603
|
-
providerId = "openai";
|
|
1604
|
-
break;
|
|
1605
|
-
case "grok":
|
|
1606
|
-
providerId = "grok";
|
|
1607
|
-
break;
|
|
1608
|
-
case "custom":
|
|
1609
|
-
providerId = "openai-compatible";
|
|
1610
|
-
break;
|
|
1611
|
-
default:
|
|
1612
|
-
providerId = "openai";
|
|
1613
|
-
break;
|
|
1614
|
-
}
|
|
1615
|
-
const providerMeta = createProviderMeta(providerId, legacy);
|
|
1616
|
-
const modelMeta = createModelMeta(legacy.defaultModel, providerId, legacy);
|
|
1617
|
-
const schema = modelMeta.parameterDefinitions ?? [];
|
|
1618
|
-
const legacyParams = legacy.llmParams || {};
|
|
1619
|
-
const { builtIn, custom } = splitOverridesBySchema(schema, legacyParams);
|
|
1620
|
-
const textModelConfig = {
|
|
1621
|
-
id: key,
|
|
1622
|
-
name: legacy.name,
|
|
1623
|
-
enabled: legacy.enabled,
|
|
1624
|
-
providerId,
|
|
1625
|
-
modelId: modelMeta.id,
|
|
1626
|
-
providerMeta,
|
|
1627
|
-
modelMeta,
|
|
1628
|
-
connectionConfig: {
|
|
1629
|
-
apiKey: legacy.apiKey,
|
|
1630
|
-
baseURL: legacy.baseURL,
|
|
1631
|
-
requestStyle: providerId === "openai-compatible" ? "chat_completions" : void 0
|
|
1632
|
-
},
|
|
1633
|
-
paramOverrides: builtIn,
|
|
1634
|
-
customParamOverrides: custom
|
|
1635
|
-
};
|
|
1636
|
-
return textModelConfig;
|
|
1637
|
-
}
|
|
1638
|
-
function createProviderMeta(providerId, legacy) {
|
|
1639
|
-
if (providerId === "gemini") {
|
|
1640
|
-
return {
|
|
1641
|
-
id: "gemini",
|
|
1642
|
-
name: "Google Gemini",
|
|
1643
|
-
description: "Google Generative AI models",
|
|
1644
|
-
requiresApiKey: true,
|
|
1645
|
-
defaultBaseURL: "https://generativelanguage.googleapis.com",
|
|
1646
|
-
supportsDynamicModels: false,
|
|
1647
|
-
connectionSchema: {
|
|
1648
|
-
required: ["apiKey"],
|
|
1649
|
-
optional: ["baseURL", "timeout"],
|
|
1650
|
-
fieldTypes: {
|
|
1651
|
-
apiKey: "string",
|
|
1652
|
-
baseURL: "string",
|
|
1653
|
-
timeout: "number"
|
|
1654
|
-
}
|
|
1655
|
-
}
|
|
1656
|
-
};
|
|
1657
|
-
} else if (providerId === "deepseek") {
|
|
1658
|
-
return {
|
|
1659
|
-
id: "deepseek",
|
|
1660
|
-
name: "DeepSeek",
|
|
1661
|
-
description: "DeepSeek OpenAI-compatible models",
|
|
1662
|
-
requiresApiKey: true,
|
|
1663
|
-
defaultBaseURL: legacy.baseURL || "https://api.deepseek.com",
|
|
1664
|
-
supportsDynamicModels: true,
|
|
1665
|
-
connectionSchema: {
|
|
1666
|
-
required: ["apiKey"],
|
|
1667
|
-
optional: ["baseURL", "timeout"],
|
|
1668
|
-
fieldTypes: {
|
|
1669
|
-
apiKey: "string",
|
|
1670
|
-
baseURL: "string",
|
|
1671
|
-
timeout: "number"
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
};
|
|
1675
|
-
} else if (providerId === "siliconflow") {
|
|
1676
|
-
return {
|
|
1677
|
-
id: "siliconflow",
|
|
1678
|
-
name: "SiliconFlow",
|
|
1679
|
-
description: "SiliconFlow OpenAI-compatible models",
|
|
1680
|
-
requiresApiKey: true,
|
|
1681
|
-
defaultBaseURL: legacy.baseURL || "https://api.siliconflow.cn/v1",
|
|
1682
|
-
supportsDynamicModels: true,
|
|
1683
|
-
connectionSchema: {
|
|
1684
|
-
required: ["apiKey"],
|
|
1685
|
-
optional: ["baseURL", "timeout"],
|
|
1686
|
-
fieldTypes: {
|
|
1687
|
-
apiKey: "string",
|
|
1688
|
-
baseURL: "string",
|
|
1689
|
-
timeout: "number"
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
};
|
|
1693
|
-
} else if (providerId === "zhipu") {
|
|
1694
|
-
return {
|
|
1695
|
-
id: "zhipu",
|
|
1696
|
-
name: "Zhipu AI",
|
|
1697
|
-
description: "Zhipu GLM OpenAI-compatible models",
|
|
1698
|
-
requiresApiKey: true,
|
|
1699
|
-
defaultBaseURL: legacy.baseURL || "https://open.bigmodel.cn/api/paas/v4",
|
|
1700
|
-
supportsDynamicModels: false,
|
|
1701
|
-
connectionSchema: {
|
|
1702
|
-
required: ["apiKey"],
|
|
1703
|
-
optional: ["baseURL", "timeout"],
|
|
1704
|
-
fieldTypes: {
|
|
1705
|
-
apiKey: "string",
|
|
1706
|
-
baseURL: "string",
|
|
1707
|
-
timeout: "number"
|
|
1708
|
-
}
|
|
1709
|
-
}
|
|
1710
|
-
};
|
|
1711
|
-
} else if (providerId === "anthropic") {
|
|
1712
|
-
return {
|
|
1713
|
-
id: "anthropic",
|
|
1714
|
-
name: "Anthropic",
|
|
1715
|
-
description: "Anthropic Claude models",
|
|
1716
|
-
requiresApiKey: true,
|
|
1717
|
-
defaultBaseURL: "https://api.anthropic.com/v1",
|
|
1718
|
-
supportsDynamicModels: false,
|
|
1719
|
-
connectionSchema: {
|
|
1720
|
-
required: ["apiKey"],
|
|
1721
|
-
optional: ["baseURL", "timeout"],
|
|
1722
|
-
fieldTypes: {
|
|
1723
|
-
apiKey: "string",
|
|
1724
|
-
baseURL: "string",
|
|
1725
|
-
timeout: "number"
|
|
1726
|
-
}
|
|
1727
|
-
}
|
|
1728
|
-
};
|
|
1729
|
-
} else if (providerId === "grok") {
|
|
1730
|
-
return {
|
|
1731
|
-
id: "grok",
|
|
1732
|
-
name: "Grok",
|
|
1733
|
-
description: "xAI Grok models via OpenAI-compatible API",
|
|
1734
|
-
requiresApiKey: true,
|
|
1735
|
-
defaultBaseURL: legacy.baseURL || "https://api.x.ai/v1",
|
|
1736
|
-
supportsDynamicModels: true,
|
|
1737
|
-
connectionSchema: {
|
|
1738
|
-
required: ["apiKey"],
|
|
1739
|
-
optional: ["baseURL", "timeout"],
|
|
1740
|
-
fieldTypes: {
|
|
1741
|
-
apiKey: "string",
|
|
1742
|
-
baseURL: "string",
|
|
1743
|
-
timeout: "number"
|
|
1744
|
-
}
|
|
1745
|
-
}
|
|
1746
|
-
};
|
|
1747
|
-
} else if (providerId === "openai-compatible") {
|
|
1748
|
-
return {
|
|
1749
|
-
id: "openai-compatible",
|
|
1750
|
-
name: "OpenAI Compatible (Custom)",
|
|
1751
|
-
description: "Custom endpoints that implement OpenAI Chat Completions or Responses APIs",
|
|
1752
|
-
requiresApiKey: false,
|
|
1753
|
-
defaultBaseURL: legacy.baseURL || "http://localhost:11434/v1",
|
|
1754
|
-
supportsDynamicModels: true,
|
|
1755
|
-
connectionSchema: {
|
|
1756
|
-
required: [],
|
|
1757
|
-
optional: ["baseURL", "apiKey", "requestStyle", "timeout"],
|
|
1758
|
-
fieldTypes: {
|
|
1759
|
-
apiKey: "string",
|
|
1760
|
-
baseURL: "string",
|
|
1761
|
-
requestStyle: "string",
|
|
1762
|
-
timeout: "number"
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
};
|
|
1766
|
-
} else {
|
|
1767
|
-
return {
|
|
1768
|
-
id: "openai",
|
|
1769
|
-
name: "OpenAI",
|
|
1770
|
-
description: "Official OpenAI API for GPT and reasoning models",
|
|
1771
|
-
requiresApiKey: true,
|
|
1772
|
-
defaultBaseURL: legacy.baseURL || "https://api.openai.com/v1",
|
|
1773
|
-
supportsDynamicModels: true,
|
|
1774
|
-
connectionSchema: {
|
|
1775
|
-
required: ["apiKey"],
|
|
1776
|
-
optional: ["baseURL", "organization", "requestStyle", "timeout"],
|
|
1777
|
-
fieldTypes: {
|
|
1778
|
-
apiKey: "string",
|
|
1779
|
-
baseURL: "string",
|
|
1780
|
-
organization: "string",
|
|
1781
|
-
requestStyle: "string",
|
|
1782
|
-
timeout: "number"
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
};
|
|
1786
|
-
}
|
|
1787
|
-
}
|
|
1788
|
-
function createModelMeta(modelId, providerId, legacy) {
|
|
1789
|
-
const defaultCapabilities = {
|
|
1790
|
-
supportsTools: providerId !== "gemini",
|
|
1791
|
-
// Gemini 工具支持可能不同
|
|
1792
|
-
supportsReasoning: modelId.includes("o1") || modelId.includes("reasoner") || modelId.includes("thinking"),
|
|
1793
|
-
maxContextLength: 4096
|
|
1794
|
-
};
|
|
1795
|
-
if (modelId.includes("gpt-4o")) {
|
|
1796
|
-
defaultCapabilities.maxContextLength = 128e3;
|
|
1797
|
-
} else if (modelId.includes("gemini")) {
|
|
1798
|
-
defaultCapabilities.maxContextLength = 1e6;
|
|
1799
|
-
defaultCapabilities.supportsTools = true;
|
|
1800
|
-
} else if (modelId.includes("claude")) {
|
|
1801
|
-
defaultCapabilities.maxContextLength = 2e5;
|
|
1802
|
-
} else if (modelId.includes("deepseek")) {
|
|
1803
|
-
defaultCapabilities.maxContextLength = 64e3;
|
|
1804
|
-
} else if (modelId.includes("grok")) {
|
|
1805
|
-
defaultCapabilities.maxContextLength = 1e6;
|
|
1806
|
-
defaultCapabilities.supportsTools = true;
|
|
1807
|
-
defaultCapabilities.supportsReasoning = true;
|
|
1808
|
-
}
|
|
1809
|
-
if (providerId === "siliconflow") {
|
|
1810
|
-
defaultCapabilities.supportsTools = false;
|
|
1811
|
-
defaultCapabilities.maxContextLength = 8192;
|
|
1812
|
-
} else if (providerId === "zhipu") {
|
|
1813
|
-
defaultCapabilities.maxContextLength = 128e3;
|
|
1814
|
-
}
|
|
1815
|
-
if (modelId.includes("glm-4-air")) {
|
|
1816
|
-
defaultCapabilities.supportsTools = false;
|
|
1817
|
-
}
|
|
1818
|
-
const parameterDefinitions = createParameterDefinitions(providerId);
|
|
1819
|
-
return {
|
|
1820
|
-
id: modelId,
|
|
1821
|
-
name: modelId,
|
|
1822
|
-
description: `Model ${modelId} from ${legacy.name}`,
|
|
1823
|
-
providerId,
|
|
1824
|
-
capabilities: defaultCapabilities,
|
|
1825
|
-
parameterDefinitions,
|
|
1826
|
-
defaultParameterValues: legacy.llmParams || {}
|
|
1827
|
-
};
|
|
1828
|
-
}
|
|
1829
|
-
function createParameterDefinitions(providerId) {
|
|
1830
|
-
if (providerId === "gemini") {
|
|
1831
|
-
return [
|
|
1832
|
-
{
|
|
1833
|
-
name: "temperature",
|
|
1834
|
-
labelKey: "params.temperature.label",
|
|
1835
|
-
descriptionKey: "params.temperature.description",
|
|
1836
|
-
type: "number",
|
|
1837
|
-
defaultValue: 1,
|
|
1838
|
-
minValue: 0,
|
|
1839
|
-
maxValue: 2,
|
|
1840
|
-
step: 0.1
|
|
1841
|
-
},
|
|
1842
|
-
{
|
|
1843
|
-
name: "maxOutputTokens",
|
|
1844
|
-
labelKey: "params.maxOutputTokens.label",
|
|
1845
|
-
descriptionKey: "params.maxOutputTokens.description",
|
|
1846
|
-
type: "integer",
|
|
1847
|
-
defaultValue: 8192,
|
|
1848
|
-
minValue: 1,
|
|
1849
|
-
unitKey: "params.tokens.unit",
|
|
1850
|
-
step: 1
|
|
1851
|
-
}
|
|
1852
|
-
];
|
|
1853
|
-
} else {
|
|
1854
|
-
return [
|
|
1855
|
-
{
|
|
1856
|
-
name: "temperature",
|
|
1857
|
-
labelKey: "params.temperature.label",
|
|
1858
|
-
descriptionKey: "params.temperature.description",
|
|
1859
|
-
type: "number",
|
|
1860
|
-
defaultValue: 1,
|
|
1861
|
-
minValue: 0,
|
|
1862
|
-
maxValue: 2,
|
|
1863
|
-
step: 0.1
|
|
1864
|
-
},
|
|
1865
|
-
{
|
|
1866
|
-
name: "max_tokens",
|
|
1867
|
-
labelKey: "params.max_tokens.label",
|
|
1868
|
-
descriptionKey: "params.max_tokens.description",
|
|
1869
|
-
type: "integer",
|
|
1870
|
-
minValue: 1,
|
|
1871
|
-
unitKey: "params.tokens.unit",
|
|
1872
|
-
step: 1
|
|
1873
|
-
}
|
|
1874
|
-
];
|
|
1875
|
-
}
|
|
1876
|
-
}
|
|
1877
|
-
function isLegacyConfig(config) {
|
|
1878
|
-
return config && typeof config === "object" && "provider" in config && "baseURL" in config && "defaultModel" in config && !("providerMeta" in config) && !("modelMeta" in config);
|
|
1879
|
-
}
|
|
1880
|
-
function isTextModelConfig(config) {
|
|
1881
|
-
return config && typeof config === "object" && "providerMeta" in config && "modelMeta" in config && "connectionConfig" in config;
|
|
1882
|
-
}
|
|
1883
|
-
var AssetReadError = class extends Error {
|
|
1884
|
-
constructor(code) {
|
|
1885
|
-
super(`Read-only asset access failed (${code}).`);
|
|
1886
|
-
__publicField(this, "code");
|
|
1887
|
-
this.name = "AssetReadError";
|
|
1888
|
-
this.code = code;
|
|
1889
|
-
}
|
|
1890
|
-
};
|
|
1891
|
-
var record = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
1892
|
-
var text = (v) => typeof v === "string" && v.trim().length > 0;
|
|
1893
|
-
var strings = (v) => Array.isArray(v) && v.every((item) => typeof item === "string");
|
|
1894
|
-
var time = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0;
|
|
1895
|
-
var requireData = (condition) => {
|
|
1896
|
-
if (!condition) throw new AssetReadError("SOURCE_DATA_INVALID");
|
|
1897
|
-
};
|
|
1898
|
-
var noUnversionedEnvelope = (v) => {
|
|
1899
|
-
if (record(v) && Object.prototype.hasOwnProperty.call(v, "schemaVersion")) throw new AssetReadError("SCHEMA_UNSUPPORTED");
|
|
1900
|
-
};
|
|
1901
|
-
function parseModels(value) {
|
|
1902
|
-
noUnversionedEnvelope(value);
|
|
1903
|
-
requireData(record(value));
|
|
1904
|
-
return Object.keys(value).sort().map((configKey) => {
|
|
1905
|
-
const raw = value[configKey];
|
|
1906
|
-
requireData(text(configKey) && record(raw));
|
|
1907
|
-
noUnversionedEnvelope(raw);
|
|
1908
|
-
requireData(text(raw.name) && typeof raw.enabled === "boolean");
|
|
1909
|
-
if (isTextModelConfig(raw)) {
|
|
1910
|
-
requireData(record(raw.providerMeta) && record(raw.modelMeta) && record(raw.connectionConfig));
|
|
1911
|
-
requireData(text(raw.providerMeta.id) && text(raw.modelMeta.id) && text(raw.modelMeta.providerId));
|
|
1912
|
-
requireData((raw.providerId === void 0 || text(raw.providerId)) && (raw.modelId === void 0 || text(raw.modelId)));
|
|
1913
|
-
const identity = getTextModelConfigIdentity(raw);
|
|
1914
|
-
requireData(identity);
|
|
1915
|
-
const aligned = identity.providerId === raw.providerMeta.id && identity.providerId === raw.modelMeta.providerId && identity.modelId === raw.modelMeta.id;
|
|
1916
|
-
const caps = raw.modelMeta.capabilities;
|
|
1917
|
-
requireData(record(caps) && typeof caps.supportsTools === "boolean");
|
|
1918
|
-
requireData(caps.supportsReasoning === void 0 || typeof caps.supportsReasoning === "boolean");
|
|
1919
|
-
requireData(caps.maxContextLength === void 0 || time(caps.maxContextLength) && caps.maxContextLength > 0);
|
|
1920
|
-
const capabilities = aligned ? {
|
|
1921
|
-
supportsTools: caps.supportsTools,
|
|
1922
|
-
...caps.supportsReasoning !== void 0 ? { supportsReasoning: caps.supportsReasoning } : {},
|
|
1923
|
-
...caps.maxContextLength !== void 0 ? { maxContextLength: caps.maxContextLength } : {}
|
|
1924
|
-
} : {};
|
|
1925
|
-
return { raw, model: {
|
|
1926
|
-
configKey,
|
|
1927
|
-
name: raw.name,
|
|
1928
|
-
enabled: raw.enabled,
|
|
1929
|
-
...identity,
|
|
1930
|
-
capabilities,
|
|
1931
|
-
executable: false,
|
|
1932
|
-
unavailableReason: !raw.enabled ? "MODEL_DISABLED" : aligned ? "EXECUTION_NOT_CONNECTED" : "MODEL_METADATA_MISMATCH"
|
|
1933
|
-
} };
|
|
1934
|
-
}
|
|
1935
|
-
requireData(isLegacyConfig(raw) && text(raw.provider) && text(raw.defaultModel) && typeof raw.baseURL === "string");
|
|
1936
|
-
return { raw, model: {
|
|
1937
|
-
configKey,
|
|
1938
|
-
name: raw.name,
|
|
1939
|
-
enabled: raw.enabled,
|
|
1940
|
-
providerId: raw.provider === "custom" ? "openai-compatible" : raw.provider,
|
|
1941
|
-
modelId: raw.defaultModel,
|
|
1942
|
-
capabilities: {},
|
|
1943
|
-
executable: false,
|
|
1944
|
-
unavailableReason: "MODEL_REQUIRES_MIGRATION"
|
|
1945
|
-
} };
|
|
1946
|
-
});
|
|
1947
|
-
}
|
|
1948
|
-
function validateContent(value) {
|
|
1949
|
-
requireData(record(value));
|
|
1950
|
-
switch (value.kind) {
|
|
1951
|
-
case "text":
|
|
1952
|
-
case "image-prompt":
|
|
1953
|
-
requireData(typeof value.text === "string");
|
|
1954
|
-
break;
|
|
1955
|
-
case "messages":
|
|
1956
|
-
requireData(Array.isArray(value.messages) && value.messages.every((message) => record(message) && typeof message.role === "string" && ["system", "user", "assistant", "tool"].includes(message.role) && typeof message.content === "string"));
|
|
1957
|
-
break;
|
|
1958
|
-
default:
|
|
1959
|
-
throw new AssetReadError("SCHEMA_UNSUPPORTED");
|
|
1960
|
-
}
|
|
1961
|
-
}
|
|
1962
|
-
function validateAsset(value) {
|
|
1963
|
-
requireData(record(value));
|
|
1964
|
-
if (value.schemaVersion !== PROMPT_MODEL_SCHEMA_VERSION) throw new AssetReadError("SCHEMA_UNSUPPORTED");
|
|
1965
|
-
requireData(isPromptAsset(value) && strings(value.tags) && Array.isArray(value.contract.variables));
|
|
1966
|
-
const contract = createPromptContract(value.contract.modeKey);
|
|
1967
|
-
requireData(value.contract.family === contract.family && (!("subMode" in contract) || "subMode" in value.contract && value.contract.subMode === contract.subMode));
|
|
1968
|
-
const variableNames = /* @__PURE__ */ new Set();
|
|
1969
|
-
for (const variable of value.contract.variables) {
|
|
1970
|
-
requireData(record(variable) && text(variable.name) && typeof variable.required === "boolean" && !variableNames.has(variable.name));
|
|
1971
|
-
requireData(variable.type === void 0 || ["string", "number", "boolean", "enum"].includes(variable.type));
|
|
1972
|
-
requireData(variable.options === void 0 || strings(variable.options));
|
|
1973
|
-
requireData(variable.defaultValue === void 0 || typeof variable.defaultValue === "string");
|
|
1974
|
-
variableNames.add(variable.name);
|
|
1975
|
-
}
|
|
1976
|
-
const ids = /* @__PURE__ */ new Set();
|
|
1977
|
-
for (const version of value.versions) {
|
|
1978
|
-
requireData(record(version) && text(version.id) && Number.isSafeInteger(version.version) && version.version > 0 && time(version.createdAt) && !ids.has(version.id));
|
|
1979
|
-
validateContent(version.content);
|
|
1980
|
-
ids.add(version.id);
|
|
1981
|
-
}
|
|
1982
|
-
requireData(ids.size > 0 && ids.has(value.currentVersionId) && time(value.createdAt) && time(value.updatedAt));
|
|
1983
|
-
}
|
|
1984
|
-
function parseFavorites(value) {
|
|
1985
|
-
noUnversionedEnvelope(value);
|
|
1986
|
-
requireData(Array.isArray(value));
|
|
1987
|
-
const ids = /* @__PURE__ */ new Set();
|
|
1988
|
-
return value.map((raw) => {
|
|
1989
|
-
requireData(record(raw));
|
|
1990
|
-
noUnversionedEnvelope(raw);
|
|
1991
|
-
requireData(text(raw.id) && text(raw.title) && typeof raw.content === "string" && strings(raw.tags) && time(raw.createdAt) && time(raw.updatedAt) && !ids.has(raw.id));
|
|
1992
|
-
requireData(raw.metadata === void 0 || record(raw.metadata));
|
|
1993
|
-
requireData(raw.functionMode === void 0 || typeof raw.functionMode === "string");
|
|
1994
|
-
if (raw.functionMode !== void 0 && !["basic", "context", "image"].includes(raw.functionMode)) throw new AssetReadError("SCHEMA_UNSUPPORTED");
|
|
1995
|
-
requireData(raw.optimizationMode === void 0 || typeof raw.optimizationMode === "string" && ["system", "user"].includes(raw.optimizationMode));
|
|
1996
|
-
requireData(raw.imageSubMode === void 0 || typeof raw.imageSubMode === "string" && ["text2image", "image2image", "multiimage"].includes(raw.imageSubMode));
|
|
1997
|
-
if (record(raw.metadata) && Object.prototype.hasOwnProperty.call(raw.metadata, "promptAsset")) validateAsset(raw.metadata.promptAsset);
|
|
1998
|
-
const asset = promptAssetFromFavorite(raw);
|
|
1999
|
-
validateAsset(asset);
|
|
2000
|
-
requireData(isPromptModeKey(asset.contract.modeKey));
|
|
2001
|
-
ids.add(raw.id);
|
|
2002
|
-
return { raw, favoriteId: raw.id, asset };
|
|
2003
|
-
}).sort((a, b) => a.favoriteId < b.favoriteId ? -1 : a.favoriteId > b.favoriteId ? 1 : 0);
|
|
2004
|
-
}
|
|
2005
|
-
var hex = (bytes) => Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
2006
|
-
var hashText = (value) => hex(sha256(new TextEncoder().encode(value)));
|
|
2007
|
-
var signText = (key, value) => hex(hmac(sha256, key, new TextEncoder().encode(value)));
|
|
2008
|
-
var canonical = (v) => Array.isArray(v) ? `[${v.map(canonical).join(",")}]` : v !== null && typeof v === "object" ? `{${Object.keys(v).sort().map((k) => `${JSON.stringify(k)}:${canonical(v[k])}`).join(",")}}` : JSON.stringify(v);
|
|
2009
|
-
function createReadonlyAssetReader(storage, source, options) {
|
|
2010
|
-
return createAssetReadAccess(storage, source, options).reader;
|
|
2011
|
-
}
|
|
2012
|
-
function createAssetReadAccess(storage, source, options) {
|
|
2013
|
-
if (!text(source.sourceId) || !text(source.sourceEpoch)) throw new AssetReadError("INVALID_INPUT");
|
|
2014
|
-
const scope = Object.freeze({ sourceId: source.sourceId, sourceEpoch: source.sourceEpoch });
|
|
2015
|
-
const getItem = storage.getItem.bind(storage);
|
|
2016
|
-
let revisionKey = options?.revisionKey;
|
|
2017
|
-
let portableKey;
|
|
2018
|
-
async function revision(kind, snapshot) {
|
|
2019
|
-
try {
|
|
2020
|
-
if (!globalThis.crypto.subtle) {
|
|
2021
|
-
portableKey ?? (portableKey = globalThis.crypto.getRandomValues(new Uint8Array(32)));
|
|
2022
|
-
return `read-v1:${signText(portableKey, canonical([scope, kind, snapshot]))}`;
|
|
2023
|
-
}
|
|
2024
|
-
revisionKey ?? (revisionKey = globalThis.crypto.subtle.generateKey({ name: "HMAC", hash: "SHA-256" }, false, ["sign"]));
|
|
2025
|
-
const signature = await globalThis.crypto.subtle.sign(
|
|
2026
|
-
"HMAC",
|
|
2027
|
-
await revisionKey,
|
|
2028
|
-
new TextEncoder().encode(canonical([scope, kind, snapshot]))
|
|
2029
|
-
);
|
|
2030
|
-
return `read-v1:${Array.from(new Uint8Array(signature), (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
2031
|
-
} catch {
|
|
2032
|
-
throw new AssetReadError("REVISION_UNAVAILABLE");
|
|
2033
|
-
}
|
|
2034
|
-
}
|
|
2035
|
-
async function read(key) {
|
|
2036
|
-
let raw;
|
|
2037
|
-
try {
|
|
2038
|
-
raw = await getItem(key);
|
|
2039
|
-
} catch {
|
|
2040
|
-
throw new AssetReadError("SOURCE_READ_FAILED");
|
|
2041
|
-
}
|
|
2042
|
-
if (raw === null) throw new AssetReadError("SOURCE_DATA_MISSING");
|
|
2043
|
-
try {
|
|
2044
|
-
return JSON.parse(raw, (_key, value) => {
|
|
2045
|
-
if (typeof value === "number" && !Number.isFinite(value)) throw new Error();
|
|
2046
|
-
return value;
|
|
2047
|
-
});
|
|
2048
|
-
} catch {
|
|
2049
|
-
throw new AssetReadError("SOURCE_DATA_INVALID");
|
|
2050
|
-
}
|
|
2051
|
-
}
|
|
2052
|
-
async function page(items, options2, signature) {
|
|
2053
|
-
const limit = options2.limit ?? 20;
|
|
2054
|
-
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100) throw new AssetReadError("INVALID_INPUT");
|
|
2055
|
-
let offset = 0;
|
|
2056
|
-
if (options2.cursor !== void 0) {
|
|
2057
|
-
if (typeof options2.cursor !== "string") throw new AssetReadError("INVALID_CURSOR");
|
|
2058
|
-
const match = /^(0|[1-9]\d*)\.(read-v1:[a-f0-9]{64})$/.exec(options2.cursor);
|
|
2059
|
-
if (!match || match[2] !== signature) throw new AssetReadError("INVALID_CURSOR");
|
|
2060
|
-
offset = Number(match[1]);
|
|
2061
|
-
if (!Number.isSafeInteger(offset) || offset >= items.length) throw new AssetReadError("INVALID_CURSOR");
|
|
2062
|
-
}
|
|
2063
|
-
return {
|
|
2064
|
-
...scope,
|
|
2065
|
-
items: items.slice(offset, offset + limit),
|
|
2066
|
-
...offset + limit < items.length ? { nextCursor: `${offset + limit}.${signature}` } : {}
|
|
2067
|
-
};
|
|
2068
|
-
}
|
|
2069
|
-
function validatePagination(options2) {
|
|
2070
|
-
const limit = options2.limit ?? 20;
|
|
2071
|
-
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100) throw new AssetReadError("INVALID_INPUT");
|
|
2072
|
-
if (options2.cursor !== void 0 && (typeof options2.cursor !== "string" || !/^(0|[1-9]\d*)\.read-v1:[a-f0-9]{64}$/.test(options2.cursor))) throw new AssetReadError("INVALID_CURSOR");
|
|
2073
|
-
}
|
|
2074
|
-
async function readAsset(selection) {
|
|
2075
|
-
if (![selection.favoriteId, selection.assetId].every(text) || selection.expectedRevision !== void 0 && !text(selection.expectedRevision)) throw new AssetReadError("INVALID_INPUT");
|
|
2076
|
-
const entry = parseFavorites(await read("favorites")).find((item) => item.favoriteId === selection.favoriteId && item.asset.id === selection.assetId);
|
|
2077
|
-
if (!entry) throw new AssetReadError("ASSET_VERSION_NOT_FOUND");
|
|
2078
|
-
return entry;
|
|
2079
|
-
}
|
|
2080
|
-
async function assetDescription(favoriteId, raw, asset, expectedRevision) {
|
|
2081
|
-
const assetRevision = await revision(`favorite:${favoriteId}`, raw);
|
|
2082
|
-
if (expectedRevision !== void 0 && expectedRevision !== assetRevision) throw new AssetReadError("REVISION_CONFLICT");
|
|
2083
|
-
return {
|
|
2084
|
-
favoriteId,
|
|
2085
|
-
assetId: asset.id,
|
|
2086
|
-
title: asset.title,
|
|
2087
|
-
modeKey: asset.contract.modeKey,
|
|
2088
|
-
tags: [...asset.tags],
|
|
2089
|
-
currentVersionId: asset.currentVersionId,
|
|
2090
|
-
versionCount: asset.versions.length,
|
|
2091
|
-
updatedAt: asset.updatedAt,
|
|
2092
|
-
revision: assetRevision
|
|
2093
|
-
};
|
|
2094
|
-
}
|
|
2095
|
-
async function signedModel({ model, raw }) {
|
|
2096
|
-
const signed = { ...model, revision: await revision(`model:${model.configKey}`, raw) };
|
|
2097
|
-
return { model: signed, raw };
|
|
2098
|
-
}
|
|
2099
|
-
async function readStoredModels(configKeys) {
|
|
2100
|
-
const entries = parseModels(await read(CORE_SERVICE_KEYS.MODELS));
|
|
2101
|
-
return Promise.all(entries.filter(({ model }) => configKeys.includes(model.configKey)).map(signedModel));
|
|
2102
|
-
}
|
|
2103
|
-
async function listModels(options2, project) {
|
|
2104
|
-
validatePagination(options2);
|
|
2105
|
-
const snapshot = await read(CORE_SERVICE_KEYS.MODELS);
|
|
2106
|
-
const entries = await Promise.all(parseModels(snapshot).map(signedModel));
|
|
2107
|
-
return page(entries.map(project), options2, await revision("models-page", snapshot));
|
|
2108
|
-
}
|
|
2109
|
-
const reader = {
|
|
2110
|
-
listModels(options2 = {}) {
|
|
2111
|
-
return listModels(options2, ({ model }) => model);
|
|
2112
|
-
},
|
|
2113
|
-
async listAssets(options2 = {}) {
|
|
2114
|
-
validatePagination(options2);
|
|
2115
|
-
if (options2.modeKey !== void 0 && !isPromptModeKey(options2.modeKey)) throw new AssetReadError("INVALID_INPUT");
|
|
2116
|
-
if (options2.query !== void 0 && typeof options2.query !== "string") throw new AssetReadError("INVALID_INPUT");
|
|
2117
|
-
const raw = await read("favorites");
|
|
2118
|
-
const query = (options2.query ?? "").trim().toLowerCase();
|
|
2119
|
-
const assets = parseFavorites(raw).filter(({ asset }) => (!options2.modeKey || options2.modeKey === asset.contract.modeKey) && (!query || [asset.title, ...asset.tags].some((value) => value.toLowerCase().includes(query))));
|
|
2120
|
-
const items = await Promise.all(assets.map(({ favoriteId, raw: raw2, asset }) => assetDescription(favoriteId, raw2, asset)));
|
|
2121
|
-
return page(items, options2, await revision("favorites-page", [raw, options2.modeKey ?? null, query]));
|
|
2122
|
-
},
|
|
2123
|
-
async listAssetVersions(selection, options2 = {}) {
|
|
2124
|
-
validatePagination(options2);
|
|
2125
|
-
const { favoriteId, raw, asset } = await readAsset(selection);
|
|
2126
|
-
const description = await assetDescription(favoriteId, raw, asset, selection.expectedRevision);
|
|
2127
|
-
const versions = asset.versions.map(({ id, version, createdAt }) => ({ versionId: id, version, createdAt })).sort((a, b) => b.version - a.version || b.createdAt - a.createdAt);
|
|
2128
|
-
return {
|
|
2129
|
-
...await page(versions, options2, description.revision),
|
|
2130
|
-
favoriteId,
|
|
2131
|
-
assetId: description.assetId,
|
|
2132
|
-
currentVersionId: description.currentVersionId,
|
|
2133
|
-
versionCount: description.versionCount,
|
|
2134
|
-
revision: description.revision
|
|
2135
|
-
};
|
|
2136
|
-
},
|
|
2137
|
-
async getAssetVersion(selection) {
|
|
2138
|
-
if (!text(selection.versionId)) throw new AssetReadError("INVALID_INPUT");
|
|
2139
|
-
const entry = await readAsset(selection);
|
|
2140
|
-
const version = entry.asset.versions.find((item) => item.id === selection.versionId);
|
|
2141
|
-
if (!version) throw new AssetReadError("ASSET_VERSION_NOT_FOUND");
|
|
2142
|
-
const description = await assetDescription(entry.favoriteId, entry.raw, entry.asset, selection.expectedRevision);
|
|
2143
|
-
if (version.content.kind !== "text") throw new AssetReadError("ASSET_CONTENT_UNSUPPORTED");
|
|
2144
|
-
return {
|
|
2145
|
-
...scope,
|
|
2146
|
-
...description,
|
|
2147
|
-
versionId: version.id,
|
|
2148
|
-
version: version.version,
|
|
2149
|
-
content: { kind: "text", text: version.content.text },
|
|
2150
|
-
variables: entry.asset.contract.variables.map((variable) => ({
|
|
2151
|
-
name: variable.name,
|
|
2152
|
-
required: variable.required,
|
|
2153
|
-
...variable.type !== void 0 ? { type: variable.type } : {},
|
|
2154
|
-
...variable.options !== void 0 ? { options: [...variable.options] } : {}
|
|
2155
|
-
}))
|
|
2156
|
-
};
|
|
2157
|
-
}
|
|
2158
|
-
};
|
|
2159
|
-
return { reader, readStoredModels, listModels };
|
|
2160
|
-
}
|
|
2161
|
-
|
|
2162
|
-
export {
|
|
2163
|
-
CORE_SERVICE_KEYS,
|
|
2164
|
-
UI_SETTINGS_KEYS,
|
|
2165
|
-
TEMPLATE_SELECTION_KEYS,
|
|
2166
|
-
IMAGE_MODE_KEYS,
|
|
2167
|
-
FUNCTION_MODEL_KEYS,
|
|
2168
|
-
getModeModelKey,
|
|
2169
|
-
ALL_STORAGE_KEYS,
|
|
2170
|
-
ALL_STORAGE_KEYS_ARRAY,
|
|
2171
|
-
PROMPT_MODE_KEYS,
|
|
2172
|
-
isPromptModeKey,
|
|
2173
|
-
resolvePromptModeKey,
|
|
2174
|
-
promptModeKeyToFavoriteMode,
|
|
2175
|
-
createPromptContract,
|
|
2176
|
-
getTextModelConfigIdentity,
|
|
2177
|
-
resolveTextModelMetadata,
|
|
2178
|
-
hasTextModelMetadataIdentityMismatch,
|
|
2179
|
-
hasExplicitTextModelIdentity,
|
|
2180
|
-
resolveTextModelParameterDefinitions,
|
|
2181
|
-
DANGEROUS_PARAM_KEY_PATTERNS,
|
|
2182
|
-
isValueEmpty,
|
|
2183
|
-
normalizeDefaultValue,
|
|
2184
|
-
isSafeCustomKey,
|
|
2185
|
-
parseCustomValue,
|
|
2186
|
-
splitOverridesBySchema,
|
|
2187
|
-
mergeOverrides,
|
|
2188
|
-
validateOverrides,
|
|
2189
|
-
PROMPT_MODEL_SCHEMA_VERSION,
|
|
2190
|
-
promptContentFromText,
|
|
2191
|
-
isPromptAsset,
|
|
2192
|
-
promptContentToFavoriteContent,
|
|
2193
|
-
switchPromptAssetCurrentVersion,
|
|
2194
|
-
deletePromptAssetVersion,
|
|
2195
|
-
promptAssetFromFavorite,
|
|
2196
|
-
refreshPromptAssetFromFavorite,
|
|
2197
|
-
ModelError,
|
|
2198
|
-
convertLegacyToTextModelConfigWithRegistry,
|
|
2199
|
-
convertLegacyToTextModelConfig,
|
|
2200
|
-
isLegacyConfig,
|
|
2201
|
-
isTextModelConfig,
|
|
2202
|
-
AssetReadError,
|
|
2203
|
-
record,
|
|
2204
|
-
text,
|
|
2205
|
-
hashText,
|
|
2206
|
-
signText,
|
|
2207
|
-
createReadonlyAssetReader,
|
|
2208
|
-
createAssetReadAccess
|
|
2209
|
-
};
|