Skip to main content

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_*:

ToolDoes
fs_read_file / fs_write_fileRead and write file contents.
apply_diffApply a diff to a file.
fs_list_directory / fs_treeList a directory or the whole tree.
fs_search_files / fs_search_within_filesFind files by name or by content.
fs_copy_file / fs_move_file / fs_delete_fileManage files.
fs_create_directory / fs_get_file_infoMake 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 / FileList browse and open the project's files.
  • ScriptTestingPanel runs scripts against those files (see Browser Scripting).
import { FileWorkspace } from '@distri/fs';

<FileWorkspace projectId="project-123" />