@@ -17,6 +17,8 @@ public enum ContentType: String {
17
17
case toolUse = " tool_use "
18
18
/// result of tool use
19
19
case toolResult = " tool_result "
20
+ /// document, like pdf
21
+ case document
20
22
}
21
23
22
24
/// The content of message.
@@ -31,18 +33,21 @@ public enum Content {
31
33
case image( ImageContent )
32
34
case toolUse( ToolUseContent )
33
35
case toolResult( ToolResultContent )
36
+ case document( DocumentContent )
34
37
35
38
/// The type of content block.
36
39
public var contentType : ContentType {
37
40
switch self {
38
41
case . text:
39
- return ContentType . text
42
+ return . text
40
43
case . image:
41
- return ContentType . image
44
+ return . image
42
45
case . toolUse:
43
- return ContentType . toolUse
46
+ return . toolUse
44
47
case . toolResult:
45
- return ContentType . toolResult
48
+ return . toolResult
49
+ case . document:
50
+ return . document
46
51
}
47
52
}
48
53
}
@@ -92,6 +97,10 @@ extension Content: Encodable {
92
97
if toolResult. isError != nil {
93
98
try container. encode ( toolResult. isError, forKey: . isError)
94
99
}
100
+ case let . document( document) :
101
+ var container = encoder. container ( keyedBy: CodingKeys . self)
102
+ try container. encode ( self . contentType. rawValue, forKey: . type)
103
+ try container. encode ( document, forKey: . source)
95
104
}
96
105
}
97
106
}
@@ -114,6 +123,9 @@ extension Content: Decodable {
114
123
self = . toolUse( content)
115
124
case . toolResult:
116
125
fatalError ( " ContentType: `tool_result` is only used by user, not by assistant " )
126
+ case . document:
127
+ let document = try container. decode ( DocumentContent . self, forKey: . source)
128
+ self = . document( document)
117
129
case . none:
118
130
throw ClientError . failedToParseContentType ( contentTypeString)
119
131
}
0 commit comments