Skip to content

Commit e3552c2

Browse files
committed
fix: allow diagnostic without auth
1 parent 8ff6db8 commit e3552c2

File tree

6 files changed

+44
-23
lines changed

6 files changed

+44
-23
lines changed

crates/chat-cli/src/cli/agent/root_command_args.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,16 @@ pub struct AgentArgs {
8181
impl AgentArgs {
8282
pub async fn execute(self, os: &mut Os) -> Result<ExitCode> {
8383
let mut stderr = std::io::stderr();
84-
let mcp_enabled = match os.client.is_mcp_enabled().await {
85-
Ok(enabled) => enabled,
86-
Err(err) => {
87-
tracing::warn!(?err, "Failed to check MCP configuration, defaulting to enabled");
84+
let mcp_enabled = match os.client.as_ref() {
85+
Some(client) => match client.is_mcp_enabled().await {
86+
Ok(enabled) => enabled,
87+
Err(err) => {
88+
tracing::warn!(?err, "Failed to check MCP configuration, defaulting to enabled");
89+
true
90+
},
91+
},
92+
None => {
93+
tracing::debug!("API client not available, defaulting MCP to enabled");
8894
true
8995
},
9096
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ pub async fn get_available_models(os: &Os) -> Result<(Vec<ModelInfo>, ModelInfo)
174174
let endpoint = Endpoint::configured_value(&os.database);
175175
let region = endpoint.region().as_ref();
176176

177-
match os.client.get_available_models(region).await {
177+
match os.client.as_ref().unwrap().get_available_models(region).await {
178178
Ok(api_res) => {
179179
let models: Vec<ModelInfo> = api_res.models.iter().map(ModelInfo::from_api_model).collect();
180180
let default_model = ModelInfo::from_api_model(&api_res.default_model);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ async fn upgrade_to_pro(os: &mut Os, session: &mut ChatSession) -> Result<(), Ch
162162
}
163163

164164
// Create a subscription token and open the webpage
165-
let r = os.client.create_subscription_token().await?;
165+
let r = os.client.as_ref().unwrap().create_subscription_token().await?;
166166

167167
let url = with_spinner(&mut session.stderr, "Preparing to upgrade...", || async move {
168168
r.encoded_verification_url()

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl ChatArgs {
297297
info!(?conversation_id, "Generated new conversation id");
298298

299299
// Check MCP status once at the beginning of the session
300-
let mcp_enabled = match os.client.is_mcp_enabled().await {
300+
let mcp_enabled = match os.client.as_ref().unwrap().is_mcp_enabled().await {
301301
Ok(enabled) => enabled,
302302
Err(err) => {
303303
tracing::warn!(?err, "Failed to check MCP configuration, defaulting to enabled");
@@ -1222,7 +1222,7 @@ impl ChatSession {
12221222
request_metadata_lock: Arc<Mutex<Option<RequestMetadata>>>,
12231223
message_meta_tags: Option<Vec<MessageMetaTag>>,
12241224
) -> Result<SendMessageStream, ChatError> {
1225-
match SendMessageStream::send_message(&os.client, conversation_state, request_metadata_lock, message_meta_tags)
1225+
match SendMessageStream::send_message(os.client.as_ref().unwrap(), conversation_state, request_metadata_lock, message_meta_tags)
12261226
.await
12271227
{
12281228
Ok(res) => Ok(res),
@@ -3329,7 +3329,7 @@ impl ChatSession {
33293329
}
33303330

33313331
async fn retry_model_overload(&mut self, os: &mut Os) -> Result<ChatState, ChatError> {
3332-
os.client.invalidate_model_cache().await;
3332+
os.client.as_ref().unwrap().invalidate_model_cache().await;
33333333
match select_model(os, self).await {
33343334
Ok(Some(_)) => (),
33353335
Ok(None) => {
@@ -3752,7 +3752,7 @@ async fn get_subscription_status(os: &mut Os) -> Result<ActualSubscriptionStatus
37523752
return Ok(ActualSubscriptionStatus::Active);
37533753
}
37543754

3755-
match os.client.create_subscription_token().await {
3755+
match os.client.as_ref().unwrap().create_subscription_token().await {
37563756
Ok(response) => match response.status() {
37573757
SubscriptionStatus::Active => Ok(ActualSubscriptionStatus::Expiring),
37583758
SubscriptionStatus::Inactive => Ok(ActualSubscriptionStatus::None),
@@ -3892,7 +3892,7 @@ mod tests {
38923892
#[tokio::test]
38933893
async fn test_flow() {
38943894
let mut os = Os::new().await.unwrap();
3895-
os.client.set_mock_output(serde_json::json!([
3895+
os.client.as_mut().unwrap().set_mock_output(serde_json::json!([
38963896
[
38973897
"Sure, I'll create a file for you",
38983898
{
@@ -3945,7 +3945,7 @@ mod tests {
39453945
#[tokio::test]
39463946
async fn test_flow_tool_permissions() {
39473947
let mut os = Os::new().await.unwrap();
3948-
os.client.set_mock_output(serde_json::json!([
3948+
os.client.as_mut().unwrap().set_mock_output(serde_json::json!([
39493949
[
39503950
"Ok",
39513951
{
@@ -4092,7 +4092,7 @@ mod tests {
40924092
async fn test_flow_multiple_tools() {
40934093
// let _ = tracing_subscriber::fmt::try_init();
40944094
let mut os = Os::new().await.unwrap();
4095-
os.client.set_mock_output(serde_json::json!([
4095+
os.client.as_mut().unwrap().set_mock_output(serde_json::json!([
40964096
[
40974097
"Sure, I'll create a file for you",
40984098
{
@@ -4186,7 +4186,7 @@ mod tests {
41864186
async fn test_flow_tools_trust_all() {
41874187
// let _ = tracing_subscriber::fmt::try_init();
41884188
let mut os = Os::new().await.unwrap();
4189-
os.client.set_mock_output(serde_json::json!([
4189+
os.client.as_mut().unwrap().set_mock_output(serde_json::json!([
41904190
[
41914191
"Sure, I'll create a file for you",
41924192
{
@@ -4273,7 +4273,7 @@ mod tests {
42734273
#[cfg(unix)]
42744274
async fn test_subscribe_flow() {
42754275
let mut os = Os::new().await.unwrap();
4276-
os.client.set_mock_output(serde_json::Value::Array(vec![]));
4276+
os.client.as_mut().unwrap().set_mock_output(serde_json::Value::Array(vec![]));
42774277
let agents = get_test_agents(&os).await;
42784278

42794279
let tool_manager = ToolManager::default();
@@ -4315,7 +4315,7 @@ mod tests {
43154315
};
43164316

43174317
let mut os = Os::new().await.unwrap();
4318-
os.client.set_mock_output(serde_json::json!([
4318+
os.client.as_mut().unwrap().set_mock_output(serde_json::json!([
43194319
[
43204320
"I'll read that file for you",
43214321
{
@@ -4463,7 +4463,7 @@ mod tests {
44634463
os.fs.write("/sensitive.txt", "classified information").await.unwrap();
44644464

44654465
// Mock LLM responses: first tries fs_read, gets blocked, then responds to error
4466-
os.client.set_mock_output(serde_json::json!([
4466+
os.client.as_mut().unwrap().set_mock_output(serde_json::json!([
44674467
[
44684468
"I'll read that file for you",
44694469
{

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,16 @@ impl StatusArgs {
435435
async fn get_mcp_server_configs(os: &mut Os) -> Result<BTreeMap<Scope, Vec<(String, Option<McpServerConfig>, bool)>>> {
436436
let mut results = BTreeMap::new();
437437
let mut stderr = std::io::stderr();
438-
let mcp_enabled = match os.client.is_mcp_enabled().await {
439-
Ok(enabled) => enabled,
440-
Err(err) => {
441-
tracing::warn!(?err, "Failed to check MCP configuration, defaulting to enabled");
438+
let mcp_enabled = match os.client.as_ref() {
439+
Some(client) => match client.is_mcp_enabled().await {
440+
Ok(enabled) => enabled,
441+
Err(err) => {
442+
tracing::warn!(?err, "Failed to check MCP configuration, defaulting to enabled");
443+
true
444+
},
445+
},
446+
None => {
447+
tracing::debug!("API client not available, defaulting MCP to enabled");
442448
true
443449
},
444450
};

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub struct Os {
3636
pub fs: Fs,
3737
pub sysinfo: SysInfo,
3838
pub database: Database,
39-
pub client: ApiClient,
39+
pub client: Option<ApiClient>,
4040
pub telemetry: TelemetryThread,
4141
}
4242

@@ -45,7 +45,16 @@ impl Os {
4545
let env = Env::new();
4646
let fs = Fs::new();
4747
let mut database = Database::new().await?;
48-
let client = ApiClient::new(&env, &fs, &mut database, None).await?;
48+
49+
// Try to initialize ApiClient, but don't fail if it's not possible
50+
let client = match ApiClient::new(&env, &fs, &mut database, None).await {
51+
Ok(client) => Some(client),
52+
Err(err) => {
53+
tracing::debug!("Failed to initialize ApiClient: {err}");
54+
None
55+
}
56+
};
57+
4958
let telemetry = TelemetryThread::new(&env, &fs, &mut database).await?;
5059

5160
Ok(Self {

0 commit comments

Comments
 (0)