@ai-sdk/openai 2.0.25 → 2.0.26
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 +7 -0
- package/dist/index.d.mts +47 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +371 -320
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +340 -289
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +310 -263
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +298 -251
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ __export(src_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(src_exports);
|
|
27
27
|
|
|
28
28
|
// src/openai-provider.ts
|
|
29
|
-
var
|
|
29
|
+
var import_provider_utils16 = require("@ai-sdk/provider-utils");
|
|
30
30
|
|
|
31
31
|
// src/chat/openai-chat-language-model.ts
|
|
32
32
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -1825,23 +1825,65 @@ var codeInterpreter = (0, import_provider_utils9.createProviderDefinedToolFactor
|
|
|
1825
1825
|
inputSchema: import_v411.z.object({})
|
|
1826
1826
|
});
|
|
1827
1827
|
|
|
1828
|
+
// src/tool/web-search.ts
|
|
1829
|
+
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
|
1830
|
+
var import_v412 = require("zod/v4");
|
|
1831
|
+
var webSearchArgsSchema = import_v412.z.object({
|
|
1832
|
+
filters: import_v412.z.object({
|
|
1833
|
+
allowedDomains: import_v412.z.array(import_v412.z.string()).optional()
|
|
1834
|
+
}).optional(),
|
|
1835
|
+
searchContextSize: import_v412.z.enum(["low", "medium", "high"]).optional(),
|
|
1836
|
+
userLocation: import_v412.z.object({
|
|
1837
|
+
type: import_v412.z.literal("approximate"),
|
|
1838
|
+
country: import_v412.z.string().optional(),
|
|
1839
|
+
city: import_v412.z.string().optional(),
|
|
1840
|
+
region: import_v412.z.string().optional(),
|
|
1841
|
+
timezone: import_v412.z.string().optional()
|
|
1842
|
+
}).optional()
|
|
1843
|
+
});
|
|
1844
|
+
var factory = (0, import_provider_utils10.createProviderDefinedToolFactory)({
|
|
1845
|
+
id: "openai.web_search",
|
|
1846
|
+
name: "web_search",
|
|
1847
|
+
inputSchema: import_v412.z.object({
|
|
1848
|
+
action: import_v412.z.discriminatedUnion("type", [
|
|
1849
|
+
import_v412.z.object({
|
|
1850
|
+
type: import_v412.z.literal("search"),
|
|
1851
|
+
query: import_v412.z.string().nullish()
|
|
1852
|
+
}),
|
|
1853
|
+
import_v412.z.object({
|
|
1854
|
+
type: import_v412.z.literal("open_page"),
|
|
1855
|
+
url: import_v412.z.string()
|
|
1856
|
+
}),
|
|
1857
|
+
import_v412.z.object({
|
|
1858
|
+
type: import_v412.z.literal("find"),
|
|
1859
|
+
url: import_v412.z.string(),
|
|
1860
|
+
pattern: import_v412.z.string()
|
|
1861
|
+
})
|
|
1862
|
+
]).nullish()
|
|
1863
|
+
})
|
|
1864
|
+
});
|
|
1865
|
+
var webSearch = (args = {}) => {
|
|
1866
|
+
return factory(args);
|
|
1867
|
+
};
|
|
1868
|
+
|
|
1828
1869
|
// src/openai-tools.ts
|
|
1829
1870
|
var openaiTools = {
|
|
1830
1871
|
codeInterpreter,
|
|
1831
1872
|
fileSearch,
|
|
1832
|
-
webSearchPreview
|
|
1873
|
+
webSearchPreview,
|
|
1874
|
+
webSearch
|
|
1833
1875
|
};
|
|
1834
1876
|
|
|
1835
1877
|
// src/responses/openai-responses-language-model.ts
|
|
1836
1878
|
var import_provider8 = require("@ai-sdk/provider");
|
|
1837
|
-
var
|
|
1838
|
-
var
|
|
1879
|
+
var import_provider_utils13 = require("@ai-sdk/provider-utils");
|
|
1880
|
+
var import_v414 = require("zod/v4");
|
|
1839
1881
|
|
|
1840
1882
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1841
1883
|
var import_provider6 = require("@ai-sdk/provider");
|
|
1842
|
-
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
|
1843
|
-
var import_v412 = require("zod/v4");
|
|
1844
1884
|
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
|
1885
|
+
var import_v413 = require("zod/v4");
|
|
1886
|
+
var import_provider_utils12 = require("@ai-sdk/provider-utils");
|
|
1845
1887
|
function isFileId(data, prefixes) {
|
|
1846
1888
|
if (!prefixes) return false;
|
|
1847
1889
|
return prefixes.some((prefix) => data.startsWith(prefix));
|
|
@@ -1897,7 +1939,7 @@ async function convertToOpenAIResponsesMessages({
|
|
|
1897
1939
|
return {
|
|
1898
1940
|
type: "input_image",
|
|
1899
1941
|
...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
1900
|
-
image_url: `data:${mediaType};base64,${(0,
|
|
1942
|
+
image_url: `data:${mediaType};base64,${(0, import_provider_utils12.convertToBase64)(part.data)}`
|
|
1901
1943
|
},
|
|
1902
1944
|
detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
|
|
1903
1945
|
};
|
|
@@ -1912,7 +1954,7 @@ async function convertToOpenAIResponsesMessages({
|
|
|
1912
1954
|
type: "input_file",
|
|
1913
1955
|
...typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
1914
1956
|
filename: (_c2 = part.filename) != null ? _c2 : `part-${index}.pdf`,
|
|
1915
|
-
file_data: `data:application/pdf;base64,${(0,
|
|
1957
|
+
file_data: `data:application/pdf;base64,${(0, import_provider_utils12.convertToBase64)(part.data)}`
|
|
1916
1958
|
}
|
|
1917
1959
|
};
|
|
1918
1960
|
} else {
|
|
@@ -1959,7 +2001,7 @@ async function convertToOpenAIResponsesMessages({
|
|
|
1959
2001
|
break;
|
|
1960
2002
|
}
|
|
1961
2003
|
case "reasoning": {
|
|
1962
|
-
const providerOptions = await (0,
|
|
2004
|
+
const providerOptions = await (0, import_provider_utils11.parseProviderOptions)({
|
|
1963
2005
|
provider: "openai",
|
|
1964
2006
|
providerOptions: part.providerOptions,
|
|
1965
2007
|
schema: openaiResponsesReasoningProviderOptionsSchema
|
|
@@ -2030,26 +2072,26 @@ async function convertToOpenAIResponsesMessages({
|
|
|
2030
2072
|
}
|
|
2031
2073
|
return { messages, warnings };
|
|
2032
2074
|
}
|
|
2033
|
-
var openaiResponsesReasoningProviderOptionsSchema =
|
|
2034
|
-
itemId:
|
|
2035
|
-
reasoningEncryptedContent:
|
|
2075
|
+
var openaiResponsesReasoningProviderOptionsSchema = import_v413.z.object({
|
|
2076
|
+
itemId: import_v413.z.string().nullish(),
|
|
2077
|
+
reasoningEncryptedContent: import_v413.z.string().nullish()
|
|
2036
2078
|
});
|
|
2037
2079
|
|
|
2038
2080
|
// src/responses/map-openai-responses-finish-reason.ts
|
|
2039
2081
|
function mapOpenAIResponseFinishReason({
|
|
2040
2082
|
finishReason,
|
|
2041
|
-
|
|
2083
|
+
hasFunctionCall
|
|
2042
2084
|
}) {
|
|
2043
2085
|
switch (finishReason) {
|
|
2044
2086
|
case void 0:
|
|
2045
2087
|
case null:
|
|
2046
|
-
return
|
|
2088
|
+
return hasFunctionCall ? "tool-calls" : "stop";
|
|
2047
2089
|
case "max_output_tokens":
|
|
2048
2090
|
return "length";
|
|
2049
2091
|
case "content_filter":
|
|
2050
2092
|
return "content-filter";
|
|
2051
2093
|
default:
|
|
2052
|
-
return
|
|
2094
|
+
return hasFunctionCall ? "tool-calls" : "unknown";
|
|
2053
2095
|
}
|
|
2054
2096
|
}
|
|
2055
2097
|
|
|
@@ -2099,6 +2141,16 @@ function prepareResponsesTools({
|
|
|
2099
2141
|
});
|
|
2100
2142
|
break;
|
|
2101
2143
|
}
|
|
2144
|
+
case "openai.web_search": {
|
|
2145
|
+
const args = webSearchArgsSchema.parse(tool.args);
|
|
2146
|
+
openaiTools2.push({
|
|
2147
|
+
type: "web_search",
|
|
2148
|
+
filters: args.filters != null ? { allowed_domains: args.filters.allowedDomains } : void 0,
|
|
2149
|
+
search_context_size: args.searchContextSize,
|
|
2150
|
+
user_location: args.userLocation
|
|
2151
|
+
});
|
|
2152
|
+
break;
|
|
2153
|
+
}
|
|
2102
2154
|
case "openai.code_interpreter": {
|
|
2103
2155
|
const args = codeInterpreterArgsSchema.parse(tool.args);
|
|
2104
2156
|
openaiTools2.push({
|
|
@@ -2131,7 +2183,7 @@ function prepareResponsesTools({
|
|
|
2131
2183
|
case "tool":
|
|
2132
2184
|
return {
|
|
2133
2185
|
tools: openaiTools2,
|
|
2134
|
-
toolChoice: toolChoice.toolName === "code_interpreter" || toolChoice.toolName === "file_search" || toolChoice.toolName === "web_search_preview" ? { type: toolChoice.toolName } : { type: "function", name: toolChoice.toolName },
|
|
2186
|
+
toolChoice: toolChoice.toolName === "code_interpreter" || toolChoice.toolName === "file_search" || toolChoice.toolName === "web_search_preview" || toolChoice.toolName === "web_search" ? { type: toolChoice.toolName } : { type: "function", name: toolChoice.toolName },
|
|
2135
2187
|
toolWarnings
|
|
2136
2188
|
};
|
|
2137
2189
|
default: {
|
|
@@ -2144,35 +2196,35 @@ function prepareResponsesTools({
|
|
|
2144
2196
|
}
|
|
2145
2197
|
|
|
2146
2198
|
// src/responses/openai-responses-language-model.ts
|
|
2147
|
-
var webSearchCallItem =
|
|
2148
|
-
type:
|
|
2149
|
-
id:
|
|
2150
|
-
status:
|
|
2151
|
-
action:
|
|
2152
|
-
|
|
2153
|
-
type:
|
|
2154
|
-
query:
|
|
2199
|
+
var webSearchCallItem = import_v414.z.object({
|
|
2200
|
+
type: import_v414.z.literal("web_search_call"),
|
|
2201
|
+
id: import_v414.z.string(),
|
|
2202
|
+
status: import_v414.z.string(),
|
|
2203
|
+
action: import_v414.z.discriminatedUnion("type", [
|
|
2204
|
+
import_v414.z.object({
|
|
2205
|
+
type: import_v414.z.literal("search"),
|
|
2206
|
+
query: import_v414.z.string().nullish()
|
|
2155
2207
|
}),
|
|
2156
|
-
|
|
2157
|
-
type:
|
|
2158
|
-
url:
|
|
2208
|
+
import_v414.z.object({
|
|
2209
|
+
type: import_v414.z.literal("open_page"),
|
|
2210
|
+
url: import_v414.z.string()
|
|
2159
2211
|
}),
|
|
2160
|
-
|
|
2161
|
-
type:
|
|
2162
|
-
url:
|
|
2163
|
-
pattern:
|
|
2212
|
+
import_v414.z.object({
|
|
2213
|
+
type: import_v414.z.literal("find"),
|
|
2214
|
+
url: import_v414.z.string(),
|
|
2215
|
+
pattern: import_v414.z.string()
|
|
2164
2216
|
})
|
|
2165
2217
|
]).nullish()
|
|
2166
2218
|
});
|
|
2167
2219
|
var TOP_LOGPROBS_MAX = 20;
|
|
2168
|
-
var LOGPROBS_SCHEMA =
|
|
2169
|
-
|
|
2170
|
-
token:
|
|
2171
|
-
logprob:
|
|
2172
|
-
top_logprobs:
|
|
2173
|
-
|
|
2174
|
-
token:
|
|
2175
|
-
logprob:
|
|
2220
|
+
var LOGPROBS_SCHEMA = import_v414.z.array(
|
|
2221
|
+
import_v414.z.object({
|
|
2222
|
+
token: import_v414.z.string(),
|
|
2223
|
+
logprob: import_v414.z.number(),
|
|
2224
|
+
top_logprobs: import_v414.z.array(
|
|
2225
|
+
import_v414.z.object({
|
|
2226
|
+
token: import_v414.z.string(),
|
|
2227
|
+
logprob: import_v414.z.number()
|
|
2176
2228
|
})
|
|
2177
2229
|
)
|
|
2178
2230
|
})
|
|
@@ -2235,7 +2287,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2235
2287
|
fileIdPrefixes: this.config.fileIdPrefixes
|
|
2236
2288
|
});
|
|
2237
2289
|
warnings.push(...messageWarnings);
|
|
2238
|
-
const openaiOptions = await (0,
|
|
2290
|
+
const openaiOptions = await (0, import_provider_utils13.parseProviderOptions)({
|
|
2239
2291
|
provider: "openai",
|
|
2240
2292
|
providerOptions,
|
|
2241
2293
|
schema: openaiResponsesProviderOptionsSchema
|
|
@@ -2370,98 +2422,98 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2370
2422
|
responseHeaders,
|
|
2371
2423
|
value: response,
|
|
2372
2424
|
rawValue: rawResponse
|
|
2373
|
-
} = await (0,
|
|
2425
|
+
} = await (0, import_provider_utils13.postJsonToApi)({
|
|
2374
2426
|
url,
|
|
2375
|
-
headers: (0,
|
|
2427
|
+
headers: (0, import_provider_utils13.combineHeaders)(this.config.headers(), options.headers),
|
|
2376
2428
|
body,
|
|
2377
2429
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2378
|
-
successfulResponseHandler: (0,
|
|
2379
|
-
|
|
2380
|
-
id:
|
|
2381
|
-
created_at:
|
|
2382
|
-
error:
|
|
2383
|
-
code:
|
|
2384
|
-
message:
|
|
2430
|
+
successfulResponseHandler: (0, import_provider_utils13.createJsonResponseHandler)(
|
|
2431
|
+
import_v414.z.object({
|
|
2432
|
+
id: import_v414.z.string(),
|
|
2433
|
+
created_at: import_v414.z.number(),
|
|
2434
|
+
error: import_v414.z.object({
|
|
2435
|
+
code: import_v414.z.string(),
|
|
2436
|
+
message: import_v414.z.string()
|
|
2385
2437
|
}).nullish(),
|
|
2386
|
-
model:
|
|
2387
|
-
output:
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
type:
|
|
2391
|
-
role:
|
|
2392
|
-
id:
|
|
2393
|
-
content:
|
|
2394
|
-
|
|
2395
|
-
type:
|
|
2396
|
-
text:
|
|
2438
|
+
model: import_v414.z.string(),
|
|
2439
|
+
output: import_v414.z.array(
|
|
2440
|
+
import_v414.z.discriminatedUnion("type", [
|
|
2441
|
+
import_v414.z.object({
|
|
2442
|
+
type: import_v414.z.literal("message"),
|
|
2443
|
+
role: import_v414.z.literal("assistant"),
|
|
2444
|
+
id: import_v414.z.string(),
|
|
2445
|
+
content: import_v414.z.array(
|
|
2446
|
+
import_v414.z.object({
|
|
2447
|
+
type: import_v414.z.literal("output_text"),
|
|
2448
|
+
text: import_v414.z.string(),
|
|
2397
2449
|
logprobs: LOGPROBS_SCHEMA.nullish(),
|
|
2398
|
-
annotations:
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
type:
|
|
2402
|
-
start_index:
|
|
2403
|
-
end_index:
|
|
2404
|
-
url:
|
|
2405
|
-
title:
|
|
2450
|
+
annotations: import_v414.z.array(
|
|
2451
|
+
import_v414.z.discriminatedUnion("type", [
|
|
2452
|
+
import_v414.z.object({
|
|
2453
|
+
type: import_v414.z.literal("url_citation"),
|
|
2454
|
+
start_index: import_v414.z.number(),
|
|
2455
|
+
end_index: import_v414.z.number(),
|
|
2456
|
+
url: import_v414.z.string(),
|
|
2457
|
+
title: import_v414.z.string()
|
|
2406
2458
|
}),
|
|
2407
|
-
|
|
2408
|
-
type:
|
|
2409
|
-
file_id:
|
|
2410
|
-
filename:
|
|
2411
|
-
index:
|
|
2412
|
-
start_index:
|
|
2413
|
-
end_index:
|
|
2414
|
-
quote:
|
|
2459
|
+
import_v414.z.object({
|
|
2460
|
+
type: import_v414.z.literal("file_citation"),
|
|
2461
|
+
file_id: import_v414.z.string(),
|
|
2462
|
+
filename: import_v414.z.string().nullish(),
|
|
2463
|
+
index: import_v414.z.number().nullish(),
|
|
2464
|
+
start_index: import_v414.z.number().nullish(),
|
|
2465
|
+
end_index: import_v414.z.number().nullish(),
|
|
2466
|
+
quote: import_v414.z.string().nullish()
|
|
2415
2467
|
})
|
|
2416
2468
|
])
|
|
2417
2469
|
)
|
|
2418
2470
|
})
|
|
2419
2471
|
)
|
|
2420
2472
|
}),
|
|
2421
|
-
|
|
2422
|
-
type:
|
|
2423
|
-
call_id:
|
|
2424
|
-
name:
|
|
2425
|
-
arguments:
|
|
2426
|
-
id:
|
|
2473
|
+
import_v414.z.object({
|
|
2474
|
+
type: import_v414.z.literal("function_call"),
|
|
2475
|
+
call_id: import_v414.z.string(),
|
|
2476
|
+
name: import_v414.z.string(),
|
|
2477
|
+
arguments: import_v414.z.string(),
|
|
2478
|
+
id: import_v414.z.string()
|
|
2427
2479
|
}),
|
|
2428
2480
|
webSearchCallItem,
|
|
2429
|
-
|
|
2430
|
-
type:
|
|
2431
|
-
id:
|
|
2432
|
-
status:
|
|
2481
|
+
import_v414.z.object({
|
|
2482
|
+
type: import_v414.z.literal("computer_call"),
|
|
2483
|
+
id: import_v414.z.string(),
|
|
2484
|
+
status: import_v414.z.string().optional()
|
|
2433
2485
|
}),
|
|
2434
|
-
|
|
2435
|
-
type:
|
|
2436
|
-
id:
|
|
2437
|
-
status:
|
|
2438
|
-
queries:
|
|
2439
|
-
results:
|
|
2440
|
-
|
|
2441
|
-
attributes:
|
|
2442
|
-
file_id:
|
|
2443
|
-
filename:
|
|
2444
|
-
score:
|
|
2445
|
-
text:
|
|
2486
|
+
import_v414.z.object({
|
|
2487
|
+
type: import_v414.z.literal("file_search_call"),
|
|
2488
|
+
id: import_v414.z.string(),
|
|
2489
|
+
status: import_v414.z.string().optional(),
|
|
2490
|
+
queries: import_v414.z.array(import_v414.z.string()).nullish(),
|
|
2491
|
+
results: import_v414.z.array(
|
|
2492
|
+
import_v414.z.object({
|
|
2493
|
+
attributes: import_v414.z.object({
|
|
2494
|
+
file_id: import_v414.z.string(),
|
|
2495
|
+
filename: import_v414.z.string(),
|
|
2496
|
+
score: import_v414.z.number(),
|
|
2497
|
+
text: import_v414.z.string()
|
|
2446
2498
|
})
|
|
2447
2499
|
})
|
|
2448
2500
|
).nullish()
|
|
2449
2501
|
}),
|
|
2450
|
-
|
|
2451
|
-
type:
|
|
2452
|
-
id:
|
|
2453
|
-
encrypted_content:
|
|
2454
|
-
summary:
|
|
2455
|
-
|
|
2456
|
-
type:
|
|
2457
|
-
text:
|
|
2502
|
+
import_v414.z.object({
|
|
2503
|
+
type: import_v414.z.literal("reasoning"),
|
|
2504
|
+
id: import_v414.z.string(),
|
|
2505
|
+
encrypted_content: import_v414.z.string().nullish(),
|
|
2506
|
+
summary: import_v414.z.array(
|
|
2507
|
+
import_v414.z.object({
|
|
2508
|
+
type: import_v414.z.literal("summary_text"),
|
|
2509
|
+
text: import_v414.z.string()
|
|
2458
2510
|
})
|
|
2459
2511
|
)
|
|
2460
2512
|
})
|
|
2461
2513
|
])
|
|
2462
2514
|
),
|
|
2463
|
-
service_tier:
|
|
2464
|
-
incomplete_details:
|
|
2515
|
+
service_tier: import_v414.z.string().nullish(),
|
|
2516
|
+
incomplete_details: import_v414.z.object({ reason: import_v414.z.string() }).nullable(),
|
|
2465
2517
|
usage: usageSchema2
|
|
2466
2518
|
})
|
|
2467
2519
|
),
|
|
@@ -2481,6 +2533,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2481
2533
|
}
|
|
2482
2534
|
const content = [];
|
|
2483
2535
|
const logprobs = [];
|
|
2536
|
+
let hasFunctionCall = false;
|
|
2484
2537
|
for (const part of response.output) {
|
|
2485
2538
|
switch (part.type) {
|
|
2486
2539
|
case "reasoning": {
|
|
@@ -2520,7 +2573,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2520
2573
|
content.push({
|
|
2521
2574
|
type: "source",
|
|
2522
2575
|
sourceType: "url",
|
|
2523
|
-
id: (_f = (_e = (_d = this.config).generateId) == null ? void 0 : _e.call(_d)) != null ? _f : (0,
|
|
2576
|
+
id: (_f = (_e = (_d = this.config).generateId) == null ? void 0 : _e.call(_d)) != null ? _f : (0, import_provider_utils13.generateId)(),
|
|
2524
2577
|
url: annotation.url,
|
|
2525
2578
|
title: annotation.title
|
|
2526
2579
|
});
|
|
@@ -2528,7 +2581,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2528
2581
|
content.push({
|
|
2529
2582
|
type: "source",
|
|
2530
2583
|
sourceType: "document",
|
|
2531
|
-
id: (_i = (_h = (_g = this.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : (0,
|
|
2584
|
+
id: (_i = (_h = (_g = this.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : (0, import_provider_utils13.generateId)(),
|
|
2532
2585
|
mediaType: "text/plain",
|
|
2533
2586
|
title: (_k = (_j = annotation.quote) != null ? _j : annotation.filename) != null ? _k : "Document",
|
|
2534
2587
|
filename: (_l = annotation.filename) != null ? _l : annotation.file_id
|
|
@@ -2539,6 +2592,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2539
2592
|
break;
|
|
2540
2593
|
}
|
|
2541
2594
|
case "function_call": {
|
|
2595
|
+
hasFunctionCall = true;
|
|
2542
2596
|
content.push({
|
|
2543
2597
|
type: "tool-call",
|
|
2544
2598
|
toolCallId: part.call_id,
|
|
@@ -2626,7 +2680,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2626
2680
|
content,
|
|
2627
2681
|
finishReason: mapOpenAIResponseFinishReason({
|
|
2628
2682
|
finishReason: (_m = response.incomplete_details) == null ? void 0 : _m.reason,
|
|
2629
|
-
|
|
2683
|
+
hasFunctionCall
|
|
2630
2684
|
}),
|
|
2631
2685
|
usage: {
|
|
2632
2686
|
inputTokens: response.usage.input_tokens,
|
|
@@ -2649,18 +2703,18 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2649
2703
|
}
|
|
2650
2704
|
async doStream(options) {
|
|
2651
2705
|
const { args: body, warnings } = await this.getArgs(options);
|
|
2652
|
-
const { responseHeaders, value: response } = await (0,
|
|
2706
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils13.postJsonToApi)({
|
|
2653
2707
|
url: this.config.url({
|
|
2654
2708
|
path: "/responses",
|
|
2655
2709
|
modelId: this.modelId
|
|
2656
2710
|
}),
|
|
2657
|
-
headers: (0,
|
|
2711
|
+
headers: (0, import_provider_utils13.combineHeaders)(this.config.headers(), options.headers),
|
|
2658
2712
|
body: {
|
|
2659
2713
|
...body,
|
|
2660
2714
|
stream: true
|
|
2661
2715
|
},
|
|
2662
2716
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2663
|
-
successfulResponseHandler: (0,
|
|
2717
|
+
successfulResponseHandler: (0, import_provider_utils13.createEventSourceResponseHandler)(
|
|
2664
2718
|
openaiResponsesChunkSchema
|
|
2665
2719
|
),
|
|
2666
2720
|
abortSignal: options.abortSignal,
|
|
@@ -2676,7 +2730,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2676
2730
|
const logprobs = [];
|
|
2677
2731
|
let responseId = null;
|
|
2678
2732
|
const ongoingToolCalls = {};
|
|
2679
|
-
let
|
|
2733
|
+
let hasFunctionCall = false;
|
|
2680
2734
|
const activeReasoning = {};
|
|
2681
2735
|
let serviceTier;
|
|
2682
2736
|
return {
|
|
@@ -2766,7 +2820,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2766
2820
|
} else if (isResponseOutputItemDoneChunk(value)) {
|
|
2767
2821
|
if (value.item.type === "function_call") {
|
|
2768
2822
|
ongoingToolCalls[value.output_index] = void 0;
|
|
2769
|
-
|
|
2823
|
+
hasFunctionCall = true;
|
|
2770
2824
|
controller.enqueue({
|
|
2771
2825
|
type: "tool-input-end",
|
|
2772
2826
|
id: value.item.call_id
|
|
@@ -2784,7 +2838,6 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2784
2838
|
});
|
|
2785
2839
|
} else if (value.item.type === "web_search_call") {
|
|
2786
2840
|
ongoingToolCalls[value.output_index] = void 0;
|
|
2787
|
-
hasToolCalls = true;
|
|
2788
2841
|
controller.enqueue({
|
|
2789
2842
|
type: "tool-input-end",
|
|
2790
2843
|
id: value.item.id
|
|
@@ -2792,20 +2845,19 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2792
2845
|
controller.enqueue({
|
|
2793
2846
|
type: "tool-call",
|
|
2794
2847
|
toolCallId: value.item.id,
|
|
2795
|
-
toolName: "
|
|
2848
|
+
toolName: "web_search",
|
|
2796
2849
|
input: JSON.stringify({ action: value.item.action }),
|
|
2797
2850
|
providerExecuted: true
|
|
2798
2851
|
});
|
|
2799
2852
|
controller.enqueue({
|
|
2800
2853
|
type: "tool-result",
|
|
2801
2854
|
toolCallId: value.item.id,
|
|
2802
|
-
toolName: "
|
|
2855
|
+
toolName: "web_search",
|
|
2803
2856
|
result: { status: value.item.status },
|
|
2804
2857
|
providerExecuted: true
|
|
2805
2858
|
});
|
|
2806
2859
|
} else if (value.item.type === "computer_call") {
|
|
2807
2860
|
ongoingToolCalls[value.output_index] = void 0;
|
|
2808
|
-
hasToolCalls = true;
|
|
2809
2861
|
controller.enqueue({
|
|
2810
2862
|
type: "tool-input-end",
|
|
2811
2863
|
id: value.item.id
|
|
@@ -2829,7 +2881,6 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2829
2881
|
});
|
|
2830
2882
|
} else if (value.item.type === "file_search_call") {
|
|
2831
2883
|
ongoingToolCalls[value.output_index] = void 0;
|
|
2832
|
-
hasToolCalls = true;
|
|
2833
2884
|
controller.enqueue({
|
|
2834
2885
|
type: "tool-input-end",
|
|
2835
2886
|
id: value.item.id
|
|
@@ -2930,7 +2981,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2930
2981
|
} else if (isResponseFinishedChunk(value)) {
|
|
2931
2982
|
finishReason = mapOpenAIResponseFinishReason({
|
|
2932
2983
|
finishReason: (_h = value.response.incomplete_details) == null ? void 0 : _h.reason,
|
|
2933
|
-
|
|
2984
|
+
hasFunctionCall
|
|
2934
2985
|
});
|
|
2935
2986
|
usage.inputTokens = value.response.usage.input_tokens;
|
|
2936
2987
|
usage.outputTokens = value.response.usage.output_tokens;
|
|
@@ -2945,7 +2996,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2945
2996
|
controller.enqueue({
|
|
2946
2997
|
type: "source",
|
|
2947
2998
|
sourceType: "url",
|
|
2948
|
-
id: (_o = (_n = (_m = self.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : (0,
|
|
2999
|
+
id: (_o = (_n = (_m = self.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : (0, import_provider_utils13.generateId)(),
|
|
2949
3000
|
url: value.annotation.url,
|
|
2950
3001
|
title: value.annotation.title
|
|
2951
3002
|
});
|
|
@@ -2953,7 +3004,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2953
3004
|
controller.enqueue({
|
|
2954
3005
|
type: "source",
|
|
2955
3006
|
sourceType: "document",
|
|
2956
|
-
id: (_r = (_q = (_p = self.config).generateId) == null ? void 0 : _q.call(_p)) != null ? _r : (0,
|
|
3007
|
+
id: (_r = (_q = (_p = self.config).generateId) == null ? void 0 : _q.call(_p)) != null ? _r : (0, import_provider_utils13.generateId)(),
|
|
2957
3008
|
mediaType: "text/plain",
|
|
2958
3009
|
title: (_t = (_s = value.annotation.quote) != null ? _s : value.annotation.filename) != null ? _t : "Document",
|
|
2959
3010
|
filename: (_u = value.annotation.filename) != null ? _u : value.annotation.file_id
|
|
@@ -2989,176 +3040,176 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2989
3040
|
};
|
|
2990
3041
|
}
|
|
2991
3042
|
};
|
|
2992
|
-
var usageSchema2 =
|
|
2993
|
-
input_tokens:
|
|
2994
|
-
input_tokens_details:
|
|
2995
|
-
output_tokens:
|
|
2996
|
-
output_tokens_details:
|
|
3043
|
+
var usageSchema2 = import_v414.z.object({
|
|
3044
|
+
input_tokens: import_v414.z.number(),
|
|
3045
|
+
input_tokens_details: import_v414.z.object({ cached_tokens: import_v414.z.number().nullish() }).nullish(),
|
|
3046
|
+
output_tokens: import_v414.z.number(),
|
|
3047
|
+
output_tokens_details: import_v414.z.object({ reasoning_tokens: import_v414.z.number().nullish() }).nullish()
|
|
2997
3048
|
});
|
|
2998
|
-
var textDeltaChunkSchema =
|
|
2999
|
-
type:
|
|
3000
|
-
item_id:
|
|
3001
|
-
delta:
|
|
3049
|
+
var textDeltaChunkSchema = import_v414.z.object({
|
|
3050
|
+
type: import_v414.z.literal("response.output_text.delta"),
|
|
3051
|
+
item_id: import_v414.z.string(),
|
|
3052
|
+
delta: import_v414.z.string(),
|
|
3002
3053
|
logprobs: LOGPROBS_SCHEMA.nullish()
|
|
3003
3054
|
});
|
|
3004
|
-
var errorChunkSchema =
|
|
3005
|
-
type:
|
|
3006
|
-
code:
|
|
3007
|
-
message:
|
|
3008
|
-
param:
|
|
3009
|
-
sequence_number:
|
|
3055
|
+
var errorChunkSchema = import_v414.z.object({
|
|
3056
|
+
type: import_v414.z.literal("error"),
|
|
3057
|
+
code: import_v414.z.string(),
|
|
3058
|
+
message: import_v414.z.string(),
|
|
3059
|
+
param: import_v414.z.string().nullish(),
|
|
3060
|
+
sequence_number: import_v414.z.number()
|
|
3010
3061
|
});
|
|
3011
|
-
var responseFinishedChunkSchema =
|
|
3012
|
-
type:
|
|
3013
|
-
response:
|
|
3014
|
-
incomplete_details:
|
|
3062
|
+
var responseFinishedChunkSchema = import_v414.z.object({
|
|
3063
|
+
type: import_v414.z.enum(["response.completed", "response.incomplete"]),
|
|
3064
|
+
response: import_v414.z.object({
|
|
3065
|
+
incomplete_details: import_v414.z.object({ reason: import_v414.z.string() }).nullish(),
|
|
3015
3066
|
usage: usageSchema2,
|
|
3016
|
-
service_tier:
|
|
3067
|
+
service_tier: import_v414.z.string().nullish()
|
|
3017
3068
|
})
|
|
3018
3069
|
});
|
|
3019
|
-
var responseCreatedChunkSchema =
|
|
3020
|
-
type:
|
|
3021
|
-
response:
|
|
3022
|
-
id:
|
|
3023
|
-
created_at:
|
|
3024
|
-
model:
|
|
3025
|
-
service_tier:
|
|
3070
|
+
var responseCreatedChunkSchema = import_v414.z.object({
|
|
3071
|
+
type: import_v414.z.literal("response.created"),
|
|
3072
|
+
response: import_v414.z.object({
|
|
3073
|
+
id: import_v414.z.string(),
|
|
3074
|
+
created_at: import_v414.z.number(),
|
|
3075
|
+
model: import_v414.z.string(),
|
|
3076
|
+
service_tier: import_v414.z.string().nullish()
|
|
3026
3077
|
})
|
|
3027
3078
|
});
|
|
3028
|
-
var responseOutputItemAddedSchema =
|
|
3029
|
-
type:
|
|
3030
|
-
output_index:
|
|
3031
|
-
item:
|
|
3032
|
-
|
|
3033
|
-
type:
|
|
3034
|
-
id:
|
|
3079
|
+
var responseOutputItemAddedSchema = import_v414.z.object({
|
|
3080
|
+
type: import_v414.z.literal("response.output_item.added"),
|
|
3081
|
+
output_index: import_v414.z.number(),
|
|
3082
|
+
item: import_v414.z.discriminatedUnion("type", [
|
|
3083
|
+
import_v414.z.object({
|
|
3084
|
+
type: import_v414.z.literal("message"),
|
|
3085
|
+
id: import_v414.z.string()
|
|
3035
3086
|
}),
|
|
3036
|
-
|
|
3037
|
-
type:
|
|
3038
|
-
id:
|
|
3039
|
-
encrypted_content:
|
|
3087
|
+
import_v414.z.object({
|
|
3088
|
+
type: import_v414.z.literal("reasoning"),
|
|
3089
|
+
id: import_v414.z.string(),
|
|
3090
|
+
encrypted_content: import_v414.z.string().nullish()
|
|
3040
3091
|
}),
|
|
3041
|
-
|
|
3042
|
-
type:
|
|
3043
|
-
id:
|
|
3044
|
-
call_id:
|
|
3045
|
-
name:
|
|
3046
|
-
arguments:
|
|
3092
|
+
import_v414.z.object({
|
|
3093
|
+
type: import_v414.z.literal("function_call"),
|
|
3094
|
+
id: import_v414.z.string(),
|
|
3095
|
+
call_id: import_v414.z.string(),
|
|
3096
|
+
name: import_v414.z.string(),
|
|
3097
|
+
arguments: import_v414.z.string()
|
|
3047
3098
|
}),
|
|
3048
|
-
|
|
3049
|
-
type:
|
|
3050
|
-
id:
|
|
3051
|
-
status:
|
|
3052
|
-
action:
|
|
3053
|
-
type:
|
|
3054
|
-
query:
|
|
3099
|
+
import_v414.z.object({
|
|
3100
|
+
type: import_v414.z.literal("web_search_call"),
|
|
3101
|
+
id: import_v414.z.string(),
|
|
3102
|
+
status: import_v414.z.string(),
|
|
3103
|
+
action: import_v414.z.object({
|
|
3104
|
+
type: import_v414.z.literal("search"),
|
|
3105
|
+
query: import_v414.z.string().optional()
|
|
3055
3106
|
}).nullish()
|
|
3056
3107
|
}),
|
|
3057
|
-
|
|
3058
|
-
type:
|
|
3059
|
-
id:
|
|
3060
|
-
status:
|
|
3108
|
+
import_v414.z.object({
|
|
3109
|
+
type: import_v414.z.literal("computer_call"),
|
|
3110
|
+
id: import_v414.z.string(),
|
|
3111
|
+
status: import_v414.z.string()
|
|
3061
3112
|
}),
|
|
3062
|
-
|
|
3063
|
-
type:
|
|
3064
|
-
id:
|
|
3065
|
-
status:
|
|
3066
|
-
queries:
|
|
3067
|
-
results:
|
|
3068
|
-
|
|
3069
|
-
attributes:
|
|
3070
|
-
file_id:
|
|
3071
|
-
filename:
|
|
3072
|
-
score:
|
|
3073
|
-
text:
|
|
3113
|
+
import_v414.z.object({
|
|
3114
|
+
type: import_v414.z.literal("file_search_call"),
|
|
3115
|
+
id: import_v414.z.string(),
|
|
3116
|
+
status: import_v414.z.string(),
|
|
3117
|
+
queries: import_v414.z.array(import_v414.z.string()).nullish(),
|
|
3118
|
+
results: import_v414.z.array(
|
|
3119
|
+
import_v414.z.object({
|
|
3120
|
+
attributes: import_v414.z.object({
|
|
3121
|
+
file_id: import_v414.z.string(),
|
|
3122
|
+
filename: import_v414.z.string(),
|
|
3123
|
+
score: import_v414.z.number(),
|
|
3124
|
+
text: import_v414.z.string()
|
|
3074
3125
|
})
|
|
3075
3126
|
})
|
|
3076
3127
|
).optional()
|
|
3077
3128
|
})
|
|
3078
3129
|
])
|
|
3079
3130
|
});
|
|
3080
|
-
var responseOutputItemDoneSchema =
|
|
3081
|
-
type:
|
|
3082
|
-
output_index:
|
|
3083
|
-
item:
|
|
3084
|
-
|
|
3085
|
-
type:
|
|
3086
|
-
id:
|
|
3131
|
+
var responseOutputItemDoneSchema = import_v414.z.object({
|
|
3132
|
+
type: import_v414.z.literal("response.output_item.done"),
|
|
3133
|
+
output_index: import_v414.z.number(),
|
|
3134
|
+
item: import_v414.z.discriminatedUnion("type", [
|
|
3135
|
+
import_v414.z.object({
|
|
3136
|
+
type: import_v414.z.literal("message"),
|
|
3137
|
+
id: import_v414.z.string()
|
|
3087
3138
|
}),
|
|
3088
|
-
|
|
3089
|
-
type:
|
|
3090
|
-
id:
|
|
3091
|
-
encrypted_content:
|
|
3139
|
+
import_v414.z.object({
|
|
3140
|
+
type: import_v414.z.literal("reasoning"),
|
|
3141
|
+
id: import_v414.z.string(),
|
|
3142
|
+
encrypted_content: import_v414.z.string().nullish()
|
|
3092
3143
|
}),
|
|
3093
|
-
|
|
3094
|
-
type:
|
|
3095
|
-
id:
|
|
3096
|
-
call_id:
|
|
3097
|
-
name:
|
|
3098
|
-
arguments:
|
|
3099
|
-
status:
|
|
3144
|
+
import_v414.z.object({
|
|
3145
|
+
type: import_v414.z.literal("function_call"),
|
|
3146
|
+
id: import_v414.z.string(),
|
|
3147
|
+
call_id: import_v414.z.string(),
|
|
3148
|
+
name: import_v414.z.string(),
|
|
3149
|
+
arguments: import_v414.z.string(),
|
|
3150
|
+
status: import_v414.z.literal("completed")
|
|
3100
3151
|
}),
|
|
3101
3152
|
webSearchCallItem,
|
|
3102
|
-
|
|
3103
|
-
type:
|
|
3104
|
-
id:
|
|
3105
|
-
status:
|
|
3153
|
+
import_v414.z.object({
|
|
3154
|
+
type: import_v414.z.literal("computer_call"),
|
|
3155
|
+
id: import_v414.z.string(),
|
|
3156
|
+
status: import_v414.z.literal("completed")
|
|
3106
3157
|
}),
|
|
3107
|
-
|
|
3108
|
-
type:
|
|
3109
|
-
id:
|
|
3110
|
-
status:
|
|
3111
|
-
queries:
|
|
3112
|
-
results:
|
|
3113
|
-
|
|
3114
|
-
attributes:
|
|
3115
|
-
file_id:
|
|
3116
|
-
filename:
|
|
3117
|
-
score:
|
|
3118
|
-
text:
|
|
3158
|
+
import_v414.z.object({
|
|
3159
|
+
type: import_v414.z.literal("file_search_call"),
|
|
3160
|
+
id: import_v414.z.string(),
|
|
3161
|
+
status: import_v414.z.literal("completed"),
|
|
3162
|
+
queries: import_v414.z.array(import_v414.z.string()).nullish(),
|
|
3163
|
+
results: import_v414.z.array(
|
|
3164
|
+
import_v414.z.object({
|
|
3165
|
+
attributes: import_v414.z.object({
|
|
3166
|
+
file_id: import_v414.z.string(),
|
|
3167
|
+
filename: import_v414.z.string(),
|
|
3168
|
+
score: import_v414.z.number(),
|
|
3169
|
+
text: import_v414.z.string()
|
|
3119
3170
|
})
|
|
3120
3171
|
})
|
|
3121
3172
|
).nullish()
|
|
3122
3173
|
})
|
|
3123
3174
|
])
|
|
3124
3175
|
});
|
|
3125
|
-
var responseFunctionCallArgumentsDeltaSchema =
|
|
3126
|
-
type:
|
|
3127
|
-
item_id:
|
|
3128
|
-
output_index:
|
|
3129
|
-
delta:
|
|
3176
|
+
var responseFunctionCallArgumentsDeltaSchema = import_v414.z.object({
|
|
3177
|
+
type: import_v414.z.literal("response.function_call_arguments.delta"),
|
|
3178
|
+
item_id: import_v414.z.string(),
|
|
3179
|
+
output_index: import_v414.z.number(),
|
|
3180
|
+
delta: import_v414.z.string()
|
|
3130
3181
|
});
|
|
3131
|
-
var responseAnnotationAddedSchema =
|
|
3132
|
-
type:
|
|
3133
|
-
annotation:
|
|
3134
|
-
|
|
3135
|
-
type:
|
|
3136
|
-
url:
|
|
3137
|
-
title:
|
|
3182
|
+
var responseAnnotationAddedSchema = import_v414.z.object({
|
|
3183
|
+
type: import_v414.z.literal("response.output_text.annotation.added"),
|
|
3184
|
+
annotation: import_v414.z.discriminatedUnion("type", [
|
|
3185
|
+
import_v414.z.object({
|
|
3186
|
+
type: import_v414.z.literal("url_citation"),
|
|
3187
|
+
url: import_v414.z.string(),
|
|
3188
|
+
title: import_v414.z.string()
|
|
3138
3189
|
}),
|
|
3139
|
-
|
|
3140
|
-
type:
|
|
3141
|
-
file_id:
|
|
3142
|
-
filename:
|
|
3143
|
-
index:
|
|
3144
|
-
start_index:
|
|
3145
|
-
end_index:
|
|
3146
|
-
quote:
|
|
3190
|
+
import_v414.z.object({
|
|
3191
|
+
type: import_v414.z.literal("file_citation"),
|
|
3192
|
+
file_id: import_v414.z.string(),
|
|
3193
|
+
filename: import_v414.z.string().nullish(),
|
|
3194
|
+
index: import_v414.z.number().nullish(),
|
|
3195
|
+
start_index: import_v414.z.number().nullish(),
|
|
3196
|
+
end_index: import_v414.z.number().nullish(),
|
|
3197
|
+
quote: import_v414.z.string().nullish()
|
|
3147
3198
|
})
|
|
3148
3199
|
])
|
|
3149
3200
|
});
|
|
3150
|
-
var responseReasoningSummaryPartAddedSchema =
|
|
3151
|
-
type:
|
|
3152
|
-
item_id:
|
|
3153
|
-
summary_index:
|
|
3201
|
+
var responseReasoningSummaryPartAddedSchema = import_v414.z.object({
|
|
3202
|
+
type: import_v414.z.literal("response.reasoning_summary_part.added"),
|
|
3203
|
+
item_id: import_v414.z.string(),
|
|
3204
|
+
summary_index: import_v414.z.number()
|
|
3154
3205
|
});
|
|
3155
|
-
var responseReasoningSummaryTextDeltaSchema =
|
|
3156
|
-
type:
|
|
3157
|
-
item_id:
|
|
3158
|
-
summary_index:
|
|
3159
|
-
delta:
|
|
3206
|
+
var responseReasoningSummaryTextDeltaSchema = import_v414.z.object({
|
|
3207
|
+
type: import_v414.z.literal("response.reasoning_summary_text.delta"),
|
|
3208
|
+
item_id: import_v414.z.string(),
|
|
3209
|
+
summary_index: import_v414.z.number(),
|
|
3210
|
+
delta: import_v414.z.string()
|
|
3160
3211
|
});
|
|
3161
|
-
var openaiResponsesChunkSchema =
|
|
3212
|
+
var openaiResponsesChunkSchema = import_v414.z.union([
|
|
3162
3213
|
textDeltaChunkSchema,
|
|
3163
3214
|
responseFinishedChunkSchema,
|
|
3164
3215
|
responseCreatedChunkSchema,
|
|
@@ -3169,7 +3220,7 @@ var openaiResponsesChunkSchema = import_v413.z.union([
|
|
|
3169
3220
|
responseReasoningSummaryPartAddedSchema,
|
|
3170
3221
|
responseReasoningSummaryTextDeltaSchema,
|
|
3171
3222
|
errorChunkSchema,
|
|
3172
|
-
|
|
3223
|
+
import_v414.z.object({ type: import_v414.z.string() }).loose()
|
|
3173
3224
|
// fallback for unknown chunks
|
|
3174
3225
|
]);
|
|
3175
3226
|
function isTextDeltaChunk(chunk) {
|
|
@@ -3242,27 +3293,27 @@ function getResponsesModelConfig(modelId) {
|
|
|
3242
3293
|
isReasoningModel: false
|
|
3243
3294
|
};
|
|
3244
3295
|
}
|
|
3245
|
-
var openaiResponsesProviderOptionsSchema =
|
|
3246
|
-
metadata:
|
|
3247
|
-
parallelToolCalls:
|
|
3248
|
-
previousResponseId:
|
|
3249
|
-
store:
|
|
3250
|
-
user:
|
|
3251
|
-
reasoningEffort:
|
|
3252
|
-
strictJsonSchema:
|
|
3253
|
-
instructions:
|
|
3254
|
-
reasoningSummary:
|
|
3255
|
-
serviceTier:
|
|
3256
|
-
include:
|
|
3257
|
-
|
|
3296
|
+
var openaiResponsesProviderOptionsSchema = import_v414.z.object({
|
|
3297
|
+
metadata: import_v414.z.any().nullish(),
|
|
3298
|
+
parallelToolCalls: import_v414.z.boolean().nullish(),
|
|
3299
|
+
previousResponseId: import_v414.z.string().nullish(),
|
|
3300
|
+
store: import_v414.z.boolean().nullish(),
|
|
3301
|
+
user: import_v414.z.string().nullish(),
|
|
3302
|
+
reasoningEffort: import_v414.z.string().nullish(),
|
|
3303
|
+
strictJsonSchema: import_v414.z.boolean().nullish(),
|
|
3304
|
+
instructions: import_v414.z.string().nullish(),
|
|
3305
|
+
reasoningSummary: import_v414.z.string().nullish(),
|
|
3306
|
+
serviceTier: import_v414.z.enum(["auto", "flex", "priority"]).nullish(),
|
|
3307
|
+
include: import_v414.z.array(
|
|
3308
|
+
import_v414.z.enum([
|
|
3258
3309
|
"reasoning.encrypted_content",
|
|
3259
3310
|
"file_search_call.results",
|
|
3260
3311
|
"message.output_text.logprobs"
|
|
3261
3312
|
])
|
|
3262
3313
|
).nullish(),
|
|
3263
|
-
textVerbosity:
|
|
3264
|
-
promptCacheKey:
|
|
3265
|
-
safetyIdentifier:
|
|
3314
|
+
textVerbosity: import_v414.z.enum(["low", "medium", "high"]).nullish(),
|
|
3315
|
+
promptCacheKey: import_v414.z.string().nullish(),
|
|
3316
|
+
safetyIdentifier: import_v414.z.string().nullish(),
|
|
3266
3317
|
/**
|
|
3267
3318
|
* Return the log probabilities of the tokens.
|
|
3268
3319
|
*
|
|
@@ -3275,15 +3326,15 @@ var openaiResponsesProviderOptionsSchema = import_v413.z.object({
|
|
|
3275
3326
|
* @see https://platform.openai.com/docs/api-reference/responses/create
|
|
3276
3327
|
* @see https://cookbook.openai.com/examples/using_logprobs
|
|
3277
3328
|
*/
|
|
3278
|
-
logprobs:
|
|
3329
|
+
logprobs: import_v414.z.union([import_v414.z.boolean(), import_v414.z.number().min(1).max(TOP_LOGPROBS_MAX)]).optional()
|
|
3279
3330
|
});
|
|
3280
3331
|
|
|
3281
3332
|
// src/speech/openai-speech-model.ts
|
|
3282
|
-
var
|
|
3283
|
-
var
|
|
3284
|
-
var OpenAIProviderOptionsSchema =
|
|
3285
|
-
instructions:
|
|
3286
|
-
speed:
|
|
3333
|
+
var import_provider_utils14 = require("@ai-sdk/provider-utils");
|
|
3334
|
+
var import_v415 = require("zod/v4");
|
|
3335
|
+
var OpenAIProviderOptionsSchema = import_v415.z.object({
|
|
3336
|
+
instructions: import_v415.z.string().nullish(),
|
|
3337
|
+
speed: import_v415.z.number().min(0.25).max(4).default(1).nullish()
|
|
3287
3338
|
});
|
|
3288
3339
|
var OpenAISpeechModel = class {
|
|
3289
3340
|
constructor(modelId, config) {
|
|
@@ -3304,7 +3355,7 @@ var OpenAISpeechModel = class {
|
|
|
3304
3355
|
providerOptions
|
|
3305
3356
|
}) {
|
|
3306
3357
|
const warnings = [];
|
|
3307
|
-
const openAIOptions = await (0,
|
|
3358
|
+
const openAIOptions = await (0, import_provider_utils14.parseProviderOptions)({
|
|
3308
3359
|
provider: "openai",
|
|
3309
3360
|
providerOptions,
|
|
3310
3361
|
schema: OpenAIProviderOptionsSchema
|
|
@@ -3357,15 +3408,15 @@ var OpenAISpeechModel = class {
|
|
|
3357
3408
|
value: audio,
|
|
3358
3409
|
responseHeaders,
|
|
3359
3410
|
rawValue: rawResponse
|
|
3360
|
-
} = await (0,
|
|
3411
|
+
} = await (0, import_provider_utils14.postJsonToApi)({
|
|
3361
3412
|
url: this.config.url({
|
|
3362
3413
|
path: "/audio/speech",
|
|
3363
3414
|
modelId: this.modelId
|
|
3364
3415
|
}),
|
|
3365
|
-
headers: (0,
|
|
3416
|
+
headers: (0, import_provider_utils14.combineHeaders)(this.config.headers(), options.headers),
|
|
3366
3417
|
body: requestBody,
|
|
3367
3418
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
3368
|
-
successfulResponseHandler: (0,
|
|
3419
|
+
successfulResponseHandler: (0, import_provider_utils14.createBinaryResponseHandler)(),
|
|
3369
3420
|
abortSignal: options.abortSignal,
|
|
3370
3421
|
fetch: this.config.fetch
|
|
3371
3422
|
});
|
|
@@ -3386,34 +3437,34 @@ var OpenAISpeechModel = class {
|
|
|
3386
3437
|
};
|
|
3387
3438
|
|
|
3388
3439
|
// src/transcription/openai-transcription-model.ts
|
|
3389
|
-
var
|
|
3390
|
-
var
|
|
3440
|
+
var import_provider_utils15 = require("@ai-sdk/provider-utils");
|
|
3441
|
+
var import_v417 = require("zod/v4");
|
|
3391
3442
|
|
|
3392
3443
|
// src/transcription/openai-transcription-options.ts
|
|
3393
|
-
var
|
|
3394
|
-
var openAITranscriptionProviderOptions =
|
|
3444
|
+
var import_v416 = require("zod/v4");
|
|
3445
|
+
var openAITranscriptionProviderOptions = import_v416.z.object({
|
|
3395
3446
|
/**
|
|
3396
3447
|
* Additional information to include in the transcription response.
|
|
3397
3448
|
*/
|
|
3398
|
-
include:
|
|
3449
|
+
include: import_v416.z.array(import_v416.z.string()).optional(),
|
|
3399
3450
|
/**
|
|
3400
3451
|
* The language of the input audio in ISO-639-1 format.
|
|
3401
3452
|
*/
|
|
3402
|
-
language:
|
|
3453
|
+
language: import_v416.z.string().optional(),
|
|
3403
3454
|
/**
|
|
3404
3455
|
* An optional text to guide the model's style or continue a previous audio segment.
|
|
3405
3456
|
*/
|
|
3406
|
-
prompt:
|
|
3457
|
+
prompt: import_v416.z.string().optional(),
|
|
3407
3458
|
/**
|
|
3408
3459
|
* The sampling temperature, between 0 and 1.
|
|
3409
3460
|
* @default 0
|
|
3410
3461
|
*/
|
|
3411
|
-
temperature:
|
|
3462
|
+
temperature: import_v416.z.number().min(0).max(1).default(0).optional(),
|
|
3412
3463
|
/**
|
|
3413
3464
|
* The timestamp granularities to populate for this transcription.
|
|
3414
3465
|
* @default ['segment']
|
|
3415
3466
|
*/
|
|
3416
|
-
timestampGranularities:
|
|
3467
|
+
timestampGranularities: import_v416.z.array(import_v416.z.enum(["word", "segment"])).default(["segment"]).optional()
|
|
3417
3468
|
});
|
|
3418
3469
|
|
|
3419
3470
|
// src/transcription/openai-transcription-model.ts
|
|
@@ -3491,15 +3542,15 @@ var OpenAITranscriptionModel = class {
|
|
|
3491
3542
|
providerOptions
|
|
3492
3543
|
}) {
|
|
3493
3544
|
const warnings = [];
|
|
3494
|
-
const openAIOptions = await (0,
|
|
3545
|
+
const openAIOptions = await (0, import_provider_utils15.parseProviderOptions)({
|
|
3495
3546
|
provider: "openai",
|
|
3496
3547
|
providerOptions,
|
|
3497
3548
|
schema: openAITranscriptionProviderOptions
|
|
3498
3549
|
});
|
|
3499
3550
|
const formData = new FormData();
|
|
3500
|
-
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0,
|
|
3551
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils15.convertBase64ToUint8Array)(audio)]);
|
|
3501
3552
|
formData.append("model", this.modelId);
|
|
3502
|
-
const fileExtension = (0,
|
|
3553
|
+
const fileExtension = (0, import_provider_utils15.mediaTypeToExtension)(mediaType);
|
|
3503
3554
|
formData.append(
|
|
3504
3555
|
"file",
|
|
3505
3556
|
new File([blob], "audio", { type: mediaType }),
|
|
@@ -3544,15 +3595,15 @@ var OpenAITranscriptionModel = class {
|
|
|
3544
3595
|
value: response,
|
|
3545
3596
|
responseHeaders,
|
|
3546
3597
|
rawValue: rawResponse
|
|
3547
|
-
} = await (0,
|
|
3598
|
+
} = await (0, import_provider_utils15.postFormDataToApi)({
|
|
3548
3599
|
url: this.config.url({
|
|
3549
3600
|
path: "/audio/transcriptions",
|
|
3550
3601
|
modelId: this.modelId
|
|
3551
3602
|
}),
|
|
3552
|
-
headers: (0,
|
|
3603
|
+
headers: (0, import_provider_utils15.combineHeaders)(this.config.headers(), options.headers),
|
|
3553
3604
|
formData,
|
|
3554
3605
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
3555
|
-
successfulResponseHandler: (0,
|
|
3606
|
+
successfulResponseHandler: (0, import_provider_utils15.createJsonResponseHandler)(
|
|
3556
3607
|
openaiTranscriptionResponseSchema
|
|
3557
3608
|
),
|
|
3558
3609
|
abortSignal: options.abortSignal,
|
|
@@ -3582,29 +3633,29 @@ var OpenAITranscriptionModel = class {
|
|
|
3582
3633
|
};
|
|
3583
3634
|
}
|
|
3584
3635
|
};
|
|
3585
|
-
var openaiTranscriptionResponseSchema =
|
|
3586
|
-
text:
|
|
3587
|
-
language:
|
|
3588
|
-
duration:
|
|
3589
|
-
words:
|
|
3590
|
-
|
|
3591
|
-
word:
|
|
3592
|
-
start:
|
|
3593
|
-
end:
|
|
3636
|
+
var openaiTranscriptionResponseSchema = import_v417.z.object({
|
|
3637
|
+
text: import_v417.z.string(),
|
|
3638
|
+
language: import_v417.z.string().nullish(),
|
|
3639
|
+
duration: import_v417.z.number().nullish(),
|
|
3640
|
+
words: import_v417.z.array(
|
|
3641
|
+
import_v417.z.object({
|
|
3642
|
+
word: import_v417.z.string(),
|
|
3643
|
+
start: import_v417.z.number(),
|
|
3644
|
+
end: import_v417.z.number()
|
|
3594
3645
|
})
|
|
3595
3646
|
).nullish(),
|
|
3596
|
-
segments:
|
|
3597
|
-
|
|
3598
|
-
id:
|
|
3599
|
-
seek:
|
|
3600
|
-
start:
|
|
3601
|
-
end:
|
|
3602
|
-
text:
|
|
3603
|
-
tokens:
|
|
3604
|
-
temperature:
|
|
3605
|
-
avg_logprob:
|
|
3606
|
-
compression_ratio:
|
|
3607
|
-
no_speech_prob:
|
|
3647
|
+
segments: import_v417.z.array(
|
|
3648
|
+
import_v417.z.object({
|
|
3649
|
+
id: import_v417.z.number(),
|
|
3650
|
+
seek: import_v417.z.number(),
|
|
3651
|
+
start: import_v417.z.number(),
|
|
3652
|
+
end: import_v417.z.number(),
|
|
3653
|
+
text: import_v417.z.string(),
|
|
3654
|
+
tokens: import_v417.z.array(import_v417.z.number()),
|
|
3655
|
+
temperature: import_v417.z.number(),
|
|
3656
|
+
avg_logprob: import_v417.z.number(),
|
|
3657
|
+
compression_ratio: import_v417.z.number(),
|
|
3658
|
+
no_speech_prob: import_v417.z.number()
|
|
3608
3659
|
})
|
|
3609
3660
|
).nullish()
|
|
3610
3661
|
});
|
|
@@ -3612,10 +3663,10 @@ var openaiTranscriptionResponseSchema = import_v416.z.object({
|
|
|
3612
3663
|
// src/openai-provider.ts
|
|
3613
3664
|
function createOpenAI(options = {}) {
|
|
3614
3665
|
var _a, _b;
|
|
3615
|
-
const baseURL = (_a = (0,
|
|
3666
|
+
const baseURL = (_a = (0, import_provider_utils16.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.openai.com/v1";
|
|
3616
3667
|
const providerName = (_b = options.name) != null ? _b : "openai";
|
|
3617
3668
|
const getHeaders = () => ({
|
|
3618
|
-
Authorization: `Bearer ${(0,
|
|
3669
|
+
Authorization: `Bearer ${(0, import_provider_utils16.loadApiKey)({
|
|
3619
3670
|
apiKey: options.apiKey,
|
|
3620
3671
|
environmentVariableName: "OPENAI_API_KEY",
|
|
3621
3672
|
description: "OpenAI"
|