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

66 lines (65 loc) • 3.58 kB
/** * The one HITL confirmation step every tool-execution path shares. * * `NeuroLink.executeTool` runs it once per call, before the circuit breaker, * the retry loop and the attempt timeout, and records the decision on the * call's `HITLExecutionState`. The tool registry and the external server * manager run the same step inline only for a caller that arrives with no * recorded decision, so a gated call is never asked twice. */ import type { Span } from "@opentelemetry/api"; import type { HITLConfirmationContext, HITLExecutionState, HITLManager, HITLOutcomeAction, PauseDeadline } from "../types/index.js"; /** * A fresh state for one tool call. `triggered` is kept for callers that read * it and is only ever true once a human approved the call. */ export declare function createHITLExecutionState(): HITLExecutionState; /** * Whether `hitl` confirms every call to the built-in tool `toolName`, whether * or not its rule matches the name: true for the built-ins that change the * machine unless the host set `hitl.confirmBuiltinTools: false`. */ export declare function builtInToolAlwaysConfirmed(hitl: HITLManager, toolName: string): boolean; /** * `builtInToolAlwaysConfirmed` for a direct call to a tool resolved from the * registry. It is opt-in (`hitl.confirmDirectToolCalls: true`) because direct * callers were never prompted for these tools. Only a tool registered by * NeuroLink itself (server `direct`) is a built-in, so a custom or external * tool that reuses the name `writeFile` is not swept in. */ export declare function registeredToolAlwaysConfirmed(hitl: HITLManager, toolName: string, serverId: string | undefined): boolean; /** Mark `result` as a HITL refusal and return it. */ export declare function markRefusalResult<T extends object>(result: T): T; /** Whether `result` was marked as a HITL refusal (`markRefusalResult`). */ export declare function isRefusalResult(result: unknown): boolean; /** * Whether the call's recorded decision refused it. The result of such a call * is a refusal, and a refusal must never be cached: the next identical call * has to raise a fresh card. */ export declare function hitlStateRefused(state: HITLExecutionState | undefined): boolean; /** * The confirmation step for one tool call, shared by `NeuroLink.executeTool`'s * gate, the tool registry and the external server manager. * * - A state that already records a decision is not asked again: `approved` * and `not-required` run with the arguments they were decided for, any * refusal is refused. A state reused with other arguments is decided again. * - With HITL off, the call runs and nothing is recorded. * - Otherwise the human is asked (when the tool needs it) and the decision is * written to `state` after the wait, never before it. * * `report` lets the caller log the ask and the decision with its own logger * and puts `tool.hitl_*` events and `tool.hitl.decision` on its span; * `subject` names the tool kind in the messages (default "Tool"); * `pauseDeadline` pauses the caller's outer deadlines while the human decides; * `alwaysConfirm` asks even when the rule does not match the tool (see * `builtInToolAlwaysConfirmed`). */ export declare function resolveToolCallConfirmation(hitl: HITLManager | undefined, toolName: string, args: unknown, state: HITLExecutionState | undefined, context: HITLConfirmationContext, report?: { log?: (message: string) => void; span?: Span; subject?: string; pauseDeadline?: PauseDeadline; alwaysConfirm?: boolean; }): Promise<HITLOutcomeAction>;