Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(limits): keep plan-usage.ts within its line pin (fix for #6528)
milind-soni8765a03c7b85
diff --git a/server/codex-credits.ts b/server/codex-credits.tsnew file mode 100644index 0000000000..9090a350fb--- /dev/null+++ b/server/codex-credits.ts@@ -0,0 +1,18 @@+// ChatGPT credits on a Codex account: what the usage endpoint says about them, and whether they carry a send past a+// full window.++/** The ChatGPT usage endpoint's `credits` object: `has_credits`, `unlimited` and `balance`. Anything else reads as+ * no credits. */+export function codexHasCredits(value: unknown): boolean {+ const credits = value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : null;+ if (!credits) return false;+ if (credits.unlimited === true) return true;+ if (credits.has_credits !== true) return false;+ const balance = typeof credits.balance === "string" ? Number(credits.balance) : credits.balance;+ return typeof balance === "number" && Number.isFinite(balance) && balance > 0;+}++/** A local signal that Codex's ChatGPT credits are on and not used up, so a full window does not stop a send here. */+export function codexHasCreditRoom(row: { driver: string; codexCredits?: true }): boolean {+ return row.driver === "codex" && row.codexCredits === true;+}diff --git a/server/limit-resets.ts b/server/limit-resets.tsindex e0f2369a23..2e2e3aa661 100644--- a/server/limit-resets.ts+++ b/server/limit-resets.ts@@ -6,7 +6,8 @@ import { readFileSync } from "node:fs";import { NEAR_LIMIT_PERCENT, type EngineLimit, type EngineLimitsReport, type LimitWindowName } from "../shared/limit-reset.ts";import { writeFileAtomic } from "./atomic.ts";import { LIMIT_POLL_MS, limitReadDue } from "./limit-poll.ts";-import { claudeHasExtraUsageRoom, codexHasCreditRoom, loadPlanUsage, type PlanAccount, type PlanProviderRow, type PlanUsageReport, type PlanWindow } from "./plan-usage.ts";+import { codexHasCreditRoom } from "./codex-credits.ts";+import { claudeHasExtraUsageRoom, loadPlanUsage, type PlanAccount, type PlanProviderRow, type PlanUsageReport, type PlanWindow } from "./plan-usage.ts";import type { RuntimeEvent } from "../shared/runtime-events.ts";import { OPENCODE_GO_MODEL_PREFIX, typedOpenCodeModel } from "../shared/opencode-model-id.ts";diff --git a/server/plan-usage.ts b/server/plan-usage.tsindex 488722fe72..fd6aa67147 100644--- a/server/plan-usage.ts+++ b/server/plan-usage.ts@@ -7,6 +7,7 @@ import { join } from "node:path";import type { InstanceConfigMap } from "./contracts.ts";import { resolveClaudeConfigDir } from "./drivers/claude.ts";import { codexHome } from "./drivers/codex-identity.ts";+import { codexHasCredits } from "./codex-credits.ts";import { antigravityPlanUsage } from "./drivers/antigravity-usage-limits.ts";import { harnessHome, sealedFixture } from "./env-path.ts";@@ -47,22 +48,15 @@ export interface PlanWindows {weekly: PlanWindow;extra: PlanExtra[];models: PlanModelUsage[];- /** Codex only: the ChatGPT account has credits to spend past a full window, or has no limit. */- codexCredits?: true;+ codexCredits?: true; // Codex only: the ChatGPT account has credits to spend past a full window, or has no limit}-export interface PlanProviderRow {+export interface PlanProviderRow extends PlanWindows {id: string;name: string;driver: string;- plan: string | null;ok: boolean;error: string | null;- fiveHour: PlanWindow;- weekly: PlanWindow;- extra: PlanExtra[];- models: PlanModelUsage[];- codexCredits?: true;}export interface PlanUsageReport {@@ -209,22 +203,6 @@ export function parseCodexUsage(body: unknown): PlanWindows {return { ...assigned, extra, models, plan: planLabel(root?.plan_type ?? root?.plan), ...(codexHasCredits(root?.credits) ? { codexCredits: true as const } : {}) };}-/** The ChatGPT usage endpoint's `credits` object: `has_credits`, `unlimited` and `balance`. Anything else reads as- * no credits. */-function codexHasCredits(value: unknown): boolean {- const credits = asRecord(value);- if (!credits) return false;- if (credits.unlimited === true) return true;- if (credits.has_credits !== true) return false;- const balance = typeof credits.balance === "string" ? Number(credits.balance) : credits.balance;- return typeof balance === "number" && Number.isFinite(balance) && balance > 0;-}--/** A local signal that Codex's ChatGPT credits are on and not used up, so a full window does not stop a send here. */-export function codexHasCreditRoom(row: Pick<PlanProviderRow, "driver" | "codexCredits">): boolean {- return row.driver === "codex" && row.codexCredits === true;-}-export function parseGrokUsage(credits: unknown, billing?: unknown, settings?: unknown): PlanWindows {let fiveHour = closedWindow();let weekly = closedWindow();@@ -932,8 +910,7 @@ function okRow(account: PlanAccount, windows: PlanWindows): PlanProviderRow {fiveHour: windows.fiveHour,weekly: windows.weekly,extra: windows.extra,- models: windows.models,- ...(windows.codexCredits ? { codexCredits: true as const } : {}),+ models: windows.models, ...(windows.codexCredits ? { codexCredits: true as const } : {}),};}