Skip to content

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

refactor(chat): polish model profile switching

Danila Poyarkov7a3a8bf53f4a
diff --git a/packages/vue/src/i18n/locales/de/dialogs.json b/packages/vue/src/i18n/locales/de/dialogs.json
index eca0e86ae..084f974d1 100644
--- a/packages/vue/src/i18n/locales/de/dialogs.json
+++ b/packages/vue/src/i18n/locales/de/dialogs.json
@@ -90,6 +90,7 @@
"modelCapabilityVision": "Bildeingabe",
"modelCapabilityToolsShort": "Werkzeuge",
"modelCapabilityVisionShort": "Vision",
+ "selectDesignModel": "Designmodell auswählen",
"modelNeedsCredential": "Schlüssel fehlt",
"modelAgentConnection": "Agent",
"saveModel": "Modell speichern",
diff --git a/packages/vue/src/i18n/locales/es/dialogs.json b/packages/vue/src/i18n/locales/es/dialogs.json
index da6abff8a..bdd552560 100644
--- a/packages/vue/src/i18n/locales/es/dialogs.json
+++ b/packages/vue/src/i18n/locales/es/dialogs.json
@@ -90,6 +90,7 @@
"modelCapabilityVision": "Entrada de imágenes",
"modelCapabilityToolsShort": "Herramientas",
"modelCapabilityVisionShort": "Visión",
+ "selectDesignModel": "Seleccionar modelo de diseño",
"modelNeedsCredential": "Falta la clave",
"modelAgentConnection": "Agente",
"saveModel": "Guardar modelo",
diff --git a/packages/vue/src/i18n/locales/fr/dialogs.json b/packages/vue/src/i18n/locales/fr/dialogs.json
index 9beb59b30..1e2ff138a 100644
--- a/packages/vue/src/i18n/locales/fr/dialogs.json
+++ b/packages/vue/src/i18n/locales/fr/dialogs.json
@@ -90,6 +90,7 @@
"modelCapabilityVision": "Entrée d’images",
"modelCapabilityToolsShort": "Outils",
"modelCapabilityVisionShort": "Vision",
+ "selectDesignModel": "Sélectionner le modèle de conception",
"modelNeedsCredential": "Clé requise",
"modelAgentConnection": "Agent",
"saveModel": "Enregistrer le modèle",
diff --git a/packages/vue/src/i18n/locales/it/dialogs.json b/packages/vue/src/i18n/locales/it/dialogs.json
index 8e2df317e..045b65c90 100644
--- a/packages/vue/src/i18n/locales/it/dialogs.json
+++ b/packages/vue/src/i18n/locales/it/dialogs.json
@@ -90,6 +90,7 @@
"modelCapabilityVision": "Input immagini",
"modelCapabilityToolsShort": "Strumenti",
"modelCapabilityVisionShort": "Visione",
+ "selectDesignModel": "Seleziona modello di progettazione",
"modelNeedsCredential": "Chiave necessaria",
"modelAgentConnection": "Agente",
"saveModel": "Salva modello",
diff --git a/packages/vue/src/i18n/locales/ja/dialogs.json b/packages/vue/src/i18n/locales/ja/dialogs.json
index 3550f4cbb..139e2d35d 100644
--- a/packages/vue/src/i18n/locales/ja/dialogs.json
+++ b/packages/vue/src/i18n/locales/ja/dialogs.json
@@ -90,6 +90,7 @@
"modelCapabilityVision": "画像入力",
"modelCapabilityToolsShort": "ツール",
"modelCapabilityVisionShort": "ビジョン",
+ "selectDesignModel": "デザインモデルを選択",
"modelNeedsCredential": "キーが必要",
"modelAgentConnection": "エージェント",
"saveModel": "モデルを保存",
diff --git a/packages/vue/src/i18n/locales/pl/dialogs.json b/packages/vue/src/i18n/locales/pl/dialogs.json
index 5957310cc..425f74a0d 100644
--- a/packages/vue/src/i18n/locales/pl/dialogs.json
+++ b/packages/vue/src/i18n/locales/pl/dialogs.json
@@ -90,6 +90,7 @@
"modelCapabilityVision": "Obrazy wejściowe",
"modelCapabilityToolsShort": "Narzędzia",
"modelCapabilityVisionShort": "Wizja",
+ "selectDesignModel": "Wybierz model projektowy",
"modelNeedsCredential": "Brak klucza",
"modelAgentConnection": "Agent",
"saveModel": "Zapisz model",
diff --git a/packages/vue/src/i18n/locales/ru/dialogs.json b/packages/vue/src/i18n/locales/ru/dialogs.json
index 39f2102dd..658863c6e 100644
--- a/packages/vue/src/i18n/locales/ru/dialogs.json
+++ b/packages/vue/src/i18n/locales/ru/dialogs.json
@@ -90,6 +90,7 @@
"modelCapabilityVision": "Ввод изображений",
"modelCapabilityToolsShort": "Инструменты",
"modelCapabilityVisionShort": "Зрение",
+ "selectDesignModel": "Выбрать модель для дизайна",
"modelNeedsCredential": "Нужен ключ",
"modelAgentConnection": "Агент",
"saveModel": "Сохранить модель",
diff --git a/packages/vue/src/i18n/locales/zh-cn/dialogs.json b/packages/vue/src/i18n/locales/zh-cn/dialogs.json
index b3ab5b653..b7366c9a5 100644
--- a/packages/vue/src/i18n/locales/zh-cn/dialogs.json
+++ b/packages/vue/src/i18n/locales/zh-cn/dialogs.json
@@ -90,6 +90,7 @@
"modelCapabilityVision": "图像输入",
"modelCapabilityToolsShort": "工具",
"modelCapabilityVisionShort": "视觉",
+ "selectDesignModel": "选择设计模型",
"modelNeedsCredential": "需要密钥",
"modelAgentConnection": "代理",
"saveModel": "保存模型",
diff --git a/packages/vue/src/i18n/messages/dialogs.ts b/packages/vue/src/i18n/messages/dialogs.ts
index 58ba6b6a7..d136b33cc 100644
--- a/packages/vue/src/i18n/messages/dialogs.ts
+++ b/packages/vue/src/i18n/messages/dialogs.ts
@@ -139,6 +139,7 @@ export const dialogMessageDefaults = {
modelCapabilityVision: 'Image input',
modelCapabilityToolsShort: 'Tools',
modelCapabilityVisionShort: 'Vision',
+ selectDesignModel: 'Select design model',
modelNeedsCredential: 'Needs key',
modelAgentConnection: 'Agent',
saveModel: 'Save model',
diff --git a/src/app/ai/models/store.ts b/src/app/ai/models/store.ts
index 532f892c9..0ae9ebfa3 100644
--- a/src/app/ai/models/store.ts
+++ b/src/app/ai/models/store.ts
@@ -203,6 +203,14 @@ export function modelConnection(connectionId: string): AIModelConnection | null
)
}
+export function isDesignModelProfile(profile: AIModelProfile): boolean {
+ return profile.capabilities.includes('tools')
+}
+
+export function designModelProfiles(): AIModelProfile[] {
+ return aiModelSettings.value.models.filter(isDesignModelProfile)
+}
+
export function isACPModelProfile(profile: AIModelProfile | null): boolean {
return Boolean(profile && modelConnection(profile.connectionId)?.providerID.startsWith('acp:'))
}
@@ -213,7 +221,7 @@ export function resolveAIModelRole(role: AIModelRole): ResolvedAIModelRole | nul
const profileId = assignment === 'design' ? aiModelSettings.value.assignments.design : assignment
const profile = modelProfile(profileId)
if (!profile) return null
- if (role === 'design' && !profile.capabilities.includes('tools')) return null
+ if (role === 'design' && !isDesignModelProfile(profile)) return null
if (role === 'vision' && !profile.capabilities.includes('vision')) return null
const connection = modelConnection(profile.connectionId)
return connection ? { requestedRole: role, profile, connection } : null
@@ -344,9 +352,7 @@ export function removeModelProfile(profileId: string): void {
aiModelSettings.value.models = aiModelSettings.value.models.filter(
(profile) => profile.id !== profileId
)
- const fallback =
- aiModelSettings.value.models.find((profile) => profile.capabilities.includes('tools')) ??
- aiModelSettings.value.models[0]
+ const fallback = designModelProfiles()[0] ?? aiModelSettings.value.models[0]
if (aiModelSettings.value.assignments.design === profileId) {
aiModelSettings.value.assignments.design = fallback.id
if (
@@ -377,7 +383,7 @@ export function setModelRoleAssignment(role: AIModelRole, assignment: AIModelRol
if (role === 'design') {
if (assignment === null || assignment === 'design') return
const profile = modelProfile(assignment)
- if (!profile?.capabilities.includes('tools')) return
+ if (!profile || !isDesignModelProfile(profile)) return
aiModelSettings.value.assignments.design = assignment
return
}
diff --git a/src/components/chat/ChatInput.vue b/src/components/chat/ChatInput.vue
index 91042b127..7e3d16efb 100644
--- a/src/components/chat/ChatInput.vue
+++ b/src/components/chat/ChatInput.vue
@@ -8,7 +8,7 @@ import AppInput from '@/components/ui/AppInput.vue'
import Tip from '@/components/ui/Tip.vue'
import { useButtonUI } from '@/components/ui/button'
import { useAIChat } from '@/app/ai/chat/use'
-import { aiModelSettings, designModelProfile } from '@/app/ai/models'
+import { designModelProfile, designModelProfiles } from '@/app/ai/models'
import { openSettingsDialog } from '@/app/settings/dialog'
import { useI18n } from '@open-pencil/vue'
@@ -61,9 +61,7 @@ const selectedModelName = computed(() => {
})
// Switching between saved profiles only makes sense once more than one can drive the design agent.
-const switchableProfiles = computed(() =>
- aiModelSettings.value.models.filter((profile) => profile.capabilities.includes('tools'))
-)
+const switchableProfiles = computed(designModelProfiles)
const canSwitchProfile = computed(() => switchableProfiles.value.length > 1)
const selectedProfileName = computed(
() => designModelProfile.value?.name ?? selectedModelName.value
@@ -89,8 +87,10 @@ function handleSubmit(e: Event) {
{{ acpAgentName }}
</div>
</template>
- <ChatProfileSelect v-else-if="canSwitchProfile">
- <template #value>{{ selectedProfileName }}</template>
+ <ChatProfileSelect v-else-if="canSwitchProfile && (isCustomProvider || usesCustomModel)">
+ <template #value>
+ <span class="min-w-0 truncate">{{ selectedProfileName }}</span>
+ </template>
</ChatProfileSelect>
<template v-else-if="isCustomProvider || usesCustomModel">
<div
diff --git a/src/components/chat/ChatProfileSelect.vue b/src/components/chat/ChatProfileSelect.vue
index 859668d8c..cf189be50 100644
--- a/src/components/chat/ChatProfileSelect.vue
+++ b/src/components/chat/ChatProfileSelect.vue
@@ -12,7 +12,7 @@ import {
import { useI18n } from '@open-pencil/vue'
-import { aiModelSettings, setModelRoleAssignment } from '@/app/ai/models'
+import { aiModelSettings, designModelProfiles, setModelRoleAssignment } from '@/app/ai/models'
import type { AIModelProfileId } from '@/app/ai/models'
import AppBadge from '@/components/ui/AppBadge.vue'
import { useSelectUI } from '@/components/ui/select'
@@ -20,9 +20,7 @@ import { useSelectUI } from '@/components/ui/select'
const { dialogs } = useI18n()
// Only profiles that can drive the design agent — setModelRoleAssignment rejects the rest.
-const profiles = computed(() =>
- aiModelSettings.value.models.filter((profile) => profile.capabilities.includes('tools'))
-)
+const profiles = computed(designModelProfiles)
const selectedProfileId = computed({
get: () => aiModelSettings.value.assignments.design,
@@ -30,9 +28,10 @@ const selectedProfileId = computed({
})
const selectCls = useSelectUI({
- trigger: 'gap-1 rounded border-none bg-transparent px-1.5 py-0.5 text-[10px] text-muted',
+ trigger:
+ 'min-w-0 max-w-full gap-1 rounded border-none bg-transparent px-1.5 py-0.5 text-[10px] text-muted',
content: 'max-h-60 overflow-y-auto',
- item: 'gap-2 rounded px-2 py-1.5 text-[11px]'
+ item: 'min-w-0 gap-2 rounded px-2 py-1.5 text-[11px]'
})
</script>
@@ -40,7 +39,7 @@ const selectCls = useSelectUI({
<SelectRoot v-model="selectedProfileId">
<SelectTrigger
data-test-id="chat-profile-selector"
- :aria-label="dialogs.models"
+ :aria-label="dialogs.selectDesignModel"
:class="selectCls.trigger"
>
<icon-lucide-bot class="size-3" />
@@ -56,7 +55,7 @@ const selectCls = useSelectUI({
:value="profile.id"
:class="selectCls.item"
>
- <SelectItemText class="flex-1">{{ profile.name }}</SelectItemText>
+ <SelectItemText class="min-w-0 flex-1 truncate">{{ profile.name }}</SelectItemText>
<AppBadge v-if="profile.capabilities.includes('vision')">
{{ dialogs.modelCapabilityVisionShort }}
</AppBadge>
diff --git a/tests/engine/app/ai/model-roles.test.ts b/tests/engine/app/ai/model-roles.test.ts
index 677bd87ba..e0d57498c 100644
--- a/tests/engine/app/ai/model-roles.test.ts
+++ b/tests/engine/app/ai/model-roles.test.ts
@@ -4,6 +4,7 @@ import {
aiModelSettings,
createAIModelRuntime,
createModelProfileDraft,
+ designModelProfiles,
modelSettingsSnapshot,
removeModelProfile,
replaceAIModelSettings,
@@ -101,10 +102,7 @@ describe('AI model profiles and role assignments', () => {
})
test('switches the design agent between saved profiles', () => {
- // Backs the chat model switcher: it lists tools-capable profiles and reassigns the design role.
- const switchable = aiModelSettings.value.models.filter((profile) =>
- profile.capabilities.includes('tools')
- )
+ const switchable = designModelProfiles()
expect(switchable.map((profile) => profile.id)).toEqual(['model-design', 'model-fast'])
setModelRoleAssignment('design', 'model-fast')