diff options
| author | adamdottv <[email protected]> | 2025-05-28 14:02:03 -0500 |
|---|---|---|
| committer | adamdottv <[email protected]> | 2025-05-28 15:36:35 -0500 |
| commit | 8863a499a9e311a48d6ab8bc05d267fb2a01f060 (patch) | |
| tree | 304aabab518270af4b2ca4c0870f3b1bf0012038 | |
| parent | 15d21bf04acd6af75df97918f66df866c239b248 (diff) | |
| download | opencode-8863a499a9e311a48d6ab8bc05d267fb2a01f060.tar.gz opencode-8863a499a9e311a48d6ab8bc05d267fb2a01f060.zip | |
wip: refactoring tui
| -rw-r--r-- | internal/app/services_bridge.go | 32 | ||||
| -rw-r--r-- | internal/tui/components/chat/messages.go | 4 | ||||
| -rw-r--r-- | internal/tui/tui.go | 5 |
3 files changed, 18 insertions, 23 deletions
diff --git a/internal/app/services_bridge.go b/internal/app/services_bridge.go index d7e032bfd..d3f2e9a23 100644 --- a/internal/app/services_bridge.go +++ b/internal/app/services_bridge.go @@ -24,20 +24,14 @@ func NewSessionServiceBridge(client *client.ClientWithResponses) *SessionService // Create creates a new session func (s *SessionServiceBridge) Create(ctx context.Context, title string) (session.Session, error) { - resp, err := s.client.PostSessionCreate(ctx) + resp, err := s.client.PostSessionCreateWithResponse(ctx) if err != nil { return session.Session{}, err } - defer resp.Body.Close() - - if resp.StatusCode != 200 { + if resp.StatusCode() != 200 { return session.Session{}, fmt.Errorf("failed to create session: %d", resp.StatusCode) } - - var info client.SessionInfo - if err := json.NewDecoder(resp.Body).Decode(&info); err != nil { - return session.Session{}, err - } + info := resp.JSON200 // Convert to old session type return session.Session{ @@ -68,17 +62,21 @@ func (s *SessionServiceBridge) Get(ctx context.Context, id string) (session.Sess // List retrieves all sessions func (s *SessionServiceBridge) List(ctx context.Context) ([]session.Session, error) { - resp, err := s.client.PostSessionList(ctx) + resp, err := s.client.PostSessionListWithResponse(ctx) if err != nil { return nil, err } - defer resp.Body.Close() - var infos []client.SessionInfo - if err := json.NewDecoder(resp.Body).Decode(&infos); 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 []session.Session{}, nil + } + + infos := *resp.JSON200 + // Convert to old session type sessions := make([]session.Session, len(infos)) for i, info := range infos { @@ -130,14 +128,10 @@ func (a *AgentServiceBridge) Run(ctx context.Context, sessionID string, text str }, }) - resp, err := a.client.PostSessionChat(ctx, client.PostSessionChatJSONRequestBody{ + go a.client.PostSessionChatWithResponse(ctx, client.PostSessionChatJSONRequestBody{ SessionID: sessionID, Parts: &parts, }) - if err != nil { - return "", err - } - defer resp.Body.Close() // The actual response will come through SSE // For now, just return success diff --git a/internal/tui/components/chat/messages.go b/internal/tui/components/chat/messages.go index 681606b9f..668f0f6cd 100644 --- a/internal/tui/components/chat/messages.go +++ b/internal/tui/components/chat/messages.go @@ -104,6 +104,10 @@ func (m *messagesCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case renderFinishedMsg: m.rendering = false m.viewport.GotoBottom() + case state.StateUpdatedMsg: + m.renderView() + m.viewport.GotoBottom() + case pubsub.Event[message.Message]: needsRerender := false if msg.Type == message.EventMessageCreated { diff --git a/internal/tui/tui.go b/internal/tui/tui.go index 939607678..c70d1f2bf 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -2,8 +2,6 @@ package tui import ( "context" - "encoding/json" - // "fmt" "log/slog" "strings" @@ -15,7 +13,6 @@ import ( "github.com/sst/opencode/internal/app" "github.com/sst/opencode/internal/config" - // "github.com/sst/opencode/internal/llm/agent" "github.com/sst/opencode/internal/logging" "github.com/sst/opencode/internal/message" "github.com/sst/opencode/internal/permission" @@ -288,7 +285,7 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // Handle SSE events from the TypeScript backend case *client.EventStorageWrite: - slog.Debug("Received SSE event", "key", msg.Key, "content", msg.Content) + slog.Debug("Received SSE event", "key", msg.Key) // Create a deep copy of the state to avoid mutation issues newState := deepCopyState(a.app.State) |
