@zenning/openai 3.0.22 → 3.0.24

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,21 @@ 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 || []);
2503
+ console.log("CALDEBUG [convertToOpenAIResponsesInput] Starting conversion:", {
2504
+ containsApprovalResponses,
2505
+ approvalToolCallIdsCount: approvalToolCallIds.size,
2506
+ approvalToolCallIds: Array.from(approvalToolCallIds),
2507
+ previousResponseId,
2508
+ promptLength: prompt.length
2509
+ });
2516
2510
  if (compactionInput && compactionInput.length > 0) {
2517
2511
  input.push(...compactionInput);
2518
2512
  }
@@ -2676,10 +2670,11 @@ async function convertToOpenAIResponsesInput({
2676
2670
  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
2671
  break;
2678
2672
  }
2679
- if (store) {
2673
+ const toolResultHadApproval = containsApprovalResponses && approvalToolCallIds.has(part.toolCallId);
2674
+ if (store && !toolResultHadApproval) {
2680
2675
  const itemId = (_j = (_i = (_h = part.providerMetadata) == null ? void 0 : _h[providerOptionsName]) == null ? void 0 : _i.itemId) != null ? _j : part.toolCallId;
2681
2676
  input.push({ type: "item_reference", id: itemId });
2682
- } else {
2677
+ } else if (!store) {
2683
2678
  warnings.push({
2684
2679
  type: "other",
2685
2680
  message: `Results for OpenAI tool ${part.toolName} are not sent to the API when store is false`
@@ -2746,6 +2741,10 @@ async function convertToOpenAIResponsesInput({
2746
2741
  break;
2747
2742
  }
2748
2743
  case "tool": {
2744
+ console.log("CALDEBUG [convertToOpenAIResponsesInput] Processing tool role message:", {
2745
+ partsCount: content.length,
2746
+ partTypes: content.map((p) => p.type)
2747
+ });
2749
2748
  for (const part of content) {
2750
2749
  if (part.type === "tool-approval-response") {
2751
2750
  const approvalResponse = part;
@@ -2769,6 +2768,13 @@ async function convertToOpenAIResponsesInput({
2769
2768
  const output = part.output;
2770
2769
  if (output.type === "execution-denied") {
2771
2770
  const approvalId = (_l = (_k = output.providerOptions) == null ? void 0 : _k.openai) == null ? void 0 : _l.approvalId;
2771
+ console.log("CALDEBUG [convertToOpenAIResponsesInput] Found execution-denied:", {
2772
+ toolCallId: part.toolCallId,
2773
+ toolName: part.toolName,
2774
+ hasApprovalId: !!approvalId,
2775
+ approvalId,
2776
+ willSkip: !!approvalId
2777
+ });
2772
2778
  if (approvalId) {
2773
2779
  continue;
2774
2780
  }
@@ -3829,7 +3835,12 @@ var openaiResponsesProviderOptionsSchema = lazySchema15(
3829
3835
  * Whether the request contains tool approval responses.
3830
3836
  * Defaults to `false`.
3831
3837
  */
3832
- containsApprovalResponses: z17.boolean().optional()
3838
+ containsApprovalResponses: z17.boolean().optional(),
3839
+ /**
3840
+ * Array of tool call IDs that have approval responses (approved or denied).
3841
+ * Used to skip item_reference for tools that had user approval flow.
3842
+ */
3843
+ approvalToolCallIds: z17.array(z17.string()).optional()
3833
3844
  })
3834
3845
  )
3835
3846
  );
@@ -4378,7 +4389,7 @@ var OpenAIResponsesLanguageModel = class {
4378
4389
  toolChoice,
4379
4390
  responseFormat
4380
4391
  }) {
4381
- var _a, _b, _c, _d, _e, _f, _g, _h;
4392
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4382
4393
  const warnings = [];
4383
4394
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
4384
4395
  if (topK != null) {
@@ -4443,10 +4454,11 @@ var OpenAIResponsesLanguageModel = class {
4443
4454
  hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
4444
4455
  compactionInput: openaiOptions == null ? void 0 : openaiOptions.compactionInput,
4445
4456
  previousResponseId: (_d = openaiOptions == null ? void 0 : openaiOptions.previousResponseId) != null ? _d : void 0,
4446
- containsApprovalResponses: (_e = openaiOptions == null ? void 0 : openaiOptions.containsApprovalResponses) != null ? _e : false
4457
+ containsApprovalResponses: (_e = openaiOptions == null ? void 0 : openaiOptions.containsApprovalResponses) != null ? _e : false,
4458
+ approvalToolCallIds: (_f = openaiOptions == null ? void 0 : openaiOptions.approvalToolCallIds) != null ? _f : void 0
4447
4459
  });
4448
4460
  warnings.push(...inputWarnings);
4449
- const strictJsonSchema = (_f = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _f : true;
4461
+ const strictJsonSchema = (_g = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _g : true;
4450
4462
  let include = openaiOptions == null ? void 0 : openaiOptions.include;
4451
4463
  function addInclude(key) {
4452
4464
  if (include == null) {
@@ -4462,9 +4474,9 @@ var OpenAIResponsesLanguageModel = class {
4462
4474
  if (topLogprobs) {
4463
4475
  addInclude("message.output_text.logprobs");
4464
4476
  }
4465
- const webSearchToolName = (_g = tools == null ? void 0 : tools.find(
4477
+ const webSearchToolName = (_h = tools == null ? void 0 : tools.find(
4466
4478
  (tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
4467
- )) == null ? void 0 : _g.name;
4479
+ )) == null ? void 0 : _h.name;
4468
4480
  if (webSearchToolName) {
4469
4481
  addInclude("web_search_call.action.sources");
4470
4482
  }
@@ -4487,7 +4499,7 @@ var OpenAIResponsesLanguageModel = class {
4487
4499
  format: responseFormat.schema != null ? {
4488
4500
  type: "json_schema",
4489
4501
  strict: strictJsonSchema,
4490
- name: (_h = responseFormat.name) != null ? _h : "response",
4502
+ name: (_i = responseFormat.name) != null ? _i : "response",
4491
4503
  description: responseFormat.description,
4492
4504
  schema: responseFormat.schema
4493
4505
  } : { type: "json_object" }