Skip to content

[Feat]: file attachments support for chat component #1893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: feat/assistant
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,37 @@ export const ChatEventHandlerControl = eventHandlerControl(ChatEventOptions);
export function addSystemPromptToHistory(
conversationHistory: ChatMessage[],
systemPrompt: string
): Array<{ role: string; content: string; timestamp: number }> {
): Array<{ role: string; content: string; timestamp: number; attachments?: any[] }> {
// Format conversation history for use in queries
const formattedHistory = conversationHistory.map(msg => ({
role: msg.role,
content: msg.text,
timestamp: msg.timestamp
}));
const formattedHistory = conversationHistory.map(msg => {
const baseMessage = {
role: msg.role,
content: msg.text,
timestamp: msg.timestamp
};

// Include attachment metadata if present (for API calls and external integrations)
if (msg.attachments && msg.attachments.length > 0) {
return {
...baseMessage,
attachments: msg.attachments.map(att => ({
id: att.id,
type: att.type,
name: att.name,
contentType: att.contentType,
// Include content for images (base64 data URLs are useful for APIs)
...(att.type === "image" && att.content && {
content: att.content.map(c => ({
type: c.type,
...(c.type === "image" && { image: c.image })
}))
})
}))
};
}

return baseMessage;
});

// Create system message (always exists since we have default)
const systemMessage = [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from "react";
import { ChatProvider } from "./context/ChatContext";
import { ChatCoreMain } from "./ChatCoreMain";
import { ChatCoreProps } from "../types/chatTypes";
import { TooltipProvider } from "@radix-ui/react-tooltip";

// ============================================================================
// CHAT CORE - THE SHARED FOUNDATION
Expand All @@ -18,14 +19,16 @@ export function ChatCore({
onEvent
}: ChatCoreProps) {
return (
<ChatProvider storage={storage}>
<ChatCoreMain
messageHandler={messageHandler}
<TooltipProvider>
<ChatProvider storage={storage}>
<ChatCoreMain
messageHandler={messageHandler}
placeholder={placeholder}
onMessageUpdate={onMessageUpdate}
onConversationUpdate={onConversationUpdate}
onEvent={onEvent}
/>
</ChatProvider>
onEvent={onEvent}
/>
</ChatProvider>
</TooltipProvider>
);
}
Loading
Loading