@copilotkit/shared 0.2.0-alpha.7 → 0.2.0

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.
Files changed (65) hide show
  1. package/.turbo/turbo-build.log +87 -94
  2. package/CHANGELOG.md +22 -0
  3. package/dist/chunk-4MTSDAP6.mjs +3 -2
  4. package/dist/chunk-4MTSDAP6.mjs.map +1 -1
  5. package/dist/chunk-FD6FGKYY.mjs +0 -2
  6. package/dist/chunk-FD6FGKYY.mjs.map +1 -1
  7. package/dist/chunk-GFCJUF6J.mjs +3 -2
  8. package/dist/chunk-GFCJUF6J.mjs.map +1 -1
  9. package/dist/chunk-IAFBVORQ.mjs +0 -2
  10. package/dist/chunk-IAFBVORQ.mjs.map +1 -1
  11. package/dist/chunk-L46AW3ET.mjs +3 -2
  12. package/dist/chunk-L46AW3ET.mjs.map +1 -1
  13. package/dist/chunk-NCTOECKL.mjs +9 -2
  14. package/dist/chunk-NCTOECKL.mjs.map +1 -1
  15. package/dist/chunk-UAPRMZEY.mjs +0 -2
  16. package/dist/chunk-UAPRMZEY.mjs.map +1 -1
  17. package/dist/chunk-W6NBBCWB.mjs +3 -2
  18. package/dist/chunk-W6NBBCWB.mjs.map +1 -1
  19. package/dist/chunk-YBHX4Y25.mjs +0 -2
  20. package/dist/chunk-YBHX4Y25.mjs.map +1 -1
  21. package/dist/index.js +49 -14
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +38 -10
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/types/annotated-function.js +17 -2
  26. package/dist/types/annotated-function.js.map +1 -1
  27. package/dist/types/annotated-function.mjs +1 -2
  28. package/dist/types/annotated-function.mjs.map +1 -1
  29. package/dist/types/index.js +17 -2
  30. package/dist/types/index.js.map +1 -1
  31. package/dist/types/index.mjs +3 -4
  32. package/dist/types/index.mjs.map +1 -1
  33. package/dist/types/openai-assistant.js +17 -2
  34. package/dist/types/openai-assistant.js.map +1 -1
  35. package/dist/types/openai-assistant.mjs +1 -2
  36. package/dist/types/openai-assistant.mjs.map +1 -1
  37. package/dist/utils/annotated-function.js +27 -4
  38. package/dist/utils/annotated-function.js.map +1 -1
  39. package/dist/utils/annotated-function.mjs +6 -2
  40. package/dist/utils/annotated-function.mjs.map +1 -1
  41. package/dist/utils/decode-chat-completion-as-text.js +27 -4
  42. package/dist/utils/decode-chat-completion-as-text.js.map +1 -1
  43. package/dist/utils/decode-chat-completion-as-text.mjs +6 -2
  44. package/dist/utils/decode-chat-completion-as-text.mjs.map +1 -1
  45. package/dist/utils/decode-chat-completion.js +27 -4
  46. package/dist/utils/decode-chat-completion.js.map +1 -1
  47. package/dist/utils/decode-chat-completion.mjs +6 -2
  48. package/dist/utils/decode-chat-completion.mjs.map +1 -1
  49. package/dist/utils/index.js +49 -14
  50. package/dist/utils/index.js.map +1 -1
  51. package/dist/utils/index.mjs +35 -7
  52. package/dist/utils/index.mjs.map +1 -1
  53. package/dist/utils/parse-chat-completion.js +27 -4
  54. package/dist/utils/parse-chat-completion.js.map +1 -1
  55. package/dist/utils/parse-chat-completion.mjs +6 -2
  56. package/dist/utils/parse-chat-completion.mjs.map +1 -1
  57. package/dist/utils/utils.js +39 -10
  58. package/dist/utils/utils.js.map +1 -1
  59. package/dist/utils/utils.mjs +18 -2
  60. package/dist/utils/utils.mjs.map +1 -1
  61. package/dist/utils/utils.test.js +1 -2
  62. package/dist/utils/utils.test.js.map +1 -1
  63. package/dist/utils/utils.test.mjs +0 -1
  64. package/dist/utils/utils.test.mjs.map +1 -1
  65. package/package.json +4 -4
@@ -1,96 +1,89 @@
1
1
 
2
- > @copilotkit/shared@0.1.1 build /Users/ataibarkai/LocalGit/Recursively.ai/CopilotKit/CopilotKit/packages/shared
3
- > tsup --treeshake --clean
2
+ > @copilotkit/shared@0.2.0 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/shared
3
+ > tsup --clean
4
4
 
