page-agent-sdk 4.1.0 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ function l(e) {
8
8
  return !!(e == null || typeof e == "string" || e instanceof ArrayBuffer || ArrayBuffer.isView(e) || typeof Blob < "u" && e instanceof Blob || e instanceof URLSearchParams || e instanceof FormData);
9
9
  }
10
10
  function u(e) {
11
- let t = e.model || "gpt-3.5-turbo", r = e.temperature, i = e.maxTokens, a = e.baseUrl;
11
+ let t = e.model || "deepseek-v4-flash", r = e.temperature, i = e.maxTokens, a = e.baseUrl;
12
12
  if (e.mode === "direct") {
13
13
  let o = !1;
14
14
  try {
@@ -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 = "deepseek-v4-flash", 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;
@@ -5215,6 +5215,7 @@ function nc(e) {
5215
5215
  "## 当前精修目标",
5216
5216
  t.map((e) => `· ${e.path}${e.label ? `(${e.label})` : ""}`).join("\n"),
5217
5217
  `仅操作上述 ${t.length} 个聚焦子树${t.length > 1 ? "之一" : ""},用户未指明目标的指令默认作用于聚焦组件(「增加/修改/删除 X」类指令优先理解为对聚焦组件本身的改动 —— 如为其加页签/子项,写焦点路径的子路径;仅用户明确要求新建独立组件时才需解除焦点);不要改动其他组件;${a}`,
5218
+ "用户用指示代词提问(「这是啥/这个/它是干什么的」等)时,所指默认是聚焦目标 —— 先 read 聚焦子树,再围绕聚焦组件回答,勿泛答整页",
5218
5219
  "read 不带路径时默认只返回聚焦子树;需要全量主数据时显式列顶层键(read({jsonPaths:[...]}) )"
5219
5220
  ], r = e.getSchema();
5220
5221
  if (r) {
@@ -7644,47 +7645,63 @@ function Pu(e, t, n, r) {
7644
7645
  hint: "重新 read 该字段触发懒注册重建句柄,再写回新句柄 ⟦res:<handle>⟧"
7645
7646
  };
7646
7647
  }
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;
7648
+ function Fu(e, t, n) {
7649
+ let r = t.getBind();
7650
+ for (let [i, a] of t.resourcesByPath) {
7651
+ let o = Q(r, i), s = Q(e, i);
7652
+ if (s === void 0) {
7653
+ if (o === void 0) continue;
7654
+ let t = i.split(".");
7655
+ if (Q(e, t.length > 1 ? t.slice(0, -1).join(".") : "") !== void 0) {
7656
+ Ps(e, i, o);
7657
+ continue;
7658
+ }
7659
+ if (!(e && typeof e == "object" && t[0] in e)) {
7660
+ if (n) continue;
7661
+ Ps(e, i, o);
7662
+ continue;
7663
+ }
7664
+ return {
7665
+ ok: !1,
7666
+ code: a.mode === "freeze" ? "FROZEN_FIELD" : "VERBATIM_PROTECTED",
7667
+ path: i,
7668
+ message: `整体替换会移除受保护字段 "${i}"(${a.mode}),已拒绝`,
7669
+ hint: a.mode === "freeze" ? "含冻结字段的容器不可整体清空/替换:保留包含该字段的元素(补齐其必填字段,如 type),或逐个 remove 其余元素;彻底移除该字段需集成方调整 data.resources" : "含 verbatim 字段的容器不可整体清空/替换:保留包含该字段的元素,或先 resource_delete({path}) 释放保护后再整体替换"
7670
+ };
7654
7671
  }
7655
- if (i.mode === "freeze") {
7656
- if (o === Tu(r)) {
7657
- Ps(e, r, a);
7672
+ if (a.mode === "freeze") {
7673
+ if (s === Tu(i)) {
7674
+ Ps(e, i, o);
7658
7675
  continue;
7659
7676
  }
7660
- if (!Au(o, a)) return {
7677
+ if (!Au(s, o)) return {
7661
7678
  ok: !1,
7662
7679
  code: "FROZEN_FIELD",
7663
- path: r,
7664
- message: `字段 "${r}" 已冻结(freeze 保护),不可修改`,
7680
+ path: i,
7681
+ message: `字段 "${i}" 已冻结(freeze 保护),不可修改`,
7665
7682
  hint: "该字段由系统/集成方维护,LLM 不得改动。如需展示其值用 resource_get({path}) 取真值"
7666
7683
  };
7667
7684
  } else {
7668
- let n = Du(o);
7685
+ let n = Du(s);
7669
7686
  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);
7687
+ let r = Pu(n.handle, i, o, t.resourceStore);
7688
+ if ("value" in r) {
7689
+ Ps(e, i, r.value);
7673
7690
  continue;
7674
7691
  }
7675
7692
  return {
7676
7693
  ok: !1,
7677
- code: i.code,
7678
- path: r,
7679
- message: i.message,
7680
- hint: i.hint
7694
+ code: r.code,
7695
+ path: i,
7696
+ message: r.message,
7697
+ hint: r.hint
7681
7698
  };
7682
7699
  }
7683
- if (!Au(o, a)) return {
7700
+ if (!Au(s, o)) return {
7684
7701
  ok: !1,
7685
7702
  code: "VERBATIM_MISMATCH",
7686
- path: r,
7687
- message: `字段 "${r}" 为 verbatim 保护(精确原样保留),写入值与原值不符`,
7703
+ path: i,
7704
+ message: `字段 "${i}" 为 verbatim 保护(精确原样保留),写入值与原值不符`,
7688
7705
  hint: "要改该值请先 resource_update({path, value}) 更新资源池,再写回句柄 ⟦res:<handle>⟧;或写回原值(经 resource_get 取到的值)保持不变"
7689
7706
  };
7690
7707
  }
@@ -7705,18 +7722,18 @@ function Iu(e, t, n) {
7705
7722
  });
7706
7723
  }
7707
7724
  function Lu(e) {
7708
- let { value: t, ctx: n } = e;
7725
+ let { value: t, ctx: n, mergeMode: r } = e;
7709
7726
  if (!n || !n.resourcesByPath.size) return {
7710
7727
  ok: !0,
7711
7728
  value: t
7712
7729
  };
7713
- let r = Is(t), i = Fu(r, n);
7714
- return i.ok ? {
7730
+ let i = Is(t), a = Fu(i, n, r);
7731
+ return a.ok ? {
7715
7732
  ok: !0,
7716
- value: r
7733
+ value: i
7717
7734
  } : {
7718
7735
  ok: !1,
7719
- error: Iu(i)
7736
+ error: Iu(a)
7720
7737
  };
7721
7738
  }
7722
7739
  function Ru(e) {
@@ -7935,7 +7952,32 @@ function Wu(e) {
7935
7952
  continue;
7936
7953
  }
7937
7954
  if (i === "append") {
7938
- let e = o[p++]?.elems ?? [];
7955
+ let e = o[p++]?.elems ?? [], r = Q(n, a);
7956
+ if (typeof r == "string" && typeof e[0] == "string") {
7957
+ let n = e[0], i = Vo(t, a);
7958
+ if (i.kind === "missing") return {
7959
+ ok: !1,
7960
+ error: d([a]),
7961
+ writeBacks: [],
7962
+ notices: c
7963
+ };
7964
+ let o = r + n;
7965
+ if (i.kind !== "open") {
7966
+ let e = i.schemas.map((e) => e.safeParse(o)).find((e) => !e.success);
7967
+ if (e) return {
7968
+ ok: !1,
7969
+ error: u(a, e.error?.issues ?? []),
7970
+ writeBacks: [],
7971
+ notices: c
7972
+ };
7973
+ }
7974
+ f.push({
7975
+ op: "appendStr",
7976
+ jp: a,
7977
+ str: n
7978
+ });
7979
+ continue;
7980
+ }
7939
7981
  if (!e.length) {
7940
7982
  f.push({
7941
7983
  op: "appendElems",
@@ -7944,14 +7986,14 @@ function Wu(e) {
7944
7986
  });
7945
7987
  continue;
7946
7988
  }
7947
- let n = Vo(t, a);
7948
- if (n.kind === "missing") return {
7989
+ let i = Vo(t, a);
7990
+ if (i.kind === "missing") return {
7949
7991
  ok: !1,
7950
7992
  error: d([a || "(根)"]),
7951
7993
  writeBacks: [],
7952
7994
  notices: c
7953
7995
  };
7954
- if (n.kind === "open") {
7996
+ if (i.kind === "open") {
7955
7997
  c.push(`${a || "(根)"}=开放节点放行`), f.push({
7956
7998
  op: "appendElems",
7957
7999
  jp: a,
@@ -7959,8 +8001,8 @@ function Wu(e) {
7959
8001
  });
7960
8002
  continue;
7961
8003
  }
7962
- let r = Go(n.schemas);
7963
- if (!r.length) {
8004
+ let s = Go(i.schemas);
8005
+ if (!s.length) {
7964
8006
  c.push(`${a || "(根)"}:目标非 schema 声明数组,元素未校验放行`), f.push({
7965
8007
  op: "appendElems",
7966
8008
  jp: a,
@@ -7968,36 +8010,36 @@ function Wu(e) {
7968
8010
  });
7969
8011
  continue;
7970
8012
  }
7971
- let i = [];
8013
+ let l = [];
7972
8014
  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;
8015
+ let n = [], r, i = !1;
8016
+ for (let a of s) {
8017
+ let o = a.safeParse(e[t]);
8018
+ if (o.success) {
8019
+ i = !0, r = o.data;
7978
8020
  break;
7979
8021
  }
7980
- n.push(...r.error?.issues ?? []);
8022
+ n.push(...o.error?.issues ?? []);
7981
8023
  }
7982
- if (!s) return {
8024
+ if (!i) return {
7983
8025
  ok: !1,
7984
8026
  error: u(`${a || "(根)"}[新增元素${t}]`, n),
7985
8027
  writeBacks: [],
7986
8028
  notices: c
7987
8029
  };
7988
- let l = Xs(void 0, e[t], o, a ? `${a}.${t}` : String(t));
7989
- if (l.length) return {
8030
+ let o = Xs(void 0, e[t], r, a ? `${a}.${t}` : String(t));
8031
+ if (o.length) return {
7990
8032
  ok: !1,
7991
- error: d(l),
8033
+ error: d(o),
7992
8034
  writeBacks: [],
7993
8035
  notices: c
7994
8036
  };
7995
- i.push(o);
8037
+ l.push(r);
7996
8038
  }
7997
8039
  f.push({
7998
8040
  op: "appendElems",
7999
8041
  jp: a,
8000
- elems: i
8042
+ elems: l
8001
8043
  });
8002
8044
  continue;
8003
8045
  }
@@ -8130,7 +8172,8 @@ function Gu(e) {
8130
8172
  if (l) {
8131
8173
  let e = Lu({
8132
8174
  value: d,
8133
- ctx: l
8175
+ ctx: l,
8176
+ mergeMode: !!r
8134
8177
  });
8135
8178
  if (!e.ok) return {
8136
8179
  ok: !1,
@@ -8252,7 +8295,7 @@ function Ku(e) {
8252
8295
  error: Z({
8253
8296
  code: "PATCH_FAILED",
8254
8297
  message: `patches[${e}]: ${c}`,
8255
- hint: "检查 op 与目标类型:merge 需对象,append 需数组"
8298
+ hint: "检查 op 与目标类型:merge 需对象,append 需数组或字符串"
8256
8299
  })
8257
8300
  };
8258
8301
  v(o, a), m.push({
@@ -8309,6 +8352,9 @@ function Ku(e) {
8309
8352
  } else if (e.op === "appendElems") {
8310
8353
  let n = e.jp ? Q(t, e.jp) : t;
8311
8354
  Array.isArray(n) && e.elems?.length && n.push(...e.elems);
8355
+ } else if (e.op === "appendStr") {
8356
+ let n = e.jp ? Q(t, e.jp) : t;
8357
+ typeof n == "string" && typeof e.str == "string" && Ps(t, e.jp, n + e.str);
8312
8358
  }
8313
8359
  return e.internalAfterWrite?.(t, f), s?.(), {
8314
8360
  ok: !0,
@@ -8494,9 +8540,9 @@ function rd(e, n = {}) {
8494
8540
  arrayPath: e.slice(0, t),
8495
8541
  field: e.slice(t + 1)
8496
8542
  } : null;
8497
- }).filter((e) => e !== null), M = !0;
8498
- function re() {
8499
- M = !0;
8543
+ }).filter((e) => e !== null), re = !0;
8544
+ function M() {
8545
+ re = !0;
8500
8546
  }
8501
8547
  let N = {
8502
8548
  get: () => ({
@@ -8505,15 +8551,15 @@ function rd(e, n = {}) {
8505
8551
  description: c
8506
8552
  }),
8507
8553
  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();
8554
+ 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
8555
  },
8510
8556
  update: (e) => {
8511
- s = e, m.length = 0, g.clear(), re();
8557
+ s = e, m.length = 0, g.clear(), M();
8512
8558
  },
8513
- markDataDirty: re,
8559
+ markDataDirty: M,
8514
8560
  consumeDataDirty: () => {
8515
- let e = M;
8516
- return M = !1, e;
8561
+ let e = re;
8562
+ return re = !1, e;
8517
8563
  },
8518
8564
  enterScope: (e) => {
8519
8565
  let t = _;
@@ -8567,7 +8613,7 @@ function rd(e, n = {}) {
8567
8613
  } : void 0,
8568
8614
  updateResource: d ? (e, t) => {
8569
8615
  let n = Ou(e);
8570
- d.update(n, t), Ps(s, n, t), re(), C(D(), "");
8616
+ d.update(n, t), Ps(s, n, t), M(), C(D(), "");
8571
8617
  } : void 0,
8572
8618
  deleteResource: d ? (e) => d.delete(e) : void 0,
8573
8619
  listResources: d ? () => d.list() : void 0
@@ -8607,7 +8653,7 @@ function rd(e, n = {}) {
8607
8653
  if (o.action === "restore") {
8608
8654
  if (await i?.reacquire(), !m.length) return `无历史快照可回退(本次为首次操作)。当前值:${$(s, 400)} (hash=${a})。请重新 read 再改或选「强制覆盖」。`;
8609
8655
  let e = m[m.length - 1];
8610
- return Js(s, Is(e.value)), re(), C(D()), `已回退主数据到历史快照 #${e.id}[${e.op}]。当前值:${$(s, 400)} (hash=${D()})。请基于回退后的值重写或停止。`;
8656
+ return Js(s, Is(e.value)), M(), C(D()), `已回退主数据到历史快照 #${e.id}[${e.op}]。当前值:${$(s, 400)} (hash=${D()})。请基于回退后的值重写或停止。`;
8611
8657
  }
8612
8658
  await i?.reacquire();
8613
8659
  let c = D();
@@ -8641,7 +8687,7 @@ function rd(e, n = {}) {
8641
8687
  hint: "用 history_data({list:true}) 查看可用快照序号"
8642
8688
  });
8643
8689
  let i = o.safeParse(r.value);
8644
- return i.success ? (Js(s, Is(r.value)), re(), P({
8690
+ return i.success ? (Js(s, Is(r.value)), M(), P({
8645
8691
  op: "restore",
8646
8692
  detail: `#${r.id}`,
8647
8693
  timestamp: Date.now()
@@ -8820,7 +8866,7 @@ function rd(e, n = {}) {
8820
8866
  allowKeys: l,
8821
8867
  snapshots: m,
8822
8868
  maxSnapshots: h,
8823
- markDataDirty: re,
8869
+ markDataDirty: M,
8824
8870
  schemaErrorMode: "schema_invalid",
8825
8871
  snapshotLabel: "eval_transform_subtree",
8826
8872
  internalAfterWrite: a,
@@ -8850,7 +8896,7 @@ function rd(e, n = {}) {
8850
8896
  allowKeys: l,
8851
8897
  snapshots: m,
8852
8898
  maxSnapshots: h,
8853
- markDataDirty: re,
8899
+ markDataDirty: M,
8854
8900
  schemaErrorMode: "schema_invalid",
8855
8901
  snapshotLabel: "eval_transform",
8856
8902
  internalAfterWrite: a,
@@ -8888,7 +8934,7 @@ function rd(e, n = {}) {
8888
8934
  value: t,
8889
8935
  bindRef: s
8890
8936
  });
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({
8937
+ 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
8938
  op: "edit",
8893
8939
  detail: "eval_transform",
8894
8940
  timestamp: Date.now()
@@ -9053,11 +9099,11 @@ function rd(e, n = {}) {
9053
9099
  }
9054
9100
  ie("delete");
9055
9101
  let r = Fs(s, t.jsonPath);
9056
- return re(), P({
9102
+ return M(), P({
9057
9103
  op: "delete",
9058
9104
  detail: t.jsonPath,
9059
9105
  timestamp: Date.now()
9060
- }), a && (a(s, null), re()), C(D(), d), r ? `已删除主数据 @ ${t.jsonPath}` : `主数据 @ ${t.jsonPath} 不存在(无需删除)`;
9106
+ }), a && (a(s, null), M()), C(D(), d), r ? `已删除主数据 @ ${t.jsonPath}` : `主数据 @ ${t.jsonPath} 不存在(无需删除)`;
9061
9107
  }
9062
9108
  if (f === "edit") {
9063
9109
  if (typeof s != "object" || !s) return Z({
@@ -9078,7 +9124,7 @@ function rd(e, n = {}) {
9078
9124
  allowKeys: l,
9079
9125
  snapshots: m,
9080
9126
  maxSnapshots: h,
9081
- markDataDirty: re,
9127
+ markDataDirty: M,
9082
9128
  schemaErrorMode: "zod",
9083
9129
  dryRun: c,
9084
9130
  internalAfterWrite: a,
@@ -9108,7 +9154,7 @@ function rd(e, n = {}) {
9108
9154
  maxSnapshots: h,
9109
9155
  audit: P,
9110
9156
  dryRun: c,
9111
- onWrite: re,
9157
+ onWrite: M,
9112
9158
  internalAfterWrite: a,
9113
9159
  protectedCtx: p,
9114
9160
  hashFn: D
@@ -9251,7 +9297,7 @@ function rd(e, n = {}) {
9251
9297
  maxSnapshots: h,
9252
9298
  audit: P,
9253
9299
  op: "draft_commit",
9254
- onWrite: re,
9300
+ onWrite: M,
9255
9301
  internalAfterWrite: a,
9256
9302
  protectedCtx: p,
9257
9303
  hashFn: D
@@ -9337,7 +9383,7 @@ function rd(e, n = {}) {
9337
9383
  details: ei(n.error.issues)
9338
9384
  });
9339
9385
  }
9340
- d.update(i, t), Ps(s, i, t), C(D(), r), re();
9386
+ d.update(i, t), Ps(s, i, t), C(D(), r), M();
9341
9387
  let l = d.get(i)?.handle;
9342
9388
  return `已更新 verbatim 资源 "${e}" = ${$(t, 200)}(handle ${l ?? "(未知)"} 不变)。后续 write 该字段写回句柄 ⟦res:${l}⟧ 或新值`;
9343
9389
  }, {
@@ -9351,14 +9397,22 @@ function rd(e, n = {}) {
9351
9397
  I(n);
9352
9398
  let i = r(async () => {
9353
9399
  let e = d.list();
9354
- return e.length ? $({ resources: e }) : "当前无已注册的受保护资源(read 受保护路径会懒注册)";
9400
+ if (!e.length) {
9401
+ let e = [...p.resourcesByPath.entries()].filter(([, e]) => e.mode === "freeze").map(([e]) => e);
9402
+ return e.length ? `资源池为空,但集成方静态配置了 freeze 只读字段:${e.join("、 ")}(freeze 无句柄、不可释放;resource_delete 仅对 verbatim 生效)` : "当前无已注册的受保护资源(read 受保护路径会懒注册)";
9403
+ }
9404
+ return $({ resources: e });
9355
9405
  }, {
9356
9406
  name: "resource_list",
9357
9407
  description: "列出所有已注册的受保护资源(path/mode/handle/bytes)。",
9358
9408
  schema: t.object({})
9359
9409
  }), a = r(async ({ path: e, handle: t }) => {
9360
9410
  let n = e;
9361
- return !n && t && (n = d.get(t)?.path), n ? d.delete(n) ? `已释放资源 "${n}"(后续 read 该字段会重新懒注册)` : `资源 "${n}" 不存在(无需释放)` : Z({
9411
+ return !n && t && (n = d.get(t)?.path), n ? d.delete(n) ? `已释放资源 "${n}"(后续 read 该字段会重新懒注册)` : p.resourcesByPath.get(n)?.mode === "freeze" ? Z({
9412
+ code: "FROZEN_FIELD",
9413
+ message: `字段 "${n}" 为 freeze 静态保护(不在资源池、无句柄、不可释放)`,
9414
+ hint: "freeze 由集成方在 data.resources 静态配置,只读不可解;含冻结字段的元素无法整体删除,请保留该元素或由集成方调整 data.resources"
9415
+ }) : `资源 "${n}" 不存在(无需释放)` : Z({
9362
9416
  code: "RESOURCE_NOT_FOUND",
9363
9417
  message: "未提供 path 或有效 handle",
9364
9418
  hint: "传要释放的受保护字段 path 或 handle"
@@ -10396,6 +10450,7 @@ ${`- 输出形态:完整、自包含的 HTML 页面(.${r},可独立成页)`}
10396
10450
  - **机械决定一次定**:写法选择(read 回读 vs 复制、vfs 草稿 vs 直写 data、并行 vs 串行)快速选一个,**不在思考里反复权衡 token 成本**(为之纠结反更费 token)。
10397
10451
  - **禁止在思考里整段写出完整代码草稿**:CSS/JS/HTML 代码只写进 write / vfs_write / vfs_edit 工具调用(代码只出现一次);思考里只做高层设计(结构 / 字段 / 方案选择),不要先逐行预写一遍代码再在工具里重复一遍 —— 那会让代码 token 翻倍。
10398
10452
  - **终稿纪律(一次写成)**:动手前要点清单一次定稿(≤10 条:结构 + DOM 分层/z-index + 关键尺寸 + 动画时序),清单齐了**直接在工具调用里写终稿**;① 不先写一版再推翻重写第二版(整段重写 = 代码 token 翻倍,写前多花 30 秒把清单想齐);② 同一几何/层级约束(bottom 定位/遮挡/z-index)**只推演一次**,不重复推导第二遍;③ 写完发现小问题(遮挡/重叠/命名),只改那一处,不重写整段。
10453
+ - **大段 code 分块写(超长代码硬约束)**:预计 code 超过 ~8K 字符时,**一次工具调用装不下会被 max_tokens 掐断** —— 必须分块:① 首块用 write 把组件连同 code 第一段写入(如 code 写到 CSS 中段即止);② 后续每段用 write({op:'append', jsonPath:'${n}.N.${t}', value:'下一段文本'}) 逐块尾接(每块 ≤4K 字符);③ 全部拼完再 validate_code。**禁止**在任何一次调用里塞完整超长代码(截断 = 静默失败重来,token 全废)。
10399
10454
  - **代码字符串不纠结转义**:代码字段(${t})/ content 参数就是普通字符串,直接写完整代码文本(换行、引号照常写),不要纠结「\n」转义、单双引号、字面换行会不会被拒 —— 框架自动序列化,反复权衡纯属浪费 token。
10400
10455
  - 一次想清楚 → 动手 → 验证 → 收口。**思考是手段不是目的,产出代码才是**。
10401
10456
  8. **收口格式(必守,最后一行)**:收口回复 = 简短结果总结 + **末行交接笔记** \`[note] <一句话实现要点>\` —— 关键设计决策 / 用户偏好 / 踩坑(如「[note] 液面用 height keyframes 4.2s 循环;装饰仅灯串+光斑 2 类」)。框架只识别末尾 [note] 行存进组件、自动转交下次维护该组件的子 agent;**漏写 = 下任失去交接**(真 LLM 实测漏写率 3/4,务必末行带上)。一行内,只写可复用结论。`;
@@ -12186,9 +12241,9 @@ function am(e, n) {
12186
12241
  type: "focus_change",
12187
12242
  focuses: e
12188
12243
  })
12189
- }), j = fl(), M = pl(e.memory || "");
12190
- typeof e.memory == "function" && M.refresh();
12191
- let re = { current: null }, N = e.data ? {
12244
+ }), j = fl(), re = pl(e.memory || "");
12245
+ typeof e.memory == "function" && re.refresh();
12246
+ let M = { current: null }, N = e.data ? {
12192
12247
  ...e.data,
12193
12248
  description: e.data.description ?? "主数据对象"
12194
12249
  } : void 0, P = !(e.subagents ?? []).some((e) => e._codeAsset) && Qf(e.capabilities).subagent, ie = e.subagents;
@@ -12205,7 +12260,7 @@ function am(e, n) {
12205
12260
  slotPaths: N ? [""] : [],
12206
12261
  vfsStore: x,
12207
12262
  todosMw: w,
12208
- getTodos: () => re.current?.getState?.()?.todos ?? [],
12263
+ getTodos: () => M.current?.getState?.()?.todos ?? [],
12209
12264
  messages: b,
12210
12265
  maxCheckpoints: le && typeof le == "object" ? le.maxCheckpoints : void 0
12211
12266
  }) : 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 +12609,7 @@ function am(e, n) {
12554
12609
  ...ze ? [j] : [],
12555
12610
  ...ke ? [A] : [],
12556
12611
  ...ge ? [ge] : [],
12557
- ...We ? [M] : [],
12612
+ ...We ? [re] : [],
12558
12613
  ...$e ? [$e] : [],
12559
12614
  ...ue && de && R ? [Ml(R)] : [],
12560
12615
  ...Ee ? [ne] : [],
@@ -12609,7 +12664,7 @@ function am(e, n) {
12609
12664
  vfsStore: x,
12610
12665
  listeners: _t.listeners,
12611
12666
  todosMw: w,
12612
- memoryMw: M,
12667
+ memoryMw: re,
12613
12668
  missionMw: T,
12614
12669
  workingMemoryMw: j,
12615
12670
  focusMw: A,
@@ -12645,7 +12700,7 @@ function am(e, n) {
12645
12700
  K = Ie(), X.agent && X.agent.setTools(K);
12646
12701
  },
12647
12702
  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) {
12703
+ 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
12704
  let n = t.focus, r = n ? Array.isArray(n) ? n : [n] : [];
12650
12705
  if (r.length) {
12651
12706
  let t = U()?.schema, n = t ? r.filter((e) => Ro(t, e.path)) : [];
@@ -12881,7 +12936,7 @@ function am(e, n) {
12881
12936
  }
12882
12937
  x.flush?.(), await s.flush();
12883
12938
  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 {
12939
+ 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
12940
  i = await s.load(n, r);
12886
12941
  } catch (e) {
12887
12942
  J({
@@ -12896,10 +12951,10 @@ function am(e, n) {
12896
12951
  type: "session_restored",
12897
12952
  sessionId: r,
12898
12953
  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;
12954
+ })), e.memory && Gt({ memory: re.get() || (typeof e.memory == "string" ? e.memory : "") }), jt(), Ht = void 0, Ut = !1, X.infoTick.value++, r;
12900
12955
  },
12901
12956
  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) => {
12957
+ 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
12958
  e.debug && console.warn("[page-agent-sdk][persist] createSession 失败(已吞):", t);
12904
12959
  }), J({
12905
12960
  type: "session_restored",
@@ -12971,10 +13026,10 @@ function am(e, n) {
12971
13026
  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
13027
  },
12973
13028
  setMemory(e) {
12974
- M.reset(e), typeof e == "function" && M.refresh(), X.infoTick.value++;
13029
+ re.reset(e), typeof e == "function" && re.refresh(), X.infoTick.value++;
12975
13030
  },
12976
13031
  refreshMemory() {
12977
- return M.refresh();
13032
+ return re.refresh();
12978
13033
  },
12979
13034
  setSubagents(t) {
12980
13035
  if (!ct) {
@@ -13027,7 +13082,7 @@ function am(e, n) {
13027
13082
  summaryThresholdRatio: h.summaryThresholdRatio ?? .5,
13028
13083
  promptSoftCap: Fc(f.contextWindow, h.promptSoftCapTokens)
13029
13084
  },
13030
- memory: M.get(),
13085
+ memory: re.get(),
13031
13086
  staleReadsInvalidated: X.agent?.getStaleReadsInvalidated?.() ?? 0,
13032
13087
  middleware: Dt.map((e) => e.name),
13033
13088
  todos: (X.agent?.getState?.()?.todos ?? []).map((e) => ({
@@ -13179,7 +13234,7 @@ function am(e, n) {
13179
13234
  }), 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
13235
  } else X.sessionId = await s.createSession(n, r.title), e.debug && console.log("[page-agent-sdk][restore] 新建会话(无历史)", X.sessionId);
13181
13236
  } else X.sessionId = await s.createSession(n, r.title);
13182
- e.memory && Gt({ memory: M.get() || (typeof e.memory == "string" ? e.memory : "") }), jt();
13237
+ e.memory && Gt({ memory: re.get() || (typeof e.memory == "string" ? e.memory : "") }), jt();
13183
13238
  }
13184
13239
  async function It() {
13185
13240
  await wt();
@@ -13399,7 +13454,7 @@ function am(e, n) {
13399
13454
  y = e;
13400
13455
  },
13401
13456
  debug: e.debug
13402
- }), re.current = X.agent, st && st.setReconfigureHook && st.setReconfigureHook(() => {
13457
+ }), M.current = X.agent, st && st.setReconfigureHook && st.setReconfigureHook(() => {
13403
13458
  X.agent && X.agent.setTools(Ie());
13404
13459
  });
13405
13460
  })(), X;
@@ -14484,7 +14539,7 @@ function Sm(e = {}) {
14484
14539
  minute: "2-digit"
14485
14540
  }), w = () => {
14486
14541
  let e = T.value;
14487
- !o.value.trim() && !e.length || (r(o.value, M.value, e.length ? [...e] : void 0), o.value = "", T.value = []);
14542
+ !o.value.trim() && !e.length || (r(o.value, re.value, e.length ? [...e] : void 0), o.value = "", T.value = []);
14488
14543
  }, T = /* @__PURE__ */ Lt([]), E = /* @__PURE__ */ Lt(""), D = /* @__PURE__ */ Lt(!1), ee, O = (e) => {
14489
14544
  E.value = e, clearTimeout(ee), ee = setTimeout(() => {
14490
14545
  E.value = "";
@@ -14519,7 +14574,7 @@ function Sm(e = {}) {
14519
14574
  if (!r || r.role !== "assistant") return !1;
14520
14575
  let i = "reasoning" in r ? r.reasoning : void 0, a = "steps" in r ? r.steps : void 0;
14521
14576
  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) : {
14577
+ }, re = Zr(() => (e.infoTick?.value, e.getFocuses?.() ?? [])), M = Zr(() => (e.infoTick?.value, e.getInfo?.()?.planConfirmation)), N = (t) => e.onAddFocus ? e.onAddFocus(t) : {
14523
14578
  ok: !1,
14524
14579
  error: "focus 未启用"
14525
14580
  }, P = (t) => {
@@ -14558,8 +14613,8 @@ function Sm(e = {}) {
14558
14613
  compressingImages: D,
14559
14614
  editQueued: A,
14560
14615
  isPendingAssistant: j,
14561
- focuses: M,
14562
- planConfirmation: re,
14616
+ focuses: re,
14617
+ planConfirmation: M,
14563
14618
  addFocus: N,
14564
14619
  removeFocus: P,
14565
14620
  clearFocus: ie,