mirror of
https://github.com/gorules/zen.git
synced 2026-11-29 16:07:47 +00:00
Compiled engine only; the interpreted engine keeps legacy traces. The interpreted graph, policy and function code is unchanged from release/2.2: asked for a trace (true, v1 or legacy) it returns its legacy trace, never converts to v1, and ignores now, timezone and seed. - trace format v1 inside the engine (compiled/trace), public as zen_engine::trace: convert (legacy to v1), restore (v1 to legacy), inspect and redact, with the native encoder and policy writer, and TraceFormat, TraceDocument, PolicyTrace and TraceBatch; no separate crate - TraceFormat option (off, v1, legacy) replacing EvaluationTraceKind on every evaluation path; on the compiled engine legacy traces are restored from v1 - native TraceCollector for single-row, batch and columnar evaluation: a static template per compiled graph and typed facts pushed by the engine (rule hits, switch branches, expression results, sub-decision and loop levels), written as v1 without a legacy map - native policy writer for executions, members, reads, writes and absence markers - engine glue under compiled/ (compiled/trace/mod.rs, compiled/pinning.rs); workspace request, result and error types take the trace format and the policy trace as type parameters defaulting to the legacy types, with public aliases for TraceFormat and PolicyTrace; the response trace enum gains V1 and its policy variant holds a PolicyTrace - pinned evaluation context on the compiled engine: now, timezone and seed options, one clock read per evaluation and per batch, per-row random streams (row i draws from row_seed(seed, i)) in every batch and columnar path, Date and Math.random pinned in compiled function nodes; evaluatedAt, timezone and seed in the envelope - format additions: result rows for repeated keys, $redacted and $omitted with truncated, reserved context, requires flags - now, timezone, seed and trace format options in the Node, Python, C and uniffi bindings - golden tests: compiled v1 and legacy restore to the base traces for every spec case, interpreted variants return legacy traces equal to the base for any trace option, native and convert agree, batch and columnar rows equal single rows, timing stress, pinned and random-stream tests, and the interpreted engine ignores pinning; trace API, damaged-input, POC fixture (tests/fixtures/trace) and corpus tests, and the trace_corpus example for the POC cross-check
113 lines
3.1 KiB
Python
113 lines
3.1 KiB
Python
from collections.abc import Awaitable, Callable
|
|
from typing import Any, Optional, TypedDict, Literal, TypeAlias, Union
|
|
|
|
|
|
class DecisionEvaluateOptions(TypedDict, total=False):
|
|
max_depth: int
|
|
trace: Union[bool, Literal["v1", "legacy"]]
|
|
|
|
|
|
class EvaluateResponse(TypedDict):
|
|
performance: str
|
|
result: dict
|
|
trace: dict
|
|
|
|
|
|
ZenContext: TypeAlias = Union[str, bytes, dict]
|
|
ZenDecisionContentInput: TypeAlias = Union[str, ZenDecisionContent]
|
|
|
|
|
|
class StaticLoaderConfig(TypedDict):
|
|
type: Literal["static"]
|
|
content: dict[str, dict]
|
|
|
|
|
|
class FilesystemLoaderConfig(TypedDict):
|
|
type: Literal["fs"]
|
|
path: str
|
|
|
|
|
|
class ZipLoaderConfig(TypedDict):
|
|
type: Literal["zip"]
|
|
bytes: bytes
|
|
|
|
|
|
ZenLoaderConfig: TypeAlias = Union[StaticLoaderConfig, FilesystemLoaderConfig, ZipLoaderConfig]
|
|
ZenLoaderCallback: TypeAlias = Callable[[str], Union[str, dict, ZenDecisionContent, Awaitable[Union[str, dict, ZenDecisionContent]]]]
|
|
|
|
|
|
class ZenEngineOptions(TypedDict, total=False):
|
|
loader: Union[ZenLoaderCallback, ZenLoaderConfig]
|
|
customHandler: Callable
|
|
|
|
|
|
class EvaluateBatchRequest(TypedDict):
|
|
key: str
|
|
context: Any
|
|
|
|
|
|
class EvaluateBatchResult(TypedDict, total=False):
|
|
success: bool
|
|
data: EvaluateResponse
|
|
error: Any
|
|
|
|
|
|
class ZenEngine:
|
|
def __init__(self, options: Optional[ZenEngineOptions] = None) -> None: ...
|
|
|
|
def evaluate(self, key: str, context: ZenContext,
|
|
options: Optional[DecisionEvaluateOptions] = None) -> EvaluateResponse: ...
|
|
|
|
def evaluate_batch(self, requests: list[EvaluateBatchRequest],
|
|
options: Optional[DecisionEvaluateOptions] = None) -> list[EvaluateBatchResult]: ...
|
|
|
|
def async_evaluate(self, key: str, context: ZenContext, options: Optional[DecisionEvaluateOptions] = None) -> \
|
|
Awaitable[EvaluateResponse]: ...
|
|
|
|
def create_decision(self, content: ZenDecisionContentInput) -> ZenDecision: ...
|
|
|
|
def get_decision(self, key: str) -> ZenDecision: ...
|
|
|
|
|
|
class ZenDecisionContent:
|
|
def __init__(self, decision_content: str) -> None: ...
|
|
|
|
|
|
class ZenDecision:
|
|
def evaluate(self, context: ZenContext, options: Optional[DecisionEvaluateOptions] = None) -> EvaluateResponse: ...
|
|
|
|
def async_evaluate(self, context: ZenContext, options: Optional[DecisionEvaluateOptions] = None) -> Awaitable[
|
|
EvaluateResponse]: ...
|
|
|
|
def validate(self) -> None: ...
|
|
|
|
|
|
def evaluate_expression(expression: str, context: Optional[ZenContext] = None) -> Any: ...
|
|
|
|
|
|
def evaluate_unary_expression(expression: str, context: ZenContext) -> bool: ...
|
|
|
|
|
|
def render_template(template: str, context: ZenContext) -> Any: ...
|
|
|
|
|
|
def compile_expression(expression: str) -> Expression: ...
|
|
|
|
|
|
def compile_unary_expression(expression: str) -> Expression: ...
|
|
|
|
|
|
class Expression:
|
|
def evaluate(self, context: Optional[ZenContext] = None) -> Any: ...
|
|
|
|
|
|
def validate_expression(expression: str) -> Optional[ValidationResponse]: ...
|
|
|
|
|
|
def validate_unary_expression(expression: str) -> Optional[ValidationResponse]: ...
|
|
|
|
|
|
class ValidationResponse(TypedDict):
|
|
type: Literal["lexerError", "parserError", "compilerError"]
|
|
source: str
|