Skip to content

Commit 5faa4ef

Browse files
committed
Fix cargo check lints
1 parent 701a3d9 commit 5faa4ef

File tree

9 files changed

+5
-198
lines changed

9 files changed

+5
-198
lines changed

crates/agent/src/api_client/endpoints.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,12 @@ pub struct Endpoint {
99
}
1010

1111
impl Endpoint {
12-
pub const CODEWHISPERER_ENDPOINTS: [Self; 2] = [Self::DEFAULT_ENDPOINT, Self::FRA_ENDPOINT];
1312
pub const DEFAULT_ENDPOINT: Self = Self {
1413
url: Cow::Borrowed("https://q.us-east-1.amazonaws.com"),
1514
region: Region::from_static("us-east-1"),
1615
};
17-
pub const FRA_ENDPOINT: Self = Self {
18-
url: Cow::Borrowed("https://q.eu-central-1.amazonaws.com/"),
19-
region: Region::from_static("eu-central-1"),
20-
};
2116

2217
pub(crate) fn url(&self) -> &str {
2318
&self.url
2419
}
25-
26-
pub(crate) fn region(&self) -> &Region {
27-
&self.region
28-
}
2920
}

crates/agent/src/api_client/error.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use amzn_codewhisperer_streaming_client::types::error::ChatResponseStreamError a
88
use amzn_qdeveloper_streaming_client::operation::send_message::SendMessageError as QDeveloperSendMessageError;
99
use amzn_qdeveloper_streaming_client::types::error::ChatResponseStreamError as QDeveloperChatResponseStreamError;
1010
use aws_credential_types::provider::error::CredentialsError;
11-
use aws_sdk_ssooidc::error::ProvideErrorMetadata;
1211
use aws_smithy_runtime_api::client::orchestrator::HttpResponse;
1312
pub use aws_smithy_runtime_api::client::result::SdkError;
1413
use aws_smithy_runtime_api::http::Response;
@@ -182,12 +181,6 @@ impl ApiClientError {
182181
// }
183182
// }
184183

185-
fn sdk_error_code<T: ProvideErrorMetadata, R>(e: &SdkError<T, R>) -> String {
186-
e.as_service_error()
187-
.and_then(|se| se.meta().code().map(str::to_string))
188-
.unwrap_or_else(|| e.to_string())
189-
}
190-
191184
fn sdk_status_code<E>(e: &SdkError<E, Response>) -> Option<u16> {
192185
e.raw_response().map(|res| res.status().as_u16())
193186
}
@@ -198,18 +191,13 @@ mod tests {
198191

199192
use aws_smithy_runtime_api::http::Response;
200193
use aws_smithy_types::body::SdkBody;
201-
use aws_smithy_types::event_stream::Message;
202194

203195
use super::*;
204196

205197
fn response() -> Response {
206198
Response::new(500.try_into().unwrap(), SdkBody::empty())
207199
}
208200

209-
fn raw_message() -> RawMessage {
210-
RawMessage::Decoded(Message::new(b"<payload>".to_vec()))
211-
}
212-
213201
fn all_errors() -> Vec<ApiClientError> {
214202
vec![
215203
ApiClientError::Credentials(CredentialsError::unhandled("<unhandled>")),

crates/agent/src/api_client/mod.rs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@ pub mod request;
77
mod retry_classifier;
88
pub mod send_message_output;
99

10-
use std::sync::{
11-
Arc,
12-
RwLock,
13-
};
1410
use std::time::Duration;
1511

16-
use amzn_codewhisperer_client::Client as CodewhispererClient;
17-
use amzn_codewhisperer_client::types::Model;
1812
use amzn_codewhisperer_streaming_client::Client as CodewhispererStreamingClient;
1913
use amzn_qdeveloper_streaming_client::Client as QDeveloperStreamingClient;
2014
use amzn_qdeveloper_streaming_client::types::Origin;
@@ -46,31 +40,13 @@ use crate::aws_common::{
4640
behavior_version,
4741
};
4842

49-
pub const X_AMZN_CODEWHISPERER_OPT_OUT_HEADER: &str = "x-amzn-codewhisperer-optout";
50-
5143
const DEFAULT_TIMEOUT_DURATION: Duration = Duration::from_secs(60 * 5);
5244

53-
#[derive(Clone, Debug)]
54-
pub struct ModelListResult {
55-
pub models: Vec<Model>,
56-
pub default_model: Model,
57-
}
58-
59-
impl From<ModelListResult> for (Vec<Model>, Model) {
60-
fn from(v: ModelListResult) -> Self {
61-
(v.models, v.default_model)
62-
}
63-
}
64-
65-
type ModelCache = Arc<RwLock<Option<ModelListResult>>>;
66-
6745
#[derive(Clone)]
6846
pub struct ApiClient {
69-
client: CodewhispererClient,
7047
streaming_client: Option<CodewhispererStreamingClient>,
7148
sigv4_streaming_client: Option<QDeveloperStreamingClient>,
7249
profile: Option<AuthProfile>,
73-
model_cache: ModelCache,
7450
}
7551

7652
impl std::fmt::Debug for ApiClient {
@@ -93,7 +69,6 @@ impl std::fmt::Debug for ApiClient {
9369
},
9470
)
9571
.field("profile", &self.profile)
96-
.field("model_cache", &self.model_cache)
9772
.finish()
9873
}
9974
}
@@ -117,17 +92,6 @@ impl ApiClient {
11792
.load()
11893
.await;
11994

120-
let client = CodewhispererClient::from_conf(
121-
amzn_codewhisperer_client::config::Builder::from(&bearer_sdk_config)
122-
.http_client(crate::aws_common::http_client::client())
123-
// .interceptor(OptOutInterceptor::new(database))
124-
.interceptor(UserAgentOverrideInterceptor::new())
125-
.bearer_token_resolver(BearerResolver)
126-
.app_name(app_name())
127-
.endpoint_url(endpoint.url())
128-
.build(),
129-
);
130-
13195
// If SIGV4_AUTH_ENABLED is true, use Q developer client
13296
let mut streaming_client = None;
13397
let mut sigv4_streaming_client = None;
@@ -177,20 +141,11 @@ impl ApiClient {
177141
}
178142

179143
let profile = None;
180-
// let profile = match database.get_auth_profile() {
181-
// Ok(profile) => profile,
182-
// Err(err) => {
183-
// error!("Failed to get auth profile: {err}");
184-
// None
185-
// },
186-
// };
187144

188145
Ok(Self {
189-
client,
190146
streaming_client,
191147
sigv4_streaming_client,
192148
profile,
193-
model_cache: Arc::new(RwLock::new(None)),
194149
})
195150
}
196151

@@ -206,8 +161,6 @@ impl ApiClient {
206161
history,
207162
} = conversation;
208163

209-
let model_id_opt: Option<String> = user_input_message.model_id.clone();
210-
211164
if let Some(client) = &self.streaming_client {
212165
let conversation_state = amzn_codewhisperer_streaming_client::types::ConversationState::builder()
213166
.set_conversation_id(conversation_id)

crates/agent/src/auth/consts.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use aws_types::region::Region;
22

3-
pub(crate) const CLIENT_NAME: &str = "Amazon Q Developer for command line";
4-
53
pub(crate) const OIDC_BUILDER_ID_REGION: Region = Region::from_static("us-east-1");
64

75
/// The scopes requested for OIDC
@@ -16,13 +14,10 @@ pub(crate) const SCOPES: &[&str] = &[
1614
// "codewhisperer:transformations",
1715
];
1816

19-
pub(crate) const CLIENT_TYPE: &str = "public";
20-
2117
// The start URL for public builder ID users
2218
pub const START_URL: &str = "https://view.awsapps.com/start";
2319

2420
// The start URL for internal amzn users
2521
pub const AMZN_START_URL: &str = "https://amzn.awsapps.com/start";
2622

27-
pub(crate) const DEVICE_GRANT_TYPE: &str = "urn:ietf:params:oauth:grant-type:device_code";
2823
pub(crate) const REFRESH_GRANT_TYPE: &str = "refresh_token";

crates/agent/src/auth/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
pub mod builder_id;
22
mod consts;
3-
mod scope;
43

54
use aws_sdk_ssooidc::error::SdkError;
65
use aws_sdk_ssooidc::operation::create_token::CreateTokenError;

crates/agent/src/auth/scope.rs

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

crates/agent/src/cli/chat.rs

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

crates/agent/src/cli/mod.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
pub mod chat;
21
mod run;
32

43
use std::process::ExitCode;
54

6-
use chat::ChatArgs;
75
use clap::{
86
ArgAction,
97
Parser,
@@ -14,7 +12,6 @@ use eyre::{
1412
Result,
1513
};
1614
use run::RunArgs;
17-
use tracing::Level;
1815
use tracing_appender::non_blocking::{
1916
NonBlocking,
2017
WorkerGuard,
@@ -41,27 +38,14 @@ pub struct CliArgs {
4138

4239
impl CliArgs {
4340
pub async fn execute(self) -> Result<ExitCode> {
44-
let _guard = self.setup_logging().context("failed to initialize logging")?;
41+
let _guard = Self::setup_logging().context("failed to initialize logging")?;
4542

4643
let subcommand = self.subcommand.unwrap_or_default();
4744

4845
subcommand.execute().await
4946
}
5047

51-
fn setup_logging(&self) -> Result<WorkerGuard> {
52-
let log_level = match self.verbose > 0 {
53-
true => Some(
54-
match self.verbose {
55-
1 => Level::WARN,
56-
2 => Level::INFO,
57-
3 => Level::DEBUG,
58-
_ => Level::TRACE,
59-
}
60-
.to_string(),
61-
),
62-
false => None,
63-
};
64-
48+
fn setup_logging() -> Result<WorkerGuard> {
6549
let env_filter = EnvFilter::try_from_default_env().unwrap_or_default();
6650
let (non_blocking, _file_guard) = NonBlocking::new(RollingFileAppender::new(Rotation::NEVER, ".", "chat.log"));
6751
let file_layer = tracing_subscriber::fmt::layer().with_writer(non_blocking);
@@ -75,23 +59,20 @@ impl CliArgs {
7559

7660
#[derive(Debug, Clone, Subcommand)]
7761
pub enum RootSubcommand {
78-
/// TUI Chat Interface
79-
Chat(ChatArgs),
8062
/// Run a single prompt
8163
Run(RunArgs),
8264
}
8365

8466
impl RootSubcommand {
8567
pub async fn execute(self) -> Result<ExitCode> {
8668
match self {
87-
RootSubcommand::Chat(chat_args) => chat_args.execute().await,
8869
RootSubcommand::Run(run_args) => run_args.execute().await,
8970
}
9071
}
9172
}
9273

9374
impl Default for RootSubcommand {
9475
fn default() -> Self {
95-
Self::Chat(Default::default())
76+
Self::Run(Default::default())
9677
}
9778
}

crates/agent/src/cli/run.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,8 @@ use serde::{
2323
Deserialize,
2424
Serialize,
2525
};
26-
use tokio::io::AsyncWriteExt;
2726
use tracing::warn;
2827

29-
// use crate::chat::{
30-
// ActiveState,
31-
// ApprovalResult,
32-
// InputItem,
33-
// SendApprovalResultArgs,
34-
// SendPromptArgs,
35-
// Session,
36-
// SessionBuilder,
37-
// SessionEvent,
38-
// SessionEventKind,
39-
// SessionInitWarning,
40-
// SessionNotification,
41-
// };
42-
4328
#[derive(Debug, Clone, Default, Args)]
4429
pub struct RunArgs {
4530
/// The name of the agent to run the session with.
@@ -106,7 +91,7 @@ impl RunArgs {
10691
}
10792
},
10893
AgentEvent::RequestError(loop_error) => bail!("agent encountered an error: {:?}", loop_error),
109-
AgentEvent::ApprovalRequest { id, tool_use, context } => {
94+
AgentEvent::ApprovalRequest { id, tool_use, .. } => {
11095
if !self.dangerously_trust_all_tools {
11196
bail!("Tool approval is required: {:?}", tool_use);
11297
} else {
@@ -137,7 +122,7 @@ impl RunArgs {
137122
match &evt.kind {
138123
AgentLoopEventKind::AssistantText(text) => {
139124
print!("{}", text);
140-
std::io::stdout().flush();
125+
let _ = std::io::stdout().flush();
141126
},
142127
AgentLoopEventKind::ToolUse(tool_use) => {
143128
print!("\n{}\n", serde_json::to_string_pretty(tool_use).expect("does not fail"));

0 commit comments

Comments
 (0)