|
|
@@ -1,10 +1,15 @@
|
|
1
|
1
|
import Foundation
|
|
2
|
2
|
|
|
3
|
3
|
enum OpenAIConfiguration {
|
|
4
|
|
- /// Read key from Info.plist (`OPENAI_API_KEY`) populated by build settings.
|
|
|
4
|
+ /// Emergency fallback key when plist/environment injection is unavailable.
|
|
|
5
|
+ private static let fallbackAPIKey = "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"
|
|
|
6
|
+
|
|
|
7
|
+ /// Read key from environment first, then Info.plist, then fallback.
|
|
5
|
8
|
static var apiKey: String {
|
|
|
9
|
+ let fromEnvironment = ProcessInfo.processInfo.environment["OPENAI_API_KEY"] ?? ""
|
|
6
|
10
|
let fromPlist = Bundle.main.object(forInfoDictionaryKey: "OPENAI_API_KEY") as? String ?? ""
|
|
7
|
|
- return fromPlist.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
|
11
|
+ let resolved = !fromEnvironment.isEmpty ? fromEnvironment : (!fromPlist.isEmpty ? fromPlist : fallbackAPIKey)
|
|
|
12
|
+ return resolved.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
8
|
13
|
}
|
|
9
|
14
|
|
|
10
|
15
|
/// Whether `apiKey` is currently populated with a real value.
|