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

131 lines
5.7 KiB
TypeScript

import { request } from '../../lib/http'
import type {
IdentityImagePreview,
IdentityValidationResult,
StableAnchorQualityInput,
StableAnchorQualityResult,
CastingBatchResult,
CharacterCastingReadiness,
ConfirmCastingResult,
GenerateCastingCandidateInput,
GenerateCastingCandidatesInput,
GenerateIdentityImageInput,
IdentityBatchResult,
IdentityImage,
IdentityModule,
SaveIdentityInput,
StableAnchorBatchResult,
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; module?: IdentityModule }) =>
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 }
),
/** 为场景或道具生成稳定身份母版,并由后端原子设为 Anchor、锁定 Identity。 */
generateStableAnchors: (
projectId: string,
input: { module: 'scene' | 'prop'; limit: number; concurrency: number }
) =>
request<StableAnchorBatchResult>(
`/projects/${encodeURIComponent(projectId)}/subject-identities/anchors/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 }),
/**
* 读取与实际生图同源的输入预览,道具可能执行已确认的结构模型编译。
* @param subjectId 正式主体 ID
* @param input 与实际生图相同的参数
* @param signal 只读预览取消信号,可能付费的道具不传
* @returns 后端真实输入与最终参数
*/
previewImage: (subjectId: string, input: GenerateIdentityImageInput, signal?: AbortSignal) =>
request<IdentityImagePreview>(`${identityPath(subjectId)}/images/preview`, {
method: 'POST',
body: input,
signal,
timeoutMs: 0
}),
/**
* 明确确认后对指定身份图片执行视觉校验。
* @param subjectId 正式主体 ID
* @param imageId 此主体的正式图片 ID
* @returns 真实视觉校验回执
*/
validateImage: (subjectId: string, imageId: string) =>
request<IdentityValidationResult>(`${identityPath(subjectId)}/images/${encodeURIComponent(imageId)}/validate`, {
method: 'POST',
timeoutMs: 0
}),
/**
* 为单个场景或道具执行有限预算的稳定母版质量闭环。
* @param subjectId 正式主体 ID
* @param input 已确认的模型与修复预算
* @returns 候选、各轮质量和实际母版确认回执
*/
generateStableAnchorQuality: (subjectId: string, input: StableAnchorQualityInput) =>
request<StableAnchorQualityResult>(`${identityPath(subjectId)}/stable-anchor/generate-quality`, {
method: 'POST',
body: input,
timeoutMs: 0
}),
setAnchor: (subjectId: string, imageId: string) =>
request<IdentityImage>(`${identityPath(subjectId)}/images/${encodeURIComponent(imageId)}/anchor`, {
method: 'PUT'
}),
confirmStableAnchor: (subjectId: string, imageId: string) =>
request<ConfirmCastingResult>(
`${identityPath(subjectId)}/images/${encodeURIComponent(imageId)}/stable-anchor`,
{
method: 'PUT'
}
),
confirmCasting: (subjectId: string, imageId: string) =>
request<ConfirmCastingResult>(`${identityPath(subjectId)}/images/${encodeURIComponent(imageId)}/casting`, {
method: 'PUT'
})
}