@juspay/neurolink 10.5.3 → 10.6.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.
- package/CHANGELOG.md +6 -0
- package/dist/agent/agent.js +39 -8
- package/dist/agent/agentNetwork.js +62 -20
- package/dist/agent/agentToolRegistrar.d.ts +48 -0
- package/dist/agent/agentToolRegistrar.js +336 -0
- package/dist/agent/index.d.ts +3 -0
- package/dist/agent/index.js +4 -0
- package/dist/agent/isolatedAgentRunner.d.ts +73 -0
- package/dist/agent/isolatedAgentRunner.js +946 -0
- package/dist/agent/structuredRecovery.d.ts +30 -0
- package/dist/agent/structuredRecovery.js +104 -0
- package/dist/browser/neurolink.min.js +414 -398
- package/dist/cli/loop/optionsSchema.d.ts +1 -1
- package/dist/core/baseProvider.d.ts +8 -0
- package/dist/core/baseProvider.js +40 -19
- package/dist/core/modules/GenerationHandler.d.ts +2 -6
- package/dist/core/modules/GenerationHandler.js +10 -1
- package/dist/core/toolExecutionRecorder.d.ts +76 -0
- package/dist/core/toolExecutionRecorder.js +261 -0
- package/dist/evaluation/contextBuilder.js +6 -6
- package/dist/lib/agent/agent.js +39 -8
- package/dist/lib/agent/agentNetwork.js +62 -20
- package/dist/lib/agent/agentToolRegistrar.d.ts +48 -0
- package/dist/lib/agent/agentToolRegistrar.js +337 -0
- package/dist/lib/agent/index.d.ts +3 -0
- package/dist/lib/agent/index.js +4 -0
- package/dist/lib/agent/isolatedAgentRunner.d.ts +73 -0
- package/dist/lib/agent/isolatedAgentRunner.js +947 -0
- package/dist/lib/agent/structuredRecovery.d.ts +30 -0
- package/dist/lib/agent/structuredRecovery.js +105 -0
- package/dist/lib/core/baseProvider.d.ts +8 -0
- package/dist/lib/core/baseProvider.js +40 -19
- package/dist/lib/core/modules/GenerationHandler.d.ts +2 -6
- package/dist/lib/core/modules/GenerationHandler.js +10 -1
- package/dist/lib/core/toolExecutionRecorder.d.ts +76 -0
- package/dist/lib/core/toolExecutionRecorder.js +262 -0
- package/dist/lib/evaluation/contextBuilder.js +6 -6
- package/dist/lib/models/modelRegistry.d.ts +23 -0
- package/dist/lib/models/modelRegistry.js +62 -1
- package/dist/lib/models/modelResolver.js +1 -0
- package/dist/lib/neurolink.d.ts +80 -1
- package/dist/lib/neurolink.js +199 -37
- package/dist/lib/providers/amazonBedrock.js +15 -2
- package/dist/lib/providers/anthropic.js +23 -11
- package/dist/lib/providers/googleAiStudio.js +8 -1
- package/dist/lib/providers/googleNativeGemini3.d.ts +2 -0
- package/dist/lib/providers/googleNativeGemini3.js +8 -1
- package/dist/lib/providers/googleVertex.js +56 -16
- package/dist/lib/providers/openaiChatCompletionsClient.js +18 -5
- package/dist/lib/tasks/autoresearchTaskExecutor.js +7 -6
- package/dist/lib/tasks/taskExecutor.js +2 -5
- package/dist/lib/types/agentNetwork.d.ts +23 -8
- package/dist/lib/types/generate.d.ts +62 -5
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/index.js +1 -0
- package/dist/lib/types/isolatedAgent.d.ts +365 -0
- package/dist/lib/types/isolatedAgent.js +12 -0
- package/dist/lib/types/model.d.ts +8 -0
- package/dist/lib/types/stream.d.ts +3 -1
- package/dist/lib/types/task.d.ts +3 -3
- package/dist/lib/utils/logger.d.ts +12 -3
- package/dist/lib/utils/logger.js +11 -3
- package/dist/lib/utils/transformationUtils.d.ts +14 -0
- package/dist/lib/utils/transformationUtils.js +33 -10
- package/dist/lib/voice/livekit/realtimeVoiceAgent.js +6 -3
- package/dist/models/modelRegistry.d.ts +23 -0
- package/dist/models/modelRegistry.js +62 -1
- package/dist/models/modelResolver.js +1 -0
- package/dist/neurolink.d.ts +80 -1
- package/dist/neurolink.js +199 -37
- package/dist/providers/amazonBedrock.js +15 -2
- package/dist/providers/anthropic.js +23 -11
- package/dist/providers/googleAiStudio.js +8 -1
- package/dist/providers/googleNativeGemini3.d.ts +2 -0
- package/dist/providers/googleNativeGemini3.js +8 -1
- package/dist/providers/googleVertex.js +56 -16
- package/dist/providers/openaiChatCompletionsClient.js +18 -5
- package/dist/tasks/autoresearchTaskExecutor.js +7 -6
- package/dist/tasks/taskExecutor.js +2 -5
- package/dist/types/agentNetwork.d.ts +23 -8
- package/dist/types/generate.d.ts +62 -5
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/isolatedAgent.d.ts +365 -0
- package/dist/types/isolatedAgent.js +11 -0
- package/dist/types/model.d.ts +8 -0
- package/dist/types/stream.d.ts +3 -1
- package/dist/types/task.d.ts +3 -3
- package/dist/utils/logger.d.ts +12 -3
- package/dist/utils/logger.js +11 -3
- package/dist/utils/transformationUtils.d.ts +14 -0
- package/dist/utils/transformationUtils.js +33 -10
- package/dist/voice/livekit/realtimeVoiceAgent.js +6 -3
- 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
|
+
}
|