ai 5.0.0-canary.8 → 5.0.0-canary.9
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 +18 -0
- package/dist/index.d.mts +172 -37
- package/dist/index.d.ts +172 -37
- package/dist/index.js +255 -152
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +247 -142
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
@@ -85,8 +85,8 @@ __export(ai_exports, {
|
|
85
85
|
experimental_createProviderRegistry: () => experimental_createProviderRegistry,
|
86
86
|
experimental_customProvider: () => experimental_customProvider,
|
87
87
|
experimental_generateImage: () => generateImage,
|
88
|
+
experimental_generateSpeech: () => generateSpeech,
|
88
89
|
experimental_transcribe: () => transcribe,
|
89
|
-
experimental_wrapLanguageModel: () => experimental_wrapLanguageModel,
|
90
90
|
extractMaxToolInvocationStep: () => extractMaxToolInvocationStep,
|
91
91
|
extractReasoningMiddleware: () => extractReasoningMiddleware,
|
92
92
|
fillMessageParts: () => fillMessageParts,
|
@@ -4193,6 +4193,17 @@ function validateObjectGenerationInput({
|
|
4193
4193
|
}
|
4194
4194
|
}
|
4195
4195
|
|
4196
|
+
// core/generate-text/extract-content-text.ts
|
4197
|
+
function extractContentText(content) {
|
4198
|
+
const parts = content.filter(
|
4199
|
+
(content2) => content2.type === "text"
|
4200
|
+
);
|
4201
|
+
if (parts.length === 0) {
|
4202
|
+
return void 0;
|
4203
|
+
}
|
4204
|
+
return parts.map((content2) => content2.text).join("");
|
4205
|
+
}
|
4206
|
+
|
4196
4207
|
// core/generate-object/generate-object.ts
|
4197
4208
|
var originalGenerateId = (0, import_provider_utils11.createIdGenerator)({ prefix: "aiobj", size: 24 });
|
4198
4209
|
async function generateObject({
|
@@ -4266,7 +4277,7 @@ async function generateObject({
|
|
4266
4277
|
}),
|
4267
4278
|
tracer,
|
4268
4279
|
fn: async (span) => {
|
4269
|
-
var _a17, _b, _c, _d
|
4280
|
+
var _a17, _b, _c, _d;
|
4270
4281
|
if (mode === "auto" || mode == null) {
|
4271
4282
|
mode = model.defaultObjectGenerationMode;
|
4272
4283
|
}
|
@@ -4328,7 +4339,7 @@ async function generateObject({
|
|
4328
4339
|
}),
|
4329
4340
|
tracer,
|
4330
4341
|
fn: async (span2) => {
|
4331
|
-
var _a18, _b2, _c2, _d2,
|
4342
|
+
var _a18, _b2, _c2, _d2, _e, _f, _g, _h;
|
4332
4343
|
const result2 = await model.doGenerate({
|
4333
4344
|
responseFormat: {
|
4334
4345
|
type: "json",
|
@@ -4346,11 +4357,12 @@ async function generateObject({
|
|
4346
4357
|
const responseData = {
|
4347
4358
|
id: (_b2 = (_a18 = result2.response) == null ? void 0 : _a18.id) != null ? _b2 : generateId3(),
|
4348
4359
|
timestamp: (_d2 = (_c2 = result2.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : currentDate(),
|
4349
|
-
modelId: (_f = (
|
4360
|
+
modelId: (_f = (_e = result2.response) == null ? void 0 : _e.modelId) != null ? _f : model.modelId,
|
4350
4361
|
headers: (_g = result2.response) == null ? void 0 : _g.headers,
|
4351
4362
|
body: (_h = result2.response) == null ? void 0 : _h.body
|
4352
4363
|
};
|
4353
|
-
|
4364
|
+
const text2 = extractContentText(result2.content);
|
4365
|
+
if (text2 === void 0) {
|
4354
4366
|
throw new NoObjectGeneratedError({
|
4355
4367
|
message: "No object generated: the model did not return a response.",
|
4356
4368
|
response: responseData,
|
@@ -4363,10 +4375,7 @@ async function generateObject({
|
|
4363
4375
|
telemetry,
|
4364
4376
|
attributes: {
|
4365
4377
|
"ai.response.finishReason": result2.finishReason,
|
4366
|
-
"ai.response.object": { output: () =>
|
4367
|
-
var _a19;
|
4368
|
-
return (_a19 = result2.text) == null ? void 0 : _a19.text;
|
4369
|
-
} },
|
4378
|
+
"ai.response.object": { output: () => text2 },
|
4370
4379
|
"ai.response.id": responseData.id,
|
4371
4380
|
"ai.response.model": responseData.modelId,
|
4372
4381
|
"ai.response.timestamp": responseData.timestamp.toISOString(),
|
@@ -4382,17 +4391,17 @@ async function generateObject({
|
|
4382
4391
|
}
|
4383
4392
|
})
|
4384
4393
|
);
|
4385
|
-
return { ...result2, objectText:
|
4394
|
+
return { ...result2, objectText: text2, responseData };
|
4386
4395
|
}
|
4387
4396
|
})
|
4388
4397
|
);
|
4389
|
-
result =
|
4398
|
+
result = generateResult.objectText;
|
4390
4399
|
finishReason = generateResult.finishReason;
|
4391
4400
|
usage = generateResult.usage;
|
4392
4401
|
warnings = generateResult.warnings;
|
4393
4402
|
logprobs = generateResult.logprobs;
|
4394
4403
|
resultProviderMetadata = generateResult.providerMetadata;
|
4395
|
-
request = (
|
4404
|
+
request = (_b = generateResult.request) != null ? _b : {};
|
4396
4405
|
response = generateResult.responseData;
|
4397
4406
|
break;
|
4398
4407
|
}
|
@@ -4404,7 +4413,7 @@ async function generateObject({
|
|
4404
4413
|
const promptMessages = await convertToLanguageModelPrompt({
|
4405
4414
|
prompt: standardizedPrompt,
|
4406
4415
|
modelSupportsImageUrls: model.supportsImageUrls,
|
4407
|
-
modelSupportsUrl: (
|
4416
|
+
modelSupportsUrl: (_c = model.supportsUrl) == null ? void 0 : _c.bind(model)
|
4408
4417
|
// support 'this' context,
|
4409
4418
|
});
|
4410
4419
|
const inputFormat = standardizedPrompt.type;
|
@@ -4439,7 +4448,7 @@ async function generateObject({
|
|
4439
4448
|
}),
|
4440
4449
|
tracer,
|
4441
4450
|
fn: async (span2) => {
|
4442
|
-
var _a18, _b2, _c2, _d2,
|
4451
|
+
var _a18, _b2, _c2, _d2, _e, _f, _g, _h;
|
4443
4452
|
const result2 = await model.doGenerate({
|
4444
4453
|
tools: [
|
4445
4454
|
{
|
@@ -4457,13 +4466,16 @@ async function generateObject({
|
|
4457
4466
|
abortSignal,
|
4458
4467
|
headers
|
4459
4468
|
});
|
4460
|
-
const
|
4469
|
+
const firstToolCall = result2.content.find(
|
4470
|
+
(content) => content.type === "tool-call"
|
4471
|
+
);
|
4472
|
+
const objectText = firstToolCall == null ? void 0 : firstToolCall.args;
|
4461
4473
|
const responseData = {
|
4462
|
-
id: (
|
4463
|
-
timestamp: (
|
4464
|
-
modelId: (
|
4465
|
-
headers: (
|
4466
|
-
body: (
|
4474
|
+
id: (_b2 = (_a18 = result2.response) == null ? void 0 : _a18.id) != null ? _b2 : generateId3(),
|
4475
|
+
timestamp: (_d2 = (_c2 = result2.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : currentDate(),
|
4476
|
+
modelId: (_f = (_e = result2.response) == null ? void 0 : _e.modelId) != null ? _f : model.modelId,
|
4477
|
+
headers: (_g = result2.response) == null ? void 0 : _g.headers,
|
4478
|
+
body: (_h = result2.response) == null ? void 0 : _h.body
|
4467
4479
|
};
|
4468
4480
|
if (objectText === void 0) {
|
4469
4481
|
throw new NoObjectGeneratedError({
|
@@ -4504,7 +4516,7 @@ async function generateObject({
|
|
4504
4516
|
warnings = generateResult.warnings;
|
4505
4517
|
logprobs = generateResult.logprobs;
|
4506
4518
|
resultProviderMetadata = generateResult.providerMetadata;
|
4507
|
-
request = (
|
4519
|
+
request = (_d = generateResult.request) != null ? _d : {};
|
4508
4520
|
response = generateResult.responseData;
|
4509
4521
|
break;
|
4510
4522
|
}
|
@@ -5000,7 +5012,7 @@ var DefaultStreamObjectResult = class {
|
|
5000
5012
|
}
|
5001
5013
|
}
|
5002
5014
|
const {
|
5003
|
-
result: { stream,
|
5015
|
+
result: { stream, response, request },
|
5004
5016
|
doStreamSpan,
|
5005
5017
|
startTimestampMs
|
5006
5018
|
} = await retry(
|
@@ -5042,6 +5054,7 @@ var DefaultStreamObjectResult = class {
|
|
5042
5054
|
})
|
5043
5055
|
);
|
5044
5056
|
self.requestPromise.resolve(request != null ? request : {});
|
5057
|
+
let warnings;
|
5045
5058
|
let usage;
|
5046
5059
|
let finishReason;
|
5047
5060
|
let providerMetadata;
|
@@ -5062,6 +5075,10 @@ var DefaultStreamObjectResult = class {
|
|
5062
5075
|
new TransformStream({
|
5063
5076
|
async transform(chunk, controller) {
|
5064
5077
|
var _a18, _b2, _c;
|
5078
|
+
if (typeof chunk === "object" && chunk.type === "stream-start") {
|
5079
|
+
warnings = chunk.warnings;
|
5080
|
+
return;
|
5081
|
+
}
|
5065
5082
|
if (isFirstChunk) {
|
5066
5083
|
const msToFirstChunk = now2() - startTimestampMs;
|
5067
5084
|
isFirstChunk = false;
|
@@ -5585,7 +5602,7 @@ async function doParseToolCall({
|
|
5585
5602
|
};
|
5586
5603
|
}
|
5587
5604
|
|
5588
|
-
// core/generate-text/reasoning
|
5605
|
+
// core/generate-text/reasoning.ts
|
5589
5606
|
function asReasoningText(reasoning) {
|
5590
5607
|
const reasoningText = reasoning.filter((part) => part.type === "text").map((part) => part.text).join("");
|
5591
5608
|
return reasoningText.length > 0 ? reasoningText : void 0;
|
@@ -5736,7 +5753,7 @@ async function generateText({
|
|
5736
5753
|
}),
|
5737
5754
|
tracer,
|
5738
5755
|
fn: async (span) => {
|
5739
|
-
var _a18, _b, _c, _d
|
5756
|
+
var _a18, _b, _c, _d;
|
5740
5757
|
const toolsAndToolChoice = {
|
5741
5758
|
...prepareToolsAndToolChoice({ tools, toolChoice, activeTools })
|
5742
5759
|
};
|
@@ -5811,7 +5828,7 @@ async function generateText({
|
|
5811
5828
|
}),
|
5812
5829
|
tracer,
|
5813
5830
|
fn: async (span2) => {
|
5814
|
-
var _a19, _b2, _c2, _d2,
|
5831
|
+
var _a19, _b2, _c2, _d2, _e, _f, _g, _h;
|
5815
5832
|
const result = await model.doGenerate({
|
5816
5833
|
...callSettings,
|
5817
5834
|
...toolsAndToolChoice,
|
@@ -5825,9 +5842,9 @@ async function generateText({
|
|
5825
5842
|
const responseData = {
|
5826
5843
|
id: (_b2 = (_a19 = result.response) == null ? void 0 : _a19.id) != null ? _b2 : generateId3(),
|
5827
5844
|
timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : currentDate(),
|
5828
|
-
modelId: (
|
5829
|
-
headers: (
|
5830
|
-
body: (
|
5845
|
+
modelId: (_f = (_e = result.response) == null ? void 0 : _e.modelId) != null ? _f : model.modelId,
|
5846
|
+
headers: (_g = result.response) == null ? void 0 : _g.headers,
|
5847
|
+
body: (_h = result.response) == null ? void 0 : _h.body
|
5831
5848
|
};
|
5832
5849
|
span2.setAttributes(
|
5833
5850
|
selectTelemetryAttributes({
|
@@ -5835,22 +5852,12 @@ async function generateText({
|
|
5835
5852
|
attributes: {
|
5836
5853
|
"ai.response.finishReason": result.finishReason,
|
5837
5854
|
"ai.response.text": {
|
5838
|
-
output: () =>
|
5839
|
-
var _a20;
|
5840
|
-
return (_a20 = result.text) == null ? void 0 : _a20.text;
|
5841
|
-
}
|
5855
|
+
output: () => extractContentText(result.content)
|
5842
5856
|
},
|
5843
5857
|
"ai.response.toolCalls": {
|
5844
5858
|
output: () => {
|
5845
|
-
|
5846
|
-
return JSON.stringify(
|
5847
|
-
(_a20 = result.toolCalls) == null ? void 0 : _a20.map((toolCall) => ({
|
5848
|
-
toolCallType: toolCall.toolCallType,
|
5849
|
-
toolCallId: toolCall.toolCallId,
|
5850
|
-
toolName: toolCall.toolName,
|
5851
|
-
args: toolCall.args
|
5852
|
-
}))
|
5853
|
-
);
|
5859
|
+
const toolCalls = asToolCalls(result.content);
|
5860
|
+
return toolCalls == null ? void 0 : JSON.stringify(toolCalls);
|
5854
5861
|
}
|
5855
5862
|
},
|
5856
5863
|
"ai.response.id": responseData.id,
|
@@ -5873,7 +5880,9 @@ async function generateText({
|
|
5873
5880
|
})
|
5874
5881
|
);
|
5875
5882
|
currentToolCalls = await Promise.all(
|
5876
|
-
|
5883
|
+
currentModelResponse.content.filter(
|
5884
|
+
(part) => part.type === "tool-call"
|
5885
|
+
).map(
|
5877
5886
|
(toolCall) => parseToolCall({
|
5878
5887
|
toolCall,
|
5879
5888
|
tools,
|
@@ -5908,15 +5917,19 @@ async function generateText({
|
|
5908
5917
|
nextStepType = "tool-result";
|
5909
5918
|
}
|
5910
5919
|
}
|
5911
|
-
const originalText = (
|
5920
|
+
const originalText = (_b = extractContentText(currentModelResponse.content)) != null ? _b : "";
|
5912
5921
|
const stepTextLeadingWhitespaceTrimmed = stepType === "continue" && // only for continue steps
|
5913
5922
|
text2.trimEnd() !== text2 ? originalText.trimStart() : originalText;
|
5914
5923
|
const stepText = nextStepType === "continue" ? removeTextAfterLastWhitespace(stepTextLeadingWhitespaceTrimmed) : stepTextLeadingWhitespaceTrimmed;
|
5915
5924
|
text2 = nextStepType === "continue" || stepType === "continue" ? text2 + stepText : stepText;
|
5916
5925
|
currentReasoningDetails = asReasoningDetails(
|
5917
|
-
currentModelResponse.
|
5926
|
+
currentModelResponse.content
|
5927
|
+
);
|
5928
|
+
sources.push(
|
5929
|
+
...currentModelResponse.content.filter(
|
5930
|
+
(part) => part.type === "source"
|
5931
|
+
)
|
5918
5932
|
);
|
5919
|
-
sources.push(...(_e = currentModelResponse.sources) != null ? _e : []);
|
5920
5933
|
if (stepType === "continue") {
|
5921
5934
|
const lastMessage = responseMessages[responseMessages.length - 1];
|
5922
5935
|
if (typeof lastMessage.content === "string") {
|
@@ -5931,8 +5944,8 @@ async function generateText({
|
|
5931
5944
|
responseMessages.push(
|
5932
5945
|
...toResponseMessages({
|
5933
5946
|
text: text2,
|
5934
|
-
files: asFiles(currentModelResponse.
|
5935
|
-
reasoning: asReasoningDetails(currentModelResponse.
|
5947
|
+
files: asFiles(currentModelResponse.content),
|
5948
|
+
reasoning: asReasoningDetails(currentModelResponse.content),
|
5936
5949
|
tools: tools != null ? tools : {},
|
5937
5950
|
toolCalls: currentToolCalls,
|
5938
5951
|
toolResults: currentToolResults,
|
@@ -5944,18 +5957,19 @@ async function generateText({
|
|
5944
5957
|
const currentStepResult = {
|
5945
5958
|
stepType,
|
5946
5959
|
text: stepText,
|
5947
|
-
|
5948
|
-
reasoning:
|
5949
|
-
|
5950
|
-
|
5951
|
-
|
5960
|
+
reasoningText: asReasoningText(currentReasoningDetails),
|
5961
|
+
reasoning: currentReasoningDetails,
|
5962
|
+
files: asFiles(currentModelResponse.content),
|
5963
|
+
sources: currentModelResponse.content.filter(
|
5964
|
+
(part) => part.type === "source"
|
5965
|
+
),
|
5952
5966
|
toolCalls: currentToolCalls,
|
5953
5967
|
toolResults: currentToolResults,
|
5954
5968
|
finishReason: currentModelResponse.finishReason,
|
5955
5969
|
usage: currentUsage,
|
5956
5970
|
warnings: currentModelResponse.warnings,
|
5957
5971
|
logprobs: currentModelResponse.logprobs,
|
5958
|
-
request: (
|
5972
|
+
request: (_c = currentModelResponse.request) != null ? _c : {},
|
5959
5973
|
response: {
|
5960
5974
|
...currentModelResponse.response,
|
5961
5975
|
// deep clone msgs to avoid mutating past messages in multi-step:
|
@@ -5974,22 +5988,12 @@ async function generateText({
|
|
5974
5988
|
attributes: {
|
5975
5989
|
"ai.response.finishReason": currentModelResponse.finishReason,
|
5976
5990
|
"ai.response.text": {
|
5977
|
-
output: () =>
|
5978
|
-
var _a19;
|
5979
|
-
return (_a19 = currentModelResponse.text) == null ? void 0 : _a19.text;
|
5980
|
-
}
|
5991
|
+
output: () => extractContentText(currentModelResponse.content)
|
5981
5992
|
},
|
5982
5993
|
"ai.response.toolCalls": {
|
5983
5994
|
output: () => {
|
5984
|
-
|
5985
|
-
return JSON.stringify(
|
5986
|
-
(_a19 = currentModelResponse.toolCalls) == null ? void 0 : _a19.map((toolCall) => ({
|
5987
|
-
toolCallType: toolCall.toolCallType,
|
5988
|
-
toolCallId: toolCall.toolCallId,
|
5989
|
-
toolName: toolCall.toolName,
|
5990
|
-
args: toolCall.args
|
5991
|
-
}))
|
5992
|
-
);
|
5995
|
+
const toolCalls = asToolCalls(currentModelResponse.content);
|
5996
|
+
return toolCalls == null ? void 0 : JSON.stringify(toolCalls);
|
5993
5997
|
}
|
5994
5998
|
},
|
5995
5999
|
// TODO rename telemetry attributes to inputTokens and outputTokens
|
@@ -6000,7 +6004,7 @@ async function generateText({
|
|
6000
6004
|
);
|
6001
6005
|
return new DefaultGenerateTextResult({
|
6002
6006
|
text: text2,
|
6003
|
-
files: asFiles(currentModelResponse.
|
6007
|
+
files: asFiles(currentModelResponse.content),
|
6004
6008
|
reasoning: asReasoningText(currentReasoningDetails),
|
6005
6009
|
reasoningDetails: currentReasoningDetails,
|
6006
6010
|
sources,
|
@@ -6022,7 +6026,7 @@ async function generateText({
|
|
6022
6026
|
finishReason: currentModelResponse.finishReason,
|
6023
6027
|
usage,
|
6024
6028
|
warnings: currentModelResponse.warnings,
|
6025
|
-
request: (
|
6029
|
+
request: (_d = currentModelResponse.request) != null ? _d : {},
|
6026
6030
|
response: {
|
6027
6031
|
...currentModelResponse.response,
|
6028
6032
|
messages: responseMessages
|
@@ -6113,8 +6117,8 @@ var DefaultGenerateTextResult = class {
|
|
6113
6117
|
constructor(options) {
|
6114
6118
|
this.text = options.text;
|
6115
6119
|
this.files = options.files;
|
6116
|
-
this.
|
6117
|
-
this.
|
6120
|
+
this.reasoningText = options.reasoning;
|
6121
|
+
this.reasoning = options.reasoningDetails;
|
6118
6122
|
this.toolCalls = options.toolCalls;
|
6119
6123
|
this.toolResults = options.toolResults;
|
6120
6124
|
this.finishReason = options.finishReason;
|
@@ -6132,8 +6136,9 @@ var DefaultGenerateTextResult = class {
|
|
6132
6136
|
return this.outputResolver();
|
6133
6137
|
}
|
6134
6138
|
};
|
6135
|
-
function asReasoningDetails(
|
6136
|
-
|
6139
|
+
function asReasoningDetails(content) {
|
6140
|
+
const reasoning = content.filter((part) => part.type === "reasoning");
|
6141
|
+
if (reasoning.length === 0) {
|
6137
6142
|
return [];
|
6138
6143
|
}
|
6139
6144
|
const result = [];
|
@@ -6159,9 +6164,22 @@ function asReasoningDetails(reasoning) {
|
|
6159
6164
|
}
|
6160
6165
|
return result;
|
6161
6166
|
}
|
6162
|
-
function asFiles(
|
6163
|
-
|
6164
|
-
|
6167
|
+
function asFiles(content) {
|
6168
|
+
return content.filter((part) => part.type === "file").map((part) => new DefaultGeneratedFile(part));
|
6169
|
+
}
|
6170
|
+
function asToolCalls(content) {
|
6171
|
+
const parts = content.filter(
|
6172
|
+
(part) => part.type === "tool-call"
|
6173
|
+
);
|
6174
|
+
if (parts.length === 0) {
|
6175
|
+
return void 0;
|
6176
|
+
}
|
6177
|
+
return parts.map((toolCall) => ({
|
6178
|
+
toolCallType: toolCall.toolCallType,
|
6179
|
+
toolCallId: toolCall.toolCallId,
|
6180
|
+
toolName: toolCall.toolName,
|
6181
|
+
args: toolCall.args
|
6182
|
+
}));
|
6165
6183
|
}
|
6166
6184
|
|
6167
6185
|
// core/generate-text/output.ts
|
@@ -6515,6 +6533,7 @@ function runToolsTransformation({
|
|
6515
6533
|
async transform(chunk, controller) {
|
6516
6534
|
const chunkType = chunk.type;
|
6517
6535
|
switch (chunkType) {
|
6536
|
+
case "stream-start":
|
6518
6537
|
case "text":
|
6519
6538
|
case "reasoning":
|
6520
6539
|
case "source":
|
@@ -6952,8 +6971,8 @@ var DefaultStreamTextResult = class {
|
|
6952
6971
|
const currentStepResult = {
|
6953
6972
|
stepType,
|
6954
6973
|
text: recordedStepText,
|
6955
|
-
|
6956
|
-
|
6974
|
+
reasoningText: asReasoningText(stepReasoning),
|
6975
|
+
reasoning: stepReasoning,
|
6957
6976
|
files: stepFiles,
|
6958
6977
|
sources: recordedStepSources,
|
6959
6978
|
toolCalls: recordedToolCalls,
|
@@ -7009,8 +7028,8 @@ var DefaultStreamTextResult = class {
|
|
7009
7028
|
self.toolCallsPromise.resolve(lastStep.toolCalls);
|
7010
7029
|
self.toolResultsPromise.resolve(lastStep.toolResults);
|
7011
7030
|
self.providerMetadataPromise.resolve(lastStep.providerMetadata);
|
7012
|
-
self.reasoningPromise.resolve(lastStep.
|
7013
|
-
self.reasoningDetailsPromise.resolve(lastStep.
|
7031
|
+
self.reasoningPromise.resolve(lastStep.reasoningText);
|
7032
|
+
self.reasoningDetailsPromise.resolve(lastStep.reasoning);
|
7014
7033
|
const finishReason = recordedFinishReason != null ? recordedFinishReason : "unknown";
|
7015
7034
|
const usage = recordedUsage != null ? recordedUsage : {
|
7016
7035
|
completionTokens: NaN,
|
@@ -7028,8 +7047,8 @@ var DefaultStreamTextResult = class {
|
|
7028
7047
|
logprobs: void 0,
|
7029
7048
|
usage,
|
7030
7049
|
text: recordedFullText,
|
7050
|
+
reasoningText: lastStep.reasoningText,
|
7031
7051
|
reasoning: lastStep.reasoning,
|
7032
|
-
reasoningDetails: lastStep.reasoningDetails,
|
7033
7052
|
files: lastStep.files,
|
7034
7053
|
sources: lastStep.sources,
|
7035
7054
|
toolCalls: lastStep.toolCalls,
|
@@ -7145,7 +7164,7 @@ var DefaultStreamTextResult = class {
|
|
7145
7164
|
...prepareToolsAndToolChoice({ tools, toolChoice, activeTools })
|
7146
7165
|
};
|
7147
7166
|
const {
|
7148
|
-
result: { stream: stream2,
|
7167
|
+
result: { stream: stream2, response, request },
|
7149
7168
|
doStreamSpan,
|
7150
7169
|
startTimestampMs
|
7151
7170
|
} = await retry(
|
@@ -7222,6 +7241,7 @@ var DefaultStreamTextResult = class {
|
|
7222
7241
|
const stepRequest = request != null ? request : {};
|
7223
7242
|
const stepToolCalls = [];
|
7224
7243
|
const stepToolResults = [];
|
7244
|
+
let warnings;
|
7225
7245
|
const stepReasoning2 = [];
|
7226
7246
|
const stepFiles2 = [];
|
7227
7247
|
let activeReasoningText2 = void 0;
|
@@ -7260,6 +7280,10 @@ var DefaultStreamTextResult = class {
|
|
7260
7280
|
new TransformStream({
|
7261
7281
|
async transform(chunk, controller) {
|
7262
7282
|
var _a19, _b, _c;
|
7283
|
+
if (chunk.type === "stream-start") {
|
7284
|
+
warnings = chunk.warnings;
|
7285
|
+
return;
|
7286
|
+
}
|
7263
7287
|
if (stepFirstChunk) {
|
7264
7288
|
const msToFirstChunk = now2() - startTimestampMs;
|
7265
7289
|
stepFirstChunk = false;
|
@@ -7552,10 +7576,10 @@ var DefaultStreamTextResult = class {
|
|
7552
7576
|
get text() {
|
7553
7577
|
return this.textPromise.value;
|
7554
7578
|
}
|
7555
|
-
get
|
7579
|
+
get reasoningText() {
|
7556
7580
|
return this.reasoningPromise.value;
|
7557
7581
|
}
|
7558
|
-
get
|
7582
|
+
get reasoning() {
|
7559
7583
|
return this.reasoningDetailsPromise.value;
|
7560
7584
|
}
|
7561
7585
|
get sources() {
|
@@ -7888,9 +7912,99 @@ var DefaultStreamTextResult = class {
|
|
7888
7912
|
}
|
7889
7913
|
};
|
7890
7914
|
|
7891
|
-
// errors/no-
|
7915
|
+
// errors/no-speech-generated-error.ts
|
7892
7916
|
var import_provider24 = require("@ai-sdk/provider");
|
7893
|
-
var
|
7917
|
+
var NoSpeechGeneratedError = class extends import_provider24.AISDKError {
|
7918
|
+
constructor(options) {
|
7919
|
+
super({
|
7920
|
+
name: "AI_NoSpeechGeneratedError",
|
7921
|
+
message: "No speech audio generated."
|
7922
|
+
});
|
7923
|
+
this.responses = options.responses;
|
7924
|
+
}
|
7925
|
+
};
|
7926
|
+
|
7927
|
+
// core/generate-speech/generated-audio-file.ts
|
7928
|
+
var DefaultGeneratedAudioFile = class extends DefaultGeneratedFile {
|
7929
|
+
constructor({
|
7930
|
+
data,
|
7931
|
+
mediaType
|
7932
|
+
}) {
|
7933
|
+
super({ data, mediaType });
|
7934
|
+
let format = "mp3";
|
7935
|
+
if (mediaType) {
|
7936
|
+
const mimeTypeParts = mediaType.split("/");
|
7937
|
+
if (mimeTypeParts.length === 2) {
|
7938
|
+
if (mediaType !== "audio/mpeg") {
|
7939
|
+
format = mimeTypeParts[1];
|
7940
|
+
}
|
7941
|
+
}
|
7942
|
+
}
|
7943
|
+
if (!format) {
|
7944
|
+
throw new Error(
|
7945
|
+
"Audio format must be provided or determinable from mimeType"
|
7946
|
+
);
|
7947
|
+
}
|
7948
|
+
this.format = format;
|
7949
|
+
}
|
7950
|
+
};
|
7951
|
+
|
7952
|
+
// core/generate-speech/generate-speech.ts
|
7953
|
+
async function generateSpeech({
|
7954
|
+
model,
|
7955
|
+
text: text2,
|
7956
|
+
voice,
|
7957
|
+
outputFormat,
|
7958
|
+
instructions,
|
7959
|
+
speed,
|
7960
|
+
providerOptions = {},
|
7961
|
+
maxRetries: maxRetriesArg,
|
7962
|
+
abortSignal,
|
7963
|
+
headers
|
7964
|
+
}) {
|
7965
|
+
var _a17;
|
7966
|
+
const { retry } = prepareRetries({ maxRetries: maxRetriesArg });
|
7967
|
+
const result = await retry(
|
7968
|
+
() => model.doGenerate({
|
7969
|
+
text: text2,
|
7970
|
+
voice,
|
7971
|
+
outputFormat,
|
7972
|
+
instructions,
|
7973
|
+
speed,
|
7974
|
+
abortSignal,
|
7975
|
+
headers,
|
7976
|
+
providerOptions
|
7977
|
+
})
|
7978
|
+
);
|
7979
|
+
if (!result.audio || result.audio.length === 0) {
|
7980
|
+
throw new NoSpeechGeneratedError({ responses: [result.response] });
|
7981
|
+
}
|
7982
|
+
return new DefaultSpeechResult({
|
7983
|
+
audio: new DefaultGeneratedAudioFile({
|
7984
|
+
data: result.audio,
|
7985
|
+
mediaType: (_a17 = detectMediaType({
|
7986
|
+
data: result.audio,
|
7987
|
+
signatures: audioMediaTypeSignatures
|
7988
|
+
})) != null ? _a17 : "audio/mp3"
|
7989
|
+
}),
|
7990
|
+
warnings: result.warnings,
|
7991
|
+
responses: [result.response],
|
7992
|
+
providerMetadata: result.providerMetadata
|
7993
|
+
});
|
7994
|
+
}
|
7995
|
+
var DefaultSpeechResult = class {
|
7996
|
+
constructor(options) {
|
7997
|
+
var _a17;
|
7998
|
+
this.audio = options.audio;
|
7999
|
+
this.warnings = options.warnings;
|
8000
|
+
this.responses = options.responses;
|
8001
|
+
this.providerMetadata = (_a17 = options.providerMetadata) != null ? _a17 : {};
|
8002
|
+
}
|
8003
|
+
};
|
8004
|
+
|
8005
|
+
// errors/no-transcript-generated-error.ts
|
8006
|
+
var import_provider25 = require("@ai-sdk/provider");
|
8007
|
+
var NoTranscriptGeneratedError = class extends import_provider25.AISDKError {
|
7894
8008
|
constructor(options) {
|
7895
8009
|
super({
|
7896
8010
|
name: "AI_NoTranscriptGeneratedError",
|
@@ -8037,37 +8151,41 @@ function extractReasoningMiddleware({
|
|
8037
8151
|
return {
|
8038
8152
|
middlewareVersion: "v2",
|
8039
8153
|
wrapGenerate: async ({ doGenerate }) => {
|
8040
|
-
const {
|
8041
|
-
|
8042
|
-
|
8043
|
-
|
8044
|
-
|
8045
|
-
|
8046
|
-
|
8047
|
-
|
8048
|
-
|
8049
|
-
|
8050
|
-
|
8051
|
-
|
8052
|
-
|
8053
|
-
|
8054
|
-
const
|
8055
|
-
|
8056
|
-
|
8057
|
-
|
8058
|
-
|
8154
|
+
const { content, ...rest } = await doGenerate();
|
8155
|
+
const transformedContent = [];
|
8156
|
+
for (const part of content) {
|
8157
|
+
if (part.type !== "text") {
|
8158
|
+
transformedContent.push(part);
|
8159
|
+
continue;
|
8160
|
+
}
|
8161
|
+
const text2 = startWithReasoning ? openingTag + part.text : part.text;
|
8162
|
+
const regexp = new RegExp(`${openingTag}(.*?)${closingTag}`, "gs");
|
8163
|
+
const matches = Array.from(text2.matchAll(regexp));
|
8164
|
+
if (!matches.length) {
|
8165
|
+
transformedContent.push(part);
|
8166
|
+
continue;
|
8167
|
+
}
|
8168
|
+
const reasoningText = matches.map((match) => match[1]).join(separator);
|
8169
|
+
let textWithoutReasoning = text2;
|
8170
|
+
for (let i = matches.length - 1; i >= 0; i--) {
|
8171
|
+
const match = matches[i];
|
8172
|
+
const beforeMatch = textWithoutReasoning.slice(0, match.index);
|
8173
|
+
const afterMatch = textWithoutReasoning.slice(
|
8174
|
+
match.index + match[0].length
|
8175
|
+
);
|
8176
|
+
textWithoutReasoning = beforeMatch + (beforeMatch.length > 0 && afterMatch.length > 0 ? separator : "") + afterMatch;
|
8177
|
+
}
|
8178
|
+
transformedContent.push({
|
8179
|
+
type: "reasoning",
|
8180
|
+
reasoningType: "text",
|
8181
|
+
text: reasoningText
|
8182
|
+
});
|
8183
|
+
transformedContent.push({
|
8184
|
+
type: "text",
|
8185
|
+
text: textWithoutReasoning
|
8186
|
+
});
|
8059
8187
|
}
|
8060
|
-
return {
|
8061
|
-
...rest,
|
8062
|
-
text: { type: "text", text: textWithoutReasoning },
|
8063
|
-
reasoning: reasoningText.length > 0 ? [
|
8064
|
-
{
|
8065
|
-
type: "reasoning",
|
8066
|
-
reasoningType: "text",
|
8067
|
-
text: reasoningText
|
8068
|
-
}
|
8069
|
-
] : void 0
|
8070
|
-
};
|
8188
|
+
return { content: transformedContent, ...rest };
|
8071
8189
|
},
|
8072
8190
|
wrapStream: async ({ doStream }) => {
|
8073
8191
|
const { stream, ...rest } = await doStream();
|
@@ -8142,26 +8260,13 @@ function simulateStreamingMiddleware() {
|
|
8142
8260
|
const result = await doGenerate();
|
8143
8261
|
const simulatedStream = new ReadableStream({
|
8144
8262
|
start(controller) {
|
8263
|
+
controller.enqueue({
|
8264
|
+
type: "stream-start",
|
8265
|
+
warnings: result.warnings
|
8266
|
+
});
|
8145
8267
|
controller.enqueue({ type: "response-metadata", ...result.response });
|
8146
|
-
|
8147
|
-
|
8148
|
-
controller.enqueue(reasoningPart);
|
8149
|
-
}
|
8150
|
-
}
|
8151
|
-
if (result.text) {
|
8152
|
-
controller.enqueue(result.text);
|
8153
|
-
}
|
8154
|
-
if (result.toolCalls) {
|
8155
|
-
for (const toolCall of result.toolCalls) {
|
8156
|
-
controller.enqueue({
|
8157
|
-
type: "tool-call-delta",
|
8158
|
-
toolCallType: "function",
|
8159
|
-
toolCallId: toolCall.toolCallId,
|
8160
|
-
toolName: toolCall.toolName,
|
8161
|
-
argsTextDelta: toolCall.args
|
8162
|
-
});
|
8163
|
-
controller.enqueue(toolCall);
|
8164
|
-
}
|
8268
|
+
for (const part of result.content) {
|
8269
|
+
controller.enqueue(part);
|
8165
8270
|
}
|
8166
8271
|
controller.enqueue({
|
8167
8272
|
type: "finish",
|
@@ -8176,8 +8281,7 @@ function simulateStreamingMiddleware() {
|
|
8176
8281
|
return {
|
8177
8282
|
stream: simulatedStream,
|
8178
8283
|
request: result.request,
|
8179
|
-
response: result.response
|
8180
|
-
warnings: result.warnings
|
8284
|
+
response: result.response
|
8181
8285
|
};
|
8182
8286
|
}
|
8183
8287
|
};
|
@@ -8234,7 +8338,6 @@ var doWrap = ({
|
|
8234
8338
|
}
|
8235
8339
|
};
|
8236
8340
|
};
|
8237
|
-
var experimental_wrapLanguageModel = wrapLanguageModel;
|
8238
8341
|
|
8239
8342
|
// core/prompt/append-client-message.ts
|
8240
8343
|
function appendClientMessage({
|
@@ -8248,7 +8351,7 @@ function appendClientMessage({
|
|
8248
8351
|
}
|
8249
8352
|
|
8250
8353
|
// core/prompt/append-response-messages.ts
|
8251
|
-
var
|
8354
|
+
var import_provider26 = require("@ai-sdk/provider");
|
8252
8355
|
function appendResponseMessages({
|
8253
8356
|
messages,
|
8254
8357
|
responseMessages,
|
@@ -8331,7 +8434,7 @@ function appendResponseMessages({
|
|
8331
8434
|
break;
|
8332
8435
|
case "file":
|
8333
8436
|
if (part.data instanceof URL) {
|
8334
|
-
throw new
|
8437
|
+
throw new import_provider26.AISDKError({
|
8335
8438
|
name: "InvalidAssistantFileData",
|
8336
8439
|
message: "File data cannot be a URL"
|
8337
8440
|
});
|
@@ -8425,7 +8528,7 @@ function appendResponseMessages({
|
|
8425
8528
|
}
|
8426
8529
|
|
8427
8530
|
// core/registry/custom-provider.ts
|
8428
|
-
var
|
8531
|
+
var import_provider27 = require("@ai-sdk/provider");
|
8429
8532
|
function customProvider({
|
8430
8533
|
languageModels,
|
8431
8534
|
textEmbeddingModels,
|
@@ -8440,7 +8543,7 @@ function customProvider({
|
|
8440
8543
|
if (fallbackProvider) {
|
8441
8544
|
return fallbackProvider.languageModel(modelId);
|
8442
8545
|
}
|
8443
|
-
throw new
|
8546
|
+
throw new import_provider27.NoSuchModelError({ modelId, modelType: "languageModel" });
|
8444
8547
|
},
|
8445
8548
|
textEmbeddingModel(modelId) {
|
8446
8549
|
if (textEmbeddingModels != null && modelId in textEmbeddingModels) {
|
@@ -8449,7 +8552,7 @@ function customProvider({
|
|
8449
8552
|
if (fallbackProvider) {
|
8450
8553
|
return fallbackProvider.textEmbeddingModel(modelId);
|
8451
8554
|
}
|
8452
|
-
throw new
|
8555
|
+
throw new import_provider27.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
8453
8556
|
},
|
8454
8557
|
imageModel(modelId) {
|
8455
8558
|
if (imageModels != null && modelId in imageModels) {
|
@@ -8458,19 +8561,19 @@ function customProvider({
|
|
8458
8561
|
if (fallbackProvider == null ? void 0 : fallbackProvider.imageModel) {
|
8459
8562
|
return fallbackProvider.imageModel(modelId);
|
8460
8563
|
}
|
8461
|
-
throw new
|
8564
|
+
throw new import_provider27.NoSuchModelError({ modelId, modelType: "imageModel" });
|
8462
8565
|
}
|
8463
8566
|
};
|
8464
8567
|
}
|
8465
8568
|
var experimental_customProvider = customProvider;
|
8466
8569
|
|
8467
8570
|
// core/registry/no-such-provider-error.ts
|
8468
|
-
var
|
8571
|
+
var import_provider28 = require("@ai-sdk/provider");
|
8469
8572
|
var name16 = "AI_NoSuchProviderError";
|
8470
8573
|
var marker16 = `vercel.ai.error.${name16}`;
|
8471
8574
|
var symbol16 = Symbol.for(marker16);
|
8472
8575
|
var _a16;
|
8473
|
-
var NoSuchProviderError = class extends
|
8576
|
+
var NoSuchProviderError = class extends import_provider28.NoSuchModelError {
|
8474
8577
|
constructor({
|
8475
8578
|
modelId,
|
8476
8579
|
modelType,
|
@@ -8484,13 +8587,13 @@ var NoSuchProviderError = class extends import_provider27.NoSuchModelError {
|
|
8484
8587
|
this.availableProviders = availableProviders;
|
8485
8588
|
}
|
8486
8589
|
static isInstance(error) {
|
8487
|
-
return
|
8590
|
+
return import_provider28.AISDKError.hasMarker(error, marker16);
|
8488
8591
|
}
|
8489
8592
|
};
|
8490
8593
|
_a16 = symbol16;
|
8491
8594
|
|
8492
8595
|
// core/registry/provider-registry.ts
|
8493
|
-
var
|
8596
|
+
var import_provider29 = require("@ai-sdk/provider");
|
8494
8597
|
function createProviderRegistry(providers, {
|
8495
8598
|
separator = ":"
|
8496
8599
|
} = {}) {
|
@@ -8529,7 +8632,7 @@ var DefaultProviderRegistry = class {
|
|
8529
8632
|
splitId(id, modelType) {
|
8530
8633
|
const index = id.indexOf(this.separator);
|
8531
8634
|
if (index === -1) {
|
8532
|
-
throw new
|
8635
|
+
throw new import_provider29.NoSuchModelError({
|
8533
8636
|
modelId: id,
|
8534
8637
|
modelType,
|
8535
8638
|
message: `Invalid ${modelType} id for registry: ${id} (must be in the format "providerId${this.separator}modelId")`
|
@@ -8542,7 +8645,7 @@ var DefaultProviderRegistry = class {
|
|
8542
8645
|
const [providerId, modelId] = this.splitId(id, "languageModel");
|
8543
8646
|
const model = (_b = (_a17 = this.getProvider(providerId)).languageModel) == null ? void 0 : _b.call(_a17, modelId);
|
8544
8647
|
if (model == null) {
|
8545
|
-
throw new
|
8648
|
+
throw new import_provider29.NoSuchModelError({ modelId: id, modelType: "languageModel" });
|
8546
8649
|
}
|
8547
8650
|
return model;
|
8548
8651
|
}
|
@@ -8552,7 +8655,7 @@ var DefaultProviderRegistry = class {
|
|
8552
8655
|
const provider = this.getProvider(providerId);
|
8553
8656
|
const model = (_a17 = provider.textEmbeddingModel) == null ? void 0 : _a17.call(provider, modelId);
|
8554
8657
|
if (model == null) {
|
8555
|
-
throw new
|
8658
|
+
throw new import_provider29.NoSuchModelError({
|
8556
8659
|
modelId: id,
|
8557
8660
|
modelType: "textEmbeddingModel"
|
8558
8661
|
});
|
@@ -8565,7 +8668,7 @@ var DefaultProviderRegistry = class {
|
|
8565
8668
|
const provider = this.getProvider(providerId);
|
8566
8669
|
const model = (_a17 = provider.imageModel) == null ? void 0 : _a17.call(provider, modelId);
|
8567
8670
|
if (model == null) {
|
8568
|
-
throw new
|
8671
|
+
throw new import_provider29.NoSuchModelError({ modelId: id, modelType: "imageModel" });
|
8569
8672
|
}
|
8570
8673
|
return model;
|
8571
8674
|
}
|
@@ -9463,8 +9566,8 @@ var StreamData = class {
|
|
9463
9566
|
experimental_createProviderRegistry,
|
9464
9567
|
experimental_customProvider,
|
9465
9568
|
experimental_generateImage,
|
9569
|
+
experimental_generateSpeech,
|
9466
9570
|
experimental_transcribe,
|
9467
|
-
experimental_wrapLanguageModel,
|
9468
9571
|
extractMaxToolInvocationStep,
|
9469
9572
|
extractReasoningMiddleware,
|
9470
9573
|
fillMessageParts,
|