/** * Default ceiling on logical function-call nesting depth. Sits well above any * realistic call nesting (deep tree walks, recursive descent) yet far below * where an unbounded async recursion would OOM the process — the failure this * guard exists to turn into an actionable error. Overridable per program via * the `maxCallDepth` config option. * * Why a logical counter rather than V8's native stack limit: most Agency * functions are async (they `await`), so each call flattens V8's frame and an * infinite async cycle never throws `RangeError` — it just grows the promise * chain until the heap is exhausted, minutes later, with no diagnostic. We * track the LOGICAL depth of the async call tree instead. * * Budget accuracy caveat: EVERY Agency call — including the stdlib higher-order * functions `map`/`filter`/`reduce`/`flatMap` — consumes one depth level, and a * HOF also dispatches its callback through another call. So recursion written as * `walk(n) { children.map(walk) }` burns ~2 levels per user level (more when * HOFs nest), i.e. the effective budget is roughly halved versus the same walk * written with a `for` loop, which costs 1 level per user level. The default is * generous enough that this rarely matters; raise `maxCallDepth` for very deep * HOF-style recursion. (Counting is by call, not by heap growth, so a bounded * fire-and-forget spawn like `async produce(n-1)` also climbs the depth and can * trip even though it holds only a bounded promise queue — a conservative false * positive, acceptable for a safety net.) */ export declare const DEFAULT_MAX_CALL_DEPTH = 2048; /** * Run `fn` one level deeper in the call-depth lineage. Throws * `CallDepthExceededError` (an `AgencyAbort`) if entering this call would push * the logical depth past the active limit, instead of letting an unbounded * recursion run until the process OOMs. `name` labels the call for the overflow * diagnostic. The limit is read from the active execution context's * `maxCallDepth` once at the root of each lineage and inherited by nested calls * (so a deep recursion pays a single `agencyStore` lookup, not one per frame). */ export declare function withCallDepth(name: string, fn: () => T): T;