package tools import ( "context" "strings" ) type SendMessageConnector interface { ExecuteSendMessage(context.Context, SendMessageConnectorRequest) (SendMessageConnectorResult, error) } type SendMessageConnectorRequest struct { TargetType string TargetID string TargetRef string ContentText string ContentSHA256 string ContentLength int IdempotencyKeySHA256 string ExecutionMode string } type SendMessageConnectorResult struct { Accepted bool Status string AckRef string ErrorCode string ErrorMessage string ConnectorMode string ProductionEnabled bool SideEffects map[string]any } func sendMessageConnectorRequestFromNormalized(input normalizedSendMessageArgs) SendMessageConnectorRequest { return SendMessageConnectorRequest{ TargetType: input.TargetType, TargetID: input.TargetID, TargetRef: input.TargetRef, ContentText: input.ContentText, ContentSHA256: input.ContentSHA256, ContentLength: input.ContentLength, IdempotencyKeySHA256: input.IdempotencyKeySHA256, ExecutionMode: input.ExecutionMode, } } func normalizeSendMessageConnectorResult(result SendMessageConnectorResult, err error) SendMessageConnectorResult { normalized := result normalized.Status = strings.TrimSpace(normalized.Status) normalized.AckRef = strings.TrimSpace(normalized.AckRef) normalized.ErrorCode = strings.TrimSpace(normalized.ErrorCode) normalized.ErrorMessage = strings.TrimSpace(normalized.ErrorMessage) normalized.ConnectorMode = strings.TrimSpace(normalized.ConnectorMode) if normalized.ConnectorMode == "" { normalized.ConnectorMode = sendMessageConnectorMode } if err != nil { normalized.Accepted = false if normalized.Status == "" { normalized.Status = "failed" } if normalized.ErrorCode == "" { normalized.ErrorCode = "connector_error" } if normalized.ErrorMessage == "" { normalized.ErrorMessage = err.Error() } return normalized } if normalized.Status == "" { if normalized.Accepted { normalized.Status = "accepted" } else { normalized.Status = "failed" } } if !normalized.Accepted && normalized.ErrorCode == "" { normalized.ErrorCode = "connector_rejected" } return normalized }