ai 2.2.1 → 2.2.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.
@@ -9,14 +9,44 @@ var nanoid = customAlphabet(
9
9
  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
10
10
  7
11
11
  );
12
- function createChunkDecoder() {
12
+ function createChunkDecoder(complex) {
13
13
  const decoder = new TextDecoder();
14
+ if (!complex) {
15
+ return function(chunk) {
16
+ if (!chunk)
17
+ return "";
18
+ return decoder.decode(chunk, { stream: true });
19
+ };
20
+ }
14
21
  return function(chunk) {
15
- if (!chunk)
16
- return "";
17
- return decoder.decode(chunk, { stream: true });
22
+ const decoded = decoder.decode(chunk, { stream: true }).split("\n");
23
+ return decoded.map(getStreamStringTypeAndValue).filter(Boolean);
18
24
  };
19
25
  }
26
+ var StreamStringPrefixes = {
27
+ text: 0,
28
+ function_call: 1,
29
+ data: 2
30
+ // user_err: 3?
31
+ };
32
+ var getStreamStringTypeAndValue = (line) => {
33
+ const firstSeperatorIndex = line.indexOf(":");
34
+ const prefix = line.slice(0, firstSeperatorIndex);
35
+ const type = Object.keys(StreamStringPrefixes).find(
36
+ (key) => StreamStringPrefixes[key] === Number(prefix)
37
+ );
38
+ const val = line.slice(firstSeperatorIndex + 1);
39
+ let parsedVal = val;
40
+ if (!val) {
41
+ return { type, value: "" };
42
+ }
43
+ try {
44
+ parsedVal = JSON.parse(val);
45
+ } catch (e) {
46
+ console.error("Failed to parse JSON value:", val);
47
+ }
48
+ return { type, value: parsedVal };
49
+ };
20
50
 
21
51
  // solid/use-chat.ts
22
52
  var uniqueId = 0;
@@ -531,14 +531,44 @@ var nanoid = (0, import_non_secure.customAlphabet)(
531
531
  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
532
532
  7
533
533
  );
534
- function createChunkDecoder() {
534
+ function createChunkDecoder(complex) {
535
535
  const decoder = new TextDecoder();
536
+ if (!complex) {
537
+ return function(chunk) {
538
+ if (!chunk)
539
+ return "";
540
+ return decoder.decode(chunk, { stream: true });
541
+ };
542
+ }
536
543
  return function(chunk) {
537
- if (!chunk)
538
- return "";
539
- return decoder.decode(chunk, { stream: true });
544
+ const decoded = decoder.decode(chunk, { stream: true }).split("\n");
545
+ return decoded.map(getStreamStringTypeAndValue).filter(Boolean);
540
546
  };
541
547
  }
548
+ var StreamStringPrefixes = {
549
+ text: 0,
550
+ function_call: 1,
551
+ data: 2
552
+ // user_err: 3?
553
+ };
554
+ var getStreamStringTypeAndValue = (line) => {
555
+ const firstSeperatorIndex = line.indexOf(":");
556
+ const prefix = line.slice(0, firstSeperatorIndex);
557
+ const type = Object.keys(StreamStringPrefixes).find(
558
+ (key) => StreamStringPrefixes[key] === Number(prefix)
559
+ );
560
+ const val = line.slice(firstSeperatorIndex + 1);
561
+ let parsedVal = val;
562
+ if (!val) {
563
+ return { type, value: "" };
564
+ }
565
+ try {
566
+ parsedVal = JSON.parse(val);
567
+ } catch (e) {
568
+ console.error("Failed to parse JSON value:", val);
569
+ }
570
+ return { type, value: parsedVal };
571
+ };
542
572
 
543
573
  // svelte/use-chat.ts
544
574
  var getStreamedResponse = async (api, chatRequest, mutate, extraMetadata, previousMessages, abortControllerRef, onFinish, onResponse, sendExtraMessageFields) => {
@@ -504,14 +504,44 @@ var nanoid = customAlphabet(
504
504
  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
505
505
  7
506
506
  );
507
- function createChunkDecoder() {
507
+ function createChunkDecoder(complex) {
508
508
  const decoder = new TextDecoder();
509
+ if (!complex) {
510
+ return function(chunk) {
511
+ if (!chunk)
512
+ return "";
513
+ return decoder.decode(chunk, { stream: true });
514
+ };
515
+ }
509
516
  return function(chunk) {
510
- if (!chunk)
511
- return "";
512
- return decoder.decode(chunk, { stream: true });
517
+ const decoded = decoder.decode(chunk, { stream: true }).split("\n");
518
+ return decoded.map(getStreamStringTypeAndValue).filter(Boolean);
513
519
  };
514
520
  }
521
+ var StreamStringPrefixes = {
522
+ text: 0,
523
+ function_call: 1,
524
+ data: 2
525
+ // user_err: 3?
526
+ };
527
+ var getStreamStringTypeAndValue = (line) => {
528
+ const firstSeperatorIndex = line.indexOf(":");
529
+ const prefix = line.slice(0, firstSeperatorIndex);
530
+ const type = Object.keys(StreamStringPrefixes).find(
531
+ (key) => StreamStringPrefixes[key] === Number(prefix)
532
+ );
533
+ const val = line.slice(firstSeperatorIndex + 1);
534
+ let parsedVal = val;
535
+ if (!val) {
536
+ return { type, value: "" };
537
+ }
538
+ try {
539
+ parsedVal = JSON.parse(val);
540
+ } catch (e) {
541
+ console.error("Failed to parse JSON value:", val);
542
+ }
543
+ return { type, value: parsedVal };
544
+ };
515
545
 
516
546
  // svelte/use-chat.ts
517
547
  var getStreamedResponse = async (api, chatRequest, mutate, extraMetadata, previousMessages, abortControllerRef, onFinish, onResponse, sendExtraMessageFields) => {
package/vue/dist/index.js CHANGED
@@ -45,14 +45,44 @@ var nanoid = (0, import_non_secure.customAlphabet)(
45
45
  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
46
46
  7
47
47
  );
48
- function createChunkDecoder() {
48
+ function createChunkDecoder(complex) {
49
49
  const decoder = new TextDecoder();
50
+ if (!complex) {
51
+ return function(chunk) {
52
+ if (!chunk)
53
+ return "";
54
+ return decoder.decode(chunk, { stream: true });
55
+ };
56
+ }
50
57
  return function(chunk) {
51
- if (!chunk)
52
- return "";
53
- return decoder.decode(chunk, { stream: true });
58
+ const decoded = decoder.decode(chunk, { stream: true }).split("\n");
59
+ return decoded.map(getStreamStringTypeAndValue).filter(Boolean);
54
60
  };
55
61
  }
62
+ var StreamStringPrefixes = {
63
+ text: 0,
64
+ function_call: 1,
65
+ data: 2
66
+ // user_err: 3?
67
+ };
68
+ var getStreamStringTypeAndValue = (line) => {
69
+ const firstSeperatorIndex = line.indexOf(":");
70
+ const prefix = line.slice(0, firstSeperatorIndex);
71
+ const type = Object.keys(StreamStringPrefixes).find(
72
+ (key) => StreamStringPrefixes[key] === Number(prefix)
73
+ );
74
+ const val = line.slice(firstSeperatorIndex + 1);
75
+ let parsedVal = val;
76
+ if (!val) {
77
+ return { type, value: "" };
78
+ }
79
+ try {
80
+ parsedVal = JSON.parse(val);
81
+ } catch (e) {
82
+ console.error("Failed to parse JSON value:", val);
83
+ }
84
+ return { type, value: parsedVal };
85
+ };
56
86
 
57
87
  // vue/use-chat.ts
58
88
  var uniqueId = 0;
@@ -8,14 +8,44 @@ var nanoid = customAlphabet(
8
8
  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
9
9
  7
10
10
  );
11
- function createChunkDecoder() {
11
+ function createChunkDecoder(complex) {
12
12
  const decoder = new TextDecoder();
13
+ if (!complex) {
14
+ return function(chunk) {
15
+ if (!chunk)
16
+ return "";
17
+ return decoder.decode(chunk, { stream: true });
18
+ };
19
+ }
13
20
  return function(chunk) {
14
- if (!chunk)
15
- return "";
16
- return decoder.decode(chunk, { stream: true });
21
+ const decoded = decoder.decode(chunk, { stream: true }).split("\n");
22
+ return decoded.map(getStreamStringTypeAndValue).filter(Boolean);
17
23
  };
18
24
  }
25
+ var StreamStringPrefixes = {
26
+ text: 0,
27
+ function_call: 1,
28
+ data: 2
29
+ // user_err: 3?
30
+ };
31
+ var getStreamStringTypeAndValue = (line) => {
32
+ const firstSeperatorIndex = line.indexOf(":");
33
+ const prefix = line.slice(0, firstSeperatorIndex);
34
+ const type = Object.keys(StreamStringPrefixes).find(
35
+ (key) => StreamStringPrefixes[key] === Number(prefix)
36
+ );
37
+ const val = line.slice(firstSeperatorIndex + 1);
38
+ let parsedVal = val;
39
+ if (!val) {
40
+ return { type, value: "" };
41
+ }
42
+ try {
43
+ parsedVal = JSON.parse(val);
44
+ } catch (e) {
45
+ console.error("Failed to parse JSON value:", val);
46
+ }
47
+ return { type, value: parsedVal };
48
+ };
19
49
 
20
50
  // vue/use-chat.ts
21
51
  var uniqueId = 0;