@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.
@@ -168,6 +168,8 @@ type OpenAITranscriptionModelId = 'whisper-1' | 'gpt-4o-mini-transcribe' | 'gpt-
168
168
  declare const openAITranscriptionProviderOptions: _ai_sdk_provider_utils.LazyValidator<{
169
169
  include?: string[] | undefined;
170
170
  language?: string | undefined;
171
+ languages?: string[] | undefined;
172
+ keywords?: string[] | undefined;
171
173
  prompt?: string | undefined;
172
174
  temperature?: number | undefined;
173
175
  timestampGranularities?: ("word" | "segment")[] | undefined;
@@ -168,6 +168,8 @@ type OpenAITranscriptionModelId = 'whisper-1' | 'gpt-4o-mini-transcribe' | 'gpt-
168
168
  declare const openAITranscriptionProviderOptions: _ai_sdk_provider_utils.LazyValidator<{
169
169
  include?: string[] | undefined;
170
170
  language?: string | undefined;
171
+ languages?: string[] | undefined;
172
+ keywords?: string[] | undefined;
171
173
  prompt?: string | undefined;
172
174
  temperature?: number | undefined;
173
175
  timestampGranularities?: ("word" | "segment")[] | undefined;
@@ -129,7 +129,18 @@ function getGptVersion(modelId) {
129
129
  var import_provider = require("@ai-sdk/provider");
130
130
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
131
131
  function serializeToolCallArguments(input) {
132
- return JSON.stringify(
132
+ if (typeof input === "string") {
133
+ try {
134
+ const parsed = (0, import_provider_utils2.secureJsonParse)(input);
135
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
136
+ return "{}";
137
+ }
138
+ return input;
139
+ } catch (e) {
140
+ return "{}";
141
+ }
142
+ }
143
+ return (0, import_provider_utils2.stringifyWithBigIntAndCycles)(
133
144
  typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
134
145
  );
135
146
  }
@@ -352,7 +363,7 @@ function convertToOpenAIChatMessages({
352
363
  case "content":
353
364
  case "json":
354
365
  case "error-json":
355
- contentValue = JSON.stringify(output.value);
366
+ contentValue = (0, import_provider_utils2.stringifyWithBigIntAndCycles)(output.value);
356
367
  break;
357
368
  }
358
369
  messages.push({
@@ -392,10 +403,13 @@ function getResponseMetadata({
392
403
  }
393
404
 
394
405
  // src/chat/map-openai-finish-reason.ts
395
- function mapOpenAIFinishReason(finishReason) {
406
+ function mapOpenAIFinishReason({
407
+ finishReason,
408
+ hasRefusal = false
409
+ }) {
396
410
  switch (finishReason) {
397
411
  case "stop":
398
- return "stop";
412
+ return hasRefusal ? "content-filter" : "stop";
399
413
  case "length":
400
414
  return "length";
401
415
  case "content_filter":
@@ -422,6 +436,8 @@ var openaiChatResponseSchema = (0, import_provider_utils3.lazyValidator)(
422
436
  message: import_v42.z.object({
423
437
  role: import_v42.z.literal("assistant").nullish(),
424
438
  content: import_v42.z.string().nullish(),
439
+ // set instead of `content` when the model refuses to answer:
440
+ refusal: import_v42.z.string().nullish(),
425
441
  audio: import_v42.z.object({
426
442
  transcript: import_v42.z.string().nullish()
427
443
  }).nullish(),
@@ -460,6 +476,20 @@ var openaiChatResponseSchema = (0, import_provider_utils3.lazyValidator)(
460
476
  })
461
477
  )
462
478
  })
479
+ ).nullish(),
480
+ // logprobs of the refusal tokens (set instead of `content` when
481
+ // the model refuses to answer):
482
+ refusal: import_v42.z.array(
483
+ import_v42.z.object({
484
+ token: import_v42.z.string(),
485
+ logprob: import_v42.z.number(),
486
+ top_logprobs: import_v42.z.array(
487
+ import_v42.z.object({
488
+ token: import_v42.z.string(),
489
+ logprob: import_v42.z.number()
490
+ })
491
+ )
492
+ })
463
493
  ).nullish()
464
494
  }).nullish(),
465
495
  finish_reason: import_v42.z.string().nullish()
@@ -494,6 +524,8 @@ var openaiChatChunkSchema = (0, import_provider_utils3.lazyValidator)(
494
524
  delta: import_v42.z.object({
495
525
  role: import_v42.z.enum(["assistant"]).nullish(),
496
526
  content: import_v42.z.string().nullish(),
527
+ // set instead of `content` when the model refuses to answer:
528
+ refusal: import_v42.z.string().nullish(),
497
529
  tool_calls: import_v42.z.array(
498
530
  import_v42.z.object({
499
531
  index: import_v42.z.number(),
@@ -529,6 +561,20 @@ var openaiChatChunkSchema = (0, import_provider_utils3.lazyValidator)(
529
561
  })
530
562
  )
531
563
  })
564
+ ).nullish(),
565
+ // logprobs of the refusal tokens (set instead of `content` when
566
+ // the model refuses to answer):
567
+ refusal: import_v42.z.array(
568
+ import_v42.z.object({
569
+ token: import_v42.z.string(),
570
+ logprob: import_v42.z.number(),
571
+ top_logprobs: import_v42.z.array(
572
+ import_v42.z.object({
573
+ token: import_v42.z.string(),
574
+ logprob: import_v42.z.number()
575
+ })
576
+ )
577
+ })
532
578
  ).nullish()
533
579
  }).nullish(),
534
580
  finish_reason: import_v42.z.string().nullish(),
@@ -960,7 +1006,7 @@ var OpenAIChatLanguageModel = class {
960
1006
  };
961
1007
  }
962
1008
  async doGenerate(options) {
963
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1009
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
964
1010
  const { args: body, warnings } = await this.getArgs(options);
965
1011
  const {
966
1012
  responseHeaders,
@@ -992,6 +1038,11 @@ var OpenAIChatLanguageModel = class {
992
1038
  if (text != null && text.length > 0) {
993
1039
  content.push({ type: "text", text });
994
1040
  }
1041
+ const refusal = choice.message.refusal;
1042
+ const hasRefusal = refusal != null && refusal.length > 0;
1043
+ if (hasRefusal) {
1044
+ content.push({ type: "text", text: refusal });
1045
+ }
995
1046
  for (const toolCall of (_b = choice.message.tool_calls) != null ? _b : []) {
996
1047
  content.push({
997
1048
  type: "tool-call",
@@ -1023,18 +1074,26 @@ var OpenAIChatLanguageModel = class {
1023
1074
  cacheWriteTokens: promptTokenDetails.cache_write_tokens
1024
1075
  };
1025
1076
  }
1026
- if (((_g = choice.logprobs) == null ? void 0 : _g.content) != null) {
1027
- providerMetadata.openai.logprobs = choice.logprobs.content;
1077
+ const contentLogprobs = (_g = choice.logprobs) == null ? void 0 : _g.content;
1078
+ const refusalLogprobs = (_h = choice.logprobs) == null ? void 0 : _h.refusal;
1079
+ if (contentLogprobs != null || refusalLogprobs != null) {
1080
+ providerMetadata.openai.logprobs = [
1081
+ ...contentLogprobs != null ? contentLogprobs : [],
1082
+ ...refusalLogprobs != null ? refusalLogprobs : []
1083
+ ];
1028
1084
  }
1029
1085
  return {
1030
1086
  content,
1031
- finishReason: mapOpenAIFinishReason(choice.finish_reason),
1087
+ finishReason: mapOpenAIFinishReason({
1088
+ finishReason: choice.finish_reason,
1089
+ hasRefusal
1090
+ }),
1032
1091
  usage: {
1033
- inputTokens: (_i = (_h = response.usage) == null ? void 0 : _h.prompt_tokens) != null ? _i : void 0,
1034
- outputTokens: (_k = (_j = response.usage) == null ? void 0 : _j.completion_tokens) != null ? _k : void 0,
1035
- totalTokens: (_m = (_l = response.usage) == null ? void 0 : _l.total_tokens) != null ? _m : void 0,
1036
- reasoningTokens: (_n = completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens) != null ? _n : void 0,
1037
- cachedInputTokens: (_o = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens) != null ? _o : void 0
1092
+ inputTokens: (_j = (_i = response.usage) == null ? void 0 : _i.prompt_tokens) != null ? _j : void 0,
1093
+ outputTokens: (_l = (_k = response.usage) == null ? void 0 : _k.completion_tokens) != null ? _l : void 0,
1094
+ totalTokens: (_n = (_m = response.usage) == null ? void 0 : _m.total_tokens) != null ? _n : void 0,
1095
+ reasoningTokens: (_o = completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens) != null ? _o : void 0,
1096
+ cachedInputTokens: (_p = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens) != null ? _p : void 0
1038
1097
  },
1039
1098
  request: { body },
1040
1099
  response: {
@@ -1078,6 +1137,10 @@ var OpenAIChatLanguageModel = class {
1078
1137
  };
1079
1138
  let metadataExtracted = false;
1080
1139
  let isActiveText = false;
1140
+ let hasRefusal = false;
1141
+ let rawFinishReason = void 0;
1142
+ let hasLogprobs = false;
1143
+ const streamedLogprobs = [];
1081
1144
  const providerMetadata = { openai: {} };
1082
1145
  return {
1083
1146
  stream: response.pipeThrough(
@@ -1090,18 +1153,20 @@ var OpenAIChatLanguageModel = class {
1090
1153
  controller.enqueue({ type: "stream-start", warnings });
1091
1154
  },
1092
1155
  transform(chunk, controller) {
1093
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1156
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1094
1157
  if (options.includeRawChunks) {
1095
1158
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1096
1159
  }
1097
1160
  if (!chunk.success) {
1098
1161
  finishReason = "error";
1162
+ rawFinishReason = void 0;
1099
1163
  controller.enqueue({ type: "error", error: chunk.error });
1100
1164
  return;
1101
1165
  }
1102
1166
  const value = chunk.value;
1103
1167
  if ("error" in value) {
1104
1168
  finishReason = "error";
1169
+ rawFinishReason = void 0;
1105
1170
  controller.enqueue({ type: "error", error: value.error });
1106
1171
  return;
1107
1172
  }
@@ -1135,16 +1200,35 @@ var OpenAIChatLanguageModel = class {
1135
1200
  }
1136
1201
  const choice = value.choices[0];
1137
1202
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
1138
- finishReason = mapOpenAIFinishReason(choice.finish_reason);
1203
+ rawFinishReason = choice.finish_reason;
1139
1204
  }
1140
- if (((_m = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _m.content) != null) {
1141
- providerMetadata.openai.logprobs = choice.logprobs.content;
1205
+ if ((choice == null ? void 0 : choice.logprobs) != null) {
1206
+ const contentLogprobs = choice.logprobs.content;
1207
+ const refusalLogprobs = choice.logprobs.refusal;
1208
+ if (contentLogprobs != null || refusalLogprobs != null) {
1209
+ hasLogprobs = true;
1210
+ streamedLogprobs.push(
1211
+ ...contentLogprobs != null ? contentLogprobs : [],
1212
+ ...refusalLogprobs != null ? refusalLogprobs : []
1213
+ );
1214
+ }
1142
1215
  }
1143
1216
  if ((choice == null ? void 0 : choice.delta) == null) {
1144
1217
  return;
1145
1218
  }
1146
1219
  const delta = choice.delta;
1147
- if (delta.content != null) {
1220
+ const textDeltas = [];
1221
+ if (delta.content != null && delta.content.length > 0) {
1222
+ textDeltas.push(delta.content);
1223
+ }
1224
+ if (delta.refusal != null && delta.refusal.length > 0) {
1225
+ hasRefusal = true;
1226
+ textDeltas.push(delta.refusal);
1227
+ }
1228
+ if (textDeltas.length === 0 && delta.content === "") {
1229
+ textDeltas.push(delta.content);
1230
+ }
1231
+ for (const textDelta of textDeltas) {
1148
1232
  if (!isActiveText) {
1149
1233
  controller.enqueue({ type: "text-start", id: "0" });
1150
1234
  isActiveText = true;
@@ -1152,7 +1236,7 @@ var OpenAIChatLanguageModel = class {
1152
1236
  controller.enqueue({
1153
1237
  type: "text-delta",
1154
1238
  id: "0",
1155
- delta: delta.content
1239
+ delta: textDelta
1156
1240
  });
1157
1241
  }
1158
1242
  if (delta.tool_calls != null) {
@@ -1177,6 +1261,15 @@ var OpenAIChatLanguageModel = class {
1177
1261
  controller.enqueue({ type: "text-end", id: "0" });
1178
1262
  }
1179
1263
  toolCallTracker.flush();
1264
+ if (rawFinishReason != null) {
1265
+ finishReason = mapOpenAIFinishReason({
1266
+ finishReason: rawFinishReason,
1267
+ hasRefusal
1268
+ });
1269
+ }
1270
+ if (hasLogprobs) {
1271
+ providerMetadata.openai.logprobs = streamedLogprobs;
1272
+ }
1180
1273
  controller.enqueue({
1181
1274
  type: "finish",
1182
1275
  finishReason,
@@ -2024,6 +2117,16 @@ var openAITranscriptionProviderOptions = (0, import_provider_utils16.lazyValidat
2024
2117
  * The language of the input audio in ISO-639-1 format.
2025
2118
  */
2026
2119
  language: import_v411.z.string().optional(),
2120
+ /**
2121
+ * Expected languages for REST transcription, e.g. with gpt-transcribe.
2122
+ * Use this instead of language. The API validates model support.
2123
+ */
2124
+ languages: import_v411.z.array(import_v411.z.string()).optional(),
2125
+ /**
2126
+ * Vocabulary hints for REST transcription, e.g. names or technical terms.
2127
+ * The API validates model support.
2128
+ */
2129
+ keywords: import_v411.z.array(import_v411.z.string()).optional(),
2027
2130
  /**
2028
2131
  * An optional text to guide the model's style or continue a previous audio segment.
2029
2132
  */
@@ -2135,6 +2238,8 @@ var OpenAITranscriptionModel = class {
2135
2238
  const transcriptionModelOptions = {
2136
2239
  include: openAIOptions.include,
2137
2240
  language: openAIOptions.language,
2241
+ languages: openAIOptions.languages,
2242
+ keywords: openAIOptions.keywords,
2138
2243
  prompt: openAIOptions.prompt,
2139
2244
  // https://platform.openai.com/docs/api-reference/audio/createTranscription#audio_createtranscription-response_format
2140
2245
  // prefer verbose_json to get segments for models that support it
@@ -2898,7 +3003,7 @@ async function convertToOpenAIResponsesInput({
2898
3003
  type: "function_call",
2899
3004
  call_id: part.toolCallId,
2900
3005
  name: part.toolName,
2901
- arguments: JSON.stringify(part.input),
3006
+ arguments: serializeToolCallArguments2(part.input),
2902
3007
  ...isAsync != null && { async: isAsync },
2903
3008
  id: canUseItemId ? id : void 0
2904
3009
  });
@@ -2960,7 +3065,7 @@ async function convertToOpenAIResponsesInput({
2960
3065
  } else if (reasoningMessage !== void 0) {
2961
3066
  warnings.push({
2962
3067
  type: "other",
2963
- message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${JSON.stringify(part)}.`
3068
+ message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${(0, import_provider_utils23.stringifyWithBigIntAndCycles)(part)}.`
2964
3069
  });
2965
3070
  }
2966
3071
  if (reasoningMessage === void 0) {
@@ -2981,7 +3086,7 @@ async function convertToOpenAIResponsesInput({
2981
3086
  } else {
2982
3087
  warnings.push({
2983
3088
  type: "other",
2984
- message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
3089
+ message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${(0, import_provider_utils23.stringifyWithBigIntAndCycles)(part)}.`
2985
3090
  });
2986
3091
  }
2987
3092
  break;
@@ -3022,10 +3127,10 @@ async function convertToOpenAIResponsesInput({
3022
3127
  break;
3023
3128
  case "json":
3024
3129
  case "error-json":
3025
- contentValue = promptCacheBreakpoint == null ? JSON.stringify(output.value) : [
3130
+ contentValue = promptCacheBreakpoint == null ? (0, import_provider_utils23.stringifyWithBigIntAndCycles)(output.value) : [
3026
3131
  {
3027
3132
  type: "input_text",
3028
- text: JSON.stringify(output.value),
3133
+ text: (0, import_provider_utils23.stringifyWithBigIntAndCycles)(output.value),
3029
3134
  prompt_cache_breakpoint: promptCacheBreakpoint
3030
3135
  }
3031
3136
  ];
@@ -3098,16 +3203,29 @@ var openaiResponsesReasoningProviderOptionsSchema = (0, import_provider_utils23.
3098
3203
  })
3099
3204
  )
3100
3205
  );
3206
+ function serializeToolCallArguments2(input) {
3207
+ if (typeof input === "string") {
3208
+ try {
3209
+ (0, import_provider_utils23.secureJsonParse)(input);
3210
+ return input;
3211
+ } catch (e) {
3212
+ return (0, import_provider_utils23.stringifyWithBigIntAndCycles)(input);
3213
+ }
3214
+ }
3215
+ return (0, import_provider_utils23.stringifyWithBigIntAndCycles)(input === void 0 ? {} : input);
3216
+ }
3101
3217
 
3102
3218
  // src/responses/map-openai-responses-finish-reason.ts
3103
3219
  function mapOpenAIResponseFinishReason({
3104
3220
  finishReason,
3105
- hasFunctionCall
3221
+ hasFunctionCall,
3222
+ hasRefusal = false
3106
3223
  }) {
3107
3224
  switch (finishReason) {
3108
3225
  case void 0:
3109
3226
  case null:
3110
- return hasFunctionCall ? "tool-calls" : "stop";
3227
+ if (hasFunctionCall) return "tool-calls";
3228
+ return hasRefusal ? "content-filter" : "stop";
3111
3229
  case "max_output_tokens":
3112
3230
  return "length";
3113
3231
  case "content_filter":
@@ -3140,6 +3258,20 @@ var openaiResponsesChunkSchema = (0, import_provider_utils24.lazyValidator)(
3140
3258
  })
3141
3259
  ).nullish()
3142
3260
  }),
3261
+ import_v417.z.object({
3262
+ type: import_v417.z.literal("response.refusal.delta"),
3263
+ item_id: import_v417.z.string(),
3264
+ output_index: import_v417.z.number().nullish(),
3265
+ content_index: import_v417.z.number().nullish(),
3266
+ delta: import_v417.z.string()
3267
+ }),
3268
+ import_v417.z.object({
3269
+ type: import_v417.z.literal("response.refusal.done"),
3270
+ item_id: import_v417.z.string(),
3271
+ output_index: import_v417.z.number().nullish(),
3272
+ content_index: import_v417.z.number().nullish(),
3273
+ refusal: import_v417.z.string()
3274
+ }),
3143
3275
  import_v417.z.object({
3144
3276
  type: import_v417.z.enum(["response.completed", "response.incomplete"]),
3145
3277
  response: import_v417.z.object({
@@ -3426,57 +3558,64 @@ var openaiResponsesResponseSchema = (0, import_provider_utils24.lazyValidator)(
3426
3558
  role: import_v417.z.literal("assistant"),
3427
3559
  id: import_v417.z.string(),
3428
3560
  phase: import_v417.z.enum(["commentary", "final_answer"]).nullish(),
3561
+ // the API returns either text or a refusal as content parts:
3429
3562
  content: import_v417.z.array(
3430
- import_v417.z.object({
3431
- type: import_v417.z.literal("output_text"),
3432
- text: import_v417.z.string(),
3433
- logprobs: import_v417.z.array(
3434
- import_v417.z.object({
3435
- token: import_v417.z.string(),
3436
- logprob: import_v417.z.number(),
3437
- top_logprobs: import_v417.z.array(
3438
- import_v417.z.object({
3439
- token: import_v417.z.string(),
3440
- logprob: import_v417.z.number()
3441
- })
3442
- )
3443
- })
3444
- ).nullish(),
3445
- annotations: import_v417.z.array(
3446
- import_v417.z.discriminatedUnion("type", [
3447
- import_v417.z.object({
3448
- type: import_v417.z.literal("url_citation"),
3449
- start_index: import_v417.z.number(),
3450
- end_index: import_v417.z.number(),
3451
- url: import_v417.z.string(),
3452
- title: import_v417.z.string()
3453
- }),
3454
- import_v417.z.object({
3455
- type: import_v417.z.literal("file_citation"),
3456
- file_id: import_v417.z.string(),
3457
- filename: import_v417.z.string().nullish(),
3458
- index: import_v417.z.number().nullish(),
3459
- start_index: import_v417.z.number().nullish(),
3460
- end_index: import_v417.z.number().nullish(),
3461
- quote: import_v417.z.string().nullish()
3462
- }),
3463
- import_v417.z.object({
3464
- type: import_v417.z.literal("container_file_citation"),
3465
- container_id: import_v417.z.string(),
3466
- file_id: import_v417.z.string(),
3467
- filename: import_v417.z.string().nullish(),
3468
- start_index: import_v417.z.number().nullish(),
3469
- end_index: import_v417.z.number().nullish(),
3470
- index: import_v417.z.number().nullish()
3471
- }),
3563
+ import_v417.z.discriminatedUnion("type", [
3564
+ import_v417.z.object({
3565
+ type: import_v417.z.literal("output_text"),
3566
+ text: import_v417.z.string(),
3567
+ logprobs: import_v417.z.array(
3472
3568
  import_v417.z.object({
3473
- type: import_v417.z.literal("file_path"),
3474
- file_id: import_v417.z.string(),
3475
- index: import_v417.z.number().nullish()
3569
+ token: import_v417.z.string(),
3570
+ logprob: import_v417.z.number(),
3571
+ top_logprobs: import_v417.z.array(
3572
+ import_v417.z.object({
3573
+ token: import_v417.z.string(),
3574
+ logprob: import_v417.z.number()
3575
+ })
3576
+ )
3476
3577
  })
3477
- ])
3478
- )
3479
- })
3578
+ ).nullish(),
3579
+ annotations: import_v417.z.array(
3580
+ import_v417.z.discriminatedUnion("type", [
3581
+ import_v417.z.object({
3582
+ type: import_v417.z.literal("url_citation"),
3583
+ start_index: import_v417.z.number(),
3584
+ end_index: import_v417.z.number(),
3585
+ url: import_v417.z.string(),
3586
+ title: import_v417.z.string()
3587
+ }),
3588
+ import_v417.z.object({
3589
+ type: import_v417.z.literal("file_citation"),
3590
+ file_id: import_v417.z.string(),
3591
+ filename: import_v417.z.string().nullish(),
3592
+ index: import_v417.z.number().nullish(),
3593
+ start_index: import_v417.z.number().nullish(),
3594
+ end_index: import_v417.z.number().nullish(),
3595
+ quote: import_v417.z.string().nullish()
3596
+ }),
3597
+ import_v417.z.object({
3598
+ type: import_v417.z.literal("container_file_citation"),
3599
+ container_id: import_v417.z.string(),
3600
+ file_id: import_v417.z.string(),
3601
+ filename: import_v417.z.string().nullish(),
3602
+ start_index: import_v417.z.number().nullish(),
3603
+ end_index: import_v417.z.number().nullish(),
3604
+ index: import_v417.z.number().nullish()
3605
+ }),
3606
+ import_v417.z.object({
3607
+ type: import_v417.z.literal("file_path"),
3608
+ file_id: import_v417.z.string(),
3609
+ index: import_v417.z.number().nullish()
3610
+ })
3611
+ ])
3612
+ )
3613
+ }),
3614
+ import_v417.z.object({
3615
+ type: import_v417.z.literal("refusal"),
3616
+ refusal: import_v417.z.string()
3617
+ })
3618
+ ])
3480
3619
  )
3481
3620
  }),
3482
3621
  import_v417.z.object({
@@ -4320,6 +4459,7 @@ var OpenAIResponsesLanguageModel = class {
4320
4459
  const content = [];
4321
4460
  const logprobs = [];
4322
4461
  let hasFunctionCall = false;
4462
+ let hasRefusal = false;
4323
4463
  for (const part of response.output) {
4324
4464
  switch (part.type) {
4325
4465
  case "reasoning": {
@@ -4377,6 +4517,20 @@ var OpenAIResponsesLanguageModel = class {
4377
4517
  }
4378
4518
  case "message": {
4379
4519
  for (const contentPart of part.content) {
4520
+ if (contentPart.type === "refusal") {
4521
+ hasRefusal = true;
4522
+ content.push({
4523
+ type: "text",
4524
+ text: contentPart.refusal,
4525
+ providerMetadata: {
4526
+ [providerKey]: {
4527
+ itemId: part.id,
4528
+ ...part.phase != null && { phase: part.phase }
4529
+ }
4530
+ }
4531
+ });
4532
+ continue;
4533
+ }
4380
4534
  if (((_c = (_b = options.providerOptions) == null ? void 0 : _b.openai) == null ? void 0 : _c.logprobs) && contentPart.logprobs) {
4381
4535
  logprobs.push(contentPart.logprobs);
4382
4536
  }
@@ -4577,7 +4731,8 @@ var OpenAIResponsesLanguageModel = class {
4577
4731
  content,
4578
4732
  finishReason: mapOpenAIResponseFinishReason({
4579
4733
  finishReason: (_y = response.incomplete_details) == null ? void 0 : _y.reason,
4580
- hasFunctionCall
4734
+ hasFunctionCall,
4735
+ hasRefusal
4581
4736
  }),
4582
4737
  usage: {
4583
4738
  inputTokens: usage.input_tokens,
@@ -4636,6 +4791,7 @@ var OpenAIResponsesLanguageModel = class {
4636
4791
  const ongoingAnnotations = [];
4637
4792
  let activeMessagePhase;
4638
4793
  let hasFunctionCall = false;
4794
+ let hasRefusal = false;
4639
4795
  const activeReasoning = {};
4640
4796
  let serviceTier;
4641
4797
  let reasoningContext;
@@ -4977,6 +5133,15 @@ var OpenAIResponsesLanguageModel = class {
4977
5133
  if (((_h = (_g = options.providerOptions) == null ? void 0 : _g.openai) == null ? void 0 : _h.logprobs) && value.logprobs) {
4978
5134
  logprobs.push(value.logprobs);
4979
5135
  }
5136
+ } else if (isRefusalDeltaChunk(value)) {
5137
+ hasRefusal = true;
5138
+ controller.enqueue({
5139
+ type: "text-delta",
5140
+ id: value.item_id,
5141
+ delta: value.delta
5142
+ });
5143
+ } else if (isRefusalDoneChunk(value)) {
5144
+ hasRefusal = true;
4980
5145
  } else if (value.type === "response.reasoning_summary_part.added") {
4981
5146
  if (value.summary_index > 0) {
4982
5147
  const activeReasoningPart = activeReasoning[value.item_id];
@@ -5033,7 +5198,8 @@ var OpenAIResponsesLanguageModel = class {
5033
5198
  } else if (isResponseFinishedChunk(value)) {
5034
5199
  finishReason = mapOpenAIResponseFinishReason({
5035
5200
  finishReason: (_k = value.response.incomplete_details) == null ? void 0 : _k.reason,
5036
- hasFunctionCall
5201
+ hasFunctionCall,
5202
+ hasRefusal
5037
5203
  });
5038
5204
  usage.inputTokens = value.response.usage.input_tokens;
5039
5205
  usage.outputTokens = value.response.usage.output_tokens;
@@ -5110,6 +5276,12 @@ var OpenAIResponsesLanguageModel = class {
5110
5276
  };
5111
5277
  }
5112
5278
  };
5279
+ function isRefusalDeltaChunk(chunk) {
5280
+ return chunk.type === "response.refusal.delta";
5281
+ }
5282
+ function isRefusalDoneChunk(chunk) {
5283
+ return chunk.type === "response.refusal.done";
5284
+ }
5113
5285
  function isTextDeltaChunk(chunk) {
5114
5286
  return chunk.type === "response.output_text.delta";
5115
5287
  }