5
- CLI Building entry: src/index.ts, src/types/annotated-function.ts, src/types/index.ts, src/types/openai-assistant.ts, src/utils/annotated-function.ts, src/utils/decode-chat-completion-as-text.ts, src/utils/decode-chat-completion.ts, src/utils/index.ts, src/utils/parse-chat-completion.ts, src/utils/utils.test.ts, src/utils/utils.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v6.7.0
8
- CLI Using tsup config: /Users/ataibarkai/LocalGit/Recursively.ai/CopilotKit/CopilotKit/packages/shared/tsup.config.ts
9
- CLI Target: node14
10
- CLI Cleaning output folder
11
- ESM Build start
12
- CJS Build start
13
- Generated an empty chunk: "annotated-function".
14
- Generated an empty chunk: "index".
15
- Generated an empty chunk: "openai-assistant".
16
- Generated an empty chunk: "chunk-FD6FGKYY".
17
- Generated an empty chunk: "chunk-YBHX4Y25".
18
- Generated an empty chunk: "chunk-IAFBVORQ".
19
- Generated an empty chunk: "chunk-UAPRMZEY".
20
- ESM dist/chunk-FD6FGKYY.mjs 76.00 B
21
- ESM dist/utils/utils.test.mjs 202.00 B
22
- ESM dist/chunk-IAFBVORQ.mjs 76.00 B
23
- ESM dist/chunk-UAPRMZEY.mjs 76.00 B
24
- ESM dist/chunk-YBHX4Y25.mjs 76.00 B
25
- ESM dist/chunk-GFCJUF6J.mjs 2.58 KB
26
- ESM dist/chunk-L46AW3ET.mjs 860.00 B
27
- ESM dist/utils/utils.mjs 237.00 B
28
- ESM dist/utils/parse-chat-completion.mjs 143.00 B
29
- ESM dist/chunk-NCTOECKL.mjs 4.62 KB
30
- ESM dist/utils/annotated-function.mjs 162.00 B
31
- ESM dist/index.mjs 630.00 B
32
- ESM dist/types/openai-assistant.mjs 109.00 B
33
- ESM dist/types/annotated-function.mjs 111.00 B
34
- ESM dist/types/index.mjs 162.00 B
35
- ESM dist/utils/decode-chat-completion.mjs 145.00 B
36
- ESM dist/chunk-4MTSDAP6.mjs 759.00 B
37
- ESM dist/utils/index.mjs 543.00 B
38
- ESM dist/chunk-W6NBBCWB.mjs 1.66 KB
39
- ESM dist/utils/decode-chat-completion-as-text.mjs 159.00 B
40
- ESM dist/chunk-FD6FGKYY.mjs.map 51.00 B
41
- ESM dist/chunk-IAFBVORQ.mjs.map 51.00 B
42
- ESM dist/chunk-YBHX4Y25.mjs.map 51.00 B
43
- ESM dist/chunk-UAPRMZEY.mjs.map 51.00 B
44
- ESM dist/chunk-GFCJUF6J.mjs.map 5.24 KB
45
- ESM dist/utils/parse-chat-completion.mjs.map 51.00 B
46
- ESM dist/utils/utils.test.mjs.map 351.00 B
47
- ESM dist/types/annotated-function.mjs.map 51.00 B
48
- ESM dist/types/openai-assistant.mjs.map 51.00 B
49
- ESM dist/index.mjs.map 51.00 B
50
- ESM dist/types/index.mjs.map 51.00 B
51
- ESM dist/utils/annotated-function.mjs.map 51.00 B
52
- ESM dist/chunk-L46AW3ET.mjs.map 1.55 KB
53
- ESM dist/utils/decode-chat-completion.mjs.map 51.00 B
54
- ESM dist/chunk-4MTSDAP6.mjs.map 1.30 KB
55
- ESM dist/utils/index.mjs.map 51.00 B
56
- ESM dist/utils/utils.mjs.map 51.00 B
57
- ESM dist/chunk-NCTOECKL.mjs.map 11.39 KB
58
- ESM dist/chunk-W6NBBCWB.mjs.map 3.42 KB
59
- ESM dist/utils/decode-chat-completion-as-text.mjs.map 51.00 B
60
- ESM ⚡️ Build success in 112ms
61
- CJS dist/index.js 10.43 KB
62
- CJS dist/types/index.js 80.00 B
63
- CJS dist/utils/annotated-function.js 919.00 B
64
- CJS dist/utils/decode-chat-completion-as-text.js 815.00 B
65
- CJS dist/utils/index.js 10.43 KB
66
- CJS dist/utils/utils.test.js 216.00 B
67
- CJS dist/utils/parse-chat-completion.js 1.70 KB
68
- CJS dist/utils/utils.js 4.80 KB
69
- CJS dist/utils/decode-chat-completion.js 2.62 KB
70
- CJS dist/types/openai-assistant.js 91.00 B
71
- CJS dist/types/annotated-function.js 93.00 B
72
- CJS dist/index.js.map 22.64 KB
73
- CJS dist/types/index.js.map 51.00 B
74
- CJS dist/utils/annotated-function.js.map 1.56 KB
75
- CJS dist/utils/index.js.map 22.66 KB
76
- CJS dist/utils/decode-chat-completion-as-text.js.map 1.30 KB
77
- CJS dist/utils/parse-chat-completion.js.map 3.43 KB
78
- CJS dist/utils/utils.js.map 11.39 KB
79
- CJS dist/utils/utils.test.js.map 351.00 B
80
- CJS dist/utils/decode-chat-completion.js.map 5.24 KB
81
- CJS dist/types/openai-assistant.js.map 51.00 B
82
- CJS dist/types/annotated-function.js.map 51.00 B
83
- CJS ⚡️ Build success in 113ms
84
- DTS Build start
85
- DTS ⚡️ Build success in 916ms
86
- DTS dist/index.d.ts 954.00 B
87
- DTS dist/types/openai-assistant.d.ts 2.36 KB
88
- DTS dist/types/annotated-function.d.ts 767.00 B
89
- DTS dist/utils/utils.d.ts 4.17 KB
90
- DTS dist/utils/parse-chat-completion.d.ts 478.00 B
91
- DTS dist/utils/decode-chat-completion.d.ts 769.00 B
92
- DTS dist/utils/decode-chat-completion-as-text.d.ts 298.00 B
93
- DTS dist/utils/annotated-function.d.ts 296.00 B
94
- DTS dist/types/index.d.ts 282.00 B
95
- DTS dist/utils/index.d.ts 710.00 B
96
- DTS dist/utils/utils.test.d.ts 12.00 B
5
+ CLI Building entry: src/index.ts, src/types/annotated-function.ts, src/types/index.ts, src/types/openai-assistant.ts, src/utils/annotated-function.ts, src/utils/decode-chat-completion-as-text.ts, src/utils/decode-chat-completion.ts, src/utils/index.ts, src/utils/parse-chat-completion.ts, src/utils/utils.test.ts, src/utils/utils.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v6.7.0
8
+ CLI Using tsup config: /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/shared/tsup.config.ts
9
+ CLI Target: node14
10
+ CLI Cleaning output folder
11
+ ESM Build start
12
+ CJS Build start
13
+ CJS dist/index.js 11.61 KB
14
+ CJS dist/types/annotated-function.js 849.00 B
15
+ CJS dist/types/index.js 797.00 B
16
+ CJS dist/types/openai-assistant.js 841.00 B
17
+ CJS dist/utils/annotated-function.js 1.90 KB
18
+ CJS dist/utils/decode-chat-completion.js 3.61 KB
19
+ CJS dist/utils/decode-chat-completion-as-text.js 1.82 KB
20
+ CJS dist/utils/index.js 11.62 KB
21
+ CJS dist/utils/parse-chat-completion.js 2.68 KB
22
+ CJS dist/utils/utils.test.js 184.00 B
23
+ CJS dist/utils/utils.js 5.85 KB
24
+ CJS dist/index.js.map 22.81 KB
25
+ CJS dist/types/annotated-function.js.map 872.00 B
26
+ CJS dist/types/index.js.map 205.00 B
27
+ CJS dist/types/openai-assistant.js.map 2.45 KB
28
+ CJS dist/utils/annotated-function.js.map 1.60 KB
29
+ CJS dist/utils/decode-chat-completion.js.map 5.28 KB
30
+ CJS dist/utils/decode-chat-completion-as-text.js.map 1.34 KB
31
+ CJS dist/utils/index.js.map 22.99 KB
32
+ CJS dist/utils/parse-chat-completion.js.map 3.47 KB
33
+ CJS dist/utils/utils.test.js.map 354.00 B
34
+ CJS dist/utils/utils.js.map 11.47 KB
35
+ CJS ⚡️ Build success in 50ms
36
+ ESM dist/index.mjs 898.00 B
37
+ ESM dist/types/openai-assistant.mjs 77.00 B
38
+ ESM dist/utils/annotated-function.mjs 188.00 B
39
+ ESM dist/chunk-FD6FGKYY.mjs 43.00 B
40
+ ESM dist/chunk-YBHX4Y25.mjs 43.00 B
41
+ ESM dist/chunk-IAFBVORQ.mjs 43.00 B
42
+ ESM dist/utils/decode-chat-completion-as-text.mjs 170.00 B
43
+ ESM dist/utils/index.mjs 811.00 B
44
+ ESM dist/utils/decode-chat-completion.mjs 150.00 B
45
+ ESM dist/chunk-UAPRMZEY.mjs 43.00 B
46
+ ESM dist/chunk-W6NBBCWB.mjs 1.63 KB
47
+ ESM dist/chunk-NCTOECKL.mjs 4.60 KB
48
+ ESM dist/chunk-L46AW3ET.mjs 830.00 B
49
+ ESM dist/chunk-4MTSDAP6.mjs 729.00 B
50
+ ESM dist/chunk-GFCJUF6J.mjs 2.55 KB
51
+ ESM dist/utils/parse-chat-completion.mjs 147.00 B
52
+ ESM dist/utils/utils.test.mjs 170.00 B
53
+ ESM dist/utils/utils.mjs 375.00 B
54
+ ESM dist/types/annotated-function.mjs 79.00 B
55
+ ESM dist/types/index.mjs 130.00 B
56
+ ESM dist/index.mjs.map 71.00 B
57
+ ESM dist/types/openai-assistant.mjs.map 71.00 B
58
+ ESM dist/utils/annotated-function.mjs.map 71.00 B
59
+ ESM dist/chunk-FD6FGKYY.mjs.map 71.00 B
60
+ ESM dist/chunk-YBHX4Y25.mjs.map 71.00 B
61
+ ESM dist/chunk-IAFBVORQ.mjs.map 71.00 B
62
+ ESM dist/utils/decode-chat-completion-as-text.mjs.map 71.00 B
63
+ ESM dist/utils/index.mjs.map 71.00 B
64
+ ESM dist/utils/decode-chat-completion.mjs.map 71.00 B
65
+ ESM dist/chunk-UAPRMZEY.mjs.map 71.00 B
66
+ ESM dist/chunk-W6NBBCWB.mjs.map 3.42 KB
67
+ ESM dist/chunk-NCTOECKL.mjs.map 11.39 KB
68
+ ESM dist/chunk-L46AW3ET.mjs.map 1.55 KB
69
+ ESM dist/chunk-4MTSDAP6.mjs.map 1.30 KB
70
+ ESM dist/chunk-GFCJUF6J.mjs.map 5.24 KB
71
+ ESM dist/utils/parse-chat-completion.mjs.map 71.00 B
72
+ ESM dist/utils/utils.test.mjs.map 352.00 B
73
+ ESM dist/utils/utils.mjs.map 71.00 B
74
+ ESM dist/types/annotated-function.mjs.map 71.00 B
75
+ ESM dist/types/index.mjs.map 71.00 B
76
+ ESM ⚡️ Build success in 53ms
77
+ DTS Build start
78
+ DTS ⚡️ Build success in 1838ms
79
+ DTS dist/index.d.ts 954.00 B
80
+ DTS dist/types/openai-assistant.d.ts 2.36 KB
81
+ DTS dist/types/annotated-function.d.ts 767.00 B
82
+ DTS dist/utils/utils.d.ts 4.17 KB
83
+ DTS dist/utils/parse-chat-completion.d.ts 478.00 B
84
+ DTS dist/utils/decode-chat-completion.d.ts 769.00 B
85
+ DTS dist/utils/decode-chat-completion-as-text.d.ts 298.00 B
86
+ DTS dist/utils/annotated-function.d.ts 296.00 B
87
+ DTS dist/types/index.d.ts 282.00 B
88
+ DTS dist/utils/index.d.ts 710.00 B
89
+ DTS dist/utils/utils.test.d.ts 12.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @copilotkit/shared
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - eba87c7: .4
8
+ - 61168c7: no treeshake
9
+ - fb32fe3: .2
10
+ - eba87c7: .3
11
+ - new chatbot ui, new component names, new build system, new docs
12
+ - 61168c7: no treeshake take 2
13
+ - 61168c7: remove treeshake in build
14
+ - fb32fe3: build naming refactor
15
+ - eba87c7: .5
16
+ - 61168c7: cache clean
17
+ - fb32fe3: .3
18
+
19
+ ## 0.2.0-alpha.8
20
+
21
+ ### Minor Changes
22
+
23
+ - cache clean
24
+
3
25
  ## 0.2.0-alpha.7
