@juspay/neurolink 11.2.4 → 11.3.0

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 (55) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/dist/browser/neurolink.min.js +391 -391
  3. package/dist/core/loopEngine.d.ts +23 -0
  4. package/dist/core/loopEngine.js +245 -0
  5. package/dist/core/nativeToolFormat.d.ts +33 -0
  6. package/dist/core/nativeToolFormat.js +30 -0
  7. package/dist/core/streamChannel.d.ts +10 -0
  8. package/dist/core/streamChannel.js +76 -0
  9. package/dist/lib/core/loopEngine.d.ts +23 -0
  10. package/dist/lib/core/loopEngine.js +246 -0
  11. package/dist/lib/core/nativeToolFormat.d.ts +33 -0
  12. package/dist/lib/core/nativeToolFormat.js +31 -0
  13. package/dist/lib/core/streamChannel.d.ts +10 -0
  14. package/dist/lib/core/streamChannel.js +77 -0
  15. package/dist/lib/providers/anthropic/cacheControl.d.ts +12 -0
  16. package/dist/lib/providers/anthropic/cacheControl.js +15 -0
  17. package/dist/lib/providers/anthropic/client.js +12 -45
  18. package/dist/lib/providers/googleAiStudio/client.js +7 -5
  19. package/dist/lib/providers/googleNativeGemini3/utils.d.ts +4 -11
  20. package/dist/lib/providers/googleNativeGemini3/utils.js +1 -75
  21. package/dist/lib/providers/googleVertex/client.js +28 -30
  22. package/dist/lib/providers/openaiChatCompletionsBase.js +10 -12
  23. package/dist/lib/providers/openaiChatCompletionsClient.d.ts +1 -5
  24. package/dist/lib/providers/openaiChatCompletionsClient.js +0 -26
  25. package/dist/lib/types/index.d.ts +3 -0
  26. package/dist/lib/types/index.js +3 -0
  27. package/dist/lib/types/loopEngine.d.ts +78 -0
  28. package/dist/lib/types/loopEngine.js +2 -0
  29. package/dist/lib/types/nativeTools.d.ts +16 -0
  30. package/dist/lib/types/nativeTools.js +2 -0
  31. package/dist/lib/types/openaiCompatible.d.ts +2 -2
  32. package/dist/lib/types/providers.d.ts +0 -13
  33. package/dist/lib/types/streaming.d.ts +15 -0
  34. package/dist/lib/types/streaming.js +2 -0
  35. package/dist/providers/anthropic/cacheControl.d.ts +12 -0
  36. package/dist/providers/anthropic/cacheControl.js +14 -0
  37. package/dist/providers/anthropic/client.js +12 -45
  38. package/dist/providers/googleAiStudio/client.js +7 -5
  39. package/dist/providers/googleNativeGemini3/utils.d.ts +4 -11
  40. package/dist/providers/googleNativeGemini3/utils.js +1 -75
  41. package/dist/providers/googleVertex/client.js +28 -30
  42. package/dist/providers/openaiChatCompletionsBase.js +10 -12
  43. package/dist/providers/openaiChatCompletionsClient.d.ts +1 -5
  44. package/dist/providers/openaiChatCompletionsClient.js +0 -26
  45. package/dist/types/index.d.ts +3 -0
  46. package/dist/types/index.js +3 -0
  47. package/dist/types/loopEngine.d.ts +78 -0
  48. package/dist/types/loopEngine.js +1 -0
  49. package/dist/types/nativeTools.d.ts +16 -0
  50. package/dist/types/nativeTools.js +1 -0
  51. package/dist/types/openaiCompatible.d.ts +2 -2
  52. package/dist/types/providers.d.ts +0 -13
  53. package/dist/types/streaming.d.ts +15 -0
  54. package/dist/types/streaming.js +1 -0
  55. package/package.json +3 -1
