feat(web): support image messages in pico chat (#2299)

This commit is contained in:
wenjie authored and GitHub committed 2026-04-03 14:15:20 +08:00
1 parent f3ad5d9305
commit f2a19ab947
21 files changed
+1009 -79

No files matched your search

+35 -4
View File
@@ -18,7 +18,11 @@ import {
normalizeWsUrlForBrowser,
} from "@/features/chat/websocket"
import i18n from "@/i18n"
import { getChatState, updateChatStore } from "@/store/chat"
import {
type ChatAttachment,
getChatState,
updateChatStore,
} from "@/store/chat"
import { type GatewayState, gatewayAtom } from "@/store/gateway"
const store = getDefaultStore()
@@ -324,19 +328,43 @@ export async function hydrateActiveSession() {
return hydratePromise
}
export function sendChatMessage(content: string) {
interface SendChatMessageInput {
content: string
attachments?: ChatAttachment[]
}
export function sendChatMessage({
content,
attachments = [],
}: SendChatMessageInput) {
if (!wsRef || wsRef.readyState !== WebSocket.OPEN) {
console.warn("WebSocket not connected")
return false
}
const normalizedContent = content.trim()
const normalizedAttachments = attachments
.filter((attachment) => attachment.type === "image" && attachment.url)
.map((attachment) => ({ ...attachment }))
if (!normalizedContent && normalizedAttachments.length === 0) {
return false
}
const socket = wsRef
const id = `msg-${++msgIdCounter}-${Date.now()}`
updateChatStore((prev) => ({
messages: [
...prev.messages,
{ id, role: "user", content, timestamp: Date.now() },
{
id,
role: "user",
content: normalizedContent,
attachments:
normalizedAttachments.length > 0 ? normalizedAttachments : undefined,
timestamp: Date.now(),
},
],
isTyping: true,
}))
@@ -346,7 +374,10 @@ export function sendChatMessage(content: string) {
JSON.stringify({
type: "message.send",
id,
payload: { content },
payload: {
content: normalizedContent,
media: normalizedAttachments.map((attachment) => attachment.url),
},
}),
)
return true