Skip to content

AI-native design editor. Open-source Figma alternative.

feat(ai): default MiniMax text models to M3.1 Flash (#1360)

Octopus4c8f202a400b
diff --git a/changes/1360/changed.md b/changes/1360/changed.md
new file mode 100644
index 000000000..3d5b58b92
--- /dev/null
+++ b/changes/1360/changed.md
@@ -0,0 +1 @@
+- MiniMax recommends MiniMax-M3.1-Flash by default, with MiniMax-M3 as the other recommended model, and Flash runs at low effort when thinking is set to Off or Minimal, the lowest it supports.
diff --git a/changes/1360/fixed.md b/changes/1360/fixed.md
new file mode 100644
index 000000000..fc3e12779
--- /dev/null
+++ b/changes/1360/fixed.md
@@ -0,0 +1 @@
+- Off and Minimal thinking no longer fail on OpenRouter models that always reason: requests use the lowest effort OpenRouter lists for the model.
diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts
index a4a325d3a..8434af936 100644
--- a/packages/core/src/constants.ts
+++ b/packages/core/src/constants.ts
@@ -230,6 +230,9 @@ export type AIProviderID =
| 'harness:pi'
| `acp:${ACPAgentID}`
+export const REASONING_EFFORTS = ['minimal', 'low', 'medium', 'high', 'xhigh'] as const
+export type ReasoningEffort = (typeof REASONING_EFFORTS)[number]
+
export interface ModelOption {
id: string
name: string
@@ -238,6 +241,8 @@ export interface ModelOption {
recommendedMaxOutputTokens?: number
releaseDate?: string
status?: 'active' | 'beta' | 'deprecated'
+ /** Lowest reasoning effort the model accepts; lower thinking levels, Off included, use it. */
+ minReasoningEffort?: ReasoningEffort
}
export interface AIProviderDef {
@@ -447,16 +452,15 @@ export const AI_PROVIDERS: AIProviderDef[] = [
name: 'MiniMax',
keyPlaceholder: 'API key',
keyURL: 'https://platform.minimax.io/user-center/basic-information/interface-key',
- defaultModel: 'MiniMax-M3',
+ defaultModel: 'MiniMax-M3.1-Flash',
models: [
- { id: 'MiniMax-M3', name: 'MiniMax-M3', tag: 'Best' },
- { id: 'MiniMax-M2.7', name: 'MiniMax-M2.7' },
- { id: 'MiniMax-M2.7-highspeed', name: 'MiniMax-M2.7-highspeed', tag: 'Fast' },
- { id: 'MiniMax-M2.5', name: 'MiniMax-M2.5' },
- { id: 'MiniMax-M2.5-highspeed', name: 'MiniMax-M2.5 Highspeed', tag: 'Fast' },
- { id: 'MiniMax-M2.1', name: 'MiniMax-M2.1' },
- { id: 'MiniMax-M2.1-highspeed', name: 'MiniMax-M2.1 Highspeed', tag: 'Fast' },
- { id: 'MiniMax-M2', name: 'MiniMax-M2' }
+ {
+ id: 'MiniMax-M3.1-Flash',
+ name: 'MiniMax-M3.1-Flash',
+ tag: 'Best',
+ minReasoningEffort: 'low'
+ },
+ { id: 'MiniMax-M3', name: 'MiniMax-M3' }
]
},
{
diff --git a/src/app/ai/attachment/image/analyze.ts b/src/app/ai/attachment/image/analyze.ts
index 8397de67c..6dade2b32 100644
--- a/src/app/ai/attachment/image/analyze.ts
+++ b/src/app/ai/attachment/image/analyze.ts
@@ -4,7 +4,7 @@ import { computeContentBounds } from '@open-pencil/core/io'
import { IMAGE_ATTACHMENT_MAX_EDGE } from '@/app/ai/attachment/image/prepare'
import type { PreparedImageAttachment } from '@/app/ai/attachment/image/types'
-import { reasoningCallSettings } from '@/app/ai/chat/reasoning'
+import { runtimeReasoningSettings } from '@/app/ai/chat/reasoning'
import { createAIModelRuntime } from '@/app/ai/models'
import { boundedImageScale } from '@/app/ai/tools/vision'
import type { VisionModelDependencies } from '@/app/ai/vision-runtime'
@@ -70,10 +70,7 @@ export async function analyzeAttachedImages(
const result = await dependencies.inspect({
model: runtime.model,
maxOutputTokens: Math.min(runtime.role.profile.maxOutputTokens, MAX_IMAGE_ANALYSIS_TOKENS),
- ...reasoningCallSettings(
- runtime.role.connection.providerID,
- runtime.role.profile.thinkingLevel
- ),
+ ...runtimeReasoningSettings(runtime),
messages: [{ role: 'user', content }]
})
diff --git a/src/app/ai/chat/provider-models.ts b/src/app/ai/chat/provider-models.ts
index 7c6fb8d20..8358b01dc 100644
--- a/src/app/ai/chat/provider-models.ts
+++ b/src/app/ai/chat/provider-models.ts
@@ -1,7 +1,7 @@
import * as v from 'valibot'
-import { AI_PROVIDERS } from '@open-pencil/core/constants'
-import type { AIProviderID, ModelOption } from '@open-pencil/core/constants'
+import { AI_PROVIDERS, REASONING_EFFORTS } from '@open-pencil/core/constants'
+import type { AIProviderID, ModelOption, ReasoningEffort } from '@open-pencil/core/constants'
import { readCacheJSON, writeCacheJSON } from '@/app/cache'
@@ -13,7 +13,8 @@ const CachedModelOptions = v.array(
capabilities: v.optional(v.array(v.picklist(['tools', 'vision']))),
recommendedMaxOutputTokens: v.optional(v.number()),
releaseDate: v.optional(v.string()),
- status: v.optional(v.picklist(['active', 'beta', 'deprecated']))
+ status: v.optional(v.picklist(['active', 'beta', 'deprecated'])),
+ minReasoningEffort: v.optional(v.picklist(REASONING_EFFORTS))
})
) satisfies v.GenericSchema<unknown, ModelOption[]>
@@ -22,7 +23,13 @@ const OpenRouterModelSchema = v.looseObject({
name: v.optional(v.unknown()),
supported_parameters: v.optional(v.unknown()),
architecture: v.nullish(v.looseObject({ input_modalities: v.optional(v.unknown()) })),
- top_provider: v.nullish(v.looseObject({ max_completion_tokens: v.optional(v.unknown()) }))
+ top_provider: v.nullish(v.looseObject({ max_completion_tokens: v.optional(v.unknown()) })),
+ reasoning: v.nullish(
+ v.looseObject({
+ mandatory: v.optional(v.unknown()),
+ supported_efforts: v.optional(v.unknown())
+ })
+ )
})
type OpenRouterModel = v.InferOutput<typeof OpenRouterModelSchema>
@@ -35,8 +42,10 @@ const OpenRouterModelsResponseJSON = v.pipe(
)
const OPENROUTER_MODELS_URL = 'https://openrouter.ai/api/v1/models'
-const OPENROUTER_MODELS_CACHE_KEY = 'openrouter/models'
+const OPENROUTER_MODELS_CACHE_KEY = 'openrouter/models-v2'
const OPENROUTER_MODELS_CACHE_TTL_MS = 24 * 60 * 60 * 1000
+// Runtime creation waits for the list, so a stalled request falls back to the curated models.
+const OPENROUTER_MODELS_TIMEOUT_MS = 10_000
function curatedProviderModels(providerID: AIProviderID) {
return AI_PROVIDERS.find((provider) => provider.id === providerID)?.models ?? []
}
@@ -49,12 +58,23 @@ function isToolCapableOpenRouterModel(model: OpenRouterModel) {
return Array.isArray(model.supported_parameters) && model.supported_parameters.includes('tools')
}
+/**
+ * Models that always reason reject `none`, so Off and lower levels use the lowest effort
+ * OpenRouter lists. Without a list, `minimal` lets OpenRouter pick its nearest supported level.
+ */
+function minReasoningEffort(model: OpenRouterModel): ReasoningEffort | undefined {
+ if (model.reasoning?.mandatory !== true) return undefined
+ const supported = model.reasoning.supported_efforts
+ if (!Array.isArray(supported)) return 'minimal'
+ return REASONING_EFFORTS.find((effort) => supported.includes(effort)) ?? 'minimal'
+}
+
export function normalizeOpenRouterModel(model: OpenRouterModel): ModelOption | null {
if (!isToolCapableOpenRouterModel(model)) return null
if (typeof model.id !== 'string' || !model.id) return null
const inputModalities = model.architecture?.input_modalities
const maxOutputTokens = model.top_provider?.max_completion_tokens
- return {
+ const normalized: ModelOption = {
id: model.id,
name: typeof model.name === 'string' && model.name ? model.name : model.id,
capabilities: [
@@ -62,15 +82,20 @@ export function normalizeOpenRouterModel(model: OpenRouterModel): ModelOption |
...(Array.isArray(inputModalities) && inputModalities.includes('image')
? (['vision'] as const)
: [])
- ],
- ...(typeof maxOutputTokens === 'number' && Number.isFinite(maxOutputTokens)
- ? { recommendedMaxOutputTokens: Math.min(128_000, Math.max(1024, maxOutputTokens)) }
- : {})
+ ]
+ }
+ if (typeof maxOutputTokens === 'number' && Number.isFinite(maxOutputTokens)) {
+ normalized.recommendedMaxOutputTokens = Math.min(128_000, Math.max(1024, maxOutputTokens))
}
+ const minEffort = minReasoningEffort(model)
+ if (minEffort) normalized.minReasoningEffort = minEffort
+ return normalized
}
async function fetchOpenRouterModels(fetcher: typeof fetch): Promise<ModelOption[]> {
- const response = await fetcher(OPENROUTER_MODELS_URL)
+ const response = await fetcher(OPENROUTER_MODELS_URL, {
+ signal: AbortSignal.timeout(OPENROUTER_MODELS_TIMEOUT_MS)
+ })
if (!response.ok) throw new Error(`OpenRouter models request failed: ${response.status}`)
const json = v.parse(OpenRouterModelsResponseJSON, await response.text())
return (json.data ?? []).flatMap((entry) => {
@@ -81,19 +106,24 @@ async function fetchOpenRouterModels(fetcher: typeof fetch): Promise<ModelOption
async function listOpenRouterModels(fetcher: typeof fetch = fetch): Promise<ModelOption[]> {
modelsPromise ??= (async () => {
- const cached = await readCacheJSON(
- OPENROUTER_MODELS_CACHE_KEY,
- CachedModelOptions,
- OPENROUTER_MODELS_CACHE_TTL_MS
- )
- if (cached?.length) return cached
-
try {
+ // Storage failures only skip the cache; they never hide the fetched list.
+ const cached = await readCacheJSON(
+ OPENROUTER_MODELS_CACHE_KEY,
+ CachedModelOptions,
+ OPENROUTER_MODELS_CACHE_TTL_MS
+ ).catch(() => null)
+ if (cached?.length) return cached
+
const models = await fetchOpenRouterModels(fetcher)
if (!models.length) return curatedOpenRouterModels
- await writeCacheJSON(OPENROUTER_MODELS_CACHE_KEY, models)
+ await writeCacheJSON(OPENROUTER_MODELS_CACHE_KEY, models).catch((error: unknown) => {
+ console.warn('OpenRouter model cache write skipped:', error)
+ })
return models
} catch {
+ // Retried on the next call rather than held for the session.
+ modelsPromise = null
return curatedOpenRouterModels
}
})()
@@ -108,3 +138,15 @@ export async function listProviderModels(
if (providerID === 'openrouter') return listOpenRouterModels(fetcher)
return curatedProviderModels(providerID)
}
+
+export async function resolveProviderModel(
+ providerID: AIProviderID,
+ modelID: string,
+ fetcher?: typeof fetch
+): Promise<ModelOption | undefined> {
+ return (await listProviderModels(providerID, fetcher)).find((model) => model.id === modelID)
+}
+
+export function resetOpenRouterModelsForTests(): void {
+ modelsPromise = null
+}
diff --git a/src/app/ai/chat/reasoning.ts b/src/app/ai/chat/reasoning.ts
index c4e8d4244..d0bd0f678 100644
--- a/src/app/ai/chat/reasoning.ts
+++ b/src/app/ai/chat/reasoning.ts
@@ -1,7 +1,9 @@
import type { LanguageModelCallOptions } from 'ai'
-import type { AIProviderID } from '@open-pencil/core/constants'
+import { REASONING_EFFORTS } from '@open-pencil/core/constants'
+import type { AIProviderID, ReasoningEffort } from '@open-pencil/core/constants'
+import type { DirectAIModelRuntime } from '@/app/ai/models/runtime'
import type { ThinkingLevel } from '@/app/ai/models/types'
type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue }
@@ -12,18 +14,38 @@ export type ReasoningCallSettings = {
providerOptions?: AIProviderOptions
}
+function raisedLevel(level: ThinkingLevel, minEffort: ReasoningEffort | undefined) {
+ if (!minEffort || level === 'default') return level
+ if (level === 'off') return minEffort
+ return REASONING_EFFORTS.indexOf(level) < REASONING_EFFORTS.indexOf(minEffort) ? minEffort : level
+}
+
/**
* AI SDK providers map the standard `reasoning` level to their own thinking options.
* OpenRouter's provider ignores it, so it receives the equivalent provider option.
+ * Models that always reason raise lower levels to the lowest effort they accept.
*/
export function reasoningCallSettings(
providerID: AIProviderID,
- level: ThinkingLevel
+ level: ThinkingLevel,
+ minEffort?: ReasoningEffort
): ReasoningCallSettings {
- if (level === 'default') return {}
- const reasoning = level === 'off' ? 'none' : level
+ const effective = raisedLevel(level, minEffort)
+ if (effective === 'default') return {}
+ const reasoning = effective === 'off' ? 'none' : effective
if (providerID === 'openrouter') {
return { providerOptions: { openrouter: { reasoning: { effort: reasoning } } } }
}
return { reasoning }
}
+
+/** Reasoning settings for a runtime's own thinking level. */
+export function runtimeReasoningSettings(
+ runtime: Pick<DirectAIModelRuntime, 'role' | 'minReasoningEffort'>
+): ReasoningCallSettings {
+ return reasoningCallSettings(
+ runtime.role.connection.providerID,
+ runtime.role.profile.thinkingLevel,
+ runtime.minReasoningEffort
+ )
+}
diff --git a/src/app/ai/chat/transports.ts b/src/app/ai/chat/transports.ts
index 861cb2a4d..76e60dff6 100644
--- a/src/app/ai/chat/transports.ts
+++ b/src/app/ai/chat/transports.ts
@@ -12,7 +12,7 @@ import type { ComputedRef, Ref } from 'vue'
import { ref } from 'vue'
import { ACP_AGENTS } from '@open-pencil/core/constants'
-import type { ACPAgentID, AIProviderID } from '@open-pencil/core/constants'
+import type { ACPAgentID, AIProviderID, ReasoningEffort } from '@open-pencil/core/constants'
import { AgentSetupError, assertAgentReady } from '@/app/ai/agents/readiness'
import { classifyAIChatError, type AIChatFailure } from '@/app/ai/chat/failure'
@@ -62,6 +62,7 @@ export type ToolLoopTransportOptions = {
providerID: AIProviderID
model: LanguageModel
effectiveModelID: string
+ minReasoningEffort?: ReasoningEffort
maxOutputTokens: number
/** Read per request, so the composer's level applies to the next message. */
thinkingLevel: () => ThinkingLevel
@@ -94,9 +95,14 @@ function mergeProviderOptions(
function callSettings(
providerID: AIProviderID,
cacheOptions: typeof ANTHROPIC_CACHE_CONTROL | undefined,
- thinkingLevel: ThinkingLevel
+ thinkingLevel: ThinkingLevel,
+ minReasoningEffort: ReasoningEffort | undefined
) {
- const { reasoning, providerOptions } = reasoningCallSettings(providerID, thinkingLevel)
+ const { reasoning, providerOptions } = reasoningCallSettings(
+ providerID,
+ thinkingLevel,
+ minReasoningEffort
+ )
return { reasoning, providerOptions: mergeProviderOptions(cacheOptions, providerOptions) }
}
@@ -115,6 +121,7 @@ export function createToolLoopTransport({
providerID,
model,
effectiveModelID,
+ minReasoningEffort,
maxOutputTokens,
thinkingLevel,
onError,
@@ -159,7 +166,7 @@ export function createToolLoopTransport({
stopWhen: stepCountIs(currentRun(store).maxSteps),
tools: offered,
maxOutputTokens,
- ...callSettings(providerID, cacheProviderOptions, thinkingLevel())
+ ...callSettings(providerID, cacheProviderOptions, thinkingLevel(), minReasoningEffort)
}
},
onFinish: () => {
@@ -391,6 +398,7 @@ export function createChatSessionManager({
modelID: runtime.role.profile.modelID,
customModelID: runtime.role.profile.customModelID
}),
+ minReasoningEffort: runtime.minReasoningEffort,
maxOutputTokens: runtime.role.profile.maxOutputTokens,
thinkingLevel: () => chatThinkingLevel.value,
onError: captureProviderError,
diff --git a/src/app/ai/models/runtime.ts b/src/app/ai/models/runtime.ts
index c25865d10..4e3154600 100644
--- a/src/app/ai/models/runtime.ts
+++ b/src/app/ai/models/runtime.ts
@@ -1,7 +1,10 @@
import type { LanguageModel } from 'ai'
import { ref } from 'vue'
-import { createLanguageModel } from '@/app/ai/chat/model'
+import type { ReasoningEffort } from '@open-pencil/core/constants'
+
+import { createLanguageModel, resolveLanguageModelID } from '@/app/ai/chat/model'
+import { resolveProviderModel } from '@/app/ai/chat/provider-models'
import { modelConnection, resolveAIModelRole } from '@/app/ai/models/store'
import type { AIModelConnection, AIModelRole, ResolvedAIModelRole } from '@/app/ai/models/types'
import { appCredentialServices } from '@/app/settings/credentials/app'
@@ -15,6 +18,7 @@ export type DirectAIModelRuntime = {
kind: 'direct'
role: ResolvedAIModelRole
model: LanguageModel
+ minReasoningEffort?: ReasoningEffort
}
export type ACPModelRuntime = {
@@ -88,9 +92,15 @@ export async function createAIModelRuntime(role: AIModelRole): Promise<AIModelRu
const apiKey = await resolveModelConnectionAPIKey(resolved.connection.id)
if (!apiKey) throw new Error(`Credential is unavailable for the ${role} model role`)
+ const { providerID } = resolved.connection
+ const known = await resolveProviderModel(
+ providerID,
+ resolveLanguageModelID({ providerID, ...resolved.profile })
+ )
return {
kind: 'direct',
role: resolved,
+ minReasoningEffort: known?.minReasoningEffort,
model: createLanguageModel({
providerID: resolved.connection.providerID,
apiKey,
diff --git a/src/app/ai/tools/vision.ts b/src/app/ai/tools/vision.ts
index e4a5bc93a..87f5292ea 100644
--- a/src/app/ai/tools/vision.ts
+++ b/src/app/ai/tools/vision.ts
@@ -4,7 +4,7 @@ import * as v from 'valibot'
import { computeContentBounds } from '@open-pencil/core/io'
-import { reasoningCallSettings } from '@/app/ai/chat/reasoning'
+import { runtimeReasoningSettings } from '@/app/ai/chat/reasoning'
import { createAIModelRuntime } from '@/app/ai/models'
import { runPageId } from '@/app/ai/tools/run'
import type { VisionModelDependencies } from '@/app/ai/vision-runtime'
@@ -72,10 +72,7 @@ export async function inspectRenderedDesign(
const result = await dependencies.inspect({
model: runtime.model,
maxOutputTokens: Math.min(runtime.role.profile.maxOutputTokens, MAX_VISION_OUTPUT_TOKENS),
- ...reasoningCallSettings(
- runtime.role.connection.providerID,
- runtime.role.profile.thinkingLevel
- ),
+ ...runtimeReasoningSettings(runtime),
messages: [
{
role: 'user',
diff --git a/tests/app/ai/chat/provider-models.test.ts b/tests/app/ai/chat/provider-models.test.ts
new file mode 100644
index 000000000..b6aceae5b
--- /dev/null
+++ b/tests/app/ai/chat/provider-models.test.ts
@@ -0,0 +1,131 @@
+import { afterEach, describe, expect, spyOn, test } from 'bun:test'
+
+import {
+ normalizeOpenRouterModel,
+ resetOpenRouterModelsForTests,
+ resolveProviderModel
+} from '@/app/ai/chat/provider-models'
+import * as cache from '@/app/cache'
+
+import { fetchStub } from '#tests/helpers/fetch'
+
+afterEach(() => resetOpenRouterModelsForTests())
+
+describe('normalizeOpenRouterModel', () => {
+ test('keeps tool-capable OpenRouter models', () => {
+ expect(
+ normalizeOpenRouterModel({
+ id: 'meta-llama/llama-3.3-70b-instruct',
+ name: 'Llama 3.3 70B Instruct',
+ supported_parameters: ['tools'],
+ architecture: { input_modalities: ['text', 'image'] },
+ top_provider: { max_completion_tokens: 32_768 }
+ })
+ ).toEqual({
+ id: 'meta-llama/llama-3.3-70b-instruct',
+ name: 'Llama 3.3 70B Instruct',
+ capabilities: ['tools', 'vision'],
+ recommendedMaxOutputTokens: 32_768
+ })
+ })
+
+ test('skips OpenRouter models without tool support', () => {
+ expect(
+ normalizeOpenRouterModel({
+ id: 'text-only/model',
+ name: 'Text Only',
+ supported_parameters: []
+ })
+ ).toBeNull()
+ })
+
+ test('takes the lowest listed effort of models that always reason', () => {
+ const model = (reasoning: { mandatory: boolean; supported_efforts?: string[] }) =>
+ normalizeOpenRouterModel({ id: 'm', supported_parameters: ['tools'], reasoning })
+ expect(
+ model({ mandatory: true, supported_efforts: ['max', 'xhigh', 'high', 'medium', 'low'] })
+ ).toMatchObject({ minReasoningEffort: 'low' })
+ expect(model({ mandatory: true })).toMatchObject({ minReasoningEffort: 'minimal' })
+ expect(model({ mandatory: false, supported_efforts: ['low'] })).not.toHaveProperty(
+ 'minReasoningEffort'
+ )
+ })
+})
+
+describe('resolveProviderModel', () => {
+ test('reads curated models for direct providers', async () => {
+ expect(await resolveProviderModel('minimax', 'MiniMax-M3.1-Flash')).toMatchObject({
+ minReasoningEffort: 'low'
+ })
+ expect(await resolveProviderModel('minimax', 'MiniMax-M3')).not.toHaveProperty(
+ 'minReasoningEffort'
+ )
+ })
+
+ test('reads OpenRouter’s own model metadata', async () => {
+ const fetcher = fetchStub(async () =>
+ Response.json({
+ data: [
+ {
+ id: 'minimax/minimax-m3.1-flash:free',
+ supported_parameters: ['tools', 'reasoning'],
+ reasoning: { mandatory: true, supported_efforts: ['max', 'low'] }
+ }
+ ]
+ })
+ )
+ expect(
+ await resolveProviderModel('openrouter', 'minimax/minimax-m3.1-flash:free', fetcher)
+ ).toMatchObject({ minReasoningEffort: 'low' })
+ })
+
+ test('falls back to curated models when the request times out, then retries', async () => {
+ const deadline = new AbortController()
+ const timeout = spyOn(AbortSignal, 'timeout').mockReturnValue(deadline.signal)
+ let stall = true
+ const { promise: started, resolve: start } = Promise.withResolvers<undefined>()
+ const fetcher = fetchStub(async (_input, init) => {
+ if (!stall) {
+ return Response.json({ data: [{ id: 'some/model', supported_parameters: ['tools'] }] })
+ }
+ start(undefined)
+ return new Promise<Response>((_resolve, reject) => {
+ init?.signal?.addEventListener('abort', () => reject(init.signal?.reason))
+ })
+ })
+ try {
+ const pending = resolveProviderModel('openrouter', 'some/model', fetcher)
+ await started
+ deadline.abort(new DOMException('The operation timed out.', 'TimeoutError'))
+ expect(await pending).toBeUndefined()
+ expect(timeout).toHaveBeenCalledWith(10_000)
+
+ stall = false
+ expect(await resolveProviderModel('openrouter', 'some/model', fetcher)).toMatchObject({
+ id: 'some/model'
+ })
+ } finally {
+ timeout.mockRestore()
+ }
+ })
+
+ test('fetches models when the model cache cannot be read or written', async () => {
+ const read = spyOn(cache, 'readCacheJSON').mockRejectedValueOnce(new Error('storage denied'))
+ const write = spyOn(cache, 'writeCacheJSON').mockRejectedValueOnce(new Error('quota exceeded'))
+ const warn = spyOn(console, 'warn').mockImplementation(() => undefined)
+ const fetcher = fetchStub(async () =>
+ Response.json({ data: [{ id: 'some/model', supported_parameters: ['tools'] }] })
+ )
+ try {
+ expect(await resolveProviderModel('openrouter', 'some/model', fetcher)).toMatchObject({
+ id: 'some/model'
+ })
+ expect(write).toHaveBeenCalledTimes(1)
+ expect(warn).toHaveBeenCalledTimes(1)
+ } finally {
+ read.mockRestore()
+ write.mockRestore()
+ warn.mockRestore()
+ }
+ })
+})
diff --git a/tests/app/ai/chat/reasoning.test.ts b/tests/app/ai/chat/reasoning.test.ts
new file mode 100644
index 000000000..c693d8513
--- /dev/null
+++ b/tests/app/ai/chat/reasoning.test.ts
@@ -0,0 +1,36 @@
+import { describe, expect, test } from 'bun:test'
+
+import { reasoningCallSettings, runtimeReasoningSettings } from '@/app/ai/chat/reasoning'
+import type { DirectAIModelRuntime } from '@/app/ai/models/runtime'
+
+describe('reasoningCallSettings', () => {
+ test('maps thinking levels to the AI SDK reasoning option', () => {
+ expect(reasoningCallSettings('anthropic', 'high')).toEqual({ reasoning: 'high' })
+ expect(reasoningCallSettings('google', 'off')).toEqual({ reasoning: 'none' })
+ expect(reasoningCallSettings('openai-compatible', 'xhigh')).toEqual({ reasoning: 'xhigh' })
+ expect(reasoningCallSettings('openrouter', 'low')).toEqual({
+ providerOptions: { openrouter: { reasoning: { effort: 'low' } } }
+ })
+ expect(reasoningCallSettings('anthropic', 'default')).toEqual({})
+ })
+
+ test('raises levels below a model’s lowest supported effort', () => {
+ expect(reasoningCallSettings('minimax', 'default', 'low')).toEqual({})
+ expect(reasoningCallSettings('minimax', 'off', 'low')).toEqual({ reasoning: 'low' })
+ expect(reasoningCallSettings('minimax', 'minimal', 'low')).toEqual({ reasoning: 'low' })
+ expect(reasoningCallSettings('minimax', 'medium', 'low')).toEqual({ reasoning: 'medium' })
+ expect(reasoningCallSettings('openrouter', 'off', 'minimal')).toEqual({
+ providerOptions: { openrouter: { reasoning: { effort: 'minimal' } } }
+ })
+ })
+
+ test('applies a runtime’s floor to its own thinking level', () => {
+ const runtime = {
+ role: { connection: { providerID: 'openrouter' }, profile: { thinkingLevel: 'off' } },
+ minReasoningEffort: 'low'
+ } as Pick<DirectAIModelRuntime, 'role' | 'minReasoningEffort'>
+ expect(runtimeReasoningSettings(runtime)).toEqual({
+ providerOptions: { openrouter: { reasoning: { effort: 'low' } } }
+ })
+ })
+})
diff --git a/tests/engine/app/ai/attachment/image.test.ts b/tests/engine/app/ai/attachment/image.test.ts
index 474832cd4..dc99054f2 100644
--- a/tests/engine/app/ai/attachment/image.test.ts
+++ b/tests/engine/app/ai/attachment/image.test.ts
@@ -70,7 +70,12 @@ describe('image attachment analysis', () => {
model: {} as LanguageModel,
role: {
requestedRole: 'vision',
- profile: { maxOutputTokens: 8000, thinkingLevel: 'low' },
+ profile: {
+ modelID: 'anthropic/claude-sonnet-4.6',
+ customModelID: '',
+ maxOutputTokens: 8000,
+ thinkingLevel: 'low'
+ },
connection: { providerID: 'openrouter' }
}
}) as never,
diff --git a/tests/engine/app/ai/model/providers.test.ts b/tests/engine/app/ai/model/providers.test.ts
index 2d00d12de..8f0788369 100644
--- a/tests/engine/app/ai/model/providers.test.ts
+++ b/tests/engine/app/ai/model/providers.test.ts
@@ -5,7 +5,8 @@ import type { LanguageModel } from 'ai'
import { AI_PROVIDERS } from '@open-pencil/core/constants'
import { resolveLanguageModelID } from '@/app/ai/chat/model'
-import { normalizeOpenRouterModel } from '@/app/ai/chat/provider-models'
+import { resolveProviderModel } from '@/app/ai/chat/provider-models'
+import { reasoningCallSettings } from '@/app/ai/chat/reasoning'
import { createAnthropicCompatibleAdapter } from '@/app/ai/providers/compatible'
import { modelProviderAdapter } from '@/app/ai/providers/registry'
import type { ModelConfig } from '@/app/ai/providers/types'
@@ -39,39 +40,83 @@ describe('resolveLanguageModelID', () => {
})
describe('model provider registry', () => {
- test('offers MiniMax-M3 as the default MiniMax model', () => {
+ test('offers Flash first and M3 as the MiniMax fallback', () => {
const provider = AI_PROVIDERS.find(({ id }) => id === 'minimax')
- expect(provider?.defaultModel).toBe('MiniMax-M3')
- expect(provider?.models[0]).toMatchObject({ id: 'MiniMax-M3' })
+ expect(provider?.defaultModel).toBe('MiniMax-M3.1-Flash')
+ expect(provider?.models.map(({ id }) => id)).toEqual(['MiniMax-M3.1-Flash', 'MiniMax-M3'])
})
- test('sends MiniMax-M3 through the OpenAI-compatible chat endpoint', async () => {
- let requestURL = ''
- let requestBody = ''
- const fetchSpy: FetchFunction = async (input, init) => {
- requestURL = String(input)
- requestBody = String(init?.body)
- throw new Error('stop')
+ test.each(['MiniMax-M3.1-Flash', 'MiniMax-M3', 'MiniMax-M2.7'])(
+ 'sends %s through the OpenAI-compatible chat endpoint',
+ async (modelID) => {
+ let requestURL = ''
+ let requestBody = ''
+ const fetchSpy: FetchFunction = async (input, init) => {
+ requestURL = String(input)
+ requestBody = String(init?.body)
+ throw new Error('stop')
+ }
+ const config: ModelConfig = {
+ providerID: 'minimax',
+ apiKey: 'test-key',
+ modelID,
+ customModelID: '',
+ customBaseURL: '',
+ customAPIType: 'completions'
+ }
+
+ const model = languageModelInstance(
+ modelProviderAdapter('minimax').create(config, { fetch: fetchSpy })
+ )
+ await Promise.resolve(
+ model.doGenerate({ prompt: [{ role: 'user', content: [{ type: 'text', text: 'hi' }] }] })
+ ).catch(() => undefined)
+
+ const body: unknown = JSON.parse(requestBody)
+ expect(requestURL).toBe('https://api.minimax.io/v1/chat/completions')
+ expect(body).toMatchObject({ model: modelID })
+ expect(body).not.toHaveProperty('reasoning_effort')
+ expect(body).not.toHaveProperty('thinking')
}
- const config: ModelConfig = {
- providerID: 'minimax',
- apiKey: 'test-key',
- modelID: 'MiniMax-M3',
- customModelID: '',
- customBaseURL: '',
- customAPIType: 'completions'
+ )
+
+ test.each(['off', 'minimal', 'low', 'medium', 'high', 'xhigh'] as const)(
+ 'sends a supported Flash effort for %s',
+ async (level) => {
+ let requestBody = ''
+ const fetchSpy: FetchFunction = async (_input, init) => {
+ requestBody = String(init?.body)
+ throw new Error('stop')
+ }
+ const model = languageModelInstance(
+ modelProviderAdapter('minimax').create(
+ {
+ providerID: 'minimax',
+ apiKey: 'test-key',
+ modelID: 'MiniMax-M3.1-Flash',
+ customModelID: '',
+ customBaseURL: '',
+ customAPIType: 'completions'
+ },
+ { fetch: fetchSpy }
+ )
+ )
+ await Promise.resolve(
+ model.doGenerate({
+ ...reasoningCallSettings(
+ 'minimax',
+ level,
+ (await resolveProviderModel('minimax', 'MiniMax-M3.1-Flash'))?.minReasoningEffort
+ ),
+ prompt: [{ role: 'user', content: [{ type: 'text', text: 'hi' }] }]
+ })
+ ).catch(() => undefined)
+ expect(JSON.parse(requestBody)).toMatchObject({
+ model: 'MiniMax-M3.1-Flash',
+ reasoning_effort: level === 'off' || level === 'minimal' ? 'low' : level
+ })
}
-
- const model = languageModelInstance(
- modelProviderAdapter('minimax').create(config, { fetch: fetchSpy })
- )
- await Promise.resolve(
- model.doGenerate({ prompt: [{ role: 'user', content: [{ type: 'text', text: 'hi' }] }] })
- ).catch(() => undefined)
-
- expect(requestURL).toBe('https://api.minimax.io/v1/chat/completions')
- expect(requestBody).toContain('"model":"MiniMax-M3"')
- })
+ )
test('registers every direct provider without handling agent runtimes as models', () => {
for (const provider of AI_PROVIDERS.filter((entry) => entry.id !== 'harness:pi')) {
@@ -120,32 +165,3 @@ describe('anthropic compatible adapter', () => {
)
})
})
-
-describe('normalizeOpenRouterModel', () => {
- test('keeps tool-capable OpenRouter models', () => {
- expect(
- normalizeOpenRouterModel({
- id: 'meta-llama/llama-3.3-70b-instruct',
- name: 'Llama 3.3 70B Instruct',
- supported_parameters: ['tools'],
- architecture: { input_modalities: ['text', 'image'] },
- top_provider: { max_completion_tokens: 32_768 }
- })
- ).toEqual({
- id: 'meta-llama/llama-3.3-70b-instruct',
- name: 'Llama 3.3 70B Instruct',
- capabilities: ['tools', 'vision'],
- recommendedMaxOutputTokens: 32_768
- })
- })
-
- test('skips OpenRouter models without tool support', () => {
- expect(
- normalizeOpenRouterModel({
- id: 'text-only/model',
- name: 'Text Only',
- supported_parameters: []
- })
- ).toBeNull()
- })
-})
diff --git a/tests/engine/app/ai/model/roles.test.ts b/tests/engine/app/ai/model/roles.test.ts
index b6c96792b..68437fc45 100644
--- a/tests/engine/app/ai/model/roles.test.ts
+++ b/tests/engine/app/ai/model/roles.test.ts
@@ -2,7 +2,6 @@ import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
import { omit } from 'es-toolkit'
-import { reasoningCallSettings } from '@/app/ai/chat/reasoning'
import {
aiModelSettings,
createAIModelRuntime,
@@ -241,16 +240,6 @@ describe('AI model profiles and role assignments', () => {
expect(parsed?.models.map((profile) => profile.thinkingLevel)).toEqual(['high', 'off'])
})
- test('maps thinking levels to the AI SDK reasoning option', () => {
- expect(reasoningCallSettings('anthropic', 'high')).toEqual({ reasoning: 'high' })
- expect(reasoningCallSettings('google', 'off')).toEqual({ reasoning: 'none' })
- expect(reasoningCallSettings('openai-compatible', 'xhigh')).toEqual({ reasoning: 'xhigh' })
- expect(reasoningCallSettings('openrouter', 'low')).toEqual({
- providerOptions: { openrouter: { reasoning: { effort: 'low' } } }
- })
- expect(reasoningCallSettings('anthropic', 'default')).toEqual({})
- })
-
test('repairs assignments when removing a model', () => {
expect(canRemoveModelProfile('model-design')).toBe(true)
removeModelProfile('model-design')
diff --git a/tests/engine/app/ai/vision.test.ts b/tests/engine/app/ai/vision.test.ts
index 48113b37e..d06519883 100644
--- a/tests/engine/app/ai/vision.test.ts
+++ b/tests/engine/app/ai/vision.test.ts
@@ -35,7 +35,12 @@ describe('isolated visual inspection', () => {
model: {} as LanguageModel,
role: {
requestedRole: 'vision',
- profile: { maxOutputTokens: 8000, thinkingLevel: 'low' },
+ profile: {
+ modelID: 'anthropic/claude-sonnet-4.6',
+ customModelID: '',
+ maxOutputTokens: 8000,
+ thinkingLevel: 'low'
+ },
connection: { providerID: 'openrouter' }
}
}) as never,