Skip to content

Commit 4e331f5

Browse files
committed
Collapse Go and Zen catalog bindings into one parameterized module
1 parent a40fec3 commit 4e331f5

12 files changed

Lines changed: 86 additions & 87 deletions

File tree

‎src/config.test.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ import {
4343
} from "../packages/zen/src/index.js";
4444
import {
4545
prefetchGoModels,
46-
resetGoModelDiscoveryForTests,
47-
} from "./provider/opencode-go-models.js";
48-
import {
4946
prefetchZenModels,
47+
resetGoModelDiscoveryForTests,
5048
resetZenModelDiscoveryForTests,
51-
} from "./provider/zen-models.js";
49+
} from "./provider/model-catalogs.js";
5250
import {
5351
generateSessionId,
5452
initSessionDir,

‎src/config/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ import {
5757
} from "../provider/grok-responses.js";
5858
import { BIFROST_PROVIDER } from "../provider/bifrost-adapter.js";
5959
import { isOllamaProviderId, ollamaOpenAIBaseURL } from "../provider/ollama.js";
60-
import { selectableGoModelIds } from "../provider/opencode-go-models.js";
60+
import { selectableGoModelIds } from "../provider/model-catalogs.js";
6161
import {
6262
OPENCODE_GO_MESSAGES_PROVIDER,
6363
ZEN_MESSAGES_PROVIDER,
6464
} from "../provider/anthropic-session-adapter.js";
65-
import { selectableZenModelIds } from "../provider/zen-models.js";
65+
import { selectableZenModelIds } from "../provider/model-catalogs.js";
6666
import {
6767
OPENAI_RESPONSES_PROVIDER,
6868
OPENAI_SESSION_ID_OPTION,

‎src/provider/identity-divergence.test.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ import {
3333
import { OAUTH_SURFACES } from "../tui/provider/choices.js";
3434
import {
3535
resetGoModelDiscoveryForTests,
36-
selectableGoModelIds,
37-
} from "./opencode-go-models.js";
38-
import {
3936
resetZenModelDiscoveryForTests,
37+
selectableGoModelIds,
4038
selectableZenModelIds,
41-
} from "./zen-models.js";
39+
} from "./model-catalogs.js";
4240

4341
// CL-5691: provider/model identity unification. FIRST_CLASS_PROVIDERS is the
4442
// canonical static registry; the Codex/xAI live-fetch fallbacks stay separate

‎src/provider/model-catalogs.ts‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import {
2+
OPENCODE_GO_BASE_URL,
3+
OPENCODE_GO_MODEL_IDS,
4+
} from "../../packages/opencode-go/src/index.js";
5+
import {
6+
ZEN_DEFAULT_BASE_URL,
7+
ZEN_MODEL_IDS,
8+
} from "../../packages/zen/src/index.js";
9+
import {
10+
createBoundedModelCatalog,
11+
type CatalogDiscoveryState,
12+
} from "./bounded-model-catalog.js";
13+
14+
// Bound live /models so a huge or hostile catalog cannot blow process memory.
15+
export const MAX_GO_CATALOG_BYTES = 256 * 1024;
16+
export const MAX_GO_CATALOG_MODELS = 1024;
17+
export const MAX_ZEN_CATALOG_BYTES = 256 * 1024;
18+
export const MAX_ZEN_CATALOG_MODELS = 1024;
19+
20+
export type GoDiscoveryState = CatalogDiscoveryState;
21+
export type ZenDiscoveryState = CatalogDiscoveryState;
22+
23+
const goCatalog = createBoundedModelCatalog({
24+
baseURL: OPENCODE_GO_BASE_URL,
25+
seedIds: OPENCODE_GO_MODEL_IDS,
26+
catalogLabel: "OpenCode Go",
27+
maxBytes: MAX_GO_CATALOG_BYTES,
28+
maxModels: MAX_GO_CATALOG_MODELS,
29+
});
30+
31+
const zenCatalog = createBoundedModelCatalog({
32+
baseURL: ZEN_DEFAULT_BASE_URL,
33+
seedIds: ZEN_MODEL_IDS,
34+
catalogLabel: "OpenCode Zen",
35+
maxBytes: MAX_ZEN_CATALOG_BYTES,
36+
maxModels: MAX_ZEN_CATALOG_MODELS,
37+
});
38+
39+
/** Discover public OpenCode Go models without leaking transport or parsing failures. */
40+
export const discoverGoModels = goCatalog.discoverModels;
41+
42+
/** Sync picker ids: last successful live list, else the packaged seed. Never empty. */
43+
export const selectableGoModelIds = goCatalog.selectableModelIds;
44+
45+
/** Join or start a live fetch; the snapshot is the cache, inflight is only a mutex. */
46+
export const prefetchGoModels = goCatalog.prefetchModels;
47+
48+
export const resetGoModelDiscoveryForTests = goCatalog.resetDiscoveryForTests;
49+
50+
/** Discover public OpenCode Zen models without leaking transport or parsing failures. */
51+
export const discoverZenModels = zenCatalog.discoverModels;
52+
53+
/** Sync picker ids: last successful live list, else the packaged seed. Never empty. */
54+
export const selectableZenModelIds = zenCatalog.selectableModelIds;
55+
56+
/** Join or start a live fetch; the snapshot is the cache, inflight is only a mutex. */
57+
export const prefetchZenModels = zenCatalog.prefetchModels;
58+
59+
export const resetZenModelDiscoveryForTests = zenCatalog.resetDiscoveryForTests;

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

Lines changed: 0 additions & 33 deletions
This file was deleted.

‎src/provider/zen-models.ts‎

Lines changed: 0 additions & 33 deletions
This file was deleted.

‎src/tui/provider-setup.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { defined } from "../../tests/helpers/defined.js";
77

88
import { OAuthProviderScopeError } from "../auth/oauth-scope-check.js";
99
import { OPENCODE_GO_MODEL_IDS } from "../../packages/opencode-go/src/index.js";
10-
import { resetGoModelDiscoveryForTests } from "../provider/opencode-go-models.js";
10+
import { resetGoModelDiscoveryForTests } from "../provider/model-catalogs.js";
1111
import {
1212
loadLocalSettings,
1313
loadSettings,

‎src/tui/provider/choices.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import {
1616
import { XAI_BASE_URL, XAI_DEFAULT_MODELS } from "../../auth/xai/constants.js";
1717
import { codexProviderName } from "../../config/codex-providers.js";
1818
import { xaiProviderName } from "../../config/xai-providers.js";
19-
import { selectableGoModelIds } from "../../provider/opencode-go-models.js";
20-
import { selectableZenModelIds } from "../../provider/zen-models.js";
19+
import {
20+
selectableGoModelIds,
21+
selectableZenModelIds,
22+
} from "../../provider/model-catalogs.js";
2123
import { isZenProviderId } from "../../../packages/zen/src/index.js";
2224
import { buildModelsFirstCatalog } from "../model-catalog.js";
2325
import type { ResidualCatalogEntry } from "../residuals.js";

‎src/tui/provider/setup.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import {
2424
discoverOllamaModels as discoverOllamaModelsRequest,
2525
isOllamaProviderId,
2626
} from "../../provider/ollama.js";
27-
import { prefetchGoModels as prefetchGoModelsRequest } from "../../provider/opencode-go-models.js";
28-
import { prefetchZenModels as prefetchZenModelsRequest } from "../../provider/zen-models.js";
27+
import {
28+
prefetchGoModels as prefetchGoModelsRequest,
29+
prefetchZenModels as prefetchZenModelsRequest,
30+
} from "../../provider/model-catalogs.js";
2931
import { isZenProviderId } from "../../../packages/zen/src/index.js";
3032
import { resolveSideMargin } from "../geometry/zones.js";
3133
import {

‎src/tui/provider/types.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import type {
2020
discoverOllamaModels as discoverOllamaModelsRequest,
2121
OllamaDiscoveryState,
2222
} from "../../provider/ollama.js";
23-
import type { prefetchGoModels as prefetchGoModelsRequest } from "../../provider/opencode-go-models.js";
24-
import type { prefetchZenModels as prefetchZenModelsRequest } from "../../provider/zen-models.js";
23+
import type {
24+
prefetchGoModels as prefetchGoModelsRequest,
25+
prefetchZenModels as prefetchZenModelsRequest,
26+
} from "../../provider/model-catalogs.js";
2527
import type { ResidualCatalogEntry } from "../residuals.js";
2628
import type { OverlayList } from "../shell/internals.js";
2729
import type { SetupStep } from "./steps.js";

0 commit comments

Comments
 (0)