import { Context, Session } from "koishi"; import type { GenerateTextResult } from "xsai"; import { Scenario } from "../services/scenario/Scenario"; /** * 会话状态枚举 * 简化为三个核心状态 */ export declare enum ConversationState { IDLE = 0,// 空闲状态,等待新消息触发 PROCESSING = 1,// 处理中状态 RESPONDING = 2 } /** * 消息上下文 * 在中间件链中传递的上下文对象 */ export declare class MessageContext { koishiContext: Context; koishiSession: Session; allowedChannels: string[]; state: ConversationState; llmResponse?: GenerateTextResult; processedResponse?: string[]; isMentioned: boolean; heartbeatCount: number; currentScenario: Scenario; constructor(koishiContext: Context, koishiSession: Session, allowedChannels: string[]); /** * 转换会话状态 */ transitionTo(newState: ConversationState): Promise; } /** * 中间件接口 */ export declare abstract class Middleware { readonly name: string; protected readonly ctx: Context; protected readonly services: any; protected readonly config: any; constructor(name: string, ctx: Context, services?: any, config?: any); abstract execute(ctx: MessageContext, next: () => Promise): Promise; } /** * 中间件管理器 * 负责注册和执行中间件链 */ export declare class MiddlewareManager { middlewares: Middleware[]; /** * 注册中间件 */ use(middleware: Middleware): this; /** * 执行中间件链 */ execute(ctx: MessageContext): Promise; /** * 从指定位置开始执行中间件链 */ executeFrom(ctx: MessageContext, startIndex: number): Promise; /** * 获取指定名称的中间件 */ getMiddleware(name: string): T | undefined; findIndex(name: string): number; }