@xsai/stream-text 0.2.0-beta.1 → 0.2.0-beta.3
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 +2 -3
- package/dist/index.js +13 -14
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ToolCall, FinishReason, Usage, ChatOptions,
|
|
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: {
|
|
@@ -50,9 +50,8 @@ interface StreamTextOptions extends ChatOptions {
|
|
|
50
50
|
/**
|
|
51
51
|
* Return usage.
|
|
52
52
|
* @default `undefined`
|
|
53
|
-
* @remarks Ollama doesn't support this, see {@link https://github.com/ollama/ollama/issues/5200}
|
|
54
53
|
*/
|
|
55
|
-
|
|
54
|
+
includeUsage?: boolean;
|
|
56
55
|
};
|
|
57
56
|
/**
|
|
58
57
|
* List of tools to be used in the stream.
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
+
}
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
const strCamelToSnake = (str) => str.replace(/[A-Z]/g, (s) => `_${s.toLowerCase()}`);
|
|
13
|
+
const objCamelToSnake = (obj) => Object.fromEntries(Object.entries(obj).map(([k, v]) => [strCamelToSnake(k), v]));
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var parseChunk = (text) => {
|
|
15
|
+
const CHUNK_HEADER_PREFIX = "data:";
|
|
16
|
+
const parseChunk = (text) => {
|
|
17
17
|
if (!text || !text.startsWith(CHUNK_HEADER_PREFIX))
|
|
18
18
|
return [void 0, false];
|
|
19
19
|
const content = text.slice(CHUNK_HEADER_PREFIX.length);
|
|
@@ -28,8 +28,7 @@ var parseChunk = (text) => {
|
|
|
28
28
|
return [chunk, false];
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
var streamText = async (options) => {
|
|
31
|
+
const streamText = async (options) => {
|
|
33
32
|
let chunkCtrl;
|
|
34
33
|
let stepCtrl;
|
|
35
34
|
let textCtrl;
|
|
@@ -72,7 +71,8 @@ var streamText = async (options) => {
|
|
|
72
71
|
};
|
|
73
72
|
await chat({
|
|
74
73
|
...options2,
|
|
75
|
-
stream: true
|
|
74
|
+
stream: true,
|
|
75
|
+
streamOptions: options2.streamOptions != null ? objCamelToSnake(options2.streamOptions) : void 0
|
|
76
76
|
}).then(
|
|
77
77
|
async (res) => res.body.pipeThrough(new TransformStream({
|
|
78
78
|
transform: async (chunk, controller) => {
|
|
@@ -251,6 +251,5 @@ var streamText = async (options) => {
|
|
|
251
251
|
textStream
|
|
252
252
|
});
|
|
253
253
|
};
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
};
|
|
254
|
+
|
|
255
|
+
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.2.0-beta.
|
|
4
|
+
"version": "0.2.0-beta.3",
|
|
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",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"valibot": "^1.0.0"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
|
-
"build": "
|
|
40
|
+
"build": "pkgroll",
|
|
41
41
|
"test": "vitest run",
|
|
42
42
|
"test:watch": "vitest"
|
|
43
43
|
},
|