Chat Storage
chat/storage
Section titled “chat/storage”Classes
Section titled “Classes”FileStorage
Section titled “FileStorage”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.
Example
Section titled “Example”const store = new FileStorage<ChatSession>({ directory: "./data/sessions",});await store.create("session-1", mySession);Type Parameters
Section titled “Type Parameters”T
The type of stored items (must be JSON-serializable)
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new FileStorage<
T>(options):FileStorage<T>
Defined in: chat/storage.ts:267
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”FileStorage<T>
Methods
Section titled “Methods”clear()
Section titled “clear()”clear():
Promise<void>
Defined in: chat/storage.ts:361
Remove all items from storage.
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”count()
Section titled “count()”count():
Promise<number>
Defined in: chat/storage.ts:353
Return the number of stored items.
Returns
Section titled “Returns”Promise<number>
Count of items
Implementation of
Section titled “Implementation of”create()
Section titled “create()”create(
key,item):Promise<void>
Defined in: chat/storage.ts:312
Create a new item. Throws StorageError with code DUPLICATE_KEY if key exists.
Parameters
Section titled “Parameters”string
Unique identifier
T
Data to store
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”delete()
Section titled “delete()”delete(
key):Promise<void>
Defined in: chat/storage.ts:336
Delete an item by key. Throws StorageError with code NOT_FOUND if key missing.
Parameters
Section titled “Parameters”string
Unique identifier
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”get(
key):Promise<T|null>
Defined in: chat/storage.ts:274
Retrieve an item by key.
Parameters
Section titled “Parameters”string
Unique identifier
Returns
Section titled “Returns”Promise<T | null>
The item, or null if not found
Implementation of
Section titled “Implementation of”has(
key):Promise<boolean>
Defined in: chat/storage.ts:348
Check whether a key exists.
Parameters
Section titled “Parameters”string
Unique identifier
Returns
Section titled “Returns”Promise<boolean>
true if key exists
Implementation of
Section titled “Implementation of”list()
Section titled “list()”list(
options?):Promise<T[]>
Defined in: chat/storage.ts:283
List items with optional filtering, sorting, and pagination.
Parameters
Section titled “Parameters”options?
Section titled “options?”ListOptions<T>
Filter, sort, limit, offset options
Returns
Section titled “Returns”Promise<T[]>
Array of matching items
Implementation of
Section titled “Implementation of”update()
Section titled “update()”update(
key,item):Promise<void>
Defined in: chat/storage.ts:324
Update an existing item. Throws StorageError with code NOT_FOUND if key missing.
Parameters
Section titled “Parameters”string
Unique identifier
T
Updated data
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”InMemoryStorage
Section titled “InMemoryStorage”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.
Example
Section titled “Example”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" }]Type Parameters
Section titled “Type Parameters”T
The type of stored items
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new InMemoryStorage<
T>():InMemoryStorage<T>
Returns
Section titled “Returns”Methods
Section titled “Methods”clear()
Section titled “clear()”clear():
Promise<void>
Defined in: chat/storage.ts:231
Remove all items from storage.
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”count()
Section titled “count()”count():
Promise<number>
Defined in: chat/storage.ts:226
Return the number of stored items.
Returns
Section titled “Returns”Promise<number>
Count of items
Implementation of
Section titled “Implementation of”create()
Section titled “create()”create(
key,item):Promise<void>
Defined in: chat/storage.ts:188
Create a new item. Throws StorageError with code DUPLICATE_KEY if key exists.
Parameters
Section titled “Parameters”string
Unique identifier
T
Data to store
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”delete()
Section titled “delete()”delete(
key):Promise<void>
Defined in: chat/storage.ts:210
Delete an item by key. Throws StorageError with code NOT_FOUND if key missing.
Parameters
Section titled “Parameters”string
Unique identifier
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”get(
key):Promise<T|null>
Defined in: chat/storage.ts:162
Retrieve an item by key.
Parameters
Section titled “Parameters”string
Unique identifier
Returns
Section titled “Returns”Promise<T | null>
The item, or null if not found
Implementation of
Section titled “Implementation of”has(
key):Promise<boolean>
Defined in: chat/storage.ts:221
Check whether a key exists.
Parameters
Section titled “Parameters”string
Unique identifier
Returns
Section titled “Returns”Promise<boolean>
true if key exists
Implementation of
Section titled “Implementation of”list()
Section titled “list()”list(
options?):Promise<T[]>
Defined in: chat/storage.ts:168
List items with optional filtering, sorting, and pagination.
Parameters
Section titled “Parameters”options?
Section titled “options?”ListOptions<T>
Filter, sort, limit, offset options
Returns
Section titled “Returns”Promise<T[]>
Array of matching items
Implementation of
Section titled “Implementation of”update()
Section titled “update()”update(
key,item):Promise<void>
Defined in: chat/storage.ts:199
Update an existing item. Throws StorageError with code NOT_FOUND if key missing.
Parameters
Section titled “Parameters”string
Unique identifier
T
Updated data
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”StorageError
Section titled “StorageError”Defined in: chat/storage.ts:31
Error thrown by storage operations.
Example
Section titled “Example”try { await store.get("missing-id");} catch (e) { if (e instanceof StorageError && e.code === ErrorCode.STORAGE_NOT_FOUND) { // handle missing item }}Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new StorageError(
message,code):StorageError
Defined in: chat/storage.ts:35
Parameters
Section titled “Parameters”message
Section titled “message”string
Returns
Section titled “Returns”Overrides
Section titled “Overrides”Properties
Section titled “Properties”
readonlycode:StorageErrorCode
Defined in: chat/storage.ts:33
Machine-readable error code from the unified ErrorCode enum
Overrides
Section titled “Overrides”httpStatus?
Section titled “httpStatus?”
readonlyoptionalhttpStatus:number
Defined in: errors.ts:25
HTTP status code hint for error classification
Inherited from
Section titled “Inherited from”retryable
Section titled “retryable”
readonlyretryable:boolean
Defined in: errors.ts:23
Whether this error is safe to retry
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”
staticis(error):error is AgentSDKError
Defined in: errors.ts:36
Check if an error is an AgentSDKError (works across bundled copies)
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”error is AgentSDKError
Inherited from
Section titled “Inherited from”Interfaces
Section titled “Interfaces”FileStorageOptions
Section titled “FileStorageOptions”Defined in: chat/storage.ts:241
Options for configuring FileStorage.
Properties
Section titled “Properties”directory
Section titled “directory”directory:
string
Defined in: chat/storage.ts:243
Directory path where JSON files are stored
extension?
Section titled “extension?”
optionalextension:string
Defined in: chat/storage.ts:245
File extension (default: .json)
IStorageAdapter
Section titled “IStorageAdapter”Defined in: chat/storage.ts:80
Generic storage adapter for CRUD operations on any data type. Items are identified by a string key.
Example
Section titled “Example”const store: IStorageAdapter<{ name: string }> = new InMemoryStorage();await store.create("key1", { name: "Alice" });const item = await store.get("key1"); // { name: "Alice" }Type Parameters
Section titled “Type Parameters”T
The type of stored items
Methods
Section titled “Methods”clear()
Section titled “clear()”clear():
Promise<void>
Defined in: chat/storage.ts:131
Remove all items from storage.
Returns
Section titled “Returns”Promise<void>
count()
Section titled “count()”count():
Promise<number>
Defined in: chat/storage.ts:126
Return the number of stored items.
Returns
Section titled “Returns”Promise<number>
Count of items
create()
Section titled “create()”create(
key,item):Promise<void>
Defined in: chat/storage.ts:100
Create a new item. Throws StorageError with code DUPLICATE_KEY if key exists.
Parameters
Section titled “Parameters”string
Unique identifier
T
Data to store
Returns
Section titled “Returns”Promise<void>
delete()
Section titled “delete()”delete(
key):Promise<void>
Defined in: chat/storage.ts:113
Delete an item by key. Throws StorageError with code NOT_FOUND if key missing.
Parameters
Section titled “Parameters”string
Unique identifier
Returns
Section titled “Returns”Promise<void>
dispose()?
Section titled “dispose()?”
optionaldispose():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.
Returns
Section titled “Returns”Promise<void>
get(
key):Promise<T|null>
Defined in: chat/storage.ts:86
Retrieve an item by key.
Parameters
Section titled “Parameters”string
Unique identifier
Returns
Section titled “Returns”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.
Parameters
Section titled “Parameters”string
Unique identifier
Returns
Section titled “Returns”Promise<boolean>
true if key exists
list()
Section titled “list()”list(
options?):Promise<T[]>
Defined in: chat/storage.ts:93
List items with optional filtering, sorting, and pagination.
Parameters
Section titled “Parameters”options?
Section titled “options?”ListOptions<T>
Filter, sort, limit, offset options
Returns
Section titled “Returns”Promise<T[]>
Array of matching items
update()
Section titled “update()”update(
key,item):Promise<void>
Defined in: chat/storage.ts:107
Update an existing item. Throws StorageError with code NOT_FOUND if key missing.
Parameters
Section titled “Parameters”string
Unique identifier
T
Updated data
Returns
Section titled “Returns”Promise<void>
ListOptions
Section titled “ListOptions”Defined in: chat/storage.ts:56
Options for listing stored items.
Type Parameters
Section titled “Type Parameters”T
The type of stored items
Properties
Section titled “Properties”filter()?
Section titled “filter()?”
optionalfilter: (item) =>boolean
Defined in: chat/storage.ts:58
Filter predicate — return true to include the item
Parameters
Section titled “Parameters”T
Returns
Section titled “Returns”boolean
limit?
Section titled “limit?”
optionallimit:number
Defined in: chat/storage.ts:62
Maximum number of items to return
offset?
Section titled “offset?”
optionaloffset:number
Defined in: chat/storage.ts:64
Number of items to skip (for pagination)
sort()?
Section titled “sort()?”
optionalsort: (a,b) =>number
Defined in: chat/storage.ts:60
Sort comparator — standard Array.sort semantics
Parameters
Section titled “Parameters”T
T
Returns
Section titled “Returns”number
Type Aliases
Section titled “Type Aliases”StorageErrorCode
Section titled “StorageErrorCode”StorageErrorCode =
STORAGE_NOT_FOUND|STORAGE_DUPLICATE_KEY|STORAGE_IO_ERROR|STORAGE_SERIALIZATION_ERROR
Defined in: chat/storage.ts:43
Storage-specific subset of ErrorCode