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:
@@ -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 },
|
||||
|
||||
Reference in New Issue
Block a user