@devries-cameron20 / t3code-1 / commits / 06ded0b600
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): keep usage hubs that share a host (#23767)

Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Victor Vogel committed Oct 29, 2026 at 13:00 UTC 06ded0b60049cf213c62bf34b0b2ad85efd8d1f4
4 files changed +91 -14
apps/web/src/components/settings/AddUsageLimitSourceDialog.logic.test.ts new
+61
@@ -0,0 +1,61 @@
1 +import { DEFAULT_SERVER_SETTINGS, type ServerSettings } from "@t3tools/contracts";
2 +import { applyServerSettingsPatch } from "@t3tools/shared/serverSettings";
3 +import { describe, expect, it } from "vite-plus/test";
4 +
5 +import { sourceIdFromUrl } from "./AddUsageLimitSourceDialog.logic";
6 +
7 +describe("adding usage limit sources", () => {
8 + it.each([
9 + ["http://proxy.test:8318/hub-a", "http://proxy.test:8318/hub-b"],
10 + ["localhost:8318", "localhost:9318"],
11 + ])("retains saved configurations for %s and %s", (firstUrl, secondUrl) => {
12 + let settings: ServerSettings = DEFAULT_SERVER_SETTINGS;
13 + const sources = [
14 + [firstUrl, "First hub", "first-key"],
15 + [secondUrl, "Second hub", "second-key"],
16 + [`${secondUrl}/extra`, "Third hub", "third-key"],
17 + ] as const;
18 + for (const [url, label, managementKey] of sources) {
19 + const id = sourceIdFromUrl(url, settings.usageLimitSources);
20 + settings = applyServerSettingsPatch(settings, {
21 + usageLimitSources: {
22 + [id]: { kind: "cliproxy", url, label, managementKey, enabled: true },
23 + },
24 + });
25 + }
26 + expect(Object.values(settings.usageLimitSources)).toEqual(
27 + sources.map(([url, label, managementKey]) => ({
28 + kind: "cliproxy",
29 + url,
30 + label,
31 + managementKey,
32 + enabled: true,
33 + })),
34 + );
35 + });
36 +
37 + it("updates a saved hub when its URL is added again", () => {
38 + let settings: ServerSettings = DEFAULT_SERVER_SETTINGS;
39 + for (const managementKey of ["old-key", "new-key"]) {
40 + const url = "http://proxy.test:8318/hub-a";
41 + settings = applyServerSettingsPatch(settings, {
42 + usageLimitSources: {
43 + [sourceIdFromUrl(url, settings.usageLimitSources)]: {
44 + kind: "cliproxy",
45 + url,
46 + managementKey,
47 + enabled: true,
48 + },
49 + },
50 + });
51 + }
52 + expect(Object.values(settings.usageLimitSources)).toEqual([
53 + {
54 + kind: "cliproxy",
55 + url: "http://proxy.test:8318/hub-a",
56 + managementKey: "new-key",
57 + enabled: true,
58 + },
59 + ]);
60 + });
61 +});
apps/web/src/components/settings/AddUsageLimitSourceDialog.logic.ts new
+24
@@ -0,0 +1,24 @@
1 +import { type UnifiedSettings, UsageLimitSourceId } from "@t3tools/contracts";
2 +
3 +export function sourceIdFromUrl(
4 + url: string,
5 + sources: UnifiedSettings["usageLimitSources"],
6 +): UsageLimitSourceId {
7 + const saved = Object.entries(sources).find(([, source]) => source.url === url);
8 + if (saved) return UsageLimitSourceId.make(saved[0]);
9 + let host = url;
10 + try {
11 + host = new URL(url).host;
12 + } catch {}
13 + const slug = host
14 + .toLowerCase()
15 + .replace(/[^a-z0-9.-]+/g, "-")
16 + .replace(/^-+|-+$/g, "");
17 + // Settings merge by ID, so adding a different hub must not replace an existing entry.
18 + const base = `cliproxy-${slug || "hub"}`;
19 + let id = base;
20 + for (let suffix = 2; id in sources; suffix += 1) {
21 + id = `${base}-${suffix}`;
22 + }
23 + return UsageLimitSourceId.make(id);
24 +}
apps/web/src/components/settings/AddUsageLimitSourceDialog.tsx
+5 -14
@@ -1,4 +1,4 @@
1 -import { type EnvironmentId, UsageLimitSourceId } from "@t3tools/contracts";
1 +import type { EnvironmentId, UnifiedSettings } from "@t3tools/contracts";
2 import { useState } from "react";
3
4 import { useUpdateEnvironmentSettings } from "../../hooks/useSettings";
@@ -13,32 +13,23 @@ import {
13 DialogTitle,
14 } from "../ui/dialog";
15 import { Input } from "../ui/input";
16 +import { sourceIdFromUrl } from "./AddUsageLimitSourceDialog.logic";
17 import { SecretInput } from "./SecretInput";
18 import { Label } from "../ui/label";
19
19 -function sourceIdFromUrl(url: string): UsageLimitSourceId {
20 - let host = url;
21 - try {
22 - host = new URL(url).host;
23 - } catch {}
24 - const slug = host
25 - .toLowerCase()
26 - .replace(/[^a-z0-9.-]+/g, "-")
27 - .replace(/^-+|-+$/g, "");
28 - return UsageLimitSourceId.make(`cliproxy-${slug || "hub"}`);
29 -}
30 -
20 /** Send the management key once to server secret storage; settings retain only a redaction marker. */
21 export function AddUsageLimitSourceDialog({
22 open,
23 onOpenChange,
24 environmentId,
25 environmentLabel,
26 + sources,
27 }: {
28 readonly open: boolean;
29 readonly onOpenChange: (open: boolean) => void;
30 readonly environmentId: EnvironmentId;
31 readonly environmentLabel: string;
32 + readonly sources: UnifiedSettings["usageLimitSources"];
33 }) {
34 const updateSettings = useUpdateEnvironmentSettings(environmentId);
35 const [label, setLabel] = useState("");
@@ -55,7 +46,7 @@ export function AddUsageLimitSourceDialog({
46
47 const save = () => {
48 if (!canSave) return;
58 - const id = sourceIdFromUrl(trimmedUrl);
49 + const id = sourceIdFromUrl(trimmedUrl, sources);
50 updateSettings({
51 usageLimitSources: {
52 [id]: {
apps/web/src/components/settings/UsageProviderSettings.tsx
+1
@@ -121,6 +121,7 @@ export function UsageProviderSettings({
121 onOpenChange={setAdding}
122 environmentId={environmentId}
123 environmentLabel={environmentLabel}
124 + sources={sources}
125 />
126 ) : null}
127 </>