需求:用户可在同一设计项目中新建和切换会话,任务列表保持项目级共享。 实现: - 增加会话选择、新建入口及本地数据迁移 - Conversation 独立消息、Brief、Quote 与流式状态 - 保留项目任务并修复 Task revision 与 ABA 异步竞态 - 保持 Enter 发送、Shift+Enter 换行及 IME 保护
195 lines
4.9 KiB
TypeScript
195 lines
4.9 KiB
TypeScript
export const IMAGE_WORKSPACE_UNAVAILABLE_CODE = 'IMAGE_WORKSPACE_UNAVAILABLE';
|
|
export const IMAGE_WORKSPACE_UNAVAILABLE_MESSAGE = 'AI 设计暂不可用';
|
|
export const IMAGE_WORKSPACE_API_PATH = '/api/works/image-workspace';
|
|
|
|
export type DesignMedium = 'image' | 'video';
|
|
export type DesignWorkspacePhase = 'shaping' | 'awaiting_confirmation' | 'blocked';
|
|
export type DesignTaskStatus = 'queued' | 'running' | 'succeeded' | 'failed' | 'cancelled';
|
|
export type DesignQuoteStatus = 'active' | 'consumed' | 'expired' | 'superseded';
|
|
|
|
export type DesignCapabilities = {
|
|
conversation: boolean;
|
|
generation: boolean;
|
|
image: boolean;
|
|
video: boolean;
|
|
};
|
|
|
|
export type DesignBrief = {
|
|
version: number;
|
|
status: 'draft' | 'ready' | 'confirmed';
|
|
medium: DesignMedium | null;
|
|
summary: string;
|
|
ready: boolean;
|
|
missingDecision: string | null;
|
|
};
|
|
|
|
export type DesignGenerationQuote = {
|
|
quoteId: string;
|
|
status: DesignQuoteStatus;
|
|
medium: DesignMedium;
|
|
briefVersion: number;
|
|
briefSummary: string;
|
|
quotedDesignPoints: number;
|
|
expiresAt: string;
|
|
};
|
|
|
|
export type DesignMessage = {
|
|
id: string;
|
|
role: 'user' | 'assistant';
|
|
kind: 'user' | 'reply' | 'choice' | 'confirmation' | 'safety_redirect' | 'failure';
|
|
text: string;
|
|
quickReplies: string[];
|
|
generationQuote: DesignGenerationQuote | null;
|
|
turnRevision: number;
|
|
createdAt: string;
|
|
};
|
|
|
|
export type DesignWorkspaceSummary = {
|
|
workspaceId: string;
|
|
title: string;
|
|
viewRevision: number;
|
|
conversationCount: number;
|
|
phase: DesignWorkspacePhase;
|
|
updatedAt: string;
|
|
};
|
|
|
|
export type DesignWorkspace = DesignWorkspaceSummary & {
|
|
conversations: DesignConversationSummary[];
|
|
};
|
|
|
|
export type DesignConversationSummary = {
|
|
conversationId: string;
|
|
workspaceId: string;
|
|
title: string;
|
|
turnRevision: number;
|
|
phase: DesignWorkspacePhase;
|
|
brief: DesignBrief;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
};
|
|
|
|
export type DesignConversation = DesignConversationSummary & {
|
|
messages: DesignMessage[];
|
|
};
|
|
|
|
export type DesignAsset = {
|
|
assetId: string;
|
|
workspaceId: string;
|
|
mediaType: DesignMedium;
|
|
mimeType: string;
|
|
width: number;
|
|
height: number;
|
|
durationMilliseconds: number | null;
|
|
createdAt: string;
|
|
contentPath: string;
|
|
};
|
|
|
|
export type DesignAssetSaveResult = {
|
|
status: 'saved' | 'cancelled';
|
|
};
|
|
|
|
export type DesignImageUploadMimeType = 'image/jpeg' | 'image/png' | 'image/webp';
|
|
|
|
export type DesignAssetUploadInput = {
|
|
workspaceId: string;
|
|
fileName: string;
|
|
mimeType: DesignImageUploadMimeType;
|
|
bytes: Uint8Array;
|
|
};
|
|
|
|
export type DesignGenerationTask = {
|
|
taskId: string;
|
|
workspaceId: string;
|
|
conversationId: string | null;
|
|
medium: DesignMedium;
|
|
status: DesignTaskStatus;
|
|
briefVersion: number;
|
|
briefSummary: string;
|
|
quoteId: string | null;
|
|
quotedDesignPoints: number | null;
|
|
failureCode: string | null;
|
|
resultAssets: DesignAsset[];
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
};
|
|
|
|
export type DesignGenerationTaskUpdatedEvent = {
|
|
id: string;
|
|
type: 'design.generation_task.updated';
|
|
workspaceId: string;
|
|
workspaceViewRevision: number;
|
|
generationTask: DesignGenerationTask;
|
|
};
|
|
|
|
export type DesignConversationSnapshotEvent = {
|
|
id: string;
|
|
type: 'design.conversation.snapshot';
|
|
workspaceId: string;
|
|
conversationId: string;
|
|
workspaceViewRevision: number;
|
|
conversation: DesignConversation;
|
|
generationTasks: DesignGenerationTask[];
|
|
};
|
|
|
|
export type DesignAssistantDeltaEvent = {
|
|
id: string;
|
|
type: 'design.assistant.delta';
|
|
workspaceId: string;
|
|
conversationId: string;
|
|
clientTurnId: string;
|
|
turnRevision: number;
|
|
chunkIndex: number;
|
|
delta: string;
|
|
};
|
|
|
|
export type DesignWorkspaceEvent =
|
|
| DesignGenerationTaskUpdatedEvent
|
|
| DesignConversationSnapshotEvent
|
|
| DesignAssistantDeltaEvent;
|
|
|
|
export type DesignWorkspaceBootstrap = {
|
|
capabilities: DesignCapabilities;
|
|
workspaces: DesignWorkspaceSummary[];
|
|
};
|
|
|
|
export type DesignCreateWorkspaceInput = {
|
|
clientWorkspaceId: string;
|
|
title: string;
|
|
};
|
|
|
|
export type DesignCreateConversationInput = {
|
|
workspaceId: string;
|
|
clientConversationId: string;
|
|
title: string;
|
|
};
|
|
|
|
export type DesignRenameWorkspaceInput = {
|
|
workspaceId: string;
|
|
title: string;
|
|
};
|
|
|
|
export type DesignSubmitMessageInput = {
|
|
workspaceId: string;
|
|
conversationId: string;
|
|
clientTurnId: string;
|
|
expectedTurnRevision: number;
|
|
message: string;
|
|
attachmentAssetIds?: string[];
|
|
};
|
|
|
|
export type DesignConfirmGenerationInput = {
|
|
workspaceId: string;
|
|
conversationId: string;
|
|
clientTurnId: string;
|
|
expectedTurnRevision: number;
|
|
quoteId: string;
|
|
};
|
|
|
|
export function designAssetContentPath(workspaceId: string, assetId: string): string {
|
|
return `${IMAGE_WORKSPACE_API_PATH}/workspaces/${encodeURIComponent(workspaceId)}/assets/${encodeURIComponent(assetId)}/content`;
|
|
}
|
|
|
|
export function designAssetDownloadPath(workspaceId: string, assetId: string): string {
|
|
return `${IMAGE_WORKSPACE_API_PATH}/workspaces/${encodeURIComponent(workspaceId)}/assets/${encodeURIComponent(assetId)}/download`;
|
|
}
|