| 1 | package tui |
| 2 | |
| 3 | import ( |
| 4 | "github.com/charmbracelet/bubbles/filepicker" |
| 5 | "github.com/charmbracelet/bubbles/textinput" |
| 6 | "sourcecraft.dev/bigbes/claudio/cache" |
| 7 | "sourcecraft.dev/bigbes/claudio/config" |
| 8 | "sourcecraft.dev/bigbes/claudio/provider" |
| 9 | ) |
| 10 | |
| 11 | const logo = ` |
| 12 | _ _ _ |
| 13 | ___| | __ _ _ _ __| (_) ___ |
| 14 | / __| |/ _` + "`" + ` | | | |/ _` + "`" + ` | |/ _ \ |
| 15 | | (__| | (_| | |_| | (_| | | (_) | |
| 16 | \___|_|\__,_|\__,_|\__,_|_|\___/ ` |
| 17 | |
| 18 | type phase int |
| 19 | |
| 20 | const ( |
| 21 | phaseSelect phase = iota |
| 22 | phaseInputKey |
| 23 | phaseSelectPlan |
| 24 | phaseLoadingModels |
| 25 | phaseSelectModel |
| 26 | phaseFilePicker |
| 27 | phaseDone |
| 28 | ) |
| 29 | |
| 30 | type entry struct { |
| 31 | Key string |
| 32 | Name string |
| 33 | Description string |
| 34 | AltKey string // For grouped entries with 2 variants (e.g., "ollama" <-> "ollama-cloud") |
| 35 | AltKeys []string // For grouped entries with 3+ variants (e.g., kimi variants) |
| 36 | } |
| 37 | |
| 38 | // PickerItem is a generic model entry for the two-column picker. |
| 39 | type PickerItem struct { |
| 40 | ID string |
| 41 | Name string |
| 42 | ContextLength int |
| 43 | } |
| 44 | |
| 45 | // DisplayName returns a human-friendly label for the item. |
| 46 | func (p PickerItem) DisplayName() string { |
| 47 | if p.Name != "" { |
| 48 | return p.Name |
| 49 | } |
| 50 | return p.ID |
| 51 | } |
| 52 | |
| 53 | // pickerModelsMsg is returned by the async model-fetch command. |
| 54 | type pickerModelsMsg struct { |
| 55 | families []string |
| 56 | models map[string][]PickerItem |
| 57 | err error |
| 58 | |
| 59 | // Popular provider drill-down data (openrouter only). |
| 60 | popularProviders []string |
| 61 | popularProviderModels map[string][]PickerItem |
| 62 | |
| 63 | // All model IDs for "enter by hand" validation (openrouter only). |
| 64 | allModelIDs map[string]bool |
| 65 | } |
| 66 | |
| 67 | // Model is the Bubble Tea model for the TUI. |
| 68 | type Model struct { |
| 69 | cfg *config.Config |
| 70 | cache *cache.DB |
| 71 | entries []entry |
| 72 | phase phase |
| 73 | cursor int |
| 74 | selected string |
| 75 | input textinput.Model |
| 76 | quitting bool |
| 77 | width int |
| 78 | height int |
| 79 | launchAfterConfig bool // true if user completed configuration and should launch |
| 80 | |
| 81 | // Model picker state (copilot or openrouter). |
| 82 | pickerProvider string |
| 83 | modelCursor int |
| 84 | modelsErr error |
| 85 | |
| 86 | // Two-column model picker state. |
| 87 | families []string |
| 88 | familyModels map[string][]PickerItem |
| 89 | familyCursor int |
| 90 | modelFocus bool // true = right column focused |
| 91 | |
| 92 | // Popular provider drill-down state (openrouter). |
| 93 | popularProviders []string |
| 94 | popularProviderModels map[string][]PickerItem |
| 95 | popularProviderCursor int |
| 96 | popularDrilldown bool // true = browsing models within a provider |
| 97 | |
| 98 | // "Enter model ID" input state (openrouter). |
| 99 | pickerInput textinput.Model |
| 100 | pickerInputActive bool |
| 101 | pickerInputErr string |
| 102 | allModelIDs map[string]bool |
| 103 | |
| 104 | // Provider filter state (phaseSelect). |
| 105 | filterActive bool |
| 106 | filterInput textinput.Model |
| 107 | filteredIdx []int // indices into entries matching filter |
| 108 | |
| 109 | // Show hidden providers toggle (phaseSelect). |
| 110 | showHidden bool |
| 111 | |
| 112 | // Ollama variant toggle: false = local (ollama), true = cloud (ollama-cloud) |
| 113 | ollamaCloud bool |
| 114 | |
| 115 | // Zai variant toggle: false = API (zai), true = Coding (zai-coding) |
| 116 | zaiCoding bool |
| 117 | |
| 118 | // Kimi variant: 0 = coding (kimi), 1 = api-cn (kimi-api-cn), 2 = api-intl (kimi-api-intl) |
| 119 | kimiVariant int |
| 120 | |
| 121 | // Transient status message (e.g. after refresh). |
| 122 | statusMsg string |
| 123 | |
| 124 | // File picker state (vkproxy zip selection). |
| 125 | filePicker filepicker.Model |
| 126 | |
| 127 | // Plan selection state (phaseSelectPlan). |
| 128 | plans []provider.Plan |
| 129 | planCursor int |
| 130 | |
| 131 | // Model picker filter state (phaseSelectModel). |
| 132 | pickerFilterActive bool |
| 133 | pickerFilteredIdx []int |
| 134 | pickerFilterCursor int |
| 135 | pickerFilterRight bool // true = filtering right column, false = left |
| 136 | } |
| 137 | |