Skip to content

Commit 84e22bb

Browse files
authored
remove cloudshell special casing (#156)
1 parent 8aad335 commit 84e22bb

File tree

21 files changed

+78
-298
lines changed

21 files changed

+78
-298
lines changed

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,
@@ -180,27 +150,6 @@ impl StreamingClient {
180150
},
181151
}
182152
},
183-
inner::Inner::QDeveloper(client) => {
184-
let conversation_state_builder = amzn_qdeveloper_streaming_client::types::ConversationState::builder()
185-
.set_conversation_id(conversation_id)
186-
.current_message(amzn_qdeveloper_streaming_client::types::ChatMessage::UserInputMessage(
187-
user_input_message.into(),
188-
))
189-
.chat_trigger_type(amzn_qdeveloper_streaming_client::types::ChatTriggerType::Manual)
190-
.set_history(
191-
history
192-
.map(|v| v.into_iter().map(|i| i.try_into()).collect::<Result<Vec<_>, _>>())
193-
.transpose()?,
194-
);
195-
196-
Ok(SendMessageOutput::QDeveloper(
197-
client
198-
.send_message()
199-
.conversation_state(conversation_state_builder.build().expect("fix me"))
200-
.send()
201-
.await?,
202-
))
203-
},
204153
inner::Inner::Mock(events) => {
205154
let mut new_events = events.lock().unwrap().next().unwrap_or_default().clone();
206155
new_events.reverse();
@@ -215,15 +164,13 @@ pub enum SendMessageOutput {
215164
Codewhisperer(
216165
amzn_codewhisperer_streaming_client::operation::generate_assistant_response::GenerateAssistantResponseOutput,
217166
),
218-
QDeveloper(amzn_qdeveloper_streaming_client::operation::send_message::SendMessageOutput),
219167
Mock(Vec<ChatResponseStream>),
220168
}
221169

222170
impl SendMessageOutput {
223171
pub fn request_id(&self) -> Option<&str> {
224172
match self {
225173
SendMessageOutput::Codewhisperer(output) => output.request_id(),
226-
SendMessageOutput::QDeveloper(output) => output.request_id(),
227174
SendMessageOutput::Mock(_) => None,
228175
}
229176
}
@@ -235,7 +182,6 @@ impl SendMessageOutput {
235182
.recv()
236183
.await?
237184
.map(|s| s.into())),
238-
SendMessageOutput::QDeveloper(output) => Ok(output.send_message_response.recv().await?.map(|s| s.into())),
239185
SendMessageOutput::Mock(vec) => Ok(vec.pop()),
240186
}
241187
}
@@ -245,7 +191,6 @@ impl RequestId for SendMessageOutput {
245191
fn request_id(&self) -> Option<&str> {
246192
match self {
247193
SendMessageOutput::Codewhisperer(output) => output.request_id(),
248-
SendMessageOutput::QDeveloper(output) => output.request_id(),
249194
SendMessageOutput::Mock(_) => Some("<mock-request-id>"),
250195
}
251196
}
@@ -267,7 +212,6 @@ mod tests {
267212

268213
let _ = StreamingClient::new(&mut database).await;
269214
let _ = StreamingClient::new_codewhisperer_client(&mut database, &endpoint).await;
270-
let _ = StreamingClient::new_qdeveloper_client(&database, &endpoint).await;
271215
}
272216

273217
#[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: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use amzn_consolas_client::operation::generate_recommendations::GenerateRecommend
77
use amzn_consolas_client::operation::list_customizations::ListCustomizationsError;
88
use amzn_qdeveloper_streaming_client::operation::send_message::SendMessageError as QDeveloperSendMessageError;
99
use amzn_qdeveloper_streaming_client::types::error::ChatResponseStreamError as QDeveloperChatResponseStreamError;
10-
use aws_credential_types::provider::error::CredentialsError;
1110
use aws_smithy_runtime_api::client::orchestrator::HttpResponse;
1211
pub use aws_smithy_runtime_api::client::result::SdkError;
1312
use aws_smithy_types::event_stream::RawMessage;
@@ -18,9 +17,6 @@ use crate::aws_common::SdkErrorDisplay;
1817

1918
#[derive(Debug, Error)]
2019
pub enum ApiClientError {
21-
#[error("failed to load credentials: {}", .0)]
22-
Credentials(CredentialsError),
23-
2420
// Generate completions errors
2521
#[error("{}", SdkErrorDisplay(.0))]
2622
GenerateCompletions(#[from] SdkError<GenerateCompletionsError, HttpResponse>),
@@ -87,7 +83,6 @@ mod tests {
8783

8884
fn all_errors() -> Vec<ApiClientError> {
8985
vec![
90-
ApiClientError::Credentials(CredentialsError::unhandled("<unhandled>")),
9186
ApiClientError::GenerateCompletions(SdkError::service_error(
9287
GenerateCompletionsError::unhandled("<unhandled>"),
9388
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;

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ use util::{
141141
animate_output,
142142
drop_matched_context_files,
143143
play_notification_bell,
144-
region_check,
145144
};
146145
use uuid::Uuid;
147146
use winnow::Partial;
@@ -166,7 +165,6 @@ use crate::telemetry::{
166165
TelemetryResult,
167166
TelemetryThread,
168167
};
169-
use crate::util::CLI_BINARY_NAME;
170168

171169
#[derive(Debug, Clone, PartialEq, Eq, Default, Args)]
172170
pub struct ChatArgs {
@@ -197,15 +195,6 @@ pub struct ChatArgs {
197195

198196
impl ChatArgs {
199197
pub async fn execute(self, database: &mut Database, telemetry: &TelemetryThread) -> Result<ExitCode> {
200-
if !crate::util::system_info::in_cloudshell() && !crate::auth::is_logged_in(database).await {
201-
bail!(
202-
"You are not logged in, please log in with {}",
203-
format!("{CLI_BINARY_NAME} login").bold()
204-
);
205-
}
206-
207-
region_check("chat")?;
208-
209198
let ctx = Context::new();
210199

211200
let stdin = std::io::stdin();

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,6 @@ use eyre::Result;
1414

1515
use super::ChatError;
1616
use super::token_counter::TokenCounter;
17-
use crate::util::system_info::in_cloudshell;
18-
19-
const GOV_REGIONS: &[&str] = &["us-gov-east-1", "us-gov-west-1"];
20-
21-
pub fn region_check(capability: &'static str) -> eyre::Result<()> {
22-
let Ok(region) = std::env::var("AWS_REGION") else {
23-
return Ok(());
24-
};
25-
26-
if in_cloudshell() && GOV_REGIONS.contains(&region.as_str()) {
27-
eyre::bail!("AWS GovCloud ({region}) is not supported for {capability}.");
28-
}
29-
30-
Ok(())
31-
}
3217

3318
pub fn truncate_safe(s: &str, max_bytes: usize) -> &str {
3419
if s.len() <= max_bytes {

0 commit comments

Comments
 (0)