import type { ManagedToolInterceptor } from '../managed-interceptor'; import type { ToolContext } from '../tool'; /** * 上下文注入拦截器配置。 * * 用于注入不需要工具元信息的扩展字段到 `toolContext`。 * 外部可通过 TypeScript declaration merging 扩展 `ToolContext` 接口, * 然后在此处传入对应字段的实现。 * * @example 注入自定义分析器 * ```typescript * // 1. 扩展 ToolContext 类型 * declare module '@agforge/engine' { * interface ToolContext { * analytics: AnalyticsTracker; * } * } * * // 2. 注入实现 * const agent = new DefaultAgent({ * toolContextInject: { * analytics: new AnalyticsTracker(), * }, * }); * ``` * * ## 与 Agent 层拦截器的分工 * * - **`createBuiltinToolContextInterceptor`(Agent 层)**:负责注入需要工具元信息的能力 * (如 `permissionManager`、`executionLocker`) * - **本拦截器(Tool 层)**:负责注入不需要工具元信息的扩展字段 */ export interface ContextInjectOptions extends Omit, Record { } /** * 创建上下文注入 Tool 拦截器。 * * 在工具执行前将扩展字段合并到 `toolContext` 中, * 使工具可通过 `context.xxx` 访问这些能力。 * * Phase 为 `SYSTEM`,在所有用户 Tool 拦截器之前执行(洋葱模型最外层), * 使用户自定义 Tool 拦截器可在已注入上下文的基础上进行操作。 * * @param injectedContext 要注入的上下文字段 * @returns Tool 拦截器 */ export declare const createContextInjectInterceptor: (injectedContext: ContextInjectOptions) => ManagedToolInterceptor;