Enhance model configuration by adding modalities for input and output in OpenCodeToolCard and route.js. Introduce live model resolvers for Kiro in v1/models, allowing dynamic fetching of models based on provider credentials.

This commit is contained in:
decolua
2026-05-16 11:20:20 +07:00
parent 4a575f21a2
commit 18f87f43ca
4 changed files with 169 additions and 153 deletions

View File

@@ -9,6 +9,20 @@ import { getProviderConnections, getCombos, getCustomModels, getModelAliases } f
import { getDisabledModels } from "@/lib/disabledModelsDb";
import { resolveKiroModels } from "open-sse/services/kiroModels.js";
// Per-provider live model resolvers. Each receives a connection record and
// returns { models: [{ id, name? }, ...] } | null on failure.
// Adding a provider here makes /v1/models prefer the live catalog for it.
const LIVE_MODEL_RESOLVERS = {
kiro: async (conn) => {
const result = await resolveKiroModels({
accessToken: conn.accessToken,
refreshToken: conn.refreshToken,
providerSpecificData: conn.providerSpecificData || {}
}, { log: console });
return result?.models?.length ? { models: result.models } : null;
}
};
const parseOpenAIStyleModels = (data) => {
if (Array.isArray(data)) return data;
return data?.data || data?.models || data?.results || [];
@@ -255,6 +269,21 @@ export async function buildModelsList(kindFilter) {
rawModelIds = await fetchCompatibleModelIds(conn);
}
// Config-driven live catalog override (e.g. Kiro returns dynamic
// -thinking/-agentic variants per account). On failure, fall back to
// whatever rawModelIds already holds.
const liveResolver = LIVE_MODEL_RESOLVERS[providerId];
if (liveResolver && !hasExplicitEnabledModels) {
try {
const live = await liveResolver(conn);
if (live?.models?.length) {
rawModelIds = live.models.map((m) => m.id);
}
} catch (err) {
console.log(`Live model fetch failed for ${providerId}: ${err?.message || err}`);
}
}
const modelIds = rawModelIds
.map((modelId) => {
if (modelId.startsWith(`${outputAlias}/`)) {