page-agent-sdk 3.25.0 → 3.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/README.zh-CN.md +4 -3
- package/dist/page-agent-sdk.headless.js +1413 -1404
- package/dist/page-agent-sdk.iife.js +44 -44
- package/dist/page-agent-sdk.js +109 -100
- package/dist/page-agent-sdk.legacy.js +84926 -0
- package/dist/page-agent-sdk.umd.cjs +5 -5
- package/dist/style.css +1 -1
- package/legacy.js +10 -0
- package/package.json +10 -3
- package/skills/page-agent-sdk-integrate/SKILL.md +8 -1
- package/style.css +2 -0
package/dist/page-agent-sdk.js
CHANGED
|
@@ -10916,7 +10916,7 @@ function Sg(e) {
|
|
|
10916
10916
|
id: _,
|
|
10917
10917
|
ts: Date.now(),
|
|
10918
10918
|
op: "edit",
|
|
10919
|
-
value: Cd(t),
|
|
10919
|
+
value: f ?? Cd(t),
|
|
10920
10920
|
...l ? { label: l } : {}
|
|
10921
10921
|
}); a.length > o;) a.shift();
|
|
10922
10922
|
for (let e of m) e.op === "remove" && Sd(t, e.jp);
|
|
@@ -11002,32 +11002,35 @@ function kg(e, n = {}) {
|
|
|
11002
11002
|
} : void 0, m = [], h = n.maxSnapshots ?? 20, g = /* @__PURE__ */ new Map(), _ = "", v = (e) => e?.configurable?.__pgDataScope ?? _, y = (e) => g.get(e ?? _), b = (e, t) => {
|
|
11003
11003
|
let n = t ?? _;
|
|
11004
11004
|
e === void 0 ? g.delete(n) : g.set(n, e);
|
|
11005
|
-
}, x =
|
|
11005
|
+
}, x = (e) => {
|
|
11006
|
+
let t = kd(s);
|
|
11007
|
+
return b(t, e), t;
|
|
11008
|
+
}, S = n.autoLock !== !1, C = n.largeTextThreshold ?? 200, w = (n.largeTextPaths ?? []).map((e) => {
|
|
11006
11009
|
let t = e.lastIndexOf(".");
|
|
11007
11010
|
return t > 0 ? {
|
|
11008
11011
|
arrayPath: e.slice(0, t),
|
|
11009
11012
|
field: e.slice(t + 1)
|
|
11010
11013
|
} : null;
|
|
11011
|
-
}).filter((e) => e !== null),
|
|
11012
|
-
function
|
|
11013
|
-
|
|
11014
|
+
}).filter((e) => e !== null), T = !0;
|
|
11015
|
+
function E() {
|
|
11016
|
+
T = !0;
|
|
11014
11017
|
}
|
|
11015
|
-
let
|
|
11018
|
+
let D = {
|
|
11016
11019
|
get: () => ({
|
|
11017
11020
|
schema: o,
|
|
11018
11021
|
bind: s,
|
|
11019
11022
|
description: c
|
|
11020
11023
|
}),
|
|
11021
11024
|
set: (e) => {
|
|
11022
|
-
o = i.length ? $u(e.schema, i).schema : e.schema, s = e.bind, c = e.description ?? "主数据对象", l = Mu(o), m.length = 0, g.clear(), f(e.resources), d?.clear(),
|
|
11025
|
+
o = i.length ? $u(e.schema, i).schema : e.schema, s = e.bind, c = e.description ?? "主数据对象", l = Mu(o), m.length = 0, g.clear(), f(e.resources), d?.clear(), E();
|
|
11023
11026
|
},
|
|
11024
11027
|
update: (e) => {
|
|
11025
|
-
s = e, m.length = 0, g.clear(),
|
|
11028
|
+
s = e, m.length = 0, g.clear(), E();
|
|
11026
11029
|
},
|
|
11027
|
-
markDataDirty:
|
|
11030
|
+
markDataDirty: E,
|
|
11028
11031
|
consumeDataDirty: () => {
|
|
11029
|
-
let e =
|
|
11030
|
-
return
|
|
11032
|
+
let e = T;
|
|
11033
|
+
return T = !1, e;
|
|
11031
11034
|
},
|
|
11032
11035
|
enterScope: (e) => {
|
|
11033
11036
|
let t = _;
|
|
@@ -11074,14 +11077,14 @@ function kg(e, n = {}) {
|
|
|
11074
11077
|
} : void 0,
|
|
11075
11078
|
updateResource: d ? (e, t) => {
|
|
11076
11079
|
let n = og(e);
|
|
11077
|
-
d.update(n, t), xd(s, n, t),
|
|
11080
|
+
d.update(n, t), xd(s, n, t), E();
|
|
11078
11081
|
} : void 0,
|
|
11079
11082
|
deleteResource: d ? (e) => d.delete(e) : void 0,
|
|
11080
11083
|
listResources: d ? () => d.list() : void 0
|
|
11081
|
-
},
|
|
11084
|
+
}, O = (e) => {
|
|
11082
11085
|
n.onAudit?.(e);
|
|
11083
11086
|
};
|
|
11084
|
-
function
|
|
11087
|
+
function k(e, t) {
|
|
11085
11088
|
let n = Cd(s), r = m.length ? m[m.length - 1].id + 1 : 1;
|
|
11086
11089
|
for (m.push({
|
|
11087
11090
|
id: r,
|
|
@@ -11092,7 +11095,7 @@ function kg(e, n = {}) {
|
|
|
11092
11095
|
}); m.length > h;) m.shift();
|
|
11093
11096
|
return r;
|
|
11094
11097
|
}
|
|
11095
|
-
async function
|
|
11098
|
+
async function A(e, t, r) {
|
|
11096
11099
|
if (!t || t === "") return null;
|
|
11097
11100
|
let i = kd(s);
|
|
11098
11101
|
if (i === t) return null;
|
|
@@ -11113,17 +11116,17 @@ function kg(e, n = {}) {
|
|
|
11113
11116
|
if (a.action === "restore") {
|
|
11114
11117
|
if (!m.length) return `无历史快照可回退(本次为首次操作)。当前值:${Dd(s, 400)} (hash=${i})。请重新 read 再改或选「强制覆盖」。`;
|
|
11115
11118
|
let e = m[m.length - 1];
|
|
11116
|
-
return Pd(s, Cd(e.value)),
|
|
11119
|
+
return Pd(s, Cd(e.value)), E(), `已回退主数据到历史快照 #${e.id}[${e.op}]。当前值:${Dd(s, 400)} (hash=${kd(s)})。请基于回退后的值重写或停止。`;
|
|
11117
11120
|
}
|
|
11118
11121
|
return null;
|
|
11119
11122
|
}
|
|
11120
|
-
let
|
|
11123
|
+
let ee = (e, t = !0) => {
|
|
11121
11124
|
e.writeCapable = t;
|
|
11122
|
-
},
|
|
11125
|
+
}, j = r(async () => [`说明: ${c}`, "格式: 写入值需为 JSON,且通过声明的 schema 校验(校验失败时 set_data/edit_data 会返回结构化错误,含具体字段与期望类型)。"].join("\n"), {
|
|
11123
11126
|
name: "describe_data",
|
|
11124
11127
|
description: "获取主数据的说明与格式要求。",
|
|
11125
11128
|
schema: t.object({})
|
|
11126
|
-
}),
|
|
11129
|
+
}), te = r(async ({ jsonPath: e }, t) => {
|
|
11127
11130
|
let n = v(t), r = e || "";
|
|
11128
11131
|
if (vd(r)) return $({
|
|
11129
11132
|
code: "PATH_UNSAFE",
|
|
@@ -11143,13 +11146,13 @@ function kg(e, n = {}) {
|
|
|
11143
11146
|
resourceStore: p.resourceStore
|
|
11144
11147
|
}));
|
|
11145
11148
|
let a = kd(s);
|
|
11146
|
-
return b(a, n), i === void 0 ? `主数据${r ? ` @ ${r}` : ""} = (undefined) (hash=${a})` : (i = wg(i, n === "",
|
|
11149
|
+
return b(a, n), i === void 0 ? `主数据${r ? ` @ ${r}` : ""} = (undefined) (hash=${a})` : (i = wg(i, n === "", w, C), `主数据${r ? ` @ ${r}` : ""} = ${Dd(i)} (hash=${a})`);
|
|
11147
11150
|
}, {
|
|
11148
11151
|
name: "get_data",
|
|
11149
11152
|
description: "@deprecated(改用 read,等价且支持 fields/depth/分页)。读取主数据当前值(返回含 hash 供乐观锁);jsonPath 可选读子路径。大结果自动外存 vfs。",
|
|
11150
11153
|
schema: t.object({ jsonPath: t.string().optional().describe("相对主数据根的点号路径(如 components.0.text);不传则读整个主数据") })
|
|
11151
|
-
}),
|
|
11152
|
-
let r = v(n), i = await
|
|
11154
|
+
}), M = r(async ({ value: e, expectedHash: t }, n) => {
|
|
11155
|
+
let r = v(n), i = await A("set", t || (S ? y(r) : void 0));
|
|
11153
11156
|
if (i !== null) return i;
|
|
11154
11157
|
let c = wd(e);
|
|
11155
11158
|
if (c.parseError) return Nl("", e, c.parseError);
|
|
@@ -11160,8 +11163,8 @@ function kg(e, n = {}) {
|
|
|
11160
11163
|
allowKeys: l,
|
|
11161
11164
|
snapshots: m,
|
|
11162
11165
|
maxSnapshots: h,
|
|
11163
|
-
audit:
|
|
11164
|
-
onWrite:
|
|
11166
|
+
audit: O,
|
|
11167
|
+
onWrite: E,
|
|
11165
11168
|
internalAfterWrite: a,
|
|
11166
11169
|
protectedCtx: p
|
|
11167
11170
|
});
|
|
@@ -11174,8 +11177,8 @@ function kg(e, n = {}) {
|
|
|
11174
11177
|
expectedHash: t.string().optional().describe("乐观锁:改前 read/get 返回的 hash;传入则校验,不一致拒绝写入防覆盖。不传则自动用你最后读到的 hash(autoLock)")
|
|
11175
11178
|
})
|
|
11176
11179
|
});
|
|
11177
|
-
|
|
11178
|
-
let
|
|
11180
|
+
ee(M);
|
|
11181
|
+
let ne = r(async (e, t) => {
|
|
11179
11182
|
let n = v(t), r = e.op ?? e.patch?.op, i = e.jsonPath ?? e.patch?.jsonPath, c = e.value ?? e.patch?.value, u = e.expectedHash;
|
|
11180
11183
|
if (!r) return $({
|
|
11181
11184
|
code: "MISSING_VALUE",
|
|
@@ -11193,7 +11196,7 @@ function kg(e, n = {}) {
|
|
|
11193
11196
|
message: `edit_data @ "${d}" 不在 schema 声明字段内`,
|
|
11194
11197
|
hint: "仅 schema 声明的 key 可写;若需操作该字段,集成方需在 schema 中声明它"
|
|
11195
11198
|
});
|
|
11196
|
-
let f = await
|
|
11199
|
+
let f = await A("edit", u || (S ? y(n) : void 0));
|
|
11197
11200
|
if (f !== null) return f;
|
|
11198
11201
|
if (typeof s != "object" || !s) return $({
|
|
11199
11202
|
code: "NOT_OBJECT",
|
|
@@ -11211,19 +11214,21 @@ function kg(e, n = {}) {
|
|
|
11211
11214
|
allowKeys: l,
|
|
11212
11215
|
snapshots: m,
|
|
11213
11216
|
maxSnapshots: h,
|
|
11214
|
-
markDataDirty:
|
|
11217
|
+
markDataDirty: E,
|
|
11215
11218
|
schemaErrorMode: "zod",
|
|
11216
11219
|
internalAfterWrite: a,
|
|
11217
11220
|
protectedCtx: p
|
|
11218
11221
|
});
|
|
11219
11222
|
if (!g.ok) return g.error;
|
|
11220
11223
|
let _ = g.applied[0];
|
|
11221
|
-
|
|
11224
|
+
O({
|
|
11222
11225
|
op: "edit",
|
|
11223
11226
|
detail: `${_.op}${d ? "@" + d : ""}`,
|
|
11224
11227
|
value: _.value,
|
|
11225
11228
|
timestamp: Date.now()
|
|
11226
|
-
})
|
|
11229
|
+
});
|
|
11230
|
+
let b = x(n);
|
|
11231
|
+
return `已 edit 主数据(${_.op}${d ? " @ " + d : ""})。当前值:${Dd(s, 600)} (新 hash=${b})`;
|
|
11227
11232
|
}, {
|
|
11228
11233
|
name: "edit_data",
|
|
11229
11234
|
description: "增量编辑主数据(advanced;simple 用 write 等价)。op:set/remove/merge/append/move;jsonPath 相对根(数组索引用数字);value 对象或 JSON 字符串。schema 校验失败不写;expectedHash 可选乐观锁。大对象优先增量改。",
|
|
@@ -11250,8 +11255,8 @@ function kg(e, n = {}) {
|
|
|
11250
11255
|
}).optional().describe("容错:误传 write 的 {patch:{op,jsonPath,value}} 形式时从此取值(顶层优先)。正常用顶层 op/jsonPath/value 即可")
|
|
11251
11256
|
})
|
|
11252
11257
|
});
|
|
11253
|
-
|
|
11254
|
-
let
|
|
11258
|
+
ee(ne);
|
|
11259
|
+
let N = r(async ({ jsonPath: e, expectedHash: t }, n) => {
|
|
11255
11260
|
let r = v(n);
|
|
11256
11261
|
if (!e) return $({
|
|
11257
11262
|
code: "MISSING_VALUE",
|
|
@@ -11276,11 +11281,11 @@ function kg(e, n = {}) {
|
|
|
11276
11281
|
hint: t.spec.mode === "freeze" ? "冻结字段不可删;如需移除请联系集成方调整 data.resources" : "verbatim 字段不可直接删;先 resource_delete({path}) 释放资源保护后再删"
|
|
11277
11282
|
});
|
|
11278
11283
|
}
|
|
11279
|
-
let i = await
|
|
11284
|
+
let i = await A("delete", t || (S ? y(r) : void 0));
|
|
11280
11285
|
if (i !== null) return i;
|
|
11281
|
-
|
|
11286
|
+
k("delete");
|
|
11282
11287
|
let a = Sd(s, e);
|
|
11283
|
-
return
|
|
11288
|
+
return E(), O({
|
|
11284
11289
|
op: "delete",
|
|
11285
11290
|
detail: e,
|
|
11286
11291
|
timestamp: Date.now()
|
|
@@ -11293,8 +11298,8 @@ function kg(e, n = {}) {
|
|
|
11293
11298
|
expectedHash: t.string().optional().describe("乐观锁:改前 read/get 返回的 hash;传入则校验,不一致拒绝删除防覆盖")
|
|
11294
11299
|
})
|
|
11295
11300
|
});
|
|
11296
|
-
|
|
11297
|
-
let
|
|
11301
|
+
ee(N);
|
|
11302
|
+
let P = r(async ({ id: e }, t) => {
|
|
11298
11303
|
let n = v(t);
|
|
11299
11304
|
if (!m.length) return $({
|
|
11300
11305
|
code: "NO_SNAPSHOT",
|
|
@@ -11308,7 +11313,7 @@ function kg(e, n = {}) {
|
|
|
11308
11313
|
hint: "用 history_data({list:true}) 查看可用快照序号"
|
|
11309
11314
|
});
|
|
11310
11315
|
let i = o.safeParse(r.value);
|
|
11311
|
-
return i.success ? (Pd(s, Cd(r.value)),
|
|
11316
|
+
return i.success ? (Pd(s, Cd(r.value)), E(), O({
|
|
11312
11317
|
op: "restore",
|
|
11313
11318
|
detail: `#${r.id}`,
|
|
11314
11319
|
timestamp: Date.now()
|
|
@@ -11323,8 +11328,8 @@ function kg(e, n = {}) {
|
|
|
11323
11328
|
description: "把主数据回退到某个快照(就地还原,保留响应式)。不传 id 则回退最近一次(快速回退)。可用 history_data({list:true}) 查看快照列表。",
|
|
11324
11329
|
schema: t.object({ id: t.number().int().optional().describe("指定快照序号;不传则回退最近一次") })
|
|
11325
11330
|
});
|
|
11326
|
-
|
|
11327
|
-
let
|
|
11331
|
+
ee(P);
|
|
11332
|
+
let re = r(async ({ id: e, jsonPath: t, list: n }) => {
|
|
11328
11333
|
if (n) {
|
|
11329
11334
|
if (!m.length) return "无快照。set/edit/delete 会自动存快照。";
|
|
11330
11335
|
let e = m.map((e) => {
|
|
@@ -11369,7 +11374,7 @@ function kg(e, n = {}) {
|
|
|
11369
11374
|
jsonPath: t.string().optional().describe("只看快照的某子路径(相对主数据根);不传则整个快照"),
|
|
11370
11375
|
list: t.boolean().optional().describe("true 则列出快照时间线元信息(序号/操作/标签/时间/大小);不传则查看单条快照内容")
|
|
11371
11376
|
})
|
|
11372
|
-
}),
|
|
11377
|
+
}), F = r(async ({ expr: e, limit: t }, n) => {
|
|
11373
11378
|
let r = v(n);
|
|
11374
11379
|
if (typeof s != "object" || !s) return $({
|
|
11375
11380
|
code: "NOT_OBJECT",
|
|
@@ -11387,7 +11392,7 @@ function kg(e, n = {}) {
|
|
|
11387
11392
|
details: { expr: e }
|
|
11388
11393
|
});
|
|
11389
11394
|
}
|
|
11390
|
-
let c = t ?? 50, u = a.slice(0, c), d = u.map((e) => `{"path":${JSON.stringify(e.path)},"index":${e.index === void 0 ? "null" : e.index},"value":${Dd(wg(e.value, r === "",
|
|
11395
|
+
let c = t ?? 50, u = a.slice(0, c), d = u.map((e) => `{"path":${JSON.stringify(e.path)},"index":${e.index === void 0 ? "null" : e.index},"value":${Dd(wg(e.value, r === "", w, C))}}`);
|
|
11391
11396
|
return `{"matched":${a.length},"returned":${u.length},"truncated":${a.length > c},"results":[${d.join(",")}]}`;
|
|
11392
11397
|
}, {
|
|
11393
11398
|
name: "query_data",
|
|
@@ -11396,7 +11401,7 @@ function kg(e, n = {}) {
|
|
|
11396
11401
|
expr: t.string().describe("JSONPath 表达式,如 $.components[?(@.type==\"card\" && @.price<100)] 或 $..title(递归找所有 title)"),
|
|
11397
11402
|
limit: t.number().int().min(1).max(200).optional().describe("返回结果上限,默认 50")
|
|
11398
11403
|
})
|
|
11399
|
-
}),
|
|
11404
|
+
}), I = r(async ({ query: e, mode: t, fuzzyThreshold: n, matchKey: r, limit: i }) => {
|
|
11400
11405
|
if (s == null) return $({
|
|
11401
11406
|
code: "EMPTY",
|
|
11402
11407
|
message: "主数据为空,无可搜索内容"
|
|
@@ -11434,7 +11439,7 @@ function kg(e, n = {}) {
|
|
|
11434
11439
|
matchKey: t.boolean().optional().describe("是否同时匹配 key 名,默认 true"),
|
|
11435
11440
|
limit: t.number().int().min(1).max(200).optional().describe("返回上限,默认 50")
|
|
11436
11441
|
})
|
|
11437
|
-
}),
|
|
11442
|
+
}), ie = r(async ({ script: e, mode: t, jsonPath: n }, r) => {
|
|
11438
11443
|
let i = v(r);
|
|
11439
11444
|
if (e.length > 8e3) return $({
|
|
11440
11445
|
code: "SCRIPT_TOO_LARGE",
|
|
@@ -11480,13 +11485,13 @@ function kg(e, n = {}) {
|
|
|
11480
11485
|
allowKeys: l,
|
|
11481
11486
|
snapshots: m,
|
|
11482
11487
|
maxSnapshots: h,
|
|
11483
|
-
markDataDirty:
|
|
11488
|
+
markDataDirty: E,
|
|
11484
11489
|
schemaErrorMode: "schema_invalid",
|
|
11485
11490
|
snapshotLabel: "eval_transform_subtree",
|
|
11486
11491
|
internalAfterWrite: a,
|
|
11487
11492
|
protectedCtx: p
|
|
11488
11493
|
});
|
|
11489
|
-
return t.ok ? (
|
|
11494
|
+
return t.ok ? (O({
|
|
11490
11495
|
op: "edit",
|
|
11491
11496
|
detail: `eval_transform_subtree @ ${c}`,
|
|
11492
11497
|
timestamp: Date.now()
|
|
@@ -11505,13 +11510,13 @@ function kg(e, n = {}) {
|
|
|
11505
11510
|
allowKeys: l,
|
|
11506
11511
|
snapshots: m,
|
|
11507
11512
|
maxSnapshots: h,
|
|
11508
|
-
markDataDirty:
|
|
11513
|
+
markDataDirty: E,
|
|
11509
11514
|
schemaErrorMode: "schema_invalid",
|
|
11510
11515
|
snapshotLabel: "eval_transform",
|
|
11511
11516
|
internalAfterWrite: a,
|
|
11512
11517
|
protectedCtx: p
|
|
11513
11518
|
});
|
|
11514
|
-
return t.ok ? (
|
|
11519
|
+
return t.ok ? (O({
|
|
11515
11520
|
op: "edit",
|
|
11516
11521
|
detail: `eval_transform(${t.applied.length} patches)`,
|
|
11517
11522
|
timestamp: Date.now()
|
|
@@ -11531,7 +11536,7 @@ function kg(e, n = {}) {
|
|
|
11531
11536
|
code: "LEAF_BIND",
|
|
11532
11537
|
message: `主数据 bind 为原始类型(${s === null ? "null" : typeof s}),eval transform 无法就地替换外部持有的值引用`,
|
|
11533
11538
|
hint: "主数据 bind 必须为对象/数组;叶子值请用对象包裹或集成方通过 sdk.setData 替换 bind"
|
|
11534
|
-
}) : (
|
|
11539
|
+
}) : (k("edit", "eval_transform"), n.data !== null && typeof n.data == "object" && (l ? yd(s, n.data) : Fd(s, n.data)), E(), O({
|
|
11535
11540
|
op: "edit",
|
|
11536
11541
|
detail: "eval_transform",
|
|
11537
11542
|
timestamp: Date.now()
|
|
@@ -11556,8 +11561,8 @@ function kg(e, n = {}) {
|
|
|
11556
11561
|
jsonPath: t.string().optional().describe("子树模式:仅对 jsonPath 指向的子树执行(降低大 JSON 成本);transform 时返回值作为该子树新值")
|
|
11557
11562
|
})
|
|
11558
11563
|
});
|
|
11559
|
-
|
|
11560
|
-
let
|
|
11564
|
+
ee(ie, (e) => e?.mode === "transform");
|
|
11565
|
+
let L = r(async ({ jsonPath: e, jsonPaths: t, fields: r, depth: i, offset: a, limit: u }, d) => {
|
|
11561
11566
|
let f = v(d), m = kd(s);
|
|
11562
11567
|
if (t && t.length) {
|
|
11563
11568
|
let e = !1, a = t.map((t) => {
|
|
@@ -11581,7 +11586,7 @@ function kg(e, n = {}) {
|
|
|
11581
11586
|
} catch (e) {
|
|
11582
11587
|
return `- ${a}: [READ_INTERCEPT: ${e.message}]`;
|
|
11583
11588
|
}
|
|
11584
|
-
return r && r.length && (u = Td(u, r)), i != null && (u = Ed(u, i)), u = wg(u, f === "",
|
|
11589
|
+
return r && r.length && (u = Td(u, r)), i != null && (u = Ed(u, i)), u = wg(u, f === "", w, C), u === void 0 ? `- ${a} = (undefined)` : `- ${a} = ${Dd(u)}`;
|
|
11585
11590
|
});
|
|
11586
11591
|
return e && b(m, f), `多路径读取(共 ${t.length} 项,hash=${m}):\n${a.join("\n")}`;
|
|
11587
11592
|
}
|
|
@@ -11616,8 +11621,8 @@ function kg(e, n = {}) {
|
|
|
11616
11621
|
message: `read 拦截器抛错: ${e.message}`
|
|
11617
11622
|
});
|
|
11618
11623
|
}
|
|
11619
|
-
b(m, f), r && r.length && (_ = Td(_, r)), i != null && (_ = Ed(_, i)), _ = wg(_, f === "",
|
|
11620
|
-
let y = e ? "" : `主数据说明: ${c}\n格式: 写入值需为 JSON,且通过声明的 schema 校验(校验失败时 write 会返回结构化错误)。字段约束(类型/min/max/enum/必填/默认)见 systemPrompt「可操作数据」段,或用 schema_data({ jsonPath }) 按需查。\n\n`, x = r && r.length ? `(字段裁剪:${r.join(",")})` : "",
|
|
11624
|
+
b(m, f), r && r.length && (_ = Td(_, r)), i != null && (_ = Ed(_, i)), _ = wg(_, f === "", w, C);
|
|
11625
|
+
let y = e ? "" : `主数据说明: ${c}\n格式: 写入值需为 JSON,且通过声明的 schema 校验(校验失败时 write 会返回结构化错误)。字段约束(类型/min/max/enum/必填/默认)见 systemPrompt「可操作数据」段,或用 schema_data({ jsonPath }) 按需查。\n\n`, x = r && r.length ? `(字段裁剪:${r.join(",")})` : "", S = i == null ? "" : `(深度≤${i})`, T = x || S ? ` ${x}${S}` : "";
|
|
11621
11626
|
if ((a !== void 0 || u !== void 0) && Array.isArray(_)) {
|
|
11622
11627
|
let e = _.length, t = Math.max(0, a ?? 0), n = Math.min(200, Math.max(1, u ?? 50)), r = _.slice(t, t + n), i = t + n < e;
|
|
11623
11628
|
return `${y}主数据${h ? ` @ ${h}` : ""} 数组分页[offset=${t},limit=${n}]${T} = ${Dd(r)} (total=${e}, hasMore=${i}) (hash=${m})`;
|
|
@@ -11634,7 +11639,7 @@ function kg(e, n = {}) {
|
|
|
11634
11639
|
offset: t.number().int().min(0).optional().describe("数组分页起始偏移(仅当读取目标是数组时生效,默认 0),配合 limit 分页读大数组"),
|
|
11635
11640
|
limit: t.number().int().min(1).max(200).optional().describe("数组分页每页条数(默认 50,上限 200;仅数组时生效),返回切片 + total/hasMore")
|
|
11636
11641
|
})
|
|
11637
|
-
}),
|
|
11642
|
+
}), R = r(async ({ value: e, patch: t, patches: r, del: i, dryRun: c }, u) => {
|
|
11638
11643
|
let d = v(u), f = "set";
|
|
11639
11644
|
i ? f = "delete" : (r && r.length || t) && (f = "edit");
|
|
11640
11645
|
let g = t?.value === void 0 ? e : t.value, _;
|
|
@@ -11663,12 +11668,12 @@ function kg(e, n = {}) {
|
|
|
11663
11668
|
message: `write 拦截器抛错: ${e.message}`
|
|
11664
11669
|
});
|
|
11665
11670
|
}
|
|
11666
|
-
let
|
|
11667
|
-
if (c &&
|
|
11671
|
+
let C = S ? y(d) : void 0;
|
|
11672
|
+
if (c && C !== void 0) {
|
|
11668
11673
|
let e = kd(s);
|
|
11669
|
-
if (e !==
|
|
11674
|
+
if (e !== C) return $({
|
|
11670
11675
|
code: "VERSION_CONFLICT",
|
|
11671
|
-
message: `dryRun 预检发现乐观锁冲突: expectedHash=${
|
|
11676
|
+
message: `dryRun 预检发现乐观锁冲突: expectedHash=${C} 当前 hash=${e}(主数据在你 read 后被改)`,
|
|
11672
11677
|
hint: "重新 read 拿最新 hash 再预检/写"
|
|
11673
11678
|
});
|
|
11674
11679
|
}
|
|
@@ -11696,19 +11701,19 @@ function kg(e, n = {}) {
|
|
|
11696
11701
|
hint: e.spec.mode === "freeze" ? "冻结字段不可删" : "verbatim 字段不可直接删;先 resource_delete 释放"
|
|
11697
11702
|
});
|
|
11698
11703
|
}
|
|
11699
|
-
let e = await
|
|
11704
|
+
let e = await A("delete", C);
|
|
11700
11705
|
if (e !== null) return e;
|
|
11701
11706
|
if (c) {
|
|
11702
11707
|
let e = Cd(s);
|
|
11703
11708
|
return Sd(e, t.jsonPath) ? `dryRun(delete): 将删除 @ ${t.jsonPath}。预览剩余:${Dd(e, 600)}。未实际写入、未入快照。` : `dryRun(delete): @ ${t.jsonPath} 不存在(无需删除)。未实际写入。`;
|
|
11704
11709
|
}
|
|
11705
|
-
|
|
11710
|
+
k("delete");
|
|
11706
11711
|
let n = Sd(s, t.jsonPath);
|
|
11707
|
-
return
|
|
11712
|
+
return E(), O({
|
|
11708
11713
|
op: "delete",
|
|
11709
11714
|
detail: t.jsonPath,
|
|
11710
11715
|
timestamp: Date.now()
|
|
11711
|
-
}), a && (a(s, null),
|
|
11716
|
+
}), a && (a(s, null), E()), b(kd(s), d), n ? `已删除主数据 @ ${t.jsonPath}` : `主数据 @ ${t.jsonPath} 不存在(无需删除)`;
|
|
11712
11717
|
}
|
|
11713
11718
|
if (f === "edit") {
|
|
11714
11719
|
if (typeof s != "object" || !s) return $({
|
|
@@ -11716,7 +11721,7 @@ function kg(e, n = {}) {
|
|
|
11716
11721
|
message: `edit 仅适用于对象/数组主数据,当前是 ${s === void 0 ? "undefined" : typeof s}`,
|
|
11717
11722
|
hint: "叶子用 write(value) 整体设置"
|
|
11718
11723
|
});
|
|
11719
|
-
let e = await
|
|
11724
|
+
let e = await A("edit", C);
|
|
11720
11725
|
if (e !== null) return e;
|
|
11721
11726
|
let n = _ || (r && r.length ? r : [{
|
|
11722
11727
|
op: t.op ?? "set",
|
|
@@ -11729,40 +11734,44 @@ function kg(e, n = {}) {
|
|
|
11729
11734
|
allowKeys: l,
|
|
11730
11735
|
snapshots: m,
|
|
11731
11736
|
maxSnapshots: h,
|
|
11732
|
-
markDataDirty:
|
|
11737
|
+
markDataDirty: E,
|
|
11733
11738
|
schemaErrorMode: "zod",
|
|
11734
11739
|
dryRun: c,
|
|
11735
11740
|
internalAfterWrite: a,
|
|
11736
11741
|
protectedCtx: p
|
|
11737
11742
|
});
|
|
11738
|
-
|
|
11743
|
+
if (!i.ok) return i.error;
|
|
11744
|
+
if (c) return `dryRun(edit): ${i.applied.length} 个 patch 预检通过(schema 校验 OK)。预览结果:${Dd(i.clone, 600)}。未实际写入、未入快照。`;
|
|
11745
|
+
O({
|
|
11739
11746
|
op: "edit",
|
|
11740
11747
|
detail: `${i.applied.length} 个 patch${i.applied.length > 1 ? "(批量)" : ""}`,
|
|
11741
11748
|
value: i.applied.map((e) => `${e.op}@${e.jp}`),
|
|
11742
11749
|
timestamp: Date.now()
|
|
11743
|
-
})
|
|
11744
|
-
|
|
11745
|
-
|
|
11746
|
-
|
|
11747
|
-
let w =
|
|
11748
|
-
if (w
|
|
11749
|
-
let
|
|
11750
|
+
});
|
|
11751
|
+
let u = x(d);
|
|
11752
|
+
return Og(i.clone), `已 write(edit) 主数据(${i.applied.length} 个 patch)。当前值:${Dd(i.clone, 600)} (新 hash=${u})`;
|
|
11753
|
+
}
|
|
11754
|
+
let w = wd(g);
|
|
11755
|
+
if (w.parseError) return Nl("", g, w.parseError);
|
|
11756
|
+
let T = await A("set", C);
|
|
11757
|
+
if (T !== null) return T;
|
|
11758
|
+
let D = xg({
|
|
11750
11759
|
bindRef: s,
|
|
11751
|
-
value:
|
|
11760
|
+
value: w.parsed,
|
|
11752
11761
|
schema: o,
|
|
11753
11762
|
allowKeys: l,
|
|
11754
11763
|
snapshots: m,
|
|
11755
11764
|
maxSnapshots: h,
|
|
11756
|
-
audit:
|
|
11765
|
+
audit: O,
|
|
11757
11766
|
dryRun: c,
|
|
11758
|
-
onWrite:
|
|
11767
|
+
onWrite: E,
|
|
11759
11768
|
internalAfterWrite: a,
|
|
11760
11769
|
protectedCtx: p
|
|
11761
11770
|
});
|
|
11762
|
-
if (!
|
|
11763
|
-
if (c) return `dryRun(set): schema 校验通过。预览新值:${Dd(
|
|
11764
|
-
let
|
|
11765
|
-
return b(
|
|
11771
|
+
if (!D.ok) return D.error;
|
|
11772
|
+
if (c) return `dryRun(set): schema 校验通过。预览新值:${Dd(D.data, 600)}。未实际写入、未入快照。`;
|
|
11773
|
+
let ee = kd(s);
|
|
11774
|
+
return b(ee, d), Og(D.data), `已 write(set) 主数据 = ${Dd(D.data, 600)} (新 hash=${ee})${l ? "(白名单模式:仅更新 schema 声明字段,未声明字段保留)" : ""}`;
|
|
11766
11775
|
}, {
|
|
11767
11776
|
name: "write",
|
|
11768
11777
|
description: "写入主数据(高层入口,合并 set/edit/delete + 自动乐观锁 + 自动快照)。四意图:① 整体替换 write({value:整个对象});② 增量 write({patch:{op,jsonPath,value}}) op=set/remove/merge/append/move(move 的 value=目标路径字符串);③ 批量原子 write({patches:[...]})(任一失败整批回滚);④ 删子路径 write({patch:{jsonPath},del:true})。dryRun:true 预检不落盘。写入自动 schema 校验(失败不写,按错误修正重试)+ 自动快照。详细用法见系统提示「能力使用提示」。",
|
|
@@ -11794,8 +11803,8 @@ function kg(e, n = {}) {
|
|
|
11794
11803
|
dryRun: t.boolean().optional().describe("预检模式:走完整校验链(schema + 白名单 + patch 应用到 clone)但不落盘、不入快照,返回预览。四意图(value/patch/patches/del)均支持;乐观锁冲突照常检测(返回 VERSION_CONFLICT 不挂起)")
|
|
11795
11804
|
})
|
|
11796
11805
|
});
|
|
11797
|
-
|
|
11798
|
-
let
|
|
11806
|
+
ee(R);
|
|
11807
|
+
let z = r(async ({ jsonPath: e }) => {
|
|
11799
11808
|
let t = e || "", n = t ? Fu(o, t) : o;
|
|
11800
11809
|
return n ? `schema${t ? ` @ ${t}` : ""} = ${Dd(Ju(n))}` : $({
|
|
11801
11810
|
code: "PATH_DENIED",
|
|
@@ -11806,7 +11815,7 @@ function kg(e, n = {}) {
|
|
|
11806
11815
|
name: "schema_data",
|
|
11807
11816
|
description: "查看主数据(或子路径)的字段约束:类型/min/max/enum/必填/默认值/嵌套 shape。写前查约束,避免写错重试。不传 jsonPath 查根;传子路径(如 components.0)查该位置约束。",
|
|
11808
11817
|
schema: t.object({ jsonPath: t.string().optional().describe("要查约束的子路径;不传查根 schema") })
|
|
11809
|
-
}),
|
|
11818
|
+
}), B = r(async ({ snapshotId: e, against: t }) => {
|
|
11810
11819
|
let n = t != null, r, i;
|
|
11811
11820
|
if (n) {
|
|
11812
11821
|
let e = t;
|
|
@@ -11838,7 +11847,7 @@ function kg(e, n = {}) {
|
|
|
11838
11847
|
snapshotId: t.number().int().optional().describe("对比的快照序号;不传则最近一次"),
|
|
11839
11848
|
against: t.unknown().optional().describe("对比的一段 JSON 值(与 snapshotId 互斥;传则忽略快照)")
|
|
11840
11849
|
})
|
|
11841
|
-
}),
|
|
11850
|
+
}), ae = [];
|
|
11842
11851
|
if (n.vfsStore) {
|
|
11843
11852
|
let e = n.vfsStore, i = (e) => `drafts/${e}.json`, c = r(({ draftId: t, chunk: n, mode: r }) => {
|
|
11844
11853
|
let a = i(t), o = e.files[a], s = r === "append" && o, c = s ? o.content + n : n;
|
|
@@ -11879,7 +11888,7 @@ function kg(e, n = {}) {
|
|
|
11879
11888
|
}
|
|
11880
11889
|
});
|
|
11881
11890
|
}
|
|
11882
|
-
let g = await
|
|
11891
|
+
let g = await A("set", n || (S ? y(c) : void 0));
|
|
11883
11892
|
if (g !== null) return g;
|
|
11884
11893
|
let _ = xg({
|
|
11885
11894
|
bindRef: s,
|
|
@@ -11888,9 +11897,9 @@ function kg(e, n = {}) {
|
|
|
11888
11897
|
allowKeys: l,
|
|
11889
11898
|
snapshots: m,
|
|
11890
11899
|
maxSnapshots: h,
|
|
11891
|
-
audit:
|
|
11900
|
+
audit: O,
|
|
11892
11901
|
op: "draft_commit",
|
|
11893
|
-
onWrite:
|
|
11902
|
+
onWrite: E,
|
|
11894
11903
|
internalAfterWrite: a,
|
|
11895
11904
|
protectedCtx: p
|
|
11896
11905
|
});
|
|
@@ -11903,9 +11912,9 @@ function kg(e, n = {}) {
|
|
|
11903
11912
|
expectedHash: t.string().optional().describe("乐观锁:改前 read/get 返回的 hash;传入则校验,不一致拒绝写入防覆盖。不传则自动用你最后读到的 hash(autoLock)")
|
|
11904
11913
|
})
|
|
11905
11914
|
});
|
|
11906
|
-
|
|
11915
|
+
ee(u), ae.push(c, u);
|
|
11907
11916
|
}
|
|
11908
|
-
let
|
|
11917
|
+
let V = [];
|
|
11909
11918
|
if (e.resources?.length && d) {
|
|
11910
11919
|
let e = r(async ({ path: e, handle: t }) => {
|
|
11911
11920
|
let n = e;
|
|
@@ -11975,7 +11984,7 @@ function kg(e, n = {}) {
|
|
|
11975
11984
|
details: jl(n.error.issues)
|
|
11976
11985
|
});
|
|
11977
11986
|
}
|
|
11978
|
-
d.update(i, t), xd(s, i, t), b(kd(s), r),
|
|
11987
|
+
d.update(i, t), xd(s, i, t), b(kd(s), r), E();
|
|
11979
11988
|
let l = d.get(i)?.handle;
|
|
11980
11989
|
return `已更新 verbatim 资源 "${e}" = ${Dd(t, 200)}(handle ${l ?? "(未知)"} 不变)。后续 write 该字段写回句柄 ⟦res:${l}⟧ 或新值`;
|
|
11981
11990
|
}, {
|
|
@@ -11986,7 +11995,7 @@ function kg(e, n = {}) {
|
|
|
11986
11995
|
value: t.unknown().describe("新值(需符合字段 schema 类型)")
|
|
11987
11996
|
})
|
|
11988
11997
|
});
|
|
11989
|
-
|
|
11998
|
+
ee(n);
|
|
11990
11999
|
let i = r(async () => {
|
|
11991
12000
|
let e = d.list();
|
|
11992
12001
|
return e.length ? Dd({ resources: e }) : "当前无已注册的受保护资源(read 受保护路径会懒注册)";
|
|
@@ -12009,10 +12018,9 @@ function kg(e, n = {}) {
|
|
|
12009
12018
|
handle: t.string().optional().describe("占位符句柄(与 path 二选一)")
|
|
12010
12019
|
})
|
|
12011
12020
|
});
|
|
12012
|
-
|
|
12021
|
+
ee(a), V.push(e, n, i, a);
|
|
12013
12022
|
}
|
|
12014
|
-
let
|
|
12015
|
-
ee,
|
|
12023
|
+
let oe = [
|
|
12016
12024
|
j,
|
|
12017
12025
|
te,
|
|
12018
12026
|
M,
|
|
@@ -12026,21 +12034,22 @@ function kg(e, n = {}) {
|
|
|
12026
12034
|
L,
|
|
12027
12035
|
R,
|
|
12028
12036
|
z,
|
|
12029
|
-
|
|
12030
|
-
...ae
|
|
12037
|
+
B,
|
|
12038
|
+
...ae,
|
|
12039
|
+
...V
|
|
12031
12040
|
];
|
|
12032
|
-
Object.defineProperty(
|
|
12033
|
-
value:
|
|
12041
|
+
Object.defineProperty(oe, "controller", {
|
|
12042
|
+
value: D,
|
|
12034
12043
|
enumerable: !1,
|
|
12035
12044
|
configurable: !1,
|
|
12036
12045
|
writable: !1
|
|
12037
12046
|
});
|
|
12038
|
-
for (let e of
|
|
12047
|
+
for (let e of oe) Object.defineProperty(e, "__dataOpsScoped", {
|
|
12039
12048
|
value: !0,
|
|
12040
12049
|
enumerable: !1,
|
|
12041
12050
|
configurable: !1
|
|
12042
12051
|
});
|
|
12043
|
-
return
|
|
12052
|
+
return oe;
|
|
12044
12053
|
}
|
|
12045
12054
|
//#endregion
|
|
12046
12055
|
//#region src/core/tools/fetchDoc.ts
|