|
| 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; |
0 commit comments