157 lines
6.5 KiB
TypeScript
157 lines
6.5 KiB
TypeScript
import { request } from '../../lib/http'
|
|
import type {
|
|
IdentityImagePreview,
|
|
IdentityImageGenerationStart,
|
|
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<IdentityImageGenerationStart>(`${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
|
|
}),
|
|
/**
|
|
* 确认身份母版,质量审核可能耗时,等待真实服务结果。
|
|
* @param subjectId 正式主体编号
|
|
* @param imageId 当前候选编号
|
|
* @returns 已通过事务确认的图片或锁定回执
|
|
*/
|
|
setAnchor: (subjectId: string, imageId: string) =>
|
|
request<IdentityImage>(`${identityPath(subjectId)}/images/${encodeURIComponent(imageId)}/anchor`, {
|
|
method: 'PUT',
|
|
timeoutMs: 0
|
|
}),
|
|
/**
|
|
* 确认场景或道具母版,通过质量门禁后锁定身份。
|
|
* @param subjectId 正式主体编号
|
|
* @param imageId 当前候选编号
|
|
* @returns 已通过事务确认的图片或锁定回执
|
|
*/
|
|
confirmStableAnchor: (subjectId: string, imageId: string) =>
|
|
request<ConfirmCastingResult>(
|
|
`${identityPath(subjectId)}/images/${encodeURIComponent(imageId)}/stable-anchor`,
|
|
{
|
|
method: 'PUT',
|
|
timeoutMs: 0
|
|
}
|
|
),
|
|
/**
|
|
* 确认角色选角,通过质量门禁后锁定演员。
|
|
* @param subjectId 正式主体编号
|
|
* @param imageId 当前候选编号
|
|
* @returns 已通过事务确认的图片或锁定回执
|
|
*/
|
|
confirmCasting: (subjectId: string, imageId: string) =>
|
|
request<ConfirmCastingResult>(`${identityPath(subjectId)}/images/${encodeURIComponent(imageId)}/casting`, {
|
|
method: 'PUT',
|
|
timeoutMs: 0
|
|
})
|
|
}
|