From 11ecbe26dc6f173e2d626ec7e723c6b90f8e4840 Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Tue, 1 Apr 2025 11:10:02 -0400 Subject: [PATCH 1/6] [Vertex AI] Enable `AccessLevelOnImport` and `InternalImportsByDefault` --- FirebaseVertexAI/Sources/GenerateContentResponse.swift | 2 +- FirebaseVertexAI/Sources/GenerativeAIRequest.swift | 2 +- .../Sources/PartsRepresentable+Image.swift | 7 +++++-- .../Types/Public/Imagen/ImagenImagesBlockedError.swift | 2 +- .../Types/Public/Imagen/ImagenInlineImage.swift | 2 +- FirebaseVertexAI/Sources/Types/Public/Part.swift | 2 +- FirebaseVertexAI/Sources/VertexAI.swift | 5 ++--- FirebaseVertexAI/Sources/VertexLog.swift | 3 +-- FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift | 6 +++--- FirebaseVertexAI/Tests/Unit/VertexComponentTests.swift | 6 +++--- Package.swift | 10 +++++++++- 11 files changed, 28 insertions(+), 19 deletions(-) diff --git a/FirebaseVertexAI/Sources/GenerateContentResponse.swift b/FirebaseVertexAI/Sources/GenerateContentResponse.swift index a8a11a21e1f..8d10d17ca7f 100644 --- a/FirebaseVertexAI/Sources/GenerateContentResponse.swift +++ b/FirebaseVertexAI/Sources/GenerateContentResponse.swift @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import Foundation +public import Foundation /// The model's response to a generate content request. @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) diff --git a/FirebaseVertexAI/Sources/GenerativeAIRequest.swift b/FirebaseVertexAI/Sources/GenerativeAIRequest.swift index 4f3291e1913..1df54df7cbf 100644 --- a/FirebaseVertexAI/Sources/GenerativeAIRequest.swift +++ b/FirebaseVertexAI/Sources/GenerativeAIRequest.swift @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import Foundation +public import Foundation @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) protocol GenerativeAIRequest: Sendable, Encodable { diff --git a/FirebaseVertexAI/Sources/PartsRepresentable+Image.swift b/FirebaseVertexAI/Sources/PartsRepresentable+Image.swift index 5bedeb8f3d1..1e3b7c04b39 100644 --- a/FirebaseVertexAI/Sources/PartsRepresentable+Image.swift +++ b/FirebaseVertexAI/Sources/PartsRepresentable+Image.swift @@ -12,11 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. +import CoreGraphics +import CoreImage import UniformTypeIdentifiers + #if canImport(UIKit) - import UIKit // For UIImage extensions. + public import UIKit // For UIImage extensions. #elseif canImport(AppKit) - import AppKit // For NSImage extensions. + public import AppKit // For NSImage extensions. #endif private let imageCompressionQuality: CGFloat = 0.8 diff --git a/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenImagesBlockedError.swift b/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenImagesBlockedError.swift index e23beab5248..6408c2dfeb9 100644 --- a/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenImagesBlockedError.swift +++ b/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenImagesBlockedError.swift @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import Foundation +public import Foundation /// An error that occurs when image generation fails due to all generated images being blocked. /// diff --git a/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenInlineImage.swift b/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenInlineImage.swift index a526dca3e56..3e2296f2e1f 100644 --- a/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenInlineImage.swift +++ b/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenInlineImage.swift @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import Foundation +public import Foundation /// An image generated by Imagen, represented as inline data. @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) diff --git a/FirebaseVertexAI/Sources/Types/Public/Part.swift b/FirebaseVertexAI/Sources/Types/Public/Part.swift index 4890b725f4d..7edccbb2381 100644 --- a/FirebaseVertexAI/Sources/Types/Public/Part.swift +++ b/FirebaseVertexAI/Sources/Types/Public/Part.swift @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import Foundation +public import Foundation /// A discrete piece of data in a media format interpretable by an AI model. /// diff --git a/FirebaseVertexAI/Sources/VertexAI.swift b/FirebaseVertexAI/Sources/VertexAI.swift index 112d117047d..ad33b23fcb0 100644 --- a/FirebaseVertexAI/Sources/VertexAI.swift +++ b/FirebaseVertexAI/Sources/VertexAI.swift @@ -14,11 +14,10 @@ import FirebaseAppCheckInterop import FirebaseAuthInterop -import FirebaseCore +import FirebaseCoreExtension import Foundation -// Avoids exposing internal FirebaseCore APIs to Swift users. -@_implementationOnly import FirebaseCoreExtension +public import FirebaseCore /// The Vertex AI for Firebase SDK provides access to Gemini models directly from your app. @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) diff --git a/FirebaseVertexAI/Sources/VertexLog.swift b/FirebaseVertexAI/Sources/VertexLog.swift index ff94a2d435e..b10c9b18881 100644 --- a/FirebaseVertexAI/Sources/VertexLog.swift +++ b/FirebaseVertexAI/Sources/VertexLog.swift @@ -12,11 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. +import FirebaseCoreExtension import Foundation import os.log -@_implementationOnly import FirebaseCoreExtension - enum VertexLog { /// Log message codes for the Vertex AI SDK /// diff --git a/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift b/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift index 290238445c5..35991384246 100644 --- a/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift +++ b/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift @@ -15,9 +15,10 @@ import FirebaseAppCheckInterop import FirebaseAuthInterop import FirebaseCore +import FirebaseVertexAI import XCTest -@testable import FirebaseVertexAI +@testable import struct FirebaseVertexAI.APIConfig @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) final class GenerativeModelTests: XCTestCase { @@ -1690,8 +1691,7 @@ struct AppCheckErrorFake: Error {} @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) extension SafetyRating: Swift.Comparable { - public static func < (lhs: FirebaseVertexAI.SafetyRating, - rhs: FirebaseVertexAI.SafetyRating) -> Bool { + static func < (lhs: SafetyRating, rhs: SafetyRating) -> Bool { return lhs.category.rawValue < rhs.category.rawValue } } diff --git a/FirebaseVertexAI/Tests/Unit/VertexComponentTests.swift b/FirebaseVertexAI/Tests/Unit/VertexComponentTests.swift index 6535ba26137..7f8fbf4c502 100644 --- a/FirebaseVertexAI/Tests/Unit/VertexComponentTests.swift +++ b/FirebaseVertexAI/Tests/Unit/VertexComponentTests.swift @@ -13,12 +13,12 @@ // limitations under the License. @preconcurrency import FirebaseCore +import FirebaseCoreExtension +import FirebaseVertexAI import Foundation import XCTest -@_implementationOnly import FirebaseCoreExtension - -@testable import FirebaseVertexAI +@testable import struct FirebaseVertexAI.APIConfig @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) class VertexComponentTests: XCTestCase { diff --git a/Package.swift b/Package.swift index c19869071fc..1f64c1926ff 100644 --- a/Package.swift +++ b/Package.swift @@ -1308,7 +1308,11 @@ let package = Package( "FirebaseCore", "FirebaseCoreExtension", ], - path: "FirebaseVertexAI/Sources" + path: "FirebaseVertexAI/Sources", + swiftSettings: [ + .enableExperimentalFeature("AccessLevelOnImport"), + .enableUpcomingFeature("InternalImportsByDefault"), + ] ), .testTarget( name: "FirebaseVertexAIUnit", @@ -1323,6 +1327,10 @@ let package = Package( ], cSettings: [ .headerSearchPath("../../../"), + ], + swiftSettings: [ + .enableExperimentalFeature("AccessLevelOnImport"), + .enableUpcomingFeature("InternalImportsByDefault"), ] ), ] + firestoreTargets(), From d0491fe46019c2fb0bb0fb3e8057ed96874297a1 Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Tue, 1 Apr 2025 14:37:46 -0400 Subject: [PATCH 2/6] Add TODOs to remove AccessLevelOnImport with Swift 6 --- Package.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Package.swift b/Package.swift index 1f64c1926ff..1896d3a6664 100644 --- a/Package.swift +++ b/Package.swift @@ -1310,6 +1310,8 @@ let package = Package( ], path: "FirebaseVertexAI/Sources", swiftSettings: [ + // TODO(#14638): Remove "AccessLevelOnImport" experimental feature declaration after + // upgrading to `swift-tools-version:6.0`, where it is on by default. .enableExperimentalFeature("AccessLevelOnImport"), .enableUpcomingFeature("InternalImportsByDefault"), ] @@ -1329,6 +1331,8 @@ let package = Package( .headerSearchPath("../../../"), ], swiftSettings: [ + // TODO(#14638): Remove "AccessLevelOnImport" experimental feature declaration after + // upgrading to `swift-tools-version:6.0`, where it is on by default. .enableExperimentalFeature("AccessLevelOnImport"), .enableUpcomingFeature("InternalImportsByDefault"), ] From da7416fc506d8c95721972177faa412f987b1f7b Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Thu, 10 Apr 2025 11:17:12 -0400 Subject: [PATCH 3/6] Fix `CoreImage` import; remove "AccessLevelOnImport" --- FirebaseVertexAI/Sources/PartsRepresentable+Image.swift | 5 ++++- Package.swift | 6 ------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/FirebaseVertexAI/Sources/PartsRepresentable+Image.swift b/FirebaseVertexAI/Sources/PartsRepresentable+Image.swift index 1e3b7c04b39..16c27f34dda 100644 --- a/FirebaseVertexAI/Sources/PartsRepresentable+Image.swift +++ b/FirebaseVertexAI/Sources/PartsRepresentable+Image.swift @@ -13,7 +13,6 @@ // limitations under the License. import CoreGraphics -import CoreImage import UniformTypeIdentifiers #if canImport(UIKit) @@ -22,6 +21,10 @@ import UniformTypeIdentifiers public import AppKit // For NSImage extensions. #endif +#if canImport(CoreImage) + import CoreImage +#endif + private let imageCompressionQuality: CGFloat = 0.8 /// An enum describing failures that can occur when converting image types to model content data. diff --git a/Package.swift b/Package.swift index 1896d3a6664..0eee4361f4c 100644 --- a/Package.swift +++ b/Package.swift @@ -1310,9 +1310,6 @@ let package = Package( ], path: "FirebaseVertexAI/Sources", swiftSettings: [ - // TODO(#14638): Remove "AccessLevelOnImport" experimental feature declaration after - // upgrading to `swift-tools-version:6.0`, where it is on by default. - .enableExperimentalFeature("AccessLevelOnImport"), .enableUpcomingFeature("InternalImportsByDefault"), ] ), @@ -1331,9 +1328,6 @@ let package = Package( .headerSearchPath("../../../"), ], swiftSettings: [ - // TODO(#14638): Remove "AccessLevelOnImport" experimental feature declaration after - // upgrading to `swift-tools-version:6.0`, where it is on by default. - .enableExperimentalFeature("AccessLevelOnImport"), .enableUpcomingFeature("InternalImportsByDefault"), ] ), From 0be08ab16b1d29e919a4b5e3daf977e4539dff9e Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Thu, 10 Apr 2025 12:04:29 -0400 Subject: [PATCH 4/6] Disable `@_implementationOnly` check for `FirebaseVertexAI` --- scripts/check_imports.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/check_imports.swift b/scripts/check_imports.swift index ee058f4b0e2..fee25f61a88 100755 --- a/scripts/check_imports.swift +++ b/scripts/check_imports.swift @@ -84,7 +84,11 @@ private func checkFile(_ file: String, logger: ErrorLogger, inRepo repoURL: URL, // Swift specific checks. fileContents.components(separatedBy: .newlines) .enumerated() // [(lineNum, line), ...] - .filter { $1.starts(with: "import FirebaseCoreExtension") } + .filter { + $1.starts(with: "import FirebaseCoreExtension") + /* FirebaseVertexAI is using `InternalImportsByDefault` so its files are not checked. */ + && !file.contains("FirebaseVertexAI") + } .forEach { lineNum, line in logger .importLog( From 16244785d92e7cd09e476c7cd65048e1de646b95 Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Fri, 11 Apr 2025 16:12:28 -0400 Subject: [PATCH 5/6] Unit test fix --- FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift b/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift index 35991384246..75a4c117599 100644 --- a/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift +++ b/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift @@ -1691,7 +1691,7 @@ struct AppCheckErrorFake: Error {} @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) extension SafetyRating: Swift.Comparable { - static func < (lhs: SafetyRating, rhs: SafetyRating) -> Bool { + public static func < (lhs: SafetyRating, rhs: SafetyRating) -> Bool { return lhs.category.rawValue < rhs.category.rawValue } } From d7056ffa9471ed52a6c333a5dc4de9c6b6e5ec43 Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Fri, 11 Apr 2025 16:34:37 -0400 Subject: [PATCH 6/6] enable by default for cocoapods --- FirebaseVertexAI.podspec | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/FirebaseVertexAI.podspec b/FirebaseVertexAI.podspec index dd4d236209a..0adcb666022 100644 --- a/FirebaseVertexAI.podspec +++ b/FirebaseVertexAI.podspec @@ -49,6 +49,10 @@ Firebase SDK. s.dependency 'FirebaseCore', '~> 11.12.0' s.dependency 'FirebaseCoreExtension', '~> 11.12.0' + s.pod_target_xcconfig = { + 'SWIFT_UPCOMING_FEATURE_INTERNAL_IMPORTS_BY_DEFAULT' => 'YES', + } + s.test_spec 'unit' do |unit_tests| unit_tests_dir = 'FirebaseVertexAI/Tests/Unit/' unit_tests.scheme = { :code_coverage => true }