MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / chat

Method chat

crates/opencode-provider/src/vercel.rs:127–156  ·  view source on GitHub ↗
(&self, request: ChatRequest)

Source from the content-addressed store, hash-verified

125 }
126
127 async fn chat(&self, request: ChatRequest) -> Result<ChatResponse, ProviderError> {
128 let url = self.config.base_url.as_deref().unwrap_or(VERCEL_API_URL);
129 let vercel_request = self.convert_request(request);
130
131 let response = self
132 .client
133 .post(url)
134 .header("Content-Type", "application/json")
135 .header("Authorization", format!("Bearer {}", self.config.api_key))
136 .json(&vercel_request)
137 .send()
138 .await
139 .map_err(|e| ProviderError::NetworkError(e.to_string()))?;
140
141 if !response.status().is_success() {
142 let status = response.status();
143 let body = response.text().await.unwrap_or_default();
144 return Err(ProviderError::api_error_with_status(
145 format!("{}: {}", status, body),
146 status.as_u16(),
147 ));
148 }
149
150 let vercel_response: VercelResponse = response
151 .json()
152 .await
153 .map_err(|e| ProviderError::ApiError(e.to_string()))?;
154
155 Ok(convert_vercel_response(vercel_response))
156 }
157
158 async fn chat_stream(&self, request: ChatRequest) -> Result<StreamResult, ProviderError> {
159 let url = self.config.base_url.as_deref().unwrap_or(VERCEL_API_URL);

Callers

nothing calls this directly

Calls 6

convert_vercel_responseFunction · 0.85
ApiErrorEnum · 0.50
convert_requestMethod · 0.45
sendMethod · 0.45
statusMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected