Skip to content

Chat Storage

Defined in: chat/storage.ts:263

File-based storage adapter that persists each item as a JSON file. Suitable for local applications, CLI tools, and development. Creates the storage directory if it doesn’t exist.

const store = new FileStorage<ChatSession>({
directory: "./data/sessions",
});
await store.create("session-1", mySession);

T

The type of stored items (must be JSON-serializable)

new FileStorage<T>(options): FileStorage<T>

Defined in: chat/storage.ts:267

FileStorageOptions

FileStorage<T>

clear(): Promise<void>

Defined in: chat/storage.ts:361

Remove all items from storage.

Promise<void>

IStorageAdapter.clear

count(): Promise<number>

Defined in: chat/storage.ts:353

Return the number of stored items.

Promise<number>

Count of items

IStorageAdapter.count

create(key, item): Promise<void>

Defined in: chat/storage.ts:312

Create a new item. Throws StorageError with code DUPLICATE_KEY if key exists.

string

Unique identifier

T

Data to store

Promise<void>

IStorageAdapter.create

delete(key): Promise<void>

Defined in: chat/storage.ts:336

Delete an item by key. Throws StorageError with code NOT_FOUND if key missing.

string

Unique identifier

Promise<void>

IStorageAdapter.delete

get(key): Promise<T | null>

Defined in: chat/storage.ts:274

Retrieve an item by key.

string

Unique identifier

Promise<T | null>

The item, or null if not found

IStorageAdapter.get

has(key): Promise<boolean>

Defined in: chat/storage.ts:348

Check whether a key exists.

string

Unique identifier

Promise<boolean>

true if key exists

IStorageAdapter.has

list(options?): Promise<T[]>

Defined in: chat/storage.ts:283

List items with optional filtering, sorting, and pagination.

ListOptions<T>

Filter, sort, limit, offset options

Promise<T[]>

Array of matching items

IStorageAdapter.list

update(key, item): Promise<void>

Defined in: chat/storage.ts:324

Update an existing item. Throws StorageError with code NOT_FOUND if key missing.

string

Unique identifier

T

Updated data

Promise<void>

IStorageAdapter.update


Defined in: chat/storage.ts:158

In-memory storage adapter backed by a Map. Suitable for development, testing, and short-lived processes. Data is lost when the process exits.

const store = new InMemoryStorage<{ name: string }>();
await store.create("k1", { name: "Alice" });
await store.create("k2", { name: "Bob" });
const items = await store.list({ filter: i => i.name.startsWith("A") });
// [{ name: "Alice" }]

T

The type of stored items

new InMemoryStorage<T>(): InMemoryStorage<T>

InMemoryStorage<T>

clear(): Promise<void>

Defined in: chat/storage.ts:231

Remove all items from storage.

Promise<void>

IStorageAdapter.clear

count(): Promise<number>

Defined in: chat/storage.ts:226

Return the number of stored items.

Promise<number>

Count of items

IStorageAdapter.count

create(key, item): Promise<void>

Defined in: chat/storage.ts:188

Create a new item. Throws StorageError with code DUPLICATE_KEY if key exists.

string

Unique identifier

T

Data to store

Promise<void>

IStorageAdapter.create

delete(key): Promise<void>

Defined in: chat/storage.ts:210

Delete an item by key. Throws StorageError with code NOT_FOUND if key missing.

string

Unique identifier

Promise<void>

IStorageAdapter.delete

get(key): Promise<T | null>

Defined in: chat/storage.ts:162

Retrieve an item by key.

string

Unique identifier

Promise<T | null>

The item, or null if not found

IStorageAdapter.get

has(key): Promise<boolean>

Defined in: chat/storage.ts:221

Check whether a key exists.

string

Unique identifier

Promise<boolean>

true if key exists

IStorageAdapter.has

list(options?): Promise<T[]>

Defined in: chat/storage.ts:168

List items with optional filtering, sorting, and pagination.

ListOptions<T>

Filter, sort, limit, offset options

Promise<T[]>

Array of matching items

IStorageAdapter.list

update(key, item): Promise<void>

Defined in: chat/storage.ts:199

