Skip to content

Commit e201228

Browse files
authored
Merge pull request elizaOS#1205 from tobbelobb/main
fix: write summary file before trying to cache it
2 parents 78dd9f1 + 5cf3d7a commit e201228

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,5 @@ tsup.config.bundled_*.mjs
5252

5353
coverage
5454
.eslintcache
55+
56+
agent/content

packages/client-discord/src/actions/chat_with_attachments.ts

+31-10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
ModelClass,
1313
State,
1414
} from "@ai16z/eliza";
15+
import * as fs from 'fs';
16+
1517
export const summarizationTemplate = `# Summarized so far (we are adding to this)
1618
{{currentSummary}}
1719
@@ -225,16 +227,35 @@ ${currentSummary.trim()}
225227
`;
226228
await callback(callbackData);
227229
} else if (currentSummary.trim()) {
228-
const summaryFilename = `content/summary_${Date.now()}`;
229-
await runtime.cacheManager.set(summaryFilename, currentSummary);
230-
// save the summary to a file
231-
await callback(
232-
{
233-
...callbackData,
234-
text: `I've attached the summary of the requested attachments as a text file.`,
235-
},
236-
[summaryFilename]
237-
);
230+
const summaryFilename = `content/summary_${Date.now()}.md`;
231+
232+
try {
233+
// Debug: Log before file operations
234+
console.log("Creating summary file:", {
235+
filename: summaryFilename,
236+
summaryLength: currentSummary.length
237+
});
238+
239+
// Write file directly first
240+
await fs.promises.writeFile(summaryFilename, currentSummary, 'utf8');
241+
console.log("File written successfully");
242+
243+
// Then cache it
244+
await runtime.cacheManager.set(summaryFilename, currentSummary);
245+
console.log("Cache set operation completed");
246+
247+
await callback(
248+
{
249+
...callbackData,
250+
text: `I've attached the summary of the requested attachments as a text file.`,
251+
},
252+
[summaryFilename]
253+
);
254+
console.log("Callback completed with summary file");
255+
} catch (error) {
256+
console.error("Error in file/cache process:", error);
257+
throw error;
258+
}
238259
} else {
239260
console.warn(
240261
"Empty response from chat with attachments action, skipping"

0 commit comments

Comments
 (0)