summaryrefslogtreecommitdiffhomepage
path: root/packages/host-bin
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-06 23:18:13 +0900
committerAdam Malczewski <[email protected]>2026-06-06 23:18:13 +0900
commit395d7565b46416e9914db099b9a4c226f4c95648 (patch)
tree8b3c58bfb0db9bbe0025f6d2029885fa2bee92d0 /packages/host-bin
parent3e95b26ee2928c40db581bed4c138d3fa842b753 (diff)
downloaddispatch-395d7565b46416e9914db099b9a4c226f4c95648.tar.gz
dispatch-395d7565b46416e9914db099b9a4c226f4c95648.zip
refactor(transport-http,host-bin): transport-http owns its Bun.serve (fix log scope)
Make transport-http a full-fidelity extension that runs its own Bun.serve inside activate(host) — symmetric with transport-ws. The Hono app is now built with the extension-scoped host, so all HTTP edge logs are correctly attributed extensionId=transport-http instead of the host-bin __host__ scope (verified live in the journal). - transport-http: createTransportHttpExtension() factory; activate builds the app + Bun.serve, reads host.config httpPort (?? 24203); deactivate stops it. - host-bin: drops the HTTP Bun.serve + createServer call; config.ts maps BACKEND_PORT/PORT -> httpPort. host-bin now serves no transport (both transports self-serve); boot log -> 'Dispatch booted'. - +5 bun lifecycle tests wired into test:bun. No contract change (composition wiring). Verified live: HTTP serves on :24203; journal edge logs now scoped transport-http. typecheck clean, 498 vitest + 89 bun, biome clean.
Diffstat (limited to 'packages/host-bin')
-rw-r--r--packages/host-bin/src/config.ts8
-rw-r--r--packages/host-bin/src/main.ts15
2 files changed, 12 insertions, 11 deletions
diff --git a/packages/host-bin/src/config.ts b/packages/host-bin/src/config.ts
index cbf7bce..cf6b0ce 100644
--- a/packages/host-bin/src/config.ts
+++ b/packages/host-bin/src/config.ts
@@ -20,6 +20,14 @@ export function envToConfigMap(
map["provider.openai-compat.model"] = model;
}
+ const httpPort = env.BACKEND_PORT ?? env.PORT;
+ if (httpPort !== undefined) {
+ const n = Number(httpPort);
+ if (Number.isFinite(n) && n > 0) {
+ map.httpPort = n;
+ }
+ }
+
return map;
}
diff --git a/packages/host-bin/src/main.ts b/packages/host-bin/src/main.ts
index 68cbbdd..b18f105 100644
--- a/packages/host-bin/src/main.ts
+++ b/packages/host-bin/src/main.ts
@@ -24,7 +24,7 @@ import { createSqliteStorage, extension as storageSqliteExt } from "@dispatch/st
import { createLoadedExtensionsExtension } from "@dispatch/surface-loaded-extensions";
import { createSurfaceRegistryExtension } from "@dispatch/surface-registry";
import { extension as toolReadFileExt } from "@dispatch/tool-read-file";
-import { createServer, extension as transportHttpExt } from "@dispatch/transport-http";
+import { createTransportHttpExtension } from "@dispatch/transport-http";
import { createTransportWsExtension } from "@dispatch/transport-ws";
import type { ChildHandle } from "./collector-supervisor.js";
import { createCollectorSupervisor } from "./collector-supervisor.js";
@@ -63,7 +63,7 @@ const CORE_EXTENSIONS: readonly Extension[] = [
credentials: [{ name: "opencode", providerId: "openai-compat" }],
}),
sessionOrchestratorExt,
- transportHttpExt,
+ createTransportHttpExtension(),
// Surface extensions — dependency order: surface-registry first, then consumers.
createSurfaceRegistryExtension(),
createTransportWsExtension(),
@@ -125,13 +125,6 @@ async function boot(): Promise<void> {
}
}
- const hostAPI = host.getHostAPI();
- const app = createServer(hostAPI);
-
- // Port precedence: BACKEND_PORT (the rewrite's assigned port) → PORT → default.
- const port = Number(process.env.BACKEND_PORT) || Number(process.env.PORT) || 24203;
- const server = Bun.serve({ fetch: app.fetch, port });
-
const shutdown = async () => {
logger.info("Shutting down — draining collector");
await supervisor.stop();
@@ -140,8 +133,8 @@ async function boot(): Promise<void> {
process.on("SIGINT", shutdown);
process.on("SIGTERM", shutdown);
- logger.info(`Dispatch listening on http://localhost:${server.port}`);
- console.info(`Dispatch listening on http://localhost:${server.port}`);
+ logger.info("Dispatch booted");
+ console.info("Dispatch booted");
}
boot().catch((err) => {