From e1d396dbf2bd4d04b516d301486e9fc83c50911a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=BB=9D=E5=B0=98?= <237809796@qq.com>
Date: Wed, 17 Jun 2026 03:17:30 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=20F-05=E5=A4=9A=E6=A8=A1?=
=?UTF-8?q?=E6=80=81Phase2b=E5=89=8D=E7=AB=AF(=E5=9B=BE=E7=89=87=E7=B2=98?=
=?UTF-8?q?=E8=B4=B4/=E6=8B=96=E6=8B=BD+=E6=B8=B2=E6=9F=93+parts=E9=80=8F?=
=?UTF-8?q?=E4=BC=A0=C2=B7=E4=BF=9D=E7=95=99=E8=99=9A=E6=8B=9F=E6=BB=9A?=
=?UTF-8?q?=E5=8A=A8)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/api/types.ts | 26 +++
src/components/AiChat.vue | 258 ++++++++++++++++++++++-
src/composables/ai/useAiConversations.ts | 5 +
src/composables/ai/useAiSend.ts | 38 +++-
src/i18n/en/aiChat.ts | 7 +
src/i18n/zh-CN/aiChat.ts | 8 +
src/stores/ai.ts | 5 +-
7 files changed, 328 insertions(+), 19 deletions(-)
diff --git a/src/api/types.ts b/src/api/types.ts
index 6ec5f14..c0aff93 100644
--- a/src/api/types.ts
+++ b/src/api/types.ts
@@ -278,6 +278,25 @@ export type AiChatEvent = ({
conversation_id?: string
}
+/**
+ * 多模态消息内容片(F-260614-05 Phase 2b 前端类型,对齐后端 df-ai-core ContentPart)。
+ *
+ * 后端 serde:`#[serde(tag = "type", rename_all = "snake_case")]`,
+ * 前端 discriminator 用字面量 `type` 字段('text' | 'image'),与后端 wire 格式严格对齐。
+ * Image 片:url / base64 二选一(base64 非空时 url 忽略),media_type 仅 base64 模式必填。
+ */
+export type ContentPart =
+ | { type: 'text'; text: string }
+ | {
+ type: 'image'
+ url?: string | null
+ base64?: string | null
+ /** base64 模式必填(image/png|jpeg|webp|gif);url 模式可空 */
+ media_type?: string | null
+ /** 可选 alt(vision 模型/降级文本时用) */
+ alt?: string | null
+ }
+
/** AI 消息(前端渲染用,isError 标记错误消息用于差异化样式) */
export interface AiMessage {
id: string
@@ -287,6 +306,13 @@ export interface AiMessage {
toolCalls?: AiToolCallInfo[]
/** 生成该消息的 model(仅 assistant 消息,历史消息从 DB 读) */
model?: string
+ /**
+ * 多模态内容片(F-260614-05 Phase 2b)。
+ * undefined/空=纯文本消息(content 即全部载荷);非空含 Image 片=多模态消息,
+ * 用户气泡内渲染 (base64 data URI 或 url)。仅 user 消息有(parts 来自粘贴/拖拽输入)。
+ * 历史消息从 DB JSON 反序列化时透传(useAiConversations switchConversation)。
+ */
+ parts?: ContentPart[]
timestamp: number
}
diff --git a/src/components/AiChat.vue b/src/components/AiChat.vue
index b7c512e..0c75145 100644
--- a/src/components/AiChat.vue
+++ b/src/components/AiChat.vue
@@ -410,6 +410,20 @@