aws-sdk-assurance 1.0.0

AWS SDK for AWS Assurance
Documentation
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
pub use crate::operation::chat::_chat_input::ChatInputBuilder;

pub use crate::operation::chat::_chat_output::ChatOutputBuilder;

impl crate::operation::chat::builders::ChatInputBuilder {
    /// Sends a request with this input using the given client.
    pub async fn send_with(
        self,
        client: &crate::Client,
    ) -> ::std::result::Result<
        crate::operation::chat::ChatOutput,
        ::aws_smithy_runtime_api::client::result::SdkError<
            crate::operation::chat::ChatError,
            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
        >,
    > {
        let mut fluent_builder = client.chat();
        fluent_builder.inner = self;
        fluent_builder.send().await
    }
}
/// Fluent builder constructing a request to `Chat`.
///
/// <p>Starts a streaming chat turn with the AWS Assurance agent. Returns an event stream of chat events, including chunks, tool calls, and errors.</p>
///
/// [`ChatOutput`](crate::operation::chat::ChatOutput) contains an event stream field as well as one or more non-event stream fields.
/// Due to its current implementation, the non-event stream fields are not fully deserialized
/// until the [`send`](Self::send) method completes. As a result, accessing these fields of the operation
/// output struct within an interceptor may return uninitialized values.
///
#[derive(::std::clone::Clone, ::std::fmt::Debug)]
pub struct ChatFluentBuilder {
    handle: ::std::sync::Arc<crate::client::Handle>,
    inner: crate::operation::chat::builders::ChatInputBuilder,
    config_override: ::std::option::Option<crate::config::Builder>,
}
impl crate::client::customize::internal::CustomizableSend<crate::operation::chat::ChatOutput, crate::operation::chat::ChatError>
    for ChatFluentBuilder
{
    fn send(
        self,
        config_override: crate::config::Builder,
    ) -> crate::client::customize::internal::BoxFuture<
        crate::client::customize::internal::SendResult<crate::operation::chat::ChatOutput, crate::operation::chat::ChatError>,
    > {
        ::std::boxed::Box::pin(async move { self.config_override(config_override).send().await })
    }
}
impl ChatFluentBuilder {
    /// Creates a new `ChatFluentBuilder`.
    pub(crate) fn new(handle: ::std::sync::Arc<crate::client::Handle>) -> Self {
        Self {
            handle,
            inner: ::std::default::Default::default(),
            config_override: ::std::option::Option::None,
        }
    }
    /// Access the Chat as a reference.
    pub fn as_input(&self) -> &crate::operation::chat::builders::ChatInputBuilder {
        &self.inner
    }
    /// Sends the request and returns the response.
    ///
    /// If an error occurs, an `SdkError` will be returned with additional details that
    /// can be matched against.
    ///
    /// By default, any retryable failures will be retried twice. Retry behavior
    /// is configurable with the [RetryConfig](aws_smithy_types::retry::RetryConfig), which can be
    /// set when configuring the client.
    pub async fn send(
        self,
    ) -> ::std::result::Result<
        crate::operation::chat::ChatOutput,
        ::aws_smithy_runtime_api::client::result::SdkError<
            crate::operation::chat::ChatError,
            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
        >,
    > {
        let input = self
            .inner
            .build()
            .map_err(::aws_smithy_runtime_api::client::result::SdkError::construction_failure)?;
        let runtime_plugins =
            crate::operation::chat::Chat::operation_runtime_plugins(self.handle.runtime_plugins.clone(), &self.handle.conf, self.config_override);
        let mut output = crate::operation::chat::Chat::orchestrate(&runtime_plugins, input).await?;

        // Converts any error encountered beyond this point into an `SdkError` response error
        // with an `HttpResponse`. However, since we have already exited the `orchestrate`
        // function, the original `HttpResponse` is no longer available and cannot be restored.
        // This means that header information from the original response has been lost.
        //
        // Note that the response body would have been consumed by the deserializer
        // regardless, even if the initial message was hypothetically processed during
        // the orchestrator's deserialization phase but later resulted in an error.
        fn response_error(
            err: impl ::std::convert::Into<::aws_smithy_runtime_api::box_error::BoxError>,
        ) -> ::aws_smithy_runtime_api::client::result::SdkError<
            crate::operation::chat::ChatError,
            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
        > {
            ::aws_smithy_runtime_api::client::result::SdkError::response_error(
                err,
                ::aws_smithy_runtime_api::client::orchestrator::HttpResponse::new(
                    ::aws_smithy_runtime_api::http::StatusCode::try_from(200).expect("valid successful code"),
                    ::aws_smithy_types::body::SdkBody::empty(),
                ),
            )
        }

        let message = output.event_stream.try_recv_initial_response().await.map_err(response_error)?;

        match message {
            ::std::option::Option::Some(_message) => {
                let mut builder = output.into_builder();
                builder = crate::protocol_serde::shape_chat::de_chat(_message.payload(), builder).map_err(response_error)?;
                let output = builder.build().map_err(response_error)?;
                ::std::result::Result::Ok(output)
            }
            ::std::option::Option::None => ::std::result::Result::Ok(output),
        }
    }

