page-agent-sdk 2.1.0 → 2.4.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 +16 -9
- package/README.zh-CN.md +15 -8
- package/dist/page-agent-sdk.iife.js +119 -112
- package/dist/page-agent-sdk.js +3040 -2835
- package/dist/page-agent-sdk.umd.cjs +71 -64
- package/package.json +1 -1
- package/skills/page-agent-sdk-integrate/SKILL.md +5 -5
- package/skills/page-agent-sdk-integrate/references/advanced.md +5 -5
- package/skills/page-agent-sdk-integrate/references/api.md +52 -24
- package/skills/page-agent-sdk-integrate/references/quickstart.md +2 -2
- package/skills/page-agent-sdk-integrate/references/use-cases.md +7 -7
- package/types/index.d.ts +32 -2
package/README.md
CHANGED
|
@@ -25,8 +25,8 @@ At its core, it gives the AI a **standardized, safe JSON-operation channel**. AI
|
|
|
25
25
|
| Constraint | Mechanism | Effect |
|
|
26
26
|
|---|---|---|
|
|
27
27
|
| **Scope control** | Property registry (`dataSlots`) — only declared paths are writable | AI touching undeclared fields → rejected |
|
|
28
|
-
| **Validity check** | zod schema — `set`/`edit` validated against schema | Invalid type/enum/structure → structured error, no write |
|
|
29
|
-
| **Incremental op** | `edit_data_slot` patches by `jsonPath` (set/remove/merge/append) | Avoid re-sending the whole large JSON; precise local edits |
|
|
28
|
+
| **Validity check** | zod schema — `write`/`set`/`edit` validated against schema | Invalid type/enum/structure → structured error, no write |
|
|
29
|
+
| **Incremental op** | `write` with `patch` (or advanced `edit_data_slot`) patches by `jsonPath` (set/remove/merge/append) | Avoid re-sending the whole large JSON; precise local edits |
|
|
30
30
|
| **Rollbackable** | per-path snapshots (auto-stacked) + session checkpoint | Bad edit → one-click restore to the last good state |
|
|
31
31
|
| **Optimistic lock** | `expectedHash` on `set`/`edit`/`delete` + conflict human-in-the-loop | Concurrent external edits detected → suspend, user picks keep/overwrite/restore |
|
|
32
32
|
|
|
@@ -68,12 +68,12 @@ createChatSdk({
|
|
|
68
68
|
{ path: 'page.title', description: 'Page title', schema: z.string() },
|
|
69
69
|
{ path: 'page.theme', description: 'Theme', schema: z.enum(['light', 'dark']) },
|
|
70
70
|
],
|
|
71
|
-
approval: { tools: ['
|
|
71
|
+
approval: { tools: ['write'] }, // confirm writes
|
|
72
72
|
checkpoint: true, // one-click rollback on mistake
|
|
73
73
|
}).mount()
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
User says "title → 'Summer New', theme → dark" → AI calls `
|
|
76
|
+
User says "title → 'Summer New', theme → dark" → AI calls `write` with `patch` (incremental) → schema validation → pre-write confirm → reactive refresh. Said wrong? Click "↩ Undo".
|
|
77
77
|
|
|
78
78
|
CDN zero-config: `<script src="https://unpkg.com/page-agent-sdk"></script>` → `ChatSdk.createChatSdk({...})`.
|
|
79
79
|
|
|
@@ -175,7 +175,7 @@ createChatSdk({ subagents: [
|
|
|
175
175
|
|
|
176
176
|
### Built-in tools (Agent-callable)
|
|
177
177
|
|
|
178
|
-
- **
|
|
178
|
+
- **data slot ops** (default `toolMode:'simple'`): `read` (list/get/describe merged) / `write` (set/edit/delete merged + auto optimistic lock + auto snapshot) — recommended; `toolMode:'advanced'` also exposes low-level `list_data_slots` / `describe_data_slot` / `get_data_slot` / `get_slot_paths` / `set_data_slot` / `edit_data_slot` (jsonPath patch) / `delete_data_slot` / `snapshot_data_slot` / `list_data_snapshots` / `restore_data_snapshot`
|
|
179
179
|
- **window query**: `query_data_slot` (JSONPath) / `search_data_slot` (fuzzy) / `eval_script` (sandboxed)
|
|
180
180
|
- **fetch**: `fetch_document`
|
|
181
181
|
- **vfs**: `vfs_read` / `vfs_write` / `vfs_edit` / `vfs_ls` / `vfs_glob` / `vfs_grep`
|
|
@@ -230,7 +230,7 @@ createChatSdk({ subagents: [
|
|
|
230
230
|
|
|
231
231
|
### Built-in tools (Agent-callable)
|
|
232
232
|
|
|
233
|
-
- **
|
|
233
|
+
- **data slot ops** (default `toolMode:'simple'`): `read` (list/get/describe merged) / `write` (set/edit/delete merged + auto optimistic lock + auto snapshot) — recommended; `toolMode:'advanced'` also exposes low-level `list_data_slots` / `describe_data_slot` / `get_data_slot` / `get_slot_paths` / `set_data_slot` / `edit_data_slot` (jsonPath patch) / `delete_data_slot` / `snapshot_data_slot` / `list_data_snapshots` / `restore_data_snapshot`
|
|
234
234
|
- **window query**: `query_data_slot` (JSONPath) / `search_data_slot` (fuzzy) / `eval_script` (sandboxed)
|
|
235
235
|
- **fetch**: `fetch_document`
|
|
236
236
|
- **vfs**: `vfs_read` / `vfs_write` / `vfs_edit` / `vfs_ls` / `vfs_glob` / `vfs_grep`
|
|
@@ -320,12 +320,19 @@ createChatSdk({
|
|
|
320
320
|
llm: { apiKey, baseUrl, model },
|
|
321
321
|
id: 'my-agent', // stable id (multi-agent isolation + persistence resume)
|
|
322
322
|
systemPrompt: '...',
|
|
323
|
-
dataSlots: [{ path, description, schema }],
|
|
323
|
+
dataSlots: [{ path, description, schema, bind }], // bind: reactive/plain object auto-mounted to window[path] + registered as dataSlot; schema field .describe() auto-injected into systemPrompt「可操作属性」section
|
|
324
|
+
toolMode: 'simple', // tool presentation: simple (default, promotes read/write) / advanced (all) / minimal (read/write only)
|
|
325
|
+
interceptors: { // read/write interceptors (desensitize/transform/audit/reject; input/output at agent IO entry/exit)
|
|
326
|
+
read: (path, value) => path.endsWith('secret') ? '***' : value,
|
|
327
|
+
write: (path, payload) => path === 'app.locked' ? { error: 'locked' } : payload,
|
|
328
|
+
input: (msg) => msg, // preprocess at send entry
|
|
329
|
+
output: (reply) => reply, // postprocess before return
|
|
330
|
+
},
|
|
324
331
|
storage: 'indexed', // persistence (default off)
|
|
325
332
|
streaming: true, ui: 'default',
|
|
326
333
|
capabilities: { verify: true }, // capability toggles
|
|
327
334
|
humanConfirm: true, // proactive inquiry (default on)
|
|
328
|
-
approval: { tools: ['
|
|
335
|
+
approval: { tools: ['write'] }, // passive confirm whitelist (default off)
|
|
329
336
|
checkpoint: true,
|
|
330
337
|
contextPreset: 'auto', // auto/conservative/aggressive
|
|
331
338
|
summaryLlm: { ... }, // summary-dedicated LLM (defaults to main llm)
|
|
@@ -406,7 +413,7 @@ createChatSdk({
|
|
|
406
413
|
}).mount()
|
|
407
414
|
```
|
|
408
415
|
|
|
409
|
-
`npx vite` → type "change app.theme to dark" in the dialog → AI calls `
|
|
416
|
+
`npx vite` → type "change app.theme to dark" in the dialog → AI calls `write({ path:'app.theme', value:'dark' })` → `window.app.theme` becomes `dark` → verified.
|
|
410
417
|
|
|
411
418
|
> Add this test dir to `.gitignore` (local only, not in repo) to avoid committing `.env` with real keys to remotes.
|
|
412
419
|
|
package/README.zh-CN.md
CHANGED
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
| 约束 | 机制 | 作用 |
|
|
26
26
|
|---|---|---|
|
|
27
27
|
| **范围控制** | 属性注册表(`dataSlots`)—— 只能动声明的 path | AI 越界改未注册字段 → 拒绝 |
|
|
28
|
-
| **合法性校验** | zod schema —— `set`/`edit` 按 schema 校验 | 类型/枚举/结构不合法 → 结构化错误,不写入 |
|
|
29
|
-
| **增量操作** | `edit_data_slot`
|
|
28
|
+
| **合法性校验** | zod schema —— `write`/`set`/`edit` 按 schema 校验 | 类型/枚举/结构不合法 → 结构化错误,不写入 |
|
|
29
|
+
| **增量操作** | `write` 的 `patch`(或 advanced `edit_data_slot`)按 `jsonPath` 发 patch(set/remove/merge/append) | 避免重传整个大 JSON,精确改局部 |
|
|
30
30
|
| **可回滚** | per-path 快照(自动入栈)+ 会话 checkpoint | 改坏了一键回退到上次正常态 |
|
|
31
31
|
| **乐观锁** | `set`/`edit`/`delete` 传 `expectedHash` + 冲突人工介入 | 检测并发外部修改 → 挂起,用户选保留/覆盖/回退 |
|
|
32
32
|
|
|
@@ -68,12 +68,12 @@ createChatSdk({
|
|
|
68
68
|
{ path: 'page.title', description: '页面标题', schema: z.string() },
|
|
69
69
|
{ path: 'page.theme', description: '主题', schema: z.enum(['light', 'dark']) },
|
|
70
70
|
],
|
|
71
|
-
approval: { tools: ['
|
|
71
|
+
approval: { tools: ['write'] }, // 写操作弹确认
|
|
72
72
|
checkpoint: true, // 误改一键回退
|
|
73
73
|
}).mount()
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
用户说「标题改成『夏日新品』、主题切深色」→ AI 调 `
|
|
76
|
+
用户说「标题改成『夏日新品』、主题切深色」→ AI 调 `write` 用 `patch` 增量改 → schema 校验 → 写前确认 → 响应式刷新。说错了?点「↩ 回退」。
|
|
77
77
|
|
|
78
78
|
CDN 零配置:`<script src="https://unpkg.com/page-agent-sdk"></script>` → `ChatSdk.createChatSdk({...})`。
|
|
79
79
|
|
|
@@ -175,7 +175,7 @@ createChatSdk({ subagents: [
|
|
|
175
175
|
|
|
176
176
|
### 内置工具(Agent 可调用)
|
|
177
177
|
|
|
178
|
-
-
|
|
178
|
+
- **数据槽操作**(默认 `toolMode:'simple'`):`read`(合并 list/get/describe)/ `write`(合并 set/edit/delete + 自动乐观锁 + 自动快照)—— 推荐;`toolMode:'advanced'` 另暴露底层 `list_data_slots` / `describe_data_slot` / `get_data_slot` / `get_slot_paths` / `set_data_slot` / `edit_data_slot`(jsonPath 增量 patch)/ `delete_data_slot` / `snapshot_data_slot` / `list_data_snapshots` / `restore_data_snapshot`
|
|
179
179
|
- **window 查询**:`query_data_slot`(JSONPath)/ `search_data_slot`(模糊搜索)/ `eval_script`(沙箱脚本)
|
|
180
180
|
- **抓取**:`fetch_document`
|
|
181
181
|
- **vfs**:`vfs_read` / `vfs_write` / `vfs_edit` / `vfs_ls` / `vfs_glob` / `vfs_grep`
|
|
@@ -265,12 +265,19 @@ createChatSdk({
|
|
|
265
265
|
llm: { apiKey, baseUrl, model },
|
|
266
266
|
id: 'my-agent', // 稳定 id(多 agent 隔离 + 持久化恢复)
|
|
267
267
|
systemPrompt: '...',
|
|
268
|
-
dataSlots: [{ path, description, schema }],
|
|
268
|
+
dataSlots: [{ path, description, schema, bind }], // bind:reactive/普通对象自动挂 window[path] + 注册为 dataSlot;schema 字段 .describe() 自动注入 systemPrompt「可操作属性」段
|
|
269
|
+
toolMode: 'simple', // 工具呈现:simple(默认,主推 read/write)/ advanced(全暴露)/ minimal(只 read/write)
|
|
270
|
+
interceptors: { // 读写拦截器(脱敏/转换/审计/拒绝 LLM 读写;input/output 在 agent IO 入口/出口)
|
|
271
|
+
read: (path, value) => path.endsWith('secret') ? '***' : value,
|
|
272
|
+
write: (path, payload) => path === 'app.locked' ? { error: 'locked' } : payload,
|
|
273
|
+
input: (msg) => msg, // send 入口预处理
|
|
274
|
+
output: (reply) => reply, // 返回前 postprocess
|
|
275
|
+
},
|
|
269
276
|
storage: 'indexed', // 持久化(默认关)
|
|
270
277
|
streaming: true, ui: 'default',
|
|
271
278
|
capabilities: { verify: true }, // 能力开关
|
|
272
279
|
humanConfirm: true, // 主动征询(默认开;AI 不确定/多方案主动问你)
|
|
273
|
-
approval: { tools: ['
|
|
280
|
+
approval: { tools: ['write'] }, // 被动确认白名单(默认关)
|
|
274
281
|
checkpoint: true,
|
|
275
282
|
contextPreset: 'auto', // auto/conservative/aggressive
|
|
276
283
|
summaryLlm: { ... }, // 摘要专用 LLM(不配用主 llm)
|
|
@@ -351,7 +358,7 @@ createChatSdk({
|
|
|
351
358
|
}).mount()
|
|
352
359
|
```
|
|
353
360
|
|
|
354
|
-
`npx vite` → 对话框输入「把 app.theme 改成 dark」→ AI 调 `
|
|
361
|
+
`npx vite` → 对话框输入「把 app.theme 改成 dark」→ AI 调 `write({ path:"app.theme", value:"dark" })` → `window.app.theme` 变为 `dark` 即验证通过。
|
|
355
362
|
|
|
356
363
|
> 建议此测试目录加入 `.gitignore`(纯本地,不进仓库),避免把含真实 key 的 `.env` 提交到远程。
|
|
357
364
|
|