312 lines
6.3 KiB
TypeScript
312 lines
6.3 KiB
TypeScript
/**
|
|
* Text Video Agent API 类型定义
|
|
*/
|
|
|
|
// 任务类型枚举
|
|
export enum TaskType {
|
|
TEA = 'tea',
|
|
CHOP = 'chop',
|
|
LADY = 'lady',
|
|
VLOG = 'vlog'
|
|
}
|
|
|
|
// 任务状态枚举
|
|
export enum TaskStatus {
|
|
PENDING = 'pending',
|
|
RUNNING = 'running',
|
|
COMPLETED = 'completed',
|
|
FAILED = 'failed'
|
|
}
|
|
|
|
// 长宽比枚举
|
|
export enum AspectRatio {
|
|
SQUARE = '1:1',
|
|
PORTRAIT = '9:16',
|
|
LANDSCAPE = '16:9',
|
|
VERTICAL = '3:4',
|
|
HORIZONTAL = '4:3'
|
|
}
|
|
|
|
// 视频时长选项
|
|
export enum VideoDuration {
|
|
SHORT = '3',
|
|
MEDIUM = '5',
|
|
LONG = '10'
|
|
}
|
|
|
|
// 扩展的API响应接口
|
|
export interface ExtendedAPIResponse<T = any> {
|
|
status: boolean
|
|
msg: string
|
|
data?: T
|
|
timestamp?: string
|
|
request_id?: string
|
|
}
|
|
|
|
// 图片生成结果
|
|
export interface ImageGenerationResult {
|
|
image_url: string
|
|
thumbnail_url?: string
|
|
width?: number
|
|
height?: number
|
|
format?: string
|
|
size?: number
|
|
generation_time?: number
|
|
prompt_used?: string
|
|
}
|
|
|
|
// 视频生成结果
|
|
export interface VideoGenerationResult {
|
|
video_url: string
|
|
thumbnail_url?: string
|
|
duration: number
|
|
width?: number
|
|
height?: number
|
|
format?: string
|
|
size?: number
|
|
generation_time?: number
|
|
prompt_used?: string
|
|
image_url_used?: string
|
|
}
|
|
|
|
// 任务详细信息
|
|
export interface TaskDetail {
|
|
task_id: string
|
|
task_type: TaskType
|
|
status: TaskStatus
|
|
progress: number
|
|
created_at: string
|
|
updated_at: string
|
|
completed_at?: string
|
|
prompt: string
|
|
img_url?: string
|
|
ar: string
|
|
result?: ImageGenerationResult | VideoGenerationResult
|
|
error?: {
|
|
code: string
|
|
message: string
|
|
details?: any
|
|
}
|
|
metadata?: {
|
|
user_id?: string
|
|
session_id?: string
|
|
client_info?: any
|
|
}
|
|
}
|
|
|
|
// 图片描述结果
|
|
export interface ImageDescriptionResult {
|
|
description: string
|
|
tags?: string[]
|
|
confidence?: number
|
|
language?: string
|
|
analysis_time?: number
|
|
}
|
|
|
|
// 文件上传结果
|
|
export interface FileUploadResult {
|
|
file_url: string
|
|
file_name: string
|
|
file_size: number
|
|
file_type: string
|
|
upload_time: string
|
|
cdn_url?: string
|
|
}
|
|
|
|
// 健康检查结果
|
|
export interface HealthCheckResult {
|
|
service: string
|
|
status: 'healthy' | 'unhealthy'
|
|
version?: string
|
|
uptime?: number
|
|
dependencies?: {
|
|
[key: string]: 'healthy' | 'unhealthy'
|
|
}
|
|
}
|
|
|
|
// 示例提示词结果
|
|
export interface SamplePromptResult {
|
|
task_type: string
|
|
prompts: string[]
|
|
examples?: {
|
|
prompt: string
|
|
description: string
|
|
tags?: string[]
|
|
}[]
|
|
}
|
|
|
|
// 生成选项配置
|
|
export interface GenerationOptions {
|
|
// 通用选项
|
|
quality?: 'low' | 'medium' | 'high' | 'ultra'
|
|
style?: 'realistic' | 'artistic' | 'cartoon' | 'anime'
|
|
mood?: 'bright' | 'dark' | 'neutral' | 'vibrant'
|
|
|
|
// 图片特定选项
|
|
image_format?: 'jpg' | 'png' | 'webp'
|
|
image_quality?: number // 1-100
|
|
|
|
// 视频特定选项
|
|
video_format?: 'mp4' | 'webm' | 'avi'
|
|
video_quality?: 'low' | 'medium' | 'high' | '4k'
|
|
frame_rate?: number // fps
|
|
|
|
// 高级选项
|
|
seed?: number
|
|
guidance_scale?: number
|
|
num_inference_steps?: number
|
|
negative_prompt?: string
|
|
}
|
|
|
|
// 批量处理请求
|
|
export interface BatchRequest {
|
|
requests: {
|
|
id: string
|
|
type: 'image' | 'video'
|
|
prompt: string
|
|
options?: GenerationOptions
|
|
}[]
|
|
batch_options?: {
|
|
parallel_limit?: number
|
|
retry_failed?: boolean
|
|
notify_on_complete?: boolean
|
|
}
|
|
}
|
|
|
|
// 批量处理结果
|
|
export interface BatchResult {
|
|
batch_id: string
|
|
total_requests: number
|
|
completed: number
|
|
failed: number
|
|
results: {
|
|
id: string
|
|
status: 'completed' | 'failed'
|
|
result?: ImageGenerationResult | VideoGenerationResult
|
|
error?: string
|
|
}[]
|
|
}
|
|
|
|
// 使用统计
|
|
export interface UsageStats {
|
|
user_id?: string
|
|
period: 'daily' | 'weekly' | 'monthly'
|
|
images_generated: number
|
|
videos_generated: number
|
|
total_generation_time: number
|
|
total_cost?: number
|
|
quota_remaining?: number
|
|
}
|
|
|
|
// 错误类型
|
|
export interface APIError {
|
|
code: string
|
|
message: string
|
|
details?: any
|
|
timestamp: string
|
|
request_id?: string
|
|
suggestion?: string
|
|
}
|
|
|
|
// 进度回调函数类型
|
|
export type ProgressCallback = (step: string, progress: number, details?: any) => void
|
|
|
|
// 事件回调函数类型
|
|
export type EventCallback = (event: {
|
|
type: 'start' | 'progress' | 'complete' | 'error'
|
|
data: any
|
|
timestamp: string
|
|
}) => void
|
|
|
|
// 配置选项
|
|
export interface APIConfig {
|
|
baseURL?: string
|
|
timeout?: number
|
|
retries?: number
|
|
apiKey?: string
|
|
userAgent?: string
|
|
debug?: boolean
|
|
}
|
|
|
|
// 缓存选项
|
|
export interface CacheOptions {
|
|
enabled: boolean
|
|
ttl?: number // 缓存时间(秒)
|
|
maxSize?: number // 最大缓存条目数
|
|
storage?: 'memory' | 'localStorage' | 'sessionStorage'
|
|
}
|
|
|
|
// 高级配置
|
|
export interface AdvancedConfig extends APIConfig {
|
|
cache?: CacheOptions
|
|
rateLimit?: {
|
|
enabled: boolean
|
|
requestsPerMinute?: number
|
|
requestsPerHour?: number
|
|
}
|
|
monitoring?: {
|
|
enabled: boolean
|
|
endpoint?: string
|
|
metrics?: string[]
|
|
}
|
|
}
|
|
|
|
// 导出所有类型的联合类型
|
|
export type AllGenerationResults = ImageGenerationResult | VideoGenerationResult
|
|
export type AllAPIResponses = ExtendedAPIResponse<AllGenerationResults>
|
|
|
|
// 常用的预设配置
|
|
export const PRESET_CONFIGS = {
|
|
// 快速生成(低质量,快速)
|
|
FAST: {
|
|
quality: 'low' as const,
|
|
max_wait_time: 60,
|
|
poll_interval: 1
|
|
},
|
|
|
|
// 标准生成(中等质量)
|
|
STANDARD: {
|
|
quality: 'medium' as const,
|
|
max_wait_time: 120,
|
|
poll_interval: 2
|
|
},
|
|
|
|
// 高质量生成(高质量,较慢)
|
|
HIGH_QUALITY: {
|
|
quality: 'high' as const,
|
|
max_wait_time: 300,
|
|
poll_interval: 5
|
|
},
|
|
|
|
// 超高质量生成(最高质量,最慢)
|
|
ULTRA: {
|
|
quality: 'ultra' as const,
|
|
max_wait_time: 600,
|
|
poll_interval: 10
|
|
}
|
|
} as const
|
|
|
|
// 常用的任务类型配置
|
|
export const TASK_TYPE_CONFIGS = {
|
|
[TaskType.TEA]: {
|
|
description: '茶叶相关内容生成',
|
|
defaultAR: AspectRatio.PORTRAIT,
|
|
suggestedDuration: VideoDuration.MEDIUM
|
|
},
|
|
[TaskType.CHOP]: {
|
|
description: '切菜/烹饪相关内容生成',
|
|
defaultAR: AspectRatio.LANDSCAPE,
|
|
suggestedDuration: VideoDuration.SHORT
|
|
},
|
|
[TaskType.LADY]: {
|
|
description: '女性人物相关内容生成',
|
|
defaultAR: AspectRatio.PORTRAIT,
|
|
suggestedDuration: VideoDuration.MEDIUM
|
|
},
|
|
[TaskType.VLOG]: {
|
|
description: 'Vlog风格内容生成',
|
|
defaultAR: AspectRatio.PORTRAIT,
|
|
suggestedDuration: VideoDuration.LONG
|
|
}
|
|
} as const
|