@juspay/neurolink 13.16.2 → 13.17.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 (121) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/dist/adapters/providerImageAdapter.js +29 -495
  3. package/dist/browser/neurolink.min.js +464 -470
  4. package/dist/constants/contextWindows.js +13 -328
  5. package/dist/constants/enums.d.ts +1 -0
  6. package/dist/constants/enums.js +2 -1
  7. package/dist/context/anthropicLoopGuard.d.ts +1 -1
  8. package/dist/context/anthropicLoopGuard.js +2 -1
  9. package/dist/core/constants.js +6 -53
  10. package/dist/core/geminiLoopAdapter.js +8 -6
  11. package/dist/core/modules/structuredOutputPolicy.d.ts +0 -21
  12. package/dist/core/modules/structuredOutputPolicy.js +4 -54
  13. package/dist/factories/providerDescriptors.js +3 -2
  14. package/dist/factories/providerRegistry.js +3 -2
  15. package/dist/models/manifests/anthropic.d.ts +1 -1
  16. package/dist/models/manifests/anthropic.js +1 -1
  17. package/dist/models/manifests/azure.js +9 -9
  18. package/dist/models/manifests/ollama.js +13 -0
  19. package/dist/models/manifests/openai.d.ts +1 -1
  20. package/dist/models/manifests/openai.js +1 -1
  21. package/dist/models/modelRegistry.js +17 -42
  22. package/dist/providers/amazonBedrock/client.js +9 -37
  23. package/dist/providers/amazonBedrock/loopAdapter.js +3 -11
  24. package/dist/providers/anthropic/client.js +42 -97
  25. package/dist/providers/anthropic/loopAdapter.js +24 -22
  26. package/dist/providers/anthropic/structuredOutput.d.ts +0 -2
  27. package/dist/providers/anthropic/structuredOutput.js +3 -5
  28. package/dist/providers/azureOpenai.js +4 -22
  29. package/dist/providers/catalog/loader.js +12 -25
  30. package/dist/providers/cohere.js +5 -30
  31. package/dist/providers/googleAiStudio/client.js +12 -61
  32. package/dist/providers/googleNativeGemini3/utils.js +43 -102
  33. package/dist/providers/googleVertex/client.js +123 -184
  34. package/dist/providers/litellm/client.js +10 -50
  35. package/dist/providers/llamaCpp.js +4 -15
  36. package/dist/providers/lmStudio.js +9 -14
  37. package/dist/providers/nvidiaNim/client.js +4 -62
  38. package/dist/providers/ollama/client.js +14 -54
  39. package/dist/providers/ollama/constants.d.ts +1 -3
  40. package/dist/providers/ollama/constants.js +2 -3
  41. package/dist/providers/openAI/client.js +5 -57
  42. package/dist/providers/openRouter/client.js +4 -65
  43. package/dist/providers/openaiChatCompletionsBase.js +34 -58
  44. package/dist/providers/openaiChatCompletionsClient.js +17 -57
  45. package/dist/providers/openaiCompatible/client.js +9 -36
  46. package/dist/providers/rules/README.md +100 -0
  47. package/dist/providers/rules/anthropic.json +104 -0
  48. package/dist/providers/rules/azure.json +13 -0
  49. package/dist/providers/rules/bedrock.json +48 -0
  50. package/dist/providers/rules/cohere.json +32 -0
  51. package/dist/providers/rules/credentials.json +34 -0
  52. package/dist/providers/rules/errorRules.d.ts +17 -0
  53. package/dist/providers/rules/errorRules.js +197 -0
  54. package/dist/providers/rules/errorSignals.d.ts +2 -0
  55. package/dist/providers/rules/errorSignals.js +28 -0
  56. package/dist/providers/rules/fallbackModel.d.ts +4 -0
  57. package/dist/providers/rules/fallbackModel.js +21 -0
  58. package/dist/providers/rules/finalResultTool.d.ts +11 -0
  59. package/dist/providers/rules/finalResultTool.js +17 -0
  60. package/dist/providers/rules/finishReasons.d.ts +10 -0
  61. package/dist/providers/rules/finishReasons.js +28 -0
  62. package/dist/providers/rules/gemini.json +92 -0
  63. package/dist/providers/rules/google-ai.json +55 -0
  64. package/dist/providers/rules/limits.json +338 -0
  65. package/dist/providers/rules/litellm.json +36 -0
  66. package/dist/providers/rules/llamacpp.json +23 -0
  67. package/dist/providers/rules/lm-studio.json +21 -0
  68. package/dist/providers/rules/model-families.json +109 -0
  69. package/dist/providers/rules/modelFamilies.d.ts +10 -0
  70. package/dist/providers/rules/modelFamilies.js +45 -0
  71. package/dist/providers/rules/nvidia-nim.json +43 -0
  72. package/dist/providers/rules/ollama.json +37 -0
  73. package/dist/providers/rules/openai-chat.json +66 -0
  74. package/dist/providers/rules/openai-compatible.json +31 -0
  75. package/dist/providers/rules/openai.json +38 -0
  76. package/dist/providers/rules/openrouter.json +57 -0
  77. package/dist/providers/rules/proxy.json +44 -0
  78. package/dist/providers/rules/registry.d.ts +7 -0
  79. package/dist/providers/rules/registry.js +76 -0
  80. package/dist/providers/rules/requestDefaults.d.ts +7 -0
  81. package/dist/providers/rules/requestDefaults.js +9 -0
  82. package/dist/providers/rules/requestFields.d.ts +18 -0
  83. package/dist/providers/rules/requestFields.js +38 -0
  84. package/dist/providers/rules/sagemaker.json +88 -0
  85. package/dist/providers/rules/schema.d.ts +234 -0
  86. package/dist/providers/rules/schema.js +352 -0
  87. package/dist/providers/rules/structured-output.json +36 -0
  88. package/dist/providers/rules/thinkingLimits.d.ts +7 -0
  89. package/dist/providers/rules/thinkingLimits.js +9 -0
  90. package/dist/providers/rules/toolRules.d.ts +16 -0
  91. package/dist/providers/rules/toolRules.js +95 -0
  92. package/dist/providers/rules/usage.json +51 -0
  93. package/dist/providers/rules/vertex.json +65 -0
  94. package/dist/providers/rules/vision.json +505 -0
  95. package/dist/providers/rules/wireUsage.d.ts +38 -0
  96. package/dist/providers/rules/wireUsage.js +82 -0
  97. package/dist/providers/sagemaker/language-model.js +6 -33
  98. package/dist/providers/sagemaker/parsers.js +13 -48
  99. package/dist/providers/sagemaker/streaming.js +9 -16
  100. package/dist/proxy/claudeFormat.js +3 -16
  101. package/dist/proxy/geminiFormat.js +3 -9
  102. package/dist/proxy/openaiFormat.js +3 -16
  103. package/dist/types/index.d.ts +1 -0
  104. package/dist/types/index.js +2 -0
  105. package/dist/types/providerRules.d.ts +407 -0
  106. package/dist/types/providerRules.js +10 -0
  107. package/dist/utils/errorClassifier.d.ts +2 -2
  108. package/dist/utils/errorClassifier.js +3 -2
  109. package/dist/utils/modelDetection.d.ts +1 -1
  110. package/dist/utils/modelDetection.js +30 -71
  111. package/dist/utils/providerConfig.d.ts +10 -9
  112. package/dist/utils/providerConfig.js +26 -25
  113. package/dist/utils/providerHealth.js +1 -0
  114. package/dist/utils/thinkingConfig.d.ts +1 -1
  115. package/dist/utils/thinkingConfig.js +8 -8
  116. package/dist/utils/tokenUtils.d.ts +12 -38
  117. package/dist/utils/tokenUtils.js +44 -127
  118. package/docs-site/static/search-index.json +5 -5
  119. package/package.json +2 -1
  120. package/dist/providers/localRuntimeOpenAICompat.d.ts +0 -16
  121. package/dist/providers/localRuntimeOpenAICompat.js +0 -26
