Skip to content

Commit d318b7e

Browse files
committed
add file attachments support for chat component
1 parent 7c291df commit d318b7e

File tree

9 files changed

+518
-326
lines changed

9 files changed

+518
-326
lines changed

client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,37 @@ export const ChatEventHandlerControl = eventHandlerControl(ChatEventOptions);
8080
export function addSystemPromptToHistory(
8181
conversationHistory: ChatMessage[],
8282
systemPrompt: string
83-
): Array<{ role: string; content: string; timestamp: number }> {
83+
): Array<{ role: string; content: string; timestamp: number; attachments?: any[] }> {
8484
// Format conversation history for use in queries
85-
const formattedHistory = conversationHistory.map(msg => ({
86-
role: msg.role,
87-
content: msg.text,
88-
timestamp: msg.timestamp
89-
}));
85+
const formattedHistory = conversationHistory.map(msg => {
86+
const baseMessage = {
87+
role: msg.role,
88+
content: msg.text,
89+
timestamp: msg.timestamp
90+
};
91+
92+
// Include attachment metadata if present (for API calls and external integrations)
93+
if (msg.attachments && msg.attachments.length > 0) {
94+
return {
95+
...baseMessage,
96+
attachments: msg.attachments.map(att => ({
97+
id: att.id,
98+
type: att.type,
99+
name: att.name,
100+
contentType: att.contentType,
101+
// Include content for images (base64 data URLs are useful for APIs)
102+
...(att.type === "image" && att.content && {
103+
content: att.content.map(c => ({
104+
type: c.type,
105+
...(c.type === "image" && { image: c.image })
106+
}))
107+
})
108+
}))
109+
};
110+
}
111+
112+
return baseMessage;
113+
});
90114

91115
// Create system message (always exists since we have default)
92116
const systemMessage = [{

client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCore.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React from "react";
44
import { ChatProvider } from "./context/ChatContext";
55
import { ChatCoreMain } from "./ChatCoreMain";
66
import { ChatCoreProps } from "../types/chatTypes";
7+
import { TooltipProvider } from "@radix-ui/react-tooltip";
78

89
// ============================================================================
910
// CHAT CORE - THE SHARED FOUNDATION
@@ -18,14 +19,16 @@ export function ChatCore({
1819
onEvent
1920
}: ChatCoreProps) {
2021
return (
21-
<ChatProvider storage={storage}>
22-
<ChatCoreMain
23-
messageHandler={messageHandler}
22+
<TooltipProvider>
23+
<ChatProvider storage={storage}>
24+
<ChatCoreMain
25+
messageHandler={messageHandler}
2426
placeholder={placeholder}
2527
onMessageUpdate={onMessageUpdate}
2628
onConversationUpdate={onConversationUpdate}
27-
onEvent={onEvent}
28-
/>
29-
</ChatProvider>
29+
onEvent={onEvent}
30+
/>
31+
</ChatProvider>
32+
</TooltipProvider>
3033
);
3134
}

0 commit comments

Comments
 (0)