mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00
chore: remove debugging logs and tidy up misc stuff
This commit is contained in:
parent
f1bc15b3d5
commit
c4e86539c6
1 changed files with 10 additions and 60 deletions
|
@ -4,9 +4,9 @@ import { useRecoilValue, useSetRecoilState } from 'recoil';
|
|||
import { Constants, replaceSpecialVars } from 'librechat-data-provider';
|
||||
import type { AgentToolResources, TFile } from 'librechat-data-provider';
|
||||
import { useChatContext, useChatFormContext, useAddedChatContext } from '~/Providers';
|
||||
import useUpdateFiles from '~/hooks/Files/useUpdateFiles';
|
||||
import { useAuthContext } from '~/hooks/AuthContext';
|
||||
import { useGetFiles } from '~/data-provider';
|
||||
import useUpdateFiles from '~/hooks/Files/useUpdateFiles';
|
||||
import type { ExtendedFile } from '~/common';
|
||||
import store from '~/store';
|
||||
|
||||
|
@ -29,42 +29,27 @@ export default function useSubmitMessage() {
|
|||
const activeConvos = useRecoilValue(store.allConversationsSelector);
|
||||
const setActivePrompt = useSetRecoilState(store.activePromptByIndex(index));
|
||||
|
||||
// Create a fileMap for quick lookup
|
||||
const fileMap = useMemo(() => {
|
||||
const map: Record<string, TFile> = {};
|
||||
if (Array.isArray(allFiles)) {
|
||||
allFiles.forEach((file) => {
|
||||
if (file.file_id) {
|
||||
map[file.file_id] = file;
|
||||
}
|
||||
});
|
||||
}
|
||||
return map;
|
||||
}, [allFiles]);
|
||||
|
||||
// Convert toolResources to ExtendedFile objects for chat UI
|
||||
const convertToolResourcesToFiles = useCallback(
|
||||
(toolResources: AgentToolResources): ExtendedFile[] => {
|
||||
console.log('convertToolResourcesToFiles called with:', toolResources);
|
||||
console.log('Available fileMap keys:', Object.keys(fileMap));
|
||||
|
||||
const promptFiles: ExtendedFile[] = [];
|
||||
|
||||
Object.entries(toolResources).forEach(([toolResource, resource]) => {
|
||||
console.log(`Processing toolResource "${toolResource}":`, resource);
|
||||
if (resource?.file_ids) {
|
||||
console.log(`Found ${resource.file_ids.length} file_ids:`, resource.file_ids);
|
||||
resource.file_ids.forEach((fileId) => {
|
||||
const dbFile = fileMap[fileId];
|
||||
console.log(`Looking up fileId "${fileId}":`, dbFile ? 'FOUND' : 'NOT FOUND');
|
||||
if (dbFile) {
|
||||
console.log('Database file details:', {
|
||||
file_id: dbFile.file_id,
|
||||
filename: dbFile.filename,
|
||||
type: dbFile.type,
|
||||
bytes: dbFile.bytes,
|
||||
width: dbFile.width,
|
||||
height: dbFile.height,
|
||||
hasWidthHeight: !!(dbFile.width && dbFile.height),
|
||||
});
|
||||
const extendedFile = {
|
||||
file_id: dbFile.file_id,
|
||||
temp_file_id: dbFile.file_id,
|
||||
|
@ -79,21 +64,16 @@ export default function useSubmitMessage() {
|
|||
tool_resource: toolResource,
|
||||
preview: dbFile.type?.startsWith('image/') ? dbFile.filepath : undefined,
|
||||
};
|
||||
console.log('✅ Created ExtendedFile:', extendedFile);
|
||||
promptFiles.push(extendedFile);
|
||||
} else {
|
||||
console.warn(`File not found in fileMap: ${fileId}`);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log(`⚠️ No file_ids in resource "${toolResource}"`);
|
||||
console.warn(`No file_ids in resource "${toolResource}"`);
|
||||
}
|
||||
});
|
||||
|
||||
console.log(
|
||||
`convertToolResourcesToFiles returning ${promptFiles.length} files:`,
|
||||
promptFiles,
|
||||
);
|
||||
return promptFiles;
|
||||
},
|
||||
[fileMap],
|
||||
|
@ -122,13 +102,6 @@ export default function useSubmitMessage() {
|
|||
const rootIndex = addedIndex - 1;
|
||||
const clientTimestamp = new Date().toISOString();
|
||||
|
||||
console.log('submitMessage calling ask with:', {
|
||||
text: data.text?.substring(0, 100) + '...',
|
||||
toolResources: data.toolResources,
|
||||
overrideFiles: data.files,
|
||||
hasOverrideFiles: !!data.files?.length,
|
||||
});
|
||||
|
||||
ask(
|
||||
{
|
||||
text: data.text,
|
||||
|
@ -174,43 +147,20 @@ export default function useSubmitMessage() {
|
|||
|
||||
const submitPrompt = useCallback(
|
||||
(text: string, toolResources?: AgentToolResources) => {
|
||||
console.log('useSubmitMessage.submitPrompt called:', {
|
||||
text: text?.substring(0, 100) + '...',
|
||||
toolResources,
|
||||
hasToolResources: !!toolResources,
|
||||
autoSendPrompts,
|
||||
});
|
||||
|
||||
const parsedText = replaceSpecialVars({ text, user });
|
||||
|
||||
if (autoSendPrompts) {
|
||||
console.log('Auto-sending message with toolResources');
|
||||
// Auto-send: convert toolResources to files and pass both
|
||||
const promptFiles = toolResources ? convertToolResourcesToFiles(toolResources) : [];
|
||||
console.log('Auto-send converted files:', promptFiles);
|
||||
submitMessage({ text: parsedText, toolResources, files: promptFiles });
|
||||
return;
|
||||
}
|
||||
|
||||
// Manual mode: add files to chat state so they appear in UI
|
||||
if (toolResources) {
|
||||
console.log('Converting toolResources to files for manual mode...');
|
||||
const promptFiles = convertToolResourcesToFiles(toolResources);
|
||||
console.log('Converted files:', promptFiles);
|
||||
|
||||
// Add files to chat state so they appear in UI (same as AttachFileMenu)
|
||||
promptFiles.forEach((file, index) => {
|
||||
console.log(`Adding file ${index + 1}/${promptFiles.length}:`, {
|
||||
file_id: file.file_id,
|
||||
filename: file.filename,
|
||||
type: file.type,
|
||||
size: file.size,
|
||||
});
|
||||
promptFiles.forEach((file, _index) => {
|
||||
addFile(file);
|
||||
});
|
||||
console.log('All files added to chat state');
|
||||
} else {
|
||||
console.log('No toolResources provided');
|
||||
}
|
||||
|
||||
const currentText = methods.getValues('text');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue