mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
Replace the single 3300-line generate-models.ts with declarative provider definitions and ordered rule packs under scripts/model-generation/. Each provider is a defineProvider() call: an upstream source (usually the generic modelsDev() mapper), static models upstream lacks, and rules scoped to that provider. Cross-provider facts live in rule packs applied in a fixed order. Every rule() carries a why, matches models with plain data, and patches them with typed set/replace/apply semantics. Generated model data is unchanged: 1443 models across 41 providers compare equal against a snapshot of the same upstream responses, apart from a now stable key order. Committed models.generated.ts and provider shards are byte-identical. Also: - Bring packages/ai/scripts under tsgo and biome; the old generator had 20+ type errors that nothing checked. - Add --upstream-snapshot <dir> to record and replay upstream catalogs and --explain <provider>:<model> to list the rules applied to a model. - Report rules that matched no model so stale corrections get removed. - Export parseRadiusGatewayConfig so the generator can replay Radius too. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018ExCU9zaZnN8vB5fKpTAjP
55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
import { getEffortThinkingLevelMap } from "../../models-dev-reasoning-options.ts";
|
|
import { type DefinedRule, defineProvider, rule } from "../dsl.ts";
|
|
import { getModelsDevCost, modelsDev } from "../models-dev.ts";
|
|
|
|
const ZAI_TOOL_STREAM_UNSUPPORTED_MODEL_IDS = ["glm-4.5", "glm-4.5-air", "glm-4.5-flash", "glm-4.5v"];
|
|
|
|
const zaiRules: DefinedRule[] = [
|
|
rule({
|
|
why: "z.ai streams tool call deltas with top-level tool_stream on every model after GLM 4.5.",
|
|
match: { not: { id: ZAI_TOOL_STREAM_UNSUPPORTED_MODEL_IDS } },
|
|
set: { compat: { zaiToolStream: true } },
|
|
}),
|
|
rule({
|
|
why: "Cataloged effort levels enable reasoning_effort; GLM 5.2 additionally accepts `none` to disable thinking.",
|
|
match: { when: (_model, context) => getEffortThinkingLevelMap(context.reasoningOptions ?? []) !== undefined },
|
|
apply: (model, context) => {
|
|
const map = getEffortThinkingLevelMap(context.reasoningOptions ?? []);
|
|
if (!map) return;
|
|
if (model.id === "glm-5.2" || model.id === "glm-5.2-highspeed") map.off = "none";
|
|
model.thinkingLevelMap = map;
|
|
model.compat = { ...model.compat, supportsReasoningEffort: true };
|
|
},
|
|
}),
|
|
rule({
|
|
why: "Coding plans are subscription-priced; report the pay-as-you-go z.ai rates so usage has an estimated value.",
|
|
match: { when: (model, context) => context.modelsDev.zai?.models?.[model.id]?.cost !== undefined },
|
|
apply: (model, context) => {
|
|
model.cost = getModelsDevCost(context.modelsDev.zai?.models?.[model.id]?.cost);
|
|
},
|
|
}),
|
|
];
|
|
|
|
export const zai = defineProvider({
|
|
id: "zai",
|
|
source: modelsDev({
|
|
provider: "zai",
|
|
key: "zai-coding-plan",
|
|
api: "openai-completions",
|
|
baseUrl: "https://api.z.ai/api/coding/paas/v4",
|
|
compat: { supportsDeveloperRole: false, thinkingFormat: "zai" },
|
|
}),
|
|
rules: zaiRules,
|
|
});
|
|
|
|
export const zaiCodingCn = defineProvider({
|
|
id: "zai-coding-cn",
|
|
source: modelsDev({
|
|
provider: "zai-coding-cn",
|
|
key: "zhipuai-coding-plan",
|
|
api: "openai-completions",
|
|
baseUrl: "https://open.bigmodel.cn/api/coding/paas/v4",
|
|
compat: { supportsDeveloperRole: false, thinkingFormat: "zai" },
|
|
}),
|
|
rules: zaiRules,
|
|
});
|