Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
H1: status 值不匹配 disabled→inactive + source 补 admin 映射 + valueEnum H2: experience.rs format_for_injection 添加 xml_escape H3: TriggerContext industry_keywords 接通全局缓存 M2: ID 自动生成移除中文字符保留 + 无 ASCII 时提示手动输入 M3: TS CreateIndustryRequest 添加 id? 字段 M4: ListIndustriesQuery 添加 deny_unknown_fields
106 lines
3.1 KiB
TypeScript
106 lines
3.1 KiB
TypeScript
// ============================================================
|
||
// 行业配置 API 服务层
|
||
// ============================================================
|
||
|
||
import request, { withSignal } from './request'
|
||
import type { PaginatedResponse } from '@/types'
|
||
import type { IndustryInfo, AccountIndustryItem } from '@/types'
|
||
|
||
/** 行业列表项(列表接口返回) */
|
||
export interface IndustryListItem {
|
||
id: string
|
||
name: string
|
||
icon: string
|
||
description: string
|
||
status: string
|
||
source: string
|
||
keywords_count: number
|
||
created_at: string
|
||
updated_at: string
|
||
}
|
||
|
||
/** 行业完整配置(含关键词、prompt 等) */
|
||
export interface IndustryFullConfig {
|
||
id: string
|
||
name: string
|
||
icon: string
|
||
description: string
|
||
status: string
|
||
source: string
|
||
keywords: string[]
|
||
system_prompt: string
|
||
cold_start_template: string
|
||
pain_seed_categories: string[]
|
||
skill_priorities: Array<{ skill_id: string; priority: number }>
|
||
created_at: string
|
||
updated_at: string
|
||
}
|
||
|
||
/** 创建行业请求 */
|
||
export interface CreateIndustryRequest {
|
||
id?: string
|
||
name: string
|
||
icon: string
|
||
description: string
|
||
keywords?: string[]
|
||
system_prompt?: string
|
||
cold_start_template?: string
|
||
pain_seed_categories?: string[]
|
||
}
|
||
|
||
/** 更新行业请求 */
|
||
export interface UpdateIndustryRequest {
|
||
name?: string
|
||
icon?: string
|
||
description?: string
|
||
status?: string
|
||
keywords?: string[]
|
||
system_prompt?: string
|
||
cold_start_template?: string
|
||
pain_seed_categories?: string[]
|
||
skill_priorities?: Array<{ skill_id: string; priority: number }>
|
||
}
|
||
|
||
/** 设置用户行业请求 */
|
||
export interface SetAccountIndustriesRequest {
|
||
industries: Array<{
|
||
industry_id: string
|
||
is_primary: boolean
|
||
}>
|
||
}
|
||
|
||
export const industryService = {
|
||
/** 行业列表 */
|
||
list: (params?: { page?: number; page_size?: number; status?: string }, signal?: AbortSignal) =>
|
||
request.get<PaginatedResponse<IndustryListItem>>('/industries', withSignal({ params }, signal))
|
||
.then((r) => r.data),
|
||
|
||
/** 行业详情 */
|
||
get: (id: string, signal?: AbortSignal) =>
|
||
request.get<IndustryInfo>(`/industries/${id}`, withSignal({}, signal))
|
||
.then((r) => r.data),
|
||
|
||
/** 行业完整配置 */
|
||
getFullConfig: (id: string, signal?: AbortSignal) =>
|
||
request.get<IndustryFullConfig>(`/industries/${id}/full-config`, withSignal({}, signal))
|
||
.then((r) => r.data),
|
||
|
||
/** 创建行业 */
|
||
create: (data: CreateIndustryRequest) =>
|
||
request.post<IndustryInfo>('/industries', data).then((r) => r.data),
|
||
|
||
/** 更新行业 */
|
||
update: (id: string, data: UpdateIndustryRequest) =>
|
||
request.patch<IndustryInfo>(`/industries/${id}`, data).then((r) => r.data),
|
||
|
||
/** 获取用户授权行业 */
|
||
getAccountIndustries: (accountId: string, signal?: AbortSignal) =>
|
||
request.get<AccountIndustryItem[]>(`/accounts/${accountId}/industries`, withSignal({}, signal))
|
||
.then((r) => r.data),
|
||
|
||
/** 设置用户授权行业 */
|
||
setAccountIndustries: (accountId: string, data: SetAccountIndustriesRequest) =>
|
||
request.put<AccountIndustryItem[]>(`/accounts/${accountId}/industries`, data)
|
||
.then((r) => r.data),
|
||
}
|