| 139 | } |
| 140 | |
| 141 | export class RuntimeServer { |
| 142 | private readonly handlers = new Map<string, RegisteredRuntimeHandler>() |
| 143 | private readonly connections = new Map<string, ConnectedRuntimeConnection>() |
| 144 | private readonly notifications = new Set<string>() |
| 145 | private readonly runtimeStopHandlers: RuntimeStopHandler[] = [] |
| 146 | private readonly agentProviders: AgentProviderSummary[] |
| 147 | private readonly agentProviderResolvers = new Set<() => AgentProviderSummary[]>() |
| 148 | private readonly protocolVersion: number |
| 149 | private readonly serverName: string |
| 150 | private readonly serverVersion?: string |
| 151 | private readonly notificationLogSize: number |
| 152 | private readonly clientRequestRetentionMs: number |
| 153 | private readonly notificationLog: RuntimeNotification[] = [] |
| 154 | private readonly initializedConnections = new Set<string>() |
| 155 | private readonly clientRequests = new Map<string, RetainedRuntimeRequest>() |
| 156 | private nextNotificationCursor = 1 |
| 157 | readonly supervisor: RuntimeSupervisor |
| 158 | |
| 159 | constructor(options: RuntimeServerOptions) { |
| 160 | this.serverName = options.serverName |
| 161 | this.serverVersion = options.serverVersion |
| 162 | this.protocolVersion = options.protocolVersion ?? 1 |
| 163 | this.notificationLogSize = Math.max(0, Math.floor(options.notificationLogSize ?? DEFAULT_NOTIFICATION_LOG_SIZE)) |
| 164 | this.clientRequestRetentionMs = Math.max(0, Math.floor(options.clientRequestRetentionMs ?? DEFAULT_CLIENT_REQUEST_RETENTION_MS)) |
| 165 | this.agentProviders = options.agentProviders ?? [] |
| 166 | this.supervisor = new RuntimeSupervisor({ checkpointStore: options.checkpointStore, livenessProbe: options.livenessProbe }) |
| 167 | |
| 168 | this.register("initialize", (params, context) => this.initialize(params as RuntimeInitializeParams, context), { |
| 169 | validateParams: validateRuntimeInitializeParams, |
| 170 | }) |
| 171 | this.register("server/status/read", (_params, context) => this.serverStatus(context)) |
| 172 | this.register("subscription/update", (params, context) => this.updateSubscription(params as RuntimeSubscriptionUpdateParams, context), { |
| 173 | validateParams: validateRuntimeSubscriptionUpdateParams, |
| 174 | }) |
| 175 | this.register("agent/provider/list", () => this.agentProviders) |
| 176 | this.register("agent/provider/status", (params) => this.agentProviderStatus(params as AgentProviderIdParams), { |
| 177 | validateParams: validateAgentProviderIdParams, |
| 178 | }) |
| 179 | this.register("runtime/list", (params) => this.listRuntimes(params as RuntimeListParams), { |
| 180 | validateParams: validateRuntimeListParams, |
| 181 | }) |
| 182 | this.register("runtime/read", (params) => this.readRuntime(params as RuntimeIdParams), { |
| 183 | validateParams: validateRuntimeIdParams, |
| 184 | }) |
| 185 | this.register("runtime/reconcile", (params) => this.reconcileRuntime(params as RuntimeIdParams), { |
| 186 | validateParams: validateRuntimeIdParams, |
| 187 | }) |
| 188 | this.register("runtime/stop", (params, context) => this.stopRuntime(params as RuntimeStopParams, context), { |
| 189 | validateParams: validateRuntimeStopParams, |
| 190 | }) |
| 191 | this.registerNotification("runtime/created") |
| 192 | this.registerNotification("runtime/updated") |
| 193 | this.registerNotification("runtime/completed") |
| 194 | this.registerNotification("runtime/failed") |
| 195 | this.registerNotification("runtime/stopped") |
| 196 | this.registerNotification("connection/lagged") |
| 197 | } |
| 198 |
nothing calls this directly
no outgoing calls
no test coverage detected