Using IndexedDB
Some agents need to work with files without a server round-trip: drafting a
document, editing code, or keeping notes across turns. @distri/fs
gives them a real filesystem that lives in the browser, backed by IndexedDB
so it persists across reloads.
A filesystem per project
Files are namespaced by a projectId, so each project (or user, or thread) gets
its own isolated tree:
import { createFilesystemTools } from '@distri/fs';
const tools = createFilesystemTools('project-123');
// backed by IndexedDbFilesystem.forProject('project-123')
Hand those tools to the agent as external tools, and it can operate on the project's files directly:
<Chat agent={agent} threadId="doc" externalTools={tools} />
What the agent gets
createFilesystemTools returns a full set of file operations, each named fs_*:
| Tool | Does |
|---|---|
fs_read_file / fs_write_file | Read and write file contents. |
apply_diff | Apply a diff to a file. |
fs_list_directory / fs_tree | List a directory or the whole tree. |
fs_search_files / fs_search_within_files | Find files by name or by content. |
fs_copy_file / fs_move_file / fs_delete_file | Manage files. |
fs_create_directory / fs_get_file_info | Make folders, inspect files. |
Everything reads and writes to IndexedDB under the hood. No backend required.
Show it to the user
@distri/fs also ships the UI to make the filesystem visible:
FileWorkspace/FileListbrowse and open the project's files.ScriptTestingPanelruns scripts against those files (see Browser Scripting).
import { FileWorkspace } from '@distri/fs';
<FileWorkspace projectId="project-123" />
Related
- Browser Scripting lets the agent run code against these files, in a sandbox.
- In-Product Tools covers wiring external tools into the chat.