@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
36 lines (35 loc) • 2.04 kB
TypeScript
/**
* The multi-step tool loop that the ai package's `generateText` used to supply.
*
* It deliberately loops over a provider's own `doGenerate` rather than over any
* streaming machinery. That is the whole lesson of the reverted first attempt:
* `doGenerate` is where the JSON-versus-SSE wire choice lives, along with the
* 400 retry, the context-overflow refit and the provider's own structured-output
* handling. Looping around the streaming path instead silently changed
* generate() to send `stream: true` and broke ten providers against a
* non-streaming body.
*
* Every provider whose delegating model exposes a v3-shaped `doGenerate` can
* share this: the v3 result shape (`content` parts, `finishReason`, `usage`) is
* the same across Anthropic, the OpenAI-compatible family and SageMaker.
*/
import type { NativeGenerateLoopArgs, NativeGenerateLoopResult, ToolExecutionSummaryInternal } from "../types/index.js";
/**
* Narrow a model handle to the delegating shape this loop drives.
* `LanguageModel` is a union that includes a bare string id, and a double
* assertion through unknown is banned by Critical Rule 14.
*/
export declare const hasNativeDoGenerate: (value: unknown) => value is {
doGenerate: (options: Record<string, unknown>) => Promise<Record<string, unknown>>;
};
/**
* Spell a JSON Schema into the conversation's system turn.
*
* The structured-output fallback for vendors that reject or ignore
* `response_format`. Merged into an existing trailing system message rather
* than appended as a second one: several self-hosted OpenAI-compatible stacks
* honour only the first system message, so a second would be dropped and the
* fallback would silently do nothing.
*/
export declare const appendJsonSchemaInstruction: (conversation: Array<Record<string, unknown>>, schema: unknown) => Array<Record<string, unknown>>;
export declare function runNativeGenerateLoop(args: NativeGenerateLoopArgs, toolExecutionSummaries: ToolExecutionSummaryInternal[]): Promise<NativeGenerateLoopResult>;