page-agent-sdk 3.20.0 → 3.22.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.
- package/README.md +4 -4
- package/README.zh-CN.md +4 -4
- package/dist/page-agent-sdk.headless.js +779 -485
- package/dist/page-agent-sdk.iife.js +140 -137
- package/dist/page-agent-sdk.js +3411 -3066
- package/dist/page-agent-sdk.umd.cjs +74 -71
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/skills/page-agent-sdk-integrate/SKILL.md +22 -0
- package/types/index.d.ts +258 -83
|
@@ -3327,6 +3327,15 @@ var ga = {
|
|
|
3327
3327
|
"5. 优先用 write 的 patch 增量改(只发改动,如 write({ value, patch:{ op, jsonPath } })),避免整体重传大 JSON 被截断;",
|
|
3328
3328
|
"6. 写入若触发乐观锁冲突(返回 VERSION_CONFLICT 或工具挂起等用户决定):等工具返回结果后按其指示继续(保留外部值 → 重新 read 再改;已覆盖/已回退 → 基于结果重写),不要放弃任务。"
|
|
3329
3329
|
].join("\n"),
|
|
3330
|
+
reliableWriteRulesEn: [
|
|
3331
|
+
"[Reliable write rules]",
|
|
3332
|
+
"1. Before changing any field, read its current real value with read({ jsonPath }) and edit based on that value, never from memory;",
|
|
3333
|
+
"2. If unsure which fields are operable, call read() without jsonPath first to see the data description + schema-declared fields (the integrator can replace the schema at runtime via sdk.setData; trust the tool response over stale memory);",
|
|
3334
|
+
"3. When unsure about a field structure, the read({ jsonPath }) response includes a format description; treat the response as the source of truth;",
|
|
3335
|
+
"4. If a write is rejected by schema validation (the structured error names the field and expected type), fix it per the error and retry; do not give up;",
|
|
3336
|
+
"5. Prefer incremental write patches (send only the change, e.g. write({ value, patch:{ op, jsonPath } })) over resending the whole large JSON, which risks truncation;",
|
|
3337
|
+
"6. If a write hits an optimistic-lock conflict (VERSION_CONFLICT returned, or the tool suspends awaiting the user decision): after the tool returns, follow its instruction (keep external → re-read then edit; overwritten/restored → continue from the result); do not abandon the task."
|
|
3338
|
+
].join("\n"),
|
|
3330
3339
|
htmlPageOrchestrator: ha("html"),
|
|
3331
3340
|
htmlPageProposeFirst: ["【新建/创意类请求】先用简短文字给出 2~3 套方案(每套一两句风格/配色/结构要点),询问用户选哪套;选定前不要委派生成代码、不要写 components。", "【方案切换】已生成某套方案后改选另一套:不重新罗列,直接依据之前描述重新委派生成并覆盖相应组件(委派工具见编排段 use_<id>)。"].join("\n"),
|
|
3332
3341
|
htmlDirectWriteFallback: [
|
|
@@ -5737,58 +5746,65 @@ var nc = [
|
|
|
5737
5746
|
"大对象/数组优先用增量 patch(只发改动)而非整体重传,避免输出被截断。",
|
|
5738
5747
|
"---",
|
|
5739
5748
|
ga.reliableWriteRules
|
|
5749
|
+
].join("\n\n"), rc = [
|
|
5750
|
+
"You are a JSON operations assistant. The integrator declared a main data object (with zod schema validation); you complete tasks by reading and writing it safely through dedicated tools.",
|
|
5751
|
+
"All writes go through scope control (only schema-declared fields) and schema validation (invalid writes return a structured error instead of being applied), with automatic snapshots for rollback.",
|
|
5752
|
+
"For large objects/arrays prefer incremental patches (send only the change) over resending the whole value, to avoid output truncation.",
|
|
5753
|
+
"Respond in English.",
|
|
5754
|
+
"---",
|
|
5755
|
+
ga.reliableWriteRulesEn
|
|
5740
5756
|
].join("\n\n");
|
|
5741
|
-
function
|
|
5757
|
+
function ic(e, t) {
|
|
5742
5758
|
if (!e) return "";
|
|
5743
5759
|
let n = ba(e.schema, t);
|
|
5744
5760
|
return `\n\n## 可操作数据(字段以 read 工具返回的实际值为准)\n${e.description ? e.description + "\n" : ""}${n}`;
|
|
5745
5761
|
}
|
|
5746
|
-
function
|
|
5747
|
-
let t = e.appendReliableWriteRules !== !1;
|
|
5748
|
-
return e.systemPrompt ?
|
|
5762
|
+
function ac(e) {
|
|
5763
|
+
let t = e.locale === "en-US", n = t ? ga.reliableWriteRulesEn : ga.reliableWriteRules, r = e.appendReliableWriteRules !== !1;
|
|
5764
|
+
return e.systemPrompt ? r ? e.systemPrompt + "\n\n---\n\n" + n : e.systemPrompt : t ? rc : nc;
|
|
5749
5765
|
}
|
|
5750
|
-
var
|
|
5766
|
+
var oc = {
|
|
5751
5767
|
largeResults: 4 * 1024 * 1024,
|
|
5752
5768
|
drafts: 2 * 1024 * 1024,
|
|
5753
5769
|
userFiles: 2 * 1024 * 1024,
|
|
5754
5770
|
resources: 4 * 1024 * 1024
|
|
5755
|
-
},
|
|
5771
|
+
}, sc = [
|
|
5756
5772
|
"largeResults",
|
|
5757
5773
|
"drafts",
|
|
5758
5774
|
"userFiles",
|
|
5759
5775
|
"resources"
|
|
5760
|
-
],
|
|
5761
|
-
function
|
|
5776
|
+
], cc = .9;
|
|
5777
|
+
function lc(e, t = {}) {
|
|
5762
5778
|
let n = Object.create(null);
|
|
5763
|
-
if (e) for (let [t, r] of Object.entries(e)) n[
|
|
5779
|
+
if (e) for (let [t, r] of Object.entries(e)) n[pc(t)] = {
|
|
5764
5780
|
content: r,
|
|
5765
|
-
updatedAt:
|
|
5781
|
+
updatedAt: hc()
|
|
5766
5782
|
};
|
|
5767
5783
|
let { persist: r } = t, i = t.maxBytes ?? 8388608, a = {
|
|
5768
|
-
...
|
|
5784
|
+
...oc,
|
|
5769
5785
|
...t.poolBytes ?? {}
|
|
5770
5786
|
};
|
|
5771
5787
|
function o(e) {
|
|
5772
|
-
let t =
|
|
5788
|
+
let t = pc(e);
|
|
5773
5789
|
return t.startsWith("large_results/") ? "largeResults" : t.startsWith("drafts/") ? "drafts" : t.startsWith("resources/") ? "resources" : "userFiles";
|
|
5774
5790
|
}
|
|
5775
5791
|
function s(e) {
|
|
5776
5792
|
let t = 0;
|
|
5777
|
-
for (let [r, i] of Object.entries(n)) o(r) === e && (t +=
|
|
5793
|
+
for (let [r, i] of Object.entries(n)) o(r) === e && (t += dc(i.content));
|
|
5778
5794
|
return t;
|
|
5779
5795
|
}
|
|
5780
5796
|
function c() {
|
|
5781
|
-
for (let e of
|
|
5797
|
+
for (let e of sc) {
|
|
5782
5798
|
let t = a[e];
|
|
5783
5799
|
if (s(e) <= t) continue;
|
|
5784
|
-
let r = t *
|
|
5800
|
+
let r = t * cc, i = e === "largeResults", c = i && s(e) > t * 1.5;
|
|
5785
5801
|
c && console.warn(`[page-agent-sdk] vfs large_results 池 ${s(e)} > ${Math.round(t * 1.5)}(被引用撑爆)→ 无视 protectedRefs 强制删`);
|
|
5786
5802
|
let l = Object.entries(n).filter(([t]) => o(t) === e).sort((e, t) => e[1].updatedAt - t[1].updatedAt);
|
|
5787
5803
|
for (let [t] of l) if (!(i && !c && u.has(t)) && (delete n[t], s(e) <= r)) break;
|
|
5788
5804
|
}
|
|
5789
|
-
if (
|
|
5790
|
-
let e = i *
|
|
5791
|
-
for (let [i] of r) if (!(o(i) === "largeResults" && !t && u.has(i)) && (delete n[i],
|
|
5805
|
+
if (fc(n) > i) {
|
|
5806
|
+
let e = i * cc, t = fc(n) > i * 1.5, r = Object.entries(n).sort((e, t) => e[1].updatedAt - t[1].updatedAt);
|
|
5807
|
+
for (let [i] of r) if (!(o(i) === "largeResults" && !t && u.has(i)) && (delete n[i], fc(n) <= e)) break;
|
|
5792
5808
|
}
|
|
5793
5809
|
}
|
|
5794
5810
|
let l = !0, u = /* @__PURE__ */ new Set(), d = null;
|
|
@@ -5823,10 +5839,10 @@ function cc(e, t = {}) {
|
|
|
5823
5839
|
u = e;
|
|
5824
5840
|
},
|
|
5825
5841
|
getPoolOf: (e) => o(e),
|
|
5826
|
-
getPoolLimit: (e) => a[e] ??
|
|
5842
|
+
getPoolLimit: (e) => a[e] ?? oc.userFiles
|
|
5827
5843
|
};
|
|
5828
5844
|
return r && (m.hydrate = (e) => {
|
|
5829
|
-
for (let [t, r] of Object.entries(e)) n[
|
|
5845
|
+
for (let [t, r] of Object.entries(e)) n[pc(t)] = r;
|
|
5830
5846
|
c(), l = !0;
|
|
5831
5847
|
}, m.flush = () => {
|
|
5832
5848
|
d &&= (clearTimeout(d), null), f();
|
|
@@ -5835,19 +5851,19 @@ function cc(e, t = {}) {
|
|
|
5835
5851
|
p(), l = !0;
|
|
5836
5852
|
}), m;
|
|
5837
5853
|
}
|
|
5838
|
-
var
|
|
5839
|
-
function uc(e) {
|
|
5840
|
-
return lc ||= new TextEncoder(), lc.encode(e).length;
|
|
5841
|
-
}
|
|
5854
|
+
var uc = null;
|
|
5842
5855
|
function dc(e) {
|
|
5856
|
+
return uc ||= new TextEncoder(), uc.encode(e).length;
|
|
5857
|
+
}
|
|
5858
|
+
function fc(e) {
|
|
5843
5859
|
let t = 0;
|
|
5844
|
-
for (let n of Object.values(e)) t +=
|
|
5860
|
+
for (let n of Object.values(e)) t += dc(n.content);
|
|
5845
5861
|
return t;
|
|
5846
5862
|
}
|
|
5847
|
-
function
|
|
5863
|
+
function pc(e) {
|
|
5848
5864
|
return e.replace(/^\/+/, "").replace(/\/+/g, "/");
|
|
5849
5865
|
}
|
|
5850
|
-
function
|
|
5866
|
+
function mc(e) {
|
|
5851
5867
|
let t = "";
|
|
5852
5868
|
for (let n = 0; n < e.length; n++) {
|
|
5853
5869
|
let r = e[n];
|
|
@@ -5855,10 +5871,10 @@ function pc(e) {
|
|
|
5855
5871
|
}
|
|
5856
5872
|
return RegExp("^" + t + "$");
|
|
5857
5873
|
}
|
|
5858
|
-
function
|
|
5874
|
+
function hc() {
|
|
5859
5875
|
return Date.now();
|
|
5860
5876
|
}
|
|
5861
|
-
var
|
|
5877
|
+
var gc = [
|
|
5862
5878
|
"vfs_read",
|
|
5863
5879
|
"vfs_write",
|
|
5864
5880
|
"vfs_edit",
|
|
@@ -5869,10 +5885,10 @@ var hc = [
|
|
|
5869
5885
|
"vfs_json_patch",
|
|
5870
5886
|
"vfs_rm"
|
|
5871
5887
|
];
|
|
5872
|
-
function
|
|
5888
|
+
function _c(e) {
|
|
5873
5889
|
return [
|
|
5874
5890
|
r(async ({ path: t, offset: n, limit: r }) => {
|
|
5875
|
-
let i = e.files[
|
|
5891
|
+
let i = e.files[pc(t)];
|
|
5876
5892
|
if (!i) return Y({
|
|
5877
5893
|
code: "NOT_FOUND",
|
|
5878
5894
|
path: t,
|
|
@@ -5891,7 +5907,7 @@ function gc(e) {
|
|
|
5891
5907
|
})
|
|
5892
5908
|
}),
|
|
5893
5909
|
r(async ({ path: t, content: n, jsonString: r }) => {
|
|
5894
|
-
let i =
|
|
5910
|
+
let i = pc(t), a = e.getPoolLimit?.(e.getPoolOf?.(i) ?? "userFiles") ?? 2 * 1024 * 1024, o = dc(n);
|
|
5895
5911
|
if (o > a) {
|
|
5896
5912
|
let n = e.getPoolOf?.(i) ?? "userFiles";
|
|
5897
5913
|
return Y({
|
|
@@ -5913,7 +5929,7 @@ function gc(e) {
|
|
|
5913
5929
|
}
|
|
5914
5930
|
return e.files[i] = {
|
|
5915
5931
|
content: n,
|
|
5916
|
-
updatedAt:
|
|
5932
|
+
updatedAt: hc()
|
|
5917
5933
|
}, `已写入 ${t}(${n.length} 字符)${r ? "(JSON 校验通过)" : ""}`;
|
|
5918
5934
|
}, {
|
|
5919
5935
|
name: "vfs_write",
|
|
@@ -5925,7 +5941,7 @@ function gc(e) {
|
|
|
5925
5941
|
})
|
|
5926
5942
|
}),
|
|
5927
5943
|
r(async ({ path: t, oldString: n, newString: r }) => {
|
|
5928
|
-
let i =
|
|
5944
|
+
let i = pc(t), a = e.files[i];
|
|
5929
5945
|
if (!a) return Y({
|
|
5930
5946
|
code: "NOT_FOUND",
|
|
5931
5947
|
path: t,
|
|
@@ -5955,7 +5971,7 @@ function gc(e) {
|
|
|
5955
5971
|
}
|
|
5956
5972
|
return e.files[i] = {
|
|
5957
5973
|
content: a.content.replace(n, r),
|
|
5958
|
-
updatedAt:
|
|
5974
|
+
updatedAt: hc()
|
|
5959
5975
|
}, `已替换 ${t} 中 1 处。`;
|
|
5960
5976
|
}, {
|
|
5961
5977
|
name: "vfs_edit",
|
|
@@ -5977,7 +5993,7 @@ function gc(e) {
|
|
|
5977
5993
|
r(async ({ pattern: t }) => {
|
|
5978
5994
|
let n;
|
|
5979
5995
|
try {
|
|
5980
|
-
n =
|
|
5996
|
+
n = mc(t);
|
|
5981
5997
|
} catch (e) {
|
|
5982
5998
|
return Y({
|
|
5983
5999
|
code: "GLOB_INVALID",
|
|
@@ -6006,7 +6022,7 @@ function gc(e) {
|
|
|
6006
6022
|
details: { pattern: t }
|
|
6007
6023
|
});
|
|
6008
6024
|
}
|
|
6009
|
-
let i = n ? [
|
|
6025
|
+
let i = n ? [pc(n)] : Object.keys(e.files), a = [];
|
|
6010
6026
|
for (let t of i) {
|
|
6011
6027
|
let n = e.files[t];
|
|
6012
6028
|
n && n.content.split("\n").forEach((e, n) => {
|
|
@@ -6023,7 +6039,7 @@ function gc(e) {
|
|
|
6023
6039
|
})
|
|
6024
6040
|
}),
|
|
6025
6041
|
r(async ({ path: t, jsonPath: n }) => {
|
|
6026
|
-
let r =
|
|
6042
|
+
let r = pc(t), i = e.files[r];
|
|
6027
6043
|
if (!i) return Y({
|
|
6028
6044
|
code: "NOT_FOUND",
|
|
6029
6045
|
path: t,
|
|
@@ -6060,7 +6076,7 @@ function gc(e) {
|
|
|
6060
6076
|
})
|
|
6061
6077
|
}),
|
|
6062
6078
|
r(async ({ path: t, patches: n }) => {
|
|
6063
|
-
let r =
|
|
6079
|
+
let r = pc(t), i = e.files[r];
|
|
6064
6080
|
if (!i) return Y({
|
|
6065
6081
|
code: "NOT_FOUND",
|
|
6066
6082
|
path: t,
|
|
@@ -6093,7 +6109,7 @@ function gc(e) {
|
|
|
6093
6109
|
let c = JSON.stringify(o);
|
|
6094
6110
|
return e.files[r] = {
|
|
6095
6111
|
content: c,
|
|
6096
|
-
updatedAt:
|
|
6112
|
+
updatedAt: hc()
|
|
6097
6113
|
}, `已对 ${t} 应用 ${n.length} 个 patch(影响 ${s.length} 处:${s.join(", ")}),文件现 ${c.length} 字符`;
|
|
6098
6114
|
}, {
|
|
6099
6115
|
name: "vfs_json_patch",
|
|
@@ -6113,7 +6129,7 @@ function gc(e) {
|
|
|
6113
6129
|
})
|
|
6114
6130
|
}),
|
|
6115
6131
|
r(async ({ path: t }) => {
|
|
6116
|
-
let n =
|
|
6132
|
+
let n = pc(t);
|
|
6117
6133
|
return e.files[n] ? (delete e.files[n], `已删除 ${t}`) : Y({
|
|
6118
6134
|
code: "NOT_FOUND",
|
|
6119
6135
|
path: t,
|
|
@@ -6127,16 +6143,16 @@ function gc(e) {
|
|
|
6127
6143
|
})
|
|
6128
6144
|
];
|
|
6129
6145
|
}
|
|
6130
|
-
function
|
|
6146
|
+
function vc(e) {
|
|
6131
6147
|
return {
|
|
6132
6148
|
name: "vfs",
|
|
6133
|
-
tools:
|
|
6149
|
+
tools: _c(e),
|
|
6134
6150
|
beforeAgent: () => ({ files: e.files })
|
|
6135
6151
|
};
|
|
6136
6152
|
}
|
|
6137
6153
|
//#endregion
|
|
6138
6154
|
//#region src/core/tools/htmlValidate.ts
|
|
6139
|
-
var
|
|
6155
|
+
var yc = /* @__PURE__ */ new Set([
|
|
6140
6156
|
"area",
|
|
6141
6157
|
"base",
|
|
6142
6158
|
"br",
|
|
@@ -6151,8 +6167,8 @@ var vc = /* @__PURE__ */ new Set([
|
|
|
6151
6167
|
"source",
|
|
6152
6168
|
"track",
|
|
6153
6169
|
"wbr"
|
|
6154
|
-
]),
|
|
6155
|
-
function
|
|
6170
|
+
]), bc = /* @__PURE__ */ new Set(["script", "style"]);
|
|
6171
|
+
function xc(e) {
|
|
6156
6172
|
let t = [], n = e.length;
|
|
6157
6173
|
if (!e.trim()) return t;
|
|
6158
6174
|
let r = [0];
|
|
@@ -6229,8 +6245,8 @@ function bc(e) {
|
|
|
6229
6245
|
}
|
|
6230
6246
|
continue;
|
|
6231
6247
|
}
|
|
6232
|
-
if (!(
|
|
6233
|
-
if (
|
|
6248
|
+
if (!(yc.has(p) || m)) {
|
|
6249
|
+
if (bc.has(p)) {
|
|
6234
6250
|
let n = RegExp(`</${p}\\s*>`, "i").exec(e.slice(o));
|
|
6235
6251
|
if (!n) {
|
|
6236
6252
|
t.push({
|
|
@@ -6259,8 +6275,8 @@ function bc(e) {
|
|
|
6259
6275
|
}
|
|
6260
6276
|
//#endregion
|
|
6261
6277
|
//#region src/core/sdk/codeAssetMiddleware.ts
|
|
6262
|
-
var
|
|
6263
|
-
function
|
|
6278
|
+
var Sc = "__pgTouched", Cc = "__pgFinalText", wc = "__pgCodeHashes", Tc = "__pgNotes", Ec = 200;
|
|
6279
|
+
function Dc(e) {
|
|
6264
6280
|
let t = [];
|
|
6265
6281
|
for (let n of e.split("\n")) {
|
|
6266
6282
|
let e = n.match(/^\s*[-*]?\s*\[note\]\s*(.*)$/i);
|
|
@@ -6268,27 +6284,27 @@ function Ec(e) {
|
|
|
6268
6284
|
}
|
|
6269
6285
|
return [...new Set(t)];
|
|
6270
6286
|
}
|
|
6271
|
-
function
|
|
6272
|
-
let n = Array.isArray(e[
|
|
6273
|
-
e[
|
|
6287
|
+
function Oc(e, t) {
|
|
6288
|
+
let n = Array.isArray(e[Tc]) ? e[Tc].filter((e) => typeof e == "string") : [];
|
|
6289
|
+
e[Tc] = [.../* @__PURE__ */ new Set([...n, ...t])].map((e) => e.length > Ec ? e.slice(0, Ec) + "…" : e).slice(-5);
|
|
6274
6290
|
}
|
|
6275
|
-
function
|
|
6291
|
+
function kc(e) {
|
|
6276
6292
|
let t = 5381;
|
|
6277
6293
|
for (let n = 0; n < e.length; n++) t = (t << 5) + t + e.charCodeAt(n) | 0;
|
|
6278
6294
|
return (t >>> 0).toString(16);
|
|
6279
6295
|
}
|
|
6280
|
-
function
|
|
6296
|
+
function Ac(e, t) {
|
|
6281
6297
|
let n = [];
|
|
6282
|
-
return
|
|
6298
|
+
return Mc(e, t, (e) => {
|
|
6283
6299
|
typeof e.name == "string" && e.name && n.push(e.name);
|
|
6284
6300
|
}), n;
|
|
6285
6301
|
}
|
|
6286
|
-
function
|
|
6302
|
+
function jc(e, t) {
|
|
6287
6303
|
if (!e.startsWith(t)) return null;
|
|
6288
6304
|
let n = e.slice(t.length), r = n.lastIndexOf(".");
|
|
6289
6305
|
return (r > 0 ? n.slice(0, r) : r === 0 ? "" : n) || null;
|
|
6290
6306
|
}
|
|
6291
|
-
function
|
|
6307
|
+
function Mc(e, t, n) {
|
|
6292
6308
|
if (!(!e || typeof e != "object")) for (let r of t) {
|
|
6293
6309
|
let t = Z(e, r);
|
|
6294
6310
|
if (Array.isArray(t)) for (let e = 0; e < t.length; e++) {
|
|
@@ -6297,7 +6313,7 @@ function jc(e, t, n) {
|
|
|
6297
6313
|
}
|
|
6298
6314
|
}
|
|
6299
6315
|
}
|
|
6300
|
-
function
|
|
6316
|
+
function Nc(e, t, n) {
|
|
6301
6317
|
let r = /* @__PURE__ */ new Set();
|
|
6302
6318
|
if (!e || typeof e != "object") return r;
|
|
6303
6319
|
for (let i of t) {
|
|
@@ -6316,17 +6332,17 @@ function Mc(e, t, n) {
|
|
|
6316
6332
|
}
|
|
6317
6333
|
return r;
|
|
6318
6334
|
}
|
|
6319
|
-
function
|
|
6335
|
+
function Pc(e) {
|
|
6320
6336
|
let { writablePaths: t, codeVfsPrefix: n, ext: r, codeField: i = "code", onWarning: a, getController: o, vfsStore: s, craftNotes: c = !0 } = e;
|
|
6321
6337
|
return {
|
|
6322
6338
|
name: "code-asset-checkout-commit",
|
|
6323
6339
|
beforeAgent: (e) => {
|
|
6324
6340
|
let c = o()?.get?.().bind, l = 0, u = 0, d = /* @__PURE__ */ new Map();
|
|
6325
|
-
if (
|
|
6341
|
+
if (Mc(c, t, (e) => {
|
|
6326
6342
|
l++;
|
|
6327
6343
|
let t = Z(e, i);
|
|
6328
6344
|
if (typeof t == "string") {
|
|
6329
|
-
u++, d.set(e.__pgId,
|
|
6345
|
+
u++, d.set(e.__pgId, kc(t));
|
|
6330
6346
|
let i = `${n}${e.__pgId}.${r}`;
|
|
6331
6347
|
s.files[i] = {
|
|
6332
6348
|
content: t,
|
|
@@ -6346,22 +6362,22 @@ function Nc(e) {
|
|
|
6346
6362
|
}
|
|
6347
6363
|
return {
|
|
6348
6364
|
files: s.files,
|
|
6349
|
-
[
|
|
6350
|
-
[
|
|
6351
|
-
[
|
|
6365
|
+
[Sc]: /* @__PURE__ */ new Set(),
|
|
6366
|
+
[Cc]: { text: "" },
|
|
6367
|
+
[wc]: d
|
|
6352
6368
|
};
|
|
6353
6369
|
},
|
|
6354
6370
|
wrapModelCall: async (e, t) => {
|
|
6355
|
-
let n = await t(e), r = e.state[
|
|
6371
|
+
let n = await t(e), r = e.state[Cc];
|
|
6356
6372
|
return r && !(n.toolCalls && n.toolCalls.length) && typeof n.content == "string" && n.content && (r.text = n.content), n;
|
|
6357
6373
|
},
|
|
6358
6374
|
augmentPrompt: () => {
|
|
6359
6375
|
let e = o()?.get?.().bind, i = [], a = 0;
|
|
6360
|
-
if (
|
|
6376
|
+
if (Mc(e, t, (e, t, o) => {
|
|
6361
6377
|
a++;
|
|
6362
6378
|
let l = typeof e.name == "string" && e.name ? e.name : "", u = l ? `${l} [${o}]` : `(未命名 [${o}])`, d = `${n}${e.__pgId}.${r}`, f = !!s.files[d];
|
|
6363
6379
|
if (i.push(`- ${u} → ${d}${f ? "" : "(尚未检出,先 vfs_write 创建)"}`), c) {
|
|
6364
|
-
let t = Array.isArray(e[
|
|
6380
|
+
let t = Array.isArray(e[Tc]) ? e[Tc].filter((e) => typeof e == "string") : [];
|
|
6365
6381
|
if (t.length) {
|
|
6366
6382
|
let e = t[t.length - 1];
|
|
6367
6383
|
i.push(` 📝 笔记×${t.length}(最近):${e.length > 120 ? e.slice(0, 120) + "…" : e}`);
|
|
@@ -6379,13 +6395,13 @@ function Nc(e) {
|
|
|
6379
6395
|
return `## 组件代码文件地图(改组件时按 name 直接改对应 vfs 文件;框架自动 checkout/commit)${c ? "\n📝 笔记 = 前任维护者交接(设计决策/用户反馈/踩坑),改该组件时遵循;收口回复末行必须附一行 [note] 交接笔记(本组件本次的实现要点),框架存进组件转交下任" : ""}\n${i.join("\n")}${l}`;
|
|
6380
6396
|
},
|
|
6381
6397
|
wrapToolCall: async (e, i) => {
|
|
6382
|
-
let a = e.name === "vfs_write" || e.name === "vfs_edit" || e.name === "vfs_rm" ? e.args?.path : void 0, s = typeof a == "string" ?
|
|
6398
|
+
let a = e.name === "vfs_write" || e.name === "vfs_edit" || e.name === "vfs_rm" ? e.args?.path : void 0, s = typeof a == "string" ? pc(a) : void 0, c = typeof s == "string" && s.startsWith(n);
|
|
6383
6399
|
if (c) {
|
|
6384
6400
|
let i = e.state.focuses;
|
|
6385
6401
|
if (i && i.length) {
|
|
6386
|
-
let e =
|
|
6402
|
+
let e = Nc(o()?.get?.().bind, t, i);
|
|
6387
6403
|
if (e.size) {
|
|
6388
|
-
let t =
|
|
6404
|
+
let t = jc(s, n);
|
|
6389
6405
|
if (t && !e.has(t)) return {
|
|
6390
6406
|
content: `PATH_DENIED · vfs 越界:当前聚焦代码文件 [${[...e].map((e) => `${n}${e}.${r}`).join(", ")}],你要改的 "${s}" 不在其中。请只改焦点组件的代码文件;如需改其他组件,请在收口回复中说明需先取消聚焦(焦点由主会话/用户管理,你无 focus 工具)后重试。`,
|
|
6391
6407
|
status: "error"
|
|
@@ -6395,7 +6411,7 @@ function Nc(e) {
|
|
|
6395
6411
|
}
|
|
6396
6412
|
let l = await i(e);
|
|
6397
6413
|
if (c) {
|
|
6398
|
-
let t = e.state[
|
|
6414
|
+
let t = e.state[Sc];
|
|
6399
6415
|
t && t.add(s);
|
|
6400
6416
|
}
|
|
6401
6417
|
return l;
|
|
@@ -6403,10 +6419,10 @@ function Nc(e) {
|
|
|
6403
6419
|
afterAgent: (e) => {
|
|
6404
6420
|
let a = o(), l = a?.get?.().bind;
|
|
6405
6421
|
if (!l) return;
|
|
6406
|
-
let u = e[
|
|
6422
|
+
let u = e[Sc] ?? /* @__PURE__ */ new Set();
|
|
6407
6423
|
if (u.size) {
|
|
6408
|
-
let o = e[
|
|
6409
|
-
|
|
6424
|
+
let o = e[wc] ?? /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Set();
|
|
6425
|
+
Mc(l, t, (e) => {
|
|
6410
6426
|
let t = e.__pgId;
|
|
6411
6427
|
c.add(t);
|
|
6412
6428
|
let a = `${n}${t}.${r}`;
|
|
@@ -6416,12 +6432,12 @@ function Nc(e) {
|
|
|
6416
6432
|
let r = o.get(t);
|
|
6417
6433
|
if (r !== void 0) {
|
|
6418
6434
|
let n = Z(e, i);
|
|
6419
|
-
if (typeof n != "string" ||
|
|
6435
|
+
if (typeof n != "string" || kc(n) !== r) {
|
|
6420
6436
|
console.warn(`[page-agent-sdk][code-asset] 组件 ${e.name ?? t}(${a})在修改期间被外部更新,已保留外部版本(keep_external),本次子 agent 修改未提交`);
|
|
6421
6437
|
return;
|
|
6422
6438
|
}
|
|
6423
6439
|
}
|
|
6424
|
-
let s =
|
|
6440
|
+
let s = xc(n.content);
|
|
6425
6441
|
if (s.length) {
|
|
6426
6442
|
console.warn(`[page-agent-sdk][code-asset] 跳过 commit 未通过校验的半成品(可能 abort/timeout 未跑完 verify):${a} - ${s[0].message}(${s[0].code})`);
|
|
6427
6443
|
return;
|
|
@@ -6433,22 +6449,22 @@ function Nc(e) {
|
|
|
6433
6449
|
}
|
|
6434
6450
|
});
|
|
6435
6451
|
for (let e of u) {
|
|
6436
|
-
let t =
|
|
6452
|
+
let t = jc(e, n);
|
|
6437
6453
|
t && !c.has(t) && (console.warn(`[page-agent-sdk][code-asset] 组件 ${t}(${e})已被外部删除,放弃 commit 并清理 vfs 工作副本(不复活组件)`), delete s.files[e]);
|
|
6438
6454
|
}
|
|
6439
6455
|
a?.markDataDirty?.(), a?.recomputeBaseline?.();
|
|
6440
6456
|
}
|
|
6441
6457
|
if (!c) return;
|
|
6442
|
-
let d =
|
|
6458
|
+
let d = Dc(e[Cc]?.text ?? "");
|
|
6443
6459
|
if (!d.length) return;
|
|
6444
6460
|
let f = [];
|
|
6445
|
-
if (
|
|
6461
|
+
if (Mc(l, t, (e) => {
|
|
6446
6462
|
(u.size === 0 || u.has(`${n}${e.__pgId}.${r}`)) && f.push(e);
|
|
6447
6463
|
}), !f.length) return;
|
|
6448
6464
|
let p = !1;
|
|
6449
6465
|
for (let e of d) {
|
|
6450
6466
|
let t = f.length === 1 ? f[0] : f.find((t) => typeof t.name == "string" && !!t.name && e.includes(t.name));
|
|
6451
|
-
t && (
|
|
6467
|
+
t && (Oc(t, [e]), p = !0);
|
|
6452
6468
|
}
|
|
6453
6469
|
p && a?.markDataDirty?.();
|
|
6454
6470
|
}
|
|
@@ -6456,7 +6472,7 @@ function Nc(e) {
|
|
|
6456
6472
|
}
|
|
6457
6473
|
//#endregion
|
|
6458
6474
|
//#region src/core/sdk/componentLock.ts
|
|
6459
|
-
function
|
|
6475
|
+
function Fc() {
|
|
6460
6476
|
let e = /* @__PURE__ */ new Map();
|
|
6461
6477
|
return {
|
|
6462
6478
|
async acquire(t, n) {
|
|
@@ -6495,7 +6511,7 @@ function Pc() {
|
|
|
6495
6511
|
}
|
|
6496
6512
|
};
|
|
6497
6513
|
}
|
|
6498
|
-
function
|
|
6514
|
+
function Ic(e, t) {
|
|
6499
6515
|
if (Array.isArray(e.components) && e.components.length) {
|
|
6500
6516
|
let n = new Set(t), r = [...new Set(e.components.filter((e) => typeof e == "string" && e && n.has(e)))];
|
|
6501
6517
|
if (r.length) return {
|
|
@@ -6512,12 +6528,12 @@ function Fc(e, t) {
|
|
|
6512
6528
|
via: "none"
|
|
6513
6529
|
};
|
|
6514
6530
|
}
|
|
6515
|
-
function
|
|
6531
|
+
function Lc(e, t, n) {
|
|
6516
6532
|
let r = new Set(n);
|
|
6517
6533
|
if (!r.size || !e || typeof e != "object") return [];
|
|
6518
6534
|
let i = [];
|
|
6519
6535
|
for (let n of t) {
|
|
6520
|
-
let t =
|
|
6536
|
+
let t = Rc(e, n);
|
|
6521
6537
|
if (Array.isArray(t)) for (let e = 0; e < t.length; e++) {
|
|
6522
6538
|
let a = t[e];
|
|
6523
6539
|
a && typeof a == "object" && typeof a.name == "string" && r.has(a.name) && i.push(`${n}.${e}`);
|
|
@@ -6525,7 +6541,7 @@ function Ic(e, t, n) {
|
|
|
6525
6541
|
}
|
|
6526
6542
|
return i;
|
|
6527
6543
|
}
|
|
6528
|
-
function
|
|
6544
|
+
function Rc(e, t) {
|
|
6529
6545
|
let n = e;
|
|
6530
6546
|
for (let e of t.split(".")) {
|
|
6531
6547
|
if (!n || typeof n != "object") return;
|
|
@@ -6533,15 +6549,15 @@ function Lc(e, t) {
|
|
|
6533
6549
|
}
|
|
6534
6550
|
return n;
|
|
6535
6551
|
}
|
|
6536
|
-
function
|
|
6552
|
+
function zc(e, t) {
|
|
6537
6553
|
return t.some((t) => e === t || e.startsWith(t + "."));
|
|
6538
6554
|
}
|
|
6539
|
-
function
|
|
6555
|
+
function Bc(e) {
|
|
6540
6556
|
let t = e ?? {}, n = /* @__PURE__ */ new Set();
|
|
6541
6557
|
if (typeof t.jsonPath == "string" && t.jsonPath && n.add(t.jsonPath), typeof t.path == "string" && t.path && n.add(t.path), t.patch && typeof t.patch.jsonPath == "string" && t.patch.jsonPath && n.add(t.patch.jsonPath), Array.isArray(t.patches)) for (let e of t.patches) e && typeof e.jsonPath == "string" && e.jsonPath && n.add(e.jsonPath);
|
|
6542
6558
|
return [...n];
|
|
6543
6559
|
}
|
|
6544
|
-
function
|
|
6560
|
+
function Vc(e) {
|
|
6545
6561
|
return {
|
|
6546
6562
|
name: "component-write-guard",
|
|
6547
6563
|
wrapToolCall: async (t, n) => {
|
|
@@ -6562,9 +6578,9 @@ function Bc(e) {
|
|
|
6562
6578
|
}
|
|
6563
6579
|
let a = e.getLocked(), o = Object.keys(a);
|
|
6564
6580
|
if (!o.length) return n(t);
|
|
6565
|
-
let s =
|
|
6581
|
+
let s = Lc(e.getBind(), e.writablePaths, o);
|
|
6566
6582
|
if (!s.length) return n(t);
|
|
6567
|
-
let c =
|
|
6583
|
+
let c = Bc(i);
|
|
6568
6584
|
if (!c.length) return e.onReject?.({
|
|
6569
6585
|
paths: ["(整体 set)"],
|
|
6570
6586
|
lockedPrefixes: s,
|
|
@@ -6573,7 +6589,7 @@ function Bc(e) {
|
|
|
6573
6589
|
content: `COMPONENT_LOCKED · 组件 [${o.join(", ")}] 正在被子 agent 修改,整体写入会触碰它们。请改用增量 patch(write({patch:{jsonPath,...}}))只写未锁定组件,或等委派结束后再整体操作。`,
|
|
6574
6590
|
status: "error"
|
|
6575
6591
|
};
|
|
6576
|
-
let l = c.filter((e) =>
|
|
6592
|
+
let l = c.filter((e) => zc(e, s));
|
|
6577
6593
|
return l.length ? (e.onReject?.({
|
|
6578
6594
|
paths: l,
|
|
6579
6595
|
lockedPrefixes: s,
|
|
@@ -6587,7 +6603,7 @@ function Bc(e) {
|
|
|
6587
6603
|
}
|
|
6588
6604
|
//#endregion
|
|
6589
6605
|
//#region src/core/sdk/htmlSubagent.ts
|
|
6590
|
-
function
|
|
6606
|
+
function Hc(e, t, n) {
|
|
6591
6607
|
let r = "html";
|
|
6592
6608
|
return `你是纯代码组件生成专家。可用工具:vfs_write / vfs_edit / vfs_rm(写/改/删代码工作副本 vfs ${e}) / vfs_read + vfs_grep(读 vfs) / validate_code(代码格式自检) / write(写 data,writablePaths 限定;set/patch 增量或整体) / read / write_todos + update_todo(规划)。
|
|
6593
6609
|
|
|
@@ -6640,7 +6656,7 @@ ${`- 输出形态:完整、自包含的 HTML 页面(.${r},可独立成页)`}
|
|
|
6640
6656
|
- 一次想清楚 → 动手 → 验证 → 收口。**思考是手段不是目的,产出代码才是**。
|
|
6641
6657
|
8. **收口格式(必守,最后一行)**:收口回复 = 简短结果总结 + **末行交接笔记** \`[note] <一句话实现要点>\` —— 关键设计决策 / 用户偏好 / 踩坑(如「[note] 液面用 height keyframes 4.2s 循环;装饰仅灯串+光斑 2 类」)。框架只识别末尾 [note] 行存进组件、自动转交下次维护该组件的子 agent;**漏写 = 下任失去交接**(真 LLM 实测漏写率 3/4,务必末行带上)。一行内,只写可复用结论。`;
|
|
6642
6658
|
}
|
|
6643
|
-
function
|
|
6659
|
+
function Uc(e, t) {
|
|
6644
6660
|
return `# HTML 完整页面生成规范
|
|
6645
6661
|
|
|
6646
6662
|
## 代码资产模型(重要)
|
|
@@ -6678,14 +6694,14 @@ function Hc(e, t) {
|
|
|
6678
6694
|
- 语义化标签(button / nav / section);图片 alt;交互可键盘聚焦
|
|
6679
6695
|
- 颜色对比达标;不只用颜色传达信息`;
|
|
6680
6696
|
}
|
|
6681
|
-
function
|
|
6697
|
+
function Wc(e = "components", t = "code") {
|
|
6682
6698
|
return {
|
|
6683
6699
|
name: "html-fragment",
|
|
6684
6700
|
description: "完整 HTML 页面生成规范:代码作为 data 资产 / vfs 工作副本 / 完整自包含可独立成页 / script+CSS 集中放置 / 可引外部 JS/CSS / validate_code 自检 / 安全底线 / 可访问性",
|
|
6685
|
-
getContent: () =>
|
|
6701
|
+
getContent: () => Uc(e, t)
|
|
6686
6702
|
};
|
|
6687
6703
|
}
|
|
6688
|
-
function
|
|
6704
|
+
function Gc(e = {}) {
|
|
6689
6705
|
let t = e.vfsPrefix ?? "html/";
|
|
6690
6706
|
return ({ state: e }) => {
|
|
6691
6707
|
let n = e.files;
|
|
@@ -6693,7 +6709,7 @@ function Wc(e = {}) {
|
|
|
6693
6709
|
let r = [];
|
|
6694
6710
|
for (let [e, i] of Object.entries(n)) {
|
|
6695
6711
|
if (!e.startsWith(t)) continue;
|
|
6696
|
-
let n =
|
|
6712
|
+
let n = xc(i.content);
|
|
6697
6713
|
for (let t of n) r.push(`${e} 第 ${t.line} 行:${t.message}(${t.code})`);
|
|
6698
6714
|
}
|
|
6699
6715
|
return r.length ? {
|
|
@@ -6702,7 +6718,7 @@ function Wc(e = {}) {
|
|
|
6702
6718
|
} : { ok: !0 };
|
|
6703
6719
|
};
|
|
6704
6720
|
}
|
|
6705
|
-
function
|
|
6721
|
+
function Kc(e) {
|
|
6706
6722
|
let n, i, a = {
|
|
6707
6723
|
name: "html-validate-tools",
|
|
6708
6724
|
beforeAgent: (e) => {
|
|
@@ -6737,7 +6753,7 @@ function Gc(e) {
|
|
|
6737
6753
|
}
|
|
6738
6754
|
let s = [];
|
|
6739
6755
|
for (let e of o) {
|
|
6740
|
-
let t =
|
|
6756
|
+
let t = xc(e.content);
|
|
6741
6757
|
t.length && s.push(`${e.path}:\n${t.map((e) => ` 第 ${e.line} 行 ${e.message}(${e.code})`).join("\n")}`);
|
|
6742
6758
|
}
|
|
6743
6759
|
return s.length ? `❌ 格式校验未通过:\n${s.join("\n")}\n请用 vfs_edit 修正后重新调用 validate_code 复查。` : `✅ 格式校验通过(${o.map((e) => e.path).join(", ")}:标签闭合等结构合法)。`;
|
|
@@ -6755,16 +6771,16 @@ function Gc(e) {
|
|
|
6755
6771
|
i = e;
|
|
6756
6772
|
}, a;
|
|
6757
6773
|
}
|
|
6758
|
-
var
|
|
6759
|
-
function
|
|
6774
|
+
var qc = 2;
|
|
6775
|
+
function Jc(e = {}) {
|
|
6760
6776
|
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, formatCheck: d = !0, codeField: f = "code", orchestratorPrompt: p = !0, craftNotes: m = !0 } = e;
|
|
6761
6777
|
if (t !== void 0 && !Array.isArray(t)) throw Error("[page-agent-sdk][createHtmlSubagent] writablePaths 须为字符串数组(代码组件 data 区,如 [\"components\"])/ 省略以从 schema 自动推断");
|
|
6762
6778
|
let h = [];
|
|
6763
|
-
a && h.push(Ta()), d && (h.push(
|
|
6779
|
+
a && h.push(Ta()), d && (h.push(Kc(n)), h.push(As({ check: Gc({ vfsPrefix: n }) })));
|
|
6764
6780
|
let g = u ?? [], _ = t?.[0] ?? "components", v = l === void 0, y = {
|
|
6765
6781
|
id: r,
|
|
6766
6782
|
description: i ?? `生成/修改纯代码组件(代码作为 data 资产,代码字段 ${f} 随 data 持久化;vfs 作工作副本;能规划(write_todos)+ 执行)。需写代码组件或灵活定制时委派`,
|
|
6767
|
-
systemPrompt:
|
|
6783
|
+
systemPrompt: Hc(n, f, _),
|
|
6768
6784
|
writablePaths: t ?? [],
|
|
6769
6785
|
allowedTools: [
|
|
6770
6786
|
"vfs_write",
|
|
@@ -6775,9 +6791,9 @@ function qc(e = {}) {
|
|
|
6775
6791
|
],
|
|
6776
6792
|
middleware: h.length ? h : void 0,
|
|
6777
6793
|
summarization: o === !1 ? void 0 : o,
|
|
6778
|
-
maxVerifyAttempts: d ?
|
|
6794
|
+
maxVerifyAttempts: d ? qc : void 0,
|
|
6779
6795
|
temperature: c,
|
|
6780
|
-
skills: v ? [
|
|
6796
|
+
skills: v ? [Wc(_, f)] : l,
|
|
6781
6797
|
maxToolRounds: s,
|
|
6782
6798
|
tools: g.length ? g : void 0,
|
|
6783
6799
|
_codeAsset: {
|
|
@@ -6790,12 +6806,12 @@ function qc(e = {}) {
|
|
|
6790
6806
|
}
|
|
6791
6807
|
};
|
|
6792
6808
|
return y._rebuildCodeAssetPaths = (e) => {
|
|
6793
|
-
y.systemPrompt =
|
|
6809
|
+
y.systemPrompt = Hc(n, f, e), v && (y.skills = [Wc(e, f)]);
|
|
6794
6810
|
}, y;
|
|
6795
6811
|
}
|
|
6796
6812
|
//#endregion
|
|
6797
6813
|
//#region src/core/sdk/defineTool.ts
|
|
6798
|
-
function
|
|
6814
|
+
function Yc(e) {
|
|
6799
6815
|
return r(async (t) => {
|
|
6800
6816
|
let n = await e.handler(t);
|
|
6801
6817
|
return typeof n == "string" ? n : JSON.stringify(n);
|
|
@@ -6807,7 +6823,7 @@ function Jc(e) {
|
|
|
6807
6823
|
}
|
|
6808
6824
|
//#endregion
|
|
6809
6825
|
//#region src/core/sdk/inspectContextTool.ts
|
|
6810
|
-
var
|
|
6826
|
+
var Xc = t.object({
|
|
6811
6827
|
path: t.string().optional().describe("分类 key 过滤(如 toolResults/history/systemPrompt/dataHint);不传=全部分类"),
|
|
6812
6828
|
role: t.enum([
|
|
6813
6829
|
"user",
|
|
@@ -6817,11 +6833,11 @@ var Yc = t.object({
|
|
|
6817
6833
|
]).optional().describe("聚焦每轮首句的角色(assistant→回复摘要,user→问题摘要);不影响工具列表"),
|
|
6818
6834
|
limit: t.number().int().min(1).max(50).optional().describe("返回最近 N 轮(默认全部;超 50 自动截最近 50 防返回过大)")
|
|
6819
6835
|
});
|
|
6820
|
-
function
|
|
6821
|
-
return
|
|
6836
|
+
function Zc(e) {
|
|
6837
|
+
return Yc({
|
|
6822
6838
|
name: "inspect_context",
|
|
6823
6839
|
description: "查看当前对话上下文的构成(供压缩决策)。返回:totalTokens(历史轮次 token 总和,与触发判断同口径)、occupancy(窗口占用比)、contextWindow、categories(分类占用)、rounds(每轮 token/工具/首句)。先调用本工具查看构成,再决定压缩策略。",
|
|
6824
|
-
schema:
|
|
6840
|
+
schema: Xc,
|
|
6825
6841
|
handler: (t) => {
|
|
6826
6842
|
let n = Ho(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) => {
|
|
6827
6843
|
let n = es(e), r = Wo(e), i = t.role === "assistant" ? e.assistantMsgs[0] ?? e.userMsg : e.userMsg, a = Uo(typeof i.content == "string" ? i.content : "", 60);
|
|
@@ -6844,7 +6860,7 @@ function Xc(e) {
|
|
|
6844
6860
|
}
|
|
6845
6861
|
//#endregion
|
|
6846
6862
|
//#region src/core/sdk/compressDecision.ts
|
|
6847
|
-
var
|
|
6863
|
+
var Qc = t.object({
|
|
6848
6864
|
keepRounds: t.number().int().min(0).max(50).optional(),
|
|
6849
6865
|
windowRatio: t.number().min(0).max(1).optional(),
|
|
6850
6866
|
summarize: t.object({ mode: t.enum(["index", "llm"]) }),
|
|
@@ -6854,23 +6870,23 @@ var Zc = t.object({
|
|
|
6854
6870
|
}).refine((e) => e.keepRounds !== void 0 || e.windowRatio !== void 0, { message: "keepRounds 与 windowRatio 至少填一个(按当前触发模式)" });
|
|
6855
6871
|
//#endregion
|
|
6856
6872
|
//#region src/core/sdk/llmResolver.ts
|
|
6857
|
-
function
|
|
6873
|
+
function $c(e) {
|
|
6858
6874
|
let t = e.find((e) => e.role === "user");
|
|
6859
6875
|
if (!t) return;
|
|
6860
6876
|
let n = t.content, r = (typeof n == "string" ? n : Array.isArray(n) ? n.map((e) => typeof e == "string" ? e : e?.text ?? "").join("") : String(n ?? "")).trim().replace(/[\n\r]+/g, " ");
|
|
6861
6877
|
if (r) return r.length > 30 ? r.slice(0, 30) + "…" : r;
|
|
6862
6878
|
}
|
|
6863
|
-
function
|
|
6879
|
+
function el(e) {
|
|
6864
6880
|
return !!e && typeof e == "object" && typeof e.invoke == "function" && typeof e.stream == "function";
|
|
6865
6881
|
}
|
|
6866
|
-
function
|
|
6882
|
+
function tl(e) {
|
|
6867
6883
|
let t = e.content;
|
|
6868
6884
|
return typeof t == "string" ? t : Array.isArray(t) ? t.map((e) => typeof e == "string" ? e : e?.text ?? "").join("") : String(t ?? "");
|
|
6869
6885
|
}
|
|
6870
|
-
function
|
|
6886
|
+
function nl(e) {
|
|
6871
6887
|
let t = e.summaryLlm ?? e.llm;
|
|
6872
6888
|
if (!t) return;
|
|
6873
|
-
let n = e.summaryTemperature ?? .3, r = e.summaryMaxTokens ?? 1024, i = e.summaryTimeoutMs ?? 15e3, s =
|
|
6889
|
+
let n = e.summaryTemperature ?? .3, r = e.summaryMaxTokens ?? 1024, i = e.summaryTimeoutMs ?? 15e3, s = el(t) ? t : null, c = el(t) ? null : t;
|
|
6874
6890
|
if (c && !c.apiKey) {
|
|
6875
6891
|
e.summaryLlm && console.warn("[page-agent-sdk][summarization] summaryLlm 已配置但缺 apiKey,摘要回退主 agent 模型或零成本索引摘要");
|
|
6876
6892
|
return;
|
|
@@ -6882,16 +6898,16 @@ function tl(e) {
|
|
|
6882
6898
|
return !l && c && (l = await m(c, {
|
|
6883
6899
|
temperature: n,
|
|
6884
6900
|
maxTokens: r
|
|
6885
|
-
})),
|
|
6901
|
+
})), tl(await l.invoke([new o("你是对话历史压缩助手。把下面按轮次索引的对话要点,改写成一段连贯、紧凑的中文摘要,保留关键事实、用户意图与已用工具,不要编造。直接输出摘要正文。"), new a(e)], { signal: t.signal })).trim();
|
|
6886
6902
|
} finally {
|
|
6887
6903
|
clearTimeout(s);
|
|
6888
6904
|
}
|
|
6889
6905
|
};
|
|
6890
6906
|
}
|
|
6891
|
-
function
|
|
6907
|
+
function rl(e) {
|
|
6892
6908
|
let t = e.titleLlm ?? e.summaryLlm ?? e.llm;
|
|
6893
6909
|
if (!t) return;
|
|
6894
|
-
let n =
|
|
6910
|
+
let n = el(t) ? t : null, r = el(t) ? null : t;
|
|
6895
6911
|
if (r && !r.apiKey) return;
|
|
6896
6912
|
let i = n;
|
|
6897
6913
|
return async (t) => {
|
|
@@ -6901,8 +6917,8 @@ function nl(e) {
|
|
|
6901
6917
|
temperature: 0,
|
|
6902
6918
|
maxTokens: 30
|
|
6903
6919
|
}));
|
|
6904
|
-
let t = await i.invoke([new o(e.
|
|
6905
|
-
return
|
|
6920
|
+
let t = await i.invoke([new o(e.i18n?.locale === "en-US" ? "Generate a short English title (max 10 words) summarizing the conversation below. Output the title text only, no quotes or punctuation." : "根据以下对话的主旨,生成一个简短的中文标题(不超过15个字,不要标点和引号,直接输出标题文字)。"), new a(n)], { signal: s.signal }), c = e.i18n?.locale === "en-US" ? 60 : 20;
|
|
6921
|
+
return tl(t).trim().replace(/^["'""「『]|["'""」』]$/g, "").split("\n")[0].slice(0, c);
|
|
6906
6922
|
} catch {
|
|
6907
6923
|
return "";
|
|
6908
6924
|
} finally {
|
|
@@ -6910,10 +6926,10 @@ function nl(e) {
|
|
|
6910
6926
|
}
|
|
6911
6927
|
};
|
|
6912
6928
|
}
|
|
6913
|
-
function
|
|
6929
|
+
function il() {
|
|
6914
6930
|
return `call_dec_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
|
|
6915
6931
|
}
|
|
6916
|
-
function
|
|
6932
|
+
function al(e) {
|
|
6917
6933
|
let t = e.match(/```(?:json)?\s*([\s\S]*?)```/), n = t ? t[1] : e, r = n.indexOf("{"), i = n.lastIndexOf("}");
|
|
6918
6934
|
if (r < 0 || i < 0 || i <= r) return null;
|
|
6919
6935
|
try {
|
|
@@ -6922,21 +6938,21 @@ function il(e) {
|
|
|
6922
6938
|
return null;
|
|
6923
6939
|
}
|
|
6924
6940
|
}
|
|
6925
|
-
function
|
|
6941
|
+
function ol(e) {
|
|
6926
6942
|
if (!e) return null;
|
|
6927
|
-
let t =
|
|
6943
|
+
let t = al(e);
|
|
6928
6944
|
if (t == null) return null;
|
|
6929
|
-
let n =
|
|
6945
|
+
let n = Qc.safeParse(t);
|
|
6930
6946
|
return n.success ? n.data : null;
|
|
6931
6947
|
}
|
|
6932
|
-
async function
|
|
6948
|
+
async function sl(e, t, n, r) {
|
|
6933
6949
|
let i = [...n];
|
|
6934
6950
|
for (let n = 0; n < 3; n++) {
|
|
6935
6951
|
let n = await e.invoke(i, { signal: r }), a = n?.tool_calls ?? [];
|
|
6936
|
-
if (!a.length) return
|
|
6952
|
+
if (!a.length) return tl(n).trim();
|
|
6937
6953
|
i = [...i, n];
|
|
6938
6954
|
for (let e of a) {
|
|
6939
|
-
let n = e.id ??
|
|
6955
|
+
let n = e.id ?? il();
|
|
6940
6956
|
try {
|
|
6941
6957
|
let r = await t.invoke(e.args ?? {}), a = typeof r == "string" ? r : r?.content ?? JSON.stringify(r);
|
|
6942
6958
|
i = [...i, new s({
|
|
@@ -6953,10 +6969,10 @@ async function ol(e, t, n, r) {
|
|
|
6953
6969
|
}
|
|
6954
6970
|
return "";
|
|
6955
6971
|
}
|
|
6956
|
-
function
|
|
6972
|
+
function cl(e) {
|
|
6957
6973
|
let t = e.summaryLlm ?? e.llm;
|
|
6958
6974
|
if (!t) return;
|
|
6959
|
-
let n =
|
|
6975
|
+
let n = el(t) ? t : null, r = el(t) ? null : t;
|
|
6960
6976
|
if (r && !r.apiKey) return;
|
|
6961
6977
|
let i = e.decisionTimeoutMs ?? 6e3, s = e.decisionMaxTokens ?? 2048, c = n;
|
|
6962
6978
|
return async (e) => {
|
|
@@ -6968,12 +6984,12 @@ function sl(e) {
|
|
|
6968
6984
|
}));
|
|
6969
6985
|
let n = c;
|
|
6970
6986
|
if (typeof n.bindTools != "function") return null;
|
|
6971
|
-
let i =
|
|
6987
|
+
let i = Zc({
|
|
6972
6988
|
getMessages: e.getMessages,
|
|
6973
6989
|
getSnapshot: e.getSnapshot,
|
|
6974
6990
|
contextWindow: e.contextWindow
|
|
6975
6991
|
}), l = n.bindTools([i]), u = e.triggerMode === "token" ? "token 模式:必填 windowRatio(0~1 保留窗口预算比例,如 0.4);keepRounds 可选" : "轮数模式:必填 keepRounds(保留最近几轮,如 6);windowRatio 可选", d = [new o(`你是对话历史压缩决策助手。当前触发模式 = ${e.triggerMode}(${e.triggerReason})。先调用 inspect_context 查看上下文构成,再输出压缩决策 JSON。${u}。仅输出 JSON,不要多余文字/markdown。schema:{keepRounds?(int 0-50), windowRatio?(0-1), summarize:{mode:"index"|"llm"}, recallTopK?(int 0-10), preserveTools?(string[]≤10), reason?(≤200字)}。keepRounds/windowRatio 至少填一个。`), new a(`触发原因:${e.triggerReason}\n上下文窗口:${e.contextWindow ?? "未知"} tokens\n阈值比例:${e.thresholdRatio ?? "未知"}\n\n请决策压缩策略(先 inspect_context 查看,再输出 JSON)。`)];
|
|
6976
|
-
return
|
|
6992
|
+
return ol(await sl(l, i, d, t.signal)) || ol(await sl(l, i, [...d, new a("上一次输出无效(JSON 解析失败或 schema 校验不通过)。请只输出符合 schema 的压缩决策 JSON,不要多余文字/markdown 代码块。")], t.signal));
|
|
6977
6993
|
} catch {
|
|
6978
6994
|
return null;
|
|
6979
6995
|
} finally {
|
|
@@ -6981,22 +6997,22 @@ function sl(e) {
|
|
|
6981
6997
|
}
|
|
6982
6998
|
};
|
|
6983
6999
|
}
|
|
6984
|
-
function
|
|
6985
|
-
let t = e.llm, n =
|
|
7000
|
+
function ll(e) {
|
|
7001
|
+
let t = e.llm, n = el(e.llm) ? void 0 : e.llm;
|
|
6986
7002
|
return {
|
|
6987
7003
|
modelCaps: oi({
|
|
6988
7004
|
model: n?.model ?? t?.model ?? t?.modelName,
|
|
6989
7005
|
contextWindow: e.contextWindow ?? n?.contextWindow ?? t?.contextWindow,
|
|
6990
7006
|
maxOutputTokens: e.maxOutputTokens ?? n?.maxOutputTokens ?? t?.maxOutputTokens
|
|
6991
7007
|
}),
|
|
6992
|
-
summaryLlmInvoke:
|
|
6993
|
-
titleLlmInvoke:
|
|
6994
|
-
compressDecisionInvoke:
|
|
7008
|
+
summaryLlmInvoke: nl(e),
|
|
7009
|
+
titleLlmInvoke: rl(e),
|
|
7010
|
+
compressDecisionInvoke: cl(e)
|
|
6995
7011
|
};
|
|
6996
7012
|
}
|
|
6997
7013
|
//#endregion
|
|
6998
7014
|
//#region src/core/sdk/conflictManager.ts
|
|
6999
|
-
function
|
|
7015
|
+
function ul(e) {
|
|
7000
7016
|
let t = /* @__PURE__ */ At(null), n = 0;
|
|
7001
7017
|
function r(r) {
|
|
7002
7018
|
return new Promise((i) => {
|
|
@@ -7027,7 +7043,7 @@ function ll(e) {
|
|
|
7027
7043
|
}
|
|
7028
7044
|
//#endregion
|
|
7029
7045
|
//#region src/core/utils/id.ts
|
|
7030
|
-
function
|
|
7046
|
+
function dl() {
|
|
7031
7047
|
try {
|
|
7032
7048
|
if (typeof crypto < "u" && typeof crypto.randomUUID == "function") return crypto.randomUUID();
|
|
7033
7049
|
} catch {}
|
|
@@ -7035,7 +7051,7 @@ function ul() {
|
|
|
7035
7051
|
}
|
|
7036
7052
|
//#endregion
|
|
7037
7053
|
//#region src/core/backends/storage.ts
|
|
7038
|
-
var
|
|
7054
|
+
var fl = "chat-sdk", pl = 50 * 1024 * 1024, ml = 4 * 1024 * 1024, hl = 10 * 1024 * 1024, gl = .9, _l = 500, vl = 300, yl = "__meta__", bl = "v:1", xl = [
|
|
7039
7055
|
"messages",
|
|
7040
7056
|
"vfs",
|
|
7041
7057
|
"todos",
|
|
@@ -7046,51 +7062,51 @@ var dl = "chat-sdk", fl = 50 * 1024 * 1024, pl = 4 * 1024 * 1024, ml = 10 * 1024
|
|
|
7046
7062
|
"workingMemory",
|
|
7047
7063
|
"focus"
|
|
7048
7064
|
];
|
|
7049
|
-
function xl(e) {
|
|
7050
|
-
return e === "local" || e === "session" ? pl : fl;
|
|
7051
|
-
}
|
|
7052
7065
|
function Sl(e) {
|
|
7066
|
+
return e === "local" || e === "session" ? ml : pl;
|
|
7067
|
+
}
|
|
7068
|
+
function Cl(e) {
|
|
7053
7069
|
if (typeof e != "object" || !e) return !1;
|
|
7054
7070
|
let t = e;
|
|
7055
7071
|
return t.name === "QuotaExceededError" || t.name === "NS_ERROR_DOM_QUOTA_REACHED" || t.code === 22 || t.code === 1014;
|
|
7056
7072
|
}
|
|
7057
|
-
function
|
|
7073
|
+
function wl(e, t, n, r) {
|
|
7058
7074
|
return [
|
|
7059
|
-
|
|
7075
|
+
bl,
|
|
7060
7076
|
e,
|
|
7061
7077
|
t,
|
|
7062
7078
|
n,
|
|
7063
7079
|
r
|
|
7064
7080
|
].join("::");
|
|
7065
7081
|
}
|
|
7066
|
-
function
|
|
7082
|
+
function Tl(e, t, n) {
|
|
7067
7083
|
return [
|
|
7068
|
-
|
|
7084
|
+
bl,
|
|
7069
7085
|
e,
|
|
7070
7086
|
t,
|
|
7071
7087
|
n
|
|
7072
7088
|
].join("::") + "::";
|
|
7073
7089
|
}
|
|
7074
|
-
function
|
|
7090
|
+
function El(e, t) {
|
|
7075
7091
|
return [
|
|
7076
|
-
|
|
7092
|
+
bl,
|
|
7077
7093
|
e,
|
|
7078
7094
|
t
|
|
7079
7095
|
].join("::") + "::";
|
|
7080
7096
|
}
|
|
7081
|
-
function
|
|
7082
|
-
return [
|
|
7097
|
+
function Dl(e) {
|
|
7098
|
+
return [bl, e].join("::") + "::";
|
|
7083
7099
|
}
|
|
7084
|
-
var
|
|
7085
|
-
function
|
|
7086
|
-
|
|
7100
|
+
var Ol = null;
|
|
7101
|
+
function kl(e) {
|
|
7102
|
+
Ol ||= new TextEncoder();
|
|
7087
7103
|
try {
|
|
7088
|
-
return
|
|
7104
|
+
return Ol.encode(JSON.stringify(e)).length;
|
|
7089
7105
|
} catch {
|
|
7090
7106
|
return 0;
|
|
7091
7107
|
}
|
|
7092
7108
|
}
|
|
7093
|
-
function
|
|
7109
|
+
function Al(e, t, n) {
|
|
7094
7110
|
let r = e.reduce((e, t) => e + t.bytes, 0);
|
|
7095
7111
|
if (r <= t) return [];
|
|
7096
7112
|
let i = t * n, a = [...e].sort((e, t) => e.lastAccessed - t.lastAccessed), o = [];
|
|
@@ -7100,7 +7116,7 @@ function kl(e, t, n) {
|
|
|
7100
7116
|
}
|
|
7101
7117
|
return o;
|
|
7102
7118
|
}
|
|
7103
|
-
function
|
|
7119
|
+
function jl() {
|
|
7104
7120
|
let e = /* @__PURE__ */ new Map();
|
|
7105
7121
|
return {
|
|
7106
7122
|
async get(t) {
|
|
@@ -7120,7 +7136,7 @@ function Al() {
|
|
|
7120
7136
|
}
|
|
7121
7137
|
};
|
|
7122
7138
|
}
|
|
7123
|
-
function
|
|
7139
|
+
function Ml(e) {
|
|
7124
7140
|
return new Promise((t, n) => {
|
|
7125
7141
|
if (typeof indexedDB > "u") {
|
|
7126
7142
|
n(/* @__PURE__ */ Error("indexedDB 不可用"));
|
|
@@ -7181,7 +7197,7 @@ function jl(e) {
|
|
|
7181
7197
|
}, r.onerror = () => n(r.error);
|
|
7182
7198
|
});
|
|
7183
7199
|
}
|
|
7184
|
-
function
|
|
7200
|
+
function Nl(e) {
|
|
7185
7201
|
return {
|
|
7186
7202
|
async get(t) {
|
|
7187
7203
|
let n = e.getItem(t);
|
|
@@ -7226,12 +7242,12 @@ function Ml(e) {
|
|
|
7226
7242
|
}
|
|
7227
7243
|
};
|
|
7228
7244
|
}
|
|
7229
|
-
function
|
|
7245
|
+
function Pl(e, t, n) {
|
|
7230
7246
|
let r = (e.get(t) ?? Promise.resolve()).then(n, n);
|
|
7231
7247
|
return e.set(t, r.then(() => void 0, () => void 0)), r;
|
|
7232
7248
|
}
|
|
7233
|
-
function
|
|
7234
|
-
let t = e.dbName ??
|
|
7249
|
+
function Fl(e = {}) {
|
|
7250
|
+
let t = e.dbName ?? fl, n = e.backend ?? "indexed", r = e.maxBytes ?? Sl(n), i = e.maxBytesPerSession ?? hl, a = e.evictionWatermark ?? gl, o = e.debounceMs ?? _l, s = /* @__PURE__ */ new Set();
|
|
7235
7251
|
function c(e) {
|
|
7236
7252
|
for (let t of s) try {
|
|
7237
7253
|
t(e);
|
|
@@ -7244,16 +7260,16 @@ function Pl(e = {}) {
|
|
|
7244
7260
|
try {
|
|
7245
7261
|
if (n === "indexed") {
|
|
7246
7262
|
if (typeof indexedDB > "u") throw Error("indexedDB 不可用");
|
|
7247
|
-
l = await
|
|
7263
|
+
l = await Ml(t), d(!0);
|
|
7248
7264
|
} else if (n === "session") {
|
|
7249
7265
|
if (typeof sessionStorage > "u") throw Error("sessionStorage 不可用");
|
|
7250
|
-
l =
|
|
7266
|
+
l = Nl(sessionStorage), d(!0);
|
|
7251
7267
|
} else if (n === "local") {
|
|
7252
7268
|
if (typeof localStorage > "u") throw Error("localStorage 不可用");
|
|
7253
|
-
l =
|
|
7254
|
-
} else l =
|
|
7269
|
+
l = Nl(localStorage), d(!0);
|
|
7270
|
+
} else l = jl(), d(!1);
|
|
7255
7271
|
} catch (e) {
|
|
7256
|
-
l =
|
|
7272
|
+
l = jl();
|
|
7257
7273
|
let t = e instanceof Error ? e.message : String(e);
|
|
7258
7274
|
d(!1), Promise.resolve().then(() => c({
|
|
7259
7275
|
type: "degraded",
|
|
@@ -7263,10 +7279,10 @@ function Pl(e = {}) {
|
|
|
7263
7279
|
})();
|
|
7264
7280
|
let p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
|
|
7265
7281
|
function g(e, n, r, a) {
|
|
7266
|
-
let o =
|
|
7267
|
-
return
|
|
7282
|
+
let o = wl(t, r, a, yl);
|
|
7283
|
+
return Pl(h, o, async () => {
|
|
7268
7284
|
let t = async () => {
|
|
7269
|
-
let t = await l.get(o), s = await l.get(e), u = s == null ? 0 :
|
|
7285
|
+
let t = await l.get(o), s = await l.get(e), u = s == null ? 0 : kl(s), d = kl(n), f = (t?.bytes ?? 0) + (d - u);
|
|
7270
7286
|
if (f > i) {
|
|
7271
7287
|
c({
|
|
7272
7288
|
type: "quota",
|
|
@@ -7288,12 +7304,12 @@ function Pl(e = {}) {
|
|
|
7288
7304
|
try {
|
|
7289
7305
|
await t();
|
|
7290
7306
|
} catch (e) {
|
|
7291
|
-
if (
|
|
7307
|
+
if (Cl(e) && !u) {
|
|
7292
7308
|
u = !0;
|
|
7293
7309
|
try {
|
|
7294
7310
|
await b();
|
|
7295
7311
|
} catch {}
|
|
7296
|
-
l =
|
|
7312
|
+
l = jl(), Promise.resolve().then(() => c({
|
|
7297
7313
|
type: "degraded",
|
|
7298
7314
|
reason: "存储配额超限(QuotaExceededError),已淘汰最旧会话并降级内存"
|
|
7299
7315
|
}));
|
|
@@ -7305,7 +7321,7 @@ function Pl(e = {}) {
|
|
|
7305
7321
|
});
|
|
7306
7322
|
}
|
|
7307
7323
|
function _(e, n, r, i) {
|
|
7308
|
-
let a =
|
|
7324
|
+
let a = wl(t, e, n, r), s = p.get(a);
|
|
7309
7325
|
s && s.resolve();
|
|
7310
7326
|
let c = m.get(a);
|
|
7311
7327
|
return c && clearTimeout(c), new Promise((t) => {
|
|
@@ -7332,15 +7348,15 @@ function Pl(e = {}) {
|
|
|
7332
7348
|
function y() {
|
|
7333
7349
|
v ||= setTimeout(() => {
|
|
7334
7350
|
v = null, b();
|
|
7335
|
-
},
|
|
7351
|
+
}, vl);
|
|
7336
7352
|
}
|
|
7337
7353
|
async function b() {
|
|
7338
7354
|
let e = [];
|
|
7339
|
-
await l.scan(
|
|
7355
|
+
await l.scan(Dl(t), (t, n) => {
|
|
7340
7356
|
t.endsWith("::__meta__") && e.push(n);
|
|
7341
7357
|
});
|
|
7342
|
-
let n =
|
|
7343
|
-
for (let e of n) await l.clearPrefix(
|
|
7358
|
+
let n = Al(e, r, a);
|
|
7359
|
+
for (let e of n) await l.clearPrefix(Tl(t, e.agentId, e.sessionId)), c({
|
|
7344
7360
|
type: "evicted",
|
|
7345
7361
|
agentId: e.agentId,
|
|
7346
7362
|
sessionId: e.sessionId,
|
|
@@ -7351,13 +7367,13 @@ function Pl(e = {}) {
|
|
|
7351
7367
|
ready: f,
|
|
7352
7368
|
async listSessions(e) {
|
|
7353
7369
|
let n = [];
|
|
7354
|
-
return await l.scan(
|
|
7370
|
+
return await l.scan(El(t, e), (e, t) => {
|
|
7355
7371
|
e.endsWith("::__meta__") && n.push(t);
|
|
7356
7372
|
}), n.sort((e, t) => t.lastAccessed - e.lastAccessed);
|
|
7357
7373
|
},
|
|
7358
7374
|
async load(e, n) {
|
|
7359
|
-
let r =
|
|
7360
|
-
return await
|
|
7375
|
+
let r = wl(t, e, n, yl);
|
|
7376
|
+
return await Pl(h, r, async () => {
|
|
7361
7377
|
let i = await l.get(r);
|
|
7362
7378
|
if (!i) return;
|
|
7363
7379
|
let a = {
|
|
@@ -7366,8 +7382,8 @@ function Pl(e = {}) {
|
|
|
7366
7382
|
todos: [],
|
|
7367
7383
|
memory: ""
|
|
7368
7384
|
};
|
|
7369
|
-
for (let r of
|
|
7370
|
-
let i = await l.get(
|
|
7385
|
+
for (let r of xl) {
|
|
7386
|
+
let i = await l.get(wl(t, e, n, r));
|
|
7371
7387
|
i != null && (a[r] = i);
|
|
7372
7388
|
}
|
|
7373
7389
|
return i.lastAccessed = Date.now(), await l.set(r, i), a;
|
|
@@ -7375,12 +7391,12 @@ function Pl(e = {}) {
|
|
|
7375
7391
|
},
|
|
7376
7392
|
async save(e, t, n) {
|
|
7377
7393
|
let r = [];
|
|
7378
|
-
for (let i of
|
|
7394
|
+
for (let i of xl) n[i] !== void 0 && r.push(_(e, t, i, n[i]));
|
|
7379
7395
|
await Promise.all(r);
|
|
7380
7396
|
},
|
|
7381
7397
|
async updateTitle(e, n, r) {
|
|
7382
|
-
let i =
|
|
7383
|
-
return
|
|
7398
|
+
let i = wl(t, e, n, yl);
|
|
7399
|
+
return Pl(h, i, async () => {
|
|
7384
7400
|
let e = await l.get(i);
|
|
7385
7401
|
e && (e.title = r, e.lastAccessed = Date.now(), await l.set(i, e));
|
|
7386
7402
|
});
|
|
@@ -7396,13 +7412,13 @@ function Pl(e = {}) {
|
|
|
7396
7412
|
})), c({ type: "flush" }), await b();
|
|
7397
7413
|
},
|
|
7398
7414
|
async deleteSession(e, n) {
|
|
7399
|
-
let r =
|
|
7415
|
+
let r = Tl(t, e, n);
|
|
7400
7416
|
for (let [e, t] of p.entries()) e.startsWith(r) && (t.resolve(), p.delete(e));
|
|
7401
7417
|
for (let [e, t] of m.entries()) e.startsWith(r) && (clearTimeout(t), m.delete(e));
|
|
7402
7418
|
await l.clearPrefix(r);
|
|
7403
7419
|
},
|
|
7404
7420
|
async createSession(e, n, r) {
|
|
7405
|
-
let i = r ??
|
|
7421
|
+
let i = r ?? dl(), a = Date.now(), o = {
|
|
7406
7422
|
agentId: e,
|
|
7407
7423
|
sessionId: i,
|
|
7408
7424
|
createdAt: a,
|
|
@@ -7410,7 +7426,7 @@ function Pl(e = {}) {
|
|
|
7410
7426
|
bytes: 0,
|
|
7411
7427
|
title: n
|
|
7412
7428
|
};
|
|
7413
|
-
return await l.set(
|
|
7429
|
+
return await l.set(wl(t, e, i, yl), o), i;
|
|
7414
7430
|
},
|
|
7415
7431
|
onEvent(e) {
|
|
7416
7432
|
s.add(e);
|
|
@@ -7425,15 +7441,15 @@ function Pl(e = {}) {
|
|
|
7425
7441
|
}
|
|
7426
7442
|
//#endregion
|
|
7427
7443
|
//#region src/core/sdk/optionsResolver.ts
|
|
7428
|
-
function Fl(e) {
|
|
7429
|
-
return e === void 0 ? Pl({ backend: "memory" }) : e === !1 ? null : typeof e == "string" ? Pl({ backend: e }) : e.enabled === !1 ? null : Pl(e);
|
|
7430
|
-
}
|
|
7431
7444
|
function Il(e) {
|
|
7445
|
+
return e === void 0 ? Fl({ backend: "memory" }) : e === !1 ? null : typeof e == "string" ? Fl({ backend: e }) : e.enabled === !1 ? null : Fl(e);
|
|
7446
|
+
}
|
|
7447
|
+
function Ll(e) {
|
|
7432
7448
|
return e.dialog ?? {};
|
|
7433
7449
|
}
|
|
7434
7450
|
//#endregion
|
|
7435
7451
|
//#region src/core/capabilities.ts
|
|
7436
|
-
var
|
|
7452
|
+
var Rl = [
|
|
7437
7453
|
{
|
|
7438
7454
|
name: "dataOps",
|
|
7439
7455
|
defaultOn: !0
|
|
@@ -7522,13 +7538,13 @@ var Ll = [
|
|
|
7522
7538
|
requires: ["summarization"]
|
|
7523
7539
|
}
|
|
7524
7540
|
];
|
|
7525
|
-
function
|
|
7541
|
+
function zl(e) {
|
|
7526
7542
|
let t = {};
|
|
7527
|
-
for (let n of
|
|
7543
|
+
for (let n of Rl) {
|
|
7528
7544
|
let r = e?.[n.name];
|
|
7529
7545
|
t[n.name] = n.defaultOn ? r !== !1 : r === !0;
|
|
7530
7546
|
}
|
|
7531
|
-
for (let e of
|
|
7547
|
+
for (let e of Rl) if (e.requires && t[e.name]) {
|
|
7532
7548
|
for (let n of e.requires) if (!t[n]) {
|
|
7533
7549
|
t[e.name] = !1;
|
|
7534
7550
|
break;
|
|
@@ -7538,7 +7554,7 @@ function Rl(e) {
|
|
|
7538
7554
|
}
|
|
7539
7555
|
//#endregion
|
|
7540
7556
|
//#region src/core/sdk/events.ts
|
|
7541
|
-
function
|
|
7557
|
+
function Bl(e) {
|
|
7542
7558
|
let t = /* @__PURE__ */ new Set(), n = (n) => {
|
|
7543
7559
|
if (n.type !== "approval_request") {
|
|
7544
7560
|
if (e) try {
|
|
@@ -7564,7 +7580,7 @@ function zl(e) {
|
|
|
7564
7580
|
}
|
|
7565
7581
|
//#endregion
|
|
7566
7582
|
//#region src/core/sdk/contextPreset.ts
|
|
7567
|
-
var
|
|
7583
|
+
var Vl = {
|
|
7568
7584
|
auto: {
|
|
7569
7585
|
summaryThresholdRatio: .5,
|
|
7570
7586
|
windowRatio: .4,
|
|
@@ -7592,7 +7608,7 @@ var Bl = {
|
|
|
7592
7608
|
enableRecall: !0,
|
|
7593
7609
|
enableLLMSummary: !0
|
|
7594
7610
|
}
|
|
7595
|
-
},
|
|
7611
|
+
}, Hl = {
|
|
7596
7612
|
auto: ["describe_data", "read"],
|
|
7597
7613
|
conservative: ["describe_data"],
|
|
7598
7614
|
aggressive: ["describe_data", "read"],
|
|
@@ -7603,8 +7619,8 @@ var Bl = {
|
|
|
7603
7619
|
"search_data"
|
|
7604
7620
|
]
|
|
7605
7621
|
};
|
|
7606
|
-
function
|
|
7607
|
-
let n =
|
|
7622
|
+
function Ul(e, t) {
|
|
7623
|
+
let n = Vl[e.contextPreset ?? "auto"] ?? {}, r = e.contextOptions === !1 ? {} : e.contextOptions ?? {};
|
|
7608
7624
|
return {
|
|
7609
7625
|
...n,
|
|
7610
7626
|
...r,
|
|
@@ -7614,7 +7630,7 @@ function Hl(e, t) {
|
|
|
7614
7630
|
}
|
|
7615
7631
|
//#endregion
|
|
7616
7632
|
//#region src/core/sdk/middlewareStack.ts
|
|
7617
|
-
var
|
|
7633
|
+
var Wl = {
|
|
7618
7634
|
dataHint: 10,
|
|
7619
7635
|
usageHints: 20,
|
|
7620
7636
|
todos: 30,
|
|
@@ -7631,17 +7647,17 @@ var Ul = {
|
|
|
7631
7647
|
subagents: 140,
|
|
7632
7648
|
augmentSystem: 150
|
|
7633
7649
|
};
|
|
7634
|
-
function
|
|
7650
|
+
function Gl(e) {
|
|
7635
7651
|
return e.map((e, t) => ({
|
|
7636
7652
|
m: e,
|
|
7637
7653
|
i: t,
|
|
7638
|
-
p:
|
|
7654
|
+
p: Wl[e.name] ?? Infinity
|
|
7639
7655
|
})).sort((e, t) => e.p - t.p || e.i - t.i).map((e) => e.m);
|
|
7640
7656
|
}
|
|
7641
7657
|
//#endregion
|
|
7642
7658
|
//#region src/core/tools/dataSlotQuery.ts
|
|
7643
|
-
var
|
|
7644
|
-
function
|
|
7659
|
+
var Kl = /[\w$-]/;
|
|
7660
|
+
function ql(e) {
|
|
7645
7661
|
let t = [], n = e.trim(), r = +(n[0] === "$");
|
|
7646
7662
|
for (; r < n.length;) {
|
|
7647
7663
|
let e = n[r];
|
|
@@ -7652,7 +7668,7 @@ function Kl(e) {
|
|
|
7652
7668
|
continue;
|
|
7653
7669
|
}
|
|
7654
7670
|
let e = "";
|
|
7655
|
-
for (; r < n.length &&
|
|
7671
|
+
for (; r < n.length && Kl.test(n[r]);) e += n[r++];
|
|
7656
7672
|
if (!e) throw Error("JSONPath: .. 后缺属性名");
|
|
7657
7673
|
t.push({
|
|
7658
7674
|
type: "descendKey",
|
|
@@ -7665,7 +7681,7 @@ function Kl(e) {
|
|
|
7665
7681
|
continue;
|
|
7666
7682
|
}
|
|
7667
7683
|
let e = "";
|
|
7668
|
-
for (; r < n.length &&
|
|
7684
|
+
for (; r < n.length && Kl.test(n[r]);) e += n[r++];
|
|
7669
7685
|
if (!e) throw Error("JSONPath: . 后缺属性名");
|
|
7670
7686
|
t.push({
|
|
7671
7687
|
type: "key",
|
|
@@ -7721,7 +7737,7 @@ function Kl(e) {
|
|
|
7721
7737
|
}
|
|
7722
7738
|
return t;
|
|
7723
7739
|
}
|
|
7724
|
-
function
|
|
7740
|
+
function Jl(e) {
|
|
7725
7741
|
let t = [], n = 0, r = e.trim();
|
|
7726
7742
|
for (; n < r.length;) {
|
|
7727
7743
|
let e = r[n];
|
|
@@ -7766,7 +7782,7 @@ function ql(e) {
|
|
|
7766
7782
|
}
|
|
7767
7783
|
return t;
|
|
7768
7784
|
}
|
|
7769
|
-
var
|
|
7785
|
+
var Yl = class {
|
|
7770
7786
|
toks;
|
|
7771
7787
|
item;
|
|
7772
7788
|
pos = 0;
|
|
@@ -7802,12 +7818,12 @@ var Jl = class {
|
|
|
7802
7818
|
return this.next(), e;
|
|
7803
7819
|
}
|
|
7804
7820
|
let e = this.operand(), t = this.peek();
|
|
7805
|
-
return t === "==" || t === "!=" || t === "<" || t === "<=" || t === ">" || t === ">=" ? (this.next(),
|
|
7821
|
+
return t === "==" || t === "!=" || t === "<" || t === "<=" || t === ">" || t === ">=" ? (this.next(), Ql(t, e, this.operand())) : Xl(e);
|
|
7806
7822
|
}
|
|
7807
7823
|
operand() {
|
|
7808
7824
|
let e = this.next();
|
|
7809
7825
|
if (e === void 0) throw Error("过滤表达式:缺操作数");
|
|
7810
|
-
if (e.startsWith("@")) return
|
|
7826
|
+
if (e.startsWith("@")) return Zl(e, this.item);
|
|
7811
7827
|
if (e[0] === "'" || e[0] === "\"") return e.slice(1, -1);
|
|
7812
7828
|
if (e === "true") return !0;
|
|
7813
7829
|
if (e === "false") return !1;
|
|
@@ -7817,10 +7833,10 @@ var Jl = class {
|
|
|
7817
7833
|
throw Error(`过滤表达式:未知操作数 '${e}'`);
|
|
7818
7834
|
}
|
|
7819
7835
|
};
|
|
7820
|
-
function
|
|
7836
|
+
function Xl(e) {
|
|
7821
7837
|
return !!e && e !== 0 && e !== "" && e !== null;
|
|
7822
7838
|
}
|
|
7823
|
-
function
|
|
7839
|
+
function Zl(e, t) {
|
|
7824
7840
|
let n = e.split(".").filter((e) => e && e !== "@"), r = t;
|
|
7825
7841
|
for (let e of n) {
|
|
7826
7842
|
if (typeof r != "object" || !r) return;
|
|
@@ -7828,7 +7844,7 @@ function Xl(e, t) {
|
|
|
7828
7844
|
}
|
|
7829
7845
|
return r;
|
|
7830
7846
|
}
|
|
7831
|
-
function
|
|
7847
|
+
function Ql(e, t, n) {
|
|
7832
7848
|
switch (e) {
|
|
7833
7849
|
case "==": return t === n;
|
|
7834
7850
|
case "!=": return t !== n;
|
|
@@ -7839,47 +7855,47 @@ function Zl(e, t, n) {
|
|
|
7839
7855
|
default: return !1;
|
|
7840
7856
|
}
|
|
7841
7857
|
}
|
|
7842
|
-
function Ql(e, t) {
|
|
7843
|
-
return new Jl(ql(e), t).parse();
|
|
7844
|
-
}
|
|
7845
7858
|
function $l(e, t) {
|
|
7846
|
-
return
|
|
7859
|
+
return new Yl(Jl(e), t).parse();
|
|
7847
7860
|
}
|
|
7848
7861
|
function eu(e, t) {
|
|
7862
|
+
return e ? `${e}.${t}` : String(t);
|
|
7863
|
+
}
|
|
7864
|
+
function tu(e, t) {
|
|
7849
7865
|
let n = [{
|
|
7850
7866
|
path: "",
|
|
7851
7867
|
value: e
|
|
7852
7868
|
}];
|
|
7853
|
-
for (let e of
|
|
7869
|
+
for (let e of ql(t)) {
|
|
7854
7870
|
let t = [];
|
|
7855
7871
|
if (e.type === "key") for (let r of n) r.value != null && typeof r.value == "object" && e.key in r.value && t.push({
|
|
7856
|
-
path:
|
|
7872
|
+
path: eu(r.path, e.key),
|
|
7857
7873
|
value: r.value[e.key]
|
|
7858
7874
|
});
|
|
7859
7875
|
else if (e.type === "index") {
|
|
7860
7876
|
for (let r of n) if (Array.isArray(r.value)) {
|
|
7861
7877
|
let n = r.value[e.index];
|
|
7862
7878
|
e.index >= 0 && e.index < r.value.length && t.push({
|
|
7863
|
-
path:
|
|
7879
|
+
path: eu(r.path, e.index),
|
|
7864
7880
|
value: n,
|
|
7865
7881
|
index: e.index
|
|
7866
7882
|
});
|
|
7867
7883
|
}
|
|
7868
7884
|
} else if (e.type === "wildcard") {
|
|
7869
7885
|
for (let e of n) if (Array.isArray(e.value)) e.value.forEach((n, r) => t.push({
|
|
7870
|
-
path:
|
|
7886
|
+
path: eu(e.path, r),
|
|
7871
7887
|
value: n,
|
|
7872
7888
|
index: r
|
|
7873
7889
|
}));
|
|
7874
7890
|
else if (e.value != null && typeof e.value == "object") for (let n of Object.keys(e.value)) t.push({
|
|
7875
|
-
path:
|
|
7891
|
+
path: eu(e.path, n),
|
|
7876
7892
|
value: e.value[n]
|
|
7877
7893
|
});
|
|
7878
7894
|
} else if (e.type === "descendKey") {
|
|
7879
7895
|
let r = e.key, i = (e) => {
|
|
7880
7896
|
if (!(e.value == null || typeof e.value != "object")) for (let n of Object.keys(e.value)) {
|
|
7881
7897
|
let a = {
|
|
7882
|
-
path:
|
|
7898
|
+
path: eu(e.path, n),
|
|
7883
7899
|
value: e.value[n]
|
|
7884
7900
|
};
|
|
7885
7901
|
n === r && t.push(a), i(a);
|
|
@@ -7890,7 +7906,7 @@ function eu(e, t) {
|
|
|
7890
7906
|
let e = (n) => {
|
|
7891
7907
|
if (!(n.value == null || typeof n.value != "object")) for (let r of Object.keys(n.value)) {
|
|
7892
7908
|
let i = {
|
|
7893
|
-
path:
|
|
7909
|
+
path: eu(n.path, r),
|
|
7894
7910
|
value: n.value[r]
|
|
7895
7911
|
};
|
|
7896
7912
|
t.push(i), e(i);
|
|
@@ -7899,16 +7915,16 @@ function eu(e, t) {
|
|
|
7899
7915
|
for (let t of n) e(t);
|
|
7900
7916
|
} else if (e.type === "filter") {
|
|
7901
7917
|
for (let r of n) if (Array.isArray(r.value)) r.value.forEach((n, i) => {
|
|
7902
|
-
|
|
7903
|
-
path:
|
|
7918
|
+
$l(e.filter, n) && t.push({
|
|
7919
|
+
path: eu(r.path, i),
|
|
7904
7920
|
value: n,
|
|
7905
7921
|
index: i
|
|
7906
7922
|
});
|
|
7907
7923
|
});
|
|
7908
7924
|
else if (r.value != null && typeof r.value == "object") for (let n of Object.keys(r.value)) {
|
|
7909
7925
|
let i = r.value[n];
|
|
7910
|
-
|
|
7911
|
-
path:
|
|
7926
|
+
$l(e.filter, i) && t.push({
|
|
7927
|
+
path: eu(r.path, n),
|
|
7912
7928
|
value: i
|
|
7913
7929
|
});
|
|
7914
7930
|
}
|
|
@@ -7917,7 +7933,7 @@ function eu(e, t) {
|
|
|
7917
7933
|
}
|
|
7918
7934
|
return n;
|
|
7919
7935
|
}
|
|
7920
|
-
function
|
|
7936
|
+
function nu(e, t) {
|
|
7921
7937
|
let n = e.length, r = t.length;
|
|
7922
7938
|
if (!n) return r;
|
|
7923
7939
|
if (!r) return n;
|
|
@@ -7933,7 +7949,7 @@ function tu(e, t) {
|
|
|
7933
7949
|
}
|
|
7934
7950
|
return i[r];
|
|
7935
7951
|
}
|
|
7936
|
-
function
|
|
7952
|
+
function ru(e, t, n = {}) {
|
|
7937
7953
|
let r = n.mode || "substring", i = n.limit ?? 50, a = n.matchKey !== !1, o = [], s = null;
|
|
7938
7954
|
if (r === "regex") try {
|
|
7939
7955
|
s = new RegExp(t, "i");
|
|
@@ -7943,11 +7959,11 @@ function nu(e, t, n = {}) {
|
|
|
7943
7959
|
let c = (e, l, u) => {
|
|
7944
7960
|
if (o.length >= i || e == null) return;
|
|
7945
7961
|
if (typeof e == "object") {
|
|
7946
|
-
if (Array.isArray(e)) e.forEach((e, t) => c(e,
|
|
7947
|
-
else for (let t of Object.keys(e)) c(e[t],
|
|
7962
|
+
if (Array.isArray(e)) e.forEach((e, t) => c(e, eu(l, t), String(t)));
|
|
7963
|
+
else for (let t of Object.keys(e)) c(e[t], eu(l, t), t);
|
|
7948
7964
|
return;
|
|
7949
7965
|
}
|
|
7950
|
-
let d = String(e), f =
|
|
7966
|
+
let d = String(e), f = iu(d, t, r, n.fuzzyThreshold ?? 2, s);
|
|
7951
7967
|
if (f) {
|
|
7952
7968
|
o.push({
|
|
7953
7969
|
path: l,
|
|
@@ -7958,7 +7974,7 @@ function nu(e, t, n = {}) {
|
|
|
7958
7974
|
return;
|
|
7959
7975
|
}
|
|
7960
7976
|
if (a && u) {
|
|
7961
|
-
let e =
|
|
7977
|
+
let e = iu(u, t, r, n.fuzzyThreshold ?? 2, s);
|
|
7962
7978
|
e && o.push({
|
|
7963
7979
|
path: l,
|
|
7964
7980
|
key: u,
|
|
@@ -7969,51 +7985,51 @@ function nu(e, t, n = {}) {
|
|
|
7969
7985
|
};
|
|
7970
7986
|
return c(e, ""), o;
|
|
7971
7987
|
}
|
|
7972
|
-
function
|
|
7988
|
+
function iu(e, t, n, r, i) {
|
|
7973
7989
|
let a = e.toLowerCase(), o = t.toLowerCase();
|
|
7974
7990
|
if (n === "substring") return a.includes(o) ? 1 : null;
|
|
7975
7991
|
if (n === "regex") return i && i.test(e) ? 1 : null;
|
|
7976
7992
|
if (n === "fuzzy") {
|
|
7977
7993
|
if (a.includes(o)) return 2;
|
|
7978
|
-
let e =
|
|
7994
|
+
let e = nu(a, o);
|
|
7979
7995
|
return e <= r ? r - e + 1 : null;
|
|
7980
7996
|
}
|
|
7981
7997
|
return null;
|
|
7982
7998
|
}
|
|
7983
|
-
function
|
|
7999
|
+
function au(e, t, n = 3e3) {
|
|
7984
8000
|
return ao(t, n)(e);
|
|
7985
8001
|
}
|
|
7986
8002
|
//#endregion
|
|
7987
8003
|
//#region src/core/tools/resources.ts
|
|
7988
|
-
var
|
|
7989
|
-
function cu(e) {
|
|
7990
|
-
return `${au}${e}${su}`;
|
|
7991
|
-
}
|
|
8004
|
+
var ou = "⟦frozen:", su = "⟦res:", cu = "⟧";
|
|
7992
8005
|
function lu(e) {
|
|
7993
|
-
return `${ou}${e}${
|
|
8006
|
+
return `${ou}${e}${cu}`;
|
|
7994
8007
|
}
|
|
7995
8008
|
function uu(e) {
|
|
7996
|
-
return
|
|
8009
|
+
return `${su}${e}${cu}`;
|
|
8010
|
+
}
|
|
8011
|
+
function du(e) {
|
|
8012
|
+
return typeof e == "string" ? e.startsWith(ou) && e.endsWith(cu) ? {
|
|
7997
8013
|
type: "frozen",
|
|
7998
8014
|
path: e.slice(8, e.length - 1)
|
|
7999
|
-
} : e.startsWith(
|
|
8015
|
+
} : e.startsWith(su) && e.endsWith(cu) ? {
|
|
8000
8016
|
type: "res",
|
|
8001
8017
|
handle: e.slice(5, e.length - 1)
|
|
8002
8018
|
} : null : null;
|
|
8003
8019
|
}
|
|
8004
|
-
function
|
|
8020
|
+
function fu(e) {
|
|
8005
8021
|
return String(e ?? "").trim().replace(/^\.+/, "");
|
|
8006
8022
|
}
|
|
8007
|
-
function
|
|
8023
|
+
function pu(e) {
|
|
8008
8024
|
let t = 5381;
|
|
8009
8025
|
for (let n = 0; n < e.length; n++) t = (t * 33 ^ e.charCodeAt(n)) >>> 0;
|
|
8010
8026
|
return (t >>> 0).toString(16).padStart(8, "0").slice(0, 8);
|
|
8011
8027
|
}
|
|
8012
|
-
function
|
|
8028
|
+
function mu(e, t) {
|
|
8013
8029
|
return e === t ? !0 : e && t && typeof e == "object" && typeof t == "object" ? JSON.stringify(e) === JSON.stringify(t) : !1;
|
|
8014
8030
|
}
|
|
8015
|
-
function
|
|
8016
|
-
let n =
|
|
8031
|
+
function hu(e, t) {
|
|
8032
|
+
let n = fu(e);
|
|
8017
8033
|
if (!n) return;
|
|
8018
8034
|
let r = t.get(n);
|
|
8019
8035
|
if (r) return {
|
|
@@ -8033,7 +8049,7 @@ function mu(e, t) {
|
|
|
8033
8049
|
}));
|
|
8034
8050
|
return i;
|
|
8035
8051
|
}
|
|
8036
|
-
var
|
|
8052
|
+
var gu = class {
|
|
8037
8053
|
vfs;
|
|
8038
8054
|
constructor(e) {
|
|
8039
8055
|
this.vfs = e;
|
|
@@ -8042,7 +8058,7 @@ var hu = class {
|
|
|
8042
8058
|
return `resources/${e}.json`;
|
|
8043
8059
|
}
|
|
8044
8060
|
ensure(e, t, n) {
|
|
8045
|
-
let r =
|
|
8061
|
+
let r = pu(e), i = {
|
|
8046
8062
|
path: e,
|
|
8047
8063
|
mode: n,
|
|
8048
8064
|
value: t,
|
|
@@ -8054,7 +8070,7 @@ var hu = class {
|
|
|
8054
8070
|
}, r;
|
|
8055
8071
|
}
|
|
8056
8072
|
get(e) {
|
|
8057
|
-
return this.readEntry(this.key(e)) || this.readEntry(this.key(
|
|
8073
|
+
return this.readEntry(this.key(e)) || this.readEntry(this.key(pu(e)));
|
|
8058
8074
|
}
|
|
8059
8075
|
readEntry(e) {
|
|
8060
8076
|
let t = this.vfs.files[e];
|
|
@@ -8070,7 +8086,7 @@ var hu = class {
|
|
|
8070
8086
|
this.ensure(e, t, n?.mode ?? "verbatim");
|
|
8071
8087
|
}
|
|
8072
8088
|
delete(e) {
|
|
8073
|
-
let t = this.get(e)?.handle ??
|
|
8089
|
+
let t = this.get(e)?.handle ?? pu(e), n = this.key(t), r = !!this.vfs.files[n];
|
|
8074
8090
|
return r && delete this.vfs.files[n], r;
|
|
8075
8091
|
}
|
|
8076
8092
|
list() {
|
|
@@ -8090,7 +8106,7 @@ var hu = class {
|
|
|
8090
8106
|
for (let e of Object.keys(this.vfs.files)) e.startsWith("resources/") && delete this.vfs.files[e];
|
|
8091
8107
|
}
|
|
8092
8108
|
};
|
|
8093
|
-
function
|
|
8109
|
+
function _u(e) {
|
|
8094
8110
|
let { jp: t, resolved: n, resourcesByPath: r, resourceStore: i } = e;
|
|
8095
8111
|
if (!r.size) return n;
|
|
8096
8112
|
let a = !1;
|
|
@@ -8104,14 +8120,14 @@ function gu(e) {
|
|
|
8104
8120
|
if (t !== "" && e !== t && !e.startsWith(t + ".")) continue;
|
|
8105
8121
|
if (e === t) {
|
|
8106
8122
|
if (o === void 0) continue;
|
|
8107
|
-
return n.mode === "freeze" ?
|
|
8123
|
+
return n.mode === "freeze" ? lu(e) : i ? uu(i.ensure(e, o, "verbatim")) : o;
|
|
8108
8124
|
}
|
|
8109
8125
|
let r = t === "" ? e : e.slice(t.length + 1), a = Z(o, r);
|
|
8110
|
-
a !== void 0 && (n.mode === "freeze" ? Na(o, r,
|
|
8126
|
+
a !== void 0 && (n.mode === "freeze" ? Na(o, r, lu(e)) : i && Na(o, r, uu(i.ensure(e, a, "verbatim"))));
|
|
8111
8127
|
}
|
|
8112
8128
|
return o;
|
|
8113
8129
|
}
|
|
8114
|
-
function
|
|
8130
|
+
function vu(e, t, n, r) {
|
|
8115
8131
|
if (!r) return {
|
|
8116
8132
|
code: "RESOURCE_NOT_FOUND",
|
|
8117
8133
|
message: `句柄 "${e}" 无法展开(资源池未启用)`,
|
|
@@ -8122,7 +8138,7 @@ function _u(e, t, n, r) {
|
|
|
8122
8138
|
code: "RESOURCE_NOT_FOUND",
|
|
8123
8139
|
message: `字段 "${t}" 在 bind 中已不存在,无法展开句柄 "${e}"`,
|
|
8124
8140
|
hint: "该字段可能已被删除或 restore 到不含此字段的快照;重新 read 确认当前结构"
|
|
8125
|
-
} :
|
|
8141
|
+
} : mu(i.value, n) ? { value: i.value } : (r.update(t, n), { value: n }) : n === void 0 ? {
|
|
8126
8142
|
code: "RESOURCE_NOT_FOUND",
|
|
8127
8143
|
message: `句柄 "${e}" 不存在(字段 "${t}" 可能未注册或已被删除)`,
|
|
8128
8144
|
hint: "重新 read 该字段触发懒注册"
|
|
@@ -8132,7 +8148,7 @@ function _u(e, t, n, r) {
|
|
|
8132
8148
|
hint: "重新 read 该字段触发懒注册重建句柄,再写回新句柄 ⟦res:<handle>⟧"
|
|
8133
8149
|
};
|
|
8134
8150
|
}
|
|
8135
|
-
function
|
|
8151
|
+
function yu(e, t) {
|
|
8136
8152
|
let n = t.getBind();
|
|
8137
8153
|
for (let [r, i] of t.resourcesByPath) {
|
|
8138
8154
|
let a = Z(n, r), o = Z(e, r);
|
|
@@ -8141,11 +8157,11 @@ function vu(e, t) {
|
|
|
8141
8157
|
continue;
|
|
8142
8158
|
}
|
|
8143
8159
|
if (i.mode === "freeze") {
|
|
8144
|
-
if (o ===
|
|
8160
|
+
if (o === lu(r)) {
|
|
8145
8161
|
Na(e, r, a);
|
|
8146
8162
|
continue;
|
|
8147
8163
|
}
|
|
8148
|
-
if (!
|
|
8164
|
+
if (!mu(o, a)) return {
|
|
8149
8165
|
ok: !1,
|
|
8150
8166
|
code: "FROZEN_FIELD",
|
|
8151
8167
|
path: r,
|
|
@@ -8153,9 +8169,9 @@ function vu(e, t) {
|
|
|
8153
8169
|
hint: "该字段由系统/集成方维护,LLM 不得改动。如需展示其值用 resource_get({path}) 取真值"
|
|
8154
8170
|
};
|
|
8155
8171
|
} else {
|
|
8156
|
-
let n =
|
|
8172
|
+
let n = du(o);
|
|
8157
8173
|
if (n && n.type === "res") {
|
|
8158
|
-
let i =
|
|
8174
|
+
let i = vu(n.handle, r, a, t.resourceStore);
|
|
8159
8175
|
if ("value" in i) {
|
|
8160
8176
|
Na(e, r, i.value);
|
|
8161
8177
|
continue;
|
|
@@ -8168,7 +8184,7 @@ function vu(e, t) {
|
|
|
8168
8184
|
hint: i.hint
|
|
8169
8185
|
};
|
|
8170
8186
|
}
|
|
8171
|
-
if (!
|
|
8187
|
+
if (!mu(o, a)) return {
|
|
8172
8188
|
ok: !1,
|
|
8173
8189
|
code: "VERBATIM_MISMATCH",
|
|
8174
8190
|
path: r,
|
|
@@ -8179,7 +8195,7 @@ function vu(e, t) {
|
|
|
8179
8195
|
}
|
|
8180
8196
|
return { ok: !0 };
|
|
8181
8197
|
}
|
|
8182
|
-
function
|
|
8198
|
+
function bu(e, t, n) {
|
|
8183
8199
|
let r = t === void 0 ? e.message : `patches[${t}]${n ? ` @ "${n}"` : ""}: ${e.message}`;
|
|
8184
8200
|
return Y({
|
|
8185
8201
|
code: e.code,
|
|
@@ -8192,28 +8208,28 @@ function yu(e, t, n) {
|
|
|
8192
8208
|
} }
|
|
8193
8209
|
});
|
|
8194
8210
|
}
|
|
8195
|
-
function
|
|
8211
|
+
function xu(e) {
|
|
8196
8212
|
let { value: t, ctx: n } = e;
|
|
8197
8213
|
if (!n || !n.resourcesByPath.size) return {
|
|
8198
8214
|
ok: !0,
|
|
8199
8215
|
value: t
|
|
8200
8216
|
};
|
|
8201
|
-
let r = Fa(t), i =
|
|
8217
|
+
let r = Fa(t), i = yu(r, n);
|
|
8202
8218
|
return i.ok ? {
|
|
8203
8219
|
ok: !0,
|
|
8204
8220
|
value: r
|
|
8205
8221
|
} : {
|
|
8206
8222
|
ok: !1,
|
|
8207
|
-
error:
|
|
8223
|
+
error: bu(i)
|
|
8208
8224
|
};
|
|
8209
8225
|
}
|
|
8210
|
-
function
|
|
8226
|
+
function Su(e) {
|
|
8211
8227
|
let { patches: t, clone: n, ctx: r } = e;
|
|
8212
8228
|
if (!r || !r.resourcesByPath.size) return { ok: !0 };
|
|
8213
8229
|
for (let e = 0; e < t.length; e++) {
|
|
8214
8230
|
let n = t[e];
|
|
8215
8231
|
if (n.op === "remove") {
|
|
8216
|
-
let t =
|
|
8232
|
+
let t = hu(n.jsonPath || "", r.resourcesByPath);
|
|
8217
8233
|
if (t) {
|
|
8218
8234
|
let r = t.spec.mode === "freeze" ? "FROZEN_FIELD" : "VERBATIM_PROTECTED", i = t.spec.mode === "freeze" ? "冻结字段不可删。如需移除请联系集成方调整 data.resources 配置" : "verbatim 字段不可直接删;先 resource_delete({path}) 释放资源保护后再删";
|
|
8219
8235
|
return {
|
|
@@ -8232,27 +8248,27 @@ function xu(e) {
|
|
|
8232
8248
|
}
|
|
8233
8249
|
}
|
|
8234
8250
|
}
|
|
8235
|
-
let i =
|
|
8251
|
+
let i = yu(n, r);
|
|
8236
8252
|
if (!i.ok) {
|
|
8237
|
-
let e =
|
|
8253
|
+
let e = Cu(i.path, t);
|
|
8238
8254
|
return {
|
|
8239
8255
|
ok: !1,
|
|
8240
|
-
error:
|
|
8256
|
+
error: bu(i, e >= 0 ? e : void 0, e >= 0 ? t[e].jsonPath : void 0)
|
|
8241
8257
|
};
|
|
8242
8258
|
}
|
|
8243
8259
|
return { ok: !0 };
|
|
8244
8260
|
}
|
|
8245
|
-
function
|
|
8246
|
-
let n =
|
|
8261
|
+
function Cu(e, t) {
|
|
8262
|
+
let n = fu(e);
|
|
8247
8263
|
for (let e = 0; e < t.length; e++) {
|
|
8248
|
-
let r =
|
|
8264
|
+
let r = fu(t[e].jsonPath || "");
|
|
8249
8265
|
if (r && (r === n || n.startsWith(r + ".") || r.startsWith(n + "."))) return e;
|
|
8250
8266
|
}
|
|
8251
8267
|
return -1;
|
|
8252
8268
|
}
|
|
8253
8269
|
//#endregion
|
|
8254
8270
|
//#region src/core/tools/dataOps.ts
|
|
8255
|
-
var
|
|
8271
|
+
var wu = /* @__PURE__ */ new Set([
|
|
8256
8272
|
"describe_data",
|
|
8257
8273
|
"get_data",
|
|
8258
8274
|
"set_data",
|
|
@@ -8266,14 +8282,14 @@ var Cu = /* @__PURE__ */ new Set([
|
|
|
8266
8282
|
"resource_update",
|
|
8267
8283
|
"resource_list",
|
|
8268
8284
|
"resource_delete"
|
|
8269
|
-
]),
|
|
8270
|
-
function
|
|
8271
|
-
return t === "advanced" ? e : t === "minimal" ? e.filter((e) =>
|
|
8285
|
+
]), Tu = /* @__PURE__ */ new Set(["read", "write"]);
|
|
8286
|
+
function Eu(e, t = "simple") {
|
|
8287
|
+
return t === "advanced" ? e : t === "minimal" ? e.filter((e) => Tu.has(e.name)) : e.filter((e) => !wu.has(e.name));
|
|
8272
8288
|
}
|
|
8273
|
-
function
|
|
8289
|
+
function Du(e) {
|
|
8274
8290
|
let { bindRef: t, schema: n, allowKeys: r, snapshots: i, maxSnapshots: a, audit: o, dryRun: s, op: c = "set", protectedCtx: l } = e, u = e.value, d = e.internalAfterWrite ? Fa(t) : null;
|
|
8275
8291
|
if (l) {
|
|
8276
|
-
let e =
|
|
8292
|
+
let e = xu({
|
|
8277
8293
|
value: u,
|
|
8278
8294
|
ctx: l
|
|
8279
8295
|
});
|
|
@@ -8329,7 +8345,7 @@ function Eu(e) {
|
|
|
8329
8345
|
data: f.data
|
|
8330
8346
|
};
|
|
8331
8347
|
}
|
|
8332
|
-
function
|
|
8348
|
+
function Ou(e) {
|
|
8333
8349
|
let { bindRef: t, patches: n, schema: r, allowKeys: i, snapshots: a, maxSnapshots: o, markDataDirty: s, schemaErrorMode: c = "zod", snapshotLabel: l, dryRun: u, protectedCtx: d } = e, f = e.internalAfterWrite ? Fa(t) : null, p = Fa(t), m = [];
|
|
8334
8350
|
for (let e = 0; e < n.length; e++) {
|
|
8335
8351
|
let t = n[e], a = t.jsonPath || "";
|
|
@@ -8389,7 +8405,7 @@ function Du(e) {
|
|
|
8389
8405
|
});
|
|
8390
8406
|
}
|
|
8391
8407
|
if (d) {
|
|
8392
|
-
let e =
|
|
8408
|
+
let e = Su({
|
|
8393
8409
|
patches: n,
|
|
8394
8410
|
clone: p,
|
|
8395
8411
|
ctx: d
|
|
@@ -8440,37 +8456,37 @@ function Du(e) {
|
|
|
8440
8456
|
clone: p
|
|
8441
8457
|
};
|
|
8442
8458
|
}
|
|
8443
|
-
function
|
|
8459
|
+
function ku(e) {
|
|
8444
8460
|
return e < 1024 ? `${e}B` : e < 1024 * 1024 ? `${(e / 1024).toFixed(1)}KB` : `${(e / (1024 * 1024)).toFixed(1)}MB`;
|
|
8445
8461
|
}
|
|
8446
|
-
function
|
|
8462
|
+
function Au(e, t, n, r) {
|
|
8447
8463
|
if (!t || !n.length || typeof e != "object" || !e) return e;
|
|
8448
8464
|
let i = new Set(n.map((e) => e.field)), a = Fa(e);
|
|
8449
8465
|
return (function e(t) {
|
|
8450
8466
|
if (Array.isArray(t)) for (let n of t) e(n);
|
|
8451
8467
|
else if (t && typeof t == "object") for (let n of Object.keys(t)) {
|
|
8452
8468
|
let a = t[n];
|
|
8453
|
-
typeof a == "string" && i.has(n) && a.length >= r ? t[n] = `<${n} ${
|
|
8469
|
+
typeof a == "string" && i.has(n) && a.length >= r ? t[n] = `<${n} ${ku(a.length)}>` : e(a);
|
|
8454
8470
|
}
|
|
8455
8471
|
})(a), a;
|
|
8456
8472
|
}
|
|
8457
|
-
var
|
|
8458
|
-
function
|
|
8459
|
-
return
|
|
8473
|
+
var ju = 0;
|
|
8474
|
+
function Mu() {
|
|
8475
|
+
return ju++, "c_" + Math.random().toString(36).slice(2, 8) + ju.toString(36);
|
|
8460
8476
|
}
|
|
8461
|
-
function
|
|
8477
|
+
function Nu(e, t) {
|
|
8462
8478
|
if (!(!e || typeof e != "object")) for (let n of t) {
|
|
8463
8479
|
let t = Z(e, n);
|
|
8464
|
-
if (Array.isArray(t)) for (let e of t) e && typeof e == "object" && !("__pgId" in e) && (e.__pgId =
|
|
8480
|
+
if (Array.isArray(t)) for (let e of t) e && typeof e == "object" && !("__pgId" in e) && (e.__pgId = Mu());
|
|
8465
8481
|
}
|
|
8466
8482
|
}
|
|
8467
|
-
function
|
|
8483
|
+
function Pu(e) {
|
|
8468
8484
|
(function e(t) {
|
|
8469
8485
|
if (Array.isArray(t)) t.forEach(e);
|
|
8470
8486
|
else if (t && typeof t == "object") for (let n of Object.keys(t)) n.startsWith("__pg") ? delete t[n] : e(t[n]);
|
|
8471
8487
|
})(e);
|
|
8472
8488
|
}
|
|
8473
|
-
function
|
|
8489
|
+
function Fu(e, n = {}) {
|
|
8474
8490
|
let i = n.pgIdPaths ?? [], a = i.length ? (e, t) => {
|
|
8475
8491
|
if (t && typeof t == "object") for (let n of i) {
|
|
8476
8492
|
let r = Z(t, n), i = Z(e, n);
|
|
@@ -8485,7 +8501,7 @@ function Pu(e, n = {}) {
|
|
|
8485
8501
|
if (!(!t || typeof t != "object" || "__pgId" in t)) for (let e = 0; e < r.length; e++) {
|
|
8486
8502
|
if (o.has(e)) continue;
|
|
8487
8503
|
let n = r[e];
|
|
8488
|
-
if (!(!n || typeof n != "object" || !n.__pgId) &&
|
|
8504
|
+
if (!(!n || typeof n != "object" || !n.__pgId) && mu(a(n), a(t))) {
|
|
8489
8505
|
t.__pgId = n.__pgId, o.add(e);
|
|
8490
8506
|
break;
|
|
8491
8507
|
}
|
|
@@ -8497,11 +8513,11 @@ function Pu(e, n = {}) {
|
|
|
8497
8513
|
t && n && typeof n == "object" && !("__pgId" in n) && (n.__pgId = t, o.add(e));
|
|
8498
8514
|
}
|
|
8499
8515
|
}
|
|
8500
|
-
|
|
8501
|
-
} : void 0, o = i.length ? fa(e.schema, i).schema : e.schema, s = e.bind, c = e.description ?? "主数据对象", l = Gi(o), u = /* @__PURE__ */ new Map(), d = n.vfsStore ? new
|
|
8516
|
+
Nu(e, i);
|
|
8517
|
+
} : void 0, o = i.length ? fa(e.schema, i).schema : e.schema, s = e.bind, c = e.description ?? "主数据对象", l = Gi(o), u = /* @__PURE__ */ new Map(), d = n.vfsStore ? new gu(n.vfsStore) : void 0;
|
|
8502
8518
|
function f(e) {
|
|
8503
8519
|
if (u.clear(), e) for (let t of e) {
|
|
8504
|
-
let e =
|
|
8520
|
+
let e = fu(t.path);
|
|
8505
8521
|
u.set(e, {
|
|
8506
8522
|
path: e,
|
|
8507
8523
|
mode: t.mode
|
|
@@ -8574,7 +8590,7 @@ function Pu(e, n = {}) {
|
|
|
8574
8590
|
return e;
|
|
8575
8591
|
},
|
|
8576
8592
|
createResource: d ? (e, t) => {
|
|
8577
|
-
let n =
|
|
8593
|
+
let n = fu(e), r = u.get(n), i = t === void 0 ? Z(s, n) : t;
|
|
8578
8594
|
return d.ensure(n, i, r?.mode ?? "verbatim");
|
|
8579
8595
|
} : void 0,
|
|
8580
8596
|
getResource: d ? (e) => {
|
|
@@ -8587,7 +8603,7 @@ function Pu(e, n = {}) {
|
|
|
8587
8603
|
} : void 0;
|
|
8588
8604
|
} : void 0,
|
|
8589
8605
|
updateResource: d ? (e, t) => {
|
|
8590
|
-
let n =
|
|
8606
|
+
let n = fu(e);
|
|
8591
8607
|
d.update(n, t), Na(s, n, t), T();
|
|
8592
8608
|
} : void 0,
|
|
8593
8609
|
deleteResource: d ? (e) => d.delete(e) : void 0,
|
|
@@ -8650,14 +8666,14 @@ function Pu(e, n = {}) {
|
|
|
8650
8666
|
hint: "主数据仅暴露 schema 声明的字段;若需操作该字段,集成方需在 schema 中声明它"
|
|
8651
8667
|
});
|
|
8652
8668
|
let i = r ? Z(s, r) : s;
|
|
8653
|
-
!r && l && (i = ea(i, o)), p && (i =
|
|
8669
|
+
!r && l && (i = ea(i, o)), p && (i = _u({
|
|
8654
8670
|
jp: r,
|
|
8655
8671
|
resolved: i,
|
|
8656
8672
|
resourcesByPath: p.resourcesByPath,
|
|
8657
8673
|
resourceStore: p.resourceStore
|
|
8658
8674
|
}));
|
|
8659
8675
|
let a = $(s);
|
|
8660
|
-
return b(a, n), i === void 0 ? `主数据${r ? ` @ ${r}` : ""} = (undefined) (hash=${a})` : (i =
|
|
8676
|
+
return b(a, n), i === void 0 ? `主数据${r ? ` @ ${r}` : ""} = (undefined) (hash=${a})` : (i = Au(i, n === "", C, S), `主数据${r ? ` @ ${r}` : ""} = ${Q(i)} (hash=${a})`);
|
|
8661
8677
|
}, {
|
|
8662
8678
|
name: "get_data",
|
|
8663
8679
|
description: "@deprecated(改用 read,等价且支持 fields/depth/分页)。读取主数据当前值(返回含 hash 供乐观锁);jsonPath 可选读子路径。大结果自动外存 vfs。",
|
|
@@ -8667,7 +8683,7 @@ function Pu(e, n = {}) {
|
|
|
8667
8683
|
if (i !== null) return i;
|
|
8668
8684
|
let c = Ia(e);
|
|
8669
8685
|
if (c.parseError) return Yr("", e, c.parseError);
|
|
8670
|
-
let u =
|
|
8686
|
+
let u = Du({
|
|
8671
8687
|
bindRef: s,
|
|
8672
8688
|
value: c.parsed,
|
|
8673
8689
|
schema: o,
|
|
@@ -8714,7 +8730,7 @@ function Pu(e, n = {}) {
|
|
|
8714
8730
|
message: `edit 仅适用于对象/数组主数据,当前是 ${s === void 0 ? "undefined" : typeof s}`,
|
|
8715
8731
|
hint: "叶子(原始类型)请用 set_data 整体设置"
|
|
8716
8732
|
});
|
|
8717
|
-
let g =
|
|
8733
|
+
let g = Ou({
|
|
8718
8734
|
bindRef: s,
|
|
8719
8735
|
patches: [{
|
|
8720
8736
|
op: r,
|
|
@@ -8783,7 +8799,7 @@ function Pu(e, n = {}) {
|
|
|
8783
8799
|
hint: "仅 schema 声明的 key 可删"
|
|
8784
8800
|
});
|
|
8785
8801
|
if (p) {
|
|
8786
|
-
let t =
|
|
8802
|
+
let t = hu(e, p.resourcesByPath);
|
|
8787
8803
|
if (t) return Y({
|
|
8788
8804
|
code: t.spec.mode === "freeze" ? "FROZEN_FIELD" : "VERBATIM_PROTECTED",
|
|
8789
8805
|
message: `delete_data @ "${e}" 命中受保护字段 "${t.protectedPath}"(${t.spec.mode}),不可删除`,
|
|
@@ -8892,7 +8908,7 @@ function Pu(e, n = {}) {
|
|
|
8892
8908
|
});
|
|
8893
8909
|
let i = l ? ea(s, o) : s, a;
|
|
8894
8910
|
try {
|
|
8895
|
-
a =
|
|
8911
|
+
a = tu(i, e);
|
|
8896
8912
|
} catch (t) {
|
|
8897
8913
|
return Y({
|
|
8898
8914
|
code: "JSONPATH_SYNTAX",
|
|
@@ -8901,7 +8917,7 @@ function Pu(e, n = {}) {
|
|
|
8901
8917
|
details: { expr: e }
|
|
8902
8918
|
});
|
|
8903
8919
|
}
|
|
8904
|
-
let c = t ?? 50, u = a.slice(0, c), d = u.map((e) => `{"path":${JSON.stringify(e.path)},"index":${e.index === void 0 ? "null" : e.index},"value":${Q(
|
|
8920
|
+
let c = t ?? 50, u = a.slice(0, c), d = u.map((e) => `{"path":${JSON.stringify(e.path)},"index":${e.index === void 0 ? "null" : e.index},"value":${Q(Au(e.value, r === "", C, S))}}`);
|
|
8905
8921
|
return `{"matched":${a.length},"returned":${u.length},"truncated":${a.length > c},"results":[${d.join(",")}]}`;
|
|
8906
8922
|
}, {
|
|
8907
8923
|
name: "query_data",
|
|
@@ -8916,7 +8932,7 @@ function Pu(e, n = {}) {
|
|
|
8916
8932
|
message: "主数据为空,无可搜索内容"
|
|
8917
8933
|
});
|
|
8918
8934
|
try {
|
|
8919
|
-
let a =
|
|
8935
|
+
let a = ru(l ? ea(s, o) : s, e, {
|
|
8920
8936
|
mode: t,
|
|
8921
8937
|
fuzzyThreshold: n,
|
|
8922
8938
|
matchKey: r,
|
|
@@ -8967,7 +8983,7 @@ function Pu(e, n = {}) {
|
|
|
8967
8983
|
e && (u = ea(u, e));
|
|
8968
8984
|
}
|
|
8969
8985
|
} else u = l ? ea(s, o) : s;
|
|
8970
|
-
let d = Fa(u), f = await
|
|
8986
|
+
let d = Fa(u), f = await au(d, e, c && JSON.stringify(d).length > 1e5 ? 8e3 : 3e3);
|
|
8971
8987
|
if (!f.ok) {
|
|
8972
8988
|
let t = /超时/.test(f.error || "");
|
|
8973
8989
|
return Y({
|
|
@@ -8983,7 +8999,7 @@ function Pu(e, n = {}) {
|
|
|
8983
8999
|
if (t === "transform") {
|
|
8984
9000
|
let e = f.result;
|
|
8985
9001
|
if (c) {
|
|
8986
|
-
let t =
|
|
9002
|
+
let t = Ou({
|
|
8987
9003
|
bindRef: s,
|
|
8988
9004
|
patches: [{
|
|
8989
9005
|
op: "set",
|
|
@@ -9012,7 +9028,7 @@ function Pu(e, n = {}) {
|
|
|
9012
9028
|
message: `主数据 bind 为原始类型(${s === null ? "null" : typeof s}),eval transform(patches) 无法就地替换`,
|
|
9013
9029
|
hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹或集成方通过 sdk.setData 替换 bind"
|
|
9014
9030
|
});
|
|
9015
|
-
let t =
|
|
9031
|
+
let t = Ou({
|
|
9016
9032
|
bindRef: s,
|
|
9017
9033
|
patches: e.patches,
|
|
9018
9034
|
schema: o,
|
|
@@ -9033,7 +9049,7 @@ function Pu(e, n = {}) {
|
|
|
9033
9049
|
}
|
|
9034
9050
|
let t = e;
|
|
9035
9051
|
if (p) {
|
|
9036
|
-
let e =
|
|
9052
|
+
let e = xu({
|
|
9037
9053
|
value: t,
|
|
9038
9054
|
ctx: p
|
|
9039
9055
|
});
|
|
@@ -9085,7 +9101,7 @@ function Pu(e, n = {}) {
|
|
|
9085
9101
|
e && (c = ea(c, e));
|
|
9086
9102
|
}
|
|
9087
9103
|
let u = c;
|
|
9088
|
-
if (p && (u =
|
|
9104
|
+
if (p && (u = _u({
|
|
9089
9105
|
jp: a,
|
|
9090
9106
|
resolved: u,
|
|
9091
9107
|
resourcesByPath: p.resourcesByPath,
|
|
@@ -9095,7 +9111,7 @@ function Pu(e, n = {}) {
|
|
|
9095
9111
|
} catch (e) {
|
|
9096
9112
|
return `- ${a}: [READ_INTERCEPT: ${e.message}]`;
|
|
9097
9113
|
}
|
|
9098
|
-
return r && r.length && (u = La(u, r)), i != null && (u = Ra(u, i)), u =
|
|
9114
|
+
return r && r.length && (u = La(u, r)), i != null && (u = Ra(u, i)), u = Au(u, f === "", C, S), u === void 0 ? `- ${a} = (undefined)` : `- ${a} = ${Q(u)}`;
|
|
9099
9115
|
});
|
|
9100
9116
|
return e && b(m, f), `多路径读取(共 ${t.length} 项,hash=${m}):\n${a.join("\n")}`;
|
|
9101
9117
|
}
|
|
@@ -9117,7 +9133,7 @@ function Pu(e, n = {}) {
|
|
|
9117
9133
|
e && (g = ea(g, e));
|
|
9118
9134
|
}
|
|
9119
9135
|
let _ = g;
|
|
9120
|
-
if (p && (_ =
|
|
9136
|
+
if (p && (_ = _u({
|
|
9121
9137
|
jp: h,
|
|
9122
9138
|
resolved: _,
|
|
9123
9139
|
resourcesByPath: p.resourcesByPath,
|
|
@@ -9130,7 +9146,7 @@ function Pu(e, n = {}) {
|
|
|
9130
9146
|
message: `read 拦截器抛错: ${e.message}`
|
|
9131
9147
|
});
|
|
9132
9148
|
}
|
|
9133
|
-
b(m, f), r && r.length && (_ = La(_, r)), i != null && (_ = Ra(_, i)), _ =
|
|
9149
|
+
b(m, f), r && r.length && (_ = La(_, r)), i != null && (_ = Ra(_, i)), _ = Au(_, f === "", C, S);
|
|
9134
9150
|
let y = e ? "" : `主数据说明: ${c}\n格式: 写入值需为 JSON,且通过声明的 schema 校验(校验失败时 write 会返回结构化错误)。字段约束(类型/min/max/enum/必填/默认)见 systemPrompt「可操作数据」段,或用 schema_data({ jsonPath }) 按需查。\n\n`, x = r && r.length ? `(字段裁剪:${r.join(",")})` : "", w = i == null ? "" : `(深度≤${i})`, T = x || w ? ` ${x}${w}` : "";
|
|
9135
9151
|
if ((a !== void 0 || u !== void 0) && Array.isArray(_)) {
|
|
9136
9152
|
let e = _.length, t = Math.max(0, a ?? 0), n = Math.min(200, Math.max(1, u ?? 50)), r = _.slice(t, t + n), i = t + n < e;
|
|
@@ -9203,7 +9219,7 @@ function Pu(e, n = {}) {
|
|
|
9203
9219
|
hint: "仅 schema 声明的 key 可删"
|
|
9204
9220
|
});
|
|
9205
9221
|
if (p) {
|
|
9206
|
-
let e =
|
|
9222
|
+
let e = hu(t.jsonPath, p.resourcesByPath);
|
|
9207
9223
|
if (e) return Y({
|
|
9208
9224
|
code: e.spec.mode === "freeze" ? "FROZEN_FIELD" : "VERBATIM_PROTECTED",
|
|
9209
9225
|
message: `write delete @ "${t.jsonPath}" 命中受保护字段 "${e.protectedPath}"(${e.spec.mode}),不可删除`,
|
|
@@ -9236,7 +9252,7 @@ function Pu(e, n = {}) {
|
|
|
9236
9252
|
op: t.op ?? "set",
|
|
9237
9253
|
jsonPath: t.jsonPath || "",
|
|
9238
9254
|
value: g
|
|
9239
|
-
}]), i =
|
|
9255
|
+
}]), i = Ou({
|
|
9240
9256
|
bindRef: s,
|
|
9241
9257
|
patches: n,
|
|
9242
9258
|
schema: o,
|
|
@@ -9254,13 +9270,13 @@ function Pu(e, n = {}) {
|
|
|
9254
9270
|
detail: `${i.applied.length} 个 patch${i.applied.length > 1 ? "(批量)" : ""}`,
|
|
9255
9271
|
value: i.applied.map((e) => `${e.op}@${e.jp}`),
|
|
9256
9272
|
timestamp: Date.now()
|
|
9257
|
-
}), b($(s), d),
|
|
9273
|
+
}), b($(s), d), Pu(i.clone), `已 write(edit) 主数据(${i.applied.length} 个 patch)。当前值:${Q(i.clone, 600)} (新 hash=${$(s)})`) : i.error;
|
|
9258
9274
|
}
|
|
9259
9275
|
let C = Ia(g);
|
|
9260
9276
|
if (C.parseError) return Yr("", g, C.parseError);
|
|
9261
9277
|
let w = await k("set", S);
|
|
9262
9278
|
if (w !== null) return w;
|
|
9263
|
-
let E =
|
|
9279
|
+
let E = Du({
|
|
9264
9280
|
bindRef: s,
|
|
9265
9281
|
value: C.parsed,
|
|
9266
9282
|
schema: o,
|
|
@@ -9276,7 +9292,7 @@ function Pu(e, n = {}) {
|
|
|
9276
9292
|
if (!E.ok) return E.error;
|
|
9277
9293
|
if (c) return `dryRun(set): schema 校验通过。预览新值:${Q(E.data, 600)}。未实际写入、未入快照。`;
|
|
9278
9294
|
let A = $(s);
|
|
9279
|
-
return b(A, d),
|
|
9295
|
+
return b(A, d), Pu(E.data), `已 write(set) 主数据 = ${Q(E.data, 600)} (新 hash=${A})${l ? "(白名单模式:仅更新 schema 声明字段,未声明字段保留)" : ""}`;
|
|
9280
9296
|
}, {
|
|
9281
9297
|
name: "write",
|
|
9282
9298
|
description: "写入主数据(高层入口,合并 set/edit/delete + 自动乐观锁 + 自动快照)。四意图:① 整体替换 write({value:整个对象});② 增量 write({patch:{op,jsonPath,value}}) op=set/remove/merge/append/move(move 的 value=目标路径字符串);③ 批量原子 write({patches:[...]})(任一失败整批回滚);④ 删子路径 write({patch:{jsonPath},del:true})。dryRun:true 预检不落盘。写入自动 schema 校验(失败不写,按错误修正重试)+ 自动快照。详细用法见系统提示「能力使用提示」。",
|
|
@@ -9395,7 +9411,7 @@ function Pu(e, n = {}) {
|
|
|
9395
9411
|
}
|
|
9396
9412
|
let g = await k("set", n || (x ? y(c) : void 0));
|
|
9397
9413
|
if (g !== null) return g;
|
|
9398
|
-
let _ =
|
|
9414
|
+
let _ = Du({
|
|
9399
9415
|
bindRef: s,
|
|
9400
9416
|
value: f,
|
|
9401
9417
|
schema: o,
|
|
@@ -9428,7 +9444,7 @@ function Pu(e, n = {}) {
|
|
|
9428
9444
|
message: "未提供 path 或有效 handle",
|
|
9429
9445
|
hint: "传 path(受保护字段)或 handle(占位符 ⟦res:handle⟧ 里的句柄)"
|
|
9430
9446
|
});
|
|
9431
|
-
let r =
|
|
9447
|
+
let r = fu(n);
|
|
9432
9448
|
if (!u.has(r)) return Y({
|
|
9433
9449
|
code: "RESOURCE_NOT_FOUND",
|
|
9434
9450
|
message: `"${n}" 不是受保护字段`,
|
|
@@ -9468,7 +9484,7 @@ function Pu(e, n = {}) {
|
|
|
9468
9484
|
message: "resource_update 需要 path",
|
|
9469
9485
|
hint: "传要更新的 verbatim 受保护字段路径"
|
|
9470
9486
|
});
|
|
9471
|
-
let i =
|
|
9487
|
+
let i = fu(e), a = u.get(i);
|
|
9472
9488
|
if (!a) return Y({
|
|
9473
9489
|
code: "RESOURCE_NOT_FOUND",
|
|
9474
9490
|
message: `"${e}" 不是受保护字段`,
|
|
@@ -9558,8 +9574,8 @@ function Pu(e, n = {}) {
|
|
|
9558
9574
|
}
|
|
9559
9575
|
//#endregion
|
|
9560
9576
|
//#region src/core/tools/fetchDoc.ts
|
|
9561
|
-
var
|
|
9562
|
-
let n = new AbortController(), r = setTimeout(() => n.abort(),
|
|
9577
|
+
var Iu = 3e4, Lu = [r(async ({ url: e, as: t }) => {
|
|
9578
|
+
let n = new AbortController(), r = setTimeout(() => n.abort(), Iu);
|
|
9563
9579
|
try {
|
|
9564
9580
|
let r = await fetch(e, {
|
|
9565
9581
|
method: "GET",
|
|
@@ -9576,7 +9592,7 @@ var Fu = 3e4, Iu = [r(async ({ url: e, as: t }) => {
|
|
|
9576
9592
|
].join("\n");
|
|
9577
9593
|
} catch (t) {
|
|
9578
9594
|
let r = t?.message || String(t);
|
|
9579
|
-
return n.signal.aborted ? `获取失败:请求超时(${
|
|
9595
|
+
return n.signal.aborted ? `获取失败:请求超时(${Iu}ms,${e})。` : /Failed to fetch|NetworkError|CORS|blocked/i.test(r) ? `获取失败:可能是 CORS 跨域拦截或网络错误(${r})。浏览器仅能 GET 同源或服务端已配置 CORS 的资源;跨域抓取需后端代理。` : `获取失败:${r}`;
|
|
9580
9596
|
} finally {
|
|
9581
9597
|
clearTimeout(r);
|
|
9582
9598
|
}
|
|
@@ -9587,7 +9603,7 @@ var Fu = 3e4, Iu = [r(async ({ url: e, as: t }) => {
|
|
|
9587
9603
|
url: t.string().describe("要抓取的 URL(同源或已配 CORS)"),
|
|
9588
9604
|
as: t.enum(["text", "markdown"]).optional().describe("返回格式标签,默认 text")
|
|
9589
9605
|
})
|
|
9590
|
-
})],
|
|
9606
|
+
})], Ru = [
|
|
9591
9607
|
"id",
|
|
9592
9608
|
"class",
|
|
9593
9609
|
"href",
|
|
@@ -9599,12 +9615,12 @@ var Fu = 3e4, Iu = [r(async ({ url: e, as: t }) => {
|
|
|
9599
9615
|
"aria-label",
|
|
9600
9616
|
"name",
|
|
9601
9617
|
"type"
|
|
9602
|
-
],
|
|
9603
|
-
function
|
|
9618
|
+
], zu = /^(value|srcdoc|formaction|on\w+)$/i, Bu = /token|secret|password|passwd|api[-_]?key|auth|cred|csrf|session/i;
|
|
9619
|
+
function Vu(e, t) {
|
|
9604
9620
|
if (!e) return null;
|
|
9605
|
-
let { depth: n, attrs: r, includeText: i = !0 } = t, a = r !== void 0, o = r ??
|
|
9621
|
+
let { depth: n, attrs: r, includeText: i = !0 } = t, a = r !== void 0, o = r ?? Ru, s = (e) => {
|
|
9606
9622
|
let t = {};
|
|
9607
|
-
for (let n of Array.from(e.attributes)) (a ? o.includes(n.name) : o.includes(n.name) || n.name.startsWith("data-")) && (
|
|
9623
|
+
for (let n of Array.from(e.attributes)) (a ? o.includes(n.name) : o.includes(n.name) || n.name.startsWith("data-")) && (zu.test(n.name) || Bu.test(n.name) || (t[n.name] = n.value));
|
|
9608
9624
|
return t;
|
|
9609
9625
|
}, c = (e, t) => {
|
|
9610
9626
|
let n = {
|
|
@@ -9620,10 +9636,10 @@ function Bu(e, t) {
|
|
|
9620
9636
|
};
|
|
9621
9637
|
return c(e, n);
|
|
9622
9638
|
}
|
|
9623
|
-
var
|
|
9639
|
+
var Hu = r(({ selector: e, depth: t, attrs: n, includeText: r }) => {
|
|
9624
9640
|
let i = e ? document.querySelector(e) : document.body;
|
|
9625
9641
|
if (!i) return `未找到匹配元素:selector="${e}"`;
|
|
9626
|
-
let a =
|
|
9642
|
+
let a = Vu(i, {
|
|
9627
9643
|
depth: t ?? 3,
|
|
9628
9644
|
attrs: n,
|
|
9629
9645
|
includeText: r ?? !0
|
|
@@ -9638,14 +9654,14 @@ var Vu = r(({ selector: e, depth: t, attrs: n, includeText: r }) => {
|
|
|
9638
9654
|
attrs: t.array(t.string()).optional().describe("属性白名单(传了 = 严格白名单;不传 = 默认常用 + data-*)"),
|
|
9639
9655
|
includeText: t.boolean().optional().describe("是否包含直接文本(默认 true)")
|
|
9640
9656
|
})
|
|
9641
|
-
}),
|
|
9657
|
+
}), Uu = [Hu];
|
|
9642
9658
|
//#endregion
|
|
9643
9659
|
//#region src/core/tools/envTool.ts
|
|
9644
|
-
function
|
|
9660
|
+
function Wu(e) {
|
|
9645
9661
|
let t = e;
|
|
9646
9662
|
return typeof t.tagName == "string" || typeof t.nodeType == "number" && typeof t.nodeName == "string";
|
|
9647
9663
|
}
|
|
9648
|
-
function
|
|
9664
|
+
function Gu(e, t = 3, n = 2e3, r, i) {
|
|
9649
9665
|
if (e == null) return e;
|
|
9650
9666
|
if (typeof e == "string") return e.length > n ? e.slice(0, n) + "…(已截断)" : e;
|
|
9651
9667
|
if (typeof e == "number" || typeof e == "boolean") return e;
|
|
@@ -9654,14 +9670,14 @@ function Wu(e, t = 3, n = 2e3, r, i) {
|
|
|
9654
9670
|
if (typeof e == "bigint") return `${e.toString()}n`;
|
|
9655
9671
|
if (typeof e != "object") return String(e);
|
|
9656
9672
|
let a = e;
|
|
9657
|
-
if (
|
|
9673
|
+
if (Wu(a)) {
|
|
9658
9674
|
let e = a;
|
|
9659
9675
|
return e.tagName ? `[Element: <${e.tagName.toLowerCase()}>]` : `[Node: ${e.nodeName}]`;
|
|
9660
9676
|
}
|
|
9661
9677
|
if (r?.has(a)) return "[Circular]";
|
|
9662
9678
|
let o = r ?? /* @__PURE__ */ new WeakSet();
|
|
9663
9679
|
if (o.add(a), Array.isArray(e)) {
|
|
9664
|
-
let r = e.slice(0, 100).map((e) =>
|
|
9680
|
+
let r = e.slice(0, 100).map((e) => Gu(e, t - 1, n, o, i));
|
|
9665
9681
|
return e.length > 100 && r.push(`…(共 ${e.length} 项,已截断)`), r;
|
|
9666
9682
|
}
|
|
9667
9683
|
if (t < 0) return "(对象,已截断)";
|
|
@@ -9674,14 +9690,14 @@ function Wu(e, t = 3, n = 2e3, r, i) {
|
|
|
9674
9690
|
}
|
|
9675
9691
|
try {
|
|
9676
9692
|
let e = a[r];
|
|
9677
|
-
i?.test(r) ? s[r] = "[REDACTED]" : s[r] =
|
|
9693
|
+
i?.test(r) ? s[r] = "[REDACTED]" : s[r] = Gu(e, t - 1, n, o, i);
|
|
9678
9694
|
} catch {
|
|
9679
9695
|
s[r] = "(getter 抛错)";
|
|
9680
9696
|
}
|
|
9681
9697
|
}
|
|
9682
9698
|
return s;
|
|
9683
9699
|
}
|
|
9684
|
-
function
|
|
9700
|
+
function Ku(e) {
|
|
9685
9701
|
let t = e ?? (typeof window < "u" ? window : {}), n = t.navigator, r = t.location, i = t.document;
|
|
9686
9702
|
return {
|
|
9687
9703
|
location: {
|
|
@@ -9714,9 +9730,9 @@ function Gu(e) {
|
|
|
9714
9730
|
} : "(无 document)"
|
|
9715
9731
|
};
|
|
9716
9732
|
}
|
|
9717
|
-
var
|
|
9733
|
+
var qu = /^(localStorage|sessionStorage|cookie|document|frames|frameElement|opener|parent|top|self|window|globalThis|closed|history|navigation|trustedTypes|origin|crossOriginIsolated)$/, Ju = /token|secret|password|passwd|api[-_]?key|auth|cred|csrf|session|ticket/i, Yu = r(({ key: e }) => {
|
|
9718
9734
|
if (e) {
|
|
9719
|
-
if (
|
|
9735
|
+
if (qu.test(e) || Ju.test(e)) return JSON.stringify({
|
|
9720
9736
|
key: e,
|
|
9721
9737
|
denied: !0,
|
|
9722
9738
|
reason: "安全:该 key 在 denylist(localStorage/sessionStorage/cookie/document 或敏感命名 token/secret/key/auth),不读取防泄漏"
|
|
@@ -9726,18 +9742,18 @@ var Ku = /^(localStorage|sessionStorage|cookie|document|frames|frameElement|open
|
|
|
9726
9742
|
key: e,
|
|
9727
9743
|
exists: t !== void 0,
|
|
9728
9744
|
type: typeof t,
|
|
9729
|
-
value:
|
|
9745
|
+
value: Gu(t, 3, 2e3, void 0, Ju)
|
|
9730
9746
|
}, null, 2);
|
|
9731
9747
|
}
|
|
9732
|
-
return JSON.stringify(
|
|
9748
|
+
return JSON.stringify(Ku(), null, 2);
|
|
9733
9749
|
}, {
|
|
9734
9750
|
name: "inspect_env",
|
|
9735
9751
|
description: "读宿主页面环境信息(排查调试)。不传参返回摘要(URL/origin、浏览器/语言、viewport、title/readyState);传 key 读指定 window 属性值(如 key:\"appConfig\")。只读,大结果自动外存 vfs。",
|
|
9736
9752
|
schema: t.object({ key: t.string().optional().describe("要读取的 window 属性名(如 \"appConfig\"/\"__DEBUG__\");不传 = 返回环境摘要") })
|
|
9737
|
-
}),
|
|
9753
|
+
}), Xu = [Yu];
|
|
9738
9754
|
//#endregion
|
|
9739
9755
|
//#region src/core/harness/budget.ts
|
|
9740
|
-
function
|
|
9756
|
+
function Zu(e, t, n) {
|
|
9741
9757
|
let r = 0;
|
|
9742
9758
|
return {
|
|
9743
9759
|
name: "budget",
|
|
@@ -9762,12 +9778,12 @@ function Xu(e, t, n) {
|
|
|
9762
9778
|
}
|
|
9763
9779
|
//#endregion
|
|
9764
9780
|
//#region src/core/sdk/actions.ts
|
|
9765
|
-
var
|
|
9766
|
-
function
|
|
9781
|
+
var Qu = /^[a-zA-Z][a-zA-Z0-9_]*$/;
|
|
9782
|
+
function $u(e) {
|
|
9767
9783
|
let n = [];
|
|
9768
9784
|
for (let [i, a] of Object.entries(e)) {
|
|
9769
|
-
if (!
|
|
9770
|
-
console.warn(`[page-agent-sdk][actions] 动作名 "${i}" 非法(须匹配 ${
|
|
9785
|
+
if (!Qu.test(i)) {
|
|
9786
|
+
console.warn(`[page-agent-sdk][actions] 动作名 "${i}" 非法(须匹配 ${Qu}),已跳过`);
|
|
9771
9787
|
continue;
|
|
9772
9788
|
}
|
|
9773
9789
|
let e = a.description || `宿主动作 ${i}`;
|
|
@@ -9787,9 +9803,9 @@ function Qu(e) {
|
|
|
9787
9803
|
}
|
|
9788
9804
|
return n;
|
|
9789
9805
|
}
|
|
9790
|
-
function
|
|
9806
|
+
function ed(e) {
|
|
9791
9807
|
let t = {};
|
|
9792
|
-
for (let [n, r] of Object.entries(e))
|
|
9808
|
+
for (let [n, r] of Object.entries(e)) Qu.test(n) && (t[n] = {
|
|
9793
9809
|
description: r.description,
|
|
9794
9810
|
hasParams: !!r.params
|
|
9795
9811
|
});
|
|
@@ -9797,12 +9813,12 @@ function $u(e) {
|
|
|
9797
9813
|
}
|
|
9798
9814
|
//#endregion
|
|
9799
9815
|
//#region src/core/toolsets.ts
|
|
9800
|
-
var
|
|
9801
|
-
function
|
|
9802
|
-
return
|
|
9816
|
+
var td = Lu, nd = Uu;
|
|
9817
|
+
function rd(e, t) {
|
|
9818
|
+
return Fu(e, t);
|
|
9803
9819
|
}
|
|
9804
|
-
function
|
|
9805
|
-
let a =
|
|
9820
|
+
function id(e, t, n, r, i) {
|
|
9821
|
+
let a = zl(e);
|
|
9806
9822
|
return [
|
|
9807
9823
|
...a.dataOps ? t : [],
|
|
9808
9824
|
...a.fetch ? n : [],
|
|
@@ -9812,7 +9828,7 @@ function rd(e, t, n, r, i) {
|
|
|
9812
9828
|
}
|
|
9813
9829
|
//#endregion
|
|
9814
9830
|
//#region src/core/sdk/toolRegistry.ts
|
|
9815
|
-
function
|
|
9831
|
+
function ad(e) {
|
|
9816
9832
|
let t = /* @__PURE__ */ new Map(), n = [];
|
|
9817
9833
|
for (let r of e) for (let e of r.tools) {
|
|
9818
9834
|
let i = t.get(e.name);
|
|
@@ -9832,15 +9848,15 @@ function id(e) {
|
|
|
9832
9848
|
}
|
|
9833
9849
|
//#endregion
|
|
9834
9850
|
//#region src/core/harness/usageHints.ts
|
|
9835
|
-
var
|
|
9836
|
-
function
|
|
9837
|
-
let a =
|
|
9851
|
+
var od = .7;
|
|
9852
|
+
function sd(e, t, n = "simple", r, i) {
|
|
9853
|
+
let a = zl(e), o = n !== "advanced", s = n === "minimal";
|
|
9838
9854
|
return {
|
|
9839
9855
|
name: "usageHints",
|
|
9840
9856
|
augmentPrompt: (n) => {
|
|
9841
9857
|
let r = [];
|
|
9842
9858
|
if (a.planning && (r.push("【自适应规划】按任务复杂度决定是否先规划,不要对简单任务过度编排:"), r.push(" · 简单/明确任务(改单字段、调样式、查值)→ 直接 read/write 执行,不必 write_todos。"), r.push(" · 复杂任务(多步、大改、有歧义、不可逆)→ 先 write_todos 拆解,首个任务标 in_progress,逐项推进。"), r.push(" · 执行中发现步骤要改/补/细分 → 用 update_todo({id, content?, status?}) 按 id 增量改单项,不必重传整个清单。"), e?.humanConfirm ? r.push(" · 规划出多步方案若需用户拍板 → 先 request_human_confirmation 给方案选项,确认后再执行。") : r.push(" · 规划出多步方案若需用户拍板 → 以文字列出方案选项等用户回复,勿自行拍板。"), r.push(" · 规划阶段有轮次预算(maxPlanRevisions,默认 5):勿反复调研/改计划而不执行,规划充分后即开始 write 落地。")), t && (o ? (r.push("读写主数据用 read/write(高层入口,自动乐观锁 + 自动快照)。read({jsonPath}) 读子路径当前值(返回含 hash,write 时自动比对,无需手动传);read() 不传读整个主数据 + 说明。write 改值两姿势:① 改单个字段/子路径用 write({patch:{op:\"set\", jsonPath:\"路径.字段\", value:新值}})——patch.value 就是该字段的新值(类型匹配:string 直传字符串、number 传数字、对象传对象),不要包成 {字段:值} 对象(字段名已在 jsonPath);也兼容 write({value:新值, patch:{op,jsonPath}}) 顶层 value(向后兼容,但优先 patch.value,避免与整体 set 的 value 混淆);② 替换整个对象用 write({value:{整个新对象}})。op:set 设值 / remove 删 / merge 合并对象 / append 追加数组 / move 移动数组元素(value=目标路径字符串:数组本身=追加到末尾、数组内下标=插到该位置;同数组即重排如组件调序,目标下标按移除源后解释,一步完成免双 set 交换);批量多改动 write({patches:[{op,jsonPath,value},...]});删子路径 write({patch:{jsonPath:\"路径\"}, del:true})。写入自动经 schema 校验(失败不写,按错误提示改值类型/形状后重试)+ 自动存快照" + (s ? "。" : "(出错可用 restore_data 回退)。")), r.push("修改大对象/数组优先用 write 的 patch 增量(只发改动部分),避免整体重传被 max_tokens 截断致 JSON 不完整。"), r.push("读大数组(read 返回 hasMore=true)用 read({jsonPath,offset,limit}) 分页(offset+=limit 续读,默认 limit=50);一次读多个不相关子路径用 read({jsonPaths:[...]}) 省轮次;复杂 patches 改动先 write({patches,dryRun:true}) 预检(走完整校验不落盘)。"), r.push("read/describe 返回按 schema 投影:仅 schema 声明的字段可见(未声明字段自动隐藏,防误操作);要操作某字段需集成方在 schema 声明。"), s || (r.push("查任意路径完整约束或对比快照差异需切 advanced 工具模式(schema_data/diff_data,当前未装载勿调用);查历史快照值(只读不改当前)用 history_data({id?,jsonPath?})。"), r.push("在大数组里按条件筛选用 query_data(JSONPath,如 $.components[?(@.type==\"card\" && @.price<100)]),返回匹配元素 path/index;定位后用 write patch 改。找名字记不清的元素用 search_data(substring/regex/fuzzy)。批量过滤/映射/聚合/重写大数组用 eval_script(沙箱脚本,mode=query 只读/transform 落地)。"))) : (r.push("改主数据前先 get_data({jsonPath}) 读其当前真实值与 hash(返回末尾 hash=xxx),基于真实值改,不要凭记忆。写入(set/edit/delete)时回传 expectedHash=该 hash 启用乐观锁——若主数据在你 get 之后被外部代码/其他 agent/用户手动改过,会触发冲突:集成方若开启人工介入,工具会挂起等用户决定(保留外部/强制覆盖/回退),你应等待工具返回后按结果继续(保留外部→重新 get 再改;强制覆盖→已写入,继续;回退→已回退到历史快照,基于回退值重写);未开启人工介入时返回 VERSION_CONFLICT 不写入,重新 get 拿最新值与 hash 再改。"), r.push("不确定主数据字段结构时用 describe_data 查看说明。"), r.push("修改大对象/数组优先用 edit_data 增量 patch(只发改动部分),避免 set_data 整体重传被 max_tokens 截断导致 JSON 不完整、校验失败。"), r.push("修改主数据出错时可用 restore_data 回退最近一次。"), r.push("在大数组里按条件筛选元素用 query_data(JSONPath,如 $.components[?(@.type==\"card\" && @.price<100)]),返回匹配元素的 path/index;定位后再 edit_data 改。"), r.push("找名字记不清的元素用 search_data(支持 substring/regex/fuzzy 模糊搜索)。"), r.push("需要过滤/映射/聚合/批量重写大数组时用 eval_script(沙箱脚本,入参 data);只读探查用 mode=query,批量重写用 mode=transform(返回值经校验后落地)。"), r.push("读大数组用 read({jsonPath,offset,limit}) 分页(返回 hasMore=true 时 offset+=limit 续读);一次读多个不相关子路径用 read({jsonPaths});复杂改动先 write({...,dryRun:true}) 预检不落盘。"), r.push("对比当前与历史快照(或一段 JSON against)的差异用 diff_data({snapshotId?,against?})(返回结构化 path→from/to,verify 自纠/操作审计/\"刚才改了啥\");只读查历史快照值用 history_data({id?,jsonPath?})。"))), a.subagent && r.push("独立子任务可 spawn_agent 委派(过程隔离,不占主上下文):默认只读,需要子 agent 写数据时传 writablePaths(路径前缀白名单,越界 PATH_OUT_OF_SCOPE)。多个独立子任务可 spawn_agents 并行委派(各子互不通信,结论由你汇总;并行委派不可授写权限,写操作由你收尾执行)。"), a.inspectEnv && r.push("排查页面环境(当前 URL/浏览器/视口/集成方调试变量)用 inspect_env——不传参返回环境摘要(location/navigator/viewport/document),传 key 读特定 window 属性(如 inspect_env({key:\"appConfig\"}) 读 window.appConfig)。改完数据看渲染、定位\"为何没生效\"时用它(只读,不改数据)。"), a.domInspect && r.push("改完数据想确认渲染是否生效(或定位元素/辅助 UI 设计问答)用 get_dom({selector?,depth?}) 读渲染后 DOM(结构化返回 tag/attrs/text/children,depth 控制深度防爆炸,只读)。配合宿主 actions(save_draft/publish 等)形成\"改数据→get_dom 看渲染→触发动作\"闭环。"), a.draftWrite && !o && (r.push("生成超大 JSON(如 50+ 组件页面,单次 write 受 max_tokens 限制装不下)用 draft_write 分块构建 → draft_commit 原子提交:draft_write({draftId, chunk, mode}) mode:\"start\" 新建/\"append\" 追加(拼 JSON 片段到 drafts 池);累积完 draft_commit({draftId}) 合并 + schema 校验 + 写主数据(失败草稿保留可修后重试,成功自动清草稿)。小改仍用 write patch,只在大 JSON 从零生成时用 draft。"), r.push("⚠️ 大 JSON 分块构建是典型多轮工具调用(draft_write×N + draft_commit + read 确认 + 调研 read/query),默认 maxToolRounds=10 可能触顶被 while 截断导致草稿写不完;目标组件数大时集成方应在 createChatSdk 配 maxToolRounds ≥ 20(或按 N+5 估算)。draft_commit 提交同样走乐观锁(改前 read 拿 hash,bind 被改过会触发冲突介入,不静默覆盖)。")), a.todoDeps && r.push("复杂任务可用 todos 层级依赖:write_todos 时给 todo 传 parentId(父任务 id,表达层级)+ deps(依赖的 todo id 数组,必须先完成)。有依赖的任务,deps 全 completed 后再标 in_progress;完成时 update_todo({id, status:\"completed\", evidence:\"完成证据\"}) 记证据。无依赖关系的任务不传 parentId/deps(扁平)。"), a.focus && !o && (r.push("【上下文聚焦】判断任务范围,用 set_focus/add_focus/remove_focus/clear_focus 自动收敛工作范围:"), r.push(" · 局部任务(只改某一组件/区域,如「调导航栏」「改 components.3 样式」)→ 先 read 定位 jsonPath,再 set_focus({path:\"该子树路径\"}) 聚焦;聚焦后每轮只看该子树结构,写其他位置会被 PATH_DENIED 拒绝。"), r.push(" · 多个相关组件(如「同时改导航栏和页脚」)→ set_focus 聚焦首个后用 add_focus({path}) 追加其余;聚焦后可写任一焦点子树,越界仍被拒;移除单个用 remove_focus({path})。"), r.push(" · 全局任务(多处/整体结构,如「重排所有组件」「换主题」)→ 不要聚焦,保持全量视野直接写。"), r.push(" · 完成局部精修、要转向其他区域或做整体改动 → 调 clear_focus 退出聚焦(清空全部焦点),恢复全部读写权限。"), r.push(" · set_focus/add_focus 的 path 必须在 schema 内(类型校验);不确定路径先 read/describe_data 查。")), e?.subagents?.length) {
|
|
9843
|
-
let t = e.subagents.filter((e) => (e.temperature ?? 0) >=
|
|
9859
|
+
let t = e.subagents.filter((e) => (e.temperature ?? 0) >= od || /规划|创意|设计|方案|brainstorm|plan/i.test(e.description)), n = e.subagents.filter((e) => (e.temperature ?? 0) < od && /反思|审查|挑刺|校验|review|critique|reflect/i.test(e.description));
|
|
9844
9860
|
r.push("【规划-反思-执行·路由】按任务性质选模式,不要对简单任务过度编排:"), t.length && (r.push(` · 创作/设计/开放性需求(如"设计主题风格""换个感觉")→ 先调 ${t.map((e) => "use_" + e.id).join("/")} 出 2-3 套方案(高温创意),`), r.push(e?.humanConfirm ? " 不要自己拍板;拿到方案后,若需用户拍板用 request_human_confirmation 弹选项。" : " 不要自己拍板;拿到方案后以文字列出选项等用户回复(humanConfirm 未开,勿调不存在工具)。")), n.length && r.push(` · 严谨/易错/校验类 → 可先调 ${n.map((e) => "use_" + e.id).join("/")} 反思挑刺(低温审查),据反馈修订。`), r.push(o ? " · 方案定稿后,由你(主 agent)用 write 落地成 JSON(低温度执行 + schema 校验 + 写前确认)。" : " · 方案定稿后,由你(主 agent)用 edit_data 落地成 JSON(低温度执行 + schema 校验 + 写前确认)。"), r.push(" · 简单/明确任务(如\"标题改红色\")直接执行,不必走规划-反思。");
|
|
9845
9861
|
}
|
|
9846
9862
|
e?.humanConfirm && (r.push("【人工确认·必读】以下情形必须先调 request_human_confirmation 征询用户、拿到答复后再继续,不要自行拍板:"), r.push(" 1) 用户让你「给方案/列选项/我来选/挑一个」时:把每个方案作为一个 option,调 request_human_confirmation(question=简述, options=[方案A,方案B,...], recommendation=你推荐的)。不要只回文字罗列方案让用户自己回复——要用工具把选项做成可点选按钮。"), r.push(" 2) 需求有歧义/不确定时:调工具问清楚(options 不传则用户答同意或拒绝)。"), r.push(" 3) 即将执行高风险不可逆操作(删除/覆盖/批量改动)前:调工具确认。"), r.push(" 4) 规划出多步方案需用户确认时:把整个方案(或关键分步)作为 option 调 request_human_confirmation,确认后再执行。"), r.push("用户在选项里选了哪个,就按那个方案继续;选「拒绝」则停止并询问如何调整。"));
|
|
@@ -9860,7 +9876,7 @@ function od(e, t, n = "simple", r, i) {
|
|
|
9860
9876
|
}
|
|
9861
9877
|
//#endregion
|
|
9862
9878
|
//#region src/core/harness/resourcesPin.ts
|
|
9863
|
-
function
|
|
9879
|
+
function cd(e) {
|
|
9864
9880
|
let t = e.toolsExposed === !1 ? "读到 ⟦frozen:path⟧/⟦res:handle⟧ 占位符 = 精确值在冻结区/资源池(不入消息流);resource_get/resource_update 为 advanced 工具,当前模式未装载,勿尝试调用;freeze 字段不可写(撞 FROZEN_FIELD 即放弃);verbatim 字段保持原值,勿在当前模式下尝试改写(直接写新值会 VERBATIM_MISMATCH);撞 RESOURCE_EVICTED/RESOURCE_NOT_FOUND 重新 read 懒注册。" : "读到 ⟦frozen:path⟧/⟦res:handle⟧ 占位符 = 精确值在冻结区/资源池(不入消息流);需真值用 resource_get({path});freeze 字段不可写(撞 FROZEN_FIELD 即放弃);verbatim 直接写新值会 VERBATIM_MISMATCH,先 resource_update 再写回句柄;撞 RESOURCE_EVICTED/RESOURCE_NOT_FOUND 重新 read 懒注册。";
|
|
9865
9881
|
return {
|
|
9866
9882
|
name: "resourcesPin",
|
|
@@ -9875,78 +9891,78 @@ function sd(e) {
|
|
|
9875
9891
|
}
|
|
9876
9892
|
//#endregion
|
|
9877
9893
|
//#region src/core/backends/skillStore.ts
|
|
9878
|
-
var
|
|
9879
|
-
function
|
|
9880
|
-
return `${
|
|
9894
|
+
var ld = "v:1::skill-store", ud = "chat-sdk";
|
|
9895
|
+
function dd(e, t, n) {
|
|
9896
|
+
return `${ld}::${e}::${t}::${n}`;
|
|
9881
9897
|
}
|
|
9882
|
-
function
|
|
9883
|
-
return `${
|
|
9898
|
+
function fd(e, t) {
|
|
9899
|
+
return `${ld}::${e}::${t}::`;
|
|
9884
9900
|
}
|
|
9885
|
-
function
|
|
9886
|
-
let t = e.dbName ??
|
|
9901
|
+
function pd(e = {}) {
|
|
9902
|
+
let t = e.dbName ?? ud, n = e.backend ?? "indexed", r = e.id ?? "", i, a, o = new Promise((e) => {
|
|
9887
9903
|
a = e;
|
|
9888
9904
|
});
|
|
9889
9905
|
return (async () => {
|
|
9890
9906
|
try {
|
|
9891
9907
|
if (n === "indexed") {
|
|
9892
9908
|
if (typeof indexedDB > "u") throw Error("indexedDB 不可用");
|
|
9893
|
-
i = await
|
|
9909
|
+
i = await Ml(t), a(!0);
|
|
9894
9910
|
} else if (n === "session") {
|
|
9895
9911
|
if (typeof sessionStorage > "u") throw Error("sessionStorage 不可用");
|
|
9896
|
-
i =
|
|
9912
|
+
i = Nl(sessionStorage), a(!0);
|
|
9897
9913
|
} else if (n === "local") {
|
|
9898
9914
|
if (typeof localStorage > "u") throw Error("localStorage 不可用");
|
|
9899
|
-
i =
|
|
9900
|
-
} else i =
|
|
9915
|
+
i = Nl(localStorage), a(!0);
|
|
9916
|
+
} else i = jl(), a(!1);
|
|
9901
9917
|
} catch {
|
|
9902
|
-
i =
|
|
9918
|
+
i = jl(), a(!1);
|
|
9903
9919
|
}
|
|
9904
9920
|
})(), {
|
|
9905
9921
|
ready: o,
|
|
9906
9922
|
async list() {
|
|
9907
9923
|
let e = [];
|
|
9908
|
-
return await i.scan(
|
|
9924
|
+
return await i.scan(fd(t, r), (t, n) => {
|
|
9909
9925
|
e.push(n);
|
|
9910
9926
|
}), e;
|
|
9911
9927
|
},
|
|
9912
9928
|
async get(e) {
|
|
9913
|
-
return await i.get(
|
|
9929
|
+
return await i.get(dd(t, r, e));
|
|
9914
9930
|
},
|
|
9915
9931
|
async put(e) {
|
|
9916
9932
|
try {
|
|
9917
|
-
await i.set(
|
|
9933
|
+
await i.set(dd(t, r, e.name), e);
|
|
9918
9934
|
} catch (e) {
|
|
9919
|
-
|
|
9935
|
+
Cl(e) && (i = jl());
|
|
9920
9936
|
}
|
|
9921
9937
|
},
|
|
9922
9938
|
async remove(e) {
|
|
9923
|
-
let n =
|
|
9939
|
+
let n = dd(t, r, e);
|
|
9924
9940
|
return await i.get(n) == null ? !1 : (await i.del(n), !0);
|
|
9925
9941
|
},
|
|
9926
9942
|
async clear() {
|
|
9927
|
-
await i.clearPrefix(
|
|
9943
|
+
await i.clearPrefix(fd(t, r));
|
|
9928
9944
|
},
|
|
9929
9945
|
dispose() {}
|
|
9930
9946
|
};
|
|
9931
9947
|
}
|
|
9932
|
-
var
|
|
9933
|
-
function
|
|
9948
|
+
var md = /large_results\/[^\s"'`),]+\.txt/g;
|
|
9949
|
+
function hd(e) {
|
|
9934
9950
|
let t = /* @__PURE__ */ new Set(), n = (e) => {
|
|
9935
9951
|
if (typeof e != "string" || !e) return;
|
|
9936
9952
|
let n;
|
|
9937
|
-
for (
|
|
9953
|
+
for (md.lastIndex = 0; (n = md.exec(e)) !== null;) t.add(n[0]);
|
|
9938
9954
|
};
|
|
9939
9955
|
for (let t of e) if (n(t.content), t.steps) for (let e of t.steps) n(e.result);
|
|
9940
9956
|
return t;
|
|
9941
9957
|
}
|
|
9942
|
-
function
|
|
9958
|
+
function gd(e, t) {
|
|
9943
9959
|
let n = [];
|
|
9944
9960
|
for (let r of Object.keys(e)) r.startsWith("large_results/") && !t.has(r) && n.push(r);
|
|
9945
9961
|
return n;
|
|
9946
9962
|
}
|
|
9947
9963
|
//#endregion
|
|
9948
9964
|
//#region src/core/utils/serialRunner.ts
|
|
9949
|
-
function
|
|
9965
|
+
function _d() {
|
|
9950
9966
|
let e = Promise.resolve();
|
|
9951
9967
|
return function(t) {
|
|
9952
9968
|
let n = e.then(t, t);
|
|
@@ -9955,24 +9971,24 @@ function gd() {
|
|
|
9955
9971
|
}
|
|
9956
9972
|
//#endregion
|
|
9957
9973
|
//#region src/core/sdk/createChatSdk.ts
|
|
9958
|
-
var
|
|
9959
|
-
function
|
|
9974
|
+
var vd = 30, yd = /* @__PURE__ */ new Map();
|
|
9975
|
+
function bd(e, t) {
|
|
9960
9976
|
return e === "set_data" ? "set" : e === "edit_data" ? "edit" : e === "delete_data" ? "delete" : e === "restore_data" ? "restore" : e === "write" ? t?.del ? "delete" : t?.patch ? "edit" : "set" : null;
|
|
9961
9977
|
}
|
|
9962
|
-
function
|
|
9978
|
+
function xd(e) {
|
|
9963
9979
|
return e === "spawn_agent" || e === "spawn_agents" || e.startsWith("use_");
|
|
9964
9980
|
}
|
|
9965
|
-
function
|
|
9981
|
+
function Sd(e, t, n, r) {
|
|
9966
9982
|
let i = 0;
|
|
9967
9983
|
return {
|
|
9968
9984
|
name: "sdk-events",
|
|
9969
9985
|
wrapToolCall: async (t, r) => {
|
|
9970
|
-
let i = await r(t), a =
|
|
9986
|
+
let i = await r(t), a = bd(t.name, t.args);
|
|
9971
9987
|
return a ? e({
|
|
9972
9988
|
type: "data_change",
|
|
9973
9989
|
operation: a,
|
|
9974
9990
|
value: n()?.bind
|
|
9975
|
-
}) : i.status === "done" &&
|
|
9991
|
+
}) : i.status === "done" && xd(t.name) && e({
|
|
9976
9992
|
type: "data_change",
|
|
9977
9993
|
operation: "edit",
|
|
9978
9994
|
value: n()?.bind
|
|
@@ -9999,7 +10015,7 @@ function xd(e, t, n, r) {
|
|
|
9999
10015
|
}
|
|
10000
10016
|
};
|
|
10001
10017
|
}
|
|
10002
|
-
function
|
|
10018
|
+
function Cd(e, t, n, r, i) {
|
|
10003
10019
|
if (!n) return i && console.warn(`[page-agent-sdk][focus] capabilities.focus 关闭,${t} 忽略`), {
|
|
10004
10020
|
ok: !1,
|
|
10005
10021
|
error: "capabilities.focus 关闭"
|
|
@@ -10017,18 +10033,18 @@ function Sd(e, t, n, r, i) {
|
|
|
10017
10033
|
error: "当前无主数据 schema,无法聚焦"
|
|
10018
10034
|
});
|
|
10019
10035
|
}
|
|
10020
|
-
function
|
|
10036
|
+
function wd(e, n) {
|
|
10021
10037
|
let i = {
|
|
10022
10038
|
prompt_tokens: 0,
|
|
10023
10039
|
completion_tokens: 0,
|
|
10024
10040
|
total_tokens: 0
|
|
10025
|
-
}, a =
|
|
10041
|
+
}, a = ul(() => q), o = /* @__PURE__ */ At(0), s = Il(e.storage);
|
|
10026
10042
|
e.debug && s && s.onEvent((e) => console.log("[page-agent-sdk][storage]", e));
|
|
10027
|
-
let { modelCaps: c, summaryLlmInvoke: l, titleLlmInvoke: u, compressDecisionInvoke: d } =
|
|
10043
|
+
let { modelCaps: c, summaryLlmInvoke: l, titleLlmInvoke: u, compressDecisionInvoke: d } = ll(e), f = c;
|
|
10028
10044
|
if (e.debug && console.log("[page-agent-sdk][modelCaps]", f), f.contextWindow < 2e5) throw Error(`[page-agent-sdk] 模型上下文窗口 ${f.contextWindow} 小于最小支持 ${ai}(需 ≥200K 窗口模型,如 GLM-5.2/Claude/Kimi/Qwen-1M/DeepSeek-v4)`);
|
|
10029
|
-
let h =
|
|
10045
|
+
let h = Ul(e, f.contextWindow), g = h.enableLLMSummary !== !1, _ = (e.contextOptions && e.contextOptions.preserveLastToolResults) ?? Hl[e.contextPreset ?? "auto"], v = new Set(_), y = e.llm;
|
|
10030
10046
|
e.debug && !l && console.warn("[page-agent-sdk][summarization] 未构造 llmInvoke(apiKey 缺失?),摘要回退零成本索引摘要");
|
|
10031
|
-
let b = /* @__PURE__ */ vt([]), x =
|
|
10047
|
+
let b = /* @__PURE__ */ vt([]), x = lc(e.vfs?.initialFiles, {
|
|
10032
10048
|
persist: s ? { save: (e) => {
|
|
10033
10049
|
Ft({ vfs: e });
|
|
10034
10050
|
} } : void 0,
|
|
@@ -10047,8 +10063,8 @@ function Cd(e, n) {
|
|
|
10047
10063
|
let D = { current: null }, O = e.data ? {
|
|
10048
10064
|
...e.data,
|
|
10049
10065
|
description: e.data.description ?? "主数据对象"
|
|
10050
|
-
} : void 0, k = !(e.subagents ?? []).some((e) => e._codeAsset) &&
|
|
10051
|
-
k && O?.schema && $i(O.schema).length && (A = [...e.subagents ?? [],
|
|
10066
|
+
} : void 0, k = !(e.subagents ?? []).some((e) => e._codeAsset) && zl(e.capabilities).subagent, A = e.subagents;
|
|
10067
|
+
k && O?.schema && $i(O.schema).length && (A = [...e.subagents ?? [], Jc()], console.info("[page-agent-sdk] 检测到 schema 含代码组件数组(如 components[].code),已自动装配 HTML 代码子 agent(委派编排 + vfs 工作副本 + 格式校验 + 增量 commit)。需定制(codeField/formatCheck/craftNotes 等)请显式传 createHtmlSubagent(...)"));
|
|
10052
10068
|
let ee = (A ?? []).filter((e) => !!e._codeAsset), j = /* @__PURE__ */ new Set();
|
|
10053
10069
|
for (let e of ee) {
|
|
10054
10070
|
if (e._codeAsset.writablePaths.length) continue;
|
|
@@ -10064,12 +10080,15 @@ function Cd(e, n) {
|
|
|
10064
10080
|
getTodos: () => D.current?.getState?.()?.todos ?? [],
|
|
10065
10081
|
messages: b,
|
|
10066
10082
|
maxCheckpoints: re && typeof re == "object" ? re.maxCheckpoints : void 0
|
|
10067
|
-
}) : null, I = !re || typeof re != "object" || re.auto !== !1, L =
|
|
10083
|
+
}) : null, I = !re || typeof re != "object" || re.auto !== !1, L = zl(e.capabilities), R = L.dataOps, ae = L.draftWrite, oe = L.tracing, se = L.automation, ce = ac({
|
|
10084
|
+
...e,
|
|
10085
|
+
locale: e.i18n?.locale
|
|
10086
|
+
});
|
|
10068
10087
|
if (N) {
|
|
10069
10088
|
let e = M.map((e) => e._codeAsset.orchestratorPrompt).filter(Boolean).join("\n\n");
|
|
10070
10089
|
e && (ce += "\n\n" + e);
|
|
10071
10090
|
} else O?.schema && Qi(O.schema) && (ce += "\n\n" + ga.htmlDirectWriteFallback, console.warn("[page-agent-sdk] 检测到 schema 含 code 字段但未注册 html 子 agent:已自动注入「主 agent 自己写 HTML」编排(code 作普通字段直接 write,无 vfs 工作副本 / 无格式校验门禁)。如需代码资产机制(vfs + 格式校验 + 增量 commit + 主上下文 code 摘要),注册 createHtmlSubagent;若确为降级意图可忽略。"));
|
|
10072
|
-
let le = R && O ?
|
|
10091
|
+
let le = R && O ? Fu(O, {
|
|
10073
10092
|
onAudit: e.onAudit ?? (e.debug ? (e) => console.log("[page-agent-sdk][data audit]", e) : void 0),
|
|
10074
10093
|
maxSnapshots: e.maxSnapshots,
|
|
10075
10094
|
onConflict: a.set,
|
|
@@ -10078,14 +10097,14 @@ function Cd(e, n) {
|
|
|
10078
10097
|
vfsStore: ae || O?.resources?.length ? x : void 0,
|
|
10079
10098
|
...P.length ? { pgIdPaths: P } : {},
|
|
10080
10099
|
...ne.length ? { largeTextPaths: ne } : {}
|
|
10081
|
-
}) : [], ue = R ?
|
|
10100
|
+
}) : [], ue = R ? Eu(le, e.toolMode) : [], z = R && O ? le.controller ?? null : null, de = R && O?.resources?.length && z?.getResourcesSnapshot ? cd({
|
|
10082
10101
|
getResourcesSnapshot: () => z?.getResourcesSnapshot?.() ?? [],
|
|
10083
10102
|
toolsExposed: e.toolMode === "advanced"
|
|
10084
|
-
}) : void 0, B = () => z?.get() ?? O, V = /* @__PURE__ */ new Map(), fe =
|
|
10103
|
+
}) : void 0, B = () => z?.get() ?? O, V = /* @__PURE__ */ new Map(), fe = id(L, ue, Lu, Uu, Xu);
|
|
10085
10104
|
fe.forEach((e) => V.set(e.name, "builtin"));
|
|
10086
10105
|
let pe = [...e.tools || []];
|
|
10087
10106
|
pe.forEach((e) => V.set(e.name, "user"));
|
|
10088
|
-
let H =
|
|
10107
|
+
let H = $u(e.actions ?? {});
|
|
10089
10108
|
H.forEach((e) => V.set(e.name, "action"));
|
|
10090
10109
|
let me = [], he = !1, ge = e.humanConfirm !== !1 && (!e.approval || e.approval.humanConfirmTool !== !1), _e = ge ? Mo() : null;
|
|
10091
10110
|
_e && V.set(Ao, "builtin");
|
|
@@ -10157,7 +10176,7 @@ function Cd(e, n) {
|
|
|
10157
10176
|
Ce.forEach((e) => V.set(e.name, "builtin"));
|
|
10158
10177
|
let we = [], Te = /* @__PURE__ */ new Map(), W = G();
|
|
10159
10178
|
function G() {
|
|
10160
|
-
let { tools: e, collisions: t } =
|
|
10179
|
+
let { tools: e, collisions: t } = ad([
|
|
10161
10180
|
{
|
|
10162
10181
|
label: "builtin",
|
|
10163
10182
|
tools: fe
|
|
@@ -10194,7 +10213,7 @@ function Cd(e, n) {
|
|
|
10194
10213
|
return t.length && console.warn("[page-agent-sdk] 工具重名,后注册覆盖先注册:", t.map((e) => `${e.name}(${e.loser}→${e.winner})`).join(", ")), e;
|
|
10195
10214
|
}
|
|
10196
10215
|
let Ee = L.planning, De = L.missionAnchor, Oe = L.workingMemory, ke = L.skills, Ae = L.vfs || N;
|
|
10197
|
-
if (Ae) for (let e of
|
|
10216
|
+
if (Ae) for (let e of gc) V.set(e, "builtin");
|
|
10198
10217
|
if (Ee) for (let e of S.tools ?? []) V.set(e.name, "builtin");
|
|
10199
10218
|
let je = L.summarization, Me = L.agentCompression && !!d;
|
|
10200
10219
|
e.debug && L.agentCompression && !d && console.warn("[page-agent-sdk][agentCompression] agentCompression 开启但 summaryLlm 不可用(或缺 apiKey / 模型不支持工具),压缩决策不启用,回退静态压缩");
|
|
@@ -10224,7 +10243,7 @@ function Cd(e, n) {
|
|
|
10224
10243
|
timeoutMs: Be?.timeoutMs
|
|
10225
10244
|
}), Ke = te?.map((e) => {
|
|
10226
10245
|
if (!e._codeAsset) return e;
|
|
10227
|
-
let t = e._codeAsset, n =
|
|
10246
|
+
let t = e._codeAsset, n = Pc({
|
|
10228
10247
|
writablePaths: t.writablePaths,
|
|
10229
10248
|
codeVfsPrefix: t.codeVfsPrefix,
|
|
10230
10249
|
ext: t.ext,
|
|
@@ -10239,7 +10258,7 @@ function Cd(e, n) {
|
|
|
10239
10258
|
...e,
|
|
10240
10259
|
middleware: r
|
|
10241
10260
|
};
|
|
10242
|
-
}), qe = N && Pe ?
|
|
10261
|
+
}), qe = N && Pe ? Fc() : void 0, Je = qe ? Vc({
|
|
10243
10262
|
getBind: () => B()?.bind,
|
|
10244
10263
|
writablePaths: P,
|
|
10245
10264
|
getLocked: () => qe.locked(),
|
|
@@ -10262,7 +10281,7 @@ function Cd(e, n) {
|
|
|
10262
10281
|
timeoutMs: e.subagent?.timeoutMs,
|
|
10263
10282
|
...qe ? {
|
|
10264
10283
|
componentLock: qe,
|
|
10265
|
-
resolveComponents: (e) =>
|
|
10284
|
+
resolveComponents: (e) => Ic(e, Ac(B()?.bind, P))
|
|
10266
10285
|
} : {}
|
|
10267
10286
|
}) : void 0, Xe = Ye ? Ye.controller : null, Ze = [
|
|
10268
10287
|
"get_data",
|
|
@@ -10280,8 +10299,8 @@ function Cd(e, n) {
|
|
|
10280
10299
|
} : void 0
|
|
10281
10300
|
}) : void 0, et = ze ? Xs({
|
|
10282
10301
|
contextWindow: f.contextWindow,
|
|
10283
|
-
thresholdRatio:
|
|
10284
|
-
}) : void 0, tt =
|
|
10302
|
+
thresholdRatio: Ul(e, f.contextWindow).summaryThresholdRatio
|
|
10303
|
+
}) : void 0, tt = sd({
|
|
10285
10304
|
...L,
|
|
10286
10305
|
humanConfirm: ge,
|
|
10287
10306
|
subagents: te?.map((e) => ({
|
|
@@ -10291,7 +10310,7 @@ function Cd(e, n) {
|
|
|
10291
10310
|
}))
|
|
10292
10311
|
}, R && !!O, e.toolMode, !!O?.resources?.length, { promptSoftCap: as(f.contextWindow, h.promptSoftCapTokens) }), nt = O ? {
|
|
10293
10312
|
name: "dataHint",
|
|
10294
|
-
augmentPrompt: () =>
|
|
10313
|
+
augmentPrompt: () => ic(B(), e.schemaHint) || void 0
|
|
10295
10314
|
} : null, rt = e.augmentSystem ? {
|
|
10296
10315
|
name: "augmentSystem",
|
|
10297
10316
|
augmentPrompt: (t) => {
|
|
@@ -10305,7 +10324,7 @@ function Cd(e, n) {
|
|
|
10305
10324
|
return;
|
|
10306
10325
|
}
|
|
10307
10326
|
}
|
|
10308
|
-
} : null, it =
|
|
10327
|
+
} : null, it = Bl(e.onEvent), q = it.emit, at, ot = [], st = (e) => ({
|
|
10309
10328
|
name: e.name,
|
|
10310
10329
|
description: e.description,
|
|
10311
10330
|
content: typeof e.getContent == "function" ? e.getContent() : ""
|
|
@@ -10313,7 +10332,7 @@ function Cd(e, n) {
|
|
|
10313
10332
|
name: e.name,
|
|
10314
10333
|
description: e.description,
|
|
10315
10334
|
getContent: () => e.content
|
|
10316
|
-
}), lt = e.skillStorage === !1 ? null :
|
|
10335
|
+
}), lt = e.skillStorage === !1 ? null : pd({
|
|
10317
10336
|
...typeof e.skillStorage == "object" ? e.skillStorage : {},
|
|
10318
10337
|
id: e.skillStorage && typeof e.skillStorage == "object" && e.skillStorage.id ? e.skillStorage.id : `agent::${n}`
|
|
10319
10338
|
}), ut = () => {
|
|
@@ -10345,7 +10364,7 @@ function Cd(e, n) {
|
|
|
10345
10364
|
decideInvoke: d,
|
|
10346
10365
|
getSnapshot: () => et?.getSnapshot()
|
|
10347
10366
|
} : {}
|
|
10348
|
-
}) : void 0, pt =
|
|
10367
|
+
}) : void 0, pt = Gl([
|
|
10349
10368
|
...nt ? [nt] : [],
|
|
10350
10369
|
tt,
|
|
10351
10370
|
...De ? [C] : [],
|
|
@@ -10361,7 +10380,7 @@ function Cd(e, n) {
|
|
|
10361
10380
|
W = G(), J.agent && J.agent.setTools(W), J.infoTick.value++;
|
|
10362
10381
|
}
|
|
10363
10382
|
})] : [],
|
|
10364
|
-
...Ae ? [
|
|
10383
|
+
...Ae ? [vc(x)] : [],
|
|
10365
10384
|
...ft ? [ft] : [],
|
|
10366
10385
|
...Oe ? [T] : [],
|
|
10367
10386
|
...U ? [w] : [],
|
|
@@ -10378,12 +10397,12 @@ function Cd(e, n) {
|
|
|
10378
10397
|
...rt ? [rt] : [],
|
|
10379
10398
|
...et ? [et] : [],
|
|
10380
10399
|
...e.middleware || [],
|
|
10381
|
-
...se ? [
|
|
10400
|
+
...se ? [Zu(i, {
|
|
10382
10401
|
tokenBudget: e.tokenBudget,
|
|
10383
10402
|
timeBudgetMs: e.timeBudgetMs
|
|
10384
10403
|
}, q)] : [],
|
|
10385
|
-
|
|
10386
|
-
]), mt = e.maxMemoryRounds ??
|
|
10404
|
+
Sd(q, b, B, i)
|
|
10405
|
+
]), mt = e.maxMemoryRounds ?? vd, ht = e.approval?.timeoutMs, gt = ht === void 0 || ht === 0 ? 3e4 : !Number.isFinite(ht) || ht < 0 ? 0 : ht;
|
|
10387
10406
|
function _t(e) {
|
|
10388
10407
|
if (gt) return (t) => {
|
|
10389
10408
|
if (t.type !== "approval_request") return;
|
|
@@ -10416,7 +10435,7 @@ function Cd(e, n) {
|
|
|
10416
10435
|
e.debug && console.warn("[page-agent-sdk][persist] refreshSessions 失败(已吞):", t);
|
|
10417
10436
|
}
|
|
10418
10437
|
}
|
|
10419
|
-
let St =
|
|
10438
|
+
let St = _d(), Ct = /* @__PURE__ */ new Set();
|
|
10420
10439
|
function wt(e) {
|
|
10421
10440
|
let t = new AbortController(), n = () => t.abort();
|
|
10422
10441
|
return e && (e.aborted ? t.abort() : e.addEventListener("abort", n, { once: !0 })), Ct.add(t), {
|
|
@@ -10673,7 +10692,7 @@ function Cd(e, n) {
|
|
|
10673
10692
|
})), e.memory && Ft({ memory: E.get() || (typeof e.memory == "string" ? e.memory : "") }), xt(), Mt = void 0, Nt = !1, J.infoTick.value++, r;
|
|
10674
10693
|
},
|
|
10675
10694
|
resetSession: () => {
|
|
10676
|
-
Tt(), a.resolve("keep_external"), J.sessionId =
|
|
10695
|
+
Tt(), a.resolve("keep_external"), J.sessionId = dl(), b.splice(0, b.length), x.clear?.(), S.reset([]), e.memory || E.reset(""), C.reset(), T.reset(), w.reset(), F && F.importStack([]), J.agent && (J.agent.debugLogs.value = []), s && s.createSession(J.agentId, e.session?.title, J.sessionId).catch((t) => {
|
|
10677
10696
|
e.debug && console.warn("[page-agent-sdk][persist] createSession 失败(已吞):", t);
|
|
10678
10697
|
}), q({
|
|
10679
10698
|
type: "session_restored",
|
|
@@ -10683,7 +10702,7 @@ function Cd(e, n) {
|
|
|
10683
10702
|
},
|
|
10684
10703
|
stream: (e, t, n) => {
|
|
10685
10704
|
if (!J.agent) throw Error("page-agent-sdk: agent 尚未初始化完成,请先 await mount()");
|
|
10686
|
-
x?.setProtectedRefs?.(
|
|
10705
|
+
x?.setProtectedRefs?.(hd(e));
|
|
10687
10706
|
let r = (e) => {
|
|
10688
10707
|
t?.(e), q(e), e.type === "subagent" && (e.kind === "tool_call" || e.kind === "tool_result") && J.infoTick.value++;
|
|
10689
10708
|
};
|
|
@@ -10698,7 +10717,7 @@ function Cd(e, n) {
|
|
|
10698
10717
|
if (J.refCount--, J.refCount <= 0) {
|
|
10699
10718
|
Tt(), he = !0, s && (x.flush?.(), s.flush(), s.dispose()), lt && lt.dispose();
|
|
10700
10719
|
let e = J.mcpClosers.splice(0);
|
|
10701
|
-
e.length && Promise.allSettled(e.map((e) => e())),
|
|
10720
|
+
e.length && Promise.allSettled(e.map((e) => e())), yd.delete(n);
|
|
10702
10721
|
}
|
|
10703
10722
|
},
|
|
10704
10723
|
resolveConflict: a.resolve,
|
|
@@ -10718,14 +10737,14 @@ function Cd(e, n) {
|
|
|
10718
10737
|
},
|
|
10719
10738
|
setLlm(t) {
|
|
10720
10739
|
let n;
|
|
10721
|
-
if (
|
|
10740
|
+
if (el(t)) n = t;
|
|
10722
10741
|
else {
|
|
10723
10742
|
let e = t;
|
|
10724
10743
|
if ((e.provider ?? "openai") === "anthropic") throw Error("[page-agent-sdk][setLlm] 切换到 Anthropic 需传 BaseChatModel 实例(动态 import 无法同步);请先 const { ChatAnthropic } = await import(\"@langchain/anthropic\") 构造实例后传入");
|
|
10725
10744
|
n = p(e);
|
|
10726
10745
|
}
|
|
10727
10746
|
typeof n.bindTools != "function" && e.debug && console.warn("[page-agent-sdk][setLlm] 新模型不支持 bindTools(tool calling 会失效)"), y = t;
|
|
10728
|
-
let r =
|
|
10747
|
+
let r = el(t) ? void 0 : t;
|
|
10729
10748
|
if (f = oi({
|
|
10730
10749
|
model: r?.model ?? t.model ?? t.modelName,
|
|
10731
10750
|
contextWindow: e.contextWindow ?? r?.contextWindow,
|
|
@@ -10768,8 +10787,8 @@ function Cd(e, n) {
|
|
|
10768
10787
|
return {
|
|
10769
10788
|
id: n,
|
|
10770
10789
|
sessionId: J.sessionId,
|
|
10771
|
-
model:
|
|
10772
|
-
systemPrompt: J.agent?.getEffectiveSystemPrompt?.() ?? ce +
|
|
10790
|
+
model: el(y) ? y.model ?? y.modelName : y.model,
|
|
10791
|
+
systemPrompt: J.agent?.getEffectiveSystemPrompt?.() ?? ce + ic(B(), e.schemaHint),
|
|
10773
10792
|
tools: (J.agent?.allTools ?? W).map((e) => ({
|
|
10774
10793
|
name: e.name,
|
|
10775
10794
|
description: e.description,
|
|
@@ -10810,7 +10829,7 @@ function Cd(e, n) {
|
|
|
10810
10829
|
spans: J.agent.spans.value,
|
|
10811
10830
|
metrics: li(J.agent.spans.value)
|
|
10812
10831
|
} : void 0,
|
|
10813
|
-
actions:
|
|
10832
|
+
actions: ed(e.actions ?? {}),
|
|
10814
10833
|
subagent: {
|
|
10815
10834
|
enabled: !!Ge,
|
|
10816
10835
|
maxDepth: e.subagent?.maxDepth ?? 1,
|
|
@@ -10860,11 +10879,11 @@ function Cd(e, n) {
|
|
|
10860
10879
|
return U ? w.getFocuses() : [];
|
|
10861
10880
|
},
|
|
10862
10881
|
setFocus(t) {
|
|
10863
|
-
let n =
|
|
10882
|
+
let n = Cd(t, "setFocus", U, () => B()?.schema, e.debug);
|
|
10864
10883
|
return n.ok ? (w.setFocus(t), J.infoTick.value++, { ok: !0 }) : n;
|
|
10865
10884
|
},
|
|
10866
10885
|
addFocus(t) {
|
|
10867
|
-
let n =
|
|
10886
|
+
let n = Cd(t, "addFocus", U, () => B()?.schema, e.debug);
|
|
10868
10887
|
return n.ok ? w.getFocuses().length >= 8 ? (e.debug && console.warn("[page-agent-sdk][focus] addFocus 拒绝:焦点数已达上限 8(augmentPrompt 注入每焦点子树 schema,过多致 system prompt 超预算)"), {
|
|
10869
10888
|
ok: !1,
|
|
10870
10889
|
error: "焦点数上限 8(避免 system prompt 撑爆)"
|
|
@@ -10908,14 +10927,14 @@ function Cd(e, n) {
|
|
|
10908
10927
|
}
|
|
10909
10928
|
function Ot(e) {
|
|
10910
10929
|
let t = {};
|
|
10911
|
-
for (let n of
|
|
10930
|
+
for (let n of hd(e)) {
|
|
10912
10931
|
let e = x.files[n];
|
|
10913
10932
|
e && (t[n] = e.content);
|
|
10914
10933
|
}
|
|
10915
10934
|
return t;
|
|
10916
10935
|
}
|
|
10917
10936
|
function kt() {
|
|
10918
|
-
let e =
|
|
10937
|
+
let e = gd(x.files, hd(b));
|
|
10919
10938
|
for (let t of e) delete x.files[t];
|
|
10920
10939
|
}
|
|
10921
10940
|
function jt() {
|
|
@@ -10979,7 +10998,7 @@ function Cd(e, n) {
|
|
|
10979
10998
|
Ft({ focus: e.length ? e : null });
|
|
10980
10999
|
}
|
|
10981
11000
|
se && F && (Ft({ checkpoints: F.exportStack() }), Ft({ usage: i }));
|
|
10982
|
-
let t =
|
|
11001
|
+
let t = $c(b);
|
|
10983
11002
|
if (t && t !== Mt && (Mt = t, It(J.sessionId, t)), e.autoTitle !== !1 && u && !Nt && b.some((e) => e.role === "user") && b.some((e) => e.role === "assistant")) {
|
|
10984
11003
|
Nt = !0;
|
|
10985
11004
|
let e = J.sessionId;
|
|
@@ -11027,7 +11046,7 @@ function Cd(e, n) {
|
|
|
11027
11046
|
})) : console.warn(`[page-agent-sdk][mcp] server ${a} 连接失败:`, t.reason);
|
|
11028
11047
|
}), me.length && (W = G(), J.agent && J.agent.setTools(W), J.infoTick.value++), e.debug && console.log(`[page-agent-sdk][mcp] 注入 ${me.length} 个工具,${J.mcpServers.length} 个 server`);
|
|
11029
11048
|
})();
|
|
11030
|
-
let t =
|
|
11049
|
+
let t = el(e.llm) ? e.llm : await m(e.llm);
|
|
11031
11050
|
J.agent = Wi({
|
|
11032
11051
|
llm: t,
|
|
11033
11052
|
systemPrompt: ce,
|
|
@@ -11059,12 +11078,12 @@ function Cd(e, n) {
|
|
|
11059
11078
|
});
|
|
11060
11079
|
})(), J;
|
|
11061
11080
|
}
|
|
11062
|
-
function
|
|
11063
|
-
let n = e.id ??
|
|
11081
|
+
function Td(e, t) {
|
|
11082
|
+
let n = e.id ?? dl();
|
|
11064
11083
|
e.id || console.warn(`[page-agent-sdk] 未传 options.id,已生成随机 id "${n}"。刷新后持久化数据无法恢复,请传稳定 id。`);
|
|
11065
|
-
let r = e.streaming ?? !0, i = e.ui ?? "default", a, o = e.shareContext ?
|
|
11066
|
-
o ? a = o : (a =
|
|
11067
|
-
let s = null, c =
|
|
11084
|
+
let r = e.streaming ?? !0, i = e.ui ?? "default", a, o = e.shareContext ? yd.get(n) : void 0;
|
|
11085
|
+
o ? a = o : (a = wd(e, n), e.shareContext && yd.set(n, a)), a.refCount++;
|
|
11086
|
+
let s = null, c = Ll(e), l = null, u = null;
|
|
11068
11087
|
async function d(n) {
|
|
11069
11088
|
if (await a.initDone, s) {
|
|
11070
11089
|
s.show();
|
|
@@ -11087,6 +11106,7 @@ function wd(e, t) {
|
|
|
11087
11106
|
el: m,
|
|
11088
11107
|
core: a,
|
|
11089
11108
|
dialogCfg: c,
|
|
11109
|
+
i18n: e.i18n,
|
|
11090
11110
|
streaming: r,
|
|
11091
11111
|
runSerial: a.runSerial,
|
|
11092
11112
|
hide: p,
|
|
@@ -11235,12 +11255,12 @@ function wd(e, t) {
|
|
|
11235
11255
|
},
|
|
11236
11256
|
vfsWrite: (e, t) => {
|
|
11237
11257
|
let n = typeof t == "string" ? t : JSON.stringify(t);
|
|
11238
|
-
a.vfsStore.files[
|
|
11258
|
+
a.vfsStore.files[pc(e)] = {
|
|
11239
11259
|
content: n,
|
|
11240
11260
|
updatedAt: Date.now()
|
|
11241
11261
|
};
|
|
11242
11262
|
},
|
|
11243
|
-
vfsRead: (e) => a.vfsStore.files[
|
|
11263
|
+
vfsRead: (e) => a.vfsStore.files[pc(e)]?.content,
|
|
11244
11264
|
createResource: (e, t) => {
|
|
11245
11265
|
let n = a.dataOpsController;
|
|
11246
11266
|
if (!n?.createResource) throw Error("[page-agent-sdk] createResource 不可用:需配 data.resources + vfsStore(capabilities.vfs 默认开)");
|
|
@@ -11279,7 +11299,7 @@ function wd(e, t) {
|
|
|
11279
11299
|
}
|
|
11280
11300
|
//#endregion
|
|
11281
11301
|
//#region src/core/sdk/ragSubagent.ts
|
|
11282
|
-
function
|
|
11302
|
+
function Ed(e, t, n, r, i) {
|
|
11283
11303
|
let a = [];
|
|
11284
11304
|
e && a.push("vfs_grep + vfs_read(搜预注入文档)"), t && a.push(`${r}(语义检索)`), n && a.push(`${i}(按 source 加载)`), a.push("fetch_document(公网 URL)");
|
|
11285
11305
|
let o = [];
|
|
@@ -11294,7 +11314,7 @@ function Td(e, t, n, r, i) {
|
|
|
11294
11314
|
|
|
11295
11315
|
你是只读检索角色,不要尝试修改任何数据。不要尝试上面未列出的工具。`;
|
|
11296
11316
|
}
|
|
11297
|
-
function
|
|
11317
|
+
function Dd(e, t, n, r, i) {
|
|
11298
11318
|
let a = [], o = [];
|
|
11299
11319
|
return e && (a.push("- vfs_grep / vfs_read:搜集成方预注入 vfs 的文档(组件文档 / UI 规范)—— 快、静态,先查"), o.push("- 静态文档(组件库文档 / UI 规范):vfs_grep")), t && (a.push(`- ${r}:语义检索(retriever 向量库)—— 模糊匹配,关键词不确定 / 语义相似时用`), o.push(`- 语义相似(「瀑布流组件」「倒计时」「拼团」):${r}`)), n && (a.push(`- ${i}:按 source 精确加载(已知文档 id / URL / key)—— 精确取特定文档`), o.push(`- 已知文档 id / URL:${i}`)), a.push("- fetch_document:公网 URL —— 查公开资料"), o.push("- 公开 URL(设计规范网站 / 第三方文档):fetch_document"), `# 知识检索策略(RAG)
|
|
11300
11320
|
|
|
@@ -11311,12 +11331,12 @@ ${a.join("\n")}
|
|
|
11311
11331
|
## 何时用何源
|
|
11312
11332
|
${o.join("\n")}`;
|
|
11313
11333
|
}
|
|
11314
|
-
var
|
|
11334
|
+
var Od = {
|
|
11315
11335
|
name: "rag-search",
|
|
11316
11336
|
description: "多源知识检索策略:vfs 预注入文档 → 语义检索 → 指定文档加载 → 公网;综合结构化结论 + 溯源",
|
|
11317
|
-
getContent: () =>
|
|
11337
|
+
getContent: () => Dd(!0, !0, !0, "search_docs", "load_doc")
|
|
11318
11338
|
};
|
|
11319
|
-
function
|
|
11339
|
+
function kd(e, n, i) {
|
|
11320
11340
|
return r(async ({ query: e, topK: t }) => {
|
|
11321
11341
|
try {
|
|
11322
11342
|
let r = await n(e, { topK: t ?? i });
|
|
@@ -11333,7 +11353,7 @@ function Od(e, n, i) {
|
|
|
11333
11353
|
})
|
|
11334
11354
|
});
|
|
11335
11355
|
}
|
|
11336
|
-
function
|
|
11356
|
+
function Ad(e, n) {
|
|
11337
11357
|
return r(async ({ source: e }) => {
|
|
11338
11358
|
try {
|
|
11339
11359
|
let t = await n(e), r = Array.isArray(t) ? t : [t];
|
|
@@ -11347,19 +11367,19 @@ function kd(e, n) {
|
|
|
11347
11367
|
schema: t.object({ source: t.string().describe("文档标识(id/URL/key)") })
|
|
11348
11368
|
});
|
|
11349
11369
|
}
|
|
11350
|
-
function
|
|
11370
|
+
function jd(e) {
|
|
11351
11371
|
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;
|
|
11352
11372
|
if (!t && !n && r === !1) throw Error("[page-agent-sdk][createRagSubagent] 至少配一种知识源:retriever / loader / useVfs(true)");
|
|
11353
11373
|
let p = [];
|
|
11354
|
-
t && p.push(
|
|
11374
|
+
t && p.push(kd(s, t, o)), n && p.push(Ad(c, n)), f && p.push(...f);
|
|
11355
11375
|
let m = r ? [
|
|
11356
11376
|
"vfs_grep",
|
|
11357
11377
|
"vfs_read",
|
|
11358
11378
|
"vfs_json_read"
|
|
11359
|
-
] : void 0, h =
|
|
11379
|
+
] : void 0, h = Ed(r, !!t, !!n, s, c), g = {
|
|
11360
11380
|
name: "rag-search",
|
|
11361
|
-
description:
|
|
11362
|
-
getContent: () =>
|
|
11381
|
+
description: Od.description,
|
|
11382
|
+
getContent: () => Dd(r, !!t, !!n, s, c)
|
|
11363
11383
|
};
|
|
11364
11384
|
return {
|
|
11365
11385
|
id: i,
|
|
@@ -11374,7 +11394,7 @@ function Ad(e) {
|
|
|
11374
11394
|
}
|
|
11375
11395
|
//#endregion
|
|
11376
11396
|
//#region src/core/utils/clipboard.ts
|
|
11377
|
-
async function
|
|
11397
|
+
async function Md(e) {
|
|
11378
11398
|
try {
|
|
11379
11399
|
let t = globalThis.navigator?.clipboard;
|
|
11380
11400
|
if (t && typeof t.writeText == "function") return await t.writeText(e), !0;
|
|
@@ -11392,8 +11412,8 @@ async function jd(e) {
|
|
|
11392
11412
|
}
|
|
11393
11413
|
//#endregion
|
|
11394
11414
|
//#region src/core/composables/useChat.ts
|
|
11395
|
-
var
|
|
11396
|
-
function
|
|
11415
|
+
var Nd = 4e3;
|
|
11416
|
+
function Pd(e = {}) {
|
|
11397
11417
|
let { fetchResponse: t, fetchStream: n, onPersist: r, onClear: i, onQueuedCleared: a } = e, o = /* @__PURE__ */ vt({
|
|
11398
11418
|
messages: e.messages ?? [],
|
|
11399
11419
|
loading: !1,
|
|
@@ -11462,7 +11482,7 @@ function Nd(e = {}) {
|
|
|
11462
11482
|
let t = e.delta || "";
|
|
11463
11483
|
n.subReasonFull = (n.subReasonFull || "") + t;
|
|
11464
11484
|
let r = (n.subReason || "") + t;
|
|
11465
|
-
n.subReason = r.length >
|
|
11485
|
+
n.subReason = r.length > Nd ? r.slice(-4e3) : r;
|
|
11466
11486
|
break;
|
|
11467
11487
|
}
|
|
11468
11488
|
n.children ||= [];
|
|
@@ -11591,7 +11611,7 @@ function Nd(e = {}) {
|
|
|
11591
11611
|
}
|
|
11592
11612
|
//#endregion
|
|
11593
11613
|
//#region src/core/components/icons.ts
|
|
11594
|
-
var
|
|
11614
|
+
var Fd = {
|
|
11595
11615
|
header: "🤖",
|
|
11596
11616
|
subagent: "🤖",
|
|
11597
11617
|
subagentProgress: "🧬",
|
|
@@ -11602,10 +11622,10 @@ var Pd = {
|
|
|
11602
11622
|
recommend: "💡",
|
|
11603
11623
|
conflict: "⚠️"
|
|
11604
11624
|
};
|
|
11605
|
-
function
|
|
11606
|
-
let t = { ...
|
|
11625
|
+
function Id(e) {
|
|
11626
|
+
let t = { ...Fd };
|
|
11607
11627
|
if (!e) return t;
|
|
11608
|
-
let n = Object.keys(
|
|
11628
|
+
let n = Object.keys(Fd);
|
|
11609
11629
|
for (let r of n) {
|
|
11610
11630
|
let n = e[r];
|
|
11611
11631
|
typeof n == "string" && (t[r] = n);
|
|
@@ -11614,7 +11634,7 @@ function Fd(e) {
|
|
|
11614
11634
|
}
|
|
11615
11635
|
//#endregion
|
|
11616
11636
|
//#region src/core/components/messages.ts
|
|
11617
|
-
var
|
|
11637
|
+
var Ld = {
|
|
11618
11638
|
defaultTitle: "AI 助手",
|
|
11619
11639
|
inputPlaceholder: "输入消息,Enter 发送...",
|
|
11620
11640
|
newSession: "新建会话",
|
|
@@ -11696,9 +11716,146 @@ var Id = {
|
|
|
11696
11716
|
exitFocusTitle: "退出精修",
|
|
11697
11717
|
focusPathPlaceholder: "jsonPath,如 components.3",
|
|
11698
11718
|
focusLabelPlaceholder: "标签(可选)",
|
|
11699
|
-
focusSubmit: "聚焦"
|
|
11700
|
-
|
|
11701
|
-
"
|
|
11719
|
+
focusSubmit: "聚焦",
|
|
11720
|
+
debugTabLogs: "日志",
|
|
11721
|
+
debugTabFlow: "流程",
|
|
11722
|
+
debugTabContext: "上下文",
|
|
11723
|
+
debugTabSubagent: "子 agent",
|
|
11724
|
+
debugTabInfo: "Agent 信息",
|
|
11725
|
+
debugClearLogs: "清空日志",
|
|
11726
|
+
debugTypeContext: "上下文",
|
|
11727
|
+
debugTypeLlmRequest: "LLM请求",
|
|
11728
|
+
debugTypeLlmResponse: "LLM响应",
|
|
11729
|
+
debugTypeToolCall: "工具调用",
|
|
11730
|
+
debugTypeToolResult: "工具结果",
|
|
11731
|
+
debugTypeError: "错误",
|
|
11732
|
+
debugTypeMiddleware: "中间件",
|
|
11733
|
+
debugFilterAll: "全部",
|
|
11734
|
+
debugFlowPrep: "准备 / 其他",
|
|
11735
|
+
debugLogsEmpty: "暂无日志,发送消息后这里会显示 Agent 的完整上下文、工具调用等信息",
|
|
11736
|
+
debugFlowEmpty: "暂无日志,发送消息后这里按轮次展示执行流程",
|
|
11737
|
+
debugNoInfo: "暂无信息",
|
|
11738
|
+
debugCardView: "🗂 卡片视图",
|
|
11739
|
+
debugRequestBody: "📋 请求体",
|
|
11740
|
+
debugViewRawJson: "查看原始 JSON",
|
|
11741
|
+
debugCollapseRawJson: "收起原始 JSON",
|
|
11742
|
+
debugModel: "模型",
|
|
11743
|
+
debugTemperature: "温度",
|
|
11744
|
+
debugMessageCount: "消息数",
|
|
11745
|
+
debugToolsLabel: "工具",
|
|
11746
|
+
debugContextMessages: "上下文消息",
|
|
11747
|
+
debugRoundPrefix: "第 ",
|
|
11748
|
+
debugRoundSuffix: " 轮",
|
|
11749
|
+
debugMsgCountSuffix: " 条消息",
|
|
11750
|
+
debugToolCountSuffix: " 工具",
|
|
11751
|
+
debugToolCallsSuffix: " 个工具调用",
|
|
11752
|
+
debugResultSuffix: " 结果",
|
|
11753
|
+
debugTodoPending: "待办",
|
|
11754
|
+
debugTodoInProgress: "进行中",
|
|
11755
|
+
debugTodoCompleted: "完成",
|
|
11756
|
+
debugSubRunning: "运行中",
|
|
11757
|
+
debugSubDone: "完成",
|
|
11758
|
+
debugSubError: "错误",
|
|
11759
|
+
debugLocksTitle: "组件锁",
|
|
11760
|
+
debugSubagentEmpty: "尚未委派子 agent。主 agent 调用 use_<id> 或 spawn_agent 后,这里展示运行状态与委派历史。",
|
|
11761
|
+
debugSubRunningTitle: "运行中",
|
|
11762
|
+
debugSubHistoryTitle: "历史",
|
|
11763
|
+
debugStepsBtn: "步骤",
|
|
11764
|
+
debugStepsCountSuffix: " 步",
|
|
11765
|
+
debugTraceEmpty: "未开启 tracing(capabilities.tracing:true)或暂无 trace。跑一轮 agent 后刷新。",
|
|
11766
|
+
debugMetricRounds: "轮次",
|
|
11767
|
+
debugMetricTotal: "总耗时",
|
|
11768
|
+
debugMetricAvg: "平均/轮",
|
|
11769
|
+
debugMetricTools: "工具",
|
|
11770
|
+
debugMetricCompressions: "压缩",
|
|
11771
|
+
debugCtxEmpty: "未开启 contextInspector(默认开)或暂无快照。跑一轮 agent 后切回刷新。",
|
|
11772
|
+
debugCtxOccupancy: "占用",
|
|
11773
|
+
debugCtxThreshold: "压缩阈值",
|
|
11774
|
+
debugCtxTokens: "估算",
|
|
11775
|
+
debugCtxWindow: "窗口",
|
|
11776
|
+
debugCtxThresholdPct: "阈值",
|
|
11777
|
+
debugCtxCategories: "分类构成(近似)",
|
|
11778
|
+
debugCtxLastCompression: "最近压缩",
|
|
11779
|
+
debugCtxSummarized: "摘要",
|
|
11780
|
+
debugCtxRoundsSuffix: " 轮",
|
|
11781
|
+
debugCtxRecalled: "召回",
|
|
11782
|
+
debugCtxAgentDecision: "agent 决策:",
|
|
11783
|
+
debugInfoBasic: "基本信息",
|
|
11784
|
+
debugToolCount: "工具数",
|
|
11785
|
+
debugMiddleware: "中间件",
|
|
11786
|
+
debugMiddlewareStack: "中间件栈",
|
|
11787
|
+
debugSkillsTitle: "技能",
|
|
11788
|
+
debugSkillsHint: "点击展开查看全文",
|
|
11789
|
+
debugLoading: "加载中…",
|
|
11790
|
+
debugDataTitle: "可操作数据",
|
|
11791
|
+
debugDataFallback: "主数据对象",
|
|
11792
|
+
debugSchemaPrefix: "schema: ",
|
|
11793
|
+
debugSchemaDeclared: "已声明",
|
|
11794
|
+
debugSchemaMissing: "未声明",
|
|
11795
|
+
debugSubagentTitle: "子 Agent",
|
|
11796
|
+
debugEnabled: "启用",
|
|
11797
|
+
debugYes: "是",
|
|
11798
|
+
debugNo: "否",
|
|
11799
|
+
debugMaxDepth: "最大递归",
|
|
11800
|
+
debugMaxParallel: "并行上限",
|
|
11801
|
+
debugExtraTools: "额外工具",
|
|
11802
|
+
debugDefaultReadonly: "默认只读",
|
|
11803
|
+
debugVerifyTitle: "Verify 自检",
|
|
11804
|
+
debugMaxAttempts: "自纠上限",
|
|
11805
|
+
debugAdversarial: "对抗验证",
|
|
11806
|
+
debugOn: "开启",
|
|
11807
|
+
debugOff: "关闭",
|
|
11808
|
+
debugAdversarialModel: "对抗模型",
|
|
11809
|
+
debugSameAsMain: "(同主)",
|
|
11810
|
+
debugTodosTitle: "任务清单",
|
|
11811
|
+
debugMemoryTitle: "持久指令 (memory)",
|
|
11812
|
+
debugLastCompTitle: "上轮压缩",
|
|
11813
|
+
debugTriggered: "触发",
|
|
11814
|
+
debugNotTriggered: "✗(未达阈值)",
|
|
11815
|
+
debugRoundsSummarized: "摘要轮次",
|
|
11816
|
+
debugCountSuffix: " 条",
|
|
11817
|
+
debugStrategy: "策略",
|
|
11818
|
+
debugDecision: "压缩决策",
|
|
11819
|
+
debugSummaryMode: "摘要",
|
|
11820
|
+
debugSkillNoReader: "当前 SDK 未注入 getSkillContent,无法查看 skill 全文",
|
|
11821
|
+
debugSkillEmpty: "skill 无内容或读取失败",
|
|
11822
|
+
skillPanelTitle: "🧩 Skill 管理",
|
|
11823
|
+
skillEditingPrefix: "编辑 Skill: ",
|
|
11824
|
+
skillCreateNew: "创建新 Skill",
|
|
11825
|
+
skillCancelEdit: "取消编辑",
|
|
11826
|
+
skillNameLabel: "名称",
|
|
11827
|
+
skillNamePlaceholder: "如:my-writer",
|
|
11828
|
+
skillDescLabel: "描述",
|
|
11829
|
+
skillDescPlaceholder: "一句话说明用途与触发时机",
|
|
11830
|
+
skillContentLabel: "内容",
|
|
11831
|
+
skillContentPlaceholder: "skill 全文指令(支持 Markdown)",
|
|
11832
|
+
skillSave: "保存修改",
|
|
11833
|
+
skillAdd: "添加 Skill",
|
|
11834
|
+
skillCreatedTitle: "已创建 Skill",
|
|
11835
|
+
skillEmpty: "暂无用户创建的 skill",
|
|
11836
|
+
skillEditBtn: "编辑",
|
|
11837
|
+
skillEditTitle: "加载到表单编辑",
|
|
11838
|
+
skillDeleteBtn: "删除",
|
|
11839
|
+
skillDeleteTitle: "删除该用户 skill",
|
|
11840
|
+
skillErrName: "skill 名不能为空",
|
|
11841
|
+
skillErrDesc: "描述不能为空",
|
|
11842
|
+
skillErrContent: "内容不能为空",
|
|
11843
|
+
skillDupWarnPrefix: "已存在同名用户 skill \"",
|
|
11844
|
+
skillDupWarnSuffix: "\",将覆盖",
|
|
11845
|
+
skillHintA: "创建/编辑的 skill 会自动加入 agent(下轮 system prompt 索引可见),agent 经",
|
|
11846
|
+
skillHintB: "按需加载全文;持久化由独立 SkillStore 管理(默认 indexedDB,与 storage 选项分离),跨刷新自动恢复;可经",
|
|
11847
|
+
skillHintC: "跨页面复用。",
|
|
11848
|
+
codeCopyTitle: "复制代码",
|
|
11849
|
+
codeOpenTitle: "新窗口打开",
|
|
11850
|
+
codePreviewTitlePrefix: "代码预览 · ",
|
|
11851
|
+
codePreviewTab: "预览",
|
|
11852
|
+
codeSourceTab: "源码",
|
|
11853
|
+
codeDemoTitle: "CSS 预览",
|
|
11854
|
+
codeDemoText: "这是一段示例文字,用于展示 CSS 效果。",
|
|
11855
|
+
codeDemoButton: "按钮",
|
|
11856
|
+
codeDemoInput: "输入框"
|
|
11857
|
+
}, Rd = {
|
|
11858
|
+
"zh-CN": Ld,
|
|
11702
11859
|
"en-US": {
|
|
11703
11860
|
defaultTitle: "AI Assistant",
|
|
11704
11861
|
inputPlaceholder: "Type a message, Enter to send...",
|
|
@@ -11781,13 +11938,150 @@ var Id = {
|
|
|
11781
11938
|
exitFocusTitle: "Exit focus",
|
|
11782
11939
|
focusPathPlaceholder: "jsonPath, e.g. components.3",
|
|
11783
11940
|
focusLabelPlaceholder: "Label (optional)",
|
|
11784
|
-
focusSubmit: "Focus"
|
|
11941
|
+
focusSubmit: "Focus",
|
|
11942
|
+
debugTabLogs: "Logs",
|
|
11943
|
+
debugTabFlow: "Flow",
|
|
11944
|
+
debugTabContext: "Context",
|
|
11945
|
+
debugTabSubagent: "Sub-agents",
|
|
11946
|
+
debugTabInfo: "Agent info",
|
|
11947
|
+
debugClearLogs: "Clear logs",
|
|
11948
|
+
debugTypeContext: "Context",
|
|
11949
|
+
debugTypeLlmRequest: "LLM request",
|
|
11950
|
+
debugTypeLlmResponse: "LLM response",
|
|
11951
|
+
debugTypeToolCall: "Tool call",
|
|
11952
|
+
debugTypeToolResult: "Tool result",
|
|
11953
|
+
debugTypeError: "Error",
|
|
11954
|
+
debugTypeMiddleware: "Middleware",
|
|
11955
|
+
debugFilterAll: "All",
|
|
11956
|
+
debugFlowPrep: "Preparation / other",
|
|
11957
|
+
debugLogsEmpty: "No logs yet. After you send a message, the full agent context and tool calls appear here.",
|
|
11958
|
+
debugFlowEmpty: "No logs yet. After you send a message, the execution flow appears here by round.",
|
|
11959
|
+
debugNoInfo: "No info",
|
|
11960
|
+
debugCardView: "🗂 Cards",
|
|
11961
|
+
debugRequestBody: "📋 Request body",
|
|
11962
|
+
debugViewRawJson: "View raw JSON",
|
|
11963
|
+
debugCollapseRawJson: "Collapse raw JSON",
|
|
11964
|
+
debugModel: "Model",
|
|
11965
|
+
debugTemperature: "Temp",
|
|
11966
|
+
debugMessageCount: "Messages",
|
|
11967
|
+
debugToolsLabel: "Tools",
|
|
11968
|
+
debugContextMessages: "Context messages",
|
|
11969
|
+
debugRoundPrefix: "Round ",
|
|
11970
|
+
debugRoundSuffix: "",
|
|
11971
|
+
debugMsgCountSuffix: " messages",
|
|
11972
|
+
debugToolCountSuffix: " tools",
|
|
11973
|
+
debugToolCallsSuffix: " tool calls",
|
|
11974
|
+
debugResultSuffix: " result",
|
|
11975
|
+
debugTodoPending: "Pending",
|
|
11976
|
+
debugTodoInProgress: "In progress",
|
|
11977
|
+
debugTodoCompleted: "Done",
|
|
11978
|
+
debugSubRunning: "Running",
|
|
11979
|
+
debugSubDone: "Done",
|
|
11980
|
+
debugSubError: "Error",
|
|
11981
|
+
debugLocksTitle: "Component locks",
|
|
11982
|
+
debugSubagentEmpty: "No sub-agents yet. Once the main agent calls use_<id> or spawn_agent, run status and delegation history appear here.",
|
|
11983
|
+
debugSubRunningTitle: "Running",
|
|
11984
|
+
debugSubHistoryTitle: "History",
|
|
11985
|
+
debugStepsBtn: "Steps",
|
|
11986
|
+
debugStepsCountSuffix: " steps",
|
|
11987
|
+
debugTraceEmpty: "Tracing not enabled (capabilities.tracing:true) or no trace yet. Run a round then refresh.",
|
|
11988
|
+
debugMetricRounds: "Rounds",
|
|
11989
|
+
debugMetricTotal: "Total",
|
|
11990
|
+
debugMetricAvg: "Avg/round",
|
|
11991
|
+
debugMetricTools: "Tools",
|
|
11992
|
+
debugMetricCompressions: "Compressions",
|
|
11993
|
+
debugCtxEmpty: "contextInspector not enabled (on by default) or no snapshot yet. Run a round then switch back.",
|
|
11994
|
+
debugCtxOccupancy: "Occupancy",
|
|
11995
|
+
debugCtxThreshold: "compress threshold",
|
|
11996
|
+
debugCtxTokens: "est.",
|
|
11997
|
+
debugCtxWindow: "window",
|
|
11998
|
+
debugCtxThresholdPct: "threshold",
|
|
11999
|
+
debugCtxCategories: "Categories (approx.)",
|
|
12000
|
+
debugCtxLastCompression: "Last compression",
|
|
12001
|
+
debugCtxSummarized: "summarized",
|
|
12002
|
+
debugCtxRoundsSuffix: " rounds",
|
|
12003
|
+
debugCtxRecalled: "recalled",
|
|
12004
|
+
debugCtxAgentDecision: "agent decision: ",
|
|
12005
|
+
debugInfoBasic: "Basics",
|
|
12006
|
+
debugToolCount: "Tools",
|
|
12007
|
+
debugMiddleware: "Middleware",
|
|
12008
|
+
debugMiddlewareStack: "Middleware stack",
|
|
12009
|
+
debugSkillsTitle: "Skills",
|
|
12010
|
+
debugSkillsHint: "click to expand",
|
|
12011
|
+
debugLoading: "Loading…",
|
|
12012
|
+
debugDataTitle: "Operable data",
|
|
12013
|
+
debugDataFallback: "main data object",
|
|
12014
|
+
debugSchemaPrefix: "schema: ",
|
|
12015
|
+
debugSchemaDeclared: "declared",
|
|
12016
|
+
debugSchemaMissing: "not declared",
|
|
12017
|
+
debugSubagentTitle: "Sub-agents",
|
|
12018
|
+
debugEnabled: "Enabled",
|
|
12019
|
+
debugYes: "Yes",
|
|
12020
|
+
debugNo: "No",
|
|
12021
|
+
debugMaxDepth: "Max depth",
|
|
12022
|
+
debugMaxParallel: "Max parallel",
|
|
12023
|
+
debugExtraTools: "Extra tools",
|
|
12024
|
+
debugDefaultReadonly: "read-only by default",
|
|
12025
|
+
debugVerifyTitle: "Verify self-check",
|
|
12026
|
+
debugMaxAttempts: "Max attempts",
|
|
12027
|
+
debugAdversarial: "Adversarial",
|
|
12028
|
+
debugOn: "On",
|
|
12029
|
+
debugOff: "Off",
|
|
12030
|
+
debugAdversarialModel: "Adversarial model",
|
|
12031
|
+
debugSameAsMain: " (same as main)",
|
|
12032
|
+
debugTodosTitle: "Todos",
|
|
12033
|
+
debugMemoryTitle: "Persistent instructions (memory)",
|
|
12034
|
+
debugLastCompTitle: "Last compression",
|
|
12035
|
+
debugTriggered: "Triggered",
|
|
12036
|
+
debugNotTriggered: "✗ (below threshold)",
|
|
12037
|
+
debugRoundsSummarized: "Rounds summarized",
|
|
12038
|
+
debugCountSuffix: "",
|
|
12039
|
+
debugStrategy: "Strategy",
|
|
12040
|
+
debugDecision: "Decision",
|
|
12041
|
+
debugSummaryMode: "summary",
|
|
12042
|
+
debugSkillNoReader: "getSkillContent is not injected in this SDK build; cannot view skill content",
|
|
12043
|
+
debugSkillEmpty: "skill has no content or the read failed",
|
|
12044
|
+
skillPanelTitle: "🧩 Skills",
|
|
12045
|
+
skillEditingPrefix: "Edit skill: ",
|
|
12046
|
+
skillCreateNew: "Create new skill",
|
|
12047
|
+
skillCancelEdit: "Cancel editing",
|
|
12048
|
+
skillNameLabel: "Name",
|
|
12049
|
+
skillNamePlaceholder: "e.g. my-writer",
|
|
12050
|
+
skillDescLabel: "Description",
|
|
12051
|
+
skillDescPlaceholder: "One line: what it does and when to trigger",
|
|
12052
|
+
skillContentLabel: "Content",
|
|
12053
|
+
skillContentPlaceholder: "Full skill instructions (Markdown supported)",
|
|
12054
|
+
skillSave: "Save changes",
|
|
12055
|
+
skillAdd: "Add skill",
|
|
12056
|
+
skillCreatedTitle: "Created skills",
|
|
12057
|
+
skillEmpty: "No user-created skills yet",
|
|
12058
|
+
skillEditBtn: "Edit",
|
|
12059
|
+
skillEditTitle: "Load into the form to edit",
|
|
12060
|
+
skillDeleteBtn: "Delete",
|
|
12061
|
+
skillDeleteTitle: "Delete this user skill",
|
|
12062
|
+
skillErrName: "Skill name cannot be empty",
|
|
12063
|
+
skillErrDesc: "Description cannot be empty",
|
|
12064
|
+
skillErrContent: "Content cannot be empty",
|
|
12065
|
+
skillDupWarnPrefix: "User skill \"",
|
|
12066
|
+
skillDupWarnSuffix: "\" already exists and will be overwritten",
|
|
12067
|
+
skillHintA: "Created/edited skills are automatically added to the agent (visible in the next system prompt index); the agent loads the full text via",
|
|
12068
|
+
skillHintB: "on demand. Persistence is handled by a separate SkillStore (indexedDB by default, independent of the storage option) and survives refreshes; share across pages via",
|
|
12069
|
+
skillHintC: "cross-page reuse.",
|
|
12070
|
+
codeCopyTitle: "Copy code",
|
|
12071
|
+
codeOpenTitle: "Open in new tab",
|
|
12072
|
+
codePreviewTitlePrefix: "Code preview · ",
|
|
12073
|
+
codePreviewTab: "Preview",
|
|
12074
|
+
codeSourceTab: "Source",
|
|
12075
|
+
codeDemoTitle: "CSS Preview",
|
|
12076
|
+
codeDemoText: "Sample text to demonstrate the CSS effect.",
|
|
12077
|
+
codeDemoButton: "Button",
|
|
12078
|
+
codeDemoInput: "Input"
|
|
11785
12079
|
}
|
|
11786
12080
|
};
|
|
11787
|
-
function
|
|
12081
|
+
function zd(e = "zh-CN", t) {
|
|
11788
12082
|
let n = {
|
|
11789
|
-
...
|
|
11790
|
-
...
|
|
12083
|
+
...Ld,
|
|
12084
|
+
...Rd[e]
|
|
11791
12085
|
};
|
|
11792
12086
|
if (!t) return n;
|
|
11793
12087
|
let r = { ...n };
|
|
@@ -11799,9 +12093,9 @@ function Rd(e = "zh-CN", t) {
|
|
|
11799
12093
|
}
|
|
11800
12094
|
//#endregion
|
|
11801
12095
|
//#region src/core/composables/chatContext.ts
|
|
11802
|
-
var
|
|
11803
|
-
function
|
|
11804
|
-
let t =
|
|
12096
|
+
var Bd = Symbol("chatContext");
|
|
12097
|
+
function Vd(e = {}) {
|
|
12098
|
+
let t = Pd({
|
|
11805
12099
|
fetchResponse: e.fetchResponse,
|
|
11806
12100
|
fetchStream: e.fetchStream,
|
|
11807
12101
|
messages: e.messages,
|
|
@@ -11821,7 +12115,7 @@ function Bd(e = {}) {
|
|
|
11821
12115
|
}, h = /* @__PURE__ */ At({}), g = (e) => h.value[e] === !0, _ = (e) => {
|
|
11822
12116
|
h.value[e] = !g(e);
|
|
11823
12117
|
}, v = /* @__PURE__ */ At(!1), y = (e) => {
|
|
11824
|
-
|
|
12118
|
+
Md(e).then((e) => {
|
|
11825
12119
|
e && (v.value = !0, setTimeout(() => {
|
|
11826
12120
|
v.value = !1;
|
|
11827
12121
|
}, 1500));
|
|
@@ -11857,7 +12151,7 @@ function Bd(e = {}) {
|
|
|
11857
12151
|
e.onClearFocus?.();
|
|
11858
12152
|
}, j = (t) => {
|
|
11859
12153
|
e.onFocusChipClick?.(t);
|
|
11860
|
-
}, M =
|
|
12154
|
+
}, M = Id(e.icons), te = e.locale ?? "zh-CN";
|
|
11861
12155
|
return {
|
|
11862
12156
|
chat: t,
|
|
11863
12157
|
inputText: o,
|
|
@@ -11889,18 +12183,18 @@ function Bd(e = {}) {
|
|
|
11889
12183
|
focusChipClick: j,
|
|
11890
12184
|
icons: M,
|
|
11891
12185
|
locale: te,
|
|
11892
|
-
messages:
|
|
12186
|
+
messages: zd(te, e.dialogMessages)
|
|
11893
12187
|
};
|
|
11894
12188
|
}
|
|
11895
|
-
function
|
|
11896
|
-
let e = Rn(
|
|
12189
|
+
function Hd() {
|
|
12190
|
+
let e = Rn(Bd);
|
|
11897
12191
|
if (!e) throw Error("useChatContext 必须在 provide(chatContextKey) 的组件子树内调用");
|
|
11898
12192
|
return e;
|
|
11899
12193
|
}
|
|
11900
12194
|
//#endregion
|
|
11901
12195
|
//#region src/core/index.headless.ts
|
|
11902
|
-
function
|
|
11903
|
-
return
|
|
12196
|
+
function Ud(e) {
|
|
12197
|
+
return Td(e);
|
|
11904
12198
|
}
|
|
11905
12199
|
//#endregion
|
|
11906
|
-
export {
|
|
12200
|
+
export { Rl as CAPABILITIES, Vl as CONTEXT_PRESETS, Qc as CompressDecisionSchema, is as DEFAULT_PROMPT_SOFT_CAP, nc as DEFAULT_SYSTEM_PROMPT, yc as HTML_VOID_TAGS, Ao as HUMAN_CONFIRM_TOOL_NAME, ai as MIN_CONTEXT_WINDOW, rs as SOFT_CAP_MIN_WINDOW, Zo as STOP_WORDS, Aa as UNSAFE_KEYS, ed as actionsToInspectInfo, $u as actionsToTools, Qr as agentError, Ys as analyzeContext, Ba as applyPatchToClone, Ua as applyPatchToLive, Zr as asAgentError, ic as buildDataPrompt, ac as buildSystemPrompt, Bd as chatContextKey, Du as commitSetToBind, tc as connectMcp, m as constructLlmFromConfig, p as constructOpenLlmSync, Md as copyText, Wi as createAgent, ko as createApprovalMiddleware, Vd as createChatContext, Ud as createChatSdk, Bo as createCheckpointManager, Vo as createCheckpointMiddleware, ul as createConflictManager, Xs as createContextInspectorMiddleware, Fu as createDataOps, Gc as createHtmlFormatCheck, Jc as createHtmlSubagent, No as createHumanConfirmMiddleware, Mo as createHumanConfirmTool, jl as createMemoryBackend, So as createMemoryMiddleware, u as createProxyLlm, jd as createRagSubagent, ao as createSandboxRunner, Bl as createSdkEvents, _d as createSerialRunner, Fl as createSessionStore, pd as createSkillStore, Es as createSubagentMiddleware, us as createSubagentTracker, ks as createSubagentsMiddleware, sd as createUsageHintsMiddleware, As as createVerifyMiddleware, lc as createVfs, Nl as createWebStorageBackend, Is as createWriteBackCheck, Fa as deepClone, rd as defineDataToolset, so as defineSkill, Yc as defineTool, Pa as deleteByPath, $c as deriveTitle, sa as describeSchemaNode, Oi as detectGarbledToolCall, qa as diffObjects, Vu as domToStructure, Uu as domTools, nd as domToolsStatic, $o as estimateMessageTokens, es as estimateRoundTokens, X as estimateTokens, g as extractReasoningDelta, ba as extractSchemaHint, Zs as extractText, h as extractTextDelta, _ as extractUsage, Lu as fetchDocTools, td as fetchTools, Eu as filterByToolMode, Ka as findStrippedKeys, ca as formatConstraints, qr as formatZodIssues, Z as getByPath, Hu as getDomTool, Ku as getEnvSummary, Ji as getSchemaAtPath, Gi as getSchemaTopKeys, li as getTraceMetrics, $ as hashValue, ha as htmlOrchestratorPrompt, ts as indexSummarize, Yu as inspectEnvTool, Xu as inspectTools, el as isChatModel, yi as isContextLengthError, Ki as isPathAllowed, Cl as isQuotaError, ja as isUnsafePath, tu as jpEval, Yr as jsonParseError, Ra as limitDepth, Ia as maybeParseValue, y as normalizeUsage, ci as offloadPassThroughChars, si as offloadThresholdChars, ma as presets, ta as projectBySchema, ea as projectBySchemaDeep, La as projectFields, ns as recallRounds, la as renderSchemaHint, ua as renderSchemaOverview, pa as renderSchemaShallow, zl as resolveCapabilities, Ul as resolveContextOptions, Ll as resolveDialogConfig, ll as resolveLlm, oi as resolveModelCaps, as as resolvePromptSoftCap, Il as resolveStorage, Ga as restoreInPlace, Wa as restoreLive, Xr as routeError, oo as runHostScript, au as runSandboxedScript, Ma as safeMerge, Gu as safeSerialize, Q as safeStringify, ru as searchJson, id as selectBuiltinTools, Na as setByPath, os as shouldTriggerCompression, ga as systemPromptHelpers, Qo as tokenize, Y as toolError, qi as unwrapSchema, Pd as useChat, Hd as useChatContext, xc as validateHtmlFormat, e as z, Jr as zodError };
|