@zenning/openai 3.0.7 → 3.0.10

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.
@@ -2475,6 +2475,39 @@ async function convertToOpenAIResponsesInput({
2475
2475
  const input = [];
2476
2476
  const warnings = [];
2477
2477
  const processedApprovalIds = /* @__PURE__ */ new Set();
2478
+ const approvalIdToToolCallId = /* @__PURE__ */ new Map();
2479
+ for (const message of prompt) {
2480
+ if (message.role === "assistant" && Array.isArray(message.content)) {
2481
+ const approvalRequests = message.content.filter(
2482
+ (p) => p.type === "tool-approval-request"
2483
+ );
2484
+ for (const req of approvalRequests) {
2485
+ approvalIdToToolCallId.set(req.approvalId, req.toolCallId);
2486
+ }
2487
+ }
2488
+ }
2489
+ console.log("[OpenAI Provider] approvalIdToToolCallId:", approvalIdToToolCallId);
2490
+ const toolCallsWithApprovalResponses = /* @__PURE__ */ new Set();
2491
+ for (const message of prompt) {
2492
+ if (message.role === "tool") {
2493
+ for (const part of message.content) {
2494
+ if (part.type === "tool-approval-response") {
2495
+ const toolCallId = approvalIdToToolCallId.get(part.approvalId);
2496
+ console.log("[OpenAI Provider] Found approval response:", {
2497
+ approvalId: part.approvalId,
2498
+ toolCallId
2499
+ });
2500
+ if (toolCallId) {
2501
+ toolCallsWithApprovalResponses.add(toolCallId);
2502
+ }
2503
+ }
2504
+ }
2505
+ }
2506
+ }
2507
+ console.log(
2508
+ "[OpenAI Provider] toolCallsWithApprovalResponses:",
2509
+ toolCallsWithApprovalResponses
2510
+ );
2478
2511
  if (compactionInput && compactionInput.length > 0) {
2479
2512
  input.push(...compactionInput);
2480
2513
  }
@@ -2552,6 +2585,14 @@ async function convertToOpenAIResponsesInput({
2552
2585
  }
2553
2586
  case "assistant": {
2554
2587
  const reasoningMessages = {};
2588
+ const toolCallsWithApprovalRequest = /* @__PURE__ */ new Set();
2589
+ if (Array.isArray(content)) {
2590
+ for (const part of content) {
2591
+ if (part.type === "tool-approval-request") {
2592
+ toolCallsWithApprovalRequest.add(part.toolCallId);
2593
+ }
2594
+ }
2595
+ }
2555
2596
  for (const part of content) {
2556
2597
  switch (part.type) {
2557
2598
  case "text": {
@@ -2569,13 +2610,33 @@ async function convertToOpenAIResponsesInput({
2569
2610
  }
2570
2611
  case "tool-call": {
2571
2612
  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;
2613
+ const hasApprovalResponse = toolCallsWithApprovalResponses.has(
2614
+ part.toolCallId
2615
+ );
2616
+ const hasApprovalRequest = toolCallsWithApprovalRequest.has(
2617
+ part.toolCallId
2618
+ );
2619
+ const skipItemReference = hasApprovalResponse || hasApprovalRequest && toolCallsWithApprovalResponses.size > 0;
2620
+ console.log("[OpenAI Provider] Processing tool-call:", {
2621
+ toolCallId: part.toolCallId,
2622
+ toolName: part.toolName,
2623
+ id,
2624
+ providerExecuted: part.providerExecuted,
2625
+ store,
2626
+ hasApprovalResponse,
2627
+ hasApprovalRequest,
2628
+ skipItemReference,
2629
+ willCreateItemReference: store && id != null && !skipItemReference
2630
+ });
2572
2631
  if (part.providerExecuted) {
2573
- if (store && id != null) {
2632
+ if (store && id != null && !skipItemReference) {
2633
+ console.log("[OpenAI Provider] Creating item_reference (providerExecuted)");
2574
2634
  input.push({ type: "item_reference", id });
2575
2635
  }
2576
2636
  break;
2577
2637
  }
2578
- if (store && id != null) {
2638
+ if (store && id != null && !skipItemReference) {
2639
+ console.log("[OpenAI Provider] Creating item_reference (non-providerExecuted)");
2579
2640
  input.push({ type: "item_reference", id });
2580
2641
  break;
2581
2642
  }