UNPKG

autosnippet

Version:

Extract code patterns into a knowledge base for AI coding assistants

77 lines (76 loc) 3.18 kB
/** * IntentClassifier — 自然语言意图分类器 * * 核心问题: 用户通过飞书发了一句自然语言,应该交给谁处理? * * ┌──────────────────────────────────────────────────────────┐ * │ "帮我搜索一下项目里关于用户认证的知识" │ * │ → bot_agent (知识管理任务,服务端 AgentRuntime 处理) │ * │ │ * │ "把 src/auth.ts 里的 JWT 验证改成 OAuth2" │ * │ → ide_agent (编程任务,转发到 VSCode Copilot) │ * │ │ * │ "现在服务状态怎么样" │ * │ → system (系统状态查询,本地直接处理) │ * └──────────────────────────────────────────────────────────┘ * * 三层分类策略 (延迟递增): * 1. 规则匹配 — 零延迟关键词/模式 (~0ms) * 2. 嵌入相似度 — 轻量向量匹配 (~50ms) [可选] * 3. LLM 分类 — 精确但需 AI 调用 (~500ms) * * 设计原则: * - 宁可多走 LLM 也不要误分类 — 用户体验优先 * - bot_agent 是默认,除非明确检测到编程意图 * - 系统查询是硬编码模式,不走 AI * * @module IntentClassifier */ /** 意图类型 */ export declare const Intent: Readonly<{ /** 知识管理任务 — 搜索/创建/分析知识,由服务端 AgentRuntime 处理 */ BOT_AGENT: "bot_agent"; /** IDE 编程任务 — 代码编写/修改/调试/重构,转发到 VSCode Copilot */ IDE_AGENT: "ide_agent"; /** 系统操作 — 状态查询/截图/连接管理,本地直接处理 */ SYSTEM: "system"; }>; export declare class IntentClassifier { #private; /** * 从用户消息中提取核心指令,去除 meta 包装 * * "在编辑器内输入新增按钮""新增按钮" * "让 Copilot 帮我重构 auth""重构 auth" * "修复 bug""修复 bug" (无包装,原样返回) */ static extractCommand(text: string): string; constructor({ aiProvider }?: { aiProvider?: null | undefined; }); /** * 分类用户消息意图 * * @param text 用户原始消息文本 * @param [context] 额外上下文 (如对话历史、最近操作) */ classify(text: string, context?: Record<string, unknown>): Promise<{ intent: "system"; confidence: number; reasoning: string; method: string; action: string; } | { intent: "bot_agent" | "ide_agent"; confidence: number; reasoning: string; method: string; } | { intent: string; confidence: number; reasoning: string; method: string; extractedCommand: string | undefined; }>; } export default IntentClassifier;