Update an existing item. Throws StorageError with code NOT_FOUND if key missing.

string

Unique identifier

T

Updated data

Promise<void>

IStorageAdapter.update


Defined in: chat/storage.ts:31

Error thrown by storage operations.

try {
await store.get("missing-id");
} catch (e) {
if (e instanceof StorageError && e.code === ErrorCode.STORAGE_NOT_FOUND) {
// handle missing item
}
}

new StorageError(message, code): StorageError

Defined in: chat/storage.ts:35

string

StorageErrorCode

StorageError

AgentSDKError.constructor

readonly code: StorageErrorCode

Defined in: chat/storage.ts:33

Machine-readable error code from the unified ErrorCode enum

AgentSDKError.code

readonly optional httpStatus: number

Defined in: errors.ts:25

HTTP status code hint for error classification

AgentSDKError.httpStatus

readonly retryable: boolean

Defined in: errors.ts:23

Whether this error is safe to retry

AgentSDKError.retryable

static is(error): error is AgentSDKError

Defined in: errors.ts:36

Check if an error is an AgentSDKError (works across bundled copies)

unknown

error is AgentSDKError

AgentSDKError.is

Defined in: chat/storage.ts:241

Options for configuring FileStorage.

directory: string

Defined in: chat/storage.ts:243

Directory path where JSON files are stored

optional extension: string

Defined in: chat/storage.ts:245

File extension (default: .json)


Defined in: chat/storage.ts:80

Generic storage adapter for CRUD operations on any data type. Items are identified by a string key.

const store: IStorageAdapter<{ name: string }> = new InMemoryStorage();
await store.create("key1", { name: "Alice" });
const item = await store.get("key1"); // { name: "Alice" }

T

The type of stored items

clear(): Promise<void>

Defined in: chat/storage.ts:131

Remove all items from storage.

Promise<void>

count(): Promise<number>

Defined in: chat/storage.ts:126

Return the number of stored items.

Promise<number>

Count of items

create(key, item): Promise<void>

Defined in: chat/storage.ts:100

Create a new item. Throws StorageError with code DUPLICATE_KEY if key exists.

string

Unique identifier

T

Data to store

Promise<void>

delete(key): Promise<void>

Defined in: chat/storage.ts:113

Delete an item by key. Throws StorageError with code NOT_FOUND if key missing.

string

Unique identifier

Promise<void>

optional dispose(): Promise<void>

Defined in: chat/storage.ts:137

Release any resources held by this adapter (DB connections, file handles). Optional — adapters that don’t hold resources need not implement this.

Promise<void>

get(key): Promise<T | null>

Defined in: chat/storage.ts:86

Retrieve an item by key.

string

Unique identifier

Promise<T | null>

The item, or null if not found

has(key): Promise<boolean>

Defined in: chat/storage.ts:120

Check whether a key exists.

string

Unique identifier

Promise<boolean>

true if key exists

list(options?): Promise<T[]>

Defined in: chat/storage.ts:93

List items with optional filtering, sorting, and pagination.

ListOptions<T>

Filter, sort, limit, offset options

Promise<T[]>

Array of matching items

update(key, item): Promise<void>

Defined in: chat/storage.ts:107

Update an existing item. Throws StorageError with code NOT_FOUND if key missing.

string

Unique identifier

T

Updated data

Promise<void>


Defined in: chat/storage.ts:56

Options for listing stored items.

T

The type of stored items

optional filter: (item) => boolean

Defined in: chat/storage.ts:58

Filter predicate — return true to include the item

T

boolean

optional limit: number

Defined in: chat/storage.ts:62

Maximum number of items to return

optional offset: number

Defined in: chat/storage.ts:64

Number of items to skip (for pagination)

optional sort: (a, b) => number

Defined in: chat/storage.ts:60

Sort comparator — standard Array.sort semantics

T

T

number

StorageErrorCode = STORAGE_NOT_FOUND | STORAGE_DUPLICATE_KEY | STORAGE_IO_ERROR | STORAGE_SERIALIZATION_ERROR

Defined in: chat/storage.ts:43

Storage-specific subset of ErrorCode