mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
c7cf69a110
* fix(opencode): refresh hosted model catalogs Align Zen and Go availability, pricing, limits, transports, lifecycle metadata, and model-specific reasoning controls with current provider contracts. Co-authored-by: samson1357924 <samson1357924@gmail.com> Co-authored-by: xialonglee <li.xialong@xydigit.com> * fix(opencode): align catalog metadata with runtime contracts --------- Co-authored-by: xialonglee <li.xialong@xydigit.com>
51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
// Opencode API module exposes the plugin public contract.
|
|
import type {
|
|
ProviderDefaultThinkingPolicyContext,
|
|
ProviderThinkingProfile,
|
|
} from "openclaw/plugin-sdk/plugin-entry";
|
|
import { resolveClaudeThinkingProfile } from "openclaw/plugin-sdk/provider-model-shared";
|
|
|
|
const FIXED_REASONING_PROFILE = {
|
|
levels: [{ id: "off", label: "always on" }],
|
|
defaultLevel: "off",
|
|
} as const satisfies ProviderThinkingProfile;
|
|
|
|
const THINKING_LEVEL_IDS = new Set(["off", "minimal", "low", "medium", "high", "xhigh", "max"]);
|
|
|
|
function resolveEffortThinkingProfile(
|
|
efforts: readonly string[] | null | undefined,
|
|
): ProviderThinkingProfile | undefined {
|
|
if (!efforts || efforts.length === 0) {
|
|
return undefined;
|
|
}
|
|
const acceptedLevelIds = ["off", ...efforts.map((effort) => (effort === "none" ? "off" : effort))]
|
|
.filter((id) => THINKING_LEVEL_IDS.has(id))
|
|
.filter((id, index, values) => values.indexOf(id) === index) as Array<
|
|
"off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max"
|
|
>;
|
|
const levels = acceptedLevelIds.map((id) => ({ id }));
|
|
const levelIdSet = new Set(acceptedLevelIds);
|
|
const defaultLevel = levelIdSet.has("medium")
|
|
? "medium"
|
|
: levelIdSet.has("high")
|
|
? "high"
|
|
: levelIdSet.has("low")
|
|
? "low"
|
|
: "off";
|
|
return { levels, defaultLevel };
|
|
}
|
|
|
|
export function resolveThinkingProfile(params: ProviderDefaultThinkingPolicyContext) {
|
|
const modelId = params.modelId.trim().toLowerCase();
|
|
if (modelId.startsWith("claude-")) {
|
|
return resolveClaudeThinkingProfile(modelId);
|
|
}
|
|
const effortProfile = resolveEffortThinkingProfile(params.compat?.supportedReasoningEfforts);
|
|
if (effortProfile) {
|
|
return effortProfile;
|
|
}
|
|
return params.reasoning === true && params.api !== "anthropic-messages"
|
|
? FIXED_REASONING_PROFILE
|
|
: undefined;
|
|
}
|