openkind_client/client/
options.rs1use std::time::Duration;
4
5use openkind_core::State;
6use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
7use serde::{Deserialize, Serialize};
8
9use crate::retry::RetryPolicy;
10
11pub const DEFAULT_BASE_URL: &str = "https://api.typesafe.ai";
14
15pub const DEFAULT_MODEL: &str = "jev-latest";
17
18pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10);
20
21pub(crate) const SYSTEM_ONE_PATH: &str = "/v1/systemone";
22pub(crate) const CLOUDFLARE_RUN_PATH: &str = "/ai/run";
23pub(crate) const MODELS_PATH: &str = "/v1/models";
24pub(crate) const HEALTH_PATH: &str = "/health";
25
26pub(crate) const SDK_NAME: &str = "openkind-client";
27
28pub(crate) const USER_AGENT_HEADER: &str = "user-agent";
29pub(crate) const SDK_HEADER: &str = "x-typesafe-sdk";
30pub(crate) const RUNTIME_HEADER: &str = "x-typesafe-runtime";
31pub(crate) const RETRY_COUNT_HEADER: &str = "x-typesafe-retry-count";
34
35#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
37pub struct Health {
38 pub status: String,
40}
41
42pub trait IntoState {
49 fn into_state(self) -> State;
51}
52
53impl IntoState for State {
54 fn into_state(self) -> State {
55 self
56 }
57}
58
59impl IntoState for &str {
60 fn into_state(self) -> State {
61 State::Text(self.to_owned())
62 }
63}
64
65impl IntoState for String {
66 fn into_state(self) -> State {
67 State::Text(self)
68 }
69}
70
71impl IntoState for &String {
72 fn into_state(self) -> State {
73 State::Text(self.clone())
74 }
75}
76
77impl IntoState for serde_json::Map<String, serde_json::Value> {
78 fn into_state(self) -> State {
79 State::Object(self)
80 }
81}
82
83impl IntoState for Vec<serde_json::Value> {
84 fn into_state(self) -> State {
85 State::Array(self)
86 }
87}
88
89#[derive(Debug, Clone, Default)]
105pub struct RequestOptions {
106 pub(crate) timeout: Option<Duration>,
107 pub(crate) retry: Option<RetryPolicy>,
108 pub(crate) extra_headers: Option<HeaderMap>,
109}
110
111impl RequestOptions {
112 pub fn new() -> Self {
114 Self::default()
115 }
116
117 pub fn timeout(mut self, timeout: Duration) -> Self {
119 self.timeout = Some(timeout);
120 self
121 }
122
123 pub fn retry(mut self, retry: RetryPolicy) -> Self {
125 self.retry = Some(retry);
126 self
127 }
128
129 pub fn header(mut self, name: HeaderName, value: HeaderValue) -> Self {
131 self.extra_headers
132 .get_or_insert_with(HeaderMap::new)
133 .insert(name, value);
134 self
135 }
136}