@@ -10,16 +10,50 @@ import (
1010func ConvertMessages (openAIMsgs []api.OpenAIMessage ) []api.CCMessage {
1111 var ccMsgs []api.CCMessage
1212 for _ , m := range openAIMsgs {
13+ contentParts := parseContent (m .Content )
1314 ccMsgs = append (ccMsgs , api.CCMessage {
14- Role : m .Role ,
15- Content : []api.CCContentPart {
16- {Type : "text" , Text : m .Content },
17- },
15+ Role : m .Role ,
16+ Content : contentParts ,
1817 })
1918 }
2019 return ccMsgs
2120}
2221
22+ func parseContent (content interface {}) []api.CCContentPart {
23+ switch v := content .(type ) {
24+ case string :
25+ if v == "" {
26+ return nil
27+ }
28+ return []api.CCContentPart {{Type : "text" , Text : v }}
29+ case []any :
30+ var parts []api.CCContentPart
31+ for _ , part := range v {
32+ if partMap , ok := part .(map [string ]any ); ok {
33+ if typ , ok := partMap ["type" ].(string ); ok {
34+ p := api.CCContentPart {Type : typ }
35+ if text , ok := partMap ["text" ].(string ); ok {
36+ p .Text = text
37+ }
38+ // Note: CommandCode API may not support image_url
39+ // For now, we skip image parts
40+ if imgURL , ok := partMap ["image_url" ].(map [string ]any ); ok {
41+ if url , ok := imgURL ["url" ].(string ); ok {
42+ // Try to extract text from image (e.g., base64 data)
43+ // or just include the URL as text
44+ p .Text = p .Text + "\n [Image URL: " + url + "]"
45+ }
46+ }
47+ parts = append (parts , p )
48+ }
49+ }
50+ }
51+ return parts
52+ default :
53+ return nil
54+ }
55+ }
56+
2357// Extract system message and remaining messages
2458func ExtractSystem (msgs []api.OpenAIMessage ) (string , []api.OpenAIMessage ) {
2559 var system strings.Builder
@@ -29,7 +63,9 @@ func ExtractSystem(msgs []api.OpenAIMessage) (string, []api.OpenAIMessage) {
2963 if system .Len () > 0 {
3064 system .WriteString ("\n " )
3165 }
32- system .WriteString (m .Content )
66+ if contentStr , ok := m .Content .(string ); ok {
67+ system .WriteString (contentStr )
68+ }
3369 } else {
3470 rest = append (rest , m )
3571 }
0 commit comments