+3
-26
@@ -1,39 +1,16 @@
|
||||
import type { Plugin } from "@opencode/plugin";
|
||||
import type { ModelInfo } from "@opencode/client";
|
||||
import { z } from "zod";
|
||||
|
||||
function priority(model: ModelInfo) {
|
||||
if (model.modelID !== "gpt-6-luna") return undefined;
|
||||
for (const settings of [model.settings, ...model.variants.map((variant) => variant.settings)]) {
|
||||
if (settings?.serviceTier === "priority" || settings?.serviceTier === "fast")
|
||||
return settings.serviceTier;
|
||||
}
|
||||
const baseURL = model.settings?.baseURL;
|
||||
if (model.package !== "@opencode/ai/providers/openai" && model.package !== "@ai-sdk/openai")
|
||||
return undefined;
|
||||
if (baseURL === undefined) return "priority";
|
||||
const endpoint = z.url().safeParse(baseURL);
|
||||
if (!endpoint.success) return undefined;
|
||||
const url = new URL(endpoint.data);
|
||||
return url.origin === "https://api.openai.com" && /^\/v1\/?$/.test(url.pathname)
|
||||
? "priority"
|
||||
: undefined;
|
||||
}
|
||||
|
||||
export function modelKey(providerID: string, modelID: string) {
|
||||
return `${providerID}\0${modelID}`;
|
||||
}
|
||||
|
||||
export async function discover(context: Plugin.Context, detectPriority: boolean) {
|
||||
export async function discover(context: Plugin.Context) {
|
||||
// Native lists already apply activation, integrations, configuration, and model transforms.
|
||||
const { data } = await context.model.list();
|
||||
const models = new Map<string, { model: ModelInfo; serviceTier: string | undefined }>();
|
||||
const models = new Map<string, ModelInfo>();
|
||||
for (const model of data) {
|
||||
if (model.enabled)
|
||||
models.set(modelKey(model.providerID, model.id), {
|
||||
model,
|
||||
serviceTier: detectPriority ? priority(model) : undefined,
|
||||
});
|
||||
if (model.enabled) models.set(modelKey(model.providerID, model.id), model);
|
||||
}
|
||||
return models;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user