Skip to content

Commit e457594

Browse files
committed
merge
1 parent e5b134d commit e457594

File tree

30 files changed

+175
-579
lines changed

30 files changed

+175
-579
lines changed

crates/chat-cli/src/api_client/clients/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl Client {
8282
) -> Result<(), ApiClientError> {
8383
match &self.inner {
8484
inner::Inner::Codewhisperer(client) => {
85-
let _ = client
85+
client
8686
.send_telemetry_event()
8787
.telemetry_event(telemetry_event)
8888
.user_context(user_context)
@@ -93,7 +93,7 @@ impl Client {
9393
.set_profile_arn(self.profile.as_ref().map(|p| p.arn.clone()))
9494
.set_model_id(model_id)
9595
.send()
96-
.await;
96+
.await?;
9797
Ok(())
9898
},
9999
inner::Inner::Mock => Ok(()),

crates/chat-cli/src/api_client/clients/shared.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ use aws_credential_types::provider::ProvideCredentials;
88
use aws_types::SdkConfig;
99
use aws_types::sdk_config::StalledStreamProtectionConfig;
1010

11-
use crate::api_client::credentials::CredentialsChain;
12-
use crate::api_client::{
13-
ApiClientError,
14-
Endpoint,
15-
};
11+
use crate::api_client::Endpoint;
1612
use crate::aws_common::behavior_version;
1713
use crate::database::Database;
1814
use crate::database::settings::Setting;
@@ -59,13 +55,3 @@ pub async fn bearer_sdk_config(database: &Database, endpoint: &Endpoint) -> SdkC
5955
let credentials = Credentials::new("xxx", "xxx", None, None, "xxx");
6056
base_sdk_config(database, endpoint.region().clone(), credentials).await
6157
}
62-
63-
pub async fn sigv4_sdk_config(database: &Database, endpoint: &Endpoint) -> Result<SdkConfig, ApiClientError> {
64-
let credentials_chain = CredentialsChain::new().await;
65-
66-
if let Err(err) = credentials_chain.provide_credentials().await {
67-
return Err(ApiClientError::Credentials(err));
68-
};
69-
70-
Ok(base_sdk_config(database, endpoint.region().clone(), credentials_chain).await)
71-
}

crates/chat-cli/src/api_client/clients/streaming_client.rs

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::sync::{
44
};
55

66
use amzn_codewhisperer_streaming_client::Client as CodewhispererStreamingClient;
7-
use amzn_qdeveloper_streaming_client::Client as QDeveloperStreamingClient;
87
use aws_types::request_id::RequestId;
98
use tracing::{
109
debug,
@@ -13,7 +12,6 @@ use tracing::{
1312

1413
use super::shared::{
1514
bearer_sdk_config,
16-
sigv4_sdk_config,
1715
stalled_stream_protection_config,
1816
};
1917
use crate::api_client::interceptor::opt_out::OptOutInterceptor;
@@ -42,14 +40,12 @@ mod inner {
4240
};
4341

4442
use amzn_codewhisperer_streaming_client::Client as CodewhispererStreamingClient;
45-
use amzn_qdeveloper_streaming_client::Client as QDeveloperStreamingClient;
4643

4744
use crate::api_client::model::ChatResponseStream;
4845

4946
#[derive(Clone, Debug)]
5047
pub enum Inner {
5148
Codewhisperer(CodewhispererStreamingClient),
52-
QDeveloper(QDeveloperStreamingClient),
5349
Mock(Arc<Mutex<std::vec::IntoIter<Vec<ChatResponseStream>>>>),
5450
}
5551
}
@@ -62,15 +58,7 @@ pub struct StreamingClient {
6258

6359
impl StreamingClient {
6460
pub async fn new(database: &mut Database) -> Result<Self, ApiClientError> {
65-
Ok(
66-
if crate::util::system_info::in_cloudshell()
67-
|| std::env::var("Q_USE_SENDMESSAGE").is_ok_and(|v| !v.is_empty())
68-
{
69-
Self::new_qdeveloper_client(database, &Endpoint::load_q(database)).await?
70-
} else {
71-
Self::new_codewhisperer_client(database, &Endpoint::load_codewhisperer(database)).await?
72-
},
73-
)
61+
Self::new_codewhisperer_client(database, &Endpoint::load_codewhisperer(database)).await
7462
}
7563

7664
pub fn mock(events: Vec<Vec<ChatResponseStream>>) -> Self {
@@ -108,24 +96,6 @@ impl StreamingClient {
10896
Ok(Self { inner, profile })
10997
}
11098

111-
pub async fn new_qdeveloper_client(database: &Database, endpoint: &Endpoint) -> Result<Self, ApiClientError> {
112-
let conf_builder: amzn_qdeveloper_streaming_client::config::Builder =
113-
(&sigv4_sdk_config(database, endpoint).await?).into();
114-
let conf = conf_builder
115-
.http_client(crate::aws_common::http_client::client())
116-
.interceptor(OptOutInterceptor::new(database))
117-
.interceptor(UserAgentOverrideInterceptor::new())
118-
.app_name(app_name())
119-
.endpoint_url(endpoint.url())
120-
.stalled_stream_protection(stalled_stream_protection_config())
121-
.build();
122-
let client = QDeveloperStreamingClient::from_conf(conf);
123-
Ok(Self {
124-
inner: inner::Inner::QDeveloper(client),
125-
profile: None,
126-
})
127-
}
128-
12999
pub async fn send_message(
130100
&self,
131101
conversation_state: ConversationState,
@@ -193,27 +163,6 @@ impl StreamingClient {
193163
},
194164
}
195165
},
196-
inner::Inner::QDeveloper(client) => {
197-
let conversation_state_builder = amzn_qdeveloper_streaming_client::types::ConversationState::builder()
198-
.set_conversation_id(conversation_id)
199-
.current_message(amzn_qdeveloper_streaming_client::types::ChatMessage::UserInputMessage(
200-
user_input_message.into(),
201-
))
202-
.chat_trigger_type(amzn_qdeveloper_streaming_client::types::ChatTriggerType::Manual)
203-
.set_history(
204-
history
205-
.map(|v| v.into_iter().map(|i| i.try_into()).collect::<Result<Vec<_>, _>>())
206-
.transpose()?,
207-
);
208-
209-
Ok(SendMessageOutput::QDeveloper(
210-
client
211-
.send_message()
212-
.conversation_state(conversation_state_builder.build().expect("fix me"))
213-
.send()
214-
.await?,
215-
))
216-
},
217166
inner::Inner::Mock(events) => {
218167
let mut new_events = events.lock().unwrap().next().unwrap_or_default().clone();
219168
new_events.reverse();
@@ -228,15 +177,13 @@ pub enum SendMessageOutput {
228177
Codewhisperer(
229178
amzn_codewhisperer_streaming_client::operation::generate_assistant_response::GenerateAssistantResponseOutput,
230179
),
231-
QDeveloper(amzn_qdeveloper_streaming_client::operation::send_message::SendMessageOutput),
232180
Mock(Vec<ChatResponseStream>),
233181
}
234182

235183
impl SendMessageOutput {
236184
pub fn request_id(&self) -> Option<&str> {
237185
match self {
238186
SendMessageOutput::Codewhisperer(output) => output.request_id(),
239-
SendMessageOutput::QDeveloper(output) => output.request_id(),
240187
SendMessageOutput::Mock(_) => None,
241188
}
242189
}
@@ -248,7 +195,6 @@ impl SendMessageOutput {
248195
.recv()
249196
.await?
250197
.map(|s| s.into())),
251-
SendMessageOutput::QDeveloper(output) => Ok(output.send_message_response.recv().await?.map(|s| s.into())),
252198
SendMessageOutput::Mock(vec) => Ok(vec.pop()),
253199
}
254200
}
@@ -258,7 +204,6 @@ impl RequestId for SendMessageOutput {
258204
fn request_id(&self) -> Option<&str> {
259205
match self {
260206
SendMessageOutput::Codewhisperer(output) => output.request_id(),
261-
SendMessageOutput::QDeveloper(output) => output.request_id(),
262207
SendMessageOutput::Mock(_) => Some("<mock-request-id>"),
263208
}
264209
}
@@ -280,7 +225,6 @@ mod tests {
280225

281226
let _ = StreamingClient::new(&mut database).await;
282227
let _ = StreamingClient::new_codewhisperer_client(&mut database, &endpoint).await;
283-
let _ = StreamingClient::new_qdeveloper_client(&database, &endpoint).await;
284228
}
285229

286230
#[tokio::test]

crates/chat-cli/src/api_client/consts.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ use aws_config::Region;
44
pub const PROD_CODEWHISPERER_ENDPOINT_URL: &str = "https://codewhisperer.us-east-1.amazonaws.com";
55
pub const PROD_CODEWHISPERER_ENDPOINT_REGION: Region = Region::from_static("us-east-1");
66

7-
pub const PROD_Q_ENDPOINT_URL: &str = "https://q.us-east-1.amazonaws.com";
8-
pub const PROD_Q_ENDPOINT_REGION: Region = Region::from_static("us-east-1");
9-
107
// FRA endpoint constants
118
pub const PROD_CODEWHISPERER_FRA_ENDPOINT_URL: &str = "https://q.eu-central-1.amazonaws.com/";
129
pub const PROD_CODEWHISPERER_FRA_ENDPOINT_REGION: Region = Region::from_static("eu-central-1");

crates/chat-cli/src/api_client/credentials/mod.rs

Lines changed: 0 additions & 80 deletions
This file was deleted.

crates/chat-cli/src/api_client/endpoints.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use crate::api_client::consts::{
99
PROD_CODEWHISPERER_ENDPOINT_URL,
1010
PROD_CODEWHISPERER_FRA_ENDPOINT_REGION,
1111
PROD_CODEWHISPERER_FRA_ENDPOINT_URL,
12-
PROD_Q_ENDPOINT_REGION,
13-
PROD_Q_ENDPOINT_URL,
1412
};
1513
use crate::database::Database;
1614
use crate::database::settings::Setting;
@@ -30,10 +28,6 @@ impl Endpoint {
3028
url: Cow::Borrowed(PROD_CODEWHISPERER_ENDPOINT_URL),
3129
region: PROD_CODEWHISPERER_ENDPOINT_REGION,
3230
};
33-
pub const PROD_Q: Self = Self {
34-
url: Cow::Borrowed(PROD_Q_ENDPOINT_URL),
35-
region: PROD_Q_ENDPOINT_REGION,
36-
};
3731

3832
pub fn load_codewhisperer(database: &Database) -> Self {
3933
let (endpoint, region) = if let Some(Value::Object(o)) = database.settings.get(Setting::ApiCodeWhispererService)
@@ -69,24 +63,6 @@ impl Endpoint {
6963
}
7064
}
7165

72-
pub fn load_q(database: &Database) -> Self {
73-
match database.settings.get(Setting::ApiQService) {
74-
Some(Value::Object(o)) => {
75-
let endpoint = o.get("endpoint").and_then(|v| v.as_str());
76-
let region = o.get("region").and_then(|v| v.as_str());
77-
78-
match (endpoint, region) {
79-
(Some(endpoint), Some(region)) => Self {
80-
url: endpoint.to_owned().into(),
81-
region: Region::new(region.to_owned()),
82-
},
83-
_ => Endpoint::PROD_Q,
84-
}
85-
},
86-
_ => Endpoint::PROD_Q,
87-
}
88-
}
89-
9066
pub(crate) fn url(&self) -> &str {
9167
&self.url
9268
}
@@ -106,7 +82,6 @@ mod tests {
10682
async fn test_endpoints() {
10783
let database = Database::new().await.unwrap();
10884
let _ = Endpoint::load_codewhisperer(&database);
109-
let _ = Endpoint::load_q(&database);
11085

11186
let prod = &Endpoint::DEFAULT_ENDPOINT;
11287
Url::parse(prod.url()).unwrap();

crates/chat-cli/src/api_client/error.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use amzn_codewhisperer_client::operation::generate_completions::GenerateCompletionsError;
22
use amzn_codewhisperer_client::operation::list_available_customizations::ListAvailableCustomizationsError;
33
use amzn_codewhisperer_client::operation::list_available_profiles::ListAvailableProfilesError;
4+
use amzn_codewhisperer_client::operation::send_telemetry_event::SendTelemetryEventError;
45
pub use amzn_codewhisperer_streaming_client::operation::generate_assistant_response::GenerateAssistantResponseError;
56
use amzn_codewhisperer_streaming_client::types::error::ChatResponseStreamError as CodewhispererChatResponseStreamError;
67
use amzn_consolas_client::operation::generate_recommendations::GenerateRecommendationsError;
78
use amzn_consolas_client::operation::list_customizations::ListCustomizationsError;
89
use amzn_qdeveloper_streaming_client::operation::send_message::SendMessageError as QDeveloperSendMessageError;
910
use amzn_qdeveloper_streaming_client::types::error::ChatResponseStreamError as QDeveloperChatResponseStreamError;
10-
use aws_credential_types::provider::error::CredentialsError;
1111
use aws_smithy_runtime_api::client::orchestrator::HttpResponse;
1212
pub use aws_smithy_runtime_api::client::result::SdkError;
1313
use aws_smithy_types::event_stream::RawMessage;
@@ -18,9 +18,6 @@ use crate::aws_common::SdkErrorDisplay;
1818

1919
#[derive(Debug, Error)]
2020
pub enum ApiClientError {
21-
#[error("failed to load credentials: {}", .0)]
22-
Credentials(CredentialsError),
23-
2421
// Generate completions errors
2522
#[error("{}", SdkErrorDisplay(.0))]
2623
GenerateCompletions(#[from] SdkError<GenerateCompletionsError, HttpResponse>),
@@ -33,6 +30,10 @@ pub enum ApiClientError {
3330
#[error("{}", SdkErrorDisplay(.0))]
3431
ListAvailableServices(#[from] SdkError<ListCustomizationsError, HttpResponse>),
3532

33+
// Telemetry client error
34+
#[error("{}", SdkErrorDisplay(.0))]
35+
SendTelemetryEvent(#[from] SdkError<SendTelemetryEventError, HttpResponse>),
36+
3637
// Send message errors
3738
#[error("{}", SdkErrorDisplay(.0))]
3839
CodewhispererGenerateAssistantResponse(#[from] SdkError<GenerateAssistantResponseError, HttpResponse>),
@@ -92,7 +93,6 @@ mod tests {
9293

9394
fn all_errors() -> Vec<ApiClientError> {
9495
vec![
95-
ApiClientError::Credentials(CredentialsError::unhandled("<unhandled>")),
9696
ApiClientError::GenerateCompletions(SdkError::service_error(
9797
GenerateCompletionsError::unhandled("<unhandled>"),
9898
response(),

crates/chat-cli/src/api_client/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
pub mod clients;
22
pub(crate) mod consts;
3-
pub(crate) mod credentials;
43
pub mod customization;
54
mod endpoints;
65
mod error;

0 commit comments

Comments
 (0)