4
26
 
5
27
  ### Minor Changes
@@ -26,6 +26,7 @@ function decodeChatCompletionAsText(stream) {
26
26
  });
27
27
  }
28
28
 
29
- export { decodeChatCompletionAsText };
30
- //# sourceMappingURL=out.js.map
29
+ export {
30
+ decodeChatCompletionAsText
31
+ };
31
32
  //# sourceMappingURL=chunk-4MTSDAP6.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/decode-chat-completion-as-text.ts"],"names":[],"mappings":";AAEO,SAAS,2BACd,QACwB;AACxB,QAAM,SAAS,OAAO,UAAU;AAEhC,SAAO,IAAI,eAAuB;AAAA,IAChC,MAAM,KAAK,YAAY;AACrB,aAAO,MAAM;AACX,YAAI;AACF,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAE1C,cAAI,MAAM;AACR,uBAAW,MAAM;AACjB;AAAA,UACF;AAEA,cAAI,MAAM,SAAS,WAAW;AAC5B,uBAAW,QAAQ,MAAM,OAAO;AAChC;AAAA,UACF;AAAA,QACF,SAAS,OAAP;AACA,qBAAW,MAAM,KAAK;AACtB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,OAAO;AAAA,IAChB;AAAA,EACF,CAAC;AACH","sourcesContent":["import { ChatCompletionEvent } from \"./decode-chat-completion\";\n\nexport function decodeChatCompletionAsText(\n stream: ReadableStream<ChatCompletionEvent>,\n): ReadableStream<string> {\n const reader = stream.getReader();\n\n return new ReadableStream<string>({\n async pull(controller) {\n while (true) {\n try {\n const { done, value } = await reader.read();\n\n if (done) {\n controller.close();\n return;\n }\n\n if (value.type === \"content\") {\n controller.enqueue(value.content);\n continue;\n }\n } catch (error) {\n controller.error(error);\n return;\n }\n }\n },\n cancel() {\n reader.cancel();\n },\n });\n}\n"]}
1
+ {"version":3,"sources":["../src/utils/decode-chat-completion-as-text.ts"],"sourcesContent":["import { ChatCompletionEvent } from \"./decode-chat-completion\";\n\nexport function decodeChatCompletionAsText(\n stream: ReadableStream<ChatCompletionEvent>,\n): ReadableStream<string> {\n const reader = stream.getReader();\n\n return new ReadableStream<string>({\n async pull(controller) {\n while (true) {\n try {\n const { done, value } = await reader.read();\n\n if (done) {\n controller.close();\n return;\n }\n\n if (value.type === \"content\") {\n controller.enqueue(value.content);\n continue;\n }\n } catch (error) {\n controller.error(error);\n return;\n }\n }\n },\n cancel() {\n reader.cancel();\n },\n });\n}\n"],"mappings":";AAEO,SAAS,2BACd,QACwB;AACxB,QAAM,SAAS,OAAO,UAAU;AAEhC,SAAO,IAAI,eAAuB;AAAA,IAChC,MAAM,KAAK,YAAY;AACrB,aAAO,MAAM;AACX,YAAI;AACF,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAE1C,cAAI,MAAM;AACR,uBAAW,MAAM;AACjB;AAAA,UACF;AAEA,cAAI,MAAM,SAAS,WAAW;AAC5B,uBAAW,QAAQ,MAAM,OAAO;AAChC;AAAA,UACF;AAAA,QACF,SAAS,OAAP;AACA,qBAAW,MAAM,KAAK;AACtB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,OAAO;AAAA,IAChB;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1,3 +1 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
1
  //# sourceMappingURL=chunk-FD6FGKYY.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -90,6 +90,7 @@ function decodeChatCompletion(stream) {
90
90
  });
91
91
  }
92
92
 
93
- export { decodeChatCompletion };
94
- //# sourceMappingURL=out.js.map
93
+ export {
94
+ decodeChatCompletion
95
+ };
95
96
  //# sourceMappingURL=chunk-GFCJUF6J.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/decode-chat-completion.ts"],"names":[],"mappings":";AAwBO,SAAS,qBACd,QACqC;AACrC,QAAM,SAAS,OAAO,UAAU;AAEhC,MAAI,OAAsC;AAC1C,MAAI,mBAA2B;AAC/B,MAAI,wBAAgC;AAEpC,iBAAe,QAAQ,YAAmD;AACxE,QAAI,YAAY;AACd,UAAI;AACF,mBAAW,MAAM;AAAA,MACnB,SAAS,GAAP;AAAA,MAAW;AAAA,IACf;AACA,QAAI,QAAQ;AACV,UAAI;AACF,cAAM,OAAO,OAAO;AAAA,MACtB,SAAS,GAAP;AAAA,MAAW;AAAA,IACf;AAAA,EACF;AAEA,SAAO,IAAI,eAAoC;AAAA,IAC7C,MAAM,KAAK,YAAY;AACrB,YAAM,oBAAoB,MAAe;AACvC,YAAI,OAAY;AAChB,YAAI;AACF,iBAAO,KAAK,MAAM,qBAAqB;AAAA,QACzC,SAAS,OAAP;AACA,kBAAQ,UAAU;AAClB,qBAAW,MAAM,KAAK;AACtB,iBAAO;AAAA,QACT;AACA,mBAAW,QAAQ;AAAA,UACjB,MAAM;AAAA,UACN,MAAM;AAAA,UACN,WAAW;AAAA,QACb,CAAC;AAED,eAAO;AACP,2BAAmB;AACnB,gCAAwB;AACxB,eAAO;AAAA,MACT;AAEA,aAAO,MAAM;AACX,YAAI;AACF,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAE1C,cAAI,MAAM;AACR,gBAAI,SAAS,YAAY;AACvB,gCAAkB;AAAA,YACpB;AACA,kBAAM,QAAQ,UAAU;AACxB;AAAA,UACF;AAGA,cAAI,SAAS,cAAc,CAAC,MAAM,QAAQ,CAAC,EAAE,MAAM,eAAe;AAChE,gBAAI,CAAC,kBAAkB,GAAG;AACxB;AAAA,YACF;AAAA,UACF;AAEA,iBAAO,MAAM,QAAQ,CAAC,EAAE,MAAM,gBAAgB,aAAa;AAG3D,cAAI,SAAS,WAAW;AACtB,gBAAI,MAAM,QAAQ,CAAC,EAAE,MAAM,SAAS;AAClC,yBAAW,QAAQ;AAAA,gBACjB,MAAM;AAAA,gBACN,SAAS,MAAM,QAAQ,CAAC,EAAE,MAAM;AAAA,cAClC,CAAC;AAAA,YACH;AACA;AAAA,UACF,WAES,SAAS,YAAY;AAC5B,gBAAI,MAAM,QAAQ,CAAC,EAAE,MAAM,cAAe,MAAM;AAC9C,iCAAmB,MAAM,QAAQ,CAAC,EAAE,MAAM,cAAe;AAAA,YAC3D;AACA,gBAAI,MAAM,QAAQ,CAAC,EAAE,MAAM,cAAe,WAAW;AACnD,uCAAyB,MAAM,QAAQ,CAAC,EAAE,MAAM,cAAe;AAAA,YACjE;AACA,uBAAW,QAAQ;AAAA,cACjB,MAAM;AAAA,cACN,MAAM;AAAA,cACN,WAAW;AAAA,YACb,CAAC;AACD;AAAA,UACF;AAAA,QACF,SAAS,OAAP;AACA,qBAAW,MAAM,KAAK;AACtB,gBAAM,QAAQ,UAAU;AACxB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,OAAO;AAAA,IAChB;AAAA,EACF,CAAC;AACH","sourcesContent":["import { ChatCompletionChunk } from \"./parse-chat-completion\";\n\nexport interface ChatCompletionContentEvent {\n type: \"content\";\n content: string;\n}\n\nexport interface ChatCompletionPartialEvent {\n type: \"partial\";\n name: string;\n arguments: string;\n}\n\nexport interface ChatCompletionFunctionEvent {\n type: \"function\";\n name: string;\n arguments: any;\n}\n\nexport type ChatCompletionEvent =\n | ChatCompletionContentEvent\n | ChatCompletionPartialEvent\n | ChatCompletionFunctionEvent;\n\nexport function decodeChatCompletion(\n stream: ReadableStream<ChatCompletionChunk>,\n): ReadableStream<ChatCompletionEvent> {\n const reader = stream.getReader();\n\n let mode: \"function\" | \"message\" | null = null;\n let functionCallName: string = \"\";\n let functionCallArguments: string = \"\";\n\n async function cleanup(controller?: ReadableStreamDefaultController<any>) {\n if (controller) {\n try {\n controller.close();\n } catch (_) {}\n }\n if (reader) {\n try {\n await reader.cancel();\n } catch (_) {}\n }\n }\n\n return new ReadableStream<ChatCompletionEvent>({\n async pull(controller) {\n const flushFunctionCall = (): boolean => {\n let args: any = null;\n try {\n args = JSON.parse(functionCallArguments);\n } catch (error) {\n cleanup(controller);\n controller.error(error);\n return false;\n }\n controller.enqueue({\n type: \"function\",\n name: functionCallName,\n arguments: args,\n });\n\n mode = null;\n functionCallName = \"\";\n functionCallArguments = \"\";\n return true;\n };\n\n while (true) {\n try {\n const { done, value } = await reader.read();\n\n if (done) {\n if (mode === \"function\") {\n flushFunctionCall();\n }\n await cleanup(controller);\n return;\n }\n\n // In case we are in a function call but the next message is not a function call, flush it.\n if (mode === \"function\" && !value.choices[0].delta.function_call) {\n if (!flushFunctionCall()) {\n return;\n }\n }\n\n mode = value.choices[0].delta.function_call ? \"function\" : \"message\";\n\n // if we get a message, emit the content and continue;\n if (mode === \"message\") {\n if (value.choices[0].delta.content) {\n controller.enqueue({\n type: \"content\",\n content: value.choices[0].delta.content,\n });\n }\n continue;\n }\n // if we get a function call, buffer the name and arguments, then emit a partial event.\n else if (mode === \"function\") {\n if (value.choices[0].delta.function_call!.name) {\n functionCallName = value.choices[0].delta.function_call!.name!;\n }\n if (value.choices[0].delta.function_call!.arguments) {\n functionCallArguments += value.choices[0].delta.function_call!.arguments!;\n }\n controller.enqueue({\n type: \"partial\",\n name: functionCallName,\n arguments: functionCallArguments,\n });\n continue;\n }\n } catch (error) {\n controller.error(error);\n await cleanup(controller);\n return;\n }\n }\n },\n cancel() {\n reader.cancel();\n },\n });\n}\n"]}
