完善客户端模块与工作区能力
This commit is contained in:
@@ -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