fix(chat): hide text for ai image messages
This commit is contained in:
@@ -1,22 +1,3 @@
|
||||
/**
|
||||
* Chat 状态机:纯函数 + 数据加载
|
||||
*
|
||||
* 从 `chat-machine.ts` 抽出的"helpers"段:
|
||||
* - 翻页大小常量
|
||||
* - 仓库注入(接口类型 → 单例)
|
||||
* - DTO ↔ UiMessage 映射(纯函数 —— 可单测)
|
||||
* - `readAndSyncHistory()` —— local → network → save network to local 3 步
|
||||
*
|
||||
* 设计目标:
|
||||
* - helpers 无 XState 依赖(可独立 import / 测试)
|
||||
* - actors 依赖 helpers(import)
|
||||
* - machine 依赖 actors,并复用 helpers 里的纯状态转换函数
|
||||
*
|
||||
* 历史:
|
||||
* - `readInitData` + `InitResult` 已删(被 2 个独立 helper 替换)
|
||||
* - `AuthStorage` import 已删(只 `readInitData` 用过,移到 `chatInit` actor 上层调用)
|
||||
*/
|
||||
|
||||
import type { UiMessage } from "@/data/dto/chat";
|
||||
import { chatRepository } from "@/data/repositories/chat_repository";
|
||||
import type { IChatRepository } from "@/data/repositories/interfaces";
|
||||
@@ -61,8 +42,12 @@ export function localMessagesToUi(
|
||||
): UiMessage[] {
|
||||
return records.map((m) => ({
|
||||
...(m.id ? { id: m.id } : {}),
|
||||
content: getAiMessageDisplayContent({
|
||||
content: m.content,
|
||||
isFromAI: m.role === "assistant",
|
||||
imageUrl: m.imageUrl,
|
||||
}),
|
||||
isFromAI: m.role === "assistant",
|
||||
date: messageDateFromCreatedAt(m.createdAt),
|
||||
...(m.imageUrl ? { imageUrl: m.imageUrl } : {}),
|
||||
...(m.isPrivate != null ? { isPrivate: m.isPrivate } : {}),
|
||||
@@ -77,6 +62,14 @@ function messageDateFromCreatedAt(createdAt: string): string {
|
||||
return todayString(parsed);
|
||||
}
|
||||
|
||||
function getAiMessageDisplayContent(input: {
|
||||
content: string;
|
||||
isFromAI: boolean;
|
||||
imageUrl?: string | null;
|
||||
}): string {
|
||||
return input.isFromAI && input.imageUrl ? "" : input.content;
|
||||
}
|
||||
|
||||
/**
|
||||
* ChatSendResponse → UiMessage(纯函数)
|
||||
* - 业务事实:后端响应就是 AI 的回复
|
||||
@@ -85,8 +78,12 @@ function messageDateFromCreatedAt(createdAt: string): string {
|
||||
export function sendResponseToUiMessage(response: ChatSendResponse): UiMessage {
|
||||
return {
|
||||
...(response.messageId ? { id: response.messageId } : {}),
|
||||
content: getAiMessageDisplayContent({
|
||||
content: response.reply,
|
||||
isFromAI: true,
|
||||
imageUrl: response.imageUrl,
|
||||
}),
|
||||
isFromAI: true,
|
||||
date: todayString(new Date(response.timestamp)),
|
||||
...(response.imageUrl ? { imageUrl: response.imageUrl } : {}),
|
||||
...(response.showUpgrade && response.imageUrl
|
||||
|
||||
@@ -243,6 +243,7 @@ export const chatMachine = setup({
|
||||
if (last?.isFromAI && !last.imageUrl) {
|
||||
messages[messages.length - 1] = {
|
||||
...last,
|
||||
content: "",
|
||||
imageUrl: event.imageUrl,
|
||||
};
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user