Onboarding: fix webchat URL loopback and canonical session

This commit is contained in:
Yash
2026-02-17 00:17:14 +05:30
committed by Peter Steinberger
parent a02bcb3620
commit 59e0e7e4ff
4 changed files with 222 additions and 10 deletions

View File

@@ -8,7 +8,7 @@ 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 { resolveSessionTranscriptsDirForAgent } from "../config/sessions.js";
import { resolveMainSessionKey, 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";
@@ -454,12 +454,17 @@ function summarizeError(err: unknown): string {
export const DEFAULT_WORKSPACE = DEFAULT_AGENT_WORKSPACE_DIR;
export function resolveControlUiLinks(params: {
type ControlUiLinksParams = {
port: number;
bind?: "auto" | "lan" | "loopback" | "custom" | "tailnet";
customBindHost?: string;
basePath?: string;
}): { httpUrl: string; wsUrl: string } {
};
export function resolveControlUiLinks(params: ControlUiLinksParams): {
httpUrl: string;
wsUrl: string;
} {
const port = params.port;
const bind = params.bind ?? "loopback";
const customBindHost = params.customBindHost?.trim();
@@ -484,3 +489,39 @@ export function resolveControlUiLinks(params: {
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();
}