page-agent-sdk 3.43.1 → 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.
@@ -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();