page-agent-sdk 2.22.0 → 2.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/README.zh-CN.md +6 -6
- package/dist/page-agent-sdk.iife.js +121 -121
- package/dist/page-agent-sdk.js +744 -696
- package/dist/page-agent-sdk.umd.cjs +72 -72
- package/package.json +1 -1
- package/skills/page-agent-sdk-integrate/SKILL.md +1 -1
- package/skills/page-agent-sdk-integrate/references/advanced.md +1 -1
- package/skills/page-agent-sdk-integrate/references/api.md +2 -2
- package/skills/page-agent-sdk-integrate/references/integration-prompt.md +1 -1
- package/skills/page-agent-sdk-integrate/references/quickstart.md +4 -4
- package/skills/page-agent-sdk-integrate/references/use-cases.md +1 -1
- package/types/index.d.ts +1 -1
package/dist/page-agent-sdk.js
CHANGED
|
@@ -21,16 +21,18 @@ function _(e) {
|
|
|
21
21
|
function v(e) {
|
|
22
22
|
let t = e.model || "gpt-3.5-turbo", r = e.temperature, i = e.maxTokens, a = e.baseUrl;
|
|
23
23
|
if (e.mode === "direct") {
|
|
24
|
+
let o = !1;
|
|
24
25
|
try {
|
|
25
|
-
|
|
26
|
+
o = typeof location < "u" && location.protocol === "https:" && ![
|
|
26
27
|
"localhost",
|
|
27
28
|
"127.0.0.1",
|
|
28
29
|
"0.0.0.0"
|
|
29
|
-
].includes(location.hostname)
|
|
30
|
-
if (e.throwOnDirectInProduction) throw Error("[page-agent-sdk][proxyLlm] direct 模式在生产环境(https + 非本地)会泄露 apiKey(进 bundle),建议改用 proxy 模式(throwOnDirectInProduction 已启用强安全闸;若确需生产直连,设为 false 显式承认风险)");
|
|
31
|
-
console.warn("[page-agent-sdk][proxyLlm] direct 模式在生产环境(https + 非本地)会泄露 apiKey(进 bundle),建议改用 proxy 模式");
|
|
32
|
-
}
|
|
30
|
+
].includes(location.hostname);
|
|
33
31
|
} catch {}
|
|
32
|
+
if (o) {
|
|
33
|
+
if (e.throwOnDirectInProduction) throw Error("[page-agent-sdk][proxyLlm] direct 模式在生产环境(https + 非本地)会泄露 apiKey(进 bundle),建议改用 proxy 模式(throwOnDirectInProduction 已启用强安全闸;若确需生产直连,设为 false 显式承认风险)");
|
|
34
|
+
console.warn("[page-agent-sdk][proxyLlm] direct 模式在生产环境(https + 非本地)会泄露 apiKey(进 bundle),建议改用 proxy 模式");
|
|
35
|
+
}
|
|
34
36
|
if (!e.apiKey) throw Error("[page-agent-sdk][proxyLlm] direct 模式需提供 apiKey(开发环境用真实 key)");
|
|
35
37
|
return new n({
|
|
36
38
|
apiKey: e.apiKey,
|
|
@@ -14432,32 +14434,38 @@ function f_(e, t) {
|
|
|
14432
14434
|
function p_(e) {
|
|
14433
14435
|
return e ? /<|tool_calls|>|<||[^>]*tool_call|<||?DSML|<|tool[_a-z]*|>|<invoke\s+name=|<\/?tool_call>|<function_call>/i.test(e) : !1;
|
|
14434
14436
|
}
|
|
14435
|
-
|
|
14437
|
+
var m_ = /<|tool_calls|>|<||[^>]*tool_call|<||?DSML|<|tool[_a-z]*|>/i;
|
|
14438
|
+
function h_(e) {
|
|
14439
|
+
return e.replace(/```[\w-]*\n?[\s\S]*?```/g, "");
|
|
14440
|
+
}
|
|
14441
|
+
function g_(e) {
|
|
14436
14442
|
if (!e || !p_(e)) return null;
|
|
14437
|
-
let t =
|
|
14438
|
-
|
|
14439
|
-
|
|
14440
|
-
|
|
14441
|
-
|
|
14443
|
+
let t = h_(e);
|
|
14444
|
+
if (!m_.test(t)) return null;
|
|
14445
|
+
let n = /<(?:||?DSML||?)?\s*invoke\s+name=["']([^"']+)["'][^>]*>/gi, r = [], i;
|
|
14446
|
+
for (; (i = n.exec(t)) !== null;) r.push({
|
|
14447
|
+
name: i[1],
|
|
14448
|
+
tagStart: i.index,
|
|
14449
|
+
after: n.lastIndex
|
|
14442
14450
|
});
|
|
14443
|
-
if (!
|
|
14444
|
-
let
|
|
14445
|
-
for (let
|
|
14446
|
-
let
|
|
14447
|
-
if (u && u.index !== void 0 && (
|
|
14451
|
+
if (!r.length) return null;
|
|
14452
|
+
let a = /<\/(?:||?DSML||?)?\s*invoke\s*>/i, o = /<(?:||?DSML||?)?\s*parameter\s+name=["']([^"']+)["'][^>]*>([\s\S]*?)<\/(?:||?DSML||?)?\s*parameter\s*>/gi, s = /<(?:||?DSML||?)?\s*parameter\s+name=["'][^"']+["'][^>]*>/gi, c = /<\/(?:||?DSML||?)?\s*parameter\s*>/gi, l = [];
|
|
14453
|
+
for (let e = 0; e < r.length; e++) {
|
|
14454
|
+
let n = e + 1 < r.length ? r[e + 1].tagStart : t.length, i = t.slice(r[e].after, n), u = i.match(a);
|
|
14455
|
+
if (u && u.index !== void 0 && (i = i.slice(0, u.index)), (i.match(s) || []).length > (i.match(c) || []).length) continue;
|
|
14448
14456
|
let d = {};
|
|
14449
|
-
|
|
14457
|
+
o.lastIndex = 0;
|
|
14450
14458
|
let f;
|
|
14451
|
-
for (; (f =
|
|
14452
|
-
|
|
14453
|
-
id: `dsml_${
|
|
14454
|
-
name:
|
|
14459
|
+
for (; (f = o.exec(i)) !== null;) d[f[1]] = __(f[2].trim());
|
|
14460
|
+
l.push({
|
|
14461
|
+
id: `dsml_${e}_${Date.now().toString(36)}`,
|
|
14462
|
+
name: r[e].name,
|
|
14455
14463
|
args: d
|
|
14456
14464
|
});
|
|
14457
14465
|
}
|
|
14458
|
-
return
|
|
14466
|
+
return l.length ? l : null;
|
|
14459
14467
|
}
|
|
14460
|
-
function
|
|
14468
|
+
function __(e) {
|
|
14461
14469
|
if (e === "true") return !0;
|
|
14462
14470
|
if (e === "false") return !1;
|
|
14463
14471
|
if (e === "null") return null;
|
|
@@ -14467,8 +14475,8 @@ function h_(e) {
|
|
|
14467
14475
|
return e;
|
|
14468
14476
|
}
|
|
14469
14477
|
}
|
|
14470
|
-
var
|
|
14471
|
-
function
|
|
14478
|
+
var v_ = 10, y_ = 300, b_ = 6e3;
|
|
14479
|
+
function x_(e, t) {
|
|
14472
14480
|
let n = e.reduce((e, t) => e + (typeof t.content == "string" ? t.content.length : JSON.stringify(t.content).length), 0);
|
|
14473
14481
|
if (n <= t) return e;
|
|
14474
14482
|
let r = 0, i = n - t, a = Math.max(100, Math.min(400, Math.round(t / 500)));
|
|
@@ -14483,11 +14491,11 @@ function y_(e, t) {
|
|
|
14483
14491
|
});
|
|
14484
14492
|
});
|
|
14485
14493
|
}
|
|
14486
|
-
function
|
|
14494
|
+
function S_(e, t) {
|
|
14487
14495
|
return t ?? Math.max(e * 3, 30);
|
|
14488
14496
|
}
|
|
14489
|
-
function
|
|
14490
|
-
let { apiKey: t, baseUrl: r, model: c = "gpt-3.5-turbo", temperature: l = .7, maxTokens: u, extraBody: d, extraConfig: f, systemPrompt: p, tools: m = [], middleware: h = [], maxToolRounds: g =
|
|
14497
|
+
function C_(e) {
|
|
14498
|
+
let { apiKey: t, baseUrl: r, model: c = "gpt-3.5-turbo", temperature: l = .7, maxTokens: u, extraBody: d, extraConfig: f, systemPrompt: p, tools: m = [], middleware: h = [], maxToolRounds: g = v_, maxIterations: _, maxRetries: v = 2, retryDelayMs: y = 500, maxParallelTools: b = 1, maxVerifyAttempts: x = 0, onLog: S, onSpan: C, onTrace: w, onLlmChange: T, debug: E = !1 } = e, D = $g({
|
|
14491
14499
|
model: c,
|
|
14492
14500
|
contextWindow: e.contextWindow,
|
|
14493
14501
|
maxOutputTokens: e.maxOutputTokens
|
|
@@ -14498,10 +14506,10 @@ function x_(e) {
|
|
|
14498
14506
|
type: e,
|
|
14499
14507
|
data: t
|
|
14500
14508
|
};
|
|
14501
|
-
j.value.push(n), j.value.length >
|
|
14509
|
+
j.value.push(n), j.value.length > y_ && j.value.splice(0, j.value.length - y_), vn(j), S?.(n), E && console.log(`%c[Agent] ${e}`, "color:#667eea;font-weight:bold", t);
|
|
14502
14510
|
}
|
|
14503
14511
|
let ee = (e) => {
|
|
14504
|
-
j.value.push(e), j.value.length >
|
|
14512
|
+
j.value.push(e), j.value.length > y_ && j.value.splice(0, j.value.length - y_), vn(j);
|
|
14505
14513
|
}, N = /* @__PURE__ */ hn([]), P = 0, F = !!C || !!w;
|
|
14506
14514
|
function I(e, t, n, r = {}) {
|
|
14507
14515
|
if (!F) return null;
|
|
@@ -14514,7 +14522,7 @@ function x_(e) {
|
|
|
14514
14522
|
status: "ok",
|
|
14515
14523
|
attributes: r
|
|
14516
14524
|
};
|
|
14517
|
-
return N.value.push(i), N.value.length >
|
|
14525
|
+
return N.value.push(i), N.value.length > y_ && N.value.splice(0, N.value.length - y_), vn(N), i;
|
|
14518
14526
|
}
|
|
14519
14527
|
function te(e, t = "ok", n) {
|
|
14520
14528
|
!e || !F || (e.endTs = Date.now(), e.durationMs = e.endTs - e.startTs, e.status = t, n && Object.assign(e.attributes, n), vn(N), C?.(e));
|
|
@@ -14629,12 +14637,12 @@ function x_(e) {
|
|
|
14629
14637
|
return e instanceof a ? "human" : e instanceof i ? "ai" : e instanceof o ? "system" : e instanceof s ? "tool" : "unknown";
|
|
14630
14638
|
}
|
|
14631
14639
|
function ue(e, t) {
|
|
14632
|
-
return
|
|
14640
|
+
return x_(e, t);
|
|
14633
14641
|
}
|
|
14634
14642
|
function de(e) {
|
|
14635
14643
|
return !E && !S ? [] : e.map((e) => {
|
|
14636
14644
|
let t = le(e), n = { role: t === "human" ? "user" : t === "ai" ? "assistant" : t }, r = typeof e.content == "string" ? e.content : JSON.stringify(e.content);
|
|
14637
|
-
r && (n.content = r.length >
|
|
14645
|
+
r && (n.content = r.length > b_ ? r.slice(0, b_) + `…(截断 ${r.length - b_} 字符)` : r);
|
|
14638
14646
|
let i = e.tool_calls;
|
|
14639
14647
|
Array.isArray(i) && i.length && (n.tool_calls = i.map((e) => ({
|
|
14640
14648
|
id: e.id,
|
|
@@ -14664,7 +14672,7 @@ function x_(e) {
|
|
|
14664
14672
|
tools: L.map((e) => e.name),
|
|
14665
14673
|
middleware: h.map((e) => e.name)
|
|
14666
14674
|
});
|
|
14667
|
-
let l = d_(h, (e) => se(e, t, n)), u = f_(h, ce), d = 0, f = 0, p =
|
|
14675
|
+
let l = d_(h, (e) => se(e, t, n)), u = f_(h, ce), d = 0, f = 0, p = S_(g, _), m = null, v = 0, y = !1;
|
|
14668
14676
|
try {
|
|
14669
14677
|
for (; (d < g || y) && f < p && (f++, !n?.aborted);) {
|
|
14670
14678
|
let e = I(void 0, "round", `round ${f}`, { round: f })?.id;
|
|
@@ -14698,7 +14706,7 @@ function x_(e) {
|
|
|
14698
14706
|
content: o.content
|
|
14699
14707
|
}), o.content;
|
|
14700
14708
|
if (!o.toolCalls.length) {
|
|
14701
|
-
let e = p_(o.content), n = e ?
|
|
14709
|
+
let e = p_(o.content), n = e ? g_(o.content) : null;
|
|
14702
14710
|
if (n && n.length) {
|
|
14703
14711
|
o.toolCalls = n;
|
|
14704
14712
|
let e = o.message;
|
|
@@ -14879,13 +14887,13 @@ function x_(e) {
|
|
|
14879
14887
|
}
|
|
14880
14888
|
//#endregion
|
|
14881
14889
|
//#region src/core/harness/todos.ts
|
|
14882
|
-
var
|
|
14890
|
+
var w_ = /* @__PURE__ */ new Set([
|
|
14883
14891
|
"write",
|
|
14884
14892
|
"set_data",
|
|
14885
14893
|
"edit_data",
|
|
14886
14894
|
"delete_data"
|
|
14887
14895
|
]);
|
|
14888
|
-
function
|
|
14896
|
+
function T_(e) {
|
|
14889
14897
|
return e.map((e, t) => ({
|
|
14890
14898
|
id: e.id || `t-${t + 1}`,
|
|
14891
14899
|
content: e.content,
|
|
@@ -14896,7 +14904,7 @@ function C_(e) {
|
|
|
14896
14904
|
...e.evidence === void 0 ? {} : { evidence: e.evidence }
|
|
14897
14905
|
}));
|
|
14898
14906
|
}
|
|
14899
|
-
function
|
|
14907
|
+
function E_(e) {
|
|
14900
14908
|
if (!e.length) return;
|
|
14901
14909
|
let t = e.some((e) => e.parentId || e.deps && e.deps.length), n = [];
|
|
14902
14910
|
if (t) {
|
|
@@ -14918,14 +14926,14 @@ function w_(e) {
|
|
|
14918
14926
|
r
|
|
14919
14927
|
].join("\n");
|
|
14920
14928
|
}
|
|
14921
|
-
function
|
|
14922
|
-
let i =
|
|
14929
|
+
function D_(e = [], n = {}) {
|
|
14930
|
+
let i = T_(e), a = 0, o = !1, s = 0, c = n.maxPlanRevisions ?? 5;
|
|
14923
14931
|
return {
|
|
14924
14932
|
name: "todos",
|
|
14925
14933
|
tools: [r(async ({ todos: e }) => {
|
|
14926
14934
|
if (!o) o = !0, s = 1;
|
|
14927
14935
|
else if (s > c) return `规划阶段已达上限(${c} 轮)。停止调研/修订,基于当前清单开始执行(用 write/set_data/edit_data 落地)。当前清单:\n${i.map((e, t) => `${t + 1}. #${e.id} [${e.status}] ${e.content}`).join("\n") || "(空)"}`;
|
|
14928
|
-
return i =
|
|
14936
|
+
return i = T_(e), `已更新任务清单:${i.length} 项\n${i.map((e, t) => `${t + 1}. #${e.id} [${e.status}] ${e.content}`).join("\n")}`;
|
|
14929
14937
|
}, {
|
|
14930
14938
|
name: "write_todos",
|
|
14931
14939
|
description: "更新(整表替换)任务清单。用于多步任务的拆解与进度跟踪。每次传入完整的 todos 数组(状态 pending/in_progress/completed),不要增量 patch——增量改单项用 update_todo。",
|
|
@@ -14965,17 +14973,17 @@ function T_(e = [], n = {}) {
|
|
|
14965
14973
|
})],
|
|
14966
14974
|
beforeAgent: () => ({ todos: i }),
|
|
14967
14975
|
beforeModel: () => (a = 0, o && s++, { todos: i }),
|
|
14968
|
-
augmentPrompt: () =>
|
|
14976
|
+
augmentPrompt: () => E_(i),
|
|
14969
14977
|
wrapToolCall: async (e, t) => {
|
|
14970
14978
|
if ((e.name === "write_todos" || e.name === "update_todo") && (a++, a > 1)) return {
|
|
14971
14979
|
content: "错误:write_todos 与 update_todo 不应在一轮中并行/混用(整表替换与增量更新语义冲突)。请串行使用。",
|
|
14972
14980
|
status: "error"
|
|
14973
14981
|
};
|
|
14974
14982
|
let n = await t(e);
|
|
14975
|
-
return
|
|
14983
|
+
return w_.has(e.name) && n?.status !== "error" && (o = !1, s = 0), n;
|
|
14976
14984
|
},
|
|
14977
14985
|
reset: (e) => {
|
|
14978
|
-
i =
|
|
14986
|
+
i = T_(e.map((e) => ({ ...e }))), o = !1, s = 0;
|
|
14979
14987
|
},
|
|
14980
14988
|
getPlanPhase: () => ({
|
|
14981
14989
|
inPlanning: o,
|
|
@@ -14986,15 +14994,15 @@ function T_(e = [], n = {}) {
|
|
|
14986
14994
|
}
|
|
14987
14995
|
//#endregion
|
|
14988
14996
|
//#region src/core/harness/mission.ts
|
|
14989
|
-
var
|
|
14990
|
-
function
|
|
14991
|
-
return !e || e.trim().length < 8 || /^(你好|hi|hello|ok|好的|继续|嗯|谢谢|hey|哈喽|收到|明白)/i.test(e.trim()) || e.length > 2e3 ? !1 :
|
|
14997
|
+
var O_ = /(?:改|加|删|生成|查询|分析|创建|修改|配置|实现|检查|对比|整理|转换|设计|搭建|编排|布局|调整|更新)/;
|
|
14998
|
+
function k_(e) {
|
|
14999
|
+
return !e || e.trim().length < 8 || /^(你好|hi|hello|ok|好的|继续|嗯|谢谢|hey|哈喽|收到|明白)/i.test(e.trim()) || e.length > 2e3 ? !1 : O_.test(e);
|
|
14992
15000
|
}
|
|
14993
|
-
function
|
|
15001
|
+
function A_(e) {
|
|
14994
15002
|
for (let t = 0; t < e.length; t++) {
|
|
14995
15003
|
if (e[t].role !== "user") continue;
|
|
14996
15004
|
let n = e[t].content;
|
|
14997
|
-
if (
|
|
15005
|
+
if (k_(n)) return {
|
|
14998
15006
|
goal: n.length > 200 ? n.slice(0, 200) + "…" : n,
|
|
14999
15007
|
sourceMessageIdx: t,
|
|
15000
15008
|
capturedAt: Date.now(),
|
|
@@ -15002,11 +15010,11 @@ function O_(e) {
|
|
|
15002
15010
|
};
|
|
15003
15011
|
}
|
|
15004
15012
|
}
|
|
15005
|
-
function
|
|
15013
|
+
function j_() {
|
|
15006
15014
|
let e;
|
|
15007
15015
|
return {
|
|
15008
15016
|
name: "mission",
|
|
15009
|
-
beforeAgent: (t) => (e ||=
|
|
15017
|
+
beforeAgent: (t) => (e ||= A_(t.messages), e ? { mission: e } : {}),
|
|
15010
15018
|
augmentPrompt: () => {
|
|
15011
15019
|
if (!e) return;
|
|
15012
15020
|
let t = ["## 当前主线目标", e.goal];
|
|
@@ -15030,12 +15038,12 @@ function k_() {
|
|
|
15030
15038
|
}
|
|
15031
15039
|
//#endregion
|
|
15032
15040
|
//#region src/core/harness/workingMemory.ts
|
|
15033
|
-
var
|
|
15041
|
+
var M_ = 10, N_ = /* @__PURE__ */ new Set([
|
|
15034
15042
|
"read",
|
|
15035
15043
|
"query_data",
|
|
15036
15044
|
"search_data"
|
|
15037
15045
|
]);
|
|
15038
|
-
function
|
|
15046
|
+
function P_() {
|
|
15039
15047
|
let e = [], t = {}, n = () => e.length === 0 && Object.keys(t).length === 0, r = () => ({
|
|
15040
15048
|
locatedPaths: [...e],
|
|
15041
15049
|
lastHashes: { ...t }
|
|
@@ -15043,13 +15051,13 @@ function M_() {
|
|
|
15043
15051
|
function i(t) {
|
|
15044
15052
|
if (!t) return;
|
|
15045
15053
|
let n = e.indexOf(t);
|
|
15046
|
-
for (n >= 0 && e.splice(n, 1), e.unshift(t); e.length >
|
|
15054
|
+
for (n >= 0 && e.splice(n, 1), e.unshift(t); e.length > M_;) e.pop();
|
|
15047
15055
|
}
|
|
15048
15056
|
function a(e, n) {
|
|
15049
15057
|
if (t[e] === n) return;
|
|
15050
15058
|
delete t[e], t[e] = n;
|
|
15051
15059
|
let r = Object.keys(t);
|
|
15052
|
-
for (; r.length >
|
|
15060
|
+
for (; r.length > M_;) {
|
|
15053
15061
|
let e = r.shift();
|
|
15054
15062
|
delete t[e];
|
|
15055
15063
|
}
|
|
@@ -15060,7 +15068,7 @@ function M_() {
|
|
|
15060
15068
|
beforeModel: () => n() ? void 0 : { workingMemory: r() },
|
|
15061
15069
|
wrapToolCall: async (e, t) => {
|
|
15062
15070
|
let n = await t(e);
|
|
15063
|
-
if (n.status === "done" &&
|
|
15071
|
+
if (n.status === "done" && N_.has(e.name)) {
|
|
15064
15072
|
let t = typeof n.content == "string" ? n.content : "";
|
|
15065
15073
|
if (e.name === "read") {
|
|
15066
15074
|
let n = e.args?.jsonPath || "(root)";
|
|
@@ -15087,18 +15095,18 @@ function M_() {
|
|
|
15087
15095
|
}
|
|
15088
15096
|
//#endregion
|
|
15089
15097
|
//#region src/core/harness/skills.ts
|
|
15090
|
-
function
|
|
15098
|
+
function F_(e) {
|
|
15091
15099
|
return e;
|
|
15092
15100
|
}
|
|
15093
|
-
var
|
|
15094
|
-
function
|
|
15095
|
-
return
|
|
15101
|
+
var I_ = /^https?:\/\//i;
|
|
15102
|
+
function L_(e) {
|
|
15103
|
+
return I_.test(e) || e.startsWith("//") ? "http" : "vfs";
|
|
15096
15104
|
}
|
|
15097
|
-
function
|
|
15105
|
+
function R_(e) {
|
|
15098
15106
|
return e.replace(/^vfs:\/\//, "").replace(/^\/+/, "").replace(/\/+/g, "/");
|
|
15099
15107
|
}
|
|
15100
|
-
async function
|
|
15101
|
-
if (
|
|
15108
|
+
async function z_(e, t) {
|
|
15109
|
+
if (L_(e) === "http") try {
|
|
15102
15110
|
let t = await fetch(e);
|
|
15103
15111
|
return t.ok ? {
|
|
15104
15112
|
ok: !0,
|
|
@@ -15121,7 +15129,7 @@ async function L_(e, t) {
|
|
|
15121
15129
|
ok: !1,
|
|
15122
15130
|
error: `skill 文档 ${e} 是 vfs 路径,但 vfs 未启用`
|
|
15123
15131
|
};
|
|
15124
|
-
let n = t(
|
|
15132
|
+
let n = t(R_(e));
|
|
15125
15133
|
return n == null ? {
|
|
15126
15134
|
ok: !1,
|
|
15127
15135
|
error: `未找到 vfs 文档 ${e}(可用 vfs_ls 查看)`
|
|
@@ -15130,14 +15138,14 @@ async function L_(e, t) {
|
|
|
15130
15138
|
content: n
|
|
15131
15139
|
};
|
|
15132
15140
|
}
|
|
15133
|
-
function
|
|
15141
|
+
function B_(e) {
|
|
15134
15142
|
if (e.length) return [
|
|
15135
15143
|
"## 可用 Skills(渐进式披露)",
|
|
15136
15144
|
e.map((e) => `- ${e.name}: ${e.description}`).join("\n"),
|
|
15137
15145
|
"当某 skill 适用时,先调用 load_skill(name) 加载其完整指令,再按指令执行。不要凭记忆猜测 skill 内容。"
|
|
15138
15146
|
].join("\n");
|
|
15139
15147
|
}
|
|
15140
|
-
function
|
|
15148
|
+
function V_(e, n) {
|
|
15141
15149
|
let i = [...e], a = new Map(i.map((e) => [e.name, e])), o = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Map(), c = {
|
|
15142
15150
|
set(e) {
|
|
15143
15151
|
i = [...e], a = new Map(i.map((e) => [e.name, e])), s.clear(), o.clear();
|
|
@@ -15154,7 +15162,7 @@ function z_(e, n) {
|
|
|
15154
15162
|
let r = s.get(e);
|
|
15155
15163
|
if (r != null) return r;
|
|
15156
15164
|
if (t.doc) {
|
|
15157
|
-
let e = await
|
|
15165
|
+
let e = await z_(t.doc, n?.readVfs);
|
|
15158
15166
|
if (!e.ok) return null;
|
|
15159
15167
|
r = e.content;
|
|
15160
15168
|
} else if (t.getContent) r = await t.getContent();
|
|
@@ -15170,7 +15178,7 @@ function z_(e, n) {
|
|
|
15170
15178
|
let r = s.get(e);
|
|
15171
15179
|
if (r == null) {
|
|
15172
15180
|
if (t.doc) {
|
|
15173
|
-
let i = await
|
|
15181
|
+
let i = await z_(t.doc, n?.readVfs);
|
|
15174
15182
|
if (!i.ok) return `加载 skill "${e}" 文档失败:${i.error}`;
|
|
15175
15183
|
r = i.content;
|
|
15176
15184
|
} else if (t.getContent) r = await t.getContent();
|
|
@@ -15190,7 +15198,7 @@ function z_(e, n) {
|
|
|
15190
15198
|
})),
|
|
15191
15199
|
skillsLoaded: []
|
|
15192
15200
|
}),
|
|
15193
|
-
augmentPrompt: () =>
|
|
15201
|
+
augmentPrompt: () => B_(i),
|
|
15194
15202
|
afterModel: () => ({ skillsLoaded: [...o] })
|
|
15195
15203
|
};
|
|
15196
15204
|
return Object.defineProperty(l, "controller", {
|
|
@@ -15202,7 +15210,7 @@ function z_(e, n) {
|
|
|
15202
15210
|
}
|
|
15203
15211
|
//#endregion
|
|
15204
15212
|
//#region src/core/harness/memory.ts
|
|
15205
|
-
function
|
|
15213
|
+
function H_(e = "") {
|
|
15206
15214
|
let t = e, n = typeof e == "string" ? e : void 0;
|
|
15207
15215
|
async function r() {
|
|
15208
15216
|
if (typeof t == "string") return n = t, t;
|
|
@@ -15226,14 +15234,14 @@ function B_(e = "") {
|
|
|
15226
15234
|
}
|
|
15227
15235
|
//#endregion
|
|
15228
15236
|
//#region src/core/harness/permissions.ts
|
|
15229
|
-
var
|
|
15237
|
+
var U_ = /* @__PURE__ */ new Set([
|
|
15230
15238
|
"set_data",
|
|
15231
15239
|
"edit_data",
|
|
15232
15240
|
"delete_data",
|
|
15233
15241
|
"write",
|
|
15234
15242
|
"vfs_write",
|
|
15235
15243
|
"vfs_edit"
|
|
15236
|
-
]),
|
|
15244
|
+
]), W_ = /* @__PURE__ */ new Set([
|
|
15237
15245
|
"get_data",
|
|
15238
15246
|
"describe_data",
|
|
15239
15247
|
"read",
|
|
@@ -15244,7 +15252,7 @@ var V_ = /* @__PURE__ */ new Set([
|
|
|
15244
15252
|
"vfs_glob",
|
|
15245
15253
|
"vfs_grep"
|
|
15246
15254
|
]);
|
|
15247
|
-
function
|
|
15255
|
+
function G_(e) {
|
|
15248
15256
|
let t = "";
|
|
15249
15257
|
for (let n = 0; n < e.length; n++) {
|
|
15250
15258
|
let r = e[n];
|
|
@@ -15252,22 +15260,22 @@ function U_(e) {
|
|
|
15252
15260
|
}
|
|
15253
15261
|
return RegExp("^" + t + "$");
|
|
15254
15262
|
}
|
|
15255
|
-
function
|
|
15256
|
-
for (let r of e) if (r.operations.includes(t) && r.scopes.some((e) =>
|
|
15263
|
+
function K_(e, t, n) {
|
|
15264
|
+
for (let r of e) if (r.operations.includes(t) && r.scopes.some((e) => G_(e).test(n))) return r.mode;
|
|
15257
15265
|
return "allow";
|
|
15258
15266
|
}
|
|
15259
|
-
function
|
|
15267
|
+
function q_(e) {
|
|
15260
15268
|
let t = e ?? {}, n = /* @__PURE__ */ new Set();
|
|
15261
15269
|
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);
|
|
15262
15270
|
return [...n];
|
|
15263
15271
|
}
|
|
15264
|
-
function
|
|
15272
|
+
function J_(e) {
|
|
15265
15273
|
return {
|
|
15266
15274
|
name: "permissions",
|
|
15267
15275
|
wrapToolCall: async (t, n) => {
|
|
15268
|
-
let r =
|
|
15276
|
+
let r = U_.has(t.name) ? "write" : W_.has(t.name) ? "read" : null, i = q_(t.args);
|
|
15269
15277
|
if (r && i.length) {
|
|
15270
|
-
for (let t of i) if (
|
|
15278
|
+
for (let t of i) if (K_(e, r, t) === "deny") return {
|
|
15271
15279
|
content: `权限拒绝:${r} 操作 "${t}" 被 permissions 规则禁止。`,
|
|
15272
15280
|
status: "error"
|
|
15273
15281
|
};
|
|
@@ -15278,7 +15286,7 @@ function K_(e) {
|
|
|
15278
15286
|
}
|
|
15279
15287
|
//#endregion
|
|
15280
15288
|
//#region src/core/harness/approval.ts
|
|
15281
|
-
function
|
|
15289
|
+
function Y_(e = {}) {
|
|
15282
15290
|
let t = (t, n) => e.confirm ? !!e.confirm(t, n) : e.tools === void 0 || e.tools.includes(t);
|
|
15283
15291
|
return {
|
|
15284
15292
|
name: "approval",
|
|
@@ -15315,15 +15323,15 @@ function q_(e = {}) {
|
|
|
15315
15323
|
}
|
|
15316
15324
|
//#endregion
|
|
15317
15325
|
//#region src/core/harness/humanConfirm.ts
|
|
15318
|
-
var
|
|
15326
|
+
var X_ = "request_human_confirmation", Z_ = t.object({
|
|
15319
15327
|
question: t.string().describe("要征询用户的问题/方案描述。清晰具体:说明当前情况、为什么需要确认、确认什么。"),
|
|
15320
15328
|
options: t.array(t.string()).optional().describe("可选方案列表(2-4 个)。用户从中选一个。不传则用户只回答允许/拒绝。"),
|
|
15321
15329
|
recommendation: t.string().optional().describe("你推荐的方案(优先在 options 中选一个)及推荐理由,帮用户快速决策。"),
|
|
15322
15330
|
context: t.string().optional().describe("补充上下文:已做了什么、约束、影响范围等,帮用户判断。")
|
|
15323
15331
|
});
|
|
15324
|
-
function
|
|
15332
|
+
function Q_() {
|
|
15325
15333
|
return r(async () => "人工确认中间件未装载,无法征询用户。请直接向用户说明情况并等待回复。", {
|
|
15326
|
-
name:
|
|
15334
|
+
name: X_,
|
|
15327
15335
|
description: [
|
|
15328
15336
|
"当遇到以下情况时,主动调用本工具征询用户确认后再继续(不要默默猜测后直接执行高风险动作):",
|
|
15329
15337
|
"1) 不确定用户意图、需求有歧义;",
|
|
@@ -15333,10 +15341,10 @@ function X_() {
|
|
|
15333
15341
|
"入参:question=问题/方案描述;options=可选方案列表(多方案时给);recommendation=你推荐的方案及理由。",
|
|
15334
15342
|
"用户选择后,据其回答继续;若用户拒绝,停止当前操作并询问如何调整。"
|
|
15335
15343
|
].join(""),
|
|
15336
|
-
schema:
|
|
15344
|
+
schema: Z_
|
|
15337
15345
|
});
|
|
15338
15346
|
}
|
|
15339
|
-
function
|
|
15347
|
+
function $_() {
|
|
15340
15348
|
return {
|
|
15341
15349
|
name: "humanConfirm",
|
|
15342
15350
|
wrapToolCall: async (e, t) => e.name === "request_human_confirmation" ? new Promise((t) => {
|
|
@@ -15368,14 +15376,14 @@ function Z_() {
|
|
|
15368
15376
|
}
|
|
15369
15377
|
//#endregion
|
|
15370
15378
|
//#region src/core/harness/checkpoint.ts
|
|
15371
|
-
function
|
|
15379
|
+
function ev(e) {
|
|
15372
15380
|
if (typeof e != "object" || !e) return e;
|
|
15373
15381
|
if (typeof structuredClone == "function") try {
|
|
15374
15382
|
return structuredClone(e);
|
|
15375
15383
|
} catch {}
|
|
15376
15384
|
return JSON.parse(JSON.stringify(e));
|
|
15377
15385
|
}
|
|
15378
|
-
function
|
|
15386
|
+
function tv(e, t) {
|
|
15379
15387
|
let n = t.split("."), r = e;
|
|
15380
15388
|
for (let e of n) {
|
|
15381
15389
|
if (r == null) return;
|
|
@@ -15383,12 +15391,12 @@ function $_(e, t) {
|
|
|
15383
15391
|
}
|
|
15384
15392
|
return r;
|
|
15385
15393
|
}
|
|
15386
|
-
function
|
|
15394
|
+
function nv(e, t, n) {
|
|
15387
15395
|
let r = t.split("."), i = e;
|
|
15388
15396
|
for (let e = 0; e < r.length - 1; e++) i[r[e]] ?? (i[r[e]] = {}), i = i[r[e]];
|
|
15389
15397
|
i[r[r.length - 1]] = n;
|
|
15390
15398
|
}
|
|
15391
|
-
function
|
|
15399
|
+
function rv(e, t) {
|
|
15392
15400
|
if (Array.isArray(e)) {
|
|
15393
15401
|
e.length = 0, Array.isArray(t) && e.push(...t);
|
|
15394
15402
|
return;
|
|
@@ -15397,11 +15405,11 @@ function tv(e, t) {
|
|
|
15397
15405
|
for (let t of Object.keys(e)) t in n || delete e[t];
|
|
15398
15406
|
for (let t of Object.keys(n)) e[t] = n[t];
|
|
15399
15407
|
}
|
|
15400
|
-
function
|
|
15401
|
-
let n =
|
|
15402
|
-
typeof n == "object" && n ?
|
|
15408
|
+
function iv(e, t) {
|
|
15409
|
+
let n = tv(window, e);
|
|
15410
|
+
typeof n == "object" && n ? rv(n, t) : nv(window, e, t);
|
|
15403
15411
|
}
|
|
15404
|
-
function
|
|
15412
|
+
function av(e) {
|
|
15405
15413
|
let t = e.slice();
|
|
15406
15414
|
for (; t.length;) {
|
|
15407
15415
|
let e = t[t.length - 1];
|
|
@@ -15410,22 +15418,22 @@ function rv(e) {
|
|
|
15410
15418
|
}
|
|
15411
15419
|
return t;
|
|
15412
15420
|
}
|
|
15413
|
-
function
|
|
15421
|
+
function ov(e) {
|
|
15414
15422
|
let t = [], n = e.maxCheckpoints ?? 5, r = 1, i, a;
|
|
15415
15423
|
return {
|
|
15416
15424
|
save(o) {
|
|
15417
|
-
let s =
|
|
15418
|
-
if (e.getData) ((e.consumeDataDirty?.() ?? !0) || a === void 0) && (a =
|
|
15419
|
-
else for (let t of e.slotPaths ?? []) c[t] =
|
|
15420
|
-
((e.vfsStore.consumeDirty?.() ?? !0) || i === void 0) && (i =
|
|
15425
|
+
let s = av(e.messages), c = {};
|
|
15426
|
+
if (e.getData) ((e.consumeDataDirty?.() ?? !0) || a === void 0) && (a = ev(e.getData())), c[""] = a;
|
|
15427
|
+
else for (let t of e.slotPaths ?? []) c[t] = ev(tv(window, t));
|
|
15428
|
+
((e.vfsStore.consumeDirty?.() ?? !0) || i === void 0) && (i = ev(e.vfsStore.files));
|
|
15421
15429
|
let l = {
|
|
15422
15430
|
id: r++,
|
|
15423
15431
|
label: o,
|
|
15424
15432
|
timestamp: Date.now(),
|
|
15425
|
-
messages:
|
|
15433
|
+
messages: ev(s),
|
|
15426
15434
|
windowVals: c,
|
|
15427
15435
|
vfs: i,
|
|
15428
|
-
todos:
|
|
15436
|
+
todos: ev(e.getTodos()),
|
|
15429
15437
|
messageCount: s.length
|
|
15430
15438
|
};
|
|
15431
15439
|
for (t.push(l); t.length > n;) t.shift();
|
|
@@ -15445,19 +15453,19 @@ function iv(e) {
|
|
|
15445
15453
|
restore(n) {
|
|
15446
15454
|
let r = n == null ? t[t.length - 1] : t.find((e) => e.id === n);
|
|
15447
15455
|
if (!r) return !1;
|
|
15448
|
-
if (e.messages.splice(0, e.messages.length, ...
|
|
15456
|
+
if (e.messages.splice(0, e.messages.length, ...ev(r.messages)), e.getData) {
|
|
15449
15457
|
let t = r.windowVals[""];
|
|
15450
15458
|
if (t !== void 0) {
|
|
15451
15459
|
let n = e.getData();
|
|
15452
|
-
typeof n == "object" && n &&
|
|
15460
|
+
typeof n == "object" && n && rv(n, ev(t));
|
|
15453
15461
|
}
|
|
15454
|
-
} else for (let [e, t] of Object.entries(r.windowVals))
|
|
15462
|
+
} else for (let [e, t] of Object.entries(r.windowVals)) iv(e, ev(t));
|
|
15455
15463
|
let o = e.vfsStore.files;
|
|
15456
15464
|
for (let e of Object.keys(o)) delete o[e];
|
|
15457
|
-
return Object.assign(o,
|
|
15465
|
+
return Object.assign(o, ev(r.vfs)), e.todosMw.reset(ev(r.todos)), a = void 0, i = void 0, !0;
|
|
15458
15466
|
},
|
|
15459
15467
|
exportStack() {
|
|
15460
|
-
return
|
|
15468
|
+
return ev(t);
|
|
15461
15469
|
},
|
|
15462
15470
|
importStack(e) {
|
|
15463
15471
|
t.length = 0, i = void 0, a = void 0;
|
|
@@ -15467,7 +15475,7 @@ function iv(e) {
|
|
|
15467
15475
|
}
|
|
15468
15476
|
};
|
|
15469
15477
|
}
|
|
15470
|
-
function
|
|
15478
|
+
function sv(e) {
|
|
15471
15479
|
let t = !1;
|
|
15472
15480
|
return {
|
|
15473
15481
|
name: "checkpoint",
|
|
@@ -15481,54 +15489,54 @@ function av(e) {
|
|
|
15481
15489
|
}
|
|
15482
15490
|
//#endregion
|
|
15483
15491
|
//#region src/core/harness/subagent.ts
|
|
15484
|
-
function
|
|
15492
|
+
function cv(e) {
|
|
15485
15493
|
return !!e && typeof e == "object" && typeof e.invoke == "function" && typeof e.stream == "function";
|
|
15486
15494
|
}
|
|
15487
|
-
var
|
|
15495
|
+
var lv = [
|
|
15488
15496
|
"describe_data",
|
|
15489
15497
|
"get_data",
|
|
15490
15498
|
"read",
|
|
15491
15499
|
"query_data",
|
|
15492
15500
|
"search_data",
|
|
15493
15501
|
"fetch_document"
|
|
15494
|
-
],
|
|
15502
|
+
], uv = 1, dv = 4, fv = 6, pv = ["spawn_agent", "spawn_agents"], mv = [
|
|
15495
15503
|
"write",
|
|
15496
15504
|
"set_data",
|
|
15497
15505
|
"edit_data",
|
|
15498
15506
|
"delete_data",
|
|
15499
15507
|
"draft_commit"
|
|
15500
15508
|
];
|
|
15501
|
-
function
|
|
15509
|
+
function hv(e) {
|
|
15502
15510
|
let t = [];
|
|
15503
15511
|
if (typeof e.jsonPath == "string" && e.jsonPath && t.push(e.jsonPath), typeof e.path == "string" && e.path && t.push(e.path), e.patch && typeof e.patch.jsonPath == "string" && t.push(e.patch.jsonPath), Array.isArray(e.patches)) for (let n of e.patches) n && typeof n.jsonPath == "string" && t.push(n.jsonPath);
|
|
15504
15512
|
return t;
|
|
15505
15513
|
}
|
|
15506
|
-
function
|
|
15514
|
+
function gv(e, t) {
|
|
15507
15515
|
return t.some((t) => e === t || e.startsWith(t + ".") || e.startsWith(t + "["));
|
|
15508
15516
|
}
|
|
15509
|
-
function
|
|
15517
|
+
function _v(e, t) {
|
|
15510
15518
|
let n = e.invoke.bind(e), r = async (e) => {
|
|
15511
|
-
let r =
|
|
15519
|
+
let r = hv(e);
|
|
15512
15520
|
if (!r.length) return `PATH_OUT_OF_SCOPE:子 agent 仅可增量 patch(writablePaths: ${t.join(", ")}),不能整体替换(无 jsonPath)。用 write({patch:{jsonPath,...}}) 增量改。`;
|
|
15513
|
-
for (let e of r) if (!
|
|
15521
|
+
for (let e of r) if (!gv(e, t)) return `PATH_OUT_OF_SCOPE:子 agent 写 "${e}" 越界(仅可写 ${t.join(", ")})。`;
|
|
15514
15522
|
return n(e);
|
|
15515
15523
|
};
|
|
15516
15524
|
return new Proxy(e, { get(e, t, n) {
|
|
15517
15525
|
return t === "invoke" ? r : Reflect.get(e, t, n);
|
|
15518
15526
|
} });
|
|
15519
15527
|
}
|
|
15520
|
-
async function
|
|
15521
|
-
let a = t.depth ?? 0, o = t.maxDepth ??
|
|
15528
|
+
async function vv(e, t, n, r, i) {
|
|
15529
|
+
let a = t.depth ?? 0, o = t.maxDepth ?? uv, s = /* @__PURE__ */ new Set([...lv, ...t.allowedTools ?? []]), c = [...t.allTools.filter((e) => s.has(e.name) && !pv.includes(e.name)), ...t.extraTools ?? []];
|
|
15522
15530
|
if (t.writablePaths?.length) {
|
|
15523
|
-
c = c.filter((e) => !
|
|
15524
|
-
let e = t.allTools.filter((e) =>
|
|
15531
|
+
c = c.filter((e) => !mv.includes(e.name));
|
|
15532
|
+
let e = t.allTools.filter((e) => mv.includes(e.name) && !pv.includes(e.name)).map((e) => _v(e, t.writablePaths));
|
|
15525
15533
|
c = [...c, ...e];
|
|
15526
15534
|
}
|
|
15527
|
-
let l = a + 1 < o ? [
|
|
15535
|
+
let l = a + 1 < o ? [yv({
|
|
15528
15536
|
...t,
|
|
15529
15537
|
depth: a + 1
|
|
15530
|
-
})] : [], u =
|
|
15531
|
-
...
|
|
15538
|
+
})] : [], u = C_({
|
|
15539
|
+
...cv(t.llm) ? { llm: t.llm } : {
|
|
15532
15540
|
apiKey: t.llm.apiKey,
|
|
15533
15541
|
baseUrl: t.llm.baseUrl,
|
|
15534
15542
|
model: e.model ?? t.llm.model,
|
|
@@ -15537,8 +15545,8 @@ async function gv(e, t, n, r, i) {
|
|
|
15537
15545
|
},
|
|
15538
15546
|
systemPrompt: e.role?.trim() || t.systemPrompt || "你是一个专注的子任务执行者。你只有只读工具(读主数据 / 抓文档),用它们完成给定任务,给出简洁结论,不要展开多余解释。",
|
|
15539
15547
|
tools: c,
|
|
15540
|
-
middleware: [...t.skills?.length ? [
|
|
15541
|
-
maxToolRounds: t.maxToolRounds ??
|
|
15548
|
+
middleware: [...t.skills?.length ? [V_(t.skills)] : [], ...l],
|
|
15549
|
+
maxToolRounds: t.maxToolRounds ?? fv,
|
|
15542
15550
|
onLog: i,
|
|
15543
15551
|
debug: t.debug
|
|
15544
15552
|
});
|
|
@@ -15550,8 +15558,8 @@ async function gv(e, t, n, r, i) {
|
|
|
15550
15558
|
r && (e.type === "tool_call" || e.type === "tool_result") && r(e);
|
|
15551
15559
|
}, n);
|
|
15552
15560
|
}
|
|
15553
|
-
function
|
|
15554
|
-
let n = e.maxParallel ??
|
|
15561
|
+
function yv(e) {
|
|
15562
|
+
let n = e.maxParallel ?? dv, i, a, o, s = (e, t) => (n) => {
|
|
15555
15563
|
a && a({
|
|
15556
15564
|
type: "subagent",
|
|
15557
15565
|
taskId: e,
|
|
@@ -15571,7 +15579,7 @@ function _v(e) {
|
|
|
15571
15579
|
...r?.length ? { allowedTools: r } : {},
|
|
15572
15580
|
...a?.length ? { writablePaths: a } : {}
|
|
15573
15581
|
} : e, u = `sub-${Math.random().toString(36).slice(2, 8)}`, d = n?.trim() || "子任务";
|
|
15574
|
-
return await
|
|
15582
|
+
return await vv({
|
|
15575
15583
|
prompt: t,
|
|
15576
15584
|
role: n,
|
|
15577
15585
|
model: c
|
|
@@ -15591,7 +15599,7 @@ function _v(e) {
|
|
|
15591
15599
|
})
|
|
15592
15600
|
}), r(async ({ tasks: t }) => (await Xg(t, n, async (t, n) => {
|
|
15593
15601
|
let r = `sub-${n}-${Math.random().toString(36).slice(2, 6)}`, a = t.role?.trim() || `子任务${n + 1}`;
|
|
15594
|
-
return
|
|
15602
|
+
return vv(t, e, i, s(r, a), (e) => o?.({
|
|
15595
15603
|
...e,
|
|
15596
15604
|
source: `子:${a}`
|
|
15597
15605
|
}));
|
|
@@ -15606,8 +15614,8 @@ function _v(e) {
|
|
|
15606
15614
|
wrapToolCall: async (e, t) => (e.signal && (i = e.signal), e.emit && (a = e.emit), e.logSink && (o = e.logSink), t(e))
|
|
15607
15615
|
};
|
|
15608
15616
|
}
|
|
15609
|
-
var
|
|
15610
|
-
function
|
|
15617
|
+
var bv = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
15618
|
+
function xv(e, t) {
|
|
15611
15619
|
let n = e.tools ?? [];
|
|
15612
15620
|
return {
|
|
15613
15621
|
llm: e.llm ?? t.llm,
|
|
@@ -15622,7 +15630,7 @@ function yv(e, t) {
|
|
|
15622
15630
|
...e.writablePaths?.length ? { writablePaths: e.writablePaths } : {}
|
|
15623
15631
|
};
|
|
15624
15632
|
}
|
|
15625
|
-
function
|
|
15633
|
+
function Sv(e, n) {
|
|
15626
15634
|
let i, a, o, s = (e, t) => (n) => {
|
|
15627
15635
|
a && a({
|
|
15628
15636
|
type: "subagent",
|
|
@@ -15638,7 +15646,7 @@ function bv(e, n) {
|
|
|
15638
15646
|
function d(e) {
|
|
15639
15647
|
let a = /* @__PURE__ */ new Set(), c = [], l = [];
|
|
15640
15648
|
for (let u of e) {
|
|
15641
|
-
if (!
|
|
15649
|
+
if (!bv.test(u.id)) {
|
|
15642
15650
|
console.warn(`[subagents] id "${u.id}" 非合法工具名(须 [a-zA-Z_][a-zA-Z0-9_]*),已跳过`);
|
|
15643
15651
|
continue;
|
|
15644
15652
|
}
|
|
@@ -15648,8 +15656,8 @@ function bv(e, n) {
|
|
|
15648
15656
|
continue;
|
|
15649
15657
|
}
|
|
15650
15658
|
a.add(e), c.push(u), l.push(r(async ({ task: e }) => {
|
|
15651
|
-
let t =
|
|
15652
|
-
return
|
|
15659
|
+
let t = xv(u, n);
|
|
15660
|
+
return vv({ prompt: e }, t, i, s(`use_${u.id}`, u.id), (e) => o?.({
|
|
15653
15661
|
...e,
|
|
15654
15662
|
source: `子:${u.id}`
|
|
15655
15663
|
}));
|
|
@@ -15709,7 +15717,7 @@ function bv(e, n) {
|
|
|
15709
15717
|
}
|
|
15710
15718
|
//#endregion
|
|
15711
15719
|
//#region src/core/harness/verify.ts
|
|
15712
|
-
function
|
|
15720
|
+
function Cv(e) {
|
|
15713
15721
|
return {
|
|
15714
15722
|
name: "verify",
|
|
15715
15723
|
async beforeReturn({ messages: t, state: n, log: r }) {
|
|
@@ -15721,10 +15729,10 @@ function xv(e) {
|
|
|
15721
15729
|
if (e.adversarial) {
|
|
15722
15730
|
r?.("middleware", {
|
|
15723
15731
|
stage: "adversarial_start",
|
|
15724
|
-
model:
|
|
15732
|
+
model: jv(e.adversarial.llm),
|
|
15725
15733
|
tools: (e.adversarial.tools ?? []).length
|
|
15726
15734
|
});
|
|
15727
|
-
let n = await
|
|
15735
|
+
let n = await Fv(t, e.adversarial.llm, r, e.adversarial.tools);
|
|
15728
15736
|
if (r?.("middleware", {
|
|
15729
15737
|
stage: "adversarial_done",
|
|
15730
15738
|
clean: n === null,
|
|
@@ -15735,18 +15743,18 @@ function xv(e) {
|
|
|
15735
15743
|
}
|
|
15736
15744
|
};
|
|
15737
15745
|
}
|
|
15738
|
-
var
|
|
15746
|
+
var wv = /* @__PURE__ */ new Set([
|
|
15739
15747
|
"set_data",
|
|
15740
15748
|
"edit_data",
|
|
15741
15749
|
"delete_data",
|
|
15742
15750
|
"write"
|
|
15743
|
-
]),
|
|
15744
|
-
function
|
|
15751
|
+
]), Tv = /校验失败|SCHEMA_INVALID|未注册|不存在|仅支持|必须是|NOT_OBJECT|PATH_UNSAFE|VERSION_CONFLICT|WRITE_INTERCEPT/;
|
|
15752
|
+
function Ev(e) {
|
|
15745
15753
|
let t = /* @__PURE__ */ new Map();
|
|
15746
15754
|
for (let n of e) {
|
|
15747
15755
|
let e = n?.tool_calls;
|
|
15748
15756
|
if (Array.isArray(e)) for (let n of e) {
|
|
15749
|
-
if (!
|
|
15757
|
+
if (!wv.has(n.name)) continue;
|
|
15750
15758
|
let e = n.id, r = n?.args ?? {};
|
|
15751
15759
|
if (n.name === "write") if (r.del && r.patch?.jsonPath) t.set(r.patch.jsonPath, {
|
|
15752
15760
|
path: r.patch.jsonPath,
|
|
@@ -15785,7 +15793,7 @@ function wv(e) {
|
|
|
15785
15793
|
}
|
|
15786
15794
|
return [...t.values()];
|
|
15787
15795
|
}
|
|
15788
|
-
function
|
|
15796
|
+
function Dv(e) {
|
|
15789
15797
|
let t = /* @__PURE__ */ new Map();
|
|
15790
15798
|
for (let n of e) {
|
|
15791
15799
|
let e = n?.tool_call_id, r = n?.content;
|
|
@@ -15793,7 +15801,7 @@ function Tv(e) {
|
|
|
15793
15801
|
}
|
|
15794
15802
|
return t;
|
|
15795
15803
|
}
|
|
15796
|
-
function
|
|
15804
|
+
function Ov(e, t) {
|
|
15797
15805
|
if (t === "") return e;
|
|
15798
15806
|
if (e == null) return;
|
|
15799
15807
|
let n = e;
|
|
@@ -15803,16 +15811,16 @@ function Ev(e, t) {
|
|
|
15803
15811
|
}
|
|
15804
15812
|
return n;
|
|
15805
15813
|
}
|
|
15806
|
-
function
|
|
15814
|
+
function kv(e = {}) {
|
|
15807
15815
|
let t = typeof e.root == "function" ? e.root : e.root === void 0 ? () => e.window ?? globalThis.window : () => e.root, n = typeof e.schemas == "function" ? e.schemas : () => e.schemas ?? {};
|
|
15808
15816
|
return async ({ messages: e }) => {
|
|
15809
|
-
let r =
|
|
15817
|
+
let r = Ev(e);
|
|
15810
15818
|
if (!r.length) return { ok: !0 };
|
|
15811
|
-
let i =
|
|
15819
|
+
let i = Dv(e), a = n()[""], o = t(), s = [];
|
|
15812
15820
|
for (let { path: e, op: t, callId: n } of r) {
|
|
15813
15821
|
let r = n ? i.get(n) : void 0;
|
|
15814
|
-
if (r &&
|
|
15815
|
-
let c =
|
|
15822
|
+
if (r && Tv.test(r)) continue;
|
|
15823
|
+
let c = Ov(o, e);
|
|
15816
15824
|
if (t === "delete_data") c !== void 0 && s.push(`${e} 删除后读回仍有值,疑似未生效`);
|
|
15817
15825
|
else if (c == null) s.push(`写入 ${e} 后读回为空,疑似未生效`);
|
|
15818
15826
|
else if (a) {
|
|
@@ -15826,17 +15834,17 @@ function Dv(e = {}) {
|
|
|
15826
15834
|
} : { ok: !0 };
|
|
15827
15835
|
};
|
|
15828
15836
|
}
|
|
15829
|
-
function
|
|
15837
|
+
function Av(e) {
|
|
15830
15838
|
return !!e && typeof e == "object" && typeof e.invoke == "function" && typeof e.stream == "function";
|
|
15831
15839
|
}
|
|
15832
|
-
function kv(e) {
|
|
15833
|
-
return Ov(e) ? e.model ?? e.modelName ?? "<实例>" : e.model ?? "<配置>";
|
|
15834
|
-
}
|
|
15835
|
-
var Av = /无问题|没有问题|未发现问题|没有发现|没问题|未发现/;
|
|
15836
15840
|
function jv(e) {
|
|
15837
|
-
return Av
|
|
15841
|
+
return Av(e) ? e.model ?? e.modelName ?? "<实例>" : e.model ?? "<配置>";
|
|
15842
|
+
}
|
|
15843
|
+
var Mv = /无问题|没有问题|未发现问题|没有发现|没问题|未发现/;
|
|
15844
|
+
function Nv(e) {
|
|
15845
|
+
return Mv.test(e);
|
|
15838
15846
|
}
|
|
15839
|
-
function
|
|
15847
|
+
function Pv(e) {
|
|
15840
15848
|
let t = "", n = "";
|
|
15841
15849
|
for (let r of e) r instanceof a ? t = typeof r.content == "string" ? r.content : "" : r instanceof i && !(r.tool_calls?.length > 0) && (n = typeof r.content == "string" ? r.content : "");
|
|
15842
15850
|
return {
|
|
@@ -15844,8 +15852,8 @@ function Mv(e) {
|
|
|
15844
15852
|
lastReply: n
|
|
15845
15853
|
};
|
|
15846
15854
|
}
|
|
15847
|
-
async function
|
|
15848
|
-
let { lastUser: i, lastReply: a } =
|
|
15855
|
+
async function Fv(e, t, n, r) {
|
|
15856
|
+
let { lastUser: i, lastReply: a } = Pv(e);
|
|
15849
15857
|
if (!a) return null;
|
|
15850
15858
|
let o = Array.isArray(r) && r.length > 0, s = [
|
|
15851
15859
|
"你是严格的对抗式审查者,目标是找出以下 AI 助手回复的错误并证明它有问题(事实错误 / 遗漏 / 逻辑矛盾 / 与需求不符)。",
|
|
@@ -15856,7 +15864,7 @@ async function Nv(e, t, n, r) {
|
|
|
15856
15864
|
].join("\n"), c = "你是严格的对抗式审查者,只找问题不赞美。目标是反驳,不是改进。", l = n ? (e) => n(e.type, {
|
|
15857
15865
|
...e.data,
|
|
15858
15866
|
source: "adversarial"
|
|
15859
|
-
}) : void 0, u = await
|
|
15867
|
+
}) : void 0, u = await C_(Av(t) ? {
|
|
15860
15868
|
llm: t,
|
|
15861
15869
|
tools: r,
|
|
15862
15870
|
maxToolRounds: o ? 4 : 1,
|
|
@@ -15881,17 +15889,17 @@ async function Nv(e, t, n, r) {
|
|
|
15881
15889
|
stage: "adversarial_verdict",
|
|
15882
15890
|
verdict: u,
|
|
15883
15891
|
source: "adversarial"
|
|
15884
|
-
}),
|
|
15892
|
+
}), Nv(u) ? null : u.trim();
|
|
15885
15893
|
}
|
|
15886
15894
|
//#endregion
|
|
15887
15895
|
//#region src/core/mcp/client.ts
|
|
15888
|
-
function
|
|
15896
|
+
function Iv(e) {
|
|
15889
15897
|
let t = e?.content;
|
|
15890
15898
|
if (!Array.isArray(t) || !t.length) return "";
|
|
15891
15899
|
let n = t.map((e) => e.type === "text" && e.text ? e.text : e.type === "image" && e.data ? `[image:${String(e.data).slice(0, 32)}…]` : e.type === "audio" && e.data ? "[audio]" : e.type === "resource" && e.resource ? e.resource.text ?? e.resource.blob ?? "" : "").filter(Boolean).join("\n");
|
|
15892
15900
|
return e?.isError ? `工具错误:${n}` : n;
|
|
15893
15901
|
}
|
|
15894
|
-
async function
|
|
15902
|
+
async function Lv(e) {
|
|
15895
15903
|
let t = new URL(e.url), n = e.requestInit;
|
|
15896
15904
|
if (e.transport === "http") {
|
|
15897
15905
|
let { StreamableHTTPClientTransport: e } = await import("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
@@ -15904,8 +15912,8 @@ async function Fv(e) {
|
|
|
15904
15912
|
let { WebSocketClientTransport: r } = await import("@modelcontextprotocol/sdk/client/websocket.js");
|
|
15905
15913
|
return new r(t);
|
|
15906
15914
|
}
|
|
15907
|
-
function
|
|
15908
|
-
return r(async (n) =>
|
|
15915
|
+
function Rv(e, t) {
|
|
15916
|
+
return r(async (n) => Iv(await t.callTool({
|
|
15909
15917
|
name: e.name,
|
|
15910
15918
|
arguments: n
|
|
15911
15919
|
})), {
|
|
@@ -15914,21 +15922,21 @@ function Iv(e, t) {
|
|
|
15914
15922
|
schema: e.inputSchema
|
|
15915
15923
|
});
|
|
15916
15924
|
}
|
|
15917
|
-
async function
|
|
15918
|
-
let { Client: t } = await import("@modelcontextprotocol/sdk/client"), n = await
|
|
15925
|
+
async function zv(e) {
|
|
15926
|
+
let { Client: t } = await import("@modelcontextprotocol/sdk/client"), n = await Lv(e), r = new t({
|
|
15919
15927
|
name: "page-agent-sdk",
|
|
15920
15928
|
version: "1.0"
|
|
15921
15929
|
}, { capabilities: {} });
|
|
15922
15930
|
await r.connect(n);
|
|
15923
15931
|
let { tools: i } = await r.listTools();
|
|
15924
15932
|
return {
|
|
15925
|
-
tools: i.map((e) =>
|
|
15933
|
+
tools: i.map((e) => Rv(e, r)),
|
|
15926
15934
|
close: () => r.close()
|
|
15927
15935
|
};
|
|
15928
15936
|
}
|
|
15929
15937
|
//#endregion
|
|
15930
15938
|
//#region src/core/utils/rounds.ts
|
|
15931
|
-
function
|
|
15939
|
+
function Bv(e) {
|
|
15932
15940
|
let t = [], n = null, r = 0;
|
|
15933
15941
|
for (let i = 0; i < e.length; i++) {
|
|
15934
15942
|
let a = e[i];
|
|
@@ -15942,32 +15950,32 @@ function Rv(e) {
|
|
|
15942
15950
|
}
|
|
15943
15951
|
return n && t.push(n), t;
|
|
15944
15952
|
}
|
|
15945
|
-
function
|
|
15953
|
+
function Vv(e, t) {
|
|
15946
15954
|
let n = (e || "").replace(/```[\s\S]*?```/g, "[代码]").replace(/`([^`]+)`/g, "$1").replace(/[#*_>\-]\s?/g, "").replace(/\[(代码)\]/g, "「代码」").replace(/\s+/g, " ").trim();
|
|
15947
15955
|
return n.length > t ? n.slice(0, t) + "…" : n;
|
|
15948
15956
|
}
|
|
15949
|
-
var
|
|
15950
|
-
function
|
|
15957
|
+
var Hv = "【更早对话摘要";
|
|
15958
|
+
function Uv(e, t) {
|
|
15951
15959
|
return !t || !t.body ? e : {
|
|
15952
15960
|
body: `${t.body}\n【续】\n${e.body}`,
|
|
15953
15961
|
rounds: (t.rounds ?? 0) + (e.rounds ?? 0),
|
|
15954
15962
|
cumulative: !0
|
|
15955
15963
|
};
|
|
15956
15964
|
}
|
|
15957
|
-
function
|
|
15965
|
+
function Wv(e) {
|
|
15958
15966
|
return typeof e != "string" || !e.startsWith("【更早对话摘要") ? null : { body: e.replace(/^【[^】]*】\n?/, "") };
|
|
15959
15967
|
}
|
|
15960
|
-
function
|
|
15961
|
-
return `${
|
|
15968
|
+
function Gv(e) {
|
|
15969
|
+
return `${Hv}${e.cumulative ? `(${e.rounds ?? 0} 轮,含累积)` : e.rounds ? `(${e.rounds} 轮)` : ""}】\n${e.body}`;
|
|
15962
15970
|
}
|
|
15963
|
-
function
|
|
15971
|
+
function Kv(e, t) {
|
|
15964
15972
|
if (t <= 0) return { trimmed: !1 };
|
|
15965
|
-
let n =
|
|
15973
|
+
let n = Bv(e);
|
|
15966
15974
|
if (n.length <= t) return { trimmed: !1 };
|
|
15967
15975
|
let r = n[n.length - t].startIdx, i = n.slice(0, n.length - t), a = n[0].startIdx, o = null;
|
|
15968
15976
|
for (let t = 0; t < a; t++) {
|
|
15969
15977
|
let n = e[t];
|
|
15970
|
-
if (n.role === "system" && (o =
|
|
15978
|
+
if (n.role === "system" && (o = Wv(n.content), o)) break;
|
|
15971
15979
|
}
|
|
15972
15980
|
return {
|
|
15973
15981
|
trimmed: !0,
|
|
@@ -15975,9 +15983,9 @@ function Wv(e, t) {
|
|
|
15975
15983
|
deleteCount: r,
|
|
15976
15984
|
summary: {
|
|
15977
15985
|
role: "system",
|
|
15978
|
-
content: Uv(
|
|
15986
|
+
content: Gv(Uv({
|
|
15979
15987
|
body: i.map((e) => {
|
|
15980
|
-
let t =
|
|
15988
|
+
let t = Vv(e.userMsg.content, 60) || "(空)", n = e.assistantMsgs[0] ? Vv(e.assistantMsgs[0].content, 80) : "(无回复)";
|
|
15981
15989
|
return `- 第${e.round}轮:${t} → ${n}`;
|
|
15982
15990
|
}).join("\n"),
|
|
15983
15991
|
rounds: i.length
|
|
@@ -15988,33 +15996,33 @@ function Wv(e, t) {
|
|
|
15988
15996
|
}
|
|
15989
15997
|
//#endregion
|
|
15990
15998
|
//#region src/core/composables/contextIndex.ts
|
|
15991
|
-
var
|
|
15992
|
-
function
|
|
15993
|
-
return e.toLowerCase().split(/[^a-z0-9一-龥]+/i).map((e) => e.trim()).filter((e) => e.length >= 2 && !
|
|
15999
|
+
var qv = /* @__PURE__ */ new Set(/* @__PURE__ */ "的.了.是.在.我.你.他.她.它.这.那.和.与.及.或.一个.什么.怎么.如何.为什么.可以.能.请.帮.一下.需要.想要.the.a.an.is.are.of.to.in.on".split("."));
|
|
16000
|
+
function Jv(e) {
|
|
16001
|
+
return e.toLowerCase().split(/[^a-z0-9一-龥]+/i).map((e) => e.trim()).filter((e) => e.length >= 2 && !qv.has(e));
|
|
15994
16002
|
}
|
|
15995
|
-
function
|
|
16003
|
+
function Yv(e) {
|
|
15996
16004
|
let t = typeof e.content == "string" ? e.content : "";
|
|
15997
16005
|
if (e.reasoning && (t += e.reasoning), e.steps) for (let n of e.steps) t += " " + (n.name || ""), n.args != null && (t += " " + (typeof n.args == "string" ? n.args : JSON.stringify(n.args))), n.result && (t += " " + n.result);
|
|
15998
16006
|
return e_(t);
|
|
15999
16007
|
}
|
|
16000
|
-
function
|
|
16001
|
-
let t =
|
|
16002
|
-
for (let n of e.assistantMsgs) t +=
|
|
16008
|
+
function Xv(e) {
|
|
16009
|
+
let t = Yv(e.userMsg);
|
|
16010
|
+
for (let n of e.assistantMsgs) t += Yv(n);
|
|
16003
16011
|
return t;
|
|
16004
16012
|
}
|
|
16005
|
-
function
|
|
16013
|
+
function Zv(e, t) {
|
|
16006
16014
|
return e.map((e) => {
|
|
16007
|
-
let n =
|
|
16015
|
+
let n = Vv(e.userMsg.content, 60) || "(空)", r = e.assistantMsgs[0] ? Vv(e.assistantMsgs[0].content, 80) : "(无回复)", i = e.assistantMsgs.flatMap((e) => (e.steps || []).map((e) => e.name)), a = i.length ? ` [工具: ${i.join(", ")}]` : "", o = "";
|
|
16008
16016
|
if (t && t.size) {
|
|
16009
16017
|
let n = [];
|
|
16010
|
-
for (let r of e.assistantMsgs) for (let e of r.steps || []) e.name && t.has(e.name) && e.result && n.push(`${e.name}: ${
|
|
16018
|
+
for (let r of e.assistantMsgs) for (let e of r.steps || []) e.name && t.has(e.name) && e.result && n.push(`${e.name}: ${Vv(e.result, 120)}`);
|
|
16011
16019
|
n.length && (o = `\n 字段提示: ${n.join(" | ")}`);
|
|
16012
16020
|
}
|
|
16013
16021
|
return `- 第${e.round}轮:${n} → ${r}${a}${o}`;
|
|
16014
16022
|
}).join("\n");
|
|
16015
16023
|
}
|
|
16016
|
-
function
|
|
16017
|
-
let r =
|
|
16024
|
+
function Qv(e, t, n) {
|
|
16025
|
+
let r = Jv(t);
|
|
16018
16026
|
return r.length === 0 ? [] : e.map((e) => {
|
|
16019
16027
|
let t = (e.userMsg.content + " " + e.assistantMsgs.map((e) => e.content).join(" ")).toLowerCase(), n = 0;
|
|
16020
16028
|
for (let e of r) t.includes(e) && n++;
|
|
@@ -16026,7 +16034,7 @@ function Xv(e, t, n) {
|
|
|
16026
16034
|
}
|
|
16027
16035
|
//#endregion
|
|
16028
16036
|
//#region src/core/composables/useContextManager.ts
|
|
16029
|
-
var
|
|
16037
|
+
var $v = {
|
|
16030
16038
|
windowRounds: 6,
|
|
16031
16039
|
summaryThresholdRounds: 8,
|
|
16032
16040
|
toolResultMaxChars: 800,
|
|
@@ -16034,19 +16042,19 @@ var Zv = {
|
|
|
16034
16042
|
recallTopK: 3,
|
|
16035
16043
|
enableLLMSummary: !1
|
|
16036
16044
|
};
|
|
16037
|
-
function
|
|
16045
|
+
function ey(e = {}) {
|
|
16038
16046
|
let t = {
|
|
16039
|
-
|
|
16047
|
+
...$v,
|
|
16040
16048
|
...e
|
|
16041
16049
|
};
|
|
16042
16050
|
async function n(e) {
|
|
16043
|
-
let n =
|
|
16051
|
+
let n = Bv(e), r = e.length, i = "";
|
|
16044
16052
|
if (n.length) {
|
|
16045
16053
|
let t = n[0].startIdx;
|
|
16046
16054
|
for (let n = 0; n < t; n++) {
|
|
16047
16055
|
let t = e[n];
|
|
16048
16056
|
if (t.role === "system") {
|
|
16049
|
-
let e =
|
|
16057
|
+
let e = Wv(t.content);
|
|
16050
16058
|
if (e) {
|
|
16051
16059
|
i = e.body;
|
|
16052
16060
|
break;
|
|
@@ -16067,9 +16075,9 @@ function Qv(e = {}) {
|
|
|
16067
16075
|
}
|
|
16068
16076
|
}), o, s, c;
|
|
16069
16077
|
if (t.contextWindow && t.contextWindow > 0) {
|
|
16070
|
-
if (n.reduce((e, t) => e +
|
|
16078
|
+
if (n.reduce((e, t) => e + Xv(t), 0) <= t.contextWindow * (t.summaryThresholdRatio ?? .5)) return a("none");
|
|
16071
16079
|
let e = t.contextWindow * (t.windowRatio ?? .4), r = 0, i = 0;
|
|
16072
|
-
for (let t = n.length - 1; t >= 0; t--) if (r +=
|
|
16080
|
+
for (let t = n.length - 1; t >= 0; t--) if (r += Xv(n[t]), r >= e) {
|
|
16073
16081
|
i = t + 1;
|
|
16074
16082
|
break;
|
|
16075
16083
|
}
|
|
@@ -16082,12 +16090,12 @@ function Qv(e = {}) {
|
|
|
16082
16090
|
}
|
|
16083
16091
|
let l = [...e].reverse().find((e) => e.role === "user")?.content || "", u = t.preserveLastToolResults?.length ? new Set(t.preserveLastToolResults) : void 0, d, f;
|
|
16084
16092
|
if (t.enableLLMSummary && t.llmInvoke) try {
|
|
16085
|
-
d = await t.llmInvoke(
|
|
16093
|
+
d = await t.llmInvoke(Zv(s, u)), f = c + "llm_summary";
|
|
16086
16094
|
} catch {
|
|
16087
|
-
d =
|
|
16095
|
+
d = Zv(s, u), f = c + "index_summary(llm_fallback)";
|
|
16088
16096
|
}
|
|
16089
|
-
else d =
|
|
16090
|
-
let p = t.enableRecall ?
|
|
16097
|
+
else d = Zv(s, u), f = c + "index_summary";
|
|
16098
|
+
let p = t.enableRecall ? Qv(s, l, t.recallTopK) : [], m = p.length ? p.map((e) => `- 第${e.round}轮:${Vv(e.userMsg.content, 60)} → ${e.assistantMsgs[0] ? Vv(e.assistantMsgs[0].content, 80) : ""}`).join("\n") : "", h = i ? `${d}\n【更早累积摘要】\n${i}` : d, g = [`【对话历史摘要】以下是之前 ${s.length} 轮对话的要点(最新 ${o.length} 轮已完整保留):`, h];
|
|
16091
16099
|
m && g.push("\n【与当前问题可能相关的早期对话】", m);
|
|
16092
16100
|
let _ = t.getRegisteredData ?? t.getRegisteredSlots;
|
|
16093
16101
|
if (_) try {
|
|
@@ -16124,8 +16132,8 @@ function Qv(e = {}) {
|
|
|
16124
16132
|
}
|
|
16125
16133
|
//#endregion
|
|
16126
16134
|
//#region src/core/harness/summarization.ts
|
|
16127
|
-
function
|
|
16128
|
-
let t =
|
|
16135
|
+
function ty(e = {}) {
|
|
16136
|
+
let t = ey(e);
|
|
16129
16137
|
return {
|
|
16130
16138
|
name: "summarization",
|
|
16131
16139
|
compressInput: async (e) => {
|
|
@@ -16139,7 +16147,7 @@ function $v(e = {}) {
|
|
|
16139
16147
|
}
|
|
16140
16148
|
//#endregion
|
|
16141
16149
|
//#region src/core/tools/schemaUtils.ts
|
|
16142
|
-
function
|
|
16150
|
+
function ny(e) {
|
|
16143
16151
|
let t = e;
|
|
16144
16152
|
for (let e = 0; e < 5 && t && t._def; e++) {
|
|
16145
16153
|
if (t._def.innerType) {
|
|
@@ -16156,12 +16164,12 @@ function ey(e) {
|
|
|
16156
16164
|
return null;
|
|
16157
16165
|
}
|
|
16158
16166
|
}
|
|
16159
|
-
function
|
|
16167
|
+
function ry(e, t, n) {
|
|
16160
16168
|
if (!n || !e) return !0;
|
|
16161
|
-
let r =
|
|
16169
|
+
let r = iy(t);
|
|
16162
16170
|
for (let t of e.split(".")) {
|
|
16163
16171
|
if (!r) return !1;
|
|
16164
|
-
if (r =
|
|
16172
|
+
if (r = iy(r), r && r.shape && typeof r.shape == "object") {
|
|
16165
16173
|
let e = typeof r.shape == "function" ? r.shape() : r.shape;
|
|
16166
16174
|
if (!(t in e)) return !1;
|
|
16167
16175
|
r = e[t];
|
|
@@ -16171,7 +16179,7 @@ function ty(e, t, n) {
|
|
|
16171
16179
|
}
|
|
16172
16180
|
return !0;
|
|
16173
16181
|
}
|
|
16174
|
-
function
|
|
16182
|
+
function iy(e) {
|
|
16175
16183
|
let t = e;
|
|
16176
16184
|
for (let e = 0; e < 8 && t && t._def; e++) {
|
|
16177
16185
|
if (t._def.innerType) {
|
|
@@ -16190,59 +16198,59 @@ function ny(e) {
|
|
|
16190
16198
|
}
|
|
16191
16199
|
return t;
|
|
16192
16200
|
}
|
|
16193
|
-
function
|
|
16201
|
+
function ay(e, t) {
|
|
16194
16202
|
if (!t) return e;
|
|
16195
|
-
let n =
|
|
16203
|
+
let n = iy(e), r = t.split(".");
|
|
16196
16204
|
for (let e of r) {
|
|
16197
16205
|
if (!n) return null;
|
|
16198
|
-
if (n =
|
|
16206
|
+
if (n = iy(n), n && n.shape && typeof n.shape == "object") n = (typeof n.shape == "function" ? n.shape() : n.shape)[e];
|
|
16199
16207
|
else if (n && (n._def?.type === "array" || n.constructor?.name === "ZodArray")) n = n.element;
|
|
16200
16208
|
else if (n && (n._def?.type === "union" || n._def?.type === "discriminatedUnion" || Array.isArray(n.options))) return null;
|
|
16201
16209
|
else return null;
|
|
16202
16210
|
}
|
|
16203
16211
|
return n ?? null;
|
|
16204
16212
|
}
|
|
16205
|
-
function
|
|
16213
|
+
function oy(e, t) {
|
|
16206
16214
|
if (typeof e != "object" || !e || !t) return e;
|
|
16207
|
-
let n =
|
|
16215
|
+
let n = iy(t);
|
|
16208
16216
|
if (!n || !n.shape) {
|
|
16209
16217
|
if (Array.isArray(e) && (n?._def?.type || n?.element)) {
|
|
16210
16218
|
let t = n.element ?? n._def?.type;
|
|
16211
|
-
return e.map((e) =>
|
|
16219
|
+
return e.map((e) => oy(e, t));
|
|
16212
16220
|
}
|
|
16213
16221
|
return e;
|
|
16214
16222
|
}
|
|
16215
16223
|
let r = typeof n.shape == "function" ? n.shape() : n.shape, i = {};
|
|
16216
16224
|
for (let t of Object.keys(e)) if (t in r) {
|
|
16217
16225
|
let n = e[t];
|
|
16218
|
-
i[t] =
|
|
16226
|
+
i[t] = oy(n, r[t]);
|
|
16219
16227
|
}
|
|
16220
16228
|
return i;
|
|
16221
16229
|
}
|
|
16222
|
-
function
|
|
16230
|
+
function sy(e, t) {
|
|
16223
16231
|
if (!t || typeof e != "object" || !e || Array.isArray(e)) return e;
|
|
16224
16232
|
let n = new Set(t), r = {};
|
|
16225
16233
|
for (let t of Object.keys(e)) n.has(t) && (r[t] = e[t]);
|
|
16226
16234
|
return r;
|
|
16227
16235
|
}
|
|
16228
|
-
var
|
|
16229
|
-
function
|
|
16230
|
-
|
|
16236
|
+
var cy = !1;
|
|
16237
|
+
function ly() {
|
|
16238
|
+
cy ||= !0;
|
|
16231
16239
|
}
|
|
16232
|
-
function
|
|
16240
|
+
function uy(e) {
|
|
16233
16241
|
let t = e?._def?.checks;
|
|
16234
16242
|
if (!Array.isArray(t)) return [];
|
|
16235
16243
|
let n = [];
|
|
16236
16244
|
for (let e of t) e?._zod?.def && n.push(e._zod.def);
|
|
16237
16245
|
return n;
|
|
16238
16246
|
}
|
|
16239
|
-
function
|
|
16247
|
+
function dy(e) {
|
|
16240
16248
|
return e === -(2 ** 53 - 1) || e === -Infinity;
|
|
16241
16249
|
}
|
|
16242
|
-
function
|
|
16250
|
+
function fy(e) {
|
|
16243
16251
|
return e === 2 ** 53 - 1 || e === Infinity;
|
|
16244
16252
|
}
|
|
16245
|
-
function
|
|
16253
|
+
function py(e) {
|
|
16246
16254
|
let t = !1, n = !1, r = !1, i, a = e;
|
|
16247
16255
|
for (let e = 0; e < 8 && a && a._def; e++) {
|
|
16248
16256
|
let e = a._def.type;
|
|
@@ -16261,19 +16269,19 @@ function dy(e) {
|
|
|
16261
16269
|
break;
|
|
16262
16270
|
}
|
|
16263
16271
|
let o = a?._def?.type || "unknown";
|
|
16264
|
-
a?._def ||
|
|
16272
|
+
a?._def || ly();
|
|
16265
16273
|
let s = { type: o };
|
|
16266
16274
|
t && (s.optional = !0), n && (s.nullable = !0), r && (s.default = i), a?.description && (s.description = a.description);
|
|
16267
16275
|
let c = {};
|
|
16268
16276
|
switch (o) {
|
|
16269
16277
|
case "string": {
|
|
16270
16278
|
a.minLength != null && (c.minLength = a.minLength), a.maxLength != null && (c.maxLength = a.maxLength);
|
|
16271
|
-
let e =
|
|
16279
|
+
let e = uy(a).filter((e) => e.check === "string_format").map((e) => e.format).filter(Boolean);
|
|
16272
16280
|
e.length && (c.format = e.length === 1 ? e[0] : e);
|
|
16273
16281
|
break;
|
|
16274
16282
|
}
|
|
16275
16283
|
case "number":
|
|
16276
|
-
a.minValue != null && !
|
|
16284
|
+
a.minValue != null && !dy(a.minValue) && (c.min = a.minValue), a.maxValue != null && !fy(a.maxValue) && (c.max = a.maxValue), a.isInt && (c.int = !0), a.format && a.format !== "number" && (c.format = a.format);
|
|
16277
16285
|
break;
|
|
16278
16286
|
case "enum":
|
|
16279
16287
|
c.values = a.options;
|
|
@@ -16284,32 +16292,32 @@ function dy(e) {
|
|
|
16284
16292
|
break;
|
|
16285
16293
|
}
|
|
16286
16294
|
case "array":
|
|
16287
|
-
c.item =
|
|
16288
|
-
for (let e of
|
|
16295
|
+
c.item = py(a.element);
|
|
16296
|
+
for (let e of uy(a)) e.check === "min_length" ? c.minLength = e.minimum : e.check === "max_length" ? c.maxLength = e.maximum : e.check === "length_equals" && (c.length = e.length);
|
|
16289
16297
|
break;
|
|
16290
16298
|
case "object": {
|
|
16291
16299
|
let e = typeof a.shape == "function" ? a.shape() : a.shape;
|
|
16292
|
-
c.shape = Object.fromEntries(Object.entries(e || {}).map(([e, t]) => [e,
|
|
16300
|
+
c.shape = Object.fromEntries(Object.entries(e || {}).map(([e, t]) => [e, py(t)]));
|
|
16293
16301
|
break;
|
|
16294
16302
|
}
|
|
16295
16303
|
case "union": {
|
|
16296
|
-
let e = (a._def?.options || []).map((e) =>
|
|
16304
|
+
let e = (a._def?.options || []).map((e) => py(e));
|
|
16297
16305
|
e.length && (c.anyOf = e);
|
|
16298
16306
|
break;
|
|
16299
16307
|
}
|
|
16300
|
-
case "record": a._def?.valueType && (c.valueType =
|
|
16308
|
+
case "record": a._def?.valueType && (c.valueType = py(a._def.valueType));
|
|
16301
16309
|
}
|
|
16302
16310
|
return Object.keys(c).length && (s.constraints = c), s;
|
|
16303
16311
|
}
|
|
16304
|
-
function
|
|
16312
|
+
function my(e) {
|
|
16305
16313
|
let t = [];
|
|
16306
16314
|
return e.minLength !== void 0 && t.push(`minLen=${e.minLength}`), e.maxLength !== void 0 && t.push(`maxLen=${e.maxLength}`), e.length !== void 0 && t.push(`len=${e.length}`), e.min !== void 0 && t.push(`min=${e.min}`), e.max !== void 0 && t.push(`max=${e.max}`), e.int && t.push("int"), e.format && t.push(`format=${Array.isArray(e.format) ? e.format.join("|") : e.format}`), e.values && t.push(`enum=[${e.values.map((e) => String(e)).join("|")}]`), e.value !== void 0 && t.push(`=${JSON.stringify(e.value)}`), t.join(", ");
|
|
16307
16315
|
}
|
|
16308
|
-
function
|
|
16309
|
-
let n = t.constraints ?
|
|
16316
|
+
function hy(e, t) {
|
|
16317
|
+
let n = t.constraints ? my(t.constraints) : "", r = n ? `[${n}]` : "", i = t.optional ? "?" : "", a = t.description ? `: ${t.description}` : "";
|
|
16310
16318
|
return `- ${e} (${t.type}${i})${r}${a}`;
|
|
16311
16319
|
}
|
|
16312
|
-
function
|
|
16320
|
+
function gy(e) {
|
|
16313
16321
|
if (!e) return "";
|
|
16314
16322
|
try {
|
|
16315
16323
|
let t = e;
|
|
@@ -16329,18 +16337,18 @@ function my(e) {
|
|
|
16329
16337
|
break;
|
|
16330
16338
|
}
|
|
16331
16339
|
let n = t?.shape ? typeof t.shape == "function" ? t.shape() : t.shape : null;
|
|
16332
|
-
if (n && typeof n == "object" && Object.keys(n).length) return Object.entries(n).map(([e, t]) =>
|
|
16340
|
+
if (n && typeof n == "object" && Object.keys(n).length) return Object.entries(n).map(([e, t]) => hy(e, py(t))).join("\n");
|
|
16333
16341
|
} catch {}
|
|
16334
16342
|
try {
|
|
16335
|
-
return
|
|
16343
|
+
return hy("(root)", py(e));
|
|
16336
16344
|
} catch {}
|
|
16337
16345
|
return "";
|
|
16338
16346
|
}
|
|
16339
|
-
function
|
|
16340
|
-
let n =
|
|
16347
|
+
function _y(e, t) {
|
|
16348
|
+
let n = py(t), r = n.description ? `: ${n.description}` : "";
|
|
16341
16349
|
return `- ${e} (${n.type})${r}`;
|
|
16342
16350
|
}
|
|
16343
|
-
function
|
|
16351
|
+
function vy(e) {
|
|
16344
16352
|
if (!e) return "";
|
|
16345
16353
|
try {
|
|
16346
16354
|
let t = e;
|
|
@@ -16360,13 +16368,13 @@ function gy(e) {
|
|
|
16360
16368
|
break;
|
|
16361
16369
|
}
|
|
16362
16370
|
let n = t?.shape ? typeof t.shape == "function" ? t.shape() : t.shape : null;
|
|
16363
|
-
if (n && typeof n == "object" && Object.keys(n).length) return Object.entries(n).map(([e, t]) =>
|
|
16371
|
+
if (n && typeof n == "object" && Object.keys(n).length) return Object.entries(n).map(([e, t]) => _y(e, t)).join("\n");
|
|
16364
16372
|
} catch {}
|
|
16365
16373
|
return "";
|
|
16366
16374
|
}
|
|
16367
16375
|
//#endregion
|
|
16368
16376
|
//#region src/core/presets.ts
|
|
16369
|
-
var
|
|
16377
|
+
var yy = {
|
|
16370
16378
|
pageBuilder: { systemPrompt: "你是页面构建助手。按用户意图读写主数据(经 data 声明 + schema 校验),改完页面实时更新。" },
|
|
16371
16379
|
researcher: {
|
|
16372
16380
|
systemPrompt: "你是调研助手。多路调研用 spawn_agents 并行委派子 agent(各负责一个方向);单份资料用 fetch_document 抓取;最后结构化汇总,给出结论与依据。",
|
|
@@ -16380,33 +16388,33 @@ var _y = {
|
|
|
16380
16388
|
memory: !1,
|
|
16381
16389
|
subagent: !1
|
|
16382
16390
|
} }
|
|
16383
|
-
},
|
|
16391
|
+
}, by = { reliableWriteRules: [
|
|
16384
16392
|
"【可靠写入规则】",
|
|
16385
16393
|
"1. 改任何字段前,先用 read({ jsonPath }) 读其当前真实值,基于真实值改,不要凭记忆;",
|
|
16386
16394
|
"2. 若不确定可操作哪些字段,先 read() 不传 jsonPath 查看主数据说明 + schema 声明字段(集成方可经 sdk.setData 运行时替换 schema,以工具返回为准,勿凭旧记忆);",
|
|
16387
16395
|
"3. 不确定某字段结构时,read({ jsonPath }) 返回含格式说明,字段以返回为准;",
|
|
16388
16396
|
"4. 写入若被 schema 校验拒绝(返回结构化错误含字段名与期望类型),按错误修正后重试,不要放弃;",
|
|
16389
16397
|
"5. 优先用 write 的 patch 增量改(只发改动,如 write({ value, patch:{ op, jsonPath } })),避免整体重传大 JSON 被截断。"
|
|
16390
|
-
].join("\n") },
|
|
16391
|
-
function
|
|
16398
|
+
].join("\n") }, xy = 15, Sy = 4e3, Cy = /* @__PURE__ */ new WeakMap();
|
|
16399
|
+
function wy(e, t) {
|
|
16392
16400
|
if (!e) return "";
|
|
16393
16401
|
let n = t ? `${t.maxKeys ?? ""}|${t.maxChars ?? ""}` : "";
|
|
16394
16402
|
if (typeof e == "object") {
|
|
16395
|
-
let t =
|
|
16403
|
+
let t = Cy.get(e);
|
|
16396
16404
|
if (t && t.optsKey === n) return t.hint;
|
|
16397
16405
|
}
|
|
16398
|
-
let r =
|
|
16399
|
-
return typeof e == "object" &&
|
|
16406
|
+
let r = Ty(e, t);
|
|
16407
|
+
return typeof e == "object" && Cy.set(e, {
|
|
16400
16408
|
optsKey: n,
|
|
16401
16409
|
hint: r
|
|
16402
16410
|
}), r;
|
|
16403
16411
|
}
|
|
16404
|
-
function
|
|
16405
|
-
let n =
|
|
16412
|
+
function Ty(e, t) {
|
|
16413
|
+
let n = gy(e);
|
|
16406
16414
|
if (n) {
|
|
16407
|
-
let r = t?.maxKeys ??
|
|
16415
|
+
let r = t?.maxKeys ?? xy, i = t?.maxChars ?? Sy;
|
|
16408
16416
|
if (n.split("\n").filter((e) => e.trim().startsWith("- ")).length > r || n.length > i) {
|
|
16409
|
-
let t =
|
|
16417
|
+
let t = vy(e);
|
|
16410
16418
|
if (t) return "## 可操作数据(顶层概览;深层约束查 schema_data)\n" + t + "\n提示:改某组件深层字段前,先 schema_data({jsonPath}) 查完整约束(advanced);或 read 子路径见实际值。";
|
|
16411
16419
|
}
|
|
16412
16420
|
return n;
|
|
@@ -16415,36 +16423,36 @@ function Cy(e, t) {
|
|
|
16415
16423
|
}
|
|
16416
16424
|
//#endregion
|
|
16417
16425
|
//#region src/core/sdk/promptBuilder.ts
|
|
16418
|
-
var
|
|
16426
|
+
var Ey = [
|
|
16419
16427
|
"你是一个 JSON 操作助手。集成方声明了一个主数据对象(含 zod schema 校验),你通过专用工具安全地读写它来完成任务。",
|
|
16420
16428
|
"所有写操作都经范围控制(仅 schema 声明字段内)与 schema 校验(不合法会返回结构化错误而非写入),并自动留快照可回退。",
|
|
16421
16429
|
"大对象/数组优先用增量 patch(只发改动)而非整体重传,避免输出被截断。",
|
|
16422
16430
|
"---",
|
|
16423
|
-
|
|
16431
|
+
by.reliableWriteRules
|
|
16424
16432
|
].join("\n\n");
|
|
16425
|
-
function
|
|
16433
|
+
function Dy(e, t) {
|
|
16426
16434
|
if (!e) return "";
|
|
16427
|
-
let n =
|
|
16435
|
+
let n = wy(e.schema, t);
|
|
16428
16436
|
return `\n\n## 可操作数据(字段以 read 工具返回的实际值为准)\n${e.description ? e.description + "\n" : ""}${n}`;
|
|
16429
16437
|
}
|
|
16430
|
-
function
|
|
16438
|
+
function Oy(e) {
|
|
16431
16439
|
let t = e.appendReliableWriteRules !== !1;
|
|
16432
|
-
return e.systemPrompt ? t ? e.systemPrompt + "\n\n---\n\n" +
|
|
16440
|
+
return e.systemPrompt ? t ? e.systemPrompt + "\n\n---\n\n" + by.reliableWriteRules : e.systemPrompt : Ey;
|
|
16433
16441
|
}
|
|
16434
16442
|
//#endregion
|
|
16435
16443
|
//#region src/core/sdk/llmResolver.ts
|
|
16436
|
-
function
|
|
16444
|
+
function ky(e) {
|
|
16437
16445
|
return !!e && typeof e == "object" && typeof e.invoke == "function" && typeof e.stream == "function";
|
|
16438
16446
|
}
|
|
16439
|
-
function
|
|
16447
|
+
function Ay(e) {
|
|
16440
16448
|
let t = e.content;
|
|
16441
16449
|
return typeof t == "string" ? t : Array.isArray(t) ? t.map((e) => typeof e == "string" ? e : e?.text ?? "").join("") : String(t ?? "");
|
|
16442
16450
|
}
|
|
16443
|
-
function
|
|
16451
|
+
function jy(e) {
|
|
16444
16452
|
let t = e.summaryLlm ?? e.llm;
|
|
16445
16453
|
if (!t) return;
|
|
16446
16454
|
let r = e.summaryTemperature ?? .3, i = e.summaryMaxTokens ?? 1024, s = e.summaryTimeoutMs ?? 15e3, c;
|
|
16447
|
-
if (
|
|
16455
|
+
if (ky(t)) c = t;
|
|
16448
16456
|
else {
|
|
16449
16457
|
let a = t;
|
|
16450
16458
|
if (!a.apiKey) {
|
|
@@ -16466,26 +16474,26 @@ function ky(e) {
|
|
|
16466
16474
|
return async (e) => {
|
|
16467
16475
|
let t = new AbortController(), n = setTimeout(() => t.abort(), s);
|
|
16468
16476
|
try {
|
|
16469
|
-
return
|
|
16477
|
+
return Ay(await c.invoke([new o("你是对话历史压缩助手。把下面按轮次索引的对话要点,改写成一段连贯、紧凑的中文摘要,保留关键事实、用户意图与已用工具,不要编造。直接输出摘要正文。"), new a(e)], { signal: t.signal })).trim();
|
|
16470
16478
|
} finally {
|
|
16471
16479
|
clearTimeout(n);
|
|
16472
16480
|
}
|
|
16473
16481
|
};
|
|
16474
16482
|
}
|
|
16475
|
-
function
|
|
16476
|
-
let t =
|
|
16483
|
+
function My(e) {
|
|
16484
|
+
let t = ky(e.llm) ? void 0 : e.llm;
|
|
16477
16485
|
return {
|
|
16478
16486
|
modelCaps: $g({
|
|
16479
16487
|
model: t?.model,
|
|
16480
16488
|
contextWindow: e.contextWindow ?? t?.contextWindow,
|
|
16481
16489
|
maxOutputTokens: e.maxOutputTokens ?? t?.maxOutputTokens
|
|
16482
16490
|
}),
|
|
16483
|
-
summaryLlmInvoke:
|
|
16491
|
+
summaryLlmInvoke: jy(e)
|
|
16484
16492
|
};
|
|
16485
16493
|
}
|
|
16486
16494
|
//#endregion
|
|
16487
16495
|
//#region src/core/sdk/conflictManager.ts
|
|
16488
|
-
function
|
|
16496
|
+
function Ny(e) {
|
|
16489
16497
|
let t = /* @__PURE__ */ U(null), n = 0;
|
|
16490
16498
|
function r(r) {
|
|
16491
16499
|
return new Promise((i) => {
|
|
@@ -16516,7 +16524,7 @@ function jy(e) {
|
|
|
16516
16524
|
}
|
|
16517
16525
|
//#endregion
|
|
16518
16526
|
//#region src/core/utils/id.ts
|
|
16519
|
-
function
|
|
16527
|
+
function Py() {
|
|
16520
16528
|
try {
|
|
16521
16529
|
if (typeof crypto < "u" && typeof crypto.randomUUID == "function") return crypto.randomUUID();
|
|
16522
16530
|
} catch {}
|
|
@@ -16524,7 +16532,7 @@ function My() {
|
|
|
16524
16532
|
}
|
|
16525
16533
|
//#endregion
|
|
16526
16534
|
//#region src/core/backends/storage.ts
|
|
16527
|
-
var
|
|
16535
|
+
var Fy = "chat-sdk", Iy = 52428800, Ly = 4194304, Ry = 10485760, zy = .9, By = 500, Vy = 300, Hy = "__meta__", Uy = "v:1", Wy = [
|
|
16528
16536
|
"messages",
|
|
16529
16537
|
"vfs",
|
|
16530
16538
|
"todos",
|
|
@@ -16532,51 +16540,51 @@ var Ny = "chat-sdk", Py = 52428800, Fy = 4194304, Iy = 10485760, Ly = .9, Ry = 5
|
|
|
16532
16540
|
"checkpoints",
|
|
16533
16541
|
"usage"
|
|
16534
16542
|
];
|
|
16535
|
-
function
|
|
16536
|
-
return e === "local" || e === "session" ?
|
|
16543
|
+
function Gy(e) {
|
|
16544
|
+
return e === "local" || e === "session" ? Ly : Iy;
|
|
16537
16545
|
}
|
|
16538
|
-
function
|
|
16546
|
+
function Ky(e) {
|
|
16539
16547
|
if (typeof e != "object" || !e) return !1;
|
|
16540
16548
|
let t = e;
|
|
16541
16549
|
return t.name === "QuotaExceededError" || t.name === "NS_ERROR_DOM_QUOTA_REACHED" || t.code === 22 || t.code === 1014;
|
|
16542
16550
|
}
|
|
16543
|
-
function
|
|
16551
|
+
function qy(e, t, n, r) {
|
|
16544
16552
|
return [
|
|
16545
|
-
|
|
16553
|
+
Uy,
|
|
16546
16554
|
e,
|
|
16547
16555
|
t,
|
|
16548
16556
|
n,
|
|
16549
16557
|
r
|
|
16550
16558
|
].join("::");
|
|
16551
16559
|
}
|
|
16552
|
-
function
|
|
16560
|
+
function Jy(e, t, n) {
|
|
16553
16561
|
return [
|
|
16554
|
-
|
|
16562
|
+
Uy,
|
|
16555
16563
|
e,
|
|
16556
16564
|
t,
|
|
16557
16565
|
n
|
|
16558
16566
|
].join("::") + "::";
|
|
16559
16567
|
}
|
|
16560
|
-
function
|
|
16568
|
+
function Yy(e, t) {
|
|
16561
16569
|
return [
|
|
16562
|
-
|
|
16570
|
+
Uy,
|
|
16563
16571
|
e,
|
|
16564
16572
|
t
|
|
16565
16573
|
].join("::") + "::";
|
|
16566
16574
|
}
|
|
16567
|
-
function Jy(e) {
|
|
16568
|
-
return [Vy, e].join("::") + "::";
|
|
16569
|
-
}
|
|
16570
|
-
var Yy = null;
|
|
16571
16575
|
function Xy(e) {
|
|
16572
|
-
|
|
16576
|
+
return [Uy, e].join("::") + "::";
|
|
16577
|
+
}
|
|
16578
|
+
var Zy = null;
|
|
16579
|
+
function Qy(e) {
|
|
16580
|
+
Zy ||= new TextEncoder();
|
|
16573
16581
|
try {
|
|
16574
|
-
return
|
|
16582
|
+
return Zy.encode(JSON.stringify(e)).length;
|
|
16575
16583
|
} catch {
|
|
16576
16584
|
return 0;
|
|
16577
16585
|
}
|
|
16578
16586
|
}
|
|
16579
|
-
function
|
|
16587
|
+
function $y(e, t, n) {
|
|
16580
16588
|
let r = e.reduce((e, t) => e + t.bytes, 0);
|
|
16581
16589
|
if (r <= t) return [];
|
|
16582
16590
|
let i = t * n, a = [...e].sort((e, t) => e.lastAccessed - t.lastAccessed), o = [];
|
|
@@ -16586,7 +16594,7 @@ function Zy(e, t, n) {
|
|
|
16586
16594
|
}
|
|
16587
16595
|
return o;
|
|
16588
16596
|
}
|
|
16589
|
-
function
|
|
16597
|
+
function eb() {
|
|
16590
16598
|
let e = /* @__PURE__ */ new Map();
|
|
16591
16599
|
return {
|
|
16592
16600
|
async get(t) {
|
|
@@ -16606,7 +16614,7 @@ function Qy() {
|
|
|
16606
16614
|
}
|
|
16607
16615
|
};
|
|
16608
16616
|
}
|
|
16609
|
-
function
|
|
16617
|
+
function tb(e) {
|
|
16610
16618
|
return new Promise((t, n) => {
|
|
16611
16619
|
if (typeof indexedDB > "u") {
|
|
16612
16620
|
n(/* @__PURE__ */ Error("indexedDB 不可用"));
|
|
@@ -16667,7 +16675,7 @@ function $y(e) {
|
|
|
16667
16675
|
}, r.onerror = () => n(r.error);
|
|
16668
16676
|
});
|
|
16669
16677
|
}
|
|
16670
|
-
function
|
|
16678
|
+
function nb(e) {
|
|
16671
16679
|
return {
|
|
16672
16680
|
async get(t) {
|
|
16673
16681
|
let n = e.getItem(t);
|
|
@@ -16701,12 +16709,12 @@ function eb(e) {
|
|
|
16701
16709
|
}
|
|
16702
16710
|
};
|
|
16703
16711
|
}
|
|
16704
|
-
function
|
|
16712
|
+
function rb(e, t, n) {
|
|
16705
16713
|
let r = (e.get(t) ?? Promise.resolve()).then(n, n);
|
|
16706
16714
|
return e.set(t, r.then(() => void 0, () => void 0)), r;
|
|
16707
16715
|
}
|
|
16708
|
-
function
|
|
16709
|
-
let t = e.dbName ??
|
|
16716
|
+
function ib(e = {}) {
|
|
16717
|
+
let t = e.dbName ?? Fy, n = e.backend ?? "indexed", r = e.maxBytes ?? Gy(n), i = e.maxBytesPerSession ?? Ry, a = e.evictionWatermark ?? zy, o = e.debounceMs ?? By, s = /* @__PURE__ */ new Set();
|
|
16710
16718
|
function c(e) {
|
|
16711
16719
|
for (let t of s) try {
|
|
16712
16720
|
t(e);
|
|
@@ -16719,16 +16727,16 @@ function nb(e = {}) {
|
|
|
16719
16727
|
try {
|
|
16720
16728
|
if (n === "indexed") {
|
|
16721
16729
|
if (typeof indexedDB > "u") throw Error("indexedDB 不可用");
|
|
16722
|
-
l = await
|
|
16730
|
+
l = await tb(t), d(!0);
|
|
16723
16731
|
} else if (n === "session") {
|
|
16724
16732
|
if (typeof sessionStorage > "u") throw Error("sessionStorage 不可用");
|
|
16725
|
-
l =
|
|
16733
|
+
l = nb(sessionStorage), d(!0);
|
|
16726
16734
|
} else if (n === "local") {
|
|
16727
16735
|
if (typeof localStorage > "u") throw Error("localStorage 不可用");
|
|
16728
|
-
l =
|
|
16729
|
-
} else l =
|
|
16736
|
+
l = nb(localStorage), d(!0);
|
|
16737
|
+
} else l = eb(), d(!1);
|
|
16730
16738
|
} catch (e) {
|
|
16731
|
-
l =
|
|
16739
|
+
l = eb();
|
|
16732
16740
|
let t = e instanceof Error ? e.message : String(e);
|
|
16733
16741
|
d(!1), Promise.resolve().then(() => c({
|
|
16734
16742
|
type: "degraded",
|
|
@@ -16738,10 +16746,10 @@ function nb(e = {}) {
|
|
|
16738
16746
|
})();
|
|
16739
16747
|
let p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
|
|
16740
16748
|
function g(e, n, r, a) {
|
|
16741
|
-
let o =
|
|
16742
|
-
return
|
|
16749
|
+
let o = qy(t, r, a, Hy);
|
|
16750
|
+
return rb(h, o, async () => {
|
|
16743
16751
|
let t = async () => {
|
|
16744
|
-
let t = await l.get(o), s = await l.get(e), u = s == null ? 0 :
|
|
16752
|
+
let t = await l.get(o), s = await l.get(e), u = s == null ? 0 : Qy(s), d = Qy(n), f = (t?.bytes ?? 0) + (d - u);
|
|
16745
16753
|
if (f > i) {
|
|
16746
16754
|
c({
|
|
16747
16755
|
type: "quota",
|
|
@@ -16763,12 +16771,12 @@ function nb(e = {}) {
|
|
|
16763
16771
|
try {
|
|
16764
16772
|
await t();
|
|
16765
16773
|
} catch (e) {
|
|
16766
|
-
if (
|
|
16774
|
+
if (Ky(e) && !u) {
|
|
16767
16775
|
u = !0;
|
|
16768
16776
|
try {
|
|
16769
16777
|
await b();
|
|
16770
16778
|
} catch {}
|
|
16771
|
-
l =
|
|
16779
|
+
l = eb(), Promise.resolve().then(() => c({
|
|
16772
16780
|
type: "degraded",
|
|
16773
16781
|
reason: "存储配额超限(QuotaExceededError),已淘汰最旧会话并降级内存"
|
|
16774
16782
|
}));
|
|
@@ -16780,7 +16788,7 @@ function nb(e = {}) {
|
|
|
16780
16788
|
});
|
|
16781
16789
|
}
|
|
16782
16790
|
function _(e, n, r, i) {
|
|
16783
|
-
let a =
|
|
16791
|
+
let a = qy(t, e, n, r), s = p.get(a);
|
|
16784
16792
|
s && s.resolve();
|
|
16785
16793
|
let c = m.get(a);
|
|
16786
16794
|
return c && clearTimeout(c), new Promise((t) => {
|
|
@@ -16807,15 +16815,15 @@ function nb(e = {}) {
|
|
|
16807
16815
|
function y() {
|
|
16808
16816
|
v ||= setTimeout(() => {
|
|
16809
16817
|
v = null, b();
|
|
16810
|
-
},
|
|
16818
|
+
}, Vy);
|
|
16811
16819
|
}
|
|
16812
16820
|
async function b() {
|
|
16813
16821
|
let e = [];
|
|
16814
|
-
await l.scan(
|
|
16822
|
+
await l.scan(Xy(t), (t, n) => {
|
|
16815
16823
|
t.endsWith("::__meta__") && e.push(n);
|
|
16816
16824
|
});
|
|
16817
|
-
let n =
|
|
16818
|
-
for (let e of n) await l.clearPrefix(
|
|
16825
|
+
let n = $y(e, r, a);
|
|
16826
|
+
for (let e of n) await l.clearPrefix(Jy(t, e.agentId, e.sessionId)), c({
|
|
16819
16827
|
type: "evicted",
|
|
16820
16828
|
agentId: e.agentId,
|
|
16821
16829
|
sessionId: e.sessionId,
|
|
@@ -16826,13 +16834,13 @@ function nb(e = {}) {
|
|
|
16826
16834
|
ready: f,
|
|
16827
16835
|
async listSessions(e) {
|
|
16828
16836
|
let n = [];
|
|
16829
|
-
return await l.scan(
|
|
16837
|
+
return await l.scan(Yy(t, e), (e, t) => {
|
|
16830
16838
|
e.endsWith("::__meta__") && n.push(t);
|
|
16831
16839
|
}), n.sort((e, t) => t.lastAccessed - e.lastAccessed);
|
|
16832
16840
|
},
|
|
16833
16841
|
async load(e, n) {
|
|
16834
|
-
let r =
|
|
16835
|
-
return await
|
|
16842
|
+
let r = qy(t, e, n, Hy);
|
|
16843
|
+
return await rb(h, r, async () => {
|
|
16836
16844
|
let i = await l.get(r);
|
|
16837
16845
|
if (!i) return;
|
|
16838
16846
|
let a = {
|
|
@@ -16841,8 +16849,8 @@ function nb(e = {}) {
|
|
|
16841
16849
|
todos: [],
|
|
16842
16850
|
memory: ""
|
|
16843
16851
|
};
|
|
16844
|
-
for (let r of
|
|
16845
|
-
let i = await l.get(
|
|
16852
|
+
for (let r of Wy) {
|
|
16853
|
+
let i = await l.get(qy(t, e, n, r));
|
|
16846
16854
|
i != null && (a[r] = i);
|
|
16847
16855
|
}
|
|
16848
16856
|
return i.lastAccessed = Date.now(), await l.set(r, i), a;
|
|
@@ -16850,7 +16858,7 @@ function nb(e = {}) {
|
|
|
16850
16858
|
},
|
|
16851
16859
|
async save(e, t, n) {
|
|
16852
16860
|
let r = [];
|
|
16853
|
-
for (let i of
|
|
16861
|
+
for (let i of Wy) n[i] !== void 0 && r.push(_(e, t, i, n[i]));
|
|
16854
16862
|
await Promise.all(r);
|
|
16855
16863
|
},
|
|
16856
16864
|
async flush() {
|
|
@@ -16864,10 +16872,10 @@ function nb(e = {}) {
|
|
|
16864
16872
|
})), c({ type: "flush" }), await b();
|
|
16865
16873
|
},
|
|
16866
16874
|
async deleteSession(e, n) {
|
|
16867
|
-
await l.clearPrefix(
|
|
16875
|
+
await l.clearPrefix(Jy(t, e, n));
|
|
16868
16876
|
},
|
|
16869
16877
|
async createSession(e, n, r) {
|
|
16870
|
-
let i = r ??
|
|
16878
|
+
let i = r ?? Py(), a = Date.now(), o = {
|
|
16871
16879
|
agentId: e,
|
|
16872
16880
|
sessionId: i,
|
|
16873
16881
|
createdAt: a,
|
|
@@ -16875,7 +16883,7 @@ function nb(e = {}) {
|
|
|
16875
16883
|
bytes: 0,
|
|
16876
16884
|
title: n
|
|
16877
16885
|
};
|
|
16878
|
-
return await l.set(
|
|
16886
|
+
return await l.set(qy(t, e, i, Hy), o), i;
|
|
16879
16887
|
},
|
|
16880
16888
|
onEvent(e) {
|
|
16881
16889
|
s.add(e);
|
|
@@ -16890,15 +16898,15 @@ function nb(e = {}) {
|
|
|
16890
16898
|
}
|
|
16891
16899
|
//#endregion
|
|
16892
16900
|
//#region src/core/sdk/optionsResolver.ts
|
|
16893
|
-
function
|
|
16894
|
-
return e === void 0 || e === !1 ? null : typeof e == "string" ?
|
|
16901
|
+
function ab(e) {
|
|
16902
|
+
return e === void 0 || e === !1 ? null : typeof e == "string" ? ib({ backend: e }) : e.enabled === !1 ? null : ib(e);
|
|
16895
16903
|
}
|
|
16896
|
-
function
|
|
16904
|
+
function ob(e) {
|
|
16897
16905
|
return e.dialog ?? {};
|
|
16898
16906
|
}
|
|
16899
16907
|
//#endregion
|
|
16900
16908
|
//#region src/core/capabilities.ts
|
|
16901
|
-
var
|
|
16909
|
+
var sb = [
|
|
16902
16910
|
{
|
|
16903
16911
|
name: "dataOps",
|
|
16904
16912
|
defaultOn: !0
|
|
@@ -16969,13 +16977,13 @@ var ab = [
|
|
|
16969
16977
|
defaultOn: !1
|
|
16970
16978
|
}
|
|
16971
16979
|
];
|
|
16972
|
-
function
|
|
16980
|
+
function cb(e) {
|
|
16973
16981
|
let t = {};
|
|
16974
|
-
for (let n of
|
|
16982
|
+
for (let n of sb) {
|
|
16975
16983
|
let r = e?.[n.name];
|
|
16976
16984
|
t[n.name] = n.defaultOn ? r !== !1 : r === !0;
|
|
16977
16985
|
}
|
|
16978
|
-
for (let e of
|
|
16986
|
+
for (let e of sb) if (e.requires && t[e.name]) {
|
|
16979
16987
|
for (let n of e.requires) if (!t[n]) {
|
|
16980
16988
|
t[e.name] = !1;
|
|
16981
16989
|
break;
|
|
@@ -16985,7 +16993,7 @@ function ob(e) {
|
|
|
16985
16993
|
}
|
|
16986
16994
|
//#endregion
|
|
16987
16995
|
//#region src/core/sdk/events.ts
|
|
16988
|
-
function
|
|
16996
|
+
function lb(e) {
|
|
16989
16997
|
let t = /* @__PURE__ */ new Set(), n = (n) => {
|
|
16990
16998
|
if (n.type !== "approval_request") {
|
|
16991
16999
|
if (e) try {
|
|
@@ -17011,7 +17019,7 @@ function sb(e) {
|
|
|
17011
17019
|
}
|
|
17012
17020
|
//#endregion
|
|
17013
17021
|
//#region src/core/sdk/contextPreset.ts
|
|
17014
|
-
var
|
|
17022
|
+
var ub = {
|
|
17015
17023
|
auto: {
|
|
17016
17024
|
summaryThresholdRatio: .5,
|
|
17017
17025
|
windowRatio: .4,
|
|
@@ -17039,7 +17047,7 @@ var cb = {
|
|
|
17039
17047
|
enableRecall: !0,
|
|
17040
17048
|
enableLLMSummary: !0
|
|
17041
17049
|
}
|
|
17042
|
-
},
|
|
17050
|
+
}, db = {
|
|
17043
17051
|
auto: ["describe_data", "read"],
|
|
17044
17052
|
conservative: ["describe_data"],
|
|
17045
17053
|
aggressive: ["describe_data", "read"],
|
|
@@ -17050,8 +17058,8 @@ var cb = {
|
|
|
17050
17058
|
"search_data"
|
|
17051
17059
|
]
|
|
17052
17060
|
};
|
|
17053
|
-
function
|
|
17054
|
-
let n =
|
|
17061
|
+
function fb(e, t) {
|
|
17062
|
+
let n = ub[e.contextPreset ?? "auto"] ?? {}, r = e.contextOptions === !1 ? {} : e.contextOptions ?? {};
|
|
17055
17063
|
return {
|
|
17056
17064
|
...n,
|
|
17057
17065
|
...r,
|
|
@@ -17061,7 +17069,7 @@ function ub(e, t) {
|
|
|
17061
17069
|
}
|
|
17062
17070
|
//#endregion
|
|
17063
17071
|
//#region src/core/sdk/middlewareStack.ts
|
|
17064
|
-
var
|
|
17072
|
+
var pb = {
|
|
17065
17073
|
dataHint: 10,
|
|
17066
17074
|
usageHints: 20,
|
|
17067
17075
|
todos: 30,
|
|
@@ -17078,29 +17086,29 @@ var db = {
|
|
|
17078
17086
|
subagents: 140,
|
|
17079
17087
|
augmentSystem: 150
|
|
17080
17088
|
};
|
|
17081
|
-
function
|
|
17089
|
+
function mb(e) {
|
|
17082
17090
|
return e.map((e, t) => ({
|
|
17083
17091
|
m: e,
|
|
17084
17092
|
i: t,
|
|
17085
|
-
p:
|
|
17093
|
+
p: pb[e.name] ?? Infinity
|
|
17086
17094
|
})).sort((e, t) => e.p - t.p || e.i - t.i).map((e) => e.m);
|
|
17087
17095
|
}
|
|
17088
17096
|
//#endregion
|
|
17089
17097
|
//#region src/core/tools/jsonUtils.ts
|
|
17090
|
-
var
|
|
17098
|
+
var hb = /* @__PURE__ */ new Set([
|
|
17091
17099
|
"__proto__",
|
|
17092
17100
|
"constructor",
|
|
17093
17101
|
"prototype"
|
|
17094
17102
|
]);
|
|
17095
|
-
function
|
|
17096
|
-
return e.split(".").some((e) =>
|
|
17103
|
+
function gb(e) {
|
|
17104
|
+
return e.split(".").some((e) => hb.has(e));
|
|
17097
17105
|
}
|
|
17098
|
-
function
|
|
17099
|
-
if (!(!t || typeof t != "object" || Array.isArray(t))) for (let n of Object.keys(t))
|
|
17106
|
+
function _b(e, t) {
|
|
17107
|
+
if (!(!t || typeof t != "object" || Array.isArray(t))) for (let n of Object.keys(t)) hb.has(n) || (e[n] = t[n]);
|
|
17100
17108
|
}
|
|
17101
|
-
function
|
|
17109
|
+
function vb(e, t) {
|
|
17102
17110
|
if (!t) return e;
|
|
17103
|
-
if (
|
|
17111
|
+
if (gb(t)) return;
|
|
17104
17112
|
let n = t.split("."), r = e;
|
|
17105
17113
|
for (let e of n) {
|
|
17106
17114
|
if (r == null) return;
|
|
@@ -17108,8 +17116,8 @@ function gb(e, t) {
|
|
|
17108
17116
|
}
|
|
17109
17117
|
return r;
|
|
17110
17118
|
}
|
|
17111
|
-
function
|
|
17112
|
-
if (!t ||
|
|
17119
|
+
function yb(e, t, n) {
|
|
17120
|
+
if (!t || gb(t)) return;
|
|
17113
17121
|
let r = t.split("."), i = e;
|
|
17114
17122
|
for (let e = 0; e < r.length - 1; e++) {
|
|
17115
17123
|
let t = r[e];
|
|
@@ -17117,8 +17125,8 @@ function _b(e, t, n) {
|
|
|
17117
17125
|
}
|
|
17118
17126
|
i[r[r.length - 1]] = n;
|
|
17119
17127
|
}
|
|
17120
|
-
function
|
|
17121
|
-
if (!t ||
|
|
17128
|
+
function bb(e, t) {
|
|
17129
|
+
if (!t || gb(t)) return !1;
|
|
17122
17130
|
let n = t.split("."), r = e;
|
|
17123
17131
|
for (let e = 0; e < n.length - 1; e++) {
|
|
17124
17132
|
if (r == null) return !1;
|
|
@@ -17127,10 +17135,10 @@ function vb(e, t) {
|
|
|
17127
17135
|
let i = n[n.length - 1];
|
|
17128
17136
|
return r == null || !(i in r) ? !1 : (Array.isArray(r) && /^\d+$/.test(i) ? r.splice(Number(i), 1) : delete r[i], !0);
|
|
17129
17137
|
}
|
|
17130
|
-
function
|
|
17138
|
+
function xb(e) {
|
|
17131
17139
|
return e === void 0 ? void 0 : JSON.parse(JSON.stringify(e));
|
|
17132
17140
|
}
|
|
17133
|
-
function
|
|
17141
|
+
function Sb(e) {
|
|
17134
17142
|
if (typeof e != "string") return { parsed: e };
|
|
17135
17143
|
let t = e.trim();
|
|
17136
17144
|
if (!t) return { parsed: e };
|
|
@@ -17141,23 +17149,23 @@ function bb(e) {
|
|
|
17141
17149
|
return n ? { parseError: t } : { parsed: e };
|
|
17142
17150
|
}
|
|
17143
17151
|
}
|
|
17144
|
-
function
|
|
17152
|
+
function Cb(e, t) {
|
|
17145
17153
|
if (typeof e != "object" || !e) return e;
|
|
17146
17154
|
let n = new Set(t);
|
|
17147
|
-
if (Array.isArray(e)) return e.map((e) =>
|
|
17155
|
+
if (Array.isArray(e)) return e.map((e) => Cb(e, t));
|
|
17148
17156
|
let r = {};
|
|
17149
17157
|
for (let t of Object.keys(e)) n.has(t) && (r[t] = e[t]);
|
|
17150
17158
|
return r;
|
|
17151
17159
|
}
|
|
17152
|
-
function
|
|
17160
|
+
function wb(e, t) {
|
|
17153
17161
|
if (typeof e != "object" || !e) return e;
|
|
17154
17162
|
if (t <= 0) return Array.isArray(e) ? `[...${e.length}]` : "{...}";
|
|
17155
|
-
if (Array.isArray(e)) return e.map((e) =>
|
|
17163
|
+
if (Array.isArray(e)) return e.map((e) => wb(e, t - 1));
|
|
17156
17164
|
let n = {};
|
|
17157
|
-
for (let r of Object.keys(e)) n[r] =
|
|
17165
|
+
for (let r of Object.keys(e)) n[r] = wb(e[r], t - 1);
|
|
17158
17166
|
return n;
|
|
17159
17167
|
}
|
|
17160
|
-
function
|
|
17168
|
+
function Tb(e, t = Infinity) {
|
|
17161
17169
|
let n = /* @__PURE__ */ new WeakSet(), r;
|
|
17162
17170
|
try {
|
|
17163
17171
|
r = JSON.stringify(e, (e, t) => {
|
|
@@ -17176,7 +17184,7 @@ function Cb(e, t = Infinity) {
|
|
|
17176
17184
|
}
|
|
17177
17185
|
return r.length > t && (r = r.slice(0, t) + `\n…[已截断,原长度 ${r.length}]`), r;
|
|
17178
17186
|
}
|
|
17179
|
-
function
|
|
17187
|
+
function Eb(e, t = 0) {
|
|
17180
17188
|
let n = 3735928559 ^ t, r = 1103547991 ^ t;
|
|
17181
17189
|
for (let t = 0; t < e.length; t++) {
|
|
17182
17190
|
let i = e.charCodeAt(t);
|
|
@@ -17184,32 +17192,32 @@ function wb(e, t = 0) {
|
|
|
17184
17192
|
}
|
|
17185
17193
|
return n = Math.imul(n ^ n >>> 16, 2246822507) ^ Math.imul(r ^ r >>> 13, 3266489909), r = Math.imul(r ^ r >>> 16, 2246822507) ^ Math.imul(n ^ n >>> 13, 3266489909), 4294967296 * (2097151 & r) + (n >>> 0);
|
|
17186
17194
|
}
|
|
17187
|
-
function
|
|
17188
|
-
return
|
|
17195
|
+
function Db(e) {
|
|
17196
|
+
return Eb(Tb(e)).toString(36);
|
|
17189
17197
|
}
|
|
17190
|
-
function
|
|
17191
|
-
if (t === "set") return n ? (
|
|
17192
|
-
if (t === "remove") return n ? (
|
|
17198
|
+
function Ob(e, t, n, r) {
|
|
17199
|
+
if (t === "set") return n ? (yb(e, n, r), null) : "set 操作需要 jsonPath(整体替换请用 set_data)";
|
|
17200
|
+
if (t === "remove") return n ? (bb(e, n), null) : "remove 操作需要 jsonPath";
|
|
17193
17201
|
if (t === "merge") {
|
|
17194
|
-
let t = n ?
|
|
17195
|
-
return typeof t != "object" || !t || Array.isArray(t) ? `merge 目标${n ? `(${n})` : "(根)"}不是对象` : (
|
|
17202
|
+
let t = n ? vb(e, n) : e;
|
|
17203
|
+
return typeof t != "object" || !t || Array.isArray(t) ? `merge 目标${n ? `(${n})` : "(根)"}不是对象` : (_b(t, r), null);
|
|
17196
17204
|
}
|
|
17197
|
-
let i = n ?
|
|
17205
|
+
let i = n ? vb(e, n) : e;
|
|
17198
17206
|
return Array.isArray(i) ? (Array.isArray(r) ? i.push(...r) : i.push(r), null) : `append 目标${n ? `(${n})` : "(根)"}不是数组`;
|
|
17199
17207
|
}
|
|
17200
|
-
function
|
|
17201
|
-
if (t === "set")
|
|
17202
|
-
else if (t === "remove")
|
|
17203
|
-
else if (t === "merge")
|
|
17208
|
+
function kb(e, t, n, r) {
|
|
17209
|
+
if (t === "set") yb(e, n, r);
|
|
17210
|
+
else if (t === "remove") bb(e, n);
|
|
17211
|
+
else if (t === "merge") _b(n ? vb(e, n) : e, r);
|
|
17204
17212
|
else {
|
|
17205
|
-
let t = n ?
|
|
17213
|
+
let t = n ? vb(e, n) : e;
|
|
17206
17214
|
Array.isArray(r) ? t.push(...r) : t.push(r);
|
|
17207
17215
|
}
|
|
17208
17216
|
}
|
|
17209
|
-
function
|
|
17210
|
-
typeof e == "object" && e &&
|
|
17217
|
+
function Ab(e, t) {
|
|
17218
|
+
typeof e == "object" && e && jb(e, t);
|
|
17211
17219
|
}
|
|
17212
|
-
function
|
|
17220
|
+
function jb(e, t) {
|
|
17213
17221
|
if (Array.isArray(e)) {
|
|
17214
17222
|
e.length = 0, Array.isArray(t) && e.push(...t);
|
|
17215
17223
|
return;
|
|
@@ -17218,7 +17226,7 @@ function kb(e, t) {
|
|
|
17218
17226
|
for (let t of Object.keys(e)) t in n || delete e[t];
|
|
17219
17227
|
for (let t of Object.keys(n)) e[t] = n[t];
|
|
17220
17228
|
}
|
|
17221
|
-
function
|
|
17229
|
+
function Mb(e, t, n = "") {
|
|
17222
17230
|
let r = [];
|
|
17223
17231
|
if (!(typeof e == "object" && e) || !(typeof t == "object" && t) || Array.isArray(e) !== Array.isArray(t)) return e !== t && r.push({
|
|
17224
17232
|
path: n || "(root)",
|
|
@@ -17237,14 +17245,14 @@ function Ab(e, t, n = "") {
|
|
|
17237
17245
|
path: i,
|
|
17238
17246
|
from: e[a],
|
|
17239
17247
|
to: void 0
|
|
17240
|
-
}) : r.push(...
|
|
17248
|
+
}) : r.push(...Mb(e[a], t[a], i));
|
|
17241
17249
|
}
|
|
17242
17250
|
return r;
|
|
17243
17251
|
}
|
|
17244
17252
|
let i = e, a = t, o = /* @__PURE__ */ new Set([...Object.keys(i), ...Object.keys(a)]);
|
|
17245
17253
|
for (let e of o) {
|
|
17246
17254
|
let t = n ? `${n}.${e}` : e;
|
|
17247
|
-
e in i ? e in a ? r.push(...
|
|
17255
|
+
e in i ? e in a ? r.push(...Mb(i[e], a[e], t)) : r.push({
|
|
17248
17256
|
path: t,
|
|
17249
17257
|
from: i[e],
|
|
17250
17258
|
to: void 0
|
|
@@ -17256,44 +17264,44 @@ function Ab(e, t, n = "") {
|
|
|
17256
17264
|
}
|
|
17257
17265
|
return r;
|
|
17258
17266
|
}
|
|
17259
|
-
var
|
|
17267
|
+
var Nb = {
|
|
17260
17268
|
largeResults: 4194304,
|
|
17261
17269
|
drafts: 2097152,
|
|
17262
17270
|
userFiles: 2097152
|
|
17263
|
-
},
|
|
17271
|
+
}, Pb = [
|
|
17264
17272
|
"largeResults",
|
|
17265
17273
|
"drafts",
|
|
17266
17274
|
"userFiles"
|
|
17267
|
-
],
|
|
17268
|
-
function
|
|
17275
|
+
], Fb = .9;
|
|
17276
|
+
function Ib(e, t = {}) {
|
|
17269
17277
|
let n = Object.create(null);
|
|
17270
|
-
if (e) for (let [t, r] of Object.entries(e)) n[
|
|
17278
|
+
if (e) for (let [t, r] of Object.entries(e)) n[Bb(t)] = {
|
|
17271
17279
|
content: r,
|
|
17272
|
-
updatedAt:
|
|
17280
|
+
updatedAt: Hb()
|
|
17273
17281
|
};
|
|
17274
17282
|
let { persist: r } = t, i = t.maxBytes ?? 8388608, a = {
|
|
17275
|
-
...
|
|
17283
|
+
...Nb,
|
|
17276
17284
|
...t.poolBytes ?? {}
|
|
17277
17285
|
};
|
|
17278
17286
|
function o(e) {
|
|
17279
|
-
let t =
|
|
17287
|
+
let t = Bb(e);
|
|
17280
17288
|
return t.startsWith("large_results/") ? "largeResults" : t.startsWith("drafts/") ? "drafts" : "userFiles";
|
|
17281
17289
|
}
|
|
17282
17290
|
function s(e) {
|
|
17283
17291
|
let t = 0;
|
|
17284
|
-
for (let [r, i] of Object.entries(n)) o(r) === e && (t +=
|
|
17292
|
+
for (let [r, i] of Object.entries(n)) o(r) === e && (t += Rb(i.content));
|
|
17285
17293
|
return t;
|
|
17286
17294
|
}
|
|
17287
17295
|
function c() {
|
|
17288
|
-
for (let e of
|
|
17296
|
+
for (let e of Pb) {
|
|
17289
17297
|
let t = a[e];
|
|
17290
17298
|
if (s(e) <= t) continue;
|
|
17291
|
-
let r = t *
|
|
17299
|
+
let r = t * Fb, i = Object.entries(n).filter(([t]) => o(t) === e).sort((e, t) => e[1].updatedAt - t[1].updatedAt);
|
|
17292
17300
|
for (let [t] of i) if (delete n[t], s(e) <= r) break;
|
|
17293
17301
|
}
|
|
17294
|
-
if (
|
|
17295
|
-
let e = i *
|
|
17296
|
-
for (let [r] of t) if (delete n[r],
|
|
17302
|
+
if (zb(n) > i) {
|
|
17303
|
+
let e = i * Fb, t = Object.entries(n).sort((e, t) => e[1].updatedAt - t[1].updatedAt);
|
|
17304
|
+
for (let [r] of t) if (delete n[r], zb(n) <= e) break;
|
|
17297
17305
|
}
|
|
17298
17306
|
}
|
|
17299
17307
|
let l = !0, u = null;
|
|
@@ -17326,7 +17334,7 @@ function Pb(e, t = {}) {
|
|
|
17326
17334
|
}
|
|
17327
17335
|
};
|
|
17328
17336
|
return r && (p.hydrate = (e) => {
|
|
17329
|
-
for (let [t, r] of Object.entries(e)) n[
|
|
17337
|
+
for (let [t, r] of Object.entries(e)) n[Bb(t)] = r;
|
|
17330
17338
|
c(), l = !0;
|
|
17331
17339
|
}, p.flush = () => {
|
|
17332
17340
|
u &&= (clearTimeout(u), null), d();
|
|
@@ -17335,19 +17343,19 @@ function Pb(e, t = {}) {
|
|
|
17335
17343
|
f(), l = !0;
|
|
17336
17344
|
}), p;
|
|
17337
17345
|
}
|
|
17338
|
-
var
|
|
17339
|
-
function
|
|
17340
|
-
return
|
|
17346
|
+
var Lb = null;
|
|
17347
|
+
function Rb(e) {
|
|
17348
|
+
return Lb ||= new TextEncoder(), Lb.encode(e).length;
|
|
17341
17349
|
}
|
|
17342
|
-
function
|
|
17350
|
+
function zb(e) {
|
|
17343
17351
|
let t = 0;
|
|
17344
|
-
for (let n of Object.values(e)) t +=
|
|
17352
|
+
for (let n of Object.values(e)) t += Rb(n.content);
|
|
17345
17353
|
return t;
|
|
17346
17354
|
}
|
|
17347
|
-
function
|
|
17355
|
+
function Bb(e) {
|
|
17348
17356
|
return e.replace(/^\/+/, "").replace(/\/+/g, "/");
|
|
17349
17357
|
}
|
|
17350
|
-
function
|
|
17358
|
+
function Vb(e) {
|
|
17351
17359
|
let t = "";
|
|
17352
17360
|
for (let n = 0; n < e.length; n++) {
|
|
17353
17361
|
let r = e[n];
|
|
@@ -17355,10 +17363,10 @@ function zb(e) {
|
|
|
17355
17363
|
}
|
|
17356
17364
|
return RegExp("^" + t + "$");
|
|
17357
17365
|
}
|
|
17358
|
-
function
|
|
17366
|
+
function Hb() {
|
|
17359
17367
|
return Date.now();
|
|
17360
17368
|
}
|
|
17361
|
-
var
|
|
17369
|
+
var Ub = [
|
|
17362
17370
|
"vfs_read",
|
|
17363
17371
|
"vfs_write",
|
|
17364
17372
|
"vfs_edit",
|
|
@@ -17368,10 +17376,10 @@ var Vb = [
|
|
|
17368
17376
|
"vfs_json_read",
|
|
17369
17377
|
"vfs_json_patch"
|
|
17370
17378
|
];
|
|
17371
|
-
function
|
|
17379
|
+
function Wb(e) {
|
|
17372
17380
|
return [
|
|
17373
17381
|
r(async ({ path: t, offset: n, limit: r }) => {
|
|
17374
|
-
let i = e.files[
|
|
17382
|
+
let i = e.files[Bb(t)];
|
|
17375
17383
|
if (!i) return $({
|
|
17376
17384
|
code: "NOT_FOUND",
|
|
17377
17385
|
path: t,
|
|
@@ -17400,9 +17408,9 @@ function Hb(e) {
|
|
|
17400
17408
|
hint: "jsonString=true 要求 content 是合法 JSON;检查引号/逗号/括号配对;或省略 jsonString 写纯文本"
|
|
17401
17409
|
});
|
|
17402
17410
|
}
|
|
17403
|
-
return e.files[
|
|
17411
|
+
return e.files[Bb(t)] = {
|
|
17404
17412
|
content: n,
|
|
17405
|
-
updatedAt:
|
|
17413
|
+
updatedAt: Hb()
|
|
17406
17414
|
}, `已写入 ${t}(${n.length} 字符)${r ? "(JSON 校验通过)" : ""}`;
|
|
17407
17415
|
}, {
|
|
17408
17416
|
name: "vfs_write",
|
|
@@ -17414,7 +17422,7 @@ function Hb(e) {
|
|
|
17414
17422
|
})
|
|
17415
17423
|
}),
|
|
17416
17424
|
r(async ({ path: t, oldString: n, newString: r }) => {
|
|
17417
|
-
let i =
|
|
17425
|
+
let i = Bb(t), a = e.files[i];
|
|
17418
17426
|
if (!a) return $({
|
|
17419
17427
|
code: "NOT_FOUND",
|
|
17420
17428
|
path: t,
|
|
@@ -17444,7 +17452,7 @@ function Hb(e) {
|
|
|
17444
17452
|
}
|
|
17445
17453
|
return e.files[i] = {
|
|
17446
17454
|
content: a.content.replace(n, r),
|
|
17447
|
-
updatedAt:
|
|
17455
|
+
updatedAt: Hb()
|
|
17448
17456
|
}, `已替换 ${t} 中 1 处。`;
|
|
17449
17457
|
}, {
|
|
17450
17458
|
name: "vfs_edit",
|
|
@@ -17466,7 +17474,7 @@ function Hb(e) {
|
|
|
17466
17474
|
r(async ({ pattern: t }) => {
|
|
17467
17475
|
let n;
|
|
17468
17476
|
try {
|
|
17469
|
-
n =
|
|
17477
|
+
n = Vb(t);
|
|
17470
17478
|
} catch (e) {
|
|
17471
17479
|
return $({
|
|
17472
17480
|
code: "GLOB_INVALID",
|
|
@@ -17495,7 +17503,7 @@ function Hb(e) {
|
|
|
17495
17503
|
details: { pattern: t }
|
|
17496
17504
|
});
|
|
17497
17505
|
}
|
|
17498
|
-
let i = n ? [
|
|
17506
|
+
let i = n ? [Bb(n)] : Object.keys(e.files), a = [];
|
|
17499
17507
|
for (let t of i) {
|
|
17500
17508
|
let n = e.files[t];
|
|
17501
17509
|
n && n.content.split("\n").forEach((e, n) => {
|
|
@@ -17512,7 +17520,7 @@ function Hb(e) {
|
|
|
17512
17520
|
})
|
|
17513
17521
|
}),
|
|
17514
17522
|
r(async ({ path: t, jsonPath: n }) => {
|
|
17515
|
-
let r =
|
|
17523
|
+
let r = Bb(t), i = e.files[r];
|
|
17516
17524
|
if (!i) return $({
|
|
17517
17525
|
code: "NOT_FOUND",
|
|
17518
17526
|
path: t,
|
|
@@ -17531,7 +17539,7 @@ function Hb(e) {
|
|
|
17531
17539
|
});
|
|
17532
17540
|
}
|
|
17533
17541
|
if (n) {
|
|
17534
|
-
let e =
|
|
17542
|
+
let e = vb(a, n);
|
|
17535
17543
|
return e === void 0 ? $({
|
|
17536
17544
|
code: "VFS_PATH_NOT_FOUND",
|
|
17537
17545
|
path: t,
|
|
@@ -17549,7 +17557,7 @@ function Hb(e) {
|
|
|
17549
17557
|
})
|
|
17550
17558
|
}),
|
|
17551
17559
|
r(async ({ path: t, patches: n }) => {
|
|
17552
|
-
let r =
|
|
17560
|
+
let r = Bb(t), i = e.files[r];
|
|
17553
17561
|
if (!i) return $({
|
|
17554
17562
|
code: "NOT_FOUND",
|
|
17555
17563
|
path: t,
|
|
@@ -17567,9 +17575,9 @@ function Hb(e) {
|
|
|
17567
17575
|
hint: "vfs_json_patch 要求文件内容是合法 JSON"
|
|
17568
17576
|
});
|
|
17569
17577
|
}
|
|
17570
|
-
let o =
|
|
17578
|
+
let o = xb(a), s = [];
|
|
17571
17579
|
for (let e of n) {
|
|
17572
|
-
let n =
|
|
17580
|
+
let n = Ob(o, e.op, e.jsonPath, e.value);
|
|
17573
17581
|
if (n) return $({
|
|
17574
17582
|
code: "PATCH_FAILED",
|
|
17575
17583
|
path: t,
|
|
@@ -17582,7 +17590,7 @@ function Hb(e) {
|
|
|
17582
17590
|
let c = JSON.stringify(o);
|
|
17583
17591
|
return e.files[r] = {
|
|
17584
17592
|
content: c,
|
|
17585
|
-
updatedAt:
|
|
17593
|
+
updatedAt: Hb()
|
|
17586
17594
|
}, `已对 ${t} 应用 ${n.length} 个 patch(影响 ${s.length} 处:${s.join(", ")}),文件现 ${c.length} 字符`;
|
|
17587
17595
|
}, {
|
|
17588
17596
|
name: "vfs_json_patch",
|
|
@@ -17603,17 +17611,17 @@ function Hb(e) {
|
|
|
17603
17611
|
})
|
|
17604
17612
|
];
|
|
17605
17613
|
}
|
|
17606
|
-
function
|
|
17614
|
+
function Gb(e) {
|
|
17607
17615
|
return {
|
|
17608
17616
|
name: "vfs",
|
|
17609
|
-
tools:
|
|
17617
|
+
tools: Wb(e),
|
|
17610
17618
|
beforeAgent: () => ({ files: e.files })
|
|
17611
17619
|
};
|
|
17612
17620
|
}
|
|
17613
17621
|
//#endregion
|
|
17614
17622
|
//#region src/core/tools/dataSlotQuery.ts
|
|
17615
|
-
var
|
|
17616
|
-
function
|
|
17623
|
+
var Kb = /[\w$-]/;
|
|
17624
|
+
function qb(e) {
|
|
17617
17625
|
let t = [], n = e.trim(), r = +(n[0] === "$");
|
|
17618
17626
|
for (; r < n.length;) {
|
|
17619
17627
|
let e = n[r];
|
|
@@ -17624,7 +17632,7 @@ function Gb(e) {
|
|
|
17624
17632
|
continue;
|
|
17625
17633
|
}
|
|
17626
17634
|
let e = "";
|
|
17627
|
-
for (; r < n.length &&
|
|
17635
|
+
for (; r < n.length && Kb.test(n[r]);) e += n[r++];
|
|
17628
17636
|
if (!e) throw Error("JSONPath: .. 后缺属性名");
|
|
17629
17637
|
t.push({
|
|
17630
17638
|
type: "descendKey",
|
|
@@ -17637,7 +17645,7 @@ function Gb(e) {
|
|
|
17637
17645
|
continue;
|
|
17638
17646
|
}
|
|
17639
17647
|
let e = "";
|
|
17640
|
-
for (; r < n.length &&
|
|
17648
|
+
for (; r < n.length && Kb.test(n[r]);) e += n[r++];
|
|
17641
17649
|
if (!e) throw Error("JSONPath: . 后缺属性名");
|
|
17642
17650
|
t.push({
|
|
17643
17651
|
type: "key",
|
|
@@ -17693,7 +17701,7 @@ function Gb(e) {
|
|
|
17693
17701
|
}
|
|
17694
17702
|
return t;
|
|
17695
17703
|
}
|
|
17696
|
-
function
|
|
17704
|
+
function Jb(e) {
|
|
17697
17705
|
let t = [], n = 0, r = e.trim();
|
|
17698
17706
|
for (; n < r.length;) {
|
|
17699
17707
|
let e = r[n];
|
|
@@ -17738,7 +17746,7 @@ function Kb(e) {
|
|
|
17738
17746
|
}
|
|
17739
17747
|
return t;
|
|
17740
17748
|
}
|
|
17741
|
-
var
|
|
17749
|
+
var Yb = class {
|
|
17742
17750
|
toks;
|
|
17743
17751
|
item;
|
|
17744
17752
|
pos = 0;
|
|
@@ -17774,12 +17782,12 @@ var qb = class {
|
|
|
17774
17782
|
return this.next(), e;
|
|
17775
17783
|
}
|
|
17776
17784
|
let e = this.operand(), t = this.peek();
|
|
17777
|
-
return t === "==" || t === "!=" || t === "<" || t === "<=" || t === ">" || t === ">=" ? (this.next(),
|
|
17785
|
+
return t === "==" || t === "!=" || t === "<" || t === "<=" || t === ">" || t === ">=" ? (this.next(), Qb(t, e, this.operand())) : Xb(e);
|
|
17778
17786
|
}
|
|
17779
17787
|
operand() {
|
|
17780
17788
|
let e = this.next();
|
|
17781
17789
|
if (e === void 0) throw Error("过滤表达式:缺操作数");
|
|
17782
|
-
if (e.startsWith("@")) return
|
|
17790
|
+
if (e.startsWith("@")) return Zb(e, this.item);
|
|
17783
17791
|
if (e[0] === "'" || e[0] === "\"") return e.slice(1, -1);
|
|
17784
17792
|
if (e === "true") return !0;
|
|
17785
17793
|
if (e === "false") return !1;
|
|
@@ -17789,10 +17797,10 @@ var qb = class {
|
|
|
17789
17797
|
throw Error(`过滤表达式:未知操作数 '${e}'`);
|
|
17790
17798
|
}
|
|
17791
17799
|
};
|
|
17792
|
-
function
|
|
17800
|
+
function Xb(e) {
|
|
17793
17801
|
return !!e && e !== 0 && e !== "" && e !== null;
|
|
17794
17802
|
}
|
|
17795
|
-
function
|
|
17803
|
+
function Zb(e, t) {
|
|
17796
17804
|
let n = e.split(".").filter((e) => e && e !== "@"), r = t;
|
|
17797
17805
|
for (let e of n) {
|
|
17798
17806
|
if (typeof r != "object" || !r) return;
|
|
@@ -17800,7 +17808,7 @@ function Yb(e, t) {
|
|
|
17800
17808
|
}
|
|
17801
17809
|
return r;
|
|
17802
17810
|
}
|
|
17803
|
-
function
|
|
17811
|
+
function Qb(e, t, n) {
|
|
17804
17812
|
switch (e) {
|
|
17805
17813
|
case "==": return t === n;
|
|
17806
17814
|
case "!=": return t !== n;
|
|
@@ -17811,47 +17819,47 @@ function Xb(e, t, n) {
|
|
|
17811
17819
|
default: return !1;
|
|
17812
17820
|
}
|
|
17813
17821
|
}
|
|
17814
|
-
function
|
|
17815
|
-
return new
|
|
17822
|
+
function $b(e, t) {
|
|
17823
|
+
return new Yb(Jb(e), t).parse();
|
|
17816
17824
|
}
|
|
17817
|
-
function
|
|
17825
|
+
function ex(e, t) {
|
|
17818
17826
|
return e ? `${e}.${t}` : String(t);
|
|
17819
17827
|
}
|
|
17820
|
-
function
|
|
17828
|
+
function tx(e, t) {
|
|
17821
17829
|
let n = [{
|
|
17822
17830
|
path: "",
|
|
17823
17831
|
value: e
|
|
17824
17832
|
}];
|
|
17825
|
-
for (let e of
|
|
17833
|
+
for (let e of qb(t)) {
|
|
17826
17834
|
let t = [];
|
|
17827
17835
|
if (e.type === "key") for (let r of n) r.value != null && typeof r.value == "object" && e.key in r.value && t.push({
|
|
17828
|
-
path:
|
|
17836
|
+
path: ex(r.path, e.key),
|
|
17829
17837
|
value: r.value[e.key]
|
|
17830
17838
|
});
|
|
17831
17839
|
else if (e.type === "index") {
|
|
17832
17840
|
for (let r of n) if (Array.isArray(r.value)) {
|
|
17833
17841
|
let n = r.value[e.index];
|
|
17834
17842
|
e.index >= 0 && e.index < r.value.length && t.push({
|
|
17835
|
-
path:
|
|
17843
|
+
path: ex(r.path, e.index),
|
|
17836
17844
|
value: n,
|
|
17837
17845
|
index: e.index
|
|
17838
17846
|
});
|
|
17839
17847
|
}
|
|
17840
17848
|
} else if (e.type === "wildcard") {
|
|
17841
17849
|
for (let e of n) if (Array.isArray(e.value)) e.value.forEach((n, r) => t.push({
|
|
17842
|
-
path:
|
|
17850
|
+
path: ex(e.path, r),
|
|
17843
17851
|
value: n,
|
|
17844
17852
|
index: r
|
|
17845
17853
|
}));
|
|
17846
17854
|
else if (e.value != null && typeof e.value == "object") for (let n of Object.keys(e.value)) t.push({
|
|
17847
|
-
path:
|
|
17855
|
+
path: ex(e.path, n),
|
|
17848
17856
|
value: e.value[n]
|
|
17849
17857
|
});
|
|
17850
17858
|
} else if (e.type === "descendKey") {
|
|
17851
17859
|
let r = e.key, i = (e) => {
|
|
17852
17860
|
if (e.value != null && typeof e.value == "object") for (let n of Object.keys(e.value)) {
|
|
17853
17861
|
let a = {
|
|
17854
|
-
path:
|
|
17862
|
+
path: ex(e.path, n),
|
|
17855
17863
|
value: e.value[n]
|
|
17856
17864
|
};
|
|
17857
17865
|
n === r && t.push(a), i(a);
|
|
@@ -17862,7 +17870,7 @@ function $b(e, t) {
|
|
|
17862
17870
|
let e = (n) => {
|
|
17863
17871
|
if (n.value != null && typeof n.value == "object") for (let r of Object.keys(n.value)) {
|
|
17864
17872
|
let i = {
|
|
17865
|
-
path:
|
|
17873
|
+
path: ex(n.path, r),
|
|
17866
17874
|
value: n.value[r]
|
|
17867
17875
|
};
|
|
17868
17876
|
t.push(i), e(i);
|
|
@@ -17871,16 +17879,16 @@ function $b(e, t) {
|
|
|
17871
17879
|
for (let t of n) e(t);
|
|
17872
17880
|
} else if (e.type === "filter") {
|
|
17873
17881
|
for (let r of n) if (Array.isArray(r.value)) r.value.forEach((n, i) => {
|
|
17874
|
-
|
|
17875
|
-
path:
|
|
17882
|
+
$b(e.filter, n) && t.push({
|
|
17883
|
+
path: ex(r.path, i),
|
|
17876
17884
|
value: n,
|
|
17877
17885
|
index: i
|
|
17878
17886
|
});
|
|
17879
17887
|
});
|
|
17880
17888
|
else if (r.value != null && typeof r.value == "object") for (let n of Object.keys(r.value)) {
|
|
17881
17889
|
let i = r.value[n];
|
|
17882
|
-
|
|
17883
|
-
path:
|
|
17890
|
+
$b(e.filter, i) && t.push({
|
|
17891
|
+
path: ex(r.path, n),
|
|
17884
17892
|
value: i
|
|
17885
17893
|
});
|
|
17886
17894
|
}
|
|
@@ -17889,7 +17897,7 @@ function $b(e, t) {
|
|
|
17889
17897
|
}
|
|
17890
17898
|
return n;
|
|
17891
17899
|
}
|
|
17892
|
-
function
|
|
17900
|
+
function nx(e, t) {
|
|
17893
17901
|
let n = e.length, r = t.length;
|
|
17894
17902
|
if (!n) return r;
|
|
17895
17903
|
if (!r) return n;
|
|
@@ -17905,7 +17913,7 @@ function ex(e, t) {
|
|
|
17905
17913
|
}
|
|
17906
17914
|
return i[r];
|
|
17907
17915
|
}
|
|
17908
|
-
function
|
|
17916
|
+
function rx(e, t, n = {}) {
|
|
17909
17917
|
let r = n.mode || "substring", i = n.limit ?? 50, a = n.matchKey !== !1, o = [], s = null;
|
|
17910
17918
|
if (r === "regex") try {
|
|
17911
17919
|
s = new RegExp(t, "i");
|
|
@@ -17915,11 +17923,11 @@ function tx(e, t, n = {}) {
|
|
|
17915
17923
|
let c = (e, l, u) => {
|
|
17916
17924
|
if (o.length >= i || e == null) return;
|
|
17917
17925
|
if (typeof e == "object") {
|
|
17918
|
-
if (Array.isArray(e)) e.forEach((e, t) => c(e,
|
|
17919
|
-
else for (let t of Object.keys(e)) c(e[t],
|
|
17926
|
+
if (Array.isArray(e)) e.forEach((e, t) => c(e, ex(l, t), String(t)));
|
|
17927
|
+
else for (let t of Object.keys(e)) c(e[t], ex(l, t), t);
|
|
17920
17928
|
return;
|
|
17921
17929
|
}
|
|
17922
|
-
let d = String(e), f =
|
|
17930
|
+
let d = String(e), f = ix(d, t, r, n.fuzzyThreshold ?? 2, s);
|
|
17923
17931
|
if (f) {
|
|
17924
17932
|
o.push({
|
|
17925
17933
|
path: l,
|
|
@@ -17930,7 +17938,7 @@ function tx(e, t, n = {}) {
|
|
|
17930
17938
|
return;
|
|
17931
17939
|
}
|
|
17932
17940
|
if (a && u) {
|
|
17933
|
-
let e =
|
|
17941
|
+
let e = ix(u, t, r, n.fuzzyThreshold ?? 2, s);
|
|
17934
17942
|
e && o.push({
|
|
17935
17943
|
path: l,
|
|
17936
17944
|
key: u,
|
|
@@ -17941,18 +17949,18 @@ function tx(e, t, n = {}) {
|
|
|
17941
17949
|
};
|
|
17942
17950
|
return c(e, ""), o;
|
|
17943
17951
|
}
|
|
17944
|
-
function
|
|
17952
|
+
function ix(e, t, n, r, i) {
|
|
17945
17953
|
let a = e.toLowerCase(), o = t.toLowerCase();
|
|
17946
17954
|
if (n === "substring") return a.includes(o) ? 1 : null;
|
|
17947
17955
|
if (n === "regex") return i && i.test(e) ? 1 : null;
|
|
17948
17956
|
if (n === "fuzzy") {
|
|
17949
17957
|
if (a.includes(o)) return 2;
|
|
17950
|
-
let e =
|
|
17958
|
+
let e = nx(a, o);
|
|
17951
17959
|
return e <= r ? r - e + 1 : null;
|
|
17952
17960
|
}
|
|
17953
17961
|
return null;
|
|
17954
17962
|
}
|
|
17955
|
-
var
|
|
17963
|
+
var ax = [
|
|
17956
17964
|
"self.fetch = () => { throw new Error('fetch 已被沙箱禁用') }",
|
|
17957
17965
|
"self.XMLHttpRequest = function(){ throw new Error('XMLHttpRequest 已被沙箱禁用') }",
|
|
17958
17966
|
"self.importScripts = () => { throw new Error('importScripts 已被沙箱禁用') }",
|
|
@@ -17964,7 +17972,7 @@ var rx = [
|
|
|
17964
17972
|
"try { self.EventSource = undefined } catch {}",
|
|
17965
17973
|
"try { self.BroadcastChannel = undefined } catch {}",
|
|
17966
17974
|
"if (self.navigator && self.navigator.sendBeacon) self.navigator.sendBeacon = () => { throw new Error('sendBeacon 已被沙箱禁用') }"
|
|
17967
|
-
].join("\n"),
|
|
17975
|
+
].join("\n"), ox = [
|
|
17968
17976
|
{
|
|
17969
17977
|
re: /\bimport\s*\(/,
|
|
17970
17978
|
msg: "动态 import() 拉外网模块"
|
|
@@ -17990,8 +17998,8 @@ var rx = [
|
|
|
17990
17998
|
msg: "require() 拉模块"
|
|
17991
17999
|
}
|
|
17992
18000
|
];
|
|
17993
|
-
function
|
|
17994
|
-
for (let { re: e, msg: n } of
|
|
18001
|
+
function sx(e, t, n = 3e3) {
|
|
18002
|
+
for (let { re: e, msg: n } of ox) if (e.test(t)) return Promise.resolve({
|
|
17995
18003
|
ok: !1,
|
|
17996
18004
|
error: `沙箱拒绝执行:脚本含禁用模式(${n})`,
|
|
17997
18005
|
elapsedMs: 0
|
|
@@ -18008,7 +18016,7 @@ function ax(e, t, n = 3e3) {
|
|
|
18008
18016
|
elapsedMs: Date.now() - i
|
|
18009
18017
|
});
|
|
18010
18018
|
}
|
|
18011
|
-
}, s =
|
|
18019
|
+
}, s = ax + "\nself.onmessage = async (e) => {\n try {\n const fn = new Function(\"data\", e.data.script);\n try { self.eval = undefined; self.Function = undefined; } catch {}\n let result = fn(e.data.data);\n if (result && typeof result.then === \"function\") result = await result;\n self.postMessage({ ok: true, result });\n } catch (err) {\n self.postMessage({ ok: false, error: String((err && err.message) || err) });\n }\n};", c = "", l;
|
|
18012
18020
|
try {
|
|
18013
18021
|
let e = new Blob([s], { type: "application/javascript" });
|
|
18014
18022
|
c = URL.createObjectURL(e), l = new Worker(c);
|
|
@@ -18043,7 +18051,7 @@ function ax(e, t, n = 3e3) {
|
|
|
18043
18051
|
}
|
|
18044
18052
|
//#endregion
|
|
18045
18053
|
//#region src/core/tools/dataOps.ts
|
|
18046
|
-
var
|
|
18054
|
+
var cx = /* @__PURE__ */ new Set([
|
|
18047
18055
|
"describe_data",
|
|
18048
18056
|
"get_data",
|
|
18049
18057
|
"set_data",
|
|
@@ -18055,11 +18063,11 @@ var ox = /* @__PURE__ */ new Set([
|
|
|
18055
18063
|
"diff_data",
|
|
18056
18064
|
"draft_write",
|
|
18057
18065
|
"draft_commit"
|
|
18058
|
-
]),
|
|
18059
|
-
function
|
|
18060
|
-
return t === "advanced" ? e : t === "minimal" ? e.filter((e) =>
|
|
18066
|
+
]), lx = /* @__PURE__ */ new Set(["read", "write"]);
|
|
18067
|
+
function ux(e, t = "simple") {
|
|
18068
|
+
return t === "advanced" ? e : t === "minimal" ? e.filter((e) => lx.has(e.name)) : e.filter((e) => !cx.has(e.name));
|
|
18061
18069
|
}
|
|
18062
|
-
function
|
|
18070
|
+
function dx(e) {
|
|
18063
18071
|
let { bindRef: t, value: n, schema: r, allowKeys: i, snapshots: a, maxSnapshots: o, audit: s, dryRun: c, op: l = "set" } = e, u = r.safeParse(n);
|
|
18064
18072
|
if (!u.success) return {
|
|
18065
18073
|
ok: !1,
|
|
@@ -18078,28 +18086,28 @@ function lx(e) {
|
|
|
18078
18086
|
hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹(如 {value:\"x\"})或集成方通过 sdk.setData 替换 bind"
|
|
18079
18087
|
})
|
|
18080
18088
|
};
|
|
18081
|
-
let d =
|
|
18089
|
+
let d = xb(t), f = a.length ? a[a.length - 1].id + 1 : 1;
|
|
18082
18090
|
for (a.push({
|
|
18083
18091
|
id: f,
|
|
18084
18092
|
ts: Date.now(),
|
|
18085
18093
|
op: l,
|
|
18086
18094
|
value: d
|
|
18087
18095
|
}); a.length > o;) a.shift();
|
|
18088
|
-
return u.data !== null && typeof u.data == "object" && (i ?
|
|
18096
|
+
return u.data !== null && typeof u.data == "object" && (i ? _b(t, u.data) : jb(t, u.data)), s({
|
|
18089
18097
|
op: l,
|
|
18090
18098
|
value: u.data,
|
|
18091
18099
|
timestamp: Date.now()
|
|
18092
18100
|
}), e.onWrite?.(), {
|
|
18093
18101
|
ok: !0,
|
|
18094
|
-
hash:
|
|
18102
|
+
hash: Db(t),
|
|
18095
18103
|
data: u.data
|
|
18096
18104
|
};
|
|
18097
18105
|
}
|
|
18098
|
-
function
|
|
18099
|
-
let { bindRef: t, patches: n, schema: r, allowKeys: i, snapshots: a, maxSnapshots: o, markDataDirty: s, schemaErrorMode: c = "zod", snapshotLabel: l, dryRun: u } = e, d =
|
|
18106
|
+
function fx(e) {
|
|
18107
|
+
let { bindRef: t, patches: n, schema: r, allowKeys: i, snapshots: a, maxSnapshots: o, markDataDirty: s, schemaErrorMode: c = "zod", snapshotLabel: l, dryRun: u } = e, d = xb(t), f = [];
|
|
18100
18108
|
for (let e = 0; e < n.length; e++) {
|
|
18101
18109
|
let t = n[e], a = t.jsonPath || "";
|
|
18102
|
-
if (
|
|
18110
|
+
if (gb(a)) return {
|
|
18103
18111
|
ok: !1,
|
|
18104
18112
|
error: $({
|
|
18105
18113
|
code: "PATH_UNSAFE",
|
|
@@ -18107,7 +18115,7 @@ function ux(e) {
|
|
|
18107
18115
|
hint: "使用正常属性路径,如 components.0.text"
|
|
18108
18116
|
})
|
|
18109
18117
|
};
|
|
18110
|
-
if (!
|
|
18118
|
+
if (!ry(a, r, i)) return {
|
|
18111
18119
|
ok: !1,
|
|
18112
18120
|
error: $({
|
|
18113
18121
|
code: "PATH_DENIED",
|
|
@@ -18125,14 +18133,14 @@ function ux(e) {
|
|
|
18125
18133
|
hint: `op 为 ${o} 时 value 必填;删除请用 op:'remove'`
|
|
18126
18134
|
})
|
|
18127
18135
|
};
|
|
18128
|
-
let n =
|
|
18136
|
+
let n = Sb(t.value);
|
|
18129
18137
|
if (n.parseError) return {
|
|
18130
18138
|
ok: !1,
|
|
18131
18139
|
error: Ug(`patches[${e}]`, t.value, n.parseError)
|
|
18132
18140
|
};
|
|
18133
18141
|
s = n.parsed;
|
|
18134
18142
|
}
|
|
18135
|
-
let c =
|
|
18143
|
+
let c = Ob(d, o, a, s);
|
|
18136
18144
|
if (c) return {
|
|
18137
18145
|
ok: !1,
|
|
18138
18146
|
error: $({
|
|
@@ -18167,18 +18175,18 @@ function ux(e) {
|
|
|
18167
18175
|
id: m,
|
|
18168
18176
|
ts: Date.now(),
|
|
18169
18177
|
op: "edit",
|
|
18170
|
-
value:
|
|
18178
|
+
value: xb(t),
|
|
18171
18179
|
...l ? { label: l } : {}
|
|
18172
18180
|
}); a.length > o;) a.shift();
|
|
18173
|
-
for (let e of f)
|
|
18174
|
-
return s?.(), {
|
|
18181
|
+
for (let e of f) e.op === "remove" && bb(t, e.jp);
|
|
18182
|
+
return p.data !== null && typeof p.data == "object" && (i ? _b(t, p.data) : jb(t, p.data)), s?.(), {
|
|
18175
18183
|
ok: !0,
|
|
18176
18184
|
applied: f,
|
|
18177
18185
|
clone: d
|
|
18178
18186
|
};
|
|
18179
18187
|
}
|
|
18180
|
-
function
|
|
18181
|
-
let i = e.schema, a = e.bind, o = e.description ?? "主数据对象", s =
|
|
18188
|
+
function px(e, n = {}) {
|
|
18189
|
+
let i = e.schema, a = e.bind, o = e.description ?? "主数据对象", s = ny(i), c = [], l = n.maxSnapshots ?? 20, u, d = n.autoLock !== !1, f = !0;
|
|
18182
18190
|
function p() {
|
|
18183
18191
|
f = !0;
|
|
18184
18192
|
}
|
|
@@ -18189,7 +18197,7 @@ function dx(e, n = {}) {
|
|
|
18189
18197
|
description: o
|
|
18190
18198
|
}),
|
|
18191
18199
|
set: (e) => {
|
|
18192
|
-
i = e.schema, a = e.bind, o = e.description ?? "主数据对象", s =
|
|
18200
|
+
i = e.schema, a = e.bind, o = e.description ?? "主数据对象", s = ny(i), c.length = 0, u = void 0, p();
|
|
18193
18201
|
},
|
|
18194
18202
|
update: (e) => {
|
|
18195
18203
|
a = e, c.length = 0, u = void 0, p();
|
|
@@ -18203,7 +18211,7 @@ function dx(e, n = {}) {
|
|
|
18203
18211
|
n.onAudit?.(e);
|
|
18204
18212
|
};
|
|
18205
18213
|
function g(e, t) {
|
|
18206
|
-
let n =
|
|
18214
|
+
let n = xb(a), r = c.length ? c[c.length - 1].id + 1 : 1;
|
|
18207
18215
|
for (c.push({
|
|
18208
18216
|
id: r,
|
|
18209
18217
|
ts: Date.now(),
|
|
@@ -18215,12 +18223,12 @@ function dx(e, n = {}) {
|
|
|
18215
18223
|
}
|
|
18216
18224
|
async function _(e, t, r) {
|
|
18217
18225
|
if (!t || t === "") return null;
|
|
18218
|
-
let i =
|
|
18226
|
+
let i = Db(a);
|
|
18219
18227
|
if (i === t) return null;
|
|
18220
18228
|
if (!n.onConflict) return $({
|
|
18221
18229
|
code: "VERSION_CONFLICT",
|
|
18222
18230
|
message: `乐观锁冲突:expectedHash=${t} 但当前 hash=${i}。主数据在你 read 之后已被修改(外部代码/其他 agent/用户手动改)。`,
|
|
18223
|
-
hint: `重新 read 拿最新值与 hash,基于最新值修改后再写入(传新的 expectedHash)。当前值:${
|
|
18231
|
+
hint: `重新 read 拿最新值与 hash,基于最新值修改后再写入(传新的 expectedHash)。当前值:${Tb(a, 400)}`
|
|
18224
18232
|
});
|
|
18225
18233
|
let o = await n.onConflict({
|
|
18226
18234
|
op: e,
|
|
@@ -18230,11 +18238,11 @@ function dx(e, n = {}) {
|
|
|
18230
18238
|
expectedHash: t,
|
|
18231
18239
|
snapshotId: 0
|
|
18232
18240
|
});
|
|
18233
|
-
if (o.action === "keep_external") return `已保留外部修改(未写入)。当前值:${
|
|
18241
|
+
if (o.action === "keep_external") return `已保留外部修改(未写入)。当前值:${Tb(a, 400)} (hash=${i})。请重新 read 拿最新值与 hash 再改。`;
|
|
18234
18242
|
if (o.action === "restore") {
|
|
18235
|
-
if (!c.length) return `无历史快照可回退(本次为首次操作)。当前值:${
|
|
18243
|
+
if (!c.length) return `无历史快照可回退(本次为首次操作)。当前值:${Tb(a, 400)} (hash=${i})。请重新 read 再改或选「强制覆盖」。`;
|
|
18236
18244
|
let e = c[c.length - 1];
|
|
18237
|
-
return
|
|
18245
|
+
return Ab(a, xb(e.value)), p(), `已回退主数据到历史快照 #${e.id}[${e.op}]。当前值:${Tb(a, 400)} (hash=${Db(a)})。请基于回退后的值重写或停止。`;
|
|
18238
18246
|
}
|
|
18239
18247
|
return null;
|
|
18240
18248
|
}
|
|
@@ -18244,20 +18252,20 @@ function dx(e, n = {}) {
|
|
|
18244
18252
|
schema: t.object({})
|
|
18245
18253
|
}), y = r(async ({ jsonPath: e }) => {
|
|
18246
18254
|
let t = e || "";
|
|
18247
|
-
if (
|
|
18255
|
+
if (gb(t)) return $({
|
|
18248
18256
|
code: "PATH_UNSAFE",
|
|
18249
18257
|
message: `jsonPath "${t}" 含非法段(__proto__/constructor/prototype)`,
|
|
18250
18258
|
hint: "使用正常属性路径,如 components.0.text(数组索引用数字)"
|
|
18251
18259
|
});
|
|
18252
|
-
if (!
|
|
18260
|
+
if (!ry(t, i, s)) return $({
|
|
18253
18261
|
code: "PATH_DENIED",
|
|
18254
18262
|
message: `get_data @ "${t}" 不在 schema 声明字段内(仅 schema 声明的 key 可读)`,
|
|
18255
18263
|
hint: "主数据仅暴露 schema 声明的字段;若需操作该字段,集成方需在 schema 中声明它"
|
|
18256
18264
|
});
|
|
18257
|
-
let n = t ?
|
|
18258
|
-
t || (n =
|
|
18259
|
-
let r =
|
|
18260
|
-
return u = r, n === void 0 ? `主数据${t ? ` @ ${t}` : ""} = (undefined) (hash=${r})` : `主数据${t ? ` @ ${t}` : ""} = ${
|
|
18265
|
+
let n = t ? vb(a, t) : a;
|
|
18266
|
+
t || (n = sy(n, s));
|
|
18267
|
+
let r = Db(a);
|
|
18268
|
+
return u = r, n === void 0 ? `主数据${t ? ` @ ${t}` : ""} = (undefined) (hash=${r})` : `主数据${t ? ` @ ${t}` : ""} = ${Tb(n)} (hash=${r})`;
|
|
18261
18269
|
}, {
|
|
18262
18270
|
name: "get_data",
|
|
18263
18271
|
description: "读取主数据的当前值(安全序列化:函数/DOM/循环引用做摘要;大结果由系统自动外存,提示用 vfs_read 回读)。返回含 hash(乐观锁):改前先 read/get 拿 hash,写入时传 expectedHash 回传,系统对比当前 hash 防\"基于过期值覆盖\"。jsonPath 可选:读整个主数据不传,读子路径传(如 components.0.text)。",
|
|
@@ -18265,9 +18273,9 @@ function dx(e, n = {}) {
|
|
|
18265
18273
|
}), b = r(async ({ value: e, expectedHash: t }) => {
|
|
18266
18274
|
let n = await _("set", t || (d ? u : void 0));
|
|
18267
18275
|
if (n !== null) return n;
|
|
18268
|
-
let r =
|
|
18276
|
+
let r = Sb(e);
|
|
18269
18277
|
if (r.parseError) return Ug("", e, r.parseError);
|
|
18270
|
-
let o =
|
|
18278
|
+
let o = dx({
|
|
18271
18279
|
bindRef: a,
|
|
18272
18280
|
value: r.parsed,
|
|
18273
18281
|
schema: i,
|
|
@@ -18277,7 +18285,7 @@ function dx(e, n = {}) {
|
|
|
18277
18285
|
audit: h,
|
|
18278
18286
|
onWrite: p
|
|
18279
18287
|
});
|
|
18280
|
-
return o.ok ? (u = o.hash, `已设置主数据 = ${
|
|
18288
|
+
return o.ok ? (u = o.hash, `已设置主数据 = ${Tb(o.data, 600)} (新 hash=${o.hash})${s ? "(白名单模式:仅更新 schema 声明字段,未声明字段保留)" : ""}`) : o.error;
|
|
18281
18289
|
}, {
|
|
18282
18290
|
name: "set_data",
|
|
18283
18291
|
description: "设置主数据的值(整体替换)。value 为 JSON 对象(或 JSON 字符串),需通过 schema 校验。校验失败会返回错误而非写入。expectedHash(可选):改前 read/get 返回的 hash,传入则启用乐观锁;不传时系统自动用你最后一次读到的 hash 比对(autoLock,默认开)。大对象/数组强烈建议改用 edit_data 增量 patch。白名单模式(schema 为 ZodObject 子集):set 为根级浅合并,深层子对象整体替换(未传字段丢失);保留深层字段请用 edit_data({op:\"merge\", jsonPath:\"子路径\", value:{...}})局部合并。",
|
|
@@ -18293,12 +18301,12 @@ function dx(e, n = {}) {
|
|
|
18293
18301
|
hint: "顶层 op 或 patch.op 至少传一个"
|
|
18294
18302
|
});
|
|
18295
18303
|
let f = n || "";
|
|
18296
|
-
if (
|
|
18304
|
+
if (gb(f)) return $({
|
|
18297
18305
|
code: "PATH_UNSAFE",
|
|
18298
18306
|
message: `jsonPath "${f}" 含非法段(__proto__/constructor/prototype)`,
|
|
18299
18307
|
hint: "使用正常的属性路径,如 components.0.text(数组索引用数字)"
|
|
18300
18308
|
});
|
|
18301
|
-
if (!
|
|
18309
|
+
if (!ry(f, i, s)) return $({
|
|
18302
18310
|
code: "PATH_DENIED",
|
|
18303
18311
|
message: `edit_data @ "${f}" 不在 schema 声明字段内`,
|
|
18304
18312
|
hint: "仅 schema 声明的 key 可写;若需操作该字段,集成方需在 schema 中声明它"
|
|
@@ -18310,7 +18318,7 @@ function dx(e, n = {}) {
|
|
|
18310
18318
|
message: `edit 仅适用于对象/数组主数据,当前是 ${a === void 0 ? "undefined" : typeof a}`,
|
|
18311
18319
|
hint: "叶子(原始类型)请用 set_data 整体设置"
|
|
18312
18320
|
});
|
|
18313
|
-
let g =
|
|
18321
|
+
let g = fx({
|
|
18314
18322
|
bindRef: a,
|
|
18315
18323
|
patches: [{
|
|
18316
18324
|
op: t,
|
|
@@ -18331,7 +18339,7 @@ function dx(e, n = {}) {
|
|
|
18331
18339
|
detail: `${v.op}${f ? "@" + f : ""}`,
|
|
18332
18340
|
value: v.value,
|
|
18333
18341
|
timestamp: Date.now()
|
|
18334
|
-
}), u =
|
|
18342
|
+
}), u = Db(a), `已 edit 主数据(${v.op}${f ? " @ " + f : ""})。当前值:${Tb(a, 600)} (新 hash=${Db(a)})`;
|
|
18335
18343
|
}, {
|
|
18336
18344
|
name: "edit_data",
|
|
18337
18345
|
description: "增量编辑主数据(对象/数组),只发改动的 patch,无需重传整个大对象。op:set(在 jsonPath 设值)、remove(删 jsonPath)、merge(把 value 合并到 jsonPath 指向的对象,默认根)、append(把 value 追加到 jsonPath 指向的数组,默认根)。jsonPath 为相对主数据根的点号路径(数组索引用数字,如 components.0.text);value 为 JSON 对象(推荐直传)或 JSON 字符串。整体仍经 schema 校验,失败不写入。expectedHash(可选):改前 read/get 返回的 hash;不传时自动用你最后读到的 hash(autoLock,默认开)防\"基于过期值覆盖\"。",
|
|
@@ -18362,12 +18370,12 @@ function dx(e, n = {}) {
|
|
|
18362
18370
|
message: "delete_data 需要 jsonPath 指定要删的子路径(主数据整体不可删,用 set_data 整体替换)",
|
|
18363
18371
|
hint: "如 jsonPath:\"components.0\" 删数组首项"
|
|
18364
18372
|
});
|
|
18365
|
-
if (
|
|
18373
|
+
if (gb(e)) return $({
|
|
18366
18374
|
code: "PATH_UNSAFE",
|
|
18367
18375
|
message: `jsonPath "${e}" 含非法段`,
|
|
18368
18376
|
hint: "使用正常属性路径"
|
|
18369
18377
|
});
|
|
18370
|
-
if (!
|
|
18378
|
+
if (!ry(e, i, s)) return $({
|
|
18371
18379
|
code: "PATH_DENIED",
|
|
18372
18380
|
message: `delete_data @ "${e}" 不在 schema 声明字段内`,
|
|
18373
18381
|
hint: "仅 schema 声明的 key 可删"
|
|
@@ -18375,12 +18383,12 @@ function dx(e, n = {}) {
|
|
|
18375
18383
|
let n = await _("delete", t || (d ? u : void 0));
|
|
18376
18384
|
if (n !== null) return n;
|
|
18377
18385
|
g("delete");
|
|
18378
|
-
let r =
|
|
18386
|
+
let r = bb(a, e);
|
|
18379
18387
|
return p(), h({
|
|
18380
18388
|
op: "delete",
|
|
18381
18389
|
detail: e,
|
|
18382
18390
|
timestamp: Date.now()
|
|
18383
|
-
}), u =
|
|
18391
|
+
}), u = Db(a), r ? `已删除主数据 @ ${e}` : `主数据 @ ${e} 不存在(无需删除)`;
|
|
18384
18392
|
}, {
|
|
18385
18393
|
name: "delete_data",
|
|
18386
18394
|
description: "删除主数据的某个子路径(jsonPath)。主数据整体不可删(用 set_data 整体替换)。expectedHash(可选):改前 read/get 返回的 hash;不传时自动用你最后读到的 hash(autoLock,默认开)防\"基于过期值删除\"。",
|
|
@@ -18416,11 +18424,11 @@ function dx(e, n = {}) {
|
|
|
18416
18424
|
hint: "用 list_data_snapshots 查看可用快照序号"
|
|
18417
18425
|
});
|
|
18418
18426
|
let n = i.safeParse(t.value);
|
|
18419
|
-
return n.success ? (
|
|
18427
|
+
return n.success ? (Ab(a, xb(t.value)), p(), h({
|
|
18420
18428
|
op: "restore",
|
|
18421
18429
|
detail: `#${t.id}`,
|
|
18422
18430
|
timestamp: Date.now()
|
|
18423
|
-
}), u =
|
|
18431
|
+
}), u = Db(a), `已回退主数据到快照 #${t.id}[${t.op}]${t.label ? `(${t.label})` : ""}。`) : $({
|
|
18424
18432
|
code: "SNAPSHOT_SCHEMA_INVALID",
|
|
18425
18433
|
message: `快照 #${t.id} 的值不符合当前 schema,无法回退`,
|
|
18426
18434
|
hint: "schema 可能已变更;该快照已过期,选其他快照或重新设置",
|
|
@@ -18442,23 +18450,23 @@ function dx(e, n = {}) {
|
|
|
18442
18450
|
message: `未找到快照 #${e}`,
|
|
18443
18451
|
hint: "不传 id 查看最近一次;或用 list_data_snapshots(advanced) 查看可用序号"
|
|
18444
18452
|
});
|
|
18445
|
-
let r =
|
|
18453
|
+
let r = xb(n.value), a = t || "";
|
|
18446
18454
|
if (a) {
|
|
18447
|
-
if (
|
|
18455
|
+
if (gb(a)) return $({
|
|
18448
18456
|
code: "PATH_UNSAFE",
|
|
18449
18457
|
message: `jsonPath "${a}" 含非法段`,
|
|
18450
18458
|
hint: "使用正常属性路径"
|
|
18451
18459
|
});
|
|
18452
|
-
if (!
|
|
18460
|
+
if (!ry(a, i, s)) return $({
|
|
18453
18461
|
code: "PATH_DENIED",
|
|
18454
18462
|
message: `history_data @ "${a}" 不在 schema 声明字段内`,
|
|
18455
18463
|
hint: "仅 schema 声明的 key 可读"
|
|
18456
18464
|
});
|
|
18457
|
-
r =
|
|
18458
|
-
let e =
|
|
18459
|
-
e && (r =
|
|
18460
|
-
} else s && (r =
|
|
18461
|
-
return `快照 #${n.id}[${n.op}]${n.label ? `(${n.label})` : ""}${a ? ` @ ${a}` : ""} = ${
|
|
18465
|
+
r = vb(r, a);
|
|
18466
|
+
let e = ay(i, a);
|
|
18467
|
+
e && (r = oy(r, e));
|
|
18468
|
+
} else s && (r = oy(r, i));
|
|
18469
|
+
return `快照 #${n.id}[${n.op}]${n.label ? `(${n.label})` : ""}${a ? ` @ ${a}` : ""} = ${Tb(r)}`;
|
|
18462
18470
|
}, {
|
|
18463
18471
|
name: "history_data",
|
|
18464
18472
|
description: "只读查看某次快照(默认最近一次)的内容,不回退当前主数据。看上一版长啥样而不影响当前(冲突诊断/verify 自纠/用户问\"刚才改了啥\")。可选 id 指定快照序号、jsonPath 只看子路径(按 schema 投影)。",
|
|
@@ -18472,9 +18480,9 @@ function dx(e, n = {}) {
|
|
|
18472
18480
|
message: `主数据不是对象/数组,无法查询(当前为 ${a === void 0 ? "undefined" : typeof a})`,
|
|
18473
18481
|
hint: "query 仅适用于对象/数组;叶子用 get_data 读"
|
|
18474
18482
|
});
|
|
18475
|
-
let n = s ?
|
|
18483
|
+
let n = s ? sy(a, s) : a, r;
|
|
18476
18484
|
try {
|
|
18477
|
-
r =
|
|
18485
|
+
r = tx(n, e);
|
|
18478
18486
|
} catch (t) {
|
|
18479
18487
|
return $({
|
|
18480
18488
|
code: "JSONPATH_SYNTAX",
|
|
@@ -18483,7 +18491,7 @@ function dx(e, n = {}) {
|
|
|
18483
18491
|
details: { expr: e }
|
|
18484
18492
|
});
|
|
18485
18493
|
}
|
|
18486
|
-
let i = t ?? 50, o = r.slice(0, i), c = o.map((e) => `{"path":${JSON.stringify(e.path)},"index":${e.index === void 0 ? "null" : e.index},"value":${
|
|
18494
|
+
let i = t ?? 50, o = r.slice(0, i), c = o.map((e) => `{"path":${JSON.stringify(e.path)},"index":${e.index === void 0 ? "null" : e.index},"value":${Tb(e.value)}}`);
|
|
18487
18495
|
return `{"matched":${r.length},"returned":${o.length},"truncated":${r.length > i},"results":[${c.join(",")}]}`;
|
|
18488
18496
|
}, {
|
|
18489
18497
|
name: "query_data",
|
|
@@ -18498,13 +18506,13 @@ function dx(e, n = {}) {
|
|
|
18498
18506
|
message: "主数据为空,无可搜索内容"
|
|
18499
18507
|
});
|
|
18500
18508
|
try {
|
|
18501
|
-
let o =
|
|
18509
|
+
let o = rx(s ? sy(a, s) : a, e, {
|
|
18502
18510
|
mode: t,
|
|
18503
18511
|
fuzzyThreshold: n,
|
|
18504
18512
|
matchKey: r,
|
|
18505
18513
|
limit: i ?? 50
|
|
18506
18514
|
});
|
|
18507
|
-
return
|
|
18515
|
+
return Tb({
|
|
18508
18516
|
matched: o.length,
|
|
18509
18517
|
results: o
|
|
18510
18518
|
});
|
|
@@ -18538,17 +18546,17 @@ function dx(e, n = {}) {
|
|
|
18538
18546
|
});
|
|
18539
18547
|
let r = n || "", o;
|
|
18540
18548
|
if (r) {
|
|
18541
|
-
if (!
|
|
18549
|
+
if (!ry(r, i, s)) return $({
|
|
18542
18550
|
code: "PATH_DENIED",
|
|
18543
18551
|
message: `eval_script @ "${r}" 不在 schema 声明字段内`,
|
|
18544
18552
|
hint: "仅 schema 声明的 key 可作为子树"
|
|
18545
18553
|
});
|
|
18546
|
-
if (o =
|
|
18547
|
-
let e =
|
|
18548
|
-
e && (o =
|
|
18554
|
+
if (o = vb(a, r), s) {
|
|
18555
|
+
let e = ay(i, r);
|
|
18556
|
+
e && (o = oy(o, e));
|
|
18549
18557
|
}
|
|
18550
|
-
} else o = s ?
|
|
18551
|
-
let d =
|
|
18558
|
+
} else o = s ? sy(a, s) : a;
|
|
18559
|
+
let d = xb(o), f = await sx(d, e, r && JSON.stringify(d).length > 1e5 ? 8e3 : 3e3);
|
|
18552
18560
|
if (!f.ok) {
|
|
18553
18561
|
let t = /超时/.test(f.error || "");
|
|
18554
18562
|
return $({
|
|
@@ -18564,7 +18572,7 @@ function dx(e, n = {}) {
|
|
|
18564
18572
|
if (t === "transform") {
|
|
18565
18573
|
let e = f.result;
|
|
18566
18574
|
if (r) {
|
|
18567
|
-
let t =
|
|
18575
|
+
let t = fx({
|
|
18568
18576
|
bindRef: a,
|
|
18569
18577
|
patches: [{
|
|
18570
18578
|
op: "set",
|
|
@@ -18583,7 +18591,7 @@ function dx(e, n = {}) {
|
|
|
18583
18591
|
op: "edit",
|
|
18584
18592
|
detail: `eval_transform_subtree @ ${r}`,
|
|
18585
18593
|
timestamp: Date.now()
|
|
18586
|
-
}), u =
|
|
18594
|
+
}), u = Db(a), `已通过脚本 transform 子树 @ ${r} 更新(耗时 ${f.elapsedMs}ms)。当前值: ${Tb(a, 600)}`) : t.error;
|
|
18587
18595
|
}
|
|
18588
18596
|
if (e && typeof e == "object" && !Array.isArray(e) && "patches" in e && Array.isArray(e.patches)) {
|
|
18589
18597
|
if (typeof a != "object" || !a) return $({
|
|
@@ -18591,7 +18599,7 @@ function dx(e, n = {}) {
|
|
|
18591
18599
|
message: `主数据 bind 为原始类型(${a === null ? "null" : typeof a}),eval transform(patches) 无法就地替换`,
|
|
18592
18600
|
hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹或集成方通过 sdk.setData 替换 bind"
|
|
18593
18601
|
});
|
|
18594
|
-
let t =
|
|
18602
|
+
let t = fx({
|
|
18595
18603
|
bindRef: a,
|
|
18596
18604
|
patches: e.patches,
|
|
18597
18605
|
schema: i,
|
|
@@ -18606,25 +18614,25 @@ function dx(e, n = {}) {
|
|
|
18606
18614
|
op: "edit",
|
|
18607
18615
|
detail: `eval_transform(${t.applied.length} patches)`,
|
|
18608
18616
|
timestamp: Date.now()
|
|
18609
|
-
}), u =
|
|
18617
|
+
}), u = Db(a), `已通过脚本 transform(patches) 更新主数据(${t.applied.length} 个 patch,耗时 ${f.elapsedMs}ms)。当前值: ${Tb(a, 600)}`) : t.error;
|
|
18610
18618
|
}
|
|
18611
18619
|
let t = i.safeParse(e);
|
|
18612
18620
|
return t.success ? typeof a != "object" || !a ? $({
|
|
18613
18621
|
code: "LEAF_BIND",
|
|
18614
18622
|
message: `主数据 bind 为原始类型(${a === null ? "null" : typeof a}),eval transform 无法就地替换外部持有的值引用`,
|
|
18615
18623
|
hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹或集成方通过 sdk.setData 替换 bind"
|
|
18616
|
-
}) : (g("edit", "eval_transform"), t.data !== null && typeof t.data == "object" && (s ?
|
|
18624
|
+
}) : (g("edit", "eval_transform"), t.data !== null && typeof t.data == "object" && (s ? _b(a, t.data) : jb(a, t.data)), p(), h({
|
|
18617
18625
|
op: "edit",
|
|
18618
18626
|
detail: "eval_transform",
|
|
18619
18627
|
timestamp: Date.now()
|
|
18620
|
-
}), u =
|
|
18628
|
+
}), u = Db(a), `已通过脚本 transform 更新主数据(耗时 ${f.elapsedMs}ms)。当前值: ${Tb(a, 600)}`) : $({
|
|
18621
18629
|
code: "SCHEMA_INVALID",
|
|
18622
18630
|
message: "脚本返回值校验失败,未写入(transform 模式要求返回主数据的完整新值且符合 schema)",
|
|
18623
18631
|
hint: "确认脚本 return 了完整新值(非部分);或返回 {patches:[...]} 走增量模式;按 describe_data() 查看格式",
|
|
18624
18632
|
details: Vg(t.error.issues)
|
|
18625
18633
|
});
|
|
18626
18634
|
}
|
|
18627
|
-
return
|
|
18635
|
+
return Tb({
|
|
18628
18636
|
ok: !0,
|
|
18629
18637
|
result: f.result,
|
|
18630
18638
|
elapsedMs: f.elapsedMs
|
|
@@ -18638,16 +18646,16 @@ function dx(e, n = {}) {
|
|
|
18638
18646
|
jsonPath: t.string().optional().describe("子树模式:仅对 jsonPath 指向的子树执行(降低大 JSON 成本);transform 时返回值作为该子树新值")
|
|
18639
18647
|
})
|
|
18640
18648
|
}), A = r(async ({ jsonPath: e, jsonPaths: t, fields: r, depth: c, offset: l, limit: d }) => {
|
|
18641
|
-
let f =
|
|
18649
|
+
let f = Db(a);
|
|
18642
18650
|
if (u = f, t && t.length) {
|
|
18643
18651
|
let e = t.map((e) => {
|
|
18644
18652
|
let t = e || "";
|
|
18645
|
-
if (!
|
|
18646
|
-
let o = t ?
|
|
18647
|
-
if (!t) o =
|
|
18653
|
+
if (!ry(t, i, s)) return `- ${t || "(根)"}: [PATH_DENIED: 不在 schema 声明字段内]`;
|
|
18654
|
+
let o = t ? vb(a, t) : a;
|
|
18655
|
+
if (!t) o = sy(o, s);
|
|
18648
18656
|
else if (s) {
|
|
18649
|
-
let e =
|
|
18650
|
-
e && (o =
|
|
18657
|
+
let e = ay(i, t);
|
|
18658
|
+
e && (o = oy(o, e));
|
|
18651
18659
|
}
|
|
18652
18660
|
let l = o;
|
|
18653
18661
|
if (n.interceptors?.read) try {
|
|
@@ -18655,26 +18663,26 @@ function dx(e, n = {}) {
|
|
|
18655
18663
|
} catch (e) {
|
|
18656
18664
|
return `- ${t}: [READ_INTERCEPT: ${e.message}]`;
|
|
18657
18665
|
}
|
|
18658
|
-
return r && r.length && (l =
|
|
18666
|
+
return r && r.length && (l = Cb(l, r)), c != null && (l = wb(l, c)), l === void 0 ? `- ${t} = (undefined)` : `- ${t} = ${Tb(l)}`;
|
|
18659
18667
|
});
|
|
18660
18668
|
return `多路径读取(共 ${t.length} 项,hash=${f}):\n${e.join("\n")}`;
|
|
18661
18669
|
}
|
|
18662
18670
|
let p = e || "";
|
|
18663
|
-
if (
|
|
18671
|
+
if (gb(p)) return $({
|
|
18664
18672
|
code: "PATH_UNSAFE",
|
|
18665
18673
|
message: `jsonPath "${p}" 含非法段(__proto__/constructor/prototype)`,
|
|
18666
18674
|
hint: "使用正常属性路径,如 components.0.text(数组索引数字)"
|
|
18667
18675
|
});
|
|
18668
|
-
if (!
|
|
18676
|
+
if (!ry(p, i, s)) return $({
|
|
18669
18677
|
code: "PATH_DENIED",
|
|
18670
18678
|
message: `read @ "${p}" 不在 schema 声明字段内`,
|
|
18671
18679
|
hint: "主数据仅暴露 schema 声明的字段;若需操作该字段,集成方需在 schema 中声明它"
|
|
18672
18680
|
});
|
|
18673
|
-
let m = p ?
|
|
18674
|
-
if (!p) m =
|
|
18681
|
+
let m = p ? vb(a, p) : a;
|
|
18682
|
+
if (!p) m = sy(m, s);
|
|
18675
18683
|
else if (s) {
|
|
18676
|
-
let e =
|
|
18677
|
-
e && (m =
|
|
18684
|
+
let e = ay(i, p);
|
|
18685
|
+
e && (m = oy(m, e));
|
|
18678
18686
|
}
|
|
18679
18687
|
let h = m;
|
|
18680
18688
|
if (n.interceptors?.read) try {
|
|
@@ -18685,13 +18693,13 @@ function dx(e, n = {}) {
|
|
|
18685
18693
|
message: `read 拦截器抛错: ${e.message}`
|
|
18686
18694
|
});
|
|
18687
18695
|
}
|
|
18688
|
-
r && r.length && (h =
|
|
18696
|
+
r && r.length && (h = Cb(h, r)), c != null && (h = wb(h, c));
|
|
18689
18697
|
let g = e ? "" : `主数据说明: ${o}\n格式: 写入值需为 JSON,且通过声明的 schema 校验(校验失败时 write 会返回结构化错误)。字段约束(类型/min/max/enum/必填/默认)见 systemPrompt「可操作数据」段,或用 schema_data({ jsonPath }) 按需查。\n\n`, _ = r && r.length ? `(字段裁剪:${r.join(",")})` : "", v = c == null ? "" : `(深度≤${c})`, y = _ || v ? ` ${_}${v}` : "";
|
|
18690
18698
|
if ((l !== void 0 || d !== void 0) && Array.isArray(h)) {
|
|
18691
18699
|
let e = h.length, t = Math.max(0, l ?? 0), n = Math.min(200, Math.max(1, d ?? 50)), r = h.slice(t, t + n), i = t + n < e;
|
|
18692
|
-
return `${g}主数据${p ? ` @ ${p}` : ""} 数组分页[offset=${t},limit=${n}]${y} = ${
|
|
18700
|
+
return `${g}主数据${p ? ` @ ${p}` : ""} 数组分页[offset=${t},limit=${n}]${y} = ${Tb(r)} (total=${e}, hasMore=${i}) (hash=${f})`;
|
|
18693
18701
|
}
|
|
18694
|
-
return h === void 0 ? `${g}主数据${p ? ` @ ${p}` : ""}${y} = (undefined) (hash=${f})` : `${g}主数据${p ? ` @ ${p}` : ""}${y} = ${
|
|
18702
|
+
return h === void 0 ? `${g}主数据${p ? ` @ ${p}` : ""}${y} = (undefined) (hash=${f})` : `${g}主数据${p ? ` @ ${p}` : ""}${y} = ${Tb(h)} (hash=${f})`;
|
|
18695
18703
|
}, {
|
|
18696
18704
|
name: "read",
|
|
18697
18705
|
description: "读取主数据(高层入口,合并 describe/get)。不传 jsonPath → 返回主数据说明 + 格式提示(含字段约束);传 jsonPath → 返回该子路径当前值 + hash;传 jsonPaths → 一次读多个不相关子路径(省多轮往返)。hash 用于乐观锁(默认 autoLock,write 时自动比对,无需手动传)。fields(字段裁剪)/depth(深度截断)减体积;offset+limit 对数组目标分页(返回切片 + total/hasMore)。集成方可能经 read 拦截器对返回值脱敏/派生。",
|
|
@@ -18734,7 +18742,7 @@ function dx(e, n = {}) {
|
|
|
18734
18742
|
}
|
|
18735
18743
|
let b = d ? u : void 0;
|
|
18736
18744
|
if (f && b !== void 0) {
|
|
18737
|
-
let e =
|
|
18745
|
+
let e = Db(a);
|
|
18738
18746
|
if (e !== b) return $({
|
|
18739
18747
|
code: "VERSION_CONFLICT",
|
|
18740
18748
|
message: `dryRun 预检发现乐观锁冲突: expectedHash=${b} 当前 hash=${e}(主数据在你 read 后被改)`,
|
|
@@ -18747,12 +18755,12 @@ function dx(e, n = {}) {
|
|
|
18747
18755
|
message: "delete 需要 patch.jsonPath 指定要删的子路径(主数据整体不可删,用 write(value) 整体替换)",
|
|
18748
18756
|
hint: "如 patch:{jsonPath:\"components.0\"}, del:true"
|
|
18749
18757
|
});
|
|
18750
|
-
if (
|
|
18758
|
+
if (gb(t.jsonPath)) return $({
|
|
18751
18759
|
code: "PATH_UNSAFE",
|
|
18752
18760
|
message: `jsonPath "${t.jsonPath}" 含非法段`,
|
|
18753
18761
|
hint: "使用正常属性路径"
|
|
18754
18762
|
});
|
|
18755
|
-
if (!
|
|
18763
|
+
if (!ry(t.jsonPath, i, s)) return $({
|
|
18756
18764
|
code: "PATH_DENIED",
|
|
18757
18765
|
message: `write delete @ "${t.jsonPath}" 不在 schema 声明字段内`,
|
|
18758
18766
|
hint: "仅 schema 声明的 key 可删"
|
|
@@ -18760,16 +18768,16 @@ function dx(e, n = {}) {
|
|
|
18760
18768
|
let e = await _("delete", b);
|
|
18761
18769
|
if (e !== null) return e;
|
|
18762
18770
|
if (f) {
|
|
18763
|
-
let e =
|
|
18764
|
-
return
|
|
18771
|
+
let e = xb(a);
|
|
18772
|
+
return bb(e, t.jsonPath) ? `dryRun(delete): 将删除 @ ${t.jsonPath}。预览剩余:${Tb(e, 600)}。未实际写入、未入快照。` : `dryRun(delete): @ ${t.jsonPath} 不存在(无需删除)。未实际写入。`;
|
|
18765
18773
|
}
|
|
18766
18774
|
g("delete");
|
|
18767
|
-
let n =
|
|
18775
|
+
let n = bb(a, t.jsonPath);
|
|
18768
18776
|
return p(), h({
|
|
18769
18777
|
op: "delete",
|
|
18770
18778
|
detail: t.jsonPath,
|
|
18771
18779
|
timestamp: Date.now()
|
|
18772
|
-
}), u =
|
|
18780
|
+
}), u = Db(a), n ? `已删除主数据 @ ${t.jsonPath}` : `主数据 @ ${t.jsonPath} 不存在(无需删除)`;
|
|
18773
18781
|
}
|
|
18774
18782
|
if (m === "edit") {
|
|
18775
18783
|
if (typeof a != "object" || !a) return $({
|
|
@@ -18783,7 +18791,7 @@ function dx(e, n = {}) {
|
|
|
18783
18791
|
op: t.op ?? "set",
|
|
18784
18792
|
jsonPath: t.jsonPath || "",
|
|
18785
18793
|
value: v
|
|
18786
|
-
}]), o =
|
|
18794
|
+
}]), o = fx({
|
|
18787
18795
|
bindRef: a,
|
|
18788
18796
|
patches: n,
|
|
18789
18797
|
schema: i,
|
|
@@ -18794,18 +18802,18 @@ function dx(e, n = {}) {
|
|
|
18794
18802
|
schemaErrorMode: "zod",
|
|
18795
18803
|
dryRun: f
|
|
18796
18804
|
});
|
|
18797
|
-
return o.ok ? f ? `dryRun(edit): ${o.applied.length} 个 patch 预检通过(schema 校验 OK)。预览结果:${
|
|
18805
|
+
return o.ok ? f ? `dryRun(edit): ${o.applied.length} 个 patch 预检通过(schema 校验 OK)。预览结果:${Tb(o.clone, 600)}。未实际写入、未入快照。` : (h({
|
|
18798
18806
|
op: "edit",
|
|
18799
18807
|
detail: `${o.applied.length} 个 patch${o.applied.length > 1 ? "(批量)" : ""}`,
|
|
18800
18808
|
value: o.applied.map((e) => `${e.op}@${e.jp}`),
|
|
18801
18809
|
timestamp: Date.now()
|
|
18802
|
-
}), u =
|
|
18810
|
+
}), u = Db(a), `已 write(edit) 主数据(${o.applied.length} 个 patch)。当前值:${Tb(a, 600)} (新 hash=${Db(a)})`) : o.error;
|
|
18803
18811
|
}
|
|
18804
|
-
let x =
|
|
18812
|
+
let x = Sb(v);
|
|
18805
18813
|
if (x.parseError) return Ug("", v, x.parseError);
|
|
18806
18814
|
let S = await _("set", b);
|
|
18807
18815
|
if (S !== null) return S;
|
|
18808
|
-
let C =
|
|
18816
|
+
let C = dx({
|
|
18809
18817
|
bindRef: a,
|
|
18810
18818
|
value: x.parsed,
|
|
18811
18819
|
schema: i,
|
|
@@ -18816,7 +18824,7 @@ function dx(e, n = {}) {
|
|
|
18816
18824
|
dryRun: f,
|
|
18817
18825
|
onWrite: p
|
|
18818
18826
|
});
|
|
18819
|
-
return C.ok ? f ? `dryRun(set): schema 校验通过。预览新值:${
|
|
18827
|
+
return C.ok ? f ? `dryRun(set): schema 校验通过。预览新值:${Tb(C.data, 600)}。未实际写入、未入快照。` : (u = C.hash, `已 write(set) 主数据 = ${Tb(C.data, 600)} (新 hash=${C.hash})${s ? "(白名单模式:仅更新 schema 声明字段,未声明字段保留)" : ""}`) : C.error;
|
|
18820
18828
|
}, {
|
|
18821
18829
|
name: "write",
|
|
18822
18830
|
description: "写入主数据(高层入口,合并 set/edit/delete + 自动乐观锁 + 自动快照)。四种意图:① 整体替换 write({ value }) value 为整个 JSON 对象(推荐)或字符串;② 单个增量 patch write({ patch:{op,jsonPath,value} }) op=set/remove/merge/append,jsonPath 相对主数据根(如 components.0.props.title),patch.value 是该 patch 的值(自带,与 patches 一致——string/number 直传该字段新值,勿包成 {字段:值} 对象);也兼容 write({ value, patch:{op,jsonPath} }) 顶层 value 形式(向后兼容,但优先用 patch.value 避免与①整体 set 的 value 语义混淆);③ 批量增量 write({ patches:[{op,jsonPath,value},...] }) 一次原子应用多个 patch(任一失败整体不写入,适合一次改多处);④ 删除 write({ patch:{jsonPath}, del:true })。写入自动经 schema 校验(失败不写)+ 自动存快照(可 restore_data 回退)+ 自动乐观锁(autoLock,用你最后 read 到的 hash 比对,冲突则 VERSION_CONFLICT)。集成方可能经 write 拦截器校验/转换/拒绝(批量模式拦截器收到 {patches},返回新 patches 数组或 {error})。dryRun(可选):预检模式,走完整校验链(schema + 白名单 + patch 应用到 clone)但不落盘/入快照,返回预览(四意图均支持,复杂改动先看会改成啥、能否过 schema)。",
|
|
@@ -18846,8 +18854,8 @@ function dx(e, n = {}) {
|
|
|
18846
18854
|
dryRun: t.boolean().optional().describe("预检模式:走完整校验链(schema + 白名单 + patch 应用到 clone)但不落盘、不入快照,返回预览。四意图(value/patch/patches/del)均支持;乐观锁冲突照常检测(返回 VERSION_CONFLICT 不挂起)")
|
|
18847
18855
|
})
|
|
18848
18856
|
}), M = r(async ({ jsonPath: e }) => {
|
|
18849
|
-
let t = e || "", n = t ?
|
|
18850
|
-
return n ? `schema${t ? ` @ ${t}` : ""} = ${
|
|
18857
|
+
let t = e || "", n = t ? ay(i, t) : i;
|
|
18858
|
+
return n ? `schema${t ? ` @ ${t}` : ""} = ${Tb(py(n))}` : $({
|
|
18851
18859
|
code: "PATH_DENIED",
|
|
18852
18860
|
message: `schema @ "${t}" 不存在`,
|
|
18853
18861
|
hint: "jsonPath 需在 schema 声明字段内(用 read() 不传 jsonPath 查看顶层字段)"
|
|
@@ -18861,7 +18869,7 @@ function dx(e, n = {}) {
|
|
|
18861
18869
|
if (n) {
|
|
18862
18870
|
let e = t;
|
|
18863
18871
|
if (typeof e == "string") {
|
|
18864
|
-
let t =
|
|
18872
|
+
let t = Sb(e);
|
|
18865
18873
|
t.parseError || (e = t.parsed);
|
|
18866
18874
|
}
|
|
18867
18875
|
r = e, i = "against";
|
|
@@ -18879,8 +18887,8 @@ function dx(e, n = {}) {
|
|
|
18879
18887
|
});
|
|
18880
18888
|
r = t.value, i = `快照 #${t.id}`;
|
|
18881
18889
|
}
|
|
18882
|
-
let o = s ?
|
|
18883
|
-
return l.length ? `差异(当前 vs ${i},共 ${l.length} 处):\n${l.map((e) => ` ${e.path}: ${
|
|
18890
|
+
let o = s ? sy(a, s) : a, l = Mb(r, xb(o));
|
|
18891
|
+
return l.length ? `差异(当前 vs ${i},共 ${l.length} 处):\n${l.map((e) => ` ${e.path}: ${Tb(e.from)} → ${Tb(e.to)}`).join("\n")}` : `无差异:当前主数据与 ${i} 完全相同。`;
|
|
18884
18892
|
}, {
|
|
18885
18893
|
name: "diff_data",
|
|
18886
18894
|
description: "对比当前主数据与某快照(默认最近)或一段 JSON(against)的差异,返回结构化 {path, from→to} 列表。供 verify 自纠/冲突诊断/操作审计(\"刚才改了啥\")。snapshotId 指定快照;against 传一段 JSON 值(与 snapshotId 互斥,传则忽略快照)。",
|
|
@@ -18890,7 +18898,7 @@ function dx(e, n = {}) {
|
|
|
18890
18898
|
})
|
|
18891
18899
|
}), N = [];
|
|
18892
18900
|
if (n.vfsStore) {
|
|
18893
|
-
let e = n.vfsStore, o = (e) => `drafts/${e}.json`,
|
|
18901
|
+
let e = n.vfsStore, o = (e) => `drafts/${e}.json`, f = r(({ draftId: t, chunk: n, mode: r }) => {
|
|
18894
18902
|
let i = o(t), a = e.files[i], s = r === "append" && a, c = s ? a.content + n : n;
|
|
18895
18903
|
return e.files[i] = {
|
|
18896
18904
|
content: c,
|
|
@@ -18908,30 +18916,32 @@ function dx(e, n = {}) {
|
|
|
18908
18916
|
chunk: t.string().describe("JSON 片段字符串(分块输出,append 拼接成完整 JSON;如 '{\"components\":[' / '{\"type\":\"heading\",...},' / ']}')"),
|
|
18909
18917
|
mode: t.enum(["start", "append"]).optional().describe("start=新建/覆盖(默认);append=追加 chunk 到已有草稿")
|
|
18910
18918
|
})
|
|
18911
|
-
}),
|
|
18912
|
-
let
|
|
18913
|
-
if (!
|
|
18919
|
+
}), m = r(async ({ draftId: t, expectedHash: n }) => {
|
|
18920
|
+
let r = o(t), f = e.files[r];
|
|
18921
|
+
if (!f) return $({
|
|
18914
18922
|
code: "DRAFT_NOT_FOUND",
|
|
18915
18923
|
message: `草稿 "${t}" 不存在`,
|
|
18916
18924
|
hint: "先 draft_write({draftId, chunk, mode:\"start\"}) 新建,再 append 累积分块"
|
|
18917
18925
|
});
|
|
18918
|
-
let
|
|
18926
|
+
let m;
|
|
18919
18927
|
try {
|
|
18920
|
-
|
|
18928
|
+
m = JSON.parse(f.content);
|
|
18921
18929
|
} catch (e) {
|
|
18922
18930
|
return $({
|
|
18923
18931
|
code: "JSON_INVALID",
|
|
18924
18932
|
message: `草稿 "${t}" 拼接后非合法 JSON: ${e.message}`,
|
|
18925
18933
|
hint: "检查 chunk 拼接(逗号/括号/引号是否匹配,首尾是否闭合);草稿保留未删,可继续 draft_write 修正后重 commit",
|
|
18926
18934
|
details: {
|
|
18927
|
-
bytes:
|
|
18928
|
-
preview:
|
|
18935
|
+
bytes: f.content.length,
|
|
18936
|
+
preview: f.content.slice(0, 200) + (f.content.length > 200 ? "…" : "")
|
|
18929
18937
|
}
|
|
18930
18938
|
});
|
|
18931
18939
|
}
|
|
18932
|
-
let
|
|
18940
|
+
let g = await _("set", n || (d ? u : void 0));
|
|
18941
|
+
if (g !== null) return g;
|
|
18942
|
+
let v = dx({
|
|
18933
18943
|
bindRef: a,
|
|
18934
|
-
value:
|
|
18944
|
+
value: m,
|
|
18935
18945
|
schema: i,
|
|
18936
18946
|
allowKeys: s,
|
|
18937
18947
|
snapshots: c,
|
|
@@ -18940,13 +18950,16 @@ function dx(e, n = {}) {
|
|
|
18940
18950
|
op: "draft_commit",
|
|
18941
18951
|
onWrite: p
|
|
18942
18952
|
});
|
|
18943
|
-
return
|
|
18953
|
+
return v.ok ? (u = v.hash, delete e.files[r], `已 draft_commit 草稿 "${t}" → 主数据 = ${Tb(v.data, 600)} (新 hash=${v.hash})${s ? "(白名单模式:仅更新 schema 声明字段)" : ""}。草稿已清理。`) : v.error;
|
|
18944
18954
|
}, {
|
|
18945
18955
|
name: "draft_commit",
|
|
18946
|
-
description: "把 draft_write 累积的草稿合并 + schema 校验 + 原子提交到主数据(失败不污染 bind,草稿保留供修后重试)。流程:读 drafts/{draftId}.json → JSON.parse(失败 JSON_INVALID,草稿保留)→ schema 校验(失败 SCHEMA_INVALID,草稿保留)→ 写 bind + 自动快照(与 write(set)/set_data 共用 commitSetToBind,restore_data 可回退)→ 清草稿。适合从零生成大 JSON(如 50+ 组件页面):分块 draft_write 累积 → draft_commit 一次提交。小改仍用 write/patch(无需 draft)。",
|
|
18947
|
-
schema: t.object({
|
|
18956
|
+
description: "把 draft_write 累积的草稿合并 + schema 校验 + 原子提交到主数据(失败不污染 bind,草稿保留供修后重试)。流程:读 drafts/{draftId}.json → JSON.parse(失败 JSON_INVALID,草稿保留)→ 乐观锁校验(expectedHash/autoLock,失败触发冲突人工介入,草稿保留)→ schema 校验(失败 SCHEMA_INVALID,草稿保留)→ 写 bind + 自动快照(与 write(set)/set_data 共用 commitSetToBind,restore_data 可回退)→ 清草稿。适合从零生成大 JSON(如 50+ 组件页面):分块 draft_write 累积 → draft_commit 一次提交。小改仍用 write/patch(无需 draft)。",
|
|
18957
|
+
schema: t.object({
|
|
18958
|
+
draftId: t.string().describe("要提交的草稿标识(对应 draft_write 的 draftId)"),
|
|
18959
|
+
expectedHash: t.string().optional().describe("乐观锁:改前 read/get 返回的 hash;传入则校验,不一致拒绝写入防覆盖。不传则自动用你最后读到的 hash(autoLock)")
|
|
18960
|
+
})
|
|
18948
18961
|
});
|
|
18949
|
-
N.push(
|
|
18962
|
+
N.push(f, m);
|
|
18950
18963
|
}
|
|
18951
18964
|
let P = [
|
|
18952
18965
|
v,
|
|
@@ -18976,8 +18989,8 @@ function dx(e, n = {}) {
|
|
|
18976
18989
|
}
|
|
18977
18990
|
//#endregion
|
|
18978
18991
|
//#region src/core/tools/fetchDoc.ts
|
|
18979
|
-
var
|
|
18980
|
-
let n = new AbortController(), r = setTimeout(() => n.abort(),
|
|
18992
|
+
var mx = 3e4, hx = [r(async ({ url: e, as: t }) => {
|
|
18993
|
+
let n = new AbortController(), r = setTimeout(() => n.abort(), mx);
|
|
18981
18994
|
try {
|
|
18982
18995
|
let r = await fetch(e, {
|
|
18983
18996
|
method: "GET",
|
|
@@ -18994,7 +19007,7 @@ var fx = 3e4, px = [r(async ({ url: e, as: t }) => {
|
|
|
18994
19007
|
].join("\n");
|
|
18995
19008
|
} catch (t) {
|
|
18996
19009
|
let r = t?.message || String(t);
|
|
18997
|
-
return n.signal.aborted ? `获取失败:请求超时(${
|
|
19010
|
+
return n.signal.aborted ? `获取失败:请求超时(${mx}ms,${e})。` : /Failed to fetch|NetworkError|CORS|blocked/i.test(r) ? `获取失败:可能是 CORS 跨域拦截或网络错误(${r})。浏览器仅能 GET 同源或服务端已配置 CORS 的资源;跨域抓取需后端代理。` : `获取失败:${r}`;
|
|
18998
19011
|
} finally {
|
|
18999
19012
|
clearTimeout(r);
|
|
19000
19013
|
}
|
|
@@ -19005,7 +19018,7 @@ var fx = 3e4, px = [r(async ({ url: e, as: t }) => {
|
|
|
19005
19018
|
url: t.string().describe("要抓取的 URL(同源或已配 CORS)"),
|
|
19006
19019
|
as: t.enum(["text", "markdown"]).optional().describe("返回格式标签,默认 text")
|
|
19007
19020
|
})
|
|
19008
|
-
})],
|
|
19021
|
+
})], gx = [
|
|
19009
19022
|
"id",
|
|
19010
19023
|
"class",
|
|
19011
19024
|
"href",
|
|
@@ -19017,12 +19030,12 @@ var fx = 3e4, px = [r(async ({ url: e, as: t }) => {
|
|
|
19017
19030
|
"aria-label",
|
|
19018
19031
|
"name",
|
|
19019
19032
|
"type"
|
|
19020
|
-
],
|
|
19021
|
-
function
|
|
19033
|
+
], _x = /^(value|srcdoc|formaction|on\w+)$/i, vx = /token|secret|password|passwd|api[-_]?key|auth|cred|csrf|session/i;
|
|
19034
|
+
function yx(e, t) {
|
|
19022
19035
|
if (!e) return null;
|
|
19023
|
-
let { depth: n, attrs: r, includeText: i = !0 } = t, a = r !== void 0, o = r ??
|
|
19036
|
+
let { depth: n, attrs: r, includeText: i = !0 } = t, a = r !== void 0, o = r ?? gx, s = (e) => {
|
|
19024
19037
|
let t = {};
|
|
19025
|
-
for (let n of Array.from(e.attributes)) (a ? o.includes(n.name) : o.includes(n.name) || n.name.startsWith("data-")) && (
|
|
19038
|
+
for (let n of Array.from(e.attributes)) (a ? o.includes(n.name) : o.includes(n.name) || n.name.startsWith("data-")) && (_x.test(n.name) || vx.test(n.name) || (t[n.name] = n.value));
|
|
19026
19039
|
return t;
|
|
19027
19040
|
}, c = (e, t) => {
|
|
19028
19041
|
let n = {
|
|
@@ -19038,10 +19051,10 @@ function _x(e, t) {
|
|
|
19038
19051
|
};
|
|
19039
19052
|
return c(e, n);
|
|
19040
19053
|
}
|
|
19041
|
-
var
|
|
19054
|
+
var bx = r(({ selector: e, depth: t, attrs: n, includeText: r }) => {
|
|
19042
19055
|
let i = e ? document.querySelector(e) : document.body;
|
|
19043
19056
|
if (!i) return `未找到匹配元素:selector="${e}"`;
|
|
19044
|
-
let a =
|
|
19057
|
+
let a = yx(i, {
|
|
19045
19058
|
depth: t ?? 3,
|
|
19046
19059
|
attrs: n,
|
|
19047
19060
|
includeText: r ?? !0
|
|
@@ -19056,14 +19069,14 @@ var vx = r(({ selector: e, depth: t, attrs: n, includeText: r }) => {
|
|
|
19056
19069
|
attrs: t.array(t.string()).optional().describe("属性白名单(传了 = 严格白名单;不传 = 默认常用 + data-*)"),
|
|
19057
19070
|
includeText: t.boolean().optional().describe("是否包含直接文本(默认 true)")
|
|
19058
19071
|
})
|
|
19059
|
-
}),
|
|
19072
|
+
}), xx = [bx];
|
|
19060
19073
|
//#endregion
|
|
19061
19074
|
//#region src/core/tools/envTool.ts
|
|
19062
|
-
function
|
|
19075
|
+
function Sx(e) {
|
|
19063
19076
|
let t = e;
|
|
19064
19077
|
return typeof t.tagName == "string" || typeof t.nodeType == "number" && typeof t.nodeName == "string";
|
|
19065
19078
|
}
|
|
19066
|
-
function
|
|
19079
|
+
function Cx(e, t = 3, n = 2e3, r) {
|
|
19067
19080
|
if (e == null) return e;
|
|
19068
19081
|
if (typeof e == "string") return e.length > n ? e.slice(0, n) + "…(已截断)" : e;
|
|
19069
19082
|
if (typeof e == "number" || typeof e == "boolean") return e;
|
|
@@ -19072,14 +19085,14 @@ function xx(e, t = 3, n = 2e3, r) {
|
|
|
19072
19085
|
if (typeof e == "bigint") return `${e.toString()}n`;
|
|
19073
19086
|
if (typeof e != "object") return String(e);
|
|
19074
19087
|
let i = e;
|
|
19075
|
-
if (
|
|
19088
|
+
if (Sx(i)) {
|
|
19076
19089
|
let e = i;
|
|
19077
19090
|
return e.tagName ? `[Element: <${e.tagName.toLowerCase()}>]` : `[Node: ${e.nodeName}]`;
|
|
19078
19091
|
}
|
|
19079
19092
|
if (r?.has(i)) return "[Circular]";
|
|
19080
19093
|
let a = r ?? /* @__PURE__ */ new WeakSet();
|
|
19081
19094
|
if (a.add(i), Array.isArray(e)) {
|
|
19082
|
-
let r = e.slice(0, 100).map((e) =>
|
|
19095
|
+
let r = e.slice(0, 100).map((e) => Cx(e, t - 1, n, a));
|
|
19083
19096
|
return e.length > 100 && r.push(`…(共 ${e.length} 项,已截断)`), r;
|
|
19084
19097
|
}
|
|
19085
19098
|
if (t < 0) return "(对象,已截断)";
|
|
@@ -19091,14 +19104,14 @@ function xx(e, t = 3, n = 2e3, r) {
|
|
|
19091
19104
|
break;
|
|
19092
19105
|
}
|
|
19093
19106
|
try {
|
|
19094
|
-
o[r] =
|
|
19107
|
+
o[r] = Cx(i[r], t - 1, n, a);
|
|
19095
19108
|
} catch {
|
|
19096
19109
|
o[r] = "(getter 抛错)";
|
|
19097
19110
|
}
|
|
19098
19111
|
}
|
|
19099
19112
|
return o;
|
|
19100
19113
|
}
|
|
19101
|
-
function
|
|
19114
|
+
function wx(e) {
|
|
19102
19115
|
let t = e ?? (typeof window < "u" ? window : {}), n = t.navigator, r = t.location, i = t.document;
|
|
19103
19116
|
return {
|
|
19104
19117
|
location: {
|
|
@@ -19131,9 +19144,9 @@ function Sx(e) {
|
|
|
19131
19144
|
} : "(无 document)"
|
|
19132
19145
|
};
|
|
19133
19146
|
}
|
|
19134
|
-
var
|
|
19147
|
+
var Tx = /^(localStorage|sessionStorage|cookie|document|frames|frameElement|opener|parent|top|self|window|globalThis|closed|history|navigation|trustedTypes|origin|crossOriginIsolated)$/, Ex = /token|secret|password|passwd|api[-_]?key|auth|cred|csrf|session|ticket/i, Dx = r(({ key: e }) => {
|
|
19135
19148
|
if (e) {
|
|
19136
|
-
if (
|
|
19149
|
+
if (Tx.test(e) || Ex.test(e)) return JSON.stringify({
|
|
19137
19150
|
key: e,
|
|
19138
19151
|
denied: !0,
|
|
19139
19152
|
reason: "安全:该 key 在 denylist(localStorage/sessionStorage/cookie/document 或敏感命名 token/secret/key/auth),不读取防泄漏"
|
|
@@ -19143,18 +19156,18 @@ var Cx = /^(localStorage|sessionStorage|cookie|document|frames|frameElement|open
|
|
|
19143
19156
|
key: e,
|
|
19144
19157
|
exists: t !== void 0,
|
|
19145
19158
|
type: typeof t,
|
|
19146
|
-
value:
|
|
19159
|
+
value: Cx(t)
|
|
19147
19160
|
}, null, 2);
|
|
19148
19161
|
}
|
|
19149
|
-
return JSON.stringify(
|
|
19162
|
+
return JSON.stringify(wx(), null, 2);
|
|
19150
19163
|
}, {
|
|
19151
19164
|
name: "inspect_env",
|
|
19152
19165
|
description: "读取宿主页面环境信息(排查调试用,默认开启)。不传参 = 返回环境摘要(location 的 URL/origin/path、navigator 的浏览器/语言、viewport 视口尺寸、document 的 title/readyState);传 key = 读取指定 window 属性值(如 inspect_env({key:\"appConfig\"}) 读集成方挂的调试变量 window.appConfig)。用于排查「当前页面在哪/什么浏览器/视口多大/调试变量值是什么」。轻量只读,大结果自动外存 vfs。",
|
|
19153
19166
|
schema: t.object({ key: t.string().optional().describe("要读取的 window 属性名(如 \"appConfig\"/\"__DEBUG__\");不传 = 返回环境摘要") })
|
|
19154
|
-
}),
|
|
19167
|
+
}), Ox = [Dx];
|
|
19155
19168
|
//#endregion
|
|
19156
19169
|
//#region src/core/harness/budget.ts
|
|
19157
|
-
function
|
|
19170
|
+
function kx(e, t, n) {
|
|
19158
19171
|
let r = 0;
|
|
19159
19172
|
return {
|
|
19160
19173
|
name: "budget",
|
|
@@ -19179,12 +19192,12 @@ function Dx(e, t, n) {
|
|
|
19179
19192
|
}
|
|
19180
19193
|
//#endregion
|
|
19181
19194
|
//#region src/core/sdk/actions.ts
|
|
19182
|
-
var
|
|
19183
|
-
function
|
|
19195
|
+
var Ax = /^[a-zA-Z][a-zA-Z0-9_]*$/;
|
|
19196
|
+
function jx(e) {
|
|
19184
19197
|
let n = [];
|
|
19185
19198
|
for (let [i, a] of Object.entries(e)) {
|
|
19186
|
-
if (!
|
|
19187
|
-
console.warn(`[page-agent-sdk][actions] 动作名 "${i}" 非法(须匹配 ${
|
|
19199
|
+
if (!Ax.test(i)) {
|
|
19200
|
+
console.warn(`[page-agent-sdk][actions] 动作名 "${i}" 非法(须匹配 ${Ax}),已跳过`);
|
|
19188
19201
|
continue;
|
|
19189
19202
|
}
|
|
19190
19203
|
let e = a.description || `宿主动作 ${i}`;
|
|
@@ -19204,9 +19217,9 @@ function kx(e) {
|
|
|
19204
19217
|
}
|
|
19205
19218
|
return n;
|
|
19206
19219
|
}
|
|
19207
|
-
function
|
|
19220
|
+
function Mx(e) {
|
|
19208
19221
|
let t = {};
|
|
19209
|
-
for (let [n, r] of Object.entries(e))
|
|
19222
|
+
for (let [n, r] of Object.entries(e)) Ax.test(n) && (t[n] = {
|
|
19210
19223
|
description: r.description,
|
|
19211
19224
|
hasParams: !!r.params
|
|
19212
19225
|
});
|
|
@@ -19214,12 +19227,12 @@ function Ax(e) {
|
|
|
19214
19227
|
}
|
|
19215
19228
|
//#endregion
|
|
19216
19229
|
//#region src/core/toolsets.ts
|
|
19217
|
-
var
|
|
19218
|
-
function
|
|
19219
|
-
return
|
|
19230
|
+
var Nx = hx, Px = xx;
|
|
19231
|
+
function Fx(e, t) {
|
|
19232
|
+
return px(e, t);
|
|
19220
19233
|
}
|
|
19221
|
-
function
|
|
19222
|
-
let a =
|
|
19234
|
+
function Ix(e, t, n, r, i) {
|
|
19235
|
+
let a = cb(e);
|
|
19223
19236
|
return [
|
|
19224
19237
|
...a.dataOps ? t : [],
|
|
19225
19238
|
...a.fetch ? n : [],
|
|
@@ -19228,16 +19241,36 @@ function Px(e, t, n, r, i) {
|
|
|
19228
19241
|
];
|
|
19229
19242
|
}
|
|
19230
19243
|
//#endregion
|
|
19244
|
+
//#region src/core/sdk/toolRegistry.ts
|
|
19245
|
+
function Lx(e) {
|
|
19246
|
+
let t = /* @__PURE__ */ new Map(), n = [];
|
|
19247
|
+
for (let r of e) for (let e of r.tools) {
|
|
19248
|
+
let i = t.get(e.name);
|
|
19249
|
+
i && n.push({
|
|
19250
|
+
name: e.name,
|
|
19251
|
+
winner: r.label,
|
|
19252
|
+
loser: i.label
|
|
19253
|
+
}), t.set(e.name, {
|
|
19254
|
+
tool: e,
|
|
19255
|
+
label: r.label
|
|
19256
|
+
});
|
|
19257
|
+
}
|
|
19258
|
+
return {
|
|
19259
|
+
tools: [...t.values()].map((e) => e.tool),
|
|
19260
|
+
collisions: n
|
|
19261
|
+
};
|
|
19262
|
+
}
|
|
19263
|
+
//#endregion
|
|
19231
19264
|
//#region src/core/harness/usageHints.ts
|
|
19232
|
-
var
|
|
19233
|
-
function
|
|
19234
|
-
let r =
|
|
19265
|
+
var Rx = .7;
|
|
19266
|
+
function zx(e, t, n = "simple") {
|
|
19267
|
+
let r = cb(e), i = n !== "advanced";
|
|
19235
19268
|
return {
|
|
19236
19269
|
name: "usageHints",
|
|
19237
19270
|
augmentPrompt: () => {
|
|
19238
19271
|
let n = [];
|
|
19239
|
-
if (r.planning && (n.push("【自适应规划】按任务复杂度决定是否先规划,不要对简单任务过度编排:"), n.push(" · 简单/明确任务(改单字段、调样式、查值)→ 直接 read/write 执行,不必 write_todos。"), n.push(" · 复杂任务(多步、大改、有歧义、不可逆)→ 先 write_todos 拆解,首个任务标 in_progress,逐项推进。"), n.push(" · 执行中发现步骤要改/补/细分 → 用 update_todo({id, content?, status?}) 按 id 增量改单项,不必重传整个清单。"), n.push(" · 规划出多步方案若需用户拍板 → 先 request_human_confirmation 给方案选项,确认后再执行。"), n.push(" · 规划阶段有轮次预算(maxPlanRevisions,默认 5):勿反复调研/改计划而不执行,规划充分后即开始 write 落地。")), t && (i ? (n.push("读写主数据用 read/write(高层入口,自动乐观锁 + 自动快照)。read({jsonPath}) 读子路径当前值(返回含 hash,write 时自动比对,无需手动传);read() 不传读整个主数据 + 说明。write 改值两姿势:① 改单个字段/子路径用 write({patch:{op:\"set\", jsonPath:\"路径.字段\", value:新值}})——patch.value 就是该字段的新值(类型匹配:string 直传字符串、number 传数字、对象传对象),不要包成 {字段:值} 对象(字段名已在 jsonPath);也兼容 write({value:新值, patch:{op,jsonPath}}) 顶层 value(向后兼容,但优先 patch.value,避免与整体 set 的 value 混淆);② 替换整个对象用 write({value:{整个新对象}})。op:set 设值 / remove 删 / merge 合并对象 / append 追加数组;批量多改动 write({patches:[{op,jsonPath,value},...]});删子路径 write({patch:{jsonPath:\"路径\"}, del:true})。写入自动经 schema 校验(失败不写,按错误提示改值类型/形状后重试)+ 自动存快照(出错可用 restore_data 回退)。"), n.push("修改大对象/数组优先用 write 的 patch 增量(只发改动部分),避免整体重传被 max_tokens 截断致 JSON 不完整。"), n.push("读大数组(read 返回 hasMore=true)用 read({jsonPath,offset,limit}) 分页(offset+=limit 续读,默认 limit=50);一次读多个不相关子路径用 read({jsonPaths:[...]}) 省轮次;复杂 patches 改动先 write({patches,dryRun:true}) 预检(走完整校验不落盘)。"), n.push("查历史快照值(看上一版长啥样 / 冲突诊断 / 用户问\"刚才改了啥\")用 history_data({id?,jsonPath?})(只读不改当前);对比当前与历史快照的差异需切 advanced 用 diff_data(返回结构化 path→from/to)。"), n.push("在大数组里按条件筛选用 query_data(JSONPath,如 $.components[?(@.type==\"card\" && @.price<100)]),返回匹配元素 path/index;定位后用 write patch 改。找名字记不清的元素用 search_data(substring/regex/fuzzy)。批量过滤/映射/聚合/重写大数组用 eval_script(沙箱脚本,mode=query 只读/transform 落地)。")) : (n.push("改主数据前先 get_data({jsonPath}) 读其当前真实值与 hash(返回末尾 hash=xxx),基于真实值改,不要凭记忆。写入(set/edit/delete)时回传 expectedHash=该 hash 启用乐观锁——若主数据在你 get 之后被外部代码/其他 agent/用户手动改过,会触发冲突:集成方若开启人工介入,工具会挂起等用户决定(保留外部/强制覆盖/回退),你应等待工具返回后按结果继续(保留外部→重新 get 再改;强制覆盖→已写入,继续;回退→已回退到历史快照,基于回退值重写);未开启人工介入时返回 VERSION_CONFLICT 不写入,重新 get 拿最新值与 hash 再改。"), n.push("不确定主数据字段结构时用 describe_data 查看说明。"), n.push("修改大对象/数组优先用 edit_data 增量 patch(只发改动部分),避免 set_data 整体重传被 max_tokens 截断导致 JSON 不完整、校验失败。"), n.push("修改主数据出错时可用 restore_data 回退最近一次。"), n.push("在大数组里按条件筛选元素用 query_data(JSONPath,如 $.components[?(@.type==\"card\" && @.price<100)]),返回匹配元素的 path/index;定位后再 edit_data 改。"), n.push("找名字记不清的元素用 search_data(支持 substring/regex/fuzzy 模糊搜索)。"), n.push("需要过滤/映射/聚合/批量重写大数组时用 eval_script(沙箱脚本,入参 data);只读探查用 mode=query,批量重写用 mode=transform(返回值经校验后落地)。"), n.push("读大数组用 read({jsonPath,offset,limit}) 分页(返回 hasMore=true 时 offset+=limit 续读);一次读多个不相关子路径用 read({jsonPaths});复杂改动先 write({...,dryRun:true}) 预检不落盘。"), n.push("对比当前与历史快照(或一段 JSON against)的差异用 diff_data({snapshotId?,against?})(返回结构化 path→from/to,verify 自纠/操作审计/\"刚才改了啥\");只读查历史快照值用 history_data({id?,jsonPath?})。"))), r.subagent && n.push("独立子任务可 spawn_agent 委派(只读工具,过程不占主上下文)。"), r.inspectEnv && n.push("排查页面环境(当前 URL/浏览器/视口/集成方调试变量)用 inspect_env——不传参返回环境摘要(location/navigator/viewport/document),传 key 读特定 window 属性(如 inspect_env({key:\"appConfig\"}) 读 window.appConfig)。改完数据看渲染、定位\"为何没生效\"时用它(只读,不改数据)。"), r.draftWrite && n.push("生成超大 JSON(如 50+ 组件页面,单次 write 受 max_tokens 限制装不下)用 draft_write 分块构建 → draft_commit 原子提交:draft_write({draftId, chunk, mode}) mode:\"start\" 新建/\"append\" 追加(拼 JSON 片段到 drafts 池);累积完 draft_commit({draftId}) 合并 + schema 校验 + 写主数据(失败草稿保留可修后重试,成功自动清草稿)。小改仍用 write patch,只在大 JSON 从零生成时用 draft。"), r.todoDeps && n.push("复杂任务可用 todos 层级依赖:write_todos 时给 todo 传 parentId(父任务 id,表达层级)+ deps(依赖的 todo id 数组,必须先完成)。有依赖的任务,deps 全 completed 后再标 in_progress;完成时 update_todo({id, status:\"completed\", evidence:\"完成证据\"}) 记证据。无依赖关系的任务不传 parentId/deps(扁平)。"), e?.subagents?.length) {
|
|
19240
|
-
let t = e.subagents.filter((e) => (e.temperature ?? 0) >=
|
|
19272
|
+
if (r.planning && (n.push("【自适应规划】按任务复杂度决定是否先规划,不要对简单任务过度编排:"), n.push(" · 简单/明确任务(改单字段、调样式、查值)→ 直接 read/write 执行,不必 write_todos。"), n.push(" · 复杂任务(多步、大改、有歧义、不可逆)→ 先 write_todos 拆解,首个任务标 in_progress,逐项推进。"), n.push(" · 执行中发现步骤要改/补/细分 → 用 update_todo({id, content?, status?}) 按 id 增量改单项,不必重传整个清单。"), n.push(" · 规划出多步方案若需用户拍板 → 先 request_human_confirmation 给方案选项,确认后再执行。"), n.push(" · 规划阶段有轮次预算(maxPlanRevisions,默认 5):勿反复调研/改计划而不执行,规划充分后即开始 write 落地。")), t && (i ? (n.push("读写主数据用 read/write(高层入口,自动乐观锁 + 自动快照)。read({jsonPath}) 读子路径当前值(返回含 hash,write 时自动比对,无需手动传);read() 不传读整个主数据 + 说明。write 改值两姿势:① 改单个字段/子路径用 write({patch:{op:\"set\", jsonPath:\"路径.字段\", value:新值}})——patch.value 就是该字段的新值(类型匹配:string 直传字符串、number 传数字、对象传对象),不要包成 {字段:值} 对象(字段名已在 jsonPath);也兼容 write({value:新值, patch:{op,jsonPath}}) 顶层 value(向后兼容,但优先 patch.value,避免与整体 set 的 value 混淆);② 替换整个对象用 write({value:{整个新对象}})。op:set 设值 / remove 删 / merge 合并对象 / append 追加数组;批量多改动 write({patches:[{op,jsonPath,value},...]});删子路径 write({patch:{jsonPath:\"路径\"}, del:true})。写入自动经 schema 校验(失败不写,按错误提示改值类型/形状后重试)+ 自动存快照(出错可用 restore_data 回退)。"), n.push("修改大对象/数组优先用 write 的 patch 增量(只发改动部分),避免整体重传被 max_tokens 截断致 JSON 不完整。"), n.push("读大数组(read 返回 hasMore=true)用 read({jsonPath,offset,limit}) 分页(offset+=limit 续读,默认 limit=50);一次读多个不相关子路径用 read({jsonPaths:[...]}) 省轮次;复杂 patches 改动先 write({patches,dryRun:true}) 预检(走完整校验不落盘)。"), n.push("查历史快照值(看上一版长啥样 / 冲突诊断 / 用户问\"刚才改了啥\")用 history_data({id?,jsonPath?})(只读不改当前);对比当前与历史快照的差异需切 advanced 用 diff_data(返回结构化 path→from/to)。"), n.push("在大数组里按条件筛选用 query_data(JSONPath,如 $.components[?(@.type==\"card\" && @.price<100)]),返回匹配元素 path/index;定位后用 write patch 改。找名字记不清的元素用 search_data(substring/regex/fuzzy)。批量过滤/映射/聚合/重写大数组用 eval_script(沙箱脚本,mode=query 只读/transform 落地)。")) : (n.push("改主数据前先 get_data({jsonPath}) 读其当前真实值与 hash(返回末尾 hash=xxx),基于真实值改,不要凭记忆。写入(set/edit/delete)时回传 expectedHash=该 hash 启用乐观锁——若主数据在你 get 之后被外部代码/其他 agent/用户手动改过,会触发冲突:集成方若开启人工介入,工具会挂起等用户决定(保留外部/强制覆盖/回退),你应等待工具返回后按结果继续(保留外部→重新 get 再改;强制覆盖→已写入,继续;回退→已回退到历史快照,基于回退值重写);未开启人工介入时返回 VERSION_CONFLICT 不写入,重新 get 拿最新值与 hash 再改。"), n.push("不确定主数据字段结构时用 describe_data 查看说明。"), n.push("修改大对象/数组优先用 edit_data 增量 patch(只发改动部分),避免 set_data 整体重传被 max_tokens 截断导致 JSON 不完整、校验失败。"), n.push("修改主数据出错时可用 restore_data 回退最近一次。"), n.push("在大数组里按条件筛选元素用 query_data(JSONPath,如 $.components[?(@.type==\"card\" && @.price<100)]),返回匹配元素的 path/index;定位后再 edit_data 改。"), n.push("找名字记不清的元素用 search_data(支持 substring/regex/fuzzy 模糊搜索)。"), n.push("需要过滤/映射/聚合/批量重写大数组时用 eval_script(沙箱脚本,入参 data);只读探查用 mode=query,批量重写用 mode=transform(返回值经校验后落地)。"), n.push("读大数组用 read({jsonPath,offset,limit}) 分页(返回 hasMore=true 时 offset+=limit 续读);一次读多个不相关子路径用 read({jsonPaths});复杂改动先 write({...,dryRun:true}) 预检不落盘。"), n.push("对比当前与历史快照(或一段 JSON against)的差异用 diff_data({snapshotId?,against?})(返回结构化 path→from/to,verify 自纠/操作审计/\"刚才改了啥\");只读查历史快照值用 history_data({id?,jsonPath?})。"))), r.subagent && n.push("独立子任务可 spawn_agent 委派(只读工具,过程不占主上下文)。"), r.inspectEnv && n.push("排查页面环境(当前 URL/浏览器/视口/集成方调试变量)用 inspect_env——不传参返回环境摘要(location/navigator/viewport/document),传 key 读特定 window 属性(如 inspect_env({key:\"appConfig\"}) 读 window.appConfig)。改完数据看渲染、定位\"为何没生效\"时用它(只读,不改数据)。"), r.draftWrite && n.push("生成超大 JSON(如 50+ 组件页面,单次 write 受 max_tokens 限制装不下)用 draft_write 分块构建 → draft_commit 原子提交:draft_write({draftId, chunk, mode}) mode:\"start\" 新建/\"append\" 追加(拼 JSON 片段到 drafts 池);累积完 draft_commit({draftId}) 合并 + schema 校验 + 写主数据(失败草稿保留可修后重试,成功自动清草稿)。小改仍用 write patch,只在大 JSON 从零生成时用 draft。"), r.draftWrite && n.push("⚠️ 大 JSON 分块构建是典型多轮工具调用(draft_write×N + draft_commit + read 确认 + 调研 read/query),默认 maxToolRounds=10 可能触顶被 while 截断导致草稿写不完;目标组件数大时集成方应在 createChatSdk 配 maxToolRounds ≥ 20(或按 N+5 估算)。draft_commit 提交同样走乐观锁(改前 read 拿 hash,bind 被改过会触发冲突介入,不静默覆盖)。"), r.todoDeps && n.push("复杂任务可用 todos 层级依赖:write_todos 时给 todo 传 parentId(父任务 id,表达层级)+ deps(依赖的 todo id 数组,必须先完成)。有依赖的任务,deps 全 completed 后再标 in_progress;完成时 update_todo({id, status:\"completed\", evidence:\"完成证据\"}) 记证据。无依赖关系的任务不传 parentId/deps(扁平)。"), e?.subagents?.length) {
|
|
19273
|
+
let t = e.subagents.filter((e) => (e.temperature ?? 0) >= Rx || /规划|创意|设计|方案|brainstorm|plan/i.test(e.description)), r = e.subagents.filter((e) => (e.temperature ?? 0) < Rx && /反思|审查|挑刺|校验|review|critique|reflect/i.test(e.description));
|
|
19241
19274
|
n.push("【规划-反思-执行·路由】按任务性质选模式,不要对简单任务过度编排:"), t.length && (n.push(` · 创作/设计/开放性需求(如"设计主题风格""换个感觉")→ 先调 ${t.map((e) => "use_" + e.id).join("/")} 出 2-3 套方案(高温创意),`), n.push(" 不要自己拍板;拿到方案后,若需用户拍板用 request_human_confirmation 弹选项。")), r.length && n.push(` · 严谨/易错/校验类 → 可先调 ${r.map((e) => "use_" + e.id).join("/")} 反思挑刺(低温审查),据反馈修订。`), n.push(i ? " · 方案定稿后,由你(主 agent)用 write 落地成 JSON(低温度执行 + schema 校验 + 写前确认)。" : " · 方案定稿后,由你(主 agent)用 edit_data 落地成 JSON(低温度执行 + schema 校验 + 写前确认)。"), n.push(" · 简单/明确任务(如\"标题改红色\")直接执行,不必走规划-反思。");
|
|
19242
19275
|
}
|
|
19243
19276
|
return e?.humanConfirm && (n.push("【人工确认·必读】以下情形必须先调 request_human_confirmation 征询用户、拿到答复后再继续,不要自行拍板:"), n.push(" 1) 用户让你「给方案/列选项/我来选/挑一个」时:把每个方案作为一个 option,调 request_human_confirmation(question=简述, options=[方案A,方案B,...], recommendation=你推荐的)。不要只回文字罗列方案让用户自己回复——要用工具把选项做成可点选按钮。"), n.push(" 2) 需求有歧义/不确定时:调工具问清楚(options 不传则用户答同意或拒绝)。"), n.push(" 3) 即将执行高风险不可逆操作(删除/覆盖/批量改动)前:调工具确认。"), n.push(" 4) 规划出多步方案需用户确认时:把整个方案(或关键分步)作为 option 调 request_human_confirmation,确认后再执行。"), n.push("用户在选项里选了哪个,就按那个方案继续;选「拒绝」则停止并询问如何调整。")), n.length && n.unshift("调用工具务必用标准 function calling(工具调用)格式发起,不要在回复正文里输出伪 XML/标签(如 deepseek 的 tool_calls 标签、invoke、function_call、tool_call 等)或 JSON 文本——那不会被识别为工具调用,会被当普通文字,工具不执行。"), n.length ? "## 能力使用提示\n" + n.join("\n") : void 0;
|
|
@@ -19246,72 +19279,72 @@ function Ix(e, t, n = "simple") {
|
|
|
19246
19279
|
}
|
|
19247
19280
|
//#endregion
|
|
19248
19281
|
//#region src/core/backends/skillStore.ts
|
|
19249
|
-
var
|
|
19250
|
-
function
|
|
19251
|
-
return `${
|
|
19282
|
+
var Bx = "v:1::skill-store", Vx = "chat-sdk";
|
|
19283
|
+
function Hx(e, t, n) {
|
|
19284
|
+
return `${Bx}::${e}::${t}::${n}`;
|
|
19252
19285
|
}
|
|
19253
|
-
function
|
|
19254
|
-
return `${
|
|
19286
|
+
function Ux(e, t) {
|
|
19287
|
+
return `${Bx}::${e}::${t}::`;
|
|
19255
19288
|
}
|
|
19256
|
-
function
|
|
19257
|
-
let t = e.dbName ??
|
|
19289
|
+
function Wx(e = {}) {
|
|
19290
|
+
let t = e.dbName ?? Vx, n = e.backend ?? "indexed", r = e.id ?? "", i, a, o = new Promise((e) => {
|
|
19258
19291
|
a = e;
|
|
19259
19292
|
});
|
|
19260
19293
|
return (async () => {
|
|
19261
19294
|
try {
|
|
19262
19295
|
if (n === "indexed") {
|
|
19263
19296
|
if (typeof indexedDB > "u") throw Error("indexedDB 不可用");
|
|
19264
|
-
i = await
|
|
19297
|
+
i = await tb(t), a(!0);
|
|
19265
19298
|
} else if (n === "session") {
|
|
19266
19299
|
if (typeof sessionStorage > "u") throw Error("sessionStorage 不可用");
|
|
19267
|
-
i =
|
|
19300
|
+
i = nb(sessionStorage), a(!0);
|
|
19268
19301
|
} else if (n === "local") {
|
|
19269
19302
|
if (typeof localStorage > "u") throw Error("localStorage 不可用");
|
|
19270
|
-
i =
|
|
19271
|
-
} else i =
|
|
19303
|
+
i = nb(localStorage), a(!0);
|
|
19304
|
+
} else i = eb(), a(!1);
|
|
19272
19305
|
} catch {
|
|
19273
|
-
i =
|
|
19306
|
+
i = eb(), a(!1);
|
|
19274
19307
|
}
|
|
19275
19308
|
})(), {
|
|
19276
19309
|
ready: o,
|
|
19277
19310
|
async list() {
|
|
19278
19311
|
let e = [];
|
|
19279
|
-
return await i.scan(
|
|
19312
|
+
return await i.scan(Ux(t, r), (t, n) => {
|
|
19280
19313
|
e.push(n);
|
|
19281
19314
|
}), e;
|
|
19282
19315
|
},
|
|
19283
19316
|
async get(e) {
|
|
19284
|
-
return await i.get(
|
|
19317
|
+
return await i.get(Hx(t, r, e));
|
|
19285
19318
|
},
|
|
19286
19319
|
async put(e) {
|
|
19287
19320
|
try {
|
|
19288
|
-
await i.set(
|
|
19321
|
+
await i.set(Hx(t, r, e.name), e);
|
|
19289
19322
|
} catch (e) {
|
|
19290
|
-
|
|
19323
|
+
Ky(e) && (i = eb());
|
|
19291
19324
|
}
|
|
19292
19325
|
},
|
|
19293
19326
|
async remove(e) {
|
|
19294
|
-
let n =
|
|
19327
|
+
let n = Hx(t, r, e);
|
|
19295
19328
|
return await i.get(n) != null && (await i.del(n), !0);
|
|
19296
19329
|
},
|
|
19297
19330
|
async clear() {
|
|
19298
|
-
await i.clearPrefix(
|
|
19331
|
+
await i.clearPrefix(Ux(t, r));
|
|
19299
19332
|
},
|
|
19300
19333
|
dispose() {}
|
|
19301
19334
|
};
|
|
19302
19335
|
}
|
|
19303
19336
|
//#endregion
|
|
19304
19337
|
//#region src/core/sdk/createChatSdk.ts
|
|
19305
|
-
var
|
|
19306
|
-
function
|
|
19338
|
+
var Gx = 50, Kx = /* @__PURE__ */ new Map();
|
|
19339
|
+
function qx(e, t) {
|
|
19307
19340
|
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;
|
|
19308
19341
|
}
|
|
19309
|
-
function
|
|
19342
|
+
function Jx(e, t, n, r) {
|
|
19310
19343
|
let i = 0;
|
|
19311
19344
|
return {
|
|
19312
19345
|
name: "sdk-events",
|
|
19313
19346
|
wrapToolCall: async (t, r) => {
|
|
19314
|
-
let i = await r(t), a =
|
|
19347
|
+
let i = await r(t), a = qx(t.name, t.args);
|
|
19315
19348
|
return a && e({
|
|
19316
19349
|
type: "data_change",
|
|
19317
19350
|
operation: a,
|
|
@@ -19346,29 +19379,29 @@ function Gx(e, t, n, r) {
|
|
|
19346
19379
|
}
|
|
19347
19380
|
};
|
|
19348
19381
|
}
|
|
19349
|
-
function
|
|
19382
|
+
function Yx(e, i) {
|
|
19350
19383
|
let a = {
|
|
19351
19384
|
prompt_tokens: 0,
|
|
19352
19385
|
completion_tokens: 0,
|
|
19353
19386
|
total_tokens: 0
|
|
19354
|
-
}, o =
|
|
19387
|
+
}, o = Ny(() => Oe), s = /* @__PURE__ */ U(0), c = ab(e.storage);
|
|
19355
19388
|
e.debug && c && c.onEvent((e) => console.log("[page-agent-sdk][storage]", e));
|
|
19356
|
-
let { modelCaps: l, summaryLlmInvoke: u } =
|
|
19389
|
+
let { modelCaps: l, summaryLlmInvoke: u } = My(e), d = l;
|
|
19357
19390
|
e.debug && console.log("[page-agent-sdk][modelCaps]", d);
|
|
19358
19391
|
let f = e.llm;
|
|
19359
19392
|
e.debug && !u && console.warn("[page-agent-sdk][summarization] 未构造 llmInvoke(apiKey 缺失?),摘要回退零成本索引摘要");
|
|
19360
|
-
let p = /* @__PURE__ */ tn([]), m =
|
|
19393
|
+
let p = /* @__PURE__ */ tn([]), m = Ib(e.vfs?.initialFiles, {
|
|
19361
19394
|
persist: c ? { save: (e) => {
|
|
19362
19395
|
B.sessionId && c && c.save(i, B.sessionId, { vfs: e });
|
|
19363
19396
|
} } : void 0,
|
|
19364
19397
|
maxBytes: e.vfs?.maxBytes,
|
|
19365
19398
|
poolBytes: e.vfs?.poolBytes
|
|
19366
|
-
}), h =
|
|
19399
|
+
}), h = D_([], { maxPlanRevisions: e.maxPlanRevisions }), g = j_(), _ = P_(), v = H_(e.memory || "");
|
|
19367
19400
|
typeof e.memory == "function" && v.refresh();
|
|
19368
19401
|
let y = { current: null }, b = e.data ? {
|
|
19369
19402
|
...e.data,
|
|
19370
19403
|
description: e.data.description ?? "主数据对象"
|
|
19371
|
-
} : void 0, x = e.checkpoint, S = x !== void 0 && x !== !1, C = S ?
|
|
19404
|
+
} : void 0, x = e.checkpoint, S = x !== void 0 && x !== !1, C = S ? ov({
|
|
19372
19405
|
getData: () => N()?.bind,
|
|
19373
19406
|
consumeDataDirty: () => ee?.consumeDataDirty?.() ?? !0,
|
|
19374
19407
|
slotPaths: b ? [""] : [],
|
|
@@ -19377,21 +19410,21 @@ function Kx(e, i) {
|
|
|
19377
19410
|
getTodos: () => y.current?.getState?.()?.todos ?? [],
|
|
19378
19411
|
messages: p,
|
|
19379
19412
|
maxCheckpoints: x && typeof x == "object" ? x.maxCheckpoints : void 0
|
|
19380
|
-
}) : null, w = !x || typeof x != "object" || x.auto !== !1, T =
|
|
19413
|
+
}) : null, w = !x || typeof x != "object" || x.auto !== !1, T = cb(e.capabilities), E = T.dataOps, D = T.draftWrite, O = T.tracing, k = T.automation, A = Oy(e), j = E && b ? px(b, {
|
|
19381
19414
|
onAudit: e.onAudit ?? (e.debug ? (e) => console.log("[page-agent-sdk][data audit]", e) : void 0),
|
|
19382
19415
|
maxSnapshots: e.maxSnapshots,
|
|
19383
19416
|
onConflict: o.set,
|
|
19384
19417
|
autoLock: e.autoLock,
|
|
19385
19418
|
interceptors: e.interceptors,
|
|
19386
19419
|
vfsStore: D ? m : void 0
|
|
19387
|
-
}) : [], M = E ?
|
|
19420
|
+
}) : [], M = E ? ux(j, e.toolMode) : [], ee = E && b ? j.controller ?? null : null, N = () => ee?.get() ?? b, P = /* @__PURE__ */ new Map(), F = Ix(T, M, hx, xx, Ox);
|
|
19388
19421
|
F.forEach((e) => P.set(e.name, "builtin"));
|
|
19389
19422
|
let I = [...e.tools || []];
|
|
19390
19423
|
I.forEach((e) => P.set(e.name, "user"));
|
|
19391
|
-
let te =
|
|
19424
|
+
let te = jx(e.actions ?? {});
|
|
19392
19425
|
te.forEach((e) => P.set(e.name, "action"));
|
|
19393
|
-
let L = [], R = e.humanConfirm !== !1 && (!e.approval || e.approval.humanConfirmTool !== !1), ne = R ?
|
|
19394
|
-
ne && P.set(
|
|
19426
|
+
let L = [], R = e.humanConfirm !== !1 && (!e.approval || e.approval.humanConfirmTool !== !1), ne = R ? Q_() : null;
|
|
19427
|
+
ne && P.set(X_, "builtin");
|
|
19395
19428
|
let re = S && C ? [r(async () => {
|
|
19396
19429
|
let e = C.list();
|
|
19397
19430
|
return e.length ? C.restore() ? `已回退到最近一次正常状态(checkpoint #${e[e.length - 1].id})。对话历史、主数据、vfs、todos 已整体还原。请基于回退后的状态重新判断并继续。` : "回退失败:无可用 checkpoint。" : "无可用 checkpoint,无法回退。";
|
|
@@ -19408,29 +19441,42 @@ function Kx(e, i) {
|
|
|
19408
19441
|
schema: t.object({}).optional()
|
|
19409
19442
|
})] : [];
|
|
19410
19443
|
re.forEach((e) => P.set(e.name, "builtin"));
|
|
19411
|
-
let z =
|
|
19412
|
-
...F,
|
|
19413
|
-
...I,
|
|
19414
|
-
...te,
|
|
19415
|
-
...ne ? [ne] : [],
|
|
19416
|
-
...re
|
|
19417
|
-
];
|
|
19444
|
+
let z = ie();
|
|
19418
19445
|
function ie() {
|
|
19419
|
-
|
|
19420
|
-
|
|
19421
|
-
|
|
19422
|
-
|
|
19423
|
-
|
|
19424
|
-
|
|
19425
|
-
|
|
19426
|
-
|
|
19446
|
+
let { tools: e, collisions: t } = Lx([
|
|
19447
|
+
{
|
|
19448
|
+
label: "builtin",
|
|
19449
|
+
tools: F
|
|
19450
|
+
},
|
|
19451
|
+
{
|
|
19452
|
+
label: "user",
|
|
19453
|
+
tools: I
|
|
19454
|
+
},
|
|
19455
|
+
{
|
|
19456
|
+
label: "action",
|
|
19457
|
+
tools: te
|
|
19458
|
+
},
|
|
19459
|
+
{
|
|
19460
|
+
label: "humanConfirm",
|
|
19461
|
+
tools: ne ? [ne] : []
|
|
19462
|
+
},
|
|
19463
|
+
{
|
|
19464
|
+
label: "checkpoint",
|
|
19465
|
+
tools: re
|
|
19466
|
+
},
|
|
19467
|
+
{
|
|
19468
|
+
label: "mcp",
|
|
19469
|
+
tools: L
|
|
19470
|
+
}
|
|
19471
|
+
]);
|
|
19472
|
+
return t.length && console.warn("[page-agent-sdk] 工具重名,后注册覆盖先注册:", t.map((e) => `${e.name}(${e.loser}→${e.winner})`).join(", ")), e;
|
|
19427
19473
|
}
|
|
19428
19474
|
let ae = T.planning, oe = T.missionAnchor, se = T.workingMemory, ce = T.skills, le = T.vfs;
|
|
19429
|
-
if (le) for (let e of
|
|
19475
|
+
if (le) for (let e of Ub) P.set(e, "builtin");
|
|
19430
19476
|
if (ae) for (let e of h.tools ?? []) P.set(e.name, "builtin");
|
|
19431
19477
|
let ue = T.summarization, de = T.memory, fe = T.subagent, pe = e.verify?.maxAttempts ?? 2, me = T.verify && e.verify?.enabled !== !1 && pe > 0;
|
|
19432
19478
|
e.verify?.check && !T.verify && console.warn("[page-agent-sdk][verify] 检测到 verify.check 但 capabilities.verify 未开启,verify 未装载");
|
|
19433
|
-
let he = e.subagent, ge = he?.allowedTools ?? [], _e = !fe || he?.enabled === !1 ? void 0 :
|
|
19479
|
+
let he = e.subagent, ge = he?.allowedTools ?? [], _e = !fe || he?.enabled === !1 ? void 0 : yv({
|
|
19434
19480
|
llm: he?.llm ?? e.llm,
|
|
19435
19481
|
allTools: z,
|
|
19436
19482
|
allowedTools: ge.length ? ge : void 0,
|
|
@@ -19441,7 +19487,7 @@ function Kx(e, i) {
|
|
|
19441
19487
|
maxDepth: he?.maxDepth,
|
|
19442
19488
|
maxParallel: he?.maxParallel,
|
|
19443
19489
|
debug: e.debug
|
|
19444
|
-
}), ve = fe && e.subagents !== void 0 ?
|
|
19490
|
+
}), ve = fe && e.subagents !== void 0 ? Sv(e.subagents, {
|
|
19445
19491
|
llm: e.llm,
|
|
19446
19492
|
allTools: z,
|
|
19447
19493
|
debug: e.debug
|
|
@@ -19450,8 +19496,8 @@ function Kx(e, i) {
|
|
|
19450
19496
|
"describe_data",
|
|
19451
19497
|
"read",
|
|
19452
19498
|
"fetch_document"
|
|
19453
|
-
], xe = z.filter((e) => be.includes(e.name)), Se = me ?
|
|
19454
|
-
check: e.verify.check ??
|
|
19499
|
+
], xe = z.filter((e) => be.includes(e.name)), Se = me ? Cv({
|
|
19500
|
+
check: e.verify.check ?? kv({
|
|
19455
19501
|
schemas: () => N() ? { "": N().schema } : {},
|
|
19456
19502
|
root: () => N()?.bind
|
|
19457
19503
|
}),
|
|
@@ -19459,7 +19505,7 @@ function Kx(e, i) {
|
|
|
19459
19505
|
llm: e.llm,
|
|
19460
19506
|
tools: xe
|
|
19461
19507
|
} : void 0
|
|
19462
|
-
}) : void 0, Ce =
|
|
19508
|
+
}) : void 0, Ce = zx({
|
|
19463
19509
|
...T,
|
|
19464
19510
|
humanConfirm: R,
|
|
19465
19511
|
subagents: e.subagents?.map((e) => ({
|
|
@@ -19469,7 +19515,7 @@ function Kx(e, i) {
|
|
|
19469
19515
|
}))
|
|
19470
19516
|
}, E && !!b, e.toolMode), we = b ? {
|
|
19471
19517
|
name: "dataHint",
|
|
19472
|
-
augmentPrompt: () =>
|
|
19518
|
+
augmentPrompt: () => Dy(N(), e.schemaHint) || void 0
|
|
19473
19519
|
} : null, Te = e.augmentSystem ? {
|
|
19474
19520
|
name: "augmentSystem",
|
|
19475
19521
|
augmentPrompt: (t) => {
|
|
@@ -19483,7 +19529,7 @@ function Kx(e, i) {
|
|
|
19483
19529
|
return;
|
|
19484
19530
|
}
|
|
19485
19531
|
}
|
|
19486
|
-
} : null, Ee = e.onEvent, De =
|
|
19532
|
+
} : null, Ee = e.onEvent, De = lb(e.onEvent), Oe = De.emit, ke, Ae = [], je = (e) => ({
|
|
19487
19533
|
name: e.name,
|
|
19488
19534
|
description: e.description,
|
|
19489
19535
|
content: typeof e.getContent == "function" ? e.getContent() : ""
|
|
@@ -19491,7 +19537,7 @@ function Kx(e, i) {
|
|
|
19491
19537
|
name: e.name,
|
|
19492
19538
|
description: e.description,
|
|
19493
19539
|
getContent: () => e.content
|
|
19494
|
-
}), Ne = e.skillStorage === !1 ? null :
|
|
19540
|
+
}), Ne = e.skillStorage === !1 ? null : Wx({
|
|
19495
19541
|
...typeof e.skillStorage == "object" ? e.skillStorage : {},
|
|
19496
19542
|
id: e.skillStorage && typeof e.skillStorage == "object" && e.skillStorage.id ? e.skillStorage.id : `agent::${i}`
|
|
19497
19543
|
}), Pe = () => {
|
|
@@ -19514,36 +19560,36 @@ function Kx(e, i) {
|
|
|
19514
19560
|
B.infoTick.value++;
|
|
19515
19561
|
}
|
|
19516
19562
|
} catch {}
|
|
19517
|
-
}, Ie =
|
|
19563
|
+
}, Ie = mb([
|
|
19518
19564
|
...we ? [we] : [],
|
|
19519
19565
|
Ce,
|
|
19520
19566
|
...oe ? [g] : [],
|
|
19521
19567
|
...ae ? [h] : [],
|
|
19522
|
-
...ce ? [ke =
|
|
19523
|
-
...le ? [
|
|
19524
|
-
...ue ? [
|
|
19525
|
-
...
|
|
19568
|
+
...ce ? [ke = V_(e.skills || [], { readVfs: le ? (e) => m.files[e]?.content : void 0 })] : [],
|
|
19569
|
+
...le ? [Gb(m)] : [],
|
|
19570
|
+
...ue ? [ty({
|
|
19571
|
+
...fb(e, d.contextWindow),
|
|
19526
19572
|
llmInvoke: u,
|
|
19527
19573
|
getRegisteredData: () => N() ? [{ description: N().description ?? "主数据对象" }] : [],
|
|
19528
|
-
preserveLastToolResults: (e.contextOptions && e.contextOptions.preserveLastToolResults) ??
|
|
19574
|
+
preserveLastToolResults: (e.contextOptions && e.contextOptions.preserveLastToolResults) ?? db[e.contextPreset ?? "auto"]
|
|
19529
19575
|
})] : [],
|
|
19530
19576
|
...se ? [_] : [],
|
|
19531
19577
|
...de ? [v] : [],
|
|
19532
|
-
...e.permissions?.length ? [
|
|
19533
|
-
...S && w && C ? [
|
|
19534
|
-
...R ? [
|
|
19535
|
-
...e.approval && (e.approval.tools !== void 0 || e.approval.confirm) ? [
|
|
19578
|
+
...e.permissions?.length ? [J_(e.permissions)] : [],
|
|
19579
|
+
...S && w && C ? [sv(C)] : [],
|
|
19580
|
+
...R ? [$_()] : [],
|
|
19581
|
+
...e.approval && (e.approval.tools !== void 0 || e.approval.confirm) ? [Y_(e.approval)] : [],
|
|
19536
19582
|
...Se ? [Se] : [],
|
|
19537
19583
|
..._e ? [_e] : [],
|
|
19538
19584
|
...ve ? [ve] : [],
|
|
19539
19585
|
...Te ? [Te] : [],
|
|
19540
19586
|
...e.middleware || [],
|
|
19541
|
-
...k ? [
|
|
19587
|
+
...k ? [kx(a, {
|
|
19542
19588
|
tokenBudget: e.tokenBudget,
|
|
19543
19589
|
timeBudgetMs: e.timeBudgetMs
|
|
19544
19590
|
}, Oe)] : [],
|
|
19545
|
-
|
|
19546
|
-
]), Le = e.maxMemoryRounds ??
|
|
19591
|
+
Jx(Oe, p, N, a)
|
|
19592
|
+
]), Le = e.maxMemoryRounds ?? Gx, B = {
|
|
19547
19593
|
agentId: i,
|
|
19548
19594
|
store: c,
|
|
19549
19595
|
messages: p,
|
|
@@ -19721,7 +19767,7 @@ function Kx(e, i) {
|
|
|
19721
19767
|
if (B.refCount--, B.refCount <= 0) {
|
|
19722
19768
|
c && (m.flush?.(), c.flush(), c.dispose()), Ne && Ne.dispose();
|
|
19723
19769
|
let e = B.mcpClosers.splice(0);
|
|
19724
|
-
e.length && Promise.allSettled(e.map((e) => e())),
|
|
19770
|
+
e.length && Promise.allSettled(e.map((e) => e())), Kx.delete(i);
|
|
19725
19771
|
}
|
|
19726
19772
|
},
|
|
19727
19773
|
resolveConflict: o.resolve,
|
|
@@ -19731,14 +19777,16 @@ function Kx(e, i) {
|
|
|
19731
19777
|
}), z = ie(), B.agent && B.agent.setTools(z), B.infoTick.value++;
|
|
19732
19778
|
},
|
|
19733
19779
|
addTool(e) {
|
|
19734
|
-
|
|
19780
|
+
z.some((t) => t.name === e.name) && console.warn(`[page-agent-sdk] 工具 "${e.name}" 已存在,新工具覆盖(后注册覆盖先注册)`);
|
|
19781
|
+
for (let t = I.length - 1; t >= 0; t--) I[t].name === e.name && I.splice(t, 1);
|
|
19782
|
+
I.push(e), P.set(e.name, "user"), z = ie(), B.agent && B.agent.setTools(z), B.infoTick.value++;
|
|
19735
19783
|
},
|
|
19736
19784
|
removeTool(e) {
|
|
19737
19785
|
let t = I.findIndex((t) => t.name === e);
|
|
19738
|
-
return t < 0 ? !1 : (I.splice(t, 1), z = ie(), B.agent && B.agent.setTools(z), B.infoTick.value++, !0);
|
|
19786
|
+
return t < 0 ? !1 : (I.splice(t, 1), P.delete(e), z = ie(), B.agent && B.agent.setTools(z), B.infoTick.value++, !0);
|
|
19739
19787
|
},
|
|
19740
19788
|
setLlm(t) {
|
|
19741
|
-
let r =
|
|
19789
|
+
let r = ky(t) ? t : new n({
|
|
19742
19790
|
apiKey: t.apiKey,
|
|
19743
19791
|
model: t.model,
|
|
19744
19792
|
temperature: t.temperature,
|
|
@@ -19779,8 +19827,8 @@ function Kx(e, i) {
|
|
|
19779
19827
|
getInfo() {
|
|
19780
19828
|
return {
|
|
19781
19829
|
id: i,
|
|
19782
|
-
model:
|
|
19783
|
-
systemPrompt: B.agent?.getEffectiveSystemPrompt?.() ?? A +
|
|
19830
|
+
model: ky(f) ? f.model ?? f.modelName : f.model,
|
|
19831
|
+
systemPrompt: B.agent?.getEffectiveSystemPrompt?.() ?? A + Dy(N(), e.schemaHint),
|
|
19784
19832
|
tools: (B.agent?.allTools ?? z).map((e) => ({
|
|
19785
19833
|
name: e.name,
|
|
19786
19834
|
description: e.description,
|
|
@@ -19814,7 +19862,7 @@ function Kx(e, i) {
|
|
|
19814
19862
|
spans: B.agent.spans.value,
|
|
19815
19863
|
metrics: r_(B.agent.spans.value)
|
|
19816
19864
|
} : void 0,
|
|
19817
|
-
actions:
|
|
19865
|
+
actions: Mx(e.actions ?? {}),
|
|
19818
19866
|
subagent: {
|
|
19819
19867
|
enabled: !!_e,
|
|
19820
19868
|
maxDepth: e.subagent?.maxDepth ?? 1,
|
|
@@ -19877,7 +19925,7 @@ function Kx(e, i) {
|
|
|
19877
19925
|
await Fe();
|
|
19878
19926
|
}
|
|
19879
19927
|
function Be() {
|
|
19880
|
-
let e =
|
|
19928
|
+
let e = Kv(p, Le);
|
|
19881
19929
|
e.trimmed && p.splice(e.deleteFrom, e.deleteCount, e.summary);
|
|
19882
19930
|
}
|
|
19883
19931
|
function Ve() {
|
|
@@ -19889,7 +19937,7 @@ function Kx(e, i) {
|
|
|
19889
19937
|
}
|
|
19890
19938
|
return B.initDone = (async () => {
|
|
19891
19939
|
if (await Re(), await ze(), e.mcp?.length) {
|
|
19892
|
-
let t = await Promise.allSettled(e.mcp.map((e) =>
|
|
19940
|
+
let t = await Promise.allSettled(e.mcp.map((e) => zv(e)));
|
|
19893
19941
|
B.mcpClosers = t.flatMap((e) => e.status === "fulfilled" ? [e.value.close] : []), B.mcpServers = [];
|
|
19894
19942
|
let n = [];
|
|
19895
19943
|
t.forEach((t, r) => {
|
|
@@ -19901,8 +19949,8 @@ function Kx(e, i) {
|
|
|
19901
19949
|
}), t.value.tools.forEach((e) => P.set(e.name, `mcp:${a}`)), n.push(...t.value.tools)) : console.warn(`[page-agent-sdk][mcp] server ${a} 连接失败:`, t.reason);
|
|
19902
19950
|
}), z = ie(), e.debug && console.log(`[page-agent-sdk][mcp] 注入 ${n.length} 个工具,${B.mcpServers.length} 个 server`);
|
|
19903
19951
|
}
|
|
19904
|
-
B.agent =
|
|
19905
|
-
...
|
|
19952
|
+
B.agent = C_({
|
|
19953
|
+
...ky(e.llm) ? { llm: e.llm } : {
|
|
19906
19954
|
apiKey: e.llm.apiKey,
|
|
19907
19955
|
baseUrl: e.llm.baseUrl,
|
|
19908
19956
|
model: e.llm.model,
|
|
@@ -19921,7 +19969,7 @@ function Kx(e, i) {
|
|
|
19921
19969
|
maxOutputTokens: d.maxOutputTokens,
|
|
19922
19970
|
maxVerifyAttempts: me ? pe : 0,
|
|
19923
19971
|
onLlmChange: (t) => {
|
|
19924
|
-
let n =
|
|
19972
|
+
let n = ky(t) ? void 0 : t;
|
|
19925
19973
|
d = $g({
|
|
19926
19974
|
model: n?.model ?? t.model ?? t.modelName,
|
|
19927
19975
|
contextWindow: e.contextWindow ?? n?.contextWindow,
|
|
@@ -19943,12 +19991,12 @@ function Kx(e, i) {
|
|
|
19943
19991
|
});
|
|
19944
19992
|
})(), B;
|
|
19945
19993
|
}
|
|
19946
|
-
function
|
|
19947
|
-
let t = e.id ??
|
|
19994
|
+
function Xx(e) {
|
|
19995
|
+
let t = e.id ?? Py();
|
|
19948
19996
|
e.id || console.warn(`[page-agent-sdk] 未传 options.id,已生成随机 id "${t}"。刷新后持久化数据无法恢复,请传稳定 id。`);
|
|
19949
|
-
let n = e.streaming ?? !0, r = e.ui ?? "default", i, a = e.shareContext ?
|
|
19950
|
-
a ? i = a : (i =
|
|
19951
|
-
let o = null, s = null, c =
|
|
19997
|
+
let n = e.streaming ?? !0, r = e.ui ?? "default", i, a = e.shareContext ? Kx.get(t) : void 0;
|
|
19998
|
+
a ? i = a : (i = Yx(e, t), e.shareContext && Kx.set(t, i)), i.refCount++;
|
|
19999
|
+
let o = null, s = null, c = ob(e), l = null, u = null;
|
|
19952
20000
|
async function d(t) {
|
|
19953
20001
|
if (await i.initDone, o) {
|
|
19954
20002
|
m();
|
|
@@ -19987,7 +20035,7 @@ function qx(e) {
|
|
|
19987
20035
|
i.afterRound(), i.store && await i.store.flush();
|
|
19988
20036
|
},
|
|
19989
20037
|
onClear: () => {
|
|
19990
|
-
i.store && (i.sessionId =
|
|
20038
|
+
i.store && (i.sessionId = Py(), i.vfsStore.clear?.(), i.todosMw.reset([]), e.memory || i.memoryMw.reset(""), i.agent.debugLogs.value = [], i.store.createSession(i.agentId, e.session?.title, i.sessionId));
|
|
19991
20039
|
},
|
|
19992
20040
|
pendingConflict: i.pendingConflict.value,
|
|
19993
20041
|
onResolveConflict: (e) => i.resolveConflict(e),
|
|
@@ -20106,7 +20154,7 @@ function qx(e) {
|
|
|
20106
20154
|
error: "schema 校验失败:" + (t.error?.message ?? "未知错误")
|
|
20107
20155
|
};
|
|
20108
20156
|
}
|
|
20109
|
-
return
|
|
20157
|
+
return rv(r, e), i.dataOpsController?.markDataDirty?.(), t?.emit !== !1 && i.emit({
|
|
20110
20158
|
type: "data_change",
|
|
20111
20159
|
operation: "set",
|
|
20112
20160
|
value: r
|
|
@@ -20128,7 +20176,7 @@ function qx(e) {
|
|
|
20128
20176
|
}
|
|
20129
20177
|
//#endregion
|
|
20130
20178
|
//#region src/core/sdk/defineTool.ts
|
|
20131
|
-
function
|
|
20179
|
+
function Zx(e) {
|
|
20132
20180
|
return r(async (t) => {
|
|
20133
20181
|
let n = await e.handler(t);
|
|
20134
20182
|
return typeof n == "string" ? n : JSON.stringify(n);
|
|
@@ -20139,4 +20187,4 @@ function Jx(e) {
|
|
|
20139
20187
|
});
|
|
20140
20188
|
}
|
|
20141
20189
|
//#endregion
|
|
20142
|
-
export {
|
|
20190
|
+
export { sb as CAPABILITIES, ub as CONTEXT_PRESETS, Bg as ChatDialog, nf as CodePreview, Ey as DEFAULT_SYSTEM_PROMPT, X_ as HUMAN_CONFIRM_TOOL_NAME, af as MessageContent, qv as STOP_WORDS, xh as SkillPanel, hb as UNSAFE_KEYS, Mx as actionsToInspectInfo, jx as actionsToTools, Kg as agentError, Ob as applyPatchToClone, kb as applyPatchToLive, Gg as asAgentError, Dy as buildDataPrompt, Oy as buildSystemPrompt, dx as commitSetToBind, zv as connectMcp, wl as copyText, C_ as createAgent, Y_ as createApprovalMiddleware, Xx as createChatSdk, ov as createCheckpointManager, sv as createCheckpointMiddleware, Ny as createConflictManager, px as createDataOps, $_ as createHumanConfirmMiddleware, Q_ as createHumanConfirmTool, eb as createMemoryBackend, H_ as createMemoryMiddleware, v as createProxyLlm, lb as createSdkEvents, ib as createSessionStore, Wx as createSkillStore, yv as createSubagentMiddleware, Sv as createSubagentsMiddleware, zx as createUsageHintsMiddleware, Cv as createVerifyMiddleware, Ib as createVfs, nb as createWebStorageBackend, kv as createWriteBackCheck, xb as deepClone, Fx as defineDataToolset, F_ as defineSkill, Zx as defineTool, bb as deleteByPath, py as describeSchemaNode, p_ as detectGarbledToolCall, Mb as diffObjects, yx as domToStructure, xx as domTools, Px as domToolsStatic, Yv as estimateMessageTokens, Xv as estimateRoundTokens, e_ as estimateTokens, wy as extractSchemaHint, Iv as extractText, hx as fetchDocTools, Nx as fetchTools, ux as filterByToolMode, my as formatConstraints, Vg as formatZodIssues, vb as getByPath, bx as getDomTool, wx as getEnvSummary, ay as getSchemaAtPath, ny as getSchemaTopKeys, r_ as getTraceMetrics, Db as hashValue, Zv as indexSummarize, Dx as inspectEnvTool, Ox as inspectTools, ky as isChatModel, ry as isPathAllowed, Ky as isQuotaError, gb as isUnsafePath, tx as jpEval, Ug as jsonParseError, wb as limitDepth, Sb as maybeParseValue, n_ as offloadPassThroughChars, t_ as offloadThresholdChars, yy as presets, sy as projectBySchema, oy as projectBySchemaDeep, Cb as projectFields, Qv as recallRounds, hy as renderSchemaHint, gy as renderSchemaOverview, vy as renderSchemaShallow, cb as resolveCapabilities, fb as resolveContextOptions, ob as resolveDialogConfig, My as resolveLlm, $g as resolveModelCaps, ab as resolveStorage, jb as restoreInPlace, Ab as restoreLive, Wg as routeError, sx as runSandboxedScript, _b as safeMerge, Cx as safeSerialize, Tb as safeStringify, rx as searchJson, Ix as selectBuiltinTools, yb as setByPath, by as systemPromptHelpers, Jv as tokenize, $ as toolError, iy as unwrapSchema, Cl as useChat, e as z, Hg as zodError };
|