| 1 | #nullable enable |
| 2 | |
| 3 | using CascadeIDE.Contracts; |
| 4 | using CascadeIDE.Models.Intercom; |
| 5 | using CascadeIDE.Services.Intercom; |
| 6 | |
| 7 | namespace CascadeIDE.Features.Chat.DataAcquisition; |
| 8 | |
| 9 | /// <summary>DAL: prepare outbound @ send с Roslyn resolve вне UI-потока (ADR 0102 / 0128 / 0134).</summary> |
| 10 | [IoBoundary] |
| 11 | public static class IntercomAttachmentResolveAtSendWorker |
| 12 | { |
| 13 | public static Task<(bool Ok, IntercomAttachmentMessageBuilder.Outbound Outbound, string Error)> TryBuildAsync( |
| 14 | string rawInput, |
| 15 | IReadOnlyDictionary<string, AttachmentAnchor> pendingByShortId, |
| 16 | IntercomAttachmentResolveAtSend.EditorSnapshot editor, |
| 17 | string? workspaceRoot, |
| 18 | string? solutionPath, |
| 19 | CancellationToken cancellationToken = default, |
| 20 | string? indexDirectoryRelative = null) => |
| 21 | Task.Run( |
| 22 | () => |
| 23 | { |
| 24 | cancellationToken.ThrowIfCancellationRequested(); |
| 25 | var ok = IntercomAttachmentMessageBuilder.TryBuild( |
| 26 | rawInput, |
| 27 | pendingByShortId, |
| 28 | editor, |
| 29 | workspaceRoot, |
| 30 | solutionPath, |
| 31 | out var outbound, |
| 32 | out var error, |
| 33 | indexDirectoryRelative); |
| 34 | return (ok, outbound, error); |
| 35 | }, |
| 36 | cancellationToken); |
| 37 | |
| 38 | public static Task<PreparedIntercomMessage> TryPrepareAsync( |
| 39 | string rawInput, |
| 40 | IReadOnlyDictionary<string, AttachmentAnchor> pendingByShortId, |
| 41 | IntercomAttachmentResolveAtSend.EditorSnapshot editor, |
| 42 | string? workspaceRoot, |
| 43 | string? solutionPath, |
| 44 | CancellationToken cancellationToken = default, |
| 45 | string? indexDirectoryRelative = null) => |
| 46 | tryPrepareOnPool( |
| 47 | rawInput, |
| 48 | pendingByShortId, |
| 49 | editor, |
| 50 | workspaceRoot, |
| 51 | solutionPath, |
| 52 | indexDirectoryRelative, |
| 53 | forMcp: false, |
| 54 | cancellationToken); |
| 55 | |
| 56 | public static Task<PreparedIntercomMessage> TryPrepareForMcpAsync( |
| 57 | string rawInput, |
| 58 | IReadOnlyDictionary<string, AttachmentAnchor> pendingByShortId, |
| 59 | IntercomAttachmentResolveAtSend.EditorSnapshot editor, |
| 60 | string? workspaceRoot, |
| 61 | string? solutionPath, |
| 62 | CancellationToken cancellationToken = default) => |
| 63 | tryPrepareOnPool( |
| 64 | rawInput, |
| 65 | pendingByShortId, |
| 66 | editor, |
| 67 | workspaceRoot, |
| 68 | solutionPath, |
| 69 | indexDirectoryRelative: null, |
| 70 | forMcp: true, |
| 71 | cancellationToken); |
| 72 | |
| 73 | private static Task<PreparedIntercomMessage> tryPrepareOnPool( |
| 74 | string rawInput, |
| 75 | IReadOnlyDictionary<string, AttachmentAnchor> pendingByShortId, |
| 76 | IntercomAttachmentResolveAtSend.EditorSnapshot editor, |
| 77 | string? workspaceRoot, |
| 78 | string? solutionPath, |
| 79 | string? indexDirectoryRelative, |
| 80 | bool forMcp, |
| 81 | CancellationToken cancellationToken) => |
| 82 | Task.Run( |
| 83 | () => |
| 84 | { |
| 85 | cancellationToken.ThrowIfCancellationRequested(); |
| 86 | if (forMcp) |
| 87 | { |
| 88 | _ = IntercomAttachmentMessageBuilder.TryPrepareForMcp( |
| 89 | rawInput, |
| 90 | pendingByShortId, |
| 91 | editor, |
| 92 | workspaceRoot, |
| 93 | solutionPath, |
| 94 | out var preparedMcp); |
| 95 | return preparedMcp; |
| 96 | } |
| 97 | |
| 98 | _ = IntercomAttachmentMessageBuilder.TryPrepare( |
| 99 | rawInput, |
| 100 | pendingByShortId, |
| 101 | editor, |
| 102 | workspaceRoot, |
| 103 | solutionPath, |
| 104 | out var prepared); |
| 105 | return prepared; |
| 106 | }, |
| 107 | cancellationToken); |
| 108 | } |
| 109 | |