import { type AbortLog } from "./abortedResult.js"; /** The sentence a tripped guard reports. The numbers are in the guard's own * unit: dollars for cost, milliseconds for time, matching the fields in * GuardFailureData. */ export declare function guardFailureMessage(dimension: "cost" | "time", limit: number, spent: number, label?: string): string; export type ResultValue = ResultSuccess | ResultFailure; export type ResultSuccess = { __type: "resultType"; success: true; value: any; }; export type FailureOpts = { checkpoint?: any; /** The call failed before its function body began (argument binding, * arity, schema). Its only producer is the tool loop, from the invoke * layer's pre-execution tag — trust-the-producer, because nothing can * correct a wrongly-true claim. */ neverStarted?: boolean; /** Execution entered a destructive region — a `destructive def` body (which * commits at entry) or a `destructive { }` region. */ destructiveRan?: boolean; /** This failure is a rejected interrupt: a handler, policy, or user * said no. Its only producers are the interrupt codegen templates * (interruptReturn/interruptAssignment). The tool loop reads it to * tell "you may not do this" apart from "the tool broke". */ rejected?: boolean; functionName?: string; args?: Record; /** The guard ids this `try` boundary OWNS. A `guardTrip` cause is * converted to a Failure ONLY when its `guardId` is in this list; * any other guard's trip (an outer guard, or a plain `try` that owns * no guards) re-throws so it reaches its owning boundary. Set by the * stdlib `guard`'s `_runGuarded`. Absent for a plain `try`. */ ownedGuardIds?: string[]; }; /** One hop in a propagated failure's journey: the function whose body was * skipped and the parameter that rejected the failure. */ export type SkippedFunction = { name: string; param: string; }; export type ResultFailure = { __type: "resultType"; success: false; error: string; /** Extra structured detail, named by the second `Result` type parameter. * `{}` when the producer passed none. Never null: a reader may write * `err.data.status` without checking first. */ data: Record; checkpoint: any; /** The call failed before its function body began. Birth default false; * set only by the tool loop from the invoke layer's pre-execution tag. * Trust-the-producer: there is no correcting machinery, so nothing else * may set it. */ neverStarted: boolean; /** Execution had entered a destructive region — a `destructive def` body * (commits at function entry) or a `destructive { }` region (commits at * region entry) — when this failure was produced. Birth default false; * boundaries OR the activation's flag in via stampFailureBoundary. */ destructiveRan: boolean; /** This failure is a rejected interrupt (see FailureOpts.rejected). * Birth default false; set only by the interrupt codegen templates. */ rejected: boolean; functionName: string | null; args: Record | null; skippedFunctions: SkippedFunction[]; }; export declare function success(value: any): ResultSuccess; export declare function failure(error: unknown, data?: Record | null, opts?: FailureOpts): ResultFailure; /** The failure a generated program or the runtime itself produces: a thrown * exception converted at a function boundary, a rejected interrupt, a tool * that crashed. None of these carry user data. Most are written from * templates the compiler does not check, which is why they get an entry point * with no positional slot to get wrong. Pass the raw error; it coerces. */ export declare function runtimeFailure(error: unknown, opts: FailureOpts): ResultFailure; /** A Result that imported TypeScript built by hand, rather than by calling * `failure()`, can carry an object error and no data at all. Every place a * value crosses from JavaScript into Agency (`try`, a call through * `__call`, an `AgencyFunction` wrapping a TypeScript function) runs it * through here so the invariant the type checker relies on holds: `error` * is a string, `data` is an object. Anything that is not a failure, and a * well-formed failure, is returned unchanged by identity. */ export declare function normalizeForeignResult(value: T): T; /** Fold an activation's destructive flag into a failure crossing a * boundary (function exit, block halt, block join). OR: once destructive * work started anywhere below, the failure reports it. */ export declare function stampFailureBoundary(f: ResultFailure, destructiveRan: boolean): ResultFailure; /** Record that destructive work ran in the given activation. Writes the * slot the codegen flag lives in (frame.locals IS the generated * function's __self — see lib/runtime/node.ts), so the exit stamp picks * it up with no second source. Sole caller: the tool loop, when a * destructive-marked tool executed or a tool failed destructively. */ export declare function markDestructiveWork(frame: { locals: Record; } | undefined): void; /** Shallow-clone a failure with one more skip entry. Used by the * failure-propagation check when a call short-circuits: the ORIGINAL * failure's error/functionName/args survive untouched so the origin is * never hidden. `failure()` is the single initializer of * skippedFunctions — no `?? []` fallback here (spec: no backward-compat * handling for pre-feature serialized failures). */ export declare function propagateFailure(orig: ResultFailure, skipped: SkippedFunction): ResultFailure; export declare function isSuccess(result: unknown): result is ResultSuccess; export declare function isFailure(result: unknown): result is ResultFailure; /** Wrap a function call in try-catch, returning a Result. * If the function already returns a Result, pass it through (no double-wrapping). * `log` is the logger of the run the `try` is in: a guard trip delivered * here posts its closing event through it. */ export declare function __tryCall(log: AbortLog, fn: () => any, opts?: FailureOpts): Promise; /** Unwrap a Result: return value on success, evaluate fallback on failure. * If the input is not a valid Result, returns it as-is. */ export declare function __catchResult(result: any, fallback: () => any): any; export declare function __pipeBind(result: any, fn: (value: any) => any): Promise;