| 1 | #nullable enable |
| 2 | using CascadeIDE.Models.AgentChat; |
| 3 | using CascadeIDE.Models.Intercom; |
| 4 | using CascadeIDE.ViewModels; |
| 5 | |
| 6 | namespace CascadeIDE.Features.Chat; |
| 7 | |
| 8 | internal static class ChatHistoryPayloadMapping |
| 9 | { |
| 10 | public static ChatHistoryMessagePayload ToMessagePayload(ChatMessageViewModel message) |
| 11 | { |
| 12 | string? slashStatus = message.SlashCommandStatus?.ToString(); |
| 13 | return new ChatHistoryMessagePayload( |
| 14 | message.MessageId.ToString("N"), |
| 15 | message.Role, |
| 16 | message.Content, |
| 17 | message.ThreadId.ToString("N"), |
| 18 | message.ParentMessageId?.ToString("N"), |
| 19 | message.SlashCommandPath, |
| 20 | string.IsNullOrWhiteSpace(message.SlashCommandArgs) ? null : message.SlashCommandArgs, |
| 21 | slashStatus, |
| 22 | message.Attachments.Count > 0 ? message.Attachments : null, |
| 23 | message.SenderWorkspaceContext, |
| 24 | message.Audience == IntercomMessageAudience.Channel ? null : message.Audience, |
| 25 | message.DeliveryMode); |
| 26 | } |
| 27 | |
| 28 | public static ChatHistoryMessageEditedPayload ToMessageEditedPayload( |
| 29 | Guid messageId, |
| 30 | string newContent, |
| 31 | string? reason) => |
| 32 | new( |
| 33 | messageId.ToString("N"), |
| 34 | newContent, |
| 35 | string.IsNullOrWhiteSpace(reason) ? "correction" : reason.Trim()); |
| 36 | |
| 37 | public static ChatHistoryThreadForkedPayload ToThreadForkedPayload( |
| 38 | Guid newThreadId, |
| 39 | Guid previousThreadId, |
| 40 | Guid? parentMessageId) => |
| 41 | new( |
| 42 | newThreadId.ToString("N"), |
| 43 | previousThreadId.ToString("N"), |
| 44 | parentMessageId?.ToString("N")); |
| 45 | |
| 46 | public static ChatHistoryClarificationAnswerSubmittedPayload ToClarificationAnswerPayload( |
| 47 | ClarificationResponse response, |
| 48 | IReadOnlyDictionary<string, string> answers) => |
| 49 | new(response.BatchId.ToString("N"), answers); |
| 50 | |
| 51 | public static SedmContextCardMaterializedPayload ToContextCardMaterializedPayload( |
| 52 | Guid worklineId, |
| 53 | string anchorPath, |
| 54 | string? anchorSymbol, |
| 55 | string? worklineLabel, |
| 56 | string? pathHint, |
| 57 | string? triggerReason, |
| 58 | IReadOnlyList<SedmAppliesEntryPayload>? applies = null) => |
| 59 | new( |
| 60 | SchemaVersion: 1, |
| 61 | WorklineId: worklineId.ToString("N"), |
| 62 | Anchor: new SedmContextCardAnchorPayload(anchorPath, anchorSymbol), |
| 63 | Workline: new SedmWorklineRefPayload(worklineId.ToString("N"), worklineLabel), |
| 64 | Applies: applies, |
| 65 | PathHint: pathHint, |
| 66 | TriggerReason: triggerReason); |
| 67 | |
| 68 | public static SedmIntentCardRecordedPayload ToIntentCardRecordedPayload( |
| 69 | Guid worklineId, |
| 70 | SedmIntentCardBodyPayload card, |
| 71 | IReadOnlyList<SedmIntentConsideredOptionPayload>? considered, |
| 72 | string author = "operator", |
| 73 | Guid? messageId = null) => |
| 74 | new( |
| 75 | SchemaVersion: 1, |
| 76 | Author: author, |
| 77 | WorklineId: worklineId.ToString("N"), |
| 78 | Card: card, |
| 79 | MessageId: messageId?.ToString("N"), |
| 80 | Considered: considered); |
| 81 | |
| 82 | public static SedmDecisionRecordedPayload ToDecisionRecordedPayload( |
| 83 | Guid worklineId, |
| 84 | SedmIntentCardBodyPayload card, |
| 85 | IReadOnlyList<SedmIntentConsideredOptionPayload>? considered, |
| 86 | IReadOnlyList<SedmDecisionFindingPayload>? findings, |
| 87 | SedmDecisionBasisPayload? basis, |
| 88 | string author = "agent", |
| 89 | Guid? messageId = null) => |
| 90 | new( |
| 91 | SchemaVersion: 1, |
| 92 | Author: author, |
| 93 | WorklineId: worklineId.ToString("N"), |
| 94 | Card: card, |
| 95 | MessageId: messageId?.ToString("N"), |
| 96 | Considered: considered, |
| 97 | Findings: findings, |
| 98 | Basis: basis, |
| 99 | Status: "active"); |
| 100 | |
| 101 | public static SedmDecisionLifecyclePayload ToDecisionLifecyclePayload( |
| 102 | Guid worklineId, |
| 103 | Guid decisionEventId, |
| 104 | string? reason) => |
| 105 | new( |
| 106 | SchemaVersion: 1, |
| 107 | WorklineId: worklineId.ToString("N"), |
| 108 | DecisionEventId: decisionEventId.ToString("N"), |
| 109 | Reason: reason); |
| 110 | } |
| 111 | |