page-agent-sdk 4.10.0 → 4.11.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.
@@ -14649,6 +14649,7 @@ function Dy(e, t) {
14649
14649
  return c(e, n);
14650
14650
  }
14651
14651
  var Oy = s(({ selector: e, depth: t, attrs: n, includeText: r }) => {
14652
+ if (typeof document > "u") return "ERROR: get_dom 仅在浏览器环境可用(当前运行在 node/服务端,无 DOM)。请改用数据工具(read/schema_data)排查结构。";
14652
14653
  let i = e ? document.querySelector(e) : document.body;
14653
14654
  if (!i) return `未找到匹配元素:selector="${e}"`;
14654
14655
  let a = Dy(i, {
@@ -31267,21 +31268,95 @@ function vL(e) {
31267
31268
  };
31268
31269
  }
31269
31270
  //#endregion
31271
+ //#region src/core/sdk/evalToolkit.ts
31272
+ function yL(e = {}) {
31273
+ let t = e.quietMs ?? 9e4, n = e.confirmSamples ?? 3, r = e.baselineMessageCount ?? 0, i = 0;
31274
+ return {
31275
+ push(e) {
31276
+ return e.quietMs > 0xe8d4a51000 ? (i = 0, "reset") : (i = e.messageCount > r && e.hasResponse && e.activeSubagents === 0 && e.quietMs > t ? i + 1 : 0, i >= n ? "done" : "pending");
31277
+ },
31278
+ reset() {
31279
+ i = 0;
31280
+ }
31281
+ };
31282
+ }
31283
+ var bL = /* @__PURE__ */ new Set(["elapsedSec"]);
31284
+ function xL(e, t, n = {}) {
31285
+ let r = n.tokenAbs ?? 2e3, i = n.tokenPct ?? 15, a = n.toolCountAbs ?? 3, o = [], s = 0, c = 0, l = 0, u = /* @__PURE__ */ new Set([...Object.keys(e ?? {}), ...Object.keys(t ?? {})]);
31286
+ for (let n of u) {
31287
+ let u = Number(e?.[n] ?? 0), d = Number(t?.[n] ?? 0), f = u - d, p = d > 0 ? Math.round(f / d * 100) : 0, m = "";
31288
+ bL.has(n) || (n === "toolCount" ? Math.abs(f) > a : Math.abs(f) > r && Math.abs(p) >= i) && (m = f > 0 ? "up" : "down", m === "up" ? (s++, c++) : l++), o.push({
31289
+ key: n,
31290
+ prev: d,
31291
+ cur: u,
31292
+ delta: f,
31293
+ pct: p,
31294
+ flag: m
31295
+ });
31296
+ }
31297
+ return {
31298
+ status: c > 0 ? "worse" : l > 0 ? "better" : "ok",
31299
+ regressions: s,
31300
+ fields: o
31301
+ };
31302
+ }
31303
+ function SL(e) {
31304
+ let { sdk: t } = e, n = () => {
31305
+ let e = t.debugLogs.value ?? [], n = e.length ? e[e.length - 1].timestamp : 0;
31306
+ return {
31307
+ messageCount: t.messages?.length ?? 0,
31308
+ quietMs: n ? Date.now() - n : 2 ** 53 - 1,
31309
+ hasResponse: e.some((e) => e.type === "llm_response"),
31310
+ activeSubagents: t.inspect?.().subagent?.active?.length ?? 0,
31311
+ logCount: e.length
31312
+ };
31313
+ };
31314
+ return {
31315
+ async waitForIdle(e = {}) {
31316
+ let { timeoutMs: r = 6e5, sampleMs: i = 2500, onSample: a, ...o } = e, s = yL(o), c = Date.now();
31317
+ for (;;) {
31318
+ let e = n(), o = s.push(e);
31319
+ if (a?.(e), o === "done") return e;
31320
+ if (o === "reset") throw Error(`eval: 等待 idle 期间日志被清空(会话切换/重置;logCount=${e.logCount})—— 采样口径已失效`);
31321
+ if (Date.now() - c > r) {
31322
+ let n = t.debugLogs.value ?? [], i = [...n].reverse().find((e) => e.type === "tool_result"), a = [...n].reverse().find((e) => e.type === "llm_request"), o = t.inspect?.().subagent?.active ?? [];
31323
+ throw Error(`eval: 等待 agent idle 超时(${Math.round(r / 1e3)}s)。诊断:msgs=${e.messageCount} logs=${e.logCount} lastRound=${String(a?.data?.round ?? "-")} lastTool=${i ? `${String(i.data?.name)}@${String(i.data?.round)}` : "-"} activeSubagents=${o.length}${o.length ? `(${o.map((e) => String(e.label ?? "?")).join(",")})` : ""}`);
31324
+ }
31325
+ await new Promise((e) => setTimeout(e, i));
31326
+ }
31327
+ },
31328
+ collectReport() {
31329
+ let e = t.debugLogs.value ?? [], n = t.usage;
31330
+ return {
31331
+ at: (/* @__PURE__ */ new Date()).toISOString(),
31332
+ messageCount: t.messages?.length ?? 0,
31333
+ toolCount: e.filter((e) => e.type === "tool_result").length,
31334
+ usage: {
31335
+ prompt: n?.prompt ?? 0,
31336
+ completion: n?.completion ?? 0,
31337
+ ...n?.cacheRead ? { cacheRead: n.cacheRead } : {},
31338
+ ...n?.cacheCreate ? { cacheCreate: n.cacheCreate } : {}
31339
+ }
31340
+ };
31341
+ }
31342
+ };
31343
+ }
31344
+ //#endregion
31270
31345
  //#region src/core/components/CodePreview.vue?vue&type=script&setup=true&lang.ts
31271
- var yL = { class: "code-preview-modal" }, bL = { class: "preview-header" }, xL = { class: "preview-title" }, SL = { class: "preview-tabs" }, CL = ["disabled"], wL = { class: "preview-actions" }, TL = ["title"], EL = {
31346
+ var CL = { class: "code-preview-modal" }, wL = { class: "preview-header" }, TL = { class: "preview-title" }, EL = { class: "preview-tabs" }, DL = ["disabled"], OL = { class: "preview-actions" }, kL = ["title"], AL = {
31272
31347
  key: 0,
31273
31348
  viewBox: "0 0 16 16",
31274
31349
  fill: "none",
31275
31350
  "aria-hidden": "true"
31276
- }, DL = {
31351
+ }, jL = {
31277
31352
  key: 1,
31278
31353
  viewBox: "0 0 16 16",
31279
31354
  fill: "none",
31280
31355
  "aria-hidden": "true"
31281
- }, OL = ["title"], kL = ["title"], AL = { class: "preview-body" }, jL = ["srcdoc"], ML = {
31356
+ }, ML = ["title"], NL = ["title"], PL = { class: "preview-body" }, FL = ["srcdoc"], IL = {
31282
31357
  key: 1,
31283
31358
  class: "preview-source"
31284
- }, NL = /*#__PURE__*/ wE(/* @__PURE__ */ Zi({
31359
+ }, LL = /*#__PURE__*/ wE(/* @__PURE__ */ Zi({
31285
31360
  __name: "CodePreview",
31286
31361
  props: {
31287
31362
  code: {},
@@ -31348,28 +31423,28 @@ app.mount('#app');
31348
31423
  return (t, n) => (J(), Y("div", {
31349
31424
  class: "code-preview-overlay",
31350
31425
  onClick: n[3] ||= Fl((e) => r("close"), ["self"])
31351
- }, [X("div", yL, [X("div", bL, [
31352
- X("span", xL, U(e.messages.codePreviewTitlePrefix) + U(e.lang), 1),
31353
- X("div", SL, [X("button", {
31426
+ }, [X("div", CL, [X("div", wL, [
31427
+ X("span", TL, U(e.messages.codePreviewTitlePrefix) + U(e.lang), 1),
31428
+ X("div", EL, [X("button", {
31354
31429
  class: qe({ active: a.value === "preview" }),
31355
31430
  disabled: !s.value,
31356
31431
  onClick: n[0] ||= (e) => a.value = "preview"
31357
- }, U(e.messages.codePreviewTab), 11, CL), X("button", {
31432
+ }, U(e.messages.codePreviewTab), 11, DL), X("button", {
31358
31433
  class: qe({ active: a.value === "source" }),
31359
31434
  onClick: n[1] ||= (e) => a.value = "source"
31360
31435
  }, U(e.messages.codeSourceTab), 3)]),
31361
- X("div", wL, [
31436
+ X("div", OL, [
31362
31437
  X("button", {
31363
31438
  class: qe(["icon-btn", { done: o.value }]),
31364
31439
  title: o.value ? e.messages.copied : e.messages.codeCopyTitle,
31365
31440
  onClick: u
31366
- }, [o.value ? (J(), Y("svg", EL, [...n[4] ||= [X("path", {
31441
+ }, [o.value ? (J(), Y("svg", AL, [...n[4] ||= [X("path", {
31367
31442
  d: "M3 8.5l3 3 7-7",
31368
31443
  stroke: "currentColor",
31369
31444
  "stroke-width": "1.6",
31370
31445
  "stroke-linecap": "round",
31371
31446
  "stroke-linejoin": "round"
31372
- }, null, -1)]])) : (J(), Y("svg", DL, [...n[5] ||= [X("rect", {
31447
+ }, null, -1)]])) : (J(), Y("svg", jL, [...n[5] ||= [X("rect", {
31373
31448
  x: "5.5",
31374
31449
  y: "5.5",
31375
31450
  width: "8",
@@ -31381,7 +31456,7 @@ app.mount('#app');
31381
31456
  d: "M10.5 3.5v-.5A1.5 1.5 0 0 0 9 1.5H3.5A1.5 1.5 0 0 0 2 3v5.5A1.5 1.5 0 0 0 3.5 10H4",
31382
31457
  stroke: "currentColor",
31383
31458
  "stroke-width": "1.3"
31384
- }, null, -1)]]))], 10, TL),
31459
+ }, null, -1)]]))], 10, kL),
31385
31460
  X("button", {
31386
31461
  class: "icon-btn",
31387
31462
  title: e.messages.codeOpenTitle,
@@ -31401,7 +31476,7 @@ app.mount('#app');
31401
31476
  "stroke-width": "1.3",
31402
31477
  "stroke-linecap": "round",
31403
31478
  "stroke-linejoin": "round"
31404
- })], -1)]], 8, OL),
31479
+ })], -1)]], 8, ML),
31405
31480
  X("button", {
31406
31481
  class: "icon-btn",
31407
31482
  title: e.messages.close,
@@ -31415,22 +31490,22 @@ app.mount('#app');
31415
31490
  stroke: "currentColor",
31416
31491
  "stroke-width": "1.4",
31417
31492
  "stroke-linecap": "round"
31418
- })], -1)]], 8, kL)
31493
+ })], -1)]], 8, NL)
31419
31494
  ])
31420
- ]), X("div", AL, [a.value === "preview" && s.value ? (J(), Y("iframe", {
31495
+ ]), X("div", PL, [a.value === "preview" && s.value ? (J(), Y("iframe", {
31421
31496
  key: 0,
31422
31497
  ref_key: "iframeRef",
31423
31498
  ref: i,
31424
31499
  class: "preview-iframe",
31425
31500
  sandbox: "allow-scripts allow-modals allow-popups allow-forms",
31426
31501
  srcdoc: c.value
31427
- }, null, 8, jL)) : (J(), Y("pre", ML, [X("code", null, U(e.code), 1)]))])])]));
31502
+ }, null, 8, FL)) : (J(), Y("pre", IL, [X("code", null, U(e.code), 1)]))])])]));
31428
31503
  }
