Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,995 changes: 1,389 additions & 606 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
watch:
RUSTFLAGS=-Awarnings cargo watch -c -w backend/src -x run
RUSTFLAGS=-Awarnings cargo watch -c -x run
2 changes: 1 addition & 1 deletion backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
zen-engine = { version = "0.45.0" }
zen-engine = { version = "0.53" }
34 changes: 16 additions & 18 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use axum::response::{IntoResponse, Response};
use axum::routing::{get, post};
use axum::{Extension, Json, Router};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_json::{json, Value};
use std::env;
use std::path::Path;
use std::sync::atomic::Ordering;
use std::thread::available_parallelism;
use tokio_util::task::LocalPoolHandle;
use tower_http::compression::CompressionLayer;
Expand All @@ -17,13 +18,14 @@ use tower_http::trace::TraceLayer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use zen_engine::model::DecisionContent;
use zen_engine::{DecisionEngine, EvaluationError, EvaluationOptions};
use zen_engine::{DecisionEngine, EvaluationSerializedOptions, EvaluationTraceKind, ZEN_CONFIG};

const IS_DEVELOPMENT: bool = cfg!(debug_assertions);

#[tokio::main]
async fn main() {
let local_pool = LocalPoolHandle::new(available_parallelism().map(Into::into).unwrap_or(1));
ZEN_CONFIG.http_auth.store(false, Ordering::Relaxed);

tracing_subscriber::registry()
.with(
Expand Down Expand Up @@ -85,44 +87,40 @@ struct SimulateRequest {
async fn simulate(
Extension(local_pool): Extension<LocalPoolHandle>,
Json(payload): Json<SimulateRequest>,
) -> Result<Json<Value>, SimulateError> {
) -> Result<Json<Value>, JsonError> {
let engine = DecisionEngine::default();
let decision = engine.create_decision(payload.content.into());

let result = local_pool
.spawn_pinned(move || async move {
decision
.evaluate_with_opts(
.evaluate_serialized(
payload.context.into(),
EvaluationOptions {
trace: Some(true),
max_depth: None,
EvaluationSerializedOptions {
trace: EvaluationTraceKind::Default,
max_depth: 10,
},
)
.await
.map(serde_json::to_value)
})
.await
.expect("Thread failed to join")?
.map_err(|_| SimulateError::from(Box::new(EvaluationError::DepthLimitExceeded)))?;
.map_err(|err| json!({ "error": err.to_string() }))?;

Ok(Json(result))
}

struct SimulateError(Box<EvaluationError>);
struct JsonError(Value);

impl IntoResponse for SimulateError {
impl IntoResponse for JsonError {
fn into_response(self) -> Response {
(
StatusCode::BAD_REQUEST,
serde_json::to_string(&self.0).unwrap_or_default(),
)
.into_response()
(StatusCode::BAD_REQUEST, Json(self.0)).into_response()
}
}

impl From<Box<EvaluationError>> for SimulateError {
fn from(value: Box<EvaluationError>) -> Self {
Self(value)
impl From<Value> for JsonError {
fn from(value: Value) -> Self {
JsonError(value)
}
}
72 changes: 36 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,50 @@
"preview": "vite preview"
},
"dependencies": {
"@ant-design/icons": "^6.0.0",
"@gorules/jdm-editor": "^1.41.0",
"@gorules/zen-engine-wasm": "^0.18.0",
"ace-builds": "^1.41.0",
"antd": "^5.25.2",
"axios": "^1.9.0",
"@ant-design/icons": "^6.1.0",
"@gorules/jdm-editor": "^1.50.6",
"@gorules/zen-engine-wasm": "^0.22.1",
"ace-builds": "^1.43.5",
"antd": "^6.2.1",
"axios": "^1.13.2",
"graphology": "^0.26.0",
"graphology-dag": "^0.4.1",
"json5": "^2.2.3",
"react": "^18.3.1",
"react": "^19.2.3",
"react-ace": "^14.0.1",
"react-dom": "^18.3.1",
"react-router": "^7.6.0",
"react-router-dom": "^7.6.0",
"ts-pattern": "^5.7.1",
"vite-plugin-wasm": "^3.4.1",
"zod": "^3.25.20"
"react-dom": "^19.2.3",
"react-router": "^7.12.0",
"react-router-dom": "^7.12.0",
"ts-pattern": "^5.9.0",
"vite-plugin-wasm": "^3.5.0",
"zod": "^4.3.5"
},
"devDependencies": {
"@eslint/compat": "^1.2.9",
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.27.0",
"@eslint/compat": "^2.0.1",
"@eslint/eslintrc": "^3.3.3",
"@eslint/js": "^9.39.2",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^13.0.1",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^11.0.2",
"@semantic-release/npm": "^12.0.1",
"@semantic-release/release-notes-generator": "^14.0.3",
"@types/node": "^22.15.21",
"@types/react": "^18.3.22",
"@types/react-dom": "^18.3.7",
"@types/wicg-file-system-access": "^2023.10.6",
"@typescript-eslint/eslint-plugin": "^8.32.1",
"@typescript-eslint/parser": "^8.32.1",
"@vitejs/plugin-react-swc": "^3.9.0",
"eslint": "^9.27.0",
"eslint-config-prettier": "^10.1.5",
"eslint-plugin-prettier": "^5.4.0",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.20",
"globals": "^16.1.0",
"prettier": "^3.5.3",
"semantic-release": "^24.2.4",
"typescript": "^5.8.3",
"vite": "^6.3.5"
"@semantic-release/github": "^12.0.2",
"@semantic-release/npm": "^13.1.3",
"@semantic-release/release-notes-generator": "^14.1.0",
"@types/node": "^25.0.10",
"@types/react": "^19.2.9",
"@types/react-dom": "^19.2.3",
"@types/wicg-file-system-access": "^2023.10.7",
"@typescript-eslint/eslint-plugin": "^8.53.1",
"@typescript-eslint/parser": "^8.53.1",
"@vitejs/plugin-react-swc": "^4.2.2",
"eslint": "^9.39.2",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.5",
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.4.26",
"globals": "^17.0.0",
"prettier": "^3.8.1",
"semantic-release": "^25.0.2",
"typescript": "^5.9.3",
"vite": "^7.3.1"
}
}
Loading
Loading