@zenning/openai 3.0.21 → 3.0.23

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.
@@ -2492,12 +2492,14 @@ async function convertToOpenAIResponsesInput({
2492
2492
  hasApplyPatchTool = false,
2493
2493
  compactionInput,
2494
2494
  previousResponseId,
2495
- containsApprovalResponses
2495
+ containsApprovalResponses,
2496
+ approvalToolCallIds: approvalToolCallIdsArray
2496
2497
  }) {
2497
2498
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2498
2499
  const input = [];
2499
2500
  const warnings = [];
2500
2501
  const processedApprovalIds = /* @__PURE__ */ new Set();
2502
+ const approvalToolCallIds = new Set(approvalToolCallIdsArray || []);
2501
2503
  if (compactionInput && compactionInput.length > 0) {
2502
2504
  input.push(...compactionInput);
2503
2505
  }
@@ -2592,17 +2594,18 @@ async function convertToOpenAIResponsesInput({
2592
2594
  }
2593
2595
  case "tool-call": {
2594
2596
  const id = (_g = (_d = (_c = part.providerOptions) == null ? void 0 : _c[providerOptionsName]) == null ? void 0 : _d.itemId) != null ? _g : (_f = (_e = part.providerMetadata) == null ? void 0 : _e[providerOptionsName]) == null ? void 0 : _f.itemId;
2597
+ const toolHadApproval = containsApprovalResponses && approvalToolCallIds.has(part.toolCallId);
2595
2598
  if (part.providerExecuted) {
2596
- if (store && id != null && !containsApprovalResponses) {
2599
+ if (store && id != null && !toolHadApproval) {
2597
2600
  input.push({ type: "item_reference", id });
2598
2601
  }
2599
2602
  break;
2600
2603
  }
2601
- if (store && id != null && !containsApprovalResponses) {
2604
+ if (store && id != null && !toolHadApproval) {
2602
2605
  input.push({ type: "item_reference", id });
2603
2606
  break;
2604
2607
  }
2605
- if (store && id != null && containsApprovalResponses) {
2608
+ if (store && id != null && toolHadApproval) {
2606
2609
  break;
2607
2610
  }
2608
2611
  const resolvedToolName = toolNameMapping.toProviderToolName(
@@ -2660,10 +2663,11 @@ async function convertToOpenAIResponsesInput({
2660
2663
  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") {
2661
2664
  break;
2662
2665
  }
2663
- if (store) {
2666
+ const toolResultHadApproval = containsApprovalResponses && approvalToolCallIds.has(part.toolCallId);
2667
+ if (store && !toolResultHadApproval) {
2664
2668
  const itemId = (_j = (_i = (_h = part.providerMetadata) == null ? void 0 : _h[providerOptionsName]) == null ? void 0 : _i.itemId) != null ? _j : part.toolCallId;
2665
2669
  input.push({ type: "item_reference", id: itemId });
2666
- } else {
2670
+ } else if (!store) {
2667
2671
  warnings.push({
2668
2672
  type: "other",
2669
2673
  message: `Results for OpenAI tool ${part.toolName} are not sent to the API when store is false`
@@ -3813,7 +3817,12 @@ var openaiResponsesProviderOptionsSchema = lazySchema15(
3813
3817
  * Whether the request contains tool approval responses.
3814
3818
  * Defaults to `false`.
3815
3819
  */
3816
- containsApprovalResponses: z17.boolean().optional()
3820
+ containsApprovalResponses: z17.boolean().optional(),
3821
+ /**
3822
+ * Array of tool call IDs that have approval responses (approved or denied).
3823
+ * Used to skip item_reference for tools that had user approval flow.
3824
+ */
3825
+ approvalToolCallIds: z17.array(z17.string()).optional()
3817
3826
  })
3818
3827
  )
3819
3828
  );
@@ -4362,7 +4371,7 @@ var OpenAIResponsesLanguageModel = class {
4362
4371
  toolChoice,
4363
4372
  responseFormat
4364
4373
  }) {
4365
- var _a, _b, _c, _d, _e, _f, _g, _h;
4374
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4366
4375
  const warnings = [];
4367
4376
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
4368
4377
  if (topK != null) {
@@ -4427,10 +4436,11 @@ var OpenAIResponsesLanguageModel = class {
4427
4436
  hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
4428
4437
  compactionInput: openaiOptions == null ? void 0 : openaiOptions.compactionInput,
4429
4438
  previousResponseId: (_d = openaiOptions == null ? void 0 : openaiOptions.previousResponseId) != null ? _d : void 0,
4430
- containsApprovalResponses: (_e = openaiOptions == null ? void 0 : openaiOptions.containsApprovalResponses) != null ? _e : false
4439
+ containsApprovalResponses: (_e = openaiOptions == null ? void 0 : openaiOptions.containsApprovalResponses) != null ? _e : false,
4440
+ approvalToolCallIds: (_f = openaiOptions == null ? void 0 : openaiOptions.approvalToolCallIds) != null ? _f : void 0
4431
4441
  });
4432
4442
  warnings.push(...inputWarnings);
4433
- const strictJsonSchema = (_f = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _f : true;
4443
+ const strictJsonSchema = (_g = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _g : true;
4434
4444
  let include = openaiOptions == null ? void 0 : openaiOptions.include;
4435
4445
  function addInclude(key) {
4436
4446
  if (include == null) {
@@ -4446,9 +4456,9 @@ var OpenAIResponsesLanguageModel = class {
4446
4456
  if (topLogprobs) {
4447
4457
  addInclude("message.output_text.logprobs");
4448
4458
  }
4449
- const webSearchToolName = (_g = tools == null ? void 0 : tools.find(
4459
+ const webSearchToolName = (_h = tools == null ? void 0 : tools.find(
4450
4460
  (tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
4451
- )) == null ? void 0 : _g.name;
4461
+ )) == null ? void 0 : _h.name;
4452
4462
  if (webSearchToolName) {
4453
4463
  addInclude("web_search_call.action.sources");
4454
4464
  }
@@ -4471,7 +4481,7 @@ var OpenAIResponsesLanguageModel = class {
4471
4481
  format: responseFormat.schema != null ? {
4472
4482
  type: "json_schema",
4473
4483
  strict: strictJsonSchema,
4474
- name: (_h = responseFormat.name) != null ? _h : "response",
4484
+ name: (_i = responseFormat.name) != null ? _i : "response",
4475
4485
  description: responseFormat.description,
4476
4486
  schema: responseFormat.schema
4477
4487
  } : { type: "json_object" }