Repository Public MIT
1# GlassModelPicker23| | |4|---|---|5| Identifier | `glass-model-picker` |6| Module | `SPGlassAI` |7| Kind | `native-wrapper` — the system draws the `Menu` and its rows; the optional list style is drawn by GlassKit on opaque surfaces |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/AI/GlassModelPickerExample.swift` |1011UI only: the list of models and their states are supplied by the host. The picker downloads nothing and contacts no provider.1213## Minimal usage1415```swift16@State private var modelID: String? = "small"1718GlassModelPicker(models: models, selection: $modelID)19```2021## Variants2223| Availability | Row |24|---|---|25| `.local` | "On device · Text, Vision" |26| `.remote` | "Remote · Text, Tools" |27| `.unavailable(reason:)` | Disabled, "Unavailable · Not downloaded" |2829Models are grouped in sections by `provider`. The menu's label is the selected model's name with a symbol for where it runs, or the title when nothing is selected.3031| Style | Use |32|---|---|33| `.menu` (default) | A compact chip that opens the system menu. For a toolbar or the accessory slot of a prompt bar. |34| `.list` | The models as rows, grouped by provider under a small heading: name, a marker saying where the model runs (symbol and word), one chip per capability, a checkmark on the selected row. Unavailable models are dimmed and show their reason. For a settings screen or a sheet. |3536## Parameters3738| Parameter | Type | Default | Meaning |39|---|---|---|---|40| `title` | `LocalizedStringKey?` | "Model" | Accessibility label, and visible title when nothing is selected. |41| `models` | `[GlassModelInfo]` | — | `id`, `name`, `provider`, `capabilities`, `availability`. Any order. |42| `selection` | `Binding<String?>` | — | Identifier of the selected model. |43| `style` | `GlassModelPickerStyle` | `.menu` | `.menu` or `.list`. |4445`GlassModelCapabilities` is an option set: `.text`, `.vision`, `.tools`, `.reasoning`, `.audio`, `.code`. Each has a localised name and a symbol (`descriptors`) for hosts that draw their own summary.4647## States4849- **Selected**: the row carries the system checkmark (each row is a `Toggle` inside the menu).50- **Unavailable**: the row is disabled and gives the reason in words.51- **No selection**: the label shows the title.52- **Empty list**: the menu is disabled.5354Sorting and grouping are `GlassModelCatalog.grouped(_:)`: providers alphabetically; inside a provider, selectable models first, then by name with numeric-aware comparison; a repeated identifier keeps its first occurrence.5556## Advanced example5758```swift59struct ModelToolbarItem: ToolbarContent {60 let registry: ModelRegistry // host type61 @Binding var selection: String?6263 var body: some ToolbarContent {64 ToolbarItem(placement: .principal) {65 GlassModelPicker("Model", models: registry.models.map { model in66 GlassModelInfo(67 id: model.id,68 name: model.displayName,69 provider: model.vendor,70 capabilities: model.supportsImages ? [.text, .vision] : [.text],71 availability: model.isDownloaded ? .local : .unavailable(reason: "Not downloaded")72 )73 }, selection: $selection)74 }75 }76}77```7879## Accessibility8081- The menu is labelled with the title; its value is the selected model's name, where it runs and its capabilities.82- Capabilities and availability are written in words in every row; symbols are never the only carrier.83- Unavailable rows are disabled by the system and state the reason.84- Everything else (keyboard navigation, VoiceOver, Dynamic Type) is the system menu's behaviour.8586## Limits8788- How a second line of text is displayed in a menu row is decided by the platform; the text is always available to assistive technologies.89- The picker does not validate that `selection` exists in `models`; an unknown identifier shows the title.90- No search field: for long catalogues present a searchable list in a sheet instead.91- The rendering of the menu was not inspected in a running application during verification; grouping, sorting and wording are unit-tested.92