@xsai/stream-text 0.4.0 → 0.4.2

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.
Files changed (2) hide show
  1. package/dist/index.js +11 -3
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -46,6 +46,7 @@ const streamText = (options) => {
46
46
  const maxSteps = options.maxSteps ?? 1;
47
47
  let usage;
48
48
  let totalUsage;
49
+ let reasoningField;
49
50
  const resultSteps = new DelayedPromise();
50
51
  const resultMessages = new DelayedPromise();
51
52
  const resultUsage = new DelayedPromise();
@@ -78,7 +79,7 @@ const streamText = (options) => {
78
79
  completion_tokens: totalUsage.completion_tokens + u.completion_tokens,
79
80
  prompt_tokens: totalUsage.prompt_tokens + u.prompt_tokens,
80
81
  total_tokens: totalUsage.total_tokens + u.total_tokens
81
- } : { ...u };
82
+ } : u;
82
83
  };
83
84
  let text = "";
84
85
  let reasoningText;
@@ -110,7 +111,14 @@ const streamText = (options) => {
110
111
  if (chunk.choices == null || chunk.choices.length === 0)
111
112
  return;
112
113
  const choice = chunk.choices[0];
113
- if (choice.delta.reasoning_content != null) {
114
+ if (choice.delta.reasoning != null) {
115
+ if (reasoningField !== "reasoning")
116
+ reasoningField = "reasoning";
117
+ pushEvent({ text: choice.delta.reasoning, type: "reasoning-delta" });
118
+ pushReasoningText(choice.delta.reasoning);
119
+ } else if (choice.delta.reasoning_content != null) {
120
+ if (reasoningField !== "reasoning_content")
121
+ reasoningField = "reasoning_content";
114
122
  pushEvent({ text: choice.delta.reasoning_content, type: "reasoning-delta" });
115
123
  pushReasoningText(choice.delta.reasoning_content);
116
124
  }
@@ -151,8 +159,8 @@ const streamText = (options) => {
151
159
  }
152
160
  }));
153
161
  messages.push({
162
+ ...reasoningField != null ? { [reasoningField]: reasoningText } : {},
154
163
  content: text,
155
- reasoning_content: reasoningText,
156
164
  role: "assistant",
157
165
  tool_calls: tool_calls.length > 0 ? tool_calls : void 0
158
166
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xsai/stream-text",
3
3
  "type": "module",
4
- "version": "0.4.0",
4
+ "version": "0.4.2",
5
5
  "description": "extra-small AI SDK.",
6
6
  "author": "Moeru AI",
7
7
  "license": "MIT",
@@ -29,12 +29,12 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@xsai/shared": "~0.4.0",
33
- "@xsai/shared-chat": "~0.4.0"
32
+ "@xsai/shared": "~0.4.2",
33
+ "@xsai/shared-chat": "~0.4.2"
34
34
  },
35
35
  "devDependencies": {
36
36
  "valibot": "^1.0.0",
37
- "@xsai/tool": "~0.4.0"
37
+ "@xsai/tool": "~0.4.2"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "pkgroll",