MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / getOpencodeGoModels

Function getOpencodeGoModels

src/api/providers/fetchers/opencode-go.ts:95–127  ·  view source on GitHub ↗
(apiKey?: string)

Source from the content-addressed store, hash-verified

93 * @returns A record mapping model IDs to their normalised {@link ModelInfo}.
94 */
95export async function getOpencodeGoModels(apiKey?: string): Promise<Record<string, ModelInfo>> {
96 const models: Record<string, ModelInfo> = {}
97
98 try {
99 const response = await axios.get(`${OPENCODE_GO_BASE_URL}/models`, {
100 headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : undefined,
101 timeout: 10_000,
102 })
103
104 const result = opencodeGoModelsResponseSchema.safeParse(response.data)
105 const rawData = result.success ? result.data.data : response.data?.data
106 const data = Array.isArray(rawData) ? rawData : []
107
108 if (!result.success) {
109 console.warn(
110 `Opencode Go models response did not match expected schema; falling back to per-item parsing: ${JSON.stringify(result.error.format())}`,
111 )
112 }
113
114 for (const rawModel of data) {
115 const parsed = opencodeGoModelSchema.safeParse(rawModel)
116 if (!parsed.success) {
117 console.warn(`Skipping invalid Opencode Go model entry: ${JSON.stringify(rawModel)}`)
118 continue
119 }
120 models[parsed.data.id] = parseOpencodeGoModel(parsed.data)
121 }
122 } catch (error) {
123 console.error(`Error fetching Opencode Go models: ${error instanceof Error ? error.message : String(error)}`)
124 }
125
126 return models
127}

Callers 2

fetchModelsFromProviderFunction · 0.90

Calls 5

parseOpencodeGoModelFunction · 0.85
getMethod · 0.65
warnMethod · 0.65
errorMethod · 0.65
StringInterface · 0.50

Tested by

no test coverage detected