需求:设计 Agent 对话与确认生成的回复需要实时展示。 实现:统一通过 Agent Gateway 提交 Turn,接收并去重 assistant delta,以 canonical Workspace 收口,并修复跨项目旧请求回写竞态。
153 lines
3.8 KiB
TypeScript
153 lines
3.8 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;
|
|
turnRevision: number;
|
|
viewRevision: number;
|
|
phase: DesignWorkspacePhase;
|
|
brief: DesignBrief;
|
|
updatedAt: string;
|
|
};
|
|
|
|
export type DesignWorkspace = DesignWorkspaceSummary & {
|
|
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 DesignGenerationTask = {
|
|
taskId: string;
|
|
workspaceId: string;
|
|
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 DesignGenerationTasksSnapshotEvent = {
|
|
id: string;
|
|
type: 'design.generation_tasks.snapshot';
|
|
workspaceId: string;
|
|
workspaceViewRevision: number;
|
|
workspace: DesignWorkspace;
|
|
generationTasks: DesignGenerationTask[];
|
|
};
|
|
|
|
export type DesignAssistantDeltaEvent = {
|
|
id: string;
|
|
type: 'design.assistant.delta';
|
|
workspaceId: string;
|
|
clientTurnId: string;
|
|
turnRevision: number;
|
|
chunkIndex: number;
|
|
delta: string;
|
|
};
|
|
|
|
export type DesignWorkspaceEvent =
|
|
| DesignGenerationTaskUpdatedEvent
|
|
| DesignGenerationTasksSnapshotEvent
|
|
| DesignAssistantDeltaEvent;
|
|
|
|
export type DesignWorkspaceBootstrap = {
|
|
capabilities: DesignCapabilities;
|
|
workspaces: DesignWorkspaceSummary[];
|
|
};
|
|
|
|
export type DesignCreateWorkspaceInput = {
|
|
clientWorkspaceId: string;
|
|
title: string;
|
|
};
|
|
|
|
export type DesignRenameWorkspaceInput = {
|
|
workspaceId: string;
|
|
title: string;
|
|
};
|
|
|
|
export type DesignSubmitMessageInput = {
|
|
workspaceId: string;
|
|
clientTurnId: string;
|
|
expectedTurnRevision: number;
|
|
message: string;
|
|
attachmentAssetIds?: string[];
|
|
};
|
|
|
|
export type DesignConfirmGenerationInput = {
|
|
workspaceId: 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`;
|
|
}
|