Fix file uploads: include content in messages, update README, remove secrets
- File uploads now read content and include in AI context - Truncate files over 50KB to avoid token limits - Updated README with JSON config documentation - Removed secrets.json from git tracking
This commit is contained in:
@@ -550,15 +550,18 @@ async function handleFileSelect(e) {
|
||||
|
||||
for (const file of files) {
|
||||
try {
|
||||
const uploaded = await api.uploadFile(file);
|
||||
// Read file content
|
||||
const content = await readFileContent(file);
|
||||
|
||||
state.files.push({
|
||||
id: uploaded.id,
|
||||
id: file.name + '-' + Date.now(),
|
||||
name: file.name,
|
||||
type: file.type,
|
||||
size: file.size
|
||||
size: file.size,
|
||||
content: content
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Failed to upload file:', file.name, err);
|
||||
console.error('Failed to read file:', file.name, err);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -566,6 +569,15 @@ async function handleFileSelect(e) {
|
||||
e.target.value = '';
|
||||
}
|
||||
|
||||
function readFileContent(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => resolve(reader.result);
|
||||
reader.onerror = reject;
|
||||
reader.readAsText(file);
|
||||
});
|
||||
}
|
||||
|
||||
function renderFilesPreview() {
|
||||
const container = document.getElementById('files-preview');
|
||||
if (!container) return;
|
||||
@@ -663,8 +675,16 @@ async function handleSendMessage() {
|
||||
function buildMessageContent(text, files) {
|
||||
if (!files.length) return text;
|
||||
|
||||
const fileDescriptions = files.map(f => `[Attached: ${f.name}]`).join('\n');
|
||||
return `${text}\n\n${fileDescriptions}`;
|
||||
const fileContents = files.map(f => {
|
||||
const maxLen = 50000; // Limit file content length
|
||||
const content = f.content || '[File content not available]';
|
||||
const truncated = content.length > maxLen
|
||||
? content.substring(0, maxLen) + '\n... [truncated]'
|
||||
: content;
|
||||
return `--- ${f.name} ---\n${truncated}\n--- end of ${f.name} ---`;
|
||||
}).join('\n\n');
|
||||
|
||||
return `${text}\n\n${fileContents}`;
|
||||
}
|
||||
|
||||
function updateLastMessage(content) {
|
||||
|
||||
Reference in New Issue
Block a user