@juspay/neurolink 9.81.2 → 9.81.3

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/browser/neurolink.min.js +356 -356
  3. package/dist/constants/contextWindows.js +10 -0
  4. package/dist/core/constants.d.ts +16 -0
  5. package/dist/core/constants.js +16 -0
  6. package/dist/core/modules/ToolsManager.d.ts +5 -0
  7. package/dist/core/modules/ToolsManager.js +62 -6
  8. package/dist/lib/constants/contextWindows.js +10 -0
  9. package/dist/lib/core/constants.d.ts +16 -0
  10. package/dist/lib/core/constants.js +16 -0
  11. package/dist/lib/core/modules/ToolsManager.d.ts +5 -0
  12. package/dist/lib/core/modules/ToolsManager.js +62 -6
  13. package/dist/lib/neurolink.js +21 -3
  14. package/dist/lib/providers/googleNativeGemini3.d.ts +43 -0
  15. package/dist/lib/providers/googleNativeGemini3.js +73 -1
  16. package/dist/lib/providers/googleVertex.js +495 -80
  17. package/dist/lib/types/generate.d.ts +5 -1
  18. package/dist/lib/utils/async/index.d.ts +1 -1
  19. package/dist/lib/utils/async/index.js +1 -1
  20. package/dist/lib/utils/async/withTimeout.d.ts +12 -0
  21. package/dist/lib/utils/async/withTimeout.js +45 -0
  22. package/dist/lib/utils/mcpErrorText.d.ts +11 -0
  23. package/dist/lib/utils/mcpErrorText.js +23 -0
  24. package/dist/neurolink.js +21 -3
  25. package/dist/providers/googleNativeGemini3.d.ts +43 -0
  26. package/dist/providers/googleNativeGemini3.js +73 -1
  27. package/dist/providers/googleVertex.js +495 -80
  28. package/dist/types/generate.d.ts +5 -1
  29. package/dist/utils/async/index.d.ts +1 -1
  30. package/dist/utils/async/index.js +1 -1
  31. package/dist/utils/async/withTimeout.d.ts +12 -0
  32. package/dist/utils/async/withTimeout.js +45 -0
  33. package/dist/utils/mcpErrorText.d.ts +11 -0
  34. package/dist/utils/mcpErrorText.js +23 -0
  35. package/docs/assets/dashboards/neurolink-proxy-observability-dashboard.json +1258 -0
  36. package/package.json +1 -1
@@ -602,13 +602,17 @@ export type AdditionalMemoryUser = {
602
602
  *
603
603
  * - `completed` — the model finished on its own (text answer or final_result)
604
604
  * - `step-cap` — the `maxSteps` budget ran out while the model still wanted tools
605
+ * - `context-cap` — the in-loop context guard stopped the tool loop because the
606
+ * accumulated conversation approached the model's context window (and the
607
+ * terminal synthesis could not produce an answer); without the guard these
608
+ * turns died mid-loop on a provider 400 "prompt is too long"
605
609
  * - `time-limit` — the `turnTimeoutMs` wall-clock deadline passed
606
610
  * - `stalled` — no progress (no chunk, no tool start/finish) for `stallTimeoutMs`
607
611
  * - `aborted` — the caller's `abortSignal` ended the turn
608
612
  * - `provider-error` — the provider/model failed the turn (e.g. persistent
609
613
  * MALFORMED_FUNCTION_CALL after retry); usually worth a caller-side retry
610
614
  */
611
- export type GenerateStopReason = "completed" | "step-cap" | "time-limit" | "stalled" | "aborted" | "provider-error";
615
+ export type GenerateStopReason = "completed" | "step-cap" | "context-cap" | "time-limit" | "stalled" | "aborted" | "provider-error";
612
616
  /**
613
617
  * Generate function result type - Primary output format
614
618
  * Future-ready for multi-modal outputs while maintaining text focus
@@ -20,4 +20,4 @@
20
20
  */
21
21
  export { delay, sleep } from "./delay.js";
22
22
  export { calculateBackoff, createRetry, DEFAULT_RETRY_OPTIONS, RetryExhaustedError, retry, } from "./retry.js";
23
- export { TimeoutError, withTimeout, withTimeoutFn } from "./withTimeout.js";
23
+ export { TimeoutError, raceWithAbort, withTimeout, withTimeoutFn, } from "./withTimeout.js";
@@ -20,4 +20,4 @@
20
20
  */
21
21
  export { delay, sleep } from "./delay.js";
22
22
  export { calculateBackoff, createRetry, DEFAULT_RETRY_OPTIONS, RetryExhaustedError, retry, } from "./retry.js";
