page-agent-sdk 4.19.2 → 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/README.md +4 -2
- package/README.zh-CN.md +4 -2
- package/dist/page-agent-sdk.headless.js +2741 -2594
- package/dist/page-agent-sdk.iife.js +171 -171
- package/dist/page-agent-sdk.js +6716 -6569
- package/dist/page-agent-sdk.legacy.js +6157 -5997
- package/dist/page-agent-sdk.umd.cjs +112 -112
- package/package.json +1 -1
- package/types/headless.d.ts +33 -2
- package/types/index.d.ts +33 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "page-agent-sdk",
|
|
3
|
-
"version": "4.
|
|
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",
|
package/types/headless.d.ts
CHANGED
|
@@ -413,13 +413,15 @@ export interface AgentInfo {
|
|
|
413
413
|
/** 方案确认留痕(save-and-plan-gates 3c:RHC 带 options 的方案被点选;undefined=本会话无已确认方案) */
|
|
414
414
|
planConfirmation?: PlanConfirmationRecord;
|
|
415
415
|
/** 宿主动作元信息(actions 注册;集成方 save_draft/publish 等) */
|
|
416
|
-
actions?: Record<string, { description: string; hasParams: boolean }>;
|
|
416
|
+
actions?: Record<string, { description: string; hasParams: boolean; readsHostState?: boolean; deferredWrite?: boolean }>;
|
|
417
417
|
/** 跨压缩工作记忆(workingMemory 中间件;pin 最近 read/query/search 定位 path + read hash,≤10 LRU) */
|
|
418
418
|
workingMemory?: WorkingMemory;
|
|
419
419
|
/** 写驱动过期读失效会话累计(stale-read-invalidation;写后旧 read/query/search 结果被替换为占位的次数) */
|
|
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 时可观察) */
|
|
@@ -926,6 +928,10 @@ export interface ActionDef {
|
|
|
926
928
|
run: (args: Record<string, unknown>) => unknown | Promise<unknown>;
|
|
927
929
|
/** 可选参数 schema(ZodObject);不传 = 无参 tool */
|
|
928
930
|
params?: any;
|
|
931
|
+
/** 标记本 action 读取宿主态(4.20+):旧工具结果随 `sdk.notifyHostChange()` 替换为过期占位(修前仅 read_page 等五个内置页面读工具享受,action 仅靠 reason 文案口头告知);页面断言门禁的「页面依据」计数也计入。不标记 = 现行为零变化 */
|
|
932
|
+
readsHostState?: boolean;
|
|
933
|
+
/** 标记本 action 的效果延迟到用户确认才生效(提案类,4.20+):调用成功 ≠ 已写入 → 零工具门禁事实清单对此类调用注记「待用户确认后才生效」,防模型收口「已修改完成」;等效写计数不含此类。不标记 = 现行为零变化 */
|
|
934
|
+
deferredWrite?: boolean;
|
|
929
935
|
}
|
|
930
936
|
/** actions 配置:动作名 → 定义(动作名即 tool 名,须合法标识符) */
|
|
931
937
|
export type ActionMap = Record<string, ActionDef>;
|
|
@@ -1060,10 +1066,31 @@ export interface ChatSdkOptions {
|
|
|
1060
1066
|
onEvent?: SdkEventHandler;
|
|
1061
1067
|
/** 流式输出(默认 true);false 时等整段回复再显示 */
|
|
1062
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;
|
|
1063
1077
|
/** Dialog UI config (title/placeholder/drawer/drawerWidth/drawerHidden/inputRows/onClose grouped) */
|
|
1064
1078
|
dialog?: DialogConfig;
|
|
1065
1079
|
}
|
|
1066
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
|
+
}
|
|
1067
1094
|
/** Dialog UI config (grouped form, recommended) */
|
|
1068
1095
|
export interface DialogConfig {
|
|
1069
1096
|
title?: string;
|
|
@@ -1496,7 +1523,7 @@ export declare const getDomTool: any;
|
|
|
1496
1523
|
export declare function domToStructure(node: Element | null, opts: { depth: number; attrs?: string[]; includeText?: boolean }): DomNode | null;
|
|
1497
1524
|
/** 把集成方注册的 actions 转成命名 tool 数组(每个 action 一个 tool) */
|
|
1498
1525
|
export declare function actionsToTools(actions: ActionMap): any[];
|
|
1499
|
-
export declare function actionsToInspectInfo(actions: ActionMap): Record<string, { description: string; hasParams: boolean }>;
|
|
1526
|
+
export declare function actionsToInspectInfo(actions: ActionMap): Record<string, { description: string; hasParams: boolean; readsHostState: boolean; deferredWrite: boolean }>;
|
|
1500
1527
|
export interface DomNode { tag: string; attrs: Record<string, string>; text?: string; children?: DomNode[]; childCount?: number }
|
|
1501
1528
|
export interface DomReadOptions { depth: number; attrs?: string[]; includeText?: boolean }
|
|
1502
1529
|
|
|
@@ -1599,6 +1626,10 @@ export interface CreateAgentOptions {
|
|
|
1599
1626
|
* 传入(仅页面问答形态装配 —— 数据槽场景「页面上已改成…」误伤路径从结构上切断);false/缺省 = 门禁层不进判定。
|
|
1600
1627
|
*/
|
|
1601
1628
|
pageAssertionGate?: boolean;
|
|
1629
|
+
/** 有效页面读集扩展(action-host-semantics,4.20):宿主标记 readsHostState 的 action 名 —— 进页面断言门禁「页面依据」计数;缺省 = 仅默认五工具 */
|
|
1630
|
+
pageReadTools?: Set<string>;
|
|
1631
|
+
/** 延迟生效写 action 名集(action-host-semantics,4.20):零工具门禁事实清单对其调用注记「待用户确认后才生效」;缺省 = 清单与现行为逐字节一致 */
|
|
1632
|
+
deferredWriteTools?: Set<string>;
|
|
1602
1633
|
/** LLM 运行时切换回调(setLlm 后触发,供重解析模型能力 contextWindow/maxOutputTokens) */
|
|
1603
1634
|
onLlmChange?: (newLlm: import('@langchain/core/language_models/chat_models').BaseChatModel) => void;
|
|
1604
1635
|
/** 显式声明主模型是否多模态识图(声明 > 查表 > 缺省 false) */
|
package/types/index.d.ts
CHANGED
|
@@ -722,13 +722,15 @@ export interface AgentInfo {
|
|
|
722
722
|
/** 方案确认留痕(save-and-plan-gates 3c:RHC 带 options 的方案被点选;undefined=本会话无已确认方案) */
|
|
723
723
|
planConfirmation?: PlanConfirmationRecord;
|
|
724
724
|
/** 宿主动作元信息(actions 注册;集成方 save_draft/publish 等) */
|
|
725
|
-
actions?: Record<string, { description: string; hasParams: boolean }>;
|
|
725
|
+
actions?: Record<string, { description: string; hasParams: boolean; readsHostState?: boolean; deferredWrite?: boolean }>;
|
|
726
726
|
/** 跨压缩工作记忆(workingMemory 中间件;pin 最近 read/query/search 定位 path + read hash,≤10 LRU) */
|
|
727
727
|
workingMemory?: WorkingMemory;
|
|
728
728
|
/** 写驱动过期读失效会话累计(stale-read-invalidation;写后旧 read/query/search 结果被替换为占位的次数) */
|
|
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 时可观察) */
|
|
@@ -1286,6 +1288,10 @@ export interface ActionDef {
|
|
|
1286
1288
|
run: (args: Record<string, unknown>) => unknown | Promise<unknown>;
|
|
1287
1289
|
/** 可选参数 schema(ZodObject);不传 = 无参 tool */
|
|
1288
1290
|
params?: any;
|
|
1291
|
+
/** 标记本 action 读取宿主态(4.20+):旧工具结果随 `sdk.notifyHostChange()` 替换为过期占位(修前仅 read_page 等五个内置页面读工具享受,action 仅靠 reason 文案口头告知);页面断言门禁的「页面依据」计数也计入。不标记 = 现行为零变化 */
|
|
1292
|
+
readsHostState?: boolean;
|
|
1293
|
+
/** 标记本 action 的效果延迟到用户确认才生效(提案类,4.20+):调用成功 ≠ 已写入 → 零工具门禁事实清单对此类调用注记「待用户确认后才生效」,防模型收口「已修改完成」;等效写计数不含此类。不标记 = 现行为零变化 */
|
|
1294
|
+
deferredWrite?: boolean;
|
|
1289
1295
|
}
|
|
1290
1296
|
/** actions 配置:动作名 → 定义(动作名即 tool 名,须合法标识符) */
|
|
1291
1297
|
export type ActionMap = Record<string, ActionDef>;
|
|
@@ -1428,6 +1434,14 @@ export interface ChatSdkOptions {
|
|
|
1428
1434
|
dialog?: DialogConfig;
|
|
1429
1435
|
/** 国际化:locale 切语言 + messages 键级覆盖文案(3.22+;UI 文案包 + 默认 systemPrompt/autoTitle 语言;原 dialog.locale/dialog.messages 两键合并至此) */
|
|
1430
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;
|
|
1431
1445
|
}
|
|
1432
1446
|
|
|
1433
1447
|
/** Dialog UI config (grouped form, recommended) */
|
|
@@ -1480,6 +1494,19 @@ export interface QuickActionItem {
|
|
|
1480
1494
|
* 国际化配置(顶层 i18n;3.22 起,原 dialog.locale/dialog.messages 两键移入此处合并)。
|
|
1481
1495
|
* 不放 dialog 组:locale 除 UI 文案包外还驱动默认 systemPrompt 语言与 autoTitle 标题语言(agent 层)。
|
|
1482
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
|
+
}
|
|
1483
1510
|
export interface I18nOptions {
|
|
1484
1511
|
/** 语言:'zh-CN'(默认)/'en-US';切换内置文案包(聊天面 + Debug 抽屉 + Skill 面板 + 代码预览);
|
|
1485
1512
|
* formatTime(12h/24h)/autoTitle/默认 systemPrompt 跟随(en → 英文版身份 + "Respond in English" 锚,
|
|
@@ -1925,7 +1952,7 @@ export declare const getDomTool: any;
|
|
|
1925
1952
|
export declare function domToStructure(node: Element | null, opts: { depth: number; attrs?: string[]; includeText?: boolean }): DomNode | null;
|
|
1926
1953
|
/** 把集成方注册的 actions 转成命名 tool 数组(每个 action 一个 tool) */
|
|
1927
1954
|
export declare function actionsToTools(actions: ActionMap): any[];
|
|
1928
|
-
export declare function actionsToInspectInfo(actions: ActionMap): Record<string, { description: string; hasParams: boolean }>;
|
|
1955
|
+
export declare function actionsToInspectInfo(actions: ActionMap): Record<string, { description: string; hasParams: boolean; readsHostState: boolean; deferredWrite: boolean }>;
|
|
1929
1956
|
export interface DomNode { tag: string; attrs: Record<string, string>; text?: string; children?: DomNode[]; childCount?: number }
|
|
1930
1957
|
export interface DomReadOptions { depth: number; attrs?: string[]; includeText?: boolean }
|
|
1931
1958
|
|
|
@@ -2028,6 +2055,10 @@ export interface CreateAgentOptions {
|
|
|
2028
2055
|
* 传入(仅页面问答形态装配 —— 数据槽场景「页面上已改成…」误伤路径从结构上切断);false/缺省 = 门禁层不进判定。
|
|
2029
2056
|
*/
|
|
2030
2057
|
pageAssertionGate?: boolean;
|
|
2058
|
+
/** 有效页面读集扩展(action-host-semantics,4.20):宿主标记 readsHostState 的 action 名 —— 进页面断言门禁「页面依据」计数;缺省 = 仅默认五工具 */
|
|
2059
|
+
pageReadTools?: Set<string>;
|
|
2060
|
+
/** 延迟生效写 action 名集(action-host-semantics,4.20):零工具门禁事实清单对其调用注记「待用户确认后才生效」;缺省 = 清单与现行为逐字节一致 */
|
|
2061
|
+
deferredWriteTools?: Set<string>;
|
|
2031
2062
|
/** LLM 运行时切换回调(setLlm 后触发,供重解析模型能力 contextWindow/maxOutputTokens) */
|
|
2032
2063
|
onLlmChange?: (newLlm: import('@langchain/core/language_models/chat_models').BaseChatModel) => void;
|
|
2033
2064
|
/** 显式声明主模型是否多模态识图(声明 > 查表 > 缺省 false) */
|