page-agent-sdk 2.25.0 → 2.26.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.25.0",
3
+ "version": "2.26.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",
package/types/index.d.ts CHANGED
@@ -328,7 +328,20 @@ export interface SkillSpec {
328
328
  /** 文档源(http(s):// 远程 md,或 vfs://path / 裸路径;SDK 代劳 fetch+vfs);与 getContent 二选一,doc 优先 */
329
329
  doc?: string;
330
330
  getContent?: () => string | Promise<string>;
331
+ /** 加载时执行脚本,结果注入全文(skill-external-scripts);code/url 二选一,默认 sandbox,失败不缓存 */
332
+ exec?: SkillExecSpec;
333
+ /** 附带可调工具工厂;load_skill 后注入工具池(命名空间 <skill>__<tool>,走 dedupeTools);与 exec 正交 */
334
+ tools?: SkillToolFactory[];
331
335
  }
336
+ /** skill 执行钩子:code(内联 JS)/url(远程,仅 sandbox)二选一;context 默认 sandbox,host 需 skillHostScript */
337
+ export interface SkillExecSpec {
338
+ code?: string;
339
+ url?: string;
340
+ context?: 'sandbox' | 'host';
341
+ inject?: 'append' | 'prepend';
342
+ }
343
+ /** skill 附带工具工厂(返回单个/数组工具,可异步;ctx.signal 运行时中止信号) */
344
+ export type SkillToolFactory = () => any | any[] | Promise<any | any[]>;
332
345
 
333
346
  // ===== Verify 自检中间件 =====
334
347
  /** verify check 上下文:与 beforeReturn 底层一致(messages 含 system 头 + agent 最新回复 + 历史 tool_result) */
@@ -570,7 +583,7 @@ export interface ChatSdkOptions {
570
583
  /** 模型最大输出(token);顶层声明对 llm 实例场景也生效,缺省按 model 名查表 */
571
584
  maxOutputTokens?: number;
572
585
  /** 子 agent 委派(默认开启;{ enabled: false } 关闭) */
573
- capabilities?: { dataOps?: boolean; fetch?: boolean; planning?: boolean; missionAnchor?: boolean; skills?: boolean; vfs?: boolean; summarization?: boolean; memory?: boolean; subagent?: boolean; verify?: boolean; domInspect?: boolean; inspectEnv?: boolean; draftWrite?: boolean; tracing?: boolean; todoDeps?: boolean; automation?: boolean; workingMemory?: boolean };
586
+ capabilities?: { dataOps?: boolean; fetch?: boolean; planning?: boolean; missionAnchor?: boolean; skills?: boolean; vfs?: boolean; summarization?: boolean; memory?: boolean; subagent?: boolean; verify?: boolean; domInspect?: boolean; inspectEnv?: boolean; draftWrite?: boolean; tracing?: boolean; todoDeps?: boolean; automation?: boolean; workingMemory?: boolean; skillHostScript?: boolean; contextInspector?: boolean };
574
587
  subagent?: { enabled?: boolean; allowedTools?: string[]; systemPrompt?: string; temperature?: number; maxTokens?: number; skills?: SkillSpec[]; llm?: LLMConfig | ChatModelLike; maxDepth?: number; maxParallel?: number };
575
588
  /** 预声明子 agent 列表:每个用同主配置方式声明,自动生成 use_<id> 委派工具(与 spawn_agent 共存) */
576
589
  subagents?: SubagentConfig[];
@@ -999,6 +1012,21 @@ export declare function searchJson(
999
1012
  ): SearchHit[];
1000
1013
  /** Web Worker 沙箱执行自定义 JS(无 window/document,禁 fetch/XHR/WebSocket/importScripts,超时可终止) */
1001
1014
  export declare function runSandboxedScript(data: unknown, script: string, timeoutMs?: number): Promise<EvalResult>;
1015
+ /** 通用 Worker 沙箱结果(eval_script 与 skill exec 共用;EvalResult 的别名同构) */
1016
+ export interface SandboxResult {
1017
+ ok: boolean;
1018
+ result?: unknown;
1019
+ error?: string;
1020
+ elapsedMs: number;
1021
+ }
1022
+ /**
1023
+ * 创建沙箱执行器(柯里化:先绑 script+timeoutMs,再传可选 input)。三层防护:静态扫描禁用模式 +
1024
+ * lockSandboxGlobal defineProperty 锁网络/存储 API(防 delete self.fetch 逃逸)+ 超时 terminate。
1025
+ * 无 input 传 undefined(skill exec);有 input 作 data 入参(eval_script)。
1026
+ */
1027
+ export declare function createSandboxRunner(script: string, timeoutMs?: number): (input?: unknown) => Promise<SandboxResult>;
1028
+ /** 宿主脚本执行(skill exec context:'host';AsyncFunction 主线程全权,不经静态扫描,需 capabilities.skillHostScript:true) */
1029
+ export declare function runHostScript(code: string, timeoutMs?: number): Promise<SandboxResult>;
1002
1030
 
1003
1031
  // ============ 工具报错(结构化 ERROR:{json},供 LLM 排查)============
1004
1032
  export interface ToolErrorInput {