Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

Enhance Chat Context with File Management Features

Salman-Ahamed7d079c1671f9
diff --git a/packages/app/src/react/features/ai-chat/contexts/chat-context.tsx b/packages/app/src/react/features/ai-chat/contexts/chat-context.tsx
index ff7badd1..59e878de 100644
--- a/packages/app/src/react/features/ai-chat/contexts/chat-context.tsx
+++ b/packages/app/src/react/features/ai-chat/contexts/chat-context.tsx
@@ -1,13 +1,29 @@
+/* eslint-disable no-unused-vars */
import { ChatInputRef } from '@react/features/ai-chat/components/input';
+import { IMessageFile } from '@react/features/ai-chat/types/chat.types';
import { AgentDetails, AgentSettings } from '@react/shared/types/agent-data.types';
import { createContext, MutableRefObject } from 'react';
export interface IChatContext {
ref: { input?: MutableRefObject<ChatInputRef>; container?: MutableRefObject<HTMLDivElement> };
agent: { data?: AgentDetails; settings?: AgentSettings; loading: boolean };
+ files: {
+ isLoading: boolean;
+ errorMessage: string;
+ data: IMessageFile[];
+ addFiles: (newFiles: File[]) => Promise<void>;
+ removeFile: (index: number) => Promise<void>;
+ };
}
export const ChatContext = createContext<IChatContext>({
ref: { input: undefined, container: undefined },
agent: { data: undefined, settings: undefined, loading: false },
+ files: {
+ data: [],
+ isLoading: false,
+ errorMessage: '',
+ addFiles: async () => {},
+ removeFile: async () => {},
+ },
});
diff --git a/packages/app/src/react/features/ai-chat/contexts/index.new.tsx b/packages/app/src/react/features/ai-chat/contexts/index.new.tsx
index f3504cf9..93e12ddb 100644
--- a/packages/app/src/react/features/ai-chat/contexts/index.new.tsx
+++ b/packages/app/src/react/features/ai-chat/contexts/index.new.tsx
@@ -4,6 +4,7 @@ import { useAgent } from '@src/react/shared/hooks/agent';
import { FC, ReactNode, useMemo, useRef } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { useAgentSettings } from '../hooks/agent-settings';
+import { useAttachments } from '../hooks/use-attachments';
interface IProps {
children: ReactNode;
@@ -31,18 +32,22 @@ export const ChatContextProvider: FC<IProps> = ({ children }) => {
const { data: settingsData, isLoading: isAgentSettingsLoading } = useAgentSettings(agentId);
const agentSettings = settingsData?.settings;
+ const agentLoading = isAgentLoading || isAgentSettingsLoading;
+
+ // ============================================================================
+ // FILE UPLOAD MANAGEMENT
+ // ============================================================================
+
+ const files = useAttachments({ agentId, chatId: agentSettings?.lastConversationId });
// Memoize the store to avoid unnecessary re-renders
const values: IChatContext = useMemo(
() => ({
ref: { input: inputRef, container: containerRef },
- agent: {
- data: agent,
- settings: agentSettings,
- loading: isAgentLoading || isAgentSettingsLoading,
- },
+ agent: { data: agent, settings: agentSettings, loading: agentLoading },
+ files,
}),
- [inputRef, containerRef, agent, agentSettings, isAgentLoading, isAgentSettingsLoading],
+ [inputRef, containerRef, agent, agentSettings, agentLoading, files],
);
return <ChatContext.Provider value={values}>{children}</ChatContext.Provider>;
diff --git a/packages/app/src/react/features/ai-chat/hooks/use-attachments.ts b/packages/app/src/react/features/ai-chat/hooks/use-attachments.ts
index 6276809e..eee4ae8b 100644
--- a/packages/app/src/react/features/ai-chat/hooks/use-attachments.ts
+++ b/packages/app/src/react/features/ai-chat/hooks/use-attachments.ts
@@ -133,7 +133,7 @@ export const useAttachments = (props: IProps) => {
);
return {
- files,
+ data: files,
isLoading,
errorMessage,
diff --git a/packages/app/src/react/features/ai-chat/types/chat.types.ts b/packages/app/src/react/features/ai-chat/types/chat.types.ts
index 9e2f57f9..0aa0e1f5 100644
--- a/packages/app/src/react/features/ai-chat/types/chat.types.ts
+++ b/packages/app/src/react/features/ai-chat/types/chat.types.ts
@@ -45,11 +45,11 @@ export interface IMessageFile {
id: string; // Required ID for React keys and tracking
file: File; // The actual File object
metadata: {
- publicUrl?: string;
- fileType?: string;
key?: string;
- isUploading?: boolean;
+ fileType?: string;
+ publicUrl?: string;
previewUrl?: string;
+ isUploading?: boolean;
};
}