@xsai/stream-text 0.1.3 → 0.2.0-beta.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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ToolCall, FinishReason, Usage, ChatOptions, Tool, Message, StepType, CompletionToolCall, CompletionToolResult, AssistantMessage } from '@xsai/shared-chat';
1
+ import { ToolCall, FinishReason, Usage, ChatOptions, AssistantMessage, Message, StepType, CompletionToolCall, CompletionToolResult, Tool } from '@xsai/shared-chat';
2
2
 
3
3
  interface StreamTextChunkResult {
4
4
  choices: {
package/dist/index.js CHANGED
@@ -1,19 +1,16 @@
1
- // ../shared/src/error/index.ts
2
- var XSAIError = class extends Error {
1
+ import { chat, executeTool, determineStepType } from '@xsai/shared-chat';
2
+
3
+ class XSAIError extends Error {
3
4
  response;
4
5
  constructor(message, response) {
5
6
  super(message);
6
7
  this.name = "XSAIError";
7
8
  this.response = response;
8
9
  }
9
- };
10
-
11
- // src/index.ts
12
- import { chat, determineStepType, executeTool } from "@xsai/shared-chat";
10
+ }
13
11
 
14
- // src/helper.ts
15
- var CHUNK_HEADER_PREFIX = "data:";
16
- var parseChunk = (text) => {
12
+ const CHUNK_HEADER_PREFIX = "data:";
13
+ const parseChunk = (text) => {
17
14
  if (!text || !text.startsWith(CHUNK_HEADER_PREFIX))
18
15
  return [void 0, false];
19
16
  const content = text.slice(CHUNK_HEADER_PREFIX.length);
@@ -28,8 +25,7 @@ var parseChunk = (text) => {
28
25
  return [chunk, false];
29
26
  };
30
27
 
31
- // src/index.ts
32
- var streamText = async (options) => {
28
+ const streamText = async (options) => {
33
29
  let chunkCtrl;
34
30
  let stepCtrl;
35
31
  let textCtrl;
@@ -67,12 +63,6 @@ var streamText = async (options) => {
67
63
  if (state.endedToolCallIDs.has(id)) {
68
64
  return;
69
65
  }
70
- const toolCall = step.choices[state.index].message.tool_calls[id];
71
- try {
72
- toolCall.function.parsed_arguments = JSON.parse(toolCall.function.arguments);
73
- } catch (error) {
74
- state.toolCallErrors[id] = error;
75
- }
76
66
  state.endedToolCallIDs.add(id);
77
67
  state.currentToolID = null;
78
68
  };
@@ -199,12 +189,13 @@ var streamText = async (options) => {
199
189
  return;
200
190
  }
201
191
  try {
202
- const { result } = await executeTool({
192
+ const { parsedArgs, result, toolName } = await executeTool({
203
193
  abortSignal: options2.abortSignal,
204
194
  messages: options2.messages,
205
195
  toolCall,
206
196
  tools: options2.tools
207
197
  });
198
+ toolCall.function.parsed_arguments = parsedArgs;
208
199
  state.toolCallResults[id] = result;
209
200
  step.messages.push({
210
201
  content: result,
@@ -212,12 +203,10 @@ var streamText = async (options) => {
212
203
  tool_call_id: id
213
204
  });
214
205
  step.toolResults.push({
215
- args: toolCall.function.parsed_arguments,
216
- // TODO: use parsedArgs from executeTool
206
+ args: parsedArgs,
217
207
  result,
218
208
  toolCallId: id,
219
- toolName: toolCall.function.name
220
- // TODO: use toolName from executeTool
209
+ toolName
221
210
  });
222
211
  } catch (error) {
223
212
  state.toolCallErrors[id] = error;
@@ -258,6 +247,5 @@ var streamText = async (options) => {
258
247
  textStream
259
248
  });
260
249
  };
261
- export {
262
- streamText
263
- };
250
+
251
+ export { streamText };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xsai/stream-text",
3
3
  "type": "module",
4
- "version": "0.1.3",
4
+ "version": "0.2.0-beta.2",
5
5
  "description": "extra-small AI SDK for Browser, Node.js, Deno, Bun or Edge Runtime.",
6
6
  "author": "Moeru AI",
7
7
  "license": "MIT",
@@ -34,10 +34,10 @@
34
34
  "devDependencies": {
35
35
  "@xsai/shared": "",
36
36
  "@xsai/tool": "",
37
- "valibot": "^1.0.0-rc.3"
37
+ "valibot": "^1.0.0"
38
38
  },
39
39
  "scripts": {
40
- "build": "tsup",
40
+ "build": "pkgroll",
41
41
  "test": "vitest run",
42
42
  "test:watch": "vitest"
43
43
  },