Skip to content

Commit beb60a2

Browse files
authored
Revert "feat(oauth): implement authentication flow with login and logout (#442)"
This reverts commit 14dac83.
1 parent 14dac83 commit beb60a2

37 files changed

+215
-2819
lines changed

Cargo.lock

+49-1,395
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/forge_api/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ forge_stream = { path = "../forge_stream" }
1111
forge_app = { path = "../forge_app" }
1212
forge_walker = { path = "../forge_walker" }
1313
forge_infra = { path = "../forge_infra" }
14-
forge_oauth = { path = "../forge_oauth" }
1514
serde_yaml = "0.9.34"
1615
serde_json = { version = "1.0" }
1716

crates/forge_api/src/api.rs

+1-17
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ use std::path::Path;
22
use std::sync::Arc;
33

44
use anyhow::Result;
5-
use forge_app::{CredentialRepository, EnvironmentService, ForgeApp, Infrastructure};
5+
use forge_app::{EnvironmentService, ForgeApp, Infrastructure};
66
use forge_domain::*;
77
use forge_infra::ForgeInfra;
8-
use forge_oauth::AuthFlowState;
98
use forge_stream::MpscStream;
109
use serde_json::Value;
1110

@@ -65,21 +64,6 @@ impl<F: App + Infrastructure> API for ForgeAPI<F> {
6564
self.app.conversation_service().create(workflow).await
6665
}
6766

68-
fn init_login(&self) -> AuthFlowState {
69-
self.app.credential_repository().create()
70-
}
71-
72-
async fn login(&self, auth_flow_state: AuthFlowState) -> anyhow::Result<()> {
73-
self.app
74-
.credential_repository()
75-
.authenticate(auth_flow_state)
76-
.await
77-
}
78-
79-
fn logout(&self) -> anyhow::Result<bool> {
80-
self.app.credential_repository().delete()
81-
}
82-
8367
fn environment(&self) -> Environment {
8468
self.app.environment_service().get_environment().clone()
8569
}

crates/forge_api/src/lib.rs

-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::path::Path;
77

88
pub use api::*;
99
pub use forge_domain::*;
10-
use forge_oauth::AuthFlowState;
1110
use forge_stream::MpscStream;
1211
use serde_json::Value;
1312

@@ -30,14 +29,6 @@ pub trait API {
3029
chat: ChatRequest,
3130
) -> anyhow::Result<MpscStream<anyhow::Result<AgentMessage<ChatResponse>, anyhow::Error>>>;
3231

33-
fn init_login(&self) -> AuthFlowState;
34-
/// Authenticates the user with Clerk OAuth
35-
async fn login(&self, auth_flow_state: AuthFlowState) -> anyhow::Result<()>;
36-
37-
/// Logs out the user by deleting stored credentials
38-
/// Returns true if credentials were found and deleted, false otherwise
39-
fn logout(&self) -> anyhow::Result<bool>;
40-
4132
/// Returns the current environment
4233
fn environment(&self) -> Environment;
4334

crates/forge_app/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ forge_open_router = { path = "../forge_open_router" }
1414
forge_tool_macros = { path = "../forge_tool_macros" }
1515
forge_display = { path = "../forge_display" }
1616
forge_walker = { path = "../forge_walker" }
17-
forge_oauth = { path = "../forge_oauth" }
1817
serde = { version = "1.0", features = ["derive"] }
1918
serde_json = "1.0.133"
2019
derive_setters = "0.1.6"

