UNPKG

@essentialai/cogent-bridge

Version:

Cogent Bridge — cross-agent comms for Claude Code, OpenAI Codex and Slack. Codex users: install with `curl -fsSL https://cogent.tools/install.sh | sh`, then start with `cogent-codex` for real-time peer wake.

54 lines • 2.85 kB
import { StorageBackend } from "./storage-backend.js"; /** Set the singleton backend (called during server startup). */ export declare function initBackend(backend: StorageBackend): void; /** * Get the active storage backend. * * If no backend has been set via initBackend(), lazy-initializes a FileBackend. * This makes existing tests pass without modification -- they never call * initBackend(), so getBackend() auto-creates a FileBackend that delegates * to the same service functions the tests already mock via vi.mock(). */ export declare function getBackend(): StorageBackend; /** Reset the singleton to null (for test isolation). */ export declare function resetBackend(): void; /** Check whether a value looks like a cloud endpoint (http:// or https://). */ export declare function isCloudEndpoint(value: string): boolean; /** * Check whether the active backend is cloud-mode (HttpBackend). * Unlike checking config.COGENT_ENDPOINT, this reflects runtime state * after reinitCloudBackend() may have swapped the backend at runtime. */ export declare function isCloudMode(): boolean; /** * SECURITY — cloud-configured but NOT yet joined ("deferred"). * * True when the bridge is cloud-CONFIGURED (endpoint is an http(s) relay URL) * yet the active backend is still the local FileBackend placeholder, i.e. the * agent has not completed a join/register and belongs to NO channel yet * (startup.ts deferred branch installs `createBackend(undefined)` until * reinitCloudBackend swaps in the HttpBackend). * * In this state, channel-scoped reads (`cogent_get_history` / `cogent_list_peers`) * MUST return empty rather than read the host-global `~/.cogent/cogent-state.json`, * which can contain OTHER local/deferred agents' peers and message bodies on the * same host — surfacing them would disclose another channel's content to an agent * that is not on it. `endpoint` is passed in (this module deliberately does not * import config; the caller supplies `getConfig().COGENT_ENDPOINT`). * * Genuine local mode (COGENT_LOCAL / non-http endpoint → `endpoint` undefined or * non-URL) returns false: its single-host shared-file semantics are unchanged. */ export declare function isCloudDeferred(endpoint: string | undefined): boolean; /** * Factory: create a backend from an optional endpoint string. * * - If endpoint is an HTTP/HTTPS URL, creates an HttpBackend for cloud mode. * Requires sessionId and token (from env vars or tool-based session setup). * - Otherwise returns a FileBackend for local file-based state. * * Note: Does NOT import config.ts to avoid circular dependency risk * (decision from 02B-01). Caller passes params explicitly. */ export declare function createBackend(endpoint?: string, sessionId?: string, token?: string): StorageBackend; //# sourceMappingURL=backend-provider.d.ts.map