@juspay/neurolink 13.16.0 → 13.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -3
- package/dist/browser/neurolink.min.js +411 -411
- package/dist/providers/openaiChatCompletionsBase.js +20 -5
- package/dist/types/generate.d.ts +6 -0
- package/dist/utils/timeout.d.ts +16 -0
- package/dist/utils/timeout.js +19 -0
- package/package.json +2 -1
|
@@ -34,7 +34,7 @@ import { logger } from "../utils/logger.js";
|
|
|
34
34
|
import { redactUrlCredentials } from "../utils/logSanitize.js";
|
|
35
35
|
import { NoOutputGeneratedError } from "../utils/generationErrors.js";
|
|
36
36
|
import { buildNoOutputSentinel, stampNoOutputSpan, } from "../utils/noOutputSentinel.js";
|
|
37
|
-
import { composeAbortSignalsScoped, createTimeoutController, getStreamLifetimeTimeout, mergeAbortSignals, monitorStreamActivity, TimeoutError, } from "../utils/timeout.js";
|
|
37
|
+
import { composeAbortSignalsScoped, createTimeoutController, getStepHardCapTimeout, getStreamLifetimeTimeout, mergeAbortSignals, monitorStreamActivity, TimeoutError, } from "../utils/timeout.js";
|
|
38
38
|
import { resolveRequestKind } from "../core/resolveRequestKind.js";
|
|
39
39
|
import { appendJsonSchemaInstruction, hasNativeDoGenerate, parseToolInput, resolveStepToolChoice, runNativeGenerateLoop, toNativeToolDeclaration, toPrepareStepRecord, validateToolInput, } from "../core/nativeGenerateLoop.js";
|
|
40
40
|
import { resolveToolExecutionRecords, toolCallsFromSummaries, } from "../core/toolExecutionRecorder.js";
|
|
@@ -643,14 +643,27 @@ export class OpenAIChatCompletionsProvider extends BaseProvider {
|
|
|
643
643
|
// orchestrator forwards the caller's resolved timeout via
|
|
644
644
|
// providerOptions.neurolink.timeoutMs; prefer it when present.
|
|
645
645
|
const nlStepTimeoutMs = options.providerOptions?.neurolink?.timeoutMs;
|
|
646
|
-
const
|
|
646
|
+
const stepTimeout = typeof nlStepTimeoutMs === "number"
|
|
647
647
|
? nlStepTimeoutMs
|
|
648
|
-
: getTimeoutForOptions(options)
|
|
648
|
+
: getTimeoutForOptions(options);
|
|
649
|
+
const timeoutController = createTimeoutController(stepTimeout, providerName, "generate");
|
|
650
|
+
// On the SSE wire the controller above is an IDLE timer (every chunk
|
|
651
|
+
// re-arms it), so it cannot bound a stream that keeps sending bytes.
|
|
652
|
+
// This second, never-reset controller is the step's absolute
|
|
653
|
+
// wall-clock ceiling.
|
|
654
|
+
const stepCapController = sseWire
|
|
655
|
+
? createTimeoutController(getStepHardCapTimeout(stepTimeout), providerName, "generate")
|
|
656
|
+
: null;
|
|
649
657
|
// Scoped composition: a plain AbortSignal.any per step accumulates
|
|
650
658
|
// registrations on the long-lived generate-call signal for the whole
|
|
651
659
|
// turn (MaxListenersExceededWarning at 10+ steps); dispose() detaches
|
|
652
660
|
// this step's listeners the moment the request settles.
|
|
653
|
-
const { signal: composedSignal, dispose: disposeComposedSignal } = composeAbortSignalsScoped(options.abortSignal,
|
|
661
|
+
const { signal: composedSignal, dispose: disposeComposedSignal } = composeAbortSignalsScoped(options.abortSignal, stepCapController
|
|
662
|
+
? mergeAbortSignals([
|
|
663
|
+
timeoutController?.controller.signal,
|
|
664
|
+
stepCapController.controller.signal,
|
|
665
|
+
]).signal
|
|
666
|
+
: timeoutController?.controller.signal);
|
|
654
667
|
let json;
|
|
655
668
|
// Whether the response we end up consuming is SSE. Starts as the
|
|
656
669
|
// provider's wire preference; the 400 fallback below can flip it
|
|
@@ -726,7 +739,8 @@ export class OpenAIChatCompletionsProvider extends BaseProvider {
|
|
|
726
739
|
// Idle-timeout semantics: every raw chunk re-arms the timeout,
|
|
727
740
|
// so the configured window bounds silence, not total duration —
|
|
728
741
|
// the whole point of the SSE wire is that a slow-but-alive
|
|
729
|
-
// completion keeps the connection (and the timer) fed.
|
|
742
|
+
// completion keeps the connection (and the timer) fed. Total
|
|
743
|
+
// duration is bounded separately by `stepCapController`.
|
|
730
744
|
const monitored = timeoutController
|
|
731
745
|
? monitorStreamActivity(res.body, timeoutController.reset)
|
|
732
746
|
: res.body;
|
|
@@ -770,6 +784,7 @@ export class OpenAIChatCompletionsProvider extends BaseProvider {
|
|
|
770
784
|
}
|
|
771
785
|
finally {
|
|
772
786
|
timeoutController?.cleanup();
|
|
787
|
+
stepCapController?.cleanup();
|
|
773
788
|
disposeComposedSignal();
|
|
774
789
|
}
|
|
775
790
|
const choice = json.choices?.[0];
|
package/dist/types/generate.d.ts
CHANGED
|
@@ -441,6 +441,12 @@ export type GenerateOptions = {
|
|
|
441
441
|
* `turnTimeoutMs` unset, this value bounds the WHOLE turn there (the
|
|
442
442
|
* pre-existing defensive behavior, kept for backward compatibility).
|
|
443
443
|
*
|
|
444
|
+
* On the SSE wire that `generate()` uses for LiteLLM, this value is an IDLE
|
|
445
|
+
* window (every received byte re-arms it, so a slow-but-alive completion
|
|
446
|
+
* survives proxy idle limits) and each model call additionally has an
|
|
447
|
+
* absolute wall-clock ceiling of 3x this value, so a stream that keeps
|
|
448
|
+
* sending keep-alive frames can no longer run until `turnTimeoutMs`.
|
|
449
|
+
*
|
|
444
450
|
* When set explicitly, a step timeout is surfaced immediately instead of
|
|
445
451
|
* burning internal retries/fallbacks that would re-run the same
|
|
446
452
|
* provider+model with the same doomed budget.
|
package/dist/utils/timeout.d.ts
CHANGED
|
@@ -136,6 +136,22 @@ export declare function createTimeoutController(timeout: number | string | undef
|
|
|
136
136
|
reset: () => void;
|
|
137
137
|
timeoutMs: number;
|
|
138
138
|
} | null;
|
|
139
|
+
/**
|
|
140
|
+
* How many times the per-step idle window a single streamed model call may
|
|
141
|
+
* last in total. The idle window re-arms on every received byte, so on its
|
|
142
|
+
* own a stream that keeps delivering keep-alive frames (or a model emitting
|
|
143
|
+
* one token a minute) is never bounded per call; this multiple is the
|
|
144
|
+
* absolute wall-clock ceiling that closes that gap.
|
|
145
|
+
*/
|
|
146
|
+
export declare const STEP_HARD_CAP_MULTIPLIER = 3;
|
|
147
|
+
/**
|
|
148
|
+
* Absolute wall-clock ceiling (ms) for ONE streamed model call, derived from
|
|
149
|
+
* its idle window: `STEP_HARD_CAP_MULTIPLIER` x the window. A slow-but-alive
|
|
150
|
+
* completion still gets several idle windows of room, but can never outlive
|
|
151
|
+
* the cap, so the whole-turn deadline is no longer the only thing that stops
|
|
152
|
+
* a runaway step.
|
|
153
|
+
*/
|
|
154
|
+
export declare function getStepHardCapTimeout(idleTimeout: number | string | undefined): number | undefined;
|
|
139
155
|
/** Keep a stream's idle deadline alive for every received wire chunk. */
|
|
140
156
|
export declare function monitorStreamActivity(body: ReadableStream<Uint8Array>, onActivity: () => void): ReadableStream<Uint8Array>;
|
|
141
157
|
/**
|
package/dist/utils/timeout.js
CHANGED
|
@@ -378,6 +378,25 @@ export function createTimeoutController(timeout, provider, operation) {
|
|
|
378
378
|
};
|
|
379
379
|
return { controller, cleanup, reset, timeoutMs };
|
|
380
380
|
}
|
|
381
|
+
/**
|
|
382
|
+
* How many times the per-step idle window a single streamed model call may
|
|
383
|
+
* last in total. The idle window re-arms on every received byte, so on its
|
|
384
|
+
* own a stream that keeps delivering keep-alive frames (or a model emitting
|
|
385
|
+
* one token a minute) is never bounded per call; this multiple is the
|
|
386
|
+
* absolute wall-clock ceiling that closes that gap.
|
|
387
|
+
*/
|
|
388
|
+
export const STEP_HARD_CAP_MULTIPLIER = 3;
|
|
389
|
+
/**
|
|
390
|
+
* Absolute wall-clock ceiling (ms) for ONE streamed model call, derived from
|
|
391
|
+
* its idle window: `STEP_HARD_CAP_MULTIPLIER` x the window. A slow-but-alive
|
|
392
|
+
* completion still gets several idle windows of room, but can never outlive
|
|
393
|
+
* the cap, so the whole-turn deadline is no longer the only thing that stops
|
|
394
|
+
* a runaway step.
|
|
395
|
+
*/
|
|
396
|
+
export function getStepHardCapTimeout(idleTimeout) {
|
|
397
|
+
const idleMs = parseTimeout(idleTimeout);
|
|
398
|
+
return idleMs ? idleMs * STEP_HARD_CAP_MULTIPLIER : undefined;
|
|
399
|
+
}
|
|
381
400
|
/** Keep a stream's idle deadline alive for every received wire chunk. */
|
|
382
401
|
export function monitorStreamActivity(body, onActivity) {
|
|
383
402
|
return body.pipeThrough(new TransformStream({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juspay/neurolink",
|
|
3
|
-
"version": "13.16.
|
|
3
|
+
"version": "13.16.2",
|
|
4
4
|
"packageManager": "pnpm@10.34.9+sha512.f49b5a8ea0fdedb44bb3c0c1d6575092a53c2950d95b7ad15df11f17974877a2de3a01c07e934e9b28ce716e51c09a94962c7306d09be2e1e4b18a8c8762fd32",
|
|
5
5
|
"description": "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/call) for routing, tool selection and context budgeting. MCP-native (4 transports), voice TTS/STT/realtime, RAG, agents, memory, compaction, 9 observability exporters. OpenAI · Anthropic · Gemini · Bedrock · Azure · Ollama · TypeSafe Jev and more.",
|
|
6
6
|
"author": {
|
|
@@ -108,6 +108,7 @@
|
|
|
108
108
|
"test:multimodal-text-content-fold": "pnpm exec tsx test/continuous-test-suite-multimodal-text-content-fold.ts",
|
|
109
109
|
"test:proxy-sharing": "pnpm run build && pnpm exec tsx test/continuous-test-suite-proxy-sharing.ts",
|
|
110
110
|
"test:openai-compat-streaming-retry": "pnpm exec tsx test/continuous-test-suite-openai-compat-streaming-retry.ts",
|
|
111
|
+
"test:litellm-sse-step-cap": "pnpm exec tsx test/continuous-test-suite-litellm-sse-step-cap.ts",
|
|
111
112
|
"test:openai-compat-stream-truncation": "pnpm exec tsx test/continuous-test-suite-openai-compat-stream-truncation.ts",
|
|
112
113
|
"test:openai-compat-stream-cancel": "pnpm exec tsx test/continuous-test-suite-openai-compat-stream-cancel.ts",
|
|
113
114
|
"test:anthropic-streaming-retry": "pnpm exec tsx test/continuous-test-suite-anthropic-streaming-retry.ts",
|