(token: string)
| 89 | * test seam where a test wants to bypass the boot graph. |
| 90 | */ |
| 91 | export const makeLocalApiHandler = async (token: string): Promise<LocalApiHandler> => { |
| 92 | const { executor, plugins } = await getExecutorBundle(); |
| 93 | |
| 94 | // Build the fixed-execution seam ONCE (one executor + one engine). The same |
| 95 | // Layer is the `fixedExecution` seam declaration AND lives in `boot` so the |
| 96 | // fixed middleware's residual `FixedExecutionProvider` resolves there — exactly |
| 97 | // as self-host declares `db: SelfHostDbProvider` and puts the handle in `boot`. |
| 98 | const fixedExecution = localFixedExecutionLayer(executor); |
| 99 | |
| 100 | // The authoritative identity gate for the typed `/api`: validates the boot |
| 101 | // bearer token and resolves the one local Principal. The Bun shell |
| 102 | // (`serve.ts`) fast-path-rejects unauthenticated requests with the same token. |
| 103 | const identity = makeLocalIdentityLayer(token); |
| 104 | |
| 105 | const { toWebHandler } = ExecutorApp.make({ |
| 106 | plugins, |
| 107 | providers: { |
| 108 | // Single-user: validates the boot bearer token and resolves the one local |
| 109 | // Principal. Boot-scoped (`RIdentity = never`), captured once. |
| 110 | identity, |
| 111 | // The ONE boot executor + engine, served directly — local's fixed |
| 112 | // execution model (no per-request scoped-executor rebuild). |
| 113 | fixedExecution, |
| 114 | // account omitted (local has no account API). |
| 115 | // mcp omitted (local's /mcp is its own in-process surface in serve.ts). |
| 116 | errorCapture: ErrorCaptureLive, |
| 117 | }, |
| 118 | extensions: { |
| 119 | // Swagger UI at /docs, over the root-mounted spec (matches the served |
| 120 | // paths — local serves the API at root; the Bun shell strips `/api`). |
| 121 | routes: [HttpApiSwagger.layer(composePluginApi(plugins), { path: "/docs" })], |
| 122 | }, |
| 123 | // No mountPrefix: local serves the typed API at root and the Bun shell |
| 124 | // strips the `/api` prefix before dispatching here. Local renders identity |
| 125 | // failures as text (matching self-host); the single-user provider never |
| 126 | // produces one in practice. |
| 127 | config: { failure: textFailureStrategy }, |
| 128 | // The boot-scoped context provideMerge'd under everything: the identity |
| 129 | // provider (captured once by the fixed-execution middleware) + the fixed |
| 130 | // execution seam (the one executor + engine + extension map) + the |
| 131 | // artifact-usage observer (this HTTP plane is the console UI's data layer, |
| 132 | // so operations it serves file as `via: "ui"`). |
| 133 | boot: Layer.mergeAll( |
| 134 | identity, |
| 135 | fixedExecution, |
| 136 | Layer.succeed(ArtifactUsageObserver)((action) => |
| 137 | localAnalytics.record(`artifact_${action}`, { via: "ui" }), |
| 138 | ), |
| 139 | ), |
| 140 | }); |
| 141 | |
| 142 | const web = toWebHandler(); |
| 143 | return { handler: web.handler, dispose: web.dispose }; |
| 144 | }; |
no test coverage detected