@@ -0,0 +1,78 @@
1
+ export type AgenticLoopToolCall = {
2
+ id: string;
3
+ name: string;
4
+ args: Record<string, unknown>;
5
+ };
6
+ export type AgenticLoopUsage = {
7
+ inputTokens: number;
8
+ outputTokens: number;
9
+ cacheReadTokens?: number;
10
+ cacheWriteTokens?: number;
11
+ reasoningTokens?: number;
12
+ };
13
+ export type AgenticLoopStepResult<TRaw = unknown> = {
14
+ text: string;
15
+ reasoning?: string;
16
+ toolCalls: AgenticLoopToolCall[];
17
+ usage: AgenticLoopUsage;
18
+ /** Provider's own raw stop/finish-reason string, e.g. "tool_use", "MAX_TOKENS" */
19
+ rawStopReason: string | undefined;
20
+ /** Adapter-private accumulated response data needed by buildToolResultMessages
21
+ * (e.g. Anthropic's ordered content blocks, Gemini's rawResponseParts). */
22
+ raw: TRaw;
23
+ };
24
+ export type AgenticLoopToolCallResult = AgenticLoopToolCall & {
25
+ output: unknown;
26
+ error?: string;
27
+ permanentlyFailed?: boolean;
28
+ };
29
+ export type AgenticLoopStepRequest = {
30
+ raw: unknown;
31
+ };
32
+ export type AgenticLoopReclaimResult<TConversation> = {
33
+ conversation: TConversation;
34
+ };
35
+ export type AgenticLoopToolFailureBreaker = {
36
+ maxRetries: number;
37
+ };
38
+ export type AgenticLoopAdapter<TConversation = unknown, TRaw = unknown> = {
39
+ readonly providerLabel: string;
40
+ readonly maxSteps: number;
41
+ /** Pre-existing per-family flat timeout, used as createTurnClock's deadline default. */
42
+ readonly defaultTurnTimeoutMs?: number;
43
+ readonly stallTimeoutMs?: number;
44
+ /** Set only for adapter instances whose client has the TOOL_NOT_FOUND strike breaker today: both Gemini adapters (AI Studio, Vertex+Gemini) AND the Vertex+Claude call to createAnthropicLoopAdapter — NOT the native-Anthropic call to that same factory, and not Bedrock. See Verified Fact 4. */
45
+ readonly toolFailureBreaker?: AgenticLoopToolFailureBreaker;
46
+ buildStepRequest(conversation: TConversation, step: number): AgenticLoopStepRequest;
47
+ executeStep(request: AgenticLoopStepRequest, channel: {
48
+ push(chunk: {
49
+ content: string;
50
+ }): void;
51
+ }, signal: AbortSignal): Promise<AgenticLoopStepResult<TRaw>>;
52
+ buildToolResultMessages(conversation: TConversation, stepResult: AgenticLoopStepResult<TRaw>, toolResults: AgenticLoopToolCallResult[]): TConversation;
53
+ mapFinishReason(rawStopReason: string | undefined, hadToolCalls: boolean): string;
54
+ /** Optional: in-turn context-budget reclaim, called once per step before buildStepRequest. */
55
+ planReclaim?(conversation: TConversation, step: number): AgenticLoopReclaimResult<TConversation> | undefined;
56
+ /** Optional: Vertex+Gemini-only single-retry-on-malformed-call. */
57
+ isMalformedStep?(stepResult: AgenticLoopStepResult<TRaw>): boolean;
58
+ buildMalformedRetryNote?(conversation: TConversation): TConversation;
59
+ };
60
+ export type AgenticLoopOptions = {
61
+ tools?: Record<string, {
62
+ execute?: (args: Record<string, unknown>, opts: unknown) => Promise<unknown>;
63
+ }>;
64
+ abortSignal?: AbortSignal;
65
+ };
66
+ export type AgenticLoopResult<TConversation> = {
67
+ text: string;
68
+ toolCalls: AgenticLoopToolCall[];
69
+ toolExecutions: Array<{
70
+ name: string;
71
+ input: Record<string, unknown>;
72
+ output: unknown;
73
+ }>;
74
+ usage: AgenticLoopUsage;
75
+ finishReason: string;
76
+ rawStopReason: string | undefined;
77
+ conversation: TConversation;
78
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Wire formats accepted by `toNativeToolDeclarations` (src/lib/core/nativeToolFormat.ts).
3
+ * `"input_schema"` is Anthropic's native Messages-API tool shape;
4
+ * `"functionDeclarations"` is the @google/genai SDK shape shared by the
5
+ * Gemini-family native providers (Google AI Studio, Vertex+Gemini).
6
+ */
7
+ export type NativeToolFormat = "input_schema" | "functionDeclarations";
8
+ /** A single tool declaration in Anthropic's native `input_schema` wire format. */
9
+ export type NativeAnthropicToolDeclaration = {
10
+ name: string;
11
+ description?: string;
12
+ input_schema: Record<string, unknown>;
13
+ cache_control?: {
14
+ type: "ephemeral";
15
+ };
16
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -203,8 +203,6 @@ export type OpenAICompatSSEResult = {
203
203
  export type OpenAICompatStreamChunk = {
204
204
  content: string;
205
205
  reasoning?: string;
206
- } | {
207
- done: true;
208
206
  };
209
207
  export type ToolExecutionSummaryInternal = {
210
208
  toolCallId: string;
@@ -232,6 +230,8 @@ export type StreamLoopArgs = {
232
230
  toolsUsed: string[];
233
231
  toolExecutionSummaries: ToolExecutionSummaryInternal[];
234
232
  pushChunk: (chunk: OpenAICompatStreamChunk) => void;
233
+ /** Signals the channel that no further chunks will arrive (success or error path alike). */
234
+ closeChannel: () => void;
235
235
  resolveUsage: (u: {
236
236
  promptTokens: number;
237
237
  completionTokens: number;
@@ -1740,19 +1740,6 @@ export type CollectedChunkResult = {
1740
1740
  */
1741
1741
  reasoningTokens?: number;
1742
1742
  };
1743
- /** Push-based text channel for incremental streaming. */
1744
- export type TextChannel = {
1745
- /** Push a text chunk to the consumer. */
1746
- push: (text: string) => void;
1747
- /** Signal that no more chunks will arrive. */
1748
- close: () => void;
1749
- /** Signal that the producer encountered a fatal error. */
1750
- error: (err: unknown) => void;
1751
- /** Async iterable consumed by the StreamResult. */
1752
- iterable: AsyncIterable<{
1753
- content: string;
1754
- }>;
1755
- };
1756
1743
  /** Language model object shape (LanguageModelV2/V3). */
1757
1744
  export type LanguageModelObject = {
1758
1745
  readonly modelId: string;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Shared push-based channel bridging a background producer (an agentic
3
+ * tool-calling loop) with an async-iterable consumer. Replaces the two
4
+ * independently-invented primitives this type unifies: the OpenAI-family
5
+ * `createChunkQueue` (pull-based, in-band `{done:true}` sentinel) and the
6
+ * Gemini-family `createTextChannel` (push-based, out-of-band close/error).
7
+ */
8
+ export type StreamChannel<T = {
9
+ content: string;
10
+ }> = {
11
+ push(value: T): void;
12
+ close(): void;
13
+ error(err: unknown): void;
14
+ readonly iterable: AsyncIterable<T>;
15
+ };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/neurolink",
3
- "version": "11.2.4",
3
+ "version": "11.3.0",
4
4
  "packageManager": "pnpm@10.15.1",
5
5
  "description": "TypeScript AI SDK with 24+ LLM providers behind one consistent API. MCP-native (connect any MCP server), voice TTS/STT/realtime, RAG, agents, memory, context compaction. OpenAI · Anthropic · Gemini · Bedrock · Azure · Ollama · DeepSeek · NVIDIA NIM and more.",
6
6
  "author": {
@@ -86,6 +86,7 @@
86
86
  "test:adjust-body-after-400": "npx tsx test/continuous-test-suite-adjust-body-after-400.ts",
87
87
  "test:error-classification-e2e": "npx tsx test/continuous-test-suite-error-classification-e2e.ts",
88
88
  "test:error-classifier-contract": "npx tsx test/continuous-test-suite-error-classifier-contract.ts",
89
+ "test:loop-engine": "npx tsx test/continuous-test-suite-loop-engine.ts",
89
90
  "test:middleware": "npx tsx test/continuous-test-suite-middleware.ts",
90
91
  "test:observability": "npx tsx test/continuous-test-suite-observability.ts",
91
92
  "test:ppt": "npx tsx test/continuous-test-suite-ppt.ts",
@@ -110,6 +111,7 @@
110
111
  "test:tts:unit": "npx tsx test/continuous-test-suite-tts-unit.ts",
111
112
  "test:stt:unit": "npx tsx test/continuous-test-suite-stt-unit.ts",
112
113
  "test:realtime:unit": "npx tsx test/continuous-test-suite-realtime-unit.ts",
114
+ "test:video:unit": "npx tsx test/continuous-test-suite-video-generation-unit.ts",
113
115
  "test:voice": "npx tsx test/continuous-test-suite-voice.ts",
114
116
  "test:avatar": "npx tsx test/continuous-test-suite-avatar.ts",
115
117
  "test:avatar:unit": "npx tsx test/continuous-test-suite-avatar-unit.ts",