page-agent-sdk 2.20.1 → 2.21.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.
@@ -22,11 +22,14 @@ function v(e) {
22
22
  let t = e.model || "gpt-3.5-turbo", r = e.temperature, i = e.maxTokens, a = e.baseUrl;
23
23
  if (e.mode === "direct") {
24
24
  try {
25
- typeof location < "u" && location.protocol === "https:" && ![
25
+ if (typeof location < "u" && location.protocol === "https:" && ![
26
26
  "localhost",
27
27
  "127.0.0.1",
28
28
  "0.0.0.0"
29
- ].includes(location.hostname) && console.warn("[page-agent-sdk][proxyLlm] direct 模式在生产环境会泄露 apiKey,建议改用 proxy 模式");
29
+ ].includes(location.hostname)) {
30
+ if (e.throwOnDirectInProduction) throw Error("[page-agent-sdk][proxyLlm] direct 模式在生产环境(https + 非本地)会泄露 apiKey(进 bundle),建议改用 proxy 模式(throwOnDirectInProduction 已启用强安全闸;若确需生产直连,设为 false 显式承认风险)");
31
+ console.warn("[page-agent-sdk][proxyLlm] direct 模式在生产环境(https + 非本地)会泄露 apiKey(进 bundle),建议改用 proxy 模式");
32
+ }
30
33
  } catch {}
31
34
  if (!e.apiKey) throw Error("[page-agent-sdk][proxyLlm] direct 模式需提供 apiKey(开发环境用真实 key)");
32
35
  return new n({
@@ -14044,12 +14047,12 @@ function Hg(e, t) {
14044
14047
  });
14045
14048
  }
14046
14049
  function Ug(e, t, n) {
14047
- let r = n?.message || String(n);
14050
+ let r = n?.message || String(n), i = typeof t == "string" ? t : JSON.stringify(t);
14048
14051
  return $({
14049
14052
  code: "JSON_PARSE",
14050
14053
  ...e === void 0 ? {} : { path: e },
14051
14054
  message: `value 不是合法 JSON:${r}`,
14052
- hint: `检查引号/逗号/括号是否闭合;字符串值需双引号包裹(如 '"dark"' 表示字符串 dark,数字直接写如 5);预览前 80 字符:${t.slice(0, 80)}`
14055
+ hint: `检查引号/逗号/括号是否闭合;字符串值需双引号包裹(如 '"dark"' 表示字符串 dark,数字直接写如 5);预览前 80 字符:${i.slice(0, 80)}`
14053
14056
  });
14054
14057
  }
14055
14058
  function Wg(e) {
@@ -14629,7 +14632,7 @@ function x_(e) {
14629
14632
  return y_(e, t);
14630
14633
  }
14631
14634
  function de(e) {
14632
- return e.map((e) => {
14635
+ return !E && !S ? [] : e.map((e) => {
14633
14636
  let t = le(e), n = { role: t === "human" ? "user" : t === "ai" ? "assistant" : t }, r = typeof e.content == "string" ? e.content : JSON.stringify(e.content);
14634
14637
  r && (n.content = r.length > v_ ? r.slice(0, v_) + `…(截断 ${r.length - v_} 字符)` : r);
14635
14638
  let i = e.tool_calls;
@@ -15408,24 +15411,25 @@ function rv(e) {
15408
15411
  return t;
15409
15412
  }
15410
15413
  function iv(e) {
15411
- let t = [], n = e.maxCheckpoints ?? 5, r = 1;
15414
+ let t = [], n = e.maxCheckpoints ?? 5, r = 1, i, a;
15412
15415
  return {
15413
- save(i) {
15414
- let a = rv(e.messages), o = {};
15415
- if (e.getData) o[""] = Q_(e.getData());
15416
- else for (let t of e.slotPaths ?? []) o[t] = Q_($_(window, t));
15417
- let s = {
15416
+ save(o) {
15417
+ let s = rv(e.messages), c = {};
15418
+ if (e.getData) ((e.consumeDataDirty?.() ?? !0) || a === void 0) && (a = Q_(e.getData())), c[""] = a;
15419
+ else for (let t of e.slotPaths ?? []) c[t] = Q_($_(window, t));
15420
+ ((e.vfsStore.consumeDirty?.() ?? !0) || i === void 0) && (i = Q_(e.vfsStore.files));
15421
+ let l = {
15418
15422
  id: r++,
15419
- label: i,
15423
+ label: o,
15420
15424
  timestamp: Date.now(),
15421
- messages: Q_(a),
15422
- windowVals: o,
15423
- vfs: Q_(e.vfsStore.files),
15425
+ messages: Q_(s),
15426
+ windowVals: c,
15427
+ vfs: i,
15424
15428
  todos: Q_(e.getTodos()),
15425
- messageCount: a.length
15429
+ messageCount: s.length
15426
15430
  };
15427
- for (t.push(s); t.length > n;) t.shift();
15428
- return s.id;
15431
+ for (t.push(l); t.length > n;) t.shift();
15432
+ return l.id;
15429
15433
  },
15430
15434
  list() {
15431
15435
  return t.map((e) => ({
@@ -15448,15 +15452,15 @@ function iv(e) {
15448
15452
  typeof n == "object" && n && tv(n, Q_(t));
15449
15453
  }
15450
15454
  } else for (let [e, t] of Object.entries(r.windowVals)) nv(e, Q_(t));
15451
- let i = e.vfsStore.files;
15452
- for (let e of Object.keys(i)) delete i[e];
15453
- return Object.assign(i, Q_(r.vfs)), e.todosMw.reset(Q_(r.todos)), !0;
15455
+ let o = e.vfsStore.files;
15456
+ for (let e of Object.keys(o)) delete o[e];
15457
+ return Object.assign(o, Q_(r.vfs)), e.todosMw.reset(Q_(r.todos)), a = void 0, i = void 0, !0;
15454
15458
  },
15455
15459
  exportStack() {
15456
15460
  return Q_(t);
15457
15461
  },
15458
15462
  importStack(e) {
15459
- t.length = 0;
15463
+ t.length = 0, i = void 0, a = void 0;
15460
15464
  let n = Array.isArray(e) ? e : [];
15461
15465
  for (let e of n) e && typeof e == "object" && "id" in e && "messages" in e && typeof e.id == "number" && Number.isFinite(e.id) && t.push(e);
15462
15466
  r = t.reduce((e, t) => Math.max(e, t.id), 0) + 1;
@@ -16383,9 +16387,21 @@ var _y = {
16383
16387
  "3. 不确定某字段结构时,read({ jsonPath }) 返回含格式说明,字段以返回为准;",
16384
16388
  "4. 写入若被 schema 校验拒绝(返回结构化错误含字段名与期望类型),按错误修正后重试,不要放弃;",
16385
16389
  "5. 优先用 write 的 patch 增量改(只发改动,如 write({ value, patch:{ op, jsonPath } })),避免整体重传大 JSON 被截断。"
16386
- ].join("\n") }, yy = 15, by = 4e3;
16387
- function xy(e, t) {
16390
+ ].join("\n") }, yy = 15, by = 4e3, xy = /* @__PURE__ */ new WeakMap();
16391
+ function Sy(e, t) {
16388
16392
  if (!e) return "";
16393
+ let n = t ? `${t.maxKeys ?? ""}|${t.maxChars ?? ""}` : "";
16394
+ if (typeof e == "object") {
16395
+ let t = xy.get(e);
16396
+ if (t && t.optsKey === n) return t.hint;
16397
+ }
16398
+ let r = Cy(e, t);
16399
+ return typeof e == "object" && xy.set(e, {
16400
+ optsKey: n,
16401
+ hint: r
16402
+ }), r;
16403
+ }
16404
+ function Cy(e, t) {
16389
16405
  let n = my(e);
16390
16406
  if (n) {
16391
16407
  let r = t?.maxKeys ?? yy, i = t?.maxChars ?? by;
@@ -16399,36 +16415,36 @@ function xy(e, t) {
16399
16415
  }
16400
16416
  //#endregion
16401
16417
  //#region src/core/sdk/promptBuilder.ts
16402
- var Sy = [
16418
+ var wy = [
16403
16419
  "你是一个 JSON 操作助手。集成方声明了一个主数据对象(含 zod schema 校验),你通过专用工具安全地读写它来完成任务。",
16404
16420
  "所有写操作都经范围控制(仅 schema 声明字段内)与 schema 校验(不合法会返回结构化错误而非写入),并自动留快照可回退。",
16405
16421
  "大对象/数组优先用增量 patch(只发改动)而非整体重传,避免输出被截断。",
16406
16422
  "---",
16407
16423
  vy.reliableWriteRules
16408
16424
  ].join("\n\n");
16409
- function Cy(e, t) {
16425
+ function Ty(e, t) {
16410
16426
  if (!e) return "";
16411
- let n = xy(e.schema, t);
16427
+ let n = Sy(e.schema, t);
16412
16428
  return `\n\n## 可操作数据(字段以 read 工具返回的实际值为准)\n${e.description ? e.description + "\n" : ""}${n}`;
16413
16429
  }
16414
- function wy(e) {
16430
+ function Ey(e) {
16415
16431
  let t = e.appendReliableWriteRules !== !1;
16416
- return e.systemPrompt ? t ? e.systemPrompt + "\n\n---\n\n" + vy.reliableWriteRules : e.systemPrompt : Sy;
16432
+ return e.systemPrompt ? t ? e.systemPrompt + "\n\n---\n\n" + vy.reliableWriteRules : e.systemPrompt : wy;
16417
16433
  }
16418
16434
  //#endregion
16419
16435
  //#region src/core/sdk/llmResolver.ts
16420
- function Ty(e) {
16436
+ function Dy(e) {
16421
16437
  return !!e && typeof e == "object" && typeof e.invoke == "function" && typeof e.stream == "function";
16422
16438
  }
16423
- function Ey(e) {
16439
+ function Oy(e) {
16424
16440
  let t = e.content;
16425
16441
  return typeof t == "string" ? t : Array.isArray(t) ? t.map((e) => typeof e == "string" ? e : e?.text ?? "").join("") : String(t ?? "");
16426
16442
  }
16427
- function Dy(e) {
16443
+ function ky(e) {
16428
16444
  let t = e.summaryLlm ?? e.llm;
16429
16445
  if (!t) return;
16430
16446
  let r = e.summaryTemperature ?? .3, i = e.summaryMaxTokens ?? 1024, s = e.summaryTimeoutMs ?? 15e3, c;
16431
- if (Ty(t)) c = t;
16447
+ if (Dy(t)) c = t;
16432
16448
  else {
16433
16449
  let a = t;
16434
16450
  if (!a.apiKey) {
@@ -16450,26 +16466,26 @@ function Dy(e) {
16450
16466
  return async (e) => {
16451
16467
  let t = new AbortController(), n = setTimeout(() => t.abort(), s);
16452
16468
  try {
16453
- return Ey(await c.invoke([new o("你是对话历史压缩助手。把下面按轮次索引的对话要点,改写成一段连贯、紧凑的中文摘要,保留关键事实、用户意图与已用工具,不要编造。直接输出摘要正文。"), new a(e)], { signal: t.signal })).trim();
16469
+ return Oy(await c.invoke([new o("你是对话历史压缩助手。把下面按轮次索引的对话要点,改写成一段连贯、紧凑的中文摘要,保留关键事实、用户意图与已用工具,不要编造。直接输出摘要正文。"), new a(e)], { signal: t.signal })).trim();
16454
16470
  } finally {
16455
16471
  clearTimeout(n);
16456
16472
  }
16457
16473
  };
16458
16474
  }
16459
- function Oy(e) {
16460
- let t = Ty(e.llm) ? void 0 : e.llm;
16475
+ function Ay(e) {
16476
+ let t = Dy(e.llm) ? void 0 : e.llm;
16461
16477
  return {
16462
16478
  modelCaps: $g({
16463
16479
  model: t?.model,
16464
16480
  contextWindow: e.contextWindow ?? t?.contextWindow,
16465
16481
  maxOutputTokens: e.maxOutputTokens ?? t?.maxOutputTokens
16466
16482
  }),
16467
- summaryLlmInvoke: Dy(e)
16483
+ summaryLlmInvoke: ky(e)
16468
16484
  };
16469
16485
  }
16470
16486
  //#endregion
16471
16487
  //#region src/core/sdk/conflictManager.ts
16472
- function ky(e) {
16488
+ function jy(e) {
16473
16489
  let t = /* @__PURE__ */ U(null), n = 0;
16474
16490
  function r(r) {
16475
16491
  return new Promise((i) => {
@@ -16480,7 +16496,9 @@ function ky(e) {
16480
16496
  id: ++n,
16481
16497
  resolve: i
16482
16498
  };
16483
- t.value = o, e?.()({
16499
+ t.value = o;
16500
+ let s = e?.();
16501
+ s?.({
16484
16502
  type: "conflict",
16485
16503
  conflict: o
16486
16504
  });
@@ -16498,7 +16516,7 @@ function ky(e) {
16498
16516
  }
16499
16517
  //#endregion
16500
16518
  //#region src/core/utils/id.ts
16501
- function Ay() {
16519
+ function My() {
16502
16520
  try {
16503
16521
  if (typeof crypto < "u" && typeof crypto.randomUUID == "function") return crypto.randomUUID();
16504
16522
  } catch {}
@@ -16506,57 +16524,59 @@ function Ay() {
16506
16524
  }
16507
16525
  //#endregion
16508
16526
  //#region src/core/backends/storage.ts
16509
- var jy = "chat-sdk", My = 52428800, Ny = 4194304, Py = 10485760, Fy = .9, Iy = 500, Ly = 300, Ry = "__meta__", zy = "v:1", By = [
16527
+ var Ny = "chat-sdk", Py = 52428800, Fy = 4194304, Iy = 10485760, Ly = .9, Ry = 500, zy = 300, By = "__meta__", Vy = "v:1", Hy = [
16510
16528
  "messages",
16511
16529
  "vfs",
16512
16530
  "todos",
16513
- "memory"
16531
+ "memory",
16532
+ "checkpoints",
16533
+ "usage"
16514
16534
  ];
16515
- function Vy(e) {
16516
- return e === "local" || e === "session" ? Ny : My;
16535
+ function Uy(e) {
16536
+ return e === "local" || e === "session" ? Fy : Py;
16517
16537
  }
16518
- function Hy(e) {
16538
+ function Wy(e) {
16519
16539
  if (typeof e != "object" || !e) return !1;
16520
16540
  let t = e;
16521
16541
  return t.name === "QuotaExceededError" || t.name === "NS_ERROR_DOM_QUOTA_REACHED" || t.code === 22 || t.code === 1014;
16522
16542
  }
16523
- function Uy(e, t, n, r) {
16543
+ function Gy(e, t, n, r) {
16524
16544
  return [
16525
- zy,
16545
+ Vy,
16526
16546
  e,
16527
16547
  t,
16528
16548
  n,
16529
16549
  r
16530
16550
  ].join("::");
16531
16551
  }
16532
- function Wy(e, t, n) {
16552
+ function Ky(e, t, n) {
16533
16553
  return [
16534
- zy,
16554
+ Vy,
16535
16555
  e,
16536
16556
  t,
16537
16557
  n
16538
16558
  ].join("::") + "::";
16539
16559
  }
16540
- function Gy(e, t) {
16560
+ function qy(e, t) {
16541
16561
  return [
16542
- zy,
16562
+ Vy,
16543
16563
  e,
16544
16564
  t
16545
16565
  ].join("::") + "::";
16546
16566
  }
16547
- function Ky(e) {
16548
- return [zy, e].join("::") + "::";
16549
- }
16550
- var qy = null;
16551
16567
  function Jy(e) {
16552
- qy ||= new TextEncoder();
16568
+ return [Vy, e].join("::") + "::";
16569
+ }
16570
+ var Yy = null;
16571
+ function Xy(e) {
16572
+ Yy ||= new TextEncoder();
16553
16573
  try {
16554
- return qy.encode(JSON.stringify(e)).length;
16574
+ return Yy.encode(JSON.stringify(e)).length;
16555
16575
  } catch {
16556
16576
  return 0;
16557
16577
  }
16558
16578
  }
16559
- function Yy(e, t, n) {
16579
+ function Zy(e, t, n) {
16560
16580
  let r = e.reduce((e, t) => e + t.bytes, 0);
16561
16581
  if (r <= t) return [];
16562
16582
  let i = t * n, a = [...e].sort((e, t) => e.lastAccessed - t.lastAccessed), o = [];
@@ -16566,7 +16586,7 @@ function Yy(e, t, n) {
16566
16586
  }
16567
16587
  return o;
16568
16588
  }
16569
- function Xy() {
16589
+ function Qy() {
16570
16590
  let e = /* @__PURE__ */ new Map();
16571
16591
  return {
16572
16592
  async get(t) {
@@ -16586,7 +16606,7 @@ function Xy() {
16586
16606
  }
16587
16607
  };
16588
16608
  }
16589
- function Zy(e) {
16609
+ function $y(e) {
16590
16610
  return new Promise((t, n) => {
16591
16611
  if (typeof indexedDB > "u") {
16592
16612
  n(/* @__PURE__ */ Error("indexedDB 不可用"));
@@ -16647,7 +16667,7 @@ function Zy(e) {
16647
16667
  }, r.onerror = () => n(r.error);
16648
16668
  });
16649
16669
  }
16650
- function Qy(e) {
16670
+ function eb(e) {
16651
16671
  return {
16652
16672
  async get(t) {
16653
16673
  let n = e.getItem(t);
@@ -16681,12 +16701,12 @@ function Qy(e) {
16681
16701
  }
16682
16702
  };
16683
16703
  }
16684
- function $y(e, t, n) {
16704
+ function tb(e, t, n) {
16685
16705
  let r = (e.get(t) ?? Promise.resolve()).then(n, n);
16686
16706
  return e.set(t, r.then(() => void 0, () => void 0)), r;
16687
16707
  }
16688
- function eb(e = {}) {
16689
- let t = e.dbName ?? jy, n = e.backend ?? "indexed", r = e.maxBytes ?? Vy(n), i = e.maxBytesPerSession ?? Py, a = e.evictionWatermark ?? Fy, o = e.debounceMs ?? Iy, s = /* @__PURE__ */ new Set();
16708
+ function nb(e = {}) {
16709
+ let t = e.dbName ?? Ny, n = e.backend ?? "indexed", r = e.maxBytes ?? Uy(n), i = e.maxBytesPerSession ?? Iy, a = e.evictionWatermark ?? Ly, o = e.debounceMs ?? Ry, s = /* @__PURE__ */ new Set();
16690
16710
  function c(e) {
16691
16711
  for (let t of s) try {
16692
16712
  t(e);
@@ -16699,16 +16719,16 @@ function eb(e = {}) {
16699
16719
  try {
16700
16720
  if (n === "indexed") {
16701
16721
  if (typeof indexedDB > "u") throw Error("indexedDB 不可用");
16702
- l = await Zy(t), d(!0);
16722
+ l = await $y(t), d(!0);
16703
16723
  } else if (n === "session") {
16704
16724
  if (typeof sessionStorage > "u") throw Error("sessionStorage 不可用");
16705
- l = Qy(sessionStorage), d(!0);
16725
+ l = eb(sessionStorage), d(!0);
16706
16726
  } else if (n === "local") {
16707
16727
  if (typeof localStorage > "u") throw Error("localStorage 不可用");
16708
- l = Qy(localStorage), d(!0);
16709
- } else l = Xy(), d(!1);
16728
+ l = eb(localStorage), d(!0);
16729
+ } else l = Qy(), d(!1);
16710
16730
  } catch (e) {
16711
- l = Xy();
16731
+ l = Qy();
16712
16732
  let t = e instanceof Error ? e.message : String(e);
16713
16733
  d(!1), Promise.resolve().then(() => c({
16714
16734
  type: "degraded",
@@ -16718,10 +16738,10 @@ function eb(e = {}) {
16718
16738
  })();
16719
16739
  let p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
16720
16740
  function g(e, n, r, a) {
16721
- let o = Uy(t, r, a, Ry);
16722
- return $y(h, o, async () => {
16741
+ let o = Gy(t, r, a, By);
16742
+ return tb(h, o, async () => {
16723
16743
  let t = async () => {
16724
- let t = await l.get(o), s = await l.get(e), u = s == null ? 0 : Jy(s), d = Jy(n), f = (t?.bytes ?? 0) + (d - u);
16744
+ let t = await l.get(o), s = await l.get(e), u = s == null ? 0 : Xy(s), d = Xy(n), f = (t?.bytes ?? 0) + (d - u);
16725
16745
  if (f > i) {
16726
16746
  c({
16727
16747
  type: "quota",
@@ -16743,12 +16763,12 @@ function eb(e = {}) {
16743
16763
  try {
16744
16764
  await t();
16745
16765
  } catch (e) {
16746
- if (Hy(e) && !u) {
16766
+ if (Wy(e) && !u) {
16747
16767
  u = !0;
16748
16768
  try {
16749
16769
  await b();
16750
16770
  } catch {}
16751
- l = Xy(), Promise.resolve().then(() => c({
16771
+ l = Qy(), Promise.resolve().then(() => c({
16752
16772
  type: "degraded",
16753
16773
  reason: "存储配额超限(QuotaExceededError),已淘汰最旧会话并降级内存"
16754
16774
  }));
@@ -16760,7 +16780,7 @@ function eb(e = {}) {
16760
16780
  });
16761
16781
  }
16762
16782
  function _(e, n, r, i) {
16763
- let a = Uy(t, e, n, r), s = p.get(a);
16783
+ let a = Gy(t, e, n, r), s = p.get(a);
16764
16784
  s && s.resolve();
16765
16785
  let c = m.get(a);
16766
16786
  return c && clearTimeout(c), new Promise((t) => {
@@ -16787,15 +16807,15 @@ function eb(e = {}) {
16787
16807
  function y() {
16788
16808
  v ||= setTimeout(() => {
16789
16809
  v = null, b();
16790
- }, Ly);
16810
+ }, zy);
16791
16811
  }
16792
16812
  async function b() {
16793
16813
  let e = [];
16794
- await l.scan(Ky(t), (t, n) => {
16814
+ await l.scan(Jy(t), (t, n) => {
16795
16815
  t.endsWith("::__meta__") && e.push(n);
16796
16816
  });
16797
- let n = Yy(e, r, a);
16798
- for (let e of n) await l.clearPrefix(Wy(t, e.agentId, e.sessionId)), c({
16817
+ let n = Zy(e, r, a);
16818
+ for (let e of n) await l.clearPrefix(Ky(t, e.agentId, e.sessionId)), c({
16799
16819
  type: "evicted",
16800
16820
  agentId: e.agentId,
16801
16821
  sessionId: e.sessionId,
@@ -16806,13 +16826,13 @@ function eb(e = {}) {
16806
16826
  ready: f,
16807
16827
  async listSessions(e) {
16808
16828
  let n = [];
16809
- return await l.scan(Gy(t, e), (e, t) => {
16829
+ return await l.scan(qy(t, e), (e, t) => {
16810
16830
  e.endsWith("::__meta__") && n.push(t);
16811
16831
  }), n.sort((e, t) => t.lastAccessed - e.lastAccessed);
16812
16832
  },
16813
16833
  async load(e, n) {
16814
- let r = Uy(t, e, n, Ry);
16815
- return await $y(h, r, async () => {
16834
+ let r = Gy(t, e, n, By);
16835
+ return await tb(h, r, async () => {
16816
16836
  let i = await l.get(r);
16817
16837
  if (!i) return;
16818
16838
  let a = {
@@ -16821,8 +16841,8 @@ function eb(e = {}) {
16821
16841
  todos: [],
16822
16842
  memory: ""
16823
16843
  };
16824
- for (let r of By) {
16825
- let i = await l.get(Uy(t, e, n, r));
16844
+ for (let r of Hy) {
16845
+ let i = await l.get(Gy(t, e, n, r));
16826
16846
  i != null && (a[r] = i);
16827
16847
  }
16828
16848
  return i.lastAccessed = Date.now(), await l.set(r, i), a;
@@ -16830,7 +16850,7 @@ function eb(e = {}) {
16830
16850
  },
16831
16851
  async save(e, t, n) {
16832
16852
  let r = [];
16833
- for (let i of By) n[i] !== void 0 && r.push(_(e, t, i, n[i]));
16853
+ for (let i of Hy) n[i] !== void 0 && r.push(_(e, t, i, n[i]));
16834
16854
  await Promise.all(r);
16835
16855
  },
16836
16856
  async flush() {
@@ -16844,10 +16864,10 @@ function eb(e = {}) {
16844
16864
  })), c({ type: "flush" }), await b();
16845
16865
  },
16846
16866
  async deleteSession(e, n) {
16847
- await l.clearPrefix(Wy(t, e, n));
16867
+ await l.clearPrefix(Ky(t, e, n));
16848
16868
  },
16849
16869
  async createSession(e, n, r) {
16850
- let i = r ?? Ay(), a = Date.now(), o = {
16870
+ let i = r ?? My(), a = Date.now(), o = {
16851
16871
  agentId: e,
16852
16872
  sessionId: i,
16853
16873
  createdAt: a,
@@ -16855,7 +16875,7 @@ function eb(e = {}) {
16855
16875
  bytes: 0,
16856
16876
  title: n
16857
16877
  };
16858
- return await l.set(Uy(t, e, i, Ry), o), i;
16878
+ return await l.set(Gy(t, e, i, By), o), i;
16859
16879
  },
16860
16880
  onEvent(e) {
16861
16881
  s.add(e);
@@ -16870,15 +16890,15 @@ function eb(e = {}) {
16870
16890
  }
16871
16891
  //#endregion
16872
16892
  //#region src/core/sdk/optionsResolver.ts
16873
- function tb(e) {
16874
- return e === void 0 || e === !1 ? null : typeof e == "string" ? eb({ backend: e }) : e.enabled === !1 ? null : eb(e);
16893
+ function rb(e) {
16894
+ return e === void 0 || e === !1 ? null : typeof e == "string" ? nb({ backend: e }) : e.enabled === !1 ? null : nb(e);
16875
16895
  }
16876
- function nb(e) {
16896
+ function ib(e) {
16877
16897
  return e.dialog ?? {};
16878
16898
  }
16879
16899
  //#endregion
16880
16900
  //#region src/core/sdk/events.ts
16881
- function rb(e) {
16901
+ function ab(e) {
16882
16902
  let t = /* @__PURE__ */ new Set(), n = (n) => {
16883
16903
  if (n.type !== "approval_request") {
16884
16904
  if (e) try {
@@ -16904,7 +16924,7 @@ function rb(e) {
16904
16924
  }
16905
16925
  //#endregion
16906
16926
  //#region src/core/sdk/contextPreset.ts
16907
- var ib = {
16927
+ var ob = {
16908
16928
  auto: {
16909
16929
  summaryThresholdRatio: .5,
16910
16930
  windowRatio: .4,
@@ -16932,7 +16952,7 @@ var ib = {
16932
16952
  enableRecall: !0,
16933
16953
  enableLLMSummary: !0
16934
16954
  }
16935
- }, ab = {
16955
+ }, sb = {
16936
16956
  auto: ["describe_data", "read"],
16937
16957
  conservative: ["describe_data"],
16938
16958
  aggressive: ["describe_data", "read"],
@@ -16943,8 +16963,8 @@ var ib = {
16943
16963
  "search_data"
16944
16964
  ]
16945
16965
  };
16946
- function ob(e, t) {
16947
- let n = ib[e.contextPreset ?? "auto"] ?? {}, r = e.contextOptions === !1 ? {} : e.contextOptions ?? {};
16966
+ function cb(e, t) {
16967
+ let n = ob[e.contextPreset ?? "auto"] ?? {}, r = e.contextOptions === !1 ? {} : e.contextOptions ?? {};
16948
16968
  return {
16949
16969
  ...n,
16950
16970
  ...r,
@@ -16954,7 +16974,7 @@ function ob(e, t) {
16954
16974
  }
16955
16975
  //#endregion
16956
16976
  //#region src/core/sdk/middlewareStack.ts
16957
- var sb = {
16977
+ var lb = {
16958
16978
  dataHint: 10,
16959
16979
  usageHints: 20,
16960
16980
  todos: 30,
@@ -16971,29 +16991,29 @@ var sb = {
16971
16991
  subagents: 140,
16972
16992
  augmentSystem: 150
16973
16993
  };
16974
- function cb(e) {
16994
+ function ub(e) {
16975
16995
  return e.map((e, t) => ({
16976
16996
  m: e,
16977
16997
  i: t,
16978
- p: sb[e.name] ?? Infinity
16998
+ p: lb[e.name] ?? Infinity
16979
16999
  })).sort((e, t) => e.p - t.p || e.i - t.i).map((e) => e.m);
16980
17000
  }
16981
17001
  //#endregion
16982
17002
  //#region src/core/tools/jsonUtils.ts
16983
- var lb = /* @__PURE__ */ new Set([
17003
+ var db = /* @__PURE__ */ new Set([
16984
17004
  "__proto__",
16985
17005
  "constructor",
16986
17006
  "prototype"
16987
17007
  ]);
16988
- function ub(e) {
16989
- return e.split(".").some((e) => lb.has(e));
17008
+ function fb(e) {
17009
+ return e.split(".").some((e) => db.has(e));
16990
17010
  }
16991
- function db(e, t) {
16992
- if (!(!t || typeof t != "object" || Array.isArray(t))) for (let n of Object.keys(t)) lb.has(n) || (e[n] = t[n]);
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]);
16993
17013
  }
16994
- function fb(e, t) {
17014
+ function mb(e, t) {
16995
17015
  if (!t) return e;
16996
- if (ub(t)) return;
17016
+ if (fb(t)) return;
16997
17017
  let n = t.split("."), r = e;
16998
17018
  for (let e of n) {
16999
17019
  if (r == null) return;
@@ -17001,8 +17021,8 @@ function fb(e, t) {
17001
17021
  }
17002
17022
  return r;
17003
17023
  }
17004
- function pb(e, t, n) {
17005
- if (!t || ub(t)) return;
17024
+ function hb(e, t, n) {
17025
+ if (!t || fb(t)) return;
17006
17026
  let r = t.split("."), i = e;
17007
17027
  for (let e = 0; e < r.length - 1; e++) {
17008
17028
  let t = r[e];
@@ -17010,8 +17030,8 @@ function pb(e, t, n) {
17010
17030
  }
17011
17031
  i[r[r.length - 1]] = n;
17012
17032
  }
17013
- function mb(e, t) {
17014
- if (!t || ub(t)) return !1;
17033
+ function gb(e, t) {
17034
+ if (!t || fb(t)) return !1;
17015
17035
  let n = t.split("."), r = e;
17016
17036
  for (let e = 0; e < n.length - 1; e++) {
17017
17037
  if (r == null) return !1;
@@ -17020,10 +17040,10 @@ function mb(e, t) {
17020
17040
  let i = n[n.length - 1];
17021
17041
  return r == null || !(i in r) ? !1 : (Array.isArray(r) && /^\d+$/.test(i) ? r.splice(Number(i), 1) : delete r[i], !0);
17022
17042
  }
17023
- function hb(e) {
17043
+ function _b(e) {
17024
17044
  return e === void 0 ? void 0 : JSON.parse(JSON.stringify(e));
17025
17045
  }
17026
- function gb(e) {
17046
+ function vb(e) {
17027
17047
  if (typeof e != "string") return { parsed: e };
17028
17048
  let t = e.trim();
17029
17049
  if (!t) return { parsed: e };
@@ -17034,23 +17054,23 @@ function gb(e) {
17034
17054
  return n ? { parseError: t } : { parsed: e };
17035
17055
  }
17036
17056
  }
17037
- function _b(e, t) {
17057
+ function yb(e, t) {
17038
17058
  if (typeof e != "object" || !e) return e;
17039
17059
  let n = new Set(t);
17040
- if (Array.isArray(e)) return e.map((e) => _b(e, t));
17060
+ if (Array.isArray(e)) return e.map((e) => yb(e, t));
17041
17061
  let r = {};
17042
17062
  for (let t of Object.keys(e)) n.has(t) && (r[t] = e[t]);
17043
17063
  return r;
17044
17064
  }
17045
- function vb(e, t) {
17065
+ function bb(e, t) {
17046
17066
  if (typeof e != "object" || !e) return e;
17047
17067
  if (t <= 0) return Array.isArray(e) ? `[...${e.length}]` : "{...}";
17048
- if (Array.isArray(e)) return e.map((e) => vb(e, t - 1));
17068
+ if (Array.isArray(e)) return e.map((e) => bb(e, t - 1));
17049
17069
  let n = {};
17050
- for (let r of Object.keys(e)) n[r] = vb(e[r], t - 1);
17070
+ for (let r of Object.keys(e)) n[r] = bb(e[r], t - 1);
17051
17071
  return n;
17052
17072
  }
17053
- function yb(e, t = Infinity) {
17073
+ function xb(e, t = Infinity) {
17054
17074
  let n = /* @__PURE__ */ new WeakSet(), r;
17055
17075
  try {
17056
17076
  r = JSON.stringify(e, (e, t) => {
@@ -17069,7 +17089,7 @@ function yb(e, t = Infinity) {
17069
17089
  }
17070
17090
  return r.length > t && (r = r.slice(0, t) + `\n…[已截断,原长度 ${r.length}]`), r;
17071
17091
  }
17072
- function bb(e, t = 0) {
17092
+ function Sb(e, t = 0) {
17073
17093
  let n = 3735928559 ^ t, r = 1103547991 ^ t;
17074
17094
  for (let t = 0; t < e.length; t++) {
17075
17095
  let i = e.charCodeAt(t);
@@ -17077,32 +17097,32 @@ function bb(e, t = 0) {
17077
17097
  }
17078
17098
  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);
17079
17099
  }
17080
- function xb(e) {
17081
- return bb(yb(e)).toString(36);
17100
+ function Cb(e) {
17101
+ return Sb(xb(e)).toString(36);
17082
17102
  }
17083
- function Sb(e, t, n, r) {
17084
- if (t === "set") return n ? (pb(e, n, r), null) : "set 操作需要 jsonPath(整体替换请用 set_data)";
17085
- if (t === "remove") return n ? (mb(e, n), null) : "remove 操作需要 jsonPath";
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";
17086
17106
  if (t === "merge") {
17087
- let t = n ? fb(e, n) : e;
17088
- return typeof t != "object" || !t || Array.isArray(t) ? `merge 目标${n ? `(${n})` : "(根)"}不是对象` : (db(t, r), null);
17107
+ let t = n ? mb(e, n) : e;
17108
+ return typeof t != "object" || !t || Array.isArray(t) ? `merge 目标${n ? `(${n})` : "(根)"}不是对象` : (pb(t, r), null);
17089
17109
  }
17090
- let i = n ? fb(e, n) : e;
17110
+ let i = n ? mb(e, n) : e;
17091
17111
  return Array.isArray(i) ? (Array.isArray(r) ? i.push(...r) : i.push(r), null) : `append 目标${n ? `(${n})` : "(根)"}不是数组`;
17092
17112
  }
17093
- function Cb(e, t, n, r) {
17094
- if (t === "set") pb(e, n, r);
17095
- else if (t === "remove") mb(e, n);
17096
- else if (t === "merge") db(n ? fb(e, n) : e, r);
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);
17097
17117
  else {
17098
- let t = n ? fb(e, n) : e;
17118
+ let t = n ? mb(e, n) : e;
17099
17119
  Array.isArray(r) ? t.push(...r) : t.push(r);
17100
17120
  }
17101
17121
  }
17102
- function wb(e, t) {
17103
- typeof e == "object" && e && Tb(e, t);
17122
+ function Eb(e, t) {
17123
+ typeof e == "object" && e && Db(e, t);
17104
17124
  }
17105
- function Tb(e, t) {
17125
+ function Db(e, t) {
17106
17126
  if (Array.isArray(e)) {
17107
17127
  e.length = 0, Array.isArray(t) && e.push(...t);
17108
17128
  return;
@@ -17111,7 +17131,7 @@ function Tb(e, t) {
17111
17131
  for (let t of Object.keys(e)) t in n || delete e[t];
17112
17132
  for (let t of Object.keys(n)) e[t] = n[t];
17113
17133
  }
17114
- function Eb(e, t, n = "") {
17134
+ function Ob(e, t, n = "") {
17115
17135
  let r = [];
17116
17136
  if (!(typeof e == "object" && e) || !(typeof t == "object" && t) || Array.isArray(e) !== Array.isArray(t)) return e !== t && r.push({
17117
17137
  path: n || "(root)",
@@ -17130,14 +17150,14 @@ function Eb(e, t, n = "") {
17130
17150
  path: i,
17131
17151
  from: e[a],
17132
17152
  to: void 0
17133
- }) : r.push(...Eb(e[a], t[a], i));
17153
+ }) : r.push(...Ob(e[a], t[a], i));
17134
17154
  }
17135
17155
  return r;
17136
17156
  }
17137
17157
  let i = e, a = t, o = /* @__PURE__ */ new Set([...Object.keys(i), ...Object.keys(a)]);
17138
17158
  for (let e of o) {
17139
17159
  let t = n ? `${n}.${e}` : e;
17140
- e in i ? e in a ? r.push(...Eb(i[e], a[e], t)) : r.push({
17160
+ e in i ? e in a ? r.push(...Ob(i[e], a[e], t)) : r.push({
17141
17161
  path: t,
17142
17162
  from: i[e],
17143
17163
  to: void 0
@@ -17149,91 +17169,98 @@ function Eb(e, t, n = "") {
17149
17169
  }
17150
17170
  return r;
17151
17171
  }
17152
- var Db = {
17172
+ var kb = {
17153
17173
  largeResults: 4194304,
17154
17174
  drafts: 2097152,
17155
17175
  userFiles: 2097152
17156
- }, Ob = [
17176
+ }, Ab = [
17157
17177
  "largeResults",
17158
17178
  "drafts",
17159
17179
  "userFiles"
17160
- ], kb = .9;
17161
- function Ab(e, t = {}) {
17180
+ ], jb = .9;
17181
+ function Mb(e, t = {}) {
17162
17182
  let n = Object.create(null);
17163
- if (e) for (let [t, r] of Object.entries(e)) n[Pb(t)] = {
17183
+ if (e) for (let [t, r] of Object.entries(e)) n[Ib(t)] = {
17164
17184
  content: r,
17165
- updatedAt: Ib()
17185
+ updatedAt: Rb()
17166
17186
  };
17167
17187
  let { persist: r } = t, i = t.maxBytes ?? 8388608, a = {
17168
- ...Db,
17188
+ ...kb,
17169
17189
  ...t.poolBytes ?? {}
17170
17190
  };
17171
17191
  function o(e) {
17172
- let t = Pb(e);
17192
+ let t = Ib(e);
17173
17193
  return t.startsWith("large_results/") ? "largeResults" : t.startsWith("drafts/") ? "drafts" : "userFiles";
17174
17194
  }
17175
17195
  function s(e) {
17176
17196
  let t = 0;
17177
- for (let [r, i] of Object.entries(n)) o(r) === e && (t += Mb(i.content));
17197
+ for (let [r, i] of Object.entries(n)) o(r) === e && (t += Pb(i.content));
17178
17198
  return t;
17179
17199
  }
17180
17200
  function c() {
17181
- for (let e of Ob) {
17201
+ for (let e of Ab) {
17182
17202
  let t = a[e];
17183
17203
  if (s(e) <= t) continue;
17184
- let r = t * kb, i = Object.entries(n).filter(([t]) => o(t) === e).sort((e, t) => e[1].updatedAt - t[1].updatedAt);
17204
+ let r = t * jb, i = Object.entries(n).filter(([t]) => o(t) === e).sort((e, t) => e[1].updatedAt - t[1].updatedAt);
17185
17205
  for (let [t] of i) if (delete n[t], s(e) <= r) break;
17186
17206
  }
17187
- if (Nb(n) > i) {
17188
- let e = i * kb, t = Object.entries(n).sort((e, t) => e[1].updatedAt - t[1].updatedAt);
17189
- for (let [r] of t) if (delete n[r], Nb(n) <= e) break;
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;
17190
17210
  }
17191
17211
  }
17192
- let l = null;
17193
- function u() {
17212
+ let l = !0, u = null;
17213
+ function d() {
17194
17214
  if (!r?.save) return;
17195
17215
  let e = {};
17196
17216
  for (let [t, r] of Object.entries(n)) e[t] = { ...r };
17197
17217
  r.save(e);
17198
17218
  }
17199
- function d() {
17200
- r?.save && (l && clearTimeout(l), l = setTimeout(() => {
17201
- l = null, u();
17219
+ function f() {
17220
+ r?.save && (u && clearTimeout(u), u = setTimeout(() => {
17221
+ u = null, d();
17202
17222
  }, 800));
17203
17223
  }
17204
- let f = { files: new Proxy(n, {
17205
- set(e, t, n) {
17206
- let r = Reflect.set(e, t, n);
17207
- return r && (c(), d()), r;
17208
- },
17209
- deleteProperty(e, t) {
17210
- let n = Reflect.deleteProperty(e, t);
17211
- return n && d(), n;
17212
- }
17213
- }) };
17214
- return r && (f.hydrate = (e) => {
17215
- for (let [t, r] of Object.entries(e)) n[Pb(t)] = r;
17216
- c();
17217
- }, f.flush = () => {
17218
- l &&= (clearTimeout(l), null), u();
17219
- }, f.clear = () => {
17224
+ let p = {
17225
+ files: new Proxy(n, {
17226
+ set(e, t, n) {
17227
+ let r = Reflect.set(e, t, n);
17228
+ return r && (l = !0, c(), f()), r;
17229
+ },
17230
+ deleteProperty(e, t) {
17231
+ let n = Reflect.deleteProperty(e, t);
17232
+ return n && (l = !0, f()), n;
17233
+ }
17234
+ }),
17235
+ isDirty: () => l,
17236
+ consumeDirty: () => {
17237
+ let e = l;
17238
+ return l = !1, e;
17239
+ }
17240
+ };
17241
+ return r && (p.hydrate = (e) => {
17242
+ for (let [t, r] of Object.entries(e)) n[Ib(t)] = r;
17243
+ c(), l = !0;
17244
+ }, p.flush = () => {
17245
+ u &&= (clearTimeout(u), null), d();
17246
+ }, p.clear = () => {
17220
17247
  for (let e of Object.keys(n)) delete n[e];
17221
- d();
17222
- }), f;
17248
+ f(), l = !0;
17249
+ }), p;
17223
17250
  }
17224
- var jb = null;
17225
- function Mb(e) {
17226
- return jb ||= new TextEncoder(), jb.encode(e).length;
17251
+ var Nb = null;
17252
+ function Pb(e) {
17253
+ return Nb ||= new TextEncoder(), Nb.encode(e).length;
17227
17254
  }
17228
- function Nb(e) {
17255
+ function Fb(e) {
17229
17256
  let t = 0;
17230
- for (let n of Object.values(e)) t += Mb(n.content);
17257
+ for (let n of Object.values(e)) t += Pb(n.content);
17231
17258
  return t;
17232
17259
  }
17233
- function Pb(e) {
17260
+ function Ib(e) {
17234
17261
  return e.replace(/^\/+/, "").replace(/\/+/g, "/");
17235
17262
  }
17236
- function Fb(e) {
17263
+ function Lb(e) {
17237
17264
  let t = "";
17238
17265
  for (let n = 0; n < e.length; n++) {
17239
17266
  let r = e[n];
@@ -17241,10 +17268,10 @@ function Fb(e) {
17241
17268
  }
17242
17269
  return RegExp("^" + t + "$");
17243
17270
  }
17244
- function Ib() {
17271
+ function Rb() {
17245
17272
  return Date.now();
17246
17273
  }
17247
- var Lb = [
17274
+ var zb = [
17248
17275
  "vfs_read",
17249
17276
  "vfs_write",
17250
17277
  "vfs_edit",
@@ -17254,10 +17281,10 @@ var Lb = [
17254
17281
  "vfs_json_read",
17255
17282
  "vfs_json_patch"
17256
17283
  ];
17257
- function Rb(e) {
17284
+ function Bb(e) {
17258
17285
  return [
17259
17286
  r(async ({ path: t, offset: n, limit: r }) => {
17260
- let i = e.files[Pb(t)];
17287
+ let i = e.files[Ib(t)];
17261
17288
  if (!i) return $({
17262
17289
  code: "NOT_FOUND",
17263
17290
  path: t,
@@ -17286,9 +17313,9 @@ function Rb(e) {
17286
17313
  hint: "jsonString=true 要求 content 是合法 JSON;检查引号/逗号/括号配对;或省略 jsonString 写纯文本"
17287
17314
  });
17288
17315
  }
17289
- return e.files[Pb(t)] = {
17316
+ return e.files[Ib(t)] = {
17290
17317
  content: n,
17291
- updatedAt: Ib()
17318
+ updatedAt: Rb()
17292
17319
  }, `已写入 ${t}(${n.length} 字符)${r ? "(JSON 校验通过)" : ""}`;
17293
17320
  }, {
17294
17321
  name: "vfs_write",
@@ -17300,7 +17327,7 @@ function Rb(e) {
17300
17327
  })
17301
17328
  }),
17302
17329
  r(async ({ path: t, oldString: n, newString: r }) => {
17303
- let i = Pb(t), a = e.files[i];
17330
+ let i = Ib(t), a = e.files[i];
17304
17331
  if (!a) return $({
17305
17332
  code: "NOT_FOUND",
17306
17333
  path: t,
@@ -17330,7 +17357,7 @@ function Rb(e) {
17330
17357
  }
17331
17358
  return e.files[i] = {
17332
17359
  content: a.content.replace(n, r),
17333
- updatedAt: Ib()
17360
+ updatedAt: Rb()
17334
17361
  }, `已替换 ${t} 中 1 处。`;
17335
17362
  }, {
17336
17363
  name: "vfs_edit",
@@ -17352,7 +17379,7 @@ function Rb(e) {
17352
17379
  r(async ({ pattern: t }) => {
17353
17380
  let n;
17354
17381
  try {
17355
- n = Fb(t);
17382
+ n = Lb(t);
17356
17383
  } catch (e) {
17357
17384
  return $({
17358
17385
  code: "GLOB_INVALID",
@@ -17381,7 +17408,7 @@ function Rb(e) {
17381
17408
  details: { pattern: t }
17382
17409
  });
17383
17410
  }
17384
- let i = n ? [Pb(n)] : Object.keys(e.files), a = [];
17411
+ let i = n ? [Ib(n)] : Object.keys(e.files), a = [];
17385
17412
  for (let t of i) {
17386
17413
  let n = e.files[t];
17387
17414
  n && n.content.split("\n").forEach((e, n) => {
@@ -17398,7 +17425,7 @@ function Rb(e) {
17398
17425
  })
17399
17426
  }),
17400
17427
  r(async ({ path: t, jsonPath: n }) => {
17401
- let r = Pb(t), i = e.files[r];
17428
+ let r = Ib(t), i = e.files[r];
17402
17429
  if (!i) return $({
17403
17430
  code: "NOT_FOUND",
17404
17431
  path: t,
@@ -17417,7 +17444,7 @@ function Rb(e) {
17417
17444
  });
17418
17445
  }
17419
17446
  if (n) {
17420
- let e = fb(a, n);
17447
+ let e = mb(a, n);
17421
17448
  return e === void 0 ? $({
17422
17449
  code: "VFS_PATH_NOT_FOUND",
17423
17450
  path: t,
@@ -17435,7 +17462,7 @@ function Rb(e) {
17435
17462
  })
17436
17463
  }),
17437
17464
  r(async ({ path: t, patches: n }) => {
17438
- let r = Pb(t), i = e.files[r];
17465
+ let r = Ib(t), i = e.files[r];
17439
17466
  if (!i) return $({
17440
17467
  code: "NOT_FOUND",
17441
17468
  path: t,
@@ -17453,9 +17480,9 @@ function Rb(e) {
17453
17480
  hint: "vfs_json_patch 要求文件内容是合法 JSON"
17454
17481
  });
17455
17482
  }
17456
- let o = hb(a), s = [];
17483
+ let o = _b(a), s = [];
17457
17484
  for (let e of n) {
17458
- let n = Sb(o, e.op, e.jsonPath, e.value);
17485
+ let n = wb(o, e.op, e.jsonPath, e.value);
17459
17486
  if (n) return $({
17460
17487
  code: "PATCH_FAILED",
17461
17488
  path: t,
@@ -17468,7 +17495,7 @@ function Rb(e) {
17468
17495
  let c = JSON.stringify(o);
17469
17496
  return e.files[r] = {
17470
17497
  content: c,
17471
- updatedAt: Ib()
17498
+ updatedAt: Rb()
17472
17499
  }, `已对 ${t} 应用 ${n.length} 个 patch(影响 ${s.length} 处:${s.join(", ")}),文件现 ${c.length} 字符`;
17473
17500
  }, {
17474
17501
  name: "vfs_json_patch",
@@ -17489,17 +17516,17 @@ function Rb(e) {
17489
17516
  })
17490
17517
  ];
17491
17518
  }
17492
- function zb(e) {
17519
+ function Vb(e) {
17493
17520
  return {
17494
17521
  name: "vfs",
17495
- tools: Rb(e),
17522
+ tools: Bb(e),
17496
17523
  beforeAgent: () => ({ files: e.files })
17497
17524
  };
17498
17525
  }
17499
17526
  //#endregion
17500
17527
  //#region src/core/tools/dataSlotQuery.ts
17501
- var Bb = /[\w$-]/;
17502
- function Vb(e) {
17528
+ var Hb = /[\w$-]/;
17529
+ function Ub(e) {
17503
17530
  let t = [], n = e.trim(), r = +(n[0] === "$");
17504
17531
  for (; r < n.length;) {
17505
17532
  let e = n[r];
@@ -17510,7 +17537,7 @@ function Vb(e) {
17510
17537
  continue;
17511
17538
  }
17512
17539
  let e = "";
17513
- for (; r < n.length && Bb.test(n[r]);) e += n[r++];
17540
+ for (; r < n.length && Hb.test(n[r]);) e += n[r++];
17514
17541
  if (!e) throw Error("JSONPath: .. 后缺属性名");
17515
17542
  t.push({
17516
17543
  type: "descendKey",
@@ -17523,7 +17550,7 @@ function Vb(e) {
17523
17550
  continue;
17524
17551
  }
17525
17552
  let e = "";
17526
- for (; r < n.length && Bb.test(n[r]);) e += n[r++];
17553
+ for (; r < n.length && Hb.test(n[r]);) e += n[r++];
17527
17554
  if (!e) throw Error("JSONPath: . 后缺属性名");
17528
17555
  t.push({
17529
17556
  type: "key",
@@ -17579,7 +17606,7 @@ function Vb(e) {
17579
17606
  }
17580
17607
  return t;
17581
17608
  }
17582
- function Hb(e) {
17609
+ function Wb(e) {
17583
17610
  let t = [], n = 0, r = e.trim();
17584
17611
  for (; n < r.length;) {
17585
17612
  let e = r[n];
@@ -17624,7 +17651,7 @@ function Hb(e) {
17624
17651
  }
17625
17652
  return t;
17626
17653
  }
17627
- var Ub = class {
17654
+ var Gb = class {
17628
17655
  toks;
17629
17656
  item;
17630
17657
  pos = 0;
@@ -17660,12 +17687,12 @@ var Ub = class {
17660
17687
  return this.next(), e;
17661
17688
  }
17662
17689
  let e = this.operand(), t = this.peek();
17663
- return t === "==" || t === "!=" || t === "<" || t === "<=" || t === ">" || t === ">=" ? (this.next(), Kb(t, e, this.operand())) : Wb(e);
17690
+ return t === "==" || t === "!=" || t === "<" || t === "<=" || t === ">" || t === ">=" ? (this.next(), Jb(t, e, this.operand())) : Kb(e);
17664
17691
  }
17665
17692
  operand() {
17666
17693
  let e = this.next();
17667
17694
  if (e === void 0) throw Error("过滤表达式:缺操作数");
17668
- if (e.startsWith("@")) return Gb(e, this.item);
17695
+ if (e.startsWith("@")) return qb(e, this.item);
17669
17696
  if (e[0] === "'" || e[0] === "\"") return e.slice(1, -1);
17670
17697
  if (e === "true") return !0;
17671
17698
  if (e === "false") return !1;
@@ -17675,10 +17702,10 @@ var Ub = class {
17675
17702
  throw Error(`过滤表达式:未知操作数 '${e}'`);
17676
17703
  }
17677
17704
  };
17678
- function Wb(e) {
17705
+ function Kb(e) {
17679
17706
  return !!e && e !== 0 && e !== "" && e !== null;
17680
17707
  }
17681
- function Gb(e, t) {
17708
+ function qb(e, t) {
17682
17709
  let n = e.split(".").filter((e) => e && e !== "@"), r = t;
17683
17710
  for (let e of n) {
17684
17711
  if (typeof r != "object" || !r) return;
@@ -17686,7 +17713,7 @@ function Gb(e, t) {
17686
17713
  }
17687
17714
  return r;
17688
17715
  }
17689
- function Kb(e, t, n) {
17716
+ function Jb(e, t, n) {
17690
17717
  switch (e) {
17691
17718
  case "==": return t === n;
17692
17719
  case "!=": return t !== n;
@@ -17697,47 +17724,47 @@ function Kb(e, t, n) {
17697
17724
  default: return !1;
17698
17725
  }
17699
17726
  }
17700
- function qb(e, t) {
17701
- return new Ub(Hb(e), t).parse();
17727
+ function Yb(e, t) {
17728
+ return new Gb(Wb(e), t).parse();
17702
17729
  }
17703
- function Jb(e, t) {
17730
+ function Xb(e, t) {
17704
17731
  return e ? `${e}.${t}` : String(t);
17705
17732
  }
17706
- function Yb(e, t) {
17733
+ function Zb(e, t) {
17707
17734
  let n = [{
17708
17735
  path: "",
17709
17736
  value: e
17710
17737
  }];
17711
- for (let e of Vb(t)) {
17738
+ for (let e of Ub(t)) {
17712
17739
  let t = [];
17713
17740
  if (e.type === "key") for (let r of n) r.value != null && typeof r.value == "object" && e.key in r.value && t.push({
17714
- path: Jb(r.path, e.key),
17741
+ path: Xb(r.path, e.key),
17715
17742
  value: r.value[e.key]
17716
17743
  });
17717
17744
  else if (e.type === "index") {
17718
17745
  for (let r of n) if (Array.isArray(r.value)) {
17719
17746
  let n = r.value[e.index];
17720
17747
  e.index >= 0 && e.index < r.value.length && t.push({
17721
- path: Jb(r.path, e.index),
17748
+ path: Xb(r.path, e.index),
17722
17749
  value: n,
17723
17750
  index: e.index
17724
17751
  });
17725
17752
  }
17726
17753
  } else if (e.type === "wildcard") {
17727
17754
  for (let e of n) if (Array.isArray(e.value)) e.value.forEach((n, r) => t.push({
17728
- path: Jb(e.path, r),
17755
+ path: Xb(e.path, r),
17729
17756
  value: n,
17730
17757
  index: r
17731
17758
  }));
17732
17759
  else if (e.value != null && typeof e.value == "object") for (let n of Object.keys(e.value)) t.push({
17733
- path: Jb(e.path, n),
17760
+ path: Xb(e.path, n),
17734
17761
  value: e.value[n]
17735
17762
  });
17736
17763
  } else if (e.type === "descendKey") {
17737
17764
  let r = e.key, i = (e) => {
17738
17765
  if (e.value != null && typeof e.value == "object") for (let n of Object.keys(e.value)) {
17739
17766
  let a = {
17740
- path: Jb(e.path, n),
17767
+ path: Xb(e.path, n),
17741
17768
  value: e.value[n]
17742
17769
  };
17743
17770
  n === r && t.push(a), i(a);
@@ -17748,7 +17775,7 @@ function Yb(e, t) {
17748
17775
  let e = (n) => {
17749
17776
  if (n.value != null && typeof n.value == "object") for (let r of Object.keys(n.value)) {
17750
17777
  let i = {
17751
- path: Jb(n.path, r),
17778
+ path: Xb(n.path, r),
17752
17779
  value: n.value[r]
17753
17780
  };
17754
17781
  t.push(i), e(i);
@@ -17757,16 +17784,16 @@ function Yb(e, t) {
17757
17784
  for (let t of n) e(t);
17758
17785
  } else if (e.type === "filter") {
17759
17786
  for (let r of n) if (Array.isArray(r.value)) r.value.forEach((n, i) => {
17760
- qb(e.filter, n) && t.push({
17761
- path: Jb(r.path, i),
17787
+ Yb(e.filter, n) && t.push({
17788
+ path: Xb(r.path, i),
17762
17789
  value: n,
17763
17790
  index: i
17764
17791
  });
17765
17792
  });
17766
17793
  else if (r.value != null && typeof r.value == "object") for (let n of Object.keys(r.value)) {
17767
17794
  let i = r.value[n];
17768
- qb(e.filter, i) && t.push({
17769
- path: Jb(r.path, n),
17795
+ Yb(e.filter, i) && t.push({
17796
+ path: Xb(r.path, n),
17770
17797
  value: i
17771
17798
  });
17772
17799
  }
@@ -17775,7 +17802,7 @@ function Yb(e, t) {
17775
17802
  }
17776
17803
  return n;
17777
17804
  }
17778
- function Xb(e, t) {
17805
+ function Qb(e, t) {
17779
17806
  let n = e.length, r = t.length;
17780
17807
  if (!n) return r;
17781
17808
  if (!r) return n;
@@ -17791,7 +17818,7 @@ function Xb(e, t) {
17791
17818
  }
17792
17819
  return i[r];
17793
17820
  }
17794
- function Zb(e, t, n = {}) {
17821
+ function $b(e, t, n = {}) {
17795
17822
  let r = n.mode || "substring", i = n.limit ?? 50, a = n.matchKey !== !1, o = [], s = null;
17796
17823
  if (r === "regex") try {
17797
17824
  s = new RegExp(t, "i");
@@ -17801,11 +17828,11 @@ function Zb(e, t, n = {}) {
17801
17828
  let c = (e, l, u) => {
17802
17829
  if (o.length >= i || e == null) return;
17803
17830
  if (typeof e == "object") {
17804
- if (Array.isArray(e)) e.forEach((e, t) => c(e, Jb(l, t), String(t)));
17805
- else for (let t of Object.keys(e)) c(e[t], Jb(l, t), t);
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);
17806
17833
  return;
17807
17834
  }
17808
- let d = String(e), f = Qb(d, t, r, n.fuzzyThreshold ?? 2, s);
17835
+ let d = String(e), f = ex(d, t, r, n.fuzzyThreshold ?? 2, s);
17809
17836
  if (f) {
17810
17837
  o.push({
17811
17838
  path: l,
@@ -17816,7 +17843,7 @@ function Zb(e, t, n = {}) {
17816
17843
  return;
17817
17844
  }
17818
17845
  if (a && u) {
17819
- let e = Qb(u, t, r, n.fuzzyThreshold ?? 2, s);
17846
+ let e = ex(u, t, r, n.fuzzyThreshold ?? 2, s);
17820
17847
  e && o.push({
17821
17848
  path: l,
17822
17849
  key: u,
@@ -17827,18 +17854,18 @@ function Zb(e, t, n = {}) {
17827
17854
  };
17828
17855
  return c(e, ""), o;
17829
17856
  }
17830
- function Qb(e, t, n, r, i) {
17857
+ function ex(e, t, n, r, i) {
17831
17858
  let a = e.toLowerCase(), o = t.toLowerCase();
17832
17859
  if (n === "substring") return a.includes(o) ? 1 : null;
17833
17860
  if (n === "regex") return i && i.test(e) ? 1 : null;
17834
17861
  if (n === "fuzzy") {
17835
17862
  if (a.includes(o)) return 2;
17836
- let e = Xb(a, o);
17863
+ let e = Qb(a, o);
17837
17864
  return e <= r ? r - e + 1 : null;
17838
17865
  }
17839
17866
  return null;
17840
17867
  }
17841
- var $b = [
17868
+ var tx = [
17842
17869
  "self.fetch = () => { throw new Error('fetch 已被沙箱禁用') }",
17843
17870
  "self.XMLHttpRequest = function(){ throw new Error('XMLHttpRequest 已被沙箱禁用') }",
17844
17871
  "self.importScripts = () => { throw new Error('importScripts 已被沙箱禁用') }",
@@ -17850,7 +17877,7 @@ var $b = [
17850
17877
  "try { self.EventSource = undefined } catch {}",
17851
17878
  "try { self.BroadcastChannel = undefined } catch {}",
17852
17879
  "if (self.navigator && self.navigator.sendBeacon) self.navigator.sendBeacon = () => { throw new Error('sendBeacon 已被沙箱禁用') }"
17853
- ].join("\n"), ex = [
17880
+ ].join("\n"), nx = [
17854
17881
  {
17855
17882
  re: /\bimport\s*\(/,
17856
17883
  msg: "动态 import() 拉外网模块"
@@ -17876,8 +17903,8 @@ var $b = [
17876
17903
  msg: "require() 拉模块"
17877
17904
  }
17878
17905
  ];
17879
- function tx(e, t, n = 3e3) {
17880
- for (let { re: e, msg: n } of ex) if (e.test(t)) return Promise.resolve({
17906
+ function rx(e, t, n = 3e3) {
17907
+ for (let { re: e, msg: n } of nx) if (e.test(t)) return Promise.resolve({
17881
17908
  ok: !1,
17882
17909
  error: `沙箱拒绝执行:脚本含禁用模式(${n})`,
17883
17910
  elapsedMs: 0
@@ -17894,7 +17921,7 @@ function tx(e, t, n = 3e3) {
17894
17921
  elapsedMs: Date.now() - i
17895
17922
  });
17896
17923
  }
17897
- }, s = $b + "\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;
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;
17898
17925
  try {
17899
17926
  let e = new Blob([s], { type: "application/javascript" });
17900
17927
  c = URL.createObjectURL(e), l = new Worker(c);
@@ -17929,7 +17956,7 @@ function tx(e, t, n = 3e3) {
17929
17956
  }
17930
17957
  //#endregion
17931
17958
  //#region src/core/tools/dataOps.ts
17932
- var nx = /* @__PURE__ */ new Set([
17959
+ var ix = /* @__PURE__ */ new Set([
17933
17960
  "describe_data",
17934
17961
  "get_data",
17935
17962
  "set_data",
@@ -17941,11 +17968,11 @@ var nx = /* @__PURE__ */ new Set([
17941
17968
  "diff_data",
17942
17969
  "draft_write",
17943
17970
  "draft_commit"
17944
- ]), rx = /* @__PURE__ */ new Set(["read", "write"]);
17945
- function ix(e, t = "simple") {
17946
- return t === "advanced" ? e : t === "minimal" ? e.filter((e) => rx.has(e.name)) : e.filter((e) => !nx.has(e.name));
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));
17947
17974
  }
17948
- function ax(e) {
17975
+ function sx(e) {
17949
17976
  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);
17950
17977
  if (!u.success) return {
17951
17978
  ok: !1,
@@ -17964,41 +17991,50 @@ function ax(e) {
17964
17991
  hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹(如 {value:\"x\"})或集成方通过 sdk.setData 替换 bind"
17965
17992
  })
17966
17993
  };
17967
- let d = hb(t), f = a.length ? a[a.length - 1].id + 1 : 1;
17994
+ let d = _b(t), f = a.length ? a[a.length - 1].id + 1 : 1;
17968
17995
  for (a.push({
17969
17996
  id: f,
17970
17997
  ts: Date.now(),
17971
17998
  op: l,
17972
17999
  value: d
17973
18000
  }); a.length > o;) a.shift();
17974
- return u.data !== null && typeof u.data == "object" && (i ? db(t, u.data) : Tb(t, u.data)), s({
18001
+ return u.data !== null && typeof u.data == "object" && (i ? pb(t, u.data) : Db(t, u.data)), s({
17975
18002
  op: l,
17976
18003
  value: u.data,
17977
18004
  timestamp: Date.now()
17978
- }), {
18005
+ }), e.onWrite?.(), {
17979
18006
  ok: !0,
17980
- hash: xb(t),
18007
+ hash: Cb(t),
17981
18008
  data: u.data
17982
18009
  };
17983
18010
  }
17984
- function ox(e, n = {}) {
17985
- let i = e.schema, a = e.bind, o = e.description ?? "主数据对象", s = ey(i), c = [], l = n.maxSnapshots ?? 20, u, d = n.autoLock !== !1, f = {
18011
+ function cx(e, n = {}) {
18012
+ 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
+ function p() {
18014
+ f = !0;
18015
+ }
18016
+ let m = {
17986
18017
  get: () => ({
17987
18018
  schema: i,
17988
18019
  bind: a,
17989
18020
  description: o
17990
18021
  }),
17991
18022
  set: (e) => {
17992
- i = e.schema, a = e.bind, o = e.description ?? "主数据对象", s = ey(i), c.length = 0, u = void 0;
18023
+ i = e.schema, a = e.bind, o = e.description ?? "主数据对象", s = ey(i), c.length = 0, u = void 0, p();
17993
18024
  },
17994
18025
  update: (e) => {
17995
- a = e, c.length = 0, u = void 0;
18026
+ a = e, c.length = 0, u = void 0, p();
18027
+ },
18028
+ markDataDirty: p,
18029
+ consumeDataDirty: () => {
18030
+ let e = f;
18031
+ return f = !1, e;
17996
18032
  }
17997
- }, p = (e) => {
18033
+ }, h = (e) => {
17998
18034
  n.onAudit?.(e);
17999
18035
  };
18000
- function m(e, t) {
18001
- let n = hb(a), r = c.length ? c[c.length - 1].id + 1 : 1;
18036
+ function g(e, t) {
18037
+ let n = _b(a), r = c.length ? c[c.length - 1].id + 1 : 1;
18002
18038
  for (c.push({
18003
18039
  id: r,
18004
18040
  ts: Date.now(),
@@ -18008,14 +18044,14 @@ function ox(e, n = {}) {
18008
18044
  }); c.length > l;) c.shift();
18009
18045
  return r;
18010
18046
  }
18011
- async function h(e, t, r) {
18047
+ async function _(e, t, r) {
18012
18048
  if (!t || t === "") return null;
18013
- let i = xb(a);
18049
+ let i = Cb(a);
18014
18050
  if (i === t) return null;
18015
18051
  if (!n.onConflict) return $({
18016
18052
  code: "VERSION_CONFLICT",
18017
18053
  message: `乐观锁冲突:expectedHash=${t} 但当前 hash=${i}。主数据在你 read 之后已被修改(外部代码/其他 agent/用户手动改)。`,
18018
- hint: `重新 read 拿最新值与 hash,基于最新值修改后再写入(传新的 expectedHash)。当前值:${yb(a, 400)}`
18054
+ hint: `重新 read 拿最新值与 hash,基于最新值修改后再写入(传新的 expectedHash)。当前值:${xb(a, 400)}`
18019
18055
  });
18020
18056
  let o = await n.onConflict({
18021
18057
  op: e,
@@ -18025,21 +18061,21 @@ function ox(e, n = {}) {
18025
18061
  expectedHash: t,
18026
18062
  snapshotId: 0
18027
18063
  });
18028
- if (o.action === "keep_external") return `已保留外部修改(未写入)。当前值:${yb(a, 400)} (hash=${i})。请重新 read 拿最新值与 hash 再改。`;
18064
+ if (o.action === "keep_external") return `已保留外部修改(未写入)。当前值:${xb(a, 400)} (hash=${i})。请重新 read 拿最新值与 hash 再改。`;
18029
18065
  if (o.action === "restore") {
18030
- if (!c.length) return `无历史快照可回退(本次为首次操作)。当前值:${yb(a, 400)} (hash=${i})。请重新 read 再改或选「强制覆盖」。`;
18066
+ if (!c.length) return `无历史快照可回退(本次为首次操作)。当前值:${xb(a, 400)} (hash=${i})。请重新 read 再改或选「强制覆盖」。`;
18031
18067
  let e = c[c.length - 1];
18032
- return wb(a, hb(e.value)), `已回退主数据到历史快照 #${e.id}[${e.op}]。当前值:${yb(a, 400)} (hash=${xb(a)})。请基于回退后的值重写或停止。`;
18068
+ return Eb(a, _b(e.value)), p(), `已回退主数据到历史快照 #${e.id}[${e.op}]。当前值:${xb(a, 400)} (hash=${Cb(a)})。请基于回退后的值重写或停止。`;
18033
18069
  }
18034
18070
  return null;
18035
18071
  }
18036
- let g = r(async () => [`说明: ${o}`, "格式: 写入值需为 JSON,且通过声明的 schema 校验(校验失败时 set_data/edit_data 会返回结构化错误,含具体字段与期望类型)。"].join("\n"), {
18072
+ let v = r(async () => [`说明: ${o}`, "格式: 写入值需为 JSON,且通过声明的 schema 校验(校验失败时 set_data/edit_data 会返回结构化错误,含具体字段与期望类型)。"].join("\n"), {
18037
18073
  name: "describe_data",
18038
18074
  description: "获取主数据的说明与格式要求。",
18039
18075
  schema: t.object({})
18040
- }), _ = r(async ({ jsonPath: e }) => {
18076
+ }), y = r(async ({ jsonPath: e }) => {
18041
18077
  let t = e || "";
18042
- if (ub(t)) return $({
18078
+ if (fb(t)) return $({
18043
18079
  code: "PATH_UNSAFE",
18044
18080
  message: `jsonPath "${t}" 含非法段(__proto__/constructor/prototype)`,
18045
18081
  hint: "使用正常属性路径,如 components.0.text(数组索引用数字)"
@@ -18049,29 +18085,30 @@ function ox(e, n = {}) {
18049
18085
  message: `get_data @ "${t}" 不在 schema 声明字段内(仅 schema 声明的 key 可读)`,
18050
18086
  hint: "主数据仅暴露 schema 声明的字段;若需操作该字段,集成方需在 schema 中声明它"
18051
18087
  });
18052
- let n = t ? fb(a, t) : a;
18088
+ let n = t ? mb(a, t) : a;
18053
18089
  t || (n = ay(n, s));
18054
- let r = xb(a);
18055
- return u = r, n === void 0 ? `主数据${t ? ` @ ${t}` : ""} = (undefined) (hash=${r})` : `主数据${t ? ` @ ${t}` : ""} = ${yb(n)} (hash=${r})`;
18090
+ let r = Cb(a);
18091
+ return u = r, n === void 0 ? `主数据${t ? ` @ ${t}` : ""} = (undefined) (hash=${r})` : `主数据${t ? ` @ ${t}` : ""} = ${xb(n)} (hash=${r})`;
18056
18092
  }, {
18057
18093
  name: "get_data",
18058
18094
  description: "读取主数据的当前值(安全序列化:函数/DOM/循环引用做摘要;大结果由系统自动外存,提示用 vfs_read 回读)。返回含 hash(乐观锁):改前先 read/get 拿 hash,写入时传 expectedHash 回传,系统对比当前 hash 防\"基于过期值覆盖\"。jsonPath 可选:读整个主数据不传,读子路径传(如 components.0.text)。",
18059
18095
  schema: t.object({ jsonPath: t.string().optional().describe("相对主数据根的点号路径(如 components.0.text);不传则读整个主数据") })
18060
- }), v = r(async ({ value: e, expectedHash: t }) => {
18061
- let n = await h("set", t || (d ? u : void 0));
18096
+ }), b = r(async ({ value: e, expectedHash: t }) => {
18097
+ let n = await _("set", t || (d ? u : void 0));
18062
18098
  if (n !== null) return n;
18063
- let r = gb(e);
18099
+ let r = vb(e);
18064
18100
  if (r.parseError) return Ug("", e, r.parseError);
18065
- let o = ax({
18101
+ let o = sx({
18066
18102
  bindRef: a,
18067
18103
  value: r.parsed,
18068
18104
  schema: i,
18069
18105
  allowKeys: s,
18070
18106
  snapshots: c,
18071
18107
  maxSnapshots: l,
18072
- audit: p
18108
+ audit: h,
18109
+ onWrite: p
18073
18110
  });
18074
- return o.ok ? (u = o.hash, `已设置主数据 = ${yb(o.data, 600)} (新 hash=${o.hash})${s ? "(白名单模式:仅更新 schema 声明字段,未声明字段保留)" : ""}`) : o.error;
18111
+ return o.ok ? (u = o.hash, `已设置主数据 = ${xb(o.data, 600)} (新 hash=${o.hash})${s ? "(白名单模式:仅更新 schema 声明字段,未声明字段保留)" : ""}`) : o.error;
18075
18112
  }, {
18076
18113
  name: "set_data",
18077
18114
  description: "设置主数据的值(整体替换)。value 为 JSON 对象(或 JSON 字符串),需通过 schema 校验。校验失败会返回错误而非写入。expectedHash(可选):改前 read/get 返回的 hash,传入则启用乐观锁;不传时系统自动用你最后一次读到的 hash 比对(autoLock,默认开)。大对象/数组强烈建议改用 edit_data 增量 patch。白名单模式(schema 为 ZodObject 子集):set 为根级浅合并,深层子对象整体替换(未传字段丢失);保留深层字段请用 edit_data({op:\"merge\", jsonPath:\"子路径\", value:{...}})局部合并。",
@@ -18079,7 +18116,7 @@ function ox(e, n = {}) {
18079
18116
  value: t.unknown().describe("JSON 对象(推荐直传,如 {title:\"x\"}),或 JSON 字符串;需符合 schema"),
18080
18117
  expectedHash: t.string().optional().describe("乐观锁:改前 read/get 返回的 hash;传入则校验,不一致拒绝写入防覆盖。不传则自动用你最后读到的 hash(autoLock)")
18081
18118
  })
18082
- }), y = r(async (e) => {
18119
+ }), x = r(async (e) => {
18083
18120
  let t = e.op ?? e.patch?.op, n = e.jsonPath ?? e.patch?.jsonPath, r = e.value ?? e.patch?.value, o = e.expectedHash;
18084
18121
  if (!t) return $({
18085
18122
  code: "MISSING_VALUE",
@@ -18087,7 +18124,7 @@ function ox(e, n = {}) {
18087
18124
  hint: "顶层 op 或 patch.op 至少传一个"
18088
18125
  });
18089
18126
  let c = n || "";
18090
- if (ub(c)) return $({
18127
+ if (fb(c)) return $({
18091
18128
  code: "PATH_UNSAFE",
18092
18129
  message: `jsonPath "${c}" 含非法段(__proto__/constructor/prototype)`,
18093
18130
  hint: "使用正常的属性路径,如 components.0.text(数组索引用数字)"
@@ -18097,7 +18134,7 @@ function ox(e, n = {}) {
18097
18134
  message: `edit_data @ "${c}" 不在 schema 声明字段内`,
18098
18135
  hint: "仅 schema 声明的 key 可写;若需操作该字段,集成方需在 schema 中声明它"
18099
18136
  });
18100
- let l = await h("edit", o || (d ? u : void 0));
18137
+ let l = await _("edit", o || (d ? u : void 0));
18101
18138
  if (l !== null) return l;
18102
18139
  if (typeof a != "object" || !a) return $({
18103
18140
  code: "NOT_OBJECT",
@@ -18111,23 +18148,23 @@ function ox(e, n = {}) {
18111
18148
  message: `${t} 操作需要 value`,
18112
18149
  hint: `op 为 ${t} 时 value 必填;删除请用 op:'remove'`
18113
18150
  });
18114
- let e = gb(r);
18151
+ let e = vb(r);
18115
18152
  if (e.parseError) return Ug("", r, e.parseError);
18116
18153
  f = e.parsed;
18117
18154
  }
18118
- let g = hb(a), _ = Sb(g, t, c, f);
18119
- if (_) return $({
18155
+ let m = _b(a), v = wb(m, t, c, f);
18156
+ if (v) return $({
18120
18157
  code: "PATCH_FAILED",
18121
- message: _,
18158
+ message: v,
18122
18159
  hint: "检查 op 与目标类型:merge 需对象,append 需数组;jsonPath 指向需存在"
18123
18160
  });
18124
- let v = i.safeParse(g);
18125
- return v.success ? (m("edit"), Cb(a, t, c, f), p({
18161
+ let y = i.safeParse(m);
18162
+ return y.success ? (g("edit"), Tb(a, t, c, f), p(), h({
18126
18163
  op: "edit",
18127
18164
  detail: `${t}${c ? "@" + c : ""}`,
18128
18165
  value: f,
18129
18166
  timestamp: Date.now()
18130
- }), u = xb(a), `已 edit 主数据(${t}${c ? " @ " + c : ""})。当前值:${yb(a, 600)} (新 hash=${xb(a)})`) : Hg("", v.error.issues);
18167
+ }), u = Cb(a), `已 edit 主数据(${t}${c ? " @ " + c : ""})。当前值:${xb(a, 600)} (新 hash=${Cb(a)})`) : Hg("", y.error.issues);
18131
18168
  }, {
18132
18169
  name: "edit_data",
18133
18170
  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,默认开)防\"基于过期值覆盖\"。",
@@ -18152,13 +18189,13 @@ function ox(e, n = {}) {
18152
18189
  value: t.unknown().optional()
18153
18190
  }).optional().describe("容错:误传 write 的 {patch:{op,jsonPath,value}} 形式时从此取值(顶层优先)。正常用顶层 op/jsonPath/value 即可")
18154
18191
  })
18155
- }), b = r(async ({ jsonPath: e, expectedHash: t }) => {
18192
+ }), S = r(async ({ jsonPath: e, expectedHash: t }) => {
18156
18193
  if (!e) return $({
18157
18194
  code: "MISSING_VALUE",
18158
18195
  message: "delete_data 需要 jsonPath 指定要删的子路径(主数据整体不可删,用 set_data 整体替换)",
18159
18196
  hint: "如 jsonPath:\"components.0\" 删数组首项"
18160
18197
  });
18161
- if (ub(e)) return $({
18198
+ if (fb(e)) return $({
18162
18199
  code: "PATH_UNSAFE",
18163
18200
  message: `jsonPath "${e}" 含非法段`,
18164
18201
  hint: "使用正常属性路径"
@@ -18168,15 +18205,15 @@ function ox(e, n = {}) {
18168
18205
  message: `delete_data @ "${e}" 不在 schema 声明字段内`,
18169
18206
  hint: "仅 schema 声明的 key 可删"
18170
18207
  });
18171
- let n = await h("delete", t || (d ? u : void 0));
18208
+ let n = await _("delete", t || (d ? u : void 0));
18172
18209
  if (n !== null) return n;
18173
- m("delete");
18174
- let r = mb(a, e);
18175
- return p({
18210
+ g("delete");
18211
+ let r = gb(a, e);
18212
+ return p(), h({
18176
18213
  op: "delete",
18177
18214
  detail: e,
18178
18215
  timestamp: Date.now()
18179
- }), u = xb(a), r ? `已删除主数据 @ ${e}` : `主数据 @ ${e} 不存在(无需删除)`;
18216
+ }), u = Cb(a), r ? `已删除主数据 @ ${e}` : `主数据 @ ${e} 不存在(无需删除)`;
18180
18217
  }, {
18181
18218
  name: "delete_data",
18182
18219
  description: "删除主数据的某个子路径(jsonPath)。主数据整体不可删(用 set_data 整体替换)。expectedHash(可选):改前 read/get 返回的 hash;不传时自动用你最后读到的 hash(autoLock,默认开)防\"基于过期值删除\"。",
@@ -18184,11 +18221,11 @@ function ox(e, n = {}) {
18184
18221
  jsonPath: t.string().describe("要删除的子路径(相对主数据根,如 components.0)"),
18185
18222
  expectedHash: t.string().optional().describe("乐观锁:改前 read/get 返回的 hash;传入则校验,不一致拒绝删除防覆盖")
18186
18223
  })
18187
- }), x = r(async ({ label: e }) => `已为主数据创建快照 #${m("manual", e)}${e ? `(${e})` : ""}。可用 list_data_snapshots 查看、restore_data 回退。`, {
18224
+ }), C = r(async ({ label: e }) => `已为主数据创建快照 #${g("manual", e)}${e ? `(${e})` : ""}。可用 list_data_snapshots 查看、restore_data 回退。`, {
18188
18225
  name: "snapshot_data",
18189
18226
  description: "为主数据手动创建一个命名快照(检查点)。set/edit/delete 也会自动存快照。",
18190
18227
  schema: t.object({ label: t.string().optional().describe("可选的快照标签,便于识别") })
18191
- }), S = r(async () => {
18228
+ }), w = r(async () => {
18192
18229
  if (!c.length) return "无快照。set/edit/delete 会自动存快照,也可用 snapshot_data 手动创建检查点。";
18193
18230
  let e = c.map((e) => {
18194
18231
  let t = JSON.stringify(e.value ?? "").length, n = new Date(e.ts).toLocaleTimeString("zh-CN", { hour12: !1 });
@@ -18199,7 +18236,7 @@ function ox(e, n = {}) {
18199
18236
  name: "list_data_snapshots",
18200
18237
  description: "列出主数据的快照时间线(序号、操作类型、标签、大小)。",
18201
18238
  schema: t.object({})
18202
- }), C = r(async ({ id: e }) => {
18239
+ }), T = r(async ({ id: e }) => {
18203
18240
  if (!c.length) return $({
18204
18241
  code: "NO_SNAPSHOT",
18205
18242
  message: "无快照可回退",
@@ -18212,11 +18249,11 @@ function ox(e, n = {}) {
18212
18249
  hint: "用 list_data_snapshots 查看可用快照序号"
18213
18250
  });
18214
18251
  let n = i.safeParse(t.value);
18215
- return n.success ? (wb(a, hb(t.value)), p({
18252
+ return n.success ? (Eb(a, _b(t.value)), p(), h({
18216
18253
  op: "restore",
18217
18254
  detail: `#${t.id}`,
18218
18255
  timestamp: Date.now()
18219
- }), u = xb(a), `已回退主数据到快照 #${t.id}[${t.op}]${t.label ? `(${t.label})` : ""}。`) : $({
18256
+ }), u = Cb(a), `已回退主数据到快照 #${t.id}[${t.op}]${t.label ? `(${t.label})` : ""}。`) : $({
18220
18257
  code: "SNAPSHOT_SCHEMA_INVALID",
18221
18258
  message: `快照 #${t.id} 的值不符合当前 schema,无法回退`,
18222
18259
  hint: "schema 可能已变更;该快照已过期,选其他快照或重新设置",
@@ -18226,7 +18263,7 @@ function ox(e, n = {}) {
18226
18263
  name: "restore_data",
18227
18264
  description: "把主数据回退到某个快照(就地还原,保留响应式)。不传 id 则回退最近一次(快速回退)。可用 list_data_snapshots 查看快照列表。",
18228
18265
  schema: t.object({ id: t.number().int().optional().describe("指定快照序号;不传则回退最近一次") })
18229
- }), w = r(async ({ id: e, jsonPath: t }) => {
18266
+ }), E = r(async ({ id: e, jsonPath: t }) => {
18230
18267
  if (!c.length) return $({
18231
18268
  code: "NO_SNAPSHOT",
18232
18269
  message: "无历史快照可查看",
@@ -18238,9 +18275,9 @@ function ox(e, n = {}) {
18238
18275
  message: `未找到快照 #${e}`,
18239
18276
  hint: "不传 id 查看最近一次;或用 list_data_snapshots(advanced) 查看可用序号"
18240
18277
  });
18241
- let r = hb(n.value), a = t || "";
18278
+ let r = _b(n.value), a = t || "";
18242
18279
  if (a) {
18243
- if (ub(a)) return $({
18280
+ if (fb(a)) return $({
18244
18281
  code: "PATH_UNSAFE",
18245
18282
  message: `jsonPath "${a}" 含非法段`,
18246
18283
  hint: "使用正常属性路径"
@@ -18250,11 +18287,11 @@ function ox(e, n = {}) {
18250
18287
  message: `history_data @ "${a}" 不在 schema 声明字段内`,
18251
18288
  hint: "仅 schema 声明的 key 可读"
18252
18289
  });
18253
- r = fb(r, a);
18290
+ r = mb(r, a);
18254
18291
  let e = ry(i, a);
18255
18292
  e && (r = iy(r, e));
18256
18293
  } else s && (r = iy(r, i));
18257
- return `快照 #${n.id}[${n.op}]${n.label ? `(${n.label})` : ""}${a ? ` @ ${a}` : ""} = ${yb(r)}`;
18294
+ return `快照 #${n.id}[${n.op}]${n.label ? `(${n.label})` : ""}${a ? ` @ ${a}` : ""} = ${xb(r)}`;
18258
18295
  }, {
18259
18296
  name: "history_data",
18260
18297
  description: "只读查看某次快照(默认最近一次)的内容,不回退当前主数据。看上一版长啥样而不影响当前(冲突诊断/verify 自纠/用户问\"刚才改了啥\")。可选 id 指定快照序号、jsonPath 只看子路径(按 schema 投影)。",
@@ -18262,7 +18299,7 @@ function ox(e, n = {}) {
18262
18299
  id: t.number().int().optional().describe("快照序号;不传则最近一次"),
18263
18300
  jsonPath: t.string().optional().describe("只看快照的某子路径(相对主数据根);不传则整个快照")
18264
18301
  })
18265
- }), T = r(async ({ expr: e, limit: t }) => {
18302
+ }), D = r(async ({ expr: e, limit: t }) => {
18266
18303
  if (typeof a != "object" || !a) return $({
18267
18304
  code: "NOT_OBJECT",
18268
18305
  message: `主数据不是对象/数组,无法查询(当前为 ${a === void 0 ? "undefined" : typeof a})`,
@@ -18270,7 +18307,7 @@ function ox(e, n = {}) {
18270
18307
  });
18271
18308
  let n = s ? ay(a, s) : a, r;
18272
18309
  try {
18273
- r = Yb(n, e);
18310
+ r = Zb(n, e);
18274
18311
  } catch (t) {
18275
18312
  return $({
18276
18313
  code: "JSONPATH_SYNTAX",
@@ -18279,7 +18316,7 @@ function ox(e, n = {}) {
18279
18316
  details: { expr: e }
18280
18317
  });
18281
18318
  }
18282
- 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":${yb(e.value)}}`);
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)}}`);
18283
18320
  return `{"matched":${r.length},"returned":${o.length},"truncated":${r.length > i},"results":[${c.join(",")}]}`;
18284
18321
  }, {
18285
18322
  name: "query_data",
@@ -18288,19 +18325,19 @@ function ox(e, n = {}) {
18288
18325
  expr: t.string().describe("JSONPath 表达式,如 $.components[?(@.type==\"card\" && @.price<100)] 或 $..title(递归找所有 title)"),
18289
18326
  limit: t.number().int().min(1).max(200).optional().describe("返回结果上限,默认 50")
18290
18327
  })
18291
- }), E = r(async ({ query: e, mode: t, fuzzyThreshold: n, matchKey: r, limit: i }) => {
18328
+ }), O = r(async ({ query: e, mode: t, fuzzyThreshold: n, matchKey: r, limit: i }) => {
18292
18329
  if (a == null) return $({
18293
18330
  code: "EMPTY",
18294
18331
  message: "主数据为空,无可搜索内容"
18295
18332
  });
18296
18333
  try {
18297
- let o = Zb(s ? ay(a, s) : a, e, {
18334
+ let o = $b(s ? ay(a, s) : a, e, {
18298
18335
  mode: t,
18299
18336
  fuzzyThreshold: n,
18300
18337
  matchKey: r,
18301
18338
  limit: i ?? 50
18302
18339
  });
18303
- return yb({
18340
+ return xb({
18304
18341
  matched: o.length,
18305
18342
  results: o
18306
18343
  });
@@ -18326,7 +18363,7 @@ function ox(e, n = {}) {
18326
18363
  matchKey: t.boolean().optional().describe("是否同时匹配 key 名,默认 true"),
18327
18364
  limit: t.number().int().min(1).max(200).optional().describe("返回上限,默认 50")
18328
18365
  })
18329
- }), D = r(async ({ script: e, mode: t, jsonPath: n }) => {
18366
+ }), k = r(async ({ script: e, mode: t, jsonPath: n }) => {
18330
18367
  if (e.length > 8e3) return $({
18331
18368
  code: "SCRIPT_TOO_LARGE",
18332
18369
  message: `脚本过长(${e.length} 字符,上限 8000)`,
@@ -18339,12 +18376,12 @@ function ox(e, n = {}) {
18339
18376
  message: `eval_script @ "${r}" 不在 schema 声明字段内`,
18340
18377
  hint: "仅 schema 声明的 key 可作为子树"
18341
18378
  });
18342
- if (o = fb(a, r), s) {
18379
+ if (o = mb(a, r), s) {
18343
18380
  let e = ry(i, r);
18344
18381
  e && (o = iy(o, e));
18345
18382
  }
18346
18383
  } else o = s ? ay(a, s) : a;
18347
- let c = hb(o), l = await tx(c, e, r && JSON.stringify(c).length > 1e5 ? 8e3 : 3e3);
18384
+ let c = _b(o), l = await rx(c, e, r && JSON.stringify(c).length > 1e5 ? 8e3 : 3e3);
18348
18385
  if (!l.ok) {
18349
18386
  let t = /超时/.test(l.error || "");
18350
18387
  return $({
@@ -18360,18 +18397,18 @@ function ox(e, n = {}) {
18360
18397
  if (t === "transform") {
18361
18398
  let e = l.result;
18362
18399
  if (r) {
18363
- let t = hb(a), n = Sb(t, "set", r, e);
18400
+ let t = _b(a), n = wb(t, "set", r, e);
18364
18401
  if (n) return $({
18365
18402
  code: "PATCH_FAILED",
18366
18403
  message: `eval 子树 transform @ "${r}" 失败: ${n}`,
18367
18404
  hint: "检查子路径:set 需父为对象/数组"
18368
18405
  });
18369
18406
  let o = i.safeParse(t);
18370
- return o.success ? (m("edit", "eval_transform_subtree"), Cb(a, "set", r, e), p({
18407
+ return o.success ? (g("edit", "eval_transform_subtree"), Tb(a, "set", r, e), p(), h({
18371
18408
  op: "edit",
18372
18409
  detail: `eval_transform_subtree @ ${r}`,
18373
18410
  timestamp: Date.now()
18374
- }), u = xb(a), `已通过脚本 transform 子树 @ ${r} 更新(耗时 ${l.elapsedMs}ms)。当前值: ${yb(a, 600)}`) : $({
18411
+ }), u = Cb(a), `已通过脚本 transform 子树 @ ${r} 更新(耗时 ${l.elapsedMs}ms)。当前值: ${xb(a, 600)}`) : $({
18375
18412
  code: "SCHEMA_INVALID",
18376
18413
  message: `脚本返回值作为子树 @ "${r}" 后整体校验失败,未写入`,
18377
18414
  hint: `确认返回值符合 ${r} 处的子 schema`,
@@ -18384,10 +18421,10 @@ function ox(e, n = {}) {
18384
18421
  message: `主数据 bind 为原始类型(${a === null ? "null" : typeof a}),eval transform(patches) 无法就地替换`,
18385
18422
  hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹或集成方通过 sdk.setData 替换 bind"
18386
18423
  });
18387
- let t = e.patches, n = hb(a), r = [];
18424
+ let t = e.patches, n = _b(a), r = [];
18388
18425
  for (let e = 0; e < t.length; e++) {
18389
18426
  let a = t[e], o = a.jsonPath || "";
18390
- if (ub(o)) return $({
18427
+ if (fb(o)) return $({
18391
18428
  code: "PATH_UNSAFE",
18392
18429
  message: `patches[${e}] jsonPath "${o}" 含非法段`,
18393
18430
  hint: "使用正常属性路径"
@@ -18404,11 +18441,11 @@ function ox(e, n = {}) {
18404
18441
  message: `patches[${e}] ${c} 操作需要 value`,
18405
18442
  hint: `op 为 ${c} 时 value 必填`
18406
18443
  });
18407
- let t = gb(a.value);
18444
+ let t = vb(a.value);
18408
18445
  if (t.parseError) return Ug(`patches[${e}]`, a.value, t.parseError);
18409
18446
  l = t.parsed;
18410
18447
  }
18411
- let u = Sb(n, c, o, l);
18448
+ let u = wb(n, c, o, l);
18412
18449
  if (u) return $({
18413
18450
  code: "PATCH_FAILED",
18414
18451
  message: `patches[${e}]: ${u}`,
@@ -18427,31 +18464,31 @@ function ox(e, n = {}) {
18427
18464
  hint: "确认 patches 合并后整体仍符合 schema",
18428
18465
  details: Vg(o.error.issues)
18429
18466
  });
18430
- m("edit", "eval_transform");
18431
- for (let e of r) Cb(a, e.op, e.jp, e.value);
18432
- return p({
18467
+ g("edit", "eval_transform");
18468
+ for (let e of r) Tb(a, e.op, e.jp, e.value);
18469
+ return p(), h({
18433
18470
  op: "edit",
18434
18471
  detail: `eval_transform(${r.length} patches)`,
18435
18472
  timestamp: Date.now()
18436
- }), u = xb(a), `已通过脚本 transform(patches) 更新主数据(${r.length} 个 patch,耗时 ${l.elapsedMs}ms)。当前值: ${yb(a, 600)}`;
18473
+ }), u = Cb(a), `已通过脚本 transform(patches) 更新主数据(${r.length} 个 patch,耗时 ${l.elapsedMs}ms)。当前值: ${xb(a, 600)}`;
18437
18474
  }
18438
18475
  let t = i.safeParse(e);
18439
18476
  return t.success ? typeof a != "object" || !a ? $({
18440
18477
  code: "LEAF_BIND",
18441
18478
  message: `主数据 bind 为原始类型(${a === null ? "null" : typeof a}),eval transform 无法就地替换外部持有的值引用`,
18442
18479
  hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹或集成方通过 sdk.setData 替换 bind"
18443
- }) : (m("edit", "eval_transform"), t.data !== null && typeof t.data == "object" && (s ? db(a, t.data) : Tb(a, t.data)), p({
18480
+ }) : (g("edit", "eval_transform"), t.data !== null && typeof t.data == "object" && (s ? pb(a, t.data) : Db(a, t.data)), p(), h({
18444
18481
  op: "edit",
18445
18482
  detail: "eval_transform",
18446
18483
  timestamp: Date.now()
18447
- }), u = xb(a), `已通过脚本 transform 更新主数据(耗时 ${l.elapsedMs}ms)。当前值: ${yb(a, 600)}`) : $({
18484
+ }), u = Cb(a), `已通过脚本 transform 更新主数据(耗时 ${l.elapsedMs}ms)。当前值: ${xb(a, 600)}`) : $({
18448
18485
  code: "SCHEMA_INVALID",
18449
18486
  message: "脚本返回值校验失败,未写入(transform 模式要求返回主数据的完整新值且符合 schema)",
18450
18487
  hint: "确认脚本 return 了完整新值(非部分);或返回 {patches:[...]} 走增量模式;按 describe_data() 查看格式",
18451
18488
  details: Vg(t.error.issues)
18452
18489
  });
18453
18490
  }
18454
- return yb({
18491
+ return xb({
18455
18492
  ok: !0,
18456
18493
  result: l.result,
18457
18494
  elapsedMs: l.elapsedMs
@@ -18464,13 +18501,13 @@ function ox(e, n = {}) {
18464
18501
  mode: t.enum(["query", "transform"]).optional().describe("query=只读返回结果(默认),transform=校验后落地为新值"),
18465
18502
  jsonPath: t.string().optional().describe("子树模式:仅对 jsonPath 指向的子树执行(降低大 JSON 成本);transform 时返回值作为该子树新值")
18466
18503
  })
18467
- }), O = r(async ({ jsonPath: e, jsonPaths: t, fields: r, depth: c, offset: l, limit: d }) => {
18468
- let f = xb(a);
18504
+ }), A = r(async ({ jsonPath: e, jsonPaths: t, fields: r, depth: c, offset: l, limit: d }) => {
18505
+ let f = Cb(a);
18469
18506
  if (u = f, t && t.length) {
18470
18507
  let e = t.map((e) => {
18471
18508
  let t = e || "";
18472
18509
  if (!ty(t, i, s)) return `- ${t || "(根)"}: [PATH_DENIED: 不在 schema 声明字段内]`;
18473
- let o = t ? fb(a, t) : a;
18510
+ let o = t ? mb(a, t) : a;
18474
18511
  if (!t) o = ay(o, s);
18475
18512
  else if (s) {
18476
18513
  let e = ry(i, t);
@@ -18482,12 +18519,12 @@ function ox(e, n = {}) {
18482
18519
  } catch (e) {
18483
18520
  return `- ${t}: [READ_INTERCEPT: ${e.message}]`;
18484
18521
  }
18485
- return r && r.length && (l = _b(l, r)), c != null && (l = vb(l, c)), l === void 0 ? `- ${t} = (undefined)` : `- ${t} = ${yb(l)}`;
18522
+ return r && r.length && (l = yb(l, r)), c != null && (l = bb(l, c)), l === void 0 ? `- ${t} = (undefined)` : `- ${t} = ${xb(l)}`;
18486
18523
  });
18487
18524
  return `多路径读取(共 ${t.length} 项,hash=${f}):\n${e.join("\n")}`;
18488
18525
  }
18489
18526
  let p = e || "";
18490
- if (ub(p)) return $({
18527
+ if (fb(p)) return $({
18491
18528
  code: "PATH_UNSAFE",
18492
18529
  message: `jsonPath "${p}" 含非法段(__proto__/constructor/prototype)`,
18493
18530
  hint: "使用正常属性路径,如 components.0.text(数组索引数字)"
@@ -18497,7 +18534,7 @@ function ox(e, n = {}) {
18497
18534
  message: `read @ "${p}" 不在 schema 声明字段内`,
18498
18535
  hint: "主数据仅暴露 schema 声明的字段;若需操作该字段,集成方需在 schema 中声明它"
18499
18536
  });
18500
- let m = p ? fb(a, p) : a;
18537
+ let m = p ? mb(a, p) : a;
18501
18538
  if (!p) m = ay(m, s);
18502
18539
  else if (s) {
18503
18540
  let e = ry(i, p);
@@ -18512,13 +18549,13 @@ function ox(e, n = {}) {
18512
18549
  message: `read 拦截器抛错: ${e.message}`
18513
18550
  });
18514
18551
  }
18515
- r && r.length && (h = _b(h, r)), c != null && (h = vb(h, c));
18552
+ r && r.length && (h = yb(h, r)), c != null && (h = bb(h, c));
18516
18553
  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}` : "";
18517
18554
  if ((l !== void 0 || d !== void 0) && Array.isArray(h)) {
18518
18555
  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;
18519
- return `${g}主数据${p ? ` @ ${p}` : ""} 数组分页[offset=${t},limit=${n}]${y} = ${yb(r)} (total=${e}, hasMore=${i}) (hash=${f})`;
18556
+ return `${g}主数据${p ? ` @ ${p}` : ""} 数组分页[offset=${t},limit=${n}]${y} = ${xb(r)} (total=${e}, hasMore=${i}) (hash=${f})`;
18520
18557
  }
18521
- return h === void 0 ? `${g}主数据${p ? ` @ ${p}` : ""}${y} = (undefined) (hash=${f})` : `${g}主数据${p ? ` @ ${p}` : ""}${y} = ${yb(h)} (hash=${f})`;
18558
+ return h === void 0 ? `${g}主数据${p ? ` @ ${p}` : ""}${y} = (undefined) (hash=${f})` : `${g}主数据${p ? ` @ ${p}` : ""}${y} = ${xb(h)} (hash=${f})`;
18522
18559
  }, {
18523
18560
  name: "read",
18524
18561
  description: "读取主数据(高层入口,合并 describe/get)。不传 jsonPath → 返回主数据说明 + 格式提示(含字段约束);传 jsonPath → 返回该子路径当前值 + hash;传 jsonPaths → 一次读多个不相关子路径(省多轮往返)。hash 用于乐观锁(默认 autoLock,write 时自动比对,无需手动传)。fields(字段裁剪)/depth(深度截断)减体积;offset+limit 对数组目标分页(返回切片 + total/hasMore)。集成方可能经 read 拦截器对返回值脱敏/派生。",
@@ -18530,51 +18567,51 @@ function ox(e, n = {}) {
18530
18567
  offset: t.number().int().min(0).optional().describe("数组分页起始偏移(仅当读取目标是数组时生效,默认 0),配合 limit 分页读大数组"),
18531
18568
  limit: t.number().int().min(1).max(200).optional().describe("数组分页每页条数(默认 50,上限 200;仅数组时生效),返回切片 + total/hasMore")
18532
18569
  })
18533
- }), k = r(async ({ value: e, patch: t, patches: r, del: o, dryRun: f }) => {
18534
- let g = "set";
18535
- o ? g = "delete" : (r && r.length || t) && (g = "edit");
18536
- let _ = t?.value === void 0 ? e : t.value, v;
18570
+ }), j = r(async ({ value: e, patch: t, patches: r, del: o, dryRun: f }) => {
18571
+ let m = "set";
18572
+ o ? m = "delete" : (r && r.length || t) && (m = "edit");
18573
+ let v = t?.value === void 0 ? e : t.value, y;
18537
18574
  if (n.interceptors?.write) try {
18538
- let i = g === "delete" ? {
18575
+ let i = m === "delete" ? {
18539
18576
  del: !0,
18540
18577
  jsonPath: t?.jsonPath
18541
- } : g === "edit" && r && r.length ? { patches: r } : g === "edit" ? {
18578
+ } : m === "edit" && r && r.length ? { patches: r } : m === "edit" ? {
18542
18579
  op: t.op ?? "set",
18543
18580
  jsonPath: t.jsonPath || "",
18544
- value: _
18581
+ value: v
18545
18582
  } : e, o = n.interceptors.write(i, a);
18546
18583
  if (o && typeof o == "object" && "error" in o) return $({
18547
18584
  code: "WRITE_INTERCEPT",
18548
18585
  message: `write 拦截器拒绝: ${o.error}`
18549
18586
  });
18550
- if (g !== "delete") if (g === "edit" && r && r.length) v = o && Array.isArray(o) ? o : r;
18551
- else if (g === "edit") if (o && typeof o == "object" && "op" in o && "jsonPath" in o) {
18587
+ if (m !== "delete") if (m === "edit" && r && r.length) y = o && Array.isArray(o) ? o : r;
18588
+ else if (m === "edit") if (o && typeof o == "object" && "op" in o && "jsonPath" in o) {
18552
18589
  let e = o;
18553
- e.op && (t.op = e.op), e.jsonPath !== void 0 && (t.jsonPath = e.jsonPath), _ = e.value;
18554
- } else _ = o;
18555
- else _ = o;
18590
+ e.op && (t.op = e.op), e.jsonPath !== void 0 && (t.jsonPath = e.jsonPath), v = e.value;
18591
+ } else v = o;
18592
+ else v = o;
18556
18593
  } catch (e) {
18557
18594
  return $({
18558
18595
  code: "WRITE_INTERCEPT",
18559
18596
  message: `write 拦截器抛错: ${e.message}`
18560
18597
  });
18561
18598
  }
18562
- let y = d ? u : void 0;
18563
- if (f && y !== void 0) {
18564
- let e = xb(a);
18565
- if (e !== y) return $({
18599
+ let b = d ? u : void 0;
18600
+ if (f && b !== void 0) {
18601
+ let e = Cb(a);
18602
+ if (e !== b) return $({
18566
18603
  code: "VERSION_CONFLICT",
18567
- message: `dryRun 预检发现乐观锁冲突: expectedHash=${y} 当前 hash=${e}(主数据在你 read 后被改)`,
18604
+ message: `dryRun 预检发现乐观锁冲突: expectedHash=${b} 当前 hash=${e}(主数据在你 read 后被改)`,
18568
18605
  hint: "重新 read 拿最新 hash 再预检/写"
18569
18606
  });
18570
18607
  }
18571
- if (g === "delete") {
18608
+ if (m === "delete") {
18572
18609
  if (!t?.jsonPath) return $({
18573
18610
  code: "MISSING_VALUE",
18574
18611
  message: "delete 需要 patch.jsonPath 指定要删的子路径(主数据整体不可删,用 write(value) 整体替换)",
18575
18612
  hint: "如 patch:{jsonPath:\"components.0\"}, del:true"
18576
18613
  });
18577
- if (ub(t.jsonPath)) return $({
18614
+ if (fb(t.jsonPath)) return $({
18578
18615
  code: "PATH_UNSAFE",
18579
18616
  message: `jsonPath "${t.jsonPath}" 含非法段`,
18580
18617
  hint: "使用正常属性路径"
@@ -18584,36 +18621,36 @@ function ox(e, n = {}) {
18584
18621
  message: `write delete @ "${t.jsonPath}" 不在 schema 声明字段内`,
18585
18622
  hint: "仅 schema 声明的 key 可删"
18586
18623
  });
18587
- let e = await h("delete", y);
18624
+ let e = await _("delete", b);
18588
18625
  if (e !== null) return e;
18589
18626
  if (f) {
18590
- let e = hb(a);
18591
- return mb(e, t.jsonPath) ? `dryRun(delete): 将删除 @ ${t.jsonPath}。预览剩余:${yb(e, 600)}。未实际写入、未入快照。` : `dryRun(delete): @ ${t.jsonPath} 不存在(无需删除)。未实际写入。`;
18627
+ let e = _b(a);
18628
+ return gb(e, t.jsonPath) ? `dryRun(delete): 将删除 @ ${t.jsonPath}。预览剩余:${xb(e, 600)}。未实际写入、未入快照。` : `dryRun(delete): @ ${t.jsonPath} 不存在(无需删除)。未实际写入。`;
18592
18629
  }
18593
- m("delete");
18594
- let n = mb(a, t.jsonPath);
18595
- return p({
18630
+ g("delete");
18631
+ let n = gb(a, t.jsonPath);
18632
+ return p(), h({
18596
18633
  op: "delete",
18597
18634
  detail: t.jsonPath,
18598
18635
  timestamp: Date.now()
18599
- }), u = xb(a), n ? `已删除主数据 @ ${t.jsonPath}` : `主数据 @ ${t.jsonPath} 不存在(无需删除)`;
18636
+ }), u = Cb(a), n ? `已删除主数据 @ ${t.jsonPath}` : `主数据 @ ${t.jsonPath} 不存在(无需删除)`;
18600
18637
  }
18601
- if (g === "edit") {
18638
+ if (m === "edit") {
18602
18639
  if (typeof a != "object" || !a) return $({
18603
18640
  code: "NOT_OBJECT",
18604
18641
  message: `edit 仅适用于对象/数组主数据,当前是 ${a === void 0 ? "undefined" : typeof a}`,
18605
18642
  hint: "叶子用 write(value) 整体设置"
18606
18643
  });
18607
- let e = await h("edit", y);
18644
+ let e = await _("edit", b);
18608
18645
  if (e !== null) return e;
18609
- let n = v || (r && r.length ? r : [{
18646
+ let n = y || (r && r.length ? r : [{
18610
18647
  op: t.op ?? "set",
18611
18648
  jsonPath: t.jsonPath || "",
18612
- value: _
18613
- }]), o = hb(a), c = [];
18649
+ value: v
18650
+ }]), o = _b(a), c = [];
18614
18651
  for (let e = 0; e < n.length; e++) {
18615
18652
  let t = n[e], r = t.jsonPath || "";
18616
- if (ub(r)) return $({
18653
+ if (fb(r)) return $({
18617
18654
  code: "PATH_UNSAFE",
18618
18655
  message: `patches[${e}] jsonPath "${r}" 含非法段`,
18619
18656
  hint: "使用正常属性路径,如 components.0.text"
@@ -18623,18 +18660,18 @@ function ox(e, n = {}) {
18623
18660
  message: `patches[${e}] @ "${r}" 不在 schema 声明字段内`,
18624
18661
  hint: "仅 schema 声明的 key 可写"
18625
18662
  });
18626
- let a = t.op, l;
18663
+ let a = t.op ?? "set", l;
18627
18664
  if (a !== "remove") {
18628
18665
  if (t.value === void 0 || t.value === "") return $({
18629
18666
  code: "MISSING_VALUE",
18630
18667
  message: `patches[${e}] ${a} 操作需要 value`,
18631
18668
  hint: `op 为 ${a} 时 value 必填;删除请用 op:'remove'`
18632
18669
  });
18633
- let n = gb(t.value);
18670
+ let n = vb(t.value);
18634
18671
  if (n.parseError) return Ug(`patches[${e}]`, t.value, n.parseError);
18635
18672
  l = n.parsed;
18636
18673
  }
18637
- let u = Sb(o, a, r, l);
18674
+ let u = wb(o, a, r, l);
18638
18675
  if (u) return $({
18639
18676
  code: "PATCH_FAILED",
18640
18677
  message: `patches[${e}]: ${u}`,
@@ -18648,31 +18685,32 @@ function ox(e, n = {}) {
18648
18685
  }
18649
18686
  let l = i.safeParse(o);
18650
18687
  if (!l.success) return Hg("", l.error.issues);
18651
- if (f) return `dryRun(edit): ${c.length} 个 patch 预检通过(schema 校验 OK)。预览结果:${yb(o, 600)}。未实际写入、未入快照。`;
18652
- m("edit");
18653
- for (let e of c) Cb(a, e.op, e.jp, e.value);
18654
- return p({
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({
18655
18692
  op: "edit",
18656
18693
  detail: `${c.length} 个 patch${c.length > 1 ? "(批量)" : ""}`,
18657
18694
  value: c.map((e) => `${e.op}@${e.jp}`),
18658
18695
  timestamp: Date.now()
18659
- }), u = xb(a), `已 write(edit) 主数据(${c.length} 个 patch)。当前值:${yb(a, 600)} (新 hash=${xb(a)})`;
18696
+ }), u = Cb(a), `已 write(edit) 主数据(${c.length} 个 patch)。当前值:${xb(a, 600)} (新 hash=${Cb(a)})`;
18660
18697
  }
18661
- let b = gb(_);
18662
- if (b.parseError) return Ug("", _, b.parseError);
18663
- let x = await h("set", y);
18664
- if (x !== null) return x;
18665
- let S = ax({
18698
+ let x = vb(v);
18699
+ if (x.parseError) return Ug("", v, x.parseError);
18700
+ let S = await _("set", b);
18701
+ if (S !== null) return S;
18702
+ let C = sx({
18666
18703
  bindRef: a,
18667
- value: b.parsed,
18704
+ value: x.parsed,
18668
18705
  schema: i,
18669
18706
  allowKeys: s,
18670
18707
  snapshots: c,
18671
18708
  maxSnapshots: l,
18672
- audit: p,
18673
- dryRun: f
18709
+ audit: h,
18710
+ dryRun: f,
18711
+ onWrite: p
18674
18712
  });
18675
- return S.ok ? f ? `dryRun(set): schema 校验通过。预览新值:${yb(S.data, 600)}。未实际写入、未入快照。` : (u = S.hash, `已 write(set) 主数据 = ${yb(S.data, 600)} (新 hash=${S.hash})${s ? "(白名单模式:仅更新 schema 声明字段,未声明字段保留)" : ""}`) : S.error;
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;
18676
18714
  }, {
18677
18715
  name: "write",
18678
18716
  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)。",
@@ -18701,9 +18739,9 @@ function ox(e, n = {}) {
18701
18739
  del: t.boolean().optional().describe("true 则删除 patch.jsonPath 指定的子路径(等价 delete_data)"),
18702
18740
  dryRun: t.boolean().optional().describe("预检模式:走完整校验链(schema + 白名单 + patch 应用到 clone)但不落盘、不入快照,返回预览。四意图(value/patch/patches/del)均支持;乐观锁冲突照常检测(返回 VERSION_CONFLICT 不挂起)")
18703
18741
  })
18704
- }), A = r(async ({ jsonPath: e }) => {
18742
+ }), M = r(async ({ jsonPath: e }) => {
18705
18743
  let t = e || "", n = t ? ry(i, t) : i;
18706
- return n ? `schema${t ? ` @ ${t}` : ""} = ${yb(dy(n))}` : $({
18744
+ return n ? `schema${t ? ` @ ${t}` : ""} = ${xb(dy(n))}` : $({
18707
18745
  code: "PATH_DENIED",
18708
18746
  message: `schema @ "${t}" 不存在`,
18709
18747
  hint: "jsonPath 需在 schema 声明字段内(用 read() 不传 jsonPath 查看顶层字段)"
@@ -18712,12 +18750,12 @@ function ox(e, n = {}) {
18712
18750
  name: "schema_data",
18713
18751
  description: "查看主数据(或子路径)的字段约束:类型/min/max/enum/必填/默认值/嵌套 shape。写前查约束,避免写错重试。不传 jsonPath 查根;传子路径(如 components.0)查该位置约束。",
18714
18752
  schema: t.object({ jsonPath: t.string().optional().describe("要查约束的子路径;不传查根 schema") })
18715
- }), j = r(async ({ snapshotId: e, against: t }) => {
18753
+ }), ee = r(async ({ snapshotId: e, against: t }) => {
18716
18754
  let n = t != null, r, i;
18717
18755
  if (n) {
18718
18756
  let e = t;
18719
18757
  if (typeof e == "string") {
18720
- let t = gb(e);
18758
+ let t = vb(e);
18721
18759
  t.parseError || (e = t.parsed);
18722
18760
  }
18723
18761
  r = e, i = "against";
@@ -18735,8 +18773,8 @@ function ox(e, n = {}) {
18735
18773
  });
18736
18774
  r = t.value, i = `快照 #${t.id}`;
18737
18775
  }
18738
- let o = s ? ay(a, s) : a, l = Eb(r, hb(o));
18739
- return l.length ? `差异(当前 vs ${i},共 ${l.length} 处):\n${l.map((e) => ` ${e.path}: ${yb(e.from)} → ${yb(e.to)}`).join("\n")}` : `无差异:当前主数据与 ${i} 完全相同。`;
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} 完全相同。`;
18740
18778
  }, {
18741
18779
  name: "diff_data",
18742
18780
  description: "对比当前主数据与某快照(默认最近)或一段 JSON(against)的差异,返回结构化 {path, from→to} 列表。供 verify 自纠/冲突诊断/操作审计(\"刚才改了啥\")。snapshotId 指定快照;against 传一段 JSON 值(与 snapshotId 互斥,传则忽略快照)。",
@@ -18744,7 +18782,7 @@ function ox(e, n = {}) {
18744
18782
  snapshotId: t.number().int().optional().describe("对比的快照序号;不传则最近一次"),
18745
18783
  against: t.unknown().optional().describe("对比的一段 JSON 值(与 snapshotId 互斥;传则忽略快照)")
18746
18784
  })
18747
- }), M = [];
18785
+ }), N = [];
18748
18786
  if (n.vfsStore) {
18749
18787
  let e = n.vfsStore, o = (e) => `drafts/${e}.json`, d = r(({ draftId: t, chunk: n, mode: r }) => {
18750
18788
  let i = o(t), a = e.files[i], s = r === "append" && a, c = s ? a.content + n : n;
@@ -18785,27 +18823,26 @@ function ox(e, n = {}) {
18785
18823
  }
18786
18824
  });
18787
18825
  }
18788
- let f = ax({
18826
+ let f = sx({
18789
18827
  bindRef: a,
18790
18828
  value: d,
18791
18829
  schema: i,
18792
18830
  allowKeys: s,
18793
18831
  snapshots: c,
18794
18832
  maxSnapshots: l,
18795
- audit: p,
18796
- op: "draft_commit"
18833
+ audit: h,
18834
+ op: "draft_commit",
18835
+ onWrite: p
18797
18836
  });
18798
- return f.ok ? (u = f.hash, delete e.files[n], `已 draft_commit 草稿 "${t}" → 主数据 = ${yb(f.data, 600)} (新 hash=${f.hash})${s ? "(白名单模式:仅更新 schema 声明字段)" : ""}。草稿已清理。`) : f.error;
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;
18799
18838
  }, {
18800
18839
  name: "draft_commit",
18801
18840
  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)。",
18802
18841
  schema: t.object({ draftId: t.string().describe("要提交的草稿标识(对应 draft_write 的 draftId)") })
18803
18842
  });
18804
- M.push(d, f);
18843
+ N.push(d, f);
18805
18844
  }
18806
- let ee = [
18807
- g,
18808
- _,
18845
+ let P = [
18809
18846
  v,
18810
18847
  y,
18811
18848
  b,
@@ -18820,19 +18857,21 @@ function ox(e, n = {}) {
18820
18857
  k,
18821
18858
  A,
18822
18859
  j,
18823
- ...M
18860
+ M,
18861
+ ee,
18862
+ ...N
18824
18863
  ];
18825
- return Object.defineProperty(ee, "controller", {
18826
- value: f,
18864
+ return Object.defineProperty(P, "controller", {
18865
+ value: m,
18827
18866
  enumerable: !1,
18828
18867
  configurable: !1,
18829
18868
  writable: !1
18830
- }), ee;
18869
+ }), P;
18831
18870
  }
18832
18871
  //#endregion
18833
18872
  //#region src/core/tools/fetchDoc.ts
18834
- var sx = 3e4, cx = [r(async ({ url: e, as: t }) => {
18835
- let n = new AbortController(), r = setTimeout(() => n.abort(), sx);
18873
+ var lx = 3e4, ux = [r(async ({ url: e, as: t }) => {
18874
+ let n = new AbortController(), r = setTimeout(() => n.abort(), lx);
18836
18875
  try {
18837
18876
  let r = await fetch(e, {
18838
18877
  method: "GET",
@@ -18849,7 +18888,7 @@ var sx = 3e4, cx = [r(async ({ url: e, as: t }) => {
18849
18888
  ].join("\n");
18850
18889
  } catch (t) {
18851
18890
  let r = t?.message || String(t);
18852
- return n.signal.aborted ? `获取失败:请求超时(${sx}ms,${e})。` : /Failed to fetch|NetworkError|CORS|blocked/i.test(r) ? `获取失败:可能是 CORS 跨域拦截或网络错误(${r})。浏览器仅能 GET 同源或服务端已配置 CORS 的资源;跨域抓取需后端代理。` : `获取失败:${r}`;
18891
+ return n.signal.aborted ? `获取失败:请求超时(${lx}ms,${e})。` : /Failed to fetch|NetworkError|CORS|blocked/i.test(r) ? `获取失败:可能是 CORS 跨域拦截或网络错误(${r})。浏览器仅能 GET 同源或服务端已配置 CORS 的资源;跨域抓取需后端代理。` : `获取失败:${r}`;
18853
18892
  } finally {
18854
18893
  clearTimeout(r);
18855
18894
  }
@@ -18860,7 +18899,7 @@ var sx = 3e4, cx = [r(async ({ url: e, as: t }) => {
18860
18899
  url: t.string().describe("要抓取的 URL(同源或已配 CORS)"),
18861
18900
  as: t.enum(["text", "markdown"]).optional().describe("返回格式标签,默认 text")
18862
18901
  })
18863
- })], lx = [
18902
+ })], dx = [
18864
18903
  "id",
18865
18904
  "class",
18866
18905
  "href",
@@ -18872,12 +18911,12 @@ var sx = 3e4, cx = [r(async ({ url: e, as: t }) => {
18872
18911
  "aria-label",
18873
18912
  "name",
18874
18913
  "type"
18875
- ], ux = /^(value|srcdoc|formaction|on\w+)$/i, dx = /token|secret|password|passwd|api[-_]?key|auth|cred|csrf|session/i;
18876
- function fx(e, t) {
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) {
18877
18916
  if (!e) return null;
18878
- let { depth: n, attrs: r, includeText: i = !0 } = t, a = r !== void 0, o = r ?? lx, s = (e) => {
18917
+ let { depth: n, attrs: r, includeText: i = !0 } = t, a = r !== void 0, o = r ?? dx, s = (e) => {
18879
18918
  let t = {};
18880
- for (let n of Array.from(e.attributes)) (a ? o.includes(n.name) : o.includes(n.name) || n.name.startsWith("data-")) && (ux.test(n.name) || dx.test(n.name) || (t[n.name] = n.value));
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));
18881
18920
  return t;
18882
18921
  }, c = (e, t) => {
18883
18922
  let n = {
@@ -18893,10 +18932,10 @@ function fx(e, t) {
18893
18932
  };
18894
18933
  return c(e, n);
18895
18934
  }
18896
- var px = r(({ selector: e, depth: t, attrs: n, includeText: r }) => {
18935
+ var hx = r(({ selector: e, depth: t, attrs: n, includeText: r }) => {
18897
18936
  let i = e ? document.querySelector(e) : document.body;
18898
18937
  if (!i) return `未找到匹配元素:selector="${e}"`;
18899
- let a = fx(i, {
18938
+ let a = mx(i, {
18900
18939
  depth: t ?? 3,
18901
18940
  attrs: n,
18902
18941
  includeText: r ?? !0
@@ -18911,14 +18950,14 @@ var px = r(({ selector: e, depth: t, attrs: n, includeText: r }) => {
18911
18950
  attrs: t.array(t.string()).optional().describe("属性白名单(传了 = 严格白名单;不传 = 默认常用 + data-*)"),
18912
18951
  includeText: t.boolean().optional().describe("是否包含直接文本(默认 true)")
18913
18952
  })
18914
- }), mx = [px];
18953
+ }), gx = [hx];
18915
18954
  //#endregion
18916
18955
  //#region src/core/tools/envTool.ts
18917
- function hx(e) {
18956
+ function _x(e) {
18918
18957
  let t = e;
18919
18958
  return typeof t.tagName == "string" || typeof t.nodeType == "number" && typeof t.nodeName == "string";
18920
18959
  }
18921
- function gx(e, t = 3, n = 2e3, r) {
18960
+ function vx(e, t = 3, n = 2e3, r) {
18922
18961
  if (e == null) return e;
18923
18962
  if (typeof e == "string") return e.length > n ? e.slice(0, n) + "…(已截断)" : e;
18924
18963
  if (typeof e == "number" || typeof e == "boolean") return e;
@@ -18927,14 +18966,14 @@ function gx(e, t = 3, n = 2e3, r) {
18927
18966
  if (typeof e == "bigint") return `${e.toString()}n`;
18928
18967
  if (typeof e != "object") return String(e);
18929
18968
  let i = e;
18930
- if (hx(i)) {
18969
+ if (_x(i)) {
18931
18970
  let e = i;
18932
18971
  return e.tagName ? `[Element: <${e.tagName.toLowerCase()}>]` : `[Node: ${e.nodeName}]`;
18933
18972
  }
18934
18973
  if (r?.has(i)) return "[Circular]";
18935
18974
  let a = r ?? /* @__PURE__ */ new WeakSet();
18936
18975
  if (a.add(i), Array.isArray(e)) {
18937
- let r = e.slice(0, 100).map((e) => gx(e, t - 1, n, a));
18976
+ let r = e.slice(0, 100).map((e) => vx(e, t - 1, n, a));
18938
18977
  return e.length > 100 && r.push(`…(共 ${e.length} 项,已截断)`), r;
18939
18978
  }
18940
18979
  if (t < 0) return "(对象,已截断)";
@@ -18946,14 +18985,14 @@ function gx(e, t = 3, n = 2e3, r) {
18946
18985
  break;
18947
18986
  }
18948
18987
  try {
18949
- o[r] = gx(i[r], t - 1, n, a);
18988
+ o[r] = vx(i[r], t - 1, n, a);
18950
18989
  } catch {
18951
18990
  o[r] = "(getter 抛错)";
18952
18991
  }
18953
18992
  }
18954
18993
  return o;
18955
18994
  }
18956
- function _x(e) {
18995
+ function yx(e) {
18957
18996
  let t = e ?? (typeof window < "u" ? window : {}), n = t.navigator, r = t.location, i = t.document;
18958
18997
  return {
18959
18998
  location: {
@@ -18986,9 +19025,9 @@ function _x(e) {
18986
19025
  } : "(无 document)"
18987
19026
  };
18988
19027
  }
18989
- var vx = /^(localStorage|sessionStorage|cookie|document|frames|frameElement|opener|parent|top|self|window|globalThis|closed|history|navigation|trustedTypes|origin|crossOriginIsolated)$/, yx = /token|secret|password|passwd|api[-_]?key|auth|cred|csrf|session|ticket/i, bx = r(({ key: e }) => {
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 }) => {
18990
19029
  if (e) {
18991
- if (vx.test(e) || yx.test(e)) return JSON.stringify({
19030
+ if (bx.test(e) || xx.test(e)) return JSON.stringify({
18992
19031
  key: e,
18993
19032
  denied: !0,
18994
19033
  reason: "安全:该 key 在 denylist(localStorage/sessionStorage/cookie/document 或敏感命名 token/secret/key/auth),不读取防泄漏"
@@ -18998,18 +19037,18 @@ var vx = /^(localStorage|sessionStorage|cookie|document|frames|frameElement|open
18998
19037
  key: e,
18999
19038
  exists: t !== void 0,
19000
19039
  type: typeof t,
19001
- value: gx(t)
19040
+ value: vx(t)
19002
19041
  }, null, 2);
19003
19042
  }
19004
- return JSON.stringify(_x(), null, 2);
19043
+ return JSON.stringify(yx(), null, 2);
19005
19044
  }, {
19006
19045
  name: "inspect_env",
19007
19046
  description: "读取宿主页面环境信息(排查调试用,默认开启)。不传参 = 返回环境摘要(location 的 URL/origin/path、navigator 的浏览器/语言、viewport 视口尺寸、document 的 title/readyState);传 key = 读取指定 window 属性值(如 inspect_env({key:\"appConfig\"}) 读集成方挂的调试变量 window.appConfig)。用于排查「当前页面在哪/什么浏览器/视口多大/调试变量值是什么」。轻量只读,大结果自动外存 vfs。",
19008
19047
  schema: t.object({ key: t.string().optional().describe("要读取的 window 属性名(如 \"appConfig\"/\"__DEBUG__\");不传 = 返回环境摘要") })
19009
- }), xx = [bx];
19048
+ }), Cx = [Sx];
19010
19049
  //#endregion
19011
19050
  //#region src/core/harness/budget.ts
19012
- function Sx(e, t, n) {
19051
+ function wx(e, t, n) {
19013
19052
  let r = 0;
19014
19053
  return {
19015
19054
  name: "budget",
@@ -19034,12 +19073,12 @@ function Sx(e, t, n) {
19034
19073
  }
19035
19074
  //#endregion
19036
19075
  //#region src/core/sdk/actions.ts
19037
- var Cx = /^[a-zA-Z][a-zA-Z0-9_]*$/;
19038
- function wx(e) {
19076
+ var Tx = /^[a-zA-Z][a-zA-Z0-9_]*$/;
19077
+ function Ex(e) {
19039
19078
  let n = [];
19040
19079
  for (let [i, a] of Object.entries(e)) {
19041
- if (!Cx.test(i)) {
19042
- console.warn(`[page-agent-sdk][actions] 动作名 "${i}" 非法(须匹配 ${Cx}),已跳过`);
19080
+ if (!Tx.test(i)) {
19081
+ console.warn(`[page-agent-sdk][actions] 动作名 "${i}" 非法(须匹配 ${Tx}),已跳过`);
19043
19082
  continue;
19044
19083
  }
19045
19084
  let e = a.description || `宿主动作 ${i}`;
@@ -19059,9 +19098,9 @@ function wx(e) {
19059
19098
  }
19060
19099
  return n;
19061
19100
  }
19062
- function Tx(e) {
19101
+ function Dx(e) {
19063
19102
  let t = {};
19064
- for (let [n, r] of Object.entries(e)) Cx.test(n) && (t[n] = {
19103
+ for (let [n, r] of Object.entries(e)) Tx.test(n) && (t[n] = {
19065
19104
  description: r.description,
19066
19105
  hasParams: !!r.params
19067
19106
  });
@@ -19069,11 +19108,11 @@ function Tx(e) {
19069
19108
  }
19070
19109
  //#endregion
19071
19110
  //#region src/core/toolsets.ts
19072
- var Ex = cx, Dx = mx;
19073
- function Ox(e, t) {
19074
- return ox(e, t);
19111
+ var Ox = ux, kx = gx;
19112
+ function Ax(e, t) {
19113
+ return cx(e, t);
19075
19114
  }
19076
- function kx(e, t, n, r, i) {
19115
+ function jx(e, t, n, r, i) {
19077
19116
  let a = e?.dataOps !== !1, o = e?.fetch !== !1, s = e?.domInspect === !0, c = e?.inspectEnv !== !1;
19078
19117
  return [
19079
19118
  ...a ? t : [],
@@ -19084,15 +19123,15 @@ function kx(e, t, n, r, i) {
19084
19123
  }
19085
19124
  //#endregion
19086
19125
  //#region src/core/harness/usageHints.ts
19087
- var Ax = .7;
19088
- function jx(e, t, n = "simple") {
19126
+ var Mx = .7;
19127
+ function Nx(e, t, n = "simple") {
19089
19128
  let r = n !== "advanced";
19090
19129
  return {
19091
19130
  name: "usageHints",
19092
19131
  augmentPrompt: () => {
19093
19132
  let n = [];
19094
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) {
19095
- let t = e.subagents.filter((e) => (e.temperature ?? 0) >= Ax || /规划|创意|设计|方案|brainstorm|plan/i.test(e.description)), i = e.subagents.filter((e) => (e.temperature ?? 0) < Ax && /反思|审查|挑刺|校验|review|critique|reflect/i.test(e.description));
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));
19096
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(" · 简单/明确任务(如\"标题改红色\")直接执行,不必走规划-反思。");
19097
19136
  }
19098
19137
  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;
@@ -19101,72 +19140,72 @@ function jx(e, t, n = "simple") {
19101
19140
  }
19102
19141
  //#endregion
19103
19142
  //#region src/core/backends/skillStore.ts
19104
- var Mx = "v:1::skill-store", Nx = "chat-sdk";
19105
- function Px(e, t, n) {
19106
- return `${Mx}::${e}::${t}::${n}`;
19143
+ var Px = "v:1::skill-store", Fx = "chat-sdk";
19144
+ function Ix(e, t, n) {
19145
+ return `${Px}::${e}::${t}::${n}`;
19107
19146
  }
19108
- function Fx(e, t) {
19109
- return `${Mx}::${e}::${t}::`;
19147
+ function Lx(e, t) {
19148
+ return `${Px}::${e}::${t}::`;
19110
19149
  }
19111
- function Ix(e = {}) {
19112
- let t = e.dbName ?? Nx, n = e.backend ?? "indexed", r = e.id ?? "", i, a, o = new Promise((e) => {
19150
+ function Rx(e = {}) {
19151
+ let t = e.dbName ?? Fx, n = e.backend ?? "indexed", r = e.id ?? "", i, a, o = new Promise((e) => {
19113
19152
  a = e;
19114
19153
  });
19115
19154
  return (async () => {
19116
19155
  try {
19117
19156
  if (n === "indexed") {
19118
19157
  if (typeof indexedDB > "u") throw Error("indexedDB 不可用");
19119
- i = await Zy(t), a(!0);
19158
+ i = await $y(t), a(!0);
19120
19159
  } else if (n === "session") {
19121
19160
  if (typeof sessionStorage > "u") throw Error("sessionStorage 不可用");
19122
- i = Qy(sessionStorage), a(!0);
19161
+ i = eb(sessionStorage), a(!0);
19123
19162
  } else if (n === "local") {
19124
19163
  if (typeof localStorage > "u") throw Error("localStorage 不可用");
19125
- i = Qy(localStorage), a(!0);
19126
- } else i = Xy(), a(!1);
19164
+ i = eb(localStorage), a(!0);
19165
+ } else i = Qy(), a(!1);
19127
19166
  } catch {
19128
- i = Xy(), a(!1);
19167
+ i = Qy(), a(!1);
19129
19168
  }
19130
19169
  })(), {
19131
19170
  ready: o,
19132
19171
  async list() {
19133
19172
  let e = [];
19134
- return await i.scan(Fx(t, r), (t, n) => {
19173
+ return await i.scan(Lx(t, r), (t, n) => {
19135
19174
  e.push(n);
19136
19175
  }), e;
19137
19176
  },
19138
19177
  async get(e) {
19139
- return await i.get(Px(t, r, e));
19178
+ return await i.get(Ix(t, r, e));
19140
19179
  },
19141
19180
  async put(e) {
19142
19181
  try {
19143
- await i.set(Px(t, r, e.name), e);
19182
+ await i.set(Ix(t, r, e.name), e);
19144
19183
  } catch (e) {
19145
- Hy(e) && (i = Xy());
19184
+ Wy(e) && (i = Qy());
19146
19185
  }
19147
19186
  },
19148
19187
  async remove(e) {
19149
- let n = Px(t, r, e);
19188
+ let n = Ix(t, r, e);
19150
19189
  return await i.get(n) != null && (await i.del(n), !0);
19151
19190
  },
19152
19191
  async clear() {
19153
- await i.clearPrefix(Fx(t, r));
19192
+ await i.clearPrefix(Lx(t, r));
19154
19193
  },
19155
19194
  dispose() {}
19156
19195
  };
19157
19196
  }
19158
19197
  //#endregion
19159
19198
  //#region src/core/sdk/createChatSdk.ts
19160
- var Lx = 50, Rx = /* @__PURE__ */ new Map();
19161
- function zx(e, t) {
19199
+ var zx = 50, Bx = /* @__PURE__ */ new Map();
19200
+ function Vx(e, t) {
19162
19201
  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;
19163
19202
  }
19164
- function Bx(e, t, n, r) {
19203
+ function Hx(e, t, n, r) {
19165
19204
  let i = 0;
19166
19205
  return {
19167
19206
  name: "sdk-events",
19168
19207
  wrapToolCall: async (t, r) => {
19169
- let i = await r(t), a = zx(t.name, t.args);
19208
+ let i = await r(t), a = Vx(t.name, t.args);
19170
19209
  return a && e({
19171
19210
  type: "data_change",
19172
19211
  operation: a,
@@ -19201,18 +19240,18 @@ function Bx(e, t, n, r) {
19201
19240
  }
19202
19241
  };
19203
19242
  }
19204
- function Vx(e, i) {
19243
+ function Ux(e, i) {
19205
19244
  let a = {
19206
19245
  prompt_tokens: 0,
19207
19246
  completion_tokens: 0,
19208
19247
  total_tokens: 0
19209
- }, o = ky(() => Oe), s = /* @__PURE__ */ U(0), c = tb(e.storage);
19248
+ }, o = jy(() => Oe), s = /* @__PURE__ */ U(0), c = rb(e.storage);
19210
19249
  e.debug && c && c.onEvent((e) => console.log("[page-agent-sdk][storage]", e));
19211
- let { modelCaps: l, summaryLlmInvoke: u } = Oy(e), d = l;
19250
+ let { modelCaps: l, summaryLlmInvoke: u } = Ay(e), d = l;
19212
19251
  e.debug && console.log("[page-agent-sdk][modelCaps]", d);
19213
19252
  let f = e.llm;
19214
19253
  e.debug && !u && console.warn("[page-agent-sdk][summarization] 未构造 llmInvoke(apiKey 缺失?),摘要回退零成本索引摘要");
19215
- let p = /* @__PURE__ */ tn([]), m = Ab(e.vfs?.initialFiles, {
19254
+ let p = /* @__PURE__ */ tn([]), m = Mb(e.vfs?.initialFiles, {
19216
19255
  persist: c ? { save: (e) => {
19217
19256
  B.sessionId && c && c.save(i, B.sessionId, { vfs: e });
19218
19257
  } } : void 0,
@@ -19225,24 +19264,25 @@ function Vx(e, i) {
19225
19264
  description: e.data.description ?? "主数据对象"
19226
19265
  } : void 0, x = e.checkpoint, S = x !== void 0 && x !== !1, C = S ? iv({
19227
19266
  getData: () => N()?.bind,
19267
+ consumeDataDirty: () => ee?.consumeDataDirty?.() ?? !0,
19228
19268
  slotPaths: b ? [""] : [],
19229
19269
  vfsStore: m,
19230
19270
  todosMw: h,
19231
19271
  getTodos: () => y.current?.getState?.()?.todos ?? [],
19232
19272
  messages: p,
19233
19273
  maxCheckpoints: x && typeof x == "object" ? x.maxCheckpoints : void 0
19234
- }) : 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 = wy(e), j = E && b ? ox(b, {
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, {
19235
19275
  onAudit: e.onAudit ?? (e.debug ? (e) => console.log("[page-agent-sdk][data audit]", e) : void 0),
19236
19276
  maxSnapshots: e.maxSnapshots,
19237
19277
  onConflict: o.set,
19238
19278
  autoLock: e.autoLock,
19239
19279
  interceptors: e.interceptors,
19240
19280
  vfsStore: D ? m : void 0
19241
- }) : [], M = E ? ix(j, e.toolMode) : [], ee = E && b ? j.controller ?? null : null, N = () => ee?.get() ?? b, P = /* @__PURE__ */ new Map(), F = kx(T, M, cx, mx, xx);
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);
19242
19282
  F.forEach((e) => P.set(e.name, "builtin"));
19243
19283
  let I = [...e.tools || []];
19244
19284
  I.forEach((e) => P.set(e.name, "user"));
19245
- let te = wx(e.actions ?? {});
19285
+ let te = Ex(e.actions ?? {});
19246
19286
  te.forEach((e) => P.set(e.name, "action"));
19247
19287
  let L = [], R = e.humanConfirm !== !1 && (!e.approval || e.approval.humanConfirmTool !== !1), ne = R ? X_() : null;
19248
19288
  ne && P.set(J_, "builtin");
@@ -19280,7 +19320,7 @@ function Vx(e, i) {
19280
19320
  ];
19281
19321
  }
19282
19322
  let ae = T?.planning !== !1, oe = T?.missionAnchor !== !1, se = T?.workingMemory !== !1, ce = T?.skills !== !1, le = T?.vfs !== !1;
19283
- if (le) for (let e of Lb) P.set(e, "builtin");
19323
+ if (le) for (let e of zb) P.set(e, "builtin");
19284
19324
  if (ae) for (let e of h.tools ?? []) P.set(e.name, "builtin");
19285
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;
19286
19326
  e.verify?.check && T?.verify !== !0 && console.warn("[page-agent-sdk][verify] 检测到 verify.check 但 capabilities.verify 未开启,verify 未装载");
@@ -19313,7 +19353,7 @@ function Vx(e, i) {
19313
19353
  llm: e.llm,
19314
19354
  tools: xe
19315
19355
  } : void 0
19316
- }) : void 0, Ce = jx({
19356
+ }) : void 0, Ce = Nx({
19317
19357
  ...T,
19318
19358
  humanConfirm: R,
19319
19359
  subagents: e.subagents?.map((e) => ({
@@ -19323,7 +19363,7 @@ function Vx(e, i) {
19323
19363
  }))
19324
19364
  }, E && !!b, e.toolMode), we = b ? {
19325
19365
  name: "dataHint",
19326
- augmentPrompt: () => Cy(N(), e.schemaHint) || void 0
19366
+ augmentPrompt: () => Ty(N(), e.schemaHint) || void 0
19327
19367
  } : null, Te = e.augmentSystem ? {
19328
19368
  name: "augmentSystem",
19329
19369
  augmentPrompt: (t) => {
@@ -19337,7 +19377,7 @@ function Vx(e, i) {
19337
19377
  return;
19338
19378
  }
19339
19379
  }
19340
- } : null, Ee = e.onEvent, De = rb(e.onEvent), Oe = De.emit, ke, Ae = [], je = (e) => ({
19380
+ } : null, Ee = e.onEvent, De = ab(e.onEvent), Oe = De.emit, ke, Ae = [], je = (e) => ({
19341
19381
  name: e.name,
19342
19382
  description: e.description,
19343
19383
  content: typeof e.getContent == "function" ? e.getContent() : ""
@@ -19345,7 +19385,7 @@ function Vx(e, i) {
19345
19385
  name: e.name,
19346
19386
  description: e.description,
19347
19387
  getContent: () => e.content
19348
- }), Ne = e.skillStorage === !1 ? null : Ix({
19388
+ }), Ne = e.skillStorage === !1 ? null : Rx({
19349
19389
  ...typeof e.skillStorage == "object" ? e.skillStorage : {},
19350
19390
  id: e.skillStorage && typeof e.skillStorage == "object" && e.skillStorage.id ? e.skillStorage.id : `agent::${i}`
19351
19391
  }), Pe = () => {
@@ -19368,18 +19408,18 @@ function Vx(e, i) {
19368
19408
  B.infoTick.value++;
19369
19409
  }
19370
19410
  } catch {}
19371
- }, Ie = cb([
19411
+ }, Ie = ub([
19372
19412
  ...we ? [we] : [],
19373
19413
  Ce,
19374
19414
  ...oe ? [g] : [],
19375
19415
  ...ae ? [h] : [],
19376
19416
  ...ce ? [ke = z_(e.skills || [], { readVfs: le ? (e) => m.files[e]?.content : void 0 })] : [],
19377
- ...le ? [zb(m)] : [],
19417
+ ...le ? [Vb(m)] : [],
19378
19418
  ...ue ? [$v({
19379
- ...ob(e, d.contextWindow),
19419
+ ...cb(e, d.contextWindow),
19380
19420
  llmInvoke: u,
19381
19421
  getRegisteredData: () => N() ? [{ description: N().description ?? "主数据对象" }] : [],
19382
- preserveLastToolResults: (e.contextOptions && e.contextOptions.preserveLastToolResults) ?? ab[e.contextPreset ?? "auto"]
19422
+ preserveLastToolResults: (e.contextOptions && e.contextOptions.preserveLastToolResults) ?? sb[e.contextPreset ?? "auto"]
19383
19423
  })] : [],
19384
19424
  ...se ? [_] : [],
19385
19425
  ...de ? [v] : [],
@@ -19392,12 +19432,12 @@ function Vx(e, i) {
19392
19432
  ...ve ? [ve] : [],
19393
19433
  ...Te ? [Te] : [],
19394
19434
  ...e.middleware || [],
19395
- ...k ? [Sx(a, {
19435
+ ...k ? [wx(a, {
19396
19436
  tokenBudget: e.tokenBudget,
19397
19437
  timeBudgetMs: e.timeBudgetMs
19398
19438
  }, Oe)] : [],
19399
- Bx(Oe, p, N, a)
19400
- ]), Le = e.maxMemoryRounds ?? Lx, B = {
19439
+ Hx(Oe, p, N, a)
19440
+ ]), Le = e.maxMemoryRounds ?? zx, B = {
19401
19441
  agentId: i,
19402
19442
  store: c,
19403
19443
  messages: p,
@@ -19500,6 +19540,7 @@ function Vx(e, i) {
19500
19540
  for (let r = 0; r < e.length; r++) {
19501
19541
  let i = e[r];
19502
19542
  C && C.save(`batch:${r}`);
19543
+ let a = p.length;
19503
19544
  try {
19504
19545
  p.push({
19505
19546
  role: "user",
@@ -19522,11 +19563,12 @@ function Vx(e, i) {
19522
19563
  task: i,
19523
19564
  ok: !0
19524
19565
  });
19525
- } catch (a) {
19526
- let o = Gg(a, "fatal");
19566
+ } catch (o) {
19567
+ p.length > a && p.splice(a);
19568
+ let s = Gg(o, "fatal");
19527
19569
  Oe({
19528
19570
  type: "error",
19529
- message: `批量任务 ${r + 1}/${e.length} 失败:${o.message}`,
19571
+ message: `批量任务 ${r + 1}/${e.length} 失败:${s.message}`,
19530
19572
  severity: "observable",
19531
19573
  code: "BATCH_TASK_FAILED",
19532
19574
  context: {
@@ -19536,7 +19578,7 @@ function Vx(e, i) {
19536
19578
  }), n.push({
19537
19579
  index: r,
19538
19580
  task: i,
19539
- error: o.message,
19581
+ error: s.message,
19540
19582
  ok: !1
19541
19583
  }), t?.({
19542
19584
  done: r + 1,
@@ -19573,7 +19615,7 @@ function Vx(e, i) {
19573
19615
  if (B.refCount--, B.refCount <= 0) {
19574
19616
  c && (m.flush?.(), c.flush(), c.dispose()), Ne && Ne.dispose();
19575
19617
  let e = B.mcpClosers.splice(0);
19576
- e.length && Promise.allSettled(e.map((e) => e())), Rx.delete(i);
19618
+ e.length && Promise.allSettled(e.map((e) => e())), Bx.delete(i);
19577
19619
  }
19578
19620
  },
19579
19621
  resolveConflict: o.resolve,
@@ -19590,7 +19632,7 @@ function Vx(e, i) {
19590
19632
  return t < 0 ? !1 : (I.splice(t, 1), z = ie(), B.agent && B.agent.setTools(z), B.infoTick.value++, !0);
19591
19633
  },
19592
19634
  setLlm(t) {
19593
- let r = Ty(t) ? t : new n({
19635
+ let r = Dy(t) ? t : new n({
19594
19636
  apiKey: t.apiKey,
19595
19637
  model: t.model,
19596
19638
  temperature: t.temperature,
@@ -19631,8 +19673,8 @@ function Vx(e, i) {
19631
19673
  getInfo() {
19632
19674
  return {
19633
19675
  id: i,
19634
- model: Ty(f) ? f.model ?? f.modelName : f.model,
19635
- systemPrompt: B.agent?.getEffectiveSystemPrompt?.() ?? A + Cy(N(), e.schemaHint),
19676
+ model: Dy(f) ? f.model ?? f.modelName : f.model,
19677
+ systemPrompt: B.agent?.getEffectiveSystemPrompt?.() ?? A + Ty(N(), e.schemaHint),
19636
19678
  tools: (B.agent?.allTools ?? z).map((e) => ({
19637
19679
  name: e.name,
19638
19680
  description: e.description,
@@ -19666,7 +19708,7 @@ function Vx(e, i) {
19666
19708
  spans: B.agent.spans.value,
19667
19709
  metrics: r_(B.agent.spans.value)
19668
19710
  } : void 0,
19669
- actions: Tx(e.actions ?? {}),
19711
+ actions: Dx(e.actions ?? {}),
19670
19712
  subagent: {
19671
19713
  enabled: !!_e,
19672
19714
  maxDepth: e.subagent?.maxDepth ?? 1,
@@ -19754,7 +19796,7 @@ function Vx(e, i) {
19754
19796
  }), z = ie(), e.debug && console.log(`[page-agent-sdk][mcp] 注入 ${n.length} 个工具,${B.mcpServers.length} 个 server`);
19755
19797
  }
19756
19798
  B.agent = x_({
19757
- ...Ty(e.llm) ? { llm: e.llm } : {
19799
+ ...Dy(e.llm) ? { llm: e.llm } : {
19758
19800
  apiKey: e.llm.apiKey,
19759
19801
  baseUrl: e.llm.baseUrl,
19760
19802
  model: e.llm.model,
@@ -19773,7 +19815,7 @@ function Vx(e, i) {
19773
19815
  maxOutputTokens: d.maxOutputTokens,
19774
19816
  maxVerifyAttempts: me ? pe : 0,
19775
19817
  onLlmChange: (t) => {
19776
- let n = Ty(t) ? void 0 : t;
19818
+ let n = Dy(t) ? void 0 : t;
19777
19819
  d = $g({
19778
19820
  model: n?.model ?? t.model ?? t.modelName,
19779
19821
  contextWindow: e.contextWindow ?? n?.contextWindow,
@@ -19795,12 +19837,12 @@ function Vx(e, i) {
19795
19837
  });
19796
19838
  })(), B;
19797
19839
  }
19798
- function Hx(e) {
19799
- let t = e.id ?? Ay();
19840
+ function Wx(e) {
19841
+ let t = e.id ?? My();
19800
19842
  e.id || console.warn(`[page-agent-sdk] 未传 options.id,已生成随机 id "${t}"。刷新后持久化数据无法恢复,请传稳定 id。`);
19801
- let n = e.streaming ?? !0, r = e.ui ?? "default", i, a = e.shareContext ? Rx.get(t) : void 0;
19802
- a ? i = a : (i = Vx(e, t), e.shareContext && Rx.set(t, i)), i.refCount++;
19803
- let o = null, s = null, c = nb(e), l = null, u = null;
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++;
19845
+ let o = null, s = null, c = ib(e), l = null, u = null;
19804
19846
  async function d(t) {
19805
19847
  if (await i.initDone, o) {
19806
19848
  m();
@@ -19839,7 +19881,7 @@ function Hx(e) {
19839
19881
  i.afterRound(), i.store && await i.store.flush();
19840
19882
  },
19841
19883
  onClear: () => {
19842
- i.store && (i.sessionId = Ay(), i.vfsStore.clear?.(), i.todosMw.reset([]), e.memory || i.memoryMw.reset(""), i.agent.debugLogs.value = [], i.store.createSession(i.agentId, e.session?.title, i.sessionId));
19884
+ i.store && (i.sessionId = My(), i.vfsStore.clear?.(), i.todosMw.reset([]), e.memory || i.memoryMw.reset(""), i.agent.debugLogs.value = [], i.store.createSession(i.agentId, e.session?.title, i.sessionId));
19843
19885
  },
19844
19886
  pendingConflict: i.pendingConflict.value,
19845
19887
  onResolveConflict: (e) => i.resolveConflict(e),
@@ -19958,7 +20000,7 @@ function Hx(e) {
19958
20000
  error: "schema 校验失败:" + (t.error?.message ?? "未知错误")
19959
20001
  };
19960
20002
  }
19961
- return tv(r, e), t?.emit !== !1 && i.emit({
20003
+ return tv(r, e), i.dataOpsController?.markDataDirty?.(), t?.emit !== !1 && i.emit({
19962
20004
  type: "data_change",
19963
20005
  operation: "set",
19964
20006
  value: r
@@ -19980,7 +20022,7 @@ function Hx(e) {
19980
20022
  }
19981
20023
  //#endregion
19982
20024
  //#region src/core/sdk/defineTool.ts
19983
- function Ux(e) {
20025
+ function Gx(e) {
19984
20026
  return r(async (t) => {
19985
20027
  let n = await e.handler(t);
19986
20028
  return typeof n == "string" ? n : JSON.stringify(n);
@@ -19991,4 +20033,4 @@ function Ux(e) {
19991
20033
  });
19992
20034
  }
19993
20035
  //#endregion
19994
- export { ib as CONTEXT_PRESETS, Bg as ChatDialog, nf as CodePreview, Sy as DEFAULT_SYSTEM_PROMPT, J_ as HUMAN_CONFIRM_TOOL_NAME, af as MessageContent, Gv as STOP_WORDS, xh as SkillPanel, lb as UNSAFE_KEYS, Tx as actionsToInspectInfo, wx as actionsToTools, Kg as agentError, Sb as applyPatchToClone, Cb as applyPatchToLive, Gg as asAgentError, Cy as buildDataPrompt, wy as buildSystemPrompt, ax as commitSetToBind, Lv as connectMcp, wl as copyText, x_ as createAgent, q_ as createApprovalMiddleware, Hx as createChatSdk, iv as createCheckpointManager, av as createCheckpointMiddleware, ky as createConflictManager, ox as createDataOps, Z_ as createHumanConfirmMiddleware, X_ as createHumanConfirmTool, Xy as createMemoryBackend, B_ as createMemoryMiddleware, v as createProxyLlm, rb as createSdkEvents, eb as createSessionStore, Ix as createSkillStore, _v as createSubagentMiddleware, bv as createSubagentsMiddleware, jx as createUsageHintsMiddleware, xv as createVerifyMiddleware, Ab as createVfs, Qy as createWebStorageBackend, Dv as createWriteBackCheck, hb as deepClone, Ox as defineDataToolset, N_ as defineSkill, Ux as defineTool, mb as deleteByPath, dy as describeSchemaNode, p_ as detectGarbledToolCall, Eb as diffObjects, fx as domToStructure, mx as domTools, Dx as domToolsStatic, qv as estimateMessageTokens, Jv as estimateRoundTokens, e_ as estimateTokens, xy as extractSchemaHint, Pv as extractText, cx as fetchDocTools, Ex as fetchTools, ix as filterByToolMode, fy as formatConstraints, Vg as formatZodIssues, fb as getByPath, px as getDomTool, _x as getEnvSummary, ry as getSchemaAtPath, ey as getSchemaTopKeys, r_ as getTraceMetrics, xb as hashValue, Yv as indexSummarize, bx as inspectEnvTool, xx as inspectTools, Ty as isChatModel, ty as isPathAllowed, Hy as isQuotaError, ub as isUnsafePath, Yb as jpEval, Ug as jsonParseError, vb as limitDepth, gb as maybeParseValue, n_ as offloadPassThroughChars, t_ as offloadThresholdChars, _y as presets, ay as projectBySchema, iy as projectBySchemaDeep, _b as projectFields, Xv as recallRounds, py as renderSchemaHint, my as renderSchemaOverview, gy as renderSchemaShallow, ob as resolveContextOptions, nb as resolveDialogConfig, Oy as resolveLlm, $g as resolveModelCaps, tb as resolveStorage, Tb as restoreInPlace, wb as restoreLive, Wg as routeError, tx as runSandboxedScript, db as safeMerge, gx as safeSerialize, yb as safeStringify, Zb as searchJson, kx as selectBuiltinTools, pb as setByPath, vy as systemPromptHelpers, Kv as tokenize, $ as toolError, ny as unwrapSchema, Cl as useChat, e as z, Hg as zodError };
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 };