page-agent-sdk 3.44.1 → 3.44.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/README.zh-CN.md +2 -2
- package/dist/page-agent-sdk.headless.js +468 -455
- package/dist/page-agent-sdk.iife.js +143 -143
- package/dist/page-agent-sdk.js +1891 -1878
- package/dist/page-agent-sdk.legacy.js +10113 -10097
- package/dist/page-agent-sdk.umd.cjs +57 -57
- package/package.json +1 -1
|
@@ -3221,7 +3221,12 @@ function Ka(e, t) {
|
|
|
3221
3221
|
return !(!e.length || !e.some((e) => e.status !== "completed") || /[??]\s*$/.test(t));
|
|
3222
3222
|
}
|
|
3223
3223
|
function qa(e, t) {
|
|
3224
|
-
let n = e.filter((e) => e.status !== "completed"), r = n.map((e) => `#${e.id} [${e.status}] ${e.content.length > 60 ? `${e.content.slice(0, 60)}…` : e.content}`).join("\n"), i = e.filter((e) =>
|
|
3224
|
+
let n = e.filter((e) => e.status !== "completed"), r = n.map((e) => `#${e.id} [${e.status}] ${e.content.length > 60 ? `${e.content.slice(0, 60)}…` : e.content}`).join("\n"), i = e.filter((e) => {
|
|
3225
|
+
if (e.status !== "completed" || e.evidence) return !1;
|
|
3226
|
+
if (!t) return !0;
|
|
3227
|
+
let n = t.get(e.id);
|
|
3228
|
+
return !n || n.status !== "completed" || n.content !== e.content;
|
|
3229
|
+
}), a = i.length ? `\n另有 ${i.length} 项已标记完成但 evidence 为空(${i.map((e) => `#${e.id}`).join("、")}):标记完成时请用 update_todo 附 evidence(本次实际写入的 jsonPath,如 components.2);经委派完成等无主写路径时如实写明完成方式。` : "";
|
|
3225
3230
|
return `⚠️ 任务未完成:待办清单还有 ${n.length} 项未完成:\n${r}\n若这些工作实际已完成,请先用 update_todo 把它们全部标记 completed(或一次 write_todos 整表替换)再给出最终总结;若尚未完成,请继续执行剩余任务。不要中途停止。${a}`;
|
|
3226
3231
|
}
|
|
3227
3232
|
function Ja(e = [], n = {}) {
|
|
@@ -3399,9 +3404,11 @@ function eo(e) {
|
|
|
3399
3404
|
function to(e, t, n) {
|
|
3400
3405
|
let r = Array.from(n ?? []);
|
|
3401
3406
|
return e.filter((e) => {
|
|
3402
|
-
if (e.status !== "completed"
|
|
3403
|
-
let n =
|
|
3404
|
-
|
|
3407
|
+
if (e.status !== "completed") return !1;
|
|
3408
|
+
let n = t?.get(e.id);
|
|
3409
|
+
if (n && n.status === "completed" && n.content === e.content) return !1;
|
|
3410
|
+
let i = Va(e.evidence ?? "");
|
|
3411
|
+
return i.length ? !Ha(i, r) : !1;
|
|
3405
3412
|
});
|
|
3406
3413
|
}
|
|
3407
3414
|
function no(e) {
|
|
@@ -3873,7 +3880,10 @@ function Eo(e) {
|
|
|
3873
3880
|
counts: {},
|
|
3874
3881
|
writePaths: [],
|
|
3875
3882
|
failures: 0
|
|
3876
|
-
}, p = Ya(), m = new Map((U.todos ?? []).map((e) => [e.id,
|
|
3883
|
+
}, p = Ya(), m = new Map((U.todos ?? []).map((e) => [e.id, {
|
|
3884
|
+
status: e.status,
|
|
3885
|
+
content: e.content
|
|
3886
|
+
}])), g = /* @__PURE__ */ new Map(), _ = (e) => {
|
|
3877
3887
|
let t = B.find((t) => t.name === e);
|
|
3878
3888
|
return t && "writeCapable" in t ? typeof t.writeCapable == "function" || t.writeCapable === !0 : wo.has(e);
|
|
3879
3889
|
}, y = 0, S = 0, w = So(ne, C), T = null, E = 0, D = !1;
|
|
@@ -7807,7 +7817,13 @@ function ju(e, t) {
|
|
|
7807
7817
|
}
|
|
7808
7818
|
//#endregion
|
|
7809
7819
|
//#region src/core/tools/dataOps.ts
|
|
7810
|
-
function Mu(e) {
|
|
7820
|
+
function Mu(e, t) {
|
|
7821
|
+
if (!e) return null;
|
|
7822
|
+
let n = (t ? Ao(e, t) : e)?.shape;
|
|
7823
|
+
return n && typeof n == "object" ? Object.keys(n) : null;
|
|
7824
|
+
}
|
|
7825
|
+
var Nu = (e) => e && e.length ? `(可用字段:${e.slice(0, 12).join(", ")}${e.length > 12 ? " …" : ""})` : "", Pu = (e) => /[.[]/.test(e) ? e.replace(/[.[][^.[]*$/, "") : "";
|
|
7826
|
+
function Fu(e) {
|
|
7811
7827
|
let { schema: t, allowKeys: n, value: r, bindRef: i } = e, a = [];
|
|
7812
7828
|
if (n) {
|
|
7813
7829
|
if (typeof r != "object" || !r || Array.isArray(r)) return {
|
|
@@ -7832,7 +7848,7 @@ function Mu(e) {
|
|
|
7832
7848
|
error: X({
|
|
7833
7849
|
code: "SCHEMA_STRIP",
|
|
7834
7850
|
message: `字段 ${r} 不在 schema 声明内,写入被拒绝(防静默丢失)`,
|
|
7835
|
-
hint:
|
|
7851
|
+
hint: `该数据结构不支持这些字段;请只用 schema 声明的字段,或在 data.schema 中声明后重试${Nu(Mu(t, ""))}`,
|
|
7836
7852
|
path: r,
|
|
7837
7853
|
details: { stripped: [r] }
|
|
7838
7854
|
}),
|
|
@@ -7852,7 +7868,7 @@ function Mu(e) {
|
|
|
7852
7868
|
error: X({
|
|
7853
7869
|
code: "SCHEMA_STRIP",
|
|
7854
7870
|
message: `字段 ${c.join(", ")} 不在 schema 声明内,写入被拒绝(防静默丢失)`,
|
|
7855
|
-
hint:
|
|
7871
|
+
hint: `该数据结构不支持这些字段;请只用 schema 声明的字段,或在 data.schema 中声明后重试${Nu(Mu(t, Pu(String(c[0]))))}`,
|
|
7856
7872
|
path: c[0],
|
|
7857
7873
|
details: { stripped: c }
|
|
7858
7874
|
}),
|
|
@@ -7891,7 +7907,7 @@ function Mu(e) {
|
|
|
7891
7907
|
notices: a
|
|
7892
7908
|
};
|
|
7893
7909
|
}
|
|
7894
|
-
function
|
|
7910
|
+
function Iu(e) {
|
|
7895
7911
|
let { schema: t, bindRef: n, clone: r, patches: i, schemaErrorMode: a = "zod", appendCaptures: o, moveCaptures: s } = e, c = [], l = (t) => {
|
|
7896
7912
|
let n = Q(r, t);
|
|
7897
7913
|
return n === void 0 ? e.valueAt?.(t) : n;
|
|
@@ -8158,7 +8174,7 @@ function Nu(e) {
|
|
|
8158
8174
|
notices: c
|
|
8159
8175
|
};
|
|
8160
8176
|
}
|
|
8161
|
-
function
|
|
8177
|
+
function Lu(e) {
|
|
8162
8178
|
let { bindRef: t, schema: n, allowKeys: r, snapshots: i, maxSnapshots: a, audit: o, dryRun: s, op: c = "set", protectedCtx: l, snapshotLabel: u } = e, d = e.value, f = e.internalAfterWrite ? Os(t) : null;
|
|
8163
8179
|
if (l) {
|
|
8164
8180
|
let e = ku({
|
|
@@ -8171,7 +8187,7 @@ function Pu(e) {
|
|
|
8171
8187
|
};
|
|
8172
8188
|
d = e.value;
|
|
8173
8189
|
}
|
|
8174
|
-
let p =
|
|
8190
|
+
let p = Fu({
|
|
8175
8191
|
schema: n,
|
|
8176
8192
|
allowKeys: r,
|
|
8177
8193
|
value: d,
|
|
@@ -8215,7 +8231,7 @@ function Pu(e) {
|
|
|
8215
8231
|
notices: p.notices
|
|
8216
8232
|
};
|
|
8217
8233
|
}
|
|
8218
|
-
function
|
|
8234
|
+
function Ru(e) {
|
|
8219
8235
|
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 ? Os(t) : null, p = Os(t), m = [], h = [], g = [], _ = [], v = (e, t) => {
|
|
8220
8236
|
(e === "set" || e === "merge") && _.push({
|
|
8221
8237
|
jp: t,
|
|
@@ -8237,7 +8253,7 @@ function Fu(e) {
|
|
|
8237
8253
|
error: X({
|
|
8238
8254
|
code: "PATH_DENIED",
|
|
8239
8255
|
message: `patches[${e}] @ "${a}" 不在 schema 声明字段内`,
|
|
8240
|
-
hint:
|
|
8256
|
+
hint: `仅 schema 声明的 key 可写${Nu(Mu(r, Pu(a)))}`
|
|
8241
8257
|
})
|
|
8242
8258
|
};
|
|
8243
8259
|
let o = t.op ?? "set", s;
|
|
@@ -8260,7 +8276,7 @@ function Fu(e) {
|
|
|
8260
8276
|
error: X({
|
|
8261
8277
|
code: "PATH_DENIED",
|
|
8262
8278
|
message: `patches[${e}] move 目标 "${s}" 不在 schema 声明字段内`,
|
|
8263
|
-
hint:
|
|
8279
|
+
hint: `move 的 value(目标路径)也须在 schema 声明字段内${Nu(Mu(r, Pu(String(s))))}`
|
|
8264
8280
|
})
|
|
8265
8281
|
};
|
|
8266
8282
|
}
|
|
@@ -8298,7 +8314,7 @@ function Fu(e) {
|
|
|
8298
8314
|
error: e.error
|
|
8299
8315
|
};
|
|
8300
8316
|
}
|
|
8301
|
-
let y =
|
|
8317
|
+
let y = Iu({
|
|
8302
8318
|
schema: r,
|
|
8303
8319
|
bindRef: t,
|
|
8304
8320
|
clone: p,
|
|
@@ -8343,37 +8359,37 @@ function Fu(e) {
|
|
|
8343
8359
|
notices: y.notices
|
|
8344
8360
|
};
|
|
8345
8361
|
}
|
|
8346
|
-
function
|
|
8362
|
+
function zu(e) {
|
|
8347
8363
|
return e < 1024 ? `${e}B` : e < 1024 * 1024 ? `${(e / 1024).toFixed(1)}KB` : `${(e / (1024 * 1024)).toFixed(1)}MB`;
|
|
8348
8364
|
}
|
|
8349
|
-
function
|
|
8365
|
+
function Bu(e, t, n, r) {
|
|
8350
8366
|
if (!t || !n.length || typeof e != "object" || !e) return e;
|
|
8351
8367
|
let i = new Set(n.map((e) => e.field)), a = Os(e);
|
|
8352
8368
|
return (function e(t) {
|
|
8353
8369
|
if (Array.isArray(t)) for (let n of t) e(n);
|
|
8354
8370
|
else if (t && typeof t == "object") for (let n of Object.keys(t)) {
|
|
8355
8371
|
let a = t[n];
|
|
8356
|
-
typeof a == "string" && i.has(n) && a.length >= r ? t[n] = `<${n} ${
|
|
8372
|
+
typeof a == "string" && i.has(n) && a.length >= r ? t[n] = `<${n} ${zu(a.length)}>` : e(a);
|
|
8357
8373
|
}
|
|
8358
8374
|
})(a), a;
|
|
8359
8375
|
}
|
|
8360
|
-
var
|
|
8361
|
-
function
|
|
8362
|
-
return
|
|
8376
|
+
var Vu = 0;
|
|
8377
|
+
function Hu() {
|
|
8378
|
+
return Vu++, "c_" + Math.random().toString(36).slice(2, 8) + Vu.toString(36);
|
|
8363
8379
|
}
|
|
8364
|
-
function
|
|
8380
|
+
function Uu(e, t) {
|
|
8365
8381
|
if (!(!e || typeof e != "object")) for (let n of t) {
|
|
8366
8382
|
let t = Q(e, n);
|
|
8367
|
-
if (Array.isArray(t)) for (let e of t) e && typeof e == "object" && !("__pgId" in e) && (e.__pgId =
|
|
8383
|
+
if (Array.isArray(t)) for (let e of t) e && typeof e == "object" && !("__pgId" in e) && (e.__pgId = Hu());
|
|
8368
8384
|
}
|
|
8369
8385
|
}
|
|
8370
|
-
function
|
|
8386
|
+
function Wu(e) {
|
|
8371
8387
|
(function e(t) {
|
|
8372
8388
|
if (Array.isArray(t)) t.forEach(e);
|
|
8373
8389
|
else if (t && typeof t == "object") for (let n of Object.keys(t)) n.startsWith("__pg") ? delete t[n] : e(t[n]);
|
|
8374
8390
|
})(e);
|
|
8375
8391
|
}
|
|
8376
|
-
function
|
|
8392
|
+
function Gu(e, n = {}) {
|
|
8377
8393
|
let i = n.pgIdPaths ?? [], a = i.length ? (e, t) => {
|
|
8378
8394
|
if (t && typeof t == "object") for (let n of i) {
|
|
8379
8395
|
let r = Q(t, n), i = Q(e, n);
|
|
@@ -8400,7 +8416,7 @@ function Hu(e, n = {}) {
|
|
|
8400
8416
|
t && n && typeof n == "object" && !("__pgId" in n) && (n.__pgId = t, o.add(e));
|
|
8401
8417
|
}
|
|
8402
8418
|
}
|
|
8403
|
-
|
|
8419
|
+
Uu(e, i);
|
|
8404
8420
|
} : void 0, o = i.length ? ts(e.schema, i).schema : e.schema, s = e.bind, c = e.description ?? "主数据对象", l = Do(o), u = /* @__PURE__ */ new Map(), d = n.vfsStore ? new wu(n.vfsStore) : void 0;
|
|
8405
8421
|
function f(e) {
|
|
8406
8422
|
if (u.clear(), e) for (let t of e) {
|
|
@@ -8568,7 +8584,7 @@ function Hu(e, n = {}) {
|
|
|
8568
8584
|
resourceStore: p.resourceStore
|
|
8569
8585
|
}));
|
|
8570
8586
|
let a = w();
|
|
8571
|
-
return b(a, n), i === void 0 ? `主数据${r ? ` @ ${r}` : ""} = (undefined) (hash=${a})` : (i =
|
|
8587
|
+
return b(a, n), i === void 0 ? `主数据${r ? ` @ ${r}` : ""} = (undefined) (hash=${a})` : (i = Bu(i, n === "", D, E), `主数据${r ? ` @ ${r}` : ""} = ${$(i)} (hash=${a})`);
|
|
8572
8588
|
}, {
|
|
8573
8589
|
name: "get_data",
|
|
8574
8590
|
description: "@deprecated(改用 read,等价且支持 fields/depth/分页)。读取主数据当前值(返回含 hash 供乐观锁);jsonPath 可选读子路径。大结果自动外存 vfs。",
|
|
@@ -8578,7 +8594,7 @@ function Hu(e, n = {}) {
|
|
|
8578
8594
|
if (r !== null) return r;
|
|
8579
8595
|
let i = ks(e);
|
|
8580
8596
|
if (i.parseError) return Yr("", e, i.parseError);
|
|
8581
|
-
let c =
|
|
8597
|
+
let c = Lu({
|
|
8582
8598
|
bindRef: s,
|
|
8583
8599
|
value: i.parsed,
|
|
8584
8600
|
schema: o,
|
|
@@ -8623,7 +8639,7 @@ function Hu(e, n = {}) {
|
|
|
8623
8639
|
message: `edit 仅适用于对象/数组主数据,当前是 ${s === void 0 ? "undefined" : typeof s}`,
|
|
8624
8640
|
hint: "叶子(原始类型)请用 set_data 整体设置"
|
|
8625
8641
|
});
|
|
8626
|
-
let f =
|
|
8642
|
+
let f = Ru({
|
|
8627
8643
|
bindRef: s,
|
|
8628
8644
|
patches: [{
|
|
8629
8645
|
op: r,
|
|
@@ -8808,7 +8824,7 @@ function Hu(e, n = {}) {
|
|
|
8808
8824
|
details: { expr: e }
|
|
8809
8825
|
});
|
|
8810
8826
|
}
|
|
8811
|
-
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":${$(
|
|
8827
|
+
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":${$(Bu(e.value, r === "", D, E))}}`);
|
|
8812
8828
|
return `{"matched":${a.length},"returned":${u.length},"truncated":${a.length > c},"results":[${d.join(",")}]}`;
|
|
8813
8829
|
}, {
|
|
8814
8830
|
name: "query_data",
|
|
@@ -8890,7 +8906,7 @@ function Hu(e, n = {}) {
|
|
|
8890
8906
|
if (t === "transform") {
|
|
8891
8907
|
let e = f.result;
|
|
8892
8908
|
if (c) {
|
|
8893
|
-
let t =
|
|
8909
|
+
let t = Ru({
|
|
8894
8910
|
bindRef: s,
|
|
8895
8911
|
patches: [{
|
|
8896
8912
|
op: "set",
|
|
@@ -8919,7 +8935,7 @@ function Hu(e, n = {}) {
|
|
|
8919
8935
|
message: `主数据 bind 为原始类型(${s === null ? "null" : typeof s}),eval transform(patches) 无法就地替换`,
|
|
8920
8936
|
hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹或集成方通过 sdk.setData 替换 bind"
|
|
8921
8937
|
});
|
|
8922
|
-
let t =
|
|
8938
|
+
let t = Ru({
|
|
8923
8939
|
bindRef: s,
|
|
8924
8940
|
patches: e.patches,
|
|
8925
8941
|
schema: o,
|
|
@@ -8952,7 +8968,7 @@ function Hu(e, n = {}) {
|
|
|
8952
8968
|
message: `主数据 bind 为原始类型(${s === null ? "null" : typeof s}),eval transform 无法就地替换外部持有的值引用`,
|
|
8953
8969
|
hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹或集成方通过 sdk.setData 替换 bind"
|
|
8954
8970
|
});
|
|
8955
|
-
let n =
|
|
8971
|
+
let n = Fu({
|
|
8956
8972
|
schema: o,
|
|
8957
8973
|
allowKeys: l,
|
|
8958
8974
|
value: t,
|
|
@@ -9003,7 +9019,7 @@ function Hu(e, n = {}) {
|
|
|
9003
9019
|
resolved: c,
|
|
9004
9020
|
resourcesByPath: p.resourcesByPath,
|
|
9005
9021
|
resourceStore: p.resourceStore
|
|
9006
|
-
})), n && n.length && (c = As(c, n)), r != null && (c = js(c, r)), c =
|
|
9022
|
+
})), n && n.length && (c = As(c, n)), r != null && (c = js(c, r)), c = Bu(c, d === "", D, E), c === void 0 ? `- ${i} = (undefined)` : `- ${i} = ${$(c)}`;
|
|
9007
9023
|
});
|
|
9008
9024
|
return e && b(f, d), `多路径读取(共 ${t.length} 项,hash=${f}):\n${i.join("\n")}`;
|
|
9009
9025
|
}
|
|
@@ -9013,10 +9029,7 @@ function Hu(e, n = {}) {
|
|
|
9013
9029
|
message: `jsonPath "${m}" 含非法段(__proto__/constructor/prototype)`,
|
|
9014
9030
|
hint: "使用正常属性路径,如 components.0.text(数组索引数字)"
|
|
9015
9031
|
});
|
|
9016
|
-
let h = (e, t) =>
|
|
9017
|
-
let n = (e ? Ao(o, e) : o)?.shape;
|
|
9018
|
-
return n && typeof n == "object" ? Object.keys(n) : t && typeof t == "object" && !Array.isArray(t) ? Object.keys(t) : [];
|
|
9019
|
-
};
|
|
9032
|
+
let h = (e, t) => Mu(o, e) ?? (t && typeof t == "object" && !Array.isArray(t) ? Object.keys(t) : []);
|
|
9020
9033
|
if (!Oo(m, o, l)) {
|
|
9021
9034
|
let e = /[.[]/.test(m) ? m.replace(/[.[][^.[]*$/, "") : "", t = h(e, e ? Q(s, e) : s), n = t.length ? `;父级 "${e || "(root)"}" 的可用字段:${t.slice(0, 12).join(", ")}${t.length > 12 ? " …" : ""}` : "";
|
|
9022
9035
|
return X({
|
|
@@ -9049,7 +9062,7 @@ function Hu(e, n = {}) {
|
|
|
9049
9062
|
resolved: _,
|
|
9050
9063
|
resourcesByPath: p.resourcesByPath,
|
|
9051
9064
|
resourceStore: p.resourceStore
|
|
9052
|
-
})), b(f, d), n && n.length && (_ = As(_, n)), r != null && (_ = js(_, r)), _ =
|
|
9065
|
+
})), b(f, d), n && n.length && (_ = As(_, n)), r != null && (_ = js(_, r)), _ = Bu(_, d === "", D, E);
|
|
9053
9066
|
let y = e ? "" : `主数据说明: ${c}\n格式: 写入值需为 JSON,且通过声明的 schema 校验(校验失败时 write 会返回结构化错误)。字段约束(类型/min/max/enum/必填/默认)见 systemPrompt「可操作数据」段,或用 schema_data({ jsonPath }) 按需查。\n\n`, x = n && n.length ? `(字段裁剪:${n.join(",")})` : "", S = r == null ? "" : `(深度≤${r})`, C = x || S ? ` ${x}${S}` : "";
|
|
9054
9067
|
if ((i !== void 0 || a !== void 0) && Array.isArray(_)) {
|
|
9055
9068
|
let e = _.length, t = Math.max(0, i ?? 0), n = Math.min(200, Math.max(1, a ?? 50)), r = _.slice(t, t + n), o = t + n < e;
|
|
@@ -9129,7 +9142,7 @@ function Hu(e, n = {}) {
|
|
|
9129
9142
|
op: t.op ?? "set",
|
|
9130
9143
|
jsonPath: t.jsonPath || "",
|
|
9131
9144
|
value: f
|
|
9132
|
-
}], c =
|
|
9145
|
+
}], c = Ru({
|
|
9133
9146
|
bindRef: s,
|
|
9134
9147
|
patches: r,
|
|
9135
9148
|
schema: o,
|
|
@@ -9151,13 +9164,13 @@ function Hu(e, n = {}) {
|
|
|
9151
9164
|
timestamp: Date.now()
|
|
9152
9165
|
});
|
|
9153
9166
|
let d = T(u);
|
|
9154
|
-
return
|
|
9167
|
+
return Wu(c.clone), `已 write(edit) 主数据(${c.applied.length} 个 patch)。当前值:${$(c.clone, 600)} (新 hash=${d})`;
|
|
9155
9168
|
}
|
|
9156
9169
|
let _ = ks(f);
|
|
9157
9170
|
if (_.parseError) return Yr("", f, _.parseError);
|
|
9158
9171
|
let x = await N("set", g);
|
|
9159
9172
|
if (x !== null) return x;
|
|
9160
|
-
let S =
|
|
9173
|
+
let S = Lu({
|
|
9161
9174
|
bindRef: s,
|
|
9162
9175
|
value: _.parsed,
|
|
9163
9176
|
schema: o,
|
|
@@ -9174,7 +9187,7 @@ function Hu(e, n = {}) {
|
|
|
9174
9187
|
if (!S.ok) return S.error;
|
|
9175
9188
|
if (i) return `dryRun(set): schema 校验通过。预览新值:${$(S.data, 600)}。未实际写入、未入快照。`;
|
|
9176
9189
|
let E = w();
|
|
9177
|
-
return b(E, u),
|
|
9190
|
+
return b(E, u), Wu(S.data), `已 write(set) 主数据 = ${$(S.data, 600)} (新 hash=${E})${l ? "(白名单模式:仅更新 schema 声明字段,未声明字段保留)" : ""}`;
|
|
9178
9191
|
}, {
|
|
9179
9192
|
name: "write",
|
|
9180
9193
|
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 校验(失败不写,按错误修正重试)+ 自动快照。详细用法见系统提示「能力使用提示」。",
|
|
@@ -9293,7 +9306,7 @@ function Hu(e, n = {}) {
|
|
|
9293
9306
|
}
|
|
9294
9307
|
let f = await N("set", C ? y(r) : void 0);
|
|
9295
9308
|
if (f !== null) return f;
|
|
9296
|
-
let g =
|
|
9309
|
+
let g = Lu({
|
|
9297
9310
|
bindRef: s,
|
|
9298
9311
|
value: d,
|
|
9299
9312
|
schema: o,
|
|
@@ -9454,7 +9467,7 @@ function Hu(e, n = {}) {
|
|
|
9454
9467
|
}
|
|
9455
9468
|
//#endregion
|
|
9456
9469
|
//#region src/core/tools/htmlValidate.ts
|
|
9457
|
-
var
|
|
9470
|
+
var Ku = /* @__PURE__ */ new Set([
|
|
9458
9471
|
"area",
|
|
9459
9472
|
"base",
|
|
9460
9473
|
"br",
|
|
@@ -9469,8 +9482,8 @@ var Uu = /* @__PURE__ */ new Set([
|
|
|
9469
9482
|
"source",
|
|
9470
9483
|
"track",
|
|
9471
9484
|
"wbr"
|
|
9472
|
-
]),
|
|
9473
|
-
function
|
|
9485
|
+
]), qu = /* @__PURE__ */ new Set(["script", "style"]);
|
|
9486
|
+
function Ju(e) {
|
|
9474
9487
|
let t = [], n = e.length;
|
|
9475
9488
|
if (!e.trim()) return t;
|
|
9476
9489
|
let r = [0];
|
|
@@ -9547,8 +9560,8 @@ function Gu(e) {
|
|
|
9547
9560
|
}
|
|
9548
9561
|
continue;
|
|
9549
9562
|
}
|
|
9550
|
-
if (!(
|
|
9551
|
-
if (
|
|
9563
|
+
if (!(Ku.has(p) || m)) {
|
|
9564
|
+
if (qu.has(p)) {
|
|
9552
9565
|
let n = RegExp(`</${p}\\s*>`, "i").exec(e.slice(o));
|
|
9553
9566
|
if (!n) {
|
|
9554
9567
|
t.push({
|
|
@@ -9577,8 +9590,8 @@ function Gu(e) {
|
|
|
9577
9590
|
}
|
|
9578
9591
|
//#endregion
|
|
9579
9592
|
//#region src/core/sdk/codeAssetMiddleware.ts
|
|
9580
|
-
var
|
|
9581
|
-
function
|
|
9593
|
+
var Yu = "__pgTouched", Xu = "__pgFinalText", Zu = "__pgCodeHashes", Qu = "__pgKeepExternal", $u = "__pgNotes", ed = 200;
|
|
9594
|
+
function td(e) {
|
|
9582
9595
|
let t = [];
|
|
9583
9596
|
for (let n of e.split("\n")) {
|
|
9584
9597
|
let e = n.match(/^\s*[-*]?\s*\[note\]\s*(.*)$/i);
|
|
@@ -9586,27 +9599,27 @@ function Qu(e) {
|
|
|
9586
9599
|
}
|
|
9587
9600
|
return [...new Set(t)];
|
|
9588
9601
|
}
|
|
9589
|
-
function
|
|
9590
|
-
let n = Array.isArray(e[
|
|
9591
|
-
e[
|
|
9602
|
+
function nd(e, t) {
|
|
9603
|
+
let n = Array.isArray(e[$u]) ? e[$u].filter((e) => typeof e == "string") : [];
|
|
9604
|
+
e[$u] = [.../* @__PURE__ */ new Set([...n, ...t])].map((e) => e.length > ed ? e.slice(0, ed) + "…" : e).slice(-5);
|
|
9592
9605
|
}
|
|
9593
|
-
function
|
|
9606
|
+
function rd(e) {
|
|
9594
9607
|
let t = 5381;
|
|
9595
9608
|
for (let n = 0; n < e.length; n++) t = (t << 5) + t + e.charCodeAt(n) | 0;
|
|
9596
9609
|
return (t >>> 0).toString(16);
|
|
9597
9610
|
}
|
|
9598
|
-
function
|
|
9611
|
+
function id(e, t) {
|
|
9599
9612
|
let n = [];
|
|
9600
|
-
return
|
|
9613
|
+
return od(e, t, (e) => {
|
|
9601
9614
|
typeof e.name == "string" && e.name && n.push(e.name);
|
|
9602
9615
|
}), n;
|
|
9603
9616
|
}
|
|
9604
|
-
function
|
|
9617
|
+
function ad(e, t) {
|
|
9605
9618
|
if (!e.startsWith(t)) return null;
|
|
9606
9619
|
let n = e.slice(t.length), r = n.lastIndexOf(".");
|
|
9607
9620
|
return (r > 0 ? n.slice(0, r) : r === 0 ? "" : n) || null;
|
|
9608
9621
|
}
|
|
9609
|
-
function
|
|
9622
|
+
function od(e, t, n) {
|
|
9610
9623
|
if (!(!e || typeof e != "object")) for (let r of t) {
|
|
9611
9624
|
let t = Q(e, r);
|
|
9612
9625
|
if (Array.isArray(t)) for (let e = 0; e < t.length; e++) {
|
|
@@ -9615,7 +9628,7 @@ function rd(e, t, n) {
|
|
|
9615
9628
|
}
|
|
9616
9629
|
}
|
|
9617
9630
|
}
|
|
9618
|
-
function
|
|
9631
|
+
function sd(e, t, n) {
|
|
9619
9632
|
let r = /* @__PURE__ */ new Set();
|
|
9620
9633
|
if (!e || typeof e != "object") return r;
|
|
9621
9634
|
for (let i of t) {
|
|
@@ -9634,20 +9647,20 @@ function id(e, t, n) {
|
|
|
9634
9647
|
}
|
|
9635
9648
|
return r;
|
|
9636
9649
|
}
|
|
9637
|
-
function
|
|
9650
|
+
function cd(e) {
|
|
9638
9651
|
let { writablePaths: t, codeVfsPrefix: n, ext: r, codeField: i = "code", onWarning: a, getController: o, vfsStore: s, craftNotes: c = !0 } = e, l = s, u = l.__pgLastCheckout ??= /* @__PURE__ */ new Map(), d = l.__pgPendingRetry ??= /* @__PURE__ */ new Set();
|
|
9639
9652
|
return {
|
|
9640
9653
|
name: "code-asset-checkout-commit",
|
|
9641
9654
|
beforeAgent: (e) => {
|
|
9642
9655
|
let c = o()?.get?.().bind;
|
|
9643
|
-
c &&
|
|
9656
|
+
c && Uu(c, t);
|
|
9644
9657
|
let l = 0, f = 0, p = /* @__PURE__ */ new Map();
|
|
9645
|
-
if (
|
|
9658
|
+
if (od(c, t, (e) => {
|
|
9646
9659
|
l++;
|
|
9647
9660
|
let t = Q(e, i);
|
|
9648
9661
|
if (typeof t == "string") {
|
|
9649
9662
|
f++;
|
|
9650
|
-
let i = e.__pgId, a =
|
|
9663
|
+
let i = e.__pgId, a = rd(t);
|
|
9651
9664
|
p.set(i, a);
|
|
9652
9665
|
let o = `${n}${i}.${r}`, c = s.files[o], l = u.get(i);
|
|
9653
9666
|
c && typeof c.content == "string" && c.content !== t && l === a ? d.add(o) : (s.files[o] = {
|
|
@@ -9668,23 +9681,23 @@ function ad(e) {
|
|
|
9668
9681
|
}
|
|
9669
9682
|
return {
|
|
9670
9683
|
files: s.files,
|
|
9671
|
-
[
|
|
9672
|
-
[
|
|
9673
|
-
[
|
|
9674
|
-
[
|
|
9684
|
+
[Yu]: /* @__PURE__ */ new Set(),
|
|
9685
|
+
[Xu]: { text: "" },
|
|
9686
|
+
[Zu]: p,
|
|
9687
|
+
[Qu]: []
|
|
9675
9688
|
};
|
|
9676
9689
|
},
|
|
9677
9690
|
wrapModelCall: async (e, t) => {
|
|
9678
|
-
let n = await t(e), r = e.state[
|
|
9691
|
+
let n = await t(e), r = e.state[Xu];
|
|
9679
9692
|
return r && !(n.toolCalls && n.toolCalls.length) && typeof n.content == "string" && n.content && (r.text = n.content), n;
|
|
9680
9693
|
},
|
|
9681
9694
|
augmentPrompt: () => {
|
|
9682
9695
|
let e = o()?.get?.().bind, i = [], a = 0;
|
|
9683
|
-
if (
|
|
9696
|
+
if (od(e, t, (e, t, o) => {
|
|
9684
9697
|
a++;
|
|
9685
9698
|
let l = typeof e.name == "string" && e.name ? e.name : "", u = l ? `${l} [${o}]` : `(未命名 [${o}])`, d = `${n}${e.__pgId}.${r}`, f = !!s.files[d];
|
|
9686
9699
|
if (i.push(`- ${u} → ${d}${f ? "" : "(尚未检出,先 vfs_write 创建)"}`), c) {
|
|
9687
|
-
let t = Array.isArray(e[
|
|
9700
|
+
let t = Array.isArray(e[$u]) ? e[$u].filter((e) => typeof e == "string") : [];
|
|
9688
9701
|
if (t.length) {
|
|
9689
9702
|
let e = t[t.length - 1];
|
|
9690
9703
|
i.push(` 📝 笔记×${t.length}(最近):${e.length > 120 ? e.slice(0, 120) + "…" : e}`);
|
|
@@ -9706,9 +9719,9 @@ function ad(e) {
|
|
|
9706
9719
|
if (c) {
|
|
9707
9720
|
let i = e.state.focuses;
|
|
9708
9721
|
if (i && i.length) {
|
|
9709
|
-
let e =
|
|
9722
|
+
let e = sd(o()?.get?.().bind, t, i);
|
|
9710
9723
|
if (e.size) {
|
|
9711
|
-
let t =
|
|
9724
|
+
let t = ad(s, n);
|
|
9712
9725
|
if (t && !e.has(t)) return {
|
|
9713
9726
|
content: `PATH_DENIED · vfs 越界:当前聚焦代码文件 [${[...e].map((e) => `${n}${e}.${r}`).join(", ")}],你要改的 "${s}" 不在其中。请只改焦点组件的代码文件;如需改其他组件,请在收口回复中说明需先取消聚焦(焦点由主会话/用户管理,你无 focus 工具)后重试。`,
|
|
9714
9727
|
status: "error"
|
|
@@ -9718,7 +9731,7 @@ function ad(e) {
|
|
|
9718
9731
|
}
|
|
9719
9732
|
let l = await i(e);
|
|
9720
9733
|
if (c) {
|
|
9721
|
-
let t = e.state[
|
|
9734
|
+
let t = e.state[Yu];
|
|
9722
9735
|
t && t.add(s);
|
|
9723
9736
|
}
|
|
9724
9737
|
return l;
|
|
@@ -9726,10 +9739,10 @@ function ad(e) {
|
|
|
9726
9739
|
afterAgent: (e) => {
|
|
9727
9740
|
let a = o(), l = a?.get?.().bind;
|
|
9728
9741
|
if (!l) return;
|
|
9729
|
-
let u = e[
|
|
9742
|
+
let u = e[Yu] ?? /* @__PURE__ */ new Set();
|
|
9730
9743
|
if (u.size) {
|
|
9731
|
-
let o = e[
|
|
9732
|
-
|
|
9744
|
+
let o = e[Zu] ?? /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Set();
|
|
9745
|
+
od(l, t, (t) => {
|
|
9733
9746
|
let a = t.__pgId;
|
|
9734
9747
|
c.add(a);
|
|
9735
9748
|
let l = `${n}${a}.${r}`;
|
|
@@ -9739,14 +9752,14 @@ function ad(e) {
|
|
|
9739
9752
|
let r = o.get(a);
|
|
9740
9753
|
if (r !== void 0) {
|
|
9741
9754
|
let n = Q(t, i);
|
|
9742
|
-
if (typeof n != "string" ||
|
|
9755
|
+
if (typeof n != "string" || rd(n) !== r) {
|
|
9743
9756
|
console.warn(`[page-agent-sdk][code-asset] 组件 ${t.name ?? a}(${l})在修改期间被外部更新,已保留外部版本(keep_external),本次子 agent 修改未提交`);
|
|
9744
|
-
let n = e[
|
|
9745
|
-
Array.isArray(n) ? n.push(r) : e[
|
|
9757
|
+
let n = e[Qu], r = String(t.name ?? a);
|
|
9758
|
+
Array.isArray(n) ? n.push(r) : e[Qu] = [r];
|
|
9746
9759
|
return;
|
|
9747
9760
|
}
|
|
9748
9761
|
}
|
|
9749
|
-
let s =
|
|
9762
|
+
let s = Ju(n.content);
|
|
9750
9763
|
if (s.length) {
|
|
9751
9764
|
console.warn(`[page-agent-sdk][code-asset] 跳过 commit 未通过校验的半成品(可能 abort/timeout 未跑完 verify):${l} - ${s[0].message}(${s[0].code})`);
|
|
9752
9765
|
return;
|
|
@@ -9758,22 +9771,22 @@ function ad(e) {
|
|
|
9758
9771
|
}
|
|
9759
9772
|
});
|
|
9760
9773
|
for (let e of u) {
|
|
9761
|
-
let t =
|
|
9774
|
+
let t = ad(e, n);
|
|
9762
9775
|
t && !c.has(t) && (console.warn(`[page-agent-sdk][code-asset] 组件 ${t}(${e})已被外部删除,放弃 commit 并清理 vfs 工作副本(不复活组件)`), delete s.files[e]);
|
|
9763
9776
|
}
|
|
9764
9777
|
a?.markDataDirty?.(), a?.recomputeBaseline?.();
|
|
9765
9778
|
}
|
|
9766
9779
|
if (!c) return;
|
|
9767
|
-
let f =
|
|
9780
|
+
let f = td(e[Xu]?.text ?? "");
|
|
9768
9781
|
if (!f.length) return;
|
|
9769
9782
|
let p = [];
|
|
9770
|
-
if (
|
|
9783
|
+
if (od(l, t, (e) => {
|
|
9771
9784
|
(u.size === 0 || u.has(`${n}${e.__pgId}.${r}`)) && p.push(e);
|
|
9772
9785
|
}), !p.length) return;
|
|
9773
9786
|
let m = !1;
|
|
9774
9787
|
for (let e of f) {
|
|
9775
9788
|
let t = p.length === 1 ? p[0] : p.find((t) => typeof t.name == "string" && !!t.name && e.includes(t.name));
|
|
9776
|
-
t && (
|
|
9789
|
+
t && (nd(t, [e]), m = !0);
|
|
9777
9790
|
}
|
|
9778
9791
|
m && a?.markDataDirty?.();
|
|
9779
9792
|
}
|
|
@@ -9781,7 +9794,7 @@ function ad(e) {
|
|
|
9781
9794
|
}
|
|
9782
9795
|
//#endregion
|
|
9783
9796
|
//#region src/core/sdk/componentLock.ts
|
|
9784
|
-
function
|
|
9797
|
+
function ld() {
|
|
9785
9798
|
let e = /* @__PURE__ */ new Map();
|
|
9786
9799
|
return {
|
|
9787
9800
|
async acquire(t, n) {
|
|
@@ -9820,7 +9833,7 @@ function od() {
|
|
|
9820
9833
|
}
|
|
9821
9834
|
};
|
|
9822
9835
|
}
|
|
9823
|
-
function
|
|
9836
|
+
function ud(e, t) {
|
|
9824
9837
|
if (Array.isArray(e.components) && e.components.length) {
|
|
9825
9838
|
let n = new Set(t), r = [...new Set(e.components.filter((e) => typeof e == "string" && e && n.has(e)))];
|
|
9826
9839
|
if (r.length) return {
|
|
@@ -9837,12 +9850,12 @@ function sd(e, t) {
|
|
|
9837
9850
|
via: "none"
|
|
9838
9851
|
};
|
|
9839
9852
|
}
|
|
9840
|
-
function
|
|
9853
|
+
function dd(e, t, n) {
|
|
9841
9854
|
let r = new Set(n);
|
|
9842
9855
|
if (!r.size || !e || typeof e != "object") return [];
|
|
9843
9856
|
let i = [];
|
|
9844
9857
|
for (let n of t) {
|
|
9845
|
-
let t =
|
|
9858
|
+
let t = fd(e, n);
|
|
9846
9859
|
if (Array.isArray(t)) for (let e = 0; e < t.length; e++) {
|
|
9847
9860
|
let a = t[e];
|
|
9848
9861
|
a && typeof a == "object" && typeof a.name == "string" && r.has(a.name) && i.push(`${n}.${e}`);
|
|
@@ -9850,7 +9863,7 @@ function cd(e, t, n) {
|
|
|
9850
9863
|
}
|
|
9851
9864
|
return i;
|
|
9852
9865
|
}
|
|
9853
|
-
function
|
|
9866
|
+
function fd(e, t) {
|
|
9854
9867
|
let n = e;
|
|
9855
9868
|
for (let e of t.split(".")) {
|
|
9856
9869
|
if (!n || typeof n != "object") return;
|
|
@@ -9858,26 +9871,26 @@ function ld(e, t) {
|
|
|
9858
9871
|
}
|
|
9859
9872
|
return n;
|
|
9860
9873
|
}
|
|
9861
|
-
function
|
|
9874
|
+
function pd(e, t) {
|
|
9862
9875
|
return t.some((t) => e === t || e.startsWith(t + "."));
|
|
9863
9876
|
}
|
|
9864
|
-
function
|
|
9877
|
+
function md(e, t) {
|
|
9865
9878
|
let n = [];
|
|
9866
9879
|
for (let { writablePaths: r, codeField: i } of t) for (let t of r) {
|
|
9867
|
-
let r =
|
|
9880
|
+
let r = fd(e, t);
|
|
9868
9881
|
if (Array.isArray(r)) for (let e = 0; e < r.length; e++) {
|
|
9869
9882
|
let a = r[e];
|
|
9870
|
-
a && typeof a == "object" && typeof
|
|
9883
|
+
a && typeof a == "object" && typeof fd(a, i) == "string" && n.push(`${t}.${e}.${i}`);
|
|
9871
9884
|
}
|
|
9872
9885
|
}
|
|
9873
9886
|
return n;
|
|
9874
9887
|
}
|
|
9875
|
-
function
|
|
9888
|
+
function hd(e) {
|
|
9876
9889
|
let t = e ?? {}, n = /* @__PURE__ */ new Set();
|
|
9877
9890
|
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);
|
|
9878
9891
|
return [...n];
|
|
9879
9892
|
}
|
|
9880
|
-
function
|
|
9893
|
+
function gd(e) {
|
|
9881
9894
|
return {
|
|
9882
9895
|
name: "component-write-guard",
|
|
9883
9896
|
wrapToolCall: async (t, n) => {
|
|
@@ -9896,9 +9909,9 @@ function pd(e) {
|
|
|
9896
9909
|
status: "error"
|
|
9897
9910
|
};
|
|
9898
9911
|
}
|
|
9899
|
-
let a = e.getLocked(), o = Object.keys(a), s = e.getCodeFieldPaths?.() ?? [], c =
|
|
9912
|
+
let a = e.getLocked(), o = Object.keys(a), s = e.getCodeFieldPaths?.() ?? [], c = hd(i);
|
|
9900
9913
|
if (s.length) {
|
|
9901
|
-
let t = c.filter((e) =>
|
|
9914
|
+
let t = c.filter((e) => pd(e, s));
|
|
9902
9915
|
if (t.length) return e.onReject?.({
|
|
9903
9916
|
paths: t,
|
|
9904
9917
|
lockedPrefixes: s,
|
|
@@ -9909,7 +9922,7 @@ function pd(e) {
|
|
|
9909
9922
|
};
|
|
9910
9923
|
}
|
|
9911
9924
|
if (!o.length) return n(t);
|
|
9912
|
-
let l =
|
|
9925
|
+
let l = dd(e.getBind(), e.writablePaths, o);
|
|
9913
9926
|
if (!l.length) return n(t);
|
|
9914
9927
|
if (!c.length) return e.onReject?.({
|
|
9915
9928
|
paths: ["(整体 set)"],
|
|
@@ -9919,7 +9932,7 @@ function pd(e) {
|
|
|
9919
9932
|
content: `COMPONENT_LOCKED · 组件 [${o.join(", ")}] 正在被子 agent 修改,整体写入会触碰它们。请改用增量 patch(write({patch:{jsonPath,...}}))只写未锁定组件,或等委派结束后再整体操作。`,
|
|
9920
9933
|
status: "error"
|
|
9921
9934
|
};
|
|
9922
|
-
let u = c.filter((e) =>
|
|
9935
|
+
let u = c.filter((e) => pd(e, l));
|
|
9923
9936
|
return u.length ? (e.onReject?.({
|
|
9924
9937
|
paths: u,
|
|
9925
9938
|
lockedPrefixes: l,
|
|
@@ -9933,7 +9946,7 @@ function pd(e) {
|
|
|
9933
9946
|
}
|
|
9934
9947
|
//#endregion
|
|
9935
9948
|
//#region src/core/sdk/baselineGuard.ts
|
|
9936
|
-
function
|
|
9949
|
+
function _d(e) {
|
|
9937
9950
|
return {
|
|
9938
9951
|
name: "baseline-guard",
|
|
9939
9952
|
wrapToolCall: async (t, n) => {
|
|
@@ -9953,21 +9966,21 @@ function md(e) {
|
|
|
9953
9966
|
}
|
|
9954
9967
|
//#endregion
|
|
9955
9968
|
//#region src/core/sdk/diagnostics.ts
|
|
9956
|
-
var
|
|
9957
|
-
function
|
|
9969
|
+
var vd = 5e4, yd = 6e6;
|
|
9970
|
+
function bd(e) {
|
|
9958
9971
|
return e.replace(/([?&][^=&?]*(?:key|token|secret|password|signature)[^=&?]*=)[^&]*/gi, "$1***");
|
|
9959
9972
|
}
|
|
9960
|
-
function
|
|
9961
|
-
if (typeof e == "string") return e.length >
|
|
9962
|
-
if (Array.isArray(e)) return e.map(
|
|
9973
|
+
function xd(e) {
|
|
9974
|
+
if (typeof e == "string") return e.length > vd ? e.slice(0, vd) + `…<truncated:${e.length - vd} chars>` : e;
|
|
9975
|
+
if (Array.isArray(e)) return e.map(xd);
|
|
9963
9976
|
if (e && typeof e == "object") {
|
|
9964
9977
|
let t = {};
|
|
9965
|
-
for (let [n, r] of Object.entries(e)) t[n] =
|
|
9978
|
+
for (let [n, r] of Object.entries(e)) t[n] = xd(r);
|
|
9966
9979
|
return t;
|
|
9967
9980
|
}
|
|
9968
9981
|
return e;
|
|
9969
9982
|
}
|
|
9970
|
-
function
|
|
9983
|
+
function Sd(e) {
|
|
9971
9984
|
let t = Array.isArray(e.debugLogs) ? e.debugLogs : [];
|
|
9972
9985
|
return {
|
|
9973
9986
|
format: "page-agent-sdk/diagnostics",
|
|
@@ -9975,23 +9988,23 @@ function yd(e) {
|
|
|
9975
9988
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9976
9989
|
environment: {
|
|
9977
9990
|
userAgent: typeof navigator < "u" ? navigator.userAgent : "node",
|
|
9978
|
-
url: typeof location < "u" ?
|
|
9991
|
+
url: typeof location < "u" ? bd(location.href) : null
|
|
9979
9992
|
},
|
|
9980
9993
|
sessionId: e.sessionId ?? null,
|
|
9981
9994
|
usage: e.usage ?? null,
|
|
9982
9995
|
pendingConflict: e.pendingConflict ?? null,
|
|
9983
9996
|
dataSummary: e.dataSummary ?? null,
|
|
9984
|
-
info: e.info ?
|
|
9985
|
-
messages: (e.messages ?? []).map(
|
|
9986
|
-
debugLogs: t.map(
|
|
9997
|
+
info: e.info ? xd(e.info) : null,
|
|
9998
|
+
messages: (e.messages ?? []).map(xd),
|
|
9999
|
+
debugLogs: t.map(xd),
|
|
9987
10000
|
extra: e.extra ?? null
|
|
9988
10001
|
};
|
|
9989
10002
|
}
|
|
9990
|
-
function
|
|
10003
|
+
function Cd(e) {
|
|
9991
10004
|
let t = JSON.stringify(e);
|
|
9992
|
-
if (t.length <=
|
|
10005
|
+
if (t.length <= yd) return t;
|
|
9993
10006
|
let n = Array.isArray(e.debugLogs) ? e.debugLogs : [], r = 0;
|
|
9994
|
-
for (; t.length >
|
|
10007
|
+
for (; t.length > yd && n.length > 1;) {
|
|
9995
10008
|
let i = Math.max(1, Math.floor(n.length / 2));
|
|
9996
10009
|
n.splice(0, i), r += i, t = JSON.stringify(e);
|
|
9997
10010
|
}
|
|
@@ -10001,13 +10014,13 @@ function bd(e) {
|
|
|
10001
10014
|
data: {
|
|
10002
10015
|
stage: "diagnostics_truncated",
|
|
10003
10016
|
droppedOldestLogs: r,
|
|
10004
|
-
reason: `report > ${
|
|
10017
|
+
reason: `report > ${yd} chars`
|
|
10005
10018
|
}
|
|
10006
10019
|
}), t = JSON.stringify(e)), t;
|
|
10007
10020
|
}
|
|
10008
10021
|
//#endregion
|
|
10009
10022
|
//#region src/core/sdk/htmlSubagent.ts
|
|
10010
|
-
function
|
|
10023
|
+
function wd(e, t, n) {
|
|
10011
10024
|
let r = "html";
|
|
10012
10025
|
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(规划)。
|
|
10013
10026
|
|
|
@@ -10061,7 +10074,7 @@ ${`- 输出形态:完整、自包含的 HTML 页面(.${r},可独立成页)`}
|
|
|
10061
10074
|
- 一次想清楚 → 动手 → 验证 → 收口。**思考是手段不是目的,产出代码才是**。
|
|
10062
10075
|
8. **收口格式(必守,最后一行)**:收口回复 = 简短结果总结 + **末行交接笔记** \`[note] <一句话实现要点>\` —— 关键设计决策 / 用户偏好 / 踩坑(如「[note] 液面用 height keyframes 4.2s 循环;装饰仅灯串+光斑 2 类」)。框架只识别末尾 [note] 行存进组件、自动转交下次维护该组件的子 agent;**漏写 = 下任失去交接**(真 LLM 实测漏写率 3/4,务必末行带上)。一行内,只写可复用结论。`;
|
|
10063
10076
|
}
|
|
10064
|
-
function
|
|
10077
|
+
function Td(e, t) {
|
|
10065
10078
|
return `# HTML 完整页面生成规范
|
|
10066
10079
|
|
|
10067
10080
|
## 代码资产模型(重要)
|
|
@@ -10099,14 +10112,14 @@ function Sd(e, t) {
|
|
|
10099
10112
|
- 语义化标签(button / nav / section);图片 alt;交互可键盘聚焦
|
|
10100
10113
|
- 颜色对比达标;不只用颜色传达信息`;
|
|
10101
10114
|
}
|
|
10102
|
-
function
|
|
10115
|
+
function Ed(e = "components", t = "code") {
|
|
10103
10116
|
return {
|
|
10104
10117
|
name: "html-fragment",
|
|
10105
10118
|
description: "完整 HTML 页面生成规范:代码作为 data 资产 / vfs 工作副本 / 完整自包含可独立成页 / script+CSS 集中放置 / 可引外部 JS/CSS / validate_code 自检 / 安全底线 / 可访问性",
|
|
10106
|
-
getContent: () =>
|
|
10119
|
+
getContent: () => Td(e, t)
|
|
10107
10120
|
};
|
|
10108
10121
|
}
|
|
10109
|
-
function
|
|
10122
|
+
function Dd(e = {}) {
|
|
10110
10123
|
let t = e.vfsPrefix ?? "html/";
|
|
10111
10124
|
return ({ state: e }) => {
|
|
10112
10125
|
let n = e.files;
|
|
@@ -10114,7 +10127,7 @@ function wd(e = {}) {
|
|
|
10114
10127
|
let r = [];
|
|
10115
10128
|
for (let [e, i] of Object.entries(n)) {
|
|
10116
10129
|
if (!e.startsWith(t)) continue;
|
|
10117
|
-
let n =
|
|
10130
|
+
let n = Ju(i.content);
|
|
10118
10131
|
for (let t of n) r.push(`${e} 第 ${t.line} 行:${t.message}(${t.code})`);
|
|
10119
10132
|
}
|
|
10120
10133
|
return r.length ? {
|
|
@@ -10123,7 +10136,7 @@ function wd(e = {}) {
|
|
|
10123
10136
|
} : { ok: !0 };
|
|
10124
10137
|
};
|
|
10125
10138
|
}
|
|
10126
|
-
function
|
|
10139
|
+
function Od(e) {
|
|
10127
10140
|
let n, i, a = {
|
|
10128
10141
|
name: "html-validate-tools",
|
|
10129
10142
|
beforeAgent: (e) => {
|
|
@@ -10158,7 +10171,7 @@ function Td(e) {
|
|
|
10158
10171
|
}
|
|
10159
10172
|
let s = [];
|
|
10160
10173
|
for (let e of o) {
|
|
10161
|
-
let t =
|
|
10174
|
+
let t = Ju(e.content);
|
|
10162
10175
|
t.length && s.push(`${e.path}:\n${t.map((e) => ` 第 ${e.line} 行 ${e.message}(${e.code})`).join("\n")}`);
|
|
10163
10176
|
}
|
|
10164
10177
|
return s.length ? `❌ 格式校验未通过:\n${s.join("\n")}\n请用 vfs_edit 修正后重新调用 validate_code 复查。` : `✅ 格式校验通过(${o.map((e) => e.path).join(", ")}:标签闭合等结构合法)。`;
|
|
@@ -10176,16 +10189,16 @@ function Td(e) {
|
|
|
10176
10189
|
i = e;
|
|
10177
10190
|
}, a;
|
|
10178
10191
|
}
|
|
10179
|
-
var
|
|
10180
|
-
function
|
|
10192
|
+
var kd = 2;
|
|
10193
|
+
function Ad(e = {}) {
|
|
10181
10194
|
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, llm: h, thinkingMode: g } = e;
|
|
10182
10195
|
if (t !== void 0 && !Array.isArray(t)) throw Error("[page-agent-sdk][createHtmlSubagent] writablePaths 须为字符串数组(代码组件 data 区,如 [\"components\"])/ 省略以从 schema 自动推断");
|
|
10183
10196
|
let _ = [];
|
|
10184
|
-
a && _.push(Ja()), d && (_.push(
|
|
10197
|
+
a && _.push(Ja()), d && (_.push(Od(n)), _.push(Tl({ check: Dd({ vfsPrefix: n }) })));
|
|
10185
10198
|
let v = u ?? [], y = t?.[0] ?? "components", b = l === void 0, x = {
|
|
10186
10199
|
id: r,
|
|
10187
10200
|
description: i ?? `生成/修改纯代码组件(代码作为 data 资产,代码字段 ${f} 随 data 持久化;vfs 作工作副本;能规划(write_todos)+ 执行)。需写代码组件或灵活定制时委派`,
|
|
10188
|
-
systemPrompt:
|
|
10201
|
+
systemPrompt: wd(n, f, y),
|
|
10189
10202
|
...h ? { llm: h } : {},
|
|
10190
10203
|
...g ? { thinkingMode: g } : {},
|
|
10191
10204
|
writablePaths: t ?? [],
|
|
@@ -10198,9 +10211,9 @@ function Dd(e = {}) {
|
|
|
10198
10211
|
],
|
|
10199
10212
|
middleware: _.length ? _ : void 0,
|
|
10200
10213
|
summarization: o === !1 ? void 0 : o,
|
|
10201
|
-
maxVerifyAttempts: d ?
|
|
10214
|
+
maxVerifyAttempts: d ? kd : void 0,
|
|
10202
10215
|
temperature: c,
|
|
10203
|
-
skills: b ? [
|
|
10216
|
+
skills: b ? [Ed(y, f)] : l,
|
|
10204
10217
|
maxToolRounds: s,
|
|
10205
10218
|
tools: v.length ? v : void 0,
|
|
10206
10219
|
_codeAsset: {
|
|
@@ -10213,12 +10226,12 @@ function Dd(e = {}) {
|
|
|
10213
10226
|
}
|
|
10214
10227
|
};
|
|
10215
10228
|
return x._rebuildCodeAssetPaths = (e) => {
|
|
10216
|
-
x.systemPrompt =
|
|
10229
|
+
x.systemPrompt = wd(n, f, e), b && (x.skills = [Ed(e, f)]);
|
|
10217
10230
|
}, x;
|
|
10218
10231
|
}
|
|
10219
10232
|
//#endregion
|
|
10220
10233
|
//#region src/core/sdk/defineTool.ts
|
|
10221
|
-
function
|
|
10234
|
+
function jd(e) {
|
|
10222
10235
|
return r(async (t) => {
|
|
10223
10236
|
let n = await e.handler(t);
|
|
10224
10237
|
return typeof n == "string" ? n : JSON.stringify(n);
|
|
@@ -10230,7 +10243,7 @@ function Od(e) {
|
|
|
10230
10243
|
}
|
|
10231
10244
|
//#endregion
|
|
10232
10245
|
//#region src/core/sdk/inspectContextTool.ts
|
|
10233
|
-
var
|
|
10246
|
+
var Md = t.object({
|
|
10234
10247
|
path: t.string().optional().describe("分类 key 过滤(如 toolResults/history/systemPrompt/dataHint);不传=全部分类"),
|
|
10235
10248
|
role: t.enum([
|
|
10236
10249
|
"user",
|
|
@@ -10240,11 +10253,11 @@ var kd = t.object({
|
|
|
10240
10253
|
]).optional().describe("聚焦每轮首句的角色(assistant→回复摘要,user→问题摘要);不影响工具列表"),
|
|
10241
10254
|
limit: t.number().int().min(1).max(50).optional().describe("返回最近 N 轮(默认全部;超 50 自动截最近 50 防返回过大)")
|
|
10242
10255
|
});
|
|
10243
|
-
function
|
|
10244
|
-
return
|
|
10256
|
+
function Nd(e) {
|
|
10257
|
+
return jd({
|
|
10245
10258
|
name: "inspect_context",
|
|
10246
10259
|
description: "查看当前对话上下文的构成(供压缩决策)。返回:totalTokens(历史轮次 token 总和,与触发判断同口径)、occupancy(窗口占用比)、contextWindow、categories(分类占用)、rounds(每轮 token/工具/首句)。先调用本工具查看构成,再决定压缩策略。",
|
|
10247
|
-
schema:
|
|
10260
|
+
schema: Md,
|
|
10248
10261
|
handler: (t) => {
|
|
10249
10262
|
let n = lc(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) => {
|
|
10250
10263
|
let n = xc(e), r = dc(e), i = t.role === "assistant" ? e.assistantMsgs[0] ?? e.userMsg : e.userMsg, a = uc(typeof i.content == "string" ? i.content : "", 60);
|
|
@@ -10267,7 +10280,7 @@ function Ad(e) {
|
|
|
10267
10280
|
}
|
|
10268
10281
|
//#endregion
|
|
10269
10282
|
//#region src/core/sdk/compressDecision.ts
|
|
10270
|
-
var
|
|
10283
|
+
var Pd = t.object({
|
|
10271
10284
|
keepRounds: t.number().int().min(0).max(50).optional(),
|
|
10272
10285
|
windowRatio: t.number().min(0).max(1).optional(),
|
|
10273
10286
|
summarize: t.object({ mode: t.enum(["index", "llm"]) }),
|
|
@@ -10277,23 +10290,23 @@ var jd = t.object({
|
|
|
10277
10290
|
}).refine((e) => e.keepRounds !== void 0 || e.windowRatio !== void 0, { message: "keepRounds 与 windowRatio 至少填一个(按当前触发模式)" });
|
|
10278
10291
|
//#endregion
|
|
10279
10292
|
//#region src/core/sdk/llmResolver.ts
|
|
10280
|
-
function
|
|
10293
|
+
function Fd(e) {
|
|
10281
10294
|
let t = e.find((e) => e.role === "user");
|
|
10282
10295
|
if (!t) return;
|
|
10283
10296
|
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, " ");
|
|
10284
10297
|
if (r) return r.length > 30 ? r.slice(0, 30) + "…" : r;
|
|
10285
10298
|
}
|
|
10286
|
-
function
|
|
10299
|
+
function Id(e) {
|
|
10287
10300
|
return !!e && typeof e == "object" && typeof e.invoke == "function" && typeof e.stream == "function";
|
|
10288
10301
|
}
|
|
10289
|
-
function
|
|
10302
|
+
function Ld(e) {
|
|
10290
10303
|
let t = e.content;
|
|
10291
10304
|
return typeof t == "string" ? t : Array.isArray(t) ? t.map((e) => typeof e == "string" ? e : e?.text ?? "").join("") : String(t ?? "");
|
|
10292
10305
|
}
|
|
10293
|
-
function
|
|
10306
|
+
function Rd(e) {
|
|
10294
10307
|
let t = e.summaryLlm ?? e.llm;
|
|
10295
10308
|
if (!t) return;
|
|
10296
|
-
let n = e.summaryTemperature ?? .3, r = e.summaryMaxTokens ?? 1024, i = e.summaryTimeoutMs ?? 15e3, s =
|
|
10309
|
+
let n = e.summaryTemperature ?? .3, r = e.summaryMaxTokens ?? 1024, i = e.summaryTimeoutMs ?? 15e3, s = Id(t) ? t : null, c = Id(t) ? null : t;
|
|
10297
10310
|
if (c && !c.apiKey) {
|
|
10298
10311
|
e.summaryLlm && console.warn("[page-agent-sdk][summarization] summaryLlm 已配置但缺 apiKey,摘要回退主 agent 模型或零成本索引摘要");
|
|
10299
10312
|
return;
|
|
@@ -10305,16 +10318,16 @@ function Fd(e) {
|
|
|
10305
10318
|
return !l && c && (l = await h(c, {
|
|
10306
10319
|
temperature: n,
|
|
10307
10320
|
maxTokens: r
|
|
10308
|
-
})),
|
|
10321
|
+
})), Ld(await l.invoke([new o("你是对话历史压缩助手。把下面按轮次索引的对话要点,改写成一段连贯、紧凑的中文摘要,保留关键事实、用户意图与已用工具,不要编造。直接输出摘要正文。"), new a(e)], { signal: t.signal })).trim();
|
|
10309
10322
|
} finally {
|
|
10310
10323
|
clearTimeout(s);
|
|
10311
10324
|
}
|
|
10312
10325
|
};
|
|
10313
10326
|
}
|
|
10314
|
-
function
|
|
10327
|
+
function zd(e) {
|
|
10315
10328
|
let t = e.titleLlm ?? e.summaryLlm ?? e.llm;
|
|
10316
10329
|
if (!t) return;
|
|
10317
|
-
let n =
|
|
10330
|
+
let n = Id(t) ? t : null, r = Id(t) ? null : t;
|
|
10318
10331
|
if (r && !r.apiKey) return;
|
|
10319
10332
|
let i = n;
|
|
10320
10333
|
return async (t) => {
|
|
@@ -10325,7 +10338,7 @@ function Id(e) {
|
|
|
10325
10338
|
maxTokens: 30
|
|
10326
10339
|
}));
|
|
10327
10340
|
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;
|
|
10328
|
-
return
|
|
10341
|
+
return Ld(t).trim().replace(/^["'""「『]|["'""」』]$/g, "").split("\n")[0].slice(0, c);
|
|
10329
10342
|
} catch {
|
|
10330
10343
|
return "";
|
|
10331
10344
|
} finally {
|
|
@@ -10333,10 +10346,10 @@ function Id(e) {
|
|
|
10333
10346
|
}
|
|
10334
10347
|
};
|
|
10335
10348
|
}
|
|
10336
|
-
function
|
|
10349
|
+
function Bd() {
|
|
10337
10350
|
return `call_dec_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
|
|
10338
10351
|
}
|
|
10339
|
-
function
|
|
10352
|
+
function Vd(e) {
|
|
10340
10353
|
let t = e.match(/```(?:json)?\s*([\s\S]*?)```/), n = t ? t[1] : e, r = n.indexOf("{"), i = n.lastIndexOf("}");
|
|
10341
10354
|
if (r < 0 || i < 0 || i <= r) return null;
|
|
10342
10355
|
try {
|
|
@@ -10345,21 +10358,21 @@ function Rd(e) {
|
|
|
10345
10358
|
return null;
|
|
10346
10359
|
}
|
|
10347
10360
|
}
|
|
10348
|
-
function
|
|
10361
|
+
function Hd(e) {
|
|
10349
10362
|
if (!e) return null;
|
|
10350
|
-
let t =
|
|
10363
|
+
let t = Vd(e);
|
|
10351
10364
|
if (t == null) return null;
|
|
10352
|
-
let n =
|
|
10365
|
+
let n = Pd.safeParse(t);
|
|
10353
10366
|
return n.success ? n.data : null;
|
|
10354
10367
|
}
|
|
10355
|
-
async function
|
|
10368
|
+
async function Ud(e, t, n, r) {
|
|
10356
10369
|
let i = [...n];
|
|
10357
10370
|
for (let n = 0; n < 3; n++) {
|
|
10358
10371
|
let n = await e.invoke(i, { signal: r }), a = n?.tool_calls ?? [];
|
|
10359
|
-
if (!a.length) return
|
|
10372
|
+
if (!a.length) return Ld(n).trim();
|
|
10360
10373
|
i = [...i, n];
|
|
10361
10374
|
for (let e of a) {
|
|
10362
|
-
let n = e.id ??
|
|
10375
|
+
let n = e.id ?? Bd();
|
|
10363
10376
|
try {
|
|
10364
10377
|
let r = await t.invoke(e.args ?? {}), a = typeof r == "string" ? r : r?.content ?? JSON.stringify(r);
|
|
10365
10378
|
i = [...i, new s({
|
|
@@ -10376,10 +10389,10 @@ async function Bd(e, t, n, r) {
|
|
|
10376
10389
|
}
|
|
10377
10390
|
return "";
|
|
10378
10391
|
}
|
|
10379
|
-
function
|
|
10392
|
+
function Wd(e) {
|
|
10380
10393
|
let t = e.summaryLlm ?? e.llm;
|
|
10381
10394
|
if (!t) return;
|
|
10382
|
-
let n =
|
|
10395
|
+
let n = Id(t) ? t : null, r = Id(t) ? null : t;
|
|
10383
10396
|
if (r && !r.apiKey) return;
|
|
10384
10397
|
let i = e.decisionTimeoutMs ?? 6e3, s = e.decisionMaxTokens ?? 2048, c = n;
|
|
10385
10398
|
return async (e) => {
|
|
@@ -10391,12 +10404,12 @@ function Vd(e) {
|
|
|
10391
10404
|
}));
|
|
10392
10405
|
let n = c;
|
|
10393
10406
|
if (typeof n.bindTools != "function") return null;
|
|
10394
|
-
let i =
|
|
10407
|
+
let i = Nd({
|
|
10395
10408
|
getMessages: e.getMessages,
|
|
10396
10409
|
getSnapshot: e.getSnapshot,
|
|
10397
10410
|
contextWindow: e.contextWindow
|
|
10398
10411
|
}), 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)。`)];
|
|
10399
|
-
return
|
|
10412
|
+
return Hd(await Ud(l, i, d, t.signal)) || Hd(await Ud(l, i, [...d, new a("上一次输出无效(JSON 解析失败或 schema 校验不通过)。请只输出符合 schema 的压缩决策 JSON,不要多余文字/markdown 代码块。")], t.signal));
|
|
10400
10413
|
} catch {
|
|
10401
10414
|
return null;
|
|
10402
10415
|
} finally {
|
|
@@ -10404,8 +10417,8 @@ function Vd(e) {
|
|
|
10404
10417
|
}
|
|
10405
10418
|
};
|
|
10406
10419
|
}
|
|
10407
|
-
function
|
|
10408
|
-
let t = e.llm, n =
|
|
10420
|
+
function Gd(e) {
|
|
10421
|
+
let t = e.llm, n = Id(e.llm) ? void 0 : e.llm;
|
|
10409
10422
|
return {
|
|
10410
10423
|
modelCaps: Ci({
|
|
10411
10424
|
model: n?.model ?? t?.model ?? t?.modelName,
|
|
@@ -10413,14 +10426,14 @@ function Hd(e) {
|
|
|
10413
10426
|
maxOutputTokens: e.maxOutputTokens ?? n?.maxOutputTokens ?? t?.maxOutputTokens,
|
|
10414
10427
|
vision: n?.vision ?? t?.vision
|
|
10415
10428
|
}),
|
|
10416
|
-
summaryLlmInvoke:
|
|
10417
|
-
titleLlmInvoke:
|
|
10418
|
-
compressDecisionInvoke:
|
|
10429
|
+
summaryLlmInvoke: Rd(e),
|
|
10430
|
+
titleLlmInvoke: zd(e),
|
|
10431
|
+
compressDecisionInvoke: Wd(e)
|
|
10419
10432
|
};
|
|
10420
10433
|
}
|
|
10421
10434
|
//#endregion
|
|
10422
10435
|
//#region src/core/sdk/conflictManager.ts
|
|
10423
|
-
function
|
|
10436
|
+
function Kd(e, t) {
|
|
10424
10437
|
let n = /* @__PURE__ */ jt(null), r = 0;
|
|
10425
10438
|
function i(i) {
|
|
10426
10439
|
let a = t?.() ?? "ask";
|
|
@@ -10464,7 +10477,7 @@ function Ud(e, t) {
|
|
|
10464
10477
|
}
|
|
10465
10478
|
//#endregion
|
|
10466
10479
|
//#region src/core/utils/id.ts
|
|
10467
|
-
function
|
|
10480
|
+
function qd() {
|
|
10468
10481
|
try {
|
|
10469
10482
|
if (typeof crypto < "u" && typeof crypto.randomUUID == "function") return crypto.randomUUID();
|
|
10470
10483
|
} catch {}
|
|
@@ -10472,7 +10485,7 @@ function Wd() {
|
|
|
10472
10485
|
}
|
|
10473
10486
|
//#endregion
|
|
10474
10487
|
//#region src/core/backends/storage.ts
|
|
10475
|
-
var
|
|
10488
|
+
var Jd = "chat-sdk", Yd = 50 * 1024 * 1024, Xd = 4 * 1024 * 1024, Zd = 10 * 1024 * 1024, Qd = .9, $d = 500, ef = 300, tf = "__meta__", nf = "v:1", rf = [
|
|
10476
10489
|
"messages",
|
|
10477
10490
|
"vfs",
|
|
10478
10491
|
"todos",
|
|
@@ -10484,51 +10497,51 @@ var Gd = "chat-sdk", Kd = 50 * 1024 * 1024, qd = 4 * 1024 * 1024, Jd = 10 * 1024
|
|
|
10484
10497
|
"focus",
|
|
10485
10498
|
"planConfirmation"
|
|
10486
10499
|
];
|
|
10487
|
-
function
|
|
10488
|
-
return e === "local" || e === "session" ?
|
|
10500
|
+
function af(e) {
|
|
10501
|
+
return e === "local" || e === "session" ? Xd : Yd;
|
|
10489
10502
|
}
|
|
10490
|
-
function
|
|
10503
|
+
function of(e) {
|
|
10491
10504
|
if (typeof e != "object" || !e) return !1;
|
|
10492
10505
|
let t = e;
|
|
10493
10506
|
return t.name === "QuotaExceededError" || t.name === "NS_ERROR_DOM_QUOTA_REACHED" || t.code === 22 || t.code === 1014;
|
|
10494
10507
|
}
|
|
10495
|
-
function
|
|
10508
|
+
function sf(e, t, n, r) {
|
|
10496
10509
|
return [
|
|
10497
|
-
|
|
10510
|
+
nf,
|
|
10498
10511
|
e,
|
|
10499
10512
|
t,
|
|
10500
10513
|
n,
|
|
10501
10514
|
r
|
|
10502
10515
|
].join("::");
|
|
10503
10516
|
}
|
|
10504
|
-
function
|
|
10517
|
+
function cf(e, t, n) {
|
|
10505
10518
|
return [
|
|
10506
|
-
|
|
10519
|
+
nf,
|
|
10507
10520
|
e,
|
|
10508
10521
|
t,
|
|
10509
10522
|
n
|
|
10510
10523
|
].join("::") + "::";
|
|
10511
10524
|
}
|
|
10512
|
-
function
|
|
10525
|
+
function lf(e, t) {
|
|
10513
10526
|
return [
|
|
10514
|
-
|
|
10527
|
+
nf,
|
|
10515
10528
|
e,
|
|
10516
10529
|
t
|
|
10517
10530
|
].join("::") + "::";
|
|
10518
10531
|
}
|
|
10519
|
-
function
|
|
10520
|
-
return [
|
|
10532
|
+
function uf(e) {
|
|
10533
|
+
return [nf, e].join("::") + "::";
|
|
10521
10534
|
}
|
|
10522
|
-
var
|
|
10523
|
-
function
|
|
10524
|
-
|
|
10535
|
+
var df = null;
|
|
10536
|
+
function ff(e) {
|
|
10537
|
+
df ||= new TextEncoder();
|
|
10525
10538
|
try {
|
|
10526
|
-
return
|
|
10539
|
+
return df.encode(JSON.stringify(e)).length;
|
|
10527
10540
|
} catch {
|
|
10528
10541
|
return 0;
|
|
10529
10542
|
}
|
|
10530
10543
|
}
|
|
10531
|
-
function
|
|
10544
|
+
function pf(e, t, n) {
|
|
10532
10545
|
let r = e.reduce((e, t) => e + t.bytes, 0);
|
|
10533
10546
|
if (r <= t) return [];
|
|
10534
10547
|
let i = t * n, a = [...e].sort((e, t) => e.lastAccessed - t.lastAccessed), o = [];
|
|
@@ -10538,7 +10551,7 @@ function uf(e, t, n) {
|
|
|
10538
10551
|
}
|
|
10539
10552
|
return o;
|
|
10540
10553
|
}
|
|
10541
|
-
function
|
|
10554
|
+
function mf() {
|
|
10542
10555
|
let e = /* @__PURE__ */ new Map();
|
|
10543
10556
|
return {
|
|
10544
10557
|
async get(t) {
|
|
@@ -10558,7 +10571,7 @@ function df() {
|
|
|
10558
10571
|
}
|
|
10559
10572
|
};
|
|
10560
10573
|
}
|
|
10561
|
-
function
|
|
10574
|
+
function hf(e) {
|
|
10562
10575
|
return new Promise((t, n) => {
|
|
10563
10576
|
if (typeof indexedDB > "u") {
|
|
10564
10577
|
n(/* @__PURE__ */ Error("indexedDB 不可用"));
|
|
@@ -10619,7 +10632,7 @@ function ff(e) {
|
|
|
10619
10632
|
}, r.onerror = () => n(r.error);
|
|
10620
10633
|
});
|
|
10621
10634
|
}
|
|
10622
|
-
function
|
|
10635
|
+
function gf(e) {
|
|
10623
10636
|
return {
|
|
10624
10637
|
async get(t) {
|
|
10625
10638
|
let n = e.getItem(t);
|
|
@@ -10664,12 +10677,12 @@ function pf(e) {
|
|
|
10664
10677
|
}
|
|
10665
10678
|
};
|
|
10666
10679
|
}
|
|
10667
|
-
function
|
|
10680
|
+
function _f(e, t, n) {
|
|
10668
10681
|
let r = (e.get(t) ?? Promise.resolve()).then(n, n);
|
|
10669
10682
|
return e.set(t, r.then(() => void 0, () => void 0)), r;
|
|
10670
10683
|
}
|
|
10671
|
-
function
|
|
10672
|
-
let t = e.dbName ??
|
|
10684
|
+
function vf(e = {}) {
|
|
10685
|
+
let t = e.dbName ?? Jd, n = e.backend ?? "indexed", r = e.maxBytes ?? af(n), i = e.maxBytesPerSession ?? Zd, a = e.evictionWatermark ?? Qd, o = e.debounceMs ?? $d, s = /* @__PURE__ */ new Set();
|
|
10673
10686
|
function c(e) {
|
|
10674
10687
|
for (let t of s) try {
|
|
10675
10688
|
t(e);
|
|
@@ -10682,16 +10695,16 @@ function hf(e = {}) {
|
|
|
10682
10695
|
try {
|
|
10683
10696
|
if (n === "indexed") {
|
|
10684
10697
|
if (typeof indexedDB > "u") throw Error("indexedDB 不可用");
|
|
10685
|
-
l = await
|
|
10698
|
+
l = await hf(t), d(!0);
|
|
10686
10699
|
} else if (n === "session") {
|
|
10687
10700
|
if (typeof sessionStorage > "u") throw Error("sessionStorage 不可用");
|
|
10688
|
-
l =
|
|
10701
|
+
l = gf(sessionStorage), d(!0);
|
|
10689
10702
|
} else if (n === "local") {
|
|
10690
10703
|
if (typeof localStorage > "u") throw Error("localStorage 不可用");
|
|
10691
|
-
l =
|
|
10692
|
-
} else l =
|
|
10704
|
+
l = gf(localStorage), d(!0);
|
|
10705
|
+
} else l = mf(), d(!1);
|
|
10693
10706
|
} catch (e) {
|
|
10694
|
-
l =
|
|
10707
|
+
l = mf();
|
|
10695
10708
|
let t = e instanceof Error ? e.message : String(e);
|
|
10696
10709
|
d(!1), Promise.resolve().then(() => c({
|
|
10697
10710
|
type: "degraded",
|
|
@@ -10701,10 +10714,10 @@ function hf(e = {}) {
|
|
|
10701
10714
|
})();
|
|
10702
10715
|
let p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
|
|
10703
10716
|
function g(e, n, r, a) {
|
|
10704
|
-
let o =
|
|
10705
|
-
return
|
|
10717
|
+
let o = sf(t, r, a, tf);
|
|
10718
|
+
return _f(h, o, async () => {
|
|
10706
10719
|
let t = async () => {
|
|
10707
|
-
let t = await l.get(o), s = await l.get(e), u = s == null ? 0 :
|
|
10720
|
+
let t = await l.get(o), s = await l.get(e), u = s == null ? 0 : ff(s), d = ff(n), f = (t?.bytes ?? 0) + (d - u);
|
|
10708
10721
|
if (f > i) {
|
|
10709
10722
|
c({
|
|
10710
10723
|
type: "quota",
|
|
@@ -10726,12 +10739,12 @@ function hf(e = {}) {
|
|
|
10726
10739
|
try {
|
|
10727
10740
|
await t();
|
|
10728
10741
|
} catch (e) {
|
|
10729
|
-
if (
|
|
10742
|
+
if (of(e) && !u) {
|
|
10730
10743
|
u = !0;
|
|
10731
10744
|
try {
|
|
10732
10745
|
await b();
|
|
10733
10746
|
} catch {}
|
|
10734
|
-
l =
|
|
10747
|
+
l = mf(), Promise.resolve().then(() => c({
|
|
10735
10748
|
type: "degraded",
|
|
10736
10749
|
reason: "存储配额超限(QuotaExceededError),已淘汰最旧会话并降级内存"
|
|
10737
10750
|
}));
|
|
@@ -10743,7 +10756,7 @@ function hf(e = {}) {
|
|
|
10743
10756
|
});
|
|
10744
10757
|
}
|
|
10745
10758
|
function _(e, n, r, i) {
|
|
10746
|
-
let a =
|
|
10759
|
+
let a = sf(t, e, n, r), s = p.get(a);
|
|
10747
10760
|
s && s.resolve();
|
|
10748
10761
|
let c = m.get(a);
|
|
10749
10762
|
return c && clearTimeout(c), new Promise((t) => {
|
|
@@ -10770,15 +10783,15 @@ function hf(e = {}) {
|
|
|
10770
10783
|
function y() {
|
|
10771
10784
|
v ||= setTimeout(() => {
|
|
10772
10785
|
v = null, b();
|
|
10773
|
-
},
|
|
10786
|
+
}, ef);
|
|
10774
10787
|
}
|
|
10775
10788
|
async function b() {
|
|
10776
10789
|
let e = [];
|
|
10777
|
-
await l.scan(
|
|
10790
|
+
await l.scan(uf(t), (t, n) => {
|
|
10778
10791
|
t.endsWith("::__meta__") && e.push(n);
|
|
10779
10792
|
});
|
|
10780
|
-
let n =
|
|
10781
|
-
for (let e of n) await l.clearPrefix(
|
|
10793
|
+
let n = pf(e, r, a);
|
|
10794
|
+
for (let e of n) await l.clearPrefix(cf(t, e.agentId, e.sessionId)), c({
|
|
10782
10795
|
type: "evicted",
|
|
10783
10796
|
agentId: e.agentId,
|
|
10784
10797
|
sessionId: e.sessionId,
|
|
@@ -10789,13 +10802,13 @@ function hf(e = {}) {
|
|
|
10789
10802
|
ready: f,
|
|
10790
10803
|
async listSessions(e) {
|
|
10791
10804
|
let n = [];
|
|
10792
|
-
return await l.scan(
|
|
10805
|
+
return await l.scan(lf(t, e), (e, t) => {
|
|
10793
10806
|
e.endsWith("::__meta__") && n.push(t);
|
|
10794
10807
|
}), n.sort((e, t) => t.lastAccessed - e.lastAccessed);
|
|
10795
10808
|
},
|
|
10796
10809
|
async load(e, n) {
|
|
10797
|
-
let r =
|
|
10798
|
-
return await
|
|
10810
|
+
let r = sf(t, e, n, tf);
|
|
10811
|
+
return await _f(h, r, async () => {
|
|
10799
10812
|
let i = await l.get(r);
|
|
10800
10813
|
if (!i) return;
|
|
10801
10814
|
let a = {
|
|
@@ -10804,8 +10817,8 @@ function hf(e = {}) {
|
|
|
10804
10817
|
todos: [],
|
|
10805
10818
|
memory: ""
|
|
10806
10819
|
};
|
|
10807
|
-
for (let r of
|
|
10808
|
-
let i = await l.get(
|
|
10820
|
+
for (let r of rf) {
|
|
10821
|
+
let i = await l.get(sf(t, e, n, r));
|
|
10809
10822
|
i != null && (a[r] = i);
|
|
10810
10823
|
}
|
|
10811
10824
|
return i.lastAccessed = Date.now(), await l.set(r, i), a;
|
|
@@ -10813,12 +10826,12 @@ function hf(e = {}) {
|
|
|
10813
10826
|
},
|
|
10814
10827
|
async save(e, t, n) {
|
|
10815
10828
|
let r = [];
|
|
10816
|
-
for (let i of
|
|
10829
|
+
for (let i of rf) n[i] !== void 0 && r.push(_(e, t, i, n[i]));
|
|
10817
10830
|
await Promise.all(r);
|
|
10818
10831
|
},
|
|
10819
10832
|
async updateTitle(e, n, r) {
|
|
10820
|
-
let i =
|
|
10821
|
-
return
|
|
10833
|
+
let i = sf(t, e, n, tf);
|
|
10834
|
+
return _f(h, i, async () => {
|
|
10822
10835
|
let e = await l.get(i);
|
|
10823
10836
|
e && (e.title = r, e.lastAccessed = Date.now(), await l.set(i, e));
|
|
10824
10837
|
});
|
|
@@ -10834,13 +10847,13 @@ function hf(e = {}) {
|
|
|
10834
10847
|
})), c({ type: "flush" }), await b();
|
|
10835
10848
|
},
|
|
10836
10849
|
async deleteSession(e, n) {
|
|
10837
|
-
let r =
|
|
10850
|
+
let r = cf(t, e, n);
|
|
10838
10851
|
for (let [e, t] of p.entries()) e.startsWith(r) && (t.resolve(), p.delete(e));
|
|
10839
10852
|
for (let [e, t] of m.entries()) e.startsWith(r) && (clearTimeout(t), m.delete(e));
|
|
10840
10853
|
await l.clearPrefix(r);
|
|
10841
10854
|
},
|
|
10842
10855
|
async createSession(e, n, r) {
|
|
10843
|
-
let i = r ??
|
|
10856
|
+
let i = r ?? qd(), a = Date.now(), o = {
|
|
10844
10857
|
agentId: e,
|
|
10845
10858
|
sessionId: i,
|
|
10846
10859
|
createdAt: a,
|
|
@@ -10848,7 +10861,7 @@ function hf(e = {}) {
|
|
|
10848
10861
|
bytes: 0,
|
|
10849
10862
|
title: n
|
|
10850
10863
|
};
|
|
10851
|
-
return await l.set(
|
|
10864
|
+
return await l.set(sf(t, e, i, tf), o), i;
|
|
10852
10865
|
},
|
|
10853
10866
|
onEvent(e) {
|
|
10854
10867
|
s.add(e);
|
|
@@ -10863,15 +10876,15 @@ function hf(e = {}) {
|
|
|
10863
10876
|
}
|
|
10864
10877
|
//#endregion
|
|
10865
10878
|
//#region src/core/sdk/optionsResolver.ts
|
|
10866
|
-
function
|
|
10867
|
-
return e === void 0 ?
|
|
10879
|
+
function yf(e) {
|
|
10880
|
+
return e === void 0 ? vf({ backend: "memory" }) : e === !1 ? null : typeof e == "string" ? vf({ backend: e }) : e.enabled === !1 ? null : vf(e);
|
|
10868
10881
|
}
|
|
10869
|
-
function
|
|
10882
|
+
function bf(e) {
|
|
10870
10883
|
return e.dialog ?? {};
|
|
10871
10884
|
}
|
|
10872
10885
|
//#endregion
|
|
10873
10886
|
//#region src/core/capabilities.ts
|
|
10874
|
-
var
|
|
10887
|
+
var xf = [
|
|
10875
10888
|
{
|
|
10876
10889
|
name: "dataOps",
|
|
10877
10890
|
defaultOn: !0
|
|
@@ -10964,13 +10977,13 @@ var vf = [
|
|
|
10964
10977
|
defaultOn: !1
|
|
10965
10978
|
}
|
|
10966
10979
|
];
|
|
10967
|
-
function
|
|
10980
|
+
function Sf(e) {
|
|
10968
10981
|
let t = {};
|
|
10969
|
-
for (let n of
|
|
10982
|
+
for (let n of xf) {
|
|
10970
10983
|
let r = e?.[n.name];
|
|
10971
10984
|
t[n.name] = n.defaultOn ? r !== !1 : r === !0;
|
|
10972
10985
|
}
|
|
10973
|
-
for (let e of
|
|
10986
|
+
for (let e of xf) if (e.requires && t[e.name]) {
|
|
10974
10987
|
for (let n of e.requires) if (!t[n]) {
|
|
10975
10988
|
t[e.name] = !1;
|
|
10976
10989
|
break;
|
|
@@ -10980,7 +10993,7 @@ function yf(e) {
|
|
|
10980
10993
|
}
|
|
10981
10994
|
//#endregion
|
|
10982
10995
|
//#region src/core/sdk/events.ts
|
|
10983
|
-
function
|
|
10996
|
+
function Cf(e) {
|
|
10984
10997
|
let t = /* @__PURE__ */ new Set(), n = (n) => {
|
|
10985
10998
|
if (n.type !== "approval_request") {
|
|
10986
10999
|
if (e) try {
|
|
@@ -11006,7 +11019,7 @@ function bf(e) {
|
|
|
11006
11019
|
}
|
|
11007
11020
|
//#endregion
|
|
11008
11021
|
//#region src/core/sdk/contextPreset.ts
|
|
11009
|
-
var
|
|
11022
|
+
var wf = {
|
|
11010
11023
|
auto: {
|
|
11011
11024
|
summaryThresholdRatio: .5,
|
|
11012
11025
|
windowRatio: .4,
|
|
@@ -11034,7 +11047,7 @@ var xf = {
|
|
|
11034
11047
|
enableRecall: !0,
|
|
11035
11048
|
enableLLMSummary: !0
|
|
11036
11049
|
}
|
|
11037
|
-
},
|
|
11050
|
+
}, Tf = {
|
|
11038
11051
|
auto: ["describe_data", "read"],
|
|
11039
11052
|
conservative: ["describe_data"],
|
|
11040
11053
|
aggressive: ["describe_data", "read"],
|
|
@@ -11045,8 +11058,8 @@ var xf = {
|
|
|
11045
11058
|
"search_data"
|
|
11046
11059
|
]
|
|
11047
11060
|
};
|
|
11048
|
-
function
|
|
11049
|
-
let n =
|
|
11061
|
+
function Ef(e, t) {
|
|
11062
|
+
let n = wf[e.contextPreset ?? "auto"] ?? {}, r = e.contextOptions === !1 ? {} : e.contextOptions ?? {};
|
|
11050
11063
|
return {
|
|
11051
11064
|
...n,
|
|
11052
11065
|
...r,
|
|
@@ -11056,7 +11069,7 @@ function Cf(e, t) {
|
|
|
11056
11069
|
}
|
|
11057
11070
|
//#endregion
|
|
11058
11071
|
//#region src/core/sdk/middlewareStack.ts
|
|
11059
|
-
var
|
|
11072
|
+
var Df = {
|
|
11060
11073
|
dataHint: 10,
|
|
11061
11074
|
usageHints: 20,
|
|
11062
11075
|
todos: 30,
|
|
@@ -11073,17 +11086,17 @@ var wf = {
|
|
|
11073
11086
|
subagents: 140,
|
|
11074
11087
|
augmentSystem: 150
|
|
11075
11088
|
};
|
|
11076
|
-
function
|
|
11089
|
+
function Of(e) {
|
|
11077
11090
|
return e.map((e, t) => ({
|
|
11078
11091
|
m: e,
|
|
11079
11092
|
i: t,
|
|
11080
|
-
p:
|
|
11093
|
+
p: Df[e.name] ?? Infinity
|
|
11081
11094
|
})).sort((e, t) => e.p - t.p || e.i - t.i).map((e) => e.m);
|
|
11082
11095
|
}
|
|
11083
11096
|
//#endregion
|
|
11084
11097
|
//#region src/core/tools/fetchDoc.ts
|
|
11085
|
-
var
|
|
11086
|
-
let n = new AbortController(), r = setTimeout(() => n.abort(),
|
|
11098
|
+
var kf = 3e4, Af = [r(async ({ url: e, as: t }) => {
|
|
11099
|
+
let n = new AbortController(), r = setTimeout(() => n.abort(), kf);
|
|
11087
11100
|
try {
|
|
11088
11101
|
let r = await fetch(e, {
|
|
11089
11102
|
method: "GET",
|
|
@@ -11100,7 +11113,7 @@ var Ef = 3e4, Df = [r(async ({ url: e, as: t }) => {
|
|
|
11100
11113
|
].join("\n");
|
|
11101
11114
|
} catch (t) {
|
|
11102
11115
|
let r = t?.message || String(t);
|
|
11103
|
-
return n.signal.aborted ? `获取失败:请求超时(${
|
|
11116
|
+
return n.signal.aborted ? `获取失败:请求超时(${kf}ms,${e})。` : /Failed to fetch|NetworkError|CORS|blocked/i.test(r) ? `获取失败:可能是 CORS 跨域拦截或网络错误(${r})。浏览器仅能 GET 同源或服务端已配置 CORS 的资源;跨域抓取需后端代理。` : `获取失败:${r}`;
|
|
11104
11117
|
} finally {
|
|
11105
11118
|
clearTimeout(r);
|
|
11106
11119
|
}
|
|
@@ -11111,7 +11124,7 @@ var Ef = 3e4, Df = [r(async ({ url: e, as: t }) => {
|
|
|
11111
11124
|
url: t.string().describe("要抓取的 URL(同源或已配 CORS)"),
|
|
11112
11125
|
as: t.enum(["text", "markdown"]).optional().describe("返回格式标签,默认 text")
|
|
11113
11126
|
})
|
|
11114
|
-
})],
|
|
11127
|
+
})], jf = [
|
|
11115
11128
|
"id",
|
|
11116
11129
|
"class",
|
|
11117
11130
|
"href",
|
|
@@ -11123,12 +11136,12 @@ var Ef = 3e4, Df = [r(async ({ url: e, as: t }) => {
|
|
|
11123
11136
|
"aria-label",
|
|
11124
11137
|
"name",
|
|
11125
11138
|
"type"
|
|
11126
|
-
],
|
|
11127
|
-
function
|
|
11139
|
+
], Mf = /^(value|srcdoc|formaction|on\w+)$/i, Nf = /token|secret|password|passwd|api[-_]?key|auth|cred|csrf|session/i;
|
|
11140
|
+
function Pf(e, t) {
|
|
11128
11141
|
if (!e) return null;
|
|
11129
|
-
let { depth: n, attrs: r, includeText: i = !0 } = t, a = r !== void 0, o = r ??
|
|
11142
|
+
let { depth: n, attrs: r, includeText: i = !0 } = t, a = r !== void 0, o = r ?? jf, s = (e) => {
|
|
11130
11143
|
let t = {};
|
|
11131
|
-
for (let n of Array.from(e.attributes)) (a ? o.includes(n.name) : o.includes(n.name) || n.name.startsWith("data-")) && (
|
|
11144
|
+
for (let n of Array.from(e.attributes)) (a ? o.includes(n.name) : o.includes(n.name) || n.name.startsWith("data-")) && (Mf.test(n.name) || Nf.test(n.name) || (t[n.name] = n.value));
|
|
11132
11145
|
return t;
|
|
11133
11146
|
}, c = (e, t) => {
|
|
11134
11147
|
let n = {
|
|
@@ -11144,10 +11157,10 @@ function jf(e, t) {
|
|
|
11144
11157
|
};
|
|
11145
11158
|
return c(e, n);
|
|
11146
11159
|
}
|
|
11147
|
-
var
|
|
11160
|
+
var Ff = r(({ selector: e, depth: t, attrs: n, includeText: r }) => {
|
|
11148
11161
|
let i = e ? document.querySelector(e) : document.body;
|
|
11149
11162
|
if (!i) return `未找到匹配元素:selector="${e}"`;
|
|
11150
|
-
let a =
|
|
11163
|
+
let a = Pf(i, {
|
|
11151
11164
|
depth: t ?? 3,
|
|
11152
11165
|
attrs: n,
|
|
11153
11166
|
includeText: r ?? !0
|
|
@@ -11162,22 +11175,22 @@ var Mf = r(({ selector: e, depth: t, attrs: n, includeText: r }) => {
|
|
|
11162
11175
|
attrs: t.array(t.string()).optional().describe("属性白名单(传了 = 严格白名单;不传 = 默认常用 + data-*)"),
|
|
11163
11176
|
includeText: t.boolean().optional().describe("是否包含直接文本(默认 true)")
|
|
11164
11177
|
})
|
|
11165
|
-
}),
|
|
11166
|
-
function
|
|
11167
|
-
if (
|
|
11178
|
+
}), If = [Ff], Lf = /* @__PURE__ */ "display.position.visibility.opacity.color.background-color.background-image.font-size.font-weight.line-height.text-align.z-index.overflow.width.height.margin.padding.border.border-radius.box-shadow.transform.transition.animation.cursor.pointer-events.flex-direction.gap.max-width.min-height".split("."), Rf = /* @__PURE__ */ new WeakMap(), zf = !1;
|
|
11179
|
+
function Bf() {
|
|
11180
|
+
if (zf) return;
|
|
11168
11181
|
let e = globalThis.EventTarget;
|
|
11169
11182
|
if (!e?.prototype?.addEventListener) return;
|
|
11170
|
-
|
|
11183
|
+
zf = !0;
|
|
11171
11184
|
let t = e.prototype.addEventListener, n = e.prototype.removeEventListener;
|
|
11172
11185
|
e.prototype.addEventListener = function(e, ...n) {
|
|
11173
11186
|
try {
|
|
11174
|
-
let t =
|
|
11175
|
-
t || (t = /* @__PURE__ */ new Map(),
|
|
11187
|
+
let t = Rf.get(this);
|
|
11188
|
+
t || (t = /* @__PURE__ */ new Map(), Rf.set(this, t)), t.set(String(e), (t.get(String(e)) ?? 0) + 1);
|
|
11176
11189
|
} catch {}
|
|
11177
11190
|
return t.call(this, e, ...n);
|
|
11178
11191
|
}, e.prototype.removeEventListener = function(e, ...t) {
|
|
11179
11192
|
try {
|
|
11180
|
-
let t =
|
|
11193
|
+
let t = Rf.get(this);
|
|
11181
11194
|
if (t) {
|
|
11182
11195
|
let n = (t.get(String(e)) ?? 1) - 1;
|
|
11183
11196
|
n <= 0 ? t.delete(String(e)) : t.set(String(e), n);
|
|
@@ -11186,10 +11199,10 @@ function Lf() {
|
|
|
11186
11199
|
return n.call(this, e, ...t);
|
|
11187
11200
|
};
|
|
11188
11201
|
}
|
|
11189
|
-
function
|
|
11190
|
-
return [...
|
|
11202
|
+
function Vf(e) {
|
|
11203
|
+
return [...Rf.get(e)?.entries() ?? []].filter(([, e]) => e > 0).map(([e]) => e);
|
|
11191
11204
|
}
|
|
11192
|
-
function
|
|
11205
|
+
function Hf(e, t = 12) {
|
|
11193
11206
|
let n = [], r = e, i = 0;
|
|
11194
11207
|
for (; r && r.tagName && i < t;) {
|
|
11195
11208
|
let e = r.tagName.toLowerCase(), t = r.id;
|
|
@@ -11210,7 +11223,7 @@ function zf(e, t = 12) {
|
|
|
11210
11223
|
}
|
|
11211
11224
|
return n.join(" > ");
|
|
11212
11225
|
}
|
|
11213
|
-
function
|
|
11226
|
+
function Uf(e, t, n = {}) {
|
|
11214
11227
|
if (!e) return {
|
|
11215
11228
|
hits: [],
|
|
11216
11229
|
total: 0,
|
|
@@ -11248,7 +11261,7 @@ function Bf(e, t, n = {}) {
|
|
|
11248
11261
|
n = r.slice(Math.max(0, i - 20), i + t.length + 40);
|
|
11249
11262
|
}
|
|
11250
11263
|
return {
|
|
11251
|
-
selector:
|
|
11264
|
+
selector: Hf(e),
|
|
11252
11265
|
tag: e.tagName.toLowerCase(),
|
|
11253
11266
|
text: n.slice(0, 120)
|
|
11254
11267
|
};
|
|
@@ -11257,7 +11270,7 @@ function Bf(e, t, n = {}) {
|
|
|
11257
11270
|
truncated: a.length > o
|
|
11258
11271
|
};
|
|
11259
11272
|
}
|
|
11260
|
-
var
|
|
11273
|
+
var Wf = [
|
|
11261
11274
|
"content",
|
|
11262
11275
|
"display",
|
|
11263
11276
|
"width",
|
|
@@ -11265,14 +11278,14 @@ var Vf = [
|
|
|
11265
11278
|
"background-color",
|
|
11266
11279
|
"position"
|
|
11267
11280
|
];
|
|
11268
|
-
function
|
|
11281
|
+
function Gf(e, t = {}) {
|
|
11269
11282
|
if (!e) return null;
|
|
11270
11283
|
let n = {
|
|
11271
|
-
selector:
|
|
11284
|
+
selector: Hf(e),
|
|
11272
11285
|
tag: e.tagName.toLowerCase(),
|
|
11273
11286
|
attrs: {}
|
|
11274
11287
|
};
|
|
11275
|
-
for (let t of Array.from(e.attributes)) !(
|
|
11288
|
+
for (let t of Array.from(e.attributes)) !(jf.includes(t.name) || t.name.startsWith("data-")) || Mf.test(t.name) || Nf.test(t.name) || (n.attrs[t.name] = t.value);
|
|
11276
11289
|
let r = Array.from(e.childNodes).filter((e) => e.nodeType === 3).map((e) => e.textContent || "").join("").trim();
|
|
11277
11290
|
r && (n.text = r.slice(0, 400));
|
|
11278
11291
|
let i = String(e.innerText ?? e.textContent ?? "").trim();
|
|
@@ -11294,7 +11307,7 @@ function Hf(e, t = {}) {
|
|
|
11294
11307
|
if (typeof a != "function") return r;
|
|
11295
11308
|
try {
|
|
11296
11309
|
let i = a(e, n ?? null);
|
|
11297
|
-
for (let e of n ?
|
|
11310
|
+
for (let e of n ? Wf : t.styles ?? Lf) {
|
|
11298
11311
|
let t = typeof i.getPropertyValue == "function" ? i.getPropertyValue(e) : i[e];
|
|
11299
11312
|
t && (r[e] = String(t).slice(0, 200));
|
|
11300
11313
|
}
|
|
@@ -11312,16 +11325,16 @@ function Hf(e, t = {}) {
|
|
|
11312
11325
|
n.events = {
|
|
11313
11326
|
inline: t,
|
|
11314
11327
|
vue: r ? Object.keys(r).filter((e) => /^on[A-Z]/.test(e)).map((e) => e.slice(2).toLowerCase()) : [],
|
|
11315
|
-
captured:
|
|
11328
|
+
captured: Vf(e)
|
|
11316
11329
|
};
|
|
11317
11330
|
}
|
|
11318
11331
|
return n;
|
|
11319
11332
|
}
|
|
11320
|
-
var
|
|
11321
|
-
|
|
11333
|
+
var Kf = r(({ query: e, mode: t, limit: n, root: r }) => {
|
|
11334
|
+
Bf();
|
|
11322
11335
|
let i = r ? document.querySelector(r) : document;
|
|
11323
11336
|
if (r && !i) return `未找到 root 元素:selector="${r}"`;
|
|
11324
|
-
let a =
|
|
11337
|
+
let a = Uf(i, e, {
|
|
11325
11338
|
mode: t,
|
|
11326
11339
|
limit: n
|
|
11327
11340
|
});
|
|
@@ -11338,11 +11351,11 @@ var Uf = r(({ query: e, mode: t, limit: n, root: r }) => {
|
|
|
11338
11351
|
limit: t.number().int().min(1).max(20).optional().describe("返回上限(默认 10)"),
|
|
11339
11352
|
root: t.string().optional().describe("限定搜索范围的容器选择器(默认整页)")
|
|
11340
11353
|
})
|
|
11341
|
-
}),
|
|
11342
|
-
|
|
11354
|
+
}), qf = r(({ selector: e, styles: t, includeHtml: n, htmlLimit: r, includeEvents: i, includeRect: a, pseudo: o }) => {
|
|
11355
|
+
Bf();
|
|
11343
11356
|
let s = document.querySelector(e);
|
|
11344
11357
|
if (!s) return `未找到匹配元素:selector="${e}"(可先用 dom_search 定位)`;
|
|
11345
|
-
let c =
|
|
11358
|
+
let c = Gf(s, {
|
|
11346
11359
|
styles: t,
|
|
11347
11360
|
includeHtml: n,
|
|
11348
11361
|
htmlLimit: r,
|
|
@@ -11363,7 +11376,7 @@ var Uf = r(({ query: e, mode: t, limit: n, root: r }) => {
|
|
|
11363
11376
|
includeRect: t.boolean().optional().describe("是否含几何位置(默认 true)"),
|
|
11364
11377
|
pseudo: t.boolean().optional().describe("是否含 ::before/::after 伪元素摘要(默认 false)")
|
|
11365
11378
|
})
|
|
11366
|
-
}),
|
|
11379
|
+
}), Jf = {
|
|
11367
11380
|
name: "dom-inspect",
|
|
11368
11381
|
description: "页面 DOM 深度检视工具(dom_search 搜索元素 / dom_info 读内容·计算样式·事件绑定·几何)。定位元素、验证样式落地、排查交互绑定时加载",
|
|
11369
11382
|
getContent: () => [
|
|
@@ -11380,15 +11393,15 @@ var Uf = r(({ query: e, mode: t, limit: n, root: r }) => {
|
|
|
11380
11393
|
"## 排障套路",
|
|
11381
11394
|
"1. dom_search(mode:\"text\", query:按钮文案) 定位 → 2. dom_info(styles:[\"display\",\"background-color\",\"pointer-events\"]) 验证样式/点击性 → 3. 不符则改数据(get_dom 看结构对照)"
|
|
11382
11395
|
].join("\n"),
|
|
11383
|
-
tools: [() => [
|
|
11396
|
+
tools: [() => [Kf, qf]]
|
|
11384
11397
|
};
|
|
11385
11398
|
//#endregion
|
|
11386
11399
|
//#region src/core/tools/envTool.ts
|
|
11387
|
-
function
|
|
11400
|
+
function Yf(e) {
|
|
11388
11401
|
let t = e;
|
|
11389
11402
|
return typeof t.tagName == "string" || typeof t.nodeType == "number" && typeof t.nodeName == "string";
|
|
11390
11403
|
}
|
|
11391
|
-
function
|
|
11404
|
+
function Xf(e, t = 3, n = 2e3, r, i) {
|
|
11392
11405
|
if (e == null) return e;
|
|
11393
11406
|
if (typeof e == "string") return e.length > n ? e.slice(0, n) + "…(已截断)" : e;
|
|
11394
11407
|
if (typeof e == "number" || typeof e == "boolean") return e;
|
|
@@ -11397,14 +11410,14 @@ function qf(e, t = 3, n = 2e3, r, i) {
|
|
|
11397
11410
|
if (typeof e == "bigint") return `${e.toString()}n`;
|
|
11398
11411
|
if (typeof e != "object") return String(e);
|
|
11399
11412
|
let a = e;
|
|
11400
|
-
if (
|
|
11413
|
+
if (Yf(a)) {
|
|
11401
11414
|
let e = a;
|
|
11402
11415
|
return e.tagName ? `[Element: <${e.tagName.toLowerCase()}>]` : `[Node: ${e.nodeName}]`;
|
|
11403
11416
|
}
|
|
11404
11417
|
if (r?.has(a)) return "[Circular]";
|
|
11405
11418
|
let o = r ?? /* @__PURE__ */ new WeakSet();
|
|
11406
11419
|
if (o.add(a), Array.isArray(e)) {
|
|
11407
|
-
let r = e.slice(0, 100).map((e) =>
|
|
11420
|
+
let r = e.slice(0, 100).map((e) => Xf(e, t - 1, n, o, i));
|
|
11408
11421
|
return e.length > 100 && r.push(`…(共 ${e.length} 项,已截断)`), r;
|
|
11409
11422
|
}
|
|
11410
11423
|
if (t < 0) return "(对象,已截断)";
|
|
@@ -11417,14 +11430,14 @@ function qf(e, t = 3, n = 2e3, r, i) {
|
|
|
11417
11430
|
}
|
|
11418
11431
|
try {
|
|
11419
11432
|
let e = a[r];
|
|
11420
|
-
i?.test(r) ? s[r] = "[REDACTED]" : s[r] =
|
|
11433
|
+
i?.test(r) ? s[r] = "[REDACTED]" : s[r] = Xf(e, t - 1, n, o, i);
|
|
11421
11434
|
} catch {
|
|
11422
11435
|
s[r] = "(getter 抛错)";
|
|
11423
11436
|
}
|
|
11424
11437
|
}
|
|
11425
11438
|
return s;
|
|
11426
11439
|
}
|
|
11427
|
-
function
|
|
11440
|
+
function Zf(e) {
|
|
11428
11441
|
let t = e ?? (typeof window < "u" ? window : {}), n = t.navigator, r = t.location, i = t.document;
|
|
11429
11442
|
return {
|
|
11430
11443
|
location: {
|
|
@@ -11457,9 +11470,9 @@ function Jf(e) {
|
|
|
11457
11470
|
} : "(无 document)"
|
|
11458
11471
|
};
|
|
11459
11472
|
}
|
|
11460
|
-
var
|
|
11473
|
+
var Qf = /^(localStorage|sessionStorage|cookie|document|frames|frameElement|opener|parent|top|self|window|globalThis|closed|history|navigation|trustedTypes|origin|crossOriginIsolated)$/, $f = /token|secret|password|passwd|api[-_]?key|auth|cred|csrf|session|ticket/i, ep = r(({ key: e }) => {
|
|
11461
11474
|
if (e) {
|
|
11462
|
-
if (
|
|
11475
|
+
if (Qf.test(e) || $f.test(e)) return JSON.stringify({
|
|
11463
11476
|
key: e,
|
|
11464
11477
|
denied: !0,
|
|
11465
11478
|
reason: "安全:该 key 在 denylist(localStorage/sessionStorage/cookie/document 或敏感命名 token/secret/key/auth),不读取防泄漏"
|
|
@@ -11469,18 +11482,18 @@ var Yf = /^(localStorage|sessionStorage|cookie|document|frames|frameElement|open
|
|
|
11469
11482
|
key: e,
|
|
11470
11483
|
exists: t !== void 0,
|
|
11471
11484
|
type: typeof t,
|
|
11472
|
-
value:
|
|
11485
|
+
value: Xf(t, 3, 2e3, void 0, $f)
|
|
11473
11486
|
}, null, 2);
|
|
11474
11487
|
}
|
|
11475
|
-
return JSON.stringify(
|
|
11488
|
+
return JSON.stringify(Zf(), null, 2);
|
|
11476
11489
|
}, {
|
|
11477
11490
|
name: "inspect_env",
|
|
11478
11491
|
description: "读宿主页面环境信息(排查调试)。不传参返回摘要(URL/origin、浏览器/语言、viewport、title/readyState);传 key 读指定 window 属性值(如 key:\"appConfig\")。只读,大结果自动外存 vfs。",
|
|
11479
11492
|
schema: t.object({ key: t.string().optional().describe("要读取的 window 属性名(如 \"appConfig\"/\"__DEBUG__\");不传 = 返回环境摘要") })
|
|
11480
|
-
}),
|
|
11493
|
+
}), tp = [ep];
|
|
11481
11494
|
//#endregion
|
|
11482
11495
|
//#region src/core/harness/budget.ts
|
|
11483
|
-
function
|
|
11496
|
+
function np(e, t, n) {
|
|
11484
11497
|
let r = 0;
|
|
11485
11498
|
return {
|
|
11486
11499
|
name: "budget",
|
|
@@ -11505,12 +11518,12 @@ function $f(e, t, n) {
|
|
|
11505
11518
|
}
|
|
11506
11519
|
//#endregion
|
|
11507
11520
|
//#region src/core/sdk/actions.ts
|
|
11508
|
-
var
|
|
11509
|
-
function
|
|
11521
|
+
var rp = /^[a-zA-Z][a-zA-Z0-9_]*$/;
|
|
11522
|
+
function ip(e) {
|
|
11510
11523
|
let n = [];
|
|
11511
11524
|
for (let [i, a] of Object.entries(e)) {
|
|
11512
|
-
if (!
|
|
11513
|
-
console.warn(`[page-agent-sdk][actions] 动作名 "${i}" 非法(须匹配 ${
|
|
11525
|
+
if (!rp.test(i)) {
|
|
11526
|
+
console.warn(`[page-agent-sdk][actions] 动作名 "${i}" 非法(须匹配 ${rp}),已跳过`);
|
|
11514
11527
|
continue;
|
|
11515
11528
|
}
|
|
11516
11529
|
let e = a.description || `宿主动作 ${i}`;
|
|
@@ -11530,9 +11543,9 @@ function tp(e) {
|
|
|
11530
11543
|
}
|
|
11531
11544
|
return n;
|
|
11532
11545
|
}
|
|
11533
|
-
function
|
|
11546
|
+
function ap(e) {
|
|
11534
11547
|
let t = {};
|
|
11535
|
-
for (let [n, r] of Object.entries(e))
|
|
11548
|
+
for (let [n, r] of Object.entries(e)) rp.test(n) && (t[n] = {
|
|
11536
11549
|
description: r.description,
|
|
11537
11550
|
hasParams: !!r.params
|
|
11538
11551
|
});
|
|
@@ -11540,12 +11553,12 @@ function np(e) {
|
|
|
11540
11553
|
}
|
|
11541
11554
|
//#endregion
|
|
11542
11555
|
//#region src/core/toolsets.ts
|
|
11543
|
-
var
|
|
11544
|
-
function
|
|
11545
|
-
return
|
|
11556
|
+
var op = Af, sp = If;
|
|
11557
|
+
function cp(e, t) {
|
|
11558
|
+
return Gu(e, t);
|
|
11546
11559
|
}
|
|
11547
|
-
function
|
|
11548
|
-
let a =
|
|
11560
|
+
function lp(e, t, n, r, i) {
|
|
11561
|
+
let a = Sf(e);
|
|
11549
11562
|
return [
|
|
11550
11563
|
...a.dataOps ? t : [],
|
|
11551
11564
|
...a.fetch ? n : [],
|
|
@@ -11555,7 +11568,7 @@ function op(e, t, n, r, i) {
|
|
|
11555
11568
|
}
|
|
11556
11569
|
//#endregion
|
|
11557
11570
|
//#region src/core/sdk/toolRegistry.ts
|
|
11558
|
-
function
|
|
11571
|
+
function up(e) {
|
|
11559
11572
|
let t = /* @__PURE__ */ new Map(), n = [];
|
|
11560
11573
|
for (let r of e) for (let e of r.tools) {
|
|
11561
11574
|
let i = t.get(e.name);
|
|
@@ -11575,15 +11588,15 @@ function sp(e) {
|
|
|
11575
11588
|
}
|
|
11576
11589
|
//#endregion
|
|
11577
11590
|
//#region src/core/harness/usageHints.ts
|
|
11578
|
-
var
|
|
11579
|
-
function
|
|
11580
|
-
let r =
|
|
11591
|
+
var dp = .7;
|
|
11592
|
+
function fp(e, t, n) {
|
|
11593
|
+
let r = Sf(e);
|
|
11581
11594
|
return {
|
|
11582
11595
|
name: "usageHints",
|
|
11583
11596
|
augmentPrompt: (i) => {
|
|
11584
11597
|
let a = [];
|
|
11585
11598
|
if (r.planning && (a.push("【自适应规划】按任务复杂度决定是否先规划,不要对简单任务过度编排:"), a.push(" · 简单/明确任务(改单字段、调样式、查值)→ 直接 read/write 执行,不必 write_todos。"), a.push(" · 复杂任务(多步、大改、有歧义、不可逆)→ 先 write_todos 拆解,首个任务标 in_progress,逐项推进。"), a.push(" · 执行中发现步骤要改/补/细分 → 用 update_todo({id, content?, status?}) 按 id 增量改单项,不必重传整个清单。"), a.push(" · update_todo 标 completed 时附 evidence: 本次实际写入的 jsonPath(如 \"components.2\"),供收口对账;工作经委派子 agent 完成等无主写路径时,如实写明完成方式(勿编造路径)。"), e?.humanConfirm ? a.push(" · 规划出多步方案若需用户拍板 → 先 request_human_confirmation 给方案选项,确认后再执行。") : a.push(" · 规划出多步方案若需用户拍板 → 以文字列出方案选项等用户回复,勿自行拍板。"), a.push(" · 计划修订有次数上限(maxPlanRevisions,默认 5,只计 write_todos 调用、调研轮不计):勿反复改计划而不执行,规划充分后即开始 write 落地。")), t && (a.push("改主数据前先 get_data({jsonPath}) 读其当前真实值(返回末尾 hash=xxx 为乐观锁标识),基于真实值改,不要凭记忆。写入是否被自动校验由集成方 conflictWatchFields 声明决定:若已声明且主数据在你 read 之后被外部改过,会触发冲突——集成方若开启人工介入,工具会挂起等用户决定(保留外部/强制覆盖/回退),你应等待工具返回后按结果继续(保留外部→重新 get 再改;强制覆盖→已写入,继续;回退→已回退到历史快照,基于回退值重写);未开启人工介入时返回 VERSION_CONFLICT 不写入,重新 get 拿最新值再改。"), a.push("不确定主数据字段结构时用 describe_data 查看说明。"), a.push("修改大对象/数组优先用 edit_data 增量 patch(只发改动部分),避免 set_data 整体重传被 max_tokens 截断导致 JSON 不完整、校验失败。"), a.push("修改主数据出错时可用 restore_data 回退最近一次。"), a.push("在大数组里按条件筛选元素用 query_data(JSONPath,如 $.components[?(@.type==\"card\" && @.price<100)]),返回匹配元素的 path/index;定位后再 edit_data 改。"), a.push("找名字记不清的元素用 search_data(支持 substring/regex/fuzzy 模糊搜索)。"), a.push("需要过滤/映射/聚合/批量重写大数组时用 eval_script(沙箱脚本,入参 data);只读探查用 mode=query,批量重写用 mode=transform(返回值经校验后落地)。"), a.push("读大数组用 read({jsonPath,offset,limit}) 分页(返回 hasMore=true 时 offset+=limit 续读);一次读多个不相关子路径用 read({jsonPaths});复杂改动先 write({...,dryRun:true}) 预检不落盘。"), a.push("【省轮次·批量】读多个同构子路径(如各组件 props)用 read({jsonPaths:[...]}) 一次取回,勿发多个独立 read;改多处用 write({patches:[{op:\"set\",jsonPath,value},...]}) 一次提交多改动(原子任一失败回滚),勿逐个 edit_data/write 烧轮次预算。"), a.push("对比当前与历史快照(或一段 JSON against)的差异用 diff_data({snapshotId?,against?})(返回结构化 path→from/to,verify 自纠/操作审计/\"刚才改了啥\");只读查历史快照值用 history_data({id?,jsonPath?})。")), r.subagent && a.push("独立子任务可 spawn_agent 委派(过程隔离,不占主上下文):默认只读,需要子 agent 写数据时传 writablePaths(路径前缀白名单,越界 PATH_OUT_OF_SCOPE)。多个独立子任务可 spawn_agents 并行委派(各子互不通信,结论由你汇总;并行委派不可授写权限,写操作由你收尾执行)。"), r.inspectEnv && a.push("排查页面环境(当前 URL/浏览器/视口/集成方调试变量)用 inspect_env——不传参返回环境摘要(location/navigator/viewport/document),传 key 读特定 window 属性(如 inspect_env({key:\"appConfig\"}) 读 window.appConfig)。改完数据看渲染、定位\"为何没生效\"时用它(只读,不改数据)。"), r.domInspect && a.push("改完数据想确认渲染是否生效(或定位元素/辅助 UI 设计问答)用 get_dom({selector?,depth?}) 读渲染后 DOM(结构化返回 tag/attrs/text/children,depth 控制深度防爆炸,只读)。配合宿主 actions(save_draft/publish 等)形成\"改数据→get_dom 看渲染→触发动作\"闭环。"), r.draftWrite && (a.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。"), a.push("⚠️ 大 JSON 分块构建是典型多轮工具调用(draft_write×N + draft_commit + read 确认 + 调研 read/query),默认 maxToolRounds=30(3.43 起;轮次预算吃紧时 system 会注入预算提示段,按提示优先收口);目标组件数很大时集成方仍可在 createChatSdk 显式上调 maxToolRounds(按 N+10 估算)。draft_commit 提交同样走乐观锁(改前 read 拿 hash,bind 被改过会触发冲突介入,不静默覆盖)。")), r.todoDeps && a.push("复杂任务可用 todos 层级依赖:write_todos 时给 todo 传 parentId(父任务 id,表达层级)+ deps(依赖的 todo id 数组,必须先完成)。有依赖的任务,deps 全 completed 后再标 in_progress;完成时 update_todo({id, status:\"completed\", evidence:\"完成证据\"}) 记证据。无依赖关系的任务不传 parentId/deps(扁平)。"), r.focus && (a.push("【上下文聚焦】判断任务范围,用 set_focus/add_focus/remove_focus/clear_focus 自动收敛工作范围:"), a.push(" · 局部任务(只改某一组件/区域,如「调导航栏」「改 components.3 样式」)→ 先 read 定位 jsonPath,再 set_focus({path:\"该子树路径\"}) 聚焦;聚焦后每轮只看该子树结构,写其他位置会被 PATH_DENIED 拒绝。"), a.push(" · 多个相关组件(如「同时改导航栏和页脚」)→ set_focus 聚焦首个后用 add_focus({path}) 追加其余;聚焦后可写任一焦点子树,越界仍被拒;移除单个用 remove_focus({path})。"), a.push(" · 全局任务(多处/整体结构,如「重排所有组件」「换主题」)→ 不要聚焦,保持全量视野直接写。"), a.push(" · 完成局部精修、要转向其他区域或做整体改动 → 调 clear_focus 退出聚焦(清空全部焦点),恢复全部读写权限。"), a.push(" · set_focus/add_focus 的 path 必须在 schema 内(类型校验);不确定路径先 read/describe_data 查。")), e?.subagents?.length) {
|
|
11586
|
-
let t = e.subagents.filter((e) => (e.temperature ?? 0) >=
|
|
11599
|
+
let t = e.subagents.filter((e) => (e.temperature ?? 0) >= dp || /规划|创意|设计|方案|brainstorm|plan/i.test(e.description)), n = e.subagents.filter((e) => (e.temperature ?? 0) < dp && /反思|审查|挑刺|校验|review|critique|reflect/i.test(e.description));
|
|
11587
11600
|
a.push("【规划-反思-执行·路由】按任务性质选模式,不要对简单任务过度编排:"), t.length && (a.push(` · 创作/设计/开放性需求(如"设计主题风格""换个感觉")→ 先调 ${t.map((e) => "use_" + e.id).join("/")} 出 2-3 套方案(高温创意),`), a.push(e?.humanConfirm ? " 不要自己拍板;拿到方案后,若需用户拍板用 request_human_confirmation 弹选项。" : " 不要自己拍板;拿到方案后以文字列出选项等用户回复(humanConfirm 未开,勿调不存在工具)。")), n.length && a.push(` · 严谨/易错/校验类 → 可先调 ${n.map((e) => "use_" + e.id).join("/")} 反思挑刺(低温审查),据反馈修订。`), a.push(" · 方案定稿后,由你(主 agent)用 edit_data 落地成 JSON(低温度执行 + schema 校验 + 写前确认)。"), a.push(" · 简单/明确任务(如\"标题改红色\")直接执行,不必走规划-反思。");
|
|
11588
11601
|
}
|
|
11589
11602
|
e?.humanConfirm && (a.push("【人工确认·必读】以下情形必须先调 request_human_confirmation 征询用户、拿到答复后再继续,不要自行拍板:"), a.push(" 1) 用户让你「给方案/列选项/我来选/挑一个」时:把每个方案作为一个 option,调 request_human_confirmation(question=简述, options=[方案A,方案B,...], recommendation=你推荐的)。不要只回文字罗列方案让用户自己回复——要用工具把选项做成可点选按钮。"), a.push(" 2) 需求有歧义/不确定时:调工具问清楚(options 不传则用户答同意或拒绝)。"), a.push(" 3) 即将执行高风险不可逆操作(删除/覆盖/批量改动)前:调工具确认。"), a.push(" 4) 规划出多步方案需用户确认时:把整个方案(或关键分步)作为 option 调 request_human_confirmation,确认后再执行。"), a.push("用户在选项里选了哪个,就按那个方案继续;选「拒绝」则停止并询问如何调整。"));
|
|
@@ -11603,7 +11616,7 @@ function lp(e, t, n) {
|
|
|
11603
11616
|
}
|
|
11604
11617
|
//#endregion
|
|
11605
11618
|
//#region src/core/harness/resourcesPin.ts
|
|
11606
|
-
function
|
|
11619
|
+
function pp(e) {
|
|
11607
11620
|
return {
|
|
11608
11621
|
name: "resourcesPin",
|
|
11609
11622
|
augmentPrompt: () => {
|
|
@@ -11617,102 +11630,102 @@ function up(e) {
|
|
|
11617
11630
|
}
|
|
11618
11631
|
//#endregion
|
|
11619
11632
|
//#region src/core/backends/skillStore.ts
|
|
11620
|
-
var
|
|
11621
|
-
function
|
|
11622
|
-
return `${
|
|
11633
|
+
var mp = "v:1::skill-store", hp = "chat-sdk";
|
|
11634
|
+
function gp(e, t, n) {
|
|
11635
|
+
return `${mp}::${e}::${t}::${n}`;
|
|
11623
11636
|
}
|
|
11624
|
-
function
|
|
11625
|
-
return `${
|
|
11637
|
+
function _p(e, t) {
|
|
11638
|
+
return `${mp}::${e}::${t}::`;
|
|
11626
11639
|
}
|
|
11627
|
-
function
|
|
11628
|
-
let t = e.dbName ??
|
|
11640
|
+
function vp(e = {}) {
|
|
11641
|
+
let t = e.dbName ?? hp, n = e.backend ?? "indexed", r = e.id ?? "", i, a, o = new Promise((e) => {
|
|
11629
11642
|
a = e;
|
|
11630
11643
|
});
|
|
11631
11644
|
return (async () => {
|
|
11632
11645
|
try {
|
|
11633
11646
|
if (n === "indexed") {
|
|
11634
11647
|
if (typeof indexedDB > "u") throw Error("indexedDB 不可用");
|
|
11635
|
-
i = await
|
|
11648
|
+
i = await hf(t), a(!0);
|
|
11636
11649
|
} else if (n === "session") {
|
|
11637
11650
|
if (typeof sessionStorage > "u") throw Error("sessionStorage 不可用");
|
|
11638
|
-
i =
|
|
11651
|
+
i = gf(sessionStorage), a(!0);
|
|
11639
11652
|
} else if (n === "local") {
|
|
11640
11653
|
if (typeof localStorage > "u") throw Error("localStorage 不可用");
|
|
11641
|
-
i =
|
|
11642
|
-
} else i =
|
|
11654
|
+
i = gf(localStorage), a(!0);
|
|
11655
|
+
} else i = mf(), a(!1);
|
|
11643
11656
|
} catch {
|
|
11644
|
-
i =
|
|
11657
|
+
i = mf(), a(!1);
|
|
11645
11658
|
}
|
|
11646
11659
|
})(), {
|
|
11647
11660
|
ready: o,
|
|
11648
11661
|
async list() {
|
|
11649
11662
|
let e = [];
|
|
11650
|
-
return await i.scan(
|
|
11663
|
+
return await i.scan(_p(t, r), (t, n) => {
|
|
11651
11664
|
e.push(n);
|
|
11652
11665
|
}), e;
|
|
11653
11666
|
},
|
|
11654
11667
|
async get(e) {
|
|
11655
|
-
return await i.get(
|
|
11668
|
+
return await i.get(gp(t, r, e));
|
|
11656
11669
|
},
|
|
11657
11670
|
async put(e) {
|
|
11658
11671
|
try {
|
|
11659
|
-
await i.set(
|
|
11672
|
+
await i.set(gp(t, r, e.name), e);
|
|
11660
11673
|
} catch (e) {
|
|
11661
|
-
|
|
11674
|
+
of(e) && (i = mf());
|
|
11662
11675
|
}
|
|
11663
11676
|
},
|
|
11664
11677
|
async remove(e) {
|
|
11665
|
-
let n =
|
|
11678
|
+
let n = gp(t, r, e);
|
|
11666
11679
|
return await i.get(n) == null ? !1 : (await i.del(n), !0);
|
|
11667
11680
|
},
|
|
11668
11681
|
async clear() {
|
|
11669
|
-
await i.clearPrefix(
|
|
11682
|
+
await i.clearPrefix(_p(t, r));
|
|
11670
11683
|
},
|
|
11671
11684
|
dispose() {}
|
|
11672
11685
|
};
|
|
11673
11686
|
}
|
|
11674
11687
|
//#endregion
|
|
11675
11688
|
//#region src/core/backends/preferenceStore.ts
|
|
11676
|
-
var
|
|
11689
|
+
var yp = [
|
|
11677
11690
|
"color",
|
|
11678
11691
|
"copy",
|
|
11679
11692
|
"layout",
|
|
11680
11693
|
"interaction",
|
|
11681
11694
|
"tech",
|
|
11682
11695
|
"other"
|
|
11683
|
-
],
|
|
11684
|
-
function
|
|
11685
|
-
return `${
|
|
11696
|
+
], bp = "v:1::pref-store", xp = "chat-sdk";
|
|
11697
|
+
function Sp(e, t, n) {
|
|
11698
|
+
return `${bp}::${e}::${t}::${n}`;
|
|
11686
11699
|
}
|
|
11687
|
-
function
|
|
11688
|
-
return `${
|
|
11700
|
+
function Cp(e, t) {
|
|
11701
|
+
return `${bp}::${e}::${t}::`;
|
|
11689
11702
|
}
|
|
11690
|
-
function
|
|
11703
|
+
function wp() {
|
|
11691
11704
|
return `pref-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
11692
11705
|
}
|
|
11693
|
-
function
|
|
11694
|
-
let t = e.dbName ??
|
|
11706
|
+
function Tp(e = {}) {
|
|
11707
|
+
let t = e.dbName ?? xp, n = e.backend ?? "indexed", r = e.id ?? "", i = e.maxEntries ?? 20, a, o, s = new Promise((e) => {
|
|
11695
11708
|
o = e;
|
|
11696
11709
|
});
|
|
11697
11710
|
(async () => {
|
|
11698
11711
|
try {
|
|
11699
11712
|
if (n === "indexed") {
|
|
11700
11713
|
if (typeof indexedDB > "u") throw Error("indexedDB 不可用");
|
|
11701
|
-
a = await
|
|
11714
|
+
a = await hf(t), o(!0);
|
|
11702
11715
|
} else if (n === "session") {
|
|
11703
11716
|
if (typeof sessionStorage > "u") throw Error("sessionStorage 不可用");
|
|
11704
|
-
a =
|
|
11717
|
+
a = gf(sessionStorage), o(!0);
|
|
11705
11718
|
} else if (n === "local") {
|
|
11706
11719
|
if (typeof localStorage > "u") throw Error("localStorage 不可用");
|
|
11707
|
-
a =
|
|
11708
|
-
} else a =
|
|
11720
|
+
a = gf(localStorage), o(!0);
|
|
11721
|
+
} else a = mf(), o(!1);
|
|
11709
11722
|
} catch {
|
|
11710
|
-
a =
|
|
11723
|
+
a = mf(), o(!1);
|
|
11711
11724
|
}
|
|
11712
11725
|
})();
|
|
11713
11726
|
async function c() {
|
|
11714
11727
|
let e = [];
|
|
11715
|
-
return await a.scan(
|
|
11728
|
+
return await a.scan(Cp(t, r), (t, n) => {
|
|
11716
11729
|
e.push(n);
|
|
11717
11730
|
}), e;
|
|
11718
11731
|
}
|
|
@@ -11723,7 +11736,7 @@ function Sp(e = {}) {
|
|
|
11723
11736
|
},
|
|
11724
11737
|
async put(e) {
|
|
11725
11738
|
let n = await c(), o = Date.now(), s = n.reduce((e, t) => Math.max(e, t.updatedAt), 0), l = n.find((t) => t.topic === e.topic), u = {
|
|
11726
|
-
id: e.id ?? l?.id ??
|
|
11739
|
+
id: e.id ?? l?.id ?? wp(),
|
|
11727
11740
|
content: e.content,
|
|
11728
11741
|
topic: e.topic,
|
|
11729
11742
|
sourceSessionId: l?.sourceSessionId ?? e.sourceSessionId,
|
|
@@ -11731,71 +11744,71 @@ function Sp(e = {}) {
|
|
|
11731
11744
|
createdAt: l?.createdAt ?? o,
|
|
11732
11745
|
updatedAt: Math.max(o, s + 1)
|
|
11733
11746
|
};
|
|
11734
|
-
l && l.id !== u.id && await a.del(
|
|
11747
|
+
l && l.id !== u.id && await a.del(Sp(t, r, l.id));
|
|
11735
11748
|
try {
|
|
11736
|
-
await a.set(
|
|
11749
|
+
await a.set(Sp(t, r, u.id), u);
|
|
11737
11750
|
} catch (e) {
|
|
11738
|
-
|
|
11751
|
+
of(e) && (a = mf(), await a.set(Sp(t, r, u.id), u));
|
|
11739
11752
|
}
|
|
11740
11753
|
let d = await c();
|
|
11741
11754
|
if (d.length > i) {
|
|
11742
11755
|
let e = d.sort((e, t) => e.updatedAt - t.updatedAt).slice(0, d.length - i);
|
|
11743
|
-
for (let n of e) await a.del(
|
|
11756
|
+
for (let n of e) await a.del(Sp(t, r, n.id));
|
|
11744
11757
|
}
|
|
11745
11758
|
return u;
|
|
11746
11759
|
},
|
|
11747
11760
|
async remove(e) {
|
|
11748
|
-
let n =
|
|
11761
|
+
let n = Sp(t, r, e);
|
|
11749
11762
|
return await a.get(n) == null ? !1 : (await a.del(n), !0);
|
|
11750
11763
|
},
|
|
11751
11764
|
async clear() {
|
|
11752
|
-
await a.clearPrefix(
|
|
11765
|
+
await a.clearPrefix(Cp(t, r));
|
|
11753
11766
|
},
|
|
11754
11767
|
dispose() {}
|
|
11755
11768
|
};
|
|
11756
11769
|
}
|
|
11757
11770
|
//#endregion
|
|
11758
11771
|
//#region src/core/harness/preferences.ts
|
|
11759
|
-
var
|
|
11772
|
+
var Ep = {
|
|
11760
11773
|
color: "颜色",
|
|
11761
11774
|
copy: "文案",
|
|
11762
11775
|
layout: "排版",
|
|
11763
11776
|
interaction: "交互",
|
|
11764
11777
|
tech: "技术",
|
|
11765
11778
|
other: "其他"
|
|
11766
|
-
},
|
|
11779
|
+
}, Dp = [
|
|
11767
11780
|
/^(?:请|帮我|麻烦)?你?记住[::,,、]?\s*(.{4,200})/,
|
|
11768
11781
|
/^(?:从)?今后(?:开始|起)?[::,,]?\s*(.{4,200})/,
|
|
11769
11782
|
/^以后(?:都|全都|总是|尽量)?[::,,]?\s*(.{4,200})/
|
|
11770
|
-
],
|
|
11783
|
+
], Op = /(?:不要|别再|别用|别加|太(?:艳|花|亮|暗|大|小|密|挤|乱|复杂|素|少)|不喜欢|讨厌|希望|更喜欢|偏好|永远|一律|统一保持|保持统一)/, kp = [
|
|
11771
11784
|
["layout", /布局|排版|间距|留白|密度|居中|对齐|栅格|边距|紧凑|圆角|分栏|层级|大小|尺寸/],
|
|
11772
11785
|
["copy", /文案|文字|标题|副标题|字体|字号|措辞|语气|口语|书面|简洁|简短|详尽|emoji|表情/],
|
|
11773
11786
|
["interaction", /动画|动效|过渡|交互|悬停|hover|点击反馈|弹窗|提示|加载|滚动/],
|
|
11774
11787
|
["tech", /代码|框架|组件|技术|写法|命名|注释|依赖|版本|接口/],
|
|
11775
11788
|
["color", /颜色|配色|色调|色彩|深色|浅色|饱和|渐变|紫|红|橙|黄|绿|青|蓝|粉|棕|灰|黑|白|金|银/]
|
|
11776
11789
|
];
|
|
11777
|
-
function
|
|
11778
|
-
for (let [t, n] of
|
|
11790
|
+
function Ap(e) {
|
|
11791
|
+
for (let [t, n] of kp) if (n.test(e)) return t;
|
|
11779
11792
|
return "other";
|
|
11780
11793
|
}
|
|
11781
|
-
function
|
|
11794
|
+
function jp(e) {
|
|
11782
11795
|
let t = e.trim();
|
|
11783
|
-
if (!(!t || t.length > 500)) for (let e of
|
|
11796
|
+
if (!(!t || t.length > 500)) for (let e of Dp) {
|
|
11784
11797
|
let n = t.match(e);
|
|
11785
11798
|
if (n?.[1]) {
|
|
11786
11799
|
let e = n[1].trim().replace(/[。.!!]+$/, "");
|
|
11787
11800
|
return e.length < 3 ? void 0 : {
|
|
11788
11801
|
content: e,
|
|
11789
|
-
topic:
|
|
11802
|
+
topic: Ap(e)
|
|
11790
11803
|
};
|
|
11791
11804
|
}
|
|
11792
11805
|
}
|
|
11793
11806
|
}
|
|
11794
|
-
function
|
|
11807
|
+
function Mp(e) {
|
|
11795
11808
|
let t = e.trim();
|
|
11796
|
-
return t.length < 4 || t.length > 500 || /^(你好|hi|hello|ok|好的|继续|嗯|谢谢|hey|哈喽|收到|明白)/i.test(t) ? !1 :
|
|
11809
|
+
return t.length < 4 || t.length > 500 || /^(你好|hi|hello|ok|好的|继续|嗯|谢谢|hey|哈喽|收到|明白)/i.test(t) ? !1 : Op.test(t);
|
|
11797
11810
|
}
|
|
11798
|
-
function
|
|
11811
|
+
function Np(e) {
|
|
11799
11812
|
return [
|
|
11800
11813
|
"你是用户偏好提取器。判断下面的用户消息是否包含「持久偏好」—— 对未来同类工作都适用的口味/规则(如配色口味、文案风格、排版密度),而非仅针对本轮的任务指令。",
|
|
11801
11814
|
"只输出 JSON(无任何其他文本):{\"captured\": true, \"content\": \"一句话中性陈述(用户视角,如:不用紫色,偏好低饱和)\", \"topic\": \"color|copy|layout|interaction|tech|other\"} 或 {\"captured\": false, \"content\": \"\", \"topic\": \"other\"}",
|
|
@@ -11804,7 +11817,7 @@ function Ap(e) {
|
|
|
11804
11817
|
`用户消息:"""${e.slice(0, 800)}"""`
|
|
11805
11818
|
].join("\n");
|
|
11806
11819
|
}
|
|
11807
|
-
function
|
|
11820
|
+
function Pp(e) {
|
|
11808
11821
|
if (!e) return;
|
|
11809
11822
|
let t = (e.match(/```(?:json)?\s*([\s\S]*?)```/)?.[1] ?? e).match(/\{[\s\S]*\}/)?.[0];
|
|
11810
11823
|
if (t) try {
|
|
@@ -11813,19 +11826,19 @@ function jp(e) {
|
|
|
11813
11826
|
let n = typeof e.content == "string" ? e.content.trim().replace(/[。.!!]+$/, "") : "";
|
|
11814
11827
|
return n.length < 3 || n.length > 200 ? void 0 : {
|
|
11815
11828
|
content: n,
|
|
11816
|
-
topic:
|
|
11829
|
+
topic: yp.includes(e.topic) ? e.topic : "other"
|
|
11817
11830
|
};
|
|
11818
11831
|
} catch {
|
|
11819
11832
|
return;
|
|
11820
11833
|
}
|
|
11821
11834
|
}
|
|
11822
|
-
function
|
|
11835
|
+
function Fp(e) {
|
|
11823
11836
|
if (!e.length) return;
|
|
11824
11837
|
let t = ["## 用户偏好(跨会话沉淀;除非用户本轮另有指示,遵守以下偏好)"];
|
|
11825
|
-
for (let n of e) t.push(`- ${
|
|
11838
|
+
for (let n of e) t.push(`- ${Ep[n.topic]}:${n.content}`);
|
|
11826
11839
|
return t.join("\n");
|
|
11827
11840
|
}
|
|
11828
|
-
function
|
|
11841
|
+
function Ip(e) {
|
|
11829
11842
|
let t = [], n = -1, r = Promise.resolve(), i = (t) => e.onDebug?.({
|
|
11830
11843
|
stage: "preferences",
|
|
11831
11844
|
...t
|
|
@@ -11846,21 +11859,21 @@ function Np(e) {
|
|
|
11846
11859
|
}
|
|
11847
11860
|
return {
|
|
11848
11861
|
name: "preferences",
|
|
11849
|
-
augmentPrompt: () =>
|
|
11862
|
+
augmentPrompt: () => Fp(t),
|
|
11850
11863
|
afterAgent: (t) => {
|
|
11851
11864
|
let r = t.messages ?? [];
|
|
11852
11865
|
for (let t = n + 1; t < r.length; t++) {
|
|
11853
11866
|
let n = r[t];
|
|
11854
11867
|
if (n.role !== "user" || typeof n.content != "string" || !n.content) continue;
|
|
11855
|
-
let o = n.content, s =
|
|
11868
|
+
let o = n.content, s = jp(o);
|
|
11856
11869
|
if (s) {
|
|
11857
11870
|
a(s.content, s.topic, t, "explicit");
|
|
11858
11871
|
continue;
|
|
11859
11872
|
}
|
|
11860
|
-
if (e.llmInvoke &&
|
|
11873
|
+
if (e.llmInvoke && Mp(o)) {
|
|
11861
11874
|
let n = t;
|
|
11862
|
-
e.llmInvoke(
|
|
11863
|
-
let t =
|
|
11875
|
+
e.llmInvoke(Np(o)).then((e) => {
|
|
11876
|
+
let t = Pp(e);
|
|
11864
11877
|
t && a(t.content, t.topic, n, "llm");
|
|
11865
11878
|
}).catch((e) => i({ extractError: String(e) }));
|
|
11866
11879
|
}
|
|
@@ -11883,12 +11896,12 @@ function Np(e) {
|
|
|
11883
11896
|
}
|
|
11884
11897
|
};
|
|
11885
11898
|
}
|
|
11886
|
-
var
|
|
11887
|
-
function
|
|
11899
|
+
var Lp = /large_results\/[^\s"'`),]+\.txt/g;
|
|
11900
|
+
function Rp(e) {
|
|
11888
11901
|
let t = /* @__PURE__ */ new Set(), n = (e) => {
|
|
11889
11902
|
if (typeof e != "string" || !e) return;
|
|
11890
11903
|
let n;
|
|
11891
|
-
for (
|
|
11904
|
+
for (Lp.lastIndex = 0; (n = Lp.exec(e)) !== null;) t.add(n[0]);
|
|
11892
11905
|
};
|
|
11893
11906
|
for (let r of e) {
|
|
11894
11907
|
if (n(r.content), r.steps) for (let e of r.steps) n(e.result);
|
|
@@ -11896,14 +11909,14 @@ function Fp(e) {
|
|
|
11896
11909
|
}
|
|
11897
11910
|
return t;
|
|
11898
11911
|
}
|
|
11899
|
-
function
|
|
11912
|
+
function zp(e, t) {
|
|
11900
11913
|
let n = [];
|
|
11901
11914
|
for (let r of Object.keys(e)) r.startsWith("large_results/") && !t.has(r) && n.push(r);
|
|
11902
11915
|
return n;
|
|
11903
11916
|
}
|
|
11904
11917
|
//#endregion
|
|
11905
11918
|
//#region src/core/utils/serialRunner.ts
|
|
11906
|
-
function
|
|
11919
|
+
function Bp() {
|
|
11907
11920
|
let e = Promise.resolve();
|
|
11908
11921
|
return function(t) {
|
|
11909
11922
|
let n = e.then(t, t);
|
|
@@ -11912,24 +11925,24 @@ function Lp() {
|
|
|
11912
11925
|
}
|
|
11913
11926
|
//#endregion
|
|
11914
11927
|
//#region src/core/sdk/createChatSdk.ts
|
|
11915
|
-
var
|
|
11916
|
-
function
|
|
11928
|
+
var Vp = 30, Hp = /* @__PURE__ */ new Map();
|
|
11929
|
+
function Up(e, t) {
|
|
11917
11930
|
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;
|
|
11918
11931
|
}
|
|
11919
|
-
function
|
|
11932
|
+
function Wp(e) {
|
|
11920
11933
|
return e === "spawn_agent" || e === "spawn_agents" || e.startsWith("use_");
|
|
11921
11934
|
}
|
|
11922
|
-
function
|
|
11935
|
+
function Gp(e, t, n, r) {
|
|
11923
11936
|
let i = 0;
|
|
11924
11937
|
return {
|
|
11925
11938
|
name: "sdk-events",
|
|
11926
11939
|
wrapToolCall: async (t, r) => {
|
|
11927
|
-
let i = await r(t), a =
|
|
11940
|
+
let i = await r(t), a = Up(t.name, t.args);
|
|
11928
11941
|
return a ? e({
|
|
11929
11942
|
type: "data_change",
|
|
11930
11943
|
operation: a,
|
|
11931
11944
|
value: n()?.bind
|
|
11932
|
-
}) : i.status === "done" &&
|
|
11945
|
+
}) : i.status === "done" && Wp(t.name) && e({
|
|
11933
11946
|
type: "data_change",
|
|
11934
11947
|
operation: "edit",
|
|
11935
11948
|
value: n()?.bind
|
|
@@ -11956,7 +11969,7 @@ function Hp(e, t, n, r) {
|
|
|
11956
11969
|
}
|
|
11957
11970
|
};
|
|
11958
11971
|
}
|
|
11959
|
-
function
|
|
11972
|
+
function Kp(e, t, n, r, i) {
|
|
11960
11973
|
if (!n) return i && console.warn(`[page-agent-sdk][focus] capabilities.focus 关闭,${t} 忽略`), {
|
|
11961
11974
|
ok: !1,
|
|
11962
11975
|
error: "capabilities.focus 关闭"
|
|
@@ -11974,16 +11987,16 @@ function Up(e, t, n, r, i) {
|
|
|
11974
11987
|
error: "当前无主数据 schema,无法聚焦"
|
|
11975
11988
|
});
|
|
11976
11989
|
}
|
|
11977
|
-
function
|
|
11990
|
+
function qp(e, n) {
|
|
11978
11991
|
let i = {
|
|
11979
11992
|
prompt_tokens: 0,
|
|
11980
11993
|
completion_tokens: 0,
|
|
11981
11994
|
total_tokens: 0
|
|
11982
|
-
}, a =
|
|
11995
|
+
}, a = Kd(() => K, () => e.conflictPolicy ?? "ask"), o = /* @__PURE__ */ jt(0), s = yf(e.storage);
|
|
11983
11996
|
e.debug && s && s.onEvent((e) => console.log("[page-agent-sdk][storage]", e));
|
|
11984
|
-
let { modelCaps: c, summaryLlmInvoke: l, titleLlmInvoke: u, compressDecisionInvoke: d } =
|
|
11997
|
+
let { modelCaps: c, summaryLlmInvoke: l, titleLlmInvoke: u, compressDecisionInvoke: d } = Gd(e), f = c;
|
|
11985
11998
|
if (e.debug && console.log("[page-agent-sdk][modelCaps]", f), f.contextWindow < 2e5) throw Error(`[page-agent-sdk] 模型上下文窗口 ${f.contextWindow} 小于最小支持 ${Si}(需 ≥200K 窗口模型,如 GLM-5.2/Claude/Kimi/Qwen-1M/DeepSeek-v4)`);
|
|
11986
|
-
let p =
|
|
11999
|
+
let p = Ef(e, f.contextWindow), g = p.enableLLMSummary !== !1, _ = (e.contextOptions && e.contextOptions.preserveLastToolResults) ?? Tf[e.contextPreset ?? "auto"], v = new Set(_), y = e.llm;
|
|
11987
12000
|
e.debug && !l && console.warn("[page-agent-sdk][summarization] 未构造 llmInvoke(apiKey 缺失?),摘要回退零成本索引摘要");
|
|
11988
12001
|
let b = /* @__PURE__ */ bt([]), x = iu(e.vfs?.initialFiles, {
|
|
11989
12002
|
persist: s ? { save: (e) => {
|
|
@@ -12028,8 +12041,8 @@ function Wp(e, n) {
|
|
|
12028
12041
|
let j = { current: null }, M = e.data ? {
|
|
12029
12042
|
...e.data,
|
|
12030
12043
|
description: e.data.description ?? "主数据对象"
|
|
12031
|
-
} : void 0, N = !(e.subagents ?? []).some((e) => e._codeAsset) &&
|
|
12032
|
-
N && M?.schema && Ho(M.schema).length && (P = [...e.subagents ?? [],
|
|
12044
|
+
} : void 0, N = !(e.subagents ?? []).some((e) => e._codeAsset) && Sf(e.capabilities).subagent, P = e.subagents;
|
|
12045
|
+
N && M?.schema && Ho(M.schema).length && (P = [...e.subagents ?? [], Ad()], console.info("[page-agent-sdk] 检测到 schema 含代码组件数组(如 components[].code),已自动装配 HTML 代码子 agent(委派编排 + vfs 工作副本 + 格式校验 + 增量 commit)。需定制(codeField/formatCheck/craftNotes 等)请显式传 createHtmlSubagent(...)"));
|
|
12033
12046
|
let ee = (P ?? []).filter((e) => !!e._codeAsset), F = /* @__PURE__ */ new Set();
|
|
12034
12047
|
for (let e of ee) {
|
|
12035
12048
|
if (e._codeAsset.writablePaths.length) continue;
|
|
@@ -12045,7 +12058,7 @@ function Wp(e, n) {
|
|
|
12045
12058
|
getTodos: () => j.current?.getState?.()?.todos ?? [],
|
|
12046
12059
|
messages: b,
|
|
12047
12060
|
maxCheckpoints: ae && typeof ae == "object" ? ae.maxCheckpoints : void 0
|
|
12048
|
-
}) : null, se = !ae || typeof ae != "object" || ae.auto !== !1, R =
|
|
12061
|
+
}) : null, se = !ae || typeof ae != "object" || ae.auto !== !1, R = Sf(e.capabilities), z = R.dataOps, ce = R.draftWrite, le = R.tracing, ue = R.automation, de = eu({
|
|
12049
12062
|
...e,
|
|
12050
12063
|
locale: e.i18n?.locale
|
|
12051
12064
|
});
|
|
@@ -12053,7 +12066,7 @@ function Wp(e, n) {
|
|
|
12053
12066
|
let e = te.map((e) => e._codeAsset.orchestratorPrompt).filter(Boolean).join("\n\n");
|
|
12054
12067
|
e && (de += "\n\n" + e);
|
|
12055
12068
|
} else M?.schema && Vo(M.schema) && (de += "\n\n" + as.htmlDirectWriteFallback, console.warn("[page-agent-sdk] 检测到 schema 含 code 字段但未注册 html 子 agent:已自动注入「主 agent 自己写 HTML」编排(code 作普通字段直接 write,无 vfs 工作副本 / 无格式校验门禁)。如需代码资产机制(vfs + 格式校验 + 增量 commit + 主上下文 code 摘要),注册 createHtmlSubagent;若确为降级意图可忽略。"));
|
|
12056
|
-
let fe = z && M ?
|
|
12069
|
+
let fe = z && M ? Gu(M, {
|
|
12057
12070
|
onAudit: e.onAudit ?? (e.debug ? (e) => console.log("[page-agent-sdk][data audit]", e) : void 0),
|
|
12058
12071
|
maxSnapshots: e.maxSnapshots,
|
|
12059
12072
|
onConflict: a.set,
|
|
@@ -12061,7 +12074,7 @@ function Wp(e, n) {
|
|
|
12061
12074
|
vfsStore: ce || M?.resources?.length ? x : void 0,
|
|
12062
12075
|
...re.length ? { pgIdPaths: re } : {},
|
|
12063
12076
|
...ie.length ? { largeTextPaths: ie } : {}
|
|
12064
|
-
}) : [], pe = z ? fe : [], B = z && M ? fe.controller ?? null : null, me = z && M?.resources?.length && B?.getResourcesSnapshot ?
|
|
12077
|
+
}) : [], pe = z ? fe : [], B = z && M ? fe.controller ?? null : null, me = z && M?.resources?.length && B?.getResourcesSnapshot ? pp({ getResourcesSnapshot: () => B?.getResourcesSnapshot?.() ?? [] }) : void 0, V = () => B?.get() ?? M, H = new Set(fe.map((e) => e.name)), he = e.conflictWatchFields ?? [], U = !he.includes("*") && he.length ? new Set(he) : void 0, ge = B ? _d({
|
|
12065
12078
|
getBind: () => V()?.bind,
|
|
12066
12079
|
recomputeAll: () => B.recomputeAllBaselines?.(),
|
|
12067
12080
|
hasBaselines: () => B.hasBaselines?.() ?? !1,
|
|
@@ -12078,15 +12091,15 @@ function Wp(e, n) {
|
|
|
12078
12091
|
}
|
|
12079
12092
|
}), Ft(n));
|
|
12080
12093
|
}
|
|
12081
|
-
}) : void 0, W = /* @__PURE__ */ new Map(), _e =
|
|
12082
|
-
...
|
|
12083
|
-
|
|
12084
|
-
|
|
12085
|
-
] :
|
|
12094
|
+
}) : void 0, W = /* @__PURE__ */ new Map(), _e = lp(R, pe, Af, R.domInspect && !R.skills ? [
|
|
12095
|
+
...If,
|
|
12096
|
+
Kf,
|
|
12097
|
+
qf
|
|
12098
|
+
] : If, tp);
|
|
12086
12099
|
_e.forEach((e) => W.set(e.name, "builtin"));
|
|
12087
12100
|
let ve = [...e.tools || []];
|
|
12088
12101
|
ve.forEach((e) => W.set(e.name, "user"));
|
|
12089
|
-
let ye =
|
|
12102
|
+
let ye = ip(e.actions ?? {});
|
|
12090
12103
|
ye.forEach((e) => W.set(e.name, "action"));
|
|
12091
12104
|
let be = [], xe = !1, Se = e.humanConfirm !== !1 && (!e.approval || e.approval.humanConfirmTool !== !1), Ce = Se ? pl() : null;
|
|
12092
12105
|
Ce && W.set(dl, "builtin");
|
|
@@ -12158,7 +12171,7 @@ function Wp(e, n) {
|
|
|
12158
12171
|
Ae.forEach((e) => W.set(e.name, "builtin"));
|
|
12159
12172
|
let je = [], Me = /* @__PURE__ */ new Map(), G = Ne();
|
|
12160
12173
|
function Ne() {
|
|
12161
|
-
let { tools: e, collisions: t } =
|
|
12174
|
+
let { tools: e, collisions: t } = up([
|
|
12162
12175
|
{
|
|
12163
12176
|
label: "builtin",
|
|
12164
12177
|
tools: _e
|
|
@@ -12231,7 +12244,7 @@ function Wp(e, n) {
|
|
|
12231
12244
|
timeoutMs: Ye?.timeoutMs
|
|
12232
12245
|
}), tt = ne?.map((e) => {
|
|
12233
12246
|
if (!e._codeAsset) return e;
|
|
12234
|
-
let t = e._codeAsset, n =
|
|
12247
|
+
let t = e._codeAsset, n = cd({
|
|
12235
12248
|
writablePaths: t.writablePaths,
|
|
12236
12249
|
codeVfsPrefix: t.codeVfsPrefix,
|
|
12237
12250
|
ext: t.ext,
|
|
@@ -12246,12 +12259,12 @@ function Wp(e, n) {
|
|
|
12246
12259
|
...e,
|
|
12247
12260
|
middleware: r
|
|
12248
12261
|
};
|
|
12249
|
-
}), nt = I && He ?
|
|
12262
|
+
}), nt = I && He ? ld() : void 0, rt = nt ? gd({
|
|
12250
12263
|
getBind: () => V()?.bind,
|
|
12251
12264
|
writablePaths: re,
|
|
12252
12265
|
getLocked: () => nt.locked(),
|
|
12253
12266
|
tools: G,
|
|
12254
|
-
getCodeFieldPaths: () =>
|
|
12267
|
+
getCodeFieldPaths: () => md(V()?.bind, te.map((e) => ({
|
|
12255
12268
|
writablePaths: e._codeAsset.writablePaths,
|
|
12256
12269
|
codeField: e._codeAsset.codeField
|
|
12257
12270
|
})))
|
|
@@ -12275,7 +12288,7 @@ function Wp(e, n) {
|
|
|
12275
12288
|
timeoutMs: e.subagent?.timeoutMs,
|
|
12276
12289
|
...nt ? {
|
|
12277
12290
|
componentLock: nt,
|
|
12278
|
-
resolveComponents: (e) =>
|
|
12291
|
+
resolveComponents: (e) => ud(e, id(V()?.bind, re))
|
|
12279
12292
|
} : {}
|
|
12280
12293
|
}) : void 0, at = !!e.capabilities?.bulkGuard && !!Qe, ot = at ? gl({
|
|
12281
12294
|
...e.bulkGuard ?? {},
|
|
@@ -12292,7 +12305,7 @@ function Wp(e, n) {
|
|
|
12292
12305
|
}) : void 0;
|
|
12293
12306
|
e.capabilities?.bulkGuard && !Qe && console.info("[page-agent-sdk] bulkGuard 已请求但未配置 approval,门禁未装配(整体 no-op;配置 approval.tools 或 approval.confirm 后生效)");
|
|
12294
12307
|
let st = it ? it.controller : null, ct = (t) => {
|
|
12295
|
-
let n = t.thinkingMode ?? e.subagent?.thinkingMode, r = n ?
|
|
12308
|
+
let n = t.thinkingMode ?? e.subagent?.thinkingMode, r = n ? Id(t.llm ?? e.llm) ? "instance-noop" : "applied" : "inherited";
|
|
12296
12309
|
return {
|
|
12297
12310
|
...t,
|
|
12298
12311
|
...n ? { thinkingMode: n } : {},
|
|
@@ -12314,8 +12327,8 @@ function Wp(e, n) {
|
|
|
12314
12327
|
} : void 0
|
|
12315
12328
|
}) : void 0, ft = Je ? Gl({
|
|
12316
12329
|
contextWindow: f.contextWindow,
|
|
12317
|
-
thresholdRatio:
|
|
12318
|
-
}) : void 0, pt =
|
|
12330
|
+
thresholdRatio: Ef(e, f.contextWindow).summaryThresholdRatio
|
|
12331
|
+
}) : void 0, pt = fp({
|
|
12319
12332
|
...R,
|
|
12320
12333
|
humanConfirm: Se,
|
|
12321
12334
|
subagents: ne?.map(ct)
|
|
@@ -12335,7 +12348,7 @@ function Wp(e, n) {
|
|
|
12335
12348
|
return;
|
|
12336
12349
|
}
|
|
12337
12350
|
}
|
|
12338
|
-
} : null, gt =
|
|
12351
|
+
} : null, gt = Cf(e.onEvent), K = gt.emit, _t, vt = [], yt = (e) => ({
|
|
12339
12352
|
name: e.name,
|
|
12340
12353
|
description: e.description,
|
|
12341
12354
|
content: typeof e.getContent == "function" ? e.getContent() : ""
|
|
@@ -12343,13 +12356,13 @@ function Wp(e, n) {
|
|
|
12343
12356
|
name: e.name,
|
|
12344
12357
|
description: e.description,
|
|
12345
12358
|
getContent: () => e.content
|
|
12346
|
-
}), St = e.skillStorage === !1 ? null :
|
|
12359
|
+
}), St = e.skillStorage === !1 ? null : vp({
|
|
12347
12360
|
...typeof e.skillStorage == "object" ? e.skillStorage : {},
|
|
12348
12361
|
id: e.skillStorage && typeof e.skillStorage == "object" && e.skillStorage.id ? e.skillStorage.id : `agent::${n}`
|
|
12349
|
-
}), Ct = R.preferences, wt = Ct && e.preferenceStorage !== !1 ?
|
|
12362
|
+
}), Ct = R.preferences, wt = Ct && e.preferenceStorage !== !1 ? Tp({
|
|
12350
12363
|
...typeof e.preferenceStorage == "object" ? e.preferenceStorage : {},
|
|
12351
12364
|
id: e.preferenceStorage && typeof e.preferenceStorage == "object" && e.preferenceStorage.id ? e.preferenceStorage.id : `agent::${n}`
|
|
12352
|
-
}) : null, q = wt ?
|
|
12365
|
+
}) : null, q = wt ? Ip({
|
|
12353
12366
|
store: wt,
|
|
12354
12367
|
llmInvoke: l,
|
|
12355
12368
|
getSessionId: () => Y.sessionId,
|
|
@@ -12390,7 +12403,7 @@ function Wp(e, n) {
|
|
|
12390
12403
|
decideInvoke: d,
|
|
12391
12404
|
getSnapshot: () => ft?.getSnapshot()
|
|
12392
12405
|
} : {}
|
|
12393
|
-
}) : void 0, Dt =
|
|
12406
|
+
}) : void 0, Dt = Of([
|
|
12394
12407
|
...mt ? [mt] : [],
|
|
12395
12408
|
pt,
|
|
12396
12409
|
...Fe ? [C] : [],
|
|
@@ -12398,7 +12411,7 @@ function Wp(e, n) {
|
|
|
12398
12411
|
T,
|
|
12399
12412
|
...q ? [q] : [],
|
|
12400
12413
|
...Pe ? [S] : [],
|
|
12401
|
-
...Le ? [_t = cc([...R.domInspect && !(e.skills || []).some((e) => e.name ===
|
|
12414
|
+
...Le ? [_t = cc([...R.domInspect && !(e.skills || []).some((e) => e.name === Jf.name) ? [Jf] : [], ...e.skills || []], {
|
|
12402
12415
|
readVfs: Re ? (e) => x.files[e]?.content : void 0,
|
|
12403
12416
|
hostScriptEnabled: R.skillHostScript,
|
|
12404
12417
|
onToolsReady: (e, t) => {
|
|
@@ -12428,12 +12441,12 @@ function Wp(e, n) {
|
|
|
12428
12441
|
...ht ? [ht] : [],
|
|
12429
12442
|
...ft ? [ft] : [],
|
|
12430
12443
|
...e.middleware || [],
|
|
12431
|
-
...ue ? [
|
|
12444
|
+
...ue ? [np(i, {
|
|
12432
12445
|
tokenBudget: e.tokenBudget,
|
|
12433
12446
|
timeBudgetMs: e.timeBudgetMs
|
|
12434
12447
|
}, K)] : [],
|
|
12435
|
-
|
|
12436
|
-
]), Ot = e.maxMemoryRounds ??
|
|
12448
|
+
Gp(K, b, V, i)
|
|
12449
|
+
]), Ot = e.maxMemoryRounds ?? Vp, kt = e.approval?.timeoutMs, At = kt === void 0 || kt === 0 ? 3e4 : !Number.isFinite(kt) || kt < 0 ? 0 : kt;
|
|
12437
12450
|
function Mt(e) {
|
|
12438
12451
|
if (At) return (t) => {
|
|
12439
12452
|
if (t.type !== "approval_request") return;
|
|
@@ -12466,7 +12479,7 @@ function Wp(e, n) {
|
|
|
12466
12479
|
e.debug && console.warn("[page-agent-sdk][persist] refreshSessions 失败(已吞):", t);
|
|
12467
12480
|
}
|
|
12468
12481
|
}
|
|
12469
|
-
let Lt =
|
|
12482
|
+
let Lt = Bp(), Rt = /* @__PURE__ */ new Set();
|
|
12470
12483
|
function zt(e) {
|
|
12471
12484
|
let t = new AbortController(), n = () => t.abort();
|
|
12472
12485
|
return e && (e.aborted ? t.abort() : e.addEventListener("abort", n, { once: !0 })), Rt.add(t), {
|
|
@@ -12730,7 +12743,7 @@ function Wp(e, n) {
|
|
|
12730
12743
|
})), e.memory && Yt({ memory: A.get() || (typeof e.memory == "string" ? e.memory : "") }), It(), Kt = void 0, qt = !1, Y.infoTick.value++, r;
|
|
12731
12744
|
},
|
|
12732
12745
|
resetSession: () => {
|
|
12733
|
-
Bt(), a.resolve("keep_external"), Y.sessionId =
|
|
12746
|
+
Bt(), a.resolve("keep_external"), Y.sessionId = qd(), b.splice(0, b.length), x.clear?.(), S.reset([]), e.memory || A.reset(""), C.reset(), k.reset(), O.reset(), T.reset(), E = void 0, ot?.state.reset(), q?.resetScanCursor(), L && L.importStack([]), Y.agent && (Y.agent.debugLogs.value = [], Y.agent.resetStaleReadsInvalidated?.()), s && s.createSession(Y.agentId, e.session?.title, Y.sessionId).catch((t) => {
|
|
12734
12747
|
e.debug && console.warn("[page-agent-sdk][persist] createSession 失败(已吞):", t);
|
|
12735
12748
|
}), K({
|
|
12736
12749
|
type: "session_restored",
|
|
@@ -12750,7 +12763,7 @@ function Wp(e, n) {
|
|
|
12750
12763
|
code: "IMAGE_UNSUPPORTED_MODEL"
|
|
12751
12764
|
}), Error(`[page-agent-sdk] ${e}`);
|
|
12752
12765
|
}
|
|
12753
|
-
x?.setProtectedRefs?.(
|
|
12766
|
+
x?.setProtectedRefs?.(Rp(e));
|
|
12754
12767
|
let i = (e) => {
|
|
12755
12768
|
t?.(e), K(e), e.type === "subagent" && (e.kind === "tool_call" || e.kind === "tool_result") && Y.infoTick.value++;
|
|
12756
12769
|
};
|
|
@@ -12765,7 +12778,7 @@ function Wp(e, n) {
|
|
|
12765
12778
|
if (Y.refCount--, Y.refCount <= 0) {
|
|
12766
12779
|
Bt(), xe = !0, s && (x.flush?.(), s.flush(), s.dispose()), St && St.dispose();
|
|
12767
12780
|
let e = Y.mcpClosers.splice(0);
|
|
12768
|
-
e.length && Promise.allSettled(e.map((e) => e())),
|
|
12781
|
+
e.length && Promise.allSettled(e.map((e) => e())), Hp.delete(n);
|
|
12769
12782
|
}
|
|
12770
12783
|
},
|
|
12771
12784
|
resolveConflict: a.resolve,
|
|
@@ -12785,14 +12798,14 @@ function Wp(e, n) {
|
|
|
12785
12798
|
},
|
|
12786
12799
|
setLlm(t) {
|
|
12787
12800
|
let n;
|
|
12788
|
-
if (
|
|
12801
|
+
if (Id(t)) n = t;
|
|
12789
12802
|
else {
|
|
12790
12803
|
let e = t;
|
|
12791
12804
|
if ((e.provider ?? "openai") === "anthropic") throw Error("[page-agent-sdk][setLlm] 切换到 Anthropic 需传 BaseChatModel 实例(动态 import 无法同步);请先 const { ChatAnthropic } = await import(\"@langchain/anthropic\") 构造实例后传入");
|
|
12792
12805
|
n = m(e);
|
|
12793
12806
|
}
|
|
12794
12807
|
typeof n.bindTools != "function" && e.debug && console.warn("[page-agent-sdk][setLlm] 新模型不支持 bindTools(tool calling 会失效)"), y = t;
|
|
12795
|
-
let r =
|
|
12808
|
+
let r = Id(t) ? void 0 : t;
|
|
12796
12809
|
if (f = Ci({
|
|
12797
12810
|
model: r?.model ?? t.model ?? t.modelName,
|
|
12798
12811
|
contextWindow: e.contextWindow ?? r?.contextWindow,
|
|
@@ -12836,7 +12849,7 @@ function Wp(e, n) {
|
|
|
12836
12849
|
return {
|
|
12837
12850
|
id: n,
|
|
12838
12851
|
sessionId: Y.sessionId,
|
|
12839
|
-
model:
|
|
12852
|
+
model: Id(y) ? y.model ?? y.modelName : y.model,
|
|
12840
12853
|
systemPrompt: Y.agent?.getEffectiveSystemPrompt?.() ?? de + $l(V(), e.schemaHint),
|
|
12841
12854
|
tools: (Y.agent?.allTools ?? G).map((e) => ({
|
|
12842
12855
|
name: e.name,
|
|
@@ -12887,7 +12900,7 @@ function Wp(e, n) {
|
|
|
12887
12900
|
spans: Y.agent.spans.value,
|
|
12888
12901
|
metrics: Ei(Y.agent.spans.value)
|
|
12889
12902
|
} : void 0,
|
|
12890
|
-
actions:
|
|
12903
|
+
actions: ap(e.actions ?? {}),
|
|
12891
12904
|
subagent: {
|
|
12892
12905
|
enabled: !!et,
|
|
12893
12906
|
maxDepth: e.subagent?.maxDepth ?? 1,
|
|
@@ -12946,7 +12959,7 @@ function Wp(e, n) {
|
|
|
12946
12959
|
approxBytes: e
|
|
12947
12960
|
};
|
|
12948
12961
|
}
|
|
12949
|
-
return
|
|
12962
|
+
return Cd(Sd({
|
|
12950
12963
|
debugLogs: Y.agent?.debugLogs?.value ?? [],
|
|
12951
12964
|
messages: Y.messages,
|
|
12952
12965
|
info: t,
|
|
@@ -12984,11 +12997,11 @@ function Wp(e, n) {
|
|
|
12984
12997
|
return Te ? O.getFocuses() : [];
|
|
12985
12998
|
},
|
|
12986
12999
|
setFocus(t) {
|
|
12987
|
-
let n =
|
|
13000
|
+
let n = Kp(t, "setFocus", Te, () => V()?.schema, e.debug);
|
|
12988
13001
|
return n.ok ? (O.setFocus(t), Y.infoTick.value++, { ok: !0 }) : n;
|
|
12989
13002
|
},
|
|
12990
13003
|
addFocus(t) {
|
|
12991
|
-
let n =
|
|
13004
|
+
let n = Kp(t, "addFocus", Te, () => V()?.schema, e.debug);
|
|
12992
13005
|
return n.ok ? O.getFocuses().length >= 8 ? (e.debug && console.warn("[page-agent-sdk][focus] addFocus 拒绝:焦点数已达上限 8(augmentPrompt 注入每焦点子树 schema,过多致 system prompt 超预算)"), {
|
|
12993
13006
|
ok: !1,
|
|
12994
13007
|
error: "焦点数上限 8(避免 system prompt 撑爆)"
|
|
@@ -13032,14 +13045,14 @@ function Wp(e, n) {
|
|
|
13032
13045
|
}
|
|
13033
13046
|
function Ut(e) {
|
|
13034
13047
|
let t = {};
|
|
13035
|
-
for (let n of
|
|
13048
|
+
for (let n of Rp(e)) {
|
|
13036
13049
|
let e = x.files[n];
|
|
13037
13050
|
e && (t[n] = e.content);
|
|
13038
13051
|
}
|
|
13039
13052
|
return t;
|
|
13040
13053
|
}
|
|
13041
13054
|
function Wt() {
|
|
13042
|
-
let e =
|
|
13055
|
+
let e = zp(x.files, Rp(b));
|
|
13043
13056
|
for (let t of e) delete x.files[t];
|
|
13044
13057
|
}
|
|
13045
13058
|
function Gt() {
|
|
@@ -13143,7 +13156,7 @@ function Wp(e, n) {
|
|
|
13143
13156
|
Yt({ focus: e.length ? e : null });
|
|
13144
13157
|
}
|
|
13145
13158
|
ue && L && (Yt({ checkpoints: L.exportStack() }), Yt({ usage: i }));
|
|
13146
|
-
let t =
|
|
13159
|
+
let t = Fd(b);
|
|
13147
13160
|
if (t && t !== Kt && (Kt = t, Xt(Y.sessionId, t)), e.autoTitle !== !1 && u && !qt && b.some((e) => e.role === "user") && b.some((e) => e.role === "assistant")) {
|
|
13148
13161
|
qt = !0;
|
|
13149
13162
|
let e = Y.sessionId;
|
|
@@ -13221,7 +13234,7 @@ function Wp(e, n) {
|
|
|
13221
13234
|
}
|
|
13222
13235
|
}));
|
|
13223
13236
|
})();
|
|
13224
|
-
let t =
|
|
13237
|
+
let t = Id(e.llm) ? e.llm : await h(e.llm);
|
|
13225
13238
|
Y.agent = Eo({
|
|
13226
13239
|
llm: t,
|
|
13227
13240
|
systemPrompt: de,
|
|
@@ -13235,7 +13248,7 @@ function Wp(e, n) {
|
|
|
13235
13248
|
contextWindow: f.contextWindow,
|
|
13236
13249
|
maxOutputTokens: f.maxOutputTokens,
|
|
13237
13250
|
vision: f.vision,
|
|
13238
|
-
imageContentFormat: !
|
|
13251
|
+
imageContentFormat: !Id(e.llm) && (e.llm.provider ?? "openai") === "anthropic" ? "anthropic" : "openai",
|
|
13239
13252
|
maxVerifyAttempts: qe ? We : 0,
|
|
13240
13253
|
roundTokenBudget: e.roundTokenBudget ?? 0,
|
|
13241
13254
|
staleReadInvalidation: e.staleReadInvalidation,
|
|
@@ -13257,12 +13270,12 @@ function Wp(e, n) {
|
|
|
13257
13270
|
});
|
|
13258
13271
|
})(), Y;
|
|
13259
13272
|
}
|
|
13260
|
-
function
|
|
13261
|
-
let n = e.id ??
|
|
13273
|
+
function Jp(e, t) {
|
|
13274
|
+
let n = e.id ?? qd();
|
|
13262
13275
|
e.id || console.warn(`[page-agent-sdk] 未传 options.id,已生成随机 id "${n}"。刷新后持久化数据无法恢复,请传稳定 id。`);
|
|
13263
|
-
let r = e.streaming ?? !0, i = e.ui ?? "default", a, o = e.shareContext ?
|
|
13264
|
-
o ? a = o : (a =
|
|
13265
|
-
let s = null, c =
|
|
13276
|
+
let r = e.streaming ?? !0, i = e.ui ?? "default", a, o = e.shareContext ? Hp.get(n) : void 0;
|
|
13277
|
+
o ? a = o : (a = qp(e, n), e.shareContext && Hp.set(n, a)), a.refCount++;
|
|
13278
|
+
let s = null, c = bf(e), l = null, u = null;
|
|
13266
13279
|
async function d(n) {
|
|
13267
13280
|
if (await a.initDone, s) {
|
|
13268
13281
|
s.show();
|
|
@@ -13484,7 +13497,7 @@ function Gp(e, t) {
|
|
|
13484
13497
|
}
|
|
13485
13498
|
//#endregion
|
|
13486
13499
|
//#region src/core/sdk/ragSubagent.ts
|
|
13487
|
-
function
|
|
13500
|
+
function Yp(e, t, n, r, i) {
|
|
13488
13501
|
let a = [];
|
|
13489
13502
|
e && a.push("vfs_grep + vfs_read(搜预注入文档)"), t && a.push(`${r}(语义检索)`), n && a.push(`${i}(按 source 加载)`), a.push("fetch_document(公网 URL)");
|
|
13490
13503
|
let o = [];
|
|
@@ -13499,7 +13512,7 @@ function Kp(e, t, n, r, i) {
|
|
|
13499
13512
|
|
|
13500
13513
|
你是只读检索角色,不要尝试修改任何数据。不要尝试上面未列出的工具。`;
|
|
13501
13514
|
}
|
|
13502
|
-
function
|
|
13515
|
+
function Xp(e, t, n, r, i) {
|
|
13503
13516
|
let a = [], o = [];
|
|
13504
13517
|
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)
|
|
13505
13518
|
|
|
@@ -13516,12 +13529,12 @@ ${a.join("\n")}
|
|
|
13516
13529
|
## 何时用何源
|
|
13517
13530
|
${o.join("\n")}`;
|
|
13518
13531
|
}
|
|
13519
|
-
var
|
|
13532
|
+
var Zp = {
|
|
13520
13533
|
name: "rag-search",
|
|
13521
13534
|
description: "多源知识检索策略:vfs 预注入文档 → 语义检索 → 指定文档加载 → 公网;综合结构化结论 + 溯源",
|
|
13522
|
-
getContent: () =>
|
|
13535
|
+
getContent: () => Xp(!0, !0, !0, "search_docs", "load_doc")
|
|
13523
13536
|
};
|
|
13524
|
-
function
|
|
13537
|
+
function Qp(e, n, i) {
|
|
13525
13538
|
return r(async ({ query: e, topK: t }) => {
|
|
13526
13539
|
try {
|
|
13527
13540
|
let r = await n(e, { topK: t ?? i });
|
|
@@ -13538,7 +13551,7 @@ function Yp(e, n, i) {
|
|
|
13538
13551
|
})
|
|
13539
13552
|
});
|
|
13540
13553
|
}
|
|
13541
|
-
function
|
|
13554
|
+
function $p(e, n) {
|
|
13542
13555
|
return r(async ({ source: e }) => {
|
|
13543
13556
|
try {
|
|
13544
13557
|
let t = await n(e), r = Array.isArray(t) ? t : [t];
|
|
@@ -13552,19 +13565,19 @@ function Xp(e, n) {
|
|
|
13552
13565
|
schema: t.object({ source: t.string().describe("文档标识(id/URL/key)") })
|
|
13553
13566
|
});
|
|
13554
13567
|
}
|
|
13555
|
-
function
|
|
13568
|
+
function em(e) {
|
|
13556
13569
|
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;
|
|
13557
13570
|
if (!t && !n && r === !1) throw Error("[page-agent-sdk][createRagSubagent] 至少配一种知识源:retriever / loader / useVfs(true)");
|
|
13558
13571
|
let p = [];
|
|
13559
|
-
t && p.push(
|
|
13572
|
+
t && p.push(Qp(s, t, o)), n && p.push($p(c, n)), f && p.push(...f);
|
|
13560
13573
|
let m = r ? [
|
|
13561
13574
|
"vfs_grep",
|
|
13562
13575
|
"vfs_read",
|
|
13563
13576
|
"vfs_json_read"
|
|
13564
|
-
] : void 0, h =
|
|
13577
|
+
] : void 0, h = Yp(r, !!t, !!n, s, c), g = {
|
|
13565
13578
|
name: "rag-search",
|
|
13566
|
-
description:
|
|
13567
|
-
getContent: () =>
|
|
13579
|
+
description: Zp.description,
|
|
13580
|
+
getContent: () => Xp(r, !!t, !!n, s, c)
|
|
13568
13581
|
};
|
|
13569
13582
|
return {
|
|
13570
13583
|
id: i,
|
|
@@ -13579,7 +13592,7 @@ function Zp(e) {
|
|
|
13579
13592
|
}
|
|
13580
13593
|
//#endregion
|
|
13581
13594
|
//#region src/core/utils/clipboard.ts
|
|
13582
|
-
async function
|
|
13595
|
+
async function tm(e) {
|
|
13583
13596
|
try {
|
|
13584
13597
|
let t = globalThis.navigator?.clipboard;
|
|
13585
13598
|
if (t && typeof t.writeText == "function") return await t.writeText(e), !0;
|
|
@@ -13597,8 +13610,8 @@ async function Qp(e) {
|
|
|
13597
13610
|
}
|
|
13598
13611
|
//#endregion
|
|
13599
13612
|
//#region src/core/composables/useChat.ts
|
|
13600
|
-
var
|
|
13601
|
-
function
|
|
13613
|
+
var nm = 4e3;
|
|
13614
|
+
function rm(e = {}) {
|
|
13602
13615
|
let { fetchResponse: t, fetchStream: n, onPersist: r, onClear: i, onQueuedCleared: a, onBeforeRegenerate: o } = e, s = /* @__PURE__ */ bt({
|
|
13603
13616
|
messages: e.messages ?? [],
|
|
13604
13617
|
loading: !1,
|
|
@@ -13677,7 +13690,7 @@ function em(e = {}) {
|
|
|
13677
13690
|
let t = e.delta || "";
|
|
13678
13691
|
n.subReasonFull = (n.subReasonFull || "") + t;
|
|
13679
13692
|
let r = (n.subReason || "") + t;
|
|
13680
|
-
n.subReason = r.length >
|
|
13693
|
+
n.subReason = r.length > nm ? r.slice(-4e3) : r;
|
|
13681
13694
|
break;
|
|
13682
13695
|
}
|
|
13683
13696
|
n.children ||= [];
|
|
@@ -13807,7 +13820,7 @@ function em(e = {}) {
|
|
|
13807
13820
|
}
|
|
13808
13821
|
//#endregion
|
|
13809
13822
|
//#region src/core/components/icons.ts
|
|
13810
|
-
var
|
|
13823
|
+
var im = {
|
|
13811
13824
|
header: "🤖",
|
|
13812
13825
|
subagent: "🤖",
|
|
13813
13826
|
subagentProgress: "🧬",
|
|
@@ -13818,10 +13831,10 @@ var tm = {
|
|
|
13818
13831
|
recommend: "💡",
|
|
13819
13832
|
conflict: "⚠️"
|
|
13820
13833
|
};
|
|
13821
|
-
function
|
|
13822
|
-
let t = { ...
|
|
13834
|
+
function am(e) {
|
|
13835
|
+
let t = { ...im };
|
|
13823
13836
|
if (!e) return t;
|
|
13824
|
-
let n = Object.keys(
|
|
13837
|
+
let n = Object.keys(im);
|
|
13825
13838
|
for (let r of n) {
|
|
13826
13839
|
let n = e[r];
|
|
13827
13840
|
typeof n == "string" && (t[r] = n);
|
|
@@ -13830,7 +13843,7 @@ function nm(e) {
|
|
|
13830
13843
|
}
|
|
13831
13844
|
//#endregion
|
|
13832
13845
|
//#region src/core/components/messages.ts
|
|
13833
|
-
var
|
|
13846
|
+
var om = {
|
|
13834
13847
|
defaultTitle: "AI 助手",
|
|
13835
13848
|
inputPlaceholder: "输入消息,Enter 发送...",
|
|
13836
13849
|
newSession: "新建会话",
|
|
@@ -14069,8 +14082,8 @@ var rm = {
|
|
|
14069
14082
|
codeDemoText: "这是一段示例文字,用于展示 CSS 效果。",
|
|
14070
14083
|
codeDemoButton: "按钮",
|
|
14071
14084
|
codeDemoInput: "输入框"
|
|
14072
|
-
},
|
|
14073
|
-
"zh-CN":
|
|
14085
|
+
}, sm = {
|
|
14086
|
+
"zh-CN": om,
|
|
14074
14087
|
"en-US": {
|
|
14075
14088
|
defaultTitle: "AI Assistant",
|
|
14076
14089
|
inputPlaceholder: "Type a message, Enter to send...",
|
|
@@ -14312,10 +14325,10 @@ var rm = {
|
|
|
14312
14325
|
codeDemoInput: "Input"
|
|
14313
14326
|
}
|
|
14314
14327
|
};
|
|
14315
|
-
function
|
|
14328
|
+
function cm(e = "zh-CN", t) {
|
|
14316
14329
|
let n = {
|
|
14317
|
-
...
|
|
14318
|
-
...
|
|
14330
|
+
...om,
|
|
14331
|
+
...sm[e]
|
|
14319
14332
|
};
|
|
14320
14333
|
if (!t) return n;
|
|
14321
14334
|
let r = { ...n };
|
|
@@ -14327,9 +14340,9 @@ function am(e = "zh-CN", t) {
|
|
|
14327
14340
|
}
|
|
14328
14341
|
//#endregion
|
|
14329
14342
|
//#region src/core/composables/chatContext.ts
|
|
14330
|
-
var
|
|
14331
|
-
function
|
|
14332
|
-
let t =
|
|
14343
|
+
var lm = Symbol("chatContext");
|
|
14344
|
+
function um(e = {}) {
|
|
14345
|
+
let t = rm({
|
|
14333
14346
|
fetchResponse: e.fetchResponse,
|
|
14334
14347
|
fetchStream: e.fetchStream,
|
|
14335
14348
|
messages: e.messages,
|
|
@@ -14350,7 +14363,7 @@ function sm(e = {}) {
|
|
|
14350
14363
|
}, h = /* @__PURE__ */ jt({}), g = (e) => h.value[e] === !0, _ = (e) => {
|
|
14351
14364
|
h.value[e] = !g(e);
|
|
14352
14365
|
}, v = /* @__PURE__ */ jt(!1), y = (e) => {
|
|
14353
|
-
|
|
14366
|
+
tm(e).then((e) => {
|
|
14354
14367
|
e && (v.value = !0, setTimeout(() => {
|
|
14355
14368
|
v.value = !1;
|
|
14356
14369
|
}, 1500));
|
|
@@ -14412,7 +14425,7 @@ function sm(e = {}) {
|
|
|
14412
14425
|
e.onClearFocus?.();
|
|
14413
14426
|
}, re = (t) => {
|
|
14414
14427
|
e.onFocusChipClick?.(t);
|
|
14415
|
-
}, ie =
|
|
14428
|
+
}, ie = am(e.icons), ae = e.locale ?? "zh-CN", oe = cm(ae, e.dialogMessages);
|
|
14416
14429
|
return {
|
|
14417
14430
|
chat: t,
|
|
14418
14431
|
inputText: o,
|
|
@@ -14453,15 +14466,15 @@ function sm(e = {}) {
|
|
|
14453
14466
|
messages: oe
|
|
14454
14467
|
};
|
|
14455
14468
|
}
|
|
14456
|
-
function
|
|
14457
|
-
let e = Rn(
|
|
14469
|
+
function dm() {
|
|
14470
|
+
let e = Rn(lm);
|
|
14458
14471
|
if (!e) throw Error("useChatContext 必须在 provide(chatContextKey) 的组件子树内调用");
|
|
14459
14472
|
return e;
|
|
14460
14473
|
}
|
|
14461
14474
|
//#endregion
|
|
14462
14475
|
//#region src/core/index.headless.ts
|
|
14463
|
-
function
|
|
14464
|
-
return
|
|
14476
|
+
function fm(e) {
|
|
14477
|
+
return Jp(e);
|
|
14465
14478
|
}
|
|
14466
14479
|
//#endregion
|
|
14467
|
-
export {
|
|
14480
|
+
export { xf as CAPABILITIES, wf as CONTEXT_PRESETS, Pd as CompressDecisionSchema, Lf as DEFAULT_COMPUTED_STYLES, Tc as DEFAULT_PROMPT_SOFT_CAP, Zl as DEFAULT_SYSTEM_PROMPT, Ku as HTML_VOID_TAGS, dl as HUMAN_CONFIRM_TOOL_NAME, ni as ImageInputError, Si as MIN_CONTEXT_WINDOW, wc as SOFT_CAP_MIN_WINDOW, vc as STOP_WORDS, Cs as UNSAFE_KEYS, ap as actionsToInspectInfo, ip as actionsToTools, Qr as agentError, Wl as analyzeContext, Fs as applyPatchToClone, Rs as applyPatchToLive, Ru as applyPatchesToBind, Io as arrayMinLength, Zr as asAgentError, Hf as buildCssPath, $l as buildDataPrompt, Sd as buildDiagnosticsReport, eu as buildSystemPrompt, lm as chatContextKey, Lu as commitSetToBind, pi as compressImage, Xl as connectMcp, h as constructLlmFromConfig, m as constructOpenLlmSync, tm as copyText, Eo as createAgent, ul as createApprovalMiddleware, gl as createBulkGuardMiddleware, um as createChatContext, fm as createChatSdk, Cl as createCheckpointManager, wl as createCheckpointMiddleware, Kd as createConflictManager, Gl as createContextInspectorMiddleware, Gu as createDataOps, Dd as createHtmlFormatCheck, Ad as createHtmlSubagent, ml as createHumanConfirmMiddleware, pl as createHumanConfirmTool, mf as createMemoryBackend, rl as createMemoryMiddleware, u as createProxyLlm, em as createRagSubagent, Wi as createSandboxRunner, Cf as createSdkEvents, Bp as createSerialRunner, vf as createSessionStore, vp as createSkillStore, Jc as createSubagentMiddleware, jc as createSubagentTracker, Zc as createSubagentsMiddleware, fp as createUsageHintsMiddleware, Tl as createVerifyMiddleware, iu as createVfs, gf as createWebStorageBackend, jl as createWriteBackCheck, Os as deepClone, cp as defineDataToolset, Ys as defineSkill, jd as defineTool, Ds as deleteByPath, Fd as deriveTitle, Xo as describeSchemaNode, fo as detectGarbledToolCall, Hs as diffObjects, qf as domInfoTool, Jf as domInspectSkill, Kf as domSearchTool, Pf as domToStructure, If as domTools, sp as domToolsStatic, Lo as elementSchemaCandidates, Bf as ensureDomListenerRecorder, bc as estimateMessageTokens, xc as estimateRoundTokens, Z as estimateTokens, _ as extractReasoningDelta, ls as extractSchemaHint, Kl as extractText, g as extractTextDelta, v as extractUsage, Af as fetchDocTools, op as fetchTools, Vs as findStrippedKeys, Zo as formatConstraints, qr as formatZodIssues, Q as getByPath, Ff as getDomTool, Gf as getElementInfo, Zf as getEnvSummary, Vf as getRecordedListeners, Ao as getSchemaAtPath, Do as getSchemaTopKeys, Ei as getTraceMetrics, Ns as hashValue, is as htmlOrchestratorPrompt, Sc as indexSummarize, ep as inspectEnvTool, tp as inspectTools, Id as isChatModel, zi as isContextLengthError, Oo as isPathAllowed, of as isQuotaError, ws as isUnsafePath, ea as jpEval, Yr as jsonParseError, js as limitDepth, bd as maskUrlCredentials, ks as maybeParseValue, hl as measureWriteScale, b as normalizeUsage, Ti as offloadPassThroughChars, wi as offloadThresholdChars, rs as presets, Wo as projectBySchema, Uo as projectBySchemaDeep, As as projectFields, Cc as recallRounds, Qo as renderSchemaHint, $o as renderSchemaOverview, ns as renderSchemaShallow, Sf as resolveCapabilities, Ef as resolveContextOptions, bf as resolveDialogConfig, Gd as resolveLlm, Ci as resolveModelCaps, Ec as resolvePromptSoftCap, No as resolveSchemaPath, yf as resolveStorage, Bs as restoreInPlace, zs as restoreLive, Xr as routeError, Js as runHostScript, ia as runSandboxedScript, Ts as safeMerge, Xf as safeSerialize, $ as safeStringify, Fo as schemaHasRefinement, Uf as searchDom, na as searchJson, lp as selectBuiltinTools, Es as setByPath, Dc as shouldTriggerCompression, Cd as stringifyDiagnosticsReport, as as systemPromptHelpers, yc as tokenize, X as toolError, ko as unwrapSchema, rm as useChat, dm as useChatContext, Po as validateAtPath, Ju as validateHtmlFormat, Fu as validateRootValueLocally, Iu as validateWriteLocally, Ps as watchFieldsHash, e as z, Jr as zodError };
|