@juspay/neurolink 13.16.2 → 13.17.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 (126) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/dist/adapters/providerImageAdapter.js +29 -495
  3. package/dist/browser/neurolink.min.js +465 -471
  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/core/nativeGenerateLoop.js +5 -0
  14. package/dist/factories/providerDescriptors.js +3 -2
  15. package/dist/factories/providerRegistry.js +3 -2
  16. package/dist/models/manifests/anthropic.d.ts +1 -1
  17. package/dist/models/manifests/anthropic.js +1 -1
  18. package/dist/models/manifests/azure.js +9 -9
  19. package/dist/models/manifests/ollama.js +13 -0
  20. package/dist/models/manifests/openai.d.ts +1 -1
  21. package/dist/models/manifests/openai.js +1 -1
  22. package/dist/models/modelRegistry.js +25 -42
  23. package/dist/neurolink.js +1 -0
  24. package/dist/providers/amazonBedrock/client.js +9 -37
  25. package/dist/providers/amazonBedrock/loopAdapter.js +3 -11
  26. package/dist/providers/amazonSagemaker.js +6 -0
  27. package/dist/providers/anthropic/client.js +57 -100
  28. package/dist/providers/anthropic/loopAdapter.js +24 -22
  29. package/dist/providers/anthropic/structuredOutput.d.ts +0 -2
  30. package/dist/providers/anthropic/structuredOutput.js +3 -5
  31. package/dist/providers/azureOpenai.js +4 -22
  32. package/dist/providers/catalog/loader.js +12 -25
  33. package/dist/providers/cohere.js +5 -30
  34. package/dist/providers/googleAiStudio/client.js +12 -61
  35. package/dist/providers/googleNativeGemini3/utils.js +43 -102
  36. package/dist/providers/googleVertex/client.d.ts +7 -0
  37. package/dist/providers/googleVertex/client.js +150 -192
  38. package/dist/providers/litellm/client.js +10 -50
  39. package/dist/providers/llamaCpp.js +4 -15
  40. package/dist/providers/lmStudio.js +9 -14
  41. package/dist/providers/nvidiaNim/client.js +4 -62
  42. package/dist/providers/ollama/client.js +14 -54
  43. package/dist/providers/ollama/constants.d.ts +1 -3
  44. package/dist/providers/ollama/constants.js +2 -3
  45. package/dist/providers/openAI/client.js +5 -57
  46. package/dist/providers/openRouter/client.js +4 -65
  47. package/dist/providers/openaiChatCompletionsBase.js +53 -62
  48. package/dist/providers/openaiChatCompletionsClient.js +17 -57
  49. package/dist/providers/openaiCompatible/client.js +9 -36
  50. package/dist/providers/rules/README.md +100 -0
  51. package/dist/providers/rules/anthropic.json +108 -0
  52. package/dist/providers/rules/azure.json +13 -0
  53. package/dist/providers/rules/bedrock.json +48 -0
  54. package/dist/providers/rules/cohere.json +32 -0
  55. package/dist/providers/rules/credentials.json +34 -0
  56. package/dist/providers/rules/errorRules.d.ts +17 -0
  57. package/dist/providers/rules/errorRules.js +197 -0
  58. package/dist/providers/rules/errorSignals.d.ts +2 -0
  59. package/dist/providers/rules/errorSignals.js +28 -0
  60. package/dist/providers/rules/fallbackModel.d.ts +4 -0
  61. package/dist/providers/rules/fallbackModel.js +21 -0
  62. package/dist/providers/rules/finalResultTool.d.ts +11 -0
  63. package/dist/providers/rules/finalResultTool.js +17 -0
  64. package/dist/providers/rules/finishReasons.d.ts +10 -0
  65. package/dist/providers/rules/finishReasons.js +28 -0
  66. package/dist/providers/rules/gemini.json +92 -0
  67. package/dist/providers/rules/google-ai.json +55 -0
  68. package/dist/providers/rules/limits.json +338 -0
  69. package/dist/providers/rules/litellm.json +36 -0
  70. package/dist/providers/rules/llamacpp.json +23 -0
  71. package/dist/providers/rules/lm-studio.json +21 -0
  72. package/dist/providers/rules/model-families.json +115 -0
  73. package/dist/providers/rules/modelFamilies.d.ts +10 -0
  74. package/dist/providers/rules/modelFamilies.js +45 -0
  75. package/dist/providers/rules/nvidia-nim.json +43 -0
  76. package/dist/providers/rules/ollama.json +37 -0
  77. package/dist/providers/rules/openai-chat.json +66 -0
  78. package/dist/providers/rules/openai-compatible.json +31 -0
  79. package/dist/providers/rules/openai.json +38 -0
  80. package/dist/providers/rules/openrouter.json +57 -0
  81. package/dist/providers/rules/proxy.json +44 -0
  82. package/dist/providers/rules/registry.d.ts +7 -0
  83. package/dist/providers/rules/registry.js +76 -0
  84. package/dist/providers/rules/requestDefaults.d.ts +7 -0
  85. package/dist/providers/rules/requestDefaults.js +9 -0
  86. package/dist/providers/rules/requestFields.d.ts +21 -0
  87. package/dist/providers/rules/requestFields.js +42 -0
  88. package/dist/providers/rules/sagemaker.json +88 -0
  89. package/dist/providers/rules/schema.d.ts +242 -0
  90. package/dist/providers/rules/schema.js +359 -0
  91. package/dist/providers/rules/structured-output.json +36 -0
  92. package/dist/providers/rules/thinkingLimits.d.ts +7 -0
  93. package/dist/providers/rules/thinkingLimits.js +9 -0
  94. package/dist/providers/rules/toolRules.d.ts +16 -0
  95. package/dist/providers/rules/toolRules.js +95 -0
  96. package/dist/providers/rules/usage.json +51 -0
  97. package/dist/providers/rules/vertex.json +65 -0
  98. package/dist/providers/rules/vision.json +505 -0
  99. package/dist/providers/rules/wireUsage.d.ts +38 -0
  100. package/dist/providers/rules/wireUsage.js +82 -0
  101. package/dist/providers/sagemaker/language-model.js +6 -33
  102. package/dist/providers/sagemaker/parsers.js +13 -48
  103. package/dist/providers/sagemaker/streaming.js +9 -16
  104. package/dist/proxy/claudeFormat.js +3 -16
  105. package/dist/proxy/geminiFormat.js +3 -9
  106. package/dist/proxy/openaiFormat.js +3 -16
  107. package/dist/types/generate.d.ts +2 -0
  108. package/dist/types/index.d.ts +1 -0
  109. package/dist/types/index.js +2 -0
  110. package/dist/types/providerRules.d.ts +414 -0
  111. package/dist/types/providerRules.js +10 -0
  112. package/dist/utils/errorClassifier.d.ts +2 -2
  113. package/dist/utils/errorClassifier.js +3 -2
  114. package/dist/utils/modelDetection.d.ts +1 -1
  115. package/dist/utils/modelDetection.js +30 -71
  116. package/dist/utils/providerConfig.d.ts +10 -9
  117. package/dist/utils/providerConfig.js +26 -25
  118. package/dist/utils/providerHealth.js +1 -0
  119. package/dist/utils/thinkingConfig.d.ts +1 -1
  120. package/dist/utils/thinkingConfig.js +8 -8
  121. package/dist/utils/tokenUtils.d.ts +12 -38
  122. package/dist/utils/tokenUtils.js +44 -127
  123. package/docs-site/static/search-index.json +5 -5
  124. package/package.json +2 -1
  125. package/dist/providers/localRuntimeOpenAICompat.d.ts +0 -16
  126. package/dist/providers/localRuntimeOpenAICompat.js +0 -26
