(spec: ComputerSpec | null)
| 301 | function authorizeAction(request: Request, action: string, env: CloudboxBindings): Response | null { |
| 302 | if (request.headers.get("x-cloudbox-demo") === "1") return null; |
| 303 | if (env.CLOUDBOX_INTERNAL_TOKEN && request.headers.get("x-cloudbox-internal-token") === env.CLOUDBOX_INTERNAL_TOKEN) return null; |
| 304 | const token = env.CLOUDBOX_API_TOKEN; |
| 305 | if (!token) return null; |
| 306 | const got = request.headers.get("authorization")?.replace(/^Bearer\s+/i, "") ?? request.headers.get("x-cloudbox-token"); |
| 307 | return got === token ? null : jsonErrorResponse(401, "unauthorized", "valid Cloudbox token required"); |
| 308 | } |
| 309 | |
| 310 | function isPublicDemoSpec(spec: ComputerSpec | null): boolean { |
| 311 | return !!spec?.name && spec.name === "agent-launch-readiness" && typeof spec.runId === "string" && spec.runId.startsWith("browser-"); |
| 312 | } |
| 313 | |
| 314 | function validateSpec(spec: ComputerSpec | null): Response | null { |
no test coverage detected