UNPKG

trellis

Version:

Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications

132 lines 4.99 kB
/** * Trellis Client — browser SDK * * Remote-only runtime for browser bundles. It intentionally excludes local * embedded-kernel mode, filesystem config reads, and server tenancy imports. * * @module trellis/client */ import type { SchemaDefinition } from '../core/ontology/types.js'; import type { ResolveSpec } from '../schema/resolve.js'; import type { AuthResult, CreateEntityOptions, EntityData, ListResult, QueryResult, Subscription, SubscriptionCallback, TrellisDbOptions, UploadResult } from './sdk.js'; export type { AuthResult, CreateEntityOptions, EntityData, ListResult, QueryResult, Subscription, SubscriptionCallback, TrellisDbLocalOptions, TrellisDbOptions, TrellisDbRemoteOptions, UploadResult, } from './sdk.js'; export interface SubscribeOptions { /** Entity type name (e.g. `NavSection`) for server `resolve`. */ entityType?: string; resolve?: ResolveSpec; } declare global { interface Window { /** Set by host app when WKWebView drops fetch POST bodies (XHR fallback). */ __TRELLIS_USE_XHR__?: boolean; /** Host patched fetch via Tauri plugin-http — always use fetch, never XHR. */ __TRELLIS_NATIVE_HTTP__?: boolean; } } export declare class TrellisDb { private opts; private _ws; /** In-flight connect — concurrent subscribe() shares one socket open. */ private _wsPromise; private _subCallbacks; constructor(opts: TrellisDbOptions); /** * Browser bundles cannot read `.trellis-db.json`. */ static fromConfig(_dir?: string): Promise<TrellisDb>; /** * Create a new entity. * Returns the entity ID (generated or caller-supplied via options.id). */ create(type: string, attributes?: Record<string, unknown>, links?: Array<{ attribute: string; targetEntityId: string; }>, options?: CreateEntityOptions): Promise<string>; /** * Read an entity by ID. * Returns null if not found. */ read<T extends EntityData = EntityData>(id: string): Promise<T | null>; /** * Update an entity's attributes (partial update). */ update(id: string, attributes: Record<string, unknown>): Promise<void>; /** * Delete an entity by ID. */ delete(id: string): Promise<void>; /** * List entities of a given type. */ list<T extends EntityData = EntityData>(type?: string, opts?: { limit?: number; offset?: number; filters?: Record<string, unknown>; }): Promise<ListResult<T>>; /** * Run an EQL-S query string. */ query(eql: string): Promise<QueryResult>; /** * Register a user/system-tier ontology schema with a remote Trellis server. */ registerType(schema: SchemaDefinition | { definition: SchemaDefinition; }): Promise<void>; /** * Upload a file to the blob store. * Returns a content-addressed hash. */ upload(data: Uint8Array | ArrayBuffer, contentType?: string): Promise<UploadResult>; /** * Download a file by its blob hash. */ getFile(hash: string): Promise<Uint8Array | null>; register(email: string, password: string, name?: string): Promise<AuthResult>; login(email: string, password: string): Promise<AuthResult>; /** * Set the active API key / JWT token for subsequent requests. */ setToken(token: string): void; /** * Subscribe to a live EQL-S query. * Callback is fired immediately with the initial result, then on every update. */ subscribe<T = EntityData>(eql: string, callback: SubscriptionCallback<T>, opts?: SubscribeOptions): Subscription<T>; /** * Close the WebSocket connection. */ disconnect(): void; /** * Close open client resources. */ close(): void; /** * Tenant isolation, not authorization: when `tenantId` is supplied out-of-band * (not bound to the JWT), the server trusts the query param. Safe for ephemeral * showcase rooms with unguessable ids; real multi-tenant auth must bind the * tenant to the auth token instead. Skipped when the JWT already carries it. */ private _applyTenant; private _fetch; private _ensureWs; } export interface FetchErrorContext { method?: string; path?: string; url?: string; operation?: string; requestBodyBytes?: number; responseBytes?: number; transport?: 'fetch' | 'xhr'; } export declare class FetchError extends Error { status: number; body?: unknown | undefined; readonly context: FetchErrorContext; constructor(status: number, message: string, body?: unknown | undefined, context?: FetchErrorContext); static format(status: number, message: string, ctx: FetchErrorContext): string; toString(): string; } export { clearDevRegistry, getDevRegistry, registerDevRegistry, type FractalShellName, type TrellisDevRegistry, type TrellisFractalDev, } from './dev-registry.js'; //# sourceMappingURL=sdk.browser.d.ts.map