page-agent-sdk 2.34.0 → 2.36.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
@@ -195,7 +195,7 @@ resolveContextOptions, CONTEXT_PRESETS, resolveModelCaps, estimateTokens, isCont
195
195
  // storage
196
196
  createSessionStore, createMemoryBackend, createWebStorageBackend, isQuotaError
197
197
  // UI (reuse when headless)
198
- ChatDialog, MessageContent, CodePreview, SkillPanel, useChat
198
+ ChatDialog, MessageContent, CodePreview, SkillPanel, DebugDrawer, useChat
199
199
  // types (omitted): ChatSdkOptions, Middleware, SubagentConfig, SkillSpec, DataConfig, AgentMessage, StreamEvent …
200
200
  ```
201
201
 
@@ -490,8 +490,7 @@ After `npm run dev`, visit the corresponding page:
490
490
  | mcp-demo | `/examples/mcp-demo/` | MCP remote tools (needs `npm run mcp:mock`) |
491
491
  | animation-demo | `/examples/animation-demo/` | ChatDialog enter/collapse/unmount animations + inline/drawer + hide/show |
492
492
  | multi-agent-demo | `/examples/multi-agent-demo/` | Multi-agent parallel + exclusive switch (3 independent agents, drawer hide/show keeps each history) |
493
- | proxy-demo | `/examples/proxy-demo/` | Proxy connection to prevent apiKey leakage (browser holds only userToken, proxy injects real key; includes auto-refresh on expired token; needs `npm run proxy:mock`) |
494
- | anthropic-demo | `/examples/anthropic-demo/` | Anthropic Claude (`provider:'anthropic'` uses Claude native protocol; streaming text + extended thinking; needs `.env` with Anthropic key + `claude-*` model) |
493
+ | proxy-demo | `/examples/proxy-demo/` | LLM connection config: proxy to prevent apiKey leakage (browser holds only userToken, proxy injects real key; auto-refresh on expired token; needs `npm run proxy:mock`) + Provider switch (`provider:'anthropic'` for Claude native protocol, streaming + extended thinking) |
495
494
 
496
495
  Framework-agnostic integration: `demo/plain.html` (importmap + esm.sh).
497
496
 
@@ -582,27 +581,29 @@ The package ships three builds — pick by integration scenario:
582
581
  | ESM (bundled, peer external) | `dist/page-agent-sdk.js` | `import` via npm or esm.sh — recommended for module hosts | ~620 KB |
583
582
  | UMD | `dist/page-agent-sdk.umd.cjs` | `require()` in Node/legacy bundlers | ~560 KB |
584
583
  | IIFE (all-inlined, single file) | `dist/page-agent-sdk.iife.js` | `<script src>` CDN direct include, zero config | ~1.4 MB |
584
+ | **headless ESM** (no UI layer) | `dist/page-agent-sdk.headless.js` | `page-agent-sdk/headless` — pure core for `ui:false` custom UI | **~325 KB** |
585
585
 
586
586
  ### Import only what you need (subpath exports)
587
587
 
588
- Besides the top-level `import { createChatSdk } from 'page-agent-sdk'`, three subpath entries scope your import to a single capability (the bundler tree-shakes the rest):
588
+ Besides the top-level `import { createChatSdk } from 'page-agent-sdk'`, four subpath entries scope your import to a single capability:
589
589
 
590
590
  | subpath | key exports | use case |
591
591
  |---|---|---|
592
592
  | `page-agent-sdk/storage` | `createSessionStore` / `createMemoryBackend` / `createWebStorageBackend` / `isQuotaError` | persistence layer only, no Agent |
593
593
  | `page-agent-sdk/query` | `jpEval` / `searchJson` / `runSandboxedScript` + all jsonUtils/schemaUtils pure fns | JSON query / sandbox / path helpers |
594
594
  | `page-agent-sdk/llm` | `createProxyLlm` + `ProxyLlmMode` / `ProxyLlmOptions` | proxy connection to avoid leaking apiKey |
595
+ | `page-agent-sdk/headless` | `createChatSdk` + full core API — **without** ChatDialog/marked/highlight.js/dompurify | `ui:false` custom UI, leanest bundle |
595
596
 
596
597
  ```js
597
598
  import { createSessionStore, createMemoryBackend } from 'page-agent-sdk/storage'
598
599
  import { jpEval, searchJson } from 'page-agent-sdk/query'
