page-agent-sdk 2.16.0 → 2.17.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.16.0",
3
+ "version": "2.17.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
@@ -75,7 +75,7 @@ export type SdkEvent =
75
75
  | { type: 'conflict'; conflict: PendingConflict }
76
76
  | { type: 'session_restored'; sessionId: string; rounds: number }
77
77
  | { type: 'usage'; round: number; usage: TokenUsage; cumulative: TokenUsage }
78
- | { type: 'error'; message: string };
78
+ | { type: 'error'; message: string; severity?: 'recoverable' | 'fatal' | 'observable'; code?: string; context?: unknown };
79
79
 
80
80
  /** token 用量(OpenAI 协议字段名) */
81
81
  export interface TokenUsage {
@@ -639,6 +639,8 @@ export declare function applyPatchToClone(clone: any, op: EditOp, jsonPath: stri
639
639
  export declare function applyPatchToLive(bind: any, op: EditOp, jsonPath: string, value: unknown): void;
640
640
  export declare function restoreLive(bind: any, snapshotVal: unknown): void;
641
641
  export declare function restoreInPlace(live: Record<string, unknown> | unknown[], snapshotVal: unknown): void;
642
+ /** 深度差异对比(对象/数组递归,叶子差异),返回 {path, from, to}[];供 diff_data / verify 自纠 / 审计复用 */
643
+ export declare function diffObjects(a: unknown, b: unknown, prefix?: string): { path: string; from: unknown; to: unknown }[];
642
644
  // ============ schema 白名单投影纯函数(schemaUtils,refactor-module-extraction 从 dataOps 抽离)============
643
645
  export declare function getSchemaTopKeys(schema: any): string[] | null;
644
646
  export declare function isPathAllowed(jsonPath: string, schema: any | null, allowKeys: string[] | null): boolean;
@@ -646,6 +648,33 @@ export declare function unwrapSchema(schema: any): any;
646
648
  export declare function getSchemaAtPath(schema: any, jsonPath: string): any | null;
647
649
  export declare function projectBySchemaDeep(obj: unknown, schema: any | null): unknown;
648
650
  export declare function projectBySchema(obj: unknown, allowKeys: string[] | null): unknown;
651
+ // ============ schema 约束结构化提取(expose-schema-constraints;供 systemPrompt「可操作数据」段 / read 概览 / schema_data 工具)============
652
+ export interface SchemaNodeDesc {
653
+ type: string;
654
+ constraints?: {
655
+ minLength?: number; maxLength?: number; length?: number;
656
+ min?: number; max?: number; int?: boolean;
657
+ format?: string | string[];
658
+ values?: readonly (string | number)[];
659
+ value?: unknown;
660
+ item?: SchemaNodeDesc;
661
+ shape?: Record<string, SchemaNodeDesc>;
662
+ anyOf?: SchemaNodeDesc[];
663
+ valueType?: SchemaNodeDesc;
664
+ };
665
+ optional?: boolean;
666
+ nullable?: boolean;
667
+ default?: unknown;
668
+ description?: string;
669
+ }
670
+ /** 结构化提取单个 zod 节点的约束(type + 关键约束 + optional/default/nullable;zod 4 `_def`/`_zod.def` 读取) */
671
+ export declare function describeSchemaNode(schema: any): SchemaNodeDesc;
672
+ /** 把标量约束格式化为括号内短串(min/max/enum/format 等;shape/item/anyOf 不渲染) */
673
+ export declare function formatConstraints(c: NonNullable<SchemaNodeDesc['constraints']>): string;
674
+ /** 渲染单行字段标注 `- key (Type?)[约束]: description` */
675
+ export declare function renderSchemaHint(key: string, desc: SchemaNodeDesc): string;
676
+ /** 渲染 schema 顶层字段约束总览(非 object fallback 根节点;供 extractSchemaHint + read 概览复用) */
677
+ export declare function renderSchemaOverview(schema: any): string;
649
678
  // ============ 上下文索引纯函数(contextIndex,refactor-module-extraction 期二 从 useContextManager 抽离)============
650
679
  export declare const STOP_WORDS: Set<string>;
651
680
  export declare function tokenize(text: string): string[];
@@ -770,6 +799,24 @@ export declare function zodError(path: string, issues: unknown[]): string;
770
799
  export declare function jsonParseError(path: string | undefined, raw: string, err: unknown): string;
771
800
  /** 提取 zod issues 为结构化 details(每条 path/expected/received/message) */
772
801
  export declare function formatZodIssues(issues: unknown[]): unknown[];
802
+ // ============ 统一错误模型(unify-error-model:三档 severity,各 catch 点按档路由)============
803
+ /** 错误严重程度三档:recoverable(回灌)/ fatal(中断)/ observable(记录不中断) */
804
+ export type ErrorSeverity = 'recoverable' | 'fatal' | 'observable';
805
+ /** 统一错误对象(结构化,跨层传递;普通 Error 经 asAgentError 归一化) */
806
+ export interface AgentError {
807
+ severity: ErrorSeverity;
808
+ message: string;
809
+ code?: string;
810
+ context?: unknown;
811
+ }
812
+ /** 错误路由:recoverable→feedback / fatal→abort / observable→log */
813
+ export type ErrorRouting = 'feedback' | 'abort' | 'log';
814
+ /** 路由纯函数:据 severity 决定错误如何被处理 */
815
+ export declare function routeError(err: AgentError): ErrorRouting;
816
+ /** 把任意错误归一化为 AgentError(已是 AgentError 不覆盖;普通 Error 用 defaultSeverity,默认 fatal) */
817
+ export declare function asAgentError(err: unknown, defaultSeverity?: ErrorSeverity): AgentError;
818
+ /** AgentError 便捷工厂 */
819
+ export declare function agentError(severity: ErrorSeverity, message: string, code?: string, context?: unknown): AgentError;
773
820
 
774
821
  // === 与 src/core/index.ts 导出对齐(消费者类型完整;复杂内部类型用宽松声明,消费者主要消费工厂返回值) ===
775
822
  // 上下文压缩预设