Add OpenAIRealtimeUpstream + RealtimeSessionFactory + DI registrations

This commit is contained in:
2026-06-11 21:48:21 +00:00
parent 8f53f9daa9
commit 78373b0912
3 changed files with 98 additions and 0 deletions
@@ -0,0 +1,37 @@
using backend.Conversations;
using backend.Tools;
using Microsoft.Extensions.Logging;
namespace backend.Realtime;
public class RealtimeSessionFactory
{
protected readonly OpenAIKeyProvider keys;
protected readonly ToolRegistry registry;
protected readonly ConversationLog log;
protected readonly ILoggerFactory loggerFactory;
public RealtimeSessionFactory(
OpenAIKeyProvider keys, ToolRegistry registry,
ConversationLog log, ILoggerFactory loggerFactory)
{
this.keys = keys;
this.registry = registry;
this.log = log;
this.loggerFactory = loggerFactory;
}
public virtual async Task<RealtimeSession> CreateAsync(
Guid deviceId,
RealtimeSettings cfg,
ISessionOutput output,
IDeviceChannel channel,
CancellationToken ct)
{
var upstream = new OpenAIRealtimeUpstream();
await upstream.ConnectAsync(keys.GetRequired(), cfg.Model, ct);
return new RealtimeSession(
deviceId, upstream, output, log, registry, cfg, channel,
loggerFactory.CreateLogger<RealtimeSession>());
}
}