349 lines
7.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { AgentWorkflowPersistedState } from "@/types/agent";
import type { UiScreenDocument } from "@/lib/ui-screen/schema";
import type { StyleProPersistedState } from "@/lib/style-pro/config";
export type CanvasWorkspaceType = 'canvas' | 'agent' | 'video';
// 画布节点类型定义
export type NodeType =
| 'message'
| 'image'
| 'video'
| 'text'
| 'ui-screen'
| 'workflow'
| 'scene-fusion'
| 'model3d'
| 'world3d'
| 'agent-slot';
export type NodeStatus = 'pending' | 'uploading' | 'generating' | 'completed' | 'failed';
export type AgentSlotStatus = 'empty' | 'generating' | 'completed' | 'failed';
export type ToolType = 'select' | 'pan' | 'draw' | 'text';
// 画布节点位置
export interface Position {
x: number;
y: number;
}
// 画布节点尺寸
export interface Size {
width: number;
height: number;
}
// 视口状态
export interface Viewport {
x: number;
y: number;
zoom: number;
}
// 消息节点数据
export interface MessageNodeData {
role: 'user' | 'assistant';
content: string;
attachments?: Attachment[];
}
// 图片文字编辑项
export interface ImageTextEditItem {
id: string;
originalText: string;
editedText: string;
textColor?: string;
confidence?: number;
}
// 图片节点数据
export interface ImageNodeData {
src: string;
thumbnailUrl?: string;
assetId?: string;
title?: string;
note?: string;
prompt?: string;
model?: string;
status: NodeStatus;
metadata?: Record<string, any>;
// 图片编辑相关
originalSrc?: string;
editHistory?: ImageEditAction[];
hasAnnotations?: boolean; // 🆕 标记图片是否有用户标注
textEditItems?: ImageTextEditItem[]; // OCR 识别到的可编辑文字
textEditSource?: string; // OCR 结果对应的图片 URL
textEditUpdatedAt?: string; // OCR 更新时间
}
// 视频节点数据
export interface VideoNodeData {
src: string;
assetId?: string;
thumbnail?: string;
prompt?: string;
model?: string;
status: NodeStatus;
duration?: number;
progress?: number; // 生成进度百分比
coverImage?: string; // 用于生成视频的封面图
metadata?: Record<string, any>;
}
// 文本节点数据
export interface TextNodeData {
content: string;
fontSize?: number;
fontFamily?: string;
color?: string;
fontWeight?: string;
lineHeight?: number;
letterSpacing?: number;
textAlign?: "left" | "center" | "right";
transparent?: boolean;
backgroundColor?: string;
borderColor?: string;
borderWidth?: number;
borderRadius?: number;
padding?: number;
boxShadow?: string;
backdropBlur?: number;
textTransform?: "none" | "uppercase" | "lowercase" | "capitalize";
metadata?: Record<string, any>;
}
export interface UiScreenNodeData {
status: NodeStatus;
document: UiScreenDocument;
renderArtifacts?: {
htmlUrl?: string;
screenshotUrl?: string;
thumbnailUrl?: string;
layerMap?: Array<{
layerId: string;
x: number;
y: number;
width: number;
height: number;
}>;
};
source?: {
prompt?: string;
model?: string;
generationId?: string;
};
evaluation?: {
score?: number;
issues?: string[];
reviewedAt?: string;
};
metadata?: Record<string, any>;
}
export interface AgentSlotNodeData {
slotType: "image" | "video" | "ui-screen";
label?: string;
status: AgentSlotStatus;
acceptedSources?: Array<"text" | "image" | "selection" | "annotation">;
fillPolicy?: "replace-empty" | "append-version" | "replace-existing";
filledNodeIds?: string[];
aspectRatio?: string;
metadata?: Record<string, any>;
}
// 工作流节点数据
export interface WorkflowNodeData {
templateType: string;
title: string;
description?: string;
summary?: string;
status: NodeStatus;
group?: string;
accentColor?: string;
metadata?: Record<string, any>;
}
// 场景裂变节点数据
export interface SceneFusionNodeData {
productImage: string;
backgroundImages: string[];
productName?: string;
results: string[];
status: NodeStatus;
}
// 3D 模型节点数据
export interface Model3DNodeData {
src: string;
assetId?: string;
previewImage?: string;
prompt?: string;
modelVersion?: string;
format?: string;
status: NodeStatus;
metadata?: Record<string, any>;
}
export type World3DViewMode = 'world' | 'image' | 'mesh' | 'splat';
export interface World3DHotspot {
id: string;
label: string;
position: {
x: number;
y: number;
z: number;
};
description?: string;
createdAt?: string;
}
// 3D 世界节点数据
export interface World3DNodeData {
worldUrl?: string;
imageUrl?: string;
meshUrl?: string;
splatUrl?: string;
assetId?: string;
previewImage?: string;
prompt?: string;
modelVersion?: string;
status: NodeStatus;
activeView?: World3DViewMode;
firstPerson?: boolean;
hotspots?: World3DHotspot[];
semanticsMetadata?: Record<string, any>;
metadata?: Record<string, any>;
}
// 画布节点
export interface CanvasNode {
id: string;
type: NodeType;
position: Position;
size: Size;
data:
| MessageNodeData
| ImageNodeData
| VideoNodeData
| TextNodeData
| UiScreenNodeData
| WorkflowNodeData
| SceneFusionNodeData
| Model3DNodeData
| World3DNodeData
| AgentSlotNodeData;
connections: string[]; // 连接的节点 ID
parentId?: string; // 父节点 ID(用于对话上下文)
createdAt: Date;
updatedAt: Date;
}
// 画布连接线
export interface CanvasEdge {
id: string;
source: string;
target: string;
type?: 'default' | 'conversation' | 'reference';
}
// 画布状态
export interface CanvasState {
nodes: CanvasNode[];
edges: CanvasEdge[];
selectedNodeIds: string[];
viewport: Viewport;
tool: ToolType;
suppressedMediaKeys?: string[];
workflowState?: AgentWorkflowPersistedState;
styleProState?: StyleProPersistedState;
}
// 画布项目
export interface CanvasProject {
id: string;
userId: string;
title: string;
description?: string;
thumbnail?: string;
workspaceType?: CanvasWorkspaceType;
canvasData: CanvasState;
createdAt: Date;
updatedAt: Date;
}
export type CanvasInitialProject = Omit<
CanvasProject,
"canvasData" | "createdAt" | "description" | "thumbnail" | "updatedAt"
> & {
canvasData: any;
createdAt: string;
description?: string | null;
thumbnail?: string | null;
updatedAt: string;
};
export type CanvasProjectListItem = Omit<CanvasProject, "canvasData">;
// 附件类型
export interface Attachment {
type: 'image' | 'file';
url: string;
name?: string;
mimeType?: string;
}
// 图片编辑操作
export interface ImageEditAction {
type:
| 'rmbg'
| 'enhance'
| 'enhance-pro'
| 'extend'
| 'crop'
| 'adjust'
| 'flip-rotate'
| 'resize'
| 'angle-edit'
| 'scene-fusion'
| 'annotate'
| 'text-edit'
| 'box-cutout'
| 'layer-split';
timestamp: Date;
params?: Record<string, any>;
resultUrl?: string;
}
// 图片操作菜单项
export interface ImageAction {
label: string;
action: string;
icon?: React.ComponentType<{ className?: string }>;
api?: string;
component?: React.ComponentType<any>;
tool?: string;
}
// AI 生成参数
export interface GenerationParams {
prompt: string;
model: string;
negativePrompt?: string;
size?: string;
style?: string;
referenceImage?: string;
// 图片生成特有
aspectRatio?: string;
// 视频生成特有
duration?: number;
fps?: number;
}
// API 响应类型
export interface CanvasApiResponse<T = any> {
success: boolean;
data?: T;
error?: string;
}