Add OpenAIKeyProvider + RealtimeSettings record

This commit is contained in:
2026-06-11 21:23:54 +00:00
parent 212ce06f07
commit d3e101eb29
3 changed files with 30 additions and 0 deletions
+1
View File
@@ -34,6 +34,7 @@ builder.Services.AddScoped<backend.Devices.DeviceTokenService>();
builder.Services.AddScoped<backend.Pairing.PairingService>(); builder.Services.AddScoped<backend.Pairing.PairingService>();
builder.Services.AddSingleton<backend.Install.InstallScriptBuilder>(); builder.Services.AddSingleton<backend.Install.InstallScriptBuilder>();
builder.Services.AddScoped<backend.Conversations.ConversationLog>(); builder.Services.AddScoped<backend.Conversations.ConversationLog>();
builder.Services.AddSingleton<backend.Realtime.OpenAIKeyProvider>();
var app = builder.Build(); var app = builder.Build();
+21
View File
@@ -0,0 +1,21 @@
namespace backend.Realtime;
public class OpenAIKeyProvider
{
private readonly string? _key;
public OpenAIKeyProvider(IConfiguration cfg)
{
_key = cfg["OPENAI_API_KEY"] ?? cfg["OpenAI:ApiKey"];
}
public bool HasKey => !string.IsNullOrWhiteSpace(_key);
public string GetRequired()
{
if (string.IsNullOrWhiteSpace(_key))
throw new InvalidOperationException(
"OPENAI_API_KEY is not configured. Set the env var on the Coolify app.");
return _key!;
}
}
+8
View File
@@ -0,0 +1,8 @@
namespace backend.Realtime;
public record RealtimeSettings(
string Model,
string Voice,
string SystemPrompt,
int IdleTimeoutSeconds,
IReadOnlySet<string> EnabledTools);