ai 6.0.313 → 6.0.315

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,18 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.315
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [e4469a3]
8
+ - @ai-sdk/gateway@3.0.221
9
+
10
+ ## 6.0.314
11
+
12
+ ### Patch Changes
13
+
14
+ - 6572f26: Fix `toolChoice: 'none'` by forwarding it to the Hugging Face Responses API and rejecting tool calls before local execution in `generateText` and `streamText`. Streamed tool parts are withheld so client-side tools cannot act on them, and `experimental_repairToolCall` is not invoked for rejected tool calls.
15
+
3
16
  ## 6.0.313
4
17
 
5
18
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -4985,6 +4985,8 @@ declare class NoVideoGeneratedError extends AISDKError {
4985
4985
 
4986
4986
  declare const symbol$7: unique symbol;
4987
4987
  type EnforcedToolChoice = Extract<LanguageModelV3ToolChoice, {
4988
+ type: 'none';
4989
+ } | {
4988
4990
  type: 'required';
4989
4991
  } | {
4990
4992
  type: 'tool';
package/dist/index.d.ts CHANGED
@@ -4985,6 +4985,8 @@ declare class NoVideoGeneratedError extends AISDKError {
4985
4985
 
4986
4986
  declare const symbol$7: unique symbol;
4987
4987
  type EnforcedToolChoice = Extract<LanguageModelV3ToolChoice, {
4988
+ type: 'none';
4989
+ } | {
4988
4990
  type: 'required';
4989
4991
  } | {
4990
4992
  type: 'tool';
package/dist/index.js CHANGED
@@ -521,7 +521,7 @@ var ToolChoiceViolationError = class extends import_provider15.AISDKError {
521
521
  provider,
522
522
  modelId,
523
523
  content,
524
- message = toolChoice.type === "required" ? "Model response did not contain a tool call even though tool choice was required." : `Model response did not contain a call to the required tool '${toolChoice.toolName}'.`
524
+ message = toolChoice.type === "none" ? "Model response contained a tool call even though tool choice was none." : toolChoice.type === "required" ? "Model response did not contain a tool call even though tool choice was required." : `Model response did not contain a call to the required tool '${toolChoice.toolName}'.`
525
525
  }) {
526
526
  super({ name: name15, message });
527
527
  this[_a15] = true;
@@ -1335,7 +1335,7 @@ function detectMediaType({
1335
1335
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
1336
1336
 
1337
1337
  // src/version.ts
1338
- var VERSION = true ? "6.0.313" : "0.0.0-test";
1338
+ var VERSION = true ? "6.0.315" : "0.0.0-test";
1339
1339
 
1340
1340
  // src/util/download/download.ts
1341
1341
  var download = async ({
@@ -5045,16 +5045,18 @@ async function generateText({
5045
5045
  (toolCall) => parseToolCall({
5046
5046
  toolCall,
5047
5047
  tools: stepToolSet,
5048
- repairToolCall,
5048
+ // tool calls are rejected with tool choice none,
5049
+ // so user callbacks must not process them:
5050
+ repairToolCall: (stepToolChoice == null ? void 0 : stepToolChoice.type) === "none" ? void 0 : repairToolCall,
5049
5051
  system,
5050
5052
  messages: stepInputMessages
5051
5053
  })
5052
5054
  )
5053
5055
  );
5054
- const enforcedToolChoice = (stepToolChoice == null ? void 0 : stepToolChoice.type) === "required" || (stepToolChoice == null ? void 0 : stepToolChoice.type) === "tool" ? stepToolChoice : void 0;
5055
- if (enforcedToolChoice != null && !stepToolCalls.some(
5056
+ const enforcedToolChoice = (stepToolChoice == null ? void 0 : stepToolChoice.type) === "auto" ? void 0 : stepToolChoice;
5057
+ if (enforcedToolChoice != null && (enforcedToolChoice.type === "none" ? stepToolCalls.length > 0 : !stepToolCalls.some(
5056
5058
  (toolCall) => enforcedToolChoice.type === "required" || toolCall.toolName === enforcedToolChoice.toolName
5057
- )) {
5059
+ ))) {
5058
5060
  throw new ToolChoiceViolationError({
5059
5061
  toolChoice: enforcedToolChoice,
5060
5062
  finishReason: currentModelResponse.finishReason.unified,
@@ -7106,6 +7108,7 @@ function createStitchableStream() {
7106
7108
  var import_provider_utils19 = require("@ai-sdk/provider-utils");
7107
7109
  function runToolsTransformation({
7108
7110
  tools,
7111
+ toolChoice,
7109
7112
  generatorStream,
7110
7113
  tracer,
7111
7114
  telemetry,
@@ -7195,10 +7198,19 @@ function runToolsTransformation({
7195
7198
  });
7196
7199
  }
7197
7200
  const activeToolCallToolNames = /* @__PURE__ */ new Map();
7201
+ const withholdToolParts = (toolChoice == null ? void 0 : toolChoice.type) === "none";
7202
+ const withheldToolContent = [];
7198
7203
  const forwardStream = new TransformStream({
7199
7204
  async transform(chunk, controller) {
7200
- var _a23, _b, _c, _d;
7205
+ var _a23, _b, _c, _d, _e, _f;
7201
7206
  const chunkType = chunk.type;
7207
+ if (withholdToolParts && (chunkType === "tool-input-start" || chunkType === "tool-input-delta" || chunkType === "tool-input-end" || chunkType === "tool-approval-request")) {
7208
+ return;
7209
+ }
7210
+ if (withholdToolParts && (chunkType === "tool-call" || chunkType === "tool-result")) {
7211
+ withheldToolContent.push(chunk);
7212
+ return;
7213
+ }
7202
7214
  switch (chunkType) {
7203
7215
  case "stream-start":
7204
7216
  case "text-start":
@@ -7256,13 +7268,26 @@ function runToolsTransformation({
7256
7268
  break;
7257
7269
  }
7258
7270
  case "finish": {
7271
+ const toolChoiceViolationError = withholdToolParts && withheldToolContent.some((part) => part.type === "tool-call") ? new ToolChoiceViolationError({
7272
+ toolChoice: { type: "none" },
7273
+ finishReason: chunk.finishReason.unified,
7274
+ provider: (_e = model == null ? void 0 : model.provider) != null ? _e : "unknown",
7275
+ modelId: (_f = model == null ? void 0 : model.modelId) != null ? _f : "unknown",
7276
+ content: withheldToolContent
7277
+ }) : void 0;
7259
7278
  finishChunk = {
7260
7279
  type: "finish",
7261
- finishReason: chunk.finishReason.unified,
7280
+ finishReason: toolChoiceViolationError == null ? chunk.finishReason.unified : "error",
7262
7281
  rawFinishReason: chunk.finishReason.raw,
7263
7282
  usage: asLanguageModelUsage(chunk.usage),
7264
7283
  providerMetadata: chunk.providerMetadata
7265
7284
  };
7285
+ if (toolChoiceViolationError != null) {
7286
+ controller.enqueue({
7287
+ type: "error",
7288
+ error: toolChoiceViolationError
7289
+ });
7290
+ }
7266
7291
  if (isToolExecutionAllowedFinishReason(chunk.finishReason.unified)) {
7267
7292
  for (const toolCall of toolCallsToExecute.splice(0)) {
7268
7293
  executeToolCallAfterFinish(toolCall);
@@ -8451,6 +8476,7 @@ var DefaultStreamTextResult = class {
8451
8476
  );
8452
8477
  const streamWithToolResults = runToolsTransformation({
8453
8478
  tools: stepToolSet,
8479
+ toolChoice: stepToolChoice,
8454
8480
  generatorStream: stream2,
8455
8481
  tracer,
8456
8482
  telemetry,