Repository Public License
1import Foundation2import PrismAIOrchestrator3import PrismSecurity45public enum StudioKeyTool {6 /// Reads a key from standard input, checks it against the API, and stores it in PRISM's Keychain item. Returns a process exit code.7 @MainActor8 public static func storeKeyFromStandardInput() async -> Int32 {9 let data = FileHandle.standardInput.readDataToEndOfFile()10 let key = String(decoding: data, as: UTF8.self).trimmingCharacters(in: .whitespacesAndNewlines)11 guard !key.isEmpty else { print("No key on standard input."); return 2 }12 let secrets = KeychainSecretStore()13 do {14 let models = try await AnthropicClient(secrets: secrets).listModels(key: key)15 try secrets.setSecret(key, for: SecretAccount.anthropicAPIKey)16 print("Key \(Redactor.fingerprint(key)) verified (\(models.count) models) and stored in the Keychain (service \(secrets.service)).")17 return 018 } catch {19 print("The key was not stored: \(error.localizedDescription)")20 return 121 }22 }23}24