Files
gott/Program.cs
T
Meleki 3b7bdb7a20 feat: OpenClaw session import with sorted history
Backend:
- New OpenClawEndpoint with GET /api/openclaw/sessions and POST /api/openclaw/import
- Lists all OpenClaw sessions with preview messages, model, summary
- Imports user/assistant text messages (skips tool-use/tool-result)
- Cleans user messages (removes webchat prefixes, cron tags, conversation info blocks)
- Re-import support: deletes previous openclaw-import chains before importing
- New DatabaseService methods: CreateChainForImport, CreateMessageForImport, DeleteOpenClawImport
- Added SortKey to MessageRecord (computed: openclaw-import gets id-10B, else id)

History sorting:
- OpenClaw-imported messages always appear before native messages
- Sort by CASE WHEN tag='openclaw-import' THEN id-10000000000 ELSE id END
- Cursor-based paging updated from beforeId/afterId to beforeSortKey/afterSortKey
- All history queries (GetLatestActive, Before, After, CountBefore) updated

Frontend:
- Dashboard: new 'OpenClaw Import' menu item in session card dropdown
- Modal: shows OpenClaw sessions with metadata, summary, preview messages
- Imported messages display blue 'OC' badge in chat
- API functions: apiGetOpenclawSessions, apiImportOpenclawSession
- History paging updated to use sortKey cursors
2026-03-08 17:32:32 +01:00

90 lines
3.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.IO;
using System.Net.Http;
using Gott.Endpoints;
using Gott.Middleware;
using Gott.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHttpClient();
var dataDir = Path.Combine(AppContext.BaseDirectory, "data");
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());
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.Services.AddSingleton(toolService);
var chatService = new ChatService(dbService, toolService, memoryService, skillService);
builder.Services.AddSingleton(chatService);
// AnthropicService (Singleton – shared zwischen ChatEndpoint und TelegramService)
var anthropicToken = builder.Configuration["AnthropicToken"] ?? "";
var payloadLogging = builder.Configuration.GetValue<bool>("PayloadLogging", false);
var payloadLoggingGzip = builder.Configuration.GetValue<bool>("PayloadLoggingGzip", false);
builder.Services.AddSingleton<AnthropicService>(sp =>
new AnthropicService(
sp.GetRequiredService<IHttpClientFactory>(),
anthropicToken, toolService, dbService, memoryService,
payloadLogging, payloadLoggingGzip));
// Telegram Bot (pro Session – Token aus Session-Config)
var maxIterations = builder.Configuration.GetValue<int>("MaxIterations", 100);
builder.Services.AddSingleton<TelegramService>(sp =>
new TelegramService(
sp.GetRequiredService<IHttpClientFactory>(),
dbService, chatService,
sp.GetRequiredService<AnthropicService>(),
maxIterations));
// Krea Image Generation
var kreaToken = builder.Configuration["KreaToken"] ?? "";
builder.Services.AddSingleton(sp =>
new KreaService(sp.GetRequiredService<IHttpClientFactory>(), kreaToken, dataDir));
// Cronjob-Service (BackgroundService)
builder.Services.AddSingleton<CronjobService>();
builder.Services.AddHostedService<CronjobService>(sp => sp.GetRequiredService<CronjobService>());
var app = builder.Build();
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseMiddleware<AuthMiddleware>();
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();
var port = app.Configuration.GetValue<int>("Port", 19000);
app.Run($"http://0.0.0.0:{port}");