import { type ComputedRef, type MaybeRefOrGetter, type Ref } from 'vue'; import { AGUIProtocol } from '@blueking/chat-helper'; import type { IChatHelper, IRequestOptions } from '../types'; import type { IAgentInfo, ISession } from '@blueking/chat-helper'; /** * Bootstrap 阶段枚举 */ export declare enum BootstrapPhase { /** 初始化失败 */ ERROR = "error", /** 未开始 */ IDLE = "idle", /** 正在获取 Agent 信息 */ LOADING_AGENT = "loading_agent", /** 初始化完成(Agent 信息已获取,会话初始化由 SessionBusinessManager 负责) */ READY = "ready" } /** * useChatBootstrap 配置选项 */ export interface ChatBootstrapOptions { /** 是否自动初始化(默认 true) */ autoInit?: boolean; /** 请求配置(支持 ref/computed,替换后后续请求自动生效) */ requestOptions?: MaybeRefOrGetter; /** API 服务地址(支持响应式) */ url: MaybeRefOrGetter; /** Protocol 事件回调 */ protocolCallbacks?: { onDone?: () => void; onError?: (error: unknown) => void; onMessage?: (event: unknown) => void; onStart?: () => void; }; } /** * useChatBootstrap 返回值 */ export interface ChatBootstrapReturn { /** Agent 信息 */ agentInfo: ComputedRef; /** Agent 名称 */ agentName: ComputedRef; /** ChatHelper 实例(生命周期内不变) */ chatHelper: IChatHelper; /** 当前会话 */ currentSession: ComputedRef; /** 初始化错误 */ error: Ref; /** 是否正在初始化 */ isInitializing: ComputedRef; /** 是否已初始化完成 */ isReady: ComputedRef; /** 当前初始化阶段 */ phase: Ref; /** Protocol 实例 */ protocol: AGUIProtocol; /** 会话列表 */ sessionList: ComputedRef; /** 获取扩展方法 */ getExtension: any>(key: string) => T | undefined; /** 初始化(获取 Agent 信息 + 加载最近会话) */ initialize: () => Promise; /** * 扩展方法注册器 * 用于未来添加更多组合式业务逻辑 * @example * const { registerExtension } = useChatBootstrap({ url: '...' }); * registerExtension('createNewSession', async () => { ... }); */ registerExtension: any>(key: string, fn: T) => void; /** 重试初始化 */ retry: () => Promise; /** * 更新配置并重新初始化 * @param newUrl 新的 URL */ updateConfig: (newUrl: string) => Promise; } /** * 聊天初始化 Composable * * 职责单一:只负责创建 ChatHelper 和获取 Agent 信息 * 会话管理由 SessionBusinessManager 统一负责 * * 初始化流程: * 1. 创建 ChatHelper 实例(同步,生命周期内不变) * 2. 获取 Agent 信息 (getAgentInfo) * * 注意:会话初始化应在 isReady 后通过 SessionBusinessManager.loadRecentSession() 执行 * * @example * ```ts * // 基础用法 * const { chatHelper, isReady, agentInfo } = useChatBootstrap({ * url: '/api/chat', * autoInit: true, * }); * * // 会话初始化由 SessionBusinessManager 负责 * watch(isReady, (ready) => { * if (ready) { * sessionBusinessManager.loadRecentSession(); * } * }); * ``` */ export declare function useChatBootstrap(options: ChatBootstrapOptions): ChatBootstrapReturn; //# sourceMappingURL=use-chat-bootstrap.d.ts.map