@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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.23
4
+
5
+ ### Patch Changes
6
+
7
+ - grg
8
+
9
+ ## 6.0.22
10
+
11
+ ### Patch Changes
12
+
13
+ - reep
14
+
3
15
  ## 6.0.21
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1001,7 +1001,7 @@ var import_provider_utils3 = require("@zenning/provider-utils");
1001
1001
  var import_provider_utils4 = require("@zenning/provider-utils");
1002
1002
 
1003
1003
  // src/version.ts
1004
- var VERSION = true ? "6.0.18" : "0.0.0-test";
1004
+ var VERSION = true ? "6.0.23" : "0.0.0-test";
1005
1005
 
1006
1006
  // src/util/download/download.ts
1007
1007
  var download = async ({ url }) => {
@@ -2383,8 +2383,9 @@ function prepareRetries({
2383
2383
  // src/generate-text/collect-tool-approvals.ts
2384
2384
  function collectToolApprovals({
2385
2385
  messages,
2386
- skipValidation = false
2386
+ allowMissingApprovalContext = false
2387
2387
  }) {
2388
+ var _a16;
2388
2389
  const lastMessage = messages.at(-1);
2389
2390
  if ((lastMessage == null ? void 0 : lastMessage.role) != "tool") {
2390
2391
  return {
@@ -2426,27 +2427,40 @@ function collectToolApprovals({
2426
2427
  (part) => part.type === "tool-approval-response"
2427
2428
  );
2428
2429
  for (const approvalResponse of approvalResponses) {
2429
- const approvalRequest = toolApprovalRequestsByApprovalId[approvalResponse.approvalId];
2430
+ let approvalRequest = toolApprovalRequestsByApprovalId[approvalResponse.approvalId];
2430
2431
  if (approvalRequest == null) {
2431
- if (!skipValidation) {
2432
+ if (allowMissingApprovalContext) {
2433
+ const toolCallId = (_a16 = approvalResponse.toolCallId) != null ? _a16 : approvalResponse.approvalId;
2434
+ approvalRequest = {
2435
+ type: "tool-approval-request",
2436
+ approvalId: approvalResponse.approvalId,
2437
+ toolCallId
2438
+ };
2439
+ } else {
2432
2440
  throw new InvalidToolApprovalError({
2433
2441
  approvalId: approvalResponse.approvalId
2434
2442
  });
2435
2443
  }
2436
- continue;
2437
2444
  }
2438
2445
  if (toolResults[approvalRequest.toolCallId] != null) {
2439
2446
  continue;
2440
2447
  }
2441
- const toolCall = toolCallsByToolCallId[approvalRequest.toolCallId];
2448
+ let toolCall = toolCallsByToolCallId[approvalRequest.toolCallId];
2442
2449
  if (toolCall == null) {
2443
- if (!skipValidation) {
2450
+ if (allowMissingApprovalContext) {
2451
+ toolCall = {
2452
+ type: "tool-call",
2453
+ toolCallId: approvalRequest.toolCallId,
2454
+ toolName: "unknown",
2455
+ input: {},
2456
+ providerExecuted: true
2457
+ };
2458
+ } else {
2444
2459
  throw new ToolCallNotFoundForApprovalError({
2445
2460
  toolCallId: approvalRequest.toolCallId,
2446
2461
  approvalId: approvalRequest.approvalId
2447
2462
  });
2448
2463
  }
2449
- continue;
2450
2464
  }
2451
2465
  const approval = {
2452
2466
  approvalRequest,
@@ -3679,7 +3693,7 @@ async function generateText({
3679
3693
  const responseMessages = [];
3680
3694
  const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({
3681
3695
  messages: initialMessages,
3682
- skipValidation: ((_a16 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a16.previousResponseId) != null
3696
+ allowMissingApprovalContext: !!((_a16 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a16.previousResponseId)
3683
3697
  });
3684
3698
  const localApprovedToolApprovals = approvedToolApprovals.filter(
3685
3699
  (toolApproval) => !toolApproval.toolCall.providerExecuted
@@ -6189,7 +6203,7 @@ var DefaultStreamTextResult = class {
6189
6203
  const initialResponseMessages = [];
6190
6204
  const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({
6191
6205
  messages: initialMessages,
6192
- skipValidation: ((_a16 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a16.previousResponseId) != null
6206
+ allowMissingApprovalContext: !!((_a16 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a16.previousResponseId)
6193
6207
  });
6194
6208
  if (deniedToolApprovals.length > 0 || approvedToolApprovals.length > 0) {
6195
6209
  const providerExecutedToolApprovals = [
@@ -7502,11 +7516,6 @@ async function convertToModelMessages(messages, options) {
7502
7516
  ...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
7503
7517
  });
7504
7518
  if (part.approval != null) {
7505
- console.log("[SDK convertToModelMessages] Creating tool-approval-request:", {
7506
- approvalId: part.approval.id,
7507
- toolCallId: part.toolCallId,
7508
- toolName
7509
- });
7510
7519
  content.push({
7511
7520
  type: "tool-approval-request",
7512
7521
  approvalId: part.approval.id,
@@ -7557,12 +7566,6 @@ async function convertToModelMessages(messages, options) {
7557
7566
  const content2 = [];
7558
7567
  for (const toolPart of toolParts) {
7559
7568
  if (((_d = toolPart.approval) == null ? void 0 : _d.approved) != null) {
7560
- console.log("[SDK convertToModelMessages] Creating tool-approval-response:", {
7561
- approvalId: toolPart.approval.id,
7562
- approved: toolPart.approval.approved,
7563
- toolCallId: toolPart.toolCallId,
7564
- toolName: getToolName(toolPart)
7565
- });
7566
7569
  content2.push({
7567
7570
  type: "tool-approval-response",
7568
7571
  approvalId: toolPart.approval.id,