page-agent-sdk 2.25.0 → 2.26.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 +9 -5
- package/README.zh-CN.md +8 -4
- package/dist/page-agent-sdk.iife.js +193 -187
- package/dist/page-agent-sdk.js +6409 -6283
- package/dist/page-agent-sdk.umd.cjs +129 -123
- package/package.json +1 -1
- package/types/index.d.ts +29 -1
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
|
|
|
@@ -249,6 +249,8 @@ createChatSdk({ tools: [myTool], /*...*/ })
|
|
|
249
249
|
|
|
250
250
|
// ② Custom skill (progressive disclosure: load_skill fetches details on demand)
|
|
251
251
|
const mySkill = defineSkill({ name: 'style_guide', description: 'Brand color spec', body: 'Primary #1f4d3a…' })
|
|
252
|
+
// Dynamic skill (skill-external-scripts): exec runs a script on load → inject live data; tools attaches callable tools
|
|
253
|
+
// defineSkill({ name: 'orders', getContent: () => 'spec…', exec: { code: '...', context: 'sandbox' }, tools: [() => orderQueryTool] })
|
|
252
254
|
createChatSdk({ skills: [mySkill], /*...*/ })
|
|
253
255
|
|
|
254
256
|
// ③ Custom middleware (8 hooks: beforeAgent/wrapModelCall/beforeModel/afterModel/wrapToolCall/afterAgent/beforeReturn + augmentPrompt/compressInput/tools)
|
|
@@ -268,7 +270,7 @@ createChatSdk({ subagents: [
|
|
|
268
270
|
- **window query**: `query_data` (JSONPath) / `search_data` (fuzzy) / `eval_script` (sandboxed)
|
|
269
271
|
- **fetch**: `fetch_document`
|
|
270
272
|
- **vfs**: `vfs_read` / `vfs_write` / `vfs_edit` / `vfs_ls` / `vfs_glob` / `vfs_grep`
|
|
271
|
-
- **planning/skills**: `write_todos` / `define_skill` / `load_skill`
|
|
273
|
+
- **planning/skills**: `write_todos` / `define_skill` / `load_skill` (skill can carry `exec` to run a script on load injecting live data + `tools` for repeatedly-callable tools; `exec.context:'host'` requires `capabilities.skillHostScript:true`)
|
|
272
274
|
- **human confirm**: `request_human_confirmation` (proactive inquiry, default on)
|
|
273
275
|
- **subagents**: `spawn_agent` / `spawn_agents` / `use_<id>` (pre-declared)
|
|
274
276
|
- **checkpoint**: `restore_last_checkpoint` / `list_checkpoints`
|
|
@@ -304,6 +306,8 @@ createChatSdk({ tools: [myTool], /*...*/ })
|
|
|
304
306
|
|
|
305
307
|
// ② Custom skill (progressive disclosure: load_skill fetches details on demand)
|
|
306
308
|
const mySkill = defineSkill({ name: 'style_guide', description: 'Brand color spec', body: 'Primary #1f4d3a…' })
|
|
309
|
+
// Dynamic skill (skill-external-scripts): exec runs a script on load → inject live data; tools attaches callable tools
|
|
310
|
+
// defineSkill({ name: 'orders', getContent: () => 'spec…', exec: { code: '...', context: 'sandbox' }, tools: [() => orderQueryTool] })
|
|
307
311
|
createChatSdk({ skills: [mySkill], /*...*/ })
|
|
308
312
|
|
|
309
313
|
// ③ Custom middleware (8 hooks: beforeAgent/wrapModelCall/beforeModel/afterModel/wrapToolCall/afterAgent/beforeReturn + augmentPrompt/compressInput/tools)
|
|
@@ -323,7 +327,7 @@ createChatSdk({ subagents: [
|
|
|
323
327
|
- **window query**: `query_data` (JSONPath) / `search_data` (fuzzy) / `eval_script` (sandboxed)
|
|
324
328
|
- **fetch**: `fetch_document`
|
|
325
329
|
- **vfs**: `vfs_read` / `vfs_write` / `vfs_edit` / `vfs_ls` / `vfs_glob` / `vfs_grep`
|
|
326
|
-
- **planning/skills**: `write_todos` / `define_skill` / `load_skill`
|
|
330
|
+
- **planning/skills**: `write_todos` / `define_skill` / `load_skill` (skill can carry `exec` to run a script on load injecting live data + `tools` for repeatedly-callable tools; `exec.context:'host'` requires `capabilities.skillHostScript:true`)
|
|
327
331
|
- **human confirm**: `request_human_confirmation` (proactive inquiry, default on)
|
|
328
332
|
- **subagents**: `spawn_agent` / `spawn_agents` / `use_<id>` (pre-declared)
|
|
329
333
|
- **checkpoint**: `restore_last_checkpoint` / `list_checkpoints`
|
|
@@ -515,8 +519,8 @@ function switchTo(i: number) {
|
|
|
515
519
|
## Self-tests
|
|
516
520
|
|
|
517
521
|
```bash
|
|
518
|
-
npm test #
|
|
519
|
-
npm run test:e2e #
|
|
522
|
+
npm test # 1231 assertions (tsx, source-level; no LLM dependency)
|
|
523
|
+
npm run test:e2e # 312 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)
|
|
520
524
|
```
|
|
521
525
|
|
|
522
526
|
## 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
|
|
|
@@ -247,6 +247,10 @@ createChatSdk({ tools: [myTool], /*...*/ })
|
|
|
247
247
|
// ② 自定义技能(渐进披露:用到才 load_skill 加载详情)
|
|
248
248
|
const mySkill = defineSkill({ name: 'style_guide', description: '品牌色规范', body: '主色 #1f4d3a…' })
|
|
249
249
|
createChatSdk({ skills: [mySkill], /*...*/ })
|
|
250
|
+
// 动态技能(skill-external-scripts):exec 加载时执行脚本注入实时数据 + tools 附带可反复调用的工具
|
|
251
|
+
// defineSkill({ name: 'orders', description: '订单概览', getContent: () => '说明…',
|
|
252
|
+
// exec: { code: 'return await fetch("/api/orders").then(r=>r.json())', context: 'sandbox' }, // 默认沙箱;host 需 capabilities.skillHostScript
|
|
253
|
+
// tools: [() => orderQueryTool] }) // load_skill 后注入工具池,可反复调
|
|
250
254
|
|
|
251
255
|
// ③ 自定义中间件(8 钩子:beforeAgent/wrapModelCall/beforeModel/afterModel/wrapToolCall/afterAgent/beforeReturn + augmentPrompt/compressInput/tools)
|
|
252
256
|
const mw: Middleware = { name: 'telemetry', afterModel: async (ctx, next) => { await next(ctx); console.log('round done') } }
|
|
@@ -268,7 +272,7 @@ createChatSdk({ subagents: [
|
|
|
268
272
|
- **上下文检查**(`capabilities.contextInspector` 默认开):`sdk.inspectContext()`/`inspect().context` 读每轮实际消息的分类 token 占比(system 段 / 工具结果 / 历史等),DebugDrawer「📊 上下文」tab 展示占用/分类/压缩;纯计算零 LLM 成本
|
|
269
273
|
- **宿主动作**(2.18+,`actions` 注册):集成方注册 save_draft/publish 等页面操作,SDK 自动生成命名 tool,agent 直接调用触发宿主(无需 trigger_action 中转)
|
|
270
274
|
- **vfs**:`vfs_read` / `vfs_write` / `vfs_edit` / `vfs_ls` / `vfs_glob` / `vfs_grep`
|
|
271
|
-
- **规划/技能**:`write_todos` / `define_skill` / `load_skill`
|
|
275
|
+
- **规划/技能**:`write_todos` / `define_skill` / `load_skill`(skill 可配 `exec` 加载时执行脚本注入实时数据 + `tools` 附带可反复调用的工具;`exec.context:'host'` 需 `capabilities.skillHostScript:true`)
|
|
272
276
|
- **人工确认**:`request_human_confirmation`(主动征询,默认开)
|
|
273
277
|
- **子 agent**:`spawn_agent` / `spawn_agents` / `use_<id>`(预声明)
|
|
274
278
|
- **checkpoint**:`restore_last_checkpoint` / `list_checkpoints`
|
|
@@ -460,8 +464,8 @@ function switchTo(i: number) {
|
|
|
460
464
|
## 自测
|
|
461
465
|
|
|
462
466
|
```bash
|
|
463
|
-
npm test #
|
|
464
|
-
npm run test:e2e #
|
|
467
|
+
npm test # 1231 项断言(tsx 源码级,不依赖 LLM)
|
|
468
|
+
npm run test:e2e # 312 项集成断言(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 配置 / 错误场景)
|
|
465
469
|
```
|
|
466
470
|
|
|
467
471
|
## 本地 npm 包测试
|