@@ -21,12 +21,28 @@ func ConvertMessages(openAIMsgs []api.OpenAIMessage) []api.CCMessage {
2121 }
2222
2323 if m .Role == "tool" {
24+ toolName := m .Name
25+ if toolName == "" {
26+ toolName = toolNames [m .ToolCallID ]
27+ }
28+ if toolName == "" {
29+ toolName = "unknown"
30+ }
31+ contentStr := contentToString (m .Content )
32+ outputType := "text"
33+ if strings .HasPrefix (contentStr , "Error:" ) {
34+ outputType = "error-text"
35+ }
2436 ccMsgs = append (ccMsgs , api.CCMessage {
2537 Role : "tool" ,
2638 Content : []api.CCContentPart {{
27- Type : "tool_result" ,
28- ToolUseID : strPtr (m .ToolCallID ),
29- Content : contentToString (m .Content ),
39+ Type : "tool-result" ,
40+ ToolCallID : strPtr (m .ToolCallID ),
41+ ToolName : strPtr (toolName ),
42+ Output : & api.CCToolOutput {
43+ Type : outputType ,
44+ Value : contentStr ,
45+ },
3046 }},
3147 })
3248 continue
@@ -225,7 +241,30 @@ func parseContent(content interface{}, toolNames map[string]string) []api.CCCont
225241 if toolID == "" {
226242 toolID , _ = partMap ["toolCallId" ].(string )
227243 }
228- parts = append (parts , api.CCContentPart {Type : "tool_result" , ToolUseID : strPtr (toolID ), Content : contentPartToString (partMap ["content" ])})
244+ toolName , _ := partMap ["toolName" ].(string )
245+ if toolName == "" {
246+ toolName = toolNames [toolID ]
247+ }
248+ if toolName == "" {
249+ toolName = "unknown"
250+ }
251+ contentVal := contentPartToString (partMap ["content" ])
252+ if contentVal == "" {
253+ contentVal = contentPartToString (partMap ["output" ])
254+ }
255+ outputType := "text"
256+ if strings .HasPrefix (contentVal , "Error:" ) {
257+ outputType = "error-text"
258+ }
259+ parts = append (parts , api.CCContentPart {
260+ Type : "tool-result" ,
261+ ToolCallID : strPtr (toolID ),
262+ ToolName : strPtr (toolName ),
263+ Output : & api.CCToolOutput {
264+ Type : outputType ,
265+ Value : contentVal ,
266+ },
267+ })
229268 }
230269 }
231270 return parts
0 commit comments