ai 2.1.0 → 2.1.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/README.md +89 -0
- package/dist/index.d.ts +48 -8
- package/dist/index.mjs +234 -26
- package/package.json +4 -4
- package/react/dist/index.d.ts +206 -3
- package/react/dist/index.js +2 -1
- package/react/dist/index.mjs +385 -7
- package/svelte/dist/index.d.ts +194 -4
- package/svelte/dist/index.js +2 -1
- package/svelte/dist/index.mjs +780 -7
- package/vue/dist/index.d.ts +194 -4
- package/vue/dist/index.mjs +345 -7
- package/dist/ai-stream.d.ts +0 -18
- package/dist/ai-stream.js +0 -132
- package/dist/ai-stream.mjs +0 -15
- package/dist/anthropic-stream.d.ts +0 -5
- package/dist/anthropic-stream.js +0 -133
- package/dist/anthropic-stream.mjs +0 -10
- package/dist/chunk-2JQWCLY2.mjs +0 -70
- package/dist/chunk-7KLTYB74.mjs +0 -70
- package/dist/chunk-BJMBMGA3.mjs +0 -34
- package/dist/chunk-KKQRUR3E.mjs +0 -51
- package/dist/chunk-RBP6ONSV.mjs +0 -45
- package/dist/chunk-TWW2ODJW.mjs +0 -32
- package/dist/chunk-U2OQ6HW6.mjs +0 -41
- package/dist/chunk-UJV6VDVU.mjs +0 -97
- package/dist/huggingface-stream.d.ts +0 -5
- package/dist/huggingface-stream.js +0 -121
- package/dist/huggingface-stream.mjs +0 -10
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.js +0 -568
- package/dist/index.test.mjs +0 -286
- package/dist/langchain-stream.d.ts +0 -12
- package/dist/langchain-stream.js +0 -102
- package/dist/langchain-stream.mjs +0 -10
- package/dist/openai-stream.d.ts +0 -5
- package/dist/openai-stream.js +0 -144
- package/dist/openai-stream.mjs +0 -10
- package/dist/streaming-text-response.d.ts +0 -17
- package/dist/streaming-text-response.js +0 -75
- package/dist/streaming-text-response.mjs +0 -11
- package/react/dist/chunk-5PP6W52J.mjs +0 -202
- package/react/dist/chunk-6EH3SWMP.mjs +0 -55
- package/react/dist/chunk-PW6HSU2N.mjs +0 -154
- package/react/dist/types-f862f74a.d.ts +0 -123
- package/react/dist/use-chat.d.ts +0 -42
- package/react/dist/use-chat.js +0 -276
- package/react/dist/use-chat.mjs +0 -8
- package/react/dist/use-completion.d.ts +0 -47
- package/react/dist/use-completion.js +0 -229
- package/react/dist/use-completion.mjs +0 -8
- package/svelte/dist/chunk-6USBQIV6.mjs +0 -177
- package/svelte/dist/chunk-BQ64GHZ3.mjs +0 -136
- package/svelte/dist/chunk-CENOSGDG.mjs +0 -493
- package/svelte/dist/types-f862f74a.d.ts +0 -123
- package/svelte/dist/use-chat.d.ts +0 -39
- package/svelte/dist/use-chat.js +0 -680
- package/svelte/dist/use-chat.mjs +0 -7
- package/svelte/dist/use-completion.d.ts +0 -38
- package/svelte/dist/use-completion.js +0 -640
- package/svelte/dist/use-completion.mjs +0 -7
- package/vue/dist/chunk-FT26CHLO.mjs +0 -137
- package/vue/dist/chunk-OYI6GFBM.mjs +0 -178
- package/vue/dist/chunk-WXH4YPZV.mjs +0 -54
- package/vue/dist/types-f862f74a.d.ts +0 -123
- package/vue/dist/use-chat.d.ts +0 -39
- package/vue/dist/use-chat.js +0 -252
- package/vue/dist/use-chat.mjs +0 -7
- package/vue/dist/use-completion.d.ts +0 -38
- package/vue/dist/use-completion.js +0 -212
- package/vue/dist/use-completion.mjs +0 -7
package/dist/ai-stream.mjs
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
AIStream,
|
3
|
-
createCallbacksTransformer,
|
4
|
-
createEventStreamTransformer,
|
5
|
-
init_ai_stream,
|
6
|
-
trimStartOfStreamHelper
|
7
|
-
} from "./chunk-UJV6VDVU.mjs";
|
8
|
-
import "./chunk-2JQWCLY2.mjs";
|
9
|
-
init_ai_stream();
|
10
|
-
export {
|
11
|
-
AIStream,
|
12
|
-
createCallbacksTransformer,
|
13
|
-
createEventStreamTransformer,
|
14
|
-
trimStartOfStreamHelper
|
15
|
-
};
|
package/dist/anthropic-stream.js
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
var __async = (__this, __arguments, generator) => {
|
20
|
-
return new Promise((resolve, reject) => {
|
21
|
-
var fulfilled = (value) => {
|
22
|
-
try {
|
23
|
-
step(generator.next(value));
|
24
|
-
} catch (e) {
|
25
|
-
reject(e);
|
26
|
-
}
|
27
|
-
};
|
28
|
-
var rejected = (value) => {
|
29
|
-
try {
|
30
|
-
step(generator.throw(value));
|
31
|
-
} catch (e) {
|
32
|
-
reject(e);
|
33
|
-
}
|
34
|
-
};
|
35
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
36
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
37
|
-
});
|
38
|
-
};
|
39
|
-
|
40
|
-
// streams/anthropic-stream.ts
|
41
|
-
var anthropic_stream_exports = {};
|
42
|
-
__export(anthropic_stream_exports, {
|
43
|
-
AnthropicStream: () => AnthropicStream
|
44
|
-
});
|
45
|
-
module.exports = __toCommonJS(anthropic_stream_exports);
|
46
|
-
|
47
|
-
// streams/ai-stream.ts
|
48
|
-
var import_eventsource_parser = require("eventsource-parser");
|
49
|
-
function createEventStreamTransformer(customParser) {
|
50
|
-
const decoder = new TextDecoder();
|
51
|
-
let parser;
|
52
|
-
return new TransformStream({
|
53
|
-
start(controller) {
|
54
|
-
return __async(this, null, function* () {
|
55
|
-
function onParse(event) {
|
56
|
-
if (event.type === "event") {
|
57
|
-
const data = event.data;
|
58
|
-
if (data === "[DONE]") {
|
59
|
-
controller.terminate();
|
60
|
-
return;
|
61
|
-
}
|
62
|
-
const message = customParser(data);
|
63
|
-
if (message)
|
64
|
-
controller.enqueue(message);
|
65
|
-
}
|
66
|
-
}
|
67
|
-
parser = (0, import_eventsource_parser.createParser)(onParse);
|
68
|
-
});
|
69
|
-
},
|
70
|
-
transform(chunk) {
|
71
|
-
parser.feed(decoder.decode(chunk));
|
72
|
-
}
|
73
|
-
});
|
74
|
-
}
|
75
|
-
function createCallbacksTransformer(callbacks) {
|
76
|
-
const encoder = new TextEncoder();
|
77
|
-
let fullResponse = "";
|
78
|
-
const { onStart, onToken, onCompletion } = callbacks || {};
|
79
|
-
return new TransformStream({
|
80
|
-
start() {
|
81
|
-
return __async(this, null, function* () {
|
82
|
-
if (onStart)
|
83
|
-
yield onStart();
|
84
|
-
});
|
85
|
-
},
|
86
|
-
transform(message, controller) {
|
87
|
-
return __async(this, null, function* () {
|
88
|
-
controller.enqueue(encoder.encode(message));
|
89
|
-
if (onToken)
|
90
|
-
yield onToken(message);
|
91
|
-
if (onCompletion)
|
92
|
-
fullResponse += message;
|
93
|
-
});
|
94
|
-
},
|
95
|
-
flush() {
|
96
|
-
return __async(this, null, function* () {
|
97
|
-
yield onCompletion == null ? void 0 : onCompletion(fullResponse);
|
98
|
-
});
|
99
|
-
}
|
100
|
-
});
|
101
|
-
}
|
102
|
-
function AIStream(res, customParser, callbacks) {
|
103
|
-
if (!res.ok) {
|
104
|
-
throw new Error(
|
105
|
-
`Failed to convert the response to stream. Received status code: ${res.status}.`
|
106
|
-
);
|
107
|
-
}
|
108
|
-
const stream = res.body || new ReadableStream({
|
109
|
-
start(controller) {
|
110
|
-
controller.close();
|
111
|
-
}
|
112
|
-
});
|
113
|
-
return stream.pipeThrough(createEventStreamTransformer(customParser)).pipeThrough(createCallbacksTransformer(callbacks));
|
114
|
-
}
|
115
|
-
|
116
|
-
// streams/anthropic-stream.ts
|
117
|
-
function parseAnthropicStream() {
|
118
|
-
let previous = "";
|
119
|
-
return (data) => {
|
120
|
-
const json = JSON.parse(data);
|
121
|
-
const text = json.completion;
|
122
|
-
const delta = text.slice(previous.length);
|
123
|
-
previous = text;
|
124
|
-
return delta;
|
125
|
-
};
|
126
|
-
}
|
127
|
-
function AnthropicStream(res, cb) {
|
128
|
-
return AIStream(res, parseAnthropicStream(), cb);
|
129
|
-
}
|
130
|
-
// Annotate the CommonJS export names for ESM import in node:
|
131
|
-
0 && (module.exports = {
|
132
|
-
AnthropicStream
|
133
|
-
});
|
package/dist/chunk-2JQWCLY2.mjs
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __defProps = Object.defineProperties;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
10
|
-
var __spreadValues = (a, b) => {
|
11
|
-
for (var prop in b || (b = {}))
|
12
|
-
if (__hasOwnProp.call(b, prop))
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
14
|
-
if (__getOwnPropSymbols)
|
15
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
16
|
-
if (__propIsEnum.call(b, prop))
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
18
|
-
}
|
19
|
-
return a;
|
20
|
-
};
|
21
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
22
|
-
var __esm = (fn, res) => function __init() {
|
23
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
24
|
-
};
|
25
|
-
var __commonJS = (cb, mod) => function __require() {
|
26
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
27
|
-
};
|
28
|
-
var __export = (target, all) => {
|
29
|
-
for (var name in all)
|
30
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
31
|
-
};
|
32
|
-
var __copyProps = (to, from, except, desc) => {
|
33
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
34
|
-
for (let key of __getOwnPropNames(from))
|
35
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
36
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
37
|
-
}
|
38
|
-
return to;
|
39
|
-
};
|
40
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
41
|
-
var __async = (__this, __arguments, generator) => {
|
42
|
-
return new Promise((resolve, reject) => {
|
43
|
-
var fulfilled = (value) => {
|
44
|
-
try {
|
45
|
-
step(generator.next(value));
|
46
|
-
} catch (e) {
|
47
|
-
reject(e);
|
48
|
-
}
|
49
|
-
};
|
50
|
-
var rejected = (value) => {
|
51
|
-
try {
|
52
|
-
step(generator.throw(value));
|
53
|
-
} catch (e) {
|
54
|
-
reject(e);
|
55
|
-
}
|
56
|
-
};
|
57
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
58
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
59
|
-
});
|
60
|
-
};
|
61
|
-
|
62
|
-
export {
|
63
|
-
__spreadValues,
|
64
|
-
__spreadProps,
|
65
|
-
__esm,
|
66
|
-
__commonJS,
|
67
|
-
__export,
|
68
|
-
__toCommonJS,
|
69
|
-
__async
|
70
|
-
};
|
package/dist/chunk-7KLTYB74.mjs
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
AnthropicStream,
|
3
|
-
init_anthropic_stream
|
4
|
-
} from "./chunk-TWW2ODJW.mjs";
|
5
|
-
import {
|
6
|
-
HuggingFaceStream,
|
7
|
-
init_huggingface_stream
|
8
|
-
} from "./chunk-KKQRUR3E.mjs";
|
9
|
-
import {
|
10
|
-
LangChainStream,
|
11
|
-
init_langchain_stream
|
12
|
-
} from "./chunk-U2OQ6HW6.mjs";
|
13
|
-
import {
|
14
|
-
OpenAIStream,
|
15
|
-
init_openai_stream
|
16
|
-
} from "./chunk-BJMBMGA3.mjs";
|
17
|
-
import {
|
18
|
-
AIStream,
|
19
|
-
createCallbacksTransformer,
|
20
|
-
createEventStreamTransformer,
|
21
|
-
init_ai_stream,
|
22
|
-
trimStartOfStreamHelper
|
23
|
-
} from "./chunk-UJV6VDVU.mjs";
|
24
|
-
import {
|
25
|
-
StreamingTextResponse,
|
26
|
-
init_streaming_text_response,
|
27
|
-
streamToResponse
|
28
|
-
} from "./chunk-RBP6ONSV.mjs";
|
29
|
-
import {
|
30
|
-
__esm,
|
31
|
-
__export
|
32
|
-
} from "./chunk-2JQWCLY2.mjs";
|
33
|
-
|
34
|
-
// shared/types.ts
|
35
|
-
var init_types = __esm({
|
36
|
-
"shared/types.ts"() {
|
37
|
-
"use strict";
|
38
|
-
}
|
39
|
-
});
|
40
|
-
|
41
|
-
// streams/index.ts
|
42
|
-
var streams_exports = {};
|
43
|
-
__export(streams_exports, {
|
44
|
-
AIStream: () => AIStream,
|
45
|
-
AnthropicStream: () => AnthropicStream,
|
46
|
-
HuggingFaceStream: () => HuggingFaceStream,
|
47
|
-
LangChainStream: () => LangChainStream,
|
48
|
-
OpenAIStream: () => OpenAIStream,
|
49
|
-
StreamingTextResponse: () => StreamingTextResponse,
|
50
|
-
createCallbacksTransformer: () => createCallbacksTransformer,
|
51
|
-
createEventStreamTransformer: () => createEventStreamTransformer,
|
52
|
-
streamToResponse: () => streamToResponse,
|
53
|
-
trimStartOfStreamHelper: () => trimStartOfStreamHelper
|
54
|
-
});
|
55
|
-
var init_streams = __esm({
|
56
|
-
"streams/index.ts"() {
|
57
|
-
init_ai_stream();
|
58
|
-
init_openai_stream();
|
59
|
-
init_streaming_text_response();
|
60
|
-
init_huggingface_stream();
|
61
|
-
init_anthropic_stream();
|
62
|
-
init_langchain_stream();
|
63
|
-
init_types();
|
64
|
-
}
|
65
|
-
});
|
66
|
-
|
67
|
-
export {
|
68
|
-
streams_exports,
|
69
|
-
init_streams
|
70
|
-
};
|
package/dist/chunk-BJMBMGA3.mjs
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
AIStream,
|
3
|
-
init_ai_stream,
|
4
|
-
trimStartOfStreamHelper
|
5
|
-
} from "./chunk-UJV6VDVU.mjs";
|
6
|
-
import {
|
7
|
-
__esm
|
8
|
-
} from "./chunk-2JQWCLY2.mjs";
|
9
|
-
|
10
|
-
// streams/openai-stream.ts
|
11
|
-
function parseOpenAIStream() {
|
12
|
-
const trimStartOfStream = trimStartOfStreamHelper();
|
13
|
-
return (data) => {
|
14
|
-
var _a, _b, _c, _d, _e;
|
15
|
-
const json = JSON.parse(data);
|
16
|
-
const text = trimStartOfStream(
|
17
|
-
(_e = (_d = (_b = (_a = json.choices[0]) == null ? void 0 : _a.delta) == null ? void 0 : _b.content) != null ? _d : (_c = json.choices[0]) == null ? void 0 : _c.text) != null ? _e : ""
|
18
|
-
);
|
19
|
-
return text;
|
20
|
-
};
|
21
|
-
}
|
22
|
-
function OpenAIStream(res, cb) {
|
23
|
-
return AIStream(res, parseOpenAIStream(), cb);
|
24
|
-
}
|
25
|
-
var init_openai_stream = __esm({
|
26
|
-
"streams/openai-stream.ts"() {
|
27
|
-
init_ai_stream();
|
28
|
-
}
|
29
|
-
});
|
30
|
-
|
31
|
-
export {
|
32
|
-
OpenAIStream,
|
33
|
-
init_openai_stream
|
34
|
-
};
|
package/dist/chunk-KKQRUR3E.mjs
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
createCallbacksTransformer,
|
3
|
-
init_ai_stream,
|
4
|
-
trimStartOfStreamHelper
|
5
|
-
} from "./chunk-UJV6VDVU.mjs";
|
6
|
-
import {
|
7
|
-
__async,
|
8
|
-
__esm
|
9
|
-
} from "./chunk-2JQWCLY2.mjs";
|
10
|
-
|
11
|
-
// streams/huggingface-stream.ts
|
12
|
-
function createParser(res) {
|
13
|
-
const trimStartOfStream = trimStartOfStreamHelper();
|
14
|
-
return new ReadableStream({
|
15
|
-
pull(controller) {
|
16
|
-
return __async(this, null, function* () {
|
17
|
-
var _a2, _b;
|
18
|
-
const { value, done } = yield res.next();
|
19
|
-
if (done) {
|
20
|
-
controller.close();
|
21
|
-
return;
|
22
|
-
}
|
23
|
-
const text = trimStartOfStream((_b = (_a2 = value.token) == null ? void 0 : _a2.text) != null ? _b : "");
|
24
|
-
if (!text)
|
25
|
-
return;
|
26
|
-
if (value.generated_text != null && value.generated_text.length > 0) {
|
27
|
-
controller.close();
|
28
|
-
return;
|
29
|
-
}
|
30
|
-
if (text === "</s>" || text === "<|endoftext|>") {
|
31
|
-
controller.close();
|
32
|
-
} else {
|
33
|
-
controller.enqueue(text);
|
34
|
-
}
|
35
|
-
});
|
36
|
-
}
|
37
|
-
});
|
38
|
-
}
|
39
|
-
function HuggingFaceStream(res, callbacks) {
|
40
|
-
return createParser(res).pipeThrough(createCallbacksTransformer(callbacks));
|
41
|
-
}
|
42
|
-
var init_huggingface_stream = __esm({
|
43
|
-
"streams/huggingface-stream.ts"() {
|
44
|
-
init_ai_stream();
|
45
|
-
}
|
46
|
-
});
|
47
|
-
|
48
|
-
export {
|
49
|
-
HuggingFaceStream,
|
50
|
-
init_huggingface_stream
|
51
|
-
};
|
package/dist/chunk-RBP6ONSV.mjs
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
__esm,
|
3
|
-
__spreadProps,
|
4
|
-
__spreadValues
|
5
|
-
} from "./chunk-2JQWCLY2.mjs";
|
6
|
-
|
7
|
-
// streams/streaming-text-response.ts
|
8
|
-
function streamToResponse(res, response, init) {
|
9
|
-
response.writeHead((init == null ? void 0 : init.status) || 200, __spreadValues({
|
10
|
-
"Content-Type": "text/plain; charset=utf-8"
|
11
|
-
}, init == null ? void 0 : init.headers));
|
12
|
-
const reader = res.getReader();
|
13
|
-
function read() {
|
14
|
-
reader.read().then(({ done, value }) => {
|
15
|
-
if (done) {
|
16
|
-
response.end();
|
17
|
-
return;
|
18
|
-
}
|
19
|
-
response.write(value);
|
20
|
-
read();
|
21
|
-
});
|
22
|
-
}
|
23
|
-
read();
|
24
|
-
}
|
25
|
-
var StreamingTextResponse;
|
26
|
-
var init_streaming_text_response = __esm({
|
27
|
-
"streams/streaming-text-response.ts"() {
|
28
|
-
StreamingTextResponse = class extends Response {
|
29
|
-
constructor(res, init) {
|
30
|
-
super(res, __spreadProps(__spreadValues({}, init), {
|
31
|
-
status: 200,
|
32
|
-
headers: __spreadValues({
|
33
|
-
"Content-Type": "text/plain; charset=utf-8"
|
34
|
-
}, init == null ? void 0 : init.headers)
|
35
|
-
}));
|
36
|
-
}
|
37
|
-
};
|
38
|
-
}
|
39
|
-
});
|
40
|
-
|
41
|
-
export {
|
42
|
-
StreamingTextResponse,
|
43
|
-
streamToResponse,
|
44
|
-
init_streaming_text_response
|
45
|
-
};
|
package/dist/chunk-TWW2ODJW.mjs
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
AIStream,
|
3
|
-
init_ai_stream
|
4
|
-
} from "./chunk-UJV6VDVU.mjs";
|
5
|
-
import {
|
6
|
-
__esm
|
7
|
-
} from "./chunk-2JQWCLY2.mjs";
|
8
|
-
|
9
|
-
// streams/anthropic-stream.ts
|
10
|
-
function parseAnthropicStream() {
|
11
|
-
let previous = "";
|
12
|
-
return (data) => {
|
13
|
-
const json = JSON.parse(data);
|
14
|
-
const text = json.completion;
|
15
|
-
const delta = text.slice(previous.length);
|
16
|
-
previous = text;
|
17
|
-
return delta;
|
18
|
-
};
|
19
|
-
}
|
20
|
-
function AnthropicStream(res, cb) {
|
21
|
-
return AIStream(res, parseAnthropicStream(), cb);
|
22
|
-
}
|
23
|
-
var init_anthropic_stream = __esm({
|
24
|
-
"streams/anthropic-stream.ts"() {
|
25
|
-
init_ai_stream();
|
26
|
-
}
|
27
|
-
});
|
28
|
-
|
29
|
-
export {
|
30
|
-
AnthropicStream,
|
31
|
-
init_anthropic_stream
|
32
|
-
};
|
package/dist/chunk-U2OQ6HW6.mjs
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
createCallbacksTransformer,
|
3
|
-
init_ai_stream
|
4
|
-
} from "./chunk-UJV6VDVU.mjs";
|
5
|
-
import {
|
6
|
-
__async,
|
7
|
-
__esm
|
8
|
-
} from "./chunk-2JQWCLY2.mjs";
|
9
|
-
|
10
|
-
// streams/langchain-stream.ts
|
11
|
-
function LangChainStream(callbacks) {
|
12
|
-
const stream = new TransformStream();
|
13
|
-
const writer = stream.writable.getWriter();
|
14
|
-
return {
|
15
|
-
stream: stream.readable.pipeThrough(createCallbacksTransformer(callbacks)),
|
16
|
-
handlers: {
|
17
|
-
handleLLMNewToken: (token) => __async(this, null, function* () {
|
18
|
-
yield writer.ready;
|
19
|
-
yield writer.write(token);
|
20
|
-
}),
|
21
|
-
handleChainEnd: () => __async(this, null, function* () {
|
22
|
-
yield writer.ready;
|
23
|
-
yield writer.close();
|
24
|
-
}),
|
25
|
-
handleLLMError: (e) => __async(this, null, function* () {
|
26
|
-
yield writer.ready;
|
27
|
-
yield writer.abort(e);
|
28
|
-
})
|
29
|
-
}
|
30
|
-
};
|
31
|
-
}
|
32
|
-
var init_langchain_stream = __esm({
|
33
|
-
"streams/langchain-stream.ts"() {
|
34
|
-
init_ai_stream();
|
35
|
-
}
|
36
|
-
});
|
37
|
-
|
38
|
-
export {
|
39
|
-
LangChainStream,
|
40
|
-
init_langchain_stream
|
41
|
-
};
|
package/dist/chunk-UJV6VDVU.mjs
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
__async,
|
3
|
-
__esm
|
4
|
-
} from "./chunk-2JQWCLY2.mjs";
|
5
|
-
|
6
|
-
// streams/ai-stream.ts
|
7
|
-
import {
|
8
|
-
createParser
|
9
|
-
} from "eventsource-parser";
|
10
|
-
function createEventStreamTransformer(customParser) {
|
11
|
-
const decoder = new TextDecoder();
|
12
|
-
let parser;
|
13
|
-
return new TransformStream({
|
14
|
-
start(controller) {
|
15
|
-
return __async(this, null, function* () {
|
16
|
-
function onParse(event) {
|
17
|
-
if (event.type === "event") {
|
18
|
-
const data = event.data;
|
19
|
-
if (data === "[DONE]") {
|
20
|
-
controller.terminate();
|
21
|
-
return;
|
22
|
-
}
|
23
|
-
const message = customParser(data);
|
24
|
-
if (message)
|
25
|
-
controller.enqueue(message);
|
26
|
-
}
|
27
|
-
}
|
28
|
-
parser = createParser(onParse);
|
29
|
-
});
|
30
|
-
},
|
31
|
-
transform(chunk) {
|
32
|
-
parser.feed(decoder.decode(chunk));
|
33
|
-
}
|
34
|
-
});
|
35
|
-
}
|
36
|
-
function createCallbacksTransformer(callbacks) {
|
37
|
-
const encoder = new TextEncoder();
|
38
|
-
let fullResponse = "";
|
39
|
-
const { onStart, onToken, onCompletion } = callbacks || {};
|
40
|
-
return new TransformStream({
|
41
|
-
start() {
|
42
|
-
return __async(this, null, function* () {
|
43
|
-
if (onStart)
|
44
|
-
yield onStart();
|
45
|
-
});
|
46
|
-
},
|
47
|
-
transform(message, controller) {
|
48
|
-
return __async(this, null, function* () {
|
49
|
-
controller.enqueue(encoder.encode(message));
|
50
|
-
if (onToken)
|
51
|
-
yield onToken(message);
|
52
|
-
if (onCompletion)
|
53
|
-
fullResponse += message;
|
54
|
-
});
|
55
|
-
},
|
56
|
-
flush() {
|
57
|
-
return __async(this, null, function* () {
|
58
|
-
yield onCompletion == null ? void 0 : onCompletion(fullResponse);
|
59
|
-
});
|
60
|
-
}
|
61
|
-
});
|
62
|
-
}
|
63
|
-
function trimStartOfStreamHelper() {
|
64
|
-
let start = true;
|
65
|
-
return (text) => {
|
66
|
-
if (start)
|
67
|
-
text = text.trimStart();
|
68
|
-
if (text)
|
69
|
-
start = false;
|
70
|
-
return text;
|
71
|
-
};
|
72
|
-
}
|
73
|
-
function AIStream(res, customParser, callbacks) {
|
74
|
-
if (!res.ok) {
|
75
|
-
throw new Error(
|
76
|
-
`Failed to convert the response to stream. Received status code: ${res.status}.`
|
77
|
-
);
|
78
|
-
}
|
79
|
-
const stream = res.body || new ReadableStream({
|
80
|
-
start(controller) {
|
81
|
-
controller.close();
|
82
|
-
}
|
83
|
-
});
|
84
|
-
return stream.pipeThrough(createEventStreamTransformer(customParser)).pipeThrough(createCallbacksTransformer(callbacks));
|
85
|
-
}
|
86
|
-
var init_ai_stream = __esm({
|
87
|
-
"streams/ai-stream.ts"() {
|
88
|
-
}
|
89
|
-
});
|
90
|
-
|
91
|
-
export {
|
92
|
-
createEventStreamTransformer,
|
93
|
-
createCallbacksTransformer,
|
94
|
-
trimStartOfStreamHelper,
|
95
|
-
AIStream,
|
96
|
-
init_ai_stream
|
97
|
-
};
|