summaryrefslogtreecommitdiffhomepage
path: root/packages/tui/internal/app
diff options
context:
space:
mode:
authorDax <[email protected]>2025-07-07 15:53:43 -0400
committerGitHub <[email protected]>2025-07-07 15:53:43 -0400
commitf884766445bbf1fbce11f1db4bc6174e72d9baa5 (patch)
treee7d9e7b3d8efc8bed249f9d29e2d8fb838a275f2 /packages/tui/internal/app
parent76b2e4539cb97bae5812ed2d832ce49d02e70c64 (diff)
downloadopencode-f884766445bbf1fbce11f1db4bc6174e72d9baa5.tar.gz
opencode-f884766445bbf1fbce11f1db4bc6174e72d9baa5.zip
v2 message format and upgrade to ai sdk v5 (#743)
Co-authored-by: GitHub Action <[email protected]> Co-authored-by: Liang-Shih Lin <[email protected]> Co-authored-by: Dominik Engelhardt <[email protected]> Co-authored-by: Jay V <[email protected]> Co-authored-by: adamdottv <[email protected]>
Diffstat (limited to 'packages/tui/internal/app')
-rw-r--r--packages/tui/internal/app/app.go51
1 files changed, 26 insertions, 25 deletions
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,
})
}
}