feat(cn): map Qoder thinking_config to pi thinkingLevelMap for the picker

The catalog API returns each model's supported thinking efforts
(thinking_config.enabled.efforts, e.g. low/medium/xhigh for qwen3.8), but the
provider never populated Model.thinkingLevelMap, so pi's getSupportedThinkingLevels
hid xhigh/max (they require a non-undefined map entry) and the picker topped out
at "high" even for models that support xhigh.

Parse thinking_config at catalog fetch time and build the map:

- effort-based models (qwen3.8-max/flash, DeepSeek, GLM): each supported
  effort maps to its same-named pi level; unsupported levels pin to null
  (hidden). xhigh is now exposed. "off" is selectable when the catalog also
  advertises a "disabled" option.
- toggle-only models (qwen3.7-max/plus: enabled/disabled, no efforts):
  every pi level is exposed and maps to "enabled" so picking any level turns
  thinking on; "off" selectable when "disabled" is advertised.
- models without thinking_config (qwen3.7-flash): no map, pi falls back to its
  default level set.

Qoder effort keys are already pi level names (low/medium/high/xhigh/max), so
the mapping is by identity — no translation table.

This is display-layer only: it fixes which thinking levels the picker shows.
Sending the chosen effort upstream is a separate change that needs the exact
request field from a qoder-cli capture; the map values ("low"/"xhigh"/
"enabled"/"disabled") are placeholders that will be mapped to the request
shape once confirmed.
This commit is contained in:
Loongphy
2026-08-28 17:27:07 +08:00
parent cc461cd145
commit 88cf414a8e
+54 -1
View File
@@ -1,6 +1,7 @@
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { dirname, join } from "node:path";
import type { ThinkingLevel, ThinkingLevelMap } from "@earendil-works/pi-ai";
import {
buildAuthHeaders,
getQoderBaseUrl,
@@ -22,7 +23,10 @@ export interface QoderModelEntry {
context_config?: Record<string, { token_count?: number; is_default?: boolean }>;
is_vl?: boolean;
is_reasoning?: boolean;
thinking_config?: { enabled?: { efforts?: unknown } };
thinking_config?: {
disabled?: unknown;
enabled?: { efforts?: Record<string, { is_default?: boolean }>; is_default?: boolean };
};
source?: string;
[key: string]: unknown;
}
@@ -35,6 +39,7 @@ export interface QoderModelDef {
baseUrl: string;
reasoning: boolean;
supportsEffort: boolean;
thinkingLevelMap?: ThinkingLevelMap;
input: ("text" | "image")[];
cost: typeof ZERO_COST;
contextWindow: number;
@@ -378,6 +383,52 @@ export const staticCnModels: QoderModelDef[] = [
},
];
/** pi thinking levels in display order (matches the pi-ai SDK this build targets). */
const PI_THINKING_LEVELS: readonly ThinkingLevel[] = ["minimal", "low", "medium", "high", "xhigh"];
/**
* Map Qoder's `thinking_config` to pi's `thinkingLevelMap` so the TUI exposes
* the levels the upstream model actually supports.
*
* Qoder has two shapes:
* - effort-based: `thinking_config.enabled.efforts = { low, medium, xhigh, ... }`
* Each effort key is already a pi level name, so supported levels map to
* themselves and the rest are pinned to null (hidden in the picker).
* `xhigh`/`max` are only shown when the map carries them, otherwise the
* picker tops out at `high`.
* - toggle-based: `thinking_config.enabled` without `efforts` (only on/off).
* Every pi level is exposed and maps to "enabled" so a user picking any
* level turns thinking on; the exact effort sent upstream is decided at
* request time.
* Returns undefined for models that do not support thinking, so pi falls back
* to `reasoning: false`-style behavior (only `off`).
*/
function buildThinkingLevelMap(entry: QoderModelEntry): ThinkingLevelMap | undefined {
const tc = entry.thinking_config;
if (!tc) return undefined;
const efforts = tc.enabled?.efforts;
if (efforts && typeof efforts === "object") {
const supported = new Set(Object.keys(efforts));
// `off` (disable thinking) is selectable when the catalog advertises a
// `disabled` option; otherwise pin it to null to hide it.
const map: ThinkingLevelMap = { off: tc.disabled ? "disabled" : null };
for (const level of PI_THINKING_LEVELS) {
map[level] = supported.has(level) ? level : null;
}
return map;
}
// toggle-only (enabled/disabled, no efforts) — expose every level as "on".
// `off` is selectable when the catalog advertises `disabled`.
if (tc.enabled) {
const map: ThinkingLevelMap = { off: tc.disabled ? "disabled" : null };
for (const level of PI_THINKING_LEVELS) {
map[level] = "enabled";
}
return map;
}
return undefined;
}
export function getCachedModels(mode?: string): QoderModelDef[] {
const cachePath = getQoderCachePath(mode);
if (existsSync(cachePath)) {
@@ -515,6 +566,7 @@ export async function updateQoderModelsCache(
const isVL = !!entry.is_vl;
const isReasoning = !!entry.is_reasoning || !!entry.thinking_config;
const supportsEffort = !!entry.thinking_config?.enabled?.efforts;
const thinkingLevelMap = buildThinkingLevelMap(entry);
// CN models expose the upstream display_name (whitespace-stripped) as the
// pi-visible id; the original `key` is stored in `configs` and read back at
// request time, so no key<->friendlyId mapping table is needed.
@@ -533,6 +585,7 @@ export async function updateQoderModelsCache(
baseUrl: getQoderBaseUrl(mode),
reasoning: isReasoning,
supportsEffort,
thinkingLevelMap,
input: isVL ? ["text", "image"] : ["text"],
cost: ZERO_COST,
contextWindow: ctxLen,