internal virtual object?Send(IAgentMessage message) { using var socketStream = new SshAgentSocketStream(_socketPath); using var writer = new AgentWriter(socketStream); using var reader = new AgentReader(socketStream); message.To(writer); return(message.From(reader)); }
internal override object?Send(IAgentMessage message) { using var socketStream = new PageantSocketStream(); using var writer = new AgentWriter(socketStream); using var reader = new AgentReader(socketStream); message.To(writer); socketStream.Send(); return(message.From(reader)); }
/// <inheritdoc /> public virtual async Task SendAsync(Wallet wallet, IAgentMessage message, ConnectionRecord connection, string recipientKey = null) { Logger.LogInformation(LoggingEvents.SendMessage, "Recipient {0} Endpoint {1}", connection.TheirVk, connection.Endpoint.Uri); if (string.IsNullOrEmpty(message.Id)) { throw new AgentFrameworkException(ErrorCode.InvalidMessage, "@id field on message must be populated"); } if (string.IsNullOrEmpty(message.Type)) { throw new AgentFrameworkException(ErrorCode.InvalidMessage, "@type field on message must be populated"); } var encryptionKey = recipientKey ?? connection.TheirVk ?? throw new AgentFrameworkException( ErrorCode.A2AMessageTransmissionError, "Cannot find encryption key"); var inner = await CryptoUtils.PackAsync( wallet, encryptionKey, connection.MyVk, message.ToByteArray()); var forward = await CryptoUtils.PackAsync( wallet, connection.Endpoint.Verkey, null, new ForwardMessage { Message = inner.GetUTF8String(), To = encryptionKey }); var request = new HttpRequestMessage { RequestUri = new Uri(connection.Endpoint.Uri), Method = HttpMethod.Post, Content = new ByteArrayContent(forward) }; request.Content.Headers.ContentType = new MediaTypeHeaderValue(AgentWireMessageMimeType); try { var response = await HttpClient.SendAsync(request); response.EnsureSuccessStatusCode(); } catch (Exception e) { throw new AgentFrameworkException( ErrorCode.A2AMessageTransmissionError, "Failed to send A2A message", e); } }
public static async Task <AgentMessageEnvelope> Create( ICryptographicImplementation cryptographicImplementation, string originator, string target, IAgentMessage message) { var envelope = new AgentMessageEnvelope() { Created = DateTimeOffset.UtcNow, Originator = originator, Target = target, MessageType = message.GetType().Name, Message = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message)) }; envelope.Signature = await cryptographicImplementation.Sign( await GetMessageEnvelopeHash(cryptographicImplementation, envelope)); return(envelope); }
/// <inheritdoc /> /// <param name="message">The message.</param> public MessagePayload(IAgentMessage message) : this(message.ToJson(), false) { }
/// <summary>Wraps the message in payload.</summary> /// <param name="agentMessage">The agent message.</param> /// <returns></returns> public static MessagePayload AsMessagePayload(this IAgentMessage agentMessage) => new MessagePayload(agentMessage);