opencode_sdk/http/
providers.rs1use crate::error::Result;
6use crate::http::HttpClient;
7use crate::types::api::{OAuthCallbackResponse, SetAuthResponse};
8use crate::types::provider::{
9 OAuthAuthorizeResponse, OAuthCallbackRequest, ProviderAuth, ProviderListResponse,
10 SetAuthRequest,
11};
12use reqwest::Method;
13
14#[derive(Clone)]
16pub struct ProvidersApi {
17 http: HttpClient,
18}
19
20impl ProvidersApi {
21 pub fn new(http: HttpClient) -> Self {
23 Self { http }
24 }
25
26 pub async fn list(&self) -> Result<ProviderListResponse> {
35 self.http.request_json(Method::GET, "/provider", None).await
36 }
37
38 pub async fn auth(&self) -> Result<Vec<ProviderAuth>> {
44 self.http
45 .request_json(Method::GET, "/provider/auth", None)
46 .await
47 }
48
49 pub async fn oauth_authorize(&self, provider_id: &str) -> Result<OAuthAuthorizeResponse> {
55 self.http
56 .request_json(
57 Method::POST,
58 &format!("/provider/{}/oauth/authorize", provider_id),
59 Some(serde_json::json!({})),
60 )
61 .await
62 }
63
64 pub async fn oauth_callback(
70 &self,
71 provider_id: &str,
72 req: &OAuthCallbackRequest,
73 ) -> Result<OAuthCallbackResponse> {
74 let body = serde_json::to_value(req)?;
75 self.http
76 .request_json(
77 Method::POST,
78 &format!("/provider/{}/oauth/callback", provider_id),
79 Some(body),
80 )
81 .await
82 }
83
84 pub async fn set_auth(
90 &self,
91 provider_id: &str,
92 req: &SetAuthRequest,
93 ) -> Result<SetAuthResponse> {
94 let body = serde_json::to_value(req)?;
95 self.http
96 .request_json(Method::PUT, &format!("/auth/{}", provider_id), Some(body))
97 .await
98 }
99}