anything-llm/server/utils/agents/aibitat/plugins/file-history.js
Timothy Carambat a5bb77f97a
Agent support for @agent default agent inside workspace chat (#1093)
V1 of agent support via built-in `@agent` that can be invoked alongside normal workspace RAG chat.
2024-04-16 10:50:10 -07:00

38 lines
857 B
JavaScript

const fs = require("fs");
const path = require("path");
/**
* Plugin to save chat history to a json file
*/
const fileHistory = {
name: "file-history-plugin",
startupConfig: {
params: {},
},
plugin: function ({
filename = `history/chat-history-${new Date().toISOString()}.json`,
} = {}) {
return {
name: this.name,
setup(aibitat) {
const folderPath = path.dirname(filename);
// get path from filename
if (folderPath) {
fs.mkdirSync(folderPath, { recursive: true });
}
aibitat.onMessage(() => {
const content = JSON.stringify(aibitat.chats, null, 2);
fs.writeFile(filename, content, (err) => {
if (err) {
console.error(err);
}
});
});
},
};
},
};
module.exports = { fileHistory };