@ai-sdk/openai 4.0.0-beta.37 → 4.0.0-beta.39
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 +22 -0
- package/dist/index.d.ts +24 -10
- package/dist/index.js +37 -37
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +6 -6
- package/dist/internal/index.js +36 -36
- package/dist/internal/index.js.map +1 -1
- package/package.json +4 -3
- package/src/chat/convert-to-openai-chat-messages.ts +2 -2
- package/src/chat/openai-chat-language-model.ts +7 -9
- package/src/image/openai-image-options.ts +3 -0
- package/src/responses/convert-to-openai-responses-input.ts +2 -2
- package/src/tool/apply-patch.ts +33 -32
- package/src/tool/code-interpreter.ts +40 -41
- package/src/tool/custom.ts +2 -2
- package/src/tool/file-search.ts +2 -2
- package/src/tool/image-generation.ts +2 -2
- package/src/tool/local-shell.ts +2 -2
- package/src/tool/mcp.ts +2 -2
- package/src/tool/shell.ts +2 -2
- package/src/tool/tool-search.ts +2 -2
- package/src/tool/web-search-preview.ts +2 -2
- package/src/tool/web-search.ts +2 -2
package/dist/internal/index.d.ts
CHANGED
|
@@ -142,7 +142,7 @@ declare class OpenAIEmbeddingModel implements EmbeddingModelV4 {
|
|
|
142
142
|
doEmbed({ values, headers, abortSignal, providerOptions, }: Parameters<EmbeddingModelV4['doEmbed']>[0]): Promise<Awaited<ReturnType<EmbeddingModelV4['doEmbed']>>>;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
type OpenAIImageModelId = 'dall-e-3' | 'dall-e-2' | 'gpt-image-1' | 'gpt-image-1-mini' | 'gpt-image-1.5' | 'chatgpt-image-latest' | (string & {});
|
|
145
|
+
type OpenAIImageModelId = 'dall-e-3' | 'dall-e-2' | 'gpt-image-1' | 'gpt-image-1-mini' | 'gpt-image-1.5' | 'gpt-image-2' | 'chatgpt-image-latest' | (string & {});
|
|
146
146
|
declare const modelMaxImagesPerCall: Record<OpenAIImageModelId, number>;
|
|
147
147
|
declare function hasDefaultResponseFormat(modelId: string): boolean;
|
|
148
148
|
|
|
@@ -874,7 +874,7 @@ type ApplyPatchOperation = {
|
|
|
874
874
|
* - Returns the status of applying those patches (completed or failed)
|
|
875
875
|
*
|
|
876
876
|
*/
|
|
877
|
-
declare const applyPatchToolFactory: _ai_sdk_provider_utils.
|
|
877
|
+
declare const applyPatchToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<{
|
|
878
878
|
/**
|
|
879
879
|
* The unique ID of the apply patch tool call generated by the model.
|
|
880
880
|
*/
|
|
@@ -902,7 +902,7 @@ declare const applyPatchToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryW
|
|
|
902
902
|
* emits patch operations that your application applies and then reports back on,
|
|
903
903
|
* enabling iterative, multi-step code editing workflows.
|
|
904
904
|
*/
|
|
905
|
-
declare const applyPatch: _ai_sdk_provider_utils.
|
|
905
|
+
declare const applyPatch: _ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<{
|
|
906
906
|
/**
|
|
907
907
|
* The unique ID of the apply patch tool call generated by the model.
|
|
908
908
|
*/
|
|
@@ -953,7 +953,7 @@ type CodeInterpreterArgs = {
|
|
|
953
953
|
fileIds?: string[];
|
|
954
954
|
};
|
|
955
955
|
};
|
|
956
|
-
declare const codeInterpreterToolFactory: _ai_sdk_provider_utils.
|
|
956
|
+
declare const codeInterpreterToolFactory: _ai_sdk_provider_utils.ProviderExecutedToolFactory<{
|
|
957
957
|
/**
|
|
958
958
|
* The code to run, or null if not available.
|
|
959
959
|
*/
|
|
@@ -1029,7 +1029,7 @@ declare const fileSearchOutputSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
1029
1029
|
text: string;
|
|
1030
1030
|
}[] | null;
|
|
1031
1031
|
}>;
|
|
1032
|
-
declare const fileSearch: _ai_sdk_provider_utils.
|
|
1032
|
+
declare const fileSearch: _ai_sdk_provider_utils.ProviderExecutedToolFactory<{}, {
|
|
1033
1033
|
/**
|
|
1034
1034
|
* The search query to execute.
|
|
1035
1035
|
*/
|
|
@@ -1185,7 +1185,7 @@ declare const webSearchPreviewArgsSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
1185
1185
|
} | undefined;
|
|
1186
1186
|
}>;
|
|
1187
1187
|
declare const webSearchPreviewInputSchema: _ai_sdk_provider_utils.LazySchema<Record<string, never>>;
|
|
1188
|
-
declare const webSearchPreview: _ai_sdk_provider_utils.
|
|
1188
|
+
declare const webSearchPreview: _ai_sdk_provider_utils.ProviderExecutedToolFactory<{}, {
|
|
1189
1189
|
/**
|
|
1190
1190
|
* An object describing the specific action taken in this web search call.
|
|
1191
1191
|
* Includes details on how the model used the web (search, open_page, find_in_page).
|
package/dist/internal/index.js
CHANGED
|
@@ -248,7 +248,7 @@ function convertToOpenAIChatMessages({
|
|
|
248
248
|
}
|
|
249
249
|
messages.push({
|
|
250
250
|
role: "assistant",
|
|
251
|
-
content: text,
|
|
251
|
+
content: text || null,
|
|
252
252
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
253
253
|
});
|
|
254
254
|
break;
|
|
@@ -266,7 +266,7 @@ function convertToOpenAIChatMessages({
|
|
|
266
266
|
contentValue = output.value;
|
|
267
267
|
break;
|
|
268
268
|
case "execution-denied":
|
|
269
|
-
contentValue = (_a = output.reason) != null ? _a : "Tool execution denied.";
|
|
269
|
+
contentValue = (_a = output.reason) != null ? _a : "Tool call execution denied.";
|
|
270
270
|
break;
|
|
271
271
|
case "content":
|
|
272
272
|
case "json":
|
|
@@ -947,10 +947,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
947
947
|
abortSignal: options.abortSignal,
|
|
948
948
|
fetch: this.config.fetch
|
|
949
949
|
});
|
|
950
|
-
|
|
951
|
-
generateId,
|
|
952
|
-
typeValidation: "if-present"
|
|
953
|
-
});
|
|
950
|
+
let toolCallTracker;
|
|
954
951
|
let finishReason = {
|
|
955
952
|
unified: "other",
|
|
956
953
|
raw: void 0
|
|
@@ -963,6 +960,10 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
963
960
|
stream: response.pipeThrough(
|
|
964
961
|
new TransformStream({
|
|
965
962
|
start(controller) {
|
|
963
|
+
toolCallTracker = new StreamingToolCallTracker(controller, {
|
|
964
|
+
generateId,
|
|
965
|
+
typeValidation: "if-present"
|
|
966
|
+
});
|
|
966
967
|
controller.enqueue({ type: "stream-start", warnings });
|
|
967
968
|
},
|
|
968
969
|
transform(chunk, controller) {
|
|
@@ -1027,10 +1028,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1027
1028
|
}
|
|
1028
1029
|
if (delta.tool_calls != null) {
|
|
1029
1030
|
for (const toolCallDelta of delta.tool_calls) {
|
|
1030
|
-
toolCallTracker.processDelta(
|
|
1031
|
-
toolCallDelta,
|
|
1032
|
-
controller.enqueue.bind(controller)
|
|
1033
|
-
);
|
|
1031
|
+
toolCallTracker.processDelta(toolCallDelta);
|
|
1034
1032
|
}
|
|
1035
1033
|
}
|
|
1036
1034
|
if (delta.annotations != null) {
|
|
@@ -1049,7 +1047,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1049
1047
|
if (isActiveText) {
|
|
1050
1048
|
controller.enqueue({ type: "text-end", id: "0" });
|
|
1051
1049
|
}
|
|
1052
|
-
toolCallTracker.flush(
|
|
1050
|
+
toolCallTracker.flush();
|
|
1053
1051
|
controller.enqueue({
|
|
1054
1052
|
type: "finish",
|
|
1055
1053
|
finishReason,
|
|
@@ -1738,13 +1736,15 @@ var modelMaxImagesPerCall = {
|
|
|
1738
1736
|
"gpt-image-1": 10,
|
|
1739
1737
|
"gpt-image-1-mini": 10,
|
|
1740
1738
|
"gpt-image-1.5": 10,
|
|
1739
|
+
"gpt-image-2": 10,
|
|
1741
1740
|
"chatgpt-image-latest": 10
|
|
1742
1741
|
};
|
|
1743
1742
|
var defaultResponseFormatPrefixes = [
|
|
1744
1743
|
"chatgpt-image-",
|
|
1745
1744
|
"gpt-image-1-mini",
|
|
1746
1745
|
"gpt-image-1.5",
|
|
1747
|
-
"gpt-image-1"
|
|
1746
|
+
"gpt-image-1",
|
|
1747
|
+
"gpt-image-2"
|
|
1748
1748
|
];
|
|
1749
1749
|
function hasDefaultResponseFormat(modelId) {
|
|
1750
1750
|
return defaultResponseFormatPrefixes.some(
|
|
@@ -2416,7 +2416,7 @@ import { z as z16 } from "zod/v4";
|
|
|
2416
2416
|
|
|
2417
2417
|
// src/tool/apply-patch.ts
|
|
2418
2418
|
import {
|
|
2419
|
-
|
|
2419
|
+
createProviderDefinedToolFactoryWithOutputSchema,
|
|
2420
2420
|
lazySchema as lazySchema11,
|
|
2421
2421
|
zodSchema as zodSchema11
|
|
2422
2422
|
} from "@ai-sdk/provider-utils";
|
|
@@ -2453,7 +2453,7 @@ var applyPatchOutputSchema = lazySchema11(
|
|
|
2453
2453
|
)
|
|
2454
2454
|
);
|
|
2455
2455
|
var applyPatchArgsSchema = lazySchema11(() => zodSchema11(z12.object({})));
|
|
2456
|
-
var applyPatchToolFactory =
|
|
2456
|
+
var applyPatchToolFactory = createProviderDefinedToolFactoryWithOutputSchema({
|
|
2457
2457
|
id: "openai.apply_patch",
|
|
2458
2458
|
inputSchema: applyPatchInputSchema,
|
|
2459
2459
|
outputSchema: applyPatchOutputSchema
|
|
@@ -2462,7 +2462,7 @@ var applyPatch = applyPatchToolFactory;
|
|
|
2462
2462
|
|
|
2463
2463
|
// src/tool/local-shell.ts
|
|
2464
2464
|
import {
|
|
2465
|
-
|
|
2465
|
+
createProviderDefinedToolFactoryWithOutputSchema as createProviderDefinedToolFactoryWithOutputSchema2,
|
|
2466
2466
|
lazySchema as lazySchema12,
|
|
2467
2467
|
zodSchema as zodSchema12
|
|
2468
2468
|
} from "@ai-sdk/provider-utils";
|
|
@@ -2484,7 +2484,7 @@ var localShellInputSchema = lazySchema12(
|
|
|
2484
2484
|
var localShellOutputSchema = lazySchema12(
|
|
2485
2485
|
() => zodSchema12(z13.object({ output: z13.string() }))
|
|
2486
2486
|
);
|
|
2487
|
-
var localShell =
|
|
2487
|
+
var localShell = createProviderDefinedToolFactoryWithOutputSchema2({
|
|
2488
2488
|
id: "openai.local_shell",
|
|
2489
2489
|
inputSchema: localShellInputSchema,
|
|
2490
2490
|
outputSchema: localShellOutputSchema
|
|
@@ -2492,7 +2492,7 @@ var localShell = createProviderToolFactoryWithOutputSchema2({
|
|
|
2492
2492
|
|
|
2493
2493
|
// src/tool/shell.ts
|
|
2494
2494
|
import {
|
|
2495
|
-
|
|
2495
|
+
createProviderDefinedToolFactoryWithOutputSchema as createProviderDefinedToolFactoryWithOutputSchema3,
|
|
2496
2496
|
lazySchema as lazySchema13,
|
|
2497
2497
|
zodSchema as zodSchema13
|
|
2498
2498
|
} from "@ai-sdk/provider-utils";
|
|
@@ -2585,7 +2585,7 @@ var shellArgsSchema = lazySchema13(
|
|
|
2585
2585
|
})
|
|
2586
2586
|
)
|
|
2587
2587
|
);
|
|
2588
|
-
var shell =
|
|
2588
|
+
var shell = createProviderDefinedToolFactoryWithOutputSchema3({
|
|
2589
2589
|
id: "openai.shell",
|
|
2590
2590
|
inputSchema: shellInputSchema,
|
|
2591
2591
|
outputSchema: shellOutputSchema
|
|
@@ -2593,7 +2593,7 @@ var shell = createProviderToolFactoryWithOutputSchema3({
|
|
|
2593
2593
|
|
|
2594
2594
|
// src/tool/tool-search.ts
|
|
2595
2595
|
import {
|
|
2596
|
-
|
|
2596
|
+
createProviderDefinedToolFactoryWithOutputSchema as createProviderDefinedToolFactoryWithOutputSchema4,
|
|
2597
2597
|
lazySchema as lazySchema14,
|
|
2598
2598
|
zodSchema as zodSchema14
|
|
2599
2599
|
} from "@ai-sdk/provider-utils";
|
|
@@ -2622,7 +2622,7 @@ var toolSearchOutputSchema = lazySchema14(
|
|
|
2622
2622
|
})
|
|
2623
2623
|
)
|
|
2624
2624
|
);
|
|
2625
|
-
var toolSearchToolFactory =
|
|
2625
|
+
var toolSearchToolFactory = createProviderDefinedToolFactoryWithOutputSchema4({
|
|
2626
2626
|
id: "openai.tool_search",
|
|
2627
2627
|
inputSchema: toolSearchInputSchema,
|
|
2628
2628
|
outputSchema: toolSearchOutputSchema
|
|
@@ -3136,7 +3136,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3136
3136
|
outputValue = output.value;
|
|
3137
3137
|
break;
|
|
3138
3138
|
case "execution-denied":
|
|
3139
|
-
outputValue = (_q = output.reason) != null ? _q : "Tool execution denied.";
|
|
3139
|
+
outputValue = (_q = output.reason) != null ? _q : "Tool call execution denied.";
|
|
3140
3140
|
break;
|
|
3141
3141
|
case "json":
|
|
3142
3142
|
case "error-json":
|
|
@@ -3197,7 +3197,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3197
3197
|
contentValue = output.value;
|
|
3198
3198
|
break;
|
|
3199
3199
|
case "execution-denied":
|
|
3200
|
-
contentValue = (_r = output.reason) != null ? _r : "Tool execution denied.";
|
|
3200
|
+
contentValue = (_r = output.reason) != null ? _r : "Tool call execution denied.";
|
|
3201
3201
|
break;
|
|
3202
3202
|
case "json":
|
|
3203
3203
|
case "error-json":
|
|
@@ -4398,7 +4398,7 @@ import {
|
|
|
4398
4398
|
|
|
4399
4399
|
// src/tool/code-interpreter.ts
|
|
4400
4400
|
import {
|
|
4401
|
-
|
|
4401
|
+
createProviderExecutedToolFactory,
|
|
4402
4402
|
lazySchema as lazySchema17,
|
|
4403
4403
|
zodSchema as zodSchema17
|
|
4404
4404
|
} from "@ai-sdk/provider-utils";
|
|
@@ -4435,7 +4435,7 @@ var codeInterpreterArgsSchema = lazySchema17(
|
|
|
4435
4435
|
})
|
|
4436
4436
|
)
|
|
4437
4437
|
);
|
|
4438
|
-
var codeInterpreterToolFactory =
|
|
4438
|
+
var codeInterpreterToolFactory = createProviderExecutedToolFactory({
|
|
4439
4439
|
id: "openai.code_interpreter",
|
|
4440
4440
|
inputSchema: codeInterpreterInputSchema,
|
|
4441
4441
|
outputSchema: codeInterpreterOutputSchema
|
|
@@ -4446,7 +4446,7 @@ var codeInterpreter = (args = {}) => {
|
|
|
4446
4446
|
|
|
4447
4447
|
// src/tool/file-search.ts
|
|
4448
4448
|
import {
|
|
4449
|
-
|
|
4449
|
+
createProviderExecutedToolFactory as createProviderExecutedToolFactory2,
|
|
4450
4450
|
lazySchema as lazySchema18,
|
|
4451
4451
|
zodSchema as zodSchema18
|
|
4452
4452
|
} from "@ai-sdk/provider-utils";
|
|
@@ -4491,7 +4491,7 @@ var fileSearchOutputSchema = lazySchema18(
|
|
|
4491
4491
|
})
|
|
4492
4492
|
)
|
|
4493
4493
|
);
|
|
4494
|
-
var fileSearch =
|
|
4494
|
+
var fileSearch = createProviderExecutedToolFactory2({
|
|
4495
4495
|
id: "openai.file_search",
|
|
4496
4496
|
inputSchema: z20.object({}),
|
|
4497
4497
|
outputSchema: fileSearchOutputSchema
|
|
@@ -4499,7 +4499,7 @@ var fileSearch = createProviderToolFactoryWithOutputSchema6({
|
|
|
4499
4499
|
|
|
4500
4500
|
// src/tool/image-generation.ts
|
|
4501
4501
|
import {
|
|
4502
|
-
|
|
4502
|
+
createProviderExecutedToolFactory as createProviderExecutedToolFactory3,
|
|
4503
4503
|
lazySchema as lazySchema19,
|
|
4504
4504
|
zodSchema as zodSchema19
|
|
4505
4505
|
} from "@ai-sdk/provider-utils";
|
|
@@ -4527,7 +4527,7 @@ var imageGenerationInputSchema = lazySchema19(() => zodSchema19(z21.object({})))
|
|
|
4527
4527
|
var imageGenerationOutputSchema = lazySchema19(
|
|
4528
4528
|
() => zodSchema19(z21.object({ result: z21.string() }))
|
|
4529
4529
|
);
|
|
4530
|
-
var imageGenerationToolFactory =
|
|
4530
|
+
var imageGenerationToolFactory = createProviderExecutedToolFactory3({
|
|
4531
4531
|
id: "openai.image_generation",
|
|
4532
4532
|
inputSchema: imageGenerationInputSchema,
|
|
4533
4533
|
outputSchema: imageGenerationOutputSchema
|
|
@@ -4538,7 +4538,7 @@ var imageGeneration = (args = {}) => {
|
|
|
4538
4538
|
|
|
4539
4539
|
// src/tool/custom.ts
|
|
4540
4540
|
import {
|
|
4541
|
-
|
|
4541
|
+
createProviderDefinedToolFactory,
|
|
4542
4542
|
lazySchema as lazySchema20,
|
|
4543
4543
|
zodSchema as zodSchema20
|
|
4544
4544
|
} from "@ai-sdk/provider-utils";
|
|
@@ -4561,14 +4561,14 @@ var customArgsSchema = lazySchema20(
|
|
|
4561
4561
|
)
|
|
4562
4562
|
);
|
|
4563
4563
|
var customInputSchema = lazySchema20(() => zodSchema20(z22.string()));
|
|
4564
|
-
var customToolFactory =
|
|
4564
|
+
var customToolFactory = createProviderDefinedToolFactory({
|
|
4565
4565
|
id: "openai.custom",
|
|
4566
4566
|
inputSchema: customInputSchema
|
|
4567
4567
|
});
|
|
4568
4568
|
|
|
4569
4569
|
// src/tool/mcp.ts
|
|
4570
4570
|
import {
|
|
4571
|
-
|
|
4571
|
+
createProviderExecutedToolFactory as createProviderExecutedToolFactory4,
|
|
4572
4572
|
lazySchema as lazySchema21,
|
|
4573
4573
|
zodSchema as zodSchema21
|
|
4574
4574
|
} from "@ai-sdk/provider-utils";
|
|
@@ -4626,7 +4626,7 @@ var mcpOutputSchema = lazySchema21(
|
|
|
4626
4626
|
})
|
|
4627
4627
|
)
|
|
4628
4628
|
);
|
|
4629
|
-
var mcpToolFactory =
|
|
4629
|
+
var mcpToolFactory = createProviderExecutedToolFactory4({
|
|
4630
4630
|
id: "openai.mcp",
|
|
4631
4631
|
inputSchema: mcpInputSchema,
|
|
4632
4632
|
outputSchema: mcpOutputSchema
|
|
@@ -4634,7 +4634,7 @@ var mcpToolFactory = createProviderToolFactoryWithOutputSchema8({
|
|
|
4634
4634
|
|
|
4635
4635
|
// src/tool/web-search.ts
|
|
4636
4636
|
import {
|
|
4637
|
-
|
|
4637
|
+
createProviderExecutedToolFactory as createProviderExecutedToolFactory5,
|
|
4638
4638
|
lazySchema as lazySchema22,
|
|
4639
4639
|
zodSchema as zodSchema22
|
|
4640
4640
|
} from "@ai-sdk/provider-utils";
|
|
@@ -4683,7 +4683,7 @@ var webSearchOutputSchema = lazySchema22(
|
|
|
4683
4683
|
})
|
|
4684
4684
|
)
|
|
4685
4685
|
);
|
|
4686
|
-
var webSearchToolFactory =
|
|
4686
|
+
var webSearchToolFactory = createProviderExecutedToolFactory5({
|
|
4687
4687
|
id: "openai.web_search",
|
|
4688
4688
|
inputSchema: webSearchInputSchema,
|
|
4689
4689
|
outputSchema: webSearchOutputSchema
|
|
@@ -4691,7 +4691,7 @@ var webSearchToolFactory = createProviderToolFactoryWithOutputSchema9({
|
|
|
4691
4691
|
|
|
4692
4692
|
// src/tool/web-search-preview.ts
|
|
4693
4693
|
import {
|
|
4694
|
-
|
|
4694
|
+
createProviderExecutedToolFactory as createProviderExecutedToolFactory6,
|
|
4695
4695
|
lazySchema as lazySchema23,
|
|
4696
4696
|
zodSchema as zodSchema23
|
|
4697
4697
|
} from "@ai-sdk/provider-utils";
|
|
@@ -4734,7 +4734,7 @@ var webSearchPreviewOutputSchema = lazySchema23(
|
|
|
4734
4734
|
})
|
|
4735
4735
|
)
|
|
4736
4736
|
);
|
|
4737
|
-
var webSearchPreview =
|
|
4737
|
+
var webSearchPreview = createProviderExecutedToolFactory6({
|
|
4738
4738
|
id: "openai.web_search_preview",
|
|
4739
4739
|
inputSchema: webSearchPreviewInputSchema,
|
|
4740
4740
|
outputSchema: webSearchPreviewOutputSchema
|