-
Notifications
You must be signed in to change notification settings - Fork 5.3k
feat: show provider usage limits with /usage-limits #9875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chrisdeeming
wants to merge
18
commits into
pingdotgg:main
Choose a base branch
from
chrisdeeming:t3code/add-provider-usage-limits-command
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,315
−128
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2be7bda
feat: show provider usage limits with /usage-limits
chrisdeeming 7f5b75a
fix: clear stale usage limits and surface failed sources
chrisdeeming 8183ada
fix: republish limit commands on source refresh and drop stale panels
chrisdeeming 50666af
fix: keep the limits panel live and out of New Task
chrisdeeming 3836513
feat: open usage limits when the command is picked
chrisdeeming 819ff67
fix: never drop a provider update and advertise failed sources
chrisdeeming e7a71ac
fix: tell sibling instances apart and scope panel clears
chrisdeeming c8d8115
fix(mobile): let a notice-only limits card be dismissed
chrisdeeming a1227e7
fix: scope the on-send panel clear to the sending thread
chrisdeeming b0faf85
fix(mobile): keep the limits panel when a reply fails
chrisdeeming af50a48
fix(mobile): name pooled accounts in the limits card
chrisdeeming 78b805b
fix: identify the panel's thread exactly
chrisdeeming d1b7828
fix(web): do not repeat a driver-named instance in the panel heading
chrisdeeming a23a1f4
fix(web): clear the limits panel only once the turn starts
chrisdeeming ee64aaa
fix: claim /usage-limits only where T3 has limits data
chrisdeeming 4ada290
fix: advertise /usage-limits only to clients that answer it
chrisdeeming 7115102
fix(web): keep the typed command while the panel cannot open
chrisdeeming f370809
fix: only offer the menu action for a text-only draft
chrisdeeming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
apps/mobile/src/features/threads/ComposerUsageLimits.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| import type { EnvironmentId, UsageLimitsReport } from "@t3tools/contracts"; | ||
| import { Pressable, ScrollView, useWindowDimensions, View } from "react-native"; | ||
|
|
||
| import { SymbolView } from "../../components/AppSymbol"; | ||
| import { AppText as Text } from "../../components/AppText"; | ||
| import { AccountLimits, ResetCredits } from "../usage/UsageLimitsSection"; | ||
|
|
||
| const DRIVER_LABEL: Partial<Record<string, string>> = { codex: "Codex", claudeAgent: "Claude" }; | ||
|
|
||
| /** | ||
| * The /usage-limits result, docked above the composer. It is the Usage → Limits | ||
| * card one size down, so the two read as the same thing. The surface is opaque | ||
| * because nothing blurs the feed behind it. | ||
| */ | ||
| export function ComposerUsageLimits({ | ||
| report, | ||
| environmentId, | ||
| onClose, | ||
| }: { | ||
| readonly report: UsageLimitsReport; | ||
| readonly environmentId: EnvironmentId; | ||
| readonly onClose: () => void; | ||
| }) { | ||
| const now = Date.parse(report.createdAt); | ||
| const { height } = useWindowDimensions(); | ||
| const close = ( | ||
| <Pressable | ||
| accessibilityLabel="Dismiss usage limits" | ||
| accessibilityRole="button" | ||
| hitSlop={12} | ||
| onPress={onClose} | ||
| className="-me-1 p-1 active:opacity-60" | ||
| > | ||
| <SymbolView name="xmark" size={14} tintColorClassName="accent-icon-muted" type="monochrome" /> | ||
| </Pressable> | ||
| ); | ||
| return ( | ||
| <View className="overflow-hidden rounded-[20px] border-continuous bg-card"> | ||
| <ScrollView | ||
| bounces={false} | ||
| showsVerticalScrollIndicator={false} | ||
| style={{ maxHeight: Math.round(height * 0.4) }} | ||
| > | ||
| {report.accounts.map((account, index) => { | ||
| const driverLabel = DRIVER_LABEL[account.driver] ?? String(account.driver); | ||
| return ( | ||
| <AccountLimits | ||
| key={account.id} | ||
| dense | ||
| first={index === 0} | ||
| driver={account.driver} | ||
| label={driverLabel} | ||
| // Siblings need telling apart: a custom instance without a name shows its | ||
| // id, and a pooled account shows its hub and account id. | ||
| instanceLabel={ | ||
| account.instanceId | ||
| ? account.displayName?.trim() || | ||
| (String(account.instanceId) !== String(account.driver) | ||
| ? account.instanceId | ||
| : driverLabel) | ||
| : account.label | ||
| } | ||
| detail={account.plan} | ||
| limits={account.limits} | ||
| now={now} | ||
| trailing={index === 0 ? close : undefined} | ||
| footer={ | ||
| account.instanceId && account.limits.resetCredits ? ( | ||
| <ResetCredits | ||
| dense | ||
| environmentId={environmentId} | ||
| instanceId={account.instanceId} | ||
| credits={account.limits.resetCredits} | ||
| now={now} | ||
| /> | ||
| ) : undefined | ||
| } | ||
| /> | ||
| ); | ||
| })} | ||
| {report.accounts.length === 0 ? ( | ||
| // Nothing but notices, so the close control needs a row of its own. | ||
| <View className="flex-row items-center gap-3 px-4 pt-3"> | ||
| <Text className="min-w-0 flex-1 text-base text-foreground">Usage limits</Text> | ||
| {close} | ||
| </View> | ||
| ) : null} | ||
| {report.notices.map((notice) => ( | ||
| <Text | ||
| key={notice} | ||
| className={ | ||
| report.accounts.length === 0 | ||
| ? "px-4 py-3 text-xs text-foreground-muted" | ||
| : "border-t border-border-subtle px-4 py-3 text-xs text-foreground-muted" | ||
| } | ||
| > | ||
| {notice} | ||
| </Text> | ||
| ))} | ||
| </ScrollView> | ||
| </View> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.