//! TypeScript 类型定义 — 与 Rust Record 结构体严格对齐 // ============================================================ // 灵感 // ============================================================ export interface IdeaRecord { id: string title: string description: string status: string // draft | pending_review | approved | rejected | promoted | archived priority: number score: number | null tags: string | null // JSON 数组字符串 source: string | null promoted_to: string | null ai_analysis: string | null scores: string | null created_at: string updated_at: string } export interface CreateIdeaInput { title: string description?: string priority?: number tags?: string source?: string } // ============================================================ // 项目 // ============================================================ export interface ProjectRecord { id: string name: string description: string status: string // planning | in_progress | testing | releasing | completed | paused idea_id: string | null /** 绑定的本地代码目录绝对路径(null=未绑定) */ path: string | null /** 技术栈 JSON 数组字符串(如 ["rust","vue"],null=未探测) */ stack: string | null created_at: string updated_at: string } export interface CreateProjectInput { name: string description?: string idea_id?: string /** 绑定的本地代码目录(可选) */ path?: string /** 技术栈 JSON 数组字符串(可选,空则后端自动探测) */ stack?: string } /** AI 扫描项目结果(预览用,用户确认后填入) */ export interface AiScanResult { /** 项目摘要(空=LLM 未得出,需手填) */ description: string /** 技术栈(规则 ∪ LLM,去重小写) */ stack: string[] /** 项目类型(web/api/cli/library/desktop/mobile/monorepo/other) */ project_type: string | null /** LLM 原始返回(降级时含错误信息) */ raw: string | null } /** 灵感晋升结果(后端 promote_idea 返回) */ export interface PromotionResult { idea_id: string project_id: string promoted: boolean reason: string } // ============================================================ // 任务 // ============================================================ export interface TaskRecord { id: string project_id: string title: string description: string status: string // todo | in_progress | in_review | testing | done | blocked | cancelled priority: number // 0=critical, 1=high, 2=medium, 3=low branch_name: string | null assignee: string | null workflow_def_id: string | null base_branch: string | null /** review 退回累计轮数(in_review→in_progress / testing→in_review 各 +1) */ review_rounds: number created_at: string updated_at: string } export interface CreateTaskInput { project_id: string title: string description?: string priority?: number branch_name?: string assignee?: string } // ============================================================ // 工作流 // ============================================================ export interface WorkflowRecord { id: string name: string dag_json: string status: string // running | completed | failed | cancelled triggered_by: string | null project_id: string | null task_id: string | null created_at: string completed_at: string | null } /** 工作流事件载荷(后端 emit 的结构) */ /** 工作流事件类型字面量联合(对应后端 WorkflowEvent serde tag=type rename_all=snake_case,R7收窄防写错 type 字符串) */ export type WorkflowEventType = | 'node_started' | 'node_progress' | 'node_output' | 'node_completed' | 'node_failed' | 'node_cancelled' | 'workflow_paused' | 'workflow_completed' | 'workflow_failed' | 'human_approval_request' | 'human_approval_response' export interface WorkflowEventPayload { execution_id: string event: { type: WorkflowEventType [key: string]: unknown } } // ============================================================ // 通用 // ============================================================ export type UpdateField = { id: string field: string value: string } // ============================================================ // 数据变更联动刷新(AR-11 方案A) // ============================================================ /** * 后端 AI 工具(create/update/delete/restore/purge/bind_directory 等)执行成功后 * emit 的 "df-data-changed" 事件负载。前端 store listen 后按 entity 调对应 load 刷新列表。 */ export interface DfDataChangedPayload { /** 变更实体:project / task / idea */ entity: 'project' | 'task' | 'idea' /** 变更动作:create / update / delete */ action: 'create' | 'update' | 'delete' } // ============================================================ // AI 聊天 // ============================================================ export interface AiProviderConfig { id: string name: string provider_type: string api_key: string base_url: string default_model: string models: string | null is_default: boolean config: string | null created_at: string updated_at: string } /** * AI 错误分类字面量集(B-260615-42)。 * 与后端 `commands::ai::ErrorType` 的 serde(rename_all = "snake_case") 严格对齐。 * 前端消费方 switch 于此常量集做差异化提示(auth 引导填 key / network 提示连接 / 等)。 */ export type AiErrorType = 'auth' | 'network' | 'timeout' | 'provider_config' | 'unknown' /** AI 聊天事件(后端 emit 的结构,conversation_id 用于多对话流式路由) */ export type AiChatEvent = ({ type: 'AiTextDelta'; delta: string } | { type: 'AiToolCallStarted'; id: string; name: string; args: unknown } | { type: 'AiToolCallCompleted'; id: string; result: unknown } | { type: 'AiApprovalRequired'; id: string; name: string; args: unknown; reason: string } | { type: 'AiApprovalResult'; id: string; approved: boolean } | { // UX-2025-04 / CR-30-2 / 决策 F-260616-07 a1: incomplete 标记流中途失败保文(网络中断), // 前端据此差异化展示(如系统提示「⚠ 响应因网络中断不完整」)。正常完成/停止均为 undefined。 type: 'AiCompleted'; total_tokens: number; prompt_tokens: number; completion_tokens: number; incomplete?: boolean } | { type: 'AiError'; error: string; error_type?: AiErrorType } | { type: 'AiAgentRound'; round: number } | { type: 'AiHeartbeat' } | { // F-260616-03: 达 max_iterations 暂停态(后端仍 generating=true),前端展示操作卡询问继续/停止 type: 'AiMaxRoundsReached' } | { // F-260616-07: 流式调用自动重试提示(前端可在错误气泡内显示「重试 n/m」) type: 'AiStreamRetry'; attempt: number; max_attempts: number }) & { conversation_id?: string } /** AI 消息(前端渲染用,isError 标记错误消息用于差异化样式) */ export interface AiMessage { id: string role: 'user' | 'assistant' | 'tool' content: string isError?: boolean toolCalls?: AiToolCallInfo[] /** 生成该消息的 model(仅 assistant 消息,历史消息从 DB 读) */ model?: string timestamp: number } /** 工具调用信息 */ export interface AiToolCallInfo { id: string name: string args: unknown status: 'running' | 'pending_approval' | 'completed' | 'rejected' result?: unknown /** 审批风险说明(AiApprovalRequired 时填充) */ reason?: string } /** 对话列表摘要 */ export interface AiConversationSummary { id: string title: string | null provider_id: string | null model: string | null archived: boolean pinned?: boolean prompt_tokens?: number | null completion_tokens?: number | null created_at: string updated_at: string } /** 审批选择类型(F-260615-01: single=单选默认,multiple=多选) */ export type ApprovalSelectType = 'single' | 'multiple' /** 人工审批请求 */ export interface HumanApprovalRequest { execution_id: string node_id: string title: string description: string options: string[] /** F-260615-01: 缺省 single(向后兼容),multiple 时允许多选 */ select_type?: ApprovalSelectType } /** 人工审批响应 */ export interface HumanApprovalResponse { execution_id: string node_id: string decision: string /** F-260615-01: 多选结果(single 时长度=1,multiple 时长度≥1) */ decisions?: string[] comment?: string } /** 切换对话返回(含 messages JSON) */ export interface AiConversationDetail { id: string title: string | null messages: string // JSON string of ChatMessage[] /** 生成中返回 true(后端 ai_conversation_switch 在 generating 时置),前端据此禁编辑(FR-C5) */ readonly?: boolean } /** 技能信息(本机 Claude skill,供 `/` 联想 + 注入) */ export interface SkillInfo { name: string description: string argument_hint?: string /** skill | command | plugin */ source: string /** SKILL.md 绝对路径(后端注入时读全文) */ path: string } // ============================================================ // 知识库 // ============================================================ /** 知识条目(与 Rust KnowledgeRecord 严格对齐) */ export interface KnowledgeRecord { id: string kind: string // review_rule | prompt_template | pitfall | architecture_pattern | diagnosis | deployment_note | workflow_optimization title: string content: string tags: string | null // JSON 数组字符串 status: string // candidate | pending_review | published | archived confidence: string | null // high | medium | low reuse_count: number verified: boolean source_project: string | null source_ref: string | null /** AI 提炼判断依据("为何值得沉淀"),手动录入为 null */ reasoning: string | null created_at: string updated_at: string } /** 创建知识入参 */ export interface CreateKnowledgeInput { kind: string title: string content: string tags?: string source_project?: string source_ref?: string confidence?: string } /** 检索知识入参 */ export interface KnowledgeSearchInput { query: string kind?: string limit?: number } /** 知识生命线事件记录(产生/审核/引用/归档审计) */ export interface KnowledgeEventRecord { id: string knowledge_id: string /** created | extracted | status_changed | referenced */ event_type: string source_ref: string | null /** JSON 字符串,内容因 event_type 而异(见后端 KnowledgeTimeline) */ context_json: string | null timestamp: string } /** 知识详情聚合负载(基本信息 + 全部生命线事件) */ export interface KnowledgeDetailPayload { knowledge: KnowledgeRecord events: KnowledgeEventRecord[] } /** 编辑知识入参(部分更新,仅传需改字段) */ export interface UpdateKnowledgeInput { title?: string content?: string tags?: string confidence?: string reasoning?: string } /** 知识库行为配置(提取 + 注入 + 向量检索) */ export interface KnowledgeConfig { auto_extract: boolean trigger_mode: 'on_complete' | 'on_idle' | 'manual_only' min_messages: number idle_timeout_ms: number auto_inject: boolean /** 语义检索(向量)开关,默认 false——关闭时纯 LIKE 零外部依赖 */ vector_enabled: boolean /** embedding 用的 provider id(仅 openai_compat 类型) */ embedding_provider_id: string | null /** embedding 模型名(如 embedding-3) */ embedding_model: string | null }