Postgres and SQLite

The storage adapters, migrations, limit stores, secret stores and agent stores in @intentface/latch-drizzle.

@intentface/latch-drizzle keeps everything in your own Postgres or SQLite database (including libSQL and Turso), through a Drizzle instance you create and own.

Storage adapters

ts
import { createPostgresAdapter, migratePostgres } from "@intentface/latch-drizzle";

await migratePostgres(db); // once per deploy: creates and updates the latch_* tables
const storage = createPostgresAdapter<Principal>(db, { owner: (p) => [p.orgId, p.userId] });

createSqliteAdapter and migrate do the same for SQLite. Both adapters take:

OptionTypeDefaultDetails
owner(principal: P) => string[]—

Postgres needs a driver that supports transactions (pg, postgres, Neon's neon-serverless), not neon-http.

Everything else in the package

ExportWhat it is
createPostgresLimitStore(db), createSqliteLimitStore(db)Counters for limits.
createPostgresSecretStore(db, { owner }), createSqliteSecretStore(db, { owner })Where the vault keeps encrypted secrets. Its owner can differ from storage's: shared per team while chats are per person.
createPostgresAgentBuilderStore(db, options), createSqliteAgentBuilderStore(db, options)Agents in a database, with versions. Options below.
createPostgresMemoryJobStore, createMemoryJobStoreFor memory, which is experimental.
schema, pgSchemaThe Drizzle table definitions, for your own queries.

Agent store options

OptionTypeDefaultDetails
owner(principal: P, scope: AgentScope) => string[]—
modelFor(id: string) => LanguageModel—
loadAuthoredTools?function—
decorateResolve?function—
editorKey?((principal: P) => string)the `"user"` scope's owner key

The store's methods: Agent store.