summaryrefslogtreecommitdiffhomepage
path: root/packages/tui
diff options
context:
space:
mode:
authoradamdotdevin <[email protected]>2025-08-10 19:24:16 -0500
committeradamdotdevin <[email protected]>2025-08-10 19:25:03 -0500
commitb8d2aebf09313d451cec873b3d0807b818015b32 (patch)
tree05f4edc9e4b15b6754e555a7b4eb03b46c997a58 /packages/tui
parent20e818ad05b385b51a29d265f0731155562e88c2 (diff)
downloadopencode-b8d2aebf09313d451cec873b3d0807b818015b32.tar.gz
opencode-b8d2aebf09313d451cec873b3d0807b818015b32.zip
feat: thinking blocks rendered in tui and share page
Diffstat (limited to 'packages/tui')
-rw-r--r--packages/tui/internal/components/chat/message.go20
-rw-r--r--packages/tui/internal/components/chat/messages.go32
-rw-r--r--packages/tui/internal/tui/tui.go4
3 files changed, 55 insertions, 1 deletions
diff --git a/packages/tui/internal/components/chat/message.go b/packages/tui/internal/components/chat/message.go
index 5f4dc9612..66f8d728e 100644
--- a/packages/tui/internal/components/chat/message.go
+++ b/packages/tui/internal/components/chat/message.go
@@ -208,6 +208,7 @@ func renderText(
showToolDetails bool,
width int,
extra string,
+ isThinking bool,
fileParts []opencode.FilePart,
agentParts []opencode.AgentPart,
toolCalls ...opencode.ToolPart,
@@ -219,8 +220,15 @@ func renderText(
var content string
switch casted := message.(type) {
case opencode.AssistantMessage:
+ bg := t.Background()
+ if isThinking {
+ bg = t.BackgroundPanel()
+ }
ts = time.UnixMilli(int64(casted.Time.Created))
- content = util.ToMarkdown(text, width, t.Background())
+ content = util.ToMarkdown(text, width, bg)
+ if isThinking {
+ content = styles.NewStyle().Background(bg).Foreground(t.TextMuted()).Render("Thinking") + "\n\n" + content
+ }
case opencode.UserMessage:
ts = time.UnixMilli(int64(casted.Time.Created))
base := styles.NewStyle().Foreground(t.Text()).Background(backgroundColor)
@@ -385,6 +393,16 @@ func renderText(
WithBorderColor(t.Secondary()),
)
case opencode.AssistantMessage:
+ if isThinking {
+ return renderContentBlock(
+ app,
+ content,
+ width,
+ WithTextColor(t.Text()),
+ WithBackgroundColor(t.BackgroundPanel()),
+ WithBorderColor(t.BackgroundPanel()),
+ )
+ }
return renderContentBlock(
app,
content,
diff --git a/packages/tui/internal/components/chat/messages.go b/packages/tui/internal/components/chat/messages.go
index 22cb97fb5..ff279821f 100644
--- a/packages/tui/internal/components/chat/messages.go
+++ b/packages/tui/internal/components/chat/messages.go
@@ -369,6 +369,7 @@ func (m *messagesComponent) renderView() tea.Cmd {
m.showToolDetails,
width,
files,
+ false,
fileParts,
agentParts,
)
@@ -448,6 +449,7 @@ func (m *messagesComponent) renderView() tea.Cmd {
m.showToolDetails,
width,
"",
+ false,
[]opencode.FilePart{},
[]opencode.AgentPart{},
toolCallParts...,
@@ -469,6 +471,7 @@ func (m *messagesComponent) renderView() tea.Cmd {
m.showToolDetails,
width,
"",
+ false,
[]opencode.FilePart{},
[]opencode.AgentPart{},
toolCallParts...,
@@ -546,6 +549,35 @@ func (m *messagesComponent) renderView() tea.Cmd {
lineCount += lipgloss.Height(content) + 1
blocks = append(blocks, content)
}
+ case opencode.ReasoningPart:
+ if reverted {
+ continue
+ }
+ text := "..."
+ if part.Text != "" {
+ text = part.Text
+ }
+ content = renderText(
+ m.app,
+ message.Info,
+ text,
+ casted.ModelID,
+ m.showToolDetails,
+ width,
+ "",
+ true,
+ []opencode.FilePart{},
+ []opencode.AgentPart{},
+ )
+ content = lipgloss.PlaceHorizontal(
+ m.width,
+ lipgloss.Center,
+ content,
+ styles.WhitespaceStyle(t.Background()),
+ )
+ partCount++
+ lineCount += lipgloss.Height(content) + 1
+ blocks = append(blocks, content)
}
}
}
diff --git a/packages/tui/internal/tui/tui.go b/packages/tui/internal/tui/tui.go
index 5f178e15a..639d15d04 100644
--- a/packages/tui/internal/tui/tui.go
+++ b/packages/tui/internal/tui/tui.go
@@ -423,6 +423,8 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch casted := p.(type) {
case opencode.TextPart:
return casted.ID == msg.Properties.Part.ID
+ case opencode.ReasoningPart:
+ return casted.ID == msg.Properties.Part.ID
case opencode.FilePart:
return casted.ID == msg.Properties.Part.ID
case opencode.ToolPart:
@@ -461,6 +463,8 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch casted := p.(type) {
case opencode.TextPart:
return casted.ID == msg.Properties.PartID
+ case opencode.ReasoningPart:
+ return casted.ID == msg.Properties.PartID
case opencode.FilePart:
return casted.ID == msg.Properties.PartID
case opencode.ToolPart: