From f884766445bbf1fbce11f1db4bc6174e72d9baa5 Mon Sep 17 00:00:00 2001 From: Dax Date: Mon, 7 Jul 2025 15:53:43 -0400 Subject: v2 message format and upgrade to ai sdk v5 (#743) Co-authored-by: GitHub Action Co-authored-by: Liang-Shih Lin Co-authored-by: Dominik Engelhardt Co-authored-by: Jay V Co-authored-by: adamdottv <2363879+adamdottv@users.noreply.github.com> --- packages/tui/internal/app/app.go | 51 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'packages/tui/internal/app') diff --git a/packages/tui/internal/app/app.go b/packages/tui/internal/app/app.go index 469857ab0..cffd07391 100644 --- a/packages/tui/internal/app/app.go +++ b/packages/tui/internal/app/app.go @@ -30,7 +30,7 @@ type App struct { Provider *opencode.Provider Model *opencode.Model Session *opencode.Session - Messages []opencode.Message + Messages []opencode.MessageUnion Commands commands.CommandRegistry } @@ -47,7 +47,7 @@ type SendMsg struct { Attachments []opencode.FilePartParam } type OptimisticMessageAddedMsg struct { - Message opencode.Message + Message opencode.MessageUnion } type FileRenderedMsg struct { FilePath string @@ -116,7 +116,7 @@ func New( State: appState, Client: httpClient, Session: &opencode.Session{}, - Messages: []opencode.Message{}, + Messages: []opencode.MessageUnion{}, Commands: commands.LoadFromConfig(configInfo), } @@ -223,7 +223,10 @@ func (a *App) IsBusy() bool { } lastMessage := a.Messages[len(a.Messages)-1] - return lastMessage.Metadata.Time.Completed == 0 + if casted, ok := lastMessage.(opencode.AssistantMessage); ok { + return casted.Time.Completed == 0 + } + return false } func (a *App) SaveState() { @@ -304,30 +307,28 @@ func (a *App) SendChatMessage( cmds = append(cmds, util.CmdHandler(SessionSelectedMsg(session))) } - optimisticParts := []opencode.MessagePart{{ - Type: opencode.MessagePartTypeText, + optimisticParts := []opencode.UserMessagePart{{ + Type: opencode.UserMessagePartTypeText, Text: text, }} if len(attachments) > 0 { for _, attachment := range attachments { - optimisticParts = append(optimisticParts, opencode.MessagePart{ - Type: opencode.MessagePartTypeFile, - Filename: attachment.Filename.Value, - MediaType: attachment.MediaType.Value, - URL: attachment.URL.Value, + optimisticParts = append(optimisticParts, opencode.UserMessagePart{ + Type: opencode.UserMessagePartTypeFile, + Filename: attachment.Filename.Value, + Mime: attachment.Mime.Value, + URL: attachment.URL.Value, }) } } - optimisticMessage := opencode.Message{ - ID: fmt.Sprintf("optimistic-%d", time.Now().UnixNano()), - Role: opencode.MessageRoleUser, - Parts: optimisticParts, - Metadata: opencode.MessageMetadata{ - SessionID: a.Session.ID, - Time: opencode.MessageMetadataTime{ - Created: float64(time.Now().Unix()), - }, + optimisticMessage := opencode.UserMessage{ + ID: fmt.Sprintf("optimistic-%d", time.Now().UnixNano()), + Role: opencode.UserMessageRoleUser, + Parts: optimisticParts, + SessionID: a.Session.ID, + Time: opencode.UserMessageTime{ + Created: float64(time.Now().Unix()), }, } @@ -335,7 +336,7 @@ func (a *App) SendChatMessage( cmds = append(cmds, util.CmdHandler(OptimisticMessageAddedMsg{Message: optimisticMessage})) cmds = append(cmds, func() tea.Msg { - parts := []opencode.MessagePartUnionParam{ + parts := []opencode.UserMessagePartUnionParam{ opencode.TextPartParam{ Type: opencode.F(opencode.TextPartTypeText), Text: opencode.F(text), @@ -344,10 +345,10 @@ func (a *App) SendChatMessage( if len(attachments) > 0 { for _, attachment := range attachments { parts = append(parts, opencode.FilePartParam{ - MediaType: attachment.MediaType, - Type: attachment.Type, - URL: attachment.URL, - Filename: attachment.Filename, + Mime: attachment.Mime, + Type: attachment.Type, + URL: attachment.URL, + Filename: attachment.Filename, }) } } -- cgit v1.2.3