@ai-sdk/openai 2.0.0-beta.2 → 2.0.0-beta.4
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 +13 -0
- package/dist/index.d.mts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +317 -212
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +305 -200
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +7 -2
- package/dist/internal/index.d.ts +7 -2
- package/dist/internal/index.js +305 -200
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +299 -194
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/internal/index.mjs
CHANGED
|
@@ -284,7 +284,13 @@ var openaiProviderOptions = z.object({
|
|
|
284
284
|
*
|
|
285
285
|
* @default 'auto'
|
|
286
286
|
*/
|
|
287
|
-
serviceTier: z.enum(["auto", "flex"]).optional()
|
|
287
|
+
serviceTier: z.enum(["auto", "flex"]).optional(),
|
|
288
|
+
/**
|
|
289
|
+
* Whether to use strict JSON schema validation.
|
|
290
|
+
*
|
|
291
|
+
* @default true
|
|
292
|
+
*/
|
|
293
|
+
strictJsonSchema: z.boolean().optional()
|
|
288
294
|
});
|
|
289
295
|
|
|
290
296
|
// src/openai-error.ts
|
|
@@ -383,7 +389,8 @@ var webSearchPreview = createProviderDefinedToolFactory2({
|
|
|
383
389
|
function prepareTools({
|
|
384
390
|
tools,
|
|
385
391
|
toolChoice,
|
|
386
|
-
structuredOutputs
|
|
392
|
+
structuredOutputs,
|
|
393
|
+
strictJsonSchema
|
|
387
394
|
}) {
|
|
388
395
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
389
396
|
const toolWarnings = [];
|
|
@@ -400,7 +407,7 @@ function prepareTools({
|
|
|
400
407
|
name: tool.name,
|
|
401
408
|
description: tool.description,
|
|
402
409
|
parameters: tool.inputSchema,
|
|
403
|
-
strict: structuredOutputs ?
|
|
410
|
+
strict: structuredOutputs ? strictJsonSchema : void 0
|
|
404
411
|
}
|
|
405
412
|
});
|
|
406
413
|
break;
|
|
@@ -492,7 +499,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
492
499
|
toolChoice,
|
|
493
500
|
providerOptions
|
|
494
501
|
}) {
|
|
495
|
-
var _a, _b, _c;
|
|
502
|
+
var _a, _b, _c, _d;
|
|
496
503
|
const warnings = [];
|
|
497
504
|
const openaiOptions = (_a = await parseProviderOptions({
|
|
498
505
|
provider: "openai",
|
|
@@ -520,6 +527,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
520
527
|
}
|
|
521
528
|
);
|
|
522
529
|
warnings.push(...messageWarnings);
|
|
530
|
+
const strictJsonSchema = (_c = openaiOptions.strictJsonSchema) != null ? _c : false;
|
|
523
531
|
const baseArgs = {
|
|
524
532
|
// model id:
|
|
525
533
|
model: this.modelId,
|
|
@@ -535,18 +543,15 @@ var OpenAIChatLanguageModel = class {
|
|
|
535
543
|
top_p: topP,
|
|
536
544
|
frequency_penalty: frequencyPenalty,
|
|
537
545
|
presence_penalty: presencePenalty,
|
|
538
|
-
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ?
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
}
|
|
548
|
-
} : { type: "json_object" }
|
|
549
|
-
) : void 0,
|
|
546
|
+
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? structuredOutputs && responseFormat.schema != null ? {
|
|
547
|
+
type: "json_schema",
|
|
548
|
+
json_schema: {
|
|
549
|
+
schema: responseFormat.schema,
|
|
550
|
+
strict: strictJsonSchema,
|
|
551
|
+
name: (_d = responseFormat.name) != null ? _d : "response",
|
|
552
|
+
description: responseFormat.description
|
|
553
|
+
}
|
|
554
|
+
} : { type: "json_object" } : void 0,
|
|
550
555
|
stop: stopSequences,
|
|
551
556
|
seed,
|
|
552
557
|
// openai specific settings:
|
|
@@ -645,7 +650,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
645
650
|
} = prepareTools({
|
|
646
651
|
tools,
|
|
647
652
|
toolChoice,
|
|
648
|
-
structuredOutputs
|
|
653
|
+
structuredOutputs,
|
|
654
|
+
strictJsonSchema
|
|
649
655
|
});
|
|
650
656
|
return {
|
|
651
657
|
args: {
|
|
@@ -1982,19 +1988,22 @@ import {
|
|
|
1982
1988
|
createEventSourceResponseHandler as createEventSourceResponseHandler3,
|
|
1983
1989
|
createJsonResponseHandler as createJsonResponseHandler6,
|
|
1984
1990
|
generateId as generateId2,
|
|
1985
|
-
parseProviderOptions as
|
|
1991
|
+
parseProviderOptions as parseProviderOptions7,
|
|
1986
1992
|
postJsonToApi as postJsonToApi6
|
|
1987
1993
|
} from "@ai-sdk/provider-utils";
|
|
1988
|
-
import { z as
|
|
1994
|
+
import { z as z15 } from "zod/v4";
|
|
1989
1995
|
|
|
1990
1996
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1991
1997
|
import {
|
|
1992
1998
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError4
|
|
1993
1999
|
} from "@ai-sdk/provider";
|
|
1994
|
-
|
|
2000
|
+
import { parseProviderOptions as parseProviderOptions6 } from "@ai-sdk/provider-utils";
|
|
2001
|
+
import { z as z14 } from "zod/v4";
|
|
2002
|
+
async function convertToOpenAIResponsesMessages({
|
|
1995
2003
|
prompt,
|
|
1996
2004
|
systemMessageMode
|
|
1997
2005
|
}) {
|
|
2006
|
+
var _a, _b;
|
|
1998
2007
|
const messages = [];
|
|
1999
2008
|
const warnings = [];
|
|
2000
2009
|
for (const { role, content } of prompt) {
|
|
@@ -2029,7 +2038,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
2029
2038
|
messages.push({
|
|
2030
2039
|
role: "user",
|
|
2031
2040
|
content: content.map((part, index) => {
|
|
2032
|
-
var
|
|
2041
|
+
var _a2, _b2, _c;
|
|
2033
2042
|
switch (part.type) {
|
|
2034
2043
|
case "text": {
|
|
2035
2044
|
return { type: "input_text", text: part.text };
|
|
@@ -2041,7 +2050,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
2041
2050
|
type: "input_image",
|
|
2042
2051
|
image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`,
|
|
2043
2052
|
// OpenAI specific extension: image detail
|
|
2044
|
-
detail: (
|
|
2053
|
+
detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
|
|
2045
2054
|
};
|
|
2046
2055
|
} else if (part.mediaType === "application/pdf") {
|
|
2047
2056
|
if (part.data instanceof URL) {
|
|
@@ -2066,6 +2075,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
2066
2075
|
break;
|
|
2067
2076
|
}
|
|
2068
2077
|
case "assistant": {
|
|
2078
|
+
const reasoningMessages = {};
|
|
2069
2079
|
for (const part of content) {
|
|
2070
2080
|
switch (part.type) {
|
|
2071
2081
|
case "text": {
|
|
@@ -2094,6 +2104,43 @@ function convertToOpenAIResponsesMessages({
|
|
|
2094
2104
|
});
|
|
2095
2105
|
break;
|
|
2096
2106
|
}
|
|
2107
|
+
case "reasoning": {
|
|
2108
|
+
const providerOptions = await parseProviderOptions6({
|
|
2109
|
+
provider: "openai",
|
|
2110
|
+
providerOptions: part.providerOptions,
|
|
2111
|
+
schema: openaiResponsesReasoningProviderOptionsSchema
|
|
2112
|
+
});
|
|
2113
|
+
const reasoningId = (_a = providerOptions == null ? void 0 : providerOptions.reasoning) == null ? void 0 : _a.id;
|
|
2114
|
+
if (reasoningId != null) {
|
|
2115
|
+
const existingReasoningMessage = reasoningMessages[reasoningId];
|
|
2116
|
+
const summaryParts = [];
|
|
2117
|
+
if (part.text.length > 0) {
|
|
2118
|
+
summaryParts.push({ type: "summary_text", text: part.text });
|
|
2119
|
+
} else {
|
|
2120
|
+
warnings.push({
|
|
2121
|
+
type: "other",
|
|
2122
|
+
message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${JSON.stringify(part)}.`
|
|
2123
|
+
});
|
|
2124
|
+
}
|
|
2125
|
+
if (existingReasoningMessage === void 0) {
|
|
2126
|
+
reasoningMessages[reasoningId] = {
|
|
2127
|
+
type: "reasoning",
|
|
2128
|
+
id: reasoningId,
|
|
2129
|
+
encrypted_content: (_b = providerOptions == null ? void 0 : providerOptions.reasoning) == null ? void 0 : _b.encryptedContent,
|
|
2130
|
+
summary: summaryParts
|
|
2131
|
+
};
|
|
2132
|
+
messages.push(reasoningMessages[reasoningId]);
|
|
2133
|
+
} else {
|
|
2134
|
+
existingReasoningMessage.summary.push(...summaryParts);
|
|
2135
|
+
}
|
|
2136
|
+
} else {
|
|
2137
|
+
warnings.push({
|
|
2138
|
+
type: "other",
|
|
2139
|
+
message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
|
|
2140
|
+
});
|
|
2141
|
+
}
|
|
2142
|
+
break;
|
|
2143
|
+
}
|
|
2097
2144
|
}
|
|
2098
2145
|
}
|
|
2099
2146
|
break;
|
|
@@ -2129,6 +2176,12 @@ function convertToOpenAIResponsesMessages({
|
|
|
2129
2176
|
}
|
|
2130
2177
|
return { messages, warnings };
|
|
2131
2178
|
}
|
|
2179
|
+
var openaiResponsesReasoningProviderOptionsSchema = z14.object({
|
|
2180
|
+
reasoning: z14.object({
|
|
2181
|
+
id: z14.string().nullish(),
|
|
2182
|
+
encryptedContent: z14.string().nullish()
|
|
2183
|
+
}).nullish()
|
|
2184
|
+
});
|
|
2132
2185
|
|
|
2133
2186
|
// src/responses/map-openai-responses-finish-reason.ts
|
|
2134
2187
|
function mapOpenAIResponseFinishReason({
|
|
@@ -2155,7 +2208,7 @@ import {
|
|
|
2155
2208
|
function prepareResponsesTools({
|
|
2156
2209
|
tools,
|
|
2157
2210
|
toolChoice,
|
|
2158
|
-
|
|
2211
|
+
strictJsonSchema
|
|
2159
2212
|
}) {
|
|
2160
2213
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
2161
2214
|
const toolWarnings = [];
|
|
@@ -2171,7 +2224,7 @@ function prepareResponsesTools({
|
|
|
2171
2224
|
name: tool.name,
|
|
2172
2225
|
description: tool.description,
|
|
2173
2226
|
parameters: tool.inputSchema,
|
|
2174
|
-
strict:
|
|
2227
|
+
strict: strictJsonSchema
|
|
2175
2228
|
});
|
|
2176
2229
|
break;
|
|
2177
2230
|
case "provider-defined":
|
|
@@ -2269,17 +2322,17 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2269
2322
|
if (stopSequences != null) {
|
|
2270
2323
|
warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
|
|
2271
2324
|
}
|
|
2272
|
-
const { messages, warnings: messageWarnings } = convertToOpenAIResponsesMessages({
|
|
2325
|
+
const { messages, warnings: messageWarnings } = await convertToOpenAIResponsesMessages({
|
|
2273
2326
|
prompt,
|
|
2274
2327
|
systemMessageMode: modelConfig.systemMessageMode
|
|
2275
2328
|
});
|
|
2276
2329
|
warnings.push(...messageWarnings);
|
|
2277
|
-
const openaiOptions = await
|
|
2330
|
+
const openaiOptions = await parseProviderOptions7({
|
|
2278
2331
|
provider: "openai",
|
|
2279
2332
|
providerOptions,
|
|
2280
2333
|
schema: openaiResponsesProviderOptionsSchema
|
|
2281
2334
|
});
|
|
2282
|
-
const
|
|
2335
|
+
const strictJsonSchema = (_a = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _a : false;
|
|
2283
2336
|
const baseArgs = {
|
|
2284
2337
|
model: this.modelId,
|
|
2285
2338
|
input: messages,
|
|
@@ -2290,7 +2343,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2290
2343
|
text: {
|
|
2291
2344
|
format: responseFormat.schema != null ? {
|
|
2292
2345
|
type: "json_schema",
|
|
2293
|
-
strict:
|
|
2346
|
+
strict: strictJsonSchema,
|
|
2294
2347
|
name: (_b = responseFormat.name) != null ? _b : "response",
|
|
2295
2348
|
description: responseFormat.description,
|
|
2296
2349
|
schema: responseFormat.schema
|
|
@@ -2305,6 +2358,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2305
2358
|
user: openaiOptions == null ? void 0 : openaiOptions.user,
|
|
2306
2359
|
instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
|
|
2307
2360
|
service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
|
|
2361
|
+
include: openaiOptions == null ? void 0 : openaiOptions.include,
|
|
2308
2362
|
// model-specific settings:
|
|
2309
2363
|
...modelConfig.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
|
|
2310
2364
|
reasoning: {
|
|
@@ -2337,6 +2391,21 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2337
2391
|
details: "topP is not supported for reasoning models"
|
|
2338
2392
|
});
|
|
2339
2393
|
}
|
|
2394
|
+
} else {
|
|
2395
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null) {
|
|
2396
|
+
warnings.push({
|
|
2397
|
+
type: "unsupported-setting",
|
|
2398
|
+
setting: "reasoningEffort",
|
|
2399
|
+
details: "reasoningEffort is not supported for non-reasoning models"
|
|
2400
|
+
});
|
|
2401
|
+
}
|
|
2402
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) {
|
|
2403
|
+
warnings.push({
|
|
2404
|
+
type: "unsupported-setting",
|
|
2405
|
+
setting: "reasoningSummary",
|
|
2406
|
+
details: "reasoningSummary is not supported for non-reasoning models"
|
|
2407
|
+
});
|
|
2408
|
+
}
|
|
2340
2409
|
}
|
|
2341
2410
|
if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !supportsFlexProcessing2(this.modelId)) {
|
|
2342
2411
|
warnings.push({
|
|
@@ -2353,7 +2422,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2353
2422
|
} = prepareResponsesTools({
|
|
2354
2423
|
tools,
|
|
2355
2424
|
toolChoice,
|
|
2356
|
-
|
|
2425
|
+
strictJsonSchema
|
|
2357
2426
|
});
|
|
2358
2427
|
return {
|
|
2359
2428
|
args: {
|
|
@@ -2365,7 +2434,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2365
2434
|
};
|
|
2366
2435
|
}
|
|
2367
2436
|
async doGenerate(options) {
|
|
2368
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2437
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2369
2438
|
const { args: body, warnings } = await this.getArgs(options);
|
|
2370
2439
|
const {
|
|
2371
2440
|
responseHeaders,
|
|
@@ -2380,59 +2449,61 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2380
2449
|
body,
|
|
2381
2450
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2382
2451
|
successfulResponseHandler: createJsonResponseHandler6(
|
|
2383
|
-
|
|
2384
|
-
id:
|
|
2385
|
-
created_at:
|
|
2386
|
-
model:
|
|
2387
|
-
output:
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
type:
|
|
2391
|
-
role:
|
|
2392
|
-
content:
|
|
2393
|
-
|
|
2394
|
-
type:
|
|
2395
|
-
text:
|
|
2396
|
-
annotations:
|
|
2397
|
-
|
|
2398
|
-
type:
|
|
2399
|
-
start_index:
|
|
2400
|
-
end_index:
|
|
2401
|
-
url:
|
|
2402
|
-
title:
|
|
2452
|
+
z15.object({
|
|
2453
|
+
id: z15.string(),
|
|
2454
|
+
created_at: z15.number(),
|
|
2455
|
+
model: z15.string(),
|
|
2456
|
+
output: z15.array(
|
|
2457
|
+
z15.discriminatedUnion("type", [
|
|
2458
|
+
z15.object({
|
|
2459
|
+
type: z15.literal("message"),
|
|
2460
|
+
role: z15.literal("assistant"),
|
|
2461
|
+
content: z15.array(
|
|
2462
|
+
z15.object({
|
|
2463
|
+
type: z15.literal("output_text"),
|
|
2464
|
+
text: z15.string(),
|
|
2465
|
+
annotations: z15.array(
|
|
2466
|
+
z15.object({
|
|
2467
|
+
type: z15.literal("url_citation"),
|
|
2468
|
+
start_index: z15.number(),
|
|
2469
|
+
end_index: z15.number(),
|
|
2470
|
+
url: z15.string(),
|
|
2471
|
+
title: z15.string()
|
|
2403
2472
|
})
|
|
2404
2473
|
)
|
|
2405
2474
|
})
|
|
2406
2475
|
)
|
|
2407
2476
|
}),
|
|
2408
|
-
|
|
2409
|
-
type:
|
|
2410
|
-
call_id:
|
|
2411
|
-
name:
|
|
2412
|
-
arguments:
|
|
2477
|
+
z15.object({
|
|
2478
|
+
type: z15.literal("function_call"),
|
|
2479
|
+
call_id: z15.string(),
|
|
2480
|
+
name: z15.string(),
|
|
2481
|
+
arguments: z15.string()
|
|
2413
2482
|
}),
|
|
2414
|
-
|
|
2415
|
-
type:
|
|
2416
|
-
id:
|
|
2417
|
-
status:
|
|
2483
|
+
z15.object({
|
|
2484
|
+
type: z15.literal("web_search_call"),
|
|
2485
|
+
id: z15.string(),
|
|
2486
|
+
status: z15.string().optional()
|
|
2418
2487
|
}),
|
|
2419
|
-
|
|
2420
|
-
type:
|
|
2421
|
-
id:
|
|
2422
|
-
status:
|
|
2488
|
+
z15.object({
|
|
2489
|
+
type: z15.literal("computer_call"),
|
|
2490
|
+
id: z15.string(),
|
|
2491
|
+
status: z15.string().optional()
|
|
2423
2492
|
}),
|
|
2424
|
-
|
|
2425
|
-
type:
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2493
|
+
z15.object({
|
|
2494
|
+
type: z15.literal("reasoning"),
|
|
2495
|
+
id: z15.string(),
|
|
2496
|
+
encrypted_content: z15.string().nullish(),
|
|
2497
|
+
summary: z15.array(
|
|
2498
|
+
z15.object({
|
|
2499
|
+
type: z15.literal("summary_text"),
|
|
2500
|
+
text: z15.string()
|
|
2430
2501
|
})
|
|
2431
2502
|
)
|
|
2432
2503
|
})
|
|
2433
2504
|
])
|
|
2434
2505
|
),
|
|
2435
|
-
incomplete_details:
|
|
2506
|
+
incomplete_details: z15.object({ reason: z15.string() }).nullable(),
|
|
2436
2507
|
usage: usageSchema2
|
|
2437
2508
|
})
|
|
2438
2509
|
),
|
|
@@ -2443,10 +2514,23 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2443
2514
|
for (const part of response.output) {
|
|
2444
2515
|
switch (part.type) {
|
|
2445
2516
|
case "reasoning": {
|
|
2446
|
-
|
|
2447
|
-
type: "
|
|
2448
|
-
|
|
2449
|
-
|
|
2517
|
+
if (part.summary.length === 0) {
|
|
2518
|
+
part.summary.push({ type: "summary_text", text: "" });
|
|
2519
|
+
}
|
|
2520
|
+
for (const summary of part.summary) {
|
|
2521
|
+
content.push({
|
|
2522
|
+
type: "reasoning",
|
|
2523
|
+
text: summary.text,
|
|
2524
|
+
providerMetadata: {
|
|
2525
|
+
openai: {
|
|
2526
|
+
reasoning: {
|
|
2527
|
+
id: part.id,
|
|
2528
|
+
encryptedContent: (_a = part.encrypted_content) != null ? _a : null
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
});
|
|
2533
|
+
}
|
|
2450
2534
|
break;
|
|
2451
2535
|
}
|
|
2452
2536
|
case "message": {
|
|
@@ -2459,7 +2543,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2459
2543
|
content.push({
|
|
2460
2544
|
type: "source",
|
|
2461
2545
|
sourceType: "url",
|
|
2462
|
-
id: (
|
|
2546
|
+
id: (_d = (_c = (_b = this.config).generateId) == null ? void 0 : _c.call(_b)) != null ? _d : generateId2(),
|
|
2463
2547
|
url: annotation.url,
|
|
2464
2548
|
title: annotation.title
|
|
2465
2549
|
});
|
|
@@ -2518,15 +2602,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2518
2602
|
return {
|
|
2519
2603
|
content,
|
|
2520
2604
|
finishReason: mapOpenAIResponseFinishReason({
|
|
2521
|
-
finishReason: (
|
|
2605
|
+
finishReason: (_e = response.incomplete_details) == null ? void 0 : _e.reason,
|
|
2522
2606
|
hasToolCalls: content.some((part) => part.type === "tool-call")
|
|
2523
2607
|
}),
|
|
2524
2608
|
usage: {
|
|
2525
2609
|
inputTokens: response.usage.input_tokens,
|
|
2526
2610
|
outputTokens: response.usage.output_tokens,
|
|
2527
2611
|
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
2528
|
-
reasoningTokens: (
|
|
2529
|
-
cachedInputTokens: (
|
|
2612
|
+
reasoningTokens: (_g = (_f = response.usage.output_tokens_details) == null ? void 0 : _f.reasoning_tokens) != null ? _g : void 0,
|
|
2613
|
+
cachedInputTokens: (_i = (_h = response.usage.input_tokens_details) == null ? void 0 : _h.cached_tokens) != null ? _i : void 0
|
|
2530
2614
|
},
|
|
2531
2615
|
request: { body },
|
|
2532
2616
|
response: {
|
|
@@ -2580,7 +2664,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2580
2664
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2581
2665
|
},
|
|
2582
2666
|
transform(chunk, controller) {
|
|
2583
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2667
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2584
2668
|
if (options.includeRawChunks) {
|
|
2585
2669
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2586
2670
|
}
|
|
@@ -2629,7 +2713,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2629
2713
|
} else if (value.item.type === "reasoning") {
|
|
2630
2714
|
controller.enqueue({
|
|
2631
2715
|
type: "reasoning-start",
|
|
2632
|
-
id: value.item.id
|
|
2716
|
+
id: value.item.id,
|
|
2717
|
+
providerMetadata: {
|
|
2718
|
+
openai: {
|
|
2719
|
+
reasoning: {
|
|
2720
|
+
id: value.item.id,
|
|
2721
|
+
encryptedContent: (_a = value.item.encrypted_content) != null ? _a : null
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
}
|
|
2633
2725
|
});
|
|
2634
2726
|
}
|
|
2635
2727
|
} else if (isResponseOutputItemDoneChunk(value)) {
|
|
@@ -2702,7 +2794,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2702
2794
|
} else if (value.item.type === "reasoning") {
|
|
2703
2795
|
controller.enqueue({
|
|
2704
2796
|
type: "reasoning-end",
|
|
2705
|
-
id: value.item.id
|
|
2797
|
+
id: value.item.id,
|
|
2798
|
+
providerMetadata: {
|
|
2799
|
+
openai: {
|
|
2800
|
+
reasoning: {
|
|
2801
|
+
id: value.item.id,
|
|
2802
|
+
encryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2706
2806
|
});
|
|
2707
2807
|
}
|
|
2708
2808
|
} else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
|
|
@@ -2731,24 +2831,24 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2731
2831
|
} else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
|
|
2732
2832
|
controller.enqueue({
|
|
2733
2833
|
type: "reasoning-delta",
|
|
2734
|
-
|
|
2735
|
-
|
|
2834
|
+
id: value.item_id,
|
|
2835
|
+
delta: value.delta
|
|
2736
2836
|
});
|
|
2737
2837
|
} else if (isResponseFinishedChunk(value)) {
|
|
2738
2838
|
finishReason = mapOpenAIResponseFinishReason({
|
|
2739
|
-
finishReason: (
|
|
2839
|
+
finishReason: (_c = value.response.incomplete_details) == null ? void 0 : _c.reason,
|
|
2740
2840
|
hasToolCalls
|
|
2741
2841
|
});
|
|
2742
2842
|
usage.inputTokens = value.response.usage.input_tokens;
|
|
2743
2843
|
usage.outputTokens = value.response.usage.output_tokens;
|
|
2744
2844
|
usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
|
|
2745
|
-
usage.reasoningTokens = (
|
|
2746
|
-
usage.cachedInputTokens = (
|
|
2845
|
+
usage.reasoningTokens = (_e = (_d = value.response.usage.output_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : void 0;
|
|
2846
|
+
usage.cachedInputTokens = (_g = (_f = value.response.usage.input_tokens_details) == null ? void 0 : _f.cached_tokens) != null ? _g : void 0;
|
|
2747
2847
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
2748
2848
|
controller.enqueue({
|
|
2749
2849
|
type: "source",
|
|
2750
2850
|
sourceType: "url",
|
|
2751
|
-
id: (
|
|
2851
|
+
id: (_j = (_i = (_h = self.config).generateId) == null ? void 0 : _i.call(_h)) != null ? _j : generateId2(),
|
|
2752
2852
|
url: value.annotation.url,
|
|
2753
2853
|
title: value.annotation.title
|
|
2754
2854
|
});
|
|
@@ -2773,124 +2873,129 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2773
2873
|
};
|
|
2774
2874
|
}
|
|
2775
2875
|
};
|
|
2776
|
-
var usageSchema2 =
|
|
2777
|
-
input_tokens:
|
|
2778
|
-
input_tokens_details:
|
|
2779
|
-
output_tokens:
|
|
2780
|
-
output_tokens_details:
|
|
2876
|
+
var usageSchema2 = z15.object({
|
|
2877
|
+
input_tokens: z15.number(),
|
|
2878
|
+
input_tokens_details: z15.object({ cached_tokens: z15.number().nullish() }).nullish(),
|
|
2879
|
+
output_tokens: z15.number(),
|
|
2880
|
+
output_tokens_details: z15.object({ reasoning_tokens: z15.number().nullish() }).nullish()
|
|
2781
2881
|
});
|
|
2782
|
-
var textDeltaChunkSchema =
|
|
2783
|
-
type:
|
|
2784
|
-
item_id:
|
|
2785
|
-
delta:
|
|
2882
|
+
var textDeltaChunkSchema = z15.object({
|
|
2883
|
+
type: z15.literal("response.output_text.delta"),
|
|
2884
|
+
item_id: z15.string(),
|
|
2885
|
+
delta: z15.string()
|
|
2786
2886
|
});
|
|
2787
|
-
var responseFinishedChunkSchema =
|
|
2788
|
-
type:
|
|
2789
|
-
response:
|
|
2790
|
-
incomplete_details:
|
|
2887
|
+
var responseFinishedChunkSchema = z15.object({
|
|
2888
|
+
type: z15.enum(["response.completed", "response.incomplete"]),
|
|
2889
|
+
response: z15.object({
|
|
2890
|
+
incomplete_details: z15.object({ reason: z15.string() }).nullish(),
|
|
2791
2891
|
usage: usageSchema2
|
|
2792
2892
|
})
|
|
2793
2893
|
});
|
|
2794
|
-
var responseCreatedChunkSchema =
|
|
2795
|
-
type:
|
|
2796
|
-
response:
|
|
2797
|
-
id:
|
|
2798
|
-
created_at:
|
|
2799
|
-
model:
|
|
2894
|
+
var responseCreatedChunkSchema = z15.object({
|
|
2895
|
+
type: z15.literal("response.created"),
|
|
2896
|
+
response: z15.object({
|
|
2897
|
+
id: z15.string(),
|
|
2898
|
+
created_at: z15.number(),
|
|
2899
|
+
model: z15.string()
|
|
2800
2900
|
})
|
|
2801
2901
|
});
|
|
2802
|
-
var responseOutputItemAddedSchema =
|
|
2803
|
-
type:
|
|
2804
|
-
output_index:
|
|
2805
|
-
item:
|
|
2806
|
-
|
|
2807
|
-
type:
|
|
2808
|
-
id:
|
|
2902
|
+
var responseOutputItemAddedSchema = z15.object({
|
|
2903
|
+
type: z15.literal("response.output_item.added"),
|
|
2904
|
+
output_index: z15.number(),
|
|
2905
|
+
item: z15.discriminatedUnion("type", [
|
|
2906
|
+
z15.object({
|
|
2907
|
+
type: z15.literal("message"),
|
|
2908
|
+
id: z15.string()
|
|
2809
2909
|
}),
|
|
2810
|
-
|
|
2811
|
-
type:
|
|
2812
|
-
id:
|
|
2910
|
+
z15.object({
|
|
2911
|
+
type: z15.literal("reasoning"),
|
|
2912
|
+
id: z15.string(),
|
|
2913
|
+
encrypted_content: z15.string().nullish(),
|
|
2914
|
+
summary: z15.array(
|
|
2915
|
+
z15.object({
|
|
2916
|
+
type: z15.literal("summary_text"),
|
|
2917
|
+
text: z15.string()
|
|
2918
|
+
})
|
|
2919
|
+
)
|
|
2813
2920
|
}),
|
|
2814
|
-
|
|
2815
|
-
type:
|
|
2816
|
-
id:
|
|
2817
|
-
call_id:
|
|
2818
|
-
name:
|
|
2819
|
-
arguments:
|
|
2921
|
+
z15.object({
|
|
2922
|
+
type: z15.literal("function_call"),
|
|
2923
|
+
id: z15.string(),
|
|
2924
|
+
call_id: z15.string(),
|
|
2925
|
+
name: z15.string(),
|
|
2926
|
+
arguments: z15.string()
|
|
2820
2927
|
}),
|
|
2821
|
-
|
|
2822
|
-
type:
|
|
2823
|
-
id:
|
|
2824
|
-
status:
|
|
2928
|
+
z15.object({
|
|
2929
|
+
type: z15.literal("web_search_call"),
|
|
2930
|
+
id: z15.string(),
|
|
2931
|
+
status: z15.string()
|
|
2825
2932
|
}),
|
|
2826
|
-
|
|
2827
|
-
type:
|
|
2828
|
-
id:
|
|
2829
|
-
status:
|
|
2933
|
+
z15.object({
|
|
2934
|
+
type: z15.literal("computer_call"),
|
|
2935
|
+
id: z15.string(),
|
|
2936
|
+
status: z15.string()
|
|
2830
2937
|
})
|
|
2831
2938
|
])
|
|
2832
2939
|
});
|
|
2833
|
-
var responseOutputItemDoneSchema =
|
|
2834
|
-
type:
|
|
2835
|
-
output_index:
|
|
2836
|
-
item:
|
|
2837
|
-
|
|
2838
|
-
type:
|
|
2839
|
-
id:
|
|
2940
|
+
var responseOutputItemDoneSchema = z15.object({
|
|
2941
|
+
type: z15.literal("response.output_item.done"),
|
|
2942
|
+
output_index: z15.number(),
|
|
2943
|
+
item: z15.discriminatedUnion("type", [
|
|
2944
|
+
z15.object({
|
|
2945
|
+
type: z15.literal("message"),
|
|
2946
|
+
id: z15.string()
|
|
2840
2947
|
}),
|
|
2841
|
-
|
|
2842
|
-
type:
|
|
2843
|
-
id:
|
|
2948
|
+
z15.object({
|
|
2949
|
+
type: z15.literal("reasoning"),
|
|
2950
|
+
id: z15.string(),
|
|
2951
|
+
encrypted_content: z15.string().nullish(),
|
|
2952
|
+
summary: z15.array(
|
|
2953
|
+
z15.object({
|
|
2954
|
+
type: z15.literal("summary_text"),
|
|
2955
|
+
text: z15.string()
|
|
2956
|
+
})
|
|
2957
|
+
)
|
|
2844
2958
|
}),
|
|
2845
|
-
|
|
2846
|
-
type:
|
|
2847
|
-
id:
|
|
2848
|
-
call_id:
|
|
2849
|
-
name:
|
|
2850
|
-
arguments:
|
|
2851
|
-
status:
|
|
2959
|
+
z15.object({
|
|
2960
|
+
type: z15.literal("function_call"),
|
|
2961
|
+
id: z15.string(),
|
|
2962
|
+
call_id: z15.string(),
|
|
2963
|
+
name: z15.string(),
|
|
2964
|
+
arguments: z15.string(),
|
|
2965
|
+
status: z15.literal("completed")
|
|
2852
2966
|
}),
|
|
2853
|
-
|
|
2854
|
-
type:
|
|
2855
|
-
id:
|
|
2856
|
-
status:
|
|
2967
|
+
z15.object({
|
|
2968
|
+
type: z15.literal("web_search_call"),
|
|
2969
|
+
id: z15.string(),
|
|
2970
|
+
status: z15.literal("completed")
|
|
2857
2971
|
}),
|
|
2858
|
-
|
|
2859
|
-
type:
|
|
2860
|
-
id:
|
|
2861
|
-
status:
|
|
2972
|
+
z15.object({
|
|
2973
|
+
type: z15.literal("computer_call"),
|
|
2974
|
+
id: z15.string(),
|
|
2975
|
+
status: z15.literal("completed")
|
|
2862
2976
|
})
|
|
2863
2977
|
])
|
|
2864
2978
|
});
|
|
2865
|
-
var responseFunctionCallArgumentsDeltaSchema =
|
|
2866
|
-
type:
|
|
2867
|
-
item_id:
|
|
2868
|
-
output_index:
|
|
2869
|
-
delta:
|
|
2979
|
+
var responseFunctionCallArgumentsDeltaSchema = z15.object({
|
|
2980
|
+
type: z15.literal("response.function_call_arguments.delta"),
|
|
2981
|
+
item_id: z15.string(),
|
|
2982
|
+
output_index: z15.number(),
|
|
2983
|
+
delta: z15.string()
|
|
2870
2984
|
});
|
|
2871
|
-
var responseAnnotationAddedSchema =
|
|
2872
|
-
type:
|
|
2873
|
-
annotation:
|
|
2874
|
-
type:
|
|
2875
|
-
url:
|
|
2876
|
-
title:
|
|
2985
|
+
var responseAnnotationAddedSchema = z15.object({
|
|
2986
|
+
type: z15.literal("response.output_text.annotation.added"),
|
|
2987
|
+
annotation: z15.object({
|
|
2988
|
+
type: z15.literal("url_citation"),
|
|
2989
|
+
url: z15.string(),
|
|
2990
|
+
title: z15.string()
|
|
2877
2991
|
})
|
|
2878
2992
|
});
|
|
2879
|
-
var responseReasoningSummaryTextDeltaSchema =
|
|
2880
|
-
type:
|
|
2881
|
-
item_id:
|
|
2882
|
-
|
|
2883
|
-
summary_index: z14.number(),
|
|
2884
|
-
delta: z14.string()
|
|
2885
|
-
});
|
|
2886
|
-
var responseReasoningSummaryPartDoneSchema = z14.object({
|
|
2887
|
-
type: z14.literal("response.reasoning_summary_part.done"),
|
|
2888
|
-
item_id: z14.string(),
|
|
2889
|
-
output_index: z14.number(),
|
|
2890
|
-
summary_index: z14.number(),
|
|
2891
|
-
part: z14.unknown().nullish()
|
|
2993
|
+
var responseReasoningSummaryTextDeltaSchema = z15.object({
|
|
2994
|
+
type: z15.literal("response.reasoning_summary_text.delta"),
|
|
2995
|
+
item_id: z15.string(),
|
|
2996
|
+
delta: z15.string()
|
|
2892
2997
|
});
|
|
2893
|
-
var openaiResponsesChunkSchema =
|
|
2998
|
+
var openaiResponsesChunkSchema = z15.union([
|
|
2894
2999
|
textDeltaChunkSchema,
|
|
2895
3000
|
responseFinishedChunkSchema,
|
|
2896
3001
|
responseCreatedChunkSchema,
|
|
@@ -2899,8 +3004,7 @@ var openaiResponsesChunkSchema = z14.union([
|
|
|
2899
3004
|
responseFunctionCallArgumentsDeltaSchema,
|
|
2900
3005
|
responseAnnotationAddedSchema,
|
|
2901
3006
|
responseReasoningSummaryTextDeltaSchema,
|
|
2902
|
-
|
|
2903
|
-
z14.object({ type: z14.string() }).passthrough()
|
|
3007
|
+
z15.object({ type: z15.string() }).passthrough()
|
|
2904
3008
|
// fallback for unknown chunks
|
|
2905
3009
|
]);
|
|
2906
3010
|
function isTextDeltaChunk(chunk) {
|
|
@@ -2928,7 +3032,7 @@ function isResponseReasoningSummaryTextDeltaChunk(chunk) {
|
|
|
2928
3032
|
return chunk.type === "response.reasoning_summary_text.delta";
|
|
2929
3033
|
}
|
|
2930
3034
|
function getResponsesModelConfig(modelId) {
|
|
2931
|
-
if (modelId.startsWith("o")) {
|
|
3035
|
+
if (modelId.startsWith("o") || modelId.startsWith("codex-") || modelId.startsWith("computer-use")) {
|
|
2932
3036
|
if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {
|
|
2933
3037
|
return {
|
|
2934
3038
|
isReasoningModel: true,
|
|
@@ -2951,17 +3055,18 @@ function getResponsesModelConfig(modelId) {
|
|
|
2951
3055
|
function supportsFlexProcessing2(modelId) {
|
|
2952
3056
|
return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
2953
3057
|
}
|
|
2954
|
-
var openaiResponsesProviderOptionsSchema =
|
|
2955
|
-
metadata:
|
|
2956
|
-
parallelToolCalls:
|
|
2957
|
-
previousResponseId:
|
|
2958
|
-
store:
|
|
2959
|
-
user:
|
|
2960
|
-
reasoningEffort:
|
|
2961
|
-
|
|
2962
|
-
instructions:
|
|
2963
|
-
reasoningSummary:
|
|
2964
|
-
serviceTier:
|
|
3058
|
+
var openaiResponsesProviderOptionsSchema = z15.object({
|
|
3059
|
+
metadata: z15.any().nullish(),
|
|
3060
|
+
parallelToolCalls: z15.boolean().nullish(),
|
|
3061
|
+
previousResponseId: z15.string().nullish(),
|
|
3062
|
+
store: z15.boolean().nullish(),
|
|
3063
|
+
user: z15.string().nullish(),
|
|
3064
|
+
reasoningEffort: z15.string().nullish(),
|
|
3065
|
+
strictJsonSchema: z15.boolean().nullish(),
|
|
3066
|
+
instructions: z15.string().nullish(),
|
|
3067
|
+
reasoningSummary: z15.string().nullish(),
|
|
3068
|
+
serviceTier: z15.enum(["auto", "flex"]).nullish(),
|
|
3069
|
+
include: z15.array(z15.enum(["reasoning.encrypted_content"])).nullish()
|
|
2965
3070
|
});
|
|
2966
3071
|
export {
|
|
2967
3072
|
OpenAIChatLanguageModel,
|