Sample code
import Foundation
import FoundationModels
@available(macOS 26.0, *)
func testTranscriptAPIs() {
print("Testing FoundationModels Transcript APIs on macOS 26...")
// Test 1: Try to create a simple Transcript with entries
print("\n=== Test 1: Transcript.init(entries:) ===")
do {
// Create some basic transcript entries
let textSegment = Transcript.TextSegment(content: "Hello world")
let prompt = Transcript.Prompt(segments: [.text(textSegment)])
let entries: [Transcript.Entry] = [.prompt(prompt)]
// This should fail if the initializer was removed
let transcript = Transcript(entries: entries)
print("✅ Transcript.init(entries:) is available")
print(" Created transcript with \(transcript.entries.count) entries")
} catch {
print("❌ Transcript.init(entries:) failed: \(error)")
}
// Test 2: Try to create ToolCall - this will likely fail
print("\n=== Test 2: Transcript.ToolCall construction ===")
// Note: This test is commented out because the compiler already shows it's not available
print("❌ Transcript.ToolCall cannot be constructed (no accessible initializers)")
print(" This confirms the API changed in beta 2")
// Test 3: Try alternative LanguageModelSession initializers
print("\n=== Test 3: LanguageModelSession initializers ===")
do {
let session1 = LanguageModelSession(
guardrails: LanguageModelSession.Guardrails.default,
instructions: "Test instructions"
)
print("✅ LanguageModelSession.init(guardrails:instructions:) is available")
let session2 = LanguageModelSession(
guardrails: LanguageModelSession.Guardrails.default,
tools: [],
instructions: "Test with tools"
)
print("✅ LanguageModelSession.init(guardrails:tools:instructions:) is available")
} catch {
print("❌ LanguageModelSession alternative initializers failed: \(error)")
}
// Test 4: Try creating basic transcript components that should work
print("\n=== Test 4: Basic Transcript components ===")
do {
let textSegment = Transcript.TextSegment(content: "Test content")
print("✅ Transcript.TextSegment.init(content:) works")
let prompt = Transcript.Prompt(segments: [.text(textSegment)])
print("✅ Transcript.Prompt.init(segments:) works")
let response = Transcript.Response(assetIDs: [], segments: [.text(textSegment)])
print("✅ Transcript.Response.init(assetIDs:segments:) works")
} catch {
print("❌ Basic component creation failed: \(error)")
}
print("\n✅ Test completed - API availability confirmed")
}
// Only run if this is the main module
if CommandLine.arguments.count > 0 && CommandLine.arguments[0].contains("test_transcript_api") {
if #available(macOS 26.0, *) {
testTranscriptAPIs()
} else {
print("This test requires macOS 26.0 or later")
}
}