@sema-agent/core
Version:
Stateless, task-oriented AI agent core
32 lines (31 loc) • 2 kB
TypeScript
/**
* The whole-number env grammar, with one deliberate narrowing against the reference harness: no
* `parseInt` prefix leg, so `"30s"` is a REJECTION rather than `30` — "a typo silently becomes a budget" is
* the class of defect this chokepoint exists to close, and the prefix leg is survivable upstream only
* because its clamp floor catches the result. What IS accepted is what an operator plausibly means: plain
* digits (an explicit sign included), scientific notation, and digit grouping — the last one because this
* repository writes its own constants that way (`100_000_000`), and copying a source literal into the
* environment must not silently become `100`. Hex, octal and every other spelling are rejected.
*/
export declare function parseWholeNumber(raw: string): number | undefined;
/** What a knob is a budget OF — the unit word the invalid-value announcement names. */
export type EnvBudgetUnit = "characters" | "tokens" | "milliseconds";
/** One knob's contract: its name, its unit, the value in force when it is absent or invalid (`undefined`
* = "a downstream built-in default stands", the SDK-timeout shape), and the range it is held to. */
export interface EnvBudgetSpec<D extends number | undefined> {
readonly name: string;
readonly unit: EnvBudgetUnit;
readonly default: D;
/** Inclusive floor; a smaller value is raised to it, loudly. */
readonly min?: number;
/** Inclusive ceiling; a larger value is capped to it, loudly. */
readonly max?: number;
}
/**
* Resolve one knob from its raw environment string (see the module note for the four states).
*
* @contract env_budget.single_resolver — every process-level numeric env knob resolves through this
* function: one grammar, one range rule, one loud outlet. A knob resolved elsewhere is a fork of this
* contract, not a knob.
*/
export declare function resolveEnvBudget<D extends number | undefined>(rawEnv: string | undefined, spec: EnvBudgetSpec<D>): number | D;