page-agent-sdk 3.43.0 → 3.43.2

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.
@@ -54732,7 +54732,7 @@ function tQ(e = [], t = {}) {
54732
54732
  name: "todos",
54733
54733
  tools: [yF(async ({ todos: e }) => {
54734
54734
  if (!o) o = !0, s = 1;
54735
- else if (s > c) return `规划阶段已达上限(${c} 轮,现在已是第 ${s} 版计划)。停止调研/修订,基于当前清单开始执行(用 write 落地;advanced 模式亦可用 set_data/edit_data)。当前清单:\n${r.map((e, t) => `${t + 1}. #${e.id} [${e.status}] ${e.content}`).join("\n") || "(空)"}`;
54735
+ else if (s++, s > c) return `规划阶段已达上限(${c} 次修订,现在已是第 ${s} 版计划)。停止修订,基于当前清单开始执行(用 write 落地;advanced 模式亦可用 set_data/edit_data)。当前清单:\n${r.map((e, t) => `${t + 1}. #${e.id} [${e.status}] ${e.content}`).join("\n") || "(空)"}`;
54736
54736
  return r = eQ(e), `已更新任务清单:${r.length} 项\n${r.map((e, t) => `${t + 1}. #${e.id} [${e.status}] ${e.content}`).join("\n")}`;
54737
54737
  }, {
54738
54738
  name: "write_todos",
@@ -54751,7 +54751,7 @@ function tQ(e = [], t = {}) {
54751
54751
  evidence: z().optional().describe("完成证据(可选)")
54752
54752
  })).describe("完整的任务清单(整表替换)") })
54753
54753
  }), yF(async ({ id: e, content: t, status: n, parentId: i, deps: a, criteria: l, evidence: u }) => {
54754
- if (o && s > c) return `规划阶段已达上限(${c} 轮,现在已是第 ${s} 版计划)。停止修订,基于当前清单开始执行。当前任务 id:${r.map((e) => e.id).join(", ") || "(空)"}`;
54754
+ if (o && s > c && (t !== void 0 || i !== void 0 || a !== void 0 || l !== void 0)) return `规划阶段已达上限(${c} 次修订,现在已是第 ${s} 版计划)。停止修订计划内容(改任务文本/层级/依赖);status/evidence 进度跟踪可继续,或基于当前清单开始执行。当前任务 id:${r.map((e) => e.id).join(", ") || "(空)"}`;
54755
54755
  let d = r.findIndex((t) => t.id === e);
54756
54756
  return d < 0 ? `错误:找不到 id="${e}" 的任务(TODO_NOT_FOUND)。当前任务 id:${r.map((e) => e.id).join(", ") || "(空)"}` : (t !== void 0 && (r[d].content = t), n !== void 0 && (r[d].status = n), i !== void 0 && (r[d].parentId = i), a !== void 0 && (r[d].deps = a), l !== void 0 && (r[d].criteria = l), u !== void 0 && (r[d].evidence = u), `已更新任务 #${e}:[${r[d].status}] ${r[d].content}`);
54757
54757
  }, {
@@ -54772,7 +54772,7 @@ function tQ(e = [], t = {}) {
54772
54772
  })
54773
54773
  })],
54774
54774
  beforeAgent: () => ({ todos: r }),
54775
- beforeModel: () => (i = 0, a = 0, o && s++, { todos: r }),
54775
+ beforeModel: () => (i = 0, a = 0, { todos: r }),
54776
54776
  augmentPrompt: () => $Se(r),
54777
54777
  wrapToolCall: async (e, t) => {
54778
54778
  if (e.name === "write_todos" || e.name === "update_todo") {
@@ -55697,43 +55697,46 @@ function OQ(e) {
55697
55697
  temperature: s,
55698
55698
  maxTokens: ee,
55699
55699
  configuration: j(j({}, a ? { baseURL: YG(a) } : {}), {}, { fetch: JG }, u)
55700
- }, l ? { modelKwargs: l } : {})) : t, de = ue.length > 0 ? (n = (r = I.bindTools) == null ? void 0 : r.call(I, ue)) == null ? I : n : I;
55701
- function fe() {
55700
+ }, l ? { modelKwargs: l } : {})) : t, de = ue.length > 0 ? (n = (r = I.bindTools) == null ? void 0 : r.call(I, ue)) == null ? I : n : I, fe = () => {
55701
+ let e = I;
55702
+ return (typeof e.model == "string" && e.model ? e.model : typeof e.modelName == "string" && e.modelName ? e.modelName : "") || o;
55703
+ };
55704
+ function pe() {
55702
55705
  var e, t;
55703
55706
  de = ue.length > 0 ? (e = (t = I.bindTools) == null ? void 0 : t.call(I, ue)) == null ? I : e : I;
55704
55707
  }
