summaryrefslogtreecommitdiffhomepage
path: root/internal/tui/app
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-05-30 15:34:22 -0500
committeradamdottv <[email protected]>2025-05-30 15:34:25 -0500
commitc69c9327da4a43a63928807fcf36b24755cfac18 (patch)
treedf79a6c58976af977a28717619d70db4a62f4853 /internal/tui/app
parentf5e2c596d4f887daa4df579975dd5451fadc8457 (diff)
downloadopencode-c69c9327da4a43a63928807fcf36b24755cfac18.tar.gz
opencode-c69c9327da4a43a63928807fcf36b24755cfac18.zip
wip: refactoring tui
Diffstat (limited to 'internal/tui/app')
-rw-r--r--internal/tui/app/app.go48
-rw-r--r--internal/tui/app/bridge.go27
-rw-r--r--internal/tui/app/interfaces.go1
3 files changed, 23 insertions, 53 deletions
diff --git a/internal/tui/app/app.go b/internal/tui/app/app.go
index b00a6d61a..8320d815b 100644
--- a/internal/tui/app/app.go
+++ b/internal/tui/app/app.go
@@ -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?
}
diff --git a/internal/tui/app/bridge.go b/internal/tui/app/bridge.go
index 3e8768ac1..cd149f6b3 100644
--- a/internal/tui/app/bridge.go
+++ b/internal/tui/app/bridge.go
@@ -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
diff --git a/internal/tui/app/interfaces.go b/internal/tui/app/interfaces.go
index 4cc9b8022..a396ef586 100644
--- a/internal/tui/app/interfaces.go
+++ b/internal/tui/app/interfaces.go
@@ -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