webchat: move serving to relay loopback and tunnel from mac app

This commit is contained in:
Peter Steinberger
2025-12-08 11:54:30 +01:00
parent dc69d20ec9
commit dc22661744
7 changed files with 387 additions and 331 deletions

View File

@@ -17,6 +17,7 @@ import {
setHeartbeatsEnabled,
type WebMonitorTuning,
} from "../provider-web.js";
import { startWebChatServer, getWebChatServer } from "../webchat/server.js";
import { defaultRuntime, type RuntimeEnv } from "../runtime.js";
import { VERSION } from "../version.js";
import {
@@ -818,5 +819,26 @@ Shows token usage per session when the agent reports it; set inbound.reply.agent
}
});
program
.command("webchat")
.description("Start or query the loopback-only web chat server")
.option("--port <port>", "Port to bind (default 18788)")
.option("--json", "Return JSON", false)
.action(async (opts) => {
const port = opts.port ? Number.parseInt(String(opts.port), 10) : undefined;
const server = await startWebChatServer(port);
const payload = {
port: server.port,
token: server.token ?? null,
basePath: "/webchat/",
host: "127.0.0.1",
};
if (opts.json) {
defaultRuntime.log(JSON.stringify(payload));
} else {
defaultRuntime.log(info(`webchat listening on http://127.0.0.1:${server.port}/webchat/`));
}
});
return program;
}