Model Switcher
kai-model-switcher
A compact dropdown trigger that lets users swap the active AI model mid-conversation — set a list of models, handle one event, done.
- Shadow DOM
- 1 event
- 2 props
- Property API or declarative children
- Only renders with 2+ models
Preview
Section titled “Preview”Set models in JavaScript (arrays can’t be HTML attributes) and reflect the selection back on kai-model-change:
<kai-model-switcher id="ms"></kai-model-switcher>
<script type="module"> import '@kitn.ai/ui/elements'; const ms = document.getElementById('ms');
ms.models = [ { id: 'claude-opus', name: 'Claude Opus', provider: 'Anthropic' }, { id: 'claude-sonnet', name: 'Claude Sonnet', provider: 'Anthropic' }, ]; ms.currentModel = 'claude-opus';
ms.addEventListener('kai-model-change', (e) => { ms.currentModel = e.detail.modelId; });</script>models— an array, so assign it as a property. Each item:{ id: string; name: string; provider?: string }.currentModel— the selected model’sid. Omit it to default to the first item in the list.- Reflect the selection — set
el.currentModel = e.detail.modelIdafter eachkai-model-changeso the trigger label updates.
Declarative child API — compose <kai-model> children instead of setting the models property:
<kai-model-switcher> <kai-model id="gpt-4o" provider="OpenAI">GPT-4o</kai-model> <kai-model id="claude-sonnet" provider="Anthropic">Claude Sonnet</kai-model></kai-model-switcher>Each <kai-model> carries id (required), provider (optional), and a text label. When you mix both approaches, property items render first.
Examples
Section titled “Examples”Default
Section titled “Default”Three Claude models loaded via the models property.
Preselected Model
Section titled “Preselected Model”current-model="claude-sonnet" starts with a specific model active rather than the first item.
Multiple Providers
Section titled “Multiple Providers”Models from different providers — the dropdown groups them by the provider field.
| Property | Type | Default | Notes |
|---|---|---|---|
| models | | [] | The selectable models. Set as a JS property (array). |
| currentModel | string | — | The currently-selected model id. Defaults to the first model. |
Events
Section titled “Events”| Event | Detail | Notes |
|---|---|---|
| kai-model-change | | A model was selected. |
Composed from
Section titled “Composed from”This element wraps these SolidJS components — reach for them directly when you need finer control than the props expose.