@juspay/neurolink 12.40.1 → 12.40.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 +3 -3
- package/dist/browser/neurolink.min.js +393 -392
- package/dist/utils/schemaConversion.js +74 -4
- package/package.json +1 -1
|
@@ -1,8 +1,70 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { jsonSchemaToZod } from "json-schema-to-zod";
|
|
1
|
+
import { createRequire } from "node:module";
|
|
3
2
|
import * as zodModule from "zod";
|
|
4
3
|
import { z } from "zod";
|
|
5
4
|
import { logger } from "./logger.js";
|
|
5
|
+
/**
|
|
6
|
+
* zod-to-json-schema and json-schema-to-zod are loaded synchronously via
|
|
7
|
+
* require() on first actual use, not via a top-level import, so merely
|
|
8
|
+
* importing this module no longer pulls in either package for the many
|
|
9
|
+
* callers who never convert a schema. Both ship a CJS `require` export
|
|
10
|
+
* condition (checked against their package.json), so require() works on
|
|
11
|
+
* any Node >=22.0.0 — no experimental flag, unlike require(esm) of a local
|
|
12
|
+
* ES module (which only works unflagged from Node >=22.12). Zod itself
|
|
13
|
+
* stays a normal static import: its runtime schemas (`z`, `zodModule`) are
|
|
14
|
+
* public exports used well beyond schema conversion. Follows the pattern in
|
|
15
|
+
* src/lib/proxy/otelLogSink.ts — construction stays one synchronous call,
|
|
16
|
+
* exactly as before; only the *import* is deferred.
|
|
17
|
+
*
|
|
18
|
+
* A require() made through createRequire() is invisible to bundlers, so a
|
|
19
|
+
* consumer that bundles the SDK without these packages next to the output can
|
|
20
|
+
* no longer resolve them, and listing them as external changes nothing for the
|
|
21
|
+
* same reason: the bundler never sees the call. That must not pass for a
|
|
22
|
+
* schema that simply had no properties: the failure is reported once per
|
|
23
|
+
* package at error level (the only level shown without NEUROLINK_DEBUG),
|
|
24
|
+
* remembered so later calls neither retry the lookup nor repeat the report,
|
|
25
|
+
* and the caller degrades exactly as it does when a conversion throws. The
|
|
26
|
+
* browser artifact is the one bundle we build ourselves;
|
|
27
|
+
* scripts/build-browser.mjs bundles both packages into it and serves them from
|
|
28
|
+
* its `module` stub.
|
|
29
|
+
*/
|
|
30
|
+
const require = createRequire(import.meta.url);
|
|
31
|
+
function lazyPackageFunction(packageName, exportName) {
|
|
32
|
+
let attempted = false;
|
|
33
|
+
let resolved;
|
|
34
|
+
return () => {
|
|
35
|
+
if (attempted) {
|
|
36
|
+
return resolved;
|
|
37
|
+
}
|
|
38
|
+
attempted = true;
|
|
39
|
+
let failure;
|
|
40
|
+
try {
|
|
41
|
+
const loadedModule = require(packageName);
|
|
42
|
+
const candidate = typeof loadedModule === "object" && loadedModule !== null
|
|
43
|
+
? Reflect.get(loadedModule, exportName)
|
|
44
|
+
: undefined;
|
|
45
|
+
if (typeof candidate === "function") {
|
|
46
|
+
resolved = candidate;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
failure = `it resolved without a "${exportName}" function`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
failure = (error instanceof Error ? error.message : String(error)).split("\n")[0];
|
|
54
|
+
}
|
|
55
|
+
if (failure !== undefined) {
|
|
56
|
+
logger.error(`[SCHEMA-CONVERSION] Cannot load "${packageName}" (${failure}). Any schema ` +
|
|
57
|
+
`that needs it is replaced with an empty object schema, so the model ` +
|
|
58
|
+
`sees no parameters for it. The SDK loads this package at run time ` +
|
|
59
|
+
`and a bundler cannot see that load, so bundling the SDK does not ` +
|
|
60
|
+
`provide it: install "${packageName}" where @juspay/neurolink can ` +
|
|
61
|
+
`resolve it, next to your bundle if you bundle the SDK.`);
|
|
62
|
+
}
|
|
63
|
+
return resolved;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const loadZodToJsonSchema = lazyPackageFunction("zod-to-json-schema", "zodToJsonSchema");
|
|
67
|
+
const loadJsonSchemaToZod = lazyPackageFunction("json-schema-to-zod", "jsonSchemaToZod");
|
|
6
68
|
// Zod 4 ships a built-in `z.toJSONSchema(...)`. Zod 3 does not — it returned
|
|
7
69
|
// nothing of the sort and we relied entirely on `zod-to-json-schema`. The
|
|
8
70
|
// `zod-to-json-schema` package only understands Zod 3's internal `_def`
|
|
@@ -360,12 +422,16 @@ target = "jsonSchema7") {
|
|
|
360
422
|
}
|
|
361
423
|
}
|
|
362
424
|
// Zod 3 fallback path
|
|
425
|
+
const convertWithZodToJsonSchema = loadZodToJsonSchema();
|
|
426
|
+
if (!convertWithZodToJsonSchema) {
|
|
427
|
+
return { type: "object", properties: {} };
|
|
428
|
+
}
|
|
363
429
|
try {
|
|
364
430
|
// Zod 4→3 boundary: zodToJsonSchema types reference Zod 3's ZodSchema via zod/v3.
|
|
365
431
|
// Runtime compatible — cast through unknown at this third-party boundary only.
|
|
366
432
|
// eslint-disable-next-line no-restricted-syntax -- genuine third-party type-system boundary: zod-to-json-schema's input type is zod/v3's ZodType, structurally incompatible with the Zod 4 schema held here (no overlap, single assertion cannot compile); runtime-compatible fallback contract documented above.
|
|
367
433
|
const zodV3Schema = zodSchema;
|
|
368
|
-
const jsonSchema =
|
|
434
|
+
const jsonSchema = convertWithZodToJsonSchema(zodV3Schema, {
|
|
369
435
|
name: "ToolParameters",
|
|
370
436
|
target,
|
|
371
437
|
errorMessages: true,
|
|
@@ -612,7 +678,11 @@ export function convertJsonSchemaToZod(jsonSchema) {
|
|
|
612
678
|
: [],
|
|
613
679
|
});
|
|
614
680
|
// Use official library to convert JSON Schema to Zod code
|
|
615
|
-
const
|
|
681
|
+
const convertToZodCode = loadJsonSchemaToZod();
|
|
682
|
+
if (!convertToZodCode) {
|
|
683
|
+
return z.object({}).passthrough();
|
|
684
|
+
}
|
|
685
|
+
const zodCodeResult = convertToZodCode(jsonSchema, {
|
|
616
686
|
module: "esm",
|
|
617
687
|
name: "schema",
|
|
618
688
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juspay/neurolink",
|
|
3
|
-
"version": "12.40.
|
|
3
|
+
"version": "12.40.2",
|
|
4
4
|
"packageManager": "pnpm@10.15.1",
|
|
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": {
|