refactor: unwrap CopilotModels namespace + self-reexport (#22947)
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
import type { Model } from "@opencode-ai/sdk/v2"
|
import type { Model } from "@opencode-ai/sdk/v2"
|
||||||
|
|
||||||
export namespace CopilotModels {
|
export const schema = z.object({
|
||||||
export const schema = z.object({
|
|
||||||
data: z.array(
|
data: z.array(
|
||||||
z.object({
|
z.object({
|
||||||
model_picker_enabled: z.boolean(),
|
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 =
|
const reasoning =
|
||||||
!!remote.capabilities.supports.adaptive_thinking ||
|
!!remote.capabilities.supports.adaptive_thinking ||
|
||||||
!!remote.capabilities.supports.reasoning_effort?.length ||
|
!!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),
|
(remote.version.startsWith(`${remote.id}-`) ? remote.version.slice(remote.id.length + 1) : remote.version),
|
||||||
variants: prev?.variants ?? {},
|
variants: prev?.variants ?? {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get(
|
export async function get(
|
||||||
baseURL: string,
|
baseURL: string,
|
||||||
headers: HeadersInit = {},
|
headers: HeadersInit = {},
|
||||||
existing: Record<string, Model> = {},
|
existing: Record<string, Model> = {},
|
||||||
): Promise<Record<string, Model>> {
|
): Promise<Record<string, Model>> {
|
||||||
const data = await fetch(`${baseURL}/models`, {
|
const data = await fetch(`${baseURL}/models`, {
|
||||||
headers,
|
headers,
|
||||||
signal: AbortSignal.timeout(5_000),
|
signal: AbortSignal.timeout(5_000),
|
||||||
@@ -142,5 +141,6 @@ export namespace CopilotModels {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export * as CopilotModels from "./models"
|
||||||
|
|||||||
Reference in New Issue
Block a user