iCloud Backup, better chatview exp. bugfixes++

This commit is contained in:
2026-02-27 14:05:11 +01:00
parent 3997f3feee
commit e9d0ad3c66
11 changed files with 634 additions and 30 deletions

View File

@@ -318,7 +318,41 @@ class AnthropicProvider: AIProvider {
conversationMessages.append(["role": "assistant", "content": msg["content"] as? String ?? ""])
}
} else {
conversationMessages.append(["role": role, "content": msg["content"] as? String ?? ""])
// Content may be a String (plain text) or an Array (image/multipart blocks)
if let contentArray = msg["content"] as? [[String: Any]] {
// Convert image_url blocks (OpenAI format) to Anthropic image blocks
let anthropicBlocks: [[String: Any]] = contentArray.compactMap { block in
let type = block["type"] as? String ?? ""
if type == "text" {
return block
} else if type == "image_url",
let imageUrl = block["image_url"] as? [String: Any],
let url = imageUrl["url"] as? String,
url.hasPrefix("data:") {
// data:<mediaType>;base64,<data>
let withoutData = url.dropFirst(5) // strip "data:"
guard let semicolon = withoutData.firstIndex(of: ";"),
let comma = withoutData.firstIndex(of: ",") else { return nil }
let mediaType = String(withoutData[withoutData.startIndex..<semicolon])
let base64Data = String(withoutData[withoutData.index(after: comma)...])
return [
"type": "image",
"source": [
"type": "base64",
"media_type": mediaType,
"data": base64Data
]
]
}
return nil
}
if !anthropicBlocks.isEmpty {
conversationMessages.append(["role": role, "content": anthropicBlocks])
}
} else {
let content = (msg["content"] as? String ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
conversationMessages.append(["role": role, "content": content.isEmpty ? "[Image]" : content])
}
}
}
@@ -518,7 +552,9 @@ class AnthropicProvider: AIProvider {
if hasAttachments, let attachments = msg.attachments {
var contentBlocks: [[String: Any]] = []
contentBlocks.append(["type": "text", "text": msg.content])
if !msg.content.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
contentBlocks.append(["type": "text", "text": msg.content])
}
for attachment in attachments {
guard let data = attachment.data else { continue }
@@ -541,7 +577,8 @@ class AnthropicProvider: AIProvider {
}
apiMessages.append(["role": msg.role.rawValue, "content": contentBlocks])
} else {
apiMessages.append(["role": msg.role.rawValue, "content": msg.content])
let content = msg.content.trimmingCharacters(in: .whitespacesAndNewlines)
apiMessages.append(["role": msg.role.rawValue, "content": content.isEmpty ? "[Image]" : content])
}
}