ai 2.1.26 → 2.1.27
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 +48 -3
- package/dist/index.js +236 -253
- package/dist/index.mjs +235 -256
- package/package.json +3 -3
- package/react/dist/index.js +177 -197
- package/react/dist/index.mjs +177 -199
- package/react/dist/index.server.js +14 -38
- package/react/dist/index.server.mjs +14 -39
- package/solid/dist/index.js +156 -184
- package/solid/dist/index.mjs +156 -187
- package/svelte/dist/index.d.ts +2 -2
- package/svelte/dist/index.js +232 -236
- package/svelte/dist/index.mjs +232 -239
- package/vue/dist/index.d.ts +2 -2
- package/vue/dist/index.js +153 -177
- package/vue/dist/index.mjs +153 -180
package/react/dist/index.mjs
CHANGED
@@ -1,44 +1,7 @@
|
|
1
1
|
'use client'
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
5
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
7
|
-
var __spreadValues = (a, b) => {
|
8
|
-
for (var prop in b || (b = {}))
|
9
|
-
if (__hasOwnProp.call(b, prop))
|
10
|
-
__defNormalProp(a, prop, b[prop]);
|
11
|
-
if (__getOwnPropSymbols)
|
12
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
13
|
-
if (__propIsEnum.call(b, prop))
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
15
|
-
}
|
16
|
-
return a;
|
17
|
-
};
|
18
|
-
var __async = (__this, __arguments, generator) => {
|
19
|
-
return new Promise((resolve, reject) => {
|
20
|
-
var fulfilled = (value) => {
|
21
|
-
try {
|
22
|
-
step(generator.next(value));
|
23
|
-
} catch (e) {
|
24
|
-
reject(e);
|
25
|
-
}
|
26
|
-
};
|
27
|
-
var rejected = (value) => {
|
28
|
-
try {
|
29
|
-
step(generator.throw(value));
|
30
|
-
} catch (e) {
|
31
|
-
reject(e);
|
32
|
-
}
|
33
|
-
};
|
34
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
35
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
36
|
-
});
|
37
|
-
};
|
38
2
|
|
39
3
|
// react/use-chat.ts
|
40
4
|
import { useCallback, useEffect, useId, useRef, useState } from "react";
|
41
|
-
import useSWRMutation from "swr/mutation";
|
42
5
|
import useSWR from "swr";
|
43
6
|
|
44
7
|
// shared/utils.ts
|
@@ -57,44 +20,54 @@ function createChunkDecoder() {
|
|
57
20
|
}
|
58
21
|
|
59
22
|
// react/use-chat.ts
|
60
|
-
var getStreamedResponse = (api, chatRequest, mutate, extraMetadataRef, messagesRef, abortControllerRef, onFinish, onResponse, sendExtraMessageFields) =>
|
23
|
+
var getStreamedResponse = async (api, chatRequest, mutate, extraMetadataRef, messagesRef, abortControllerRef, onFinish, onResponse, sendExtraMessageFields) => {
|
61
24
|
var _a, _b;
|
62
25
|
const previousMessages = messagesRef.current;
|
63
26
|
mutate(chatRequest.messages, false);
|
64
|
-
const res =
|
27
|
+
const res = await fetch(api, {
|
65
28
|
method: "POST",
|
66
|
-
body: JSON.stringify(
|
29
|
+
body: JSON.stringify({
|
67
30
|
messages: sendExtraMessageFields ? chatRequest.messages : chatRequest.messages.map(
|
68
|
-
({ role, content, name, function_call }) =>
|
31
|
+
({ role, content, name, function_call }) => ({
|
69
32
|
role,
|
70
|
-
content
|
71
|
-
|
72
|
-
function_call
|
33
|
+
content,
|
34
|
+
...name !== void 0 && { name },
|
35
|
+
...function_call !== void 0 && {
|
36
|
+
function_call
|
37
|
+
}
|
73
38
|
})
|
74
|
-
)
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
39
|
+
),
|
40
|
+
...extraMetadataRef.current.body,
|
41
|
+
...(_a = chatRequest.options) == null ? void 0 : _a.body,
|
42
|
+
...chatRequest.functions !== void 0 && {
|
43
|
+
functions: chatRequest.functions
|
44
|
+
},
|
45
|
+
...chatRequest.function_call !== void 0 && {
|
46
|
+
function_call: chatRequest.function_call
|
47
|
+
}
|
48
|
+
}),
|
80
49
|
credentials: extraMetadataRef.current.credentials,
|
81
|
-
headers:
|
82
|
-
|
83
|
-
|
84
|
-
|
50
|
+
headers: {
|
51
|
+
...extraMetadataRef.current.headers,
|
52
|
+
...(_b = chatRequest.options) == null ? void 0 : _b.headers
|
53
|
+
},
|
54
|
+
...abortControllerRef.current !== null && {
|
55
|
+
signal: abortControllerRef.current.signal
|
56
|
+
}
|
57
|
+
}).catch((err) => {
|
85
58
|
mutate(previousMessages, false);
|
86
59
|
throw err;
|
87
60
|
});
|
88
61
|
if (onResponse) {
|
89
62
|
try {
|
90
|
-
|
63
|
+
await onResponse(res);
|
91
64
|
} catch (err) {
|
92
65
|
throw err;
|
93
66
|
}
|
94
67
|
}
|
95
68
|
if (!res.ok) {
|
96
69
|
mutate(previousMessages, false);
|
97
|
-
throw new Error(
|
70
|
+
throw new Error(await res.text() || "Failed to fetch the chat response.");
|
98
71
|
}
|
99
72
|
if (!res.body) {
|
100
73
|
throw new Error("The response body is empty.");
|
@@ -111,7 +84,7 @@ var getStreamedResponse = (api, chatRequest, mutate, extraMetadataRef, messagesR
|
|
111
84
|
role: "assistant"
|
112
85
|
};
|
113
86
|
while (true) {
|
114
|
-
const { done, value } =
|
87
|
+
const { done, value } = await reader.read();
|
115
88
|
if (done) {
|
116
89
|
break;
|
117
90
|
}
|
@@ -121,7 +94,7 @@ var getStreamedResponse = (api, chatRequest, mutate, extraMetadataRef, messagesR
|
|
121
94
|
} else {
|
122
95
|
responseMessage["content"] = streamedResponse;
|
123
96
|
}
|
124
|
-
mutate([...chatRequest.messages,
|
97
|
+
mutate([...chatRequest.messages, { ...responseMessage }], false);
|
125
98
|
if (abortControllerRef.current === null) {
|
126
99
|
reader.cancel();
|
127
100
|
break;
|
@@ -130,13 +103,13 @@ var getStreamedResponse = (api, chatRequest, mutate, extraMetadataRef, messagesR
|
|
130
103
|
if (streamedResponse.startsWith('{"function_call":')) {
|
131
104
|
const parsedFunctionCall = JSON.parse(streamedResponse).function_call;
|
132
105
|
responseMessage["function_call"] = parsedFunctionCall;
|
133
|
-
mutate([...chatRequest.messages,
|
106
|
+
mutate([...chatRequest.messages, { ...responseMessage }]);
|
134
107
|
}
|
135
108
|
if (onFinish) {
|
136
109
|
onFinish(responseMessage);
|
137
110
|
}
|
138
111
|
return responseMessage;
|
139
|
-
}
|
112
|
+
};
|
140
113
|
function useChat({
|
141
114
|
api = "/api/chat",
|
142
115
|
id,
|
@@ -156,6 +129,10 @@ function useChat({
|
|
156
129
|
const { data, mutate } = useSWR([api, chatId], null, {
|
157
130
|
fallbackData: initialMessages
|
158
131
|
});
|
132
|
+
const { data: isLoading = false, mutate: mutateLoading } = useSWR(
|
133
|
+
[api, chatId, "loading"],
|
134
|
+
null
|
135
|
+
);
|
159
136
|
const messages = data;
|
160
137
|
const messagesRef = useRef(messages);
|
161
138
|
useEffect(() => {
|
@@ -174,91 +151,88 @@ function useChat({
|
|
174
151
|
body
|
175
152
|
};
|
176
153
|
}, [credentials, headers, body]);
|
177
|
-
const
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
154
|
+
const [error, setError] = useState();
|
155
|
+
async function triggerRequest(chatRequest) {
|
156
|
+
try {
|
157
|
+
mutateLoading(true);
|
158
|
+
const abortController = new AbortController();
|
159
|
+
abortControllerRef.current = abortController;
|
160
|
+
while (true) {
|
161
|
+
const streamedResponseMessage = await getStreamedResponse(
|
162
|
+
api,
|
163
|
+
chatRequest,
|
164
|
+
mutate,
|
165
|
+
extraMetadataRef,
|
166
|
+
messagesRef,
|
167
|
+
abortControllerRef,
|
168
|
+
onFinish,
|
169
|
+
onResponse,
|
170
|
+
sendExtraMessageFields
|
171
|
+
);
|
172
|
+
if (streamedResponseMessage.function_call === void 0 || typeof streamedResponseMessage.function_call === "string") {
|
173
|
+
break;
|
174
|
+
}
|
175
|
+
if (experimental_onFunctionCall) {
|
176
|
+
const functionCall = streamedResponseMessage.function_call;
|
177
|
+
const functionCallResponse = await experimental_onFunctionCall(messagesRef.current, functionCall);
|
178
|
+
if (functionCallResponse === void 0)
|
197
179
|
break;
|
198
|
-
|
199
|
-
if (experimental_onFunctionCall) {
|
200
|
-
const functionCall = streamedResponseMessage.function_call;
|
201
|
-
const functionCallResponse = yield experimental_onFunctionCall(
|
202
|
-
messagesRef.current,
|
203
|
-
functionCall
|
204
|
-
);
|
205
|
-
if (functionCallResponse === void 0)
|
206
|
-
break;
|
207
|
-
chatRequest = functionCallResponse;
|
208
|
-
}
|
180
|
+
chatRequest = functionCallResponse;
|
209
181
|
}
|
182
|
+
}
|
183
|
+
abortControllerRef.current = null;
|
184
|
+
return null;
|
185
|
+
} catch (err) {
|
186
|
+
if (err.name === "AbortError") {
|
210
187
|
abortControllerRef.current = null;
|
211
188
|
return null;
|
212
|
-
} catch (err) {
|
213
|
-
if (err.name === "AbortError") {
|
214
|
-
abortControllerRef.current = null;
|
215
|
-
return null;
|
216
|
-
}
|
217
|
-
if (onError && err instanceof Error) {
|
218
|
-
onError(err);
|
219
|
-
}
|
220
|
-
throw err;
|
221
189
|
}
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
190
|
+
if (onError && err instanceof Error) {
|
191
|
+
onError(err);
|
192
|
+
}
|
193
|
+
setError(err);
|
194
|
+
} finally {
|
195
|
+
mutateLoading(false);
|
228
196
|
}
|
229
|
-
|
197
|
+
}
|
230
198
|
const append = useCallback(
|
231
|
-
|
199
|
+
async (message, { options, functions, function_call } = {}) => {
|
232
200
|
if (!message.id) {
|
233
201
|
message.id = nanoid();
|
234
202
|
}
|
235
|
-
const chatRequest =
|
203
|
+
const chatRequest = {
|
236
204
|
messages: messagesRef.current.concat(message),
|
237
|
-
options
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
205
|
+
options,
|
206
|
+
...functions !== void 0 && { functions },
|
207
|
+
...function_call !== void 0 && { function_call }
|
208
|
+
};
|
209
|
+
return triggerRequest(chatRequest);
|
210
|
+
},
|
211
|
+
[triggerRequest]
|
242
212
|
);
|
243
213
|
const reload = useCallback(
|
244
|
-
|
214
|
+
async ({ options, functions, function_call } = {}) => {
|
245
215
|
if (messagesRef.current.length === 0)
|
246
216
|
return null;
|
247
217
|
const lastMessage = messagesRef.current[messagesRef.current.length - 1];
|
248
218
|
if (lastMessage.role === "assistant") {
|
249
|
-
const chatRequest2 =
|
219
|
+
const chatRequest2 = {
|
250
220
|
messages: messagesRef.current.slice(0, -1),
|
251
|
-
options
|
252
|
-
|
253
|
-
|
221
|
+
options,
|
222
|
+
...functions !== void 0 && { functions },
|
223
|
+
...function_call !== void 0 && { function_call }
|
224
|
+
};
|
225
|
+
return triggerRequest(chatRequest2);
|
254
226
|
}
|
255
|
-
const chatRequest =
|
227
|
+
const chatRequest = {
|
256
228
|
messages: messagesRef.current,
|
257
|
-
options
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
229
|
+
options,
|
230
|
+
...functions !== void 0 && { functions },
|
231
|
+
...function_call !== void 0 && { function_call }
|
232
|
+
};
|
233
|
+
return triggerRequest(chatRequest);
|
234
|
+
},
|
235
|
+
[triggerRequest]
|
262
236
|
);
|
263
237
|
const stop = useCallback(() => {
|
264
238
|
if (abortControllerRef.current) {
|
@@ -277,7 +251,10 @@ function useChat({
|
|
277
251
|
const handleSubmit = useCallback(
|
278
252
|
(e, { options, functions, function_call } = {}, metadata) => {
|
279
253
|
if (metadata) {
|
280
|
-
extraMetadataRef.current =
|
254
|
+
extraMetadataRef.current = {
|
255
|
+
...extraMetadataRef.current,
|
256
|
+
...metadata
|
257
|
+
};
|
281
258
|
}
|
282
259
|
e.preventDefault();
|
283
260
|
if (!input)
|
@@ -308,13 +285,12 @@ function useChat({
|
|
308
285
|
setInput,
|
309
286
|
handleInputChange,
|
310
287
|
handleSubmit,
|
311
|
-
isLoading
|
288
|
+
isLoading
|
312
289
|
};
|
313
290
|
}
|
314
291
|
|
315
292
|
// react/use-completion.ts
|
316
293
|
import { useCallback as useCallback2, useEffect as useEffect2, useId as useId2, useRef as useRef2, useState as useState2 } from "react";
|
317
|
-
import useSWRMutation2 from "swr/mutation";
|
318
294
|
import useSWR2 from "swr";
|
319
295
|
function useCompletion({
|
320
296
|
api = "/api/completion",
|
@@ -333,6 +309,11 @@ function useCompletion({
|
|
333
309
|
const { data, mutate } = useSWR2([api, completionId], null, {
|
334
310
|
fallbackData: initialCompletion
|
335
311
|
});
|
312
|
+
const { data: isLoading = false, mutate: mutateLoading } = useSWR2(
|
313
|
+
[api, completionId, "loading"],
|
314
|
+
null
|
315
|
+
);
|
316
|
+
const [error, setError] = useState2(void 0);
|
336
317
|
const completion = data;
|
337
318
|
const [abortController, setAbortController] = useState2(null);
|
338
319
|
const extraMetadataRef = useRef2({
|
@@ -347,78 +328,78 @@ function useCompletion({
|
|
347
328
|
body
|
348
329
|
};
|
349
330
|
}, [credentials, headers, body]);
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
body
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
331
|
+
async function triggerRequest(prompt, options) {
|
332
|
+
try {
|
333
|
+
mutateLoading(true);
|
334
|
+
const abortController2 = new AbortController();
|
335
|
+
setAbortController(abortController2);
|
336
|
+
mutate("", false);
|
337
|
+
const res = await fetch(api, {
|
338
|
+
method: "POST",
|
339
|
+
body: JSON.stringify({
|
340
|
+
prompt,
|
341
|
+
...extraMetadataRef.current.body,
|
342
|
+
...options == null ? void 0 : options.body
|
343
|
+
}),
|
344
|
+
credentials: extraMetadataRef.current.credentials,
|
345
|
+
headers: {
|
346
|
+
...extraMetadataRef.current.headers,
|
347
|
+
...options == null ? void 0 : options.headers
|
348
|
+
},
|
349
|
+
signal: abortController2.signal
|
350
|
+
}).catch((err) => {
|
351
|
+
throw err;
|
352
|
+
});
|
353
|
+
if (onResponse) {
|
354
|
+
try {
|
355
|
+
await onResponse(res);
|
356
|
+
} catch (err) {
|
367
357
|
throw err;
|
368
|
-
});
|
369
|
-
if (onResponse) {
|
370
|
-
try {
|
371
|
-
yield onResponse(res);
|
372
|
-
} catch (err) {
|
373
|
-
throw err;
|
374
|
-
}
|
375
358
|
}
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
)
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
result += decoder(value);
|
393
|
-
mutate(result, false);
|
394
|
-
if (abortController2 === null) {
|
395
|
-
reader.cancel();
|
396
|
-
break;
|
397
|
-
}
|
359
|
+
}
|
360
|
+
if (!res.ok) {
|
361
|
+
throw new Error(
|
362
|
+
await res.text() || "Failed to fetch the chat response."
|
363
|
+
);
|
364
|
+
}
|
365
|
+
if (!res.body) {
|
366
|
+
throw new Error("The response body is empty.");
|
367
|
+
}
|
368
|
+
let result = "";
|
369
|
+
const reader = res.body.getReader();
|
370
|
+
const decoder = createChunkDecoder();
|
371
|
+
while (true) {
|
372
|
+
const { done, value } = await reader.read();
|
373
|
+
if (done) {
|
374
|
+
break;
|
398
375
|
}
|
399
|
-
|
400
|
-
|
376
|
+
result += decoder(value);
|
377
|
+
mutate(result, false);
|
378
|
+
if (abortController2 === null) {
|
379
|
+
reader.cancel();
|
380
|
+
break;
|
401
381
|
}
|
382
|
+
}
|
383
|
+
if (onFinish) {
|
384
|
+
onFinish(prompt, result);
|
385
|
+
}
|
386
|
+
setAbortController(null);
|
387
|
+
return result;
|
388
|
+
} catch (err) {
|
389
|
+
if (err.name === "AbortError") {
|
402
390
|
setAbortController(null);
|
403
|
-
return
|
404
|
-
}
|
405
|
-
|
406
|
-
|
407
|
-
return null;
|
408
|
-
}
|
409
|
-
if (onError && err instanceof Error) {
|
391
|
+
return null;
|
392
|
+
}
|
393
|
+
if (err instanceof Error) {
|
394
|
+
if (onError) {
|
410
395
|
onError(err);
|
411
396
|
}
|
412
|
-
throw err;
|
413
397
|
}
|
414
|
-
|
415
|
-
{
|
416
|
-
|
417
|
-
revalidate: false,
|
418
|
-
// @ts-expect-error - SWR tries to be clever with the throwOnError type
|
419
|
-
throwOnError: Boolean(onError)
|
398
|
+
setError(err);
|
399
|
+
} finally {
|
400
|
+
mutateLoading(false);
|
420
401
|
}
|
421
|
-
|
402
|
+
}
|
422
403
|
const stop = useCallback2(() => {
|
423
404
|
if (abortController) {
|
424
405
|
abortController.abort();
|
@@ -432,13 +413,10 @@ function useCompletion({
|
|
432
413
|
[mutate]
|
433
414
|
);
|
434
415
|
const complete = useCallback2(
|
435
|
-
(prompt, options) =>
|
436
|
-
return
|
437
|
-
|
438
|
-
|
439
|
-
});
|
440
|
-
}),
|
441
|
-
[trigger]
|
416
|
+
async (prompt, options) => {
|
417
|
+
return triggerRequest(prompt, options);
|
418
|
+
},
|
419
|
+
[triggerRequest]
|
442
420
|
);
|
443
421
|
const [input, setInput] = useState2(initialInput);
|
444
422
|
const handleSubmit = useCallback2(
|
@@ -463,7 +441,7 @@ function useCompletion({
|
|
463
441
|
setInput,
|
464
442
|
handleInputChange,
|
465
443
|
handleSubmit,
|
466
|
-
isLoading
|
444
|
+
isLoading
|
467
445
|
};
|
468
446
|
}
|
469
447
|
export {
|
@@ -16,26 +16,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
16
16
|
return to;
|
17
17
|
};
|
18
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
19
|
|
40
20
|
// react/index.server.ts
|
41
21
|
var index_server_exports = {};
|
@@ -47,25 +27,21 @@ module.exports = __toCommonJS(index_server_exports);
|
|
47
27
|
// react/tokens.tsx
|
48
28
|
var import_react = require("react");
|
49
29
|
var import_jsx_runtime = require("react/jsx-runtime");
|
50
|
-
function Tokens(props) {
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RecursiveTokens, { reader }) });
|
55
|
-
});
|
30
|
+
async function Tokens(props) {
|
31
|
+
const { stream } = props;
|
32
|
+
const reader = stream.getReader();
|
33
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RecursiveTokens, { reader }) });
|
56
34
|
}
|
57
|
-
function RecursiveTokens(
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
] });
|
68
|
-
});
|
35
|
+
async function RecursiveTokens({ reader }) {
|
36
|
+
const { done, value } = await reader.read();
|
37
|
+
if (done) {
|
38
|
+
return null;
|
39
|
+
}
|
40
|
+
const text = new TextDecoder().decode(value);
|
41
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
42
|
+
text,
|
43
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RecursiveTokens, { reader }) })
|
44
|
+
] });
|
69
45
|
}
|
70
46
|
// Annotate the CommonJS export names for ESM import in node:
|
71
47
|
0 && (module.exports = {
|
@@ -1,46 +1,21 @@
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
2
|
-
return new Promise((resolve, reject) => {
|
3
|
-
var fulfilled = (value) => {
|
4
|
-
try {
|
5
|
-
step(generator.next(value));
|
6
|
-
} catch (e) {
|
7
|
-
reject(e);
|
8
|
-
}
|
9
|
-
};
|
10
|
-
var rejected = (value) => {
|
11
|
-
try {
|
12
|
-
step(generator.throw(value));
|
13
|
-
} catch (e) {
|
14
|
-
reject(e);
|
15
|
-
}
|
16
|
-
};
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
19
|
-
});
|
20
|
-
};
|
21
|
-
|
22
1
|
// react/tokens.tsx
|
23
2
|
import { Suspense } from "react";
|
24
3
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
25
|
-
function Tokens(props) {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
return /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(RecursiveTokens, { reader }) });
|
30
|
-
});
|
4
|
+
async function Tokens(props) {
|
5
|
+
const { stream } = props;
|
6
|
+
const reader = stream.getReader();
|
7
|
+
return /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(RecursiveTokens, { reader }) });
|
31
8
|
}
|
32
|
-
function RecursiveTokens(
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
] });
|
43
|
-
});
|
9
|
+
async function RecursiveTokens({ reader }) {
|
10
|
+
const { done, value } = await reader.read();
|
11
|
+
if (done) {
|
12
|
+
return null;
|
13
|
+
}
|
14
|
+
const text = new TextDecoder().decode(value);
|
15
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
16
|
+
text,
|
17
|
+
/* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(RecursiveTokens, { reader }) })
|
18
|
+
] });
|
44
19
|
}
|
45
20
|
export {
|
46
21
|
Tokens
|