Files
zen/bindings/python/zen.pyi
T
Stefan ae431abe37 feat(trace): trace format v1 with TraceCollector on the compiled engine
Adds trace format v1 to the compiled engine, recorded by explicit trace
recorders and written natively. The interpreted engine keeps the legacy
trace.

- EvaluationOptions.trace is a TraceFormat (off, v1, legacy). Legacy
  traces are produced directly from the same recording.
- zen_engine::trace exposes convert, restore and inspect for
  stored documents, with redaction and truncation markers.
- The trace header takes evaluatedAt, timezone and seed from the
  evaluation context, so an evaluation replays from its own trace.
- Batch and columnar evaluations record events as columns and write one
  document per row.
- Bindings accept the trace format (true, 'v1', 'legacy'); the Node
  binding ships TypeScript types for the v1 document.
- Golden, fixture and damaged-document tests cover byte identity with the
  legacy trace, restore, interop with the reference fixtures and
  malformed input.
2026-11-17 18:57:34 +01:00

117 lines
3.2 KiB
Python

from collections.abc import Awaitable, Callable
from datetime import datetime
from typing import Any, Optional, TypedDict, Literal, TypeAlias, Union
class DecisionEvaluateOptions(TypedDict, total=False):
max_depth: int
trace: Union[bool, Literal["v1", "legacy"]]
now: Union[int, str, datetime]
timezone: str
seed: Union[int, str]
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