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