Skip to content

Commit f1e90e3

Browse files
refactor(web): move usage provider controls to settings (pingdotgg#9599)
1 parent caab2fd commit f1e90e3

9 files changed

Lines changed: 176 additions & 234 deletions

File tree

‎apps/mobile/src/features/settings/components/SettingsSection.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import { View } from "react-native";
44
import { AppText as Text } from "../../../components/AppText";
55

66
export function SettingsSection(props: {
7-
readonly title: string;
7+
readonly title?: string;
88
readonly children: ReactNode;
99
/** Force the grouped card background; Android otherwise lists options flat. */
1010
readonly card?: boolean;
1111
}) {
1212
return (
1313
<View className="gap-2">
14-
<Text className="px-2 text-sm font-t3-medium text-foreground-muted">{props.title}</Text>
14+
{props.title ? (
15+
<Text className="px-2 text-sm font-t3-medium text-foreground-muted">{props.title}</Text>
16+
) : null}
1517
<View
1618
className={
1719
props.card

‎apps/mobile/src/features/usage/UsageLimitsSection.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ export function UsageLimitsSection() {
255255
return (
256256
<>
257257
{sources.map((source) => (
258-
<SettingsSection key={source.key} title={source.label} card>
258+
<SettingsSection key={source.key} card>
259259
{source.error ? (
260260
<Text className="p-4 text-sm text-foreground-muted">{source.error}</Text>
261261
) : source.accounts.length === 0 ? (

apps/web/src/components/usage/AddUsageLimitSourceDialog.tsx renamed to apps/web/src/components/settings/AddUsageLimitSourceDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function sourceIdFromUrl(url: string): UsageLimitSourceId {
3535
}
3636

3737
/**
38-
* Adds a CLIProxyAPI hub as a usage-limit source on one environment. The
38+
* Adds a CLIProxyAPI hub from provider settings on one environment. The
3939
* management key is sent once and kept in that server's secret store;
4040
* settings only ever carry a redaction marker for it afterwards.
4141
*/

‎apps/web/src/components/settings/ProviderSettingsPanel.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
6868
import { stackedThreadToast, toastManager } from "../ui/toast";
6969
import { AddProviderInstanceDialog } from "./AddProviderInstanceDialog";
7070
import { ProviderInstanceCard } from "./ProviderInstanceCard";
71+
import { UsageProviderSettings } from "./UsageProviderSettings";
7172
import { ProviderSetupSection, readAntigravityAuthMethod } from "./ProviderSetupSection";
7273
import { DRIVER_OPTIONS, getDriverOption } from "./providerDriverMeta";
7374
import { providerSettingsTabClassName } from "./providerSettingsTabs";
@@ -241,7 +242,8 @@ function ProviderSettingsPanelContent(target: ProviderSettingsTarget) {
241242
)?.environmentId;
242243
useEffect(() => {
243244
if (
244-
searchTargetId === searchableSetting("provider-health-check-interval").id &&
245+
(searchTargetId === searchableSetting("provider-health-check-interval").id ||
246+
searchTargetId === searchableSetting("usage-providers").id) &&
245247
!selectedEnvironmentCanRenderSettings &&
246248
searchableEnvironmentId !== undefined
247249
) {
@@ -997,6 +999,14 @@ export function EnvironmentProviderSettings({
997999
</div>
9981000
</SettingsSection>
9991001

1002+
<UsageProviderSettings
1003+
key={environmentId}
1004+
environmentId={environmentId}
1005+
environmentLabel={environmentLabel}
1006+
sources={settings.usageLimitSources}
1007+
readOnly={readOnly}
1008+
/>
1009+
10001010
<SettingsSection title="Advanced">
10011011
<SettingsRow
10021012
id={searchableSetting("provider-health-check-interval").id}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import type { EnvironmentId, UnifiedSettings } from "@t3tools/contracts";
2+
import { PlusIcon } from "lucide-react";
3+
import { useState } from "react";
4+
5+
import { useUpdateEnvironmentSettings } from "../../hooks/useSettings";
6+
import {
7+
AlertDialog,
8+
AlertDialogClose,
9+
AlertDialogDescription,
10+
AlertDialogFooter,
11+
AlertDialogHeader,
12+
AlertDialogPopup,
13+
AlertDialogTitle,
14+
} from "../ui/alert-dialog";
15+
import { Button } from "../ui/button";
16+
import { AddUsageLimitSourceDialog } from "./AddUsageLimitSourceDialog";
17+
import { searchableSetting } from "./settingsSearch";
18+
import { SettingsRow, SettingsSection } from "./settingsLayout";
19+
20+
/** Hub management follows the selected device and access rules of provider settings. */
21+
export function UsageProviderSettings({
22+
environmentId,
23+
environmentLabel,
24+
sources,
25+
readOnly,
26+
}: {
27+
readonly environmentId: EnvironmentId;
28+
readonly environmentLabel: string;
29+
readonly sources: UnifiedSettings["usageLimitSources"];
30+
readonly readOnly: boolean;
31+
}) {
32+
const updateSettings = useUpdateEnvironmentSettings(environmentId);
33+
const [adding, setAdding] = useState(false);
34+
const entries = Object.entries(sources);
35+
36+
return (
37+
<>
38+
<SettingsSection
39+
{...searchableSetting("usage-providers")}
40+
description="Connect a CLIProxyAPI hub to show its accounts on Usage → Limits."
41+
headerAction={
42+
!readOnly ? (
43+
<Button size="xs" variant="outline" onClick={() => setAdding(true)}>
44+
<PlusIcon className="size-3" aria-hidden />
45+
Add hub
46+
</Button>
47+
) : null
48+
}
49+
>
50+
{entries.length === 0 ? (
51+
<SettingsRow title="No usage providers configured." />
52+
) : (
53+
entries.map(([id, source]) => {
54+
const label = source.label?.trim() || source.url;
55+
return (
56+
<SettingsRow
57+
key={id}
58+
title={label}
59+
description={
60+
<span className="break-all">
61+
CLI Proxy{source.enabled ? "" : " · Disabled"}
62+
{label !== source.url ? ` · ${source.url}` : ""}
63+
</span>
64+
}
65+
control={
66+
!readOnly ? (
67+
<RemoveUsageProviderButton
68+
label={label}
69+
onConfirm={() => updateSettings({ usageLimitSources: { [id]: null } })}
70+
/>
71+
) : null
72+
}
73+
/>
74+
);
75+
})
76+
)}
77+
</SettingsSection>
78+
{adding && !readOnly ? (
79+
<AddUsageLimitSourceDialog
80+
open
81+
onOpenChange={setAdding}
82+
environmentId={environmentId}
83+
environmentLabel={environmentLabel}
84+
/>
85+
) : null}
86+
</>
87+
);
88+
}
89+
90+
/** Removing a hub deletes its stored management key, so it requires confirmation. */
91+
function RemoveUsageProviderButton({
92+
label,
93+
onConfirm,
94+
}: {
95+
readonly label: string;
96+
readonly onConfirm: () => void;
97+
}) {
98+
const [open, setOpen] = useState(false);
99+
return (
100+
<>
101+
<Button size="xs" variant="ghost" onClick={() => setOpen(true)}>
102+
Remove
103+
</Button>
104+
<AlertDialog open={open} onOpenChange={setOpen}>
105+
<AlertDialogPopup>
106+
<AlertDialogHeader>
107+
<AlertDialogTitle>Remove {label}?</AlertDialogTitle>
108+
<AlertDialogDescription>
109+
The hub's management key is deleted from this server. Its accounts leave the Limits
110+
view; the hub itself is untouched. Add it again with the URL and key to bring them
111+
back.
112+
</AlertDialogDescription>
113+
</AlertDialogHeader>
114+
<AlertDialogFooter>
115+
<AlertDialogClose render={<Button variant="outline" />}>Cancel</AlertDialogClose>
116+
<Button
117+
variant="destructive"
118+
onClick={() => {
119+
setOpen(false);
120+
onConfirm();
121+
}}
122+
>
123+
Remove hub
124+
</Button>
125+
</AlertDialogFooter>
126+
</AlertDialogPopup>
127+
</AlertDialog>
128+
</>
129+
);
130+
}

‎apps/web/src/components/settings/settingsSearch.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ describe("searchSettings", () => {
101101
]);
102102
});
103103

104+
it.each(["usage providers", "CLIProxyAPI", "CLI proxy hub", "management key"])(
105+
"finds usage-provider management by %s",
106+
(query) => {
107+
expect(searchSettings(query)[0]).toMatchObject({
108+
id: "usage-providers",
109+
to: "/settings/providers",
110+
});
111+
},
112+
);
113+
104114
it("returns no results for an empty query", () => {
105115
expect(searchSettings(" ", ITEMS)).toEqual([]);
106116
});

‎apps/web/src/components/settings/settingsSearch.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,15 @@ export const SETTINGS_SEARCH_ITEMS = [
324324
"agents cli codex claude cursor grok opencode antigravity google sign in sign out install subscription instances authentication api key models configuration binary path config directory endpoint arguments environment variables display name accent color custom favorite hidden auto compact",
325325
],
326326
},
327+
{
328+
id: "usage-providers",
329+
title: "Usage providers",
330+
to: "/settings/providers",
331+
searchTerms: [
332+
"usage sources CLIProxyAPI CLI proxy hub quota subscription limits management key add remove",
333+
],
334+
providerSettingsOnly: true,
335+
},
327336
{
328337
id: "provider-health-check-interval",
329338
title: "Health check interval",

0 commit comments

Comments
 (0)