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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.239
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [d3d9e0b]
|
|
8
|
+
- @ai-sdk/gateway@3.0.161
|
|
9
|
+
|
|
10
|
+
## 6.0.238
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 9ecdefe: Prevent validated downloads on Node.js from reaching private or internal services through DNS aliases or DNS rebinding by validating and pinning every resolved address at connection time.
|
|
15
|
+
- 26d10c0: support overriding model call settings for individual `prepareStep` invocations
|
|
16
|
+
- 7767170: Preserve provider metadata from empty text deltas in `streamText`.
|
|
17
|
+
- Updated dependencies [9ecdefe]
|
|
18
|
+
- Updated dependencies [87fb433]
|
|
19
|
+
- @ai-sdk/provider-utils@4.0.41
|
|
20
|
+
- @ai-sdk/gateway@3.0.160
|
|
21
|
+
|
|
3
22
|
## 6.0.237
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -861,7 +861,8 @@ type StepResult<TOOLS extends ToolSet> = {
|
|
|
861
861
|
*/
|
|
862
862
|
readonly content: Array<ContentPart<TOOLS>>;
|
|
863
863
|
/**
|
|
864
|
-
* The generated
|
|
864
|
+
* The concatenation of all text parts generated in this step.
|
|
865
|
+
* It is an empty string if the step contains no text parts.
|
|
865
866
|
*/
|
|
866
867
|
readonly text: string;
|
|
867
868
|
/**
|
|
@@ -947,6 +948,7 @@ type StepResult<TOOLS extends ToolSet> = {
|
|
|
947
948
|
readonly providerMetadata: ProviderMetadata | undefined;
|
|
948
949
|
};
|
|
949
950
|
|
|
951
|
+
type PrepareStepCallSettings = Pick<CallSettings, 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed'>;
|
|
950
952
|
/**
|
|
951
953
|
* Function that you can use to provide different settings for a step.
|
|
952
954
|
*
|
|
@@ -984,9 +986,13 @@ type PrepareStepFunction<TOOLS extends Record<string, Tool> = Record<string, Too
|
|
|
984
986
|
}) => PromiseLike<PrepareStepResult<TOOLS>> | PrepareStepResult<TOOLS>;
|
|
985
987
|
/**
|
|
986
988
|
* The result type returned by a {@link PrepareStepFunction},
|
|
987
|
-
* allowing per-step overrides of model, tools, or
|
|
989
|
+
* allowing per-step overrides of model call settings, model, tools, or
|
|
990
|
+
* messages.
|
|
991
|
+
*
|
|
992
|
+
* Model call setting overrides apply only to the current step. Undefined
|
|
993
|
+
* settings fall back to the outer call settings.
|
|
988
994
|
*/
|
|
989
|
-
type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = {
|
|
995
|
+
type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = ({
|
|
990
996
|
/**
|
|
991
997
|
* Optionally override which LanguageModel instance is used for this step.
|
|
992
998
|
*/
|
|
@@ -1023,7 +1029,7 @@ type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>
|
|
|
1023
1029
|
* container IDs for Anthropic's code execution.
|
|
1024
1030
|
*/
|
|
1025
1031
|
providerOptions?: ProviderOptions;
|
|
1026
|
-
} | undefined;
|
|
1032
|
+
} & PrepareStepCallSettings) | undefined;
|
|
1027
1033
|
|
|
1028
1034
|
type StopCondition<TOOLS extends ToolSet> = (options: {
|
|
1029
1035
|
steps: Array<StepResult<TOOLS>>;
|
|
@@ -1055,7 +1061,9 @@ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
|
|
|
1055
1061
|
*/
|
|
1056
1062
|
readonly content: Array<ContentPart<TOOLS>>;
|
|
1057
1063
|
/**
|
|
1058
|
-
* The text
|
|
1064
|
+
* The concatenation of all text parts generated in the final step.
|
|
1065
|
+
* It is an empty string if the final step contains no text parts.
|
|
1066
|
+
* Inspect `content` for a text part to distinguish that case.
|
|
1059
1067
|
*/
|
|
1060
1068
|
readonly text: string;
|
|
1061
1069
|
/**
|
|
@@ -1162,8 +1170,10 @@ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
|
|
|
1162
1170
|
*/
|
|
1163
1171
|
readonly experimental_output: InferCompleteOutput<OUTPUT>;
|
|
1164
1172
|
/**
|
|
1165
|
-
* The generated
|
|
1173
|
+
* The generated output according to the `output` specification.
|
|
1166
1174
|
*
|
|
1175
|
+
* @throws {NoOutputGeneratedError} When no output is available, for example
|
|
1176
|
+
* when the final step does not finish with a `stop` reason.
|
|
1167
1177
|
*/
|
|
1168
1178
|
readonly output: InferCompleteOutput<OUTPUT>;
|
|
1169
1179
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -861,7 +861,8 @@ type StepResult<TOOLS extends ToolSet> = {
|
|
|
861
861
|
*/
|
|
862
862
|
readonly content: Array<ContentPart<TOOLS>>;
|
|
863
863
|
/**
|
|
864
|
-
* The generated
|
|
864
|
+
* The concatenation of all text parts generated in this step.
|
|
865
|
+
* It is an empty string if the step contains no text parts.
|
|
865
866
|
*/
|
|
866
867
|
readonly text: string;
|
|
867
868
|
/**
|
|
@@ -947,6 +948,7 @@ type StepResult<TOOLS extends ToolSet> = {
|
|
|
947
948
|
readonly providerMetadata: ProviderMetadata | undefined;
|
|
948
949
|
};
|
|
949
950
|
|
|
951
|
+
type PrepareStepCallSettings = Pick<CallSettings, 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed'>;
|
|
950
952
|
/**
|
|
951
953
|
* Function that you can use to provide different settings for a step.
|
|
952
954
|
*
|
|
@@ -984,9 +986,13 @@ type PrepareStepFunction<TOOLS extends Record<string, Tool> = Record<string, Too
|
|
|
984
986
|
}) => PromiseLike<PrepareStepResult<TOOLS>> | PrepareStepResult<TOOLS>;
|
|
985
987
|
/**
|
|
986
988
|
* The result type returned by a {@link PrepareStepFunction},
|
|
987
|
-
* allowing per-step overrides of model, tools, or
|
|
989
|
+
* allowing per-step overrides of model call settings, model, tools, or
|
|
990
|
+
* messages.
|
|
991
|
+
*
|
|
992
|
+
* Model call setting overrides apply only to the current step. Undefined
|
|
993
|
+
* settings fall back to the outer call settings.
|
|
988
994
|
*/
|
|
989
|
-
type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = {
|
|
995
|
+
type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = ({
|
|
990
996
|
/**
|
|
991
997
|
* Optionally override which LanguageModel instance is used for this step.
|
|
992
998
|
*/
|
|
@@ -1023,7 +1029,7 @@ type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>
|
|
|
1023
1029
|
* container IDs for Anthropic's code execution.
|
|
1024
1030
|
*/
|
|
1025
1031
|
providerOptions?: ProviderOptions;
|
|
1026
|
-
} | undefined;
|
|
1032
|
+
} & PrepareStepCallSettings) | undefined;
|
|
1027
1033
|
|
|
1028
1034
|
type StopCondition<TOOLS extends ToolSet> = (options: {
|
|
1029
1035
|
steps: Array<StepResult<TOOLS>>;
|
|
@@ -1055,7 +1061,9 @@ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
|
|
|
1055
1061
|
*/
|
|
1056
1062
|
readonly content: Array<ContentPart<TOOLS>>;
|
|
1057
1063
|
/**
|
|
1058
|
-
* The text
|
|
1064
|
+
* The concatenation of all text parts generated in the final step.
|
|
1065
|
+
* It is an empty string if the final step contains no text parts.
|
|
1066
|
+
* Inspect `content` for a text part to distinguish that case.
|
|
1059
1067
|
*/
|
|
1060
1068
|
readonly text: string;
|
|
1061
1069
|
/**
|
|
@@ -1162,8 +1170,10 @@ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
|
|
|
1162
1170
|
*/
|
|
1163
1171
|
readonly experimental_output: InferCompleteOutput<OUTPUT>;
|
|
1164
1172
|
/**
|
|
1165
|
-
* The generated
|
|
1173
|
+
* The generated output according to the `output` specification.
|
|
1166
1174
|
*
|
|
1175
|
+
* @throws {NoOutputGeneratedError} When no output is available, for example
|
|
1176
|
+
* when the final step does not finish with a `stop` reason.
|
|
1167
1177
|
*/
|
|
1168
1178
|
readonly output: InferCompleteOutput<OUTPUT>;
|
|
1169
1179
|
}
|
package/dist/index.js
CHANGED
|
@@ -1304,7 +1304,7 @@ function detectMediaType({
|
|
|
1304
1304
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
1305
1305
|
|
|
1306
1306
|
// src/version.ts
|
|
1307
|
-
var VERSION = true ? "6.0.
|
|
1307
|
+
var VERSION = true ? "6.0.239" : "0.0.0-test";
|
|
1308
1308
|
|
|
1309
1309
|
// src/util/download/download.ts
|
|
1310
1310
|
var download = async ({
|
|
@@ -4189,6 +4189,24 @@ async function doParseToolCall({
|
|
|
4189
4189
|
};
|
|
4190
4190
|
}
|
|
4191
4191
|
|
|
4192
|
+
// src/generate-text/prepare-step-call-settings.ts
|
|
4193
|
+
function prepareStepCallSettings({
|
|
4194
|
+
callSettings,
|
|
4195
|
+
stepSettings
|
|
4196
|
+
}) {
|
|
4197
|
+
var _a22, _b, _c, _d, _e, _f, _g, _h;
|
|
4198
|
+
return prepareCallSettings({
|
|
4199
|
+
maxOutputTokens: (_a22 = stepSettings == null ? void 0 : stepSettings.maxOutputTokens) != null ? _a22 : callSettings.maxOutputTokens,
|
|
4200
|
+
temperature: (_b = stepSettings == null ? void 0 : stepSettings.temperature) != null ? _b : callSettings.temperature,
|
|
4201
|
+
topP: (_c = stepSettings == null ? void 0 : stepSettings.topP) != null ? _c : callSettings.topP,
|
|
4202
|
+
topK: (_d = stepSettings == null ? void 0 : stepSettings.topK) != null ? _d : callSettings.topK,
|
|
4203
|
+
presencePenalty: (_e = stepSettings == null ? void 0 : stepSettings.presencePenalty) != null ? _e : callSettings.presencePenalty,
|
|
4204
|
+
frequencyPenalty: (_f = stepSettings == null ? void 0 : stepSettings.frequencyPenalty) != null ? _f : callSettings.frequencyPenalty,
|
|
4205
|
+
stopSequences: (_g = stepSettings == null ? void 0 : stepSettings.stopSequences) != null ? _g : callSettings.stopSequences,
|
|
4206
|
+
seed: (_h = stepSettings == null ? void 0 : stepSettings.seed) != null ? _h : callSettings.seed
|
|
4207
|
+
});
|
|
4208
|
+
}
|
|
4209
|
+
|
|
4192
4210
|
// src/generate-text/step-result.ts
|
|
4193
4211
|
var DefaultStepResult = class {
|
|
4194
4212
|
constructor({
|
|
@@ -4744,6 +4762,10 @@ async function generateText({
|
|
|
4744
4762
|
providerOptions,
|
|
4745
4763
|
prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
|
|
4746
4764
|
);
|
|
4765
|
+
const stepCallSettings = prepareStepCallSettings({
|
|
4766
|
+
callSettings: callSettings2,
|
|
4767
|
+
stepSettings: prepareStepResult
|
|
4768
|
+
});
|
|
4747
4769
|
await notify({
|
|
4748
4770
|
event: {
|
|
4749
4771
|
stepNumber: steps.length,
|
|
@@ -4771,113 +4793,110 @@ async function generateText({
|
|
|
4771
4793
|
]
|
|
4772
4794
|
});
|
|
4773
4795
|
currentModelResponse = await retry(
|
|
4774
|
-
() => {
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
attributes:
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
"gen_ai.request.top_k": settings.topK,
|
|
4809
|
-
"gen_ai.request.top_p": settings.topP
|
|
4810
|
-
}
|
|
4811
|
-
}),
|
|
4812
|
-
tracer,
|
|
4813
|
-
fn: async (span2) => {
|
|
4814
|
-
var _a24, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
|
|
4815
|
-
const result = await stepModel.doGenerate({
|
|
4816
|
-
...callSettings2,
|
|
4817
|
-
tools: stepTools,
|
|
4818
|
-
toolChoice: stepToolChoice,
|
|
4819
|
-
responseFormat: await (output == null ? void 0 : output.responseFormat),
|
|
4820
|
-
prompt: promptMessages,
|
|
4821
|
-
providerOptions: stepProviderOptions,
|
|
4822
|
-
abortSignal: mergedAbortSignal,
|
|
4823
|
-
headers: headersWithUserAgent
|
|
4824
|
-
});
|
|
4825
|
-
const responseData = {
|
|
4826
|
-
id: (_b2 = (_a24 = result.response) == null ? void 0 : _a24.id) != null ? _b2 : generateId2(),
|
|
4827
|
-
timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : /* @__PURE__ */ new Date(),
|
|
4828
|
-
modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : stepModel.modelId,
|
|
4829
|
-
headers: (_g2 = result.response) == null ? void 0 : _g2.headers,
|
|
4830
|
-
body: (_h2 = result.response) == null ? void 0 : _h2.body
|
|
4831
|
-
};
|
|
4832
|
-
const usage = asLanguageModelUsage(result.usage);
|
|
4833
|
-
span2.setAttributes(
|
|
4834
|
-
await selectTelemetryAttributes({
|
|
4835
|
-
telemetry,
|
|
4836
|
-
attributes: {
|
|
4837
|
-
"ai.response.finishReason": result.finishReason.unified,
|
|
4838
|
-
"ai.response.text": {
|
|
4839
|
-
output: () => extractTextContent(result.content)
|
|
4840
|
-
},
|
|
4841
|
-
"ai.response.reasoning": {
|
|
4842
|
-
output: () => extractReasoningContent(result.content)
|
|
4843
|
-
},
|
|
4844
|
-
"ai.response.toolCalls": {
|
|
4845
|
-
output: () => {
|
|
4846
|
-
const toolCalls = asToolCalls(result.content);
|
|
4847
|
-
return toolCalls == null ? void 0 : JSON.stringify(toolCalls);
|
|
4848
|
-
}
|
|
4849
|
-
},
|
|
4850
|
-
"ai.response.id": responseData.id,
|
|
4851
|
-
"ai.response.model": responseData.modelId,
|
|
4852
|
-
"ai.response.timestamp": responseData.timestamp.toISOString(),
|
|
4853
|
-
"ai.response.providerMetadata": JSON.stringify(
|
|
4854
|
-
result.providerMetadata
|
|
4855
|
-
),
|
|
4856
|
-
"ai.usage.inputTokens": result.usage.inputTokens.total,
|
|
4857
|
-
"ai.usage.inputTokenDetails.noCacheTokens": result.usage.inputTokens.noCache,
|
|
4858
|
-
"ai.usage.inputTokenDetails.cacheReadTokens": result.usage.inputTokens.cacheRead,
|
|
4859
|
-
"ai.usage.inputTokenDetails.cacheWriteTokens": result.usage.inputTokens.cacheWrite,
|
|
4860
|
-
"ai.usage.outputTokens": result.usage.outputTokens.total,
|
|
4861
|
-
"ai.usage.outputTokenDetails.textTokens": result.usage.outputTokens.text,
|
|
4862
|
-
"ai.usage.outputTokenDetails.reasoningTokens": result.usage.outputTokens.reasoning,
|
|
4863
|
-
"ai.usage.totalTokens": usage.totalTokens,
|
|
4864
|
-
"ai.usage.reasoningTokens": result.usage.outputTokens.reasoning,
|
|
4865
|
-
"ai.usage.cachedInputTokens": result.usage.inputTokens.cacheRead,
|
|
4866
|
-
// standardized gen-ai llm span attributes:
|
|
4867
|
-
"gen_ai.response.finish_reasons": [
|
|
4868
|
-
result.finishReason.unified
|
|
4869
|
-
],
|
|
4870
|
-
"gen_ai.response.id": responseData.id,
|
|
4871
|
-
"gen_ai.response.model": responseData.modelId,
|
|
4872
|
-
"gen_ai.usage.input_tokens": result.usage.inputTokens.total,
|
|
4873
|
-
"gen_ai.usage.output_tokens": result.usage.outputTokens.total
|
|
4874
|
-
}
|
|
4875
|
-
})
|
|
4876
|
-
);
|
|
4877
|
-
return { ...result, response: responseData };
|
|
4796
|
+
() => recordSpan({
|
|
4797
|
+
name: "ai.generateText.doGenerate",
|
|
4798
|
+
attributes: selectTelemetryAttributes({
|
|
4799
|
+
telemetry,
|
|
4800
|
+
attributes: {
|
|
4801
|
+
...assembleOperationName({
|
|
4802
|
+
operationId: "ai.generateText.doGenerate",
|
|
4803
|
+
telemetry
|
|
4804
|
+
}),
|
|
4805
|
+
...baseTelemetryAttributes,
|
|
4806
|
+
// model:
|
|
4807
|
+
"ai.model.provider": stepModel.provider,
|
|
4808
|
+
"ai.model.id": stepModel.modelId,
|
|
4809
|
+
// prompt:
|
|
4810
|
+
"ai.prompt.messages": {
|
|
4811
|
+
input: () => stringifyForTelemetry(promptMessages)
|
|
4812
|
+
},
|
|
4813
|
+
"ai.prompt.tools": {
|
|
4814
|
+
// convert the language model level tools:
|
|
4815
|
+
input: () => stepTools == null ? void 0 : stepTools.map((tool2) => JSON.stringify(tool2))
|
|
4816
|
+
},
|
|
4817
|
+
"ai.prompt.toolChoice": {
|
|
4818
|
+
input: () => stepToolChoice != null ? JSON.stringify(stepToolChoice) : void 0
|
|
4819
|
+
},
|
|
4820
|
+
// standardized gen-ai llm span attributes:
|
|
4821
|
+
"gen_ai.system": stepModel.provider,
|
|
4822
|
+
"gen_ai.request.model": stepModel.modelId,
|
|
4823
|
+
"gen_ai.request.frequency_penalty": stepCallSettings.frequencyPenalty,
|
|
4824
|
+
"gen_ai.request.max_tokens": stepCallSettings.maxOutputTokens,
|
|
4825
|
+
"gen_ai.request.presence_penalty": stepCallSettings.presencePenalty,
|
|
4826
|
+
"gen_ai.request.stop_sequences": stepCallSettings.stopSequences,
|
|
4827
|
+
"gen_ai.request.temperature": stepCallSettings.temperature,
|
|
4828
|
+
"gen_ai.request.top_k": stepCallSettings.topK,
|
|
4829
|
+
"gen_ai.request.top_p": stepCallSettings.topP
|
|
4878
4830
|
}
|
|
4879
|
-
})
|
|
4880
|
-
|
|
4831
|
+
}),
|
|
4832
|
+
tracer,
|
|
4833
|
+
fn: async (span2) => {
|
|
4834
|
+
var _a23, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
|
|
4835
|
+
const result = await stepModel.doGenerate({
|
|
4836
|
+
...stepCallSettings,
|
|
4837
|
+
tools: stepTools,
|
|
4838
|
+
toolChoice: stepToolChoice,
|
|
4839
|
+
responseFormat: await (output == null ? void 0 : output.responseFormat),
|
|
4840
|
+
prompt: promptMessages,
|
|
4841
|
+
providerOptions: stepProviderOptions,
|
|
4842
|
+
abortSignal: mergedAbortSignal,
|
|
4843
|
+
headers: headersWithUserAgent
|
|
4844
|
+
});
|
|
4845
|
+
const responseData = {
|
|
4846
|
+
id: (_b2 = (_a23 = result.response) == null ? void 0 : _a23.id) != null ? _b2 : generateId2(),
|
|
4847
|
+
timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : /* @__PURE__ */ new Date(),
|
|
4848
|
+
modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : stepModel.modelId,
|
|
4849
|
+
headers: (_g2 = result.response) == null ? void 0 : _g2.headers,
|
|
4850
|
+
body: (_h2 = result.response) == null ? void 0 : _h2.body
|
|
4851
|
+
};
|
|
4852
|
+
const usage = asLanguageModelUsage(result.usage);
|
|
4853
|
+
span2.setAttributes(
|
|
4854
|
+
await selectTelemetryAttributes({
|
|
4855
|
+
telemetry,
|
|
4856
|
+
attributes: {
|
|
4857
|
+
"ai.response.finishReason": result.finishReason.unified,
|
|
4858
|
+
"ai.response.text": {
|
|
4859
|
+
output: () => extractTextContent(result.content)
|
|
4860
|
+
},
|
|
4861
|
+
"ai.response.reasoning": {
|
|
4862
|
+
output: () => extractReasoningContent(result.content)
|
|
4863
|
+
},
|
|
4864
|
+
"ai.response.toolCalls": {
|
|
4865
|
+
output: () => {
|
|
4866
|
+
const toolCalls = asToolCalls(result.content);
|
|
4867
|
+
return toolCalls == null ? void 0 : JSON.stringify(toolCalls);
|
|
4868
|
+
}
|
|
4869
|
+
},
|
|
4870
|
+
"ai.response.id": responseData.id,
|
|
4871
|
+
"ai.response.model": responseData.modelId,
|
|
4872
|
+
"ai.response.timestamp": responseData.timestamp.toISOString(),
|
|
4873
|
+
"ai.response.providerMetadata": JSON.stringify(
|
|
4874
|
+
result.providerMetadata
|
|
4875
|
+
),
|
|
4876
|
+
"ai.usage.inputTokens": result.usage.inputTokens.total,
|
|
4877
|
+
"ai.usage.inputTokenDetails.noCacheTokens": result.usage.inputTokens.noCache,
|
|
4878
|
+
"ai.usage.inputTokenDetails.cacheReadTokens": result.usage.inputTokens.cacheRead,
|
|
4879
|
+
"ai.usage.inputTokenDetails.cacheWriteTokens": result.usage.inputTokens.cacheWrite,
|
|
4880
|
+
"ai.usage.outputTokens": result.usage.outputTokens.total,
|
|
4881
|
+
"ai.usage.outputTokenDetails.textTokens": result.usage.outputTokens.text,
|
|
4882
|
+
"ai.usage.outputTokenDetails.reasoningTokens": result.usage.outputTokens.reasoning,
|
|
4883
|
+
"ai.usage.totalTokens": usage.totalTokens,
|
|
4884
|
+
"ai.usage.reasoningTokens": result.usage.outputTokens.reasoning,
|
|
4885
|
+
"ai.usage.cachedInputTokens": result.usage.inputTokens.cacheRead,
|
|
4886
|
+
// standardized gen-ai llm span attributes:
|
|
4887
|
+
"gen_ai.response.finish_reasons": [
|
|
4888
|
+
result.finishReason.unified
|
|
4889
|
+
],
|
|
4890
|
+
"gen_ai.response.id": responseData.id,
|
|
4891
|
+
"gen_ai.response.model": responseData.modelId,
|
|
4892
|
+
"gen_ai.usage.input_tokens": result.usage.inputTokens.total,
|
|
4893
|
+
"gen_ai.usage.output_tokens": result.usage.outputTokens.total
|
|
4894
|
+
}
|
|
4895
|
+
})
|
|
4896
|
+
);
|
|
4897
|
+
return { ...result, response: responseData };
|
|
4898
|
+
}
|
|
4899
|
+
})
|
|
4881
4900
|
);
|
|
4882
4901
|
const stepToolCalls = await Promise.all(
|
|
4883
4902
|
currentModelResponse.content.filter(
|
|
@@ -7144,6 +7163,10 @@ function createOutputTransformStream(output) {
|
|
|
7144
7163
|
text2 += chunk.text;
|
|
7145
7164
|
textChunk += chunk.text;
|
|
7146
7165
|
textProviderMetadata = (_a22 = chunk.providerMetadata) != null ? _a22 : textProviderMetadata;
|
|
7166
|
+
if (chunk.text.length === 0 && chunk.providerMetadata != null) {
|
|
7167
|
+
controller.enqueue({ part: chunk, partialOutput: void 0 });
|
|
7168
|
+
return;
|
|
7169
|
+
}
|
|
7147
7170
|
const result = await output.parsePartialOutput({ text: text2 });
|
|
7148
7171
|
if (result !== void 0) {
|
|
7149
7172
|
const currentValue = typeof result.partial === "string" ? result.partial : JSON.stringify(result.partial);
|
|
@@ -7795,6 +7818,10 @@ var DefaultStreamTextResult = class {
|
|
|
7795
7818
|
providerOptions,
|
|
7796
7819
|
prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
|
|
7797
7820
|
);
|
|
7821
|
+
const stepCallSettings = prepareStepCallSettings({
|
|
7822
|
+
callSettings,
|
|
7823
|
+
stepSettings: prepareStepResult
|
|
7824
|
+
});
|
|
7798
7825
|
await notify({
|
|
7799
7826
|
event: {
|
|
7800
7827
|
stepNumber: recordedSteps.length,
|
|
@@ -7852,13 +7879,13 @@ var DefaultStreamTextResult = class {
|
|
|
7852
7879
|
// standardized gen-ai llm span attributes:
|
|
7853
7880
|
"gen_ai.system": stepModel.provider,
|
|
7854
7881
|
"gen_ai.request.model": stepModel.modelId,
|
|
7855
|
-
"gen_ai.request.frequency_penalty":
|
|
7856
|
-
"gen_ai.request.max_tokens":
|
|
7857
|
-
"gen_ai.request.presence_penalty":
|
|
7858
|
-
"gen_ai.request.stop_sequences":
|
|
7859
|
-
"gen_ai.request.temperature":
|
|
7860
|
-
"gen_ai.request.top_k":
|
|
7861
|
-
"gen_ai.request.top_p":
|
|
7882
|
+
"gen_ai.request.frequency_penalty": stepCallSettings.frequencyPenalty,
|
|
7883
|
+
"gen_ai.request.max_tokens": stepCallSettings.maxOutputTokens,
|
|
7884
|
+
"gen_ai.request.presence_penalty": stepCallSettings.presencePenalty,
|
|
7885
|
+
"gen_ai.request.stop_sequences": stepCallSettings.stopSequences,
|
|
7886
|
+
"gen_ai.request.temperature": stepCallSettings.temperature,
|
|
7887
|
+
"gen_ai.request.top_k": stepCallSettings.topK,
|
|
7888
|
+
"gen_ai.request.top_p": stepCallSettings.topP
|
|
7862
7889
|
}
|
|
7863
7890
|
}),
|
|
7864
7891
|
tracer,
|
|
@@ -7868,7 +7895,7 @@ var DefaultStreamTextResult = class {
|
|
|
7868
7895
|
// get before the call
|
|
7869
7896
|
doStreamSpan: doStreamSpan2,
|
|
7870
7897
|
result: await stepModel.doStream({
|
|
7871
|
-
...
|
|
7898
|
+
...stepCallSettings,
|
|
7872
7899
|
tools: stepTools,
|
|
7873
7900
|
toolChoice: stepToolChoice,
|
|
7874
7901
|
responseFormat: await (output == null ? void 0 : output.responseFormat),
|
|
@@ -7959,15 +7986,15 @@ var DefaultStreamTextResult = class {
|
|
|
7959
7986
|
break;
|
|
7960
7987
|
}
|
|
7961
7988
|
case "text-delta": {
|
|
7962
|
-
if (chunk.delta.length > 0) {
|
|
7989
|
+
if (chunk.delta.length > 0 || chunk.providerMetadata != null) {
|
|
7963
7990
|
controller.enqueue({
|
|
7964
7991
|
type: "text-delta",
|
|
7965
7992
|
id: chunk.id,
|
|
7966
7993
|
text: chunk.delta,
|
|
7967
7994
|
providerMetadata: chunk.providerMetadata
|
|
7968
7995
|
});
|
|
7969
|
-
activeText += chunk.delta;
|
|
7970
7996
|
}
|
|
7997
|
+
activeText += chunk.delta;
|
|
7971
7998
|
break;
|
|
7972
7999
|
}
|
|
7973
8000
|
case "reasoning-start":
|