d7d98acfd4
切换画布 Agent 与通用 LLM 代理到 VectorEngine gpt-5.4-mini。 为画布 Agent 注入上一轮生成结果并默认承接上一张图编辑。 补齐规范图工具分流、规范展板 prompt 要求和 JSON 残片回复兜底。 同步前后端契约、测试脚本、环境示例和项目文档。
172 lines
4.3 KiB
TypeScript
172 lines
4.3 KiB
TypeScript
// 画布Agent对话契约:会话元数据存 SpacetimeDB,消息正文整体存 OSS(editor-agent/{conversationId}.json)。
|
||
|
||
export const EDITOR_AGENT_MAX_ATTACHMENTS = 9;
|
||
export const EDITOR_AGENT_TITLE_MAX_CHARS = 20;
|
||
export const EDITOR_AGENT_DEFAULT_CONVERSATION_TITLE = '新对话';
|
||
export const EDITOR_AGENT_MESSAGES_DOCUMENT_VERSION = 1;
|
||
|
||
export type EditorAgentStage =
|
||
| 'idle'
|
||
| 'thinking'
|
||
| 'responding'
|
||
| 'generating'
|
||
| 'completed'
|
||
| 'failed';
|
||
|
||
export type EditorAgentMessageRole = 'user' | 'assistant';
|
||
|
||
export type EditorAgentMessageKind = 'chat' | 'stage' | 'error';
|
||
|
||
export type EditorAgentMessageStatus =
|
||
| 'streaming'
|
||
| 'generating'
|
||
| 'completed'
|
||
| 'failed'
|
||
| 'stopped';
|
||
|
||
export type EditorAgentAttachmentSource = 'canvas_resource' | 'library_asset';
|
||
|
||
export type EditorAgentToolName =
|
||
| 'generate_image'
|
||
| 'edit_image'
|
||
| 'generate_character'
|
||
| 'generate_icon_spritesheet'
|
||
| 'generate_ui_design';
|
||
|
||
export interface EditorAgentAttachmentRef {
|
||
source: EditorAgentAttachmentSource;
|
||
referenceId: string;
|
||
objectKey?: string | null;
|
||
imageSrc: string;
|
||
thumbnailSrc?: string | null;
|
||
label?: string | null;
|
||
width?: number | null;
|
||
height?: number | null;
|
||
}
|
||
|
||
export interface EditorAgentGeneratedImage {
|
||
resourceId: string | null;
|
||
objectKey?: string | null;
|
||
assetObjectId?: string | null;
|
||
imageSrc: string;
|
||
thumbnailSrc: string | null;
|
||
width: number | null;
|
||
height: number | null;
|
||
}
|
||
|
||
export type EditorAgentGenerationStatus = 'generating' | 'completed' | 'failed';
|
||
|
||
export interface EditorAgentGenerationRecord {
|
||
toolCallId: string;
|
||
toolName: EditorAgentToolName;
|
||
summary?: string | null;
|
||
taskId: string | null;
|
||
status: EditorAgentGenerationStatus;
|
||
model: string | null;
|
||
images: EditorAgentGeneratedImage[];
|
||
error?: string | null;
|
||
}
|
||
|
||
export interface EditorAgentMessage {
|
||
id: string;
|
||
role: EditorAgentMessageRole;
|
||
kind: EditorAgentMessageKind;
|
||
text: string;
|
||
attachments: EditorAgentAttachmentRef[];
|
||
generations: EditorAgentGenerationRecord[];
|
||
status: EditorAgentMessageStatus;
|
||
createdAt: string;
|
||
}
|
||
|
||
export interface EditorAgentConversationSummary {
|
||
conversationId: string;
|
||
projectId: string;
|
||
title: string;
|
||
createdAt: string;
|
||
updatedAt: string;
|
||
}
|
||
|
||
export interface EditorAgentConversationDetail
|
||
extends EditorAgentConversationSummary {
|
||
messages: EditorAgentMessage[];
|
||
}
|
||
|
||
export interface EditorAgentConversationMessagesDocument {
|
||
version: number;
|
||
conversationId: string;
|
||
messages: EditorAgentMessage[];
|
||
}
|
||
|
||
export interface CreateEditorAgentConversationRequest {
|
||
title?: string | null;
|
||
}
|
||
|
||
export interface EditorAgentConversationListResponse {
|
||
conversations: EditorAgentConversationSummary[];
|
||
}
|
||
|
||
export interface EditorAgentConversationResponse {
|
||
conversation: EditorAgentConversationDetail;
|
||
}
|
||
|
||
export interface StreamEditorAgentMessageRequest {
|
||
clientMessageId: string;
|
||
text: string;
|
||
attachments?: EditorAgentAttachmentRef[];
|
||
}
|
||
|
||
export interface EditorAgentStageEvent {
|
||
conversationId: string;
|
||
stage: EditorAgentStage;
|
||
}
|
||
|
||
export interface EditorAgentMessageDeltaEvent {
|
||
conversationId: string;
|
||
messageId: string;
|
||
role: EditorAgentMessageRole;
|
||
kind: EditorAgentMessageKind;
|
||
textDelta: string;
|
||
}
|
||
|
||
export interface EditorAgentToolEvent {
|
||
conversationId: string;
|
||
messageId: string;
|
||
toolCallId: string;
|
||
toolName: EditorAgentToolName;
|
||
summary?: string | null;
|
||
taskId?: string | null;
|
||
model?: string | null;
|
||
status?: EditorAgentGenerationStatus | null;
|
||
error?: string | null;
|
||
}
|
||
|
||
export interface EditorAgentGenerationResultEvent {
|
||
conversationId: string;
|
||
messageId: string;
|
||
toolCallId: string;
|
||
toolName: EditorAgentToolName;
|
||
model: string | null;
|
||
images: EditorAgentGeneratedImage[];
|
||
}
|
||
|
||
export interface EditorAgentErrorEvent {
|
||
conversationId: string | null;
|
||
code: string;
|
||
message: string;
|
||
recoverable: boolean;
|
||
}
|
||
|
||
export interface EditorAgentDoneEvent {
|
||
conversationId: string;
|
||
title: string | null;
|
||
}
|
||
|
||
export type EditorAgentSseEvent =
|
||
| { event: 'stage'; data: EditorAgentStageEvent }
|
||
| { event: 'message_delta'; data: EditorAgentMessageDeltaEvent }
|
||
| { event: 'tool_started'; data: EditorAgentToolEvent }
|
||
| { event: 'tool_completed'; data: EditorAgentToolEvent }
|
||
| { event: 'generation_result'; data: EditorAgentGenerationResultEvent }
|
||
| { event: 'error'; data: EditorAgentErrorEvent }
|
||
| { event: 'done'; data: EditorAgentDoneEvent };
|