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

56 lines (55 loc) • 2.51 kB
import { trace } from "@opentelemetry/api"; import { JEV_ROUTING_AUDIT_OBSERVATION_NAME, JEV_ROUTING_AUDIT_PROVIDER, JEV_ROUTING_AUDIT_SCHEMA_VERSION, } from "../core/constants.js"; import { buildJevRoutingAuditSelection, logJevRoutingAuditFailure, } from "../utils/jevRoutingAudit.js"; import { observe } from "./observation.js"; import { tracers } from "./tracers.js"; /** Create a native child only after the actual routing exclusions are applied. */ export const recordJevRoutingAudit = (evidence, decision, catalog, finalExcludedTools, preExistingExcludedTools = []) => { try { if (evidence === null || evidence.provider !== JEV_ROUTING_AUDIT_PROVIDER) { return; } if (decision === undefined) { return; } const serverRoutingWasApplied = decision.strategy === "decision" && decision.outcome === "applied" && decision.granularity !== "tool"; if (!serverRoutingWasApplied) { return; } const parent = trace.getActiveSpan(); if (!parent?.isRecording()) { return; } const selection = buildJevRoutingAuditSelection(evidence.input.candidateServers, catalog, finalExcludedTools, preExistingExcludedTools); let evaluable = false; if (evidence.input.evidenceComplete && selection.selectionComplete) { evaluable = true; } const output = { retainedServers: selection.retainedServers, excludedServers: selection.excludedServers, routingStrategy: decision.strategy, outcome: decision.outcome, evaluable: evaluable, excludedToolCount: selection.excludedToolCount, }; const span = tracers.decision.startSpan(JEV_ROUTING_AUDIT_OBSERVATION_NAME, { attributes: { "jev.audit.schema_version": JEV_ROUTING_AUDIT_SCHEMA_VERSION, "jev.audit.evaluable": evaluable, "jev.audit.provider": evidence.provider, "jev.audit.model": evidence.model, "jev.audit.decision_succeeded": true, "jev.audit.source_span_id": parent.spanContext().spanId, }, }); // observe() masks credentials and omits input when NEUROLINK_RECORD_INPUTS=false. observe(span, "span", { input: evidence.input, output: output }); span.end(); } catch (error) { logJevRoutingAuditFailure(error); } };