@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
48 lines (47 loc) • 2.6 kB
TypeScript
/**
* Step 1 of "One stream core, rules as data": one `run()` that yields typed
* events, and `generate()` built by collecting them.
*
* `run()` sits in front of today's stream path: it calls `stream()` and turns
* the StreamResult into the closed event set in `types/runCore.ts`. Collecting
* those events gives the same fields the separate generate path returns.
*
* The collect path answers `generate()` only behind a switch (the `runCore`
* constructor option or `NEUROLINK_RUN_CORE=1`), only for the provider named
* in RUN_CORE_PROVIDERS, and only for requests whose options it covers. Every
* other call keeps today's path.
*/
import type { GenerateOptions, RunCoreWireLookup, RunCoreCollected, RunEvent, StreamResult } from "../types/index.js";
/**
* Hidden key on a StreamResult's metadata under which a provider stream path
* records RunCoreStreamDetails. Non-enumerable and symbol-keyed, so existing
* stream() readers, spreads and JSON never see it.
*/
export declare const RUN_CORE_STREAM_DETAILS: unique symbol;
/** True when the switch is on for this instance or the environment. */
export declare function isRunCoreEnabled(instanceFlag: boolean | undefined): boolean;
/**
* Whether a generate request can be answered by collecting `run()` events.
* Text-only input, a provider on the openai-chat wire, and only option keys the
* collect path covers.
*/
export declare function runCoreSupports(options: GenerateOptions, wireOf: RunCoreWireLookup): boolean;
/**
* Turn today's StreamResult into run events: start, the text and reasoning
* deltas in order, then (once the stream has drained) the tool calls and
* results, the object for a schema turn, usage and finish. A stream that
* throws ends with an error event.
*
* The stream is pulled once before `start` is yielded, so a caller that stops
* at any event (even the first) closes a started stream, whose own cleanup
* then runs. Tool events come after the text because this stream path reports
* tool executions on the result, not inline; a later step moves them inline.
*/
export declare function streamResultToRunEvents(result: StreamResult, requestId: string): AsyncGenerator<RunEvent>;
/**
* Collect a run's events. An error event is rethrown as the error it carries,
* so a caller of generate() sees the same failure the stream raised. The
* content is the joined text, or a multi-step turn's answer text, which is
* what generate() returns; reasoning accumulates across steps, as there.
*/
export declare function collectRunEvents(events: AsyncIterable<RunEvent>): Promise<RunCoreCollected>;