599
600
  ```
600
601
 
601
- > All three subpaths currently resolve to the same dist + types (no multi-entry build yet) — clear semantics and per-entry CDN fetch; when a multi-entry build lands, your import paths won't change.
602
+ > `storage` / `query` / `llm` resolve to the same dist + types (clear semantics and per-entry CDN fetch); when a multi-entry build lands, your import paths won't change. `headless` is a **separately-built lean bundle** (own dist + types) — see below.
602
603
 
603
604
  `sideEffects` is set to `["**/*.css"]` only, so bundlers can tree-shake the JS when you import named symbols. Tips to keep your bundle lean:
604
605
 
605
- - **Headless (`ui:false`)**: skip the built-in dialog and render `agent.messages` yourself — you can avoid importing `ChatDialog`/`CodePreview` and drop the CSS (`import 'page-agent-sdk'` without `'page-agent-sdk/style.css'`).
606
+ - **Headless (`ui:false`)**: skip the built-in dialog and render `agent.messages` yourself. For the leanest bundle, import from the **headless subpath** `import { createChatSdk } from 'page-agent-sdk/headless'` (~325 KB ESM vs ~789 KB main; drops marked/highlight.js/dompurify/ChatDialog you never use at runtime). Same `createChatSdk(options): ChatSdk` signature; pair with `ui:false`. From the main package you can also avoid importing `ChatDialog`/`CodePreview` and drop the CSS (`import 'page-agent-sdk'` without `'page-agent-sdk/style.css'`). **Persistence pitfall**: `sdk.stream` does NOT auto-persist (built-in `useChat` calls `afterRound` via `onPersist`); in a self-built dialog call `sdk.afterRound()` after each turn, otherwise `switchSession` won't restore messages. **Reuse the built-in DebugDrawer** (main package only): `import { DebugDrawer }` — pure-props (`logs=sdk.debugLogs`, `getInfo=()=>sdk.inspect()`, `infoTick=sdk.infoTick`), mount it in your own UI without needing ChatDialog.
606
607
  - **Disable unused capabilities**: `capabilities:{ dataOps:false, fetch:false, planning:false, skills:false, vfs:false, summarization:false, memory:false, subagent:false }` — removes the corresponding tool schemas and middleware from the agent prompt (saves tokens, not bytes).
607
608
  - **CDN via esm.sh**: `import { createChatSdk } from 'https://esm.sh/page-agent-sdk'` — peer deps (`zod`, `@langchain/*`) are resolved and deduped by esm.sh automatically; smallest for module scenarios.
608
609
  - **IIFE only for zero-config**: the all-inlined single file is convenient but heaviest; prefer ESM when the host supports modules.
package/README.zh-CN.md CHANGED
@@ -189,7 +189,7 @@ resolveContextOptions, CONTEXT_PRESETS, resolveModelCaps, estimateTokens, isCont
189
189
  // 存储
190
190
  createSessionStore, createMemoryBackend, createWebStorageBackend, isQuotaError
191
191
  // UI(headless 自建 UI 复用)
192
- ChatDialog, MessageContent, CodePreview, SkillPanel, useChat
192
+ ChatDialog, MessageContent, CodePreview, SkillPanel, DebugDrawer, useChat
193
193
  // 类型(略):ChatSdkOptions, Middleware, SubagentConfig, SkillSpec, DataConfig, AgentMessage, StreamEvent …
194
194
  ```
195
195
 
@@ -435,8 +435,7 @@ createChatSdk({
435
435
  | mcp-demo | `/examples/mcp-demo/` | MCP 远程工具(需 `npm run mcp:mock`) |
436
436
  | animation-demo | `/examples/animation-demo/` | ChatDialog 入场/收起/卸载动画 + inline/drawer 模式 + hide/show |
437
437
  | multi-agent-demo | `/examples/multi-agent-demo/` | 多 Agent 并行 + 互斥切换(三独立 agent,drawer hide/show 保留各自历史) |
438
- | proxy-demo | `/examples/proxy-demo/` | 代理连接防 apiKey 泄露(浏览器只持 userToken,代理注入真实 key;含 token 过期自动刷新;需 `npm run proxy:mock`) |
439
- | anthropic-demo | `/examples/anthropic-demo/` | Anthropic Claude(`provider:'anthropic'` 走 Claude 原生协议;流式文本 + extended thinking;需 `.env` 配 Anthropic key + `claude-*` model) |
438
+ | proxy-demo | `/examples/proxy-demo/` | LLM 连接配置:代理防 apiKey 泄露(浏览器只持 userToken,代理注入真实 key;含 token 过期自动刷新;需 `npm run proxy:mock`)+ Provider 切换(`provider:'anthropic'` 走 Claude 原生协议,流式 + extended thinking) |
440
439
 
441
440
  框架无关集成:`demo/plain.html`(importmap + esm.sh)。
442
441
 
@@ -527,27 +526,29 @@ createChatSdk({
527
526
  | ESM(peer 外置) | `dist/page-agent-sdk.js` | npm 或 esm.sh `import`,模块化宿主推荐 | ~620 KB |
528
527
  | UMD | `dist/page-agent-sdk.umd.cjs` | Node/老 bundler `require` | ~560 KB |
529
528
  | IIFE(全量单文件) | `dist/page-agent-sdk.iife.js` | CDN `<script>` 直引,零配置 | ~1.4 MB |
529
+ | **headless ESM**(无 UI 层) | `dist/page-agent-sdk.headless.js` | `page-agent-sdk/headless` —— `ui:false` 自建 UI 纯核心 | **~325 KB** |
530
530
 
531
531
  ### 按需引入(subpath exports)
532
532
 
533
- 除了顶层 `import { createChatSdk } from 'page-agent-sdk'`,三个子路径入口让你只引特定能力(bundler 对未用部分 tree-shaking):
533
+ 除了顶层 `import { createChatSdk } from 'page-agent-sdk'`,四个子路径入口让你只引特定能力:
534
534
 
535
535
  | subpath | 主要导出 | 场景 |
536
536
  |---|---|---|
537
537
  | `page-agent-sdk/storage` | `createSessionStore` / `createMemoryBackend` / `createWebStorageBackend` / `isQuotaError` | 只要持久化层,不引 Agent |
538
538
  | `page-agent-sdk/query` | `jpEval` / `searchJson` / `runSandboxedScript` + jsonUtils/schemaUtils 全部纯函数 | JSON 查询 / 沙箱 / 路径操作工具集 |
539
539
  | `page-agent-sdk/llm` | `createProxyLlm` + `ProxyLlmMode` / `ProxyLlmOptions` | 防 apiKey 泄露的代理连接 |
540
+ | `page-agent-sdk/headless` | `createChatSdk` + 全核心 API —— **不含** ChatDialog/marked/highlight.js/dompurify | `ui:false` 自建 UI,最精简 bundle |
540
541
 
541
542
  ```js
542
543
  import { createSessionStore, createMemoryBackend } from 'page-agent-sdk/storage'
543
544
  import { jpEval, searchJson } from 'page-agent-sdk/query'
544
545
  ```
545
546
 
546
- > 三个 subpath 当前指向同一份 dist + types(未拆多入口构建),语义清晰 + 便于 CDN 按入口拉取;未来切多入口构建时 import 路径零迁移。
547
+ > `storage` / `query` / `llm` 指向同一份 dist + types(语义清晰 + 便于 CDN 按入口拉取);未来切多入口构建时 import 路径零迁移。`headless` 是**独立打包的精简产物**(独立 dist + types)—— 见下。
547
548
 
548
549
  `sideEffects` 仅标记 `["**/*.css"]`,打包器可对 JS 做 tree-shaking。瘦身建议:
