1- // Copyright © 2025 Compiler, Inc. All rights reserved.
1+ // Copyright 2025 Compiler, Inc. All rights reserved.
22
33import Foundation
44
55public struct MessageDTO : Codable , Sendable {
66 public enum ContentType : String , Codable , Sendable {
77 case text = " text "
88 case imageUrl = " image_url "
9+ case toolCall = " tool_call "
10+ case toolCallResult = " tool_call_result "
911 }
1012
1113 public struct Content : Codable , Sendable {
1214 let type : ContentType
1315 let text : String ?
1416 let imageUrl : ImageUrl ?
17+ let toolCall : ToolCallDelta ?
1518
1619 private enum CodingKeys : String , CodingKey {
1720 case type
1821 case text
1922 case imageUrl = " image_url "
23+ case toolCall = " tool_call "
2024 }
2125 }
2226
@@ -34,9 +38,13 @@ public struct MessageDTO: Codable, Sendable {
3438 self . content = message. content. map { content in
3539 switch content {
3640 case . text( let text) :
37- return Content ( type: . text, text: text, imageUrl: nil )
41+ return Content ( type: . text, text: text, imageUrl: nil , toolCall : nil )
3842 case . image( let url) :
39- return Content ( type: . imageUrl, text: nil , imageUrl: ImageUrl ( url: url) )
43+ return Content ( type: . imageUrl, text: nil , imageUrl: ImageUrl ( url: url) , toolCall: nil )
44+ case . toolCall( let delta) :
45+ return Content ( type: . toolCall, text: nil , imageUrl: nil , toolCall: delta)
46+ case . toolCallResult( let result) :
47+ return Content ( type: . toolCallResult, text: result, imageUrl: nil , toolCall: nil )
4048 }
4149 }
4250 }
@@ -46,12 +54,16 @@ public struct MessageDTO: Codable, Sendable {
4654 id: id,
4755 role: . init( rawValue: role) ?? . user,
4856 content: content. compactMap { content in
49- if let text = content. text {
50- return . text( text)
51- } else if let imageUrl = content. imageUrl {
52- return . image( imageUrl. url)
57+ switch content. type {
58+ case . text:
59+ return content. text. map { . text( $0) }
60+ case . imageUrl:
61+ return content. imageUrl. map { . image( $0. url) }
62+ case . toolCall:
63+ return content. toolCall. map { . toolCall( $0) }
64+ case . toolCallResult:
65+ return content. text. map { . toolCallResult( $0) }
5366 }
54- return nil
5567 }
5668 )
5769 }
0 commit comments