page-agent-sdk 2.7.0 → 2.7.1
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 +26 -0
- package/README.zh-CN.md +26 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -102,6 +102,32 @@ CDN zero-config: `<script src="https://unpkg.com/page-agent-sdk"></script>` →
|
|
|
102
102
|
|
|
103
103
|
Capabilities default on (`verify`/`approval`/`checkpoint` default off; **proactive `humanConfirm` default on** — AI asks when uncertain/multi-plan instead of guessing). Turn off unneeded ones via `capabilities` to save tokens.
|
|
104
104
|
|
|
105
|
+
## Design: the schema / systemPrompt / skill three-layer split
|
|
106
|
+
|
|
107
|
+
The core of letting AI safely edit JSON is a **three-layer decoupled split** — each layer has its own job, changing one never forces changes to the others:
|
|
108
|
+
|
|
109
|
+
| Layer | Carrier | Real intent | Loaded when |
|
|
110
|
+
|---|---|---|---|
|
|
111
|
+
| **Mechanical (structure + validation)** | `data.schema` (zod) | Defines field names/types/shapes; write-time validation guardrail (invalid → structured error, no write); `ZodObject` top-level keys auto-whitelist (hides undeclared fields, prevents accidental delete/edit) | Fixed at construction; field `.describe()` text auto-extracted into systemPrompt |
|
|
112
|
+
| **Generic rules (identity + write methodology)** | `systemPrompt` | Agent identity; `reliableWriteRules` (read before write, fields per `describe`, retry on validation error, prefer incremental patch) | Every round (persistent) |
|
|
113
|
+
| **Deep business (semantics + edit recipes)** | `skills` (`defineSkill`) | Component-library specs, detailed field business semantics, scenario-specific edit strategies, glossaries | On-demand (agent sees name+description index, calls `load_skill` to pull full text — saves tokens) |
|
|
114
|
+
|
|
115
|
+
**How they cooperate**
|
|
116
|
+
|
|
117
|
+
- **Structure** → schema defines it (integrator writes); the agent never sees the zod itself, but `.describe()` text auto-enters the systemPrompt "operable data" section so the agent knows field names + purpose
|
|
118
|
+
- **Semantics** → shallow via schema `.describe()` (one line per field, persistent); deep via skills (full business spec, on-demand)
|
|
119
|
+
- **Edit judgment** → generic strategy via `systemPrompt` `reliableWriteRules` (persistent); business-specific strategy via skills (on-demand); fallback via schema validation feedback (write errors return structured errors the agent retries from)
|
|
120
|
+
|
|
121
|
+
**Design intent**: schema governs "what can be changed / whether a change is valid" (mechanical safety); systemPrompt + skills govern "how to change / why to change it this way" (semantic guidance). Three layers decoupled — change schema and validation follows automatically; change skills without touching the prompt; change the prompt without touching the schema.
|
|
122
|
+
|
|
123
|
+
**Example (low-code page builder)**
|
|
124
|
+
|
|
125
|
+
- schema: `z.object({ components: z.array(...) }).describe('component tree')` → agent knows there's a `components` field, an array of components
|
|
126
|
+
- systemPrompt: built-in "JSON operation assistant" + `reliableWriteRules` (default `appendReliableWriteRules:true` auto-appends with a `---` separator distinguishing user content from SDK-appended rules) → agent knows to `read` before write, prefer `write` patch incremental
|
|
127
|
+
- skill: `page-builder` skill details each component's props field meanings + edit recipes (e.g. "to change Banner bg use `write({patch:{op:'set', jsonPath:'components.0.props.bg'}})`") → agent loads on demand, edits precisely
|
|
128
|
+
|
|
129
|
+
> `appendReliableWriteRules` defaults to `true`: when a custom `systemPrompt` is set, auto-appends `reliableWriteRules` with a `---` separator (avoids forgetting the write methodology); set `false` to disable; no effect when `systemPrompt` is omitted (default prompt already includes them).
|
|
130
|
+
|
|
105
131
|
## Agent Integration Cheat Sheet (for AI agents)
|
|
106
132
|
|
|
107
133
|
> Dense integration reference for AI agents: exports / options / extension points / built-in tools / file structure. Deep dive in `doc/` and `CLAUDE.md`.
|
package/README.zh-CN.md
CHANGED
|
@@ -102,6 +102,32 @@ CDN 零配置:`<script src="https://unpkg.com/page-agent-sdk"></script>` → `
|
|
|
102
102
|
|
|
103
103
|
能力默认开(`verify`/`approval`/`checkpoint` 默认关;**主动征询 `humanConfirm` 默认开**——AI 遇不确定/多方案主动问你、不猜测),可经 `capabilities` 关掉无用的省 token。
|
|
104
104
|
|
|
105
|
+
## 设计思路:schema / systemPrompt / skill 三层配合
|
|
106
|
+
|
|
107
|
+
SDK 让 AI 安全改 JSON 的核心是**三层解耦配合**——各司其职、互不耦合,改一层不用动另两层:
|
|
108
|
+
|
|
109
|
+
| 层 | 载体 | 真实意图 | 加载时机 |
|
|
110
|
+
|---|---|---|---|
|
|
111
|
+
| **机械层(结构 + 校验)** | `data.schema`(zod) | 定义字段名/类型/形状;写时校验护栏(不合法→结构化错误,不写入);`ZodObject` 顶层键自动白名单(隐藏未声明字段,防误删/误改) | 构造时固定;字段 `.describe()` 文本自动提取注入 systemPrompt |
|
|
112
|
+
| **通用规则层(身份 + 写入方法论)** | `systemPrompt` | agent 身份;`reliableWriteRules`(改前先 read、字段以 describe 为准、写错看校验错误重试、优先增量 patch) | 常驻每轮 |
|
|
113
|
+
| **深度业务层(含义 + 修改套路)** | `skills`(`defineSkill`) | 组件库规范、字段业务语义详解、场景化修改策略、术语表 | 按需加载(agent 见 name+description 索引,调用 `load_skill` 拉全文,省 token) |
|
|
114
|
+
|
|
115
|
+
**配合机制**
|
|
116
|
+
|
|
117
|
+
- **结构** → schema 定义(集成方写);agent 看不到 zod 本身,但 `.describe()` 文本自动进 systemPrompt「可操作数据」段,agent 据此知字段名 + 用途
|
|
118
|
+
- **含义** → 浅层靠 schema `.describe()`(每字段一句话,常驻);深层靠 skills(整篇业务规范,按需)
|
|
119
|
+
- **修改判断** → 通用策略靠 `systemPrompt` 的 `reliableWriteRules`(常驻);业务特有策略靠 skills(按需);兜底靠 schema 校验反馈(写错返回结构化错误,agent 据此重试)
|
|
120
|
+
|
|
121
|
+
**设计意图**:schema 管「能改什么 / 改得对不对」(机械安全),systemPrompt + skills 管「怎么改 / 为什么这么改」(语义引导)。三者解耦——schema 变了校验自动跟,skills 变了不用改 prompt,prompt 变了不用动 schema。
|
|
122
|
+
|
|
123
|
+
**举例(低代码页面搭建)**
|
|
124
|
+
|
|
125
|
+
- schema:`z.object({ components: z.array(...) }).describe('组件树')` → agent 知道有 `components` 字段、是组件数组
|
|
126
|
+
- systemPrompt:内置「JSON 操作助手」+ `reliableWriteRules`(默认 `appendReliableWriteRules:true` 自动追加,用 `---` 分隔线区分用户内容与 SDK 追加的规则)→ agent 知道改前先 `read`、优先 `write` patch 增量
|
|
127
|
+
- skill:`page-builder` skill 详述各组件 props 字段含义 + 修改套路(如「改 Banner 背景用 `write({patch:{op:'set', jsonPath:'components.0.props.bg'}})`」)→ agent 按需加载,精确操作
|
|
128
|
+
|
|
129
|
+
> `appendReliableWriteRules` 默认 `true`:传自定义 `systemPrompt` 时自动用 `---` 分隔线追加 `reliableWriteRules`(避免忘写写入方法论);设 `false` 关闭;不传 `systemPrompt` 用默认 prompt 时已内置。
|
|
130
|
+
|
|
105
131
|
## Agent 接入速查(给 AI agent 读)
|
|
106
132
|
|
|
107
133
|
> 本节是给 AI agent 的密集接入参考:导出清单 / 选项表 / 扩展点 / 内置工具 / 文件结构。深挖见 `doc/` 与 `CLAUDE.md`。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "page-agent-sdk",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "框架无关的页面内 Agent JS SDK —— 以对话框形态挂载到任意网页,通过自定义 tool 读写宿主预注册的数据槽(经 schema 校验 + jsonPath 增量 patch + 快照回退;GET 抓文档),具备 planning/skills/虚拟工作区/context 管理能力。Vue 打包进库,使用者无需安装 Vue。",
|
|
6
6
|
"main": "./dist/page-agent-sdk.umd.cjs",
|