page-agent-sdk 2.15.0 → 2.16.0
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 +40 -6
- package/README.zh-CN.md +40 -6
- package/dist/page-agent-sdk.iife.js +125 -124
- package/dist/page-agent-sdk.js +647 -478
- package/dist/page-agent-sdk.umd.cjs +29 -29
- package/package.json +24 -4
- package/skills/page-agent-sdk-integrate/references/api.md +29 -0
- package/types/index.d.ts +4 -2
package/dist/page-agent-sdk.js
CHANGED
|
@@ -9,7 +9,7 @@ var c = Object.create, l = Object.defineProperty, u = Object.getOwnPropertyDescr
|
|
|
9
9
|
enumerable: !(r = u(t, s)) || r.enumerable
|
|
10
10
|
});
|
|
11
11
|
return e;
|
|
12
|
-
}, g = (e, t, n) => (n = e == null ? {} : c(f(e)), h(t || !e || !e.__esModule ? l(n, "default", {
|
|
12
|
+
}, g = (e, t, n) => (n = e == null ? {} : c(f(e)), h(t || !e || !e.__esModule || !p.call(e, "default") ? l(n, "default", {
|
|
13
13
|
value: e,
|
|
14
14
|
enumerable: !0
|
|
15
15
|
}) : n, e));
|
|
@@ -106,7 +106,8 @@ function Se(e) {
|
|
|
106
106
|
if (i) for (let e in i) t[e] = i[e];
|
|
107
107
|
}
|
|
108
108
|
return t;
|
|
109
|
-
}
|
|
109
|
+
}
|
|
110
|
+
if (P(e) || I(e)) return e;
|
|
110
111
|
}
|
|
111
112
|
var Ce = /;(?![^(]*\))/g, we = /:([^]+)/, Te = /\/\*[^]*?\*\//g;
|
|
112
113
|
function Ee(e) {
|
|
@@ -162,7 +163,7 @@ function Be(e, ...t) {
|
|
|
162
163
|
}
|
|
163
164
|
var Ve, He = class {
|
|
164
165
|
constructor(e = !1) {
|
|
165
|
-
this.detached = e, this._active = !0, this._on = 0, this.effects = [], this.cleanups = [], this._isPaused = !1, this._warnOnRun = !0, this.__v_skip = !0, !e && Ve && (Ve.active ? (this.parent = Ve, this.index = (Ve.scopes
|
|
166
|
+
this.detached = e, this._active = !0, this._on = 0, this.effects = [], this.cleanups = [], this._isPaused = !1, this._warnOnRun = !0, this.__v_skip = !0, !e && Ve && (Ve.active ? (this.parent = Ve, this.index = (Ve.scopes || (Ve.scopes = [])).push(this) - 1) : (this._active = !1, this._warnOnRun = !1));
|
|
166
167
|
}
|
|
167
168
|
get active() {
|
|
168
169
|
return this._active;
|
|
@@ -171,7 +172,10 @@ var Ve, He = class {
|
|
|
171
172
|
if (this._active) {
|
|
172
173
|
this._isPaused = !0;
|
|
173
174
|
let e, t;
|
|
174
|
-
if (this.scopes)
|
|
175
|
+
if (this.scopes) {
|
|
176
|
+
let n = this.scopes.slice();
|
|
177
|
+
for (e = 0, t = n.length; e < t; e++) n[e].pause();
|
|
178
|
+
}
|
|
175
179
|
for (e = 0, t = this.effects.length; e < t; e++) this.effects[e].pause();
|
|
176
180
|
}
|
|
177
181
|
}
|
|
@@ -179,8 +183,12 @@ var Ve, He = class {
|
|
|
179
183
|
if (this._active && this._isPaused) {
|
|
180
184
|
this._isPaused = !1;
|
|
181
185
|
let e, t;
|
|
182
|
-
if (this.scopes)
|
|
183
|
-
|
|
186
|
+
if (this.scopes) {
|
|
187
|
+
let n = this.scopes.slice();
|
|
188
|
+
for (e = 0, t = n.length; e < t; e++) n[e].resume();
|
|
189
|
+
}
|
|
190
|
+
let n = this.effects.slice();
|
|
191
|
+
for (e = 0, t = n.length; e < t; e++) n[e].resume();
|
|
184
192
|
}
|
|
185
193
|
}
|
|
186
194
|
run(e) {
|
|
@@ -191,7 +199,8 @@ var Ve, He = class {
|
|
|
191
199
|
} finally {
|
|
192
200
|
Ve = t;
|
|
193
201
|
}
|
|
194
|
-
}
|
|
202
|
+
}
|
|
203
|
+
process.env.NODE_ENV !== "production" && this._warnOnRun && Be("cannot run an inactive effect scope.");
|
|
195
204
|
}
|
|
196
205
|
on() {
|
|
197
206
|
++this._on === 1 && (this.prevScope = Ve, Ve = this);
|
|
@@ -219,7 +228,8 @@ var Ve, He = class {
|
|
|
219
228
|
for (t = 0, n = this.effects.length; t < n; t++) this.effects[t].stop();
|
|
220
229
|
for (this.effects.length = 0, t = 0, n = this.cleanups.length; t < n; t++) this.cleanups[t]();
|
|
221
230
|
if (this.cleanups.length = 0, this.scopes) {
|
|
222
|
-
|
|
231
|
+
let e = this.scopes.slice();
|
|
232
|
+
for (t = 0, n = e.length; t < n; t++) e[t].stop(!0);
|
|
223
233
|
this.scopes.length = 0;
|
|
224
234
|
}
|
|
225
235
|
if (!this.detached && this.parent && !e) {
|
|
@@ -455,9 +465,7 @@ function vt(e, t, n, r, i, a) {
|
|
|
455
465
|
case "delete":
|
|
456
466
|
i || (s(o.get(mt)), j(e) && s(o.get(ht)));
|
|
457
467
|
break;
|
|
458
|
-
case "set":
|
|
459
|
-
j(e) && s(o.get(mt));
|
|
460
|
-
break;
|
|
468
|
+
case "set": j(e) && s(o.get(mt));
|
|
461
469
|
}
|
|
462
470
|
}
|
|
463
471
|
Ze();
|
|
@@ -1119,7 +1127,8 @@ function Vn(e, t, n, r) {
|
|
|
1119
1127
|
let i = [];
|
|
1120
1128
|
for (let a = 0; a < e.length; a++) i.push(Vn(e[a], t, n, r));
|
|
1121
1129
|
return i;
|
|
1122
|
-
}
|
|
1130
|
+
}
|
|
1131
|
+
process.env.NODE_ENV !== "production" && G(`Invalid value type passed to callWithAsyncErrorHandling(): ${typeof e}`);
|
|
1123
1132
|
}
|
|
1124
1133
|
function Hn(e, t, n, r = !0) {
|
|
1125
1134
|
let i = t ? t.vnode : null, { errorHandler: a, throwUnhandledErrorInProduction: o } = t && t.appContext.config || b;
|
|
@@ -1248,7 +1257,7 @@ function pr(e) {
|
|
|
1248
1257
|
dr.get(e.type.__hmrId).instances.delete(e);
|
|
1249
1258
|
}
|
|
1250
1259
|
function mr(e, t) {
|
|
1251
|
-
return dr.has(e)
|
|
1260
|
+
return !dr.has(e) && (dr.set(e, {
|
|
1252
1261
|
initialDef: hr(t),
|
|
1253
1262
|
instances: /* @__PURE__ */ new Set()
|
|
1254
1263
|
}), !0);
|
|
@@ -1342,13 +1351,14 @@ function zr(e, t = Ir, n) {
|
|
|
1342
1351
|
if (!t || e._n) return e;
|
|
1343
1352
|
let r = (...n) => {
|
|
1344
1353
|
r._d && Ko(-1);
|
|
1345
|
-
let i = Rr(t), a;
|
|
1354
|
+
let i = Rr(t), a = Ho.length, o;
|
|
1346
1355
|
try {
|
|
1347
|
-
|
|
1356
|
+
o = e(...n);
|
|
1348
1357
|
} finally {
|
|
1358
|
+
for (let e = Ho.length; e > a; e--) Wo();
|
|
1349
1359
|
Rr(i), r._d && Ko(1);
|
|
1350
1360
|
}
|
|
1351
|
-
return process.env.NODE_ENV !== "production" && Or(t),
|
|
1361
|
+
return process.env.NODE_ENV !== "production" && Or(t), o;
|
|
1352
1362
|
};
|
|
1353
1363
|
return r._n = !0, r._c = !0, r._d = !0, r;
|
|
1354
1364
|
}
|
|
@@ -1460,7 +1470,7 @@ var Zr = /* @__PURE__ */ new WeakMap(), Qr = /* @__PURE__ */ Symbol("_vte"), $r
|
|
|
1460
1470
|
let r = t(n);
|
|
1461
1471
|
return process.env.NODE_ENV !== "production" && !r && !ei(e) && G(`Failed to locate Teleport target with selector "${n}". Note the target element must exist before the component is mounted - i.e. the target cannot be rendered by the component itself, and ideally should be outside of the entire Vue component tree.`), r;
|
|
1462
1472
|
} else return process.env.NODE_ENV !== "production" && G("Current renderer does not support string target for Teleports. (missing querySelector renderer option)"), null;
|
|
1463
|
-
|
|
1473
|
+
return process.env.NODE_ENV !== "production" && !n && !ei(e) && G(`Invalid Teleport target: ${n}`), n;
|
|
1464
1474
|
}, ai = {
|
|
1465
1475
|
name: "Teleport",
|
|
1466
1476
|
__isTeleport: !0,
|
|
@@ -1756,14 +1766,8 @@ function ji(e, t, n, r, i = !1) {
|
|
|
1756
1766
|
m(l, e.k) && (l.value = null), e.k && (u[e.k] = null);
|
|
1757
1767
|
}
|
|
1758
1768
|
}
|
|
1759
|
-
if (N(c))
|
|
1760
|
-
|
|
1761
|
-
try {
|
|
1762
|
-
Bn(c, s, 12, [o, u]);
|
|
1763
|
-
} finally {
|
|
1764
|
-
st();
|
|
1765
|
-
}
|
|
1766
|
-
} else {
|
|
1769
|
+
if (N(c)) Bn(c, s, 12, [o, u]);
|
|
1770
|
+
else {
|
|
1767
1771
|
let t = P(c), r = /* @__PURE__ */ mn(c);
|
|
1768
1772
|
if (t || r) {
|
|
1769
1773
|
let s = () => {
|
|
@@ -1827,7 +1831,8 @@ function zi(e, t, n = hs, r = !1) {
|
|
|
1827
1831
|
return i(), st(), a;
|
|
1828
1832
|
};
|
|
1829
1833
|
return r ? i.unshift(a) : i.push(a), a;
|
|
1830
|
-
}
|
|
1834
|
+
}
|
|
1835
|
+
process.env.NODE_ENV !== "production" && G(`${me(zn[e].replace(/ hook$/, ""))} is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup(). If you are using async setup(), make sure to register lifecycle hooks before the first await statement.`);
|
|
1831
1836
|
}
|
|
1832
1837
|
var Bi = (e) => (t, n = hs) => {
|
|
1833
1838
|
(!ws || e === "sp") && zi(e, (...e) => t(...e), n);
|
|
@@ -2387,7 +2392,7 @@ function Ja(e, t, n, r = !1) {
|
|
|
2387
2392
|
let i = {}, a = Ka();
|
|
2388
2393
|
e.propsDefaults = /* @__PURE__ */ Object.create(null), Za(e, t, i, a);
|
|
2389
2394
|
for (let t in e.propsOptions[0]) t in i || (i[t] = void 0);
|
|
2390
|
-
process.env.NODE_ENV !== "production" && ro(t || {}, i, e),
|
|
2395
|
+
process.env.NODE_ENV !== "production" && ro(t || {}, i, e), e.props = n ? r ? i : /* @__PURE__ */ nn(i) : e.type.props ? i : a, e.attrs = a;
|
|
2391
2396
|
}
|
|
2392
2397
|
function Ya(e) {
|
|
2393
2398
|
for (; e;) {
|
|
@@ -2486,7 +2491,8 @@ function eo(e, t, n = !1) {
|
|
|
2486
2491
|
if (n === "Boolean") {
|
|
2487
2492
|
c = !0;
|
|
2488
2493
|
break;
|
|
2489
|
-
}
|
|
2494
|
+
}
|
|
2495
|
+
n === "String" && (l = !1);
|
|
2490
2496
|
}
|
|
2491
2497
|
else c = N(i) && i.name === "Boolean";
|
|
2492
2498
|
r[0] = c, r[1] = l, (c || k(r, "default")) && s.push(t);
|
|
@@ -2497,7 +2503,7 @@ function eo(e, t, n = !1) {
|
|
|
2497
2503
|
return I(e) && r.set(e, l), l;
|
|
2498
2504
|
}
|
|
2499
2505
|
function to(e) {
|
|
2500
|
-
return e[0] !== "$" && !se(e)
|
|
2506
|
+
return e[0] !== "$" && !se(e) || (process.env.NODE_ENV !== "production" && G(`Invalid prop name: "${e}" is a reserved property.`), !1);
|
|
2501
2507
|
}
|
|
2502
2508
|
function no(e) {
|
|
2503
2509
|
return e === null ? "null" : typeof e == "function" ? e.name || "" : typeof e == "object" && e.constructor && e.constructor.name || "";
|
|
@@ -2828,7 +2834,8 @@ function Oo(e, t) {
|
|
|
2828
2834
|
if (p & 128) {
|
|
2829
2835
|
re(l, f, n, r, i, a, o, s, c);
|
|
2830
2836
|
return;
|
|
2831
|
-
}
|
|
2837
|
+
}
|
|
2838
|
+
if (p & 256) {
|
|
2832
2839
|
ne(l, f, n, r, i, a, o, s, c);
|
|
2833
2840
|
return;
|
|
2834
2841
|
}
|
|
@@ -3293,7 +3300,7 @@ function ms(e, t, n) {
|
|
|
3293
3300
|
ec: null,
|
|
3294
3301
|
sp: null
|
|
3295
3302
|
};
|
|
3296
|
-
return process.env.NODE_ENV === "production" ?
|
|
3303
|
+
return a.ctx = process.env.NODE_ENV === "production" ? { _: a } : ia(a), a.root = t ? t.root : a, a.emit = ka.bind(null, a), e.ce && e.ce(a), a;
|
|
3297
3304
|
}
|
|
3298
3305
|
var hs = null, gs = () => hs || Ir, _s, vs;
|
|
3299
3306
|
{
|
|
@@ -3426,7 +3433,8 @@ function Ps(e) {
|
|
|
3426
3433
|
},
|
|
3427
3434
|
expose: t
|
|
3428
3435
|
});
|
|
3429
|
-
}
|
|
3436
|
+
}
|
|
3437
|
+
return {
|
|
3430
3438
|
attrs: new Proxy(e.attrs, Ms),
|
|
3431
3439
|
slots: e.slots,
|
|
3432
3440
|
emit: e.emit,
|
|
@@ -3508,7 +3516,8 @@ function Us() {
|
|
|
3508
3516
|
s(n),
|
|
3509
3517
|
">"
|
|
3510
3518
|
];
|
|
3511
|
-
}
|
|
3519
|
+
}
|
|
3520
|
+
return /* @__PURE__ */ sn(t) ? [
|
|
3512
3521
|
"div",
|
|
3513
3522
|
{},
|
|
3514
3523
|
[
|
|
@@ -3519,8 +3528,7 @@ function Us() {
|
|
|
3519
3528
|
"<",
|
|
3520
3529
|
s(t),
|
|
3521
3530
|
`>${/* @__PURE__ */ cn(t) ? " (readonly)" : ""}`
|
|
3522
|
-
]
|
|
3523
|
-
else if (/* @__PURE__ */ cn(t)) return [
|
|
3531
|
+
] : /* @__PURE__ */ cn(t) ? [
|
|
3524
3532
|
"div",
|
|
3525
3533
|
{},
|
|
3526
3534
|
[
|
|
@@ -3531,8 +3539,7 @@ function Us() {
|
|
|
3531
3539
|
"<",
|
|
3532
3540
|
s(t),
|
|
3533
3541
|
">"
|
|
3534
|
-
];
|
|
3535
|
-
return null;
|
|
3542
|
+
] : null;
|
|
3536
3543
|
},
|
|
3537
3544
|
hasBody(e) {
|
|
3538
3545
|
return e && e.__isVue;
|
|
@@ -3622,7 +3629,7 @@ function Us() {
|
|
|
3622
3629
|
}
|
|
3623
3630
|
window.devtoolsFormatters ? window.devtoolsFormatters.push(i) : window.devtoolsFormatters = [i];
|
|
3624
3631
|
}
|
|
3625
|
-
var Ws = "3.5.
|
|
3632
|
+
var Ws = "3.5.40", Gs = process.env.NODE_ENV === "production" ? S : G;
|
|
3626
3633
|
process.env.NODE_ENV, process.env.NODE_ENV;
|
|
3627
3634
|
//#endregion
|
|
3628
3635
|
//#region node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js
|
|
@@ -4212,13 +4219,11 @@ function Cl(e = {}) {
|
|
|
4212
4219
|
}
|
|
4213
4220
|
break;
|
|
4214
4221
|
}
|
|
4215
|
-
case "approval_request":
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
};
|
|
4221
|
-
break;
|
|
4222
|
+
case "approval_request": l.value = {
|
|
4223
|
+
toolName: e.toolName,
|
|
4224
|
+
args: e.args,
|
|
4225
|
+
resolve: e.resolve
|
|
4226
|
+
};
|
|
4222
4227
|
}
|
|
4223
4228
|
f();
|
|
4224
4229
|
}, e);
|
|
@@ -4409,7 +4414,7 @@ var Al = ((e = "") => {
|
|
|
4409
4414
|
headingBeginRegex: kl((e) => RegExp(`^ {0,${e}}#`)),
|
|
4410
4415
|
htmlBeginRegex: kl((e) => RegExp(`^ {0,${e}}<(?:[a-z].*>|!--)`, "i")),
|
|
4411
4416
|
blockquoteBeginRegex: kl((e) => RegExp(`^ {0,${e}}>`))
|
|
4412
|
-
}, Ml = /^(?:[ \t]*(?:\n|$))+/, Nl = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/, Pl = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/, Fl = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/, Il = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/, Ll = / {0,3}(?:[*+-]|\d{1,9}[.)])/, Rl = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/, zl = Z(Rl).replace(/bull/g, Ll).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/\|table/g, "").getRegex(), Bl = Z(Rl).replace(/bull/g, Ll).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(), Vl = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/, Hl = /^[^\n]+/, Ul = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/, Wl = Z(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", Ul).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(), Gl = Z(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g, Ll).getRegex(), Kl = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul", ql = /<!--(?:-?>|[\s\S]*?(?:-->|$))/, Jl = Z("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n
|
|
4417
|
+
}, Ml = /^(?:[ \t]*(?:\n|$))+/, Nl = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/, Pl = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/, Fl = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/, Il = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/, Ll = / {0,3}(?:[*+-]|\d{1,9}[.)])/, Rl = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/, zl = Z(Rl).replace(/bull/g, Ll).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}(?:\s|$)/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/\|table/g, "").getRegex(), Bl = Z(Rl).replace(/bull/g, Ll).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}(?:\s|$)/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(), Vl = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/, Hl = /^[^\n]+/, Ul = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/, Wl = Z(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", Ul).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(), Gl = Z(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g, Ll).getRegex(), Kl = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul", ql = /<!--(?:-?>|[\s\S]*?(?:-->|$))/, Jl = Z("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))", "i").replace("comment", ql).replace("tag", Kl).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(), Yl = (e) => Z(Vl).replace("hr", Fl).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~~~)[^\\n]*\\n").replace("list", e).replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", Kl).getRegex(), Xl = Yl(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/), Zl = Yl(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/), Ql = {
|
|
4413
4418
|
blockquote: Z(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", Zl).getRegex(),
|
|
4414
4419
|
code: Nl,
|
|
4415
4420
|
def: Wl,
|
|
@@ -4423,11 +4428,11 @@ var Al = ((e = "") => {
|
|
|
4423
4428
|
paragraph: Xl,
|
|
4424
4429
|
table: Ol,
|
|
4425
4430
|
text: Hl
|
|
4426
|
-
}, $l = Z("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", Fl).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("blockquote", " {0,3}>").replace("code", "(?: {4}| {0,3} )[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)
|
|
4431
|
+
}, $l = Z("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", Fl).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("blockquote", " {0,3}>").replace("code", "(?: {4}| {0,3} )[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~~~)[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", Kl).getRegex(), eu = {
|
|
4427
4432
|
...Ql,
|
|
4428
4433
|
lheading: Bl,
|
|
4429
4434
|
table: $l,
|
|
4430
|
-
paragraph: Z(Vl).replace("hr", Fl).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", $l).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)
|
|
4435
|
+
paragraph: Z(Vl).replace("hr", Fl).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", $l).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~~~)[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", Kl).getRegex()
|
|
4431
4436
|
}, tu = {
|
|
4432
4437
|
...Ql,
|
|
4433
4438
|
html: Z("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment", ql).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),
|
|
@@ -4471,7 +4476,7 @@ var Al = ((e = "") => {
|
|
|
4471
4476
|
url: Z(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol", Mu).replace("email", /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),
|
|
4472
4477
|
_backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
|
|
4473
4478
|
del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,
|
|
4474
|
-
text: Z(/^([
|
|
4479
|
+
text: Z(/^(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol", Mu).getRegex()
|
|
4475
4480
|
}, Iu = {
|
|
4476
4481
|
...Fu,
|
|
4477
4482
|
br: Z(iu).replace("{2,}", "*").getRegex(),
|
|
@@ -4658,7 +4663,8 @@ ${c}` : c;
|
|
|
4658
4663
|
let t = u, a = t.raw + "\n" + e.join("\n"), o = this.blockquote(a);
|
|
4659
4664
|
i[i.length - 1] = o, n = n.substring(0, n.length - t.raw.length) + o.raw, r = r.substring(0, r.length - t.text.length) + o.text;
|
|
4660
4665
|
break;
|
|
4661
|
-
}
|
|
4666
|
+
}
|
|
4667
|
+
if (u?.type === "list") {
|
|
4662
4668
|
let t = u, a = t.raw + "\n" + e.join("\n"), o = this.list(a);
|
|
4663
4669
|
i[i.length - 1] = o, n = n.substring(0, n.length - u.raw.length) + o.raw, r = r.substring(0, r.length - t.raw.length) + o.raw, e = a.substring(i.at(-1).raw.length).split("\n");
|
|
4664
4670
|
continue;
|
|
@@ -4909,7 +4915,8 @@ ${c}` : c;
|
|
|
4909
4915
|
if (a = [...i].length, r[3] || r[4]) {
|
|
4910
4916
|
o += a;
|
|
4911
4917
|
continue;
|
|
4912
|
-
}
|
|
4918
|
+
}
|
|
4919
|
+
if ((r[5] || r[6]) && n % 3 && !((n + a) % 3)) {
|
|
4913
4920
|
s += a;
|
|
4914
4921
|
continue;
|
|
4915
4922
|
}
|
|
@@ -5046,7 +5053,7 @@ ${c}` : c;
|
|
|
5046
5053
|
block: Lu.normal,
|
|
5047
5054
|
inline: Ru.normal
|
|
5048
5055
|
};
|
|
5049
|
-
this.options.pedantic ? (t.block = Lu.pedantic, t.inline = Ru.pedantic) : this.options.gfm && (t.block = Lu.gfm, this.options.breaks ?
|
|
5056
|
+
this.options.pedantic ? (t.block = Lu.pedantic, t.inline = Ru.pedantic) : this.options.gfm && (t.block = Lu.gfm, t.inline = this.options.breaks ? Ru.breaks : Ru.gfm), this.tokenizer.rules = t;
|
|
5050
5057
|
}
|
|
5051
5058
|
static get rules() {
|
|
5052
5059
|
return {
|
|
@@ -5165,78 +5172,78 @@ ${c}` : c;
|
|
|
5165
5172
|
}
|
|
5166
5173
|
inlineTokens(e, t = []) {
|
|
5167
5174
|
this.tokenizer.lexer = this;
|
|
5168
|
-
let n = e
|
|
5175
|
+
let n = e;
|
|
5169
5176
|
if (this.tokens.links) {
|
|
5170
5177
|
let e = Object.keys(this.tokens.links);
|
|
5171
|
-
|
|
5178
|
+
e.length > 0 && (n = n.replace(this.tokenizer.rules.inline.reflinkSearch, (t) => e.includes(t.slice(t.lastIndexOf("[") + 1, -1)) ? "[" + "a".repeat(t.length - 2) + "]" : t));
|
|
5172
5179
|
}
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
|
|
5177
|
-
let
|
|
5180
|
+
n = n.replace(this.tokenizer.rules.inline.anyPunctuation, "++"), n = n.replace(this.tokenizer.rules.inline.blockSkip, (e, t, n) => {
|
|
5181
|
+
let r = n ? n.length : 0;
|
|
5182
|
+
return e.slice(0, r) + "[" + "a".repeat(e.length - r - 2) + "]";
|
|
5183
|
+
}), n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
|
|
5184
|
+
let r = !1, i = "", a = Infinity;
|
|
5178
5185
|
for (; e;) {
|
|
5179
|
-
if (e.length <
|
|
5186
|
+
if (e.length < a) a = e.length;
|
|
5180
5187
|
else {
|
|
5181
5188
|
this.infiniteLoopError(e.charCodeAt(0));
|
|
5182
5189
|
break;
|
|
5183
5190
|
}
|
|
5184
|
-
|
|
5185
|
-
let
|
|
5186
|
-
if (this.options.extensions?.inline?.some((n) => (
|
|
5187
|
-
if (
|
|
5188
|
-
e = e.substring(
|
|
5191
|
+
r || (i = ""), r = !1;
|
|
5192
|
+
let o;
|
|
5193
|
+
if (this.options.extensions?.inline?.some((n) => (o = n.call({ lexer: this }, e, t)) ? (e = e.substring(o.raw.length), t.push(o), !0) : !1)) continue;
|
|
5194
|
+
if (o = this.tokenizer.escape(e)) {
|
|
5195
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
5189
5196
|
continue;
|
|
5190
5197
|
}
|
|
5191
|
-
if (
|
|
5192
|
-
e = e.substring(
|
|
5198
|
+
if (o = this.tokenizer.tag(e)) {
|
|
5199
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
5193
5200
|
continue;
|
|
5194
5201
|
}
|
|
5195
|
-
if (
|
|
5196
|
-
e = e.substring(
|
|
5202
|
+
if (o = this.tokenizer.link(e)) {
|
|
5203
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
5197
5204
|
continue;
|
|
5198
5205
|
}
|
|
5199
|
-
if (
|
|
5200
|
-
e = e.substring(
|
|
5206
|
+
if (o = this.tokenizer.reflink(e, this.tokens.links)) {
|
|
5207
|
+
e = e.substring(o.raw.length);
|
|
5201
5208
|
let n = t.at(-1);
|
|
5202
|
-
|
|
5209
|
+
o.type === "text" && n?.type === "text" ? (n.raw += o.raw, n.text += o.text) : t.push(o);
|
|
5203
5210
|
continue;
|
|
5204
5211
|
}
|
|
5205
|
-
if (
|
|
5206
|
-
e = e.substring(
|
|
5212
|
+
if (o = this.tokenizer.emStrong(e, n, i)) {
|
|
5213
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
5207
5214
|
continue;
|
|
5208
5215
|
}
|
|
5209
|
-
if (
|
|
5210
|
-
e = e.substring(
|
|
5216
|
+
if (o = this.tokenizer.codespan(e)) {
|
|
5217
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
5211
5218
|
continue;
|
|
5212
5219
|
}
|
|
5213
|
-
if (
|
|
5214
|
-
e = e.substring(
|
|
5220
|
+
if (o = this.tokenizer.br(e)) {
|
|
5221
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
5215
5222
|
continue;
|
|
5216
5223
|
}
|
|
5217
|
-
if (
|
|
5218
|
-
e = e.substring(
|
|
5224
|
+
if (o = this.tokenizer.del(e, n, i)) {
|
|
5225
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
5219
5226
|
continue;
|
|
5220
5227
|
}
|
|
5221
|
-
if (
|
|
5222
|
-
e = e.substring(
|
|
5228
|
+
if (o = this.tokenizer.autolink(e)) {
|
|
5229
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
5223
5230
|
continue;
|
|
5224
5231
|
}
|
|
5225
|
-
if (!this.state.inLink && (
|
|
5226
|
-
e = e.substring(
|
|
5232
|
+
if (!this.state.inLink && (o = this.tokenizer.url(e))) {
|
|
5233
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
5227
5234
|
continue;
|
|
5228
5235
|
}
|
|
5229
|
-
let
|
|
5236
|
+
let s = e;
|
|
5230
5237
|
if (this.options.extensions?.startInline) {
|
|
5231
5238
|
let t = Infinity, n = e.slice(1), r;
|
|
5232
5239
|
this.options.extensions.startInline.forEach((e) => {
|
|
5233
5240
|
r = e.call({ lexer: this }, n), typeof r == "number" && r >= 0 && (t = Math.min(t, r));
|
|
5234
|
-
}), t < Infinity && t >= 0 && (
|
|
5241
|
+
}), t < Infinity && t >= 0 && (s = e.substring(0, t + 1));
|
|
5235
5242
|
}
|
|
5236
|
-
if (
|
|
5237
|
-
e = e.substring(
|
|
5243
|
+
if (o = this.tokenizer.inlineText(s)) {
|
|
5244
|
+
e = e.substring(o.raw.length), o.raw.slice(-1) !== "_" && (i = o.raw.slice(-1)), r = !0;
|
|
5238
5245
|
let n = t.at(-1);
|
|
5239
|
-
n?.type === "text" ? (n.raw +=
|
|
5246
|
+
n?.type === "text" ? (n.raw += o.raw, n.text += o.text) : t.push(o);
|
|
5240
5247
|
continue;
|
|
5241
5248
|
}
|
|
5242
5249
|
if (e) {
|
|
@@ -5671,14 +5678,14 @@ ${e}</tr>
|
|
|
5671
5678
|
if (!(n in t)) throw Error(`hook '${n}' does not exist`);
|
|
5672
5679
|
if (["options", "block"].includes(n)) continue;
|
|
5673
5680
|
let r = n, i = e.hooks[r], a = t[r];
|
|
5674
|
-
td.passThroughHooks.has(n) ?
|
|
5681
|
+
t[r] = td.passThroughHooks.has(n) ? (e) => {
|
|
5675
5682
|
if (this.defaults.async && td.passThroughHooksRespectAsync.has(n)) return (async () => {
|
|
5676
5683
|
let n = await i.call(t, e);
|
|
5677
5684
|
return a.call(t, n);
|
|
5678
5685
|
})();
|
|
5679
5686
|
let r = i.call(t, e);
|
|
5680
5687
|
return a.call(t, r);
|
|
5681
|
-
} :
|
|
5688
|
+
} : (...e) => {
|
|
5682
5689
|
if (this.defaults.async) return (async () => {
|
|
5683
5690
|
let n = await i.apply(t, e);
|
|
5684
5691
|
return n === !1 && (n = await a.apply(t, e)), n;
|
|
@@ -6381,7 +6388,8 @@ var rd = /* @__PURE__ */ m(((e, t) => {
|
|
|
6381
6388
|
if (r.type === "illegal" && !i) {
|
|
6382
6389
|
let e = /* @__PURE__ */ Error("Illegal lexeme \"" + a + "\" for mode \"" + (A.scope || "<unnamed>") + "\"");
|
|
6383
6390
|
throw e.mode = A, e;
|
|
6384
|
-
}
|
|
6391
|
+
}
|
|
6392
|
+
if (r.type === "end") {
|
|
6385
6393
|
let e = C(r);
|
|
6386
6394
|
if (e !== z) return e;
|
|
6387
6395
|
}
|
|
@@ -6527,7 +6535,7 @@ var rd = /* @__PURE__ */ m(((e, t) => {
|
|
|
6527
6535
|
else throw e;
|
|
6528
6536
|
i = c;
|
|
6529
6537
|
}
|
|
6530
|
-
i.name
|
|
6538
|
+
i.name || (i.name = n), t[n] = i, i.rawDefinition = r.bind(null, e), i.aliases && N(i.aliases, { languageName: n });
|
|
6531
6539
|
}
|
|
6532
6540
|
function j(e) {
|
|
6533
6541
|
delete t[e];
|
|
@@ -13928,20 +13936,34 @@ function xg(e) {
|
|
|
13928
13936
|
}
|
|
13929
13937
|
function Sg(e, t) {
|
|
13930
13938
|
let n = t.threshold ?? 6e3;
|
|
13931
|
-
if (e.length <= n) return e;
|
|
13939
|
+
if (e.length <= n) return { content: e };
|
|
13932
13940
|
if (t.vfsAvailable && t.files) {
|
|
13933
13941
|
let n = `large_results/${t.toolName}-${xg(e)}.txt`, r = bg(n);
|
|
13934
|
-
|
|
13942
|
+
t.files[r] = {
|
|
13935
13943
|
content: e,
|
|
13936
13944
|
updatedAt: Date.now()
|
|
13937
|
-
}
|
|
13938
|
-
|
|
13939
|
-
|
|
13940
|
-
|
|
13941
|
-
|
|
13945
|
+
};
|
|
13946
|
+
let i = e.slice(0, 1e3), a = e.length, o = a > 1e4 ? `结果较大(共 ${a} 字符),建议分页读取:vfs_read({ path: "${n}", offset: 0, limit: 100 }) 起步,按需 offset += 100 续读,或 vfs_grep({ pattern, path: "${n}" }) 局部检索` : void 0;
|
|
13947
|
+
return {
|
|
13948
|
+
offloaded: !0,
|
|
13949
|
+
content: [
|
|
13950
|
+
i,
|
|
13951
|
+
`…[结果过大(共 ${a} 字符),已转存到虚拟工作区:${n}]`,
|
|
13952
|
+
`需要完整或局部数据时:用 vfs_read({ path: "${n}", offset, limit }) 分页回读,或 vfs_grep({ pattern, path: "${n}" }) 局部检索。`,
|
|
13953
|
+
...o ? [o] : []
|
|
13954
|
+
].join("\n"),
|
|
13955
|
+
path: n,
|
|
13956
|
+
totalChars: a,
|
|
13957
|
+
preview: i,
|
|
13958
|
+
suggestedReadPlan: o
|
|
13959
|
+
};
|
|
13942
13960
|
}
|
|
13943
13961
|
let r = t.passThroughChars ?? n;
|
|
13944
|
-
return e.length <= r ?
|
|
13962
|
+
return e.length <= r ? { content: e } : {
|
|
13963
|
+
offloaded: !1,
|
|
13964
|
+
content: e.slice(0, r) + `\n…[结果过大(共 ${e.length} 字符),vfs 未启用无法外存,已截断,仅显示前 ${r} 字符。建议开启 vfs(capabilities.vfs 默认开启)以完整外存可回读]`,
|
|
13965
|
+
totalChars: e.length
|
|
13966
|
+
};
|
|
13945
13967
|
}
|
|
13946
13968
|
//#endregion
|
|
13947
13969
|
//#region src/core/utils/pool.ts
|
|
@@ -14346,7 +14368,7 @@ function Wg(e) {
|
|
|
14346
14368
|
toolName: e.name,
|
|
14347
14369
|
threshold: E,
|
|
14348
14370
|
passThroughChars: D
|
|
14349
|
-
}), {
|
|
14371
|
+
}).content, {
|
|
14350
14372
|
content: r,
|
|
14351
14373
|
status: "done"
|
|
14352
14374
|
};
|
|
@@ -15705,7 +15727,7 @@ function _v() {
|
|
|
15705
15727
|
}
|
|
15706
15728
|
//#endregion
|
|
15707
15729
|
//#region src/core/backends/storage.ts
|
|
15708
|
-
var vv = "chat-sdk", yv =
|
|
15730
|
+
var vv = "chat-sdk", yv = 52428800, bv = 4194304, xv = 10485760, Sv = .9, Cv = 500, wv = 300, Tv = "__meta__", Ev = "v:1", Dv = [
|
|
15709
15731
|
"messages",
|
|
15710
15732
|
"vfs",
|
|
15711
15733
|
"todos",
|
|
@@ -16119,9 +16141,26 @@ var Gv = {
|
|
|
16119
16141
|
recallTopK: 5,
|
|
16120
16142
|
enableRecall: !0,
|
|
16121
16143
|
enableLLMSummary: !0
|
|
16144
|
+
},
|
|
16145
|
+
complex: {
|
|
16146
|
+
summaryThresholdRatio: .7,
|
|
16147
|
+
windowRatio: .6,
|
|
16148
|
+
recallTopK: 5,
|
|
16149
|
+
enableRecall: !0,
|
|
16150
|
+
enableLLMSummary: !0
|
|
16122
16151
|
}
|
|
16152
|
+
}, Kv = {
|
|
16153
|
+
auto: ["describe_data", "read"],
|
|
16154
|
+
conservative: ["describe_data"],
|
|
16155
|
+
aggressive: ["describe_data", "read"],
|
|
16156
|
+
complex: [
|
|
16157
|
+
"describe_data",
|
|
16158
|
+
"read",
|
|
16159
|
+
"query_data",
|
|
16160
|
+
"search_data"
|
|
16161
|
+
]
|
|
16123
16162
|
};
|
|
16124
|
-
function
|
|
16163
|
+
function qv(e, t) {
|
|
16125
16164
|
let n = Gv[e.contextPreset ?? "auto"] ?? {}, r = e.contextOptions === !1 ? {} : e.contextOptions ?? {};
|
|
16126
16165
|
return {
|
|
16127
16166
|
...n,
|
|
@@ -16139,7 +16178,7 @@ function $(e) {
|
|
|
16139
16178
|
};
|
|
16140
16179
|
return e.path !== void 0 && (t.path = e.path), e.hint && (t.hint = e.hint), e.details !== void 0 && (t.details = e.details), `ERROR: ${JSON.stringify(t)}`;
|
|
16141
16180
|
}
|
|
16142
|
-
function
|
|
16181
|
+
function Jv(e) {
|
|
16143
16182
|
return e.slice(0, 10).map((e) => {
|
|
16144
16183
|
let t = e, n = {
|
|
16145
16184
|
path: (Array.isArray(t.path) ? t.path.join(".") : String(t.path ?? "")) || "(root)",
|
|
@@ -16148,16 +16187,16 @@ function qv(e) {
|
|
|
16148
16187
|
return t.expected !== void 0 && (n.expected = t.expected), t.received !== void 0 && (n.received = t.received), t.code !== void 0 && (n.code = t.code), n;
|
|
16149
16188
|
});
|
|
16150
16189
|
}
|
|
16151
|
-
function
|
|
16190
|
+
function Yv(e, t) {
|
|
16152
16191
|
return $({
|
|
16153
16192
|
code: "SCHEMA_INVALID",
|
|
16154
16193
|
path: e,
|
|
16155
16194
|
message: `值不符合 "${e}" 的 schema(${t.length} 处问题)`,
|
|
16156
16195
|
hint: `用 read({jsonPath:"${e}"}) 查看当前值,按 describe_data() 查看主数据 schema,修正后重试;改大对象优先用 write 的 patch 增量(只发改动部分)`,
|
|
16157
|
-
details:
|
|
16196
|
+
details: Jv(t)
|
|
16158
16197
|
});
|
|
16159
16198
|
}
|
|
16160
|
-
function
|
|
16199
|
+
function Xv(e, t, n) {
|
|
16161
16200
|
let r = n?.message || String(n);
|
|
16162
16201
|
return $({
|
|
16163
16202
|
code: "JSON_PARSE",
|
|
@@ -16166,62 +16205,218 @@ function Yv(e, t, n) {
|
|
|
16166
16205
|
hint: `检查引号/逗号/括号是否闭合;字符串值需双引号包裹(如 '"dark"' 表示字符串 dark,数字直接写如 5);预览前 80 字符:${t.slice(0, 80)}`
|
|
16167
16206
|
});
|
|
16168
16207
|
}
|
|
16169
|
-
|
|
16170
|
-
|
|
16208
|
+
//#endregion
|
|
16209
|
+
//#region src/core/tools/jsonUtils.ts
|
|
16210
|
+
var Zv = /* @__PURE__ */ new Set([
|
|
16211
|
+
"__proto__",
|
|
16212
|
+
"constructor",
|
|
16213
|
+
"prototype"
|
|
16214
|
+
]);
|
|
16215
|
+
function Qv(e) {
|
|
16216
|
+
return e.split(".").some((e) => Zv.has(e));
|
|
16217
|
+
}
|
|
16218
|
+
function $v(e, t) {
|
|
16219
|
+
if (!(!t || typeof t != "object" || Array.isArray(t))) for (let n of Object.keys(t)) Zv.has(n) || (e[n] = t[n]);
|
|
16220
|
+
}
|
|
16221
|
+
function ey(e, t) {
|
|
16222
|
+
if (!t) return e;
|
|
16223
|
+
if (Qv(t)) return;
|
|
16224
|
+
let n = t.split("."), r = e;
|
|
16225
|
+
for (let e of n) {
|
|
16226
|
+
if (r == null) return;
|
|
16227
|
+
r = r[e];
|
|
16228
|
+
}
|
|
16229
|
+
return r;
|
|
16230
|
+
}
|
|
16231
|
+
function ty(e, t, n) {
|
|
16232
|
+
if (!t || Qv(t)) return;
|
|
16233
|
+
let r = t.split("."), i = e;
|
|
16234
|
+
for (let e = 0; e < r.length - 1; e++) {
|
|
16235
|
+
let t = r[e];
|
|
16236
|
+
(i[t] == null || typeof i[t] != "object") && (i[t] = {}), i = i[t];
|
|
16237
|
+
}
|
|
16238
|
+
i[r[r.length - 1]] = n;
|
|
16239
|
+
}
|
|
16240
|
+
function ny(e, t) {
|
|
16241
|
+
if (!t || Qv(t)) return !1;
|
|
16242
|
+
let n = t.split("."), r = e;
|
|
16243
|
+
for (let e = 0; e < n.length - 1; e++) {
|
|
16244
|
+
if (r == null) return !1;
|
|
16245
|
+
r = r[n[e]];
|
|
16246
|
+
}
|
|
16247
|
+
let i = n[n.length - 1];
|
|
16248
|
+
return r == null || !(i in r) ? !1 : (Array.isArray(r) && /^\d+$/.test(i) ? r.splice(Number(i), 1) : delete r[i], !0);
|
|
16249
|
+
}
|
|
16250
|
+
function ry(e) {
|
|
16251
|
+
return e === void 0 ? void 0 : JSON.parse(JSON.stringify(e));
|
|
16252
|
+
}
|
|
16253
|
+
function iy(e) {
|
|
16254
|
+
if (typeof e != "string") return { parsed: e };
|
|
16255
|
+
let t = e.trim();
|
|
16256
|
+
if (!t) return { parsed: e };
|
|
16257
|
+
let n = t[0] === "{" || t[0] === "[";
|
|
16258
|
+
try {
|
|
16259
|
+
return { parsed: JSON.parse(t) };
|
|
16260
|
+
} catch (t) {
|
|
16261
|
+
return n ? { parseError: t } : { parsed: e };
|
|
16262
|
+
}
|
|
16263
|
+
}
|
|
16264
|
+
function ay(e, t) {
|
|
16265
|
+
if (typeof e != "object" || !e) return e;
|
|
16266
|
+
let n = new Set(t);
|
|
16267
|
+
if (Array.isArray(e)) return e.map((e) => ay(e, t));
|
|
16268
|
+
let r = {};
|
|
16269
|
+
for (let t of Object.keys(e)) n.has(t) && (r[t] = e[t]);
|
|
16270
|
+
return r;
|
|
16271
|
+
}
|
|
16272
|
+
function oy(e, t) {
|
|
16273
|
+
if (typeof e != "object" || !e) return e;
|
|
16274
|
+
if (t <= 0) return Array.isArray(e) ? `[...${e.length}]` : "{...}";
|
|
16275
|
+
if (Array.isArray(e)) return e.map((e) => oy(e, t - 1));
|
|
16276
|
+
let n = {};
|
|
16277
|
+
for (let r of Object.keys(e)) n[r] = oy(e[r], t - 1);
|
|
16278
|
+
return n;
|
|
16279
|
+
}
|
|
16280
|
+
function sy(e, t = Infinity) {
|
|
16281
|
+
let n = /* @__PURE__ */ new WeakSet(), r;
|
|
16282
|
+
try {
|
|
16283
|
+
r = JSON.stringify(e, (e, t) => {
|
|
16284
|
+
if (typeof t == "function") return "[Function]";
|
|
16285
|
+
if (typeof t == "bigint") return t.toString();
|
|
16286
|
+
if (typeof t == "object" && t) {
|
|
16287
|
+
if (typeof HTMLElement < "u" && t instanceof HTMLElement) return `[HTMLElement: <${t.tagName.toLowerCase()}>]`;
|
|
16288
|
+
if (typeof Node < "u" && t instanceof Node) return `[Node: type=${t.nodeType}]`;
|
|
16289
|
+
if (n.has(t)) return "[Circular]";
|
|
16290
|
+
n.add(t);
|
|
16291
|
+
}
|
|
16292
|
+
return t;
|
|
16293
|
+
}, 0);
|
|
16294
|
+
} catch (e) {
|
|
16295
|
+
r = `[无法序列化: ${e?.message || String(e)}]`;
|
|
16296
|
+
}
|
|
16297
|
+
return r.length > t && (r = r.slice(0, t) + `\n…[已截断,原长度 ${r.length}]`), r;
|
|
16298
|
+
}
|
|
16299
|
+
function cy(e) {
|
|
16300
|
+
let t = sy(e), n = 5381;
|
|
16301
|
+
for (let e = 0; e < t.length; e++) n = (n << 5) + n + t.charCodeAt(e) >>> 0;
|
|
16302
|
+
return n.toString(36);
|
|
16303
|
+
}
|
|
16304
|
+
function ly(e, t, n, r) {
|
|
16305
|
+
if (t === "set") return n ? (ty(e, n, r), null) : "set 操作需要 jsonPath(整体替换请用 set_data)";
|
|
16306
|
+
if (t === "remove") return n ? (ny(e, n), null) : "remove 操作需要 jsonPath";
|
|
16307
|
+
if (t === "merge") {
|
|
16308
|
+
let t = n ? ey(e, n) : e;
|
|
16309
|
+
return typeof t != "object" || !t || Array.isArray(t) ? `merge 目标${n ? `(${n})` : "(根)"}不是对象` : ($v(t, r), null);
|
|
16310
|
+
}
|
|
16311
|
+
let i = n ? ey(e, n) : e;
|
|
16312
|
+
return Array.isArray(i) ? (Array.isArray(r) ? i.push(...r) : i.push(r), null) : `append 目标${n ? `(${n})` : "(根)"}不是数组`;
|
|
16313
|
+
}
|
|
16314
|
+
function uy(e, t, n, r) {
|
|
16315
|
+
if (t === "set") ty(e, n, r);
|
|
16316
|
+
else if (t === "remove") ny(e, n);
|
|
16317
|
+
else if (t === "merge") $v(n ? ey(e, n) : e, r);
|
|
16318
|
+
else {
|
|
16319
|
+
let t = n ? ey(e, n) : e;
|
|
16320
|
+
Array.isArray(r) ? t.push(...r) : t.push(r);
|
|
16321
|
+
}
|
|
16322
|
+
}
|
|
16323
|
+
function dy(e, t) {
|
|
16324
|
+
typeof e == "object" && e && fy(e, t);
|
|
16325
|
+
}
|
|
16326
|
+
function fy(e, t) {
|
|
16327
|
+
if (Array.isArray(e)) {
|
|
16328
|
+
e.length = 0, Array.isArray(t) && e.push(...t);
|
|
16329
|
+
return;
|
|
16330
|
+
}
|
|
16331
|
+
let n = t && typeof t == "object" && !Array.isArray(t) ? t : {};
|
|
16332
|
+
for (let t of Object.keys(e)) t in n || delete e[t];
|
|
16333
|
+
for (let t of Object.keys(n)) e[t] = n[t];
|
|
16334
|
+
}
|
|
16335
|
+
var py = {
|
|
16336
|
+
largeResults: 4194304,
|
|
16337
|
+
drafts: 2097152,
|
|
16338
|
+
userFiles: 2097152
|
|
16339
|
+
}, my = [
|
|
16340
|
+
"largeResults",
|
|
16341
|
+
"drafts",
|
|
16342
|
+
"userFiles"
|
|
16343
|
+
], hy = .9;
|
|
16344
|
+
function gy(e, t = {}) {
|
|
16171
16345
|
let n = Object.create(null);
|
|
16172
|
-
if (e) for (let [t, r] of Object.entries(e)) n[
|
|
16346
|
+
if (e) for (let [t, r] of Object.entries(e)) n[by(t)] = {
|
|
16173
16347
|
content: r,
|
|
16174
|
-
updatedAt:
|
|
16348
|
+
updatedAt: Sy()
|
|
16349
|
+
};
|
|
16350
|
+
let { persist: r } = t, i = t.maxBytes ?? 8388608, a = {
|
|
16351
|
+
...py,
|
|
16352
|
+
...t.poolBytes ?? {}
|
|
16175
16353
|
};
|
|
16176
|
-
|
|
16177
|
-
|
|
16178
|
-
|
|
16179
|
-
|
|
16180
|
-
|
|
16181
|
-
|
|
16182
|
-
|
|
16183
|
-
|
|
16354
|
+
function o(e) {
|
|
16355
|
+
let t = by(e);
|
|
16356
|
+
return t.startsWith("large_results/") ? "largeResults" : t.startsWith("drafts/") ? "drafts" : "userFiles";
|
|
16357
|
+
}
|
|
16358
|
+
function s(e) {
|
|
16359
|
+
let t = 0;
|
|
16360
|
+
for (let [r, i] of Object.entries(n)) o(r) === e && (t += vy(i.content));
|
|
16361
|
+
return t;
|
|
16362
|
+
}
|
|
16363
|
+
function c() {
|
|
16364
|
+
for (let e of my) {
|
|
16365
|
+
let t = a[e];
|
|
16366
|
+
if (s(e) <= t) continue;
|
|
16367
|
+
let r = t * hy, i = Object.entries(n).filter(([t]) => o(t) === e).sort((e, t) => e[1].updatedAt - t[1].updatedAt);
|
|
16368
|
+
for (let [t] of i) if (delete n[t], s(e) <= r) break;
|
|
16369
|
+
}
|
|
16370
|
+
if (yy(n) > i) {
|
|
16371
|
+
let e = i * hy, t = Object.entries(n).sort((e, t) => e[1].updatedAt - t[1].updatedAt);
|
|
16372
|
+
for (let [r] of t) if (delete n[r], yy(n) <= e) break;
|
|
16373
|
+
}
|
|
16374
|
+
}
|
|
16375
|
+
let l = null;
|
|
16376
|
+
function u() {
|
|
16184
16377
|
if (!r?.save) return;
|
|
16185
16378
|
let e = {};
|
|
16186
16379
|
for (let [t, r] of Object.entries(n)) e[t] = { ...r };
|
|
16187
16380
|
r.save(e);
|
|
16188
16381
|
}
|
|
16189
|
-
function
|
|
16190
|
-
r?.save && (
|
|
16191
|
-
|
|
16382
|
+
function d() {
|
|
16383
|
+
r?.save && (l && clearTimeout(l), l = setTimeout(() => {
|
|
16384
|
+
l = null, u();
|
|
16192
16385
|
}, 800));
|
|
16193
16386
|
}
|
|
16194
|
-
let
|
|
16387
|
+
let f = { files: new Proxy(n, {
|
|
16195
16388
|
set(e, t, n) {
|
|
16196
16389
|
let r = Reflect.set(e, t, n);
|
|
16197
|
-
return r && (
|
|
16390
|
+
return r && (c(), d()), r;
|
|
16198
16391
|
},
|
|
16199
16392
|
deleteProperty(e, t) {
|
|
16200
16393
|
let n = Reflect.deleteProperty(e, t);
|
|
16201
|
-
return n &&
|
|
16394
|
+
return n && d(), n;
|
|
16202
16395
|
}
|
|
16203
16396
|
}) };
|
|
16204
|
-
return r && (
|
|
16205
|
-
for (let [t, r] of Object.entries(e)) n[
|
|
16206
|
-
a();
|
|
16207
|
-
}, l.flush = () => {
|
|
16208
|
-
o &&= (clearTimeout(o), null), s();
|
|
16209
|
-
}, l.clear = () => {
|
|
16210
|
-
for (let e of Object.keys(n)) delete n[e];
|
|
16397
|
+
return r && (f.hydrate = (e) => {
|
|
16398
|
+
for (let [t, r] of Object.entries(e)) n[by(t)] = r;
|
|
16211
16399
|
c();
|
|
16212
|
-
}
|
|
16400
|
+
}, f.flush = () => {
|
|
16401
|
+
l &&= (clearTimeout(l), null), u();
|
|
16402
|
+
}, f.clear = () => {
|
|
16403
|
+
for (let e of Object.keys(n)) delete n[e];
|
|
16404
|
+
d();
|
|
16405
|
+
}), f;
|
|
16406
|
+
}
|
|
16407
|
+
var _y = null;
|
|
16408
|
+
function vy(e) {
|
|
16409
|
+
return _y ||= new TextEncoder(), _y.encode(e).length;
|
|
16213
16410
|
}
|
|
16214
|
-
|
|
16215
|
-
function $v(e) {
|
|
16216
|
-
Qv ||= new TextEncoder();
|
|
16411
|
+
function yy(e) {
|
|
16217
16412
|
let t = 0;
|
|
16218
|
-
for (let n of Object.values(e)) t +=
|
|
16413
|
+
for (let n of Object.values(e)) t += vy(n.content);
|
|
16219
16414
|
return t;
|
|
16220
16415
|
}
|
|
16221
|
-
function
|
|
16416
|
+
function by(e) {
|
|
16222
16417
|
return e.replace(/^\/+/, "").replace(/\/+/g, "/");
|
|
16223
16418
|
}
|
|
16224
|
-
function
|
|
16419
|
+
function xy(e) {
|
|
16225
16420
|
let t = "";
|
|
16226
16421
|
for (let n = 0; n < e.length; n++) {
|
|
16227
16422
|
let r = e[n];
|
|
@@ -16229,13 +16424,23 @@ function ty(e) {
|
|
|
16229
16424
|
}
|
|
16230
16425
|
return RegExp("^" + t + "$");
|
|
16231
16426
|
}
|
|
16232
|
-
function
|
|
16427
|
+
function Sy() {
|
|
16233
16428
|
return Date.now();
|
|
16234
16429
|
}
|
|
16235
|
-
|
|
16430
|
+
var Cy = [
|
|
16431
|
+
"vfs_read",
|
|
16432
|
+
"vfs_write",
|
|
16433
|
+
"vfs_edit",
|
|
16434
|
+
"vfs_ls",
|
|
16435
|
+
"vfs_glob",
|
|
16436
|
+
"vfs_grep",
|
|
16437
|
+
"vfs_json_read",
|
|
16438
|
+
"vfs_json_patch"
|
|
16439
|
+
];
|
|
16440
|
+
function wy(e) {
|
|
16236
16441
|
return [
|
|
16237
16442
|
r(async ({ path: t, offset: n, limit: r }) => {
|
|
16238
|
-
let i = e.files[
|
|
16443
|
+
let i = e.files[by(t)];
|
|
16239
16444
|
if (!i) return $({
|
|
16240
16445
|
code: "NOT_FOUND",
|
|
16241
16446
|
path: t,
|
|
@@ -16253,19 +16458,32 @@ function ry(e) {
|
|
|
16253
16458
|
limit: t.number().int().min(1).default(2e3).describe("读取行数")
|
|
16254
16459
|
})
|
|
16255
16460
|
}),
|
|
16256
|
-
r(async ({ path: t, content: n }) =>
|
|
16257
|
-
|
|
16258
|
-
|
|
16259
|
-
|
|
16461
|
+
r(async ({ path: t, content: n, jsonString: r }) => {
|
|
16462
|
+
if (r) try {
|
|
16463
|
+
JSON.parse(n);
|
|
16464
|
+
} catch (e) {
|
|
16465
|
+
return $({
|
|
16466
|
+
code: "VFS_JSON_INVALID",
|
|
16467
|
+
path: t,
|
|
16468
|
+
message: `content 非合法 JSON: ${e.message}`,
|
|
16469
|
+
hint: "jsonString=true 要求 content 是合法 JSON;检查引号/逗号/括号配对;或省略 jsonString 写纯文本"
|
|
16470
|
+
});
|
|
16471
|
+
}
|
|
16472
|
+
return e.files[by(t)] = {
|
|
16473
|
+
content: n,
|
|
16474
|
+
updatedAt: Sy()
|
|
16475
|
+
}, `已写入 ${t}(${n.length} 字符)${r ? "(JSON 校验通过)" : ""}`;
|
|
16476
|
+
}, {
|
|
16260
16477
|
name: "vfs_write",
|
|
16261
|
-
description: "写入/覆盖虚拟工作区文件,作为中间工作记忆。",
|
|
16478
|
+
description: "写入/覆盖虚拟工作区文件,作为中间工作记忆。jsonString=true 时校验 content 是合法 JSON(配合 vfs_json_read/vfs_json_patch 操作 JSON 文件)。",
|
|
16262
16479
|
schema: t.object({
|
|
16263
16480
|
path: t.string().describe("文件路径"),
|
|
16264
|
-
content: t.string().describe("完整内容")
|
|
16481
|
+
content: t.string().describe("完整内容"),
|
|
16482
|
+
jsonString: t.boolean().optional().describe("true 时校验 content 是合法 JSON(非法返回 VFS_JSON_INVALID 不写入);省略/false 写纯文本不校验")
|
|
16265
16483
|
})
|
|
16266
16484
|
}),
|
|
16267
16485
|
r(async ({ path: t, oldString: n, newString: r }) => {
|
|
16268
|
-
let i =
|
|
16486
|
+
let i = by(t), a = e.files[i];
|
|
16269
16487
|
if (!a) return $({
|
|
16270
16488
|
code: "NOT_FOUND",
|
|
16271
16489
|
path: t,
|
|
@@ -16295,7 +16513,7 @@ function ry(e) {
|
|
|
16295
16513
|
}
|
|
16296
16514
|
return e.files[i] = {
|
|
16297
16515
|
content: a.content.replace(n, r),
|
|
16298
|
-
updatedAt:
|
|
16516
|
+
updatedAt: Sy()
|
|
16299
16517
|
}, `已替换 ${t} 中 1 处。`;
|
|
16300
16518
|
}, {
|
|
16301
16519
|
name: "vfs_edit",
|
|
@@ -16317,7 +16535,7 @@ function ry(e) {
|
|
|
16317
16535
|
r(async ({ pattern: t }) => {
|
|
16318
16536
|
let n;
|
|
16319
16537
|
try {
|
|
16320
|
-
n =
|
|
16538
|
+
n = xy(t);
|
|
16321
16539
|
} catch (e) {
|
|
16322
16540
|
return $({
|
|
16323
16541
|
code: "GLOB_INVALID",
|
|
@@ -16346,7 +16564,7 @@ function ry(e) {
|
|
|
16346
16564
|
details: { pattern: t }
|
|
16347
16565
|
});
|
|
16348
16566
|
}
|
|
16349
|
-
let i = n ? [
|
|
16567
|
+
let i = n ? [by(n)] : Object.keys(e.files), a = [];
|
|
16350
16568
|
for (let t of i) {
|
|
16351
16569
|
let n = e.files[t];
|
|
16352
16570
|
n && n.content.split("\n").forEach((e, n) => {
|
|
@@ -16361,20 +16579,110 @@ function ry(e) {
|
|
|
16361
16579
|
pattern: t.string().describe("正则表达式"),
|
|
16362
16580
|
path: t.string().optional().describe("限定单个文件,不传则搜索全部")
|
|
16363
16581
|
})
|
|
16582
|
+
}),
|
|
16583
|
+
r(async ({ path: t, jsonPath: n }) => {
|
|
16584
|
+
let r = by(t), i = e.files[r];
|
|
16585
|
+
if (!i) return $({
|
|
16586
|
+
code: "NOT_FOUND",
|
|
16587
|
+
path: t,
|
|
16588
|
+
message: `未找到文件 "${t}"`,
|
|
16589
|
+
hint: "用 vfs_ls 查看虚拟工作区文件列表"
|
|
16590
|
+
});
|
|
16591
|
+
let a;
|
|
16592
|
+
try {
|
|
16593
|
+
a = JSON.parse(i.content);
|
|
16594
|
+
} catch (e) {
|
|
16595
|
+
return $({
|
|
16596
|
+
code: "VFS_JSON_INVALID",
|
|
16597
|
+
path: t,
|
|
16598
|
+
message: `文件内容非合法 JSON: ${e.message}`,
|
|
16599
|
+
hint: "vfs_json_read 要求文件内容是合法 JSON;先 vfs_read 查看实际内容,或 vfs_write({jsonString:true}) 重写为合法 JSON"
|
|
16600
|
+
});
|
|
16601
|
+
}
|
|
16602
|
+
if (n) {
|
|
16603
|
+
let e = ey(a, n);
|
|
16604
|
+
return e === void 0 ? $({
|
|
16605
|
+
code: "VFS_PATH_NOT_FOUND",
|
|
16606
|
+
path: t,
|
|
16607
|
+
message: `jsonPath "${n}" 不存在`,
|
|
16608
|
+
hint: "不传 jsonPath 整体读查看结构,或核对路径段"
|
|
16609
|
+
}) : `${t}#${n} (JSON):\n${JSON.stringify(e)}`;
|
|
16610
|
+
}
|
|
16611
|
+
return `${t} (JSON):\n${JSON.stringify(a)}`;
|
|
16612
|
+
}, {
|
|
16613
|
+
name: "vfs_json_read",
|
|
16614
|
+
description: "把虚拟工作区文件当 JSON 读取:先 parse 整文件,再按 jsonPath 取子树(省略返整体)。文件非合法 JSON 报 VFS_JSON_INVALID。适合结构化读取 vfs 内大 JSON。",
|
|
16615
|
+
schema: t.object({
|
|
16616
|
+
path: t.string().describe("文件路径(内容须为合法 JSON)"),
|
|
16617
|
+
jsonPath: t.string().optional().describe("点分隔子路径(如 components.0.title);省略读整体")
|
|
16618
|
+
})
|
|
16619
|
+
}),
|
|
16620
|
+
r(async ({ path: t, patches: n }) => {
|
|
16621
|
+
let r = by(t), i = e.files[r];
|
|
16622
|
+
if (!i) return $({
|
|
16623
|
+
code: "NOT_FOUND",
|
|
16624
|
+
path: t,
|
|
16625
|
+
message: `未找到文件 "${t}"`,
|
|
16626
|
+
hint: "用 vfs_ls 查看虚拟工作区文件列表"
|
|
16627
|
+
});
|
|
16628
|
+
let a;
|
|
16629
|
+
try {
|
|
16630
|
+
a = JSON.parse(i.content);
|
|
16631
|
+
} catch (e) {
|
|
16632
|
+
return $({
|
|
16633
|
+
code: "VFS_JSON_INVALID",
|
|
16634
|
+
path: t,
|
|
16635
|
+
message: `文件内容非合法 JSON: ${e.message}`,
|
|
16636
|
+
hint: "vfs_json_patch 要求文件内容是合法 JSON"
|
|
16637
|
+
});
|
|
16638
|
+
}
|
|
16639
|
+
let o = ry(a), s = [];
|
|
16640
|
+
for (let e of n) {
|
|
16641
|
+
let n = ly(o, e.op, e.jsonPath, e.value);
|
|
16642
|
+
if (n) return $({
|
|
16643
|
+
code: "PATCH_FAILED",
|
|
16644
|
+
path: t,
|
|
16645
|
+
message: n,
|
|
16646
|
+
hint: "修正 patches 后重试(原文件未改动)",
|
|
16647
|
+
details: { failedPatch: e }
|
|
16648
|
+
});
|
|
16649
|
+
s.push(e.jsonPath || "(根)");
|
|
16650
|
+
}
|
|
16651
|
+
let c = JSON.stringify(o);
|
|
16652
|
+
return e.files[r] = {
|
|
16653
|
+
content: c,
|
|
16654
|
+
updatedAt: Sy()
|
|
16655
|
+
}, `已对 ${t} 应用 ${n.length} 个 patch(影响 ${s.length} 处:${s.join(", ")}),文件现 ${c.length} 字符`;
|
|
16656
|
+
}, {
|
|
16657
|
+
name: "vfs_json_patch",
|
|
16658
|
+
description: "在虚拟工作区 JSON 文件内做原子 jsonPath patch(set/remove/merge/append)。先 parse → clone 上应用全部 patches → 任一失败或 JSON 非法则整体不写回(原文件不变)。",
|
|
16659
|
+
schema: t.object({
|
|
16660
|
+
path: t.string().describe("文件路径(内容须为合法 JSON)"),
|
|
16661
|
+
patches: t.array(t.object({
|
|
16662
|
+
op: t.enum([
|
|
16663
|
+
"set",
|
|
16664
|
+
"remove",
|
|
16665
|
+
"merge",
|
|
16666
|
+
"append"
|
|
16667
|
+
]).describe("操作"),
|
|
16668
|
+
jsonPath: t.string().describe("点分隔路径(如 components.0.title);merge/append 目标可为根(空串)"),
|
|
16669
|
+
value: t.any().optional().describe("set/merge/append 的值(remove 不需要)")
|
|
16670
|
+
})).describe("按顺序应用的 patch 列表(原子:任一失败整体不写回)")
|
|
16671
|
+
})
|
|
16364
16672
|
})
|
|
16365
16673
|
];
|
|
16366
16674
|
}
|
|
16367
|
-
function
|
|
16675
|
+
function Ty(e) {
|
|
16368
16676
|
return {
|
|
16369
16677
|
name: "vfs",
|
|
16370
|
-
tools:
|
|
16678
|
+
tools: wy(e),
|
|
16371
16679
|
beforeAgent: () => ({ files: e.files })
|
|
16372
16680
|
};
|
|
16373
16681
|
}
|
|
16374
16682
|
//#endregion
|
|
16375
16683
|
//#region src/core/tools/dataSlotQuery.ts
|
|
16376
|
-
var
|
|
16377
|
-
function
|
|
16684
|
+
var Ey = /[\w$-]/;
|
|
16685
|
+
function Dy(e) {
|
|
16378
16686
|
let t = [], n = e.trim(), r = +(n[0] === "$");
|
|
16379
16687
|
for (; r < n.length;) {
|
|
16380
16688
|
let e = n[r];
|
|
@@ -16385,7 +16693,7 @@ function oy(e) {
|
|
|
16385
16693
|
continue;
|
|
16386
16694
|
}
|
|
16387
16695
|
let e = "";
|
|
16388
|
-
for (; r < n.length &&
|
|
16696
|
+
for (; r < n.length && Ey.test(n[r]);) e += n[r++];
|
|
16389
16697
|
if (!e) throw Error("JSONPath: .. 后缺属性名");
|
|
16390
16698
|
t.push({
|
|
16391
16699
|
type: "descendKey",
|
|
@@ -16398,7 +16706,7 @@ function oy(e) {
|
|
|
16398
16706
|
continue;
|
|
16399
16707
|
}
|
|
16400
16708
|
let e = "";
|
|
16401
|
-
for (; r < n.length &&
|
|
16709
|
+
for (; r < n.length && Ey.test(n[r]);) e += n[r++];
|
|
16402
16710
|
if (!e) throw Error("JSONPath: . 后缺属性名");
|
|
16403
16711
|
t.push({
|
|
16404
16712
|
type: "key",
|
|
@@ -16454,7 +16762,7 @@ function oy(e) {
|
|
|
16454
16762
|
}
|
|
16455
16763
|
return t;
|
|
16456
16764
|
}
|
|
16457
|
-
function
|
|
16765
|
+
function Oy(e) {
|
|
16458
16766
|
let t = [], n = 0, r = e.trim();
|
|
16459
16767
|
for (; n < r.length;) {
|
|
16460
16768
|
let e = r[n];
|
|
@@ -16499,7 +16807,7 @@ function sy(e) {
|
|
|
16499
16807
|
}
|
|
16500
16808
|
return t;
|
|
16501
16809
|
}
|
|
16502
|
-
var
|
|
16810
|
+
var ky = class {
|
|
16503
16811
|
toks;
|
|
16504
16812
|
item;
|
|
16505
16813
|
pos = 0;
|
|
@@ -16535,12 +16843,12 @@ var cy = class {
|
|
|
16535
16843
|
return this.next(), e;
|
|
16536
16844
|
}
|
|
16537
16845
|
let e = this.operand(), t = this.peek();
|
|
16538
|
-
return t === "==" || t === "!=" || t === "<" || t === "<=" || t === ">" || t === ">=" ? (this.next(),
|
|
16846
|
+
return t === "==" || t === "!=" || t === "<" || t === "<=" || t === ">" || t === ">=" ? (this.next(), My(t, e, this.operand())) : Ay(e);
|
|
16539
16847
|
}
|
|
16540
16848
|
operand() {
|
|
16541
16849
|
let e = this.next();
|
|
16542
16850
|
if (e === void 0) throw Error("过滤表达式:缺操作数");
|
|
16543
|
-
if (e.startsWith("@")) return
|
|
16851
|
+
if (e.startsWith("@")) return jy(e, this.item);
|
|
16544
16852
|
if (e[0] === "'" || e[0] === "\"") return e.slice(1, -1);
|
|
16545
16853
|
if (e === "true") return !0;
|
|
16546
16854
|
if (e === "false") return !1;
|
|
@@ -16550,10 +16858,10 @@ var cy = class {
|
|
|
16550
16858
|
throw Error(`过滤表达式:未知操作数 '${e}'`);
|
|
16551
16859
|
}
|
|
16552
16860
|
};
|
|
16553
|
-
function
|
|
16861
|
+
function Ay(e) {
|
|
16554
16862
|
return !!e && e !== 0 && e !== "" && e !== null;
|
|
16555
16863
|
}
|
|
16556
|
-
function
|
|
16864
|
+
function jy(e, t) {
|
|
16557
16865
|
let n = e.split(".").filter((e) => e && e !== "@"), r = t;
|
|
16558
16866
|
for (let e of n) {
|
|
16559
16867
|
if (typeof r != "object" || !r) return;
|
|
@@ -16561,7 +16869,7 @@ function uy(e, t) {
|
|
|
16561
16869
|
}
|
|
16562
16870
|
return r;
|
|
16563
16871
|
}
|
|
16564
|
-
function
|
|
16872
|
+
function My(e, t, n) {
|
|
16565
16873
|
switch (e) {
|
|
16566
16874
|
case "==": return t === n;
|
|
16567
16875
|
case "!=": return t !== n;
|
|
@@ -16572,47 +16880,47 @@ function dy(e, t, n) {
|
|
|
16572
16880
|
default: return !1;
|
|
16573
16881
|
}
|
|
16574
16882
|
}
|
|
16575
|
-
function
|
|
16576
|
-
return new
|
|
16883
|
+
function Ny(e, t) {
|
|
16884
|
+
return new ky(Oy(e), t).parse();
|
|
16577
16885
|
}
|
|
16578
|
-
function
|
|
16886
|
+
function Py(e, t) {
|
|
16579
16887
|
return e ? `${e}.${t}` : String(t);
|
|
16580
16888
|
}
|
|
16581
|
-
function
|
|
16889
|
+
function Fy(e, t) {
|
|
16582
16890
|
let n = [{
|
|
16583
16891
|
path: "",
|
|
16584
16892
|
value: e
|
|
16585
16893
|
}];
|
|
16586
|
-
for (let e of
|
|
16894
|
+
for (let e of Dy(t)) {
|
|
16587
16895
|
let t = [];
|
|
16588
16896
|
if (e.type === "key") for (let r of n) r.value != null && typeof r.value == "object" && e.key in r.value && t.push({
|
|
16589
|
-
path:
|
|
16897
|
+
path: Py(r.path, e.key),
|
|
16590
16898
|
value: r.value[e.key]
|
|
16591
16899
|
});
|
|
16592
16900
|
else if (e.type === "index") {
|
|
16593
16901
|
for (let r of n) if (Array.isArray(r.value)) {
|
|
16594
16902
|
let n = r.value[e.index];
|
|
16595
16903
|
e.index >= 0 && e.index < r.value.length && t.push({
|
|
16596
|
-
path:
|
|
16904
|
+
path: Py(r.path, e.index),
|
|
16597
16905
|
value: n,
|
|
16598
16906
|
index: e.index
|
|
16599
16907
|
});
|
|
16600
16908
|
}
|
|
16601
16909
|
} else if (e.type === "wildcard") {
|
|
16602
16910
|
for (let e of n) if (Array.isArray(e.value)) e.value.forEach((n, r) => t.push({
|
|
16603
|
-
path:
|
|
16911
|
+
path: Py(e.path, r),
|
|
16604
16912
|
value: n,
|
|
16605
16913
|
index: r
|
|
16606
16914
|
}));
|
|
16607
16915
|
else if (e.value != null && typeof e.value == "object") for (let n of Object.keys(e.value)) t.push({
|
|
16608
|
-
path:
|
|
16916
|
+
path: Py(e.path, n),
|
|
16609
16917
|
value: e.value[n]
|
|
16610
16918
|
});
|
|
16611
16919
|
} else if (e.type === "descendKey") {
|
|
16612
16920
|
let r = e.key, i = (e) => {
|
|
16613
|
-
if (
|
|
16921
|
+
if (e.value != null && typeof e.value == "object") for (let n of Object.keys(e.value)) {
|
|
16614
16922
|
let a = {
|
|
16615
|
-
path:
|
|
16923
|
+
path: Py(e.path, n),
|
|
16616
16924
|
value: e.value[n]
|
|
16617
16925
|
};
|
|
16618
16926
|
n === r && t.push(a), i(a);
|
|
@@ -16621,9 +16929,9 @@ function my(e, t) {
|
|
|
16621
16929
|
for (let e of n) i(e);
|
|
16622
16930
|
} else if (e.type === "descendAll") {
|
|
16623
16931
|
let e = (n) => {
|
|
16624
|
-
if (
|
|
16932
|
+
if (n.value != null && typeof n.value == "object") for (let r of Object.keys(n.value)) {
|
|
16625
16933
|
let i = {
|
|
16626
|
-
path:
|
|
16934
|
+
path: Py(n.path, r),
|
|
16627
16935
|
value: n.value[r]
|
|
16628
16936
|
};
|
|
16629
16937
|
t.push(i), e(i);
|
|
@@ -16632,16 +16940,16 @@ function my(e, t) {
|
|
|
16632
16940
|
for (let t of n) e(t);
|
|
16633
16941
|
} else if (e.type === "filter") {
|
|
16634
16942
|
for (let r of n) if (Array.isArray(r.value)) r.value.forEach((n, i) => {
|
|
16635
|
-
|
|
16636
|
-
path:
|
|
16943
|
+
Ny(e.filter, n) && t.push({
|
|
16944
|
+
path: Py(r.path, i),
|
|
16637
16945
|
value: n,
|
|
16638
16946
|
index: i
|
|
16639
16947
|
});
|
|
16640
16948
|
});
|
|
16641
16949
|
else if (r.value != null && typeof r.value == "object") for (let n of Object.keys(r.value)) {
|
|
16642
16950
|
let i = r.value[n];
|
|
16643
|
-
|
|
16644
|
-
path:
|
|
16951
|
+
Ny(e.filter, i) && t.push({
|
|
16952
|
+
path: Py(r.path, n),
|
|
16645
16953
|
value: i
|
|
16646
16954
|
});
|
|
16647
16955
|
}
|
|
@@ -16650,7 +16958,7 @@ function my(e, t) {
|
|
|
16650
16958
|
}
|
|
16651
16959
|
return n;
|
|
16652
16960
|
}
|
|
16653
|
-
function
|
|
16961
|
+
function Iy(e, t) {
|
|
16654
16962
|
let n = e.length, r = t.length;
|
|
16655
16963
|
if (!n) return r;
|
|
16656
16964
|
if (!r) return n;
|
|
@@ -16666,7 +16974,7 @@ function hy(e, t) {
|
|
|
16666
16974
|
}
|
|
16667
16975
|
return i[r];
|
|
16668
16976
|
}
|
|
16669
|
-
function
|
|
16977
|
+
function Ly(e, t, n = {}) {
|
|
16670
16978
|
let r = n.mode || "substring", i = n.limit ?? 50, a = n.matchKey !== !1, o = [], s = null;
|
|
16671
16979
|
if (r === "regex") try {
|
|
16672
16980
|
s = new RegExp(t, "i");
|
|
@@ -16676,11 +16984,11 @@ function gy(e, t, n = {}) {
|
|
|
16676
16984
|
let c = (e, l, u) => {
|
|
16677
16985
|
if (o.length >= i || e == null) return;
|
|
16678
16986
|
if (typeof e == "object") {
|
|
16679
|
-
if (Array.isArray(e)) e.forEach((e, t) => c(e,
|
|
16680
|
-
else for (let t of Object.keys(e)) c(e[t],
|
|
16987
|
+
if (Array.isArray(e)) e.forEach((e, t) => c(e, Py(l, t), String(t)));
|
|
16988
|
+
else for (let t of Object.keys(e)) c(e[t], Py(l, t), t);
|
|
16681
16989
|
return;
|
|
16682
16990
|
}
|
|
16683
|
-
let d = String(e), f =
|
|
16991
|
+
let d = String(e), f = Ry(d, t, r, n.fuzzyThreshold ?? 2, s);
|
|
16684
16992
|
if (f) {
|
|
16685
16993
|
o.push({
|
|
16686
16994
|
path: l,
|
|
@@ -16691,7 +16999,7 @@ function gy(e, t, n = {}) {
|
|
|
16691
16999
|
return;
|
|
16692
17000
|
}
|
|
16693
17001
|
if (a && u) {
|
|
16694
|
-
let e =
|
|
17002
|
+
let e = Ry(u, t, r, n.fuzzyThreshold ?? 2, s);
|
|
16695
17003
|
e && o.push({
|
|
16696
17004
|
path: l,
|
|
16697
17005
|
key: u,
|
|
@@ -16702,18 +17010,18 @@ function gy(e, t, n = {}) {
|
|
|
16702
17010
|
};
|
|
16703
17011
|
return c(e, ""), o;
|
|
16704
17012
|
}
|
|
16705
|
-
function
|
|
17013
|
+
function Ry(e, t, n, r, i) {
|
|
16706
17014
|
let a = e.toLowerCase(), o = t.toLowerCase();
|
|
16707
17015
|
if (n === "substring") return a.includes(o) ? 1 : null;
|
|
16708
17016
|
if (n === "regex") return i && i.test(e) ? 1 : null;
|
|
16709
17017
|
if (n === "fuzzy") {
|
|
16710
17018
|
if (a.includes(o)) return 2;
|
|
16711
|
-
let e =
|
|
17019
|
+
let e = Iy(a, o);
|
|
16712
17020
|
return e <= r ? r - e + 1 : null;
|
|
16713
17021
|
}
|
|
16714
17022
|
return null;
|
|
16715
17023
|
}
|
|
16716
|
-
var
|
|
17024
|
+
var zy = [
|
|
16717
17025
|
"self.fetch = () => { throw new Error('fetch 已被沙箱禁用') }",
|
|
16718
17026
|
"self.XMLHttpRequest = function(){ throw new Error('XMLHttpRequest 已被沙箱禁用') }",
|
|
16719
17027
|
"self.importScripts = () => { throw new Error('importScripts 已被沙箱禁用') }",
|
|
@@ -16726,7 +17034,7 @@ var vy = [
|
|
|
16726
17034
|
"try { self.BroadcastChannel = undefined } catch {}",
|
|
16727
17035
|
"if (self.navigator && self.navigator.sendBeacon) self.navigator.sendBeacon = () => { throw new Error('sendBeacon 已被沙箱禁用') }"
|
|
16728
17036
|
].join("\n");
|
|
16729
|
-
function
|
|
17037
|
+
function By(e, t, n = 3e3) {
|
|
16730
17038
|
return new Promise((r) => {
|
|
16731
17039
|
let i = Date.now(), a = !1, o = (e) => {
|
|
16732
17040
|
if (!a) {
|
|
@@ -16739,7 +17047,7 @@ function yy(e, t, n = 3e3) {
|
|
|
16739
17047
|
elapsedMs: Date.now() - i
|
|
16740
17048
|
});
|
|
16741
17049
|
}
|
|
16742
|
-
}, s =
|
|
17050
|
+
}, s = zy + "\nself.onmessage = async (e) => {\n try {\n const fn = new Function(\"data\", e.data.script);\n let result = fn(e.data.data);\n if (result && typeof result.then === \"function\") result = await result;\n self.postMessage({ ok: true, result });\n } catch (err) {\n self.postMessage({ ok: false, error: String((err && err.message) || err) });\n }\n};", c, l;
|
|
16743
17051
|
try {
|
|
16744
17052
|
let e = new Blob([s], { type: "application/javascript" });
|
|
16745
17053
|
c = URL.createObjectURL(e), l = new Worker(c);
|
|
@@ -16773,135 +17081,8 @@ function yy(e, t, n = 3e3) {
|
|
|
16773
17081
|
});
|
|
16774
17082
|
}
|
|
16775
17083
|
//#endregion
|
|
16776
|
-
//#region src/core/tools/jsonUtils.ts
|
|
16777
|
-
var by = /* @__PURE__ */ new Set([
|
|
16778
|
-
"__proto__",
|
|
16779
|
-
"constructor",
|
|
16780
|
-
"prototype"
|
|
16781
|
-
]);
|
|
16782
|
-
function xy(e) {
|
|
16783
|
-
return e.split(".").some((e) => by.has(e));
|
|
16784
|
-
}
|
|
16785
|
-
function Sy(e, t) {
|
|
16786
|
-
if (!(!t || typeof t != "object" || Array.isArray(t))) for (let n of Object.keys(t)) by.has(n) || (e[n] = t[n]);
|
|
16787
|
-
}
|
|
16788
|
-
function Cy(e, t) {
|
|
16789
|
-
if (!t) return e;
|
|
16790
|
-
if (xy(t)) return;
|
|
16791
|
-
let n = t.split("."), r = e;
|
|
16792
|
-
for (let e of n) {
|
|
16793
|
-
if (r == null) return;
|
|
16794
|
-
r = r[e];
|
|
16795
|
-
}
|
|
16796
|
-
return r;
|
|
16797
|
-
}
|
|
16798
|
-
function wy(e, t, n) {
|
|
16799
|
-
if (!t || xy(t)) return;
|
|
16800
|
-
let r = t.split("."), i = e;
|
|
16801
|
-
for (let e = 0; e < r.length - 1; e++) {
|
|
16802
|
-
let t = r[e];
|
|
16803
|
-
(i[t] == null || typeof i[t] != "object") && (i[t] = {}), i = i[t];
|
|
16804
|
-
}
|
|
16805
|
-
i[r[r.length - 1]] = n;
|
|
16806
|
-
}
|
|
16807
|
-
function Ty(e, t) {
|
|
16808
|
-
if (!t || xy(t)) return !1;
|
|
16809
|
-
let n = t.split("."), r = e;
|
|
16810
|
-
for (let e = 0; e < n.length - 1; e++) {
|
|
16811
|
-
if (r == null) return !1;
|
|
16812
|
-
r = r[n[e]];
|
|
16813
|
-
}
|
|
16814
|
-
let i = n[n.length - 1];
|
|
16815
|
-
return r == null || !(i in r) ? !1 : (delete r[i], !0);
|
|
16816
|
-
}
|
|
16817
|
-
function Ey(e) {
|
|
16818
|
-
return e === void 0 ? void 0 : JSON.parse(JSON.stringify(e));
|
|
16819
|
-
}
|
|
16820
|
-
function Dy(e) {
|
|
16821
|
-
if (typeof e != "string") return { parsed: e };
|
|
16822
|
-
let t = e.trim();
|
|
16823
|
-
if (!t) return { parsed: e };
|
|
16824
|
-
let n = t[0] === "{" || t[0] === "[";
|
|
16825
|
-
try {
|
|
16826
|
-
return { parsed: JSON.parse(t) };
|
|
16827
|
-
} catch (t) {
|
|
16828
|
-
return n ? { parseError: t } : { parsed: e };
|
|
16829
|
-
}
|
|
16830
|
-
}
|
|
16831
|
-
function Oy(e, t) {
|
|
16832
|
-
if (typeof e != "object" || !e) return e;
|
|
16833
|
-
let n = new Set(t);
|
|
16834
|
-
if (Array.isArray(e)) return e.map((e) => Oy(e, t));
|
|
16835
|
-
let r = {};
|
|
16836
|
-
for (let t of Object.keys(e)) n.has(t) && (r[t] = e[t]);
|
|
16837
|
-
return r;
|
|
16838
|
-
}
|
|
16839
|
-
function ky(e, t) {
|
|
16840
|
-
if (typeof e != "object" || !e) return e;
|
|
16841
|
-
if (t <= 0) return Array.isArray(e) ? `[...${e.length}]` : "{...}";
|
|
16842
|
-
if (Array.isArray(e)) return e.map((e) => ky(e, t - 1));
|
|
16843
|
-
let n = {};
|
|
16844
|
-
for (let r of Object.keys(e)) n[r] = ky(e[r], t - 1);
|
|
16845
|
-
return n;
|
|
16846
|
-
}
|
|
16847
|
-
function Ay(e, t = Infinity) {
|
|
16848
|
-
let n = /* @__PURE__ */ new WeakSet(), r;
|
|
16849
|
-
try {
|
|
16850
|
-
r = JSON.stringify(e, (e, t) => {
|
|
16851
|
-
if (typeof t == "function") return "[Function]";
|
|
16852
|
-
if (typeof t == "bigint") return t.toString();
|
|
16853
|
-
if (typeof t == "object" && t) {
|
|
16854
|
-
if (typeof HTMLElement < "u" && t instanceof HTMLElement) return `[HTMLElement: <${t.tagName.toLowerCase()}>]`;
|
|
16855
|
-
if (typeof Node < "u" && t instanceof Node) return `[Node: type=${t.nodeType}]`;
|
|
16856
|
-
if (n.has(t)) return "[Circular]";
|
|
16857
|
-
n.add(t);
|
|
16858
|
-
}
|
|
16859
|
-
return t;
|
|
16860
|
-
}, 0);
|
|
16861
|
-
} catch (e) {
|
|
16862
|
-
r = `[无法序列化: ${e?.message || String(e)}]`;
|
|
16863
|
-
}
|
|
16864
|
-
return r.length > t && (r = r.slice(0, t) + `\n…[已截断,原长度 ${r.length}]`), r;
|
|
16865
|
-
}
|
|
16866
|
-
function jy(e) {
|
|
16867
|
-
let t = Ay(e), n = 5381;
|
|
16868
|
-
for (let e = 0; e < t.length; e++) n = (n << 5) + n + t.charCodeAt(e) >>> 0;
|
|
16869
|
-
return n.toString(36);
|
|
16870
|
-
}
|
|
16871
|
-
function My(e, t, n, r) {
|
|
16872
|
-
if (t === "set") return n ? (wy(e, n, r), null) : "set 操作需要 jsonPath(整体替换请用 set_data)";
|
|
16873
|
-
if (t === "remove") return n ? (Ty(e, n), null) : "remove 操作需要 jsonPath";
|
|
16874
|
-
if (t === "merge") {
|
|
16875
|
-
let t = n ? Cy(e, n) : e;
|
|
16876
|
-
return typeof t != "object" || !t || Array.isArray(t) ? `merge 目标${n ? `(${n})` : "(根)"}不是对象` : (Sy(t, r), null);
|
|
16877
|
-
}
|
|
16878
|
-
let i = n ? Cy(e, n) : e;
|
|
16879
|
-
return Array.isArray(i) ? (Array.isArray(r) ? i.push(...r) : i.push(r), null) : `append 目标${n ? `(${n})` : "(根)"}不是数组`;
|
|
16880
|
-
}
|
|
16881
|
-
function Ny(e, t, n, r) {
|
|
16882
|
-
if (t === "set") wy(e, n, r);
|
|
16883
|
-
else if (t === "remove") Ty(e, n);
|
|
16884
|
-
else if (t === "merge") Sy(n ? Cy(e, n) : e, r);
|
|
16885
|
-
else {
|
|
16886
|
-
let t = n ? Cy(e, n) : e;
|
|
16887
|
-
Array.isArray(r) ? t.push(...r) : t.push(r);
|
|
16888
|
-
}
|
|
16889
|
-
}
|
|
16890
|
-
function Py(e, t) {
|
|
16891
|
-
typeof e == "object" && e && Fy(e, t);
|
|
16892
|
-
}
|
|
16893
|
-
function Fy(e, t) {
|
|
16894
|
-
if (Array.isArray(e)) {
|
|
16895
|
-
e.length = 0, Array.isArray(t) && e.push(...t);
|
|
16896
|
-
return;
|
|
16897
|
-
}
|
|
16898
|
-
let n = t && typeof t == "object" && !Array.isArray(t) ? t : {};
|
|
16899
|
-
for (let t of Object.keys(e)) t in n || delete e[t];
|
|
16900
|
-
for (let t of Object.keys(n)) e[t] = n[t];
|
|
16901
|
-
}
|
|
16902
|
-
//#endregion
|
|
16903
17084
|
//#region src/core/tools/schemaUtils.ts
|
|
16904
|
-
function
|
|
17085
|
+
function Vy(e) {
|
|
16905
17086
|
let t = e;
|
|
16906
17087
|
for (let e = 0; e < 5 && t && t._def; e++) {
|
|
16907
17088
|
if (t._def.innerType) {
|
|
@@ -16918,12 +17099,12 @@ function Iy(e) {
|
|
|
16918
17099
|
return null;
|
|
16919
17100
|
}
|
|
16920
17101
|
}
|
|
16921
|
-
function
|
|
17102
|
+
function Hy(e, t, n) {
|
|
16922
17103
|
if (!n || !e) return !0;
|
|
16923
|
-
let r =
|
|
17104
|
+
let r = Uy(t);
|
|
16924
17105
|
for (let t of e.split(".")) {
|
|
16925
17106
|
if (!r) return !1;
|
|
16926
|
-
if (r =
|
|
17107
|
+
if (r = Uy(r), r && r.shape && typeof r.shape == "object") {
|
|
16927
17108
|
let e = typeof r.shape == "function" ? r.shape() : r.shape;
|
|
16928
17109
|
if (!(t in e)) return !1;
|
|
16929
17110
|
r = e[t];
|
|
@@ -16932,7 +17113,7 @@ function Ly(e, t, n) {
|
|
|
16932
17113
|
}
|
|
16933
17114
|
return !0;
|
|
16934
17115
|
}
|
|
16935
|
-
function
|
|
17116
|
+
function Uy(e) {
|
|
16936
17117
|
let t = e;
|
|
16937
17118
|
for (let e = 0; e < 8 && t && t._def; e++) {
|
|
16938
17119
|
if (t._def.innerType) {
|
|
@@ -16951,35 +17132,35 @@ function Ry(e) {
|
|
|
16951
17132
|
}
|
|
16952
17133
|
return t;
|
|
16953
17134
|
}
|
|
16954
|
-
function
|
|
17135
|
+
function Wy(e, t) {
|
|
16955
17136
|
if (!t) return e;
|
|
16956
|
-
let n =
|
|
17137
|
+
let n = Uy(e), r = t.split(".");
|
|
16957
17138
|
for (let e of r) {
|
|
16958
17139
|
if (!n) return null;
|
|
16959
|
-
if (n =
|
|
17140
|
+
if (n = Uy(n), n && n.shape && typeof n.shape == "object") n = (typeof n.shape == "function" ? n.shape() : n.shape)[e];
|
|
16960
17141
|
else if (n && (n._def?.type || n.element)) n = n.element ?? n._def?.type;
|
|
16961
17142
|
else return null;
|
|
16962
17143
|
}
|
|
16963
17144
|
return n ?? null;
|
|
16964
17145
|
}
|
|
16965
|
-
function
|
|
17146
|
+
function Gy(e, t) {
|
|
16966
17147
|
if (typeof e != "object" || !e || !t) return e;
|
|
16967
|
-
let n =
|
|
17148
|
+
let n = Uy(t);
|
|
16968
17149
|
if (!n || !n.shape) {
|
|
16969
17150
|
if (Array.isArray(e) && (n?._def?.type || n?.element)) {
|
|
16970
17151
|
let t = n.element ?? n._def?.type;
|
|
16971
|
-
return e.map((e) =>
|
|
17152
|
+
return e.map((e) => Gy(e, t));
|
|
16972
17153
|
}
|
|
16973
17154
|
return e;
|
|
16974
17155
|
}
|
|
16975
17156
|
let r = typeof n.shape == "function" ? n.shape() : n.shape, i = {};
|
|
16976
17157
|
for (let t of Object.keys(e)) if (t in r) {
|
|
16977
17158
|
let n = e[t];
|
|
16978
|
-
i[t] =
|
|
17159
|
+
i[t] = Gy(n, r[t]);
|
|
16979
17160
|
}
|
|
16980
17161
|
return i;
|
|
16981
17162
|
}
|
|
16982
|
-
function
|
|
17163
|
+
function Ky(e, t) {
|
|
16983
17164
|
if (!t || typeof e != "object" || !e || Array.isArray(e)) return e;
|
|
16984
17165
|
let n = new Set(t), r = {};
|
|
16985
17166
|
for (let t of Object.keys(e)) n.has(t) && (r[t] = e[t]);
|
|
@@ -16987,25 +17168,25 @@ function Vy(e, t) {
|
|
|
16987
17168
|
}
|
|
16988
17169
|
//#endregion
|
|
16989
17170
|
//#region src/core/tools/dataOps.ts
|
|
16990
|
-
var
|
|
17171
|
+
var qy = /* @__PURE__ */ new Set([
|
|
16991
17172
|
"describe_data",
|
|
16992
17173
|
"get_data",
|
|
16993
17174
|
"set_data",
|
|
16994
17175
|
"edit_data",
|
|
16995
17176
|
"delete_data"
|
|
16996
|
-
]),
|
|
16997
|
-
function
|
|
16998
|
-
return t === "advanced" ? e : t === "minimal" ? e.filter((e) =>
|
|
17177
|
+
]), Jy = /* @__PURE__ */ new Set(["read", "write"]);
|
|
17178
|
+
function Yy(e, t = "simple") {
|
|
17179
|
+
return t === "advanced" ? e : t === "minimal" ? e.filter((e) => Jy.has(e.name)) : e.filter((e) => !qy.has(e.name));
|
|
16999
17180
|
}
|
|
17000
|
-
function
|
|
17001
|
-
let i = e.schema, a = e.bind, o = e.description ?? "主数据对象", s =
|
|
17181
|
+
function Xy(e, n = {}) {
|
|
17182
|
+
let i = e.schema, a = e.bind, o = e.description ?? "主数据对象", s = Vy(i), c = [], l = n.maxSnapshots ?? 20, u, d = n.autoLock !== !1, f = {
|
|
17002
17183
|
get: () => ({
|
|
17003
17184
|
schema: i,
|
|
17004
17185
|
bind: a,
|
|
17005
17186
|
description: o
|
|
17006
17187
|
}),
|
|
17007
17188
|
set: (e) => {
|
|
17008
|
-
i = e.schema, a = e.bind, o = e.description ?? "主数据对象", s =
|
|
17189
|
+
i = e.schema, a = e.bind, o = e.description ?? "主数据对象", s = Vy(i), c.length = 0, u = void 0;
|
|
17009
17190
|
},
|
|
17010
17191
|
update: (e) => {
|
|
17011
17192
|
a = e, c.length = 0, u = void 0;
|
|
@@ -17014,7 +17195,7 @@ function Gy(e, n = {}) {
|
|
|
17014
17195
|
n.onAudit?.(e);
|
|
17015
17196
|
};
|
|
17016
17197
|
function m(e, t) {
|
|
17017
|
-
let n =
|
|
17198
|
+
let n = ry(a), r = c.length ? c[c.length - 1].id + 1 : 1;
|
|
17018
17199
|
for (c.push({
|
|
17019
17200
|
id: r,
|
|
17020
17201
|
ts: Date.now(),
|
|
@@ -17026,12 +17207,12 @@ function Gy(e, n = {}) {
|
|
|
17026
17207
|
}
|
|
17027
17208
|
async function h(e, t, r) {
|
|
17028
17209
|
if (!t || t === "") return null;
|
|
17029
|
-
let i =
|
|
17210
|
+
let i = cy(a);
|
|
17030
17211
|
if (i === t) return null;
|
|
17031
17212
|
if (!n.onConflict) return $({
|
|
17032
17213
|
code: "VERSION_CONFLICT",
|
|
17033
17214
|
message: `乐观锁冲突:expectedHash=${t} 但当前 hash=${i}。主数据在你 read 之后已被修改(外部代码/其他 agent/用户手动改)。`,
|
|
17034
|
-
hint: `重新 read 拿最新值与 hash,基于最新值修改后再写入(传新的 expectedHash)。当前值:${
|
|
17215
|
+
hint: `重新 read 拿最新值与 hash,基于最新值修改后再写入(传新的 expectedHash)。当前值:${sy(a, 400)}`
|
|
17035
17216
|
});
|
|
17036
17217
|
let o = await n.onConflict({
|
|
17037
17218
|
op: e,
|
|
@@ -17041,11 +17222,11 @@ function Gy(e, n = {}) {
|
|
|
17041
17222
|
expectedHash: t,
|
|
17042
17223
|
snapshotId: 0
|
|
17043
17224
|
});
|
|
17044
|
-
if (o.action === "keep_external") return `已保留外部修改(未写入)。当前值:${
|
|
17225
|
+
if (o.action === "keep_external") return `已保留外部修改(未写入)。当前值:${sy(a, 400)} (hash=${i})。请重新 read 拿最新值与 hash 再改。`;
|
|
17045
17226
|
if (o.action === "restore") {
|
|
17046
|
-
if (!c.length) return `无历史快照可回退(本次为首次操作)。当前值:${
|
|
17227
|
+
if (!c.length) return `无历史快照可回退(本次为首次操作)。当前值:${sy(a, 400)} (hash=${i})。请重新 read 再改或选「强制覆盖」。`;
|
|
17047
17228
|
let e = c[c.length - 1];
|
|
17048
|
-
return
|
|
17229
|
+
return dy(a, ry(e.value)), `已回退主数据到历史快照 #${e.id}[${e.op}]。当前值:${sy(a, 400)} (hash=${cy(a)})。请基于回退后的值重写或停止。`;
|
|
17049
17230
|
}
|
|
17050
17231
|
return null;
|
|
17051
17232
|
}
|
|
@@ -17057,15 +17238,15 @@ function Gy(e, n = {}) {
|
|
|
17057
17238
|
}),
|
|
17058
17239
|
r(async ({ jsonPath: e }) => {
|
|
17059
17240
|
let t = e || "";
|
|
17060
|
-
if (!
|
|
17241
|
+
if (!Hy(t, i, s)) return $({
|
|
17061
17242
|
code: "PATH_DENIED",
|
|
17062
17243
|
message: `get_data @ "${t}" 不在 schema 声明字段内(仅 schema 声明的 key 可读)`,
|
|
17063
17244
|
hint: "主数据仅暴露 schema 声明的字段;若需操作该字段,集成方需在 schema 中声明它"
|
|
17064
17245
|
});
|
|
17065
|
-
let n = t ?
|
|
17066
|
-
t || (n =
|
|
17067
|
-
let r =
|
|
17068
|
-
return u = r, n === void 0 ? `主数据${t ? ` @ ${t}` : ""} = (undefined) (hash=${r})` : `主数据${t ? ` @ ${t}` : ""} = ${
|
|
17246
|
+
let n = t ? ey(a, t) : a;
|
|
17247
|
+
t || (n = Ky(n, s));
|
|
17248
|
+
let r = cy(a);
|
|
17249
|
+
return u = r, n === void 0 ? `主数据${t ? ` @ ${t}` : ""} = (undefined) (hash=${r})` : `主数据${t ? ` @ ${t}` : ""} = ${sy(n)} (hash=${r})`;
|
|
17069
17250
|
}, {
|
|
17070
17251
|
name: "get_data",
|
|
17071
17252
|
description: "读取主数据的当前值(安全序列化:函数/DOM/循环引用做摘要;大结果由系统自动外存,提示用 vfs_read 回读)。返回含 hash(乐观锁):改前先 read/get 拿 hash,写入时传 expectedHash 回传,系统对比当前 hash 防\"基于过期值覆盖\"。jsonPath 可选:读整个主数据不传,读子路径传(如 components.0.text)。",
|
|
@@ -17074,27 +17255,19 @@ function Gy(e, n = {}) {
|
|
|
17074
17255
|
r(async ({ value: e, expectedHash: t }) => {
|
|
17075
17256
|
let n = await h("set", t || (d ? u : void 0));
|
|
17076
17257
|
if (n !== null) return n;
|
|
17077
|
-
let r, o =
|
|
17078
|
-
if (o.parseError) return
|
|
17258
|
+
let r, o = iy(e);
|
|
17259
|
+
if (o.parseError) return Xv("", e, o.parseError);
|
|
17079
17260
|
r = o.parsed;
|
|
17080
17261
|
let c = i.safeParse(r);
|
|
17081
|
-
|
|
17082
|
-
if (typeof a != "object" || !a) return $({
|
|
17262
|
+
return c.success ? typeof a != "object" || !a ? $({
|
|
17083
17263
|
code: "LEAF_BIND",
|
|
17084
17264
|
message: `主数据 bind 为原始类型(${a === null ? "null" : typeof a}),set_data 无法就地替换外部持有的值引用`,
|
|
17085
17265
|
hint: "主数据 bind 必须为对象/数组(低代码主 JSON 本就是);叶子值请用对象包裹(如 {value:\"x\"})或集成方通过 sdk.setData 替换 bind"
|
|
17086
|
-
})
|
|
17087
|
-
if (m("set"), c.data !== null && typeof c.data == "object") if (s) {
|
|
17088
|
-
if (Sy(a, c.data), r && typeof r == "object" && !Array.isArray(r)) {
|
|
17089
|
-
let e = new Set(s);
|
|
17090
|
-
for (let [t, n] of Object.entries(r)) e.has(t) || (a[t] = n);
|
|
17091
|
-
}
|
|
17092
|
-
} else Fy(a, c.data);
|
|
17093
|
-
return p({
|
|
17266
|
+
}) : (m("set"), c.data !== null && typeof c.data == "object" && (s ? $v(a, c.data) : fy(a, c.data)), p({
|
|
17094
17267
|
op: "set",
|
|
17095
17268
|
value: c.data,
|
|
17096
17269
|
timestamp: Date.now()
|
|
17097
|
-
}), u =
|
|
17270
|
+
}), u = cy(a), `已设置主数据 = ${sy(c.data, 600)} (新 hash=${cy(a)})${s ? "(白名单模式:仅更新 schema 声明字段,未声明字段保留)" : ""}`) : Yv("", c.error.issues);
|
|
17098
17271
|
}, {
|
|
17099
17272
|
name: "set_data",
|
|
17100
17273
|
description: "设置主数据的值(整体替换)。value 为 JSON 对象(或 JSON 字符串),需通过 schema 校验。校验失败会返回错误而非写入。expectedHash(可选):改前 read/get 返回的 hash,传入则启用乐观锁;不传时系统自动用你最后一次读到的 hash 比对(autoLock,默认开)。大对象/数组强烈建议改用 edit_data 增量 patch。",
|
|
@@ -17105,12 +17278,12 @@ function Gy(e, n = {}) {
|
|
|
17105
17278
|
}),
|
|
17106
17279
|
r(async ({ op: e, jsonPath: t, value: n, expectedHash: r }) => {
|
|
17107
17280
|
let o = t || "";
|
|
17108
|
-
if (
|
|
17281
|
+
if (Qv(o)) return $({
|
|
17109
17282
|
code: "PATH_UNSAFE",
|
|
17110
17283
|
message: `jsonPath "${o}" 含非法段(__proto__/constructor/prototype)`,
|
|
17111
17284
|
hint: "使用正常的属性路径,如 components.0.text(数组索引用数字)"
|
|
17112
17285
|
});
|
|
17113
|
-
if (!
|
|
17286
|
+
if (!Hy(o, i, s)) return $({
|
|
17114
17287
|
code: "PATH_DENIED",
|
|
17115
17288
|
message: `edit_data @ "${o}" 不在 schema 声明字段内`,
|
|
17116
17289
|
hint: "仅 schema 声明的 key 可写;若需操作该字段,集成方需在 schema 中声明它"
|
|
@@ -17129,23 +17302,23 @@ function Gy(e, n = {}) {
|
|
|
17129
17302
|
message: `${e} 操作需要 value`,
|
|
17130
17303
|
hint: `op 为 ${e} 时 value 必填;删除请用 op:'remove'`
|
|
17131
17304
|
});
|
|
17132
|
-
let t =
|
|
17133
|
-
if (t.parseError) return
|
|
17305
|
+
let t = iy(n);
|
|
17306
|
+
if (t.parseError) return Xv("", n, t.parseError);
|
|
17134
17307
|
l = t.parsed;
|
|
17135
17308
|
}
|
|
17136
|
-
let f =
|
|
17309
|
+
let f = ry(a), g = ly(f, e, o, l);
|
|
17137
17310
|
if (g) return $({
|
|
17138
17311
|
code: "PATCH_FAILED",
|
|
17139
17312
|
message: g,
|
|
17140
17313
|
hint: "检查 op 与目标类型:merge 需对象,append 需数组;jsonPath 指向需存在"
|
|
17141
17314
|
});
|
|
17142
17315
|
let _ = i.safeParse(f);
|
|
17143
|
-
return _.success ? (m("edit"),
|
|
17316
|
+
return _.success ? (m("edit"), uy(a, e, o, l), p({
|
|
17144
17317
|
op: "edit",
|
|
17145
17318
|
detail: `${e}${o ? "@" + o : ""}`,
|
|
17146
17319
|
value: l,
|
|
17147
17320
|
timestamp: Date.now()
|
|
17148
|
-
}), u =
|
|
17321
|
+
}), u = cy(a), `已 edit 主数据(${e}${o ? " @ " + o : ""})。当前值:${sy(a, 600)} (新 hash=${cy(a)})`) : Yv("", _.error.issues);
|
|
17149
17322
|
}, {
|
|
17150
17323
|
name: "edit_data",
|
|
17151
17324
|
description: "增量编辑主数据(对象/数组),只发改动的 patch,无需重传整个大对象。op:set(在 jsonPath 设值)、remove(删 jsonPath)、merge(把 value 合并到 jsonPath 指向的对象,默认根)、append(把 value 追加到 jsonPath 指向的数组,默认根)。jsonPath 为相对主数据根的点号路径(数组索引用数字,如 components.0.text);value 为 JSON 对象(推荐直传)或 JSON 字符串。整体仍经 schema 校验,失败不写入。expectedHash(可选):改前 read/get 返回的 hash;不传时自动用你最后读到的 hash(autoLock,默认开)防\"基于过期值覆盖\"。",
|
|
@@ -17167,12 +17340,12 @@ function Gy(e, n = {}) {
|
|
|
17167
17340
|
message: "delete_data 需要 jsonPath 指定要删的子路径(主数据整体不可删,用 set_data 整体替换)",
|
|
17168
17341
|
hint: "如 jsonPath:\"components.0\" 删数组首项"
|
|
17169
17342
|
});
|
|
17170
|
-
if (
|
|
17343
|
+
if (Qv(e)) return $({
|
|
17171
17344
|
code: "PATH_UNSAFE",
|
|
17172
17345
|
message: `jsonPath "${e}" 含非法段`,
|
|
17173
17346
|
hint: "使用正常属性路径"
|
|
17174
17347
|
});
|
|
17175
|
-
if (!
|
|
17348
|
+
if (!Hy(e, i, s)) return $({
|
|
17176
17349
|
code: "PATH_DENIED",
|
|
17177
17350
|
message: `delete_data @ "${e}" 不在 schema 声明字段内`,
|
|
17178
17351
|
hint: "仅 schema 声明的 key 可删"
|
|
@@ -17180,12 +17353,12 @@ function Gy(e, n = {}) {
|
|
|
17180
17353
|
let n = await h("delete", t || (d ? u : void 0));
|
|
17181
17354
|
if (n !== null) return n;
|
|
17182
17355
|
m("delete");
|
|
17183
|
-
let r =
|
|
17356
|
+
let r = ny(a, e);
|
|
17184
17357
|
return p({
|
|
17185
17358
|
op: "delete",
|
|
17186
17359
|
detail: e,
|
|
17187
17360
|
timestamp: Date.now()
|
|
17188
|
-
}), u =
|
|
17361
|
+
}), u = cy(a), r ? `已删除主数据 @ ${e}` : `主数据 @ ${e} 不存在(无需删除)`;
|
|
17189
17362
|
}, {
|
|
17190
17363
|
name: "delete_data",
|
|
17191
17364
|
description: "删除主数据的某个子路径(jsonPath)。主数据整体不可删(用 set_data 整体替换)。expectedHash(可选):改前 read/get 返回的 hash;不传时自动用你最后读到的 hash(autoLock,默认开)防\"基于过期值删除\"。",
|
|
@@ -17224,15 +17397,15 @@ function Gy(e, n = {}) {
|
|
|
17224
17397
|
hint: "用 list_data_snapshots 查看可用快照序号"
|
|
17225
17398
|
});
|
|
17226
17399
|
let n = i.safeParse(t.value);
|
|
17227
|
-
return n.success ? (
|
|
17400
|
+
return n.success ? (dy(a, ry(t.value)), p({
|
|
17228
17401
|
op: "restore",
|
|
17229
17402
|
detail: `#${t.id}`,
|
|
17230
17403
|
timestamp: Date.now()
|
|
17231
|
-
}), u =
|
|
17404
|
+
}), u = cy(a), `已回退主数据到快照 #${t.id}[${t.op}]${t.label ? `(${t.label})` : ""}。`) : $({
|
|
17232
17405
|
code: "SNAPSHOT_SCHEMA_INVALID",
|
|
17233
17406
|
message: `快照 #${t.id} 的值不符合当前 schema,无法回退`,
|
|
17234
17407
|
hint: "schema 可能已变更;该快照已过期,选其他快照或重新设置",
|
|
17235
|
-
details:
|
|
17408
|
+
details: Jv(n.error.issues)
|
|
17236
17409
|
});
|
|
17237
17410
|
}, {
|
|
17238
17411
|
name: "restore_data",
|
|
@@ -17245,9 +17418,9 @@ function Gy(e, n = {}) {
|
|
|
17245
17418
|
message: `主数据不是对象/数组,无法查询(当前为 ${a === void 0 ? "undefined" : typeof a})`,
|
|
17246
17419
|
hint: "query 仅适用于对象/数组;叶子用 get_data 读"
|
|
17247
17420
|
});
|
|
17248
|
-
let n = s ?
|
|
17421
|
+
let n = s ? Ky(a, s) : a, r;
|
|
17249
17422
|
try {
|
|
17250
|
-
r =
|
|
17423
|
+
r = Fy(n, e);
|
|
17251
17424
|
} catch (t) {
|
|
17252
17425
|
return $({
|
|
17253
17426
|
code: "JSONPATH_SYNTAX",
|
|
@@ -17256,7 +17429,7 @@ function Gy(e, n = {}) {
|
|
|
17256
17429
|
details: { expr: e }
|
|
17257
17430
|
});
|
|
17258
17431
|
}
|
|
17259
|
-
let i = t ?? 50, o = r.slice(0, i), c = o.map((e) => `{"path":${JSON.stringify(e.path)},"index":${e.index === void 0 ? "null" : e.index},"value":${
|
|
17432
|
+
let i = t ?? 50, o = r.slice(0, i), c = o.map((e) => `{"path":${JSON.stringify(e.path)},"index":${e.index === void 0 ? "null" : e.index},"value":${sy(e.value)}}`);
|
|
17260
17433
|
return `{"matched":${r.length},"returned":${o.length},"truncated":${r.length > i},"results":[${c.join(",")}]}`;
|
|
17261
17434
|
}, {
|
|
17262
17435
|
name: "query_data",
|
|
@@ -17272,13 +17445,13 @@ function Gy(e, n = {}) {
|
|
|
17272
17445
|
message: "主数据为空,无可搜索内容"
|
|
17273
17446
|
});
|
|
17274
17447
|
try {
|
|
17275
|
-
let o =
|
|
17448
|
+
let o = Ly(s ? Ky(a, s) : a, e, {
|
|
17276
17449
|
mode: t,
|
|
17277
17450
|
fuzzyThreshold: n,
|
|
17278
17451
|
matchKey: r,
|
|
17279
17452
|
limit: i ?? 50
|
|
17280
17453
|
});
|
|
17281
|
-
return
|
|
17454
|
+
return sy({
|
|
17282
17455
|
matched: o.length,
|
|
17283
17456
|
results: o
|
|
17284
17457
|
});
|
|
@@ -17311,7 +17484,7 @@ function Gy(e, n = {}) {
|
|
|
17311
17484
|
message: `脚本过长(${e.length} 字符,上限 8000)`,
|
|
17312
17485
|
hint: "精简脚本;复杂逻辑可分步(先 query 探查再 transform 改),或拆成多次 eval"
|
|
17313
17486
|
});
|
|
17314
|
-
let n = await
|
|
17487
|
+
let n = await By(ry(s ? Ky(a, s) : a), e, 3e3);
|
|
17315
17488
|
if (!n.ok) {
|
|
17316
17489
|
let t = /超时/.test(n.error || "");
|
|
17317
17490
|
return $({
|
|
@@ -17332,15 +17505,15 @@ function Gy(e, n = {}) {
|
|
|
17332
17505
|
message: `主数据 bind 为原始类型(${a === null ? "null" : typeof a}),eval transform(patches) 无法就地替换`,
|
|
17333
17506
|
hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹或集成方通过 sdk.setData 替换 bind"
|
|
17334
17507
|
});
|
|
17335
|
-
let t = e.patches, r =
|
|
17508
|
+
let t = e.patches, r = ry(a), o = [];
|
|
17336
17509
|
for (let e = 0; e < t.length; e++) {
|
|
17337
17510
|
let n = t[e], a = n.jsonPath || "";
|
|
17338
|
-
if (
|
|
17511
|
+
if (Qv(a)) return $({
|
|
17339
17512
|
code: "PATH_UNSAFE",
|
|
17340
17513
|
message: `patches[${e}] jsonPath "${a}" 含非法段`,
|
|
17341
17514
|
hint: "使用正常属性路径"
|
|
17342
17515
|
});
|
|
17343
|
-
if (!
|
|
17516
|
+
if (!Hy(a, i, s)) return $({
|
|
17344
17517
|
code: "PATH_DENIED",
|
|
17345
17518
|
message: `patches[${e}] @ "${a}" 不在 schema 声明字段内`,
|
|
17346
17519
|
hint: "仅 schema 声明的 key 可写"
|
|
@@ -17352,11 +17525,11 @@ function Gy(e, n = {}) {
|
|
|
17352
17525
|
message: `patches[${e}] ${c} 操作需要 value`,
|
|
17353
17526
|
hint: `op 为 ${c} 时 value 必填`
|
|
17354
17527
|
});
|
|
17355
|
-
let t =
|
|
17356
|
-
if (t.parseError) return
|
|
17528
|
+
let t = iy(n.value);
|
|
17529
|
+
if (t.parseError) return Xv(`patches[${e}]`, n.value, t.parseError);
|
|
17357
17530
|
l = t.parsed;
|
|
17358
17531
|
}
|
|
17359
|
-
let u =
|
|
17532
|
+
let u = ly(r, c, a, l);
|
|
17360
17533
|
if (u) return $({
|
|
17361
17534
|
code: "PATCH_FAILED",
|
|
17362
17535
|
message: `patches[${e}]: ${u}`,
|
|
@@ -17373,33 +17546,33 @@ function Gy(e, n = {}) {
|
|
|
17373
17546
|
code: "SCHEMA_INVALID",
|
|
17374
17547
|
message: "脚本 patches 应用后整体校验失败,未写入",
|
|
17375
17548
|
hint: "确认 patches 合并后整体仍符合 schema",
|
|
17376
|
-
details:
|
|
17549
|
+
details: Jv(c.error.issues)
|
|
17377
17550
|
});
|
|
17378
17551
|
m("edit", "eval_transform");
|
|
17379
|
-
for (let e of o)
|
|
17552
|
+
for (let e of o) uy(a, e.op, e.jp, e.value);
|
|
17380
17553
|
return p({
|
|
17381
17554
|
op: "edit",
|
|
17382
17555
|
detail: `eval_transform(${o.length} patches)`,
|
|
17383
17556
|
timestamp: Date.now()
|
|
17384
|
-
}), u =
|
|
17557
|
+
}), u = cy(a), `已通过脚本 transform(patches) 更新主数据(${o.length} 个 patch,耗时 ${n.elapsedMs}ms)。当前值: ${sy(a, 600)}`;
|
|
17385
17558
|
}
|
|
17386
17559
|
let t = i.safeParse(e);
|
|
17387
17560
|
return t.success ? typeof a != "object" || !a ? $({
|
|
17388
17561
|
code: "LEAF_BIND",
|
|
17389
17562
|
message: `主数据 bind 为原始类型(${a === null ? "null" : typeof a}),eval transform 无法就地替换外部持有的值引用`,
|
|
17390
17563
|
hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹或集成方通过 sdk.setData 替换 bind"
|
|
17391
|
-
}) : (m("edit", "eval_transform"), t.data !== null && typeof t.data == "object" && (s ?
|
|
17564
|
+
}) : (m("edit", "eval_transform"), t.data !== null && typeof t.data == "object" && (s ? $v(a, t.data) : fy(a, t.data)), p({
|
|
17392
17565
|
op: "edit",
|
|
17393
17566
|
detail: "eval_transform",
|
|
17394
17567
|
timestamp: Date.now()
|
|
17395
|
-
}), u =
|
|
17568
|
+
}), u = cy(a), `已通过脚本 transform 更新主数据(耗时 ${n.elapsedMs}ms)。当前值: ${sy(a, 600)}`) : $({
|
|
17396
17569
|
code: "SCHEMA_INVALID",
|
|
17397
17570
|
message: "脚本返回值校验失败,未写入(transform 模式要求返回主数据的完整新值且符合 schema)",
|
|
17398
17571
|
hint: "确认脚本 return 了完整新值(非部分);或返回 {patches:[...]} 走增量模式;按 describe_data() 查看格式",
|
|
17399
|
-
details:
|
|
17572
|
+
details: Jv(t.error.issues)
|
|
17400
17573
|
});
|
|
17401
17574
|
}
|
|
17402
|
-
return
|
|
17575
|
+
return sy({
|
|
17403
17576
|
ok: !0,
|
|
17404
17577
|
result: n.result,
|
|
17405
17578
|
elapsedMs: n.elapsedMs
|
|
@@ -17414,16 +17587,16 @@ function Gy(e, n = {}) {
|
|
|
17414
17587
|
}),
|
|
17415
17588
|
r(async ({ jsonPath: e, fields: t, depth: r }) => {
|
|
17416
17589
|
let c = e || "";
|
|
17417
|
-
if (!
|
|
17590
|
+
if (!Hy(c, i, s)) return $({
|
|
17418
17591
|
code: "PATH_DENIED",
|
|
17419
17592
|
message: `read @ "${c}" 不在 schema 声明字段内`,
|
|
17420
17593
|
hint: "主数据仅暴露 schema 声明的字段;若需操作该字段,集成方需在 schema 中声明它"
|
|
17421
17594
|
});
|
|
17422
|
-
let l = c ?
|
|
17423
|
-
if (!c) l =
|
|
17595
|
+
let l = c ? ey(a, c) : a;
|
|
17596
|
+
if (!c) l = Ky(l, s);
|
|
17424
17597
|
else if (s) {
|
|
17425
|
-
let e =
|
|
17426
|
-
e && (l =
|
|
17598
|
+
let e = Wy(i, c);
|
|
17599
|
+
e && (l = Gy(l, e));
|
|
17427
17600
|
}
|
|
17428
17601
|
let d = l;
|
|
17429
17602
|
if (n.interceptors?.read) try {
|
|
@@ -17434,11 +17607,11 @@ function Gy(e, n = {}) {
|
|
|
17434
17607
|
message: `read 拦截器抛错: ${e.message}`
|
|
17435
17608
|
});
|
|
17436
17609
|
}
|
|
17437
|
-
t && t.length && (d =
|
|
17438
|
-
let f =
|
|
17610
|
+
t && t.length && (d = ay(d, t)), r != null && (d = oy(d, r));
|
|
17611
|
+
let f = cy(a);
|
|
17439
17612
|
u = f;
|
|
17440
17613
|
let p = t && t.length ? `(字段裁剪:${t.join(",")})` : "", m = r == null ? "" : `(深度≤${r})`, h = p || m ? ` ${p}${m}` : "", g = e ? "" : `主数据说明: ${o}\n格式: 写入值需为 JSON,且通过声明的 schema 校验(校验失败时 write 会返回结构化错误)。\n\n`;
|
|
17441
|
-
return d === void 0 ? `${g}主数据${e ? ` @ ${e}` : ""}${h} = (undefined) (hash=${f})` : `${g}主数据${e ? ` @ ${e}` : ""}${h} = ${
|
|
17614
|
+
return d === void 0 ? `${g}主数据${e ? ` @ ${e}` : ""}${h} = (undefined) (hash=${f})` : `${g}主数据${e ? ` @ ${e}` : ""}${h} = ${sy(d)} (hash=${f})`;
|
|
17442
17615
|
}, {
|
|
17443
17616
|
name: "read",
|
|
17444
17617
|
description: "读取主数据(高层入口,合并 describe/get)。不传 jsonPath → 返回主数据说明 + 格式提示;传 jsonPath → 返回该子路径当前值 + hash。hash 用于乐观锁(默认 autoLock,write 时自动比对,无需手动传)。fields(可选):字段裁剪,只返回对象(及数组元素)的指定字段,减少大对象返回体积;depth(可选):嵌套深度限制(0=只根占位,1=根+子,递归截断深层),减少深层结构返回体积。两者可组合,先裁字段再截深度。集成方可能经 read 拦截器对返回值脱敏/派生。",
|
|
@@ -17484,12 +17657,12 @@ function Gy(e, n = {}) {
|
|
|
17484
17657
|
message: "delete 需要 patch.jsonPath 指定要删的子路径(主数据整体不可删,用 write(value) 整体替换)",
|
|
17485
17658
|
hint: "如 patch:{jsonPath:\"components.0\"}, del:true"
|
|
17486
17659
|
});
|
|
17487
|
-
if (
|
|
17660
|
+
if (Qv(t.jsonPath)) return $({
|
|
17488
17661
|
code: "PATH_UNSAFE",
|
|
17489
17662
|
message: `jsonPath "${t.jsonPath}" 含非法段`,
|
|
17490
17663
|
hint: "使用正常属性路径"
|
|
17491
17664
|
});
|
|
17492
|
-
if (!
|
|
17665
|
+
if (!Hy(t.jsonPath, i, s)) return $({
|
|
17493
17666
|
code: "PATH_DENIED",
|
|
17494
17667
|
message: `write delete @ "${t.jsonPath}" 不在 schema 声明字段内`,
|
|
17495
17668
|
hint: "仅 schema 声明的 key 可删"
|
|
@@ -17497,12 +17670,12 @@ function Gy(e, n = {}) {
|
|
|
17497
17670
|
let e = await h("delete", g);
|
|
17498
17671
|
if (e !== null) return e;
|
|
17499
17672
|
m("delete");
|
|
17500
|
-
let n =
|
|
17673
|
+
let n = ny(a, t.jsonPath);
|
|
17501
17674
|
return p({
|
|
17502
17675
|
op: "delete",
|
|
17503
17676
|
detail: t.jsonPath,
|
|
17504
17677
|
timestamp: Date.now()
|
|
17505
|
-
}), u =
|
|
17678
|
+
}), u = cy(a), n ? `已删除主数据 @ ${t.jsonPath}` : `主数据 @ ${t.jsonPath} 不存在(无需删除)`;
|
|
17506
17679
|
}
|
|
17507
17680
|
if (c === "edit") {
|
|
17508
17681
|
if (typeof a != "object" || !a) return $({
|
|
@@ -17516,15 +17689,15 @@ function Gy(e, n = {}) {
|
|
|
17516
17689
|
op: t.op,
|
|
17517
17690
|
jsonPath: t.jsonPath || "",
|
|
17518
17691
|
value: l
|
|
17519
|
-
}]), o =
|
|
17692
|
+
}]), o = ry(a), c = [];
|
|
17520
17693
|
for (let e = 0; e < n.length; e++) {
|
|
17521
17694
|
let t = n[e], r = t.jsonPath || "";
|
|
17522
|
-
if (
|
|
17695
|
+
if (Qv(r)) return $({
|
|
17523
17696
|
code: "PATH_UNSAFE",
|
|
17524
17697
|
message: `patches[${e}] jsonPath "${r}" 含非法段`,
|
|
17525
17698
|
hint: "使用正常属性路径,如 components.0.text"
|
|
17526
17699
|
});
|
|
17527
|
-
if (!
|
|
17700
|
+
if (!Hy(r, i, s)) return $({
|
|
17528
17701
|
code: "PATH_DENIED",
|
|
17529
17702
|
message: `patches[${e}] @ "${r}" 不在 schema 声明字段内`,
|
|
17530
17703
|
hint: "仅 schema 声明的 key 可写"
|
|
@@ -17536,11 +17709,11 @@ function Gy(e, n = {}) {
|
|
|
17536
17709
|
message: `patches[${e}] ${a} 操作需要 value`,
|
|
17537
17710
|
hint: `op 为 ${a} 时 value 必填;删除请用 op:'remove'`
|
|
17538
17711
|
});
|
|
17539
|
-
let n =
|
|
17540
|
-
if (n.parseError) return
|
|
17712
|
+
let n = iy(t.value);
|
|
17713
|
+
if (n.parseError) return Xv(`patches[${e}]`, t.value, n.parseError);
|
|
17541
17714
|
l = n.parsed;
|
|
17542
17715
|
}
|
|
17543
|
-
let u =
|
|
17716
|
+
let u = ly(o, a, r, l);
|
|
17544
17717
|
if (u) return $({
|
|
17545
17718
|
code: "PATCH_FAILED",
|
|
17546
17719
|
message: `patches[${e}]: ${u}`,
|
|
@@ -17553,39 +17726,31 @@ function Gy(e, n = {}) {
|
|
|
17553
17726
|
});
|
|
17554
17727
|
}
|
|
17555
17728
|
let d = i.safeParse(o);
|
|
17556
|
-
if (!d.success) return
|
|
17729
|
+
if (!d.success) return Yv("", d.error.issues);
|
|
17557
17730
|
m("edit");
|
|
17558
|
-
for (let e of c)
|
|
17731
|
+
for (let e of c) uy(a, e.op, e.jp, e.value);
|
|
17559
17732
|
return p({
|
|
17560
17733
|
op: "edit",
|
|
17561
17734
|
detail: `${c.length} 个 patch${c.length > 1 ? "(批量)" : ""}`,
|
|
17562
17735
|
value: c.map((e) => `${e.op}@${e.jp}`),
|
|
17563
17736
|
timestamp: Date.now()
|
|
17564
|
-
}), u =
|
|
17737
|
+
}), u = cy(a), `已 write(edit) 主数据(${c.length} 个 patch)。当前值:${sy(a, 600)} (新 hash=${cy(a)})`;
|
|
17565
17738
|
}
|
|
17566
|
-
let _, v =
|
|
17567
|
-
if (v.parseError) return
|
|
17739
|
+
let _, v = iy(l);
|
|
17740
|
+
if (v.parseError) return Xv("", l, v.parseError);
|
|
17568
17741
|
_ = v.parsed;
|
|
17569
17742
|
let y = await h("set", g);
|
|
17570
17743
|
if (y !== null) return y;
|
|
17571
17744
|
let b = i.safeParse(_);
|
|
17572
|
-
|
|
17573
|
-
if (typeof a != "object" || !a) return $({
|
|
17745
|
+
return b.success ? typeof a != "object" || !a ? $({
|
|
17574
17746
|
code: "LEAF_BIND",
|
|
17575
17747
|
message: `主数据 bind 为原始类型(${a === null ? "null" : typeof a}),write(set) 无法就地替换外部持有的值引用`,
|
|
17576
17748
|
hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹(如 {value:\"x\"})或集成方通过 sdk.setData 替换 bind"
|
|
17577
|
-
})
|
|
17578
|
-
if (m("set"), b.data !== null && typeof b.data == "object") if (s) {
|
|
17579
|
-
if (Sy(a, b.data), _ && typeof _ == "object" && !Array.isArray(_)) {
|
|
17580
|
-
let e = new Set(s);
|
|
17581
|
-
for (let [t, n] of Object.entries(_)) e.has(t) || (a[t] = n);
|
|
17582
|
-
}
|
|
17583
|
-
} else Fy(a, b.data);
|
|
17584
|
-
return p({
|
|
17749
|
+
}) : (m("set"), b.data !== null && typeof b.data == "object" && (s ? $v(a, b.data) : fy(a, b.data)), p({
|
|
17585
17750
|
op: "set",
|
|
17586
17751
|
value: b.data,
|
|
17587
17752
|
timestamp: Date.now()
|
|
17588
|
-
}), u =
|
|
17753
|
+
}), u = cy(a), `已 write(set) 主数据 = ${sy(b.data, 600)} (新 hash=${cy(a)})${s ? "(白名单模式:仅更新 schema 声明字段,未声明字段保留)" : ""}`) : Yv("", b.error.issues);
|
|
17589
17754
|
}, {
|
|
17590
17755
|
name: "write",
|
|
17591
17756
|
description: "写入主数据(高层入口,合并 set/edit/delete + 自动乐观锁 + 自动快照)。四种意图:① 整体替换 write({ value }) value 为 JSON 对象(推荐)或字符串;② 单个增量 patch write({ value, patch:{op,jsonPath} }) op=set/remove/merge/append,jsonPath 相对主数据根(如 components.0.text),value 作为该 patch 的值;③ 批量增量 write({ patches:[{op,jsonPath,value},...] }) 一次原子应用多个 patch(任一失败整体不写入,适合一次改多处);④ 删除 write({ patch:{jsonPath}, del:true })。写入自动经 schema 校验(失败不写)+ 自动存快照(可 restore_data 回退)+ 自动乐观锁(autoLock,用你最后 read 到的 hash 比对,冲突则 VERSION_CONFLICT)。集成方可能经 write 拦截器校验/转换/拒绝(批量模式拦截器收到 {patches},返回新 patches 数组或 {error})。",
|
|
@@ -17623,8 +17788,8 @@ function Gy(e, n = {}) {
|
|
|
17623
17788
|
}
|
|
17624
17789
|
//#endregion
|
|
17625
17790
|
//#region src/core/tools/fetchDoc.ts
|
|
17626
|
-
var
|
|
17627
|
-
let n = new AbortController(), r = setTimeout(() => n.abort(),
|
|
17791
|
+
var Zy = 3e4, Qy = [r(async ({ url: e, as: t }) => {
|
|
17792
|
+
let n = new AbortController(), r = setTimeout(() => n.abort(), Zy);
|
|
17628
17793
|
try {
|
|
17629
17794
|
let r = await fetch(e, {
|
|
17630
17795
|
method: "GET",
|
|
@@ -17641,7 +17806,7 @@ var Ky = 3e4, qy = [r(async ({ url: e, as: t }) => {
|
|
|
17641
17806
|
].join("\n");
|
|
17642
17807
|
} catch (t) {
|
|
17643
17808
|
let r = t?.message || String(t);
|
|
17644
|
-
return n.signal.aborted ? `获取失败:请求超时(${
|
|
17809
|
+
return n.signal.aborted ? `获取失败:请求超时(${Zy}ms,${e})。` : /Failed to fetch|NetworkError|CORS|blocked/i.test(r) ? `获取失败:可能是 CORS 跨域拦截或网络错误(${r})。浏览器仅能 GET 同源或服务端已配置 CORS 的资源;跨域抓取需后端代理。` : `获取失败:${r}`;
|
|
17645
17810
|
} finally {
|
|
17646
17811
|
clearTimeout(r);
|
|
17647
17812
|
}
|
|
@@ -17652,25 +17817,25 @@ var Ky = 3e4, qy = [r(async ({ url: e, as: t }) => {
|
|
|
17652
17817
|
url: t.string().describe("要抓取的 URL(同源或已配 CORS)"),
|
|
17653
17818
|
as: t.enum(["text", "markdown"]).optional().describe("返回格式标签,默认 text")
|
|
17654
17819
|
})
|
|
17655
|
-
})],
|
|
17656
|
-
function
|
|
17657
|
-
return
|
|
17820
|
+
})], $y = Qy;
|
|
17821
|
+
function eb(e, t) {
|
|
17822
|
+
return Xy(e, t);
|
|
17658
17823
|
}
|
|
17659
|
-
function
|
|
17824
|
+
function tb(e, t, n) {
|
|
17660
17825
|
let r = e?.dataOps !== !1, i = e?.fetch !== !1;
|
|
17661
17826
|
return [...r ? t : [], ...i ? n : []];
|
|
17662
17827
|
}
|
|
17663
17828
|
//#endregion
|
|
17664
17829
|
//#region src/core/harness/usageHints.ts
|
|
17665
|
-
var
|
|
17666
|
-
function
|
|
17830
|
+
var nb = .7;
|
|
17831
|
+
function rb(e, t, n = "simple") {
|
|
17667
17832
|
let r = n !== "advanced";
|
|
17668
17833
|
return {
|
|
17669
17834
|
name: "usageHints",
|
|
17670
17835
|
augmentPrompt: () => {
|
|
17671
17836
|
let n = [];
|
|
17672
17837
|
if (e?.planning !== !1 && n.push("多步任务建议先 write_todos 拆解为步骤并逐步推进。"), t && (r ? (n.push("读写主数据用 read/write(高层入口,自动乐观锁 + 自动快照)。read({jsonPath}) 读子路径当前值(返回含 hash,write 时自动比对,无需手动传);read() 不传读整个主数据 + 说明。write({value}) 整体替换(value 直传 JSON 对象,如 {title:\"x\"},无需 stringify);write({value, patch:{op,jsonPath}}) 增量 patch(op=set/remove/merge/append);write({patch:{jsonPath}, del:true}) 删除子路径。写入自动经 schema 校验(失败不写)+ 自动存快照(出错可用 restore_data 回退)。"), n.push("修改大对象/数组优先用 write 的 patch 增量(只发改动部分),避免整体重传被 max_tokens 截断致 JSON 不完整。"), n.push("在大数组里按条件筛选用 query_data(JSONPath,如 $.components[?(@.type==\"card\" && @.price<100)]),返回匹配元素 path/index;定位后用 write patch 改。找名字记不清的元素用 search_data(substring/regex/fuzzy)。批量过滤/映射/聚合/重写大数组用 eval_script(沙箱脚本,mode=query 只读/transform 落地)。")) : (n.push("改主数据前先 get_data({jsonPath}) 读其当前真实值与 hash(返回末尾 hash=xxx),基于真实值改,不要凭记忆。写入(set/edit/delete)时回传 expectedHash=该 hash 启用乐观锁——若主数据在你 get 之后被外部代码/其他 agent/用户手动改过,会触发冲突:集成方若开启人工介入,工具会挂起等用户决定(保留外部/强制覆盖/回退),你应等待工具返回后按结果继续(保留外部→重新 get 再改;强制覆盖→已写入,继续;回退→已回退到历史快照,基于回退值重写);未开启人工介入时返回 VERSION_CONFLICT 不写入,重新 get 拿最新值与 hash 再改。"), n.push("不确定主数据字段结构时用 describe_data 查看说明。"), n.push("修改大对象/数组优先用 edit_data 增量 patch(只发改动部分),避免 set_data 整体重传被 max_tokens 截断导致 JSON 不完整、校验失败。"), n.push("修改主数据出错时可用 restore_data 回退最近一次。"), n.push("在大数组里按条件筛选元素用 query_data(JSONPath,如 $.components[?(@.type==\"card\" && @.price<100)]),返回匹配元素的 path/index;定位后再 edit_data 改。"), n.push("找名字记不清的元素用 search_data(支持 substring/regex/fuzzy 模糊搜索)。"), n.push("需要过滤/映射/聚合/批量重写大数组时用 eval_script(沙箱脚本,入参 data);只读探查用 mode=query,批量重写用 mode=transform(返回值经校验后落地)。"))), e?.subagent !== !1 && n.push("独立子任务可 spawn_agent 委派(只读工具,过程不占主上下文)。"), e?.subagents?.length) {
|
|
17673
|
-
let t = e.subagents.filter((e) => (e.temperature ?? 0) >=
|
|
17838
|
+
let t = e.subagents.filter((e) => (e.temperature ?? 0) >= nb || /规划|创意|设计|方案|brainstorm|plan/i.test(e.description)), i = e.subagents.filter((e) => (e.temperature ?? 0) < nb && /反思|审查|挑刺|校验|review|critique|reflect/i.test(e.description));
|
|
17674
17839
|
n.push("【规划-反思-执行·路由】按任务性质选模式,不要对简单任务过度编排:"), t.length && (n.push(` · 创作/设计/开放性需求(如"设计主题风格""换个感觉")→ 先调 ${t.map((e) => "use_" + e.id).join("/")} 出 2-3 套方案(高温创意),`), n.push(" 不要自己拍板;拿到方案后,若需用户拍板用 request_human_confirmation 弹选项。")), i.length && n.push(` · 严谨/易错/校验类 → 可先调 ${i.map((e) => "use_" + e.id).join("/")} 反思挑刺(低温审查),据反馈修订。`), n.push(r ? " · 方案定稿后,由你(主 agent)用 write 落地成 JSON(低温度执行 + schema 校验 + 写前确认)。" : " · 方案定稿后,由你(主 agent)用 edit_data 落地成 JSON(低温度执行 + schema 校验 + 写前确认)。"), n.push(" · 简单/明确任务(如\"标题改红色\")直接执行,不必走规划-反思。");
|
|
17675
17840
|
}
|
|
17676
17841
|
return e?.humanConfirm && (n.push("【人工确认·必读】以下情形必须先调 request_human_confirmation 征询用户、拿到答复后再继续,不要自行拍板:"), n.push(" 1) 用户让你「给方案/列选项/我来选/挑一个」时:把每个方案作为一个 option,调 request_human_confirmation(question=简述, options=[方案A,方案B,...], recommendation=你推荐的)。不要只回文字罗列方案让用户自己回复——要用工具把选项做成可点选按钮。"), n.push(" 2) 需求有歧义/不确定时:调工具问清楚(options 不传则用户答同意或拒绝)。"), n.push(" 3) 即将执行高风险不可逆操作(删除/覆盖/批量改动)前:调工具确认。"), n.push("用户在选项里选了哪个,就按那个方案继续;选「拒绝」则停止并询问如何调整。")), n.length && n.unshift("调用工具务必用标准 function calling(工具调用)格式发起,不要在回复正文里输出伪 XML/标签(如 deepseek 的 tool_calls 标签、invoke、function_call、tool_call 等)或 JSON 文本——那不会被识别为工具调用,会被当普通文字,工具不执行。"), n.length ? "## 能力使用提示\n" + n.join("\n") : void 0;
|
|
@@ -17679,15 +17844,15 @@ function Qy(e, t, n = "simple") {
|
|
|
17679
17844
|
}
|
|
17680
17845
|
//#endregion
|
|
17681
17846
|
//#region src/core/backends/skillStore.ts
|
|
17682
|
-
var
|
|
17683
|
-
function
|
|
17684
|
-
return `${
|
|
17847
|
+
var ib = "v:1::skill-store", ab = "chat-sdk";
|
|
17848
|
+
function ob(e, t, n) {
|
|
17849
|
+
return `${ib}::${e}::${t}::${n}`;
|
|
17685
17850
|
}
|
|
17686
|
-
function
|
|
17687
|
-
return `${
|
|
17851
|
+
function sb(e, t) {
|
|
17852
|
+
return `${ib}::${e}::${t}::`;
|
|
17688
17853
|
}
|
|
17689
|
-
function
|
|
17690
|
-
let t = e.dbName ??
|
|
17854
|
+
function cb(e = {}) {
|
|
17855
|
+
let t = e.dbName ?? ab, n = e.backend ?? "indexed", r = e.id ?? "", i, a, o = new Promise((e) => {
|
|
17691
17856
|
a = e;
|
|
17692
17857
|
});
|
|
17693
17858
|
return (async () => {
|
|
@@ -17709,42 +17874,42 @@ function rb(e = {}) {
|
|
|
17709
17874
|
ready: o,
|
|
17710
17875
|
async list() {
|
|
17711
17876
|
let e = [];
|
|
17712
|
-
return await i.scan(
|
|
17877
|
+
return await i.scan(sb(t, r), (t, n) => {
|
|
17713
17878
|
e.push(n);
|
|
17714
17879
|
}), e;
|
|
17715
17880
|
},
|
|
17716
17881
|
async get(e) {
|
|
17717
|
-
return await i.get(
|
|
17882
|
+
return await i.get(ob(t, r, e));
|
|
17718
17883
|
},
|
|
17719
17884
|
async put(e) {
|
|
17720
17885
|
try {
|
|
17721
|
-
await i.set(
|
|
17886
|
+
await i.set(ob(t, r, e.name), e);
|
|
17722
17887
|
} catch (e) {
|
|
17723
17888
|
kv(e) && (i = Lv());
|
|
17724
17889
|
}
|
|
17725
17890
|
},
|
|
17726
17891
|
async remove(e) {
|
|
17727
|
-
let n =
|
|
17728
|
-
return await i.get(n)
|
|
17892
|
+
let n = ob(t, r, e);
|
|
17893
|
+
return await i.get(n) != null && (await i.del(n), !0);
|
|
17729
17894
|
},
|
|
17730
17895
|
async clear() {
|
|
17731
|
-
await i.clearPrefix(
|
|
17896
|
+
await i.clearPrefix(sb(t, r));
|
|
17732
17897
|
},
|
|
17733
17898
|
dispose() {}
|
|
17734
17899
|
};
|
|
17735
17900
|
}
|
|
17736
17901
|
//#endregion
|
|
17737
17902
|
//#region src/core/sdk/createChatSdk.ts
|
|
17738
|
-
var
|
|
17739
|
-
function
|
|
17903
|
+
var lb = 50, ub = /* @__PURE__ */ new Map();
|
|
17904
|
+
function db(e, t) {
|
|
17740
17905
|
return e === "set_data" ? "set" : e === "edit_data" ? "edit" : e === "delete_data" ? "delete" : e === "restore_data" ? "restore" : e === "write" ? t?.del ? "delete" : t?.patch ? "edit" : "set" : null;
|
|
17741
17906
|
}
|
|
17742
|
-
function
|
|
17907
|
+
function fb(e, t, n, r) {
|
|
17743
17908
|
let i = 0;
|
|
17744
17909
|
return {
|
|
17745
17910
|
name: "sdk-events",
|
|
17746
17911
|
wrapToolCall: async (t, r) => {
|
|
17747
|
-
let i = await r(t), a =
|
|
17912
|
+
let i = await r(t), a = db(t.name, t.args);
|
|
17748
17913
|
return a && e({
|
|
17749
17914
|
type: "data_change",
|
|
17750
17915
|
operation: a,
|
|
@@ -17779,7 +17944,7 @@ function sb(e, t, n, r) {
|
|
|
17779
17944
|
}
|
|
17780
17945
|
};
|
|
17781
17946
|
}
|
|
17782
|
-
function
|
|
17947
|
+
function pb(e, i) {
|
|
17783
17948
|
let a = {
|
|
17784
17949
|
prompt_tokens: 0,
|
|
17785
17950
|
completion_tokens: 0,
|
|
@@ -17790,11 +17955,12 @@ function cb(e, i) {
|
|
|
17790
17955
|
e.debug && console.log("[page-agent-sdk][modelCaps]", d);
|
|
17791
17956
|
let f = e.llm;
|
|
17792
17957
|
e.debug && !u && console.warn("[page-agent-sdk][summarization] 未构造 llmInvoke(apiKey 缺失?),摘要回退零成本索引摘要");
|
|
17793
|
-
let p = /* @__PURE__ */ tn([]), m =
|
|
17958
|
+
let p = /* @__PURE__ */ tn([]), m = gy(e.vfs?.initialFiles, {
|
|
17794
17959
|
persist: c ? { save: (e) => {
|
|
17795
17960
|
z.sessionId && c && c.save(i, z.sessionId, { vfs: e });
|
|
17796
17961
|
} } : void 0,
|
|
17797
|
-
maxBytes: e.vfs?.maxBytes
|
|
17962
|
+
maxBytes: e.vfs?.maxBytes,
|
|
17963
|
+
poolBytes: e.vfs?.poolBytes
|
|
17798
17964
|
}), h = Kg(), g = e_(e.memory || "");
|
|
17799
17965
|
typeof e.memory == "function" && g.refresh();
|
|
17800
17966
|
let _ = { current: null }, v = e.data ? {
|
|
@@ -17808,13 +17974,13 @@ function cb(e, i) {
|
|
|
17808
17974
|
getTodos: () => _.current?.getState?.()?.todos ?? [],
|
|
17809
17975
|
messages: p,
|
|
17810
17976
|
maxCheckpoints: y && typeof y == "object" ? y.maxCheckpoints : void 0
|
|
17811
|
-
}) : null, S = !y || typeof y != "object" || y.auto !== !1, C = e.capabilities, w = C?.dataOps !== !1, T = dv(e), E = w && v ?
|
|
17977
|
+
}) : null, S = !y || typeof y != "object" || y.auto !== !1, C = e.capabilities, w = C?.dataOps !== !1, T = dv(e), E = w && v ? Xy(v, {
|
|
17812
17978
|
onAudit: e.onAudit ?? (e.debug ? (e) => console.log("[page-agent-sdk][data audit]", e) : void 0),
|
|
17813
17979
|
maxSnapshots: e.maxSnapshots,
|
|
17814
17980
|
onConflict: o.set,
|
|
17815
17981
|
autoLock: e.autoLock,
|
|
17816
17982
|
interceptors: e.interceptors
|
|
17817
|
-
}) : [], D = w ?
|
|
17983
|
+
}) : [], D = w ? Yy(E, e.toolMode) : [], O = w && v ? E.controller ?? null : null, k = () => O?.get() ?? v, A = /* @__PURE__ */ new Map(), j = tb(C, D, Qy);
|
|
17818
17984
|
j.forEach((e) => A.set(e.name, "builtin"));
|
|
17819
17985
|
let M = [...e.tools || []];
|
|
17820
17986
|
M.forEach((e) => A.set(e.name, "user"));
|
|
@@ -17851,7 +18017,9 @@ function cb(e, i) {
|
|
|
17851
18017
|
...ee
|
|
17852
18018
|
];
|
|
17853
18019
|
}
|
|
17854
|
-
let ne = C?.planning !== !1, re = C?.skills !== !1, ie = C?.vfs !== !1
|
|
18020
|
+
let ne = C?.planning !== !1, re = C?.skills !== !1, ie = C?.vfs !== !1;
|
|
18021
|
+
if (ie) for (let e of Cy) A.set(e, "builtin");
|
|
18022
|
+
let ae = C?.summarization !== !1, oe = C?.memory !== !1, se = C?.subagent !== !1, ce = e.verify?.maxAttempts ?? 2, le = C?.verify === !0 && e.verify?.enabled !== !1 && ce > 0;
|
|
17855
18023
|
e.verify?.check && C?.verify !== !0 && console.warn("[page-agent-sdk][verify] 检测到 verify.check 但 capabilities.verify 未开启,verify 未装载");
|
|
17856
18024
|
let ue = e.subagent, L = ue?.allowedTools ?? [], de = !se || ue?.enabled === !1 ? void 0 : E_({
|
|
17857
18025
|
llm: ue?.llm ?? e.llm,
|
|
@@ -17882,7 +18050,7 @@ function cb(e, i) {
|
|
|
17882
18050
|
llm: e.llm,
|
|
17883
18051
|
tools: he
|
|
17884
18052
|
} : void 0
|
|
17885
|
-
}) : void 0, _e =
|
|
18053
|
+
}) : void 0, _e = rb({
|
|
17886
18054
|
...C,
|
|
17887
18055
|
humanConfirm: N,
|
|
17888
18056
|
subagents: e.subagents?.map((e) => ({
|
|
@@ -17914,7 +18082,7 @@ function cb(e, i) {
|
|
|
17914
18082
|
name: e.name,
|
|
17915
18083
|
description: e.description,
|
|
17916
18084
|
getContent: () => e.content
|
|
17917
|
-
}), R = e.skillStorage === !1 ? null :
|
|
18085
|
+
}), R = e.skillStorage === !1 ? null : cb({
|
|
17918
18086
|
...typeof e.skillStorage == "object" ? e.skillStorage : {},
|
|
17919
18087
|
id: e.skillStorage && typeof e.skillStorage == "object" && e.skillStorage.id ? e.skillStorage.id : `agent::${i}`
|
|
17920
18088
|
}), De = () => {
|
|
@@ -17942,12 +18110,12 @@ function cb(e, i) {
|
|
|
17942
18110
|
_e,
|
|
17943
18111
|
...ne ? [h] : [],
|
|
17944
18112
|
...re ? [Ce = $g(e.skills || [], { readVfs: ie ? (e) => m.files[e]?.content : void 0 })] : [],
|
|
17945
|
-
...ie ? [
|
|
18113
|
+
...ie ? [Ty(m)] : [],
|
|
17946
18114
|
...ae ? [av({
|
|
17947
|
-
...
|
|
18115
|
+
...qv(e, d.contextWindow),
|
|
17948
18116
|
llmInvoke: u,
|
|
17949
18117
|
getRegisteredData: () => k() ? [{ description: k().description ?? "主数据对象" }] : [],
|
|
17950
|
-
preserveLastToolResults: (e.contextOptions && e.contextOptions.preserveLastToolResults) ?? [
|
|
18118
|
+
preserveLastToolResults: (e.contextOptions && e.contextOptions.preserveLastToolResults) ?? Kv[e.contextPreset ?? "auto"]
|
|
17951
18119
|
})] : [],
|
|
17952
18120
|
...oe ? [g] : [],
|
|
17953
18121
|
...e.permissions?.length ? [a_(e.permissions)] : [],
|
|
@@ -17959,8 +18127,8 @@ function cb(e, i) {
|
|
|
17959
18127
|
...fe ? [fe] : [],
|
|
17960
18128
|
...ye ? [ye] : [],
|
|
17961
18129
|
...e.middleware || [],
|
|
17962
|
-
|
|
17963
|
-
], Ae = e.maxMemoryRounds ??
|
|
18130
|
+
fb(Se, p, k, a)
|
|
18131
|
+
], Ae = e.maxMemoryRounds ?? lb, z = {
|
|
17964
18132
|
agentId: i,
|
|
17965
18133
|
store: c,
|
|
17966
18134
|
messages: p,
|
|
@@ -18062,7 +18230,7 @@ function cb(e, i) {
|
|
|
18062
18230
|
if (z.refCount--, z.refCount <= 0) {
|
|
18063
18231
|
c && (m.flush?.(), c.flush(), c.dispose()), R && R.dispose();
|
|
18064
18232
|
let e = z.mcpClosers.splice(0);
|
|
18065
|
-
e.length && Promise.allSettled(e.map((e) => e())),
|
|
18233
|
+
e.length && Promise.allSettled(e.map((e) => e())), ub.delete(i);
|
|
18066
18234
|
}
|
|
18067
18235
|
},
|
|
18068
18236
|
resolveConflict: o.resolve,
|
|
@@ -18136,6 +18304,7 @@ function cb(e, i) {
|
|
|
18136
18304
|
description: k().description,
|
|
18137
18305
|
schema: k().schema
|
|
18138
18306
|
} : void 0,
|
|
18307
|
+
contextPreset: e.contextPreset ?? "auto",
|
|
18139
18308
|
memory: g.get(),
|
|
18140
18309
|
middleware: ke.map((e) => e.name),
|
|
18141
18310
|
todos: (z.agent?.getState?.()?.todos ?? []).map((e) => ({
|
|
@@ -18251,11 +18420,11 @@ function cb(e, i) {
|
|
|
18251
18420
|
});
|
|
18252
18421
|
})(), z;
|
|
18253
18422
|
}
|
|
18254
|
-
function
|
|
18423
|
+
function mb(e) {
|
|
18255
18424
|
let t = e.id ?? _v();
|
|
18256
18425
|
e.id || console.warn(`[page-agent-sdk] 未传 options.id,已生成随机 id "${t}"。刷新后持久化数据无法恢复,请传稳定 id。`);
|
|
18257
|
-
let n = e.streaming ?? !0, r = e.ui ?? "default", i, a = e.shareContext ?
|
|
18258
|
-
a ? i = a : (i =
|
|
18426
|
+
let n = e.streaming ?? !0, r = e.ui ?? "default", i, a = e.shareContext ? ub.get(t) : void 0;
|
|
18427
|
+
a ? i = a : (i = pb(e, t), e.shareContext && ub.set(t, i)), i.refCount++;
|
|
18259
18428
|
let o = null, s = null, c = Uv(e), l = null, u = null;
|
|
18260
18429
|
async function d(t) {
|
|
18261
18430
|
if (await i.initDone, o) {
|
|
@@ -18433,7 +18602,7 @@ function lb(e) {
|
|
|
18433
18602
|
}
|
|
18434
18603
|
//#endregion
|
|
18435
18604
|
//#region src/core/sdk/defineTool.ts
|
|
18436
|
-
function
|
|
18605
|
+
function hb(e) {
|
|
18437
18606
|
return r(async (t) => {
|
|
18438
18607
|
let n = await e.handler(t);
|
|
18439
18608
|
return typeof n == "string" ? n : JSON.stringify(n);
|
|
@@ -18444,4 +18613,4 @@ function ub(e) {
|
|
|
18444
18613
|
});
|
|
18445
18614
|
}
|
|
18446
18615
|
//#endregion
|
|
18447
|
-
export { Gv as CONTEXT_PRESETS, yg as ChatDialog, nf as CodePreview, lv as DEFAULT_SYSTEM_PROMPT, s_ as HUMAN_CONFIRM_TOOL_NAME, af as MessageContent, Z_ as STOP_WORDS, sh as SkillPanel,
|
|
18616
|
+
export { Gv as CONTEXT_PRESETS, yg as ChatDialog, nf as CodePreview, lv as DEFAULT_SYSTEM_PROMPT, s_ as HUMAN_CONFIRM_TOOL_NAME, af as MessageContent, Z_ as STOP_WORDS, sh as SkillPanel, Zv as UNSAFE_KEYS, ly as applyPatchToClone, uy as applyPatchToLive, uv as buildDataPrompt, dv as buildSystemPrompt, K_ as connectMcp, wl as copyText, Wg as createAgent, o_ as createApprovalMiddleware, mb as createChatSdk, __ as createCheckpointManager, v_ as createCheckpointMiddleware, gv as createConflictManager, Xy as createDataOps, u_ as createHumanConfirmMiddleware, l_ as createHumanConfirmTool, Lv as createMemoryBackend, e_ as createMemoryMiddleware, v as createProxyLlm, Wv as createSdkEvents, Vv as createSessionStore, cb as createSkillStore, E_ as createSubagentMiddleware, k_ as createSubagentsMiddleware, rb as createUsageHintsMiddleware, A_ as createVerifyMiddleware, gy as createVfs, zv as createWebStorageBackend, I_ as createWriteBackCheck, ry as deepClone, eb as defineDataToolset, qg as defineSkill, hb as defineTool, ny as deleteByPath, zg as detectGarbledToolCall, $_ as estimateMessageTokens, ev as estimateRoundTokens, Dg as estimateTokens, cv as extractSchemaHint, U_ as extractText, Qy as fetchDocTools, $y as fetchTools, Yy as filterByToolMode, Jv as formatZodIssues, ey as getByPath, Wy as getSchemaAtPath, Vy as getSchemaTopKeys, cy as hashValue, tv as indexSummarize, fv as isChatModel, Hy as isPathAllowed, kv as isQuotaError, Qv as isUnsafePath, Fy as jpEval, Xv as jsonParseError, oy as limitDepth, iy as maybeParseValue, kg as offloadPassThroughChars, Og as offloadThresholdChars, ov as presets, Ky as projectBySchema, Gy as projectBySchemaDeep, ay as projectFields, nv as recallRounds, qv as resolveContextOptions, Uv as resolveDialogConfig, hv as resolveLlm, Eg as resolveModelCaps, Hv as resolveStorage, fy as restoreInPlace, dy as restoreLive, By as runSandboxedScript, $v as safeMerge, sy as safeStringify, Ly as searchJson, tb as selectBuiltinTools, ty as setByPath, sv as systemPromptHelpers, Q_ as tokenize, $ as toolError, Uy as unwrapSchema, Cl as useChat, e as z, Yv as zodError };
|