ai 3.4.31 → 3.4.33
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 +12 -0
- package/dist/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +28 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# ai
|
2
2
|
|
3
|
+
## 3.4.33
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- ac380e3: fix (provider/anthropic): continuation mode with 3+ steps
|
8
|
+
|
9
|
+
## 3.4.32
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- 6bb9e51: fix (ai/core): expose response.messages in streamText
|
14
|
+
|
3
15
|
## 3.4.31
|
4
16
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
@@ -1775,7 +1775,17 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>> {
|
|
1775
1775
|
/**
|
1776
1776
|
Additional response information from the last step.
|
1777
1777
|
*/
|
1778
|
-
readonly response: Promise<
|
1778
|
+
readonly response: Promise<LanguageModelResponseMetadata & {
|
1779
|
+
/**
|
1780
|
+
The response messages that were generated during the call. It consists of an assistant message,
|
1781
|
+
potentially containing tool calls.
|
1782
|
+
|
1783
|
+
When there are tool results, there is an additional tool message with the tool results that are available.
|
1784
|
+
If there are tools that do not have execute functions, they are not included in the tool results and
|
1785
|
+
need to be added separately.
|
1786
|
+
*/
|
1787
|
+
messages: Array<CoreAssistantMessage | CoreToolMessage>;
|
1788
|
+
}>;
|
1779
1789
|
/**
|
1780
1790
|
A text stream that returns only the generated text deltas. You can use it
|
1781
1791
|
as either an AsyncIterable or a ReadableStream. When an error occurs, the
|
package/dist/index.d.ts
CHANGED
@@ -1775,7 +1775,17 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>> {
|
|
1775
1775
|
/**
|
1776
1776
|
Additional response information from the last step.
|
1777
1777
|
*/
|
1778
|
-
readonly response: Promise<
|
1778
|
+
readonly response: Promise<LanguageModelResponseMetadata & {
|
1779
|
+
/**
|
1780
|
+
The response messages that were generated during the call. It consists of an assistant message,
|
1781
|
+
potentially containing tool calls.
|
1782
|
+
|
1783
|
+
When there are tool results, there is an additional tool message with the tool results that are available.
|
1784
|
+
If there are tools that do not have execute functions, they are not included in the tool results and
|
1785
|
+
need to be added separately.
|
1786
|
+
*/
|
1787
|
+
messages: Array<CoreAssistantMessage | CoreToolMessage>;
|
1788
|
+
}>;
|
1779
1789
|
/**
|
1780
1790
|
A text stream that returns only the generated text deltas. You can use it
|
1781
1791
|
as either an AsyncIterable or a ReadableStream. When an error occurs, the
|
package/dist/index.js
CHANGED
@@ -3395,7 +3395,7 @@ async function generateText({
|
|
3395
3395
|
}),
|
3396
3396
|
tracer,
|
3397
3397
|
fn: async (span) => {
|
3398
|
-
var _a11, _b, _c, _d, _e, _f
|
3398
|
+
var _a11, _b, _c, _d, _e, _f;
|
3399
3399
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
3400
3400
|
const mode = {
|
3401
3401
|
type: "regular",
|
@@ -3549,12 +3549,15 @@ async function generateText({
|
|
3549
3549
|
nextStepType = "tool-result";
|
3550
3550
|
}
|
3551
3551
|
}
|
3552
|
-
const
|
3552
|
+
const originalText = (_b = currentModelResponse.text) != null ? _b : "";
|
3553
|
+
const stepTextLeadingWhitespaceTrimmed = stepType === "continue" && // only for continue steps
|
3554
|
+
text.trimEnd() !== text ? originalText.trimStart() : originalText;
|
3555
|
+
const stepText = nextStepType === "continue" ? removeTextAfterLastWhitespace(stepTextLeadingWhitespaceTrimmed) : stepTextLeadingWhitespaceTrimmed;
|
3553
3556
|
text = nextStepType === "continue" || stepType === "continue" ? text + stepText : stepText;
|
3554
3557
|
if (stepType === "continue") {
|
3555
3558
|
const lastMessage = responseMessages[responseMessages.length - 1];
|
3556
3559
|
if (typeof lastMessage.content === "string") {
|
3557
|
-
lastMessage.content
|
3560
|
+
lastMessage.content += stepText;
|
3558
3561
|
} else {
|
3559
3562
|
lastMessage.content.push({
|
3560
3563
|
text: stepText,
|
@@ -3580,10 +3583,10 @@ async function generateText({
|
|
3580
3583
|
usage: currentUsage,
|
3581
3584
|
warnings: currentModelResponse.warnings,
|
3582
3585
|
logprobs: currentModelResponse.logprobs,
|
3583
|
-
request: (
|
3586
|
+
request: (_c = currentModelResponse.request) != null ? _c : {},
|
3584
3587
|
response: {
|
3585
3588
|
...currentModelResponse.response,
|
3586
|
-
headers: (
|
3589
|
+
headers: (_d = currentModelResponse.rawResponse) == null ? void 0 : _d.headers,
|
3587
3590
|
// deep clone msgs to avoid mutating past messages in multi-step:
|
3588
3591
|
messages: JSON.parse(JSON.stringify(responseMessages))
|
3589
3592
|
},
|
@@ -3625,10 +3628,10 @@ async function generateText({
|
|
3625
3628
|
finishReason: currentModelResponse.finishReason,
|
3626
3629
|
usage,
|
3627
3630
|
warnings: currentModelResponse.warnings,
|
3628
|
-
request: (
|
3631
|
+
request: (_e = currentModelResponse.request) != null ? _e : {},
|
3629
3632
|
response: {
|
3630
3633
|
...currentModelResponse.response,
|
3631
|
-
headers: (
|
3634
|
+
headers: (_f = currentModelResponse.rawResponse) == null ? void 0 : _f.headers,
|
3632
3635
|
messages: responseMessages
|
3633
3636
|
},
|
3634
3637
|
logprobs: currentModelResponse.logprobs,
|
@@ -4328,7 +4331,8 @@ var DefaultStreamTextResult = class {
|
|
4328
4331
|
},
|
4329
4332
|
stepType,
|
4330
4333
|
previousStepText = "",
|
4331
|
-
stepRequest
|
4334
|
+
stepRequest,
|
4335
|
+
hasLeadingWhitespace
|
4332
4336
|
}) {
|
4333
4337
|
const stepToolCalls = [];
|
4334
4338
|
const stepToolResults = [];
|
@@ -4350,6 +4354,8 @@ var DefaultStreamTextResult = class {
|
|
4350
4354
|
};
|
4351
4355
|
let chunkBuffer = "";
|
4352
4356
|
let chunkTextPublished = false;
|
4357
|
+
let inWhitespacePrefix = true;
|
4358
|
+
let hasWhitespaceSuffix = false;
|
4353
4359
|
async function publishTextChunk({
|
4354
4360
|
controller,
|
4355
4361
|
chunk
|
@@ -4358,6 +4364,7 @@ var DefaultStreamTextResult = class {
|
|
4358
4364
|
stepText += chunk.textDelta;
|
4359
4365
|
fullStepText += chunk.textDelta;
|
4360
4366
|
chunkTextPublished = true;
|
4367
|
+
hasWhitespaceSuffix = chunk.textDelta.trimEnd() !== chunk.textDelta;
|
4361
4368
|
await (onChunk == null ? void 0 : onChunk({ chunk }));
|
4362
4369
|
}
|
4363
4370
|
addStream(
|
@@ -4386,7 +4393,12 @@ var DefaultStreamTextResult = class {
|
|
4386
4393
|
switch (chunkType) {
|
4387
4394
|
case "text-delta": {
|
4388
4395
|
if (continueSteps) {
|
4389
|
-
|
4396
|
+
const trimmedChunkText = inWhitespacePrefix && hasLeadingWhitespace ? chunk.textDelta.trimStart() : chunk.textDelta;
|
4397
|
+
if (trimmedChunkText.length === 0) {
|
4398
|
+
break;
|
4399
|
+
}
|
4400
|
+
inWhitespacePrefix = false;
|
4401
|
+
chunkBuffer += trimmedChunkText;
|
4390
4402
|
const split = splitOnLastWhitespace(chunkBuffer);
|
4391
4403
|
if (split != null) {
|
4392
4404
|
chunkBuffer = split.suffix;
|
@@ -4529,7 +4541,7 @@ var DefaultStreamTextResult = class {
|
|
4529
4541
|
if (stepType === "continue") {
|
4530
4542
|
const lastMessage = responseMessages[responseMessages.length - 1];
|
4531
4543
|
if (typeof lastMessage.content === "string") {
|
4532
|
-
lastMessage.content
|
4544
|
+
lastMessage.content += stepText;
|
4533
4545
|
} else {
|
4534
4546
|
lastMessage.content.push({
|
4535
4547
|
text: stepText,
|
@@ -4590,7 +4602,8 @@ var DefaultStreamTextResult = class {
|
|
4590
4602
|
usage: combinedUsage,
|
4591
4603
|
stepType: nextStepType,
|
4592
4604
|
previousStepText: fullStepText,
|
4593
|
-
stepRequest: result.request
|
4605
|
+
stepRequest: result.request,
|
4606
|
+
hasLeadingWhitespace: hasWhitespaceSuffix
|
4594
4607
|
});
|
4595
4608
|
return;
|
4596
4609
|
}
|
@@ -4635,7 +4648,8 @@ var DefaultStreamTextResult = class {
|
|
4635
4648
|
resolveRequest(stepRequest);
|
4636
4649
|
resolveResponse({
|
4637
4650
|
...stepResponse,
|
4638
|
-
headers: rawResponse == null ? void 0 : rawResponse.headers
|
4651
|
+
headers: rawResponse == null ? void 0 : rawResponse.headers,
|
4652
|
+
messages: responseMessages
|
4639
4653
|
});
|
4640
4654
|
resolveSteps(stepResults);
|
4641
4655
|
resolveResponseMessages(responseMessages);
|
@@ -4680,7 +4694,8 @@ var DefaultStreamTextResult = class {
|
|
4680
4694
|
responseMessages: [],
|
4681
4695
|
usage: void 0,
|
4682
4696
|
stepType: "initial",
|
4683
|
-
stepRequest: request
|
4697
|
+
stepRequest: request,
|
4698
|
+
hasLeadingWhitespace: false
|
4684
4699
|
});
|
4685
4700
|
}
|
4686
4701
|
/**
|