From f3da73553c45f17e04b1e77cb13eb0fca714d1bd Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Fri, 30 May 2025 20:47:56 -0400 Subject: sync --- internal/tui/app/app.go | 215 ----------------------------------------- internal/tui/app/bridge.go | 42 -------- internal/tui/app/interfaces.go | 13 --- 3 files changed, 270 deletions(-) delete mode 100644 internal/tui/app/app.go delete mode 100644 internal/tui/app/bridge.go delete mode 100644 internal/tui/app/interfaces.go (limited to 'internal/tui/app') diff --git a/internal/tui/app/app.go b/internal/tui/app/app.go deleted file mode 100644 index 8320d815b..000000000 --- a/internal/tui/app/app.go +++ /dev/null @@ -1,215 +0,0 @@ -package app - -import ( - "context" - "fmt" - - "log/slog" - - tea "github.com/charmbracelet/bubbletea" - "github.com/sst/opencode/internal/config" - "github.com/sst/opencode/internal/fileutil" - "github.com/sst/opencode/internal/status" - "github.com/sst/opencode/internal/tui/state" - "github.com/sst/opencode/internal/tui/theme" - "github.com/sst/opencode/internal/tui/util" - "github.com/sst/opencode/pkg/client" -) - -type App struct { - Client *client.ClientWithResponses - Events *client.Client - Provider *client.ProviderInfo - Model *client.ProviderModel - Session *client.SessionInfo - Messages []client.MessageInfo - Status status.Service - - PrimaryAgentOLD AgentService - - // UI state - filepickerOpen bool - completionDialogOpen bool -} - -func New(ctx context.Context) (*App, error) { - // Initialize status service (still needed for UI notifications) - err := status.InitService() - if err != nil { - slog.Error("Failed to initialize status service", "error", err) - return nil, err - } - - // Initialize file utilities - fileutil.Init() - - // Create HTTP client - url := "http://localhost:16713" - httpClient, err := client.NewClientWithResponses(url) - if err != nil { - slog.Error("Failed to create client", "error", err) - return nil, err - } - eventClient, err := client.NewClient(url) - if err != nil { - slog.Error("Failed to create event client", "error", err) - return nil, err - } - - // Create service bridges - agentBridge := NewAgentServiceBridge(httpClient) - - app := &App{ - Client: httpClient, - Events: eventClient, - Session: &client.SessionInfo{}, - Messages: []client.MessageInfo{}, - PrimaryAgentOLD: agentBridge, - Status: status.GetService(), - } - - // Initialize theme based on configuration - app.initTheme() - - return app, nil -} - -type Attachment struct { - FilePath string - FileName string - MimeType string - Content []byte -} - -// Create creates a new session -func (a *App) SendChatMessage(ctx context.Context, text string, attachments []Attachment) tea.Cmd { - var cmds []tea.Cmd - if a.Session.Id == "" { - resp, err := a.Client.PostSessionCreateWithResponse(ctx) - if err != nil { - status.Error(err.Error()) - return nil - } - if resp.StatusCode() != 200 { - status.Error(fmt.Sprintf("failed to create session: %d", resp.StatusCode())) - return nil - } - - info := resp.JSON200 - a.Session = info - - cmds = append(cmds, util.CmdHandler(state.SessionSelectedMsg(info))) - } - - // 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: a.Session.Id, - Parts: parts, - ProviderID: a.Provider.Id, - ModelID: a.Model.Id, - }) - - // The actual response will come through SSE - // For now, just return success - return tea.Batch(cmds...) -} - -func (a *App) ListSessions(ctx context.Context) ([]client.SessionInfo, error) { - resp, err := a.Client.PostSessionListWithResponse(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.SessionInfo{}, nil - } - - sessions := *resp.JSON200 - return sessions, nil -} - -func (a *App) ListMessages(ctx context.Context, sessionId string) ([]client.MessageInfo, error) { - resp, err := a.Client.PostSessionMessagesWithResponse(ctx, client.PostSessionMessagesJSONRequestBody{SessionID: sessionId}) - if err != nil { - return nil, err - } - if resp.StatusCode() != 200 { - return nil, fmt.Errorf("failed to list messages: %d", resp.StatusCode()) - } - if resp.JSON200 == nil { - return []client.MessageInfo{}, nil - } - messages := *resp.JSON200 - 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() - if cfg == nil || cfg.TUI.Theme == "" { - return // Use default theme - } - - // Try to set the theme from config - err := theme.SetTheme(cfg.TUI.Theme) - if err != nil { - slog.Warn("Failed to set theme from config, using default theme", "theme", cfg.TUI.Theme, "error", err) - } else { - slog.Debug("Set theme from config", "theme", cfg.TUI.Theme) - } -} - -// IsFilepickerOpen returns whether the filepicker is currently open -func (app *App) IsFilepickerOpen() bool { - return app.filepickerOpen -} - -// SetFilepickerOpen sets the state of the filepicker -func (app *App) SetFilepickerOpen(open bool) { - app.filepickerOpen = open -} - -// IsCompletionDialogOpen returns whether the completion dialog is currently open -func (app *App) IsCompletionDialogOpen() bool { - return app.completionDialogOpen -} - -// SetCompletionDialogOpen sets the state of the completion dialog -func (app *App) SetCompletionDialogOpen(open bool) { - app.completionDialogOpen = open -} - -// Shutdown performs a clean shutdown of the application -func (app *App) Shutdown() { - // TODO: cleanup? -} diff --git a/internal/tui/app/bridge.go b/internal/tui/app/bridge.go deleted file mode 100644 index cd149f6b3..000000000 --- a/internal/tui/app/bridge.go +++ /dev/null @@ -1,42 +0,0 @@ -package app - -import ( - "context" - "fmt" - - "github.com/sst/opencode/pkg/client" -) - -// AgentServiceBridge provides a minimal agent service that sends messages to the API -type AgentServiceBridge struct { - client *client.ClientWithResponses -} - -// NewAgentServiceBridge creates a new agent service bridge -func NewAgentServiceBridge(client *client.ClientWithResponses) *AgentServiceBridge { - return &AgentServiceBridge{client: client} -} - -// Cancel cancels the current generation - NOT IMPLEMENTED IN API YET -func (a *AgentServiceBridge) Cancel(sessionID string) error { - // TODO: Not implemented in TypeScript API yet - return nil -} - -// IsBusy checks if the agent is busy - NOT IMPLEMENTED IN API YET -func (a *AgentServiceBridge) IsBusy() bool { - // TODO: Not implemented in TypeScript API yet - return false -} - -// IsSessionBusy checks if the agent is busy for a specific session - NOT IMPLEMENTED IN API YET -func (a *AgentServiceBridge) IsSessionBusy(sessionID string) bool { - // TODO: Not implemented in TypeScript API yet - return false -} - -// CompactSession compacts a session - NOT IMPLEMENTED IN API YET -func (a *AgentServiceBridge) CompactSession(ctx context.Context, sessionID string, force bool) error { - // TODO: Not implemented in TypeScript API yet - return fmt.Errorf("session compaction not implemented in API") -} diff --git a/internal/tui/app/interfaces.go b/internal/tui/app/interfaces.go deleted file mode 100644 index a396ef586..000000000 --- a/internal/tui/app/interfaces.go +++ /dev/null @@ -1,13 +0,0 @@ -package app - -import ( - "context" -) - -// AgentService defines the interface for agent operations -type AgentService interface { - Cancel(sessionID string) error - IsBusy() bool - IsSessionBusy(sessionID string) bool - CompactSession(ctx context.Context, sessionID string, force bool) error -} -- cgit v1.2.3