@@ -0,0 +1,95 @@
1
+ import { getProviderRules } from "./registry.js";
2
+ const TOOL_NAME_PLACEHOLDER = "{toolName}";
3
+ /** The named tool-choice table from a rules file; throws when it is missing. */
4
+ export function getToolChoiceMap(id, name) {
5
+ const table = getProviderRules(id).toolChoices?.[name];
6
+ if (!table) {
7
+ throw new Error(`Provider rules file "${id}.json" has no toolChoices.${name} table`);
8
+ }
9
+ return table;
10
+ }
11
+ const fillToolName = (value, toolName) => {
12
+ if (value === TOOL_NAME_PLACEHOLDER) {
13
+ return toolName;
14
+ }
15
+ if (Array.isArray(value)) {
16
+ return value.map((item) => fillToolName(item, toolName));
17
+ }
18
+ if (value && typeof value === "object") {
19
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [
20
+ key,
21
+ fillToolName(item, toolName),
22
+ ]));
23
+ }
24
+ return value;
25
+ };
26
+ const fromRule = (value) => value === null || value === undefined ? undefined : structuredClone(value);
27
+ /**
28
+ * Spell a tool choice for one wire (see ProviderToolChoiceMap). `toWireName`
29
+ * maps a registered tool name onto the name the wire knows it by. Returns
30
+ * undefined when nothing should be sent.
31
+ */
32
+ export function translateToolChoice(table, choice, toWireName) {
33
+ if (choice === null || choice === undefined) {
34
+ return undefined;
35
+ }
36
+ if (typeof choice === "string") {
37
+ if (table.acceptStrings && Object.hasOwn(table.modes, choice)) {
38
+ return fromRule(table.modes[choice]);
39
+ }
40
+ return table.passthroughStrings ? choice : fromRule(table.fallback);
41
+ }
42
+ if (typeof choice === "object") {
43
+ const { type, toolName } = choice;
44
+ if (type === "tool" && (!table.toolRequiresName || toolName)) {
45
+ const wireName = typeof toolName === "string" && toWireName
46
+ ? toWireName(toolName)
47
+ : toolName;
48
+ return fillToolName(table.tool, wireName);
49
+ }
50
+ if (table.acceptModeObjects &&
51
+ typeof type === "string" &&
52
+ Object.hasOwn(table.modes, type)) {
53
+ return fromRule(table.modes[type]);
54
+ }
55
+ }
56
+ return fromRule(table.fallback);
57
+ }
58
+ /** A provider's tool-name rules; throws when its rules file has none. */
59
+ export function getToolNameRules(id) {
60
+ const rules = getProviderRules(id).toolNames;
61
+ if (!rules) {
62
+ throw new Error(`Provider rules file "${id}.json" has no toolNames block`);
63
+ }
64
+ return rules;
65
+ }
66
+ export function compileToolNameRules(rules) {
67
+ const valid = new RegExp(`^[${rules.firstChars}][${rules.allowedChars}]{0,${rules.maxLength - 1}}$`);
68
+ const disallowed = new RegExp(`[^${rules.allowedChars}]`, "g");
69
+ const validFirst = new RegExp(`^[${rules.firstChars}]`);
70
+ return {
71
+ isValid: (name) => valid.test(name),
72
+ sanitize: (name) => {
73
+ if (valid.test(name)) {
74
+ return name;
75
+ }
76
+ let sanitized = name.replace(disallowed, "_");
77
+ if (!validFirst.test(sanitized)) {
78
+ sanitized = `_${sanitized}`;
79
+ }
80
+ return sanitized.slice(0, rules.maxLength);
81
+ },
82
+ unique: (base, isTaken) => {
83
+ if (!isTaken(base)) {
84
+ return base;
85
+ }
86
+ for (let suffix = 2;; suffix++) {
87
+ const tail = `_${suffix}`;
88
+ const candidate = `${base.slice(0, rules.maxLength - tail.length)}${tail}`;
89
+ if (!isTaken(candidate)) {
90
+ return candidate;
91
+ }
92
+ }
93
+ },
94
+ };
95
+ }
@@ -0,0 +1,51 @@
1
+ {
2
+ "$schema": "./provider-rules.schema.json",
3
+ "id": "usage",
4
+ "usageFields": {
5
+ "input": { "paths": ["input", "inputTokens", "promptTokens"] },
6
+ "output": { "paths": ["output", "outputTokens", "completionTokens"] },
7
+ "total": { "paths": ["total", "totalTokens"], "positiveOnly": true },
8
+ "reasoning": {
9
+ "paths": [
10
+ "reasoningTokens",
11
+ "thinkingTokens",
12
+ "reasoning_tokens",
13
+ "reasoning"
14
+ ],
15
+ "positiveOnly": true
16
+ },
17
+ "cacheCreation": {
18
+ "paths": [
19
+ "cacheCreationInputTokens",
20
+ "cacheCreationTokens",
21
+ "inputTokenDetails.cacheWriteTokens"
22
+ ],
23
+ "positiveOnly": true
24
+ },
25
+ "cacheRead": {
26
+ "paths": [
27
+ "cacheReadInputTokens",
28
+ "cacheReadTokens",
29
+ "cachedInputTokens",
30
+ "inputTokenDetails.cacheReadTokens"
31
+ ],
32
+ "positiveOnly": true
33
+ },
34
+ "cacheReadIncludedInInput": {
35
+ "paths": ["prompt_tokens_details.cached_tokens"],
36
+ "positiveOnly": true
37
+ }
38
+ },
39
+ "usageRebase": {
40
+ "whenAnyPresent": ["cachedInputTokens", "inputTokenDetails"],
41
+ "unlessAnyPresent": [
42
+ "cacheReadInputTokens",
43
+ "cacheReadTokens",
44
+ "cacheCreationInputTokens",
45
+ "cacheCreationTokens",
46
+ "prompt_tokens_details.cached_tokens"
47
+ ],
48
+ "uncachedInput": "inputTokenDetails.noCacheTokens",
49
+ "cacheWrite": "inputTokenDetails.cacheWriteTokens"
50
+ }
51
+ }
@@ -0,0 +1,65 @@
1
+ {
2
+ "$schema": "./provider-rules.schema.json",
3
+ "id": "vertex",
4
+ "errors": {
5
+ "statusFrom": "top-level",
6
+ "useDefaults": false,
7
+ "rules": [
8
+ {
9
+ "errorName": "TimeoutError",
10
+ "pattern": "^Request timed out\\.?$",
11
+ "class": "network",
12
+ "message": "Google Vertex AI request timed out. Consider increasing timeout or using a lighter model."
13
+ },
14
+ {
15
+ "status": [401, 403],
16
+ "pattern": "PERMISSION_DENIED|UNAUTHENTICATED|Invalid API key",
17
+ "class": "authentication",
18
+ "message": "Google Vertex AI Permission Denied. Your Google Cloud credentials don't have permission to access Vertex AI. Required Steps: 1. Ensure your service account has Vertex AI User role 2. Check if Vertex AI API is enabled in your project 3. Verify your project ID is correct 4. Confirm your location/region has Vertex AI available"
19
+ },
20
+ {
21
+ "status": 404,
22
+ "pattern": "NOT_FOUND|model not found|Model not found",
23
+ "class": "invalid-model",
24
+ "messageHook": "vertex.modelUnavailable"
25
+ },
26
+ {
27
+ "status": [429, 529],
28
+ "messageStatus": 429,
29
+ "pattern": "QUOTA_EXCEEDED|RATE_LIMIT_EXCEEDED|rate limit|overloaded",
30
+ "class": "rate-limit",
31
+ "messageHook": "vertex.rateLimit"
32
+ },
33
+ {
34
+ "pattern": "ECONNRESET|ENOTFOUND|ETIMEDOUT|ECONNREFUSED|network|connection",
35
+ "class": "network",
36
+ "message": "Connection error: {message}"
37
+ },
38
+ {
39
+ "statusRange": [500, 599],
40
+ "messageStatus": [500, 502, 503, 504],
41
+ "pattern": "server error|Internal Server Error|INTERNAL|UNAVAILABLE",
42
+ "class": "provider",
43
+ "message": "Google Vertex AI server error: {message}. Please try again later."
44
+ },
45
+ {
46
+ "pattern": "INVALID_ARGUMENT",
47
+ "class": "provider",
48
+ "message": "Google Vertex AI Invalid Request: {message}. Check: 1. Request parameters are within model limits 2. Input text is properly formatted 3. Temperature and other settings are valid 4. Model supports your request type"
49
+ },
50
+ {
51
+ "always": true,
52
+ "class": "provider",
53
+ "message": "Google Vertex AI error: {message}"
54
+ }
55
+ ]
56
+ },
57
+ "requestDefaults": {
58
+ "finalizationMinTokens": 1024,
59
+ "finalizationHeadroomTokens": 4000
60
+ },
61
+ "requestDefaultNotes": {
62
+ "finalizationMinTokens": "The forced finalization call after a Claude-on-Vertex loop stops always gets at least this many output tokens.",
63
+ "finalizationHeadroomTokens": "Room kept free of the context window when sizing that call, beyond the projected prompt."
64
+ }
65
+ }