31429
31504
  }), [["__scopeId", "data-v-27eac25e"]]);
31430
31505
  //#endregion
31431
31506
  //#region src/core/index.ts
31432
- function PL(e) {
31507
+ function RL(e) {
31433
31508
  return Tb(e, fL);
31434
31509
  }
31435
31510
  //#endregion
31436
- export { zj as ApprovalBar, my as CAPABILITIES, _y as CONTEXT_PRESETS, dL as ChatDialog, tD as ChatHeader, OM as ChatInput, NL as CodePreview, Sv as CompressDecisionSchema, nM as ConflictBar, Ay as DEFAULT_COMPUTED_STYLES, Fw as DEFAULT_DIALOG_ICONS, Pm as DEFAULT_PROMPT_SOFT_CAP, lg as DEFAULT_SYSTEM_PROMPT, ug as DEFAULT_SYSTEM_PROMPT_EN, RI as DebugDrawer, fD as FocusBar, pA as HLJS_BLOCK_MAX_CHARS, d_ as HTML_VOID_TAGS, wh as HUMAN_CONFIRM_TOOL_NAME, TE as IconGlyph, nu as ImageInputError, T as LOW_CAPS_HINT_BASELINE, Rw as MESSAGES_EN_US, Lw as MESSAGES_ZH_CN, S as MIN_CONTEXT_WINDOW, zu as MODEL_UNAVAILABLE_GUIDANCE, TA as MessageContent, ij as MessageList, JA as MessageRow, mj as QueuedBar, Nm as SOFT_CAP_MIN_WINDOW, Tm as STOP_WORDS, uL as SkillPanel, Tp as UNSAFE_KEYS, Qy as actionsToInspectInfo, Zy as actionsToTools, Ql as agentError, ng as analyzeContext, zp as applyPatchToClone, Hp as applyPatchToLive, $g as applyPatchesToBind, Wf as arrayMinLength, Zl as asAgentError, nv as buildCollectorJs, Fy as buildCssPath, dg as buildDataPrompt, J_ as buildDiagnosticsReport, fv as buildHtmlFragmentSkill, rv as buildSandboxSrcdoc, fg as buildSystemPrompt, Vw as chatContextKey, Qg as commitSetToBind, lv as composeStructureThenRender, pu as compressImage, cg as connectMcp, re as constructLlmFromConfig, te as constructOpenLlmSync, Pw as copyText, Pf as createAgent, Ch as createApprovalMiddleware, Hw as createChatContext, PL as createChatSdk, Ph as createCheckpointManager, Fh as createCheckpointMiddleware, Fv as createConflictManager, rg as createContextInspectorMiddleware, gv as createCraftNoteCheck, u_ as createDataOps, mv as createHtmlFormatCheck, cv as createHtmlRenderCheck, vv as createHtmlSubagent, Dh as createHumanConfirmMiddleware, Eh as createHumanConfirmTool, ry as createMemoryBackend, gh as createMemoryMiddleware, y as createProxyLlm, vL as createRagSubagent, Gu as createSandboxRunner, gy as createSdkEvents, hb as createSerialRunner, sy as createSessionStore, cy as createSessionStoreWithBackend, db as createSkillStore, sh as createSubagentMiddleware, Vm as createSubagentTracker, uh as createSubagentsMiddleware, ab as createUsageHintsMiddleware, Lh as createVerifyMiddleware, gg as createVfs, ay as createWebStorageBackend, Uh as createWriteBackCheck, Bu as decorateModelUnavailable, Ap as deepClone, tb as defineDataToolset, tm as defineSkill, yv as defineTool, kp as deleteByPath, Cv as deriveTitle, ip as describeSchemaNode, bf as detectGarbledToolCall, Rd as detectTransitionalReply, Kp as diffObjects, By as domInfoTool, Vy as domInspectSkill, zy as domSearchTool, Dy as domToStructure, ky as domTools, eb as domToolsStatic, Gf as elementSchemaCandidates, Ny as ensureDomListenerRecorder, Dm as estimateMessageTokens, Am as estimateRoundTokens, O as estimateTokens, ae as extractReasoningDelta, _p as extractSchemaHint, ig as extractText, ie as extractTextDelta, oe as extractUsage, Cy as fetchDocTools, $y as fetchTools, Gp as findStrippedKeys, ap as formatConstraints, ql as formatZodIssues, $ as getByPath, Oy as getDomTool, Ry as getElementInfo, Wy as getEnvSummary, Py as getRecordedListeners, ov as getSandboxLifecycle, Rf as getSchemaAtPath, Ff as getSchemaTopKeys, Lp as hashValue, pv as htmlFragmentSkill, fp as htmlOrchestratorPrompt, jm as indexSummarize, qy as inspectEnvTool, Jy as inspectTools, Tv as isChatModel, Lu as isContextLengthError, pE as isIconHtml, Ru as isModelUnavailableError, If as isPathAllowed, Yv as isQuotaError, Ep as isUnsafePath, td as jpEval, Yl as jsonParseError, Pp as limitDepth, E as lowCapsHint, yA as markedToHtml, K_ as maskUrlCredentials, Mp as maybeParseValue, B_ as measureWriteScale, Vp as moveByPath, N as normalizeBaseUrl, tv as normalizeRenderResult, ce as normalizeUsage, A as offloadPassThroughChars, k as offloadThresholdChars, dp as presets, Qf as projectBySchema, Zf as projectBySchemaDeep, Np as projectFields, Mm as recallRounds, sv as renderInSandbox, bA as renderMarkdownHtml, op as renderSchemaHint, sp as renderSchemaOverview, up as renderSchemaShallow, hy as resolveCapabilities, yy as resolveContextOptions, dy as resolveDialogConfig, Iw as resolveDialogIcons, Bw as resolveDialogMessages, Pv as resolveLlm, D as resolveModelCaps, Im as resolvePromptSoftCap, Vf as resolveSchemaPath, uy as resolveStorage, Wp as restoreInPlace, Up as restoreLive, Xl as routeError, ad as runSandboxedScript, Dp as safeMerge, Uy as safeSerialize, Fp as safeStringify, xf as sanitizeGarbledContent, _E as sanitizeIconHtml, bE as sanitizeMessageHtml, Uf as schemaHasRefinement, Iy as searchDom, rd as searchJson, nb as selectBuiltinTools, Op as setByPath, Lm as shouldTriggerCompression, Y_ as stringifyDiagnosticsReport, M as stripStainlessFetch, pp as systemPromptHelpers, w as tableMaxOutputTokens, Em as tokenize, Q as toolError, Lf as unwrapSchema, Nw as useChat, Uw as useChatContext, Hf as validateAtPath, p_ as validateHtmlFormat, Xg as validateRootValueLocally, Zg as validateWriteLocally, Rp as watchFieldsHash, e as z, Jl as zodError };
31511
+ export { zj as ApprovalBar, my as CAPABILITIES, _y as CONTEXT_PRESETS, dL as ChatDialog, tD as ChatHeader, OM as ChatInput, LL as CodePreview, Sv as CompressDecisionSchema, nM as ConflictBar, Ay as DEFAULT_COMPUTED_STYLES, Fw as DEFAULT_DIALOG_ICONS, Pm as DEFAULT_PROMPT_SOFT_CAP, lg as DEFAULT_SYSTEM_PROMPT, ug as DEFAULT_SYSTEM_PROMPT_EN, RI as DebugDrawer, fD as FocusBar, pA as HLJS_BLOCK_MAX_CHARS, d_ as HTML_VOID_TAGS, wh as HUMAN_CONFIRM_TOOL_NAME, TE as IconGlyph, nu as ImageInputError, T as LOW_CAPS_HINT_BASELINE, Rw as MESSAGES_EN_US, Lw as MESSAGES_ZH_CN, S as MIN_CONTEXT_WINDOW, zu as MODEL_UNAVAILABLE_GUIDANCE, TA as MessageContent, ij as MessageList, JA as MessageRow, mj as QueuedBar, Nm as SOFT_CAP_MIN_WINDOW, Tm as STOP_WORDS, uL as SkillPanel, Tp as UNSAFE_KEYS, Qy as actionsToInspectInfo, Zy as actionsToTools, Ql as agentError, ng as analyzeContext, zp as applyPatchToClone, Hp as applyPatchToLive, $g as applyPatchesToBind, Wf as arrayMinLength, Zl as asAgentError, nv as buildCollectorJs, Fy as buildCssPath, dg as buildDataPrompt, J_ as buildDiagnosticsReport, fv as buildHtmlFragmentSkill, rv as buildSandboxSrcdoc, fg as buildSystemPrompt, Vw as chatContextKey, Qg as commitSetToBind, lv as composeStructureThenRender, pu as compressImage, cg as connectMcp, re as constructLlmFromConfig, te as constructOpenLlmSync, Pw as copyText, Pf as createAgent, Ch as createApprovalMiddleware, Hw as createChatContext, RL as createChatSdk, Ph as createCheckpointManager, Fh as createCheckpointMiddleware, Fv as createConflictManager, rg as createContextInspectorMiddleware, gv as createCraftNoteCheck, u_ as createDataOps, SL as createEvalHarness, mv as createHtmlFormatCheck, cv as createHtmlRenderCheck, vv as createHtmlSubagent, Dh as createHumanConfirmMiddleware, Eh as createHumanConfirmTool, yL as createIdleDetector, ry as createMemoryBackend, gh as createMemoryMiddleware, y as createProxyLlm, vL as createRagSubagent, Gu as createSandboxRunner, gy as createSdkEvents, hb as createSerialRunner, sy as createSessionStore, cy as createSessionStoreWithBackend, db as createSkillStore, sh as createSubagentMiddleware, Vm as createSubagentTracker, uh as createSubagentsMiddleware, ab as createUsageHintsMiddleware, Lh as createVerifyMiddleware, gg as createVfs, ay as createWebStorageBackend, Uh as createWriteBackCheck, Bu as decorateModelUnavailable, Ap as deepClone, tb as defineDataToolset, tm as defineSkill, yv as defineTool, kp as deleteByPath, Cv as deriveTitle, ip as describeSchemaNode, bf as detectGarbledToolCall, Rd as detectTransitionalReply, Kp as diffObjects, xL as diffReport, By as domInfoTool, Vy as domInspectSkill, zy as domSearchTool, Dy as domToStructure, ky as domTools, eb as domToolsStatic, Gf as elementSchemaCandidates, Ny as ensureDomListenerRecorder, Dm as estimateMessageTokens, Am as estimateRoundTokens, O as estimateTokens, ae as extractReasoningDelta, _p as extractSchemaHint, ig as extractText, ie as extractTextDelta, oe as extractUsage, Cy as fetchDocTools, $y as fetchTools, Gp as findStrippedKeys, ap as formatConstraints, ql as formatZodIssues, $ as getByPath, Oy as getDomTool, Ry as getElementInfo, Wy as getEnvSummary, Py as getRecordedListeners, ov as getSandboxLifecycle, Rf as getSchemaAtPath, Ff as getSchemaTopKeys, Lp as hashValue, pv as htmlFragmentSkill, fp as htmlOrchestratorPrompt, jm as indexSummarize, qy as inspectEnvTool, Jy as inspectTools, Tv as isChatModel, Lu as isContextLengthError, pE as isIconHtml, Ru as isModelUnavailableError, If as isPathAllowed, Yv as isQuotaError, Ep as isUnsafePath, td as jpEval, Yl as jsonParseError, Pp as limitDepth, E as lowCapsHint, yA as markedToHtml, K_ as maskUrlCredentials, Mp as maybeParseValue, B_ as measureWriteScale, Vp as moveByPath, N as normalizeBaseUrl, tv as normalizeRenderResult, ce as normalizeUsage, A as offloadPassThroughChars, k as offloadThresholdChars, dp as presets, Qf as projectBySchema, Zf as projectBySchemaDeep, Np as projectFields, Mm as recallRounds, sv as renderInSandbox, bA as renderMarkdownHtml, op as renderSchemaHint, sp as renderSchemaOverview, up as renderSchemaShallow, hy as resolveCapabilities, yy as resolveContextOptions, dy as resolveDialogConfig, Iw as resolveDialogIcons, Bw as resolveDialogMessages, Pv as resolveLlm, D as resolveModelCaps, Im as resolvePromptSoftCap, Vf as resolveSchemaPath, uy as resolveStorage, Wp as restoreInPlace, Up as restoreLive, Xl as routeError, ad as runSandboxedScript, Dp as safeMerge, Uy as safeSerialize, Fp as safeStringify, xf as sanitizeGarbledContent, _E as sanitizeIconHtml, bE as sanitizeMessageHtml, Uf as schemaHasRefinement, Iy as searchDom, rd as searchJson, nb as selectBuiltinTools, Op as setByPath, Lm as shouldTriggerCompression, Y_ as stringifyDiagnosticsReport, M as stripStainlessFetch, pp as systemPromptHelpers, w as tableMaxOutputTokens, Em as tokenize, Q as toolError, Lf as unwrapSchema, Nw as useChat, Uw as useChatContext, Hf as validateAtPath, p_ as validateHtmlFormat, Xg as validateRootValueLocally, Zg as validateWriteLocally, Rp as watchFieldsHash, e as z, Jl as zodError };