page-agent-sdk 2.19.0 → 2.20.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 +2 -1
- package/README.zh-CN.md +4 -3
- package/dist/page-agent-sdk.iife.js +128 -127
- package/dist/page-agent-sdk.js +2817 -2668
- package/dist/page-agent-sdk.umd.cjs +74 -73
- package/package.json +3 -2
- package/types/index.d.ts +58 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "page-agent-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.1",
|
|
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",
|
|
@@ -54,7 +54,8 @@
|
|
|
54
54
|
"test:browser": "playwright test",
|
|
55
55
|
"test:browser:ui": "playwright test --ui",
|
|
56
56
|
"test:draft-real": "tsx tests/runtime/draft-real-llm.ts",
|
|
57
|
-
"test:trace-real": "tsx tests/runtime/trace-real-llm.ts"
|
|
57
|
+
"test:trace-real": "tsx tests/runtime/trace-real-llm.ts",
|
|
58
|
+
"test:maliang-real": "tsx tests/runtime/maliang-real-llm.ts"
|
|
58
59
|
},
|
|
59
60
|
"keywords": [
|
|
60
61
|
"ai",
|
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
|
|
|
@@ -127,6 +147,8 @@ export interface SubagentConfig {
|
|
|
127
147
|
temperature?: number;
|
|
128
148
|
maxTokens?: number;
|
|
129
149
|
maxToolRounds?: number;
|
|
150
|
+
/** 子 agent 可写路径前缀白名单(给子 agent 写权限;写工具包 path guard,越界 PATH_OUT_OF_SCOPE;整体 set 禁)。subagent-writable Phase 2 */
|
|
151
|
+
writablePaths?: string[];
|
|
130
152
|
}
|
|
131
153
|
export interface AgentInfo {
|
|
132
154
|
id: string;
|
|
@@ -316,11 +338,21 @@ export interface CheckpointMeta {
|
|
|
316
338
|
timestamp: number;
|
|
317
339
|
messageCount: number;
|
|
318
340
|
}
|
|
341
|
+
export interface Checkpoint extends CheckpointMeta {
|
|
342
|
+
messages: AgentMessage[];
|
|
343
|
+
windowVals: Record<string, unknown>;
|
|
344
|
+
vfs: Record<string, { content: string; mimeType?: string; updatedAt: number }>;
|
|
345
|
+
todos: { id: string; content: string; status: 'pending' | 'in_progress' | 'completed' }[];
|
|
346
|
+
}
|
|
319
347
|
export interface CheckpointManager {
|
|
320
348
|
save(label?: string): number;
|
|
321
349
|
list(): CheckpointMeta[];
|
|
322
350
|
restore(id?: number): boolean;
|
|
323
351
|
canRestore(): boolean;
|
|
352
|
+
/** 导出栈快照(深拷贝,可序列化;供 automation 断点续跑持久化,刷新/崩溃后恢复 restoreLastCheckpoint 能力) */
|
|
353
|
+
exportStack(): Checkpoint[];
|
|
354
|
+
/** 灌入栈快照(刷新/崩溃恢复时重建 checkpoint 栈;重置 nextId 防后续 save id 冲突) */
|
|
355
|
+
importStack(cps: unknown[]): void;
|
|
324
356
|
}
|
|
325
357
|
export declare function createCheckpointManager(deps: any): CheckpointManager;
|
|
326
358
|
export declare function createCheckpointMiddleware(mgr: CheckpointManager): any;
|
|
@@ -358,6 +390,10 @@ export interface SessionSnapshot {
|
|
|
358
390
|
vfs: Record<string, { content: string; mimeType?: string; updatedAt: number }>;
|
|
359
391
|
todos: { id: string; content: string; status: 'pending' | 'in_progress' | 'completed' }[];
|
|
360
392
|
memory: string;
|
|
393
|
+
/** automation 断点续跑:checkpoint 栈快照(刷新/崩溃后恢复 restoreLastCheckpoint 能力);仅 capabilities.automation 开启时写入 */
|
|
394
|
+
checkpoints?: unknown[];
|
|
395
|
+
/** automation 断点续跑:累计 token usage(刷新后续跑预算统计连续) */
|
|
396
|
+
usage?: TokenUsage;
|
|
361
397
|
}
|
|
362
398
|
export type StorageEvent =
|
|
363
399
|
| { type: 'degraded'; reason: string }
|
|
@@ -473,6 +509,12 @@ export interface ChatSdkOptions {
|
|
|
473
509
|
maxPlanRevisions?: number;
|
|
474
510
|
/** 模型调用失败自动重试次数(默认 2;网络/429/5xx 重试,4xx 与 abort 不重试) */
|
|
475
511
|
maxRetries?: number;
|
|
512
|
+
/** token 预算上限(累计 total_tokens 超过 → 停止 agent + emit BUDGET_EXCEEDED;需 capabilities.automation:true) */
|
|
513
|
+
tokenBudget?: number;
|
|
514
|
+
/** 时间预算 ms(从 agent 开始计时,超过 → 停止;需 capabilities.automation:true) */
|
|
515
|
+
timeBudgetMs?: number;
|
|
516
|
+
/** 无人值守错误恢复:致命错误(invoke 抛错)自动 restore_last_checkpoint + 重试次数(默认 1;防单点错误永久中断批量/长任务)。需 capabilities.automation:true */
|
|
517
|
+
maxAutoRetries?: number;
|
|
476
518
|
/** 同轮工具并发上限(默认 1 串行) */
|
|
477
519
|
maxParallelTools?: number;
|
|
478
520
|
/** 模型上下文窗口(token);顶层声明对 llm 实例场景也生效,缺省按 model 名查表。影响 offload 阈值与压缩触发 */
|
|
@@ -480,7 +522,7 @@ export interface ChatSdkOptions {
|
|
|
480
522
|
/** 模型最大输出(token);顶层声明对 llm 实例场景也生效,缺省按 model 名查表 */
|
|
481
523
|
maxOutputTokens?: number;
|
|
482
524
|
/** 子 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 };
|
|
525
|
+
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
526
|
subagent?: { enabled?: boolean; allowedTools?: string[]; systemPrompt?: string; temperature?: number; maxTokens?: number; skills?: SkillSpec[]; llm?: LLMConfig | ChatModelLike; maxDepth?: number; maxParallel?: number };
|
|
485
527
|
/** 预声明子 agent 列表:每个用同主配置方式声明,自动生成 use_<id> 委派工具(与 spawn_agent 共存) */
|
|
486
528
|
subagents?: SubagentConfig[];
|
|
@@ -571,6 +613,12 @@ export interface ChatSdk {
|
|
|
571
613
|
restoreLastCheckpoint(): boolean;
|
|
572
614
|
/** 列出可用 checkpoint(回退点);需开启 checkpoint,未开启返回空数组 */
|
|
573
615
|
listCheckpoints(): CheckpointMeta[];
|
|
616
|
+
/**
|
|
617
|
+
* 批处理(automation):逐任务跑 agent,每任务前自动 checkpoint,任务间错误隔离(单任务失败记 error 不中断整批)。
|
|
618
|
+
* 适合无人值守批量操作(批量生成/改一批页面)。不经 UI 排队(直接 invoke);返回每个任务结果(成功 reply / 失败 error)。
|
|
619
|
+
* 配合 capabilities.automation + checkpoint 使用。
|
|
620
|
+
*/
|
|
621
|
+
batch(tasks: string[], onProgress?: (p: BatchProgress) => void): Promise<BatchResult[]>;
|
|
574
622
|
/** 运行时订阅 SDK 事件(可多个监听器,返回取消函数);与构造时 onEvent 互补 */
|
|
575
623
|
hook(handler: SdkEventHandler): () => void;
|
|
576
624
|
/** 运行时替换主数据配置(如页面切换、schema 变更);立即对数据工具生效,无需重建 agent。需开启 dataOps */
|
|
@@ -950,7 +998,15 @@ export interface SubagentsController {
|
|
|
950
998
|
remove(id: string): boolean;
|
|
951
999
|
get(): SubagentConfig[];
|
|
952
1000
|
}
|
|
953
|
-
|
|
1001
|
+
/** spawn_agent / spawn_agents 运行时选项(role/tools/writablePaths 等可运行时覆盖) */
|
|
1002
|
+
export interface SubagentOptions {
|
|
1003
|
+
role?: string;
|
|
1004
|
+
tools?: string[];
|
|
1005
|
+
/** 子 agent 可写路径前缀白名单(运行时覆盖;写工具包 path guard,越界 PATH_OUT_OF_SCOPE)。subagent-writable Phase 2 */
|
|
1006
|
+
writablePaths?: string[];
|
|
1007
|
+
model?: string;
|
|
1008
|
+
[k: string]: any;
|
|
1009
|
+
}
|
|
954
1010
|
export interface SubagentLlmConfig { [k: string]: any }
|
|
955
1011
|
|
|
956
1012
|
// checkpoint / dataOps / permissions
|