549
550
 
550
- - **headless(`ui:false`)**:不渲染内置对话框,自渲染 `agent.messages` —— 可不引 `ChatDialog`/`CodePreview`,并省略 CSS(`import 'page-agent-sdk'` 不引 `'page-agent-sdk/style.css'`)。
551
+ - **headless(`ui:false`)**:不渲染内置对话框,自渲染 `agent.messages`。要最精简 bundle,从 **headless 子路径** 引入 —— `import { createChatSdk } from 'page-agent-sdk/headless'`(ESM ~325KB vs 主包 ~789KB;去掉运行时从不使用的 marked/highlight.js/dompurify/ChatDialog)。`createChatSdk(options): ChatSdk` 签名不变,配 `ui:false` 用。从主包引入也可不引 `ChatDialog`/`CodePreview` 并省略 CSS(`import 'page-agent-sdk'` 不引 `'page-agent-sdk/style.css'`)。**持久化坑**:`sdk.stream` 不自动落盘(内置 useChat 经 onPersist 调 afterRound);自建对话框每轮后需手动 `sdk.afterRound()`,否则 `switchSession` 切回丢消息。**复用内置 DebugDrawer**(仅主包):`import { DebugDrawer }`(纯 props:`logs=sdk.debugLogs` / `getInfo=()=>sdk.inspect()` / `infoTick=sdk.infoTick`),在自己的 UI 里挂载,无需 ChatDialog
551
552
  - **关闭无用能力**:`capabilities:{ dataOps:false, fetch:false, planning:false, skills:false, vfs:false, summarization:false, memory:false, subagent:false }` —— 移除对应工具 schema 与中间件(省 token,非字节)。
552
553
  - **CDN 用 esm.sh**:`import { createChatSdk } from 'https://esm.sh/page-agent-sdk'` —— peer(`zod`、`@langchain/*`)由 esm.sh 自动解析去重,模块场景最小。
553
554
  - **IIFE 仅用于零配置**:全量单文件方便但最重,宿主支持模块时优先 ESM。