page-agent-sdk 2.10.3 → 2.12.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 +18 -5
- package/README.zh-CN.md +17 -4
- package/dist/page-agent-sdk.css +1 -1
- package/dist/page-agent-sdk.iife.js +106 -106
- package/dist/page-agent-sdk.js +3440 -3229
- package/dist/page-agent-sdk.umd.cjs +66 -66
- package/package.json +2 -1
- package/skills/page-agent-sdk-integrate/references/advanced.md +28 -0
- package/skills/page-agent-sdk-integrate/references/api.md +56 -0
- package/skills/page-agent-sdk-integrate/references/integration-prompt.md +4 -0
- package/skills/page-agent-sdk-integrate/references/options.md +2 -1
- package/skills/page-agent-sdk-integrate/references/quickstart.md +34 -0
- package/types/index.d.ts +57 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "page-agent-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.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",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"dev": "vite",
|
|
29
29
|
"mcp:mock": "tsx scripts/mcp-mock-server.ts",
|
|
30
30
|
"mcp:probe": "tsx scripts/mcp-probe.ts",
|
|
31
|
+
"proxy:mock": "tsx scripts/proxy-mock-server.ts",
|
|
31
32
|
"verify:probe": "tsx scripts/verify-probe.ts",
|
|
32
33
|
"build": "npm run build:lib && npm run build:iife",
|
|
33
34
|
"build:lib": "vite build",
|
|
@@ -276,3 +276,31 @@ createChatSdk({
|
|
|
276
276
|
checkpoint: true, // rollback
|
|
277
277
|
}).mount()
|
|
278
278
|
```
|
|
279
|
+
|
|
280
|
+
## 6. Runtime dynamic reconfiguration (tools / llm / memory / subagents)
|
|
281
|
+
|
|
282
|
+
Beyond `setData` / `setSkills`, you can dynamically reconfigure **tools / LLM / memory / pre-declared subagents** at runtime — zero-breakage (not calling = current behavior), no agent rebuild (preserves conversation history & middleware state). All setters trigger `infoTick++` → DebugDrawer refresh; `inspect()` reflects the latest tools/model/memory/subagent.subagents.
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
// 1. Tools: swap/append/remove user tools at runtime (built-ins untouched; internal rebind)
|
|
286
|
+
sdk.setTools([toolA, toolB]) // replace user tool set (built-ins stay)
|
|
287
|
+
sdk.addTool(toolC) // append (dedup by name)
|
|
288
|
+
sdk.removeTool('toolA') // remove by name → boolean
|
|
289
|
+
|
|
290
|
+
// 2. LLM: switch model at runtime (quota-exhausted→cheaper / complex task→stronger / switch provider)
|
|
291
|
+
sdk.setLlm({ apiKey, baseUrl, model: 'gpt-4o' }) // LLMConfig form (constructs ChatOpenAI)
|
|
292
|
+
sdk.setLlm(otherChatModel) // or pass a BaseChatModel instance
|
|
293
|
+
// rebinds tools + re-resolves model caps (contextWindow/maxOutputTokens); summaryLlm unaffected
|
|
294
|
+
|
|
295
|
+
// 3. Memory: update persistent directive at runtime (next augmentPrompt injects latest)
|
|
296
|
+
sdk.setMemory('User is VIP; prefer concise answers; use incremental patch when editing.')
|
|
297
|
+
sdk.setMemory('') // clear (empty string skips injection)
|
|
298
|
+
|
|
299
|
+
// 4. Subagents: runtime add/remove pre-declared subagents (requires subagents:[] at creation)
|
|
300
|
+
// Pass subagents: [] (empty array) at creation to enable the controller for dynamic add later.
|
|
301
|
+
sdk.addSubagent({ id: 'translator', description: '中英互译子 agent', systemPrompt: '你是翻译助手。' })
|
|
302
|
+
sdk.removeSubagent('translator') // → boolean
|
|
303
|
+
sdk.setSubagents([{ id: 'a', description: 'A' }, { id: 'b', description: 'B' }]) // replace all
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
> **Note**: `setSystemPrompt` / `setMiddleware` (runtime middleware-array swap) are not yet implemented — they touch the harness core and are deferred. Use `setData` / `setSkills` / `augmentSystem` hook to cover most dynamic system-prompt scenarios. See `doc/roadmap.md` #5.
|
|
@@ -19,6 +19,14 @@
|
|
|
19
19
|
| `setSkills(skills)` | `(skills: SkillSpec[]) => void` | Runtime swap the entire skill list (same-name skill overwrites). Takes effect next round: the skill index section of the system prompt re-renders with the new skills; clears the skill full-text cache & in-round loaded set, so the next `load_skill` re-fetches the latest full text (incl. vfs doc). Requires skills enabled (default on). |
|
|
20
20
|
| `invalidateSkillCache(name?)` | `(name?: string) => void` | Invalidate the skill full-text cache (proactive invalidation when a dynamic skill's content changes). Omit `name` to clear all; pass `name` to clear one. The next `load_skill` re-runs `getContent`/`readSkillDoc`. Requires skills enabled (default on). |
|
|
21
21
|
| `usage` | `TokenUsage` | Cumulative token usage `{prompt_tokens, completion_tokens, total_tokens}` (accumulated per LLM call). |
|
|
22
|
+
| `setTools(tools)` | `(tools: StructuredToolInterface[]) => void` | Runtime swap user tools (built-ins untouched; internal `rebindTools` re-binds to LLM; next round uses new set). Zero-breakage: not calling = current behavior. Supports per-permission/business-stage/A-B-test dynamic tool groups without rebuilding agent. |
|
|
23
|
+
| `addTool(tool)` | `(tool: StructuredToolInterface) => void` | Append user tool at runtime (dedup by name; built-ins untouched). |
|
|
24
|
+
| `removeTool(name)` | `(name: string) => boolean` | Remove user tool at runtime (built-ins untouched). Returns whether removed. |
|
|
25
|
+
| `setLlm(llm)` | `(llm: BaseChatModel \| LLMConfig) => void` | Switch LLM at runtime (quota-exhausted→cheaper model / complex task→stronger model / switch provider). Param `BaseChatModel` or `LLMConfig` (constructs `ChatOpenAI` internally). Rebinds tools + re-resolves model caps (`contextWindow`/`maxOutputTokens`). `summaryLlm` unaffected. If new model lacks `bindTools`, tool-calling degrades (agent stays up). |
|
|
26
|
+
| `setMemory(text)` | `(text: string) => void` | Update persistent memory directive at runtime (next `augmentPrompt` injects latest; `setMemory('')` clears). |
|
|
27
|
+
| `setSubagents(configs)` | `(configs: SubagentConfig[]) => void` | Runtime swap pre-declared subagents (regenerates `use_<id>` delegation tools + triggers rebind). Requires `subagents:[]` at creation (else controller is null, setter warns, no throw). |
|
|
28
|
+
| `addSubagent(config)` | `(config: SubagentConfig) => void` | Append pre-declared subagent at runtime (duplicate id warns & skips). Requires `subagents:[]` at creation. |
|
|
29
|
+
| `removeSubagent(id)` | `(id: string) => boolean` | Remove pre-declared subagent at runtime (by id). Returns whether removed. Requires `subagents:[]` at creation. |
|
|
22
30
|
| `restoreLastCheckpoint()` | `() => boolean` | Restore last good checkpoint (needs `checkpoint` enabled). |
|
|
23
31
|
| `listCheckpoints()` | `() => CheckpointMeta[]` | List available checkpoints. |
|
|
24
32
|
| `addSkill(skill)` | `(skill: { name, description, prompt \| getContent \| doc }) => void` | Add a user-created skill at runtime. Auto-merges into the skill list, persists via **independent SkillStore** (default indexedDB, separate from `storage` option), takes effect next round. Same-name overwrites. Requires `capabilities.skills` (default on) + `skillStorage` not `false` for persistence. |
|
|
@@ -164,6 +172,12 @@ createChatSdk({
|
|
|
164
172
|
- **Notifying the outside world of changes**: subscribe `data_change` via `onEvent` (constructor) or `sdk.hook` (runtime, multi-listener, cancellable) — fires after `write`/`set`/`edit`/`delete`/`restore`, with `operation`/`value`. For Vue + reactive bind, template/watch auto-react (no manual notify needed); `onEvent` can coexist for audit/analytics.
|
|
165
173
|
- **Runtime swap**: `sdk.setData({ schema, bind, description? })` replaces the whole config; tools pick up immediately (no rebuild). Snapshots & lock hash reset.
|
|
166
174
|
- **Runtime skill swap**: `sdk.setSkills(skills)` replaces the entire skill list (same-name overwrites); the skill index section of the system prompt re-renders next round, and the skill full-text cache is cleared so the next `load_skill` re-fetches the latest content (incl. vfs doc). Use `sdk.invalidateSkillCache(name?)` to proactively invalidate the cache when a dynamic skill's content changes (without swapping the whole list).
|
|
175
|
+
- **Runtime dynamic reconfiguration (zero-breakage; not calling = current behavior)**: beyond data/skills, you can also dynamically reconfigure tools / LLM / memory / subagents at runtime without rebuilding the agent:
|
|
176
|
+
- `sdk.setTools(tools)` / `addTool(tool)` / `removeTool(name)` — swap/append/remove user tools (built-ins untouched; internal `rebindTools` re-binds to LLM; next round uses new set). Use cases: per-permission tool groups, business-stage gating, A/B experiments.
|
|
177
|
+
- `sdk.setLlm(llm)` — switch LLM at runtime (quota-exhausted→cheaper model / complex task→stronger model / switch provider). Param `BaseChatModel` or `LLMConfig`. Rebinds tools + re-resolves model caps. `summaryLlm` unaffected.
|
|
178
|
+
- `sdk.setMemory(text)` — update the persistent memory directive at runtime (next `augmentPrompt` injects latest).
|
|
179
|
+
- `sdk.setSubagents(configs)` / `addSubagent(config)` / `removeSubagent(id)` — swap/append/remove pre-declared subagents (regenerates `use_<id>` delegation tools + triggers rebind). Requires `subagents:[]` at creation.
|
|
180
|
+
- All setters trigger `infoTick++` → DebugDrawer refreshes; `inspect()` reflects the latest tools/model/memory/subagent.subagents.
|
|
167
181
|
|
|
168
182
|
## Exported building blocks (for custom UIs)
|
|
169
183
|
|
|
@@ -173,3 +187,45 @@ createChatSdk({
|
|
|
173
187
|
- Middleware factories: `createApprovalMiddleware`, `createVerifyMiddleware`, `createWriteBackCheck`, `createSubagentMiddleware`, `createCheckpointMiddleware`, `createUsageHintsMiddleware`
|
|
174
188
|
- Storage: `createSessionStore`, `createMemoryBackend`, `createWebStorageBackend`, `isQuotaError`
|
|
175
189
|
- JSON helpers: `jpEval`, `searchJson`, `runSandboxedScript`, `toolError`, `zodError`
|
|
190
|
+
|
|
191
|
+
## Proxy connection (`createProxyLlm`) — prevent apiKey leakage
|
|
192
|
+
|
|
193
|
+
Browser-direct LLM calls expose `apiKey` in DevTools. Use `createProxyLlm` to unify dev/prod access:
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
import { createChatSdk, createProxyLlm } from 'page-agent-sdk'
|
|
197
|
+
|
|
198
|
+
// Production: proxy mode (server injects real key)
|
|
199
|
+
createChatSdk({
|
|
200
|
+
llm: createProxyLlm({
|
|
201
|
+
mode: 'proxy',
|
|
202
|
+
baseUrl: '/api/llm', // your proxy (same-origin avoids CORS)
|
|
203
|
+
userToken: getUserToken(), // session token (server validates)
|
|
204
|
+
model: 'deepseek-chat',
|
|
205
|
+
refreshToken?: async () => ..., // optional: refresh on 401
|
|
206
|
+
headers?: { 'X-Tenant': 'acme' }, // optional: extra headers
|
|
207
|
+
}),
|
|
208
|
+
...
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
// Dev: direct mode (browser holds real key; dev only)
|
|
212
|
+
createChatSdk({
|
|
213
|
+
llm: createProxyLlm({
|
|
214
|
+
mode: 'direct',
|
|
215
|
+
apiKey: 'sk-xxx',
|
|
216
|
+
baseUrl: 'https://api.deepseek.com/v1',
|
|
217
|
+
model: 'deepseek-chat',
|
|
218
|
+
}),
|
|
219
|
+
...
|
|
220
|
+
})
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
| | `proxy` (prod) | `direct` (dev) |
|
|
224
|
+
|---|---|---|
|
|
225
|
+
| apiKey | server (invisible) | browser (DevTools visible) |
|
|
226
|
+
| browser holds | userToken | real apiKey |
|
|
227
|
+
| token refresh | yes (401 retry) | n/a |
|
|
228
|
+
| headers | supported | n/a |
|
|
229
|
+
|
|
230
|
+
Server-side proxy essentials: validate userToken → inject real apiKey → forward to LLM API; handle CORS; stream SSE through; pass tool-calling fields. See `doc/usage-guide*.md` §8.6 for full guide.
|
|
231
|
+
|
|
@@ -146,6 +146,7 @@ const sdk = createChatSdk({
|
|
|
146
146
|
5. **Schema whitelist**: `z.object` auto-enables whitelist (only declared fields exposed); `discriminatedUnion`/`record`/`lazy` non-top-level don't enable (fully open)
|
|
147
147
|
6. **Vue2 new-property non-reactive**: `write` patch `set` on a new field — Vue2 `Object.defineProperty` won't react → `onEvent('data_change')` `tick++`, use `:key="tick"` to force rebuild
|
|
148
148
|
7. **MCP cold-start injects 0 tools**: `vite.config.ts` `optimizeDeps.include` pre-declares SDK sub-paths; keep those entries when forking config, else first MCP page load injects nothing (reload fixes)
|
|
149
|
+
8. **apiKey leakage in production**: browser-direct LLM calls expose `apiKey` in DevTools. Use `createProxyLlm({ mode:'proxy', baseUrl:'/api/llm', userToken })` — browser holds only user token, your server injects the real key. See `references/quickstart.md` Stage 8 + `doc/usage-guide*.md` §8.6.
|
|
149
150
|
|
|
150
151
|
## Verification checklist
|
|
151
152
|
|
|
@@ -155,6 +156,8 @@ const sdk = createChatSdk({
|
|
|
155
156
|
- [ ] [Reactive bind] edits → UI reacts; [non-reactive] `data_change` → re-render
|
|
156
157
|
- [ ] [Drawer mode] close then open (`show()`) → history & in-flight generation preserved
|
|
157
158
|
- [ ] Schema validation failure → structured error, no write
|
|
159
|
+
- [ ] [Production] `createProxyLlm({ mode:'proxy' })` — real apiKey not in browser bundle / network tab
|
|
160
|
+
- [ ] [Production] `createProxyLlm({ mode:'proxy' })` — real apiKey not in browser bundle / network tab
|
|
158
161
|
|
|
159
162
|
## References
|
|
160
163
|
|
|
@@ -177,3 +180,4 @@ Per your business scenario, fill in `systemPrompt` / `skills` / `data.schema`:
|
|
|
177
180
|
- **Multi-agent on one page**: same `id` + `shareContext:true` → multiple dialogs share one `AgentCore`; or independent `id`s + `dialog.drawer:true` + `hide`/`show` for exclusive switching
|
|
178
181
|
- **MCP integration**: `mcp:[{transport,url}]` remote tool servers; `@modelcontextprotocol/sdk` optional peerDep
|
|
179
182
|
- **Dynamic/lazy-loaded schema**: `sdk.setData({ schema, bind })` on component mount to swap main data; tools pick up immediately, no rebuild
|
|
183
|
+
- **Production proxy (prevent apiKey leakage)**: `createProxyLlm({ mode:'proxy', baseUrl:'/api/llm', userToken, refreshToken })` — browser holds only user token, server injects real key + forwards; dev uses `mode:'direct'` with real key. See `examples/proxy-demo/` + `npm run proxy:mock`
|
|
@@ -9,6 +9,7 @@ Full reference for `createChatSdk(options)`. Grouped by purpose. Required: `llm`
|
|
|
9
9
|
| `llm` | `LLMConfig \| BaseChatModel` | — (required) | The model. `LLMConfig = { apiKey, baseUrl, model, temperature?, maxTokens? }` (OpenAI-compatible; DeepSeek default). Or pass any LangChain `BaseChatModel` (e.g. `ChatAnthropic`, install its peerDep). |
|
|
10
10
|
| `systemPrompt` | `string` | built-in default (JSON-operation assistant + reliable write rules) | Agent identity/instructions. Inject here, not hardcoded. Keep single-line in `.env` (`VITE_AI_SYSTEM_PROMPT`). If omitted, a built-in default is used (JSON-operation assistant + `systemPromptHelpers.reliableWriteRules`); passing your own fully overrides it. |
|
|
11
11
|
| `appendReliableWriteRules` | `boolean` | `true` | When `true` (default) and a custom `systemPrompt` is set, auto-append `systemPromptHelpers.reliableWriteRules` to it with a `---` separator (clearly distinguishes user content from SDK-appended write rules; avoids forgetting the write rules). Set `false` to disable. No effect when `systemPrompt` is omitted (default prompt already includes them). |
|
|
12
|
+
| `augmentSystem` | `(ctx:{state,data?}) => string \| undefined` | — | Dynamic system-prompt injection hook. Called each turn; return a string to inject as a segment, or `undefined` to skip. Callback errors degrade to skip (no crash). `ctx.data` is taken from `liveData()` each turn (auto-syncs after `setData`), so you can compute dynamic component descriptions / partial schema hints from current runtime state. Segment is placed after built-in segments (base/dataHint/usageHints/.../subagents) and before user `middleware`. Not set = current behavior (no segment). See `doc/system-prompt.md` §B6. |
|
|
12
13
|
| `id` | `string` | random + warn | Stable agent id for multi-agent isolation & persistence. **Must pass a stable value** if you use `storage` or run multiple agents on one page. |
|
|
13
14
|
|
|
14
15
|
## UI & mounting
|
|
@@ -98,7 +99,7 @@ Full reference for `createChatSdk(options)`. Grouped by purpose. Required: `llm`
|
|
|
98
99
|
| Option | Type | Default | Purpose / when |
|
|
99
100
|
|---|---|---|---|
|
|
100
101
|
| `subagent` | `object` | enabled | `{ enabled?, allowedTools?, systemPrompt?, temperature?, maxTokens?, skills?, llm?, maxDepth?, maxParallel? }`. `maxDepth` (1) physically cuts recursion. Subagents get a read-only tool subset (no spawn). |
|
|
101
|
-
| `subagents` | `SubagentConfig[]` | `[]` | Pre-declared named subagents → each auto-generates a `use_<id>({ task })` delegation tool (Claude-Code style). Fixed roles (research/review) vs ad-hoc `spawn_agent`. |
|
|
102
|
+
| `subagents` | `SubagentConfig[]` | `[]` | Pre-declared named subagents → each auto-generates a `use_<id>({ task })` delegation tool (Claude-Code style). Fixed roles (research/review) vs ad-hoc `spawn_agent`. Pass `[]` (empty array) to enable the `SubagentsController` for runtime `addSubagent`/`removeSubagent`/`setSubagents` (initial no subagents, add dynamically later). |
|
|
102
103
|
|
|
103
104
|
## Verify (self-check before return)
|
|
104
105
|
|
|
@@ -147,6 +147,40 @@ sdk.getData() // read current config
|
|
|
147
147
|
|
|
148
148
|
**Full runnable demo**: `examples/dynamic-demo/` (`npm run dev` → `/examples/dynamic-demo/`).
|
|
149
149
|
|
|
150
|
+
## Stage 8 — Production: proxy the LLM (prevent apiKey leakage)
|
|
151
|
+
|
|
152
|
+
Browser-direct LLM calls expose your `apiKey` in DevTools — anyone can drain your quota. **Production must proxy through your server**: the browser holds only a user token; your server injects the real `apiKey` and forwards. Use `createProxyLlm` to unify dev (direct) and prod (proxy) without restructuring:
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
import { createChatSdk, createProxyLlm } from 'page-agent-sdk'
|
|
156
|
+
|
|
157
|
+
// Production: proxy mode (safe — real key stays server-side)
|
|
158
|
+
const sdk = createChatSdk({
|
|
159
|
+
container: '#root',
|
|
160
|
+
llm: createProxyLlm({
|
|
161
|
+
mode: 'proxy',
|
|
162
|
+
baseUrl: '/api/llm', // your proxy (same-origin avoids CORS)
|
|
163
|
+
userToken: getUserToken(), // session token (server validates, swaps in real key)
|
|
164
|
+
model: 'deepseek-chat',
|
|
165
|
+
refreshToken: async () => (await (await fetch('/api/refresh')).json()).token, // auto-refresh on 401
|
|
166
|
+
headers: { 'X-Tenant': 'acme' }, // optional custom headers
|
|
167
|
+
}),
|
|
168
|
+
// ...data, systemPrompt...
|
|
169
|
+
}).mount()
|
|
170
|
+
|
|
171
|
+
// Dev: direct mode (convenient — real key in browser; dev only)
|
|
172
|
+
const sdkDev = createChatSdk({
|
|
173
|
+
container: '#root',
|
|
174
|
+
llm: createProxyLlm({
|
|
175
|
+
mode: 'direct',
|
|
176
|
+
apiKey: 'sk-...', baseUrl: 'https://api.deepseek.com/v1', model: 'deepseek-chat',
|
|
177
|
+
}),
|
|
178
|
+
// ...data, systemPrompt...
|
|
179
|
+
}).mount()
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Both modes require an **OpenAI Chat Completions compatible** endpoint (the SDK uses `ChatOpenAI` internally). The proxy must: validate `userToken` → inject real `apiKey` → forward to upstream → stream SSE through → pass `tools`/`tool_calls` through. See `doc/usage-guide*.md` §8.6 for the full guide + a Node.js proxy example, and `examples/proxy-demo/` for a runnable demo (`npm run proxy:mock` + `npm run dev` → `/examples/proxy-demo/`).
|
|
183
|
+
|
|
150
184
|
## Next
|
|
151
185
|
|
|
152
186
|
- All options: see [options.md](options.md)
|
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { DefineComponent, Ref } from 'vue';
|
|
2
2
|
export { z } from 'zod';
|
|
3
3
|
|
|
4
|
+
// 代理连接模块(防 apiKey 泄露:proxy 代理模式 / direct 直连模式)
|
|
5
|
+
export type ProxyLlmMode = 'proxy' | 'direct';
|
|
6
|
+
export interface ProxyLlmOptions {
|
|
7
|
+
mode: ProxyLlmMode;
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
userToken?: string;
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
model?: string;
|
|
12
|
+
temperature?: number;
|
|
13
|
+
maxTokens?: number;
|
|
14
|
+
refreshToken?: () => Promise<string>;
|
|
15
|
+
headers?: Record<string, string>;
|
|
16
|
+
}
|
|
17
|
+
export declare function createProxyLlm(opts: ProxyLlmOptions): import('@langchain/core/language_models/chat_models').BaseChatModel;
|
|
18
|
+
|
|
4
19
|
export interface ToolStep {
|
|
5
20
|
name: string;
|
|
6
21
|
args?: any;
|
|
@@ -95,6 +110,8 @@ export interface SubagentInfo {
|
|
|
95
110
|
maxDepth: number;
|
|
96
111
|
maxParallel: number;
|
|
97
112
|
allowedTools: string[];
|
|
113
|
+
/** 预声明子 agent 列表(动态:反映 setSubagents/addSubagent/removeSubagent 后的最新) */
|
|
114
|
+
subagents?: { id: string; description: string }[];
|
|
98
115
|
}
|
|
99
116
|
/** 预声明子 agent 配置(同主配置子集 + id/description;缺省继承主 agent) */
|
|
100
117
|
export interface SubagentConfig {
|
|
@@ -354,6 +371,16 @@ export interface SessionOptions {
|
|
|
354
371
|
title?: string;
|
|
355
372
|
}
|
|
356
373
|
|
|
374
|
+
/**
|
|
375
|
+
* augmentSystem 钩子上下文:集成方回调据此按运行时状态动态注入 system prompt 段。
|
|
376
|
+
* - `state`:harness 当前状态(messages/todos/files/skills/memory…);不含 data(data 是 createChatSdk 层概念)
|
|
377
|
+
* - `data`:当前主数据配置(每轮从 liveData() 取最新,setData 后自动同步;含 schema/bind/description)
|
|
378
|
+
*/
|
|
379
|
+
export interface SystemAugmentContext {
|
|
380
|
+
state: any;
|
|
381
|
+
data?: DataConfig;
|
|
382
|
+
}
|
|
383
|
+
|
|
357
384
|
export interface ChatSdkOptions {
|
|
358
385
|
container?: string | HTMLElement;
|
|
359
386
|
/** UI:'default'(内置 ChatDialog)/ false(headless 不渲染,自建 UI) */
|
|
@@ -367,9 +394,17 @@ export interface ChatSdkOptions {
|
|
|
367
394
|
session?: SessionOptions;
|
|
368
395
|
/** 共享上下文:默认 false;true 时同 id 复用同一核心(messages/agent/工作区) */
|
|
369
396
|
shareContext?: boolean;
|
|
397
|
+
/** 系统提示词(base + 可操作数据段,数据段随 data 动态;不含 todos/skills/memory/augmentSystem 等运行态 augmentPrompt 段) */
|
|
370
398
|
systemPrompt?: string;
|
|
371
399
|
/** 自定义 systemPrompt 时是否自动追加 reliableWriteRules(默认 true,用 '---' 分隔线区分;设 false 关闭;不传 systemPrompt 用默认 prompt 时已内置,此项无效) */
|
|
372
400
|
appendReliableWriteRules?: boolean;
|
|
401
|
+
/**
|
|
402
|
+
* 动态 system prompt 注入钩子:每轮 buildSystemPrompt 时调用,集成方按运行时状态(state/data)返回字符串 → 作为 system prompt 一段注入;返回 undefined → 跳过。
|
|
403
|
+
* - ctx.data 每轮从 liveData() 取最新(setData 后自动同步),可据此动态算组件说明 / 部分 schema 描述
|
|
404
|
+
* - 回调异常降级为跳过该段 + debug 日志(不崩 agent)
|
|
405
|
+
* - 段排在内置段之后、用户 middleware 之前;不配 = 完全现状行为
|
|
406
|
+
*/
|
|
407
|
+
augmentSystem?: (ctx: SystemAugmentContext) => string | undefined;
|
|
373
408
|
tools?: any[];
|
|
374
409
|
skills?: SkillSpec[];
|
|
375
410
|
/** 用户创建 skill 的独立持久化存储(与 storage 选项分离)。默认 `{ backend: 'indexed' }`(即使 storage:false 也持久化);`false` 关闭;`id` 手动指定同一 id 可跨页面/跨 agent 复用 */
|
|
@@ -510,6 +545,22 @@ export interface ChatSdk {
|
|
|
510
545
|
pendingConflict: Ref<PendingConflict | null>;
|
|
511
546
|
/** 冲突解决:用户点「保留外部」(keep_external)/「强制覆盖」(overwrite)/「回退」(restore) → 收口挂起的 conflict,被挂起的工具调用继续 */
|
|
512
547
|
resolveConflict(action: ConflictResolution['action']): void;
|
|
548
|
+
/** 运行时替换用户工具集(内置工具不动);立即 rebind + infoTick 刷新 */
|
|
549
|
+
setTools(tools: any[]): void;
|
|
550
|
+
/** 运行时追加用户工具(去重 by name);立即生效 */
|
|
551
|
+
addTool(tool: any): void;
|
|
552
|
+
/** 运行时移除用户工具(by name;内置不动);返回是否移除成功 */
|
|
553
|
+
removeTool(name: string): boolean;
|
|
554
|
+
/** 运行时切换 LLM(BaseChatModel 或 LLMConfig);rebind + 重解析能力 + infoTick */
|
|
555
|
+
setLlm(llm: ChatModelLike | LLMConfig): void;
|
|
556
|
+
/** 运行时更新 memory 文本;立即生效 + infoTick */
|
|
557
|
+
setMemory(text: string): void;
|
|
558
|
+
/** 运行时替换预声明子 agent 列表(重新生成委派工具 + rebind);需创建时配 subagents:[] */
|
|
559
|
+
setSubagents(configs: SubagentConfig[]): void;
|
|
560
|
+
/** 运行时追加预声明子 agent(id 重复 warn 跳过);需创建时配 subagents:[] */
|
|
561
|
+
addSubagent(config: SubagentConfig): void;
|
|
562
|
+
/** 运行时移除预声明子 agent(by id);返回是否移除成功;需创建时配 subagents:[] */
|
|
563
|
+
removeSubagent(id: string): boolean;
|
|
513
564
|
}
|
|
514
565
|
|
|
515
566
|
/** 乐观锁冲突挂起(dataOps 写入时 expectedHash 不匹配,挂起等用户决定) */
|
|
@@ -668,6 +719,12 @@ export interface StateUpdate { [k: string]: any }
|
|
|
668
719
|
|
|
669
720
|
// 子 agent
|
|
670
721
|
export declare function createSubagentsMiddleware(opts: any): any;
|
|
722
|
+
export interface SubagentsController {
|
|
723
|
+
set(configs: SubagentConfig[]): void;
|
|
724
|
+
add(config: SubagentConfig): void;
|
|
725
|
+
remove(id: string): boolean;
|
|
726
|
+
get(): SubagentConfig[];
|
|
727
|
+
}
|
|
671
728
|
export interface SubagentOptions { [k: string]: any }
|
|
672
729
|
export interface SubagentLlmConfig { [k: string]: any }
|
|
673
730
|
|