use std::time::Duration;
use openkind_core::State;
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
use serde::{Deserialize, Serialize};
use crate::retry::RetryPolicy;
pub const DEFAULT_BASE_URL: &str = "https://api.typesafe.ai";
pub const DEFAULT_MODEL: &str = "jev-latest";
pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10);
pub(crate) const SYSTEM_ONE_PATH: &str = "/v1/systemone";
pub(crate) const CLOUDFLARE_RUN_PATH: &str = "/ai/run";
pub(crate) const MODELS_PATH: &str = "/v1/models";
pub(crate) const HEALTH_PATH: &str = "/health";
pub(crate) const SDK_NAME: &str = "openkind-client";
pub(crate) const USER_AGENT_HEADER: &str = "user-agent";
pub(crate) const SDK_HEADER: &str = "x-typesafe-sdk";
pub(crate) const RUNTIME_HEADER: &str = "x-typesafe-runtime";
pub(crate) const RETRY_COUNT_HEADER: &str = "x-typesafe-retry-count";
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Health {
pub status: String,
}
pub trait IntoState {
fn into_state(self) -> State;
}
impl IntoState for State {
fn into_state(self) -> State {
self
}
}
impl IntoState for &str {
fn into_state(self) -> State {
State::Text(self.to_owned())
}
}
impl IntoState for String {
fn into_state(self) -> State {
State::Text(self)
}
}
impl IntoState for &String {
fn into_state(self) -> State {
State::Text(self.clone())
}
}
impl IntoState for serde_json::Map<String, serde_json::Value> {
fn into_state(self) -> State {
State::Object(self)
}
}
impl IntoState for Vec<serde_json::Value> {
fn into_state(self) -> State {
State::Array(self)
}
}
#[derive(Debug, Clone, Default)]
pub struct RequestOptions {
pub(crate) timeout: Option<Duration>,
pub(crate) retry: Option<RetryPolicy>,
pub(crate) extra_headers: Option<HeaderMap>,
}
impl RequestOptions {
pub fn new() -> Self {
Self::default()
}
pub fn timeout(mut self, timeout: Duration) -> Self {
self.timeout = Some(timeout);
self
}
pub fn retry(mut self, retry: RetryPolicy) -> Self {
self.retry = Some(retry);
self
}
pub fn header(mut self, name: HeaderName, value: HeaderValue) -> Self {
self.extra_headers
.get_or_insert_with(HeaderMap::new)
.insert(name, value);
self
}
}