Revert "Onboarding: fix webchat URL loopback and canonical session"

This reverts commit 59e0e7e4ff.
This commit is contained in:
Gustavo Madeira Santana
2026-02-16 20:29:54 -05:00
parent 726ad45c75
commit 0d1eceb9cf
4 changed files with 19 additions and 231 deletions

View File

@@ -1,11 +1,9 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import {
buildWebchatUrl,
normalizeGatewayTokenInput,
openUrl,
resolveBrowserOpenCommand,
resolveControlUiLinks,
resolveLocalBrowserControlUiLinks,
validateGatewayPasswordInput,
} from "./onboard-helpers.js";
@@ -109,35 +107,6 @@ describe("resolveControlUiLinks", () => {
expect(links.httpUrl).toBe("http://127.0.0.1:18789/");
expect(links.wsUrl).toBe("ws://127.0.0.1:18789");
});
it("coerces lan bind to loopback for local browser links", () => {
const links = resolveLocalBrowserControlUiLinks({
port: 18789,
bind: "lan",
});
expect(links.httpUrl).toBe("http://127.0.0.1:18789/");
expect(links.wsUrl).toBe("ws://127.0.0.1:18789");
});
});
describe("buildWebchatUrl", () => {
it("encodes canonical session key exactly once", () => {
const url = buildWebchatUrl({
httpUrl: "http://127.0.0.1:18789/",
sessionKey: "agent:main:main",
});
expect(url).toBe("http://127.0.0.1:18789/chat?session=agent%3Amain%3Amain");
});
it("preserves base path and appends token in fragment", () => {
const url = buildWebchatUrl({
httpUrl: "http://127.0.0.1:18789/ui/",
sessionKey: "agent:main:main",
token: "abc 123",
});
expect(url).toBe("http://127.0.0.1:18789/ui/chat?session=agent%3Amain%3Amain#token=abc%20123");
expect(url).not.toContain("%2520");
});
});
describe("normalizeGatewayTokenInput", () => {

View File

@@ -1,12 +1,14 @@
import { cancel, isCancel } from "@clack/prompts";
import crypto from "node:crypto";
import fs from "node:fs/promises";
import path from "node:path";
import { inspect } from "node:util";
import { cancel, isCancel } from "@clack/prompts";
import { DEFAULT_AGENT_WORKSPACE_DIR, ensureAgentWorkspace } from "../agents/workspace.js";
import type { OpenClawConfig } from "../config/config.js";
import type { RuntimeEnv } from "../runtime.js";
import type { NodeManagerChoice, OnboardMode, ResetScope } from "./onboard-types.js";
import { DEFAULT_AGENT_WORKSPACE_DIR, ensureAgentWorkspace } from "../agents/workspace.js";
import { CONFIG_PATH } from "../config/config.js";
import { resolveMainSessionKey, resolveSessionTranscriptsDirForAgent } from "../config/sessions.js";
import { resolveSessionTranscriptsDirForAgent } from "../config/sessions.js";
import { callGateway } from "../gateway/call.js";
import { normalizeControlUiBasePath } from "../gateway/control-ui-shared.js";
import { pickPrimaryLanIPv4, isValidIPv4 } from "../gateway/net.js";
@@ -14,7 +16,6 @@ import { isSafeExecutableValue } from "../infra/exec-safety.js";
import { pickPrimaryTailnetIPv4 } from "../infra/tailnet.js";
import { isWSL } from "../infra/wsl.js";
import { runCommandWithTimeout } from "../process/exec.js";
import type { RuntimeEnv } from "../runtime.js";
import { stylePromptTitle } from "../terminal/prompt-style.js";
import {
CONFIG_DIR,
@@ -25,7 +26,6 @@ import {
} from "../utils.js";
import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from "../utils/message-channel.js";
import { VERSION } from "../version.js";
import type { NodeManagerChoice, OnboardMode, ResetScope } from "./onboard-types.js";
export function guardCancel<T>(value: T | symbol, runtime: RuntimeEnv): T {
if (isCancel(value)) {
@@ -454,17 +454,12 @@ function summarizeError(err: unknown): string {
export const DEFAULT_WORKSPACE = DEFAULT_AGENT_WORKSPACE_DIR;
type ControlUiLinksParams = {
export function resolveControlUiLinks(params: {
port: number;
bind?: "auto" | "lan" | "loopback" | "custom" | "tailnet";
customBindHost?: string;
basePath?: string;
};
export function resolveControlUiLinks(params: ControlUiLinksParams): {
httpUrl: string;
wsUrl: string;
} {
}): { httpUrl: string; wsUrl: string } {
const port = params.port;
const bind = params.bind ?? "loopback";
const customBindHost = params.customBindHost?.trim();
@@ -489,39 +484,3 @@ export function resolveControlUiLinks(params: ControlUiLinksParams): {
wsUrl: `ws://${host}:${port}${wsPath}`,
};
}
export function resolveLocalBrowserControlUiLinks(params: ControlUiLinksParams): {
httpUrl: string;
wsUrl: string;
} {
const bind = params.bind === "lan" ? "loopback" : params.bind;
return resolveControlUiLinks({
...params,
bind,
});
}
export function resolveCanonicalMainSessionKey(cfg: OpenClawConfig): string {
return resolveMainSessionKey(cfg);
}
export function buildWebchatUrl(params: {
httpUrl: string;
sessionKey: string;
token?: string;
}): string {
const base = new URL(params.httpUrl);
if (!base.pathname.endsWith("/")) {
base.pathname = `${base.pathname}/`;
}
const chatUrl = new URL("chat", base);
chatUrl.searchParams.set("session", params.sessionKey.trim());
const token = params.token?.trim();
if (token) {
chatUrl.hash = `token=${encodeURIComponent(token)}`;
}
return chatUrl.toString();
}