@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.
@@ -2471,27 +2471,21 @@ async function convertToOpenAIResponsesInput({
2471
2471
  hasApplyPatchTool = false,
2472
2472
  compactionInput,
2473
2473
  previousResponseId,
2474
- containsApprovalResponses
2474
+ containsApprovalResponses,
2475
+ approvalToolCallIds: approvalToolCallIdsArray
2475
2476
  }) {
2476
2477
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2477
2478
  const input = [];
2478
2479
  const warnings = [];
2479
2480
  const processedApprovalIds = /* @__PURE__ */ new Set();
2480
- const approvalToolCallIds = /* @__PURE__ */ new Set();
2481
- if (containsApprovalResponses) {
2482
- for (const message of prompt) {
2483
- if (message.role !== "assistant") continue;
2484
- if (typeof message.content === "string") continue;
2485
- for (const part of message.content) {
2486
- if (part.type === "tool-call") {
2487
- const approval = part.approval;
2488
- if ((approval == null ? void 0 : approval.approved) != null) {
2489
- approvalToolCallIds.add(part.toolCallId);
2490
- }
2491
- }
2492
- }
2493
- }
2494
- }
2481
+ const approvalToolCallIds = new Set(approvalToolCallIdsArray || []);
2482
+ console.log("CALDEBUG [convertToOpenAIResponsesInput] Starting conversion:", {
2483
+ containsApprovalResponses,
2484
+ approvalToolCallIdsCount: approvalToolCallIds.size,
2485
+ approvalToolCallIds: Array.from(approvalToolCallIds),
2486
+ previousResponseId,
2487
+ promptLength: prompt.length
2488
+ });
2495
2489
  if (compactionInput && compactionInput.length > 0) {
2496
2490
  input.push(...compactionInput);
2497
2491
  }
@@ -2655,10 +2649,11 @@ async function convertToOpenAIResponsesInput({
2655
2649
  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") {
2656
2650
  break;
2657
2651
  }
2658
- if (store) {
2652
+ const toolResultHadApproval = containsApprovalResponses && approvalToolCallIds.has(part.toolCallId);
2653
+ if (store && !toolResultHadApproval) {
2659
2654
  const itemId = (_j = (_i = (_h = part.providerMetadata) == null ? void 0 : _h[providerOptionsName]) == null ? void 0 : _i.itemId) != null ? _j : part.toolCallId;
2660
2655
  input.push({ type: "item_reference", id: itemId });
2661
- } else {
2656
+ } else if (!store) {
2662
2657
  warnings.push({
2663
2658
  type: "other",
2664
2659
  message: `Results for OpenAI tool ${part.toolName} are not sent to the API when store is false`
@@ -2725,6 +2720,10 @@ async function convertToOpenAIResponsesInput({
2725
2720
  break;
2726
2721
  }
2727
2722
  case "tool": {
2723
+ console.log("CALDEBUG [convertToOpenAIResponsesInput] Processing tool role message:", {
2724
+ partsCount: content.length,
2725
+ partTypes: content.map((p) => p.type)
2726
+ });
2728
2727
  for (const part of content) {
2729
2728
  if (part.type === "tool-approval-response") {
2730
2729
  const approvalResponse = part;
@@ -2748,6 +2747,13 @@ async function convertToOpenAIResponsesInput({
2748
2747
  const output = part.output;
2749
2748
  if (output.type === "execution-denied") {
2750
2749
  const approvalId = (_l = (_k = output.providerOptions) == null ? void 0 : _k.openai) == null ? void 0 : _l.approvalId;
2750
+ console.log("CALDEBUG [convertToOpenAIResponsesInput] Found execution-denied:", {
2751
+ toolCallId: part.toolCallId,
2752
+ toolName: part.toolName,
2753
+ hasApprovalId: !!approvalId,
2754
+ approvalId,
2755
+ willSkip: !!approvalId
2756
+ });
2751
2757
  if (approvalId) {
2752
2758
  continue;
2753
2759
  }
@@ -3808,7 +3814,12 @@ var openaiResponsesProviderOptionsSchema = (0, import_provider_utils24.lazySchem
3808
3814
  * Whether the request contains tool approval responses.
3809
3815
  * Defaults to `false`.
3810
3816
  */
3811
- containsApprovalResponses: import_v417.z.boolean().optional()
3817
+ containsApprovalResponses: import_v417.z.boolean().optional(),
3818
+ /**
3819
+ * Array of tool call IDs that have approval responses (approved or denied).
3820
+ * Used to skip item_reference for tools that had user approval flow.
3821
+ */
3822
+ approvalToolCallIds: import_v417.z.array(import_v417.z.string()).optional()
3812
3823
  })
3813
3824
  )
3814
3825
  );
@@ -4331,7 +4342,7 @@ var OpenAIResponsesLanguageModel = class {
4331
4342
  toolChoice,
4332
4343
  responseFormat
4333
4344
  }) {
4334
- var _a, _b, _c, _d, _e, _f, _g, _h;
4345
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4335
4346
  const warnings = [];
4336
4347
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
4337
4348
  if (topK != null) {
@@ -4396,10 +4407,11 @@ var OpenAIResponsesLanguageModel = class {
4396
4407
  hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
4397
4408
  compactionInput: openaiOptions == null ? void 0 : openaiOptions.compactionInput,
4398
4409
  previousResponseId: (_d = openaiOptions == null ? void 0 : openaiOptions.previousResponseId) != null ? _d : void 0,
4399
- containsApprovalResponses: (_e = openaiOptions == null ? void 0 : openaiOptions.containsApprovalResponses) != null ? _e : false
4410
+ containsApprovalResponses: (_e = openaiOptions == null ? void 0 : openaiOptions.containsApprovalResponses) != null ? _e : false,
4411
+ approvalToolCallIds: (_f = openaiOptions == null ? void 0 : openaiOptions.approvalToolCallIds) != null ? _f : void 0
4400
4412
  });
4401
4413
  warnings.push(...inputWarnings);
4402
- const strictJsonSchema = (_f = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _f : true;
4414
+ const strictJsonSchema = (_g = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _g : true;
4403
4415
  let include = openaiOptions == null ? void 0 : openaiOptions.include;
4404
4416
  function addInclude(key) {
4405
4417
  if (include == null) {
@@ -4415,9 +4427,9 @@ var OpenAIResponsesLanguageModel = class {
4415
4427
  if (topLogprobs) {
4416
4428
  addInclude("message.output_text.logprobs");
4417
4429
  }
4418
- const webSearchToolName = (_g = tools == null ? void 0 : tools.find(
4430
+ const webSearchToolName = (_h = tools == null ? void 0 : tools.find(
4419
4431
  (tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
4420
- )) == null ? void 0 : _g.name;
4432
+ )) == null ? void 0 : _h.name;
4421
4433
  if (webSearchToolName) {
4422
4434
  addInclude("web_search_call.action.sources");
4423
4435
  }
@@ -4440,7 +4452,7 @@ var OpenAIResponsesLanguageModel = class {
4440
4452
  format: responseFormat.schema != null ? {
4441
4453
  type: "json_schema",
4442
4454
  strict: strictJsonSchema,
4443
- name: (_h = responseFormat.name) != null ? _h : "response",
4455
+ name: (_i = responseFormat.name) != null ? _i : "response",
4444
4456
  description: responseFormat.description,
4445
4457
  schema: responseFormat.schema
4446
4458
  } : { type: "json_object" }