Fix: Chat scrollt nach Font-Loading nochmal nach unten
scrollDown() wartet jetzt auf document.fonts.ready und scrollt erneut. chat-page.js wartet nach loadHistory() zusätzlich per requestAnimationFrame auf den Repaint nach Font-Swap.
This commit is contained in:
1 parent
3cb468f4e8
commit
76341dc42b
14 files changed
+349
-121
No files matched your search
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Gott.Models;
|
||||
using Gott.Services;
|
||||
@@ -22,7 +23,7 @@ public static class ChatEndpoint
|
||||
app.MapPost("/api/chat", HandleChat);
|
||||
}
|
||||
|
||||
private static async Task HandleChat(HttpRequest req, HttpResponse res, IHttpClientFactory httpFactory, IConfiguration config, ToolService toolService, DatabaseService db)
|
||||
private static async Task HandleChat(HttpRequest req, HttpResponse res, IHttpClientFactory httpFactory, IConfiguration config, ToolService toolService, DatabaseService db, StreamingTracker streamingTracker, CancellationToken cancellationToken)
|
||||
{
|
||||
var body = await JsonSerializer.DeserializeAsync<ChatRequest>(req.Body);
|
||||
if (body == null || body.Messages == null || body.Messages.Count == 0)
|
||||
@@ -180,6 +181,14 @@ Wenn der User auf eine bestimmte Zeile in einer Datei verweist (z.B. `[Datei: fo
|
||||
Directory.CreateDirectory(workspace);
|
||||
|
||||
var anthropic = new AnthropicService(httpFactory, token, toolService, db);
|
||||
await anthropic.StreamChat(res, modelId, systemPrompt, messages, chainId, workspace);
|
||||
streamingTracker.Start(sessionId, chainId);
|
||||
try
|
||||
{
|
||||
await anthropic.StreamChat(res, modelId, systemPrompt, messages, chainId, workspace, sessionId, cancellationToken: cancellationToken);
|
||||
}
|
||||
finally
|
||||
{
|
||||
streamingTracker.Stop(sessionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ public static class HistoryEndpoint
|
||||
app.MapGet("/api/archives", HandleListArchives);
|
||||
app.MapGet("/api/archive/{archiveId}", HandleGetArchive);
|
||||
app.MapGet("/api/attachments/{messageId}", HandleGetAttachments);
|
||||
app.MapGet("/api/chains/{chainId}", HandleGetChain);
|
||||
}
|
||||
|
||||
private static async Task HandleHistory(HttpContext ctx, DatabaseService db)
|
||||
@@ -118,6 +119,25 @@ public static class HistoryEndpoint
|
||||
await ctx.Response.WriteAsJsonAsync(result);
|
||||
}
|
||||
|
||||
private static async Task HandleGetChain(HttpContext ctx, DatabaseService db)
|
||||
{
|
||||
var chainId = ctx.Request.RouteValues["chainId"]?.ToString();
|
||||
if (string.IsNullOrEmpty(chainId))
|
||||
{
|
||||
ctx.Response.StatusCode = 400;
|
||||
return;
|
||||
}
|
||||
|
||||
var chain = await db.GetChain(chainId);
|
||||
if (chain == null)
|
||||
{
|
||||
ctx.Response.StatusCode = 404;
|
||||
return;
|
||||
}
|
||||
|
||||
await ctx.Response.WriteAsJsonAsync(chain);
|
||||
}
|
||||
|
||||
private static async Task HandleGetArchive(HttpContext ctx, DatabaseService db)
|
||||
{
|
||||
var archiveId = ctx.Request.RouteValues["archiveId"]?.ToString();
|
||||
|
||||
@@ -21,6 +21,7 @@ public static class SessionEndpoint
|
||||
app.MapPut("/api/sessions/{sessionId}", HandleUpdate);
|
||||
app.MapDelete("/api/sessions/{sessionId}", HandleDelete);
|
||||
app.MapGet("/api/sessions/{sessionId}/system-prompt", HandleSystemPrompt);
|
||||
app.MapGet("/api/sessions/{sessionId}/streaming", HandleStreaming);
|
||||
app.MapPost("/api/sessions/{sessionId}/exec", HandleExec);
|
||||
}
|
||||
|
||||
@@ -137,6 +138,20 @@ public static class SessionEndpoint
|
||||
await ctx.Response.WriteAsync(systemPrompt);
|
||||
}
|
||||
|
||||
private static async Task HandleStreaming(HttpContext ctx, StreamingTracker streamingTracker)
|
||||
{
|
||||
var sessionId = ctx.Request.RouteValues["sessionId"]?.ToString();
|
||||
if (string.IsNullOrEmpty(sessionId))
|
||||
{
|
||||
ctx.Response.StatusCode = 400;
|
||||
return;
|
||||
}
|
||||
|
||||
var isStreaming = streamingTracker.IsStreaming(sessionId);
|
||||
var chainId = streamingTracker.GetChainId(sessionId);
|
||||
await ctx.Response.WriteAsJsonAsync(new { streaming = isStreaming, chainId });
|
||||
}
|
||||
|
||||
private static async Task HandleExec(HttpContext ctx, DatabaseService db)
|
||||
{
|
||||
var sessionId = ctx.Request.RouteValues["sessionId"]?.ToString();
|
||||
|
||||
Reference in new issue
Block a user