MCPcopy Create free account
hub / github.com/backnotprop/plannotator / fetchModels

Method fetchModels

packages/ai/providers/opencode-sdk.ts:210–244  ·  view source on GitHub ↗

Fetch available models from OpenCode. Call before registering the provider.

()

Source from the content-addressed store, hash-verified

208
209 /** Fetch available models from OpenCode. Call before registering the provider. */
210 async fetchModels(): Promise<void> {
211 try {
212 await this.ensureServer();
213 const client = this.getClient();
214
215 const result = await client.provider.list({
216 query: { directory: this.config.cwd ?? process.cwd() },
217 });
218 const data = result.data;
219 if (!data) {
220 return;
221 }
222 const connected = new Set(data.connected ?? []);
223 const allProviders = data.all ?? [];
224
225 const models: Array<{ id: string; label: string; default?: boolean }> = [];
226 for (const provider of allProviders) {
227 if (!connected.has(provider.id)) continue;
228 for (const model of Object.values(provider.models)) {
229 models.push({
230 id: `${provider.id}/${model.id}`,
231 label: model.name ?? model.id,
232 });
233 }
234 }
235
236 if (models.length > 0) {
237 // Mark first model as default
238 models[0].default = true;
239 this.models = models;
240 }
241 } catch {
242 // OpenCode not configured or no models available
243 }
244 }
245}
246
247// ---------------------------------------------------------------------------

Callers

nothing calls this directly

Calls 5

ensureServerMethod · 0.95
getClientMethod · 0.95
hasMethod · 0.80
listMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected