message.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. package chat
  2. import (
  3. "fmt"
  4. "path/filepath"
  5. "strings"
  6. "time"
  7. "github.com/charmbracelet/lipgloss"
  8. "github.com/charmbracelet/x/ansi"
  9. "github.com/sst/opencode/internal/components/diff"
  10. "github.com/sst/opencode/internal/styles"
  11. "github.com/sst/opencode/internal/theme"
  12. "github.com/sst/opencode/pkg/client"
  13. "golang.org/x/text/cases"
  14. "golang.org/x/text/language"
  15. )
  16. const (
  17. maxResultHeight = 10
  18. )
  19. func toMarkdown(content string, width int) string {
  20. r := styles.GetMarkdownRenderer(width)
  21. rendered, _ := r.Render(content)
  22. return strings.TrimSuffix(rendered, "\n")
  23. }
  24. func renderUserMessage(user string, msg client.MessageInfo, width int) string {
  25. t := theme.CurrentTheme()
  26. style := styles.BaseStyle().
  27. BorderLeft(true).
  28. Foreground(t.TextMuted()).
  29. BorderForeground(t.Secondary()).
  30. BorderStyle(lipgloss.ThickBorder())
  31. // var styledAttachments []string
  32. // attachmentStyles := baseStyle.
  33. // MarginLeft(1).
  34. // Background(t.TextMuted()).
  35. // Foreground(t.Text())
  36. // for _, attachment := range msg.BinaryContent() {
  37. // file := filepath.Base(attachment.Path)
  38. // var filename string
  39. // if len(file) > 10 {
  40. // filename = fmt.Sprintf(" %s %s...", styles.DocumentIcon, file[0:7])
  41. // } else {
  42. // filename = fmt.Sprintf(" %s %s", styles.DocumentIcon, file)
  43. // }
  44. // styledAttachments = append(styledAttachments, attachmentStyles.Render(filename))
  45. // }
  46. timestamp := time.UnixMilli(int64(msg.Metadata.Time.Created)).Local().Format("02 Jan 2006 03:04 PM")
  47. if time.Now().Format("02 Jan 2006") == timestamp[:11] {
  48. timestamp = timestamp[12:]
  49. }
  50. info := styles.Padded().
  51. Foreground(t.TextMuted()).
  52. Render(fmt.Sprintf("%s (%s)", user, timestamp))
  53. content := ""
  54. // if len(styledAttachments) > 0 {
  55. // attachmentContent := baseStyle.Width(width).Render(lipgloss.JoinHorizontal(lipgloss.Left, styledAttachments...))
  56. // content = renderMessage(msg.Content().String(), true, isFocused, width, append(info, attachmentContent)...)
  57. // } else {
  58. for _, p := range msg.Parts {
  59. part, err := p.ValueByDiscriminator()
  60. if err != nil {
  61. continue //TODO: handle error?
  62. }
  63. switch part.(type) {
  64. case client.MessagePartText:
  65. textPart := part.(client.MessagePartText)
  66. text := toMarkdown(textPart.Text, width)
  67. content = style.Render(lipgloss.JoinVertical(lipgloss.Left, text, info))
  68. }
  69. }
  70. return styles.ForceReplaceBackgroundWithLipgloss(content, t.Background())
  71. }
  72. func convertToMap(input *any) (map[string]any, bool) {
  73. if input == nil {
  74. return nil, false // Handle nil pointer
  75. }
  76. value := *input // Dereference the pointer to get the interface value
  77. m, ok := value.(map[string]any) // Type assertion
  78. return m, ok
  79. }
  80. func renderAssistantMessage(
  81. msg client.MessageInfo,
  82. width int,
  83. showToolMessages bool,
  84. ) string {
  85. t := theme.CurrentTheme()
  86. style := styles.BaseStyle().
  87. BorderLeft(true).
  88. Foreground(t.TextMuted()).
  89. BorderForeground(t.Primary()).
  90. BorderStyle(lipgloss.ThickBorder())
  91. messages := []string{}
  92. timestamp := time.UnixMilli(int64(msg.Metadata.Time.Created)).Local().Format("02 Jan 2006 03:04 PM")
  93. if time.Now().Format("02 Jan 2006") == timestamp[:11] {
  94. timestamp = timestamp[12:]
  95. }
  96. modelName := msg.Metadata.Assistant.ModelID
  97. info := styles.Padded().
  98. Foreground(t.TextMuted()).
  99. Render(fmt.Sprintf("%s (%s)", modelName, timestamp))
  100. for _, p := range msg.Parts {
  101. part, err := p.ValueByDiscriminator()
  102. if err != nil {
  103. continue //TODO: handle error?
  104. }
  105. switch part.(type) {
  106. // case client.MessagePartReasoning:
  107. // reasoningPart := part.(client.MessagePartReasoning)
  108. case client.MessagePartText:
  109. textPart := part.(client.MessagePartText)
  110. text := toMarkdown(textPart.Text, width)
  111. content := style.Render(lipgloss.JoinVertical(lipgloss.Left, text, info))
  112. message := styles.ForceReplaceBackgroundWithLipgloss(content, t.Background())
  113. messages = append(messages, message)
  114. case client.MessagePartToolInvocation:
  115. if !showToolMessages {
  116. continue
  117. }
  118. toolInvocationPart := part.(client.MessagePartToolInvocation)
  119. toolCall, _ := toolInvocationPart.ToolInvocation.AsMessageToolInvocationToolCall()
  120. var result *string
  121. resultPart, resultError := toolInvocationPart.ToolInvocation.AsMessageToolInvocationToolResult()
  122. if resultError == nil {
  123. result = &resultPart.Result
  124. }
  125. metadata := map[string]any{}
  126. if _, ok := msg.Metadata.Tool[toolCall.ToolCallId]; ok {
  127. metadata = msg.Metadata.Tool[toolCall.ToolCallId].(map[string]any)
  128. }
  129. message := renderToolInvocation(toolCall, result, metadata, width)
  130. messages = append(messages, message)
  131. }
  132. }
  133. return strings.Join(messages, "\n\n")
  134. }
  135. func renderToolInvocation(toolCall client.MessageToolInvocationToolCall, result *string, metadata map[string]any, width int) string {
  136. t := theme.CurrentTheme()
  137. style := styles.BaseStyle().
  138. BorderLeft(true).
  139. Foreground(t.TextMuted()).
  140. BorderForeground(t.TextMuted()).
  141. BorderStyle(lipgloss.ThickBorder())
  142. toolName := renderToolName(toolCall.ToolName)
  143. var toolArgs []string
  144. toolMap, _ := convertToMap(toolCall.Args)
  145. for _, arg := range toolMap {
  146. toolArgs = append(toolArgs, fmt.Sprintf("%v", arg))
  147. }
  148. params := renderParams(width-lipgloss.Width(toolName)-1, toolArgs...)
  149. title := styles.Padded().Render(fmt.Sprintf("%s: %s", toolName, params))
  150. finished := result != nil
  151. body := styles.Padded().Render("In progress...")
  152. if finished {
  153. body = *result
  154. }
  155. if toolCall.ToolName == "opencode_edit" {
  156. filename := toolMap["filePath"].(string)
  157. title = styles.Padded().Render(fmt.Sprintf("%s: %s", toolName, filename))
  158. if finished && metadata["diff"] != nil {
  159. patch := metadata["diff"].(string)
  160. formattedDiff, _ := diff.FormatDiff(patch, diff.WithTotalWidth(width))
  161. body = strings.TrimSpace(formattedDiff)
  162. }
  163. return style.Render(lipgloss.JoinVertical(lipgloss.Left,
  164. title,
  165. body,
  166. ))
  167. } else if toolCall.ToolName == "opencode_read" {
  168. filename := toolMap["filePath"].(string)
  169. ext := filepath.Ext(filename)
  170. if ext == "" {
  171. ext = ""
  172. } else {
  173. ext = strings.ToLower(ext[1:])
  174. }
  175. if finished {
  176. if metadata["preview"] != nil {
  177. body = metadata["preview"].(string)
  178. }
  179. body = fmt.Sprintf("```%s\n%s\n```", ext, truncateHeight(body, 10))
  180. body = toMarkdown(body, width)
  181. }
  182. content := style.Render(lipgloss.JoinVertical(lipgloss.Left,
  183. title,
  184. body,
  185. ))
  186. return styles.ForceReplaceBackgroundWithLipgloss(content, t.Background())
  187. }
  188. // Default rendering
  189. if finished {
  190. body = styles.Padded().Render(truncateHeight(strings.TrimSpace(body), 10))
  191. body = toMarkdown(body, width)
  192. }
  193. content := style.Render(lipgloss.JoinVertical(lipgloss.Left,
  194. title,
  195. body,
  196. ))
  197. return styles.ForceReplaceBackgroundWithLipgloss(content, t.Background())
  198. }
  199. func renderToolName(name string) string {
  200. switch name {
  201. // case agent.AgentToolName:
  202. // return "Task"
  203. case "opencode_ls":
  204. return "List"
  205. default:
  206. normalizedName := name
  207. if strings.HasPrefix(name, "opencode_") {
  208. normalizedName = strings.TrimPrefix(name, "opencode_")
  209. }
  210. return cases.Title(language.Und).String(normalizedName)
  211. }
  212. }
  213. func renderToolAction(name string) string {
  214. switch name {
  215. // case agent.AgentToolName:
  216. // return "Preparing prompt..."
  217. case "opencode_bash":
  218. return "Building command..."
  219. case "opencode_edit":
  220. return "Preparing edit..."
  221. case "opencode_fetch":
  222. return "Writing fetch..."
  223. case "opencode_glob":
  224. return "Finding files..."
  225. case "opencode_grep":
  226. return "Searching content..."
  227. case "opencode_ls":
  228. return "Listing directory..."
  229. case "opencode_read":
  230. return "Reading file..."
  231. case "opencode_write":
  232. return "Preparing write..."
  233. case "opencode_patch":
  234. return "Preparing patch..."
  235. case "opencode_batch":
  236. return "Running batch operations..."
  237. }
  238. return "Working..."
  239. }
  240. // renders params, params[0] (params[1]=params[2] ....)
  241. func renderParams(paramsWidth int, params ...string) string {
  242. if len(params) == 0 {
  243. return ""
  244. }
  245. mainParam := params[0]
  246. if len(mainParam) > paramsWidth {
  247. mainParam = mainParam[:paramsWidth-3] + "..."
  248. }
  249. if len(params) == 1 {
  250. return mainParam
  251. }
  252. otherParams := params[1:]
  253. // create pairs of key/value
  254. // if odd number of params, the last one is a key without value
  255. if len(otherParams)%2 != 0 {
  256. otherParams = append(otherParams, "")
  257. }
  258. parts := make([]string, 0, len(otherParams)/2)
  259. for i := 0; i < len(otherParams); i += 2 {
  260. key := otherParams[i]
  261. value := otherParams[i+1]
  262. if value == "" {
  263. continue
  264. }
  265. parts = append(parts, fmt.Sprintf("%s=%s", key, value))
  266. }
  267. partsRendered := strings.Join(parts, ", ")
  268. remainingWidth := paramsWidth - lipgloss.Width(partsRendered) - 5 // for the space
  269. if remainingWidth < 30 {
  270. // No space for the params, just show the main
  271. return mainParam
  272. }
  273. if len(parts) > 0 {
  274. mainParam = fmt.Sprintf("%s (%s)", mainParam, strings.Join(parts, ", "))
  275. }
  276. return ansi.Truncate(mainParam, paramsWidth, "...")
  277. }
  278. func renderToolParams(paramWidth int, toolCall any) string {
  279. params := ""
  280. switch toolCall {
  281. // // case agent.AgentToolName:
  282. // // var params agent.AgentParams
  283. // // json.Unmarshal([]byte(toolCall.Input), &params)
  284. // // prompt := strings.ReplaceAll(params.Prompt, "\n", " ")
  285. // // return renderParams(paramWidth, prompt)
  286. // case "bash":
  287. // var params tools.BashParams
  288. // json.Unmarshal([]byte(toolCall.Input), &params)
  289. // command := strings.ReplaceAll(params.Command, "\n", " ")
  290. // return renderParams(paramWidth, command)
  291. // case "edit":
  292. // var params tools.EditParams
  293. // json.Unmarshal([]byte(toolCall.Input), &params)
  294. // filePath := removeWorkingDirPrefix(params.FilePath)
  295. // return renderParams(paramWidth, filePath)
  296. // case "fetch":
  297. // var params tools.FetchParams
  298. // json.Unmarshal([]byte(toolCall.Input), &params)
  299. // url := params.URL
  300. // toolParams := []string{
  301. // url,
  302. // }
  303. // if params.Format != "" {
  304. // toolParams = append(toolParams, "format", params.Format)
  305. // }
  306. // if params.Timeout != 0 {
  307. // toolParams = append(toolParams, "timeout", (time.Duration(params.Timeout) * time.Second).String())
  308. // }
  309. // return renderParams(paramWidth, toolParams...)
  310. // case tools.GlobToolName:
  311. // var params tools.GlobParams
  312. // json.Unmarshal([]byte(toolCall.Input), &params)
  313. // pattern := params.Pattern
  314. // toolParams := []string{
  315. // pattern,
  316. // }
  317. // if params.Path != "" {
  318. // toolParams = append(toolParams, "path", params.Path)
  319. // }
  320. // return renderParams(paramWidth, toolParams...)
  321. // case tools.GrepToolName:
  322. // var params tools.GrepParams
  323. // json.Unmarshal([]byte(toolCall.Input), &params)
  324. // pattern := params.Pattern
  325. // toolParams := []string{
  326. // pattern,
  327. // }
  328. // if params.Path != "" {
  329. // toolParams = append(toolParams, "path", params.Path)
  330. // }
  331. // if params.Include != "" {
  332. // toolParams = append(toolParams, "include", params.Include)
  333. // }
  334. // if params.LiteralText {
  335. // toolParams = append(toolParams, "literal", "true")
  336. // }
  337. // return renderParams(paramWidth, toolParams...)
  338. // case tools.LSToolName:
  339. // var params tools.LSParams
  340. // json.Unmarshal([]byte(toolCall.Input), &params)
  341. // path := params.Path
  342. // if path == "" {
  343. // path = "."
  344. // }
  345. // return renderParams(paramWidth, path)
  346. // case tools.ViewToolName:
  347. // var params tools.ViewParams
  348. // json.Unmarshal([]byte(toolCall.Input), &params)
  349. // filePath := removeWorkingDirPrefix(params.FilePath)
  350. // toolParams := []string{
  351. // filePath,
  352. // }
  353. // if params.Limit != 0 {
  354. // toolParams = append(toolParams, "limit", fmt.Sprintf("%d", params.Limit))
  355. // }
  356. // if params.Offset != 0 {
  357. // toolParams = append(toolParams, "offset", fmt.Sprintf("%d", params.Offset))
  358. // }
  359. // return renderParams(paramWidth, toolParams...)
  360. // case tools.WriteToolName:
  361. // var params tools.WriteParams
  362. // json.Unmarshal([]byte(toolCall.Input), &params)
  363. // filePath := removeWorkingDirPrefix(params.FilePath)
  364. // return renderParams(paramWidth, filePath)
  365. // case tools.BatchToolName:
  366. // var params tools.BatchParams
  367. // json.Unmarshal([]byte(toolCall.Input), &params)
  368. // return renderParams(paramWidth, fmt.Sprintf("%d parallel calls", len(params.Calls)))
  369. // default:
  370. // input := strings.ReplaceAll(toolCall, "\n", " ")
  371. // params = renderParams(paramWidth, input)
  372. }
  373. return params
  374. }
  375. func truncateHeight(content string, height int) string {
  376. lines := strings.Split(content, "\n")
  377. if len(lines) > height {
  378. return strings.Join(lines[:height], "\n")
  379. }
  380. return content
  381. }
  382. func renderToolResponse(toolCall any, response any, width int) string {
  383. return ""
  384. // t := theme.CurrentTheme()
  385. // baseStyle := styles.BaseStyle()
  386. //
  387. // if response.IsError {
  388. // errContent := fmt.Sprintf("Error: %s", strings.ReplaceAll(response.Content, "\n", " "))
  389. // errContent = ansi.Truncate(errContent, width-1, "...")
  390. // return baseStyle.
  391. // Width(width).
  392. // Foreground(t.Error()).
  393. // Render(errContent)
  394. // }
  395. //
  396. // resultContent := truncateHeight(response.Content, maxResultHeight)
  397. // switch toolCall.Name {
  398. // case agent.AgentToolName:
  399. // return styles.ForceReplaceBackgroundWithLipgloss(
  400. // toMarkdown(resultContent, false, width),
  401. // t.Background(),
  402. // )
  403. // case tools.BashToolName:
  404. // resultContent = fmt.Sprintf("```bash\n%s\n```", resultContent)
  405. // return styles.ForceReplaceBackgroundWithLipgloss(
  406. // toMarkdown(resultContent, width),
  407. // t.Background(),
  408. // )
  409. // case tools.EditToolName:
  410. // metadata := tools.EditResponseMetadata{}
  411. // json.Unmarshal([]byte(response.Metadata), &metadata)
  412. // formattedDiff, _ := diff.FormatDiff(metadata.Diff, diff.WithTotalWidth(width))
  413. // return formattedDiff
  414. // case tools.FetchToolName:
  415. // var params tools.FetchParams
  416. // json.Unmarshal([]byte(toolCall.Input), &params)
  417. // mdFormat := "markdown"
  418. // switch params.Format {
  419. // case "text":
  420. // mdFormat = "text"
  421. // case "html":
  422. // mdFormat = "html"
  423. // }
  424. // resultContent = fmt.Sprintf("```%s\n%s\n```", mdFormat, resultContent)
  425. // return styles.ForceReplaceBackgroundWithLipgloss(
  426. // toMarkdown(resultContent, width),
  427. // t.Background(),
  428. // )
  429. // case tools.GlobToolName:
  430. // return baseStyle.Width(width).Foreground(t.TextMuted()).Render(resultContent)
  431. // case tools.GrepToolName:
  432. // return baseStyle.Width(width).Foreground(t.TextMuted()).Render(resultContent)
  433. // case tools.LSToolName:
  434. // return baseStyle.Width(width).Foreground(t.TextMuted()).Render(resultContent)
  435. // case tools.ViewToolName:
  436. // metadata := tools.ViewResponseMetadata{}
  437. // json.Unmarshal([]byte(response.Metadata), &metadata)
  438. // ext := filepath.Ext(metadata.FilePath)
  439. // if ext == "" {
  440. // ext = ""
  441. // } else {
  442. // ext = strings.ToLower(ext[1:])
  443. // }
  444. // resultContent = fmt.Sprintf("```%s\n%s\n```", ext, truncateHeight(metadata.Content, maxResultHeight))
  445. // return styles.ForceReplaceBackgroundWithLipgloss(
  446. // toMarkdown(resultContent, width),
  447. // t.Background(),
  448. // )
  449. // case tools.WriteToolName:
  450. // params := tools.WriteParams{}
  451. // json.Unmarshal([]byte(toolCall.Input), &params)
  452. // metadata := tools.WriteResponseMetadata{}
  453. // json.Unmarshal([]byte(response.Metadata), &metadata)
  454. // ext := filepath.Ext(params.FilePath)
  455. // if ext == "" {
  456. // ext = ""
  457. // } else {
  458. // ext = strings.ToLower(ext[1:])
  459. // }
  460. // resultContent = fmt.Sprintf("```%s\n%s\n```", ext, truncateHeight(params.Content, maxResultHeight))
  461. // return styles.ForceReplaceBackgroundWithLipgloss(
  462. // toMarkdown(resultContent, width),
  463. // t.Background(),
  464. // )
  465. // case tools.BatchToolName:
  466. // var batchResult tools.BatchResult
  467. // if err := json.Unmarshal([]byte(resultContent), &batchResult); err != nil {
  468. // return baseStyle.Width(width).Foreground(t.Error()).Render(fmt.Sprintf("Error parsing batch result: %s", err))
  469. // }
  470. //
  471. // var toolCalls []string
  472. // for i, result := range batchResult.Results {
  473. // toolName := renderToolName(result.ToolName)
  474. //
  475. // // Format the tool input as a string
  476. // inputStr := string(result.ToolInput)
  477. //
  478. // // Format the result
  479. // var resultStr string
  480. // if result.Error != "" {
  481. // resultStr = fmt.Sprintf("Error: %s", result.Error)
  482. // } else {
  483. // var toolResponse tools.ToolResponse
  484. // if err := json.Unmarshal(result.Result, &toolResponse); err != nil {
  485. // resultStr = "Error parsing tool response"
  486. // } else {
  487. // resultStr = truncateHeight(toolResponse.Content, 3)
  488. // }
  489. // }
  490. //
  491. // // Format the tool call
  492. // toolCall := fmt.Sprintf("%d. %s: %s\n %s", i+1, toolName, inputStr, resultStr)
  493. // toolCalls = append(toolCalls, toolCall)
  494. // }
  495. //
  496. // return baseStyle.Width(width).Foreground(t.TextMuted()).Render(strings.Join(toolCalls, "\n\n"))
  497. // default:
  498. // resultContent = fmt.Sprintf("```text\n%s\n```", resultContent)
  499. // return styles.ForceReplaceBackgroundWithLipgloss(
  500. // toMarkdown(resultContent, width),
  501. // t.Background(),
  502. // )
  503. // }
  504. }
  505. // func renderToolMessage(
  506. // toolCall message.ToolCall,
  507. // allMessages []message.Message,
  508. // messagesService message.Service,
  509. // focusedUIMessageId string,
  510. // nested bool,
  511. // width int,
  512. // position int,
  513. // ) string {
  514. // if nested {
  515. // width = width - 3
  516. // }
  517. //
  518. // t := theme.CurrentTheme()
  519. // baseStyle := styles.BaseStyle()
  520. //
  521. // style := baseStyle.
  522. // Width(width - 1).
  523. // BorderLeft(true).
  524. // BorderStyle(lipgloss.ThickBorder()).
  525. // PaddingLeft(1).
  526. // BorderForeground(t.TextMuted())
  527. //
  528. // response := findToolResponse(toolCall.ID, allMessages)
  529. // toolNameText := baseStyle.Foreground(t.TextMuted()).
  530. // Render(fmt.Sprintf("%s: ", renderToolName(toolCall.Name)))
  531. //
  532. // if !toolCall.Finished {
  533. // // Get a brief description of what the tool is doing
  534. // toolAction := renderToolAction(toolCall.Name)
  535. //
  536. // progressText := baseStyle.
  537. // Width(width - 2 - lipgloss.Width(toolNameText)).
  538. // Foreground(t.TextMuted()).
  539. // Render(fmt.Sprintf("%s", toolAction))
  540. //
  541. // content := style.Render(lipgloss.JoinHorizontal(lipgloss.Left, toolNameText, progressText))
  542. // return content
  543. // }
  544. //
  545. // params := renderToolParams(width-1-lipgloss.Width(toolNameText), toolCall)
  546. // responseContent := ""
  547. // if response != nil {
  548. // responseContent = renderToolResponse(toolCall, *response, width-2)
  549. // responseContent = strings.TrimSuffix(responseContent, "\n")
  550. // } else {
  551. // responseContent = baseStyle.
  552. // Italic(true).
  553. // Width(width - 2).
  554. // Foreground(t.TextMuted()).
  555. // Render("Waiting for response...")
  556. // }
  557. //
  558. // parts := []string{}
  559. // if !nested {
  560. // formattedParams := baseStyle.
  561. // Width(width - 2 - lipgloss.Width(toolNameText)).
  562. // Foreground(t.TextMuted()).
  563. // Render(params)
  564. //
  565. // parts = append(parts, lipgloss.JoinHorizontal(lipgloss.Left, toolNameText, formattedParams))
  566. // } else {
  567. // prefix := baseStyle.
  568. // Foreground(t.TextMuted()).
  569. // Render(" └ ")
  570. // formattedParams := baseStyle.
  571. // Width(width - 2 - lipgloss.Width(toolNameText)).
  572. // Foreground(t.TextMuted()).
  573. // Render(params)
  574. // parts = append(parts, lipgloss.JoinHorizontal(lipgloss.Left, prefix, toolNameText, formattedParams))
  575. // }
  576. //
  577. // // if toolCall.Name == agent.AgentToolName {
  578. // // taskMessages, _ := messagesService.List(context.Background(), toolCall.ID)
  579. // // toolCalls := []message.ToolCall{}
  580. // // for _, v := range taskMessages {
  581. // // toolCalls = append(toolCalls, v.ToolCalls()...)
  582. // // }
  583. // // for _, call := range toolCalls {
  584. // // rendered := renderToolMessage(call, []message.Message{}, messagesService, focusedUIMessageId, true, width, 0)
  585. // // parts = append(parts, rendered.content)
  586. // // }
  587. // // }
  588. // if responseContent != "" && !nested {
  589. // parts = append(parts, responseContent)
  590. // }
  591. //
  592. // content := style.Render(
  593. // lipgloss.JoinVertical(
  594. // lipgloss.Left,
  595. // parts...,
  596. // ),
  597. // )
  598. // if nested {
  599. // content = lipgloss.JoinVertical(
  600. // lipgloss.Left,
  601. // parts...,
  602. // )
  603. // }
  604. // return content
  605. // }