23
- export { TimeoutError, withTimeout, withTimeoutFn } from "./withTimeout.js";
23
+ export { TimeoutError, raceWithAbort, withTimeout, withTimeoutFn, } from "./withTimeout.js";
@@ -49,6 +49,18 @@ export declare class TimeoutError extends Error {
49
49
  * ```
50
50
  */
51
51
  export declare function withTimeout<T>(promise: Promise<T>, ms: number, message?: string): Promise<T>;
52
+ /**
53
+ * Race a promise against an AbortSignal so the caller observes an abort
54
+ * IMMEDIATELY instead of waiting for the operation to settle (or for a
55
+ * separate timeout to expire). Rejects with an abort-shaped error
56
+ * (`name === "AbortError"`) so provider loops route it to their existing
57
+ * cancellation handling.
58
+ *
59
+ * The underlying operation is NOT cancelled — it continues as a bounded
60
+ * ghost (the same tradeoff as {@link withTimeout}); its eventual settlement
61
+ * is swallowed so it can never surface as an unhandled rejection.
62
+ */
63
+ export declare function raceWithAbort<T>(promise: Promise<T>, signal: AbortSignal | undefined): Promise<T>;
52
64
  /**
53
65
  * Execute a function with timeout protection.
54
66
  *
@@ -72,6 +72,51 @@ export async function withTimeout(promise, ms, message) {
72
72
  }
73
73
  }
74
74
  }
75
+ /**
76
+ * Race a promise against an AbortSignal so the caller observes an abort
77
+ * IMMEDIATELY instead of waiting for the operation to settle (or for a
78
+ * separate timeout to expire). Rejects with an abort-shaped error
79
+ * (`name === "AbortError"`) so provider loops route it to their existing
80
+ * cancellation handling.
81
+ *
82
+ * The underlying operation is NOT cancelled — it continues as a bounded
83
+ * ghost (the same tradeoff as {@link withTimeout}); its eventual settlement
84
+ * is swallowed so it can never surface as an unhandled rejection.
85
+ */
86
+ export async function raceWithAbort(promise, signal) {
87
+ if (!signal || typeof signal.addEventListener !== "function") {
88
+ return promise;
89
+ }
90
+ const makeAbortError = () => {
91
+ const e = new Error("Operation aborted");
92
+ e.name = "AbortError";
93
+ return e;
94
+ };
95
+ if (signal.aborted) {
96
+ promise.catch(() => {
97
+ // Swallow the abandoned settlement — it must never surface as an
98
+ // unhandled rejection after the race has already been decided.
99
+ });
100
+ return Promise.reject(makeAbortError());
101
+ }
102
+ return new Promise((resolve, reject) => {
103
+ const onAbort = () => {
104
+ promise.catch(() => {
105
+ // Swallow the abandoned settlement — it must never surface as an
106
+ // unhandled rejection after the race has already been decided.
107
+ });
108
+ reject(makeAbortError());
109
+ };
110
+ signal.addEventListener("abort", onAbort, { once: true });
111
+ promise.then((value) => {
112
+ signal.removeEventListener("abort", onAbort);
113
+ resolve(value);
114
+ }, (error) => {
115
+ signal.removeEventListener("abort", onAbort);
116
+ reject(error);
117
+ });
118
+ });
119
+ }
75
120
  /**
76
121
  * Execute a function with timeout protection.
77
122
  *
@@ -24,3 +24,14 @@ export declare function extractMcpErrorText(raw: unknown): string;
24
24
  * but no readable text is present, falls back to a generic message.
25
25
  */
26
26
  export declare function extractMcpToolErrorMessage(result: unknown): string | undefined;
27
+ /**
28
+ * Detect a tool result that REPORTS failure without throwing, for the native
29
+ * loops' consecutive-failure breaker. Covers the two shapes NeuroLink itself
30
+ * produces or forwards:
31
+ * - MCP CallToolResult with `isError: true` (e.g. proxy-blocked tools) —
32
+ * delegated to {@link extractMcpToolErrorMessage}
33
+ * - our own `{ error: "..." }` payloads
34
+ * Plain strings are never classified (too false-positive-prone).
35
+ * Returns the error text, or null when the result looks like a success.
36
+ */
37
+ export declare function extractToolFailureText(result: unknown): string | null;
@@ -69,3 +69,26 @@ export function extractMcpToolErrorMessage(result) {
69
69
  ? `MCP tool returned isError: ${text}`
70
70
  : "MCP tool returned isError: true";
71
71
  }
72
+ /**
73
+ * Detect a tool result that REPORTS failure without throwing, for the native
74
+ * loops' consecutive-failure breaker. Covers the two shapes NeuroLink itself
75
+ * produces or forwards:
76
+ * - MCP CallToolResult with `isError: true` (e.g. proxy-blocked tools) —
77
+ * delegated to {@link extractMcpToolErrorMessage}
78
+ * - our own `{ error: "..." }` payloads
79
+ * Plain strings are never classified (too false-positive-prone).
80
+ * Returns the error text, or null when the result looks like a success.
81
+ */
82
+ export function extractToolFailureText(result) {
83
+ const mcpError = extractMcpToolErrorMessage(result);
84
+ if (mcpError) {
85
+ return mcpError;
86
+ }
87
+ if (result !== null &&
88
+ typeof result === "object" &&
89
+ typeof result.error === "string" &&
90
+ result.error.length > 0) {
91
+ return result.error;
92
+ }
93
+ return null;
94
+ }