page-agent-sdk 1.0.2 → 1.1.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": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "description": "框架无关的页面内 Agent JS SDK —— 以对话框形态挂载到任意网页,通过自定义 tool 读写宿主 window 属性(GET 抓文档),具备 planning/skills/虚拟工作区/快照回退/context 管理能力。Vue 打包进库,使用者无需安装 Vue。",
6
6
  "main": "./dist/page-agent-sdk.umd.cjs",
package/types/index.d.ts CHANGED
@@ -42,6 +42,25 @@ export type StreamEvent =
42
42
 
43
43
  export type StreamHandler = (event: StreamEvent) => void;
44
44
 
45
+ /**
46
+ * SDK 事件(供 createChatSdk({ onEvent }) 订阅常用时机)。
47
+ * 复用 StreamEvent(round_start/reasoning/text/tool_call/tool_result/subagent/done;approval_request 不外发)
48
+ * + 额外时机:window_prop_change / message_update / error。
49
+ */
50
+ export type SdkEvent =
51
+ | { type: 'round_start'; round: number }
52
+ | { type: 'reasoning'; delta: string }
53
+ | { type: 'text'; delta: string }
54
+ | { type: 'tool_call'; name: string; args: any }
55
+ | { type: 'tool_result'; name: string; result: string; status: 'done' | 'error' }
56
+ | { type: 'subagent'; taskId: string; label: string; kind: 'tool_call' | 'tool_result'; name: string; args?: any; result?: string; status?: 'done' | 'error' }
57
+ | { type: 'done'; content: string }
58
+ | { type: 'window_prop_change'; path: string; operation: 'set' | 'edit' | 'delete' | 'restore'; value?: unknown }
59
+ | { type: 'message_update'; count: number }
60
+ | { type: 'error'; message: string };
61
+
62
+ export type SdkEventHandler = (event: SdkEvent) => void;
63
+
45
64
  /** 调试日志(与 harness/createAgent 的 DebugLog 一致) */
46
65
  export interface DebugLog {
47
66
  timestamp: number;
@@ -336,6 +355,12 @@ export interface ChatSdkOptions {
336
355
  summaryMaxTokens?: number;
337
356
  /** 摘要 LLM 超时毫秒(默认 15000;超时回退索引摘要) */
338
357
  summaryTimeoutMs?: number;
358
+ /**
359
+ * SDK 事件回调:订阅常用时机(window 属性变化 / 消息更新 / 工具调用 / 流式文本 / 轮次 / 错误)。
360
+ * UI 与 headless 模式均生效;用于外部联动(宿主页面响应式刷新、埋点、日志),替代轮询。
361
+ * approval_request 不外发(UI 已处理)。
362
+ */
363
+ onEvent?: SdkEventHandler;
339
364
  /** 流式输出(默认 true);false 时等整段回复再显示 */
340
365
  streaming?: boolean;
341
366
  title?: string;
@@ -356,6 +381,8 @@ export interface ChatSdk {
356
381
  restoreLastCheckpoint(): boolean;
357
382
  /** 列出可用 checkpoint(回退点);需开启 checkpoint,未开启返回空数组 */
358
383
  listCheckpoints(): CheckpointMeta[];
384
+ /** 运行时订阅 SDK 事件(可多个监听器,返回取消函数);与构造时 onEvent 互补 */
385
+ hook(handler: SdkEventHandler): () => void;
359
386
  }
360
387
 
361
388
  export declare function createChatSdk(options: ChatSdkOptions): ChatSdk;