page-agent-sdk 3.10.2 → 3.11.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": "3.10.2",
3
+ "version": "3.11.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",
@@ -275,6 +275,8 @@ export interface AgentInfo {
275
275
  data?: DataInfo;
276
276
  /** 当前上下文压缩预设(默认 auto;complex 为多步复杂任务/大 JSON 场景) */
277
277
  contextPreset: 'auto' | 'conservative' | 'aggressive' | 'complex';
278
+ /** 压缩触发配置反射:contextWindow / summaryThresholdRatio / promptSoftCap(softCap 解析结果,Infinity=不参与) */
279
+ compression: { contextWindow: number; summaryThresholdRatio: number; promptSoftCap: number };
278
280
  memory: string;
279
281
  middleware: string[];
280
282
  todos: { id: string; content: string; status: string }[];
@@ -767,6 +769,8 @@ export interface ChatSdkOptions {
767
769
  streamStallMs?: number;
768
770
  /** token 预算上限(累计 total_tokens 超过 → 停止 agent + emit BUDGET_EXCEEDED;需 capabilities.automation:true) */
769
771
  tokenBudget?: number;
772
+ /** 单次 invoke 的 token 预算上限(opt-in,默认关):本次 agent 调用累计 total_tokens 超限 → 中断收口(observable emit + 友好文本,已完成部分保留);与 automation 全局 tokenBudget 正交 */
773
+ roundTokenBudget?: number;
770
774
  /** 时间预算 ms(从 agent 开始计时,超过 → 停止;需 capabilities.automation:true) */
771
775
  timeBudgetMs?: number;
772
776
  /** 无人值守错误恢复:致命错误(invoke 抛错)自动 restore_last_checkpoint + 重试次数(默认 1;防单点错误永久中断批量/长任务)。需 capabilities.automation:true */
@@ -792,7 +796,7 @@ export interface ChatSdkOptions {
792
796
  checkpoint?: boolean | { maxCheckpoints?: number; auto?: boolean };
793
797
  /** MCP server 列表(连远程 server 动态注入其 tools;浏览器仅 http/sse/websocket) */
794
798
  mcp?: McpServerConfig[];
795
- /** 上下文压缩配置(false 关闭;默认 LLM 摘要,失败回退索引摘要) */
799
+ /** 上下文压缩配置(false 关闭;默认 LLM 摘要,失败回退索引摘要)。含 promptSoftCapTokens(prompt 软上限:窗口 ≥320K 模型默认 160K,历史 token 超 min(window×ratio, softCap) 即提前压缩;传 0 显式关) */
796
800
  contextOptions?: any;
797
801
  /** 上下文压缩预设档位(默认 'auto'):auto / conservative / aggressive / complex(多步复杂任务/大 JSON);提供合理默认,contextOptions 细参可覆盖 */
798
802
  contextPreset?: 'auto' | 'conservative' | 'aggressive' | 'complex';
@@ -1145,7 +1149,13 @@ export declare function estimateMessageTokens(m: any): number;
1145
1149
  export declare function estimateRoundTokens(r: any): number;
1146
1150
  export declare function indexSummarize(older: any[], preserve?: Set<string>): string;
1147
1151
  export declare function recallRounds(older: any[], query: string, topK: number): any[];
1148
- export declare function shouldTriggerCompression(rounds: any[], config: { contextWindow?: number; summaryThresholdRatio?: number; summaryThresholdRounds?: number }): boolean;
1152
+ export declare function shouldTriggerCompression(rounds: any[], config: { contextWindow?: number; summaryThresholdRatio?: number; summaryThresholdRounds?: number; promptSoftCapTokens?: number }): boolean;
1153
+ /** 解析有效 prompt 软上限:显式 >0 用该值 / 显式 0 关(Infinity) / 未传且窗口 ≥320K 默认 160K / 其余不参与 */
1154
+ export declare function resolvePromptSoftCap(contextWindow?: number, promptSoftCapTokens?: number): number;
1155
+ /** softCap 默认参与门槛(窗口 ≥320K) */
1156
+ export declare const SOFT_CAP_MIN_WINDOW: number;
1157
+ /** 默认 prompt 软上限(160K) */
1158
+ export declare const DEFAULT_PROMPT_SOFT_CAP: number;
1149
1159
  // ============ LLM 解析(llmResolver,refactor-module-extraction 期二 从 createChatSdk 抽离)============
1150
1160
  export declare function isChatModel(v: unknown): boolean;
1151
1161
  export declare function resolveLlm(options: any): { modelCaps: any; summaryLlmInvoke: ((prompt: string) => Promise<string>) | undefined };
package/types/index.d.ts CHANGED
@@ -17,6 +17,8 @@ export interface ProxyLlmOptions {
17
17
  export declare function createProxyLlm(opts: ProxyLlmOptions): import('@langchain/core/language_models/chat_models').BaseChatModel;
18
18
  /** 检测 garbled 工具调用文本(DeepSeek DSML/伪 XML 泄漏到正文) */
19
19
  export declare function detectGarbledToolCall(content: string): boolean;
20
+ /** 剥离 garbled 工具调用文本,只保留首个强守卫标记出现前的正常 prose(wrap-up/重试耗尽路径防 DSML 原文当结论返回) */
21
+ export declare function sanitizeGarbledContent(content: string): string;
20
22
  /** 检测过程性收口(短文本 + 过渡模式如「我先看看…稍后委派」+ 无完成动词)—— createAgent 据此有界回灌(≤2) */
21
23
  export declare function detectTransitionalReply(content: string): boolean;
22
24
  export interface ConstructOpts {
@@ -279,6 +281,8 @@ export interface AgentInfo {
279
281
  data?: DataInfo;
280
282
  /** 当前上下文压缩预设(默认 auto;complex 为多步复杂任务/大 JSON 场景) */
281
283
  contextPreset: 'auto' | 'conservative' | 'aggressive' | 'complex';
284
+ /** 压缩触发配置反射:contextWindow / summaryThresholdRatio / promptSoftCap(softCap 解析结果,Infinity=不参与) */
285
+ compression: { contextWindow: number; summaryThresholdRatio: number; promptSoftCap: number };
282
286
  memory: string;
283
287
  middleware: string[];
284
288
  todos: { id: string; content: string; status: string }[];
@@ -791,6 +795,8 @@ export interface ChatSdkOptions {
791
795
  streamStallMs?: number;
792
796
  /** token 预算上限(累计 total_tokens 超过 → 停止 agent + emit BUDGET_EXCEEDED;需 capabilities.automation:true) */
793
797
  tokenBudget?: number;
798
+ /** 单次 invoke 的 token 预算上限(opt-in,默认关):本次 agent 调用累计 total_tokens 超限 → 中断收口(observable emit + 友好文本,已完成部分保留);与 automation 全局 tokenBudget 正交 */
799
+ roundTokenBudget?: number;
794
800
  /** 时间预算 ms(从 agent 开始计时,超过 → 停止;需 capabilities.automation:true) */
795
801
  timeBudgetMs?: number;
796
802
  /** 无人值守错误恢复:致命错误(invoke 抛错)自动 restore_last_checkpoint + 重试次数(默认 1;防单点错误永久中断批量/长任务)。需 capabilities.automation:true */
@@ -816,7 +822,7 @@ export interface ChatSdkOptions {
816
822
  checkpoint?: boolean | { maxCheckpoints?: number; auto?: boolean };
817
823
  /** MCP server 列表(连远程 server 动态注入其 tools;浏览器仅 http/sse/websocket) */
818
824
  mcp?: McpServerConfig[];
819
- /** 上下文压缩配置(false 关闭;默认 LLM 摘要,失败回退索引摘要) */
825
+ /** 上下文压缩配置(false 关闭;默认 LLM 摘要,失败回退索引摘要)。含 promptSoftCapTokens(prompt 软上限:窗口 ≥320K 模型默认 160K,历史 token 超 min(window×ratio, softCap) 即提前压缩;传 0 显式关) */
820
826
  contextOptions?: any;
821
827
  /** 上下文压缩预设档位(默认 'auto'):auto / conservative / aggressive / complex(多步复杂任务/大 JSON);提供合理默认,contextOptions 细参可覆盖 */
822
828
  contextPreset?: 'auto' | 'conservative' | 'aggressive' | 'complex';
@@ -1171,7 +1177,13 @@ export declare function estimateMessageTokens(m: any): number;
1171
1177
  export declare function estimateRoundTokens(r: any): number;
1172
1178
  export declare function indexSummarize(older: any[], preserve?: Set<string>): string;
1173
1179
  export declare function recallRounds(older: any[], query: string, topK: number): any[];
1174
- export declare function shouldTriggerCompression(rounds: any[], config: { contextWindow?: number; summaryThresholdRatio?: number; summaryThresholdRounds?: number }): boolean;
1180
+ export declare function shouldTriggerCompression(rounds: any[], config: { contextWindow?: number; summaryThresholdRatio?: number; summaryThresholdRounds?: number; promptSoftCapTokens?: number }): boolean;
1181
+ /** 解析有效 prompt 软上限:显式 >0 用该值 / 显式 0 关(Infinity) / 未传且窗口 ≥320K 默认 160K / 其余不参与 */
1182
+ export declare function resolvePromptSoftCap(contextWindow?: number, promptSoftCapTokens?: number): number;
1183
+ /** softCap 默认参与门槛(窗口 ≥320K) */
1184
+ export declare const SOFT_CAP_MIN_WINDOW: number;
1185
+ /** 默认 prompt 软上限(160K) */
1186
+ export declare const DEFAULT_PROMPT_SOFT_CAP: number;
1175
1187
  // ============ LLM 解析(llmResolver,refactor-module-extraction 期二 从 createChatSdk 抽离)============
1176
1188
  export declare function isChatModel(v: unknown): boolean;
1177
1189
  export declare function resolveLlm(options: any): { modelCaps: any; summaryLlmInvoke: ((prompt: string) => Promise<string>) | undefined };