Skip to content

Commit 7ced44d

Browse files
fengju02134pmtong
andauthored
Add camel log upload and organize files by source type (#1548)
Co-authored-by: 4pmtong <web_chentong@163.com>
1 parent eacda32 commit 7ced44d

3 files changed

Lines changed: 25 additions & 15 deletions

File tree

electron/main/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,6 @@ function registerIpcHandlers() {
18301830

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

18351834
return {
18361835
success: true,

src/store/chatStore.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ interface GeneratedUploadFile {
9696
path?: string;
9797
name?: string;
9898
isFolder?: boolean;
99+
relativePath?: string;
99100
source?: Exclude<UploadFileSource, 'user_attachment'>;
100101
}
101102

@@ -120,17 +121,21 @@ function buildUploadName(
120121
fileName: string,
121122
source: UploadFileSource,
122123
taskId: string,
123-
attachmentIndex: number
124+
attachmentIndex: number,
125+
relativePath?: string
124126
): string {
125127
if (source === 'camel_log') {
126-
return `camel_log_${taskId}__${fileName}`;
128+
if (relativePath) {
129+
return `camel_log/${relativePath}/${fileName}`;
130+
}
131+
return `camel_log/${fileName}`;
127132
}
128133

129134
if (source === 'user_attachment') {
130-
return `user_attachment_${attachmentIndex}__${fileName}`;
135+
return `user_attachment/${fileName}`;
131136
}
132137

133-
return fileName;
138+
return `project_output/${fileName}`;
134139
}
135140

136141
export function collectTaskUploadFiles(
@@ -139,13 +144,16 @@ export function collectTaskUploadFiles(
139144
pendingAttaches: File[] = [],
140145
taskId = 'unknown_task'
141146
): UploadCandidate[] {
142-
const uploadCandidates: Array<Omit<UploadCandidate, 'uploadName'>> = [];
147+
const uploadCandidates: Array<
148+
Omit<UploadCandidate, 'uploadName'> & { relativePath?: string }
149+
> = [];
143150

144151
for (const file of generatedFiles) {
145152
if (!file?.path || !file?.name || file.isFolder) continue;
146153
uploadCandidates.push({
147154
path: file.path,
148155
name: file.name,
156+
relativePath: file.relativePath,
149157
source: file.source === 'camel_log' ? 'camel_log' : 'project_output',
150158
});
151159
}
@@ -169,13 +177,15 @@ export function collectTaskUploadFiles(
169177
let attachmentIndex = 1;
170178
for (const file of uploadCandidates) {
171179
if (!uniqueCandidates.has(file.path)) {
180+
const { relativePath, ...rest } = file;
172181
uniqueCandidates.set(file.path, {
173-
...file,
182+
...rest,
174183
uploadName: buildUploadName(
175184
file.name,
176185
file.source,
177186
taskId,
178-
file.source === 'user_attachment' ? attachmentIndex++ : 0
187+
file.source === 'user_attachment' ? attachmentIndex++ : 0,
188+
relativePath
179189
),
180190
});
181191
}

test/unit/store/chatStore.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ describe('ChatStore - Core Functionality', () => {
127127
source: 'project_output',
128128
},
129129
{
130-
path: '/tmp/logs/agent.log',
130+
path: '/tmp/logs/ba4462e1/agent.log',
131131
name: 'agent.log',
132+
relativePath: 'ba4462e1',
132133
source: 'camel_log',
133134
},
134135
{
@@ -168,25 +169,25 @@ describe('ChatStore - Core Functionality', () => {
168169
{
169170
path: '/tmp/project/report.md',
170171
name: 'report.md',
171-
uploadName: 'report.md',
172+
uploadName: 'project_output/report.md',
172173
source: 'project_output',
173174
},
174175
{
175-
path: '/tmp/logs/agent.log',
176+
path: '/tmp/logs/ba4462e1/agent.log',
176177
name: 'agent.log',
177-
uploadName: 'camel_log_task-123__agent.log',
178+
uploadName: 'camel_log/ba4462e1/agent.log',
178179
source: 'camel_log',
179180
},
180181
{
181182
path: '/Users/test/Documents/brief.pdf',
182183
name: 'brief.pdf',
183-
uploadName: 'user_attachment_1__brief.pdf',
184+
uploadName: 'user_attachment/brief.pdf',
184185
source: 'user_attachment',
185186
},
186187
{
187188
path: '/Users/test/Documents/followup.csv',
188189
name: 'followup.csv',
189-
uploadName: 'user_attachment_2__followup.csv',
190+
uploadName: 'user_attachment/followup.csv',
190191
source: 'user_attachment',
191192
},
192193
]);
@@ -220,7 +221,7 @@ describe('ChatStore - Core Functionality', () => {
220221
{
221222
path: 'C:\\Users\\test\\Desktop\\notes.txt',
222223
name: 'notes.txt',
223-
uploadName: 'user_attachment_1__notes.txt',
224+
uploadName: 'user_attachment/notes.txt',
224225
source: 'user_attachment',
225226
},
226227
]);

0 commit comments

Comments
 (0)