1
+ {"version":3,"sources":["../src/utils/decode-chat-completion.ts"],"sourcesContent":["import { ChatCompletionChunk } from \"./parse-chat-completion\";\n\nexport interface ChatCompletionContentEvent {\n type: \"content\";\n content: string;\n}\n\nexport interface ChatCompletionPartialEvent {\n type: \"partial\";\n name: string;\n arguments: string;\n}\n\nexport interface ChatCompletionFunctionEvent {\n type: \"function\";\n name: string;\n arguments: any;\n}\n\nexport type ChatCompletionEvent =\n | ChatCompletionContentEvent\n | ChatCompletionPartialEvent\n | ChatCompletionFunctionEvent;\n\nexport function decodeChatCompletion(\n stream: ReadableStream<ChatCompletionChunk>,\n): ReadableStream<ChatCompletionEvent> {\n const reader = stream.getReader();\n\n let mode: \"function\" | \"message\" | null = null;\n let functionCallName: string = \"\";\n let functionCallArguments: string = \"\";\n\n async function cleanup(controller?: ReadableStreamDefaultController<any>) {\n if (controller) {\n try {\n controller.close();\n } catch (_) {}\n }\n if (reader) {\n try {\n await reader.cancel();\n } catch (_) {}\n }\n }\n\n return new ReadableStream<ChatCompletionEvent>({\n async pull(controller) {\n const flushFunctionCall = (): boolean => {\n let args: any = null;\n try {\n args = JSON.parse(functionCallArguments);\n } catch (error) {\n cleanup(controller);\n controller.error(error);\n return false;\n }\n controller.enqueue({\n type: \"function\",\n name: functionCallName,\n arguments: args,\n });\n\n mode = null;\n functionCallName = \"\";\n functionCallArguments = \"\";\n return true;\n };\n\n while (true) {\n try {\n const { done, value } = await reader.read();\n\n if (done) {\n if (mode === \"function\") {\n flushFunctionCall();\n }\n await cleanup(controller);\n return;\n }\n\n // In case we are in a function call but the next message is not a function call, flush it.\n if (mode === \"function\" && !value.choices[0].delta.function_call) {\n if (!flushFunctionCall()) {\n return;\n }\n }\n\n mode = value.choices[0].delta.function_call ? \"function\" : \"message\";\n\n // if we get a message, emit the content and continue;\n if (mode === \"message\") {\n if (value.choices[0].delta.content) {\n controller.enqueue({\n type: \"content\",\n content: value.choices[0].delta.content,\n });\n }\n continue;\n }\n // if we get a function call, buffer the name and arguments, then emit a partial event.\n else if (mode === \"function\") {\n if (value.choices[0].delta.function_call!.name) {\n functionCallName = value.choices[0].delta.function_call!.name!;\n }\n if (value.choices[0].delta.function_call!.arguments) {\n functionCallArguments += value.choices[0].delta.function_call!.arguments!;\n }\n controller.enqueue({\n type: \"partial\",\n name: functionCallName,\n arguments: functionCallArguments,\n });\n continue;\n }\n } catch (error) {\n controller.error(error);\n await cleanup(controller);\n return;\n }\n }\n },\n cancel() {\n reader.cancel();\n },\n });\n}\n"],"mappings":";AAwBO,SAAS,qBACd,QACqC;AACrC,QAAM,SAAS,OAAO,UAAU;AAEhC,MAAI,OAAsC;AAC1C,MAAI,mBAA2B;AAC/B,MAAI,wBAAgC;AAEpC,iBAAe,QAAQ,YAAmD;AACxE,QAAI,YAAY;AACd,UAAI;AACF,mBAAW,MAAM;AAAA,MACnB,SAAS,GAAP;AAAA,MAAW;AAAA,IACf;AACA,QAAI,QAAQ;AACV,UAAI;AACF,cAAM,OAAO,OAAO;AAAA,MACtB,SAAS,GAAP;AAAA,MAAW;AAAA,IACf;AAAA,EACF;AAEA,SAAO,IAAI,eAAoC;AAAA,IAC7C,MAAM,KAAK,YAAY;AACrB,YAAM,oBAAoB,MAAe;AACvC,YAAI,OAAY;AAChB,YAAI;AACF,iBAAO,KAAK,MAAM,qBAAqB;AAAA,QACzC,SAAS,OAAP;AACA,kBAAQ,UAAU;AAClB,qBAAW,MAAM,KAAK;AACtB,iBAAO;AAAA,QACT;AACA,mBAAW,QAAQ;AAAA,UACjB,MAAM;AAAA,UACN,MAAM;AAAA,UACN,WAAW;AAAA,QACb,CAAC;AAED,eAAO;AACP,2BAAmB;AACnB,gCAAwB;AACxB,eA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VORQ.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -23,6 +23,7 @@ function annotatedFunctionToChatCompletionFunction(annotatedFunction) {
23
23
  return chatCompletionFunction;
24
24
  }
25
25
 
26
- export { annotatedFunctionToChatCompletionFunction };
27
- //# sourceMappingURL=out.js.map
26
+ export {
27
+ annotatedFunctionToChatCompletionFunction
28
+ };
28
29
  //# sourceMappingURL=chunk-L46AW3ET.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/annotated-function.ts"],"names":[],"mappings":";AAEO,SAAS,0CACd,mBACU;AAEV,MAAI,aAAqC,CAAC;AAC1C,WAAS,OAAO,kBAAkB,qBAAqB;AAErD,QAAI,EAAE,MAAM,UAAU,GAAG,cAAc,IAAI;AAC3C,eAAW,IAAI,IAAI,IAAI;AAAA,EACzB;AAEA,MAAI,yBAAmC,CAAC;AACxC,WAAS,OAAO,kBAAkB,qBAAqB;AACrD,QAAI,IAAI,UAAU;AAChB,6BAAuB,KAAK,IAAI,IAAI;AAAA,IACtC;AAAA,EACF;AAGA,MAAI,yBAAmC;AAAA,IACrC,MAAM,kBAAkB;AAAA,IACxB,aAAa,kBAAkB;AAAA,IAC/B,YAAY;AAAA,MACV,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,UAAU;AAAA,IACZ;AAAA,EACF;AAEA,SAAO;AACT","sourcesContent":["import { AnnotatedFunction, Function } from \"../types\";\n\nexport function annotatedFunctionToChatCompletionFunction(\n annotatedFunction: AnnotatedFunction<any[]>,\n): Function {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let arg of annotatedFunction.argumentAnnotations) {\n // isolate the args we should forward inline\n let { name, required, ...forwardedArgs } = arg;\n parameters[arg.name] = forwardedArgs;\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of annotatedFunction.argumentAnnotations) {\n if (arg.required) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: Function = {\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n };\n\n return chatCompletionFunction;\n}\n"]}
