page-agent-sdk 2.36.0 → 2.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3926,66 +3926,323 @@ function $a(e) {
3926
3926
  };
3927
3927
  }
3928
3928
  //#endregion
3929
- //#region src/core/harness/subagent.ts
3929
+ //#region src/core/utils/rounds.ts
3930
3930
  function eo(e) {
3931
+ let t = [], n = null, r = 0;
3932
+ for (let i = 0; i < e.length; i++) {
3933
+ let a = e[i];
3934
+ a.role === "user" ? (n && t.push(n), r++, n = {
3935
+ round: r,
3936
+ userMsg: a,
3937
+ assistantMsgs: [],
3938
+ startIdx: i,
3939
+ endIdx: i
3940
+ }) : n && (n.assistantMsgs.push(a), n.endIdx = i);
3941
+ }
3942
+ return n && t.push(n), t;
3943
+ }
3944
+ function to(e, t) {
3945
+ let n = (e || "").replace(/```[\s\S]*?```/g, "[代码]").replace(/`([^`]+)`/g, "$1").replace(/[#*_>\-]\s?/g, "").replace(/\[(代码)\]/g, "「代码」").replace(/\s+/g, " ").trim();
3946
+ return n.length > t ? n.slice(0, t) + "…" : n;
3947
+ }
3948
+ function no(e) {
3949
+ let t = [];
3950
+ for (let n of e.assistantMsgs) for (let e of n.steps || []) t.push(e.name);
3951
+ return t;
3952
+ }
3953
+ var ro = "【更早对话摘要";
3954
+ function io(e, t) {
3955
+ return !t || !t.body ? e : {
3956
+ body: `${t.body}\n【续】\n${e.body}`,
3957
+ rounds: (t.rounds ?? 0) + (e.rounds ?? 0),
3958
+ cumulative: !0
3959
+ };
3960
+ }
3961
+ function ao(e) {
3962
+ return typeof e != "string" || !e.startsWith("【更早对话摘要") ? null : { body: e.replace(/^【[^】]*】\n?/, "") };
3963
+ }
3964
+ function oo(e) {
3965
+ return `${ro}${e.cumulative ? `(${e.rounds ?? 0} 轮,含累积)` : e.rounds ? `(${e.rounds} 轮)` : ""}】\n${e.body}`;
3966
+ }
3967
+ function so(e, t, n) {
3968
+ return oo(io({
3969
+ body: n,
3970
+ rounds: e.length
3971
+ }, t ?? void 0));
3972
+ }
3973
+ function co(e, t) {
3974
+ if (t <= 0) return { trimmed: !1 };
3975
+ let n = eo(e);
3976
+ if (n.length <= t) return { trimmed: !1 };
3977
+ let r = n[n.length - t].startIdx, i = n.slice(0, n.length - t), a = n[0].startIdx, o = null;
3978
+ for (let t = 0; t < a; t++) {
3979
+ let n = e[t];
3980
+ if (n.role === "system" && (o = ao(n.content), o)) break;
3981
+ }
3982
+ return {
3983
+ trimmed: !0,
3984
+ deleteFrom: 0,
3985
+ deleteCount: r,
3986
+ summary: {
3987
+ role: "system",
3988
+ content: oo(io({
3989
+ body: i.map((e) => {
3990
+ let t = to(e.userMsg.content, 60) || "(空)", n = e.assistantMsgs[0] ? to(e.assistantMsgs[0].content, 80) : "(无回复)";
3991
+ return `- 第${e.round}轮:${t} → ${n}`;
3992
+ }).join("\n"),
3993
+ rounds: i.length
3994
+ }, o ?? void 0)),
3995
+ timestamp: i[0].userMsg.timestamp
3996
+ },
3997
+ older: i,
3998
+ prevSeg: o
3999
+ };
4000
+ }
4001
+ //#endregion
4002
+ //#region src/core/composables/contextIndex.ts
4003
+ var lo = /* @__PURE__ */ new Set(/* @__PURE__ */ "的.了.是.在.我.你.他.她.它.这.那.和.与.及.或.一个.什么.怎么.如何.为什么.可以.能.请.帮.一下.需要.想要.the.a.an.is.are.of.to.in.on".split("."));
4004
+ function uo(e) {
4005
+ return e.toLowerCase().split(/[^a-z0-9一-龥]+/i).map((e) => e.trim()).filter((e) => e.length >= 2 && !lo.has(e));
4006
+ }
4007
+ function fo(e) {
4008
+ let t = typeof e.content == "string" ? e.content : "";
4009
+ if (e.reasoning && (t += e.reasoning), e.steps) for (let n of e.steps) t += " " + (n.name || ""), n.args != null && (t += " " + (typeof n.args == "string" ? n.args : JSON.stringify(n.args))), n.result && (t += " " + n.result);
4010
+ return X(t);
4011
+ }
4012
+ function po(e) {
4013
+ let t = fo(e.userMsg);
4014
+ for (let n of e.assistantMsgs) t += fo(n);
4015
+ return t;
4016
+ }
4017
+ function mo(e, t) {
4018
+ return e.map((e) => {
4019
+ let n = to(e.userMsg.content, 60) || "(空)", r = e.assistantMsgs[0] ? to(e.assistantMsgs[0].content, 80) : "(无回复)", i = e.assistantMsgs.flatMap((e) => (e.steps || []).map((e) => e.name)), a = i.length ? ` [工具: ${i.join(", ")}]` : "", o = "";
4020
+ if (t && t.size) {
4021
+ let n = [];
4022
+ for (let r of e.assistantMsgs) for (let e of r.steps || []) e.name && t.has(e.name) && e.result && n.push(`${e.name}: ${to(e.result, 120)}`);
4023
+ n.length && (o = `\n 字段提示: ${n.join(" | ")}`);
4024
+ }
4025
+ return `- 第${e.round}轮:${n} → ${r}${a}${o}`;
4026
+ }).join("\n");
4027
+ }
4028
+ function ho(e, t, n) {
4029
+ let r = uo(t);
4030
+ return r.length === 0 ? [] : e.map((e) => {
4031
+ let t = (e.userMsg.content + " " + e.assistantMsgs.map((e) => e.content).join(" ") + " " + e.assistantMsgs.flatMap((e) => (e.steps || []).map((e) => to(e.result || "", 120))).join(" ")).toLowerCase(), n = 0;
4032
+ for (let e of r) t.includes(e) && n++;
4033
+ return {
4034
+ r: e,
4035
+ score: n
4036
+ };
4037
+ }).filter((e) => e.score > 0).sort((e, t) => t.score - e.score).slice(0, n).map((e) => e.r);
4038
+ }
4039
+ function go(e, t) {
4040
+ return t.contextWindow && t.contextWindow > 0 ? e.reduce((e, t) => e + po(t), 0) > t.contextWindow * (t.summaryThresholdRatio ?? .5) : e.length > (t.summaryThresholdRounds ?? 8);
4041
+ }
4042
+ //#endregion
4043
+ //#region src/core/composables/useContextManager.ts
4044
+ var _o = {
4045
+ windowRounds: 6,
4046
+ summaryThresholdRounds: 8,
4047
+ toolResultMaxChars: 800,
4048
+ enableRecall: !0,
4049
+ recallTopK: 3,
4050
+ enableLLMSummary: !1
4051
+ };
4052
+ function vo(e = {}) {
4053
+ let t = {
4054
+ ..._o,
4055
+ ...e
4056
+ };
4057
+ async function n(e, n) {
4058
+ let r = eo(e), i = e.length, a = "";
4059
+ if (r.length) {
4060
+ let t = r[0].startIdx;
4061
+ for (let n = 0; n < t; n++) {
4062
+ let t = e[n];
4063
+ if (t.role === "system") {
4064
+ let e = ao(t.content);
4065
+ if (e) {
4066
+ a = e.body;
4067
+ break;
4068
+ }
4069
+ }
4070
+ }
4071
+ }
4072
+ let o = (t) => ({
4073
+ messages: e,
4074
+ stats: {
4075
+ triggered: !1,
4076
+ roundsTotal: r.length,
4077
+ roundsSummarized: 0,
4078
+ roundsRecalled: 0,
4079
+ originalMessages: i,
4080
+ compressedMessages: i,
4081
+ strategy: t
4082
+ }
4083
+ });
4084
+ if (!go(r, t)) return o("none");
4085
+ let s, c, l;
4086
+ if (t.contextWindow && t.contextWindow > 0) {
4087
+ let e = t.contextWindow * (n?.windowRatio ?? t.windowRatio ?? .4), i = 0, a = 0;
4088
+ for (let t = r.length - 1; t >= 0; t--) if (i += po(r[t]), i >= e) {
4089
+ a = t + 1;
4090
+ break;
4091
+ }
4092
+ if (a > r.length - 1 && (a = r.length - 1), a < 0 && (a = 0), s = r.slice(a), c = r.slice(0, a), !c.length) return o("none");
4093
+ l = "token-window+";
4094
+ } else {
4095
+ let e = n?.keepRounds ?? t.windowRounds, i = Math.min(Math.max(1, e), r.length);
4096
+ if (s = r.slice(r.length - i), c = r.slice(0, r.length - i), !c.length) return o("none");
4097
+ l = "window+";
4098
+ }
4099
+ let u = [...e].reverse().find((e) => e.role === "user")?.content || "", d = n?.summarize?.mode ?? (t.enableLLMSummary ? "llm" : "index"), f = /* @__PURE__ */ new Set([...t.preserveLastToolResults ?? [], ...n?.preserveTools ?? []]), p = f.size ? f : void 0, m, h;
4100
+ if (d === "llm" && t.llmInvoke) try {
4101
+ m = await t.llmInvoke(mo(c, p)), h = l + "llm_summary";
4102
+ } catch {
4103
+ m = mo(c, p), h = l + "index_summary(llm_fallback)";
4104
+ }
4105
+ else m = mo(c, p), h = l + "index_summary";
4106
+ let g = n?.recallTopK == null ? t.enableRecall ? t.recallTopK : 0 : n.recallTopK, _ = g > 0 ? ho(c, u, g) : [], v = _.length ? _.map((e) => `- 第${e.round}轮:${to(e.userMsg.content, 60)} → ${e.assistantMsgs[0] ? to(e.assistantMsgs[0].content, 80) : ""}`).join("\n") : "", y = a ? `${m}\n【更早累积摘要】\n${a}` : m, b = [`【对话历史摘要】以下是之前 ${c.length} 轮对话的要点(最新 ${s.length} 轮已完整保留):`, y];
4107
+ if (n) {
4108
+ let e = t.contextWindow && t.contextWindow > 0 ? `windowRatio=${n.windowRatio ?? t.windowRatio}` : `keepRounds=${n.keepRounds ?? t.windowRounds}`;
4109
+ b.push(`\n(压缩决策:${e} · 摘要=${n.summarize.mode} · 召回=${g}${n.reason ? " · " + n.reason : ""})`);
4110
+ }
4111
+ v && b.push("\n【与当前问题可能相关的早期对话】", v);
4112
+ let x = t.getRegisteredData ?? t.getRegisteredSlots;
4113
+ if (x) try {
4114
+ let e = x();
4115
+ if (e.length) {
4116
+ let t = e.map((e) => `- ${e.path ? e.path + ": " : ""}${e.description}`).join("\n");
4117
+ b.push("\n【当前可操作数据(动态增删后的最新状态,操作前以 describe_data / read 为准)】", t);
4118
+ }
4119
+ } catch {}
4120
+ let S = {
4121
+ role: "system",
4122
+ content: b.join("\n"),
4123
+ timestamp: Date.now()
4124
+ }, C = [];
4125
+ for (let e of s) C.push(e.userMsg), C.push(...e.assistantMsgs);
4126
+ let w = [S, ...C], T = w.reduce((e, t) => e + X(typeof t.content == "string" ? t.content : JSON.stringify(t.content)), 0);
4127
+ return t.contextWindow && T > t.contextWindow && console.warn(`[page-agent-sdk] compress 后仍超窗口:${T} > ${t.contextWindow} tokens(单条消息超窗口,compress 无法压)`), {
4128
+ messages: w,
4129
+ stats: {
4130
+ triggered: !0,
4131
+ roundsTotal: r.length,
4132
+ roundsSummarized: c.length,
4133
+ roundsRecalled: _.length,
4134
+ originalMessages: i,
4135
+ compressedMessages: w.length,
4136
+ strategy: h,
4137
+ decision: n
4138
+ }
4139
+ };
4140
+ }
4141
+ return {
4142
+ compress: n,
4143
+ config: t
4144
+ };
4145
+ }
4146
+ //#endregion
4147
+ //#region src/core/harness/summarization.ts
4148
+ function yo(e = {}) {
4149
+ let t = vo(e);
4150
+ return Object.assign({
4151
+ name: "summarization",
4152
+ compressInput: async (n) => {
4153
+ let r;
4154
+ if (e.decideInvoke) {
4155
+ let i = eo(n);
4156
+ if (go(i, t.config)) {
4157
+ let a = t.config.contextWindow && t.config.contextWindow > 0 ? "token" : "rounds", o = a === "token" ? `历史 token 超阈值 ${Math.round((t.config.contextWindow ?? 0) * (t.config.summaryThresholdRatio ?? .5))}` : `轮数 ${i.length} 超阈值 ${t.config.summaryThresholdRounds}`;
4158
+ try {
4159
+ r = await e.decideInvoke({
4160
+ getMessages: () => n,
4161
+ getSnapshot: e.getSnapshot,
4162
+ contextWindow: t.config.contextWindow,
4163
+ thresholdRatio: t.config.summaryThresholdRatio,
4164
+ triggerReason: o,
4165
+ triggerMode: a
4166
+ }) ?? void 0;
4167
+ } catch {
4168
+ r = void 0;
4169
+ }
4170
+ }
4171
+ }
4172
+ let { messages: i, stats: a } = await t.compress(n, r);
4173
+ return {
4174
+ messages: i,
4175
+ stats: a
4176
+ };
4177
+ }
4178
+ }, { setContextWindow(e) {
4179
+ t.config.contextWindow = e;
4180
+ } });
4181
+ }
4182
+ //#endregion
4183
+ //#region src/core/harness/subagent.ts
4184
+ function bo(e) {
3931
4185
  return !!e && typeof e == "object" && typeof e.invoke == "function" && typeof e.stream == "function";
3932
4186
  }
3933
- var to = [
4187
+ var xo = [
3934
4188
  "describe_data",
3935
4189
  "get_data",
3936
4190
  "read",
3937
4191
  "query_data",
3938
4192
  "search_data",
3939
4193
  "fetch_document"
3940
- ], no = 1, ro = 4, io = 6, ao = ["spawn_agent", "spawn_agents"], oo = [
4194
+ ], So = 1, Co = 4, wo = 6, To = ["spawn_agent", "spawn_agents"], Eo = [
3941
4195
  "write",
3942
4196
  "set_data",
3943
4197
  "edit_data",
3944
4198
  "delete_data",
3945
4199
  "draft_commit"
3946
4200
  ];
3947
- function so(e) {
4201
+ function Do(e) {
3948
4202
  let t = [];
3949
4203
  if (typeof e.jsonPath == "string" && e.jsonPath && t.push(e.jsonPath), typeof e.path == "string" && e.path && t.push(e.path), e.patch && typeof e.patch.jsonPath == "string" && t.push(e.patch.jsonPath), Array.isArray(e.patches)) for (let n of e.patches) n && typeof n.jsonPath == "string" && t.push(n.jsonPath);
3950
4204
  return t;
3951
4205
  }
3952
- function co(e, t) {
4206
+ function Oo(e, t) {
3953
4207
  return t.some((t) => e === t || e.startsWith(t + ".") || e.startsWith(t + "["));
3954
4208
  }
3955
- function lo(e, t) {
4209
+ function ko(e, t) {
3956
4210
  let n = e.invoke.bind(e), r = async (e) => {
3957
- let r = so(e);
4211
+ let r = Do(e);
3958
4212
  if (!r.length) return `PATH_OUT_OF_SCOPE:子 agent 仅可增量 patch(writablePaths: ${t.join(", ")}),不能整体替换(无 jsonPath)。用 write({patch:{jsonPath,...}}) 增量改。`;
3959
- for (let e of r) if (!co(e, t)) return `PATH_OUT_OF_SCOPE:子 agent 写 "${e}" 越界(仅可写 ${t.join(", ")})。`;
4213
+ for (let e of r) if (!Oo(e, t)) return `PATH_OUT_OF_SCOPE:子 agent 写 "${e}" 越界(仅可写 ${t.join(", ")})。`;
3960
4214
  return n(e);
3961
4215
  };
3962
4216
  return new Proxy(e, { get(e, t, n) {
3963
4217
  return t === "invoke" ? r : Reflect.get(e, t, n);
3964
4218
  } });
3965
4219
  }
3966
- async function uo(e, t, n, r, i) {
3967
- let a = t.depth ?? 0, o = t.maxDepth ?? no, s = /* @__PURE__ */ new Set([...to, ...t.allowedTools ?? []]), c = () => typeof t.allTools == "function" ? t.allTools() : t.allTools, l = [...c().filter((e) => s.has(e.name) && !ao.includes(e.name)), ...t.extraTools ?? []];
4220
+ async function Ao(e, t, n, r, i) {
4221
+ let a = t.depth ?? 0, o = t.maxDepth ?? So, s = /* @__PURE__ */ new Set([...xo, ...t.allowedTools ?? []]), c = () => typeof t.allTools == "function" ? t.allTools() : t.allTools, l = [...c().filter((e) => s.has(e.name) && !To.includes(e.name)), ...t.extraTools ?? []];
3968
4222
  if (t.writablePaths?.length) {
3969
- l = l.filter((e) => !oo.includes(e.name));
3970
- let e = c().filter((e) => oo.includes(e.name) && !ao.includes(e.name)).map((e) => lo(e, t.writablePaths));
4223
+ l = l.filter((e) => !Eo.includes(e.name));
4224
+ let e = c().filter((e) => Eo.includes(e.name) && !To.includes(e.name)).map((e) => ko(e, t.writablePaths));
3971
4225
  l = [...l, ...e];
3972
4226
  }
3973
- let u = a + 1 < o ? [fo({
4227
+ let u = a + 1 < o ? [jo({
3974
4228
  ...t,
3975
4229
  depth: a + 1
3976
4230
  })] : [], d = t.getFocuses?.() ?? [], f = d.length ? pa({
3977
4231
  getSchema: t.getSchema ?? (() => null),
3978
4232
  initialFocuses: d
3979
4233
  }) : void 0, p = ni({
3980
- model: eo(t.llm) ? t.llm.model ?? t.llm.modelName : e.model ?? t.llm.model,
4234
+ model: bo(t.llm) ? t.llm.model ?? t.llm.modelName : e.model ?? t.llm.model,
3981
4235
  contextWindow: t.llm.contextWindow,
3982
4236
  maxOutputTokens: t.llm.maxOutputTokens
3983
4237
  });
3984
4238
  if (p.contextWindow < 2e5) throw Error(`[page-agent-sdk][subagent] 子 agent 模型上下文窗口 ${p.contextWindow} 小于最小支持 ${ti}(需 ≥200K 窗口模型)`);
3985
- let m = ji({
4239
+ let m = t.summarization === void 0 ? void 0 : yo(typeof t.summarization == "object" ? {
4240
+ contextWindow: p.contextWindow,
4241
+ ...t.summarization
4242
+ } : { contextWindow: p.contextWindow }), h = ji({
3986
4243
  contextWindow: p.contextWindow,
3987
4244
  maxOutputTokens: p.maxOutputTokens,
3988
- ...eo(t.llm) ? { llm: t.llm } : {
4245
+ ...bo(t.llm) ? { llm: t.llm } : {
3989
4246
  apiKey: t.llm.apiKey,
3990
4247
  baseUrl: t.llm.baseUrl,
3991
4248
  model: e.model ?? t.llm.model,
@@ -3996,14 +4253,16 @@ async function uo(e, t, n, r, i) {
3996
4253
  tools: l,
3997
4254
  middleware: [
3998
4255
  ...t.skills?.length ? [Na(t.skills)] : [],
4256
+ ...m ? [m] : [],
3999
4257
  ...u,
4000
- ...f ? [f] : []
4258
+ ...f ? [f] : [],
4259
+ ...t.middleware ?? []
4001
4260
  ],
4002
- maxToolRounds: t.maxToolRounds ?? io,
4261
+ maxToolRounds: t.maxToolRounds ?? wo,
4003
4262
  onLog: i,
4004
4263
  debug: t.debug
4005
4264
  });
4006
- return t.debug && console.log(`[subagent] 启动子 agent(depth=${a},工具 ${l.length} 个)`), m.stream([{
4265
+ return t.debug && console.log(`[subagent] 启动子 agent(depth=${a},工具 ${l.length} 个)`), h.stream([{
4007
4266
  role: "user",
4008
4267
  content: e.prompt,
4009
4268
  timestamp: Date.now()
@@ -4011,8 +4270,8 @@ async function uo(e, t, n, r, i) {
4011
4270
  r && (e.type === "tool_call" || e.type === "tool_result") && r(e);
4012
4271
  }, n);
4013
4272
  }
4014
- function fo(e) {
4015
- let n = e.maxParallel ?? ro, i, a, o, s = (e, t) => (n) => {
4273
+ function jo(e) {
4274
+ let n = e.maxParallel ?? Co, i, a, o, s = (e, t) => (n) => {
4016
4275
  a && a({
4017
4276
  type: "subagent",
4018
4277
  taskId: e,
@@ -4032,7 +4291,7 @@ function fo(e) {
4032
4291
  ...r?.length ? { allowedTools: r } : {},
4033
4292
  ...a?.length ? { writablePaths: a } : {}
4034
4293
  } : e, u = `sub-${Math.random().toString(36).slice(2, 8)}`, d = n?.trim() || "子任务";
4035
- return await uo({
4294
+ return await Ao({
4036
4295
  prompt: t,
4037
4296
  role: n,
4038
4297
  model: c
@@ -4052,7 +4311,7 @@ function fo(e) {
4052
4311
  })
4053
4312
  }), r(async ({ tasks: t }) => (await Qr(t, n, async (t, n) => {
4054
4313
  let r = `sub-${n}-${Math.random().toString(36).slice(2, 6)}`, a = t.role?.trim() || `子任务${n + 1}`;
4055
- return uo(t, e, i, s(r, a), (e) => o?.({
4314
+ return Ao(t, e, i, s(r, a), (e) => o?.({
4056
4315
  ...e,
4057
4316
  source: `子:${a}`
4058
4317
  }));
@@ -4067,8 +4326,8 @@ function fo(e) {
4067
4326
  wrapToolCall: async (e, t) => (e.signal && (i = e.signal), e.emit && (a = e.emit), e.logSink && (o = e.logSink), t(e))
4068
4327
  };
4069
4328
  }
4070
- var po = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
4071
- function mo(e, t) {
4329
+ var Mo = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
4330
+ function No(e, t) {
4072
4331
  let n = e.tools ?? [];
4073
4332
  return {
4074
4333
  llm: e.llm ?? t.llm,
@@ -4081,11 +4340,14 @@ function mo(e, t) {
4081
4340
  maxToolRounds: e.maxToolRounds,
4082
4341
  debug: t.debug,
4083
4342
  ...e.writablePaths?.length ? { writablePaths: e.writablePaths } : {},
4343
+ ...e.allowedTools?.length ? { allowedTools: e.allowedTools } : {},
4344
+ ...e.middleware?.length ? { middleware: e.middleware } : {},
4345
+ ...e.summarization === void 0 ? {} : { summarization: e.summarization },
4084
4346
  ...t.getFocuses ? { getFocuses: t.getFocuses } : {},
4085
4347
  ...t.getSchema ? { getSchema: t.getSchema } : {}
4086
4348
  };
4087
4349
  }
4088
- function ho(e, n) {
4350
+ function Po(e, n) {
4089
4351
  let i, a, o, s = (e, t) => (n) => {
4090
4352
  a && a({
4091
4353
  type: "subagent",
@@ -4101,7 +4363,7 @@ function ho(e, n) {
4101
4363
  function d(e) {
4102
4364
  let a = /* @__PURE__ */ new Set(), c = [], l = [];
4103
4365
  for (let u of e) {
4104
- if (!po.test(u.id)) {
4366
+ if (!Mo.test(u.id)) {
4105
4367
  console.warn(`[subagents] id "${u.id}" 非合法工具名(须 [a-zA-Z_][a-zA-Z0-9_]*),已跳过`);
4106
4368
  continue;
4107
4369
  }
@@ -4111,8 +4373,8 @@ function ho(e, n) {
4111
4373
  continue;
4112
4374
  }
4113
4375
  a.add(e), c.push(u), l.push(r(async ({ task: e }) => {
4114
- let t = mo(u, n);
4115
- return uo({ prompt: e }, t, i, s(`use_${u.id}`, u.id), (e) => o?.({
4376
+ let t = No(u, n);
4377
+ return Ao({ prompt: e }, t, i, s(`use_${u.id}`, u.id), (e) => o?.({
4116
4378
  ...e,
4117
4379
  source: `子:${u.id}`
4118
4380
  }));
@@ -4156,7 +4418,7 @@ function ho(e, n) {
4156
4418
  augmentPrompt: () => c.length ? [
4157
4419
  "## 可用子 agent(预声明,经专属工具委派)",
4158
4420
  ...c.map((e) => `- use_${e.id}: ${e.description}`),
4159
- "需要某子 agent 时,直接调用对应的 use_<id>({ task }) 委派,任务描述要清晰。"
4421
+ "复杂或专项任务(检索 / 生成 / 调研 / 多步等)优先委派子 agent:过程隔离不占主上下文 + 各子 agent 专项处理更优。需要时直接调 use_<id>({ task }) 委派,任务描述要清晰(含背景 + 用户观点/反馈,转述给子 agent);委派后信任子 agent 自主完成,不微操、不读其代码/中间细节(少占主上下文),只据其结论继续。简单任务(单字段改、直接读)用内置工具更快,不必委派。"
4160
4422
  ].join("\n") : void 0,
4161
4423
  wrapToolCall: async (e, t) => (e.signal && (i = e.signal), e.emit && (a = e.emit), e.logSink && (o = e.logSink), t(e))
4162
4424
  };
@@ -4172,7 +4434,7 @@ function ho(e, n) {
4172
4434
  }
4173
4435
  //#endregion
4174
4436
  //#region src/core/harness/verify.ts
4175
- function go(e) {
4437
+ function Fo(e) {
4176
4438
  return {
4177
4439
  name: "verify",
4178
4440
  async beforeReturn({ messages: t, state: n, log: r }) {
@@ -4184,10 +4446,10 @@ function go(e) {
4184
4446
  if (e.adversarial) {
4185
4447
  r?.("middleware", {
4186
4448
  stage: "adversarial_start",
4187
- model: wo(e.adversarial.llm),
4449
+ model: Uo(e.adversarial.llm),
4188
4450
  tools: (e.adversarial.tools ?? []).length
4189
4451
  });
4190
- let n = await Oo(t, e.adversarial.llm, r, e.adversarial.tools);
4452
+ let n = await qo(t, e.adversarial.llm, r, e.adversarial.tools);
4191
4453
  if (r?.("middleware", {
4192
4454
  stage: "adversarial_done",
4193
4455
  clean: n === null,
@@ -4198,18 +4460,18 @@ function go(e) {
4198
4460
  }
4199
4461
  };
4200
4462
  }
4201
- var _o = /* @__PURE__ */ new Set([
4463
+ var Io = /* @__PURE__ */ new Set([
4202
4464
  "set_data",
4203
4465
  "edit_data",
4204
4466
  "delete_data",
4205
4467
  "write"
4206
- ]), vo = /校验失败|SCHEMA_INVALID|未注册|不存在|仅支持|必须是|NOT_OBJECT|PATH_UNSAFE|VERSION_CONFLICT|WRITE_INTERCEPT/;
4207
- function yo(e) {
4468
+ ]), Lo = /校验失败|SCHEMA_INVALID|未注册|不存在|仅支持|必须是|NOT_OBJECT|PATH_UNSAFE|VERSION_CONFLICT|WRITE_INTERCEPT/;
4469
+ function Ro(e) {
4208
4470
  let t = /* @__PURE__ */ new Map();
4209
4471
  for (let n of e) {
4210
4472
  let e = n?.tool_calls;
4211
4473
  if (Array.isArray(e)) for (let n of e) {
4212
- if (!_o.has(n.name)) continue;
4474
+ if (!Io.has(n.name)) continue;
4213
4475
  let e = n.id, r = n?.args ?? {};
4214
4476
  if (n.name === "write") if (r.del && r.patch?.jsonPath) t.set(r.patch.jsonPath, {
4215
4477
  path: r.patch.jsonPath,
@@ -4248,7 +4510,7 @@ function yo(e) {
4248
4510
  }
4249
4511
  return [...t.values()];
4250
4512
  }
4251
- function bo(e) {
4513
+ function zo(e) {
4252
4514
  let t = /* @__PURE__ */ new Map();
4253
4515
  for (let n of e) {
4254
4516
  let e = n?.tool_call_id, r = n?.content;
@@ -4256,7 +4518,7 @@ function bo(e) {
4256
4518
  }
4257
4519
  return t;
4258
4520
  }
4259
- function xo(e, t) {
4521
+ function Bo(e, t) {
4260
4522
  if (t === "") return e;
4261
4523
  if (e == null) return;
4262
4524
  let n = e;
@@ -4266,16 +4528,16 @@ function xo(e, t) {
4266
4528
  }
4267
4529
  return n;
4268
4530
  }
4269
- function So(e = {}) {
4531
+ function Vo(e = {}) {
4270
4532
  let t = typeof e.root == "function" ? e.root : e.root === void 0 ? () => e.window ?? globalThis.window : () => e.root, n = typeof e.schemas == "function" ? e.schemas : () => e.schemas ?? {};
4271
4533
  return async ({ messages: e }) => {
4272
- let r = yo(e);
4534
+ let r = Ro(e);
4273
4535
  if (!r.length) return { ok: !0 };
4274
- let i = bo(e), a = n()[""], o = t(), s = [];
4536
+ let i = zo(e), a = n()[""], o = t(), s = [];
4275
4537
  for (let { path: e, op: t, callId: n } of r) {
4276
4538
  let r = n ? i.get(n) : void 0;
4277
- if (r && vo.test(r)) continue;
4278
- let c = xo(o, e);
4539
+ if (r && Lo.test(r)) continue;
4540
+ let c = Bo(o, e);
4279
4541
  if (t === "delete_data") c !== void 0 && s.push(`${e} 删除后读回仍有值,疑似未生效`);
4280
4542
  else if (c == null) s.push(`写入 ${e} 后读回为空,疑似未生效`);
4281
4543
  else if (a) {
@@ -4289,17 +4551,17 @@ function So(e = {}) {
4289
4551
  } : { ok: !0 };
4290
4552
  };
4291
4553
  }
4292
- function Co(e) {
4554
+ function Ho(e) {
4293
4555
  return !!e && typeof e == "object" && typeof e.invoke == "function" && typeof e.stream == "function";
4294
4556
  }
4295
- function wo(e) {
4296
- return Co(e) ? e.model ?? e.modelName ?? "<实例>" : e.model ?? "<配置>";
4557
+ function Uo(e) {
4558
+ return Ho(e) ? e.model ?? e.modelName ?? "<实例>" : e.model ?? "<配置>";
4297
4559
  }
4298
- var To = /无问题|没有问题|未发现问题|没有发现|没问题|未发现/;
4299
- function Eo(e) {
4300
- return To.test(e);
4560
+ var Wo = /无问题|没有问题|未发现问题|没有发现|没问题|未发现/;
4561
+ function Go(e) {
4562
+ return Wo.test(e);
4301
4563
  }
4302
- function Do(e) {
4564
+ function Ko(e) {
4303
4565
  let t = "", n = "";
4304
4566
  for (let r of e) r instanceof a ? t = typeof r.content == "string" ? r.content : "" : r instanceof i && !(r.tool_calls?.length > 0) && (n = typeof r.content == "string" ? r.content : "");
4305
4567
  return {
@@ -4307,8 +4569,8 @@ function Do(e) {
4307
4569
  lastReply: n
4308
4570
  };
4309
4571
  }
4310
- async function Oo(e, t, n, r) {
4311
- let { lastUser: i, lastReply: a } = Do(e);
4572
+ async function qo(e, t, n, r) {
4573
+ let { lastUser: i, lastReply: a } = Ko(e);
4312
4574
  if (!a) return null;
4313
4575
  let o = Array.isArray(r) && r.length > 0, s = [
4314
4576
  "你是严格的对抗式审查者,目标是找出以下 AI 助手回复的错误并证明它有问题(事实错误 / 遗漏 / 逻辑矛盾 / 与需求不符)。",
@@ -4319,7 +4581,7 @@ async function Oo(e, t, n, r) {
4319
4581
  ].join("\n"), c = "你是严格的对抗式审查者,只找问题不赞美。目标是反驳,不是改进。", l = n ? (e) => n(e.type, {
4320
4582
  ...e.data,
4321
4583
  source: "adversarial"
4322
- }) : void 0, u = await ji(Co(t) ? {
4584
+ }) : void 0, u = await ji(Ho(t) ? {
4323
4585
  llm: t,
4324
4586
  tools: r,
4325
4587
  maxToolRounds: o ? 4 : 1,
@@ -4344,11 +4606,11 @@ async function Oo(e, t, n, r) {
4344
4606
  stage: "adversarial_verdict",
4345
4607
  verdict: u,
4346
4608
  source: "adversarial"
4347
- }), Eo(u) ? null : u.trim();
4609
+ }), Go(u) ? null : u.trim();
4348
4610
  }
4349
4611
  //#endregion
4350
4612
  //#region src/core/utils/contextAnalysis.ts
4351
- var ko = [
4613
+ var Jo = [
4352
4614
  {
4353
4615
  prefix: "## 可操作数据",
4354
4616
  key: "dataHint"
@@ -4377,7 +4639,7 @@ var ko = [
4377
4639
  prefix: "【与当前问题可能相关的早期对话】",
4378
4640
  key: "recall"
4379
4641
  }
4380
- ], Ao = [
4642
+ ], Yo = [
4381
4643
  {
4382
4644
  key: "systemPrompt",
4383
4645
  label: "系统提示词(身份/规则)"
@@ -4431,9 +4693,9 @@ var ko = [
4431
4693
  label: "其他"
4432
4694
  }
4433
4695
  ];
4434
- function jo() {
4696
+ function Xo() {
4435
4697
  let e = {};
4436
- for (let t of Ao) e[t.key] = {
4698
+ for (let t of Yo) e[t.key] = {
4437
4699
  key: t.key,
4438
4700
  label: t.label,
4439
4701
  tokens: 0,
@@ -4442,16 +4704,16 @@ function jo() {
4442
4704
  };
4443
4705
  return e;
4444
4706
  }
4445
- function Mo(e, t) {
4707
+ function Zo(e, t) {
4446
4708
  e.tokens += t, e.msgCount += 1;
4447
4709
  }
4448
- function No(e) {
4710
+ function Qo(e) {
4449
4711
  let t = e.content;
4450
4712
  return typeof t == "string" ? t : JSON.stringify(t ?? "");
4451
4713
  }
4452
- function Po(e, t) {
4714
+ function $o(e, t) {
4453
4715
  let n = [];
4454
- for (let t of ko) {
4716
+ for (let t of Jo) {
4455
4717
  let r = 0;
4456
4718
  for (;;) {
4457
4719
  let i = e.indexOf(t.prefix, r);
@@ -4464,35 +4726,35 @@ function Po(e, t) {
4464
4726
  }
4465
4727
  if (n.sort((e, t) => e.idx - t.idx), !n.length) {
4466
4728
  let n = e.trim();
4467
- n && Mo(t.systemPrompt, X(n));
4729
+ n && Zo(t.systemPrompt, X(n));
4468
4730
  return;
4469
4731
  }
4470
4732
  if (n[0].idx > 0) {
4471
4733
  let r = e.slice(0, n[0].idx).trim();
4472
- r && Mo(t.systemPrompt, X(r));
4734
+ r && Zo(t.systemPrompt, X(r));
4473
4735
  }
4474
4736
  for (let r = 0; r < n.length; r++) {
4475
4737
  let i = n[r].idx, a = r + 1 < n.length ? n[r + 1].idx : e.length, o = e.slice(i, a).trim();
4476
- o && Mo(t[n[r].key], X(o));
4738
+ o && Zo(t[n[r].key], X(o));
4477
4739
  }
4478
4740
  }
4479
- function Fo(e, t = {}) {
4480
- let n = jo(), r = -1;
4741
+ function es(e, t = {}) {
4742
+ let n = Xo(), r = -1;
4481
4743
  for (let t = e.length - 1; t >= 0; t--) if (e[t] instanceof a) {
4482
4744
  r = t;
4483
4745
  break;
4484
4746
  }
4485
4747
  for (let t = 0; t < e.length; t++) {
4486
4748
  let c = e[t];
4487
- if (c instanceof o) Po(No(c), n);
4488
- else if (c instanceof a) Mo(n[t === r ? "current" : "history"], X(No(c)));
4749
+ if (c instanceof o) $o(Qo(c), n);
4750
+ else if (c instanceof a) Zo(n[t === r ? "current" : "history"], X(Qo(c)));
4489
4751
  else if (c instanceof i) {
4490
4752
  let e = c.tool_calls ?? [];
4491
4753
  if (e.length) {
4492
4754
  let t = e.map((e) => JSON.stringify(e.args ?? {})).join(" ");
4493
- Mo(n.toolResults, X(t));
4494
- } else Mo(n.assistant, X(No(c)));
4495
- } else c instanceof s ? Mo(n.toolResults, X(No(c))) : Mo(n.other, X(No(c)));
4755
+ Zo(n.toolResults, X(t));
4756
+ } else Zo(n.assistant, X(Qo(c)));
4757
+ } else c instanceof s ? Zo(n.toolResults, X(Qo(c))) : Zo(n.other, X(Qo(c)));
4496
4758
  }
4497
4759
  let c = Object.values(n).filter((e) => e.tokens > 0);
4498
4760
  c.sort((e, t) => t.tokens - e.tokens);
@@ -4509,12 +4771,12 @@ function Fo(e, t = {}) {
4509
4771
  }
4510
4772
  //#endregion
4511
4773
  //#region src/core/harness/contextInspector.ts
4512
- function Io(e = {}) {
4774
+ function ts(e = {}) {
4513
4775
  let t, n = e.contextWindow;
4514
4776
  return {
4515
4777
  name: "context-inspector",
4516
4778
  async wrapModelCall(r, i) {
4517
- return t = Fo(r.messages, {
4779
+ return t = es(r.messages, {
4518
4780
  contextWindow: n,
4519
4781
  thresholdRatio: e.thresholdRatio
4520
4782
  }), i(r);
@@ -4527,13 +4789,13 @@ function Io(e = {}) {
4527
4789
  }
4528
4790
  //#endregion
4529
4791
  //#region src/core/mcp/client.ts
4530
- function Lo(e) {
4792
+ function ns(e) {
4531
4793
  let t = e?.content;
4532
4794
  if (!Array.isArray(t) || !t.length) return "";
4533
4795
  let n = t.map((e) => e.type === "text" && e.text ? e.text : e.type === "image" && e.data ? `[image:${String(e.data).slice(0, 32)}…]` : e.type === "audio" && e.data ? "[audio]" : e.type === "resource" && e.resource ? e.resource.text ?? e.resource.blob ?? "" : "").filter(Boolean).join("\n");
4534
4796
  return e?.isError ? `工具错误:${n}` : n;
4535
4797
  }
4536
- async function Ro(e) {
4798
+ async function rs(e) {
4537
4799
  let t = new URL(e.url), n = e.requestInit;
4538
4800
  if (e.transport === "http") {
4539
4801
  let { StreamableHTTPClientTransport: e } = await import("@modelcontextprotocol/sdk/client/streamableHttp.js");
@@ -4546,8 +4808,8 @@ async function Ro(e) {
4546
4808
  let { WebSocketClientTransport: r } = await import("@modelcontextprotocol/sdk/client/websocket.js");
4547
4809
  return new r(t);
4548
4810
  }
4549
- function zo(e, t) {
4550
- return r(async (n) => Lo(await t.callTool({
4811
+ function is(e, t) {
4812
+ return r(async (n) => ns(await t.callTool({
4551
4813
  name: e.name,
4552
4814
  arguments: n
4553
4815
  })), {
@@ -4556,273 +4818,19 @@ function zo(e, t) {
4556
4818
  schema: e.inputSchema
4557
4819
  });
4558
4820
  }
4559
- async function Bo(e) {
4560
- let { Client: t } = await import("@modelcontextprotocol/sdk/client"), n = await Ro(e), r = new t({
4821
+ async function as(e) {
4822
+ let { Client: t } = await import("@modelcontextprotocol/sdk/client"), n = await rs(e), r = new t({
4561
4823
  name: "page-agent-sdk",
4562
4824
  version: "1.0"
4563
4825
  }, { capabilities: {} });
4564
4826
  await r.connect(n);
4565
4827
  let { tools: i } = await r.listTools();
4566
4828
  return {
4567
- tools: i.map((e) => zo(e, r)),
4829
+ tools: i.map((e) => is(e, r)),
4568
4830
  close: () => r.close()
4569
4831
  };
4570
4832
  }
4571
4833
  //#endregion
4572
- //#region src/core/utils/rounds.ts
4573
- function Vo(e) {
4574
- let t = [], n = null, r = 0;
4575
- for (let i = 0; i < e.length; i++) {
4576
- let a = e[i];
4577
- a.role === "user" ? (n && t.push(n), r++, n = {
4578
- round: r,
4579
- userMsg: a,
4580
- assistantMsgs: [],
4581
- startIdx: i,
4582
- endIdx: i
4583
- }) : n && (n.assistantMsgs.push(a), n.endIdx = i);
4584
- }
4585
- return n && t.push(n), t;
4586
- }
4587
- function Ho(e, t) {
4588
- let n = (e || "").replace(/```[\s\S]*?```/g, "[代码]").replace(/`([^`]+)`/g, "$1").replace(/[#*_>\-]\s?/g, "").replace(/\[(代码)\]/g, "「代码」").replace(/\s+/g, " ").trim();
4589
- return n.length > t ? n.slice(0, t) + "…" : n;
4590
- }
4591
- function Uo(e) {
4592
- let t = [];
4593
- for (let n of e.assistantMsgs) for (let e of n.steps || []) t.push(e.name);
4594
- return t;
4595
- }
4596
- var Wo = "【更早对话摘要";
4597
- function Go(e, t) {
4598
- return !t || !t.body ? e : {
4599
- body: `${t.body}\n【续】\n${e.body}`,
4600
- rounds: (t.rounds ?? 0) + (e.rounds ?? 0),
4601
- cumulative: !0
4602
- };
4603
- }
4604
- function Ko(e) {
4605
- return typeof e != "string" || !e.startsWith("【更早对话摘要") ? null : { body: e.replace(/^【[^】]*】\n?/, "") };
4606
- }
4607
- function qo(e) {
4608
- return `${Wo}${e.cumulative ? `(${e.rounds ?? 0} 轮,含累积)` : e.rounds ? `(${e.rounds} 轮)` : ""}】\n${e.body}`;
4609
- }
4610
- function Jo(e, t, n) {
4611
- return qo(Go({
4612
- body: n,
4613
- rounds: e.length
4614
- }, t ?? void 0));
4615
- }
4616
- function Yo(e, t) {
4617
- if (t <= 0) return { trimmed: !1 };
4618
- let n = Vo(e);
4619
- if (n.length <= t) return { trimmed: !1 };
4620
- let r = n[n.length - t].startIdx, i = n.slice(0, n.length - t), a = n[0].startIdx, o = null;
4621
- for (let t = 0; t < a; t++) {
4622
- let n = e[t];
4623
- if (n.role === "system" && (o = Ko(n.content), o)) break;
4624
- }
4625
- return {
4626
- trimmed: !0,
4627
- deleteFrom: 0,
4628
- deleteCount: r,
4629
- summary: {
4630
- role: "system",
4631
- content: qo(Go({
4632
- body: i.map((e) => {
4633
- let t = Ho(e.userMsg.content, 60) || "(空)", n = e.assistantMsgs[0] ? Ho(e.assistantMsgs[0].content, 80) : "(无回复)";
4634
- return `- 第${e.round}轮:${t} → ${n}`;
4635
- }).join("\n"),
4636
- rounds: i.length
4637
- }, o ?? void 0)),
4638
- timestamp: i[0].userMsg.timestamp
4639
- },
4640
- older: i,
4641
- prevSeg: o
4642
- };
4643
- }
4644
- //#endregion
4645
- //#region src/core/composables/contextIndex.ts
4646
- var Xo = /* @__PURE__ */ new Set(/* @__PURE__ */ "的.了.是.在.我.你.他.她.它.这.那.和.与.及.或.一个.什么.怎么.如何.为什么.可以.能.请.帮.一下.需要.想要.the.a.an.is.are.of.to.in.on".split("."));
4647
- function Zo(e) {
4648
- return e.toLowerCase().split(/[^a-z0-9一-龥]+/i).map((e) => e.trim()).filter((e) => e.length >= 2 && !Xo.has(e));
4649
- }
4650
- function Qo(e) {
4651
- let t = typeof e.content == "string" ? e.content : "";
4652
- if (e.reasoning && (t += e.reasoning), e.steps) for (let n of e.steps) t += " " + (n.name || ""), n.args != null && (t += " " + (typeof n.args == "string" ? n.args : JSON.stringify(n.args))), n.result && (t += " " + n.result);
4653
- return X(t);
4654
- }
4655
- function $o(e) {
4656
- let t = Qo(e.userMsg);
4657
- for (let n of e.assistantMsgs) t += Qo(n);
4658
- return t;
4659
- }
4660
- function es(e, t) {
4661
- return e.map((e) => {
4662
- let n = Ho(e.userMsg.content, 60) || "(空)", r = e.assistantMsgs[0] ? Ho(e.assistantMsgs[0].content, 80) : "(无回复)", i = e.assistantMsgs.flatMap((e) => (e.steps || []).map((e) => e.name)), a = i.length ? ` [工具: ${i.join(", ")}]` : "", o = "";
4663
- if (t && t.size) {
4664
- let n = [];
4665
- for (let r of e.assistantMsgs) for (let e of r.steps || []) e.name && t.has(e.name) && e.result && n.push(`${e.name}: ${Ho(e.result, 120)}`);
4666
- n.length && (o = `\n 字段提示: ${n.join(" | ")}`);
4667
- }
4668
- return `- 第${e.round}轮:${n} → ${r}${a}${o}`;
4669
- }).join("\n");
4670
- }
4671
- function ts(e, t, n) {
4672
- let r = Zo(t);
4673
- return r.length === 0 ? [] : e.map((e) => {
4674
- let t = (e.userMsg.content + " " + e.assistantMsgs.map((e) => e.content).join(" ") + " " + e.assistantMsgs.flatMap((e) => (e.steps || []).map((e) => Ho(e.result || "", 120))).join(" ")).toLowerCase(), n = 0;
4675
- for (let e of r) t.includes(e) && n++;
4676
- return {
4677
- r: e,
4678
- score: n
4679
- };
4680
- }).filter((e) => e.score > 0).sort((e, t) => t.score - e.score).slice(0, n).map((e) => e.r);
4681
- }
4682
- function ns(e, t) {
4683
- return t.contextWindow && t.contextWindow > 0 ? e.reduce((e, t) => e + $o(t), 0) > t.contextWindow * (t.summaryThresholdRatio ?? .5) : e.length > (t.summaryThresholdRounds ?? 8);
4684
- }
4685
- //#endregion
4686
- //#region src/core/composables/useContextManager.ts
4687
- var rs = {
4688
- windowRounds: 6,
4689
- summaryThresholdRounds: 8,
4690
- toolResultMaxChars: 800,
4691
- enableRecall: !0,
4692
- recallTopK: 3,
4693
- enableLLMSummary: !1
4694
- };
4695
- function is(e = {}) {
4696
- let t = {
4697
- ...rs,
4698
- ...e
4699
- };
4700
- async function n(e, n) {
4701
- let r = Vo(e), i = e.length, a = "";
4702
- if (r.length) {
4703
- let t = r[0].startIdx;
4704
- for (let n = 0; n < t; n++) {
4705
- let t = e[n];
4706
- if (t.role === "system") {
4707
- let e = Ko(t.content);
4708
- if (e) {
4709
- a = e.body;
4710
- break;
4711
- }
4712
- }
4713
- }
4714
- }
4715
- let o = (t) => ({
4716
- messages: e,
4717
- stats: {
4718
- triggered: !1,
4719
- roundsTotal: r.length,
4720
- roundsSummarized: 0,
4721
- roundsRecalled: 0,
4722
- originalMessages: i,
4723
- compressedMessages: i,
4724
- strategy: t
4725
- }
4726
- });
4727
- if (!ns(r, t)) return o("none");
4728
- let s, c, l;
4729
- if (t.contextWindow && t.contextWindow > 0) {
4730
- let e = t.contextWindow * (n?.windowRatio ?? t.windowRatio ?? .4), i = 0, a = 0;
4731
- for (let t = r.length - 1; t >= 0; t--) if (i += $o(r[t]), i >= e) {
4732
- a = t + 1;
4733
- break;
4734
- }
4735
- if (a > r.length - 1 && (a = r.length - 1), a < 0 && (a = 0), s = r.slice(a), c = r.slice(0, a), !c.length) return o("none");
4736
- l = "token-window+";
4737
- } else {
4738
- let e = n?.keepRounds ?? t.windowRounds, i = Math.min(Math.max(1, e), r.length);
4739
- if (s = r.slice(r.length - i), c = r.slice(0, r.length - i), !c.length) return o("none");
4740
- l = "window+";
4741
- }
4742
- let u = [...e].reverse().find((e) => e.role === "user")?.content || "", d = n?.summarize?.mode ?? (t.enableLLMSummary ? "llm" : "index"), f = /* @__PURE__ */ new Set([...t.preserveLastToolResults ?? [], ...n?.preserveTools ?? []]), p = f.size ? f : void 0, m, h;
4743
- if (d === "llm" && t.llmInvoke) try {
4744
- m = await t.llmInvoke(es(c, p)), h = l + "llm_summary";
4745
- } catch {
4746
- m = es(c, p), h = l + "index_summary(llm_fallback)";
4747
- }
4748
- else m = es(c, p), h = l + "index_summary";
4749
- let g = n?.recallTopK == null ? t.enableRecall ? t.recallTopK : 0 : n.recallTopK, _ = g > 0 ? ts(c, u, g) : [], v = _.length ? _.map((e) => `- 第${e.round}轮:${Ho(e.userMsg.content, 60)} → ${e.assistantMsgs[0] ? Ho(e.assistantMsgs[0].content, 80) : ""}`).join("\n") : "", y = a ? `${m}\n【更早累积摘要】\n${a}` : m, b = [`【对话历史摘要】以下是之前 ${c.length} 轮对话的要点(最新 ${s.length} 轮已完整保留):`, y];
4750
- if (n) {
4751
- let e = t.contextWindow && t.contextWindow > 0 ? `windowRatio=${n.windowRatio ?? t.windowRatio}` : `keepRounds=${n.keepRounds ?? t.windowRounds}`;
4752
- b.push(`\n(压缩决策:${e} · 摘要=${n.summarize.mode} · 召回=${g}${n.reason ? " · " + n.reason : ""})`);
4753
- }
4754
- v && b.push("\n【与当前问题可能相关的早期对话】", v);
4755
- let x = t.getRegisteredData ?? t.getRegisteredSlots;
4756
- if (x) try {
4757
- let e = x();
4758
- if (e.length) {
4759
- let t = e.map((e) => `- ${e.path ? e.path + ": " : ""}${e.description}`).join("\n");
4760
- b.push("\n【当前可操作数据(动态增删后的最新状态,操作前以 describe_data / read 为准)】", t);
4761
- }
4762
- } catch {}
4763
- let S = {
4764
- role: "system",
4765
- content: b.join("\n"),
4766
- timestamp: Date.now()
4767
- }, C = [];
4768
- for (let e of s) C.push(e.userMsg), C.push(...e.assistantMsgs);
4769
- let w = [S, ...C], T = w.reduce((e, t) => e + X(typeof t.content == "string" ? t.content : JSON.stringify(t.content)), 0);
4770
- return t.contextWindow && T > t.contextWindow && console.warn(`[page-agent-sdk] compress 后仍超窗口:${T} > ${t.contextWindow} tokens(单条消息超窗口,compress 无法压)`), {
4771
- messages: w,
4772
- stats: {
4773
- triggered: !0,
4774
- roundsTotal: r.length,
4775
- roundsSummarized: c.length,
4776
- roundsRecalled: _.length,
4777
- originalMessages: i,
4778
- compressedMessages: w.length,
4779
- strategy: h,
4780
- decision: n
4781
- }
4782
- };
4783
- }
4784
- return {
4785
- compress: n,
4786
- config: t
4787
- };
4788
- }
4789
- //#endregion
4790
- //#region src/core/harness/summarization.ts
4791
- function as(e = {}) {
4792
- let t = is(e);
4793
- return Object.assign({
4794
- name: "summarization",
4795
- compressInput: async (n) => {
4796
- let r;
4797
- if (e.decideInvoke) {
4798
- let i = Vo(n);
4799
- if (ns(i, t.config)) {
4800
- let a = t.config.contextWindow && t.config.contextWindow > 0 ? "token" : "rounds", o = a === "token" ? `历史 token 超阈值 ${Math.round((t.config.contextWindow ?? 0) * (t.config.summaryThresholdRatio ?? .5))}` : `轮数 ${i.length} 超阈值 ${t.config.summaryThresholdRounds}`;
4801
- try {
4802
- r = await e.decideInvoke({
4803
- getMessages: () => n,
4804
- getSnapshot: e.getSnapshot,
4805
- contextWindow: t.config.contextWindow,
4806
- thresholdRatio: t.config.summaryThresholdRatio,
4807
- triggerReason: o,
4808
- triggerMode: a
4809
- }) ?? void 0;
4810
- } catch {
4811
- r = void 0;
4812
- }
4813
- }
4814
- }
4815
- let { messages: i, stats: a } = await t.compress(n, r);
4816
- return {
4817
- messages: i,
4818
- stats: a
4819
- };
4820
- }
4821
- }, { setContextWindow(e) {
4822
- t.config.contextWindow = e;
4823
- } });
4824
- }
4825
- //#endregion
4826
4834
  //#region src/core/sdk/promptBuilder.ts
4827
4835
  var os = [
4828
4836
  "你是一个 JSON 操作助手。集成方声明了一个主数据对象(含 zod schema 校验),你通过专用工具安全地读写它来完成任务。",
@@ -4870,8 +4878,8 @@ function ds(e) {
4870
4878
  description: "查看当前对话上下文的构成(供压缩决策)。返回:totalTokens(历史轮次 token 总和,与触发判断同口径)、occupancy(窗口占用比)、contextWindow、categories(分类占用)、rounds(每轮 token/工具/首句)。先调用本工具查看构成,再决定压缩策略。",
4871
4879
  schema: us,
4872
4880
  handler: (t) => {
4873
- let n = Vo(e.getMessages()), r = n.length > 50 ? n.slice(n.length - 50) : n, i = (t.limit && r.length > t.limit ? r.slice(r.length - t.limit) : r).map((e) => {
4874
- let n = $o(e), r = Uo(e), i = t.role === "assistant" ? e.assistantMsgs[0] ?? e.userMsg : e.userMsg, a = Ho(typeof i.content == "string" ? i.content : "", 60);
4881
+ let n = eo(e.getMessages()), r = n.length > 50 ? n.slice(n.length - 50) : n, i = (t.limit && r.length > t.limit ? r.slice(r.length - t.limit) : r).map((e) => {
4882
+ let n = po(e), r = no(e), i = t.role === "assistant" ? e.assistantMsgs[0] ?? e.userMsg : e.userMsg, a = to(typeof i.content == "string" ? i.content : "", 60);
4875
4883
  return {
4876
4884
  round: e.round,
4877
4885
  tokens: n,
@@ -8590,7 +8598,7 @@ function au(e, n) {
8590
8598
  e.debug && j.agentCompression && !p && console.warn("[page-agent-sdk][agentCompression] agentCompression 开启但 summaryLlm 不可用(或缺 apiKey / 模型不支持工具),压缩决策不启用,回退静态压缩");
8591
8599
  let Oe = j.memory, ke = j.subagent, Ae = e.verify?.maxAttempts ?? 2, je = j.verify && e.verify?.enabled !== !1 && Ae > 0, Me = j.contextInspector;
8592
8600
  e.verify?.check && !j.verify && console.warn("[page-agent-sdk][verify] 检测到 verify.check 但 capabilities.verify 未开启,verify 未装载");
8593
- let Ne = e.subagent, Pe = Ne?.allowedTools ?? [], Fe = !ke || Ne?.enabled === !1 ? void 0 : fo({
8601
+ let Ne = e.subagent, Pe = Ne?.allowedTools ?? [], Fe = !ke || Ne?.enabled === !1 ? void 0 : jo({
8594
8602
  llm: Ne?.llm ?? e.llm,
8595
8603
  allTools: () => B,
8596
8604
  allowedTools: Pe.length ? Pe : void 0,
@@ -8603,7 +8611,7 @@ function au(e, n) {
8603
8611
  debug: e.debug,
8604
8612
  getFocuses: () => w.getFocuses(),
8605
8613
  getSchema: () => F()?.schema ?? null
8606
- }), Ie = ke && e.subagents !== void 0 ? ho(e.subagents, {
8614
+ }), Ie = ke && e.subagents !== void 0 ? Po(e.subagents, {
8607
8615
  llm: e.llm,
8608
8616
  allTools: () => B,
8609
8617
  debug: e.debug,
@@ -8614,8 +8622,8 @@ function au(e, n) {
8614
8622
  "describe_data",
8615
8623
  "read",
8616
8624
  "fetch_document"
8617
- ], V = B.filter((e) => Re.includes(e.name)), ze = je ? go({
8618
- check: e.verify.check ?? So({
8625
+ ], V = B.filter((e) => Re.includes(e.name)), ze = je ? Fo({
8626
+ check: e.verify.check ?? Vo({
8619
8627
  schemas: () => F() ? { "": F().schema } : {},
8620
8628
  root: () => F()?.bind
8621
8629
  }),
@@ -8623,7 +8631,7 @@ function au(e, n) {
8623
8631
  llm: e.llm,
8624
8632
  tools: V
8625
8633
  } : void 0
8626
- }) : void 0, Be = Me ? Io({
8634
+ }) : void 0, Be = Me ? ts({
8627
8635
  contextWindow: m.contextWindow,
8628
8636
  thresholdRatio: rc(e, m.contextWindow).summaryThresholdRatio
8629
8637
  }) : void 0, Ve = Ul({
@@ -8681,7 +8689,7 @@ function au(e, n) {
8681
8689
  W.infoTick.value++;
8682
8690
  }
8683
8691
  } catch {}
8684
- }, Qe = Ee ? as({
8692
+ }, Qe = Ee ? yo({
8685
8693
  ...h,
8686
8694
  llmInvoke: l,
8687
8695
  getRegisteredData: () => F() ? [{ description: F().description ?? "主数据对象" }] : [],
@@ -9164,7 +9172,7 @@ function au(e, n) {
9164
9172
  for (let t of e) delete x.files[t];
9165
9173
  }
9166
9174
  function st() {
9167
- let e = Yo(b, et);
9175
+ let e = co(b, et);
9168
9176
  if (!e.trimmed) return;
9169
9177
  let { older: t, summary: n } = e;
9170
9178
  if (H({
@@ -9182,9 +9190,9 @@ function au(e, n) {
9182
9190
  let n = e.summary, { prevSeg: r } = e;
9183
9191
  (async () => {
9184
9192
  try {
9185
- let e = await l(es(t, v)), i = b.indexOf(n);
9193
+ let e = await l(mo(t, v)), i = b.indexOf(n);
9186
9194
  if (i < 0) return;
9187
- b[i].content = Jo(t, r, e), ut();
9195
+ b[i].content = so(t, r, e), ut();
9188
9196
  } catch {}
9189
9197
  })();
9190
9198
  }
@@ -9216,7 +9224,7 @@ function au(e, n) {
9216
9224
  }
9217
9225
  return W.initDone = (async () => {
9218
9226
  if (await rt(), await it(), e.mcp?.length) {
9219
- let t = await Promise.allSettled(e.mcp.map((e) => Bo(e)));
9227
+ let t = await Promise.allSettled(e.mcp.map((e) => as(e)));
9220
9228
  W.mcpClosers = t.flatMap((e) => e.status === "fulfilled" ? [e.value.close] : []), W.mcpServers = [], t.forEach((t, n) => {
9221
9229
  let r = e.mcp[n], i = r.name ?? r.url;
9222
9230
  t.status === "fulfilled" ? (W.mcpServers.push({
@@ -9414,6 +9422,13 @@ function ou(e, t) {
9414
9422
  value: r
9415
9423
  }), { ok: !0 };
9416
9424
  },
9425
+ vfsWrite: (e, t) => {
9426
+ let n = typeof t == "string" ? t : JSON.stringify(t);
9427
+ a.vfsStore.files[Oc(e)] = {
9428
+ content: n,
9429
+ updatedAt: Date.now()
9430
+ };
9431
+ },
9417
9432
  createResource: (e, t) => {
9418
9433
  let n = a.dataOpsController;
9419
9434
  if (!n?.createResource) throw Error("[page-agent-sdk] createResource 不可用:需配 data.resources + vfsStore(capabilities.vfs 默认开)");
@@ -9447,8 +9462,114 @@ function ou(e, t) {
9447
9462
  };
9448
9463
  }
9449
9464
  //#endregion
9465
+ //#region src/core/sdk/ragSubagent.ts
9466
+ var su = "你是知识检索专家。可用工具:search_docs(语义检索)/ load_doc(按 source 加载)/ vfs_grep+vfs_read(搜预注入文档)/ fetch_document(公网 URL)。\n\n工作方式:\n1. 分析任务,拆出需查证的要点(如:需要哪些组件、各自的 props 约束、UI 规范要求);\n2. 多源检索:先 vfs_grep 搜预注入文档(快、静态)→ 不够用 search_docs 语义检索 → 需特定文档用 load_doc → 公网用 fetch_document;\n3. 检索结果不足时换关键词、扩大 topK、或换源重试;\n4. 综合成结构化、可执行结论(不堆原文,提炼成可直接用于决策/配置的信息);\n5. 标注关键信息来源(文档名/段落),便于溯源;检索不到明确说「未检索到」,不编造。\n\n你是只读检索角色,不要尝试修改任何数据。", cu = "# 知识检索策略(RAG)\n\n## 多源决策树\n- vfs_grep / vfs_read:搜集成方预注入 vfs 的文档(组件文档 / UI 规范)—— 快、静态,先查\n- search_docs:语义检索(retriever 向量库)—— 模糊匹配,关键词不确定 / 语义相似时用\n- load_doc:按 source 精确加载(已知文档 id / URL / key)—— 精确取特定文档\n- fetch_document:公网 URL —— 查公开资料\n\n## 综合规范\n- 多源交叉验证(关键结论优先 ≥2 源印证,或单一权威源)\n- 标注来源(文档名 / URL / 段落),便于溯源\n- 结构化、可执行结论(组件清单 + 各自 props 约束 + 适用场景),不堆原文\n- 未检索到明确说「未检索到」,不编造;建议替代方案(改关键词 / 建议写代码组件等)\n\n## 何时用何源\n- 静态文档(组件库文档 / UI 规范):vfs_grep\n- 语义相似(「瀑布流组件」「倒计时」「拼团」):search_docs\n- 已知文档 id / URL:load_doc\n- 公开 URL(设计规范网站 / 第三方文档):fetch_document", lu = {
9467
+ name: "rag-search",
9468
+ description: "多源知识检索策略:vfs 预注入文档 → 语义检索 → 指定文档加载 → 公网;综合结构化结论 + 溯源",
9469
+ getContent: () => cu
9470
+ };
9471
+ function uu(e, n, i) {
9472
+ return r(async ({ query: e, topK: t }) => {
9473
+ try {
9474
+ let r = await n(e, { topK: t ?? i });
9475
+ return r?.length ? r.map((e, t) => `【${t + 1}】${e.source ? `来源:${e.source}\n` : ""}${e.content}`).join("\n\n") : `未检索到与「${e}」相关的内容。可换关键词或扩大 topK 重试。`;
9476
+ } catch (e) {
9477
+ return `检索出错:${e.message}。可换关键词重试。`;
9478
+ }
9479
+ }, {
9480
+ name: e,
9481
+ description: "语义检索知识库(组件文档/UI 规范/业务规则等),返回相关片段。需要查阅文档才能回答或配置时用;可多次调用不同关键词。",
9482
+ schema: t.object({
9483
+ query: t.string().describe("检索关键词或自然语言问题"),
9484
+ topK: t.number().int().positive().optional().describe("期望召回数量(默认使用系统配置)")
9485
+ })
9486
+ });
9487
+ }
9488
+ function du(e, n) {
9489
+ return r(async ({ source: e }) => {
9490
+ try {
9491
+ let t = await n(e), r = Array.isArray(t) ? t : [t];
9492
+ return r.length ? r.map((e, t) => `【${t + 1}】${e.source ? `来源:${e.source}\n` : ""}${e.content}`).join("\n\n") : `未加载到「${e}」。检查 source 是否正确。`;
9493
+ } catch (e) {
9494
+ return `加载出错:${e.message}。`;
9495
+ }
9496
+ }, {
9497
+ name: e,
9498
+ description: "按 source 加载指定文档(文档 id/URL/key);已知要查的具体文档用此工具精确加载。",
9499
+ schema: t.object({ source: t.string().describe("文档标识(id/URL/key)") })
9500
+ });
9501
+ }
9502
+ function fu(e) {
9503
+ let { retriever: t, loader: n, useVfs: r = !0, id: i = "rag", description: a, topK: o = 5, searchToolName: s = "search_docs", loadToolName: c = "load_doc", maxToolRounds: l = 8, summarization: u, skills: d, extraTools: f } = e;
9504
+ if (!t && !n && r === !1) throw Error("[page-agent-sdk][createRagSubagent] 至少配一种知识源:retriever / loader / useVfs(true)");
9505
+ let p = [];
9506
+ t && p.push(uu(s, t, o)), n && p.push(du(c, n)), f && p.push(...f);
9507
+ let m = r ? [
9508
+ "vfs_grep",
9509
+ "vfs_read",
9510
+ "vfs_json_read"
9511
+ ] : void 0;
9512
+ return {
9513
+ id: i,
9514
+ description: a ?? "检索知识库(组件文档/UI 规范/业务规则),返回有依据的结构化结论。需要查阅文档才能回答或决定如何配置时委派",
9515
+ systemPrompt: su,
9516
+ tools: p.length ? p : void 0,
9517
+ allowedTools: m,
9518
+ skills: d ?? [lu],
9519
+ maxToolRounds: l,
9520
+ ...u === void 0 ? {} : { summarization: u }
9521
+ };
9522
+ }
9523
+ //#endregion
9524
+ //#region src/core/sdk/htmlSubagent.ts
9525
+ function pu(e) {
9526
+ return `你是纯代码组件生成专家。可用工具:vfs_write / vfs_edit / vfs_rm(写/改/删代码到 vfs ${e}) / vfs_grep + vfs_read(读 vfs) / write + set(写 data 引用,writablePaths 限定) / read / write_todos + update_todo(规划)。
9527
+
9528
+ 代码存储约定(重要):
9529
+ - 代码正文写 vfs:${e}<name>.vue(如 ${e}hero.vue)
9530
+ - data 存引用:write({ patch:{ op:'set', jsonPath:'components.N', value:{ type:'custom', codeRef:'vfs://${e}<name>.vue', name, props } } })
9531
+ - 改代码:先 vfs_edit 改 vfs 文件(data 的 codeRef 引用不变,无需改 data)
9532
+
9533
+ 工作方式:
9534
+ 1. 中等任务(多组件 / 大段代码)先 write_todos 拆解:读现有结构 → 规划各组件 → 逐个生成 → read 确认;
9535
+ 2. 遵循 html-builder skill 规范(SFC 规范 / 安全底线 / 可访问性 / props 定义 / 组件库引用);
9536
+ 3. 小段代码 vfs_write 整体写;大段用 vfs_edit 增量拼(避免单次输出超限);
9537
+ 4. 生成后 read(vfs 文件 + data 引用)确认结构正确;只写 writablePaths 内 data + ${e} 下 vfs。`;
9538
+ }
9539
+ var mu = "# 纯代码组件生成规范\n\n## 代码存储约定(重要)\n- 代码正文写 vfs:html/<name>.vue(如 html/hero.vue)\n- data 存引用:{ type:'custom', codeRef:'vfs://html/<name>.vue', name, props }\n- 改代码:vfs_edit 改 vfs 文件(data 的 codeRef 引用不变)\n\n## 何时写代码组件\n- 组件库无对应类型(高度定制交互 / 一次性特效 / 特殊布局)→ 写 custom 代码组件\n- 组件库已有(按钮 / 卡片 / 列表)→ 用现有组件配置,不重造\n\n## Vue SFC 规范\n- Vue 3 <template> + <script setup>(组合式)\n- props 用 defineProps;事件用 defineEmits\n- 只渲染 UI,不做副作用(不发请求 / 不读写 storage)\n\n## props 定义\n- 代码组件 defineProps 接受外部 data 传入(集成方渲染时按 data 的 props 字段传)\n\n## 组件库引用\n- 代码内可 import 组件库组件(如 <Button>);所用依赖以集成方渲染层已注入为准,不重复造\n\n## 安全底线(必须)\n- 禁 eval / new Function / Function 构造器\n- 禁访问 window 敏感属性(document.cookie / apiKey / token)\n- 不引入外部脚本 / CDN\n\n## 可访问性 + 语义化\n- 语义化标签(button / nav / section);图片 alt;交互可键盘聚焦\n- 颜色对比达标;不只用颜色传达信息", hu = {
9540
+ name: "html-builder",
9541
+ description: "纯代码组件(custom Vue SFC)生成规范:代码存 vfs+data 引用 / SFC 规范 / 安全底线 / props / 组件库引用 / 可访问性",
9542
+ getContent: () => mu
9543
+ };
9544
+ function gu(e) {
9545
+ let { writablePaths: t, codeVfsPrefix: n = "html/", id: r = "html", description: i, planning: a = !0, summarization: o = !0, maxToolRounds: s = 12, temperature: c = .4, skills: l, extraTools: u } = e;
9546
+ if (!t?.length) throw Error("[page-agent-sdk][createHtmlSubagent] writablePaths 必填(代码组件 data 区,如 [\"components\"])");
9547
+ let d = [];
9548
+ a && d.push(Qi());
9549
+ let f = u ?? [];
9550
+ return {
9551
+ id: r,
9552
+ description: i ?? "生成/修改纯代码组件(custom Vue SFC)。代码写 vfs,data 存引用;能规划(write_todos)+ 执行。需写代码组件或灵活定制时委派",
9553
+ systemPrompt: pu(n),
9554
+ writablePaths: t,
9555
+ allowedTools: [
9556
+ "vfs_write",
9557
+ "vfs_edit",
9558
+ "vfs_rm",
9559
+ "vfs_grep",
9560
+ "vfs_read"
9561
+ ],
9562
+ middleware: d.length ? d : void 0,
9563
+ summarization: o === !1 ? void 0 : o,
9564
+ temperature: c,
9565
+ skills: l ?? [hu],
9566
+ maxToolRounds: s,
9567
+ tools: f.length ? f : void 0
9568
+ };
9569
+ }
9570
+ //#endregion
9450
9571
  //#region src/core/utils/clipboard.ts
9451
- async function su(e) {
9572
+ async function _u(e) {
9452
9573
  try {
9453
9574
  let t = globalThis.navigator?.clipboard;
9454
9575
  if (t && typeof t.writeText == "function") return await t.writeText(e), !0;
@@ -9466,7 +9587,7 @@ async function su(e) {
9466
9587
  }
9467
9588
  //#endregion
9468
9589
  //#region src/core/composables/useChat.ts
9469
- function cu(e = {}) {
9590
+ function vu(e = {}) {
9470
9591
  let { fetchResponse: t, fetchStream: n, onPersist: r, onClear: i } = e, a = /* @__PURE__ */ _t({
9471
9592
  messages: e.messages ?? [],
9472
9593
  loading: !1,
@@ -9645,9 +9766,9 @@ function cu(e = {}) {
9645
9766
  }
9646
9767
  //#endregion
9647
9768
  //#region src/core/composables/chatContext.ts
9648
- var lu = Symbol("chatContext");
9649
- function uu(e = {}) {
9650
- let t = cu({
9769
+ var yu = Symbol("chatContext");
9770
+ function bu(e = {}) {
9771
+ let t = vu({
9651
9772
  fetchResponse: e.fetchResponse,
9652
9773
  fetchStream: e.fetchStream,
9653
9774
  messages: e.messages,
@@ -9666,7 +9787,7 @@ function uu(e = {}) {
9666
9787
  }, h = /* @__PURE__ */ Ot({}), g = (e) => h.value[e] !== !1, _ = (e) => {
9667
9788
  h.value[e] = !g(e);
9668
9789
  }, v = /* @__PURE__ */ Ot(!1), y = (e) => {
9669
- su(e).then((e) => {
9790
+ _u(e).then((e) => {
9670
9791
  e && (v.value = !0, setTimeout(() => {
9671
9792
  v.value = !1;
9672
9793
  }, 1500));
@@ -9734,15 +9855,15 @@ function uu(e = {}) {
9734
9855
  }
9735
9856
  };
9736
9857
  }
9737
- function du() {
9738
- let e = Fn(lu);
9858
+ function xu() {
9859
+ let e = Fn(yu);
9739
9860
  if (!e) throw Error("useChatContext 必须在 provide(chatContextKey) 的组件子树内调用");
9740
9861
  return e;
9741
9862
  }
9742
9863
  //#endregion
9743
9864
  //#region src/core/index.headless.ts
9744
- function fu(e) {
9865
+ function Su(e) {
9745
9866
  return ou(e);
9746
9867
  }
9747
9868
  //#endregion
9748
- export { Qs as CAPABILITIES, tc as CONTEXT_PRESETS, fs as CompressDecisionSchema, os as DEFAULT_SYSTEM_PROMPT, Ha as HUMAN_CONFIRM_TOOL_NAME, ti as MIN_CONTEXT_WINDOW, Xo as STOP_WORDS, oc as UNSAFE_KEYS, Il as actionsToInspectInfo, Fl as actionsToTools, Jr as agentError, Fo as analyzeContext, gc as applyPatchToClone, _c as applyPatchToLive, qr as asAgentError, ss as buildDataPrompt, cs as buildSystemPrompt, lu as chatContextKey, hl as commitSetToBind, Bo as connectMcp, f as constructLlmFromConfig, d as constructOpenLlmSync, su as copyText, ji as createAgent, Va as createApprovalMiddleware, uu as createChatContext, fu as createChatSdk, Qa as createCheckpointManager, $a as createCheckpointMiddleware, ws as createConflictManager, Io as createContextInspectorMiddleware, _l as createDataOps, Ga as createHumanConfirmMiddleware, Wa as createHumanConfirmTool, Gs as createMemoryBackend, Pa as createMemoryMiddleware, u as createProxyLlm, ba as createSandboxRunner, ec as createSdkEvents, $l as createSerialRunner, Ys as createSessionStore, Yl as createSkillStore, fo as createSubagentMiddleware, ho as createSubagentsMiddleware, Ul as createUsageHintsMiddleware, go as createVerifyMiddleware, wc as createVfs, qs as createWebStorageBackend, So as createWriteBackCheck, dc as deepClone, zl as defineDataToolset, Sa as defineSkill, ls as defineTool, uc as deleteByPath, ps as deriveTitle, Ui as describeSchemaNode, xi as detectGarbledToolCall, bc as diffObjects, Cl as domToStructure, Tl as domTools, Rl as domToolsStatic, Qo as estimateMessageTokens, $o as estimateRoundTokens, X as estimateTokens, m as extractReasoningDelta, ca as extractSchemaHint, Lo as extractText, p as extractTextDelta, h as extractUsage, yl as fetchDocTools, Ll as fetchTools, ml as filterByToolMode, Wi as formatConstraints, Ur as formatZodIssues, Z as getByPath, wl as getDomTool, Ol as getEnvSummary, Fi as getSchemaAtPath, Mi as getSchemaTopKeys, ai as getTraceMetrics, $ as hashValue, es as indexSummarize, jl as inspectEnvTool, Ml as inspectTools, ms as isChatModel, fi as isContextLengthError, Ni as isPathAllowed, Ls as isQuotaError, sc as isUnsafePath, Uc as jpEval, Gr as jsonParseError, mc as limitDepth, fc as maybeParseValue, ii as offloadPassThroughChars, ri as offloadThresholdChars, ra as presets, Li as projectBySchema, Ii as projectBySchemaDeep, pc as projectFields, ts as recallRounds, Gi as renderSchemaHint, Ki as renderSchemaOverview, Ji as renderSchemaShallow, $s as resolveCapabilities, rc as resolveContextOptions, Zs as resolveDialogConfig, Cs as resolveLlm, ni as resolveModelCaps, Xs as resolveStorage, yc as restoreInPlace, vc as restoreLive, Kr as routeError, xa as runHostScript, qc as runSandboxedScript, cc as safeMerge, Dl as safeSerialize, Q as safeStringify, Gc as searchJson, Bl as selectBuiltinTools, lc as setByPath, ns as shouldTriggerCompression, ia as systemPromptHelpers, Zo as tokenize, Y as toolError, Pi as unwrapSchema, cu as useChat, du as useChatContext, e as z, Wr as zodError };
9869
+ export { Qs as CAPABILITIES, tc as CONTEXT_PRESETS, fs as CompressDecisionSchema, os as DEFAULT_SYSTEM_PROMPT, Ha as HUMAN_CONFIRM_TOOL_NAME, ti as MIN_CONTEXT_WINDOW, lo as STOP_WORDS, oc as UNSAFE_KEYS, Il as actionsToInspectInfo, Fl as actionsToTools, Jr as agentError, es as analyzeContext, gc as applyPatchToClone, _c as applyPatchToLive, qr as asAgentError, ss as buildDataPrompt, cs as buildSystemPrompt, yu as chatContextKey, hl as commitSetToBind, as as connectMcp, f as constructLlmFromConfig, d as constructOpenLlmSync, _u as copyText, ji as createAgent, Va as createApprovalMiddleware, bu as createChatContext, Su as createChatSdk, Qa as createCheckpointManager, $a as createCheckpointMiddleware, ws as createConflictManager, ts as createContextInspectorMiddleware, _l as createDataOps, gu as createHtmlSubagent, Ga as createHumanConfirmMiddleware, Wa as createHumanConfirmTool, Gs as createMemoryBackend, Pa as createMemoryMiddleware, u as createProxyLlm, fu as createRagSubagent, ba as createSandboxRunner, ec as createSdkEvents, $l as createSerialRunner, Ys as createSessionStore, Yl as createSkillStore, jo as createSubagentMiddleware, Po as createSubagentsMiddleware, Ul as createUsageHintsMiddleware, Fo as createVerifyMiddleware, wc as createVfs, qs as createWebStorageBackend, Vo as createWriteBackCheck, dc as deepClone, zl as defineDataToolset, Sa as defineSkill, ls as defineTool, uc as deleteByPath, ps as deriveTitle, Ui as describeSchemaNode, xi as detectGarbledToolCall, bc as diffObjects, Cl as domToStructure, Tl as domTools, Rl as domToolsStatic, fo as estimateMessageTokens, po as estimateRoundTokens, X as estimateTokens, m as extractReasoningDelta, ca as extractSchemaHint, ns as extractText, p as extractTextDelta, h as extractUsage, yl as fetchDocTools, Ll as fetchTools, ml as filterByToolMode, Wi as formatConstraints, Ur as formatZodIssues, Z as getByPath, wl as getDomTool, Ol as getEnvSummary, Fi as getSchemaAtPath, Mi as getSchemaTopKeys, ai as getTraceMetrics, $ as hashValue, mo as indexSummarize, jl as inspectEnvTool, Ml as inspectTools, ms as isChatModel, fi as isContextLengthError, Ni as isPathAllowed, Ls as isQuotaError, sc as isUnsafePath, Uc as jpEval, Gr as jsonParseError, mc as limitDepth, fc as maybeParseValue, ii as offloadPassThroughChars, ri as offloadThresholdChars, ra as presets, Li as projectBySchema, Ii as projectBySchemaDeep, pc as projectFields, ho as recallRounds, Gi as renderSchemaHint, Ki as renderSchemaOverview, Ji as renderSchemaShallow, $s as resolveCapabilities, rc as resolveContextOptions, Zs as resolveDialogConfig, Cs as resolveLlm, ni as resolveModelCaps, Xs as resolveStorage, yc as restoreInPlace, vc as restoreLive, Kr as routeError, xa as runHostScript, qc as runSandboxedScript, cc as safeMerge, Dl as safeSerialize, Q as safeStringify, Gc as searchJson, Bl as selectBuiltinTools, lc as setByPath, go as shouldTriggerCompression, ia as systemPromptHelpers, uo as tokenize, Y as toolError, Pi as unwrapSchema, vu as useChat, xu as useChatContext, e as z, Wr as zodError };