wip: refactoring tui

This commit is contained in:
adamdottv
2025-05-30 15:34:22 -05:00
parent f5e2c596d4
commit c69c9327da
13 changed files with 244 additions and 263 deletions

View File

@@ -3,7 +3,6 @@ package app
import (
"context"
"fmt"
"sync"
"log/slog"
@@ -20,20 +19,14 @@ import (
type App struct {
Client *client.ClientWithResponses
Events *client.Client
Provider *client.ProviderInfo
Model *client.ProviderModel
Session *client.SessionInfo
Messages []client.MessageInfo
LogsOLD any // TODO: Define LogService interface when needed
HistoryOLD any // TODO: Define HistoryService interface when needed
PermissionsOLD any // TODO: Define PermissionService interface when needed
Status status.Service
Status status.Service
PrimaryAgentOLD AgentService
watcherCancelFuncs []context.CancelFunc
cancelFuncsMutex sync.Mutex
watcherWG sync.WaitGroup
// UI state
filepickerOpen bool
completionDialogOpen bool
@@ -70,13 +63,9 @@ func New(ctx context.Context) (*App, error) {
Client: httpClient,
Events: eventClient,
Session: &client.SessionInfo{},
Messages: []client.MessageInfo{},
PrimaryAgentOLD: agentBridge,
Status: status.GetService(),
// TODO: These services need API endpoints:
LogsOLD: nil, // logging.GetService(),
HistoryOLD: nil, // history.GetService(),
PermissionsOLD: nil, // permission.GetService(),
}
// Initialize theme based on configuration
@@ -128,13 +117,12 @@ func (a *App) SendChatMessage(ctx context.Context, text string, attachments []At
go a.Client.PostSessionChatWithResponse(ctx, client.PostSessionChatJSONRequestBody{
SessionID: a.Session.Id,
Parts: parts,
ProviderID: "anthropic",
ModelID: "claude-sonnet-4-20250514",
ProviderID: a.Provider.Id,
ModelID: a.Model.Id,
})
// The actual response will come through SSE
// For now, just return success
return tea.Batch(cmds...)
}
@@ -169,6 +157,22 @@ func (a *App) ListMessages(ctx context.Context, sessionId string) ([]client.Mess
return messages, nil
}
func (a *App) ListProviders(ctx context.Context) ([]client.ProviderInfo, error) {
resp, err := a.Client.PostProviderListWithResponse(ctx)
if err != nil {
return nil, err
}
if resp.StatusCode() != 200 {
return nil, fmt.Errorf("failed to list sessions: %d", resp.StatusCode())
}
if resp.JSON200 == nil {
return []client.ProviderInfo{}, nil
}
providers := *resp.JSON200
return providers, nil
}
// initTheme sets the application theme based on the configuration
func (app *App) initTheme() {
cfg := config.Get()
@@ -207,11 +211,5 @@ func (app *App) SetCompletionDialogOpen(open bool) {
// Shutdown performs a clean shutdown of the application
func (app *App) Shutdown() {
// Cancel all watcher goroutines
app.cancelFuncsMutex.Lock()
for _, cancel := range app.watcherCancelFuncs {
cancel()
}
app.cancelFuncsMutex.Unlock()
app.watcherWG.Wait()
// TODO: cleanup?
}

View File

@@ -17,33 +17,6 @@ func NewAgentServiceBridge(client *client.ClientWithResponses) *AgentServiceBrid
return &AgentServiceBridge{client: client}
}
// Run sends a message to the chat API
func (a *AgentServiceBridge) Run(ctx context.Context, sessionID string, text string, attachments ...Attachment) (string, error) {
// TODO: Handle attachments when API supports them
if len(attachments) > 0 {
// For now, ignore attachments
// return "", fmt.Errorf("attachments not supported yet")
}
part := client.MessagePart{}
part.FromMessagePartText(client.MessagePartText{
Type: "text",
Text: text,
})
parts := []client.MessagePart{part}
go a.client.PostSessionChatWithResponse(ctx, client.PostSessionChatJSONRequestBody{
SessionID: sessionID,
Parts: parts,
ProviderID: "anthropic",
ModelID: "claude-sonnet-4-20250514",
})
// The actual response will come through SSE
// For now, just return success
return "", nil
}
// Cancel cancels the current generation - NOT IMPLEMENTED IN API YET
func (a *AgentServiceBridge) Cancel(sessionID string) error {
// TODO: Not implemented in TypeScript API yet

View File

@@ -6,7 +6,6 @@ import (
// AgentService defines the interface for agent operations
type AgentService interface {
Run(ctx context.Context, sessionID string, text string, attachments ...Attachment) (string, error)
Cancel(sessionID string) error
IsBusy() bool
IsSessionBusy(sessionID string) bool