@ai-sdk/openai 4.0.108 → 4.0.109
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 +31 -0
- package/dist/index.d.ts +67 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +620 -378
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +244 -4
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +481 -345
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +156 -18
- package/package.json +3 -3
- package/src/chat/convert-to-openai-chat-messages.ts +29 -4
- package/src/chat/openai-chat-language-model-options.ts +13 -0
- package/src/chat/openai-chat-language-model.ts +10 -10
- package/src/chat/openai-chat-prompt.ts +4 -0
- package/src/image/openai-image-model-options.ts +48 -0
- package/src/image/openai-image-model.ts +49 -4
- package/src/index.ts +1 -0
- package/src/internal/index.ts +2 -0
- package/src/live/openai-realtime-model-live.ts +21 -2
- package/src/openai-model-catalog.ts +3 -1
- package/src/openai-tools.ts +4 -3
- package/src/realtime/openai-realtime-event-mapper.ts +172 -11
- package/src/realtime/openai-realtime-model.ts +57 -3
- package/src/responses/openai-responses-api.ts +19 -1
- package/src/responses/openai-responses-prepare-tools.ts +18 -1
- package/src/tool/code-interpreter.ts +38 -2
- package/src/tool/mcp.ts +27 -8
- package/src/transcription/openai-transcription-model.ts +43 -8
package/dist/internal/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { APICallError, InvalidPromptError, InvalidResponseDataError, TooManyEmbeddingValuesForCallError, UnsupportedFunctionalityError, isJSONObject } from "@ai-sdk/provider";
|
|
1
|
+
import { APICallError, InvalidArgumentError, InvalidPromptError, InvalidResponseDataError, TooManyEmbeddingValuesForCallError, UnsupportedFunctionalityError, isJSONObject } from "@ai-sdk/provider";
|
|
2
2
|
import { EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, StreamingToolCallTracker, WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, connectToWebSocket, convertBase64ToUint8Array, convertToBase64, convertToFormData, createBinaryResponseHandler, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createLanguageModelResponseMetadata, createLanguageModelResponseMetadata as getResponseMetadata, createNullLanguageModelUsage, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, downloadBlob, experimental_toolCaller, generateId, getTopLevelMediaType, isCustomReasoning, isNonNullable, isRecord, lazySchema, mapReasoningToProviderEffort, mediaTypeToExtension, parseJSON, parseProviderOptions, postFormDataToApi, postJsonToApi, resolve, resolveFullMediaType, resolveProviderReference, safeParseJSON, safeValidateTypes, secureJsonParse, serializeModelOptions, stringifyWithBigIntAndCycles, toWebSocketUrl, validateTypes, waitForWebSocketBufferDrain, zodSchema } from "@ai-sdk/provider-utils";
|
|
3
3
|
import { z } from "zod/v4";
|
|
4
4
|
//#region src/openai-error.ts
|
|
@@ -263,6 +263,8 @@ function createGptImageEntry(sizes) {
|
|
|
263
263
|
};
|
|
264
264
|
}
|
|
265
265
|
const openaiImageModelEntries = {
|
|
266
|
+
"gpt-image-2.6-flare": createGptImageEntry(customImageSizes),
|
|
267
|
+
"gpt-image-2.6-sunburst": createGptImageEntry(customImageSizes),
|
|
266
268
|
"gpt-image-2.5-flare": createGptImageEntry(customImageSizes),
|
|
267
269
|
"gpt-image-2.5-sunburst": createGptImageEntry(customImageSizes),
|
|
268
270
|
"gpt-image-2": createGptImageEntry(gptImageSizes),
|
|
@@ -453,7 +455,7 @@ const realtimeModelEntries = {
|
|
|
453
455
|
capabilities: { realtime: {
|
|
454
456
|
conversation: "turn-based",
|
|
455
457
|
transports: ["websocket"],
|
|
456
|
-
connections: ["client-secret-websocket"]
|
|
458
|
+
connections: ["client-secret-websocket", "server-websocket"]
|
|
457
459
|
} },
|
|
458
460
|
requestConfig: { realtime: {
|
|
459
461
|
api: "realtime",
|
|
@@ -716,6 +718,158 @@ function convertOpenAIChatUsage(usage) {
|
|
|
716
718
|
};
|
|
717
719
|
}
|
|
718
720
|
//#endregion
|
|
721
|
+
//#region src/chat/openai-chat-language-model-options.ts
|
|
722
|
+
const openaiLanguageModelChatOptions = lazySchema(() => zodSchema(z.object({
|
|
723
|
+
/**
|
|
724
|
+
* Modify the likelihood of specified tokens appearing in the completion.
|
|
725
|
+
*
|
|
726
|
+
* Accepts a JSON object that maps tokens (specified by their token ID in
|
|
727
|
+
* the GPT tokenizer) to an associated bias value from -100 to 100.
|
|
728
|
+
*/
|
|
729
|
+
logitBias: z.record(z.coerce.number(), z.number()).optional(),
|
|
730
|
+
/**
|
|
731
|
+
* Return the log probabilities of the tokens.
|
|
732
|
+
*
|
|
733
|
+
* Setting to true will return the log probabilities of the tokens that
|
|
734
|
+
* were generated.
|
|
735
|
+
*
|
|
736
|
+
* Setting to a number will return the log probabilities of the top n
|
|
737
|
+
* tokens that were generated.
|
|
738
|
+
*/
|
|
739
|
+
logprobs: z.union([z.boolean(), z.number()]).optional(),
|
|
740
|
+
/**
|
|
741
|
+
* Whether to enable parallel function calling during tool use. Default to true.
|
|
742
|
+
*/
|
|
743
|
+
parallelToolCalls: z.boolean().optional(),
|
|
744
|
+
/**
|
|
745
|
+
* A unique identifier representing your end-user, which can help OpenAI to
|
|
746
|
+
* monitor and detect abuse.
|
|
747
|
+
*/
|
|
748
|
+
user: z.string().optional(),
|
|
749
|
+
/**
|
|
750
|
+
* Reasoning effort for reasoning models. Defaults to `medium`.
|
|
751
|
+
*/
|
|
752
|
+
reasoningEffort: z.enum([
|
|
753
|
+
"none",
|
|
754
|
+
"minimal",
|
|
755
|
+
"low",
|
|
756
|
+
"medium",
|
|
757
|
+
"high",
|
|
758
|
+
"xhigh",
|
|
759
|
+
"max"
|
|
760
|
+
]).optional(),
|
|
761
|
+
/**
|
|
762
|
+
* Maximum number of completion tokens to generate. Useful for reasoning models.
|
|
763
|
+
*/
|
|
764
|
+
maxCompletionTokens: z.number().optional(),
|
|
765
|
+
/**
|
|
766
|
+
* Whether to enable persistence in responses API.
|
|
767
|
+
*/
|
|
768
|
+
store: z.boolean().optional(),
|
|
769
|
+
/**
|
|
770
|
+
* Metadata to associate with the request.
|
|
771
|
+
*/
|
|
772
|
+
metadata: z.record(z.string().max(64), z.string().max(512)).optional(),
|
|
773
|
+
/**
|
|
774
|
+
* Parameters for prediction mode.
|
|
775
|
+
*/
|
|
776
|
+
prediction: z.record(z.string(), z.any()).optional(),
|
|
777
|
+
/**
|
|
778
|
+
* Service tier for the request.
|
|
779
|
+
* - 'auto': Default service tier. The request will be processed with the service tier configured in the
|
|
780
|
+
* Project settings. Unless otherwise configured, the Project will use 'default'.
|
|
781
|
+
* - 'flex': 50% cheaper processing at the cost of increased latency. Only available for o3 and o4-mini models.
|
|
782
|
+
* - 'priority': Higher-speed processing with predictably low latency at premium cost. Available for Enterprise customers.
|
|
783
|
+
* - 'fast': OpenAI's newer name for the 'priority' tier. Interchangeable with it.
|
|
784
|
+
* - 'ultrafast': Access-controlled Ultrafast processing. Only available for gpt-5.6-sol.
|
|
785
|
+
* - 'default': The request will be processed with the standard pricing and performance for the selected model.
|
|
786
|
+
*
|
|
787
|
+
* @default 'auto'
|
|
788
|
+
*/
|
|
789
|
+
serviceTier: z.enum([
|
|
790
|
+
"auto",
|
|
791
|
+
"flex",
|
|
792
|
+
"priority",
|
|
793
|
+
"fast",
|
|
794
|
+
"ultrafast",
|
|
795
|
+
"default"
|
|
796
|
+
]).optional(),
|
|
797
|
+
/**
|
|
798
|
+
* Whether to use strict JSON schema validation.
|
|
799
|
+
*
|
|
800
|
+
* @default true
|
|
801
|
+
*/
|
|
802
|
+
strictJsonSchema: z.boolean().optional(),
|
|
803
|
+
/**
|
|
804
|
+
* Controls the verbosity of the model's responses.
|
|
805
|
+
* Lower values will result in more concise responses, while higher values will result in more verbose responses.
|
|
806
|
+
*/
|
|
807
|
+
textVerbosity: z.enum([
|
|
808
|
+
"low",
|
|
809
|
+
"medium",
|
|
810
|
+
"high"
|
|
811
|
+
]).optional(),
|
|
812
|
+
/**
|
|
813
|
+
* A cache key for prompt caching. Allows manual control over prompt caching behavior.
|
|
814
|
+
* Useful for improving cache hit rates and working around automatic caching issues.
|
|
815
|
+
*/
|
|
816
|
+
promptCacheKey: z.string().optional(),
|
|
817
|
+
/**
|
|
818
|
+
* Prompt cache behavior for GPT-5.6 and later models.
|
|
819
|
+
* `mode` controls whether OpenAI also places an implicit breakpoint.
|
|
820
|
+
* `ttl` sets the minimum cache lifetime and currently only supports 30 minutes.
|
|
821
|
+
*/
|
|
822
|
+
promptCacheOptions: z.object({
|
|
823
|
+
mode: z.enum(["implicit", "explicit"]).optional(),
|
|
824
|
+
ttl: z.literal("30m").optional()
|
|
825
|
+
}).optional(),
|
|
826
|
+
/**
|
|
827
|
+
* The retention policy for the prompt cache.
|
|
828
|
+
* - 'in_memory': Default. Standard prompt caching behavior.
|
|
829
|
+
* - '24h': Extended prompt caching that keeps cached prefixes active for up to 24 hours.
|
|
830
|
+
* Available for models before GPT-5.6 that support extended caching.
|
|
831
|
+
*
|
|
832
|
+
* @deprecated For GPT-5.6 and later models, use `promptCacheOptions.ttl`.
|
|
833
|
+
*
|
|
834
|
+
* @default 'in_memory'
|
|
835
|
+
*/
|
|
836
|
+
promptCacheRetention: z.enum(["in_memory", "24h"]).optional(),
|
|
837
|
+
/**
|
|
838
|
+
* A stable identifier used to help detect users of your application
|
|
839
|
+
* that may be violating OpenAI's usage policies. The IDs should be a
|
|
840
|
+
* string that uniquely identifies each user. We recommend hashing their
|
|
841
|
+
* username or email address, in order to avoid sending us any identifying
|
|
842
|
+
* information.
|
|
843
|
+
*/
|
|
844
|
+
safetyIdentifier: z.string().optional(),
|
|
845
|
+
/**
|
|
846
|
+
* Override the system message mode for this model.
|
|
847
|
+
* - 'system': Use the 'system' role for system messages (default for most models)
|
|
848
|
+
* - 'developer': Use the 'developer' role for system messages (used by reasoning models)
|
|
849
|
+
* - 'remove': Remove system messages entirely
|
|
850
|
+
*
|
|
851
|
+
* If not specified, the mode is automatically determined based on the model.
|
|
852
|
+
*/
|
|
853
|
+
systemMessageMode: z.enum([
|
|
854
|
+
"system",
|
|
855
|
+
"developer",
|
|
856
|
+
"remove"
|
|
857
|
+
]).optional(),
|
|
858
|
+
/**
|
|
859
|
+
* Force treating this model as a reasoning model.
|
|
860
|
+
*
|
|
861
|
+
* This is useful for "stealth" reasoning models (e.g. via a custom baseURL)
|
|
862
|
+
* where the model ID is not recognized by the SDK's allowlist.
|
|
863
|
+
*
|
|
864
|
+
* When enabled, the SDK applies reasoning-model parameter compatibility rules
|
|
865
|
+
* and defaults `systemMessageMode` to `developer` unless overridden.
|
|
866
|
+
*/
|
|
867
|
+
forceReasoning: z.boolean().optional()
|
|
868
|
+
})));
|
|
869
|
+
const openaiChatMessageProviderOptions = lazySchema(() => zodSchema(z.object({
|
|
870
|
+
/** The participant name on a system, developer, user, or assistant message. */
|
|
871
|
+
name: z.string().optional() })));
|
|
872
|
+
//#endregion
|
|
719
873
|
//#region src/chat/convert-to-openai-chat-messages.ts
|
|
720
874
|
function serializeToolCallArguments$1(input) {
|
|
721
875
|
if (typeof input === "string") try {
|
|
@@ -730,197 +884,213 @@ function serializeToolCallArguments$1(input) {
|
|
|
730
884
|
function getPromptCacheBreakpoint$1(providerOptions) {
|
|
731
885
|
return providerOptions?.openai?.promptCacheBreakpoint;
|
|
732
886
|
}
|
|
733
|
-
function convertToOpenAIChatMessages({ prompt, systemMessageMode = "system" }) {
|
|
887
|
+
async function convertToOpenAIChatMessages({ prompt, systemMessageMode = "system" }) {
|
|
734
888
|
const messages = [];
|
|
735
889
|
const warnings = [];
|
|
736
|
-
for (const { role, content, providerOptions } of prompt)
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
890
|
+
for (const { role, content, providerOptions } of prompt) {
|
|
891
|
+
const name = (await parseProviderOptions({
|
|
892
|
+
provider: "openai",
|
|
893
|
+
providerOptions,
|
|
894
|
+
schema: openaiChatMessageProviderOptions
|
|
895
|
+
}))?.name;
|
|
896
|
+
switch (role) {
|
|
897
|
+
case "system":
|
|
898
|
+
switch (systemMessageMode) {
|
|
899
|
+
case "system": {
|
|
900
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint$1(providerOptions);
|
|
901
|
+
messages.push({
|
|
902
|
+
role: "system",
|
|
903
|
+
...name != null && { name },
|
|
904
|
+
content: promptCacheBreakpoint == null ? content : [{
|
|
905
|
+
type: "text",
|
|
906
|
+
text: content,
|
|
907
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
908
|
+
}]
|
|
909
|
+
});
|
|
910
|
+
break;
|
|
911
|
+
}
|
|
912
|
+
case "developer": {
|
|
913
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint$1(providerOptions);
|
|
914
|
+
messages.push({
|
|
915
|
+
role: "developer",
|
|
916
|
+
...name != null && { name },
|
|
917
|
+
content: promptCacheBreakpoint == null ? content : [{
|
|
918
|
+
type: "text",
|
|
919
|
+
text: content,
|
|
920
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
921
|
+
}]
|
|
922
|
+
});
|
|
923
|
+
break;
|
|
924
|
+
}
|
|
925
|
+
case "remove":
|
|
926
|
+
warnings.push({
|
|
927
|
+
type: "other",
|
|
928
|
+
message: "system messages are removed for this model"
|
|
929
|
+
});
|
|
930
|
+
break;
|
|
931
|
+
default: throw new Error(`Unsupported system message mode: ${systemMessageMode}`);
|
|
750
932
|
}
|
|
751
|
-
|
|
752
|
-
|
|
933
|
+
break;
|
|
934
|
+
case "user":
|
|
935
|
+
if (content.length === 1 && content[0].type === "text" && getPromptCacheBreakpoint$1(content[0].providerOptions) == null) {
|
|
753
936
|
messages.push({
|
|
754
|
-
role: "
|
|
755
|
-
content:
|
|
756
|
-
|
|
757
|
-
text: content,
|
|
758
|
-
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
759
|
-
}]
|
|
937
|
+
role: "user",
|
|
938
|
+
content: content[0].text,
|
|
939
|
+
...name != null && { name }
|
|
760
940
|
});
|
|
761
941
|
break;
|
|
762
942
|
}
|
|
763
|
-
case "remove":
|
|
764
|
-
warnings.push({
|
|
765
|
-
type: "other",
|
|
766
|
-
message: "system messages are removed for this model"
|
|
767
|
-
});
|
|
768
|
-
break;
|
|
769
|
-
default: throw new Error(`Unsupported system message mode: ${systemMessageMode}`);
|
|
770
|
-
}
|
|
771
|
-
break;
|
|
772
|
-
case "user":
|
|
773
|
-
if (content.length === 1 && content[0].type === "text" && getPromptCacheBreakpoint$1(content[0].providerOptions) == null) {
|
|
774
943
|
messages.push({
|
|
775
944
|
role: "user",
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
case "text": {
|
|
785
|
-
const promptCacheBreakpoint = getPromptCacheBreakpoint$1(part.providerOptions);
|
|
786
|
-
return {
|
|
787
|
-
type: "text",
|
|
788
|
-
text: part.text,
|
|
789
|
-
...promptCacheBreakpoint != null && { prompt_cache_breakpoint: promptCacheBreakpoint }
|
|
790
|
-
};
|
|
791
|
-
}
|
|
792
|
-
case "file": {
|
|
793
|
-
const promptCacheBreakpoint = getPromptCacheBreakpoint$1(part.providerOptions);
|
|
794
|
-
switch (part.data.type) {
|
|
795
|
-
case "reference": return {
|
|
796
|
-
type: "file",
|
|
797
|
-
file: { file_id: resolveProviderReference({
|
|
798
|
-
reference: part.data.reference,
|
|
799
|
-
provider: "openai"
|
|
800
|
-
}) },
|
|
945
|
+
...name != null && { name },
|
|
946
|
+
content: content.map((part, index) => {
|
|
947
|
+
switch (part.type) {
|
|
948
|
+
case "text": {
|
|
949
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint$1(part.providerOptions);
|
|
950
|
+
return {
|
|
951
|
+
type: "text",
|
|
952
|
+
text: part.text,
|
|
801
953
|
...promptCacheBreakpoint != null && { prompt_cache_breakpoint: promptCacheBreakpoint }
|
|
802
954
|
};
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
type: "
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
},
|
|
955
|
+
}
|
|
956
|
+
case "file": {
|
|
957
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint$1(part.providerOptions);
|
|
958
|
+
switch (part.data.type) {
|
|
959
|
+
case "reference": return {
|
|
960
|
+
type: "file",
|
|
961
|
+
file: { file_id: resolveProviderReference({
|
|
962
|
+
reference: part.data.reference,
|
|
963
|
+
provider: "openai"
|
|
964
|
+
}) },
|
|
813
965
|
...promptCacheBreakpoint != null && { prompt_cache_breakpoint: promptCacheBreakpoint }
|
|
814
966
|
};
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
967
|
+
case "text": throw new UnsupportedFunctionalityError({ functionality: "text file parts" });
|
|
968
|
+
case "url":
|
|
969
|
+
case "data": {
|
|
970
|
+
const topLevel = getTopLevelMediaType(part.mediaType);
|
|
971
|
+
if (topLevel === "image") return {
|
|
972
|
+
type: "image_url",
|
|
973
|
+
image_url: {
|
|
974
|
+
url: part.data.type === "url" ? part.data.url.toString() : `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`,
|
|
975
|
+
detail: part.providerOptions?.openai?.imageDetail
|
|
976
|
+
},
|
|
977
|
+
...promptCacheBreakpoint != null && { prompt_cache_breakpoint: promptCacheBreakpoint }
|
|
978
|
+
};
|
|
979
|
+
else if (topLevel === "audio") {
|
|
980
|
+
if (part.data.type === "url") throw new UnsupportedFunctionalityError({ functionality: "audio file parts with URLs" });
|
|
981
|
+
const fullMediaType = resolveFullMediaType({ part });
|
|
982
|
+
switch (fullMediaType) {
|
|
983
|
+
case "audio/wav": return {
|
|
984
|
+
type: "input_audio",
|
|
985
|
+
input_audio: {
|
|
986
|
+
data: convertToBase64(part.data.data),
|
|
987
|
+
format: "wav"
|
|
988
|
+
},
|
|
989
|
+
...promptCacheBreakpoint != null && { prompt_cache_breakpoint: promptCacheBreakpoint }
|
|
990
|
+
};
|
|
991
|
+
case "audio/mp3":
|
|
992
|
+
case "audio/mpeg": return {
|
|
993
|
+
type: "input_audio",
|
|
994
|
+
input_audio: {
|
|
995
|
+
data: convertToBase64(part.data.data),
|
|
996
|
+
format: "mp3"
|
|
997
|
+
},
|
|
998
|
+
...promptCacheBreakpoint != null && { prompt_cache_breakpoint: promptCacheBreakpoint }
|
|
999
|
+
};
|
|
1000
|
+
default: throw new UnsupportedFunctionalityError({ functionality: `audio content parts with media type ${fullMediaType}` });
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
{
|
|
1004
|
+
const fullMediaType = resolveFullMediaType({ part });
|
|
1005
|
+
if (fullMediaType !== "application/pdf") throw new UnsupportedFunctionalityError({ functionality: `file part media type ${fullMediaType}` });
|
|
1006
|
+
if (part.data.type === "url") throw new UnsupportedFunctionalityError({ functionality: "PDF file parts with URLs" });
|
|
1007
|
+
return {
|
|
1008
|
+
type: "file",
|
|
1009
|
+
file: {
|
|
1010
|
+
filename: part.filename ?? `part-${index}.pdf`,
|
|
1011
|
+
file_data: `data:application/pdf;base64,${convertToBase64(part.data.data)}`
|
|
833
1012
|
},
|
|
834
1013
|
...promptCacheBreakpoint != null && { prompt_cache_breakpoint: promptCacheBreakpoint }
|
|
835
1014
|
};
|
|
836
|
-
default: throw new UnsupportedFunctionalityError({ functionality: `audio content parts with media type ${fullMediaType}` });
|
|
837
1015
|
}
|
|
838
1016
|
}
|
|
839
|
-
{
|
|
840
|
-
const fullMediaType = resolveFullMediaType({ part });
|
|
841
|
-
if (fullMediaType !== "application/pdf") throw new UnsupportedFunctionalityError({ functionality: `file part media type ${fullMediaType}` });
|
|
842
|
-
if (part.data.type === "url") throw new UnsupportedFunctionalityError({ functionality: "PDF file parts with URLs" });
|
|
843
|
-
return {
|
|
844
|
-
type: "file",
|
|
845
|
-
file: {
|
|
846
|
-
filename: part.filename ?? `part-${index}.pdf`,
|
|
847
|
-
file_data: `data:application/pdf;base64,${convertToBase64(part.data.data)}`
|
|
848
|
-
},
|
|
849
|
-
...promptCacheBreakpoint != null && { prompt_cache_breakpoint: promptCacheBreakpoint }
|
|
850
|
-
};
|
|
851
|
-
}
|
|
852
1017
|
}
|
|
853
1018
|
}
|
|
854
1019
|
}
|
|
855
|
-
}
|
|
856
|
-
})
|
|
857
|
-
});
|
|
858
|
-
break;
|
|
859
|
-
case "assistant": {
|
|
860
|
-
let text = "";
|
|
861
|
-
const textParts = [];
|
|
862
|
-
let hasPromptCacheBreakpoint = false;
|
|
863
|
-
const toolCalls = [];
|
|
864
|
-
for (const part of content) switch (part.type) {
|
|
865
|
-
case "text": {
|
|
866
|
-
const promptCacheBreakpoint = getPromptCacheBreakpoint$1(part.providerOptions);
|
|
867
|
-
text += part.text;
|
|
868
|
-
textParts.push({
|
|
869
|
-
type: "text",
|
|
870
|
-
text: part.text,
|
|
871
|
-
...promptCacheBreakpoint != null && { prompt_cache_breakpoint: promptCacheBreakpoint }
|
|
872
|
-
});
|
|
873
|
-
hasPromptCacheBreakpoint ||= promptCacheBreakpoint != null;
|
|
874
|
-
break;
|
|
875
|
-
}
|
|
876
|
-
case "tool-call": toolCalls.push({
|
|
877
|
-
id: part.toolCallId,
|
|
878
|
-
type: "function",
|
|
879
|
-
function: {
|
|
880
|
-
name: part.toolName,
|
|
881
|
-
arguments: serializeToolCallArguments$1(part.input)
|
|
882
|
-
}
|
|
1020
|
+
})
|
|
883
1021
|
});
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
contentValue = output.value;
|
|
901
|
-
break;
|
|
902
|
-
case "error-text":
|
|
903
|
-
case "error-json":
|
|
904
|
-
contentValue = stringifyWithBigIntAndCycles({ error: output.value });
|
|
905
|
-
break;
|
|
906
|
-
case "execution-denied":
|
|
907
|
-
contentValue = output.reason ?? "Tool call execution denied.";
|
|
1022
|
+
break;
|
|
1023
|
+
case "assistant": {
|
|
1024
|
+
let text = "";
|
|
1025
|
+
const textParts = [];
|
|
1026
|
+
let hasPromptCacheBreakpoint = false;
|
|
1027
|
+
const toolCalls = [];
|
|
1028
|
+
for (const part of content) switch (part.type) {
|
|
1029
|
+
case "text": {
|
|
1030
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint$1(part.providerOptions);
|
|
1031
|
+
text += part.text;
|
|
1032
|
+
textParts.push({
|
|
1033
|
+
type: "text",
|
|
1034
|
+
text: part.text,
|
|
1035
|
+
...promptCacheBreakpoint != null && { prompt_cache_breakpoint: promptCacheBreakpoint }
|
|
1036
|
+
});
|
|
1037
|
+
hasPromptCacheBreakpoint ||= promptCacheBreakpoint != null;
|
|
908
1038
|
break;
|
|
909
|
-
|
|
910
|
-
case "
|
|
1039
|
+
}
|
|
1040
|
+
case "tool-call": toolCalls.push({
|
|
1041
|
+
id: part.toolCallId,
|
|
1042
|
+
type: "function",
|
|
1043
|
+
function: {
|
|
1044
|
+
name: part.toolName,
|
|
1045
|
+
arguments: serializeToolCallArguments$1(part.input)
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
911
1048
|
}
|
|
912
1049
|
messages.push({
|
|
913
|
-
role: "
|
|
914
|
-
|
|
915
|
-
content:
|
|
916
|
-
|
|
917
|
-
text: contentValue,
|
|
918
|
-
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
919
|
-
}]
|
|
1050
|
+
role: "assistant",
|
|
1051
|
+
...name != null && { name },
|
|
1052
|
+
content: hasPromptCacheBreakpoint ? textParts : toolCalls.length > 0 ? text || null : text,
|
|
1053
|
+
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
920
1054
|
});
|
|
1055
|
+
break;
|
|
921
1056
|
}
|
|
922
|
-
|
|
923
|
-
|
|
1057
|
+
case "tool":
|
|
1058
|
+
if (name != null) warnings.push({
|
|
1059
|
+
type: "unsupported",
|
|
1060
|
+
feature: "message name on tool messages"
|
|
1061
|
+
});
|
|
1062
|
+
for (const toolResponse of content) {
|
|
1063
|
+
if (toolResponse.type === "tool-approval-response") continue;
|
|
1064
|
+
const output = toolResponse.output;
|
|
1065
|
+
const promptCacheBreakpoint = (output.type === "content" ? output.value.map((part) => getPromptCacheBreakpoint$1(part.providerOptions)).find((breakpoint) => breakpoint != null) : getPromptCacheBreakpoint$1(output.providerOptions)) ?? getPromptCacheBreakpoint$1(toolResponse.providerOptions);
|
|
1066
|
+
let contentValue;
|
|
1067
|
+
switch (output.type) {
|
|
1068
|
+
case "text":
|
|
1069
|
+
contentValue = output.value;
|
|
1070
|
+
break;
|
|
1071
|
+
case "error-text":
|
|
1072
|
+
case "error-json":
|
|
1073
|
+
contentValue = stringifyWithBigIntAndCycles({ error: output.value });
|
|
1074
|
+
break;
|
|
1075
|
+
case "execution-denied":
|
|
1076
|
+
contentValue = output.reason ?? "Tool call execution denied.";
|
|
1077
|
+
break;
|
|
1078
|
+
case "content":
|
|
1079
|
+
case "json": contentValue = stringifyWithBigIntAndCycles(output.value);
|
|
1080
|
+
}
|
|
1081
|
+
messages.push({
|
|
1082
|
+
role: "tool",
|
|
1083
|
+
tool_call_id: toolResponse.toolCallId,
|
|
1084
|
+
content: promptCacheBreakpoint == null ? contentValue : [{
|
|
1085
|
+
type: "text",
|
|
1086
|
+
text: contentValue,
|
|
1087
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
1088
|
+
}]
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
break;
|
|
1092
|
+
default: throw new Error(`Unsupported role: ${role}`);
|
|
1093
|
+
}
|
|
924
1094
|
}
|
|
925
1095
|
return {
|
|
926
1096
|
messages,
|
|
@@ -1057,155 +1227,6 @@ const openaiChatChunkSchema = lazySchema(() => zodSchema(z.union([z.object({
|
|
|
1057
1227
|
}).nullish()
|
|
1058
1228
|
}), openaiErrorDataSchema()])));
|
|
1059
1229
|
//#endregion
|
|
1060
|
-
//#region src/chat/openai-chat-language-model-options.ts
|
|
1061
|
-
const openaiLanguageModelChatOptions = lazySchema(() => zodSchema(z.object({
|
|
1062
|
-
/**
|
|
1063
|
-
* Modify the likelihood of specified tokens appearing in the completion.
|
|
1064
|
-
*
|
|
1065
|
-
* Accepts a JSON object that maps tokens (specified by their token ID in
|
|
1066
|
-
* the GPT tokenizer) to an associated bias value from -100 to 100.
|
|
1067
|
-
*/
|
|
1068
|
-
logitBias: z.record(z.coerce.number(), z.number()).optional(),
|
|
1069
|
-
/**
|
|
1070
|
-
* Return the log probabilities of the tokens.
|
|
1071
|
-
*
|
|
1072
|
-
* Setting to true will return the log probabilities of the tokens that
|
|
1073
|
-
* were generated.
|
|
1074
|
-
*
|
|
1075
|
-
* Setting to a number will return the log probabilities of the top n
|
|
1076
|
-
* tokens that were generated.
|
|
1077
|
-
*/
|
|
1078
|
-
logprobs: z.union([z.boolean(), z.number()]).optional(),
|
|
1079
|
-
/**
|
|
1080
|
-
* Whether to enable parallel function calling during tool use. Default to true.
|
|
1081
|
-
*/
|
|
1082
|
-
parallelToolCalls: z.boolean().optional(),
|
|
1083
|
-
/**
|
|
1084
|
-
* A unique identifier representing your end-user, which can help OpenAI to
|
|
1085
|
-
* monitor and detect abuse.
|
|
1086
|
-
*/
|
|
1087
|
-
user: z.string().optional(),
|
|
1088
|
-
/**
|
|
1089
|
-
* Reasoning effort for reasoning models. Defaults to `medium`.
|
|
1090
|
-
*/
|
|
1091
|
-
reasoningEffort: z.enum([
|
|
1092
|
-
"none",
|
|
1093
|
-
"minimal",
|
|
1094
|
-
"low",
|
|
1095
|
-
"medium",
|
|
1096
|
-
"high",
|
|
1097
|
-
"xhigh",
|
|
1098
|
-
"max"
|
|
1099
|
-
]).optional(),
|
|
1100
|
-
/**
|
|
1101
|
-
* Maximum number of completion tokens to generate. Useful for reasoning models.
|
|
1102
|
-
*/
|
|
1103
|
-
maxCompletionTokens: z.number().optional(),
|
|
1104
|
-
/**
|
|
1105
|
-
* Whether to enable persistence in responses API.
|
|
1106
|
-
*/
|
|
1107
|
-
store: z.boolean().optional(),
|
|
1108
|
-
/**
|
|
1109
|
-
* Metadata to associate with the request.
|
|
1110
|
-
*/
|
|
1111
|
-
metadata: z.record(z.string().max(64), z.string().max(512)).optional(),
|
|
1112
|
-
/**
|
|
1113
|
-
* Parameters for prediction mode.
|
|
1114
|
-
*/
|
|
1115
|
-
prediction: z.record(z.string(), z.any()).optional(),
|
|
1116
|
-
/**
|
|
1117
|
-
* Service tier for the request.
|
|
1118
|
-
* - 'auto': Default service tier. The request will be processed with the service tier configured in the
|
|
1119
|
-
* Project settings. Unless otherwise configured, the Project will use 'default'.
|
|
1120
|
-
* - 'flex': 50% cheaper processing at the cost of increased latency. Only available for o3 and o4-mini models.
|
|
1121
|
-
* - 'priority': Higher-speed processing with predictably low latency at premium cost. Available for Enterprise customers.
|
|
1122
|
-
* - 'fast': OpenAI's newer name for the 'priority' tier. Interchangeable with it.
|
|
1123
|
-
* - 'ultrafast': Access-controlled Ultrafast processing. Only available for gpt-5.6-sol.
|
|
1124
|
-
* - 'default': The request will be processed with the standard pricing and performance for the selected model.
|
|
1125
|
-
*
|
|
1126
|
-
* @default 'auto'
|
|
1127
|
-
*/
|
|
1128
|
-
serviceTier: z.enum([
|
|
1129
|
-
"auto",
|
|
1130
|
-
"flex",
|
|
1131
|
-
"priority",
|
|
1132
|
-
"fast",
|
|
1133
|
-
"ultrafast",
|
|
1134
|
-
"default"
|
|
1135
|
-
]).optional(),
|
|
1136
|
-
/**
|
|
1137
|
-
* Whether to use strict JSON schema validation.
|
|
1138
|
-
*
|
|
1139
|
-
* @default true
|
|
1140
|
-
*/
|
|
1141
|
-
strictJsonSchema: z.boolean().optional(),
|
|
1142
|
-
/**
|
|
1143
|
-
* Controls the verbosity of the model's responses.
|
|
1144
|
-
* Lower values will result in more concise responses, while higher values will result in more verbose responses.
|
|
1145
|
-
*/
|
|
1146
|
-
textVerbosity: z.enum([
|
|
1147
|
-
"low",
|
|
1148
|
-
"medium",
|
|
1149
|
-
"high"
|
|
1150
|
-
]).optional(),
|
|
1151
|
-
/**
|
|
1152
|
-
* A cache key for prompt caching. Allows manual control over prompt caching behavior.
|
|
1153
|
-
* Useful for improving cache hit rates and working around automatic caching issues.
|
|
1154
|
-
*/
|
|
1155
|
-
promptCacheKey: z.string().optional(),
|
|
1156
|
-
/**
|
|
1157
|
-
* Prompt cache behavior for GPT-5.6 and later models.
|
|
1158
|
-
* `mode` controls whether OpenAI also places an implicit breakpoint.
|
|
1159
|
-
* `ttl` sets the minimum cache lifetime and currently only supports 30 minutes.
|
|
1160
|
-
*/
|
|
1161
|
-
promptCacheOptions: z.object({
|
|
1162
|
-
mode: z.enum(["implicit", "explicit"]).optional(),
|
|
1163
|
-
ttl: z.literal("30m").optional()
|
|
1164
|
-
}).optional(),
|
|
1165
|
-
/**
|
|
1166
|
-
* The retention policy for the prompt cache.
|
|
1167
|
-
* - 'in_memory': Default. Standard prompt caching behavior.
|
|
1168
|
-
* - '24h': Extended prompt caching that keeps cached prefixes active for up to 24 hours.
|
|
1169
|
-
* Available for models before GPT-5.6 that support extended caching.
|
|
1170
|
-
*
|
|
1171
|
-
* @deprecated For GPT-5.6 and later models, use `promptCacheOptions.ttl`.
|
|
1172
|
-
*
|
|
1173
|
-
* @default 'in_memory'
|
|
1174
|
-
*/
|
|
1175
|
-
promptCacheRetention: z.enum(["in_memory", "24h"]).optional(),
|
|
1176
|
-
/**
|
|
1177
|
-
* A stable identifier used to help detect users of your application
|
|
1178
|
-
* that may be violating OpenAI's usage policies. The IDs should be a
|
|
1179
|
-
* string that uniquely identifies each user. We recommend hashing their
|
|
1180
|
-
* username or email address, in order to avoid sending us any identifying
|
|
1181
|
-
* information.
|
|
1182
|
-
*/
|
|
1183
|
-
safetyIdentifier: z.string().optional(),
|
|
1184
|
-
/**
|
|
1185
|
-
* Override the system message mode for this model.
|
|
1186
|
-
* - 'system': Use the 'system' role for system messages (default for most models)
|
|
1187
|
-
* - 'developer': Use the 'developer' role for system messages (used by reasoning models)
|
|
1188
|
-
* - 'remove': Remove system messages entirely
|
|
1189
|
-
*
|
|
1190
|
-
* If not specified, the mode is automatically determined based on the model.
|
|
1191
|
-
*/
|
|
1192
|
-
systemMessageMode: z.enum([
|
|
1193
|
-
"system",
|
|
1194
|
-
"developer",
|
|
1195
|
-
"remove"
|
|
1196
|
-
]).optional(),
|
|
1197
|
-
/**
|
|
1198
|
-
* Force treating this model as a reasoning model.
|
|
1199
|
-
*
|
|
1200
|
-
* This is useful for "stealth" reasoning models (e.g. via a custom baseURL)
|
|
1201
|
-
* where the model ID is not recognized by the SDK's allowlist.
|
|
1202
|
-
*
|
|
1203
|
-
* When enabled, the SDK applies reasoning-model parameter compatibility rules
|
|
1204
|
-
* and defaults `systemMessageMode` to `developer` unless overridden.
|
|
1205
|
-
*/
|
|
1206
|
-
forceReasoning: z.boolean().optional()
|
|
1207
|
-
})));
|
|
1208
|
-
//#endregion
|
|
1209
1230
|
//#region src/normalize-openai-json-schema.ts
|
|
1210
1231
|
/**
|
|
1211
1232
|
* Normalizes JSON Schema for OpenAI structured outputs.
|
|
@@ -1444,7 +1465,7 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1444
1465
|
feature: "reasoningSummary",
|
|
1445
1466
|
details: "reasoningSummary is only supported by the Responses API, not the Chat Completions API"
|
|
1446
1467
|
});
|
|
1447
|
-
const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages({
|
|
1468
|
+
const { messages, warnings: messageWarnings } = await convertToOpenAIChatMessages({
|
|
1448
1469
|
prompt,
|
|
1449
1470
|
systemMessageMode: openaiOptions.systemMessageMode ?? (isReasoningModel ? "developer" : modelRequestConfig.systemMessageMode)
|
|
1450
1471
|
});
|
|
@@ -1597,11 +1618,12 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1597
1618
|
}
|
|
1598
1619
|
async doGenerate(options) {
|
|
1599
1620
|
const { args: body, warnings } = await this.getArgs(options);
|
|
1621
|
+
const url = this.config.url({
|
|
1622
|
+
path: "/chat/completions",
|
|
1623
|
+
modelId: this.config.requestModelId ?? this.modelId
|
|
1624
|
+
});
|
|
1600
1625
|
const { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
|
|
1601
|
-
url
|
|
1602
|
-
path: "/chat/completions",
|
|
1603
|
-
modelId: this.config.requestModelId ?? this.modelId
|
|
1604
|
-
}),
|
|
1626
|
+
url,
|
|
1605
1627
|
headers: combineHeaders(await resolve(this.config.headers), options.headers),
|
|
1606
1628
|
body,
|
|
1607
1629
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
@@ -1645,7 +1667,10 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1645
1667
|
raw: choice.finish_reason ?? void 0
|
|
1646
1668
|
},
|
|
1647
1669
|
usage: convertOpenAIChatUsage(response.usage),
|
|
1648
|
-
request: {
|
|
1670
|
+
request: {
|
|
1671
|
+
body,
|
|
1672
|
+
url
|
|
1673
|
+
},
|
|
1649
1674
|
response: {
|
|
1650
1675
|
...getResponseMetadata$1(response),
|
|
1651
1676
|
headers: responseHeaders,
|
|
@@ -1792,7 +1817,10 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1792
1817
|
});
|
|
1793
1818
|
}
|
|
1794
1819
|
})),
|
|
1795
|
-
request: {
|
|
1820
|
+
request: {
|
|
1821
|
+
body,
|
|
1822
|
+
url
|
|
1823
|
+
},
|
|
1796
1824
|
response: { headers: responseHeaders }
|
|
1797
1825
|
};
|
|
1798
1826
|
}
|
|
@@ -2343,6 +2371,15 @@ const baseImageModelOptionsObject = () => z.object({
|
|
|
2343
2371
|
"webp"
|
|
2344
2372
|
]).optional(),
|
|
2345
2373
|
/**
|
|
2374
|
+
* How much detail the model puts into the image. Supported by GPT Image
|
|
2375
|
+
* 2.6 models. The API defaults to `high`.
|
|
2376
|
+
*/
|
|
2377
|
+
complexity: z.enum([
|
|
2378
|
+
"low",
|
|
2379
|
+
"medium",
|
|
2380
|
+
"high"
|
|
2381
|
+
]).optional(),
|
|
2382
|
+
/**
|
|
2346
2383
|
* Compression level (0-100) for the generated image(s). Applies to the
|
|
2347
2384
|
* `jpeg` and `webp` output formats.
|
|
2348
2385
|
*/
|
|
@@ -2351,7 +2388,13 @@ const baseImageModelOptionsObject = () => z.object({
|
|
|
2351
2388
|
* A unique identifier representing your end-user, which can help OpenAI
|
|
2352
2389
|
* to monitor and detect abuse.
|
|
2353
2390
|
*/
|
|
2354
|
-
user: z.string().optional()
|
|
2391
|
+
user: z.string().optional(),
|
|
2392
|
+
/**
|
|
2393
|
+
* A stable identifier used to help detect users of your application that
|
|
2394
|
+
* may be violating OpenAI's usage policies. Should be a hashed username
|
|
2395
|
+
* or email address.
|
|
2396
|
+
*/
|
|
2397
|
+
safetyIdentifier: z.string().max(128).optional()
|
|
2355
2398
|
});
|
|
2356
2399
|
const openaiImageModelOptions = lazySchema(() => zodSchema(baseImageModelOptionsObject()));
|
|
2357
2400
|
const openaiImageModelGenerationOptions = lazySchema(() => zodSchema(baseImageModelOptionsObject().extend({
|
|
@@ -2362,16 +2405,50 @@ const openaiImageModelGenerationOptions = lazySchema(() => zodSchema(baseImageMo
|
|
|
2362
2405
|
*/
|
|
2363
2406
|
style: z.enum(["vivid", "natural"]).optional(),
|
|
2364
2407
|
/**
|
|
2408
|
+
* Format in which the generated image(s) are returned. `gif` produces
|
|
2409
|
+
* an animated GIF and is supported by GPT Image 2.6 models.
|
|
2410
|
+
*/
|
|
2411
|
+
outputFormat: z.enum([
|
|
2412
|
+
"png",
|
|
2413
|
+
"jpeg",
|
|
2414
|
+
"webp",
|
|
2415
|
+
"gif"
|
|
2416
|
+
]).optional(),
|
|
2417
|
+
/**
|
|
2418
|
+
* Number of frames (2-64) of an animated GIF. Only applies to the `gif`
|
|
2419
|
+
* output format. The API defaults to 9.
|
|
2420
|
+
*/
|
|
2421
|
+
frameCount: z.number().int().min(2).max(64).optional(),
|
|
2422
|
+
/**
|
|
2423
|
+
* Duration of each frame in milliseconds (20-2000) of an animated GIF.
|
|
2424
|
+
* The API rounds it to the nearest 10 ms. Only applies to the `gif`
|
|
2425
|
+
* output format. The API defaults to 200.
|
|
2426
|
+
*/
|
|
2427
|
+
frameDurationMs: z.number().int().min(20).max(2e3).optional(),
|
|
2428
|
+
/**
|
|
2365
2429
|
* Content moderation level for the generated image(s). `low` applies
|
|
2366
2430
|
* less restrictive filtering.
|
|
2367
2431
|
*/
|
|
2368
2432
|
moderation: z.enum(["auto", "low"]).optional()
|
|
2369
2433
|
})));
|
|
2370
|
-
const openaiImageModelEditOptions = lazySchema(() => zodSchema(baseImageModelOptionsObject().extend({
|
|
2371
|
-
/**
|
|
2372
|
-
* Fidelity of the output image(s) to the input image(s).
|
|
2373
|
-
*/
|
|
2374
|
-
inputFidelity: z.enum(["high", "low"]).optional()
|
|
2434
|
+
const openaiImageModelEditOptions = lazySchema(() => zodSchema(baseImageModelOptionsObject().extend({
|
|
2435
|
+
/**
|
|
2436
|
+
* Fidelity of the output image(s) to the input image(s).
|
|
2437
|
+
*/
|
|
2438
|
+
inputFidelity: z.enum(["high", "low"]).optional(),
|
|
2439
|
+
/**
|
|
2440
|
+
* A transparent PNG overlaid on the first input image to mark up the
|
|
2441
|
+
* regions to change, as an HTTPS URL or a base64 data URL. It must match
|
|
2442
|
+
* the dimensions of the first image. Supported by GPT Image 2.5 and 2.6
|
|
2443
|
+
* models. Cannot be combined with a `mask`.
|
|
2444
|
+
*/
|
|
2445
|
+
markup: z.string().optional(),
|
|
2446
|
+
/**
|
|
2447
|
+
* Content moderation level for the edited image(s). `low` applies
|
|
2448
|
+
* less restrictive filtering. Supported by GPT Image models.
|
|
2449
|
+
*/
|
|
2450
|
+
moderation: z.enum(["auto", "low"]).optional()
|
|
2451
|
+
})));
|
|
2375
2452
|
//#endregion
|
|
2376
2453
|
//#region src/image/openai-image-model.ts
|
|
2377
2454
|
var OpenAIImageModel = class OpenAIImageModel {
|
|
@@ -2423,6 +2500,10 @@ var OpenAIImageModel = class OpenAIImageModel {
|
|
|
2423
2500
|
providerOptions,
|
|
2424
2501
|
schema: openaiImageModelEditOptions
|
|
2425
2502
|
}) ?? {};
|
|
2503
|
+
if (mask != null && openaiOptions.markup != null) throw new InvalidArgumentError({
|
|
2504
|
+
argument: "providerOptions.openai.markup",
|
|
2505
|
+
message: "`markup` cannot be combined with `mask`."
|
|
2506
|
+
});
|
|
2426
2507
|
const { value: response, responseHeaders } = await postFormDataToApi({
|
|
2427
2508
|
url: this.config.url({
|
|
2428
2509
|
path: "/images/edits",
|
|
@@ -2434,14 +2515,18 @@ var OpenAIImageModel = class OpenAIImageModel {
|
|
|
2434
2515
|
prompt,
|
|
2435
2516
|
image: await Promise.all(files.map((file) => file.type === "file" ? new Blob([file.data instanceof Uint8Array ? new Blob([file.data], { type: file.mediaType }) : new Blob([convertBase64ToUint8Array(file.data)], { type: file.mediaType })], { type: file.mediaType }) : downloadBlob(file.url, { abortSignal }))),
|
|
2436
2517
|
mask: mask != null ? await fileToBlob(mask, abortSignal) : void 0,
|
|
2518
|
+
markup: openaiOptions.markup != null ? await markupToBlob(openaiOptions.markup, abortSignal) : void 0,
|
|
2437
2519
|
n,
|
|
2438
2520
|
size,
|
|
2439
2521
|
quality: openaiOptions.quality,
|
|
2440
2522
|
background: openaiOptions.background,
|
|
2441
2523
|
output_format: openaiOptions.outputFormat,
|
|
2442
2524
|
output_compression: openaiOptions.outputCompression,
|
|
2525
|
+
complexity: openaiOptions.complexity,
|
|
2443
2526
|
input_fidelity: openaiOptions.inputFidelity,
|
|
2444
|
-
|
|
2527
|
+
moderation: openaiOptions.moderation,
|
|
2528
|
+
user: openaiOptions.user,
|
|
2529
|
+
safety_identifier: openaiOptions.safetyIdentifier
|
|
2445
2530
|
}),
|
|
2446
2531
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2447
2532
|
successfulResponseHandler: createJsonResponseHandler(openaiImageResponseSchema),
|
|
@@ -2494,7 +2579,11 @@ var OpenAIImageModel = class OpenAIImageModel {
|
|
|
2494
2579
|
moderation: openaiOptions.moderation,
|
|
2495
2580
|
output_format: openaiOptions.outputFormat,
|
|
2496
2581
|
output_compression: openaiOptions.outputCompression,
|
|
2582
|
+
complexity: openaiOptions.complexity,
|
|
2583
|
+
frame_count: openaiOptions.frameCount,
|
|
2584
|
+
frame_duration_ms: openaiOptions.frameDurationMs,
|
|
2497
2585
|
user: openaiOptions.user,
|
|
2586
|
+
safety_identifier: openaiOptions.safetyIdentifier,
|
|
2498
2587
|
...!hasDefaultResponseFormat(this.modelId) ? { response_format: "b64_json" } : {}
|
|
2499
2588
|
},
|
|
2500
2589
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
@@ -2547,6 +2636,15 @@ function distributeTokenDetails(details, index, total) {
|
|
|
2547
2636
|
}
|
|
2548
2637
|
return result;
|
|
2549
2638
|
}
|
|
2639
|
+
async function markupToBlob(markup, abortSignal) {
|
|
2640
|
+
const dataUrl = /^data:([^;,]*)(;base64)?,(.*)$/s.exec(markup);
|
|
2641
|
+
if (dataUrl == null) return downloadBlob(markup, { abortSignal });
|
|
2642
|
+
if (dataUrl[2] == null) throw new InvalidArgumentError({
|
|
2643
|
+
argument: "providerOptions.openai.markup",
|
|
2644
|
+
message: "`markup` data URLs must be base64 encoded."
|
|
2645
|
+
});
|
|
2646
|
+
return new Blob([convertBase64ToUint8Array(dataUrl[3])], { type: dataUrl[1] || "image/png" });
|
|
2647
|
+
}
|
|
2550
2648
|
async function fileToBlob(file, abortSignal) {
|
|
2551
2649
|
if (!file) return void 0;
|
|
2552
2650
|
if (file.type === "url") return downloadBlob(file.url, { abortSignal });
|
|
@@ -2740,7 +2838,7 @@ var OpenAITranscriptionModel = class OpenAITranscriptionModel {
|
|
|
2740
2838
|
this.config = config;
|
|
2741
2839
|
this.specificationVersion = "v4";
|
|
2742
2840
|
}
|
|
2743
|
-
async getArgs({ audio, mediaType, providerOptions }) {
|
|
2841
|
+
async getArgs({ audio, mediaType, providerOptions, timestampGranularities: requestedTimestampGranularities }) {
|
|
2744
2842
|
const warnings = [];
|
|
2745
2843
|
const openAIOptions = await parseProviderOptions({
|
|
2746
2844
|
provider: "openai",
|
|
@@ -2754,7 +2852,17 @@ var OpenAITranscriptionModel = class OpenAITranscriptionModel {
|
|
|
2754
2852
|
formData.append("file", new File([blob], "audio", { type: mediaType }), `audio.${fileExtension}`);
|
|
2755
2853
|
const { transcription: requestConfig } = getOpenAITranscriptionModelEntry(this.modelId).requestConfig;
|
|
2756
2854
|
const responseFormat = openAIOptions?.responseFormat ?? requestConfig.responseFormat;
|
|
2757
|
-
const timestampGranularities = openAIOptions?.timestampGranularities ?? (responseFormat === "verbose_json" ? ["segment"] : void 0);
|
|
2855
|
+
const timestampGranularities = openAIOptions?.timestampGranularities ?? requestedTimestampGranularities ?? (responseFormat === "verbose_json" ? ["segment"] : void 0);
|
|
2856
|
+
for (const granularity of requestedTimestampGranularities ?? []) if (openAIOptions?.timestampGranularities != null && !openAIOptions.timestampGranularities.includes(granularity)) warnings.push({
|
|
2857
|
+
type: "unsupported",
|
|
2858
|
+
feature: "timestampGranularities",
|
|
2859
|
+
details: `The "${granularity}" timestamp granularity is excluded by providerOptions.openai.timestampGranularities.`
|
|
2860
|
+
});
|
|
2861
|
+
for (const granularity of timestampGranularities ?? []) if (responseFormat !== "verbose_json" && !(responseFormat === "diarized_json" && granularity === "segment")) warnings.push({
|
|
2862
|
+
type: "unsupported",
|
|
2863
|
+
feature: openAIOptions?.timestampGranularities != null ? "providerOptions.openai.timestampGranularities" : "timestampGranularities",
|
|
2864
|
+
details: `OpenAI transcription with the ${responseFormat ?? "default JSON"} response format does not support ${granularity} timestamps.`
|
|
2865
|
+
});
|
|
2758
2866
|
const chunkingStrategy = openAIOptions?.chunkingStrategy ?? requestConfig.chunkingStrategy;
|
|
2759
2867
|
const transcriptionModelOptions = {
|
|
2760
2868
|
response_format: responseFormat,
|
|
@@ -2764,7 +2872,7 @@ var OpenAITranscriptionModel = class OpenAITranscriptionModel {
|
|
|
2764
2872
|
keywords: openAIOptions?.keywords,
|
|
2765
2873
|
prompt: openAIOptions?.prompt,
|
|
2766
2874
|
temperature: openAIOptions?.temperature,
|
|
2767
|
-
timestamp_granularities: timestampGranularities
|
|
2875
|
+
timestamp_granularities: responseFormat === "verbose_json" ? timestampGranularities : void 0
|
|
2768
2876
|
};
|
|
2769
2877
|
for (const [key, value] of Object.entries(transcriptionModelOptions)) if (value != null) {
|
|
2770
2878
|
if (Array.isArray(value)) for (const item of value) formData.append(`${key}[]`, String(item));
|
|
@@ -2804,17 +2912,19 @@ var OpenAITranscriptionModel = class OpenAITranscriptionModel {
|
|
|
2804
2912
|
endSecond: segment.end,
|
|
2805
2913
|
speaker: segment.speaker
|
|
2806
2914
|
}] : []);
|
|
2915
|
+
const words = response.words?.map((word) => ({
|
|
2916
|
+
text: word.word,
|
|
2917
|
+
startSecond: word.start,
|
|
2918
|
+
endSecond: word.end
|
|
2919
|
+
}));
|
|
2807
2920
|
return {
|
|
2808
2921
|
text: response.text,
|
|
2809
2922
|
segments: response.segments?.map((segment) => ({
|
|
2810
2923
|
text: segment.text,
|
|
2811
2924
|
startSecond: segment.start,
|
|
2812
2925
|
endSecond: segment.end
|
|
2813
|
-
})) ??
|
|
2814
|
-
|
|
2815
|
-
startSecond: word.start,
|
|
2816
|
-
endSecond: word.end
|
|
2817
|
-
})) ?? [],
|
|
2926
|
+
})) ?? words ?? [],
|
|
2927
|
+
...words != null && words.length > 0 ? { words } : {},
|
|
2818
2928
|
language,
|
|
2819
2929
|
durationInSeconds: response.duration ?? (response.usage?.type === "duration" && typeof response.usage.seconds === "number" ? response.usage.seconds : void 0),
|
|
2820
2930
|
warnings,
|
|
@@ -3692,7 +3802,7 @@ const shellArgsSchema = lazySchema(() => zodSchema(z.object({ environment: z.uni
|
|
|
3692
3802
|
})).optional()
|
|
3693
3803
|
})
|
|
3694
3804
|
]).optional() })));
|
|
3695
|
-
createProviderDefinedToolFactoryWithOutputSchema({
|
|
3805
|
+
const shell = createProviderDefinedToolFactoryWithOutputSchema({
|
|
3696
3806
|
id: "openai.shell",
|
|
3697
3807
|
inputSchema: shellInputSchema,
|
|
3698
3808
|
outputSchema: shellOutputSchema
|
|
@@ -5996,7 +6106,24 @@ const codeInterpreterOutputSchema = lazySchema(() => zodSchema(z.object({ output
|
|
|
5996
6106
|
type: z.literal("image"),
|
|
5997
6107
|
url: z.string()
|
|
5998
6108
|
})])).nullish() })));
|
|
5999
|
-
const codeInterpreterArgsSchema = lazySchema(() => zodSchema(z.object({ container: z.union([z.string(), z.object({
|
|
6109
|
+
const codeInterpreterArgsSchema = lazySchema(() => zodSchema(z.object({ container: z.union([z.string(), z.object({
|
|
6110
|
+
fileIds: z.array(z.string()).optional(),
|
|
6111
|
+
memoryLimit: z.enum([
|
|
6112
|
+
"1g",
|
|
6113
|
+
"4g",
|
|
6114
|
+
"16g",
|
|
6115
|
+
"64g"
|
|
6116
|
+
]).optional(),
|
|
6117
|
+
networkPolicy: z.discriminatedUnion("type", [z.object({ type: z.literal("disabled") }), z.object({
|
|
6118
|
+
type: z.literal("allowlist"),
|
|
6119
|
+
allowedDomains: z.array(z.string()),
|
|
6120
|
+
domainSecrets: z.array(z.object({
|
|
6121
|
+
domain: z.string(),
|
|
6122
|
+
name: z.string(),
|
|
6123
|
+
value: z.string()
|
|
6124
|
+
})).optional()
|
|
6125
|
+
})]).optional()
|
|
6126
|
+
})]).optional() })));
|
|
6000
6127
|
const codeInterpreterToolFactory = createProviderExecutedToolFactory({
|
|
6001
6128
|
id: "openai.code_interpreter",
|
|
6002
6129
|
inputSchema: codeInterpreterInputSchema,
|
|
@@ -6119,10 +6246,11 @@ const customArgsSchema = lazySchema(() => zodSchema(z.object({
|
|
|
6119
6246
|
}), z.object({ type: z.literal("text") })]).optional()
|
|
6120
6247
|
})));
|
|
6121
6248
|
const customInputSchema = lazySchema(() => zodSchema(z.string()));
|
|
6122
|
-
createProviderDefinedToolFactory({
|
|
6249
|
+
const customToolFactory = createProviderDefinedToolFactory({
|
|
6123
6250
|
id: "openai.custom",
|
|
6124
6251
|
inputSchema: customInputSchema
|
|
6125
6252
|
});
|
|
6253
|
+
const customTool = (args) => customToolFactory(args);
|
|
6126
6254
|
//#endregion
|
|
6127
6255
|
//#region src/tool/mcp.ts
|
|
6128
6256
|
let cachedJsonValueSchema;
|
|
@@ -6145,8 +6273,9 @@ const mcpArgsSchema = lazySchema(() => zodSchema(z.object({
|
|
|
6145
6273
|
headers: z.record(z.string(), z.string()).optional(),
|
|
6146
6274
|
requireApproval: z.union([z.enum(["always", "never"]), z.object({ never: z.object({ toolNames: z.array(z.string()).optional() }).optional() })]).optional(),
|
|
6147
6275
|
serverDescription: z.string().optional(),
|
|
6148
|
-
serverUrl: z.string().optional()
|
|
6149
|
-
|
|
6276
|
+
serverUrl: z.string().optional(),
|
|
6277
|
+
tunnelId: z.string().optional()
|
|
6278
|
+
}).refine((v) => v.serverUrl != null || v.connectorId != null || v.tunnelId != null, "One of serverUrl, connectorId, or tunnelId must be provided.").refine((v) => v.tunnelId == null || v.serverUrl == null && v.connectorId == null, "tunnelId cannot be combined with serverUrl or connectorId.")));
|
|
6150
6279
|
const mcpInputSchema = lazySchema(() => zodSchema(z.object({})));
|
|
6151
6280
|
const mcpOutputSchema = lazySchema(() => zodSchema(z.object({
|
|
6152
6281
|
type: z.literal("call"),
|
|
@@ -6355,7 +6484,13 @@ async function prepareResponsesTools({ tools, toolChoice, allowedTools, toolName
|
|
|
6355
6484
|
file_ids: void 0
|
|
6356
6485
|
} : typeof args.container === "string" ? args.container : {
|
|
6357
6486
|
type: "auto",
|
|
6358
|
-
file_ids: args.container.fileIds
|
|
6487
|
+
file_ids: args.container.fileIds,
|
|
6488
|
+
memory_limit: args.container.memoryLimit,
|
|
6489
|
+
network_policy: args.container.networkPolicy == null ? void 0 : args.container.networkPolicy.type === "disabled" ? { type: "disabled" } : {
|
|
6490
|
+
type: "allowlist",
|
|
6491
|
+
allowed_domains: args.container.networkPolicy.allowedDomains,
|
|
6492
|
+
domain_secrets: args.container.networkPolicy.domainSecrets
|
|
6493
|
+
}
|
|
6359
6494
|
}
|
|
6360
6495
|
});
|
|
6361
6496
|
break;
|
|
@@ -6404,7 +6539,8 @@ async function prepareResponsesTools({ tools, toolChoice, allowedTools, toolName
|
|
|
6404
6539
|
headers: args.headers,
|
|
6405
6540
|
require_approval: requireApprovalParam ?? "never",
|
|
6406
6541
|
server_description: args.serverDescription,
|
|
6407
|
-
server_url: args.serverUrl
|
|
6542
|
+
server_url: args.serverUrl,
|
|
6543
|
+
tunnel_id: args.tunnelId
|
|
6408
6544
|
});
|
|
6409
6545
|
break;
|
|
6410
6546
|
}
|
|
@@ -8563,6 +8699,6 @@ function escapeJSONDelta(delta) {
|
|
|
8563
8699
|
return JSON.stringify(delta).slice(1, -1);
|
|
8564
8700
|
}
|
|
8565
8701
|
//#endregion
|
|
8566
|
-
export { OpenAIChatLanguageModel, OpenAICompletionLanguageModel, OpenAIEmbeddingModel, OpenAIImageModel, OpenAIResponsesLanguageModel, OpenAISpeechModel, OpenAITranscriptionModel, applyPatch, applyPatchArgsSchema, applyPatchInputSchema, applyPatchOutputSchema, applyPatchToolFactory, codeInterpreter, codeInterpreterArgsSchema, codeInterpreterInputSchema, codeInterpreterOutputSchema, codeInterpreterToolFactory, fileSearch, fileSearchArgsSchema, fileSearchOutputSchema, getMaxImagesPerCall, hasDefaultResponseFormat, imageGeneration, imageGenerationArgsSchema, imageGenerationOutputSchema, mapWebSearchResult, modelMaxImagesPerCall, openAITranscriptionModelOptions, openaiEmbeddingModelOptions, openaiImageModelEditOptions, openaiImageModelGenerationOptions, openaiImageModelOptions, openaiLanguageModelChatOptions, openaiLanguageModelCompletionOptions, openaiResponsesSupportedUrls, openaiSpeechModelOptionsSchema, programmaticToolCalling, programmaticToolCallingInputSchema, programmaticToolCallingOutputSchema, toolSearch, toolSearchArgsSchema, toolSearchInputSchema, toolSearchOutputSchema, webSearch, webSearchArgsSchema, webSearchOutputSchema, webSearchPreview, webSearchPreviewArgsSchema, webSearchPreviewInputSchema, webSearchToolFactory };
|
|
8702
|
+
export { OpenAIChatLanguageModel, OpenAICompletionLanguageModel, OpenAIEmbeddingModel, OpenAIImageModel, OpenAIResponsesLanguageModel, OpenAISpeechModel, OpenAITranscriptionModel, applyPatch, applyPatchArgsSchema, applyPatchInputSchema, applyPatchOutputSchema, applyPatchToolFactory, codeInterpreter, codeInterpreterArgsSchema, codeInterpreterInputSchema, codeInterpreterOutputSchema, codeInterpreterToolFactory, customArgsSchema, customTool, customToolFactory, fileSearch, fileSearchArgsSchema, fileSearchOutputSchema, getMaxImagesPerCall, hasDefaultResponseFormat, imageGeneration, imageGenerationArgsSchema, imageGenerationOutputSchema, mapWebSearchResult, modelMaxImagesPerCall, openAITranscriptionModelOptions, openaiChatMessageProviderOptions, openaiEmbeddingModelOptions, openaiImageModelEditOptions, openaiImageModelGenerationOptions, openaiImageModelOptions, openaiLanguageModelChatOptions, openaiLanguageModelCompletionOptions, openaiResponsesSupportedUrls, openaiSpeechModelOptionsSchema, programmaticToolCalling, programmaticToolCallingInputSchema, programmaticToolCallingOutputSchema, shell, shellArgsSchema, shellInputSchema, shellOutputSchema, toolSearch, toolSearchArgsSchema, toolSearchInputSchema, toolSearchOutputSchema, webSearch, webSearchArgsSchema, webSearchOutputSchema, webSearchPreview, webSearchPreviewArgsSchema, webSearchPreviewInputSchema, webSearchToolFactory };
|
|
8567
8703
|
|
|
8568
8704
|
//# sourceMappingURL=index.js.map
|