@@ -10,6 +10,38 @@ import (
1010func ConvertMessages (openAIMsgs []api.OpenAIMessage ) []api.CCMessage {
1111 var ccMsgs []api.CCMessage
1212 for _ , m := range openAIMsgs {
13+ // Convert tool role to user with tool-result type
14+ if m .Role == "tool" {
15+ ccMsgs = append (ccMsgs , api.CCMessage {
16+ Role : "user" ,
17+ Content : []api.CCContentPart {{
18+ Type : "tool-result" ,
19+ ToolCallID : m .ToolCallID ,
20+ ToolName : m .Name ,
21+ Text : contentToString (m .Content ),
22+ }},
23+ })
24+ continue
25+ }
26+
27+ // Convert assistant with tool_calls
28+ if m .Role == "assistant" && len (m .ToolCalls ) > 0 {
29+ contentParts := parseContent (m .Content )
30+ for _ , tc := range m .ToolCalls {
31+ contentParts = append (contentParts , api.CCContentPart {
32+ Type : "tool_use" ,
33+ ToolCallID : tc .ID ,
34+ ToolName : tc .Function .Name ,
35+ Text : tc .Function .Arguments ,
36+ })
37+ }
38+ ccMsgs = append (ccMsgs , api.CCMessage {
39+ Role : m .Role ,
40+ Content : contentParts ,
41+ })
42+ continue
43+ }
44+
1345 contentParts := parseContent (m .Content )
1446 ccMsgs = append (ccMsgs , api.CCMessage {
1547 Role : m .Role ,
@@ -19,6 +51,22 @@ func ConvertMessages(openAIMsgs []api.OpenAIMessage) []api.CCMessage {
1951 return ccMsgs
2052}
2153
54+ func contentToString (content interface {}) string {
55+ switch v := content .(type ) {
56+ case string :
57+ return v
58+ case []any :
59+ for _ , part := range v {
60+ if partMap , ok := part .(map [string ]any ); ok {
61+ if text , ok := partMap ["text" ].(string ); ok {
62+ return text
63+ }
64+ }
65+ }
66+ }
67+ return ""
68+ }
69+
2270func parseContent (content interface {}) []api.CCContentPart {
2371 switch v := content .(type ) {
2472 case string :
0 commit comments