page-agent-sdk 2.15.1 → 2.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13936,20 +13936,34 @@ function xg(e) {
13936
13936
  }
13937
13937
  function Sg(e, t) {
13938
13938
  let n = t.threshold ?? 6e3;
13939
- if (e.length <= n) return e;
13939
+ if (e.length <= n) return { content: e };
13940
13940
  if (t.vfsAvailable && t.files) {
13941
13941
  let n = `large_results/${t.toolName}-${xg(e)}.txt`, r = bg(n);
13942
- return t.files[r] = {
13942
+ t.files[r] = {
13943
13943
  content: e,
13944
13944
  updatedAt: Date.now()
13945
- }, [
13946
- e.slice(0, 1e3),
13947
- `…[结果过大(共 ${e.length} 字符),已转存到虚拟工作区:${n}]`,
13948
- `需要完整或局部数据时:用 vfs_read({ path: "${n}", offset, limit }) 分页回读,或 vfs_grep({ pattern, path: "${n}" }) 局部检索。`
13949
- ].join("\n");
13945
+ };
13946
+ let i = e.slice(0, 1e3), a = e.length, o = a > 1e4 ? `结果较大(共 ${a} 字符),建议分页读取:vfs_read({ path: "${n}", offset: 0, limit: 100 }) 起步,按需 offset += 100 续读,或 vfs_grep({ pattern, path: "${n}" }) 局部检索` : void 0;
13947
+ return {
13948
+ offloaded: !0,
13949
+ content: [
13950
+ i,
13951
+ `…[结果过大(共 ${a} 字符),已转存到虚拟工作区:${n}]`,
13952
+ `需要完整或局部数据时:用 vfs_read({ path: "${n}", offset, limit }) 分页回读,或 vfs_grep({ pattern, path: "${n}" }) 局部检索。`,
13953
+ ...o ? [o] : []
13954
+ ].join("\n"),
13955
+ path: n,
13956
+ totalChars: a,
13957
+ preview: i,
13958
+ suggestedReadPlan: o
13959
+ };
13950
13960
  }
13951
13961
  let r = t.passThroughChars ?? n;
13952
- return e.length <= r ? e : e.slice(0, r) + `\n…[结果过大(共 ${e.length} 字符),vfs 未启用无法外存,已截断,仅显示前 ${r} 字符。建议开启 vfs(capabilities.vfs 默认开启)以完整外存可回读]`;
13962
+ return e.length <= r ? { content: e } : {
13963
+ offloaded: !1,
13964
+ content: e.slice(0, r) + `\n…[结果过大(共 ${e.length} 字符),vfs 未启用无法外存,已截断,仅显示前 ${r} 字符。建议开启 vfs(capabilities.vfs 默认开启)以完整外存可回读]`,
13965
+ totalChars: e.length
13966
+ };
13953
13967
  }
13954
13968
  //#endregion
13955
13969
  //#region src/core/utils/pool.ts
@@ -14354,7 +14368,7 @@ function Wg(e) {
14354
14368
  toolName: e.name,
14355
14369
  threshold: E,
14356
14370
  passThroughChars: D
14357
- }), {
14371
+ }).content, {
14358
14372
  content: r,
14359
14373
  status: "done"
14360
14374
  };
@@ -16127,9 +16141,26 @@ var Gv = {
16127
16141
  recallTopK: 5,
16128
16142
  enableRecall: !0,
16129
16143
  enableLLMSummary: !0
16144
+ },
16145
+ complex: {
16146
+ summaryThresholdRatio: .7,
16147
+ windowRatio: .6,
16148
+ recallTopK: 5,
16149
+ enableRecall: !0,
16150
+ enableLLMSummary: !0
16130
16151
  }
16152
+ }, Kv = {
16153
+ auto: ["describe_data", "read"],
16154
+ conservative: ["describe_data"],
16155
+ aggressive: ["describe_data", "read"],
16156
+ complex: [
16157
+ "describe_data",
16158
+ "read",
16159
+ "query_data",
16160
+ "search_data"
16161
+ ]
16131
16162
  };
