feat(usage): add OpenCode provider priced from models.dev #6014
ClosedSkyVence(GitHub profile, opens in a new tab)wants to merge 5 commits into
main fromrefs/pull/6014/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
- apps/server/src/usage/UsageService.ts line 228Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -183,3 +205,13 @@183205 );184206 });185207208+ /**209+ * Loads OpenCode's go/zen rates from models.dev and merges them over the210+ * LiteLLM table.211+ *212+ * Mirrors `ensureRates`: fresh copy preferred, then the on-disk snapshot,213+ * and silence (rather than failure) when neither exists. models.dev keys its214+ * entries by `providerID/modelID`, so go and zen prices for one model id stay215+ * distinct. The same `RatesCacheFile` shape is reused under its own path.216+ */217+ const ensureOpenCodeRates = Effect.fn("UsageService.ensureOpenCodeRates")(function* () {
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/server/src/usage/UsageService.test.ts lines 18 to 18OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,18 @@1+// @effect-diagnostics nodeBuiltinImport:off2+import { expect, it } from "@effect/vitest";3+import * as NodeServices from "@effect/platform-node/NodeServices";4+import * as NodeCrypto from "node:crypto";5+import * as NodeFS from "node:fs";6+import * as NodeOS from "node:os";7+import * as NodePath from "node:path";8+import { UsageDay, type UsageSummaryInput } from "@t3tools/contracts";9+import { HostProcessEnvironment } from "@t3tools/shared/hostProcess";10+import * as Duration from "effect/Duration";11+import * as Effect from "effect/Effect";12+import * as Schema from "effect/Schema";13+import * as TestClock from "effect/testing/TestClock";14+import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http";15+16+import * as ServerConfig from "../config.ts";17+import * as ServerSettings from "../serverSettings.ts";18+import { make as makeUsageService } from "./UsageService.ts";
- @@ -340,7 +465,13 @@340465 const windowStartMs =341466 (hourlyWindow?.sinceTimeMs ?? DateTime.toEpochMillis(windowStart.value)) - MTIME_SLACK_MS;342467468+ // Always re-compose the served table, regardless of which source refreshed469+ // this pass: a LiteLLM refresh on its own clock must not drop the still470+ // valid OpenCode go/zen overlay (and vice versa).471+ const servedRates = mergeRateTables(litellmRates, openCodeRates);472+343473 const aggregator = new UsageAggregator({344474 timeZone: input.timeZone,345475 sinceDay: input.sinceDay,346476 untilDay: input.untilDay,477+ rates: servedRates,
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
ee04446b-efa0-4fc2-8d51-9bcc27decb04You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share