Skip to content

Commit b3214b8

Browse files
committed
make Content directory and move related files
1 parent 69af746 commit b3214b8

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

Sources/AnthropicSwiftSDK/Entity/Content.swift renamed to Sources/AnthropicSwiftSDK/Entity/Content/Content.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public enum ContentType: String {
1717
case toolUse = "tool_use"
1818
/// result of tool use
1919
case toolResult = "tool_result"
20+
/// document, like pdf
21+
case document
2022
}
2123

2224
/// The content of message.
@@ -31,18 +33,21 @@ public enum Content {
3133
case image(ImageContent)
3234
case toolUse(ToolUseContent)
3335
case toolResult(ToolResultContent)
36+
case document(DocumentContent)
3437

3538
/// The type of content block.
3639
public var contentType: ContentType {
3740
switch self {
3841
case .text:
39-
return ContentType.text
42+
return .text
4043
case .image:
41-
return ContentType.image
44+
return .image
4245
case .toolUse:
43-
return ContentType.toolUse
46+
return .toolUse
4447
case .toolResult:
45-
return ContentType.toolResult
48+
return .toolResult
49+
case .document:
50+
return .document
4651
}
4752
}
4853
}
@@ -92,6 +97,10 @@ extension Content: Encodable {
9297
if toolResult.isError != nil {
9398
try container.encode(toolResult.isError, forKey: .isError)
9499
}
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)
95104
}
96105
}
97106
}
@@ -114,6 +123,9 @@ extension Content: Decodable {
114123
self = .toolUse(content)
115124
case .toolResult:
116125
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)
117129
case .none:
118130
throw ClientError.failedToParseContentType(contentTypeString)
119131
}

0 commit comments

Comments
 (0)