1
+ {"version":3,"sources":["../src/utils/annotated-function.ts"],"sourcesContent":["import { AnnotatedFunction, Function } from \"../types\";\n\nexport function annotatedFunctionToChatCompletionFunction(\n annotatedFunction: AnnotatedFunction<any[]>,\n): Function {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let arg of annotatedFunction.argumentAnnotations) {\n // isolate the args we should forward inline\n let { name, required, ...forwardedArgs } = arg;\n parameters[arg.name] = forwardedArgs;\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of annotatedFunction.argumentAnnotations) {\n if (arg.required) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: Function = {\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n };\n\n return chatCompletionFunction;\n}\n"],"mappings":";AAEO,SAAS,0CACd,mBACU;AAEV,MAAI,aAAqC,CAAC;AAC1C,WAAS,OAAO,kBAAkB,qBAAqB;AAErD,QAAI,EAAE,MAAM,UAAU,GAAG,cAAc,IAAI;AAC3C,eAAW,IAAI,IAAI,IAAI;AAAA,EACzB;AAEA,MAAI,yBAAmC,CAAC;AACxC,WAAS,OAAO,kBAAkB,qBAAqB;AACrD,QAAI,IAAI,UAAU;AAChB,6BAAuB,KAAK,IAAI,IAAI;AAAA,IACtC;AAAA,EACF;AAGA,MAAI,yBAAmC;AAAA,IACrC,MAAM,kBAAkB;AAAA,IACxB,aAAa,kBAAkB;AAAA,IAC/B,YAAY;AAAA,MACV,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,UAAU;AAAA,IACZ;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -127,6 +127,13 @@ function formatStreamPart(type, value) {
127
127
  var isStreamStringEqualToType = (type, value) => value.startsWith(`${StreamStringPrefixes[type]}:`) && value.endsWith("\n");
128
128
  var COMPLEX_HEADER = "X-Experimental-Stream-Data";
129
129
 
130
- export { COMPLEX_HEADER, StreamStringPrefixes, formatStreamPart, isStreamStringEqualToType, parseStreamPart, streamPartsByCode, validCodes };
131
- //# sourceMappingURL=out.js.map
130
+ export {
131
+ streamPartsByCode,
132
+ StreamStringPrefixes,
133
+ validCodes,
134
+ parseStreamPart,
135
+ formatStreamPart,
136
+ isStreamStringEqualToType,
137
+ COMPLEX_HEADER
138
+ };
132
139
  //# sourceMappingURL=chunk-NCTOECKL.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/utils.ts"],"names":[],"mappings":";AAQA,IAAM,iBAAkD;AAAA,EACtD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO,CAAC,UAAqB;AAC3B,QAAI,OAAO,UAAU,UAAU;AAC7B,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACvD;AACA,WAAO,EAAE,MAAM,QAAQ,MAAM;AAAA,EAC/B;AACF;AASA,IAAM,yBAA4F;AAAA,EAChG,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO,CAAC,UAAqB;AAC3B,QACE,SAAS,QACT,OAAO,UAAU,YACjB,EAAE,mBAAmB,UACrB,OAAO,MAAM,kBAAkB,YAC/B,MAAM,iBAAiB,QACvB,EAAE,UAAU,MAAM,kBAClB,EAAE,eAAe,MAAM,kBACvB,OAAO,MAAM,cAAc,SAAS,YACpC,OAAO,MAAM,cAAc,cAAc,UACzC;AACA,YAAM,IAAI,MAAM,yEAAyE;AAAA,IAC3F;AAEA,WAAO;AAAA,MACL,MAAM;AAAA,MACN;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAM,iBAA4D;AAAA,EAChE,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO,CAAC,U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SAAO,kBAAkB,IAAI,EAAE,MAAM,SAAS;AAChD;AAQO,SAAS,iBACd,MACA,OACc;AACd,QAAM,aAAa,YAAY,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI;AAEhE,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,6BAA6B,MAAM;AAAA,EACrD;AAEA,SAAO,GAAG,WAAW,QAAQ,KAAK,UAAU,KAAK;AAAA;AACnD;AAEO,IAAM,4BAA4B,CACvC,MACA,UAEA,MAAM,WAAW,GAAG,qBAAqB,IAAI,IAAI,KAAK,MAAM,SAAS,IAAI;AAQpE,IAAM,iBAAiB","sourcesContent":["import { AssistantMessage, FunctionCall, JSONValue } from \"../types/openai-assistant\";\n\nexport interface StreamPart<CODE extends string, NAME extends string, TYPE> {\n code: CODE;\n name: NAME;\n parse: (value: JSONValue) => { type: NAME; value: TYPE };\n}\n\nconst textStreamPart: StreamPart<\"0\", \"text\", string> = {\n code: \"0\",\n name: \"text\",\n parse: (value: JSONValue) => {\n if (typeof value !== \"string\") {\n throw new Error('\"text\" parts expect a string value.');\n }\n return { type: \"text\", value };\n },\n};\n\n/**\n * This is a utility function that helps in parsing the stream parts.\n * It takes a JSONValue as input and returns an object with type and value.\n * The type is a string that represents the type of the stream part.\n * The value is the actual value of the stream part.\n * If the input value is not a string, it throws an error.\n */\nconst functionCallStreamPart: StreamPart<\"1\", \"function_call\", { function_call: FunctionCall }> = {\n code: \"1\",\n name: \"function_call\",\n parse: (value: JSONValue) => {\n if (\n value == null ||\n typeof value !== \"object\" ||\n !(\"function_call\" in value) ||\n typeof value.function_call !== \"object\" ||\n value.function_call == null ||\n !(\"name\" in value.function_call) ||\n !(\"arguments\" in value.function_call) ||\n typeof value.function_call.name !== \"string\" ||\n typeof value.function_call.arguments !== \"string\"\n ) {\n throw new Error('\"function_call\" parts expect an object with a \"function_call\" property.');\n }\n\n return {\n type: \"function_call\",\n value: value as unknown as { function_call: FunctionCall },\n };\n },\n};\n\nconst dataStreamPart: StreamPart<\"2\", \"data\", Array<JSONValue>> = {\n code: \"2\",\n name: \"data\",\n parse: (value: JSONValue) => {\n if (!Array.isArray(value)) {\n throw new Error('\"data\" parts expect an array value.');\n }\n\n return { type: \"data\", value };\n },\n};\n\nconst errorStreamPart: StreamPart<\"3\", \"error\", string> = {\n code: \"3\",\n name: \"error\",\n parse: (value: JSONValue) => {\n if (typeof value !== \"string\") {\n throw new Error('\"error\" parts expect a string value.');\n }\n return { type: \"error\", value };\n },\n};\n\nconst assistantMessage: StreamPart<\"4\", \"assistant_message\", AssistantMessage> = {\n code: \"4\",\n name: \"assistant_message\",\n parse: (value: JSONValue) => {\n if (\n value == null ||\n typeof value !== \"object\" ||\n !(\"id\" in value) ||\n !(\"role\" in value) ||\n !(\"content\" in value) ||\n typeof value.id !== \"string\" ||\n typeof value.role !== \"string\" ||\n value.role !== \"assistant\" ||\n !Array.isArray(value.content) ||\n !value.content.every(\n (item) =>\n item != null &&\n typeof item === \"object\" &&\n \"type\" in item &&\n item.type === \"text\" &&\n \"text\" in item &&\n item.text != null &&\n typeof item.text === \"object\" &&\n \"value\" in item.text &&\n typeof item.text.value === \"string\",\n )\n ) {\n throw new Error(\n '\"assistant_message\" parts expect an object with an \"id\", \"role\", and \"content\" property.',\n );\n }\n\n return {\n type: \"assistant_message\",\n value: value as AssistantMessage,\n };\n },\n};\n\nconst assistantControlData: StreamPart<\n \"5\",\n \"assistant_control_data\",\n {\n threadId: string;\n messageId: string;\n }\n> = {\n code: \"5\",\n name: \"assistant_control_data\",\n parse: (value: JSONValue) => {\n if (\n value == null ||\n typeof value !== \"object\" ||\n !(\"threadId\" in value) ||\n !(\"messageId\" in value) ||\n typeof value.threadId !== \"string\" ||\n typeof value.messageId !== \"string\"\n ) {\n throw new Error(\n '\"assistant_control_data\" parts expect an object with a \"threadId\" and \"messageId\" property.',\n );\n }\n\n return {\n type: \"assistant_control_data\",\n value: {\n threadId: value.threadId,\n messageId: value.messageId,\n },\n };\n },\n};\n\nconst streamParts = [\n textStreamPart,\n functionCallStreamPart,\n dataStreamPart,\n errorStreamPart,\n assistantMessage,\n assistantControlData,\n] as const;\n\n// union type of all stream parts\ntype StreamParts =\n | typeof textStreamPart\n | typeof functionCallStreamPart\n | typeof dataStreamPart\n | typeof errorStreamPart\n | typeof assistantMessage\n | typeof assistantControlData;\n\n/**\n * Maps the type of a stream part to its value type.\n */\ntype StreamPartValueType = {\n [P in StreamParts as P[\"name\"]]: ReturnType<P[\"parse\"]>[\"value\"];\n};\n\nexport type StreamPartType =\n | ReturnType<typeof textStreamPart.parse>\n | ReturnType<typeof functionCallStreamPart.parse>\n | ReturnType<typeof dataStreamPart.parse>\n | ReturnType<typeof errorStreamPart.parse>\n | ReturnType<typeof assistantMessage.parse>\n | ReturnType<typeof assistantControlData.parse>;\n\nexport const streamPartsByCode = {\n [textStreamPart.code]: textStreamPart,\n [functionCallStreamPart.code]: functionCallStreamPart,\n [dataStreamPart.code]: dataStreamPart,\n [errorStreamPart.code]: errorStreamPart,\n [assistantMessage.code]: assistantMessage,\n [assistantControlData.code]: assistantControlData,\n} as const;\n\n/**\n * The map of prefixes for data in the stream\n *\n * - 0: Text from the LLM response\n * - 1: (OpenAI) function_call responses\n * - 2: custom JSON added by the user using `Data`\n *\n * Example:\n * ```\n * 0:Vercel\n * 0:'s\n * 0: AI\n * 0: AI\n * 0: SDK\n * 0: is great\n * 0:!\n * 2: { \"someJson\": \"value\" }\n * 1: {\"function_call\": {\"name\": \"get_current_weather\", \"arguments\": \"{\\\\n\\\\\"location\\\\\": \\\\\"Charlottesville, Virginia\\\\\",\\\\n\\\\\"format\\\\\": \\\\\"celsius\\\\\"\\\\n}\"}}\n *```\n */\nexport const StreamStringPrefixes = {\n [textStreamPart.name]: textStreamPart.code,\n [functionCallStreamPart.name]: functionCallStreamPart.code,\n [dataStreamPart.name]: dataStreamPart.code,\n [errorStreamPart.name]: errorStreamPart.code,\n [assistantMessage.name]: assistantMessage.code,\n [assistantControlData.name]: assistantControlData.code,\n} as const;\n\nexport const validCodes = streamParts.map((part) => part.code);\n\n/**\n * Parses a stream part from a string.\n *\n * @param line The string to parse.\n * @returns The parsed stream part.\n * @throws An error if the string cannot be parsed.\n */\nexport const parseStreamPart = (line: string): StreamPartType => {\n const firstSeparatorIndex = line.indexOf(\":\");\n\n if (firstSeparatorIndex === -1) {\n throw new Error(\"Failed to parse stream string. No separator found.\");\n }\n\n const prefix = line.slice(0, firstSeparatorIndex);\n\n if (!validCodes.includes(prefix as keyof typeof streamPartsByCode)) {\n throw new Error(`Failed to parse stream string. Invalid code ${prefix}.`);\n }\n\n const code = prefix as keyof typeof streamPartsByCode;\n\n const textValue = line.slice(firstSeparatorIndex + 1);\n const jsonValue: JSONValue = JSON.parse(textValue);\n\n return streamPartsByCode[code].parse(jsonValue);\n};\n\n/**\n * Prepends a string with a prefix from the `StreamChunkPrefixes`, JSON-ifies it,\n * and appends a new line.\n *\n * It ensures type-safety for the part type and value.\n */\nexport function formatStreamPart<T extends keyof StreamPartValueType>(\n type: T,\n value: StreamPartValueType[T],\n): StreamString {\n const streamPart = streamParts.find((part) => part.name === type);\n\n if (!streamPart) {\n throw new Error(`Invalid stream part type: ${type}`);\n }\n\n return `${streamPart.code}:${JSON.stringify(value)}\\n`;\n}\n\nexport const isStreamStringEqualToType = (\n type: keyof typeof StreamStringPrefixes,\n value: string,\n): value is StreamString =>\n value.startsWith(`${StreamStringPrefixes[type]}:`) && value.endsWith(\"\\n\");\n\nexport type StreamString =\n `${typeof StreamStringPrefixes[keyof typeof StreamStringPrefixes]}:${string}\\n`;\n\n/**\n * A header sent to the client so it knows how to handle parsing the stream (as a deprecated text response or using the new prefixed protocol)\n */\nexport const COMPLEX_HEADER = \"X-Experimental-Stream-Data\";\n"]}
1
+ {"version":3,"sources":["../src/utils/utils.ts"],"sourcesContent":["import { AssistantMessage, FunctionCall, JSONValue } from \"../types/openai-assistant\";\n\nexport interface StreamPart<CODE extends string, NAME extends string, TYPE> {\n code: CODE;\n name: NAME;\n parse: (value: JSONValue) => { type: NAME; value: TYPE };\n}\n\nconst textStreamPart: StreamPart<\"0\", \"text\", string> = {\n code: \"0\",\n name: \"text\",\n parse: (value: JSONValue) => {\n if (typeof value !== \"string\") {\n throw new Error('\"text\" parts expect a string value.');\n }\n return { type: \"text\", value };\n },\n};\n\n/**\n * This is a utility function that helps in parsing the stream parts.\n * It takes a JSONValue as input and returns an object with type and value.\n * The type is a string that represents the type of the stream part.\n * The value is the actual value of the stream part.\n * If the input value is not a string, it throws an error.\n */\nconst functionCallStreamPart: StreamPart<\"1\", \"function_call\", { function_call: FunctionCall }> = {\n code: \"1\",\n name: \"function_call\",\n parse: (value: JSONValue) => {\n if (\n value == null ||\n typeof value !== \"object\" ||\n !(\"function_call\" in value) ||\n typeof value.function_call !== \"object\" ||\n value.function_call == null ||\n !(\"name\" in value.function_call) ||\n !(\"arguments\" in value.function_call) ||\n typeof value.function_call.name !== \"string\" ||\n typeof value.function_call.arguments !== \"string\"\n ) {\n throw new Error('\"function_call\" parts expect an object with a \"function_call\" property.');\n }\n\n return {\n type: \"function_call\",\n value: value as unknown as { function_call: FunctionCall },\n };\n },\n};\n\nconst dataStreamPart: StreamPart<\"2\", \"data\", Array<JSONValue>> = {\n code: \"2\",\n name: \"data\",\n parse: (value: JSONValue) => {\n if (!Array.isArray(value)) {\n throw new Error('\"data\" parts expect an array value.');\n }\n\n return { type: \"data\", value };\n },\n};\n\nconst errorStreamPart: StreamPart<\"3\", \"error\", string> = {\n code: \"3\",\n name: \"error\",\n parse: (value: JSONValue) => {\n if (typeof value !== \"string\") {\n throw new Error('\"error\" parts expect a string value.');\n }\n return { type: \"error\", value };\n },\n};\n\nconst assistantMessage: StreamPart<\"4\", \"assistant_message\", AssistantMessage> = {\n code: \"4\",\n name: \"assistant_message\",\n parse: (value: JSONValue) => {\n if (\n value == null ||\n typeof value !== \"object\" ||\n !(\"id\" in value) ||\n !(\"role\" in value) ||\n !(\"content\" in value) ||\n typeof value.id !== \"string\" ||\n typeof value.role !== \"string\" ||\n value.role !== \"assistant\" ||\n !Array.isArray(value.content) ||\n !value.content.every(\n (item) =>\n item != null &&\n typeof item === \"object\" &&\n \"type\" in item &&\n item.type === \"text\" &&\n \"text\" in item &&\n item.text != null &&\n typeof item.text === \"object\" &&\n \"value\" in item.text &&\n typeof item.text.value === \"string\",\n )\n ) {\n throw new Error(\n '\"assistant_message\" parts expect an object with an \"id\", \"role\", and \"content\" property.',\n );\n }\n\n return {\n type: \"assistant_message\",\n value: value as AssistantMessage,\n };\n },\n};\n\nconst assistantControlData: StreamPart<\n \"5\",\n \"assistant_control_data\",\n {\n threadId: string;\n messageId: string;\n }\n> = {\n code: \"5\",\n name: \"assistant_control_data\",\n parse: (value: JSONValue) => {\n if (\n value == null ||\n typeof value !== \"object\" ||\n !(\"threadId\" in value) ||\n !(\"messageId\" in value) ||\n typeof value.threadId !== \"string\" ||\n typeof value.messageId !== \"string\"\n ) {\n throw new Error(\n '\"assistant_control_data\" parts expect an object with a \"threadId\" and \"messageId\" property.',\n );\n }\n\n return {\n type: \"assistant_control_data\",\n value: {\n threadId: value.threadId,\n messageId: value.messageId,\n },\n };\n },\n};\n\nconst streamParts = [\n textStreamPart,\n functionCallStreamPart,\n dataStreamPart,\n errorStreamPart,\n assistantMessage,\n assistantControlData,\n] as const;\n\n// union type of all stream parts\ntype StreamParts =\n | typeof textStreamPart\n | typeof functionCallStreamPart\n | typeof dataStreamPart\n | typeof errorStreamPart\n | typeof assistantMessage\n | typeof assistantControlData;\n\n/**\n * Maps the type of a stream part to its value type.\n */\ntype StreamPartValueType = {\n [P in StreamParts as P[\"name\"]]: ReturnType<P[\"parse\"]>[\"value\"];\n};\n\nexport type StreamPartType =\n | ReturnType<typeof textStreamPart.parse>\n | ReturnType<typeof functionCallStreamPart.parse>\n | ReturnType<typeof dataStreamPart.parse>\n | ReturnType<typeof errorStreamPart.parse>\n | ReturnType<typeof assistantMessage.parse>\n | ReturnType<typeof assistantControlData.parse>;\n\nexport const streamPartsByCode = {\n [textStreamPart.code]: textStreamPart,\n [functionCallStreamPart.code]: functionCallStreamPart,\n [dataStreamPart.code]: dataStreamPart,\n [errorStreamPart.code]: errorStreamPart,\n [assistantMessage.code]: assistantMessage,\n [assistantControlData.code]: assistantControlData,\n} as const;\n\n/**\n * The map of prefixes for data in the stream\n *\n * - 0: Text from the LLM response\n * - 1: (OpenAI) function_call responses\n * - 2: custom JSON added by the user using `Data`\n *\n * Example:\n * ```\n * 0:Vercel\n * 0:'s\n * 0: AI\n * 0: AI\n * 0: SDK\n * 0: is great\n * 0:!\n * 2: { \"someJson\": \"value\" }\n * 1: {\"function_call\": {\"name\": \"get_current_weather\", \"arguments\": \"{\\\\n\\\\\"location\\\\\": \\\\\"Charlottesville, Virginia\\\\\",\\\\n\\\\\"format\\\\\": \\\\\"celsius\\\\\"\\\\n}\"}}\n *```\n */\nexport const StreamStringPrefixes = {\n [textStreamPart.name]: textStreamPart.code,\n [functionCallStreamPart.name]: functionCallStreamPart.code,\n [dataStreamPart.name]: dataStreamPart.code,\n [errorStreamPart.name]: errorStreamPart.code,\n [assistantMessage.name]: assistantMessage.code,\n [assistantControlData.name]: assistantControlData.code,\n} as const;\n\nexport const validCodes = streamParts.map((part) => part.code);\n\n/**\n * Parses a stream part from a string.\n *\n * @param line The string to parse.\n * @returns The parsed stream part.\n * @throws An error if the string cannot be parsed.\n */\nexport const parseStreamPart = (line: string): StreamPartType => {\n const firstSeparatorIndex = line.indexOf(\":\");\n\n if (firstSeparatorIndex === -1) {\n throw new Error(\"Failed to parse stream string. No separator found.\");\n }\n\n const prefix = line.slice(0, firstSeparatorIndex);\n\n if (!validCodes.includes(prefix as keyof typeof streamPartsByCode)) {\n throw new Error(`Failed to parse stream string. Invalid code ${prefix}.`);\n }\n\n const code = prefix as keyof typeof streamPartsByCode;\n\n const textValue = line.slice(firstSeparatorIndex + 1);\n const jsonValue: JSONValue = JSON.parse(textValue);\n\n return streamPartsByCode[code].parse(jsonValue);\n};\n\n/**\n * Prepends a string with a prefix from the `StreamChunkPrefixes`, JSON-ifies it,\n * and appends a new line.\n *\n * It ensures type-safety for the part type and value.\n */\nexport function formatStreamPart<T extends keyof StreamPartValueType>(\n type: T,\n value: StreamPartValueType[T],\n): StreamString {\n const streamPart = streamParts.find((part) => part.name === type);\n\n if (!streamPart) {\n throw new Error(`Invalid stream part type: ${type}`);\n }\n\n return `${streamPart.code}:${JSON.stringify(value)}\\n`;\n}\n\nexport const isStreamStringEqualToType = (\n type: keyof typeof StreamStringPrefixes,\n value: string,\n): value is StreamString =>\n value.startsWith(`${StreamStringPrefixes[type]}:`) && value.endsWith(\"\\n\");\n\nexport type StreamString =\n `${typeof StreamStringPrefixes[keyof typeof StreamStringPrefixes]}:${string}\\n`;\n\n/**\n * A header sent to the client so it knows how to handle parsing the stream (as a deprecated text response or using the new prefixed protocol)\n */\nexport const COMPLEX_HEADER = \"X-Experimental-Stream-Data\";\n"],"mappings":";AAQA,IAAM,iBAAkD;AAAA,EACtD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO,CAAC,UAAqB;AAC3B,QAAI,OAAO,UAAU,UAAU;AAC7B,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACvD;AACA,WAAO,EAAE,MAAM,QAAQ,MAAM;AAAA,EAC/B;AACF;AASA,IAAM,yBAA4F;AAAA,EAChG,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO,CAAC,UAAqB;AAC3B,QACE,SAAS,QACT,OAAO,UAAU,YACjB,EAAE,mBAAmB,UACrB,OAAO,MAAM,kBAAkB,YAC/B,MAAM,iBAAiB,QACvB,EAAE,UAAU,MAAM,kBAClB,EAAE,eAAe,MAAM,kBACvB,OAAO,MAAM,cAAc,SAAS,YACpC,OAAO,MAAM,cAAc,cAAc,UACzC;AACA,YAAM,IAAI,MAAM,yEAAyE;AAAA,IAC3F;AAEA,WAAO;AAAA,MACL,MAAM;AAAA,MACN;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAM,i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,MAAM,sBAAsB,CAAC;AACpD,QAAM,YAAuB,KAAK,MAAM,SAAS;AAEjD,SAAO,kBAAkB,IAAI,EAAE,MAAM,SAAS;AAChD;AAQO,SAAS,iBACd,MACA,OACc;AACd,QAAM,aAAa,YAAY,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI;AAEhE,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,6BAA6B,MAAM;AAAA,EACrD;AAEA,SAAO,GAAG,WAAW,QAAQ,KAAK,UAAU,KAAK;AAAA;AACnD;AAEO,IAAM,4BAA4B,CACvC,MACA,UAEA,MAAM,WAAW,GAAG,qBAAqB,IAAI,IAAI,KAAK,MAAM,SAAS,IAAI;AAQpE,IAAM,iBAAiB;","names":[]}
@@ -1,3 +1 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
1
  //# sourceMappingURL=chunk-UAPRMZEY.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -54,6 +54,7 @@ function parseChatCompletion(stream) {
54
54
  });
