@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
83 lines • 3.66 kB
JavaScript
import { getSupportedThinkingLevels as getSupportedModelThinkingLevels, supportsMax as modelSupportsMax, supportsXhigh as modelSupportsXhigh, } from "@earendil-works/pi-ai";
/**
* Tier detection is owned by `packages/ai`, which already treats an explicit `thinkingLevelMap` as
* authoritative and infers tiers from the model id only when no map is present. These wrappers keep
* the coding-agent's `ThinkingLevel` vocabulary without duplicating the capability rules.
*/
export function supportsXhigh(model) {
return modelSupportsXhigh(model);
}
export function supportsMax(model) {
return modelSupportsMax(model);
}
export function getSupportedThinkingLevels(model) {
const supportedLevels = getSupportedModelThinkingLevels(model);
return supportedLevels.length > 0 ? supportedLevels : ["off"];
}
/**
* Apply the effective `level` to an explicit selection. When it differs from `requested`, the selection keeps
* the requested level and the clamp reason instead of reading as if `level` had been chosen.
*/
export function clampThinkingSelection(selection, requested, level, model) {
if (selection === undefined)
return undefined;
const { requested: _staleRequested, clampReason: _staleReason, ...base } = selection;
if (requested === level || model === undefined)
return { ...base, level };
const clamped = {
...base,
level,
requested,
clampReason: model.reasoning ? "level-unsupported" : "model-not-reasoning",
};
return clamped;
}
export function getThinkingClampNotice(selection, model) {
const clamped = selection;
if (model === undefined || clamped?.requested === undefined || clamped.clampReason === undefined)
return undefined;
return {
provider: model.provider,
modelId: model.id,
requestedLevel: clamped.requested,
appliedLevel: clamped.level,
reason: clamped.clampReason,
};
}
export function formatThinkingClampWarning(notice) {
const model = `${notice.provider}/${notice.modelId}`;
if (notice.reason === "model-not-reasoning") {
return `Thinking level "${notice.requestedLevel}" was requested, but ${model} is not marked as a reasoning model, so thinking is "${notice.appliedLevel}". If the model supports reasoning, set "reasoning": true for it in models.json.`;
}
return `Thinking level "${notice.requestedLevel}" is not available on ${model}; using "${notice.appliedLevel}".`;
}
/**
* Classify a model's reasoning capability purely from `model.reasoning` and its supported thinking
* levels — never from the model id or thinkingFormat/compat config.
*
* - reasoning=false -> "none"
* - "off" is not supported -> "always-on"
* - exactly one non-off level -> "on-off"
* - otherwise -> "graded"
*
* Malformed input (e.g. a thinkingLevelMap that vetoes every level) cannot throw: the wrapper's
* ["off"] fallback means the model degrades to kind "none" with levels ["off"].
*/
export function classifyReasoningCapability(model) {
if (!model.reasoning) {
return { kind: "none", levels: ["off"], nonOffLevels: [] };
}
const levels = getSupportedThinkingLevels(model);
const nonOffLevels = levels.filter((level) => level !== "off");
if (!levels.includes("off")) {
return { kind: "always-on", levels, nonOffLevels };
}
if (nonOffLevels.length === 1) {
return { kind: "on-off", levels, nonOffLevels };
}
if (nonOffLevels.length === 0) {
return { kind: "none", levels, nonOffLevels };
}
return { kind: "graded", levels, nonOffLevels };
}
//# sourceMappingURL=thinking-levels.js.map