| 1 | #nullable enable |
| 2 | |
| 3 | using CascadeIDE.Features.Intercom.Admin; |
| 4 | using CascadeIDE.Features.Intercom.Transport; |
| 5 | |
| 6 | namespace CascadeIDE.ViewModels; |
| 7 | |
| 8 | /// <summary> |
| 9 | /// Координатор team transport Intercom: подключение SSE/HTTP ingest и делегирование в ChatPanel. |
| 10 | /// </summary> |
| 11 | public partial class MainWindowViewModel |
| 12 | { |
| 13 | private readonly IntercomTransportCoordinator _intercomTransport = new(); |
| 14 | private IntercomAdminService? _intercomAdmin; |
| 15 | |
| 16 | internal IntercomTransportCoordinator IntercomTransport => _intercomTransport; |
| 17 | |
| 18 | private IntercomAdminService IntercomAdmin => |
| 19 | _intercomAdmin ??= new IntercomAdminService( |
| 20 | _intercomTransport, |
| 21 | () => _settings, |
| 22 | SaveSettingsIfChanged); |
| 23 | |
| 24 | public Task<(bool Ok, string Message)> ConnectIntercomTeamTransportAsync(CancellationToken ct = default) => |
| 25 | ChatPanel.ConnectIntercomTransportAsync(ct); |
| 26 | |
| 27 | public Task DisconnectIntercomTeamTransportAsync(CancellationToken ct = default) => |
| 28 | ChatPanel.DisconnectIntercomTransportAsync(ct); |
| 29 | |
| 30 | public Task<(bool Ok, string Message)> RefreshIntercomWorkspaceContextAsync(CancellationToken ct = default) => |
| 31 | IntercomAdmin.RefreshWorkspaceContextAsync(ct); |
| 32 | |
| 33 | internal Task<CascadeIDE.Features.Chat.ChatSlashIntercomResult> RunIntercomAdminSlashAsync( |
| 34 | string handlerId, |
| 35 | string? argsTail, |
| 36 | CancellationToken ct) => |
| 37 | IntercomAdmin.ExecuteAsync(handlerId, argsTail, ct); |
| 38 | |
| 39 | private void RefreshIntercomOnSolutionOpen() |
| 40 | { |
| 41 | _intercomTransport.OnWorkspaceChanged(); |
| 42 | _ = RefreshIntercomWorkspaceContextAsync(); |
| 43 | } |
| 44 | } |
| 45 | |