fix: gracefully disable thinking for non-reasoning models (fixes #350) (#351)

When a user switches to a model that doesn't support thinking (e.g.,
Gemini 1.5 Flash) while a thinking level is still set from a previous
model, the app crashes with an uncaught exception from
requireSupportedEffort().

Add model.reasoning guards in mapOptionsForApi() for all provider paths
(Anthropic, Google, Google Gemini CLI, Google Vertex, OpenAI) so that
thinking is gracefully disabled instead of throwing. The Bedrock path
already had this guard.
This commit is contained in:
Sascha Buehrle
2026-03-10 02:39:55 +01:00
committed by GitHub
parent 6eb5b3fc59
commit b892e7a3d8
+8 -8
View File
@@ -391,7 +391,7 @@ function resolveOpenAiReasoningEffort<TApi extends Api>(
options?: SimpleStreamOptions,
): Effort | undefined {
const reasoning = options?.reasoning;
if (!reasoning) return undefined;
if (!reasoning || !model.reasoning) return undefined;
return requireSupportedEffort(model, reasoning);
}
@@ -424,9 +424,9 @@ function mapOptionsForApi<TApi extends Api>(
switch (model.api) {
case "anthropic-messages": {
// Explicitly disable thinking when reasoning is not specified
// Explicitly disable thinking when reasoning is not specified or model doesn't support it
const reasoning = options?.reasoning;
if (!reasoning) {
if (!reasoning || !model.reasoning) {
return castApi<"anthropic-messages">({
...base,
thinkingEnabled: false,
@@ -548,10 +548,10 @@ function mapOptionsForApi<TApi extends Api>(
});
case "google-generative-ai": {
// Explicitly disable thinking when reasoning is not specified
// Explicitly disable thinking when reasoning is not specified or model doesn't support it
// This is needed because Gemini has "dynamic thinking" enabled by default
const reasoning = options?.reasoning;
if (!reasoning) {
if (!reasoning || !model.reasoning) {
return castApi<"google-generative-ai">({
...base,
thinking: { enabled: false },
@@ -587,7 +587,7 @@ function mapOptionsForApi<TApi extends Api>(
case "google-gemini-cli": {
const reasoning = options?.reasoning;
if (!reasoning) {
if (!reasoning || !model.reasoning) {
return castApi<"google-gemini-cli">({
...base,
thinking: { enabled: false },
@@ -637,9 +637,9 @@ function mapOptionsForApi<TApi extends Api>(
}
case "google-vertex": {
// Explicitly disable thinking when reasoning is not specified
// Explicitly disable thinking when reasoning is not specified or model doesn't support it
const reasoning = options?.reasoning;
if (!reasoning) {
if (!reasoning || !model.reasoning) {
return castApi<"google-vertex">({
...base,
thinking: { enabled: false },