feat(fx): show AI Gateway, Token Pass, Codex, and Grok limits in Usage #48314
Openprivatenumber(GitHub profile, opens in a new tab)wants to merge 7 commits into
main fromrefs/pull/48314/headopened View on GitHubtanstack-source added labelsfeature
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- @@ -134,0 +220,21 @@220+ Effect.provideService(Path.Path, path),221+ );222+ const checkUsageLimits = Effect.gen(function* () {223+ const startGeneration = (yield* Ref.get(cachedUsageRef)).generation;224+ const result = yield* readFxUsageLimits(effectiveConfig, processEnv).pipe(225+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),226+ );227+ yield* Ref.update(cachedUsageRef, (previous) => {228+ // Ignore stale probes that started before a sign-out, team switch, or backend change.229+ if (previous.generation !== startGeneration) return previous;230+ const retained =231+ result.usageLimits?.unavailable?.reason === "probeFailed" &&232+ previous.usageLimits !== undefined &&233+ previous.usageLimits.unavailable === undefined;234+ return {235+ ...previous,236+ usageLimits: retained ? previous.usageLimits : result.usageLimits,237+ needsBackgroundRefresh: result.hadPartialFailure === true,238+ };239+ });240+ return result;
Pushed56b7e25
- @@ -0,0 +230,21 @@230+ name231+ .trim()232+ .toLowerCase()233+ .replaceAll(/[^a-z0-9]+/g, "_")234+ .replaceAll(/^_+|_+$/g, "") || "limit";235+236+const parseExternalUsage = (237+ url: string | null | undefined,238+ label: string | null | undefined,239+ fallbackLabel: string,240+): { readonly label: string; readonly url: string } | undefined => {241+ const trimmed = nonEmptyTrimmed(url ?? undefined);242+ if (trimmed === undefined) return undefined;243+ const parsed = URL.parse(trimmed);244+ if (parsed?.protocol !== "http:" && parsed?.protocol !== "https:") return undefined;245+ return { label: nonEmptyTrimmed(label ?? undefined) ?? fallbackLabel, url: parsed.href };246+};247+248+const isUnsupportedUsageCliError = (code: number, stderr: string): boolean =>249+ code === 2 ||250+ (code !== 0 && /unknown (?:command|option|flag)|invalid .*period|usage:\s*fx/i.test(stderr));@@ -0,0 +319,21 @@319+320+ if (input.backend === "grok" && decoded.grok) {321+ const grok = decoded.grok;322+ const resetsAt = formatEpochMs(grok.resets_at_ms);323+ if (grok.used_percent !== null && grok.used_percent !== undefined) {324+ const kind: ServerProviderUsageWindow["kind"] =325+ grok.period === "weekly" ? "weekly" : grok.period === "monthly" ? "monthly" : "other";326+ const label =327+ grok.period === "weekly"328+ ? "Grok · Weekly"329+ : grok.period === "monthly"330+ ? "Grok · Monthly"331+ : "Grok";332+ windows.push({333+ id: "grok_allowance",334+ kind,335+ label,336+ usedPercent: clampPercent(grok.used_percent),337+ ...(resetsAt === undefined ? {} : { resetsAt }),338+ });339+ } else if (grok.products && grok.products.length > 0) {@@ -0,0 +532,21 @@532+ FX_USAGE_BACKENDS,533+ (backend) =>534+ Effect.gen(function* () {535+ const env = fxBackendEnv(probeEnvironment, backend);536+ const status = Option.getOrUndefined(537+ Option.flatMap(yield* readFxCli(settings, ["status", "--json"], env), decodeFxStatusAuth),538+ );539+ const { signedIn, team } = normalizeFxBackendStatus(backend, status?.auth, status?.team);540+ const results = signedIn === true ? yield* probeFxBackendUsage(settings, env, backend) : [];541+ return { backend, signedIn, team, results };542+ }),543+ { concurrency: "unbounded" },544+ );545+546+ const signedInBackends = backendChecks547+ .filter((entry) => entry.signedIn === true)548+ .map((entry) => entry.backend);549+ const unknownStatusBackends = backendChecks550+ .filter((entry) => entry.signedIn === undefined)551+ .map((entry) => entry.backend);552+ const gatewayTeam = backendChecks.find((entry) => entry.backend === "gateway")?.team;@@ -71,3 +71,10 @@7171 return exhausted.find(7272 (window) => !window.id.startsWith("go_") || model.startsWith("opencode-go/"),7373 );74+ case "fx":75+ return exhausted.find((window) => {76+ // Exhausted Token Pass falls back to AI Gateway team credits on fx login and standard keys.77+ if (window.id === "gateway_token_pass") return false;78+ if (window.id.startsWith("gateway_")) return model.startsWith("gateway:");79+ // Only the main Codex limit blocks Codex chat models; feature-specific limits (e.g. Code Review) do not.80+ if (window.id.startsWith("codex_codex_")) return model.startsWith("codex:");
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed