}
type Catalog = Record<string, CatalogModel>;
const thinkingFormat = (id: string): "qwen" | "deepseek" | "zai" | undefined =>
id.startsWith("qwen") ? "qwen" : id.startsWith("deepseek") ? "deepseek" : id.startsWith("glm") ? "zai" : undefined;
type Family = "qwen" | "deepseek" | "zai" | "other";
const familyOf = (id: string): Family =>
id.startsWith("qwen") ? "qwen" : id.startsWith("deepseek") ? "deepseek" : id.startsWith("glm") ? "zai" : "other";
/**
* Per-family request quirks, mirroring what Prime's own catalog applies to the same
* model families. Without the DeepSeek entry, replayed thinking blocks from another
* provider land in the assistant text instead of `reasoning_content`, and the model
* answers by writing its reasoning into the visible reply.
*/
const FAMILY_COMPAT: Record<Family, Record<string, unknown>> = {
qwen: { thinkingFormat: "qwen", supportsReasoningEffort: false, cacheControlFormat: "anthropic" },
deepseek: { thinkingFormat: "deepseek", requiresReasoningContentOnAssistantMessages: true },
zai: { thinkingFormat: "zai", supportsReasoningEffort: false },
other: {},
};
/** DeepSeek V4 exposes only high/max, same as Prime's built-in DeepSeek models. */
const DEEPSEEK_THINKING_LEVELS = { minimal: null, low: null, medium: null, high: "high", xhigh: "max", max: null };
const isChatModel = (m: CatalogModel): boolean => m.tool_call && m.modalities.output.includes("text");
const readKeyFile = (): string | undefined => {
try {
maxTokens: m.limit.output,
compat: {
supportsDeveloperRole: false,
maxTokensField: "max_tokens" as const,
...(m.reasoning ? { thinkingFormat: thinkingFormat(id) } : {}),
// Only Qwen honours cache_control here; the other families cache implicitly
// and report hits through prompt_tokens_details.cached_tokens.
...(id.startsWith("qwen") ? { cacheControlFormat: "anthropic" as const } : {}),
...FAMILY_COMPAT[familyOf(id)],
},
...(m.reasoning && familyOf(id) === "deepseek" ? { thinkingLevelMap: DEEPSEEK_THINKING_LEVELS } : {}),
}))
.sort((a, b) => a.id.localeCompare(b.id));
pi.registerProvider(PROVIDER, {