page-agent-sdk 2.22.1 → 2.24.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "page-agent-sdk",
3
- "version": "2.22.1",
3
+ "version": "2.24.0",
4
4
  "type": "module",
5
5
  "description": "AI agent SDK for web pages — embed a chat assistant that edits page data via schema-validated tools. A lighter, framework-agnostic alternative to CopilotKit/LangChain for in-page JSON-editing agents. Vue-bundled; works with DeepSeek, OpenAI, MCP.",
6
6
  "main": "./dist/page-agent-sdk.umd.cjs",
@@ -37,7 +37,7 @@ const app = { title: 'Demo', theme: 'light', items: [] } // plain object (or re
37
37
 
38
38
  createChatSdk({
39
39
  container: '#root',
40
- llm: { apiKey, baseUrl: 'https://api.deepseek.com/v1', model: 'deepseek-chat' },
40
+ llm: { apiKey, baseUrl: 'https://api.deepseek.com/v1', model: 'deepseek-v4-flash' },
41
41
  systemPrompt: 'You are a JSON operation assistant; read/write the main data via tools.',
42
42
  data: {
43
43
  schema: z.object({
@@ -317,4 +317,4 @@ sdk.removeSubagent('translator') // → boolean
317
317
  sdk.setSubagents([{ id: 'a', description: 'A' }, { id: 'b', description: 'B' }]) // replace all
318
318
  ```
319
319
 
320
- > **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.
320
+ > **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/archive/roadmap.md` #5.
@@ -231,7 +231,7 @@ createChatSdk({
231
231
  mode: 'proxy',
232
232
  baseUrl: '/api/llm', // your proxy (same-origin avoids CORS)
233
233
  userToken: getUserToken(), // session token (server validates)
234
- model: 'deepseek-chat',
234
+ model: 'deepseek-v4-flash',
235
235
  refreshToken?: async () => ..., // optional: refresh on 401
236
236
  headers?: { 'X-Tenant': 'acme' }, // optional: extra headers
237
237
  }),
@@ -244,7 +244,7 @@ createChatSdk({
244
244
  mode: 'direct',
245
245
  apiKey: 'sk-xxx',
246
246
  baseUrl: 'https://api.deepseek.com/v1',
247
- model: 'deepseek-chat',
247
+ model: 'deepseek-v4-flash',
248
248
  }),
249
249
  ...
250
250
  })
@@ -78,7 +78,7 @@ const sdk = createChatSdk({
78
78
  llm: {
79
79
  apiKey: import.meta.env.VITE_AI_API_KEY || 'YOUR_API_KEY',
80
80
  baseUrl: 'https://api.deepseek.com/v1', // OpenAI-compatible protocol; DeepSeek by default
81
- model: 'deepseek-chat',
81
+ model: 'deepseek-v4-flash',
82
82
  temperature: 0.3, // low temp recommended for large JSON ops
83
83
  },
84
84
  // [UI form: built-in dialog (default) / drawer mode (dialog.drawer:true) / headless (ui:false)]
@@ -18,7 +18,7 @@ Drop into any HTML page. The built-in dialog mounts itself. (`systemPrompt` is o
18
18
  const app = { title: 'Hello', theme: 'light' } // plain object (no window needed)
19
19
  ChatSdk.createChatSdk({
20
20
  container: '#root',
21
- llm: { apiKey: 'sk-...', baseUrl: 'https://api.deepseek.com/v1', model: 'deepseek-chat' },
21
+ llm: { apiKey: 'sk-...', baseUrl: 'https://api.deepseek.com/v1', model: 'deepseek-v4-flash' },
22
22
  systemPrompt: 'You are a JSON operation assistant. Read/write the main data via tools.',
23
23
  data: {
24
24
  schema: ChatSdk.z.object({
@@ -47,7 +47,7 @@ const app = { title: 'Hello', theme: 'light', items: [] }
47
47
 
48
48
  const sdk = createChatSdk({
49
49
  container: '#root',
50
- llm: { apiKey: import.meta.env.VITE_AI_API_KEY, baseUrl: 'https://api.deepseek.com/v1', model: 'deepseek-chat' },
50
+ llm: { apiKey: import.meta.env.VITE_AI_API_KEY, baseUrl: 'https://api.deepseek.com/v1', model: 'deepseek-v4-flash' },
51
51
  systemPrompt: 'You are a JSON operation assistant. Read/write the main data via tools.',
52
52
  data: {
53
53
  schema: z.object({
@@ -161,7 +161,7 @@ const sdk = createChatSdk({
161
161
  mode: 'proxy',
162
162
  baseUrl: '/api/llm', // your proxy (same-origin avoids CORS)
163
163
  userToken: getUserToken(), // session token (server validates, swaps in real key)
164
- model: 'deepseek-chat',
164
+ model: 'deepseek-v4-flash',
165
165
  refreshToken: async () => (await (await fetch('/api/refresh')).json()).token, // auto-refresh on 401
166
166
  headers: { 'X-Tenant': 'acme' }, // optional custom headers
167
167
  }),
@@ -173,7 +173,7 @@ const sdkDev = createChatSdk({
173
173
  container: '#root',
174
174
  llm: createProxyLlm({
175
175
  mode: 'direct',
176
- apiKey: 'sk-...', baseUrl: 'https://api.deepseek.com/v1', model: 'deepseek-chat',
176
+ apiKey: 'sk-...', baseUrl: 'https://api.deepseek.com/v1', model: 'deepseek-v4-flash',
177
177
  }),
178
178
  // ...data, systemPrompt...
179
179
  }).mount()
@@ -16,7 +16,7 @@ const page = {
16
16
 
17
17
  createChatSdk({
18
18
  container: '#chat',
19
- llm: { apiKey, baseUrl: 'https://api.deepseek.com/v1', model: 'deepseek-chat', temperature: 0.3 },
19
+ llm: { apiKey, baseUrl: 'https://api.deepseek.com/v1', model: 'deepseek-v4-flash', temperature: 0.3 },
20
20
  systemPrompt: '你是页面搭建助手。用 write 的 patch 按 jsonPath 增量改 components,不要重传整树。',
21
21
  data: {
22
22
  schema: z.object({
package/types/index.d.ts CHANGED
@@ -21,6 +21,8 @@ export interface ToolStep {
21
21
  args?: any;
22
22
  result?: string;
23
23
  status: 'running' | 'done' | 'error';
24
+ /** 工具执行耗时(毫秒,tool_result 时回填) */
25
+ durationMs?: number;
24
26
  /** 子 agent 工具步骤(spawn 委派时展示子进度) */
25
27
  children?: ToolStep[];
26
28
  }
@@ -152,6 +154,8 @@ export interface SubagentConfig {
152
154
  }
153
155
  export interface AgentInfo {
154
156
  id: string;
157
+ /** 当前会话 id(switchSession/onClear 后实时反映) */
158
+ sessionId: string;
155
159
  model?: string;
156
160
  /** 当前生效的 systemPrompt(默认或用户传入;仅 base 段,不含中间件 augmentPrompt,便于调试/验证默认提示词) */
157
161
  systemPrompt: string;
@@ -412,6 +416,8 @@ export interface SessionStore {
412
416
  listSessions(agentId: string): Promise<SessionMeta[]>;
413
417
  load(agentId: string, sessionId: string): Promise<SessionSnapshot | undefined>;
414
418
  save(agentId: string, sessionId: string, snap: Partial<SessionSnapshot>): Promise<void>;
419
+ /** 更新会话标题(自动从首条 user 消息生成,供历史列表显示) */
420
+ updateTitle(agentId: string, sessionId: string, title: string): Promise<void>;
415
421
  flush(): Promise<void>;
416
422
  deleteSession(agentId: string, sessionId: string): Promise<void>;
417
423
  createSession(agentId: string, title?: string, sessionId?: string): Promise<string>;
@@ -540,6 +546,10 @@ export interface ChatSdkOptions {
540
546
  contextPreset?: 'auto' | 'conservative' | 'aggressive' | 'complex';
541
547
  /** 摘要压缩专用 LLM(BaseChatModel 实例或 LLMConfig);不传则默认用主 agent 模型(llm) */
542
548
  summaryLlm?: any;
549
+ /** 标题生成 LLM(BaseChatModel 实例或 LLMConfig);不传则用 summaryLlm → 主 llm。首轮后自动生成会话标题(主旨) */
550
+ titleLlm?: any;
551
+ /** 自动生成会话标题(默认 true:首轮后调 LLM 生成主旨标题;false 关闭,用规则 deriveTitle 截取) */
552
+ autoTitle?: boolean;
543
553
  /** 摘要 LLM 温度(默认 0.3) */
544
554
  summaryTemperature?: number;
545
555
  /** 摘要 LLM 输出上限(默认 1024) */
@@ -602,6 +612,14 @@ export interface ChatSdk {
602
612
  show(): void;
603
613
  send(message: string, options?: { mission?: Partial<Mission> }): Promise<string>;
604
614
  switchSession(sessionId?: string): Promise<string>;
615
+ /** 列出当前 agent 的所有历史会话(供「历史列表」UI;storage 未开启 → []) */
616
+ listSessions(): Promise<SessionMeta[]>;
617
+ /** 历史会话列表(响应式;switchSession/deleteSession/onClear/init 后自动 refresh;直接消费无需手动 listSessions/refresh/hook) */
618
+ readonly sessions: import('vue').Ref<SessionMeta[]>;
619
+ /** 删除指定历史会话;不可删除当前会话(删当前请先 switchSession 切走);storage 未开启 → no-op + warn */
620
+ deleteSession(sessionId: string): Promise<void>;
621
+ /** 当前会话 id(switchSession/onClear 后实时反映;供历史列表高亮当前项) */
622
+ readonly sessionId: string;
605
623
  stream: (messages: AgentMessage[], onEvent: StreamHandler, signal?: AbortSignal) => Promise<string>;
606
624
  /** 检视 agent 详细信息(tools/skills/data/middleware/todos) */
607
625
  inspect(): AgentInfo;
@@ -818,6 +836,7 @@ export declare function recallRounds(older: any[], query: string, topK: number):
818
836
  // ============ LLM 解析(llmResolver,refactor-module-extraction 期二 从 createChatSdk 抽离)============
819
837
  export declare function isChatModel(v: unknown): boolean;
820
838
  export declare function resolveLlm(options: any): { modelCaps: any; summaryLlmInvoke: ((prompt: string) => Promise<string>) | undefined };
839
+ export declare function deriveTitle(msgs: AgentMessage[]): string | undefined;
821
840
  // ============ 乐观锁冲突管理器(conflictManager,refactor-module-extraction 期二 从 createChatSdk 抽离)============
822
841
  export interface ConflictManager {
823
842
  pendingConflict: import('vue').Ref<any | null>;
@@ -1038,3 +1057,9 @@ export interface ModelCaps { [k: string]: any }
1038
1057
 
1039
1058
  // 剪贴板复制(clipboard API + execCommand 降级,兼容非 secure context / 旧浏览器)
1040
1059
  export declare function copyText(text: string): Promise<boolean>;
1060
+ /**
1061
+ * 串行化运行器(P1-2,arch-review):把并发异步操作排成串行链,一个跑完下一个才开始。
1062
+ * createChatSdk 的 send/switchSession/batch 经此串行化,防并发共享 state 竞态。
1063
+ * 返回的 runSerial(fn):fn 排队执行(前一个无论成败都继续),返回 fn 的 Promise(透传结果/错误)。
1064
+ */
1065
+ export declare function createSerialRunner(): <T>(fn: () => Promise<T>) => Promise<T>;