Skip to content

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

feat(ai): refresh recommended models and fix Off thinking for models that always reason (#1373)

Danila Poyarkovc3525b2aa1f3
diff --git a/changes/1373/changed.md b/changes/1373/changed.md
new file mode 100644
index 000000000..61e8b2061
--- /dev/null
+++ b/changes/1373/changed.md
@@ -0,0 +1 @@
+- Recommended models now include Claude Haiku 5.5, used for fast work with an Anthropic key, Gemini 4 Argon, GLM-5.3-FlashX, and the free MiniMax-M3.1-Flash route on OpenRouter. DeepSeek recommends DeepSeek Flash, and Z.ai lists its current models; earlier models remain available from the full model list.
diff --git a/changes/1373/fixed.md b/changes/1373/fixed.md
new file mode 100644
index 000000000..885771f59
--- /dev/null
+++ b/changes/1373/fixed.md
@@ -0,0 +1,2 @@
+- Off and Minimal thinking no longer fail on GLM-5.3, GLM-5.3-Flash, or Gemini 3.1 Pro, and no longer run GPT-6.1 Sol and GPT-6 Astra at their default effort: these models use low, the lowest each accepts.
+- The free model shown first for OpenRouter no longer points at the removed Qwen3.8 27B route.
diff --git a/packages/core/src/ai/providers.ts b/packages/core/src/ai/providers.ts
new file mode 100644
index 000000000..c20a06320
--- /dev/null
+++ b/packages/core/src/ai/providers.ts
@@ -0,0 +1,346 @@
+/** ACP agents, direct AI providers, and the models each provider recommends. */
+
+export type ACPAgentID = 'claude-code' | 'codex' | 'gemini-cli'
+
+export interface ACPAgentDef {
+ id: ACPAgentID
+ name: string
+ command: string
+ args: string[]
+ /** The agent's own CLI, when the ACP program is a separate adapter for it. */
+ cliCommand?: string
+ /** npm package that provides `command` when it is an adapter. */
+ adapterPackage?: string
+ /** The vendor's installation guide for the agent itself. */
+ setupURL?: string
+ installCommand?: string
+}
+
+export const ACP_AGENTS: ACPAgentDef[] = [
+ {
+ id: 'claude-code',
+ name: 'Claude Code',
+ command: 'claude-agent-acp',
+ args: [],
+ cliCommand: 'claude',
+ adapterPackage: '@agentclientprotocol/claude-agent-acp',
+ setupURL: 'https://code.claude.com/docs/en/setup',
+ installCommand: 'npm i -g @agentclientprotocol/claude-agent-acp'
+ },
+ {
+ id: 'codex',
+ name: 'Codex',
+ command: 'codex-acp',
+ args: [],
+ cliCommand: 'codex',
+ adapterPackage: '@agentclientprotocol/codex-acp',
+ setupURL: 'https://developers.openai.com/codex/cli',
+ installCommand: 'npm i -g @agentclientprotocol/codex-acp'
+ },
+ {
+ id: 'gemini-cli',
+ name: 'Gemini CLI',
+ command: 'gemini',
+ args: ['--acp'],
+ setupURL: 'https://geminicli.com/docs/get-started/installation/',
+ installCommand: 'npm i -g @google/gemini-cli'
+ }
+]
+
+export type AIProviderID =
+ | 'openrouter'
+ | 'anthropic'
+ | 'openai'
+ | 'google'
+ | 'deepseek'
+ | 'openai-compatible'
+ | 'zai'
+ | 'minimax'
+ | 'anthropic-compatible'
+ | '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
+ tag?: string
+ capabilities?: readonly ('tools' | 'vision')[]
+ 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 {
+ id: AIProviderID
+ name: string
+ keyPlaceholder: string
+ keyURL: string
+ models: ModelOption[]
+ defaultModel: string
+ supportsCustomBaseURL?: boolean
+ supportsCustomModel?: boolean
+}
+
+export const HARNESS_PROVIDER_ID = 'harness:pi' as const
+
+export const AI_PROVIDERS: AIProviderDef[] = [
+ {
+ id: HARNESS_PROVIDER_ID,
+ name: 'Pi',
+ keyPlaceholder: 'AI Gateway key (optional)',
+ keyURL: '',
+ defaultModel: '',
+ supportsCustomModel: true,
+ models: []
+ },
+ {
+ id: 'openrouter',
+ name: 'OpenRouter',
+ keyPlaceholder: 'sk-or-…',
+ keyURL: 'https://openrouter.ai/keys',
+ defaultModel: 'anthropic/claude-sonnet-5.5',
+ supportsCustomModel: true,
+ models: [
+ {
+ id: 'anthropic/claude-sonnet-5.5',
+ name: 'Claude Sonnet 5.5',
+ tag: 'Best for design',
+ capabilities: ['tools', 'vision']
+ },
+ {
+ id: 'anthropic/claude-opus-5.5',
+ name: 'Claude Opus 5.5',
+ tag: 'Deep reasoning',
+ capabilities: ['tools', 'vision']
+ },
+ {
+ id: 'anthropic/claude-fable-5.1',
+ name: 'Claude Fable 5.1',
+ tag: 'Most capable',
+ capabilities: ['tools', 'vision']
+ },
+ {
+ id: 'anthropic/claude-haiku-5.5',
+ name: 'Claude Haiku 5.5',
+ tag: 'Fast',
+ capabilities: ['tools', 'vision']
+ },
+ {
+ id: 'openai/gpt-6.1-sol',
+ name: 'GPT-6.1 Sol',
+ tag: 'Latest OpenAI',
+ capabilities: ['tools', 'vision']
+ },
+ {
+ id: 'google/gemini-3.8-flash',
+ name: 'Gemini 3.8 Flash',
+ tag: 'Fast',
+ capabilities: ['tools', 'vision']
+ },
+ { id: 'z-ai/glm-5.3', name: 'GLM-5.3', capabilities: ['tools'] },
+ {
+ id: 'deepseek/deepseek-v4-pro',
+ name: 'DeepSeek V4 Pro',
+ tag: 'Reasoning',
+ capabilities: ['tools']
+ },
+ {
+ id: 'moonshotai/kimi-k3',
+ name: 'Kimi K3',
+ tag: 'Vision + code',
+ capabilities: ['tools', 'vision']
+ },
+ {
+ id: 'minimax/minimax-m3.1-flash:free',
+ name: 'MiniMax-M3.1-Flash',
+ tag: 'Free',
+ capabilities: ['tools', 'vision']
+ },
+ {
+ id: 'google/gemma-4-31b-it:free',
+ name: 'Gemma 4 31B',
+ tag: 'Free',
+ capabilities: ['tools', 'vision']
+ }
+ ]
+ },
+ {
+ id: 'anthropic',
+ name: 'Anthropic',
+ keyPlaceholder: 'sk-ant-…',
+ keyURL: 'https://console.anthropic.com/settings/keys',
+ defaultModel: 'claude-sonnet-5-5',
+ models: [
+ {
+ id: 'claude-sonnet-5-5',
+ name: 'Claude Sonnet 5.5',
+ tag: 'Best for design',
+ capabilities: ['tools', 'vision']
+ },
+ {
+ id: 'claude-opus-5-5',
+ name: 'Claude Opus 5.5',
+ tag: 'Deep reasoning',
+ capabilities: ['tools', 'vision']
+ },
+ {
+ id: 'claude-fable-5-1',
+ name: 'Claude Fable 5.1',
+ tag: 'Most capable',
+ capabilities: ['tools', 'vision']
+ },
+ {
+ id: 'claude-haiku-5-5',
+ name: 'Claude Haiku 5.5',
+ tag: 'Fast',
+ capabilities: ['tools', 'vision']
+ }
+ ]
+ },
+ {
+ id: 'openai',
+ name: 'OpenAI',
+ keyPlaceholder: 'sk-…',
+ keyURL: 'https://platform.openai.com/api-keys',
+ defaultModel: 'gpt-6.1-sol',
+ models: [
+ {
+ id: 'gpt-6.1-sol',
+ name: 'GPT-6.1 Sol',
+ tag: 'Best',
+ capabilities: ['tools', 'vision'],
+ minReasoningEffort: 'low'
+ },
+ {
+ id: 'gpt-6-astra',
+ name: 'GPT-6 Astra',
+ tag: 'Smartest',
+ capabilities: ['tools', 'vision'],
+ minReasoningEffort: 'low'
+ },
+ { id: 'gpt-6-luna', name: 'GPT-6 Luna', tag: 'Fast', capabilities: ['tools', 'vision'] }
+ ]
+ },
+ {
+ id: 'google',
+ name: 'Google AI',
+ keyPlaceholder: 'AIza…',
+ keyURL: 'https://aistudio.google.com/apikey',
+ defaultModel: 'gemini-3.8-flash',
+ models: [
+ {
+ id: 'gemini-3.8-flash',
+ name: 'Gemini 3.8 Flash',
+ tag: 'Best',
+ capabilities: ['tools', 'vision']
+ },
+ {
+ id: 'gemini-4-argon',
+ name: 'Gemini 4 Argon',
+ tag: 'Most capable',
+ capabilities: ['tools', 'vision'],
+ minReasoningEffort: 'low'
+ },
+ {
+ id: 'gemini-flash-latest',
+ name: 'Gemini Flash Latest',
+ tag: 'Alias',
+ capabilities: ['tools', 'vision']
+ },
+ {
+ id: 'gemini-3.1-pro-preview',
+ name: 'Gemini 3.1 Pro',
+ tag: 'Pro',
+ capabilities: ['tools', 'vision'],
+ minReasoningEffort: 'low'
+ }
+ ]
+ },
+ {
+ id: 'deepseek',
+ name: 'DeepSeek',
+ keyPlaceholder: 'sk-…',
+ keyURL: 'https://platform.deepseek.com/api_keys',
+ defaultModel: 'deepseek-flash',
+ models: [
+ { id: 'deepseek-flash', name: 'DeepSeek Flash', tag: 'Fast' },
+ { id: 'deepseek-v4-pro', name: 'DeepSeek V4 Pro', tag: 'Reasoning' }
+ ]
+ },
+ {
+ id: 'zai',
+ name: 'Z.ai',
+ keyPlaceholder: 'API key',
+ keyURL: 'https://docs.z.ai/devpack/quick-start',
+ defaultModel: 'glm-5.3',
+ models: [
+ { id: 'glm-5.3', name: 'GLM-5.3', tag: 'Best', minReasoningEffort: 'low' },
+ {
+ id: 'glm-5.3-flash',
+ name: 'GLM-5.3-Flash',
+ tag: 'Fast',
+ capabilities: ['tools', 'vision'],
+ minReasoningEffort: 'low'
+ },
+ {
+ id: 'glm-5.3-flashx',
+ name: 'GLM-5.3-FlashX',
+ capabilities: ['tools', 'vision'],
+ minReasoningEffort: 'low'
+ },
+ {
+ id: 'glm-5v-turbo',
+ name: 'GLM-5V-Turbo',
+ tag: 'Vision',
+ capabilities: ['tools', 'vision']
+ },
+ { id: 'glm-5.2', name: 'GLM-5.2' },
+ { id: 'glm-4.7-flash', name: 'GLM-4.7-Flash', tag: 'Free' }
+ ]
+ },
+ {
+ id: 'minimax',
+ name: 'MiniMax',
+ keyPlaceholder: 'API key',
+ keyURL: 'https://platform.minimax.io/user-center/basic-information/interface-key',
+ defaultModel: 'MiniMax-M3.1-Flash',
+ models: [
+ {
+ id: 'MiniMax-M3.1-Flash',
+ name: 'MiniMax-M3.1-Flash',
+ tag: 'Best',
+ minReasoningEffort: 'low'
+ },
+ { id: 'MiniMax-M3', name: 'MiniMax-M3' }
+ ]
+ },
+ {
+ id: 'openai-compatible',
+ name: 'OpenAI-compatible',
+ keyPlaceholder: 'API key',
+ keyURL: '',
+ defaultModel: '',
+ models: [],
+ supportsCustomBaseURL: true,
+ supportsCustomModel: true
+ },
+ {
+ id: 'anthropic-compatible',
+ name: 'Anthropic-compatible',
+ keyPlaceholder: 'API key',
+ keyURL: '',
+ defaultModel: '',
+ models: [],
+ supportsCustomBaseURL: true,
+ supportsCustomModel: true
+ }
+]
+
+export const DEFAULT_AI_PROVIDER: AIProviderID = 'openai-compatible'
+export const DEFAULT_AI_MODEL =
+ AI_PROVIDERS.find((provider) => provider.id === DEFAULT_AI_PROVIDER)?.defaultModel ?? ''
diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts
index 8434af936..c93aca754 100644
--- a/packages/core/src/constants.ts
+++ b/packages/core/src/constants.ts
@@ -4,6 +4,8 @@ import type { Color } from '@open-pencil/scene-graph/primitives'
import type { SelectionTheme } from '#core/canvas/renderer/types'
+export * from './ai/providers'
+
export const IS_BROWSER = typeof window !== 'undefined'
export const IS_TAURI = IS_BROWSER && '__TAURI_INTERNALS__' in window
@@ -170,325 +172,6 @@ export const TEXT_SELECTION_ALPHA = 0.3
export const TEXT_CARET_COLOR = BLACK
export const TEXT_CARET_WIDTH = 1
-export type ACPAgentID = 'claude-code' | 'codex' | 'gemini-cli'
-
-export interface ACPAgentDef {
- id: ACPAgentID
- name: string
- command: string
- args: string[]
- /** The agent's own CLI, when the ACP program is a separate adapter for it. */
- cliCommand?: string
- /** npm package that provides `command` when it is an adapter. */
- adapterPackage?: string
- /** The vendor's installation guide for the agent itself. */
- setupURL?: string
- installCommand?: string
-}
-
-export const ACP_AGENTS: ACPAgentDef[] = [
- {
- id: 'claude-code',
- name: 'Claude Code',
- command: 'claude-agent-acp',
- args: [],
- cliCommand: 'claude',
- adapterPackage: '@agentclientprotocol/claude-agent-acp',
- setupURL: 'https://code.claude.com/docs/en/setup',
- installCommand: 'npm i -g @agentclientprotocol/claude-agent-acp'
- },
- {
- id: 'codex',
- name: 'Codex',
- command: 'codex-acp',
- args: [],
- cliCommand: 'codex',
- adapterPackage: '@agentclientprotocol/codex-acp',
- setupURL: 'https://developers.openai.com/codex/cli',
- installCommand: 'npm i -g @agentclientprotocol/codex-acp'
- },
- {
- id: 'gemini-cli',
- name: 'Gemini CLI',
- command: 'gemini',
- args: ['--acp'],
- setupURL: 'https://geminicli.com/docs/get-started/installation/',
- installCommand: 'npm i -g @google/gemini-cli'
- }
-]
-
-export type AIProviderID =
- | 'openrouter'
- | 'anthropic'
- | 'openai'
- | 'google'
- | 'deepseek'
- | 'openai-compatible'
- | 'zai'
- | 'minimax'
- | 'anthropic-compatible'
- | '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
- tag?: string
- capabilities?: readonly ('tools' | 'vision')[]
- 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 {
- id: AIProviderID
- name: string
- keyPlaceholder: string
- keyURL: string
- models: ModelOption[]
- defaultModel: string
- supportsCustomBaseURL?: boolean
- supportsCustomModel?: boolean
-}
-
-export const HARNESS_PROVIDER_ID = 'harness:pi' as const
-
-export const AI_PROVIDERS: AIProviderDef[] = [
- {
- id: HARNESS_PROVIDER_ID,
- name: 'Pi',
- keyPlaceholder: 'AI Gateway key (optional)',
- keyURL: '',
- defaultModel: '',
- supportsCustomModel: true,
- models: []
- },
- {
- id: 'openrouter',
- name: 'OpenRouter',
- keyPlaceholder: 'sk-or-…',
- keyURL: 'https://openrouter.ai/keys',
- defaultModel: 'anthropic/claude-sonnet-5.5',
- supportsCustomModel: true,
- models: [
- {
- id: 'anthropic/claude-sonnet-5.5',
- name: 'Claude Sonnet 5.5',
- tag: 'Best for design',
- capabilities: ['tools', 'vision']
- },
- {
- id: 'anthropic/claude-opus-5.5',
- name: 'Claude Opus 5.5',
- tag: 'Deep reasoning',
- capabilities: ['tools', 'vision']
- },
- {
- id: 'anthropic/claude-fable-5.1',
- name: 'Claude Fable 5.1',
- tag: 'Most capable',
- capabilities: ['tools', 'vision']
- },
- {
- id: 'openai/gpt-6.1-sol',
- name: 'GPT-6.1 Sol',
- tag: 'Latest OpenAI',
- capabilities: ['tools', 'vision']
- },
- {
- id: 'google/gemini-3.8-flash',
- name: 'Gemini 3.8 Flash',
- tag: 'Fast',
- capabilities: ['tools', 'vision']
- },
- { id: 'z-ai/glm-5.3', name: 'GLM-5.3', capabilities: ['tools'] },
- {
- id: 'deepseek/deepseek-v4-pro',
- name: 'DeepSeek V4 Pro',
- tag: 'Reasoning',
- capabilities: ['tools']
- },
- {
- id: 'moonshotai/kimi-k3',
- name: 'Kimi K3',
- tag: 'Vision + code',
- capabilities: ['tools', 'vision']
- },
- {
- id: 'qwen/qwen3.8-27b:free',
- name: 'Qwen3.8 27B',
- tag: 'Free',
- capabilities: ['tools', 'vision']
- },
- {
- id: 'google/gemma-4-31b-it:free',
- name: 'Gemma 4 31B',
- tag: 'Free',
- capabilities: ['tools', 'vision']
- }
- ]
- },
- {
- id: 'anthropic',
- name: 'Anthropic',
- keyPlaceholder: 'sk-ant-…',
- keyURL: 'https://console.anthropic.com/settings/keys',
- defaultModel: 'claude-sonnet-5-5',
- models: [
- {
- id: 'claude-sonnet-5-5',
- name: 'Claude Sonnet 5.5',
- tag: 'Best for design',
- capabilities: ['tools', 'vision']
- },
- {
- id: 'claude-opus-5-5',
- name: 'Claude Opus 5.5',
- tag: 'Deep reasoning',
- capabilities: ['tools', 'vision']
- },
- {
- id: 'claude-fable-5-1',
- name: 'Claude Fable 5.1',
- tag: 'Most capable',
- capabilities: ['tools', 'vision']
- }
- ]
- },
- {
- id: 'openai',
- name: 'OpenAI',
- keyPlaceholder: 'sk-…',
- keyURL: 'https://platform.openai.com/api-keys',
- defaultModel: 'gpt-6.1-sol',
- models: [
- { id: 'gpt-6.1-sol', name: 'GPT-6.1 Sol', tag: 'Best', capabilities: ['tools', 'vision'] },
- {
- id: 'gpt-6-astra',
- name: 'GPT-6 Astra',
- tag: 'Smartest',
- capabilities: ['tools', 'vision']
- },
- { id: 'gpt-6-luna', name: 'GPT-6 Luna', tag: 'Fast', capabilities: ['tools', 'vision'] }
- ]
- },
- {
- id: 'google',
- name: 'Google AI',
- keyPlaceholder: 'AIza…',
- keyURL: 'https://aistudio.google.com/apikey',
- defaultModel: 'gemini-3.8-flash',
- models: [
- {
- id: 'gemini-3.8-flash',
- name: 'Gemini 3.8 Flash',
- tag: 'Latest',
- capabilities: ['tools', 'vision']
- },
- { id: 'gemini-3.7-flash', name: 'Gemini 3.7 Flash', capabilities: ['tools', 'vision'] },
- {
- id: 'gemini-flash-latest',
- name: 'Gemini Flash Latest',
- tag: 'Alias',
- capabilities: ['tools', 'vision']
- },
- {
- id: 'gemini-3.1-pro-preview',
- name: 'Gemini 3.1 Pro',
- tag: 'Pro',
- capabilities: ['tools', 'vision']
- }
- ]
- },
- {
- id: 'deepseek',
- name: 'DeepSeek',
- keyPlaceholder: 'sk-…',
- keyURL: 'https://platform.deepseek.com/api_keys',
- defaultModel: 'deepseek-v4-flash',
- models: [
- { id: 'deepseek-v4-flash', name: 'DeepSeek V4 Flash', tag: 'Fast' },
- { id: 'deepseek-v4-pro', name: 'DeepSeek V4 Pro', tag: 'Reasoning' }
- ]
- },
- {
- id: 'zai',
- name: 'Z.ai',
- keyPlaceholder: 'API key',
- keyURL: 'https://docs.z.ai/devpack/quick-start',
- defaultModel: 'glm-5.3',
- models: [
- { id: 'glm-5.3', name: 'GLM-5.3', tag: 'Best' },
- { id: 'glm-5.3-flash', name: 'GLM-5.3-Flash', tag: 'Fast' },
- { id: 'glm-5.2', name: 'GLM-5.2' },
- {
- id: 'glm-5v-turbo',
- name: 'GLM-5V-Turbo',
- tag: 'Vision',
- capabilities: ['tools', 'vision']
- },
- { id: 'glm-5.1', name: 'GLM-5.1' },
- { id: 'glm-5', name: 'GLM-5' },
- { id: 'glm-5-code', name: 'GLM-5-Code' },
- { id: 'glm-4.7', name: 'GLM-4.7' },
- { id: 'glm-4.7-flashx', name: 'GLM-4.7-FlashX' },
- { id: 'glm-4.6', name: 'GLM-4.6' },
- { id: 'glm-4.5', name: 'GLM-4.5' },
- { id: 'glm-4.5-x', name: 'GLM-4.5-X' },
- { id: 'glm-4.5-air', name: 'GLM-4.5-Air' },
- { id: 'glm-4.5-airx', name: 'GLM-4.5-AirX' },
- { id: 'glm-4-32b-0414-128k', name: 'GLM-4-32B-0414-128K' },
- { id: 'glm-4.7-flash', name: 'GLM-4.7-Flash', tag: 'Free' },
- { id: 'glm-4.5-flash', name: 'GLM-4.5-Flash', tag: 'Free' }
- ]
- },
- {
- id: 'minimax',
- name: 'MiniMax',
- keyPlaceholder: 'API key',
- keyURL: 'https://platform.minimax.io/user-center/basic-information/interface-key',
- defaultModel: 'MiniMax-M3.1-Flash',
- models: [
- {
- id: 'MiniMax-M3.1-Flash',
- name: 'MiniMax-M3.1-Flash',
- tag: 'Best',
- minReasoningEffort: 'low'
- },
- { id: 'MiniMax-M3', name: 'MiniMax-M3' }
- ]
- },
- {
- id: 'openai-compatible',
- name: 'OpenAI-compatible',
- keyPlaceholder: 'API key',
- keyURL: '',
- defaultModel: '',
- models: [],
- supportsCustomBaseURL: true,
- supportsCustomModel: true
- },
- {
- id: 'anthropic-compatible',
- name: 'Anthropic-compatible',
- keyPlaceholder: 'API key',
- keyURL: '',
- defaultModel: '',
- models: [],
- supportsCustomBaseURL: true,
- supportsCustomModel: true
- }
-]
-
-export const DEFAULT_AI_PROVIDER: AIProviderID = 'openai-compatible'
-export const DEFAULT_AI_MODEL =
- AI_PROVIDERS.find((provider) => provider.id === DEFAULT_AI_PROVIDER)?.defaultModel ?? ''
-
export const AUTOMATION_HTTP_PORT = 7600
/**
* Request header the app's own ACP and Pi harness chats send to the MCP server, so their sessions
diff --git a/packages/docs/de/programmable/ai-chat.md b/packages/docs/de/programmable/ai-chat.md
index 1c7b0e847..2a57dbc7a 100644
--- a/packages/docs/de/programmable/ai-chat.md
+++ b/packages/docs/de/programmable/ai-chat.md
@@ -23,11 +23,12 @@ Mehrere Modelle können getrennt für Gestaltung, Prüfung, schnelle Aufgaben un
| Anbieter | Beispiele | Einrichtung |
|----------|-----------|-------------|
| **OpenRouter** | Claude, GPT, Gemini, DeepSeek, Qwen und weitere | API-Schlüssel von [openrouter.ai](https://openrouter.ai) |
-| **Anthropic** | Claude Sonnet 4.6, Claude Opus 4.6 | API-Schlüssel von [console.anthropic.com](https://console.anthropic.com) |
-| **OpenAI** | GPT-5.3 Codex, GPT-4.1, o3, o4-mini | API-Schlüssel von [platform.openai.com](https://platform.openai.com) |
-| **Google AI** | Gemini 3.1 Pro, Gemini 3 Flash | API-Schlüssel von [aistudio.google.dev](https://aistudio.google.dev) |
-| **Z.ai** | GLM-5.1, GLM-5, GLM-4.7 und GLM-4.5 | API-Schlüssel laut [Z.ai-Dokumentation](https://docs.z.ai/devpack/quick-start) |
-| **MiniMax** | MiniMax M3, M2.7, M2.7-highspeed, M2.5 und M2.1 | API-Schlüssel von [platform.minimax.io](https://platform.minimax.io/user-center/basic-information/interface-key) |
+| **Anthropic** | Claude Sonnet 5.5, Claude Opus 5.5, Claude Fable 5.1 und Claude Haiku 5.5 | API-Schlüssel von [console.anthropic.com](https://console.anthropic.com) |
+| **OpenAI** | GPT-6.1 Sol, GPT-6 Astra und GPT-6 Luna | API-Schlüssel von [platform.openai.com](https://platform.openai.com) |
+| **Google AI** | Gemini 3.8 Flash und Gemini 4 Argon | API-Schlüssel von [aistudio.google.dev](https://aistudio.google.dev) |
+| **DeepSeek** | DeepSeek Flash und DeepSeek V4 Pro | API-Schlüssel von [platform.deepseek.com](https://platform.deepseek.com/api_keys) |
+| **Z.ai** | GLM-5.3, GLM-5.3-Flash, GLM-5.3-FlashX und GLM-5V-Turbo | API-Schlüssel laut [Z.ai-Dokumentation](https://docs.z.ai/devpack/quick-start) |
+| **MiniMax** | MiniMax-M3.1-Flash und MiniMax-M3 | API-Schlüssel von [platform.minimax.io](https://platform.minimax.io/user-center/basic-information/interface-key) |
| **OpenAI-kompatibel** | Endpunkt im OpenAI-API-Format | Eigene Basisadresse und Schlüssel |
| **Anthropic-kompatibel** | Endpunkt im Anthropic-API-Format | Eigene Basisadresse und Schlüssel |
diff --git a/packages/docs/pl/programmable/ai-chat.md b/packages/docs/pl/programmable/ai-chat.md
index 862c070f5..42e65afaf 100644
--- a/packages/docs/pl/programmable/ai-chat.md
+++ b/packages/docs/pl/programmable/ai-chat.md
@@ -23,11 +23,12 @@ Możesz utworzyć kilka modeli i osobno przypisać je do projektowania, przeglą
| Dostawca | Modele | Konfiguracja |
|----------|--------|--------------|
| **OpenRouter** | Claude, GPT, Gemini, DeepSeek, Qwen i inne | Klucz API z [openrouter.ai](https://openrouter.ai) |
-| **Anthropic** | Claude Sonnet 4.6, Claude Opus 4.6 | Klucz API z [console.anthropic.com](https://console.anthropic.com) |
-| **OpenAI** | GPT-5.3 Codex, GPT-4.1, o3, o4-mini | Klucz API z [platform.openai.com](https://platform.openai.com) |
-| **Google AI** | Gemini 3.1 Pro, Gemini 3 Flash | Klucz API z [aistudio.google.dev](https://aistudio.google.dev) |
-| **Z.ai** | GLM-5.1, GLM-5, GLM-4.7 i rodzina GLM-4.5 | Klucz API zgodnie z [dokumentacją Z.ai](https://docs.z.ai/devpack/quick-start) |
-| **MiniMax** | MiniMax M3, M2.7, M2.7-highspeed, M2.5, M2.1 | Klucz API z [platform.minimax.io](https://platform.minimax.io/user-center/basic-information/interface-key) |
+| **Anthropic** | Claude Sonnet 5.5, Claude Opus 5.5, Claude Fable 5.1, Claude Haiku 5.5 | Klucz API z [console.anthropic.com](https://console.anthropic.com) |
+| **OpenAI** | GPT-6.1 Sol, GPT-6 Astra, GPT-6 Luna | Klucz API z [platform.openai.com](https://platform.openai.com) |
+| **Google AI** | Gemini 3.8 Flash, Gemini 4 Argon | Klucz API z [aistudio.google.dev](https://aistudio.google.dev) |
+| **DeepSeek** | DeepSeek Flash, DeepSeek V4 Pro | Klucz API z [platform.deepseek.com](https://platform.deepseek.com/api_keys) |
+| **Z.ai** | GLM-5.3, GLM-5.3-Flash, GLM-5.3-FlashX, GLM-5V-Turbo | Klucz API zgodnie z [dokumentacją Z.ai](https://docs.z.ai/devpack/quick-start) |
+| **MiniMax** | MiniMax-M3.1-Flash, MiniMax-M3 | Klucz API z [platform.minimax.io](https://platform.minimax.io/user-center/basic-information/interface-key) |
| **Zgodny z OpenAI** | Dowolny punkt końcowy w formacie OpenAI API | Własny adres bazowy i klucz; wybór Completions API lub Responses API |
| **Zgodny z Anthropic** | Dowolny punkt końcowy w formacie Anthropic API | Własny adres bazowy i klucz |
diff --git a/packages/docs/programmable/ai-chat.md b/packages/docs/programmable/ai-chat.md
index 076421003..f0500d703 100644
--- a/packages/docs/programmable/ai-chat.md
+++ b/packages/docs/programmable/ai-chat.md
@@ -46,16 +46,17 @@ In the Chat settings beside the model overview, choose whether reasoning is **Co
## Supported Providers
-| Provider | Models | Setup |
-| ------------------------ | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
-| **OpenRouter** | Claude, GPT, Gemini, DeepSeek, Qwen, and others | API key from [openrouter.ai](https://openrouter.ai) |
-| **Anthropic** | Claude Sonnet 4.6, Claude Opus 4.6 | API key from [console.anthropic.com](https://console.anthropic.com) |
-| **OpenAI** | GPT-5.3 Codex, GPT-4.1, o3, o4-mini | API key from [platform.openai.com](https://platform.openai.com) |
-| **Google AI** | Gemini 3.1 Pro, Gemini 3 Flash | API key from [aistudio.google.dev](https://aistudio.google.dev) |
-| **Z.ai** | GLM-5.1, GLM-5, GLM-4.7, GLM-4.5 family | API key from [docs.z.ai](https://docs.z.ai/devpack/quick-start) |
-| **MiniMax** | MiniMax M3, M2.7, M2.7-highspeed, M2.5, M2.1 | API key from [platform.minimax.io](https://platform.minimax.io/user-center/basic-information/interface-key) |
-| **OpenAI-compatible** | Any endpoint with OpenAI API format | Custom base URL + key. Supports Completions and Responses API toggle. |
-| **Anthropic-compatible** | Any endpoint with Anthropic API format | Custom base URL + key |
+| Provider | Models | Setup |
+| ------------------------ | ---------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
+| **OpenRouter** | Claude, GPT, Gemini, DeepSeek, Qwen, and others | API key from [openrouter.ai](https://openrouter.ai) |
+| **Anthropic** | Claude Sonnet 5.5, Claude Opus 5.5, Claude Fable 5.1, Claude Haiku 5.5 | API key from [console.anthropic.com](https://console.anthropic.com) |
+| **OpenAI** | GPT-6.1 Sol, GPT-6 Astra, GPT-6 Luna | API key from [platform.openai.com](https://platform.openai.com) |
+| **Google AI** | Gemini 3.8 Flash, Gemini 4 Argon | API key from [aistudio.google.dev](https://aistudio.google.dev) |
+| **DeepSeek** | DeepSeek Flash, DeepSeek V4 Pro | API key from [platform.deepseek.com](https://platform.deepseek.com/api_keys) |
+| **Z.ai** | GLM-5.3, GLM-5.3-Flash, GLM-5.3-FlashX, GLM-5V-Turbo | API key from [docs.z.ai](https://docs.z.ai/devpack/quick-start) |
+| **MiniMax** | MiniMax-M3.1-Flash, MiniMax-M3 | API key from [platform.minimax.io](https://platform.minimax.io/user-center/basic-information/interface-key) |
+| **OpenAI-compatible** | Any endpoint with OpenAI API format | Custom base URL + key. Supports Completions and Responses API toggle. |
+| **Anthropic-compatible** | Any endpoint with Anthropic API format | Custom base URL + key |
No backend, no subscription — your key talks directly to the provider. Browser requests are subject to each provider's CORS policy, and model deployments vary in how reliably they stream tool calls. See [BYOK provider and model compatibility](./byok-provider-compatibility) for measured results and reproduction steps.
diff --git a/packages/docs/ru/programmable/ai-chat.md b/packages/docs/ru/programmable/ai-chat.md
index 440c1be13..a05c744f4 100644
--- a/packages/docs/ru/programmable/ai-chat.md
+++ b/packages/docs/ru/programmable/ai-chat.md
@@ -23,11 +23,12 @@ description: Встроенный помощник с более чем 90 ин
| Поставщик | Модели | Настройка |
|-----------|--------|-----------|
| **OpenRouter** | Claude, GPT, Gemini, DeepSeek, Qwen и другие | Ключ API с [openrouter.ai](https://openrouter.ai) |
-| **Anthropic** | Claude Sonnet 4.6, Claude Opus 4.6 | Ключ API с [console.anthropic.com](https://console.anthropic.com) |
-| **OpenAI** | GPT-5.3 Codex, GPT-4.1, o3, o4-mini | Ключ API с [platform.openai.com](https://platform.openai.com) |
-| **Google AI** | Gemini 3.1 Pro, Gemini 3 Flash | Ключ API с [aistudio.google.dev](https://aistudio.google.dev) |
-| **Z.ai** | GLM-5.1, GLM-5, GLM-4.7 и семейство GLM-4.5 | Ключ API из [документации Z.ai](https://docs.z.ai/devpack/quick-start) |
-| **MiniMax** | MiniMax M3, M2.7, M2.7-highspeed, M2.5, M2.1 | Ключ API с [platform.minimax.io](https://platform.minimax.io/user-center/basic-information/interface-key) |
+| **Anthropic** | Claude Sonnet 5.5, Claude Opus 5.5, Claude Fable 5.1, Claude Haiku 5.5 | Ключ API с [console.anthropic.com](https://console.anthropic.com) |
+| **OpenAI** | GPT-6.1 Sol, GPT-6 Astra, GPT-6 Luna | Ключ API с [platform.openai.com](https://platform.openai.com) |
+| **Google AI** | Gemini 3.8 Flash, Gemini 4 Argon | Ключ API с [aistudio.google.dev](https://aistudio.google.dev) |
+| **DeepSeek** | DeepSeek Flash, DeepSeek V4 Pro | Ключ API с [platform.deepseek.com](https://platform.deepseek.com/api_keys) |
+| **Z.ai** | GLM-5.3, GLM-5.3-Flash, GLM-5.3-FlashX, GLM-5V-Turbo | Ключ API из [документации Z.ai](https://docs.z.ai/devpack/quick-start) |
+| **MiniMax** | MiniMax-M3.1-Flash, MiniMax-M3 | Ключ API с [platform.minimax.io](https://platform.minimax.io/user-center/basic-information/interface-key) |
| **Совместимый с OpenAI** | Любая конечная точка в формате OpenAI API | Собственные базовый URL и ключ; можно выбрать Completions API или Responses API |
| **Совместимый с Anthropic** | Любая конечная точка в формате Anthropic API | Собственные базовый URL и ключ |
diff --git a/src/AGENTS.md b/src/AGENTS.md
index a6e1ea07f..21c43b1dd 100644
--- a/src/AGENTS.md
+++ b/src/AGENTS.md
@@ -23,7 +23,7 @@ Root Tauri/Vite app. Services and state live under `src/app/**`, views under `sr
- How a chat reply runs, ends, and reports undone edits to the model, and which file owns each step, is in `packages/docs/development/ai-chat.md`; keep it current when that flow changes.
- `src/app/ai/tools/index.ts` binds Core ToolDefs to the active editor's `FigmaAPI`. The chat and ACP prompt compose the Core authoring reference rather than copying it (`packages/core/AGENTS.md`, Tools).
-- ACP transport lives under `src/app/ai/acp/**`; provider definitions in `packages/core/src/constants.ts`; profiles in `src/app/ai/models/**`. Keep provider connections, reusable profiles, and role assignments separate, and resolve credentials lazily. ACP process changes require checking `desktop/capabilities/**`.
+- ACP transport lives under `src/app/ai/acp/**`; provider definitions in `packages/core/src/ai/providers.ts`, exported from `@open-pencil/core/constants`; profiles in `src/app/ai/models/**`. Keep provider connections, reusable profiles, and role assignments separate, and resolve credentials lazily. ACP process changes require checking `desktop/capabilities/**`.
- Browser-native WebMCP registration lives under `src/app/automation/webmcp/`, consumes per-tool exposure metadata, and is feature-detected through `document.modelContext`. App completion under `src/app/automation/execution/` loads fonts after commit.
- Collaboration lives under `src/app/collab/**` on Yjs and awareness over a `CollabRoomTransport`: Trystero for peer-to-peer rooms, the Cloud relay (`transport/cloud.ts`) for Cloud documents. Preserve crypto-safe room IDs and peer cleanup. Room channels are named in `COLLAB_ACTIONS` from `@open-pencil/cloud/contract`, because the relay reads the document ones to persist rooms and drop viewer writes (`tests/integration/collab/cloud-relay.test.ts`).
- Outside Cloud's own folders, app code reaches Cloud only through `@/app/cloud/integration` (and its `/storage` provider list) and components through `@/components/cloud/integration`; a `VITE_OPENPENCIL_CLOUD=off` build swaps both for their `off` stand-ins, which must keep the same names (`tests/app/cloud/integration/off.test.ts`), and must bundle no other Cloud module (`bun run check:cloud-off`).
diff --git a/src/app/ai/chat/provider-models.ts b/src/app/ai/chat/provider-models.ts
index 8358b01dc..eda61e46d 100644
--- a/src/app/ai/chat/provider-models.ts
+++ b/src/app/ai/chat/provider-models.ts
@@ -3,7 +3,7 @@ import * as v from 'valibot'
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'
+import { cachedRemoteJSON } from '@/app/cache/remote'
const CachedModelOptions = v.array(
v.object({
@@ -52,8 +52,6 @@ function curatedProviderModels(providerID: AIProviderID) {
const curatedOpenRouterModels = curatedProviderModels('openrouter')
-let modelsPromise: Promise<ModelOption[]> | null = null
-
function isToolCapableOpenRouterModel(model: OpenRouterModel) {
return Array.isArray(model.supported_parameters) && model.supported_parameters.includes('tools')
}
@@ -104,38 +102,23 @@ async function fetchOpenRouterModels(fetcher: typeof fetch): Promise<ModelOption
})
}
-async function listOpenRouterModels(fetcher: typeof fetch = fetch): Promise<ModelOption[]> {
- modelsPromise ??= (async () => {
- 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).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
- }
- })()
-
- return modelsPromise
-}
+const openRouterModels = cachedRemoteJSON<ModelOption[]>({
+ key: OPENROUTER_MODELS_CACHE_KEY,
+ schema: CachedModelOptions,
+ maxAgeMs: OPENROUTER_MODELS_CACHE_TTL_MS,
+ load: async (fetcher) => {
+ const models = await fetchOpenRouterModels(fetcher)
+ return models.length ? models : null
+ }
+})
export async function listProviderModels(
providerID: AIProviderID,
- fetcher: typeof fetch = fetch
+ fetcher?: typeof fetch
): Promise<ModelOption[]> {
- if (providerID === 'openrouter') return listOpenRouterModels(fetcher)
+ if (providerID === 'openrouter') {
+ return (await openRouterModels.get(fetcher)) ?? curatedOpenRouterModels
+ }
return curatedProviderModels(providerID)
}
@@ -148,5 +131,5 @@ export async function resolveProviderModel(
}
export function resetOpenRouterModelsForTests(): void {
- modelsPromise = null
+ openRouterModels.reset()
}
diff --git a/src/app/ai/models/catalog/index.ts b/src/app/ai/models/catalog/index.ts
index c15c6300e..ec70139ff 100644
--- a/src/app/ai/models/catalog/index.ts
+++ b/src/app/ai/models/catalog/index.ts
@@ -4,7 +4,7 @@ import * as v from 'valibot'
import { AI_PROVIDERS } from '@open-pencil/core/constants'
import type { AIProviderID, ModelOption } from '@open-pencil/core/constants'
-import { readCacheJSON, writeCacheJSON } from '@/app/cache'
+import { cachedRemoteJSON } from '@/app/cache/remote'
const MODELS_DEV_URL = 'https://models.dev/api.json'
const MODELS_DEV_CACHE_KEY = 'models-dev/catalog'
@@ -52,8 +52,6 @@ const ModelsDevCatalogSchema = v.record(
})
) satisfies v.GenericSchema<unknown, ModelsDevCatalog>
-let catalogPromise: Promise<ModelsDevCatalog | null> | null = null
-
function normalizedStatus(status: unknown): ModelOption['status'] {
if (status === 'beta' || status === 'deprecated') return status
return 'active'
@@ -77,49 +75,17 @@ function normalizeModel(id: string, model: ModelsDevModel): ModelOption {
return normalized
}
-async function loadCatalog(
- fetcher: typeof fetch,
- options: { useCache: boolean }
-): Promise<ModelsDevCatalog | null> {
- if (options.useCache) {
- const cached = await readCacheJSON(
- MODELS_DEV_CACHE_KEY,
- ModelsDevCatalogSchema,
- MODELS_DEV_CACHE_TTL_MS
- )
- if (cached) return cached
- }
- try {
+const modelsDevCatalog = cachedRemoteJSON({
+ key: MODELS_DEV_CACHE_KEY,
+ schema: ModelsDevCatalogSchema,
+ maxAgeMs: MODELS_DEV_CACHE_TTL_MS,
+ load: async (fetcher) => {
const response = await fetcher(MODELS_DEV_URL)
if (!response.ok) throw new Error(`models.dev catalog request failed: ${response.status}`)
// Validated like the cached copy, so a bad entry falls back instead of crashing the list.
- const catalog = v.parse(
- v.pipe(v.string(), v.parseJson(), ModelsDevCatalogSchema),
- await response.text()
- )
- if (options.useCache) await writeCacheJSON(MODELS_DEV_CACHE_KEY, catalog)
- return catalog
- } catch {
- return null
+ return v.parse(v.pipe(v.string(), v.parseJson(), ModelsDevCatalogSchema), await response.text())
}
-}
-
-async function resolvedCatalog(fetcher?: typeof fetch): Promise<ModelsDevCatalog | null> {
- const nativeFetch = typeof globalThis.fetch === 'function' ? globalThis.fetch : undefined
- const resolvedFetcher = fetcher ?? nativeFetch
- if (!resolvedFetcher) return null
- const useCache = resolvedFetcher === nativeFetch
- if (!useCache) return loadCatalog(resolvedFetcher, { useCache: false })
- const pending = (catalogPromise ??= loadCatalog(resolvedFetcher, { useCache: true }))
- try {
- const catalog = await pending
- if (!catalog && catalogPromise === pending) catalogPromise = null
- return catalog
- } catch {
- if (catalogPromise === pending) catalogPromise = null
- return null
- }
-}
+})
function modelIDCandidates(providerKey: string, modelID: string): string[] {
const unprefixed = modelID.startsWith(`${providerKey}/`)
@@ -166,7 +132,7 @@ export async function listCatalogModels(
const curated = curatedProviderModels(providerID)
const providerKeys = PROVIDER_KEYS[providerID]
if (!providerKeys?.length) return curated
- const catalog = await resolvedCatalog(fetcher)
+ const catalog = await modelsDevCatalog.get(fetcher)
if (!catalog) return curated
const models = providerKeys.flatMap((providerKey) =>
@@ -184,7 +150,7 @@ export async function resolveModelsDevModel(
): Promise<ModelOption | null> {
const providerKeys = PROVIDER_KEYS[providerID]
if (!providerKeys?.length || !modelID) return null
- const catalog = await resolvedCatalog(fetcher)
+ const catalog = await modelsDevCatalog.get(fetcher)
if (!catalog) return null
for (const providerKey of providerKeys) {
@@ -198,5 +164,5 @@ export async function resolveModelsDevModel(
}
export function resetModelsDevCatalogForTests(): void {
- catalogPromise = null
+ modelsDevCatalog.reset()
}
diff --git a/src/app/cache/remote.ts b/src/app/cache/remote.ts
new file mode 100644
index 000000000..e10468e3b
--- /dev/null
+++ b/src/app/cache/remote.ts
@@ -0,0 +1,56 @@
+import type * as v from 'valibot'
+
+import { readCacheJSON, writeCacheJSON } from './index'
+
+export type CachedRemoteJSONOptions<TValue> = {
+ key: string
+ schema: v.GenericSchema<unknown, TValue>
+ maxAgeMs: number
+ /** Fetches a fresh value; null means the response had nothing worth keeping. */
+ load: (fetcher: typeof fetch) => Promise<TValue | null>
+}
+
+export type CachedRemoteJSON<TValue> = {
+ /**
+ * The cached value, or a fresh one shared by concurrent callers. A passed fetcher loads
+ * directly, without the cache or the shared request.
+ */
+ get(fetcher?: typeof fetch): Promise<TValue | null>
+ reset(): void
+}
+
+/**
+ * A JSON value fetched over the network and cached for `maxAgeMs`. Storage failures only skip
+ * the cache, and a failed or empty load is not kept, so the next call retries.
+ */
+export function cachedRemoteJSON<TValue>(
+ options: CachedRemoteJSONOptions<TValue>
+): CachedRemoteJSON<TValue> {
+ let shared: Promise<TValue | null> | null = null
+
+ async function loadAndCache(): Promise<TValue | null> {
+ const cached = await readCacheJSON(options.key, options.schema, options.maxAgeMs).catch(
+ () => null
+ )
+ if (cached != null) return cached
+ const value = await options.load(fetch)
+ if (value == null) return null
+ await writeCacheJSON(options.key, value).catch((error: unknown) => {
+ console.warn(`Cache write skipped for "${options.key}":`, error)
+ })
+ return value
+ }
+
+ return {
+ async get(fetcher) {
+ if (fetcher) return options.load(fetcher).catch(() => null)
+ const pending = (shared ??= loadAndCache())
+ const value = await pending.catch(() => null)
+ if (value == null && shared === pending) shared = null
+ return value
+ },
+ reset() {
+ shared = null
+ }
+ }
+}
diff --git a/tests/app/ai/chat/provider-models.test.ts b/tests/app/ai/chat/provider-models.test.ts
index b6aceae5b..7e7bf1384 100644
--- a/tests/app/ai/chat/provider-models.test.ts
+++ b/tests/app/ai/chat/provider-models.test.ts
@@ -5,7 +5,6 @@ import {
resetOpenRouterModelsForTests,
resolveProviderModel
} from '@/app/ai/chat/provider-models'
-import * as cache from '@/app/cache'
import { fetchStub } from '#tests/helpers/fetch'
@@ -108,24 +107,4 @@ describe('resolveProviderModel', () => {
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/models/settings/onboarding/plan.test.ts b/tests/app/ai/models/settings/onboarding/plan.test.ts
index 029af8595..9987bab95 100644
--- a/tests/app/ai/models/settings/onboarding/plan.test.ts
+++ b/tests/app/ai/models/settings/onboarding/plan.test.ts
@@ -181,7 +181,7 @@ describe('planOnboarding for review and fast work', () => {
})
test('follows the design model when its provider has no separate fast model', () => {
- expect(planOnboarding(answers({ access: ['anthropic'] }), desktop).fast).toBe('design')
+ expect(planOnboarding(answers({ access: ['google'] }), desktop).fast).toBe('design')
})
test('uses the API vision model for review and fast work behind an agent', () => {
diff --git a/tests/app/cache/remote.test.ts b/tests/app/cache/remote.test.ts
new file mode 100644
index 000000000..d43c02819
--- /dev/null
+++ b/tests/app/cache/remote.test.ts
@@ -0,0 +1,79 @@
+import { afterEach, describe, expect, mock, spyOn, test } from 'bun:test'
+
+import * as v from 'valibot'
+
+import * as cache from '@/app/cache'
+import { cachedRemoteJSON } from '@/app/cache/remote'
+
+import { fetchStub } from '#tests/helpers/fetch'
+
+const Names = v.array(v.string())
+
+function remoteNames(load: (fetcher: typeof fetch) => Promise<string[] | null>) {
+ return cachedRemoteJSON({ key: 'tests/names', schema: Names, maxAgeMs: 60_000, load })
+}
+
+describe('cachedRemoteJSON', () => {
+ const spies: { mockRestore(): void }[] = []
+ afterEach(() => {
+ for (const spy of spies.splice(0)) spy.mockRestore()
+ })
+
+ test('shares one load between callers', async () => {
+ const load = mock(async () => ['a'])
+ const names = remoteNames(load)
+
+ expect(await Promise.all([names.get(), names.get()])).toEqual([['a'], ['a']])
+ expect(await names.get()).toEqual(['a'])
+ expect(load).toHaveBeenCalledTimes(1)
+ })
+
+ test('returns a cached value without loading', async () => {
+ spies.push(spyOn(cache, 'readCacheJSON').mockResolvedValueOnce(['cached']))
+ const load = mock(async () => ['fresh'])
+
+ expect(await remoteNames(load).get()).toEqual(['cached'])
+ expect(load).not.toHaveBeenCalled()
+ })
+
+ test('retries after a failed or empty load', async () => {
+ const load = mock<() => Promise<string[] | null>>()
+ .mockRejectedValueOnce(new Error('offline'))
+ .mockResolvedValueOnce(null)
+ .mockResolvedValueOnce(['a'])
+ const names = remoteNames(load)
+
+ expect(await names.get()).toBeNull()
+ expect(await names.get()).toBeNull()
+ expect(await names.get()).toEqual(['a'])
+ expect(load).toHaveBeenCalledTimes(3)
+ })
+
+ test('loads when the cache cannot be read and keeps the value when it cannot be written', async () => {
+ spies.push(
+ spyOn(cache, 'readCacheJSON').mockRejectedValueOnce(new Error('storage denied')),
+ spyOn(cache, 'writeCacheJSON').mockRejectedValueOnce(new Error('quota exceeded'))
+ )
+ const warn = spyOn(console, 'warn').mockImplementation(() => undefined)
+ spies.push(warn)
+ const load = mock(async () => ['a'])
+ const names = remoteNames(load)
+
+ expect(await names.get()).toEqual(['a'])
+ expect(await names.get()).toEqual(['a'])
+ expect(load).toHaveBeenCalledTimes(1)
+ expect(warn).toHaveBeenCalledTimes(1)
+ })
+
+ test('loads through a passed fetcher without the cache or the shared request', async () => {
+ const read = spyOn(cache, 'readCacheJSON')
+ spies.push(read)
+ const fetcher = fetchStub(async () => Response.json([]))
+ const load = mock(async (used: typeof fetch) => (used === fetcher ? ['stub'] : ['shared']))
+ const names = remoteNames(load)
+
+ expect(await names.get(fetcher)).toEqual(['stub'])
+ expect(await names.get()).toEqual(['shared'])
+ expect(read).toHaveBeenCalledTimes(1)
+ })
+})
diff --git a/tests/engine/app/ai/model/providers.test.ts b/tests/engine/app/ai/model/providers.test.ts
index 8f0788369..9f9576737 100644
--- a/tests/engine/app/ai/model/providers.test.ts
+++ b/tests/engine/app/ai/model/providers.test.ts
@@ -3,10 +3,12 @@ import { describe, expect, test } from 'bun:test'
import type { LanguageModel } from 'ai'
import { AI_PROVIDERS } from '@open-pencil/core/constants'
+import type { AIProviderID } from '@open-pencil/core/constants'
import { resolveLanguageModelID } from '@/app/ai/chat/model'
import { resolveProviderModel } from '@/app/ai/chat/provider-models'
import { reasoningCallSettings } from '@/app/ai/chat/reasoning'
+import type { ThinkingLevel } from '@/app/ai/models/types'
import { createAnthropicCompatibleAdapter } from '@/app/ai/providers/compatible'
import { modelProviderAdapter } from '@/app/ai/providers/registry'
import type { ModelConfig } from '@/app/ai/providers/types'
@@ -17,6 +19,40 @@ function languageModelInstance(model: LanguageModel): Exclude<LanguageModel, str
return model
}
+/** The JSON body a curated model sends at a thinking level, with its reasoning floor applied. */
+async function thinkingRequestBody(
+ providerID: AIProviderID,
+ modelID: string,
+ level: ThinkingLevel
+): Promise<unknown> {
+ let requestBody = ''
+ const fetchSpy: FetchFunction = async (_input, init) => {
+ requestBody = String(init?.body)
+ throw new Error('stop')
+ }
+ const model = languageModelInstance(
+ modelProviderAdapter(providerID).create(
+ {
+ providerID,
+ apiKey: 'test-key',
+ modelID,
+ customModelID: '',
+ customBaseURL: '',
+ customAPIType: 'completions'
+ },
+ { fetch: fetchSpy }
+ )
+ )
+ const known = await resolveProviderModel(providerID, modelID)
+ await Promise.resolve(
+ model.doGenerate({
+ ...reasoningCallSettings(providerID, level, known?.minReasoningEffort),
+ prompt: [{ role: 'user', content: [{ type: 'text', text: 'hi' }] }]
+ })
+ ).catch(() => undefined)
+ return JSON.parse(requestBody)
+}
+
describe('resolveLanguageModelID', () => {
test('uses the selected OpenRouter model when no custom model is configured', () => {
expect(
@@ -83,41 +119,34 @@ describe('model provider registry', () => {
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({
+ expect(await thinkingRequestBody('minimax', 'MiniMax-M3.1-Flash', level)).toMatchObject({
model: 'MiniMax-M3.1-Flash',
reasoning_effort: level === 'off' || level === 'minimal' ? 'low' : level
})
}
)
+ describe.each(['off', 'minimal'] as const)('at %s thinking', (level) => {
+ test.each([
+ ['zai', 'glm-5.3', { thinking: { type: 'enabled' } }],
+ ['zai', 'glm-5.3-flash', { thinking: { type: 'enabled' } }],
+ [
+ 'google',
+ 'gemini-4-argon',
+ { generationConfig: { thinkingConfig: { thinkingLevel: 'low' } } }
+ ],
+ [
+ 'google',
+ 'gemini-3.1-pro-preview',
+ { generationConfig: { thinkingConfig: { thinkingLevel: 'low' } } }
+ ],
+ ['openai', 'gpt-6.1-sol', { reasoning: { effort: 'low' } }],
+ ['openai', 'gpt-6-astra', { reasoning: { effort: 'low' } }]
+ ] as const)('%s %s sends the lowest thinking it accepts', async (providerID, modelID, sent) => {
+ expect(await thinkingRequestBody(providerID, modelID, level)).toMatchObject(sent)
+ })
+ })
+
test('registers every direct provider without handling agent runtimes as models', () => {
for (const provider of AI_PROVIDERS.filter((entry) => entry.id !== 'harness:pi')) {
expect(modelProviderAdapter(provider.id).create).toBeFunction()