supercode-harness 0.4.13

The optional native Supercode agent and tool harness
Documentation
//! Compatibility provider contract for the extracted native runtime.

use async_trait::async_trait;

use crate::{ChatMessage, Error, Result};

pub use supercode_runtime::{
    apply_cache_plan, cache_cold_reason, is_anthropic_family_model, model_context_limit,
    tier_change_is_cache_bust, ChatRequest, HttpOptions, OpenAiProvider, PromptTokensDetails,
    ToolSchema, Usage, UNKNOWN_MODEL_CONTEXT_FLOOR,
};

/// Legacy provider abstraction preserved by the composition facade.
#[async_trait]
pub trait Provider: Send + Sync {
    /// Run one completion and return its canonical assistant message and usage.
    async fn complete(
        &self,
        request: &ChatRequest,
        on_delta: &(dyn for<'a> Fn(&'a str) + Send + Sync),
    ) -> Result<(ChatMessage, Usage)>;
}

#[async_trait]
impl Provider for OpenAiProvider {
    async fn complete(
        &self,
        request: &ChatRequest,
        on_delta: &(dyn for<'a> Fn(&'a str) + Send + Sync),
    ) -> Result<(ChatMessage, Usage)> {
        supercode_runtime::Provider::complete(self, request, on_delta)
            .await
            .map_err(map_runtime_error)
    }
}

fn map_runtime_error(error: supercode_runtime::RuntimeError) -> Error {
    match error {
        supercode_runtime::RuntimeError::Http(source) => Error::Http(source),
        supercode_runtime::RuntimeError::Provider { status, body } => {
            Error::Provider { status, body }
        }
        supercode_runtime::RuntimeError::Decode(source) => Error::Decode(source),
        other => Error::Other(other.to_string()),
    }
}