message.go 20 KB

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