page-agent-sdk 3.33.0 → 3.34.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.
@@ -3526,6 +3526,7 @@ var Fa = {
3526
3526
  function Ia(e, t = "code") {
3527
3527
  let n = `use_${e}`;
3528
3528
  return [
3529
+ `【先判意图(防长对话误路由)】先判断用户是「问」还是「要生成/改」:**提问类**(这是什么组件/怎么用/某字段什么意思/为什么这样/解释代码)→ 用 read / list_components / rag_component_docs **直接回答**,绝不委派 ${n};**生成/修改类**(做一个/生成/改成/加一个 XX 组件)才按下面纪律委派 ${n}。长对话里上文全是生成记录时尤须警惕,不要把新问题当成延续旧任务。`,
3529
3530
  `【执行纪律(最重要)】收到代码组件任务后:**新建类直接委派**(追加组件无需通读/翻页现有数组,子 agent 自会采样一个组件看结构;**新建组件由子 agent 全权创建** —— 它自己把整个组件(含 ${t})写进数组,你不需要也不能替它创建/追加/落地代码)→ 修改类才 read 定位(by name)→ 调 ${n} 委派 → read 核对 → 回复用户。**中间绝不输出过渡性文字** —— 「我先看看…」「稍后委派」「接下来我会…」这类计划性回复等于任务没做就结束了(回复即本轮终止);所有调研和委派在本轮内连续完成,完成后才回复总结。`,
3530
3531
  "【产物形态】每个组件是完整、自包含的 HTML 页面(含 style/script,可独立成页);你只负责委派和收尾,不关心宿主如何渲染(v-html / iframe / SFC 是集成方的事)。",
3531
3532
  `【主 agent 职责边界(硬规则)】禁止直接 read/write 代码组件的 ${t} 字段(read 只得 <code Nkb> 摘要没用;write 绕过 vfs/verify 危险)—— 生成/修改/排查代码一律经 ${n},收尾 read 核对。**委派返回即已落地**:${n} 的结论说「已创建组件 X」= 组件已在数组里,**不要再 write/append 一遍**(子 agent 已自己创建,你再写 = 造出重复组件,还得花轮次删;真 LLM 实测踩过:主 agent 把返回的 code 又追加了一次 → 索引 8/9 重复)。核对方式 = read 该数组尾部(确认新组件存在 + name 唯一),仅此而已。`,
@@ -6573,23 +6574,25 @@ function il(e, t, n) {
6573
6574
  return r;
6574
6575
  }
6575
6576
  function al(e) {
6576
- let { writablePaths: t, codeVfsPrefix: n, ext: r, codeField: i = "code", onWarning: a, getController: o, vfsStore: s, craftNotes: c = !0 } = e;
6577
+ let { writablePaths: t, codeVfsPrefix: n, ext: r, codeField: i = "code", onWarning: a, getController: o, vfsStore: s, craftNotes: c = !0 } = e, l = s, u = l.__pgLastCheckout ??= /* @__PURE__ */ new Map(), d = l.__pgPendingRetry ??= /* @__PURE__ */ new Set();
6577
6578
  return {
6578
6579
  name: "code-asset-checkout-commit",
6579
6580
  beforeAgent: (e) => {
6580
- let c = o()?.get?.().bind, l = 0, u = 0, d = /* @__PURE__ */ new Map();
6581
+ let c = o()?.get?.().bind, l = 0, f = 0, p = /* @__PURE__ */ new Map();
6581
6582
  if (rl(c, t, (e) => {
6582
6583
  l++;
6583
6584
  let t = Q(e, i);
6584
6585
  if (typeof t == "string") {
6585
- u++, d.set(e.__pgId, el(t));
6586
- let i = `${n}${e.__pgId}.${r}`;
6587
- s.files[i] = {
6586
+ f++;
6587
+ let i = e.__pgId, a = el(t);
6588
+ p.set(i, a);
6589
+ let o = `${n}${i}.${r}`, c = s.files[o], l = u.get(i);
6590
+ c && typeof c.content == "string" && c.content !== t && l === a ? d.add(o) : (s.files[o] = {
6588
6591
  content: t,
6589
6592
  updatedAt: Date.now()
6590
- };
6593
+ }, d.delete(o)), u.set(i, a);
6591
6594
  }
6592
- }), l > 0 && u === 0 && a) {
6595
+ }), l > 0 && f === 0 && a) {
6593
6596
  let e = "";
6594
6597
  for (let n of t) {
6595
6598
  let t = Q(c, n);
@@ -6604,7 +6607,7 @@ function al(e) {
6604
6607
  files: s.files,
6605
6608
  [Kc]: /* @__PURE__ */ new Set(),
6606
6609
  [qc]: { text: "" },
6607
- [Jc]: d,
6610
+ [Jc]: p,
6608
6611
  [Yc]: []
6609
6612
  };
6610
6613
  },
@@ -6667,7 +6670,7 @@ function al(e) {
6667
6670
  let a = t.__pgId;
6668
6671
  c.add(a);
6669
6672
  let l = `${n}${a}.${r}`;
6670
- if (u.has(l)) try {
6673
+ if (!(!u.has(l) && !d.has(l))) try {
6671
6674
  let n = s.files[l];
6672
6675
  if (n && typeof n.content == "string") {
6673
6676
  let r = o.get(a);
@@ -6685,7 +6688,7 @@ function al(e) {
6685
6688
  console.warn(`[page-agent-sdk][code-asset] 跳过 commit 未通过校验的半成品(可能 abort/timeout 未跑完 verify):${l} - ${s[0].message}(${s[0].code})`);
6686
6689
  return;
6687
6690
  }
6688
- eo(t, i, n.content);
6691
+ eo(t, i, n.content), d.delete(l);
6689
6692
  }
6690
6693
  } catch (e) {
6691
6694
  console.warn(`[page-agent-sdk][code-asset] 组件 commit 失败已跳过(其余组件不受影响):${l} - ${String(e?.message ?? e)}`);
@@ -6698,18 +6701,18 @@ function al(e) {
6698
6701
  a?.markDataDirty?.(), a?.recomputeBaseline?.();
6699
6702
  }
6700
6703
  if (!c) return;
6701
- let d = Qc(e[qc]?.text ?? "");
6702
- if (!d.length) return;
6703
- let f = [];
6704
+ let f = Qc(e[qc]?.text ?? "");
6705
+ if (!f.length) return;
6706
+ let p = [];
6704
6707
  if (rl(l, t, (e) => {
6705
- (u.size === 0 || u.has(`${n}${e.__pgId}.${r}`)) && f.push(e);
6706
- }), !f.length) return;
6707
- let p = !1;
6708
- for (let e of d) {
6709
- let t = f.length === 1 ? f[0] : f.find((t) => typeof t.name == "string" && !!t.name && e.includes(t.name));
6710
- t && ($c(t, [e]), p = !0);
6708
+ (u.size === 0 || u.has(`${n}${e.__pgId}.${r}`)) && p.push(e);
6709
+ }), !p.length) return;
6710
+ let m = !1;
6711
+ for (let e of f) {
6712
+ let t = p.length === 1 ? p[0] : p.find((t) => typeof t.name == "string" && !!t.name && e.includes(t.name));
6713
+ t && ($c(t, [e]), m = !0);
6711
6714
  }
6712
- p && a?.markDataDirty?.();
6715
+ m && a?.markDataDirty?.();
6713
6716
  }
6714
6717
  };
6715
6718
  }
@@ -11307,6 +11310,10 @@ function jf(e, n) {
11307
11310
  afterRound() {
11308
11311
  Rt(), Kt();
11309
11312
  },
11313
+ clearCodeReuse() {
11314
+ let e = x;
11315
+ e.__pgPendingRetry?.clear(), e.__pgLastCheckout?.clear();
11316
+ },
11310
11317
  async send(e, t) {
11311
11318
  if (await Y.initDone, Y.refCount <= 0) throw Error("page-agent-sdk: agent 已释放(unmount),拒绝排队中的 send");
11312
11319
  t ??= {}, t?.mission && Me && C.setMission(t.mission);
@@ -12074,6 +12081,7 @@ function Mf(e, t) {
12074
12081
  },
12075
12082
  stream: (e, t, n) => a.stream(e, t, n),
12076
12083
  afterRound: a.afterRound,
12084
+ clearCodeReuse: () => a.clearCodeReuse(),
12077
12085
  get debugLogs() {
12078
12086
  return a.agent.debugLogs;
12079
12087
  },
@@ -12323,33 +12331,33 @@ async function zf(e) {
12323
12331
  //#region src/core/composables/useChat.ts
12324
12332
  var Bf = 4e3;
12325
12333
  function Vf(e = {}) {
12326
- let { fetchResponse: t, fetchStream: n, onPersist: r, onClear: i, onQueuedCleared: a } = e, o = /* @__PURE__ */ yt({
12334
+ let { fetchResponse: t, fetchStream: n, onPersist: r, onClear: i, onQueuedCleared: a, onBeforeRegenerate: o } = e, s = /* @__PURE__ */ yt({
12327
12335
  messages: e.messages ?? [],
12328
12336
  loading: !1,
12329
12337
  error: null
12330
- }), s = /* @__PURE__ */ At(null), c = /* @__PURE__ */ At(!0), l = null, u = /* @__PURE__ */ At([]), d = /* @__PURE__ */ At(null);
12331
- function f() {}
12332
- function p(e) {
12333
- let t = s.value;
12334
- e.deltaY < 0 ? c.value = !1 : t && (c.value = t.scrollHeight - t.scrollTop - t.clientHeight < 64);
12335
- }
12336
- function m() {
12337
- s.value && requestAnimationFrame(() => {
12338
- let e = s.value;
12339
- !e || !c.value || (e.scrollTop = e.scrollHeight);
12338
+ }), c = /* @__PURE__ */ At(null), l = /* @__PURE__ */ At(!0), u = null, d = /* @__PURE__ */ At([]), f = /* @__PURE__ */ At(null);
12339
+ function p() {}
12340
+ function m(e) {
12341
+ let t = c.value;
12342
+ e.deltaY < 0 ? l.value = !1 : t && (l.value = t.scrollHeight - t.scrollTop - t.clientHeight < 64);
12343
+ }
12344
+ function h() {
12345
+ c.value && requestAnimationFrame(() => {
12346
+ let e = c.value;
12347
+ !e || !l.value || (e.scrollTop = e.scrollHeight);
12340
12348
  });
12341
12349
  }
12342
- function h(e, t, n, r) {
12343
- o.messages.push({
12350
+ function g(e, t, n, r) {
12351
+ s.messages.push({
12344
12352
  role: e,
12345
12353
  content: t,
12346
12354
  timestamp: Date.now(),
12347
12355
  ...n && n.length ? { focuses: n } : {},
12348
12356
  ...r?.length ? { images: r } : {}
12349
- }), c.value = !0, m();
12357
+ }), l.value = !0, h();
12350
12358
  }
12351
- async function g(e) {
12352
- if (c.value = !0, n) {
12359
+ async function _(e) {
12360
+ if (l.value = !0, n) {
12353
12361
  let t = /* @__PURE__ */ yt({
12354
12362
  role: "assistant",
12355
12363
  content: "",
@@ -12357,9 +12365,9 @@ function Vf(e = {}) {
12357
12365
  reasoning: "",
12358
12366
  steps: []
12359
12367
  }), r = !1;
12360
- o.messages.push(t);
12368
+ s.messages.push(t);
12361
12369
  try {
12362
- await n(o.messages.slice(0, -1), (e) => {
12370
+ await n(s.messages.slice(0, -1), (e) => {
12363
12371
  switch (e.type) {
12364
12372
  case "round_start":
12365
12373
  e.round > 1 && (t.content || t.reasoning) && (r = !0);
@@ -12418,34 +12426,34 @@ function Vf(e = {}) {
12418
12426
  break;
12419
12427
  }
12420
12428
  case "approval_request":
12421
- d.value = {
12429
+ f.value = {
12422
12430
  toolName: e.toolName,
12423
12431
  args: e.args,
12424
12432
  resolve: e.resolve
12425
12433
  };
12426
12434
  break;
12427
12435
  }
12428
- m();
12436
+ h();
12429
12437
  }, e);
12430
12438
  } catch (n) {
12431
- if (Di(n, e) || (o.error = n.message || "请求失败,请重试"), !t.content && !t.reasoning) {
12432
- let e = o.messages.indexOf(t);
12433
- e >= 0 && o.messages.splice(e, 1);
12439
+ if (Di(n, e) || (s.error = n.message || "请求失败,请重试"), !t.content && !t.reasoning) {
12440
+ let e = s.messages.indexOf(t);
12441
+ e >= 0 && s.messages.splice(e, 1);
12434
12442
  }
12435
12443
  } finally {
12436
- await v();
12444
+ await y();
12437
12445
  }
12438
12446
  return;
12439
12447
  }
12440
12448
  try {
12441
- h("assistant", await (t || S)(o.messages, e));
12449
+ g("assistant", await (t || C)(s.messages, e));
12442
12450
  } catch (t) {
12443
- Di(t, e) || (o.error = t.message || "请求失败,请重试");
12451
+ Di(t, e) || (s.error = t.message || "请求失败,请重试");
12444
12452
  } finally {
12445
- await v();
12453
+ await y();
12446
12454
  }
12447
12455
  }
12448
- function _(e) {
12456
+ function v(e) {
12449
12457
  let t = (e) => {
12450
12458
  if (e?.length) for (let n of e) n.status === "running" && (n.status = "error", n.result ||= "(本轮已结束,该步骤未收到结果 —— 子 agent 中断/异常)"), n.children?.length && t(n.children);
12451
12459
  };
@@ -12454,78 +12462,79 @@ function Vf(e = {}) {
12454
12462
  break;
12455
12463
  }
12456
12464
  }
12457
- async function v() {
12458
- _(o.messages);
12465
+ async function y() {
12466
+ v(s.messages);
12459
12467
  try {
12460
- await r?.(o.messages);
12468
+ await r?.(s.messages);
12461
12469
  } catch {}
12462
- o.loading = !1, l = null;
12463
- let e = u.value.shift();
12464
- e !== void 0 && (h("user", e), o.loading = !0, o.error = null, l = new AbortController(), await g(l.signal));
12470
+ s.loading = !1, u = null;
12471
+ let e = d.value.shift();
12472
+ e !== void 0 && (g("user", e), s.loading = !0, s.error = null, u = new AbortController(), await _(u.signal));
12465
12473
  }
12466
- function y(e) {
12467
- u.value.splice(e, 1);
12474
+ function b(e) {
12475
+ d.value.splice(e, 1);
12468
12476
  }
12469
- async function b(e, t, n) {
12477
+ async function x(e, t, n) {
12470
12478
  if (!(!e.trim() && !n?.length)) {
12471
- if (o.loading) {
12472
- u.value.push(e.trim());
12479
+ if (s.loading) {
12480
+ d.value.push(e.trim());
12473
12481
  return;
12474
12482
  }
12475
- h("user", e.trim() || "[image]", t, n), o.loading = !0, o.error = null, l = new AbortController(), await g(l.signal);
12483
+ g("user", e.trim() || "[image]", t, n), s.loading = !0, s.error = null, u = new AbortController(), await _(u.signal);
12476
12484
  }
12477
12485
  }
12478
- async function x() {
12479
- if (o.loading) return;
12480
- let e = o.messages;
12486
+ async function S() {
12487
+ if (s.loading) return;
12488
+ o?.();
12489
+ let e = s.messages;
12481
12490
  for (let t = e.length - 1; t >= 0; t--) if (e[t].role === "assistant") {
12482
12491
  e.splice(t);
12483
12492
  break;
12484
12493
  }
12485
- e.some((e) => e.role === "user") && (o.loading = !0, o.error = null, l = new AbortController(), await g(l.signal));
12494
+ e.some((e) => e.role === "user") && (s.loading = !0, s.error = null, u = new AbortController(), await _(u.signal));
12486
12495
  }
12487
- async function S(e) {
12496
+ async function C(e) {
12488
12497
  return await new Promise((e) => setTimeout(e, 800 + Math.random() * 1200)), `收到你的消息:"${e.filter((e) => e.role === "user").pop()?.content}"。这是一个模拟回复,请接入实际的 AI API。`;
12489
12498
  }
12490
- function C() {
12491
- i?.(), o.messages.splice(0, o.messages.length), o.error = null;
12492
- }
12493
12499
  function w() {
12494
- u.value.length && a?.([...u.value]), u.value = [], l?.abort();
12500
+ i?.(), s.messages.splice(0, s.messages.length), s.error = null;
12495
12501
  }
12496
12502
  function T() {
12497
- u.value = [], l?.abort(), l = null, o.loading = !1, o.error = null, d.value = null;
12503
+ d.value.length && a?.([...d.value]), d.value = [], u?.abort();
12504
+ }
12505
+ function E() {
12506
+ d.value = [], u?.abort(), u = null, s.loading = !1, s.error = null, f.value = null;
12498
12507
  }
12499
- function E(e) {
12500
- let t = d.value;
12501
- t && (d.value = null, t.resolve(e));
12508
+ function ee(e) {
12509
+ let t = f.value;
12510
+ t && (f.value = null, t.resolve(e));
12502
12511
  }
12503
- async function ee() {
12504
- if (!o.error) return;
12505
- let e = o.messages, t = -1;
12512
+ async function D() {
12513
+ if (!s.error) return;
12514
+ let e = s.messages, t = -1;
12506
12515
  for (let n = e.length - 1; n >= 0; n--) if (e[n].role === "user") {
12507
12516
  t = n;
12508
12517
  break;
12509
12518
  }
12510
12519
  if (t < 0) return;
12511
12520
  let n = e[t].content;
12512
- e.splice(t), o.error = null, await b(n);
12521
+ e.splice(t), s.error = null, await x(n);
12513
12522
  }
12514
12523
  return {
12515
- state: o,
12516
- scrollContainer: s,
12517
- pendingApproval: d,
12518
- queuedTasks: u,
12519
- sendMessage: b,
12520
- removeQueuedTask: y,
12521
- clearMessages: C,
12522
- stop: w,
12523
- reset: T,
12524
- retry: ee,
12525
- regenerate: x,
12526
- resolveApproval: E,
12527
- onScroll: f,
12528
- onWheel: p
12524
+ state: s,
12525
+ scrollContainer: c,
12526
+ pendingApproval: f,
12527
+ queuedTasks: d,
12528
+ sendMessage: x,
12529
+ removeQueuedTask: b,
12530
+ clearMessages: w,
12531
+ stop: T,
12532
+ reset: E,
12533
+ retry: D,
12534
+ regenerate: S,
12535
+ resolveApproval: ee,
12536
+ onScroll: p,
12537
+ onWheel: m
12529
12538
  };
12530
12539
  }
12531
12540
  //#endregion
@@ -13054,7 +13063,8 @@ function Jf(e = {}) {
13054
13063
  messages: e.messages,
13055
13064
  onPersist: e.onPersist,
13056
13065
  onClear: e.onClear,
13057
- onQueuedCleared: e.onQueuedCleared
13066
+ onQueuedCleared: e.onQueuedCleared,
13067
+ onBeforeRegenerate: e.onBeforeRegenerate
13058
13068
  }), { state: n, sendMessage: r, removeQueuedTask: i, queuedTasks: a } = t, o = /* @__PURE__ */ At(""), s = /* @__PURE__ */ At(!0), c = () => {
13059
13069
  s.value = !s.value;
13060
13070
  }, l = /* @__PURE__ */ At(!1), u = () => {