ai 6.0.237 → 6.0.239
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 +19 -0
- package/dist/index.d.mts +16 -6
- package/dist/index.d.ts +16 -6
- package/dist/index.js +144 -117
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +144 -117
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/docs/03-agents/02-building-agents.mdx +4 -0
- package/docs/03-agents/04-loop-control.mdx +40 -0
- package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +24 -9
- package/docs/03-ai-sdk-core/60-telemetry.mdx +4 -4
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +64 -6
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +57 -1
- package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +7 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-output-generated-error.mdx +5 -0
- package/docs/08-migration-guides/26-migration-guide-5-0.mdx +40 -3
- package/package.json +3 -3
- package/src/generate-text/generate-text-result.ts +6 -2
- package/src/generate-text/generate-text.ts +17 -9
- package/src/generate-text/prepare-step-call-settings.ts +30 -0
- package/src/generate-text/prepare-step.ts +20 -3
- package/src/generate-text/step-result.ts +2 -1
- package/src/generate-text/stream-text.ts +26 -10
package/dist/index.mjs
CHANGED
|
@@ -1193,7 +1193,7 @@ import {
|
|
|
1193
1193
|
} from "@ai-sdk/provider-utils";
|
|
1194
1194
|
|
|
1195
1195
|
// src/version.ts
|
|
1196
|
-
var VERSION = true ? "6.0.
|
|
1196
|
+
var VERSION = true ? "6.0.239" : "0.0.0-test";
|
|
1197
1197
|
|
|
1198
1198
|
// src/util/download/download.ts
|
|
1199
1199
|
var download = async ({
|
|
@@ -4108,6 +4108,24 @@ async function doParseToolCall({
|
|
|
4108
4108
|
};
|
|
4109
4109
|
}
|
|
4110
4110
|
|
|
4111
|
+
// src/generate-text/prepare-step-call-settings.ts
|
|
4112
|
+
function prepareStepCallSettings({
|
|
4113
|
+
callSettings,
|
|
4114
|
+
stepSettings
|
|
4115
|
+
}) {
|
|
4116
|
+
var _a22, _b, _c, _d, _e, _f, _g, _h;
|
|
4117
|
+
return prepareCallSettings({
|
|
4118
|
+
maxOutputTokens: (_a22 = stepSettings == null ? void 0 : stepSettings.maxOutputTokens) != null ? _a22 : callSettings.maxOutputTokens,
|
|
4119
|
+
temperature: (_b = stepSettings == null ? void 0 : stepSettings.temperature) != null ? _b : callSettings.temperature,
|
|
4120
|
+
topP: (_c = stepSettings == null ? void 0 : stepSettings.topP) != null ? _c : callSettings.topP,
|
|
4121
|
+
topK: (_d = stepSettings == null ? void 0 : stepSettings.topK) != null ? _d : callSettings.topK,
|
|
4122
|
+
presencePenalty: (_e = stepSettings == null ? void 0 : stepSettings.presencePenalty) != null ? _e : callSettings.presencePenalty,
|
|
4123
|
+
frequencyPenalty: (_f = stepSettings == null ? void 0 : stepSettings.frequencyPenalty) != null ? _f : callSettings.frequencyPenalty,
|
|
4124
|
+
stopSequences: (_g = stepSettings == null ? void 0 : stepSettings.stopSequences) != null ? _g : callSettings.stopSequences,
|
|
4125
|
+
seed: (_h = stepSettings == null ? void 0 : stepSettings.seed) != null ? _h : callSettings.seed
|
|
4126
|
+
});
|
|
4127
|
+
}
|
|
4128
|
+
|
|
4111
4129
|
// src/generate-text/step-result.ts
|
|
4112
4130
|
var DefaultStepResult = class {
|
|
4113
4131
|
constructor({
|
|
@@ -4663,6 +4681,10 @@ async function generateText({
|
|
|
4663
4681
|
providerOptions,
|
|
4664
4682
|
prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
|
|
4665
4683
|
);
|
|
4684
|
+
const stepCallSettings = prepareStepCallSettings({
|
|
4685
|
+
callSettings: callSettings2,
|
|
4686
|
+
stepSettings: prepareStepResult
|
|
4687
|
+
});
|
|
4666
4688
|
await notify({
|
|
4667
4689
|
event: {
|
|
4668
4690
|
stepNumber: steps.length,
|
|
@@ -4690,113 +4712,110 @@ async function generateText({
|
|
|
4690
4712
|
]
|
|
4691
4713
|
});
|
|
4692
4714
|
currentModelResponse = await retry(
|
|
4693
|
-
() => {
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
attributes:
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
"gen_ai.request.top_k": settings.topK,
|
|
4728
|
-
"gen_ai.request.top_p": settings.topP
|
|
4729
|
-
}
|
|
4730
|
-
}),
|
|
4731
|
-
tracer,
|
|
4732
|
-
fn: async (span2) => {
|
|
4733
|
-
var _a24, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
|
|
4734
|
-
const result = await stepModel.doGenerate({
|
|
4735
|
-
...callSettings2,
|
|
4736
|
-
tools: stepTools,
|
|
4737
|
-
toolChoice: stepToolChoice,
|
|
4738
|
-
responseFormat: await (output == null ? void 0 : output.responseFormat),
|
|
4739
|
-
prompt: promptMessages,
|
|
4740
|
-
providerOptions: stepProviderOptions,
|
|
4741
|
-
abortSignal: mergedAbortSignal,
|
|
4742
|
-
headers: headersWithUserAgent
|
|
4743
|
-
});
|
|
4744
|
-
const responseData = {
|
|
4745
|
-
id: (_b2 = (_a24 = result.response) == null ? void 0 : _a24.id) != null ? _b2 : generateId2(),
|
|
4746
|
-
timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : /* @__PURE__ */ new Date(),
|
|
4747
|
-
modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : stepModel.modelId,
|
|
4748
|
-
headers: (_g2 = result.response) == null ? void 0 : _g2.headers,
|
|
4749
|
-
body: (_h2 = result.response) == null ? void 0 : _h2.body
|
|
4750
|
-
};
|
|
4751
|
-
const usage = asLanguageModelUsage(result.usage);
|
|
4752
|
-
span2.setAttributes(
|
|
4753
|
-
await selectTelemetryAttributes({
|
|
4754
|
-
telemetry,
|
|
4755
|
-
attributes: {
|
|
4756
|
-
"ai.response.finishReason": result.finishReason.unified,
|
|
4757
|
-
"ai.response.text": {
|
|
4758
|
-
output: () => extractTextContent(result.content)
|
|
4759
|
-
},
|
|
4760
|
-
"ai.response.reasoning": {
|
|
4761
|
-
output: () => extractReasoningContent(result.content)
|
|
4762
|
-
},
|
|
4763
|
-
"ai.response.toolCalls": {
|
|
4764
|
-
output: () => {
|
|
4765
|
-
const toolCalls = asToolCalls(result.content);
|
|
4766
|
-
return toolCalls == null ? void 0 : JSON.stringify(toolCalls);
|
|
4767
|
-
}
|
|
4768
|
-
},
|
|
4769
|
-
"ai.response.id": responseData.id,
|
|
4770
|
-
"ai.response.model": responseData.modelId,
|
|
4771
|
-
"ai.response.timestamp": responseData.timestamp.toISOString(),
|
|
4772
|
-
"ai.response.providerMetadata": JSON.stringify(
|
|
4773
|
-
result.providerMetadata
|
|
4774
|
-
),
|
|
4775
|
-
"ai.usage.inputTokens": result.usage.inputTokens.total,
|
|
4776
|
-
"ai.usage.inputTokenDetails.noCacheTokens": result.usage.inputTokens.noCache,
|
|
4777
|
-
"ai.usage.inputTokenDetails.cacheReadTokens": result.usage.inputTokens.cacheRead,
|
|
4778
|
-
"ai.usage.inputTokenDetails.cacheWriteTokens": result.usage.inputTokens.cacheWrite,
|
|
4779
|
-
"ai.usage.outputTokens": result.usage.outputTokens.total,
|
|
4780
|
-
"ai.usage.outputTokenDetails.textTokens": result.usage.outputTokens.text,
|
|
4781
|
-
"ai.usage.outputTokenDetails.reasoningTokens": result.usage.outputTokens.reasoning,
|
|
4782
|
-
"ai.usage.totalTokens": usage.totalTokens,
|
|
4783
|
-
"ai.usage.reasoningTokens": result.usage.outputTokens.reasoning,
|
|
4784
|
-
"ai.usage.cachedInputTokens": result.usage.inputTokens.cacheRead,
|
|
4785
|
-
// standardized gen-ai llm span attributes:
|
|
4786
|
-
"gen_ai.response.finish_reasons": [
|
|
4787
|
-
result.finishReason.unified
|
|
4788
|
-
],
|
|
4789
|
-
"gen_ai.response.id": responseData.id,
|
|
4790
|
-
"gen_ai.response.model": responseData.modelId,
|
|
4791
|
-
"gen_ai.usage.input_tokens": result.usage.inputTokens.total,
|
|
4792
|
-
"gen_ai.usage.output_tokens": result.usage.outputTokens.total
|
|
4793
|
-
}
|
|
4794
|
-
})
|
|
4795
|
-
);
|
|
4796
|
-
return { ...result, response: responseData };
|
|
4715
|
+
() => recordSpan({
|
|
4716
|
+
name: "ai.generateText.doGenerate",
|
|
4717
|
+
attributes: selectTelemetryAttributes({
|
|
4718
|
+
telemetry,
|
|
4719
|
+
attributes: {
|
|
4720
|
+
...assembleOperationName({
|
|
4721
|
+
operationId: "ai.generateText.doGenerate",
|
|
4722
|
+
telemetry
|
|
4723
|
+
}),
|
|
4724
|
+
...baseTelemetryAttributes,
|
|
4725
|
+
// model:
|
|
4726
|
+
"ai.model.provider": stepModel.provider,
|
|
4727
|
+
"ai.model.id": stepModel.modelId,
|
|
4728
|
+
// prompt:
|
|
4729
|
+
"ai.prompt.messages": {
|
|
4730
|
+
input: () => stringifyForTelemetry(promptMessages)
|
|
4731
|
+
},
|
|
4732
|
+
"ai.prompt.tools": {
|
|
4733
|
+
// convert the language model level tools:
|
|
4734
|
+
input: () => stepTools == null ? void 0 : stepTools.map((tool2) => JSON.stringify(tool2))
|
|
4735
|
+
},
|
|
4736
|
+
"ai.prompt.toolChoice": {
|
|
4737
|
+
input: () => stepToolChoice != null ? JSON.stringify(stepToolChoice) : void 0
|
|
4738
|
+
},
|
|
4739
|
+
// standardized gen-ai llm span attributes:
|
|
4740
|
+
"gen_ai.system": stepModel.provider,
|
|
4741
|
+
"gen_ai.request.model": stepModel.modelId,
|
|
4742
|
+
"gen_ai.request.frequency_penalty": stepCallSettings.frequencyPenalty,
|
|
4743
|
+
"gen_ai.request.max_tokens": stepCallSettings.maxOutputTokens,
|
|
4744
|
+
"gen_ai.request.presence_penalty": stepCallSettings.presencePenalty,
|
|
4745
|
+
"gen_ai.request.stop_sequences": stepCallSettings.stopSequences,
|
|
4746
|
+
"gen_ai.request.temperature": stepCallSettings.temperature,
|
|
4747
|
+
"gen_ai.request.top_k": stepCallSettings.topK,
|
|
4748
|
+
"gen_ai.request.top_p": stepCallSettings.topP
|
|
4797
4749
|
}
|
|
4798
|
-
})
|
|
4799
|
-
|
|
4750
|
+
}),
|
|
4751
|
+
tracer,
|
|
4752
|
+
fn: async (span2) => {
|
|
4753
|
+
var _a23, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
|
|
4754
|
+
const result = await stepModel.doGenerate({
|
|
4755
|
+
...stepCallSettings,
|
|
4756
|
+
tools: stepTools,
|
|
4757
|
+
toolChoice: stepToolChoice,
|
|
4758
|
+
responseFormat: await (output == null ? void 0 : output.responseFormat),
|
|
4759
|
+
prompt: promptMessages,
|
|
4760
|
+
providerOptions: stepProviderOptions,
|
|
4761
|
+
abortSignal: mergedAbortSignal,
|
|
4762
|
+
headers: headersWithUserAgent
|
|
4763
|
+
});
|
|
4764
|
+
const responseData = {
|
|
4765
|
+
id: (_b2 = (_a23 = result.response) == null ? void 0 : _a23.id) != null ? _b2 : generateId2(),
|
|
4766
|
+
timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : /* @__PURE__ */ new Date(),
|
|
4767
|
+
modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : stepModel.modelId,
|
|
4768
|
+
headers: (_g2 = result.response) == null ? void 0 : _g2.headers,
|
|
4769
|
+
body: (_h2 = result.response) == null ? void 0 : _h2.body
|
|
4770
|
+
};
|
|
4771
|
+
const usage = asLanguageModelUsage(result.usage);
|
|
4772
|
+
span2.setAttributes(
|
|
4773
|
+
await selectTelemetryAttributes({
|
|
4774
|
+
telemetry,
|
|
4775
|
+
attributes: {
|
|
4776
|
+
"ai.response.finishReason": result.finishReason.unified,
|
|
4777
|
+
"ai.response.text": {
|
|
4778
|
+
output: () => extractTextContent(result.content)
|
|
4779
|
+
},
|
|
4780
|
+
"ai.response.reasoning": {
|
|
4781
|
+
output: () => extractReasoningContent(result.content)
|
|
4782
|
+
},
|
|
4783
|
+
"ai.response.toolCalls": {
|
|
4784
|
+
output: () => {
|
|
4785
|
+
const toolCalls = asToolCalls(result.content);
|
|
4786
|
+
return toolCalls == null ? void 0 : JSON.stringify(toolCalls);
|
|
4787
|
+
}
|
|
4788
|
+
},
|
|
4789
|
+
"ai.response.id": responseData.id,
|
|
4790
|
+
"ai.response.model": responseData.modelId,
|
|
4791
|
+
"ai.response.timestamp": responseData.timestamp.toISOString(),
|
|
4792
|
+
"ai.response.providerMetadata": JSON.stringify(
|
|
4793
|
+
result.providerMetadata
|
|
4794
|
+
),
|
|
4795
|
+
"ai.usage.inputTokens": result.usage.inputTokens.total,
|
|
4796
|
+
"ai.usage.inputTokenDetails.noCacheTokens": result.usage.inputTokens.noCache,
|
|
4797
|
+
"ai.usage.inputTokenDetails.cacheReadTokens": result.usage.inputTokens.cacheRead,
|
|
4798
|
+
"ai.usage.inputTokenDetails.cacheWriteTokens": result.usage.inputTokens.cacheWrite,
|
|
4799
|
+
"ai.usage.outputTokens": result.usage.outputTokens.total,
|
|
4800
|
+
"ai.usage.outputTokenDetails.textTokens": result.usage.outputTokens.text,
|
|
4801
|
+
"ai.usage.outputTokenDetails.reasoningTokens": result.usage.outputTokens.reasoning,
|
|
4802
|
+
"ai.usage.totalTokens": usage.totalTokens,
|
|
4803
|
+
"ai.usage.reasoningTokens": result.usage.outputTokens.reasoning,
|
|
4804
|
+
"ai.usage.cachedInputTokens": result.usage.inputTokens.cacheRead,
|
|
4805
|
+
// standardized gen-ai llm span attributes:
|
|
4806
|
+
"gen_ai.response.finish_reasons": [
|
|
4807
|
+
result.finishReason.unified
|
|
4808
|
+
],
|
|
4809
|
+
"gen_ai.response.id": responseData.id,
|
|
4810
|
+
"gen_ai.response.model": responseData.modelId,
|
|
4811
|
+
"gen_ai.usage.input_tokens": result.usage.inputTokens.total,
|
|
4812
|
+
"gen_ai.usage.output_tokens": result.usage.outputTokens.total
|
|
4813
|
+
}
|
|
4814
|
+
})
|
|
4815
|
+
);
|
|
4816
|
+
return { ...result, response: responseData };
|
|
4817
|
+
}
|
|
4818
|
+
})
|
|
4800
4819
|
);
|
|
4801
4820
|
const stepToolCalls = await Promise.all(
|
|
4802
4821
|
currentModelResponse.content.filter(
|
|
@@ -7072,6 +7091,10 @@ function createOutputTransformStream(output) {
|
|
|
7072
7091
|
text2 += chunk.text;
|
|
7073
7092
|
textChunk += chunk.text;
|
|
7074
7093
|
textProviderMetadata = (_a22 = chunk.providerMetadata) != null ? _a22 : textProviderMetadata;
|
|
7094
|
+
if (chunk.text.length === 0 && chunk.providerMetadata != null) {
|
|
7095
|
+
controller.enqueue({ part: chunk, partialOutput: void 0 });
|
|
7096
|
+
return;
|
|
7097
|
+
}
|
|
7075
7098
|
const result = await output.parsePartialOutput({ text: text2 });
|
|
7076
7099
|
if (result !== void 0) {
|
|
7077
7100
|
const currentValue = typeof result.partial === "string" ? result.partial : JSON.stringify(result.partial);
|
|
@@ -7723,6 +7746,10 @@ var DefaultStreamTextResult = class {
|
|
|
7723
7746
|
providerOptions,
|
|
7724
7747
|
prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
|
|
7725
7748
|
);
|
|
7749
|
+
const stepCallSettings = prepareStepCallSettings({
|
|
7750
|
+
callSettings,
|
|
7751
|
+
stepSettings: prepareStepResult
|
|
7752
|
+
});
|
|
7726
7753
|
await notify({
|
|
7727
7754
|
event: {
|
|
7728
7755
|
stepNumber: recordedSteps.length,
|
|
@@ -7780,13 +7807,13 @@ var DefaultStreamTextResult = class {
|
|
|
7780
7807
|
// standardized gen-ai llm span attributes:
|
|
7781
7808
|
"gen_ai.system": stepModel.provider,
|
|
7782
7809
|
"gen_ai.request.model": stepModel.modelId,
|
|
7783
|
-
"gen_ai.request.frequency_penalty":
|
|
7784
|
-
"gen_ai.request.max_tokens":
|
|
7785
|
-
"gen_ai.request.presence_penalty":
|
|
7786
|
-
"gen_ai.request.stop_sequences":
|
|
7787
|
-
"gen_ai.request.temperature":
|
|
7788
|
-
"gen_ai.request.top_k":
|
|
7789
|
-
"gen_ai.request.top_p":
|
|
7810
|
+
"gen_ai.request.frequency_penalty": stepCallSettings.frequencyPenalty,
|
|
7811
|
+
"gen_ai.request.max_tokens": stepCallSettings.maxOutputTokens,
|
|
7812
|
+
"gen_ai.request.presence_penalty": stepCallSettings.presencePenalty,
|
|
7813
|
+
"gen_ai.request.stop_sequences": stepCallSettings.stopSequences,
|
|
7814
|
+
"gen_ai.request.temperature": stepCallSettings.temperature,
|
|
7815
|
+
"gen_ai.request.top_k": stepCallSettings.topK,
|
|
7816
|
+
"gen_ai.request.top_p": stepCallSettings.topP
|
|
7790
7817
|
}
|
|
7791
7818
|
}),
|
|
7792
7819
|
tracer,
|
|
@@ -7796,7 +7823,7 @@ var DefaultStreamTextResult = class {
|
|
|
7796
7823
|
// get before the call
|
|
7797
7824
|
doStreamSpan: doStreamSpan2,
|
|
7798
7825
|
result: await stepModel.doStream({
|
|
7799
|
-
...
|
|
7826
|
+
...stepCallSettings,
|
|
7800
7827
|
tools: stepTools,
|
|
7801
7828
|
toolChoice: stepToolChoice,
|
|
7802
7829
|
responseFormat: await (output == null ? void 0 : output.responseFormat),
|
|
@@ -7887,15 +7914,15 @@ var DefaultStreamTextResult = class {
|
|
|
7887
7914
|
break;
|
|
7888
7915
|
}
|
|
7889
7916
|
case "text-delta": {
|
|
7890
|
-
if (chunk.delta.length > 0) {
|
|
7917
|
+
if (chunk.delta.length > 0 || chunk.providerMetadata != null) {
|
|
7891
7918
|
controller.enqueue({
|
|
7892
7919
|
type: "text-delta",
|
|
7893
7920
|
id: chunk.id,
|
|
7894
7921
|
text: chunk.delta,
|
|
7895
7922
|
providerMetadata: chunk.providerMetadata
|
|
7896
7923
|
});
|
|
7897
|
-
activeText += chunk.delta;
|
|
7898
7924
|
}
|
|
7925
|
+
activeText += chunk.delta;
|
|
7899
7926
|
break;
|
|
7900
7927
|
}
|
|
7901
7928
|
case "reasoning-start":
|