@zenning/ai 6.0.21 → 6.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.
package/dist/index.mjs CHANGED
@@ -898,7 +898,7 @@ import {
898
898
  } from "@zenning/provider-utils";
899
899
 
900
900
  // src/version.ts
901
- var VERSION = true ? "6.0.18" : "0.0.0-test";
901
+ var VERSION = true ? "6.0.23" : "0.0.0-test";
902
902
 
903
903
  // src/util/download/download.ts
904
904
  var download = async ({ url }) => {
@@ -2285,8 +2285,9 @@ function prepareRetries({
2285
2285
  // src/generate-text/collect-tool-approvals.ts
2286
2286
  function collectToolApprovals({
2287
2287
  messages,
2288
- skipValidation = false
2288
+ allowMissingApprovalContext = false
2289
2289
  }) {
2290
+ var _a16;
2290
2291
  const lastMessage = messages.at(-1);
2291
2292
  if ((lastMessage == null ? void 0 : lastMessage.role) != "tool") {
2292
2293
  return {
@@ -2328,27 +2329,40 @@ function collectToolApprovals({
2328
2329
  (part) => part.type === "tool-approval-response"
2329
2330
  );
2330
2331
  for (const approvalResponse of approvalResponses) {
2331
- const approvalRequest = toolApprovalRequestsByApprovalId[approvalResponse.approvalId];
2332
+ let approvalRequest = toolApprovalRequestsByApprovalId[approvalResponse.approvalId];
2332
2333
  if (approvalRequest == null) {
2333
- if (!skipValidation) {
2334
+ if (allowMissingApprovalContext) {
2335
+ const toolCallId = (_a16 = approvalResponse.toolCallId) != null ? _a16 : approvalResponse.approvalId;
2336
+ approvalRequest = {
2337
+ type: "tool-approval-request",
2338
+ approvalId: approvalResponse.approvalId,
2339
+ toolCallId
2340
+ };
2341
+ } else {
2334
2342
  throw new InvalidToolApprovalError({
2335
2343
  approvalId: approvalResponse.approvalId
2336
2344
  });
2337
2345
  }
2338
- continue;
2339
2346
  }
2340
2347
  if (toolResults[approvalRequest.toolCallId] != null) {
2341
2348
  continue;
2342
2349
  }
2343
- const toolCall = toolCallsByToolCallId[approvalRequest.toolCallId];
2350
+ let toolCall = toolCallsByToolCallId[approvalRequest.toolCallId];
2344
2351
  if (toolCall == null) {
2345
- if (!skipValidation) {
2352
+ if (allowMissingApprovalContext) {
2353
+ toolCall = {
2354
+ type: "tool-call",
2355
+ toolCallId: approvalRequest.toolCallId,
2356
+ toolName: "unknown",
2357
+ input: {},
2358
+ providerExecuted: true
2359
+ };
2360
+ } else {
2346
2361
  throw new ToolCallNotFoundForApprovalError({
2347
2362
  toolCallId: approvalRequest.toolCallId,
2348
2363
  approvalId: approvalRequest.approvalId
2349
2364
  });
2350
2365
  }
2351
- continue;
2352
2366
  }
2353
2367
  const approval = {
2354
2368
  approvalRequest,
@@ -3595,7 +3609,7 @@ async function generateText({
3595
3609
  const responseMessages = [];
3596
3610
  const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({
3597
3611
  messages: initialMessages,
3598
- skipValidation: ((_a16 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a16.previousResponseId) != null
3612
+ allowMissingApprovalContext: !!((_a16 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a16.previousResponseId)
3599
3613
  });
3600
3614
  const localApprovedToolApprovals = approvedToolApprovals.filter(
3601
3615
  (toolApproval) => !toolApproval.toolCall.providerExecuted
@@ -6113,7 +6127,7 @@ var DefaultStreamTextResult = class {
6113
6127
  const initialResponseMessages = [];
6114
6128
  const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({
6115
6129
  messages: initialMessages,
6116
- skipValidation: ((_a16 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a16.previousResponseId) != null
6130
+ allowMissingApprovalContext: !!((_a16 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a16.previousResponseId)
6117
6131
  });
6118
6132
  if (deniedToolApprovals.length > 0 || approvedToolApprovals.length > 0) {
6119
6133
  const providerExecutedToolApprovals = [
@@ -7431,11 +7445,6 @@ async function convertToModelMessages(messages, options) {
7431
7445
  ...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
7432
7446
  });
7433
7447
  if (part.approval != null) {
7434
- console.log("[SDK convertToModelMessages] Creating tool-approval-request:", {
7435
- approvalId: part.approval.id,
7436
- toolCallId: part.toolCallId,
7437
- toolName
7438
- });
7439
7448
  content.push({
7440
7449
  type: "tool-approval-request",
7441
7450
  approvalId: part.approval.id,
@@ -7486,12 +7495,6 @@ async function convertToModelMessages(messages, options) {
7486
7495
  const content2 = [];
7487
7496
  for (const toolPart of toolParts) {
7488
7497
  if (((_d = toolPart.approval) == null ? void 0 : _d.approved) != null) {
7489
- console.log("[SDK convertToModelMessages] Creating tool-approval-response:", {
7490
- approvalId: toolPart.approval.id,
7491
- approved: toolPart.approval.approved,
7492
- toolCallId: toolPart.toolCallId,
7493
- toolName: getToolName(toolPart)
7494
- });
7495
7498
  content2.push({
7496
7499
  type: "tool-approval-response",
7497
7500
  approvalId: toolPart.approval.id,