@ai-sdk/openai 4.0.0-beta.11 → 4.0.0-beta.13

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.
@@ -7,6 +7,7 @@ import {
7
7
  createEventSourceResponseHandler,
8
8
  createJsonResponseHandler,
9
9
  generateId,
10
+ isCustomReasoning,
10
11
  isParsableJson,
11
12
  parseProviderOptions,
12
13
  postJsonToApi
@@ -654,9 +655,10 @@ var OpenAIChatLanguageModel = class {
654
655
  seed,
655
656
  tools,
656
657
  toolChoice,
658
+ reasoning,
657
659
  providerOptions
658
660
  }) {
659
- var _a, _b, _c, _d, _e;
661
+ var _a, _b, _c, _d, _e, _f;
660
662
  const warnings = [];
661
663
  const openaiOptions = (_a = await parseProviderOptions({
662
664
  provider: "openai",
@@ -664,18 +666,19 @@ var OpenAIChatLanguageModel = class {
664
666
  schema: openaiLanguageModelChatOptions
665
667
  })) != null ? _a : {};
666
668
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
667
- const isReasoningModel = (_b = openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
669
+ const resolvedReasoningEffort = (_b = openaiOptions.reasoningEffort) != null ? _b : isCustomReasoning(reasoning) ? reasoning : void 0;
670
+ const isReasoningModel = (_c = openaiOptions.forceReasoning) != null ? _c : modelCapabilities.isReasoningModel;
668
671
  if (topK != null) {
669
672
  warnings.push({ type: "unsupported", feature: "topK" });
670
673
  }
671
674
  const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages(
672
675
  {
673
676
  prompt,
674
- systemMessageMode: (_c = openaiOptions.systemMessageMode) != null ? _c : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode
677
+ systemMessageMode: (_d = openaiOptions.systemMessageMode) != null ? _d : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode
675
678
  }
676
679
  );
677
680
  warnings.push(...messageWarnings);
678
- const strictJsonSchema = (_d = openaiOptions.strictJsonSchema) != null ? _d : true;
681
+ const strictJsonSchema = (_e = openaiOptions.strictJsonSchema) != null ? _e : true;
679
682
  const baseArgs = {
680
683
  // model id:
681
684
  model: this.modelId,
@@ -696,7 +699,7 @@ var OpenAIChatLanguageModel = class {
696
699
  json_schema: {
697
700
  schema: responseFormat.schema,
698
701
  strict: strictJsonSchema,
699
- name: (_e = responseFormat.name) != null ? _e : "response",
702
+ name: (_f = responseFormat.name) != null ? _f : "response",
700
703
  description: responseFormat.description
701
704
  }
702
705
  } : { type: "json_object" } : void 0,
@@ -709,7 +712,7 @@ var OpenAIChatLanguageModel = class {
709
712
  store: openaiOptions.store,
710
713
  metadata: openaiOptions.metadata,
711
714
  prediction: openaiOptions.prediction,
712
- reasoning_effort: openaiOptions.reasoningEffort,
715
+ reasoning_effort: resolvedReasoningEffort,
713
716
  service_tier: openaiOptions.serviceTier,
714
717
  prompt_cache_key: openaiOptions.promptCacheKey,
715
718
  prompt_cache_retention: openaiOptions.promptCacheRetention,
@@ -718,7 +721,7 @@ var OpenAIChatLanguageModel = class {
718
721
  messages
719
722
  };
720
723
  if (isReasoningModel) {
721
- if (openaiOptions.reasoningEffort !== "none" || !modelCapabilities.supportsNonReasoningParameters) {
724
+ if (resolvedReasoningEffort !== "none" || !modelCapabilities.supportsNonReasoningParameters) {
722
725
  if (baseArgs.temperature != null) {
723
726
  baseArgs.temperature = void 0;
724
727
  warnings.push({
@@ -2338,6 +2341,7 @@ import {
2338
2341
  createJsonResponseHandler as createJsonResponseHandler6,
2339
2342
  createToolNameMapping,
2340
2343
  generateId as generateId2,
2344
+ isCustomReasoning as isCustomReasoning2,
2341
2345
  parseProviderOptions as parseProviderOptions7,
2342
2346
  postJsonToApi as postJsonToApi6
2343
2347
  } from "@ai-sdk/provider-utils";
@@ -2626,7 +2630,7 @@ async function convertToOpenAIResponsesInput({
2626
2630
  hasApplyPatchTool = false,
2627
2631
  customProviderToolNames
2628
2632
  }) {
2629
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
2633
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
2630
2634
  let input = [];
2631
2635
  const warnings = [];
2632
2636
  const processedApprovalIds = /* @__PURE__ */ new Set();
@@ -2973,6 +2977,28 @@ async function convertToOpenAIResponsesInput({
2973
2977
  }
2974
2978
  break;
2975
2979
  }
2980
+ case "custom": {
2981
+ if (part.kind === "openai-compaction") {
2982
+ const providerOpts = (_n = part.providerOptions) == null ? void 0 : _n[providerOptionsName];
2983
+ const id = providerOpts == null ? void 0 : providerOpts.itemId;
2984
+ if (hasConversation && id != null) {
2985
+ break;
2986
+ }
2987
+ if (store && id != null) {
2988
+ input.push({ type: "item_reference", id });
2989
+ break;
2990
+ }
2991
+ const encryptedContent = providerOpts == null ? void 0 : providerOpts.encryptedContent;
2992
+ if (id != null) {
2993
+ input.push({
2994
+ type: "compaction",
2995
+ id,
2996
+ encrypted_content: encryptedContent
2997
+ });
2998
+ }
2999
+ }
3000
+ break;
3001
+ }
2976
3002
  }
2977
3003
  }
2978
3004
  break;
@@ -3000,7 +3026,7 @@ async function convertToOpenAIResponsesInput({
3000
3026
  }
3001
3027
  const output = part.output;
3002
3028
  if (output.type === "execution-denied") {
3003
- const approvalId = (_o = (_n = output.providerOptions) == null ? void 0 : _n.openai) == null ? void 0 : _o.approvalId;
3029
+ const approvalId = (_p = (_o = output.providerOptions) == null ? void 0 : _o.openai) == null ? void 0 : _p.approvalId;
3004
3030
  if (approvalId) {
3005
3031
  continue;
3006
3032
  }
@@ -3074,7 +3100,7 @@ async function convertToOpenAIResponsesInput({
3074
3100
  outputValue = output.value;
3075
3101
  break;
3076
3102
  case "execution-denied":
3077
- outputValue = (_p = output.reason) != null ? _p : "Tool execution denied.";
3103
+ outputValue = (_q = output.reason) != null ? _q : "Tool execution denied.";
3078
3104
  break;
3079
3105
  case "json":
3080
3106
  case "error-json":
@@ -3128,7 +3154,7 @@ async function convertToOpenAIResponsesInput({
3128
3154
  contentValue = output.value;
3129
3155
  break;
3130
3156
  case "execution-denied":
3131
- contentValue = (_q = output.reason) != null ? _q : "Tool execution denied.";
3157
+ contentValue = (_r = output.reason) != null ? _r : "Tool execution denied.";
3132
3158
  break;
3133
3159
  case "json":
3134
3160
  case "error-json":
@@ -3380,6 +3406,11 @@ var openaiResponsesChunkSchema = lazySchema15(
3380
3406
  commands: z17.array(z17.string())
3381
3407
  })
3382
3408
  }),
3409
+ z17.object({
3410
+ type: z17.literal("compaction"),
3411
+ id: z17.string(),
3412
+ encrypted_content: z17.string().nullish()
3413
+ }),
3383
3414
  z17.object({
3384
3415
  type: z17.literal("shell_call_output"),
3385
3416
  id: z17.string(),
@@ -3603,6 +3634,11 @@ var openaiResponsesChunkSchema = lazySchema15(
3603
3634
  commands: z17.array(z17.string())
3604
3635
  })
3605
3636
  }),
3637
+ z17.object({
3638
+ type: z17.literal("compaction"),
3639
+ id: z17.string(),
3640
+ encrypted_content: z17.string()
3641
+ }),
3606
3642
  z17.object({
3607
3643
  type: z17.literal("shell_call_output"),
3608
3644
  id: z17.string(),
@@ -4000,6 +4036,11 @@ var openaiResponsesResponseSchema = lazySchema15(
4000
4036
  commands: z17.array(z17.string())
4001
4037
  })
4002
4038
  }),
4039
+ z17.object({
4040
+ type: z17.literal("compaction"),
4041
+ id: z17.string(),
4042
+ encrypted_content: z17.string()
4043
+ }),
4003
4044
  z17.object({
4004
4045
  type: z17.literal("shell_call_output"),
4005
4046
  id: z17.string(),
@@ -4262,7 +4303,16 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema16(
4262
4303
  * When enabled, the SDK applies reasoning-model parameter compatibility rules
4263
4304
  * and defaults `systemMessageMode` to `developer` unless overridden.
4264
4305
  */
4265
- forceReasoning: z18.boolean().optional()
4306
+ forceReasoning: z18.boolean().optional(),
4307
+ /**
4308
+ * Enable server-side context management (compaction).
4309
+ */
4310
+ contextManagement: z18.array(
4311
+ z18.object({
4312
+ type: z18.literal("compaction"),
4313
+ compactThreshold: z18.number()
4314
+ })
4315
+ ).nullish()
4266
4316
  })
4267
4317
  )
4268
4318
  );
@@ -4926,12 +4976,13 @@ var OpenAIResponsesLanguageModel = class {
4926
4976
  frequencyPenalty,
4927
4977
  seed,
4928
4978
  prompt,
4979
+ reasoning,
4929
4980
  providerOptions,
4930
4981
  tools,
4931
4982
  toolChoice,
4932
4983
  responseFormat
4933
4984
  }) {
4934
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4985
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
4935
4986
  const warnings = [];
4936
4987
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
4937
4988
  if (topK != null) {
@@ -4962,7 +5013,8 @@ var OpenAIResponsesLanguageModel = class {
4962
5013
  schema: openaiLanguageModelResponsesOptionsSchema
4963
5014
  });
4964
5015
  }
4965
- const isReasoningModel = (_a = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _a : modelCapabilities.isReasoningModel;
5016
+ const resolvedReasoningEffort = (_a = openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null ? _a : isCustomReasoning2(reasoning) ? reasoning : void 0;
5017
+ const isReasoningModel = (_b = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
4966
5018
  if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
4967
5019
  warnings.push({
4968
5020
  type: "unsupported",
@@ -4999,10 +5051,10 @@ var OpenAIResponsesLanguageModel = class {
4999
5051
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
5000
5052
  prompt,
5001
5053
  toolNameMapping,
5002
- systemMessageMode: (_b = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _b : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
5054
+ systemMessageMode: (_c = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _c : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
5003
5055
  providerOptionsName,
5004
5056
  fileIdPrefixes: this.config.fileIdPrefixes,
5005
- store: (_c = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _c : true,
5057
+ store: (_d = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _d : true,
5006
5058
  hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
5007
5059
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
5008
5060
  hasShellTool: hasOpenAITool("openai.shell"),
@@ -5010,7 +5062,7 @@ var OpenAIResponsesLanguageModel = class {
5010
5062
  customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
5011
5063
  });
5012
5064
  warnings.push(...inputWarnings);
5013
- const strictJsonSchema = (_d = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _d : true;
5065
+ const strictJsonSchema = (_e = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _e : true;
5014
5066
  let include = openaiOptions == null ? void 0 : openaiOptions.include;
5015
5067
  function addInclude(key) {
5016
5068
  if (include == null) {
@@ -5026,9 +5078,9 @@ var OpenAIResponsesLanguageModel = class {
5026
5078
  if (topLogprobs) {
5027
5079
  addInclude("message.output_text.logprobs");
5028
5080
  }
5029
- const webSearchToolName = (_e = tools == null ? void 0 : tools.find(
5081
+ const webSearchToolName = (_f = tools == null ? void 0 : tools.find(
5030
5082
  (tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
5031
- )) == null ? void 0 : _e.name;
5083
+ )) == null ? void 0 : _f.name;
5032
5084
  if (webSearchToolName) {
5033
5085
  addInclude("web_search_call.action.sources");
5034
5086
  }
@@ -5051,7 +5103,7 @@ var OpenAIResponsesLanguageModel = class {
5051
5103
  format: responseFormat.schema != null ? {
5052
5104
  type: "json_schema",
5053
5105
  strict: strictJsonSchema,
5054
- name: (_f = responseFormat.name) != null ? _f : "response",
5106
+ name: (_g = responseFormat.name) != null ? _g : "response",
5055
5107
  description: responseFormat.description,
5056
5108
  schema: responseFormat.schema
5057
5109
  } : { type: "json_object" }
@@ -5077,11 +5129,18 @@ var OpenAIResponsesLanguageModel = class {
5077
5129
  safety_identifier: openaiOptions == null ? void 0 : openaiOptions.safetyIdentifier,
5078
5130
  top_logprobs: topLogprobs,
5079
5131
  truncation: openaiOptions == null ? void 0 : openaiOptions.truncation,
5132
+ // context management (server-side compaction):
5133
+ ...(openaiOptions == null ? void 0 : openaiOptions.contextManagement) && {
5134
+ context_management: openaiOptions.contextManagement.map((cm) => ({
5135
+ type: cm.type,
5136
+ compact_threshold: cm.compactThreshold
5137
+ }))
5138
+ },
5080
5139
  // model-specific settings:
5081
- ...isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
5140
+ ...isReasoningModel && (resolvedReasoningEffort != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
5082
5141
  reasoning: {
5083
- ...(openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null && {
5084
- effort: openaiOptions.reasoningEffort
5142
+ ...resolvedReasoningEffort != null && {
5143
+ effort: resolvedReasoningEffort
5085
5144
  },
5086
5145
  ...(openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null && {
5087
5146
  summary: openaiOptions.reasoningSummary
@@ -5090,7 +5149,7 @@ var OpenAIResponsesLanguageModel = class {
5090
5149
  }
5091
5150
  };
5092
5151
  if (isReasoningModel) {
5093
- if (!((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) === "none" && modelCapabilities.supportsNonReasoningParameters)) {
5152
+ if (!(resolvedReasoningEffort === "none" && modelCapabilities.supportsNonReasoningParameters)) {
5094
5153
  if (baseArgs.temperature != null) {
5095
5154
  baseArgs.temperature = void 0;
5096
5155
  warnings.push({
@@ -5140,9 +5199,9 @@ var OpenAIResponsesLanguageModel = class {
5140
5199
  });
5141
5200
  delete baseArgs.service_tier;
5142
5201
  }
5143
- const shellToolEnvType = (_i = (_h = (_g = tools == null ? void 0 : tools.find(
5202
+ const shellToolEnvType = (_j = (_i = (_h = tools == null ? void 0 : tools.find(
5144
5203
  (tool) => tool.type === "provider" && tool.id === "openai.shell"
5145
- )) == null ? void 0 : _g.args) == null ? void 0 : _h.environment) == null ? void 0 : _i.type;
5204
+ )) == null ? void 0 : _h.args) == null ? void 0 : _i.environment) == null ? void 0 : _j.type;
5146
5205
  const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
5147
5206
  return {
5148
5207
  webSearchToolName,
@@ -5601,6 +5660,20 @@ var OpenAIResponsesLanguageModel = class {
5601
5660
  });
5602
5661
  break;
5603
5662
  }
5663
+ case "compaction": {
5664
+ content.push({
5665
+ type: "custom",
5666
+ kind: "openai-compaction",
5667
+ providerMetadata: {
5668
+ [providerOptionsName]: {
5669
+ type: "compaction",
5670
+ itemId: part.id,
5671
+ encryptedContent: part.encrypted_content
5672
+ }
5673
+ }
5674
+ });
5675
+ break;
5676
+ }
5604
5677
  }
5605
5678
  }
5606
5679
  const providerMetadata = {
@@ -6230,6 +6303,18 @@ var OpenAIResponsesLanguageModel = class {
6230
6303
  });
6231
6304
  }
6232
6305
  delete activeReasoning[value.item.id];
6306
+ } else if (value.item.type === "compaction") {
6307
+ controller.enqueue({
6308
+ type: "custom",
6309
+ kind: "openai-compaction",
6310
+ providerMetadata: {
6311
+ [providerOptionsName]: {
6312
+ type: "compaction",
6313
+ itemId: value.item.id,
6314
+ encryptedContent: value.item.encrypted_content
6315
+ }
6316
+ }
6317
+ });
6233
6318
  }
6234
6319
  } else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
6235
6320
  const toolCall = ongoingToolCalls[value.output_index];