Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(codex): price a Fast row as its base model
Bugfixer 2b52b7f5f754f
diff --git a/server/drivers/codex-catalog.ts b/server/drivers/codex-catalog.tsindex 062b88fba4..dd82d0d735 100644--- a/server/drivers/codex-catalog.ts+++ b/server/drivers/codex-catalog.ts@@ -8,6 +8,7 @@ import type { ModelCatalog } from "../contracts.ts";import { qualifiedModelLabel } from "../contracts.ts";import { killCliTree, spawnCli } from "../procs.ts";import { codexHome } from "./codex-identity.ts";+import { TIERED_ID } from "./codex-tier.ts";import { unconfirmedModelCatalog } from "../startup-model-catalog.ts";import { codexLocalProviderArgs, mergeLocalInject } from "./local-inject.ts";@@ -39,10 +40,6 @@ export function encodeCodexSelection(provider: string, model: string): string {return `${provider}${SEP}${model}`;}-/** An official row run on one of its model's service tiers (`gpt-5.5+priority`, the catalog's Fast). The driver sends- * the tier as turn/start's `serviceTierForTurn`: that turn only, so the thread's own tier stays and a plain row is standard. */-const TIERED_ID = /^(.+)\+([a-z][a-z0-9_-]*)$/i;-export function decodeCodexSelection(id: string | null | undefined): {model: string | null;modelProvider: string | null;diff --git a/server/drivers/codex-tier.ts b/server/drivers/codex-tier.tsnew file mode 100644index 0000000000..885d66afd9--- /dev/null+++ b/server/drivers/codex-tier.ts@@ -0,0 +1,3 @@+/** An official Codex row run on one of its model's service tiers (`gpt-5.5+priority`, the catalog's Fast). The driver sends+ * the tier as turn/start's `serviceTierForTurn`: that turn only, so the thread's own tier stays and a plain row is standard. */+export const TIERED_ID = /^(.+)\+([a-z][a-z0-9_-]*)$/i;diff --git a/server/model-prices.test.ts b/server/model-prices.test.tsindex 622bffe0ff..c704a8aba4 100644--- a/server/model-prices.test.ts+++ b/server/model-prices.test.ts@@ -74,6 +74,15 @@ describe("what the ledger books for a settled turn", () => {expect(ledgerCost({ driverKind: "acp", model: "fake-model", input: 1_000_000, output: 0, costUsd: null }, operator)).toEqual({ costUsd: 10, costSource: "estimated" });});+ it("prices a Codex Fast row as its base model", () => {+ const fast = { ...codex, model: "gpt-5.5+priority", costUsd: null };+ expect(ledgerCost(fast, null)).toEqual(ledgerCost({ ...codex, costUsd: null }, null));+ const operator: PriceList = { "codex/gpt-5.5": { inputPerMillion: 1, outputPerMillion: 2 }, default: { inputPerMillion: 10, outputPerMillion: 10 } };+ expect(ledgerCost(fast, operator).costUsd).toBeCloseTo(1 * 1 + 0.1 * 2, 9);+ expect(estimatePriceFor({ driverKind: "codex", model: "gpt-5.5+priority" }, { "codex/gpt-5.5+priority": { inputPerMillion: 7, outputPerMillion: 7 } })?.inputPerMillion).toBe(7);+ expect(estimatePriceFor({ driverKind: "acp", model: "gpt-5.5+priority" }, null)).toBeNull();+ });+it("books an unpriced model as unpriced, not as free", () => {expect(ledgerCost({ driverKind: "grokAgent", model: "fake-model", input: 5000, output: 100, costUsd: null }, null)).toEqual({ costUsd: null });expect(ledgerCost({ driverKind: "codex", model: "gpt-5.3-codex-spark", input: 5000, output: 100, costUsd: undefined }, { "claude-sonnet-5": { inputPerMillion: 1, outputPerMillion: 1 } })).toEqual({ costUsd: null });diff --git a/server/model-prices.ts b/server/model-prices.tsindex cd81a2334b..1e809fde09 100644--- a/server/model-prices.ts+++ b/server/model-prices.ts@@ -1,4 +1,5 @@import type { ModelPrice, PriceList, PricedTurn } from "./prices.ts";+import { TIERED_ID } from "./drivers/codex-tier.ts";import { currentPrices } from "./model-manifest/manifest.ts";import { billableFor } from "./prices.ts";@@ -30,8 +31,11 @@ export function listPriceFor(model: string, at: Date = new Date()): ModelPrice |export type CostSource = "reported" | "estimated";export function estimatePriceFor(turn: Pick<PricedTurn, "driverKind" | "model">, operatorPrices: PriceList | null, at: Date = new Date()): ModelPrice | null {+ // A Codex Fast row (`gpt-5.5+priority`) costs what its base model costs; the usage row keeps the full id.+ const model = turn.driverKind === "codex" ? TIERED_ID.exec(turn.model)?.[1] ?? turn.model : turn.model;return operatorPrices?.[`${turn.driverKind}/${turn.model}`] ?? operatorPrices?.[turn.model] ??- listPriceFor(turn.model, at) ?? operatorPrices?.default ?? null;+ operatorPrices?.[`${turn.driverKind}/${model}`] ?? operatorPrices?.[model] ??+ listPriceFor(model, at) ?? operatorPrices?.default ?? null;}export function ledgerCost(