@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/dist/index.mjs CHANGED
@@ -91,9 +91,24 @@ function getGptVersion(modelId) {
91
91
  import {
92
92
  UnsupportedFunctionalityError
93
93
  } from "@ai-sdk/provider";
94
- import { convertToBase64 } from "@ai-sdk/provider-utils";
94
+ import {
95
+ stringifyWithBigIntAndCycles,
96
+ secureJsonParse,
97
+ convertToBase64
98
+ } from "@ai-sdk/provider-utils";
95
99
  function serializeToolCallArguments(input) {
96
- return JSON.stringify(
100
+ if (typeof input === "string") {
101
+ try {
102
+ const parsed = secureJsonParse(input);
103
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
104
+ return "{}";
105
+ }
106
+ return input;
107
+ } catch (e) {
108
+ return "{}";
109
+ }
110
+ }
111
+ return stringifyWithBigIntAndCycles(
97
112
  typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
98
113
  );
99
114
  }
@@ -316,7 +331,7 @@ function convertToOpenAIChatMessages({
316
331
  case "content":
317
332
  case "json":
318
333
  case "error-json":
319
- contentValue = JSON.stringify(output.value);
334
+ contentValue = stringifyWithBigIntAndCycles(output.value);
320
335
  break;
321
336
  }
322
337
  messages.push({
@@ -356,10 +371,13 @@ function getResponseMetadata({
356
371
  }
357
372
 
358
373
  // src/chat/map-openai-finish-reason.ts
359
- function mapOpenAIFinishReason(finishReason) {
374
+ function mapOpenAIFinishReason({
375
+ finishReason,
376
+ hasRefusal = false
377
+ }) {
360
378
  switch (finishReason) {
361
379
  case "stop":
362
- return "stop";
380
+ return hasRefusal ? "content-filter" : "stop";
363
381
  case "length":
364
382
  return "length";
365
383
  case "content_filter":
@@ -389,6 +407,8 @@ var openaiChatResponseSchema = lazyValidator(
389
407
  message: z2.object({
390
408
  role: z2.literal("assistant").nullish(),
391
409
  content: z2.string().nullish(),
410
+ // set instead of `content` when the model refuses to answer:
411
+ refusal: z2.string().nullish(),
392
412
  audio: z2.object({
393
413
  transcript: z2.string().nullish()
394
414
  }).nullish(),
@@ -427,6 +447,20 @@ var openaiChatResponseSchema = lazyValidator(
427
447
  })
428
448
  )
429
449
  })
450
+ ).nullish(),
451
+ // logprobs of the refusal tokens (set instead of `content` when
452
+ // the model refuses to answer):
453
+ refusal: z2.array(
454
+ z2.object({
455
+ token: z2.string(),
456
+ logprob: z2.number(),
457
+ top_logprobs: z2.array(
458
+ z2.object({
459
+ token: z2.string(),
460
+ logprob: z2.number()
461
+ })
462
+ )
463
+ })
430
464
  ).nullish()
431
465
  }).nullish(),
432
466
  finish_reason: z2.string().nullish()
@@ -461,6 +495,8 @@ var openaiChatChunkSchema = lazyValidator(
461
495
  delta: z2.object({
462
496
  role: z2.enum(["assistant"]).nullish(),
463
497
  content: z2.string().nullish(),
498
+ // set instead of `content` when the model refuses to answer:
499
+ refusal: z2.string().nullish(),
464
500
  tool_calls: z2.array(
465
501
  z2.object({
466
502
  index: z2.number(),
@@ -496,6 +532,20 @@ var openaiChatChunkSchema = lazyValidator(
496
532
  })
497
533
  )
498
534
  })
535
+ ).nullish(),
536
+ // logprobs of the refusal tokens (set instead of `content` when
537
+ // the model refuses to answer):
538
+ refusal: z2.array(
539
+ z2.object({
540
+ token: z2.string(),
541
+ logprob: z2.number(),
542
+ top_logprobs: z2.array(
543
+ z2.object({
544
+ token: z2.string(),
545
+ logprob: z2.number()
546
+ })
547
+ )
548
+ })
499
549
  ).nullish()
500
550
  }).nullish(),
501
551
  finish_reason: z2.string().nullish(),
@@ -932,7 +982,7 @@ var OpenAIChatLanguageModel = class {
932
982
  };
933
983
  }
934
984
  async doGenerate(options) {
935
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
985
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
936
986
  const { args: body, warnings } = await this.getArgs(options);
937
987
  const {
938
988
  responseHeaders,
@@ -964,6 +1014,11 @@ var OpenAIChatLanguageModel = class {
964
1014
  if (text != null && text.length > 0) {
965
1015
  content.push({ type: "text", text });
966
1016
  }
1017
+ const refusal = choice.message.refusal;
1018
+ const hasRefusal = refusal != null && refusal.length > 0;
1019
+ if (hasRefusal) {
1020
+ content.push({ type: "text", text: refusal });
1021
+ }
967
1022
  for (const toolCall of (_b = choice.message.tool_calls) != null ? _b : []) {
968
1023
  content.push({
969
1024
  type: "tool-call",
@@ -995,18 +1050,26 @@ var OpenAIChatLanguageModel = class {
995
1050
  cacheWriteTokens: promptTokenDetails.cache_write_tokens
996
1051
  };
997
1052
  }
998
- if (((_g = choice.logprobs) == null ? void 0 : _g.content) != null) {
999
- providerMetadata.openai.logprobs = choice.logprobs.content;
1053
+ const contentLogprobs = (_g = choice.logprobs) == null ? void 0 : _g.content;
1054
+ const refusalLogprobs = (_h = choice.logprobs) == null ? void 0 : _h.refusal;
1055
+ if (contentLogprobs != null || refusalLogprobs != null) {
1056
+ providerMetadata.openai.logprobs = [
1057
+ ...contentLogprobs != null ? contentLogprobs : [],
1058
+ ...refusalLogprobs != null ? refusalLogprobs : []
1059
+ ];
1000
1060
  }
1001
1061
  return {
1002
1062
  content,
1003
- finishReason: mapOpenAIFinishReason(choice.finish_reason),
1063
+ finishReason: mapOpenAIFinishReason({
1064
+ finishReason: choice.finish_reason,
1065
+ hasRefusal
1066
+ }),
1004
1067
  usage: {
1005
- inputTokens: (_i = (_h = response.usage) == null ? void 0 : _h.prompt_tokens) != null ? _i : void 0,
1006
- outputTokens: (_k = (_j = response.usage) == null ? void 0 : _j.completion_tokens) != null ? _k : void 0,
1007
- totalTokens: (_m = (_l = response.usage) == null ? void 0 : _l.total_tokens) != null ? _m : void 0,
1008
- reasoningTokens: (_n = completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens) != null ? _n : void 0,
1009
- cachedInputTokens: (_o = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens) != null ? _o : void 0
1068
+ inputTokens: (_j = (_i = response.usage) == null ? void 0 : _i.prompt_tokens) != null ? _j : void 0,
1069
+ outputTokens: (_l = (_k = response.usage) == null ? void 0 : _k.completion_tokens) != null ? _l : void 0,
1070
+ totalTokens: (_n = (_m = response.usage) == null ? void 0 : _m.total_tokens) != null ? _n : void 0,
1071
+ reasoningTokens: (_o = completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens) != null ? _o : void 0,
1072
+ cachedInputTokens: (_p = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens) != null ? _p : void 0
1010
1073
  },
1011
1074
  request: { body },
1012
1075
  response: {
@@ -1050,6 +1113,10 @@ var OpenAIChatLanguageModel = class {
1050
1113
  };
1051
1114
  let metadataExtracted = false;
1052
1115
  let isActiveText = false;
1116
+ let hasRefusal = false;
1117
+ let rawFinishReason = void 0;
1118
+ let hasLogprobs = false;
1119
+ const streamedLogprobs = [];
1053
1120
  const providerMetadata = { openai: {} };
1054
1121
  return {
1055
1122
  stream: response.pipeThrough(
@@ -1062,18 +1129,20 @@ var OpenAIChatLanguageModel = class {
1062
1129
  controller.enqueue({ type: "stream-start", warnings });
1063
1130
  },
1064
1131
  transform(chunk, controller) {
1065
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1132
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1066
1133
  if (options.includeRawChunks) {
1067
1134
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1068
1135
  }
1069
1136
  if (!chunk.success) {
1070
1137
  finishReason = "error";
1138
+ rawFinishReason = void 0;
1071
1139
  controller.enqueue({ type: "error", error: chunk.error });
1072
1140
  return;
1073
1141
  }
1074
1142
  const value = chunk.value;
1075
1143
  if ("error" in value) {
1076
1144
  finishReason = "error";
1145
+ rawFinishReason = void 0;
1077
1146
  controller.enqueue({ type: "error", error: value.error });
1078
1147
  return;
1079
1148
  }
@@ -1107,16 +1176,35 @@ var OpenAIChatLanguageModel = class {
1107
1176
  }
1108
1177
  const choice = value.choices[0];
1109
1178
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
1110
- finishReason = mapOpenAIFinishReason(choice.finish_reason);
1179
+ rawFinishReason = choice.finish_reason;
1111
1180
  }
1112
- if (((_m = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _m.content) != null) {
1113
- providerMetadata.openai.logprobs = choice.logprobs.content;
1181
+ if ((choice == null ? void 0 : choice.logprobs) != null) {
1182
+ const contentLogprobs = choice.logprobs.content;
1183
+ const refusalLogprobs = choice.logprobs.refusal;
1184
+ if (contentLogprobs != null || refusalLogprobs != null) {
1185
+ hasLogprobs = true;
1186
+ streamedLogprobs.push(
1187
+ ...contentLogprobs != null ? contentLogprobs : [],
1188
+ ...refusalLogprobs != null ? refusalLogprobs : []
1189
+ );
1190
+ }
1114
1191
  }
1115
1192
  if ((choice == null ? void 0 : choice.delta) == null) {
1116
1193
  return;
1117
1194
  }
1118
1195
  const delta = choice.delta;
1119
- if (delta.content != null) {
1196
+ const textDeltas = [];
1197
+ if (delta.content != null && delta.content.length > 0) {
1198
+ textDeltas.push(delta.content);
1199
+ }
1200
+ if (delta.refusal != null && delta.refusal.length > 0) {
1201
+ hasRefusal = true;
1202
+ textDeltas.push(delta.refusal);
1203
+ }
1204
+ if (textDeltas.length === 0 && delta.content === "") {
1205
+ textDeltas.push(delta.content);
1206
+ }
1207
+ for (const textDelta of textDeltas) {
1120
1208
  if (!isActiveText) {
1121
1209
  controller.enqueue({ type: "text-start", id: "0" });
1122
1210
  isActiveText = true;
@@ -1124,7 +1212,7 @@ var OpenAIChatLanguageModel = class {
1124
1212
  controller.enqueue({
1125
1213
  type: "text-delta",
1126
1214
  id: "0",
1127
- delta: delta.content
1215
+ delta: textDelta
1128
1216
  });
1129
1217
  }
1130
1218
  if (delta.tool_calls != null) {
@@ -1149,6 +1237,15 @@ var OpenAIChatLanguageModel = class {
1149
1237
  controller.enqueue({ type: "text-end", id: "0" });
1150
1238
  }
1151
1239
  toolCallTracker.flush();
1240
+ if (rawFinishReason != null) {
1241
+ finishReason = mapOpenAIFinishReason({
1242
+ finishReason: rawFinishReason,
1243
+ hasRefusal
1244
+ });
1245
+ }
1246
+ if (hasLogprobs) {
1247
+ providerMetadata.openai.logprobs = streamedLogprobs;
1248
+ }
1152
1249
  controller.enqueue({
1153
1250
  type: "finish",
1154
1251
  finishReason,
@@ -2355,6 +2452,8 @@ import {
2355
2452
  UnsupportedFunctionalityError as UnsupportedFunctionalityError4
2356
2453
  } from "@ai-sdk/provider";
2357
2454
  import {
2455
+ stringifyWithBigIntAndCycles as stringifyWithBigIntAndCycles2,
2456
+ secureJsonParse as secureJsonParse2,
2358
2457
  lazySchema as lazySchema8,
2359
2458
  zodSchema as zodSchema17,
2360
2459
  convertToBase64 as convertToBase642,
@@ -2845,7 +2944,7 @@ async function convertToOpenAIResponsesInput({
2845
2944
  type: "function_call",
2846
2945
  call_id: part.toolCallId,
2847
2946
  name: part.toolName,
2848
- arguments: JSON.stringify(part.input),
2947
+ arguments: serializeToolCallArguments2(part.input),
2849
2948
  ...isAsync != null && { async: isAsync },
2850
2949
  id: canUseItemId ? id : void 0
2851
2950
  });
@@ -2907,7 +3006,7 @@ async function convertToOpenAIResponsesInput({
2907
3006
  } else if (reasoningMessage !== void 0) {
2908
3007
  warnings.push({
2909
3008
  type: "other",
2910
- message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${JSON.stringify(part)}.`
3009
+ message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${stringifyWithBigIntAndCycles2(part)}.`
2911
3010
  });
2912
3011
  }
2913
3012
  if (reasoningMessage === void 0) {
@@ -2928,7 +3027,7 @@ async function convertToOpenAIResponsesInput({
2928
3027
  } else {
2929
3028
  warnings.push({
2930
3029
  type: "other",
2931
- message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
3030
+ message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${stringifyWithBigIntAndCycles2(part)}.`
2932
3031
  });
2933
3032
  }
2934
3033
  break;
@@ -2969,10 +3068,10 @@ async function convertToOpenAIResponsesInput({
2969
3068
  break;
2970
3069
  case "json":
2971
3070
  case "error-json":
2972
- contentValue = promptCacheBreakpoint == null ? JSON.stringify(output.value) : [
3071
+ contentValue = promptCacheBreakpoint == null ? stringifyWithBigIntAndCycles2(output.value) : [
2973
3072
  {
2974
3073
  type: "input_text",
2975
- text: JSON.stringify(output.value),
3074
+ text: stringifyWithBigIntAndCycles2(output.value),
2976
3075
  prompt_cache_breakpoint: promptCacheBreakpoint
2977
3076
  }
2978
3077
  ];
@@ -3045,16 +3144,29 @@ var openaiResponsesReasoningProviderOptionsSchema = lazySchema8(
3045
3144
  })
3046
3145
  )
3047
3146
  );
3147
+ function serializeToolCallArguments2(input) {
3148
+ if (typeof input === "string") {
3149
+ try {
3150
+ secureJsonParse2(input);
3151
+ return input;
3152
+ } catch (e) {
3153
+ return stringifyWithBigIntAndCycles2(input);
3154
+ }
3155
+ }
3156
+ return stringifyWithBigIntAndCycles2(input === void 0 ? {} : input);
3157
+ }
3048
3158
 
3049
3159
  // src/responses/map-openai-responses-finish-reason.ts
3050
3160
  function mapOpenAIResponseFinishReason({
3051
3161
  finishReason,
3052
- hasFunctionCall
3162
+ hasFunctionCall,
3163
+ hasRefusal = false
3053
3164
  }) {
3054
3165
  switch (finishReason) {
3055
3166
  case void 0:
3056
3167
  case null:
3057
- return hasFunctionCall ? "tool-calls" : "stop";
3168
+ if (hasFunctionCall) return "tool-calls";
3169
+ return hasRefusal ? "content-filter" : "stop";
3058
3170
  case "max_output_tokens":
3059
3171
  return "length";
3060
3172
  case "content_filter":
@@ -3090,6 +3202,20 @@ var openaiResponsesChunkSchema = lazyValidator10(
3090
3202
  })
3091
3203
  ).nullish()
3092
3204
  }),
3205
+ z18.object({
3206
+ type: z18.literal("response.refusal.delta"),
3207
+ item_id: z18.string(),
3208
+ output_index: z18.number().nullish(),
3209
+ content_index: z18.number().nullish(),
3210
+ delta: z18.string()
3211
+ }),
3212
+ z18.object({
3213
+ type: z18.literal("response.refusal.done"),
3214
+ item_id: z18.string(),
3215
+ output_index: z18.number().nullish(),
3216
+ content_index: z18.number().nullish(),
3217
+ refusal: z18.string()
3218
+ }),
3093
3219
  z18.object({
3094
3220
  type: z18.enum(["response.completed", "response.incomplete"]),
3095
3221
  response: z18.object({
@@ -3376,57 +3502,64 @@ var openaiResponsesResponseSchema = lazyValidator10(
3376
3502
  role: z18.literal("assistant"),
3377
3503
  id: z18.string(),
3378
3504
  phase: z18.enum(["commentary", "final_answer"]).nullish(),
3505
+ // the API returns either text or a refusal as content parts:
3379
3506
  content: z18.array(
3380
- z18.object({
3381
- type: z18.literal("output_text"),
3382
- text: z18.string(),
3383
- logprobs: z18.array(
3384
- z18.object({
3385
- token: z18.string(),
3386
- logprob: z18.number(),
3387
- top_logprobs: z18.array(
3388
- z18.object({
3389
- token: z18.string(),
3390
- logprob: z18.number()
3391
- })
3392
- )
3393
- })
3394
- ).nullish(),
3395
- annotations: z18.array(
3396
- z18.discriminatedUnion("type", [
3397
- z18.object({
3398
- type: z18.literal("url_citation"),
3399
- start_index: z18.number(),
3400
- end_index: z18.number(),
3401
- url: z18.string(),
3402
- title: z18.string()
3403
- }),
3404
- z18.object({
3405
- type: z18.literal("file_citation"),
3406
- file_id: z18.string(),
3407
- filename: z18.string().nullish(),
3408
- index: z18.number().nullish(),
3409
- start_index: z18.number().nullish(),
3410
- end_index: z18.number().nullish(),
3411
- quote: z18.string().nullish()
3412
- }),
3413
- z18.object({
3414
- type: z18.literal("container_file_citation"),
3415
- container_id: z18.string(),
3416
- file_id: z18.string(),
3417
- filename: z18.string().nullish(),
3418
- start_index: z18.number().nullish(),
3419
- end_index: z18.number().nullish(),
3420
- index: z18.number().nullish()
3421
- }),
3507
+ z18.discriminatedUnion("type", [
3508
+ z18.object({
3509
+ type: z18.literal("output_text"),
3510
+ text: z18.string(),
3511
+ logprobs: z18.array(
3422
3512
  z18.object({
3423
- type: z18.literal("file_path"),
3424
- file_id: z18.string(),
3425
- index: z18.number().nullish()
3513
+ token: z18.string(),
3514
+ logprob: z18.number(),
3515
+ top_logprobs: z18.array(
3516
+ z18.object({
3517
+ token: z18.string(),
3518
+ logprob: z18.number()
3519
+ })
3520
+ )
3426
3521
  })
3427
- ])
3428
- )
3429
- })
3522
+ ).nullish(),
3523
+ annotations: z18.array(
3524
+ z18.discriminatedUnion("type", [
3525
+ z18.object({
3526
+ type: z18.literal("url_citation"),
3527
+ start_index: z18.number(),
3528
+ end_index: z18.number(),
3529
+ url: z18.string(),
3530
+ title: z18.string()
3531
+ }),
3532
+ z18.object({
3533
+ type: z18.literal("file_citation"),
3534
+ file_id: z18.string(),
3535
+ filename: z18.string().nullish(),
3536
+ index: z18.number().nullish(),
3537
+ start_index: z18.number().nullish(),
3538
+ end_index: z18.number().nullish(),
3539
+ quote: z18.string().nullish()
3540
+ }),
3541
+ z18.object({
3542
+ type: z18.literal("container_file_citation"),
3543
+ container_id: z18.string(),
3544
+ file_id: z18.string(),
3545
+ filename: z18.string().nullish(),
3546
+ start_index: z18.number().nullish(),
3547
+ end_index: z18.number().nullish(),
3548
+ index: z18.number().nullish()
3549
+ }),
3550
+ z18.object({
3551
+ type: z18.literal("file_path"),
3552
+ file_id: z18.string(),
3553
+ index: z18.number().nullish()
3554
+ })
3555
+ ])
3556
+ )
3557
+ }),
3558
+ z18.object({
3559
+ type: z18.literal("refusal"),
3560
+ refusal: z18.string()
3561
+ })
3562
+ ])
3430
3563
  )
3431
3564
  }),
3432
3565
  z18.object({
@@ -4090,6 +4223,7 @@ var OpenAIResponsesLanguageModel = class {
4090
4223
  const content = [];
4091
4224
  const logprobs = [];
4092
4225
  let hasFunctionCall = false;
4226
+ let hasRefusal = false;
4093
4227
  for (const part of response.output) {
4094
4228
  switch (part.type) {
4095
4229
  case "reasoning": {
@@ -4147,6 +4281,20 @@ var OpenAIResponsesLanguageModel = class {
4147
4281
  }
4148
4282
  case "message": {
4149
4283
  for (const contentPart of part.content) {
4284
+ if (contentPart.type === "refusal") {
4285
+ hasRefusal = true;
4286
+ content.push({
4287
+ type: "text",
4288
+ text: contentPart.refusal,
4289
+ providerMetadata: {
4290
+ [providerKey]: {
4291
+ itemId: part.id,
4292
+ ...part.phase != null && { phase: part.phase }
4293
+ }
4294
+ }
4295
+ });
4296
+ continue;
4297
+ }
4150
4298
  if (((_c = (_b = options.providerOptions) == null ? void 0 : _b.openai) == null ? void 0 : _c.logprobs) && contentPart.logprobs) {
4151
4299
  logprobs.push(contentPart.logprobs);
4152
4300
  }
@@ -4347,7 +4495,8 @@ var OpenAIResponsesLanguageModel = class {
4347
4495
  content,
4348
4496
  finishReason: mapOpenAIResponseFinishReason({
4349
4497
  finishReason: (_y = response.incomplete_details) == null ? void 0 : _y.reason,
4350
- hasFunctionCall
4498
+ hasFunctionCall,
4499
+ hasRefusal
4351
4500
  }),
4352
4501
  usage: {
4353
4502
  inputTokens: usage.input_tokens,
@@ -4406,6 +4555,7 @@ var OpenAIResponsesLanguageModel = class {
4406
4555
  const ongoingAnnotations = [];
4407
4556
  let activeMessagePhase;
4408
4557
  let hasFunctionCall = false;
4558
+ let hasRefusal = false;
4409
4559
  const activeReasoning = {};
4410
4560
  let serviceTier;
4411
4561
  let reasoningContext;
@@ -4747,6 +4897,15 @@ var OpenAIResponsesLanguageModel = class {
4747
4897
  if (((_h = (_g = options.providerOptions) == null ? void 0 : _g.openai) == null ? void 0 : _h.logprobs) && value.logprobs) {
4748
4898
  logprobs.push(value.logprobs);
4749
4899
  }
4900
+ } else if (isRefusalDeltaChunk(value)) {
4901
+ hasRefusal = true;
4902
+ controller.enqueue({
4903
+ type: "text-delta",
4904
+ id: value.item_id,
4905
+ delta: value.delta
4906
+ });
4907
+ } else if (isRefusalDoneChunk(value)) {
4908
+ hasRefusal = true;
4750
4909
  } else if (value.type === "response.reasoning_summary_part.added") {
4751
4910
  if (value.summary_index > 0) {
4752
4911
  const activeReasoningPart = activeReasoning[value.item_id];
@@ -4803,7 +4962,8 @@ var OpenAIResponsesLanguageModel = class {
4803
4962
  } else if (isResponseFinishedChunk(value)) {
4804
4963
  finishReason = mapOpenAIResponseFinishReason({
4805
4964
  finishReason: (_k = value.response.incomplete_details) == null ? void 0 : _k.reason,
4806
- hasFunctionCall
4965
+ hasFunctionCall,
4966
+ hasRefusal
4807
4967
  });
4808
4968
  usage.inputTokens = value.response.usage.input_tokens;
4809
4969
  usage.outputTokens = value.response.usage.output_tokens;
@@ -4880,6 +5040,12 @@ var OpenAIResponsesLanguageModel = class {
4880
5040
  };
4881
5041
  }
4882
5042
  };
5043
+ function isRefusalDeltaChunk(chunk) {
5044
+ return chunk.type === "response.refusal.delta";
5045
+ }
5046
+ function isRefusalDoneChunk(chunk) {
5047
+ return chunk.type === "response.refusal.done";
5048
+ }
4883
5049
  function isTextDeltaChunk(chunk) {
4884
5050
  return chunk.type === "response.output_text.delta";
4885
5051
  }
@@ -5149,6 +5315,16 @@ var openAITranscriptionProviderOptions = lazyValidator13(
5149
5315
  * The language of the input audio in ISO-639-1 format.
5150
5316
  */
5151
5317
  language: z21.string().optional(),
5318
+ /**
5319
+ * Expected languages for REST transcription, e.g. with gpt-transcribe.
5320
+ * Use this instead of language. The API validates model support.
5321
+ */
5322
+ languages: z21.array(z21.string()).optional(),
5323
+ /**
5324
+ * Vocabulary hints for REST transcription, e.g. names or technical terms.
5325
+ * The API validates model support.
5326
+ */
5327
+ keywords: z21.array(z21.string()).optional(),
5152
5328
  /**
5153
5329
  * An optional text to guide the model's style or continue a previous audio segment.
5154
5330
  */
@@ -5260,6 +5436,8 @@ var OpenAITranscriptionModel = class {
5260
5436
  const transcriptionModelOptions = {
5261
5437
  include: openAIOptions.include,
5262
5438
  language: openAIOptions.language,
5439
+ languages: openAIOptions.languages,
5440
+ keywords: openAIOptions.keywords,
5263
5441
  prompt: openAIOptions.prompt,
5264
5442
  // https://platform.openai.com/docs/api-reference/audio/createTranscription#audio_createtranscription-response_format
5265
5443
  // prefer verbose_json to get segments for models that support it
@@ -5336,7 +5514,7 @@ var OpenAITranscriptionModel = class {
5336
5514
  };
5337
5515
 
5338
5516
  // src/version.ts
5339
- var VERSION = true ? "2.0.139" : "0.0.0-test";
5517
+ var VERSION = true ? "2.0.141" : "0.0.0-test";
5340
5518
 
5341
5519
  // src/openai-provider.ts
5342
5520
  function createOpenAI(options = {}) {