zidane/ durable/ sqlite
A durable runtime that checkpoints agent runs in a SQLite file, for Bun.
import { … } from 'zidane/durable/sqlite'src/durable/sqlite.ts
Use createSqliteRuntime when a run must continue after its process crashes. It records each model call and tool call in the SQLite sessions file, commits with synchronous = FULL, and its stores.session is the session store to create sessions on. After a crash, agent.resume() in the next process continues the run. It needs Bun (bun:sqlite). See crash recovery.
createSqliteRuntime takes a SqliteRuntimeOptions with one field, path. It creates the file when it is missing, but the directory must exist. It returns a SqliteRuntime, a SqliteDurableRuntime that owns its connection. Call close() to stop its waits and close the connection. A second call does nothing.
import { createAgent } from 'zidane'
import { createSqliteRuntime } from 'zidane/durable/sqlite'
import { anthropic } from 'zidane/providers/anthropic'
const runtime = createSqliteRuntime({ path: './sessions.db' })
const agent = createAgent({ provider: anthropic(), durable: runtime, sessionId: 'job-42' })
// Continue the run a crash cut off, if any; null when there is none.
if (!await agent.resume())
await agent.run({ prompt: 'Migrate the config files.' })
runtime.close()Functions#
createSqliteRuntimeFunction#
Open the checkpoint durable runtime over the SQLite file at path, with
its own connection. Close it with close().
function createSqliteRuntime(options: SqliteRuntimeOptions): SqliteRuntimeParameters
| Name | Type | Description |
|---|---|---|
| options | SqliteRuntimeOptions | Runtime options. |
Returns
Interfaces#
SqliteDurableRuntimeInterface#
A runtime whose timers can be stopped; the caller closes the connection.
interface SqliteDurableRuntime extends DurableRuntimeProperties
| Name | Type | Description |
|---|---|---|
| dispose | () => void | Stop the awakeable waits of this runtime (they never settle). Idempotent. |
findAwakeable?from DurableRuntime | (sessionId: string, key: `${string}:${number}:${string}:${number}`) => Promise<AwakeableRecord | undefined> | The stored awakeable of |
isControlErrorfrom DurableRuntime | (error: unknown) => boolean | Errors the runtime uses to stop or suspend a run: the loop rethrows them untouched instead of reporting a failed call. |
lease?readonlyfrom DurableRuntime | DurableLease | Who runs each session's run. Absent where the platform guarantees one writer. |
modereadonlyfrom DurableRuntime | DurableMode | How the runtime recovers a run, see |
openRunfrom DurableRuntime | (options: OpenRunOptions) => Promise<RunScope> | Open a run's scope. Handlers are per scope, never shared with another run. |
resolveAwakeablefrom DurableRuntime | (id: string, value: JsonValue) => Promise<boolean> | Resolve an awakeable, also while no process runs its run (the run gets
the value when it resumes). Call it from the resumer's side: another
process or an ingress client, never the run that waits. In
|
storesreadonlyfrom DurableRuntime | DurableStores | Where a run persists its session, tool state, queue and submissions. |
SqliteRuntimeInterface#
A SQLite durable runtime that owns its connection.
interface SqliteRuntime extends SqliteDurableRuntimeProperties
| Name | Type | Description |
|---|---|---|
| close | () => void | Stop its waits and close the connection. Idempotent. |
disposefrom SqliteDurableRuntime | () => void | Stop the awakeable waits of this runtime (they never settle). Idempotent. |
findAwakeable?from SqliteDurableRuntime | (sessionId: string, key: `${string}:${number}:${string}:${number}`) => Promise<AwakeableRecord | undefined> | The stored awakeable of |
isControlErrorfrom SqliteDurableRuntime | (error: unknown) => boolean | Errors the runtime uses to stop or suspend a run: the loop rethrows them untouched instead of reporting a failed call. |
lease?readonlyfrom SqliteDurableRuntime | DurableLease | Who runs each session's run. Absent where the platform guarantees one writer. |
modereadonlyfrom SqliteDurableRuntime | DurableMode | How the runtime recovers a run, see |
openRunfrom SqliteDurableRuntime | (options: OpenRunOptions) => Promise<RunScope> | Open a run's scope. Handlers are per scope, never shared with another run. |
resolveAwakeablefrom SqliteDurableRuntime | (id: string, value: JsonValue) => Promise<boolean> | Resolve an awakeable, also while no process runs its run (the run gets
the value when it resumes). Call it from the resumer's side: another
process or an ingress client, never the run that waits. In
|
storesreadonlyfrom SqliteDurableRuntime | DurableStores | Where a run persists its session, tool state, queue and submissions. |
SqliteRuntimeOptionsInterface#
Options of createSqliteRuntime.
interface SqliteRuntimeOptionsProperties
| Name | Type | Description |
|---|---|---|
| path | string | Path of the SQLite sessions file. Created when missing (its directory must exist). |