csharpdeeb25a2 | 1 | #nullable enable |
| 2 | |
| 3 | using System.Text; |
| 4 | using System.Text.Json; |
| 5 | using CascadeIDE.Contracts; |
| 6 | using CascadeIDE.Models.Intercom; |
| 7 | |
| 8 | namespace CascadeIDE.Features.Chat; |
| 9 | |
| 10 | /// <summary>Блок attachments для prompt агента (ADR 0128 §10).</summary> |
| 11 | [ComputingUnit] |
| 12 | public static class IntercomAttachmentPromptFormatter |
| 13 | { |
| 14 | private static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web) |
| 15 | { |
| 16 | WriteIndented = false, |
| 17 | }; |
| 18 | |
| 19 | public static string AppendToUserMessage( |
| 20 | string userContent, |
| 21 | IReadOnlyList<AttachmentAnchor> attachments, |
| 22 | SenderWorkspaceContext? senderContext) |
| 23 | { |
| 24 | if (attachments.Count == 0 && senderContext is null) |
| 25 | return userContent; |
| 26 | |
| 27 | var sb = new StringBuilder(userContent); |
| 28 | if (senderContext is not null) |
| 29 | { |
| 30 | sb.AppendLine(); |
| 31 | sb.AppendLine(); |
| 32 | sb.AppendLine("--- sender_workspace_context ---"); |
| 33 | sb.AppendLine(JsonSerializer.Serialize(senderContext, JsonOptions)); |
| 34 | } |
| 35 | |
| 36 | if (attachments.Count > 0) |
| 37 | { |
| 38 | sb.AppendLine(); |
| 39 | sb.AppendLine("--- attachments ---"); |
| 40 | sb.AppendLine(JsonSerializer.Serialize(attachments, JsonOptions)); |
| 41 | } |
| 42 | |
| 43 | return sb.ToString(); |
| 44 | } |
| 45 | } |
| 46 | |
View only · write via MCP/CIDE