新增: F-01模型拉取IPC+Settings拉取UI(FR-S1密钥内存解析闭环)

This commit is contained in:
2026-06-17 00:14:38 +08:00
parent 8a142c212c
commit a26b86e003
7 changed files with 257 additions and 2 deletions

View File

@@ -2,7 +2,7 @@
import { invoke } from '@tauri-apps/api/core'
import { listen, type UnlistenFn } from '@tauri-apps/api/event'
import type { AiChatEvent, AiConversationDetail, AiConversationSummary, AiProviderConfig, SkillInfo } from './types'
import type { AiChatEvent, AiConversationDetail, AiConversationSummary, AiProviderConfig, ModelConfig, SkillInfo } from './types'
export const aiApi = {
/** 发送消息(非阻塞,通过 ai-chat-event 流式返回skill 传技能名则注入其 SKILL.md */
@@ -105,6 +105,25 @@ export const aiApi = {
return invoke('ai_delete_provider', { providerId })
},
/**
* 测试连接并拉取厂商模型列表(F-01 阶段5)。
* 后端:DB 取 provider → FR-S1 内存解析 api_key → fetch_and_probe
* (网络拉模型名 + 探测 4 维度)→ 写回 model_configs → 返回。
* 返回值 ModelConfig 不含 api_key(FR-S1 闭环)。
* 需已落库的 providerId(新建态先保存再拉取)。
*/
fetchModels(providerId: string): Promise<ModelConfig[]> {
return invoke('ai_fetch_models', { providerId })
},
/**
* 单模型探测(F-01 阶段5):纯 CPU 启发式 + 预设表,无网络。
* 返回填充了 probe_source 的 ModelConfig。用途:手动补模型名后探测能力维度。
*/
probeModel(modelId: string): Promise<ModelConfig> {
return invoke('ai_probe_model', { modelId })
},
/** 设置 LLM 调用并发上限(全局 / 单对话,运行时即时生效;软收敛不中断进行中调用) */
setConcurrencyConfig(globalLimit: number, perConvLimit: number): Promise<void> {
return invoke('ai_set_concurrency_config', { globalLimit, perConvLimit })

View File

@@ -181,12 +181,57 @@ export interface AiProviderConfig {
base_url: string
default_model: string
models: string | null
/** 模型能力配置数组(F-01:4 维度 + 路由控制;DB TEXT 列 JSON 解析,老库可能缺失) */
model_configs?: ModelConfig[]
is_default: boolean
config: string | null
created_at: string
updated_at: string
}
// ============================================================
// F-01 模型能力系统(ModelConfig,与 crates/df-ai-core/src/model.rs 严格对齐)
// ============================================================
/** 维度 1 — 模态(模型能接收什么输入)。serde snake_case 字面量。 */
export type Modality = 'text' | 'vision' | 'audio' | 'video'
/** 维度 2 — 能力(模型能做什么)。serde snake_case 字面量。 */
export type Capability = 'tool_use' | 'embedding' | 'code_gen'
/** 维度 3 — 价格分级(成本)。serde snake_case 字面量。 */
export type CostTier = 'free' | 'low' | 'medium' | 'high'
/** 维度 4 — 智力分级。serde snake_case 字面量。 */
export type IntelligenceTier = 'lite' | 'standard' | 'plus' | 'ultra'
/** 探测来源(只读,由后端探测器填充)。serde snake_case 字面量。 */
export type ProbeSource = 'user_set' | 'preset_table' | 'heuristic' | 'default'
/** 单模型完整配置(4 维度 + 路由控制 + 探测元数据)。 */
export interface ModelConfig {
/** 模型名(如 "glm-4v-flash") */
model_id: string
/** 启用/禁用(false=配了但不参与路由) */
enabled: boolean
/** 用户自定义别名(可选) */
label?: string
/** 模态集合 */
modalities: Modality[]
/** 能力集合 */
capabilities: Capability[]
/** 价格分级 */
cost_tier: CostTier
/** 智力分级 */
intelligence: IntelligenceTier
/** 权重(0-100,同能力候选中优先选权重高的) */
weight: number
/** 上下文窗口大小(tokens) */
context_window: number
/** 探测来源(可选) */
probe_source?: ProbeSource
}
/**
* AI 错误分类字面量集(B-260615-42)。
* 与后端 `commands::ai::ErrorType` 的 serde(rename_all = "snake_case") 严格对齐。