feat(frontend): 接入真实媒体工作流与模型配置卡片
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { apiClient, resolveApiUrl } from './apiClient'
|
||||
|
||||
export interface Segment { segment_id: string; start_time: number; end_time: number; text: string; speaker: string | null; language?: string }
|
||||
export interface MediaJob {
|
||||
job_id: string; attachment_id: string; status: 'queued' | 'running' | 'processing' | 'completed' | 'failed' | 'cancelled'
|
||||
text: string | null; original_text: string | null; segments: Segment[]; speaker_names: Record<string, string>
|
||||
revision: number; created_at: string; progress: number | null; error_code: string | null; error_message: string | null
|
||||
warnings: string[]; source: string | null; fallback_reason: string | null; local_only: boolean
|
||||
}
|
||||
export const mediaService = {
|
||||
list: () => apiClient.get<{ items: MediaJob[] }>('/api/media/transcriptions'),
|
||||
get: (id: string) => apiClient.get<MediaJob>(`/api/media/transcriptions/${encodeURIComponent(id)}`),
|
||||
create: (body: unknown) => apiClient.post<MediaJob>('/api/media/transcriptions', body),
|
||||
cancel: (id: string) => apiClient.post<MediaJob>(`/api/media/transcriptions/${encodeURIComponent(id)}/cancel`),
|
||||
retry: (id: string) => apiClient.post<MediaJob>(`/api/media/transcriptions/${encodeURIComponent(id)}/retry`),
|
||||
match: (attachment_id: string, reference_attachment_id: string, local_only: boolean) => apiClient.post<{score:number;source:string;fallback_reason:string|null}>('/api/media/speaker-matches', {attachment_id,reference_attachment_id,local_only}),
|
||||
save: (job: MediaJob) => apiClient.patch<MediaJob>(`/api/media/transcriptions/${encodeURIComponent(job.job_id)}`, {
|
||||
revision: job.revision, text: job.text, segments: job.segments, speaker_names: job.speaker_names,
|
||||
}),
|
||||
revisions: (id: string) => apiClient.get<{items: MediaJob[]}>(`/api/media/transcriptions/${encodeURIComponent(id)}/revisions`),
|
||||
note: (id: string, title: string) => apiClient.post<{note_id: string; title: string}>(`/api/media/transcriptions/${encodeURIComponent(id)}/notes`, { title }),
|
||||
audio: (id: string) => resolveApiUrl(`/api/media/attachments/${encodeURIComponent(id)}`),
|
||||
impact: (id: string) => apiClient.get<{message:string;retained_note_ids:string[]}>(`/api/media/attachments/${encodeURIComponent(id)}/cleanup-impact`),
|
||||
purge: (id: string) => apiClient.delete(`/api/media/attachments/${encodeURIComponent(id)}`),
|
||||
async upload(file: File) {
|
||||
const response = await fetch(resolveApiUrl(`/api/media/attachments?filename=${encodeURIComponent(file.name)}`), {
|
||||
method: 'POST', headers: {'Content-Type': 'application/octet-stream'}, body: file,
|
||||
})
|
||||
if (!response.ok) throw new Error((await response.json())?.error?.message || '附件上传失败')
|
||||
return await response.json() as {attachment_id: string}
|
||||
},
|
||||
}
|
||||
@@ -8,6 +8,8 @@ function capabilityMap(capabilities: string[]): Partial<ModelCapability> {
|
||||
function toProvider(provider: ApiProviderConfig): ProviderConfig {
|
||||
return {
|
||||
provider_id: provider.provider_id,
|
||||
version: provider.version,
|
||||
request_overrides: provider.request_overrides || [],
|
||||
provider_type: provider.provider_type,
|
||||
name: provider.name,
|
||||
base_url: provider.base_url ?? undefined,
|
||||
@@ -35,6 +37,7 @@ export async function getProvider(providerId: string): Promise<ProviderConfig> {
|
||||
export async function createProvider(data: Omit<ProviderConfig, 'provider_id'>): Promise<ProviderConfig> {
|
||||
const response = await apiClient.post<ApiProviderConfig>('/api/providers', {
|
||||
provider_type: data.provider_type,
|
||||
request_overrides: data.request_overrides,
|
||||
name: data.name,
|
||||
base_url: data.base_url,
|
||||
default_model: data.default_model || null,
|
||||
@@ -64,6 +67,8 @@ export async function putCredential(credentialId: string, apiKey: string): Promi
|
||||
export async function updateProvider(providerId: string, data: ProviderUpdateRequest): Promise<ProviderConfig> {
|
||||
const response = await apiClient.patch<ApiProviderConfig>(`/api/providers/${providerId}`, {
|
||||
provider_type: data.provider_type,
|
||||
version: data.version,
|
||||
request_overrides: data.request_overrides,
|
||||
name: data.name,
|
||||
base_url: data.base_url,
|
||||
default_model: data.default_model,
|
||||
|
||||
Reference in New Issue
Block a user