Skip to content

Commit 43b7a7b

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-26852
2 parents e2cb8a9 + 6d82a22 commit 43b7a7b

14 files changed

Lines changed: 297 additions & 15 deletions

File tree

‎apps/desktop/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@t3tools/desktop",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"private": true,
55
"type": "module",
66
"main": "dist-electron/boot.cjs",
@@ -22,7 +22,7 @@
2222
"@t3tools/tailscale": "workspace:*",
2323
"dbus-next": "0.10.2",
2424
"effect": "catalog:",
25-
"electron": "44.9.3",
25+
"electron": "44.10.0",
2626
"electron-store": "^8.2.0",
2727
"electron-updater": "^6.8.9",
2828
"electron-webauthn": "catalog:",

‎apps/desktop/src/settings/DesktopClientSettings.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const clientSettings: ClientSettings = {
6464
sidebarThreadSortOrder: "created_at",
6565
boringSidebarEnabled: false,
6666
boringSidebarMultilineRows: false,
67+
threadDetailsUsageEnabled: false,
6768
legacySidebarEnabled: false,
6869
sidebarWorkingShelfEnabled: false,
6970
loadBalancingEnabled: false,

‎apps/server/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "t3",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"license": "MIT",
55
"repository": {
66
"type": "git",

‎apps/web/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@t3tools/web",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"private": true,
55
"type": "module",
66
"scripts": {

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,9 @@ export default function ChatView(props: ChatViewProps) {
12281228
const canChangeEnvironment =
12291229
hasMultipleEnvironments && !envLocked && draftId !== null && !draftThread?.promotedTo;
12301230

1231+
const threadDetailsUsageEnabled = useClientSettings(
1232+
(settings) => settings.threadDetailsUsageEnabled,
1233+
);
12311234
const loadBalancingSettings = useClientSettings((settings) => ({
12321235
loadBalancingEnabled: settings.loadBalancingEnabled,
12331236
loadBalancingWeights: settings.loadBalancingWeights,
@@ -3770,6 +3773,16 @@ export default function ChatView(props: ChatViewProps) {
37703773
onAddProjectScript={saveProjectScriptStable}
37713774
onUpdateProjectScript={updateProjectScriptStable}
37723775
onDeleteProjectScript={deleteProjectScriptStable}
3776+
usage={
3777+
threadDetailsUsageEnabled
3778+
? {
3779+
providerInstanceId: activeProviderInstanceId,
3780+
providers: providerStatuses,
3781+
sources: serverConfig?.usageLimitSources ?? EMPTY_USAGE_LIMIT_SOURCES,
3782+
contextWindow: activeContextWindow,
3783+
}
3784+
: undefined
3785+
}
37733786
/>
37743787

37753788
<PullRequestThreadDialogHost

‎apps/web/src/components/chat/ThreadDetailsPanel.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { ThreadDetailsSection } from "./ThreadDetailsSection";
2323
import { ThreadAutomationsPanel } from "./ThreadAutomationsPanel";
2424
import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl";
2525
import { ThreadServersPanel } from "./ThreadServersPanel";
26+
import { ThreadDetailsUsage, type ThreadDetailsUsageInput } from "./ThreadDetailsUsage";
2627

2728
const GitActionsControl = memo(BaseGitActionsControl);
2829

@@ -67,6 +68,8 @@ interface ThreadDetailsPanelProps extends Pick<
6768
input: NewProjectScriptInput,
6869
) => Promise<ProjectScriptActionResult>;
6970
onDeleteProjectScript: (scriptId: string) => Promise<ProjectScriptActionResult>;
71+
/** Set only while the Labs usage readout is on. */
72+
usage?: ThreadDetailsUsageInput | undefined;
7073
}
7174

7275
export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
@@ -195,6 +198,8 @@ export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
195198
threadId={props.threadId}
196199
/>
197200
) : null}
201+
202+
{props.usage ? <ThreadDetailsUsage {...props.usage} /> : null}
198203
</>
199204
)}
200205
</ThreadDetailsCard>
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
import type {
2+
ProviderInstanceId,
3+
ServerProvider,
4+
ServerProviderUsageWindow,
5+
UsageLimitSourceSnapshots,
6+
} from "@t3tools/contracts";
7+
import {
8+
collectProviderUsageLimits,
9+
formatDuration,
10+
type LimitPace,
11+
limitsNotice,
12+
paceOf,
13+
remainingPercent,
14+
} from "@t3tools/shared/usageLimits";
15+
import type { ReactNode } from "react";
16+
17+
import { usePrimarySettings } from "../../hooks/useSettings";
18+
import { useNowMinute } from "../../hooks/useNowMinute";
19+
import { type ContextWindowSnapshot, formatContextWindowTokens } from "../../lib/contextWindow";
20+
import { cn } from "../../lib/utils";
21+
import { formatUpcomingTimestamp } from "../../timestampFormat";
22+
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
23+
import { ThreadDetailsSection } from "./ThreadDetailsSection";
24+
25+
const PACE_LABEL: Record<LimitPace, string> = {
26+
ahead: "Ahead of pace",
27+
on: "On pace",
28+
under: "Under pace",
29+
};
30+
31+
export interface ThreadDetailsUsageInput {
32+
readonly providerInstanceId: ProviderInstanceId | null;
33+
readonly providers: readonly ServerProvider[];
34+
readonly sources: UsageLimitSourceSnapshots;
35+
readonly contextWindow: ContextWindowSnapshot | null;
36+
}
37+
38+
/**
39+
* Labs readout of the selected provider's limit windows and the thread's context window.
40+
* Every row reads as room left, so a longer bar always means more headroom.
41+
*/
42+
export function ThreadDetailsUsage({
43+
providerInstanceId,
44+
providers,
45+
sources,
46+
contextWindow,
47+
}: ThreadDetailsUsageInput) {
48+
const nowMinute = useNowMinute();
49+
const now = Date.parse(`${nowMinute}:00Z`);
50+
const report =
51+
providerInstanceId !== null
52+
? collectProviderUsageLimits(providerInstanceId, providers, sources, now)
53+
: null;
54+
// Only this instance's data: the report keeps one instance per login, and any other entry may be
55+
// a different login or workspace, so fall back to the instance's own snapshot.
56+
const limits =
57+
report?.accounts.find((entry) => entry.instanceId === providerInstanceId)?.limits ??
58+
providers.find((provider) => provider.instanceId === providerInstanceId)?.usageLimits;
59+
const notice = limits ? limitsNotice(limits) : null;
60+
if (!limits && !contextWindow) return null;
61+
62+
return (
63+
<ThreadDetailsSection
64+
headingId="thread-details-usage-heading"
65+
title="Usage"
66+
showHeading={false}
67+
>
68+
<div className="grid grid-cols-[auto_minmax(3rem,1fr)_auto] gap-x-3 text-xs">
69+
{notice ? (
70+
<UsageRow
71+
label="Limits"
72+
left={null}
73+
value="Unavailable"
74+
tooltip={<span className="text-foreground">{notice}</span>}
75+
/>
76+
) : null}
77+
{limits && !notice
78+
? limits.windows.map((window) => <LimitRow key={window.id} window={window} now={now} />)
79+
: null}
80+
{contextWindow ? <ContextRow usage={contextWindow} spaced={limits !== undefined} /> : null}
81+
</div>
82+
</ThreadDetailsSection>
83+
);
84+
}
85+
86+
function LimitRow({
87+
window,
88+
now,
89+
}: {
90+
readonly window: ServerProviderUsageWindow;
91+
readonly now: number;
92+
}) {
93+
const timestampFormat = usePrimarySettings((settings) => settings.timestampFormat);
94+
const left = remainingPercent(window);
95+
const pace = paceOf(window, now);
96+
const resetsAt = window.resetsAt ? Date.parse(window.resetsAt) : Number.NaN;
97+
return (
98+
<UsageRow
99+
label={window.label}
100+
left={left}
101+
tooltip={
102+
<>
103+
<span className="text-foreground">
104+
{window.label}: {left}% left
105+
</span>
106+
{window.resetsAt && resetsAt > now ? (
107+
<span className="text-muted-foreground">
108+
Resets in {formatDuration(resetsAt - now)} ·{" "}
109+
{formatUpcomingTimestamp(window.resetsAt, timestampFormat, now)}
110+
</span>
111+
) : null}
112+
{pace ? <span className="text-muted-foreground">{PACE_LABEL[pace]}</span> : null}
113+
</>
114+
}
115+
/>
116+
);
117+
}
118+
119+
function ContextRow({
120+
usage,
121+
spaced,
122+
}: {
123+
readonly usage: ContextWindowSnapshot;
124+
readonly spaced: boolean;
125+
}) {
126+
const maxTokens = usage.maxTokens ?? null;
127+
const left =
128+
maxTokens !== null && usage.usedPercentage !== null
129+
? Math.round(100 - Math.max(0, Math.min(100, usage.usedPercentage)))
130+
: null;
131+
const used = formatContextWindowTokens(usage.usedTokens);
132+
return (
133+
<UsageRow
134+
label="Context"
135+
left={left}
136+
muted
137+
className={cn(spaced && "mt-2")}
138+
tooltip={
139+
<>
140+
{left !== null ? <span className="text-foreground">Context: {left}% left</span> : null}
141+
<span className={left !== null ? "text-muted-foreground" : "text-foreground"}>
142+
{maxTokens !== null
143+
? `${used} of ${formatContextWindowTokens(maxTokens)} tokens used`
144+
: `${used} tokens used`}
145+
</span>
146+
</>
147+
}
148+
value={left === null ? used : undefined}
149+
/>
150+
);
151+
}
152+
153+
/** One label, hairline, and value row; the whole row opens the details tooltip. */
154+
function UsageRow({
155+
label,
156+
left,
157+
tooltip,
158+
value,
159+
muted = false,
160+
className,
161+
}: {
162+
readonly label: string;
163+
readonly left: number | null;
164+
readonly tooltip: ReactNode;
165+
/** Replaces the percentage when there is none. */
166+
readonly value?: string | undefined;
167+
readonly muted?: boolean;
168+
readonly className?: string | undefined;
169+
}) {
170+
const tone = left === null ? null : left <= 10 ? "error" : left <= 20 ? "warning" : null;
171+
return (
172+
<Tooltip>
173+
<TooltipTrigger
174+
render={
175+
<div
176+
tabIndex={0}
177+
aria-label={`${label}: ${value ?? `${left}% left`}`}
178+
className={cn(
179+
"col-span-3 grid h-6 cursor-default grid-cols-subgrid items-center rounded-lg px-2.5 outline-none hover:bg-black/[0.035] focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring data-popup-open:bg-black/[0.035] dark:hover:bg-white/[0.08] dark:data-popup-open:bg-white/[0.08]",
180+
className,
181+
)}
182+
/>
183+
}
184+
>
185+
<span className="max-w-28 truncate text-muted-foreground">{label}</span>
186+
{left !== null ? (
187+
<span className="relative h-[3px] rounded-full bg-muted-foreground/30 dark:bg-muted-foreground/20">
188+
{left > 0 ? (
189+
<span
190+
className={cn(
191+
"absolute inset-y-0 left-0 rounded-full",
192+
tone === "error"
193+
? "bg-error"
194+
: tone === "warning"
195+
? "bg-warning"
196+
: muted
197+
? "bg-muted-foreground"
198+
: "bg-foreground/80",
199+
)}
200+
style={{ width: `max(${left}%, 6px)` }}
201+
/>
202+
) : null}
203+
</span>
204+
) : null}
205+
<span
206+
className={cn(
207+
// Text-only rows span the bar column so they never widen the shared value column.
208+
"text-end font-medium tabular-nums",
209+
left === null && "col-span-2",
210+
tone === "error"
211+
? "text-error-foreground"
212+
: tone === "warning"
213+
? "text-warning-foreground"
214+
: left === null
215+
? "text-muted-foreground"
216+
: "text-foreground/80",
217+
)}
218+
>
219+
{value ?? `${left}%`}
220+
</span>
221+
</TooltipTrigger>
222+
{/* Rows sit 8px inside the card; clear its edge instead of overlapping it. */}
223+
<TooltipPopup side="left" sideOffset={16}>
224+
<div className="flex flex-col gap-0.5">{tooltip}</div>
225+
</TooltipPopup>
226+
</Tooltip>
227+
);
228+
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function LabsSettingsPanel() {
1818
<SettingsSection id="beta" title="Beta">
1919
<BoringSidebarRow />
2020
<BoringSidebarMultilineRow />
21+
<ThreadDetailsUsageRow />
2122
{/* Clerk is only mounted when this build has T3 Connect. */}
2223
{hasCloudPublicConfig() ? <GuestLinksRowWithSignIn /> : <GuestLinksRow />}
2324
<LinkedEnvironmentsRow />
@@ -69,6 +70,26 @@ function BoringSidebarMultilineRow() {
6970
);
7071
}
7172

73+
function ThreadDetailsUsageRow() {
74+
const settings = useScopedSettings();
75+
const updateSettings = useUpdateScopedSettings();
76+
return (
77+
<SettingsRow
78+
{...searchableSetting("thread-details-usage")}
79+
description="Show the current provider's usage limits and the thread's context window at the bottom of the thread details card."
80+
control={
81+
<Switch
82+
checked={settings.threadDetailsUsageEnabled}
83+
onCheckedChange={(checked) =>
84+
updateSettings({ threadDetailsUsageEnabled: Boolean(checked) })
85+
}
86+
aria-label="Usage in thread details"
87+
/>
88+
}
89+
/>
90+
);
91+
}
92+
7293
/** Signed out of T3 Connect, the row offers to sign in instead of its switch. */
7394
function GuestLinksRowWithSignIn() {
7495
const { isSignedIn } = useAuth();

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,12 @@ export const SETTINGS_SEARCH_ITEMS = [
437437
to: "/settings/labs",
438438
searchTerms: ["beta boring sidebar folder rows multiline branch pull request details"],
439439
},
440+
{
441+
id: "thread-details-usage",
442+
title: "Usage in thread details",
443+
to: "/settings/labs",
444+
searchTerms: ["beta limits 5 hour weekly context window tokens quota rate limit"],
445+
},
440446
{
441447
id: "guest-links",
442448
title: "Guest links",

‎docs/user/usage.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ current model's limits without leaving the conversation. The result opens above
116116
closes when you dismiss it or send your next message. It uses the same snapshot as **Usage → Limits**, so it does not run the agent or refresh
117117
anything. The command is offered only for providers that appear under **Usage → Limits**.
118118

119+
To keep them in view, turn on **Settings → Labs → Usage in thread details** on web and desktop.
120+
The bottom of the thread details card then shows how much is left in each limit window of the
121+
current provider account and in the thread's context window. Some windows, such as a weekly Opus
122+
limit, count only one model. Hover a row to see when it resets, your pace, or
123+
the token count.
124+
119125
OpenCode Go reports its session, weekly, and monthly allowance when OpenCode runs locally in
120126
the environment. T3 cannot report limits for external OpenCode servers because their credentials
121127
belong to the remote server. Limits need an OpenCode Go API key, or an OpenCode Console connected

0 commit comments

Comments
 (0)