    /// Consumes this builder, creating a customizable operation that can be modified before being sent.
    pub fn customize(
        self,
    ) -> crate::client::customize::CustomizableOperation<crate::operation::chat::ChatOutput, crate::operation::chat::ChatError, Self> {
        crate::client::customize::CustomizableOperation::new(self)
    }
    pub(crate) fn config_override(mut self, config_override: impl ::std::convert::Into<crate::config::Builder>) -> Self {
        self.set_config_override(::std::option::Option::Some(config_override.into()));
        self
    }

    pub(crate) fn set_config_override(&mut self, config_override: ::std::option::Option<crate::config::Builder>) -> &mut Self {
        self.config_override = config_override;
        self
    }
    /// <p>The chat message to send to the AWS Assurance agent.</p>
    pub fn message(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
        self.inner = self.inner.message(input.into());
        self
    }
    /// <p>The chat message to send to the AWS Assurance agent.</p>
    pub fn set_message(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
        self.inner = self.inner.set_message(input);
        self
    }
    /// <p>The chat message to send to the AWS Assurance agent.</p>
    pub fn get_message(&self) -> &::std::option::Option<::std::string::String> {
        self.inner.get_message()
    }
    /// <p>The session to continue. Pass the <code>sessionId</code> returned by a previous <code>Chat</code> call to continue that session. If you omit it, AWS Assurance starts a new session. If the session doesn't exist or has expired, the operation returns <code>ResourceNotFoundException</code>. If the format isn't valid, the operation returns <code>ValidationException</code>.</p>
    pub fn session_id(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
        self.inner = self.inner.session_id(input.into());
        self
    }
    /// <p>The session to continue. Pass the <code>sessionId</code> returned by a previous <code>Chat</code> call to continue that session. If you omit it, AWS Assurance starts a new session. If the session doesn't exist or has expired, the operation returns <code>ResourceNotFoundException</code>. If the format isn't valid, the operation returns <code>ValidationException</code>.</p>
    pub fn set_session_id(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
        self.inner = self.inner.set_session_id(input);
        self
    }
    /// <p>The session to continue. Pass the <code>sessionId</code> returned by a previous <code>Chat</code> call to continue that session. If you omit it, AWS Assurance starts a new session. If the session doesn't exist or has expired, the operation returns <code>ResourceNotFoundException</code>. If the format isn't valid, the operation returns <code>ValidationException</code>.</p>
    pub fn get_session_id(&self) -> &::std::option::Option<::std::string::String> {
        self.inner.get_session_id()
    }
    /// <p>The ARN of this governance environment.</p>
    pub fn environment_arn(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
        self.inner = self.inner.environment_arn(input.into());
        self
    }
    /// <p>The ARN of this governance environment.</p>
    pub fn set_environment_arn(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
        self.inner = self.inner.set_environment_arn(input);
        self
    }
    /// <p>The ARN of this governance environment.</p>
    pub fn get_environment_arn(&self) -> &::std::option::Option<::std::string::String> {
        self.inner.get_environment_arn()
    }
    /// <p>The sequence number of the last message you received. If the service detects a more recent sequence number, the request fails with <code>ConflictException</code>, indicating a concurrent update.</p>
    pub fn expected_sequence_number(mut self, input: i64) -> Self {
        self.inner = self.inner.expected_sequence_number(input);
        self
    }
    /// <p>The sequence number of the last message you received. If the service detects a more recent sequence number, the request fails with <code>ConflictException</code>, indicating a concurrent update.</p>
    pub fn set_expected_sequence_number(mut self, input: ::std::option::Option<i64>) -> Self {
        self.inner = self.inner.set_expected_sequence_number(input);
        self
    }
    /// <p>The sequence number of the last message you received. If the service detects a more recent sequence number, the request fails with <code>ConflictException</code>, indicating a concurrent update.</p>
    pub fn get_expected_sequence_number(&self) -> &::std::option::Option<i64> {
        self.inner.get_expected_sequence_number()
    }
}