Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions packages/first-class-providers/src/providers.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { describe, expect, test } from "bun:test";
import {
FIRST_CLASS_PROVIDERS,
connectListProviders,
firstClassPathAsProvider,
firstClassProviderById,
} from "./providers.js";
Expand All @@ -21,10 +20,6 @@ describe("FIRST_CLASS_PROVIDERS", () => {
]);
});

test("connectListProviders matches FIRST_CLASS_PROVIDERS", () => {
expect(connectListProviders()).toBe(FIRST_CLASS_PROVIDERS);
});

test("has no separate Codex connect row", () => {
expect(FIRST_CLASS_PROVIDERS.some((p) => p.id === "codex")).toBe(false);
expect(FIRST_CLASS_PROVIDERS.map((p) => p.label)).not.toContain(
Expand Down
5 changes: 0 additions & 5 deletions packages/first-class-providers/src/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,6 @@ export const FIRST_CLASS_PROVIDERS: readonly FirstClassProviderDef[] = [
},
] as const;

/** Connect-list rows (same as FIRST_CLASS_PROVIDERS; explicit export for hosts). */
export function connectListProviders(): readonly FirstClassProviderDef[] {
return FIRST_CLASS_PROVIDERS;
}

export function firstClassProviderById(
id: string,
): FirstClassProviderDef | undefined {
Expand Down
8 changes: 3 additions & 5 deletions packages/opencode-go/src/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import {
OPENCODE_GO_DEFAULT_MODEL,
OPENCODE_GO_MODEL_IDS,
OPENCODE_GO_MODELS,
PROTOCOL_BY_ID,
type GoProtocol,
} from "./models.js";

Expand All @@ -23,10 +23,8 @@ interface GoCatalogEntry {
}

export function buildGoCatalogEntry(): GoCatalogEntry {
const protocols: Record<string, GoProtocol> = {};
for (const m of OPENCODE_GO_MODELS) {
protocols[m.id] = m.protocol;
}
const protocols: Record<string, GoProtocol> =
Object.fromEntries(PROTOCOL_BY_ID);
return {
name: OPENCODE_GO_PROVIDER_ID,
displayName: OPENCODE_GO_DISPLAY_NAME,
Expand Down
11 changes: 7 additions & 4 deletions packages/opencode-go/src/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import {
OPENCODE_GO_PROVIDER_ID,
} from "./constants.js";

/** True when `host` is opencode.ai or a subdomain of it (case-insensitive). */
export function hostMatchesOpencodeDotAi(host: string): boolean {
const normalized = host.trim().toLowerCase();
return normalized === "opencode.ai" || normalized.endsWith(".opencode.ai");
}

/**
* True when the URL or base is the public OpenCode Go gateway.
*
Expand All @@ -21,10 +27,7 @@ export function isOpenCodeGoURL(urlOrBase: string | undefined): boolean {
if (trimmed.length === 0) return false;
try {
const url = new URL(trimmed);
if (
url.hostname !== "opencode.ai" &&
!url.hostname.endsWith(".opencode.ai")
) {
if (!hostMatchesOpencodeDotAi(url.hostname)) {
return false;
}
// Strip trailing slashes, then compare path segments case-insensitively.
Expand Down
1 change: 1 addition & 0 deletions packages/opencode-go/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ export {
isOpenCodeGoProvider,
isOpenCodeGoProviderId,
isOpenCodeGoURL,
hostMatchesOpencodeDotAi,
} from "./identity.js";
export { parseGoAPIError } from "./errors.js";
7 changes: 4 additions & 3 deletions packages/opencode-go/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ export const OPENCODE_GO_MODEL_IDS: readonly string[] = OPENCODE_GO_MODELS.map(

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

const PROTOCOL_BY_ID = new Map<string, GoProtocol>(
OPENCODE_GO_MODELS.map((m) => [m.id, m.protocol]),
);
export const PROTOCOL_BY_ID: ReadonlyMap<string, GoProtocol> = new Map<
string,
GoProtocol
>(OPENCODE_GO_MODELS.map((m) => [m.id, m.protocol]));

export function protocolForGoModel(modelId: string): GoProtocol | undefined {
return PROTOCOL_BY_ID.get(modelId);
Expand Down
28 changes: 15 additions & 13 deletions packages/opencode-go/src/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ export async function fetchGoUsage(
}
}

function formatWindowUsage(w: GoUsageWindow): string {
if (w.usagePercent !== undefined) return `${Math.round(w.usagePercent)}%`;
if (w.usageDollars !== undefined && w.limitDollars !== undefined) {
return `$${w.usageDollars.toFixed(2)}/$${w.limitDollars.toFixed(0)}`;
}
return "ok";
}

function usageWindowLabel(usage: GoUsage): string {
if (usage.rolling5h !== undefined) return "5h";
if (usage.weekly !== undefined) return "week";
return "month";
}

export function formatGoUsage(usage: GoUsage): string {
if (usage.status !== "ok") {
if (usage.status === "unavailable") return "Go usage unavailable";
Expand All @@ -109,17 +123,5 @@ export function formatGoUsage(usage: GoUsage): string {
}
const w = usage.rolling5h ?? usage.weekly ?? usage.monthly;
if (w === undefined) return "Go usage ok";
const pct =
w.usagePercent !== undefined
? `${Math.round(w.usagePercent)}%`
: w.usageDollars !== undefined && w.limitDollars !== undefined
? `$${w.usageDollars.toFixed(2)}/$${w.limitDollars.toFixed(0)}`
: "ok";
const window =
usage.rolling5h !== undefined
? "5h"
: usage.weekly !== undefined
? "week"
: "month";
return `Go ${window} ${pct}`;
return `Go ${usageWindowLabel(usage)} ${formatWindowUsage(w)}`;
}
6 changes: 1 addition & 5 deletions packages/zen/src/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
// helpers; Go's own URL and id keep matching Go first, never Zen.

import { ZEN_DISPLAY_NAME, ZEN_PROVIDER_ID } from "./constants.js";

function hostMatchesOpencodeDotAi(host: string): boolean {
const normalized = host.trim().toLowerCase();
return normalized === "opencode.ai" || normalized.endsWith(".opencode.ai");
}
import { hostMatchesOpencodeDotAi } from "../../opencode-go/src/index.js";

/**
* Match a bare Zen base URL: an opencode.ai URL whose first path segment is
Expand Down
6 changes: 2 additions & 4 deletions src/provider/billing-product.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
hostMatchesOpencodeDotAi,
isKnownGoModel,
isOpenCodeGoProvider,
} from "../../packages/opencode-go/src/index.js";
Expand All @@ -25,10 +26,7 @@ export function isBareZenBaseURL(baseURL: string): boolean {
if (BARE_ZEN_BASES.has(trimmed)) return true;
try {
const url = new URL(trimmed);
if (
url.hostname !== "opencode.ai" &&
!url.hostname.endsWith(".opencode.ai")
) {
if (!hostMatchesOpencodeDotAi(url.hostname)) {
return false;
}
const path = url.pathname.replace(/\/+$/, "");
Expand Down
Loading