Files
short-drama-agent-front/src/features/subject-identity/api.ts
T

72 lines
3.2 KiB
TypeScript

import { request } from '../../lib/http'
import type {
CastingBatchResult,
CharacterCastingReadiness,
ConfirmCastingResult,
GenerateCastingCandidateInput,
GenerateCastingCandidatesInput,
GenerateIdentityImageInput,
IdentityBatchResult,
IdentityImage,
SaveIdentityInput,
SubjectIdentity
} from './types'
/** 身份接口使用正式 Subject ID,与形态 ID、角色表 ID 分开。 */
function identityPath(subjectId: string) {
return `/subjects/${encodeURIComponent(subjectId)}/identity`
}
/** 身份文本和参考图分开操作;有费用的请求均不自动重试。 */
export const subjectIdentityApi = {
get: (subjectId: string, signal?: AbortSignal) =>
request<SubjectIdentity | null>(identityPath(subjectId), { signal }),
save: (subjectId: string, input: SaveIdentityInput) =>
request<SubjectIdentity>(identityPath(subjectId), { method: 'PUT', body: input }),
generate: (subjectId: string, force: boolean) =>
request<SubjectIdentity>(`${identityPath(subjectId)}/generate`, {
method: 'POST',
body: { force },
timeoutMs: 0
}),
generateProject: (projectId: string, input: { force: boolean; concurrency: number }) =>
request<IdentityBatchResult>(`/projects/${encodeURIComponent(projectId)}/subject-identities/generate`, {
method: 'POST',
body: input,
timeoutMs: 0
}),
generateCharacters: (projectId: string, input: { force: boolean; concurrency: number }) =>
request<IdentityBatchResult>(`/projects/${encodeURIComponent(projectId)}/character-identities/generate`, {
method: 'POST',
body: input,
timeoutMs: 0
}),
castingReadiness: (projectId: string, signal?: AbortSignal) =>
request<CharacterCastingReadiness>(`/projects/${encodeURIComponent(projectId)}/character-casting/readiness`, {
signal
}),
generateCastingCandidate: (subjectId: string, input: GenerateCastingCandidateInput) =>
request<IdentityImage>(`${identityPath(subjectId)}/casting-candidates`, {
method: 'POST',
body: input,
timeoutMs: 0
}),
generateCastingCandidates: (projectId: string, input: GenerateCastingCandidatesInput) =>
request<CastingBatchResult>(
`/projects/${encodeURIComponent(projectId)}/character-casting/candidates/generate`,
{ method: 'POST', body: input, timeoutMs: 0 }
),
listImages: (subjectId: string, signal?: AbortSignal) =>
request<IdentityImage[]>(`${identityPath(subjectId)}/images`, { signal }),
generateImage: (subjectId: string, input: GenerateIdentityImageInput) =>
request<IdentityImage>(`${identityPath(subjectId)}/images`, { method: 'POST', body: input, timeoutMs: 0 }),
setAnchor: (subjectId: string, imageId: string) =>
request<IdentityImage>(`${identityPath(subjectId)}/images/${encodeURIComponent(imageId)}/anchor`, {
method: 'PUT'
}),
confirmCasting: (subjectId: string, imageId: string) =>
request<ConfirmCastingResult>(`${identityPath(subjectId)}/images/${encodeURIComponent(imageId)}/casting`, {
method: 'PUT'
})
}