mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
Combine the completed comment cleanup from 319 stacked PRs into one change against `main`, so the full CI suite validates the combined result once. This replaces the previous audit stack; no additional audit work is included. The change shortens redundant comments across 2,753 source and shell-snapshot files (25,235 net lines removed). Conflicts preserve current-main executable code. Runtime behavior, test assertions, directives, licenses, generated notices, SAFETY rationales, and compatibility markers are preserved. The audit tracker remains local, outside the repository. Validation: - Equivalent source/emitted AST and executable tokens across all 2,750 source files, with separate checks for embedded shell, SQL, JavaScript, CSS, and generated fixtures. - Identical executable lines in the three shell snapshots; protected comments unchanged. - Changed-code quality gate passed with no new findings. - 358 tests passed, 2 skipped across 23 focused test files. - `git diff --check` passed.
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
import { MODEL_PRICING, normalizeModelForPricing } from './codex-model-pricing'
|
|
|
|
/** Long-context counts are subsets of the corresponding token totals. */
|
|
export type CodexBillableTokens = {
|
|
inputTokens: number
|
|
cachedInputTokens: number
|
|
outputTokens: number
|
|
longContextInputTokens: number
|
|
longContextCachedInputTokens: number
|
|
longContextOutputTokens: number
|
|
}
|
|
|
|
function priceTokens(
|
|
rates: { input: number; cachedInput: number; output: number },
|
|
inputTokens: number,
|
|
cachedInputTokens: number,
|
|
outputTokens: number
|
|
): number {
|
|
const clampedCached = Math.min(Math.max(cachedInputTokens, 0), Math.max(inputTokens, 0))
|
|
// Cached tokens are included in input; subtract them to avoid charging both rates.
|
|
const nonCachedInputTokens = Math.max(inputTokens - clampedCached, 0)
|
|
return (
|
|
nonCachedInputTokens * rates.input +
|
|
clampedCached * rates.cachedInput +
|
|
Math.max(outputTokens, 0) * rates.output
|
|
)
|
|
}
|
|
|
|
export function estimateCostUsd(model: string | null, tokens: CodexBillableTokens): number | null {
|
|
const normalized = normalizeModelForPricing(model)
|
|
if (!normalized) {
|
|
return null
|
|
}
|
|
const pricing = MODEL_PRICING[normalized]
|
|
if (!pricing.longContext) {
|
|
return (
|
|
priceTokens(pricing, tokens.inputTokens, tokens.cachedInputTokens, tokens.outputTokens) /
|
|
1_000_000
|
|
)
|
|
}
|
|
const longInput = Math.min(tokens.longContextInputTokens, tokens.inputTokens)
|
|
const longCached = Math.min(tokens.longContextCachedInputTokens, tokens.cachedInputTokens)
|
|
const longOutput = Math.min(tokens.longContextOutputTokens, tokens.outputTokens)
|
|
return (
|
|
(priceTokens(
|
|
pricing,
|
|
tokens.inputTokens - longInput,
|
|
tokens.cachedInputTokens - longCached,
|
|
tokens.outputTokens - longOutput
|
|
) +
|
|
priceTokens(pricing.longContext, longInput, longCached, longOutput)) /
|
|
1_000_000
|
|
)
|
|
}
|