55
55
  }
56
56
 
57
- export { parseChatCompletion };
58
- //# sourceMappingURL=out.js.map
57
+ export {
58
+ parseChatCompletion
59
+ };
59
60
  //# sourceMappingURL=chunk-W6NBBCWB.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/parse-chat-completion.ts"],"names":[],"mappings":";AAkBO,SAAS,oBACd,QACqC;AACrC,QAAM,SAAS,OAAO,UAAU;AAChC,MAAI,SAAS,IAAI,WAAW;AAE5B,iBAAe,QAAQ,YAAmD;AACxE,QAAI,YAAY;AACd,UAAI;AACF,mBAAW,MAAM;AAAA,MACnB,SAAS,GAAP;AAAA,MAAW;AAAA,IACf;AACA,QAAI,QAAQ;AACV,UAAI;AACF,cAAM,OAAO,OAAO;AAAA,MACtB,SAAS,GAAP;AAAA,MAAW;AAAA,IACf;AAAA,EACF;AAEA,SAAO,IAAI,eAAoC;AAAA,IAC7C,MAAM,KAAK,YAAY;AACrB,aAAO,MAAM;AACX,YAAI;AACF,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAE1C,cAAI,MAAM;AACR,kBAAM,QAAQ,UAAU;AACxB;AAAA,UACF;AAEA,gBAAM,YAAY,IAAI,WAAW,OAAO,SAAS,MAAM,MAAM;AAC7D,oBAAU,IAAI,MAAM;AACpB,oBAAU,IAAI,OAAO,OAAO,MAAM;AAClC,mBAAS;AAET,gBAAM,cAAc,IAAI,YAAY,OAAO,EAAE,OAAO,MAAM;AAC1D,gBAAM,QAAQ,YAAY,MAAM,IAAI,EAAE,OAAO,CAAC,SAAS,KAAK,KAAK,MAAM,EAAE;AAGzE,mBAAS,CAAC,YAAY,SAAS,IAAI,IAC/B,IAAI,YAAY,EAAE,OAAO,MAAM,IAAI,KAAK,EAAE,IAC1C,IAAI,WAAW;AAEnB,qBAAW,QAAQ,OAAO;AACxB,kBAAM,cAAc,KAAK,QAAQ,WAAW,EAAE;AAE9C,gBAAI,gBAAgB,UAAU;AAC5B,oBAAM,QAAQ,UAAU;AACxB;AAAA,YACF;AAEA,kBAAM,OAAO,KAAK,MAAM,WAAW;AACnC,uBAAW,QAAQ,IAAI;AAAA,UACzB;AAAA,QACF,SAAS,OAAP;AACA,qBAAW,MAAM,KAAK;AACtB,gBAAM,QAAQ,UAAU;AACxB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,OAAO;AAAA,IAChB;AAAA,EACF,CAAC;AACH","sourcesContent":["import { Role } from \"../types/openai-assistant\";\n\nexport interface ChatCompletionChunk {\n choices: {\n delta: {\n role: Role;\n content?: string | null;\n function_call?: {\n name?: string;\n arguments?: string;\n };\n };\n }[];\n}\n\n// TODO:\n// it's possible that unicode characters could be split across chunks\n// make sure to properly handle that\nexport function parseChatCompletion(\n stream: ReadableStream<Uint8Array>,\n): ReadableStream<ChatCompletionChunk> {\n const reader = stream.getReader();\n let buffer = new Uint8Array();\n\n async function cleanup(controller?: ReadableStreamDefaultController<any>) {\n if (controller) {\n try {\n controller.close();\n } catch (_) {}\n }\n if (reader) {\n try {\n await reader.cancel();\n } catch (_) {}\n }\n }\n\n return new ReadableStream<ChatCompletionChunk>({\n async pull(controller) {\n while (true) {\n try {\n const { done, value } = await reader.read();\n\n if (done) {\n await cleanup(controller);\n return;\n }\n\n const newBuffer = new Uint8Array(buffer.length + value.length);\n newBuffer.set(buffer);\n newBuffer.set(value, buffer.length);\n buffer = newBuffer;\n\n const valueString = new TextDecoder(\"utf-8\").decode(buffer);\n const lines = valueString.split(\"\\n\").filter((line) => line.trim() !== \"\");\n\n // If the last line isn't complete, keep it in the buffer for next time\n buffer = !valueString.endsWith(\"\\n\")\n ? new TextEncoder().encode(lines.pop() || \"\")\n : new Uint8Array();\n\n for (const line of lines) {\n const cleanedLine = line.replace(/^data: /, \"\");\n\n if (cleanedLine === \"[DONE]\") {\n await cleanup(controller);\n return;\n }\n\n const json = JSON.parse(cleanedLine);\n controller.enqueue(json);\n }\n } catch (error) {\n controller.error(error);\n await cleanup(controller);\n return;\n }\n }\n },\n cancel() {\n reader.cancel();\n },\n });\n}\n"]}