55705
- let pe = GZ();
55706
- e.__pgIsSubagent && (pe.__pgIsSubagent = !0);
55707
- let me = .25, he = /* @__PURE__ */ new Set([
55708
+ let me = GZ();
55709
+ e.__pgIsSubagent && (me.__pgIsSubagent = !0);
55710
+ let he = .25, ge = /* @__PURE__ */ new Set([
55708
55711
  "mission",
55709
55712
  "workingMemory",
55710
55713
  "intentGuard",
55711
55714
  "resumeNotice"
55712
55715
  ]);
55713
- function ge() {
55716
+ function _e() {
55714
55717
  let e = d || "你是一个智能助手。", t = [];
55715
55718
  for (let e of p) if (e.augmentPrompt) {
55716
- let n = e.augmentPrompt(pe);
55719
+ let n = e.augmentPrompt(me);
55717
55720
  n && t.push({
55718
55721
  name: e.name,
55719
55722
  text: n,
55720
55723
  tokens: VZ(n),
55721
- pin: he.has(e.name)
55724
+ pin: ge.has(e.name)
55722
55725
  });
55723
55726
  }
55724
- let n = Math.max(2e3, Math.round(M.contextWindow * me)), r = VZ(e) + t.reduce((e, t) => e + t.tokens, 0);
55727
+ let n = Math.max(2e3, Math.round(M.contextWindow * he)), r = VZ(e) + t.reduce((e, t) => e + t.tokens, 0);
55725
55728
  if (r > n) {
55726
55729
  let e = r, i = [];
55727
55730
  for (let e of t.filter((e) => !e.pin).sort((e, t) => t.tokens - e.tokens)) {
55728
55731
  if (r <= n) break;
55729
55732
  i.push(`${e.name}(${e.tokens})`), r -= e.tokens, e.text = "";
55730
55733
  }
55731
- i.length && console.warn(`[page-agent-sdk] 系统段超预算(${e} > ${n} tokens,窗口 ${M.contextWindow} 的 ${me * 100}%),drop 非核心段:${i.join(", ")}(保 base/mission/workingMemory)`);
55734
+ i.length && console.warn(`[page-agent-sdk] 系统段超预算(${e} > ${n} tokens,窗口 ${M.contextWindow} 的 ${he * 100}%),drop 非核心段:${i.join(", ")}(保 base/mission/workingMemory)`);
55732
55735
  }
55733
55736
  return [e, ...t.filter((e) => e.text).map((e) => e.text)].join("\n\n");
55734
55737
  }
55735
- function _e(e) {
55736
- let t = [new eb(ge())];
55738
+ function ve(e) {
55739
+ let t = [new eb(_e())];
55737
55740
  for (let i of e) if (i.role === "user") {
55738
55741
  var n, r;
55739
55742
  let e = M.vision && (n = i.images) != null && n.length ? NSe(i.content, i.images, D) : null;
@@ -55741,11 +55744,11 @@ function OQ(e) {
55741
55744
  } else i.role === "assistant" ? t.push(new mb(i.content)) : i.role === "system" && t.push(new eb(i.content));
55742
55745
  return t;
55743
55746
  }
55744
- function ve(e, t) {
55745
- let n = e[0] && xe(e[0]) === "system" ? e.slice(1) : e.slice(), r = ge();
55747
+ function ye(e, t) {
55748
+ let n = e[0] && Se(e[0]) === "system" ? e.slice(1) : e.slice(), r = _e();
55746
55749
  return [new eb(t ? `${r}\n\n${t}` : r), ...n];
55747
55750
  }
55748
- async function ye(e, t, n, r) {
55751
+ async function be(e, t, n, r) {
55749
55752
  let i = r == null ? de : r, a = {
55750
55753
  signal: n,
55751
55754
  maxRetries: g,
@@ -55785,14 +55788,14 @@ function OQ(e) {
55785
55788
  };
55786
55789
  if ($Z(i) && !e._ctxRetry) {
55787
55790
  e._ctxRetry = !0;
55788
- let i = (e) => VZ(typeof e.content == "string" ? e.content : JSON.stringify(e.content)), a = e.messages.reduce((e, t) => e + i(t), 0), o = Se(e.messages, Math.round(M.contextWindow * .3)), s = o.reduce((e, t) => e + i(t), 0);
55791
+ let i = (e) => VZ(typeof e.content == "string" ? e.content : JSON.stringify(e.content)), a = e.messages.reduce((e, t) => e + i(t), 0), o = Ce(e.messages, Math.round(M.contextWindow * .3)), s = o.reduce((e, t) => e + i(t), 0);
55789
55792
  return ie("error", {
55790
55793
  stage: "context_overflow_retry",
55791
55794
  at: "launch",
55792
55795
  beforeTokens: a,
55793
55796
  afterTokens: s,
55794
55797
  window: M.contextWindow
55795
- }), console.warn(`[page-agent-sdk] 上下文超限(启动)→ 激进 trim 重试:${a} → ${s} tokens`), ye(j(j({}, e), {}, { messages: o }), t, n, r);
55798
+ }), console.warn(`[page-agent-sdk] 上下文超限(启动)→ 激进 trim 重试:${a} → ${s} tokens`), be(j(j({}, e), {}, { messages: o }), t, n, r);
55796
55799
  }
55797
55800
  throw i;
55798
55801
  }
@@ -55849,13 +55852,13 @@ function OQ(e) {
55849
55852
  }
55850
55853
  if ($Z(i) && c === null && l === "" && !e._ctxRetry) {
55851
55854
  e._ctxRetry = !0;
55852
- let i = (e) => VZ(typeof e.content == "string" ? e.content : JSON.stringify(e.content)), a = e.messages.reduce((e, t) => e + i(t), 0), o = Se(e.messages, Math.round(M.contextWindow * .3)), s = o.reduce((e, t) => e + i(t), 0);
55855
+ let i = (e) => VZ(typeof e.content == "string" ? e.content : JSON.stringify(e.content)), a = e.messages.reduce((e, t) => e + i(t), 0), o = Ce(e.messages, Math.round(M.contextWindow * .3)), s = o.reduce((e, t) => e + i(t), 0);
55853
55856
  return ie("error", {
55854
55857
  stage: "context_overflow_retry",
55855
55858
  beforeTokens: a,
55856
55859
  afterTokens: s,
55857
55860
  window: M.contextWindow
55858
- }), console.warn(`[page-agent-sdk] 上下文超限 → 激进 trim 重试:${a} → ${s} tokens(窗口 ${M.contextWindow})`), ye(j(j({}, e), {}, { messages: o }), t, n, r);
55861
+ }), console.warn(`[page-agent-sdk] 上下文超限 → 激进 trim 重试:${a} → ${s} tokens(窗口 ${M.contextWindow})`), be(j(j({}, e), {}, { messages: o }), t, n, r);
55859
55862
  }
55860
55863
  throw i;
55861
55864
  }
@@ -55863,7 +55866,7 @@ function OQ(e) {
55863
55866
  if (!e._emptyRetry) return e._emptyRetry = !0, ie("error", {
55864
55867
  stage: "empty_llm_response_retry",
55865
55868
  hint: "流正常结束但零 chunk(网关 200+错误体形态),自动重试 1 次"
55866
- }), ye(e, t, n, r);
55869
+ }), be(e, t, n, r);
55867
55870
  throw ie("error", {
55868
55871
  stage: "empty_llm_response",
55869
55872
  retried: !0,
@@ -55877,7 +55880,7 @@ function OQ(e) {
55877
55880
  content: l
55878
55881
  };
55879
55882
  }
55880
- async function be(e) {
55883
+ async function xe(e) {
55881
55884
  let t = ue.find((t) => t.name === e.name);
55882
55885
  if (!t) return {
55883
55886
  content: `工具 "${e.name}" 不存在`,
@@ -55903,15 +55906,15 @@ function OQ(e) {
55903
55906
  };
55904
55907
  }
55905
55908
  }
55906
- function xe(e) {
55909
+ function Se(e) {
55907
55910
  return e instanceof Yy ? "human" : e instanceof mb ? "ai" : e instanceof eb ? "system" : e instanceof my ? "tool" : "unknown";
55908
55911
  }
55909
- function Se(e, t) {
55912
+ function Ce(e, t) {
55910
55913
  return XCe(e, t);
55911
55914
  }
55912
- function Ce(e) {
55915
+ function we(e) {
55913
55916
  return !k && !C ? [] : e.map((e) => {
55914
- let t = xe(e), n = { role: t === "human" ? "user" : t === "ai" ? "assistant" : t }, r = typeof e.content == "string" ? e.content : JSON.stringify(e.content);
55917
+ let t = Se(e), n = { role: t === "human" ? "user" : t === "ai" ? "assistant" : t }, r = typeof e.content == "string" ? e.content : JSON.stringify(e.content);
55915
55918
  r && (n.content = r.length > TQ ? r.slice(0, TQ) + `…(截断 ${r.length - TQ} 字符)` : r);
55916
55919
  let i = e.tool_calls;
55917
55920
  Array.isArray(i) && i.length && (n.tool_calls = i.map((e) => ({
@@ -55926,17 +55929,17 @@ function OQ(e) {
55926
55929
  return a && (n.tool_call_id = a), n;
55927
55930
  });
55928
55931
  }
55929
- async function we(t, n, r) {
55930
- oe.value = [], se = 0, pe = GZ(), e.__pgIsSubagent && (pe.__pgIsSubagent = !0), pe.messages = t, pe = await FCe(p, pe);
55932
+ async function Te(t, n, r) {
55933
+ oe.value = [], se = 0, me = GZ(), e.__pgIsSubagent && (me.__pgIsSubagent = !0), me.messages = t, me = await FCe(p, me);
55931
55934
  let i = t;
55932
55935
  for (let e of p) if (e.compressInput) {
55933
55936
  let t = F(void 0, "compression", `compress:${e.name}`, {}), n = await e.compressInput(i);
55934
- i = Array.isArray(n) ? n : n.messages, n && !Array.isArray(n) && n.stats ? (pe = j(j({}, pe), {}, { lastCompression: n.stats }), le(t, "ok", { stats: n.stats })) : le(t);
55937
+ i = Array.isArray(n) ? n : n.messages, n && !Array.isArray(n) && n.stats ? (me = j(j({}, me), {}, { lastCompression: n.stats }), le(t, "ok", { stats: n.stats })) : le(t);
55935
55938
  }
55936
55939
  {
55937
- let e = VZ(d || "你是一个智能助手。"), t = Math.max(2e3, Math.round(M.contextWindow * me));
55940
+ let e = VZ(d || "你是一个智能助手。"), t = Math.max(2e3, Math.round(M.contextWindow * he));
55938
55941
  if (e > t) {
55939
- let r = `[page-agent-sdk] systemPrompt 本身(${e} tokens)超过系统段预算(${t} tokens,窗口 ${M.contextWindow} 的 ${me * 100}%);请缩减 systemPrompt 或换更大窗口模型`;
55942
+ let r = `[page-agent-sdk] systemPrompt 本身(${e} tokens)超过系统段预算(${t} tokens,窗口 ${M.contextWindow} 的 ${he * 100}%);请缩减 systemPrompt 或换更大窗口模型`;
55940
55943
  return console.error(r), n({
55941
55944
  type: "error",
55942
55945
  message: r,
@@ -55948,13 +55951,13 @@ function OQ(e) {
55948
55951
  }), "";
55949
55952
  }
55950
55953
  }
55951
- let a = _e(i);
55954
+ let a = ve(i);
55952
55955
  ie("context", {
55953
- model: o,
55956
+ model: fe(),
55954
55957
  tools: ue.map((e) => e.name),
55955
55958
  middleware: p.map((e) => e.name)
55956
55959
  });
55957
- let s = bQ(p, (e) => ye(e, n, r)), c = zCe(p, be), l = {
55960
+ let o = bQ(p, (e) => be(e, n, r)), s = zCe(p, xe), c = {
55958
55961
  rounds: 0,
55959
55962
  maxToolRounds: A,
55960
55963
  invokeUsage: {
@@ -55965,33 +55968,33 @@ function OQ(e) {
55965
55968
  writeFailures: {},
55966
55969
  budgetHinted: !1
55967
55970
  };
55968
- pe.loopProgress = l;
55969
- let u = {
55971
+ me.loopProgress = c;
55972
+ let l = {
55970
55973
  counts: {},
55971
55974
  writePaths: [],
55972
55975
  failures: 0
55973
- }, f = 0, m = (e) => {
55976
+ }, u = 0, f = (e) => {
55974
55977
  let t = ue.find((t) => t.name === e);
55975
55978
  return t && "writeCapable" in t ? typeof t.writeCapable == "function" || t.writeCapable === !0 : EQ.has(e);
55976
- }, g = 0, _ = 0, v = ZCe(A, h), y = null, C = 0, w = !1, E = 0, D = 0;
55979
+ }, m = 0, g = 0, _ = ZCe(A, h), v = null, y = 0, C = !1, w = 0, E = 0;
55977
55980
  try {
55978
- for (; (g < A || w) && _ < v;) {
55979
- var k;
55980
- if (_++, r != null && r.aborted) break;
55981
- if (S > 0 && l.invokeUsage.total_tokens > S) {
55982
- let e = `本轮 token 预算(约 ${S})已用尽:任务在 ${g} 轮工具调用后中断,已完成的部分均保留。可继续对话,指定下一步(如「继续完成」/「只改 X」/「提高预算重试」)。`;
55981
+ for (; (m < A || C) && g < _;) {
55982
+ var D;
55983
+ if (g++, r != null && r.aborted) break;
55984
+ if (S > 0 && c.invokeUsage.total_tokens > S) {
55985
+ let e = `本轮 token 预算(约 ${S})已用尽:任务在 ${m} 轮工具调用后中断,已完成的部分均保留。可继续对话,指定下一步(如「继续完成」/「只改 X」/「提高预算重试」)。`;
55983
55986
  return ie("error", {
55984
55987
  stage: "round_token_budget_exceeded",
55985
- used: l.invokeUsage.total_tokens,
55988
+ used: c.invokeUsage.total_tokens,
55986
55989
  budget: S,
55987
- rounds: g
55990
+ rounds: m
55988
55991
  }), n({
55989
55992
  type: "error",
55990
55993
  message: e,
55991
55994
  severity: "observable",
55992
55995
  code: "ROUND_TOKEN_BUDGET_EXCEEDED",
55993
55996
  context: {
55994
- used: l.invokeUsage.total_tokens,
55997
+ used: c.invokeUsage.total_tokens,
55995
55998
  budget: S
55996
55999
  }
55997
56000
  }), n({
@@ -55999,41 +56002,41 @@ function OQ(e) {
55999
56002
  content: e
56000
56003
  }), e;
56001
56004
  }
56002
- let e = (k = F(void 0, "round", `round ${_}`, { round: _ })) == null ? void 0 : k.id;
56005
+ let e = (D = F(void 0, "round", `round ${g}`, { round: g })) == null ? void 0 : D.id;
56003
56006
  n({
56004
56007
  type: "round_start",
56005
- round: _
56006
- }), pe = ICe(p, {
56008
+ round: g
56009
+ }), me = ICe(p, {
56007
56010
  messages: a,
56008
- state: pe
56009
- }), a = ve(a, QCe(g, A)), a = Se(a, Math.round(M.contextWindow * .6));
56010
- let t = F(e, "model", o, {
56011
- round: g + 1,
56011
+ state: me
56012
+ }), a = ye(a, QCe(m, A)), a = Ce(a, Math.round(M.contextWindow * .6));
56013
+ let t = F(e, "model", fe(), {
56014
+ round: m + 1,
56012
56015
  tools: ue.map((e) => e.name)
56013
56016
  });
56014
56017
  ie("llm_request", {
56015
- round: g + 1,
56016
- model: o,
56018
+ round: m + 1,
56019
+ model: fe(),
56017
56020
  tools: ue.map((e) => e.name),
56018
- messages: Ce(a)
56021
+ messages: we(a)
56019
56022
  });
56020
- let i = await s({
56023
+ let i = await o({
56021
56024
  messages: a,
56022
- state: pe
56025
+ state: me
56023
56026
  });
56024
56027
  a.push(i.message), ie("llm_response", {
56025
- round: g + 1,
56028
+ round: m + 1,
56026
56029
  content: i.content,
56027
56030
  toolCalls: i.toolCalls
56028
56031
  }), le(t, i.aborted ? "timeout" : "ok", { usage: eK(i.message) });
56029
56032
  {
56030
56033
  let e = tK(i.message);
56031
56034
  if (e) {
56032
- var ee, te, N;
56033
- l.invokeUsage.prompt_tokens += (ee = e.prompt_tokens) == null ? 0 : ee, l.invokeUsage.completion_tokens += (te = e.completion_tokens) == null ? 0 : te, l.invokeUsage.total_tokens += (N = e.total_tokens) == null ? 0 : N;
56035
+ var k, ee, te;
56036
+ c.invokeUsage.prompt_tokens += (k = e.prompt_tokens) == null ? 0 : k, c.invokeUsage.completion_tokens += (ee = e.completion_tokens) == null ? 0 : ee, c.invokeUsage.total_tokens += (te = e.total_tokens) == null ? 0 : te;
56034
56037
  }
56035
56038
  }
56036
- if (pe = yQ(p, i, pe), i.aborted) return n({
56039
+ if (me = yQ(p, i, me), i.aborted) return n({
56037
56040
  type: "done",
56038
56041
  content: i.content
56039
56042
  }), i.content;
@@ -56053,17 +56056,17 @@ function OQ(e) {
56053
56056
  names: t.map((e) => e.name)
56054
56057
  });
56055
56058
  } else {
56056
- if (e && C < 2) {
56057
- C += 1, w = !0, ie("middleware", {
56059
+ if (e && y < 2) {
56060
+ y += 1, C = !0, ie("middleware", {
56058
56061
  stage: "format_retry",
56059
- attempt: C,
56062
+ attempt: y,
56060
56063
  content: i.content.slice(0, 200)
56061
56064
  }), a.push(new Yy("⚠️ 你刚才把工具调用写成了文本(伪 XML/标签/DSML 标记,如 <|tool_calls|>、<||DSML||>、<invoke name=...>),未被系统识别为工具调用,因此未执行,页面无变化。请直接用标准 function calling(工具调用)格式重新发起工具调用,不要在回复正文里输出这些标签或 JSON 文本。"));
56062
56065
  continue;
56063
56066
  }
56064
56067
  e && (ie("error", {
56065
56068
  stage: "garbled_exhausted",
56066
- retries: C,
56069
+ retries: y,
56067
56070
  content: i.content.slice(0, 200)
56068
56071
  }), n({
56069
56072
  type: "error",
@@ -56072,23 +56075,23 @@ function OQ(e) {
56072
56075
  code: "GARBLED_TOOL_CALL_EXHAUSTED",
56073
56076
  context: { content: i.content.slice(0, 200) }
56074
56077
  }));
56075
- let t = g > 0 ? CQ(i.content) : WCe(i.content);
56076
- if (!e && E < 2 && t) {
56077
- E += 1, w = !0, ie("middleware", {
56078
+ let t = m > 0 ? CQ(i.content) : WCe(i.content);
56079
+ if (!e && w < 2 && t) {
56080
+ w += 1, C = !0, ie("middleware", {
56078
56081
  stage: "transitional_retry",
56079
- attempt: E,
56080
- rounds: g,
56082
+ attempt: w,
56083
+ rounds: m,
56081
56084
  content: i.content.slice(0, 160)
56082
56085
  }), a.push(new Yy("⚠️ 你刚才只输出了计划/行动叙述(如「我先看看」「开始添加」),没有发起任何工具调用,因此什么都未执行。请立即用标准 function calling 调用所需工具把任务做完,全部完成后再给出总结回复。"));
56083
56086
  continue;
56084
56087
  }
56085
- if (!e && g > 0 && D < 2 && eCe(pe.todos, i.content)) {
56086
- D += 1, w = !0, ie("middleware", {
56088
+ if (!e && m > 0 && E < 2 && eCe(me.todos, i.content)) {
56089
+ E += 1, C = !0, ie("middleware", {
56087
56090
  stage: "completion_gate",
56088
- attempt: D,
56089
- pending: pe.todos.filter((e) => e.status !== "completed").map((e) => e.id),
56091
+ attempt: E,
56092
+ pending: me.todos.filter((e) => e.status !== "completed").map((e) => e.id),
56090
56093
  content: i.content.slice(0, 160)
56091
- }), a.push(new Yy(tCe(pe.todos)));
56094
+ }), a.push(new Yy(tCe(me.todos)));
56092
56095
  continue;
56093
56096
  }
56094
56097
  let r = (() => {
@@ -56099,47 +56102,47 @@ function OQ(e) {
56099
56102
  }
56100
56103
  return "";
56101
56104
  })();
56102
- if (!e && !pe.__pgIsSubagent && f < 2 && rQ(u, m) && nQ(r) && !cCe(i.content) && !/[??]\s*$/.test(i.content.trim())) {
56103
- f += 1, w = !0, ie("middleware", {
56105
+ if (!e && !me.__pgIsSubagent && u < 2 && rQ(l, f) && nQ(r) && !cCe(i.content) && !/[??]\s*$/.test(i.content.trim())) {
56106
+ u += 1, C = !0, ie("middleware", {
56104
56107
  stage: "zero_tool_gate",
56105
- attempt: f,
56106
- factSheet: iQ(u, pe.todos, m),
56108
+ attempt: u,
56109
+ factSheet: iQ(l, me.todos, f),
56107
56110
  content: i.content.slice(0, 160)
56108
- }), a.push(new Yy(sCe(iQ(u, pe.todos, m))));
56111
+ }), a.push(new Yy(sCe(iQ(l, me.todos, f))));
56109
56112
  continue;
56110
56113
  }
56111
- if (!e && !pe.__pgIsSubagent && f < 2 && pCe(u) && dCe(r) && fCe(i.content)) {
56112
- f += 1, w = !0, ie("middleware", {
56114
+ if (!e && !me.__pgIsSubagent && u < 2 && pCe(l) && dCe(r) && fCe(i.content)) {
56115
+ u += 1, C = !0, ie("middleware", {
56113
56116
  stage: "status_query_gate",
56114
- attempt: f,
56115
- factSheet: iQ(u, pe.todos, m),
56117
+ attempt: u,
56118
+ factSheet: iQ(l, me.todos, f),
56116
56119
  content: i.content.slice(0, 160)
56117
- }), a.push(new Yy(mCe(iQ(u, pe.todos, m))));
56120
+ }), a.push(new Yy(mCe(iQ(l, me.todos, f))));
56118
56121
  continue;
56119
56122
  }
56120
- if (!e && !pe.__pgIsSubagent && f >= 2 && rQ(u, m) && nQ(r) && n({
56123
+ if (!e && !me.__pgIsSubagent && u >= 2 && rQ(l, f) && nQ(r) && n({
56121
56124
  type: "error",
56122
56125
  message: "操作指令经 2 次回灌后仍以零工具纯文本收尾(疑似谎报完成),已放行;最终回复可能不实",
56123
56126
  severity: "observable",
56124
56127
  code: "ZERO_TOOL_GATE_EXHAUSTED",
56125
- context: { factSheet: iQ(u, pe.todos, m) }
56126
- }), !e && x > 0 && pe.verifyAttempts < x) {
56128
+ context: { factSheet: iQ(l, me.todos, f) }
56129
+ }), !e && x > 0 && me.verifyAttempts < x) {
56127
56130
  let e = await RCe(p, {
56128
56131
  messages: a,
56129
- state: pe,
56132
+ state: me,
56130
56133
  response: i,
56131
56134
  log: (e, t) => ie(e, t)
56132
56135
  });
56133
56136
  if (e) {
56134
- y = i.content, pe.verifyAttempts += 1, a.push(new Yy(`⚠️ 验证未通过,请修正:${e}`)), ie("middleware", {
56137
+ v = i.content, me.verifyAttempts += 1, a.push(new Yy(`⚠️ 验证未通过,请修正:${e}`)), ie("middleware", {
56135
56138
  stage: "verify_retry",
56136
- attempt: pe.verifyAttempts,
56139
+ attempt: me.verifyAttempts,
56137
56140
  feedback: e
56138
56141
  });
56139
56142
  continue;
56140
56143
  }
56141
56144
  }
56142
- w = !1;
56145
+ C = !1;
56143
56146
  let o = i.content;
56144
56147
  if (e) {
56145
56148
  let e = SQ(o);
@@ -56151,7 +56154,7 @@ function OQ(e) {
56151
56154
  }), o;
56152
56155
  }
56153
56156
  }
56154
- w = !1;
56157
+ C = !1;
56155
56158
  let d = i.toolCalls.map((e) => {
56156
56159
  let t = e.id || `call_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
56157
56160
  return {
@@ -56161,7 +56164,7 @@ function OQ(e) {
56161
56164
  id: t,
56162
56165
  name: e.name,
56163
56166
  args: e.args,
56164
- state: pe,
56167
+ state: me,
56165
56168
  signal: r,
56166
56169
  emit: n,
56167
56170
  logSink: ae
@@ -56176,14 +56179,14 @@ function OQ(e) {
56176
56179
  args: t.call.args,
56177
56180
  id: t.id
56178
56181
  }), ie("tool_call", {
56179
- round: g + 1,
56182
+ round: m + 1,
56180
56183
  name: t.call.name,
56181
56184
  args: t.call.args,
56182
56185
  id: t.id
56183
56186
  });
56184
56187
  let o;
56185
56188
  try {
56186
- o = await c(t.ctx);
56189
+ o = await s(t.ctx);
56187
56190
  } catch (e) {
56188
56191
  if (KZ(e, r)) throw e;
56189
56192
  o = {
@@ -56191,20 +56194,20 @@ function OQ(e) {
56191
56194
  status: "error"
56192
56195
  };
56193
56196
  }
56194
- let s = Date.now() - a;
56197
+ let c = Date.now() - a;
56195
56198
  return n({
56196
56199
  type: "tool_result",
56197
56200
  name: t.call.name,
56198
56201
  result: o.content,
56199
56202
  status: o.status,
56200
- durationMs: s,
56203
+ durationMs: c,
56201
56204
  id: t.id
56202
56205
  }), ie("tool_result", {
56203
- round: g + 1,
56206
+ round: m + 1,
56204
56207
  name: t.call.name,
56205
56208
  result: o.content,
56206
56209
  status: o.status,
56207
- durationMs: s
56210
+ durationMs: c
56208
56211
  }), le(i, o.status === "error" ? "error" : "ok", { resultSnippet: String(o.content).slice(0, 100) }), o;
56209
56212
  }, r);
56210
56213
  for (let e = 0; e < d.length; e++) {
@@ -56215,93 +56218,93 @@ function OQ(e) {
56215
56218
  }));
56216
56219
  }
56217
56220
  for (let e = 0; e < d.length; e++) {
56218
- var P;
56221
+ var N;
56219
56222
  let t = h[e];
56220
56223
  if (!t || !EQ.has(d[e].call.name)) continue;
56221
56224
  let n = DQ(d[e].call.args);
56222
- t.status === "error" ? l.writeFailures[n] = ((P = l.writeFailures[n]) == null ? 0 : P) + 1 : delete l.writeFailures[n];
56225
+ t.status === "error" ? c.writeFailures[n] = ((N = c.writeFailures[n]) == null ? 0 : N) + 1 : delete c.writeFailures[n];
56223
56226
  }
56224
- let v = [];
56227
+ let _ = [];
56225
56228
  for (let e = 0; e < d.length; e++) {
56226
- var ne;
56229
+ var P;
56227
56230
  let t = h[e];
56228
56231
  if (!t) continue;
56229
56232
  let n = d[e].call.name;
56230
- if (u.counts[n] = ((ne = u.counts[n]) == null ? 0 : ne) + 1, t.status === "error" && (u.failures += 1), hCe(ue.find((e) => e.name === n), d[e].call.args, t)) {
56233
+ if (l.counts[n] = ((P = l.counts[n]) == null ? 0 : P) + 1, t.status === "error" && (l.failures += 1), hCe(ue.find((e) => e.name === n), d[e].call.args, t)) {
56231
56234
  let t = DQ(d[e].call.args);
56232
- u.writePaths.push(t || "(整体)"), v.push({
56235
+ l.writePaths.push(t || "(整体)"), _.push({
56233
56236
  name: n,
56234
56237
  args: d[e].call.args,
56235
56238
  callIndex: e
56236
56239
  });
56237
56240
  }
56238
56241
  }
56239
- if (O && v.length) {
56240
- let e = PCe(a, v, {
56241
- round: g + 1,
56242
+ if (O && _.length) {
56243
+ let e = PCe(a, _, {
56244
+ round: m + 1,
56242
56245
  maxParallelTools: b
56243
56246
  });
56244
56247
  e.invalidatedCount > 0 && (a = e.messages, re += e.invalidatedCount, ie("middleware", {
56245
56248
  stage: "stale_read_invalidated",
56246
- round: g + 1,
56247
- writtenPaths: v.map((e) => DQ(e.args) || "(整体)"),
56249
+ round: m + 1,
56250
+ writtenPaths: _.map((e) => DQ(e.args) || "(整体)"),
56248
56251
  invalidatedCount: e.invalidatedCount
56249
56252
  }));
56250
56253
  }
56251
56254
  if (r != null && r.aborted) break;
56252
- g++, l.rounds = g;
56255
+ m++, c.rounds = m;
56253
56256
  }
56254
56257
  if (r != null && r.aborted) return n({
56255
56258
  type: "done",
56256
56259
  content: ""
56257
56260
  }), "";
56258
- let e = `\n\n(提示:工具调用次数已达上限(${A} 轮 / ${v} 次迭代),以上为基于已完成操作的阶段性结果,任务可能未完成。回复「继续」或告诉我下一步重点,即可接着做。)`;
56261
+ let e = `\n\n(提示:工具调用次数已达上限(${A} 轮 / ${_} 次迭代),以上为基于已完成操作的阶段性结果,任务可能未完成。回复「继续」或告诉我下一步重点,即可接着做。)`;
56259
56262
  if (ie("error", {
56260
56263
  stage: "react_call_limit_exceeded",
56261
- rounds: g,
56264
+ rounds: m,
56262
56265
  maxToolRounds: A,
56263
- iterations: _,
56264
- maxIterations: v
56266
+ iterations: g,
56267
+ maxIterations: _
56265
56268
  }), n({
56266
56269
  type: "error",
56267
- message: `ReAct 循环达到调用上限(rounds=${g}/${A},iterations=${_}/${v}),已强制收口,可回复「继续」。`,
56270
+ message: `ReAct 循环达到调用上限(rounds=${m}/${A},iterations=${g}/${_}),已强制收口,可回复「继续」。`,
56268
56271
  severity: "observable",
56269
56272
  code: "REACT_CALL_LIMIT_EXCEEDED",
56270
56273
  context: {
56271
- rounds: g,
56274
+ rounds: m,
56272
56275
  maxToolRounds: A,
56273
- iterations: _,
56274
- maxIterations: v
56276
+ iterations: g,
56277
+ maxIterations: _
56275
56278
  }
56276
- }), y != null) {
56277
- let t = y + e;
56279
+ }), v != null) {
56280
+ let t = v + e;
56278
56281
  return n({
56279
56282
  type: "done",
56280
56283
  content: t
56281
56284
  }), t;
56282
56285
  }
56283
56286
  let t = a[a.length - 1];
56284
- if (t && xe(t) === "tool") {
56285
- let t = a[0] && xe(a[0]) === "system" ? a.slice(1) : a.slice(), i = [new eb(ge() + "\n\n工具调用次数已达上限,请基于已有工具结果直接给出最终回答,不要再调用工具。"), ...t];
56287
+ if (t && Se(t) === "tool") {
56288
+ let t = a[0] && Se(a[0]) === "system" ? a.slice(1) : a.slice(), i = [new eb(_e() + "\n\n工具调用次数已达上限,请基于已有工具结果直接给出最终回答,不要再调用工具。"), ...t];
56286
56289
  ie("llm_request", {
56287
56290
  round: "wrap_up",
56288
- model: o,
56291
+ model: fe(),
56289
56292
  tools: [],
56290
- messages: Ce(i)
56293
+ messages: we(i)
56291
56294
  });
56292
- let s = await bQ(p, (e) => ye(e, n, r, I))({
56295
+ let o = await bQ(p, (e) => be(e, n, r, I))({
56293
56296
  messages: i,
56294
- state: pe
56297
+ state: me
56295
56298
  });
56296
- if (pe = yQ(p, s, pe), ie("llm_response", {
56299
+ if (me = yQ(p, o, me), ie("llm_response", {
56297
56300
  round: "wrap_up",
56298
- content: s.content
56299
- }), s.aborted) return n({
56301
+ content: o.content
56302
+ }), o.aborted) return n({
56300
56303
  type: "done",
56301
- content: s.content
56302
- }), s.content;
56303
- if (s.content) {
56304
- let t = s.content;
56304
+ content: o.content
56305
+ }), o.content;
56306
+ if (o.content) {
56307
+ let t = o.content;
56305
56308
  if (xQ(t)) {
56306
56309
  let e = SQ(t);
56307
56310
  ie("error", {
@@ -56328,7 +56331,7 @@ function OQ(e) {
56328
56331
  }), i + e;
56329
56332
  } finally {
56330
56333
  try {
56331
- await LCe(p, pe);
56334
+ await LCe(p, me);
56332
56335
  } catch (e) {
56333
56336
  let t = NZ(e, "observable");
56334
56337
  console.warn("[Agent] afterAgent 清理出错(observable,已忽略):", t.message);
@@ -56338,22 +56341,22 @@ function OQ(e) {
56338
56341
  } catch (e) {}
56339
56342
  }
56340
56343
  }
56341
- async function Te(e, t, n) {
56344
+ async function Ee(e, t, n) {
56342
56345
  let r = "";
56343
- return await we(e, (e) => {
56346
+ return await Te(e, (e) => {
56344
56347
  e.type === "done" && (r = e.content), n == null || n(e);
56345
56348
  }, t), r;
56346
56349
  }
56347
- function Ee(e) {
56348
- ue = [...p.flatMap((e) => e.tools || []), ...e], fe();
56349
- }
56350
56350
  function De(e) {
56351
- I = e, fe(), E == null || E(e);
56351
+ ue = [...p.flatMap((e) => e.tools || []), ...e], pe();
56352
+ }
56353
+ function Oe(e) {
56354
+ I = e, pe(), E == null || E(e);
56352
56355
  }
56353
56356
  return {
56354
- invoke: Te,
56355
- stream: we,
56356
- getState: () => pe,
56357
+ invoke: Ee,
56358
+ stream: Te,
56359
+ getState: () => me,
56357
56360
  get allTools() {
56358
56361
  return ue;
56359
56362
  },
@@ -56361,12 +56364,12 @@ function OQ(e) {
56361
56364
  resetStaleReadsInvalidated: () => {
56362
56365
  re = 0;
56363
56366
  },
56364
- setTools: Ee,
56365
- setLlm: De,
56367
+ setTools: De,
56368
+ setLlm: Oe,
56366
56369
  setModelCaps: P,
56367
56370
  debugLogs: ne,
56368
56371
  spans: oe,
56369
- getEffectiveSystemPrompt: () => ge()
56372
+ getEffectiveSystemPrompt: () => _e()
56370
56373
  };
56371
56374
  }
56372
56375
  Jf(), M();
@@ -71549,7 +71552,7 @@ function nje(e, t, n) {
71549
71552
  augmentPrompt: (i) => {
71550
71553
  var a;
71551
71554
  let o = [];
71552
- if (r.planning && (o.push("【自适应规划】按任务复杂度决定是否先规划,不要对简单任务过度编排:"), o.push(" · 简单/明确任务(改单字段、调样式、查值)→ 直接 read/write 执行,不必 write_todos。"), o.push(" · 复杂任务(多步、大改、有歧义、不可逆)→ 先 write_todos 拆解,首个任务标 in_progress,逐项推进。"), o.push(" · 执行中发现步骤要改/补/细分 → 用 update_todo({id, content?, status?}) 按 id 增量改单项,不必重传整个清单。"), e != null && e.humanConfirm ? o.push(" · 规划出多步方案若需用户拍板 → 先 request_human_confirmation 给方案选项,确认后再执行。") : o.push(" · 规划出多步方案若需用户拍板 → 以文字列出方案选项等用户回复,勿自行拍板。"), o.push(" · 规划阶段有轮次预算(maxPlanRevisions,默认 5):勿反复调研/改计划而不执行,规划充分后即开始 write 落地。")), t && (o.push("改主数据前先 get_data({jsonPath}) 读其当前真实值(返回末尾 hash=xxx 为乐观锁标识),基于真实值改,不要凭记忆。写入是否被自动校验由集成方 conflictWatchFields 声明决定:若已声明且主数据在你 read 之后被外部改过,会触发冲突——集成方若开启人工介入,工具会挂起等用户决定(保留外部/强制覆盖/回退),你应等待工具返回后按结果继续(保留外部→重新 get 再改;强制覆盖→已写入,继续;回退→已回退到历史快照,基于回退值重写);未开启人工介入时返回 VERSION_CONFLICT 不写入,重新 get 拿最新值再改。"), o.push("不确定主数据字段结构时用 describe_data 查看说明。"), o.push("修改大对象/数组优先用 edit_data 增量 patch(只发改动部分),避免 set_data 整体重传被 max_tokens 截断导致 JSON 不完整、校验失败。"), o.push("修改主数据出错时可用 restore_data 回退最近一次。"), o.push("在大数组里按条件筛选元素用 query_data(JSONPath,如 $.components[?(@.type==\"card\" && @.price<100)]),返回匹配元素的 path/index;定位后再 edit_data 改。"), o.push("找名字记不清的元素用 search_data(支持 substring/regex/fuzzy 模糊搜索)。"), o.push("需要过滤/映射/聚合/批量重写大数组时用 eval_script(沙箱脚本,入参 data);只读探查用 mode=query,批量重写用 mode=transform(返回值经校验后落地)。"), o.push("读大数组用 read({jsonPath,offset,limit}) 分页(返回 hasMore=true 时 offset+=limit 续读);一次读多个不相关子路径用 read({jsonPaths});复杂改动先 write({...,dryRun:true}) 预检不落盘。"), o.push("【省轮次·批量】读多个同构子路径(如各组件 props)用 read({jsonPaths:[...]}) 一次取回,勿发多个独立 read;改多处用 write({patches:[{op:\"set\",jsonPath,value},...]}) 一次提交多改动(原子任一失败回滚),勿逐个 edit_data/write 烧轮次预算。"), o.push("对比当前与历史快照(或一段 JSON against)的差异用 diff_data({snapshotId?,against?})(返回结构化 path→from/to,verify 自纠/操作审计/\"刚才改了啥\");只读查历史快照值用 history_data({id?,jsonPath?})。")), r.subagent && o.push("独立子任务可 spawn_agent 委派(过程隔离,不占主上下文):默认只读,需要子 agent 写数据时传 writablePaths(路径前缀白名单,越界 PATH_OUT_OF_SCOPE)。多个独立子任务可 spawn_agents 并行委派(各子互不通信,结论由你汇总;并行委派不可授写权限,写操作由你收尾执行)。"), r.inspectEnv && o.push("排查页面环境(当前 URL/浏览器/视口/集成方调试变量)用 inspect_env——不传参返回环境摘要(location/navigator/viewport/document),传 key 读特定 window 属性(如 inspect_env({key:\"appConfig\"}) 读 window.appConfig)。改完数据看渲染、定位\"为何没生效\"时用它(只读,不改数据)。"), r.domInspect && o.push("改完数据想确认渲染是否生效(或定位元素/辅助 UI 设计问答)用 get_dom({selector?,depth?}) 读渲染后 DOM(结构化返回 tag/attrs/text/children,depth 控制深度防爆炸,只读)。配合宿主 actions(save_draft/publish 等)形成\"改数据→get_dom 看渲染→触发动作\"闭环。"), r.draftWrite && (o.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。"), o.push("⚠️ 大 JSON 分块构建是典型多轮工具调用(draft_write×N + draft_commit + read 确认 + 调研 read/query),默认 maxToolRounds=30(3.43 起;轮次预算吃紧时 system 会注入预算提示段,按提示优先收口);目标组件数很大时集成方仍可在 createChatSdk 显式上调 maxToolRounds(按 N+10 估算)。draft_commit 提交同样走乐观锁(改前 read 拿 hash,bind 被改过会触发冲突介入,不静默覆盖)。")), r.todoDeps && o.push("复杂任务可用 todos 层级依赖:write_todos 时给 todo 传 parentId(父任务 id,表达层级)+ deps(依赖的 todo id 数组,必须先完成)。有依赖的任务,deps 全 completed 后再标 in_progress;完成时 update_todo({id, status:\"completed\", evidence:\"完成证据\"}) 记证据。无依赖关系的任务不传 parentId/deps(扁平)。"), r.focus && (o.push("【上下文聚焦】判断任务范围,用 set_focus/add_focus/remove_focus/clear_focus 自动收敛工作范围:"), o.push(" · 局部任务(只改某一组件/区域,如「调导航栏」「改 components.3 样式」)→ 先 read 定位 jsonPath,再 set_focus({path:\"该子树路径\"}) 聚焦;聚焦后每轮只看该子树结构,写其他位置会被 PATH_DENIED 拒绝。"), o.push(" · 多个相关组件(如「同时改导航栏和页脚」)→ set_focus 聚焦首个后用 add_focus({path}) 追加其余;聚焦后可写任一焦点子树,越界仍被拒;移除单个用 remove_focus({path})。"), o.push(" · 全局任务(多处/整体结构,如「重排所有组件」「换主题」)→ 不要聚焦,保持全量视野直接写。"), o.push(" · 完成局部精修、要转向其他区域或做整体改动 → 调 clear_focus 退出聚焦(清空全部焦点),恢复全部读写权限。"), o.push(" · set_focus/add_focus 的 path 必须在 schema 内(类型校验);不确定路径先 read/describe_data 查。")), !(e == null || (a = e.subagents) == null) && a.length) {
71555
+ if (r.planning && (o.push("【自适应规划】按任务复杂度决定是否先规划,不要对简单任务过度编排:"), o.push(" · 简单/明确任务(改单字段、调样式、查值)→ 直接 read/write 执行,不必 write_todos。"), o.push(" · 复杂任务(多步、大改、有歧义、不可逆)→ 先 write_todos 拆解,首个任务标 in_progress,逐项推进。"), o.push(" · 执行中发现步骤要改/补/细分 → 用 update_todo({id, content?, status?}) 按 id 增量改单项,不必重传整个清单。"), e != null && e.humanConfirm ? o.push(" · 规划出多步方案若需用户拍板 → 先 request_human_confirmation 给方案选项,确认后再执行。") : o.push(" · 规划出多步方案若需用户拍板 → 以文字列出方案选项等用户回复,勿自行拍板。"), o.push(" · 计划修订有次数上限(maxPlanRevisions,默认 5,只计 write_todos 调用、调研轮不计):勿反复改计划而不执行,规划充分后即开始 write 落地。")), t && (o.push("改主数据前先 get_data({jsonPath}) 读其当前真实值(返回末尾 hash=xxx 为乐观锁标识),基于真实值改,不要凭记忆。写入是否被自动校验由集成方 conflictWatchFields 声明决定:若已声明且主数据在你 read 之后被外部改过,会触发冲突——集成方若开启人工介入,工具会挂起等用户决定(保留外部/强制覆盖/回退),你应等待工具返回后按结果继续(保留外部→重新 get 再改;强制覆盖→已写入,继续;回退→已回退到历史快照,基于回退值重写);未开启人工介入时返回 VERSION_CONFLICT 不写入,重新 get 拿最新值再改。"), o.push("不确定主数据字段结构时用 describe_data 查看说明。"), o.push("修改大对象/数组优先用 edit_data 增量 patch(只发改动部分),避免 set_data 整体重传被 max_tokens 截断导致 JSON 不完整、校验失败。"), o.push("修改主数据出错时可用 restore_data 回退最近一次。"), o.push("在大数组里按条件筛选元素用 query_data(JSONPath,如 $.components[?(@.type==\"card\" && @.price<100)]),返回匹配元素的 path/index;定位后再 edit_data 改。"), o.push("找名字记不清的元素用 search_data(支持 substring/regex/fuzzy 模糊搜索)。"), o.push("需要过滤/映射/聚合/批量重写大数组时用 eval_script(沙箱脚本,入参 data);只读探查用 mode=query,批量重写用 mode=transform(返回值经校验后落地)。"), o.push("读大数组用 read({jsonPath,offset,limit}) 分页(返回 hasMore=true 时 offset+=limit 续读);一次读多个不相关子路径用 read({jsonPaths});复杂改动先 write({...,dryRun:true}) 预检不落盘。"), o.push("【省轮次·批量】读多个同构子路径(如各组件 props)用 read({jsonPaths:[...]}) 一次取回,勿发多个独立 read;改多处用 write({patches:[{op:\"set\",jsonPath,value},...]}) 一次提交多改动(原子任一失败回滚),勿逐个 edit_data/write 烧轮次预算。"), o.push("对比当前与历史快照(或一段 JSON against)的差异用 diff_data({snapshotId?,against?})(返回结构化 path→from/to,verify 自纠/操作审计/\"刚才改了啥\");只读查历史快照值用 history_data({id?,jsonPath?})。")), r.subagent && o.push("独立子任务可 spawn_agent 委派(过程隔离,不占主上下文):默认只读,需要子 agent 写数据时传 writablePaths(路径前缀白名单,越界 PATH_OUT_OF_SCOPE)。多个独立子任务可 spawn_agents 并行委派(各子互不通信,结论由你汇总;并行委派不可授写权限,写操作由你收尾执行)。"), r.inspectEnv && o.push("排查页面环境(当前 URL/浏览器/视口/集成方调试变量)用 inspect_env——不传参返回环境摘要(location/navigator/viewport/document),传 key 读特定 window 属性(如 inspect_env({key:\"appConfig\"}) 读 window.appConfig)。改完数据看渲染、定位\"为何没生效\"时用它(只读,不改数据)。"), r.domInspect && o.push("改完数据想确认渲染是否生效(或定位元素/辅助 UI 设计问答)用 get_dom({selector?,depth?}) 读渲染后 DOM(结构化返回 tag/attrs/text/children,depth 控制深度防爆炸,只读)。配合宿主 actions(save_draft/publish 等)形成\"改数据→get_dom 看渲染→触发动作\"闭环。"), r.draftWrite && (o.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。"), o.push("⚠️ 大 JSON 分块构建是典型多轮工具调用(draft_write×N + draft_commit + read 确认 + 调研 read/query),默认 maxToolRounds=30(3.43 起;轮次预算吃紧时 system 会注入预算提示段,按提示优先收口);目标组件数很大时集成方仍可在 createChatSdk 显式上调 maxToolRounds(按 N+10 估算)。draft_commit 提交同样走乐观锁(改前 read 拿 hash,bind 被改过会触发冲突介入,不静默覆盖)。")), r.todoDeps && o.push("复杂任务可用 todos 层级依赖:write_todos 时给 todo 传 parentId(父任务 id,表达层级)+ deps(依赖的 todo id 数组,必须先完成)。有依赖的任务,deps 全 completed 后再标 in_progress;完成时 update_todo({id, status:\"completed\", evidence:\"完成证据\"}) 记证据。无依赖关系的任务不传 parentId/deps(扁平)。"), r.focus && (o.push("【上下文聚焦】判断任务范围,用 set_focus/add_focus/remove_focus/clear_focus 自动收敛工作范围:"), o.push(" · 局部任务(只改某一组件/区域,如「调导航栏」「改 components.3 样式」)→ 先 read 定位 jsonPath,再 set_focus({path:\"该子树路径\"}) 聚焦;聚焦后每轮只看该子树结构,写其他位置会被 PATH_DENIED 拒绝。"), o.push(" · 多个相关组件(如「同时改导航栏和页脚」)→ set_focus 聚焦首个后用 add_focus({path}) 追加其余;聚焦后可写任一焦点子树,越界仍被拒;移除单个用 remove_focus({path})。"), o.push(" · 全局任务(多处/整体结构,如「重排所有组件」「换主题」)→ 不要聚焦,保持全量视野直接写。"), o.push(" · 完成局部精修、要转向其他区域或做整体改动 → 调 clear_focus 退出聚焦(清空全部焦点),恢复全部读写权限。"), o.push(" · set_focus/add_focus 的 path 必须在 schema 内(类型校验);不确定路径先 read/describe_data 查。")), !(e == null || (a = e.subagents) == null) && a.length) {
71553
71556
  let t = e.subagents.filter((e) => {
71554
71557
  var t;
71555
71558
  return ((t = e.temperature) == null ? 0 : t) >= tje || /规划|创意|设计|方案|brainstorm|plan/i.test(e.description);