page-agent-sdk 3.46.0 → 4.0.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/types/index.d.ts CHANGED
@@ -172,6 +172,8 @@ export interface TokenUsage {
172
172
  cache_read_input_tokens?: number;
173
173
  /** prompt caching 本次写入的 input tokens(Anthropic;写价格 1.25x,5m/1h TTL 内复用) */
174
174
  cache_creation_input_tokens?: number;
175
+ /** 推理/思考 token 数(completion 子集,展示为占比;OpenAI 兼容可得,Anthropic 当前依赖栈不暴露则省略) */
176
+ reasoning_tokens?: number;
175
177
  }
176
178
  /** 批处理单任务结果(sdk.batch 返回;ok=true 含 reply,ok=false 含 error) */
177
179
  export interface BatchResult {
@@ -948,6 +950,8 @@ export type SkillToolFactory = () => any | any[] | Promise<any | any[]>;
948
950
  export interface VerifyCheckContext {
949
951
  messages: any[];
950
952
  state: any;
953
+ /** 结构化日志(debugLogs;render-check 类环境降级留痕用,可缺省) */
954
+ log?: (type: string, data: unknown) => void;
951
955
  }
952
956
  export interface VerifyCheckResult {
953
957
  ok: boolean;
@@ -1251,7 +1255,7 @@ export interface ChatSdkOptions {
1251
1255
  /** 图片输入配置组(image-input-vision):images.upload 上传换 URL(集成方 OSS)/ images.describe 绑定识图转述(集成方识图子 agent / 自有 vision API,非多模态主模型时转述注入) */
1252
1256
  images?: ImagesConfig;
1253
1257
  /** 子 agent 委派(默认开启;{ enabled: false } 关闭) */
1254
- capabilities?: { dataOps?: boolean; fetch?: boolean; planning?: boolean; missionAnchor?: boolean; skills?: boolean; vfs?: boolean; summarization?: boolean; memory?: boolean; subagent?: boolean; verify?: boolean; domInspect?: boolean; inspectEnv?: boolean; draftWrite?: boolean; tracing?: boolean; todoDeps?: boolean; automation?: boolean; workingMemory?: boolean; focus?: boolean; skillHostScript?: boolean; contextInspector?: boolean; agentCompression?: boolean; preferences?: boolean; bulkGuard?: boolean };
1258
+ capabilities?: { dataOps?: boolean; fetch?: boolean; planning?: boolean; missionAnchor?: boolean; skills?: boolean; vfs?: boolean; summarization?: boolean; memory?: boolean; subagent?: boolean; verify?: boolean; domInspect?: boolean; inspectEnv?: boolean; draftWrite?: boolean; tracing?: boolean; automation?: boolean; workingMemory?: boolean; focus?: boolean; skillHostScript?: boolean; contextInspector?: boolean; agentCompression?: boolean; preferences?: boolean; bulkGuard?: boolean };
1255
1259
  subagent?: { enabled?: boolean; allowedTools?: string[]; systemPrompt?: string; temperature?: number; maxTokens?: number; skills?: SkillSpec[]; llm?: LLMConfig | ChatModelLike; maxDepth?: number; maxParallel?: number; timeoutMs?: number; thinkingMode?: 'simple' | 'deep' };
1256
1260
  /** 预声明子 agent 列表:每个用同主配置方式声明,自动生成 use_<id> 委派工具(与 spawn_agent 共存) */
1257
1261
  subagents?: SubagentConfig[];
@@ -1567,7 +1571,7 @@ export declare function defineTool(opts: {
1567
1571
  writeCapable?: boolean | ((args: Record<string, unknown>) => boolean);
1568
1572
  }): any;
1569
1573
  export declare function createDataOps(config: DataConfig, opts?: DataOpsOptions): any[];
1570
- /** 整体 set 写入纯函数:schema 校验 + 快照 + merge/替换 + audit。set_data / write(set) / draft_commit 共用。返回 {ok,hash,data} 或 {ok:false,error} */
1574
+ /** 整体 set 写入纯函数:schema 校验 + 快照 + merge/替换 + audit。write(set) / draft_commit 共用。返回 {ok,hash,data} 或 {ok:false,error} */
1571
1575
  export declare function commitSetToBind(args: { bindRef: unknown; value: unknown; schema: any; allowKeys: string[] | null; snapshots: any[]; maxSnapshots: number; audit: (e: any) => void; dryRun?: boolean; op?: 'set' | 'draft_commit'; snapshotLabel?: string }): { ok: true; hash: string; data: unknown; notices: string[] } | { ok: false; error: string };
1572
1576
  /** path-scoped-validation:增量 patch 逐目标局部校验(全部 apply 后按最终态;兄弟脏数据不株连)。返回写回计划 */
1573
1577
  export interface LocalWriteBack {
@@ -1588,7 +1592,7 @@ export interface LocalValidationPlan {
1588
1592
  export declare function validateRootValueLocally(args: { schema: any; allowKeys: string[] | null; value: unknown; bindRef: unknown }): { ok: true; assembly: unknown; wholeParsed: Record<string, unknown> | null; notices: string[] } | { ok: false; error: string; notices: string[] };
1589
1593
  /** 增量 patch 逐目标局部校验纯函数(appendCaptures/moveCaptures 由 apply 循环捕获;valueAt 为位移兜底) */
1590
1594
  export declare function validateWriteLocally(args: { schema: any; bindRef: unknown; clone: unknown; patches: { op?: string; jsonPath?: string; value?: unknown }[]; schemaErrorMode?: 'zod' | 'schema_invalid'; appendCaptures: { jp: string; elems: unknown[] }[]; moveCaptures: { jp: string; toPath: string; elem: unknown }[]; valueAt?: (jp: string) => unknown }): LocalValidationPlan;
1591
- /** 增量 patch 写入纯函数(clone + 局部校验 + 快照 + 外科手术式写回);edit_data / write(edit) / eval 共用 */
1595
+ /** 增量 patch 写入纯函数(clone + 局部校验 + 快照 + 外科手术式写回);write(edit) / eval 共用 */
1592
1596
  export declare function applyPatchesToBind(args: { bindRef: unknown; patches: { op?: string; jsonPath?: string; value?: unknown }[]; schema: any; allowKeys: string[] | null; snapshots: any[]; maxSnapshots: number; markDataDirty?: () => void; schemaErrorMode?: 'zod' | 'schema_invalid'; snapshotLabel?: string; dryRun?: boolean; internalAfterWrite?: (bind: any, before: any) => void; protectedCtx?: unknown }): { ok: true; applied: { op: string; jp: string; value: unknown }[]; clone: unknown; notices: string[] } | { ok: false; error: string };
1593
1597
  /** 结构化追踪 span(revive-observability-tracing Phase 3) */
1594
1598
  export type SpanType = 'round' | 'model' | 'tool' | 'compression';
@@ -1761,6 +1765,8 @@ export interface Capability { name: string; defaultOn: boolean; requires?: reado
1761
1765
  export type CapabilityFlags = Partial<Record<string, boolean>>;
1762
1766
  export type ResolvedCapabilities = Record<string, boolean>;
1763
1767
  export declare const CAPABILITIES: readonly Capability[];
1768
+ /** 已列入移除计划的配置键(config-surface-pruning;维护者确认外部零使用,warn 一版后移除)。键 = capabilities 键名,值 = 迁移指引 */
1769
+ export declare const DEPRECATED_CAPABILITIES: Readonly<Record<string, string>>;
1764
1770
  /** 单一解析:集成方原始 caps(Partial)→ 全量 boolean(opt-out 默认开 !==false / opt-in 默认关 ===true;requires 依赖未满足强制关)。参数宽松 Record<string,unknown>(兼容含 subagents 等非 boolean 字段的 caps 对象;只读已知 capability 的 boolean) */
1765
1771
  export declare function resolveCapabilities(caps?: Record<string, unknown>): ResolvedCapabilities;
1766
1772
  export declare function resolveStorage(storage: any): any | null;
@@ -1772,7 +1778,7 @@ export interface SdkEvents {
1772
1778
  }
1773
1779
  export declare function createSdkEvents(onEvent?: (e: any) => void): SdkEvents;
1774
1780
  export declare function selectBuiltinTools(caps: { dataOps?: boolean; fetch?: boolean; domInspect?: boolean; inspectEnv?: boolean } | undefined, dataOps: any[], fetchDocs: any[], dom?: any[], inspect?: any[]): any[];
1775
- export declare function createUsageHintsMiddleware(caps: { planning?: boolean; dataOps?: boolean; subagent?: boolean; humanConfirm?: boolean; inspectEnv?: boolean; domInspect?: boolean; draftWrite?: boolean; todoDeps?: boolean; focus?: boolean; subagents?: { id: string; description: string; temperature?: number }[] } | undefined, hasDataOps: boolean, budget?: { promptSoftCap?: number }): any;
1781
+ export declare function createUsageHintsMiddleware(caps: { planning?: boolean; dataOps?: boolean; subagent?: boolean; humanConfirm?: boolean; inspectEnv?: boolean; domInspect?: boolean; draftWrite?: boolean; focus?: boolean; subagents?: { id: string; description: string; temperature?: number }[] } | undefined, hasDataOps: boolean, budget?: { promptSoftCap?: number }): any;
1776
1782
  export declare const fetchDocTools: any[];
1777
1783
  /** DOM 读取工具 get_dom(随 capabilities.domInspect 装配,opt-in) */
1778
1784
  export declare const domTools: any[];
@@ -1930,7 +1936,7 @@ export interface JpNode {
1930
1936
  path: string;
1931
1937
  /** 匹配元素值 */
1932
1938
  value: unknown;
1933
- /** 父为数组时的索引(便于后续 edit_data_slot 的 jsonPath 定位) */
1939
+ /** 父为数组时的索引(便于后续 write patch 的 jsonPath 定位) */
1934
1940
  index?: number;
1935
1941
  }
1936
1942
  export interface SearchHit {
@@ -2122,6 +2128,76 @@ export interface HtmlFormatCheckOptions {
2122
2128
  }
2123
2129
  /** HTML 格式 verify check(beforeReturn 门禁):扫 state.files 代码文件,不通过回灌 feedback 自纠 */
2124
2130
  export declare function createHtmlFormatCheck(opts?: HtmlFormatCheckOptions): VerifyCheck;
2131
+ /** 沙箱采集到的原始渲染信号(console.error / js-error / unhandledrejection / 资源失败 / CSP 违规 / console.warn) */
2132
+ export interface RenderSignal {
2133
+ type: 'console-error' | 'console-warn' | 'js-error' | 'unhandledrejection' | 'resource-error' | 'csp-violation';
2134
+ message: string;
2135
+ source?: string;
2136
+ lineno?: number;
2137
+ }
2138
+ /** 渲染指标(收集窗结束时采集;白屏判定口径 = 内容级:body 子节点数 / scrollHeight / 图片数) */
2139
+ export interface RenderMetrics {
2140
+ bodyChildren: number;
2141
+ scrollHeight: number;
2142
+ imgCount: number;
2143
+ }
2144
+ /** 单组件沙箱渲染的原始结果(未归一;noDom = node/无 DOM 环境标记) */
2145
+ export interface RawRenderResult {
2146
+ handshake: boolean;
2147
+ signals: RenderSignal[];
2148
+ metrics?: RenderMetrics;
2149
+ timedOut?: boolean;
2150
+ noDom?: boolean;
2151
+ }
2152
+ /** 归一后的单组件判定:pass / fail(带 problems)/ unavailable(握手缺失或超时,不算通过防假绿) */
2153
+ export interface RenderVerdict {
2154
+ verdict: 'pass' | 'fail' | 'unavailable';
2155
+ problems: string[];
2156
+ warnings: string[];
2157
+ metrics?: RenderMetrics;
2158
+ reason?: 'handshake-missing' | 'timeout';
2159
+ }
2160
+ /** 渲染自检 VerifyCheck 工厂选项(runner 注入供测试桩用) */
2161
+ export interface HtmlRenderCheckOptions {
2162
+ vfsPrefix?: string;
2163
+ codeField?: string;
2164
+ writablePaths?: string[];
2165
+ runner?: (html: string) => Promise<RawRenderResult>;
2166
+ maxTargets?: number;
2167
+ }
2168
+ /** 渲染自检对象:check 组合进 createHtmlSubagent 的 formatCheck 链;两个注入槽由装配期回填 */
2169
+ export interface HtmlRenderCheck {
2170
+ check: VerifyCheck;
2171
+ setGetController: (g: () => {
2172
+ get?: () => { bind?: unknown } | null | undefined;
2173
+ } | null | undefined) => void;
2174
+ setWritablePaths: (paths: string[]) => void;
2175
+ }
2176
+ /** 沙箱运行参数(活动静默窗/硬上限/指标应答宽限;默认 900ms / 4000ms / 500ms) */
2177
+ export interface SandboxRunOptions {
2178
+ silenceMs?: number;
2179
+ hardCapMs?: number;
2180
+ metricsGraceMs?: number;
2181
+ }
2182
+ /**
2183
+ * 渲染级自检(render-check):本轮触达的 code 资产放沙箱 iframe(srcdoc + sandbox="allow-scripts")独立渲染,
2184
+ * 采集 console.error / window.onerror / unhandledrejection / 资源失败 / 白屏指标 → 归一回灌自纠。
2185
+ * 仅门禁形态(组合进 createHtmlSubagent 的 formatCheck 链);node/无 DOM 自动跳过渲染段保留结构段;
2186
+ * 握手缺失(宿主 CSP 拦沙箱内联脚本)/ 超时 → unavailable 不算通过(零信号 ≠ 通过)。
2187
+ */
2188
+ export declare function createHtmlRenderCheck(opts?: HtmlRenderCheckOptions): HtmlRenderCheck;
2189
+ /** 组合「结构 → 渲染」为单一 VerifyCheck(结构不过短路渲染;runBeforeReturn 不短路,两段必须单 check 内早返回) */
2190
+ export declare function composeStructureThenRender(structure: VerifyCheck, render: VerifyCheck): VerifyCheck;
2191
+ /** 信号归一纯函数:storage 类 SecurityError 降 warn(沙箱假阳性);无失败信号但 body 空 + scrollHeight<10 → 疑似白屏 fail */
2192
+ export declare function normalizeRenderResult(raw: RawRenderResult): RenderVerdict;
2193
+ /** 单组件沙箱渲染(离屏 iframe;用后销毁;node/无 DOM 返回 noDom) */
2194
+ export declare function renderInSandbox(html: string, opts?: SandboxRunOptions): Promise<RawRenderResult>;
2195
+ /** 沙箱 srcdoc 构造(collector 注入文档最前,不改组件原文) */
2196
+ export declare function buildSandboxSrcdoc(html: string, nonce: string): string;
2197
+ /** collector 采集脚本源码(nonce 握手 + 信号上报 + 活动信号 + 指标应答) */
2198
+ export declare function buildCollectorJs(nonce: string): string;
2199
+ /** 累计创建/销毁的沙箱 iframe 数(测试观察「用后销毁」契约) */
2200
+ export declare function getSandboxLifecycle(): { created: number; destroyed: number };
2125
2201
  /** 内置完整 HTML 生成规范 skill 构造器(示例路径按 root/codeField 参数化,集成方字段命名各异勿写死;默认快照 root='components'/codeField='code') */
2126
2202
  export declare function buildHtmlFragmentSkill(root?: string, codeField?: string): SkillSpec;
2127
2203
  /** 内置完整 HTML 生成规范 skill(createHtmlSubagent 默认装;传自定义 skills 覆盖默认时,显式并回此 skill 保住生成规范/安全底线;默认快照 root='components'/codeField='code') */
@@ -2160,6 +2236,12 @@ export declare const CompressDecisionSchema: {
2160
2236
  export declare const MIN_CONTEXT_WINDOW: number;
2161
2237
  /** 判定错误是否为上下文超限(模型输入超 contextWindow);复用 langchain ContextOverflowError + 兜底正则。harden-context-resilience */
2162
2238
  export declare function isContextLengthError(err: unknown): boolean;
2239
+ /** 判定错误是否为「模型不可用」(网关/厂商下线模型面:model is offline / not support for model / model_not_found)。model-offline-guidance;仅消费于模型调用失败 catch 点,勿用于工具错误归一化(裸 "does not exist" 形态会误伤路径错误) */
2240
+ export declare function isModelUnavailableError(err: unknown): boolean;
2241
+ /** 命中模型不可用 → 就地打 `code:'MODEL_UNAVAILABLE'` + message 尾附可操作引导(幂等);返回是否命中。severity/重试语义由调用方维持现状 */
2242
+ export declare function decorateModelUnavailable(err: unknown): boolean;
2243
+ /** 模型不可用引导文案(换模型名 setLlm / 查网关模型面;不引导声明任何新配置) */
2244
+ export declare const MODEL_UNAVAILABLE_GUIDANCE: string;
2163
2245
  export declare function resolveModelCaps(model: string): any;
2164
2246
  export declare function estimateTokens(text: string): number;
2165
2247
  export declare function offloadThresholdChars(contextWindow: number): number;