supercode_harness/
provider.rs1use async_trait::async_trait;
4
5use crate::{ChatMessage, Error, Result};
6
7pub use supercode_runtime::{
8 apply_cache_plan, cache_cold_reason, is_anthropic_family_model, model_context_limit,
9 tier_change_is_cache_bust, ChatRequest, HttpOptions, OpenAiProvider, PromptTokensDetails,
10 ToolSchema, Usage, UNKNOWN_MODEL_CONTEXT_FLOOR,
11};
12
13#[async_trait]
15pub trait Provider: Send + Sync {
16 async fn complete(
18 &self,
19 request: &ChatRequest,
20 on_delta: &(dyn for<'a> Fn(&'a str) + Send + Sync),
21 ) -> Result<(ChatMessage, Usage)>;
22}
23
24#[async_trait]
25impl Provider for OpenAiProvider {
26 async fn complete(
27 &self,
28 request: &ChatRequest,
29 on_delta: &(dyn for<'a> Fn(&'a str) + Send + Sync),
30 ) -> Result<(ChatMessage, Usage)> {
31 supercode_runtime::Provider::complete(self, request, on_delta)
32 .await
33 .map_err(map_runtime_error)
34 }
35}
36
37fn map_runtime_error(error: supercode_runtime::RuntimeError) -> Error {
38 match error {
39 supercode_runtime::RuntimeError::Http(source) => Error::Http(source),
40 supercode_runtime::RuntimeError::Provider { status, body } => {
41 Error::Provider { status, body }
42 }
43 supercode_runtime::RuntimeError::Decode(source) => Error::Decode(source),
44 other => Error::Other(other.to_string()),
45 }
46}