@ai-sdk/openai 2.0.139 → 2.0.141
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 +37 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +249 -77
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +256 -78
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +2 -0
- package/dist/internal/index.d.ts +2 -0
- package/dist/internal/index.js +248 -76
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +255 -77
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/internal/index.mjs
CHANGED
|
@@ -83,9 +83,24 @@ function getGptVersion(modelId) {
|
|
|
83
83
|
import {
|
|
84
84
|
UnsupportedFunctionalityError
|
|
85
85
|
} from "@ai-sdk/provider";
|
|
86
|
-
import {
|
|
86
|
+
import {
|
|
87
|
+
stringifyWithBigIntAndCycles,
|
|
88
|
+
secureJsonParse,
|
|
89
|
+
convertToBase64
|
|
90
|
+
} from "@ai-sdk/provider-utils";
|
|
87
91
|
function serializeToolCallArguments(input) {
|
|
88
|
-
|
|
92
|
+
if (typeof input === "string") {
|
|
93
|
+
try {
|
|
94
|
+
const parsed = secureJsonParse(input);
|
|
95
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
96
|
+
return "{}";
|
|
97
|
+
}
|
|
98
|
+
return input;
|
|
99
|
+
} catch (e) {
|
|
100
|
+
return "{}";
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return stringifyWithBigIntAndCycles(
|
|
89
104
|
typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
|
|
90
105
|
);
|
|
91
106
|
}
|
|
@@ -308,7 +323,7 @@ function convertToOpenAIChatMessages({
|
|
|
308
323
|
case "content":
|
|
309
324
|
case "json":
|
|
310
325
|
case "error-json":
|
|
311
|
-
contentValue =
|
|
326
|
+
contentValue = stringifyWithBigIntAndCycles(output.value);
|
|
312
327
|
break;
|
|
313
328
|
}
|
|
314
329
|
messages.push({
|
|
@@ -348,10 +363,13 @@ function getResponseMetadata({
|
|
|
348
363
|
}
|
|
349
364
|
|
|
350
365
|
// src/chat/map-openai-finish-reason.ts
|
|
351
|
-
function mapOpenAIFinishReason(
|
|
366
|
+
function mapOpenAIFinishReason({
|
|
367
|
+
finishReason,
|
|
368
|
+
hasRefusal = false
|
|
369
|
+
}) {
|
|
352
370
|
switch (finishReason) {
|
|
353
371
|
case "stop":
|
|
354
|
-
return "stop";
|
|
372
|
+
return hasRefusal ? "content-filter" : "stop";
|
|
355
373
|
case "length":
|
|
356
374
|
return "length";
|
|
357
375
|
case "content_filter":
|
|
@@ -381,6 +399,8 @@ var openaiChatResponseSchema = lazyValidator(
|
|
|
381
399
|
message: z2.object({
|
|
382
400
|
role: z2.literal("assistant").nullish(),
|
|
383
401
|
content: z2.string().nullish(),
|
|
402
|
+
// set instead of `content` when the model refuses to answer:
|
|
403
|
+
refusal: z2.string().nullish(),
|
|
384
404
|
audio: z2.object({
|
|
385
405
|
transcript: z2.string().nullish()
|
|
386
406
|
}).nullish(),
|
|
@@ -419,6 +439,20 @@ var openaiChatResponseSchema = lazyValidator(
|
|
|
419
439
|
})
|
|
420
440
|
)
|
|
421
441
|
})
|
|
442
|
+
).nullish(),
|
|
443
|
+
// logprobs of the refusal tokens (set instead of `content` when
|
|
444
|
+
// the model refuses to answer):
|
|
445
|
+
refusal: z2.array(
|
|
446
|
+
z2.object({
|
|
447
|
+
token: z2.string(),
|
|
448
|
+
logprob: z2.number(),
|
|
449
|
+
top_logprobs: z2.array(
|
|
450
|
+
z2.object({
|
|
451
|
+
token: z2.string(),
|
|
452
|
+
logprob: z2.number()
|
|
453
|
+
})
|
|
454
|
+
)
|
|
455
|
+
})
|
|
422
456
|
).nullish()
|
|
423
457
|
}).nullish(),
|
|
424
458
|
finish_reason: z2.string().nullish()
|
|
@@ -453,6 +487,8 @@ var openaiChatChunkSchema = lazyValidator(
|
|
|
453
487
|
delta: z2.object({
|
|
454
488
|
role: z2.enum(["assistant"]).nullish(),
|
|
455
489
|
content: z2.string().nullish(),
|
|
490
|
+
// set instead of `content` when the model refuses to answer:
|
|
491
|
+
refusal: z2.string().nullish(),
|
|
456
492
|
tool_calls: z2.array(
|
|
457
493
|
z2.object({
|
|
458
494
|
index: z2.number(),
|
|
@@ -488,6 +524,20 @@ var openaiChatChunkSchema = lazyValidator(
|
|
|
488
524
|
})
|
|
489
525
|
)
|
|
490
526
|
})
|
|
527
|
+
).nullish(),
|
|
528
|
+
// logprobs of the refusal tokens (set instead of `content` when
|
|
529
|
+
// the model refuses to answer):
|
|
530
|
+
refusal: z2.array(
|
|
531
|
+
z2.object({
|
|
532
|
+
token: z2.string(),
|
|
533
|
+
logprob: z2.number(),
|
|
534
|
+
top_logprobs: z2.array(
|
|
535
|
+
z2.object({
|
|
536
|
+
token: z2.string(),
|
|
537
|
+
logprob: z2.number()
|
|
538
|
+
})
|
|
539
|
+
)
|
|
540
|
+
})
|
|
491
541
|
).nullish()
|
|
492
542
|
}).nullish(),
|
|
493
543
|
finish_reason: z2.string().nullish(),
|
|
@@ -924,7 +974,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
924
974
|
};
|
|
925
975
|
}
|
|
926
976
|
async doGenerate(options) {
|
|
927
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
977
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
928
978
|
const { args: body, warnings } = await this.getArgs(options);
|
|
929
979
|
const {
|
|
930
980
|
responseHeaders,
|
|
@@ -956,6 +1006,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
956
1006
|
if (text != null && text.length > 0) {
|
|
957
1007
|
content.push({ type: "text", text });
|
|
958
1008
|
}
|
|
1009
|
+
const refusal = choice.message.refusal;
|
|
1010
|
+
const hasRefusal = refusal != null && refusal.length > 0;
|
|
1011
|
+
if (hasRefusal) {
|
|
1012
|
+
content.push({ type: "text", text: refusal });
|
|
1013
|
+
}
|
|
959
1014
|
for (const toolCall of (_b = choice.message.tool_calls) != null ? _b : []) {
|
|
960
1015
|
content.push({
|
|
961
1016
|
type: "tool-call",
|
|
@@ -987,18 +1042,26 @@ var OpenAIChatLanguageModel = class {
|
|
|
987
1042
|
cacheWriteTokens: promptTokenDetails.cache_write_tokens
|
|
988
1043
|
};
|
|
989
1044
|
}
|
|
990
|
-
|
|
991
|
-
|
|
1045
|
+
const contentLogprobs = (_g = choice.logprobs) == null ? void 0 : _g.content;
|
|
1046
|
+
const refusalLogprobs = (_h = choice.logprobs) == null ? void 0 : _h.refusal;
|
|
1047
|
+
if (contentLogprobs != null || refusalLogprobs != null) {
|
|
1048
|
+
providerMetadata.openai.logprobs = [
|
|
1049
|
+
...contentLogprobs != null ? contentLogprobs : [],
|
|
1050
|
+
...refusalLogprobs != null ? refusalLogprobs : []
|
|
1051
|
+
];
|
|
992
1052
|
}
|
|
993
1053
|
return {
|
|
994
1054
|
content,
|
|
995
|
-
finishReason: mapOpenAIFinishReason(
|
|
1055
|
+
finishReason: mapOpenAIFinishReason({
|
|
1056
|
+
finishReason: choice.finish_reason,
|
|
1057
|
+
hasRefusal
|
|
1058
|
+
}),
|
|
996
1059
|
usage: {
|
|
997
|
-
inputTokens: (
|
|
998
|
-
outputTokens: (
|
|
999
|
-
totalTokens: (
|
|
1000
|
-
reasoningTokens: (
|
|
1001
|
-
cachedInputTokens: (
|
|
1060
|
+
inputTokens: (_j = (_i = response.usage) == null ? void 0 : _i.prompt_tokens) != null ? _j : void 0,
|
|
1061
|
+
outputTokens: (_l = (_k = response.usage) == null ? void 0 : _k.completion_tokens) != null ? _l : void 0,
|
|
1062
|
+
totalTokens: (_n = (_m = response.usage) == null ? void 0 : _m.total_tokens) != null ? _n : void 0,
|
|
1063
|
+
reasoningTokens: (_o = completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens) != null ? _o : void 0,
|
|
1064
|
+
cachedInputTokens: (_p = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens) != null ? _p : void 0
|
|
1002
1065
|
},
|
|
1003
1066
|
request: { body },
|
|
1004
1067
|
response: {
|
|
@@ -1042,6 +1105,10 @@ var OpenAIChatLanguageModel = class {
|
|
|
1042
1105
|
};
|
|
1043
1106
|
let metadataExtracted = false;
|
|
1044
1107
|
let isActiveText = false;
|
|
1108
|
+
let hasRefusal = false;
|
|
1109
|
+
let rawFinishReason = void 0;
|
|
1110
|
+
let hasLogprobs = false;
|
|
1111
|
+
const streamedLogprobs = [];
|
|
1045
1112
|
const providerMetadata = { openai: {} };
|
|
1046
1113
|
return {
|
|
1047
1114
|
stream: response.pipeThrough(
|
|
@@ -1054,18 +1121,20 @@ var OpenAIChatLanguageModel = class {
|
|
|
1054
1121
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1055
1122
|
},
|
|
1056
1123
|
transform(chunk, controller) {
|
|
1057
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l
|
|
1124
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1058
1125
|
if (options.includeRawChunks) {
|
|
1059
1126
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1060
1127
|
}
|
|
1061
1128
|
if (!chunk.success) {
|
|
1062
1129
|
finishReason = "error";
|
|
1130
|
+
rawFinishReason = void 0;
|
|
1063
1131
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
1064
1132
|
return;
|
|
1065
1133
|
}
|
|
1066
1134
|
const value = chunk.value;
|
|
1067
1135
|
if ("error" in value) {
|
|
1068
1136
|
finishReason = "error";
|
|
1137
|
+
rawFinishReason = void 0;
|
|
1069
1138
|
controller.enqueue({ type: "error", error: value.error });
|
|
1070
1139
|
return;
|
|
1071
1140
|
}
|
|
@@ -1099,16 +1168,35 @@ var OpenAIChatLanguageModel = class {
|
|
|
1099
1168
|
}
|
|
1100
1169
|
const choice = value.choices[0];
|
|
1101
1170
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
1102
|
-
|
|
1171
|
+
rawFinishReason = choice.finish_reason;
|
|
1103
1172
|
}
|
|
1104
|
-
if ((
|
|
1105
|
-
|
|
1173
|
+
if ((choice == null ? void 0 : choice.logprobs) != null) {
|
|
1174
|
+
const contentLogprobs = choice.logprobs.content;
|
|
1175
|
+
const refusalLogprobs = choice.logprobs.refusal;
|
|
1176
|
+
if (contentLogprobs != null || refusalLogprobs != null) {
|
|
1177
|
+
hasLogprobs = true;
|
|
1178
|
+
streamedLogprobs.push(
|
|
1179
|
+
...contentLogprobs != null ? contentLogprobs : [],
|
|
1180
|
+
...refusalLogprobs != null ? refusalLogprobs : []
|
|
1181
|
+
);
|
|
1182
|
+
}
|
|
1106
1183
|
}
|
|
1107
1184
|
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
1108
1185
|
return;
|
|
1109
1186
|
}
|
|
1110
1187
|
const delta = choice.delta;
|
|
1111
|
-
|
|
1188
|
+
const textDeltas = [];
|
|
1189
|
+
if (delta.content != null && delta.content.length > 0) {
|
|
1190
|
+
textDeltas.push(delta.content);
|
|
1191
|
+
}
|
|
1192
|
+
if (delta.refusal != null && delta.refusal.length > 0) {
|
|
1193
|
+
hasRefusal = true;
|
|
1194
|
+
textDeltas.push(delta.refusal);
|
|
1195
|
+
}
|
|
1196
|
+
if (textDeltas.length === 0 && delta.content === "") {
|
|
1197
|
+
textDeltas.push(delta.content);
|
|
1198
|
+
}
|
|
1199
|
+
for (const textDelta of textDeltas) {
|
|
1112
1200
|
if (!isActiveText) {
|
|
1113
1201
|
controller.enqueue({ type: "text-start", id: "0" });
|
|
1114
1202
|
isActiveText = true;
|
|
@@ -1116,7 +1204,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1116
1204
|
controller.enqueue({
|
|
1117
1205
|
type: "text-delta",
|
|
1118
1206
|
id: "0",
|
|
1119
|
-
delta:
|
|
1207
|
+
delta: textDelta
|
|
1120
1208
|
});
|
|
1121
1209
|
}
|
|
1122
1210
|
if (delta.tool_calls != null) {
|
|
@@ -1141,6 +1229,15 @@ var OpenAIChatLanguageModel = class {
|
|
|
1141
1229
|
controller.enqueue({ type: "text-end", id: "0" });
|
|
1142
1230
|
}
|
|
1143
1231
|
toolCallTracker.flush();
|
|
1232
|
+
if (rawFinishReason != null) {
|
|
1233
|
+
finishReason = mapOpenAIFinishReason({
|
|
1234
|
+
finishReason: rawFinishReason,
|
|
1235
|
+
hasRefusal
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
if (hasLogprobs) {
|
|
1239
|
+
providerMetadata.openai.logprobs = streamedLogprobs;
|
|
1240
|
+
}
|
|
1144
1241
|
controller.enqueue({
|
|
1145
1242
|
type: "finish",
|
|
1146
1243
|
finishReason,
|
|
@@ -2032,6 +2129,16 @@ var openAITranscriptionProviderOptions = lazyValidator10(
|
|
|
2032
2129
|
* The language of the input audio in ISO-639-1 format.
|
|
2033
2130
|
*/
|
|
2034
2131
|
language: z11.string().optional(),
|
|
2132
|
+
/**
|
|
2133
|
+
* Expected languages for REST transcription, e.g. with gpt-transcribe.
|
|
2134
|
+
* Use this instead of language. The API validates model support.
|
|
2135
|
+
*/
|
|
2136
|
+
languages: z11.array(z11.string()).optional(),
|
|
2137
|
+
/**
|
|
2138
|
+
* Vocabulary hints for REST transcription, e.g. names or technical terms.
|
|
2139
|
+
* The API validates model support.
|
|
2140
|
+
*/
|
|
2141
|
+
keywords: z11.array(z11.string()).optional(),
|
|
2035
2142
|
/**
|
|
2036
2143
|
* An optional text to guide the model's style or continue a previous audio segment.
|
|
2037
2144
|
*/
|
|
@@ -2143,6 +2250,8 @@ var OpenAITranscriptionModel = class {
|
|
|
2143
2250
|
const transcriptionModelOptions = {
|
|
2144
2251
|
include: openAIOptions.include,
|
|
2145
2252
|
language: openAIOptions.language,
|
|
2253
|
+
languages: openAIOptions.languages,
|
|
2254
|
+
keywords: openAIOptions.keywords,
|
|
2146
2255
|
prompt: openAIOptions.prompt,
|
|
2147
2256
|
// https://platform.openai.com/docs/api-reference/audio/createTranscription#audio_createtranscription-response_format
|
|
2148
2257
|
// prefer verbose_json to get segments for models that support it
|
|
@@ -2361,6 +2470,8 @@ import {
|
|
|
2361
2470
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError4
|
|
2362
2471
|
} from "@ai-sdk/provider";
|
|
2363
2472
|
import {
|
|
2473
|
+
stringifyWithBigIntAndCycles as stringifyWithBigIntAndCycles2,
|
|
2474
|
+
secureJsonParse as secureJsonParse2,
|
|
2364
2475
|
lazySchema as lazySchema4,
|
|
2365
2476
|
zodSchema as zodSchema16,
|
|
2366
2477
|
convertToBase64 as convertToBase642,
|
|
@@ -2944,7 +3055,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2944
3055
|
type: "function_call",
|
|
2945
3056
|
call_id: part.toolCallId,
|
|
2946
3057
|
name: part.toolName,
|
|
2947
|
-
arguments:
|
|
3058
|
+
arguments: serializeToolCallArguments2(part.input),
|
|
2948
3059
|
...isAsync != null && { async: isAsync },
|
|
2949
3060
|
id: canUseItemId ? id : void 0
|
|
2950
3061
|
});
|
|
@@ -3006,7 +3117,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3006
3117
|
} else if (reasoningMessage !== void 0) {
|
|
3007
3118
|
warnings.push({
|
|
3008
3119
|
type: "other",
|
|
3009
|
-
message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${
|
|
3120
|
+
message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${stringifyWithBigIntAndCycles2(part)}.`
|
|
3010
3121
|
});
|
|
3011
3122
|
}
|
|
3012
3123
|
if (reasoningMessage === void 0) {
|
|
@@ -3027,7 +3138,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3027
3138
|
} else {
|
|
3028
3139
|
warnings.push({
|
|
3029
3140
|
type: "other",
|
|
3030
|
-
message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${
|
|
3141
|
+
message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${stringifyWithBigIntAndCycles2(part)}.`
|
|
3031
3142
|
});
|
|
3032
3143
|
}
|
|
3033
3144
|
break;
|
|
@@ -3068,10 +3179,10 @@ async function convertToOpenAIResponsesInput({
|
|
|
3068
3179
|
break;
|
|
3069
3180
|
case "json":
|
|
3070
3181
|
case "error-json":
|
|
3071
|
-
contentValue = promptCacheBreakpoint == null ?
|
|
3182
|
+
contentValue = promptCacheBreakpoint == null ? stringifyWithBigIntAndCycles2(output.value) : [
|
|
3072
3183
|
{
|
|
3073
3184
|
type: "input_text",
|
|
3074
|
-
text:
|
|
3185
|
+
text: stringifyWithBigIntAndCycles2(output.value),
|
|
3075
3186
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3076
3187
|
}
|
|
3077
3188
|
];
|
|
@@ -3144,16 +3255,29 @@ var openaiResponsesReasoningProviderOptionsSchema = lazySchema4(
|
|
|
3144
3255
|
})
|
|
3145
3256
|
)
|
|
3146
3257
|
);
|
|
3258
|
+
function serializeToolCallArguments2(input) {
|
|
3259
|
+
if (typeof input === "string") {
|
|
3260
|
+
try {
|
|
3261
|
+
secureJsonParse2(input);
|
|
3262
|
+
return input;
|
|
3263
|
+
} catch (e) {
|
|
3264
|
+
return stringifyWithBigIntAndCycles2(input);
|
|
3265
|
+
}
|
|
3266
|
+
}
|
|
3267
|
+
return stringifyWithBigIntAndCycles2(input === void 0 ? {} : input);
|
|
3268
|
+
}
|
|
3147
3269
|
|
|
3148
3270
|
// src/responses/map-openai-responses-finish-reason.ts
|
|
3149
3271
|
function mapOpenAIResponseFinishReason({
|
|
3150
3272
|
finishReason,
|
|
3151
|
-
hasFunctionCall
|
|
3273
|
+
hasFunctionCall,
|
|
3274
|
+
hasRefusal = false
|
|
3152
3275
|
}) {
|
|
3153
3276
|
switch (finishReason) {
|
|
3154
3277
|
case void 0:
|
|
3155
3278
|
case null:
|
|
3156
|
-
|
|
3279
|
+
if (hasFunctionCall) return "tool-calls";
|
|
3280
|
+
return hasRefusal ? "content-filter" : "stop";
|
|
3157
3281
|
case "max_output_tokens":
|
|
3158
3282
|
return "length";
|
|
3159
3283
|
case "content_filter":
|
|
@@ -3189,6 +3313,20 @@ var openaiResponsesChunkSchema = lazyValidator13(
|
|
|
3189
3313
|
})
|
|
3190
3314
|
).nullish()
|
|
3191
3315
|
}),
|
|
3316
|
+
z17.object({
|
|
3317
|
+
type: z17.literal("response.refusal.delta"),
|
|
3318
|
+
item_id: z17.string(),
|
|
3319
|
+
output_index: z17.number().nullish(),
|
|
3320
|
+
content_index: z17.number().nullish(),
|
|
3321
|
+
delta: z17.string()
|
|
3322
|
+
}),
|
|
3323
|
+
z17.object({
|
|
3324
|
+
type: z17.literal("response.refusal.done"),
|
|
3325
|
+
item_id: z17.string(),
|
|
3326
|
+
output_index: z17.number().nullish(),
|
|
3327
|
+
content_index: z17.number().nullish(),
|
|
3328
|
+
refusal: z17.string()
|
|
3329
|
+
}),
|
|
3192
3330
|
z17.object({
|
|
3193
3331
|
type: z17.enum(["response.completed", "response.incomplete"]),
|
|
3194
3332
|
response: z17.object({
|
|
@@ -3475,57 +3613,64 @@ var openaiResponsesResponseSchema = lazyValidator13(
|
|
|
3475
3613
|
role: z17.literal("assistant"),
|
|
3476
3614
|
id: z17.string(),
|
|
3477
3615
|
phase: z17.enum(["commentary", "final_answer"]).nullish(),
|
|
3616
|
+
// the API returns either text or a refusal as content parts:
|
|
3478
3617
|
content: z17.array(
|
|
3479
|
-
z17.
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
z17.
|
|
3484
|
-
token: z17.string(),
|
|
3485
|
-
logprob: z17.number(),
|
|
3486
|
-
top_logprobs: z17.array(
|
|
3487
|
-
z17.object({
|
|
3488
|
-
token: z17.string(),
|
|
3489
|
-
logprob: z17.number()
|
|
3490
|
-
})
|
|
3491
|
-
)
|
|
3492
|
-
})
|
|
3493
|
-
).nullish(),
|
|
3494
|
-
annotations: z17.array(
|
|
3495
|
-
z17.discriminatedUnion("type", [
|
|
3496
|
-
z17.object({
|
|
3497
|
-
type: z17.literal("url_citation"),
|
|
3498
|
-
start_index: z17.number(),
|
|
3499
|
-
end_index: z17.number(),
|
|
3500
|
-
url: z17.string(),
|
|
3501
|
-
title: z17.string()
|
|
3502
|
-
}),
|
|
3503
|
-
z17.object({
|
|
3504
|
-
type: z17.literal("file_citation"),
|
|
3505
|
-
file_id: z17.string(),
|
|
3506
|
-
filename: z17.string().nullish(),
|
|
3507
|
-
index: z17.number().nullish(),
|
|
3508
|
-
start_index: z17.number().nullish(),
|
|
3509
|
-
end_index: z17.number().nullish(),
|
|
3510
|
-
quote: z17.string().nullish()
|
|
3511
|
-
}),
|
|
3512
|
-
z17.object({
|
|
3513
|
-
type: z17.literal("container_file_citation"),
|
|
3514
|
-
container_id: z17.string(),
|
|
3515
|
-
file_id: z17.string(),
|
|
3516
|
-
filename: z17.string().nullish(),
|
|
3517
|
-
start_index: z17.number().nullish(),
|
|
3518
|
-
end_index: z17.number().nullish(),
|
|
3519
|
-
index: z17.number().nullish()
|
|
3520
|
-
}),
|
|
3618
|
+
z17.discriminatedUnion("type", [
|
|
3619
|
+
z17.object({
|
|
3620
|
+
type: z17.literal("output_text"),
|
|
3621
|
+
text: z17.string(),
|
|
3622
|
+
logprobs: z17.array(
|
|
3521
3623
|
z17.object({
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3624
|
+
token: z17.string(),
|
|
3625
|
+
logprob: z17.number(),
|
|
3626
|
+
top_logprobs: z17.array(
|
|
3627
|
+
z17.object({
|
|
3628
|
+
token: z17.string(),
|
|
3629
|
+
logprob: z17.number()
|
|
3630
|
+
})
|
|
3631
|
+
)
|
|
3525
3632
|
})
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3633
|
+
).nullish(),
|
|
3634
|
+
annotations: z17.array(
|
|
3635
|
+
z17.discriminatedUnion("type", [
|
|
3636
|
+
z17.object({
|
|
3637
|
+
type: z17.literal("url_citation"),
|
|
3638
|
+
start_index: z17.number(),
|
|
3639
|
+
end_index: z17.number(),
|
|
3640
|
+
url: z17.string(),
|
|
3641
|
+
title: z17.string()
|
|
3642
|
+
}),
|
|
3643
|
+
z17.object({
|
|
3644
|
+
type: z17.literal("file_citation"),
|
|
3645
|
+
file_id: z17.string(),
|
|
3646
|
+
filename: z17.string().nullish(),
|
|
3647
|
+
index: z17.number().nullish(),
|
|
3648
|
+
start_index: z17.number().nullish(),
|
|
3649
|
+
end_index: z17.number().nullish(),
|
|
3650
|
+
quote: z17.string().nullish()
|
|
3651
|
+
}),
|
|
3652
|
+
z17.object({
|
|
3653
|
+
type: z17.literal("container_file_citation"),
|
|
3654
|
+
container_id: z17.string(),
|
|
3655
|
+
file_id: z17.string(),
|
|
3656
|
+
filename: z17.string().nullish(),
|
|
3657
|
+
start_index: z17.number().nullish(),
|
|
3658
|
+
end_index: z17.number().nullish(),
|
|
3659
|
+
index: z17.number().nullish()
|
|
3660
|
+
}),
|
|
3661
|
+
z17.object({
|
|
3662
|
+
type: z17.literal("file_path"),
|
|
3663
|
+
file_id: z17.string(),
|
|
3664
|
+
index: z17.number().nullish()
|
|
3665
|
+
})
|
|
3666
|
+
])
|
|
3667
|
+
)
|
|
3668
|
+
}),
|
|
3669
|
+
z17.object({
|
|
3670
|
+
type: z17.literal("refusal"),
|
|
3671
|
+
refusal: z17.string()
|
|
3672
|
+
})
|
|
3673
|
+
])
|
|
3529
3674
|
)
|
|
3530
3675
|
}),
|
|
3531
3676
|
z17.object({
|
|
@@ -4387,6 +4532,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4387
4532
|
const content = [];
|
|
4388
4533
|
const logprobs = [];
|
|
4389
4534
|
let hasFunctionCall = false;
|
|
4535
|
+
let hasRefusal = false;
|
|
4390
4536
|
for (const part of response.output) {
|
|
4391
4537
|
switch (part.type) {
|
|
4392
4538
|
case "reasoning": {
|
|
@@ -4444,6 +4590,20 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4444
4590
|
}
|
|
4445
4591
|
case "message": {
|
|
4446
4592
|
for (const contentPart of part.content) {
|
|
4593
|
+
if (contentPart.type === "refusal") {
|
|
4594
|
+
hasRefusal = true;
|
|
4595
|
+
content.push({
|
|
4596
|
+
type: "text",
|
|
4597
|
+
text: contentPart.refusal,
|
|
4598
|
+
providerMetadata: {
|
|
4599
|
+
[providerKey]: {
|
|
4600
|
+
itemId: part.id,
|
|
4601
|
+
...part.phase != null && { phase: part.phase }
|
|
4602
|
+
}
|
|
4603
|
+
}
|
|
4604
|
+
});
|
|
4605
|
+
continue;
|
|
4606
|
+
}
|
|
4447
4607
|
if (((_c = (_b = options.providerOptions) == null ? void 0 : _b.openai) == null ? void 0 : _c.logprobs) && contentPart.logprobs) {
|
|
4448
4608
|
logprobs.push(contentPart.logprobs);
|
|
4449
4609
|
}
|
|
@@ -4644,7 +4804,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4644
4804
|
content,
|
|
4645
4805
|
finishReason: mapOpenAIResponseFinishReason({
|
|
4646
4806
|
finishReason: (_y = response.incomplete_details) == null ? void 0 : _y.reason,
|
|
4647
|
-
hasFunctionCall
|
|
4807
|
+
hasFunctionCall,
|
|
4808
|
+
hasRefusal
|
|
4648
4809
|
}),
|
|
4649
4810
|
usage: {
|
|
4650
4811
|
inputTokens: usage.input_tokens,
|
|
@@ -4703,6 +4864,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4703
4864
|
const ongoingAnnotations = [];
|
|
4704
4865
|
let activeMessagePhase;
|
|
4705
4866
|
let hasFunctionCall = false;
|
|
4867
|
+
let hasRefusal = false;
|
|
4706
4868
|
const activeReasoning = {};
|
|
4707
4869
|
let serviceTier;
|
|
4708
4870
|
let reasoningContext;
|
|
@@ -5044,6 +5206,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5044
5206
|
if (((_h = (_g = options.providerOptions) == null ? void 0 : _g.openai) == null ? void 0 : _h.logprobs) && value.logprobs) {
|
|
5045
5207
|
logprobs.push(value.logprobs);
|
|
5046
5208
|
}
|
|
5209
|
+
} else if (isRefusalDeltaChunk(value)) {
|
|
5210
|
+
hasRefusal = true;
|
|
5211
|
+
controller.enqueue({
|
|
5212
|
+
type: "text-delta",
|
|
5213
|
+
id: value.item_id,
|
|
5214
|
+
delta: value.delta
|
|
5215
|
+
});
|
|
5216
|
+
} else if (isRefusalDoneChunk(value)) {
|
|
5217
|
+
hasRefusal = true;
|
|
5047
5218
|
} else if (value.type === "response.reasoning_summary_part.added") {
|
|
5048
5219
|
if (value.summary_index > 0) {
|
|
5049
5220
|
const activeReasoningPart = activeReasoning[value.item_id];
|
|
@@ -5100,7 +5271,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5100
5271
|
} else if (isResponseFinishedChunk(value)) {
|
|
5101
5272
|
finishReason = mapOpenAIResponseFinishReason({
|
|
5102
5273
|
finishReason: (_k = value.response.incomplete_details) == null ? void 0 : _k.reason,
|
|
5103
|
-
hasFunctionCall
|
|
5274
|
+
hasFunctionCall,
|
|
5275
|
+
hasRefusal
|
|
5104
5276
|
});
|
|
5105
5277
|
usage.inputTokens = value.response.usage.input_tokens;
|
|
5106
5278
|
usage.outputTokens = value.response.usage.output_tokens;
|
|
@@ -5177,6 +5349,12 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5177
5349
|
};
|
|
5178
5350
|
}
|
|
5179
5351
|
};
|
|
5352
|
+
function isRefusalDeltaChunk(chunk) {
|
|
5353
|
+
return chunk.type === "response.refusal.delta";
|
|
5354
|
+
}
|
|
5355
|
+
function isRefusalDoneChunk(chunk) {
|
|
5356
|
+
return chunk.type === "response.refusal.done";
|
|
5357
|
+
}
|
|
5180
5358
|
function isTextDeltaChunk(chunk) {
|
|
5181
5359
|
return chunk.type === "response.output_text.delta";
|
|
5182
5360
|
}
|