@juspay/neurolink 13.15.1 → 13.15.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 +2 -2
- package/dist/browser/neurolink.min.js +273 -273
- package/dist/neurolink.js +2 -3
- package/dist/providers/systemOneDecision.js +8 -9
- package/dist/utils/timeout.d.ts +13 -0
- package/dist/utils/timeout.js +29 -0
- package/package.json +1 -1
package/dist/neurolink.js
CHANGED
|
@@ -14903,9 +14903,8 @@ Current user's request: ${currentInput}`;
|
|
|
14903
14903
|
*/
|
|
14904
14904
|
async siteDecide(request, outer) {
|
|
14905
14905
|
// Either cancellation must win: the outer call's abort and the site's own
|
|
14906
|
-
// deadline are independent limits. Scoped, not AbortSignal.any
|
|
14907
|
-
//
|
|
14908
|
-
// awaiting could lose the link and never see the abort.
|
|
14906
|
+
// deadline are independent limits. Scoped, not AbortSignal.any, so the
|
|
14907
|
+
// listeners are removed as soon as the decision settles.
|
|
14909
14908
|
const linked = composeAbortSignalsScoped(outer?.signal, request.signal);
|
|
14910
14909
|
try {
|
|
14911
14910
|
return await this.siteDecideLinked(request, outer, linked.signal);
|
|
@@ -6,7 +6,7 @@ import { ProviderError } from "../types/index.js";
|
|
|
6
6
|
import { prepareDecisionMedia } from "../utils/decisionMedia.js";
|
|
7
7
|
import { logger } from "../utils/logger.js";
|
|
8
8
|
import { redactUrlsInText } from "../utils/logSanitize.js";
|
|
9
|
-
import { composeAbortSignalsScoped } from "../utils/timeout.js";
|
|
9
|
+
import { composeAbortSignalsScoped, readJsonWithSignal, } from "../utils/timeout.js";
|
|
10
10
|
import { estimateDecisionStateTokens, resolveDecisionLimitsReading, unsupportedDecisionQuestion, } from "../utils/decisionLimits.js";
|
|
11
11
|
import { systemOneDialect } from "./decide/dialects/systemOne.js";
|
|
12
12
|
import { asNumber, isRecord } from "./decide/guards.js";
|
|
@@ -299,11 +299,10 @@ export class SystemOneDecisionProvider extends BaseProvider {
|
|
|
299
299
|
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
300
300
|
const startedAt = Date.now();
|
|
301
301
|
const timeout = AbortSignal.timeout(timeoutMs);
|
|
302
|
-
// Scoped, not AbortSignal.any:
|
|
303
|
-
//
|
|
304
|
-
//
|
|
305
|
-
//
|
|
306
|
-
// the call never settled. Plain listeners keep the link strong.
|
|
302
|
+
// Scoped, not AbortSignal.any: plain listeners, removed in `finally`,
|
|
303
|
+
// so a long-lived caller signal does not collect one registration per
|
|
304
|
+
// attempt. (The stalled-body hang once blamed on `any` was fetch losing
|
|
305
|
+
// the abort; see readJsonWithSignal below.)
|
|
307
306
|
const { signal: composed, dispose: disposeSignal } = composeAbortSignalsScoped(request.signal, timeout);
|
|
308
307
|
const signal = composed ?? timeout;
|
|
309
308
|
try {
|
|
@@ -320,9 +319,9 @@ export class SystemOneDecisionProvider extends BaseProvider {
|
|
|
320
319
|
const requestId = this.readRequestId(response.headers);
|
|
321
320
|
const upstreamMs = Number(response.headers.get("x-envoy-upstream-service-time")) ||
|
|
322
321
|
undefined;
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
322
|
+
// Not response.json(): on Node 22 a GC during a stalled body read can
|
|
323
|
+
// lose fetch's abort, and the call would never settle.
|
|
324
|
+
const payload = await readJsonWithSignal(response, signal).catch((error) => {
|
|
326
325
|
// A deadline or abort that cuts the body read short is a timeout,
|
|
327
326
|
// not a response without answers; the catch below classifies it.
|
|
328
327
|
if (signal.aborted) {
|
package/dist/utils/timeout.d.ts
CHANGED
|
@@ -168,6 +168,19 @@ export declare function composeAbortSignalsScoped(externalSignal?: AbortSignal,
|
|
|
168
168
|
signal: AbortSignal | undefined;
|
|
169
169
|
dispose: () => void;
|
|
170
170
|
};
|
|
171
|
+
/**
|
|
172
|
+
* `response.json()` that settles when `signal` aborts, even if `fetch` lost
|
|
173
|
+
* the abort.
|
|
174
|
+
*
|
|
175
|
+
* Node 22's built-in fetch (undici 6) can drop the abort for a body that is
|
|
176
|
+
* still streaming when the request used `redirect: "error"` and the garbage
|
|
177
|
+
* collector runs during the read: the signal fires, the read never ends.
|
|
178
|
+
* Measured on Node 22.23.4 under forced GC, 8 hangs in 8; Node 26 is not
|
|
179
|
+
* affected. Listening on the signal here and cancelling the body does not
|
|
180
|
+
* depend on fetch's own link, so the read rejects with the signal's reason,
|
|
181
|
+
* which is what fetch rejects with when the link holds.
|
|
182
|
+
*/
|
|
183
|
+
export declare function readJsonWithSignal(response: Response, signal: AbortSignal): Promise<unknown>;
|
|
171
184
|
/**
|
|
172
185
|
* Merge abort signals (for combining user abort with timeout)
|
|
173
186
|
*
|
package/dist/utils/timeout.js
CHANGED
|
@@ -460,6 +460,35 @@ export function composeAbortSignalsScoped(externalSignal, timeoutSignal) {
|
|
|
460
460
|
}
|
|
461
461
|
return { signal: controller.signal, dispose };
|
|
462
462
|
}
|
|
463
|
+
/**
|
|
464
|
+
* `response.json()` that settles when `signal` aborts, even if `fetch` lost
|
|
465
|
+
* the abort.
|
|
466
|
+
*
|
|
467
|
+
* Node 22's built-in fetch (undici 6) can drop the abort for a body that is
|
|
468
|
+
* still streaming when the request used `redirect: "error"` and the garbage
|
|
469
|
+
* collector runs during the read: the signal fires, the read never ends.
|
|
470
|
+
* Measured on Node 22.23.4 under forced GC, 8 hangs in 8; Node 26 is not
|
|
471
|
+
* affected. Listening on the signal here and cancelling the body does not
|
|
472
|
+
* depend on fetch's own link, so the read rejects with the signal's reason,
|
|
473
|
+
* which is what fetch rejects with when the link holds.
|
|
474
|
+
*/
|
|
475
|
+
export function readJsonWithSignal(response, signal) {
|
|
476
|
+
return new Promise((resolve, reject) => {
|
|
477
|
+
const onAbort = () => {
|
|
478
|
+
response.body?.cancel(signal.reason).catch(() => undefined);
|
|
479
|
+
reject(signal.reason);
|
|
480
|
+
};
|
|
481
|
+
if (signal.aborted) {
|
|
482
|
+
onAbort();
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
486
|
+
response
|
|
487
|
+
.json()
|
|
488
|
+
.then(resolve, reject)
|
|
489
|
+
.finally(() => signal.removeEventListener("abort", onAbort));
|
|
490
|
+
});
|
|
491
|
+
}
|
|
463
492
|
/**
|
|
464
493
|
* Merge abort signals (for combining user abort with timeout)
|
|
465
494
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juspay/neurolink",
|
|
3
|
-
"version": "13.15.
|
|
3
|
+
"version": "13.15.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": {
|