import type { AgentManager } from '../tools/agent/index.js'; import type { UserAuthManager } from '../security/user-auth.js'; import { type PairingTokenAuthenticator } from '../security/http-auth.js'; import type { ControlPlaneGateway } from '../control-plane/index.js'; import type { GatewayMethodCatalog, GatewayMethodDescriptor } from '../control-plane/index.js'; import type { RuntimeEventDomain } from '../runtime/events/index.js'; import type { DistributedRuntimeManager } from '../runtime/remote/index.js'; import { type AuthenticatedPrincipal } from './http-policy.js'; export interface ControlPlaneWebSocketData { readonly channel: 'control-plane'; authToken: string; principalId: string | null; principalKind: 'user' | 'bot' | 'service' | 'token' | null; admin: boolean; scopes: readonly string[]; readonly domains: readonly RuntimeEventDomain[]; readonly clientKind: 'tui' | 'web' | 'slack' | 'discord' | 'ntfy' | 'webhook' | 'telegram' | 'google-chat' | 'signal' | 'whatsapp' | 'telephony' | 'imessage' | 'msteams' | 'bluebubbles' | 'mattermost' | 'matrix' | 'daemon'; readonly remoteAddress?: string | undefined; clientId?: string | undefined; authenticated: boolean; } export interface DaemonControlPlaneContext { readonly authToken: () => string | null; /** * Per-pairing token authenticator. When present, a named per-device token is * checked (and its revocation honored) before the legacy shared token; absent * ⇒ only the shared token / user sessions authenticate. */ readonly pairingTokens?: PairingTokenAuthenticator | undefined; readonly userAuth: UserAuthManager; readonly agentManager: AgentManager; readonly controlPlaneGateway: ControlPlaneGateway; readonly gatewayMethods: GatewayMethodCatalog; readonly distributedRuntime: DistributedRuntimeManager; readonly host: string; readonly port: number; readonly trustProxyEnabled: () => boolean; readonly dispatchApiRoutes: (req: Request) => Promise; readonly parseJsonBody: (req: Request) => Promise | Response>; readonly requireAuthenticatedSession: (req: Request) => { username: string; roles: readonly string[]; } | null; } interface UpgradeCapableServer { upgrade(req: Request, options?: { data?: unknown; }): boolean; } export declare class DaemonControlPlaneHelper { private readonly context; /** Live WS 'call' invocations (full lifetime incl. response buffering). */ private wsCallsInFlight; /** Calls refused at the in-flight cap (cumulative, for ops visibility). */ private wsCallsRefused; /** Events dropped to stalled WS consumers (cumulative). */ private wsEventsDropped; constructor(context: DaemonControlPlaneContext); /** Retained-context footprint of the WS call path, for tests and ops output. */ wsCallStats(): { inFlight: number; refused: number; eventsDropped: number; }; private trustProxyEnabled; extractAuthToken(req: Request): string; /** The shared operator-auth context: shared token + per-pairing tokens + user sessions. */ private authContext; checkAuth(req: Request): boolean; requireAuthenticatedSession(req: Request): { username: string; roles: readonly string[]; } | null; requireAdmin(req: Request): Response | null; requireRemotePeer(req: Request, scope?: string): Promise; describeAuthenticatedPrincipal(token: string): AuthenticatedPrincipal | null; getGrantedGatewayScopes(includeWrite: boolean): readonly string[]; validateGatewayInvocation(descriptor: GatewayMethodDescriptor, context?: { readonly principalKind?: 'user' | 'bot' | 'service' | 'token' | 'remote-peer' | undefined; readonly scopes?: readonly string[] | undefined; readonly admin?: boolean | undefined; }): { status: number; ok: false; body: Record; } | null; tryUpgradeControlPlaneWebSocket(req: Request, server: UpgradeCapableServer): Response | 'upgraded' | null; handleControlPlaneWebSocketOpen(ws: { data: ControlPlaneWebSocketData; send(message: string): void; getBufferedAmount?(): number; }): void; handleControlPlaneWebSocketMessage(ws: { data: ControlPlaneWebSocketData; send(message: string): void; }, message: string | Buffer | ArrayBuffer | Uint8Array): Promise; handleControlPlaneWebSocketClose(ws: { data: ControlPlaneWebSocketData; }): void; invokeWebSocketControlPlaneCall(input: { readonly authToken: string; readonly method: string; readonly path: string; readonly query?: Record | undefined; readonly body?: unknown | undefined; readonly context?: { readonly principalKind?: 'user' | 'bot' | 'service' | 'token' | 'remote-peer' | undefined; readonly admin?: boolean | undefined; readonly scopes?: readonly string[] | undefined; }; /** Synthesized dispatches behind this call. 0 = a real client. */ readonly synthesizedDepth?: number | undefined; }): Promise<{ status: number; ok: boolean; body: unknown; }>; invokeGatewayMethodCall(input: { readonly authToken: string; readonly methodId: string; readonly query?: Record | undefined; readonly body?: unknown | undefined; readonly context?: { readonly principalId?: string | undefined; readonly principalKind?: 'user' | 'bot' | 'service' | 'token' | 'remote-peer' | undefined; readonly admin?: boolean | undefined; readonly scopes?: readonly string[] | undefined; readonly clientKind?: string | undefined; /** * True when a person asked for this, now. Set ONLY by transports that * can honestly claim it; scheduled work and triggers leave it unset * because they cannot. It gates the explicit-user-request refusal and * starts a new untrusted-content turn, see * control-plane/routes/explicit-user-request.ts and * security/turn-boundary.ts. */ readonly explicitUserRequest?: boolean | undefined; }; /** Synthesized dispatches behind this call. 0 = a real client. */ readonly synthesizedDepth?: number | undefined; }): Promise<{ status: number; ok: boolean; body: unknown; }>; } export {}; //# sourceMappingURL=control-plane.d.ts.map