- 新增 web/src/api/ 目录(6 个文件):client.ts 基础设施 + 5 个领域模块 - 封装 18 处 fetch 调用为强类型函数,消除 17 处硬编码 /api/ 路径 - 统一 13 处重复的 fetch+json+错误处理模式 - 删除旧 web/src/components/Settings/api/expert.ts,合并到新 api/experts.ts - ConfigPage.tsx 替换 15 处 fetch 调用,ExpertSelector.tsx 改用新 API - 保持现有组件行为不变(静默失败仍静默,错误处理等价)
15 lines
507 B
TypeScript
15 lines
507 B
TypeScript
import { API, apiGetSilent } from './client'
|
|
import type { SkillListResponse } from '../components/Settings/types'
|
|
|
|
export function listSkills(): Promise<SkillListResponse | null> {
|
|
return apiGetSilent<SkillListResponse>(API.skills)
|
|
}
|
|
|
|
export async function toggleSkill(name: string, scope: string, enabled: boolean): Promise<Response> {
|
|
return fetch(API.skillsToggle, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ name, scope, enabled }),
|
|
})
|
|
}
|