Skip to content

Commit d96d498

Browse files
committed
feat: beta 2 removed .entries
1 parent 9c17b30 commit d96d498

File tree

5 files changed

+3
-65
lines changed

5 files changed

+3
-65
lines changed

build/AppleOnDeviceAI.swiftdoc

-820 Bytes
Binary file not shown.

build/AppleOnDeviceAI.swiftmodule

-2.62 KB
Binary file not shown.
-848 Bytes
Binary file not shown.

build/libappleai.dylib

-1.91 KB
Binary file not shown.

src/apple-ai.swift

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ private func debugPrintTranscript(_ transcript: Transcript, prompt: String) {
112112

113113
print("\n=== DEBUG: TRANSCRIPT SENT TO APPLE INTELLIGENCE ===")
114114
print("Current Prompt: '\(prompt)'")
115-
print("Transcript Entries (\(transcript.entries.count)):")
115+
print("Transcript Entries (\(transcript.count)):")
116116

117-
for (index, entry) in transcript.entries.enumerated() {
117+
for (index, entry) in transcript.enumerated() {
118118
print(" [\(index)] \(describeTranscriptEntry(entry))")
119119
}
120120
print("=== END DEBUG TRANSCRIPT ===\n")
@@ -599,15 +599,12 @@ private func convertOpenAIToolCalls(_ toolCalls: [[String: Any]]) -> Transcript.
599599
arguments = args
600600
}
601601

602-
// Get description if available (usually not present)
603-
let description = function["description"] as? String ?? ""
604-
605602
// Create GeneratedContent from arguments
606603
guard let content = createGeneratedContentFromDictionary(arguments) else { return nil }
607604

608605
// Use the unsafe tool call creation function
609606
return Transcript.ToolCall(
610-
id: id, toolName: name, arguments: content, description: description)
607+
id: id, toolName: name, arguments: content)
611608
}
612609

613610
return Transcript.ToolCalls(calls)
@@ -837,65 +834,6 @@ private struct AnyCodable: Codable {
837834
}
838835
}
839836

840-
// MARK: - Tool Call Mirror (because apple decided to make it private)
841-
842-
extension FoundationModels.Transcript.ToolCall {
843-
/// A private mirror of the memory layout of `FoundationModels.Transcript.ToolCall`.
844-
/// This struct must be kept in sync with the target system framework's version.
845-
private struct ToolCallMirror {
846-
// 0x00 – Swift String (16 B)
847-
let id: String
848-
// 0x10 – Swift String (16 B)
849-
let toolName: String
850-
// 0x20 – GeneratedContent (40 B)
851-
let arguments: GeneratedContent
852-
// 0x48 – Swift String (16 B)
853-
let description: String
854-
}
855-
856-
/// The private, unsafe initializer that performs the memory transmutation.
857-
private init(transmuting mirror: ToolCallMirror) {
858-
// This precondition is the critical safety guarantee.
859-
let mirrorSize = MemoryLayout<ToolCallMirror>.size
860-
let toolCallSize = MemoryLayout<Self>.size
861-
let mirrorAlignment = MemoryLayout<ToolCallMirror>.alignment
862-
let toolCallAlignment = MemoryLayout<Self>.alignment
863-
864-
precondition(
865-
mirrorSize == toolCallSize && mirrorAlignment == toolCallAlignment,
866-
"ToolCall.Mirror layout does not match FoundationModels.Transcript.ToolCall. Please update the private Mirror to match the system framework version."
867-
)
868-
869-
self = unsafeBitCast(mirror, to: Self.self)
870-
}
871-
872-
/// Creates an instance of `FoundationModels.Transcript.ToolCall`.
873-
///
874-
/// This initializer provides a safe, public interface for a type that lacks a public
875-
/// initializer, relying on a verified memory layout transmutation.
876-
///
877-
/// - Parameters:
878-
/// - id: The unique identifier for the tool call.
879-
/// - toolName: The name of the tool being called.
880-
/// - arguments: The arguments for the tool, as `GeneratedContent`.
881-
/// - description: An optional description for the tool call. Defaults to an empty string.
882-
public init(
883-
id: String,
884-
toolName: String,
885-
arguments: GeneratedContent,
886-
description: String = "" // Expose the new field with a safe default.
887-
) {
888-
let mirror = ToolCallMirror(
889-
id: id,
890-
toolName: toolName,
891-
arguments: arguments,
892-
description: description
893-
)
894-
895-
self.init(transmuting: mirror)
896-
}
897-
}
898-
899837
// MARK: - Structured Object Generation Support (Implementation)
900838

901839
#if canImport(FoundationModels)

0 commit comments

Comments
 (0)