@zenning/openai 3.0.22 → 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,27 +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();
2501
- const approvalToolCallIds = /* @__PURE__ */ new Set();
2502
- if (containsApprovalResponses) {
2503
- for (const message of prompt) {
2504
- if (message.role !== "assistant") continue;
2505
- if (typeof message.content === "string") continue;
2506
- for (const part of message.content) {
2507
- if (part.type === "tool-call") {
2508
- const approval = part.approval;
2509
- if ((approval == null ? void 0 : approval.approved) != null) {
2510
- approvalToolCallIds.add(part.toolCallId);
2511
- }
2512
- }
2513
- }
2514
- }
2515
- }
2502
+ const approvalToolCallIds = new Set(approvalToolCallIdsArray || []);
2516
2503
  if (compactionInput && compactionInput.length > 0) {
2517
2504
  input.push(...compactionInput);
2518
2505
  }
@@ -2676,10 +2663,11 @@ async function convertToOpenAIResponsesInput({
2676
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") {
2677
2664
  break;
2678
2665
  }
2679
- if (store) {
2666
+ const toolResultHadApproval = containsApprovalResponses && approvalToolCallIds.has(part.toolCallId);
2667
+ if (store && !toolResultHadApproval) {
2680
2668
  const itemId = (_j = (_i = (_h = part.providerMetadata) == null ? void 0 : _h[providerOptionsName]) == null ? void 0 : _i.itemId) != null ? _j : part.toolCallId;
2681
2669
  input.push({ type: "item_reference", id: itemId });
2682
- } else {
2670
+ } else if (!store) {
2683
2671
  warnings.push({
2684
2672
  type: "other",
2685
2673
  message: `Results for OpenAI tool ${part.toolName} are not sent to the API when store is false`
@@ -3829,7 +3817,12 @@ var openaiResponsesProviderOptionsSchema = lazySchema15(
3829
3817
  * Whether the request contains tool approval responses.
3830
3818
  * Defaults to `false`.
3831
3819
  */
3832
- 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()
3833
3826
  })
3834
3827
  )
3835
3828
  );
@@ -4378,7 +4371,7 @@ var OpenAIResponsesLanguageModel = class {
4378
4371
  toolChoice,
4379
4372
  responseFormat
4380
4373
  }) {
4381
- var _a, _b, _c, _d, _e, _f, _g, _h;
4374
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4382
4375
  const warnings = [];
4383
4376
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
4384
4377
  if (topK != null) {
@@ -4443,10 +4436,11 @@ var OpenAIResponsesLanguageModel = class {
4443
4436
  hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
4444
4437
  compactionInput: openaiOptions == null ? void 0 : openaiOptions.compactionInput,
4445
4438
  previousResponseId: (_d = openaiOptions == null ? void 0 : openaiOptions.previousResponseId) != null ? _d : void 0,
4446
- 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
4447
4441
  });
4448
4442
  warnings.push(...inputWarnings);
4449
- 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;
4450
4444
  let include = openaiOptions == null ? void 0 : openaiOptions.include;
4451
4445
  function addInclude(key) {
4452
4446
  if (include == null) {
@@ -4462,9 +4456,9 @@ var OpenAIResponsesLanguageModel = class {
4462
4456
  if (topLogprobs) {
4463
4457
  addInclude("message.output_text.logprobs");
4464
4458
  }
4465
- const webSearchToolName = (_g = tools == null ? void 0 : tools.find(
4459
+ const webSearchToolName = (_h = tools == null ? void 0 : tools.find(
4466
4460
  (tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
4467
- )) == null ? void 0 : _g.name;
4461
+ )) == null ? void 0 : _h.name;
4468
4462
  if (webSearchToolName) {
4469
4463
  addInclude("web_search_call.action.sources");
4470
4464
  }
@@ -4487,7 +4481,7 @@ var OpenAIResponsesLanguageModel = class {
4487
4481
  format: responseFormat.schema != null ? {
4488
4482
  type: "json_schema",
4489
4483
  strict: strictJsonSchema,
4490
- name: (_h = responseFormat.name) != null ? _h : "response",
4484
+ name: (_i = responseFormat.name) != null ? _i : "response",
4491
4485
  description: responseFormat.description,
4492
4486
  schema: responseFormat.schema
4493
4487
  } : { type: "json_object" }