page-agent-sdk 4.20.0 → 4.21.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": "4.20.0",
3
+ "version": "4.21.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",
@@ -420,6 +420,8 @@ export interface AgentInfo {
420
420
  staleReadsInvalidated?: number;
421
421
  /** S2 宿主变更失效会话累计(host-integration-contract;notifyHostChange 触发的页面读占位替换次数,与写驱动分列) */
422
422
  hostReadsInvalidated?: number;
423
+ /** hostWatch 装配反射(4.21+;配置存在才出现):enabled=false = 服务端/headless 特性探测全缺(合法 no-op);autoNotified = 自动报案会话累计 */
424
+ hostWatch?: { enabled: boolean; url: boolean; pushState: boolean; title: boolean; autoNotified: number };
423
425
  /** A9 收口门禁会话累计(stage → { retries 回灌, exhausted 耗尽放行 };page_assertion_gate 键存在性 = domInspect 装配反射) */
424
426
  gates?: Record<string, { retries: number; exhausted: number }>;
425
427
  /** A9 最近一次 system 段构成(段名/字节/超预算 drop 标记;集成方 augmentSystem/pageContext 段被 drop 时可观察) */
@@ -1064,10 +1066,31 @@ export interface ChatSdkOptions {
1064
1066
  onEvent?: SdkEventHandler;
1065
1067
  /** 流式输出(默认 true);false 时等整段回复再显示 */
1066
1068
  streaming?: boolean;
1069
+ /**
1070
+ * 宿主导航自动报案(4.21+,配置即开关):监听 URL/title 变化自动触发 notifyHostChange 全链路
1071
+ * (流内页面读占位失效 + 一次性重读提示段)—— 把「防线靠宿主记得调」变「防线自动」。
1072
+ * `true` = { url: true };细配见 HostWatchConfig。服务端/headless(无 window)逐 API 特性探测
1073
+ * 静默降级 no-op(合法形态,inspect().hostWatch.enabled=false 可确认)。
1074
+ * 另:dom_edit/dom_restore 落地成功后既有页面读自动失效(默认开,与本选项无关)
1075
+ */
1076
+ hostWatch?: boolean | HostWatchConfig;
1067
1077
  /** Dialog UI config (title/placeholder/drawer/drawerWidth/drawerHidden/inputRows/onClose grouped) */
1068
1078
  dialog?: DialogConfig;
1069
1079
  }
1070
1080
 
1081
+ /** hostWatch 细配(4.21+):各项独立降级,缺失依赖只关该项不弃整个 watcher */
1082
+ export interface HostWatchConfig {
1083
+ /** 原生 hashchange + popstate(默认项,零 patch;hash 路由文档站主场景) */
1084
+ url?: boolean;
1085
+ /** patch history.pushState/replaceState(hashless SPA 路由;链式保留 + unmount 还原;opt-in) */
1086
+ pushState?: boolean;
1087
+ /** 观察 document.title(不改 URL 的换文站;噪声较高故 opt-in;配 debounceMs 消化) */
1088
+ title?: boolean;
1089
+ /** 去抖窗口 ms(默认 300:路由切换常伴 hash+title 连发,窗口内合并为一次报案,url 类优先) */
1090
+ debounceMs?: number;
1091
+ /** 宿主自定义忽略(如自家 #section 纯锚点):返回 true 不报案 */
1092
+ ignore?: (e: { kind: 'hash' | 'pop' | 'push' | 'title'; from: string; to: string }) => boolean;
1093
+ }
1071
1094
  /** Dialog UI config (grouped form, recommended) */
1072
1095
  export interface DialogConfig {
1073
1096
  title?: string;
package/types/index.d.ts CHANGED
@@ -729,6 +729,8 @@ export interface AgentInfo {
729
729
  staleReadsInvalidated?: number;
730
730
  /** S2 宿主变更失效会话累计(host-integration-contract;notifyHostChange 触发的页面读占位替换次数,与写驱动分列) */
731
731
  hostReadsInvalidated?: number;
732
+ /** hostWatch 装配反射(4.21+;配置存在才出现):enabled=false = 服务端/headless 特性探测全缺(合法 no-op);autoNotified = 自动报案会话累计 */
733
+ hostWatch?: { enabled: boolean; url: boolean; pushState: boolean; title: boolean; autoNotified: number };
732
734
  /** A9 收口门禁会话累计(stage → { retries 回灌, exhausted 耗尽放行 };page_assertion_gate 键存在性 = domInspect 装配反射) */
733
735
  gates?: Record<string, { retries: number; exhausted: number }>;
734
736
  /** A9 最近一次 system 段构成(段名/字节/超预算 drop 标记;集成方 augmentSystem/pageContext 段被 drop 时可观察) */
@@ -1432,6 +1434,14 @@ export interface ChatSdkOptions {
1432
1434
  dialog?: DialogConfig;
1433
1435
  /** 国际化:locale 切语言 + messages 键级覆盖文案(3.22+;UI 文案包 + 默认 systemPrompt/autoTitle 语言;原 dialog.locale/dialog.messages 两键合并至此) */
1434
1436
  i18n?: I18nOptions;
1437
+ /**
1438
+ * 宿主导航自动报案(4.21+,配置即开关):监听 URL/title 变化自动触发 notifyHostChange 全链路
1439
+ * (流内页面读占位失效 + 一次性重读提示段)—— 把「防线靠宿主记得调」变「防线自动」。
1440
+ * `true` = { url: true };细配见 HostWatchConfig。服务端/headless(无 window)逐 API 特性探测
1441
+ * 静默降级 no-op(合法形态,inspect().hostWatch.enabled=false 可确认)。
1442
+ * 另:dom_edit/dom_restore 落地成功后既有页面读自动失效(默认开,与本选项无关)
1443
+ */
1444
+ hostWatch?: boolean | HostWatchConfig;
1435
1445
  }
1436
1446
 
1437
1447
  /** Dialog UI config (grouped form, recommended) */
@@ -1484,6 +1494,19 @@ export interface QuickActionItem {
1484
1494
  * 国际化配置(顶层 i18n;3.22 起,原 dialog.locale/dialog.messages 两键移入此处合并)。
1485
1495
  * 不放 dialog 组:locale 除 UI 文案包外还驱动默认 systemPrompt 语言与 autoTitle 标题语言(agent 层)。
1486
1496
  */
1497
+ /** hostWatch 细配(4.21+):各项独立降级,缺失依赖只关该项不弃整个 watcher */
1498
+ export interface HostWatchConfig {
1499
+ /** 原生 hashchange + popstate(默认项,零 patch;hash 路由文档站主场景) */
1500
+ url?: boolean;
1501
+ /** patch history.pushState/replaceState(hashless SPA 路由;链式保留 + unmount 还原;opt-in) */
1502
+ pushState?: boolean;
1503
+ /** 观察 document.title(不改 URL 的换文站;噪声较高故 opt-in;配 debounceMs 消化) */
1504
+ title?: boolean;
1505
+ /** 去抖窗口 ms(默认 300:路由切换常伴 hash+title 连发,窗口内合并为一次报案,url 类优先) */
1506
+ debounceMs?: number;
1507
+ /** 宿主自定义忽略(如自家 #section 纯锚点):返回 true 不报案 */
1508
+ ignore?: (e: { kind: 'hash' | 'pop' | 'push' | 'title'; from: string; to: string }) => boolean;
1509
+ }
1487
1510
  export interface I18nOptions {
1488
1511
  /** 语言:'zh-CN'(默认)/'en-US';切换内置文案包(聊天面 + Debug 抽屉 + Skill 面板 + 代码预览);
1489
1512
  * formatTime(12h/24h)/autoTitle/默认 systemPrompt 跟随(en → 英文版身份 + "Respond in English" 锚,