完善客户端模块与工作区能力
This commit is contained in:
@@ -10,6 +10,7 @@ import type {
|
||||
DesignCreateWorkspaceInput,
|
||||
DesignGenerationQuote,
|
||||
DesignGenerationTask,
|
||||
DesignMessage,
|
||||
DesignMedium,
|
||||
DesignRenameWorkspaceInput,
|
||||
DesignSubmitMessageInput,
|
||||
@@ -138,6 +139,14 @@ function messageHash(value: unknown): string {
|
||||
return createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
||||
}
|
||||
|
||||
function latestMessagePreview(messages: DesignMessage[]): string | null {
|
||||
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
||||
const preview = messages[index]?.text.replace(/\s+/gu, ' ').trim();
|
||||
if (preview) return preview;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function detectMedium(message: string): DesignMedium {
|
||||
return /视频|动画|动效|镜头|转场/.test(message) ? 'video' : 'image';
|
||||
}
|
||||
@@ -776,7 +785,10 @@ export class LocalImageWorkspace implements DesignWorkspaceModule {
|
||||
messages: _messages,
|
||||
...summary
|
||||
} = conversation;
|
||||
return clone(summary);
|
||||
return clone({
|
||||
...summary,
|
||||
latestMessagePreview: latestMessagePreview(conversation.messages),
|
||||
});
|
||||
}
|
||||
|
||||
private conversationView(conversation: PersistedConversation): DesignConversation {
|
||||
@@ -785,6 +797,9 @@ export class LocalImageWorkspace implements DesignWorkspaceModule {
|
||||
requestHashes: _requestHashes,
|
||||
...view
|
||||
} = conversation;
|
||||
return clone(view);
|
||||
return clone({
|
||||
...view,
|
||||
latestMessagePreview: latestMessagePreview(conversation.messages),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ type ServerConversationSummary = {
|
||||
workspace_id: string;
|
||||
agent_session_id: string | null;
|
||||
title: string;
|
||||
latest_message_preview?: string | null;
|
||||
turn_revision: number;
|
||||
phase: DesignConversationSummary['phase'];
|
||||
brief: ServerBrief;
|
||||
@@ -270,6 +271,19 @@ function mapWorkspace(workspace: ServerWorkspace): DesignWorkspace {
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeMessagePreview(value: string | null | undefined): string | null {
|
||||
const preview = value?.replace(/\s+/gu, ' ').trim();
|
||||
return preview || null;
|
||||
}
|
||||
|
||||
function latestServerMessagePreview(messages: ServerMessage[]): string | null {
|
||||
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
||||
const preview = normalizeMessagePreview(messages[index]?.text);
|
||||
if (preview) return preview;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function mapConversationSummary(
|
||||
conversation: ServerConversationSummary,
|
||||
): DesignConversationSummary {
|
||||
@@ -277,6 +291,9 @@ function mapConversationSummary(
|
||||
conversationId: conversation.conversation_id,
|
||||
workspaceId: conversation.workspace_id,
|
||||
title: conversation.title,
|
||||
latestMessagePreview: normalizeMessagePreview(
|
||||
conversation.latest_message_preview,
|
||||
) ?? normalizeMessagePreview(conversation.brief.summary),
|
||||
turnRevision: conversation.turn_revision,
|
||||
phase: conversation.phase,
|
||||
brief: mapBrief(conversation.brief),
|
||||
@@ -286,18 +303,22 @@ function mapConversationSummary(
|
||||
}
|
||||
|
||||
function mapConversation(conversation: ServerConversation): DesignConversation {
|
||||
const messages = conversation.messages.map((message, index) => ({
|
||||
id: `${conversation.conversation_id}:${message.turn_revision}:${message.role}:${index}`,
|
||||
role: message.role,
|
||||
kind: message.kind,
|
||||
text: message.text,
|
||||
quickReplies: message.quick_replies,
|
||||
generationQuote: mapQuote(message.generation_quote),
|
||||
turnRevision: message.turn_revision,
|
||||
createdAt: message.created_at,
|
||||
}));
|
||||
return {
|
||||
...mapConversationSummary(conversation),
|
||||
messages: conversation.messages.map((message, index) => ({
|
||||
id: `${conversation.conversation_id}:${message.turn_revision}:${message.role}:${index}`,
|
||||
role: message.role,
|
||||
kind: message.kind,
|
||||
text: message.text,
|
||||
quickReplies: message.quick_replies,
|
||||
generationQuote: mapQuote(message.generation_quote),
|
||||
turnRevision: message.turn_revision,
|
||||
createdAt: message.created_at,
|
||||
})),
|
||||
latestMessagePreview: latestServerMessagePreview(messages)
|
||||
?? normalizeMessagePreview(conversation.latest_message_preview)
|
||||
?? normalizeMessagePreview(conversation.brief.summary),
|
||||
messages,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user