feat(agent): unify models and validate OpenCode providers
Generate chat, task and learning models from agent-models.json. Use WaterNetwork fast/expert models with 272k context and validate upstream names before readiness. Add an isolated model check command with signal-safe cleanup and plugin, Skill and MCP management docs. Verified in isolation: type checks, 26 focused tests and both model catalog checks; no model inference requests.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { z } from "zod";
|
||||
import { type AgentModelConfig } from "../chat/modelConfig.js";
|
||||
|
||||
export const modelCheckInputSchema = z.object({ models: z.array(z.object({
|
||||
id: z.string(), provider_id: z.string(), model_id: z.string(), wire_id: z.string(), requires_tools: z.boolean(),
|
||||
}).strict()).min(1).max(1000) }).strict();
|
||||
export type ModelCheckInput = z.infer<typeof modelCheckInputSchema>;
|
||||
export const modelCheckReportSchema = z.object({
|
||||
models: z.array(z.object({
|
||||
id: z.string(), model_id: z.string(),
|
||||
status: z.enum(["valid", "not_registered", "not_enabled", "no_tools", "wire_id_mismatch", "not_advertised", "unchecked"]),
|
||||
}).strict()),
|
||||
providers: z.array(z.object({
|
||||
id: z.string(), status: z.enum(["checked", "not_registered", "unsupported_catalog", "catalog_unavailable", "catalog_invalid", "credentials_unavailable"]),
|
||||
http_status: z.number().int().optional(),
|
||||
}).strict()),
|
||||
}).strict();
|
||||
export type ModelCheckReport = z.infer<typeof modelCheckReportSchema>;
|
||||
|
||||
export function modelCheckTargets(configuration: AgentModelConfig): ModelCheckInput {
|
||||
return { models: Object.entries(configuration.providers).flatMap(([providerID, provider]) =>
|
||||
Object.entries(provider.models).filter(([, model]) => !model.disabled).map(([modelID, model]) => ({
|
||||
id: `${providerID}/${modelID}`, provider_id: providerID, model_id: modelID,
|
||||
wire_id: model.model_id ?? modelID, requires_tools: model.capabilities.tools,
|
||||
})),
|
||||
) };
|
||||
}
|
||||
|
||||
export function assertModelCheckPassed(report: ModelCheckReport) {
|
||||
const failures = [
|
||||
...report.providers.filter((provider) => provider.status !== "checked").map((provider) => `${provider.id}: ${provider.status}${provider.http_status ? ` (HTTP ${provider.http_status})` : ""}`),
|
||||
...report.models.filter((model) => model.status !== "valid").map((model) => `${model.id}: ${model.status}`),
|
||||
];
|
||||
if (!report.models.length || failures.length) throw new Error(`OpenCode model validation failed: ${failures.join("; ") || "empty model catalog"}`);
|
||||
}
|
||||
Reference in New Issue
Block a user