page-agent-sdk 2.21.0 → 2.22.0

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