page-agent-sdk 2.37.0 → 2.38.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/README.zh-CN.md +4 -3
- package/dist/page-agent-sdk.headless.js +685 -598
- package/dist/page-agent-sdk.iife.js +130 -130
- package/dist/page-agent-sdk.js +1554 -1380
- package/dist/page-agent-sdk.umd.cjs +59 -59
- package/dist/style.css +1 -1
- package/package.json +2 -1
- package/types/headless.d.ts +39 -2
- package/types/index.d.ts +39 -2
|
@@ -2769,8 +2769,10 @@ function Ni(e, t, n) {
|
|
|
2769
2769
|
let e = typeof r.shape == "function" ? r.shape() : r.shape;
|
|
2770
2770
|
if (!(t in e)) return !1;
|
|
2771
2771
|
r = e[t];
|
|
2772
|
-
} else if (r && (r._def?.type === "array" || r.constructor?.name === "ZodArray"))
|
|
2773
|
-
|
|
2772
|
+
} else if (r && (r._def?.type === "array" || r.constructor?.name === "ZodArray")) {
|
|
2773
|
+
if (!/^\d+$/.test(t)) return !1;
|
|
2774
|
+
r = r.element;
|
|
2775
|
+
} else if (r && (r._def?.type === "union" || r._def?.type === "discriminatedUnion" || Array.isArray(r.options))) return !0;
|
|
2774
2776
|
else return !1;
|
|
2775
2777
|
}
|
|
2776
2778
|
return !0;
|
|
@@ -2800,8 +2802,10 @@ function Fi(e, t) {
|
|
|
2800
2802
|
for (let e of r) {
|
|
2801
2803
|
if (!n) return null;
|
|
2802
2804
|
if (n = Pi(n), n && n.shape && typeof n.shape == "object") n = (typeof n.shape == "function" ? n.shape() : n.shape)[e];
|
|
2803
|
-
else if (n && (n._def?.type === "array" || n.constructor?.name === "ZodArray"))
|
|
2804
|
-
|
|
2805
|
+
else if (n && (n._def?.type === "array" || n.constructor?.name === "ZodArray")) {
|
|
2806
|
+
if (!/^\d+$/.test(e)) return null;
|
|
2807
|
+
n = n.element;
|
|
2808
|
+
} else if (n && (n._def?.type === "union" || n._def?.type === "discriminatedUnion" || Array.isArray(n.options))) return null;
|
|
2805
2809
|
else return null;
|
|
2806
2810
|
}
|
|
2807
2811
|
return n ?? null;
|
|
@@ -4181,57 +4185,86 @@ function yo(e = {}) {
|
|
|
4181
4185
|
}
|
|
4182
4186
|
//#endregion
|
|
4183
4187
|
//#region src/core/harness/subagent.ts
|
|
4184
|
-
function bo(e) {
|
|
4188
|
+
function bo(e = 20) {
|
|
4189
|
+
let t = /* @__PURE__ */ new Map(), n = [];
|
|
4190
|
+
return {
|
|
4191
|
+
start(e, n, r, i) {
|
|
4192
|
+
t.set(e, {
|
|
4193
|
+
taskId: e,
|
|
4194
|
+
task: n,
|
|
4195
|
+
label: r,
|
|
4196
|
+
status: "running",
|
|
4197
|
+
steps: [],
|
|
4198
|
+
startedAt: i
|
|
4199
|
+
});
|
|
4200
|
+
},
|
|
4201
|
+
pushStep(e, n) {
|
|
4202
|
+
let r = t.get(e);
|
|
4203
|
+
r && r.steps.push(n);
|
|
4204
|
+
},
|
|
4205
|
+
finish(r, i, a) {
|
|
4206
|
+
let o = t.get(r);
|
|
4207
|
+
if (o) for (o.status = i, o.durationMs = Date.now() - o.startedAt, o.resultPreview = a.length > 120 ? a.slice(0, 120) + "…" : a, t.delete(r), n.unshift(o); n.length > e;) n.pop();
|
|
4208
|
+
},
|
|
4209
|
+
getActive() {
|
|
4210
|
+
return [...t.values()];
|
|
4211
|
+
},
|
|
4212
|
+
getHistory() {
|
|
4213
|
+
return [...n];
|
|
4214
|
+
}
|
|
4215
|
+
};
|
|
4216
|
+
}
|
|
4217
|
+
function xo(e) {
|
|
4185
4218
|
return !!e && typeof e == "object" && typeof e.invoke == "function" && typeof e.stream == "function";
|
|
4186
4219
|
}
|
|
4187
|
-
var
|
|
4220
|
+
var So = [
|
|
4188
4221
|
"describe_data",
|
|
4189
4222
|
"get_data",
|
|
4190
4223
|
"read",
|
|
4191
4224
|
"query_data",
|
|
4192
4225
|
"search_data",
|
|
4193
4226
|
"fetch_document"
|
|
4194
|
-
],
|
|
4227
|
+
], Co = 1, wo = 4, To = 6, Eo = ["spawn_agent", "spawn_agents"], Do = [
|
|
4195
4228
|
"write",
|
|
4196
4229
|
"set_data",
|
|
4197
4230
|
"edit_data",
|
|
4198
4231
|
"delete_data",
|
|
4199
4232
|
"draft_commit"
|
|
4200
4233
|
];
|
|
4201
|
-
function
|
|
4234
|
+
function Oo(e) {
|
|
4202
4235
|
let t = [];
|
|
4203
4236
|
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);
|
|
4204
4237
|
return t;
|
|
4205
4238
|
}
|
|
4206
|
-
function
|
|
4239
|
+
function ko(e, t) {
|
|
4207
4240
|
return t.some((t) => e === t || e.startsWith(t + ".") || e.startsWith(t + "["));
|
|
4208
4241
|
}
|
|
4209
|
-
function
|
|
4242
|
+
function Ao(e, t) {
|
|
4210
4243
|
let n = e.invoke.bind(e), r = async (e) => {
|
|
4211
|
-
let r =
|
|
4244
|
+
let r = Oo(e);
|
|
4212
4245
|
if (!r.length) return `PATH_OUT_OF_SCOPE:子 agent 仅可增量 patch(writablePaths: ${t.join(", ")}),不能整体替换(无 jsonPath)。用 write({patch:{jsonPath,...}}) 增量改。`;
|
|
4213
|
-
for (let e of r) if (!
|
|
4246
|
+
for (let e of r) if (!ko(e, t)) return `PATH_OUT_OF_SCOPE:子 agent 写 "${e}" 越界(仅可写 ${t.join(", ")})。`;
|
|
4214
4247
|
return n(e);
|
|
4215
4248
|
};
|
|
4216
4249
|
return new Proxy(e, { get(e, t, n) {
|
|
4217
4250
|
return t === "invoke" ? r : Reflect.get(e, t, n);
|
|
4218
4251
|
} });
|
|
4219
4252
|
}
|
|
4220
|
-
async function
|
|
4221
|
-
let a = t.depth ?? 0, o = t.maxDepth ??
|
|
4253
|
+
async function jo(e, t, n, r, i) {
|
|
4254
|
+
let a = t.depth ?? 0, o = t.maxDepth ?? Co, s = /* @__PURE__ */ new Set([...So, ...t.allowedTools ?? []]), c = () => typeof t.allTools == "function" ? t.allTools() : t.allTools, l = [...c().filter((e) => s.has(e.name) && !Eo.includes(e.name)), ...t.extraTools ?? []];
|
|
4222
4255
|
if (t.writablePaths?.length) {
|
|
4223
|
-
l = l.filter((e) => !
|
|
4224
|
-
let e = c().filter((e) =>
|
|
4256
|
+
l = l.filter((e) => !Do.includes(e.name));
|
|
4257
|
+
let e = c().filter((e) => Do.includes(e.name) && !Eo.includes(e.name)).map((e) => Ao(e, t.writablePaths));
|
|
4225
4258
|
l = [...l, ...e];
|
|
4226
4259
|
}
|
|
4227
|
-
let u = a + 1 < o ? [
|
|
4260
|
+
let u = a + 1 < o ? [Mo({
|
|
4228
4261
|
...t,
|
|
4229
4262
|
depth: a + 1
|
|
4230
4263
|
})] : [], d = t.getFocuses?.() ?? [], f = d.length ? pa({
|
|
4231
4264
|
getSchema: t.getSchema ?? (() => null),
|
|
4232
4265
|
initialFocuses: d
|
|
4233
4266
|
}) : void 0, p = ni({
|
|
4234
|
-
model:
|
|
4267
|
+
model: xo(t.llm) ? t.llm.model ?? t.llm.modelName : e.model ?? t.llm.model,
|
|
4235
4268
|
contextWindow: t.llm.contextWindow,
|
|
4236
4269
|
maxOutputTokens: t.llm.maxOutputTokens
|
|
4237
4270
|
});
|
|
@@ -4242,7 +4275,7 @@ async function Ao(e, t, n, r, i) {
|
|
|
4242
4275
|
} : { contextWindow: p.contextWindow }), h = ji({
|
|
4243
4276
|
contextWindow: p.contextWindow,
|
|
4244
4277
|
maxOutputTokens: p.maxOutputTokens,
|
|
4245
|
-
...
|
|
4278
|
+
...xo(t.llm) ? { llm: t.llm } : {
|
|
4246
4279
|
apiKey: t.llm.apiKey,
|
|
4247
4280
|
baseUrl: t.llm.baseUrl,
|
|
4248
4281
|
model: e.model ?? t.llm.model,
|
|
@@ -4258,7 +4291,7 @@ async function Ao(e, t, n, r, i) {
|
|
|
4258
4291
|
...f ? [f] : [],
|
|
4259
4292
|
...t.middleware ?? []
|
|
4260
4293
|
],
|
|
4261
|
-
maxToolRounds: t.maxToolRounds ??
|
|
4294
|
+
maxToolRounds: t.maxToolRounds ?? To,
|
|
4262
4295
|
onLog: i,
|
|
4263
4296
|
debug: t.debug
|
|
4264
4297
|
});
|
|
@@ -4270,17 +4303,21 @@ async function Ao(e, t, n, r, i) {
|
|
|
4270
4303
|
r && (e.type === "tool_call" || e.type === "tool_result") && r(e);
|
|
4271
4304
|
}, n);
|
|
4272
4305
|
}
|
|
4273
|
-
function
|
|
4274
|
-
let n = e.maxParallel ??
|
|
4275
|
-
|
|
4306
|
+
function Mo(e) {
|
|
4307
|
+
let n = e.maxParallel ?? wo, i, a, o, s = (t, n) => (r) => {
|
|
4308
|
+
e.tracker?.pushStep(t, {
|
|
4309
|
+
kind: r.type,
|
|
4310
|
+
name: r.name,
|
|
4311
|
+
ts: Date.now()
|
|
4312
|
+
}), a && a({
|
|
4276
4313
|
type: "subagent",
|
|
4277
|
-
taskId:
|
|
4278
|
-
label:
|
|
4279
|
-
kind:
|
|
4280
|
-
name:
|
|
4281
|
-
args:
|
|
4282
|
-
result:
|
|
4283
|
-
status:
|
|
4314
|
+
taskId: t,
|
|
4315
|
+
label: n,
|
|
4316
|
+
kind: r.type,
|
|
4317
|
+
name: r.name,
|
|
4318
|
+
args: r.type === "tool_call" ? r.args : void 0,
|
|
4319
|
+
result: r.type === "tool_result" ? r.result : void 0,
|
|
4320
|
+
status: r.type === "tool_result" ? r.status : void 0
|
|
4284
4321
|
});
|
|
4285
4322
|
};
|
|
4286
4323
|
return {
|
|
@@ -4290,15 +4327,21 @@ function jo(e) {
|
|
|
4290
4327
|
...e,
|
|
4291
4328
|
...r?.length ? { allowedTools: r } : {},
|
|
4292
4329
|
...a?.length ? { writablePaths: a } : {}
|
|
4293
|
-
} : e, u = `sub-${Math.random().toString(36).slice(2, 8)}`, d = n?.trim() || "子任务"
|
|
4294
|
-
return await Ao({
|
|
4295
|
-
prompt: t,
|
|
4296
|
-
role: n,
|
|
4297
|
-
model: c
|
|
4298
|
-
}, l, i, s(u, d), (e) => o?.({
|
|
4330
|
+
} : e, u = `sub-${Math.random().toString(36).slice(2, 8)}`, d = n?.trim() || "子任务", f = (e) => o?.({
|
|
4299
4331
|
...e,
|
|
4300
4332
|
source: `子:${d}`
|
|
4301
|
-
}));
|
|
4333
|
+
}), p = Date.now();
|
|
4334
|
+
e.tracker?.start(u, t, d, p);
|
|
4335
|
+
try {
|
|
4336
|
+
let r = await jo({
|
|
4337
|
+
prompt: t,
|
|
4338
|
+
role: n,
|
|
4339
|
+
model: c
|
|
4340
|
+
}, l, i, s(u, d), f);
|
|
4341
|
+
return e.tracker?.finish(u, "done", r), r;
|
|
4342
|
+
} catch (t) {
|
|
4343
|
+
throw e.tracker?.finish(u, "error", String(t?.message ?? t)), t;
|
|
4344
|
+
}
|
|
4302
4345
|
}, {
|
|
4303
4346
|
name: "spawn_agent",
|
|
4304
4347
|
description: "委派一个独立子 agent 执行子任务,返回其最终结论(过程隔离,不占主上下文)。用于:分治大任务、专项调研、独立验证。子 agent 默认只读(不改页面)。",
|
|
@@ -4310,11 +4353,17 @@ function jo(e) {
|
|
|
4310
4353
|
model: t.string().optional().describe("覆盖模型(默认同主)")
|
|
4311
4354
|
})
|
|
4312
4355
|
}), r(async ({ tasks: t }) => (await Qr(t, n, async (t, n) => {
|
|
4313
|
-
let r = `sub-${n}-${Math.random().toString(36).slice(2, 6)}`, a = t.role?.trim() || `子任务${n + 1}
|
|
4314
|
-
return Ao(t, e, i, s(r, a), (e) => o?.({
|
|
4356
|
+
let r = `sub-${n}-${Math.random().toString(36).slice(2, 6)}`, a = t.role?.trim() || `子任务${n + 1}`, c = (e) => o?.({
|
|
4315
4357
|
...e,
|
|
4316
4358
|
source: `子:${a}`
|
|
4317
|
-
}));
|
|
4359
|
+
}), l = Date.now();
|
|
4360
|
+
e.tracker?.start(r, t.prompt, a, l);
|
|
4361
|
+
try {
|
|
4362
|
+
let n = await jo(t, e, i, s(r, a), c);
|
|
4363
|
+
return e.tracker?.finish(r, "done", n ?? "(未完成)"), n;
|
|
4364
|
+
} catch (t) {
|
|
4365
|
+
throw e.tracker?.finish(r, "error", String(t?.message ?? t)), t;
|
|
4366
|
+
}
|
|
4318
4367
|
}, i)).map((e, t) => `【子任务 ${t + 1}】\n${e ?? "(未完成)"}`).join("\n\n"), {
|
|
4319
4368
|
name: "spawn_agents",
|
|
4320
4369
|
description: "并行委派多个独立子 agent,聚合各自结论(子 agent 间互不通信,由你汇总)。适合:多路调研、多视角审查、批量处理。",
|
|
@@ -4326,8 +4375,8 @@ function jo(e) {
|
|
|
4326
4375
|
wrapToolCall: async (e, t) => (e.signal && (i = e.signal), e.emit && (a = e.emit), e.logSink && (o = e.logSink), t(e))
|
|
4327
4376
|
};
|
|
4328
4377
|
}
|
|
4329
|
-
var
|
|
4330
|
-
function
|
|
4378
|
+
var No = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
4379
|
+
function Po(e, t) {
|
|
4331
4380
|
let n = e.tools ?? [];
|
|
4332
4381
|
return {
|
|
4333
4382
|
llm: e.llm ?? t.llm,
|
|
@@ -4344,10 +4393,11 @@ function No(e, t) {
|
|
|
4344
4393
|
...e.middleware?.length ? { middleware: e.middleware } : {},
|
|
4345
4394
|
...e.summarization === void 0 ? {} : { summarization: e.summarization },
|
|
4346
4395
|
...t.getFocuses ? { getFocuses: t.getFocuses } : {},
|
|
4347
|
-
...t.getSchema ? { getSchema: t.getSchema } : {}
|
|
4396
|
+
...t.getSchema ? { getSchema: t.getSchema } : {},
|
|
4397
|
+
...t.tracker ? { tracker: t.tracker } : {}
|
|
4348
4398
|
};
|
|
4349
4399
|
}
|
|
4350
|
-
function
|
|
4400
|
+
function Fo(e, n) {
|
|
4351
4401
|
let i, a, o, s = (e, t) => (n) => {
|
|
4352
4402
|
a && a({
|
|
4353
4403
|
type: "subagent",
|
|
@@ -4363,7 +4413,7 @@ function Po(e, n) {
|
|
|
4363
4413
|
function d(e) {
|
|
4364
4414
|
let a = /* @__PURE__ */ new Set(), c = [], l = [];
|
|
4365
4415
|
for (let u of e) {
|
|
4366
|
-
if (!
|
|
4416
|
+
if (!No.test(u.id)) {
|
|
4367
4417
|
console.warn(`[subagents] id "${u.id}" 非合法工具名(须 [a-zA-Z_][a-zA-Z0-9_]*),已跳过`);
|
|
4368
4418
|
continue;
|
|
4369
4419
|
}
|
|
@@ -4373,11 +4423,23 @@ function Po(e, n) {
|
|
|
4373
4423
|
continue;
|
|
4374
4424
|
}
|
|
4375
4425
|
a.add(e), c.push(u), l.push(r(async ({ task: e }) => {
|
|
4376
|
-
let t =
|
|
4377
|
-
return Ao({ prompt: e }, t, i, s(`use_${u.id}`, u.id), (e) => o?.({
|
|
4426
|
+
let t = Po(u, n), r = (e) => o?.({
|
|
4378
4427
|
...e,
|
|
4379
4428
|
source: `子:${u.id}`
|
|
4380
|
-
}))
|
|
4429
|
+
}), a = n.tracker, c = a ? `use_${u.id}-${Math.random().toString(36).slice(2, 6)}` : `use_${u.id}`, l = s(`use_${u.id}`, u.id), d = a ? (e) => {
|
|
4430
|
+
a.pushStep(c, {
|
|
4431
|
+
kind: e.type,
|
|
4432
|
+
name: e.name,
|
|
4433
|
+
ts: Date.now()
|
|
4434
|
+
}), l(e);
|
|
4435
|
+
} : l, f = Date.now();
|
|
4436
|
+
a?.start(c, e, u.id, f);
|
|
4437
|
+
try {
|
|
4438
|
+
let n = await jo({ prompt: e }, t, i, d, r);
|
|
4439
|
+
return a?.finish(c, "done", n), n;
|
|
4440
|
+
} catch (e) {
|
|
4441
|
+
throw a?.finish(c, "error", String(e?.message ?? e)), e;
|
|
4442
|
+
}
|
|
4381
4443
|
}, {
|
|
4382
4444
|
name: `use_${u.id}`,
|
|
4383
4445
|
description: `委派给「${u.description}」子 agent 执行任务,返回其结论(过程隔离,不占主上下文)。`,
|
|
@@ -4434,7 +4496,7 @@ function Po(e, n) {
|
|
|
4434
4496
|
}
|
|
4435
4497
|
//#endregion
|
|
4436
4498
|
//#region src/core/harness/verify.ts
|
|
4437
|
-
function
|
|
4499
|
+
function Io(e) {
|
|
4438
4500
|
return {
|
|
4439
4501
|
name: "verify",
|
|
4440
4502
|
async beforeReturn({ messages: t, state: n, log: r }) {
|
|
@@ -4446,10 +4508,10 @@ function Fo(e) {
|
|
|
4446
4508
|
if (e.adversarial) {
|
|
4447
4509
|
r?.("middleware", {
|
|
4448
4510
|
stage: "adversarial_start",
|
|
4449
|
-
model:
|
|
4511
|
+
model: Wo(e.adversarial.llm),
|
|
4450
4512
|
tools: (e.adversarial.tools ?? []).length
|
|
4451
4513
|
});
|
|
4452
|
-
let n = await
|
|
4514
|
+
let n = await Jo(t, e.adversarial.llm, r, e.adversarial.tools);
|
|
4453
4515
|
if (r?.("middleware", {
|
|
4454
4516
|
stage: "adversarial_done",
|
|
4455
4517
|
clean: n === null,
|
|
@@ -4460,18 +4522,18 @@ function Fo(e) {
|
|
|
4460
4522
|
}
|
|
4461
4523
|
};
|
|
4462
4524
|
}
|
|
4463
|
-
var
|
|
4525
|
+
var Lo = /* @__PURE__ */ new Set([
|
|
4464
4526
|
"set_data",
|
|
4465
4527
|
"edit_data",
|
|
4466
4528
|
"delete_data",
|
|
4467
4529
|
"write"
|
|
4468
|
-
]),
|
|
4469
|
-
function
|
|
4530
|
+
]), Ro = /校验失败|SCHEMA_INVALID|未注册|不存在|仅支持|必须是|NOT_OBJECT|PATH_UNSAFE|VERSION_CONFLICT|WRITE_INTERCEPT/;
|
|
4531
|
+
function zo(e) {
|
|
4470
4532
|
let t = /* @__PURE__ */ new Map();
|
|
4471
4533
|
for (let n of e) {
|
|
4472
4534
|
let e = n?.tool_calls;
|
|
4473
4535
|
if (Array.isArray(e)) for (let n of e) {
|
|
4474
|
-
if (!
|
|
4536
|
+
if (!Lo.has(n.name)) continue;
|
|
4475
4537
|
let e = n.id, r = n?.args ?? {};
|
|
4476
4538
|
if (n.name === "write") if (r.del && r.patch?.jsonPath) t.set(r.patch.jsonPath, {
|
|
4477
4539
|
path: r.patch.jsonPath,
|
|
@@ -4510,7 +4572,7 @@ function Ro(e) {
|
|
|
4510
4572
|
}
|
|
4511
4573
|
return [...t.values()];
|
|
4512
4574
|
}
|
|
4513
|
-
function
|
|
4575
|
+
function Bo(e) {
|
|
4514
4576
|
let t = /* @__PURE__ */ new Map();
|
|
4515
4577
|
for (let n of e) {
|
|
4516
4578
|
let e = n?.tool_call_id, r = n?.content;
|
|
@@ -4518,7 +4580,7 @@ function zo(e) {
|
|
|
4518
4580
|
}
|
|
4519
4581
|
return t;
|
|
4520
4582
|
}
|
|
4521
|
-
function
|
|
4583
|
+
function Vo(e, t) {
|
|
4522
4584
|
if (t === "") return e;
|
|
4523
4585
|
if (e == null) return;
|
|
4524
4586
|
let n = e;
|
|
@@ -4528,16 +4590,16 @@ function Bo(e, t) {
|
|
|
4528
4590
|
}
|
|
4529
4591
|
return n;
|
|
4530
4592
|
}
|
|
4531
|
-
function
|
|
4593
|
+
function Ho(e = {}) {
|
|
4532
4594
|
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 ?? {};
|
|
4533
4595
|
return async ({ messages: e }) => {
|
|
4534
|
-
let r =
|
|
4596
|
+
let r = zo(e);
|
|
4535
4597
|
if (!r.length) return { ok: !0 };
|
|
4536
|
-
let i =
|
|
4598
|
+
let i = Bo(e), a = n()[""], o = t(), s = [];
|
|
4537
4599
|
for (let { path: e, op: t, callId: n } of r) {
|
|
4538
4600
|
let r = n ? i.get(n) : void 0;
|
|
4539
|
-
if (r &&
|
|
4540
|
-
let c =
|
|
4601
|
+
if (r && Ro.test(r)) continue;
|
|
4602
|
+
let c = Vo(o, e);
|
|
4541
4603
|
if (t === "delete_data") c !== void 0 && s.push(`${e} 删除后读回仍有值,疑似未生效`);
|
|
4542
4604
|
else if (c == null) s.push(`写入 ${e} 后读回为空,疑似未生效`);
|
|
4543
4605
|
else if (a) {
|
|
@@ -4551,17 +4613,17 @@ function Vo(e = {}) {
|
|
|
4551
4613
|
} : { ok: !0 };
|
|
4552
4614
|
};
|
|
4553
4615
|
}
|
|
4554
|
-
function Ho(e) {
|
|
4555
|
-
return !!e && typeof e == "object" && typeof e.invoke == "function" && typeof e.stream == "function";
|
|
4556
|
-
}
|
|
4557
4616
|
function Uo(e) {
|
|
4558
|
-
return
|
|
4617
|
+
return !!e && typeof e == "object" && typeof e.invoke == "function" && typeof e.stream == "function";
|
|
4559
4618
|
}
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
return Wo.test(e);
|
|
4619
|
+
function Wo(e) {
|
|
4620
|
+
return Uo(e) ? e.model ?? e.modelName ?? "<实例>" : e.model ?? "<配置>";
|
|
4563
4621
|
}
|
|
4622
|
+
var Go = /无问题|没有问题|未发现问题|没有发现|没问题|未发现/;
|
|
4564
4623
|
function Ko(e) {
|
|
4624
|
+
return Go.test(e);
|
|
4625
|
+
}
|
|
4626
|
+
function qo(e) {
|
|
4565
4627
|
let t = "", n = "";
|
|
4566
4628
|
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 : "");
|
|
4567
4629
|
return {
|
|
@@ -4569,8 +4631,8 @@ function Ko(e) {
|
|
|
4569
4631
|
lastReply: n
|
|
4570
4632
|
};
|
|
4571
4633
|
}
|
|
4572
|
-
async function
|
|
4573
|
-
let { lastUser: i, lastReply: a } =
|
|
4634
|
+
async function Jo(e, t, n, r) {
|
|
4635
|
+
let { lastUser: i, lastReply: a } = qo(e);
|
|
4574
4636
|
if (!a) return null;
|
|
4575
4637
|
let o = Array.isArray(r) && r.length > 0, s = [
|
|
4576
4638
|
"你是严格的对抗式审查者,目标是找出以下 AI 助手回复的错误并证明它有问题(事实错误 / 遗漏 / 逻辑矛盾 / 与需求不符)。",
|
|
@@ -4581,7 +4643,7 @@ async function qo(e, t, n, r) {
|
|
|
4581
4643
|
].join("\n"), c = "你是严格的对抗式审查者,只找问题不赞美。目标是反驳,不是改进。", l = n ? (e) => n(e.type, {
|
|
4582
4644
|
...e.data,
|
|
4583
4645
|
source: "adversarial"
|
|
4584
|
-
}) : void 0, u = await ji(
|
|
4646
|
+
}) : void 0, u = await ji(Uo(t) ? {
|
|
4585
4647
|
llm: t,
|
|
4586
4648
|
tools: r,
|
|
4587
4649
|
maxToolRounds: o ? 4 : 1,
|
|
@@ -4606,11 +4668,11 @@ async function qo(e, t, n, r) {
|
|
|
4606
4668
|
stage: "adversarial_verdict",
|
|
4607
4669
|
verdict: u,
|
|
4608
4670
|
source: "adversarial"
|
|
4609
|
-
}),
|
|
4671
|
+
}), Ko(u) ? null : u.trim();
|
|
4610
4672
|
}
|
|
4611
4673
|
//#endregion
|
|
4612
4674
|
//#region src/core/utils/contextAnalysis.ts
|
|
4613
|
-
var
|
|
4675
|
+
var Yo = [
|
|
4614
4676
|
{
|
|
4615
4677
|
prefix: "## 可操作数据",
|
|
4616
4678
|
key: "dataHint"
|
|
@@ -4639,7 +4701,7 @@ var Jo = [
|
|
|
4639
4701
|
prefix: "【与当前问题可能相关的早期对话】",
|
|
4640
4702
|
key: "recall"
|
|
4641
4703
|
}
|
|
4642
|
-
],
|
|
4704
|
+
], Xo = [
|
|
4643
4705
|
{
|
|
4644
4706
|
key: "systemPrompt",
|
|
4645
4707
|
label: "系统提示词(身份/规则)"
|
|
@@ -4693,9 +4755,9 @@ var Jo = [
|
|
|
4693
4755
|
label: "其他"
|
|
4694
4756
|
}
|
|
4695
4757
|
];
|
|
4696
|
-
function
|
|
4758
|
+
function Zo() {
|
|
4697
4759
|
let e = {};
|
|
4698
|
-
for (let t of
|
|
4760
|
+
for (let t of Xo) e[t.key] = {
|
|
4699
4761
|
key: t.key,
|
|
4700
4762
|
label: t.label,
|
|
4701
4763
|
tokens: 0,
|
|
@@ -4704,16 +4766,16 @@ function Xo() {
|
|
|
4704
4766
|
};
|
|
4705
4767
|
return e;
|
|
4706
4768
|
}
|
|
4707
|
-
function
|
|
4769
|
+
function Qo(e, t) {
|
|
4708
4770
|
e.tokens += t, e.msgCount += 1;
|
|
4709
4771
|
}
|
|
4710
|
-
function
|
|
4772
|
+
function $o(e) {
|
|
4711
4773
|
let t = e.content;
|
|
4712
4774
|
return typeof t == "string" ? t : JSON.stringify(t ?? "");
|
|
4713
4775
|
}
|
|
4714
|
-
function
|
|
4776
|
+
function es(e, t) {
|
|
4715
4777
|
let n = [];
|
|
4716
|
-
for (let t of
|
|
4778
|
+
for (let t of Yo) {
|
|
4717
4779
|
let r = 0;
|
|
4718
4780
|
for (;;) {
|
|
4719
4781
|
let i = e.indexOf(t.prefix, r);
|
|
@@ -4726,35 +4788,35 @@ function $o(e, t) {
|
|
|
4726
4788
|
}
|
|
4727
4789
|
if (n.sort((e, t) => e.idx - t.idx), !n.length) {
|
|
4728
4790
|
let n = e.trim();
|
|
4729
|
-
n &&
|
|
4791
|
+
n && Qo(t.systemPrompt, X(n));
|
|
4730
4792
|
return;
|
|
4731
4793
|
}
|
|
4732
4794
|
if (n[0].idx > 0) {
|
|
4733
4795
|
let r = e.slice(0, n[0].idx).trim();
|
|
4734
|
-
r &&
|
|
4796
|
+
r && Qo(t.systemPrompt, X(r));
|
|
4735
4797
|
}
|
|
4736
4798
|
for (let r = 0; r < n.length; r++) {
|
|
4737
4799
|
let i = n[r].idx, a = r + 1 < n.length ? n[r + 1].idx : e.length, o = e.slice(i, a).trim();
|
|
4738
|
-
o &&
|
|
4800
|
+
o && Qo(t[n[r].key], X(o));
|
|
4739
4801
|
}
|
|
4740
4802
|
}
|
|
4741
|
-
function
|
|
4742
|
-
let n =
|
|
4803
|
+
function ts(e, t = {}) {
|
|
4804
|
+
let n = Zo(), r = -1;
|
|
4743
4805
|
for (let t = e.length - 1; t >= 0; t--) if (e[t] instanceof a) {
|
|
4744
4806
|
r = t;
|
|
4745
4807
|
break;
|
|
4746
4808
|
}
|
|
4747
4809
|
for (let t = 0; t < e.length; t++) {
|
|
4748
4810
|
let c = e[t];
|
|
4749
|
-
if (c instanceof o) $o(
|
|
4750
|
-
else if (c instanceof a)
|
|
4811
|
+
if (c instanceof o) es($o(c), n);
|
|
4812
|
+
else if (c instanceof a) Qo(n[t === r ? "current" : "history"], X($o(c)));
|
|
4751
4813
|
else if (c instanceof i) {
|
|
4752
4814
|
let e = c.tool_calls ?? [];
|
|
4753
4815
|
if (e.length) {
|
|
4754
4816
|
let t = e.map((e) => JSON.stringify(e.args ?? {})).join(" ");
|
|
4755
|
-
|
|
4756
|
-
} else
|
|
4757
|
-
} else c instanceof s ?
|
|
4817
|
+
Qo(n.toolResults, X(t));
|
|
4818
|
+
} else Qo(n.assistant, X($o(c)));
|
|
4819
|
+
} else c instanceof s ? Qo(n.toolResults, X($o(c))) : Qo(n.other, X($o(c)));
|
|
4758
4820
|
}
|
|
4759
4821
|
let c = Object.values(n).filter((e) => e.tokens > 0);
|
|
4760
4822
|
c.sort((e, t) => t.tokens - e.tokens);
|
|
@@ -4771,12 +4833,12 @@ function es(e, t = {}) {
|
|
|
4771
4833
|
}
|
|
4772
4834
|
//#endregion
|
|
4773
4835
|
//#region src/core/harness/contextInspector.ts
|
|
4774
|
-
function
|
|
4836
|
+
function ns(e = {}) {
|
|
4775
4837
|
let t, n = e.contextWindow;
|
|
4776
4838
|
return {
|
|
4777
4839
|
name: "context-inspector",
|
|
4778
4840
|
async wrapModelCall(r, i) {
|
|
4779
|
-
return t =
|
|
4841
|
+
return t = ts(r.messages, {
|
|
4780
4842
|
contextWindow: n,
|
|
4781
4843
|
thresholdRatio: e.thresholdRatio
|
|
4782
4844
|
}), i(r);
|
|
@@ -4789,13 +4851,13 @@ function ts(e = {}) {
|
|
|
4789
4851
|
}
|
|
4790
4852
|
//#endregion
|
|
4791
4853
|
//#region src/core/mcp/client.ts
|
|
4792
|
-
function
|
|
4854
|
+
function rs(e) {
|
|
4793
4855
|
let t = e?.content;
|
|
4794
4856
|
if (!Array.isArray(t) || !t.length) return "";
|
|
4795
4857
|
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");
|
|
4796
4858
|
return e?.isError ? `工具错误:${n}` : n;
|
|
4797
4859
|
}
|
|
4798
|
-
async function
|
|
4860
|
+
async function is(e) {
|
|
4799
4861
|
let t = new URL(e.url), n = e.requestInit;
|
|
4800
4862
|
if (e.transport === "http") {
|
|
4801
4863
|
let { StreamableHTTPClientTransport: e } = await import("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
@@ -4808,8 +4870,8 @@ async function rs(e) {
|
|
|
4808
4870
|
let { WebSocketClientTransport: r } = await import("@modelcontextprotocol/sdk/client/websocket.js");
|
|
4809
4871
|
return new r(t);
|
|
4810
4872
|
}
|
|
4811
|
-
function
|
|
4812
|
-
return r(async (n) =>
|
|
4873
|
+
function as(e, t) {
|
|
4874
|
+
return r(async (n) => rs(await t.callTool({
|
|
4813
4875
|
name: e.name,
|
|
4814
4876
|
arguments: n
|
|
4815
4877
|
})), {
|
|
@@ -4818,39 +4880,39 @@ function is(e, t) {
|
|
|
4818
4880
|
schema: e.inputSchema
|
|
4819
4881
|
});
|
|
4820
4882
|
}
|
|
4821
|
-
async function
|
|
4822
|
-
let { Client: t } = await import("@modelcontextprotocol/sdk/client"), n = await
|
|
4883
|
+
async function os(e) {
|
|
4884
|
+
let { Client: t } = await import("@modelcontextprotocol/sdk/client"), n = await is(e), r = new t({
|
|
4823
4885
|
name: "page-agent-sdk",
|
|
4824
4886
|
version: "1.0"
|
|
4825
4887
|
}, { capabilities: {} });
|
|
4826
4888
|
await r.connect(n);
|
|
4827
4889
|
let { tools: i } = await r.listTools();
|
|
4828
4890
|
return {
|
|
4829
|
-
tools: i.map((e) =>
|
|
4891
|
+
tools: i.map((e) => as(e, r)),
|
|
4830
4892
|
close: () => r.close()
|
|
4831
4893
|
};
|
|
4832
4894
|
}
|
|
4833
4895
|
//#endregion
|
|
4834
4896
|
//#region src/core/sdk/promptBuilder.ts
|
|
4835
|
-
var
|
|
4897
|
+
var ss = [
|
|
4836
4898
|
"你是一个 JSON 操作助手。集成方声明了一个主数据对象(含 zod schema 校验),你通过专用工具安全地读写它来完成任务。",
|
|
4837
4899
|
"所有写操作都经范围控制(仅 schema 声明字段内)与 schema 校验(不合法会返回结构化错误而非写入),并自动留快照可回退。",
|
|
4838
4900
|
"大对象/数组优先用增量 patch(只发改动)而非整体重传,避免输出被截断。",
|
|
4839
4901
|
"---",
|
|
4840
4902
|
ia.reliableWriteRules
|
|
4841
4903
|
].join("\n\n");
|
|
4842
|
-
function
|
|
4904
|
+
function cs(e, t) {
|
|
4843
4905
|
if (!e) return "";
|
|
4844
4906
|
let n = ca(e.schema, t);
|
|
4845
4907
|
return `\n\n## 可操作数据(字段以 read 工具返回的实际值为准)\n${e.description ? e.description + "\n" : ""}${n}`;
|
|
4846
4908
|
}
|
|
4847
|
-
function
|
|
4909
|
+
function ls(e) {
|
|
4848
4910
|
let t = e.appendReliableWriteRules !== !1;
|
|
4849
|
-
return e.systemPrompt ? t ? e.systemPrompt + "\n\n---\n\n" + ia.reliableWriteRules : e.systemPrompt :
|
|
4911
|
+
return e.systemPrompt ? t ? e.systemPrompt + "\n\n---\n\n" + ia.reliableWriteRules : e.systemPrompt : ss;
|
|
4850
4912
|
}
|
|
4851
4913
|
//#endregion
|
|
4852
4914
|
//#region src/core/sdk/defineTool.ts
|
|
4853
|
-
function
|
|
4915
|
+
function us(e) {
|
|
4854
4916
|
return r(async (t) => {
|
|
4855
4917
|
let n = await e.handler(t);
|
|
4856
4918
|
return typeof n == "string" ? n : JSON.stringify(n);
|
|
@@ -4862,7 +4924,7 @@ function ls(e) {
|
|
|
4862
4924
|
}
|
|
4863
4925
|
//#endregion
|
|
4864
4926
|
//#region src/core/sdk/inspectContextTool.ts
|
|
4865
|
-
var
|
|
4927
|
+
var ds = t.object({
|
|
4866
4928
|
path: t.string().optional().describe("分类 key 过滤(如 toolResults/history/systemPrompt/dataHint);不传=全部分类"),
|
|
4867
4929
|
role: t.enum([
|
|
4868
4930
|
"user",
|
|
@@ -4872,11 +4934,11 @@ var us = t.object({
|
|
|
4872
4934
|
]).optional().describe("聚焦每轮首句的角色(assistant→回复摘要,user→问题摘要);不影响工具列表"),
|
|
4873
4935
|
limit: t.number().int().min(1).max(50).optional().describe("返回最近 N 轮(默认全部;超 50 自动截最近 50 防返回过大)")
|
|
4874
4936
|
});
|
|
4875
|
-
function
|
|
4876
|
-
return
|
|
4937
|
+
function fs(e) {
|
|
4938
|
+
return us({
|
|
4877
4939
|
name: "inspect_context",
|
|
4878
4940
|
description: "查看当前对话上下文的构成(供压缩决策)。返回:totalTokens(历史轮次 token 总和,与触发判断同口径)、occupancy(窗口占用比)、contextWindow、categories(分类占用)、rounds(每轮 token/工具/首句)。先调用本工具查看构成,再决定压缩策略。",
|
|
4879
|
-
schema:
|
|
4941
|
+
schema: ds,
|
|
4880
4942
|
handler: (t) => {
|
|
4881
4943
|
let n = eo(e.getMessages()), r = n.length > 50 ? n.slice(n.length - 50) : n, i = (t.limit && r.length > t.limit ? r.slice(r.length - t.limit) : r).map((e) => {
|
|
4882
4944
|
let n = po(e), r = no(e), i = t.role === "assistant" ? e.assistantMsgs[0] ?? e.userMsg : e.userMsg, a = to(typeof i.content == "string" ? i.content : "", 60);
|
|
@@ -4899,7 +4961,7 @@ function ds(e) {
|
|
|
4899
4961
|
}
|
|
4900
4962
|
//#endregion
|
|
4901
4963
|
//#region src/core/sdk/compressDecision.ts
|
|
4902
|
-
var
|
|
4964
|
+
var ps = t.object({
|
|
4903
4965
|
keepRounds: t.number().int().min(0).max(50).optional(),
|
|
4904
4966
|
windowRatio: t.number().min(0).max(1).optional(),
|
|
4905
4967
|
summarize: t.object({ mode: t.enum(["index", "llm"]) }),
|
|
@@ -4909,23 +4971,23 @@ var fs = t.object({
|
|
|
4909
4971
|
}).refine((e) => e.keepRounds !== void 0 || e.windowRatio !== void 0, { message: "keepRounds 与 windowRatio 至少填一个(按当前触发模式)" });
|
|
4910
4972
|
//#endregion
|
|
4911
4973
|
//#region src/core/sdk/llmResolver.ts
|
|
4912
|
-
function
|
|
4974
|
+
function ms(e) {
|
|
4913
4975
|
let t = e.find((e) => e.role === "user");
|
|
4914
4976
|
if (!t) return;
|
|
4915
4977
|
let n = t.content, r = (typeof n == "string" ? n : Array.isArray(n) ? n.map((e) => typeof e == "string" ? e : e?.text ?? "").join("") : String(n ?? "")).trim().replace(/[\n\r]+/g, " ");
|
|
4916
4978
|
if (r) return r.length > 30 ? r.slice(0, 30) + "…" : r;
|
|
4917
4979
|
}
|
|
4918
|
-
function
|
|
4980
|
+
function hs(e) {
|
|
4919
4981
|
return !!e && typeof e == "object" && typeof e.invoke == "function" && typeof e.stream == "function";
|
|
4920
4982
|
}
|
|
4921
|
-
function
|
|
4983
|
+
function gs(e) {
|
|
4922
4984
|
let t = e.content;
|
|
4923
4985
|
return typeof t == "string" ? t : Array.isArray(t) ? t.map((e) => typeof e == "string" ? e : e?.text ?? "").join("") : String(t ?? "");
|
|
4924
4986
|
}
|
|
4925
|
-
function
|
|
4987
|
+
function _s(e) {
|
|
4926
4988
|
let t = e.summaryLlm ?? e.llm;
|
|
4927
4989
|
if (!t) return;
|
|
4928
|
-
let n = e.summaryTemperature ?? .3, r = e.summaryMaxTokens ?? 1024, i = e.summaryTimeoutMs ?? 15e3, s =
|
|
4990
|
+
let n = e.summaryTemperature ?? .3, r = e.summaryMaxTokens ?? 1024, i = e.summaryTimeoutMs ?? 15e3, s = hs(t) ? t : null, c = hs(t) ? null : t;
|
|
4929
4991
|
if (c && !c.apiKey) {
|
|
4930
4992
|
e.summaryLlm && console.warn("[page-agent-sdk][summarization] summaryLlm 已配置但缺 apiKey,摘要回退主 agent 模型或零成本索引摘要");
|
|
4931
4993
|
return;
|
|
@@ -4937,16 +4999,16 @@ function gs(e) {
|
|
|
4937
4999
|
return !l && c && (l = await f(c, {
|
|
4938
5000
|
temperature: n,
|
|
4939
5001
|
maxTokens: r
|
|
4940
|
-
})),
|
|
5002
|
+
})), gs(await l.invoke([new o("你是对话历史压缩助手。把下面按轮次索引的对话要点,改写成一段连贯、紧凑的中文摘要,保留关键事实、用户意图与已用工具,不要编造。直接输出摘要正文。"), new a(e)], { signal: t.signal })).trim();
|
|
4941
5003
|
} finally {
|
|
4942
5004
|
clearTimeout(s);
|
|
4943
5005
|
}
|
|
4944
5006
|
};
|
|
4945
5007
|
}
|
|
4946
|
-
function
|
|
5008
|
+
function vs(e) {
|
|
4947
5009
|
let t = e.titleLlm ?? e.summaryLlm ?? e.llm;
|
|
4948
5010
|
if (!t) return;
|
|
4949
|
-
let n =
|
|
5011
|
+
let n = hs(t) ? t : null, r = hs(t) ? null : t;
|
|
4950
5012
|
if (r && !r.apiKey) return;
|
|
4951
5013
|
let i = n;
|
|
4952
5014
|
return async (e) => {
|
|
@@ -4955,7 +5017,7 @@ function _s(e) {
|
|
|
4955
5017
|
return !i && r && (i = await f(r, {
|
|
4956
5018
|
temperature: 0,
|
|
4957
5019
|
maxTokens: 30
|
|
4958
|
-
})),
|
|
5020
|
+
})), gs(await i.invoke([new o("根据以下对话的主旨,生成一个简短的中文标题(不超过15个字,不要标点和引号,直接输出标题文字)。"), new a(t)], { signal: n.signal })).trim().replace(/^["'""「『]|["'""」』]$/g, "").split("\n")[0].slice(0, 20);
|
|
4959
5021
|
} catch {
|
|
4960
5022
|
return "";
|
|
4961
5023
|
} finally {
|
|
@@ -4963,10 +5025,10 @@ function _s(e) {
|
|
|
4963
5025
|
}
|
|
4964
5026
|
};
|
|
4965
5027
|
}
|
|
4966
|
-
function
|
|
5028
|
+
function ys() {
|
|
4967
5029
|
return `call_dec_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
|
|
4968
5030
|
}
|
|
4969
|
-
function
|
|
5031
|
+
function bs(e) {
|
|
4970
5032
|
let t = e.match(/```(?:json)?\s*([\s\S]*?)```/), n = t ? t[1] : e, r = n.indexOf("{"), i = n.lastIndexOf("}");
|
|
4971
5033
|
if (r < 0 || i < 0 || i <= r) return null;
|
|
4972
5034
|
try {
|
|
@@ -4975,21 +5037,21 @@ function ys(e) {
|
|
|
4975
5037
|
return null;
|
|
4976
5038
|
}
|
|
4977
5039
|
}
|
|
4978
|
-
function
|
|
5040
|
+
function xs(e) {
|
|
4979
5041
|
if (!e) return null;
|
|
4980
|
-
let t =
|
|
5042
|
+
let t = bs(e);
|
|
4981
5043
|
if (t == null) return null;
|
|
4982
|
-
let n =
|
|
5044
|
+
let n = ps.safeParse(t);
|
|
4983
5045
|
return n.success ? n.data : null;
|
|
4984
5046
|
}
|
|
4985
|
-
async function
|
|
5047
|
+
async function Ss(e, t, n, r) {
|
|
4986
5048
|
let i = [...n];
|
|
4987
5049
|
for (let n = 0; n < 3; n++) {
|
|
4988
5050
|
let n = await e.invoke(i, { signal: r }), a = n?.tool_calls ?? [];
|
|
4989
|
-
if (!a.length) return
|
|
5051
|
+
if (!a.length) return gs(n).trim();
|
|
4990
5052
|
i = [...i, n];
|
|
4991
5053
|
for (let e of a) {
|
|
4992
|
-
let n = e.id ??
|
|
5054
|
+
let n = e.id ?? ys();
|
|
4993
5055
|
try {
|
|
4994
5056
|
let r = await t.invoke(e.args ?? {}), a = typeof r == "string" ? r : r?.content ?? JSON.stringify(r);
|
|
4995
5057
|
i = [...i, new s({
|
|
@@ -5006,10 +5068,10 @@ async function xs(e, t, n, r) {
|
|
|
5006
5068
|
}
|
|
5007
5069
|
return "";
|
|
5008
5070
|
}
|
|
5009
|
-
function
|
|
5071
|
+
function Cs(e) {
|
|
5010
5072
|
let t = e.summaryLlm ?? e.llm;
|
|
5011
5073
|
if (!t) return;
|
|
5012
|
-
let n =
|
|
5074
|
+
let n = hs(t) ? t : null, r = hs(t) ? null : t;
|
|
5013
5075
|
if (r && !r.apiKey) return;
|
|
5014
5076
|
let i = e.decisionTimeoutMs ?? 6e3, s = e.decisionMaxTokens ?? 2048, c = n;
|
|
5015
5077
|
return async (e) => {
|
|
@@ -5021,12 +5083,12 @@ function Ss(e) {
|
|
|
5021
5083
|
}));
|
|
5022
5084
|
let n = c;
|
|
5023
5085
|
if (typeof n.bindTools != "function") return null;
|
|
5024
|
-
let i =
|
|
5086
|
+
let i = fs({
|
|
5025
5087
|
getMessages: e.getMessages,
|
|
5026
5088
|
getSnapshot: e.getSnapshot,
|
|
5027
5089
|
contextWindow: e.contextWindow
|
|
5028
5090
|
}), l = n.bindTools([i]), u = e.triggerMode === "token" ? "token 模式:必填 windowRatio(0~1 保留窗口预算比例,如 0.4);keepRounds 可选" : "轮数模式:必填 keepRounds(保留最近几轮,如 6);windowRatio 可选", d = [new o(`你是对话历史压缩决策助手。当前触发模式 = ${e.triggerMode}(${e.triggerReason})。先调用 inspect_context 查看上下文构成,再输出压缩决策 JSON。${u}。仅输出 JSON,不要多余文字/markdown。schema:{keepRounds?(int 0-50), windowRatio?(0-1), summarize:{mode:"index"|"llm"}, recallTopK?(int 0-10), preserveTools?(string[]≤10), reason?(≤200字)}。keepRounds/windowRatio 至少填一个。`), new a(`触发原因:${e.triggerReason}\n上下文窗口:${e.contextWindow ?? "未知"} tokens\n阈值比例:${e.thresholdRatio ?? "未知"}\n\n请决策压缩策略(先 inspect_context 查看,再输出 JSON)。`)];
|
|
5029
|
-
return
|
|
5091
|
+
return xs(await Ss(l, i, d, t.signal)) || xs(await Ss(l, i, [...d, new a("上一次输出无效(JSON 解析失败或 schema 校验不通过)。请只输出符合 schema 的压缩决策 JSON,不要多余文字/markdown 代码块。")], t.signal));
|
|
5030
5092
|
} catch {
|
|
5031
5093
|
return null;
|
|
5032
5094
|
} finally {
|
|
@@ -5034,22 +5096,22 @@ function Ss(e) {
|
|
|
5034
5096
|
}
|
|
5035
5097
|
};
|
|
5036
5098
|
}
|
|
5037
|
-
function
|
|
5038
|
-
let t = e.llm, n =
|
|
5099
|
+
function ws(e) {
|
|
5100
|
+
let t = e.llm, n = hs(e.llm) ? void 0 : e.llm;
|
|
5039
5101
|
return {
|
|
5040
5102
|
modelCaps: ni({
|
|
5041
5103
|
model: n?.model ?? t?.model ?? t?.modelName,
|
|
5042
5104
|
contextWindow: e.contextWindow ?? n?.contextWindow ?? t?.contextWindow,
|
|
5043
5105
|
maxOutputTokens: e.maxOutputTokens ?? n?.maxOutputTokens ?? t?.maxOutputTokens
|
|
5044
5106
|
}),
|
|
5045
|
-
summaryLlmInvoke:
|
|
5046
|
-
titleLlmInvoke:
|
|
5047
|
-
compressDecisionInvoke:
|
|
5107
|
+
summaryLlmInvoke: _s(e),
|
|
5108
|
+
titleLlmInvoke: vs(e),
|
|
5109
|
+
compressDecisionInvoke: Cs(e)
|
|
5048
5110
|
};
|
|
5049
5111
|
}
|
|
5050
5112
|
//#endregion
|
|
5051
5113
|
//#region src/core/sdk/conflictManager.ts
|
|
5052
|
-
function
|
|
5114
|
+
function Ts(e) {
|
|
5053
5115
|
let t = /* @__PURE__ */ Ot(null), n = 0;
|
|
5054
5116
|
function r(r) {
|
|
5055
5117
|
return new Promise((i) => {
|
|
@@ -5080,7 +5142,7 @@ function ws(e) {
|
|
|
5080
5142
|
}
|
|
5081
5143
|
//#endregion
|
|
5082
5144
|
//#region src/core/utils/id.ts
|
|
5083
|
-
function
|
|
5145
|
+
function Es() {
|
|
5084
5146
|
try {
|
|
5085
5147
|
if (typeof crypto < "u" && typeof crypto.randomUUID == "function") return crypto.randomUUID();
|
|
5086
5148
|
} catch {}
|
|
@@ -5088,7 +5150,7 @@ function Ts() {
|
|
|
5088
5150
|
}
|
|
5089
5151
|
//#endregion
|
|
5090
5152
|
//#region src/core/backends/storage.ts
|
|
5091
|
-
var
|
|
5153
|
+
var Ds = "chat-sdk", Os = 50 * 1024 * 1024, ks = 4 * 1024 * 1024, As = 10 * 1024 * 1024, js = .9, Ms = 500, Ns = 300, Ps = "__meta__", Fs = "v:1", Is = [
|
|
5092
5154
|
"messages",
|
|
5093
5155
|
"vfs",
|
|
5094
5156
|
"todos",
|
|
@@ -5099,51 +5161,51 @@ var Es = "chat-sdk", Ds = 50 * 1024 * 1024, Os = 4 * 1024 * 1024, ks = 10 * 1024
|
|
|
5099
5161
|
"workingMemory",
|
|
5100
5162
|
"focus"
|
|
5101
5163
|
];
|
|
5102
|
-
function Is(e) {
|
|
5103
|
-
return e === "local" || e === "session" ? Os : Ds;
|
|
5104
|
-
}
|
|
5105
5164
|
function Ls(e) {
|
|
5165
|
+
return e === "local" || e === "session" ? ks : Os;
|
|
5166
|
+
}
|
|
5167
|
+
function Rs(e) {
|
|
5106
5168
|
if (typeof e != "object" || !e) return !1;
|
|
5107
5169
|
let t = e;
|
|
5108
5170
|
return t.name === "QuotaExceededError" || t.name === "NS_ERROR_DOM_QUOTA_REACHED" || t.code === 22 || t.code === 1014;
|
|
5109
5171
|
}
|
|
5110
|
-
function
|
|
5172
|
+
function zs(e, t, n, r) {
|
|
5111
5173
|
return [
|
|
5112
|
-
|
|
5174
|
+
Fs,
|
|
5113
5175
|
e,
|
|
5114
5176
|
t,
|
|
5115
5177
|
n,
|
|
5116
5178
|
r
|
|
5117
5179
|
].join("::");
|
|
5118
5180
|
}
|
|
5119
|
-
function
|
|
5181
|
+
function Bs(e, t, n) {
|
|
5120
5182
|
return [
|
|
5121
|
-
|
|
5183
|
+
Fs,
|
|
5122
5184
|
e,
|
|
5123
5185
|
t,
|
|
5124
5186
|
n
|
|
5125
5187
|
].join("::") + "::";
|
|
5126
5188
|
}
|
|
5127
|
-
function
|
|
5189
|
+
function Vs(e, t) {
|
|
5128
5190
|
return [
|
|
5129
|
-
|
|
5191
|
+
Fs,
|
|
5130
5192
|
e,
|
|
5131
5193
|
t
|
|
5132
5194
|
].join("::") + "::";
|
|
5133
5195
|
}
|
|
5134
|
-
function
|
|
5135
|
-
return [
|
|
5196
|
+
function Hs(e) {
|
|
5197
|
+
return [Fs, e].join("::") + "::";
|
|
5136
5198
|
}
|
|
5137
|
-
var
|
|
5138
|
-
function
|
|
5139
|
-
|
|
5199
|
+
var Us = null;
|
|
5200
|
+
function Ws(e) {
|
|
5201
|
+
Us ||= new TextEncoder();
|
|
5140
5202
|
try {
|
|
5141
|
-
return
|
|
5203
|
+
return Us.encode(JSON.stringify(e)).length;
|
|
5142
5204
|
} catch {
|
|
5143
5205
|
return 0;
|
|
5144
5206
|
}
|
|
5145
5207
|
}
|
|
5146
|
-
function
|
|
5208
|
+
function Gs(e, t, n) {
|
|
5147
5209
|
let r = e.reduce((e, t) => e + t.bytes, 0);
|
|
5148
5210
|
if (r <= t) return [];
|
|
5149
5211
|
let i = t * n, a = [...e].sort((e, t) => e.lastAccessed - t.lastAccessed), o = [];
|
|
@@ -5153,7 +5215,7 @@ function Ws(e, t, n) {
|
|
|
5153
5215
|
}
|
|
5154
5216
|
return o;
|
|
5155
5217
|
}
|
|
5156
|
-
function
|
|
5218
|
+
function Ks() {
|
|
5157
5219
|
let e = /* @__PURE__ */ new Map();
|
|
5158
5220
|
return {
|
|
5159
5221
|
async get(t) {
|
|
@@ -5173,7 +5235,7 @@ function Gs() {
|
|
|
5173
5235
|
}
|
|
5174
5236
|
};
|
|
5175
5237
|
}
|
|
5176
|
-
function
|
|
5238
|
+
function qs(e) {
|
|
5177
5239
|
return new Promise((t, n) => {
|
|
5178
5240
|
if (typeof indexedDB > "u") {
|
|
5179
5241
|
n(/* @__PURE__ */ Error("indexedDB 不可用"));
|
|
@@ -5234,11 +5296,15 @@ function Ks(e) {
|
|
|
5234
5296
|
}, r.onerror = () => n(r.error);
|
|
5235
5297
|
});
|
|
5236
5298
|
}
|
|
5237
|
-
function
|
|
5299
|
+
function Js(e) {
|
|
5238
5300
|
return {
|
|
5239
5301
|
async get(t) {
|
|
5240
5302
|
let n = e.getItem(t);
|
|
5241
|
-
|
|
5303
|
+
if (n != null) try {
|
|
5304
|
+
return JSON.parse(n);
|
|
5305
|
+
} catch {
|
|
5306
|
+
return;
|
|
5307
|
+
}
|
|
5242
5308
|
},
|
|
5243
5309
|
async set(t, n) {
|
|
5244
5310
|
e.setItem(t, JSON.stringify(n));
|
|
@@ -5255,7 +5321,14 @@ function qs(e) {
|
|
|
5255
5321
|
r.sort();
|
|
5256
5322
|
for (let t of r) {
|
|
5257
5323
|
let r = e.getItem(t);
|
|
5258
|
-
if (r
|
|
5324
|
+
if (r == null) continue;
|
|
5325
|
+
let i;
|
|
5326
|
+
try {
|
|
5327
|
+
i = JSON.parse(r);
|
|
5328
|
+
} catch {
|
|
5329
|
+
continue;
|
|
5330
|
+
}
|
|
5331
|
+
if (n(t, i) === !1) return;
|
|
5259
5332
|
}
|
|
5260
5333
|
},
|
|
5261
5334
|
async clearPrefix(t) {
|
|
@@ -5268,12 +5341,12 @@ function qs(e) {
|
|
|
5268
5341
|
}
|
|
5269
5342
|
};
|
|
5270
5343
|
}
|
|
5271
|
-
function
|
|
5344
|
+
function Ys(e, t, n) {
|
|
5272
5345
|
let r = (e.get(t) ?? Promise.resolve()).then(n, n);
|
|
5273
5346
|
return e.set(t, r.then(() => void 0, () => void 0)), r;
|
|
5274
5347
|
}
|
|
5275
|
-
function
|
|
5276
|
-
let t = e.dbName ??
|
|
5348
|
+
function Xs(e = {}) {
|
|
5349
|
+
let t = e.dbName ?? Ds, n = e.backend ?? "indexed", r = e.maxBytes ?? Ls(n), i = e.maxBytesPerSession ?? As, a = e.evictionWatermark ?? js, o = e.debounceMs ?? Ms, s = /* @__PURE__ */ new Set();
|
|
5277
5350
|
function c(e) {
|
|
5278
5351
|
for (let t of s) try {
|
|
5279
5352
|
t(e);
|
|
@@ -5286,16 +5359,16 @@ function Ys(e = {}) {
|
|
|
5286
5359
|
try {
|
|
5287
5360
|
if (n === "indexed") {
|
|
5288
5361
|
if (typeof indexedDB > "u") throw Error("indexedDB 不可用");
|
|
5289
|
-
l = await
|
|
5362
|
+
l = await qs(t), d(!0);
|
|
5290
5363
|
} else if (n === "session") {
|
|
5291
5364
|
if (typeof sessionStorage > "u") throw Error("sessionStorage 不可用");
|
|
5292
|
-
l =
|
|
5365
|
+
l = Js(sessionStorage), d(!0);
|
|
5293
5366
|
} else if (n === "local") {
|
|
5294
5367
|
if (typeof localStorage > "u") throw Error("localStorage 不可用");
|
|
5295
|
-
l =
|
|
5296
|
-
} else l =
|
|
5368
|
+
l = Js(localStorage), d(!0);
|
|
5369
|
+
} else l = Ks(), d(!1);
|
|
5297
5370
|
} catch (e) {
|
|
5298
|
-
l =
|
|
5371
|
+
l = Ks();
|
|
5299
5372
|
let t = e instanceof Error ? e.message : String(e);
|
|
5300
5373
|
d(!1), Promise.resolve().then(() => c({
|
|
5301
5374
|
type: "degraded",
|
|
@@ -5305,10 +5378,10 @@ function Ys(e = {}) {
|
|
|
5305
5378
|
})();
|
|
5306
5379
|
let p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
|
|
5307
5380
|
function g(e, n, r, a) {
|
|
5308
|
-
let o =
|
|
5309
|
-
return
|
|
5381
|
+
let o = zs(t, r, a, Ps);
|
|
5382
|
+
return Ys(h, o, async () => {
|
|
5310
5383
|
let t = async () => {
|
|
5311
|
-
let t = await l.get(o), s = await l.get(e), u = s == null ? 0 :
|
|
5384
|
+
let t = await l.get(o), s = await l.get(e), u = s == null ? 0 : Ws(s), d = Ws(n), f = (t?.bytes ?? 0) + (d - u);
|
|
5312
5385
|
if (f > i) {
|
|
5313
5386
|
c({
|
|
5314
5387
|
type: "quota",
|
|
@@ -5330,12 +5403,12 @@ function Ys(e = {}) {
|
|
|
5330
5403
|
try {
|
|
5331
5404
|
await t();
|
|
5332
5405
|
} catch (e) {
|
|
5333
|
-
if (
|
|
5406
|
+
if (Rs(e) && !u) {
|
|
5334
5407
|
u = !0;
|
|
5335
5408
|
try {
|
|
5336
5409
|
await b();
|
|
5337
5410
|
} catch {}
|
|
5338
|
-
l =
|
|
5411
|
+
l = Ks(), Promise.resolve().then(() => c({
|
|
5339
5412
|
type: "degraded",
|
|
5340
5413
|
reason: "存储配额超限(QuotaExceededError),已淘汰最旧会话并降级内存"
|
|
5341
5414
|
}));
|
|
@@ -5347,7 +5420,7 @@ function Ys(e = {}) {
|
|
|
5347
5420
|
});
|
|
5348
5421
|
}
|
|
5349
5422
|
function _(e, n, r, i) {
|
|
5350
|
-
let a =
|
|
5423
|
+
let a = zs(t, e, n, r), s = p.get(a);
|
|
5351
5424
|
s && s.resolve();
|
|
5352
5425
|
let c = m.get(a);
|
|
5353
5426
|
return c && clearTimeout(c), new Promise((t) => {
|
|
@@ -5374,15 +5447,15 @@ function Ys(e = {}) {
|
|
|
5374
5447
|
function y() {
|
|
5375
5448
|
v ||= setTimeout(() => {
|
|
5376
5449
|
v = null, b();
|
|
5377
|
-
},
|
|
5450
|
+
}, Ns);
|
|
5378
5451
|
}
|
|
5379
5452
|
async function b() {
|
|
5380
5453
|
let e = [];
|
|
5381
|
-
await l.scan(
|
|
5454
|
+
await l.scan(Hs(t), (t, n) => {
|
|
5382
5455
|
t.endsWith("::__meta__") && e.push(n);
|
|
5383
5456
|
});
|
|
5384
|
-
let n =
|
|
5385
|
-
for (let e of n) await l.clearPrefix(
|
|
5457
|
+
let n = Gs(e, r, a);
|
|
5458
|
+
for (let e of n) await l.clearPrefix(Bs(t, e.agentId, e.sessionId)), c({
|
|
5386
5459
|
type: "evicted",
|
|
5387
5460
|
agentId: e.agentId,
|
|
5388
5461
|
sessionId: e.sessionId,
|
|
@@ -5393,13 +5466,13 @@ function Ys(e = {}) {
|
|
|
5393
5466
|
ready: f,
|
|
5394
5467
|
async listSessions(e) {
|
|
5395
5468
|
let n = [];
|
|
5396
|
-
return await l.scan(
|
|
5469
|
+
return await l.scan(Vs(t, e), (e, t) => {
|
|
5397
5470
|
e.endsWith("::__meta__") && n.push(t);
|
|
5398
5471
|
}), n.sort((e, t) => t.lastAccessed - e.lastAccessed);
|
|
5399
5472
|
},
|
|
5400
5473
|
async load(e, n) {
|
|
5401
|
-
let r =
|
|
5402
|
-
return await
|
|
5474
|
+
let r = zs(t, e, n, Ps);
|
|
5475
|
+
return await Ys(h, r, async () => {
|
|
5403
5476
|
let i = await l.get(r);
|
|
5404
5477
|
if (!i) return;
|
|
5405
5478
|
let a = {
|
|
@@ -5408,8 +5481,8 @@ function Ys(e = {}) {
|
|
|
5408
5481
|
todos: [],
|
|
5409
5482
|
memory: ""
|
|
5410
5483
|
};
|
|
5411
|
-
for (let r of
|
|
5412
|
-
let i = await l.get(
|
|
5484
|
+
for (let r of Is) {
|
|
5485
|
+
let i = await l.get(zs(t, e, n, r));
|
|
5413
5486
|
i != null && (a[r] = i);
|
|
5414
5487
|
}
|
|
5415
5488
|
return i.lastAccessed = Date.now(), await l.set(r, i), a;
|
|
@@ -5417,12 +5490,12 @@ function Ys(e = {}) {
|
|
|
5417
5490
|
},
|
|
5418
5491
|
async save(e, t, n) {
|
|
5419
5492
|
let r = [];
|
|
5420
|
-
for (let i of
|
|
5493
|
+
for (let i of Is) n[i] !== void 0 && r.push(_(e, t, i, n[i]));
|
|
5421
5494
|
await Promise.all(r);
|
|
5422
5495
|
},
|
|
5423
5496
|
async updateTitle(e, n, r) {
|
|
5424
|
-
let i =
|
|
5425
|
-
return
|
|
5497
|
+
let i = zs(t, e, n, Ps);
|
|
5498
|
+
return Ys(h, i, async () => {
|
|
5426
5499
|
let e = await l.get(i);
|
|
5427
5500
|
e && (e.title = r, e.lastAccessed = Date.now(), await l.set(i, e));
|
|
5428
5501
|
});
|
|
@@ -5438,10 +5511,10 @@ function Ys(e = {}) {
|
|
|
5438
5511
|
})), c({ type: "flush" }), await b();
|
|
5439
5512
|
},
|
|
5440
5513
|
async deleteSession(e, n) {
|
|
5441
|
-
await l.clearPrefix(
|
|
5514
|
+
await l.clearPrefix(Bs(t, e, n));
|
|
5442
5515
|
},
|
|
5443
5516
|
async createSession(e, n, r) {
|
|
5444
|
-
let i = r ??
|
|
5517
|
+
let i = r ?? Es(), a = Date.now(), o = {
|
|
5445
5518
|
agentId: e,
|
|
5446
5519
|
sessionId: i,
|
|
5447
5520
|
createdAt: a,
|
|
@@ -5449,7 +5522,7 @@ function Ys(e = {}) {
|
|
|
5449
5522
|
bytes: 0,
|
|
5450
5523
|
title: n
|
|
5451
5524
|
};
|
|
5452
|
-
return await l.set(
|
|
5525
|
+
return await l.set(zs(t, e, i, Ps), o), i;
|
|
5453
5526
|
},
|
|
5454
5527
|
onEvent(e) {
|
|
5455
5528
|
s.add(e);
|
|
@@ -5464,15 +5537,15 @@ function Ys(e = {}) {
|
|
|
5464
5537
|
}
|
|
5465
5538
|
//#endregion
|
|
5466
5539
|
//#region src/core/sdk/optionsResolver.ts
|
|
5467
|
-
function Xs(e) {
|
|
5468
|
-
return e === void 0 || e === !1 ? null : typeof e == "string" ? Ys({ backend: e }) : e.enabled === !1 ? null : Ys(e);
|
|
5469
|
-
}
|
|
5470
5540
|
function Zs(e) {
|
|
5541
|
+
return e === void 0 || e === !1 ? null : typeof e == "string" ? Xs({ backend: e }) : e.enabled === !1 ? null : Xs(e);
|
|
5542
|
+
}
|
|
5543
|
+
function Qs(e) {
|
|
5471
5544
|
return e.dialog ?? {};
|
|
5472
5545
|
}
|
|
5473
5546
|
//#endregion
|
|
5474
5547
|
//#region src/core/capabilities.ts
|
|
5475
|
-
var
|
|
5548
|
+
var $s = [
|
|
5476
5549
|
{
|
|
5477
5550
|
name: "dataOps",
|
|
5478
5551
|
defaultOn: !0
|
|
@@ -5561,13 +5634,13 @@ var Qs = [
|
|
|
5561
5634
|
requires: ["summarization"]
|
|
5562
5635
|
}
|
|
5563
5636
|
];
|
|
5564
|
-
function
|
|
5637
|
+
function ec(e) {
|
|
5565
5638
|
let t = {};
|
|
5566
|
-
for (let n of
|
|
5639
|
+
for (let n of $s) {
|
|
5567
5640
|
let r = e?.[n.name];
|
|
5568
5641
|
t[n.name] = n.defaultOn ? r !== !1 : r === !0;
|
|
5569
5642
|
}
|
|
5570
|
-
for (let e of
|
|
5643
|
+
for (let e of $s) if (e.requires && t[e.name]) {
|
|
5571
5644
|
for (let n of e.requires) if (!t[n]) {
|
|
5572
5645
|
t[e.name] = !1;
|
|
5573
5646
|
break;
|
|
@@ -5577,7 +5650,7 @@ function $s(e) {
|
|
|
5577
5650
|
}
|
|
5578
5651
|
//#endregion
|
|
5579
5652
|
//#region src/core/sdk/events.ts
|
|
5580
|
-
function
|
|
5653
|
+
function tc(e) {
|
|
5581
5654
|
let t = /* @__PURE__ */ new Set(), n = (n) => {
|
|
5582
5655
|
if (n.type !== "approval_request") {
|
|
5583
5656
|
if (e) try {
|
|
@@ -5603,7 +5676,7 @@ function ec(e) {
|
|
|
5603
5676
|
}
|
|
5604
5677
|
//#endregion
|
|
5605
5678
|
//#region src/core/sdk/contextPreset.ts
|
|
5606
|
-
var
|
|
5679
|
+
var nc = {
|
|
5607
5680
|
auto: {
|
|
5608
5681
|
summaryThresholdRatio: .5,
|
|
5609
5682
|
windowRatio: .4,
|
|
@@ -5631,7 +5704,7 @@ var tc = {
|
|
|
5631
5704
|
enableRecall: !0,
|
|
5632
5705
|
enableLLMSummary: !0
|
|
5633
5706
|
}
|
|
5634
|
-
},
|
|
5707
|
+
}, rc = {
|
|
5635
5708
|
auto: ["describe_data", "read"],
|
|
5636
5709
|
conservative: ["describe_data"],
|
|
5637
5710
|
aggressive: ["describe_data", "read"],
|
|
@@ -5642,8 +5715,8 @@ var tc = {
|
|
|
5642
5715
|
"search_data"
|
|
5643
5716
|
]
|
|
5644
5717
|
};
|
|
5645
|
-
function
|
|
5646
|
-
let n =
|
|
5718
|
+
function ic(e, t) {
|
|
5719
|
+
let n = nc[e.contextPreset ?? "auto"] ?? {}, r = e.contextOptions === !1 ? {} : e.contextOptions ?? {};
|
|
5647
5720
|
return {
|
|
5648
5721
|
...n,
|
|
5649
5722
|
...r,
|
|
@@ -5653,7 +5726,7 @@ function rc(e, t) {
|
|
|
5653
5726
|
}
|
|
5654
5727
|
//#endregion
|
|
5655
5728
|
//#region src/core/sdk/middlewareStack.ts
|
|
5656
|
-
var
|
|
5729
|
+
var ac = {
|
|
5657
5730
|
dataHint: 10,
|
|
5658
5731
|
usageHints: 20,
|
|
5659
5732
|
todos: 30,
|
|
@@ -5670,29 +5743,29 @@ var ic = {
|
|
|
5670
5743
|
subagents: 140,
|
|
5671
5744
|
augmentSystem: 150
|
|
5672
5745
|
};
|
|
5673
|
-
function
|
|
5746
|
+
function oc(e) {
|
|
5674
5747
|
return e.map((e, t) => ({
|
|
5675
5748
|
m: e,
|
|
5676
5749
|
i: t,
|
|
5677
|
-
p:
|
|
5750
|
+
p: ac[e.name] ?? Infinity
|
|
5678
5751
|
})).sort((e, t) => e.p - t.p || e.i - t.i).map((e) => e.m);
|
|
5679
5752
|
}
|
|
5680
5753
|
//#endregion
|
|
5681
5754
|
//#region src/core/tools/jsonUtils.ts
|
|
5682
|
-
var
|
|
5755
|
+
var sc = /* @__PURE__ */ new Set([
|
|
5683
5756
|
"__proto__",
|
|
5684
5757
|
"constructor",
|
|
5685
5758
|
"prototype"
|
|
5686
5759
|
]);
|
|
5687
|
-
function
|
|
5688
|
-
return e.split(".").some((e) =>
|
|
5760
|
+
function cc(e) {
|
|
5761
|
+
return e.split(".").some((e) => sc.has(e));
|
|
5689
5762
|
}
|
|
5690
|
-
function
|
|
5691
|
-
if (!(!t || typeof t != "object" || Array.isArray(t))) for (let n of Object.keys(t))
|
|
5763
|
+
function lc(e, t) {
|
|
5764
|
+
if (!(!t || typeof t != "object" || Array.isArray(t))) for (let n of Object.keys(t)) sc.has(n) || (e[n] = t[n]);
|
|
5692
5765
|
}
|
|
5693
5766
|
function Z(e, t) {
|
|
5694
5767
|
if (!t) return e;
|
|
5695
|
-
if (
|
|
5768
|
+
if (cc(t)) return;
|
|
5696
5769
|
let n = t.split("."), r = e;
|
|
5697
5770
|
for (let e of n) {
|
|
5698
5771
|
if (r == null) return;
|
|
@@ -5700,8 +5773,8 @@ function Z(e, t) {
|
|
|
5700
5773
|
}
|
|
5701
5774
|
return r;
|
|
5702
5775
|
}
|
|
5703
|
-
function
|
|
5704
|
-
if (!t ||
|
|
5776
|
+
function uc(e, t, n) {
|
|
5777
|
+
if (!t || cc(t)) return;
|
|
5705
5778
|
let r = t.split("."), i = e;
|
|
5706
5779
|
for (let e = 0; e < r.length - 1; e++) {
|
|
5707
5780
|
let t = r[e];
|
|
@@ -5709,8 +5782,8 @@ function lc(e, t, n) {
|
|
|
5709
5782
|
}
|
|
5710
5783
|
i[r[r.length - 1]] = n;
|
|
5711
5784
|
}
|
|
5712
|
-
function
|
|
5713
|
-
if (!t ||
|
|
5785
|
+
function dc(e, t) {
|
|
5786
|
+
if (!t || cc(t)) return !1;
|
|
5714
5787
|
let n = t.split("."), r = e;
|
|
5715
5788
|
for (let e = 0; e < n.length - 1; e++) {
|
|
5716
5789
|
if (r == null) return !1;
|
|
@@ -5719,10 +5792,10 @@ function uc(e, t) {
|
|
|
5719
5792
|
let i = n[n.length - 1];
|
|
5720
5793
|
return r == null || !(i in r) ? !1 : (Array.isArray(r) && /^\d+$/.test(i) ? r.splice(Number(i), 1) : delete r[i], !0);
|
|
5721
5794
|
}
|
|
5722
|
-
function
|
|
5795
|
+
function fc(e) {
|
|
5723
5796
|
return e === void 0 ? void 0 : JSON.parse(JSON.stringify(e));
|
|
5724
5797
|
}
|
|
5725
|
-
function
|
|
5798
|
+
function pc(e) {
|
|
5726
5799
|
if (typeof e != "string") return { parsed: e };
|
|
5727
5800
|
let t = e.trim();
|
|
5728
5801
|
if (!t) return { parsed: e };
|
|
@@ -5733,20 +5806,20 @@ function fc(e) {
|
|
|
5733
5806
|
return n ? { parseError: t } : { parsed: e };
|
|
5734
5807
|
}
|
|
5735
5808
|
}
|
|
5736
|
-
function
|
|
5809
|
+
function mc(e, t) {
|
|
5737
5810
|
if (typeof e != "object" || !e) return e;
|
|
5738
5811
|
let n = new Set(t);
|
|
5739
|
-
if (Array.isArray(e)) return e.map((e) =>
|
|
5812
|
+
if (Array.isArray(e)) return e.map((e) => mc(e, t));
|
|
5740
5813
|
let r = {};
|
|
5741
5814
|
for (let t of Object.keys(e)) n.has(t) && (r[t] = e[t]);
|
|
5742
5815
|
return r;
|
|
5743
5816
|
}
|
|
5744
|
-
function
|
|
5817
|
+
function hc(e, t) {
|
|
5745
5818
|
if (typeof e != "object" || !e) return e;
|
|
5746
5819
|
if (t <= 0) return Array.isArray(e) ? `[...${e.length}]` : "{...}";
|
|
5747
|
-
if (Array.isArray(e)) return e.map((e) =>
|
|
5820
|
+
if (Array.isArray(e)) return e.map((e) => hc(e, t - 1));
|
|
5748
5821
|
let n = {};
|
|
5749
|
-
for (let r of Object.keys(e)) n[r] =
|
|
5822
|
+
for (let r of Object.keys(e)) n[r] = hc(e[r], t - 1);
|
|
5750
5823
|
return n;
|
|
5751
5824
|
}
|
|
5752
5825
|
function Q(e, t = Infinity) {
|
|
@@ -5768,7 +5841,7 @@ function Q(e, t = Infinity) {
|
|
|
5768
5841
|
}
|
|
5769
5842
|
return r.length > t && (r = r.slice(0, t) + `\n…[已截断,原长度 ${r.length}]`), r;
|
|
5770
5843
|
}
|
|
5771
|
-
function
|
|
5844
|
+
function gc(e, t = 0) {
|
|
5772
5845
|
let n = 3735928559 ^ t, r = 1103547991 ^ t;
|
|
5773
5846
|
for (let t = 0; t < e.length; t++) {
|
|
5774
5847
|
let i = e.charCodeAt(t);
|
|
@@ -5777,31 +5850,31 @@ function hc(e, t = 0) {
|
|
|
5777
5850
|
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);
|
|
5778
5851
|
}
|
|
5779
5852
|
function $(e) {
|
|
5780
|
-
return
|
|
5853
|
+
return gc(Q(e)).toString(36);
|
|
5781
5854
|
}
|
|
5782
|
-
function
|
|
5783
|
-
if (t === "set") return n ? (
|
|
5784
|
-
if (t === "remove") return n ? (
|
|
5855
|
+
function _c(e, t, n, r) {
|
|
5856
|
+
if (t === "set") return n ? (uc(e, n, r), null) : "set 操作需要 jsonPath(整体替换请用 set_data)";
|
|
5857
|
+
if (t === "remove") return n ? (dc(e, n), null) : "remove 操作需要 jsonPath";
|
|
5785
5858
|
if (t === "merge") {
|
|
5786
5859
|
let t = n ? Z(e, n) : e;
|
|
5787
|
-
return typeof t != "object" || !t || Array.isArray(t) ? `merge 目标${n ? `(${n})` : "(根)"}不是对象` : (
|
|
5860
|
+
return typeof t != "object" || !t || Array.isArray(t) ? `merge 目标${n ? `(${n})` : "(根)"}不是对象` : (lc(t, r), null);
|
|
5788
5861
|
}
|
|
5789
5862
|
let i = n ? Z(e, n) : e;
|
|
5790
5863
|
return Array.isArray(i) ? (Array.isArray(r) ? i.push(...r) : i.push(r), null) : `append 目标${n ? `(${n})` : "(根)"}不是数组`;
|
|
5791
5864
|
}
|
|
5792
|
-
function
|
|
5793
|
-
if (t === "set")
|
|
5794
|
-
else if (t === "remove")
|
|
5795
|
-
else if (t === "merge")
|
|
5865
|
+
function vc(e, t, n, r) {
|
|
5866
|
+
if (t === "set") uc(e, n, r);
|
|
5867
|
+
else if (t === "remove") dc(e, n);
|
|
5868
|
+
else if (t === "merge") lc(n ? Z(e, n) : e, r);
|
|
5796
5869
|
else {
|
|
5797
5870
|
let t = n ? Z(e, n) : e;
|
|
5798
5871
|
Array.isArray(r) ? t.push(...r) : t.push(r);
|
|
5799
5872
|
}
|
|
5800
5873
|
}
|
|
5801
|
-
function vc(e, t) {
|
|
5802
|
-
typeof e == "object" && e && yc(e, t);
|
|
5803
|
-
}
|
|
5804
5874
|
function yc(e, t) {
|
|
5875
|
+
typeof e == "object" && e && bc(e, t);
|
|
5876
|
+
}
|
|
5877
|
+
function bc(e, t) {
|
|
5805
5878
|
if (Array.isArray(e)) {
|
|
5806
5879
|
e.length = 0, Array.isArray(t) && e.push(...t);
|
|
5807
5880
|
return;
|
|
@@ -5810,7 +5883,7 @@ function yc(e, t) {
|
|
|
5810
5883
|
for (let t of Object.keys(e)) t in n || delete e[t];
|
|
5811
5884
|
for (let t of Object.keys(n)) e[t] = n[t];
|
|
5812
5885
|
}
|
|
5813
|
-
function
|
|
5886
|
+
function xc(e, t, n = "") {
|
|
5814
5887
|
let r = [];
|
|
5815
5888
|
if (!(typeof e == "object" && e) || !(typeof t == "object" && t) || Array.isArray(e) !== Array.isArray(t)) return e !== t && r.push({
|
|
5816
5889
|
path: n || "(root)",
|
|
@@ -5829,14 +5902,14 @@ function bc(e, t, n = "") {
|
|
|
5829
5902
|
path: i,
|
|
5830
5903
|
from: e[a],
|
|
5831
5904
|
to: void 0
|
|
5832
|
-
}) : r.push(...
|
|
5905
|
+
}) : r.push(...xc(e[a], t[a], i));
|
|
5833
5906
|
}
|
|
5834
5907
|
return r;
|
|
5835
5908
|
}
|
|
5836
5909
|
let i = e, a = t, o = /* @__PURE__ */ new Set([...Object.keys(i), ...Object.keys(a)]);
|
|
5837
5910
|
for (let e of o) {
|
|
5838
5911
|
let t = n ? `${n}.${e}` : e;
|
|
5839
|
-
e in i ? e in a ? r.push(...
|
|
5912
|
+
e in i ? e in a ? r.push(...xc(i[e], a[e], t)) : r.push({
|
|
5840
5913
|
path: t,
|
|
5841
5914
|
from: i[e],
|
|
5842
5915
|
to: void 0
|
|
@@ -5848,48 +5921,48 @@ function bc(e, t, n = "") {
|
|
|
5848
5921
|
}
|
|
5849
5922
|
return r;
|
|
5850
5923
|
}
|
|
5851
|
-
var
|
|
5924
|
+
var Sc = {
|
|
5852
5925
|
largeResults: 4 * 1024 * 1024,
|
|
5853
5926
|
drafts: 2 * 1024 * 1024,
|
|
5854
5927
|
userFiles: 2 * 1024 * 1024,
|
|
5855
5928
|
resources: 4 * 1024 * 1024
|
|
5856
|
-
},
|
|
5929
|
+
}, Cc = [
|
|
5857
5930
|
"largeResults",
|
|
5858
5931
|
"drafts",
|
|
5859
5932
|
"userFiles",
|
|
5860
5933
|
"resources"
|
|
5861
|
-
],
|
|
5862
|
-
function
|
|
5934
|
+
], wc = .9;
|
|
5935
|
+
function Tc(e, t = {}) {
|
|
5863
5936
|
let n = Object.create(null);
|
|
5864
|
-
if (e) for (let [t, r] of Object.entries(e)) n[
|
|
5937
|
+
if (e) for (let [t, r] of Object.entries(e)) n[kc(t)] = {
|
|
5865
5938
|
content: r,
|
|
5866
|
-
updatedAt:
|
|
5939
|
+
updatedAt: jc()
|
|
5867
5940
|
};
|
|
5868
5941
|
let { persist: r } = t, i = t.maxBytes ?? 8388608, a = {
|
|
5869
|
-
...
|
|
5942
|
+
...Sc,
|
|
5870
5943
|
...t.poolBytes ?? {}
|
|
5871
5944
|
};
|
|
5872
5945
|
function o(e) {
|
|
5873
|
-
let t =
|
|
5946
|
+
let t = kc(e);
|
|
5874
5947
|
return t.startsWith("large_results/") ? "largeResults" : t.startsWith("drafts/") ? "drafts" : t.startsWith("resources/") ? "resources" : "userFiles";
|
|
5875
5948
|
}
|
|
5876
5949
|
function s(e) {
|
|
5877
5950
|
let t = 0;
|
|
5878
|
-
for (let [r, i] of Object.entries(n)) o(r) === e && (t +=
|
|
5951
|
+
for (let [r, i] of Object.entries(n)) o(r) === e && (t += Dc(i.content));
|
|
5879
5952
|
return t;
|
|
5880
5953
|
}
|
|
5881
5954
|
function c() {
|
|
5882
|
-
for (let e of
|
|
5955
|
+
for (let e of Cc) {
|
|
5883
5956
|
let t = a[e];
|
|
5884
5957
|
if (s(e) <= t) continue;
|
|
5885
|
-
let r = t *
|
|
5958
|
+
let r = t * wc, i = e === "largeResults", c = i && s(e) > t * 1.5;
|
|
5886
5959
|
c && console.warn(`[page-agent-sdk] vfs large_results 池 ${s(e)} > ${Math.round(t * 1.5)}(被引用撑爆)→ 无视 protectedRefs 强制删`);
|
|
5887
5960
|
let l = Object.entries(n).filter(([t]) => o(t) === e).sort((e, t) => e[1].updatedAt - t[1].updatedAt);
|
|
5888
5961
|
for (let [t] of l) if (!(i && !c && u.has(t)) && (delete n[t], s(e) <= r)) break;
|
|
5889
5962
|
}
|
|
5890
|
-
if (
|
|
5891
|
-
let e = i *
|
|
5892
|
-
for (let [i] of r) if (!(o(i) === "largeResults" && !t && u.has(i)) && (delete n[i],
|
|
5963
|
+
if (Oc(n) > i) {
|
|
5964
|
+
let e = i * wc, t = Oc(n) > i * 1.5, r = Object.entries(n).sort((e, t) => e[1].updatedAt - t[1].updatedAt);
|
|
5965
|
+
for (let [i] of r) if (!(o(i) === "largeResults" && !t && u.has(i)) && (delete n[i], Oc(n) <= e)) break;
|
|
5893
5966
|
}
|
|
5894
5967
|
}
|
|
5895
5968
|
let l = !0, u = /* @__PURE__ */ new Set(), d = null;
|
|
@@ -5925,7 +5998,7 @@ function wc(e, t = {}) {
|
|
|
5925
5998
|
}
|
|
5926
5999
|
};
|
|
5927
6000
|
return r && (m.hydrate = (e) => {
|
|
5928
|
-
for (let [t, r] of Object.entries(e)) n[
|
|
6001
|
+
for (let [t, r] of Object.entries(e)) n[kc(t)] = r;
|
|
5929
6002
|
c(), l = !0;
|
|
5930
6003
|
}, m.flush = () => {
|
|
5931
6004
|
d &&= (clearTimeout(d), null), f();
|
|
@@ -5934,19 +6007,19 @@ function wc(e, t = {}) {
|
|
|
5934
6007
|
p(), l = !0;
|
|
5935
6008
|
}), m;
|
|
5936
6009
|
}
|
|
5937
|
-
var
|
|
5938
|
-
function Ec(e) {
|
|
5939
|
-
return Tc ||= new TextEncoder(), Tc.encode(e).length;
|
|
5940
|
-
}
|
|
6010
|
+
var Ec = null;
|
|
5941
6011
|
function Dc(e) {
|
|
6012
|
+
return Ec ||= new TextEncoder(), Ec.encode(e).length;
|
|
6013
|
+
}
|
|
6014
|
+
function Oc(e) {
|
|
5942
6015
|
let t = 0;
|
|
5943
|
-
for (let n of Object.values(e)) t +=
|
|
6016
|
+
for (let n of Object.values(e)) t += Dc(n.content);
|
|
5944
6017
|
return t;
|
|
5945
6018
|
}
|
|
5946
|
-
function
|
|
6019
|
+
function kc(e) {
|
|
5947
6020
|
return e.replace(/^\/+/, "").replace(/\/+/g, "/");
|
|
5948
6021
|
}
|
|
5949
|
-
function
|
|
6022
|
+
function Ac(e) {
|
|
5950
6023
|
let t = "";
|
|
5951
6024
|
for (let n = 0; n < e.length; n++) {
|
|
5952
6025
|
let r = e[n];
|
|
@@ -5954,10 +6027,10 @@ function kc(e) {
|
|
|
5954
6027
|
}
|
|
5955
6028
|
return RegExp("^" + t + "$");
|
|
5956
6029
|
}
|
|
5957
|
-
function
|
|
6030
|
+
function jc() {
|
|
5958
6031
|
return Date.now();
|
|
5959
6032
|
}
|
|
5960
|
-
var
|
|
6033
|
+
var Mc = [
|
|
5961
6034
|
"vfs_read",
|
|
5962
6035
|
"vfs_write",
|
|
5963
6036
|
"vfs_edit",
|
|
@@ -5968,10 +6041,10 @@ var jc = [
|
|
|
5968
6041
|
"vfs_json_patch",
|
|
5969
6042
|
"vfs_rm"
|
|
5970
6043
|
];
|
|
5971
|
-
function
|
|
6044
|
+
function Nc(e) {
|
|
5972
6045
|
return [
|
|
5973
6046
|
r(async ({ path: t, offset: n, limit: r }) => {
|
|
5974
|
-
let i = e.files[
|
|
6047
|
+
let i = e.files[kc(t)];
|
|
5975
6048
|
if (!i) return Y({
|
|
5976
6049
|
code: "NOT_FOUND",
|
|
5977
6050
|
path: t,
|
|
@@ -6000,9 +6073,9 @@ function Mc(e) {
|
|
|
6000
6073
|
hint: "jsonString=true 要求 content 是合法 JSON;检查引号/逗号/括号配对;或省略 jsonString 写纯文本"
|
|
6001
6074
|
});
|
|
6002
6075
|
}
|
|
6003
|
-
return e.files[
|
|
6076
|
+
return e.files[kc(t)] = {
|
|
6004
6077
|
content: n,
|
|
6005
|
-
updatedAt:
|
|
6078
|
+
updatedAt: jc()
|
|
6006
6079
|
}, `已写入 ${t}(${n.length} 字符)${r ? "(JSON 校验通过)" : ""}`;
|
|
6007
6080
|
}, {
|
|
6008
6081
|
name: "vfs_write",
|
|
@@ -6014,7 +6087,7 @@ function Mc(e) {
|
|
|
6014
6087
|
})
|
|
6015
6088
|
}),
|
|
6016
6089
|
r(async ({ path: t, oldString: n, newString: r }) => {
|
|
6017
|
-
let i =
|
|
6090
|
+
let i = kc(t), a = e.files[i];
|
|
6018
6091
|
if (!a) return Y({
|
|
6019
6092
|
code: "NOT_FOUND",
|
|
6020
6093
|
path: t,
|
|
@@ -6044,7 +6117,7 @@ function Mc(e) {
|
|
|
6044
6117
|
}
|
|
6045
6118
|
return e.files[i] = {
|
|
6046
6119
|
content: a.content.replace(n, r),
|
|
6047
|
-
updatedAt:
|
|
6120
|
+
updatedAt: jc()
|
|
6048
6121
|
}, `已替换 ${t} 中 1 处。`;
|
|
6049
6122
|
}, {
|
|
6050
6123
|
name: "vfs_edit",
|
|
@@ -6066,7 +6139,7 @@ function Mc(e) {
|
|
|
6066
6139
|
r(async ({ pattern: t }) => {
|
|
6067
6140
|
let n;
|
|
6068
6141
|
try {
|
|
6069
|
-
n =
|
|
6142
|
+
n = Ac(t);
|
|
6070
6143
|
} catch (e) {
|
|
6071
6144
|
return Y({
|
|
6072
6145
|
code: "GLOB_INVALID",
|
|
@@ -6095,7 +6168,7 @@ function Mc(e) {
|
|
|
6095
6168
|
details: { pattern: t }
|
|
6096
6169
|
});
|
|
6097
6170
|
}
|
|
6098
|
-
let i = n ? [
|
|
6171
|
+
let i = n ? [kc(n)] : Object.keys(e.files), a = [];
|
|
6099
6172
|
for (let t of i) {
|
|
6100
6173
|
let n = e.files[t];
|
|
6101
6174
|
n && n.content.split("\n").forEach((e, n) => {
|
|
@@ -6112,7 +6185,7 @@ function Mc(e) {
|
|
|
6112
6185
|
})
|
|
6113
6186
|
}),
|
|
6114
6187
|
r(async ({ path: t, jsonPath: n }) => {
|
|
6115
|
-
let r =
|
|
6188
|
+
let r = kc(t), i = e.files[r];
|
|
6116
6189
|
if (!i) return Y({
|
|
6117
6190
|
code: "NOT_FOUND",
|
|
6118
6191
|
path: t,
|
|
@@ -6149,7 +6222,7 @@ function Mc(e) {
|
|
|
6149
6222
|
})
|
|
6150
6223
|
}),
|
|
6151
6224
|
r(async ({ path: t, patches: n }) => {
|
|
6152
|
-
let r =
|
|
6225
|
+
let r = kc(t), i = e.files[r];
|
|
6153
6226
|
if (!i) return Y({
|
|
6154
6227
|
code: "NOT_FOUND",
|
|
6155
6228
|
path: t,
|
|
@@ -6167,9 +6240,9 @@ function Mc(e) {
|
|
|
6167
6240
|
hint: "vfs_json_patch 要求文件内容是合法 JSON"
|
|
6168
6241
|
});
|
|
6169
6242
|
}
|
|
6170
|
-
let o =
|
|
6243
|
+
let o = fc(a), s = [];
|
|
6171
6244
|
for (let e of n) {
|
|
6172
|
-
let n =
|
|
6245
|
+
let n = _c(o, e.op, e.jsonPath, e.value);
|
|
6173
6246
|
if (n) return Y({
|
|
6174
6247
|
code: "PATCH_FAILED",
|
|
6175
6248
|
path: t,
|
|
@@ -6182,7 +6255,7 @@ function Mc(e) {
|
|
|
6182
6255
|
let c = JSON.stringify(o);
|
|
6183
6256
|
return e.files[r] = {
|
|
6184
6257
|
content: c,
|
|
6185
|
-
updatedAt:
|
|
6258
|
+
updatedAt: jc()
|
|
6186
6259
|
}, `已对 ${t} 应用 ${n.length} 个 patch(影响 ${s.length} 处:${s.join(", ")}),文件现 ${c.length} 字符`;
|
|
6187
6260
|
}, {
|
|
6188
6261
|
name: "vfs_json_patch",
|
|
@@ -6202,7 +6275,7 @@ function Mc(e) {
|
|
|
6202
6275
|
})
|
|
6203
6276
|
}),
|
|
6204
6277
|
r(async ({ path: t }) => {
|
|
6205
|
-
let n =
|
|
6278
|
+
let n = kc(t);
|
|
6206
6279
|
return e.files[n] ? (delete e.files[n], `已删除 ${t}`) : Y({
|
|
6207
6280
|
code: "NOT_FOUND",
|
|
6208
6281
|
path: t,
|
|
@@ -6216,17 +6289,17 @@ function Mc(e) {
|
|
|
6216
6289
|
})
|
|
6217
6290
|
];
|
|
6218
6291
|
}
|
|
6219
|
-
function
|
|
6292
|
+
function Pc(e) {
|
|
6220
6293
|
return {
|
|
6221
6294
|
name: "vfs",
|
|
6222
|
-
tools:
|
|
6295
|
+
tools: Nc(e),
|
|
6223
6296
|
beforeAgent: () => ({ files: e.files })
|
|
6224
6297
|
};
|
|
6225
6298
|
}
|
|
6226
6299
|
//#endregion
|
|
6227
6300
|
//#region src/core/tools/dataSlotQuery.ts
|
|
6228
|
-
var
|
|
6229
|
-
function
|
|
6301
|
+
var Fc = /[\w$-]/;
|
|
6302
|
+
function Ic(e) {
|
|
6230
6303
|
let t = [], n = e.trim(), r = +(n[0] === "$");
|
|
6231
6304
|
for (; r < n.length;) {
|
|
6232
6305
|
let e = n[r];
|
|
@@ -6237,7 +6310,7 @@ function Fc(e) {
|
|
|
6237
6310
|
continue;
|
|
6238
6311
|
}
|
|
6239
6312
|
let e = "";
|
|
6240
|
-
for (; r < n.length &&
|
|
6313
|
+
for (; r < n.length && Fc.test(n[r]);) e += n[r++];
|
|
6241
6314
|
if (!e) throw Error("JSONPath: .. 后缺属性名");
|
|
6242
6315
|
t.push({
|
|
6243
6316
|
type: "descendKey",
|
|
@@ -6250,7 +6323,7 @@ function Fc(e) {
|
|
|
6250
6323
|
continue;
|
|
6251
6324
|
}
|
|
6252
6325
|
let e = "";
|
|
6253
|
-
for (; r < n.length &&
|
|
6326
|
+
for (; r < n.length && Fc.test(n[r]);) e += n[r++];
|
|
6254
6327
|
if (!e) throw Error("JSONPath: . 后缺属性名");
|
|
6255
6328
|
t.push({
|
|
6256
6329
|
type: "key",
|
|
@@ -6306,7 +6379,7 @@ function Fc(e) {
|
|
|
6306
6379
|
}
|
|
6307
6380
|
return t;
|
|
6308
6381
|
}
|
|
6309
|
-
function
|
|
6382
|
+
function Lc(e) {
|
|
6310
6383
|
let t = [], n = 0, r = e.trim();
|
|
6311
6384
|
for (; n < r.length;) {
|
|
6312
6385
|
let e = r[n];
|
|
@@ -6351,7 +6424,7 @@ function Ic(e) {
|
|
|
6351
6424
|
}
|
|
6352
6425
|
return t;
|
|
6353
6426
|
}
|
|
6354
|
-
var
|
|
6427
|
+
var Rc = class {
|
|
6355
6428
|
toks;
|
|
6356
6429
|
item;
|
|
6357
6430
|
pos = 0;
|
|
@@ -6387,12 +6460,12 @@ var Lc = class {
|
|
|
6387
6460
|
return this.next(), e;
|
|
6388
6461
|
}
|
|
6389
6462
|
let e = this.operand(), t = this.peek();
|
|
6390
|
-
return t === "==" || t === "!=" || t === "<" || t === "<=" || t === ">" || t === ">=" ? (this.next(),
|
|
6463
|
+
return t === "==" || t === "!=" || t === "<" || t === "<=" || t === ">" || t === ">=" ? (this.next(), Vc(t, e, this.operand())) : zc(e);
|
|
6391
6464
|
}
|
|
6392
6465
|
operand() {
|
|
6393
6466
|
let e = this.next();
|
|
6394
6467
|
if (e === void 0) throw Error("过滤表达式:缺操作数");
|
|
6395
|
-
if (e.startsWith("@")) return
|
|
6468
|
+
if (e.startsWith("@")) return Bc(e, this.item);
|
|
6396
6469
|
if (e[0] === "'" || e[0] === "\"") return e.slice(1, -1);
|
|
6397
6470
|
if (e === "true") return !0;
|
|
6398
6471
|
if (e === "false") return !1;
|
|
@@ -6402,10 +6475,10 @@ var Lc = class {
|
|
|
6402
6475
|
throw Error(`过滤表达式:未知操作数 '${e}'`);
|
|
6403
6476
|
}
|
|
6404
6477
|
};
|
|
6405
|
-
function
|
|
6478
|
+
function zc(e) {
|
|
6406
6479
|
return !!e && e !== 0 && e !== "" && e !== null;
|
|
6407
6480
|
}
|
|
6408
|
-
function
|
|
6481
|
+
function Bc(e, t) {
|
|
6409
6482
|
let n = e.split(".").filter((e) => e && e !== "@"), r = t;
|
|
6410
6483
|
for (let e of n) {
|
|
6411
6484
|
if (typeof r != "object" || !r) return;
|
|
@@ -6413,7 +6486,7 @@ function zc(e, t) {
|
|
|
6413
6486
|
}
|
|
6414
6487
|
return r;
|
|
6415
6488
|
}
|
|
6416
|
-
function
|
|
6489
|
+
function Vc(e, t, n) {
|
|
6417
6490
|
switch (e) {
|
|
6418
6491
|
case "==": return t === n;
|
|
6419
6492
|
case "!=": return t !== n;
|
|
@@ -6424,47 +6497,47 @@ function Bc(e, t, n) {
|
|
|
6424
6497
|
default: return !1;
|
|
6425
6498
|
}
|
|
6426
6499
|
}
|
|
6427
|
-
function Vc(e, t) {
|
|
6428
|
-
return new Lc(Ic(e), t).parse();
|
|
6429
|
-
}
|
|
6430
6500
|
function Hc(e, t) {
|
|
6431
|
-
return
|
|
6501
|
+
return new Rc(Lc(e), t).parse();
|
|
6432
6502
|
}
|
|
6433
6503
|
function Uc(e, t) {
|
|
6504
|
+
return e ? `${e}.${t}` : String(t);
|
|
6505
|
+
}
|
|
6506
|
+
function Wc(e, t) {
|
|
6434
6507
|
let n = [{
|
|
6435
6508
|
path: "",
|
|
6436
6509
|
value: e
|
|
6437
6510
|
}];
|
|
6438
|
-
for (let e of
|
|
6511
|
+
for (let e of Ic(t)) {
|
|
6439
6512
|
let t = [];
|
|
6440
6513
|
if (e.type === "key") for (let r of n) r.value != null && typeof r.value == "object" && e.key in r.value && t.push({
|
|
6441
|
-
path:
|
|
6514
|
+
path: Uc(r.path, e.key),
|
|
6442
6515
|
value: r.value[e.key]
|
|
6443
6516
|
});
|
|
6444
6517
|
else if (e.type === "index") {
|
|
6445
6518
|
for (let r of n) if (Array.isArray(r.value)) {
|
|
6446
6519
|
let n = r.value[e.index];
|
|
6447
6520
|
e.index >= 0 && e.index < r.value.length && t.push({
|
|
6448
|
-
path:
|
|
6521
|
+
path: Uc(r.path, e.index),
|
|
6449
6522
|
value: n,
|
|
6450
6523
|
index: e.index
|
|
6451
6524
|
});
|
|
6452
6525
|
}
|
|
6453
6526
|
} else if (e.type === "wildcard") {
|
|
6454
6527
|
for (let e of n) if (Array.isArray(e.value)) e.value.forEach((n, r) => t.push({
|
|
6455
|
-
path:
|
|
6528
|
+
path: Uc(e.path, r),
|
|
6456
6529
|
value: n,
|
|
6457
6530
|
index: r
|
|
6458
6531
|
}));
|
|
6459
6532
|
else if (e.value != null && typeof e.value == "object") for (let n of Object.keys(e.value)) t.push({
|
|
6460
|
-
path:
|
|
6533
|
+
path: Uc(e.path, n),
|
|
6461
6534
|
value: e.value[n]
|
|
6462
6535
|
});
|
|
6463
6536
|
} else if (e.type === "descendKey") {
|
|
6464
6537
|
let r = e.key, i = (e) => {
|
|
6465
6538
|
if (!(e.value == null || typeof e.value != "object")) for (let n of Object.keys(e.value)) {
|
|
6466
6539
|
let a = {
|
|
6467
|
-
path:
|
|
6540
|
+
path: Uc(e.path, n),
|
|
6468
6541
|
value: e.value[n]
|
|
6469
6542
|
};
|
|
6470
6543
|
n === r && t.push(a), i(a);
|
|
@@ -6475,7 +6548,7 @@ function Uc(e, t) {
|
|
|
6475
6548
|
let e = (n) => {
|
|
6476
6549
|
if (!(n.value == null || typeof n.value != "object")) for (let r of Object.keys(n.value)) {
|
|
6477
6550
|
let i = {
|
|
6478
|
-
path:
|
|
6551
|
+
path: Uc(n.path, r),
|
|
6479
6552
|
value: n.value[r]
|
|
6480
6553
|
};
|
|
6481
6554
|
t.push(i), e(i);
|
|
@@ -6484,16 +6557,16 @@ function Uc(e, t) {
|
|
|
6484
6557
|
for (let t of n) e(t);
|
|
6485
6558
|
} else if (e.type === "filter") {
|
|
6486
6559
|
for (let r of n) if (Array.isArray(r.value)) r.value.forEach((n, i) => {
|
|
6487
|
-
|
|
6488
|
-
path:
|
|
6560
|
+
Hc(e.filter, n) && t.push({
|
|
6561
|
+
path: Uc(r.path, i),
|
|
6489
6562
|
value: n,
|
|
6490
6563
|
index: i
|
|
6491
6564
|
});
|
|
6492
6565
|
});
|
|
6493
6566
|
else if (r.value != null && typeof r.value == "object") for (let n of Object.keys(r.value)) {
|
|
6494
6567
|
let i = r.value[n];
|
|
6495
|
-
|
|
6496
|
-
path:
|
|
6568
|
+
Hc(e.filter, i) && t.push({
|
|
6569
|
+
path: Uc(r.path, n),
|
|
6497
6570
|
value: i
|
|
6498
6571
|
});
|
|
6499
6572
|
}
|
|
@@ -6502,7 +6575,7 @@ function Uc(e, t) {
|
|
|
6502
6575
|
}
|
|
6503
6576
|
return n;
|
|
6504
6577
|
}
|
|
6505
|
-
function
|
|
6578
|
+
function Gc(e, t) {
|
|
6506
6579
|
let n = e.length, r = t.length;
|
|
6507
6580
|
if (!n) return r;
|
|
6508
6581
|
if (!r) return n;
|
|
@@ -6518,7 +6591,7 @@ function Wc(e, t) {
|
|
|
6518
6591
|
}
|
|
6519
6592
|
return i[r];
|
|
6520
6593
|
}
|
|
6521
|
-
function
|
|
6594
|
+
function Kc(e, t, n = {}) {
|
|
6522
6595
|
let r = n.mode || "substring", i = n.limit ?? 50, a = n.matchKey !== !1, o = [], s = null;
|
|
6523
6596
|
if (r === "regex") try {
|
|
6524
6597
|
s = new RegExp(t, "i");
|
|
@@ -6528,11 +6601,11 @@ function Gc(e, t, n = {}) {
|
|
|
6528
6601
|
let c = (e, l, u) => {
|
|
6529
6602
|
if (o.length >= i || e == null) return;
|
|
6530
6603
|
if (typeof e == "object") {
|
|
6531
|
-
if (Array.isArray(e)) e.forEach((e, t) => c(e,
|
|
6532
|
-
else for (let t of Object.keys(e)) c(e[t],
|
|
6604
|
+
if (Array.isArray(e)) e.forEach((e, t) => c(e, Uc(l, t), String(t)));
|
|
6605
|
+
else for (let t of Object.keys(e)) c(e[t], Uc(l, t), t);
|
|
6533
6606
|
return;
|
|
6534
6607
|
}
|
|
6535
|
-
let d = String(e), f =
|
|
6608
|
+
let d = String(e), f = qc(d, t, r, n.fuzzyThreshold ?? 2, s);
|
|
6536
6609
|
if (f) {
|
|
6537
6610
|
o.push({
|
|
6538
6611
|
path: l,
|
|
@@ -6543,7 +6616,7 @@ function Gc(e, t, n = {}) {
|
|
|
6543
6616
|
return;
|
|
6544
6617
|
}
|
|
6545
6618
|
if (a && u) {
|
|
6546
|
-
let e =
|
|
6619
|
+
let e = qc(u, t, r, n.fuzzyThreshold ?? 2, s);
|
|
6547
6620
|
e && o.push({
|
|
6548
6621
|
path: l,
|
|
6549
6622
|
key: u,
|
|
@@ -6554,51 +6627,51 @@ function Gc(e, t, n = {}) {
|
|
|
6554
6627
|
};
|
|
6555
6628
|
return c(e, ""), o;
|
|
6556
6629
|
}
|
|
6557
|
-
function
|
|
6630
|
+
function qc(e, t, n, r, i) {
|
|
6558
6631
|
let a = e.toLowerCase(), o = t.toLowerCase();
|
|
6559
6632
|
if (n === "substring") return a.includes(o) ? 1 : null;
|
|
6560
6633
|
if (n === "regex") return i && i.test(e) ? 1 : null;
|
|
6561
6634
|
if (n === "fuzzy") {
|
|
6562
6635
|
if (a.includes(o)) return 2;
|
|
6563
|
-
let e =
|
|
6636
|
+
let e = Gc(a, o);
|
|
6564
6637
|
return e <= r ? r - e + 1 : null;
|
|
6565
6638
|
}
|
|
6566
6639
|
return null;
|
|
6567
6640
|
}
|
|
6568
|
-
function
|
|
6641
|
+
function Jc(e, t, n = 3e3) {
|
|
6569
6642
|
return ba(t, n)(e);
|
|
6570
6643
|
}
|
|
6571
6644
|
//#endregion
|
|
6572
6645
|
//#region src/core/tools/resources.ts
|
|
6573
|
-
var
|
|
6574
|
-
function Zc(e) {
|
|
6575
|
-
return `${Jc}${e}${Xc}`;
|
|
6576
|
-
}
|
|
6646
|
+
var Yc = "⟦frozen:", Xc = "⟦res:", Zc = "⟧";
|
|
6577
6647
|
function Qc(e) {
|
|
6578
|
-
return `${Yc}${e}${
|
|
6648
|
+
return `${Yc}${e}${Zc}`;
|
|
6579
6649
|
}
|
|
6580
6650
|
function $c(e) {
|
|
6581
|
-
return
|
|
6651
|
+
return `${Xc}${e}${Zc}`;
|
|
6652
|
+
}
|
|
6653
|
+
function el(e) {
|
|
6654
|
+
return typeof e == "string" ? e.startsWith(Yc) && e.endsWith(Zc) ? {
|
|
6582
6655
|
type: "frozen",
|
|
6583
6656
|
path: e.slice(8, e.length - 1)
|
|
6584
|
-
} : e.startsWith(
|
|
6657
|
+
} : e.startsWith(Xc) && e.endsWith(Zc) ? {
|
|
6585
6658
|
type: "res",
|
|
6586
6659
|
handle: e.slice(5, e.length - 1)
|
|
6587
6660
|
} : null : null;
|
|
6588
6661
|
}
|
|
6589
|
-
function
|
|
6662
|
+
function tl(e) {
|
|
6590
6663
|
return String(e ?? "").trim().replace(/^\.+/, "");
|
|
6591
6664
|
}
|
|
6592
|
-
function
|
|
6665
|
+
function nl(e) {
|
|
6593
6666
|
let t = 5381;
|
|
6594
6667
|
for (let n = 0; n < e.length; n++) t = (t * 33 ^ e.charCodeAt(n)) >>> 0;
|
|
6595
6668
|
return (t >>> 0).toString(16).padStart(8, "0").slice(0, 8);
|
|
6596
6669
|
}
|
|
6597
|
-
function
|
|
6670
|
+
function rl(e, t) {
|
|
6598
6671
|
return e === t ? !0 : e && t && typeof e == "object" && typeof t == "object" ? JSON.stringify(e) === JSON.stringify(t) : !1;
|
|
6599
6672
|
}
|
|
6600
|
-
function
|
|
6601
|
-
let n =
|
|
6673
|
+
function il(e, t) {
|
|
6674
|
+
let n = tl(e);
|
|
6602
6675
|
if (!n) return;
|
|
6603
6676
|
let r = t.get(n);
|
|
6604
6677
|
if (r) return {
|
|
@@ -6618,7 +6691,7 @@ function rl(e, t) {
|
|
|
6618
6691
|
}));
|
|
6619
6692
|
return i;
|
|
6620
6693
|
}
|
|
6621
|
-
var
|
|
6694
|
+
var al = class {
|
|
6622
6695
|
vfs;
|
|
6623
6696
|
constructor(e) {
|
|
6624
6697
|
this.vfs = e;
|
|
@@ -6627,7 +6700,7 @@ var il = class {
|
|
|
6627
6700
|
return `resources/${e}.json`;
|
|
6628
6701
|
}
|
|
6629
6702
|
ensure(e, t, n) {
|
|
6630
|
-
let r =
|
|
6703
|
+
let r = nl(e), i = {
|
|
6631
6704
|
path: e,
|
|
6632
6705
|
mode: n,
|
|
6633
6706
|
value: t,
|
|
@@ -6639,7 +6712,7 @@ var il = class {
|
|
|
6639
6712
|
}, r;
|
|
6640
6713
|
}
|
|
6641
6714
|
get(e) {
|
|
6642
|
-
return this.readEntry(this.key(e)) || this.readEntry(this.key(
|
|
6715
|
+
return this.readEntry(this.key(e)) || this.readEntry(this.key(nl(e)));
|
|
6643
6716
|
}
|
|
6644
6717
|
readEntry(e) {
|
|
6645
6718
|
let t = this.vfs.files[e];
|
|
@@ -6655,7 +6728,7 @@ var il = class {
|
|
|
6655
6728
|
this.ensure(e, t, n?.mode ?? "verbatim");
|
|
6656
6729
|
}
|
|
6657
6730
|
delete(e) {
|
|
6658
|
-
let t = this.get(e)?.handle ??
|
|
6731
|
+
let t = this.get(e)?.handle ?? nl(e), n = this.key(t), r = !!this.vfs.files[n];
|
|
6659
6732
|
return r && delete this.vfs.files[n], r;
|
|
6660
6733
|
}
|
|
6661
6734
|
list() {
|
|
@@ -6675,7 +6748,7 @@ var il = class {
|
|
|
6675
6748
|
for (let e of Object.keys(this.vfs.files)) e.startsWith("resources/") && delete this.vfs.files[e];
|
|
6676
6749
|
}
|
|
6677
6750
|
};
|
|
6678
|
-
function
|
|
6751
|
+
function ol(e) {
|
|
6679
6752
|
let { jp: t, resolved: n, resourcesByPath: r, resourceStore: i } = e;
|
|
6680
6753
|
if (!r.size) return n;
|
|
6681
6754
|
let a = !1;
|
|
@@ -6684,19 +6757,19 @@ function al(e) {
|
|
|
6684
6757
|
break;
|
|
6685
6758
|
}
|
|
6686
6759
|
if (!a) return n;
|
|
6687
|
-
let o =
|
|
6760
|
+
let o = fc(n);
|
|
6688
6761
|
for (let [e, n] of r) {
|
|
6689
6762
|
if (t !== "" && e !== t && !e.startsWith(t + ".")) continue;
|
|
6690
6763
|
if (e === t) {
|
|
6691
6764
|
if (o === void 0) continue;
|
|
6692
|
-
return n.mode === "freeze" ?
|
|
6765
|
+
return n.mode === "freeze" ? Qc(e) : i ? $c(i.ensure(e, o, "verbatim")) : o;
|
|
6693
6766
|
}
|
|
6694
6767
|
let r = t === "" ? e : e.slice(t.length + 1), a = Z(o, r);
|
|
6695
|
-
a !== void 0 && (n.mode === "freeze" ?
|
|
6768
|
+
a !== void 0 && (n.mode === "freeze" ? uc(o, r, Qc(e)) : i && uc(o, r, $c(i.ensure(e, a, "verbatim"))));
|
|
6696
6769
|
}
|
|
6697
6770
|
return o;
|
|
6698
6771
|
}
|
|
6699
|
-
function
|
|
6772
|
+
function sl(e, t, n, r) {
|
|
6700
6773
|
if (!r) return {
|
|
6701
6774
|
code: "RESOURCE_NOT_FOUND",
|
|
6702
6775
|
message: `句柄 "${e}" 无法展开(资源池未启用)`,
|
|
@@ -6707,7 +6780,7 @@ function ol(e, t, n, r) {
|
|
|
6707
6780
|
code: "RESOURCE_NOT_FOUND",
|
|
6708
6781
|
message: `字段 "${t}" 在 bind 中已不存在,无法展开句柄 "${e}"`,
|
|
6709
6782
|
hint: "该字段可能已被删除或 restore 到不含此字段的快照;重新 read 确认当前结构"
|
|
6710
|
-
} :
|
|
6783
|
+
} : rl(i.value, n) ? { value: i.value } : (r.update(t, n), { value: n }) : n === void 0 ? {
|
|
6711
6784
|
code: "RESOURCE_NOT_FOUND",
|
|
6712
6785
|
message: `句柄 "${e}" 不存在(字段 "${t}" 可能未注册或已被删除)`,
|
|
6713
6786
|
hint: "重新 read 该字段触发懒注册"
|
|
@@ -6717,20 +6790,20 @@ function ol(e, t, n, r) {
|
|
|
6717
6790
|
hint: "重新 read 该字段触发懒注册重建句柄,再写回新句柄 ⟦res:<handle>⟧"
|
|
6718
6791
|
};
|
|
6719
6792
|
}
|
|
6720
|
-
function
|
|
6793
|
+
function cl(e, t) {
|
|
6721
6794
|
let n = t.getBind();
|
|
6722
6795
|
for (let [r, i] of t.resourcesByPath) {
|
|
6723
6796
|
let a = Z(n, r), o = Z(e, r);
|
|
6724
6797
|
if (o === void 0) {
|
|
6725
|
-
a !== void 0 &&
|
|
6798
|
+
a !== void 0 && uc(e, r, a);
|
|
6726
6799
|
continue;
|
|
6727
6800
|
}
|
|
6728
6801
|
if (i.mode === "freeze") {
|
|
6729
|
-
if (o ===
|
|
6730
|
-
|
|
6802
|
+
if (o === Qc(r)) {
|
|
6803
|
+
uc(e, r, a);
|
|
6731
6804
|
continue;
|
|
6732
6805
|
}
|
|
6733
|
-
if (!
|
|
6806
|
+
if (!rl(o, a)) return {
|
|
6734
6807
|
ok: !1,
|
|
6735
6808
|
code: "FROZEN_FIELD",
|
|
6736
6809
|
path: r,
|
|
@@ -6738,11 +6811,11 @@ function sl(e, t) {
|
|
|
6738
6811
|
hint: "该字段由系统/集成方维护,LLM 不得改动。如需展示其值用 resource_get({path}) 取真值"
|
|
6739
6812
|
};
|
|
6740
6813
|
} else {
|
|
6741
|
-
let n =
|
|
6814
|
+
let n = el(o);
|
|
6742
6815
|
if (n && n.type === "res") {
|
|
6743
|
-
let i =
|
|
6816
|
+
let i = sl(n.handle, r, a, t.resourceStore);
|
|
6744
6817
|
if ("value" in i) {
|
|
6745
|
-
|
|
6818
|
+
uc(e, r, i.value);
|
|
6746
6819
|
continue;
|
|
6747
6820
|
}
|
|
6748
6821
|
return {
|
|
@@ -6753,7 +6826,7 @@ function sl(e, t) {
|
|
|
6753
6826
|
hint: i.hint
|
|
6754
6827
|
};
|
|
6755
6828
|
}
|
|
6756
|
-
if (!
|
|
6829
|
+
if (!rl(o, a)) return {
|
|
6757
6830
|
ok: !1,
|
|
6758
6831
|
code: "VERBATIM_MISMATCH",
|
|
6759
6832
|
path: r,
|
|
@@ -6764,7 +6837,7 @@ function sl(e, t) {
|
|
|
6764
6837
|
}
|
|
6765
6838
|
return { ok: !0 };
|
|
6766
6839
|
}
|
|
6767
|
-
function
|
|
6840
|
+
function ll(e, t, n) {
|
|
6768
6841
|
let r = t === void 0 ? e.message : `patches[${t}]${n ? ` @ "${n}"` : ""}: ${e.message}`;
|
|
6769
6842
|
return Y({
|
|
6770
6843
|
code: e.code,
|
|
@@ -6777,28 +6850,28 @@ function cl(e, t, n) {
|
|
|
6777
6850
|
} }
|
|
6778
6851
|
});
|
|
6779
6852
|
}
|
|
6780
|
-
function
|
|
6853
|
+
function ul(e) {
|
|
6781
6854
|
let { value: t, ctx: n } = e;
|
|
6782
6855
|
if (!n || !n.resourcesByPath.size) return {
|
|
6783
6856
|
ok: !0,
|
|
6784
6857
|
value: t
|
|
6785
6858
|
};
|
|
6786
|
-
let r =
|
|
6859
|
+
let r = fc(t), i = cl(r, n);
|
|
6787
6860
|
return i.ok ? {
|
|
6788
6861
|
ok: !0,
|
|
6789
6862
|
value: r
|
|
6790
6863
|
} : {
|
|
6791
6864
|
ok: !1,
|
|
6792
|
-
error:
|
|
6865
|
+
error: ll(i)
|
|
6793
6866
|
};
|
|
6794
6867
|
}
|
|
6795
|
-
function
|
|
6868
|
+
function dl(e) {
|
|
6796
6869
|
let { patches: t, clone: n, ctx: r } = e;
|
|
6797
6870
|
if (!r || !r.resourcesByPath.size) return { ok: !0 };
|
|
6798
6871
|
for (let e = 0; e < t.length; e++) {
|
|
6799
6872
|
let n = t[e];
|
|
6800
6873
|
if (n.op === "remove") {
|
|
6801
|
-
let t =
|
|
6874
|
+
let t = il(n.jsonPath || "", r.resourcesByPath);
|
|
6802
6875
|
if (t) {
|
|
6803
6876
|
let r = t.spec.mode === "freeze" ? "FROZEN_FIELD" : "VERBATIM_PROTECTED", i = t.spec.mode === "freeze" ? "冻结字段不可删。如需移除请联系集成方调整 data.resources 配置" : "verbatim 字段不可直接删;先 resource_delete({path}) 释放资源保护后再删";
|
|
6804
6877
|
return {
|
|
@@ -6817,27 +6890,27 @@ function ul(e) {
|
|
|
6817
6890
|
}
|
|
6818
6891
|
}
|
|
6819
6892
|
}
|
|
6820
|
-
let i =
|
|
6893
|
+
let i = cl(n, r);
|
|
6821
6894
|
if (!i.ok) {
|
|
6822
|
-
let e =
|
|
6895
|
+
let e = fl(i.path, t);
|
|
6823
6896
|
return {
|
|
6824
6897
|
ok: !1,
|
|
6825
|
-
error:
|
|
6898
|
+
error: ll(i, e >= 0 ? e : void 0, e >= 0 ? t[e].jsonPath : void 0)
|
|
6826
6899
|
};
|
|
6827
6900
|
}
|
|
6828
6901
|
return { ok: !0 };
|
|
6829
6902
|
}
|
|
6830
|
-
function
|
|
6831
|
-
let n =
|
|
6903
|
+
function fl(e, t) {
|
|
6904
|
+
let n = tl(e);
|
|
6832
6905
|
for (let e = 0; e < t.length; e++) {
|
|
6833
|
-
let r =
|
|
6906
|
+
let r = tl(t[e].jsonPath || "");
|
|
6834
6907
|
if (r && (r === n || n.startsWith(r + ".") || r.startsWith(n + "."))) return e;
|
|
6835
6908
|
}
|
|
6836
6909
|
return -1;
|
|
6837
6910
|
}
|
|
6838
6911
|
//#endregion
|
|
6839
6912
|
//#region src/core/tools/dataOps.ts
|
|
6840
|
-
var
|
|
6913
|
+
var pl = /* @__PURE__ */ new Set([
|
|
6841
6914
|
"describe_data",
|
|
6842
6915
|
"get_data",
|
|
6843
6916
|
"set_data",
|
|
@@ -6851,14 +6924,14 @@ var fl = /* @__PURE__ */ new Set([
|
|
|
6851
6924
|
"resource_update",
|
|
6852
6925
|
"resource_list",
|
|
6853
6926
|
"resource_delete"
|
|
6854
|
-
]),
|
|
6855
|
-
function
|
|
6856
|
-
return t === "advanced" ? e : t === "minimal" ? e.filter((e) =>
|
|
6927
|
+
]), ml = /* @__PURE__ */ new Set(["read", "write"]);
|
|
6928
|
+
function hl(e, t = "simple") {
|
|
6929
|
+
return t === "advanced" ? e : t === "minimal" ? e.filter((e) => ml.has(e.name)) : e.filter((e) => !pl.has(e.name));
|
|
6857
6930
|
}
|
|
6858
|
-
function
|
|
6931
|
+
function gl(e) {
|
|
6859
6932
|
let { bindRef: t, schema: n, allowKeys: r, snapshots: i, maxSnapshots: a, audit: o, dryRun: s, op: c = "set", protectedCtx: l } = e, u = e.value;
|
|
6860
6933
|
if (l) {
|
|
6861
|
-
let e =
|
|
6934
|
+
let e = ul({
|
|
6862
6935
|
value: u,
|
|
6863
6936
|
ctx: l
|
|
6864
6937
|
});
|
|
@@ -6886,14 +6959,14 @@ function hl(e) {
|
|
|
6886
6959
|
hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹(如 {value:\"x\"})或集成方通过 sdk.setData 替换 bind"
|
|
6887
6960
|
})
|
|
6888
6961
|
};
|
|
6889
|
-
let f =
|
|
6962
|
+
let f = fc(t), p = i.length ? i[i.length - 1].id + 1 : 1;
|
|
6890
6963
|
for (i.push({
|
|
6891
6964
|
id: p,
|
|
6892
6965
|
ts: Date.now(),
|
|
6893
6966
|
op: c,
|
|
6894
6967
|
value: f
|
|
6895
6968
|
}); i.length > a;) i.shift();
|
|
6896
|
-
return d.data !== null && typeof d.data == "object" && (r ?
|
|
6969
|
+
return d.data !== null && typeof d.data == "object" && (r ? lc(t, d.data) : bc(t, d.data)), o({
|
|
6897
6970
|
op: c,
|
|
6898
6971
|
value: d.data,
|
|
6899
6972
|
timestamp: Date.now()
|
|
@@ -6903,11 +6976,11 @@ function hl(e) {
|
|
|
6903
6976
|
data: d.data
|
|
6904
6977
|
};
|
|
6905
6978
|
}
|
|
6906
|
-
function
|
|
6907
|
-
let { bindRef: t, patches: n, schema: r, allowKeys: i, snapshots: a, maxSnapshots: o, markDataDirty: s, schemaErrorMode: c = "zod", snapshotLabel: l, dryRun: u, protectedCtx: d } = e, f =
|
|
6979
|
+
function _l(e) {
|
|
6980
|
+
let { bindRef: t, patches: n, schema: r, allowKeys: i, snapshots: a, maxSnapshots: o, markDataDirty: s, schemaErrorMode: c = "zod", snapshotLabel: l, dryRun: u, protectedCtx: d } = e, f = fc(t), p = [];
|
|
6908
6981
|
for (let e = 0; e < n.length; e++) {
|
|
6909
6982
|
let t = n[e], a = t.jsonPath || "";
|
|
6910
|
-
if (
|
|
6983
|
+
if (cc(a)) return {
|
|
6911
6984
|
ok: !1,
|
|
6912
6985
|
error: Y({
|
|
6913
6986
|
code: "PATH_UNSAFE",
|
|
@@ -6933,14 +7006,14 @@ function gl(e) {
|
|
|
6933
7006
|
hint: `op 为 ${o} 时 value 必填;删除请用 op:'remove'`
|
|
6934
7007
|
})
|
|
6935
7008
|
};
|
|
6936
|
-
let n =
|
|
7009
|
+
let n = pc(t.value);
|
|
6937
7010
|
if (n.parseError) return {
|
|
6938
7011
|
ok: !1,
|
|
6939
7012
|
error: Gr(`patches[${e}]`, t.value, n.parseError)
|
|
6940
7013
|
};
|
|
6941
7014
|
s = n.parsed;
|
|
6942
7015
|
}
|
|
6943
|
-
let c =
|
|
7016
|
+
let c = _c(f, o, a, s);
|
|
6944
7017
|
if (c) return {
|
|
6945
7018
|
ok: !1,
|
|
6946
7019
|
error: Y({
|
|
@@ -6956,7 +7029,7 @@ function gl(e) {
|
|
|
6956
7029
|
});
|
|
6957
7030
|
}
|
|
6958
7031
|
if (d) {
|
|
6959
|
-
let e =
|
|
7032
|
+
let e = dl({
|
|
6960
7033
|
patches: n,
|
|
6961
7034
|
clone: f,
|
|
6962
7035
|
ctx: d
|
|
@@ -6986,21 +7059,21 @@ function gl(e) {
|
|
|
6986
7059
|
id: h,
|
|
6987
7060
|
ts: Date.now(),
|
|
6988
7061
|
op: "edit",
|
|
6989
|
-
value:
|
|
7062
|
+
value: fc(t),
|
|
6990
7063
|
...l ? { label: l } : {}
|
|
6991
7064
|
}); a.length > o;) a.shift();
|
|
6992
|
-
for (let e of p) e.op === "remove" &&
|
|
6993
|
-
return m.data !== null && typeof m.data == "object" && (i ?
|
|
7065
|
+
for (let e of p) e.op === "remove" && dc(t, e.jp);
|
|
7066
|
+
return m.data !== null && typeof m.data == "object" && (i ? lc(t, m.data) : bc(t, m.data)), s?.(), {
|
|
6994
7067
|
ok: !0,
|
|
6995
7068
|
applied: p,
|
|
6996
7069
|
clone: f
|
|
6997
7070
|
};
|
|
6998
7071
|
}
|
|
6999
|
-
function
|
|
7000
|
-
let i = e.schema, a = e.bind, o = e.description ?? "主数据对象", s = Mi(i), c = /* @__PURE__ */ new Map(), l = n.vfsStore ? new
|
|
7072
|
+
function vl(e, n = {}) {
|
|
7073
|
+
let i = e.schema, a = e.bind, o = e.description ?? "主数据对象", s = Mi(i), c = /* @__PURE__ */ new Map(), l = n.vfsStore ? new al(n.vfsStore) : void 0;
|
|
7001
7074
|
function u(e) {
|
|
7002
7075
|
if (c.clear(), e) for (let t of e) {
|
|
7003
|
-
let e =
|
|
7076
|
+
let e = tl(t.path);
|
|
7004
7077
|
c.set(e, {
|
|
7005
7078
|
path: e,
|
|
7006
7079
|
mode: t.mode
|
|
@@ -7052,7 +7125,7 @@ function _l(e, n = {}) {
|
|
|
7052
7125
|
return e;
|
|
7053
7126
|
},
|
|
7054
7127
|
createResource: l ? (e, t) => {
|
|
7055
|
-
let n =
|
|
7128
|
+
let n = tl(e), r = c.get(n), i = t === void 0 ? Z(a, n) : t;
|
|
7056
7129
|
return l.ensure(n, i, r?.mode ?? "verbatim");
|
|
7057
7130
|
} : void 0,
|
|
7058
7131
|
getResource: l ? (e) => {
|
|
@@ -7065,8 +7138,8 @@ function _l(e, n = {}) {
|
|
|
7065
7138
|
} : void 0;
|
|
7066
7139
|
} : void 0,
|
|
7067
7140
|
updateResource: l ? (e, t) => {
|
|
7068
|
-
let n =
|
|
7069
|
-
l.update(n, t),
|
|
7141
|
+
let n = tl(e);
|
|
7142
|
+
l.update(n, t), uc(a, n, t), _();
|
|
7070
7143
|
} : void 0,
|
|
7071
7144
|
deleteResource: l ? (e) => l.delete(e) : void 0,
|
|
7072
7145
|
listResources: l ? () => l.list() : void 0
|
|
@@ -7074,7 +7147,7 @@ function _l(e, n = {}) {
|
|
|
7074
7147
|
n.onAudit?.(e);
|
|
7075
7148
|
};
|
|
7076
7149
|
function b(e, t) {
|
|
7077
|
-
let n =
|
|
7150
|
+
let n = fc(a), r = f.length ? f[f.length - 1].id + 1 : 1;
|
|
7078
7151
|
for (f.push({
|
|
7079
7152
|
id: r,
|
|
7080
7153
|
ts: Date.now(),
|
|
@@ -7105,7 +7178,7 @@ function _l(e, n = {}) {
|
|
|
7105
7178
|
if (o.action === "restore") {
|
|
7106
7179
|
if (!f.length) return `无历史快照可回退(本次为首次操作)。当前值:${Q(a, 400)} (hash=${i})。请重新 read 再改或选「强制覆盖」。`;
|
|
7107
7180
|
let e = f[f.length - 1];
|
|
7108
|
-
return
|
|
7181
|
+
return yc(a, fc(e.value)), _(), `已回退主数据到历史快照 #${e.id}[${e.op}]。当前值:${Q(a, 400)} (hash=${$(a)})。请基于回退后的值重写或停止。`;
|
|
7109
7182
|
}
|
|
7110
7183
|
return null;
|
|
7111
7184
|
}
|
|
@@ -7115,7 +7188,7 @@ function _l(e, n = {}) {
|
|
|
7115
7188
|
schema: t.object({})
|
|
7116
7189
|
}), C = r(async ({ jsonPath: e }) => {
|
|
7117
7190
|
let t = e || "";
|
|
7118
|
-
if (
|
|
7191
|
+
if (cc(t)) return Y({
|
|
7119
7192
|
code: "PATH_UNSAFE",
|
|
7120
7193
|
message: `jsonPath "${t}" 含非法段(__proto__/constructor/prototype)`,
|
|
7121
7194
|
hint: "使用正常属性路径,如 components.0.text(数组索引用数字)"
|
|
@@ -7126,7 +7199,7 @@ function _l(e, n = {}) {
|
|
|
7126
7199
|
hint: "主数据仅暴露 schema 声明的字段;若需操作该字段,集成方需在 schema 中声明它"
|
|
7127
7200
|
});
|
|
7128
7201
|
let n = t ? Z(a, t) : a;
|
|
7129
|
-
t || (n = Li(n, s)), d && (n =
|
|
7202
|
+
t || (n = Li(n, s)), d && (n = ol({
|
|
7130
7203
|
jp: t,
|
|
7131
7204
|
resolved: n,
|
|
7132
7205
|
resourcesByPath: d.resourcesByPath,
|
|
@@ -7141,9 +7214,9 @@ function _l(e, n = {}) {
|
|
|
7141
7214
|
}), w = r(async ({ value: e, expectedHash: t }) => {
|
|
7142
7215
|
let n = await x("set", t || (h ? m : void 0));
|
|
7143
7216
|
if (n !== null) return n;
|
|
7144
|
-
let r =
|
|
7217
|
+
let r = pc(e);
|
|
7145
7218
|
if (r.parseError) return Gr("", e, r.parseError);
|
|
7146
|
-
let o =
|
|
7219
|
+
let o = gl({
|
|
7147
7220
|
bindRef: a,
|
|
7148
7221
|
value: r.parsed,
|
|
7149
7222
|
schema: i,
|
|
@@ -7170,7 +7243,7 @@ function _l(e, n = {}) {
|
|
|
7170
7243
|
hint: "顶层 op 或 patch.op 至少传一个"
|
|
7171
7244
|
});
|
|
7172
7245
|
let c = n || "";
|
|
7173
|
-
if (
|
|
7246
|
+
if (cc(c)) return Y({
|
|
7174
7247
|
code: "PATH_UNSAFE",
|
|
7175
7248
|
message: `jsonPath "${c}" 含非法段(__proto__/constructor/prototype)`,
|
|
7176
7249
|
hint: "使用正常的属性路径,如 components.0.text(数组索引用数字)"
|
|
@@ -7187,7 +7260,7 @@ function _l(e, n = {}) {
|
|
|
7187
7260
|
message: `edit 仅适用于对象/数组主数据,当前是 ${a === void 0 ? "undefined" : typeof a}`,
|
|
7188
7261
|
hint: "叶子(原始类型)请用 set_data 整体设置"
|
|
7189
7262
|
});
|
|
7190
|
-
let u =
|
|
7263
|
+
let u = _l({
|
|
7191
7264
|
bindRef: a,
|
|
7192
7265
|
patches: [{
|
|
7193
7266
|
op: t,
|
|
@@ -7240,7 +7313,7 @@ function _l(e, n = {}) {
|
|
|
7240
7313
|
message: "delete_data 需要 jsonPath 指定要删的子路径(主数据整体不可删,用 set_data 整体替换)",
|
|
7241
7314
|
hint: "如 jsonPath:\"components.0\" 删数组首项"
|
|
7242
7315
|
});
|
|
7243
|
-
if (
|
|
7316
|
+
if (cc(e)) return Y({
|
|
7244
7317
|
code: "PATH_UNSAFE",
|
|
7245
7318
|
message: `jsonPath "${e}" 含非法段`,
|
|
7246
7319
|
hint: "使用正常属性路径"
|
|
@@ -7251,7 +7324,7 @@ function _l(e, n = {}) {
|
|
|
7251
7324
|
hint: "仅 schema 声明的 key 可删"
|
|
7252
7325
|
});
|
|
7253
7326
|
if (d) {
|
|
7254
|
-
let t =
|
|
7327
|
+
let t = il(e, d.resourcesByPath);
|
|
7255
7328
|
if (t) return Y({
|
|
7256
7329
|
code: t.spec.mode === "freeze" ? "FROZEN_FIELD" : "VERBATIM_PROTECTED",
|
|
7257
7330
|
message: `delete_data @ "${e}" 命中受保护字段 "${t.protectedPath}"(${t.spec.mode}),不可删除`,
|
|
@@ -7261,7 +7334,7 @@ function _l(e, n = {}) {
|
|
|
7261
7334
|
let n = await x("delete", t || (h ? m : void 0));
|
|
7262
7335
|
if (n !== null) return n;
|
|
7263
7336
|
b("delete");
|
|
7264
|
-
let r =
|
|
7337
|
+
let r = dc(a, e);
|
|
7265
7338
|
return _(), y({
|
|
7266
7339
|
op: "delete",
|
|
7267
7340
|
detail: e,
|
|
@@ -7287,7 +7360,7 @@ function _l(e, n = {}) {
|
|
|
7287
7360
|
hint: "用 history_data({list:true}) 查看可用快照序号"
|
|
7288
7361
|
});
|
|
7289
7362
|
let n = i.safeParse(t.value);
|
|
7290
|
-
return n.success ? (
|
|
7363
|
+
return n.success ? (yc(a, fc(t.value)), _(), y({
|
|
7291
7364
|
op: "restore",
|
|
7292
7365
|
detail: `#${t.id}`,
|
|
7293
7366
|
timestamp: Date.now()
|
|
@@ -7321,9 +7394,9 @@ function _l(e, n = {}) {
|
|
|
7321
7394
|
message: `未找到快照 #${e}`,
|
|
7322
7395
|
hint: "不传 id 查看最近一次;或 history_data({list:true}) 查看可用序号"
|
|
7323
7396
|
});
|
|
7324
|
-
let a =
|
|
7397
|
+
let a = fc(r.value), o = t || "";
|
|
7325
7398
|
if (o) {
|
|
7326
|
-
if (
|
|
7399
|
+
if (cc(o)) return Y({
|
|
7327
7400
|
code: "PATH_UNSAFE",
|
|
7328
7401
|
message: `jsonPath "${o}" 含非法段`,
|
|
7329
7402
|
hint: "使用正常属性路径"
|
|
@@ -7354,7 +7427,7 @@ function _l(e, n = {}) {
|
|
|
7354
7427
|
});
|
|
7355
7428
|
let n = s ? Li(a, s) : a, r;
|
|
7356
7429
|
try {
|
|
7357
|
-
r =
|
|
7430
|
+
r = Wc(n, e);
|
|
7358
7431
|
} catch (t) {
|
|
7359
7432
|
return Y({
|
|
7360
7433
|
code: "JSONPATH_SYNTAX",
|
|
@@ -7378,7 +7451,7 @@ function _l(e, n = {}) {
|
|
|
7378
7451
|
message: "主数据为空,无可搜索内容"
|
|
7379
7452
|
});
|
|
7380
7453
|
try {
|
|
7381
|
-
let o =
|
|
7454
|
+
let o = Kc(s ? Li(a, s) : a, e, {
|
|
7382
7455
|
mode: t,
|
|
7383
7456
|
fuzzyThreshold: n,
|
|
7384
7457
|
matchKey: r,
|
|
@@ -7428,7 +7501,7 @@ function _l(e, n = {}) {
|
|
|
7428
7501
|
e && (o = Ii(o, e));
|
|
7429
7502
|
}
|
|
7430
7503
|
} else o = s ? Li(a, s) : a;
|
|
7431
|
-
let c =
|
|
7504
|
+
let c = fc(o), l = await Jc(c, e, r && JSON.stringify(c).length > 1e5 ? 8e3 : 3e3);
|
|
7432
7505
|
if (!l.ok) {
|
|
7433
7506
|
let t = /超时/.test(l.error || "");
|
|
7434
7507
|
return Y({
|
|
@@ -7444,7 +7517,7 @@ function _l(e, n = {}) {
|
|
|
7444
7517
|
if (t === "transform") {
|
|
7445
7518
|
let e = l.result;
|
|
7446
7519
|
if (r) {
|
|
7447
|
-
let t =
|
|
7520
|
+
let t = _l({
|
|
7448
7521
|
bindRef: a,
|
|
7449
7522
|
patches: [{
|
|
7450
7523
|
op: "set",
|
|
@@ -7472,7 +7545,7 @@ function _l(e, n = {}) {
|
|
|
7472
7545
|
message: `主数据 bind 为原始类型(${a === null ? "null" : typeof a}),eval transform(patches) 无法就地替换`,
|
|
7473
7546
|
hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹或集成方通过 sdk.setData 替换 bind"
|
|
7474
7547
|
});
|
|
7475
|
-
let t =
|
|
7548
|
+
let t = _l({
|
|
7476
7549
|
bindRef: a,
|
|
7477
7550
|
patches: e.patches,
|
|
7478
7551
|
schema: i,
|
|
@@ -7492,7 +7565,7 @@ function _l(e, n = {}) {
|
|
|
7492
7565
|
}
|
|
7493
7566
|
let t = e;
|
|
7494
7567
|
if (d) {
|
|
7495
|
-
let e =
|
|
7568
|
+
let e = ul({
|
|
7496
7569
|
value: t,
|
|
7497
7570
|
ctx: d
|
|
7498
7571
|
});
|
|
@@ -7504,7 +7577,7 @@ function _l(e, n = {}) {
|
|
|
7504
7577
|
code: "LEAF_BIND",
|
|
7505
7578
|
message: `主数据 bind 为原始类型(${a === null ? "null" : typeof a}),eval transform 无法就地替换外部持有的值引用`,
|
|
7506
7579
|
hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹或集成方通过 sdk.setData 替换 bind"
|
|
7507
|
-
}) : (b("edit", "eval_transform"), n.data !== null && typeof n.data == "object" && (s ?
|
|
7580
|
+
}) : (b("edit", "eval_transform"), n.data !== null && typeof n.data == "object" && (s ? lc(a, n.data) : bc(a, n.data)), _(), y({
|
|
7508
7581
|
op: "edit",
|
|
7509
7582
|
detail: "eval_transform",
|
|
7510
7583
|
timestamp: Date.now()
|
|
@@ -7541,7 +7614,7 @@ function _l(e, n = {}) {
|
|
|
7541
7614
|
e && (o = Ii(o, e));
|
|
7542
7615
|
}
|
|
7543
7616
|
let l = o;
|
|
7544
|
-
if (d && (l =
|
|
7617
|
+
if (d && (l = ol({
|
|
7545
7618
|
jp: t,
|
|
7546
7619
|
resolved: l,
|
|
7547
7620
|
resourcesByPath: d.resourcesByPath,
|
|
@@ -7551,12 +7624,12 @@ function _l(e, n = {}) {
|
|
|
7551
7624
|
} catch (e) {
|
|
7552
7625
|
return `- ${t}: [READ_INTERCEPT: ${e.message}]`;
|
|
7553
7626
|
}
|
|
7554
|
-
return r && r.length && (l =
|
|
7627
|
+
return r && r.length && (l = mc(l, r)), c != null && (l = hc(l, c)), l === void 0 ? `- ${t} = (undefined)` : `- ${t} = ${Q(l)}`;
|
|
7555
7628
|
});
|
|
7556
7629
|
return `多路径读取(共 ${t.length} 项,hash=${f}):\n${e.join("\n")}`;
|
|
7557
7630
|
}
|
|
7558
7631
|
let p = e || "";
|
|
7559
|
-
if (
|
|
7632
|
+
if (cc(p)) return Y({
|
|
7560
7633
|
code: "PATH_UNSAFE",
|
|
7561
7634
|
message: `jsonPath "${p}" 含非法段(__proto__/constructor/prototype)`,
|
|
7562
7635
|
hint: "使用正常属性路径,如 components.0.text(数组索引数字)"
|
|
@@ -7573,7 +7646,7 @@ function _l(e, n = {}) {
|
|
|
7573
7646
|
e && (h = Ii(h, e));
|
|
7574
7647
|
}
|
|
7575
7648
|
let g = h;
|
|
7576
|
-
if (d && (g =
|
|
7649
|
+
if (d && (g = ol({
|
|
7577
7650
|
jp: p,
|
|
7578
7651
|
resolved: g,
|
|
7579
7652
|
resourcesByPath: d.resourcesByPath,
|
|
@@ -7586,7 +7659,7 @@ function _l(e, n = {}) {
|
|
|
7586
7659
|
message: `read 拦截器抛错: ${e.message}`
|
|
7587
7660
|
});
|
|
7588
7661
|
}
|
|
7589
|
-
r && r.length && (g =
|
|
7662
|
+
r && r.length && (g = mc(g, r)), c != null && (g = hc(g, c));
|
|
7590
7663
|
let _ = e ? "" : `主数据说明: ${o}\n格式: 写入值需为 JSON,且通过声明的 schema 校验(校验失败时 write 会返回结构化错误)。字段约束(类型/min/max/enum/必填/默认)见 systemPrompt「可操作数据」段,或用 schema_data({ jsonPath }) 按需查。\n\n`, v = r && r.length ? `(字段裁剪:${r.join(",")})` : "", y = c == null ? "" : `(深度≤${c})`, b = v || y ? ` ${v}${y}` : "";
|
|
7591
7664
|
if ((l !== void 0 || u !== void 0) && Array.isArray(g)) {
|
|
7592
7665
|
let e = g.length, t = Math.max(0, l ?? 0), n = Math.min(200, Math.max(1, u ?? 50)), r = g.slice(t, t + n), i = t + n < e;
|
|
@@ -7648,7 +7721,7 @@ function _l(e, n = {}) {
|
|
|
7648
7721
|
message: "delete 需要 patch.jsonPath 指定要删的子路径(主数据整体不可删,用 write(value) 整体替换)",
|
|
7649
7722
|
hint: "如 patch:{jsonPath:\"components.0\"}, del:true"
|
|
7650
7723
|
});
|
|
7651
|
-
if (
|
|
7724
|
+
if (cc(t.jsonPath)) return Y({
|
|
7652
7725
|
code: "PATH_UNSAFE",
|
|
7653
7726
|
message: `jsonPath "${t.jsonPath}" 含非法段`,
|
|
7654
7727
|
hint: "使用正常属性路径"
|
|
@@ -7659,7 +7732,7 @@ function _l(e, n = {}) {
|
|
|
7659
7732
|
hint: "仅 schema 声明的 key 可删"
|
|
7660
7733
|
});
|
|
7661
7734
|
if (d) {
|
|
7662
|
-
let e =
|
|
7735
|
+
let e = il(t.jsonPath, d.resourcesByPath);
|
|
7663
7736
|
if (e) return Y({
|
|
7664
7737
|
code: e.spec.mode === "freeze" ? "FROZEN_FIELD" : "VERBATIM_PROTECTED",
|
|
7665
7738
|
message: `write delete @ "${t.jsonPath}" 命中受保护字段 "${e.protectedPath}"(${e.spec.mode}),不可删除`,
|
|
@@ -7669,11 +7742,11 @@ function _l(e, n = {}) {
|
|
|
7669
7742
|
let e = await x("delete", v);
|
|
7670
7743
|
if (e !== null) return e;
|
|
7671
7744
|
if (c) {
|
|
7672
|
-
let e =
|
|
7673
|
-
return
|
|
7745
|
+
let e = fc(a);
|
|
7746
|
+
return dc(e, t.jsonPath) ? `dryRun(delete): 将删除 @ ${t.jsonPath}。预览剩余:${Q(e, 600)}。未实际写入、未入快照。` : `dryRun(delete): @ ${t.jsonPath} 不存在(无需删除)。未实际写入。`;
|
|
7674
7747
|
}
|
|
7675
7748
|
b("delete");
|
|
7676
|
-
let n =
|
|
7749
|
+
let n = dc(a, t.jsonPath);
|
|
7677
7750
|
return _(), y({
|
|
7678
7751
|
op: "delete",
|
|
7679
7752
|
detail: t.jsonPath,
|
|
@@ -7692,7 +7765,7 @@ function _l(e, n = {}) {
|
|
|
7692
7765
|
op: t.op ?? "set",
|
|
7693
7766
|
jsonPath: t.jsonPath || "",
|
|
7694
7767
|
value: u
|
|
7695
|
-
}]), o =
|
|
7768
|
+
}]), o = _l({
|
|
7696
7769
|
bindRef: a,
|
|
7697
7770
|
patches: n,
|
|
7698
7771
|
schema: i,
|
|
@@ -7711,11 +7784,11 @@ function _l(e, n = {}) {
|
|
|
7711
7784
|
timestamp: Date.now()
|
|
7712
7785
|
}), m = $(a), `已 write(edit) 主数据(${o.applied.length} 个 patch)。当前值:${Q(a, 600)} (新 hash=${$(a)})`) : o.error;
|
|
7713
7786
|
}
|
|
7714
|
-
let S =
|
|
7787
|
+
let S = pc(u);
|
|
7715
7788
|
if (S.parseError) return Gr("", u, S.parseError);
|
|
7716
7789
|
let C = await x("set", v);
|
|
7717
7790
|
if (C !== null) return C;
|
|
7718
|
-
let w =
|
|
7791
|
+
let w = gl({
|
|
7719
7792
|
bindRef: a,
|
|
7720
7793
|
value: S.parsed,
|
|
7721
7794
|
schema: i,
|
|
@@ -7772,7 +7845,7 @@ function _l(e, n = {}) {
|
|
|
7772
7845
|
if (n) {
|
|
7773
7846
|
let e = t;
|
|
7774
7847
|
if (typeof e == "string") {
|
|
7775
|
-
let t =
|
|
7848
|
+
let t = pc(e);
|
|
7776
7849
|
t.parseError || (e = t.parsed);
|
|
7777
7850
|
}
|
|
7778
7851
|
r = e, i = "against";
|
|
@@ -7790,7 +7863,7 @@ function _l(e, n = {}) {
|
|
|
7790
7863
|
});
|
|
7791
7864
|
r = t.value, i = `快照 #${t.id}`;
|
|
7792
7865
|
}
|
|
7793
|
-
let o = s ? Li(a, s) : a, c =
|
|
7866
|
+
let o = s ? Li(a, s) : a, c = xc(r, fc(o));
|
|
7794
7867
|
return c.length ? `差异(当前 vs ${i},共 ${c.length} 处):\n${c.map((e) => ` ${e.path}: ${Q(e.from)} → ${Q(e.to)}`).join("\n")}` : `无差异:当前主数据与 ${i} 完全相同。`;
|
|
7795
7868
|
}, {
|
|
7796
7869
|
name: "diff_data",
|
|
@@ -7842,7 +7915,7 @@ function _l(e, n = {}) {
|
|
|
7842
7915
|
}
|
|
7843
7916
|
let u = await x("set", n || (h ? m : void 0));
|
|
7844
7917
|
if (u !== null) return u;
|
|
7845
|
-
let g =
|
|
7918
|
+
let g = gl({
|
|
7846
7919
|
bindRef: a,
|
|
7847
7920
|
value: l,
|
|
7848
7921
|
schema: i,
|
|
@@ -7874,7 +7947,7 @@ function _l(e, n = {}) {
|
|
|
7874
7947
|
message: "未提供 path 或有效 handle",
|
|
7875
7948
|
hint: "传 path(受保护字段)或 handle(占位符 ⟦res:handle⟧ 里的句柄)"
|
|
7876
7949
|
});
|
|
7877
|
-
let r =
|
|
7950
|
+
let r = tl(n);
|
|
7878
7951
|
if (!c.has(r)) return Y({
|
|
7879
7952
|
code: "RESOURCE_NOT_FOUND",
|
|
7880
7953
|
message: `"${n}" 不是受保护字段`,
|
|
@@ -7913,7 +7986,7 @@ function _l(e, n = {}) {
|
|
|
7913
7986
|
message: "resource_update 需要 path",
|
|
7914
7987
|
hint: "传要更新的 verbatim 受保护字段路径"
|
|
7915
7988
|
});
|
|
7916
|
-
let n =
|
|
7989
|
+
let n = tl(e), r = c.get(n);
|
|
7917
7990
|
if (!r) return Y({
|
|
7918
7991
|
code: "RESOURCE_NOT_FOUND",
|
|
7919
7992
|
message: `"${e}" 不是受保护字段`,
|
|
@@ -7934,7 +8007,7 @@ function _l(e, n = {}) {
|
|
|
7934
8007
|
details: Ur(n.error.issues)
|
|
7935
8008
|
});
|
|
7936
8009
|
}
|
|
7937
|
-
l.update(n, t),
|
|
8010
|
+
l.update(n, t), uc(a, n, t), m = $(a), _();
|
|
7938
8011
|
let s = l.get(n)?.handle;
|
|
7939
8012
|
return `已更新 verbatim 资源 "${e}" = ${Q(t, 200)}(handle ${s ?? "(未知)"} 不变)。后续 write 该字段写回句柄 ⟦res:${s}⟧ 或新值`;
|
|
7940
8013
|
}, {
|
|
@@ -7995,8 +8068,8 @@ function _l(e, n = {}) {
|
|
|
7995
8068
|
}
|
|
7996
8069
|
//#endregion
|
|
7997
8070
|
//#region src/core/tools/fetchDoc.ts
|
|
7998
|
-
var
|
|
7999
|
-
let n = new AbortController(), r = setTimeout(() => n.abort(),
|
|
8071
|
+
var yl = 3e4, bl = [r(async ({ url: e, as: t }) => {
|
|
8072
|
+
let n = new AbortController(), r = setTimeout(() => n.abort(), yl);
|
|
8000
8073
|
try {
|
|
8001
8074
|
let r = await fetch(e, {
|
|
8002
8075
|
method: "GET",
|
|
@@ -8013,7 +8086,7 @@ var vl = 3e4, yl = [r(async ({ url: e, as: t }) => {
|
|
|
8013
8086
|
].join("\n");
|
|
8014
8087
|
} catch (t) {
|
|
8015
8088
|
let r = t?.message || String(t);
|
|
8016
|
-
return n.signal.aborted ? `获取失败:请求超时(${
|
|
8089
|
+
return n.signal.aborted ? `获取失败:请求超时(${yl}ms,${e})。` : /Failed to fetch|NetworkError|CORS|blocked/i.test(r) ? `获取失败:可能是 CORS 跨域拦截或网络错误(${r})。浏览器仅能 GET 同源或服务端已配置 CORS 的资源;跨域抓取需后端代理。` : `获取失败:${r}`;
|
|
8017
8090
|
} finally {
|
|
8018
8091
|
clearTimeout(r);
|
|
8019
8092
|
}
|
|
@@ -8024,7 +8097,7 @@ var vl = 3e4, yl = [r(async ({ url: e, as: t }) => {
|
|
|
8024
8097
|
url: t.string().describe("要抓取的 URL(同源或已配 CORS)"),
|
|
8025
8098
|
as: t.enum(["text", "markdown"]).optional().describe("返回格式标签,默认 text")
|
|
8026
8099
|
})
|
|
8027
|
-
})],
|
|
8100
|
+
})], xl = [
|
|
8028
8101
|
"id",
|
|
8029
8102
|
"class",
|
|
8030
8103
|
"href",
|
|
@@ -8036,12 +8109,12 @@ var vl = 3e4, yl = [r(async ({ url: e, as: t }) => {
|
|
|
8036
8109
|
"aria-label",
|
|
8037
8110
|
"name",
|
|
8038
8111
|
"type"
|
|
8039
|
-
],
|
|
8040
|
-
function
|
|
8112
|
+
], Sl = /^(value|srcdoc|formaction|on\w+)$/i, Cl = /token|secret|password|passwd|api[-_]?key|auth|cred|csrf|session/i;
|
|
8113
|
+
function wl(e, t) {
|
|
8041
8114
|
if (!e) return null;
|
|
8042
|
-
let { depth: n, attrs: r, includeText: i = !0 } = t, a = r !== void 0, o = r ??
|
|
8115
|
+
let { depth: n, attrs: r, includeText: i = !0 } = t, a = r !== void 0, o = r ?? xl, s = (e) => {
|
|
8043
8116
|
let t = {};
|
|
8044
|
-
for (let n of Array.from(e.attributes)) (a ? o.includes(n.name) : o.includes(n.name) || n.name.startsWith("data-")) && (
|
|
8117
|
+
for (let n of Array.from(e.attributes)) (a ? o.includes(n.name) : o.includes(n.name) || n.name.startsWith("data-")) && (Sl.test(n.name) || Cl.test(n.name) || (t[n.name] = n.value));
|
|
8045
8118
|
return t;
|
|
8046
8119
|
}, c = (e, t) => {
|
|
8047
8120
|
let n = {
|
|
@@ -8057,10 +8130,10 @@ function Cl(e, t) {
|
|
|
8057
8130
|
};
|
|
8058
8131
|
return c(e, n);
|
|
8059
8132
|
}
|
|
8060
|
-
var
|
|
8133
|
+
var Tl = r(({ selector: e, depth: t, attrs: n, includeText: r }) => {
|
|
8061
8134
|
let i = e ? document.querySelector(e) : document.body;
|
|
8062
8135
|
if (!i) return `未找到匹配元素:selector="${e}"`;
|
|
8063
|
-
let a =
|
|
8136
|
+
let a = wl(i, {
|
|
8064
8137
|
depth: t ?? 3,
|
|
8065
8138
|
attrs: n,
|
|
8066
8139
|
includeText: r ?? !0
|
|
@@ -8075,14 +8148,14 @@ var wl = r(({ selector: e, depth: t, attrs: n, includeText: r }) => {
|
|
|
8075
8148
|
attrs: t.array(t.string()).optional().describe("属性白名单(传了 = 严格白名单;不传 = 默认常用 + data-*)"),
|
|
8076
8149
|
includeText: t.boolean().optional().describe("是否包含直接文本(默认 true)")
|
|
8077
8150
|
})
|
|
8078
|
-
}),
|
|
8151
|
+
}), El = [Tl];
|
|
8079
8152
|
//#endregion
|
|
8080
8153
|
//#region src/core/tools/envTool.ts
|
|
8081
|
-
function
|
|
8154
|
+
function Dl(e) {
|
|
8082
8155
|
let t = e;
|
|
8083
8156
|
return typeof t.tagName == "string" || typeof t.nodeType == "number" && typeof t.nodeName == "string";
|
|
8084
8157
|
}
|
|
8085
|
-
function
|
|
8158
|
+
function Ol(e, t = 3, n = 2e3, r) {
|
|
8086
8159
|
if (e == null) return e;
|
|
8087
8160
|
if (typeof e == "string") return e.length > n ? e.slice(0, n) + "…(已截断)" : e;
|
|
8088
8161
|
if (typeof e == "number" || typeof e == "boolean") return e;
|
|
@@ -8091,14 +8164,14 @@ function Dl(e, t = 3, n = 2e3, r) {
|
|
|
8091
8164
|
if (typeof e == "bigint") return `${e.toString()}n`;
|
|
8092
8165
|
if (typeof e != "object") return String(e);
|
|
8093
8166
|
let i = e;
|
|
8094
|
-
if (
|
|
8167
|
+
if (Dl(i)) {
|
|
8095
8168
|
let e = i;
|
|
8096
8169
|
return e.tagName ? `[Element: <${e.tagName.toLowerCase()}>]` : `[Node: ${e.nodeName}]`;
|
|
8097
8170
|
}
|
|
8098
8171
|
if (r?.has(i)) return "[Circular]";
|
|
8099
8172
|
let a = r ?? /* @__PURE__ */ new WeakSet();
|
|
8100
8173
|
if (a.add(i), Array.isArray(e)) {
|
|
8101
|
-
let r = e.slice(0, 100).map((e) =>
|
|
8174
|
+
let r = e.slice(0, 100).map((e) => Ol(e, t - 1, n, a));
|
|
8102
8175
|
return e.length > 100 && r.push(`…(共 ${e.length} 项,已截断)`), r;
|
|
8103
8176
|
}
|
|
8104
8177
|
if (t < 0) return "(对象,已截断)";
|
|
@@ -8110,14 +8183,14 @@ function Dl(e, t = 3, n = 2e3, r) {
|
|
|
8110
8183
|
break;
|
|
8111
8184
|
}
|
|
8112
8185
|
try {
|
|
8113
|
-
o[r] =
|
|
8186
|
+
o[r] = Ol(i[r], t - 1, n, a);
|
|
8114
8187
|
} catch {
|
|
8115
8188
|
o[r] = "(getter 抛错)";
|
|
8116
8189
|
}
|
|
8117
8190
|
}
|
|
8118
8191
|
return o;
|
|
8119
8192
|
}
|
|
8120
|
-
function
|
|
8193
|
+
function kl(e) {
|
|
8121
8194
|
let t = e ?? (typeof window < "u" ? window : {}), n = t.navigator, r = t.location, i = t.document;
|
|
8122
8195
|
return {
|
|
8123
8196
|
location: {
|
|
@@ -8150,9 +8223,9 @@ function Ol(e) {
|
|
|
8150
8223
|
} : "(无 document)"
|
|
8151
8224
|
};
|
|
8152
8225
|
}
|
|
8153
|
-
var
|
|
8226
|
+
var Al = /^(localStorage|sessionStorage|cookie|document|frames|frameElement|opener|parent|top|self|window|globalThis|closed|history|navigation|trustedTypes|origin|crossOriginIsolated)$/, jl = /token|secret|password|passwd|api[-_]?key|auth|cred|csrf|session|ticket/i, Ml = r(({ key: e }) => {
|
|
8154
8227
|
if (e) {
|
|
8155
|
-
if (
|
|
8228
|
+
if (Al.test(e) || jl.test(e)) return JSON.stringify({
|
|
8156
8229
|
key: e,
|
|
8157
8230
|
denied: !0,
|
|
8158
8231
|
reason: "安全:该 key 在 denylist(localStorage/sessionStorage/cookie/document 或敏感命名 token/secret/key/auth),不读取防泄漏"
|
|
@@ -8162,18 +8235,18 @@ var kl = /^(localStorage|sessionStorage|cookie|document|frames|frameElement|open
|
|
|
8162
8235
|
key: e,
|
|
8163
8236
|
exists: t !== void 0,
|
|
8164
8237
|
type: typeof t,
|
|
8165
|
-
value:
|
|
8238
|
+
value: Ol(t)
|
|
8166
8239
|
}, null, 2);
|
|
8167
8240
|
}
|
|
8168
|
-
return JSON.stringify(
|
|
8241
|
+
return JSON.stringify(kl(), null, 2);
|
|
8169
8242
|
}, {
|
|
8170
8243
|
name: "inspect_env",
|
|
8171
8244
|
description: "读取宿主页面环境信息(排查调试用,默认开启)。不传参 = 返回环境摘要(location 的 URL/origin/path、navigator 的浏览器/语言、viewport 视口尺寸、document 的 title/readyState);传 key = 读取指定 window 属性值(如 inspect_env({key:\"appConfig\"}) 读集成方挂的调试变量 window.appConfig)。用于排查「当前页面在哪/什么浏览器/视口多大/调试变量值是什么」。轻量只读,大结果自动外存 vfs。",
|
|
8172
8245
|
schema: t.object({ key: t.string().optional().describe("要读取的 window 属性名(如 \"appConfig\"/\"__DEBUG__\");不传 = 返回环境摘要") })
|
|
8173
|
-
}),
|
|
8246
|
+
}), Nl = [Ml];
|
|
8174
8247
|
//#endregion
|
|
8175
8248
|
//#region src/core/harness/budget.ts
|
|
8176
|
-
function
|
|
8249
|
+
function Pl(e, t, n) {
|
|
8177
8250
|
let r = 0;
|
|
8178
8251
|
return {
|
|
8179
8252
|
name: "budget",
|
|
@@ -8198,12 +8271,12 @@ function Nl(e, t, n) {
|
|
|
8198
8271
|
}
|
|
8199
8272
|
//#endregion
|
|
8200
8273
|
//#region src/core/sdk/actions.ts
|
|
8201
|
-
var
|
|
8202
|
-
function
|
|
8274
|
+
var Fl = /^[a-zA-Z][a-zA-Z0-9_]*$/;
|
|
8275
|
+
function Il(e) {
|
|
8203
8276
|
let n = [];
|
|
8204
8277
|
for (let [i, a] of Object.entries(e)) {
|
|
8205
|
-
if (!
|
|
8206
|
-
console.warn(`[page-agent-sdk][actions] 动作名 "${i}" 非法(须匹配 ${
|
|
8278
|
+
if (!Fl.test(i)) {
|
|
8279
|
+
console.warn(`[page-agent-sdk][actions] 动作名 "${i}" 非法(须匹配 ${Fl}),已跳过`);
|
|
8207
8280
|
continue;
|
|
8208
8281
|
}
|
|
8209
8282
|
let e = a.description || `宿主动作 ${i}`;
|
|
@@ -8223,9 +8296,9 @@ function Fl(e) {
|
|
|
8223
8296
|
}
|
|
8224
8297
|
return n;
|
|
8225
8298
|
}
|
|
8226
|
-
function
|
|
8299
|
+
function Ll(e) {
|
|
8227
8300
|
let t = {};
|
|
8228
|
-
for (let [n, r] of Object.entries(e))
|
|
8301
|
+
for (let [n, r] of Object.entries(e)) Fl.test(n) && (t[n] = {
|
|
8229
8302
|
description: r.description,
|
|
8230
8303
|
hasParams: !!r.params
|
|
8231
8304
|
});
|
|
@@ -8233,12 +8306,12 @@ function Il(e) {
|
|
|
8233
8306
|
}
|
|
8234
8307
|
//#endregion
|
|
8235
8308
|
//#region src/core/toolsets.ts
|
|
8236
|
-
var
|
|
8237
|
-
function
|
|
8238
|
-
return
|
|
8309
|
+
var Rl = bl, zl = El;
|
|
8310
|
+
function Bl(e, t) {
|
|
8311
|
+
return vl(e, t);
|
|
8239
8312
|
}
|
|
8240
|
-
function
|
|
8241
|
-
let a =
|
|
8313
|
+
function Vl(e, t, n, r, i) {
|
|
8314
|
+
let a = ec(e);
|
|
8242
8315
|
return [
|
|
8243
8316
|
...a.dataOps ? t : [],
|
|
8244
8317
|
...a.fetch ? n : [],
|
|
@@ -8248,7 +8321,7 @@ function Bl(e, t, n, r, i) {
|
|
|
8248
8321
|
}
|
|
8249
8322
|
//#endregion
|
|
8250
8323
|
//#region src/core/sdk/toolRegistry.ts
|
|
8251
|
-
function
|
|
8324
|
+
function Hl(e) {
|
|
8252
8325
|
let t = /* @__PURE__ */ new Map(), n = [];
|
|
8253
8326
|
for (let r of e) for (let e of r.tools) {
|
|
8254
8327
|
let i = t.get(e.name);
|
|
@@ -8268,15 +8341,15 @@ function Vl(e) {
|
|
|
8268
8341
|
}
|
|
8269
8342
|
//#endregion
|
|
8270
8343
|
//#region src/core/harness/usageHints.ts
|
|
8271
|
-
var
|
|
8272
|
-
function
|
|
8273
|
-
let i =
|
|
8344
|
+
var Ul = .7;
|
|
8345
|
+
function Wl(e, t, n = "simple", r = !1) {
|
|
8346
|
+
let i = ec(e), a = n !== "advanced";
|
|
8274
8347
|
return {
|
|
8275
8348
|
name: "usageHints",
|
|
8276
8349
|
augmentPrompt: () => {
|
|
8277
8350
|
let n = [];
|
|
8278
8351
|
if (i.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 && (a ? (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("read/describe 返回按 schema 投影:仅 schema 声明的字段可见(未声明字段自动隐藏,防误操作);要操作某字段需集成方在 schema 声明,查任意路径完整约束用 schema_data({jsonPath})。"), 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?})。"))), i.subagent && n.push("独立子任务可 spawn_agent 委派(只读工具,过程不占主上下文)。"), i.inspectEnv && n.push("排查页面环境(当前 URL/浏览器/视口/集成方调试变量)用 inspect_env——不传参返回环境摘要(location/navigator/viewport/document),传 key 读特定 window 属性(如 inspect_env({key:\"appConfig\"}) 读 window.appConfig)。改完数据看渲染、定位\"为何没生效\"时用它(只读,不改数据)。"), i.domInspect && n.push("改完数据想确认渲染是否生效(或定位元素/辅助 UI 设计问答)用 get_dom({selector?,depth?}) 读渲染后 DOM(结构化返回 tag/attrs/text/children,depth 控制深度防爆炸,只读)。配合宿主 actions(save_draft/publish 等)形成\"改数据→get_dom 看渲染→触发动作\"闭环。"), i.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。"), i.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 被改过会触发冲突介入,不静默覆盖)。"), i.todoDeps && n.push("复杂任务可用 todos 层级依赖:write_todos 时给 todo 传 parentId(父任务 id,表达层级)+ deps(依赖的 todo id 数组,必须先完成)。有依赖的任务,deps 全 completed 后再标 in_progress;完成时 update_todo({id, status:\"completed\", evidence:\"完成证据\"}) 记证据。无依赖关系的任务不传 parentId/deps(扁平)。"), i.focus && !a && (n.push("【上下文聚焦】判断任务范围,用 set_focus/add_focus/remove_focus/clear_focus 自动收敛工作范围:"), n.push(" · 局部任务(只改某一组件/区域,如「调导航栏」「改 components.3 样式」)→ 先 read 定位 jsonPath,再 set_focus({path:\"该子树路径\"}) 聚焦;聚焦后每轮只看该子树结构,写其他位置会被 PATH_DENIED 拒绝。"), n.push(" · 多个相关组件(如「同时改导航栏和页脚」)→ set_focus 聚焦首个后用 add_focus({path}) 追加其余;聚焦后可写任一焦点子树,越界仍被拒;移除单个用 remove_focus({path})。"), n.push(" · 全局任务(多处/整体结构,如「重排所有组件」「换主题」)→ 不要聚焦,保持全量视野直接写。"), n.push(" · 完成局部精修、要转向其他区域或做整体改动 → 调 clear_focus 退出聚焦(清空全部焦点),恢复全部读写权限。"), n.push(" · set_focus/add_focus 的 path 必须在 schema 内(类型校验);不确定路径先 read/describe_data 查。")), r && (n.push("【受保护资源·精确值保护】部分字段被 freeze/verbatim 保护(集成方在 data.resources 声明):"), n.push(" · read 受保护路径返回占位符 ⟦frozen:path⟧(freeze,精确值不入消息流)或 ⟦res:handle⟧(verbatim,原值在资源池),非真值。"), n.push(" · 确需真值用 resource_get({path})(仅受保护路径);freeze 字段完全不可改,撞 FROZEN_FIELD 即放弃该字段改动。"), n.push(" · verbatim 字段改新值:先 resource_update({path,value}) 更新资源池(同步 bind),再 write 写回句柄 ⟦res:handle⟧;直接写新值 → VERBATIM_MISMATCH。"), n.push(" · 撞 RESOURCE_EVICTED(资源被池淘汰)→ 重新 read 该字段懒注册重建句柄;撞 RESOURCE_NOT_FOUND → 重新 read。")), e?.subagents?.length) {
|
|
8279
|
-
let t = e.subagents.filter((e) => (e.temperature ?? 0) >=
|
|
8352
|
+
let t = e.subagents.filter((e) => (e.temperature ?? 0) >= Ul || /规划|创意|设计|方案|brainstorm|plan/i.test(e.description)), r = e.subagents.filter((e) => (e.temperature ?? 0) < Ul && /反思|审查|挑刺|校验|review|critique|reflect/i.test(e.description));
|
|
8280
8353
|
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(a ? " · 方案定稿后,由你(主 agent)用 write 落地成 JSON(低温度执行 + schema 校验 + 写前确认)。" : " · 方案定稿后,由你(主 agent)用 edit_data 落地成 JSON(低温度执行 + schema 校验 + 写前确认)。"), n.push(" · 简单/明确任务(如\"标题改红色\")直接执行,不必走规划-反思。");
|
|
8281
8354
|
}
|
|
8282
8355
|
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;
|
|
@@ -8285,7 +8358,7 @@ function Ul(e, t, n = "simple", r = !1) {
|
|
|
8285
8358
|
}
|
|
8286
8359
|
//#endregion
|
|
8287
8360
|
//#region src/core/harness/resourcesPin.ts
|
|
8288
|
-
function
|
|
8361
|
+
function Gl(e) {
|
|
8289
8362
|
return {
|
|
8290
8363
|
name: "resourcesPin",
|
|
8291
8364
|
augmentPrompt: () => {
|
|
@@ -8299,78 +8372,78 @@ function Wl(e) {
|
|
|
8299
8372
|
}
|
|
8300
8373
|
//#endregion
|
|
8301
8374
|
//#region src/core/backends/skillStore.ts
|
|
8302
|
-
var
|
|
8303
|
-
function
|
|
8304
|
-
return `${
|
|
8375
|
+
var Kl = "v:1::skill-store", ql = "chat-sdk";
|
|
8376
|
+
function Jl(e, t, n) {
|
|
8377
|
+
return `${Kl}::${e}::${t}::${n}`;
|
|
8305
8378
|
}
|
|
8306
|
-
function
|
|
8307
|
-
return `${
|
|
8379
|
+
function Yl(e, t) {
|
|
8380
|
+
return `${Kl}::${e}::${t}::`;
|
|
8308
8381
|
}
|
|
8309
|
-
function
|
|
8310
|
-
let t = e.dbName ??
|
|
8382
|
+
function Xl(e = {}) {
|
|
8383
|
+
let t = e.dbName ?? ql, n = e.backend ?? "indexed", r = e.id ?? "", i, a, o = new Promise((e) => {
|
|
8311
8384
|
a = e;
|
|
8312
8385
|
});
|
|
8313
8386
|
return (async () => {
|
|
8314
8387
|
try {
|
|
8315
8388
|
if (n === "indexed") {
|
|
8316
8389
|
if (typeof indexedDB > "u") throw Error("indexedDB 不可用");
|
|
8317
|
-
i = await
|
|
8390
|
+
i = await qs(t), a(!0);
|
|
8318
8391
|
} else if (n === "session") {
|
|
8319
8392
|
if (typeof sessionStorage > "u") throw Error("sessionStorage 不可用");
|
|
8320
|
-
i =
|
|
8393
|
+
i = Js(sessionStorage), a(!0);
|
|
8321
8394
|
} else if (n === "local") {
|
|
8322
8395
|
if (typeof localStorage > "u") throw Error("localStorage 不可用");
|
|
8323
|
-
i =
|
|
8324
|
-
} else i =
|
|
8396
|
+
i = Js(localStorage), a(!0);
|
|
8397
|
+
} else i = Ks(), a(!1);
|
|
8325
8398
|
} catch {
|
|
8326
|
-
i =
|
|
8399
|
+
i = Ks(), a(!1);
|
|
8327
8400
|
}
|
|
8328
8401
|
})(), {
|
|
8329
8402
|
ready: o,
|
|
8330
8403
|
async list() {
|
|
8331
8404
|
let e = [];
|
|
8332
|
-
return await i.scan(
|
|
8405
|
+
return await i.scan(Yl(t, r), (t, n) => {
|
|
8333
8406
|
e.push(n);
|
|
8334
8407
|
}), e;
|
|
8335
8408
|
},
|
|
8336
8409
|
async get(e) {
|
|
8337
|
-
return await i.get(
|
|
8410
|
+
return await i.get(Jl(t, r, e));
|
|
8338
8411
|
},
|
|
8339
8412
|
async put(e) {
|
|
8340
8413
|
try {
|
|
8341
|
-
await i.set(
|
|
8414
|
+
await i.set(Jl(t, r, e.name), e);
|
|
8342
8415
|
} catch (e) {
|
|
8343
|
-
|
|
8416
|
+
Rs(e) && (i = Ks());
|
|
8344
8417
|
}
|
|
8345
8418
|
},
|
|
8346
8419
|
async remove(e) {
|
|
8347
|
-
let n =
|
|
8420
|
+
let n = Jl(t, r, e);
|
|
8348
8421
|
return await i.get(n) == null ? !1 : (await i.del(n), !0);
|
|
8349
8422
|
},
|
|
8350
8423
|
async clear() {
|
|
8351
|
-
await i.clearPrefix(
|
|
8424
|
+
await i.clearPrefix(Yl(t, r));
|
|
8352
8425
|
},
|
|
8353
8426
|
dispose() {}
|
|
8354
8427
|
};
|
|
8355
8428
|
}
|
|
8356
|
-
var
|
|
8357
|
-
function
|
|
8429
|
+
var Zl = /large_results\/[^\s"'`),]+\.txt/g;
|
|
8430
|
+
function Ql(e) {
|
|
8358
8431
|
let t = /* @__PURE__ */ new Set(), n = (e) => {
|
|
8359
8432
|
if (typeof e != "string" || !e) return;
|
|
8360
8433
|
let n;
|
|
8361
|
-
for (
|
|
8434
|
+
for (Zl.lastIndex = 0; (n = Zl.exec(e)) !== null;) t.add(n[0]);
|
|
8362
8435
|
};
|
|
8363
8436
|
for (let t of e) if (n(t.content), t.steps) for (let e of t.steps) n(e.result);
|
|
8364
8437
|
return t;
|
|
8365
8438
|
}
|
|
8366
|
-
function
|
|
8439
|
+
function $l(e, t) {
|
|
8367
8440
|
let n = [];
|
|
8368
8441
|
for (let r of Object.keys(e)) r.startsWith("large_results/") && !t.has(r) && n.push(r);
|
|
8369
8442
|
return n;
|
|
8370
8443
|
}
|
|
8371
8444
|
//#endregion
|
|
8372
8445
|
//#region src/core/utils/serialRunner.ts
|
|
8373
|
-
function
|
|
8446
|
+
function eu() {
|
|
8374
8447
|
let e = Promise.resolve();
|
|
8375
8448
|
return function(t) {
|
|
8376
8449
|
let n = e.then(t, t);
|
|
@@ -8379,16 +8452,16 @@ function $l() {
|
|
|
8379
8452
|
}
|
|
8380
8453
|
//#endregion
|
|
8381
8454
|
//#region src/core/sdk/createChatSdk.ts
|
|
8382
|
-
var
|
|
8383
|
-
function
|
|
8455
|
+
var tu = 30, nu = /* @__PURE__ */ new Map();
|
|
8456
|
+
function ru(e, t) {
|
|
8384
8457
|
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;
|
|
8385
8458
|
}
|
|
8386
|
-
function
|
|
8459
|
+
function iu(e, t, n, r) {
|
|
8387
8460
|
let i = 0;
|
|
8388
8461
|
return {
|
|
8389
8462
|
name: "sdk-events",
|
|
8390
8463
|
wrapToolCall: async (t, r) => {
|
|
8391
|
-
let i = await r(t), a =
|
|
8464
|
+
let i = await r(t), a = ru(t.name, t.args);
|
|
8392
8465
|
return a && e({
|
|
8393
8466
|
type: "data_change",
|
|
8394
8467
|
operation: a,
|
|
@@ -8423,7 +8496,7 @@ function ru(e, t, n, r) {
|
|
|
8423
8496
|
}
|
|
8424
8497
|
};
|
|
8425
8498
|
}
|
|
8426
|
-
function
|
|
8499
|
+
function au(e, t, n, r, i) {
|
|
8427
8500
|
if (!n) return i && console.warn(`[page-agent-sdk][focus] capabilities.focus 关闭,${t} 忽略`), {
|
|
8428
8501
|
ok: !1,
|
|
8429
8502
|
error: "capabilities.focus 关闭"
|
|
@@ -8441,18 +8514,18 @@ function iu(e, t, n, r, i) {
|
|
|
8441
8514
|
error: "当前无主数据 schema,无法聚焦"
|
|
8442
8515
|
});
|
|
8443
8516
|
}
|
|
8444
|
-
function
|
|
8517
|
+
function ou(e, n) {
|
|
8445
8518
|
let i = {
|
|
8446
8519
|
prompt_tokens: 0,
|
|
8447
8520
|
completion_tokens: 0,
|
|
8448
8521
|
total_tokens: 0
|
|
8449
|
-
}, a =
|
|
8522
|
+
}, a = Ts(() => H), o = /* @__PURE__ */ Ot(0), s = Zs(e.storage);
|
|
8450
8523
|
e.debug && s && s.onEvent((e) => console.log("[page-agent-sdk][storage]", e));
|
|
8451
|
-
let { modelCaps: c, summaryLlmInvoke: l, titleLlmInvoke: u, compressDecisionInvoke: p } =
|
|
8524
|
+
let { modelCaps: c, summaryLlmInvoke: l, titleLlmInvoke: u, compressDecisionInvoke: p } = ws(e), m = c;
|
|
8452
8525
|
if (e.debug && console.log("[page-agent-sdk][modelCaps]", m), m.contextWindow < 2e5) throw Error(`[page-agent-sdk] 模型上下文窗口 ${m.contextWindow} 小于最小支持 ${ti}(需 ≥200K 窗口模型,如 GLM-5.2/Claude/Kimi/Qwen-1M/DeepSeek-v4)`);
|
|
8453
|
-
let h =
|
|
8526
|
+
let h = ic(e, m.contextWindow), g = h.enableLLMSummary !== !1, _ = (e.contextOptions && e.contextOptions.preserveLastToolResults) ?? rc[e.contextPreset ?? "auto"], v = new Set(_), y = e.llm;
|
|
8454
8527
|
e.debug && !l && console.warn("[page-agent-sdk][summarization] 未构造 llmInvoke(apiKey 缺失?),摘要回退零成本索引摘要");
|
|
8455
|
-
let b = /* @__PURE__ */ _t([]), x =
|
|
8528
|
+
let b = /* @__PURE__ */ _t([]), x = Tc(e.vfs?.initialFiles, {
|
|
8456
8529
|
persist: s ? { save: (e) => {
|
|
8457
8530
|
W.sessionId && s && s.save(n, W.sessionId, { vfs: e });
|
|
8458
8531
|
} } : void 0,
|
|
@@ -8472,18 +8545,18 @@ function au(e, n) {
|
|
|
8472
8545
|
getTodos: () => ee.current?.getState?.()?.todos ?? [],
|
|
8473
8546
|
messages: b,
|
|
8474
8547
|
maxCheckpoints: O && typeof O == "object" ? O.maxCheckpoints : void 0
|
|
8475
|
-
}) : null, te = !O || typeof O != "object" || O.auto !== !1, j =
|
|
8548
|
+
}) : null, te = !O || typeof O != "object" || O.auto !== !1, j = ec(e.capabilities), ne = j.dataOps, M = j.draftWrite, N = j.tracing, re = j.automation, P = ls(e), ie = ne && D ? vl(D, {
|
|
8476
8549
|
onAudit: e.onAudit ?? (e.debug ? (e) => console.log("[page-agent-sdk][data audit]", e) : void 0),
|
|
8477
8550
|
maxSnapshots: e.maxSnapshots,
|
|
8478
8551
|
onConflict: a.set,
|
|
8479
8552
|
autoLock: e.autoLock,
|
|
8480
8553
|
interceptors: e.interceptors,
|
|
8481
8554
|
vfsStore: M || D?.resources?.length ? x : void 0
|
|
8482
|
-
}) : [], ae = ne ?
|
|
8555
|
+
}) : [], ae = ne ? hl(ie, e.toolMode) : [], oe = ne && D ? ie.controller ?? null : null, se = ne && D?.resources?.length && oe?.getResourcesSnapshot ? Gl({ getResourcesSnapshot: () => oe?.getResourcesSnapshot?.() ?? [] }) : void 0, F = () => oe?.get() ?? D, I = /* @__PURE__ */ new Map(), ce = Vl(j, ae, bl, El, Nl);
|
|
8483
8556
|
ce.forEach((e) => I.set(e.name, "builtin"));
|
|
8484
8557
|
let le = [...e.tools || []];
|
|
8485
8558
|
le.forEach((e) => I.set(e.name, "user"));
|
|
8486
|
-
let L =
|
|
8559
|
+
let L = Il(e.actions ?? {});
|
|
8487
8560
|
L.forEach((e) => I.set(e.name, "action"));
|
|
8488
8561
|
let ue = [], de = e.humanConfirm !== !1 && (!e.approval || e.approval.humanConfirmTool !== !1), fe = de ? Wa() : null;
|
|
8489
8562
|
fe && I.set(Ha, "builtin");
|
|
@@ -8555,7 +8628,7 @@ function au(e, n) {
|
|
|
8555
8628
|
ve.forEach((e) => I.set(e.name, "builtin"));
|
|
8556
8629
|
let z = [], ye = /* @__PURE__ */ new Map(), B = be();
|
|
8557
8630
|
function be() {
|
|
8558
|
-
let { tools: e, collisions: t } =
|
|
8631
|
+
let { tools: e, collisions: t } = Hl([
|
|
8559
8632
|
{
|
|
8560
8633
|
label: "builtin",
|
|
8561
8634
|
tools: ce
|
|
@@ -8592,49 +8665,51 @@ function au(e, n) {
|
|
|
8592
8665
|
return t.length && console.warn("[page-agent-sdk] 工具重名,后注册覆盖先注册:", t.map((e) => `${e.name}(${e.loser}→${e.winner})`).join(", ")), e;
|
|
8593
8666
|
}
|
|
8594
8667
|
let xe = j.planning, Se = j.missionAnchor, Ce = j.workingMemory, we = j.skills, Te = j.vfs;
|
|
8595
|
-
if (Te) for (let e of
|
|
8668
|
+
if (Te) for (let e of Mc) I.set(e, "builtin");
|
|
8596
8669
|
if (xe) for (let e of S.tools ?? []) I.set(e.name, "builtin");
|
|
8597
8670
|
let Ee = j.summarization, De = j.agentCompression && !!p;
|
|
8598
8671
|
e.debug && j.agentCompression && !p && console.warn("[page-agent-sdk][agentCompression] agentCompression 开启但 summaryLlm 不可用(或缺 apiKey / 模型不支持工具),压缩决策不启用,回退静态压缩");
|
|
8599
|
-
let Oe = j.memory, ke = j.subagent, Ae = e.verify?.maxAttempts ?? 2,
|
|
8672
|
+
let Oe = j.memory, ke = j.subagent, Ae = ke ? bo() : void 0, je = e.verify?.maxAttempts ?? 2, Me = j.verify && e.verify?.enabled !== !1 && je > 0, Ne = j.contextInspector;
|
|
8600
8673
|
e.verify?.check && !j.verify && console.warn("[page-agent-sdk][verify] 检测到 verify.check 但 capabilities.verify 未开启,verify 未装载");
|
|
8601
|
-
let
|
|
8602
|
-
llm:
|
|
8674
|
+
let Pe = e.subagent, Fe = Pe?.allowedTools ?? [], Ie = !ke || Pe?.enabled === !1 ? void 0 : Mo({
|
|
8675
|
+
llm: Pe?.llm ?? e.llm,
|
|
8603
8676
|
allTools: () => B,
|
|
8604
|
-
allowedTools:
|
|
8605
|
-
systemPrompt:
|
|
8606
|
-
temperature:
|
|
8607
|
-
maxTokens:
|
|
8608
|
-
skills:
|
|
8609
|
-
maxDepth:
|
|
8610
|
-
maxParallel:
|
|
8677
|
+
allowedTools: Fe.length ? Fe : void 0,
|
|
8678
|
+
systemPrompt: Pe?.systemPrompt,
|
|
8679
|
+
temperature: Pe?.temperature,
|
|
8680
|
+
maxTokens: Pe?.maxTokens,
|
|
8681
|
+
skills: Pe?.skills,
|
|
8682
|
+
maxDepth: Pe?.maxDepth,
|
|
8683
|
+
maxParallel: Pe?.maxParallel,
|
|
8611
8684
|
debug: e.debug,
|
|
8612
8685
|
getFocuses: () => w.getFocuses(),
|
|
8613
|
-
getSchema: () => F()?.schema ?? null
|
|
8614
|
-
|
|
8686
|
+
getSchema: () => F()?.schema ?? null,
|
|
8687
|
+
tracker: Ae
|
|
8688
|
+
}), Le = ke && e.subagents !== void 0 ? Fo(e.subagents, {
|
|
8615
8689
|
llm: e.llm,
|
|
8616
8690
|
allTools: () => B,
|
|
8617
8691
|
debug: e.debug,
|
|
8618
8692
|
getFocuses: () => w.getFocuses(),
|
|
8619
|
-
getSchema: () => F()?.schema ?? null
|
|
8620
|
-
|
|
8693
|
+
getSchema: () => F()?.schema ?? null,
|
|
8694
|
+
tracker: Ae
|
|
8695
|
+
}) : void 0, Re = Le ? Le.controller : null, V = [
|
|
8621
8696
|
"get_data",
|
|
8622
8697
|
"describe_data",
|
|
8623
8698
|
"read",
|
|
8624
8699
|
"fetch_document"
|
|
8625
|
-
],
|
|
8626
|
-
check: e.verify.check ??
|
|
8700
|
+
], ze = B.filter((e) => V.includes(e.name)), Be = Me ? Io({
|
|
8701
|
+
check: e.verify.check ?? Ho({
|
|
8627
8702
|
schemas: () => F() ? { "": F().schema } : {},
|
|
8628
8703
|
root: () => F()?.bind
|
|
8629
8704
|
}),
|
|
8630
8705
|
adversarial: e.verify?.adversarial ? {
|
|
8631
8706
|
llm: e.llm,
|
|
8632
|
-
tools:
|
|
8707
|
+
tools: ze
|
|
8633
8708
|
} : void 0
|
|
8634
|
-
}) : void 0,
|
|
8709
|
+
}) : void 0, Ve = Ne ? ns({
|
|
8635
8710
|
contextWindow: m.contextWindow,
|
|
8636
|
-
thresholdRatio:
|
|
8637
|
-
}) : void 0,
|
|
8711
|
+
thresholdRatio: ic(e, m.contextWindow).summaryThresholdRatio
|
|
8712
|
+
}) : void 0, He = Wl({
|
|
8638
8713
|
...j,
|
|
8639
8714
|
humanConfirm: de,
|
|
8640
8715
|
subagents: e.subagents?.map((e) => ({
|
|
@@ -8642,10 +8717,10 @@ function au(e, n) {
|
|
|
8642
8717
|
description: e.description,
|
|
8643
8718
|
temperature: e.temperature
|
|
8644
8719
|
}))
|
|
8645
|
-
}, ne && !!D, e.toolMode, !!D?.resources?.length),
|
|
8720
|
+
}, ne && !!D, e.toolMode, !!D?.resources?.length), Ue = D ? {
|
|
8646
8721
|
name: "dataHint",
|
|
8647
|
-
augmentPrompt: () =>
|
|
8648
|
-
} : null,
|
|
8722
|
+
augmentPrompt: () => cs(F(), e.schemaHint) || void 0
|
|
8723
|
+
} : null, We = e.augmentSystem ? {
|
|
8649
8724
|
name: "augmentSystem",
|
|
8650
8725
|
augmentPrompt: (t) => {
|
|
8651
8726
|
try {
|
|
@@ -8658,7 +8733,7 @@ function au(e, n) {
|
|
|
8658
8733
|
return;
|
|
8659
8734
|
}
|
|
8660
8735
|
}
|
|
8661
|
-
} : null,
|
|
8736
|
+
} : null, Ge = tc(e.onEvent), H = Ge.emit, Ke, U = [], qe = (e) => ({
|
|
8662
8737
|
name: e.name,
|
|
8663
8738
|
description: e.description,
|
|
8664
8739
|
content: typeof e.getContent == "function" ? e.getContent() : ""
|
|
@@ -8666,7 +8741,7 @@ function au(e, n) {
|
|
|
8666
8741
|
name: e.name,
|
|
8667
8742
|
description: e.description,
|
|
8668
8743
|
getContent: () => e.content
|
|
8669
|
-
}), Ye = e.skillStorage === !1 ? null :
|
|
8744
|
+
}), Ye = e.skillStorage === !1 ? null : Xl({
|
|
8670
8745
|
...typeof e.skillStorage == "object" ? e.skillStorage : {},
|
|
8671
8746
|
id: e.skillStorage && typeof e.skillStorage == "object" && e.skillStorage.id ? e.skillStorage.id : `agent::${n}`
|
|
8672
8747
|
}), Xe = () => {
|
|
@@ -8696,11 +8771,11 @@ function au(e, n) {
|
|
|
8696
8771
|
preserveLastToolResults: _,
|
|
8697
8772
|
...De ? {
|
|
8698
8773
|
decideInvoke: p,
|
|
8699
|
-
getSnapshot: () =>
|
|
8774
|
+
getSnapshot: () => Ve?.getSnapshot()
|
|
8700
8775
|
} : {}
|
|
8701
|
-
}) : void 0, $e =
|
|
8702
|
-
...
|
|
8703
|
-
|
|
8776
|
+
}) : void 0, $e = oc([
|
|
8777
|
+
...Ue ? [Ue] : [],
|
|
8778
|
+
He,
|
|
8704
8779
|
...Se ? [C] : [],
|
|
8705
8780
|
...xe ? [S] : [],
|
|
8706
8781
|
...we ? [Ke = Na(e.skills || [], {
|
|
@@ -8714,7 +8789,7 @@ function au(e, n) {
|
|
|
8714
8789
|
B = be(), W.agent && W.agent.setTools(B), W.infoTick.value++;
|
|
8715
8790
|
}
|
|
8716
8791
|
})] : [],
|
|
8717
|
-
...Te ? [
|
|
8792
|
+
...Te ? [Pc(x)] : [],
|
|
8718
8793
|
...Qe ? [Qe] : [],
|
|
8719
8794
|
...Ce ? [T] : [],
|
|
8720
8795
|
...R ? [w] : [],
|
|
@@ -8724,18 +8799,18 @@ function au(e, n) {
|
|
|
8724
8799
|
...k && te && A ? [$a(A)] : [],
|
|
8725
8800
|
...de ? [Ga()] : [],
|
|
8726
8801
|
...e.approval && (e.approval.tools !== void 0 || e.approval.confirm) ? [Va(e.approval)] : [],
|
|
8727
|
-
...ze ? [ze] : [],
|
|
8728
|
-
...Fe ? [Fe] : [],
|
|
8729
|
-
...Ie ? [Ie] : [],
|
|
8730
|
-
...Ue ? [Ue] : [],
|
|
8731
8802
|
...Be ? [Be] : [],
|
|
8803
|
+
...Ie ? [Ie] : [],
|
|
8804
|
+
...Le ? [Le] : [],
|
|
8805
|
+
...We ? [We] : [],
|
|
8806
|
+
...Ve ? [Ve] : [],
|
|
8732
8807
|
...e.middleware || [],
|
|
8733
|
-
...re ? [
|
|
8808
|
+
...re ? [Pl(i, {
|
|
8734
8809
|
tokenBudget: e.tokenBudget,
|
|
8735
8810
|
timeBudgetMs: e.timeBudgetMs
|
|
8736
8811
|
}, H)] : [],
|
|
8737
|
-
|
|
8738
|
-
]), et = e.maxMemoryRounds ??
|
|
8812
|
+
iu(H, b, F, i)
|
|
8813
|
+
]), et = e.maxMemoryRounds ?? tu, tt = /* @__PURE__ */ Ot([]);
|
|
8739
8814
|
async function nt() {
|
|
8740
8815
|
s && (tt.value = (await s.listSessions(n)).sort((e, t) => t.lastAccessed - e.lastAccessed));
|
|
8741
8816
|
}
|
|
@@ -8943,7 +9018,7 @@ function au(e, n) {
|
|
|
8943
9018
|
})), e.memory && s.save(n, W.sessionId, { memory: E.get() || (typeof e.memory == "string" ? e.memory : "") }), nt(), ct = void 0, lt = !1, r;
|
|
8944
9019
|
},
|
|
8945
9020
|
resetSession: () => {
|
|
8946
|
-
s && (W.sessionId =
|
|
9021
|
+
s && (W.sessionId = Es(), x.clear?.(), S.reset([]), e.memory || E.reset(""), C.reset(), T.reset(), w.reset(), A && A.importStack([]), W.agent && (W.agent.debugLogs.value = []), s.createSession(W.agentId, e.session?.title, W.sessionId), H({
|
|
8947
9022
|
type: "session_restored",
|
|
8948
9023
|
sessionId: W.sessionId,
|
|
8949
9024
|
rounds: 0
|
|
@@ -8951,10 +9026,10 @@ function au(e, n) {
|
|
|
8951
9026
|
},
|
|
8952
9027
|
stream: (e, t, n) => {
|
|
8953
9028
|
if (!W.agent) throw Error("page-agent-sdk: agent 尚未初始化完成,请先 await mount()");
|
|
8954
|
-
x?.setProtectedRefs?.(
|
|
8955
|
-
let r =
|
|
9029
|
+
x?.setProtectedRefs?.(Ql(e));
|
|
9030
|
+
let r = (e) => {
|
|
8956
9031
|
t?.(e), H(e);
|
|
8957
|
-
}
|
|
9032
|
+
};
|
|
8958
9033
|
if (n) {
|
|
8959
9034
|
let e = () => a.resolve("keep_external");
|
|
8960
9035
|
n.aborted ? e() : n.addEventListener("abort", e, { once: !0 });
|
|
@@ -8965,7 +9040,7 @@ function au(e, n) {
|
|
|
8965
9040
|
if (W.refCount--, W.refCount <= 0) {
|
|
8966
9041
|
s && (x.flush?.(), s.flush(), s.dispose()), Ye && Ye.dispose();
|
|
8967
9042
|
let e = W.mcpClosers.splice(0);
|
|
8968
|
-
e.length && Promise.allSettled(e.map((e) => e())),
|
|
9043
|
+
e.length && Promise.allSettled(e.map((e) => e())), nu.delete(n);
|
|
8969
9044
|
}
|
|
8970
9045
|
},
|
|
8971
9046
|
resolveConflict: a.resolve,
|
|
@@ -8985,20 +9060,20 @@ function au(e, n) {
|
|
|
8985
9060
|
},
|
|
8986
9061
|
setLlm(t) {
|
|
8987
9062
|
let n;
|
|
8988
|
-
if (
|
|
9063
|
+
if (hs(t)) n = t;
|
|
8989
9064
|
else {
|
|
8990
9065
|
let e = t;
|
|
8991
9066
|
if ((e.provider ?? "openai") === "anthropic") throw Error("[page-agent-sdk][setLlm] 切换到 Anthropic 需传 BaseChatModel 实例(动态 import 无法同步);请先 const { ChatAnthropic } = await import(\"@langchain/anthropic\") 构造实例后传入");
|
|
8992
9067
|
n = d(e);
|
|
8993
9068
|
}
|
|
8994
9069
|
typeof n.bindTools != "function" && e.debug && console.warn("[page-agent-sdk][setLlm] 新模型不支持 bindTools(tool calling 会失效)"), y = t;
|
|
8995
|
-
let r =
|
|
9070
|
+
let r = hs(t) ? void 0 : t;
|
|
8996
9071
|
if (m = ni({
|
|
8997
9072
|
model: r?.model ?? t.model ?? t.modelName,
|
|
8998
9073
|
contextWindow: e.contextWindow ?? r?.contextWindow,
|
|
8999
9074
|
maxOutputTokens: e.maxOutputTokens ?? r?.maxOutputTokens
|
|
9000
9075
|
}), m.contextWindow < 2e5) throw Error(`[page-agent-sdk][setLlm] 新模型上下文窗口 ${m.contextWindow} 小于最小支持 ${ti}(需 ≥200K 窗口模型)`);
|
|
9001
|
-
W.agent && (W.agent.setLlm(n), W.agent.setModelCaps?.(m)), Qe?.setContextWindow?.(m.contextWindow),
|
|
9076
|
+
W.agent && (W.agent.setLlm(n), W.agent.setModelCaps?.(m)), Qe?.setContextWindow?.(m.contextWindow), Ve?.setContextWindow?.(m.contextWindow), W.infoTick.value++, e.debug && console.log("[page-agent-sdk][setLlm] 重解析 modelCaps + 回灌:", m);
|
|
9002
9077
|
},
|
|
9003
9078
|
setMemory(e) {
|
|
9004
9079
|
E.reset(e), typeof e == "function" && E.refresh(), W.infoTick.value++;
|
|
@@ -9007,30 +9082,36 @@ function au(e, n) {
|
|
|
9007
9082
|
return E.refresh();
|
|
9008
9083
|
},
|
|
9009
9084
|
setSubagents(t) {
|
|
9010
|
-
if (!
|
|
9085
|
+
if (!Re) {
|
|
9011
9086
|
e.debug && console.warn("[page-agent-sdk][setSubagents] 未配 subagents:[] 或 capabilities.subagent 关闭,忽略");
|
|
9012
9087
|
return;
|
|
9013
9088
|
}
|
|
9014
|
-
|
|
9089
|
+
Re.set(t), W.infoTick.value++;
|
|
9015
9090
|
},
|
|
9016
9091
|
addSubagent(t) {
|
|
9017
|
-
if (!
|
|
9092
|
+
if (!Re) {
|
|
9018
9093
|
e.debug && console.warn("[page-agent-sdk][addSubagent] 未配 subagents:[] 或 capabilities.subagent 关闭,忽略");
|
|
9019
9094
|
return;
|
|
9020
9095
|
}
|
|
9021
|
-
|
|
9096
|
+
Re.add(t), W.infoTick.value++;
|
|
9022
9097
|
},
|
|
9023
9098
|
removeSubagent(t) {
|
|
9024
|
-
if (!
|
|
9025
|
-
let n =
|
|
9099
|
+
if (!Re) return e.debug && console.warn("[page-agent-sdk][removeSubagent] 未配 subagents:[] 或 capabilities.subagent 关闭,忽略"), !1;
|
|
9100
|
+
let n = Re.remove(t);
|
|
9026
9101
|
return n && W.infoTick.value++, n;
|
|
9027
9102
|
},
|
|
9103
|
+
getActiveSubagents() {
|
|
9104
|
+
return Ae?.getActive() ?? [];
|
|
9105
|
+
},
|
|
9106
|
+
get subagentHistory() {
|
|
9107
|
+
return Ae?.getHistory() ?? [];
|
|
9108
|
+
},
|
|
9028
9109
|
getInfo() {
|
|
9029
9110
|
return {
|
|
9030
9111
|
id: n,
|
|
9031
9112
|
sessionId: W.sessionId,
|
|
9032
|
-
model:
|
|
9033
|
-
systemPrompt: W.agent?.getEffectiveSystemPrompt?.() ?? P +
|
|
9113
|
+
model: hs(y) ? y.model ?? y.modelName : y.model,
|
|
9114
|
+
systemPrompt: W.agent?.getEffectiveSystemPrompt?.() ?? P + cs(F(), e.schemaHint),
|
|
9034
9115
|
tools: (W.agent?.allTools ?? B).map((e) => ({
|
|
9035
9116
|
name: e.name,
|
|
9036
9117
|
description: e.description,
|
|
@@ -9066,21 +9147,23 @@ function au(e, n) {
|
|
|
9066
9147
|
spans: W.agent.spans.value,
|
|
9067
9148
|
metrics: ai(W.agent.spans.value)
|
|
9068
9149
|
} : void 0,
|
|
9069
|
-
actions:
|
|
9150
|
+
actions: Ll(e.actions ?? {}),
|
|
9070
9151
|
subagent: {
|
|
9071
|
-
enabled: !!
|
|
9152
|
+
enabled: !!Ie,
|
|
9072
9153
|
maxDepth: e.subagent?.maxDepth ?? 1,
|
|
9073
9154
|
maxParallel: e.subagent?.maxParallel ?? 4,
|
|
9074
9155
|
allowedTools: e.subagent?.allowedTools ?? [],
|
|
9075
|
-
subagents:
|
|
9156
|
+
subagents: Re?.get() ?? [],
|
|
9157
|
+
active: Ae?.getActive() ?? [],
|
|
9158
|
+
history: Ae?.getHistory() ?? []
|
|
9076
9159
|
},
|
|
9077
9160
|
verify: {
|
|
9078
|
-
enabled: !!
|
|
9079
|
-
maxAttempts:
|
|
9080
|
-
adversarial:
|
|
9161
|
+
enabled: !!Be,
|
|
9162
|
+
maxAttempts: Me ? je : 0,
|
|
9163
|
+
adversarial: Me && !!e.verify?.adversarial
|
|
9081
9164
|
},
|
|
9082
9165
|
context: (() => {
|
|
9083
|
-
let e =
|
|
9166
|
+
let e = Ve?.getSnapshot();
|
|
9084
9167
|
if (e) {
|
|
9085
9168
|
let t = W.agent?.getState?.()?.lastCompression;
|
|
9086
9169
|
t && (e.compression = t);
|
|
@@ -9113,11 +9196,11 @@ function au(e, n) {
|
|
|
9113
9196
|
return R ? w.getFocuses() : [];
|
|
9114
9197
|
},
|
|
9115
9198
|
setFocus(t) {
|
|
9116
|
-
let n =
|
|
9199
|
+
let n = au(t, "setFocus", R, () => F()?.schema, e.debug);
|
|
9117
9200
|
return n.ok ? (w.setFocus(t), W.infoTick.value++, { ok: !0 }) : n;
|
|
9118
9201
|
},
|
|
9119
9202
|
addFocus(t) {
|
|
9120
|
-
let n =
|
|
9203
|
+
let n = au(t, "addFocus", R, () => F()?.schema, e.debug);
|
|
9121
9204
|
return n.ok ? w.getFocuses().length >= 8 ? (e.debug && console.warn("[page-agent-sdk][focus] addFocus 拒绝:焦点数已达上限 8(augmentPrompt 注入每焦点子树 schema,过多致 system prompt 超预算)"), {
|
|
9122
9205
|
ok: !1,
|
|
9123
9206
|
error: "焦点数上限 8(避免 system prompt 撑爆)"
|
|
@@ -9161,14 +9244,14 @@ function au(e, n) {
|
|
|
9161
9244
|
}
|
|
9162
9245
|
function at(e) {
|
|
9163
9246
|
let t = {};
|
|
9164
|
-
for (let n of
|
|
9247
|
+
for (let n of Ql(e)) {
|
|
9165
9248
|
let e = x.files[n];
|
|
9166
9249
|
e && (t[n] = e.content);
|
|
9167
9250
|
}
|
|
9168
9251
|
return t;
|
|
9169
9252
|
}
|
|
9170
9253
|
function ot() {
|
|
9171
|
-
let e =
|
|
9254
|
+
let e = $l(x.files, Ql(b));
|
|
9172
9255
|
for (let t of e) delete x.files[t];
|
|
9173
9256
|
}
|
|
9174
9257
|
function st() {
|
|
@@ -9216,7 +9299,7 @@ function au(e, n) {
|
|
|
9216
9299
|
s.save(n, W.sessionId, { focus: e.length ? e : null });
|
|
9217
9300
|
}
|
|
9218
9301
|
re && A && (s.save(n, W.sessionId, { checkpoints: A.exportStack() }), s.save(n, W.sessionId, { usage: i }));
|
|
9219
|
-
let a =
|
|
9302
|
+
let a = ms(b);
|
|
9220
9303
|
a && a !== ct && (ct = a, s.updateTitle(n, W.sessionId, a)), e.autoTitle !== !1 && u && !lt && b.some((e) => e.role === "user") && b.some((e) => e.role === "assistant") && (lt = !0, (async () => {
|
|
9221
9304
|
let e = await u(b);
|
|
9222
9305
|
e && (await s.updateTitle(n, W.sessionId, e), await nt());
|
|
@@ -9224,7 +9307,7 @@ function au(e, n) {
|
|
|
9224
9307
|
}
|
|
9225
9308
|
return W.initDone = (async () => {
|
|
9226
9309
|
if (await rt(), await it(), e.mcp?.length) {
|
|
9227
|
-
let t = await Promise.allSettled(e.mcp.map((e) =>
|
|
9310
|
+
let t = await Promise.allSettled(e.mcp.map((e) => os(e)));
|
|
9228
9311
|
W.mcpClosers = t.flatMap((e) => e.status === "fulfilled" ? [e.value.close] : []), W.mcpServers = [], t.forEach((t, n) => {
|
|
9229
9312
|
let r = e.mcp[n], i = r.name ?? r.url;
|
|
9230
9313
|
t.status === "fulfilled" ? (W.mcpServers.push({
|
|
@@ -9234,7 +9317,7 @@ function au(e, n) {
|
|
|
9234
9317
|
}), t.value.tools.forEach((e) => I.set(e.name, `mcp:${i}`)), ue.push(...t.value.tools)) : console.warn(`[page-agent-sdk][mcp] server ${i} 连接失败:`, t.reason);
|
|
9235
9318
|
}), B = be(), e.debug && console.log(`[page-agent-sdk][mcp] 注入 ${ue.length} 个工具,${W.mcpServers.length} 个 server`);
|
|
9236
9319
|
}
|
|
9237
|
-
let t =
|
|
9320
|
+
let t = hs(e.llm) ? e.llm : await f(e.llm);
|
|
9238
9321
|
W.agent = ji({
|
|
9239
9322
|
llm: t,
|
|
9240
9323
|
systemPrompt: P,
|
|
@@ -9245,7 +9328,7 @@ function au(e, n) {
|
|
|
9245
9328
|
maxParallelTools: e.maxParallelTools,
|
|
9246
9329
|
contextWindow: m.contextWindow,
|
|
9247
9330
|
maxOutputTokens: m.maxOutputTokens,
|
|
9248
|
-
maxVerifyAttempts:
|
|
9331
|
+
maxVerifyAttempts: Me ? je : 0,
|
|
9249
9332
|
onLlmChange: (e) => {
|
|
9250
9333
|
y = e;
|
|
9251
9334
|
},
|
|
@@ -9259,17 +9342,17 @@ function au(e, n) {
|
|
|
9259
9342
|
} catch {}
|
|
9260
9343
|
} : void 0,
|
|
9261
9344
|
debug: e.debug
|
|
9262
|
-
}), ee.current = W.agent,
|
|
9345
|
+
}), ee.current = W.agent, Le && Le.setReconfigureHook && Le.setReconfigureHook(() => {
|
|
9263
9346
|
W.agent && W.agent.setTools(be());
|
|
9264
9347
|
});
|
|
9265
9348
|
})(), W;
|
|
9266
9349
|
}
|
|
9267
|
-
function
|
|
9268
|
-
let n = e.id ??
|
|
9350
|
+
function su(e, t) {
|
|
9351
|
+
let n = e.id ?? Es();
|
|
9269
9352
|
e.id || console.warn(`[page-agent-sdk] 未传 options.id,已生成随机 id "${n}"。刷新后持久化数据无法恢复,请传稳定 id。`);
|
|
9270
|
-
let r = e.streaming ?? !0, i = e.ui ?? "default", a, o = e.shareContext ?
|
|
9271
|
-
o ? a = o : (a =
|
|
9272
|
-
let s = null, c =
|
|
9353
|
+
let r = e.streaming ?? !0, i = e.ui ?? "default", a, o = e.shareContext ? nu.get(n) : void 0;
|
|
9354
|
+
o ? a = o : (a = ou(e, n), e.shareContext && nu.set(n, a)), a.refCount++;
|
|
9355
|
+
let s = null, c = Qs(e), l = null, u = null;
|
|
9273
9356
|
async function d(n) {
|
|
9274
9357
|
if (await a.initDone, s) {
|
|
9275
9358
|
s.show();
|
|
@@ -9311,7 +9394,7 @@ function ou(e, t) {
|
|
|
9311
9394
|
function m() {
|
|
9312
9395
|
s?.show();
|
|
9313
9396
|
}
|
|
9314
|
-
let h =
|
|
9397
|
+
let h = eu();
|
|
9315
9398
|
return {
|
|
9316
9399
|
mount: d,
|
|
9317
9400
|
unmount: f,
|
|
@@ -9424,7 +9507,7 @@ function ou(e, t) {
|
|
|
9424
9507
|
},
|
|
9425
9508
|
vfsWrite: (e, t) => {
|
|
9426
9509
|
let n = typeof t == "string" ? t : JSON.stringify(t);
|
|
9427
|
-
a.vfsStore.files[
|
|
9510
|
+
a.vfsStore.files[kc(e)] = {
|
|
9428
9511
|
content: n,
|
|
9429
9512
|
updatedAt: Date.now()
|
|
9430
9513
|
};
|
|
@@ -9458,17 +9541,21 @@ function ou(e, t) {
|
|
|
9458
9541
|
refreshMemory: () => a.refreshMemory(),
|
|
9459
9542
|
setSubagents: (e) => a.setSubagents(e),
|
|
9460
9543
|
addSubagent: (e) => a.addSubagent(e),
|
|
9461
|
-
removeSubagent: (e) => a.removeSubagent(e)
|
|
9544
|
+
removeSubagent: (e) => a.removeSubagent(e),
|
|
9545
|
+
getActiveSubagents: () => a.getActiveSubagents(),
|
|
9546
|
+
get subagentHistory() {
|
|
9547
|
+
return a.subagentHistory;
|
|
9548
|
+
}
|
|
9462
9549
|
};
|
|
9463
9550
|
}
|
|
9464
9551
|
//#endregion
|
|
9465
9552
|
//#region src/core/sdk/ragSubagent.ts
|
|
9466
|
-
var
|
|
9553
|
+
var cu = "你是知识检索专家。可用工具:search_docs(语义检索)/ load_doc(按 source 加载)/ vfs_grep+vfs_read(搜预注入文档)/ fetch_document(公网 URL)。\n\n工作方式:\n1. 分析任务,拆出需查证的要点(如:需要哪些组件、各自的 props 约束、UI 规范要求);\n2. 多源检索:先 vfs_grep 搜预注入文档(快、静态)→ 不够用 search_docs 语义检索 → 需特定文档用 load_doc → 公网用 fetch_document;\n3. 检索结果不足时换关键词、扩大 topK、或换源重试;\n4. 综合成结构化、可执行结论(不堆原文,提炼成可直接用于决策/配置的信息);\n5. 标注关键信息来源(文档名/段落),便于溯源;检索不到明确说「未检索到」,不编造。\n\n你是只读检索角色,不要尝试修改任何数据。", lu = "# 知识检索策略(RAG)\n\n## 多源决策树\n- vfs_grep / vfs_read:搜集成方预注入 vfs 的文档(组件文档 / UI 规范)—— 快、静态,先查\n- search_docs:语义检索(retriever 向量库)—— 模糊匹配,关键词不确定 / 语义相似时用\n- load_doc:按 source 精确加载(已知文档 id / URL / key)—— 精确取特定文档\n- fetch_document:公网 URL —— 查公开资料\n\n## 综合规范\n- 多源交叉验证(关键结论优先 ≥2 源印证,或单一权威源)\n- 标注来源(文档名 / URL / 段落),便于溯源\n- 结构化、可执行结论(组件清单 + 各自 props 约束 + 适用场景),不堆原文\n- 未检索到明确说「未检索到」,不编造;建议替代方案(改关键词 / 建议写代码组件等)\n\n## 何时用何源\n- 静态文档(组件库文档 / UI 规范):vfs_grep\n- 语义相似(「瀑布流组件」「倒计时」「拼团」):search_docs\n- 已知文档 id / URL:load_doc\n- 公开 URL(设计规范网站 / 第三方文档):fetch_document", uu = {
|
|
9467
9554
|
name: "rag-search",
|
|
9468
9555
|
description: "多源知识检索策略:vfs 预注入文档 → 语义检索 → 指定文档加载 → 公网;综合结构化结论 + 溯源",
|
|
9469
|
-
getContent: () =>
|
|
9556
|
+
getContent: () => lu
|
|
9470
9557
|
};
|
|
9471
|
-
function
|
|
9558
|
+
function du(e, n, i) {
|
|
9472
9559
|
return r(async ({ query: e, topK: t }) => {
|
|
9473
9560
|
try {
|
|
9474
9561
|
let r = await n(e, { topK: t ?? i });
|
|
@@ -9485,7 +9572,7 @@ function uu(e, n, i) {
|
|
|
9485
9572
|
})
|
|
9486
9573
|
});
|
|
9487
9574
|
}
|
|
9488
|
-
function
|
|
9575
|
+
function fu(e, n) {
|
|
9489
9576
|
return r(async ({ source: e }) => {
|
|
9490
9577
|
try {
|
|
9491
9578
|
let t = await n(e), r = Array.isArray(t) ? t : [t];
|
|
@@ -9499,11 +9586,11 @@ function du(e, n) {
|
|
|
9499
9586
|
schema: t.object({ source: t.string().describe("文档标识(id/URL/key)") })
|
|
9500
9587
|
});
|
|
9501
9588
|
}
|
|
9502
|
-
function
|
|
9589
|
+
function pu(e) {
|
|
9503
9590
|
let { retriever: t, loader: n, useVfs: r = !0, id: i = "rag", description: a, topK: o = 5, searchToolName: s = "search_docs", loadToolName: c = "load_doc", maxToolRounds: l = 8, summarization: u, skills: d, extraTools: f } = e;
|
|
9504
9591
|
if (!t && !n && r === !1) throw Error("[page-agent-sdk][createRagSubagent] 至少配一种知识源:retriever / loader / useVfs(true)");
|
|
9505
9592
|
let p = [];
|
|
9506
|
-
t && p.push(
|
|
9593
|
+
t && p.push(du(s, t, o)), n && p.push(fu(c, n)), f && p.push(...f);
|
|
9507
9594
|
let m = r ? [
|
|
9508
9595
|
"vfs_grep",
|
|
9509
9596
|
"vfs_read",
|
|
@@ -9512,17 +9599,17 @@ function fu(e) {
|
|
|
9512
9599
|
return {
|
|
9513
9600
|
id: i,
|
|
9514
9601
|
description: a ?? "检索知识库(组件文档/UI 规范/业务规则),返回有依据的结构化结论。需要查阅文档才能回答或决定如何配置时委派",
|
|
9515
|
-
systemPrompt:
|
|
9602
|
+
systemPrompt: cu,
|
|
9516
9603
|
tools: p.length ? p : void 0,
|
|
9517
9604
|
allowedTools: m,
|
|
9518
|
-
skills: d ?? [
|
|
9605
|
+
skills: d ?? [uu],
|
|
9519
9606
|
maxToolRounds: l,
|
|
9520
9607
|
...u === void 0 ? {} : { summarization: u }
|
|
9521
9608
|
};
|
|
9522
9609
|
}
|
|
9523
9610
|
//#endregion
|
|
9524
9611
|
//#region src/core/sdk/htmlSubagent.ts
|
|
9525
|
-
function
|
|
9612
|
+
function mu(e) {
|
|
9526
9613
|
return `你是纯代码组件生成专家。可用工具:vfs_write / vfs_edit / vfs_rm(写/改/删代码到 vfs ${e}) / vfs_grep + vfs_read(读 vfs) / write + set(写 data 引用,writablePaths 限定) / read / write_todos + update_todo(规划)。
|
|
9527
9614
|
|
|
9528
9615
|
代码存储约定(重要):
|
|
@@ -9536,12 +9623,12 @@ function pu(e) {
|
|
|
9536
9623
|
3. 小段代码 vfs_write 整体写;大段用 vfs_edit 增量拼(避免单次输出超限);
|
|
9537
9624
|
4. 生成后 read(vfs 文件 + data 引用)确认结构正确;只写 writablePaths 内 data + ${e} 下 vfs。`;
|
|
9538
9625
|
}
|
|
9539
|
-
var
|
|
9626
|
+
var hu = "# 纯代码组件生成规范\n\n## 代码存储约定(重要)\n- 代码正文写 vfs:html/<name>.vue(如 html/hero.vue)\n- data 存引用:{ type:'custom', codeRef:'vfs://html/<name>.vue', name, props }\n- 改代码:vfs_edit 改 vfs 文件(data 的 codeRef 引用不变)\n\n## 何时写代码组件\n- 组件库无对应类型(高度定制交互 / 一次性特效 / 特殊布局)→ 写 custom 代码组件\n- 组件库已有(按钮 / 卡片 / 列表)→ 用现有组件配置,不重造\n\n## Vue SFC 规范\n- Vue 3 <template> + <script setup>(组合式)\n- props 用 defineProps;事件用 defineEmits\n- 只渲染 UI,不做副作用(不发请求 / 不读写 storage)\n\n## props 定义\n- 代码组件 defineProps 接受外部 data 传入(集成方渲染时按 data 的 props 字段传)\n\n## 组件库引用\n- 代码内可 import 组件库组件(如 <Button>);所用依赖以集成方渲染层已注入为准,不重复造\n\n## 安全底线(必须)\n- 禁 eval / new Function / Function 构造器\n- 禁访问 window 敏感属性(document.cookie / apiKey / token)\n- 不引入外部脚本 / CDN\n\n## 可访问性 + 语义化\n- 语义化标签(button / nav / section);图片 alt;交互可键盘聚焦\n- 颜色对比达标;不只用颜色传达信息", gu = {
|
|
9540
9627
|
name: "html-builder",
|
|
9541
9628
|
description: "纯代码组件(custom Vue SFC)生成规范:代码存 vfs+data 引用 / SFC 规范 / 安全底线 / props / 组件库引用 / 可访问性",
|
|
9542
|
-
getContent: () =>
|
|
9629
|
+
getContent: () => hu
|
|
9543
9630
|
};
|
|
9544
|
-
function
|
|
9631
|
+
function _u(e) {
|
|
9545
9632
|
let { writablePaths: t, codeVfsPrefix: n = "html/", id: r = "html", description: i, planning: a = !0, summarization: o = !0, maxToolRounds: s = 12, temperature: c = .4, skills: l, extraTools: u } = e;
|
|
9546
9633
|
if (!t?.length) throw Error("[page-agent-sdk][createHtmlSubagent] writablePaths 必填(代码组件 data 区,如 [\"components\"])");
|
|
9547
9634
|
let d = [];
|
|
@@ -9550,7 +9637,7 @@ function gu(e) {
|
|
|
9550
9637
|
return {
|
|
9551
9638
|
id: r,
|
|
9552
9639
|
description: i ?? "生成/修改纯代码组件(custom Vue SFC)。代码写 vfs,data 存引用;能规划(write_todos)+ 执行。需写代码组件或灵活定制时委派",
|
|
9553
|
-
systemPrompt:
|
|
9640
|
+
systemPrompt: mu(n),
|
|
9554
9641
|
writablePaths: t,
|
|
9555
9642
|
allowedTools: [
|
|
9556
9643
|
"vfs_write",
|
|
@@ -9562,14 +9649,14 @@ function gu(e) {
|
|
|
9562
9649
|
middleware: d.length ? d : void 0,
|
|
9563
9650
|
summarization: o === !1 ? void 0 : o,
|
|
9564
9651
|
temperature: c,
|
|
9565
|
-
skills: l ?? [
|
|
9652
|
+
skills: l ?? [gu],
|
|
9566
9653
|
maxToolRounds: s,
|
|
9567
9654
|
tools: f.length ? f : void 0
|
|
9568
9655
|
};
|
|
9569
9656
|
}
|
|
9570
9657
|
//#endregion
|
|
9571
9658
|
//#region src/core/utils/clipboard.ts
|
|
9572
|
-
async function
|
|
9659
|
+
async function vu(e) {
|
|
9573
9660
|
try {
|
|
9574
9661
|
let t = globalThis.navigator?.clipboard;
|
|
9575
9662
|
if (t && typeof t.writeText == "function") return await t.writeText(e), !0;
|
|
@@ -9587,7 +9674,7 @@ async function _u(e) {
|
|
|
9587
9674
|
}
|
|
9588
9675
|
//#endregion
|
|
9589
9676
|
//#region src/core/composables/useChat.ts
|
|
9590
|
-
function
|
|
9677
|
+
function yu(e = {}) {
|
|
9591
9678
|
let { fetchResponse: t, fetchStream: n, onPersist: r, onClear: i } = e, a = /* @__PURE__ */ _t({
|
|
9592
9679
|
messages: e.messages ?? [],
|
|
9593
9680
|
loading: !1,
|
|
@@ -9766,9 +9853,9 @@ function vu(e = {}) {
|
|
|
9766
9853
|
}
|
|
9767
9854
|
//#endregion
|
|
9768
9855
|
//#region src/core/composables/chatContext.ts
|
|
9769
|
-
var
|
|
9770
|
-
function
|
|
9771
|
-
let t =
|
|
9856
|
+
var bu = Symbol("chatContext");
|
|
9857
|
+
function xu(e = {}) {
|
|
9858
|
+
let t = yu({
|
|
9772
9859
|
fetchResponse: e.fetchResponse,
|
|
9773
9860
|
fetchStream: e.fetchStream,
|
|
9774
9861
|
messages: e.messages,
|
|
@@ -9787,7 +9874,7 @@ function bu(e = {}) {
|
|
|
9787
9874
|
}, h = /* @__PURE__ */ Ot({}), g = (e) => h.value[e] !== !1, _ = (e) => {
|
|
9788
9875
|
h.value[e] = !g(e);
|
|
9789
9876
|
}, v = /* @__PURE__ */ Ot(!1), y = (e) => {
|
|
9790
|
-
|
|
9877
|
+
vu(e).then((e) => {
|
|
9791
9878
|
e && (v.value = !0, setTimeout(() => {
|
|
9792
9879
|
v.value = !1;
|
|
9793
9880
|
}, 1500));
|
|
@@ -9855,15 +9942,15 @@ function bu(e = {}) {
|
|
|
9855
9942
|
}
|
|
9856
9943
|
};
|
|
9857
9944
|
}
|
|
9858
|
-
function
|
|
9859
|
-
let e = Fn(
|
|
9945
|
+
function Su() {
|
|
9946
|
+
let e = Fn(bu);
|
|
9860
9947
|
if (!e) throw Error("useChatContext 必须在 provide(chatContextKey) 的组件子树内调用");
|
|
9861
9948
|
return e;
|
|
9862
9949
|
}
|
|
9863
9950
|
//#endregion
|
|
9864
9951
|
//#region src/core/index.headless.ts
|
|
9865
|
-
function
|
|
9866
|
-
return
|
|
9952
|
+
function Cu(e) {
|
|
9953
|
+
return su(e);
|
|
9867
9954
|
}
|
|
9868
9955
|
//#endregion
|
|
9869
|
-
export {
|
|
9956
|
+
export { $s as CAPABILITIES, nc as CONTEXT_PRESETS, ps as CompressDecisionSchema, ss as DEFAULT_SYSTEM_PROMPT, Ha as HUMAN_CONFIRM_TOOL_NAME, ti as MIN_CONTEXT_WINDOW, lo as STOP_WORDS, sc as UNSAFE_KEYS, Ll as actionsToInspectInfo, Il as actionsToTools, Jr as agentError, ts as analyzeContext, _c as applyPatchToClone, vc as applyPatchToLive, qr as asAgentError, cs as buildDataPrompt, ls as buildSystemPrompt, bu as chatContextKey, gl as commitSetToBind, os as connectMcp, f as constructLlmFromConfig, d as constructOpenLlmSync, vu as copyText, ji as createAgent, Va as createApprovalMiddleware, xu as createChatContext, Cu as createChatSdk, Qa as createCheckpointManager, $a as createCheckpointMiddleware, Ts as createConflictManager, ns as createContextInspectorMiddleware, vl as createDataOps, _u as createHtmlSubagent, Ga as createHumanConfirmMiddleware, Wa as createHumanConfirmTool, Ks as createMemoryBackend, Pa as createMemoryMiddleware, u as createProxyLlm, pu as createRagSubagent, ba as createSandboxRunner, tc as createSdkEvents, eu as createSerialRunner, Xs as createSessionStore, Xl as createSkillStore, Mo as createSubagentMiddleware, bo as createSubagentTracker, Fo as createSubagentsMiddleware, Wl as createUsageHintsMiddleware, Io as createVerifyMiddleware, Tc as createVfs, Js as createWebStorageBackend, Ho as createWriteBackCheck, fc as deepClone, Bl as defineDataToolset, Sa as defineSkill, us as defineTool, dc as deleteByPath, ms as deriveTitle, Ui as describeSchemaNode, xi as detectGarbledToolCall, xc as diffObjects, wl as domToStructure, El as domTools, zl as domToolsStatic, fo as estimateMessageTokens, po as estimateRoundTokens, X as estimateTokens, m as extractReasoningDelta, ca as extractSchemaHint, rs as extractText, p as extractTextDelta, h as extractUsage, bl as fetchDocTools, Rl as fetchTools, hl as filterByToolMode, Wi as formatConstraints, Ur as formatZodIssues, Z as getByPath, Tl as getDomTool, kl as getEnvSummary, Fi as getSchemaAtPath, Mi as getSchemaTopKeys, ai as getTraceMetrics, $ as hashValue, mo as indexSummarize, Ml as inspectEnvTool, Nl as inspectTools, hs as isChatModel, fi as isContextLengthError, Ni as isPathAllowed, Rs as isQuotaError, cc as isUnsafePath, Wc as jpEval, Gr as jsonParseError, hc as limitDepth, pc as maybeParseValue, ii as offloadPassThroughChars, ri as offloadThresholdChars, ra as presets, Li as projectBySchema, Ii as projectBySchemaDeep, mc as projectFields, ho as recallRounds, Gi as renderSchemaHint, Ki as renderSchemaOverview, Ji as renderSchemaShallow, ec as resolveCapabilities, ic as resolveContextOptions, Qs as resolveDialogConfig, ws as resolveLlm, ni as resolveModelCaps, Zs as resolveStorage, bc as restoreInPlace, yc as restoreLive, Kr as routeError, xa as runHostScript, Jc as runSandboxedScript, lc as safeMerge, Ol as safeSerialize, Q as safeStringify, Kc as searchJson, Vl as selectBuiltinTools, uc as setByPath, go as shouldTriggerCompression, ia as systemPromptHelpers, uo as tokenize, Y as toolError, Pi as unwrapSchema, yu as useChat, Su as useChatContext, e as z, Wr as zodError };
|