ai 4.1.43 → 4.1.45
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 +56 -50
- package/dist/index.d.ts +56 -50
- package/dist/index.js +10 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -48,6 +48,9 @@ function createDataStream({
|
|
48
48
|
writeMessageAnnotation(annotation) {
|
49
49
|
safeEnqueue(formatDataStreamPart("message_annotations", [annotation]));
|
50
50
|
},
|
51
|
+
writeSource(source) {
|
52
|
+
safeEnqueue(formatDataStreamPart("source", source));
|
53
|
+
},
|
51
54
|
merge(streamArg) {
|
52
55
|
ongoingStreamPromises.push(
|
53
56
|
(async () => {
|
@@ -5793,17 +5796,19 @@ function getPotentialStartIndex(text2, searchedText) {
|
|
5793
5796
|
// core/middleware/extract-reasoning-middleware.ts
|
5794
5797
|
function extractReasoningMiddleware({
|
5795
5798
|
tagName,
|
5796
|
-
separator = "\n"
|
5799
|
+
separator = "\n",
|
5800
|
+
startWithReasoning = false
|
5797
5801
|
}) {
|
5798
5802
|
const openingTag = `<${tagName}>`;
|
5799
5803
|
const closingTag = `</${tagName}>`;
|
5800
5804
|
return {
|
5801
5805
|
middlewareVersion: "v1",
|
5802
5806
|
wrapGenerate: async ({ doGenerate }) => {
|
5803
|
-
const { text:
|
5804
|
-
if (
|
5805
|
-
return { text:
|
5807
|
+
const { text: rawText, ...rest } = await doGenerate();
|
5808
|
+
if (rawText == null) {
|
5809
|
+
return { text: rawText, ...rest };
|
5806
5810
|
}
|
5811
|
+
const text2 = startWithReasoning ? openingTag + rawText : rawText;
|
5807
5812
|
const regexp = new RegExp(`${openingTag}(.*?)${closingTag}`, "gs");
|
5808
5813
|
const matches = Array.from(text2.matchAll(regexp));
|
5809
5814
|
if (!matches.length) {
|
@@ -5826,7 +5831,7 @@ function extractReasoningMiddleware({
|
|
5826
5831
|
let isFirstReasoning = true;
|
5827
5832
|
let isFirstText = true;
|
5828
5833
|
let afterSwitch = false;
|
5829
|
-
let isReasoning =
|
5834
|
+
let isReasoning = startWithReasoning;
|
5830
5835
|
let buffer = "";
|
5831
5836
|
return {
|
5832
5837
|
stream: stream.pipeThrough(
|