okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
8e3e173
main
1package tui 2 3import ( 4"albedo/cli/internal/daemon" 5 6 tea"charm.land/bubbletea/v2" 7) 8 9func (m * AppModel )initScreen () tea.Cmd { 10switch m .State { 11case AppStateChat : 12return tea .Batch (m .Chat .Init (),m .loadCommandCatalogCmd (m .CatalogGen ),m .recordOpenCmd (m .ActiveSession .ID )) 13case AppStateLogin : 14return m .Login .initWithProfiles (m .Profiles ) 15case AppStateSessionPicker : 16return tea .Batch (m .SessionPicker .Init (),m .SessionPicker .PreviewCmd ()) 17 } 18return nil 19} 20 21func (m * AppModel )returnToChat () tea.Cmd { 22if m .Chat .SessionID != m .ActiveSession .ID { 23return tea .Batch (m .setChatSession (* m .ActiveSession ,false ),m .recordOpenCmd (m .ActiveSession .ID )) 24 } 25m .State = AppStateChat 26return nil 27} 28 29func (m * AppModel )openLogin (name string ) tea.Cmd { 30previous := m .Login .Close () 31m .Login = NewLoginModel (m .Conn ,name ,m .openBrowser ) 32m .Login .SetSize (m .Width ,m .Height ) 33m .State = AppStateLogin 34return tea .Batch (previous ,m .Login .Init ()) 35} 36 37func (m * AppModel )openSessions () tea.Cmd { 38m .State = AppStateSessionPicker 39m .SessionGen ++ 40return tea .Batch (m .SessionPicker .Init (),m .loadSessionsCmd (m .SessionGen ),m .refreshSettingsCmd ()) 41} 42 43type screen interface { 44SetSize (int ,int ) 45Init () tea.Cmd 46} 47 48func (m * AppModel )openScreen (state AppState ,s screen ) tea.Cmd { 49s .SetSize (m .Width ,m .Height ) 50m .State = state 51return s .Init () 52} 53 54func (m * AppModel )openModelPicker () tea.Cmd { 55if m .ActiveSession == nil { 56return nil 57 } 58m .ModelPicker .Close () 59m .ModelPicker = NewModelPickerModel (m .Conn ,m .Profiles ,m .ActiveSession .Model ,m .ActiveSession .Provider ,m .ActiveSession .Effort ) 60return m .openScreen (AppStateModelPicker ,& m .ModelPicker ) 61} 62 63func (m * AppModel )openExtensionPicker () tea.Cmd { 64if m .ActiveSession == nil { 65return nil 66 } 67m .ExtensionPicker = NewExtensionPickerModel (m .Conn ,m .ActiveSession .ID ) 68return m .openScreen (AppStateExtensionPicker ,& m .ExtensionPicker ) 69} 70 71func (m * AppModel )openTreePicker () tea.Cmd { 72if m .ActiveSession == nil { 73return nil 74 } 75m .TreePicker = NewTreePickerModel (m .Conn ,m .ActiveSession .ID ) 76return m .openScreen (AppStateTreePicker ,& m .TreePicker ) 77} 78 79func (m * AppModel )openQuota () tea.Cmd { 80m .Quota = NewQuotaModel (m .Conn ) 81return m .openScreen (AppStateQuota ,& m .Quota ) 82} 83 84func (m * AppModel )openContextInspector () tea.Cmd { 85if m .ActiveSession == nil { 86return nil 87 } 88m .ContextInspector = NewContextInspectorModel (m .Conn ,m .ActiveSession .ID ) 89return m .openScreen (AppStateContextInspector ,& m .ContextInspector ) 90} 91 92// openFolderPicker offers the session another folder; a retry is the turn 93// its missing folder refused. 94func (m * AppModel )openFolderPicker (retry * WorkspaceRetry ) tea.Cmd { 95if m .ActiveSession == nil { 96return nil 97 } 98m .FolderPicker .Close () 99m .FolderPicker = NewFolderPicker (daemonFolders {conn :m .Conn ,condition : daemon.SessionCondition {ETag :m .ActiveSession .ETag ,FamilyRevision :m .ActiveSession .FamilyRevision }},* m .ActiveSession ,retry ) 100m .folderReturn = AppStateChat 101return m .openScreen (AppStateFolderPicker ,& m .FolderPicker ) 102} 103 104// openFolderBrowser lists sessions by folder, from the sessions view. 105func (m * AppModel )openFolderBrowser (query string ) tea.Cmd { 106m .FolderPicker .Close () 107m .FolderPicker = NewFolderBrowser (daemonFolders {conn :m .Conn },m .Workspace ,query ) 108m .folderReturn = AppStateSessionPicker 109return m .openScreen (AppStateFolderPicker ,& m .FolderPicker ) 110} 111 112// moved takes the daemon's answer to moving the session on screen. 113func (m * AppModel )moved (msg FolderMovedMsg ) tea.Cmd { 114if m .ActiveSession == nil || msg .SessionID != m .ActiveSession .ID { 115return nil 116 } 117if msg .Err != nil { 118if m .State == AppStateFolderPicker { 119m .FolderPicker .Refused (msg .Err ) 120 }else { 121m .AddError (operationError (msg .Err ,"Could not move this session: " ,"Session may have moved; check its folder before trying again." )) 122 } 123return nil 124 } 125if msg .Session != nil && msg .Session .ETag != "" { 126captured := * msg .Session 127m .ActiveSession = & captured 128 } 129m .ActiveSession .Workspace ,m .ActiveSession .Location ,m .Workspace = msg .Workspace ,msg .Location ,msg .Workspace 130m .updateSession (* m .ActiveSession ) 131m .State = AppStateChat 132return m .Chat .Moved (* m .ActiveSession ,msg .Retry ) 133} 134 135// Close releases this application's reads and subscriptions. Shared daemon 136// work and admitted mutations continue independently of the terminal. 137func (m * AppModel )Close () tea.Cmd { 138m .Chat .Close () 139m .Agents .Close () 140m .ModelPicker .Close () 141m .FolderPicker .Close () 142return m .Login .Close () 143}