@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
41 lines (40 loc) • 2.17 kB
TypeScript
/**
* Tool policy resolution — the single, pure mapping from every tool-selection
* surface (per-call legacy options + instance-level `tools` config) to one
* ResolvedToolPolicy that the gate applies.
*
* Legacy semantics are preserved deliberately:
* - `toolFilter: []` and `enabledToolNames: []` are no-ops (fail-open), as
* they always were.
* - Malformed shapes (non-string-arrays) are ignored with a once-per-process
* WARN instead of throwing — some internal callers historically passed
* wrong shapes and relied on the silent no-op.
* - `enabledToolNames` now filters the native tool set (its docs always
* promised this; it previously only filtered the system-prompt listing) —
* but ONLY when `toolFilter` is absent. When both are set, `toolFilter`
* alone bounds the native set, exactly as before this refactor: the native
* set must never become WIDER than a caller's `toolFilter`.
*
* New semantics:
* - `tools.include: []` (the instance config surface) means NO tools
* (fail-closed); legacy empty arrays stay fail-open as above.
* - A per-call `toolFilter` is bounded by `tools.include` — it can narrow
* the instance allowlist but never widen past it.
* - Pattern entries containing `*` match as globs (e.g. `"github*"`) on ALL
* surfaces. Real tool names cannot contain `*` (MCP names are sanitized),
* so a legacy list entry with `*` previously matched nothing (dead entry);
* it now matches as a glob. Entries without `*` match exactly, unchanged.
*/
import type { ResolvedToolPolicy, ToolPolicyResolutionInput } from "../types/index.js";
/**
* Compile a list of tool-name patterns into a matcher. Patterns without `*`
* match exactly (case-sensitive, preserving legacy toolFilter semantics);
* patterns containing `*` match as globs.
*/
export declare function toolNameMatcher(patterns: string[]): (name: string) => boolean;
/**
* Resolve the effective tool policy for one request. Pure function — all
* inputs are explicit, so the legacy→policy mapping is unit-testable as a
* table.
*/
export declare function resolveToolPolicy(input: ToolPolicyResolutionInput): ResolvedToolPolicy;