Files
anything-llm/server/utils/agents/aibitat/plugins/save-file-browser.js
Timothy Carambat 96965b3f30 Intelligent Skill Selection (#5236)
* Beta Intelligent Tooling
todo: Agent Skill banner warning when tool # is high or % of content window?

* forgot files

* add UI controls and maxToolCallStack setting

* update docs link

* ISS i18n (#5237)

i18n
2026-03-19 10:06:37 -07:00

96 lines
3.3 KiB
JavaScript

const { Deduplicator } = require("../utils/dedupe");
const saveFileInBrowser = {
name: "save-file-to-browser",
startupConfig: {
params: {},
},
plugin: function () {
return {
name: this.name,
setup(aibitat) {
// List and summarize the contents of files that are embedded in the workspace
aibitat.function({
super: aibitat,
tracker: new Deduplicator(),
name: this.name,
description:
"Download or export content as a file. Save text, code, data, or conversation content to a downloadable file. Use when the user wants to save, download, or export something as a file.",
examples: [
{
prompt: "Download that as a file",
call: JSON.stringify({
file_content: "<content to save>",
filename: "download.txt",
}),
},
{
prompt: "Save that code to a file",
call: JSON.stringify({
file_content: "<code content>",
filename: "code.js",
}),
},
{
prompt: "Save me that to a file named 'output'",
call: JSON.stringify({
file_content: "<content of the file>",
filename: "output.txt",
}),
},
],
parameters: {
$schema: "http://json-schema.org/draft-07/schema#",
type: "object",
properties: {
file_content: {
type: "string",
description: "The content of the file that will be saved.",
},
filename: {
type: "string",
description:
"filename to save the file as with extension. Extension should be plaintext file extension.",
},
},
additionalProperties: false,
},
handler: async function ({ file_content = "", filename }) {
try {
const { isDuplicate, reason } = this.tracker.isDuplicate(
this.name,
{ file_content, filename }
);
if (isDuplicate) {
this.super.handlerProps.log(
`${this.name} was called, but exited early because ${reason}.`
);
return `${filename} file has been saved successfully!`;
}
this.super.socket.send("fileDownload", {
filename,
b64Content:
"data:text/plain;base64," +
Buffer.from(file_content, "utf8").toString("base64"),
});
this.super.introspect(`${this.caller}: Saving file ${filename}.`);
this.tracker.trackRun(this.name, { file_content, filename });
return `${filename} file has been saved successfully and will be downloaded automatically to the users browser.`;
} catch (error) {
this.super.handlerProps.log(
`save-file-to-browser raised an error. ${error.message}`
);
return `Let the user know this action was not successful. An error was raised while saving a file to the browser. ${error.message}`;
}
},
});
},
};
},
};
module.exports = {
saveFileInBrowser,
};