@@ -50,13 +50,23 @@ func ConvertMessages(openAIMsgs []api.OpenAIMessage) []api.CCMessage {
5050
5151 if m .Role == "assistant" && len (m .ToolCalls ) > 0 {
5252 contentParts := parseContent (m .Content , toolNames )
53+ addedTools := map [string ]bool {}
54+ for _ , part := range contentParts {
55+ if part .Type == "tool-call" && part .ToolCallID != nil {
56+ addedTools [* part .ToolCallID ] = true
57+ }
58+ }
5359 for _ , tc := range m .ToolCalls {
60+ if addedTools [tc .ID ] {
61+ continue
62+ }
5463 contentParts = append (contentParts , api.CCContentPart {
55- Type : "tool_use " ,
56- ID : strPtr (tc .ID ),
57- Name : strPtr (tc .Function .Name ),
58- Input : parseToolInput (tc .Function .Arguments ),
64+ Type : "tool-call " ,
65+ ToolCallID : strPtr (tc .ID ),
66+ ToolName : strPtr (tc .Function .Name ),
67+ Input : parseToolInput (tc .Function .Arguments ),
5968 })
69+ addedTools [tc .ID ] = true
6070 }
6171 ccMsgs = append (ccMsgs , api.CCMessage {Role : m .Role , Content : contentParts })
6272 continue
@@ -218,24 +228,31 @@ func parseContent(content interface{}, toolNames map[string]string) []api.CCCont
218228 if text := contentPartToString (partMap ); text != "" {
219229 parts = append (parts , api.CCContentPart {Type : "text" , Text : strPtr (text )})
220230 }
221- case "tool_use" :
231+ case "tool_use" , "tool-call" :
222232 id , _ := partMap ["id" ].(string )
223- name , _ := partMap ["name" ].(string )
224- if id != "" && name != "" {
225- toolNames [id ] = name
233+ if id == "" {
234+ id , _ = partMap ["toolCallId" ].(string )
235+ }
236+ if id == "" {
237+ id , _ = partMap ["tool_use_id" ].(string )
226238 }
227- parts = append (parts , api.CCContentPart {Type : "tool_use" , ID : strPtr (id ), Name : strPtr (name ), Input : partMap ["input" ]})
228- case "tool-call" :
229- id , _ := partMap ["id" ].(string )
230239 name , _ := partMap ["name" ].(string )
240+ if name == "" {
241+ name , _ = partMap ["toolName" ].(string )
242+ }
231243 if id != "" && name != "" {
232244 toolNames [id ] = name
233245 }
234246 input := partMap ["input" ]
235247 if input == nil {
236248 input = partMap ["arguments" ]
237249 }
238- parts = append (parts , api.CCContentPart {Type : "tool-call" , ID : strPtr (id ), Name : strPtr (name ), Input : input })
250+ parts = append (parts , api.CCContentPart {
251+ Type : "tool-call" ,
252+ ToolCallID : strPtr (id ),
253+ ToolName : strPtr (name ),
254+ Input : input ,
255+ })
239256 case "tool_result" , "tool-result" :
240257 toolID , _ := partMap ["tool_use_id" ].(string )
241258 if toolID == "" {
0 commit comments