page-agent-sdk 1.4.2 → 2.1.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 +29 -29
- package/README.zh-CN.md +27 -27
- package/dist/page-agent-sdk.css +1 -1
- package/dist/page-agent-sdk.iife.js +79 -79
- package/dist/page-agent-sdk.js +181 -176
- package/dist/page-agent-sdk.umd.cjs +17 -17
- package/package.json +2 -2
- package/skills/page-agent-sdk-integrate/SKILL.md +18 -18
- package/skills/page-agent-sdk-integrate/references/advanced.md +29 -29
- package/skills/page-agent-sdk-integrate/references/api.md +24 -24
- package/skills/page-agent-sdk-integrate/references/options.md +8 -8
- package/skills/page-agent-sdk-integrate/references/quickstart.md +14 -14
- package/skills/page-agent-sdk-integrate/references/use-cases.md +27 -27
- package/types/index.d.ts +46 -36
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Use cases — end-to-end scenarios
|
|
2
2
|
|
|
3
|
-
Concrete integration patterns for common scenarios. Each shows the key `
|
|
3
|
+
Concrete integration patterns for common scenarios. Each shows the key `dataSlots` + options that matter. Adapt the LLM config to your provider.
|
|
4
4
|
|
|
5
5
|
## 1. Low-code page builder
|
|
6
6
|
|
|
@@ -17,21 +17,21 @@ window.page = {
|
|
|
17
17
|
createChatSdk({
|
|
18
18
|
container: '#chat',
|
|
19
19
|
llm: { apiKey, baseUrl: 'https://api.deepseek.com/v1', model: 'deepseek-chat', temperature: 0.3 },
|
|
20
|
-
systemPrompt: '你是页面搭建助手。用
|
|
21
|
-
|
|
20
|
+
systemPrompt: '你是页面搭建助手。用 edit_data_slot 按 jsonPath 增量改 components,不要重传整树。',
|
|
21
|
+
dataSlots: [
|
|
22
22
|
{ path: 'page.components', description: '组件树',
|
|
23
23
|
schema: z.array(z.object({
|
|
24
24
|
id: z.string(), type: z.string(),
|
|
25
25
|
props: z.record(z.any()),
|
|
26
26
|
})) },
|
|
27
27
|
],
|
|
28
|
-
onEvent(e) { if (e.type === '
|
|
28
|
+
onEvent(e) { if (e.type === 'data_slot_change') renderCanvas() }, // canvas reactive refresh
|
|
29
29
|
checkpoint: true, // bad edit → one-click rollback
|
|
30
|
-
approval: { tools: ['
|
|
30
|
+
approval: { tools: ['set_data_slot', 'edit_data_slot'] }, // confirm writes
|
|
31
31
|
}).mount()
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
User: "顶部 Banner 改深色、主标题加粗、加一张新品卡" → AI calls `
|
|
34
|
+
User: "顶部 Banner 改深色、主标题加粗、加一张新品卡" → AI calls `edit_data_slot` per component.
|
|
35
35
|
|
|
36
36
|
## 2. Form designer
|
|
37
37
|
|
|
@@ -48,7 +48,7 @@ window.form = {
|
|
|
48
48
|
createChatSdk({
|
|
49
49
|
container: '#chat', llm: { ... },
|
|
50
50
|
systemPrompt: '你是表单设计助手。改 form.fields 的字段定义,保持 schema 合法。',
|
|
51
|
-
|
|
51
|
+
dataSlots: [
|
|
52
52
|
{ path: 'form.fields', description: '字段定义数组',
|
|
53
53
|
schema: z.array(z.object({
|
|
54
54
|
name: z.string(), label: z.string(),
|
|
@@ -58,7 +58,7 @@ createChatSdk({
|
|
|
58
58
|
cascade: z.boolean().optional(),
|
|
59
59
|
})) },
|
|
60
60
|
],
|
|
61
|
-
onEvent(e) { if (e.type === '
|
|
61
|
+
onEvent(e) { if (e.type === 'data_slot_change') renderForm() },
|
|
62
62
|
}).mount()
|
|
63
63
|
```
|
|
64
64
|
|
|
@@ -66,7 +66,7 @@ User: "手机号加格式校验、地址改三级联动" → AI patches `form.fi
|
|
|
66
66
|
|
|
67
67
|
## 3. CMS batch operation
|
|
68
68
|
|
|
69
|
-
Bulk-edit a product list; use `
|
|
69
|
+
Bulk-edit a product list; use `eval_script` or `search_data_slot` + `edit_data_slot` for batch ops.
|
|
70
70
|
|
|
71
71
|
```ts
|
|
72
72
|
window.products = [
|
|
@@ -77,18 +77,18 @@ window.products = [
|
|
|
77
77
|
|
|
78
78
|
createChatSdk({
|
|
79
79
|
container: '#chat', llm: { ... },
|
|
80
|
-
systemPrompt: '你是运营助手。批量改 products;标题加前缀用
|
|
81
|
-
|
|
80
|
+
systemPrompt: '你是运营助手。批量改 products;标题加前缀用 eval_script,按条件筛选用 search_data_slot。',
|
|
81
|
+
dataSlots: [
|
|
82
82
|
{ path: 'products', description: '商品列表',
|
|
83
83
|
schema: z.array(z.object({
|
|
84
84
|
id: z.number(), title: z.string(), price: z.number(), highlight: z.boolean(),
|
|
85
85
|
})) },
|
|
86
86
|
],
|
|
87
|
-
onEvent(e) { if (e.type === '
|
|
87
|
+
onEvent(e) { if (e.type === 'data_slot_change') renderTable() },
|
|
88
88
|
}).mount()
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
User: "标题加『限时』前缀、低于 100 元的标红" → AI uses `
|
|
91
|
+
User: "标题加『限时』前缀、低于 100 元的标红" → AI uses `eval_script` for the prefix loop + `search_data_slot` to find `<100` then `edit_data_slot` to set `highlight`.
|
|
92
92
|
|
|
93
93
|
## 4. Ops config console
|
|
94
94
|
|
|
@@ -103,13 +103,13 @@ window.config = {
|
|
|
103
103
|
createChatSdk({
|
|
104
104
|
container: '#chat', llm: { ... },
|
|
105
105
|
systemPrompt: '你是运维助手。改 config 前必须经用户确认。',
|
|
106
|
-
|
|
106
|
+
dataSlots: [
|
|
107
107
|
{ path: 'config.expA', description: '实验A',
|
|
108
108
|
schema: z.object({ threshold: z.number().min(0).max(1), enabled: z.boolean() }) },
|
|
109
109
|
{ path: 'config.featureB', description: 'B开关',
|
|
110
110
|
schema: z.object({ enabled: z.boolean() }) },
|
|
111
111
|
],
|
|
112
|
-
approval: { tools: ['
|
|
112
|
+
approval: { tools: ['set_data_slot', 'edit_data_slot'] }, // human-in-the-loop
|
|
113
113
|
checkpoint: true,
|
|
114
114
|
capabilities: { verify: true }, // write-back read + schema check
|
|
115
115
|
}).mount()
|
|
@@ -119,7 +119,7 @@ User: "A 实验阈值调到 30%、关掉 B 开关" → AI proposes writes → us
|
|
|
119
119
|
|
|
120
120
|
## 5. AI-native assistant (no page data, custom tools)
|
|
121
121
|
|
|
122
|
-
The agent drives your product's own API via custom tools (no
|
|
122
|
+
The agent drives your product's own API via custom tools (no dataSlotOps).
|
|
123
123
|
|
|
124
124
|
```ts
|
|
125
125
|
const lookupTool = defineTool({
|
|
@@ -134,7 +134,7 @@ createChatSdk({
|
|
|
134
134
|
llm: { ... },
|
|
135
135
|
systemPrompt: '你是订单助手。用 lookup_order 查询。',
|
|
136
136
|
tools: [lookupTool],
|
|
137
|
-
capabilities: {
|
|
137
|
+
capabilities: { dataSlotOps: false, fetch: false }, // pure custom-tool agent
|
|
138
138
|
}).mount()
|
|
139
139
|
```
|
|
140
140
|
|
|
@@ -146,7 +146,7 @@ Pure research: fetch docs, parallel subagents for multi-source investigation.
|
|
|
146
146
|
createChatSdk({
|
|
147
147
|
container: '#chat', llm: { ... },
|
|
148
148
|
systemPrompt: '你是调研助手。多源对比用 spawn_agents 并行委派。',
|
|
149
|
-
capabilities: {
|
|
149
|
+
capabilities: { dataSlotOps: false }, // read-only, no page edits
|
|
150
150
|
subagent: { allowedTools: ['fetch_document'] },
|
|
151
151
|
contextPreset: 'conservative', // long research sessions
|
|
152
152
|
}).mount()
|
|
@@ -154,7 +154,7 @@ createChatSdk({
|
|
|
154
154
|
|
|
155
155
|
## 7. Headless server-side (Node.js)
|
|
156
156
|
|
|
157
|
-
Run the agent in Node (no browser). Provide `globalThis.window` only if you enable
|
|
157
|
+
Run the agent in Node (no browser). Provide `globalThis.window` only if you enable dataSlotOps.
|
|
158
158
|
|
|
159
159
|
```ts
|
|
160
160
|
// node mjs
|
|
@@ -165,7 +165,7 @@ const sdk = createChatSdk({
|
|
|
165
165
|
storage: 'memory',
|
|
166
166
|
llm: { apiKey, baseUrl, model },
|
|
167
167
|
systemPrompt: '...',
|
|
168
|
-
capabilities: {
|
|
168
|
+
capabilities: { dataSlotOps: false, fetch: false },
|
|
169
169
|
tools: [/* your tools */],
|
|
170
170
|
})
|
|
171
171
|
await sdk.mount()
|
|
@@ -179,8 +179,8 @@ sdk.unmount()
|
|
|
179
179
|
Two dialogs backed by one agent brain.
|
|
180
180
|
|
|
181
181
|
```ts
|
|
182
|
-
const a = createChatSdk({ id: 'shared', container: '#dlg-a', llm: {...}, shareContext: true,
|
|
183
|
-
const b = createChatSdk({ id: 'shared', container: '#dlg-b', llm: {...}, shareContext: true,
|
|
182
|
+
const a = createChatSdk({ id: 'shared', container: '#dlg-a', llm: {...}, shareContext: true, dataSlots }).mount()
|
|
183
|
+
const b = createChatSdk({ id: 'shared', container: '#dlg-b', llm: {...}, shareContext: true, dataSlots }).mount()
|
|
184
184
|
// a & b share messages/agent/vfs/todos/memory — two views of one agent
|
|
185
185
|
```
|
|
186
186
|
|
|
@@ -199,7 +199,7 @@ createChatSdk({
|
|
|
199
199
|
|
|
200
200
|
> Note: `@modelcontextprotocol/sdk` is an optional peerDep — install it only if you use `mcp`. Browser supports only remote transports (http/sse/websocket), not stdio.
|
|
201
201
|
|
|
202
|
-
## 10. Lazy-loaded components with dynamic schemas (dynamic
|
|
202
|
+
## 10. Lazy-loaded components with dynamic schemas (dynamic dataSlots)
|
|
203
203
|
|
|
204
204
|
Components loaded on demand with **different structures each** — register their schema at mount time, unregister at unmount. No need to pre-declare every possible component at `createChatSdk`.
|
|
205
205
|
|
|
@@ -207,14 +207,14 @@ Components loaded on demand with **different structures each** — register thei
|
|
|
207
207
|
const sdk = createChatSdk({
|
|
208
208
|
container: '#chat', llm: { ... },
|
|
209
209
|
// only the static container is pre-declared; per-component paths are dynamic
|
|
210
|
-
|
|
211
|
-
systemPrompt: '用
|
|
210
|
+
dataSlots: [{ path: 'app.components', description: '动态组件容器', schema: z.record(z.any()) }],
|
|
211
|
+
systemPrompt: '用 list_data_slots 查看当前可操作的组件 path,再按各自 schema 操作',
|
|
212
212
|
}).mount()
|
|
213
213
|
|
|
214
214
|
// 组件挂载(懒加载)→ 动态注册其 schema,立即对 AI 生效
|
|
215
215
|
function mountComp(comp: { id: string; type: CompType }) {
|
|
216
216
|
window.app.components[comp.id] = reactive(comp)
|
|
217
|
-
sdk.
|
|
217
|
+
sdk.addDataSlot({
|
|
218
218
|
path: `app.components.${comp.id}`,
|
|
219
219
|
description: `${comp.type} 组件`,
|
|
220
220
|
schema: compSchemas[comp.type], // 结构各异:banner/card/stat/chart 各自 schema
|
|
@@ -223,7 +223,7 @@ function mountComp(comp: { id: string; type: CompType }) {
|
|
|
223
223
|
// 组件卸载 → 动态移除注册(快照栈一并清理)
|
|
224
224
|
function unmountComp(id: string) {
|
|
225
225
|
delete window.app.components[id]
|
|
226
|
-
sdk.
|
|
226
|
+
sdk.removeDataSlot(`app.components.${id}`)
|
|
227
227
|
}
|
|
228
228
|
```
|
|
229
229
|
|
package/types/index.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export type StreamHandler = (event: StreamEvent) => void;
|
|
|
45
45
|
/**
|
|
46
46
|
* SDK 事件(供 createChatSdk({ onEvent }) 订阅常用时机)。
|
|
47
47
|
* 复用 StreamEvent(round_start/reasoning/text/tool_call/tool_result/subagent/done;approval_request 不外发)
|
|
48
|
-
* + 额外时机:
|
|
48
|
+
* + 额外时机:data_slot_change / message_update / error。
|
|
49
49
|
*/
|
|
50
50
|
export type SdkEvent =
|
|
51
51
|
| { type: 'round_start'; round: number }
|
|
@@ -55,7 +55,7 @@ export type SdkEvent =
|
|
|
55
55
|
| { type: 'tool_result'; name: string; result: string; status: 'done' | 'error' }
|
|
56
56
|
| { type: 'subagent'; taskId: string; label: string; kind: 'tool_call' | 'tool_result'; name: string; args?: any; result?: string; status?: 'done' | 'error' }
|
|
57
57
|
| { type: 'done'; content: string }
|
|
58
|
-
| { type: '
|
|
58
|
+
| { type: 'data_slot_change'; path: string; operation: 'set' | 'edit' | 'delete' | 'restore'; value?: unknown }
|
|
59
59
|
| { type: 'message_update'; count: number }
|
|
60
60
|
| { type: 'conflict'; conflict: PendingConflict }
|
|
61
61
|
| { type: 'error'; message: string };
|
|
@@ -80,7 +80,7 @@ export interface ChatDialogProps {
|
|
|
80
80
|
|
|
81
81
|
export interface ToolInfo { name: string; description: string; schema?: unknown; source?: string }
|
|
82
82
|
export interface SkillInfo { name: string; description: string }
|
|
83
|
-
export interface
|
|
83
|
+
export interface DataSlotInfo { path: string; description: string; schema?: unknown }
|
|
84
84
|
export interface SubagentInfo {
|
|
85
85
|
enabled: boolean;
|
|
86
86
|
maxDepth: number;
|
|
@@ -108,7 +108,7 @@ export interface AgentInfo {
|
|
|
108
108
|
systemPrompt: string;
|
|
109
109
|
tools: ToolInfo[];
|
|
110
110
|
skills: SkillInfo[];
|
|
111
|
-
|
|
111
|
+
dataSlots: DataSlotInfo[];
|
|
112
112
|
memory: string;
|
|
113
113
|
middleware: string[];
|
|
114
114
|
todos: { content: string; status: string }[];
|
|
@@ -149,35 +149,43 @@ export type ChatModelLike = {
|
|
|
149
149
|
bindTools: (tools: any[]) => any;
|
|
150
150
|
};
|
|
151
151
|
|
|
152
|
-
export interface
|
|
152
|
+
export interface DataSlotSpec {
|
|
153
153
|
/** window 上的路径,支持点号嵌套 */
|
|
154
154
|
path: string;
|
|
155
155
|
description: string;
|
|
156
156
|
/** 值的 zod schema(写入时校验) */
|
|
157
157
|
schema: any;
|
|
158
158
|
}
|
|
159
|
-
/**
|
|
160
|
-
export interface
|
|
159
|
+
/** createDataSlotOps 选项(审计回调 / 只读探测 / 快照上限 / 字段白名单读 / 乐观锁) */
|
|
160
|
+
export interface DataSlotOpsOptions {
|
|
161
161
|
onAudit?: (entry: { op: string; path: string; value?: any; detail?: string; timestamp: number }) => void;
|
|
162
162
|
allowRawRead?: boolean;
|
|
163
163
|
maxSnapshots?: number;
|
|
164
164
|
/**
|
|
165
165
|
* 字段白名单读模式(默认 true):仅允许读「注册 path 自身 / 其后代」,禁止读未注册的祖先,
|
|
166
|
-
* 防止 LLM 经
|
|
166
|
+
* 防止 LLM 经 get_data_slot('page') 把整个大 JSON 拉进上下文。
|
|
167
167
|
* 集成方注册「可操作子路径」(如 page.theme.color / page.components)而非顶层时,默认即「LLM 只见声明字段」。
|
|
168
168
|
* 设 false 回退原行为(允许读注册 path 的祖先,即整体读)。
|
|
169
169
|
*/
|
|
170
170
|
whitelist?: boolean;
|
|
171
|
+
/** 乐观锁冲突人工介入回调(详见 ConflictInfo/ConflictResolution);不传则冲突时返回 VERSION_CONFLICT 错误 */
|
|
172
|
+
onConflict?: (conflict: ConflictInfo) => Promise<ConflictResolution>;
|
|
173
|
+
/**
|
|
174
|
+
* 自动乐观锁(默认 true):写入时若 LLM 未显式传 expectedHash,自动用「LLM 最后一次 get_data_slot 读到的 hash」作基准比对。
|
|
175
|
+
* LLM 无需手动传 expectedHash 即可享受乐观锁保护;冲突走 onConflict(无 onConflict 则返回 VERSION_CONFLICT)。
|
|
176
|
+
* LLM 未读过直接写(无基准记录)时跳过锁(等同不校验)。设 false 回退「不传 expectedHash = 不校验」的旧行为。
|
|
177
|
+
*/
|
|
178
|
+
autoLock?: boolean;
|
|
171
179
|
}
|
|
172
180
|
|
|
173
|
-
/**
|
|
174
|
-
export interface
|
|
181
|
+
/** 数据槽注册表控制器(运行时动态增删;createDataSlotOps 返回的工具数组上以不可枚举属性 `controller` 挂载) */
|
|
182
|
+
export interface DataSlotOpsController {
|
|
175
183
|
/** 新增/覆盖一个属性注册项(运行时懒加载组件场景);覆盖时旧快照栈保留 */
|
|
176
|
-
add(spec:
|
|
184
|
+
add(spec: DataSlotSpec): void;
|
|
177
185
|
/** 移除一个属性注册项;返回是否确实存在并移除。快照栈一并清理 */
|
|
178
186
|
remove(path: string): boolean;
|
|
179
187
|
/** 列出当前所有注册项(反映动态增删后的最新状态) */
|
|
180
|
-
list():
|
|
188
|
+
list(): DataSlotSpec[];
|
|
181
189
|
/** 是否已注册某 path */
|
|
182
190
|
has(path: string): boolean;
|
|
183
191
|
}
|
|
@@ -217,7 +225,7 @@ export interface VerifyMiddlewareOptions {
|
|
|
217
225
|
}
|
|
218
226
|
/** createWriteBackCheck 选项 */
|
|
219
227
|
export interface WriteBackCheckOptions {
|
|
220
|
-
/** path → zod schema(由 createChatSdk 从
|
|
228
|
+
/** path → zod schema(由 createChatSdk 从 dataSlots 构造注入);省略则只校验「读回非空」 */
|
|
221
229
|
schemas?: Record<string, any>;
|
|
222
230
|
/** 读 window 的根对象(默认 globalThis.window) */
|
|
223
231
|
window?: unknown;
|
|
@@ -325,13 +333,15 @@ export interface ChatSdkOptions {
|
|
|
325
333
|
tools?: any[];
|
|
326
334
|
skills?: SkillSpec[];
|
|
327
335
|
memory?: string;
|
|
328
|
-
|
|
336
|
+
dataSlots?: DataSlotSpec[];
|
|
329
337
|
permissions?: PermissionRule[];
|
|
330
338
|
/** 自定义中间件(注入到内置中间件之后;可拦截/观察模型调用、工具、prompt) */
|
|
331
339
|
middleware?: any[];
|
|
332
340
|
vfs?: { initialFiles?: Record<string, string>; maxBytes?: number };
|
|
333
|
-
/** 每个
|
|
341
|
+
/** 每个 数据槽最多保留快照数(默认 20) */
|
|
334
342
|
maxSnapshots?: number;
|
|
343
|
+
/** 自动乐观锁(默认 true):写入时若 LLM 未传 expectedHash,自动用其最后 get 读到的 hash 比对;设 false 回退「不传 = 不校验」 */
|
|
344
|
+
autoLock?: boolean;
|
|
335
345
|
/** 内存中保留的对话轮数上限(默认 50);超限把最旧轮次压缩为摘要 system 消息(防 OOM);0 关闭 */
|
|
336
346
|
maxMemoryRounds?: number;
|
|
337
347
|
debug?: boolean;
|
|
@@ -345,7 +355,7 @@ export interface ChatSdkOptions {
|
|
|
345
355
|
/** 模型最大输出(token);顶层声明对 llm 实例场景也生效,缺省按 model 名查表 */
|
|
346
356
|
maxOutputTokens?: number;
|
|
347
357
|
/** 子 agent 委派(默认开启;{ enabled: false } 关闭) */
|
|
348
|
-
capabilities?: {
|
|
358
|
+
capabilities?: { dataSlotOps?: boolean; fetch?: boolean; planning?: boolean; skills?: boolean; vfs?: boolean; summarization?: boolean; memory?: boolean; subagent?: boolean; verify?: boolean };
|
|
349
359
|
subagent?: { enabled?: boolean; allowedTools?: string[]; systemPrompt?: string; temperature?: number; maxTokens?: number; skills?: SkillSpec[]; llm?: LLMConfig | ChatModelLike; maxDepth?: number; maxParallel?: number };
|
|
350
360
|
/** 预声明子 agent 列表:每个用同主配置方式声明,自动生成 use_<id> 委派工具(与 spawn_agent 共存) */
|
|
351
361
|
subagents?: SubagentConfig[];
|
|
@@ -370,7 +380,7 @@ export interface ChatSdkOptions {
|
|
|
370
380
|
/** 摘要 LLM 超时毫秒(默认 15000;超时回退索引摘要) */
|
|
371
381
|
summaryTimeoutMs?: number;
|
|
372
382
|
/**
|
|
373
|
-
* SDK 事件回调:订阅常用时机(
|
|
383
|
+
* SDK 事件回调:订阅常用时机(数据槽变化 / 消息更新 / 工具调用 / 流式文本 / 轮次 / 错误)。
|
|
374
384
|
* UI 与 headless 模式均生效;用于外部联动(宿主页面响应式刷新、埋点、日志),替代轮询。
|
|
375
385
|
* approval_request 不外发(UI 已处理)。
|
|
376
386
|
*/
|
|
@@ -389,27 +399,27 @@ export interface ChatSdk {
|
|
|
389
399
|
send(message: string): Promise<string>;
|
|
390
400
|
switchSession(sessionId?: string): Promise<string>;
|
|
391
401
|
stream: (messages: AgentMessage[], onEvent: StreamHandler, signal?: AbortSignal) => Promise<string>;
|
|
392
|
-
/** 检视 agent 详细信息(tools/skills/
|
|
402
|
+
/** 检视 agent 详细信息(tools/skills/dataSlots/middleware/todos) */
|
|
393
403
|
inspect(): AgentInfo;
|
|
394
|
-
/** 回退到最近一次正常 checkpoint(整体还原对话历史 +
|
|
404
|
+
/** 回退到最近一次正常 checkpoint(整体还原对话历史 + 数据槽注册项 + vfs + todos);需开启 checkpoint,无可用返回 false */
|
|
395
405
|
restoreLastCheckpoint(): boolean;
|
|
396
406
|
/** 列出可用 checkpoint(回退点);需开启 checkpoint,未开启返回空数组 */
|
|
397
407
|
listCheckpoints(): CheckpointMeta[];
|
|
398
408
|
/** 运行时订阅 SDK 事件(可多个监听器,返回取消函数);与构造时 onEvent 互补 */
|
|
399
409
|
hook(handler: SdkEventHandler): () => void;
|
|
400
|
-
/** 运行时动态新增/覆盖一个
|
|
401
|
-
|
|
402
|
-
/** 运行时移除一个
|
|
403
|
-
|
|
404
|
-
/** 列出当前所有已注册
|
|
405
|
-
|
|
410
|
+
/** 运行时动态新增/覆盖一个 数据槽注册项(懒加载组件:组件挂载时注册其 schema);立即对 数据槽工具生效,无需重建 agent。需开启 dataSlotOps */
|
|
411
|
+
addDataSlot(spec: DataSlotSpec): void;
|
|
412
|
+
/** 运行时移除一个 数据槽注册项(组件卸载);返回是否确实存在并移除。快照栈一并清理 */
|
|
413
|
+
removeDataSlot(path: string): boolean;
|
|
414
|
+
/** 列出当前所有已注册 数据槽(反映动态增删后的最新状态) */
|
|
415
|
+
listDataSlots(): DataSlotSpec[];
|
|
406
416
|
/** 乐观锁冲突挂起状态(响应式 ref;无冲突为 null,有冲突时 UI 据此渲染冲突对话框)。headless 集成方可 watch 自建 UI */
|
|
407
417
|
pendingConflict: Ref<PendingConflict | null>;
|
|
408
418
|
/** 冲突解决:用户点「保留外部」(keep_external)/「强制覆盖」(overwrite)/「回退」(restore) → 收口挂起的 conflict,被挂起的工具调用继续 */
|
|
409
419
|
resolveConflict(action: ConflictResolution['action']): void;
|
|
410
420
|
}
|
|
411
421
|
|
|
412
|
-
/** 乐观锁冲突挂起(
|
|
422
|
+
/** 乐观锁冲突挂起(dataSlotOps 写入时 expectedHash 不匹配,挂起等用户决定) */
|
|
413
423
|
export interface PendingConflict {
|
|
414
424
|
id: number;
|
|
415
425
|
path: string;
|
|
@@ -428,7 +438,7 @@ export type ConflictResolution =
|
|
|
428
438
|
| { action: 'overwrite' }
|
|
429
439
|
| { action: 'restore' };
|
|
430
440
|
|
|
431
|
-
/** 乐观锁冲突信息(
|
|
441
|
+
/** 乐观锁冲突信息(dataSlotOps onConflict 回调参数) */
|
|
432
442
|
export interface ConflictInfo {
|
|
433
443
|
path: string;
|
|
434
444
|
op: 'set' | 'edit' | 'delete';
|
|
@@ -446,12 +456,12 @@ export declare function defineTool(opts: {
|
|
|
446
456
|
schema: any;
|
|
447
457
|
handler: (args: any) => unknown | Promise<unknown>;
|
|
448
458
|
}): any;
|
|
449
|
-
export declare function
|
|
450
|
-
export declare function selectBuiltinTools(caps: {
|
|
451
|
-
export declare function createUsageHintsMiddleware(caps: { planning?: boolean;
|
|
459
|
+
export declare function createDataSlotOps(props: DataSlotSpec[], opts?: DataSlotOpsOptions): any[];
|
|
460
|
+
export declare function selectBuiltinTools(caps: { dataSlotOps?: boolean; fetch?: boolean } | undefined, dataSlotOps: any[], fetchDocs: any[]): any[];
|
|
461
|
+
export declare function createUsageHintsMiddleware(caps: { planning?: boolean; dataSlotOps?: boolean; subagent?: boolean } | undefined, hasDataSlotOps: boolean): any;
|
|
452
462
|
export declare const fetchDocTools: any[];
|
|
453
463
|
export declare const fetchTools: any[];
|
|
454
|
-
export declare function
|
|
464
|
+
export declare function defineDataSlotToolset(props: DataSlotSpec[], opts?: DataSlotOpsOptions): any[];
|
|
455
465
|
export declare function defineSkill(spec: SkillSpec): SkillSpec;
|
|
456
466
|
export declare function createAgent(options: any): any;
|
|
457
467
|
/** 检测模型把工具调用写成文本(伪 XML/标签)而非标准 tool_calls 的异常格式;主循环据此回灌 feedback 自纠 */
|
|
@@ -470,13 +480,13 @@ export declare function createMemoryBackend(): StorageBackend;
|
|
|
470
480
|
export declare function createWebStorageBackend(storage: Storage): StorageBackend;
|
|
471
481
|
export declare function isQuotaError(err: unknown): boolean;
|
|
472
482
|
|
|
473
|
-
// ============ 大 JSON 查询/搜索/沙箱脚本(
|
|
483
|
+
// ============ 大 JSON 查询/搜索/沙箱脚本(dataSlotQuery)============
|
|
474
484
|
export interface JpNode {
|
|
475
485
|
/** 相对属性根的点号路径(数组索引用数字,如 components.0.text) */
|
|
476
486
|
path: string;
|
|
477
487
|
/** 匹配元素值 */
|
|
478
488
|
value: unknown;
|
|
479
|
-
/** 父为数组时的索引(便于后续
|
|
489
|
+
/** 父为数组时的索引(便于后续 edit_data_slot 的 jsonPath 定位) */
|
|
480
490
|
index?: number;
|
|
481
491
|
}
|
|
482
492
|
export interface SearchHit {
|
|
@@ -550,10 +560,10 @@ export declare function createSubagentsMiddleware(opts: any): any;
|
|
|
550
560
|
export interface SubagentOptions { [k: string]: any }
|
|
551
561
|
export interface SubagentLlmConfig { [k: string]: any }
|
|
552
562
|
|
|
553
|
-
// checkpoint /
|
|
563
|
+
// checkpoint / dataSlotOps / permissions
|
|
554
564
|
export interface CheckpointDeps { [k: string]: any }
|
|
555
|
-
export interface
|
|
556
|
-
export interface
|
|
565
|
+
export interface DataSlotAuditEntry { [k: string]: any }
|
|
566
|
+
export interface DataSlotSnapshotEntry { [k: string]: any }
|
|
557
567
|
export type PermissionOp = string;
|
|
558
568
|
|
|
559
569
|
// vfs
|