@ai-sdk/openai 4.0.73 → 4.0.75

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.js CHANGED
@@ -3734,7 +3734,7 @@ var openaiTools = {
3734
3734
  import {
3735
3735
  InvalidArgumentError as InvalidArgumentError2,
3736
3736
  InvalidResponseDataError as InvalidResponseDataError2,
3737
- UnsupportedFunctionalityError as UnsupportedFunctionalityError7
3737
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError8
3738
3738
  } from "@ai-sdk/provider";
3739
3739
  import {
3740
3740
  combineHeaders as combineHeaders7,
@@ -3941,7 +3941,7 @@ var openaiResponsesNestedErrorChunkSchema = z25.object({
3941
3941
  sequence_number: z25.number(),
3942
3942
  error: z25.object({
3943
3943
  type: z25.string(),
3944
- code: z25.string(),
3944
+ code: z25.string().nullish(),
3945
3945
  message: z25.string(),
3946
3946
  param: z25.string().nullish()
3947
3947
  })
@@ -4855,7 +4855,8 @@ var openaiResponsesResponseSchema = lazySchema24(
4855
4855
 
4856
4856
  // src/responses/openai-responses-language-model.ts
4857
4857
  import {
4858
- APICallError as APICallError2
4858
+ APICallError as APICallError2,
4859
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError7
4859
4860
  } from "@ai-sdk/provider";
4860
4861
  import {
4861
4862
  combineHeaders as combineHeaders6,
@@ -4907,1258 +4908,14 @@ import {
4907
4908
  resolveProviderReference as resolveProviderReference2,
4908
4909
  validateTypes
4909
4910
  } from "@ai-sdk/provider-utils";
4910
- import { z as z26 } from "zod/v4";
4911
+ import { z as z27 } from "zod/v4";
4911
4912
 
4912
- // src/responses/expand-parallel-tool-call.ts
4913
- import {
4914
- isJSONObject
4915
- } from "@ai-sdk/provider";
4916
- import { safeParseJSON } from "@ai-sdk/provider-utils";
4917
- var parallelToolName = "parallel";
4918
- var recipientNamePrefix = "functions.";
4919
- function getParallelToolCallMetadata({
4920
- providerOptions,
4921
- providerOptionsName
4922
- }) {
4923
- var _a2;
4924
- const metadata = (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.parallelToolCall;
4925
- if (!isJSONObject(metadata) || typeof metadata.itemId !== "string" || typeof metadata.toolCallId !== "string" || typeof metadata.toolName !== "string" || typeof metadata.input !== "string" || typeof metadata.index !== "number" || !Number.isInteger(metadata.index) || typeof metadata.count !== "number" || !Number.isInteger(metadata.count) || metadata.index < 0 || metadata.count <= metadata.index) {
4926
- return void 0;
4927
- }
4928
- return metadata;
4929
- }
4930
- function isUndeclaredParallelToolCall({
4931
- toolName,
4932
- tools
4933
- }) {
4934
- return toolName === parallelToolName && !tools.some((tool) => tool.name === parallelToolName);
4935
- }
4936
- async function expandParallelToolCall({
4937
- toolCall,
4938
- tools,
4939
- providerOptionsName,
4940
- itemId
4941
- }) {
4942
- if (!isUndeclaredParallelToolCall({ toolName: toolCall.toolName, tools })) {
4943
- return void 0;
4944
- }
4945
- const parsedInput = await safeParseJSON({ text: toolCall.input });
4946
- if (!parsedInput.success || !isJSONObject(parsedInput.value)) {
4947
- return void 0;
4948
- }
4949
- const toolUses = parsedInput.value.tool_uses;
4950
- if (!Array.isArray(toolUses) || toolUses.length === 0) {
4951
- return void 0;
4952
- }
4953
- const availableToolNames = new Set(tools.map((tool) => tool.name));
4954
- const expandedToolCalls = [];
4955
- for (const [index, toolUse] of toolUses.entries()) {
4956
- if (!isJSONObject(toolUse)) {
4957
- return void 0;
4958
- }
4959
- const recipientName = toolUse.recipient_name;
4960
- const parameters = toolUse.parameters;
4961
- if (typeof recipientName !== "string" || !recipientName.startsWith(recipientNamePrefix) || !isJSONObject(parameters)) {
4962
- return void 0;
4963
- }
4964
- const toolName = recipientName.slice(recipientNamePrefix.length);
4965
- if (toolName.length === 0 || !availableToolNames.has(toolName)) {
4966
- return void 0;
4967
- }
4968
- expandedToolCalls.push({
4969
- type: "tool-call",
4970
- toolCallId: `${toolCall.toolCallId}_${index}`,
4971
- toolName,
4972
- input: JSON.stringify(parameters),
4973
- providerMetadata: {
4974
- [providerOptionsName]: {
4975
- parallelToolCall: {
4976
- itemId,
4977
- toolCallId: toolCall.toolCallId,
4978
- toolName: toolCall.toolName,
4979
- input: toolCall.input,
4980
- index,
4981
- count: toolUses.length
4982
- }
4983
- }
4984
- }
4985
- });
4986
- }
4987
- return expandedToolCalls;
4988
- }
4989
-
4990
- // src/responses/convert-to-openai-responses-input.ts
4991
- function serializeToolCallArguments2(input) {
4992
- return JSON.stringify(input === void 0 ? {} : input);
4993
- }
4994
- function mapToolCaller(caller) {
4995
- return caller == null ? void 0 : caller.type === "program" ? { type: "program", caller_id: caller.callerId } : caller;
4996
- }
4997
- async function convertFunctionToolResultOutput({
4998
- output,
4999
- toolName,
5000
- outputSchemaToolNames,
5001
- promptCacheBreakpoint,
5002
- providerOptionsName,
5003
- warnings
5004
- }) {
5005
- var _a2;
5006
- const hasOutputSchema = outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.has(toolName);
5007
- const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
5008
- {
5009
- type: "input_text",
5010
- text: value,
5011
- prompt_cache_breakpoint: promptCacheBreakpoint
5012
- }
5013
- ];
5014
- switch (output.type) {
5015
- case "text":
5016
- case "error-text":
5017
- return convertScalarOutput(
5018
- hasOutputSchema ? JSON.stringify(output.value) : output.value
5019
- );
5020
- case "execution-denied": {
5021
- const reason = (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
5022
- return convertScalarOutput(
5023
- hasOutputSchema ? JSON.stringify(reason) : reason
5024
- );
5025
- }
5026
- case "json":
5027
- case "error-json":
5028
- return convertScalarOutput(JSON.stringify(output.value));
5029
- case "content":
5030
- return output.value.map((item) => {
5031
- var _a3, _b, _c;
5032
- const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
5033
- item.providerOptions,
5034
- providerOptionsName
5035
- );
5036
- switch (item.type) {
5037
- case "text": {
5038
- return {
5039
- type: "input_text",
5040
- text: item.text,
5041
- ...promptCacheBreakpoint2 != null && {
5042
- prompt_cache_breakpoint: promptCacheBreakpoint2
5043
- }
5044
- };
5045
- }
5046
- case "file": {
5047
- const topLevel = getTopLevelMediaType2(item.mediaType);
5048
- const imageDetail = (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail;
5049
- if (item.data.type === "reference") {
5050
- const fileId = resolveProviderReference2({
5051
- reference: item.data.reference,
5052
- provider: providerOptionsName
5053
- });
5054
- if (topLevel === "image") {
5055
- return {
5056
- type: "input_image",
5057
- file_id: fileId,
5058
- detail: imageDetail,
5059
- ...promptCacheBreakpoint2 != null && {
5060
- prompt_cache_breakpoint: promptCacheBreakpoint2
5061
- }
5062
- };
5063
- }
5064
- return {
5065
- type: "input_file",
5066
- file_id: fileId,
5067
- ...promptCacheBreakpoint2 != null && {
5068
- prompt_cache_breakpoint: promptCacheBreakpoint2
5069
- }
5070
- };
5071
- }
5072
- if (item.data.type === "data") {
5073
- const fullMediaType = resolveFullMediaType2({ part: item });
5074
- if (topLevel === "image") {
5075
- return {
5076
- type: "input_image",
5077
- image_url: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
5078
- detail: imageDetail,
5079
- ...promptCacheBreakpoint2 != null && {
5080
- prompt_cache_breakpoint: promptCacheBreakpoint2
5081
- }
5082
- };
5083
- }
5084
- return {
5085
- type: "input_file",
5086
- filename: (_c = item.filename) != null ? _c : "data",
5087
- file_data: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
5088
- ...promptCacheBreakpoint2 != null && {
5089
- prompt_cache_breakpoint: promptCacheBreakpoint2
5090
- }
5091
- };
5092
- }
5093
- if (item.data.type === "url") {
5094
- if (topLevel === "image") {
5095
- return {
5096
- type: "input_image",
5097
- image_url: item.data.url.toString(),
5098
- detail: imageDetail,
5099
- ...promptCacheBreakpoint2 != null && {
5100
- prompt_cache_breakpoint: promptCacheBreakpoint2
5101
- }
5102
- };
5103
- }
5104
- return {
5105
- type: "input_file",
5106
- file_url: item.data.url.toString(),
5107
- ...promptCacheBreakpoint2 != null && {
5108
- prompt_cache_breakpoint: promptCacheBreakpoint2
5109
- }
5110
- };
5111
- }
5112
- warnings.push({
5113
- type: "other",
5114
- message: `unsupported tool content part type: ${item.type} with data type: ${item.data.type}`
5115
- });
5116
- return void 0;
5117
- }
5118
- default: {
5119
- warnings.push({
5120
- type: "other",
5121
- message: `unsupported tool content part type: ${item.type}`
5122
- });
5123
- return void 0;
5124
- }
5125
- }
5126
- }).filter(isNonNullable);
5127
- }
5128
- }
5129
- function hasSameParallelToolCall(first, second) {
5130
- return first.itemId === second.itemId && first.toolCallId === second.toolCallId && first.toolName === second.toolName && first.input === second.input && first.count === second.count;
5131
- }
5132
- function collectCompleteParallelToolResultGroups({
5133
- prompt,
5134
- providerOptionsName
5135
- }) {
5136
- const pendingGroups = /* @__PURE__ */ new Map();
5137
- for (const message of prompt) {
5138
- if (message.role !== "tool") {
5139
- continue;
5140
- }
5141
- for (const part of message.content) {
5142
- if (part.type !== "tool-result") {
5143
- continue;
5144
- }
5145
- const metadata = getParallelToolCallMetadata({
5146
- providerOptions: part.providerOptions,
5147
- providerOptionsName
5148
- });
5149
- if (metadata == null) {
5150
- continue;
5151
- }
5152
- const existing = pendingGroups.get(metadata.toolCallId);
5153
- if (existing == null) {
5154
- pendingGroups.set(metadata.toolCallId, {
5155
- metadata,
5156
- results: /* @__PURE__ */ new Map([[metadata.index, part]]),
5157
- invalid: false
5158
- });
5159
- continue;
5160
- }
5161
- if (!hasSameParallelToolCall(existing.metadata, metadata) || existing.results.has(metadata.index)) {
5162
- existing.invalid = true;
5163
- continue;
5164
- }
5165
- existing.results.set(metadata.index, part);
5166
- }
5167
- }
5168
- const completeGroups = /* @__PURE__ */ new Map();
5169
- for (const [toolCallId, group] of pendingGroups) {
5170
- if (group.invalid || group.results.size !== group.metadata.count) {
5171
- continue;
5172
- }
5173
- const results = Array.from(
5174
- { length: group.metadata.count },
5175
- (_, index) => group.results.get(index)
5176
- );
5177
- if (results.every(isNonNullable)) {
5178
- completeGroups.set(toolCallId, {
5179
- metadata: group.metadata,
5180
- results
5181
- });
5182
- }
5183
- }
5184
- return completeGroups;
5185
- }
5186
- function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
5187
- var _a2;
5188
- return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
5189
- }
5190
- function getScalarToolResultPromptCacheBreakpoint({
5191
- output,
5192
- toolResultProviderOptions,
5193
- providerOptionsName
5194
- }) {
5195
- var _a2;
5196
- return output.type === "content" ? void 0 : (_a2 = getPromptCacheBreakpoint2(output.providerOptions, providerOptionsName)) != null ? _a2 : getPromptCacheBreakpoint2(
5197
- toolResultProviderOptions,
5198
- providerOptionsName
5199
- );
5200
- }
5201
- function isFileId(data, prefixes) {
5202
- if (!prefixes) return false;
5203
- return prefixes.some((prefix) => data.startsWith(prefix));
5204
- }
5205
- async function convertToOpenAIResponsesInput({
5206
- prompt,
5207
- toolNameMapping,
5208
- systemMessageMode,
5209
- providerOptionsName,
5210
- explicitMessageItemType = false,
5211
- fileIdPrefixes,
5212
- passThroughUnsupportedFiles = false,
5213
- store,
5214
- hasConversation = false,
5215
- hasPreviousResponseId = false,
5216
- hasLocalShellTool = false,
5217
- hasShellTool = false,
5218
- hasApplyPatchTool = false,
5219
- hasComputerTool = false,
5220
- toolSearchToolName,
5221
- customProviderToolNames,
5222
- outputSchemaToolNames
5223
- }) {
5224
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P;
5225
- let input = [];
5226
- const warnings = [];
5227
- const processedApprovalIds = /* @__PURE__ */ new Set();
5228
- const programmaticToolCallIds = /* @__PURE__ */ new Set();
5229
- const parallelToolResultGroups = hasConversation || hasPreviousResponseId ? collectCompleteParallelToolResultGroups({
5230
- prompt,
5231
- providerOptionsName
5232
- }) : /* @__PURE__ */ new Map();
5233
- const emittedParallelToolCalls = /* @__PURE__ */ new Set();
5234
- const emittedParallelToolResults = /* @__PURE__ */ new Set();
5235
- for (const { role, content, providerOptions } of prompt) {
5236
- switch (role) {
5237
- case "system": {
5238
- switch (systemMessageMode) {
5239
- case "system": {
5240
- const promptCacheBreakpoint = getPromptCacheBreakpoint2(
5241
- providerOptions,
5242
- providerOptionsName
5243
- );
5244
- input.push({
5245
- ...explicitMessageItemType && { type: "message" },
5246
- role: "system",
5247
- content: promptCacheBreakpoint == null ? content : [
5248
- {
5249
- type: "input_text",
5250
- text: content,
5251
- prompt_cache_breakpoint: promptCacheBreakpoint
5252
- }
5253
- ]
5254
- });
5255
- break;
5256
- }
5257
- case "developer": {
5258
- const promptCacheBreakpoint = getPromptCacheBreakpoint2(
5259
- providerOptions,
5260
- providerOptionsName
5261
- );
5262
- input.push({
5263
- ...explicitMessageItemType && { type: "message" },
5264
- role: "developer",
5265
- content: promptCacheBreakpoint == null ? content : [
5266
- {
5267
- type: "input_text",
5268
- text: content,
5269
- prompt_cache_breakpoint: promptCacheBreakpoint
5270
- }
5271
- ]
5272
- });
5273
- break;
5274
- }
5275
- case "remove": {
5276
- warnings.push({
5277
- type: "other",
5278
- message: "system messages are removed for this model"
5279
- });
5280
- break;
5281
- }
5282
- default: {
5283
- const _exhaustiveCheck = systemMessageMode;
5284
- throw new Error(
5285
- `Unsupported system message mode: ${_exhaustiveCheck}`
5286
- );
5287
- }
5288
- }
5289
- break;
5290
- }
5291
- case "user": {
5292
- input.push({
5293
- ...explicitMessageItemType && { type: "message" },
5294
- role: "user",
5295
- content: content.map((part, index) => {
5296
- var _a3, _b2, _c2, _d2, _e2;
5297
- switch (part.type) {
5298
- case "text": {
5299
- const promptCacheBreakpoint = getPromptCacheBreakpoint2(
5300
- part.providerOptions,
5301
- providerOptionsName
5302
- );
5303
- return {
5304
- type: "input_text",
5305
- text: part.text,
5306
- ...promptCacheBreakpoint != null && {
5307
- prompt_cache_breakpoint: promptCacheBreakpoint
5308
- }
5309
- };
5310
- }
5311
- case "file": {
5312
- const promptCacheBreakpoint = getPromptCacheBreakpoint2(
5313
- part.providerOptions,
5314
- providerOptionsName
5315
- );
5316
- switch (part.data.type) {
5317
- case "reference": {
5318
- const fileId = resolveProviderReference2({
5319
- reference: part.data.reference,
5320
- provider: providerOptionsName
5321
- });
5322
- if (getTopLevelMediaType2(part.mediaType) === "image") {
5323
- return {
5324
- type: "input_image",
5325
- file_id: fileId,
5326
- detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
5327
- ...promptCacheBreakpoint != null && {
5328
- prompt_cache_breakpoint: promptCacheBreakpoint
5329
- }
5330
- };
5331
- }
5332
- return {
5333
- type: "input_file",
5334
- file_id: fileId,
5335
- ...promptCacheBreakpoint != null && {
5336
- prompt_cache_breakpoint: promptCacheBreakpoint
5337
- }
5338
- };
5339
- }
5340
- case "text": {
5341
- throw new UnsupportedFunctionalityError5({
5342
- functionality: "text file parts"
5343
- });
5344
- }
5345
- case "url":
5346
- case "data": {
5347
- const topLevel = getTopLevelMediaType2(part.mediaType);
5348
- if (topLevel === "image") {
5349
- return {
5350
- type: "input_image",
5351
- ...part.data.type === "url" ? { image_url: part.data.url.toString() } : typeof part.data.data === "string" && isFileId(part.data.data, fileIdPrefixes) ? { file_id: part.data.data } : {
5352
- image_url: `data:${resolveFullMediaType2({ part })};base64,${convertToBase642(part.data.data)}`
5353
- },
5354
- detail: (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
5355
- ...promptCacheBreakpoint != null && {
5356
- prompt_cache_breakpoint: promptCacheBreakpoint
5357
- }
5358
- };
5359
- } else {
5360
- if (part.data.type === "url") {
5361
- return {
5362
- type: "input_file",
5363
- file_url: part.data.url.toString(),
5364
- ...promptCacheBreakpoint != null && {
5365
- prompt_cache_breakpoint: promptCacheBreakpoint
5366
- }
5367
- };
5368
- }
5369
- const fullMediaType = resolveFullMediaType2({ part });
5370
- if (fullMediaType !== "application/pdf" && !passThroughUnsupportedFiles) {
5371
- throw new UnsupportedFunctionalityError5({
5372
- functionality: `file part media type ${fullMediaType}`
5373
- });
5374
- }
5375
- return {
5376
- type: "input_file",
5377
- ...typeof part.data.data === "string" && isFileId(part.data.data, fileIdPrefixes) ? { file_id: part.data.data } : {
5378
- filename: (_e2 = part.filename) != null ? _e2 : fullMediaType === "application/pdf" ? `part-${index}.pdf` : `part-${index}`,
5379
- file_data: `data:${fullMediaType};base64,${convertToBase642(part.data.data)}`
5380
- },
5381
- ...promptCacheBreakpoint != null && {
5382
- prompt_cache_breakpoint: promptCacheBreakpoint
5383
- }
5384
- };
5385
- }
5386
- }
5387
- }
5388
- }
5389
- }
5390
- })
5391
- });
5392
- break;
5393
- }
5394
- case "assistant": {
5395
- const reasoningMessages = {};
5396
- for (const part of content) {
5397
- switch (part.type) {
5398
- case "text": {
5399
- const providerOptions2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName];
5400
- const id = providerOptions2 == null ? void 0 : providerOptions2.itemId;
5401
- const phase = providerOptions2 == null ? void 0 : providerOptions2.phase;
5402
- if (hasConversation && id != null) {
5403
- break;
5404
- }
5405
- if (store && id != null) {
5406
- input.push({ type: "item_reference", id });
5407
- break;
5408
- }
5409
- input.push({
5410
- ...explicitMessageItemType && { type: "message" },
5411
- role: "assistant",
5412
- content: part.text,
5413
- ...phase != null && { phase }
5414
- });
5415
- break;
5416
- }
5417
- case "tool-call": {
5418
- const parallelToolCallMetadata = getParallelToolCallMetadata({
5419
- providerOptions: part.providerOptions,
5420
- providerOptionsName
5421
- });
5422
- const parallelToolResultGroup = parallelToolCallMetadata == null ? void 0 : parallelToolResultGroups.get(
5423
- parallelToolCallMetadata.toolCallId
5424
- );
5425
- if (parallelToolCallMetadata != null && parallelToolResultGroup != null && hasSameParallelToolCall(
5426
- parallelToolResultGroup.metadata,
5427
- parallelToolCallMetadata
5428
- )) {
5429
- if (!emittedParallelToolCalls.has(
5430
- parallelToolResultGroup.metadata.toolCallId
5431
- )) {
5432
- emittedParallelToolCalls.add(
5433
- parallelToolResultGroup.metadata.toolCallId
5434
- );
5435
- if (!hasConversation) {
5436
- input.push({
5437
- type: "function_call",
5438
- call_id: parallelToolResultGroup.metadata.toolCallId,
5439
- name: parallelToolResultGroup.metadata.toolName,
5440
- arguments: parallelToolResultGroup.metadata.input
5441
- });
5442
- }
5443
- }
5444
- break;
5445
- }
5446
- const id = (_f = (_c = (_b = part.providerOptions) == null ? void 0 : _b[providerOptionsName]) == null ? void 0 : _c.itemId) != null ? _f : (_e = (_d = part.providerMetadata) == null ? void 0 : _d[providerOptionsName]) == null ? void 0 : _e.itemId;
5447
- const namespace = (_k = (_h = (_g = part.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.namespace) != null ? _k : (_j = (_i = part.providerMetadata) == null ? void 0 : _i[providerOptionsName]) == null ? void 0 : _j.namespace;
5448
- const isAsync = (_p = (_m = (_l = part.providerOptions) == null ? void 0 : _l[providerOptionsName]) == null ? void 0 : _m.async) != null ? _p : (_o = (_n = part.providerMetadata) == null ? void 0 : _n[providerOptionsName]) == null ? void 0 : _o.async;
5449
- const caller = (_r = (_q = part.providerOptions) == null ? void 0 : _q[providerOptionsName]) == null ? void 0 : _r.caller;
5450
- if ((caller == null ? void 0 : caller.type) === "program") {
5451
- programmaticToolCallIds.add(part.toolCallId);
5452
- }
5453
- if (hasConversation && id != null) {
5454
- break;
5455
- }
5456
- const resolvedToolName = toolNameMapping.toProviderToolName(
5457
- part.toolName
5458
- );
5459
- if (part.toolName === toolSearchToolName) {
5460
- if (store && id != null) {
5461
- input.push({ type: "item_reference", id });
5462
- break;
5463
- }
5464
- const parsedInput = typeof part.input === "string" ? await parseJSON({
5465
- text: part.input,
5466
- schema: toolSearchInputSchema
5467
- }) : await validateTypes({
5468
- value: part.input,
5469
- schema: toolSearchInputSchema
5470
- });
5471
- const execution = parsedInput.call_id != null ? "client" : "server";
5472
- input.push({
5473
- type: "tool_search_call",
5474
- id: id != null ? id : part.toolCallId,
5475
- execution,
5476
- call_id: (_s = parsedInput.call_id) != null ? _s : null,
5477
- status: "completed",
5478
- arguments: parsedInput.arguments
5479
- });
5480
- break;
5481
- }
5482
- if (resolvedToolName === "programmatic_tool_calling") {
5483
- if (store && id != null) {
5484
- input.push({ type: "item_reference", id });
5485
- break;
5486
- }
5487
- const parsedInput = await validateTypes({
5488
- value: part.input,
5489
- schema: programmaticToolCallingInputSchema
5490
- });
5491
- input.push({
5492
- type: "program",
5493
- id: id != null ? id : part.toolCallId,
5494
- call_id: part.toolCallId,
5495
- code: parsedInput.code,
5496
- fingerprint: parsedInput.fingerprint
5497
- });
5498
- break;
5499
- }
5500
- if (part.providerExecuted) {
5501
- if (store && id != null) {
5502
- input.push({ type: "item_reference", id });
5503
- }
5504
- if (store || !hasShellTool || resolvedToolName !== "shell") {
5505
- break;
5506
- }
5507
- }
5508
- const isProviderDefinedToolCall = hasLocalShellTool && resolvedToolName === "local_shell" || hasShellTool && resolvedToolName === "shell" || hasApplyPatchTool && resolvedToolName === "apply_patch" || hasComputerTool && resolvedToolName === "computer" || ((_t = customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) != null ? _t : false);
5509
- if (hasPreviousResponseId && store && id != null && isProviderDefinedToolCall) {
5510
- break;
5511
- }
5512
- if (store && id != null && isProviderDefinedToolCall) {
5513
- input.push({ type: "item_reference", id });
5514
- break;
5515
- }
5516
- if (hasLocalShellTool && resolvedToolName === "local_shell") {
5517
- const parsedInput = await validateTypes({
5518
- value: part.input,
5519
- schema: localShellInputSchema
5520
- });
5521
- input.push({
5522
- type: "local_shell_call",
5523
- call_id: part.toolCallId,
5524
- id,
5525
- action: {
5526
- type: "exec",
5527
- command: parsedInput.action.command,
5528
- timeout_ms: parsedInput.action.timeoutMs,
5529
- user: parsedInput.action.user,
5530
- working_directory: parsedInput.action.workingDirectory,
5531
- env: parsedInput.action.env
5532
- }
5533
- });
5534
- break;
5535
- }
5536
- if (hasShellTool && resolvedToolName === "shell") {
5537
- const parsedInput = await validateTypes({
5538
- value: part.input,
5539
- schema: shellInputSchema
5540
- });
5541
- input.push({
5542
- type: "shell_call",
5543
- call_id: part.toolCallId,
5544
- id,
5545
- status: "completed",
5546
- action: {
5547
- commands: parsedInput.action.commands,
5548
- timeout_ms: parsedInput.action.timeoutMs,
5549
- max_output_length: parsedInput.action.maxOutputLength
5550
- }
5551
- });
5552
- break;
5553
- }
5554
- if (hasApplyPatchTool && resolvedToolName === "apply_patch") {
5555
- const parsedInput = await validateTypes({
5556
- value: part.input,
5557
- schema: applyPatchInputSchema
5558
- });
5559
- input.push({
5560
- type: "apply_patch_call",
5561
- call_id: parsedInput.callId,
5562
- id,
5563
- status: "completed",
5564
- operation: parsedInput.operation
5565
- });
5566
- break;
5567
- }
5568
- if (hasComputerTool && resolvedToolName === "computer") {
5569
- const parsedInput = await validateTypes({
5570
- value: part.input,
5571
- schema: computerInputSchema
5572
- });
5573
- input.push({
5574
- type: "computer_call",
5575
- call_id: part.toolCallId,
5576
- id,
5577
- status: parsedInput.status,
5578
- actions: parsedInput.actions.map((action) => {
5579
- switch (action.type) {
5580
- case "click":
5581
- case "double_click":
5582
- case "move":
5583
- return {
5584
- ...action,
5585
- keys: action.keys
5586
- };
5587
- case "drag":
5588
- return {
5589
- ...action,
5590
- keys: action.keys
5591
- };
5592
- case "scroll":
5593
- return {
5594
- type: "scroll",
5595
- x: action.x,
5596
- y: action.y,
5597
- scroll_x: action.scrollX,
5598
- scroll_y: action.scrollY,
5599
- keys: action.keys
5600
- };
5601
- default:
5602
- return action;
5603
- }
5604
- }),
5605
- pending_safety_checks: parsedInput.pendingSafetyChecks.map(
5606
- (safetyCheck) => ({
5607
- id: safetyCheck.id,
5608
- code: safetyCheck.code,
5609
- message: safetyCheck.message
5610
- })
5611
- )
5612
- });
5613
- break;
5614
- }
5615
- if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
5616
- input.push({
5617
- type: "custom_tool_call",
5618
- call_id: part.toolCallId,
5619
- name: resolvedToolName,
5620
- input: typeof part.input === "string" ? part.input : JSON.stringify(part.input),
5621
- ...isAsync != null && { async: isAsync },
5622
- id
5623
- });
5624
- break;
5625
- }
5626
- input.push({
5627
- type: "function_call",
5628
- call_id: part.toolCallId,
5629
- name: resolvedToolName,
5630
- arguments: serializeToolCallArguments2(part.input),
5631
- ...isAsync != null && { async: isAsync },
5632
- ...namespace != null && { namespace },
5633
- ...caller != null && {
5634
- caller: mapToolCaller(caller)
5635
- }
5636
- });
5637
- break;
5638
- }
5639
- // assistant tool result parts are from provider-executed tools:
5640
- case "tool-result": {
5641
- if (part.output.type === "execution-denied" || part.output.type === "json" && typeof part.output.value === "object" && part.output.value != null && "type" in part.output.value && part.output.value.type === "execution-denied") {
5642
- break;
5643
- }
5644
- if (hasConversation) {
5645
- break;
5646
- }
5647
- const resolvedResultToolName = toolNameMapping.toProviderToolName(
5648
- part.toolName
5649
- );
5650
- if (part.toolName === toolSearchToolName) {
5651
- const itemId = (_z = (_y = (_v = (_u = part.providerOptions) == null ? void 0 : _u[providerOptionsName]) == null ? void 0 : _v.itemId) != null ? _y : (_x = (_w = part.providerMetadata) == null ? void 0 : _w[providerOptionsName]) == null ? void 0 : _x.itemId) != null ? _z : part.toolCallId;
5652
- if (store) {
5653
- input.push({ type: "item_reference", id: itemId });
5654
- } else if (part.output.type === "json") {
5655
- const parsedOutput = await validateTypes({
5656
- value: part.output.value,
5657
- schema: toolSearchOutputSchema
5658
- });
5659
- input.push({
5660
- type: "tool_search_output",
5661
- id: itemId,
5662
- execution: "server",
5663
- call_id: null,
5664
- status: "completed",
5665
- tools: parsedOutput.tools
5666
- });
5667
- }
5668
- break;
5669
- }
5670
- if (resolvedResultToolName === "programmatic_tool_calling") {
5671
- const itemId = (_F = (_E = (_B = (_A = part.providerOptions) == null ? void 0 : _A[providerOptionsName]) == null ? void 0 : _B.itemId) != null ? _E : (_D = (_C = part.providerMetadata) == null ? void 0 : _C[providerOptionsName]) == null ? void 0 : _D.itemId) != null ? _F : part.toolCallId;
5672
- if (store) {
5673
- input.push({ type: "item_reference", id: itemId });
5674
- } else if (part.output.type === "json") {
5675
- const parsedOutput = await validateTypes({
5676
- value: part.output.value,
5677
- schema: programmaticToolCallingOutputSchema
5678
- });
5679
- input.push({
5680
- type: "program_output",
5681
- id: itemId,
5682
- call_id: part.toolCallId,
5683
- result: parsedOutput.result,
5684
- status: parsedOutput.status
5685
- });
5686
- }
5687
- break;
5688
- }
5689
- if (hasShellTool && resolvedResultToolName === "shell") {
5690
- if (part.output.type === "json") {
5691
- const parsedOutput = await validateTypes({
5692
- value: part.output.value,
5693
- schema: shellOutputSchema
5694
- });
5695
- input.push({
5696
- type: "shell_call_output",
5697
- call_id: part.toolCallId,
5698
- output: parsedOutput.output.map((item) => ({
5699
- stdout: item.stdout,
5700
- stderr: item.stderr,
5701
- outcome: item.outcome.type === "timeout" ? { type: "timeout" } : {
5702
- type: "exit",
5703
- exit_code: item.outcome.exitCode
5704
- }
5705
- }))
5706
- });
5707
- }
5708
- break;
5709
- }
5710
- if (store) {
5711
- const itemId = (_I = (_H = (_G = part.providerOptions) == null ? void 0 : _G[providerOptionsName]) == null ? void 0 : _H.itemId) != null ? _I : part.toolCallId;
5712
- input.push({ type: "item_reference", id: itemId });
5713
- } else {
5714
- warnings.push({
5715
- type: "other",
5716
- message: `Results for OpenAI tool ${part.toolName} are not sent to the API when store is false`
5717
- });
5718
- }
5719
- break;
5720
- }
5721
- case "reasoning": {
5722
- const providerOptions2 = await parseProviderOptions6({
5723
- provider: providerOptionsName,
5724
- providerOptions: part.providerOptions,
5725
- schema: openaiResponsesReasoningProviderOptionsSchema
5726
- });
5727
- const reasoningId = providerOptions2 == null ? void 0 : providerOptions2.itemId;
5728
- if ((hasConversation || hasPreviousResponseId) && reasoningId != null) {
5729
- break;
5730
- }
5731
- if (reasoningId != null) {
5732
- const reasoningMessage = reasoningMessages[reasoningId];
5733
- if (store) {
5734
- if (reasoningMessage === void 0) {
5735
- input.push({ type: "item_reference", id: reasoningId });
5736
- reasoningMessages[reasoningId] = {
5737
- type: "reasoning",
5738
- id: reasoningId,
5739
- summary: []
5740
- };
5741
- }
5742
- } else {
5743
- const summaryParts = [];
5744
- if (part.text.length > 0) {
5745
- summaryParts.push({
5746
- type: "summary_text",
5747
- text: part.text
5748
- });
5749
- } else if (reasoningMessage !== void 0) {
5750
- warnings.push({
5751
- type: "other",
5752
- message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${JSON.stringify(part)}.`
5753
- });
5754
- }
5755
- if (reasoningMessage === void 0) {
5756
- reasoningMessages[reasoningId] = {
5757
- type: "reasoning",
5758
- id: reasoningId,
5759
- encrypted_content: providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent,
5760
- summary: summaryParts
5761
- };
5762
- input.push(reasoningMessages[reasoningId]);
5763
- } else {
5764
- reasoningMessage.summary.push(...summaryParts);
5765
- if ((providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent) != null) {
5766
- reasoningMessage.encrypted_content = providerOptions2.reasoningEncryptedContent;
5767
- }
5768
- }
5769
- }
5770
- } else {
5771
- const encryptedContent = providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent;
5772
- if (encryptedContent != null) {
5773
- const summaryParts = [];
5774
- if (part.text.length > 0) {
5775
- summaryParts.push({
5776
- type: "summary_text",
5777
- text: part.text
5778
- });
5779
- }
5780
- input.push({
5781
- type: "reasoning",
5782
- encrypted_content: encryptedContent,
5783
- summary: summaryParts
5784
- });
5785
- } else {
5786
- warnings.push({
5787
- type: "other",
5788
- message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
5789
- });
5790
- }
5791
- }
5792
- break;
5793
- }
5794
- case "custom": {
5795
- if (part.kind === "openai.compaction") {
5796
- const providerOptions2 = (_J = part.providerOptions) == null ? void 0 : _J[providerOptionsName];
5797
- const id = providerOptions2 == null ? void 0 : providerOptions2.itemId;
5798
- if (hasConversation && id != null) {
5799
- break;
5800
- }
5801
- if (store && id != null) {
5802
- input.push({ type: "item_reference", id });
5803
- break;
5804
- }
5805
- const encryptedContent = providerOptions2 == null ? void 0 : providerOptions2.encryptedContent;
5806
- if (id != null) {
5807
- input.push({
5808
- type: "compaction",
5809
- id,
5810
- encrypted_content: encryptedContent
5811
- });
5812
- }
5813
- }
5814
- break;
5815
- }
5816
- }
5817
- }
5818
- break;
5819
- }
5820
- case "tool": {
5821
- for (const part of content) {
5822
- if (part.type === "tool-approval-response") {
5823
- const approvalResponse = part;
5824
- if (processedApprovalIds.has(approvalResponse.approvalId)) {
5825
- continue;
5826
- }
5827
- processedApprovalIds.add(approvalResponse.approvalId);
5828
- if (store && !hasConversation && !hasPreviousResponseId) {
5829
- input.push({
5830
- type: "item_reference",
5831
- id: approvalResponse.approvalId
5832
- });
5833
- }
5834
- input.push({
5835
- type: "mcp_approval_response",
5836
- approval_request_id: approvalResponse.approvalId,
5837
- approve: approvalResponse.approved
5838
- });
5839
- continue;
5840
- }
5841
- const parallelToolCallMetadata = getParallelToolCallMetadata({
5842
- providerOptions: part.providerOptions,
5843
- providerOptionsName
5844
- });
5845
- const parallelToolResultGroup = parallelToolCallMetadata == null ? void 0 : parallelToolResultGroups.get(
5846
- parallelToolCallMetadata.toolCallId
5847
- );
5848
- if (parallelToolCallMetadata != null && parallelToolResultGroup != null && hasSameParallelToolCall(
5849
- parallelToolResultGroup.metadata,
5850
- parallelToolCallMetadata
5851
- )) {
5852
- if (!emittedParallelToolResults.has(
5853
- parallelToolResultGroup.metadata.toolCallId
5854
- )) {
5855
- emittedParallelToolResults.add(
5856
- parallelToolResultGroup.metadata.toolCallId
5857
- );
5858
- const toolOutputs = await Promise.all(
5859
- parallelToolResultGroup.results.map(async (result) => {
5860
- const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
5861
- output: result.output,
5862
- toolResultProviderOptions: result.providerOptions,
5863
- providerOptionsName
5864
- });
5865
- return {
5866
- output: await convertFunctionToolResultOutput({
5867
- output: result.output,
5868
- toolName: result.toolName,
5869
- outputSchemaToolNames,
5870
- providerOptionsName,
5871
- warnings
5872
- }),
5873
- promptCacheBreakpoint
5874
- };
5875
- })
5876
- );
5877
- const serializedToolOutputs = toolOutputs.map(
5878
- ({ output: output2 }) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
5879
- );
5880
- const hasPromptCacheBreakpoint = toolOutputs.some(
5881
- ({ promptCacheBreakpoint }) => promptCacheBreakpoint != null
5882
- );
5883
- input.push({
5884
- type: "function_call_output",
5885
- call_id: parallelToolResultGroup.metadata.toolCallId,
5886
- // The internal wrapper returns one output containing the child
5887
- // results in the same order as the original tool_uses array.
5888
- output: hasPromptCacheBreakpoint ? serializedToolOutputs.map((text, index) => ({
5889
- type: "input_text",
5890
- text: index === 0 ? text : `
5891
- ${text}`,
5892
- ...toolOutputs[index].promptCacheBreakpoint != null && {
5893
- prompt_cache_breakpoint: toolOutputs[index].promptCacheBreakpoint
5894
- }
5895
- })) : serializedToolOutputs.join("\n")
5896
- });
5897
- }
5898
- continue;
5899
- }
5900
- const output = part.output;
5901
- if (output.type === "execution-denied") {
5902
- const approvalId = (_L = (_K = output.providerOptions) == null ? void 0 : _K.openai) == null ? void 0 : _L.approvalId;
5903
- if (approvalId) {
5904
- continue;
5905
- }
5906
- }
5907
- const resolvedToolName = toolNameMapping.toProviderToolName(
5908
- part.toolName
5909
- );
5910
- if (part.toolName === toolSearchToolName && output.type === "json") {
5911
- const parsedOutput = await validateTypes({
5912
- value: output.value,
5913
- schema: toolSearchOutputSchema
5914
- });
5915
- input.push({
5916
- type: "tool_search_output",
5917
- execution: "client",
5918
- call_id: part.toolCallId,
5919
- status: "completed",
5920
- tools: parsedOutput.tools
5921
- });
5922
- continue;
5923
- }
5924
- if (hasLocalShellTool && resolvedToolName === "local_shell" && output.type === "json") {
5925
- const parsedOutput = await validateTypes({
5926
- value: output.value,
5927
- schema: localShellOutputSchema
5928
- });
5929
- input.push({
5930
- type: "local_shell_call_output",
5931
- call_id: part.toolCallId,
5932
- output: parsedOutput.output
5933
- });
5934
- continue;
5935
- }
5936
- if (hasShellTool && resolvedToolName === "shell" && output.type === "json") {
5937
- const parsedOutput = await validateTypes({
5938
- value: output.value,
5939
- schema: shellOutputSchema
5940
- });
5941
- input.push({
5942
- type: "shell_call_output",
5943
- call_id: part.toolCallId,
5944
- output: parsedOutput.output.map((item) => ({
5945
- stdout: item.stdout,
5946
- stderr: item.stderr,
5947
- outcome: item.outcome.type === "timeout" ? { type: "timeout" } : {
5948
- type: "exit",
5949
- exit_code: item.outcome.exitCode
5950
- }
5951
- }))
5952
- });
5953
- continue;
5954
- }
5955
- if (hasApplyPatchTool && part.toolName === "apply_patch" && output.type === "json") {
5956
- const parsedOutput = await validateTypes({
5957
- value: output.value,
5958
- schema: applyPatchOutputSchema
5959
- });
5960
- input.push({
5961
- type: "apply_patch_call_output",
5962
- call_id: part.toolCallId,
5963
- status: parsedOutput.status,
5964
- output: parsedOutput.output
5965
- });
5966
- continue;
5967
- }
5968
- if (hasComputerTool && resolvedToolName === "computer" && output.type === "json") {
5969
- const parsedOutput = await validateTypes({
5970
- value: output.value,
5971
- schema: computerOutputSchema
5972
- });
5973
- input.push({
5974
- type: "computer_call_output",
5975
- call_id: part.toolCallId,
5976
- output: {
5977
- type: "computer_screenshot",
5978
- image_url: parsedOutput.output.imageUrl,
5979
- file_id: parsedOutput.output.fileId,
5980
- detail: parsedOutput.output.detail
5981
- },
5982
- acknowledged_safety_checks: (_M = parsedOutput.acknowledgedSafetyChecks) == null ? void 0 : _M.map((safetyCheck) => ({
5983
- id: safetyCheck.id,
5984
- code: safetyCheck.code,
5985
- message: safetyCheck.message
5986
- }))
5987
- });
5988
- continue;
5989
- }
5990
- if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
5991
- const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
5992
- output,
5993
- toolResultProviderOptions: part.providerOptions,
5994
- providerOptionsName
5995
- });
5996
- const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
5997
- {
5998
- type: "input_text",
5999
- text: value,
6000
- prompt_cache_breakpoint: promptCacheBreakpoint
6001
- }
6002
- ];
6003
- let outputValue;
6004
- switch (output.type) {
6005
- case "text":
6006
- case "error-text":
6007
- outputValue = convertScalarOutput(output.value);
6008
- break;
6009
- case "execution-denied":
6010
- outputValue = convertScalarOutput(
6011
- (_N = output.reason) != null ? _N : "Tool call execution denied."
6012
- );
6013
- break;
6014
- case "json":
6015
- case "error-json":
6016
- outputValue = convertScalarOutput(JSON.stringify(output.value));
6017
- break;
6018
- case "content":
6019
- outputValue = output.value.map((item) => {
6020
- var _a3, _b2, _c2;
6021
- const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
6022
- item.providerOptions,
6023
- providerOptionsName
6024
- );
6025
- switch (item.type) {
6026
- case "text":
6027
- return {
6028
- type: "input_text",
6029
- text: item.text,
6030
- ...promptCacheBreakpoint2 != null && {
6031
- prompt_cache_breakpoint: promptCacheBreakpoint2
6032
- }
6033
- };
6034
- case "file": {
6035
- const topLevel = getTopLevelMediaType2(item.mediaType);
6036
- const imageDetail = (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail;
6037
- if (item.data.type === "data") {
6038
- const fullMediaType = resolveFullMediaType2({
6039
- part: item
6040
- });
6041
- if (topLevel === "image") {
6042
- return {
6043
- type: "input_image",
6044
- image_url: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
6045
- detail: imageDetail,
6046
- ...promptCacheBreakpoint2 != null && {
6047
- prompt_cache_breakpoint: promptCacheBreakpoint2
6048
- }
6049
- };
6050
- }
6051
- return {
6052
- type: "input_file",
6053
- filename: (_c2 = item.filename) != null ? _c2 : "data",
6054
- file_data: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
6055
- ...promptCacheBreakpoint2 != null && {
6056
- prompt_cache_breakpoint: promptCacheBreakpoint2
6057
- }
6058
- };
6059
- }
6060
- if (item.data.type === "url") {
6061
- if (topLevel === "image") {
6062
- return {
6063
- type: "input_image",
6064
- image_url: item.data.url.toString(),
6065
- detail: imageDetail,
6066
- ...promptCacheBreakpoint2 != null && {
6067
- prompt_cache_breakpoint: promptCacheBreakpoint2
6068
- }
6069
- };
6070
- }
6071
- return {
6072
- type: "input_file",
6073
- file_url: item.data.url.toString(),
6074
- ...promptCacheBreakpoint2 != null && {
6075
- prompt_cache_breakpoint: promptCacheBreakpoint2
6076
- }
6077
- };
6078
- }
6079
- warnings.push({
6080
- type: "other",
6081
- message: `unsupported custom tool content part type: ${item.type} with data type: ${item.data.type}`
6082
- });
6083
- return void 0;
6084
- }
6085
- default:
6086
- warnings.push({
6087
- type: "other",
6088
- message: `unsupported custom tool content part type: ${item.type}`
6089
- });
6090
- return void 0;
6091
- }
6092
- }).filter(isNonNullable);
6093
- break;
6094
- default:
6095
- outputValue = "";
6096
- }
6097
- input.push({
6098
- type: "custom_tool_call_output",
6099
- call_id: part.toolCallId,
6100
- output: outputValue
6101
- });
6102
- continue;
6103
- }
6104
- const resultCaller = (_P = (_O = part.providerOptions) == null ? void 0 : _O[providerOptionsName]) == null ? void 0 : _P.caller;
6105
- if (output.type === "execution-denied" && ((resultCaller == null ? void 0 : resultCaller.type) === "program" || programmaticToolCallIds.has(part.toolCallId))) {
6106
- throw new UnsupportedFunctionalityError5({
6107
- functionality: "execution-denied results for programmatic tool calls"
6108
- });
6109
- }
6110
- const contentValue = await convertFunctionToolResultOutput({
6111
- output,
6112
- toolName: part.toolName,
6113
- outputSchemaToolNames,
6114
- promptCacheBreakpoint: getScalarToolResultPromptCacheBreakpoint({
6115
- output,
6116
- toolResultProviderOptions: part.providerOptions,
6117
- providerOptionsName
6118
- }),
6119
- providerOptionsName,
6120
- warnings
6121
- });
6122
- const caller = mapToolCaller(resultCaller);
6123
- input.push({
6124
- type: "function_call_output",
6125
- call_id: part.toolCallId,
6126
- output: contentValue,
6127
- ...caller != null && { caller }
6128
- });
6129
- }
6130
- break;
6131
- }
6132
- default: {
6133
- const _exhaustiveCheck = role;
6134
- throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
6135
- }
6136
- }
6137
- }
6138
- if (!store && input.some(
6139
- (item) => "type" in item && item.type === "reasoning" && item.encrypted_content == null
6140
- )) {
6141
- warnings.push({
6142
- type: "other",
6143
- message: "Reasoning parts without encrypted content are not supported when store is false. Skipping reasoning parts."
6144
- });
6145
- input = input.filter(
6146
- (item) => !("type" in item) || item.type !== "reasoning" || item.encrypted_content != null
6147
- );
6148
- }
6149
- return { input, warnings };
6150
- }
6151
- var openaiResponsesReasoningProviderOptionsSchema = z26.object({
6152
- itemId: z26.string().nullish(),
6153
- reasoningEncryptedContent: z26.string().nullish()
6154
- });
6155
-
6156
- // src/responses/openai-responses-language-model-options.ts
4913
+ // src/responses/openai-responses-language-model-options.ts
6157
4914
  import {
6158
4915
  lazySchema as lazySchema25,
6159
4916
  zodSchema as zodSchema25
6160
4917
  } from "@ai-sdk/provider-utils";
6161
- import { z as z27 } from "zod/v4";
4918
+ import { z as z26 } from "zod/v4";
6162
4919
  var TOP_LOGPROBS_MAX = 20;
6163
4920
  var openaiResponsesReasoningModelIds = [
6164
4921
  "o1",
@@ -6234,7 +4991,7 @@ var openaiResponsesModelIds = [
6234
4991
  ];
6235
4992
  var openaiLanguageModelResponsesOptionsSchema = lazySchema25(
6236
4993
  () => zodSchema25(
6237
- z27.object({
4994
+ z26.object({
6238
4995
  /**
6239
4996
  * The ID of the OpenAI Conversation to continue.
6240
4997
  * You must create a conversation first via the OpenAI API.
@@ -6242,13 +4999,13 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema25(
6242
4999
  * Defaults to `undefined`.
6243
5000
  * @see https://platform.openai.com/docs/api-reference/conversations/create
6244
5001
  */
6245
- conversation: z27.string().nullish(),
5002
+ conversation: z26.string().nullish(),
6246
5003
  /**
6247
5004
  * The set of extra fields to include in the response (advanced, usually not needed).
6248
5005
  * Example values: 'reasoning.encrypted_content', 'file_search_call.results', 'web_search_call.results', 'message.output_text.logprobs'.
6249
5006
  */
6250
- include: z27.array(
6251
- z27.enum([
5007
+ include: z26.array(
5008
+ z26.enum([
6252
5009
  "reasoning.encrypted_content",
6253
5010
  // handled internally by default, only needed for unknown reasoning models
6254
5011
  "file_search_call.results",
@@ -6263,13 +5020,13 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema25(
6263
5020
  *
6264
5021
  * Defaults to `true`.
6265
5022
  */
6266
- includeWebSearchSources: z27.boolean().optional(),
5023
+ includeWebSearchSources: z26.boolean().optional(),
6267
5024
  /**
6268
5025
  * Instructions for the model.
6269
5026
  * They can be used to change the system or developer message when continuing a conversation using the `previousResponseId` option.
6270
5027
  * Defaults to `undefined`.
6271
5028
  */
6272
- instructions: z27.string().nullish(),
5029
+ instructions: z26.string().nullish(),
6273
5030
  /**
6274
5031
  * Return the log probabilities of the tokens. Including logprobs will increase
6275
5032
  * the response size and can slow down response times. However, it can
@@ -6284,38 +5041,38 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema25(
6284
5041
  * @see https://platform.openai.com/docs/api-reference/responses/create
6285
5042
  * @see https://cookbook.openai.com/examples/using_logprobs
6286
5043
  */
6287
- logprobs: z27.union([z27.boolean(), z27.number().min(1).max(TOP_LOGPROBS_MAX)]).optional(),
5044
+ logprobs: z26.union([z26.boolean(), z26.number().min(1).max(TOP_LOGPROBS_MAX)]).optional(),
6288
5045
  /**
6289
5046
  * The maximum number of total calls to built-in tools that can be processed in a response.
6290
5047
  * This maximum number applies across all built-in tool calls, not per individual tool.
6291
5048
  * Any further attempts to call a tool by the model will be ignored.
6292
5049
  */
6293
- maxToolCalls: z27.number().nullish(),
5050
+ maxToolCalls: z26.number().nullish(),
6294
5051
  /**
6295
5052
  * Additional metadata to store with the generation.
6296
5053
  */
6297
- metadata: z27.any().nullish(),
5054
+ metadata: z26.any().nullish(),
6298
5055
  /**
6299
5056
  * Whether to use parallel tool calls. Defaults to `true`.
6300
5057
  */
6301
- parallelToolCalls: z27.boolean().nullish(),
5058
+ parallelToolCalls: z26.boolean().nullish(),
6302
5059
  /**
6303
5060
  * The ID of the previous response. You can use it to continue a conversation.
6304
5061
  * Defaults to `undefined`.
6305
5062
  */
6306
- previousResponseId: z27.string().nullish(),
5063
+ previousResponseId: z26.string().nullish(),
6307
5064
  /**
6308
5065
  * Sets a cache key to tie this prompt to cached prefixes for better caching performance.
6309
5066
  */
6310
- promptCacheKey: z27.string().nullish(),
5067
+ promptCacheKey: z26.string().nullish(),
6311
5068
  /**
6312
5069
  * Prompt cache behavior for GPT-5.6 and later models.
6313
5070
  * `mode` controls whether OpenAI also places an implicit breakpoint.
6314
5071
  * `ttl` sets the minimum cache lifetime and currently only supports 30 minutes.
6315
5072
  */
6316
- promptCacheOptions: z27.object({
6317
- mode: z27.enum(["implicit", "explicit"]).optional(),
6318
- ttl: z27.literal("30m").optional()
5073
+ promptCacheOptions: z26.object({
5074
+ mode: z26.enum(["implicit", "explicit"]).optional(),
5075
+ ttl: z26.literal("30m").optional()
6319
5076
  }).optional(),
6320
5077
  /**
6321
5078
  * The retention policy for the prompt cache.
@@ -6327,14 +5084,14 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema25(
6327
5084
  *
6328
5085
  * @default 'in_memory'
6329
5086
  */
6330
- promptCacheRetention: z27.enum(["in_memory", "24h"]).nullish(),
5087
+ promptCacheRetention: z26.enum(["in_memory", "24h"]).nullish(),
6331
5088
  /**
6332
5089
  * Reasoning effort for reasoning models. Defaults to `medium`. If you use
6333
5090
  * `providerOptions` to set the `reasoningEffort` option, this model setting will be ignored.
6334
5091
  * GPT-5.6 supports 'none' | 'low' | 'medium' | 'high' | 'xhigh' | 'max'.
6335
5092
  * Supported values vary by model.
6336
5093
  */
6337
- reasoningEffort: z27.string().nullish(),
5094
+ reasoningEffort: z26.string().nullish(),
6338
5095
  /**
6339
5096
  * Updates the reasoning effort for GPT-6 and later models starting with this response
6340
5097
  * without changing the request-level reasoning effort. This preserves the
@@ -6343,28 +5100,28 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema25(
6343
5100
  * Only supported by GPT-6 and later models in standard, single-agent mode. Cannot be
6344
5101
  * combined with automatic compaction or automatic truncation.
6345
5102
  */
6346
- reasoningEffortUpdate: z27.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
5103
+ reasoningEffortUpdate: z26.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
6347
5104
  /**
6348
5105
  * Controls how much model work GPT-5.6 performs before returning a final answer.
6349
5106
  * `standard` is the default. `pro` increases quality, latency, and token usage.
6350
5107
  */
6351
- reasoningMode: z27.enum(["standard", "pro"]).optional(),
5108
+ reasoningMode: z26.enum(["standard", "pro"]).optional(),
6352
5109
  /**
6353
5110
  * Controls which available reasoning items GPT-5.6 can use.
6354
5111
  * `auto` uses the model default, `current_turn` excludes reasoning from earlier
6355
5112
  * turns, and `all_turns` makes compatible earlier reasoning available.
6356
5113
  */
6357
- reasoningContext: z27.enum(["auto", "current_turn", "all_turns"]).optional(),
5114
+ reasoningContext: z26.enum(["auto", "current_turn", "all_turns"]).optional(),
6358
5115
  /**
6359
5116
  * Controls reasoning summary output from the model.
6360
5117
  * Set to "auto" to automatically receive the richest level available,
6361
5118
  * or "detailed" for comprehensive summaries.
6362
5119
  */
6363
- reasoningSummary: z27.string().nullish(),
5120
+ reasoningSummary: z26.string().nullish(),
6364
5121
  /**
6365
5122
  * The identifier for safety monitoring and tracking.
6366
5123
  */
6367
- safetyIdentifier: z27.string().nullish(),
5124
+ safetyIdentifier: z26.string().nullish(),
6368
5125
  /**
6369
5126
  * Service tier for the request.
6370
5127
  * Set to 'flex' for 50% cheaper processing at the cost of increased latency (available for o3, o4-mini, and gpt-5 models).
@@ -6374,11 +5131,11 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema25(
6374
5131
  *
6375
5132
  * Defaults to 'auto'.
6376
5133
  */
6377
- serviceTier: z27.enum(["auto", "flex", "priority", "fast", "ultrafast", "default"]).nullish(),
5134
+ serviceTier: z26.enum(["auto", "flex", "priority", "fast", "ultrafast", "default"]).nullish(),
6378
5135
  /**
6379
5136
  * Whether to store the generation. Defaults to `true`.
6380
5137
  */
6381
- store: z27.boolean().nullish(),
5138
+ store: z26.boolean().nullish(),
6382
5139
  /**
6383
5140
  * Whether to pass through non-image file types as generic input files.
6384
5141
  *
@@ -6386,30 +5143,30 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema25(
6386
5143
  * Enable this when the target OpenAI Responses model supports additional
6387
5144
  * file media types, such as text/csv.
6388
5145
  */
6389
- passThroughUnsupportedFiles: z27.boolean().optional(),
5146
+ passThroughUnsupportedFiles: z26.boolean().optional(),
6390
5147
  /**
6391
5148
  * Whether to use strict JSON schema validation.
6392
5149
  * Defaults to `true`.
6393
5150
  */
6394
- strictJsonSchema: z27.boolean().nullish(),
5151
+ strictJsonSchema: z26.boolean().nullish(),
6395
5152
  /**
6396
5153
  * Controls the verbosity of the model's responses. Lower values ('low') will result
6397
5154
  * in more concise responses, while higher values ('high') will result in more verbose responses.
6398
5155
  * Valid values: 'low', 'medium', 'high'.
6399
5156
  */
6400
- textVerbosity: z27.enum(["low", "medium", "high"]).nullish(),
5157
+ textVerbosity: z26.enum(["low", "medium", "high"]).nullish(),
6401
5158
  /**
6402
5159
  * Controls output truncation. 'auto' (default) performs truncation automatically;
6403
5160
  * 'disabled' turns truncation off.
6404
5161
  */
6405
- truncation: z27.enum(["auto", "disabled"]).nullish(),
5162
+ truncation: z26.enum(["auto", "disabled"]).nullish(),
6406
5163
  /**
6407
5164
  * A unique identifier representing your end-user, which can help OpenAI to
6408
5165
  * monitor and detect abuse.
6409
5166
  * Defaults to `undefined`.
6410
5167
  * @see https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids
6411
5168
  */
6412
- user: z27.string().nullish(),
5169
+ user: z26.string().nullish(),
6413
5170
  /**
6414
5171
  * Override the system message mode for this model.
6415
5172
  * - 'system': Use the 'system' role for system messages (default for most models)
@@ -6418,7 +5175,7 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema25(
6418
5175
  *
6419
5176
  * If not specified, the mode is automatically determined based on the model.
6420
5177
  */
6421
- systemMessageMode: z27.enum(["system", "developer", "remove"]).optional(),
5178
+ systemMessageMode: z26.enum(["system", "developer", "remove"]).optional(),
6422
5179
  /**
6423
5180
  * Force treating this model as a reasoning model.
6424
5181
  *
@@ -6428,21 +5185,21 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema25(
6428
5185
  * When enabled, the SDK applies reasoning-model parameter compatibility rules
6429
5186
  * and defaults `systemMessageMode` to `developer` unless overridden.
6430
5187
  */
6431
- forceReasoning: z27.boolean().optional(),
5188
+ forceReasoning: z26.boolean().optional(),
6432
5189
  /**
6433
5190
  * Enable server-side context management (compaction).
6434
5191
  */
6435
- contextManagement: z27.array(
6436
- z27.object({
6437
- type: z27.literal("compaction"),
6438
- compactThreshold: z27.number()
5192
+ contextManagement: z26.array(
5193
+ z26.object({
5194
+ type: z26.literal("compaction"),
5195
+ compactThreshold: z26.number()
6439
5196
  })
6440
5197
  ).nullish(),
6441
5198
  /**
6442
5199
  * Request explicit server-side compaction by appending a
6443
5200
  * `compaction_trigger` item to the Responses input.
6444
5201
  */
6445
- compactionTrigger: z27.boolean().optional(),
5202
+ compactionTrigger: z26.boolean().optional(),
6446
5203
  /**
6447
5204
  * Restrict the callable tools to a subset while keeping the full tools
6448
5205
  * list intact, so prompt caching is preserved across requests with
@@ -6451,16 +5208,1303 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema25(
6451
5208
  * When set, this overrides the request-level `toolChoice` and emits
6452
5209
  * `tool_choice: { type: "allowed_tools", mode, tools }` on the wire.
6453
5210
  *
6454
- * @see https://developers.openai.com/api/reference/resources/responses/methods/create#(resource)%20responses%20%3E%20(model)%20tool_choice_allowed%20%3E%20(schema)
5211
+ * @see https://developers.openai.com/api/reference/resources/responses/methods/create#(resource)%20responses%20%3E%20(model)%20tool_choice_allowed%20%3E%20(schema)
5212
+ */
5213
+ allowedTools: z26.object({
5214
+ toolNames: z26.array(z26.string()).min(1),
5215
+ mode: z26.enum(["auto", "required"]).optional()
5216
+ }).optional()
5217
+ })
5218
+ )
5219
+ );
5220
+ var openaiResponsesSystemMessageOptionsSchema = lazySchema25(
5221
+ () => zodSchema25(
5222
+ z26.object({
5223
+ /**
5224
+ * Emit a configuration update at this position in Responses history.
5225
+ * Requires empty system message content and the same supported
5226
+ * configuration as the request-level reasoningEffortUpdate option.
5227
+ * Unsupported historical updates throw instead of being omitted.
5228
+ *
5229
+ * @see https://developers.openai.com/api/docs/guides/reasoning#change-reasoning-mid-conversation
6455
5230
  */
6456
- allowedTools: z27.object({
6457
- toolNames: z27.array(z27.string()).min(1),
6458
- mode: z27.enum(["auto", "required"]).optional()
6459
- }).optional()
5231
+ reasoningEffortUpdate: z26.enum(["low", "medium", "high", "xhigh", "max"]).optional()
6460
5232
  })
6461
5233
  )
6462
5234
  );
6463
5235
 
5236
+ // src/responses/expand-parallel-tool-call.ts
5237
+ import {
5238
+ isJSONObject
5239
+ } from "@ai-sdk/provider";
5240
+ import { safeParseJSON } from "@ai-sdk/provider-utils";
5241
+ var parallelToolName = "parallel";
5242
+ var recipientNamePrefix = "functions.";
5243
+ function getParallelToolCallMetadata({
5244
+ providerOptions,
5245
+ providerOptionsName
5246
+ }) {
5247
+ var _a2;
5248
+ const metadata = (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.parallelToolCall;
5249
+ if (!isJSONObject(metadata) || typeof metadata.itemId !== "string" || typeof metadata.toolCallId !== "string" || typeof metadata.toolName !== "string" || typeof metadata.input !== "string" || typeof metadata.index !== "number" || !Number.isInteger(metadata.index) || typeof metadata.count !== "number" || !Number.isInteger(metadata.count) || metadata.index < 0 || metadata.count <= metadata.index) {
5250
+ return void 0;
5251
+ }
5252
+ return metadata;
5253
+ }
5254
+ function isUndeclaredParallelToolCall({
5255
+ toolName,
5256
+ tools
5257
+ }) {
5258
+ return toolName === parallelToolName && !tools.some((tool) => tool.name === parallelToolName);
5259
+ }
5260
+ async function expandParallelToolCall({
5261
+ toolCall,
5262
+ tools,
5263
+ providerOptionsName,
5264
+ itemId
5265
+ }) {
5266
+ if (!isUndeclaredParallelToolCall({ toolName: toolCall.toolName, tools })) {
5267
+ return void 0;
5268
+ }
5269
+ const parsedInput = await safeParseJSON({ text: toolCall.input });
5270
+ if (!parsedInput.success || !isJSONObject(parsedInput.value)) {
5271
+ return void 0;
5272
+ }
5273
+ const toolUses = parsedInput.value.tool_uses;
5274
+ if (!Array.isArray(toolUses) || toolUses.length === 0) {
5275
+ return void 0;
5276
+ }
5277
+ const availableToolNames = new Set(tools.map((tool) => tool.name));
5278
+ const expandedToolCalls = [];
5279
+ for (const [index, toolUse] of toolUses.entries()) {
5280
+ if (!isJSONObject(toolUse)) {
5281
+ return void 0;
5282
+ }
5283
+ const recipientName = toolUse.recipient_name;
5284
+ const parameters = toolUse.parameters;
5285
+ if (typeof recipientName !== "string" || !recipientName.startsWith(recipientNamePrefix) || !isJSONObject(parameters)) {
5286
+ return void 0;
5287
+ }
5288
+ const toolName = recipientName.slice(recipientNamePrefix.length);
5289
+ if (toolName.length === 0 || !availableToolNames.has(toolName)) {
5290
+ return void 0;
5291
+ }
5292
+ expandedToolCalls.push({
5293
+ type: "tool-call",
5294
+ toolCallId: `${toolCall.toolCallId}_${index}`,
5295
+ toolName,
5296
+ input: JSON.stringify(parameters),
5297
+ providerMetadata: {
5298
+ [providerOptionsName]: {
5299
+ parallelToolCall: {
5300
+ itemId,
5301
+ toolCallId: toolCall.toolCallId,
5302
+ toolName: toolCall.toolName,
5303
+ input: toolCall.input,
5304
+ index,
5305
+ count: toolUses.length
5306
+ }
5307
+ }
5308
+ }
5309
+ });
5310
+ }
5311
+ return expandedToolCalls;
5312
+ }
5313
+
5314
+ // src/responses/convert-to-openai-responses-input.ts
5315
+ function serializeToolCallArguments2(input) {
5316
+ return JSON.stringify(input === void 0 ? {} : input);
5317
+ }
5318
+ function mapToolCaller(caller) {
5319
+ return caller == null ? void 0 : caller.type === "program" ? { type: "program", caller_id: caller.callerId } : caller;
5320
+ }
5321
+ async function convertFunctionToolResultOutput({
5322
+ output,
5323
+ toolName,
5324
+ outputSchemaToolNames,
5325
+ promptCacheBreakpoint,
5326
+ providerOptionsName,
5327
+ warnings
5328
+ }) {
5329
+ var _a2;
5330
+ const hasOutputSchema = outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.has(toolName);
5331
+ const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
5332
+ {
5333
+ type: "input_text",
5334
+ text: value,
5335
+ prompt_cache_breakpoint: promptCacheBreakpoint
5336
+ }
5337
+ ];
5338
+ switch (output.type) {
5339
+ case "text":
5340
+ case "error-text":
5341
+ return convertScalarOutput(
5342
+ hasOutputSchema ? JSON.stringify(output.value) : output.value
5343
+ );
5344
+ case "execution-denied": {
5345
+ const reason = (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
5346
+ return convertScalarOutput(
5347
+ hasOutputSchema ? JSON.stringify(reason) : reason
5348
+ );
5349
+ }
5350
+ case "json":
5351
+ case "error-json":
5352
+ return convertScalarOutput(JSON.stringify(output.value));
5353
+ case "content":
5354
+ return output.value.map((item) => {
5355
+ var _a3, _b, _c;
5356
+ const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
5357
+ item.providerOptions,
5358
+ providerOptionsName
5359
+ );
5360
+ switch (item.type) {
5361
+ case "text": {
5362
+ return {
5363
+ type: "input_text",
5364
+ text: item.text,
5365
+ ...promptCacheBreakpoint2 != null && {
5366
+ prompt_cache_breakpoint: promptCacheBreakpoint2
5367
+ }
5368
+ };
5369
+ }
5370
+ case "file": {
5371
+ const topLevel = getTopLevelMediaType2(item.mediaType);
5372
+ const imageDetail = (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail;
5373
+ if (item.data.type === "reference") {
5374
+ const fileId = resolveProviderReference2({
5375
+ reference: item.data.reference,
5376
+ provider: providerOptionsName
5377
+ });
5378
+ if (topLevel === "image") {
5379
+ return {
5380
+ type: "input_image",
5381
+ file_id: fileId,
5382
+ detail: imageDetail,
5383
+ ...promptCacheBreakpoint2 != null && {
5384
+ prompt_cache_breakpoint: promptCacheBreakpoint2
5385
+ }
5386
+ };
5387
+ }
5388
+ return {
5389
+ type: "input_file",
5390
+ file_id: fileId,
5391
+ ...promptCacheBreakpoint2 != null && {
5392
+ prompt_cache_breakpoint: promptCacheBreakpoint2
5393
+ }
5394
+ };
5395
+ }
5396
+ if (item.data.type === "data") {
5397
+ const fullMediaType = resolveFullMediaType2({ part: item });
5398
+ if (topLevel === "image") {
5399
+ return {
5400
+ type: "input_image",
5401
+ image_url: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
5402
+ detail: imageDetail,
5403
+ ...promptCacheBreakpoint2 != null && {
5404
+ prompt_cache_breakpoint: promptCacheBreakpoint2
5405
+ }
5406
+ };
5407
+ }
5408
+ return {
5409
+ type: "input_file",
5410
+ filename: (_c = item.filename) != null ? _c : "data",
5411
+ file_data: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
5412
+ ...promptCacheBreakpoint2 != null && {
5413
+ prompt_cache_breakpoint: promptCacheBreakpoint2
5414
+ }
5415
+ };
5416
+ }
5417
+ if (item.data.type === "url") {
5418
+ if (topLevel === "image") {
5419
+ return {
5420
+ type: "input_image",
5421
+ image_url: item.data.url.toString(),
5422
+ detail: imageDetail,
5423
+ ...promptCacheBreakpoint2 != null && {
5424
+ prompt_cache_breakpoint: promptCacheBreakpoint2
5425
+ }
5426
+ };
5427
+ }
5428
+ return {
5429
+ type: "input_file",
5430
+ file_url: item.data.url.toString(),
5431
+ ...promptCacheBreakpoint2 != null && {
5432
+ prompt_cache_breakpoint: promptCacheBreakpoint2
5433
+ }
5434
+ };
5435
+ }
5436
+ warnings.push({
5437
+ type: "other",
5438
+ message: `unsupported tool content part type: ${item.type} with data type: ${item.data.type}`
5439
+ });
5440
+ return void 0;
5441
+ }
5442
+ default: {
5443
+ warnings.push({
5444
+ type: "other",
5445
+ message: `unsupported tool content part type: ${item.type}`
5446
+ });
5447
+ return void 0;
5448
+ }
5449
+ }
5450
+ }).filter(isNonNullable);
5451
+ }
5452
+ }
5453
+ function hasSameParallelToolCall(first, second) {
5454
+ return first.itemId === second.itemId && first.toolCallId === second.toolCallId && first.toolName === second.toolName && first.input === second.input && first.count === second.count;
5455
+ }
5456
+ function collectCompleteParallelToolResultGroups({
5457
+ prompt,
5458
+ providerOptionsName
5459
+ }) {
5460
+ const pendingGroups = /* @__PURE__ */ new Map();
5461
+ for (const message of prompt) {
5462
+ if (message.role !== "tool") {
5463
+ continue;
5464
+ }
5465
+ for (const part of message.content) {
5466
+ if (part.type !== "tool-result") {
5467
+ continue;
5468
+ }
5469
+ const metadata = getParallelToolCallMetadata({
5470
+ providerOptions: part.providerOptions,
5471
+ providerOptionsName
5472
+ });
5473
+ if (metadata == null) {
5474
+ continue;
5475
+ }
5476
+ const existing = pendingGroups.get(metadata.toolCallId);
5477
+ if (existing == null) {
5478
+ pendingGroups.set(metadata.toolCallId, {
5479
+ metadata,
5480
+ results: /* @__PURE__ */ new Map([[metadata.index, part]]),
5481
+ invalid: false
5482
+ });
5483
+ continue;
5484
+ }
5485
+ if (!hasSameParallelToolCall(existing.metadata, metadata) || existing.results.has(metadata.index)) {
5486
+ existing.invalid = true;
5487
+ continue;
5488
+ }
5489
+ existing.results.set(metadata.index, part);
5490
+ }
5491
+ }
5492
+ const completeGroups = /* @__PURE__ */ new Map();
5493
+ for (const [toolCallId, group] of pendingGroups) {
5494
+ if (group.invalid || group.results.size !== group.metadata.count) {
5495
+ continue;
5496
+ }
5497
+ const results = Array.from(
5498
+ { length: group.metadata.count },
5499
+ (_, index) => group.results.get(index)
5500
+ );
5501
+ if (results.every(isNonNullable)) {
5502
+ completeGroups.set(toolCallId, {
5503
+ metadata: group.metadata,
5504
+ results
5505
+ });
5506
+ }
5507
+ }
5508
+ return completeGroups;
5509
+ }
5510
+ function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
5511
+ var _a2;
5512
+ return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
5513
+ }
5514
+ function getScalarToolResultPromptCacheBreakpoint({
5515
+ output,
5516
+ toolResultProviderOptions,
5517
+ providerOptionsName
5518
+ }) {
5519
+ var _a2;
5520
+ return output.type === "content" ? void 0 : (_a2 = getPromptCacheBreakpoint2(output.providerOptions, providerOptionsName)) != null ? _a2 : getPromptCacheBreakpoint2(
5521
+ toolResultProviderOptions,
5522
+ providerOptionsName
5523
+ );
5524
+ }
5525
+ function isFileId(data, prefixes) {
5526
+ if (!prefixes) return false;
5527
+ return prefixes.some((prefix) => data.startsWith(prefix));
5528
+ }
5529
+ async function convertToOpenAIResponsesInput({
5530
+ prompt,
5531
+ toolNameMapping,
5532
+ systemMessageMode,
5533
+ providerOptionsName,
5534
+ explicitMessageItemType = false,
5535
+ fileIdPrefixes,
5536
+ passThroughUnsupportedFiles = false,
5537
+ store,
5538
+ hasConversation = false,
5539
+ hasPreviousResponseId = false,
5540
+ hasLocalShellTool = false,
5541
+ hasShellTool = false,
5542
+ hasApplyPatchTool = false,
5543
+ hasComputerTool = false,
5544
+ toolSearchToolName,
5545
+ customProviderToolNames,
5546
+ outputSchemaToolNames,
5547
+ configurationUpdateUnsupportedReason
5548
+ }) {
5549
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P;
5550
+ let input = [];
5551
+ const warnings = [];
5552
+ const processedApprovalIds = /* @__PURE__ */ new Set();
5553
+ const programmaticToolCallIds = /* @__PURE__ */ new Set();
5554
+ const parallelToolResultGroups = hasConversation || hasPreviousResponseId ? collectCompleteParallelToolResultGroups({
5555
+ prompt,
5556
+ providerOptionsName
5557
+ }) : /* @__PURE__ */ new Map();
5558
+ const emittedParallelToolCalls = /* @__PURE__ */ new Set();
5559
+ const emittedParallelToolResults = /* @__PURE__ */ new Set();
5560
+ for (const { role, content, providerOptions } of prompt) {
5561
+ switch (role) {
5562
+ case "system": {
5563
+ let options = await parseProviderOptions6({
5564
+ provider: providerOptionsName,
5565
+ providerOptions,
5566
+ schema: openaiResponsesSystemMessageOptionsSchema
5567
+ });
5568
+ if (options == null && providerOptionsName !== "openai") {
5569
+ options = await parseProviderOptions6({
5570
+ provider: "openai",
5571
+ providerOptions,
5572
+ schema: openaiResponsesSystemMessageOptionsSchema
5573
+ });
5574
+ }
5575
+ const effort = options == null ? void 0 : options.reasoningEffortUpdate;
5576
+ if (effort != null) {
5577
+ const unsupportedReason = content !== "" ? "Message-level reasoningEffortUpdate requires empty system message content." : configurationUpdateUnsupportedReason;
5578
+ if (unsupportedReason != null) {
5579
+ throw new UnsupportedFunctionalityError5({
5580
+ functionality: "Message-level reasoningEffortUpdate",
5581
+ message: unsupportedReason
5582
+ });
5583
+ }
5584
+ input.push({
5585
+ type: "configuration_update",
5586
+ reasoning: { effort }
5587
+ });
5588
+ break;
5589
+ }
5590
+ switch (systemMessageMode) {
5591
+ case "system": {
5592
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
5593
+ providerOptions,
5594
+ providerOptionsName
5595
+ );
5596
+ input.push({
5597
+ ...explicitMessageItemType && { type: "message" },
5598
+ role: "system",
5599
+ content: promptCacheBreakpoint == null ? content : [
5600
+ {
5601
+ type: "input_text",
5602
+ text: content,
5603
+ prompt_cache_breakpoint: promptCacheBreakpoint
5604
+ }
5605
+ ]
5606
+ });
5607
+ break;
5608
+ }
5609
+ case "developer": {
5610
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
5611
+ providerOptions,
5612
+ providerOptionsName
5613
+ );
5614
+ input.push({
5615
+ ...explicitMessageItemType && { type: "message" },
5616
+ role: "developer",
5617
+ content: promptCacheBreakpoint == null ? content : [
5618
+ {
5619
+ type: "input_text",
5620
+ text: content,
5621
+ prompt_cache_breakpoint: promptCacheBreakpoint
5622
+ }
5623
+ ]
5624
+ });
5625
+ break;
5626
+ }
5627
+ case "remove": {
5628
+ warnings.push({
5629
+ type: "other",
5630
+ message: "system messages are removed for this model"
5631
+ });
5632
+ break;
5633
+ }
5634
+ default: {
5635
+ const _exhaustiveCheck = systemMessageMode;
5636
+ throw new Error(
5637
+ `Unsupported system message mode: ${_exhaustiveCheck}`
5638
+ );
5639
+ }
5640
+ }
5641
+ break;
5642
+ }
5643
+ case "user": {
5644
+ input.push({
5645
+ ...explicitMessageItemType && { type: "message" },
5646
+ role: "user",
5647
+ content: content.map((part, index) => {
5648
+ var _a3, _b2, _c2, _d2, _e2;
5649
+ switch (part.type) {
5650
+ case "text": {
5651
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
5652
+ part.providerOptions,
5653
+ providerOptionsName
5654
+ );
5655
+ return {
5656
+ type: "input_text",
5657
+ text: part.text,
5658
+ ...promptCacheBreakpoint != null && {
5659
+ prompt_cache_breakpoint: promptCacheBreakpoint
5660
+ }
5661
+ };
5662
+ }
5663
+ case "file": {
5664
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
5665
+ part.providerOptions,
5666
+ providerOptionsName
5667
+ );
5668
+ switch (part.data.type) {
5669
+ case "reference": {
5670
+ const fileId = resolveProviderReference2({
5671
+ reference: part.data.reference,
5672
+ provider: providerOptionsName
5673
+ });
5674
+ if (getTopLevelMediaType2(part.mediaType) === "image") {
5675
+ return {
5676
+ type: "input_image",
5677
+ file_id: fileId,
5678
+ detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
5679
+ ...promptCacheBreakpoint != null && {
5680
+ prompt_cache_breakpoint: promptCacheBreakpoint
5681
+ }
5682
+ };
5683
+ }
5684
+ return {
5685
+ type: "input_file",
5686
+ file_id: fileId,
5687
+ ...promptCacheBreakpoint != null && {
5688
+ prompt_cache_breakpoint: promptCacheBreakpoint
5689
+ }
5690
+ };
5691
+ }
5692
+ case "text": {
5693
+ throw new UnsupportedFunctionalityError5({
5694
+ functionality: "text file parts"
5695
+ });
5696
+ }
5697
+ case "url":
5698
+ case "data": {
5699
+ const topLevel = getTopLevelMediaType2(part.mediaType);
5700
+ if (topLevel === "image") {
5701
+ return {
5702
+ type: "input_image",
5703
+ ...part.data.type === "url" ? { image_url: part.data.url.toString() } : typeof part.data.data === "string" && isFileId(part.data.data, fileIdPrefixes) ? { file_id: part.data.data } : {
5704
+ image_url: `data:${resolveFullMediaType2({ part })};base64,${convertToBase642(part.data.data)}`
5705
+ },
5706
+ detail: (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
5707
+ ...promptCacheBreakpoint != null && {
5708
+ prompt_cache_breakpoint: promptCacheBreakpoint
5709
+ }
5710
+ };
5711
+ } else {
5712
+ if (part.data.type === "url") {
5713
+ return {
5714
+ type: "input_file",
5715
+ file_url: part.data.url.toString(),
5716
+ ...promptCacheBreakpoint != null && {
5717
+ prompt_cache_breakpoint: promptCacheBreakpoint
5718
+ }
5719
+ };
5720
+ }
5721
+ const fullMediaType = resolveFullMediaType2({ part });
5722
+ if (fullMediaType !== "application/pdf" && !passThroughUnsupportedFiles) {
5723
+ throw new UnsupportedFunctionalityError5({
5724
+ functionality: `file part media type ${fullMediaType}`
5725
+ });
5726
+ }
5727
+ return {
5728
+ type: "input_file",
5729
+ ...typeof part.data.data === "string" && isFileId(part.data.data, fileIdPrefixes) ? { file_id: part.data.data } : {
5730
+ filename: (_e2 = part.filename) != null ? _e2 : fullMediaType === "application/pdf" ? `part-${index}.pdf` : `part-${index}`,
5731
+ file_data: `data:${fullMediaType};base64,${convertToBase642(part.data.data)}`
5732
+ },
5733
+ ...promptCacheBreakpoint != null && {
5734
+ prompt_cache_breakpoint: promptCacheBreakpoint
5735
+ }
5736
+ };
5737
+ }
5738
+ }
5739
+ }
5740
+ }
5741
+ }
5742
+ })
5743
+ });
5744
+ break;
5745
+ }
5746
+ case "assistant": {
5747
+ const reasoningMessages = {};
5748
+ for (const part of content) {
5749
+ switch (part.type) {
5750
+ case "text": {
5751
+ const providerOptions2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName];
5752
+ const id = providerOptions2 == null ? void 0 : providerOptions2.itemId;
5753
+ const phase = providerOptions2 == null ? void 0 : providerOptions2.phase;
5754
+ if (hasConversation && id != null) {
5755
+ break;
5756
+ }
5757
+ if (store && id != null) {
5758
+ input.push({ type: "item_reference", id });
5759
+ break;
5760
+ }
5761
+ input.push({
5762
+ ...explicitMessageItemType && { type: "message" },
5763
+ role: "assistant",
5764
+ content: part.text,
5765
+ ...phase != null && { phase }
5766
+ });
5767
+ break;
5768
+ }
5769
+ case "tool-call": {
5770
+ const parallelToolCallMetadata = getParallelToolCallMetadata({
5771
+ providerOptions: part.providerOptions,
5772
+ providerOptionsName
5773
+ });
5774
+ const parallelToolResultGroup = parallelToolCallMetadata == null ? void 0 : parallelToolResultGroups.get(
5775
+ parallelToolCallMetadata.toolCallId
5776
+ );
5777
+ if (parallelToolCallMetadata != null && parallelToolResultGroup != null && hasSameParallelToolCall(
5778
+ parallelToolResultGroup.metadata,
5779
+ parallelToolCallMetadata
5780
+ )) {
5781
+ if (!emittedParallelToolCalls.has(
5782
+ parallelToolResultGroup.metadata.toolCallId
5783
+ )) {
5784
+ emittedParallelToolCalls.add(
5785
+ parallelToolResultGroup.metadata.toolCallId
5786
+ );
5787
+ if (!hasConversation) {
5788
+ input.push({
5789
+ type: "function_call",
5790
+ call_id: parallelToolResultGroup.metadata.toolCallId,
5791
+ name: parallelToolResultGroup.metadata.toolName,
5792
+ arguments: parallelToolResultGroup.metadata.input
5793
+ });
5794
+ }
5795
+ }
5796
+ break;
5797
+ }
5798
+ const id = (_f = (_c = (_b = part.providerOptions) == null ? void 0 : _b[providerOptionsName]) == null ? void 0 : _c.itemId) != null ? _f : (_e = (_d = part.providerMetadata) == null ? void 0 : _d[providerOptionsName]) == null ? void 0 : _e.itemId;
5799
+ const namespace = (_k = (_h = (_g = part.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.namespace) != null ? _k : (_j = (_i = part.providerMetadata) == null ? void 0 : _i[providerOptionsName]) == null ? void 0 : _j.namespace;
5800
+ const isAsync = (_p = (_m = (_l = part.providerOptions) == null ? void 0 : _l[providerOptionsName]) == null ? void 0 : _m.async) != null ? _p : (_o = (_n = part.providerMetadata) == null ? void 0 : _n[providerOptionsName]) == null ? void 0 : _o.async;
5801
+ const caller = (_r = (_q = part.providerOptions) == null ? void 0 : _q[providerOptionsName]) == null ? void 0 : _r.caller;
5802
+ if ((caller == null ? void 0 : caller.type) === "program") {
5803
+ programmaticToolCallIds.add(part.toolCallId);
5804
+ }
5805
+ if (hasConversation && id != null) {
5806
+ break;
5807
+ }
5808
+ const resolvedToolName = toolNameMapping.toProviderToolName(
5809
+ part.toolName
5810
+ );
5811
+ if (part.toolName === toolSearchToolName) {
5812
+ if (store && id != null) {
5813
+ input.push({ type: "item_reference", id });
5814
+ break;
5815
+ }
5816
+ const parsedInput = typeof part.input === "string" ? await parseJSON({
5817
+ text: part.input,
5818
+ schema: toolSearchInputSchema
5819
+ }) : await validateTypes({
5820
+ value: part.input,
5821
+ schema: toolSearchInputSchema
5822
+ });
5823
+ const execution = parsedInput.call_id != null ? "client" : "server";
5824
+ input.push({
5825
+ type: "tool_search_call",
5826
+ id: id != null ? id : part.toolCallId,
5827
+ execution,
5828
+ call_id: (_s = parsedInput.call_id) != null ? _s : null,
5829
+ status: "completed",
5830
+ arguments: parsedInput.arguments
5831
+ });
5832
+ break;
5833
+ }
5834
+ if (resolvedToolName === "programmatic_tool_calling") {
5835
+ if (store && id != null) {
5836
+ input.push({ type: "item_reference", id });
5837
+ break;
5838
+ }
5839
+ const parsedInput = await validateTypes({
5840
+ value: part.input,
5841
+ schema: programmaticToolCallingInputSchema
5842
+ });
5843
+ input.push({
5844
+ type: "program",
5845
+ id: id != null ? id : part.toolCallId,
5846
+ call_id: part.toolCallId,
5847
+ code: parsedInput.code,
5848
+ fingerprint: parsedInput.fingerprint
5849
+ });
5850
+ break;
5851
+ }
5852
+ if (part.providerExecuted) {
5853
+ if (store && id != null) {
5854
+ input.push({ type: "item_reference", id });
5855
+ }
5856
+ if (store || !hasShellTool || resolvedToolName !== "shell") {
5857
+ break;
5858
+ }
5859
+ }
5860
+ const isProviderDefinedToolCall = hasLocalShellTool && resolvedToolName === "local_shell" || hasShellTool && resolvedToolName === "shell" || hasApplyPatchTool && resolvedToolName === "apply_patch" || hasComputerTool && resolvedToolName === "computer" || ((_t = customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) != null ? _t : false);
5861
+ if (hasPreviousResponseId && store && id != null && isProviderDefinedToolCall) {
5862
+ break;
5863
+ }
5864
+ if (store && id != null && isProviderDefinedToolCall) {
5865
+ input.push({ type: "item_reference", id });
5866
+ break;
5867
+ }
5868
+ if (hasLocalShellTool && resolvedToolName === "local_shell") {
5869
+ const parsedInput = await validateTypes({
5870
+ value: part.input,
5871
+ schema: localShellInputSchema
5872
+ });
5873
+ input.push({
5874
+ type: "local_shell_call",
5875
+ call_id: part.toolCallId,
5876
+ id,
5877
+ action: {
5878
+ type: "exec",
5879
+ command: parsedInput.action.command,
5880
+ timeout_ms: parsedInput.action.timeoutMs,
5881
+ user: parsedInput.action.user,
5882
+ working_directory: parsedInput.action.workingDirectory,
5883
+ env: parsedInput.action.env
5884
+ }
5885
+ });
5886
+ break;
5887
+ }
5888
+ if (hasShellTool && resolvedToolName === "shell") {
5889
+ const parsedInput = await validateTypes({
5890
+ value: part.input,
5891
+ schema: shellInputSchema
5892
+ });
5893
+ input.push({
5894
+ type: "shell_call",
5895
+ call_id: part.toolCallId,
5896
+ id,
5897
+ status: "completed",
5898
+ action: {
5899
+ commands: parsedInput.action.commands,
5900
+ timeout_ms: parsedInput.action.timeoutMs,
5901
+ max_output_length: parsedInput.action.maxOutputLength
5902
+ }
5903
+ });
5904
+ break;
5905
+ }
5906
+ if (hasApplyPatchTool && resolvedToolName === "apply_patch") {
5907
+ const parsedInput = await validateTypes({
5908
+ value: part.input,
5909
+ schema: applyPatchInputSchema
5910
+ });
5911
+ input.push({
5912
+ type: "apply_patch_call",
5913
+ call_id: parsedInput.callId,
5914
+ id,
5915
+ status: "completed",
5916
+ operation: parsedInput.operation
5917
+ });
5918
+ break;
5919
+ }
5920
+ if (hasComputerTool && resolvedToolName === "computer") {
5921
+ const parsedInput = await validateTypes({
5922
+ value: part.input,
5923
+ schema: computerInputSchema
5924
+ });
5925
+ input.push({
5926
+ type: "computer_call",
5927
+ call_id: part.toolCallId,
5928
+ id,
5929
+ status: parsedInput.status,
5930
+ actions: parsedInput.actions.map((action) => {
5931
+ switch (action.type) {
5932
+ case "click":
5933
+ case "double_click":
5934
+ case "move":
5935
+ return {
5936
+ ...action,
5937
+ keys: action.keys
5938
+ };
5939
+ case "drag":
5940
+ return {
5941
+ ...action,
5942
+ keys: action.keys
5943
+ };
5944
+ case "scroll":
5945
+ return {
5946
+ type: "scroll",
5947
+ x: action.x,
5948
+ y: action.y,
5949
+ scroll_x: action.scrollX,
5950
+ scroll_y: action.scrollY,
5951
+ keys: action.keys
5952
+ };
5953
+ default:
5954
+ return action;
5955
+ }
5956
+ }),
5957
+ pending_safety_checks: parsedInput.pendingSafetyChecks.map(
5958
+ (safetyCheck) => ({
5959
+ id: safetyCheck.id,
5960
+ code: safetyCheck.code,
5961
+ message: safetyCheck.message
5962
+ })
5963
+ )
5964
+ });
5965
+ break;
5966
+ }
5967
+ if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
5968
+ input.push({
5969
+ type: "custom_tool_call",
5970
+ call_id: part.toolCallId,
5971
+ name: resolvedToolName,
5972
+ input: typeof part.input === "string" ? part.input : JSON.stringify(part.input),
5973
+ ...isAsync != null && { async: isAsync },
5974
+ id
5975
+ });
5976
+ break;
5977
+ }
5978
+ input.push({
5979
+ type: "function_call",
5980
+ call_id: part.toolCallId,
5981
+ name: resolvedToolName,
5982
+ arguments: serializeToolCallArguments2(part.input),
5983
+ ...isAsync != null && { async: isAsync },
5984
+ ...namespace != null && { namespace },
5985
+ ...caller != null && {
5986
+ caller: mapToolCaller(caller)
5987
+ }
5988
+ });
5989
+ break;
5990
+ }
5991
+ // assistant tool result parts are from provider-executed tools:
5992
+ case "tool-result": {
5993
+ if (part.output.type === "execution-denied" || part.output.type === "json" && typeof part.output.value === "object" && part.output.value != null && "type" in part.output.value && part.output.value.type === "execution-denied") {
5994
+ break;
5995
+ }
5996
+ if (hasConversation) {
5997
+ break;
5998
+ }
5999
+ const resolvedResultToolName = toolNameMapping.toProviderToolName(
6000
+ part.toolName
6001
+ );
6002
+ if (part.toolName === toolSearchToolName) {
6003
+ const itemId = (_z = (_y = (_v = (_u = part.providerOptions) == null ? void 0 : _u[providerOptionsName]) == null ? void 0 : _v.itemId) != null ? _y : (_x = (_w = part.providerMetadata) == null ? void 0 : _w[providerOptionsName]) == null ? void 0 : _x.itemId) != null ? _z : part.toolCallId;
6004
+ if (store) {
6005
+ input.push({ type: "item_reference", id: itemId });
6006
+ } else if (part.output.type === "json") {
6007
+ const parsedOutput = await validateTypes({
6008
+ value: part.output.value,
6009
+ schema: toolSearchOutputSchema
6010
+ });
6011
+ input.push({
6012
+ type: "tool_search_output",
6013
+ id: itemId,
6014
+ execution: "server",
6015
+ call_id: null,
6016
+ status: "completed",
6017
+ tools: parsedOutput.tools
6018
+ });
6019
+ }
6020
+ break;
6021
+ }
6022
+ if (resolvedResultToolName === "programmatic_tool_calling") {
6023
+ const itemId = (_F = (_E = (_B = (_A = part.providerOptions) == null ? void 0 : _A[providerOptionsName]) == null ? void 0 : _B.itemId) != null ? _E : (_D = (_C = part.providerMetadata) == null ? void 0 : _C[providerOptionsName]) == null ? void 0 : _D.itemId) != null ? _F : part.toolCallId;
6024
+ if (store) {
6025
+ input.push({ type: "item_reference", id: itemId });
6026
+ } else if (part.output.type === "json") {
6027
+ const parsedOutput = await validateTypes({
6028
+ value: part.output.value,
6029
+ schema: programmaticToolCallingOutputSchema
6030
+ });
6031
+ input.push({
6032
+ type: "program_output",
6033
+ id: itemId,
6034
+ call_id: part.toolCallId,
6035
+ result: parsedOutput.result,
6036
+ status: parsedOutput.status
6037
+ });
6038
+ }
6039
+ break;
6040
+ }
6041
+ if (hasShellTool && resolvedResultToolName === "shell") {
6042
+ if (part.output.type === "json") {
6043
+ const parsedOutput = await validateTypes({
6044
+ value: part.output.value,
6045
+ schema: shellOutputSchema
6046
+ });
6047
+ input.push({
6048
+ type: "shell_call_output",
6049
+ call_id: part.toolCallId,
6050
+ output: parsedOutput.output.map((item) => ({
6051
+ stdout: item.stdout,
6052
+ stderr: item.stderr,
6053
+ outcome: item.outcome.type === "timeout" ? { type: "timeout" } : {
6054
+ type: "exit",
6055
+ exit_code: item.outcome.exitCode
6056
+ }
6057
+ }))
6058
+ });
6059
+ }
6060
+ break;
6061
+ }
6062
+ if (store) {
6063
+ const itemId = (_I = (_H = (_G = part.providerOptions) == null ? void 0 : _G[providerOptionsName]) == null ? void 0 : _H.itemId) != null ? _I : part.toolCallId;
6064
+ input.push({ type: "item_reference", id: itemId });
6065
+ } else {
6066
+ warnings.push({
6067
+ type: "other",
6068
+ message: `Results for OpenAI tool ${part.toolName} are not sent to the API when store is false`
6069
+ });
6070
+ }
6071
+ break;
6072
+ }
6073
+ case "reasoning": {
6074
+ const providerOptions2 = await parseProviderOptions6({
6075
+ provider: providerOptionsName,
6076
+ providerOptions: part.providerOptions,
6077
+ schema: openaiResponsesReasoningProviderOptionsSchema
6078
+ });
6079
+ const reasoningId = providerOptions2 == null ? void 0 : providerOptions2.itemId;
6080
+ if ((hasConversation || hasPreviousResponseId) && reasoningId != null) {
6081
+ break;
6082
+ }
6083
+ if (reasoningId != null) {
6084
+ const reasoningMessage = reasoningMessages[reasoningId];
6085
+ if (store) {
6086
+ if (reasoningMessage === void 0) {
6087
+ input.push({ type: "item_reference", id: reasoningId });
6088
+ reasoningMessages[reasoningId] = {
6089
+ type: "reasoning",
6090
+ id: reasoningId,
6091
+ summary: []
6092
+ };
6093
+ }
6094
+ } else {
6095
+ const summaryParts = [];
6096
+ if (part.text.length > 0) {
6097
+ summaryParts.push({
6098
+ type: "summary_text",
6099
+ text: part.text
6100
+ });
6101
+ } else if (reasoningMessage !== void 0) {
6102
+ warnings.push({
6103
+ type: "other",
6104
+ message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${JSON.stringify(part)}.`
6105
+ });
6106
+ }
6107
+ if (reasoningMessage === void 0) {
6108
+ reasoningMessages[reasoningId] = {
6109
+ type: "reasoning",
6110
+ id: reasoningId,
6111
+ encrypted_content: providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent,
6112
+ summary: summaryParts
6113
+ };
6114
+ input.push(reasoningMessages[reasoningId]);
6115
+ } else {
6116
+ reasoningMessage.summary.push(...summaryParts);
6117
+ if ((providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent) != null) {
6118
+ reasoningMessage.encrypted_content = providerOptions2.reasoningEncryptedContent;
6119
+ }
6120
+ }
6121
+ }
6122
+ } else {
6123
+ const encryptedContent = providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent;
6124
+ if (encryptedContent != null) {
6125
+ const summaryParts = [];
6126
+ if (part.text.length > 0) {
6127
+ summaryParts.push({
6128
+ type: "summary_text",
6129
+ text: part.text
6130
+ });
6131
+ }
6132
+ input.push({
6133
+ type: "reasoning",
6134
+ encrypted_content: encryptedContent,
6135
+ summary: summaryParts
6136
+ });
6137
+ } else {
6138
+ warnings.push({
6139
+ type: "other",
6140
+ message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
6141
+ });
6142
+ }
6143
+ }
6144
+ break;
6145
+ }
6146
+ case "custom": {
6147
+ if (part.kind === "openai.compaction") {
6148
+ const providerOptions2 = (_J = part.providerOptions) == null ? void 0 : _J[providerOptionsName];
6149
+ const id = providerOptions2 == null ? void 0 : providerOptions2.itemId;
6150
+ if (hasConversation && id != null) {
6151
+ break;
6152
+ }
6153
+ if (store && id != null) {
6154
+ input.push({ type: "item_reference", id });
6155
+ break;
6156
+ }
6157
+ const encryptedContent = providerOptions2 == null ? void 0 : providerOptions2.encryptedContent;
6158
+ if (id != null) {
6159
+ input.push({
6160
+ type: "compaction",
6161
+ id,
6162
+ encrypted_content: encryptedContent
6163
+ });
6164
+ }
6165
+ }
6166
+ break;
6167
+ }
6168
+ }
6169
+ }
6170
+ break;
6171
+ }
6172
+ case "tool": {
6173
+ for (const part of content) {
6174
+ if (part.type === "tool-approval-response") {
6175
+ const approvalResponse = part;
6176
+ if (processedApprovalIds.has(approvalResponse.approvalId)) {
6177
+ continue;
6178
+ }
6179
+ processedApprovalIds.add(approvalResponse.approvalId);
6180
+ if (store && !hasConversation && !hasPreviousResponseId) {
6181
+ input.push({
6182
+ type: "item_reference",
6183
+ id: approvalResponse.approvalId
6184
+ });
6185
+ }
6186
+ input.push({
6187
+ type: "mcp_approval_response",
6188
+ approval_request_id: approvalResponse.approvalId,
6189
+ approve: approvalResponse.approved
6190
+ });
6191
+ continue;
6192
+ }
6193
+ const parallelToolCallMetadata = getParallelToolCallMetadata({
6194
+ providerOptions: part.providerOptions,
6195
+ providerOptionsName
6196
+ });
6197
+ const parallelToolResultGroup = parallelToolCallMetadata == null ? void 0 : parallelToolResultGroups.get(
6198
+ parallelToolCallMetadata.toolCallId
6199
+ );
6200
+ if (parallelToolCallMetadata != null && parallelToolResultGroup != null && hasSameParallelToolCall(
6201
+ parallelToolResultGroup.metadata,
6202
+ parallelToolCallMetadata
6203
+ )) {
6204
+ if (!emittedParallelToolResults.has(
6205
+ parallelToolResultGroup.metadata.toolCallId
6206
+ )) {
6207
+ emittedParallelToolResults.add(
6208
+ parallelToolResultGroup.metadata.toolCallId
6209
+ );
6210
+ const toolOutputs = await Promise.all(
6211
+ parallelToolResultGroup.results.map(async (result) => {
6212
+ const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
6213
+ output: result.output,
6214
+ toolResultProviderOptions: result.providerOptions,
6215
+ providerOptionsName
6216
+ });
6217
+ return {
6218
+ output: await convertFunctionToolResultOutput({
6219
+ output: result.output,
6220
+ toolName: result.toolName,
6221
+ outputSchemaToolNames,
6222
+ providerOptionsName,
6223
+ warnings
6224
+ }),
6225
+ promptCacheBreakpoint
6226
+ };
6227
+ })
6228
+ );
6229
+ const serializedToolOutputs = toolOutputs.map(
6230
+ ({ output: output2 }) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
6231
+ );
6232
+ const hasPromptCacheBreakpoint = toolOutputs.some(
6233
+ ({ promptCacheBreakpoint }) => promptCacheBreakpoint != null
6234
+ );
6235
+ input.push({
6236
+ type: "function_call_output",
6237
+ call_id: parallelToolResultGroup.metadata.toolCallId,
6238
+ // The internal wrapper returns one output containing the child
6239
+ // results in the same order as the original tool_uses array.
6240
+ output: hasPromptCacheBreakpoint ? serializedToolOutputs.map((text, index) => ({
6241
+ type: "input_text",
6242
+ text: index === 0 ? text : `
6243
+ ${text}`,
6244
+ ...toolOutputs[index].promptCacheBreakpoint != null && {
6245
+ prompt_cache_breakpoint: toolOutputs[index].promptCacheBreakpoint
6246
+ }
6247
+ })) : serializedToolOutputs.join("\n")
6248
+ });
6249
+ }
6250
+ continue;
6251
+ }
6252
+ const output = part.output;
6253
+ if (output.type === "execution-denied") {
6254
+ const approvalId = (_L = (_K = output.providerOptions) == null ? void 0 : _K.openai) == null ? void 0 : _L.approvalId;
6255
+ if (approvalId) {
6256
+ continue;
6257
+ }
6258
+ }
6259
+ const resolvedToolName = toolNameMapping.toProviderToolName(
6260
+ part.toolName
6261
+ );
6262
+ if (part.toolName === toolSearchToolName && output.type === "json") {
6263
+ const parsedOutput = await validateTypes({
6264
+ value: output.value,
6265
+ schema: toolSearchOutputSchema
6266
+ });
6267
+ input.push({
6268
+ type: "tool_search_output",
6269
+ execution: "client",
6270
+ call_id: part.toolCallId,
6271
+ status: "completed",
6272
+ tools: parsedOutput.tools
6273
+ });
6274
+ continue;
6275
+ }
6276
+ if (hasLocalShellTool && resolvedToolName === "local_shell" && output.type === "json") {
6277
+ const parsedOutput = await validateTypes({
6278
+ value: output.value,
6279
+ schema: localShellOutputSchema
6280
+ });
6281
+ input.push({
6282
+ type: "local_shell_call_output",
6283
+ call_id: part.toolCallId,
6284
+ output: parsedOutput.output
6285
+ });
6286
+ continue;
6287
+ }
6288
+ if (hasShellTool && resolvedToolName === "shell" && output.type === "json") {
6289
+ const parsedOutput = await validateTypes({
6290
+ value: output.value,
6291
+ schema: shellOutputSchema
6292
+ });
6293
+ input.push({
6294
+ type: "shell_call_output",
6295
+ call_id: part.toolCallId,
6296
+ output: parsedOutput.output.map((item) => ({
6297
+ stdout: item.stdout,
6298
+ stderr: item.stderr,
6299
+ outcome: item.outcome.type === "timeout" ? { type: "timeout" } : {
6300
+ type: "exit",
6301
+ exit_code: item.outcome.exitCode
6302
+ }
6303
+ }))
6304
+ });
6305
+ continue;
6306
+ }
6307
+ if (hasApplyPatchTool && part.toolName === "apply_patch" && output.type === "json") {
6308
+ const parsedOutput = await validateTypes({
6309
+ value: output.value,
6310
+ schema: applyPatchOutputSchema
6311
+ });
6312
+ input.push({
6313
+ type: "apply_patch_call_output",
6314
+ call_id: part.toolCallId,
6315
+ status: parsedOutput.status,
6316
+ output: parsedOutput.output
6317
+ });
6318
+ continue;
6319
+ }
6320
+ if (hasComputerTool && resolvedToolName === "computer" && output.type === "json") {
6321
+ const parsedOutput = await validateTypes({
6322
+ value: output.value,
6323
+ schema: computerOutputSchema
6324
+ });
6325
+ input.push({
6326
+ type: "computer_call_output",
6327
+ call_id: part.toolCallId,
6328
+ output: {
6329
+ type: "computer_screenshot",
6330
+ image_url: parsedOutput.output.imageUrl,
6331
+ file_id: parsedOutput.output.fileId,
6332
+ detail: parsedOutput.output.detail
6333
+ },
6334
+ acknowledged_safety_checks: (_M = parsedOutput.acknowledgedSafetyChecks) == null ? void 0 : _M.map((safetyCheck) => ({
6335
+ id: safetyCheck.id,
6336
+ code: safetyCheck.code,
6337
+ message: safetyCheck.message
6338
+ }))
6339
+ });
6340
+ continue;
6341
+ }
6342
+ if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
6343
+ const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
6344
+ output,
6345
+ toolResultProviderOptions: part.providerOptions,
6346
+ providerOptionsName
6347
+ });
6348
+ const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
6349
+ {
6350
+ type: "input_text",
6351
+ text: value,
6352
+ prompt_cache_breakpoint: promptCacheBreakpoint
6353
+ }
6354
+ ];
6355
+ let outputValue;
6356
+ switch (output.type) {
6357
+ case "text":
6358
+ case "error-text":
6359
+ outputValue = convertScalarOutput(output.value);
6360
+ break;
6361
+ case "execution-denied":
6362
+ outputValue = convertScalarOutput(
6363
+ (_N = output.reason) != null ? _N : "Tool call execution denied."
6364
+ );
6365
+ break;
6366
+ case "json":
6367
+ case "error-json":
6368
+ outputValue = convertScalarOutput(JSON.stringify(output.value));
6369
+ break;
6370
+ case "content":
6371
+ outputValue = output.value.map((item) => {
6372
+ var _a3, _b2, _c2;
6373
+ const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
6374
+ item.providerOptions,
6375
+ providerOptionsName
6376
+ );
6377
+ switch (item.type) {
6378
+ case "text":
6379
+ return {
6380
+ type: "input_text",
6381
+ text: item.text,
6382
+ ...promptCacheBreakpoint2 != null && {
6383
+ prompt_cache_breakpoint: promptCacheBreakpoint2
6384
+ }
6385
+ };
6386
+ case "file": {
6387
+ const topLevel = getTopLevelMediaType2(item.mediaType);
6388
+ const imageDetail = (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail;
6389
+ if (item.data.type === "data") {
6390
+ const fullMediaType = resolveFullMediaType2({
6391
+ part: item
6392
+ });
6393
+ if (topLevel === "image") {
6394
+ return {
6395
+ type: "input_image",
6396
+ image_url: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
6397
+ detail: imageDetail,
6398
+ ...promptCacheBreakpoint2 != null && {
6399
+ prompt_cache_breakpoint: promptCacheBreakpoint2
6400
+ }
6401
+ };
6402
+ }
6403
+ return {
6404
+ type: "input_file",
6405
+ filename: (_c2 = item.filename) != null ? _c2 : "data",
6406
+ file_data: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
6407
+ ...promptCacheBreakpoint2 != null && {
6408
+ prompt_cache_breakpoint: promptCacheBreakpoint2
6409
+ }
6410
+ };
6411
+ }
6412
+ if (item.data.type === "url") {
6413
+ if (topLevel === "image") {
6414
+ return {
6415
+ type: "input_image",
6416
+ image_url: item.data.url.toString(),
6417
+ detail: imageDetail,
6418
+ ...promptCacheBreakpoint2 != null && {
6419
+ prompt_cache_breakpoint: promptCacheBreakpoint2
6420
+ }
6421
+ };
6422
+ }
6423
+ return {
6424
+ type: "input_file",
6425
+ file_url: item.data.url.toString(),
6426
+ ...promptCacheBreakpoint2 != null && {
6427
+ prompt_cache_breakpoint: promptCacheBreakpoint2
6428
+ }
6429
+ };
6430
+ }
6431
+ warnings.push({
6432
+ type: "other",
6433
+ message: `unsupported custom tool content part type: ${item.type} with data type: ${item.data.type}`
6434
+ });
6435
+ return void 0;
6436
+ }
6437
+ default:
6438
+ warnings.push({
6439
+ type: "other",
6440
+ message: `unsupported custom tool content part type: ${item.type}`
6441
+ });
6442
+ return void 0;
6443
+ }
6444
+ }).filter(isNonNullable);
6445
+ break;
6446
+ default:
6447
+ outputValue = "";
6448
+ }
6449
+ input.push({
6450
+ type: "custom_tool_call_output",
6451
+ call_id: part.toolCallId,
6452
+ output: outputValue
6453
+ });
6454
+ continue;
6455
+ }
6456
+ const resultCaller = (_P = (_O = part.providerOptions) == null ? void 0 : _O[providerOptionsName]) == null ? void 0 : _P.caller;
6457
+ if (output.type === "execution-denied" && ((resultCaller == null ? void 0 : resultCaller.type) === "program" || programmaticToolCallIds.has(part.toolCallId))) {
6458
+ throw new UnsupportedFunctionalityError5({
6459
+ functionality: "execution-denied results for programmatic tool calls"
6460
+ });
6461
+ }
6462
+ const contentValue = await convertFunctionToolResultOutput({
6463
+ output,
6464
+ toolName: part.toolName,
6465
+ outputSchemaToolNames,
6466
+ promptCacheBreakpoint: getScalarToolResultPromptCacheBreakpoint({
6467
+ output,
6468
+ toolResultProviderOptions: part.providerOptions,
6469
+ providerOptionsName
6470
+ }),
6471
+ providerOptionsName,
6472
+ warnings
6473
+ });
6474
+ const caller = mapToolCaller(resultCaller);
6475
+ input.push({
6476
+ type: "function_call_output",
6477
+ call_id: part.toolCallId,
6478
+ output: contentValue,
6479
+ ...caller != null && { caller }
6480
+ });
6481
+ }
6482
+ break;
6483
+ }
6484
+ default: {
6485
+ const _exhaustiveCheck = role;
6486
+ throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
6487
+ }
6488
+ }
6489
+ }
6490
+ if (!store && input.some(
6491
+ (item) => "type" in item && item.type === "reasoning" && item.encrypted_content == null
6492
+ )) {
6493
+ warnings.push({
6494
+ type: "other",
6495
+ message: "Reasoning parts without encrypted content are not supported when store is false. Skipping reasoning parts."
6496
+ });
6497
+ input = input.filter(
6498
+ (item) => !("type" in item) || item.type !== "reasoning" || item.encrypted_content != null
6499
+ );
6500
+ }
6501
+ return { input, warnings };
6502
+ }
6503
+ var openaiResponsesReasoningProviderOptionsSchema = z27.object({
6504
+ itemId: z27.string().nullish(),
6505
+ reasoningEncryptedContent: z27.string().nullish()
6506
+ });
6507
+
6464
6508
  // src/responses/openai-responses-prepare-tools.ts
6465
6509
  import {
6466
6510
  UnsupportedFunctionalityError as UnsupportedFunctionalityError6
@@ -6929,7 +6973,6 @@ function resolveAsyncToolOption({
6929
6973
  feature: `async tool calling for "${toolName}"`,
6930
6974
  details: "Async tool calling is only supported by GPT-6 and later models."
6931
6975
  });
6932
- return void 0;
6933
6976
  }
6934
6977
  function mapShellEnvironment(environment) {
6935
6978
  if (environment.type === "containerReference") {
@@ -7072,6 +7115,18 @@ var openaiResponsesSupportedUrls = {
7072
7115
  "image/*": [/^https?:\/\/.*$/],
7073
7116
  "application/pdf": [/^https?:\/\/.*$/]
7074
7117
  };
7118
+ function getConfigurationUpdateUnsupportedReason({
7119
+ modelCapabilities,
7120
+ options
7121
+ }) {
7122
+ if (!modelCapabilities.supportsConfigurationUpdate) {
7123
+ return "reasoningEffortUpdate is only supported by GPT-6 and later models";
7124
+ }
7125
+ if ((options == null ? void 0 : options.reasoningMode) === "pro" || (options == null ? void 0 : options.contextManagement) != null || (options == null ? void 0 : options.truncation) === "auto") {
7126
+ return "reasoningEffortUpdate requires standard reasoning mode without automatic compaction or automatic truncation";
7127
+ }
7128
+ return void 0;
7129
+ }
7075
7130
  var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7076
7131
  constructor(modelId, config) {
7077
7132
  this.specificationVersion = "v4";
@@ -7197,11 +7252,16 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7197
7252
  outputSchemaToolNames,
7198
7253
  supportsAsyncToolCalling: modelCapabilities.supportsAsyncToolCalling
7199
7254
  });
7255
+ const configurationUpdateUnsupportedReason = getConfigurationUpdateUnsupportedReason({
7256
+ modelCapabilities,
7257
+ options: openaiOptions
7258
+ });
7200
7259
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
7201
7260
  prompt,
7202
7261
  toolNameMapping,
7203
7262
  systemMessageMode: (_d = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _d : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
7204
7263
  providerOptionsName,
7264
+ configurationUpdateUnsupportedReason,
7205
7265
  explicitMessageItemType: config.explicitMessageItemType,
7206
7266
  fileIdPrefixes: config.fileIdPrefixes,
7207
7267
  passThroughUnsupportedFiles: (_e = openaiOptions == null ? void 0 : openaiOptions.passThroughUnsupportedFiles) != null ? _e : false,
@@ -7218,18 +7278,27 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7218
7278
  });
7219
7279
  warnings.push(...inputWarnings);
7220
7280
  const reasoningEffortUpdate = openaiOptions == null ? void 0 : openaiOptions.reasoningEffortUpdate;
7221
- const configurationUpdateIsSupported = reasoningEffortUpdate == null || modelCapabilities.supportsConfigurationUpdate && (openaiOptions == null ? void 0 : openaiOptions.reasoningMode) !== "pro" && (openaiOptions == null ? void 0 : openaiOptions.contextManagement) == null && (openaiOptions == null ? void 0 : openaiOptions.truncation) !== "auto";
7222
- if (reasoningEffortUpdate != null && !configurationUpdateIsSupported) {
7281
+ if (reasoningEffortUpdate != null && configurationUpdateUnsupportedReason != null) {
7223
7282
  warnings.push({
7224
7283
  type: "unsupported",
7225
7284
  feature: "reasoningEffortUpdate",
7226
- details: !modelCapabilities.supportsConfigurationUpdate ? "reasoningEffortUpdate is only supported by GPT-6 and later models" : "reasoningEffortUpdate requires standard reasoning mode without automatic compaction or automatic truncation"
7285
+ details: configurationUpdateUnsupportedReason
7227
7286
  });
7228
7287
  } else if (reasoningEffortUpdate != null) {
7229
- input.unshift({
7230
- type: "configuration_update",
7231
- reasoning: { effort: reasoningEffortUpdate }
7232
- });
7288
+ const firstItem = input[0];
7289
+ if ((firstItem == null ? void 0 : firstItem.type) !== "configuration_update" || firstItem.reasoning.effort !== reasoningEffortUpdate) {
7290
+ input.unshift({
7291
+ type: "configuration_update",
7292
+ reasoning: { effort: reasoningEffortUpdate }
7293
+ });
7294
+ }
7295
+ }
7296
+ for (let i = 1; i < input.length; i++) {
7297
+ if (input[i - 1].type === "configuration_update" && input[i].type === "configuration_update") {
7298
+ throw new UnsupportedFunctionalityError7({
7299
+ functionality: "Adjacent reasoning effort configuration updates"
7300
+ });
7301
+ }
7233
7302
  }
7234
7303
  if (openaiOptions == null ? void 0 : openaiOptions.compactionTrigger) {
7235
7304
  input.push({ type: "compaction_trigger" });
@@ -8294,7 +8363,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8294
8363
  } else if (value.item.type === "shell_call_output") {
8295
8364
  } else if (value.item.type === "message") {
8296
8365
  activeOutputItemIds[value.output_index] = value.item.id;
8297
- ongoingAnnotations.splice(0, ongoingAnnotations.length);
8366
+ ongoingAnnotations.splice(0);
8298
8367
  activeMessagePhase = (_c2 = value.item.phase) != null ? _c2 : void 0;
8299
8368
  controller.enqueue({
8300
8369
  type: "text-start",
@@ -9318,7 +9387,7 @@ function assertTextBatchRequests(requests) {
9318
9387
  for (const request of requests) {
9319
9388
  const requestType = request.type;
9320
9389
  if (requestType !== "text") {
9321
- throw new UnsupportedFunctionalityError7({
9390
+ throw new UnsupportedFunctionalityError8({
9322
9391
  functionality: `batch request type: ${requestType}`,
9323
9392
  message: `The OpenAI Batch API does not support batch requests with type "${requestType}".`
9324
9393
  });
@@ -9977,7 +10046,7 @@ async function convertOpenAIBatchResult(body) {
9977
10046
  // src/realtime/openai-realtime-factory.ts
9978
10047
  import {
9979
10048
  InvalidArgumentError as InvalidArgumentError4,
9980
- UnsupportedFunctionalityError as UnsupportedFunctionalityError10
10049
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError11
9981
10050
  } from "@ai-sdk/provider";
9982
10051
 
9983
10052
  // src/live/openai-realtime-model-live.ts
@@ -9989,14 +10058,14 @@ import { z as z32 } from "zod/v4";
9989
10058
 
9990
10059
  // src/live/openai-live-event-mapper.ts
9991
10060
  import {
9992
- UnsupportedFunctionalityError as UnsupportedFunctionalityError9
10061
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError10
9993
10062
  } from "@ai-sdk/provider";
9994
10063
  import { z as z31 } from "zod/v4";
9995
10064
 
9996
10065
  // src/live/openai-live-session-config.ts
9997
10066
  import {
9998
10067
  InvalidArgumentError as InvalidArgumentError3,
9999
- UnsupportedFunctionalityError as UnsupportedFunctionalityError8
10068
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError9
10000
10069
  } from "@ai-sdk/provider";
10001
10070
  import { z as z30 } from "zod/v4";
10002
10071
 
@@ -10063,13 +10132,13 @@ function buildOpenAILiveSessionConfig(config, modelId, transport = "websocket")
10063
10132
  "outputAudioFormat",
10064
10133
  "providerOptions"
10065
10134
  ].includes(key)) {
10066
- throw new UnsupportedFunctionalityError8({
10135
+ throw new UnsupportedFunctionalityError9({
10067
10136
  functionality: `OpenAI Live session setting: ${key}`
10068
10137
  });
10069
10138
  }
10070
10139
  }
10071
10140
  if (z30.object({ delegation: z30.object({ type: z30.literal("responses") }) }).safeParse((_a2 = config.providerOptions) == null ? void 0 : _a2.openai).success) {
10072
- throw new UnsupportedFunctionalityError8({
10141
+ throw new UnsupportedFunctionalityError9({
10073
10142
  functionality: "OpenAI Live Responses delegation; only client delegation is supported"
10074
10143
  });
10075
10144
  }
@@ -10077,7 +10146,7 @@ function buildOpenAILiveSessionConfig(config, modelId, transport = "websocket")
10077
10146
  (_c = (_b = config.providerOptions) == null ? void 0 : _b.openai) != null ? _c : {}
10078
10147
  );
10079
10148
  if (options.client !== void 0 && transport !== "webrtc") {
10080
- throw new UnsupportedFunctionalityError8({
10149
+ throw new UnsupportedFunctionalityError9({
10081
10150
  functionality: "OpenAI Live client permissions outside WebRTC startup"
10082
10151
  });
10083
10152
  }
@@ -10088,7 +10157,7 @@ function buildOpenAILiveSessionConfig(config, modelId, transport = "websocket")
10088
10157
  });
10089
10158
  }
10090
10159
  if (transport === "webrtc" && (config.inputAudioFormat !== void 0 || config.outputAudioFormat !== void 0)) {
10091
- throw new UnsupportedFunctionalityError8({
10160
+ throw new UnsupportedFunctionalityError9({
10092
10161
  functionality: "Fixed audio formats for OpenAI Live WebRTC; audio is negotiated through SDP"
10093
10162
  });
10094
10163
  }
@@ -10343,7 +10412,7 @@ function serializeOpenAILiveClientEvent(event, modelId) {
10343
10412
  ...eventId
10344
10413
  };
10345
10414
  case "session-update":
10346
- throw new UnsupportedFunctionalityError9({
10415
+ throw new UnsupportedFunctionalityError10({
10347
10416
  functionality: "OpenAI Live session-update; startup settings are immutable; use context-append or input-audio-mute/input-audio-unmute"
10348
10417
  });
10349
10418
  case "session-close":
@@ -10374,7 +10443,7 @@ function serializeOpenAILiveClientEvent(event, modelId) {
10374
10443
  };
10375
10444
  }
10376
10445
  default:
10377
- throw new UnsupportedFunctionalityError9({
10446
+ throw new UnsupportedFunctionalityError10({
10378
10447
  functionality: `OpenAI Live command: ${event.type}; use continuous audio and context-append instead of voice-turn commands`
10379
10448
  });
10380
10449
  }
@@ -10867,7 +10936,7 @@ function createOpenAIRealtimeFactory(config) {
10867
10936
  getToken: async (options) => {
10868
10937
  const model = createModel(options.model, options);
10869
10938
  if (model instanceof OpenAIRealtimeModelLive) {
10870
- throw new UnsupportedFunctionalityError10({
10939
+ throw new UnsupportedFunctionalityError11({
10871
10940
  functionality: "Short-lived OpenAI credentials for the Live API. Use server WebSocket setup via getServerWebSocketConfig() with a server-side API key instead."
10872
10941
  });
10873
10942
  }
@@ -11026,7 +11095,7 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
11026
11095
 
11027
11096
  // src/transcription/openai-transcription-model.ts
11028
11097
  import {
11029
- UnsupportedFunctionalityError as UnsupportedFunctionalityError11
11098
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError12
11030
11099
  } from "@ai-sdk/provider";
11031
11100
  import {
11032
11101
  combineHeaders as combineHeaders9,
@@ -11316,7 +11385,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
11316
11385
  async doGenerate(options) {
11317
11386
  var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
11318
11387
  if (isRealtimeTranscriptionModelId(this.modelId)) {
11319
- throw new UnsupportedFunctionalityError11({
11388
+ throw new UnsupportedFunctionalityError12({
11320
11389
  functionality: `non-streaming transcription with ${this.modelId}`
11321
11390
  });
11322
11391
  }
@@ -11383,7 +11452,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
11383
11452
  async doStream(options) {
11384
11453
  var _a2, _b, _c, _d, _e, _f, _g;
11385
11454
  if (!isRealtimeTranscriptionModelId(this.modelId)) {
11386
- throw new UnsupportedFunctionalityError11({
11455
+ throw new UnsupportedFunctionalityError12({
11387
11456
  functionality: `streaming transcription with ${this.modelId}`
11388
11457
  });
11389
11458
  }
@@ -12024,7 +12093,7 @@ var OpenAISkills = class {
12024
12093
  };
12025
12094
 
12026
12095
  // src/version.ts
12027
- var VERSION = true ? "4.0.73" : "0.0.0-test";
12096
+ var VERSION = true ? "4.0.75" : "0.0.0-test";
12028
12097
 
12029
12098
  // src/openai-provider.ts
12030
12099
  function createOpenAI(options = {}) {