trellis
Version:
Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications
83 lines • 3.01 kB
TypeScript
/**
* Trellis Server — Multi-Tenant Kernel Pool
*
* Manages a pool of `TrellisKernel` instances, one per tenant.
* Each tenant gets an isolated SQLite database file in `<dbPath>/tenants/<tenantId>.sqlite`.
*
* The default tenant uses `<dbPath>/default.sqlite`.
*
* @module trellis/server
*/
import { TrellisKernel } from '../core/kernel/trellis-kernel.js';
import type { CreateKernelBackendOptions } from '../core/persist/factory.js';
export declare const DEFAULT_TENANT = "default";
/** `TRELLIS_BACKEND=sqljs|better-sqlite` for `trellis db serve` and custom hosts. */
export declare function resolvePoolBackendFromEnv(): CreateKernelBackendOptions | undefined;
/**
* A pool of `TrellisKernel` instances keyed by tenant ID.
*
* - Kernels are lazily created on first access.
* - Each tenant's data lives in `<dbPath>/tenants/<tenantId>.sqlite`.
* - The default tenant lives at `<dbPath>/default.sqlite`.
*/
export interface TenantPoolOptions {
agentId?: string;
/**
* Backend selection forwarded to `createKernelBackend`. Only consulted by
* `preload()` — `get()` always uses the synchronous bun:sqlite backend
* for back-compat.
*/
backend?: CreateKernelBackendOptions;
}
export declare class TenantPool {
private pool;
private dbPath;
private agentId;
private backendOpts;
constructor(dbPath: string, agentIdOrOpts?: string | TenantPoolOptions);
/**
* Get (or create) the kernel for a tenant.
* Pass `null` or `undefined` to get the default tenant.
*
* Uses the synchronous bun:sqlite backend. To use an async backend
* (better-sqlite3, sql.js) call `preload(tenantId)` first; subsequent
* `get()` calls will return the preloaded kernel from the pool.
*/
get(tenantId?: string | null): TrellisKernel;
/**
* Pre-create a tenant's kernel using the runtime-selected backend.
* Required when running with an async-only backend (sql.js / WebContainer
* / browser). Idempotent — safe to call multiple times.
*
* After `preload()`, subsequent `get(tenantId)` returns the same kernel
* synchronously from the pool.
*/
preload(tenantId?: string | null): Promise<TrellisKernel>;
/**
* Check whether a tenant has been initialized (kernel created).
*/
has(tenantId: string): boolean;
/**
* List all active tenant IDs (those with open kernels).
*/
activeTenants(): string[];
/**
* Close a specific tenant's kernel and remove it from the pool.
*/
close(tenantId: string): void;
/**
* Close all kernels and clear the pool.
*/
closeAll(): void;
/** Absolute path to the tenant data directory. */
dataPath(): string;
/**
* Return the SQLite file path for a given tenant.
*/
dbFilePath(tenantId?: string | null): string;
private _createKernelSync;
private _createKernelAsync;
private _wrapKernel;
private _ensureDirs;
}
//# sourceMappingURL=tenancy.d.ts.map