Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion crates/forge_domain/src/auth/auth_method.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use super::OAuthConfig;

/// Authentication method configuration
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum AuthMethod {
/// Authenticate using an API key
ApiKey,
/// Authenticate using OAuth device flow
#[serde(rename = "oauth_device")]
OAuthDevice(OAuthConfig),
/// Authenticate using OAuth authorization code flow
#[serde(rename = "oauth_code")]
OAuthCode(OAuthConfig),
/// Authenticate using Google Application Default Credentials
#[serde(rename = "google_adc")]
GoogleAdc,
/// Authenticate using OpenAI Codex device flow
#[serde(rename = "codex_device")]
CodexDevice(OAuthConfig),
}
Expand Down
27 changes: 25 additions & 2 deletions crates/forge_domain/src/auth/oauth_config.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,52 @@
use std::collections::HashMap;

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use url::Url;

#[derive(
Clone, Serialize, Deserialize, derive_more::From, derive_more::Deref, PartialEq, Eq, Debug,
Clone,
Serialize,
Deserialize,
derive_more::From,
derive_more::Deref,
PartialEq,
Eq,
Debug,
JsonSchema,
)]
#[serde(transparent)]
#[schemars(with = "String")]
pub struct ClientId(String);

/// OAuth configuration for authentication flows
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct OAuthConfig {
/// The URL to initiate the OAuth authorization or device code flow
#[schemars(with = "String")]
pub auth_url: Url,
/// The URL to exchange authorization codes or device codes for access
/// tokens
#[schemars(with = "String")]
pub token_url: Url,
/// The OAuth client identifier
pub client_id: ClientId,
/// The OAuth scopes to request
pub scopes: Vec<String>,
/// The redirect URI for authorization code flows
#[serde(skip_serializing_if = "Option::is_none")]
pub redirect_uri: Option<String>,
/// Whether to use PKCE (Proof Key for Code Exchange)
#[serde(default)]
pub use_pkce: bool,
/// The URL to refresh the token after OAuth-with-API-Key flow
#[schemars(with = "Option<String>")]
#[serde(skip_serializing_if = "Option::is_none")]
pub token_refresh_url: Option<Url>,
/// Custom HTTP headers to include in OAuth requests
#[serde(skip_serializing_if = "Option::is_none")]
pub custom_headers: Option<HashMap<String, String>>,
/// Extra parameters to include in the authorization request
#[serde(skip_serializing_if = "Option::is_none")]
pub extra_auth_params: Option<HashMap<String, String>>,
}
9 changes: 7 additions & 2 deletions crates/forge_domain/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
use strum_macros::EnumString;

/// Represents input modalities that a model can accept
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, EnumString)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, EnumString, JsonSchema)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase", ascii_case_insensitive)]
pub enum InputModality {
Expand All @@ -20,13 +20,18 @@ fn default_input_modalities() -> Vec<InputModality> {
vec![InputModality::Text]
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, Setters)]
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, Setters, JsonSchema)]
pub struct Model {
/// Unique model identifier
pub id: ModelId,
/// Human-readable display name for the model
pub name: Option<String>,
/// Description of the model's capabilities
pub description: Option<String>,
/// Maximum context window size in tokens
pub context_length: Option<u64>,
// TODO: add provider information to the model
/// Whether the model supports tool/function calls
pub tools_supported: Option<bool>,
/// Whether the model supports parallel tool calls
pub supports_parallel_tool_calls: Option<bool>,
Expand Down
22 changes: 20 additions & 2 deletions crates/forge_domain/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ use crate::{ApiKey, AuthCredential, AuthDetails, Model, Template};

/// Distinguishes between different categories of providers
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Display, EnumString, Default,
Debug,
Clone,
Copy,
PartialEq,
Eq,
Hash,
Serialize,
Deserialize,
Display,
EnumString,
Default,
JsonSchema,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
Expand Down Expand Up @@ -178,13 +189,20 @@ impl From<String> for ProviderId {
}
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub enum ProviderResponse {
/// OpenAI-compatible chat completions format
OpenAI,
/// OpenAI Responses API format
OpenAIResponses,
/// Anthropic messages format
Anthropic,
/// AWS Bedrock format
Bedrock,
/// Google AI format
Google,
/// OpenCode proxy format — response type is determined by the selected
/// model
OpenCode,
}

Expand Down
1 change: 1 addition & 0 deletions crates/forge_repo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ fake = { version = "5.1.0", features = ["derive"] }
derive_setters.workspace = true
mockito = { workspace = true }
regex = { workspace = true }
is_ci.workspace = true
2 changes: 2 additions & 0 deletions crates/forge_repo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ mod proto_generated {

// Only expose forge_repo container
pub use forge_repo::*;
// Expose ProviderConfig for schema generation
pub use provider::ProviderConfig;
Loading
Loading