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