using System; using System.IO; using System.Net.Http; using System.Runtime.InteropServices; using Gott.Endpoints; using Gott.Middleware; using Gott.Services; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; var builder = WebApplication.CreateBuilder(args); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) builder.Services.AddWindowsService(); builder.Services.AddHttpClient(); var dataDir = Path.Combine(AppContext.BaseDirectory, "data"); Directory.CreateDirectory(dataDir); var dbPath = Path.Combine(dataDir, "gott.db"); var authService = new AuthService(dbPath); var dbService = new DatabaseService(dbPath); dbService.EnsureDefaultUser(authService); builder.Services.AddSingleton(authService); builder.Services.AddSingleton(dbService); builder.Services.AddSingleton(new ImageService()); builder.Services.AddSingleton(new StreamingTracker()); builder.Services.AddSingleton(new RemoteConnectionManager()); var memoryService = new MemoryService(dataDir); var skillService = new SkillService(dataDir); builder.Services.AddSingleton(memoryService); builder.Services.AddSingleton(skillService); // Shared Services var toolService = new ToolService(builder.Configuration); builder.Services.AddSingleton(toolService); var maxHistory = builder.Configuration.GetValue("MaxHistory", 120); var reminderInterval = builder.Configuration.GetValue("ReminderInterval", 30); var chatService = new ChatService(dbService, toolService, memoryService, skillService, maxHistory, reminderInterval); builder.Services.AddSingleton(chatService); // AnthropicService (Singleton – shared zwischen ChatEndpoint und TelegramService) var anthropicToken = builder.Configuration["AnthropicToken"] ?? ""; var payloadLogging = builder.Configuration.GetValue("PayloadLogging", false); var payloadLoggingGzip = builder.Configuration.GetValue("PayloadLoggingGzip", false); builder.Services.AddSingleton(sp => new AnthropicService( sp.GetRequiredService(), anthropicToken, toolService, dbService, memoryService, payloadLogging, payloadLoggingGzip)); // Telegram Bot (pro Session – Token aus Session-Config) var maxIterations = builder.Configuration.GetValue("MaxIterations", 100); builder.Services.AddSingleton(sp => new TelegramService( sp.GetRequiredService(), dbService, chatService, sp.GetRequiredService(), maxIterations)); // Krea Image Generation var kreaToken = builder.Configuration["KreaToken"] ?? ""; builder.Services.AddSingleton(sp => new KreaService(sp.GetRequiredService(), kreaToken, dataDir)); // Cronjob-Service (BackgroundService) builder.Services.AddSingleton(); builder.Services.AddHostedService(sp => sp.GetRequiredService()); var app = builder.Build(); app.UseWebSockets(); app.UseDefaultFiles(); app.UseStaticFiles(); app.UseMiddleware(); app.MapAuthEndpoints(); app.MapChatEndpoint(); app.MapHistoryEndpoint(); app.MapSessionEndpoints(); app.MapAgentEndpoints(); app.MapWorkspaceEndpoint(); app.MapInfoEndpoint(); app.MapBackupEndpoint(); app.MapSkillEndpoints(); app.MapProfileEndpoints(); app.MapSettingsEndpoints(); app.MapTelegramEndpoints(); app.MapCronjobEndpoints(); app.MapKreaEndpoints(); app.MapSharedEndpoints(); app.MapAdminEndpoints(); app.MapServerSettingsEndpoints(); app.MapOpenClawEndpoints(); app.MapRemoteEndpoints(); var port = app.Configuration.GetValue("Port", 19000); app.Run($"http://0.0.0.0:{port}");