Skip to content
Source
Sign inSign up
pingdotgg/t3code

refactor(web): move the /usage-limits panel state out of ChatView #20296

Mergedjuliusmarmingemerged 1 commit intochatview-split/pending-requests-compiled fromrefs/pull/20296/headmerged by juliusmarminge View on GitHub

Showing 3 changed files with 110 additions and 88 deletions.

x
0 of 3 viewed, 3 left
90 additions and 0 deletionsapps/web/src/components/chat/useUsageLimitsPanel.tsAdded
View file
@@ -0,0 +1,90 @@
+import type {
+ EnvironmentId,
+ ProviderInstanceId,
+ ServerProvider,
+ UsageLimitSourceSnapshots,
+} from "@t3tools/contracts";
+import { collectProviderUsageLimits, hasProviderUsageLimits } from "@t3tools/shared/usageLimits";
+import { useState } from "react";
+import { useStableCallback } from "../../hooks/useStableCallback";
+import { toastManager } from "../ui/toast";
+import { usageLimitsBannerItem } from "./ComposerUsageLimits";
+​
+/**
+ * The open /usage-limits panel for one thread, model and turn. Only the open
+ * moment is stored: the rows read live provider data, so a redeemed reset
+ * credit or refreshed probe shows through. Anything that spends quota closes
+ * it: a new turn from any source, or the agent resuming after an approval or
+ * answered question.
+ *
+ * `panelKey` names that thread, model and turn. It is null while the provider
+ * list or the thread itself is unavailable, such as during a reconnect; the
+ * panel then stays hidden rather than being dropped.
+ */
+export function useUsageLimitsPanel(input: {
+ readonly environmentId: EnvironmentId;
+ readonly threadKey: string;
+ readonly panelKey: string | null;
+ readonly providerInstanceId: ProviderInstanceId | null;
+ readonly providerDriver: ServerProvider["driver"] | null;
+ readonly providers: readonly ServerProvider[];