page-agent-sdk 2.8.0 → 2.9.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 +25 -3
- package/README.zh-CN.md +25 -3
- package/dist/page-agent-sdk.css +1 -1
- package/dist/page-agent-sdk.iife.js +112 -112
- package/dist/page-agent-sdk.js +1897 -1669
- package/dist/page-agent-sdk.umd.cjs +46 -46
- package/package.json +1 -1
- package/skills/page-agent-sdk-integrate/references/api.md +1 -1
- package/skills/page-agent-sdk-integrate/references/use-cases.md +31 -0
- package/types/index.d.ts +8 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "page-agent-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
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",
|
|
@@ -99,7 +99,7 @@ Default `toolMode:'simple'` exposes high-level `read`/`write` + advanced query/s
|
|
|
99
99
|
| `query_data` / `search_data` | JSONPath query / full-text search | simple/advanced |
|
|
100
100
|
| `eval_script` | Sandboxed script on data (query/transform; transform supports `{patches:[...]}` incremental mode) | simple/advanced |
|
|
101
101
|
|
|
102
|
-
**Key rule**: `write`/`set`/`edit`/`delete` only affect **schema-declared**
|
|
102
|
+
**Key rule**: `write`/`set`/`edit`/`delete` only affect **schema-declared** fields (ZodObject auto-whitelist; undeclared fields hidden/denied). Sub-path reads are recursively projected by the sub-schema at that location (e.g. `read components.0` hides child undeclared fields). `jsonPath` is segment-by-segment validated against schema. Invalid schema → structured error, no write. `write`/`edit` writes in-place (preserves Vue reactive refs). `write` auto-tracks hash from `read` for optimistic lock (no manual `expectedHash` needed). Whole-set / `set_data` / `eval` transform become **merge** semantics in whitelist mode (only updates declared fields, undeclared fields preserved — prevents accidental deletion); `interceptors.write`-supplied invisible fields (not in schema) are written back to bind after schema+merge (not stripped).
|
|
103
103
|
|
|
104
104
|
### write / jsonPath edit operations
|
|
105
105
|
|
|
@@ -265,3 +265,34 @@ sdk.inspect().skills // reflects runtime swap (reads controller.get())
|
|
|
265
265
|
|
|
266
266
|
**何时用**:多阶段业务流程(各阶段 skill 文档不同)、运行时按权限/角色加载不同 skill、skill 文档热更新(vfs doc 内容变化需主动失效缓存)。skills 关闭(`capabilities.skills:false`)时 `setSkills`/`invalidateSkillCache` 输出 warn 并 no-op,不抛错。
|
|
267
267
|
|
|
268
|
+
## 12. Multi-agent parallel + exclusive switch (drawer hide/show)
|
|
269
|
+
|
|
270
|
+
Multiple independent agents on one page (each `createChatSdk` + distinct `id`, each its own `data`/history/tools), running their own generation tasks in parallel; exclusive chatbox switching via `drawer` + `hide()`/`show()` — `hide` the old (keeps agent/history/in-flight generation), `show` the new (history resumes), no unmount, no lost conversation.
|
|
271
|
+
|
|
272
|
+
```ts
|
|
273
|
+
const boxA = document.createElement('div'); document.body.appendChild(boxA)
|
|
274
|
+
const boxB = document.createElement('div'); document.body.appendChild(boxB)
|
|
275
|
+
const boxC = document.createElement('div'); document.body.appendChild(boxC)
|
|
276
|
+
|
|
277
|
+
const agents = [
|
|
278
|
+
createChatSdk({ id: 'agent-page', container: boxA, drawer: true, storage: 'memory', llm: LLM, data: { schema: pageSchema, bind: pageObj }, systemPrompt: '页面构建助手…' }),
|
|
279
|
+
createChatSdk({ id: 'agent-copy', container: boxB, drawer: true, storage: 'memory', llm: LLM, data: { schema: copySchema, bind: copyObj }, systemPrompt: '文案优化助手…' }),
|
|
280
|
+
createChatSdk({ id: 'agent-stats', container: boxC, drawer: true, storage: 'memory', llm: LLM, data: { schema: statsSchema, bind: statsObj }, systemPrompt: '数据分析助手…' }),
|
|
281
|
+
]
|
|
282
|
+
await Promise.all(agents.map(a => a.mount())) // three independent agents ready in parallel
|
|
283
|
+
agents.slice(1).forEach(a => a.hide()) // show only the first initially
|
|
284
|
+
|
|
285
|
+
let active = 0
|
|
286
|
+
function switchTo(i: number) {
|
|
287
|
+
agents[active].hide(); active = i; agents[i].show() // exclusive switch, each history preserved
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
**要点**:
|
|
292
|
+
- 不同 `id` 隔离:各自独立 agent 实例/历史/工具/storage,互不串扰
|
|
293
|
+
- 各管各 `data` 对象无冲突;多 agent 操作同一 `data` 需协调(乐观锁 `expectedHash` 或按 `jsonPath` 分区)
|
|
294
|
+
- `hide()` 不卸载 vueApp/不 release agent,保留聊天历史与正在进行的生成进程;`show()` 恢复可见
|
|
295
|
+
- 切换按钮若在抽屉遮罩下,需提高 `z-index`(高于遮罩 `9998` + ChatDialog `9999`)确保可点
|
|
296
|
+
|
|
297
|
+
完整示例:`examples/multi-agent-demo/`。
|
|
298
|
+
|
package/types/index.d.ts
CHANGED
|
@@ -432,6 +432,10 @@ export interface ChatSdkOptions {
|
|
|
432
432
|
streaming?: boolean;
|
|
433
433
|
title?: string;
|
|
434
434
|
placeholder?: string;
|
|
435
|
+
/** Drawer mode: ChatDialog slides in from the right + mask + close button (replaces the collapse arrow); clicking mask/close triggers unmount (with exit animation). Default false (inline, fills container). */
|
|
436
|
+
drawer?: boolean;
|
|
437
|
+
/** Drawer mode close callback: called when mask/close button clicked (default calls unmount with exit animation). Pass this to sync external mount state. */
|
|
438
|
+
onClose?: () => void;
|
|
435
439
|
}
|
|
436
440
|
|
|
437
441
|
export interface ChatSdk {
|
|
@@ -439,6 +443,10 @@ export interface ChatSdk {
|
|
|
439
443
|
/** 响应式消息数组(headless 模式自建 UI 读) */
|
|
440
444
|
messages: AgentMessage[];
|
|
441
445
|
unmount(): void;
|
|
446
|
+
/** 抽屉模式隐藏:加 cs-hidden class,不卸载 vueApp/不 release agent —— 保留聊天历史与正在进行的生成进程;再 mount() 直接 show 恢复 */
|
|
447
|
+
hide(): void;
|
|
448
|
+
/** 抽屉模式显示:移除 cs-hidden class 恢复可见(配合 hide 使用;首次挂载用 mount) */
|
|
449
|
+
show(): void;
|
|
442
450
|
send(message: string): Promise<string>;
|
|
443
451
|
switchSession(sessionId?: string): Promise<string>;
|
|
444
452
|
stream: (messages: AgentMessage[], onEvent: StreamHandler, signal?: AbortSignal) => Promise<string>;
|