@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
69 lines (68 loc) • 3.66 kB
TypeScript
import type { MiddlewareFactoryOptions } from "../types/index.js";
/**
* Middleware defaults.
*
* A generate()/stream() call resolves its middleware from up to four layers,
* lowest precedence first:
*
* 1. NEUROLINK_MIDDLEWARE_PRESET (process environment)
* 2. configureGlobalMiddleware() (module-level, set at runtime)
* 3. new NeuroLink({ middleware }) (per instance)
* 4. generate({ middleware }) (per call)
*
* A layer that is absent changes nothing, so a call made with no default set
* keeps exactly the middleware it passed.
*/
export declare const MIDDLEWARE_PRESET_ENV_VAR = "NEUROLINK_MIDDLEWARE_PRESET";
/**
* Layer `override` over `base`.
*
* - `preset`, `middleware`, `enabledMiddleware` and `disabledMiddleware`: the
* override's value replaces the base's whole; arrays are never concatenated.
* - `middlewareConfig`: merged per middleware id. Within an id, `enabled` and
* `conditions` come from the override when it sets them, and `config` is
* merged key by key, so a key the override sets replaces the base's value
* for that key as a whole (nested objects and arrays are not combined).
* - `global`: merged key by key.
*
* The factory applies `disabledMiddleware` after `enabledMiddleware`, so an id
* the override switches on must be taken out of a disabled list it inherits
* (and the reverse), or a lower layer's list would out-vote a call that asked
* for the opposite.
*/
export declare function mergeMiddlewareOptions(base: MiddlewareFactoryOptions, override: MiddlewareFactoryOptions): MiddlewareFactoryOptions;
/**
* Resolve the options a call runs with. `defaults` is ordered lowest
* precedence first; the per-call options sit on top.
*
* With no default present this returns `call` itself, so callers that never
* opted in see no change at all.
*/
export declare function resolveMiddlewareOptions(defaults: ReadonlyArray<MiddlewareFactoryOptions | undefined>, call: MiddlewareFactoryOptions | undefined): MiddlewareFactoryOptions | undefined;
/**
* Validate a default layer and copy it, so later edits to the caller's object
* cannot change a default that was already set. Plain data (a word list, a
* replacement string) is copied in full; custom middleware, callbacks and
* model handles keep their identity. Throws a TypeError for a value that is
* not an object and for a preset name that is not built in.
*/
export declare function snapshotMiddlewareOptions(options: MiddlewareFactoryOptions, source: string): MiddlewareFactoryOptions;
/**
* Process-wide middleware defaults. Applies to every NeuroLink instance, below
* the instance's own `middleware` option and above NEUROLINK_MIDDLEWARE_PRESET.
* Replaces any earlier call rather than adding to it, and is read on each
* generate()/stream(), so instances that already exist pick it up. Throws a
* TypeError when `options` is not an object or names a preset that is not
* built in.
*/
export declare function configureGlobalMiddleware(options: MiddlewareFactoryOptions): void;
/** Remove the defaults set by {@link configureGlobalMiddleware}. */
export declare function clearGlobalMiddleware(): void;
/** The current global defaults, or undefined when none are set. */
export declare function getGlobalMiddleware(): MiddlewareFactoryOptions | undefined;
/**
* The preset named by NEUROLINK_MIDDLEWARE_PRESET, as the lowest default layer.
* An unset or blank variable is no layer; an unrecognised name is reported
* on stderr once per distinct value and ignored.
*/
export declare function readEnvMiddlewarePreset(env?: NodeJS.ProcessEnv): MiddlewareFactoryOptions | undefined;