Always show tool calls, toggle whether results are hidden
This commit is contained in:
parent
c30e652103
commit
31df055430
@ -160,30 +160,34 @@ func (m *Model) renderMessage(i int) string {
|
||||
toolString = "tool_calls:\n" + string(bytes)
|
||||
}
|
||||
case api.MessageRoleToolResult:
|
||||
if !m.showToolResults {
|
||||
break
|
||||
}
|
||||
|
||||
type renderedResult struct {
|
||||
ToolName string `yaml:"tool"`
|
||||
Result any
|
||||
Result any `yaml:"result,omitempty"`
|
||||
}
|
||||
|
||||
var toolResults []renderedResult
|
||||
for _, result := range msg.ToolResults {
|
||||
var jsonResult interface{}
|
||||
err := json.Unmarshal([]byte(result.Result), &jsonResult)
|
||||
if err != nil {
|
||||
// If parsing as JSON fails, treat Result as a plain string
|
||||
toolResults = append(toolResults, renderedResult{
|
||||
ToolName: result.ToolName,
|
||||
Result: result.Result,
|
||||
})
|
||||
if m.showToolResults {
|
||||
var jsonResult interface{}
|
||||
err := json.Unmarshal([]byte(result.Result), &jsonResult)
|
||||
if err != nil {
|
||||
// If parsing as JSON fails, treat Result as a plain string
|
||||
toolResults = append(toolResults, renderedResult{
|
||||
ToolName: result.ToolName,
|
||||
Result: result.Result,
|
||||
})
|
||||
} else {
|
||||
// If parsing as JSON succeeds, marshal the parsed JSON into YAML
|
||||
toolResults = append(toolResults, renderedResult{
|
||||
ToolName: result.ToolName,
|
||||
Result: &jsonResult,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// If parsing as JSON succeeds, marshal the parsed JSON into YAML
|
||||
// Only show the tool name when results are hidden
|
||||
toolResults = append(toolResults, renderedResult{
|
||||
ToolName: result.ToolName,
|
||||
Result: &jsonResult,
|
||||
Result: "(hidden, press ctrl+t to view)",
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -226,17 +230,6 @@ func (m *Model) conversationMessagesView() string {
|
||||
for i, message := range m.messages {
|
||||
m.messageOffsets[i] = lineCnt
|
||||
|
||||
switch message.Role {
|
||||
case api.MessageRoleToolCall:
|
||||
if !m.showToolResults && message.Content == "" {
|
||||
continue
|
||||
}
|
||||
case api.MessageRoleToolResult:
|
||||
if !m.showToolResults {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
heading := m.renderMessageHeading(i, &message)
|
||||
sb.WriteString(heading)
|
||||
sb.WriteString("\n")
|
||||
|
Loading…
Reference in New Issue
Block a user