mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 13:01:42 +03:00
refactor(webchat): SwiftUI-only WebChat UI
# Conflicts: # apps/macos/Package.swift
This commit is contained in:
@@ -26,8 +26,7 @@ vi.mock("../gateway/call.js", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("../gateway/server.js", () => ({
|
||||
startGatewayServer: (port: number, opts: unknown) =>
|
||||
startGatewayServer(port, opts),
|
||||
startGatewayServer: (port: number) => startGatewayServer(port),
|
||||
}));
|
||||
|
||||
vi.mock("../globals.js", () => ({
|
||||
|
||||
+1
-15
@@ -42,10 +42,6 @@ export function registerGatewayCli(program: Command) {
|
||||
.command("gateway")
|
||||
.description("Run the WebSocket Gateway")
|
||||
.option("--port <port>", "Port for the gateway WebSocket", "18789")
|
||||
.option(
|
||||
"--webchat-port <port>",
|
||||
"Port for the loopback WebChat HTTP server (default 18788)",
|
||||
)
|
||||
.option(
|
||||
"--token <token>",
|
||||
"Shared token required in connect.params.auth.token (default: CLAWDIS_GATEWAY_TOKEN env if set)",
|
||||
@@ -63,16 +59,6 @@ export function registerGatewayCli(program: Command) {
|
||||
defaultRuntime.error("Invalid port");
|
||||
defaultRuntime.exit(1);
|
||||
}
|
||||
const webchatPort = opts.webchatPort
|
||||
? Number.parseInt(String(opts.webchatPort), 10)
|
||||
: undefined;
|
||||
if (
|
||||
webchatPort !== undefined &&
|
||||
(Number.isNaN(webchatPort) || webchatPort <= 0)
|
||||
) {
|
||||
defaultRuntime.error("Invalid webchat port");
|
||||
defaultRuntime.exit(1);
|
||||
}
|
||||
if (opts.force) {
|
||||
try {
|
||||
const killed = forceFreePort(port);
|
||||
@@ -143,7 +129,7 @@ export function registerGatewayCli(program: Command) {
|
||||
process.once("SIGINT", onSigint);
|
||||
|
||||
try {
|
||||
server = await startGatewayServer(port, { webchatPort });
|
||||
server = await startGatewayServer(port);
|
||||
} catch (err) {
|
||||
if (err instanceof GatewayLockError) {
|
||||
defaultRuntime.error(`Gateway failed to start: ${err.message}`);
|
||||
|
||||
@@ -4,7 +4,6 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
const sendCommand = vi.fn();
|
||||
const statusCommand = vi.fn();
|
||||
const loginWeb = vi.fn();
|
||||
const startWebChatServer = vi.fn(async () => ({ port: 18788 }));
|
||||
const callGateway = vi.fn();
|
||||
|
||||
const runtime = {
|
||||
@@ -25,10 +24,6 @@ vi.mock("../gateway/call.js", () => ({
|
||||
callGateway,
|
||||
randomIdempotencyKey: () => "idem-test",
|
||||
}));
|
||||
vi.mock("../webchat/server.js", () => ({
|
||||
startWebChatServer,
|
||||
getWebChatServer: () => null,
|
||||
}));
|
||||
vi.mock("./deps.js", () => ({
|
||||
createDefaultDeps: () => ({}),
|
||||
}));
|
||||
@@ -54,16 +49,6 @@ describe("cli program", () => {
|
||||
expect(statusCommand).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("starts webchat server and prints json", async () => {
|
||||
const program = buildProgram();
|
||||
runtime.log.mockClear();
|
||||
await program.parseAsync(["webchat", "--json"], { from: "user" });
|
||||
expect(startWebChatServer).toHaveBeenCalled();
|
||||
expect(runtime.log).toHaveBeenCalledWith(
|
||||
JSON.stringify({ port: 18788, basePath: "/", host: "127.0.0.1" }),
|
||||
);
|
||||
});
|
||||
|
||||
it("runs nodes list and calls node.pair.list", async () => {
|
||||
callGateway.mockResolvedValue({ pending: [], paired: [] });
|
||||
const program = buildProgram();
|
||||
|
||||
@@ -26,7 +26,6 @@ import { danger, info, setVerbose } from "../globals.js";
|
||||
import { loginWeb, logoutWeb } from "../provider-web.js";
|
||||
import { defaultRuntime } from "../runtime.js";
|
||||
import { VERSION } from "../version.js";
|
||||
import { startWebChatServer } from "../webchat/server.js";
|
||||
import { registerCronCli } from "./cron-cli.js";
|
||||
import { createDefaultDeps } from "./deps.js";
|
||||
import { registerDnsCli } from "./dns-cli.js";
|
||||
@@ -362,43 +361,6 @@ Shows token usage per session when the agent reports it; set inbound.agent.conte
|
||||
);
|
||||
});
|
||||
|
||||
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);
|
||||
if (!server) {
|
||||
const targetPort = port ?? 18788;
|
||||
const msg = `webchat failed to start on http://127.0.0.1:${targetPort}/`;
|
||||
if (opts.json) {
|
||||
defaultRuntime.error(
|
||||
JSON.stringify({ error: msg, port: targetPort }),
|
||||
);
|
||||
} else {
|
||||
defaultRuntime.error(danger(msg));
|
||||
}
|
||||
defaultRuntime.exit(1);
|
||||
return;
|
||||
}
|
||||
const payload = {
|
||||
port: server.port,
|
||||
basePath: "/",
|
||||
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}/`),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
const browser = program
|
||||
.command("browser")
|
||||
.description("Manage clawd's dedicated browser (Chrome/Chromium)")
|
||||
|
||||
Reference in New Issue
Block a user