Files
DevFlow/src/api/types.ts
绝尘 cf017f81e2 新增: Phase2 阶段收尾(Sprint 1-20)
重构:删 5 零引用 crate(df-evolve/plugin/stages/task/traceability)+ 清死模块、ai.rs 拆 11 子 module、ai.ts 拆 6 composable、i18n 拆目录
功能:知识库全栈(df-project/scan + CRUD + 时间线 + 前端)、Settings 拆分、appSettings KV 迁移、模型池、LLM 并发 Semaphore
修复:审批持久化根治、ConditionEngine 默认拒绝、NodeRegistry unimplemented 清除、promote 补偿删除、工具结果截断 50KB、路径校验防 symlink 逃逸
文档:B-03 人工审批设计、决策记录三分档、规格契约自检、经验记录、todo 看板、PROGRESS 更新

详见 PROGRESS.md。src-tauri/儿童每日打卡应用/ 与本项目无关,已排除。
2026-06-14 14:08:20 +08:00

335 lines
8.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! TypeScript 类型定义 — 与 Rust Record 结构体严格对齐
// ============================================================
// 想法
// ============================================================
export interface IdeaRecord {
id: string
title: string
description: string
status: string // draft | pending_review | approved | promoted | rejected
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 | paused | completed | cancelled
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 | review_ready | merged | abandoned
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
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 的结构) */
export interface WorkflowEventPayload {
execution_id: string
event: {
type: string
[key: string]: unknown
}
}
// ============================================================
// 通用
// ============================================================
export type UpdateField = {
id: string
field: string
value: string
}
// ============================================================
// 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 聊天事件(后端 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
} | {
type: 'AiCompleted'; total_tokens: number; prompt_tokens: number; completion_tokens: number
} | {
type: 'AiError'; error: string
} | {
type: 'AiAgentRound'; round: 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
models?: string[] | null
archived: boolean
prompt_tokens?: number | null
completion_tokens?: number | null
created_at: string
updated_at: string
}
/** 人工审批请求 */
export interface HumanApprovalRequest {
execution_id: string
node_id: string
title: string
description: string
options: string[]
}
/** 人工审批响应 */
export interface HumanApprovalResponse {
execution_id: string
node_id: string
decision: string
comment?: string
}
/** 切换对话返回(含 messages JSON */
export interface AiConversationDetail {
id: string
title: string | null
messages: string // JSON string of ChatMessage[]
}
/** 技能信息(本机 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
}