crates/forge_app/src/app.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::Infrastructure;
1818
pub struct ForgeApp<F> {
1919
infra: Arc<F>,
2020
tool_service: Arc<ForgeToolService>,
21-
provider_service: ForgeProviderService<F>,
21+
provider_service: ForgeProviderService,
2222
conversation_service: ForgeConversationService,
2323
prompt_service: ForgeTemplateService<F, ForgeToolService>,
2424
attachment_service: ForgeChatRequest<F>,
@@ -40,7 +40,7 @@ impl<F: Infrastructure> ForgeApp<F> {
4040

4141
impl<F: Infrastructure> App for ForgeApp<F> {
4242
type ToolService = ForgeToolService;
43-
type ProviderService = ForgeProviderService<F>;
43+
type ProviderService = ForgeProviderService;
4444
type ConversationService = ForgeConversationService;
4545
type TemplateService = ForgeTemplateService<F, ForgeToolService>;
4646
type AttachmentService = ForgeChatRequest<F>;
@@ -67,16 +67,11 @@ impl<F: Infrastructure> App for ForgeApp<F> {
6767
}
6868

6969
impl<F: Infrastructure> Infrastructure for ForgeApp<F> {
70-
type CredentialRepository = F::CredentialRepository;
7170
type EnvironmentService = F::EnvironmentService;
7271
type FileReadService = F::FileReadService;
7372
type VectorIndex = F::VectorIndex;
7473
type EmbeddingService = F::EmbeddingService;
7574

76-
fn credential_repository(&self) -> &Self::CredentialRepository {
77-
self.infra.credential_repository()
78-
}
79-
8075
fn environment_service(&self) -> &Self::EnvironmentService {
8176
self.infra.environment_service()
8277
}

crates/forge_app/src/attachment.rs

+2-32
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,17 @@ impl<F: Infrastructure> AttachmentService for ForgeChatRequest<F> {
6060

6161
#[cfg(test)]
6262
mod tests {
63-
use core::str;
6463
use std::collections::HashMap;
6564
use std::path::{Path, PathBuf};
6665
use std::sync::{Arc, Mutex};
6766

6867
use base64::Engine;
6968
use bytes::Bytes;
7069
use forge_domain::{AttachmentService, ContentType, Environment, Point, Query, Suggestion};
71-
use forge_oauth::AuthFlowState;
7270

7371
use crate::attachment::ForgeChatRequest;
7472
use crate::{
75-
CredentialRepository, EmbeddingService, EnvironmentService, FileReadService,
76-
Infrastructure, VectorIndex,
73+
EmbeddingService, EnvironmentService, FileReadService, Infrastructure, VectorIndex,
7774
};
7875

7976
struct MockEnvironmentService {}
@@ -93,7 +90,6 @@ mod tests {
9390
provider_key: "key".to_string(),
9491
provider_url: "url".to_string(),
9592
openai_key: None,
96-
force_antinomy: None,
9793
}
9894
}
9995
}
@@ -166,7 +162,6 @@ mod tests {
166162
file_service: MockFileReadService,
167163
vector_index: MockVectorIndex,
168164
embedding_service: MockEmbeddingService,
169-
auth_service: MockAuthService,
170165
}
171166

172167
impl MockInfrastructure {
@@ -176,37 +171,16 @@ mod tests {
176171
file_service: MockFileReadService::new(),
177172
vector_index: MockVectorIndex {},
178173
embedding_service: MockEmbeddingService {},
179-
auth_service: MockAuthService {},
180174
}
181175
}
182176
}
183177

184-
struct MockAuthService {}
185-
186-
#[async_trait::async_trait]
187-
impl CredentialRepository for MockAuthService {
188-
fn create(&self) -> AuthFlowState {
189-
unimplemented!()
190-
}
191-
async fn authenticate(&self, _: AuthFlowState) -> Result<(), anyhow::Error> {
192-
Ok(())
193-
}
194-
195-
fn delete(&self) -> Result<bool, anyhow::Error> {
196-
Ok(false)
197-
}
198-
199-
fn credentials(&self) -> Option<String> {
200-
None
201-
}
202-
}
203-
204178
impl Infrastructure for MockInfrastructure {
205179
type EnvironmentService = MockEnvironmentService;
206180
type FileReadService = MockFileReadService;
207181
type VectorIndex = MockVectorIndex;
208182
type EmbeddingService = MockEmbeddingService;
209-
type CredentialRepository = MockAuthService;
183+
210184
fn environment_service(&self) -> &Self::EnvironmentService {
211185
&self.env_service
212186
}
@@ -222,10 +196,6 @@ mod tests {
222196
fn embedding_service(&self) -> &Self::EmbeddingService {
223197
&self.embedding_service
224198
}
225-
226-
fn credential_repository(&self) -> &Self::CredentialRepository {
227-
&self.auth_service
228-
}
229199
}
230200

231201
#[tokio::test]

crates/forge_app/src/lib.rs

-20
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,6 @@ use std::path::Path;
1111
pub use app::*;
1212
use bytes::Bytes;
1313
use forge_domain::{Point, Query, Suggestion};
14-
use forge_oauth::AuthFlowState;
15-
16-
#[async_trait::async_trait]
17-
pub trait CredentialRepository: Send + Sync + 'static {
18-
/// Returns the current authentication state
19-
fn create(&self) -> AuthFlowState;
20-
21-
/// Authenticates the user and stores credentials
22-
async fn authenticate(&self, state: AuthFlowState) -> anyhow::Result<()>;
23-
24-
/// Logs out the user by removing stored credentials
25-
/// Returns true if credentials were found and removed, false otherwise
26-
fn delete(&self) -> anyhow::Result<bool>;
27-
28-
/// Retrieves the current authentication token if available
29-
/// Returns the token as a string if found, or an error if not authenticated
30-
fn credentials(&self) -> Option<String>;
31-
}
3214

3315
/// Repository for accessing system environment information
3416
#[async_trait::async_trait]
@@ -63,13 +45,11 @@ pub trait EmbeddingService: Send + Sync {
6345
}
6446

6547
pub trait Infrastructure: Send + Sync + 'static {
66-
type CredentialRepository: CredentialRepository;
6748
type EnvironmentService: EnvironmentService;
6849
type FileReadService: FileReadService;
6950
type VectorIndex: VectorIndex<Suggestion>;
7051
type EmbeddingService: EmbeddingService;
7152

72-
fn credential_repository(&self) -> &Self::CredentialRepository;
7353
fn environment_service(&self) -> &Self::EnvironmentService;
7454
fn file_read_service(&self) -> &Self::FileReadService;
7555
fn vector_index(&self) -> &Self::VectorIndex;

crates/forge_app/src/provider.rs

+19-44
Original file line numberDiff line numberDiff line change
@@ -5,80 +5,55 @@ use forge_domain::{
55
ChatCompletionMessage, Context as ChatContext, Model, ModelId, Parameters, ProviderService,
66
ResultStream,
77
};
8-
use forge_open_router::{Client, ClientBuilder};
8+
use forge_open_router::ProviderBuilder;
99
use moka2::future::Cache;
10-
use tokio::sync::Mutex;
1110

12-
use crate::{CredentialRepository, EnvironmentService, Infrastructure};
11+
use crate::{EnvironmentService, Infrastructure};
1312

14-
pub struct ForgeProviderService<F> {
15-
infra: Arc<F>,
16-
17-
// The provider service implementation
18-
client: Mutex<Option<Arc<Client>>>,
13+
pub struct ForgeProviderService {
14+
or: Box<dyn ProviderService>,
1915
cache: Cache<ModelId, Parameters>,
2016
}
2117

22-
impl<F: Infrastructure> ForgeProviderService<F> {
23-
pub fn new(infra: Arc<F>) -> Self {
24-
let infra = infra.clone();
25-
Self { infra, client: Mutex::new(None), cache: Cache::new(1024) }
26-
}
27-
28-
async fn provider(&self) -> Result<Arc<Client>> {
29-
let mut guard = self.client.lock().await;
30-
if let Some(provider) = guard.as_ref() {
31-
return Ok(provider.clone());
32-
}
33-
34-
let env = self.infra.environment_service().get_environment();
35-
let key = if env.force_antinomy.unwrap_or_default() {
36-
self.infra
37-
.credential_repository()
38-
.credentials()
39-
.ok_or_else(|| anyhow::anyhow!("Failed to authenticate the user"))?
40-
} else {
41-
env.provider_key.clone()
42-
};
43-
let provider = Arc::new(
44-
ClientBuilder::from_url(env.provider_url)
45-
.api_key(key)
46-
.build()?,
47-
);
18+
impl ForgeProviderService {
19+
pub fn new<F: Infrastructure>(infra: Arc<F>) -> Self {
20+
let env = infra.environment_service().get_environment();
21+
let or = ProviderBuilder::from_url(env.provider_url)
22+
.with_key(env.provider_key)
23+
.build()
24+
.expect("Failed to build provider");
4825

49-
*guard = Some(provider.clone());
50-
Ok(provider)
26+
Self { or, cache: Cache::new(1024) }
5127
}
5228
}
5329

5430
#[async_trait::async_trait]
55-
impl<F: Infrastructure> ProviderService for ForgeProviderService<F> {
31+
impl ProviderService for ForgeProviderService {
5632
async fn chat(
5733
&self,
5834
model_id: &ModelId,
5935
request: ChatContext,
6036
) -> ResultStream<ChatCompletionMessage, anyhow::Error> {
61-
self.provider()
62-
.await?
37+
self.or
6338
.chat(model_id, request)
6439
.await
6540
.with_context(|| format!("Failed to chat with model: {}", model_id))
6641
}
6742

6843
async fn models(&self) -> Result<Vec<Model>> {
69-
self.provider().await?.models().await
44+
self.or.models().await
7045
}
7146

7247
async fn parameters(&self, model: &ModelId) -> anyhow::Result<Parameters> {
73-
self.cache
48+
Ok(self
49+
.cache
7450
.try_get_with_by_ref(model, async {
75-
self.provider()
76-
.await?
51+
self.or
7752
.parameters(model)
7853
.await
7954
.with_context(|| format!("Failed to get parameters for model: {}", model))
8055
})
8156
.await
82-
.map_err(|e| anyhow::anyhow!(e))
57+
.map_err(|e| anyhow::anyhow!(e))?)
8358
}
8459
}

crates/forge_app/src/tools/mod.rs

+1-26
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ mod tests {
4141

4242
use bytes::Bytes;
4343
use forge_domain::{Environment, Point, Query, Suggestion};
44-
use forge_oauth::AuthFlowState;
4544

4645
use super::*;
47-
use crate::{CredentialRepository, EmbeddingService, FileReadService, VectorIndex};
46+
use crate::{EmbeddingService, FileReadService, VectorIndex};
4847

4948
/// Create a default test environment
5049
fn stub() -> Stub {
@@ -65,7 +64,6 @@ mod tests {
6564
provider_url: Default::default(),
6665
provider_key: Default::default(),
6766
openai_key: Default::default(),
68-
force_antinomy: None,
6967
},
7068
}
7169
}
@@ -104,36 +102,13 @@ mod tests {
104102
}
105103
}
106104

107-
#[async_trait::async_trait]
108-
impl CredentialRepository for Stub {
109-
fn create(&self) -> AuthFlowState {
110-
unimplemented!()
111-
}
112-
async fn authenticate(&self, _auth_flow_state: AuthFlowState) -> anyhow::Result<()> {
113-
unimplemented!()
114-
}
115-
116-
fn delete(&self) -> anyhow::Result<bool> {
117-
unimplemented!()
118-
}
119-
120-
fn credentials(&self) -> Option<String> {
121-
unimplemented!()
122-
}
123-
}
124-
125105
#[async_trait::async_trait]
126106
impl Infrastructure for Stub {
127-
type CredentialRepository = Stub;
128107
type EnvironmentService = Stub;
129108
type FileReadService = Stub;
130109
type VectorIndex = Stub;
131110
type EmbeddingService = Stub;
132111

133-
fn credential_repository(&self) -> &Self::CredentialRepository {
134-
self
135-
}
136-
137112
fn environment_service(&self) -> &Self::EnvironmentService {
138113
self
139114
}

crates/forge_app/src/tools/shell/shell_tool.rs

-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ mod tests {
146146
qdrant_cluster: None,
147147
pid: std::process::id(),
148148
openai_key: None,
149-
force_antinomy: None,
150149
}
151150
}
152151

0 commit comments

Comments
 (0)