page-agent-sdk 2.15.1 → 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/README.md +6 -5
- package/README.zh-CN.md +6 -5
- package/dist/page-agent-sdk.iife.js +121 -119
- package/dist/page-agent-sdk.js +1578 -1025
- package/dist/page-agent-sdk.umd.cjs +45 -43
- package/package.json +1 -1
- package/skills/page-agent-sdk-integrate/references/api.md +29 -0
- package/types/index.d.ts +52 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "page-agent-sdk",
|
|
3
|
-
"version": "2.
|
|
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",
|
|
@@ -128,6 +128,35 @@ Example: `write({ value: 9.9, patch: { op: 'set', jsonPath: 'items.0.price' } })
|
|
|
128
128
|
|
|
129
129
|
`fetch_document` — GET a URL, return cleaned text (HTML→markdown, truncated, offloaded to vfs if large).
|
|
130
130
|
|
|
131
|
+
## Built-in vfs tools (`capabilities.vfs`, default on)
|
|
132
|
+
|
|
133
|
+
The virtual file workspace holds tool-result offloads (>6000 chars), agent/integrator drafts, and user files. 2.16.0+ partitions it into three independent LRU pools (`large_results/*` / `drafts/*` / `userFiles`), so offloaded results can't evict drafts or user files.
|
|
134
|
+
|
|
135
|
+
| Tool | Signature | Purpose |
|
|
136
|
+
|---|---|---|
|
|
137
|
+
| `vfs_read` | `({ path }) => string` | Read a file (path may be returned by a prior offload). |
|
|
138
|
+
| `vfs_write` | `({ path, content, jsonString? }) => meta` | Write/overwrite a file. `jsonString:true` (2.16.0+) validates `content` is valid JSON before writing (invalid → `VFS_JSON_INVALID`, not written). |
|
|
139
|
+
| `vfs_grep` | `({ pattern, paths? }) => matches` | Grep across workspace files. |
|
|
140
|
+
| `vfs_json_read` (2.16.0+) | `({ path, jsonPath? }) => json\|string` | Read a JSON subtree from a vfs file via jsonPath (omit for the whole file). Returns `VFS_JSON_INVALID` if the file isn't valid JSON; `VFS_PATH_NOT_FOUND` if jsonPath doesn't exist. |
|
|
141
|
+
| `vfs_json_patch` (2.16.0+) | `({ path, patches: [{op:'set'\|'remove'\|'merge'\|'append', jsonPath, value?}] }) => meta` | Atomic jsonPath patch inside a vfs file. Applied on a clone; any patch failure → `PATCH_FAILED`, original file unchanged. Avoids re-sending large JSON (delta only). |
|
|
142
|
+
|
|
143
|
+
## Context compression presets (`contextPreset`)
|
|
144
|
+
|
|
145
|
+
`contextPreset` is a one-line knob over the `summarization` middleware (ratio-based); `contextOptions` overrides individual fields.
|
|
146
|
+
|
|
147
|
+
| Preset | When | Profile |
|
|
148
|
+
|---|---|---|
|
|
149
|
+
| `auto` (default) | General chat | window 0.4 / threshold 0.5 / recall Top-3 / LLM summary |
|
|
150
|
+
| `conservative` | Big models / cost | window 0.5 / threshold 0.7 / recall Top-2 / index summary (no LLM) |
|
|
151
|
+
| `aggressive` | Small models / save context | window 0.3 / threshold 0.3 / recall Top-5 |
|
|
152
|
+
| `complex` (2.16.0+) | Multi-step complex tasks / large JSON / long workflows | windowRatio 0.6 / summaryThresholdRatio 0.7 / recall Top-5 / LLM summary; `preserveLastToolResults` defaults to `['describe_data','read','query_data','search_data']` |
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
createChatSdk({ contextPreset: 'complex', contextOptions: { recallTopK: 8 } })
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
`inspect().contextPreset` (2.16.0+) exposes the effective preset.
|
|
159
|
+
|
|
131
160
|
## SdkEvent types (for `onEvent` / `sdk.hook`)
|
|
132
161
|
|
|
133
162
|
| `type` | Payload | When |
|
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 {
|
|
@@ -135,6 +135,8 @@ export interface AgentInfo {
|
|
|
135
135
|
tools: ToolInfo[];
|
|
136
136
|
skills: SkillInfo[];
|
|
137
137
|
data?: DataInfo;
|
|
138
|
+
/** 当前上下文压缩预设(默认 auto;complex 为多步复杂任务/大 JSON 场景) */
|
|
139
|
+
contextPreset: 'auto' | 'conservative' | 'aggressive' | 'complex';
|
|
138
140
|
memory: string;
|
|
139
141
|
middleware: string[];
|
|
140
142
|
todos: { content: string; status: string }[];
|
|
@@ -464,8 +466,8 @@ export interface ChatSdkOptions {
|
|
|
464
466
|
mcp?: McpServerConfig[];
|
|
465
467
|
/** 上下文压缩配置(false 关闭;默认 LLM 摘要,失败回退索引摘要) */
|
|
466
468
|
contextOptions?: any;
|
|
467
|
-
/** 上下文压缩预设档位(默认 'auto'):auto / conservative / aggressive;提供合理默认,contextOptions 细参可覆盖 */
|
|
468
|
-
contextPreset?: 'auto' | 'conservative' | 'aggressive';
|
|
469
|
+
/** 上下文压缩预设档位(默认 'auto'):auto / conservative / aggressive / complex(多步复杂任务/大 JSON);提供合理默认,contextOptions 细参可覆盖 */
|
|
470
|
+
contextPreset?: 'auto' | 'conservative' | 'aggressive' | 'complex';
|
|
469
471
|
/** 摘要压缩专用 LLM(BaseChatModel 实例或 LLMConfig);不传则默认用主 agent 模型(llm) */
|
|
470
472
|
summaryLlm?: any;
|
|
471
473
|
/** 摘要 LLM 温度(默认 0.3) */
|
|
@@ -637,6 +639,8 @@ export declare function applyPatchToClone(clone: any, op: EditOp, jsonPath: stri
|
|
|
637
639
|
export declare function applyPatchToLive(bind: any, op: EditOp, jsonPath: string, value: unknown): void;
|
|
638
640
|
export declare function restoreLive(bind: any, snapshotVal: unknown): void;
|
|
639
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 }[];
|
|
640
644
|
// ============ schema 白名单投影纯函数(schemaUtils,refactor-module-extraction 从 dataOps 抽离)============
|
|
641
645
|
export declare function getSchemaTopKeys(schema: any): string[] | null;
|
|
642
646
|
export declare function isPathAllowed(jsonPath: string, schema: any | null, allowKeys: string[] | null): boolean;
|
|
@@ -644,6 +648,33 @@ export declare function unwrapSchema(schema: any): any;
|
|
|
644
648
|
export declare function getSchemaAtPath(schema: any, jsonPath: string): any | null;
|
|
645
649
|
export declare function projectBySchemaDeep(obj: unknown, schema: any | null): unknown;
|
|
646
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;
|
|
647
678
|
// ============ 上下文索引纯函数(contextIndex,refactor-module-extraction 期二 从 useContextManager 抽离)============
|
|
648
679
|
export declare const STOP_WORDS: Set<string>;
|
|
649
680
|
export declare function tokenize(text: string): string[];
|
|
@@ -768,6 +799,24 @@ export declare function zodError(path: string, issues: unknown[]): string;
|
|
|
768
799
|
export declare function jsonParseError(path: string | undefined, raw: string, err: unknown): string;
|
|
769
800
|
/** 提取 zod issues 为结构化 details(每条 path/expected/received/message) */
|
|
770
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;
|
|
771
820
|
|
|
772
821
|
// === 与 src/core/index.ts 导出对齐(消费者类型完整;复杂内部类型用宽松声明,消费者主要消费工厂返回值) ===
|
|
773
822
|
// 上下文压缩预设
|