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 +13 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +34 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -8
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +6 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-tool-choice-violation-error.mdx +11 -6
- package/package.json +3 -3
- package/src/error/tool-choice-violation-error.ts +6 -4
- package/src/generate-text/generate-text.ts +14 -10
- package/src/generate-text/run-tools-transformation.ts +53 -1
- package/src/generate-text/stream-text.ts +1 -0
package/dist/index.mjs
CHANGED
|
@@ -401,7 +401,7 @@ var ToolChoiceViolationError = class extends AISDKError15 {
|
|
|
401
401
|
provider,
|
|
402
402
|
modelId,
|
|
403
403
|
content,
|
|
404
|
-
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}'.`
|
|
404
|
+
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}'.`
|
|
405
405
|
}) {
|
|
406
406
|
super({ name: name15, message });
|
|
407
407
|
this[_a15] = true;
|
|
@@ -1225,7 +1225,7 @@ import {
|
|
|
1225
1225
|
} from "@ai-sdk/provider-utils";
|
|
1226
1226
|
|
|
1227
1227
|
// src/version.ts
|
|
1228
|
-
var VERSION = true ? "6.0.
|
|
1228
|
+
var VERSION = true ? "6.0.315" : "0.0.0-test";
|
|
1229
1229
|
|
|
1230
1230
|
// src/util/download/download.ts
|
|
1231
1231
|
var download = async ({
|
|
@@ -4965,16 +4965,18 @@ async function generateText({
|
|
|
4965
4965
|
(toolCall) => parseToolCall({
|
|
4966
4966
|
toolCall,
|
|
4967
4967
|
tools: stepToolSet,
|
|
4968
|
-
|
|
4968
|
+
// tool calls are rejected with tool choice none,
|
|
4969
|
+
// so user callbacks must not process them:
|
|
4970
|
+
repairToolCall: (stepToolChoice == null ? void 0 : stepToolChoice.type) === "none" ? void 0 : repairToolCall,
|
|
4969
4971
|
system,
|
|
4970
4972
|
messages: stepInputMessages
|
|
4971
4973
|
})
|
|
4972
4974
|
)
|
|
4973
4975
|
);
|
|
4974
|
-
const enforcedToolChoice = (stepToolChoice == null ? void 0 : stepToolChoice.type) === "
|
|
4975
|
-
if (enforcedToolChoice != null && !stepToolCalls.some(
|
|
4976
|
+
const enforcedToolChoice = (stepToolChoice == null ? void 0 : stepToolChoice.type) === "auto" ? void 0 : stepToolChoice;
|
|
4977
|
+
if (enforcedToolChoice != null && (enforcedToolChoice.type === "none" ? stepToolCalls.length > 0 : !stepToolCalls.some(
|
|
4976
4978
|
(toolCall) => enforcedToolChoice.type === "required" || toolCall.toolName === enforcedToolChoice.toolName
|
|
4977
|
-
)) {
|
|
4979
|
+
))) {
|
|
4978
4980
|
throw new ToolChoiceViolationError({
|
|
4979
4981
|
toolChoice: enforcedToolChoice,
|
|
4980
4982
|
finishReason: currentModelResponse.finishReason.unified,
|
|
@@ -7035,6 +7037,7 @@ import {
|
|
|
7035
7037
|
} from "@ai-sdk/provider-utils";
|
|
7036
7038
|
function runToolsTransformation({
|
|
7037
7039
|
tools,
|
|
7040
|
+
toolChoice,
|
|
7038
7041
|
generatorStream,
|
|
7039
7042
|
tracer,
|
|
7040
7043
|
telemetry,
|
|
@@ -7124,10 +7127,19 @@ function runToolsTransformation({
|
|
|
7124
7127
|
});
|
|
7125
7128
|
}
|
|
7126
7129
|
const activeToolCallToolNames = /* @__PURE__ */ new Map();
|
|
7130
|
+
const withholdToolParts = (toolChoice == null ? void 0 : toolChoice.type) === "none";
|
|
7131
|
+
const withheldToolContent = [];
|
|
7127
7132
|
const forwardStream = new TransformStream({
|
|
7128
7133
|
async transform(chunk, controller) {
|
|
7129
|
-
var _a23, _b, _c, _d;
|
|
7134
|
+
var _a23, _b, _c, _d, _e, _f;
|
|
7130
7135
|
const chunkType = chunk.type;
|
|
7136
|
+
if (withholdToolParts && (chunkType === "tool-input-start" || chunkType === "tool-input-delta" || chunkType === "tool-input-end" || chunkType === "tool-approval-request")) {
|
|
7137
|
+
return;
|
|
7138
|
+
}
|
|
7139
|
+
if (withholdToolParts && (chunkType === "tool-call" || chunkType === "tool-result")) {
|
|
7140
|
+
withheldToolContent.push(chunk);
|
|
7141
|
+
return;
|
|
7142
|
+
}
|
|
7131
7143
|
switch (chunkType) {
|
|
7132
7144
|
case "stream-start":
|
|
7133
7145
|
case "text-start":
|
|
@@ -7185,13 +7197,26 @@ function runToolsTransformation({
|
|
|
7185
7197
|
break;
|
|
7186
7198
|
}
|
|
7187
7199
|
case "finish": {
|
|
7200
|
+
const toolChoiceViolationError = withholdToolParts && withheldToolContent.some((part) => part.type === "tool-call") ? new ToolChoiceViolationError({
|
|
7201
|
+
toolChoice: { type: "none" },
|
|
7202
|
+
finishReason: chunk.finishReason.unified,
|
|
7203
|
+
provider: (_e = model == null ? void 0 : model.provider) != null ? _e : "unknown",
|
|
7204
|
+
modelId: (_f = model == null ? void 0 : model.modelId) != null ? _f : "unknown",
|
|
7205
|
+
content: withheldToolContent
|
|
7206
|
+
}) : void 0;
|
|
7188
7207
|
finishChunk = {
|
|
7189
7208
|
type: "finish",
|
|
7190
|
-
finishReason: chunk.finishReason.unified,
|
|
7209
|
+
finishReason: toolChoiceViolationError == null ? chunk.finishReason.unified : "error",
|
|
7191
7210
|
rawFinishReason: chunk.finishReason.raw,
|
|
7192
7211
|
usage: asLanguageModelUsage(chunk.usage),
|
|
7193
7212
|
providerMetadata: chunk.providerMetadata
|
|
7194
7213
|
};
|
|
7214
|
+
if (toolChoiceViolationError != null) {
|
|
7215
|
+
controller.enqueue({
|
|
7216
|
+
type: "error",
|
|
7217
|
+
error: toolChoiceViolationError
|
|
7218
|
+
});
|
|
7219
|
+
}
|
|
7195
7220
|
if (isToolExecutionAllowedFinishReason(chunk.finishReason.unified)) {
|
|
7196
7221
|
for (const toolCall of toolCallsToExecute.splice(0)) {
|
|
7197
7222
|
executeToolCallAfterFinish(toolCall);
|
|
@@ -8380,6 +8405,7 @@ var DefaultStreamTextResult = class {
|
|
|
8380
8405
|
);
|
|
8381
8406
|
const streamWithToolResults = runToolsTransformation({
|
|
8382
8407
|
tools: stepToolSet,
|
|
8408
|
+
toolChoice: stepToolChoice,
|
|
8383
8409
|
generatorStream: stream2,
|
|
8384
8410
|
tracer,
|
|
8385
8411
|
telemetry,
|