@ai-sdk/openai 4.0.47 → 4.0.50
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 +27 -0
- package/dist/index.d.ts +29 -12
- package/dist/index.js +384 -278
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +45 -26
- package/dist/internal/index.js +280 -170
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +31 -11
- package/package.json +2 -2
- package/src/chat/convert-to-openai-chat-messages.ts +5 -1
- package/src/chat/openai-chat-language-model.ts +9 -2
- package/src/completion/openai-completion-language-model.ts +9 -2
- package/src/embedding/openai-embedding-model.ts +2 -0
- package/src/openai-responses-batch.ts +90 -102
- package/src/openai-stream-error.ts +68 -15
- package/src/responses/convert-to-openai-responses-input.ts +5 -3
- package/src/responses/openai-responses-api.ts +114 -40
- package/src/responses/openai-responses-language-model.ts +35 -21
package/dist/internal/index.js
CHANGED
|
@@ -34,10 +34,10 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
34
34
|
|
|
35
35
|
// src/openai-language-model-capabilities.ts
|
|
36
36
|
function getOpenAILanguageModelCapabilities(modelId) {
|
|
37
|
-
var
|
|
37
|
+
var _a2, _b, _c, _d, _e;
|
|
38
38
|
const oSeriesVersion = getOSeriesVersion(modelId);
|
|
39
39
|
const gptVersion = getGptVersion(modelId);
|
|
40
|
-
const isGptChatModel = (gptVersion == null ? void 0 : gptVersion.minor) == null && ((_b = (
|
|
40
|
+
const isGptChatModel = (gptVersion == null ? void 0 : gptVersion.minor) == null && ((_b = (_a2 = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _a2.startsWith("chat")) != null ? _b : false);
|
|
41
41
|
const isGptNanoModel = (_d = (_c = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _c.startsWith("nano")) != null ? _d : false;
|
|
42
42
|
const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
|
|
43
43
|
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
|
|
@@ -70,6 +70,25 @@ function getGptVersion(modelId) {
|
|
|
70
70
|
|
|
71
71
|
// src/openai-stream-error.ts
|
|
72
72
|
import { APICallError } from "@ai-sdk/provider";
|
|
73
|
+
import {
|
|
74
|
+
createProviderStreamError
|
|
75
|
+
} from "@ai-sdk/provider-utils";
|
|
76
|
+
function createOpenAIProviderStreamError(frame) {
|
|
77
|
+
var _a2, _b;
|
|
78
|
+
const streamError = parseStreamError(frame);
|
|
79
|
+
if (streamError == null) {
|
|
80
|
+
return void 0;
|
|
81
|
+
}
|
|
82
|
+
const statusCode = getStatusCode(streamError);
|
|
83
|
+
return createProviderStreamError({
|
|
84
|
+
message: streamError.message,
|
|
85
|
+
type: (_a2 = streamError.type) != null ? _a2 : void 0,
|
|
86
|
+
code: (_b = streamError.code) != null ? _b : void 0,
|
|
87
|
+
statusCode,
|
|
88
|
+
isRetryable: isRetryableStreamError(streamError, statusCode),
|
|
89
|
+
data: frame
|
|
90
|
+
});
|
|
91
|
+
}
|
|
73
92
|
async function throwIfOpenAIStreamErrorBeforeOutput({
|
|
74
93
|
stream,
|
|
75
94
|
getError,
|
|
@@ -166,20 +185,21 @@ function createOpenAIStreamError({
|
|
|
166
185
|
requestBodyValues,
|
|
167
186
|
responseHeaders
|
|
168
187
|
}) {
|
|
169
|
-
var
|
|
170
|
-
const streamError =
|
|
188
|
+
var _a2, _b;
|
|
189
|
+
const streamError = createOpenAIProviderStreamError(frame);
|
|
171
190
|
return new APICallError({
|
|
172
|
-
message: (
|
|
191
|
+
message: (_a2 = streamError == null ? void 0 : streamError.message) != null ? _a2 : "OpenAI stream failed before any output was generated",
|
|
173
192
|
url,
|
|
174
193
|
requestBodyValues,
|
|
175
|
-
statusCode: streamError == null ?
|
|
194
|
+
statusCode: (_b = streamError == null ? void 0 : streamError.statusCode) != null ? _b : 500,
|
|
176
195
|
responseHeaders,
|
|
177
196
|
responseBody: JSON.stringify(frame),
|
|
178
|
-
data: frame
|
|
197
|
+
data: frame,
|
|
198
|
+
isRetryable: streamError == null ? void 0 : streamError.isRetryable
|
|
179
199
|
});
|
|
180
200
|
}
|
|
181
201
|
function parseStreamError(frame) {
|
|
182
|
-
var
|
|
202
|
+
var _a2;
|
|
183
203
|
const value = asRecord(frame);
|
|
184
204
|
if (value == null) {
|
|
185
205
|
return void 0;
|
|
@@ -190,27 +210,20 @@ function parseStreamError(frame) {
|
|
|
190
210
|
return typeof (responseError == null ? void 0 : responseError.message) === "string" ? {
|
|
191
211
|
message: responseError.message,
|
|
192
212
|
code: getStringOrNumber(responseError.code),
|
|
193
|
-
type: "response.failed"
|
|
194
|
-
frame
|
|
213
|
+
type: "response.failed"
|
|
195
214
|
} : void 0;
|
|
196
215
|
}
|
|
197
|
-
const error = (
|
|
216
|
+
const error = (_a2 = asRecord(value.error)) != null ? _a2 : value;
|
|
198
217
|
return typeof error.message === "string" && (asRecord(value.error) != null || typeof error.type === "string" || "code" in error || "param" in error) ? {
|
|
199
218
|
message: error.message,
|
|
200
219
|
code: getStringOrNumber(error.code),
|
|
201
|
-
type: typeof error.type === "string" ? error.type : void 0
|
|
202
|
-
frame
|
|
220
|
+
type: typeof error.type === "string" ? error.type : void 0
|
|
203
221
|
} : void 0;
|
|
204
222
|
}
|
|
205
223
|
function getStatusCode(error) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (typeof error.code === "string" && /^\d{3}$/.test(error.code)) {
|
|
210
|
-
const numericCode = Number(error.code);
|
|
211
|
-
if (isHttpErrorStatusCode(numericCode)) {
|
|
212
|
-
return numericCode;
|
|
213
|
-
}
|
|
224
|
+
const explicitStatusCode = getHttpStatusCode(error.code);
|
|
225
|
+
if (explicitStatusCode != null) {
|
|
226
|
+
return explicitStatusCode;
|
|
214
227
|
}
|
|
215
228
|
const discriminator = [error.code, error.type].filter((value) => typeof value === "string" || typeof value === "number").join(" ").toLowerCase();
|
|
216
229
|
if (["insufficient_quota", "rate_limit"].some(
|
|
@@ -239,15 +252,28 @@ function getStringOrNumber(value) {
|
|
|
239
252
|
function isHttpErrorStatusCode(value) {
|
|
240
253
|
return Number.isInteger(value) && value >= 400 && value <= 599;
|
|
241
254
|
}
|
|
255
|
+
function getHttpStatusCode(value) {
|
|
256
|
+
const statusCode = typeof value === "string" && /^\d{3}$/.test(value) ? Number(value) : value;
|
|
257
|
+
return typeof statusCode === "number" && isHttpErrorStatusCode(statusCode) ? statusCode : void 0;
|
|
258
|
+
}
|
|
259
|
+
function isRetryableStatusCode(statusCode) {
|
|
260
|
+
return statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500;
|
|
261
|
+
}
|
|
262
|
+
function isRetryableStreamError(error, statusCode) {
|
|
263
|
+
if (error.code === "insufficient_quota" || error.type === "insufficient_quota") {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
return isRetryableStatusCode(statusCode);
|
|
267
|
+
}
|
|
242
268
|
|
|
243
269
|
// src/chat/convert-openai-chat-usage.ts
|
|
244
270
|
import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
|
|
245
271
|
function convertOpenAIChatUsage(usage) {
|
|
246
|
-
var
|
|
272
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
247
273
|
if (usage == null) {
|
|
248
274
|
return createNullLanguageModelUsage();
|
|
249
275
|
}
|
|
250
|
-
const promptTokens = (
|
|
276
|
+
const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
|
|
251
277
|
const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
|
|
252
278
|
const cachedTokens = (_d = (_c = usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : 0;
|
|
253
279
|
const cacheWriteTokens = (_f = (_e = usage.prompt_tokens_details) == null ? void 0 : _e.cache_write_tokens) != null ? _f : void 0;
|
|
@@ -279,17 +305,19 @@ import {
|
|
|
279
305
|
resolveProviderReference
|
|
280
306
|
} from "@ai-sdk/provider-utils";
|
|
281
307
|
function serializeToolCallArguments(input) {
|
|
282
|
-
return JSON.stringify(
|
|
308
|
+
return JSON.stringify(
|
|
309
|
+
typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
|
|
310
|
+
);
|
|
283
311
|
}
|
|
284
312
|
function getPromptCacheBreakpoint(providerOptions) {
|
|
285
|
-
var
|
|
286
|
-
return (
|
|
313
|
+
var _a2;
|
|
314
|
+
return (_a2 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a2.promptCacheBreakpoint;
|
|
287
315
|
}
|
|
288
316
|
function convertToOpenAIChatMessages({
|
|
289
317
|
prompt,
|
|
290
318
|
systemMessageMode = "system"
|
|
291
319
|
}) {
|
|
292
|
-
var
|
|
320
|
+
var _a2, _b;
|
|
293
321
|
const messages = [];
|
|
294
322
|
const warnings = [];
|
|
295
323
|
for (const { role, content, providerOptions } of prompt) {
|
|
@@ -348,7 +376,7 @@ function convertToOpenAIChatMessages({
|
|
|
348
376
|
messages.push({
|
|
349
377
|
role: "user",
|
|
350
378
|
content: content.map((part, index) => {
|
|
351
|
-
var
|
|
379
|
+
var _a3, _b2, _c;
|
|
352
380
|
switch (part.type) {
|
|
353
381
|
case "text": {
|
|
354
382
|
const promptCacheBreakpoint = getPromptCacheBreakpoint(
|
|
@@ -394,7 +422,7 @@ function convertToOpenAIChatMessages({
|
|
|
394
422
|
type: "image_url",
|
|
395
423
|
image_url: {
|
|
396
424
|
url: part.data.type === "url" ? part.data.url.toString() : `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`,
|
|
397
|
-
detail: (_b2 = (
|
|
425
|
+
detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3.openai) == null ? void 0 : _b2.imageDetail
|
|
398
426
|
},
|
|
399
427
|
...promptCacheBreakpoint != null && {
|
|
400
428
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
@@ -519,7 +547,7 @@ function convertToOpenAIChatMessages({
|
|
|
519
547
|
continue;
|
|
520
548
|
}
|
|
521
549
|
const output = toolResponse.output;
|
|
522
|
-
const promptCacheBreakpoint = (
|
|
550
|
+
const promptCacheBreakpoint = (_a2 = output.type === "content" ? output.value.map((part) => getPromptCacheBreakpoint(part.providerOptions)).find((breakpoint) => breakpoint != null) : getPromptCacheBreakpoint(output.providerOptions)) != null ? _a2 : getPromptCacheBreakpoint(toolResponse.providerOptions);
|
|
523
551
|
let contentValue;
|
|
524
552
|
switch (output.type) {
|
|
525
553
|
case "text":
|
|
@@ -974,13 +1002,13 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
974
1002
|
reasoning,
|
|
975
1003
|
providerOptions
|
|
976
1004
|
}) {
|
|
977
|
-
var
|
|
1005
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
978
1006
|
const warnings = [];
|
|
979
|
-
const openaiOptions = (
|
|
1007
|
+
const openaiOptions = (_a2 = await parseProviderOptions({
|
|
980
1008
|
provider: "openai",
|
|
981
1009
|
providerOptions,
|
|
982
1010
|
schema: openaiLanguageModelChatOptions
|
|
983
|
-
})) != null ?
|
|
1011
|
+
})) != null ? _a2 : {};
|
|
984
1012
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
985
1013
|
const resolvedReasoningEffort = (_b = openaiOptions.reasoningEffort) != null ? _b : isCustomReasoning(reasoning) ? reasoning : void 0;
|
|
986
1014
|
const isReasoningModel = (_c = openaiOptions.forceReasoning) != null ? _c : modelCapabilities.isReasoningModel;
|
|
@@ -1143,7 +1171,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1143
1171
|
};
|
|
1144
1172
|
}
|
|
1145
1173
|
async doGenerate(options) {
|
|
1146
|
-
var
|
|
1174
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
1147
1175
|
const { args: body, warnings } = await this.getArgs(options);
|
|
1148
1176
|
const {
|
|
1149
1177
|
responseHeaders,
|
|
@@ -1154,7 +1182,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1154
1182
|
path: "/chat/completions",
|
|
1155
1183
|
modelId: this.modelId
|
|
1156
1184
|
}),
|
|
1157
|
-
headers: combineHeaders((_b = (
|
|
1185
|
+
headers: combineHeaders((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
1158
1186
|
body,
|
|
1159
1187
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1160
1188
|
successfulResponseHandler: createJsonResponseHandler(
|
|
@@ -1215,7 +1243,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1215
1243
|
};
|
|
1216
1244
|
}
|
|
1217
1245
|
async doStream(options) {
|
|
1218
|
-
var
|
|
1246
|
+
var _a2, _b;
|
|
1219
1247
|
const { args, warnings } = await this.getArgs(options);
|
|
1220
1248
|
const body = {
|
|
1221
1249
|
...args,
|
|
@@ -1230,7 +1258,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1230
1258
|
});
|
|
1231
1259
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
1232
1260
|
url,
|
|
1233
|
-
headers: combineHeaders((_b = (
|
|
1261
|
+
headers: combineHeaders((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
1234
1262
|
body,
|
|
1235
1263
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1236
1264
|
successfulResponseHandler: createEventSourceResponseHandler(
|
|
@@ -1267,7 +1295,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1267
1295
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1268
1296
|
},
|
|
1269
1297
|
transform(chunk, controller) {
|
|
1270
|
-
var
|
|
1298
|
+
var _a3, _b2, _c, _d, _e, _f;
|
|
1271
1299
|
if (options.includeRawChunks) {
|
|
1272
1300
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1273
1301
|
}
|
|
@@ -1279,7 +1307,10 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1279
1307
|
const value = chunk.value;
|
|
1280
1308
|
if ("error" in value) {
|
|
1281
1309
|
finishReason = { unified: "error", raw: void 0 };
|
|
1282
|
-
controller.enqueue({
|
|
1310
|
+
controller.enqueue({
|
|
1311
|
+
type: "error",
|
|
1312
|
+
error: (_a3 = createOpenAIProviderStreamError(value.error)) != null ? _a3 : value.error
|
|
1313
|
+
});
|
|
1283
1314
|
return;
|
|
1284
1315
|
}
|
|
1285
1316
|
if (!metadataExtracted) {
|
|
@@ -1294,11 +1325,11 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1294
1325
|
}
|
|
1295
1326
|
if (value.usage != null) {
|
|
1296
1327
|
usage = value.usage;
|
|
1297
|
-
if (((
|
|
1298
|
-
providerMetadata.openai.acceptedPredictionTokens = (
|
|
1328
|
+
if (((_b2 = value.usage.completion_tokens_details) == null ? void 0 : _b2.accepted_prediction_tokens) != null) {
|
|
1329
|
+
providerMetadata.openai.acceptedPredictionTokens = (_c = value.usage.completion_tokens_details) == null ? void 0 : _c.accepted_prediction_tokens;
|
|
1299
1330
|
}
|
|
1300
|
-
if (((
|
|
1301
|
-
providerMetadata.openai.rejectedPredictionTokens = (
|
|
1331
|
+
if (((_d = value.usage.completion_tokens_details) == null ? void 0 : _d.rejected_prediction_tokens) != null) {
|
|
1332
|
+
providerMetadata.openai.rejectedPredictionTokens = (_e = value.usage.completion_tokens_details) == null ? void 0 : _e.rejected_prediction_tokens;
|
|
1302
1333
|
}
|
|
1303
1334
|
}
|
|
1304
1335
|
const choice = value.choices[0];
|
|
@@ -1308,7 +1339,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1308
1339
|
raw: choice.finish_reason
|
|
1309
1340
|
};
|
|
1310
1341
|
}
|
|
1311
|
-
if (((
|
|
1342
|
+
if (((_f = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _f.content) != null) {
|
|
1312
1343
|
providerMetadata.openai.logprobs = choice.logprobs.content;
|
|
1313
1344
|
}
|
|
1314
1345
|
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
@@ -1388,11 +1419,11 @@ import {
|
|
|
1388
1419
|
// src/completion/convert-openai-completion-usage.ts
|
|
1389
1420
|
import { createNullLanguageModelUsage as createNullLanguageModelUsage2 } from "@ai-sdk/provider-utils";
|
|
1390
1421
|
function convertOpenAICompletionUsage(usage) {
|
|
1391
|
-
var
|
|
1422
|
+
var _a2, _b, _c, _d;
|
|
1392
1423
|
if (usage == null) {
|
|
1393
1424
|
return createNullLanguageModelUsage2();
|
|
1394
1425
|
}
|
|
1395
|
-
const promptTokens = (
|
|
1426
|
+
const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
|
|
1396
1427
|
const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
|
|
1397
1428
|
return {
|
|
1398
1429
|
inputTokens: {
|
|
@@ -1717,7 +1748,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
1717
1748
|
};
|
|
1718
1749
|
}
|
|
1719
1750
|
async doGenerate(options) {
|
|
1720
|
-
var
|
|
1751
|
+
var _a2, _b, _c;
|
|
1721
1752
|
const { args, warnings } = await this.getArgs(options);
|
|
1722
1753
|
const {
|
|
1723
1754
|
responseHeaders,
|
|
@@ -1728,7 +1759,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
1728
1759
|
path: "/completions",
|
|
1729
1760
|
modelId: this.modelId
|
|
1730
1761
|
}),
|
|
1731
|
-
headers: combineHeaders2((_b = (
|
|
1762
|
+
headers: combineHeaders2((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
1732
1763
|
body: args,
|
|
1733
1764
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1734
1765
|
successfulResponseHandler: createJsonResponseHandler2(
|
|
@@ -1760,7 +1791,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
1760
1791
|
};
|
|
1761
1792
|
}
|
|
1762
1793
|
async doStream(options) {
|
|
1763
|
-
var
|
|
1794
|
+
var _a2, _b;
|
|
1764
1795
|
const { args, warnings } = await this.getArgs(options);
|
|
1765
1796
|
const body = {
|
|
1766
1797
|
...args,
|
|
@@ -1775,7 +1806,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
1775
1806
|
});
|
|
1776
1807
|
const { responseHeaders, value: response } = await postJsonToApi2({
|
|
1777
1808
|
url,
|
|
1778
|
-
headers: combineHeaders2((_b = (
|
|
1809
|
+
headers: combineHeaders2((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
1779
1810
|
body,
|
|
1780
1811
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1781
1812
|
successfulResponseHandler: createEventSourceResponseHandler2(
|
|
@@ -1806,6 +1837,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
1806
1837
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1807
1838
|
},
|
|
1808
1839
|
transform(chunk, controller) {
|
|
1840
|
+
var _a3;
|
|
1809
1841
|
if (options.includeRawChunks) {
|
|
1810
1842
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1811
1843
|
}
|
|
@@ -1817,7 +1849,10 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
1817
1849
|
const value = chunk.value;
|
|
1818
1850
|
if ("error" in value) {
|
|
1819
1851
|
finishReason = { unified: "error", raw: void 0 };
|
|
1820
|
-
controller.enqueue({
|
|
1852
|
+
controller.enqueue({
|
|
1853
|
+
type: "error",
|
|
1854
|
+
error: (_a3 = createOpenAIProviderStreamError(value.error)) != null ? _a3 : value.error
|
|
1855
|
+
});
|
|
1821
1856
|
return;
|
|
1822
1857
|
}
|
|
1823
1858
|
if (isFirstChunk) {
|
|
@@ -1879,6 +1914,7 @@ import {
|
|
|
1879
1914
|
import {
|
|
1880
1915
|
combineHeaders as combineHeaders3,
|
|
1881
1916
|
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1917
|
+
EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL,
|
|
1882
1918
|
parseProviderOptions as parseProviderOptions3,
|
|
1883
1919
|
postJsonToApi as postJsonToApi3,
|
|
1884
1920
|
serializeModelOptions as serializeModelOptions3,
|
|
@@ -1922,15 +1958,17 @@ var openaiTextEmbeddingResponseSchema = lazySchema6(
|
|
|
1922
1958
|
);
|
|
1923
1959
|
|
|
1924
1960
|
// src/embedding/openai-embedding-model.ts
|
|
1961
|
+
var _a;
|
|
1925
1962
|
var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
|
|
1926
1963
|
constructor(modelId, config) {
|
|
1927
1964
|
this.specificationVersion = "v4";
|
|
1928
1965
|
this.maxEmbeddingsPerCall = 2048;
|
|
1966
|
+
this[_a] = 3e5;
|
|
1929
1967
|
this.supportsParallelCalls = true;
|
|
1930
1968
|
this.modelId = modelId;
|
|
1931
1969
|
this.config = config;
|
|
1932
1970
|
}
|
|
1933
|
-
static [WORKFLOW_SERIALIZE3](model) {
|
|
1971
|
+
static [(_a = EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, WORKFLOW_SERIALIZE3)](model) {
|
|
1934
1972
|
return serializeModelOptions3({
|
|
1935
1973
|
modelId: model.modelId,
|
|
1936
1974
|
config: model.config
|
|
@@ -1948,7 +1986,7 @@ var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
|
|
|
1948
1986
|
abortSignal,
|
|
1949
1987
|
providerOptions
|
|
1950
1988
|
}) {
|
|
1951
|
-
var
|
|
1989
|
+
var _a2, _b, _c;
|
|
1952
1990
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1953
1991
|
throw new TooManyEmbeddingValuesForCallError({
|
|
1954
1992
|
provider: this.provider,
|
|
@@ -1957,11 +1995,11 @@ var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
|
|
|
1957
1995
|
values
|
|
1958
1996
|
});
|
|
1959
1997
|
}
|
|
1960
|
-
const openaiOptions = (
|
|
1998
|
+
const openaiOptions = (_a2 = await parseProviderOptions3({
|
|
1961
1999
|
provider: "openai",
|
|
1962
2000
|
providerOptions,
|
|
1963
2001
|
schema: openaiEmbeddingModelOptions
|
|
1964
|
-
})) != null ?
|
|
2002
|
+
})) != null ? _a2 : {};
|
|
1965
2003
|
const {
|
|
1966
2004
|
responseHeaders,
|
|
1967
2005
|
value: response,
|
|
@@ -2062,8 +2100,8 @@ function hasDefaultResponseFormat(modelId) {
|
|
|
2062
2100
|
);
|
|
2063
2101
|
}
|
|
2064
2102
|
function getMaxImagesPerCall(modelId) {
|
|
2065
|
-
var
|
|
2066
|
-
return (
|
|
2103
|
+
var _a2;
|
|
2104
|
+
return (_a2 = modelMaxImagesPerCall[modelId]) != null ? _a2 : modelId.startsWith("gpt-image-") ? 10 : 1;
|
|
2067
2105
|
}
|
|
2068
2106
|
var baseImageModelOptionsObject = z9.object({
|
|
2069
2107
|
/**
|
|
@@ -2159,7 +2197,7 @@ var OpenAIImageModel = class _OpenAIImageModel {
|
|
|
2159
2197
|
headers,
|
|
2160
2198
|
abortSignal
|
|
2161
2199
|
}) {
|
|
2162
|
-
var
|
|
2200
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
2163
2201
|
const warnings = [];
|
|
2164
2202
|
if (aspectRatio != null) {
|
|
2165
2203
|
warnings.push({
|
|
@@ -2171,7 +2209,7 @@ var OpenAIImageModel = class _OpenAIImageModel {
|
|
|
2171
2209
|
if (seed != null) {
|
|
2172
2210
|
warnings.push({ type: "unsupported", feature: "seed" });
|
|
2173
2211
|
}
|
|
2174
|
-
const currentDate = (_c = (_b = (
|
|
2212
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2175
2213
|
if (files != null) {
|
|
2176
2214
|
const openaiOptions2 = (_d = await parseProviderOptions4({
|
|
2177
2215
|
provider: "openai",
|
|
@@ -2234,10 +2272,10 @@ var OpenAIImageModel = class _OpenAIImageModel {
|
|
|
2234
2272
|
providerMetadata: {
|
|
2235
2273
|
openai: {
|
|
2236
2274
|
images: response2.data.map((item, index) => {
|
|
2237
|
-
var
|
|
2275
|
+
var _a3, _b2, _c2, _d2, _e2, _f2;
|
|
2238
2276
|
return {
|
|
2239
2277
|
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
|
|
2240
|
-
created: (
|
|
2278
|
+
created: (_a3 = response2.created) != null ? _a3 : void 0,
|
|
2241
2279
|
size: (_b2 = response2.size) != null ? _b2 : void 0,
|
|
2242
2280
|
quality: (_c2 = response2.quality) != null ? _c2 : void 0,
|
|
2243
2281
|
background: (_d2 = response2.background) != null ? _d2 : void 0,
|
|
@@ -2301,10 +2339,10 @@ var OpenAIImageModel = class _OpenAIImageModel {
|
|
|
2301
2339
|
providerMetadata: {
|
|
2302
2340
|
openai: {
|
|
2303
2341
|
images: response.data.map((item, index) => {
|
|
2304
|
-
var
|
|
2342
|
+
var _a3, _b2, _c2, _d2, _e2, _f2;
|
|
2305
2343
|
return {
|
|
2306
2344
|
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
|
|
2307
|
-
created: (
|
|
2345
|
+
created: (_a3 = response.created) != null ? _a3 : void 0,
|
|
2308
2346
|
size: (_b2 = response.size) != null ? _b2 : void 0,
|
|
2309
2347
|
quality: (_c2 = response.quality) != null ? _c2 : void 0,
|
|
2310
2348
|
background: (_d2 = response.background) != null ? _d2 : void 0,
|
|
@@ -2589,13 +2627,13 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
2589
2627
|
};
|
|
2590
2628
|
}
|
|
2591
2629
|
async doGenerate(options) {
|
|
2592
|
-
var
|
|
2630
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2593
2631
|
if (isRealtimeTranscriptionModelId(this.modelId)) {
|
|
2594
2632
|
throw new UnsupportedFunctionalityError4({
|
|
2595
2633
|
functionality: `non-streaming transcription with ${this.modelId}`
|
|
2596
2634
|
});
|
|
2597
2635
|
}
|
|
2598
|
-
const currentDate = (_c = (_b = (
|
|
2636
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2599
2637
|
const { formData, warnings } = await this.getArgs(options);
|
|
2600
2638
|
const {
|
|
2601
2639
|
value: response,
|
|
@@ -2639,13 +2677,13 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
2639
2677
|
};
|
|
2640
2678
|
}
|
|
2641
2679
|
async doStream(options) {
|
|
2642
|
-
var
|
|
2680
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
2643
2681
|
if (!isRealtimeTranscriptionModelId(this.modelId)) {
|
|
2644
2682
|
throw new UnsupportedFunctionalityError4({
|
|
2645
2683
|
functionality: `streaming transcription with ${this.modelId}`
|
|
2646
2684
|
});
|
|
2647
2685
|
}
|
|
2648
|
-
const currentDate = (_c = (_b = (
|
|
2686
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2649
2687
|
const openAIOptions = await parseProviderOptions5({
|
|
2650
2688
|
provider: "openai",
|
|
2651
2689
|
providerOptions: options.providerOptions,
|
|
@@ -2784,7 +2822,7 @@ function createOpenAIRealtimeTranscriptionStream({
|
|
|
2784
2822
|
void sendAudio(socket).catch(finishWithError);
|
|
2785
2823
|
},
|
|
2786
2824
|
onMessageText: async (text) => {
|
|
2787
|
-
var
|
|
2825
|
+
var _a2, _b, _c, _d;
|
|
2788
2826
|
const parsed = await safeParseJSON({ text });
|
|
2789
2827
|
if (!parsed.success) return;
|
|
2790
2828
|
const raw = parsed.value;
|
|
@@ -2796,7 +2834,7 @@ function createOpenAIRealtimeTranscriptionStream({
|
|
|
2796
2834
|
controller.enqueue({
|
|
2797
2835
|
type: "transcript-delta",
|
|
2798
2836
|
id: raw.item_id,
|
|
2799
|
-
delta: (
|
|
2837
|
+
delta: (_a2 = raw.delta) != null ? _a2 : ""
|
|
2800
2838
|
});
|
|
2801
2839
|
break;
|
|
2802
2840
|
}
|
|
@@ -2835,7 +2873,7 @@ function buildOpenAIRealtimeTranscriptionSession({
|
|
|
2835
2873
|
inputAudioFormat,
|
|
2836
2874
|
providerOptions
|
|
2837
2875
|
}) {
|
|
2838
|
-
var
|
|
2876
|
+
var _a2, _b;
|
|
2839
2877
|
return {
|
|
2840
2878
|
type: "session.update",
|
|
2841
2879
|
session: {
|
|
@@ -2849,7 +2887,7 @@ function buildOpenAIRealtimeTranscriptionSession({
|
|
|
2849
2887
|
transcription: {
|
|
2850
2888
|
model: modelId,
|
|
2851
2889
|
...(providerOptions == null ? void 0 : providerOptions.language) != null ? { language: providerOptions.language } : {},
|
|
2852
|
-
...((
|
|
2890
|
+
...((_a2 = providerOptions == null ? void 0 : providerOptions.streaming) == null ? void 0 : _a2.delay) != null ? { delay: providerOptions.streaming.delay } : {}
|
|
2853
2891
|
},
|
|
2854
2892
|
turn_detection: null
|
|
2855
2893
|
}
|
|
@@ -2859,14 +2897,14 @@ function buildOpenAIRealtimeTranscriptionSession({
|
|
|
2859
2897
|
};
|
|
2860
2898
|
}
|
|
2861
2899
|
function getOpenAIRealtimeConnection(headers) {
|
|
2862
|
-
var
|
|
2900
|
+
var _a2;
|
|
2863
2901
|
let authorization;
|
|
2864
2902
|
for (const [key, value] of Object.entries(headers)) {
|
|
2865
2903
|
if (key.toLowerCase() === "authorization" && value != null) {
|
|
2866
2904
|
authorization = value;
|
|
2867
2905
|
}
|
|
2868
2906
|
}
|
|
2869
|
-
const token = (
|
|
2907
|
+
const token = (_a2 = authorization == null ? void 0 : authorization.match(/^bearer\s+(.+)$/i)) == null ? void 0 : _a2[1];
|
|
2870
2908
|
if (token == null) {
|
|
2871
2909
|
return { protocols: ["realtime"], headers };
|
|
2872
2910
|
}
|
|
@@ -2981,8 +3019,8 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
|
|
|
2981
3019
|
};
|
|
2982
3020
|
}
|
|
2983
3021
|
async doGenerate(options) {
|
|
2984
|
-
var
|
|
2985
|
-
const currentDate = (_c = (_b = (
|
|
3022
|
+
var _a2, _b, _c, _d, _e;
|
|
3023
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2986
3024
|
const { requestBody, warnings } = await this.getArgs(options);
|
|
2987
3025
|
const {
|
|
2988
3026
|
value: audio,
|
|
@@ -3037,13 +3075,13 @@ import {
|
|
|
3037
3075
|
// src/responses/convert-openai-responses-usage.ts
|
|
3038
3076
|
import { createNullLanguageModelUsage as createNullLanguageModelUsage3 } from "@ai-sdk/provider-utils";
|
|
3039
3077
|
function convertOpenAIResponsesUsage(usage) {
|
|
3040
|
-
var
|
|
3078
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
3041
3079
|
if (usage == null) {
|
|
3042
3080
|
return createNullLanguageModelUsage3();
|
|
3043
3081
|
}
|
|
3044
3082
|
const inputTokens = usage.input_tokens;
|
|
3045
3083
|
const outputTokens = usage.output_tokens;
|
|
3046
|
-
const cachedTokens = (_b = (
|
|
3084
|
+
const cachedTokens = (_b = (_a2 = usage.input_tokens_details) == null ? void 0 : _a2.cached_tokens) != null ? _b : 0;
|
|
3047
3085
|
const cacheWriteTokens = (_d = (_c = usage.input_tokens_details) == null ? void 0 : _c.cache_write_tokens) != null ? _d : void 0;
|
|
3048
3086
|
const reasoningTokens = (_f = (_e = usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0;
|
|
3049
3087
|
return {
|
|
@@ -3421,7 +3459,7 @@ var programmaticToolCallingFactory = createProviderExecutedToolFactory({
|
|
|
3421
3459
|
var programmaticToolCalling = () => experimental_toolCaller(programmaticToolCallingFactory({}), {
|
|
3422
3460
|
type: "provider",
|
|
3423
3461
|
prepareProviderOptions: (providerOptions) => {
|
|
3424
|
-
var
|
|
3462
|
+
var _a2;
|
|
3425
3463
|
const openaiOptions = providerOptions == null ? void 0 : providerOptions.openai;
|
|
3426
3464
|
return {
|
|
3427
3465
|
...providerOptions,
|
|
@@ -3429,7 +3467,7 @@ var programmaticToolCalling = () => experimental_toolCaller(programmaticToolCall
|
|
|
3429
3467
|
...openaiOptions,
|
|
3430
3468
|
allowedCallers: [
|
|
3431
3469
|
.../* @__PURE__ */ new Set([
|
|
3432
|
-
...(
|
|
3470
|
+
...(_a2 = openaiOptions == null ? void 0 : openaiOptions.allowedCallers) != null ? _a2 : [],
|
|
3433
3471
|
"programmatic"
|
|
3434
3472
|
])
|
|
3435
3473
|
]
|
|
@@ -3449,8 +3487,8 @@ function getParallelToolCallMetadata({
|
|
|
3449
3487
|
providerOptions,
|
|
3450
3488
|
providerOptionsName
|
|
3451
3489
|
}) {
|
|
3452
|
-
var
|
|
3453
|
-
const metadata = (
|
|
3490
|
+
var _a2;
|
|
3491
|
+
const metadata = (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.parallelToolCall;
|
|
3454
3492
|
if (!isJSONObject(metadata) || typeof metadata.itemId !== "string" || typeof metadata.toolCallId !== "string" || typeof metadata.toolName !== "string" || typeof metadata.input !== "string" || typeof metadata.index !== "number" || !Number.isInteger(metadata.index) || typeof metadata.count !== "number" || !Number.isInteger(metadata.count) || metadata.index < 0 || metadata.count <= metadata.index) {
|
|
3455
3493
|
return void 0;
|
|
3456
3494
|
}
|
|
@@ -3530,14 +3568,14 @@ async function convertFunctionToolResultOutput({
|
|
|
3530
3568
|
providerOptionsName,
|
|
3531
3569
|
warnings
|
|
3532
3570
|
}) {
|
|
3533
|
-
var
|
|
3571
|
+
var _a2;
|
|
3534
3572
|
const hasOutputSchema = outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.has(toolName);
|
|
3535
3573
|
switch (output.type) {
|
|
3536
3574
|
case "text":
|
|
3537
3575
|
case "error-text":
|
|
3538
3576
|
return hasOutputSchema ? JSON.stringify(output.value) : output.value;
|
|
3539
3577
|
case "execution-denied": {
|
|
3540
|
-
const reason = (
|
|
3578
|
+
const reason = (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
|
|
3541
3579
|
return hasOutputSchema ? JSON.stringify(reason) : reason;
|
|
3542
3580
|
}
|
|
3543
3581
|
case "json":
|
|
@@ -3545,7 +3583,7 @@ async function convertFunctionToolResultOutput({
|
|
|
3545
3583
|
return JSON.stringify(output.value);
|
|
3546
3584
|
case "content":
|
|
3547
3585
|
return output.value.map((item) => {
|
|
3548
|
-
var
|
|
3586
|
+
var _a3, _b, _c;
|
|
3549
3587
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
3550
3588
|
item.providerOptions,
|
|
3551
3589
|
providerOptionsName
|
|
@@ -3562,7 +3600,7 @@ async function convertFunctionToolResultOutput({
|
|
|
3562
3600
|
}
|
|
3563
3601
|
case "file": {
|
|
3564
3602
|
const topLevel = getTopLevelMediaType2(item.mediaType);
|
|
3565
|
-
const imageDetail = (_b = (
|
|
3603
|
+
const imageDetail = (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail;
|
|
3566
3604
|
if (item.data.type === "data") {
|
|
3567
3605
|
const fullMediaType = resolveFullMediaType2({ part: item });
|
|
3568
3606
|
if (topLevel === "image") {
|
|
@@ -3678,8 +3716,8 @@ function collectCompleteParallelToolResultGroups({
|
|
|
3678
3716
|
return completeGroups;
|
|
3679
3717
|
}
|
|
3680
3718
|
function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
|
|
3681
|
-
var
|
|
3682
|
-
return (
|
|
3719
|
+
var _a2;
|
|
3720
|
+
return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
|
|
3683
3721
|
}
|
|
3684
3722
|
function isFileId(data, prefixes) {
|
|
3685
3723
|
if (!prefixes) return false;
|
|
@@ -3699,10 +3737,11 @@ async function convertToOpenAIResponsesInput({
|
|
|
3699
3737
|
hasShellTool = false,
|
|
3700
3738
|
hasApplyPatchTool = false,
|
|
3701
3739
|
hasComputerTool = false,
|
|
3740
|
+
toolSearchToolName,
|
|
3702
3741
|
customProviderToolNames,
|
|
3703
3742
|
outputSchemaToolNames
|
|
3704
3743
|
}) {
|
|
3705
|
-
var
|
|
3744
|
+
var _a2, _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, _D, _E, _F, _G, _H, _I, _J, _K;
|
|
3706
3745
|
let input = [];
|
|
3707
3746
|
const warnings = [];
|
|
3708
3747
|
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
@@ -3770,7 +3809,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3770
3809
|
input.push({
|
|
3771
3810
|
role: "user",
|
|
3772
3811
|
content: content.map((part, index) => {
|
|
3773
|
-
var
|
|
3812
|
+
var _a3, _b2, _c2, _d2, _e2;
|
|
3774
3813
|
switch (part.type) {
|
|
3775
3814
|
case "text": {
|
|
3776
3815
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
@@ -3800,7 +3839,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3800
3839
|
return {
|
|
3801
3840
|
type: "input_image",
|
|
3802
3841
|
file_id: fileId,
|
|
3803
|
-
detail: (_b2 = (
|
|
3842
|
+
detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
|
|
3804
3843
|
...promptCacheBreakpoint != null && {
|
|
3805
3844
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3806
3845
|
}
|
|
@@ -3873,7 +3912,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3873
3912
|
for (const part of content) {
|
|
3874
3913
|
switch (part.type) {
|
|
3875
3914
|
case "text": {
|
|
3876
|
-
const providerOptions2 = (
|
|
3915
|
+
const providerOptions2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName];
|
|
3877
3916
|
const id = providerOptions2 == null ? void 0 : providerOptions2.itemId;
|
|
3878
3917
|
const phase = providerOptions2 == null ? void 0 : providerOptions2.phase;
|
|
3879
3918
|
if (hasConversation && id != null) {
|
|
@@ -3929,7 +3968,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3929
3968
|
const resolvedToolName = toolNameMapping.toProviderToolName(
|
|
3930
3969
|
part.toolName
|
|
3931
3970
|
);
|
|
3932
|
-
if (
|
|
3971
|
+
if (part.toolName === toolSearchToolName) {
|
|
3933
3972
|
if (store && id != null) {
|
|
3934
3973
|
input.push({ type: "item_reference", id });
|
|
3935
3974
|
break;
|
|
@@ -4118,7 +4157,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4118
4157
|
const resolvedResultToolName = toolNameMapping.toProviderToolName(
|
|
4119
4158
|
part.toolName
|
|
4120
4159
|
);
|
|
4121
|
-
if (
|
|
4160
|
+
if (part.toolName === toolSearchToolName) {
|
|
4122
4161
|
const itemId = (_u = (_t = (_q = (_p = part.providerOptions) == null ? void 0 : _p[providerOptionsName]) == null ? void 0 : _q.itemId) != null ? _t : (_s = (_r = part.providerMetadata) == null ? void 0 : _r[providerOptionsName]) == null ? void 0 : _s.itemId) != null ? _u : part.toolCallId;
|
|
4123
4162
|
if (store) {
|
|
4124
4163
|
input.push({ type: "item_reference", id: itemId });
|
|
@@ -4359,7 +4398,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4359
4398
|
const resolvedToolName = toolNameMapping.toProviderToolName(
|
|
4360
4399
|
part.toolName
|
|
4361
4400
|
);
|
|
4362
|
-
if (
|
|
4401
|
+
if (part.toolName === toolSearchToolName && output.type === "json") {
|
|
4363
4402
|
const parsedOutput = await validateTypes({
|
|
4364
4403
|
value: output.value,
|
|
4365
4404
|
schema: toolSearchOutputSchema
|
|
@@ -4455,7 +4494,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4455
4494
|
break;
|
|
4456
4495
|
case "content":
|
|
4457
4496
|
outputValue = output.value.map((item) => {
|
|
4458
|
-
var
|
|
4497
|
+
var _a3, _b2, _c2;
|
|
4459
4498
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
4460
4499
|
item.providerOptions,
|
|
4461
4500
|
providerOptionsName
|
|
@@ -4471,7 +4510,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4471
4510
|
};
|
|
4472
4511
|
case "file": {
|
|
4473
4512
|
const topLevel = getTopLevelMediaType2(item.mediaType);
|
|
4474
|
-
const imageDetail = (_b2 = (
|
|
4513
|
+
const imageDetail = (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail;
|
|
4475
4514
|
if (item.data.type === "data") {
|
|
4476
4515
|
const fullMediaType = resolveFullMediaType2({
|
|
4477
4516
|
part: item
|
|
@@ -4602,6 +4641,7 @@ function mapOpenAIResponseFinishReason({
|
|
|
4602
4641
|
|
|
4603
4642
|
// src/responses/openai-responses-api.ts
|
|
4604
4643
|
import {
|
|
4644
|
+
isRecord,
|
|
4605
4645
|
lazySchema as lazySchema18,
|
|
4606
4646
|
zodSchema as zodSchema18
|
|
4607
4647
|
} from "@ai-sdk/provider-utils";
|
|
@@ -4699,6 +4739,19 @@ var openaiResponsesProgramOutputSchema = z20.object({
|
|
|
4699
4739
|
result: z20.string(),
|
|
4700
4740
|
status: z20.enum(["completed", "incomplete"])
|
|
4701
4741
|
});
|
|
4742
|
+
var openaiResponsesLocalShellCallSchema = z20.object({
|
|
4743
|
+
type: z20.literal("local_shell_call"),
|
|
4744
|
+
id: z20.string(),
|
|
4745
|
+
call_id: z20.string(),
|
|
4746
|
+
action: z20.object({
|
|
4747
|
+
type: z20.literal("exec"),
|
|
4748
|
+
command: z20.array(z20.string()),
|
|
4749
|
+
timeout_ms: z20.number().optional(),
|
|
4750
|
+
user: z20.string().optional(),
|
|
4751
|
+
working_directory: z20.string().optional(),
|
|
4752
|
+
env: z20.record(z20.string(), z20.string()).optional()
|
|
4753
|
+
})
|
|
4754
|
+
});
|
|
4702
4755
|
var openaiResponsesNestedErrorChunkSchema = z20.object({
|
|
4703
4756
|
type: z20.literal("error"),
|
|
4704
4757
|
sequence_number: z20.number(),
|
|
@@ -4716,6 +4769,64 @@ var openaiResponsesErrorChunkSchema = z20.object({
|
|
|
4716
4769
|
message: z20.string(),
|
|
4717
4770
|
param: z20.string().nullish()
|
|
4718
4771
|
});
|
|
4772
|
+
var openaiResponsesModeledChunkTypes = /* @__PURE__ */ new Set([
|
|
4773
|
+
"error",
|
|
4774
|
+
"response.apply_patch_call_operation_diff.delta",
|
|
4775
|
+
"response.apply_patch_call_operation_diff.done",
|
|
4776
|
+
"response.code_interpreter_call_code.delta",
|
|
4777
|
+
"response.code_interpreter_call_code.done",
|
|
4778
|
+
"response.completed",
|
|
4779
|
+
"response.created",
|
|
4780
|
+
"response.custom_tool_call_input.delta",
|
|
4781
|
+
"response.failed",
|
|
4782
|
+
"response.function_call_arguments.delta",
|
|
4783
|
+
"response.function_call_arguments.done",
|
|
4784
|
+
"response.image_generation_call.partial_image",
|
|
4785
|
+
"response.in_progress",
|
|
4786
|
+
"response.incomplete",
|
|
4787
|
+
"response.output_item.added",
|
|
4788
|
+
"response.output_item.done",
|
|
4789
|
+
"response.output_text.annotation.added",
|
|
4790
|
+
"response.output_text.delta",
|
|
4791
|
+
"response.reasoning_summary_part.added",
|
|
4792
|
+
"response.reasoning_summary_part.done",
|
|
4793
|
+
"response.reasoning_summary_text.delta"
|
|
4794
|
+
]);
|
|
4795
|
+
var openaiResponsesModeledOutputItemTypes = /* @__PURE__ */ new Set([
|
|
4796
|
+
"apply_patch_call",
|
|
4797
|
+
"code_interpreter_call",
|
|
4798
|
+
"compaction",
|
|
4799
|
+
"computer_call",
|
|
4800
|
+
"custom_tool_call",
|
|
4801
|
+
"file_search_call",
|
|
4802
|
+
"function_call",
|
|
4803
|
+
"image_generation_call",
|
|
4804
|
+
"local_shell_call",
|
|
4805
|
+
"mcp_approval_request",
|
|
4806
|
+
"mcp_call",
|
|
4807
|
+
"mcp_list_tools",
|
|
4808
|
+
"message",
|
|
4809
|
+
"program",
|
|
4810
|
+
"program_output",
|
|
4811
|
+
"reasoning",
|
|
4812
|
+
"shell_call",
|
|
4813
|
+
"shell_call_output",
|
|
4814
|
+
"tool_search_call",
|
|
4815
|
+
"tool_search_output",
|
|
4816
|
+
"web_search_call"
|
|
4817
|
+
]);
|
|
4818
|
+
function isModeledOpenAIResponsesChunk(value) {
|
|
4819
|
+
if (typeof value.type !== "string" || !openaiResponsesModeledChunkTypes.has(value.type)) {
|
|
4820
|
+
return false;
|
|
4821
|
+
}
|
|
4822
|
+
if (value.type !== "response.output_item.added" && value.type !== "response.output_item.done") {
|
|
4823
|
+
return true;
|
|
4824
|
+
}
|
|
4825
|
+
if (!isRecord(value.item) || typeof value.item.type !== "string") {
|
|
4826
|
+
return true;
|
|
4827
|
+
}
|
|
4828
|
+
return openaiResponsesModeledOutputItemTypes.has(value.item.type);
|
|
4829
|
+
}
|
|
4719
4830
|
var openaiResponsesChunkSchema = lazySchema18(
|
|
4720
4831
|
() => zodSchema18(
|
|
4721
4832
|
z20.union([
|
|
@@ -4843,6 +4954,7 @@ var openaiResponsesChunkSchema = lazySchema18(
|
|
|
4843
4954
|
type: z20.literal("file_search_call"),
|
|
4844
4955
|
id: z20.string()
|
|
4845
4956
|
}),
|
|
4957
|
+
openaiResponsesLocalShellCallSchema,
|
|
4846
4958
|
z20.object({
|
|
4847
4959
|
type: z20.literal("image_generation_call"),
|
|
4848
4960
|
id: z20.string()
|
|
@@ -5049,19 +5161,7 @@ var openaiResponsesChunkSchema = lazySchema18(
|
|
|
5049
5161
|
})
|
|
5050
5162
|
).nullish()
|
|
5051
5163
|
}),
|
|
5052
|
-
|
|
5053
|
-
type: z20.literal("local_shell_call"),
|
|
5054
|
-
id: z20.string(),
|
|
5055
|
-
call_id: z20.string(),
|
|
5056
|
-
action: z20.object({
|
|
5057
|
-
type: z20.literal("exec"),
|
|
5058
|
-
command: z20.array(z20.string()),
|
|
5059
|
-
timeout_ms: z20.number().optional(),
|
|
5060
|
-
user: z20.string().optional(),
|
|
5061
|
-
working_directory: z20.string().optional(),
|
|
5062
|
-
env: z20.record(z20.string(), z20.string()).optional()
|
|
5063
|
-
})
|
|
5064
|
-
}),
|
|
5164
|
+
openaiResponsesLocalShellCallSchema,
|
|
5065
5165
|
openaiResponsesComputerCallSchema,
|
|
5066
5166
|
z20.object({
|
|
5067
5167
|
type: z20.literal("mcp_call"),
|
|
@@ -5189,6 +5289,14 @@ var openaiResponsesChunkSchema = lazySchema18(
|
|
|
5189
5289
|
output_index: z20.number(),
|
|
5190
5290
|
delta: z20.string()
|
|
5191
5291
|
}),
|
|
5292
|
+
z20.object({
|
|
5293
|
+
// `name` is documented as required but omitted from live API events:
|
|
5294
|
+
// https://github.com/openai/openai-openapi/issues/545
|
|
5295
|
+
type: z20.literal("response.function_call_arguments.done"),
|
|
5296
|
+
item_id: z20.string(),
|
|
5297
|
+
output_index: z20.number(),
|
|
5298
|
+
arguments: z20.string()
|
|
5299
|
+
}),
|
|
5192
5300
|
z20.object({
|
|
5193
5301
|
type: z20.literal("response.custom_tool_call_input.delta"),
|
|
5194
5302
|
item_id: z20.string(),
|
|
@@ -5278,7 +5386,9 @@ var openaiResponsesChunkSchema = lazySchema18(
|
|
|
5278
5386
|
}),
|
|
5279
5387
|
openaiResponsesNestedErrorChunkSchema,
|
|
5280
5388
|
openaiResponsesErrorChunkSchema,
|
|
5281
|
-
z20.object({ type: z20.string() }).loose().
|
|
5389
|
+
z20.object({ type: z20.string() }).loose().refine((value) => !isModeledOpenAIResponsesChunk(value), {
|
|
5390
|
+
message: "Known response chunk failed schema validation"
|
|
5391
|
+
}).transform((value) => ({
|
|
5282
5392
|
type: "unknown_chunk",
|
|
5283
5393
|
message: value.type
|
|
5284
5394
|
}))
|
|
@@ -5418,19 +5528,7 @@ var openaiResponsesResponseSchema = lazySchema18(
|
|
|
5418
5528
|
id: z20.string(),
|
|
5419
5529
|
result: z20.string()
|
|
5420
5530
|
}),
|
|
5421
|
-
|
|
5422
|
-
type: z20.literal("local_shell_call"),
|
|
5423
|
-
id: z20.string(),
|
|
5424
|
-
call_id: z20.string(),
|
|
5425
|
-
action: z20.object({
|
|
5426
|
-
type: z20.literal("exec"),
|
|
5427
|
-
command: z20.array(z20.string()),
|
|
5428
|
-
timeout_ms: z20.number().optional(),
|
|
5429
|
-
user: z20.string().optional(),
|
|
5430
|
-
working_directory: z20.string().optional(),
|
|
5431
|
-
env: z20.record(z20.string(), z20.string()).optional()
|
|
5432
|
-
})
|
|
5433
|
-
}),
|
|
5531
|
+
openaiResponsesLocalShellCallSchema,
|
|
5434
5532
|
z20.object({
|
|
5435
5533
|
type: z20.literal("function_call"),
|
|
5436
5534
|
call_id: z20.string(),
|
|
@@ -6258,7 +6356,7 @@ async function prepareResponsesTools({
|
|
|
6258
6356
|
customProviderToolNames,
|
|
6259
6357
|
outputSchemaToolNames
|
|
6260
6358
|
}) {
|
|
6261
|
-
var
|
|
6359
|
+
var _a2, _b, _c, _d;
|
|
6262
6360
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
6263
6361
|
const toolWarnings = [];
|
|
6264
6362
|
if (tools == null) {
|
|
@@ -6284,7 +6382,7 @@ async function prepareResponsesTools({
|
|
|
6284
6382
|
for (const tool of tools) {
|
|
6285
6383
|
switch (tool.type) {
|
|
6286
6384
|
case "function": {
|
|
6287
|
-
const openaiOptions = (
|
|
6385
|
+
const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
|
|
6288
6386
|
if ((openaiOptions == null ? void 0 : openaiOptions.outputSchema) != null) {
|
|
6289
6387
|
outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.add(tool.name);
|
|
6290
6388
|
}
|
|
@@ -6702,11 +6800,11 @@ function mapShellEnvironment(environment) {
|
|
|
6702
6800
|
function mapShellSkills(skills) {
|
|
6703
6801
|
return skills == null ? void 0 : skills.map(
|
|
6704
6802
|
(skill) => {
|
|
6705
|
-
var
|
|
6803
|
+
var _a2, _b;
|
|
6706
6804
|
return skill.type === "skillReference" ? {
|
|
6707
6805
|
type: "skill_reference",
|
|
6708
6806
|
skill_id: resolveProviderReference3({
|
|
6709
|
-
reference: (
|
|
6807
|
+
reference: (_a2 = skill.providerReference) != null ? _a2 : {},
|
|
6710
6808
|
provider: "openai"
|
|
6711
6809
|
}),
|
|
6712
6810
|
version: (_b = skill.version) != null ? _b : "latest"
|
|
@@ -6726,13 +6824,13 @@ function mapShellSkills(skills) {
|
|
|
6726
6824
|
|
|
6727
6825
|
// src/responses/openai-responses-language-model.ts
|
|
6728
6826
|
function extractApprovalRequestIdToToolCallIdMapping(prompt) {
|
|
6729
|
-
var
|
|
6827
|
+
var _a2, _b;
|
|
6730
6828
|
const mapping = {};
|
|
6731
6829
|
for (const message of prompt) {
|
|
6732
6830
|
if (message.role !== "assistant") continue;
|
|
6733
6831
|
for (const part of message.content) {
|
|
6734
6832
|
if (part.type !== "tool-call") continue;
|
|
6735
|
-
const approvalRequestId = (_b = (
|
|
6833
|
+
const approvalRequestId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.approvalRequestId;
|
|
6736
6834
|
if (approvalRequestId != null) {
|
|
6737
6835
|
mapping[approvalRequestId] = part.toolCallId;
|
|
6738
6836
|
}
|
|
@@ -6795,16 +6893,16 @@ function mapComputerCallInput({
|
|
|
6795
6893
|
pending_safety_checks,
|
|
6796
6894
|
status
|
|
6797
6895
|
}) {
|
|
6798
|
-
var
|
|
6896
|
+
var _a2;
|
|
6799
6897
|
return {
|
|
6800
6898
|
actions: (actions != null ? actions : action != null ? [action] : []).map(
|
|
6801
6899
|
mapComputerAction
|
|
6802
6900
|
),
|
|
6803
|
-
pendingSafetyChecks: (
|
|
6901
|
+
pendingSafetyChecks: (_a2 = pending_safety_checks == null ? void 0 : pending_safety_checks.map((safetyCheck) => ({
|
|
6804
6902
|
id: safetyCheck.id,
|
|
6805
6903
|
...safetyCheck.code != null && { code: safetyCheck.code },
|
|
6806
6904
|
...safetyCheck.message != null && { message: safetyCheck.message }
|
|
6807
|
-
}))) != null ?
|
|
6905
|
+
}))) != null ? _a2 : [],
|
|
6808
6906
|
status
|
|
6809
6907
|
};
|
|
6810
6908
|
}
|
|
@@ -6846,7 +6944,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
6846
6944
|
toolChoice,
|
|
6847
6945
|
responseFormat
|
|
6848
6946
|
}) {
|
|
6849
|
-
var
|
|
6947
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
6850
6948
|
const warnings = [];
|
|
6851
6949
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
6852
6950
|
if (topK != null) {
|
|
@@ -6877,7 +6975,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
6877
6975
|
schema: openaiLanguageModelResponsesOptionsSchema
|
|
6878
6976
|
});
|
|
6879
6977
|
}
|
|
6880
|
-
const resolvedReasoningEffort = (
|
|
6978
|
+
const resolvedReasoningEffort = (_a2 = openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null ? _a2 : isCustomReasoning2(reasoning) ? reasoning : void 0;
|
|
6881
6979
|
const resolvedReasoningSummary = (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) !== void 0 ? openaiOptions.reasoningSummary : resolvedReasoningEffort != null && resolvedReasoningEffort !== "none" ? "detailed" : void 0;
|
|
6882
6980
|
const isReasoningModel = (_b = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
|
|
6883
6981
|
if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
|
|
@@ -6932,6 +7030,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
6932
7030
|
hasShellTool: hasOpenAITool("openai.shell"),
|
|
6933
7031
|
hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
|
|
6934
7032
|
hasComputerTool: hasOpenAITool("openai.computer"),
|
|
7033
|
+
toolSearchToolName: getOpenAIToolName("openai.tool_search"),
|
|
6935
7034
|
customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0,
|
|
6936
7035
|
outputSchemaToolNames: outputSchemaToolNames.size > 0 ? outputSchemaToolNames : void 0
|
|
6937
7036
|
});
|
|
@@ -6948,8 +7047,12 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
6948
7047
|
include = [...include, key];
|
|
6949
7048
|
}
|
|
6950
7049
|
}
|
|
7050
|
+
function getOpenAIToolName(id) {
|
|
7051
|
+
var _a3;
|
|
7052
|
+
return (_a3 = tools == null ? void 0 : tools.find((tool) => tool.type === "provider" && tool.id === id)) == null ? void 0 : _a3.name;
|
|
7053
|
+
}
|
|
6951
7054
|
function hasOpenAITool(id) {
|
|
6952
|
-
return (
|
|
7055
|
+
return getOpenAIToolName(id) != null;
|
|
6953
7056
|
}
|
|
6954
7057
|
const topLogprobs = typeof (openaiOptions == null ? void 0 : openaiOptions.logprobs) === "number" ? openaiOptions == null ? void 0 : openaiOptions.logprobs : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? TOP_LOGPROBS_MAX : void 0;
|
|
6955
7058
|
if (topLogprobs) {
|
|
@@ -7116,7 +7219,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7116
7219
|
};
|
|
7117
7220
|
}
|
|
7118
7221
|
async doGenerate(options) {
|
|
7119
|
-
var
|
|
7222
|
+
var _a2, _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, _D, _E, _F, _G, _H;
|
|
7120
7223
|
const {
|
|
7121
7224
|
args: body,
|
|
7122
7225
|
warnings,
|
|
@@ -7136,7 +7239,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7136
7239
|
rawValue: rawResponse
|
|
7137
7240
|
} = await postJsonToApi6({
|
|
7138
7241
|
url,
|
|
7139
|
-
headers: combineHeaders7((_b = (
|
|
7242
|
+
headers: combineHeaders7((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
7140
7243
|
body,
|
|
7141
7244
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
7142
7245
|
successfulResponseHandler: createJsonResponseHandler6(
|
|
@@ -7697,7 +7800,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7697
7800
|
};
|
|
7698
7801
|
}
|
|
7699
7802
|
async doStream(options) {
|
|
7700
|
-
var
|
|
7803
|
+
var _a2, _b, _c, _d;
|
|
7701
7804
|
const {
|
|
7702
7805
|
args: body,
|
|
7703
7806
|
warnings,
|
|
@@ -7713,7 +7816,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7713
7816
|
});
|
|
7714
7817
|
const { responseHeaders, value: response } = await postJsonToApi6({
|
|
7715
7818
|
url,
|
|
7716
|
-
headers: combineHeaders7((_b = (
|
|
7819
|
+
headers: combineHeaders7((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
7717
7820
|
body: {
|
|
7718
7821
|
...body,
|
|
7719
7822
|
stream: true
|
|
@@ -7757,8 +7860,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7757
7860
|
itemId,
|
|
7758
7861
|
outputIndex
|
|
7759
7862
|
}) => {
|
|
7760
|
-
var
|
|
7761
|
-
return outputIndex == null ? itemId : (
|
|
7863
|
+
var _a3;
|
|
7864
|
+
return outputIndex == null ? itemId : (_a3 = activeOutputItemIds[outputIndex]) != null ? _a3 : itemId;
|
|
7762
7865
|
};
|
|
7763
7866
|
let serviceTier;
|
|
7764
7867
|
let reasoningContext;
|
|
@@ -7771,7 +7874,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7771
7874
|
controller.enqueue({ type: "stream-start", warnings });
|
|
7772
7875
|
},
|
|
7773
7876
|
transform(chunk, controller) {
|
|
7774
|
-
var
|
|
7877
|
+
var _a3, _b2, _c2, _d2, _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, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R;
|
|
7775
7878
|
if (options.includeRawChunks) {
|
|
7776
7879
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
7777
7880
|
}
|
|
@@ -7783,6 +7886,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7783
7886
|
requestBodyValues: body,
|
|
7784
7887
|
responseHeaders
|
|
7785
7888
|
}) : chunk.error;
|
|
7889
|
+
encounteredStreamError = true;
|
|
7786
7890
|
finishReason = { unified: "error", raw: void 0 };
|
|
7787
7891
|
controller.enqueue({ type: "error", error });
|
|
7788
7892
|
return;
|
|
@@ -7849,7 +7953,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7849
7953
|
providerExecuted: true
|
|
7850
7954
|
});
|
|
7851
7955
|
} else if (value.item.type === "computer_call") {
|
|
7852
|
-
const toolCallId = (
|
|
7956
|
+
const toolCallId = (_a3 = value.item.call_id) != null ? _a3 : value.item.id;
|
|
7853
7957
|
ongoingToolCalls[value.output_index] = {
|
|
7854
7958
|
toolName: toolNameMapping.toCustomToolName("computer"),
|
|
7855
7959
|
toolCallId
|
|
@@ -8021,14 +8125,14 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8021
8125
|
tools: functionTools
|
|
8022
8126
|
});
|
|
8023
8127
|
const enqueueUnexpandedToolCall = () => {
|
|
8024
|
-
var
|
|
8128
|
+
var _a4;
|
|
8025
8129
|
if (suppressInputStreaming) {
|
|
8026
8130
|
controller.enqueue({
|
|
8027
8131
|
type: "tool-input-start",
|
|
8028
8132
|
id: item.call_id,
|
|
8029
8133
|
toolName: item.name
|
|
8030
8134
|
});
|
|
8031
|
-
const bufferedInputDeltas = (
|
|
8135
|
+
const bufferedInputDeltas = (_a4 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a4 : [];
|
|
8032
8136
|
if (bufferedInputDeltas.length > 0) {
|
|
8033
8137
|
for (const delta of bufferedInputDeltas) {
|
|
8034
8138
|
controller.enqueue({
|
|
@@ -8696,13 +8800,15 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8696
8800
|
}
|
|
8697
8801
|
}
|
|
8698
8802
|
} else if (isResponseFinishedChunk(value)) {
|
|
8699
|
-
|
|
8700
|
-
|
|
8701
|
-
|
|
8702
|
-
|
|
8703
|
-
|
|
8704
|
-
|
|
8705
|
-
|
|
8803
|
+
if (!encounteredStreamError) {
|
|
8804
|
+
finishReason = {
|
|
8805
|
+
unified: mapOpenAIResponseFinishReason({
|
|
8806
|
+
finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
|
|
8807
|
+
hasFunctionCall
|
|
8808
|
+
}),
|
|
8809
|
+
raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
|
|
8810
|
+
};
|
|
8811
|
+
}
|
|
8706
8812
|
usage = value.response.usage;
|
|
8707
8813
|
if (typeof value.response.service_tier === "string") {
|
|
8708
8814
|
serviceTier = value.response.service_tier;
|
|
@@ -8725,17 +8831,18 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8725
8831
|
}
|
|
8726
8832
|
if (!encounteredStreamError && value.response.error != null) {
|
|
8727
8833
|
encounteredStreamError = true;
|
|
8834
|
+
const error = {
|
|
8835
|
+
type: "response.failed",
|
|
8836
|
+
sequence_number: value.sequence_number,
|
|
8837
|
+
response: {
|
|
8838
|
+
error: value.response.error,
|
|
8839
|
+
incomplete_details: value.response.incomplete_details,
|
|
8840
|
+
service_tier: value.response.service_tier
|
|
8841
|
+
}
|
|
8842
|
+
};
|
|
8728
8843
|
controller.enqueue({
|
|
8729
8844
|
type: "error",
|
|
8730
|
-
error:
|
|
8731
|
-
type: "response.failed",
|
|
8732
|
-
sequence_number: value.sequence_number,
|
|
8733
|
-
response: {
|
|
8734
|
-
error: value.response.error,
|
|
8735
|
-
incomplete_details: value.response.incomplete_details,
|
|
8736
|
-
service_tier: value.response.service_tier
|
|
8737
|
-
}
|
|
8738
|
-
}
|
|
8845
|
+
error: (_E = createOpenAIProviderStreamError(error)) != null ? _E : error
|
|
8739
8846
|
});
|
|
8740
8847
|
}
|
|
8741
8848
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
@@ -8744,7 +8851,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8744
8851
|
controller.enqueue({
|
|
8745
8852
|
type: "source",
|
|
8746
8853
|
sourceType: "url",
|
|
8747
|
-
id: (
|
|
8854
|
+
id: (_H = (_G = (_F = self.config).generateId) == null ? void 0 : _G.call(_F)) != null ? _H : generateId2(),
|
|
8748
8855
|
url: value.annotation.url,
|
|
8749
8856
|
title: value.annotation.title
|
|
8750
8857
|
});
|
|
@@ -8752,7 +8859,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8752
8859
|
controller.enqueue({
|
|
8753
8860
|
type: "source",
|
|
8754
8861
|
sourceType: "document",
|
|
8755
|
-
id: (
|
|
8862
|
+
id: (_K = (_J = (_I = self.config).generateId) == null ? void 0 : _J.call(_I)) != null ? _K : generateId2(),
|
|
8756
8863
|
mediaType: "text/plain",
|
|
8757
8864
|
title: value.annotation.filename,
|
|
8758
8865
|
filename: value.annotation.filename,
|
|
@@ -8768,7 +8875,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8768
8875
|
controller.enqueue({
|
|
8769
8876
|
type: "source",
|
|
8770
8877
|
sourceType: "document",
|
|
8771
|
-
id: (
|
|
8878
|
+
id: (_N = (_M = (_L = self.config).generateId) == null ? void 0 : _M.call(_L)) != null ? _N : generateId2(),
|
|
8772
8879
|
mediaType: "text/plain",
|
|
8773
8880
|
title: value.annotation.filename,
|
|
8774
8881
|
filename: value.annotation.filename,
|
|
@@ -8784,7 +8891,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8784
8891
|
controller.enqueue({
|
|
8785
8892
|
type: "source",
|
|
8786
8893
|
sourceType: "document",
|
|
8787
|
-
id: (
|
|
8894
|
+
id: (_Q = (_P = (_O = self.config).generateId) == null ? void 0 : _P.call(_O)) != null ? _Q : generateId2(),
|
|
8788
8895
|
mediaType: "application/octet-stream",
|
|
8789
8896
|
title: value.annotation.file_id,
|
|
8790
8897
|
filename: value.annotation.file_id,
|
|
@@ -8800,11 +8907,14 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8800
8907
|
} else if (isErrorChunk(value)) {
|
|
8801
8908
|
encounteredStreamError = true;
|
|
8802
8909
|
finishReason = { unified: "error", raw: "error" };
|
|
8803
|
-
controller.enqueue({
|
|
8910
|
+
controller.enqueue({
|
|
8911
|
+
type: "error",
|
|
8912
|
+
error: (_R = createOpenAIProviderStreamError(value)) != null ? _R : value
|
|
8913
|
+
});
|
|
8804
8914
|
}
|
|
8805
8915
|
},
|
|
8806
8916
|
flush(controller) {
|
|
8807
|
-
var
|
|
8917
|
+
var _a3;
|
|
8808
8918
|
for (const toolCall of Object.values(ongoingToolCalls)) {
|
|
8809
8919
|
if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
|
|
8810
8920
|
continue;
|
|
@@ -8814,7 +8924,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8814
8924
|
id: toolCall.toolCallId,
|
|
8815
8925
|
toolName: toolCall.toolName
|
|
8816
8926
|
});
|
|
8817
|
-
for (const delta of (
|
|
8927
|
+
for (const delta of (_a3 = toolCall.bufferedInputDeltas) != null ? _a3 : []) {
|
|
8818
8928
|
controller.enqueue({
|
|
8819
8929
|
type: "tool-input-delta",
|
|
8820
8930
|
id: toolCall.toolCallId,
|
|
@@ -8922,7 +9032,7 @@ function isResponseOutputChunk(chunk) {
|
|
|
8922
9032
|
return !(chunk.type === "response.created" || chunk.type === "response.in_progress" || chunk.type === "response.failed" || chunk.type === "error" || chunk.type === "unknown_chunk");
|
|
8923
9033
|
}
|
|
8924
9034
|
function mapWebSearchOutput(action) {
|
|
8925
|
-
var
|
|
9035
|
+
var _a2;
|
|
8926
9036
|
if (action == null) {
|
|
8927
9037
|
return {};
|
|
8928
9038
|
}
|
|
@@ -8931,7 +9041,7 @@ function mapWebSearchOutput(action) {
|
|
|
8931
9041
|
return {
|
|
8932
9042
|
action: {
|
|
8933
9043
|
type: "search",
|
|
8934
|
-
query: (
|
|
9044
|
+
query: (_a2 = action.query) != null ? _a2 : void 0,
|
|
8935
9045
|
...action.queries != null && { queries: action.queries }
|
|
8936
9046
|
},
|
|
8937
9047
|
// include sources when provided by the Responses API (behind include flag)
|