refactor: unwrap CopilotModels namespace + self-reexport (#22947)

This commit is contained in:
Kit Langton
2026-04-17 00:01:09 +00:00
committed by GitHub
parent 1291e82bb4
commit cde105e7a8
@@ -1,8 +1,7 @@
import { z } from "zod"
import type { Model } from "@opencode-ai/sdk/v2"
export namespace CopilotModels {
export const schema = z.object({
export const schema = z.object({
data: z.array(
z.object({
model_picker_enabled: z.boolean(),
@@ -38,11 +37,11 @@ export namespace CopilotModels {
}),
}),
),
})
})
type Item = z.infer<typeof schema>["data"][number]
type Item = z.infer<typeof schema>["data"][number]
function build(key: string, remote: Item, url: string, prev?: Model): Model {
function build(key: string, remote: Item, url: string, prev?: Model): Model {
const reasoning =
!!remote.capabilities.supports.adaptive_thinking ||
!!remote.capabilities.supports.reasoning_effort?.length ||
@@ -105,13 +104,13 @@ export namespace CopilotModels {
(remote.version.startsWith(`${remote.id}-`) ? remote.version.slice(remote.id.length + 1) : remote.version),
variants: prev?.variants ?? {},
}
}
}
export async function get(
export async function get(
baseURL: string,
headers: HeadersInit = {},
existing: Record<string, Model> = {},
): Promise<Record<string, Model>> {
): Promise<Record<string, Model>> {
const data = await fetch(`${baseURL}/models`, {
headers,
signal: AbortSignal.timeout(5_000),
@@ -142,5 +141,6 @@ export namespace CopilotModels {
}
return result
}
}
export * as CopilotModels from "./models"