@ai-sdk/openai 3.0.0-beta.99 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +292 -0
- package/dist/index.d.mts +18 -17
- package/dist/index.d.ts +18 -17
- package/dist/index.js +342 -200
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +350 -204
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +12 -10
- package/dist/internal/index.d.ts +12 -10
- package/dist/internal/index.js +339 -199
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +347 -203
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/internal/index.mjs
CHANGED
|
@@ -35,8 +35,8 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
35
35
|
function getOpenAILanguageModelCapabilities(modelId) {
|
|
36
36
|
const supportsFlexProcessing = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
37
37
|
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
38
|
-
const isReasoningModel =
|
|
39
|
-
const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1");
|
|
38
|
+
const isReasoningModel = modelId.startsWith("o1") || modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("codex-mini") || modelId.startsWith("computer-use-preview") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
39
|
+
const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1") || modelId.startsWith("gpt-5.2");
|
|
40
40
|
const systemMessageMode = isReasoningModel ? "developer" : "system";
|
|
41
41
|
return {
|
|
42
42
|
supportsFlexProcessing,
|
|
@@ -237,6 +237,9 @@ function convertToOpenAIChatMessages({
|
|
|
237
237
|
}
|
|
238
238
|
case "tool": {
|
|
239
239
|
for (const toolResponse of content) {
|
|
240
|
+
if (toolResponse.type === "tool-approval-response") {
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
240
243
|
const output = toolResponse.output;
|
|
241
244
|
let contentValue;
|
|
242
245
|
switch (output.type) {
|
|
@@ -296,7 +299,7 @@ function mapOpenAIFinishReason(finishReason) {
|
|
|
296
299
|
case "tool_calls":
|
|
297
300
|
return "tool-calls";
|
|
298
301
|
default:
|
|
299
|
-
return "
|
|
302
|
+
return "other";
|
|
300
303
|
}
|
|
301
304
|
}
|
|
302
305
|
|
|
@@ -537,7 +540,26 @@ var openaiChatLanguageModelOptions = lazySchema2(
|
|
|
537
540
|
* username or email address, in order to avoid sending us any identifying
|
|
538
541
|
* information.
|
|
539
542
|
*/
|
|
540
|
-
safetyIdentifier: z3.string().optional()
|
|
543
|
+
safetyIdentifier: z3.string().optional(),
|
|
544
|
+
/**
|
|
545
|
+
* Override the system message mode for this model.
|
|
546
|
+
* - 'system': Use the 'system' role for system messages (default for most models)
|
|
547
|
+
* - 'developer': Use the 'developer' role for system messages (used by reasoning models)
|
|
548
|
+
* - 'remove': Remove system messages entirely
|
|
549
|
+
*
|
|
550
|
+
* If not specified, the mode is automatically determined based on the model.
|
|
551
|
+
*/
|
|
552
|
+
systemMessageMode: z3.enum(["system", "developer", "remove"]).optional(),
|
|
553
|
+
/**
|
|
554
|
+
* Force treating this model as a reasoning model.
|
|
555
|
+
*
|
|
556
|
+
* This is useful for "stealth" reasoning models (e.g. via a custom baseURL)
|
|
557
|
+
* where the model ID is not recognized by the SDK's allowlist.
|
|
558
|
+
*
|
|
559
|
+
* When enabled, the SDK applies reasoning-model parameter compatibility rules
|
|
560
|
+
* and defaults `systemMessageMode` to `developer` unless overridden.
|
|
561
|
+
*/
|
|
562
|
+
forceReasoning: z3.boolean().optional()
|
|
541
563
|
})
|
|
542
564
|
)
|
|
543
565
|
);
|
|
@@ -634,7 +656,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
634
656
|
toolChoice,
|
|
635
657
|
providerOptions
|
|
636
658
|
}) {
|
|
637
|
-
var _a, _b, _c;
|
|
659
|
+
var _a, _b, _c, _d, _e;
|
|
638
660
|
const warnings = [];
|
|
639
661
|
const openaiOptions = (_a = await parseProviderOptions({
|
|
640
662
|
provider: "openai",
|
|
@@ -642,17 +664,18 @@ var OpenAIChatLanguageModel = class {
|
|
|
642
664
|
schema: openaiChatLanguageModelOptions
|
|
643
665
|
})) != null ? _a : {};
|
|
644
666
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
667
|
+
const isReasoningModel = (_b = openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
|
|
645
668
|
if (topK != null) {
|
|
646
669
|
warnings.push({ type: "unsupported", feature: "topK" });
|
|
647
670
|
}
|
|
648
671
|
const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages(
|
|
649
672
|
{
|
|
650
673
|
prompt,
|
|
651
|
-
systemMessageMode: modelCapabilities.systemMessageMode
|
|
674
|
+
systemMessageMode: (_c = openaiOptions.systemMessageMode) != null ? _c : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode
|
|
652
675
|
}
|
|
653
676
|
);
|
|
654
677
|
warnings.push(...messageWarnings);
|
|
655
|
-
const strictJsonSchema = (
|
|
678
|
+
const strictJsonSchema = (_d = openaiOptions.strictJsonSchema) != null ? _d : true;
|
|
656
679
|
const baseArgs = {
|
|
657
680
|
// model id:
|
|
658
681
|
model: this.modelId,
|
|
@@ -673,7 +696,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
673
696
|
json_schema: {
|
|
674
697
|
schema: responseFormat.schema,
|
|
675
698
|
strict: strictJsonSchema,
|
|
676
|
-
name: (
|
|
699
|
+
name: (_e = responseFormat.name) != null ? _e : "response",
|
|
677
700
|
description: responseFormat.description
|
|
678
701
|
}
|
|
679
702
|
} : { type: "json_object" } : void 0,
|
|
@@ -694,7 +717,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
694
717
|
// messages:
|
|
695
718
|
messages
|
|
696
719
|
};
|
|
697
|
-
if (
|
|
720
|
+
if (isReasoningModel) {
|
|
698
721
|
if (openaiOptions.reasoningEffort !== "none" || !modelCapabilities.supportsNonReasoningParameters) {
|
|
699
722
|
if (baseArgs.temperature != null) {
|
|
700
723
|
baseArgs.temperature = void 0;
|
|
@@ -800,7 +823,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
800
823
|
};
|
|
801
824
|
}
|
|
802
825
|
async doGenerate(options) {
|
|
803
|
-
var _a, _b, _c, _d, _e, _f;
|
|
826
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
804
827
|
const { args: body, warnings } = await this.getArgs(options);
|
|
805
828
|
const {
|
|
806
829
|
responseHeaders,
|
|
@@ -857,7 +880,10 @@ var OpenAIChatLanguageModel = class {
|
|
|
857
880
|
}
|
|
858
881
|
return {
|
|
859
882
|
content,
|
|
860
|
-
finishReason:
|
|
883
|
+
finishReason: {
|
|
884
|
+
unified: mapOpenAIFinishReason(choice.finish_reason),
|
|
885
|
+
raw: (_g = choice.finish_reason) != null ? _g : void 0
|
|
886
|
+
},
|
|
861
887
|
usage: convertOpenAIChatUsage(response.usage),
|
|
862
888
|
request: { body },
|
|
863
889
|
response: {
|
|
@@ -893,7 +919,10 @@ var OpenAIChatLanguageModel = class {
|
|
|
893
919
|
fetch: this.config.fetch
|
|
894
920
|
});
|
|
895
921
|
const toolCalls = [];
|
|
896
|
-
let finishReason =
|
|
922
|
+
let finishReason = {
|
|
923
|
+
unified: "other",
|
|
924
|
+
raw: void 0
|
|
925
|
+
};
|
|
897
926
|
let usage = void 0;
|
|
898
927
|
let metadataExtracted = false;
|
|
899
928
|
let isActiveText = false;
|
|
@@ -910,13 +939,13 @@ var OpenAIChatLanguageModel = class {
|
|
|
910
939
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
911
940
|
}
|
|
912
941
|
if (!chunk.success) {
|
|
913
|
-
finishReason = "error";
|
|
942
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
914
943
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
915
944
|
return;
|
|
916
945
|
}
|
|
917
946
|
const value = chunk.value;
|
|
918
947
|
if ("error" in value) {
|
|
919
|
-
finishReason = "error";
|
|
948
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
920
949
|
controller.enqueue({ type: "error", error: value.error });
|
|
921
950
|
return;
|
|
922
951
|
}
|
|
@@ -941,7 +970,10 @@ var OpenAIChatLanguageModel = class {
|
|
|
941
970
|
}
|
|
942
971
|
const choice = value.choices[0];
|
|
943
972
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
944
|
-
finishReason =
|
|
973
|
+
finishReason = {
|
|
974
|
+
unified: mapOpenAIFinishReason(choice.finish_reason),
|
|
975
|
+
raw: choice.finish_reason
|
|
976
|
+
};
|
|
945
977
|
}
|
|
946
978
|
if (((_e = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _e.content) != null) {
|
|
947
979
|
providerMetadata.openai.logprobs = choice.logprobs.content;
|
|
@@ -1230,7 +1262,7 @@ function mapOpenAIFinishReason2(finishReason) {
|
|
|
1230
1262
|
case "tool_calls":
|
|
1231
1263
|
return "tool-calls";
|
|
1232
1264
|
default:
|
|
1233
|
-
return "
|
|
1265
|
+
return "other";
|
|
1234
1266
|
}
|
|
1235
1267
|
}
|
|
1236
1268
|
|
|
@@ -1428,6 +1460,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1428
1460
|
};
|
|
1429
1461
|
}
|
|
1430
1462
|
async doGenerate(options) {
|
|
1463
|
+
var _a;
|
|
1431
1464
|
const { args, warnings } = await this.getArgs(options);
|
|
1432
1465
|
const {
|
|
1433
1466
|
responseHeaders,
|
|
@@ -1455,7 +1488,10 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1455
1488
|
return {
|
|
1456
1489
|
content: [{ type: "text", text: choice.text }],
|
|
1457
1490
|
usage: convertOpenAICompletionUsage(response.usage),
|
|
1458
|
-
finishReason:
|
|
1491
|
+
finishReason: {
|
|
1492
|
+
unified: mapOpenAIFinishReason2(choice.finish_reason),
|
|
1493
|
+
raw: (_a = choice.finish_reason) != null ? _a : void 0
|
|
1494
|
+
},
|
|
1459
1495
|
request: { body: args },
|
|
1460
1496
|
response: {
|
|
1461
1497
|
...getResponseMetadata2(response),
|
|
@@ -1489,7 +1525,10 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1489
1525
|
abortSignal: options.abortSignal,
|
|
1490
1526
|
fetch: this.config.fetch
|
|
1491
1527
|
});
|
|
1492
|
-
let finishReason =
|
|
1528
|
+
let finishReason = {
|
|
1529
|
+
unified: "other",
|
|
1530
|
+
raw: void 0
|
|
1531
|
+
};
|
|
1493
1532
|
const providerMetadata = { openai: {} };
|
|
1494
1533
|
let usage = void 0;
|
|
1495
1534
|
let isFirstChunk = true;
|
|
@@ -1504,13 +1543,13 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1504
1543
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1505
1544
|
}
|
|
1506
1545
|
if (!chunk.success) {
|
|
1507
|
-
finishReason = "error";
|
|
1546
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
1508
1547
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
1509
1548
|
return;
|
|
1510
1549
|
}
|
|
1511
1550
|
const value = chunk.value;
|
|
1512
1551
|
if ("error" in value) {
|
|
1513
|
-
finishReason = "error";
|
|
1552
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
1514
1553
|
controller.enqueue({ type: "error", error: value.error });
|
|
1515
1554
|
return;
|
|
1516
1555
|
}
|
|
@@ -1527,7 +1566,10 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1527
1566
|
}
|
|
1528
1567
|
const choice = value.choices[0];
|
|
1529
1568
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
1530
|
-
finishReason =
|
|
1569
|
+
finishReason = {
|
|
1570
|
+
unified: mapOpenAIFinishReason2(choice.finish_reason),
|
|
1571
|
+
raw: choice.finish_reason
|
|
1572
|
+
};
|
|
1531
1573
|
}
|
|
1532
1574
|
if ((choice == null ? void 0 : choice.logprobs) != null) {
|
|
1533
1575
|
providerMetadata.openai.logprobs = choice.logprobs;
|
|
@@ -1670,7 +1712,11 @@ var OpenAIEmbeddingModel = class {
|
|
|
1670
1712
|
// src/image/openai-image-model.ts
|
|
1671
1713
|
import {
|
|
1672
1714
|
combineHeaders as combineHeaders4,
|
|
1715
|
+
convertBase64ToUint8Array,
|
|
1716
|
+
convertToFormData,
|
|
1673
1717
|
createJsonResponseHandler as createJsonResponseHandler4,
|
|
1718
|
+
downloadBlob,
|
|
1719
|
+
postFormDataToApi,
|
|
1674
1720
|
postJsonToApi as postJsonToApi4
|
|
1675
1721
|
} from "@ai-sdk/provider-utils";
|
|
1676
1722
|
|
|
@@ -1709,11 +1755,13 @@ var modelMaxImagesPerCall = {
|
|
|
1709
1755
|
"dall-e-3": 1,
|
|
1710
1756
|
"dall-e-2": 10,
|
|
1711
1757
|
"gpt-image-1": 10,
|
|
1712
|
-
"gpt-image-1-mini": 10
|
|
1758
|
+
"gpt-image-1-mini": 10,
|
|
1759
|
+
"gpt-image-1.5": 10
|
|
1713
1760
|
};
|
|
1714
1761
|
var hasDefaultResponseFormat = /* @__PURE__ */ new Set([
|
|
1715
1762
|
"gpt-image-1",
|
|
1716
|
-
"gpt-image-1-mini"
|
|
1763
|
+
"gpt-image-1-mini",
|
|
1764
|
+
"gpt-image-1.5"
|
|
1717
1765
|
]);
|
|
1718
1766
|
|
|
1719
1767
|
// src/image/openai-image-model.ts
|
|
@@ -1732,6 +1780,8 @@ var OpenAIImageModel = class {
|
|
|
1732
1780
|
}
|
|
1733
1781
|
async doGenerate({
|
|
1734
1782
|
prompt,
|
|
1783
|
+
files,
|
|
1784
|
+
mask,
|
|
1735
1785
|
n,
|
|
1736
1786
|
size,
|
|
1737
1787
|
aspectRatio,
|
|
@@ -1740,7 +1790,7 @@ var OpenAIImageModel = class {
|
|
|
1740
1790
|
headers,
|
|
1741
1791
|
abortSignal
|
|
1742
1792
|
}) {
|
|
1743
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1793
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1744
1794
|
const warnings = [];
|
|
1745
1795
|
if (aspectRatio != null) {
|
|
1746
1796
|
warnings.push({
|
|
@@ -1753,6 +1803,72 @@ var OpenAIImageModel = class {
|
|
|
1753
1803
|
warnings.push({ type: "unsupported", feature: "seed" });
|
|
1754
1804
|
}
|
|
1755
1805
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1806
|
+
if (files != null) {
|
|
1807
|
+
const { value: response2, responseHeaders: responseHeaders2 } = await postFormDataToApi({
|
|
1808
|
+
url: this.config.url({
|
|
1809
|
+
path: "/images/edits",
|
|
1810
|
+
modelId: this.modelId
|
|
1811
|
+
}),
|
|
1812
|
+
headers: combineHeaders4(this.config.headers(), headers),
|
|
1813
|
+
formData: convertToFormData({
|
|
1814
|
+
model: this.modelId,
|
|
1815
|
+
prompt,
|
|
1816
|
+
image: await Promise.all(
|
|
1817
|
+
files.map(
|
|
1818
|
+
(file) => file.type === "file" ? new Blob(
|
|
1819
|
+
[
|
|
1820
|
+
file.data instanceof Uint8Array ? new Blob([file.data], {
|
|
1821
|
+
type: file.mediaType
|
|
1822
|
+
}) : new Blob([convertBase64ToUint8Array(file.data)], {
|
|
1823
|
+
type: file.mediaType
|
|
1824
|
+
})
|
|
1825
|
+
],
|
|
1826
|
+
{ type: file.mediaType }
|
|
1827
|
+
) : downloadBlob(file.url)
|
|
1828
|
+
)
|
|
1829
|
+
),
|
|
1830
|
+
mask: mask != null ? await fileToBlob(mask) : void 0,
|
|
1831
|
+
n,
|
|
1832
|
+
size,
|
|
1833
|
+
...(_d = providerOptions.openai) != null ? _d : {}
|
|
1834
|
+
}),
|
|
1835
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
1836
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
1837
|
+
openaiImageResponseSchema
|
|
1838
|
+
),
|
|
1839
|
+
abortSignal,
|
|
1840
|
+
fetch: this.config.fetch
|
|
1841
|
+
});
|
|
1842
|
+
return {
|
|
1843
|
+
images: response2.data.map((item) => item.b64_json),
|
|
1844
|
+
warnings,
|
|
1845
|
+
usage: response2.usage != null ? {
|
|
1846
|
+
inputTokens: (_e = response2.usage.input_tokens) != null ? _e : void 0,
|
|
1847
|
+
outputTokens: (_f = response2.usage.output_tokens) != null ? _f : void 0,
|
|
1848
|
+
totalTokens: (_g = response2.usage.total_tokens) != null ? _g : void 0
|
|
1849
|
+
} : void 0,
|
|
1850
|
+
response: {
|
|
1851
|
+
timestamp: currentDate,
|
|
1852
|
+
modelId: this.modelId,
|
|
1853
|
+
headers: responseHeaders2
|
|
1854
|
+
},
|
|
1855
|
+
providerMetadata: {
|
|
1856
|
+
openai: {
|
|
1857
|
+
images: response2.data.map((item) => {
|
|
1858
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
1859
|
+
return {
|
|
1860
|
+
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
|
|
1861
|
+
created: (_a2 = response2.created) != null ? _a2 : void 0,
|
|
1862
|
+
size: (_b2 = response2.size) != null ? _b2 : void 0,
|
|
1863
|
+
quality: (_c2 = response2.quality) != null ? _c2 : void 0,
|
|
1864
|
+
background: (_d2 = response2.background) != null ? _d2 : void 0,
|
|
1865
|
+
outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0
|
|
1866
|
+
};
|
|
1867
|
+
})
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
};
|
|
1871
|
+
}
|
|
1756
1872
|
const { value: response, responseHeaders } = await postJsonToApi4({
|
|
1757
1873
|
url: this.config.url({
|
|
1758
1874
|
path: "/images/generations",
|
|
@@ -1764,7 +1880,7 @@ var OpenAIImageModel = class {
|
|
|
1764
1880
|
prompt,
|
|
1765
1881
|
n,
|
|
1766
1882
|
size,
|
|
1767
|
-
...(
|
|
1883
|
+
...(_h = providerOptions.openai) != null ? _h : {},
|
|
1768
1884
|
...!hasDefaultResponseFormat.has(this.modelId) ? { response_format: "b64_json" } : {}
|
|
1769
1885
|
},
|
|
1770
1886
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
@@ -1778,9 +1894,9 @@ var OpenAIImageModel = class {
|
|
|
1778
1894
|
images: response.data.map((item) => item.b64_json),
|
|
1779
1895
|
warnings,
|
|
1780
1896
|
usage: response.usage != null ? {
|
|
1781
|
-
inputTokens: (
|
|
1782
|
-
outputTokens: (
|
|
1783
|
-
totalTokens: (
|
|
1897
|
+
inputTokens: (_i = response.usage.input_tokens) != null ? _i : void 0,
|
|
1898
|
+
outputTokens: (_j = response.usage.output_tokens) != null ? _j : void 0,
|
|
1899
|
+
totalTokens: (_k = response.usage.total_tokens) != null ? _k : void 0
|
|
1784
1900
|
} : void 0,
|
|
1785
1901
|
response: {
|
|
1786
1902
|
timestamp: currentDate,
|
|
@@ -1805,15 +1921,23 @@ var OpenAIImageModel = class {
|
|
|
1805
1921
|
};
|
|
1806
1922
|
}
|
|
1807
1923
|
};
|
|
1924
|
+
async function fileToBlob(file) {
|
|
1925
|
+
if (!file) return void 0;
|
|
1926
|
+
if (file.type === "url") {
|
|
1927
|
+
return downloadBlob(file.url);
|
|
1928
|
+
}
|
|
1929
|
+
const data = file.data instanceof Uint8Array ? file.data : convertBase64ToUint8Array(file.data);
|
|
1930
|
+
return new Blob([data], { type: file.mediaType });
|
|
1931
|
+
}
|
|
1808
1932
|
|
|
1809
1933
|
// src/transcription/openai-transcription-model.ts
|
|
1810
1934
|
import {
|
|
1811
1935
|
combineHeaders as combineHeaders5,
|
|
1812
|
-
convertBase64ToUint8Array,
|
|
1936
|
+
convertBase64ToUint8Array as convertBase64ToUint8Array2,
|
|
1813
1937
|
createJsonResponseHandler as createJsonResponseHandler5,
|
|
1814
1938
|
mediaTypeToExtension,
|
|
1815
1939
|
parseProviderOptions as parseProviderOptions4,
|
|
1816
|
-
postFormDataToApi
|
|
1940
|
+
postFormDataToApi as postFormDataToApi2
|
|
1817
1941
|
} from "@ai-sdk/provider-utils";
|
|
1818
1942
|
|
|
1819
1943
|
// src/transcription/openai-transcription-api.ts
|
|
@@ -1963,7 +2087,7 @@ var OpenAITranscriptionModel = class {
|
|
|
1963
2087
|
schema: openAITranscriptionProviderOptions
|
|
1964
2088
|
});
|
|
1965
2089
|
const formData = new FormData();
|
|
1966
|
-
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([
|
|
2090
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array2(audio)]);
|
|
1967
2091
|
formData.append("model", this.modelId);
|
|
1968
2092
|
const fileExtension = mediaTypeToExtension(mediaType);
|
|
1969
2093
|
formData.append(
|
|
@@ -2010,7 +2134,7 @@ var OpenAITranscriptionModel = class {
|
|
|
2010
2134
|
value: response,
|
|
2011
2135
|
responseHeaders,
|
|
2012
2136
|
rawValue: rawResponse
|
|
2013
|
-
} = await
|
|
2137
|
+
} = await postFormDataToApi2({
|
|
2014
2138
|
url: this.config.url({
|
|
2015
2139
|
path: "/audio/transcriptions",
|
|
2016
2140
|
modelId: this.modelId
|
|
@@ -2589,6 +2713,9 @@ async function convertToOpenAIResponsesInput({
|
|
|
2589
2713
|
}
|
|
2590
2714
|
case "tool": {
|
|
2591
2715
|
for (const part of content) {
|
|
2716
|
+
if (part.type === "tool-approval-response") {
|
|
2717
|
+
continue;
|
|
2718
|
+
}
|
|
2592
2719
|
const output = part.output;
|
|
2593
2720
|
const resolvedToolName = toolNameMapping.toProviderToolName(
|
|
2594
2721
|
part.toolName
|
|
@@ -2603,7 +2730,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2603
2730
|
call_id: part.toolCallId,
|
|
2604
2731
|
output: parsedOutput.output
|
|
2605
2732
|
});
|
|
2606
|
-
|
|
2733
|
+
continue;
|
|
2607
2734
|
}
|
|
2608
2735
|
if (hasShellTool && resolvedToolName === "shell" && output.type === "json") {
|
|
2609
2736
|
const parsedOutput = await validateTypes({
|
|
@@ -2622,7 +2749,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2622
2749
|
}
|
|
2623
2750
|
}))
|
|
2624
2751
|
});
|
|
2625
|
-
|
|
2752
|
+
continue;
|
|
2626
2753
|
}
|
|
2627
2754
|
if (hasApplyPatchTool && part.toolName === "apply_patch" && output.type === "json") {
|
|
2628
2755
|
const parsedOutput = await validateTypes({
|
|
@@ -2635,7 +2762,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2635
2762
|
status: parsedOutput.status,
|
|
2636
2763
|
output: parsedOutput.output
|
|
2637
2764
|
});
|
|
2638
|
-
|
|
2765
|
+
continue;
|
|
2639
2766
|
}
|
|
2640
2767
|
let contentValue;
|
|
2641
2768
|
switch (output.type) {
|
|
@@ -2716,7 +2843,7 @@ function mapOpenAIResponseFinishReason({
|
|
|
2716
2843
|
case "content_filter":
|
|
2717
2844
|
return "content-filter";
|
|
2718
2845
|
default:
|
|
2719
|
-
return hasFunctionCall ? "tool-calls" : "
|
|
2846
|
+
return hasFunctionCall ? "tool-calls" : "other";
|
|
2720
2847
|
}
|
|
2721
2848
|
}
|
|
2722
2849
|
|
|
@@ -3115,6 +3242,19 @@ var openaiResponsesChunkSchema = lazySchema14(
|
|
|
3115
3242
|
item_id: z16.string(),
|
|
3116
3243
|
summary_index: z16.number()
|
|
3117
3244
|
}),
|
|
3245
|
+
z16.object({
|
|
3246
|
+
type: z16.literal("response.apply_patch_call_operation_diff.delta"),
|
|
3247
|
+
item_id: z16.string(),
|
|
3248
|
+
output_index: z16.number(),
|
|
3249
|
+
delta: z16.string(),
|
|
3250
|
+
obfuscation: z16.string().nullish()
|
|
3251
|
+
}),
|
|
3252
|
+
z16.object({
|
|
3253
|
+
type: z16.literal("response.apply_patch_call_operation_diff.done"),
|
|
3254
|
+
item_id: z16.string(),
|
|
3255
|
+
output_index: z16.number(),
|
|
3256
|
+
diff: z16.string()
|
|
3257
|
+
}),
|
|
3118
3258
|
z16.object({
|
|
3119
3259
|
type: z16.literal("error"),
|
|
3120
3260
|
sequence_number: z16.number(),
|
|
@@ -3595,7 +3735,26 @@ var openaiResponsesProviderOptionsSchema = lazySchema15(
|
|
|
3595
3735
|
* Defaults to `undefined`.
|
|
3596
3736
|
* @see https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids
|
|
3597
3737
|
*/
|
|
3598
|
-
user: z17.string().nullish()
|
|
3738
|
+
user: z17.string().nullish(),
|
|
3739
|
+
/**
|
|
3740
|
+
* Override the system message mode for this model.
|
|
3741
|
+
* - 'system': Use the 'system' role for system messages (default for most models)
|
|
3742
|
+
* - 'developer': Use the 'developer' role for system messages (used by reasoning models)
|
|
3743
|
+
* - 'remove': Remove system messages entirely
|
|
3744
|
+
*
|
|
3745
|
+
* If not specified, the mode is automatically determined based on the model.
|
|
3746
|
+
*/
|
|
3747
|
+
systemMessageMode: z17.enum(["system", "developer", "remove"]).optional(),
|
|
3748
|
+
/**
|
|
3749
|
+
* Force treating this model as a reasoning model.
|
|
3750
|
+
*
|
|
3751
|
+
* This is useful for "stealth" reasoning models (e.g. via a custom baseURL)
|
|
3752
|
+
* where the model ID is not recognized by the SDK's allowlist.
|
|
3753
|
+
*
|
|
3754
|
+
* When enabled, the SDK applies reasoning-model parameter compatibility rules
|
|
3755
|
+
* and defaults `systemMessageMode` to `developer` unless overridden.
|
|
3756
|
+
*/
|
|
3757
|
+
forceReasoning: z17.boolean().optional()
|
|
3599
3758
|
})
|
|
3600
3759
|
)
|
|
3601
3760
|
);
|
|
@@ -3777,16 +3936,14 @@ var mcpArgsSchema = lazySchema19(
|
|
|
3777
3936
|
authorization: z21.string().optional(),
|
|
3778
3937
|
connectorId: z21.string().optional(),
|
|
3779
3938
|
headers: z21.record(z21.string(), z21.string()).optional(),
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
// ])
|
|
3789
|
-
// .optional(),
|
|
3939
|
+
requireApproval: z21.union([
|
|
3940
|
+
z21.enum(["always", "never"]),
|
|
3941
|
+
z21.object({
|
|
3942
|
+
never: z21.object({
|
|
3943
|
+
toolNames: z21.array(z21.string()).optional()
|
|
3944
|
+
}).optional()
|
|
3945
|
+
})
|
|
3946
|
+
]).optional(),
|
|
3790
3947
|
serverDescription: z21.string().optional(),
|
|
3791
3948
|
serverUrl: z21.string().optional()
|
|
3792
3949
|
}).refine(
|
|
@@ -3798,36 +3955,14 @@ var mcpArgsSchema = lazySchema19(
|
|
|
3798
3955
|
var mcpInputSchema = lazySchema19(() => zodSchema19(z21.object({})));
|
|
3799
3956
|
var mcpOutputSchema = lazySchema19(
|
|
3800
3957
|
() => zodSchema19(
|
|
3801
|
-
z21.
|
|
3802
|
-
z21.
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
}),
|
|
3810
|
-
z21.object({
|
|
3811
|
-
type: z21.literal("listTools"),
|
|
3812
|
-
serverLabel: z21.string(),
|
|
3813
|
-
tools: z21.array(
|
|
3814
|
-
z21.object({
|
|
3815
|
-
name: z21.string(),
|
|
3816
|
-
description: z21.string().optional(),
|
|
3817
|
-
inputSchema: jsonValueSchema,
|
|
3818
|
-
annotations: z21.record(z21.string(), jsonValueSchema).optional()
|
|
3819
|
-
})
|
|
3820
|
-
),
|
|
3821
|
-
error: z21.union([z21.string(), jsonValueSchema]).optional()
|
|
3822
|
-
}),
|
|
3823
|
-
z21.object({
|
|
3824
|
-
type: z21.literal("approvalRequest"),
|
|
3825
|
-
serverLabel: z21.string(),
|
|
3826
|
-
name: z21.string(),
|
|
3827
|
-
arguments: z21.string(),
|
|
3828
|
-
approvalRequestId: z21.string()
|
|
3829
|
-
})
|
|
3830
|
-
])
|
|
3958
|
+
z21.object({
|
|
3959
|
+
type: z21.literal("call"),
|
|
3960
|
+
serverLabel: z21.string(),
|
|
3961
|
+
name: z21.string(),
|
|
3962
|
+
arguments: z21.string(),
|
|
3963
|
+
output: z21.string().nullable().optional(),
|
|
3964
|
+
error: z21.union([z21.string(), jsonValueSchema]).optional()
|
|
3965
|
+
})
|
|
3831
3966
|
)
|
|
3832
3967
|
);
|
|
3833
3968
|
var mcpToolFactory = createProviderToolFactoryWithOutputSchema7({
|
|
@@ -4148,7 +4283,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4148
4283
|
toolChoice,
|
|
4149
4284
|
responseFormat
|
|
4150
4285
|
}) {
|
|
4151
|
-
var _a, _b, _c, _d;
|
|
4286
|
+
var _a, _b, _c, _d, _e, _f;
|
|
4152
4287
|
const warnings = [];
|
|
4153
4288
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
4154
4289
|
if (topK != null) {
|
|
@@ -4171,6 +4306,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4171
4306
|
providerOptions,
|
|
4172
4307
|
schema: openaiResponsesProviderOptionsSchema
|
|
4173
4308
|
});
|
|
4309
|
+
const isReasoningModel = (_a = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _a : modelCapabilities.isReasoningModel;
|
|
4174
4310
|
if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
|
|
4175
4311
|
warnings.push({
|
|
4176
4312
|
type: "unsupported",
|
|
@@ -4195,15 +4331,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4195
4331
|
const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
|
|
4196
4332
|
prompt,
|
|
4197
4333
|
toolNameMapping,
|
|
4198
|
-
systemMessageMode: modelCapabilities.systemMessageMode,
|
|
4334
|
+
systemMessageMode: (_b = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _b : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
|
|
4199
4335
|
fileIdPrefixes: this.config.fileIdPrefixes,
|
|
4200
|
-
store: (
|
|
4336
|
+
store: (_c = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _c : true,
|
|
4201
4337
|
hasLocalShellTool: hasOpenAITool("openai.local_shell"),
|
|
4202
4338
|
hasShellTool: hasOpenAITool("openai.shell"),
|
|
4203
4339
|
hasApplyPatchTool: hasOpenAITool("openai.apply_patch")
|
|
4204
4340
|
});
|
|
4205
4341
|
warnings.push(...inputWarnings);
|
|
4206
|
-
const strictJsonSchema = (
|
|
4342
|
+
const strictJsonSchema = (_d = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _d : true;
|
|
4207
4343
|
let include = openaiOptions == null ? void 0 : openaiOptions.include;
|
|
4208
4344
|
function addInclude(key) {
|
|
4209
4345
|
if (include == null) {
|
|
@@ -4219,9 +4355,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4219
4355
|
if (topLogprobs) {
|
|
4220
4356
|
addInclude("message.output_text.logprobs");
|
|
4221
4357
|
}
|
|
4222
|
-
const webSearchToolName = (
|
|
4358
|
+
const webSearchToolName = (_e = tools == null ? void 0 : tools.find(
|
|
4223
4359
|
(tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
|
|
4224
|
-
)) == null ? void 0 :
|
|
4360
|
+
)) == null ? void 0 : _e.name;
|
|
4225
4361
|
if (webSearchToolName) {
|
|
4226
4362
|
addInclude("web_search_call.action.sources");
|
|
4227
4363
|
}
|
|
@@ -4229,7 +4365,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4229
4365
|
addInclude("code_interpreter_call.outputs");
|
|
4230
4366
|
}
|
|
4231
4367
|
const store = openaiOptions == null ? void 0 : openaiOptions.store;
|
|
4232
|
-
if (store === false &&
|
|
4368
|
+
if (store === false && isReasoningModel) {
|
|
4233
4369
|
addInclude("reasoning.encrypted_content");
|
|
4234
4370
|
}
|
|
4235
4371
|
const baseArgs = {
|
|
@@ -4244,7 +4380,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4244
4380
|
format: responseFormat.schema != null ? {
|
|
4245
4381
|
type: "json_schema",
|
|
4246
4382
|
strict: strictJsonSchema,
|
|
4247
|
-
name: (
|
|
4383
|
+
name: (_f = responseFormat.name) != null ? _f : "response",
|
|
4248
4384
|
description: responseFormat.description,
|
|
4249
4385
|
schema: responseFormat.schema
|
|
4250
4386
|
} : { type: "json_object" }
|
|
@@ -4271,7 +4407,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4271
4407
|
top_logprobs: topLogprobs,
|
|
4272
4408
|
truncation: openaiOptions == null ? void 0 : openaiOptions.truncation,
|
|
4273
4409
|
// model-specific settings:
|
|
4274
|
-
...
|
|
4410
|
+
...isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
|
|
4275
4411
|
reasoning: {
|
|
4276
4412
|
...(openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null && {
|
|
4277
4413
|
effort: openaiOptions.reasoningEffort
|
|
@@ -4282,7 +4418,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4282
4418
|
}
|
|
4283
4419
|
}
|
|
4284
4420
|
};
|
|
4285
|
-
if (
|
|
4421
|
+
if (isReasoningModel) {
|
|
4286
4422
|
if (!((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) === "none" && modelCapabilities.supportsNonReasoningParameters)) {
|
|
4287
4423
|
if (baseArgs.temperature != null) {
|
|
4288
4424
|
baseArgs.temperature = void 0;
|
|
@@ -4354,7 +4490,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4354
4490
|
};
|
|
4355
4491
|
}
|
|
4356
4492
|
async doGenerate(options) {
|
|
4357
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
4493
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
4358
4494
|
const {
|
|
4359
4495
|
args: body,
|
|
4360
4496
|
warnings,
|
|
@@ -4605,54 +4741,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4605
4741
|
break;
|
|
4606
4742
|
}
|
|
4607
4743
|
case "mcp_list_tools": {
|
|
4608
|
-
content.push({
|
|
4609
|
-
type: "tool-call",
|
|
4610
|
-
toolCallId: part.id,
|
|
4611
|
-
toolName: toolNameMapping.toCustomToolName("mcp"),
|
|
4612
|
-
input: JSON.stringify({}),
|
|
4613
|
-
providerExecuted: true
|
|
4614
|
-
});
|
|
4615
|
-
content.push({
|
|
4616
|
-
type: "tool-result",
|
|
4617
|
-
toolCallId: part.id,
|
|
4618
|
-
toolName: toolNameMapping.toCustomToolName("mcp"),
|
|
4619
|
-
result: {
|
|
4620
|
-
type: "listTools",
|
|
4621
|
-
serverLabel: part.server_label,
|
|
4622
|
-
tools: part.tools.map((t) => {
|
|
4623
|
-
var _a2, _b2;
|
|
4624
|
-
return {
|
|
4625
|
-
name: t.name,
|
|
4626
|
-
description: (_a2 = t.description) != null ? _a2 : void 0,
|
|
4627
|
-
inputSchema: t.input_schema,
|
|
4628
|
-
annotations: (_b2 = t.annotations) != null ? _b2 : void 0
|
|
4629
|
-
};
|
|
4630
|
-
}),
|
|
4631
|
-
...part.error != null ? { error: part.error } : {}
|
|
4632
|
-
}
|
|
4633
|
-
});
|
|
4634
4744
|
break;
|
|
4635
4745
|
}
|
|
4636
4746
|
case "mcp_approval_request": {
|
|
4637
|
-
content.push({
|
|
4638
|
-
type: "tool-call",
|
|
4639
|
-
toolCallId: part.id,
|
|
4640
|
-
toolName: toolNameMapping.toCustomToolName("mcp"),
|
|
4641
|
-
input: JSON.stringify({}),
|
|
4642
|
-
providerExecuted: true
|
|
4643
|
-
});
|
|
4644
|
-
content.push({
|
|
4645
|
-
type: "tool-result",
|
|
4646
|
-
toolCallId: part.id,
|
|
4647
|
-
toolName: toolNameMapping.toCustomToolName("mcp"),
|
|
4648
|
-
result: {
|
|
4649
|
-
type: "approvalRequest",
|
|
4650
|
-
serverLabel: part.server_label,
|
|
4651
|
-
name: part.name,
|
|
4652
|
-
arguments: part.arguments,
|
|
4653
|
-
approvalRequestId: part.approval_request_id
|
|
4654
|
-
}
|
|
4655
|
-
});
|
|
4656
4747
|
break;
|
|
4657
4748
|
}
|
|
4658
4749
|
case "computer_call": {
|
|
@@ -4751,10 +4842,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4751
4842
|
const usage = response.usage;
|
|
4752
4843
|
return {
|
|
4753
4844
|
content,
|
|
4754
|
-
finishReason:
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4845
|
+
finishReason: {
|
|
4846
|
+
unified: mapOpenAIResponseFinishReason({
|
|
4847
|
+
finishReason: (_x = response.incomplete_details) == null ? void 0 : _x.reason,
|
|
4848
|
+
hasFunctionCall
|
|
4849
|
+
}),
|
|
4850
|
+
raw: (_z = (_y = response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
|
|
4851
|
+
},
|
|
4758
4852
|
usage: convertOpenAIResponsesUsage(usage),
|
|
4759
4853
|
request: { body },
|
|
4760
4854
|
response: {
|
|
@@ -4795,7 +4889,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4795
4889
|
});
|
|
4796
4890
|
const self = this;
|
|
4797
4891
|
const providerKey = this.config.provider.replace(".responses", "");
|
|
4798
|
-
let finishReason =
|
|
4892
|
+
let finishReason = {
|
|
4893
|
+
unified: "other",
|
|
4894
|
+
raw: void 0
|
|
4895
|
+
};
|
|
4799
4896
|
let usage = void 0;
|
|
4800
4897
|
const logprobs = [];
|
|
4801
4898
|
let responseId = null;
|
|
@@ -4811,12 +4908,12 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4811
4908
|
controller.enqueue({ type: "stream-start", warnings });
|
|
4812
4909
|
},
|
|
4813
4910
|
transform(chunk, controller) {
|
|
4814
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A;
|
|
4911
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C;
|
|
4815
4912
|
if (options.includeRawChunks) {
|
|
4816
4913
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
4817
4914
|
}
|
|
4818
4915
|
if (!chunk.success) {
|
|
4819
|
-
finishReason = "error";
|
|
4916
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
4820
4917
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
4821
4918
|
return;
|
|
4822
4919
|
}
|
|
@@ -4915,24 +5012,40 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4915
5012
|
providerExecuted: true
|
|
4916
5013
|
});
|
|
4917
5014
|
} else if (value.item.type === "apply_patch_call") {
|
|
5015
|
+
const { call_id: callId, operation } = value.item;
|
|
4918
5016
|
ongoingToolCalls[value.output_index] = {
|
|
4919
5017
|
toolName: toolNameMapping.toCustomToolName("apply_patch"),
|
|
4920
|
-
toolCallId:
|
|
5018
|
+
toolCallId: callId,
|
|
5019
|
+
applyPatch: {
|
|
5020
|
+
// delete_file doesn't have diff
|
|
5021
|
+
hasDiff: operation.type === "delete_file",
|
|
5022
|
+
endEmitted: operation.type === "delete_file"
|
|
5023
|
+
}
|
|
4921
5024
|
};
|
|
4922
|
-
|
|
5025
|
+
controller.enqueue({
|
|
5026
|
+
type: "tool-input-start",
|
|
5027
|
+
id: callId,
|
|
5028
|
+
toolName: toolNameMapping.toCustomToolName("apply_patch")
|
|
5029
|
+
});
|
|
5030
|
+
if (operation.type === "delete_file") {
|
|
5031
|
+
const inputString = JSON.stringify({
|
|
5032
|
+
callId,
|
|
5033
|
+
operation
|
|
5034
|
+
});
|
|
4923
5035
|
controller.enqueue({
|
|
4924
|
-
type: "tool-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
5036
|
+
type: "tool-input-delta",
|
|
5037
|
+
id: callId,
|
|
5038
|
+
delta: inputString
|
|
5039
|
+
});
|
|
5040
|
+
controller.enqueue({
|
|
5041
|
+
type: "tool-input-end",
|
|
5042
|
+
id: callId
|
|
5043
|
+
});
|
|
5044
|
+
} else {
|
|
5045
|
+
controller.enqueue({
|
|
5046
|
+
type: "tool-input-delta",
|
|
5047
|
+
id: callId,
|
|
5048
|
+
delta: `{"callId":"${escapeJSONDelta(callId)}","operation":{"type":"${escapeJSONDelta(operation.type)}","path":"${escapeJSONDelta(operation.path)}","diff":"`
|
|
4936
5049
|
});
|
|
4937
5050
|
}
|
|
4938
5051
|
} else if (value.item.type === "shell_call") {
|
|
@@ -5084,31 +5197,31 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5084
5197
|
});
|
|
5085
5198
|
} else if (value.item.type === "mcp_list_tools") {
|
|
5086
5199
|
ongoingToolCalls[value.output_index] = void 0;
|
|
5087
|
-
controller.enqueue({
|
|
5088
|
-
type: "tool-result",
|
|
5089
|
-
toolCallId: value.item.id,
|
|
5090
|
-
toolName: toolNameMapping.toCustomToolName("mcp"),
|
|
5091
|
-
result: {
|
|
5092
|
-
type: "listTools",
|
|
5093
|
-
serverLabel: value.item.server_label,
|
|
5094
|
-
tools: value.item.tools.map((t) => {
|
|
5095
|
-
var _a2, _b2;
|
|
5096
|
-
return {
|
|
5097
|
-
name: t.name,
|
|
5098
|
-
description: (_a2 = t.description) != null ? _a2 : void 0,
|
|
5099
|
-
inputSchema: t.input_schema,
|
|
5100
|
-
annotations: (_b2 = t.annotations) != null ? _b2 : void 0
|
|
5101
|
-
};
|
|
5102
|
-
}),
|
|
5103
|
-
...value.item.error != null ? { error: value.item.error } : {}
|
|
5104
|
-
}
|
|
5105
|
-
});
|
|
5106
5200
|
} else if (value.item.type === "apply_patch_call") {
|
|
5107
|
-
ongoingToolCalls[value.output_index]
|
|
5108
|
-
if (value.item.
|
|
5201
|
+
const toolCall = ongoingToolCalls[value.output_index];
|
|
5202
|
+
if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted && value.item.operation.type !== "delete_file") {
|
|
5203
|
+
if (!toolCall.applyPatch.hasDiff) {
|
|
5204
|
+
controller.enqueue({
|
|
5205
|
+
type: "tool-input-delta",
|
|
5206
|
+
id: toolCall.toolCallId,
|
|
5207
|
+
delta: escapeJSONDelta(value.item.operation.diff)
|
|
5208
|
+
});
|
|
5209
|
+
}
|
|
5210
|
+
controller.enqueue({
|
|
5211
|
+
type: "tool-input-delta",
|
|
5212
|
+
id: toolCall.toolCallId,
|
|
5213
|
+
delta: '"}}'
|
|
5214
|
+
});
|
|
5215
|
+
controller.enqueue({
|
|
5216
|
+
type: "tool-input-end",
|
|
5217
|
+
id: toolCall.toolCallId
|
|
5218
|
+
});
|
|
5219
|
+
toolCall.applyPatch.endEmitted = true;
|
|
5220
|
+
}
|
|
5221
|
+
if (toolCall && value.item.status === "completed") {
|
|
5109
5222
|
controller.enqueue({
|
|
5110
5223
|
type: "tool-call",
|
|
5111
|
-
toolCallId:
|
|
5224
|
+
toolCallId: toolCall.toolCallId,
|
|
5112
5225
|
toolName: toolNameMapping.toCustomToolName("apply_patch"),
|
|
5113
5226
|
input: JSON.stringify({
|
|
5114
5227
|
callId: value.item.call_id,
|
|
@@ -5121,20 +5234,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5121
5234
|
}
|
|
5122
5235
|
});
|
|
5123
5236
|
}
|
|
5237
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
5124
5238
|
} else if (value.item.type === "mcp_approval_request") {
|
|
5125
5239
|
ongoingToolCalls[value.output_index] = void 0;
|
|
5126
|
-
controller.enqueue({
|
|
5127
|
-
type: "tool-result",
|
|
5128
|
-
toolCallId: value.item.id,
|
|
5129
|
-
toolName: toolNameMapping.toCustomToolName("mcp"),
|
|
5130
|
-
result: {
|
|
5131
|
-
type: "approvalRequest",
|
|
5132
|
-
serverLabel: value.item.server_label,
|
|
5133
|
-
name: value.item.name,
|
|
5134
|
-
arguments: value.item.arguments,
|
|
5135
|
-
approvalRequestId: value.item.approval_request_id
|
|
5136
|
-
}
|
|
5137
|
-
});
|
|
5138
5240
|
} else if (value.item.type === "local_shell_call") {
|
|
5139
5241
|
ongoingToolCalls[value.output_index] = void 0;
|
|
5140
5242
|
controller.enqueue({
|
|
@@ -5200,6 +5302,38 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5200
5302
|
delta: value.delta
|
|
5201
5303
|
});
|
|
5202
5304
|
}
|
|
5305
|
+
} else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
|
|
5306
|
+
const toolCall = ongoingToolCalls[value.output_index];
|
|
5307
|
+
if (toolCall == null ? void 0 : toolCall.applyPatch) {
|
|
5308
|
+
controller.enqueue({
|
|
5309
|
+
type: "tool-input-delta",
|
|
5310
|
+
id: toolCall.toolCallId,
|
|
5311
|
+
delta: escapeJSONDelta(value.delta)
|
|
5312
|
+
});
|
|
5313
|
+
toolCall.applyPatch.hasDiff = true;
|
|
5314
|
+
}
|
|
5315
|
+
} else if (isResponseApplyPatchCallOperationDiffDoneChunk(value)) {
|
|
5316
|
+
const toolCall = ongoingToolCalls[value.output_index];
|
|
5317
|
+
if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted) {
|
|
5318
|
+
if (!toolCall.applyPatch.hasDiff) {
|
|
5319
|
+
controller.enqueue({
|
|
5320
|
+
type: "tool-input-delta",
|
|
5321
|
+
id: toolCall.toolCallId,
|
|
5322
|
+
delta: escapeJSONDelta(value.diff)
|
|
5323
|
+
});
|
|
5324
|
+
toolCall.applyPatch.hasDiff = true;
|
|
5325
|
+
}
|
|
5326
|
+
controller.enqueue({
|
|
5327
|
+
type: "tool-input-delta",
|
|
5328
|
+
id: toolCall.toolCallId,
|
|
5329
|
+
delta: '"}}'
|
|
5330
|
+
});
|
|
5331
|
+
controller.enqueue({
|
|
5332
|
+
type: "tool-input-end",
|
|
5333
|
+
id: toolCall.toolCallId
|
|
5334
|
+
});
|
|
5335
|
+
toolCall.applyPatch.endEmitted = true;
|
|
5336
|
+
}
|
|
5203
5337
|
} else if (isResponseImageGenerationCallPartialImageChunk(value)) {
|
|
5204
5338
|
controller.enqueue({
|
|
5205
5339
|
type: "tool-result",
|
|
@@ -5216,9 +5350,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5216
5350
|
controller.enqueue({
|
|
5217
5351
|
type: "tool-input-delta",
|
|
5218
5352
|
id: toolCall.toolCallId,
|
|
5219
|
-
|
|
5220
|
-
// To escape it, we use JSON.stringify and slice to remove the outer quotes.
|
|
5221
|
-
delta: JSON.stringify(value.delta).slice(1, -1)
|
|
5353
|
+
delta: escapeJSONDelta(value.delta)
|
|
5222
5354
|
});
|
|
5223
5355
|
}
|
|
5224
5356
|
} else if (isResponseCodeInterpreterCallCodeDoneChunk(value)) {
|
|
@@ -5315,10 +5447,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5315
5447
|
activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
|
|
5316
5448
|
}
|
|
5317
5449
|
} else if (isResponseFinishedChunk(value)) {
|
|
5318
|
-
finishReason =
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5450
|
+
finishReason = {
|
|
5451
|
+
unified: mapOpenAIResponseFinishReason({
|
|
5452
|
+
finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
|
|
5453
|
+
hasFunctionCall
|
|
5454
|
+
}),
|
|
5455
|
+
raw: (_k = (_j = value.response.incomplete_details) == null ? void 0 : _j.reason) != null ? _k : void 0
|
|
5456
|
+
};
|
|
5322
5457
|
usage = value.response.usage;
|
|
5323
5458
|
if (typeof value.response.service_tier === "string") {
|
|
5324
5459
|
serviceTier = value.response.service_tier;
|
|
@@ -5329,7 +5464,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5329
5464
|
controller.enqueue({
|
|
5330
5465
|
type: "source",
|
|
5331
5466
|
sourceType: "url",
|
|
5332
|
-
id: (
|
|
5467
|
+
id: (_n = (_m = (_l = self.config).generateId) == null ? void 0 : _m.call(_l)) != null ? _n : generateId2(),
|
|
5333
5468
|
url: value.annotation.url,
|
|
5334
5469
|
title: value.annotation.title
|
|
5335
5470
|
});
|
|
@@ -5337,10 +5472,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5337
5472
|
controller.enqueue({
|
|
5338
5473
|
type: "source",
|
|
5339
5474
|
sourceType: "document",
|
|
5340
|
-
id: (
|
|
5475
|
+
id: (_q = (_p = (_o = self.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2(),
|
|
5341
5476
|
mediaType: "text/plain",
|
|
5342
|
-
title: (
|
|
5343
|
-
filename: (
|
|
5477
|
+
title: (_s = (_r = value.annotation.quote) != null ? _r : value.annotation.filename) != null ? _s : "Document",
|
|
5478
|
+
filename: (_t = value.annotation.filename) != null ? _t : value.annotation.file_id,
|
|
5344
5479
|
...value.annotation.file_id ? {
|
|
5345
5480
|
providerMetadata: {
|
|
5346
5481
|
[providerKey]: {
|
|
@@ -5353,10 +5488,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5353
5488
|
controller.enqueue({
|
|
5354
5489
|
type: "source",
|
|
5355
5490
|
sourceType: "document",
|
|
5356
|
-
id: (
|
|
5491
|
+
id: (_w = (_v = (_u = self.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : generateId2(),
|
|
5357
5492
|
mediaType: "text/plain",
|
|
5358
|
-
title: (
|
|
5359
|
-
filename: (
|
|
5493
|
+
title: (_y = (_x = value.annotation.filename) != null ? _x : value.annotation.file_id) != null ? _y : "Document",
|
|
5494
|
+
filename: (_z = value.annotation.filename) != null ? _z : value.annotation.file_id,
|
|
5360
5495
|
providerMetadata: {
|
|
5361
5496
|
[providerKey]: {
|
|
5362
5497
|
fileId: value.annotation.file_id,
|
|
@@ -5369,7 +5504,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5369
5504
|
controller.enqueue({
|
|
5370
5505
|
type: "source",
|
|
5371
5506
|
sourceType: "document",
|
|
5372
|
-
id: (
|
|
5507
|
+
id: (_C = (_B = (_A = self.config).generateId) == null ? void 0 : _B.call(_A)) != null ? _C : generateId2(),
|
|
5373
5508
|
mediaType: "application/octet-stream",
|
|
5374
5509
|
title: value.annotation.file_id,
|
|
5375
5510
|
filename: value.annotation.file_id,
|
|
@@ -5435,6 +5570,12 @@ function isResponseCodeInterpreterCallCodeDeltaChunk(chunk) {
|
|
|
5435
5570
|
function isResponseCodeInterpreterCallCodeDoneChunk(chunk) {
|
|
5436
5571
|
return chunk.type === "response.code_interpreter_call_code.done";
|
|
5437
5572
|
}
|
|
5573
|
+
function isResponseApplyPatchCallOperationDiffDeltaChunk(chunk) {
|
|
5574
|
+
return chunk.type === "response.apply_patch_call_operation_diff.delta";
|
|
5575
|
+
}
|
|
5576
|
+
function isResponseApplyPatchCallOperationDiffDoneChunk(chunk) {
|
|
5577
|
+
return chunk.type === "response.apply_patch_call_operation_diff.done";
|
|
5578
|
+
}
|
|
5438
5579
|
function isResponseOutputItemAddedChunk(chunk) {
|
|
5439
5580
|
return chunk.type === "response.output_item.added";
|
|
5440
5581
|
}
|
|
@@ -5465,6 +5606,9 @@ function mapWebSearchOutput(action) {
|
|
|
5465
5606
|
};
|
|
5466
5607
|
}
|
|
5467
5608
|
}
|
|
5609
|
+
function escapeJSONDelta(delta) {
|
|
5610
|
+
return JSON.stringify(delta).slice(1, -1);
|
|
5611
|
+
}
|
|
5468
5612
|
export {
|
|
5469
5613
|
OpenAIChatLanguageModel,
|
|
5470
5614
|
OpenAICompletionLanguageModel,
|