page-agent-sdk 4.1.0 → 4.2.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.
@@ -453,10 +453,10 @@ function O(e) {
453
453
  }
454
454
  var k = process.env.NODE_ENV === "production" ? {} : Object.freeze({});
455
455
  process.env.NODE_ENV === "production" || Object.freeze([]);
456
- var te = () => {}, ne = (e) => e.charCodeAt(0) === 111 && e.charCodeAt(1) === 110 && (e.charCodeAt(2) > 122 || e.charCodeAt(2) < 97), A = (e) => e.startsWith("onUpdate:"), j = Object.assign, M = (e, t) => {
456
+ var te = () => {}, ne = (e) => e.charCodeAt(0) === 111 && e.charCodeAt(1) === 110 && (e.charCodeAt(2) > 122 || e.charCodeAt(2) < 97), A = (e) => e.startsWith("onUpdate:"), j = Object.assign, re = (e, t) => {
457
457
  let n = e.indexOf(t);
458
458
  n > -1 && e.splice(n, 1);
459
- }, re = Object.prototype.hasOwnProperty, N = (e, t) => re.call(e, t), P = Array.isArray, ie = (e) => le(e) === "[object Map]", F = (e) => le(e) === "[object Set]", I = (e) => typeof e == "function", ae = (e) => typeof e == "string", oe = (e) => typeof e == "symbol", L = (e) => typeof e == "object" && !!e, se = (e) => (L(e) || I(e)) && I(e.then) && I(e.catch), ce = Object.prototype.toString, le = (e) => ce.call(e), ue = (e) => le(e).slice(8, -1), R = (e) => le(e) === "[object Object]", de = (e) => ae(e) && e !== "NaN" && e[0] !== "-" && "" + parseInt(e, 10) === e, z = ((e) => {
459
+ }, M = Object.prototype.hasOwnProperty, N = (e, t) => M.call(e, t), P = Array.isArray, ie = (e) => le(e) === "[object Map]", F = (e) => le(e) === "[object Set]", I = (e) => typeof e == "function", ae = (e) => typeof e == "string", oe = (e) => typeof e == "symbol", L = (e) => typeof e == "object" && !!e, se = (e) => (L(e) || I(e)) && I(e.then) && I(e.catch), ce = Object.prototype.toString, le = (e) => ce.call(e), ue = (e) => le(e).slice(8, -1), R = (e) => le(e) === "[object Object]", de = (e) => ae(e) && e !== "NaN" && e[0] !== "-" && "" + parseInt(e, 10) === e, z = ((e) => {
460
460
  let t = /* @__PURE__ */ Object.create(null);
461
461
  return ((n) => t[n] || (t[n] = e(n)));
462
462
  })((e) => e.charAt(0).toUpperCase() + e.slice(1)), B = (e, t) => !Object.is(e, t), fe = (e, t, n, r = !1) => {
@@ -1215,7 +1215,7 @@ function Zt(e, t, n = k) {
1215
1215
  f = () => Qt(e(), t);
1216
1216
  }
1217
1217
  let _ = be(), v = () => {
1218
- d.stop(), _ && _.active && M(_.effects, d);
1218
+ d.stop(), _ && _.active && re(_.effects, d);
1219
1219
  };
1220
1220
  if (a && t) {
1221
1221
  let e = t;
@@ -3575,7 +3575,7 @@ function No(e) {
3575
3575
  return Array.isArray(r) && r.length && r[0] && typeof r[0].jsonPath == "string" ? r[0].jsonPath : "";
3576
3576
  }
3577
3577
  function Po(e) {
3578
- let { apiKey: t, baseUrl: r, model: c = "gpt-3.5-turbo", temperature: l = .7, maxTokens: u, extraBody: d, extraConfig: f, systemPrompt: p, tools: v = [], middleware: y = [], maxToolRounds: S, maxIterations: C, maxRetries: E = 2, retryDelayMs: D = 500, stallMs: O = Bi, streamMaxMs: k = Hi, toolTimeoutMs: te, maxParallelTools: ne = 1, maxVerifyAttempts: A = 0, roundTokenBudget: j = 0, onLog: M, onLlmChange: re, imageContentFormat: N = "openai", staleReadInvalidation: P = !0, debug: ie = !1 } = e, F = S ?? Eo;
3578
+ let { apiKey: t, baseUrl: r, model: c = "gpt-3.5-turbo", temperature: l = .7, maxTokens: u, extraBody: d, extraConfig: f, systemPrompt: p, tools: v = [], middleware: y = [], maxToolRounds: S, maxIterations: C, maxRetries: E = 2, retryDelayMs: D = 500, stallMs: O = Bi, streamMaxMs: k = Hi, toolTimeoutMs: te, maxParallelTools: ne = 1, maxVerifyAttempts: A = 0, roundTokenBudget: j = 0, onLog: re, onLlmChange: M, imageContentFormat: N = "openai", staleReadInvalidation: P = !0, debug: ie = !1 } = e, F = S ?? Eo;
3579
3579
  (!Number.isFinite(F) || F < 1) && (console.warn(`[page-agent-sdk] maxToolRounds=${F} 非法(须 ≥1 正整数),已 clamp 到 1(0/负数致主循环 while 不进 → agent 不调 LLM 静默返回兜底文案)`), F = 1);
3580
3580
  let I = m({
3581
3581
  model: c,
@@ -3593,7 +3593,7 @@ function Po(e) {
3593
3593
  type: e,
3594
3594
  data: t
3595
3595
  };
3596
- ce.value.push(n), ce.value.length > Do && ce.value.splice(0, ce.value.length - Do), Vt(ce), M?.(n), ie && console.log(`%c[Agent] ${e}`, "color:#667eea;font-weight:bold", t);
3596
+ ce.value.push(n), ce.value.length > Do && ce.value.splice(0, ce.value.length - Do), Vt(ce), re?.(n), ie && console.log(`%c[Agent] ${e}`, "color:#667eea;font-weight:bold", t);
3597
3597
  }
3598
3598
  let de = (e) => {
3599
3599
  ce.value.push(e), ce.value.length > Do && ce.value.splice(0, ce.value.length - Do), Vt(ce);
@@ -3839,7 +3839,7 @@ function Po(e) {
3839
3839
  return ko(e, t);
3840
3840
  }
3841
3841
  function xe(e) {
3842
- return !ie && !M ? [] : e.map((e) => {
3842
+ return !ie && !re ? [] : e.map((e) => {
3843
3843
  let t = be(e), n = { role: t === "human" ? "user" : t === "ai" ? "assistant" : t }, r = typeof e.content == "string" ? e.content : JSON.stringify(e.content);
3844
3844
  r && (n.content = r.length > Oo ? r.slice(0, Oo) + `…(截断 ${r.length - Oo} 字符)` : r);
3845
3845
  let i = e.tool_calls;
@@ -4297,7 +4297,7 @@ function Po(e) {
4297
4297
  z = [...y.flatMap((e) => e.tools || []), ...e], me();
4298
4298
  }
4299
4299
  function Te(e) {
4300
- B = e, me(), re?.(e);
4300
+ B = e, me(), M?.(e);
4301
4301
  }
4302
4302
  return {
4303
4303
  invoke: Ce,
@@ -5072,7 +5072,7 @@ function Ws(e, t, n, r) {
5072
5072
  }
5073
5073
  if (t === "move") return Ks(e, n, r);
5074
5074
  let i = n ? Q(e, n) : e;
5075
- return Array.isArray(i) ? (Array.isArray(r) ? i.push(...r) : i.push(r), null) : `append 目标${n ? `(${n})` : "(根)"}不是数组`;
5075
+ return typeof i == "string" ? typeof r == "string" ? (Ps(e, n, i + r), null) : `append 目标(${n})是字符串,value 必须也是字符串(拼接语义)` : Array.isArray(i) ? (Array.isArray(r) ? i.push(...r) : i.push(r), null) : `append 目标${n ? `(${n})` : "(根)"}不是数组(也不支持非字符串标量拼接)`;
5076
5076
  }
5077
5077
  function Gs(e, t) {
5078
5078
  let n = t.split("."), r = e;
@@ -7644,47 +7644,63 @@ function Pu(e, t, n, r) {
7644
7644
  hint: "重新 read 该字段触发懒注册重建句柄,再写回新句柄 ⟦res:<handle>⟧"
7645
7645
  };
7646
7646
  }
7647
- function Fu(e, t) {
7648
- let n = t.getBind();
7649
- for (let [r, i] of t.resourcesByPath) {
7650
- let a = Q(n, r), o = Q(e, r);
7651
- if (o === void 0) {
7652
- a !== void 0 && Ps(e, r, a);
7653
- continue;
7647
+ function Fu(e, t, n) {
7648
+ let r = t.getBind();
7649
+ for (let [i, a] of t.resourcesByPath) {
7650
+ let o = Q(r, i), s = Q(e, i);
7651
+ if (s === void 0) {
7652
+ if (o === void 0) continue;
7653
+ let t = i.split(".");
7654
+ if (Q(e, t.length > 1 ? t.slice(0, -1).join(".") : "") !== void 0) {
7655
+ Ps(e, i, o);
7656
+ continue;
7657
+ }
7658
+ if (!(e && typeof e == "object" && t[0] in e)) {
7659
+ if (n) continue;
7660
+ Ps(e, i, o);
7661
+ continue;
7662
+ }
7663
+ return {
7664
+ ok: !1,
7665
+ code: a.mode === "freeze" ? "FROZEN_FIELD" : "VERBATIM_PROTECTED",
7666
+ path: i,
7667
+ message: `整体替换会移除受保护字段 "${i}"(${a.mode}),已拒绝`,
7668
+ hint: a.mode === "freeze" ? "含冻结字段的容器不可整体清空/替换:保留包含该字段的元素(补齐其必填字段,如 type),或逐个 remove 其余元素;彻底移除该字段需集成方调整 data.resources" : "含 verbatim 字段的容器不可整体清空/替换:保留包含该字段的元素,或先 resource_delete({path}) 释放保护后再整体替换"
7669
+ };
7654
7670
  }
7655
- if (i.mode === "freeze") {
7656
- if (o === Tu(r)) {
7657
- Ps(e, r, a);
7671
+ if (a.mode === "freeze") {
7672
+ if (s === Tu(i)) {
7673
+ Ps(e, i, o);
7658
7674
  continue;
7659
7675
  }
7660
- if (!Au(o, a)) return {
7676
+ if (!Au(s, o)) return {
7661
7677
  ok: !1,
7662
7678
  code: "FROZEN_FIELD",
7663
- path: r,
7664
- message: `字段 "${r}" 已冻结(freeze 保护),不可修改`,
7679
+ path: i,
7680
+ message: `字段 "${i}" 已冻结(freeze 保护),不可修改`,
7665
7681
  hint: "该字段由系统/集成方维护,LLM 不得改动。如需展示其值用 resource_get({path}) 取真值"
7666
7682
  };
7667
7683
  } else {
7668
- let n = Du(o);
7684
+ let n = Du(s);
7669
7685
  if (n && n.type === "res") {
7670
- let i = Pu(n.handle, r, a, t.resourceStore);
7671
- if ("value" in i) {
7672
- Ps(e, r, i.value);
7686
+ let r = Pu(n.handle, i, o, t.resourceStore);
7687
+ if ("value" in r) {
7688
+ Ps(e, i, r.value);
7673
7689
  continue;
7674
7690
  }
7675
7691
  return {
7676
7692
  ok: !1,
7677
- code: i.code,
7678
- path: r,
7679
- message: i.message,
7680
- hint: i.hint
7693
+ code: r.code,
7694
+ path: i,
7695
+ message: r.message,
7696
+ hint: r.hint
7681
7697
  };
7682
7698
  }
7683
- if (!Au(o, a)) return {
7699
+ if (!Au(s, o)) return {
7684
7700
  ok: !1,
7685
7701
  code: "VERBATIM_MISMATCH",
7686
- path: r,
7687
- message: `字段 "${r}" 为 verbatim 保护(精确原样保留),写入值与原值不符`,
7702
+ path: i,
7703
+ message: `字段 "${i}" 为 verbatim 保护(精确原样保留),写入值与原值不符`,
7688
7704
  hint: "要改该值请先 resource_update({path, value}) 更新资源池,再写回句柄 ⟦res:<handle>⟧;或写回原值(经 resource_get 取到的值)保持不变"
7689
7705
  };
7690
7706
  }
@@ -7705,18 +7721,18 @@ function Iu(e, t, n) {
7705
7721
  });
7706
7722
  }
7707
7723
  function Lu(e) {
7708
- let { value: t, ctx: n } = e;
7724
+ let { value: t, ctx: n, mergeMode: r } = e;
7709
7725
  if (!n || !n.resourcesByPath.size) return {
7710
7726
  ok: !0,
7711
7727
  value: t
7712
7728
  };
7713
- let r = Is(t), i = Fu(r, n);
7714
- return i.ok ? {
7729
+ let i = Is(t), a = Fu(i, n, r);
7730
+ return a.ok ? {
7715
7731
  ok: !0,
7716
- value: r
7732
+ value: i
7717
7733
  } : {
7718
7734
  ok: !1,
7719
- error: Iu(i)
7735
+ error: Iu(a)
7720
7736
  };
7721
7737
  }
7722
7738
  function Ru(e) {
@@ -7935,7 +7951,32 @@ function Wu(e) {
7935
7951
  continue;
7936
7952
  }
7937
7953
  if (i === "append") {
7938
- let e = o[p++]?.elems ?? [];
7954
+ let e = o[p++]?.elems ?? [], r = Q(n, a);
7955
+ if (typeof r == "string" && typeof e[0] == "string") {
7956
+ let n = e[0], i = Vo(t, a);
7957
+ if (i.kind === "missing") return {
7958
+ ok: !1,
7959
+ error: d([a]),
7960
+ writeBacks: [],
7961
+ notices: c
7962
+ };
7963
+ let o = r + n;
7964
+ if (i.kind !== "open") {
7965
+ let e = i.schemas.map((e) => e.safeParse(o)).find((e) => !e.success);
7966
+ if (e) return {
7967
+ ok: !1,
7968
+ error: u(a, e.error?.issues ?? []),
7969
+ writeBacks: [],
7970
+ notices: c
7971
+ };
7972
+ }
7973
+ f.push({
7974
+ op: "appendStr",
7975
+ jp: a,
7976
+ str: n
7977
+ });
7978
+ continue;
7979
+ }
7939
7980
  if (!e.length) {
7940
7981
  f.push({
7941
7982
  op: "appendElems",
@@ -7944,14 +7985,14 @@ function Wu(e) {
7944
7985
  });
7945
7986
  continue;
7946
7987
  }
7947
- let n = Vo(t, a);
7948
- if (n.kind === "missing") return {
7988
+ let i = Vo(t, a);
7989
+ if (i.kind === "missing") return {
7949
7990
  ok: !1,
7950
7991
  error: d([a || "(根)"]),
7951
7992
  writeBacks: [],
7952
7993
  notices: c
7953
7994
  };
7954
- if (n.kind === "open") {
7995
+ if (i.kind === "open") {
7955
7996
  c.push(`${a || "(根)"}=开放节点放行`), f.push({
7956
7997
  op: "appendElems",
7957
7998
  jp: a,
@@ -7959,8 +8000,8 @@ function Wu(e) {
7959
8000
  });
7960
8001
  continue;
7961
8002
  }
7962
- let r = Go(n.schemas);
7963
- if (!r.length) {
8003
+ let s = Go(i.schemas);
8004
+ if (!s.length) {
7964
8005
  c.push(`${a || "(根)"}:目标非 schema 声明数组,元素未校验放行`), f.push({
7965
8006
  op: "appendElems",
7966
8007
  jp: a,
@@ -7968,36 +8009,36 @@ function Wu(e) {
7968
8009
  });
7969
8010
  continue;
7970
8011
  }
7971
- let i = [];
8012
+ let l = [];
7972
8013
  for (let t = 0; t < e.length; t++) {
7973
- let n = [], o, s = !1;
7974
- for (let i of r) {
7975
- let r = i.safeParse(e[t]);
7976
- if (r.success) {
7977
- s = !0, o = r.data;
8014
+ let n = [], r, i = !1;
8015
+ for (let a of s) {
8016
+ let o = a.safeParse(e[t]);
8017
+ if (o.success) {
8018
+ i = !0, r = o.data;
7978
8019
  break;
7979
8020
  }
7980
- n.push(...r.error?.issues ?? []);
8021
+ n.push(...o.error?.issues ?? []);
7981
8022
  }
7982
- if (!s) return {
8023
+ if (!i) return {
7983
8024
  ok: !1,
7984
8025
  error: u(`${a || "(根)"}[新增元素${t}]`, n),
7985
8026
  writeBacks: [],
7986
8027
  notices: c
7987
8028
  };
7988
- let l = Xs(void 0, e[t], o, a ? `${a}.${t}` : String(t));
7989
- if (l.length) return {
8029
+ let o = Xs(void 0, e[t], r, a ? `${a}.${t}` : String(t));
8030
+ if (o.length) return {
7990
8031
  ok: !1,
7991
- error: d(l),
8032
+ error: d(o),
7992
8033
  writeBacks: [],
7993
8034
  notices: c
7994
8035
  };
7995
- i.push(o);
8036
+ l.push(r);
7996
8037
  }
7997
8038
  f.push({
7998
8039
  op: "appendElems",
7999
8040
  jp: a,
8000
- elems: i
8041
+ elems: l
8001
8042
  });
8002
8043
  continue;
8003
8044
  }
@@ -8130,7 +8171,8 @@ function Gu(e) {
8130
8171
  if (l) {
8131
8172
  let e = Lu({
8132
8173
  value: d,
8133
- ctx: l
8174
+ ctx: l,
8175
+ mergeMode: !!r
8134
8176
  });
8135
8177
  if (!e.ok) return {
8136
8178
  ok: !1,
@@ -8252,7 +8294,7 @@ function Ku(e) {
8252
8294
  error: Z({
8253
8295
  code: "PATCH_FAILED",
8254
8296
  message: `patches[${e}]: ${c}`,
8255
- hint: "检查 op 与目标类型:merge 需对象,append 需数组"
8297
+ hint: "检查 op 与目标类型:merge 需对象,append 需数组或字符串"
8256
8298
  })
8257
8299
  };
8258
8300
  v(o, a), m.push({
@@ -8309,6 +8351,9 @@ function Ku(e) {
8309
8351
  } else if (e.op === "appendElems") {
8310
8352
  let n = e.jp ? Q(t, e.jp) : t;
8311
8353
  Array.isArray(n) && e.elems?.length && n.push(...e.elems);
8354
+ } else if (e.op === "appendStr") {
8355
+ let n = e.jp ? Q(t, e.jp) : t;
8356
+ typeof n == "string" && typeof e.str == "string" && Ps(t, e.jp, n + e.str);
8312
8357
  }
8313
8358
  return e.internalAfterWrite?.(t, f), s?.(), {
8314
8359
  ok: !0,
@@ -8494,9 +8539,9 @@ function rd(e, n = {}) {
8494
8539
  arrayPath: e.slice(0, t),
8495
8540
  field: e.slice(t + 1)
8496
8541
  } : null;
8497
- }).filter((e) => e !== null), M = !0;
8498
- function re() {
8499
- M = !0;
8542
+ }).filter((e) => e !== null), re = !0;
8543
+ function M() {
8544
+ re = !0;
8500
8545
  }
8501
8546
  let N = {
8502
8547
  get: () => ({
@@ -8505,15 +8550,15 @@ function rd(e, n = {}) {
8505
8550
  description: c
8506
8551
  }),
8507
8552
  set: (e) => {
8508
- o = i.length ? ls(e.schema, i).schema : e.schema, s = e.bind, c = e.description ?? "主数据对象", l = Fo(o), m.length = 0, g.clear(), f(e.resources), d?.clear(), re();
8553
+ o = i.length ? ls(e.schema, i).schema : e.schema, s = e.bind, c = e.description ?? "主数据对象", l = Fo(o), m.length = 0, g.clear(), f(e.resources), d?.clear(), M();
8509
8554
  },
8510
8555
  update: (e) => {
8511
- s = e, m.length = 0, g.clear(), re();
8556
+ s = e, m.length = 0, g.clear(), M();
8512
8557
  },
8513
- markDataDirty: re,
8558
+ markDataDirty: M,
8514
8559
  consumeDataDirty: () => {
8515
- let e = M;
8516
- return M = !1, e;
8560
+ let e = re;
8561
+ return re = !1, e;
8517
8562
  },
8518
8563
  enterScope: (e) => {
8519
8564
  let t = _;
@@ -8567,7 +8612,7 @@ function rd(e, n = {}) {
8567
8612
  } : void 0,
8568
8613
  updateResource: d ? (e, t) => {
8569
8614
  let n = Ou(e);
8570
- d.update(n, t), Ps(s, n, t), re(), C(D(), "");
8615
+ d.update(n, t), Ps(s, n, t), M(), C(D(), "");
8571
8616
  } : void 0,
8572
8617
  deleteResource: d ? (e) => d.delete(e) : void 0,
8573
8618
  listResources: d ? () => d.list() : void 0
@@ -8607,7 +8652,7 @@ function rd(e, n = {}) {
8607
8652
  if (o.action === "restore") {
8608
8653
  if (await i?.reacquire(), !m.length) return `无历史快照可回退(本次为首次操作)。当前值:${$(s, 400)} (hash=${a})。请重新 read 再改或选「强制覆盖」。`;
8609
8654
  let e = m[m.length - 1];
8610
- return Js(s, Is(e.value)), re(), C(D()), `已回退主数据到历史快照 #${e.id}[${e.op}]。当前值:${$(s, 400)} (hash=${D()})。请基于回退后的值重写或停止。`;
8655
+ return Js(s, Is(e.value)), M(), C(D()), `已回退主数据到历史快照 #${e.id}[${e.op}]。当前值:${$(s, 400)} (hash=${D()})。请基于回退后的值重写或停止。`;
8611
8656
  }
8612
8657
  await i?.reacquire();
8613
8658
  let c = D();
@@ -8641,7 +8686,7 @@ function rd(e, n = {}) {
8641
8686
  hint: "用 history_data({list:true}) 查看可用快照序号"
8642
8687
  });
8643
8688
  let i = o.safeParse(r.value);
8644
- return i.success ? (Js(s, Is(r.value)), re(), P({
8689
+ return i.success ? (Js(s, Is(r.value)), M(), P({
8645
8690
  op: "restore",
8646
8691
  detail: `#${r.id}`,
8647
8692
  timestamp: Date.now()
@@ -8820,7 +8865,7 @@ function rd(e, n = {}) {
8820
8865
  allowKeys: l,
8821
8866
  snapshots: m,
8822
8867
  maxSnapshots: h,
8823
- markDataDirty: re,
8868
+ markDataDirty: M,
8824
8869
  schemaErrorMode: "schema_invalid",
8825
8870
  snapshotLabel: "eval_transform_subtree",
8826
8871
  internalAfterWrite: a,
@@ -8850,7 +8895,7 @@ function rd(e, n = {}) {
8850
8895
  allowKeys: l,
8851
8896
  snapshots: m,
8852
8897
  maxSnapshots: h,
8853
- markDataDirty: re,
8898
+ markDataDirty: M,
8854
8899
  schemaErrorMode: "schema_invalid",
8855
8900
  snapshotLabel: "eval_transform",
8856
8901
  internalAfterWrite: a,
@@ -8888,7 +8933,7 @@ function rd(e, n = {}) {
8888
8933
  value: t,
8889
8934
  bindRef: s
8890
8935
  });
8891
- return e.ok ? (ie("edit", "eval_transform"), e.wholeParsed ? Ys(s, e.assembly) : e.assembly !== null && typeof e.assembly == "object" && Ns(s, e.assembly), re(), P({
8936
+ return e.ok ? (ie("edit", "eval_transform"), e.wholeParsed ? Ys(s, e.assembly) : e.assembly !== null && typeof e.assembly == "object" && Ns(s, e.assembly), M(), P({
8892
8937
  op: "edit",
8893
8938
  detail: "eval_transform",
8894
8939
  timestamp: Date.now()
@@ -9053,11 +9098,11 @@ function rd(e, n = {}) {
9053
9098
  }
9054
9099
  ie("delete");
9055
9100
  let r = Fs(s, t.jsonPath);
9056
- return re(), P({
9101
+ return M(), P({
9057
9102
  op: "delete",
9058
9103
  detail: t.jsonPath,
9059
9104
  timestamp: Date.now()
9060
- }), a && (a(s, null), re()), C(D(), d), r ? `已删除主数据 @ ${t.jsonPath}` : `主数据 @ ${t.jsonPath} 不存在(无需删除)`;
9105
+ }), a && (a(s, null), M()), C(D(), d), r ? `已删除主数据 @ ${t.jsonPath}` : `主数据 @ ${t.jsonPath} 不存在(无需删除)`;
9061
9106
  }
9062
9107
  if (f === "edit") {
9063
9108
  if (typeof s != "object" || !s) return Z({
@@ -9078,7 +9123,7 @@ function rd(e, n = {}) {
9078
9123
  allowKeys: l,
9079
9124
  snapshots: m,
9080
9125
  maxSnapshots: h,
9081
- markDataDirty: re,
9126
+ markDataDirty: M,
9082
9127
  schemaErrorMode: "zod",
9083
9128
  dryRun: c,
9084
9129
  internalAfterWrite: a,
@@ -9108,7 +9153,7 @@ function rd(e, n = {}) {
9108
9153
  maxSnapshots: h,
9109
9154
  audit: P,
9110
9155
  dryRun: c,
9111
- onWrite: re,
9156
+ onWrite: M,
9112
9157
  internalAfterWrite: a,
9113
9158
  protectedCtx: p,
9114
9159
  hashFn: D
@@ -9251,7 +9296,7 @@ function rd(e, n = {}) {
9251
9296
  maxSnapshots: h,
9252
9297
  audit: P,
9253
9298
  op: "draft_commit",
9254
- onWrite: re,
9299
+ onWrite: M,
9255
9300
  internalAfterWrite: a,
9256
9301
  protectedCtx: p,
9257
9302
  hashFn: D
@@ -9337,7 +9382,7 @@ function rd(e, n = {}) {
9337
9382
  details: ei(n.error.issues)
9338
9383
  });
9339
9384
  }
9340
- d.update(i, t), Ps(s, i, t), C(D(), r), re();
9385
+ d.update(i, t), Ps(s, i, t), C(D(), r), M();
9341
9386
  let l = d.get(i)?.handle;
9342
9387
  return `已更新 verbatim 资源 "${e}" = ${$(t, 200)}(handle ${l ?? "(未知)"} 不变)。后续 write 该字段写回句柄 ⟦res:${l}⟧ 或新值`;
9343
9388
  }, {
@@ -9351,14 +9396,22 @@ function rd(e, n = {}) {
9351
9396
  I(n);
9352
9397
  let i = r(async () => {
9353
9398
  let e = d.list();
9354
- return e.length ? $({ resources: e }) : "当前无已注册的受保护资源(read 受保护路径会懒注册)";
9399
+ if (!e.length) {
9400
+ let e = [...p.resourcesByPath.entries()].filter(([, e]) => e.mode === "freeze").map(([e]) => e);
9401
+ return e.length ? `资源池为空,但集成方静态配置了 freeze 只读字段:${e.join("、 ")}(freeze 无句柄、不可释放;resource_delete 仅对 verbatim 生效)` : "当前无已注册的受保护资源(read 受保护路径会懒注册)";
9402
+ }
9403
+ return $({ resources: e });
9355
9404
  }, {
9356
9405
  name: "resource_list",
9357
9406
  description: "列出所有已注册的受保护资源(path/mode/handle/bytes)。",
9358
9407
  schema: t.object({})
9359
9408
  }), a = r(async ({ path: e, handle: t }) => {
9360
9409
  let n = e;
9361
- return !n && t && (n = d.get(t)?.path), n ? d.delete(n) ? `已释放资源 "${n}"(后续 read 该字段会重新懒注册)` : `资源 "${n}" 不存在(无需释放)` : Z({
9410
+ return !n && t && (n = d.get(t)?.path), n ? d.delete(n) ? `已释放资源 "${n}"(后续 read 该字段会重新懒注册)` : p.resourcesByPath.get(n)?.mode === "freeze" ? Z({
9411
+ code: "FROZEN_FIELD",
9412
+ message: `字段 "${n}" 为 freeze 静态保护(不在资源池、无句柄、不可释放)`,
9413
+ hint: "freeze 由集成方在 data.resources 静态配置,只读不可解;含冻结字段的元素无法整体删除,请保留该元素或由集成方调整 data.resources"
9414
+ }) : `资源 "${n}" 不存在(无需释放)` : Z({
9362
9415
  code: "RESOURCE_NOT_FOUND",
9363
9416
  message: "未提供 path 或有效 handle",
9364
9417
  hint: "传要释放的受保护字段 path 或 handle"
@@ -10396,6 +10449,7 @@ ${`- 输出形态:完整、自包含的 HTML 页面(.${r},可独立成页)`}
10396
10449
  - **机械决定一次定**:写法选择(read 回读 vs 复制、vfs 草稿 vs 直写 data、并行 vs 串行)快速选一个,**不在思考里反复权衡 token 成本**(为之纠结反更费 token)。
10397
10450
  - **禁止在思考里整段写出完整代码草稿**:CSS/JS/HTML 代码只写进 write / vfs_write / vfs_edit 工具调用(代码只出现一次);思考里只做高层设计(结构 / 字段 / 方案选择),不要先逐行预写一遍代码再在工具里重复一遍 —— 那会让代码 token 翻倍。
10398
10451
  - **终稿纪律(一次写成)**:动手前要点清单一次定稿(≤10 条:结构 + DOM 分层/z-index + 关键尺寸 + 动画时序),清单齐了**直接在工具调用里写终稿**;① 不先写一版再推翻重写第二版(整段重写 = 代码 token 翻倍,写前多花 30 秒把清单想齐);② 同一几何/层级约束(bottom 定位/遮挡/z-index)**只推演一次**,不重复推导第二遍;③ 写完发现小问题(遮挡/重叠/命名),只改那一处,不重写整段。
10452
+ - **大段 code 分块写(超长代码硬约束)**:预计 code 超过 ~8K 字符时,**一次工具调用装不下会被 max_tokens 掐断** —— 必须分块:① 首块用 write 把组件连同 code 第一段写入(如 code 写到 CSS 中段即止);② 后续每段用 write({op:'append', jsonPath:'${n}.N.${t}', value:'下一段文本'}) 逐块尾接(每块 ≤4K 字符);③ 全部拼完再 validate_code。**禁止**在任何一次调用里塞完整超长代码(截断 = 静默失败重来,token 全废)。
10399
10453
  - **代码字符串不纠结转义**:代码字段(${t})/ content 参数就是普通字符串,直接写完整代码文本(换行、引号照常写),不要纠结「\n」转义、单双引号、字面换行会不会被拒 —— 框架自动序列化,反复权衡纯属浪费 token。
10400
10454
  - 一次想清楚 → 动手 → 验证 → 收口。**思考是手段不是目的,产出代码才是**。
10401
10455
  8. **收口格式(必守,最后一行)**:收口回复 = 简短结果总结 + **末行交接笔记** \`[note] <一句话实现要点>\` —— 关键设计决策 / 用户偏好 / 踩坑(如「[note] 液面用 height keyframes 4.2s 循环;装饰仅灯串+光斑 2 类」)。框架只识别末尾 [note] 行存进组件、自动转交下次维护该组件的子 agent;**漏写 = 下任失去交接**(真 LLM 实测漏写率 3/4,务必末行带上)。一行内,只写可复用结论。`;
@@ -12186,9 +12240,9 @@ function am(e, n) {
12186
12240
  type: "focus_change",
12187
12241
  focuses: e
12188
12242
  })
12189
- }), j = fl(), M = pl(e.memory || "");
12190
- typeof e.memory == "function" && M.refresh();
12191
- let re = { current: null }, N = e.data ? {
12243
+ }), j = fl(), re = pl(e.memory || "");
12244
+ typeof e.memory == "function" && re.refresh();
12245
+ let M = { current: null }, N = e.data ? {
12192
12246
  ...e.data,
12193
12247
  description: e.data.description ?? "主数据对象"
12194
12248
  } : void 0, P = !(e.subagents ?? []).some((e) => e._codeAsset) && Qf(e.capabilities).subagent, ie = e.subagents;
@@ -12205,7 +12259,7 @@ function am(e, n) {
12205
12259
  slotPaths: N ? [""] : [],
12206
12260
  vfsStore: x,
12207
12261
  todosMw: w,
12208
- getTodos: () => re.current?.getState?.()?.todos ?? [],
12262
+ getTodos: () => M.current?.getState?.()?.todos ?? [],
12209
12263
  messages: b,
12210
12264
  maxCheckpoints: le && typeof le == "object" ? le.maxCheckpoints : void 0
12211
12265
  }) : null, de = !le || typeof le != "object" || le.auto !== !1, z = Qf(e.capabilities), B = z.dataOps, fe = z.draftWrite, pe = z.automation, me = cu({
@@ -12554,7 +12608,7 @@ function am(e, n) {
12554
12608
  ...ze ? [j] : [],
12555
12609
  ...ke ? [A] : [],
12556
12610
  ...ge ? [ge] : [],
12557
- ...We ? [M] : [],
12611
+ ...We ? [re] : [],
12558
12612
  ...$e ? [$e] : [],
12559
12613
  ...ue && de && R ? [Ml(R)] : [],
12560
12614
  ...Ee ? [ne] : [],
@@ -12609,7 +12663,7 @@ function am(e, n) {
12609
12663
  vfsStore: x,
12610
12664
  listeners: _t.listeners,
12611
12665
  todosMw: w,
12612
- memoryMw: M,
12666
+ memoryMw: re,
12613
12667
  missionMw: T,
12614
12668
  workingMemoryMw: j,
12615
12669
  focusMw: A,
@@ -12645,7 +12699,7 @@ function am(e, n) {
12645
12699
  K = Ie(), X.agent && X.agent.setTools(K);
12646
12700
  },
12647
12701
  applySnapshot(t) {
12648
- if (t.vfs && x.hydrate && x.hydrate(t.vfs), t.messages?.length && (b.push(..._i(t.messages, (e) => (e ? X.vfsStore?.files?.[e]?.content : void 0) || void 0)), D.markResumed()), t.todos?.length && w.reset(t.todos), t.memory && !e.memory && M.reset(t.memory), t.checkpoints?.length && R && R.importStack(t.checkpoints), t.usage && Object.assign(i, t.usage), t.mission && Re && T.setMission(t.mission), t.workingMemory && ze && j.restore(t.workingMemory), t.planConfirmation && (ee = t.planConfirmation), ke) {
12702
+ if (t.vfs && x.hydrate && x.hydrate(t.vfs), t.messages?.length && (b.push(..._i(t.messages, (e) => (e ? X.vfsStore?.files?.[e]?.content : void 0) || void 0)), D.markResumed()), t.todos?.length && w.reset(t.todos), t.memory && !e.memory && re.reset(t.memory), t.checkpoints?.length && R && R.importStack(t.checkpoints), t.usage && Object.assign(i, t.usage), t.mission && Re && T.setMission(t.mission), t.workingMemory && ze && j.restore(t.workingMemory), t.planConfirmation && (ee = t.planConfirmation), ke) {
12649
12703
  let n = t.focus, r = n ? Array.isArray(n) ? n : [n] : [];
12650
12704
  if (r.length) {
12651
12705
  let t = U()?.schema, n = t ? r.filter((e) => Ro(t, e.path)) : [];
@@ -12881,7 +12935,7 @@ function am(e, n) {
12881
12935
  }
12882
12936
  x.flush?.(), await s.flush();
12883
12937
  let r = t ?? "", i;
12884
- if (r ? (i = await s.load(n, r), i || await s.createSession(n, e.session?.title, r)) : r = await s.createSession(n, e.session?.title), X.sessionId = r, b.splice(0, b.length), x.clear?.(), w.reset([]), e.memory || M.reset(""), T.reset(), j.reset(), A.reset(), D.reset(), ee = void 0, R && R.importStack([]), X.agent.debugLogs.value = [], X.agent.resetStaleReadsInvalidated?.(), !i) try {
12938
+ if (r ? (i = await s.load(n, r), i || await s.createSession(n, e.session?.title, r)) : r = await s.createSession(n, e.session?.title), X.sessionId = r, b.splice(0, b.length), x.clear?.(), w.reset([]), e.memory || re.reset(""), T.reset(), j.reset(), A.reset(), D.reset(), ee = void 0, R && R.importStack([]), X.agent.debugLogs.value = [], X.agent.resetStaleReadsInvalidated?.(), !i) try {
12885
12939
  i = await s.load(n, r);
12886
12940
  } catch (e) {
12887
12941
  J({
@@ -12896,10 +12950,10 @@ function am(e, n) {
12896
12950
  type: "session_restored",
12897
12951
  sessionId: r,
12898
12952
  rounds: i.messages?.length ?? 0
12899
- })), e.memory && Gt({ memory: M.get() || (typeof e.memory == "string" ? e.memory : "") }), jt(), Ht = void 0, Ut = !1, X.infoTick.value++, r;
12953
+ })), e.memory && Gt({ memory: re.get() || (typeof e.memory == "string" ? e.memory : "") }), jt(), Ht = void 0, Ut = !1, X.infoTick.value++, r;
12900
12954
  },
12901
12955
  resetSession: () => {
12902
- Pt(), a.resolve("keep_external"), X.sessionId = Sf(), b.splice(0, b.length), x.clear?.(), w.reset([]), e.memory || M.reset(""), T.reset(), j.reset(), A.reset(), D.reset(), ee = void 0, R && R.importStack([]), X.agent && (X.agent.debugLogs.value = [], X.agent.resetStaleReadsInvalidated?.()), s && s.createSession(X.agentId, e.session?.title, X.sessionId).catch((t) => {
12956
+ Pt(), a.resolve("keep_external"), X.sessionId = Sf(), b.splice(0, b.length), x.clear?.(), w.reset([]), e.memory || re.reset(""), T.reset(), j.reset(), A.reset(), D.reset(), ee = void 0, R && R.importStack([]), X.agent && (X.agent.debugLogs.value = [], X.agent.resetStaleReadsInvalidated?.()), s && s.createSession(X.agentId, e.session?.title, X.sessionId).catch((t) => {
12903
12957
  e.debug && console.warn("[page-agent-sdk][persist] createSession 失败(已吞):", t);
12904
12958
  }), J({
12905
12959
  type: "session_restored",
@@ -12971,10 +13025,10 @@ function am(e, n) {
12971
13025
  X.agent && (X.agent.setLlm(n), X.agent.setModelCaps?.(f)), Tt?.setContextWindow?.(f.contextWindow), pt?.setContextWindow?.(f.contextWindow), X.infoTick.value++, e.debug && console.log("[page-agent-sdk][setLlm] 重解析 modelCaps + 回灌:", f);
12972
13026
  },
12973
13027
  setMemory(e) {
12974
- M.reset(e), typeof e == "function" && M.refresh(), X.infoTick.value++;
13028
+ re.reset(e), typeof e == "function" && re.refresh(), X.infoTick.value++;
12975
13029
  },
12976
13030
  refreshMemory() {
12977
- return M.refresh();
13031
+ return re.refresh();
12978
13032
  },
12979
13033
  setSubagents(t) {
12980
13034
  if (!ct) {
@@ -13027,7 +13081,7 @@ function am(e, n) {
13027
13081
  summaryThresholdRatio: h.summaryThresholdRatio ?? .5,
13028
13082
  promptSoftCap: Fc(f.contextWindow, h.promptSoftCapTokens)
13029
13083
  },
13030
- memory: M.get(),
13084
+ memory: re.get(),
13031
13085
  staleReadsInvalidated: X.agent?.getStaleReadsInvalidated?.() ?? 0,
13032
13086
  middleware: Dt.map((e) => e.name),
13033
13087
  todos: (X.agent?.getState?.()?.todos ?? []).map((e) => ({
@@ -13179,7 +13233,7 @@ function am(e, n) {
13179
13233
  }), e.debug && console.log("[page-agent-sdk][restore] 恢复会话", X.sessionId, `${r.messages?.length ?? 0} msgs`)) : e.debug && console.log("[page-agent-sdk][restore] 会话 meta 存在但快照为空", X.sessionId);
13180
13234
  } else X.sessionId = await s.createSession(n, r.title), e.debug && console.log("[page-agent-sdk][restore] 新建会话(无历史)", X.sessionId);
13181
13235
  } else X.sessionId = await s.createSession(n, r.title);
13182
- e.memory && Gt({ memory: M.get() || (typeof e.memory == "string" ? e.memory : "") }), jt();
13236
+ e.memory && Gt({ memory: re.get() || (typeof e.memory == "string" ? e.memory : "") }), jt();
13183
13237
  }
13184
13238
  async function It() {
13185
13239
  await wt();
@@ -13399,7 +13453,7 @@ function am(e, n) {
13399
13453
  y = e;
13400
13454
  },
13401
13455
  debug: e.debug
13402
- }), re.current = X.agent, st && st.setReconfigureHook && st.setReconfigureHook(() => {
13456
+ }), M.current = X.agent, st && st.setReconfigureHook && st.setReconfigureHook(() => {
13403
13457
  X.agent && X.agent.setTools(Ie());
13404
13458
  });
13405
13459
  })(), X;
@@ -14484,7 +14538,7 @@ function Sm(e = {}) {
14484
14538
  minute: "2-digit"
14485
14539
  }), w = () => {
14486
14540
  let e = T.value;
14487
- !o.value.trim() && !e.length || (r(o.value, M.value, e.length ? [...e] : void 0), o.value = "", T.value = []);
14541
+ !o.value.trim() && !e.length || (r(o.value, re.value, e.length ? [...e] : void 0), o.value = "", T.value = []);
14488
14542
  }, T = /* @__PURE__ */ Lt([]), E = /* @__PURE__ */ Lt(""), D = /* @__PURE__ */ Lt(!1), ee, O = (e) => {
14489
14543
  E.value = e, clearTimeout(ee), ee = setTimeout(() => {
14490
14544
  E.value = "";
@@ -14519,7 +14573,7 @@ function Sm(e = {}) {
14519
14573
  if (!r || r.role !== "assistant") return !1;
14520
14574
  let i = "reasoning" in r ? r.reasoning : void 0, a = "steps" in r ? r.steps : void 0;
14521
14575
  return n.loading && e === t.length - 1 && !r.content && !i && !(a && a.length);
14522
- }, M = Zr(() => (e.infoTick?.value, e.getFocuses?.() ?? [])), re = Zr(() => (e.infoTick?.value, e.getInfo?.()?.planConfirmation)), N = (t) => e.onAddFocus ? e.onAddFocus(t) : {
14576
+ }, re = Zr(() => (e.infoTick?.value, e.getFocuses?.() ?? [])), M = Zr(() => (e.infoTick?.value, e.getInfo?.()?.planConfirmation)), N = (t) => e.onAddFocus ? e.onAddFocus(t) : {
14523
14577
  ok: !1,
14524
14578
  error: "focus 未启用"
14525
14579
  }, P = (t) => {
@@ -14558,8 +14612,8 @@ function Sm(e = {}) {
14558
14612
  compressingImages: D,
14559
14613
  editQueued: A,
14560
14614
  isPendingAssistant: j,
14561
- focuses: M,
14562
- planConfirmation: re,
14615
+ focuses: re,
14616
+ planConfirmation: M,
14563
14617
  addFocus: N,
14564
14618
  removeFocus: P,
14565
14619
  clearFocus: ie,