Skip to content

Commit 24f41b0

Browse files
committed
refactor(provider): complete host-match dedupe, rename usage formatter
1 parent e21ed5b commit 24f41b0

3 files changed

Lines changed: 8 additions & 9 deletions

File tree

‎packages/opencode-go/src/models.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ export const OPENCODE_GO_MODEL_IDS: readonly string[] = OPENCODE_GO_MODELS.map(
6363

6464
export const OPENCODE_GO_DEFAULT_MODEL: GoModelId = "kimi-k2.7-code";
6565

66-
export const PROTOCOL_BY_ID = new Map<string, GoProtocol>(
67-
OPENCODE_GO_MODELS.map((m) => [m.id, m.protocol]),
68-
);
66+
export const PROTOCOL_BY_ID: ReadonlyMap<string, GoProtocol> = new Map<
67+
string,
68+
GoProtocol
69+
>(OPENCODE_GO_MODELS.map((m) => [m.id, m.protocol]));
6970

7071
export function protocolForGoModel(modelId: string): GoProtocol | undefined {
7172
return PROTOCOL_BY_ID.get(modelId);

‎packages/opencode-go/src/usage.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export async function fetchGoUsage(
9999
}
100100
}
101101

102-
function formatUsagePercent(w: GoUsageWindow): string {
102+
function formatWindowUsage(w: GoUsageWindow): string {
103103
if (w.usagePercent !== undefined) return `${Math.round(w.usagePercent)}%`;
104104
if (w.usageDollars !== undefined && w.limitDollars !== undefined) {
105105
return `$${w.usageDollars.toFixed(2)}/$${w.limitDollars.toFixed(0)}`;
@@ -123,5 +123,5 @@ export function formatGoUsage(usage: GoUsage): string {
123123
}
124124
const w = usage.rolling5h ?? usage.weekly ?? usage.monthly;
125125
if (w === undefined) return "Go usage ok";
126-
return `Go ${usageWindowLabel(usage)} ${formatUsagePercent(w)}`;
126+
return `Go ${usageWindowLabel(usage)} ${formatWindowUsage(w)}`;
127127
}

‎src/provider/billing-product.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
hostMatchesOpencodeDotAi,
23
isKnownGoModel,
34
isOpenCodeGoProvider,
45
} from "../../packages/opencode-go/src/index.js";
@@ -25,10 +26,7 @@ export function isBareZenBaseURL(baseURL: string): boolean {
2526
if (BARE_ZEN_BASES.has(trimmed)) return true;
2627
try {
2728
const url = new URL(trimmed);
28-
if (
29-
url.hostname !== "opencode.ai" &&
30-
!url.hostname.endsWith(".opencode.ai")
31-
) {
29+
if (!hostMatchesOpencodeDotAi(url.hostname)) {
3230
return false;
3331
}
3432
const path = url.pathname.replace(/\/+$/, "");

0 commit comments

Comments
 (0)