@juspay/neurolink 10.5.3 → 10.6.1

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 (96) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/agent/agent.js +39 -8
  3. package/dist/agent/agentNetwork.js +62 -20
  4. package/dist/agent/agentToolRegistrar.d.ts +48 -0
  5. package/dist/agent/agentToolRegistrar.js +336 -0
  6. package/dist/agent/index.d.ts +3 -0
  7. package/dist/agent/index.js +4 -0
  8. package/dist/agent/isolatedAgentRunner.d.ts +73 -0
  9. package/dist/agent/isolatedAgentRunner.js +946 -0
  10. package/dist/agent/structuredRecovery.d.ts +30 -0
  11. package/dist/agent/structuredRecovery.js +104 -0
  12. package/dist/browser/neurolink.min.js +414 -398
  13. package/dist/cli/loop/optionsSchema.d.ts +1 -1
  14. package/dist/core/baseProvider.d.ts +8 -0
  15. package/dist/core/baseProvider.js +40 -19
  16. package/dist/core/modules/GenerationHandler.d.ts +2 -6
  17. package/dist/core/modules/GenerationHandler.js +10 -1
  18. package/dist/core/toolExecutionRecorder.d.ts +76 -0
  19. package/dist/core/toolExecutionRecorder.js +261 -0
  20. package/dist/evaluation/contextBuilder.js +6 -6
  21. package/dist/lib/agent/agent.js +39 -8
  22. package/dist/lib/agent/agentNetwork.js +62 -20
  23. package/dist/lib/agent/agentToolRegistrar.d.ts +48 -0
  24. package/dist/lib/agent/agentToolRegistrar.js +337 -0
  25. package/dist/lib/agent/index.d.ts +3 -0
  26. package/dist/lib/agent/index.js +4 -0
  27. package/dist/lib/agent/isolatedAgentRunner.d.ts +73 -0
  28. package/dist/lib/agent/isolatedAgentRunner.js +947 -0
  29. package/dist/lib/agent/structuredRecovery.d.ts +30 -0
  30. package/dist/lib/agent/structuredRecovery.js +105 -0
  31. package/dist/lib/core/baseProvider.d.ts +8 -0
  32. package/dist/lib/core/baseProvider.js +40 -19
  33. package/dist/lib/core/modules/GenerationHandler.d.ts +2 -6
  34. package/dist/lib/core/modules/GenerationHandler.js +10 -1
  35. package/dist/lib/core/toolExecutionRecorder.d.ts +76 -0
  36. package/dist/lib/core/toolExecutionRecorder.js +262 -0
  37. package/dist/lib/evaluation/contextBuilder.js +6 -6
  38. package/dist/lib/models/modelRegistry.d.ts +23 -0
  39. package/dist/lib/models/modelRegistry.js +62 -1
  40. package/dist/lib/models/modelResolver.js +1 -0
  41. package/dist/lib/neurolink.d.ts +80 -1
  42. package/dist/lib/neurolink.js +199 -37
  43. package/dist/lib/processors/media/index.js +0 -10
  44. package/dist/lib/providers/amazonBedrock.js +15 -2
  45. package/dist/lib/providers/anthropic.js +23 -11
  46. package/dist/lib/providers/googleAiStudio.js +8 -1
  47. package/dist/lib/providers/googleNativeGemini3.d.ts +2 -0
  48. package/dist/lib/providers/googleNativeGemini3.js +8 -1
  49. package/dist/lib/providers/googleVertex.js +56 -16
  50. package/dist/lib/providers/openaiChatCompletionsClient.js +18 -5
  51. package/dist/lib/tasks/autoresearchTaskExecutor.js +7 -6
  52. package/dist/lib/tasks/taskExecutor.js +2 -5
  53. package/dist/lib/types/agentNetwork.d.ts +23 -8
  54. package/dist/lib/types/generate.d.ts +62 -5
  55. package/dist/lib/types/index.d.ts +1 -0
  56. package/dist/lib/types/index.js +1 -0
  57. package/dist/lib/types/isolatedAgent.d.ts +365 -0
  58. package/dist/lib/types/isolatedAgent.js +12 -0
  59. package/dist/lib/types/model.d.ts +8 -0
  60. package/dist/lib/types/stream.d.ts +3 -1
  61. package/dist/lib/types/task.d.ts +3 -3
  62. package/dist/lib/utils/logger.d.ts +12 -3
  63. package/dist/lib/utils/logger.js +11 -3
  64. package/dist/lib/utils/transformationUtils.d.ts +14 -0
  65. package/dist/lib/utils/transformationUtils.js +33 -10
  66. package/dist/lib/voice/livekit/realtimeVoiceAgent.js +6 -3
  67. package/dist/models/modelRegistry.d.ts +23 -0
  68. package/dist/models/modelRegistry.js +62 -1
  69. package/dist/models/modelResolver.js +1 -0
  70. package/dist/neurolink.d.ts +80 -1
  71. package/dist/neurolink.js +199 -37
  72. package/dist/processors/media/index.js +0 -10
  73. package/dist/providers/amazonBedrock.js +15 -2
  74. package/dist/providers/anthropic.js +23 -11
  75. package/dist/providers/googleAiStudio.js +8 -1
  76. package/dist/providers/googleNativeGemini3.d.ts +2 -0
  77. package/dist/providers/googleNativeGemini3.js +8 -1
  78. package/dist/providers/googleVertex.js +56 -16
  79. package/dist/providers/openaiChatCompletionsClient.js +18 -5
  80. package/dist/tasks/autoresearchTaskExecutor.js +7 -6
  81. package/dist/tasks/taskExecutor.js +2 -5
  82. package/dist/types/agentNetwork.d.ts +23 -8
  83. package/dist/types/generate.d.ts +62 -5
  84. package/dist/types/index.d.ts +1 -0
  85. package/dist/types/index.js +1 -0
  86. package/dist/types/isolatedAgent.d.ts +365 -0
  87. package/dist/types/isolatedAgent.js +11 -0
  88. package/dist/types/model.d.ts +8 -0
  89. package/dist/types/stream.d.ts +3 -1
  90. package/dist/types/task.d.ts +3 -3
  91. package/dist/utils/logger.d.ts +12 -3
  92. package/dist/utils/logger.js +11 -3
  93. package/dist/utils/transformationUtils.d.ts +14 -0
  94. package/dist/utils/transformationUtils.js +33 -10
  95. package/dist/voice/livekit/realtimeVoiceAgent.js +6 -3
  96. package/package.json +3 -2
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Structured-output recovery ladder for the isolated-agent runner.
3
+ *
4
+ * Ports the production-hardened pattern the framework's consumers built by
5
+ * hand: candidates are tried in a fixed order — provider `structuredData` →
6
+ * raw JSON object → ```json fence → first/last-brace span → top-level array —
7
+ * each passed through the caller's `coerce` normalizer and validated against
8
+ * the (lenient) local schema. The first schema-valid candidate wins;
9
+ * validation errors are collected for corrective re-asks.
10
+ */
11
+ import type { z } from "zod";
12
+ import type { StructuredRecoveryCandidate, StructuredRecoveryResult } from "../types/index.js";
13
+ /**
14
+ * Collect parse candidates from model text (and provider structuredData) in
15
+ * ladder order. Never throws.
16
+ */
17
+ export declare function collectStructuredCandidates(content: string | undefined, structuredData?: unknown): StructuredRecoveryCandidate[];
18
+ /**
19
+ * Run the full ladder: candidates (through `coerce`) validated against
20
+ * `schema`; first success wins. Never throws — coerce/validation failures
21
+ * become entries in `errors`.
22
+ */
23
+ export declare function recoverStructuredData(args: {
24
+ content: string | undefined;
25
+ structuredData?: unknown;
26
+ schema: z.ZodSchema;
27
+ coerce?: (candidate: unknown) => unknown;
28
+ }): StructuredRecoveryResult;
29
+ /** Bounded, prompt-friendly summary of a Zod validation error. */
30
+ export declare function summarizeZodError(error: z.ZodError): string;
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Structured-output recovery ladder for the isolated-agent runner.
3
+ *
4
+ * Ports the production-hardened pattern the framework's consumers built by
5
+ * hand: candidates are tried in a fixed order — provider `structuredData` →
6
+ * raw JSON object → ```json fence → first/last-brace span → top-level array —
7
+ * each passed through the caller's `coerce` normalizer and validated against
8
+ * the (lenient) local schema. The first schema-valid candidate wins;
9
+ * validation errors are collected for corrective re-asks.
10
+ */
11
+ function tryParse(text) {
12
+ try {
13
+ return JSON.parse(text);
14
+ }
15
+ catch {
16
+ return undefined;
17
+ }
18
+ }
19
+ /**
20
+ * Collect parse candidates from model text (and provider structuredData) in
21
+ * ladder order. Never throws.
22
+ */
23
+ export function collectStructuredCandidates(content, structuredData) {
24
+ const candidates = [];
25
+ if (structuredData !== undefined && structuredData !== null) {
26
+ candidates.push({ source: "structured-data", value: structuredData });
27
+ }
28
+ const text = (content ?? "").trim();
29
+ if (!text) {
30
+ return candidates;
31
+ }
32
+ // Raw JSON object/array/scalar
33
+ const raw = tryParse(text);
34
+ if (raw !== undefined) {
35
+ candidates.push({ source: "raw-json", value: raw });
36
+ }
37
+ // ```json fenced block (first fence wins)
38
+ const fenceMatch = text.match(/```(?:json)?\s*\n?([\s\S]*?)\n?```/i);
39
+ if (fenceMatch?.[1]) {
40
+ const fenced = tryParse(fenceMatch[1].trim());
41
+ if (fenced !== undefined) {
42
+ candidates.push({ source: "json-fence", value: fenced });
43
+ }
44
+ }
45
+ // First-brace .. last-brace span
46
+ const firstBrace = text.indexOf("{");
47
+ const lastBrace = text.lastIndexOf("}");
48
+ if (firstBrace !== -1 && lastBrace > firstBrace) {
49
+ const span = tryParse(text.slice(firstBrace, lastBrace + 1));
50
+ if (span !== undefined) {
51
+ candidates.push({ source: "brace-span", value: span });
52
+ }
53
+ }
54
+ // Top-level array span
55
+ const firstBracket = text.indexOf("[");
56
+ const lastBracket = text.lastIndexOf("]");
57
+ if (firstBracket !== -1 && lastBracket > firstBracket) {
58
+ const arraySpan = tryParse(text.slice(firstBracket, lastBracket + 1));
59
+ if (arraySpan !== undefined && Array.isArray(arraySpan)) {
60
+ candidates.push({ source: "top-level-array", value: arraySpan });
61
+ }
62
+ }
63
+ return candidates;
64
+ }
65
+ /**
66
+ * Run the full ladder: candidates (through `coerce`) validated against
67
+ * `schema`; first success wins. Never throws — coerce/validation failures
68
+ * become entries in `errors`.
69
+ */
70
+ export function recoverStructuredData(args) {
71
+ const errors = [];
72
+ const candidates = collectStructuredCandidates(args.content, args.structuredData);
73
+ for (const candidate of candidates) {
74
+ let value = candidate.value;
75
+ if (args.coerce) {
76
+ try {
77
+ value = args.coerce(value);
78
+ }
79
+ catch (coerceError) {
80
+ errors.push(`${candidate.source}: coerce failed — ${coerceError instanceof Error
81
+ ? coerceError.message
82
+ : String(coerceError)}`);
83
+ continue;
84
+ }
85
+ }
86
+ const parsed = args.schema.safeParse(value);
87
+ if (parsed.success) {
88
+ return { data: parsed.data, source: candidate.source, errors };
89
+ }
90
+ errors.push(`${candidate.source}: ${summarizeZodError(parsed.error)}`);
91
+ }
92
+ if (candidates.length === 0) {
93
+ errors.push("no JSON-shaped candidates found in output");
94
+ }
95
+ return { errors };
96
+ }
97
+ /** Bounded, prompt-friendly summary of a Zod validation error. */
98
+ export function summarizeZodError(error) {
99
+ const issues = error.issues
100
+ .slice(0, 5)
101
+ .map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`);
102
+ const extra = error.issues.length > 5 ? ` (+${error.issues.length - 5})` : "";
103
+ return issues.join("; ") + extra;
104
+ }