Skip to content
Merged
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
1 change: 0 additions & 1 deletion electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1830,7 +1830,6 @@ function registerIpcHandlers() {

// Read file content
const fileContent = await fsp.readFile(filePath);
// log.info('File read successfully:', filePath);

return {
success: true,
Expand Down
24 changes: 17 additions & 7 deletions src/store/chatStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ interface GeneratedUploadFile {
path?: string;
name?: string;
isFolder?: boolean;
relativePath?: string;
source?: Exclude<UploadFileSource, 'user_attachment'>;
}

Expand All @@ -120,17 +121,21 @@ function buildUploadName(
fileName: string,
source: UploadFileSource,
taskId: string,
attachmentIndex: number
attachmentIndex: number,
relativePath?: string
): string {
if (source === 'camel_log') {
return `camel_log_${taskId}__${fileName}`;
if (relativePath) {
return `camel_log/${relativePath}/${fileName}`;
}
return `camel_log/${fileName}`;
}

if (source === 'user_attachment') {
return `user_attachment_${attachmentIndex}__${fileName}`;
return `user_attachment/${fileName}`;
}

return fileName;
return `project_output/${fileName}`;
}

export function collectTaskUploadFiles(
Expand All @@ -139,13 +144,16 @@ export function collectTaskUploadFiles(
pendingAttaches: File[] = [],
taskId = 'unknown_task'
): UploadCandidate[] {
const uploadCandidates: Array<Omit<UploadCandidate, 'uploadName'>> = [];
const uploadCandidates: Array<
Omit<UploadCandidate, 'uploadName'> & { relativePath?: string }
> = [];

for (const file of generatedFiles) {
if (!file?.path || !file?.name || file.isFolder) continue;
uploadCandidates.push({
path: file.path,
name: file.name,
relativePath: file.relativePath,
source: file.source === 'camel_log' ? 'camel_log' : 'project_output',
});
}
Expand All @@ -169,13 +177,15 @@ export function collectTaskUploadFiles(
let attachmentIndex = 1;
for (const file of uploadCandidates) {
if (!uniqueCandidates.has(file.path)) {
const { relativePath, ...rest } = file;
uniqueCandidates.set(file.path, {
...file,
...rest,
uploadName: buildUploadName(
file.name,
file.source,
taskId,
file.source === 'user_attachment' ? attachmentIndex++ : 0
file.source === 'user_attachment' ? attachmentIndex++ : 0,
relativePath
),
});
}
Expand Down
15 changes: 8 additions & 7 deletions test/unit/store/chatStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ describe('ChatStore - Core Functionality', () => {
source: 'project_output',
},
{
path: '/tmp/logs/agent.log',
path: '/tmp/logs/ba4462e1/agent.log',
name: 'agent.log',
relativePath: 'ba4462e1',
source: 'camel_log',
},
{
Expand Down Expand Up @@ -168,25 +169,25 @@ describe('ChatStore - Core Functionality', () => {
{
path: '/tmp/project/report.md',
name: 'report.md',
uploadName: 'report.md',
uploadName: 'project_output/report.md',
source: 'project_output',
},
{
path: '/tmp/logs/agent.log',
path: '/tmp/logs/ba4462e1/agent.log',
name: 'agent.log',
uploadName: 'camel_log_task-123__agent.log',
uploadName: 'camel_log/ba4462e1/agent.log',
source: 'camel_log',
},
{
path: '/Users/test/Documents/brief.pdf',
name: 'brief.pdf',
uploadName: 'user_attachment_1__brief.pdf',
uploadName: 'user_attachment/brief.pdf',
source: 'user_attachment',
},
{
path: '/Users/test/Documents/followup.csv',
name: 'followup.csv',
uploadName: 'user_attachment_2__followup.csv',
uploadName: 'user_attachment/followup.csv',
source: 'user_attachment',
},
]);
Expand Down Expand Up @@ -220,7 +221,7 @@ describe('ChatStore - Core Functionality', () => {
{
path: 'C:\\Users\\test\\Desktop\\notes.txt',
name: 'notes.txt',
uploadName: 'user_attachment_1__notes.txt',
uploadName: 'user_attachment/notes.txt',
source: 'user_attachment',
},
]);
Expand Down
Loading