ai 7.0.10 → 7.0.12
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 +16 -0
- package/dist/index.js +42 -8
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +35 -6
- package/dist/internal/index.js.map +1 -1
- package/docs/03-ai-sdk-core/26-reasoning.mdx +1 -1
- package/docs/03-ai-sdk-core/36-transcription.mdx +2 -2
- package/docs/07-reference/01-ai-sdk-core/index.mdx +5 -0
- package/package.json +3 -3
- package/src/generate-text/to-response-messages.ts +45 -1
- package/src/middleware/extract-json-middleware.ts +12 -3
- package/src/telemetry/tracing-channel-publisher.ts +3 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 7.0.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ecfeb6f: Sort tool results by their tool call order when converting generation output to response messages.
|
|
8
|
+
- a193137: Fix `extractJsonMiddleware` preserving leading whitespace in the final streamed text suffix when no markdown fence prefix was stripped.
|
|
9
|
+
- Updated dependencies [c6f5e62]
|
|
10
|
+
- @ai-sdk/gateway@4.0.9
|
|
11
|
+
- @ai-sdk/provider-utils@5.0.4
|
|
12
|
+
|
|
13
|
+
## 7.0.11
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 0a87626: fix(ai): replace dynamic import() with loadBuiltinModule for diagnostics_channel to fix React Native/Hermes builds
|
|
18
|
+
|
|
3
19
|
## 7.0.10
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1089,7 +1089,7 @@ import {
|
|
|
1089
1089
|
} from "@ai-sdk/provider-utils";
|
|
1090
1090
|
|
|
1091
1091
|
// src/version.ts
|
|
1092
|
-
var VERSION = true ? "7.0.
|
|
1092
|
+
var VERSION = true ? "7.0.12" : "0.0.0-test";
|
|
1093
1093
|
|
|
1094
1094
|
// src/util/download/download.ts
|
|
1095
1095
|
var download = async ({
|
|
@@ -4011,10 +4011,9 @@ async function loadDiagnosticsChannel() {
|
|
|
4011
4011
|
return void 0;
|
|
4012
4012
|
}
|
|
4013
4013
|
if (diagnosticsChannelPromise == null) {
|
|
4014
|
-
diagnosticsChannelPromise =
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
).catch(() => void 0);
|
|
4014
|
+
diagnosticsChannelPromise = Promise.resolve(
|
|
4015
|
+
loadBuiltinModule("node:diagnostics_channel")
|
|
4016
|
+
);
|
|
4018
4017
|
}
|
|
4019
4018
|
return diagnosticsChannelPromise;
|
|
4020
4019
|
}
|
|
@@ -4590,6 +4589,7 @@ async function toResponseMessages({
|
|
|
4590
4589
|
tools
|
|
4591
4590
|
}) {
|
|
4592
4591
|
const responseMessages = [];
|
|
4592
|
+
const toolCallOrder = /* @__PURE__ */ new Map();
|
|
4593
4593
|
const content = [];
|
|
4594
4594
|
for (const part of inputContent) {
|
|
4595
4595
|
if (part.type === "source") {
|
|
@@ -4640,6 +4640,9 @@ async function toResponseMessages({
|
|
|
4640
4640
|
});
|
|
4641
4641
|
break;
|
|
4642
4642
|
case "tool-call":
|
|
4643
|
+
if (!toolCallOrder.has(part.toolCallId)) {
|
|
4644
|
+
toolCallOrder.set(part.toolCallId, toolCallOrder.size);
|
|
4645
|
+
}
|
|
4643
4646
|
content.push({
|
|
4644
4647
|
type: "tool-call",
|
|
4645
4648
|
toolCallId: part.toolCallId,
|
|
@@ -4747,11 +4750,37 @@ async function toResponseMessages({
|
|
|
4747
4750
|
if (toolResultContent.length > 0) {
|
|
4748
4751
|
responseMessages.push({
|
|
4749
4752
|
role: "tool",
|
|
4750
|
-
content:
|
|
4753
|
+
content: sortToolResultContentByToolCallOrder({
|
|
4754
|
+
toolResultContent,
|
|
4755
|
+
toolCallOrder
|
|
4756
|
+
})
|
|
4751
4757
|
});
|
|
4752
4758
|
}
|
|
4753
4759
|
return responseMessages;
|
|
4754
4760
|
}
|
|
4761
|
+
function sortToolResultContentByToolCallOrder({
|
|
4762
|
+
toolResultContent,
|
|
4763
|
+
toolCallOrder
|
|
4764
|
+
}) {
|
|
4765
|
+
const sortedToolResults = toolResultContent.filter((part) => part.type === "tool-result").map((part, index) => ({ part, index })).sort((a, b) => {
|
|
4766
|
+
const aOrder = toolCallOrder.get(a.part.toolCallId);
|
|
4767
|
+
const bOrder = toolCallOrder.get(b.part.toolCallId);
|
|
4768
|
+
if (aOrder == null && bOrder == null) {
|
|
4769
|
+
return a.index - b.index;
|
|
4770
|
+
}
|
|
4771
|
+
if (aOrder == null) {
|
|
4772
|
+
return 1;
|
|
4773
|
+
}
|
|
4774
|
+
if (bOrder == null) {
|
|
4775
|
+
return -1;
|
|
4776
|
+
}
|
|
4777
|
+
return aOrder - bOrder || a.index - b.index;
|
|
4778
|
+
}).map(({ part }) => part);
|
|
4779
|
+
let toolResultIndex = 0;
|
|
4780
|
+
return toolResultContent.map(
|
|
4781
|
+
(part) => part.type === "tool-result" ? sortedToolResults[toolResultIndex++] : part
|
|
4782
|
+
);
|
|
4783
|
+
}
|
|
4755
4784
|
|
|
4756
4785
|
// src/generate-text/tool-approval-signature.ts
|
|
4757
4786
|
import {
|
|
@@ -13629,6 +13658,9 @@ function defaultSettingsMiddleware({
|
|
|
13629
13658
|
function defaultTransform(text2) {
|
|
13630
13659
|
return text2.replace(/^```(?:json)?\s*\n?/, "").replace(/\n?```\s*$/, "").trim();
|
|
13631
13660
|
}
|
|
13661
|
+
function stripMarkdownCodeFenceSuffix(text2) {
|
|
13662
|
+
return text2.replace(/\n?```\s*$/, "").trimEnd();
|
|
13663
|
+
}
|
|
13632
13664
|
function extractJsonMiddleware(options) {
|
|
13633
13665
|
var _a22;
|
|
13634
13666
|
const transform = (_a22 = options == null ? void 0 : options.transform) != null ? _a22 : defaultTransform;
|
|
@@ -13723,9 +13755,11 @@ function extractJsonMiddleware(options) {
|
|
|
13723
13755
|
if (block.phase === "buffering") {
|
|
13724
13756
|
remaining = transform(remaining);
|
|
13725
13757
|
} else if (block.prefixStripped) {
|
|
13726
|
-
remaining = remaining
|
|
13727
|
-
} else {
|
|
13758
|
+
remaining = stripMarkdownCodeFenceSuffix(remaining);
|
|
13759
|
+
} else if (block.phase === "prefix") {
|
|
13728
13760
|
remaining = transform(remaining);
|
|
13761
|
+
} else {
|
|
13762
|
+
remaining = stripMarkdownCodeFenceSuffix(remaining);
|
|
13729
13763
|
}
|
|
13730
13764
|
if (remaining.length > 0) {
|
|
13731
13765
|
controller.enqueue({
|