UNPKG

@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

32 lines (31 loc) • 1.84 kB
import type { JsonCoercionResult, ScalarRecoveryDecision, ValidationSchema } from "../../types/index.js"; /** * Does `value` satisfy `schema`? A schema we cannot validate with (absent, or * without a Zod-style `safeParse`) accepts everything — callers use this as a * gate, not as proof, so an unknown schema must never block a value. * * Exists so the consumers of coerceJsonToSchema can refuse to publish a * recovered value as `structuredData` when the caller's schema rejects it — * e.g. a raw *string* under an object schema, which is the shape a truncated * response degrades to. */ export declare function schemaAccepts(schema: ValidationSchema | undefined, value: unknown): boolean; /** * Recover a JSON *scalar* root (string/number/boolean) from model text. The * object/array case is handled by `coerceJsonToSchema`; this covers the * residual scalar root after that path returns null. Encapsulates the JSON * parsing, the empty-string normalization, and the `schemaAccepts` gate so the * same policy cannot drift between consumers. `neurolink.recoverStructuredData` * is the only one left; `GenerationHandler.coerceTextMode` was the other until * the ai-package path was deleted. */ export declare function recoverScalarRoot(text: string, schema: ValidationSchema | undefined): ScalarRecoveryDecision; /** * Try to produce canonical JSON from `text`. Returns null when no JSON object * could be recovered (caller should then keep the raw text). * * When `schema` is a Zod schema, candidates that satisfy it are preferred; a * syntactically-valid-but-schema-failing object is still returned (we guarantee * JSON *validity*, leaving schema/content checks to the caller's own pipeline). */ export declare function coerceJsonToSchema(text: string, schema?: ValidationSchema): JsonCoercionResult | null;