import { Context, Schema, Session } from "koishi"; export interface Param { type: string; description?: string; default?: any; required?: boolean; properties?: Properties; enum?: any[]; items?: Param; } export type Properties = Record; export interface ToolSchema { name: string; description: string; parameters: Properties; } /** * 扩展包元数据接口,用于描述一个扩展包的基本信息。 */ export interface ExtensionMetadata { display?: string; name: string; description: string; author?: string; version: string; builtin?: boolean; } /** * 工具元数据接口,用于描述一个可供 LLM 调用的工具。 */ export interface ToolMetadata { name?: string; description: string; parameters: Schema; isSupported?: (session: Session) => boolean; } /** * 完整的工具定义,包含了元数据和可执行函数。 */ export interface ToolDefinition { name: string; description: string; parameters: Schema; isSupported?: (session: Session) => boolean; execute: (args: Infer) => Promise; } /** * 标准化的工具错误接口 */ export interface ToolError { /** 错误的类型或名称 (例如: 'ValidationError', 'APIFailure', 'RuntimeError') */ name: string; /** 人类可读的错误信息 */ message: string; /** 错误是否可重试 */ retryable?: boolean; } /** * 标准化的工具调用结果 */ export interface ToolCallResult { /** * 调用状态: * - 'success': 成功 * - 'error': 失败 */ status: "success" | "error"; /** 成功时的返回结果 */ result?: TResult; /** 失败时的结构化错误信息 */ error?: TError; /** 附加元数据,如执行时间(ms)、Token消耗等 */ metadata?: { execution_duration_ms?: number; [key: string]: any; }; } /** * 扩展包实例需要实现的接口。 */ export interface IExtension extends Object { ctx: Context; config: TConfig; metadata: ExtensionMetadata; tools: Map; } export type Infer = T & { session?: Session; };