@@ -0,0 +1,37 @@
1
+ {
2
+ "$schema": "./provider-rules.schema.json",
3
+ "id": "ollama",
4
+ "defaultModel": "gemma4:e2b",
5
+ "defaultModelNote": "The model used when neither the call nor OLLAMA_MODEL names one. It is the model Ollama's own quickstart runs first (`ollama run gemma4:e2b`, docs.ollama.com/quickstart): 128K context, tools, vision and thinking (ollama.com/library/gemma4). It replaced llama3.2:latest.",
6
+ "fallbackModel": "gemma4:e2b",
7
+ "fallbackModelNote": "The model suggested when the requested one is not installed. Same as defaultModel: the model Ollama's own quickstart runs first (`ollama run gemma4:e2b`, docs.ollama.com/quickstart). It replaced two disagreeing copies in code: llama3.1:8b (client.ts) and llama3.2:latest (constants.ts).",
8
+ "errors": {
9
+ "timeout": {
10
+ "class": "network",
11
+ "message": "Ollama request timed out. The model may be loading or the request is too large."
12
+ },
13
+ "rules": [
14
+ {
15
+ "errorCode": "ECONNREFUSED",
16
+ "pattern": "ECONNREFUSED|Failed to fetch|fetch failed",
17
+ "caseSensitive": true,
18
+ "class": "network",
19
+ "message": "Cannot connect to Ollama at {baseURL}. Install Ollama (https://ollama.com), start it with 'ollama serve', then try again."
20
+ },
21
+ {
22
+ "pattern": "model_not_found",
23
+ "allPatterns": ["model", "not found"],
24
+ "searchResponseBody": true,
25
+ "class": "invalid-model",
26
+ "message": "Ollama model '{model}' is not available locally. Pull it with 'ollama pull {model}', or pick an installed model from 'ollama list' (the default is '{fallbackModel}')."
27
+ },
28
+ {
29
+ "status": 404,
30
+ "pattern": "status 404",
31
+ "searchResponseBody": true,
32
+ "class": "provider",
33
+ "message": "Ollama returned HTTP 404 from {baseURL}. Verify the base URL serves the OpenAI-compatible /v1 API and that the model is installed ('ollama list')."
34
+ }
35
+ ]
36
+ }
37
+ }
@@ -0,0 +1,66 @@
1
+ {
2
+ "$schema": "./provider-rules.schema.json",
3
+ "id": "openai-chat",
4
+ "finishReasons": {
5
+ "chatCompletions": {
6
+ "map": {
7
+ "length": "length",
8
+ "tool_calls": "tool-calls",
9
+ "function_call": "tool-calls",
10
+ "tool-calls": "tool-calls",
11
+ "content_filter": "content-filter",
12
+ "content-filter": "content-filter"
13
+ },
14
+ "default": "stop"
15
+ }
16
+ },
17
+ "usage": {
18
+ "input": "prompt_tokens",
19
+ "output": "completion_tokens",
20
+ "total": "total_tokens",
21
+ "cacheRead": "prompt_tokens_details.cached_tokens",
22
+ "reasoning": "completion_tokens_details.reasoning_tokens",
23
+ "reasoningInOutput": true
24
+ },
25
+ "toolChoices": {
26
+ "neurolink": {
27
+ "modes": {
28
+ "auto": "auto",
29
+ "none": "none",
30
+ "required": "required"
31
+ },
32
+ "acceptStrings": true,
33
+ "acceptModeObjects": false,
34
+ "tool": {
35
+ "type": "function",
36
+ "function": {
37
+ "name": "{toolName}"
38
+ }
39
+ },
40
+ "toolRequiresName": true,
41
+ "fallback": null
42
+ },
43
+ "v3": {
44
+ "modes": {
45
+ "auto": "auto",
46
+ "none": "none",
47
+ "required": "required"
48
+ },
49
+ "acceptStrings": false,
50
+ "acceptModeObjects": true,
51
+ "tool": {
52
+ "type": "function",
53
+ "function": {
54
+ "name": "{toolName}"
55
+ }
56
+ },
57
+ "toolRequiresName": false,
58
+ "fallback": null
59
+ }
60
+ },
61
+ "toolNames": {
62
+ "firstChars": "a-zA-Z_",
63
+ "allowedChars": "a-zA-Z0-9_-",
64
+ "maxLength": 64
65
+ }
66
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "$schema": "./provider-rules.schema.json",
3
+ "id": "openai-compatible",
4
+ "errors": {
5
+ "rules": [
6
+ {
7
+ "errorName": "TimeoutError",
8
+ "pattern": "Timeout",
9
+ "caseSensitive": true,
10
+ "class": "network",
11
+ "message": "Request timed out: {message}"
12
+ },
13
+ {
14
+ "pattern": "ECONNREFUSED|Failed to fetch",
15
+ "class": "network",
16
+ "message": "OpenAI Compatible endpoint not available. Please check your OPENAI_COMPATIBLE_BASE_URL: {baseURL}"
17
+ },
18
+ {
19
+ "status": 401,
20
+ "pattern": "API_KEY_INVALID|Invalid API key|Unauthorized",
21
+ "class": "authentication",
22
+ "message": "Invalid OpenAI Compatible API key. Please check your OPENAI_COMPATIBLE_API_KEY environment variable."
23
+ },
24
+ {
25
+ "allPatterns": ["model", "not found|does not exist"],
26
+ "class": "invalid-model",
27
+ "message": "Model '{model}' not available on OpenAI Compatible endpoint. Please check available models or use getAvailableModels() to see supported models."
28
+ }
29
+ ]
30
+ }
31
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "$schema": "./provider-rules.schema.json",
3
+ "id": "openai",
4
+ "errors": {
5
+ "rules": [
6
+ {
7
+ "status": 401,
8
+ "bodyErrorType": "invalid_api_key",
9
+ "pattern": "API_KEY_INVALID|Invalid API key|Incorrect API key|invalid_api_key",
10
+ "class": "authentication",
11
+ "message": "Invalid OpenAI API key. Please check your OPENAI_API_KEY environment variable.",
12
+ "messageWhen": [
13
+ {
14
+ "pattern": "Incorrect API key|Invalid API key",
15
+ "message": "{message}"
16
+ }
17
+ ]
18
+ },
19
+ {
20
+ "bodyErrorType": "insufficient_quota",
21
+ "class": "provider",
22
+ "message": "OpenAI quota exhausted — this will not resolve by retrying. Check your plan and billing details at https://platform.openai.com/account/billing"
23
+ },
24
+ {
25
+ "status": 429,
26
+ "bodyErrorType": "rate_limit_error",
27
+ "pattern": "rate limit",
28
+ "class": "rate-limit",
29
+ "message": "OpenAI rate limit exceeded. Please try again later."
30
+ },
31
+ {
32
+ "pattern": "model_not_found",
33
+ "class": "invalid-model",
34
+ "message": "Model not found: {model}"
35
+ }
36
+ ]
37
+ }
38
+ }
@@ -0,0 +1,57 @@
1
+ {
2
+ "$schema": "./provider-rules.schema.json",
3
+ "id": "openrouter",
4
+ "errors": {
5
+ "rules": [
6
+ {
7
+ "errorName": "TimeoutError",
8
+ "pattern": "Timeout",
9
+ "caseSensitive": true,
10
+ "class": "network",
11
+ "message": "Request timed out: {message}"
12
+ },
13
+ {
14
+ "pattern": "ECONNREFUSED|Failed to fetch",
15
+ "caseSensitive": true,
16
+ "class": "network",
17
+ "message": "OpenRouter API not available. Please check your network connection and try again."
18
+ },
19
+ {
20
+ "pattern": "API_KEY_INVALID|Invalid API key|invalid_api_key|Unauthorized",
21
+ "caseSensitive": true,
22
+ "class": "authentication",
23
+ "message": "Invalid OpenRouter API key. Please check your OPENROUTER_API_KEY environment variable. Get your key at https://openrouter.ai/keys"
24
+ },
25
+ {
26
+ "pattern": "rate limit",
27
+ "caseSensitive": true,
28
+ "class": "rate-limit",
29
+ "message": "OpenRouter rate limit exceeded. Please try again later or upgrade your account at https://openrouter.ai/credits"
30
+ },
31
+ {
32
+ "allPatterns": ["model", "not found"],
33
+ "caseSensitive": true,
34
+ "class": "invalid-model",
35
+ "message": "Model '{model}' not available on OpenRouter. Browse available models at https://openrouter.ai/models"
36
+ },
37
+ {
38
+ "pattern": "insufficient_credits",
39
+ "caseSensitive": true,
40
+ "class": "provider",
41
+ "message": "Insufficient OpenRouter credits. Add credits at https://openrouter.ai/credits"
42
+ },
43
+ {
44
+ "pattern": "No endpoints found",
45
+ "caseSensitive": true,
46
+ "class": "invalid-model",
47
+ "message": "No endpoints found for model '{model}' on OpenRouter. The model may be temporarily unavailable or does not support the requested parameters. Try a different model or check availability at https://openrouter.ai/models"
48
+ },
49
+ {
50
+ "pattern": "tool use|tool_use|function_call|tools are not supported",
51
+ "caseSensitive": true,
52
+ "class": "provider",
53
+ "message": "Model '{model}' does not support tool calling. Use a tool-capable model like:\n • google/gemini-2.0-flash-exp:free (free)\n • meta-llama/llama-3.3-70b-instruct:free (free)\n • anthropic/claude-3.7-sonnet (paid)\n • openai/gpt-4o (paid)\nOr use --disableTools flag. See all tool-capable models at https://openrouter.ai/models?supported_parameters=tools"
54
+ }
55
+ ]
56
+ }
57
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "$schema": "./provider-rules.schema.json",
3
+ "id": "proxy",
4
+ "finishReasons": {
5
+ "toOpenAI": {
6
+ "map": {
7
+ "stop": "stop",
8
+ "end_turn": "stop",
9
+ "length": "length",
10
+ "max_tokens": "length",
11
+ "tool-calls": "tool_calls",
12
+ "tool_use": "tool_calls",
13
+ "content_filter": "content_filter",
14
+ "safety": "content_filter",
15
+ "": null
16
+ },
17
+ "default": "stop",
18
+ "whenAbsent": null
19
+ },
20
+ "toClaude": {
21
+ "map": {
22
+ "stop": "end_turn",
23
+ "end_turn": "end_turn",
24
+ "length": "max_tokens",
25
+ "max_tokens": "max_tokens",
26
+ "tool-calls": "tool_use",
27
+ "tool_use": "tool_use",
28
+ "content_filter": "stop_sequence",
29
+ "safety": "stop_sequence"
30
+ },
31
+ "default": null,
32
+ "whenAbsent": "end_turn",
33
+ "passthroughUnknown": true
34
+ },
35
+ "toGemini": {
36
+ "map": {
37
+ "length": "MAX_TOKENS",
38
+ "max_tokens": "MAX_TOKENS",
39
+ "content_filter": "SAFETY"
40
+ },
41
+ "default": "STOP"
42
+ }
43
+ }
44
+ }
@@ -0,0 +1,7 @@
1
+ import type { ProviderRuleErrors, ProviderRulesFile } from "../../types/index.js";
2
+ /** All rules files, for validation and documentation. */
3
+ export declare function listProviderRules(): readonly ProviderRulesFile[];
4
+ /** The rules file for a provider; throws when the provider has none. */
5
+ export declare function getProviderRules(id: string): ProviderRulesFile;
6
+ /** A provider's error rules; throws when its rules file has none. */
7
+ export declare function getProviderErrorRules(id: string): ProviderRuleErrors;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Every provider rules file, by provider id. Provider classes read their
3
+ * behaviour from here instead of hard-coding it. To add a rule, edit the
4
+ * JSON file; `schema.ts` validates every file in the provider-rules suite.
5
+ */
6
+ import anthropicRules from "./anthropic.json" with { type: "json" };
7
+ import azureRules from "./azure.json" with { type: "json" };
8
+ import bedrockRules from "./bedrock.json" with { type: "json" };
9
+ import cohereRules from "./cohere.json" with { type: "json" };
10
+ import credentialsRules from "./credentials.json" with { type: "json" };
11
+ import geminiRules from "./gemini.json" with { type: "json" };
12
+ import googleAiRules from "./google-ai.json" with { type: "json" };
13
+ import limitsRules from "./limits.json" with { type: "json" };
14
+ import modelFamiliesRules from "./model-families.json" with { type: "json" };
15
+ import litellmRules from "./litellm.json" with { type: "json" };
16
+ import llamacppRules from "./llamacpp.json" with { type: "json" };
17
+ import lmStudioRules from "./lm-studio.json" with { type: "json" };
18
+ import nvidiaNimRules from "./nvidia-nim.json" with { type: "json" };
19
+ import ollamaRules from "./ollama.json" with { type: "json" };
20
+ import openaiRules from "./openai.json" with { type: "json" };
21
+ import openaiChatRules from "./openai-chat.json" with { type: "json" };
22
+ import openaiCompatibleRules from "./openai-compatible.json" with { type: "json" };
23
+ import openrouterRules from "./openrouter.json" with { type: "json" };
24
+ import proxyRules from "./proxy.json" with { type: "json" };
25
+ import sagemakerRules from "./sagemaker.json" with { type: "json" };
26
+ import structuredOutputRules from "./structured-output.json" with { type: "json" };
27
+ import usageRules from "./usage.json" with { type: "json" };
28
+ import vertexRules from "./vertex.json" with { type: "json" };
29
+ import visionRules from "./vision.json" with { type: "json" };
30
+ const RULES_FILES = [
31
+ anthropicRules,
32
+ azureRules,
33
+ bedrockRules,
34
+ cohereRules,
35
+ credentialsRules,
36
+ geminiRules,
37
+ googleAiRules,
38
+ limitsRules,
39
+ modelFamiliesRules,
40
+ litellmRules,
41
+ llamacppRules,
42
+ lmStudioRules,
43
+ nvidiaNimRules,
44
+ ollamaRules,
45
+ openaiRules,
46
+ openaiChatRules,
47
+ openaiCompatibleRules,
48
+ openrouterRules,
49
+ proxyRules,
50
+ sagemakerRules,
51
+ structuredOutputRules,
52
+ usageRules,
53
+ vertexRules,
54
+ visionRules,
55
+ ];
56
+ const BY_ID = new Map(RULES_FILES.map((file) => [file.id, file]));
57
+ /** All rules files, for validation and documentation. */
58
+ export function listProviderRules() {
59
+ return RULES_FILES;
60
+ }
61
+ /** The rules file for a provider; throws when the provider has none. */
62
+ export function getProviderRules(id) {
63
+ const file = BY_ID.get(id);
64
+ if (!file) {
65
+ throw new Error(`No provider rules file for "${id}" in src/lib/providers/rules/`);
66
+ }
67
+ return file;
68
+ }
69
+ /** A provider's error rules; throws when its rules file has none. */
70
+ export function getProviderErrorRules(id) {
71
+ const errors = getProviderRules(id).errors;
72
+ if (!errors) {
73
+ throw new Error(`Provider rules file "${id}.json" has no "errors" block`);
74
+ }
75
+ return errors;
76
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Request defaults from the `requestDefaults` block in
3
+ * `src/lib/providers/rules/<id>.json`.
4
+ */
5
+ import type { ProviderRequestDefaults } from "../../types/index.js";
6
+ /** One request default; throws when the provider's rules file has none. */
7
+ export declare function getRequestDefault<K extends keyof ProviderRequestDefaults>(id: string, key: K): NonNullable<ProviderRequestDefaults[K]>;
@@ -0,0 +1,9 @@
1
+ import { getProviderRules } from "./registry.js";
2
+ /** One request default; throws when the provider's rules file has none. */
3
+ export function getRequestDefault(id, key) {
4
+ const value = getProviderRules(id).requestDefaults?.[key];
5
+ if (value === undefined || value === null) {
6
+ throw new Error(`Provider rules file "${id}.json" has no requestDefaults.${key}`);
7
+ }
8
+ return value;
9
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Request-building rules from `src/lib/providers/rules/<id>.json`: the wire
3
+ * names of request parameters (`requestFields`), how a failed tool call is
4
+ * reported (`toolResults`) and fixed conversation texts
5
+ * (`contextTexts`).
6
+ */
7
+ import type { ProviderContextTexts, ProviderRequestFields, ProviderToolResultRules, ProviderWireParamValues } from "../../types/index.js";
8
+ /** The provider's request field names; throws when its rules file has none. */
9
+ export declare function getRequestFields(id: string): ProviderRequestFields;
10
+ /**
11
+ * Request parameters under the provider's wire names. Unset values and empty
12
+ * lists are left out, as every request builder did by hand, and so is any
13
+ * parameter the rules file omits while extended thinking is on.
14
+ */
15
+ export declare function toWireParams(id: string, values: ProviderWireParamValues, context?: {
16
+ thinkingOn?: boolean;
17
+ }): Record<string, unknown>;
18
+ /** How a failed tool call is reported back to the model. */
19
+ export declare function getToolResultRules(id: string): ProviderToolResultRules;
20
+ /** Fixed texts inserted into the conversation. */
21
+ export declare function getContextTexts(id: string): ProviderContextTexts;
@@ -0,0 +1,42 @@
1
+ import { getProviderRules } from "./registry.js";
2
+ function required(id, key, value) {
3
+ if (value === undefined) {
4
+ throw new Error(`Provider rules file "${id}.json" has no ${key}`);
5
+ }
6
+ return value;
7
+ }
8
+ /** The provider's request field names; throws when its rules file has none. */
9
+ export function getRequestFields(id) {
10
+ return required(id, "requestFields", getProviderRules(id).requestFields);
11
+ }
12
+ /**
13
+ * Request parameters under the provider's wire names. Unset values and empty
14
+ * lists are left out, as every request builder did by hand, and so is any
15
+ * parameter the rules file omits while extended thinking is on.
16
+ */
17
+ export function toWireParams(id, values, context = {}) {
18
+ const names = getRequestFields(id);
19
+ const omitted = new Set(context.thinkingOn
20
+ ? (getProviderRules(id).requestFieldRules?.omitWhileThinking ?? [])
21
+ : []);
22
+ const out = {};
23
+ for (const key of Object.keys(values)) {
24
+ const value = values[key];
25
+ if (value === undefined || value === null || omitted.has(key)) {
26
+ continue;
27
+ }
28
+ if (Array.isArray(value) && value.length === 0) {
29
+ continue;
30
+ }
31
+ out[names[key]] = value;
32
+ }
33
+ return out;
34
+ }
35
+ /** How a failed tool call is reported back to the model. */
36
+ export function getToolResultRules(id) {
37
+ return required(id, "toolResults", getProviderRules(id).toolResults);
38
+ }
39
+ /** Fixed texts inserted into the conversation. */
40
+ export function getContextTexts(id) {
41
+ return required(id, "contextTexts", getProviderRules(id).contextTexts);
42
+ }
@@ -0,0 +1,88 @@
1
+ {
2
+ "$schema": "./provider-rules.schema.json",
3
+ "id": "sagemaker",
4
+ "finishReasons": {
5
+ "endpoint": {
6
+ "map": {
7
+ "stop": "stop",
8
+ "end_turn": "stop",
9
+ "stop_sequence": "stop",
10
+ "length": "length",
11
+ "max_tokens": "length",
12
+ "max_length": "length",
13
+ "content_filter": "content-filter",
14
+ "content_filtered": "content-filter",
15
+ "tool_calls": "tool-calls",
16
+ "function_call": "tool-calls",
17
+ "error": "error"
18
+ },
19
+ "default": "unknown",
20
+ "lowercase": true
21
+ },
22
+ "huggingfaceStream": {
23
+ "map": {
24
+ "stop": "stop",
25
+ "length": "length",
26
+ "eos_token": "stop"
27
+ },
28
+ "default": "unknown"
29
+ },
30
+ "openaiStream": {
31
+ "map": {
32
+ "stop": "stop",
33
+ "length": "length",
34
+ "function_call": "tool-calls",
35
+ "content_filter": "content-filter",
36
+ "": null
37
+ },
38
+ "default": "unknown",
39
+ "whenAbsent": null
40
+ }
41
+ },
42
+ "usageDialects": {
43
+ "huggingface": {
44
+ "input": ["input"],
45
+ "output": ["generated"],
46
+ "total": ["total"],
47
+ "pick": "truthy"
48
+ },
49
+ "openai": {
50
+ "input": ["prompt_tokens"],
51
+ "output": ["completion_tokens"],
52
+ "total": ["total_tokens"],
53
+ "pick": "truthy"
54
+ },
55
+ "custom": {
56
+ "input": ["prompt_tokens", "input_tokens"],
57
+ "output": ["completion_tokens", "output_tokens"],
58
+ "total": ["total_tokens"],
59
+ "pick": "truthy"
60
+ },
61
+ "responseBody": {
62
+ "input": ["prompt_tokens", "input_tokens"],
63
+ "output": ["completion_tokens", "output_tokens"],
64
+ "total": ["total_tokens"],
65
+ "pick": "defined"
66
+ }
67
+ },
68
+ "toolChoices": {
69
+ "openai": {
70
+ "modes": {
71
+ "auto": "auto",
72
+ "none": "none",
73
+ "required": "required"
74
+ },
75
+ "acceptStrings": false,
76
+ "acceptModeObjects": true,
77
+ "tool": {
78
+ "type": "function",
79
+ "function": {
80
+ "name": "{toolName}"
81
+ }
82
+ },
83
+ "toolRequiresName": false,
84
+ "passthroughStrings": true,
85
+ "fallback": "auto"
86
+ }
87
+ }
88
+ }