refactor(ai): isolate reasoning options

This commit is contained in:
Danila Poyarkov 2026-08-13 21:18:10 +03:00
parent 96b030699c
commit 6a44aecc24
4 changed files with 21 additions and 19 deletions

View file

@ -0,0 +1,18 @@
import type { AIProviderID } from '@open-pencil/core/constants'
type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue }
export type AIProviderOptions = Record<string, { [key: string]: JSONValue }>
export function buildReasoningProviderOptions(
providerID: AIProviderID,
reasoningEffort: string
): AIProviderOptions | undefined {
if (!reasoningEffort) return undefined
if (providerID === 'openrouter') {
return { openrouter: { reasoning: { effort: reasoningEffort } } }
}
if (providerID === 'openai' || providerID === 'openai-compatible') {
return { openai: { reasoningEffort } }
}
return undefined
}

View file

@ -13,6 +13,7 @@ import {
type AIChatFailure
} from '@/app/ai/chat/failure'
import { resolveLanguageModelID } from '@/app/ai/chat/model'
import { buildReasoningProviderOptions, type AIProviderOptions } from '@/app/ai/chat/reasoning'
import SYSTEM_PROMPT from '@/app/ai/chat/system-prompt.md?raw'
import { createAIModelRuntime } from '@/app/ai/models'
import { MAX_AGENT_STEPS, createAITools, recordStepUsage, resetRunSteps } from '@/app/ai/tools'
@ -49,23 +50,6 @@ function supportsAnthropicCaching(providerID: AIProviderID, modelID: string): bo
)
}
type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue }
type AIProviderOptions = Record<string, { [key: string]: JSONValue }>
export function buildReasoningProviderOptions(
providerID: AIProviderID,
reasoningEffort: string
): AIProviderOptions | undefined {
if (!reasoningEffort) return undefined
if (providerID === 'openrouter') {
return { openrouter: { reasoning: { effort: reasoningEffort } } }
}
if (providerID === 'openai' || providerID === 'openai-compatible') {
return { openai: { reasoningEffort } }
}
return undefined
}
function mergeProviderOptions(
cacheOptions: typeof ANTHROPIC_CACHE_CONTROL | undefined,
reasoningOptions: AIProviderOptions | undefined

View file

@ -4,7 +4,7 @@ import * as v from 'valibot'
import { computeContentBounds } from '@open-pencil/core/io'
import { buildReasoningProviderOptions } from '@/app/ai/chat/transports'
import { buildReasoningProviderOptions } from '@/app/ai/chat/reasoning'
import { createAIModelRuntime } from '@/app/ai/models'
import type { EditorStore } from '@/app/editor/active-store'

View file

@ -1,6 +1,6 @@
import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
import { buildReasoningProviderOptions } from '@/app/ai/chat/transports'
import { buildReasoningProviderOptions } from '@/app/ai/chat/reasoning'
import {
aiModelSettings,
createAIModelRuntime,