feat: thinking blocks rendered in tui and share page
This commit is contained in:
parent
20e818ad05
commit
b8d2aebf09
17 changed files with 324 additions and 55 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue