Skip to content

Commit 1ea74af

Browse files
committed
UI: preserve gateway token when editing URL
1 parent 6b87489 commit 1ea74af

4 files changed

Lines changed: 41 additions & 7 deletions

File tree

ui/src/ui/navigation.browser.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ describe("control UI routing", () => {
198198
expect(window.location.hash).toBe("");
199199
});
200200

201-
it("clears the current token when the gateway URL changes", async () => {
201+
it("preserves the current token when the gateway URL changes", async () => {
202202
const app = mountApp("/ui/overview#token=abc123");
203203
await app.updateComplete;
204204

@@ -211,7 +211,7 @@ describe("control UI routing", () => {
211211
await app.updateComplete;
212212

213213
expect(app.settings.gatewayUrl).toBe("wss://other-gateway.example/openclaw");
214-
expect(app.settings.token).toBe("");
214+
expect(app.settings.token).toBe("abc123");
215215
});
216216

217217
it("keeps a hash token pending until the gateway URL change is confirmed", async () => {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { UiSettings } from "../storage.ts";
2+
3+
export function updateOverviewGatewayUrl(settings: UiSettings, gatewayUrl: string): UiSettings {
4+
return {
5+
...settings,
6+
gatewayUrl,
7+
};
8+
}

ui/src/ui/views/overview.node.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
import { describe, expect, it } from "vitest";
22
import { ConnectErrorDetailCodes } from "../../../../src/gateway/protocol/connect-error-details.js";
3+
import type { UiSettings } from "../storage.ts";
34
import { shouldShowPairingHint } from "./overview-hints.ts";
5+
import { updateOverviewGatewayUrl } from "./overview-settings.ts";
6+
7+
function createSettings(overrides: Partial<UiSettings> = {}): UiSettings {
8+
return {
9+
gatewayUrl: "ws://127.0.0.1:18789",
10+
token: "abc123",
11+
sessionKey: "main",
12+
lastActiveSessionKey: "main",
13+
theme: "system",
14+
chatFocusMode: false,
15+
chatShowThinking: true,
16+
splitRatio: 0.6,
17+
navCollapsed: false,
18+
navGroupsCollapsed: {},
19+
...overrides,
20+
};
21+
}
422

523
describe("shouldShowPairingHint", () => {
624
it("returns true for 'pairing required' close reason", () => {
@@ -37,3 +55,14 @@ describe("shouldShowPairingHint", () => {
3755
).toBe(true);
3856
});
3957
});
58+
59+
describe("updateOverviewGatewayUrl", () => {
60+
it("preserves the current token while editing the gateway URL", () => {
61+
expect(
62+
updateOverviewGatewayUrl(createSettings(), "wss://other-gateway.example/openclaw"),
63+
).toMatchObject({
64+
gatewayUrl: "wss://other-gateway.example/openclaw",
65+
token: "abc123",
66+
});
67+
});
68+
});

ui/src/ui/views/overview.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { GatewayHelloOk } from "../gateway.ts";
77
import { formatNextRun } from "../presenter.ts";
88
import type { UiSettings } from "../storage.ts";
99
import { shouldShowPairingHint } from "./overview-hints.ts";
10+
import { updateOverviewGatewayUrl } from "./overview-settings.ts";
1011

1112
export type OverviewProps = {
1213
connected: boolean;
@@ -205,11 +206,7 @@ export function renderOverview(props: OverviewProps) {
205206
.value=${props.settings.gatewayUrl}
206207
@input=${(e: Event) => {
207208
const v = (e.target as HTMLInputElement).value;
208-
props.onSettingsChange({
209-
...props.settings,
210-
gatewayUrl: v,
211-
token: v.trim() === props.settings.gatewayUrl.trim() ? props.settings.token : "",
212-
});
209+
props.onSettingsChange(updateOverviewGatewayUrl(props.settings, v));
213210
}}
214211
placeholder="ws://100.x.y.z:18789"
215212
/>

0 commit comments

Comments
 (0)