Files
Genarrative/packages/shared/src/contracts/edutainmentBabyObject.ts

122 lines
3.1 KiB
TypeScript

export const BABY_OBJECT_MATCH_TEMPLATE_ID = 'baby-object-match';
export const BABY_OBJECT_MATCH_TEMPLATE_NAME = '宝贝识物';
export const BABY_OBJECT_MATCH_EDUTAINMENT_TAG = '寓教于乐';
export type BabyObjectMatchTemplateId = typeof BABY_OBJECT_MATCH_TEMPLATE_ID;
export type BabyObjectMatchAssetProvider =
| 'vector-engine-gpt-image-2'
| 'placeholder';
export type BabyObjectMatchPublicationStatus = 'draft' | 'published';
export type BabyObjectMatchItemAsset = {
itemId: string;
itemName: string;
imageSrc: string;
assetObjectId: string | null;
generationProvider: BabyObjectMatchAssetProvider;
prompt: string;
};
export type BabyObjectMatchVisualAssetKind =
| 'background'
| 'ui-frame'
| 'gift-box'
| 'basket'
| 'smoke-puff'
| 'left-hand'
| 'right-hand';
export type BabyObjectMatchVisualAsset = {
assetId: string;
assetKind: BabyObjectMatchVisualAssetKind;
imageSrc: string;
assetObjectId: string | null;
generationProvider: BabyObjectMatchAssetProvider;
prompt: string;
};
export type BabyObjectMatchVisualPackage = {
themePrompt: string;
assets: BabyObjectMatchVisualAsset[];
};
export type BabyObjectMatchDraft = {
draftId: string;
profileId: string;
templateId: BabyObjectMatchTemplateId;
templateName: typeof BABY_OBJECT_MATCH_TEMPLATE_NAME;
workTitle: string;
workDescription: string;
itemNames: [string, string];
itemAssets: [BabyObjectMatchItemAsset, BabyObjectMatchItemAsset];
visualPackage?: BabyObjectMatchVisualPackage | null;
themeTags: string[];
publicationStatus: BabyObjectMatchPublicationStatus;
createdAt: string;
updatedAt: string;
publishedAt: string | null;
};
export type CreateBabyObjectMatchDraftRequest = {
itemAName: string;
itemBName: string;
};
export type GenerateBabyObjectMatchAssetsRequest = {
itemNames: [string, string];
};
export type GenerateBabyObjectMatchAssetsResponse = {
assets: [BabyObjectMatchItemAsset, BabyObjectMatchItemAsset];
visualPackage?: BabyObjectMatchVisualPackage | null;
};
export type BabyObjectMatchDraftResponse = {
draft: BabyObjectMatchDraft;
};
export type SaveBabyObjectMatchDraftRequest = {
draft: BabyObjectMatchDraft;
};
export type BabyObjectMatchPublishRequest = {
draft: BabyObjectMatchDraft;
};
export type BabyObjectMatchPublishResponse = {
draft: BabyObjectMatchDraft;
publicWorkCode: string;
};
export function normalizeBabyObjectMatchItemName(value: string) {
return value.trim();
}
export function normalizeBabyObjectMatchTags(tags: string[]) {
return [
...new Set([
BABY_OBJECT_MATCH_EDUTAINMENT_TAG,
...tags.map((tag) => tag.trim()).filter(Boolean),
]),
];
}
export function hasBabyObjectMatchRequiredTag(tags: string[]) {
return tags.some((tag) => tag === BABY_OBJECT_MATCH_EDUTAINMENT_TAG);
}
export function validateBabyObjectMatchItemNames(
payload: CreateBabyObjectMatchDraftRequest,
) {
const itemAName = normalizeBabyObjectMatchItemName(payload.itemAName);
const itemBName = normalizeBabyObjectMatchItemName(payload.itemBName);
return {
itemAName,
itemBName,
valid: Boolean(itemAName && itemBName),
};
}