# `SystemOneDSL.Runner`
[🔗](https://github.com/boxxxie/jev_dsl/blob/v1.0.0/lib/system_one_dsl/runner.ex#L1)

Runtime evaluation, bounded concurrent batch execution, two-tier (L1 + L2) cache
orchestration, and deterministic test stubbing for `SystemOneDSL` contract modules backed by
`ReqLLM.Evaluation`.

## Telemetry Events

`SystemOneDSL.Runner` emits `:telemetry.span/3` events:
* `[:system_one_dsl, :evaluate, :start | :stop | :exception]`
* `[:system_one_dsl, :evaluate_many, :start | :stop | :exception]`

# `api_key`

```elixir
@spec api_key(keyword()) :: String.t()
```

Resolves the trimmed API key from `opts`, application config, or environment.

# `available?`

```elixir
@spec available?(module(), keyword(), atom()) :: boolean()
```

Returns `true` if the contract module can execute evaluations — either via an injected
1-arity test function (`:eval_fn` or `:eval_fn_key`), a configured API key, a test plug
in `:req_http_options`, or an enabled Tier-2 cache (`:tier2_cache`).

# `build_req_llm_options`

```elixir
@spec build_req_llm_options(keyword()) :: keyword()
```

Builds the strict `ReqLLM.Evaluation` keyword option list from `SystemOneDSL` merged options.

# `cache_key`

```elixir
@spec cache_key(module(), atom() | String.t(), term(), keyword()) :: String.t()
```

Computes the deterministic SHA-256 cache key (`"jev_<sha256>"`) using the contract
module's merged options (`use SystemOneDSL` + `otp_app` config + call overrides).

# `evaluate`

```elixir
@spec evaluate(module(), atom() | String.t(), map(), keyword()) ::
  {:ok, ReqLLM.Response.t() | map()} | {:error, term()}
```

Evaluates a single `state` map against `contract_key` defined in `contract_mod`.

# `evaluate!`

```elixir
@spec evaluate!(module(), atom() | String.t(), map(), keyword()) ::
  ReqLLM.Response.t() | map()
```

Evaluates a single `state` map against `contract_key` or raises `SystemOneDSL.Error`.

# `evaluate_many`

```elixir
@spec evaluate_many(module(), atom() | String.t(), [map()], keyword()) :: [
  ok: ReqLLM.Response.t() | map(),
  error: term()
]
```

Evaluates a list of `states` concurrently against `contract_key` using bounded
`Task.async_stream/3` (`:max_concurrency` default `10`, `ordered: true`).
Resolves L1 and L2 cache hits first and only dispatches uncached misses over the network.

# `has_api_key?`

```elixir
@spec has_api_key?(keyword()) :: boolean()
```

Returns `true` if a non-empty API key is available.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