16132
- function Kv(e, t) {
16163
+ function qv(e, t) {
16133
16164
  let n = Gv[e.contextPreset ?? "auto"] ?? {}, r = e.contextOptions === !1 ? {} : e.contextOptions ?? {};
16134
16165
  return {
16135
16166
  ...n,
@@ -16147,7 +16178,7 @@ function $(e) {
16147
16178
  };
16148
16179
  return e.path !== void 0 && (t.path = e.path), e.hint && (t.hint = e.hint), e.details !== void 0 && (t.details = e.details), `ERROR: ${JSON.stringify(t)}`;
16149
16180
  }
16150
- function qv(e) {
16181
+ function Jv(e) {
16151
16182
  return e.slice(0, 10).map((e) => {
16152
16183
  let t = e, n = {
16153
16184
  path: (Array.isArray(t.path) ? t.path.join(".") : String(t.path ?? "")) || "(root)",
@@ -16156,16 +16187,16 @@ function qv(e) {
16156
16187
  return t.expected !== void 0 && (n.expected = t.expected), t.received !== void 0 && (n.received = t.received), t.code !== void 0 && (n.code = t.code), n;
16157
16188
  });
16158
16189
  }
16159
- function Jv(e, t) {
16190
+ function Yv(e, t) {
16160
16191
  return $({
16161
16192
  code: "SCHEMA_INVALID",
16162
16193
  path: e,
16163
16194
  message: `值不符合 "${e}" 的 schema(${t.length} 处问题)`,
16164
16195
  hint: `用 read({jsonPath:"${e}"}) 查看当前值,按 describe_data() 查看主数据 schema,修正后重试;改大对象优先用 write 的 patch 增量(只发改动部分)`,
16165
- details: qv(t)
16196
+ details: Jv(t)
16166
16197
  });
16167
16198
  }
16168
- function Yv(e, t, n) {
16199
+ function Xv(e, t, n) {
16169
16200
  let r = n?.message || String(n);
16170
16201
  return $({
16171
16202
  code: "JSON_PARSE",
@@ -16174,62 +16205,218 @@ function Yv(e, t, n) {
16174
16205
  hint: `检查引号/逗号/括号是否闭合;字符串值需双引号包裹(如 '"dark"' 表示字符串 dark,数字直接写如 5);预览前 80 字符:${t.slice(0, 80)}`
16175
16206
  });
16176
16207
  }
16177
- var Xv = .9;
16178
- function Zv(e, t = {}) {
16208
+ //#endregion
16209
+ //#region src/core/tools/jsonUtils.ts
16210
+ var Zv = /* @__PURE__ */ new Set([
16211
+ "__proto__",
16212
+ "constructor",
16213
+ "prototype"
16214
+ ]);
16215
+ function Qv(e) {
16216
+ return e.split(".").some((e) => Zv.has(e));
16217
+ }
16218
+ function $v(e, t) {
16219
+ if (!(!t || typeof t != "object" || Array.isArray(t))) for (let n of Object.keys(t)) Zv.has(n) || (e[n] = t[n]);
16220
+ }
16221
+ function ey(e, t) {
16222
+ if (!t) return e;
16223
+ if (Qv(t)) return;
16224
+ let n = t.split("."), r = e;
16225
+ for (let e of n) {
16226
+ if (r == null) return;
16227
+ r = r[e];
16228
+ }
16229
+ return r;
16230
+ }
16231
+ function ty(e, t, n) {
16232
+ if (!t || Qv(t)) return;
16233
+ let r = t.split("."), i = e;
16234
+ for (let e = 0; e < r.length - 1; e++) {
16235
+ let t = r[e];
16236
+ (i[t] == null || typeof i[t] != "object") && (i[t] = {}), i = i[t];
16237
+ }
16238
+ i[r[r.length - 1]] = n;
16239
+ }
16240
+ function ny(e, t) {
16241
+ if (!t || Qv(t)) return !1;
16242
+ let n = t.split("."), r = e;
16243
+ for (let e = 0; e < n.length - 1; e++) {
16244
+ if (r == null) return !1;
16245
+ r = r[n[e]];
16246
+ }
16247
+ let i = n[n.length - 1];
16248
+ return r == null || !(i in r) ? !1 : (Array.isArray(r) && /^\d+$/.test(i) ? r.splice(Number(i), 1) : delete r[i], !0);
16249
+ }
16250
+ function ry(e) {
16251
+ return e === void 0 ? void 0 : JSON.parse(JSON.stringify(e));
16252
+ }
16253
+ function iy(e) {
16254
+ if (typeof e != "string") return { parsed: e };
16255
+ let t = e.trim();
16256
+ if (!t) return { parsed: e };
16257
+ let n = t[0] === "{" || t[0] === "[";
16258
+ try {
16259
+ return { parsed: JSON.parse(t) };
16260
+ } catch (t) {
16261
+ return n ? { parseError: t } : { parsed: e };
16262
+ }
16263
+ }
16264
+ function ay(e, t) {
16265
+ if (typeof e != "object" || !e) return e;
16266
+ let n = new Set(t);
16267
+ if (Array.isArray(e)) return e.map((e) => ay(e, t));
16268
+ let r = {};
16269
+ for (let t of Object.keys(e)) n.has(t) && (r[t] = e[t]);
16270
+ return r;
16271
+ }
16272
+ function oy(e, t) {
16273
+ if (typeof e != "object" || !e) return e;
16274
+ if (t <= 0) return Array.isArray(e) ? `[...${e.length}]` : "{...}";
16275
+ if (Array.isArray(e)) return e.map((e) => oy(e, t - 1));
16276
+ let n = {};
16277
+ for (let r of Object.keys(e)) n[r] = oy(e[r], t - 1);
16278
+ return n;
16279
+ }
16280
+ function sy(e, t = Infinity) {
16281
+ let n = /* @__PURE__ */ new WeakSet(), r;
16282
+ try {
16283
+ r = JSON.stringify(e, (e, t) => {
16284
+ if (typeof t == "function") return "[Function]";
16285
+ if (typeof t == "bigint") return t.toString();
16286
+ if (typeof t == "object" && t) {
16287
+ if (typeof HTMLElement < "u" && t instanceof HTMLElement) return `[HTMLElement: <${t.tagName.toLowerCase()}>]`;
16288
+ if (typeof Node < "u" && t instanceof Node) return `[Node: type=${t.nodeType}]`;
16289
+ if (n.has(t)) return "[Circular]";
16290
+ n.add(t);
16291
+ }
16292
+ return t;
16293
+ }, 0);
16294
+ } catch (e) {
16295
+ r = `[无法序列化: ${e?.message || String(e)}]`;
16296
+ }
16297
+ return r.length > t && (r = r.slice(0, t) + `\n…[已截断,原长度 ${r.length}]`), r;
16298
+ }
16299
+ function cy(e) {
16300
+ let t = sy(e), n = 5381;
16301
+ for (let e = 0; e < t.length; e++) n = (n << 5) + n + t.charCodeAt(e) >>> 0;
16302
+ return n.toString(36);
16303
+ }
16304
+ function ly(e, t, n, r) {
16305
+ if (t === "set") return n ? (ty(e, n, r), null) : "set 操作需要 jsonPath(整体替换请用 set_data)";
16306
+ if (t === "remove") return n ? (ny(e, n), null) : "remove 操作需要 jsonPath";
16307
+ if (t === "merge") {
16308
+ let t = n ? ey(e, n) : e;
16309
+ return typeof t != "object" || !t || Array.isArray(t) ? `merge 目标${n ? `(${n})` : "(根)"}不是对象` : ($v(t, r), null);
16310
+ }
16311
+ let i = n ? ey(e, n) : e;
16312
+ return Array.isArray(i) ? (Array.isArray(r) ? i.push(...r) : i.push(r), null) : `append 目标${n ? `(${n})` : "(根)"}不是数组`;
16313
+ }
16314
+ function uy(e, t, n, r) {
16315
+ if (t === "set") ty(e, n, r);
16316
+ else if (t === "remove") ny(e, n);
16317
+ else if (t === "merge") $v(n ? ey(e, n) : e, r);
16318
+ else {
16319
+ let t = n ? ey(e, n) : e;
16320
+ Array.isArray(r) ? t.push(...r) : t.push(r);
16321
+ }
16322
+ }
16323
+ function dy(e, t) {
16324
+ typeof e == "object" && e && fy(e, t);
16325
+ }
16326
+ function fy(e, t) {
16327
+ if (Array.isArray(e)) {
16328
+ e.length = 0, Array.isArray(t) && e.push(...t);
16329
+ return;
16330
+ }
16331
+ let n = t && typeof t == "object" && !Array.isArray(t) ? t : {};
16332
+ for (let t of Object.keys(e)) t in n || delete e[t];
16333
+ for (let t of Object.keys(n)) e[t] = n[t];
16334
+ }
16335
+ var py = {
16336
+ largeResults: 4194304,
16337
+ drafts: 2097152,
16338
+ userFiles: 2097152
16339
+ }, my = [
16340
+ "largeResults",
16341
+ "drafts",
16342
+ "userFiles"
16343
+ ], hy = .9;
16344
+ function gy(e, t = {}) {
16179
16345
  let n = Object.create(null);
16180
- if (e) for (let [t, r] of Object.entries(e)) n[ey(t)] = {
16346
+ if (e) for (let [t, r] of Object.entries(e)) n[by(t)] = {
16181
16347
  content: r,
16182
- updatedAt: ny()
16348
+ updatedAt: Sy()
16349
+ };
16350
+ let { persist: r } = t, i = t.maxBytes ?? 8388608, a = {
16351
+ ...py,
16352
+ ...t.poolBytes ?? {}
16183
16353
  };
16184
- let { persist: r } = t, i = t.maxBytes ?? 4194304;
16185
- function a() {
16186
- if ($v(n) <= i) return;
16187
- let e = i * Xv, t = Object.entries(n).sort((e, t) => e[1].updatedAt - t[1].updatedAt);
16188
- for (let [r] of t) if (delete n[r], $v(n) <= e) break;
16189
- }
16190
- let o = null;
16191
- function s() {
16354
+ function o(e) {
16355
+ let t = by(e);
16356
+ return t.startsWith("large_results/") ? "largeResults" : t.startsWith("drafts/") ? "drafts" : "userFiles";
16357
+ }
16358
+ function s(e) {
16359
+ let t = 0;
16360
+ for (let [r, i] of Object.entries(n)) o(r) === e && (t += vy(i.content));
16361
+ return t;
16362
+ }
16363
+ function c() {
16364
+ for (let e of my) {
16365
+ let t = a[e];
16366
+ if (s(e) <= t) continue;
16367
+ let r = t * hy, i = Object.entries(n).filter(([t]) => o(t) === e).sort((e, t) => e[1].updatedAt - t[1].updatedAt);
16368
+ for (let [t] of i) if (delete n[t], s(e) <= r) break;
16369
+ }
16370
+ if (yy(n) > i) {
16371
+ let e = i * hy, t = Object.entries(n).sort((e, t) => e[1].updatedAt - t[1].updatedAt);
16372
+ for (let [r] of t) if (delete n[r], yy(n) <= e) break;
16373
+ }
16374
+ }
16375
+ let l = null;
16376
+ function u() {
16192
16377
  if (!r?.save) return;
16193
16378
  let e = {};
16194
16379
  for (let [t, r] of Object.entries(n)) e[t] = { ...r };
16195
16380
  r.save(e);
16196
16381
  }
16197
- function c() {
16198
- r?.save && (o && clearTimeout(o), o = setTimeout(() => {
16199
- o = null, s();
16382
+ function d() {
16383
+ r?.save && (l && clearTimeout(l), l = setTimeout(() => {
16384
+ l = null, u();
16200
16385
  }, 800));
16201
16386
  }
16202
- let l = { files: new Proxy(n, {
16387
+ let f = { files: new Proxy(n, {
16203
16388
  set(e, t, n) {
16204
16389
  let r = Reflect.set(e, t, n);
16205
- return r && (a(), c()), r;
16390
+ return r && (c(), d()), r;
16206
16391
  },
16207
16392
  deleteProperty(e, t) {
16208
16393
  let n = Reflect.deleteProperty(e, t);
16209
- return n && c(), n;
16394
+ return n && d(), n;
16210
16395
  }
16211
16396
  }) };
16212
- return r && (l.hydrate = (e) => {
16213
- for (let [t, r] of Object.entries(e)) n[ey(t)] = r;
16214
- a();
16215
- }, l.flush = () => {
16216
- o &&= (clearTimeout(o), null), s();
16217
- }, l.clear = () => {
16218
- for (let e of Object.keys(n)) delete n[e];
16397
+ return r && (f.hydrate = (e) => {
16398
+ for (let [t, r] of Object.entries(e)) n[by(t)] = r;
16219
16399
  c();
16220
- }), l;
16400
+ }, f.flush = () => {
16401
+ l &&= (clearTimeout(l), null), u();
16402
+ }, f.clear = () => {
16403
+ for (let e of Object.keys(n)) delete n[e];
16404
+ d();
16405
+ }), f;
16221
16406
  }
16222
- var Qv = null;
16223
- function $v(e) {
16224
- Qv ||= new TextEncoder();
16407
+ var _y = null;
16408
+ function vy(e) {
16409
+ return _y ||= new TextEncoder(), _y.encode(e).length;
16410
+ }
16411
+ function yy(e) {
16225
16412
  let t = 0;
16226
- for (let n of Object.values(e)) t += Qv.encode(n.content).length;
16413
+ for (let n of Object.values(e)) t += vy(n.content);
16227
16414
  return t;
16228
16415
  }
16229
- function ey(e) {
16416
+ function by(e) {
16230
16417
  return e.replace(/^\/+/, "").replace(/\/+/g, "/");
16231
16418
  }
16232
- function ty(e) {
16419
+ function xy(e) {
16233
16420
  let t = "";
16234
16421
  for (let n = 0; n < e.length; n++) {
16235
16422
  let r = e[n];
@@ -16237,13 +16424,23 @@ function ty(e) {
16237
16424
  }
16238
16425
  return RegExp("^" + t + "$");
16239
16426
  }
16240
- function ny() {
16427
+ function Sy() {
16241
16428
  return Date.now();
16242
16429
  }
16243
- function ry(e) {
16430
+ var Cy = [
16431
+ "vfs_read",
16432
+ "vfs_write",
16433
+ "vfs_edit",
16434
+ "vfs_ls",
16435
+ "vfs_glob",
16436
+ "vfs_grep",
16437
+ "vfs_json_read",
16438
+ "vfs_json_patch"
16439
+ ];
16440
+ function wy(e) {
16244
16441
  return [
16245
16442
  r(async ({ path: t, offset: n, limit: r }) => {
16246
- let i = e.files[ey(t)];
16443
+ let i = e.files[by(t)];
16247
16444
  if (!i) return $({
16248
16445
  code: "NOT_FOUND",
16249
16446
  path: t,
@@ -16261,19 +16458,32 @@ function ry(e) {
16261
16458
  limit: t.number().int().min(1).default(2e3).describe("读取行数")
16262
16459
  })
16263
16460
  }),
16264
- r(async ({ path: t, content: n }) => (e.files[ey(t)] = {
16265
- content: n,
16266
- updatedAt: ny()
16267
- }, `已写入 ${t}(${n.length} 字符)`), {
16461
+ r(async ({ path: t, content: n, jsonString: r }) => {
16462
+ if (r) try {
16463
+ JSON.parse(n);
16464
+ } catch (e) {
16465
+ return $({
16466
+ code: "VFS_JSON_INVALID",
16467
+ path: t,
16468
+ message: `content 非合法 JSON: ${e.message}`,
16469
+ hint: "jsonString=true 要求 content 是合法 JSON;检查引号/逗号/括号配对;或省略 jsonString 写纯文本"
16470
+ });
16471
+ }
16472
+ return e.files[by(t)] = {
16473
+ content: n,
16474
+ updatedAt: Sy()
16475
+ }, `已写入 ${t}(${n.length} 字符)${r ? "(JSON 校验通过)" : ""}`;
16476
+ }, {
16268
16477
  name: "vfs_write",
16269
- description: "写入/覆盖虚拟工作区文件,作为中间工作记忆。",
16478
+ description: "写入/覆盖虚拟工作区文件,作为中间工作记忆。jsonString=true 时校验 content 是合法 JSON(配合 vfs_json_read/vfs_json_patch 操作 JSON 文件)。",
16270
16479
  schema: t.object({
16271
16480
  path: t.string().describe("文件路径"),
16272
- content: t.string().describe("完整内容")
16481
+ content: t.string().describe("完整内容"),
16482
+ jsonString: t.boolean().optional().describe("true 时校验 content 是合法 JSON(非法返回 VFS_JSON_INVALID 不写入);省略/false 写纯文本不校验")
16273
16483
  })
16274
16484
  }),
16275
16485
  r(async ({ path: t, oldString: n, newString: r }) => {
16276
- let i = ey(t), a = e.files[i];
16486
+ let i = by(t), a = e.files[i];
16277
16487
  if (!a) return $({
16278
16488
  code: "NOT_FOUND",
16279
16489
  path: t,
@@ -16303,7 +16513,7 @@ function ry(e) {
16303
16513
  }
16304
16514
  return e.files[i] = {
16305
16515
  content: a.content.replace(n, r),
16306
- updatedAt: ny()
16516
+ updatedAt: Sy()
16307
16517
  }, `已替换 ${t} 中 1 处。`;
16308
16518
  }, {
16309
16519
  name: "vfs_edit",
@@ -16325,7 +16535,7 @@ function ry(e) {
16325
16535
  r(async ({ pattern: t }) => {
16326
16536
  let n;
16327
16537
  try {
16328
- n = ty(t);
16538
+ n = xy(t);
16329
16539
  } catch (e) {
16330
16540
  return $({
16331
16541
  code: "GLOB_INVALID",
@@ -16354,7 +16564,7 @@ function ry(e) {
16354
16564
  details: { pattern: t }
16355
16565
  });
16356
16566
  }
16357
- let i = n ? [ey(n)] : Object.keys(e.files), a = [];
16567
+ let i = n ? [by(n)] : Object.keys(e.files), a = [];
16358
16568
  for (let t of i) {
16359
16569
  let n = e.files[t];
16360
16570
  n && n.content.split("\n").forEach((e, n) => {
@@ -16369,20 +16579,110 @@ function ry(e) {
16369
16579
  pattern: t.string().describe("正则表达式"),
16370
16580
  path: t.string().optional().describe("限定单个文件,不传则搜索全部")
16371
16581
  })
16582
+ }),
16583
+ r(async ({ path: t, jsonPath: n }) => {
16584
+ let r = by(t), i = e.files[r];
16585
+ if (!i) return $({
16586
+ code: "NOT_FOUND",
16587
+ path: t,
16588
+ message: `未找到文件 "${t}"`,
16589
+ hint: "用 vfs_ls 查看虚拟工作区文件列表"
16590
+ });
16591
+ let a;
16592
+ try {
16593
+ a = JSON.parse(i.content);
16594
+ } catch (e) {
16595
+ return $({
16596
+ code: "VFS_JSON_INVALID",
16597
+ path: t,
16598
+ message: `文件内容非合法 JSON: ${e.message}`,
16599
+ hint: "vfs_json_read 要求文件内容是合法 JSON;先 vfs_read 查看实际内容,或 vfs_write({jsonString:true}) 重写为合法 JSON"
16600
+ });
16601
+ }
16602
+ if (n) {
16603
+ let e = ey(a, n);
16604
+ return e === void 0 ? $({
16605
+ code: "VFS_PATH_NOT_FOUND",
16606
+ path: t,
16607
+ message: `jsonPath "${n}" 不存在`,
16608
+ hint: "不传 jsonPath 整体读查看结构,或核对路径段"
16609
+ }) : `${t}#${n} (JSON):\n${JSON.stringify(e)}`;
16610
+ }
16611
+ return `${t} (JSON):\n${JSON.stringify(a)}`;
16612
+ }, {
16613
+ name: "vfs_json_read",
16614
+ description: "把虚拟工作区文件当 JSON 读取:先 parse 整文件,再按 jsonPath 取子树(省略返整体)。文件非合法 JSON 报 VFS_JSON_INVALID。适合结构化读取 vfs 内大 JSON。",
16615
+ schema: t.object({
16616
+ path: t.string().describe("文件路径(内容须为合法 JSON)"),
16617
+ jsonPath: t.string().optional().describe("点分隔子路径(如 components.0.title);省略读整体")
16618
+ })
16619
+ }),
16620
+ r(async ({ path: t, patches: n }) => {
16621
+ let r = by(t), i = e.files[r];
16622
+ if (!i) return $({
16623
+ code: "NOT_FOUND",
16624
+ path: t,
16625
+ message: `未找到文件 "${t}"`,
16626
+ hint: "用 vfs_ls 查看虚拟工作区文件列表"
16627
+ });
16628
+ let a;
16629
+ try {
16630
+ a = JSON.parse(i.content);
16631
+ } catch (e) {
16632
+ return $({
16633
+ code: "VFS_JSON_INVALID",
16634
+ path: t,
16635
+ message: `文件内容非合法 JSON: ${e.message}`,
16636
+ hint: "vfs_json_patch 要求文件内容是合法 JSON"
16637
+ });
16638
+ }
16639
+ let o = ry(a), s = [];
16640
+ for (let e of n) {
16641
+ let n = ly(o, e.op, e.jsonPath, e.value);
16642
+ if (n) return $({
16643
+ code: "PATCH_FAILED",
16644
+ path: t,
16645
+ message: n,
16646
+ hint: "修正 patches 后重试(原文件未改动)",
16647
+ details: { failedPatch: e }
16648
+ });
16649
+ s.push(e.jsonPath || "(根)");
16650
+ }
16651
+ let c = JSON.stringify(o);
16652
+ return e.files[r] = {
16653
+ content: c,
16654
+ updatedAt: Sy()
16655
+ }, `已对 ${t} 应用 ${n.length} 个 patch(影响 ${s.length} 处:${s.join(", ")}),文件现 ${c.length} 字符`;
16656
+ }, {
16657
+ name: "vfs_json_patch",
16658
+ description: "在虚拟工作区 JSON 文件内做原子 jsonPath patch(set/remove/merge/append)。先 parse → clone 上应用全部 patches → 任一失败或 JSON 非法则整体不写回(原文件不变)。",
16659
+ schema: t.object({
16660
+ path: t.string().describe("文件路径(内容须为合法 JSON)"),
16661
+ patches: t.array(t.object({
16662
+ op: t.enum([
16663
+ "set",
16664
+ "remove",
16665
+ "merge",
16666
+ "append"
16667
+ ]).describe("操作"),
16668
+ jsonPath: t.string().describe("点分隔路径(如 components.0.title);merge/append 目标可为根(空串)"),
16669
+ value: t.any().optional().describe("set/merge/append 的值(remove 不需要)")
16670
+ })).describe("按顺序应用的 patch 列表(原子:任一失败整体不写回)")
16671
+ })
16372
16672
  })
16373
16673
  ];
16374
16674
  }
16375
- function iy(e) {
16675
+ function Ty(e) {
16376
16676
  return {
16377
16677
  name: "vfs",
16378
- tools: ry(e),
16678
+ tools: wy(e),
16379
16679
  beforeAgent: () => ({ files: e.files })
16380
16680
  };
16381
16681
  }
16382
16682
  //#endregion
16383
16683
  //#region src/core/tools/dataSlotQuery.ts
16384
- var ay = /[\w$-]/;
16385
- function oy(e) {
16684
+ var Ey = /[\w$-]/;
16685
+ function Dy(e) {
16386
16686
  let t = [], n = e.trim(), r = +(n[0] === "$");
16387
16687
  for (; r < n.length;) {
16388
16688
  let e = n[r];
@@ -16393,7 +16693,7 @@ function oy(e) {
16393
16693
  continue;
16394
16694
  }
16395
16695
  let e = "";
16396
- for (; r < n.length && ay.test(n[r]);) e += n[r++];
16696
+ for (; r < n.length && Ey.test(n[r]);) e += n[r++];
16397
16697
  if (!e) throw Error("JSONPath: .. 后缺属性名");
16398
16698
  t.push({
16399
16699
  type: "descendKey",
@@ -16406,7 +16706,7 @@ function oy(e) {
16406
16706
  continue;
16407
16707
  }
16408
16708
  let e = "";
16409
- for (; r < n.length && ay.test(n[r]);) e += n[r++];
16709
+ for (; r < n.length && Ey.test(n[r]);) e += n[r++];
16410
16710
  if (!e) throw Error("JSONPath: . 后缺属性名");
16411
16711
  t.push({
16412
16712
  type: "key",
@@ -16462,7 +16762,7 @@ function oy(e) {
16462
16762
  }
16463
16763
  return t;
16464
16764
  }
16465
- function sy(e) {
16765
+ function Oy(e) {
16466
16766
  let t = [], n = 0, r = e.trim();
16467
16767
  for (; n < r.length;) {
16468
16768
  let e = r[n];
@@ -16507,7 +16807,7 @@ function sy(e) {
16507
16807
  }
16508
16808
  return t;
16509
16809
  }
16510
- var cy = class {
16810
+ var ky = class {
16511
16811
  toks;
16512
16812
  item;
16513
16813
  pos = 0;
@@ -16543,12 +16843,12 @@ var cy = class {
16543
16843
  return this.next(), e;
16544
16844
  }
16545
16845
  let e = this.operand(), t = this.peek();
16546
- return t === "==" || t === "!=" || t === "<" || t === "<=" || t === ">" || t === ">=" ? (this.next(), dy(t, e, this.operand())) : ly(e);
16846
+ return t === "==" || t === "!=" || t === "<" || t === "<=" || t === ">" || t === ">=" ? (this.next(), My(t, e, this.operand())) : Ay(e);
16547
16847
  }
16548
16848
  operand() {
16549
16849
  let e = this.next();
16550
16850
  if (e === void 0) throw Error("过滤表达式:缺操作数");
16551
- if (e.startsWith("@")) return uy(e, this.item);
16851
+ if (e.startsWith("@")) return jy(e, this.item);
16552
16852
  if (e[0] === "'" || e[0] === "\"") return e.slice(1, -1);
16553
16853
  if (e === "true") return !0;
16554
16854
  if (e === "false") return !1;
@@ -16558,10 +16858,10 @@ var cy = class {
16558
16858
  throw Error(`过滤表达式:未知操作数 '${e}'`);
16559
16859
  }
16560
16860
  };
16561
- function ly(e) {
16861
+ function Ay(e) {
16562
16862
  return !!e && e !== 0 && e !== "" && e !== null;
16563
16863
  }
16564
- function uy(e, t) {
16864
+ function jy(e, t) {
16565
16865
  let n = e.split(".").filter((e) => e && e !== "@"), r = t;
16566
16866
  for (let e of n) {
16567
16867
  if (typeof r != "object" || !r) return;
@@ -16569,7 +16869,7 @@ function uy(e, t) {
16569
16869
  }
16570
16870
  return r;
16571
16871
  }
16572
- function dy(e, t, n) {
16872
+ function My(e, t, n) {
16573
16873
  switch (e) {
16574
16874
  case "==": return t === n;
16575
16875
  case "!=": return t !== n;
@@ -16580,47 +16880,47 @@ function dy(e, t, n) {
16580
16880
  default: return !1;
16581
16881
  }
16582
16882
  }
16583
- function fy(e, t) {
16584
- return new cy(sy(e), t).parse();
16883
+ function Ny(e, t) {
16884
+ return new ky(Oy(e), t).parse();
16585
16885
  }
16586
- function py(e, t) {
16886
+ function Py(e, t) {
16587
16887
  return e ? `${e}.${t}` : String(t);
16588
16888
  }
16589
- function my(e, t) {
16889
+ function Fy(e, t) {
16590
16890
  let n = [{
16591
16891
  path: "",
16592
16892
  value: e
16593
16893
  }];
16594
- for (let e of oy(t)) {
16894
+ for (let e of Dy(t)) {
16595
16895
  let t = [];
16596
16896
  if (e.type === "key") for (let r of n) r.value != null && typeof r.value == "object" && e.key in r.value && t.push({
16597
- path: py(r.path, e.key),
16897
+ path: Py(r.path, e.key),
16598
16898
  value: r.value[e.key]
16599
16899
  });
16600
16900
  else if (e.type === "index") {
16601
16901
  for (let r of n) if (Array.isArray(r.value)) {
16602
16902
  let n = r.value[e.index];
16603
16903
  e.index >= 0 && e.index < r.value.length && t.push({
16604
- path: py(r.path, e.index),
16904
+ path: Py(r.path, e.index),
16605
16905
  value: n,
16606
16906
  index: e.index
16607
16907
  });
16608
16908
  }
16609
16909
  } else if (e.type === "wildcard") {
16610
16910
  for (let e of n) if (Array.isArray(e.value)) e.value.forEach((n, r) => t.push({
16611
- path: py(e.path, r),
16911
+ path: Py(e.path, r),
16612
16912
  value: n,
16613
16913
  index: r
16614
16914
  }));
16615
16915
  else if (e.value != null && typeof e.value == "object") for (let n of Object.keys(e.value)) t.push({
16616
- path: py(e.path, n),
16916
+ path: Py(e.path, n),
16617
16917
  value: e.value[n]
16618
16918
  });
16619
16919
  } else if (e.type === "descendKey") {
16620
16920
  let r = e.key, i = (e) => {
16621
16921
  if (e.value != null && typeof e.value == "object") for (let n of Object.keys(e.value)) {
16622
16922
  let a = {
16623
- path: py(e.path, n),
16923
+ path: Py(e.path, n),
16624
16924
  value: e.value[n]
16625
16925
  };
16626
16926
  n === r && t.push(a), i(a);
@@ -16631,7 +16931,7 @@ function my(e, t) {
16631
16931
  let e = (n) => {
16632
16932
  if (n.value != null && typeof n.value == "object") for (let r of Object.keys(n.value)) {
16633
16933
  let i = {
16634
- path: py(n.path, r),
16934
+ path: Py(n.path, r),
16635
16935
  value: n.value[r]
16636
16936
  };
16637
16937
  t.push(i), e(i);
@@ -16640,16 +16940,16 @@ function my(e, t) {
16640
16940
  for (let t of n) e(t);
16641
16941
  } else if (e.type === "filter") {
16642
16942
  for (let r of n) if (Array.isArray(r.value)) r.value.forEach((n, i) => {
16643
- fy(e.filter, n) && t.push({
16644
- path: py(r.path, i),
16943
+ Ny(e.filter, n) && t.push({
16944
+ path: Py(r.path, i),
16645
16945
  value: n,
16646
16946
  index: i
16647
16947
  });
16648
16948
  });
16649
16949
  else if (r.value != null && typeof r.value == "object") for (let n of Object.keys(r.value)) {
16650
16950
  let i = r.value[n];
16651
- fy(e.filter, i) && t.push({
16652
- path: py(r.path, n),
16951
+ Ny(e.filter, i) && t.push({
16952
+ path: Py(r.path, n),
16653
16953
  value: i
16654
16954
  });
16655
16955
  }
@@ -16658,7 +16958,7 @@ function my(e, t) {
16658
16958
  }
16659
16959
  return n;
16660
16960
  }
16661
- function hy(e, t) {
16961
+ function Iy(e, t) {
16662
16962
  let n = e.length, r = t.length;
16663
16963
  if (!n) return r;
16664
16964
  if (!r) return n;
@@ -16674,7 +16974,7 @@ function hy(e, t) {
16674
16974
  }
16675
16975
  return i[r];
16676
16976
  }
16677
- function gy(e, t, n = {}) {
16977
+ function Ly(e, t, n = {}) {
16678
16978
  let r = n.mode || "substring", i = n.limit ?? 50, a = n.matchKey !== !1, o = [], s = null;
16679
16979
  if (r === "regex") try {
16680
16980
  s = new RegExp(t, "i");
@@ -16684,11 +16984,11 @@ function gy(e, t, n = {}) {
16684
16984
  let c = (e, l, u) => {
16685
16985
  if (o.length >= i || e == null) return;
16686
16986
  if (typeof e == "object") {
16687
- if (Array.isArray(e)) e.forEach((e, t) => c(e, py(l, t), String(t)));
16688
- else for (let t of Object.keys(e)) c(e[t], py(l, t), t);
16987
+ if (Array.isArray(e)) e.forEach((e, t) => c(e, Py(l, t), String(t)));
16988
+ else for (let t of Object.keys(e)) c(e[t], Py(l, t), t);
16689
16989
  return;
16690
16990
  }
16691
- let d = String(e), f = _y(d, t, r, n.fuzzyThreshold ?? 2, s);
16991
+ let d = String(e), f = Ry(d, t, r, n.fuzzyThreshold ?? 2, s);
16692
16992
  if (f) {
16693
16993
  o.push({
16694
16994
  path: l,
@@ -16699,7 +16999,7 @@ function gy(e, t, n = {}) {
16699
16999
  return;
16700
17000
  }
16701
17001
  if (a && u) {
16702
- let e = _y(u, t, r, n.fuzzyThreshold ?? 2, s);
17002
+ let e = Ry(u, t, r, n.fuzzyThreshold ?? 2, s);
16703
17003
  e && o.push({
16704
17004
  path: l,
16705
17005
  key: u,
@@ -16710,18 +17010,18 @@ function gy(e, t, n = {}) {
16710
17010
  };
16711
17011
  return c(e, ""), o;
16712
17012
  }
16713
- function _y(e, t, n, r, i) {
17013
+ function Ry(e, t, n, r, i) {
16714
17014
  let a = e.toLowerCase(), o = t.toLowerCase();
16715
17015
  if (n === "substring") return a.includes(o) ? 1 : null;
16716
17016
  if (n === "regex") return i && i.test(e) ? 1 : null;
16717
17017
  if (n === "fuzzy") {
16718
17018
  if (a.includes(o)) return 2;
16719
- let e = hy(a, o);
17019
+ let e = Iy(a, o);
16720
17020
  return e <= r ? r - e + 1 : null;
16721
17021
  }
16722
17022
  return null;
16723
17023
  }
16724
- var vy = [
17024
+ var zy = [
16725
17025
  "self.fetch = () => { throw new Error('fetch 已被沙箱禁用') }",
16726
17026
  "self.XMLHttpRequest = function(){ throw new Error('XMLHttpRequest 已被沙箱禁用') }",
16727
17027
  "self.importScripts = () => { throw new Error('importScripts 已被沙箱禁用') }",
@@ -16734,7 +17034,7 @@ var vy = [
16734
17034
  "try { self.BroadcastChannel = undefined } catch {}",
16735
17035
  "if (self.navigator && self.navigator.sendBeacon) self.navigator.sendBeacon = () => { throw new Error('sendBeacon 已被沙箱禁用') }"
16736
17036
  ].join("\n");
16737
- function yy(e, t, n = 3e3) {
17037
+ function By(e, t, n = 3e3) {
16738
17038
  return new Promise((r) => {
16739
17039
  let i = Date.now(), a = !1, o = (e) => {
16740
17040
  if (!a) {
@@ -16747,7 +17047,7 @@ function yy(e, t, n = 3e3) {
16747
17047
  elapsedMs: Date.now() - i
16748
17048
  });
16749
17049
  }
16750
- }, s = vy + "\nself.onmessage = async (e) => {\n try {\n const fn = new Function(\"data\", e.data.script);\n let result = fn(e.data.data);\n if (result && typeof result.then === \"function\") result = await result;\n self.postMessage({ ok: true, result });\n } catch (err) {\n self.postMessage({ ok: false, error: String((err && err.message) || err) });\n }\n};", c, l;
17050
+ }, s = zy + "\nself.onmessage = async (e) => {\n try {\n const fn = new Function(\"data\", e.data.script);\n let result = fn(e.data.data);\n if (result && typeof result.then === \"function\") result = await result;\n self.postMessage({ ok: true, result });\n } catch (err) {\n self.postMessage({ ok: false, error: String((err && err.message) || err) });\n }\n};", c, l;
16751
17051
  try {
16752
17052
  let e = new Blob([s], { type: "application/javascript" });
16753
17053
  c = URL.createObjectURL(e), l = new Worker(c);
@@ -16781,135 +17081,8 @@ function yy(e, t, n = 3e3) {
16781
17081
  });
16782
17082
  }
16783
17083
  //#endregion
16784
- //#region src/core/tools/jsonUtils.ts
16785
- var by = /* @__PURE__ */ new Set([
16786
- "__proto__",
16787
- "constructor",
16788
- "prototype"
16789
- ]);
16790
- function xy(e) {
16791
- return e.split(".").some((e) => by.has(e));
16792
- }
16793
- function Sy(e, t) {
16794
- if (!(!t || typeof t != "object" || Array.isArray(t))) for (let n of Object.keys(t)) by.has(n) || (e[n] = t[n]);
16795
- }
16796
- function Cy(e, t) {
16797
- if (!t) return e;
16798
- if (xy(t)) return;
16799
- let n = t.split("."), r = e;
16800
- for (let e of n) {
16801
- if (r == null) return;
16802
- r = r[e];
16803
- }
16804
- return r;
16805
- }
16806
- function wy(e, t, n) {
16807
- if (!t || xy(t)) return;
16808
- let r = t.split("."), i = e;
16809
- for (let e = 0; e < r.length - 1; e++) {
16810
- let t = r[e];
16811
- (i[t] == null || typeof i[t] != "object") && (i[t] = {}), i = i[t];
16812
- }
16813
- i[r[r.length - 1]] = n;
16814
- }
16815
- function Ty(e, t) {
16816
- if (!t || xy(t)) return !1;
16817
- let n = t.split("."), r = e;
16818
- for (let e = 0; e < n.length - 1; e++) {
16819
- if (r == null) return !1;
16820
- r = r[n[e]];
16821
- }
16822
- let i = n[n.length - 1];
16823
- return r == null || !(i in r) ? !1 : (Array.isArray(r) && /^\d+$/.test(i) ? r.splice(Number(i), 1) : delete r[i], !0);
16824
- }
16825
- function Ey(e) {
16826
- return e === void 0 ? void 0 : JSON.parse(JSON.stringify(e));
16827
- }
16828
- function Dy(e) {
16829
- if (typeof e != "string") return { parsed: e };
16830
- let t = e.trim();
16831
- if (!t) return { parsed: e };
16832
- let n = t[0] === "{" || t[0] === "[";
16833
- try {
16834
- return { parsed: JSON.parse(t) };
16835
- } catch (t) {
16836
- return n ? { parseError: t } : { parsed: e };
16837
- }
16838
- }
16839
- function Oy(e, t) {
16840
- if (typeof e != "object" || !e) return e;
16841
- let n = new Set(t);
16842
- if (Array.isArray(e)) return e.map((e) => Oy(e, t));
16843
- let r = {};
16844
- for (let t of Object.keys(e)) n.has(t) && (r[t] = e[t]);
16845
- return r;
16846
- }
16847
- function ky(e, t) {
16848
- if (typeof e != "object" || !e) return e;
16849
- if (t <= 0) return Array.isArray(e) ? `[...${e.length}]` : "{...}";
16850
- if (Array.isArray(e)) return e.map((e) => ky(e, t - 1));
16851
- let n = {};
16852
- for (let r of Object.keys(e)) n[r] = ky(e[r], t - 1);
16853
- return n;
16854
- }
16855
- function Ay(e, t = Infinity) {
16856
- let n = /* @__PURE__ */ new WeakSet(), r;
16857
- try {
16858
- r = JSON.stringify(e, (e, t) => {
16859
- if (typeof t == "function") return "[Function]";
16860
- if (typeof t == "bigint") return t.toString();
16861
- if (typeof t == "object" && t) {
16862
- if (typeof HTMLElement < "u" && t instanceof HTMLElement) return `[HTMLElement: <${t.tagName.toLowerCase()}>]`;
16863
- if (typeof Node < "u" && t instanceof Node) return `[Node: type=${t.nodeType}]`;
16864
- if (n.has(t)) return "[Circular]";
16865
- n.add(t);
16866
- }
16867
- return t;
16868
- }, 0);
16869
- } catch (e) {
16870
- r = `[无法序列化: ${e?.message || String(e)}]`;
16871
- }
16872
- return r.length > t && (r = r.slice(0, t) + `\n…[已截断,原长度 ${r.length}]`), r;
16873
- }
16874
- function jy(e) {
16875
- let t = Ay(e), n = 5381;
16876
- for (let e = 0; e < t.length; e++) n = (n << 5) + n + t.charCodeAt(e) >>> 0;
16877
- return n.toString(36);
16878
- }
16879
- function My(e, t, n, r) {
16880
- if (t === "set") return n ? (wy(e, n, r), null) : "set 操作需要 jsonPath(整体替换请用 set_data)";
16881
- if (t === "remove") return n ? (Ty(e, n), null) : "remove 操作需要 jsonPath";
16882
- if (t === "merge") {
16883
- let t = n ? Cy(e, n) : e;
16884
- return typeof t != "object" || !t || Array.isArray(t) ? `merge 目标${n ? `(${n})` : "(根)"}不是对象` : (Sy(t, r), null);
16885
- }
16886
- let i = n ? Cy(e, n) : e;
16887
- return Array.isArray(i) ? (Array.isArray(r) ? i.push(...r) : i.push(r), null) : `append 目标${n ? `(${n})` : "(根)"}不是数组`;
16888
- }
16889
- function Ny(e, t, n, r) {
16890
- if (t === "set") wy(e, n, r);
16891
- else if (t === "remove") Ty(e, n);
16892
- else if (t === "merge") Sy(n ? Cy(e, n) : e, r);
16893
- else {
16894
- let t = n ? Cy(e, n) : e;
16895
- Array.isArray(r) ? t.push(...r) : t.push(r);
16896
- }
16897
- }
16898
- function Py(e, t) {
16899
- typeof e == "object" && e && Fy(e, t);
16900
- }
16901
- function Fy(e, t) {
16902
- if (Array.isArray(e)) {
16903
- e.length = 0, Array.isArray(t) && e.push(...t);
16904
- return;
16905
- }
16906
- let n = t && typeof t == "object" && !Array.isArray(t) ? t : {};
16907
- for (let t of Object.keys(e)) t in n || delete e[t];
16908
- for (let t of Object.keys(n)) e[t] = n[t];
16909
- }
16910
- //#endregion
16911
17084
  //#region src/core/tools/schemaUtils.ts
16912
- function Iy(e) {
17085
+ function Vy(e) {
16913
17086
  let t = e;
16914
17087
  for (let e = 0; e < 5 && t && t._def; e++) {
16915
17088
  if (t._def.innerType) {
@@ -16926,12 +17099,12 @@ function Iy(e) {
16926
17099
  return null;
16927
17100
  }
16928
17101
  }
16929
- function Ly(e, t, n) {
17102
+ function Hy(e, t, n) {
16930
17103
  if (!n || !e) return !0;
16931
- let r = Ry(t);
17104
+ let r = Uy(t);
16932
17105
  for (let t of e.split(".")) {
16933
17106
  if (!r) return !1;
16934
- if (r = Ry(r), r && r.shape && typeof r.shape == "object") {
17107
+ if (r = Uy(r), r && r.shape && typeof r.shape == "object") {
16935
17108
  let e = typeof r.shape == "function" ? r.shape() : r.shape;
16936
17109
  if (!(t in e)) return !1;
16937
17110
  r = e[t];
@@ -16940,7 +17113,7 @@ function Ly(e, t, n) {
16940
17113
  }
16941
17114
  return !0;
16942
17115
  }
16943
- function Ry(e) {
17116
+ function Uy(e) {
16944
17117
  let t = e;
16945
17118
  for (let e = 0; e < 8 && t && t._def; e++) {
16946
17119
  if (t._def.innerType) {
@@ -16959,35 +17132,35 @@ function Ry(e) {
16959
17132
  }
16960
17133
  return t;
16961
17134
  }
16962
- function zy(e, t) {
17135
+ function Wy(e, t) {
16963
17136
  if (!t) return e;
16964
- let n = Ry(e), r = t.split(".");
17137
+ let n = Uy(e), r = t.split(".");
16965
17138
  for (let e of r) {
16966
17139
  if (!n) return null;
16967
- if (n = Ry(n), n && n.shape && typeof n.shape == "object") n = (typeof n.shape == "function" ? n.shape() : n.shape)[e];
17140
+ if (n = Uy(n), n && n.shape && typeof n.shape == "object") n = (typeof n.shape == "function" ? n.shape() : n.shape)[e];
16968
17141
  else if (n && (n._def?.type || n.element)) n = n.element ?? n._def?.type;
16969
17142
  else return null;
16970
17143
  }
16971
17144
  return n ?? null;
16972
17145
  }
16973
- function By(e, t) {
17146
+ function Gy(e, t) {
16974
17147
  if (typeof e != "object" || !e || !t) return e;
16975
- let n = Ry(t);
17148
+ let n = Uy(t);
16976
17149
  if (!n || !n.shape) {
16977
17150
  if (Array.isArray(e) && (n?._def?.type || n?.element)) {
16978
17151
  let t = n.element ?? n._def?.type;
16979
- return e.map((e) => By(e, t));
17152
+ return e.map((e) => Gy(e, t));
16980
17153
  }
16981
17154
  return e;
16982
17155
  }
16983
17156
  let r = typeof n.shape == "function" ? n.shape() : n.shape, i = {};
16984
17157
  for (let t of Object.keys(e)) if (t in r) {
16985
17158
  let n = e[t];
16986
- i[t] = By(n, r[t]);
17159
+ i[t] = Gy(n, r[t]);
16987
17160
  }
16988
17161
  return i;
16989
17162
  }
16990
- function Vy(e, t) {
17163
+ function Ky(e, t) {
16991
17164
  if (!t || typeof e != "object" || !e || Array.isArray(e)) return e;
16992
17165
  let n = new Set(t), r = {};
16993
17166
  for (let t of Object.keys(e)) n.has(t) && (r[t] = e[t]);
@@ -16995,25 +17168,25 @@ function Vy(e, t) {
16995
17168
  }
16996
17169
  //#endregion
16997
17170
  //#region src/core/tools/dataOps.ts
16998
- var Hy = /* @__PURE__ */ new Set([
17171
+ var qy = /* @__PURE__ */ new Set([
16999
17172
  "describe_data",
17000
17173
  "get_data",
17001
17174
  "set_data",
17002
17175
  "edit_data",
17003
17176
  "delete_data"
17004
- ]), Uy = /* @__PURE__ */ new Set(["read", "write"]);
17005
- function Wy(e, t = "simple") {
17006
- return t === "advanced" ? e : t === "minimal" ? e.filter((e) => Uy.has(e.name)) : e.filter((e) => !Hy.has(e.name));
17177
+ ]), Jy = /* @__PURE__ */ new Set(["read", "write"]);
17178
+ function Yy(e, t = "simple") {
17179
+ return t === "advanced" ? e : t === "minimal" ? e.filter((e) => Jy.has(e.name)) : e.filter((e) => !qy.has(e.name));
17007
17180
  }
17008
- function Gy(e, n = {}) {
17009
- let i = e.schema, a = e.bind, o = e.description ?? "主数据对象", s = Iy(i), c = [], l = n.maxSnapshots ?? 20, u, d = n.autoLock !== !1, f = {
17181
+ function Xy(e, n = {}) {
17182
+ let i = e.schema, a = e.bind, o = e.description ?? "主数据对象", s = Vy(i), c = [], l = n.maxSnapshots ?? 20, u, d = n.autoLock !== !1, f = {
17010
17183
  get: () => ({
17011
17184
  schema: i,
17012
17185
  bind: a,
17013
17186
  description: o
17014
17187
  }),
17015
17188
  set: (e) => {
17016
- i = e.schema, a = e.bind, o = e.description ?? "主数据对象", s = Iy(i), c.length = 0, u = void 0;
17189
+ i = e.schema, a = e.bind, o = e.description ?? "主数据对象", s = Vy(i), c.length = 0, u = void 0;
17017
17190
  },
17018
17191
  update: (e) => {
17019
17192
  a = e, c.length = 0, u = void 0;
@@ -17022,7 +17195,7 @@ function Gy(e, n = {}) {
17022
17195
  n.onAudit?.(e);
17023
17196
  };
17024
17197
  function m(e, t) {
17025
- let n = Ey(a), r = c.length ? c[c.length - 1].id + 1 : 1;
17198
+ let n = ry(a), r = c.length ? c[c.length - 1].id + 1 : 1;
17026
17199
  for (c.push({
17027
17200
  id: r,
17028
17201
  ts: Date.now(),
@@ -17034,12 +17207,12 @@ function Gy(e, n = {}) {
17034
17207
  }
17035
17208
  async function h(e, t, r) {
17036
17209
  if (!t || t === "") return null;
17037
- let i = jy(a);
17210
+ let i = cy(a);
17038
17211
  if (i === t) return null;
17039
17212
  if (!n.onConflict) return $({
17040
17213
  code: "VERSION_CONFLICT",
17041
17214
  message: `乐观锁冲突:expectedHash=${t} 但当前 hash=${i}。主数据在你 read 之后已被修改(外部代码/其他 agent/用户手动改)。`,
17042
- hint: `重新 read 拿最新值与 hash,基于最新值修改后再写入(传新的 expectedHash)。当前值:${Ay(a, 400)}`
17215
+ hint: `重新 read 拿最新值与 hash,基于最新值修改后再写入(传新的 expectedHash)。当前值:${sy(a, 400)}`
17043
17216
  });
17044
17217
  let o = await n.onConflict({
17045
17218
  op: e,
@@ -17049,11 +17222,11 @@ function Gy(e, n = {}) {
17049
17222
  expectedHash: t,
17050
17223
  snapshotId: 0
17051
17224
  });
17052
- if (o.action === "keep_external") return `已保留外部修改(未写入)。当前值:${Ay(a, 400)} (hash=${i})。请重新 read 拿最新值与 hash 再改。`;
17225
+ if (o.action === "keep_external") return `已保留外部修改(未写入)。当前值:${sy(a, 400)} (hash=${i})。请重新 read 拿最新值与 hash 再改。`;
17053
17226
  if (o.action === "restore") {
17054
- if (!c.length) return `无历史快照可回退(本次为首次操作)。当前值:${Ay(a, 400)} (hash=${i})。请重新 read 再改或选「强制覆盖」。`;
17227
+ if (!c.length) return `无历史快照可回退(本次为首次操作)。当前值:${sy(a, 400)} (hash=${i})。请重新 read 再改或选「强制覆盖」。`;
17055
17228
  let e = c[c.length - 1];
17056
- return Py(a, Ey(e.value)), `已回退主数据到历史快照 #${e.id}[${e.op}]。当前值:${Ay(a, 400)} (hash=${jy(a)})。请基于回退后的值重写或停止。`;
17229
+ return dy(a, ry(e.value)), `已回退主数据到历史快照 #${e.id}[${e.op}]。当前值:${sy(a, 400)} (hash=${cy(a)})。请基于回退后的值重写或停止。`;
17057
17230
  }
17058
17231
  return null;
17059
17232
  }
@@ -17065,15 +17238,15 @@ function Gy(e, n = {}) {
17065
17238
  }),
17066
17239
  r(async ({ jsonPath: e }) => {
17067
17240
  let t = e || "";
17068
- if (!Ly(t, i, s)) return $({
17241
+ if (!Hy(t, i, s)) return $({
17069
17242
  code: "PATH_DENIED",
17070
17243
  message: `get_data @ "${t}" 不在 schema 声明字段内(仅 schema 声明的 key 可读)`,
17071
17244
  hint: "主数据仅暴露 schema 声明的字段;若需操作该字段,集成方需在 schema 中声明它"
17072
17245
  });
17073
- let n = t ? Cy(a, t) : a;
17074
- t || (n = Vy(n, s));
17075
- let r = jy(a);
17076
- return u = r, n === void 0 ? `主数据${t ? ` @ ${t}` : ""} = (undefined) (hash=${r})` : `主数据${t ? ` @ ${t}` : ""} = ${Ay(n)} (hash=${r})`;
17246
+ let n = t ? ey(a, t) : a;
17247
+ t || (n = Ky(n, s));
17248
+ let r = cy(a);
17249
+ return u = r, n === void 0 ? `主数据${t ? ` @ ${t}` : ""} = (undefined) (hash=${r})` : `主数据${t ? ` @ ${t}` : ""} = ${sy(n)} (hash=${r})`;
17077
17250
  }, {
17078
17251
  name: "get_data",
17079
17252
  description: "读取主数据的当前值(安全序列化:函数/DOM/循环引用做摘要;大结果由系统自动外存,提示用 vfs_read 回读)。返回含 hash(乐观锁):改前先 read/get 拿 hash,写入时传 expectedHash 回传,系统对比当前 hash 防\"基于过期值覆盖\"。jsonPath 可选:读整个主数据不传,读子路径传(如 components.0.text)。",
@@ -17082,19 +17255,19 @@ function Gy(e, n = {}) {
17082
17255
  r(async ({ value: e, expectedHash: t }) => {
17083
17256
  let n = await h("set", t || (d ? u : void 0));
17084
17257
  if (n !== null) return n;
17085
- let r, o = Dy(e);
17086
- if (o.parseError) return Yv("", e, o.parseError);
17258
+ let r, o = iy(e);
17259
+ if (o.parseError) return Xv("", e, o.parseError);
17087
17260
  r = o.parsed;
17088
17261
  let c = i.safeParse(r);
17089
17262
  return c.success ? typeof a != "object" || !a ? $({
17090
17263
  code: "LEAF_BIND",
17091
17264
  message: `主数据 bind 为原始类型(${a === null ? "null" : typeof a}),set_data 无法就地替换外部持有的值引用`,
17092
17265
  hint: "主数据 bind 必须为对象/数组(低代码主 JSON 本就是);叶子值请用对象包裹(如 {value:\"x\"})或集成方通过 sdk.setData 替换 bind"
17093
- }) : (m("set"), c.data !== null && typeof c.data == "object" && (s ? Sy(a, c.data) : Fy(a, c.data)), p({
17266
+ }) : (m("set"), c.data !== null && typeof c.data == "object" && (s ? $v(a, c.data) : fy(a, c.data)), p({
17094
17267
  op: "set",
17095
17268
  value: c.data,
17096
17269
  timestamp: Date.now()
17097
- }), u = jy(a), `已设置主数据 = ${Ay(c.data, 600)} (新 hash=${jy(a)})${s ? "(白名单模式:仅更新 schema 声明字段,未声明字段保留)" : ""}`) : Jv("", c.error.issues);
17270
+ }), u = cy(a), `已设置主数据 = ${sy(c.data, 600)} (新 hash=${cy(a)})${s ? "(白名单模式:仅更新 schema 声明字段,未声明字段保留)" : ""}`) : Yv("", c.error.issues);
17098
17271
  }, {
17099
17272
  name: "set_data",
17100
17273
  description: "设置主数据的值(整体替换)。value 为 JSON 对象(或 JSON 字符串),需通过 schema 校验。校验失败会返回错误而非写入。expectedHash(可选):改前 read/get 返回的 hash,传入则启用乐观锁;不传时系统自动用你最后一次读到的 hash 比对(autoLock,默认开)。大对象/数组强烈建议改用 edit_data 增量 patch。",
@@ -17105,12 +17278,12 @@ function Gy(e, n = {}) {
17105
17278
  }),
17106
17279
  r(async ({ op: e, jsonPath: t, value: n, expectedHash: r }) => {
17107
17280
  let o = t || "";
17108
- if (xy(o)) return $({
17281
+ if (Qv(o)) return $({
17109
17282
  code: "PATH_UNSAFE",
17110
17283
  message: `jsonPath "${o}" 含非法段(__proto__/constructor/prototype)`,
17111
17284
  hint: "使用正常的属性路径,如 components.0.text(数组索引用数字)"
17112
17285
  });
17113
- if (!Ly(o, i, s)) return $({
17286
+ if (!Hy(o, i, s)) return $({
17114
17287
  code: "PATH_DENIED",
17115
17288
  message: `edit_data @ "${o}" 不在 schema 声明字段内`,
17116
17289
  hint: "仅 schema 声明的 key 可写;若需操作该字段,集成方需在 schema 中声明它"
@@ -17129,23 +17302,23 @@ function Gy(e, n = {}) {
17129
17302
  message: `${e} 操作需要 value`,
17130
17303
  hint: `op 为 ${e} 时 value 必填;删除请用 op:'remove'`
17131
17304
  });
17132
- let t = Dy(n);
17133
- if (t.parseError) return Yv("", n, t.parseError);
17305
+ let t = iy(n);
17306
+ if (t.parseError) return Xv("", n, t.parseError);
17134
17307
  l = t.parsed;
17135
17308
  }
17136
- let f = Ey(a), g = My(f, e, o, l);
17309
+ let f = ry(a), g = ly(f, e, o, l);
17137
17310
  if (g) return $({
17138
17311
  code: "PATCH_FAILED",
17139
17312
  message: g,
17140
17313
  hint: "检查 op 与目标类型:merge 需对象,append 需数组;jsonPath 指向需存在"
17141
17314
  });
17142
17315
  let _ = i.safeParse(f);
17143
- return _.success ? (m("edit"), Ny(a, e, o, l), p({
17316
+ return _.success ? (m("edit"), uy(a, e, o, l), p({
17144
17317
  op: "edit",
17145
17318
  detail: `${e}${o ? "@" + o : ""}`,
17146
17319
  value: l,
17147
17320
  timestamp: Date.now()
17148
- }), u = jy(a), `已 edit 主数据(${e}${o ? " @ " + o : ""})。当前值:${Ay(a, 600)} (新 hash=${jy(a)})`) : Jv("", _.error.issues);
17321
+ }), u = cy(a), `已 edit 主数据(${e}${o ? " @ " + o : ""})。当前值:${sy(a, 600)} (新 hash=${cy(a)})`) : Yv("", _.error.issues);
17149
17322
  }, {
17150
17323
  name: "edit_data",
17151
17324
  description: "增量编辑主数据(对象/数组),只发改动的 patch,无需重传整个大对象。op:set(在 jsonPath 设值)、remove(删 jsonPath)、merge(把 value 合并到 jsonPath 指向的对象,默认根)、append(把 value 追加到 jsonPath 指向的数组,默认根)。jsonPath 为相对主数据根的点号路径(数组索引用数字,如 components.0.text);value 为 JSON 对象(推荐直传)或 JSON 字符串。整体仍经 schema 校验,失败不写入。expectedHash(可选):改前 read/get 返回的 hash;不传时自动用你最后读到的 hash(autoLock,默认开)防\"基于过期值覆盖\"。",
@@ -17167,12 +17340,12 @@ function Gy(e, n = {}) {
17167
17340
  message: "delete_data 需要 jsonPath 指定要删的子路径(主数据整体不可删,用 set_data 整体替换)",
17168
17341
  hint: "如 jsonPath:\"components.0\" 删数组首项"
17169
17342
  });
17170
- if (xy(e)) return $({
17343
+ if (Qv(e)) return $({
17171
17344
  code: "PATH_UNSAFE",
17172
17345
  message: `jsonPath "${e}" 含非法段`,
17173
17346
  hint: "使用正常属性路径"
17174
17347
  });
17175
- if (!Ly(e, i, s)) return $({
17348
+ if (!Hy(e, i, s)) return $({
17176
17349
  code: "PATH_DENIED",
17177
17350
  message: `delete_data @ "${e}" 不在 schema 声明字段内`,
17178
17351
  hint: "仅 schema 声明的 key 可删"
@@ -17180,12 +17353,12 @@ function Gy(e, n = {}) {
17180
17353
  let n = await h("delete", t || (d ? u : void 0));
17181
17354
  if (n !== null) return n;
17182
17355
  m("delete");
17183
- let r = Ty(a, e);
17356
+ let r = ny(a, e);
17184
17357
  return p({
17185
17358
  op: "delete",
17186
17359
  detail: e,
17187
17360
  timestamp: Date.now()
17188
- }), u = jy(a), r ? `已删除主数据 @ ${e}` : `主数据 @ ${e} 不存在(无需删除)`;
17361
+ }), u = cy(a), r ? `已删除主数据 @ ${e}` : `主数据 @ ${e} 不存在(无需删除)`;
17189
17362
  }, {
17190
17363
  name: "delete_data",
17191
17364
  description: "删除主数据的某个子路径(jsonPath)。主数据整体不可删(用 set_data 整体替换)。expectedHash(可选):改前 read/get 返回的 hash;不传时自动用你最后读到的 hash(autoLock,默认开)防\"基于过期值删除\"。",
@@ -17224,15 +17397,15 @@ function Gy(e, n = {}) {
17224
17397
  hint: "用 list_data_snapshots 查看可用快照序号"
17225
17398
  });
17226
17399
  let n = i.safeParse(t.value);
17227
- return n.success ? (Py(a, Ey(t.value)), p({
17400
+ return n.success ? (dy(a, ry(t.value)), p({
17228
17401
  op: "restore",
17229
17402
  detail: `#${t.id}`,
17230
17403
  timestamp: Date.now()
17231
- }), u = jy(a), `已回退主数据到快照 #${t.id}[${t.op}]${t.label ? `(${t.label})` : ""}。`) : $({
17404
+ }), u = cy(a), `已回退主数据到快照 #${t.id}[${t.op}]${t.label ? `(${t.label})` : ""}。`) : $({
17232
17405
  code: "SNAPSHOT_SCHEMA_INVALID",
17233
17406
  message: `快照 #${t.id} 的值不符合当前 schema,无法回退`,
17234
17407
  hint: "schema 可能已变更;该快照已过期,选其他快照或重新设置",
17235
- details: qv(n.error.issues)
17408
+ details: Jv(n.error.issues)
17236
17409
  });
17237
17410
  }, {
17238
17411
  name: "restore_data",
@@ -17245,9 +17418,9 @@ function Gy(e, n = {}) {
17245
17418
  message: `主数据不是对象/数组,无法查询(当前为 ${a === void 0 ? "undefined" : typeof a})`,
17246
17419
  hint: "query 仅适用于对象/数组;叶子用 get_data 读"
17247
17420
  });
17248
- let n = s ? Vy(a, s) : a, r;
17421
+ let n = s ? Ky(a, s) : a, r;
17249
17422
  try {
17250
- r = my(n, e);
17423
+ r = Fy(n, e);
17251
17424
  } catch (t) {
17252
17425
  return $({
17253
17426
  code: "JSONPATH_SYNTAX",
@@ -17256,7 +17429,7 @@ function Gy(e, n = {}) {
17256
17429
  details: { expr: e }
17257
17430
  });
17258
17431
  }
17259
- let i = t ?? 50, o = r.slice(0, i), c = o.map((e) => `{"path":${JSON.stringify(e.path)},"index":${e.index === void 0 ? "null" : e.index},"value":${Ay(e.value)}}`);
17432
+ let i = t ?? 50, o = r.slice(0, i), c = o.map((e) => `{"path":${JSON.stringify(e.path)},"index":${e.index === void 0 ? "null" : e.index},"value":${sy(e.value)}}`);
17260
17433
  return `{"matched":${r.length},"returned":${o.length},"truncated":${r.length > i},"results":[${c.join(",")}]}`;
17261
17434
  }, {
17262
17435
  name: "query_data",
@@ -17272,13 +17445,13 @@ function Gy(e, n = {}) {
17272
17445
  message: "主数据为空,无可搜索内容"
17273
17446
  });
17274
17447
  try {
17275
- let o = gy(s ? Vy(a, s) : a, e, {
17448
+ let o = Ly(s ? Ky(a, s) : a, e, {
17276
17449
  mode: t,
17277
17450
  fuzzyThreshold: n,
17278
17451
  matchKey: r,
17279
17452
  limit: i ?? 50
17280
17453
  });
17281
- return Ay({
17454
+ return sy({
17282
17455
  matched: o.length,
17283
17456
  results: o
17284
17457
  });
@@ -17311,7 +17484,7 @@ function Gy(e, n = {}) {
17311
17484
  message: `脚本过长(${e.length} 字符,上限 8000)`,
17312
17485
  hint: "精简脚本;复杂逻辑可分步(先 query 探查再 transform 改),或拆成多次 eval"
17313
17486
  });
17314
- let n = await yy(Ey(s ? Vy(a, s) : a), e, 3e3);
17487
+ let n = await By(ry(s ? Ky(a, s) : a), e, 3e3);
17315
17488
  if (!n.ok) {
17316
17489
  let t = /超时/.test(n.error || "");
17317
17490
  return $({
@@ -17332,15 +17505,15 @@ function Gy(e, n = {}) {
17332
17505
  message: `主数据 bind 为原始类型(${a === null ? "null" : typeof a}),eval transform(patches) 无法就地替换`,
17333
17506
  hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹或集成方通过 sdk.setData 替换 bind"
17334
17507
  });
17335
- let t = e.patches, r = Ey(a), o = [];
17508
+ let t = e.patches, r = ry(a), o = [];
17336
17509
  for (let e = 0; e < t.length; e++) {
17337
17510
  let n = t[e], a = n.jsonPath || "";
17338
- if (xy(a)) return $({
17511
+ if (Qv(a)) return $({
17339
17512
  code: "PATH_UNSAFE",
17340
17513
  message: `patches[${e}] jsonPath "${a}" 含非法段`,
17341
17514
  hint: "使用正常属性路径"
17342
17515
  });
17343
- if (!Ly(a, i, s)) return $({
17516
+ if (!Hy(a, i, s)) return $({
17344
17517
  code: "PATH_DENIED",
17345
17518
  message: `patches[${e}] @ "${a}" 不在 schema 声明字段内`,
17346
17519
  hint: "仅 schema 声明的 key 可写"
@@ -17352,11 +17525,11 @@ function Gy(e, n = {}) {
17352
17525
  message: `patches[${e}] ${c} 操作需要 value`,
17353
17526
  hint: `op 为 ${c} 时 value 必填`
17354
17527
  });
17355
- let t = Dy(n.value);
17356
- if (t.parseError) return Yv(`patches[${e}]`, n.value, t.parseError);
17528
+ let t = iy(n.value);
17529
+ if (t.parseError) return Xv(`patches[${e}]`, n.value, t.parseError);
17357
17530
  l = t.parsed;
17358
17531
  }
17359
- let u = My(r, c, a, l);
17532
+ let u = ly(r, c, a, l);
17360
17533
  if (u) return $({
17361
17534
  code: "PATCH_FAILED",
17362
17535
  message: `patches[${e}]: ${u}`,
@@ -17373,33 +17546,33 @@ function Gy(e, n = {}) {
17373
17546
  code: "SCHEMA_INVALID",
17374
17547
  message: "脚本 patches 应用后整体校验失败,未写入",
17375
17548
  hint: "确认 patches 合并后整体仍符合 schema",
17376
- details: qv(c.error.issues)
17549
+ details: Jv(c.error.issues)
17377
17550
  });
17378
17551
  m("edit", "eval_transform");
17379
- for (let e of o) Ny(a, e.op, e.jp, e.value);
17552
+ for (let e of o) uy(a, e.op, e.jp, e.value);
17380
17553
  return p({
17381
17554
  op: "edit",
17382
17555
  detail: `eval_transform(${o.length} patches)`,
17383
17556
  timestamp: Date.now()
17384
- }), u = jy(a), `已通过脚本 transform(patches) 更新主数据(${o.length} 个 patch,耗时 ${n.elapsedMs}ms)。当前值: ${Ay(a, 600)}`;
17557
+ }), u = cy(a), `已通过脚本 transform(patches) 更新主数据(${o.length} 个 patch,耗时 ${n.elapsedMs}ms)。当前值: ${sy(a, 600)}`;
17385
17558
  }
17386
17559
  let t = i.safeParse(e);
17387
17560
  return t.success ? typeof a != "object" || !a ? $({
17388
17561
  code: "LEAF_BIND",
17389
17562
  message: `主数据 bind 为原始类型(${a === null ? "null" : typeof a}),eval transform 无法就地替换外部持有的值引用`,
17390
17563
  hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹或集成方通过 sdk.setData 替换 bind"
17391
- }) : (m("edit", "eval_transform"), t.data !== null && typeof t.data == "object" && (s ? Sy(a, t.data) : Fy(a, t.data)), p({
17564
+ }) : (m("edit", "eval_transform"), t.data !== null && typeof t.data == "object" && (s ? $v(a, t.data) : fy(a, t.data)), p({
17392
17565
  op: "edit",
17393
17566
  detail: "eval_transform",
17394
17567
  timestamp: Date.now()
17395
- }), u = jy(a), `已通过脚本 transform 更新主数据(耗时 ${n.elapsedMs}ms)。当前值: ${Ay(a, 600)}`) : $({
17568
+ }), u = cy(a), `已通过脚本 transform 更新主数据(耗时 ${n.elapsedMs}ms)。当前值: ${sy(a, 600)}`) : $({
17396
17569
  code: "SCHEMA_INVALID",
17397
17570
  message: "脚本返回值校验失败,未写入(transform 模式要求返回主数据的完整新值且符合 schema)",
17398
17571
  hint: "确认脚本 return 了完整新值(非部分);或返回 {patches:[...]} 走增量模式;按 describe_data() 查看格式",
17399
- details: qv(t.error.issues)
17572
+ details: Jv(t.error.issues)
17400
17573
  });
17401
17574
  }
17402
- return Ay({
17575
+ return sy({
17403
17576
  ok: !0,
17404
17577
  result: n.result,
17405
17578
  elapsedMs: n.elapsedMs
@@ -17414,16 +17587,16 @@ function Gy(e, n = {}) {
17414
17587
  }),
17415
17588
  r(async ({ jsonPath: e, fields: t, depth: r }) => {
17416
17589
  let c = e || "";
17417
- if (!Ly(c, i, s)) return $({
17590
+ if (!Hy(c, i, s)) return $({
17418
17591
  code: "PATH_DENIED",
17419
17592
  message: `read @ "${c}" 不在 schema 声明字段内`,
17420
17593
  hint: "主数据仅暴露 schema 声明的字段;若需操作该字段,集成方需在 schema 中声明它"
17421
17594
  });
17422
- let l = c ? Cy(a, c) : a;
17423
- if (!c) l = Vy(l, s);
17595
+ let l = c ? ey(a, c) : a;
17596
+ if (!c) l = Ky(l, s);
17424
17597
  else if (s) {
17425
- let e = zy(i, c);
17426
- e && (l = By(l, e));
17598
+ let e = Wy(i, c);
17599
+ e && (l = Gy(l, e));
17427
17600
  }
17428
17601
  let d = l;
17429
17602
  if (n.interceptors?.read) try {
@@ -17434,11 +17607,11 @@ function Gy(e, n = {}) {
17434
17607
  message: `read 拦截器抛错: ${e.message}`
17435
17608
  });
17436
17609
  }
17437
- t && t.length && (d = Oy(d, t)), r != null && (d = ky(d, r));
17438
- let f = jy(a);
17610
+ t && t.length && (d = ay(d, t)), r != null && (d = oy(d, r));
17611
+ let f = cy(a);
17439
17612
  u = f;
17440
17613
  let p = t && t.length ? `(字段裁剪:${t.join(",")})` : "", m = r == null ? "" : `(深度≤${r})`, h = p || m ? ` ${p}${m}` : "", g = e ? "" : `主数据说明: ${o}\n格式: 写入值需为 JSON,且通过声明的 schema 校验(校验失败时 write 会返回结构化错误)。\n\n`;
17441
- return d === void 0 ? `${g}主数据${e ? ` @ ${e}` : ""}${h} = (undefined) (hash=${f})` : `${g}主数据${e ? ` @ ${e}` : ""}${h} = ${Ay(d)} (hash=${f})`;
17614
+ return d === void 0 ? `${g}主数据${e ? ` @ ${e}` : ""}${h} = (undefined) (hash=${f})` : `${g}主数据${e ? ` @ ${e}` : ""}${h} = ${sy(d)} (hash=${f})`;
17442
17615
  }, {
17443
17616
  name: "read",
17444
17617
  description: "读取主数据(高层入口,合并 describe/get)。不传 jsonPath → 返回主数据说明 + 格式提示;传 jsonPath → 返回该子路径当前值 + hash。hash 用于乐观锁(默认 autoLock,write 时自动比对,无需手动传)。fields(可选):字段裁剪,只返回对象(及数组元素)的指定字段,减少大对象返回体积;depth(可选):嵌套深度限制(0=只根占位,1=根+子,递归截断深层),减少深层结构返回体积。两者可组合,先裁字段再截深度。集成方可能经 read 拦截器对返回值脱敏/派生。",
@@ -17484,12 +17657,12 @@ function Gy(e, n = {}) {
17484
17657
  message: "delete 需要 patch.jsonPath 指定要删的子路径(主数据整体不可删,用 write(value) 整体替换)",
17485
17658
  hint: "如 patch:{jsonPath:\"components.0\"}, del:true"
17486
17659
  });
17487
- if (xy(t.jsonPath)) return $({
17660
+ if (Qv(t.jsonPath)) return $({
17488
17661
  code: "PATH_UNSAFE",
17489
17662
  message: `jsonPath "${t.jsonPath}" 含非法段`,
17490
17663
  hint: "使用正常属性路径"
17491
17664
  });
17492
- if (!Ly(t.jsonPath, i, s)) return $({
17665
+ if (!Hy(t.jsonPath, i, s)) return $({
17493
17666
  code: "PATH_DENIED",
17494
17667
  message: `write delete @ "${t.jsonPath}" 不在 schema 声明字段内`,
17495
17668
  hint: "仅 schema 声明的 key 可删"
@@ -17497,12 +17670,12 @@ function Gy(e, n = {}) {
17497
17670
  let e = await h("delete", g);
17498
17671
  if (e !== null) return e;
17499
17672
  m("delete");
17500
- let n = Ty(a, t.jsonPath);
17673
+ let n = ny(a, t.jsonPath);
17501
17674
  return p({
17502
17675
  op: "delete",
17503
17676
  detail: t.jsonPath,
17504
17677
  timestamp: Date.now()
17505
- }), u = jy(a), n ? `已删除主数据 @ ${t.jsonPath}` : `主数据 @ ${t.jsonPath} 不存在(无需删除)`;
17678
+ }), u = cy(a), n ? `已删除主数据 @ ${t.jsonPath}` : `主数据 @ ${t.jsonPath} 不存在(无需删除)`;
17506
17679
  }
17507
17680
  if (c === "edit") {
17508
17681
  if (typeof a != "object" || !a) return $({
@@ -17516,15 +17689,15 @@ function Gy(e, n = {}) {
17516
17689
  op: t.op,
17517
17690
  jsonPath: t.jsonPath || "",
17518
17691
  value: l
17519
- }]), o = Ey(a), c = [];
17692
+ }]), o = ry(a), c = [];
17520
17693
  for (let e = 0; e < n.length; e++) {
17521
17694
  let t = n[e], r = t.jsonPath || "";
17522
- if (xy(r)) return $({
17695
+ if (Qv(r)) return $({
17523
17696
  code: "PATH_UNSAFE",
17524
17697
  message: `patches[${e}] jsonPath "${r}" 含非法段`,
17525
17698
  hint: "使用正常属性路径,如 components.0.text"
17526
17699
  });
17527
- if (!Ly(r, i, s)) return $({
17700
+ if (!Hy(r, i, s)) return $({
17528
17701
  code: "PATH_DENIED",
17529
17702
  message: `patches[${e}] @ "${r}" 不在 schema 声明字段内`,
17530
17703
  hint: "仅 schema 声明的 key 可写"
@@ -17536,11 +17709,11 @@ function Gy(e, n = {}) {
17536
17709
  message: `patches[${e}] ${a} 操作需要 value`,
17537
17710
  hint: `op 为 ${a} 时 value 必填;删除请用 op:'remove'`
17538
17711
  });
17539
- let n = Dy(t.value);
17540
- if (n.parseError) return Yv(`patches[${e}]`, t.value, n.parseError);
17712
+ let n = iy(t.value);
17713
+ if (n.parseError) return Xv(`patches[${e}]`, t.value, n.parseError);
17541
17714
  l = n.parsed;
17542
17715
  }
17543
- let u = My(o, a, r, l);
17716
+ let u = ly(o, a, r, l);
17544
17717
  if (u) return $({
17545
17718
  code: "PATCH_FAILED",
17546
17719
  message: `patches[${e}]: ${u}`,
@@ -17553,18 +17726,18 @@ function Gy(e, n = {}) {
17553
17726
  });
17554
17727
  }
17555
17728
  let d = i.safeParse(o);
17556
- if (!d.success) return Jv("", d.error.issues);
17729
+ if (!d.success) return Yv("", d.error.issues);
17557
17730
  m("edit");
17558
- for (let e of c) Ny(a, e.op, e.jp, e.value);
17731
+ for (let e of c) uy(a, e.op, e.jp, e.value);
17559
17732
  return p({
17560
17733
  op: "edit",
17561
17734
  detail: `${c.length} 个 patch${c.length > 1 ? "(批量)" : ""}`,
17562
17735
  value: c.map((e) => `${e.op}@${e.jp}`),
17563
17736
  timestamp: Date.now()
17564
- }), u = jy(a), `已 write(edit) 主数据(${c.length} 个 patch)。当前值:${Ay(a, 600)} (新 hash=${jy(a)})`;
17737
+ }), u = cy(a), `已 write(edit) 主数据(${c.length} 个 patch)。当前值:${sy(a, 600)} (新 hash=${cy(a)})`;
17565
17738
  }
17566
- let _, v = Dy(l);
17567
- if (v.parseError) return Yv("", l, v.parseError);
17739
+ let _, v = iy(l);
17740
+ if (v.parseError) return Xv("", l, v.parseError);
17568
17741
  _ = v.parsed;
17569
17742
  let y = await h("set", g);
17570
17743
  if (y !== null) return y;
@@ -17573,11 +17746,11 @@ function Gy(e, n = {}) {
17573
17746
  code: "LEAF_BIND",
17574
17747
  message: `主数据 bind 为原始类型(${a === null ? "null" : typeof a}),write(set) 无法就地替换外部持有的值引用`,
17575
17748
  hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹(如 {value:\"x\"})或集成方通过 sdk.setData 替换 bind"
17576
- }) : (m("set"), b.data !== null && typeof b.data == "object" && (s ? Sy(a, b.data) : Fy(a, b.data)), p({
17749
+ }) : (m("set"), b.data !== null && typeof b.data == "object" && (s ? $v(a, b.data) : fy(a, b.data)), p({
17577
17750
  op: "set",
17578
17751
  value: b.data,
17579
17752
  timestamp: Date.now()
17580
- }), u = jy(a), `已 write(set) 主数据 = ${Ay(b.data, 600)} (新 hash=${jy(a)})${s ? "(白名单模式:仅更新 schema 声明字段,未声明字段保留)" : ""}`) : Jv("", b.error.issues);
17753
+ }), u = cy(a), `已 write(set) 主数据 = ${sy(b.data, 600)} (新 hash=${cy(a)})${s ? "(白名单模式:仅更新 schema 声明字段,未声明字段保留)" : ""}`) : Yv("", b.error.issues);
17581
17754
  }, {
17582
17755
  name: "write",
17583
17756
  description: "写入主数据(高层入口,合并 set/edit/delete + 自动乐观锁 + 自动快照)。四种意图:① 整体替换 write({ value }) value 为 JSON 对象(推荐)或字符串;② 单个增量 patch write({ value, patch:{op,jsonPath} }) op=set/remove/merge/append,jsonPath 相对主数据根(如 components.0.text),value 作为该 patch 的值;③ 批量增量 write({ patches:[{op,jsonPath,value},...] }) 一次原子应用多个 patch(任一失败整体不写入,适合一次改多处);④ 删除 write({ patch:{jsonPath}, del:true })。写入自动经 schema 校验(失败不写)+ 自动存快照(可 restore_data 回退)+ 自动乐观锁(autoLock,用你最后 read 到的 hash 比对,冲突则 VERSION_CONFLICT)。集成方可能经 write 拦截器校验/转换/拒绝(批量模式拦截器收到 {patches},返回新 patches 数组或 {error})。",
@@ -17615,8 +17788,8 @@ function Gy(e, n = {}) {
17615
17788
  }
17616
17789
  //#endregion
17617
17790
  //#region src/core/tools/fetchDoc.ts
17618
- var Ky = 3e4, qy = [r(async ({ url: e, as: t }) => {
17619
- let n = new AbortController(), r = setTimeout(() => n.abort(), Ky);
17791
+ var Zy = 3e4, Qy = [r(async ({ url: e, as: t }) => {
17792
+ let n = new AbortController(), r = setTimeout(() => n.abort(), Zy);
17620
17793
  try {
17621
17794
  let r = await fetch(e, {
17622
17795
  method: "GET",
@@ -17633,7 +17806,7 @@ var Ky = 3e4, qy = [r(async ({ url: e, as: t }) => {
17633
17806
  ].join("\n");
17634
17807
  } catch (t) {
17635
17808
  let r = t?.message || String(t);
17636
- return n.signal.aborted ? `获取失败:请求超时(${Ky}ms,${e})。` : /Failed to fetch|NetworkError|CORS|blocked/i.test(r) ? `获取失败:可能是 CORS 跨域拦截或网络错误(${r})。浏览器仅能 GET 同源或服务端已配置 CORS 的资源;跨域抓取需后端代理。` : `获取失败:${r}`;
17809
+ return n.signal.aborted ? `获取失败:请求超时(${Zy}ms,${e})。` : /Failed to fetch|NetworkError|CORS|blocked/i.test(r) ? `获取失败:可能是 CORS 跨域拦截或网络错误(${r})。浏览器仅能 GET 同源或服务端已配置 CORS 的资源;跨域抓取需后端代理。` : `获取失败:${r}`;
17637
17810
  } finally {
17638
17811
  clearTimeout(r);
17639
17812
  }
@@ -17644,25 +17817,25 @@ var Ky = 3e4, qy = [r(async ({ url: e, as: t }) => {
17644
17817
  url: t.string().describe("要抓取的 URL(同源或已配 CORS)"),
17645
17818
  as: t.enum(["text", "markdown"]).optional().describe("返回格式标签,默认 text")
17646
17819
  })
17647
- })], Jy = qy;
17648
- function Yy(e, t) {
17649
- return Gy(e, t);
17820
+ })], $y = Qy;
17821
+ function eb(e, t) {
17822
+ return Xy(e, t);
17650
17823
  }
17651
- function Xy(e, t, n) {
17824
+ function tb(e, t, n) {
17652
17825
  let r = e?.dataOps !== !1, i = e?.fetch !== !1;
17653
17826
  return [...r ? t : [], ...i ? n : []];
17654
17827
  }
17655
17828
  //#endregion
17656
17829
  //#region src/core/harness/usageHints.ts
17657
- var Zy = .7;
17658
- function Qy(e, t, n = "simple") {
17830
+ var nb = .7;
17831
+ function rb(e, t, n = "simple") {
17659
17832
  let r = n !== "advanced";
17660
17833
  return {
17661
17834
  name: "usageHints",
17662
17835
  augmentPrompt: () => {
17663
17836
  let n = [];
17664
17837
  if (e?.planning !== !1 && n.push("多步任务建议先 write_todos 拆解为步骤并逐步推进。"), t && (r ? (n.push("读写主数据用 read/write(高层入口,自动乐观锁 + 自动快照)。read({jsonPath}) 读子路径当前值(返回含 hash,write 时自动比对,无需手动传);read() 不传读整个主数据 + 说明。write({value}) 整体替换(value 直传 JSON 对象,如 {title:\"x\"},无需 stringify);write({value, patch:{op,jsonPath}}) 增量 patch(op=set/remove/merge/append);write({patch:{jsonPath}, del:true}) 删除子路径。写入自动经 schema 校验(失败不写)+ 自动存快照(出错可用 restore_data 回退)。"), n.push("修改大对象/数组优先用 write 的 patch 增量(只发改动部分),避免整体重传被 max_tokens 截断致 JSON 不完整。"), 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(返回值经校验后落地)。"))), e?.subagent !== !1 && n.push("独立子任务可 spawn_agent 委派(只读工具,过程不占主上下文)。"), e?.subagents?.length) {
17665
- let t = e.subagents.filter((e) => (e.temperature ?? 0) >= Zy || /规划|创意|设计|方案|brainstorm|plan/i.test(e.description)), i = e.subagents.filter((e) => (e.temperature ?? 0) < Zy && /反思|审查|挑刺|校验|review|critique|reflect/i.test(e.description));
17838
+ let t = e.subagents.filter((e) => (e.temperature ?? 0) >= nb || /规划|创意|设计|方案|brainstorm|plan/i.test(e.description)), i = e.subagents.filter((e) => (e.temperature ?? 0) < nb && /反思|审查|挑刺|校验|review|critique|reflect/i.test(e.description));
17666
17839
  n.push("【规划-反思-执行·路由】按任务性质选模式,不要对简单任务过度编排:"), t.length && (n.push(` · 创作/设计/开放性需求(如"设计主题风格""换个感觉")→ 先调 ${t.map((e) => "use_" + e.id).join("/")} 出 2-3 套方案(高温创意),`), n.push(" 不要自己拍板;拿到方案后,若需用户拍板用 request_human_confirmation 弹选项。")), i.length && n.push(` · 严谨/易错/校验类 → 可先调 ${i.map((e) => "use_" + e.id).join("/")} 反思挑刺(低温审查),据反馈修订。`), n.push(r ? " · 方案定稿后,由你(主 agent)用 write 落地成 JSON(低温度执行 + schema 校验 + 写前确认)。" : " · 方案定稿后,由你(主 agent)用 edit_data 落地成 JSON(低温度执行 + schema 校验 + 写前确认)。"), n.push(" · 简单/明确任务(如\"标题改红色\")直接执行,不必走规划-反思。");
17667
17840
  }
17668
17841
  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("用户在选项里选了哪个,就按那个方案继续;选「拒绝」则停止并询问如何调整。")), n.length && n.unshift("调用工具务必用标准 function calling(工具调用)格式发起,不要在回复正文里输出伪 XML/标签(如 deepseek 的 tool_calls 标签、invoke、function_call、tool_call 等)或 JSON 文本——那不会被识别为工具调用,会被当普通文字,工具不执行。"), n.length ? "## 能力使用提示\n" + n.join("\n") : void 0;
@@ -17671,15 +17844,15 @@ function Qy(e, t, n = "simple") {
17671
17844
  }
17672
17845
  //#endregion
17673
17846
  //#region src/core/backends/skillStore.ts
17674
- var $y = "v:1::skill-store", eb = "chat-sdk";
17675
- function tb(e, t, n) {
17676
- return `${$y}::${e}::${t}::${n}`;
17847
+ var ib = "v:1::skill-store", ab = "chat-sdk";
17848
+ function ob(e, t, n) {
17849
+ return `${ib}::${e}::${t}::${n}`;
17677
17850
  }
17678
- function nb(e, t) {
17679
- return `${$y}::${e}::${t}::`;
17851
+ function sb(e, t) {
17852
+ return `${ib}::${e}::${t}::`;
17680
17853
  }
17681
- function rb(e = {}) {
17682
- let t = e.dbName ?? eb, n = e.backend ?? "indexed", r = e.id ?? "", i, a, o = new Promise((e) => {
17854
+ function cb(e = {}) {
17855
+ let t = e.dbName ?? ab, n = e.backend ?? "indexed", r = e.id ?? "", i, a, o = new Promise((e) => {
17683
17856
  a = e;
17684
17857
  });
17685
17858
  return (async () => {
@@ -17701,42 +17874,42 @@ function rb(e = {}) {
17701
17874
  ready: o,
17702
17875
  async list() {
17703
17876
  let e = [];
17704
- return await i.scan(nb(t, r), (t, n) => {
17877
+ return await i.scan(sb(t, r), (t, n) => {
17705
17878
  e.push(n);
17706
17879
  }), e;
17707
17880
  },
17708
17881
  async get(e) {
17709
- return await i.get(tb(t, r, e));
17882
+ return await i.get(ob(t, r, e));
17710
17883
  },
17711
17884
  async put(e) {
17712
17885
  try {
17713
- await i.set(tb(t, r, e.name), e);
17886
+ await i.set(ob(t, r, e.name), e);
17714
17887
  } catch (e) {
17715
17888
  kv(e) && (i = Lv());
17716
17889
  }
17717
17890
  },
17718
17891
  async remove(e) {
17719
- let n = tb(t, r, e);
17892
+ let n = ob(t, r, e);
17720
17893
  return await i.get(n) != null && (await i.del(n), !0);
17721
17894
  },
17722
17895
  async clear() {
17723
- await i.clearPrefix(nb(t, r));
17896
+ await i.clearPrefix(sb(t, r));
17724
17897
  },
17725
17898
  dispose() {}
17726
17899
  };
17727
17900
  }
17728
17901
  //#endregion
17729
17902
  //#region src/core/sdk/createChatSdk.ts
17730
- var ib = 50, ab = /* @__PURE__ */ new Map();
17731
- function ob(e, t) {
17903
+ var lb = 50, ub = /* @__PURE__ */ new Map();
17904
+ function db(e, t) {
17732
17905
  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;
17733
17906
  }
17734
- function sb(e, t, n, r) {
17907
+ function fb(e, t, n, r) {
17735
17908
  let i = 0;
17736
17909
  return {
17737
17910
  name: "sdk-events",
17738
17911
  wrapToolCall: async (t, r) => {
17739
- let i = await r(t), a = ob(t.name, t.args);
17912
+ let i = await r(t), a = db(t.name, t.args);
17740
17913
  return a && e({
17741
17914
  type: "data_change",
17742
17915
  operation: a,
@@ -17771,7 +17944,7 @@ function sb(e, t, n, r) {
17771
17944
  }
17772
17945
  };
17773
17946
  }
17774
- function cb(e, i) {
17947
+ function pb(e, i) {
17775
17948
  let a = {
17776
17949
  prompt_tokens: 0,
17777
17950
  completion_tokens: 0,
@@ -17782,11 +17955,12 @@ function cb(e, i) {
17782
17955
  e.debug && console.log("[page-agent-sdk][modelCaps]", d);
17783
17956
  let f = e.llm;
17784
17957
  e.debug && !u && console.warn("[page-agent-sdk][summarization] 未构造 llmInvoke(apiKey 缺失?),摘要回退零成本索引摘要");
17785
- let p = /* @__PURE__ */ tn([]), m = Zv(e.vfs?.initialFiles, {
17958
+ let p = /* @__PURE__ */ tn([]), m = gy(e.vfs?.initialFiles, {
17786
17959
  persist: c ? { save: (e) => {
17787
17960
  z.sessionId && c && c.save(i, z.sessionId, { vfs: e });
17788
17961
  } } : void 0,
17789
- maxBytes: e.vfs?.maxBytes
17962
+ maxBytes: e.vfs?.maxBytes,
17963
+ poolBytes: e.vfs?.poolBytes
17790
17964
  }), h = Kg(), g = e_(e.memory || "");
17791
17965
  typeof e.memory == "function" && g.refresh();
17792
17966
  let _ = { current: null }, v = e.data ? {
@@ -17800,13 +17974,13 @@ function cb(e, i) {
17800
17974
  getTodos: () => _.current?.getState?.()?.todos ?? [],
17801
17975
  messages: p,
17802
17976
  maxCheckpoints: y && typeof y == "object" ? y.maxCheckpoints : void 0
17803
- }) : null, S = !y || typeof y != "object" || y.auto !== !1, C = e.capabilities, w = C?.dataOps !== !1, T = dv(e), E = w && v ? Gy(v, {
17977
+ }) : null, S = !y || typeof y != "object" || y.auto !== !1, C = e.capabilities, w = C?.dataOps !== !1, T = dv(e), E = w && v ? Xy(v, {
17804
17978
  onAudit: e.onAudit ?? (e.debug ? (e) => console.log("[page-agent-sdk][data audit]", e) : void 0),
17805
17979
  maxSnapshots: e.maxSnapshots,
17806
17980
  onConflict: o.set,
17807
17981
  autoLock: e.autoLock,
17808
17982
  interceptors: e.interceptors
17809
- }) : [], D = w ? Wy(E, e.toolMode) : [], O = w && v ? E.controller ?? null : null, k = () => O?.get() ?? v, A = /* @__PURE__ */ new Map(), j = Xy(C, D, qy);
17983
+ }) : [], D = w ? Yy(E, e.toolMode) : [], O = w && v ? E.controller ?? null : null, k = () => O?.get() ?? v, A = /* @__PURE__ */ new Map(), j = tb(C, D, Qy);
17810
17984
  j.forEach((e) => A.set(e.name, "builtin"));
17811
17985
  let M = [...e.tools || []];
17812
17986
  M.forEach((e) => A.set(e.name, "user"));
@@ -17843,7 +18017,9 @@ function cb(e, i) {
17843
18017
  ...ee
17844
18018
  ];
17845
18019
  }
17846
- let ne = C?.planning !== !1, re = C?.skills !== !1, ie = C?.vfs !== !1, ae = C?.summarization !== !1, oe = C?.memory !== !1, se = C?.subagent !== !1, ce = e.verify?.maxAttempts ?? 2, le = C?.verify === !0 && e.verify?.enabled !== !1 && ce > 0;
18020
+ let ne = C?.planning !== !1, re = C?.skills !== !1, ie = C?.vfs !== !1;
18021
+ if (ie) for (let e of Cy) A.set(e, "builtin");
18022
+ let ae = C?.summarization !== !1, oe = C?.memory !== !1, se = C?.subagent !== !1, ce = e.verify?.maxAttempts ?? 2, le = C?.verify === !0 && e.verify?.enabled !== !1 && ce > 0;
17847
18023
  e.verify?.check && C?.verify !== !0 && console.warn("[page-agent-sdk][verify] 检测到 verify.check 但 capabilities.verify 未开启,verify 未装载");
17848
18024
  let ue = e.subagent, L = ue?.allowedTools ?? [], de = !se || ue?.enabled === !1 ? void 0 : E_({
17849
18025
  llm: ue?.llm ?? e.llm,
@@ -17874,7 +18050,7 @@ function cb(e, i) {
17874
18050
  llm: e.llm,
17875
18051
  tools: he
17876
18052
  } : void 0
17877
- }) : void 0, _e = Qy({
18053
+ }) : void 0, _e = rb({
17878
18054
  ...C,
17879
18055
  humanConfirm: N,
17880
18056
  subagents: e.subagents?.map((e) => ({
@@ -17906,7 +18082,7 @@ function cb(e, i) {
17906
18082
  name: e.name,
17907
18083
  description: e.description,
17908
18084
  getContent: () => e.content
17909
- }), R = e.skillStorage === !1 ? null : rb({
18085
+ }), R = e.skillStorage === !1 ? null : cb({
17910
18086
  ...typeof e.skillStorage == "object" ? e.skillStorage : {},
17911
18087
  id: e.skillStorage && typeof e.skillStorage == "object" && e.skillStorage.id ? e.skillStorage.id : `agent::${i}`
17912
18088
  }), De = () => {
@@ -17934,12 +18110,12 @@ function cb(e, i) {
17934
18110
  _e,
17935
18111
  ...ne ? [h] : [],
17936
18112
  ...re ? [Ce = $g(e.skills || [], { readVfs: ie ? (e) => m.files[e]?.content : void 0 })] : [],
17937
- ...ie ? [iy(m)] : [],
18113
+ ...ie ? [Ty(m)] : [],
17938
18114
  ...ae ? [av({
17939
- ...Kv(e, d.contextWindow),
18115
+ ...qv(e, d.contextWindow),
17940
18116
  llmInvoke: u,
17941
18117
  getRegisteredData: () => k() ? [{ description: k().description ?? "主数据对象" }] : [],
17942
- preserveLastToolResults: (e.contextOptions && e.contextOptions.preserveLastToolResults) ?? ["describe_data", "read"]
18118
+ preserveLastToolResults: (e.contextOptions && e.contextOptions.preserveLastToolResults) ?? Kv[e.contextPreset ?? "auto"]
17943
18119
  })] : [],
17944
18120
  ...oe ? [g] : [],
17945
18121
  ...e.permissions?.length ? [a_(e.permissions)] : [],
@@ -17951,8 +18127,8 @@ function cb(e, i) {
17951
18127
  ...fe ? [fe] : [],
17952
18128
  ...ye ? [ye] : [],
17953
18129
  ...e.middleware || [],
17954
- sb(Se, p, k, a)
17955
- ], Ae = e.maxMemoryRounds ?? ib, z = {
18130
+ fb(Se, p, k, a)
18131
+ ], Ae = e.maxMemoryRounds ?? lb, z = {
17956
18132
  agentId: i,
17957
18133
  store: c,
17958
18134
  messages: p,
@@ -18054,7 +18230,7 @@ function cb(e, i) {
18054
18230
  if (z.refCount--, z.refCount <= 0) {
18055
18231
  c && (m.flush?.(), c.flush(), c.dispose()), R && R.dispose();
18056
18232
  let e = z.mcpClosers.splice(0);
18057
- e.length && Promise.allSettled(e.map((e) => e())), ab.delete(i);
18233
+ e.length && Promise.allSettled(e.map((e) => e())), ub.delete(i);
18058
18234
  }
18059
18235
  },
18060
18236
  resolveConflict: o.resolve,
@@ -18128,6 +18304,7 @@ function cb(e, i) {
18128
18304
  description: k().description,
18129
18305
  schema: k().schema
18130
18306
  } : void 0,
18307
+ contextPreset: e.contextPreset ?? "auto",
18131
18308
  memory: g.get(),
18132
18309
  middleware: ke.map((e) => e.name),
18133
18310
  todos: (z.agent?.getState?.()?.todos ?? []).map((e) => ({
@@ -18243,11 +18420,11 @@ function cb(e, i) {
18243
18420
  });
18244
18421
  })(), z;
18245
18422
  }
18246
- function lb(e) {
18423
+ function mb(e) {
18247
18424
  let t = e.id ?? _v();
18248
18425
  e.id || console.warn(`[page-agent-sdk] 未传 options.id,已生成随机 id "${t}"。刷新后持久化数据无法恢复,请传稳定 id。`);
18249
- let n = e.streaming ?? !0, r = e.ui ?? "default", i, a = e.shareContext ? ab.get(t) : void 0;
18250
- a ? i = a : (i = cb(e, t), e.shareContext && ab.set(t, i)), i.refCount++;
18426
+ let n = e.streaming ?? !0, r = e.ui ?? "default", i, a = e.shareContext ? ub.get(t) : void 0;
18427
+ a ? i = a : (i = pb(e, t), e.shareContext && ub.set(t, i)), i.refCount++;
18251
18428
  let o = null, s = null, c = Uv(e), l = null, u = null;
18252
18429
  async function d(t) {
18253
18430
  if (await i.initDone, o) {
@@ -18425,7 +18602,7 @@ function lb(e) {
18425
18602
  }
18426
18603
  //#endregion
18427
18604
  //#region src/core/sdk/defineTool.ts
18428
- function ub(e) {
18605
+ function hb(e) {
18429
18606
  return r(async (t) => {
18430
18607
  let n = await e.handler(t);
18431
18608
  return typeof n == "string" ? n : JSON.stringify(n);
@@ -18436,4 +18613,4 @@ function ub(e) {
18436
18613
  });
18437
18614
  }
18438
18615
  //#endregion
18439
- export { Gv as CONTEXT_PRESETS, yg as ChatDialog, nf as CodePreview, lv as DEFAULT_SYSTEM_PROMPT, s_ as HUMAN_CONFIRM_TOOL_NAME, af as MessageContent, Z_ as STOP_WORDS, sh as SkillPanel, by as UNSAFE_KEYS, My as applyPatchToClone, Ny as applyPatchToLive, uv as buildDataPrompt, dv as buildSystemPrompt, K_ as connectMcp, wl as copyText, Wg as createAgent, o_ as createApprovalMiddleware, lb as createChatSdk, __ as createCheckpointManager, v_ as createCheckpointMiddleware, gv as createConflictManager, Gy as createDataOps, u_ as createHumanConfirmMiddleware, l_ as createHumanConfirmTool, Lv as createMemoryBackend, e_ as createMemoryMiddleware, v as createProxyLlm, Wv as createSdkEvents, Vv as createSessionStore, rb as createSkillStore, E_ as createSubagentMiddleware, k_ as createSubagentsMiddleware, Qy as createUsageHintsMiddleware, A_ as createVerifyMiddleware, Zv as createVfs, zv as createWebStorageBackend, I_ as createWriteBackCheck, Ey as deepClone, Yy as defineDataToolset, qg as defineSkill, ub as defineTool, Ty as deleteByPath, zg as detectGarbledToolCall, $_ as estimateMessageTokens, ev as estimateRoundTokens, Dg as estimateTokens, cv as extractSchemaHint, U_ as extractText, qy as fetchDocTools, Jy as fetchTools, Wy as filterByToolMode, qv as formatZodIssues, Cy as getByPath, zy as getSchemaAtPath, Iy as getSchemaTopKeys, jy as hashValue, tv as indexSummarize, fv as isChatModel, Ly as isPathAllowed, kv as isQuotaError, xy as isUnsafePath, my as jpEval, Yv as jsonParseError, ky as limitDepth, Dy as maybeParseValue, kg as offloadPassThroughChars, Og as offloadThresholdChars, ov as presets, Vy as projectBySchema, By as projectBySchemaDeep, Oy as projectFields, nv as recallRounds, Kv as resolveContextOptions, Uv as resolveDialogConfig, hv as resolveLlm, Eg as resolveModelCaps, Hv as resolveStorage, Fy as restoreInPlace, Py as restoreLive, yy as runSandboxedScript, Sy as safeMerge, Ay as safeStringify, gy as searchJson, Xy as selectBuiltinTools, wy as setByPath, sv as systemPromptHelpers, Q_ as tokenize, $ as toolError, Ry as unwrapSchema, Cl as useChat, e as z, Jv as zodError };
18616
+ export { Gv as CONTEXT_PRESETS, yg as ChatDialog, nf as CodePreview, lv as DEFAULT_SYSTEM_PROMPT, s_ as HUMAN_CONFIRM_TOOL_NAME, af as MessageContent, Z_ as STOP_WORDS, sh as SkillPanel, Zv as UNSAFE_KEYS, ly as applyPatchToClone, uy as applyPatchToLive, uv as buildDataPrompt, dv as buildSystemPrompt, K_ as connectMcp, wl as copyText, Wg as createAgent, o_ as createApprovalMiddleware, mb as createChatSdk, __ as createCheckpointManager, v_ as createCheckpointMiddleware, gv as createConflictManager, Xy as createDataOps, u_ as createHumanConfirmMiddleware, l_ as createHumanConfirmTool, Lv as createMemoryBackend, e_ as createMemoryMiddleware, v as createProxyLlm, Wv as createSdkEvents, Vv as createSessionStore, cb as createSkillStore, E_ as createSubagentMiddleware, k_ as createSubagentsMiddleware, rb as createUsageHintsMiddleware, A_ as createVerifyMiddleware, gy as createVfs, zv as createWebStorageBackend, I_ as createWriteBackCheck, ry as deepClone, eb as defineDataToolset, qg as defineSkill, hb as defineTool, ny as deleteByPath, zg as detectGarbledToolCall, $_ as estimateMessageTokens, ev as estimateRoundTokens, Dg as estimateTokens, cv as extractSchemaHint, U_ as extractText, Qy as fetchDocTools, $y as fetchTools, Yy as filterByToolMode, Jv as formatZodIssues, ey as getByPath, Wy as getSchemaAtPath, Vy as getSchemaTopKeys, cy as hashValue, tv as indexSummarize, fv as isChatModel, Hy as isPathAllowed, kv as isQuotaError, Qv as isUnsafePath, Fy as jpEval, Xv as jsonParseError, oy as limitDepth, iy as maybeParseValue, kg as offloadPassThroughChars, Og as offloadThresholdChars, ov as presets, Ky as projectBySchema, Gy as projectBySchemaDeep, ay as projectFields, nv as recallRounds, qv as resolveContextOptions, Uv as resolveDialogConfig, hv as resolveLlm, Eg as resolveModelCaps, Hv as resolveStorage, fy as restoreInPlace, dy as restoreLive, By as runSandboxedScript, $v as safeMerge, sy as safeStringify, Ly as searchJson, tb as selectBuiltinTools, ty as setByPath, sv as systemPromptHelpers, Q_ as tokenize, $ as toolError, Uy as unwrapSchema, Cl as useChat, e as z, Yv as zodError };