ai 4.1.43 → 4.1.44

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # ai
2
2
 
3
+ ## 4.1.44
4
+
5
+ ### Patch Changes
6
+
7
+ - f8e7df2: fix (ai/core): add `startWithReasoning` option to `extractReasoningMiddleware`
8
+
3
9
  ## 4.1.43
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -2665,10 +2665,12 @@ type Experimental_LanguageModelV1Middleware = LanguageModelV1Middleware;
2665
2665
  *
2666
2666
  * @param tagName - The name of the XML tag to extract reasoning from.
2667
2667
  * @param separator - The separator to use between reasoning and text sections.
2668
+ * @param startWithReasoning - Whether to start with reasoning tokens.
2668
2669
  */
2669
- declare function extractReasoningMiddleware({ tagName, separator, }: {
2670
+ declare function extractReasoningMiddleware({ tagName, separator, startWithReasoning, }: {
2670
2671
  tagName: string;
2671
2672
  separator?: string;
2673
+ startWithReasoning?: boolean;
2672
2674
  }): LanguageModelV1Middleware;
2673
2675
 
2674
2676
  /**
package/dist/index.d.ts CHANGED
@@ -2665,10 +2665,12 @@ type Experimental_LanguageModelV1Middleware = LanguageModelV1Middleware;
2665
2665
  *
2666
2666
  * @param tagName - The name of the XML tag to extract reasoning from.
2667
2667
  * @param separator - The separator to use between reasoning and text sections.
2668
+ * @param startWithReasoning - Whether to start with reasoning tokens.
2668
2669
  */
2669
- declare function extractReasoningMiddleware({ tagName, separator, }: {
2670
+ declare function extractReasoningMiddleware({ tagName, separator, startWithReasoning, }: {
2670
2671
  tagName: string;
2671
2672
  separator?: string;
2673
+ startWithReasoning?: boolean;
2672
2674
  }): LanguageModelV1Middleware;
2673
2675
 
2674
2676
  /**
package/dist/index.js CHANGED
@@ -5839,17 +5839,19 @@ function getPotentialStartIndex(text2, searchedText) {
5839
5839
  // core/middleware/extract-reasoning-middleware.ts
5840
5840
  function extractReasoningMiddleware({
5841
5841
  tagName,
5842
- separator = "\n"
5842
+ separator = "\n",
5843
+ startWithReasoning = false
5843
5844
  }) {
5844
5845
  const openingTag = `<${tagName}>`;
5845
5846
  const closingTag = `</${tagName}>`;
5846
5847
  return {
5847
5848
  middlewareVersion: "v1",
5848
5849
  wrapGenerate: async ({ doGenerate }) => {
5849
- const { text: text2, ...rest } = await doGenerate();
5850
- if (text2 == null) {
5851
- return { text: text2, ...rest };
5850
+ const { text: rawText, ...rest } = await doGenerate();
5851
+ if (rawText == null) {
5852
+ return { text: rawText, ...rest };
5852
5853
  }
5854
+ const text2 = startWithReasoning ? openingTag + rawText : rawText;
5853
5855
  const regexp = new RegExp(`${openingTag}(.*?)${closingTag}`, "gs");
5854
5856
  const matches = Array.from(text2.matchAll(regexp));
5855
5857
  if (!matches.length) {
@@ -5872,7 +5874,7 @@ function extractReasoningMiddleware({
5872
5874
  let isFirstReasoning = true;
5873
5875
  let isFirstText = true;
5874
5876
  let afterSwitch = false;
5875
- let isReasoning = false;
5877
+ let isReasoning = startWithReasoning;
5876
5878
  let buffer = "";
5877
5879
  return {
5878
5880
  stream: stream.pipeThrough(