page-agent-sdk 2.7.1 → 2.8.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 CHANGED
@@ -371,10 +371,20 @@ createChatSdk({
371
371
  maxRetries: 2, maxParallelTools: 1,
372
372
  subagent: { allowedTools: [...] },
373
373
  middleware: [/* custom middleware */],
374
- onEvent(e) { // SDK event callback: subscribe to common moments (data change / message update / tool call / error), replaces polling
374
+ onEvent(e) { // SDK event callback: data change / message update / tool call / usage / session_restored / error, replaces polling
375
375
  if (e.type === 'data_change') refreshUI()
376
+ if (e.type === 'usage') console.log('round tokens', e.usage, 'cumulative', e.cumulative)
377
+ if (e.type === 'session_restored') toast(`restored ${e.rounds} rounds`)
376
378
  },
379
+ // onAudit: (entry) => logAudit(entry), // structured audit of data writes (independent of debug)
377
380
  }).mount()
381
+
382
+ // Convenience API
383
+ // sdk.exportData() // deep copy of main data bind (backup/migrate)
384
+ // sdk.importData(json) // replace bind in-place (preserves reactive ref; schema-validated by default)
385
+ // sdk.setSkills(skills) // runtime swap the entire skill list (same-name overwrites; clears cache, index re-renders next round)
386
+ // sdk.invalidateSkillCache(name?) // invalidate skill full-text cache (proactive; omit name to clear all)
387
+ // sdk.usage // cumulative token usage {prompt_tokens, completion_tokens, total_tokens}
378
388
  ```
379
389
 
380
390
  ## Examples
@@ -407,8 +417,8 @@ Framework-agnostic integration: `demo/plain.html` (importmap + esm.sh).
407
417
  ## Self-tests
408
418
 
409
419
  ```bash
410
- npm test # 434 assertions (tsx, source-level; no LLM dependency)
411
- npm run test:e2e # 131 integration assertions (node, built dist; covers APIs/options/modules/simple&complex scenes: default systemPrompt(capability overview) / dynamic register + inspect sync / inspect(tools/middleware/subagent/verify/mcp/todos/lastCompression/checkpoints reflect config) / custom tools/middleware/skills/memory injection / switchSession(on/off) / shareContext on/off sharing/independent / storage backends + object config / presets(3) / checkpoint / exports complete(39+ fns/components) / util fns usable(isQuotaError/estimateTokens/jpEval/searchJson) / source=builtin / mount boundary / hook multi-listener / llm config / error scenes)
420
+ npm test # 450 assertions (tsx, source-level; no LLM dependency)
421
+ npm run test:e2e # 149 integration assertions (node, built dist; covers APIs/options/modules/simple&complex scenes: default systemPrompt(capability overview) / dynamic register + inspect sync / inspect(tools/middleware/subagent/verify/mcp/todos/lastCompression/checkpoints reflect config) / custom tools/middleware/skills/memory injection / switchSession(on/off) / shareContext on/off sharing/independent / storage backends + object config / presets(3) / checkpoint / exports complete(39+ fns/components) / util fns usable(isQuotaError/estimateTokens/jpEval/searchJson) / source=builtin / mount boundary / hook multi-listener / llm config / error scenes)
412
422
  ```
413
423
 
414
424
  ## Local npm package test
package/README.zh-CN.md CHANGED
@@ -316,10 +316,20 @@ createChatSdk({
316
316
  maxRetries: 2, maxParallelTools: 1,
317
317
  subagent: { allowedTools: [...] },
318
318
  middleware: [/* 自定义中间件 */],
319
- onEvent(e) { // SDK 事件回调:订阅常用时机(主数据变化/消息更新/工具调用/错误),替代轮询
319
+ onEvent(e) { // SDK 事件回调:订阅常用时机(主数据变化/消息更新/工具调用/用量/会话恢复/错误),替代轮询
320
320
  if (e.type === 'data_change') refreshUI()
321
+ if (e.type === 'usage') console.log('本轮 token', e.usage, '累计', e.cumulative)
322
+ if (e.type === 'session_restored') toast(`已恢复 ${e.rounds} 轮对话`)
321
323
  },
324
+ // onAudit: (entry) => logAudit(entry), // 数据写操作结构化审计(独立于 debug)
322
325
  }).mount()
326
+
327
+ // 便捷 API
328
+ // sdk.exportData() // 深拷贝主数据 bind(备份/迁移)
329
+ // sdk.importData(json) // 整体替换 bind(就地还原保留 reactive 引用,默认经 schema 校验)
330
+ // sdk.setSkills(skills) // 运行时替换整个 skill 列表(同名覆盖;清缓存,下轮索引重渲染)
331
+ // sdk.invalidateSkillCache(name?) // 清 skill 全文缓存(动态 skill 内容变化时主动失效)
332
+ // sdk.usage // 累计 token 用量 {prompt_tokens, completion_tokens, total_tokens}
323
333
  ```
324
334
 
325
335
  ## 示例
@@ -352,8 +362,8 @@ createChatSdk({
352
362
  ## 自测
353
363
 
354
364
  ```bash
355
- npm test # 434 项断言(tsx 源码级,不依赖 LLM)
356
- npm run test:e2e # 131 项集成断言(node 跑构建产物 dist;覆盖各 API/配置项/功能模块/简单与复杂场景:默认 systemPrompt(含能力概述) / 动态注册与 inspect 同步 / inspect(tools/middleware/subagent/verify/mcp/todos/lastCompression/checkpoints 反映配置) / 自定义 tools/middleware/skills/memory 注入 / switchSession(开/未开) / shareContext 开/关共享独立 / storage 后端+对象配置 / presets 三预设 / checkpoint / 导出项完整(39+ 函数/组件) / 工具函数可用(isQuotaError/estimateTokens/jpEval/searchJson) / source=builtin / mount 边界 / hook 多监听器 / llm 配置 / 错误场景)
365
+ npm test # 450 项断言(tsx 源码级,不依赖 LLM)
366
+ npm run test:e2e # 149 项集成断言(node 跑构建产物 dist;覆盖各 API/配置项/功能模块/简单与复杂场景:默认 systemPrompt(含能力概述) / 动态注册与 inspect 同步 / inspect(tools/middleware/subagent/verify/mcp/todos/lastCompression/checkpoints 反映配置) / 自定义 tools/middleware/skills/memory 注入 / switchSession(开/未开) / shareContext 开/关共享独立 / storage 后端+对象配置 / presets 三预设 / checkpoint / 导出项完整(39+ 函数/组件) / 工具函数可用(isQuotaError/estimateTokens/jpEval/searchJson) / source=builtin / mount 边界 / hook 多监听器 / llm 配置 / 错误场景)
357
367
  ```
358
368
 
359
369
  ## 本地 npm 包测试