page-agent-sdk 2.21.0 → 2.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,16 +21,18 @@ function _(e) {
21
21
  function v(e) {
22
22
  let t = e.model || "gpt-3.5-turbo", r = e.temperature, i = e.maxTokens, a = e.baseUrl;
23
23
  if (e.mode === "direct") {
24
+ let o = !1;
24
25
  try {
25
- if (typeof location < "u" && location.protocol === "https:" && ![
26
+ o = typeof location < "u" && location.protocol === "https:" && ![
26
27
  "localhost",
27
28
  "127.0.0.1",
28
29
  "0.0.0.0"
29
- ].includes(location.hostname)) {
30
- if (e.throwOnDirectInProduction) throw Error("[page-agent-sdk][proxyLlm] direct 模式在生产环境(https + 非本地)会泄露 apiKey(进 bundle),建议改用 proxy 模式(throwOnDirectInProduction 已启用强安全闸;若确需生产直连,设为 false 显式承认风险)");
31
- console.warn("[page-agent-sdk][proxyLlm] direct 模式在生产环境(https + 非本地)会泄露 apiKey(进 bundle),建议改用 proxy 模式");
32
- }
30
+ ].includes(location.hostname);
33
31
  } catch {}
32
+ if (o) {
33
+ if (e.throwOnDirectInProduction) throw Error("[page-agent-sdk][proxyLlm] direct 模式在生产环境(https + 非本地)会泄露 apiKey(进 bundle),建议改用 proxy 模式(throwOnDirectInProduction 已启用强安全闸;若确需生产直连,设为 false 显式承认风险)");
34
+ console.warn("[page-agent-sdk][proxyLlm] direct 模式在生产环境(https + 非本地)会泄露 apiKey(进 bundle),建议改用 proxy 模式");
35
+ }
34
36
  if (!e.apiKey) throw Error("[page-agent-sdk][proxyLlm] direct 模式需提供 apiKey(开发环境用真实 key)");
35
37
  return new n({
36
38
  apiKey: e.apiKey,
@@ -16897,8 +16899,95 @@ function ib(e) {
16897
16899
  return e.dialog ?? {};
16898
16900
  }
16899
16901
  //#endregion
16902
+ //#region src/core/capabilities.ts
16903
+ var ab = [
16904
+ {
16905
+ name: "dataOps",
16906
+ defaultOn: !0
16907
+ },
16908
+ {
16909
+ name: "fetch",
16910
+ defaultOn: !0
16911
+ },
16912
+ {
16913
+ name: "planning",
16914
+ defaultOn: !0
16915
+ },
16916
+ {
16917
+ name: "missionAnchor",
16918
+ defaultOn: !0
16919
+ },
16920
+ {
16921
+ name: "workingMemory",
16922
+ defaultOn: !0
16923
+ },
16924
+ {
16925
+ name: "skills",
16926
+ defaultOn: !0
16927
+ },
16928
+ {
16929
+ name: "vfs",
16930
+ defaultOn: !0
16931
+ },
16932
+ {
16933
+ name: "summarization",
16934
+ defaultOn: !0
16935
+ },
16936
+ {
16937
+ name: "memory",
16938
+ defaultOn: !0
16939
+ },
16940
+ {
16941
+ name: "subagent",
16942
+ defaultOn: !0
16943
+ },
16944
+ {
16945
+ name: "inspectEnv",
16946
+ defaultOn: !0
16947
+ },
16948
+ {
16949
+ name: "verify",
16950
+ defaultOn: !1
16951
+ },
16952
+ {
16953
+ name: "domInspect",
16954
+ defaultOn: !1
16955
+ },
16956
+ {
16957
+ name: "draftWrite",
16958
+ defaultOn: !1,
16959
+ requires: ["dataOps", "vfs"]
16960
+ },
16961
+ {
16962
+ name: "tracing",
16963
+ defaultOn: !1
16964
+ },
16965
+ {
16966
+ name: "todoDeps",
16967
+ defaultOn: !1
16968
+ },
16969
+ {
16970
+ name: "automation",
16971
+ defaultOn: !1
16972
+ }
16973
+ ];
16974
+ function ob(e) {
16975
+ let t = {};
16976
+ for (let n of ab) {
16977
+ let r = e?.[n.name];
16978
+ t[n.name] = n.defaultOn ? r !== !1 : r === !0;
16979
+ }
16980
+ for (let e of ab) if (e.requires && t[e.name]) {
16981
+ for (let n of e.requires) if (!t[n]) {
16982
+ t[e.name] = !1;
16983
+ break;
16984
+ }
16985
+ }
16986
+ return t;
16987
+ }
16988
+ //#endregion
16900
16989
  //#region src/core/sdk/events.ts
16901
- function ab(e) {
16990
+ function sb(e) {
16902
16991
  let t = /* @__PURE__ */ new Set(), n = (n) => {
16903
16992
  if (n.type !== "approval_request") {
16904
16993
  if (e) try {
@@ -16924,7 +17013,7 @@ function ab(e) {
16924
17013
  }
16925
17014
  //#endregion
16926
17015
  //#region src/core/sdk/contextPreset.ts
16927
- var ob = {
17016
+ var cb = {
16928
17017
  auto: {
16929
17018
  summaryThresholdRatio: .5,
16930
17019
  windowRatio: .4,
@@ -16952,7 +17041,7 @@ var ob = {
16952
17041
  enableRecall: !0,
16953
17042
  enableLLMSummary: !0
16954
17043
  }
16955
- }, sb = {
17044
+ }, lb = {
16956
17045
  auto: ["describe_data", "read"],
16957
17046
  conservative: ["describe_data"],
16958
17047
  aggressive: ["describe_data", "read"],
@@ -16963,8 +17052,8 @@ var ob = {
16963
17052
  "search_data"
16964
17053
  ]
16965
17054
  };
16966
- function cb(e, t) {
16967
- let n = ob[e.contextPreset ?? "auto"] ?? {}, r = e.contextOptions === !1 ? {} : e.contextOptions ?? {};
17055
+ function ub(e, t) {
17056
+ let n = cb[e.contextPreset ?? "auto"] ?? {}, r = e.contextOptions === !1 ? {} : e.contextOptions ?? {};
16968
17057
  return {
16969
17058
  ...n,
16970
17059
  ...r,
@@ -16974,7 +17063,7 @@ function cb(e, t) {
16974
17063
  }
16975
17064
  //#endregion
16976
17065
  //#region src/core/sdk/middlewareStack.ts
16977
- var lb = {
17066
+ var db = {
16978
17067
  dataHint: 10,
16979
17068
  usageHints: 20,
16980
17069
  todos: 30,
@@ -16991,29 +17080,29 @@ var lb = {
16991
17080
  subagents: 140,
16992
17081
  augmentSystem: 150
16993
17082
  };
16994
- function ub(e) {
17083
+ function fb(e) {
16995
17084
  return e.map((e, t) => ({
16996
17085
  m: e,
16997
17086
  i: t,
16998
- p: lb[e.name] ?? Infinity
17087
+ p: db[e.name] ?? Infinity
16999
17088
  })).sort((e, t) => e.p - t.p || e.i - t.i).map((e) => e.m);
17000
17089
  }
17001
17090
  //#endregion
17002
17091
  //#region src/core/tools/jsonUtils.ts
17003
- var db = /* @__PURE__ */ new Set([
17092
+ var pb = /* @__PURE__ */ new Set([
17004
17093
  "__proto__",
17005
17094
  "constructor",
17006
17095
  "prototype"
17007
17096
  ]);
17008
- function fb(e) {
17009
- return e.split(".").some((e) => db.has(e));
17097
+ function mb(e) {
17098
+ return e.split(".").some((e) => pb.has(e));
17010
17099
  }
17011
- function pb(e, t) {
17012
- if (!(!t || typeof t != "object" || Array.isArray(t))) for (let n of Object.keys(t)) db.has(n) || (e[n] = t[n]);
17100
+ function hb(e, t) {
17101
+ if (!(!t || typeof t != "object" || Array.isArray(t))) for (let n of Object.keys(t)) pb.has(n) || (e[n] = t[n]);
17013
17102
  }
17014
- function mb(e, t) {
17103
+ function gb(e, t) {
17015
17104
  if (!t) return e;
17016
- if (fb(t)) return;
17105
+ if (mb(t)) return;
17017
17106
  let n = t.split("."), r = e;
17018
17107
  for (let e of n) {
17019
17108
  if (r == null) return;
@@ -17021,8 +17110,8 @@ function mb(e, t) {
17021
17110
  }
17022
17111
  return r;
17023
17112
  }
17024
- function hb(e, t, n) {
17025
- if (!t || fb(t)) return;
17113
+ function _b(e, t, n) {
17114
+ if (!t || mb(t)) return;
17026
17115
  let r = t.split("."), i = e;
17027
17116
  for (let e = 0; e < r.length - 1; e++) {
17028
17117
  let t = r[e];
@@ -17030,8 +17119,8 @@ function hb(e, t, n) {
17030
17119
  }
17031
17120
  i[r[r.length - 1]] = n;
17032
17121
  }
17033
- function gb(e, t) {
17034
- if (!t || fb(t)) return !1;
17122
+ function vb(e, t) {
17123
+ if (!t || mb(t)) return !1;
17035
17124
  let n = t.split("."), r = e;
17036
17125
  for (let e = 0; e < n.length - 1; e++) {
17037
17126
  if (r == null) return !1;
@@ -17040,10 +17129,10 @@ function gb(e, t) {
17040
17129
  let i = n[n.length - 1];
17041
17130
  return r == null || !(i in r) ? !1 : (Array.isArray(r) && /^\d+$/.test(i) ? r.splice(Number(i), 1) : delete r[i], !0);
17042
17131
  }
17043
- function _b(e) {
17132
+ function yb(e) {
17044
17133
  return e === void 0 ? void 0 : JSON.parse(JSON.stringify(e));
17045
17134
  }
17046
- function vb(e) {
17135
+ function bb(e) {
17047
17136
  if (typeof e != "string") return { parsed: e };
17048
17137
  let t = e.trim();
17049
17138
  if (!t) return { parsed: e };
@@ -17054,23 +17143,23 @@ function vb(e) {
17054
17143
  return n ? { parseError: t } : { parsed: e };
17055
17144
  }
17056
17145
  }
17057
- function yb(e, t) {
17146
+ function xb(e, t) {
17058
17147
  if (typeof e != "object" || !e) return e;
17059
17148
  let n = new Set(t);
17060
- if (Array.isArray(e)) return e.map((e) => yb(e, t));
17149
+ if (Array.isArray(e)) return e.map((e) => xb(e, t));
17061
17150
  let r = {};
17062
17151
  for (let t of Object.keys(e)) n.has(t) && (r[t] = e[t]);
17063
17152
  return r;
17064
17153
  }
17065
- function bb(e, t) {
17154
+ function Sb(e, t) {
17066
17155
  if (typeof e != "object" || !e) return e;
17067
17156
  if (t <= 0) return Array.isArray(e) ? `[...${e.length}]` : "{...}";
17068
- if (Array.isArray(e)) return e.map((e) => bb(e, t - 1));
17157
+ if (Array.isArray(e)) return e.map((e) => Sb(e, t - 1));
17069
17158
  let n = {};
17070
- for (let r of Object.keys(e)) n[r] = bb(e[r], t - 1);
17159
+ for (let r of Object.keys(e)) n[r] = Sb(e[r], t - 1);
17071
17160
  return n;
17072
17161
  }
17073
- function xb(e, t = Infinity) {
17162
+ function Cb(e, t = Infinity) {
17074
17163
  let n = /* @__PURE__ */ new WeakSet(), r;
17075
17164
  try {
17076
17165
  r = JSON.stringify(e, (e, t) => {
@@ -17089,7 +17178,7 @@ function xb(e, t = Infinity) {
17089
17178
  }
17090
17179
  return r.length > t && (r = r.slice(0, t) + `\n…[已截断,原长度 ${r.length}]`), r;
17091
17180
  }
17092
- function Sb(e, t = 0) {
17181
+ function wb(e, t = 0) {
17093
17182
  let n = 3735928559 ^ t, r = 1103547991 ^ t;
17094
17183
  for (let t = 0; t < e.length; t++) {
17095
17184
  let i = e.charCodeAt(t);
@@ -17097,32 +17186,32 @@ function Sb(e, t = 0) {
17097
17186
  }
17098
17187
  return n = Math.imul(n ^ n >>> 16, 2246822507) ^ Math.imul(r ^ r >>> 13, 3266489909), r = Math.imul(r ^ r >>> 16, 2246822507) ^ Math.imul(n ^ n >>> 13, 3266489909), 4294967296 * (2097151 & r) + (n >>> 0);
17099
17188
  }
17100
- function Cb(e) {
17101
- return Sb(xb(e)).toString(36);
17189
+ function Tb(e) {
17190
+ return wb(Cb(e)).toString(36);
17102
17191
  }
17103
- function wb(e, t, n, r) {
17104
- if (t === "set") return n ? (hb(e, n, r), null) : "set 操作需要 jsonPath(整体替换请用 set_data)";
17105
- if (t === "remove") return n ? (gb(e, n), null) : "remove 操作需要 jsonPath";
17192
+ function Eb(e, t, n, r) {
17193
+ if (t === "set") return n ? (_b(e, n, r), null) : "set 操作需要 jsonPath(整体替换请用 set_data)";
17194
+ if (t === "remove") return n ? (vb(e, n), null) : "remove 操作需要 jsonPath";
17106
17195
  if (t === "merge") {
17107
- let t = n ? mb(e, n) : e;
17108
- return typeof t != "object" || !t || Array.isArray(t) ? `merge 目标${n ? `(${n})` : "(根)"}不是对象` : (pb(t, r), null);
17196
+ let t = n ? gb(e, n) : e;
17197
+ return typeof t != "object" || !t || Array.isArray(t) ? `merge 目标${n ? `(${n})` : "(根)"}不是对象` : (hb(t, r), null);
17109
17198
  }
17110
- let i = n ? mb(e, n) : e;
17199
+ let i = n ? gb(e, n) : e;
17111
17200
  return Array.isArray(i) ? (Array.isArray(r) ? i.push(...r) : i.push(r), null) : `append 目标${n ? `(${n})` : "(根)"}不是数组`;
17112
17201
  }
17113
- function Tb(e, t, n, r) {
17114
- if (t === "set") hb(e, n, r);
17115
- else if (t === "remove") gb(e, n);
17116
- else if (t === "merge") pb(n ? mb(e, n) : e, r);
17202
+ function Db(e, t, n, r) {
17203
+ if (t === "set") _b(e, n, r);
17204
+ else if (t === "remove") vb(e, n);
17205
+ else if (t === "merge") hb(n ? gb(e, n) : e, r);
17117
17206
  else {
17118
- let t = n ? mb(e, n) : e;
17207
+ let t = n ? gb(e, n) : e;
17119
17208
  Array.isArray(r) ? t.push(...r) : t.push(r);
17120
17209
  }
17121
17210
  }
17122
- function Eb(e, t) {
17123
- typeof e == "object" && e && Db(e, t);
17211
+ function Ob(e, t) {
17212
+ typeof e == "object" && e && kb(e, t);
17124
17213
  }
17125
- function Db(e, t) {
17214
+ function kb(e, t) {
17126
17215
  if (Array.isArray(e)) {
17127
17216
  e.length = 0, Array.isArray(t) && e.push(...t);
17128
17217
  return;
@@ -17131,7 +17220,7 @@ function Db(e, t) {
17131
17220
  for (let t of Object.keys(e)) t in n || delete e[t];
17132
17221
  for (let t of Object.keys(n)) e[t] = n[t];
17133
17222
  }
17134
- function Ob(e, t, n = "") {
17223
+ function Ab(e, t, n = "") {
17135
17224
  let r = [];
17136
17225
  if (!(typeof e == "object" && e) || !(typeof t == "object" && t) || Array.isArray(e) !== Array.isArray(t)) return e !== t && r.push({
17137
17226
  path: n || "(root)",
@@ -17150,14 +17239,14 @@ function Ob(e, t, n = "") {
17150
17239
  path: i,
17151
17240
  from: e[a],
17152
17241
  to: void 0
17153
- }) : r.push(...Ob(e[a], t[a], i));
17242
+ }) : r.push(...Ab(e[a], t[a], i));
17154
17243
  }
17155
17244
  return r;
17156
17245
  }
17157
17246
  let i = e, a = t, o = /* @__PURE__ */ new Set([...Object.keys(i), ...Object.keys(a)]);
17158
17247
  for (let e of o) {
17159
17248
  let t = n ? `${n}.${e}` : e;
17160
- e in i ? e in a ? r.push(...Ob(i[e], a[e], t)) : r.push({
17249
+ e in i ? e in a ? r.push(...Ab(i[e], a[e], t)) : r.push({
17161
17250
  path: t,
17162
17251
  from: i[e],
17163
17252
  to: void 0
@@ -17169,44 +17258,44 @@ function Ob(e, t, n = "") {
17169
17258
  }
17170
17259
  return r;
17171
17260
  }
17172
- var kb = {
17261
+ var jb = {
17173
17262
  largeResults: 4194304,
17174
17263
  drafts: 2097152,
17175
17264
  userFiles: 2097152
17176
- }, Ab = [
17265
+ }, Mb = [
17177
17266
  "largeResults",
17178
17267
  "drafts",
17179
17268
  "userFiles"
17180
- ], jb = .9;
17181
- function Mb(e, t = {}) {
17269
+ ], Nb = .9;
17270
+ function Pb(e, t = {}) {
17182
17271
  let n = Object.create(null);
17183
- if (e) for (let [t, r] of Object.entries(e)) n[Ib(t)] = {
17272
+ if (e) for (let [t, r] of Object.entries(e)) n[Rb(t)] = {
17184
17273
  content: r,
17185
- updatedAt: Rb()
17274
+ updatedAt: Bb()
17186
17275
  };
17187
17276
  let { persist: r } = t, i = t.maxBytes ?? 8388608, a = {
17188
- ...kb,
17277
+ ...jb,
17189
17278
  ...t.poolBytes ?? {}
17190
17279
  };
17191
17280
  function o(e) {
17192
- let t = Ib(e);
17281
+ let t = Rb(e);
17193
17282
  return t.startsWith("large_results/") ? "largeResults" : t.startsWith("drafts/") ? "drafts" : "userFiles";
17194
17283
  }
17195
17284
  function s(e) {
17196
17285
  let t = 0;
17197
- for (let [r, i] of Object.entries(n)) o(r) === e && (t += Pb(i.content));
17286
+ for (let [r, i] of Object.entries(n)) o(r) === e && (t += Ib(i.content));
17198
17287
  return t;
17199
17288
  }
17200
17289
  function c() {
17201
- for (let e of Ab) {
17290
+ for (let e of Mb) {
17202
17291
  let t = a[e];
17203
17292
  if (s(e) <= t) continue;
17204
- let r = t * jb, i = Object.entries(n).filter(([t]) => o(t) === e).sort((e, t) => e[1].updatedAt - t[1].updatedAt);
17293
+ let r = t * Nb, i = Object.entries(n).filter(([t]) => o(t) === e).sort((e, t) => e[1].updatedAt - t[1].updatedAt);
17205
17294
  for (let [t] of i) if (delete n[t], s(e) <= r) break;
17206
17295
  }
17207
- if (Fb(n) > i) {
17208
- let e = i * jb, t = Object.entries(n).sort((e, t) => e[1].updatedAt - t[1].updatedAt);
17209
- for (let [r] of t) if (delete n[r], Fb(n) <= e) break;
17296
+ if (Lb(n) > i) {
17297
+ let e = i * Nb, t = Object.entries(n).sort((e, t) => e[1].updatedAt - t[1].updatedAt);
17298
+ for (let [r] of t) if (delete n[r], Lb(n) <= e) break;
17210
17299
  }
17211
17300
  }
17212
17301
  let l = !0, u = null;
@@ -17239,7 +17328,7 @@ function Mb(e, t = {}) {
17239
17328
  }
17240
17329
  };
17241
17330
  return r && (p.hydrate = (e) => {
17242
- for (let [t, r] of Object.entries(e)) n[Ib(t)] = r;
17331
+ for (let [t, r] of Object.entries(e)) n[Rb(t)] = r;
17243
17332
  c(), l = !0;
17244
17333
  }, p.flush = () => {
17245
17334
  u &&= (clearTimeout(u), null), d();
@@ -17248,19 +17337,19 @@ function Mb(e, t = {}) {
17248
17337
  f(), l = !0;
17249
17338
  }), p;
17250
17339
  }
17251
- var Nb = null;
17252
- function Pb(e) {
17253
- return Nb ||= new TextEncoder(), Nb.encode(e).length;
17340
+ var Fb = null;
17341
+ function Ib(e) {
17342
+ return Fb ||= new TextEncoder(), Fb.encode(e).length;
17254
17343
  }
17255
- function Fb(e) {
17344
+ function Lb(e) {
17256
17345
  let t = 0;
17257
- for (let n of Object.values(e)) t += Pb(n.content);
17346
+ for (let n of Object.values(e)) t += Ib(n.content);
17258
17347
  return t;
17259
17348
  }
17260
- function Ib(e) {
17349
+ function Rb(e) {
17261
17350
  return e.replace(/^\/+/, "").replace(/\/+/g, "/");
17262
17351
  }
17263
- function Lb(e) {
17352
+ function zb(e) {
17264
17353
  let t = "";
17265
17354
  for (let n = 0; n < e.length; n++) {
17266
17355
  let r = e[n];
@@ -17268,10 +17357,10 @@ function Lb(e) {
17268
17357
  }
17269
17358
  return RegExp("^" + t + "$");
17270
17359
  }
17271
- function Rb() {
17360
+ function Bb() {
17272
17361
  return Date.now();
17273
17362
  }
17274
- var zb = [
17363
+ var Vb = [
17275
17364
  "vfs_read",
17276
17365
  "vfs_write",
17277
17366
  "vfs_edit",
@@ -17281,10 +17370,10 @@ var zb = [
17281
17370
  "vfs_json_read",
17282
17371
  "vfs_json_patch"
17283
17372
  ];
17284
- function Bb(e) {
17373
+ function Hb(e) {
17285
17374
  return [
17286
17375
  r(async ({ path: t, offset: n, limit: r }) => {
17287
- let i = e.files[Ib(t)];
17376
+ let i = e.files[Rb(t)];
17288
17377
  if (!i) return $({
17289
17378
  code: "NOT_FOUND",
17290
17379
  path: t,
@@ -17313,9 +17402,9 @@ function Bb(e) {
17313
17402
  hint: "jsonString=true 要求 content 是合法 JSON;检查引号/逗号/括号配对;或省略 jsonString 写纯文本"
17314
17403
  });
17315
17404
  }
17316
- return e.files[Ib(t)] = {
17405
+ return e.files[Rb(t)] = {
17317
17406
  content: n,
17318
- updatedAt: Rb()
17407
+ updatedAt: Bb()
17319
17408
  }, `已写入 ${t}(${n.length} 字符)${r ? "(JSON 校验通过)" : ""}`;
17320
17409
  }, {
17321
17410
  name: "vfs_write",
@@ -17327,7 +17416,7 @@ function Bb(e) {
17327
17416
  })
17328
17417
  }),
17329
17418
  r(async ({ path: t, oldString: n, newString: r }) => {
17330
- let i = Ib(t), a = e.files[i];
17419
+ let i = Rb(t), a = e.files[i];
17331
17420
  if (!a) return $({
17332
17421
  code: "NOT_FOUND",
17333
17422
  path: t,
@@ -17357,7 +17446,7 @@ function Bb(e) {
17357
17446
  }
17358
17447
  return e.files[i] = {
17359
17448
  content: a.content.replace(n, r),
17360
- updatedAt: Rb()
17449
+ updatedAt: Bb()
17361
17450
  }, `已替换 ${t} 中 1 处。`;
17362
17451
  }, {
17363
17452
  name: "vfs_edit",
@@ -17379,7 +17468,7 @@ function Bb(e) {
17379
17468
  r(async ({ pattern: t }) => {
17380
17469
  let n;
17381
17470
  try {
17382
- n = Lb(t);
17471
+ n = zb(t);
17383
17472
  } catch (e) {
17384
17473
  return $({
17385
17474
  code: "GLOB_INVALID",
@@ -17408,7 +17497,7 @@ function Bb(e) {
17408
17497
  details: { pattern: t }
17409
17498
  });
17410
17499
  }
17411
- let i = n ? [Ib(n)] : Object.keys(e.files), a = [];
17500
+ let i = n ? [Rb(n)] : Object.keys(e.files), a = [];
17412
17501
  for (let t of i) {
17413
17502
  let n = e.files[t];
17414
17503
  n && n.content.split("\n").forEach((e, n) => {
@@ -17425,7 +17514,7 @@ function Bb(e) {
17425
17514
  })
17426
17515
  }),
17427
17516
  r(async ({ path: t, jsonPath: n }) => {
17428
- let r = Ib(t), i = e.files[r];
17517
+ let r = Rb(t), i = e.files[r];
17429
17518
  if (!i) return $({
17430
17519
  code: "NOT_FOUND",
17431
17520
  path: t,
@@ -17444,7 +17533,7 @@ function Bb(e) {
17444
17533
  });
17445
17534
  }
17446
17535
  if (n) {
17447
- let e = mb(a, n);
17536
+ let e = gb(a, n);
17448
17537
  return e === void 0 ? $({
17449
17538
  code: "VFS_PATH_NOT_FOUND",
17450
17539
  path: t,
@@ -17462,7 +17551,7 @@ function Bb(e) {
17462
17551
  })
17463
17552
  }),
17464
17553
  r(async ({ path: t, patches: n }) => {
17465
- let r = Ib(t), i = e.files[r];
17554
+ let r = Rb(t), i = e.files[r];
17466
17555
  if (!i) return $({
17467
17556
  code: "NOT_FOUND",
17468
17557
  path: t,
@@ -17480,9 +17569,9 @@ function Bb(e) {
17480
17569
  hint: "vfs_json_patch 要求文件内容是合法 JSON"
17481
17570
  });
17482
17571
  }
17483
- let o = _b(a), s = [];
17572
+ let o = yb(a), s = [];
17484
17573
  for (let e of n) {
17485
- let n = wb(o, e.op, e.jsonPath, e.value);
17574
+ let n = Eb(o, e.op, e.jsonPath, e.value);
17486
17575
  if (n) return $({
17487
17576
  code: "PATCH_FAILED",
17488
17577
  path: t,
@@ -17495,7 +17584,7 @@ function Bb(e) {
17495
17584
  let c = JSON.stringify(o);
17496
17585
  return e.files[r] = {
17497
17586
  content: c,
17498
- updatedAt: Rb()
17587
+ updatedAt: Bb()
17499
17588
  }, `已对 ${t} 应用 ${n.length} 个 patch(影响 ${s.length} 处:${s.join(", ")}),文件现 ${c.length} 字符`;
17500
17589
  }, {
17501
17590
  name: "vfs_json_patch",
@@ -17516,17 +17605,17 @@ function Bb(e) {
17516
17605
  })
17517
17606
  ];
17518
17607
  }
17519
- function Vb(e) {
17608
+ function Ub(e) {
17520
17609
  return {
17521
17610
  name: "vfs",
17522
- tools: Bb(e),
17611
+ tools: Hb(e),
17523
17612
  beforeAgent: () => ({ files: e.files })
17524
17613
  };
17525
17614
  }
17526
17615
  //#endregion
17527
17616
  //#region src/core/tools/dataSlotQuery.ts
17528
- var Hb = /[\w$-]/;
17529
- function Ub(e) {
17617
+ var Wb = /[\w$-]/;
17618
+ function Gb(e) {
17530
17619
  let t = [], n = e.trim(), r = +(n[0] === "$");
17531
17620
  for (; r < n.length;) {
17532
17621
  let e = n[r];
@@ -17537,7 +17626,7 @@ function Ub(e) {
17537
17626
  continue;
17538
17627
  }
17539
17628
  let e = "";
17540
- for (; r < n.length && Hb.test(n[r]);) e += n[r++];
17629
+ for (; r < n.length && Wb.test(n[r]);) e += n[r++];
17541
17630
  if (!e) throw Error("JSONPath: .. 后缺属性名");
17542
17631
  t.push({
17543
17632
  type: "descendKey",
@@ -17550,7 +17639,7 @@ function Ub(e) {
17550
17639
  continue;
17551
17640
  }
17552
17641
  let e = "";
17553
- for (; r < n.length && Hb.test(n[r]);) e += n[r++];
17642
+ for (; r < n.length && Wb.test(n[r]);) e += n[r++];
17554
17643
  if (!e) throw Error("JSONPath: . 后缺属性名");
17555
17644
  t.push({
17556
17645
  type: "key",
@@ -17606,7 +17695,7 @@ function Ub(e) {
17606
17695
  }
17607
17696
  return t;
17608
17697
  }
17609
- function Wb(e) {
17698
+ function Kb(e) {
17610
17699
  let t = [], n = 0, r = e.trim();
17611
17700
  for (; n < r.length;) {
17612
17701
  let e = r[n];
@@ -17651,7 +17740,7 @@ function Wb(e) {
17651
17740
  }
17652
17741
  return t;
17653
17742
  }
17654
- var Gb = class {
17743
+ var qb = class {
17655
17744
  toks;
17656
17745
  item;
17657
17746
  pos = 0;
@@ -17687,12 +17776,12 @@ var Gb = class {
17687
17776
  return this.next(), e;
17688
17777
  }
17689
17778
  let e = this.operand(), t = this.peek();
17690
- return t === "==" || t === "!=" || t === "<" || t === "<=" || t === ">" || t === ">=" ? (this.next(), Jb(t, e, this.operand())) : Kb(e);
17779
+ return t === "==" || t === "!=" || t === "<" || t === "<=" || t === ">" || t === ">=" ? (this.next(), Xb(t, e, this.operand())) : Jb(e);
17691
17780
  }
17692
17781
  operand() {
17693
17782
  let e = this.next();
17694
17783
  if (e === void 0) throw Error("过滤表达式:缺操作数");
17695
- if (e.startsWith("@")) return qb(e, this.item);
17784
+ if (e.startsWith("@")) return Yb(e, this.item);
17696
17785
  if (e[0] === "'" || e[0] === "\"") return e.slice(1, -1);
17697
17786
  if (e === "true") return !0;
17698
17787
  if (e === "false") return !1;
@@ -17702,10 +17791,10 @@ var Gb = class {
17702
17791
  throw Error(`过滤表达式:未知操作数 '${e}'`);
17703
17792
  }
17704
17793
  };
17705
- function Kb(e) {
17794
+ function Jb(e) {
17706
17795
  return !!e && e !== 0 && e !== "" && e !== null;
17707
17796
  }
17708
- function qb(e, t) {
17797
+ function Yb(e, t) {
17709
17798
  let n = e.split(".").filter((e) => e && e !== "@"), r = t;
17710
17799
  for (let e of n) {
17711
17800
  if (typeof r != "object" || !r) return;
@@ -17713,7 +17802,7 @@ function qb(e, t) {
17713
17802
  }
17714
17803
  return r;
17715
17804
  }
17716
- function Jb(e, t, n) {
17805
+ function Xb(e, t, n) {
17717
17806
  switch (e) {
17718
17807
  case "==": return t === n;
17719
17808
  case "!=": return t !== n;
@@ -17724,47 +17813,47 @@ function Jb(e, t, n) {
17724
17813
  default: return !1;
17725
17814
  }
17726
17815
  }
17727
- function Yb(e, t) {
17728
- return new Gb(Wb(e), t).parse();
17816
+ function Zb(e, t) {
17817
+ return new qb(Kb(e), t).parse();
17729
17818
  }
17730
- function Xb(e, t) {
17819
+ function Qb(e, t) {
17731
17820
  return e ? `${e}.${t}` : String(t);
17732
17821
  }
17733
- function Zb(e, t) {
17822
+ function $b(e, t) {
17734
17823
  let n = [{
17735
17824
  path: "",
17736
17825
  value: e
17737
17826
  }];
17738
- for (let e of Ub(t)) {
17827
+ for (let e of Gb(t)) {
17739
17828
  let t = [];
17740
17829
  if (e.type === "key") for (let r of n) r.value != null && typeof r.value == "object" && e.key in r.value && t.push({
17741
- path: Xb(r.path, e.key),
17830
+ path: Qb(r.path, e.key),
17742
17831
  value: r.value[e.key]
17743
17832
  });
17744
17833
  else if (e.type === "index") {
17745
17834
  for (let r of n) if (Array.isArray(r.value)) {
17746
17835
  let n = r.value[e.index];
17747
17836
  e.index >= 0 && e.index < r.value.length && t.push({
17748
- path: Xb(r.path, e.index),
17837
+ path: Qb(r.path, e.index),
17749
17838
  value: n,
17750
17839
  index: e.index
17751
17840
  });
17752
17841
  }
17753
17842
  } else if (e.type === "wildcard") {
17754
17843
  for (let e of n) if (Array.isArray(e.value)) e.value.forEach((n, r) => t.push({
17755
- path: Xb(e.path, r),
17844
+ path: Qb(e.path, r),
17756
17845
  value: n,
17757
17846
  index: r
17758
17847
  }));
17759
17848
  else if (e.value != null && typeof e.value == "object") for (let n of Object.keys(e.value)) t.push({
17760
- path: Xb(e.path, n),
17849
+ path: Qb(e.path, n),
17761
17850
  value: e.value[n]
17762
17851
  });
17763
17852
  } else if (e.type === "descendKey") {
17764
17853
  let r = e.key, i = (e) => {
17765
17854
  if (e.value != null && typeof e.value == "object") for (let n of Object.keys(e.value)) {
17766
17855
  let a = {
17767
- path: Xb(e.path, n),
17856
+ path: Qb(e.path, n),
17768
17857
  value: e.value[n]
17769
17858
  };
17770
17859
  n === r && t.push(a), i(a);
@@ -17775,7 +17864,7 @@ function Zb(e, t) {
17775
17864
  let e = (n) => {
17776
17865
  if (n.value != null && typeof n.value == "object") for (let r of Object.keys(n.value)) {
17777
17866
  let i = {
17778
- path: Xb(n.path, r),
17867
+ path: Qb(n.path, r),
17779
17868
  value: n.value[r]
17780
17869
  };
17781
17870
  t.push(i), e(i);
@@ -17784,16 +17873,16 @@ function Zb(e, t) {
17784
17873
  for (let t of n) e(t);
17785
17874
  } else if (e.type === "filter") {
17786
17875
  for (let r of n) if (Array.isArray(r.value)) r.value.forEach((n, i) => {
17787
- Yb(e.filter, n) && t.push({
17788
- path: Xb(r.path, i),
17876
+ Zb(e.filter, n) && t.push({
17877
+ path: Qb(r.path, i),
17789
17878
  value: n,
17790
17879
  index: i
17791
17880
  });
17792
17881
  });
17793
17882
  else if (r.value != null && typeof r.value == "object") for (let n of Object.keys(r.value)) {
17794
17883
  let i = r.value[n];
17795
- Yb(e.filter, i) && t.push({
17796
- path: Xb(r.path, n),
17884
+ Zb(e.filter, i) && t.push({
17885
+ path: Qb(r.path, n),
17797
17886
  value: i
17798
17887
  });
17799
17888
  }
@@ -17802,7 +17891,7 @@ function Zb(e, t) {
17802
17891
  }
17803
17892
  return n;
17804
17893
  }
17805
- function Qb(e, t) {
17894
+ function ex(e, t) {
17806
17895
  let n = e.length, r = t.length;
17807
17896
  if (!n) return r;
17808
17897
  if (!r) return n;
@@ -17818,7 +17907,7 @@ function Qb(e, t) {
17818
17907
  }
17819
17908
  return i[r];
17820
17909
  }
17821
- function $b(e, t, n = {}) {
17910
+ function tx(e, t, n = {}) {
17822
17911
  let r = n.mode || "substring", i = n.limit ?? 50, a = n.matchKey !== !1, o = [], s = null;
17823
17912
  if (r === "regex") try {
17824
17913
  s = new RegExp(t, "i");
@@ -17828,11 +17917,11 @@ function $b(e, t, n = {}) {
17828
17917
  let c = (e, l, u) => {
17829
17918
  if (o.length >= i || e == null) return;
17830
17919
  if (typeof e == "object") {
17831
- if (Array.isArray(e)) e.forEach((e, t) => c(e, Xb(l, t), String(t)));
17832
- else for (let t of Object.keys(e)) c(e[t], Xb(l, t), t);
17920
+ if (Array.isArray(e)) e.forEach((e, t) => c(e, Qb(l, t), String(t)));
17921
+ else for (let t of Object.keys(e)) c(e[t], Qb(l, t), t);
17833
17922
  return;
17834
17923
  }
17835
- let d = String(e), f = ex(d, t, r, n.fuzzyThreshold ?? 2, s);
17924
+ let d = String(e), f = nx(d, t, r, n.fuzzyThreshold ?? 2, s);
17836
17925
  if (f) {
17837
17926
  o.push({
17838
17927
  path: l,
@@ -17843,7 +17932,7 @@ function $b(e, t, n = {}) {
17843
17932
  return;
17844
17933
  }
17845
17934
  if (a && u) {
17846
- let e = ex(u, t, r, n.fuzzyThreshold ?? 2, s);
17935
+ let e = nx(u, t, r, n.fuzzyThreshold ?? 2, s);
17847
17936
  e && o.push({
17848
17937
  path: l,
17849
17938
  key: u,
@@ -17854,18 +17943,18 @@ function $b(e, t, n = {}) {
17854
17943
  };
17855
17944
  return c(e, ""), o;
17856
17945
  }
17857
- function ex(e, t, n, r, i) {
17946
+ function nx(e, t, n, r, i) {
17858
17947
  let a = e.toLowerCase(), o = t.toLowerCase();
17859
17948
  if (n === "substring") return a.includes(o) ? 1 : null;
17860
17949
  if (n === "regex") return i && i.test(e) ? 1 : null;
17861
17950
  if (n === "fuzzy") {
17862
17951
  if (a.includes(o)) return 2;
17863
- let e = Qb(a, o);
17952
+ let e = ex(a, o);
17864
17953
  return e <= r ? r - e + 1 : null;
17865
17954
  }
17866
17955
  return null;
17867
17956
  }
17868
- var tx = [
17957
+ var rx = [
17869
17958
  "self.fetch = () => { throw new Error('fetch 已被沙箱禁用') }",
17870
17959
  "self.XMLHttpRequest = function(){ throw new Error('XMLHttpRequest 已被沙箱禁用') }",
17871
17960
  "self.importScripts = () => { throw new Error('importScripts 已被沙箱禁用') }",
@@ -17877,7 +17966,7 @@ var tx = [
17877
17966
  "try { self.EventSource = undefined } catch {}",
17878
17967
  "try { self.BroadcastChannel = undefined } catch {}",
17879
17968
  "if (self.navigator && self.navigator.sendBeacon) self.navigator.sendBeacon = () => { throw new Error('sendBeacon 已被沙箱禁用') }"
17880
- ].join("\n"), nx = [
17969
+ ].join("\n"), ix = [
17881
17970
  {
17882
17971
  re: /\bimport\s*\(/,
17883
17972
  msg: "动态 import() 拉外网模块"
@@ -17903,8 +17992,8 @@ var tx = [
17903
17992
  msg: "require() 拉模块"
17904
17993
  }
17905
17994
  ];
17906
- function rx(e, t, n = 3e3) {
17907
- for (let { re: e, msg: n } of nx) if (e.test(t)) return Promise.resolve({
17995
+ function ax(e, t, n = 3e3) {
17996
+ for (let { re: e, msg: n } of ix) if (e.test(t)) return Promise.resolve({
17908
17997
  ok: !1,
17909
17998
  error: `沙箱拒绝执行:脚本含禁用模式(${n})`,
17910
17999
  elapsedMs: 0
@@ -17921,7 +18010,7 @@ function rx(e, t, n = 3e3) {
17921
18010
  elapsedMs: Date.now() - i
17922
18011
  });
17923
18012
  }
17924
- }, s = tx + "\nself.onmessage = async (e) => {\n try {\n const fn = new Function(\"data\", e.data.script);\n try { self.eval = undefined; self.Function = undefined; } catch {}\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;
18013
+ }, s = rx + "\nself.onmessage = async (e) => {\n try {\n const fn = new Function(\"data\", e.data.script);\n try { self.eval = undefined; self.Function = undefined; } catch {}\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;
17925
18014
  try {
17926
18015
  let e = new Blob([s], { type: "application/javascript" });
17927
18016
  c = URL.createObjectURL(e), l = new Worker(c);
@@ -17956,7 +18045,7 @@ function rx(e, t, n = 3e3) {
17956
18045
  }
17957
18046
  //#endregion
17958
18047
  //#region src/core/tools/dataOps.ts
17959
- var ix = /* @__PURE__ */ new Set([
18048
+ var ox = /* @__PURE__ */ new Set([
17960
18049
  "describe_data",
17961
18050
  "get_data",
17962
18051
  "set_data",
@@ -17968,11 +18057,11 @@ var ix = /* @__PURE__ */ new Set([
17968
18057
  "diff_data",
17969
18058
  "draft_write",
17970
18059
  "draft_commit"
17971
- ]), ax = /* @__PURE__ */ new Set(["read", "write"]);
17972
- function ox(e, t = "simple") {
17973
- return t === "advanced" ? e : t === "minimal" ? e.filter((e) => ax.has(e.name)) : e.filter((e) => !ix.has(e.name));
18060
+ ]), sx = /* @__PURE__ */ new Set(["read", "write"]);
18061
+ function cx(e, t = "simple") {
18062
+ return t === "advanced" ? e : t === "minimal" ? e.filter((e) => sx.has(e.name)) : e.filter((e) => !ox.has(e.name));
17974
18063
  }
17975
- function sx(e) {
18064
+ function lx(e) {
17976
18065
  let { bindRef: t, value: n, schema: r, allowKeys: i, snapshots: a, maxSnapshots: o, audit: s, dryRun: c, op: l = "set" } = e, u = r.safeParse(n);
17977
18066
  if (!u.success) return {
17978
18067
  ok: !1,
@@ -17991,24 +18080,106 @@ function sx(e) {
17991
18080
  hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹(如 {value:\"x\"})或集成方通过 sdk.setData 替换 bind"
17992
18081
  })
17993
18082
  };
17994
- let d = _b(t), f = a.length ? a[a.length - 1].id + 1 : 1;
18083
+ let d = yb(t), f = a.length ? a[a.length - 1].id + 1 : 1;
17995
18084
  for (a.push({
17996
18085
  id: f,
17997
18086
  ts: Date.now(),
17998
18087
  op: l,
17999
18088
  value: d
18000
18089
  }); a.length > o;) a.shift();
18001
- return u.data !== null && typeof u.data == "object" && (i ? pb(t, u.data) : Db(t, u.data)), s({
18090
+ return u.data !== null && typeof u.data == "object" && (i ? hb(t, u.data) : kb(t, u.data)), s({
18002
18091
  op: l,
18003
18092
  value: u.data,
18004
18093
  timestamp: Date.now()
18005
18094
  }), e.onWrite?.(), {
18006
18095
  ok: !0,
18007
- hash: Cb(t),
18096
+ hash: Tb(t),
18008
18097
  data: u.data
18009
18098
  };
18010
18099
  }
18011
- function cx(e, n = {}) {
18100
+ function ux(e) {
18101
+ let { bindRef: t, patches: n, schema: r, allowKeys: i, snapshots: a, maxSnapshots: o, markDataDirty: s, schemaErrorMode: c = "zod", snapshotLabel: l, dryRun: u } = e, d = yb(t), f = [];
18102
+ for (let e = 0; e < n.length; e++) {
18103
+ let t = n[e], a = t.jsonPath || "";
18104
+ if (mb(a)) return {
18105
+ ok: !1,
18106
+ error: $({
18107
+ code: "PATH_UNSAFE",
18108
+ message: `patches[${e}] jsonPath "${a}" 含非法段`,
18109
+ hint: "使用正常属性路径,如 components.0.text"
18110
+ })
18111
+ };
18112
+ if (!ty(a, r, i)) return {
18113
+ ok: !1,
18114
+ error: $({
18115
+ code: "PATH_DENIED",
18116
+ message: `patches[${e}] @ "${a}" 不在 schema 声明字段内`,
18117
+ hint: "仅 schema 声明的 key 可写"
18118
+ })
18119
+ };
18120
+ let o = t.op ?? "set", s;
18121
+ if (o !== "remove") {
18122
+ if (t.value === void 0 || t.value === "") return {
18123
+ ok: !1,
18124
+ error: $({
18125
+ code: "MISSING_VALUE",
18126
+ message: `patches[${e}] ${o} 操作需要 value`,
18127
+ hint: `op 为 ${o} 时 value 必填;删除请用 op:'remove'`
18128
+ })
18129
+ };
18130
+ let n = bb(t.value);
18131
+ if (n.parseError) return {
18132
+ ok: !1,
18133
+ error: Ug(`patches[${e}]`, t.value, n.parseError)
18134
+ };
18135
+ s = n.parsed;
18136
+ }
18137
+ let c = Eb(d, o, a, s);
18138
+ if (c) return {
18139
+ ok: !1,
18140
+ error: $({
18141
+ code: "PATCH_FAILED",
18142
+ message: `patches[${e}]: ${c}`,
18143
+ hint: "检查 op 与目标类型:merge 需对象,append 需数组"
18144
+ })
18145
+ };
18146
+ f.push({
18147
+ op: o,
18148
+ jp: a,
18149
+ value: s
18150
+ });
18151
+ }
18152
+ let p = r.safeParse(d);
18153
+ if (!p.success) return {
18154
+ ok: !1,
18155
+ error: c === "schema_invalid" ? $({
18156
+ code: "SCHEMA_INVALID",
18157
+ message: "patches 应用后整体校验失败,未写入",
18158
+ hint: "确认 patches 合并后整体仍符合 schema",
18159
+ details: Vg(p.error.issues)
18160
+ }) : Hg("", p.error.issues)
18161
+ };
18162
+ if (u) return {
18163
+ ok: !0,
18164
+ applied: f,
18165
+ clone: d
18166
+ };
18167
+ let m = a.length ? a[a.length - 1].id + 1 : 1;
18168
+ for (a.push({
18169
+ id: m,
18170
+ ts: Date.now(),
18171
+ op: "edit",
18172
+ value: yb(t),
18173
+ ...l ? { label: l } : {}
18174
+ }); a.length > o;) a.shift();
18175
+ for (let e of f) Db(t, e.op, e.jp, e.value);
18176
+ return s?.(), {
18177
+ ok: !0,
18178
+ applied: f,
18179
+ clone: d
18180
+ };
18181
+ }
18182
+ function dx(e, n = {}) {
18012
18183
  let i = e.schema, a = e.bind, o = e.description ?? "主数据对象", s = ey(i), c = [], l = n.maxSnapshots ?? 20, u, d = n.autoLock !== !1, f = !0;
18013
18184
  function p() {
18014
18185
  f = !0;
@@ -18034,7 +18205,7 @@ function cx(e, n = {}) {
18034
18205
  n.onAudit?.(e);
18035
18206
  };
18036
18207
  function g(e, t) {
18037
- let n = _b(a), r = c.length ? c[c.length - 1].id + 1 : 1;
18208
+ let n = yb(a), r = c.length ? c[c.length - 1].id + 1 : 1;
18038
18209
  for (c.push({
18039
18210
  id: r,
18040
18211
  ts: Date.now(),
@@ -18046,12 +18217,12 @@ function cx(e, n = {}) {
18046
18217
  }
18047
18218
  async function _(e, t, r) {
18048
18219
  if (!t || t === "") return null;
18049
- let i = Cb(a);
18220
+ let i = Tb(a);
18050
18221
  if (i === t) return null;
18051
18222
  if (!n.onConflict) return $({
18052
18223
  code: "VERSION_CONFLICT",
18053
18224
  message: `乐观锁冲突:expectedHash=${t} 但当前 hash=${i}。主数据在你 read 之后已被修改(外部代码/其他 agent/用户手动改)。`,
18054
- hint: `重新 read 拿最新值与 hash,基于最新值修改后再写入(传新的 expectedHash)。当前值:${xb(a, 400)}`
18225
+ hint: `重新 read 拿最新值与 hash,基于最新值修改后再写入(传新的 expectedHash)。当前值:${Cb(a, 400)}`
18055
18226
  });
18056
18227
  let o = await n.onConflict({
18057
18228
  op: e,
@@ -18061,11 +18232,11 @@ function cx(e, n = {}) {
18061
18232
  expectedHash: t,
18062
18233
  snapshotId: 0
18063
18234
  });
18064
- if (o.action === "keep_external") return `已保留外部修改(未写入)。当前值:${xb(a, 400)} (hash=${i})。请重新 read 拿最新值与 hash 再改。`;
18235
+ if (o.action === "keep_external") return `已保留外部修改(未写入)。当前值:${Cb(a, 400)} (hash=${i})。请重新 read 拿最新值与 hash 再改。`;
18065
18236
  if (o.action === "restore") {
18066
- if (!c.length) return `无历史快照可回退(本次为首次操作)。当前值:${xb(a, 400)} (hash=${i})。请重新 read 再改或选「强制覆盖」。`;
18237
+ if (!c.length) return `无历史快照可回退(本次为首次操作)。当前值:${Cb(a, 400)} (hash=${i})。请重新 read 再改或选「强制覆盖」。`;
18067
18238
  let e = c[c.length - 1];
18068
- return Eb(a, _b(e.value)), p(), `已回退主数据到历史快照 #${e.id}[${e.op}]。当前值:${xb(a, 400)} (hash=${Cb(a)})。请基于回退后的值重写或停止。`;
18239
+ return Ob(a, yb(e.value)), p(), `已回退主数据到历史快照 #${e.id}[${e.op}]。当前值:${Cb(a, 400)} (hash=${Tb(a)})。请基于回退后的值重写或停止。`;
18069
18240
  }
18070
18241
  return null;
18071
18242
  }
@@ -18075,7 +18246,7 @@ function cx(e, n = {}) {
18075
18246
  schema: t.object({})
18076
18247
  }), y = r(async ({ jsonPath: e }) => {
18077
18248
  let t = e || "";
18078
- if (fb(t)) return $({
18249
+ if (mb(t)) return $({
18079
18250
  code: "PATH_UNSAFE",
18080
18251
  message: `jsonPath "${t}" 含非法段(__proto__/constructor/prototype)`,
18081
18252
  hint: "使用正常属性路径,如 components.0.text(数组索引用数字)"
@@ -18085,10 +18256,10 @@ function cx(e, n = {}) {
18085
18256
  message: `get_data @ "${t}" 不在 schema 声明字段内(仅 schema 声明的 key 可读)`,
18086
18257
  hint: "主数据仅暴露 schema 声明的字段;若需操作该字段,集成方需在 schema 中声明它"
18087
18258
  });
18088
- let n = t ? mb(a, t) : a;
18259
+ let n = t ? gb(a, t) : a;
18089
18260
  t || (n = ay(n, s));
18090
- let r = Cb(a);
18091
- return u = r, n === void 0 ? `主数据${t ? ` @ ${t}` : ""} = (undefined) (hash=${r})` : `主数据${t ? ` @ ${t}` : ""} = ${xb(n)} (hash=${r})`;
18261
+ let r = Tb(a);
18262
+ return u = r, n === void 0 ? `主数据${t ? ` @ ${t}` : ""} = (undefined) (hash=${r})` : `主数据${t ? ` @ ${t}` : ""} = ${Cb(n)} (hash=${r})`;
18092
18263
  }, {
18093
18264
  name: "get_data",
18094
18265
  description: "读取主数据的当前值(安全序列化:函数/DOM/循环引用做摘要;大结果由系统自动外存,提示用 vfs_read 回读)。返回含 hash(乐观锁):改前先 read/get 拿 hash,写入时传 expectedHash 回传,系统对比当前 hash 防\"基于过期值覆盖\"。jsonPath 可选:读整个主数据不传,读子路径传(如 components.0.text)。",
@@ -18096,9 +18267,9 @@ function cx(e, n = {}) {
18096
18267
  }), b = r(async ({ value: e, expectedHash: t }) => {
18097
18268
  let n = await _("set", t || (d ? u : void 0));
18098
18269
  if (n !== null) return n;
18099
- let r = vb(e);
18270
+ let r = bb(e);
18100
18271
  if (r.parseError) return Ug("", e, r.parseError);
18101
- let o = sx({
18272
+ let o = lx({
18102
18273
  bindRef: a,
18103
18274
  value: r.parsed,
18104
18275
  schema: i,
@@ -18108,7 +18279,7 @@ function cx(e, n = {}) {
18108
18279
  audit: h,
18109
18280
  onWrite: p
18110
18281
  });
18111
- return o.ok ? (u = o.hash, `已设置主数据 = ${xb(o.data, 600)} (新 hash=${o.hash})${s ? "(白名单模式:仅更新 schema 声明字段,未声明字段保留)" : ""}`) : o.error;
18282
+ return o.ok ? (u = o.hash, `已设置主数据 = ${Cb(o.data, 600)} (新 hash=${o.hash})${s ? "(白名单模式:仅更新 schema 声明字段,未声明字段保留)" : ""}`) : o.error;
18112
18283
  }, {
18113
18284
  name: "set_data",
18114
18285
  description: "设置主数据的值(整体替换)。value 为 JSON 对象(或 JSON 字符串),需通过 schema 校验。校验失败会返回错误而非写入。expectedHash(可选):改前 read/get 返回的 hash,传入则启用乐观锁;不传时系统自动用你最后一次读到的 hash 比对(autoLock,默认开)。大对象/数组强烈建议改用 edit_data 增量 patch。白名单模式(schema 为 ZodObject 子集):set 为根级浅合并,深层子对象整体替换(未传字段丢失);保留深层字段请用 edit_data({op:\"merge\", jsonPath:\"子路径\", value:{...}})局部合并。",
@@ -18123,48 +18294,46 @@ function cx(e, n = {}) {
18123
18294
  message: "edit_data 需要 op(set/remove/merge/append)",
18124
18295
  hint: "顶层 op 或 patch.op 至少传一个"
18125
18296
  });
18126
- let c = n || "";
18127
- if (fb(c)) return $({
18297
+ let f = n || "";
18298
+ if (mb(f)) return $({
18128
18299
  code: "PATH_UNSAFE",
18129
- message: `jsonPath "${c}" 含非法段(__proto__/constructor/prototype)`,
18300
+ message: `jsonPath "${f}" 含非法段(__proto__/constructor/prototype)`,
18130
18301
  hint: "使用正常的属性路径,如 components.0.text(数组索引用数字)"
18131
18302
  });
18132
- if (!ty(c, i, s)) return $({
18303
+ if (!ty(f, i, s)) return $({
18133
18304
  code: "PATH_DENIED",
18134
- message: `edit_data @ "${c}" 不在 schema 声明字段内`,
18305
+ message: `edit_data @ "${f}" 不在 schema 声明字段内`,
18135
18306
  hint: "仅 schema 声明的 key 可写;若需操作该字段,集成方需在 schema 中声明它"
18136
18307
  });
18137
- let l = await _("edit", o || (d ? u : void 0));
18138
- if (l !== null) return l;
18308
+ let m = await _("edit", o || (d ? u : void 0));
18309
+ if (m !== null) return m;
18139
18310
  if (typeof a != "object" || !a) return $({
18140
18311
  code: "NOT_OBJECT",
18141
18312
  message: `edit 仅适用于对象/数组主数据,当前是 ${a === void 0 ? "undefined" : typeof a}`,
18142
18313
  hint: "叶子(原始类型)请用 set_data 整体设置"
18143
18314
  });
18144
- let f;
18145
- if (t !== "remove") {
18146
- if (r === void 0 || r === "") return $({
18147
- code: "MISSING_VALUE",
18148
- message: `${t} 操作需要 value`,
18149
- hint: `op 为 ${t} 时 value 必填;删除请用 op:'remove'`
18150
- });
18151
- let e = vb(r);
18152
- if (e.parseError) return Ug("", r, e.parseError);
18153
- f = e.parsed;
18154
- }
18155
- let m = _b(a), v = wb(m, t, c, f);
18156
- if (v) return $({
18157
- code: "PATCH_FAILED",
18158
- message: v,
18159
- hint: "检查 op 与目标类型:merge 需对象,append 需数组;jsonPath 指向需存在"
18315
+ let g = ux({
18316
+ bindRef: a,
18317
+ patches: [{
18318
+ op: t,
18319
+ jsonPath: f,
18320
+ value: r
18321
+ }],
18322
+ schema: i,
18323
+ allowKeys: s,
18324
+ snapshots: c,
18325
+ maxSnapshots: l,
18326
+ markDataDirty: p,
18327
+ schemaErrorMode: "zod"
18160
18328
  });
18161
- let y = i.safeParse(m);
18162
- return y.success ? (g("edit"), Tb(a, t, c, f), p(), h({
18329
+ if (!g.ok) return g.error;
18330
+ let v = g.applied[0];
18331
+ return h({
18163
18332
  op: "edit",
18164
- detail: `${t}${c ? "@" + c : ""}`,
18165
- value: f,
18333
+ detail: `${v.op}${f ? "@" + f : ""}`,
18334
+ value: v.value,
18166
18335
  timestamp: Date.now()
18167
- }), u = Cb(a), `已 edit 主数据(${t}${c ? " @ " + c : ""})。当前值:${xb(a, 600)} (新 hash=${Cb(a)})`) : Hg("", y.error.issues);
18336
+ }), u = Tb(a), `已 edit 主数据(${v.op}${f ? " @ " + f : ""})。当前值:${Cb(a, 600)} (新 hash=${Tb(a)})`;
18168
18337
  }, {
18169
18338
  name: "edit_data",
18170
18339
  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,默认开)防\"基于过期值覆盖\"。",
@@ -18195,7 +18364,7 @@ function cx(e, n = {}) {
18195
18364
  message: "delete_data 需要 jsonPath 指定要删的子路径(主数据整体不可删,用 set_data 整体替换)",
18196
18365
  hint: "如 jsonPath:\"components.0\" 删数组首项"
18197
18366
  });
18198
- if (fb(e)) return $({
18367
+ if (mb(e)) return $({
18199
18368
  code: "PATH_UNSAFE",
18200
18369
  message: `jsonPath "${e}" 含非法段`,
18201
18370
  hint: "使用正常属性路径"
@@ -18208,12 +18377,12 @@ function cx(e, n = {}) {
18208
18377
  let n = await _("delete", t || (d ? u : void 0));
18209
18378
  if (n !== null) return n;
18210
18379
  g("delete");
18211
- let r = gb(a, e);
18380
+ let r = vb(a, e);
18212
18381
  return p(), h({
18213
18382
  op: "delete",
18214
18383
  detail: e,
18215
18384
  timestamp: Date.now()
18216
- }), u = Cb(a), r ? `已删除主数据 @ ${e}` : `主数据 @ ${e} 不存在(无需删除)`;
18385
+ }), u = Tb(a), r ? `已删除主数据 @ ${e}` : `主数据 @ ${e} 不存在(无需删除)`;
18217
18386
  }, {
18218
18387
  name: "delete_data",
18219
18388
  description: "删除主数据的某个子路径(jsonPath)。主数据整体不可删(用 set_data 整体替换)。expectedHash(可选):改前 read/get 返回的 hash;不传时自动用你最后读到的 hash(autoLock,默认开)防\"基于过期值删除\"。",
@@ -18249,11 +18418,11 @@ function cx(e, n = {}) {
18249
18418
  hint: "用 list_data_snapshots 查看可用快照序号"
18250
18419
  });
18251
18420
  let n = i.safeParse(t.value);
18252
- return n.success ? (Eb(a, _b(t.value)), p(), h({
18421
+ return n.success ? (Ob(a, yb(t.value)), p(), h({
18253
18422
  op: "restore",
18254
18423
  detail: `#${t.id}`,
18255
18424
  timestamp: Date.now()
18256
- }), u = Cb(a), `已回退主数据到快照 #${t.id}[${t.op}]${t.label ? `(${t.label})` : ""}。`) : $({
18425
+ }), u = Tb(a), `已回退主数据到快照 #${t.id}[${t.op}]${t.label ? `(${t.label})` : ""}。`) : $({
18257
18426
  code: "SNAPSHOT_SCHEMA_INVALID",
18258
18427
  message: `快照 #${t.id} 的值不符合当前 schema,无法回退`,
18259
18428
  hint: "schema 可能已变更;该快照已过期,选其他快照或重新设置",
@@ -18275,9 +18444,9 @@ function cx(e, n = {}) {
18275
18444
  message: `未找到快照 #${e}`,
18276
18445
  hint: "不传 id 查看最近一次;或用 list_data_snapshots(advanced) 查看可用序号"
18277
18446
  });
18278
- let r = _b(n.value), a = t || "";
18447
+ let r = yb(n.value), a = t || "";
18279
18448
  if (a) {
18280
- if (fb(a)) return $({
18449
+ if (mb(a)) return $({
18281
18450
  code: "PATH_UNSAFE",
18282
18451
  message: `jsonPath "${a}" 含非法段`,
18283
18452
  hint: "使用正常属性路径"
@@ -18287,11 +18456,11 @@ function cx(e, n = {}) {
18287
18456
  message: `history_data @ "${a}" 不在 schema 声明字段内`,
18288
18457
  hint: "仅 schema 声明的 key 可读"
18289
18458
  });
18290
- r = mb(r, a);
18459
+ r = gb(r, a);
18291
18460
  let e = ry(i, a);
18292
18461
  e && (r = iy(r, e));
18293
18462
  } else s && (r = iy(r, i));
18294
- return `快照 #${n.id}[${n.op}]${n.label ? `(${n.label})` : ""}${a ? ` @ ${a}` : ""} = ${xb(r)}`;
18463
+ return `快照 #${n.id}[${n.op}]${n.label ? `(${n.label})` : ""}${a ? ` @ ${a}` : ""} = ${Cb(r)}`;
18295
18464
  }, {
18296
18465
  name: "history_data",
18297
18466
  description: "只读查看某次快照(默认最近一次)的内容,不回退当前主数据。看上一版长啥样而不影响当前(冲突诊断/verify 自纠/用户问\"刚才改了啥\")。可选 id 指定快照序号、jsonPath 只看子路径(按 schema 投影)。",
@@ -18307,7 +18476,7 @@ function cx(e, n = {}) {
18307
18476
  });
18308
18477
  let n = s ? ay(a, s) : a, r;
18309
18478
  try {
18310
- r = Zb(n, e);
18479
+ r = $b(n, e);
18311
18480
  } catch (t) {
18312
18481
  return $({
18313
18482
  code: "JSONPATH_SYNTAX",
@@ -18316,7 +18485,7 @@ function cx(e, n = {}) {
18316
18485
  details: { expr: e }
18317
18486
  });
18318
18487
  }
18319
- 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":${xb(e.value)}}`);
18488
+ 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":${Cb(e.value)}}`);
18320
18489
  return `{"matched":${r.length},"returned":${o.length},"truncated":${r.length > i},"results":[${c.join(",")}]}`;
18321
18490
  }, {
18322
18491
  name: "query_data",
@@ -18331,13 +18500,13 @@ function cx(e, n = {}) {
18331
18500
  message: "主数据为空,无可搜索内容"
18332
18501
  });
18333
18502
  try {
18334
- let o = $b(s ? ay(a, s) : a, e, {
18503
+ let o = tx(s ? ay(a, s) : a, e, {
18335
18504
  mode: t,
18336
18505
  fuzzyThreshold: n,
18337
18506
  matchKey: r,
18338
18507
  limit: i ?? 50
18339
18508
  });
18340
- return xb({
18509
+ return Cb({
18341
18510
  matched: o.length,
18342
18511
  results: o
18343
18512
  });
@@ -18376,44 +18545,47 @@ function cx(e, n = {}) {
18376
18545
  message: `eval_script @ "${r}" 不在 schema 声明字段内`,
18377
18546
  hint: "仅 schema 声明的 key 可作为子树"
18378
18547
  });
18379
- if (o = mb(a, r), s) {
18548
+ if (o = gb(a, r), s) {
18380
18549
  let e = ry(i, r);
18381
18550
  e && (o = iy(o, e));
18382
18551
  }
18383
18552
  } else o = s ? ay(a, s) : a;
18384
- let c = _b(o), l = await rx(c, e, r && JSON.stringify(c).length > 1e5 ? 8e3 : 3e3);
18385
- if (!l.ok) {
18386
- let t = /超时/.test(l.error || "");
18553
+ let d = yb(o), f = await ax(d, e, r && JSON.stringify(d).length > 1e5 ? 8e3 : 3e3);
18554
+ if (!f.ok) {
18555
+ let t = /超时/.test(f.error || "");
18387
18556
  return $({
18388
18557
  code: t ? "SCRIPT_TIMEOUT" : "SCRIPT_ERROR",
18389
- message: `脚本执行失败: ${l.error}`,
18558
+ message: `脚本执行失败: ${f.error}`,
18390
18559
  hint: t ? "脚本可能有死循环或过重计算;加边界检查/分批;transform 返回完整新值勿返回巨大中间结果" : "检查脚本语法与运行时错误;入参为 data(主数据深拷贝),沙箱内禁用 fetch/XHR/WebSocket",
18391
18560
  details: {
18392
- elapsedMs: l.elapsedMs,
18561
+ elapsedMs: f.elapsedMs,
18393
18562
  scriptLen: e.length
18394
18563
  }
18395
18564
  });
18396
18565
  }
18397
18566
  if (t === "transform") {
18398
- let e = l.result;
18567
+ let e = f.result;
18399
18568
  if (r) {
18400
- let t = _b(a), n = wb(t, "set", r, e);
18401
- if (n) return $({
18402
- code: "PATCH_FAILED",
18403
- message: `eval 子树 transform @ "${r}" 失败: ${n}`,
18404
- hint: "检查子路径:set 需父为对象/数组"
18569
+ let t = ux({
18570
+ bindRef: a,
18571
+ patches: [{
18572
+ op: "set",
18573
+ jsonPath: r,
18574
+ value: e
18575
+ }],
18576
+ schema: i,
18577
+ allowKeys: s,
18578
+ snapshots: c,
18579
+ maxSnapshots: l,
18580
+ markDataDirty: p,
18581
+ schemaErrorMode: "schema_invalid",
18582
+ snapshotLabel: "eval_transform_subtree"
18405
18583
  });
18406
- let o = i.safeParse(t);
18407
- return o.success ? (g("edit", "eval_transform_subtree"), Tb(a, "set", r, e), p(), h({
18584
+ return t.ok ? (h({
18408
18585
  op: "edit",
18409
18586
  detail: `eval_transform_subtree @ ${r}`,
18410
18587
  timestamp: Date.now()
18411
- }), u = Cb(a), `已通过脚本 transform 子树 @ ${r} 更新(耗时 ${l.elapsedMs}ms)。当前值: ${xb(a, 600)}`) : $({
18412
- code: "SCHEMA_INVALID",
18413
- message: `脚本返回值作为子树 @ "${r}" 后整体校验失败,未写入`,
18414
- hint: `确认返回值符合 ${r} 处的子 schema`,
18415
- details: Vg(o.error.issues)
18416
- });
18588
+ }), u = Tb(a), `已通过脚本 transform 子树 @ ${r} 更新(耗时 ${f.elapsedMs}ms)。当前值: ${Cb(a, 600)}`) : t.error;
18417
18589
  }
18418
18590
  if (e && typeof e == "object" && !Array.isArray(e) && "patches" in e && Array.isArray(e.patches)) {
18419
18591
  if (typeof a != "object" || !a) return $({
@@ -18421,77 +18593,43 @@ function cx(e, n = {}) {
18421
18593
  message: `主数据 bind 为原始类型(${a === null ? "null" : typeof a}),eval transform(patches) 无法就地替换`,
18422
18594
  hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹或集成方通过 sdk.setData 替换 bind"
18423
18595
  });
18424
- let t = e.patches, n = _b(a), r = [];
18425
- for (let e = 0; e < t.length; e++) {
18426
- let a = t[e], o = a.jsonPath || "";
18427
- if (fb(o)) return $({
18428
- code: "PATH_UNSAFE",
18429
- message: `patches[${e}] jsonPath "${o}" 含非法段`,
18430
- hint: "使用正常属性路径"
18431
- });
18432
- if (!ty(o, i, s)) return $({
18433
- code: "PATH_DENIED",
18434
- message: `patches[${e}] @ "${o}" 不在 schema 声明字段内`,
18435
- hint: "仅 schema 声明的 key 可写"
18436
- });
18437
- let c = a.op, l;
18438
- if (c !== "remove") {
18439
- if (a.value === void 0 || a.value === "") return $({
18440
- code: "MISSING_VALUE",
18441
- message: `patches[${e}] ${c} 操作需要 value`,
18442
- hint: `op 为 ${c} 时 value 必填`
18443
- });
18444
- let t = vb(a.value);
18445
- if (t.parseError) return Ug(`patches[${e}]`, a.value, t.parseError);
18446
- l = t.parsed;
18447
- }
18448
- let u = wb(n, c, o, l);
18449
- if (u) return $({
18450
- code: "PATCH_FAILED",
18451
- message: `patches[${e}]: ${u}`,
18452
- hint: "检查 op 与目标类型:merge 需对象,append 需数组"
18453
- });
18454
- r.push({
18455
- op: c,
18456
- jp: o,
18457
- value: l
18458
- });
18459
- }
18460
- let o = i.safeParse(n);
18461
- if (!o.success) return $({
18462
- code: "SCHEMA_INVALID",
18463
- message: "脚本 patches 应用后整体校验失败,未写入",
18464
- hint: "确认 patches 合并后整体仍符合 schema",
18465
- details: Vg(o.error.issues)
18596
+ let t = ux({
18597
+ bindRef: a,
18598
+ patches: e.patches,
18599
+ schema: i,
18600
+ allowKeys: s,
18601
+ snapshots: c,
18602
+ maxSnapshots: l,
18603
+ markDataDirty: p,
18604
+ schemaErrorMode: "schema_invalid",
18605
+ snapshotLabel: "eval_transform"
18466
18606
  });
18467
- g("edit", "eval_transform");
18468
- for (let e of r) Tb(a, e.op, e.jp, e.value);
18469
- return p(), h({
18607
+ return t.ok ? (h({
18470
18608
  op: "edit",
18471
- detail: `eval_transform(${r.length} patches)`,
18609
+ detail: `eval_transform(${t.applied.length} patches)`,
18472
18610
  timestamp: Date.now()
18473
- }), u = Cb(a), `已通过脚本 transform(patches) 更新主数据(${r.length} 个 patch,耗时 ${l.elapsedMs}ms)。当前值: ${xb(a, 600)}`;
18611
+ }), u = Tb(a), `已通过脚本 transform(patches) 更新主数据(${t.applied.length} 个 patch,耗时 ${f.elapsedMs}ms)。当前值: ${Cb(a, 600)}`) : t.error;
18474
18612
  }
18475
18613
  let t = i.safeParse(e);
18476
18614
  return t.success ? typeof a != "object" || !a ? $({
18477
18615
  code: "LEAF_BIND",
18478
18616
  message: `主数据 bind 为原始类型(${a === null ? "null" : typeof a}),eval transform 无法就地替换外部持有的值引用`,
18479
18617
  hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹或集成方通过 sdk.setData 替换 bind"
18480
- }) : (g("edit", "eval_transform"), t.data !== null && typeof t.data == "object" && (s ? pb(a, t.data) : Db(a, t.data)), p(), h({
18618
+ }) : (g("edit", "eval_transform"), t.data !== null && typeof t.data == "object" && (s ? hb(a, t.data) : kb(a, t.data)), p(), h({
18481
18619
  op: "edit",
18482
18620
  detail: "eval_transform",
18483
18621
  timestamp: Date.now()
18484
- }), u = Cb(a), `已通过脚本 transform 更新主数据(耗时 ${l.elapsedMs}ms)。当前值: ${xb(a, 600)}`) : $({
18622
+ }), u = Tb(a), `已通过脚本 transform 更新主数据(耗时 ${f.elapsedMs}ms)。当前值: ${Cb(a, 600)}`) : $({
18485
18623
  code: "SCHEMA_INVALID",
18486
18624
  message: "脚本返回值校验失败,未写入(transform 模式要求返回主数据的完整新值且符合 schema)",
18487
18625
  hint: "确认脚本 return 了完整新值(非部分);或返回 {patches:[...]} 走增量模式;按 describe_data() 查看格式",
18488
18626
  details: Vg(t.error.issues)
18489
18627
  });
18490
18628
  }
18491
- return xb({
18629
+ return Cb({
18492
18630
  ok: !0,
18493
- result: l.result,
18494
- elapsedMs: l.elapsedMs
18631
+ result: f.result,
18632
+ elapsedMs: f.elapsedMs
18495
18633
  });
18496
18634
  }, {
18497
18635
  name: "eval_script",
@@ -18502,12 +18640,12 @@ function cx(e, n = {}) {
18502
18640
  jsonPath: t.string().optional().describe("子树模式:仅对 jsonPath 指向的子树执行(降低大 JSON 成本);transform 时返回值作为该子树新值")
18503
18641
  })
18504
18642
  }), A = r(async ({ jsonPath: e, jsonPaths: t, fields: r, depth: c, offset: l, limit: d }) => {
18505
- let f = Cb(a);
18643
+ let f = Tb(a);
18506
18644
  if (u = f, t && t.length) {
18507
18645
  let e = t.map((e) => {
18508
18646
  let t = e || "";
18509
18647
  if (!ty(t, i, s)) return `- ${t || "(根)"}: [PATH_DENIED: 不在 schema 声明字段内]`;
18510
- let o = t ? mb(a, t) : a;
18648
+ let o = t ? gb(a, t) : a;
18511
18649
  if (!t) o = ay(o, s);
18512
18650
  else if (s) {
18513
18651
  let e = ry(i, t);
@@ -18519,12 +18657,12 @@ function cx(e, n = {}) {
18519
18657
  } catch (e) {
18520
18658
  return `- ${t}: [READ_INTERCEPT: ${e.message}]`;
18521
18659
  }
18522
- return r && r.length && (l = yb(l, r)), c != null && (l = bb(l, c)), l === void 0 ? `- ${t} = (undefined)` : `- ${t} = ${xb(l)}`;
18660
+ return r && r.length && (l = xb(l, r)), c != null && (l = Sb(l, c)), l === void 0 ? `- ${t} = (undefined)` : `- ${t} = ${Cb(l)}`;
18523
18661
  });
18524
18662
  return `多路径读取(共 ${t.length} 项,hash=${f}):\n${e.join("\n")}`;
18525
18663
  }
18526
18664
  let p = e || "";
18527
- if (fb(p)) return $({
18665
+ if (mb(p)) return $({
18528
18666
  code: "PATH_UNSAFE",
18529
18667
  message: `jsonPath "${p}" 含非法段(__proto__/constructor/prototype)`,
18530
18668
  hint: "使用正常属性路径,如 components.0.text(数组索引数字)"
@@ -18534,7 +18672,7 @@ function cx(e, n = {}) {
18534
18672
  message: `read @ "${p}" 不在 schema 声明字段内`,
18535
18673
  hint: "主数据仅暴露 schema 声明的字段;若需操作该字段,集成方需在 schema 中声明它"
18536
18674
  });
18537
- let m = p ? mb(a, p) : a;
18675
+ let m = p ? gb(a, p) : a;
18538
18676
  if (!p) m = ay(m, s);
18539
18677
  else if (s) {
18540
18678
  let e = ry(i, p);
@@ -18549,13 +18687,13 @@ function cx(e, n = {}) {
18549
18687
  message: `read 拦截器抛错: ${e.message}`
18550
18688
  });
18551
18689
  }
18552
- r && r.length && (h = yb(h, r)), c != null && (h = bb(h, c));
18690
+ r && r.length && (h = xb(h, r)), c != null && (h = Sb(h, c));
18553
18691
  let g = e ? "" : `主数据说明: ${o}\n格式: 写入值需为 JSON,且通过声明的 schema 校验(校验失败时 write 会返回结构化错误)。字段约束(类型/min/max/enum/必填/默认)见 systemPrompt「可操作数据」段,或用 schema_data({ jsonPath }) 按需查。\n\n`, _ = r && r.length ? `(字段裁剪:${r.join(",")})` : "", v = c == null ? "" : `(深度≤${c})`, y = _ || v ? ` ${_}${v}` : "";
18554
18692
  if ((l !== void 0 || d !== void 0) && Array.isArray(h)) {
18555
18693
  let e = h.length, t = Math.max(0, l ?? 0), n = Math.min(200, Math.max(1, d ?? 50)), r = h.slice(t, t + n), i = t + n < e;
18556
- return `${g}主数据${p ? ` @ ${p}` : ""} 数组分页[offset=${t},limit=${n}]${y} = ${xb(r)} (total=${e}, hasMore=${i}) (hash=${f})`;
18694
+ return `${g}主数据${p ? ` @ ${p}` : ""} 数组分页[offset=${t},limit=${n}]${y} = ${Cb(r)} (total=${e}, hasMore=${i}) (hash=${f})`;
18557
18695
  }
18558
- return h === void 0 ? `${g}主数据${p ? ` @ ${p}` : ""}${y} = (undefined) (hash=${f})` : `${g}主数据${p ? ` @ ${p}` : ""}${y} = ${xb(h)} (hash=${f})`;
18696
+ return h === void 0 ? `${g}主数据${p ? ` @ ${p}` : ""}${y} = (undefined) (hash=${f})` : `${g}主数据${p ? ` @ ${p}` : ""}${y} = ${Cb(h)} (hash=${f})`;
18559
18697
  }, {
18560
18698
  name: "read",
18561
18699
  description: "读取主数据(高层入口,合并 describe/get)。不传 jsonPath → 返回主数据说明 + 格式提示(含字段约束);传 jsonPath → 返回该子路径当前值 + hash;传 jsonPaths → 一次读多个不相关子路径(省多轮往返)。hash 用于乐观锁(默认 autoLock,write 时自动比对,无需手动传)。fields(字段裁剪)/depth(深度截断)减体积;offset+limit 对数组目标分页(返回切片 + total/hasMore)。集成方可能经 read 拦截器对返回值脱敏/派生。",
@@ -18598,7 +18736,7 @@ function cx(e, n = {}) {
18598
18736
  }
18599
18737
  let b = d ? u : void 0;
18600
18738
  if (f && b !== void 0) {
18601
- let e = Cb(a);
18739
+ let e = Tb(a);
18602
18740
  if (e !== b) return $({
18603
18741
  code: "VERSION_CONFLICT",
18604
18742
  message: `dryRun 预检发现乐观锁冲突: expectedHash=${b} 当前 hash=${e}(主数据在你 read 后被改)`,
@@ -18611,7 +18749,7 @@ function cx(e, n = {}) {
18611
18749
  message: "delete 需要 patch.jsonPath 指定要删的子路径(主数据整体不可删,用 write(value) 整体替换)",
18612
18750
  hint: "如 patch:{jsonPath:\"components.0\"}, del:true"
18613
18751
  });
18614
- if (fb(t.jsonPath)) return $({
18752
+ if (mb(t.jsonPath)) return $({
18615
18753
  code: "PATH_UNSAFE",
18616
18754
  message: `jsonPath "${t.jsonPath}" 含非法段`,
18617
18755
  hint: "使用正常属性路径"
@@ -18624,16 +18762,16 @@ function cx(e, n = {}) {
18624
18762
  let e = await _("delete", b);
18625
18763
  if (e !== null) return e;
18626
18764
  if (f) {
18627
- let e = _b(a);
18628
- return gb(e, t.jsonPath) ? `dryRun(delete): 将删除 @ ${t.jsonPath}。预览剩余:${xb(e, 600)}。未实际写入、未入快照。` : `dryRun(delete): @ ${t.jsonPath} 不存在(无需删除)。未实际写入。`;
18765
+ let e = yb(a);
18766
+ return vb(e, t.jsonPath) ? `dryRun(delete): 将删除 @ ${t.jsonPath}。预览剩余:${Cb(e, 600)}。未实际写入、未入快照。` : `dryRun(delete): @ ${t.jsonPath} 不存在(无需删除)。未实际写入。`;
18629
18767
  }
18630
18768
  g("delete");
18631
- let n = gb(a, t.jsonPath);
18769
+ let n = vb(a, t.jsonPath);
18632
18770
  return p(), h({
18633
18771
  op: "delete",
18634
18772
  detail: t.jsonPath,
18635
18773
  timestamp: Date.now()
18636
- }), u = Cb(a), n ? `已删除主数据 @ ${t.jsonPath}` : `主数据 @ ${t.jsonPath} 不存在(无需删除)`;
18774
+ }), u = Tb(a), n ? `已删除主数据 @ ${t.jsonPath}` : `主数据 @ ${t.jsonPath} 不存在(无需删除)`;
18637
18775
  }
18638
18776
  if (m === "edit") {
18639
18777
  if (typeof a != "object" || !a) return $({
@@ -18647,59 +18785,29 @@ function cx(e, n = {}) {
18647
18785
  op: t.op ?? "set",
18648
18786
  jsonPath: t.jsonPath || "",
18649
18787
  value: v
18650
- }]), o = _b(a), c = [];
18651
- for (let e = 0; e < n.length; e++) {
18652
- let t = n[e], r = t.jsonPath || "";
18653
- if (fb(r)) return $({
18654
- code: "PATH_UNSAFE",
18655
- message: `patches[${e}] jsonPath "${r}" 含非法段`,
18656
- hint: "使用正常属性路径,如 components.0.text"
18657
- });
18658
- if (!ty(r, i, s)) return $({
18659
- code: "PATH_DENIED",
18660
- message: `patches[${e}] @ "${r}" 不在 schema 声明字段内`,
18661
- hint: "仅 schema 声明的 key 可写"
18662
- });
18663
- let a = t.op ?? "set", l;
18664
- if (a !== "remove") {
18665
- if (t.value === void 0 || t.value === "") return $({
18666
- code: "MISSING_VALUE",
18667
- message: `patches[${e}] ${a} 操作需要 value`,
18668
- hint: `op 为 ${a} 时 value 必填;删除请用 op:'remove'`
18669
- });
18670
- let n = vb(t.value);
18671
- if (n.parseError) return Ug(`patches[${e}]`, t.value, n.parseError);
18672
- l = n.parsed;
18673
- }
18674
- let u = wb(o, a, r, l);
18675
- if (u) return $({
18676
- code: "PATCH_FAILED",
18677
- message: `patches[${e}]: ${u}`,
18678
- hint: "检查 op 与目标类型:merge 需对象,append 需数组"
18679
- });
18680
- c.push({
18681
- op: a,
18682
- jp: r,
18683
- value: l
18684
- });
18685
- }
18686
- let l = i.safeParse(o);
18687
- if (!l.success) return Hg("", l.error.issues);
18688
- if (f) return `dryRun(edit): ${c.length} 个 patch 预检通过(schema 校验 OK)。预览结果:${xb(o, 600)}。未实际写入、未入快照。`;
18689
- g("edit");
18690
- for (let e of c) Tb(a, e.op, e.jp, e.value);
18691
- return p(), h({
18788
+ }]), o = ux({
18789
+ bindRef: a,
18790
+ patches: n,
18791
+ schema: i,
18792
+ allowKeys: s,
18793
+ snapshots: c,
18794
+ maxSnapshots: l,
18795
+ markDataDirty: p,
18796
+ schemaErrorMode: "zod",
18797
+ dryRun: f
18798
+ });
18799
+ return o.ok ? f ? `dryRun(edit): ${o.applied.length} 个 patch 预检通过(schema 校验 OK)。预览结果:${Cb(o.clone, 600)}。未实际写入、未入快照。` : (h({
18692
18800
  op: "edit",
18693
- detail: `${c.length} 个 patch${c.length > 1 ? "(批量)" : ""}`,
18694
- value: c.map((e) => `${e.op}@${e.jp}`),
18801
+ detail: `${o.applied.length} 个 patch${o.applied.length > 1 ? "(批量)" : ""}`,
18802
+ value: o.applied.map((e) => `${e.op}@${e.jp}`),
18695
18803
  timestamp: Date.now()
18696
- }), u = Cb(a), `已 write(edit) 主数据(${c.length} 个 patch)。当前值:${xb(a, 600)} (新 hash=${Cb(a)})`;
18804
+ }), u = Tb(a), `已 write(edit) 主数据(${o.applied.length} 个 patch)。当前值:${Cb(a, 600)} (新 hash=${Tb(a)})`) : o.error;
18697
18805
  }
18698
- let x = vb(v);
18806
+ let x = bb(v);
18699
18807
  if (x.parseError) return Ug("", v, x.parseError);
18700
18808
  let S = await _("set", b);
18701
18809
  if (S !== null) return S;
18702
- let C = sx({
18810
+ let C = lx({
18703
18811
  bindRef: a,
18704
18812
  value: x.parsed,
18705
18813
  schema: i,
@@ -18710,7 +18818,7 @@ function cx(e, n = {}) {
18710
18818
  dryRun: f,
18711
18819
  onWrite: p
18712
18820
  });
18713
- return C.ok ? f ? `dryRun(set): schema 校验通过。预览新值:${xb(C.data, 600)}。未实际写入、未入快照。` : (u = C.hash, `已 write(set) 主数据 = ${xb(C.data, 600)} (新 hash=${C.hash})${s ? "(白名单模式:仅更新 schema 声明字段,未声明字段保留)" : ""}`) : C.error;
18821
+ return C.ok ? f ? `dryRun(set): schema 校验通过。预览新值:${Cb(C.data, 600)}。未实际写入、未入快照。` : (u = C.hash, `已 write(set) 主数据 = ${Cb(C.data, 600)} (新 hash=${C.hash})${s ? "(白名单模式:仅更新 schema 声明字段,未声明字段保留)" : ""}`) : C.error;
18714
18822
  }, {
18715
18823
  name: "write",
18716
18824
  description: "写入主数据(高层入口,合并 set/edit/delete + 自动乐观锁 + 自动快照)。四种意图:① 整体替换 write({ value }) value 为整个 JSON 对象(推荐)或字符串;② 单个增量 patch write({ patch:{op,jsonPath,value} }) op=set/remove/merge/append,jsonPath 相对主数据根(如 components.0.props.title),patch.value 是该 patch 的值(自带,与 patches 一致——string/number 直传该字段新值,勿包成 {字段:值} 对象);也兼容 write({ value, patch:{op,jsonPath} }) 顶层 value 形式(向后兼容,但优先用 patch.value 避免与①整体 set 的 value 语义混淆);③ 批量增量 write({ patches:[{op,jsonPath,value},...] }) 一次原子应用多个 patch(任一失败整体不写入,适合一次改多处);④ 删除 write({ patch:{jsonPath}, del:true })。写入自动经 schema 校验(失败不写)+ 自动存快照(可 restore_data 回退)+ 自动乐观锁(autoLock,用你最后 read 到的 hash 比对,冲突则 VERSION_CONFLICT)。集成方可能经 write 拦截器校验/转换/拒绝(批量模式拦截器收到 {patches},返回新 patches 数组或 {error})。dryRun(可选):预检模式,走完整校验链(schema + 白名单 + patch 应用到 clone)但不落盘/入快照,返回预览(四意图均支持,复杂改动先看会改成啥、能否过 schema)。",
@@ -18741,7 +18849,7 @@ function cx(e, n = {}) {
18741
18849
  })
18742
18850
  }), M = r(async ({ jsonPath: e }) => {
18743
18851
  let t = e || "", n = t ? ry(i, t) : i;
18744
- return n ? `schema${t ? ` @ ${t}` : ""} = ${xb(dy(n))}` : $({
18852
+ return n ? `schema${t ? ` @ ${t}` : ""} = ${Cb(dy(n))}` : $({
18745
18853
  code: "PATH_DENIED",
18746
18854
  message: `schema @ "${t}" 不存在`,
18747
18855
  hint: "jsonPath 需在 schema 声明字段内(用 read() 不传 jsonPath 查看顶层字段)"
@@ -18755,7 +18863,7 @@ function cx(e, n = {}) {
18755
18863
  if (n) {
18756
18864
  let e = t;
18757
18865
  if (typeof e == "string") {
18758
- let t = vb(e);
18866
+ let t = bb(e);
18759
18867
  t.parseError || (e = t.parsed);
18760
18868
  }
18761
18869
  r = e, i = "against";
@@ -18773,8 +18881,8 @@ function cx(e, n = {}) {
18773
18881
  });
18774
18882
  r = t.value, i = `快照 #${t.id}`;
18775
18883
  }
18776
- let o = s ? ay(a, s) : a, l = Ob(r, _b(o));
18777
- return l.length ? `差异(当前 vs ${i},共 ${l.length} 处):\n${l.map((e) => ` ${e.path}: ${xb(e.from)} → ${xb(e.to)}`).join("\n")}` : `无差异:当前主数据与 ${i} 完全相同。`;
18884
+ let o = s ? ay(a, s) : a, l = Ab(r, yb(o));
18885
+ return l.length ? `差异(当前 vs ${i},共 ${l.length} 处):\n${l.map((e) => ` ${e.path}: ${Cb(e.from)} → ${Cb(e.to)}`).join("\n")}` : `无差异:当前主数据与 ${i} 完全相同。`;
18778
18886
  }, {
18779
18887
  name: "diff_data",
18780
18888
  description: "对比当前主数据与某快照(默认最近)或一段 JSON(against)的差异,返回结构化 {path, from→to} 列表。供 verify 自纠/冲突诊断/操作审计(\"刚才改了啥\")。snapshotId 指定快照;against 传一段 JSON 值(与 snapshotId 互斥,传则忽略快照)。",
@@ -18823,7 +18931,7 @@ function cx(e, n = {}) {
18823
18931
  }
18824
18932
  });
18825
18933
  }
18826
- let f = sx({
18934
+ let f = lx({
18827
18935
  bindRef: a,
18828
18936
  value: d,
18829
18937
  schema: i,
@@ -18834,7 +18942,7 @@ function cx(e, n = {}) {
18834
18942
  op: "draft_commit",
18835
18943
  onWrite: p
18836
18944
  });
18837
- return f.ok ? (u = f.hash, delete e.files[n], `已 draft_commit 草稿 "${t}" → 主数据 = ${xb(f.data, 600)} (新 hash=${f.hash})${s ? "(白名单模式:仅更新 schema 声明字段)" : ""}。草稿已清理。`) : f.error;
18945
+ return f.ok ? (u = f.hash, delete e.files[n], `已 draft_commit 草稿 "${t}" → 主数据 = ${Cb(f.data, 600)} (新 hash=${f.hash})${s ? "(白名单模式:仅更新 schema 声明字段)" : ""}。草稿已清理。`) : f.error;
18838
18946
  }, {
18839
18947
  name: "draft_commit",
18840
18948
  description: "把 draft_write 累积的草稿合并 + schema 校验 + 原子提交到主数据(失败不污染 bind,草稿保留供修后重试)。流程:读 drafts/{draftId}.json → JSON.parse(失败 JSON_INVALID,草稿保留)→ schema 校验(失败 SCHEMA_INVALID,草稿保留)→ 写 bind + 自动快照(与 write(set)/set_data 共用 commitSetToBind,restore_data 可回退)→ 清草稿。适合从零生成大 JSON(如 50+ 组件页面):分块 draft_write 累积 → draft_commit 一次提交。小改仍用 write/patch(无需 draft)。",
@@ -18870,8 +18978,8 @@ function cx(e, n = {}) {
18870
18978
  }
18871
18979
  //#endregion
18872
18980
  //#region src/core/tools/fetchDoc.ts
18873
- var lx = 3e4, ux = [r(async ({ url: e, as: t }) => {
18874
- let n = new AbortController(), r = setTimeout(() => n.abort(), lx);
18981
+ var fx = 3e4, px = [r(async ({ url: e, as: t }) => {
18982
+ let n = new AbortController(), r = setTimeout(() => n.abort(), fx);
18875
18983
  try {
18876
18984
  let r = await fetch(e, {
18877
18985
  method: "GET",
@@ -18888,7 +18996,7 @@ var lx = 3e4, ux = [r(async ({ url: e, as: t }) => {
18888
18996
  ].join("\n");
18889
18997
  } catch (t) {
18890
18998
  let r = t?.message || String(t);
18891
- return n.signal.aborted ? `获取失败:请求超时(${lx}ms,${e})。` : /Failed to fetch|NetworkError|CORS|blocked/i.test(r) ? `获取失败:可能是 CORS 跨域拦截或网络错误(${r})。浏览器仅能 GET 同源或服务端已配置 CORS 的资源;跨域抓取需后端代理。` : `获取失败:${r}`;
18999
+ return n.signal.aborted ? `获取失败:请求超时(${fx}ms,${e})。` : /Failed to fetch|NetworkError|CORS|blocked/i.test(r) ? `获取失败:可能是 CORS 跨域拦截或网络错误(${r})。浏览器仅能 GET 同源或服务端已配置 CORS 的资源;跨域抓取需后端代理。` : `获取失败:${r}`;
18892
19000
  } finally {
18893
19001
  clearTimeout(r);
18894
19002
  }
@@ -18899,7 +19007,7 @@ var lx = 3e4, ux = [r(async ({ url: e, as: t }) => {
18899
19007
  url: t.string().describe("要抓取的 URL(同源或已配 CORS)"),
18900
19008
  as: t.enum(["text", "markdown"]).optional().describe("返回格式标签,默认 text")
18901
19009
  })
18902
- })], dx = [
19010
+ })], mx = [
18903
19011
  "id",
18904
19012
  "class",
18905
19013
  "href",
@@ -18911,12 +19019,12 @@ var lx = 3e4, ux = [r(async ({ url: e, as: t }) => {
18911
19019
  "aria-label",
18912
19020
  "name",
18913
19021
  "type"
18914
- ], fx = /^(value|srcdoc|formaction|on\w+)$/i, px = /token|secret|password|passwd|api[-_]?key|auth|cred|csrf|session/i;
18915
- function mx(e, t) {
19022
+ ], hx = /^(value|srcdoc|formaction|on\w+)$/i, gx = /token|secret|password|passwd|api[-_]?key|auth|cred|csrf|session/i;
19023
+ function _x(e, t) {
18916
19024
  if (!e) return null;
18917
- let { depth: n, attrs: r, includeText: i = !0 } = t, a = r !== void 0, o = r ?? dx, s = (e) => {
19025
+ let { depth: n, attrs: r, includeText: i = !0 } = t, a = r !== void 0, o = r ?? mx, s = (e) => {
18918
19026
  let t = {};
18919
- for (let n of Array.from(e.attributes)) (a ? o.includes(n.name) : o.includes(n.name) || n.name.startsWith("data-")) && (fx.test(n.name) || px.test(n.name) || (t[n.name] = n.value));
19027
+ for (let n of Array.from(e.attributes)) (a ? o.includes(n.name) : o.includes(n.name) || n.name.startsWith("data-")) && (hx.test(n.name) || gx.test(n.name) || (t[n.name] = n.value));
18920
19028
  return t;
18921
19029
  }, c = (e, t) => {
18922
19030
  let n = {
@@ -18932,10 +19040,10 @@ function mx(e, t) {
18932
19040
  };
18933
19041
  return c(e, n);
18934
19042
  }
18935
- var hx = r(({ selector: e, depth: t, attrs: n, includeText: r }) => {
19043
+ var vx = r(({ selector: e, depth: t, attrs: n, includeText: r }) => {
18936
19044
  let i = e ? document.querySelector(e) : document.body;
18937
19045
  if (!i) return `未找到匹配元素:selector="${e}"`;
18938
- let a = mx(i, {
19046
+ let a = _x(i, {
18939
19047
  depth: t ?? 3,
18940
19048
  attrs: n,
18941
19049
  includeText: r ?? !0
@@ -18950,14 +19058,14 @@ var hx = r(({ selector: e, depth: t, attrs: n, includeText: r }) => {
18950
19058
  attrs: t.array(t.string()).optional().describe("属性白名单(传了 = 严格白名单;不传 = 默认常用 + data-*)"),
18951
19059
  includeText: t.boolean().optional().describe("是否包含直接文本(默认 true)")
18952
19060
  })
18953
- }), gx = [hx];
19061
+ }), yx = [vx];
18954
19062
  //#endregion
18955
19063
  //#region src/core/tools/envTool.ts
18956
- function _x(e) {
19064
+ function bx(e) {
18957
19065
  let t = e;
18958
19066
  return typeof t.tagName == "string" || typeof t.nodeType == "number" && typeof t.nodeName == "string";
18959
19067
  }
18960
- function vx(e, t = 3, n = 2e3, r) {
19068
+ function xx(e, t = 3, n = 2e3, r) {
18961
19069
  if (e == null) return e;
18962
19070
  if (typeof e == "string") return e.length > n ? e.slice(0, n) + "…(已截断)" : e;
18963
19071
  if (typeof e == "number" || typeof e == "boolean") return e;
@@ -18966,14 +19074,14 @@ function vx(e, t = 3, n = 2e3, r) {
18966
19074
  if (typeof e == "bigint") return `${e.toString()}n`;
18967
19075
  if (typeof e != "object") return String(e);
18968
19076
  let i = e;
18969
- if (_x(i)) {
19077
+ if (bx(i)) {
18970
19078
  let e = i;
18971
19079
  return e.tagName ? `[Element: <${e.tagName.toLowerCase()}>]` : `[Node: ${e.nodeName}]`;
18972
19080
  }
18973
19081
  if (r?.has(i)) return "[Circular]";
18974
19082
  let a = r ?? /* @__PURE__ */ new WeakSet();
18975
19083
  if (a.add(i), Array.isArray(e)) {
18976
- let r = e.slice(0, 100).map((e) => vx(e, t - 1, n, a));
19084
+ let r = e.slice(0, 100).map((e) => xx(e, t - 1, n, a));
18977
19085
  return e.length > 100 && r.push(`…(共 ${e.length} 项,已截断)`), r;
18978
19086
  }
18979
19087
  if (t < 0) return "(对象,已截断)";
@@ -18985,14 +19093,14 @@ function vx(e, t = 3, n = 2e3, r) {
18985
19093
  break;
18986
19094
  }
18987
19095
  try {
18988
- o[r] = vx(i[r], t - 1, n, a);
19096
+ o[r] = xx(i[r], t - 1, n, a);
18989
19097
  } catch {
18990
19098
  o[r] = "(getter 抛错)";
18991
19099
  }
18992
19100
  }
18993
19101
  return o;
18994
19102
  }
18995
- function yx(e) {
19103
+ function Sx(e) {
18996
19104
  let t = e ?? (typeof window < "u" ? window : {}), n = t.navigator, r = t.location, i = t.document;
18997
19105
  return {
18998
19106
  location: {
@@ -19025,9 +19133,9 @@ function yx(e) {
19025
19133
  } : "(无 document)"
19026
19134
  };
19027
19135
  }
19028
- var bx = /^(localStorage|sessionStorage|cookie|document|frames|frameElement|opener|parent|top|self|window|globalThis|closed|history|navigation|trustedTypes|origin|crossOriginIsolated)$/, xx = /token|secret|password|passwd|api[-_]?key|auth|cred|csrf|session|ticket/i, Sx = r(({ key: e }) => {
19136
+ var Cx = /^(localStorage|sessionStorage|cookie|document|frames|frameElement|opener|parent|top|self|window|globalThis|closed|history|navigation|trustedTypes|origin|crossOriginIsolated)$/, wx = /token|secret|password|passwd|api[-_]?key|auth|cred|csrf|session|ticket/i, Tx = r(({ key: e }) => {
19029
19137
  if (e) {
19030
- if (bx.test(e) || xx.test(e)) return JSON.stringify({
19138
+ if (Cx.test(e) || wx.test(e)) return JSON.stringify({
19031
19139
  key: e,
19032
19140
  denied: !0,
19033
19141
  reason: "安全:该 key 在 denylist(localStorage/sessionStorage/cookie/document 或敏感命名 token/secret/key/auth),不读取防泄漏"
@@ -19037,18 +19145,18 @@ var bx = /^(localStorage|sessionStorage|cookie|document|frames|frameElement|open
19037
19145
  key: e,
19038
19146
  exists: t !== void 0,
19039
19147
  type: typeof t,
19040
- value: vx(t)
19148
+ value: xx(t)
19041
19149
  }, null, 2);
19042
19150
  }
19043
- return JSON.stringify(yx(), null, 2);
19151
+ return JSON.stringify(Sx(), null, 2);
19044
19152
  }, {
19045
19153
  name: "inspect_env",
19046
19154
  description: "读取宿主页面环境信息(排查调试用,默认开启)。不传参 = 返回环境摘要(location 的 URL/origin/path、navigator 的浏览器/语言、viewport 视口尺寸、document 的 title/readyState);传 key = 读取指定 window 属性值(如 inspect_env({key:\"appConfig\"}) 读集成方挂的调试变量 window.appConfig)。用于排查「当前页面在哪/什么浏览器/视口多大/调试变量值是什么」。轻量只读,大结果自动外存 vfs。",
19047
19155
  schema: t.object({ key: t.string().optional().describe("要读取的 window 属性名(如 \"appConfig\"/\"__DEBUG__\");不传 = 返回环境摘要") })
19048
- }), Cx = [Sx];
19156
+ }), Ex = [Tx];
19049
19157
  //#endregion
19050
19158
  //#region src/core/harness/budget.ts
19051
- function wx(e, t, n) {
19159
+ function Dx(e, t, n) {
19052
19160
  let r = 0;
19053
19161
  return {
19054
19162
  name: "budget",
@@ -19073,12 +19181,12 @@ function wx(e, t, n) {
19073
19181
  }
19074
19182
  //#endregion
19075
19183
  //#region src/core/sdk/actions.ts
19076
- var Tx = /^[a-zA-Z][a-zA-Z0-9_]*$/;
19077
- function Ex(e) {
19184
+ var Ox = /^[a-zA-Z][a-zA-Z0-9_]*$/;
19185
+ function kx(e) {
19078
19186
  let n = [];
19079
19187
  for (let [i, a] of Object.entries(e)) {
19080
- if (!Tx.test(i)) {
19081
- console.warn(`[page-agent-sdk][actions] 动作名 "${i}" 非法(须匹配 ${Tx}),已跳过`);
19188
+ if (!Ox.test(i)) {
19189
+ console.warn(`[page-agent-sdk][actions] 动作名 "${i}" 非法(须匹配 ${Ox}),已跳过`);
19082
19190
  continue;
19083
19191
  }
19084
19192
  let e = a.description || `宿主动作 ${i}`;
@@ -19098,9 +19206,9 @@ function Ex(e) {
19098
19206
  }
19099
19207
  return n;
19100
19208
  }
19101
- function Dx(e) {
19209
+ function Ax(e) {
19102
19210
  let t = {};
19103
- for (let [n, r] of Object.entries(e)) Tx.test(n) && (t[n] = {
19211
+ for (let [n, r] of Object.entries(e)) Ox.test(n) && (t[n] = {
19104
19212
  description: r.description,
19105
19213
  hasParams: !!r.params
19106
19214
  });
@@ -19108,31 +19216,31 @@ function Dx(e) {
19108
19216
  }
19109
19217
  //#endregion
19110
19218
  //#region src/core/toolsets.ts
19111
- var Ox = ux, kx = gx;
19112
- function Ax(e, t) {
19113
- return cx(e, t);
19219
+ var jx = px, Mx = yx;
19220
+ function Nx(e, t) {
19221
+ return dx(e, t);
19114
19222
  }
19115
- function jx(e, t, n, r, i) {
19116
- let a = e?.dataOps !== !1, o = e?.fetch !== !1, s = e?.domInspect === !0, c = e?.inspectEnv !== !1;
19223
+ function Px(e, t, n, r, i) {
19224
+ let a = ob(e);
19117
19225
  return [
19118
- ...a ? t : [],
19119
- ...o ? n : [],
19120
- ...s && r ? r : [],
19121
- ...c && i ? i : []
19226
+ ...a.dataOps ? t : [],
19227
+ ...a.fetch ? n : [],
19228
+ ...a.domInspect && r ? r : [],
19229
+ ...a.inspectEnv && i ? i : []
19122
19230
  ];
19123
19231
  }
19124
19232
  //#endregion
19125
19233
  //#region src/core/harness/usageHints.ts
19126
- var Mx = .7;
19127
- function Nx(e, t, n = "simple") {
19128
- let r = n !== "advanced";
19234
+ var Fx = .7;
19235
+ function Ix(e, t, n = "simple") {
19236
+ let r = ob(e), i = n !== "advanced";
19129
19237
  return {
19130
19238
  name: "usageHints",
19131
19239
  augmentPrompt: () => {
19132
19240
  let n = [];
19133
- if (e?.planning !== !1 && (n.push("【自适应规划】按任务复杂度决定是否先规划,不要对简单任务过度编排:"), n.push(" · 简单/明确任务(改单字段、调样式、查值)→ 直接 read/write 执行,不必 write_todos。"), n.push(" · 复杂任务(多步、大改、有歧义、不可逆)→ 先 write_todos 拆解,首个任务标 in_progress,逐项推进。"), n.push(" · 执行中发现步骤要改/补/细分 → 用 update_todo({id, content?, status?}) 按 id 增量改单项,不必重传整个清单。"), n.push(" · 规划出多步方案若需用户拍板 → 先 request_human_confirmation 给方案选项,确认后再执行。"), n.push(" · 规划阶段有轮次预算(maxPlanRevisions,默认 5):勿反复调研/改计划而不执行,规划充分后即开始 write 落地。")), t && (r ? (n.push("读写主数据用 read/write(高层入口,自动乐观锁 + 自动快照)。read({jsonPath}) 读子路径当前值(返回含 hash,write 时自动比对,无需手动传);read() 不传读整个主数据 + 说明。write 改值两姿势:① 改单个字段/子路径用 write({patch:{op:\"set\", jsonPath:\"路径.字段\", value:新值}})——patch.value 就是该字段的新值(类型匹配:string 直传字符串、number 传数字、对象传对象),不要包成 {字段:值} 对象(字段名已在 jsonPath);也兼容 write({value:新值, patch:{op,jsonPath}}) 顶层 value(向后兼容,但优先 patch.value,避免与整体 set 的 value 混淆);② 替换整个对象用 write({value:{整个新对象}})。op:set 设值 / remove 删 / merge 合并对象 / append 追加数组;批量多改动 write({patches:[{op,jsonPath,value},...]});删子路径 write({patch:{jsonPath:\"路径\"}, del:true})。写入自动经 schema 校验(失败不写,按错误提示改值类型/形状后重试)+ 自动存快照(出错可用 restore_data 回退)。"), n.push("修改大对象/数组优先用 write 的 patch 增量(只发改动部分),避免整体重传被 max_tokens 截断致 JSON 不完整。"), n.push("读大数组(read 返回 hasMore=true)用 read({jsonPath,offset,limit}) 分页(offset+=limit 续读,默认 limit=50);一次读多个不相关子路径用 read({jsonPaths:[...]}) 省轮次;复杂 patches 改动先 write({patches,dryRun:true}) 预检(走完整校验不落盘)。"), n.push("查历史快照值(看上一版长啥样 / 冲突诊断 / 用户问\"刚才改了啥\")用 history_data({id?,jsonPath?})(只读不改当前);对比当前与历史快照的差异需切 advanced 用 diff_data(返回结构化 path→from/to)。"), 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(返回值经校验后落地)。"), n.push("读大数组用 read({jsonPath,offset,limit}) 分页(返回 hasMore=true 时 offset+=limit 续读);一次读多个不相关子路径用 read({jsonPaths});复杂改动先 write({...,dryRun:true}) 预检不落盘。"), n.push("对比当前与历史快照(或一段 JSON against)的差异用 diff_data({snapshotId?,against?})(返回结构化 path→from/to,verify 自纠/操作审计/\"刚才改了啥\");只读查历史快照值用 history_data({id?,jsonPath?})。"))), e?.subagent !== !1 && n.push("独立子任务可 spawn_agent 委派(只读工具,过程不占主上下文)。"), e?.inspectEnv !== !1 && n.push("排查页面环境(当前 URL/浏览器/视口/集成方调试变量)用 inspect_env——不传参返回环境摘要(location/navigator/viewport/document),传 key 读特定 window 属性(如 inspect_env({key:\"appConfig\"}) 读 window.appConfig)。改完数据看渲染、定位\"为何没生效\"时用它(只读,不改数据)。"), e?.draftWrite && n.push("生成超大 JSON(如 50+ 组件页面,单次 write 受 max_tokens 限制装不下)用 draft_write 分块构建 → draft_commit 原子提交:draft_write({draftId, chunk, mode}) mode:\"start\" 新建/\"append\" 追加(拼 JSON 片段到 drafts 池);累积完 draft_commit({draftId}) 合并 + schema 校验 + 写主数据(失败草稿保留可修后重试,成功自动清草稿)。小改仍用 write patch,只在大 JSON 从零生成时用 draft。"), e?.todoDeps && n.push("复杂任务可用 todos 层级依赖:write_todos 时给 todo 传 parentId(父任务 id,表达层级)+ deps(依赖的 todo id 数组,必须先完成)。有依赖的任务,deps 全 completed 后再标 in_progress;完成时 update_todo({id, status:\"completed\", evidence:\"完成证据\"}) 记证据。无依赖关系的任务不传 parentId/deps(扁平)。"), e?.subagents?.length) {
19134
- let t = e.subagents.filter((e) => (e.temperature ?? 0) >= Mx || /规划|创意|设计|方案|brainstorm|plan/i.test(e.description)), i = e.subagents.filter((e) => (e.temperature ?? 0) < Mx && /反思|审查|挑刺|校验|review|critique|reflect/i.test(e.description));
19135
- 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(" · 简单/明确任务(如\"标题改红色\")直接执行,不必走规划-反思。");
19241
+ if (r.planning && (n.push("【自适应规划】按任务复杂度决定是否先规划,不要对简单任务过度编排:"), n.push(" · 简单/明确任务(改单字段、调样式、查值)→ 直接 read/write 执行,不必 write_todos。"), n.push(" · 复杂任务(多步、大改、有歧义、不可逆)→ 先 write_todos 拆解,首个任务标 in_progress,逐项推进。"), n.push(" · 执行中发现步骤要改/补/细分 → 用 update_todo({id, content?, status?}) 按 id 增量改单项,不必重传整个清单。"), n.push(" · 规划出多步方案若需用户拍板 → 先 request_human_confirmation 给方案选项,确认后再执行。"), n.push(" · 规划阶段有轮次预算(maxPlanRevisions,默认 5):勿反复调研/改计划而不执行,规划充分后即开始 write 落地。")), t && (i ? (n.push("读写主数据用 read/write(高层入口,自动乐观锁 + 自动快照)。read({jsonPath}) 读子路径当前值(返回含 hash,write 时自动比对,无需手动传);read() 不传读整个主数据 + 说明。write 改值两姿势:① 改单个字段/子路径用 write({patch:{op:\"set\", jsonPath:\"路径.字段\", value:新值}})——patch.value 就是该字段的新值(类型匹配:string 直传字符串、number 传数字、对象传对象),不要包成 {字段:值} 对象(字段名已在 jsonPath);也兼容 write({value:新值, patch:{op,jsonPath}}) 顶层 value(向后兼容,但优先 patch.value,避免与整体 set 的 value 混淆);② 替换整个对象用 write({value:{整个新对象}})。op:set 设值 / remove 删 / merge 合并对象 / append 追加数组;批量多改动 write({patches:[{op,jsonPath,value},...]});删子路径 write({patch:{jsonPath:\"路径\"}, del:true})。写入自动经 schema 校验(失败不写,按错误提示改值类型/形状后重试)+ 自动存快照(出错可用 restore_data 回退)。"), n.push("修改大对象/数组优先用 write 的 patch 增量(只发改动部分),避免整体重传被 max_tokens 截断致 JSON 不完整。"), n.push("读大数组(read 返回 hasMore=true)用 read({jsonPath,offset,limit}) 分页(offset+=limit 续读,默认 limit=50);一次读多个不相关子路径用 read({jsonPaths:[...]}) 省轮次;复杂 patches 改动先 write({patches,dryRun:true}) 预检(走完整校验不落盘)。"), n.push("查历史快照值(看上一版长啥样 / 冲突诊断 / 用户问\"刚才改了啥\")用 history_data({id?,jsonPath?})(只读不改当前);对比当前与历史快照的差异需切 advanced 用 diff_data(返回结构化 path→from/to)。"), 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(返回值经校验后落地)。"), n.push("读大数组用 read({jsonPath,offset,limit}) 分页(返回 hasMore=true 时 offset+=limit 续读);一次读多个不相关子路径用 read({jsonPaths});复杂改动先 write({...,dryRun:true}) 预检不落盘。"), n.push("对比当前与历史快照(或一段 JSON against)的差异用 diff_data({snapshotId?,against?})(返回结构化 path→from/to,verify 自纠/操作审计/\"刚才改了啥\");只读查历史快照值用 history_data({id?,jsonPath?})。"))), r.subagent && n.push("独立子任务可 spawn_agent 委派(只读工具,过程不占主上下文)。"), r.inspectEnv && n.push("排查页面环境(当前 URL/浏览器/视口/集成方调试变量)用 inspect_env——不传参返回环境摘要(location/navigator/viewport/document),传 key 读特定 window 属性(如 inspect_env({key:\"appConfig\"}) 读 window.appConfig)。改完数据看渲染、定位\"为何没生效\"时用它(只读,不改数据)。"), r.draftWrite && n.push("生成超大 JSON(如 50+ 组件页面,单次 write 受 max_tokens 限制装不下)用 draft_write 分块构建 → draft_commit 原子提交:draft_write({draftId, chunk, mode}) mode:\"start\" 新建/\"append\" 追加(拼 JSON 片段到 drafts 池);累积完 draft_commit({draftId}) 合并 + schema 校验 + 写主数据(失败草稿保留可修后重试,成功自动清草稿)。小改仍用 write patch,只在大 JSON 从零生成时用 draft。"), r.todoDeps && n.push("复杂任务可用 todos 层级依赖:write_todos 时给 todo 传 parentId(父任务 id,表达层级)+ deps(依赖的 todo id 数组,必须先完成)。有依赖的任务,deps 全 completed 后再标 in_progress;完成时 update_todo({id, status:\"completed\", evidence:\"完成证据\"}) 记证据。无依赖关系的任务不传 parentId/deps(扁平)。"), e?.subagents?.length) {
19242
+ let t = e.subagents.filter((e) => (e.temperature ?? 0) >= Fx || /规划|创意|设计|方案|brainstorm|plan/i.test(e.description)), r = e.subagents.filter((e) => (e.temperature ?? 0) < Fx && /反思|审查|挑刺|校验|review|critique|reflect/i.test(e.description));
19243
+ n.push("【规划-反思-执行·路由】按任务性质选模式,不要对简单任务过度编排:"), t.length && (n.push(` · 创作/设计/开放性需求(如"设计主题风格""换个感觉")→ 先调 ${t.map((e) => "use_" + e.id).join("/")} 出 2-3 套方案(高温创意),`), n.push(" 不要自己拍板;拿到方案后,若需用户拍板用 request_human_confirmation 弹选项。")), r.length && n.push(` · 严谨/易错/校验类 → 可先调 ${r.map((e) => "use_" + e.id).join("/")} 反思挑刺(低温审查),据反馈修订。`), n.push(i ? " · 方案定稿后,由你(主 agent)用 write 落地成 JSON(低温度执行 + schema 校验 + 写前确认)。" : " · 方案定稿后,由你(主 agent)用 edit_data 落地成 JSON(低温度执行 + schema 校验 + 写前确认)。"), n.push(" · 简单/明确任务(如\"标题改红色\")直接执行,不必走规划-反思。");
19136
19244
  }
19137
19245
  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(" 4) 规划出多步方案需用户确认时:把整个方案(或关键分步)作为 option 调 request_human_confirmation,确认后再执行。"), 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;
19138
19246
  }
@@ -19140,15 +19248,15 @@ function Nx(e, t, n = "simple") {
19140
19248
  }
19141
19249
  //#endregion
19142
19250
  //#region src/core/backends/skillStore.ts
19143
- var Px = "v:1::skill-store", Fx = "chat-sdk";
19144
- function Ix(e, t, n) {
19145
- return `${Px}::${e}::${t}::${n}`;
19251
+ var Lx = "v:1::skill-store", Rx = "chat-sdk";
19252
+ function zx(e, t, n) {
19253
+ return `${Lx}::${e}::${t}::${n}`;
19146
19254
  }
19147
- function Lx(e, t) {
19148
- return `${Px}::${e}::${t}::`;
19255
+ function Bx(e, t) {
19256
+ return `${Lx}::${e}::${t}::`;
19149
19257
  }
19150
- function Rx(e = {}) {
19151
- let t = e.dbName ?? Fx, n = e.backend ?? "indexed", r = e.id ?? "", i, a, o = new Promise((e) => {
19258
+ function Vx(e = {}) {
19259
+ let t = e.dbName ?? Rx, n = e.backend ?? "indexed", r = e.id ?? "", i, a, o = new Promise((e) => {
19152
19260
  a = e;
19153
19261
  });
19154
19262
  return (async () => {
@@ -19170,42 +19278,42 @@ function Rx(e = {}) {
19170
19278
  ready: o,
19171
19279
  async list() {
19172
19280
  let e = [];
19173
- return await i.scan(Lx(t, r), (t, n) => {
19281
+ return await i.scan(Bx(t, r), (t, n) => {
19174
19282
  e.push(n);
19175
19283
  }), e;
19176
19284
  },
19177
19285
  async get(e) {
19178
- return await i.get(Ix(t, r, e));
19286
+ return await i.get(zx(t, r, e));
19179
19287
  },
19180
19288
  async put(e) {
19181
19289
  try {
19182
- await i.set(Ix(t, r, e.name), e);
19290
+ await i.set(zx(t, r, e.name), e);
19183
19291
  } catch (e) {
19184
19292
  Wy(e) && (i = Qy());
19185
19293
  }
19186
19294
  },
19187
19295
  async remove(e) {
19188
- let n = Ix(t, r, e);
19296
+ let n = zx(t, r, e);
19189
19297
  return await i.get(n) != null && (await i.del(n), !0);
19190
19298
  },
19191
19299
  async clear() {
19192
- await i.clearPrefix(Lx(t, r));
19300
+ await i.clearPrefix(Bx(t, r));
19193
19301
  },
19194
19302
  dispose() {}
19195
19303
  };
19196
19304
  }
19197
19305
  //#endregion
19198
19306
  //#region src/core/sdk/createChatSdk.ts
19199
- var zx = 50, Bx = /* @__PURE__ */ new Map();
19200
- function Vx(e, t) {
19307
+ var Hx = 50, Ux = /* @__PURE__ */ new Map();
19308
+ function Wx(e, t) {
19201
19309
  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;
19202
19310
  }
19203
- function Hx(e, t, n, r) {
19311
+ function Gx(e, t, n, r) {
19204
19312
  let i = 0;
19205
19313
  return {
19206
19314
  name: "sdk-events",
19207
19315
  wrapToolCall: async (t, r) => {
19208
- let i = await r(t), a = Vx(t.name, t.args);
19316
+ let i = await r(t), a = Wx(t.name, t.args);
19209
19317
  return a && e({
19210
19318
  type: "data_change",
19211
19319
  operation: a,
@@ -19240,7 +19348,7 @@ function Hx(e, t, n, r) {
19240
19348
  }
19241
19349
  };
19242
19350
  }
19243
- function Ux(e, i) {
19351
+ function Kx(e, i) {
19244
19352
  let a = {
19245
19353
  prompt_tokens: 0,
19246
19354
  completion_tokens: 0,
@@ -19251,7 +19359,7 @@ function Ux(e, i) {
19251
19359
  e.debug && console.log("[page-agent-sdk][modelCaps]", d);
19252
19360
  let f = e.llm;
19253
19361
  e.debug && !u && console.warn("[page-agent-sdk][summarization] 未构造 llmInvoke(apiKey 缺失?),摘要回退零成本索引摘要");
19254
- let p = /* @__PURE__ */ tn([]), m = Mb(e.vfs?.initialFiles, {
19362
+ let p = /* @__PURE__ */ tn([]), m = Pb(e.vfs?.initialFiles, {
19255
19363
  persist: c ? { save: (e) => {
19256
19364
  B.sessionId && c && c.save(i, B.sessionId, { vfs: e });
19257
19365
  } } : void 0,
@@ -19271,18 +19379,18 @@ function Ux(e, i) {
19271
19379
  getTodos: () => y.current?.getState?.()?.todos ?? [],
19272
19380
  messages: p,
19273
19381
  maxCheckpoints: x && typeof x == "object" ? x.maxCheckpoints : void 0
19274
- }) : null, w = !x || typeof x != "object" || x.auto !== !1, T = e.capabilities, E = T?.dataOps !== !1, D = T?.draftWrite === !0, O = T?.tracing === !0, k = T?.automation === !0, A = Ey(e), j = E && b ? cx(b, {
19382
+ }) : null, w = !x || typeof x != "object" || x.auto !== !1, T = ob(e.capabilities), E = T.dataOps, D = T.draftWrite, O = T.tracing, k = T.automation, A = Ey(e), j = E && b ? dx(b, {
19275
19383
  onAudit: e.onAudit ?? (e.debug ? (e) => console.log("[page-agent-sdk][data audit]", e) : void 0),
19276
19384
  maxSnapshots: e.maxSnapshots,
19277
19385
  onConflict: o.set,
19278
19386
  autoLock: e.autoLock,
19279
19387
  interceptors: e.interceptors,
19280
19388
  vfsStore: D ? m : void 0
19281
- }) : [], M = E ? ox(j, e.toolMode) : [], ee = E && b ? j.controller ?? null : null, N = () => ee?.get() ?? b, P = /* @__PURE__ */ new Map(), F = jx(T, M, ux, gx, Cx);
19389
+ }) : [], M = E ? cx(j, e.toolMode) : [], ee = E && b ? j.controller ?? null : null, N = () => ee?.get() ?? b, P = /* @__PURE__ */ new Map(), F = Px(T, M, px, yx, Ex);
19282
19390
  F.forEach((e) => P.set(e.name, "builtin"));
19283
19391
  let I = [...e.tools || []];
19284
19392
  I.forEach((e) => P.set(e.name, "user"));
19285
- let te = Ex(e.actions ?? {});
19393
+ let te = kx(e.actions ?? {});
19286
19394
  te.forEach((e) => P.set(e.name, "action"));
19287
19395
  let L = [], R = e.humanConfirm !== !1 && (!e.approval || e.approval.humanConfirmTool !== !1), ne = R ? X_() : null;
19288
19396
  ne && P.set(J_, "builtin");
@@ -19319,11 +19427,11 @@ function Ux(e, i) {
19319
19427
  ...L
19320
19428
  ];
19321
19429
  }
19322
- let ae = T?.planning !== !1, oe = T?.missionAnchor !== !1, se = T?.workingMemory !== !1, ce = T?.skills !== !1, le = T?.vfs !== !1;
19323
- if (le) for (let e of zb) P.set(e, "builtin");
19430
+ let ae = T.planning, oe = T.missionAnchor, se = T.workingMemory, ce = T.skills, le = T.vfs;
19431
+ if (le) for (let e of Vb) P.set(e, "builtin");
19324
19432
  if (ae) for (let e of h.tools ?? []) P.set(e.name, "builtin");
19325
- let ue = T?.summarization !== !1, de = T?.memory !== !1, fe = T?.subagent !== !1, pe = e.verify?.maxAttempts ?? 2, me = T?.verify === !0 && e.verify?.enabled !== !1 && pe > 0;
19326
- e.verify?.check && T?.verify !== !0 && console.warn("[page-agent-sdk][verify] 检测到 verify.check 但 capabilities.verify 未开启,verify 未装载");
19433
+ let ue = T.summarization, de = T.memory, fe = T.subagent, pe = e.verify?.maxAttempts ?? 2, me = T.verify && e.verify?.enabled !== !1 && pe > 0;
19434
+ e.verify?.check && !T.verify && console.warn("[page-agent-sdk][verify] 检测到 verify.check 但 capabilities.verify 未开启,verify 未装载");
19327
19435
  let he = e.subagent, ge = he?.allowedTools ?? [], _e = !fe || he?.enabled === !1 ? void 0 : _v({
19328
19436
  llm: he?.llm ?? e.llm,
19329
19437
  allTools: z,
@@ -19353,7 +19461,7 @@ function Ux(e, i) {
19353
19461
  llm: e.llm,
19354
19462
  tools: xe
19355
19463
  } : void 0
19356
- }) : void 0, Ce = Nx({
19464
+ }) : void 0, Ce = Ix({
19357
19465
  ...T,
19358
19466
  humanConfirm: R,
19359
19467
  subagents: e.subagents?.map((e) => ({
@@ -19377,7 +19485,7 @@ function Ux(e, i) {
19377
19485
  return;
19378
19486
  }
19379
19487
  }
19380
- } : null, Ee = e.onEvent, De = ab(e.onEvent), Oe = De.emit, ke, Ae = [], je = (e) => ({
19488
+ } : null, Ee = e.onEvent, De = sb(e.onEvent), Oe = De.emit, ke, Ae = [], je = (e) => ({
19381
19489
  name: e.name,
19382
19490
  description: e.description,
19383
19491
  content: typeof e.getContent == "function" ? e.getContent() : ""
@@ -19385,7 +19493,7 @@ function Ux(e, i) {
19385
19493
  name: e.name,
19386
19494
  description: e.description,
19387
19495
  getContent: () => e.content
19388
- }), Ne = e.skillStorage === !1 ? null : Rx({
19496
+ }), Ne = e.skillStorage === !1 ? null : Vx({
19389
19497
  ...typeof e.skillStorage == "object" ? e.skillStorage : {},
19390
19498
  id: e.skillStorage && typeof e.skillStorage == "object" && e.skillStorage.id ? e.skillStorage.id : `agent::${i}`
19391
19499
  }), Pe = () => {
@@ -19408,18 +19516,18 @@ function Ux(e, i) {
19408
19516
  B.infoTick.value++;
19409
19517
  }
19410
19518
  } catch {}
19411
- }, Ie = ub([
19519
+ }, Ie = fb([
19412
19520
  ...we ? [we] : [],
19413
19521
  Ce,
19414
19522
  ...oe ? [g] : [],
19415
19523
  ...ae ? [h] : [],
19416
19524
  ...ce ? [ke = z_(e.skills || [], { readVfs: le ? (e) => m.files[e]?.content : void 0 })] : [],
19417
- ...le ? [Vb(m)] : [],
19525
+ ...le ? [Ub(m)] : [],
19418
19526
  ...ue ? [$v({
19419
- ...cb(e, d.contextWindow),
19527
+ ...ub(e, d.contextWindow),
19420
19528
  llmInvoke: u,
19421
19529
  getRegisteredData: () => N() ? [{ description: N().description ?? "主数据对象" }] : [],
19422
- preserveLastToolResults: (e.contextOptions && e.contextOptions.preserveLastToolResults) ?? sb[e.contextPreset ?? "auto"]
19530
+ preserveLastToolResults: (e.contextOptions && e.contextOptions.preserveLastToolResults) ?? lb[e.contextPreset ?? "auto"]
19423
19531
  })] : [],
19424
19532
  ...se ? [_] : [],
19425
19533
  ...de ? [v] : [],
@@ -19432,12 +19540,12 @@ function Ux(e, i) {
19432
19540
  ...ve ? [ve] : [],
19433
19541
  ...Te ? [Te] : [],
19434
19542
  ...e.middleware || [],
19435
- ...k ? [wx(a, {
19543
+ ...k ? [Dx(a, {
19436
19544
  tokenBudget: e.tokenBudget,
19437
19545
  timeBudgetMs: e.timeBudgetMs
19438
19546
  }, Oe)] : [],
19439
- Hx(Oe, p, N, a)
19440
- ]), Le = e.maxMemoryRounds ?? zx, B = {
19547
+ Gx(Oe, p, N, a)
19548
+ ]), Le = e.maxMemoryRounds ?? Hx, B = {
19441
19549
  agentId: i,
19442
19550
  store: c,
19443
19551
  messages: p,
@@ -19615,7 +19723,7 @@ function Ux(e, i) {
19615
19723
  if (B.refCount--, B.refCount <= 0) {
19616
19724
  c && (m.flush?.(), c.flush(), c.dispose()), Ne && Ne.dispose();
19617
19725
  let e = B.mcpClosers.splice(0);
19618
- e.length && Promise.allSettled(e.map((e) => e())), Bx.delete(i);
19726
+ e.length && Promise.allSettled(e.map((e) => e())), Ux.delete(i);
19619
19727
  }
19620
19728
  },
19621
19729
  resolveConflict: o.resolve,
@@ -19708,7 +19816,7 @@ function Ux(e, i) {
19708
19816
  spans: B.agent.spans.value,
19709
19817
  metrics: r_(B.agent.spans.value)
19710
19818
  } : void 0,
19711
- actions: Dx(e.actions ?? {}),
19819
+ actions: Ax(e.actions ?? {}),
19712
19820
  subagent: {
19713
19821
  enabled: !!_e,
19714
19822
  maxDepth: e.subagent?.maxDepth ?? 1,
@@ -19837,11 +19945,11 @@ function Ux(e, i) {
19837
19945
  });
19838
19946
  })(), B;
19839
19947
  }
19840
- function Wx(e) {
19948
+ function qx(e) {
19841
19949
  let t = e.id ?? My();
19842
19950
  e.id || console.warn(`[page-agent-sdk] 未传 options.id,已生成随机 id "${t}"。刷新后持久化数据无法恢复,请传稳定 id。`);
19843
- let n = e.streaming ?? !0, r = e.ui ?? "default", i, a = e.shareContext ? Bx.get(t) : void 0;
19844
- a ? i = a : (i = Ux(e, t), e.shareContext && Bx.set(t, i)), i.refCount++;
19951
+ let n = e.streaming ?? !0, r = e.ui ?? "default", i, a = e.shareContext ? Ux.get(t) : void 0;
19952
+ a ? i = a : (i = Kx(e, t), e.shareContext && Ux.set(t, i)), i.refCount++;
19845
19953
  let o = null, s = null, c = ib(e), l = null, u = null;
19846
19954
  async function d(t) {
19847
19955
  if (await i.initDone, o) {
@@ -20022,7 +20130,7 @@ function Wx(e) {
20022
20130
  }
20023
20131
  //#endregion
20024
20132
  //#region src/core/sdk/defineTool.ts
20025
- function Gx(e) {
20133
+ function Jx(e) {
20026
20134
  return r(async (t) => {
20027
20135
  let n = await e.handler(t);
20028
20136
  return typeof n == "string" ? n : JSON.stringify(n);
@@ -20033,4 +20141,4 @@ function Gx(e) {
20033
20141
  });
20034
20142
  }
20035
20143
  //#endregion
20036
- export { ob as CONTEXT_PRESETS, Bg as ChatDialog, nf as CodePreview, wy as DEFAULT_SYSTEM_PROMPT, J_ as HUMAN_CONFIRM_TOOL_NAME, af as MessageContent, Gv as STOP_WORDS, xh as SkillPanel, db as UNSAFE_KEYS, Dx as actionsToInspectInfo, Ex as actionsToTools, Kg as agentError, wb as applyPatchToClone, Tb as applyPatchToLive, Gg as asAgentError, Ty as buildDataPrompt, Ey as buildSystemPrompt, sx as commitSetToBind, Lv as connectMcp, wl as copyText, x_ as createAgent, q_ as createApprovalMiddleware, Wx as createChatSdk, iv as createCheckpointManager, av as createCheckpointMiddleware, jy as createConflictManager, cx as createDataOps, Z_ as createHumanConfirmMiddleware, X_ as createHumanConfirmTool, Qy as createMemoryBackend, B_ as createMemoryMiddleware, v as createProxyLlm, ab as createSdkEvents, nb as createSessionStore, Rx as createSkillStore, _v as createSubagentMiddleware, bv as createSubagentsMiddleware, Nx as createUsageHintsMiddleware, xv as createVerifyMiddleware, Mb as createVfs, eb as createWebStorageBackend, Dv as createWriteBackCheck, _b as deepClone, Ax as defineDataToolset, N_ as defineSkill, Gx as defineTool, gb as deleteByPath, dy as describeSchemaNode, p_ as detectGarbledToolCall, Ob as diffObjects, mx as domToStructure, gx as domTools, kx as domToolsStatic, qv as estimateMessageTokens, Jv as estimateRoundTokens, e_ as estimateTokens, Sy as extractSchemaHint, Pv as extractText, ux as fetchDocTools, Ox as fetchTools, ox as filterByToolMode, fy as formatConstraints, Vg as formatZodIssues, mb as getByPath, hx as getDomTool, yx as getEnvSummary, ry as getSchemaAtPath, ey as getSchemaTopKeys, r_ as getTraceMetrics, Cb as hashValue, Yv as indexSummarize, Sx as inspectEnvTool, Cx as inspectTools, Dy as isChatModel, ty as isPathAllowed, Wy as isQuotaError, fb as isUnsafePath, Zb as jpEval, Ug as jsonParseError, bb as limitDepth, vb as maybeParseValue, n_ as offloadPassThroughChars, t_ as offloadThresholdChars, _y as presets, ay as projectBySchema, iy as projectBySchemaDeep, yb as projectFields, Xv as recallRounds, py as renderSchemaHint, my as renderSchemaOverview, gy as renderSchemaShallow, cb as resolveContextOptions, ib as resolveDialogConfig, Ay as resolveLlm, $g as resolveModelCaps, rb as resolveStorage, Db as restoreInPlace, Eb as restoreLive, Wg as routeError, rx as runSandboxedScript, pb as safeMerge, vx as safeSerialize, xb as safeStringify, $b as searchJson, jx as selectBuiltinTools, hb as setByPath, vy as systemPromptHelpers, Kv as tokenize, $ as toolError, ny as unwrapSchema, Cl as useChat, e as z, Hg as zodError };
20144
+ export { ab as CAPABILITIES, cb as CONTEXT_PRESETS, Bg as ChatDialog, nf as CodePreview, wy as DEFAULT_SYSTEM_PROMPT, J_ as HUMAN_CONFIRM_TOOL_NAME, af as MessageContent, Gv as STOP_WORDS, xh as SkillPanel, pb as UNSAFE_KEYS, Ax as actionsToInspectInfo, kx as actionsToTools, Kg as agentError, Eb as applyPatchToClone, Db as applyPatchToLive, Gg as asAgentError, Ty as buildDataPrompt, Ey as buildSystemPrompt, lx as commitSetToBind, Lv as connectMcp, wl as copyText, x_ as createAgent, q_ as createApprovalMiddleware, qx as createChatSdk, iv as createCheckpointManager, av as createCheckpointMiddleware, jy as createConflictManager, dx as createDataOps, Z_ as createHumanConfirmMiddleware, X_ as createHumanConfirmTool, Qy as createMemoryBackend, B_ as createMemoryMiddleware, v as createProxyLlm, sb as createSdkEvents, nb as createSessionStore, Vx as createSkillStore, _v as createSubagentMiddleware, bv as createSubagentsMiddleware, Ix as createUsageHintsMiddleware, xv as createVerifyMiddleware, Pb as createVfs, eb as createWebStorageBackend, Dv as createWriteBackCheck, yb as deepClone, Nx as defineDataToolset, N_ as defineSkill, Jx as defineTool, vb as deleteByPath, dy as describeSchemaNode, p_ as detectGarbledToolCall, Ab as diffObjects, _x as domToStructure, yx as domTools, Mx as domToolsStatic, qv as estimateMessageTokens, Jv as estimateRoundTokens, e_ as estimateTokens, Sy as extractSchemaHint, Pv as extractText, px as fetchDocTools, jx as fetchTools, cx as filterByToolMode, fy as formatConstraints, Vg as formatZodIssues, gb as getByPath, vx as getDomTool, Sx as getEnvSummary, ry as getSchemaAtPath, ey as getSchemaTopKeys, r_ as getTraceMetrics, Tb as hashValue, Yv as indexSummarize, Tx as inspectEnvTool, Ex as inspectTools, Dy as isChatModel, ty as isPathAllowed, Wy as isQuotaError, mb as isUnsafePath, $b as jpEval, Ug as jsonParseError, Sb as limitDepth, bb as maybeParseValue, n_ as offloadPassThroughChars, t_ as offloadThresholdChars, _y as presets, ay as projectBySchema, iy as projectBySchemaDeep, xb as projectFields, Xv as recallRounds, py as renderSchemaHint, my as renderSchemaOverview, gy as renderSchemaShallow, ob as resolveCapabilities, ub as resolveContextOptions, ib as resolveDialogConfig, Ay as resolveLlm, $g as resolveModelCaps, rb as resolveStorage, kb as restoreInPlace, Ob as restoreLive, Wg as routeError, ax as runSandboxedScript, hb as safeMerge, xx as safeSerialize, Cb as safeStringify, tx as searchJson, Px as selectBuiltinTools, _b as setByPath, vy as systemPromptHelpers, Kv as tokenize, $ as toolError, ny as unwrapSchema, Cl as useChat, e as z, Hg as zodError };