@ai-sdk/provider-utils 5.0.0-beta.5 → 5.0.0-beta.6
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 +19 -11
- package/dist/index.d.mts +37 -2
- package/dist/index.d.ts +37 -2
- package/dist/index.js +68 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -4
- package/src/index.ts +5 -0
- package/src/map-reasoning-to-provider.ts +105 -0
- package/src/validate-download-url.ts +7 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 5.0.0-beta.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3887c70: feat(provider): add new top-level reasoning parameter to spec and support it in `generateText` and `streamText`
|
|
8
|
+
- Updated dependencies [3887c70]
|
|
9
|
+
- @ai-sdk/provider@4.0.0-beta.4
|
|
10
|
+
|
|
3
11
|
## 5.0.0-beta.5
|
|
4
12
|
|
|
5
13
|
### Major Changes
|
|
@@ -50,18 +58,18 @@
|
|
|
50
58
|
const toolNameMapping = createToolNameMapping({
|
|
51
59
|
tools,
|
|
52
60
|
providerToolNames: {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
"openai.code_interpreter": "code_interpreter",
|
|
62
|
+
"openai.file_search": "file_search",
|
|
63
|
+
"openai.image_generation": "image_generation",
|
|
64
|
+
"openai.local_shell": "local_shell",
|
|
65
|
+
"openai.shell": "shell",
|
|
66
|
+
"openai.web_search": "web_search",
|
|
67
|
+
"openai.web_search_preview": "web_search_preview",
|
|
68
|
+
"openai.mcp": "mcp",
|
|
69
|
+
"openai.apply_patch": "apply_patch",
|
|
62
70
|
},
|
|
63
|
-
resolveProviderToolName: tool =>
|
|
64
|
-
tool.id ===
|
|
71
|
+
resolveProviderToolName: (tool) =>
|
|
72
|
+
tool.id === "openai.custom"
|
|
65
73
|
? (tool.args as { name?: string }).name
|
|
66
74
|
: undefined,
|
|
67
75
|
});
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, ImageModelV4File, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV4Prompt, SharedV4ProviderOptions, TypeValidationContext } from '@ai-sdk/provider';
|
|
1
|
+
import { LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, ImageModelV4File, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV4Prompt, LanguageModelV4CallOptions, SharedV4Warning, SharedV4ProviderOptions, TypeValidationContext } from '@ai-sdk/provider';
|
|
2
2
|
import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
|
|
3
3
|
export * from '@standard-schema/spec';
|
|
4
4
|
import * as z3 from 'zod/v3';
|
|
@@ -426,6 +426,41 @@ declare function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterNa
|
|
|
426
426
|
description: string;
|
|
427
427
|
}): string;
|
|
428
428
|
|
|
429
|
+
type ReasoningLevel = Exclude<LanguageModelV4CallOptions['reasoning'], 'none' | 'provider-default' | undefined>;
|
|
430
|
+
declare function isCustomReasoning(reasoning: LanguageModelV4CallOptions['reasoning']): reasoning is Exclude<LanguageModelV4CallOptions['reasoning'], 'provider-default' | undefined>;
|
|
431
|
+
/**
|
|
432
|
+
* Maps a top-level reasoning level to a provider-specific effort string using
|
|
433
|
+
* the given effort map. Pushes a compatibility warning if the reasoning level
|
|
434
|
+
* maps to a different string, or an unsupported warning if the level is not
|
|
435
|
+
* present in the map.
|
|
436
|
+
*
|
|
437
|
+
* @returns The mapped effort string, or `undefined` if the level is not
|
|
438
|
+
* supported.
|
|
439
|
+
*/
|
|
440
|
+
declare function mapReasoningToProviderEffort<T extends string>({ reasoning, effortMap, warnings, }: {
|
|
441
|
+
reasoning: ReasoningLevel;
|
|
442
|
+
effortMap: Partial<Record<ReasoningLevel, T>>;
|
|
443
|
+
warnings: SharedV4Warning[];
|
|
444
|
+
}): T | undefined;
|
|
445
|
+
/**
|
|
446
|
+
* Maps a top-level reasoning level to an absolute token budget by multiplying
|
|
447
|
+
* the model's max output tokens by a percentage from the budget percentages
|
|
448
|
+
* map. The result is clamped between `minReasoningBudget` (default 1024) and
|
|
449
|
+
* `maxReasoningBudget`. Pushes an unsupported warning if the level is not
|
|
450
|
+
* present in the budget percentages map.
|
|
451
|
+
*
|
|
452
|
+
* @returns The computed token budget, or `undefined` if the level is not
|
|
453
|
+
* supported.
|
|
454
|
+
*/
|
|
455
|
+
declare function mapReasoningToProviderBudget({ reasoning, maxOutputTokens, maxReasoningBudget, minReasoningBudget, budgetPercentages, warnings, }: {
|
|
456
|
+
reasoning: ReasoningLevel;
|
|
457
|
+
maxOutputTokens: number;
|
|
458
|
+
maxReasoningBudget: number;
|
|
459
|
+
minReasoningBudget?: number;
|
|
460
|
+
budgetPercentages?: Partial<Record<ReasoningLevel, number>>;
|
|
461
|
+
warnings: SharedV4Warning[];
|
|
462
|
+
}): number | undefined;
|
|
463
|
+
|
|
429
464
|
/**
|
|
430
465
|
* Loads an optional `string` setting from the environment or a parameter.
|
|
431
466
|
*
|
|
@@ -1469,4 +1504,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1469
1504
|
*/
|
|
1470
1505
|
type ToolCallOptions = ToolExecutionOptions;
|
|
1471
1506
|
|
|
1472
|
-
export { type AssistantContent, type AssistantModelMessage, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
|
1507
|
+
export { type AssistantContent, type AssistantModelMessage, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isCustomReasoning, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, ImageModelV4File, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV4Prompt, SharedV4ProviderOptions, TypeValidationContext } from '@ai-sdk/provider';
|
|
1
|
+
import { LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, ImageModelV4File, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV4Prompt, LanguageModelV4CallOptions, SharedV4Warning, SharedV4ProviderOptions, TypeValidationContext } from '@ai-sdk/provider';
|
|
2
2
|
import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
|
|
3
3
|
export * from '@standard-schema/spec';
|
|
4
4
|
import * as z3 from 'zod/v3';
|
|
@@ -426,6 +426,41 @@ declare function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterNa
|
|
|
426
426
|
description: string;
|
|
427
427
|
}): string;
|
|
428
428
|
|
|
429
|
+
type ReasoningLevel = Exclude<LanguageModelV4CallOptions['reasoning'], 'none' | 'provider-default' | undefined>;
|
|
430
|
+
declare function isCustomReasoning(reasoning: LanguageModelV4CallOptions['reasoning']): reasoning is Exclude<LanguageModelV4CallOptions['reasoning'], 'provider-default' | undefined>;
|
|
431
|
+
/**
|
|
432
|
+
* Maps a top-level reasoning level to a provider-specific effort string using
|
|
433
|
+
* the given effort map. Pushes a compatibility warning if the reasoning level
|
|
434
|
+
* maps to a different string, or an unsupported warning if the level is not
|
|
435
|
+
* present in the map.
|
|
436
|
+
*
|
|
437
|
+
* @returns The mapped effort string, or `undefined` if the level is not
|
|
438
|
+
* supported.
|
|
439
|
+
*/
|
|
440
|
+
declare function mapReasoningToProviderEffort<T extends string>({ reasoning, effortMap, warnings, }: {
|
|
441
|
+
reasoning: ReasoningLevel;
|
|
442
|
+
effortMap: Partial<Record<ReasoningLevel, T>>;
|
|
443
|
+
warnings: SharedV4Warning[];
|
|
444
|
+
}): T | undefined;
|
|
445
|
+
/**
|
|
446
|
+
* Maps a top-level reasoning level to an absolute token budget by multiplying
|
|
447
|
+
* the model's max output tokens by a percentage from the budget percentages
|
|
448
|
+
* map. The result is clamped between `minReasoningBudget` (default 1024) and
|
|
449
|
+
* `maxReasoningBudget`. Pushes an unsupported warning if the level is not
|
|
450
|
+
* present in the budget percentages map.
|
|
451
|
+
*
|
|
452
|
+
* @returns The computed token budget, or `undefined` if the level is not
|
|
453
|
+
* supported.
|
|
454
|
+
*/
|
|
455
|
+
declare function mapReasoningToProviderBudget({ reasoning, maxOutputTokens, maxReasoningBudget, minReasoningBudget, budgetPercentages, warnings, }: {
|
|
456
|
+
reasoning: ReasoningLevel;
|
|
457
|
+
maxOutputTokens: number;
|
|
458
|
+
maxReasoningBudget: number;
|
|
459
|
+
minReasoningBudget?: number;
|
|
460
|
+
budgetPercentages?: Partial<Record<ReasoningLevel, number>>;
|
|
461
|
+
warnings: SharedV4Warning[];
|
|
462
|
+
}): number | undefined;
|
|
463
|
+
|
|
429
464
|
/**
|
|
430
465
|
* Loads an optional `string` setting from the environment or a parameter.
|
|
431
466
|
*
|
|
@@ -1469,4 +1504,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1469
1504
|
*/
|
|
1470
1505
|
type ToolCallOptions = ToolExecutionOptions;
|
|
1471
1506
|
|
|
1472
|
-
export { type AssistantContent, type AssistantModelMessage, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
|
1507
|
+
export { type AssistantContent, type AssistantModelMessage, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isCustomReasoning, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.js
CHANGED
|
@@ -63,6 +63,7 @@ __export(index_exports, {
|
|
|
63
63
|
getRuntimeEnvironmentUserAgent: () => getRuntimeEnvironmentUserAgent,
|
|
64
64
|
injectJsonInstructionIntoMessages: () => injectJsonInstructionIntoMessages,
|
|
65
65
|
isAbortError: () => isAbortError,
|
|
66
|
+
isCustomReasoning: () => isCustomReasoning,
|
|
66
67
|
isNonNullable: () => isNonNullable,
|
|
67
68
|
isParsableJson: () => isParsableJson,
|
|
68
69
|
isUrlSupported: () => isUrlSupported,
|
|
@@ -71,6 +72,8 @@ __export(index_exports, {
|
|
|
71
72
|
loadApiKey: () => loadApiKey,
|
|
72
73
|
loadOptionalSetting: () => loadOptionalSetting,
|
|
73
74
|
loadSetting: () => loadSetting,
|
|
75
|
+
mapReasoningToProviderBudget: () => mapReasoningToProviderBudget,
|
|
76
|
+
mapReasoningToProviderEffort: () => mapReasoningToProviderEffort,
|
|
74
77
|
mediaTypeToExtension: () => mediaTypeToExtension,
|
|
75
78
|
normalizeHeaders: () => normalizeHeaders,
|
|
76
79
|
parseJSON: () => parseJSON,
|
|
@@ -390,10 +393,13 @@ function validateDownloadUrl(url) {
|
|
|
390
393
|
message: `Invalid URL: ${url}`
|
|
391
394
|
});
|
|
392
395
|
}
|
|
396
|
+
if (parsed.protocol === "data:") {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
393
399
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
394
400
|
throw new DownloadError({
|
|
395
401
|
url,
|
|
396
|
-
message: `URL scheme must be http or
|
|
402
|
+
message: `URL scheme must be http, https, or data, got ${parsed.protocol}`
|
|
397
403
|
});
|
|
398
404
|
}
|
|
399
405
|
const hostname = parsed.hostname;
|
|
@@ -670,7 +676,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
670
676
|
}
|
|
671
677
|
|
|
672
678
|
// src/version.ts
|
|
673
|
-
var VERSION = true ? "5.0.0-beta.
|
|
679
|
+
var VERSION = true ? "5.0.0-beta.6" : "0.0.0-test";
|
|
674
680
|
|
|
675
681
|
// src/get-from-api.ts
|
|
676
682
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -835,6 +841,63 @@ function loadApiKey({
|
|
|
835
841
|
return apiKey;
|
|
836
842
|
}
|
|
837
843
|
|
|
844
|
+
// src/map-reasoning-to-provider.ts
|
|
845
|
+
function isCustomReasoning(reasoning) {
|
|
846
|
+
return reasoning !== void 0 && reasoning !== "provider-default";
|
|
847
|
+
}
|
|
848
|
+
function mapReasoningToProviderEffort({
|
|
849
|
+
reasoning,
|
|
850
|
+
effortMap,
|
|
851
|
+
warnings
|
|
852
|
+
}) {
|
|
853
|
+
const mapped = effortMap[reasoning];
|
|
854
|
+
if (mapped == null) {
|
|
855
|
+
warnings.push({
|
|
856
|
+
type: "unsupported",
|
|
857
|
+
feature: "reasoning",
|
|
858
|
+
details: `reasoning "${reasoning}" is not supported by this model.`
|
|
859
|
+
});
|
|
860
|
+
return void 0;
|
|
861
|
+
}
|
|
862
|
+
if (mapped !== reasoning) {
|
|
863
|
+
warnings.push({
|
|
864
|
+
type: "compatibility",
|
|
865
|
+
feature: "reasoning",
|
|
866
|
+
details: `reasoning "${reasoning}" is not directly supported by this model. mapped to effort "${mapped}".`
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
return mapped;
|
|
870
|
+
}
|
|
871
|
+
var DEFAULT_REASONING_BUDGET_PERCENTAGES = {
|
|
872
|
+
minimal: 0.02,
|
|
873
|
+
low: 0.1,
|
|
874
|
+
medium: 0.3,
|
|
875
|
+
high: 0.6,
|
|
876
|
+
xhigh: 0.9
|
|
877
|
+
};
|
|
878
|
+
function mapReasoningToProviderBudget({
|
|
879
|
+
reasoning,
|
|
880
|
+
maxOutputTokens,
|
|
881
|
+
maxReasoningBudget,
|
|
882
|
+
minReasoningBudget = 1024,
|
|
883
|
+
budgetPercentages = DEFAULT_REASONING_BUDGET_PERCENTAGES,
|
|
884
|
+
warnings
|
|
885
|
+
}) {
|
|
886
|
+
const pct = budgetPercentages[reasoning];
|
|
887
|
+
if (pct == null) {
|
|
888
|
+
warnings.push({
|
|
889
|
+
type: "unsupported",
|
|
890
|
+
feature: "reasoning",
|
|
891
|
+
details: `reasoning "${reasoning}" is not supported by this model.`
|
|
892
|
+
});
|
|
893
|
+
return void 0;
|
|
894
|
+
}
|
|
895
|
+
return Math.min(
|
|
896
|
+
maxReasoningBudget,
|
|
897
|
+
Math.max(minReasoningBudget, Math.round(maxOutputTokens * pct))
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
|
|
838
901
|
// src/load-optional-setting.ts
|
|
839
902
|
function loadOptionalSetting({
|
|
840
903
|
settingValue,
|
|
@@ -2810,6 +2873,7 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
2810
2873
|
getRuntimeEnvironmentUserAgent,
|
|
2811
2874
|
injectJsonInstructionIntoMessages,
|
|
2812
2875
|
isAbortError,
|
|
2876
|
+
isCustomReasoning,
|
|
2813
2877
|
isNonNullable,
|
|
2814
2878
|
isParsableJson,
|
|
2815
2879
|
isUrlSupported,
|
|
@@ -2818,6 +2882,8 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
2818
2882
|
loadApiKey,
|
|
2819
2883
|
loadOptionalSetting,
|
|
2820
2884
|
loadSetting,
|
|
2885
|
+
mapReasoningToProviderBudget,
|
|
2886
|
+
mapReasoningToProviderEffort,
|
|
2821
2887
|
mediaTypeToExtension,
|
|
2822
2888
|
normalizeHeaders,
|
|
2823
2889
|
parseJSON,
|