using ClawdDotNet.Core.Api.Models; namespace ClawdDotNet.Core.Tests.Infrastructure; /// /// Baut gültige Nachrichtenfolgen für Tests — lesbar und garantiert API-konform. /// internal sealed class Conversation { private readonly List _messages = new(); private int _callCounter; public static Conversation Start(string? systemPrompt = "Du bist ein Testagent.") { var c = new Conversation(); if (!string.IsNullOrEmpty(systemPrompt)) c._messages.Add(ChatMessage.System(systemPrompt)); return c; } public Conversation User(string text) { _messages.Add(ChatMessage.User(text)); return this; } public Conversation Assistant(string text) { _messages.Add(ChatMessage.Assistant(text)); return this; } /// /// Fügt einen vollständigen Tool-Zyklus hinzu: assistant mit N tool_calls, /// gefolgt von genau N passenden tool-Antworten. /// public Conversation ToolCycle(int count = 1, int resultLength = 50, string toolName = "TestTool") { var calls = new List(); for (var i = 0; i < count; i++) { calls.Add(new ToolCall { Id = $"call_{++_callCounter}", Type = "function", Function = new ToolCallFunction { Name = toolName, Arguments = """{"action":"test"}""" } }); } _messages.Add(ChatMessage.AssistantWithToolCalls(calls)); foreach (var call in calls) _messages.Add(ChatMessage.ToolResponse(call.Id, new string('x', resultLength))); return this; } /// Wiederholt ein Muster aus User-Nachricht und Tool-Zyklus. public Conversation Repeat(int times, int toolCallsPerCycle = 1, int resultLength = 50) { for (var i = 0; i < times; i++) User($"Anfrage {i}").ToolCycle(toolCallsPerCycle, resultLength).Assistant($"Antwort {i}"); return this; } public List Build() => _messages; public static implicit operator List(Conversation c) => c._messages; }