page-agent-sdk 2.32.1 → 2.34.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 +5 -4
- package/README.zh-CN.md +5 -4
- package/dist/page-agent-sdk.iife.js +140 -139
- package/dist/page-agent-sdk.js +4455 -3822
- package/dist/page-agent-sdk.umd.cjs +85 -84
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +133 -9
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
[](https://www.npmjs.com/package/page-agent-sdk)
|
|
10
10
|
[](https://github.com/whyymj/page-agent-sdk/blob/master/LICENSE)
|
|
11
|
-
[](#self-tests)
|
|
12
12
|
|
|
13
13
|
---
|
|
14
14
|
|
|
@@ -137,6 +137,7 @@ CDN zero-config: `<script src="https://unpkg.com/page-agent-sdk"></script>` →
|
|
|
137
137
|
| 💾 persistence | IndexedDB multi-session + quota eviction + switch | `storage` |
|
|
138
138
|
| 👁 DOM read (2.20+) | Read rendered DOM structure (depth-cutoff + attr whitelist); verify modifications took effect — distinct from `eval_script` (structured + read-only) | `capabilities.domInspect` |
|
|
139
139
|
| 📊 Context inspector | Snapshot actual-LLM-message composition (total / occupancy / category ratio); DebugDrawer `📊 上下文` tab + `inspectContext()`; zero LLM cost, default on | `capabilities.contextInspector` |
|
|
140
|
+
| 🤖 Agent-driven compression (2.33+) | `capabilities.agentCompression` (opt-in) lets the summary LLM decide per-trigger compression strategy via an `inspect_context` tool loop (keepRounds / windowRatio / summary mode / recall / preserve); `shouldTriggerCompression` gate avoids per-message LLM cost; decide failure/timeout degrades to static; `decisionTimeoutMs` / `decisionMaxTokens` configurable | `capabilities.agentCompression` + `summaryLlm` |
|
|
140
141
|
| ⚡ host actions (2.20+) | Register save/publish/preview etc; SDK auto-generates named tools, agent triggers page ops directly (no `trigger_action` indirection) | `actions` |
|
|
141
142
|
| 🧩 schema tiered disclosure (2.20+) | Large schema → systemPrompt injects top-level overview only (no constraints/no recursion); deep constraints via `schema_data` on demand; small schema unaffected (full) | `schemaHint` |
|
|
142
143
|
| 📌 cross-compress working memory (2.20+) | Pin recent read/query paths + hashes across compression; no re-fetch, correct optimistic-lock hash | `capabilities.workingMemory` |
|
|
@@ -221,7 +222,7 @@ ChatDialog, MessageContent, CodePreview, SkillPanel, useChat
|
|
|
221
222
|
| **Context** | `contextPreset` | `'auto' \| 'conservative' \| 'aggressive' \| 'complex'` · default `auto` | Compression preset (`complex` for multi-step / large-JSON / long-workflow tasks) |
|
|
222
223
|
| | `contextOptions` | `Partial<ContextManagerOptions> \| false` | Fine params (`false` disables compression). Includes `preserveLastToolResults` (default `['describe_data','describe_data']` — keep field descriptions in compressed summary) |
|
|
223
224
|
| | `summaryLlm` | `BaseChatModel \| LLMConfig` | Summary-dedicated LLM (defaults to main `llm`) |
|
|
224
|
-
| | `maxMemoryRounds` | `number` · default `
|
|
225
|
+
| | `maxMemoryRounds` | `number` · default `30` | Dialog history memory round cap (`0` disables trim) |
|
|
225
226
|
| | `vfs` | `{initialFiles?,maxBytes?}` · default 4MB | In-memory workspace cap (LRU evict on overflow) |
|
|
226
227
|
| **Persistence** | `storage` | `'indexed' \| 'session' \| 'local' \| 'memory' \| config \| false` · default off | Assign to enable; multi-agent isolated by `id` |
|
|
227
228
|
| | `session` | `{id?,autoResume?,title?}` | Session control |
|
|
@@ -525,8 +526,8 @@ function switchTo(i: number) {
|
|
|
525
526
|
## Self-tests
|
|
526
527
|
|
|
527
528
|
```bash
|
|
528
|
-
npm test #
|
|
529
|
-
npm run test:e2e #
|
|
529
|
+
npm test # 1550 assertions (tsx, source-level; no LLM dependency)
|
|
530
|
+
npm run test:e2e # 387 integration assertions (node, built dist; covers APIs/options/modules/simple&complex scenes: default systemPrompt(capability overview) / dynamic register + inspect sync / inspect(tools/middleware/subagent/verify/mcp/todos/lastCompression/checkpoints reflect config) / custom tools/middleware/skills/memory injection / runtime dynamic reconfiguration(setTools/addTool/removeTool/setLlm/setMemory/setSubagents reflect) / switchSession(on/off) / shareContext on/off sharing/independent / storage backends + object config / presets(3) / checkpoint / exports complete(39+ fns/components) / util fns usable(isQuotaError/estimateTokens/jpEval/searchJson) / source=builtin / mount boundary / hook multi-listener / llm config / hide/show / error scenes)
|
|
530
531
|
```
|
|
531
532
|
|
|
532
533
|
## Local npm package test
|
package/README.zh-CN.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
[](https://www.npmjs.com/package/page-agent-sdk)
|
|
10
10
|
[](https://github.com/whyymj/page-agent-sdk/blob/master/LICENSE)
|
|
11
|
-
[](#自测)
|
|
12
12
|
|
|
13
13
|
---
|
|
14
14
|
|
|
@@ -218,7 +218,7 @@ ChatDialog, MessageContent, CodePreview, SkillPanel, useChat
|
|
|
218
218
|
| **上下文** | `contextPreset` | `'auto' \| 'conservative' \| 'aggressive' \| 'complex'` · 默认 `auto` | 压缩预设档位(`complex` 面向多步 / 大 JSON / 长流程编排任务) |
|
|
219
219
|
| | `contextOptions` | `Partial<ContextManagerOptions> \| false` | 细参覆盖(`false` 关压缩)。含 `preserveLastToolResults`(默认 `['describe_data','describe_data']`——压缩摘要里保留字段说明) |
|
|
220
220
|
| | `summaryLlm` | `BaseChatModel \| LLMConfig` | 摘要专用 LLM(不配用主 `llm`) |
|
|
221
|
-
| | `maxMemoryRounds` | `number` · 默认 `
|
|
221
|
+
| | `maxMemoryRounds` | `number` · 默认 `30` | 对话历史内存上限轮次(`0` 关裁剪) |
|
|
222
222
|
| | `vfs` | `{initialFiles?,maxBytes?}` · 默认 4MB | 内存工作区上限(超限 LRU 淘汰) |
|
|
223
223
|
| **持久化** | `storage` | `'indexed' \| 'session' \| 'local' \| 'memory' \| 配置 \| false` · 默认关 | 赋值开启;多 agent 靠 `id` 隔离 |
|
|
224
224
|
| | `session` | `{id?,autoResume?,title?}` | 会话控制 |
|
|
@@ -273,6 +273,7 @@ createChatSdk({ subagents: [
|
|
|
273
273
|
- **抓取**:`fetch_document`
|
|
274
274
|
- **DOM 读取**(2.18+,`capabilities.domInspect:true` 开,默认关):`get_dom`(读渲染后 DOM 结构,看修改是否生效;区别于 eval_script 的结构化只读)
|
|
275
275
|
- **上下文检查**(`capabilities.contextInspector` 默认开):`sdk.inspectContext()`/`inspect().context` 读每轮实际消息的分类 token 占比(system 段 / 工具结果 / 历史等),DebugDrawer「📊 上下文」tab 展示占用/分类/压缩;纯计算零 LLM 成本
|
|
276
|
+
- **压缩决策**(`capabilities.agentCompression` opt-in 默认关,需 `summaryLlm`,2.33+):开 + summaryLlm 可用 → summarization 每轮先 `shouldTriggerCompression` gate(纯函数 token/轮数两模式,避免每条消息都 decide 烧 LLM)→ `decide` 两段式工具循环(bind `inspect_context` 查构成 → 输出决策 JSON)→ `compress(messages, decision)` 用决策切分/摘要 mode/召回/preserve(∪ 扩展);decide 失败/超时/模型不支持工具 → null 降级静态压缩(零阻塞)。`decisionTimeoutMs`(默认 6s)/`decisionMaxTokens`(默认 2048)可配;决策自动流到 `inspect().lastCompression.decision` + DebugDrawer「🤖 agent 决策」注记
|
|
276
277
|
- **宿主动作**(2.18+,`actions` 注册):集成方注册 save_draft/publish 等页面操作,SDK 自动生成命名 tool,agent 直接调用触发宿主(无需 trigger_action 中转)
|
|
277
278
|
- **vfs**:`vfs_read` / `vfs_write` / `vfs_edit` / `vfs_ls` / `vfs_glob` / `vfs_grep`
|
|
278
279
|
- **规划/技能**:`write_todos` / `define_skill` / `load_skill`(skill 可配 `exec` 加载时执行脚本注入实时数据 + `tools` 附带可反复调用的工具;`exec.context:'host'` 需 `capabilities.skillHostScript:true`)
|
|
@@ -470,8 +471,8 @@ function switchTo(i: number) {
|
|
|
470
471
|
## 自测
|
|
471
472
|
|
|
472
473
|
```bash
|
|
473
|
-
npm test #
|
|
474
|
-
npm run test:e2e #
|
|
474
|
+
npm test # 1550 项断言(tsx 源码级,不依赖 LLM)
|
|
475
|
+
npm run test:e2e # 387 项集成断言(node 跑构建产物 dist;覆盖各 API/配置项/功能模块/简单与复杂场景:默认 systemPrompt(含能力概述) / 动态注册与 inspect 同步 / inspect(tools/middleware/subagent/verify/mcp/todos/lastCompression/checkpoints 反映配置) / 自定义 tools/middleware/skills/memory 注入 / 运行时动态重配置(setTools/addTool/removeTool/setLlm/setMemory/setSubagents 反映) / switchSession(开/未开) / shareContext 开/关共享独立 / storage 后端+对象配置 / presets 三预设 / checkpoint / 导出项完整(39+ 函数/组件) / 工具函数可用(isQuotaError/estimateTokens/jpEval/searchJson) / source=builtin / mount 边界 / hook 多监听器 / llm 配置 / 错误场景)
|
|
475
476
|
```
|
|
476
477
|
|
|
477
478
|
## 本地 npm 包测试
|