page-agent-sdk 2.19.0 → 2.20.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "page-agent-sdk",
3
- "version": "2.19.0",
3
+ "version": "2.20.0",
4
4
  "type": "module",
5
5
  "description": "AI agent SDK for web pages — embed a chat assistant that edits page data via schema-validated tools. A lighter, framework-agnostic alternative to CopilotKit/LangChain for in-page JSON-editing agents. Vue-bundled; works with DeepSeek, OpenAI, MCP.",
6
6
  "main": "./dist/page-agent-sdk.umd.cjs",
package/types/index.d.ts CHANGED
@@ -84,6 +84,26 @@ export interface TokenUsage {
84
84
  completion_tokens?: number;
85
85
  total_tokens?: number;
86
86
  }
87
+ /** 批处理单任务结果(sdk.batch 返回;ok=true 含 reply,ok=false 含 error) */
88
+ export interface BatchResult {
89
+ /** 任务在入参数组中的下标 */
90
+ index: number;
91
+ /** 任务文本 */
92
+ task: string;
93
+ /** 成功时的 agent 回复 */
94
+ reply?: string;
95
+ /** 失败时的错误信息 */
96
+ error?: string;
97
+ /** 是否成功 */
98
+ ok: boolean;
99
+ }
100
+ /** 批处理进度回调 payload(sdk.batch 的 onProgress 每任务完成调一次) */
101
+ export interface BatchProgress {
102
+ done: number;
103
+ total: number;
104
+ task: string;
105
+ ok: boolean;
106
+ }
87
107
 
88
108
  export type SdkEventHandler = (event: SdkEvent) => void;
89
109
 
@@ -316,11 +336,21 @@ export interface CheckpointMeta {
316
336
  timestamp: number;
317
337
  messageCount: number;
318
338
  }
339
+ export interface Checkpoint extends CheckpointMeta {
340
+ messages: AgentMessage[];
341
+ windowVals: Record<string, unknown>;
342
+ vfs: Record<string, { content: string; mimeType?: string; updatedAt: number }>;
343
+ todos: { id: string; content: string; status: 'pending' | 'in_progress' | 'completed' }[];
344
+ }
319
345
  export interface CheckpointManager {
320
346
  save(label?: string): number;
321
347
  list(): CheckpointMeta[];
322
348
  restore(id?: number): boolean;
323
349
  canRestore(): boolean;
350
+ /** 导出栈快照(深拷贝,可序列化;供 automation 断点续跑持久化,刷新/崩溃后恢复 restoreLastCheckpoint 能力) */
351
+ exportStack(): Checkpoint[];
352
+ /** 灌入栈快照(刷新/崩溃恢复时重建 checkpoint 栈;重置 nextId 防后续 save id 冲突) */
353
+ importStack(cps: unknown[]): void;
324
354
  }
325
355
  export declare function createCheckpointManager(deps: any): CheckpointManager;
326
356
  export declare function createCheckpointMiddleware(mgr: CheckpointManager): any;
@@ -358,6 +388,10 @@ export interface SessionSnapshot {
358
388
  vfs: Record<string, { content: string; mimeType?: string; updatedAt: number }>;
359
389
  todos: { id: string; content: string; status: 'pending' | 'in_progress' | 'completed' }[];
360
390
  memory: string;
391
+ /** automation 断点续跑:checkpoint 栈快照(刷新/崩溃后恢复 restoreLastCheckpoint 能力);仅 capabilities.automation 开启时写入 */
392
+ checkpoints?: unknown[];
393
+ /** automation 断点续跑:累计 token usage(刷新后续跑预算统计连续) */
394
+ usage?: TokenUsage;
361
395
  }
362
396
  export type StorageEvent =
363
397
  | { type: 'degraded'; reason: string }
@@ -473,6 +507,12 @@ export interface ChatSdkOptions {
473
507
  maxPlanRevisions?: number;
474
508
  /** 模型调用失败自动重试次数(默认 2;网络/429/5xx 重试,4xx 与 abort 不重试) */
475
509
  maxRetries?: number;
510
+ /** token 预算上限(累计 total_tokens 超过 → 停止 agent + emit BUDGET_EXCEEDED;需 capabilities.automation:true) */
511
+ tokenBudget?: number;
512
+ /** 时间预算 ms(从 agent 开始计时,超过 → 停止;需 capabilities.automation:true) */
513
+ timeBudgetMs?: number;
514
+ /** 无人值守错误恢复:致命错误(invoke 抛错)自动 restore_last_checkpoint + 重试次数(默认 1;防单点错误永久中断批量/长任务)。需 capabilities.automation:true */
515
+ maxAutoRetries?: number;
476
516
  /** 同轮工具并发上限(默认 1 串行) */
477
517
  maxParallelTools?: number;
478
518
  /** 模型上下文窗口(token);顶层声明对 llm 实例场景也生效,缺省按 model 名查表。影响 offload 阈值与压缩触发 */
@@ -480,7 +520,7 @@ export interface ChatSdkOptions {
480
520
  /** 模型最大输出(token);顶层声明对 llm 实例场景也生效,缺省按 model 名查表 */
481
521
  maxOutputTokens?: number;
482
522
  /** 子 agent 委派(默认开启;{ enabled: false } 关闭) */
483
- 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; workingMemory?: boolean };
523
+ 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 };
484
524
  subagent?: { enabled?: boolean; allowedTools?: string[]; systemPrompt?: string; temperature?: number; maxTokens?: number; skills?: SkillSpec[]; llm?: LLMConfig | ChatModelLike; maxDepth?: number; maxParallel?: number };
485
525
  /** 预声明子 agent 列表:每个用同主配置方式声明,自动生成 use_<id> 委派工具(与 spawn_agent 共存) */
486
526
  subagents?: SubagentConfig[];
@@ -571,6 +611,12 @@ export interface ChatSdk {
571
611
  restoreLastCheckpoint(): boolean;
572
612
  /** 列出可用 checkpoint(回退点);需开启 checkpoint,未开启返回空数组 */
573
613
  listCheckpoints(): CheckpointMeta[];
614
+ /**
615
+ * 批处理(automation):逐任务跑 agent,每任务前自动 checkpoint,任务间错误隔离(单任务失败记 error 不中断整批)。
616
+ * 适合无人值守批量操作(批量生成/改一批页面)。不经 UI 排队(直接 invoke);返回每个任务结果(成功 reply / 失败 error)。
617
+ * 配合 capabilities.automation + checkpoint 使用。
618
+ */
619
+ batch(tasks: string[], onProgress?: (p: BatchProgress) => void): Promise<BatchResult[]>;
574
620
  /** 运行时订阅 SDK 事件(可多个监听器,返回取消函数);与构造时 onEvent 互补 */
575
621
  hook(handler: SdkEventHandler): () => void;
576
622
  /** 运行时替换主数据配置(如页面切换、schema 变更);立即对数据工具生效,无需重建 agent。需开启 dataOps */