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.
- package/README.md +2 -2
- package/README.zh-CN.md +2 -2
- package/dist/page-agent-sdk.headless.js +393 -390
- package/dist/page-agent-sdk.iife.js +24 -24
- package/dist/page-agent-sdk.js +2204 -2201
- package/dist/page-agent-sdk.legacy.js +151 -148
- package/dist/page-agent-sdk.umd.cjs +23 -23
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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
|
|
55706
|
-
e.__pgIsSubagent && (
|
|
55707
|
-
let
|
|
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
|
|
55716
|
+
function _e() {
|
|
55714
55717
|
let e = d || "你是一个智能助手。", t = [];
|
|
55715
55718
|
for (let e of p) if (e.augmentPrompt) {
|
|
55716
|
-
let n = e.augmentPrompt(
|
|
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:
|
|
55724
|
+
pin: ge.has(e.name)
|
|
55722
55725
|
});
|
|
55723
55726
|
}
|
|
55724
|
-
let n = Math.max(2e3, Math.round(M.contextWindow *
|
|
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} 的 ${
|
|
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
|
|
55736
|
-
let t = [new eb(
|
|
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
|
|
55745
|
-
let n = e[0] &&
|
|
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
|
|
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 =
|
|
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`),
|
|
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 =
|
|
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})`),
|
|
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
|
-
}),
|
|
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
|
|
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
|
|
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
|
|
55912
|
+
function Ce(e, t) {
|
|
55910
55913
|
return XCe(e, t);
|
|
55911
55914
|
}
|
|
55912
|
-
function
|
|
55915
|
+
function we(e) {
|
|
55913
55916
|
return !k && !C ? [] : e.map((e) => {
|
|
55914
|
-
let t =
|
|
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
|
|
55930
|
-
oe.value = [], se = 0,
|
|
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 ? (
|
|
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 *
|
|
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} 的 ${
|
|
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 =
|
|
55954
|
+
let a = ve(i);
|
|
55952
55955
|
ie("context", {
|
|
55953
|
-
model:
|
|
55956
|
+
model: fe(),
|
|
55954
55957
|
tools: ue.map((e) => e.name),
|
|
55955
55958
|
middleware: p.map((e) => e.name)
|
|
55956
55959
|
});
|
|
55957
|
-
let
|
|
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
|
-
|
|
55969
|
-
let
|
|
55971
|
+
me.loopProgress = c;
|
|
55972
|
+
let l = {
|
|
55970
55973
|
counts: {},
|
|
55971
55974
|
writePaths: [],
|
|
55972
55975
|
failures: 0
|
|
55973
|
-
},
|
|
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
|
-
},
|
|
55979
|
+
}, m = 0, g = 0, _ = ZCe(A, h), v = null, y = 0, C = !1, w = 0, E = 0;
|
|
55977
55980
|
try {
|
|
55978
|
-
for (; (
|
|
55979
|
-
var
|
|
55980
|
-
if (
|
|
55981
|
-
if (S > 0 &&
|
|
55982
|
-
let e = `本轮 token 预算(约 ${S})已用尽:任务在 ${
|
|
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:
|
|
55988
|
+
used: c.invokeUsage.total_tokens,
|
|
55986
55989
|
budget: S,
|
|
55987
|
-
rounds:
|
|
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:
|
|
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 = (
|
|
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
|
-
}),
|
|
56008
|
+
round: g
|
|
56009
|
+
}), me = ICe(p, {
|
|
56007
56010
|
messages: a,
|
|
56008
|
-
state:
|
|
56009
|
-
}), a =
|
|
56010
|
-
let t = F(e, "model",
|
|
56011
|
-
round:
|
|
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:
|
|
56016
|
-
model:
|
|
56018
|
+
round: m + 1,
|
|
56019
|
+
model: fe(),
|
|
56017
56020
|
tools: ue.map((e) => e.name),
|
|
56018
|
-
messages:
|
|
56021
|
+
messages: we(a)
|
|
56019
56022
|
});
|
|
56020
|
-
let i = await
|
|
56023
|
+
let i = await o({
|
|
56021
56024
|
messages: a,
|
|
56022
|
-
state:
|
|
56025
|
+
state: me
|
|
56023
56026
|
});
|
|
56024
56027
|
a.push(i.message), ie("llm_response", {
|
|
56025
|
-
round:
|
|
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
|
|
56033
|
-
|
|
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 (
|
|
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 &&
|
|
56057
|
-
|
|
56059
|
+
if (e && y < 2) {
|
|
56060
|
+
y += 1, C = !0, ie("middleware", {
|
|
56058
56061
|
stage: "format_retry",
|
|
56059
|
-
attempt:
|
|
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:
|
|
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 =
|
|
56076
|
-
if (!e &&
|
|
56077
|
-
|
|
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:
|
|
56080
|
-
rounds:
|
|
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 &&
|
|
56086
|
-
|
|
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:
|
|
56089
|
-
pending:
|
|
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(
|
|
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 && !
|
|
56103
|
-
|
|
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:
|
|
56106
|
-
factSheet: iQ(
|
|
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(
|
|
56111
|
+
}), a.push(new Yy(sCe(iQ(l, me.todos, f))));
|
|
56109
56112
|
continue;
|
|
56110
56113
|
}
|
|
56111
|
-
if (!e && !
|
|
56112
|
-
|
|
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:
|
|
56115
|
-
factSheet: iQ(
|
|
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(
|
|
56120
|
+
}), a.push(new Yy(mCe(iQ(l, me.todos, f))));
|
|
56118
56121
|
continue;
|
|
56119
56122
|
}
|
|
56120
|
-
if (!e && !
|
|
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(
|
|
56126
|
-
}), !e && x > 0 &&
|
|
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:
|
|
56132
|
+
state: me,
|
|
56130
56133
|
response: i,
|
|
56131
56134
|
log: (e, t) => ie(e, t)
|
|
56132
56135
|
});
|
|
56133
56136
|
if (e) {
|
|
56134
|
-
|
|
56137
|
+
v = i.content, me.verifyAttempts += 1, a.push(new Yy(`⚠️ 验证未通过,请修正:${e}`)), ie("middleware", {
|
|
56135
56138
|
stage: "verify_retry",
|
|
56136
|
-
attempt:
|
|
56139
|
+
attempt: me.verifyAttempts,
|
|
56137
56140
|
feedback: e
|
|
56138
56141
|
});
|
|
56139
56142
|
continue;
|
|
56140
56143
|
}
|
|
56141
56144
|
}
|
|
56142
|
-
|
|
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
|
-
|
|
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:
|
|
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:
|
|
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
|
|
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
|
|
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:
|
|
56203
|
+
durationMs: c,
|
|
56201
56204
|
id: t.id
|
|
56202
56205
|
}), ie("tool_result", {
|
|
56203
|
-
round:
|
|
56206
|
+
round: m + 1,
|
|
56204
56207
|
name: t.call.name,
|
|
56205
56208
|
result: o.content,
|
|
56206
56209
|
status: o.status,
|
|
56207
|
-
durationMs:
|
|
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
|
|
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" ?
|
|
56225
|
+
t.status === "error" ? c.writeFailures[n] = ((N = c.writeFailures[n]) == null ? 0 : N) + 1 : delete c.writeFailures[n];
|
|
56223
56226
|
}
|
|
56224
|
-
let
|
|
56227
|
+
let _ = [];
|
|
56225
56228
|
for (let e = 0; e < d.length; e++) {
|
|
56226
|
-
var
|
|
56229
|
+
var P;
|
|
56227
56230
|
let t = h[e];
|
|
56228
56231
|
if (!t) continue;
|
|
56229
56232
|
let n = d[e].call.name;
|
|
56230
|
-
if (
|
|
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
|
-
|
|
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 &&
|
|
56240
|
-
let e = PCe(a,
|
|
56241
|
-
round:
|
|
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:
|
|
56247
|
-
writtenPaths:
|
|
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
|
-
|
|
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} 轮 / ${
|
|
56261
|
+
let e = `\n\n(提示:工具调用次数已达上限(${A} 轮 / ${_} 次迭代),以上为基于已完成操作的阶段性结果,任务可能未完成。回复「继续」或告诉我下一步重点,即可接着做。)`;
|
|
56259
56262
|
if (ie("error", {
|
|
56260
56263
|
stage: "react_call_limit_exceeded",
|
|
56261
|
-
rounds:
|
|
56264
|
+
rounds: m,
|
|
56262
56265
|
maxToolRounds: A,
|
|
56263
|
-
iterations:
|
|
56264
|
-
maxIterations:
|
|
56266
|
+
iterations: g,
|
|
56267
|
+
maxIterations: _
|
|
56265
56268
|
}), n({
|
|
56266
56269
|
type: "error",
|
|
56267
|
-
message: `ReAct 循环达到调用上限(rounds=${
|
|
56270
|
+
message: `ReAct 循环达到调用上限(rounds=${m}/${A},iterations=${g}/${_}),已强制收口,可回复「继续」。`,
|
|
56268
56271
|
severity: "observable",
|
|
56269
56272
|
code: "REACT_CALL_LIMIT_EXCEEDED",
|
|
56270
56273
|
context: {
|
|
56271
|
-
rounds:
|
|
56274
|
+
rounds: m,
|
|
56272
56275
|
maxToolRounds: A,
|
|
56273
|
-
iterations:
|
|
56274
|
-
maxIterations:
|
|
56276
|
+
iterations: g,
|
|
56277
|
+
maxIterations: _
|
|
56275
56278
|
}
|
|
56276
|
-
}),
|
|
56277
|
-
let t =
|
|
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 &&
|
|
56285
|
-
let t = a[0] &&
|
|
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:
|
|
56291
|
+
model: fe(),
|
|
56289
56292
|
tools: [],
|
|
56290
|
-
messages:
|
|
56293
|
+
messages: we(i)
|
|
56291
56294
|
});
|
|
56292
|
-
let
|
|
56295
|
+
let o = await bQ(p, (e) => be(e, n, r, I))({
|
|
56293
56296
|
messages: i,
|
|
56294
|
-
state:
|
|
56297
|
+
state: me
|
|
56295
56298
|
});
|
|
56296
|
-
if (
|
|
56299
|
+
if (me = yQ(p, o, me), ie("llm_response", {
|
|
56297
56300
|
round: "wrap_up",
|
|
56298
|
-
content:
|
|
56299
|
-
}),
|
|
56301
|
+
content: o.content
|
|
56302
|
+
}), o.aborted) return n({
|
|
56300
56303
|
type: "done",
|
|
56301
|
-
content:
|
|
56302
|
-
}),
|
|
56303
|
-
if (
|
|
56304
|
-
let t =
|
|
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,
|
|
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
|
|
56344
|
+
async function Ee(e, t, n) {
|
|
56342
56345
|
let r = "";
|
|
56343
|
-
return await
|
|
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
|
-
|
|
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:
|
|
56355
|
-
stream:
|
|
56356
|
-
getState: () =>
|
|
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:
|
|
56365
|
-
setLlm:
|
|
56367
|
+
setTools: De,
|
|
56368
|
+
setLlm: Oe,
|
|
56366
56369
|
setModelCaps: P,
|
|
56367
56370
|
debugLogs: ne,
|
|
56368
56371
|
spans: oe,
|
|
56369
|
-
getEffectiveSystemPrompt: () =>
|
|
56372
|
+
getEffectiveSystemPrompt: () => _e()
|
|
56370
56373
|
};
|
|
56371
56374
|
}
|
|
56372
56375
|
Jf(), M();
|