1
+ {"version":3,"sources":["../src/utils/parse-chat-completion.ts"],"sourcesContent":["import { Role } from \"../types/openai-assistant\";\n\nexport interface ChatCompletionChunk {\n choices: {\n delta: {\n role: Role;\n content?: string | null;\n function_call?: {\n name?: string;\n arguments?: string;\n };\n };\n }[];\n}\n\n// TODO:\n// it's possible that unicode characters could be split across chunks\n// make sure to properly handle that\nexport function parseChatCompletion(\n stream: ReadableStream<Uint8Array>,\n): ReadableStream<ChatCompletionChunk> {\n const reader = stream.getReader();\n let buffer = new Uint8Array();\n\n async function cleanup(controller?: ReadableStreamDefaultController<any>) {\n if (controller) {\n try {\n controller.close();\n } catch (_) {}\n }\n if (reader) {\n try {\n await reader.cancel();\n } catch (_) {}\n }\n }\n\n return new ReadableStream<ChatCompletionChunk>({\n async pull(controller) {\n while (true) {\n try {\n const { done, value } = await reader.read();\n\n if (done) {\n await cleanup(controller);\n return;\n }\n\n const newBuffer = new Uint8Array(buffer.length + value.length);\n newBuffer.set(buffer);\n newBuffer.set(value, buffer.length);\n buffer = newBuffer;\n\n const valueString = new TextDecoder(\"utf-8\").decode(buffer);\n const lines = valueString.split(\"\\n\").filter((line) => line.trim() !== \"\");\n\n // If the last line isn't complete, keep it in the buffer for next time\n buffer = !valueString.endsWith(\"\\n\")\n ? new TextEncoder().encode(lines.pop() || \"\")\n : new Uint8Array();\n\n for (const line of lines) {\n const cleanedLine = line.replace(/^data: /, \"\");\n\n if (cleanedLine === \"[DONE]\") {\n await cleanup(controller);\n return;\n }\n\n const json = JSON.parse(cleanedLine);\n controller.enqueue(json);\n }\n } catch (error) {\n controller.error(error);\n await cleanup(controller);\n return;\n }\n }\n },\n cancel() {\n reader.cancel();\n },\n });\n}\n"],"mappings":";AAkBO,SAAS,oBACd,QACqC;AACrC,QAAM,SAAS,OAAO,UAAU;AAChC,MAAI,SAAS,IAAI,WAAW;AAE5B,iBAAe,QAAQ,YAAmD;AACxE,QAAI,YAAY;AACd,UAAI;AACF,mBAAW,MAAM;AAAA,MACnB,SAAS,GAAP;AAAA,MAAW;AAAA,IACf;AACA,QAAI,QAAQ;AACV,UAAI;AACF,cAAM,OAAO,OAAO;AAAA,MACtB,SAAS,GAAP;AAAA,MAAW;AAAA,IACf;AAAA,EACF;AAEA,SAAO,IAAI,eAAoC;AAAA,IAC7C,MAAM,KAAK,YAAY;AACrB,aAAO,MAAM;AACX,YAAI;AACF,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAE1C,cAAI,MAAM;AACR,kBAAM,QAAQ,UAAU;AACxB;AAAA,UACF;AAEA,gBAAM,YAAY,IAAI,WAAW,OAAO,SAAS,MAAM,MAAM;AAC7D,oBAAU,IAAI,MAAM;AACpB,oBAAU,IAAI,OAAO,OAAO,MAAM;AAClC,mBAAS;AAET,gBAAM,cAAc,IAAI,YAAY,OAAO,EAAE,OAAO,MAAM;AAC1D,gBAAM,QAAQ,YAAY,MAAM,IAAI,EAAE,OAAO,CAAC,SAAS,KAAK,KAAK,MAAM,EAAE;AAGzE,mBAAS,CAAC,YAAY,SAAS,IAAI,IAC/B,IAAI,YAAY,EAAE,OAAO,MAAM,IAAI,KAAK,EAAE,IAC1C,IAAI,WAAW;AAEnB,qBAAW,QAAQ,OAAO;AACxB,kBAAM,cAAc,KAAK,QAAQ,WAAW,EAAE;AAE9C,gBAAI,gBAAgB,UAAU;AAC5B,oBAAM,QAAQ,UAAU;AACxB;AAAA,YACF;AAEA,kBAAM,OAAO,KAAK,MAAM,WAAW;AACnC,uBAAW,QAAQ,IAAI;AAAA,UACzB;AAAA,QACF,SAAS,OAAP;AACA,qBAAW,MAAM,KAAK;AACtB,gBAAM,QAAQ,UAAU;AACxB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,OAAO;AAAA,IAChB;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1,3 +1 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
1
  //# sourceMappingURL=chunk-YBHX4Y25.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/index.js CHANGED
@@ -1,4 +1,38 @@
1
- 'use strict';
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
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ COMPLEX_HEADER: () => COMPLEX_HEADER,
24
+ StreamStringPrefixes: () => StreamStringPrefixes,
25
+ annotatedFunctionToChatCompletionFunction: () => annotatedFunctionToChatCompletionFunction,
26
+ decodeChatCompletion: () => decodeChatCompletion,
27
+ decodeChatCompletionAsText: () => decodeChatCompletionAsText,
28
+ formatStreamPart: () => formatStreamPart,
29
+ isStreamStringEqualToType: () => isStreamStringEqualToType,
30
+ parseChatCompletion: () => parseChatCompletion,
31
+ parseStreamPart: () => parseStreamPart,
32
+ streamPartsByCode: () => streamPartsByCode,
33
+ validCodes: () => validCodes
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
2
36
 
3
37
  // src/utils/utils.ts
4
38
  var textStreamPart = {
@@ -329,17 +363,18 @@ function annotatedFunctionToChatCompletionFunction(annotatedFunction) {
329
363
  };
330
364
  return chatCompletionFunction;
331
365
  }
332
-
333
- exports.COMPLEX_HEADER = COMPLEX_HEADER;
334
- exports.StreamStringPrefixes = StreamStringPrefixes;
335
- exports.annotatedFunctionToChatCompletionFunction = annotatedFunctionToChatCompletionFunction;
336
- exports.decodeChatCompletion = decodeChatCompletion;
337
- exports.decodeChatCompletionAsText = decodeChatCompletionAsText;
338
- exports.formatStreamPart = formatStreamPart;
339
- exports.isStreamStringEqualToType = isStreamStringEqualToType;
340
- exports.parseChatCompletion = parseChatCompletion;
341
- exports.parseStreamPart = parseStreamPart;
342
- exports.streamPartsByCode = streamPartsByCode;
343
- exports.validCodes = validCodes;
344
- //# sourceMappingURL=out.js.map
366
+ // Annotate the CommonJS export names for ESM import in node:
367
+ 0 && (module.exports = {
368
+ COMPLEX_HEADER,
369
+ StreamStringPrefixes,
370
+ annotatedFunctionToChatCompletionFunction,
371
+ decodeChatCompletion,
372
+ decodeChatCompletionAsText,
373
+ formatStreamPart,
374
+ isStreamStringEqualToType,
375
+ parseChatCompletion,
376
+ parseStreamPart,
377
+ streamPartsByCode,
378
+ validCodes
379
+ });
345
380
  //# sourceMappingURL=index.js.map