(
params: {
credentials: RemoteCredentials
nowMs?: number
organizationUuid?: string | null
providerMode?: Exclude<LeaseProviderMode, 'third_party_provider'>
sessionId: string
},
)
| 228 | } |
| 229 | |
| 230 | export function buildBridgeWorkerLease( |
| 231 | params: { |
| 232 | credentials: RemoteCredentials |
| 233 | nowMs?: number |
| 234 | organizationUuid?: string | null |
| 235 | providerMode?: Exclude<LeaseProviderMode, 'third_party_provider'> |
| 236 | sessionId: string |
| 237 | }, |
| 238 | ): IssuedRuntimeLease { |
| 239 | const issuedAt = params.nowMs ?? Date.now() |
| 240 | const ttlMs = Math.max(0, params.credentials.expires_in * 1000) |
| 241 | const expiresAt = issuedAt + ttlMs |
| 242 | |
| 243 | return { |
| 244 | leaseKind: 'bridge_worker', |
| 245 | leaseId: `bridge_worker:${params.sessionId}:${params.credentials.worker_epoch}`, |
| 246 | sessionId: params.sessionId, |
| 247 | state: ttlMs > 0 ? 'usable' : 'expired', |
| 248 | renewable: true, |
| 249 | renewalOwner: 'bridge_control_plane', |
| 250 | issuedAt, |
| 251 | expiresAt, |
| 252 | renewAfter: computeRenewAfter(issuedAt, expiresAt, BRIDGE_RENEWAL_WINDOW_MS), |
| 253 | graceUntil: expiresAt + BRIDGE_GRACE_WINDOW_MS, |
| 254 | organizationUuid: params.organizationUuid ?? null, |
| 255 | capabilities: ['bridge_worker', 'remote_control'], |
| 256 | executionTarget: 'remote', |
| 257 | providerMode: params.providerMode ?? 'noumena_managed', |
| 258 | degradationMode: 'resume_required', |
| 259 | recoveryMessage: |
| 260 | 'Bridge worker lease expired. Reconnect or resume the remote session to continue.', |
| 261 | metadata: { |
| 262 | apiBaseUrl: params.credentials.api_base_url, |
| 263 | workerEpoch: params.credentials.worker_epoch, |
| 264 | tokenTransport: 'jwt', |
| 265 | ttlSeconds: params.credentials.expires_in, |
| 266 | }, |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | export function buildRemoteSessionLease( |
| 271 | params: { |
no test coverage detected