@zenning/openai 3.0.8 → 3.0.11
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/CHANGELOG.md +19 -0
- package/dist/index.js +64 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -3
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +63 -2
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +63 -2
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/internal/index.mjs
CHANGED
|
@@ -2496,6 +2496,39 @@ async function convertToOpenAIResponsesInput({
|
|
|
2496
2496
|
const input = [];
|
|
2497
2497
|
const warnings = [];
|
|
2498
2498
|
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
2499
|
+
const approvalIdToToolCallId = /* @__PURE__ */ new Map();
|
|
2500
|
+
for (const message of prompt) {
|
|
2501
|
+
if (message.role === "assistant" && Array.isArray(message.content)) {
|
|
2502
|
+
const approvalRequests = message.content.filter(
|
|
2503
|
+
(p) => p.type === "tool-approval-request"
|
|
2504
|
+
);
|
|
2505
|
+
for (const req of approvalRequests) {
|
|
2506
|
+
approvalIdToToolCallId.set(req.approvalId, req.toolCallId);
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
console.log("[OpenAI Provider] approvalIdToToolCallId:", approvalIdToToolCallId);
|
|
2511
|
+
const toolCallsWithApprovalResponses = /* @__PURE__ */ new Set();
|
|
2512
|
+
for (const message of prompt) {
|
|
2513
|
+
if (message.role === "tool") {
|
|
2514
|
+
for (const part of message.content) {
|
|
2515
|
+
if (part.type === "tool-approval-response") {
|
|
2516
|
+
const toolCallId = approvalIdToToolCallId.get(part.approvalId);
|
|
2517
|
+
console.log("[OpenAI Provider] Found approval response:", {
|
|
2518
|
+
approvalId: part.approvalId,
|
|
2519
|
+
toolCallId
|
|
2520
|
+
});
|
|
2521
|
+
if (toolCallId) {
|
|
2522
|
+
toolCallsWithApprovalResponses.add(toolCallId);
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
console.log(
|
|
2529
|
+
"[OpenAI Provider] toolCallsWithApprovalResponses:",
|
|
2530
|
+
toolCallsWithApprovalResponses
|
|
2531
|
+
);
|
|
2499
2532
|
if (compactionInput && compactionInput.length > 0) {
|
|
2500
2533
|
input.push(...compactionInput);
|
|
2501
2534
|
}
|
|
@@ -2573,6 +2606,14 @@ async function convertToOpenAIResponsesInput({
|
|
|
2573
2606
|
}
|
|
2574
2607
|
case "assistant": {
|
|
2575
2608
|
const reasoningMessages = {};
|
|
2609
|
+
const toolCallsWithApprovalRequest = /* @__PURE__ */ new Set();
|
|
2610
|
+
if (Array.isArray(content)) {
|
|
2611
|
+
for (const part of content) {
|
|
2612
|
+
if (part.type === "tool-approval-request") {
|
|
2613
|
+
toolCallsWithApprovalRequest.add(part.toolCallId);
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2576
2617
|
for (const part of content) {
|
|
2577
2618
|
switch (part.type) {
|
|
2578
2619
|
case "text": {
|
|
@@ -2590,13 +2631,33 @@ async function convertToOpenAIResponsesInput({
|
|
|
2590
2631
|
}
|
|
2591
2632
|
case "tool-call": {
|
|
2592
2633
|
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;
|
|
2634
|
+
const hasApprovalResponse = toolCallsWithApprovalResponses.has(
|
|
2635
|
+
part.toolCallId
|
|
2636
|
+
);
|
|
2637
|
+
const hasApprovalRequest = toolCallsWithApprovalRequest.has(
|
|
2638
|
+
part.toolCallId
|
|
2639
|
+
);
|
|
2640
|
+
const skipItemReference = hasApprovalResponse || hasApprovalRequest && toolCallsWithApprovalResponses.size > 0;
|
|
2641
|
+
console.log("[OpenAI Provider] Processing tool-call:", {
|
|
2642
|
+
toolCallId: part.toolCallId,
|
|
2643
|
+
toolName: part.toolName,
|
|
2644
|
+
id,
|
|
2645
|
+
providerExecuted: part.providerExecuted,
|
|
2646
|
+
store,
|
|
2647
|
+
hasApprovalResponse,
|
|
2648
|
+
hasApprovalRequest,
|
|
2649
|
+
skipItemReference,
|
|
2650
|
+
willCreateItemReference: store && id != null && !skipItemReference
|
|
2651
|
+
});
|
|
2593
2652
|
if (part.providerExecuted) {
|
|
2594
|
-
if (store && id != null) {
|
|
2653
|
+
if (store && id != null && !skipItemReference) {
|
|
2654
|
+
console.log("[OpenAI Provider] Creating item_reference (providerExecuted)");
|
|
2595
2655
|
input.push({ type: "item_reference", id });
|
|
2596
2656
|
}
|
|
2597
2657
|
break;
|
|
2598
2658
|
}
|
|
2599
|
-
if (store && id != null) {
|
|
2659
|
+
if (store && id != null && !skipItemReference) {
|
|
2660
|
+
console.log("[OpenAI Provider] Creating item_reference (non-providerExecuted)");
|
|
2600
2661
|
input.push({ type: "item_reference", id });
|
|
2601
2662
|
break;
|
|
2602
2663
|
}
|