page-agent-sdk 2.38.0 → 2.38.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/README.zh-CN.md +3 -3
- package/dist/page-agent-sdk.headless.js +101 -86
- package/dist/page-agent-sdk.iife.js +7 -7
- package/dist/page-agent-sdk.js +532 -517
- package/dist/page-agent-sdk.umd.cjs +15 -15
- package/package.json +2 -1
- package/types/headless.d.ts +8 -2
- package/types/index.d.ts +8 -2
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
[](https://www.npmjs.com/package/page-agent-sdk)
|
|
10
10
|
[](https://github.com/whyymj/page-agent-sdk/blob/master/LICENSE)
|
|
11
|
-
[](#self-tests)
|
|
12
12
|
|
|
13
13
|
---
|
|
14
14
|
|
package/README.zh-CN.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
[](https://www.npmjs.com/package/page-agent-sdk)
|
|
10
10
|
[](https://github.com/whyymj/page-agent-sdk/blob/master/LICENSE)
|
|
11
|
-
[](#自测)
|
|
12
12
|
|
|
13
13
|
---
|
|
14
14
|
|
|
@@ -472,8 +472,8 @@ function switchTo(i: number) {
|
|
|
472
472
|
## 自测
|
|
473
473
|
|
|
474
474
|
```bash
|
|
475
|
-
npm test #
|
|
476
|
-
npm run test:e2e #
|
|
475
|
+
npm test # 1669 项断言(tsx 源码级,不依赖 LLM)
|
|
476
|
+
npm run test:e2e # 453 项集成断言(node 跑构建产物 dist;覆盖各 API/配置项/功能模块/简单与复杂场景:默认 systemPrompt(含能力概述) / 动态注册与 inspect 同步 / inspect(tools/middleware/subagent/verify/mcp/todos/lastCompression/checkpoints 反映配置) / 自定义 tools/middleware/skills/memory 注入 / 运行时动态重配置(setTools/addTool/removeTool/setLlm/setMemory/setSubagents 反映) / switchSession(开/未开) / shareContext 开/关共享独立 / storage 后端+对象配置 / presets 三预设 / checkpoint / 导出项完整(39+ 函数/组件) / 工具函数可用(isQuotaError/estimateTokens/jpEval/searchJson) / source=builtin / mount 边界 / hook 多监听器 / llm 配置 / 错误场景)
|
|
477
477
|
```
|
|
478
478
|
|
|
479
479
|
## 本地 npm 包测试
|
|
@@ -417,61 +417,61 @@ var Ue = {
|
|
|
417
417
|
return We(this, "entries", (e) => (e[1] = He(this, e[1]), e));
|
|
418
418
|
},
|
|
419
419
|
every(e, t) {
|
|
420
|
-
return
|
|
420
|
+
return H(this, "every", e, t, void 0, arguments);
|
|
421
421
|
},
|
|
422
422
|
filter(e, t) {
|
|
423
|
-
return
|
|
423
|
+
return H(this, "filter", e, t, (e) => e.map((e) => He(this, e)), arguments);
|
|
424
424
|
},
|
|
425
425
|
find(e, t) {
|
|
426
|
-
return
|
|
426
|
+
return H(this, "find", e, t, (e) => He(this, e), arguments);
|
|
427
427
|
},
|
|
428
428
|
findIndex(e, t) {
|
|
429
|
-
return
|
|
429
|
+
return H(this, "findIndex", e, t, void 0, arguments);
|
|
430
430
|
},
|
|
431
431
|
findLast(e, t) {
|
|
432
|
-
return
|
|
432
|
+
return H(this, "findLast", e, t, (e) => He(this, e), arguments);
|
|
433
433
|
},
|
|
434
434
|
findLastIndex(e, t) {
|
|
435
|
-
return
|
|
435
|
+
return H(this, "findLastIndex", e, t, void 0, arguments);
|
|
436
436
|
},
|
|
437
437
|
forEach(e, t) {
|
|
438
|
-
return
|
|
438
|
+
return H(this, "forEach", e, t, void 0, arguments);
|
|
439
439
|
},
|
|
440
440
|
includes(...e) {
|
|
441
|
-
return
|
|
441
|
+
return U(this, "includes", e);
|
|
442
442
|
},
|
|
443
443
|
indexOf(...e) {
|
|
444
|
-
return
|
|
444
|
+
return U(this, "indexOf", e);
|
|
445
445
|
},
|
|
446
446
|
join(e) {
|
|
447
447
|
return Be(this).join(e);
|
|
448
448
|
},
|
|
449
449
|
lastIndexOf(...e) {
|
|
450
|
-
return
|
|
450
|
+
return U(this, "lastIndexOf", e);
|
|
451
451
|
},
|
|
452
452
|
map(e, t) {
|
|
453
|
-
return
|
|
453
|
+
return H(this, "map", e, t, void 0, arguments);
|
|
454
454
|
},
|
|
455
455
|
pop() {
|
|
456
|
-
return
|
|
456
|
+
return qe(this, "pop");
|
|
457
457
|
},
|
|
458
458
|
push(...e) {
|
|
459
|
-
return
|
|
459
|
+
return qe(this, "push", e);
|
|
460
460
|
},
|
|
461
461
|
reduce(e, ...t) {
|
|
462
|
-
return
|
|
462
|
+
return Ke(this, "reduce", e, t);
|
|
463
463
|
},
|
|
464
464
|
reduceRight(e, ...t) {
|
|
465
|
-
return
|
|
465
|
+
return Ke(this, "reduceRight", e, t);
|
|
466
466
|
},
|
|
467
467
|
shift() {
|
|
468
|
-
return
|
|
468
|
+
return qe(this, "shift");
|
|
469
469
|
},
|
|
470
470
|
some(e, t) {
|
|
471
|
-
return
|
|
471
|
+
return H(this, "some", e, t, void 0, arguments);
|
|
472
472
|
},
|
|
473
473
|
splice(...e) {
|
|
474
|
-
return
|
|
474
|
+
return qe(this, "splice", e);
|
|
475
475
|
},
|
|
476
476
|
toReversed() {
|
|
477
477
|
return Be(this).toReversed();
|
|
@@ -483,7 +483,7 @@ var Ue = {
|
|
|
483
483
|
return Be(this).toSpliced(...e);
|
|
484
484
|
},
|
|
485
485
|
unshift(...e) {
|
|
486
|
-
return
|
|
486
|
+
return qe(this, "unshift", e);
|
|
487
487
|
},
|
|
488
488
|
values() {
|
|
489
489
|
return We(this, "values", (e) => He(this, e));
|
|
@@ -497,7 +497,7 @@ function We(e, t, n) {
|
|
|
497
497
|
}), i;
|
|
498
498
|
}
|
|
499
499
|
var Ge = Array.prototype;
|
|
500
|
-
function
|
|
500
|
+
function H(e, t, n, r, i, a) {
|
|
501
501
|
let o = Ve(e), s = o !== e && !/* @__PURE__ */ Ct(e), c = o[t];
|
|
502
502
|
if (c !== Ge[t]) {
|
|
503
503
|
let t = c.apply(e, a);
|
|
@@ -512,7 +512,7 @@ function Ke(e, t, n, r, i, a) {
|
|
|
512
512
|
let u = c.call(o, l, r);
|
|
513
513
|
return s && i ? i(u) : u;
|
|
514
514
|
}
|
|
515
|
-
function
|
|
515
|
+
function Ke(e, t, n, r) {
|
|
516
516
|
let i = Ve(e), a = i !== e && !/* @__PURE__ */ Ct(e), o = n, s = !1;
|
|
517
517
|
i !== e && (a ? (s = r.length === 0, o = function(t, r, i) {
|
|
518
518
|
return s && (s = !1, t = He(e, t)), n.call(this, t, He(e, r), i, e);
|
|
@@ -522,13 +522,13 @@ function H(e, t, n, r) {
|
|
|
522
522
|
let c = i[t](o, ...r);
|
|
523
523
|
return s ? He(e, c) : c;
|
|
524
524
|
}
|
|
525
|
-
function
|
|
525
|
+
function U(e, t, n) {
|
|
526
526
|
let r = /* @__PURE__ */ G(e);
|
|
527
527
|
V(r, "iterate", Re);
|
|
528
528
|
let i = r[t](...n);
|
|
529
529
|
return (i === -1 || i === !1) && /* @__PURE__ */ wt(n[0]) ? (n[0] = /* @__PURE__ */ G(n[0]), r[t](...n)) : i;
|
|
530
530
|
}
|
|
531
|
-
function
|
|
531
|
+
function qe(e, t, n = []) {
|
|
532
532
|
Oe(), ye();
|
|
533
533
|
let r = (/* @__PURE__ */ G(e))[t].apply(e, n);
|
|
534
534
|
return B(), ke(), r;
|
|
@@ -598,10 +598,10 @@ var Ze = class {
|
|
|
598
598
|
deleteProperty(e, t) {
|
|
599
599
|
return process.env.NODE_ENV !== "production" && de(`Delete operation on key "${String(t)}" failed: target is readonly.`, e), !0;
|
|
600
600
|
}
|
|
601
|
-
}, et = /* @__PURE__ */ new Qe(), tt = /* @__PURE__ */ new $e(), nt = /* @__PURE__ */ new $e(!0),
|
|
601
|
+
}, et = /* @__PURE__ */ new Qe(), tt = /* @__PURE__ */ new $e(), nt = /* @__PURE__ */ new $e(!0), W = (e) => e, rt = (e) => Reflect.getPrototypeOf(e);
|
|
602
602
|
function it(e, t, n) {
|
|
603
603
|
return function(...r) {
|
|
604
|
-
let i = this.__v_raw, a = /* @__PURE__ */ G(i), o = E(a), s = e === "entries" || e === Symbol.iterator && o, c = e === "keys" && o, l = i[e](...r), u = n ?
|
|
604
|
+
let i = this.__v_raw, a = /* @__PURE__ */ G(i), o = E(a), s = e === "entries" || e === Symbol.iterator && o, c = e === "keys" && o, l = i[e](...r), u = n ? W : t ? Dt : Et;
|
|
605
605
|
return !t && V(a, "iterate", c ? Le : Ie), x(Object.create(l), { next() {
|
|
606
606
|
let { value: e, done: t } = l.next();
|
|
607
607
|
return t ? {
|
|
@@ -628,7 +628,7 @@ function ot(e, t) {
|
|
|
628
628
|
get(n) {
|
|
629
629
|
let r = this.__v_raw, i = /* @__PURE__ */ G(r), a = /* @__PURE__ */ G(n);
|
|
630
630
|
e || (ie(n, a) && V(i, "get", n), V(i, "get", a));
|
|
631
|
-
let { has: o } =
|
|
631
|
+
let { has: o } = rt(i), s = t ? W : e ? Dt : Et;
|
|
632
632
|
if (o.call(i, n)) return s(r.get(n));
|
|
633
633
|
if (o.call(i, a)) return s(r.get(a));
|
|
634
634
|
r !== i && r.get(n);
|
|
@@ -642,7 +642,7 @@ function ot(e, t) {
|
|
|
642
642
|
return e || (ie(t, i) && V(r, "has", t), V(r, "has", i)), t === i ? n.has(t) : n.has(t) || n.has(i);
|
|
643
643
|
},
|
|
644
644
|
forEach(n, r) {
|
|
645
|
-
let i = this, a = i.__v_raw, o = /* @__PURE__ */ G(a), s = t ?
|
|
645
|
+
let i = this, a = i.__v_raw, o = /* @__PURE__ */ G(a), s = t ? W : e ? Dt : Et;
|
|
646
646
|
return !e && V(o, "iterate", Ie), a.forEach((e, t) => n.call(r, s(e), s(t), i));
|
|
647
647
|
}
|
|
648
648
|
};
|
|
@@ -653,18 +653,18 @@ function ot(e, t) {
|
|
|
653
653
|
clear: at("clear")
|
|
654
654
|
} : {
|
|
655
655
|
add(e) {
|
|
656
|
-
let n = /* @__PURE__ */ G(this), r =
|
|
656
|
+
let n = /* @__PURE__ */ G(this), r = rt(n), i = /* @__PURE__ */ G(e), a = !t && !/* @__PURE__ */ Ct(e) && !/* @__PURE__ */ St(e) ? i : e;
|
|
657
657
|
return r.has.call(n, a) || ie(e, a) && r.has.call(n, e) || ie(i, a) && r.has.call(n, i) || (n.add(a), ze(n, "add", a, a)), this;
|
|
658
658
|
},
|
|
659
659
|
set(e, n) {
|
|
660
660
|
!t && !/* @__PURE__ */ Ct(n) && !/* @__PURE__ */ St(n) && (n = /* @__PURE__ */ G(n));
|
|
661
|
-
let r = /* @__PURE__ */ G(this), { has: i, get: a } =
|
|
661
|
+
let r = /* @__PURE__ */ G(this), { has: i, get: a } = rt(r), o = i.call(r, e);
|
|
662
662
|
o ? process.env.NODE_ENV !== "production" && dt(r, i, e) : (e = /* @__PURE__ */ G(e), o = i.call(r, e));
|
|
663
663
|
let s = a.call(r, e);
|
|
664
664
|
return r.set(e, n), o ? ie(n, s) && ze(r, "set", e, n, s) : ze(r, "add", e, n), this;
|
|
665
665
|
},
|
|
666
666
|
delete(e) {
|
|
667
|
-
let t = /* @__PURE__ */ G(this), { has: n, get: r } =
|
|
667
|
+
let t = /* @__PURE__ */ G(this), { has: n, get: r } = rt(t), i = n.call(t, e);
|
|
668
668
|
i ? process.env.NODE_ENV !== "production" && dt(t, n, e) : (e = /* @__PURE__ */ G(e), i = n.call(t, e));
|
|
669
669
|
let a = r ? r.call(t, e) : void 0, o = t.delete(e);
|
|
670
670
|
return i && ze(t, "delete", e, void 0, a), o;
|
|
@@ -2769,8 +2769,10 @@ function Ni(e, t, n) {
|
|
|
2769
2769
|
let e = typeof r.shape == "function" ? r.shape() : r.shape;
|
|
2770
2770
|
if (!(t in e)) return !1;
|
|
2771
2771
|
r = e[t];
|
|
2772
|
-
} else if (r && (r._def?.type === "array" || r.constructor?.name === "ZodArray"))
|
|
2773
|
-
|
|
2772
|
+
} else if (r && (r._def?.type === "array" || r.constructor?.name === "ZodArray")) {
|
|
2773
|
+
if (!/^\d+$/.test(t)) return !1;
|
|
2774
|
+
r = r.element;
|
|
2775
|
+
} else if (r && (r._def?.type === "union" || r._def?.type === "discriminatedUnion" || Array.isArray(r.options))) return !0;
|
|
2774
2776
|
else return !1;
|
|
2775
2777
|
}
|
|
2776
2778
|
return !0;
|
|
@@ -2800,8 +2802,10 @@ function Fi(e, t) {
|
|
|
2800
2802
|
for (let e of r) {
|
|
2801
2803
|
if (!n) return null;
|
|
2802
2804
|
if (n = Pi(n), n && n.shape && typeof n.shape == "object") n = (typeof n.shape == "function" ? n.shape() : n.shape)[e];
|
|
2803
|
-
else if (n && (n._def?.type === "array" || n.constructor?.name === "ZodArray"))
|
|
2804
|
-
|
|
2805
|
+
else if (n && (n._def?.type === "array" || n.constructor?.name === "ZodArray")) {
|
|
2806
|
+
if (!/^\d+$/.test(e)) return null;
|
|
2807
|
+
n = n.element;
|
|
2808
|
+
} else if (n && (n._def?.type === "union" || n._def?.type === "discriminatedUnion" || Array.isArray(n.options))) return null;
|
|
2805
2809
|
else return null;
|
|
2806
2810
|
}
|
|
2807
2811
|
return n ?? null;
|
|
@@ -5296,7 +5300,11 @@ function Js(e) {
|
|
|
5296
5300
|
return {
|
|
5297
5301
|
async get(t) {
|
|
5298
5302
|
let n = e.getItem(t);
|
|
5299
|
-
|
|
5303
|
+
if (n != null) try {
|
|
5304
|
+
return JSON.parse(n);
|
|
5305
|
+
} catch {
|
|
5306
|
+
return;
|
|
5307
|
+
}
|
|
5300
5308
|
},
|
|
5301
5309
|
async set(t, n) {
|
|
5302
5310
|
e.setItem(t, JSON.stringify(n));
|
|
@@ -5313,7 +5321,14 @@ function Js(e) {
|
|
|
5313
5321
|
r.sort();
|
|
5314
5322
|
for (let t of r) {
|
|
5315
5323
|
let r = e.getItem(t);
|
|
5316
|
-
if (r
|
|
5324
|
+
if (r == null) continue;
|
|
5325
|
+
let i;
|
|
5326
|
+
try {
|
|
5327
|
+
i = JSON.parse(r);
|
|
5328
|
+
} catch {
|
|
5329
|
+
continue;
|
|
5330
|
+
}
|
|
5331
|
+
if (n(t, i) === !1) return;
|
|
5317
5332
|
}
|
|
5318
5333
|
},
|
|
5319
5334
|
async clearPrefix(t) {
|
|
@@ -8718,30 +8733,30 @@ function ou(e, n) {
|
|
|
8718
8733
|
return;
|
|
8719
8734
|
}
|
|
8720
8735
|
}
|
|
8721
|
-
} : null, Ge =
|
|
8736
|
+
} : null, Ge = tc(e.onEvent), H = Ge.emit, Ke, U = [], qe = (e) => ({
|
|
8722
8737
|
name: e.name,
|
|
8723
8738
|
description: e.description,
|
|
8724
8739
|
content: typeof e.getContent == "function" ? e.getContent() : ""
|
|
8725
|
-
}),
|
|
8740
|
+
}), Je = (e) => ({
|
|
8726
8741
|
name: e.name,
|
|
8727
8742
|
description: e.description,
|
|
8728
8743
|
getContent: () => e.content
|
|
8729
|
-
}),
|
|
8744
|
+
}), Ye = e.skillStorage === !1 ? null : Xl({
|
|
8730
8745
|
...typeof e.skillStorage == "object" ? e.skillStorage : {},
|
|
8731
8746
|
id: e.skillStorage && typeof e.skillStorage == "object" && e.skillStorage.id ? e.skillStorage.id : `agent::${n}`
|
|
8732
|
-
}),
|
|
8733
|
-
let t =
|
|
8747
|
+
}), Xe = () => {
|
|
8748
|
+
let t = Ke ? Ke.controller : null;
|
|
8734
8749
|
if (t) {
|
|
8735
8750
|
let n = (e.skills || []).filter((e) => !U.some((t) => t.name === e.name));
|
|
8736
8751
|
t.set([...n, ...U]);
|
|
8737
8752
|
}
|
|
8738
8753
|
W.infoTick.value++;
|
|
8739
|
-
},
|
|
8740
|
-
if (
|
|
8741
|
-
let t = await
|
|
8754
|
+
}, Ze = async () => {
|
|
8755
|
+
if (Ye) try {
|
|
8756
|
+
let t = await Ye.list();
|
|
8742
8757
|
if (t.length) {
|
|
8743
|
-
U = t.map(
|
|
8744
|
-
let n =
|
|
8758
|
+
U = t.map(Je);
|
|
8759
|
+
let n = Ke ? Ke.controller : null;
|
|
8745
8760
|
if (n) {
|
|
8746
8761
|
let t = (e.skills || []).filter((e) => !U.some((t) => t.name === e.name));
|
|
8747
8762
|
n.set([...t, ...U]);
|
|
@@ -8749,7 +8764,7 @@ function ou(e, n) {
|
|
|
8749
8764
|
W.infoTick.value++;
|
|
8750
8765
|
}
|
|
8751
8766
|
} catch {}
|
|
8752
|
-
},
|
|
8767
|
+
}, Qe = Ee ? yo({
|
|
8753
8768
|
...h,
|
|
8754
8769
|
llmInvoke: l,
|
|
8755
8770
|
getRegisteredData: () => F() ? [{ description: F().description ?? "主数据对象" }] : [],
|
|
@@ -8758,12 +8773,12 @@ function ou(e, n) {
|
|
|
8758
8773
|
decideInvoke: p,
|
|
8759
8774
|
getSnapshot: () => Ve?.getSnapshot()
|
|
8760
8775
|
} : {}
|
|
8761
|
-
}) : void 0,
|
|
8776
|
+
}) : void 0, $e = oc([
|
|
8762
8777
|
...Ue ? [Ue] : [],
|
|
8763
8778
|
He,
|
|
8764
8779
|
...Se ? [C] : [],
|
|
8765
8780
|
...xe ? [S] : [],
|
|
8766
|
-
...we ? [
|
|
8781
|
+
...we ? [Ke = Na(e.skills || [], {
|
|
8767
8782
|
readVfs: Te ? (e) => x.files[e]?.content : void 0,
|
|
8768
8783
|
hostScriptEnabled: j.skillHostScript,
|
|
8769
8784
|
onToolsReady: (e, t) => {
|
|
@@ -8775,7 +8790,7 @@ function ou(e, n) {
|
|
|
8775
8790
|
}
|
|
8776
8791
|
})] : [],
|
|
8777
8792
|
...Te ? [Pc(x)] : [],
|
|
8778
|
-
|
|
8793
|
+
...Qe ? [Qe] : [],
|
|
8779
8794
|
...Ce ? [T] : [],
|
|
8780
8795
|
...R ? [w] : [],
|
|
8781
8796
|
...se ? [se] : [],
|
|
@@ -8795,16 +8810,16 @@ function ou(e, n) {
|
|
|
8795
8810
|
timeBudgetMs: e.timeBudgetMs
|
|
8796
8811
|
}, H)] : [],
|
|
8797
8812
|
iu(H, b, F, i)
|
|
8798
|
-
]),
|
|
8799
|
-
async function
|
|
8800
|
-
s && (
|
|
8813
|
+
]), et = e.maxMemoryRounds ?? tu, tt = /* @__PURE__ */ Ot([]);
|
|
8814
|
+
async function nt() {
|
|
8815
|
+
s && (tt.value = (await s.listSessions(n)).sort((e, t) => t.lastAccessed - e.lastAccessed));
|
|
8801
8816
|
}
|
|
8802
8817
|
let W = {
|
|
8803
8818
|
agentId: n,
|
|
8804
8819
|
store: s,
|
|
8805
8820
|
messages: b,
|
|
8806
8821
|
vfsStore: x,
|
|
8807
|
-
listeners:
|
|
8822
|
+
listeners: Ge.listeners,
|
|
8808
8823
|
todosMw: S,
|
|
8809
8824
|
memoryMw: E,
|
|
8810
8825
|
missionMw: C,
|
|
@@ -8818,11 +8833,11 @@ function ou(e, n) {
|
|
|
8818
8833
|
mcpServers: [],
|
|
8819
8834
|
checkpoint: A,
|
|
8820
8835
|
dataOpsController: oe,
|
|
8821
|
-
skillsController:
|
|
8836
|
+
skillsController: Ke ? Ke.controller : null,
|
|
8822
8837
|
infoTick: o,
|
|
8823
8838
|
pendingConflict: a.pendingConflict,
|
|
8824
|
-
sessions:
|
|
8825
|
-
refreshSessions:
|
|
8839
|
+
sessions: tt,
|
|
8840
|
+
refreshSessions: nt,
|
|
8826
8841
|
liveData: F,
|
|
8827
8842
|
usage: i,
|
|
8828
8843
|
emit: H,
|
|
@@ -8848,15 +8863,15 @@ function ou(e, n) {
|
|
|
8848
8863
|
}
|
|
8849
8864
|
}
|
|
8850
8865
|
}
|
|
8851
|
-
|
|
8866
|
+
ot();
|
|
8852
8867
|
},
|
|
8853
8868
|
addSkill(e) {
|
|
8854
8869
|
let t = U.findIndex((t) => t.name === e.name);
|
|
8855
|
-
t >= 0 ? U[t] = e : U.push(e),
|
|
8870
|
+
t >= 0 ? U[t] = e : U.push(e), Xe(), Ye && Ye.put(qe(e));
|
|
8856
8871
|
},
|
|
8857
8872
|
removeSkill(e) {
|
|
8858
8873
|
let t = U.findIndex((t) => t.name === e);
|
|
8859
|
-
return t < 0 ? !1 : (U.splice(t, 1),
|
|
8874
|
+
return t < 0 ? !1 : (U.splice(t, 1), Xe(), Ye && Ye.remove(e), !0);
|
|
8860
8875
|
},
|
|
8861
8876
|
listUserSkills() {
|
|
8862
8877
|
return U.map((e) => e.name);
|
|
@@ -8870,7 +8885,7 @@ function ou(e, n) {
|
|
|
8870
8885
|
};
|
|
8871
8886
|
},
|
|
8872
8887
|
afterRound() {
|
|
8873
|
-
|
|
8888
|
+
st(), ut();
|
|
8874
8889
|
},
|
|
8875
8890
|
async send(e, t) {
|
|
8876
8891
|
await W.initDone, t ??= {}, t?.mission && Se && C.setMission(t.mission);
|
|
@@ -9000,21 +9015,21 @@ function ou(e, n) {
|
|
|
9000
9015
|
type: "session_restored",
|
|
9001
9016
|
sessionId: r,
|
|
9002
9017
|
rounds: i.messages?.length ?? 0
|
|
9003
|
-
})), e.memory && s.save(n, W.sessionId, { memory: E.get() || (typeof e.memory == "string" ? e.memory : "") }),
|
|
9018
|
+
})), e.memory && s.save(n, W.sessionId, { memory: E.get() || (typeof e.memory == "string" ? e.memory : "") }), nt(), ct = void 0, lt = !1, r;
|
|
9004
9019
|
},
|
|
9005
9020
|
resetSession: () => {
|
|
9006
9021
|
s && (W.sessionId = Es(), x.clear?.(), S.reset([]), e.memory || E.reset(""), C.reset(), T.reset(), w.reset(), A && A.importStack([]), W.agent && (W.agent.debugLogs.value = []), s.createSession(W.agentId, e.session?.title, W.sessionId), H({
|
|
9007
9022
|
type: "session_restored",
|
|
9008
9023
|
sessionId: W.sessionId,
|
|
9009
9024
|
rounds: 0
|
|
9010
|
-
}),
|
|
9025
|
+
}), nt(), ct = void 0, lt = !1);
|
|
9011
9026
|
},
|
|
9012
9027
|
stream: (e, t, n) => {
|
|
9013
9028
|
if (!W.agent) throw Error("page-agent-sdk: agent 尚未初始化完成,请先 await mount()");
|
|
9014
9029
|
x?.setProtectedRefs?.(Ql(e));
|
|
9015
|
-
let r =
|
|
9030
|
+
let r = (e) => {
|
|
9016
9031
|
t?.(e), H(e);
|
|
9017
|
-
}
|
|
9032
|
+
};
|
|
9018
9033
|
if (n) {
|
|
9019
9034
|
let e = () => a.resolve("keep_external");
|
|
9020
9035
|
n.aborted ? e() : n.addEventListener("abort", e, { once: !0 });
|
|
@@ -9023,7 +9038,7 @@ function ou(e, n) {
|
|
|
9023
9038
|
},
|
|
9024
9039
|
release() {
|
|
9025
9040
|
if (W.refCount--, W.refCount <= 0) {
|
|
9026
|
-
s && (x.flush?.(), s.flush(), s.dispose()),
|
|
9041
|
+
s && (x.flush?.(), s.flush(), s.dispose()), Ye && Ye.dispose();
|
|
9027
9042
|
let e = W.mcpClosers.splice(0);
|
|
9028
9043
|
e.length && Promise.allSettled(e.map((e) => e())), nu.delete(n);
|
|
9029
9044
|
}
|
|
@@ -9058,7 +9073,7 @@ function ou(e, n) {
|
|
|
9058
9073
|
contextWindow: e.contextWindow ?? r?.contextWindow,
|
|
9059
9074
|
maxOutputTokens: e.maxOutputTokens ?? r?.maxOutputTokens
|
|
9060
9075
|
}), m.contextWindow < 2e5) throw Error(`[page-agent-sdk][setLlm] 新模型上下文窗口 ${m.contextWindow} 小于最小支持 ${ti}(需 ≥200K 窗口模型)`);
|
|
9061
|
-
W.agent && (W.agent.setLlm(n), W.agent.setModelCaps?.(m)),
|
|
9076
|
+
W.agent && (W.agent.setLlm(n), W.agent.setModelCaps?.(m)), Qe?.setContextWindow?.(m.contextWindow), Ve?.setContextWindow?.(m.contextWindow), W.infoTick.value++, e.debug && console.log("[page-agent-sdk][setLlm] 重解析 modelCaps + 回灌:", m);
|
|
9062
9077
|
},
|
|
9063
9078
|
setMemory(e) {
|
|
9064
9079
|
E.reset(e), typeof e == "function" && E.refresh(), W.infoTick.value++;
|
|
@@ -9103,7 +9118,7 @@ function ou(e, n) {
|
|
|
9103
9118
|
schema: e.schema,
|
|
9104
9119
|
source: I.get(e.name) || "user"
|
|
9105
9120
|
})),
|
|
9106
|
-
skills: (
|
|
9121
|
+
skills: (Ke ? Ke.controller.get() : e.skills ?? []).map((e) => ({
|
|
9107
9122
|
name: e.name,
|
|
9108
9123
|
description: e.description
|
|
9109
9124
|
})),
|
|
@@ -9113,7 +9128,7 @@ function ou(e, n) {
|
|
|
9113
9128
|
} : void 0,
|
|
9114
9129
|
contextPreset: e.contextPreset ?? "auto",
|
|
9115
9130
|
memory: E.get(),
|
|
9116
|
-
middleware:
|
|
9131
|
+
middleware: $e.map((e) => e.name),
|
|
9117
9132
|
todos: (W.agent?.getState?.()?.todos ?? []).map((e) => ({
|
|
9118
9133
|
id: e.id,
|
|
9119
9134
|
content: e.content,
|
|
@@ -9198,7 +9213,7 @@ function ou(e, n) {
|
|
|
9198
9213
|
R && (w.clearFocus(), W.infoTick.value++);
|
|
9199
9214
|
}
|
|
9200
9215
|
};
|
|
9201
|
-
async function
|
|
9216
|
+
async function rt() {
|
|
9202
9217
|
if (!s) return;
|
|
9203
9218
|
await s.ready;
|
|
9204
9219
|
let t = e.session || {};
|
|
@@ -9222,12 +9237,12 @@ function ou(e, n) {
|
|
|
9222
9237
|
}), e.debug && console.log("[page-agent-sdk][restore] 恢复会话", W.sessionId, `${t.messages?.length ?? 0} msgs`)) : e.debug && console.log("[page-agent-sdk][restore] 会话 meta 存在但快照为空", W.sessionId);
|
|
9223
9238
|
} else W.sessionId = await s.createSession(n, t.title), e.debug && console.log("[page-agent-sdk][restore] 新建会话(无历史)", W.sessionId);
|
|
9224
9239
|
} else W.sessionId = await s.createSession(n, t.title);
|
|
9225
|
-
e.memory && s.save(n, W.sessionId, { memory: E.get() || (typeof e.memory == "string" ? e.memory : "") }),
|
|
9240
|
+
e.memory && s.save(n, W.sessionId, { memory: E.get() || (typeof e.memory == "string" ? e.memory : "") }), nt();
|
|
9226
9241
|
}
|
|
9227
|
-
async function
|
|
9228
|
-
await
|
|
9242
|
+
async function it() {
|
|
9243
|
+
await Ze();
|
|
9229
9244
|
}
|
|
9230
|
-
function
|
|
9245
|
+
function at(e) {
|
|
9231
9246
|
let t = {};
|
|
9232
9247
|
for (let n of Ql(e)) {
|
|
9233
9248
|
let e = x.files[n];
|
|
@@ -9235,12 +9250,12 @@ function ou(e, n) {
|
|
|
9235
9250
|
}
|
|
9236
9251
|
return t;
|
|
9237
9252
|
}
|
|
9238
|
-
function
|
|
9253
|
+
function ot() {
|
|
9239
9254
|
let e = $l(x.files, Ql(b));
|
|
9240
9255
|
for (let t of e) delete x.files[t];
|
|
9241
9256
|
}
|
|
9242
|
-
function
|
|
9243
|
-
let e = co(b,
|
|
9257
|
+
function st() {
|
|
9258
|
+
let e = co(b, et);
|
|
9244
9259
|
if (!e.trimmed) return;
|
|
9245
9260
|
let { older: t, summary: n } = e;
|
|
9246
9261
|
if (H({
|
|
@@ -9251,22 +9266,22 @@ function ou(e, n) {
|
|
|
9251
9266
|
assistant: e.assistantMsgs.map((e) => e.content),
|
|
9252
9267
|
steps: e.assistantMsgs.flatMap((e) => e.steps ?? [])
|
|
9253
9268
|
})),
|
|
9254
|
-
vfsResults:
|
|
9269
|
+
vfsResults: at(t.flatMap((e) => [e.userMsg, ...e.assistantMsgs])),
|
|
9255
9270
|
summary: n.content,
|
|
9256
9271
|
reason: "max_memory_rounds"
|
|
9257
|
-
}), b.splice(e.deleteFrom, e.deleteCount, n),
|
|
9272
|
+
}), b.splice(e.deleteFrom, e.deleteCount, n), ot(), g && l) {
|
|
9258
9273
|
let n = e.summary, { prevSeg: r } = e;
|
|
9259
9274
|
(async () => {
|
|
9260
9275
|
try {
|
|
9261
9276
|
let e = await l(mo(t, v)), i = b.indexOf(n);
|
|
9262
9277
|
if (i < 0) return;
|
|
9263
|
-
b[i].content = so(t, r, e),
|
|
9278
|
+
b[i].content = so(t, r, e), ut();
|
|
9264
9279
|
} catch {}
|
|
9265
9280
|
})();
|
|
9266
9281
|
}
|
|
9267
9282
|
}
|
|
9268
|
-
let
|
|
9269
|
-
function
|
|
9283
|
+
let ct, lt = !1;
|
|
9284
|
+
function ut() {
|
|
9270
9285
|
if (!W.sessionId || !s) return;
|
|
9271
9286
|
let t = JSON.parse(JSON.stringify(b));
|
|
9272
9287
|
s.save(n, W.sessionId, { messages: t });
|
|
@@ -9285,13 +9300,13 @@ function ou(e, n) {
|
|
|
9285
9300
|
}
|
|
9286
9301
|
re && A && (s.save(n, W.sessionId, { checkpoints: A.exportStack() }), s.save(n, W.sessionId, { usage: i }));
|
|
9287
9302
|
let a = ms(b);
|
|
9288
|
-
a && a !==
|
|
9303
|
+
a && a !== ct && (ct = a, s.updateTitle(n, W.sessionId, a)), e.autoTitle !== !1 && u && !lt && b.some((e) => e.role === "user") && b.some((e) => e.role === "assistant") && (lt = !0, (async () => {
|
|
9289
9304
|
let e = await u(b);
|
|
9290
|
-
e && (await s.updateTitle(n, W.sessionId, e), await
|
|
9305
|
+
e && (await s.updateTitle(n, W.sessionId, e), await nt());
|
|
9291
9306
|
})()), e.debug && console.log("[page-agent-sdk][persist] save", W.sessionId, `${b.length} msgs`);
|
|
9292
9307
|
}
|
|
9293
9308
|
return W.initDone = (async () => {
|
|
9294
|
-
if (await
|
|
9309
|
+
if (await rt(), await it(), e.mcp?.length) {
|
|
9295
9310
|
let t = await Promise.allSettled(e.mcp.map((e) => os(e)));
|
|
9296
9311
|
W.mcpClosers = t.flatMap((e) => e.status === "fulfilled" ? [e.value.close] : []), W.mcpServers = [], t.forEach((t, n) => {
|
|
9297
9312
|
let r = e.mcp[n], i = r.name ?? r.url;
|
|
@@ -9307,7 +9322,7 @@ function ou(e, n) {
|
|
|
9307
9322
|
llm: t,
|
|
9308
9323
|
systemPrompt: P,
|
|
9309
9324
|
tools: B,
|
|
9310
|
-
middleware:
|
|
9325
|
+
middleware: $e,
|
|
9311
9326
|
maxToolRounds: e.maxToolRounds,
|
|
9312
9327
|
maxRetries: e.maxRetries,
|
|
9313
9328
|
maxParallelTools: e.maxParallelTools,
|