Skip to content

Commit b4bc635

Browse files
committed
Include test providers in wasm build
1 parent 9ccb1a5 commit b4bc635

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

src/providers/test/mod.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,17 @@ fn generate_id() -> String {
166166
}
167167

168168
fn current_timestamp() -> i64 {
169-
std::time::SystemTime::now()
170-
.duration_since(std::time::UNIX_EPOCH)
171-
.unwrap()
172-
.as_secs() as i64
169+
#[cfg(target_arch = "wasm32")]
170+
{
171+
(js_sys::Date::now() / 1000.0) as i64
172+
}
173+
#[cfg(not(target_arch = "wasm32"))]
174+
{
175+
std::time::SystemTime::now()
176+
.duration_since(std::time::UNIX_EPOCH)
177+
.unwrap()
178+
.as_secs() as i64
179+
}
173180
}
174181

175182
fn build_json_response(body: serde_json::Value) -> Result<Response, ProviderError> {

src/wasm.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
//! replacements for `axum::routing::{get, post, ...}` that wrap handlers in
3131
//! [`crate::compat::WasmHandler`], asserting `Send` since wasm32 is single-threaded.
3232
33-
use std::sync::Arc;
33+
use std::{collections::HashMap, sync::Arc};
3434

3535
use axum::{
3636
Extension, Json, Router,
@@ -477,7 +477,27 @@ fn wasm_default_config() -> config::GatewayConfig {
477477
mode: config::AuthMode::None,
478478
..Default::default()
479479
},
480-
providers: config::ProvidersConfig::default(),
480+
providers: config::ProvidersConfig {
481+
default_provider: Some("test".to_string()),
482+
providers: HashMap::from([(
483+
"test".to_string(),
484+
config::ProviderConfig::Test(config::TestProviderConfig {
485+
model_name: "test-model".to_string(),
486+
failure_mode: config::TestFailureMode::None,
487+
timeout_secs: 30,
488+
allowed_models: Vec::new(),
489+
model_aliases: HashMap::new(),
490+
models: HashMap::new(),
491+
retry: config::RetryConfig::default(),
492+
circuit_breaker: config::CircuitBreakerConfig::default(),
493+
fallback_providers: Vec::new(),
494+
model_fallbacks: HashMap::new(),
495+
health_check: config::ProviderHealthCheckConfig::default(),
496+
catalog_provider: None,
497+
sovereignty: None,
498+
}),
499+
)]),
500+
},
481501
limits: config::LimitsConfig::default(),
482502
features: config::FeaturesConfig {
483503
static_models_cache: config::StaticModelsCacheConfig {

0 commit comments

Comments
 (0)