tui.go

  1package tui
  2
  3import (
  4	"context"
  5	"fmt"
  6	"math/rand"
  7	"slices"
  8	"strings"
  9	"time"
 10
 11	"git.secluded.site/crush/internal/agent/tools/mcp"
 12	"git.secluded.site/crush/internal/app"
 13	"git.secluded.site/crush/internal/config"
 14	"git.secluded.site/crush/internal/event"
 15	"git.secluded.site/crush/internal/permission"
 16	"git.secluded.site/crush/internal/pubsub"
 17	cmpChat "git.secluded.site/crush/internal/tui/components/chat"
 18	"git.secluded.site/crush/internal/tui/components/chat/splash"
 19	"git.secluded.site/crush/internal/tui/components/completions"
 20	"git.secluded.site/crush/internal/tui/components/core"
 21	"git.secluded.site/crush/internal/tui/components/core/layout"
 22	"git.secluded.site/crush/internal/tui/components/core/status"
 23	"git.secluded.site/crush/internal/tui/components/dialogs"
 24	"git.secluded.site/crush/internal/tui/components/dialogs/commands"
 25	"git.secluded.site/crush/internal/tui/components/dialogs/filepicker"
 26	"git.secluded.site/crush/internal/tui/components/dialogs/models"
 27	"git.secluded.site/crush/internal/tui/components/dialogs/permissions"
 28	"git.secluded.site/crush/internal/tui/components/dialogs/quit"
 29	"git.secluded.site/crush/internal/tui/components/dialogs/sessions"
 30	"git.secluded.site/crush/internal/tui/page"
 31	"git.secluded.site/crush/internal/tui/page/chat"
 32	"git.secluded.site/crush/internal/tui/styles"
 33	"git.secluded.site/crush/internal/tui/util"
 34	"github.com/charmbracelet/bubbles/v2/key"
 35	tea "github.com/charmbracelet/bubbletea/v2"
 36	"github.com/charmbracelet/lipgloss/v2"
 37	"golang.org/x/text/cases"
 38	"golang.org/x/text/language"
 39)
 40
 41var lastMouseEvent time.Time
 42
 43func MouseEventFilter(m tea.Model, msg tea.Msg) tea.Msg {
 44	switch msg.(type) {
 45	case tea.MouseWheelMsg, tea.MouseMotionMsg:
 46		now := time.Now()
 47		// trackpad is sending too many requests
 48		if now.Sub(lastMouseEvent) < 15*time.Millisecond {
 49			return nil
 50		}
 51		lastMouseEvent = now
 52	}
 53	return msg
 54}
 55
 56// appModel represents the main application model that manages pages, dialogs, and UI state.
 57type appModel struct {
 58	wWidth, wHeight int // Window dimensions
 59	width, height   int
 60	keyMap          KeyMap
 61
 62	currentPage  page.PageID
 63	previousPage page.PageID
 64	pages        map[page.PageID]util.Model
 65	loadedPages  map[page.PageID]bool
 66
 67	// Status
 68	status          status.StatusCmp
 69	showingFullHelp bool
 70
 71	app *app.App
 72
 73	dialog       dialogs.DialogCmp
 74	completions  completions.Completions
 75	isConfigured bool
 76
 77	// Chat Page Specific
 78	selectedSessionID string // The ID of the currently selected session
 79
 80	// sendProgressBar instructs the TUI to send progress bar updates to the
 81	// terminal.
 82	sendProgressBar bool
 83
 84	// QueryVersion instructs the TUI to query for the terminal version when it
 85	// starts.
 86	QueryVersion bool
 87}
 88
 89// Init initializes the application model and returns initial commands.
 90func (a appModel) Init() tea.Cmd {
 91	item, ok := a.pages[a.currentPage]
 92	if !ok {
 93		return nil
 94	}
 95
 96	var cmds []tea.Cmd
 97	cmd := item.Init()
 98	cmds = append(cmds, cmd)
 99	a.loadedPages[a.currentPage] = true
100
101	cmd = a.status.Init()
102	cmds = append(cmds, cmd)
103	if a.QueryVersion {
104		cmds = append(cmds, tea.RequestTerminalVersion)
105	}
106
107	return tea.Batch(cmds...)
108}
109
110// Update handles incoming messages and updates the application state.
111func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
112	var cmds []tea.Cmd
113	var cmd tea.Cmd
114	a.isConfigured = config.HasInitialDataConfig()
115
116	switch msg := msg.(type) {
117	case tea.EnvMsg:
118		// Is this Windows Terminal?
119		if !a.sendProgressBar {
120			a.sendProgressBar = slices.Contains(msg, "WT_SESSION")
121		}
122	case tea.TerminalVersionMsg:
123		termVersion := strings.ToLower(string(msg))
124		// Only enable progress bar for the following terminals.
125		if !a.sendProgressBar {
126			a.sendProgressBar = strings.Contains(termVersion, "ghostty")
127		}
128		return a, nil
129	case tea.KeyboardEnhancementsMsg:
130		for id, page := range a.pages {
131			m, pageCmd := page.Update(msg)
132			a.pages[id] = m
133
134			if pageCmd != nil {
135				cmds = append(cmds, pageCmd)
136			}
137		}
138		return a, tea.Batch(cmds...)
139	case tea.WindowSizeMsg:
140		a.wWidth, a.wHeight = msg.Width, msg.Height
141		a.completions.Update(msg)
142		return a, a.handleWindowResize(msg.Width, msg.Height)
143
144	case pubsub.Event[mcp.Event]:
145		switch msg.Payload.Type {
146		case mcp.EventStateChanged:
147			return a, a.handleStateChanged(context.Background())
148		case mcp.EventPromptsListChanged:
149			return a, handleMCPPromptsEvent(context.Background(), msg.Payload.Name)
150		case mcp.EventToolsListChanged:
151			return a, handleMCPToolsEvent(context.Background(), msg.Payload.Name)
152		}
153
154	// Completions messages
155	case completions.OpenCompletionsMsg, completions.FilterCompletionsMsg,
156		completions.CloseCompletionsMsg, completions.RepositionCompletionsMsg:
157		u, completionCmd := a.completions.Update(msg)
158		if model, ok := u.(completions.Completions); ok {
159			a.completions = model
160		}
161
162		return a, completionCmd
163
164	// Dialog messages
165	case dialogs.OpenDialogMsg, dialogs.CloseDialogMsg:
166		u, completionCmd := a.completions.Update(completions.CloseCompletionsMsg{})
167		a.completions = u.(completions.Completions)
168		u, dialogCmd := a.dialog.Update(msg)
169		a.dialog = u.(dialogs.DialogCmp)
170		return a, tea.Batch(completionCmd, dialogCmd)
171	case commands.ShowArgumentsDialogMsg:
172		var args []commands.Argument
173		for _, arg := range msg.ArgNames {
174			args = append(args, commands.Argument{
175				Name:     arg,
176				Title:    cases.Title(language.English).String(arg),
177				Required: true,
178			})
179		}
180		return a, util.CmdHandler(
181			dialogs.OpenDialogMsg{
182				Model: commands.NewCommandArgumentsDialog(
183					msg.CommandID,
184					msg.CommandID,
185					msg.CommandID,
186					msg.Description,
187					args,
188					msg.OnSubmit,
189				),
190			},
191		)
192	case commands.ShowMCPPromptArgumentsDialogMsg:
193		args := make([]commands.Argument, 0, len(msg.Prompt.Arguments))
194		for _, arg := range msg.Prompt.Arguments {
195			args = append(args, commands.Argument(*arg))
196		}
197		dialog := commands.NewCommandArgumentsDialog(
198			msg.Prompt.Name,
199			msg.Prompt.Title,
200			msg.Prompt.Name,
201			msg.Prompt.Description,
202			args,
203			msg.OnSubmit,
204		)
205		return a, util.CmdHandler(
206			dialogs.OpenDialogMsg{
207				Model: dialog,
208			},
209		)
210	// Page change messages
211	case page.PageChangeMsg:
212		return a, a.moveToPage(msg.ID)
213
214	// Status Messages
215	case util.InfoMsg, util.ClearStatusMsg:
216		s, statusCmd := a.status.Update(msg)
217		a.status = s.(status.StatusCmp)
218		cmds = append(cmds, statusCmd)
219		return a, tea.Batch(cmds...)
220
221	// Session
222	case cmpChat.SessionSelectedMsg:
223		a.selectedSessionID = msg.ID
224	case cmpChat.SessionClearedMsg:
225		a.selectedSessionID = ""
226	// Commands
227	case commands.SwitchSessionsMsg:
228		return a, func() tea.Msg {
229			allSessions, _ := a.app.Sessions.List(context.Background())
230			return dialogs.OpenDialogMsg{
231				Model: sessions.NewSessionDialogCmp(allSessions, a.selectedSessionID),
232			}
233		}
234
235	case commands.SwitchModelMsg:
236		// Opening model dialog is interaction; cancel pending turn-end notif.
237		if a.app.AgentCoordinator != nil && a.app.AgentCoordinator.HasPendingCompletionNotification(a.selectedSessionID) {
238			a.app.AgentCoordinator.CancelCompletionNotification(a.selectedSessionID)
239		}
240		return a, util.CmdHandler(
241			dialogs.OpenDialogMsg{
242				Model: models.NewModelDialogCmp(),
243			},
244		)
245	// Compact
246	case commands.CompactMsg:
247		return a, func() tea.Msg {
248			err := a.app.AgentCoordinator.Summarize(context.Background(), msg.SessionID)
249			if err != nil {
250				return util.ReportError(err)()
251			}
252			return nil
253		}
254	case commands.QuitMsg:
255		return a, util.CmdHandler(dialogs.OpenDialogMsg{
256			Model: quit.NewQuitDialog(),
257		})
258	case commands.ToggleYoloModeMsg:
259		a.app.Permissions.SetSkipRequests(!a.app.Permissions.SkipRequests())
260	case commands.ToggleHelpMsg:
261		a.status.ToggleFullHelp()
262		a.showingFullHelp = !a.showingFullHelp
263		return a, a.handleWindowResize(a.wWidth, a.wHeight)
264	// Model Switch
265	case models.ModelSelectedMsg:
266		if a.app.AgentCoordinator.IsBusy() {
267			return a, util.ReportWarn("Agent is busy, please wait...")
268		}
269
270		cfg := config.Get()
271		if err := cfg.UpdatePreferredModel(msg.ModelType, msg.Model); err != nil {
272			return a, util.ReportError(err)
273		}
274
275		go a.app.UpdateAgentModel(context.TODO())
276
277		modelTypeName := "large"
278		if msg.ModelType == config.SelectedModelTypeSmall {
279			modelTypeName = "small"
280		}
281		return a, util.ReportInfo(fmt.Sprintf("%s model changed to %s", modelTypeName, msg.Model.Model))
282
283	// File Picker
284	case commands.OpenFilePickerMsg:
285		event.FilePickerOpened()
286
287		if a.dialog.ActiveDialogID() == filepicker.FilePickerID {
288			// If the commands dialog is already open, close it
289			return a, util.CmdHandler(dialogs.CloseDialogMsg{})
290		}
291		return a, util.CmdHandler(dialogs.OpenDialogMsg{
292			Model: filepicker.NewFilePickerCmp(a.app.Config().WorkingDir()),
293		})
294	// Permissions
295	case pubsub.Event[permission.PermissionNotification]:
296		item, ok := a.pages[a.currentPage]
297		if !ok {
298			return a, nil
299		}
300
301		// Forward to view.
302		updated, itemCmd := item.Update(msg)
303		a.pages[a.currentPage] = updated
304
305		return a, itemCmd
306	case pubsub.Event[permission.PermissionRequest]:
307		return a, util.CmdHandler(dialogs.OpenDialogMsg{
308			Model: permissions.NewPermissionDialogCmp(msg.Payload, &permissions.Options{
309				DiffMode: config.Get().Options.TUI.DiffMode,
310			}),
311		})
312	case permissions.PermissionResponseMsg:
313		switch msg.Action {
314		case permissions.PermissionAllow:
315			a.app.Permissions.Grant(msg.Permission)
316		case permissions.PermissionAllowForSession:
317			a.app.Permissions.GrantPersistent(msg.Permission)
318		case permissions.PermissionDeny:
319			a.app.Permissions.Deny(msg.Permission)
320		}
321		return a, nil
322	case permissions.PermissionInteractionMsg:
323		// Notify that the user interacted with the permission dialog.
324		a.app.Permissions.NotifyInteraction(msg.ToolCallID)
325		return a, nil
326	case splash.OnboardingCompleteMsg:
327		item, ok := a.pages[a.currentPage]
328		if !ok {
329			return a, nil
330		}
331
332		a.isConfigured = config.HasInitialDataConfig()
333		updated, pageCmd := item.Update(msg)
334		a.pages[a.currentPage] = updated
335
336		cmds = append(cmds, pageCmd)
337		return a, tea.Batch(cmds...)
338
339	case tea.KeyPressMsg:
340		return a, a.handleKeyPressMsg(msg)
341
342	case tea.MouseWheelMsg:
343		if a.dialog.HasDialogs() {
344			u, dialogCmd := a.dialog.Update(msg)
345			a.dialog = u.(dialogs.DialogCmp)
346			cmds = append(cmds, dialogCmd)
347		} else {
348			item, ok := a.pages[a.currentPage]
349			if !ok {
350				return a, nil
351			}
352
353			updated, pageCmd := item.Update(msg)
354			a.pages[a.currentPage] = updated
355
356			cmds = append(cmds, pageCmd)
357		}
358		return a, tea.Batch(cmds...)
359	case tea.PasteMsg:
360		if a.dialog.HasDialogs() {
361			u, dialogCmd := a.dialog.Update(msg)
362			if model, ok := u.(dialogs.DialogCmp); ok {
363				a.dialog = model
364			}
365
366			cmds = append(cmds, dialogCmd)
367		} else {
368			item, ok := a.pages[a.currentPage]
369			if !ok {
370				return a, nil
371			}
372
373			updated, pageCmd := item.Update(msg)
374			a.pages[a.currentPage] = updated
375
376			cmds = append(cmds, pageCmd)
377		}
378		return a, tea.Batch(cmds...)
379	}
380	s, _ := a.status.Update(msg)
381	a.status = s.(status.StatusCmp)
382
383	item, ok := a.pages[a.currentPage]
384	if !ok {
385		return a, nil
386	}
387
388	updated, cmd := item.Update(msg)
389	a.pages[a.currentPage] = updated
390
391	if a.dialog.HasDialogs() {
392		u, dialogCmd := a.dialog.Update(msg)
393		if model, ok := u.(dialogs.DialogCmp); ok {
394			a.dialog = model
395		}
396
397		cmds = append(cmds, dialogCmd)
398	}
399	cmds = append(cmds, cmd)
400	return a, tea.Batch(cmds...)
401}
402
403// handleWindowResize processes window resize events and updates all components.
404func (a *appModel) handleWindowResize(width, height int) tea.Cmd {
405	var cmds []tea.Cmd
406
407	// TODO: clean up these magic numbers.
408	if a.showingFullHelp {
409		height -= 5
410	} else {
411		height -= 2
412	}
413
414	a.width, a.height = width, height
415	// Update status bar
416	s, cmd := a.status.Update(tea.WindowSizeMsg{Width: width, Height: height})
417	if model, ok := s.(status.StatusCmp); ok {
418		a.status = model
419	}
420	cmds = append(cmds, cmd)
421
422	// Update the current view.
423	for p, page := range a.pages {
424		updated, pageCmd := page.Update(tea.WindowSizeMsg{Width: width, Height: height})
425		a.pages[p] = updated
426
427		cmds = append(cmds, pageCmd)
428	}
429
430	// Update the dialogs
431	dialog, cmd := a.dialog.Update(tea.WindowSizeMsg{Width: width, Height: height})
432	if model, ok := dialog.(dialogs.DialogCmp); ok {
433		a.dialog = model
434	}
435
436	cmds = append(cmds, cmd)
437
438	return tea.Batch(cmds...)
439}
440
441// handleKeyPressMsg processes keyboard input and routes to appropriate handlers.
442func (a *appModel) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
443	// Check this first as the user should be able to quit no matter what.
444	if key.Matches(msg, a.keyMap.Quit) {
445		if a.dialog.ActiveDialogID() == quit.QuitDialogID {
446			return tea.Quit
447		}
448		return util.CmdHandler(dialogs.OpenDialogMsg{
449			Model: quit.NewQuitDialog(),
450		})
451	}
452
453	if a.completions.Open() {
454		// completions
455		keyMap := a.completions.KeyMap()
456		switch {
457		case key.Matches(msg, keyMap.Up), key.Matches(msg, keyMap.Down),
458			key.Matches(msg, keyMap.Select), key.Matches(msg, keyMap.Cancel),
459			key.Matches(msg, keyMap.UpInsert), key.Matches(msg, keyMap.DownInsert):
460			u, cmd := a.completions.Update(msg)
461			a.completions = u.(completions.Completions)
462			return cmd
463		}
464	}
465	if a.dialog.HasDialogs() {
466		u, dialogCmd := a.dialog.Update(msg)
467		a.dialog = u.(dialogs.DialogCmp)
468		return dialogCmd
469	}
470	switch {
471	// help
472	case key.Matches(msg, a.keyMap.Help):
473		a.status.ToggleFullHelp()
474		a.showingFullHelp = !a.showingFullHelp
475		return a.handleWindowResize(a.wWidth, a.wHeight)
476		// dialogs
477	case key.Matches(msg, a.keyMap.Commands):
478		// Opening the command palette counts as interaction; cancel pending
479		// turn-end notification for the selected session if any.
480		if a.app.AgentCoordinator != nil && a.app.AgentCoordinator.HasPendingCompletionNotification(a.selectedSessionID) {
481			a.app.AgentCoordinator.CancelCompletionNotification(a.selectedSessionID)
482		}
483		// if the app is not configured show no commands
484		if !a.isConfigured {
485			return nil
486		}
487		if a.dialog.ActiveDialogID() == commands.CommandsDialogID {
488			return util.CmdHandler(dialogs.CloseDialogMsg{})
489		}
490		if a.dialog.HasDialogs() {
491			return nil
492		}
493		return util.CmdHandler(dialogs.OpenDialogMsg{
494			Model: commands.NewCommandDialog(a.selectedSessionID),
495		})
496	case key.Matches(msg, a.keyMap.Sessions):
497		// if the app is not configured show no sessions
498		if !a.isConfigured {
499			return nil
500		}
501		// Opening sessions dialog is interaction; cancel pending turn-end notif.
502		if a.app.AgentCoordinator != nil && a.app.AgentCoordinator.HasPendingCompletionNotification(a.selectedSessionID) {
503			a.app.AgentCoordinator.CancelCompletionNotification(a.selectedSessionID)
504		}
505		if a.dialog.ActiveDialogID() == sessions.SessionsDialogID {
506			return util.CmdHandler(dialogs.CloseDialogMsg{})
507		}
508		if a.dialog.HasDialogs() && a.dialog.ActiveDialogID() != commands.CommandsDialogID {
509			return nil
510		}
511		var cmds []tea.Cmd
512		if a.dialog.ActiveDialogID() == commands.CommandsDialogID {
513			// If the commands dialog is open, close it first
514			cmds = append(cmds, util.CmdHandler(dialogs.CloseDialogMsg{}))
515		}
516		cmds = append(cmds,
517			func() tea.Msg {
518				allSessions, _ := a.app.Sessions.List(context.Background())
519				return dialogs.OpenDialogMsg{
520					Model: sessions.NewSessionDialogCmp(allSessions, a.selectedSessionID),
521				}
522			},
523		)
524		return tea.Sequence(cmds...)
525	case key.Matches(msg, a.keyMap.Suspend):
526		if a.app.AgentCoordinator != nil && a.app.AgentCoordinator.IsBusy() {
527			return util.ReportWarn("Agent is busy, please wait...")
528		}
529		return tea.Suspend
530	default:
531		item, ok := a.pages[a.currentPage]
532		if !ok {
533			return nil
534		}
535
536		updated, cmd := item.Update(msg)
537		a.pages[a.currentPage] = updated
538		return cmd
539	}
540}
541
542// moveToPage handles navigation between different pages in the application.
543func (a *appModel) moveToPage(pageID page.PageID) tea.Cmd {
544	if a.app.AgentCoordinator.IsBusy() {
545		// TODO: maybe remove this :  For now we don't move to any page if the agent is busy
546		return util.ReportWarn("Agent is busy, please wait...")
547	}
548
549	var cmds []tea.Cmd
550	if _, ok := a.loadedPages[pageID]; !ok {
551		cmd := a.pages[pageID].Init()
552		cmds = append(cmds, cmd)
553		a.loadedPages[pageID] = true
554	}
555	a.previousPage = a.currentPage
556	a.currentPage = pageID
557	if sizable, ok := a.pages[a.currentPage].(layout.Sizeable); ok {
558		cmd := sizable.SetSize(a.width, a.height)
559		cmds = append(cmds, cmd)
560	}
561
562	return tea.Batch(cmds...)
563}
564
565// View renders the complete application interface including pages, dialogs, and overlays.
566func (a *appModel) View() tea.View {
567	var view tea.View
568	view.AltScreen = true
569	t := styles.CurrentTheme()
570	view.BackgroundColor = t.BgBase
571	if a.wWidth < 25 || a.wHeight < 15 {
572		view.Layer = lipgloss.NewCanvas(
573			lipgloss.NewLayer(
574				t.S().Base.Width(a.wWidth).Height(a.wHeight).
575					Align(lipgloss.Center, lipgloss.Center).
576					Render(
577						t.S().Base.
578							Padding(1, 4).
579							Foreground(t.White).
580							BorderStyle(lipgloss.RoundedBorder()).
581							BorderForeground(t.Primary).
582							Render("Window too small!"),
583					),
584			),
585		)
586		return view
587	}
588
589	page := a.pages[a.currentPage]
590	if withHelp, ok := page.(core.KeyMapHelp); ok {
591		a.status.SetKeyMap(withHelp.Help())
592	}
593	pageView := page.View()
594	components := []string{
595		pageView,
596	}
597	components = append(components, a.status.View())
598
599	appView := lipgloss.JoinVertical(lipgloss.Top, components...)
600	layers := []*lipgloss.Layer{
601		lipgloss.NewLayer(appView),
602	}
603	if a.dialog.HasDialogs() {
604		layers = append(
605			layers,
606			a.dialog.GetLayers()...,
607		)
608	}
609
610	var cursor *tea.Cursor
611	if v, ok := page.(util.Cursor); ok {
612		cursor = v.Cursor()
613		// Hide the cursor if it's positioned outside the textarea
614		statusHeight := a.height - strings.Count(pageView, "\n") + 1
615		if cursor != nil && cursor.Y+statusHeight+chat.EditorHeight-2 <= a.height { // 2 for the top and bottom app padding
616			cursor = nil
617		}
618	}
619	activeView := a.dialog.ActiveModel()
620	if activeView != nil {
621		cursor = nil // Reset cursor if a dialog is active unless it implements util.Cursor
622		if v, ok := activeView.(util.Cursor); ok {
623			cursor = v.Cursor()
624		}
625	}
626
627	if a.completions.Open() && cursor != nil {
628		cmp := a.completions.View()
629		x, y := a.completions.Position()
630		layers = append(
631			layers,
632			lipgloss.NewLayer(cmp).X(x).Y(y),
633		)
634	}
635
636	canvas := lipgloss.NewCanvas(
637		layers...,
638	)
639
640	view.Layer = canvas
641	view.Cursor = cursor
642	view.MouseMode = tea.MouseModeCellMotion
643
644	if a.sendProgressBar && a.app != nil && a.app.AgentCoordinator != nil && a.app.AgentCoordinator.IsBusy() {
645		// HACK: use a random percentage to prevent ghostty from hiding it
646		// after a timeout.
647		view.ProgressBar = tea.NewProgressBar(tea.ProgressBarIndeterminate, rand.Intn(100))
648	}
649	return view
650}
651
652func (a *appModel) handleStateChanged(ctx context.Context) tea.Cmd {
653	return func() tea.Msg {
654		a.app.UpdateAgentModel(ctx)
655		return nil
656	}
657}
658
659func handleMCPPromptsEvent(ctx context.Context, name string) tea.Cmd {
660	return func() tea.Msg {
661		mcp.RefreshPrompts(ctx, name)
662		return nil
663	}
664}
665
666func handleMCPToolsEvent(ctx context.Context, name string) tea.Cmd {
667	return func() tea.Msg {
668		mcp.RefreshTools(ctx, name)
669		return nil
670	}
671}
672
673// New creates and initializes a new TUI application model.
674func New(app *app.App) *appModel {
675	chatPage := chat.New(app)
676	keyMap := DefaultKeyMap()
677	keyMap.pageBindings = chatPage.Bindings()
678
679	model := &appModel{
680		currentPage: chat.ChatPageID,
681		app:         app,
682		status:      status.NewStatusCmp(),
683		loadedPages: make(map[page.PageID]bool),
684		keyMap:      keyMap,
685
686		pages: map[page.PageID]util.Model{
687			chat.ChatPageID: chatPage,
688		},
689
690		dialog:      dialogs.NewDialogCmp(),
691		completions: completions.New(),
692	}
693
694	return model
695}