page-agent-sdk 3.19.0 → 3.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/README.zh-CN.md +3 -3
- package/dist/page-agent-sdk.headless.js +803 -768
- package/dist/page-agent-sdk.iife.js +91 -91
- package/dist/page-agent-sdk.js +100 -61
- package/dist/page-agent-sdk.umd.cjs +9 -9
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/dist/page-agent-sdk.js
CHANGED
|
@@ -5005,15 +5005,18 @@ function ku(e) {
|
|
|
5005
5005
|
status: "error"
|
|
5006
5006
|
};
|
|
5007
5007
|
try {
|
|
5008
|
-
let n =
|
|
5009
|
-
|
|
5008
|
+
let n = {
|
|
5009
|
+
__pgDataScope: "",
|
|
5010
|
+
...e.callConfig ?? {}
|
|
5011
|
+
}, r = await t.invoke(e.args, { configurable: n }), i = typeof r == "string" ? r : JSON.stringify(r);
|
|
5012
|
+
return i = zl(i, {
|
|
5010
5013
|
files: e.state.files,
|
|
5011
5014
|
vfsAvailable: ce.some((e) => e.name === "vfs_read"),
|
|
5012
5015
|
toolName: e.name,
|
|
5013
5016
|
threshold: ne,
|
|
5014
5017
|
passThroughChars: I
|
|
5015
5018
|
}).content, {
|
|
5016
|
-
content:
|
|
5019
|
+
content: i,
|
|
5017
5020
|
status: "done"
|
|
5018
5021
|
};
|
|
5019
5022
|
} catch (e) {
|
|
@@ -7303,12 +7306,12 @@ function up(e, t) {
|
|
|
7303
7306
|
return t.some((t) => e === t || e.startsWith(t + ".") || e.startsWith(t + "["));
|
|
7304
7307
|
}
|
|
7305
7308
|
function dp(e, t) {
|
|
7306
|
-
let n = e.invoke.bind(e), r = async (e) => {
|
|
7309
|
+
let n = e.invoke.bind(e), r = async (e, r) => {
|
|
7307
7310
|
if (Array.isArray(e?.patches) && e.patches.some((e) => !e || typeof e.jsonPath != "string" || !e.jsonPath)) return `PATH_OUT_OF_SCOPE:patches 含无 jsonPath 项(作用于根),子 agent 仅可写 ${t.join(", ")} 范围内子路径。请为每个 patch 指定 jsonPath。`;
|
|
7308
|
-
let
|
|
7309
|
-
if (!
|
|
7310
|
-
for (let e of
|
|
7311
|
-
return n(e);
|
|
7311
|
+
let i = lp(e);
|
|
7312
|
+
if (!i.length) return `PATH_OUT_OF_SCOPE:子 agent 仅可增量 patch(writablePaths: ${t.join(", ")}),不能整体替换(无 jsonPath)。用 write({patch:{jsonPath,...}}) 增量改。`;
|
|
7313
|
+
for (let e of i) if (!up(e, t)) return `PATH_OUT_OF_SCOPE:子 agent 写 "${e}" 越界(仅可写 ${t.join(", ")})。`;
|
|
7314
|
+
return r === void 0 ? n(e) : n(e, r);
|
|
7312
7315
|
};
|
|
7313
7316
|
return new Proxy(e, { get(e, t, n) {
|
|
7314
7317
|
return t === "invoke" ? r : Reflect.get(e, t, n);
|
|
@@ -11057,7 +11060,7 @@ function Cg(e, n = {}) {
|
|
|
11057
11060
|
resourceStore: p.resourceStore
|
|
11058
11061
|
}));
|
|
11059
11062
|
let a = Dd(s);
|
|
11060
|
-
return b(a, n), i === void 0 ? `主数据${r ? ` @ ${r}` : ""} = (undefined) (hash=${a})` : `主数据${r ? ` @ ${r}` : ""} = ${Td(i)} (hash=${a})
|
|
11063
|
+
return b(a, n), i === void 0 ? `主数据${r ? ` @ ${r}` : ""} = (undefined) (hash=${a})` : (i = vg(i, n === "", C, S), `主数据${r ? ` @ ${r}` : ""} = ${Td(i)} (hash=${a})`);
|
|
11061
11064
|
}, {
|
|
11062
11065
|
name: "get_data",
|
|
11063
11066
|
description: "@deprecated(改用 read,等价且支持 fields/depth/分页)。读取主数据当前值(返回含 hash 供乐观锁);jsonPath 可选读子路径。大结果自动外存 vfs。",
|
|
@@ -11283,15 +11286,16 @@ function Cg(e, n = {}) {
|
|
|
11283
11286
|
jsonPath: t.string().optional().describe("只看快照的某子路径(相对主数据根);不传则整个快照"),
|
|
11284
11287
|
list: t.boolean().optional().describe("true 则列出快照时间线元信息(序号/操作/标签/时间/大小);不传则查看单条快照内容")
|
|
11285
11288
|
})
|
|
11286
|
-
}), ne = r(async ({ expr: e, limit: t }) => {
|
|
11289
|
+
}), ne = r(async ({ expr: e, limit: t }, n) => {
|
|
11290
|
+
let r = v(n);
|
|
11287
11291
|
if (typeof s != "object" || !s) return $({
|
|
11288
11292
|
code: "NOT_OBJECT",
|
|
11289
11293
|
message: `主数据不是对象/数组,无法查询(当前为 ${s === void 0 ? "undefined" : typeof s})`,
|
|
11290
11294
|
hint: "query 仅适用于对象/数组;叶子用 get_data 读"
|
|
11291
11295
|
});
|
|
11292
|
-
let
|
|
11296
|
+
let i = l ? zu(s, o) : s, a;
|
|
11293
11297
|
try {
|
|
11294
|
-
|
|
11298
|
+
a = Uh(i, e);
|
|
11295
11299
|
} catch (t) {
|
|
11296
11300
|
return $({
|
|
11297
11301
|
code: "JSONPATH_SYNTAX",
|
|
@@ -11300,8 +11304,8 @@ function Cg(e, n = {}) {
|
|
|
11300
11304
|
details: { expr: e }
|
|
11301
11305
|
});
|
|
11302
11306
|
}
|
|
11303
|
-
let
|
|
11304
|
-
return `{"matched":${
|
|
11307
|
+
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":${Td(vg(e.value, r === "", C, S))}}`);
|
|
11308
|
+
return `{"matched":${a.length},"returned":${u.length},"truncated":${a.length > c},"results":[${d.join(",")}]}`;
|
|
11305
11309
|
}, {
|
|
11306
11310
|
name: "query_data",
|
|
11307
11311
|
description: "用 JSONPath 查询主数据(只读):$ 根/.key/[n]/[*]/[?(==/!=/</<=/>/>=,&&/||)]/..key 递归。返回匹配元素 path/index/value(path 可作 write patch 的 jsonPath);大数组筛选定位用它。",
|
|
@@ -11472,30 +11476,31 @@ function Cg(e, n = {}) {
|
|
|
11472
11476
|
A(L, (e) => e?.mode === "transform");
|
|
11473
11477
|
let re = r(async ({ jsonPath: e, jsonPaths: t, fields: r, depth: i, offset: a, limit: u }, d) => {
|
|
11474
11478
|
let f = v(d), m = Dd(s);
|
|
11475
|
-
if (
|
|
11476
|
-
let e = t.map((
|
|
11477
|
-
let
|
|
11478
|
-
if (!ju(
|
|
11479
|
-
|
|
11480
|
-
|
|
11479
|
+
if (t && t.length) {
|
|
11480
|
+
let e = !1, a = t.map((t) => {
|
|
11481
|
+
let a = t || "";
|
|
11482
|
+
if (!ju(a, o, l)) return `- ${a || "(根)"}: [PATH_DENIED: 不在 schema 声明字段内]`;
|
|
11483
|
+
e = !0;
|
|
11484
|
+
let c = a ? vd(s, a) : s;
|
|
11485
|
+
if (!a && l) c = zu(c, o);
|
|
11481
11486
|
else if (l) {
|
|
11482
|
-
let e = Nu(o,
|
|
11483
|
-
e && (
|
|
11487
|
+
let e = Nu(o, a);
|
|
11488
|
+
e && (c = zu(c, e));
|
|
11484
11489
|
}
|
|
11485
|
-
let
|
|
11486
|
-
if (p && (
|
|
11487
|
-
jp:
|
|
11488
|
-
resolved:
|
|
11490
|
+
let u = c;
|
|
11491
|
+
if (p && (u = ag({
|
|
11492
|
+
jp: a,
|
|
11493
|
+
resolved: u,
|
|
11489
11494
|
resourcesByPath: p.resourcesByPath,
|
|
11490
11495
|
resourceStore: p.resourceStore
|
|
11491
11496
|
})), n.interceptors?.read) try {
|
|
11492
|
-
|
|
11497
|
+
u = n.interceptors.read(u);
|
|
11493
11498
|
} catch (e) {
|
|
11494
|
-
return `- ${
|
|
11499
|
+
return `- ${a}: [READ_INTERCEPT: ${e.message}]`;
|
|
11495
11500
|
}
|
|
11496
|
-
return r && r.length && (
|
|
11501
|
+
return r && r.length && (u = Cd(u, r)), i != null && (u = wd(u, i)), u = vg(u, f === "", C, S), u === void 0 ? `- ${a} = (undefined)` : `- ${a} = ${Td(u)}`;
|
|
11497
11502
|
});
|
|
11498
|
-
return `多路径读取(共 ${t.length} 项,hash=${m}):\n${
|
|
11503
|
+
return e && b(m, f), `多路径读取(共 ${t.length} 项,hash=${m}):\n${a.join("\n")}`;
|
|
11499
11504
|
}
|
|
11500
11505
|
let h = e || "";
|
|
11501
11506
|
if (gd(h)) return $({
|
|
@@ -11528,7 +11533,7 @@ function Cg(e, n = {}) {
|
|
|
11528
11533
|
message: `read 拦截器抛错: ${e.message}`
|
|
11529
11534
|
});
|
|
11530
11535
|
}
|
|
11531
|
-
r && r.length && (_ = Cd(_, r)), i != null && (_ = wd(_, i)), _ = vg(_, f === "", C, S);
|
|
11536
|
+
b(m, f), r && r.length && (_ = Cd(_, r)), i != null && (_ = wd(_, i)), _ = vg(_, f === "", C, S);
|
|
11532
11537
|
let y = e ? "" : `主数据说明: ${c}\n格式: 写入值需为 JSON,且通过声明的 schema 校验(校验失败时 write 会返回结构化错误)。字段约束(类型/min/max/enum/必填/默认)见 systemPrompt「可操作数据」段,或用 schema_data({ jsonPath }) 按需查。\n\n`, x = r && r.length ? `(字段裁剪:${r.join(",")})` : "", w = i == null ? "" : `(深度≤${i})`, T = x || w ? ` ${x}${w}` : "";
|
|
11533
11538
|
if ((a !== void 0 || u !== void 0) && Array.isArray(_)) {
|
|
11534
11539
|
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;
|
|
@@ -12428,7 +12433,7 @@ function f_(e, n) {
|
|
|
12428
12433
|
e.debug && !l && console.warn("[page-agent-sdk][summarization] 未构造 llmInvoke(apiKey 缺失?),摘要回退零成本索引摘要");
|
|
12429
12434
|
let v = /* @__PURE__ */ ln([]), y = Xp(e.vfs?.initialFiles, {
|
|
12430
12435
|
persist: s ? { save: (e) => {
|
|
12431
|
-
|
|
12436
|
+
It({ vfs: e });
|
|
12432
12437
|
} } : void 0,
|
|
12433
12438
|
maxBytes: e.vfs?.maxBytes,
|
|
12434
12439
|
poolBytes: e.vfs?.poolBytes
|
|
@@ -12816,10 +12821,12 @@ function f_(e, n) {
|
|
|
12816
12821
|
}
|
|
12817
12822
|
let wt = a_(), Tt = /* @__PURE__ */ new Set();
|
|
12818
12823
|
function Et(e) {
|
|
12819
|
-
let t = new AbortController();
|
|
12820
|
-
return e && (e.aborted ? t.abort() : e.addEventListener("abort",
|
|
12824
|
+
let t = new AbortController(), n = () => t.abort();
|
|
12825
|
+
return e && (e.aborted ? t.abort() : e.addEventListener("abort", n, { once: !0 })), Tt.add(t), {
|
|
12821
12826
|
controller: t,
|
|
12822
|
-
untrack: () =>
|
|
12827
|
+
untrack: () => {
|
|
12828
|
+
Tt.delete(t), e?.removeEventListener("abort", n);
|
|
12829
|
+
}
|
|
12823
12830
|
};
|
|
12824
12831
|
}
|
|
12825
12832
|
function Dt() {
|
|
@@ -12900,16 +12907,17 @@ function f_(e, n) {
|
|
|
12900
12907
|
};
|
|
12901
12908
|
},
|
|
12902
12909
|
afterRound() {
|
|
12903
|
-
Mt(),
|
|
12910
|
+
Mt(), Rt();
|
|
12904
12911
|
},
|
|
12905
12912
|
async send(e, t) {
|
|
12906
|
-
await G.initDone,
|
|
12913
|
+
if (await G.initDone, G.refCount <= 0) throw Error("page-agent-sdk: agent 已释放(unmount),拒绝排队中的 send");
|
|
12914
|
+
t ??= {}, t?.mission && je && x.setMission(t.mission);
|
|
12907
12915
|
let n = e;
|
|
12908
12916
|
if (t.interceptors?.input) try {
|
|
12909
12917
|
let r = t.interceptors.input(e);
|
|
12910
12918
|
typeof r == "string" && (n = r);
|
|
12911
12919
|
} catch {}
|
|
12912
|
-
let r = oe ? t.maxAutoRetries ?? 1 : 0, i = 0, a = !1, o = xt(t.signal);
|
|
12920
|
+
let r = oe ? t.maxAutoRetries ?? 1 : 0, i = 0, a = !1, o = xt(t.signal), c = G.sessionId;
|
|
12913
12921
|
for (;;) {
|
|
12914
12922
|
a ||= (v.push({
|
|
12915
12923
|
role: "user",
|
|
@@ -12918,6 +12926,16 @@ function f_(e, n) {
|
|
|
12918
12926
|
}), !0);
|
|
12919
12927
|
try {
|
|
12920
12928
|
let e = await G.agent.invoke(v, t.signal, o);
|
|
12929
|
+
if (t.signal?.aborted || G.sessionId !== c || G.refCount <= 0) return G.agent?.debugLogs?.value?.push({
|
|
12930
|
+
timestamp: Date.now(),
|
|
12931
|
+
type: "middleware",
|
|
12932
|
+
data: {
|
|
12933
|
+
stage: "orphan_round_dropped",
|
|
12934
|
+
fromSession: c,
|
|
12935
|
+
aborted: !!t.signal?.aborted,
|
|
12936
|
+
sessionChanged: G.sessionId !== c
|
|
12937
|
+
}
|
|
12938
|
+
}), e;
|
|
12921
12939
|
if (t.interceptors?.output) try {
|
|
12922
12940
|
let n = t.interceptors.output(e);
|
|
12923
12941
|
typeof n == "string" && (e = n);
|
|
@@ -12955,6 +12973,7 @@ function f_(e, n) {
|
|
|
12955
12973
|
},
|
|
12956
12974
|
async batch(e, t, n) {
|
|
12957
12975
|
if (await G.initDone, !e.length) return [];
|
|
12976
|
+
if (G.refCount <= 0) throw Error("page-agent-sdk: agent 已释放(unmount),拒绝排队中的 batch");
|
|
12958
12977
|
let r = [], i = xt(n);
|
|
12959
12978
|
for (let a = 0; a < e.length; a++) {
|
|
12960
12979
|
if (n?.aborted) {
|
|
@@ -13037,15 +13056,15 @@ function f_(e, n) {
|
|
|
13037
13056
|
if (a.resolve("keep_external"), G.sessionId && s) {
|
|
13038
13057
|
if (je) {
|
|
13039
13058
|
let e = x.getMission();
|
|
13040
|
-
e &&
|
|
13059
|
+
e && It({ mission: e });
|
|
13041
13060
|
}
|
|
13042
13061
|
if (Me) {
|
|
13043
13062
|
let e = T.getWorkingMemory();
|
|
13044
|
-
e &&
|
|
13063
|
+
e && It({ workingMemory: e });
|
|
13045
13064
|
}
|
|
13046
13065
|
if (be) {
|
|
13047
13066
|
let e = w.getFocuses();
|
|
13048
|
-
|
|
13067
|
+
It({ focus: e.length ? e : null });
|
|
13049
13068
|
}
|
|
13050
13069
|
}
|
|
13051
13070
|
y.flush?.(), await s.flush();
|
|
@@ -13054,7 +13073,7 @@ function f_(e, n) {
|
|
|
13054
13073
|
type: "session_restored",
|
|
13055
13074
|
sessionId: r,
|
|
13056
13075
|
rounds: i.messages?.length ?? 0
|
|
13057
|
-
})), e.memory &&
|
|
13076
|
+
})), e.memory && It({ memory: E.get() || (typeof e.memory == "string" ? e.memory : "") }), Ct(), Nt = void 0, Pt = !1, G.infoTick.value++, r;
|
|
13058
13077
|
},
|
|
13059
13078
|
resetSession: () => {
|
|
13060
13079
|
Dt(), a.resolve("keep_external"), G.sessionId = $m(), v.splice(0, v.length), y.clear?.(), b.reset([]), e.memory || E.reset(""), x.reset(), T.reset(), w.reset(), L && L.importStack([]), G.agent && (G.agent.debugLogs.value = []), s && s.createSession(G.agentId, e.session?.title, G.sessionId).catch((t) => {
|
|
@@ -13285,7 +13304,7 @@ function f_(e, n) {
|
|
|
13285
13304
|
}), e.debug && console.log("[page-agent-sdk][restore] 恢复会话", G.sessionId, `${t.messages?.length ?? 0} msgs`)) : e.debug && console.log("[page-agent-sdk][restore] 会话 meta 存在但快照为空", G.sessionId);
|
|
13286
13305
|
} else G.sessionId = await s.createSession(n, t.title), e.debug && console.log("[page-agent-sdk][restore] 新建会话(无历史)", G.sessionId);
|
|
13287
13306
|
} else G.sessionId = await s.createSession(n, t.title);
|
|
13288
|
-
e.memory &&
|
|
13307
|
+
e.memory && It({ memory: E.get() || (typeof e.memory == "string" ? e.memory : "") }), Ct();
|
|
13289
13308
|
}
|
|
13290
13309
|
async function kt() {
|
|
13291
13310
|
await mt();
|
|
@@ -13323,45 +13342,61 @@ function f_(e, n) {
|
|
|
13323
13342
|
try {
|
|
13324
13343
|
let e = await l(Uf(t, g)), i = v.indexOf(n);
|
|
13325
13344
|
if (i < 0) return;
|
|
13326
|
-
v[i].content = Lf(t, r, e),
|
|
13345
|
+
v[i].content = Lf(t, r, e), Rt();
|
|
13327
13346
|
} catch {}
|
|
13328
13347
|
})();
|
|
13329
13348
|
}
|
|
13330
13349
|
}
|
|
13331
13350
|
let Nt, Pt = !1;
|
|
13332
|
-
function Ft(t) {
|
|
13333
|
-
|
|
13334
|
-
|
|
13351
|
+
function Ft(t, n) {
|
|
13352
|
+
e.debug && console.warn(`[page-agent-sdk][persist] ${t} 失败(已吞):`, n);
|
|
13353
|
+
let r = G.agent?.debugLogs;
|
|
13354
|
+
r && r.value.push({
|
|
13355
|
+
timestamp: Date.now(),
|
|
13356
|
+
type: "middleware",
|
|
13357
|
+
data: {
|
|
13358
|
+
stage: "persist_save_failed",
|
|
13359
|
+
kind: t,
|
|
13360
|
+
error: String(n).slice(0, 160)
|
|
13361
|
+
}
|
|
13335
13362
|
});
|
|
13336
13363
|
}
|
|
13337
|
-
function It(
|
|
13338
|
-
s
|
|
13339
|
-
|
|
13340
|
-
|
|
13364
|
+
function It(e) {
|
|
13365
|
+
!G.sessionId || !s || s.save(n, G.sessionId, e).catch((e) => Ft("save", e));
|
|
13366
|
+
}
|
|
13367
|
+
function Lt(e, t) {
|
|
13368
|
+
s && s.updateTitle(n, e, t).catch((e) => Ft("updateTitle", e));
|
|
13341
13369
|
}
|
|
13342
|
-
function
|
|
13370
|
+
function Rt() {
|
|
13343
13371
|
if (!G.sessionId || !s) return;
|
|
13344
|
-
if (
|
|
13372
|
+
if (It({ messages: JSON.parse(JSON.stringify(v)) }), It({ todos: G.agent?.getState?.()?.todos ?? [] }), je) {
|
|
13345
13373
|
let e = x.getMission();
|
|
13346
|
-
e &&
|
|
13374
|
+
e && It({ mission: e });
|
|
13347
13375
|
}
|
|
13348
13376
|
if (Me) {
|
|
13349
13377
|
let e = T.getWorkingMemory();
|
|
13350
|
-
e &&
|
|
13378
|
+
e && It({ workingMemory: e });
|
|
13351
13379
|
}
|
|
13352
13380
|
if (be) {
|
|
13353
13381
|
let e = w.getFocuses();
|
|
13354
|
-
|
|
13382
|
+
It({ focus: e.length ? e : null });
|
|
13355
13383
|
}
|
|
13356
|
-
oe && L && (
|
|
13384
|
+
oe && L && (It({ checkpoints: L.exportStack() }), It({ usage: i }));
|
|
13357
13385
|
let t = Vm(v);
|
|
13358
|
-
if (t && t !== Nt && (Nt = t,
|
|
13386
|
+
if (t && t !== Nt && (Nt = t, Lt(G.sessionId, t)), e.autoTitle !== !1 && u && !Pt && v.some((e) => e.role === "user") && v.some((e) => e.role === "assistant")) {
|
|
13359
13387
|
Pt = !0;
|
|
13360
13388
|
let e = G.sessionId;
|
|
13361
13389
|
(async () => {
|
|
13362
13390
|
try {
|
|
13363
13391
|
let t = await u(v);
|
|
13364
|
-
t && G.refCount > 0 && G.sessionId === e
|
|
13392
|
+
if (t && G.refCount > 0 && G.sessionId === e) {
|
|
13393
|
+
try {
|
|
13394
|
+
await s.updateTitle(n, e, t);
|
|
13395
|
+
} catch (e) {
|
|
13396
|
+
Ft("updateTitle", e);
|
|
13397
|
+
}
|
|
13398
|
+
await Ct();
|
|
13399
|
+
}
|
|
13365
13400
|
} catch {}
|
|
13366
13401
|
})();
|
|
13367
13402
|
}
|
|
@@ -15232,7 +15267,11 @@ var Yv = ["innerHTML"], Xv = {
|
|
|
15232
15267
|
has: (e) => s.has(`${l}:${e}`),
|
|
15233
15268
|
toggle: (e) => {
|
|
15234
15269
|
let t = `${l}:${e}`;
|
|
15235
|
-
s.has(t)
|
|
15270
|
+
if (s.has(t)) s.delete(t);
|
|
15271
|
+
else {
|
|
15272
|
+
for (let e of Array.from(s)) e.startsWith(`${l}:`) && s.delete(e);
|
|
15273
|
+
s.add(t);
|
|
15274
|
+
}
|
|
15236
15275
|
}
|
|
15237
15276
|
};
|
|
15238
15277
|
function d(e) {
|
|
@@ -15340,7 +15379,7 @@ var Yv = ["innerHTML"], Xv = {
|
|
|
15340
15379
|
], 2))), 128))])) : Q("", !0)
|
|
15341
15380
|
], 2))), 128))])) : Q("", !0);
|
|
15342
15381
|
}
|
|
15343
|
-
}), [["__scopeId", "data-v-
|
|
15382
|
+
}), [["__scopeId", "data-v-558ca64f"]]);
|
|
15344
15383
|
//#endregion
|
|
15345
15384
|
//#region node_modules/marked/lib/marked.esm.js
|
|
15346
15385
|
function $y() {
|