/** * Lightweight RTDB REST helper for runtime state. * * Uses Firebase Realtime Database REST API to avoid adding firebase-admin * as a dependency to the MCP plugin. The custom token from /agents/auth-token * is exchanged for a Firebase ID token before use with RTDB REST. */ import type { CanonClient } from './client.js'; import type { DeliveryIntent, RuntimeCapabilities, TurnLifecycleState } from './turn-protocol.js'; import type { CanonControlValue, CanonRuntimeActivityItem, ModelOption, RuntimeControlError, RuntimeControlState, RuntimeInfoPayload } from './types.js'; export interface SessionStatePayload { lastError?: string; model?: string; permissionMode?: string; effort?: string; runtimeControlValues?: Record; controlState?: Record; runtimeControlErrors?: Record | null; cwd?: string; executionMode?: 'worktree' | 'locked'; executionBranch?: string; worktreePath?: string; executionFallbackReason?: string; hostMode?: boolean; clientType?: string; isActive: boolean; /** Runtimes that cannot report a context window (e.g. Codex) publish totalTokens only. */ contextUsage?: { percentage?: number; totalTokens: number; maxTokens?: number; }; availableModels?: ModelOption[]; updatedAt: { '.sv': 'timestamp'; }; } export interface TurnStatePayload { turnId?: string | null; state: TurnLifecycleState; queueDepth: number; currentSpeakerId?: string | null; lastAcceptedIntent?: DeliveryIntent | null; activeMessageIds?: string[]; capabilities?: RuntimeCapabilities; openedAt?: number | { '.sv': 'timestamp'; }; turnUpdatedAt?: number | { '.sv': 'timestamp'; } | null; completedAt?: number | { '.sv': 'timestamp'; } | null; updatedAt: { '.sv': 'timestamp'; }; } export interface AgentSessionSnapshotPatch { clientType?: string; hostMode?: boolean; model?: string | null; modelOptions?: ModelOption[] | null; permissionMode?: string | null; permissionModeOptions?: Array<{ value: string; label: string; }> | null; effort?: string | null; runtimeControlValues?: Record | null; controlState?: Record | null; runtimeControlErrors?: Record | null; workspaceId?: string | null; workspaceOptions?: Array<{ id: string; label: string; }> | null; executionMode?: 'worktree' | 'locked' | null; availableExecutionModes?: Array<'worktree' | 'locked'> | null; executionBranch?: string | null; resolvedCwd?: string | null; worktreePath?: string | null; executionFallbackReason?: string | null; state?: null; turnState?: TurnLifecycleState | null; turnId?: string | null; turnOpenedAt?: number | { '.sv': 'timestamp'; } | null; turnUpdatedAt?: number | { '.sv': 'timestamp'; } | null; supportsQueue?: boolean | null; supportsInputInterrupt?: boolean | null; queueDepth?: number; waitingForInput?: boolean; contextUsage?: { percentage?: number; totalTokens: number; maxTokens?: number; } | null; lastError?: string | null; lastHeartbeatAt?: number | { '.sv': 'timestamp'; }; updatedAt?: { '.sv': 'timestamp'; }; } export interface RuntimeInfoPayloadData extends Omit { updatedAt: { '.sv': 'timestamp'; }; } export interface RuntimeActivityPayloadData extends Omit { updatedAt: number | { '.sv': 'timestamp'; }; } interface RTDBAuthOptions { rtdbUrl?: string; firebaseApiKey?: string; } export interface RTDBClientHandle { read(path: string): Promise; write(path: string, data: unknown): Promise; patch(path: string, data: unknown): Promise; remove(path: string): Promise; writeSessionState(conversationId: string, agentId: string, state: Omit): Promise; clearSessionState(conversationId: string, agentId: string): Promise; writeTurnState(conversationId: string, agentId: string, state: Omit): Promise; clearTurnState(conversationId: string, agentId: string): Promise; patchAgentSessionSnapshot(conversationId: string, agentId: string, snapshot: Omit): Promise; writeRuntimeInfo(conversationId: string, agentId: string, payload: Omit): Promise; patchRuntimeInfo(conversationId: string, agentId: string, payload: Partial>): Promise; clearRuntimeInfo(conversationId: string, agentId: string): Promise; readRuntimeActivity(conversationId: string, agentId: string): Promise>; writeRuntimeActivity(conversationId: string, agentId: string, item: CanonRuntimeActivityItem): Promise; removeRuntimeActivityItem(conversationId: string, agentId: string, itemId: string): Promise; clearRuntimeActivity(conversationId: string, agentId: string): Promise; } /** * Creates a scoped RTDB client bound to the given CanonClient's credentials * and returns it. The returned {@link RTDBClientHandle} is the supported API: * thread it explicitly through everything that touches RTDB (pollers, * runtime-state publishers, ...). */ export declare function initRTDBAuth(client: CanonClient, options?: RTDBAuthOptions): RTDBClientHandle; export {};