@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
57 lines (56 loc) • 3.15 kB
TypeScript
import type { ToolCallRepairFunction, ToolSet } from "../types/index.js";
import type { ToolNameResolution } from "../types/index.js";
/**
* Create an `experimental_repairToolCall` handler for streamText/generateText.
* Fully dynamic — reads the tool schema at repair time, no configuration needed.
*/
export declare function createToolCallRepair(): ToolCallRepairFunction<ToolSet>;
/**
* Match a possibly-misspelled tool name against a list of available tool
* names. Strategies (in order): case-insensitive exact → unambiguous
* substring → Levenshtein.
*
* Pulled out of `repairToolName` so the same matching policy can be reused
* outside the AI-SDK generation loop — `experimental_repairToolCall` only
* runs inside `streamText`/`generateText`, so a name typo at a direct MCP
* execution boundary (`NeuroLink.executeExternalMCPTool`) previously had no
* recovery at all. This function is pure name-matching: no `LanguageModelV3ToolCall`,
* no logging, so callers with a different call shape can reuse it directly.
*/
export declare function resolveToolName(calledName: string, availableTools: string[]): ToolNameResolution | null;
/**
* Rank every available tool name by similarity to `calledName` (ascending
* normalized Levenshtein distance) and return the closest `limit`.
*
* Used to build the candidate list on `ExternalMcpToolNotFoundError` when
* `resolveToolName` found no unambiguous match — unlike `resolveToolName`,
* this makes no accept/reject judgment, it just orders what is available so
* a caller (human or AI) can pick the right name themselves.
*/
export declare function rankToolNameCandidates(calledName: string, availableTools: string[], limit?: number): string[];
/**
* Thrown at a direct MCP execution boundary (`NeuroLink.executeExternalMCPTool`)
* when `resolveToolName` cannot find an unambiguous match for a requested
* tool name against a server's discovered tools. Distinct from the plain
* `Error` that `ToolDiscoveryService.executeTool` throws deeper in the stack
* for the same condition, so callers can distinguish "no match — here are
* the closest names" from every other execution failure programmatically,
* instead of parsing a message string.
*/
export declare class ExternalMcpToolNotFoundError extends Error {
/** The tool name that was requested and could not be resolved. */
readonly requestedName: string;
/** The server the tool was requested against. */
readonly serverId: string;
/** Closest available tool names on that server, capped (see `rankToolNameCandidates`). */
readonly candidates: string[];
constructor(requestedName: string, serverId: string, candidates: string[]);
}
/**
* Coerce a value to match the expected schema type.
* Handles: string→number, JSON string→object, JSON string→array, value→[value].
* Exported for reuse by the MCP-layer parameter validator
* (toolDiscoveryService), which coerces before rejecting so a recoverable
* mismatch doesn't cost the agent loop a full model round-trip.
*/
export declare function coerceType(value: unknown, propSchema: Record<string, unknown>): unknown;