@langchain/langgraph-sdk 0.1.10 → 1.0.1

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 (235) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +11 -0
  3. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  4. package/dist/auth/error.cjs +76 -86
  5. package/dist/auth/error.cjs.map +1 -0
  6. package/dist/auth/error.d.cts +13 -0
  7. package/dist/auth/error.d.cts.map +1 -0
  8. package/dist/auth/error.d.ts +12 -8
  9. package/dist/auth/error.d.ts.map +1 -0
  10. package/dist/auth/error.js +76 -83
  11. package/dist/auth/error.js.map +1 -0
  12. package/dist/auth/index.cjs +36 -44
  13. package/dist/auth/index.cjs.map +1 -0
  14. package/dist/auth/index.d.cts +31 -0
  15. package/dist/auth/index.d.cts.map +1 -0
  16. package/dist/auth/index.d.ts +20 -15
  17. package/dist/auth/index.d.ts.map +1 -0
  18. package/dist/auth/index.js +35 -39
  19. package/dist/auth/index.js.map +1 -0
  20. package/dist/auth/types.d.cts +294 -0
  21. package/dist/auth/types.d.cts.map +1 -0
  22. package/dist/auth/types.d.ts +162 -165
  23. package/dist/auth/types.d.ts.map +1 -0
  24. package/dist/client.cjs +1110 -1294
  25. package/dist/client.cjs.map +1 -0
  26. package/dist/client.d.cts +697 -0
  27. package/dist/client.d.cts.map +1 -0
  28. package/dist/client.d.ts +656 -639
  29. package/dist/client.d.ts.map +1 -0
  30. package/dist/client.js +1101 -1281
  31. package/dist/client.js.map +1 -0
  32. package/dist/index.cjs +6 -8
  33. package/dist/index.d.cts +7 -0
  34. package/dist/index.d.ts +7 -7
  35. package/dist/index.js +4 -2
  36. package/dist/logging/index.cjs +30 -31
  37. package/dist/logging/index.cjs.map +1 -0
  38. package/dist/logging/index.d.cts +47 -0
  39. package/dist/logging/index.d.cts.map +1 -0
  40. package/dist/logging/index.d.ts +20 -16
  41. package/dist/logging/index.d.ts.map +1 -0
  42. package/dist/logging/index.js +31 -29
  43. package/dist/logging/index.js.map +1 -0
  44. package/dist/react/index.cjs +5 -7
  45. package/dist/react/index.d.cts +4 -0
  46. package/dist/react/index.d.ts +4 -3
  47. package/dist/react/index.js +4 -2
  48. package/dist/react/stream.cjs +14 -15
  49. package/dist/react/stream.cjs.map +1 -0
  50. package/dist/react/stream.custom.cjs +126 -145
  51. package/dist/react/stream.custom.cjs.map +1 -0
  52. package/dist/react/stream.custom.d.cts +39 -0
  53. package/dist/react/stream.custom.d.cts.map +1 -0
  54. package/dist/react/stream.custom.d.ts +35 -37
  55. package/dist/react/stream.custom.d.ts.map +1 -0
  56. package/dist/react/stream.custom.js +122 -137
  57. package/dist/react/stream.custom.js.map +1 -0
  58. package/dist/react/stream.d.cts +73 -0
  59. package/dist/react/stream.d.cts.map +1 -0
  60. package/dist/react/stream.d.ts +21 -15
  61. package/dist/react/stream.d.ts.map +1 -0
  62. package/dist/react/stream.js +12 -11
  63. package/dist/react/stream.js.map +1 -0
  64. package/dist/react/stream.lgp.cjs +438 -498
  65. package/dist/react/stream.lgp.cjs.map +1 -0
  66. package/dist/react/stream.lgp.js +433 -490
  67. package/dist/react/stream.lgp.js.map +1 -0
  68. package/dist/react/thread.cjs +18 -15
  69. package/dist/react/thread.cjs.map +1 -0
  70. package/dist/react/thread.js +19 -13
  71. package/dist/react/thread.js.map +1 -0
  72. package/dist/react/types.d.cts +356 -0
  73. package/dist/react/types.d.cts.map +1 -0
  74. package/dist/react/types.d.ts +334 -329
  75. package/dist/react/types.d.ts.map +1 -0
  76. package/dist/react-ui/client.cjs +123 -184
  77. package/dist/react-ui/client.cjs.map +1 -0
  78. package/dist/react-ui/client.d.cts +90 -0
  79. package/dist/react-ui/client.d.cts.map +1 -0
  80. package/dist/react-ui/client.d.ts +67 -51
  81. package/dist/react-ui/client.d.ts.map +1 -0
  82. package/dist/react-ui/client.js +118 -143
  83. package/dist/react-ui/client.js.map +1 -0
  84. package/dist/react-ui/index.cjs +14 -13
  85. package/dist/react-ui/index.cjs.map +1 -0
  86. package/dist/react-ui/index.d.cts +3 -0
  87. package/dist/react-ui/index.d.ts +3 -2
  88. package/dist/react-ui/index.js +8 -3
  89. package/dist/react-ui/index.js.map +1 -0
  90. package/dist/react-ui/server/index.cjs +5 -7
  91. package/dist/react-ui/server/index.d.cts +3 -0
  92. package/dist/react-ui/server/index.d.ts +3 -2
  93. package/dist/react-ui/server/index.js +4 -2
  94. package/dist/react-ui/server/server.cjs +53 -44
  95. package/dist/react-ui/server/server.cjs.map +1 -0
  96. package/dist/react-ui/server/server.d.cts +55 -0
  97. package/dist/react-ui/server/server.d.cts.map +1 -0
  98. package/dist/react-ui/server/server.d.ts +43 -39
  99. package/dist/react-ui/server/server.d.ts.map +1 -0
  100. package/dist/react-ui/server/server.js +54 -42
  101. package/dist/react-ui/server/server.js.map +1 -0
  102. package/dist/react-ui/types.cjs +32 -36
  103. package/dist/react-ui/types.cjs.map +1 -0
  104. package/dist/react-ui/types.d.cts +25 -0
  105. package/dist/react-ui/types.d.cts.map +1 -0
  106. package/dist/react-ui/types.d.ts +23 -19
  107. package/dist/react-ui/types.d.ts.map +1 -0
  108. package/dist/react-ui/types.js +32 -34
  109. package/dist/react-ui/types.js.map +1 -0
  110. package/dist/schema.d.cts +278 -0
  111. package/dist/schema.d.cts.map +1 -0
  112. package/dist/schema.d.ts +250 -242
  113. package/dist/schema.d.ts.map +1 -0
  114. package/dist/singletons/fetch.cjs +16 -20
  115. package/dist/singletons/fetch.cjs.map +1 -0
  116. package/dist/singletons/fetch.d.cts +14 -0
  117. package/dist/singletons/fetch.d.cts.map +1 -0
  118. package/dist/singletons/fetch.d.ts +5 -2
  119. package/dist/singletons/fetch.d.ts.map +1 -0
  120. package/dist/singletons/fetch.js +16 -17
  121. package/dist/singletons/fetch.js.map +1 -0
  122. package/dist/types.d.cts +187 -0
  123. package/dist/types.d.cts.map +1 -0
  124. package/dist/types.d.ts +178 -173
  125. package/dist/types.d.ts.map +1 -0
  126. package/dist/types.messages.d.cts +91 -0
  127. package/dist/types.messages.d.cts.map +1 -0
  128. package/dist/types.messages.d.ts +71 -66
  129. package/dist/types.messages.d.ts.map +1 -0
  130. package/dist/types.stream.d.cts +235 -0
  131. package/dist/types.stream.d.cts.map +1 -0
  132. package/dist/types.stream.d.ts +149 -142
  133. package/dist/types.stream.d.ts.map +1 -0
  134. package/dist/ui/branching.cjs +145 -141
  135. package/dist/ui/branching.cjs.map +1 -0
  136. package/dist/ui/branching.d.cts +22 -0
  137. package/dist/ui/branching.d.cts.map +1 -0
  138. package/dist/ui/branching.d.ts +17 -30
  139. package/dist/ui/branching.d.ts.map +1 -0
  140. package/dist/ui/branching.js +147 -139
  141. package/dist/ui/branching.js.map +1 -0
  142. package/dist/ui/errors.cjs +14 -12
  143. package/dist/ui/errors.cjs.map +1 -0
  144. package/dist/ui/errors.js +14 -9
  145. package/dist/ui/errors.js.map +1 -0
  146. package/dist/ui/manager.cjs +156 -232
  147. package/dist/ui/manager.cjs.map +1 -0
  148. package/dist/ui/manager.js +156 -228
  149. package/dist/ui/manager.js.map +1 -0
  150. package/dist/ui/messages.cjs +55 -69
  151. package/dist/ui/messages.cjs.map +1 -0
  152. package/dist/ui/messages.js +55 -66
  153. package/dist/ui/messages.js.map +1 -0
  154. package/dist/ui/utils.cjs +10 -10
  155. package/dist/ui/utils.cjs.map +1 -0
  156. package/dist/ui/utils.js +10 -8
  157. package/dist/ui/utils.js.map +1 -0
  158. package/dist/utils/async_caller.cjs +103 -185
  159. package/dist/utils/async_caller.cjs.map +1 -0
  160. package/dist/utils/async_caller.d.cts +53 -0
  161. package/dist/utils/async_caller.d.cts.map +1 -0
  162. package/dist/utils/async_caller.d.ts +36 -31
  163. package/dist/utils/async_caller.d.ts.map +1 -0
  164. package/dist/utils/async_caller.js +101 -177
  165. package/dist/utils/async_caller.js.map +1 -0
  166. package/dist/utils/env.cjs +11 -13
  167. package/dist/utils/env.cjs.map +1 -0
  168. package/dist/utils/env.js +11 -11
  169. package/dist/utils/env.js.map +1 -0
  170. package/dist/utils/signals.cjs +18 -19
  171. package/dist/utils/signals.cjs.map +1 -0
  172. package/dist/utils/signals.js +18 -17
  173. package/dist/utils/signals.js.map +1 -0
  174. package/dist/utils/sse.cjs +110 -140
  175. package/dist/utils/sse.cjs.map +1 -0
  176. package/dist/utils/sse.js +110 -138
  177. package/dist/utils/sse.js.map +1 -0
  178. package/dist/utils/stream.cjs +90 -114
  179. package/dist/utils/stream.cjs.map +1 -0
  180. package/dist/utils/stream.js +90 -111
  181. package/dist/utils/stream.js.map +1 -0
  182. package/package.json +73 -81
  183. package/auth.cjs +0 -1
  184. package/auth.d.cts +0 -1
  185. package/auth.d.ts +0 -1
  186. package/auth.js +0 -1
  187. package/client.cjs +0 -1
  188. package/client.d.cts +0 -1
  189. package/client.d.ts +0 -1
  190. package/client.js +0 -1
  191. package/dist/auth/types.cjs +0 -2
  192. package/dist/auth/types.js +0 -1
  193. package/dist/react/stream.lgp.d.ts +0 -7
  194. package/dist/react/thread.d.ts +0 -4
  195. package/dist/react/types.cjs +0 -2
  196. package/dist/react/types.js +0 -1
  197. package/dist/schema.cjs +0 -2
  198. package/dist/schema.js +0 -1
  199. package/dist/types.cjs +0 -2
  200. package/dist/types.js +0 -1
  201. package/dist/types.messages.cjs +0 -2
  202. package/dist/types.messages.js +0 -1
  203. package/dist/types.stream.cjs +0 -2
  204. package/dist/types.stream.js +0 -1
  205. package/dist/ui/branching.test.cjs +0 -370
  206. package/dist/ui/branching.test.d.ts +0 -1
  207. package/dist/ui/branching.test.js +0 -368
  208. package/dist/ui/errors.d.ts +0 -12
  209. package/dist/ui/manager.d.ts +0 -87
  210. package/dist/ui/messages.d.ts +0 -18
  211. package/dist/ui/utils.d.ts +0 -2
  212. package/dist/utils/env.d.ts +0 -1
  213. package/dist/utils/signals.d.ts +0 -1
  214. package/dist/utils/sse.d.ts +0 -8
  215. package/dist/utils/stream.d.ts +0 -13
  216. package/index.cjs +0 -1
  217. package/index.d.cts +0 -1
  218. package/index.d.ts +0 -1
  219. package/index.js +0 -1
  220. package/logging.cjs +0 -1
  221. package/logging.d.cts +0 -1
  222. package/logging.d.ts +0 -1
  223. package/logging.js +0 -1
  224. package/react-ui/server.cjs +0 -1
  225. package/react-ui/server.d.cts +0 -1
  226. package/react-ui/server.d.ts +0 -1
  227. package/react-ui/server.js +0 -1
  228. package/react-ui.cjs +0 -1
  229. package/react-ui.d.cts +0 -1
  230. package/react-ui.d.ts +0 -1
  231. package/react-ui.js +0 -1
  232. package/react.cjs +0 -1
  233. package/react.d.cts +0 -1
  234. package/react.d.ts +0 -1
  235. package/react.js +0 -1
@@ -1,115 +1,91 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IterableReadableStream = void 0;
4
- /*
5
- * Support async iterator syntax for ReadableStreams in all environments.
6
- * Source: https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
7
- */
8
- class IterableReadableStream extends ReadableStream {
9
- constructor() {
10
- super(...arguments);
11
- Object.defineProperty(this, "reader", {
12
- enumerable: true,
13
- configurable: true,
14
- writable: true,
15
- value: void 0
16
- });
17
- }
18
- ensureReader() {
19
- if (!this.reader) {
20
- this.reader = this.getReader();
21
- }
22
- }
23
- async next() {
24
- this.ensureReader();
25
- try {
26
- const result = await this.reader.read();
27
- if (result.done) {
28
- this.reader.releaseLock(); // release lock when stream becomes closed
29
- return {
30
- done: true,
31
- value: undefined,
32
- };
33
- }
34
- else {
35
- return {
36
- done: false,
37
- value: result.value,
38
- };
39
- }
40
- }
41
- catch (e) {
42
- this.reader.releaseLock(); // release lock when stream becomes errored
43
- throw e;
44
- }
45
- }
46
- async return() {
47
- this.ensureReader();
48
- // If wrapped in a Node stream, cancel is already called.
49
- if (this.locked) {
50
- const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet
51
- this.reader.releaseLock(); // release lock first
52
- await cancelPromise; // now await it
53
- }
54
- return { done: true, value: undefined };
55
- }
56
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
- async throw(e) {
58
- this.ensureReader();
59
- if (this.locked) {
60
- const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet
61
- this.reader.releaseLock(); // release lock first
62
- await cancelPromise; // now await it
63
- }
64
- throw e;
65
- }
66
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
67
- // @ts-ignore Not present in Node 18 types, required in latest Node 22
68
- async [Symbol.asyncDispose]() {
69
- await this.return();
70
- }
71
- [Symbol.asyncIterator]() {
72
- return this;
73
- }
74
- static fromReadableStream(stream) {
75
- // From https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams#reading_the_stream
76
- const reader = stream.getReader();
77
- return new IterableReadableStream({
78
- start(controller) {
79
- return pump();
80
- function pump() {
81
- return reader.read().then(({ done, value }) => {
82
- // When no more data needs to be consumed, close the stream
83
- if (done) {
84
- controller.close();
85
- return;
86
- }
87
- // Enqueue the next data chunk into our target stream
88
- controller.enqueue(value);
89
- return pump();
90
- });
91
- }
92
- },
93
- cancel() {
94
- reader.releaseLock();
95
- },
96
- });
97
- }
98
- static fromAsyncGenerator(generator) {
99
- return new IterableReadableStream({
100
- async pull(controller) {
101
- const { value, done } = await generator.next();
102
- // When no more data needs to be consumed, close the stream
103
- if (done) {
104
- controller.close();
105
- }
106
- // Fix: `else if (value)` will hang the streaming when nullish value (e.g. empty string) is pulled
107
- controller.enqueue(value);
108
- },
109
- async cancel(reason) {
110
- await generator.return(reason);
111
- },
112
- });
113
- }
114
- }
1
+
2
+ //#region src/utils/stream.ts
3
+ var IterableReadableStream = class IterableReadableStream extends ReadableStream {
4
+ reader;
5
+ ensureReader() {
6
+ if (!this.reader) this.reader = this.getReader();
7
+ }
8
+ async next() {
9
+ this.ensureReader();
10
+ try {
11
+ const result = await this.reader.read();
12
+ if (result.done) {
13
+ this.reader.releaseLock();
14
+ return {
15
+ done: true,
16
+ value: void 0
17
+ };
18
+ } else return {
19
+ done: false,
20
+ value: result.value
21
+ };
22
+ } catch (e) {
23
+ this.reader.releaseLock();
24
+ throw e;
25
+ }
26
+ }
27
+ async return() {
28
+ this.ensureReader();
29
+ if (this.locked) {
30
+ const cancelPromise = this.reader.cancel();
31
+ this.reader.releaseLock();
32
+ await cancelPromise;
33
+ }
34
+ return {
35
+ done: true,
36
+ value: void 0
37
+ };
38
+ }
39
+ async throw(e) {
40
+ this.ensureReader();
41
+ if (this.locked) {
42
+ const cancelPromise = this.reader.cancel();
43
+ this.reader.releaseLock();
44
+ await cancelPromise;
45
+ }
46
+ throw e;
47
+ }
48
+ async [Symbol.asyncDispose]() {
49
+ await this.return();
50
+ }
51
+ [Symbol.asyncIterator]() {
52
+ return this;
53
+ }
54
+ static fromReadableStream(stream) {
55
+ const reader = stream.getReader();
56
+ return new IterableReadableStream({
57
+ start(controller) {
58
+ return pump();
59
+ function pump() {
60
+ return reader.read().then(({ done, value }) => {
61
+ if (done) {
62
+ controller.close();
63
+ return;
64
+ }
65
+ controller.enqueue(value);
66
+ return pump();
67
+ });
68
+ }
69
+ },
70
+ cancel() {
71
+ reader.releaseLock();
72
+ }
73
+ });
74
+ }
75
+ static fromAsyncGenerator(generator) {
76
+ return new IterableReadableStream({
77
+ async pull(controller) {
78
+ const { value, done } = await generator.next();
79
+ if (done) controller.close();
80
+ controller.enqueue(value);
81
+ },
82
+ async cancel(reason) {
83
+ await generator.return(reason);
84
+ }
85
+ });
86
+ }
87
+ };
88
+
89
+ //#endregion
115
90
  exports.IterableReadableStream = IterableReadableStream;
91
+ //# sourceMappingURL=stream.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.cjs","names":[],"sources":["../../src/utils/stream.ts"],"sourcesContent":["// in this case don't quite match.\ntype IterableReadableStreamInterface<T> = ReadableStream<T> & AsyncIterable<T>;\n\n/*\n * Support async iterator syntax for ReadableStreams in all environments.\n * Source: https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490\n */\nexport class IterableReadableStream<T>\n extends ReadableStream<T>\n implements IterableReadableStreamInterface<T>\n{\n public reader: ReadableStreamDefaultReader<T>;\n\n ensureReader() {\n if (!this.reader) {\n this.reader = this.getReader();\n }\n }\n\n async next(): Promise<IteratorResult<T>> {\n this.ensureReader();\n try {\n const result = await this.reader.read();\n if (result.done) {\n this.reader.releaseLock(); // release lock when stream becomes closed\n return {\n done: true,\n value: undefined,\n };\n } else {\n return {\n done: false,\n value: result.value,\n };\n }\n } catch (e) {\n this.reader.releaseLock(); // release lock when stream becomes errored\n throw e;\n }\n }\n\n async return(): Promise<IteratorResult<T>> {\n this.ensureReader();\n // If wrapped in a Node stream, cancel is already called.\n if (this.locked) {\n const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet\n this.reader.releaseLock(); // release lock first\n await cancelPromise; // now await it\n }\n return { done: true, value: undefined };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async throw(e: any): Promise<IteratorResult<T>> {\n this.ensureReader();\n if (this.locked) {\n const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet\n this.reader.releaseLock(); // release lock first\n await cancelPromise; // now await it\n }\n throw e;\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore Not present in Node 18 types, required in latest Node 22\n async [Symbol.asyncDispose]() {\n await this.return();\n }\n\n [Symbol.asyncIterator]() {\n return this;\n }\n\n static fromReadableStream<T>(stream: ReadableStream<T>) {\n // From https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams#reading_the_stream\n const reader = stream.getReader();\n return new IterableReadableStream<T>({\n start(controller) {\n return pump();\n function pump(): Promise<T | undefined> {\n return reader.read().then(({ done, value }) => {\n // When no more data needs to be consumed, close the stream\n if (done) {\n controller.close();\n return;\n }\n // Enqueue the next data chunk into our target stream\n controller.enqueue(value);\n return pump();\n });\n }\n },\n cancel() {\n reader.releaseLock();\n },\n });\n }\n\n static fromAsyncGenerator<T>(generator: AsyncGenerator<T>) {\n return new IterableReadableStream<T>({\n async pull(controller) {\n const { value, done } = await generator.next();\n // When no more data needs to be consumed, close the stream\n if (done) {\n controller.close();\n }\n // Fix: `else if (value)` will hang the streaming when nullish value (e.g. empty string) is pulled\n controller.enqueue(value);\n },\n async cancel(reason) {\n await generator.return(reason);\n },\n });\n }\n}\n"],"mappings":";;AAOA,IAAa,yBAAb,MAAa,+BACH,eAEV;CACE,AAAO;CAEP,eAAe;AACb,MAAI,CAAC,KAAK,OACR,MAAK,SAAS,KAAK;;CAIvB,MAAM,OAAmC;AACvC,OAAK;AACL,MAAI;GACF,MAAM,SAAS,MAAM,KAAK,OAAO;AACjC,OAAI,OAAO,MAAM;AACf,SAAK,OAAO;AACZ,WAAO;KACL,MAAM;KACN,OAAO;;SAGT,QAAO;IACL,MAAM;IACN,OAAO,OAAO;;WAGX,GAAG;AACV,QAAK,OAAO;AACZ,SAAM;;;CAIV,MAAM,SAAqC;AACzC,OAAK;AAEL,MAAI,KAAK,QAAQ;GACf,MAAM,gBAAgB,KAAK,OAAO;AAClC,QAAK,OAAO;AACZ,SAAM;;AAER,SAAO;GAAE,MAAM;GAAM,OAAO;;;CAI9B,MAAM,MAAM,GAAoC;AAC9C,OAAK;AACL,MAAI,KAAK,QAAQ;GACf,MAAM,gBAAgB,KAAK,OAAO;AAClC,QAAK,OAAO;AACZ,SAAM;;AAER,QAAM;;CAKR,OAAO,OAAO,gBAAgB;AAC5B,QAAM,KAAK;;CAGb,CAAC,OAAO,iBAAiB;AACvB,SAAO;;CAGT,OAAO,mBAAsB,QAA2B;EAEtD,MAAM,SAAS,OAAO;AACtB,SAAO,IAAI,uBAA0B;GACnC,MAAM,YAAY;AAChB,WAAO;IACP,SAAS,OAA+B;AACtC,YAAO,OAAO,OAAO,MAAM,EAAE,MAAM,YAAY;AAE7C,UAAI,MAAM;AACR,kBAAW;AACX;;AAGF,iBAAW,QAAQ;AACnB,aAAO;;;;GAIb,SAAS;AACP,WAAO;;;;CAKb,OAAO,mBAAsB,WAA8B;AACzD,SAAO,IAAI,uBAA0B;GACnC,MAAM,KAAK,YAAY;IACrB,MAAM,EAAE,OAAO,SAAS,MAAM,UAAU;AAExC,QAAI,KACF,YAAW;AAGb,eAAW,QAAQ;;GAErB,MAAM,OAAO,QAAQ;AACnB,UAAM,UAAU,OAAO"}
@@ -1,111 +1,90 @@
1
- /*
2
- * Support async iterator syntax for ReadableStreams in all environments.
3
- * Source: https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
4
- */
5
- export class IterableReadableStream extends ReadableStream {
6
- constructor() {
7
- super(...arguments);
8
- Object.defineProperty(this, "reader", {
9
- enumerable: true,
10
- configurable: true,
11
- writable: true,
12
- value: void 0
13
- });
14
- }
15
- ensureReader() {
16
- if (!this.reader) {
17
- this.reader = this.getReader();
18
- }
19
- }
20
- async next() {
21
- this.ensureReader();
22
- try {
23
- const result = await this.reader.read();
24
- if (result.done) {
25
- this.reader.releaseLock(); // release lock when stream becomes closed
26
- return {
27
- done: true,
28
- value: undefined,
29
- };
30
- }
31
- else {
32
- return {
33
- done: false,
34
- value: result.value,
35
- };
36
- }
37
- }
38
- catch (e) {
39
- this.reader.releaseLock(); // release lock when stream becomes errored
40
- throw e;
41
- }
42
- }
43
- async return() {
44
- this.ensureReader();
45
- // If wrapped in a Node stream, cancel is already called.
46
- if (this.locked) {
47
- const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet
48
- this.reader.releaseLock(); // release lock first
49
- await cancelPromise; // now await it
50
- }
51
- return { done: true, value: undefined };
52
- }
53
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
- async throw(e) {
55
- this.ensureReader();
56
- if (this.locked) {
57
- const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet
58
- this.reader.releaseLock(); // release lock first
59
- await cancelPromise; // now await it
60
- }
61
- throw e;
62
- }
63
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
64
- // @ts-ignore Not present in Node 18 types, required in latest Node 22
65
- async [Symbol.asyncDispose]() {
66
- await this.return();
67
- }
68
- [Symbol.asyncIterator]() {
69
- return this;
70
- }
71
- static fromReadableStream(stream) {
72
- // From https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams#reading_the_stream
73
- const reader = stream.getReader();
74
- return new IterableReadableStream({
75
- start(controller) {
76
- return pump();
77
- function pump() {
78
- return reader.read().then(({ done, value }) => {
79
- // When no more data needs to be consumed, close the stream
80
- if (done) {
81
- controller.close();
82
- return;
83
- }
84
- // Enqueue the next data chunk into our target stream
85
- controller.enqueue(value);
86
- return pump();
87
- });
88
- }
89
- },
90
- cancel() {
91
- reader.releaseLock();
92
- },
93
- });
94
- }
95
- static fromAsyncGenerator(generator) {
96
- return new IterableReadableStream({
97
- async pull(controller) {
98
- const { value, done } = await generator.next();
99
- // When no more data needs to be consumed, close the stream
100
- if (done) {
101
- controller.close();
102
- }
103
- // Fix: `else if (value)` will hang the streaming when nullish value (e.g. empty string) is pulled
104
- controller.enqueue(value);
105
- },
106
- async cancel(reason) {
107
- await generator.return(reason);
108
- },
109
- });
110
- }
111
- }
1
+ //#region src/utils/stream.ts
2
+ var IterableReadableStream = class IterableReadableStream extends ReadableStream {
3
+ reader;
4
+ ensureReader() {
5
+ if (!this.reader) this.reader = this.getReader();
6
+ }
7
+ async next() {
8
+ this.ensureReader();
9
+ try {
10
+ const result = await this.reader.read();
11
+ if (result.done) {
12
+ this.reader.releaseLock();
13
+ return {
14
+ done: true,
15
+ value: void 0
16
+ };
17
+ } else return {
18
+ done: false,
19
+ value: result.value
20
+ };
21
+ } catch (e) {
22
+ this.reader.releaseLock();
23
+ throw e;
24
+ }
25
+ }
26
+ async return() {
27
+ this.ensureReader();
28
+ if (this.locked) {
29
+ const cancelPromise = this.reader.cancel();
30
+ this.reader.releaseLock();
31
+ await cancelPromise;
32
+ }
33
+ return {
34
+ done: true,
35
+ value: void 0
36
+ };
37
+ }
38
+ async throw(e) {
39
+ this.ensureReader();
40
+ if (this.locked) {
41
+ const cancelPromise = this.reader.cancel();
42
+ this.reader.releaseLock();
43
+ await cancelPromise;
44
+ }
45
+ throw e;
46
+ }
47
+ async [Symbol.asyncDispose]() {
48
+ await this.return();
49
+ }
50
+ [Symbol.asyncIterator]() {
51
+ return this;
52
+ }
53
+ static fromReadableStream(stream) {
54
+ const reader = stream.getReader();
55
+ return new IterableReadableStream({
56
+ start(controller) {
57
+ return pump();
58
+ function pump() {
59
+ return reader.read().then(({ done, value }) => {
60
+ if (done) {
61
+ controller.close();
62
+ return;
63
+ }
64
+ controller.enqueue(value);
65
+ return pump();
66
+ });
67
+ }
68
+ },
69
+ cancel() {
70
+ reader.releaseLock();
71
+ }
72
+ });
73
+ }
74
+ static fromAsyncGenerator(generator) {
75
+ return new IterableReadableStream({
76
+ async pull(controller) {
77
+ const { value, done } = await generator.next();
78
+ if (done) controller.close();
79
+ controller.enqueue(value);
80
+ },
81
+ async cancel(reason) {
82
+ await generator.return(reason);
83
+ }
84
+ });
85
+ }
86
+ };
87
+
88
+ //#endregion
89
+ export { IterableReadableStream };
90
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.js","names":[],"sources":["../../src/utils/stream.ts"],"sourcesContent":["// in this case don't quite match.\ntype IterableReadableStreamInterface<T> = ReadableStream<T> & AsyncIterable<T>;\n\n/*\n * Support async iterator syntax for ReadableStreams in all environments.\n * Source: https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490\n */\nexport class IterableReadableStream<T>\n extends ReadableStream<T>\n implements IterableReadableStreamInterface<T>\n{\n public reader: ReadableStreamDefaultReader<T>;\n\n ensureReader() {\n if (!this.reader) {\n this.reader = this.getReader();\n }\n }\n\n async next(): Promise<IteratorResult<T>> {\n this.ensureReader();\n try {\n const result = await this.reader.read();\n if (result.done) {\n this.reader.releaseLock(); // release lock when stream becomes closed\n return {\n done: true,\n value: undefined,\n };\n } else {\n return {\n done: false,\n value: result.value,\n };\n }\n } catch (e) {\n this.reader.releaseLock(); // release lock when stream becomes errored\n throw e;\n }\n }\n\n async return(): Promise<IteratorResult<T>> {\n this.ensureReader();\n // If wrapped in a Node stream, cancel is already called.\n if (this.locked) {\n const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet\n this.reader.releaseLock(); // release lock first\n await cancelPromise; // now await it\n }\n return { done: true, value: undefined };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async throw(e: any): Promise<IteratorResult<T>> {\n this.ensureReader();\n if (this.locked) {\n const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet\n this.reader.releaseLock(); // release lock first\n await cancelPromise; // now await it\n }\n throw e;\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore Not present in Node 18 types, required in latest Node 22\n async [Symbol.asyncDispose]() {\n await this.return();\n }\n\n [Symbol.asyncIterator]() {\n return this;\n }\n\n static fromReadableStream<T>(stream: ReadableStream<T>) {\n // From https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams#reading_the_stream\n const reader = stream.getReader();\n return new IterableReadableStream<T>({\n start(controller) {\n return pump();\n function pump(): Promise<T | undefined> {\n return reader.read().then(({ done, value }) => {\n // When no more data needs to be consumed, close the stream\n if (done) {\n controller.close();\n return;\n }\n // Enqueue the next data chunk into our target stream\n controller.enqueue(value);\n return pump();\n });\n }\n },\n cancel() {\n reader.releaseLock();\n },\n });\n }\n\n static fromAsyncGenerator<T>(generator: AsyncGenerator<T>) {\n return new IterableReadableStream<T>({\n async pull(controller) {\n const { value, done } = await generator.next();\n // When no more data needs to be consumed, close the stream\n if (done) {\n controller.close();\n }\n // Fix: `else if (value)` will hang the streaming when nullish value (e.g. empty string) is pulled\n controller.enqueue(value);\n },\n async cancel(reason) {\n await generator.return(reason);\n },\n });\n }\n}\n"],"mappings":";AAOA,IAAa,yBAAb,MAAa,+BACH,eAEV;CACE,AAAO;CAEP,eAAe;AACb,MAAI,CAAC,KAAK,OACR,MAAK,SAAS,KAAK;;CAIvB,MAAM,OAAmC;AACvC,OAAK;AACL,MAAI;GACF,MAAM,SAAS,MAAM,KAAK,OAAO;AACjC,OAAI,OAAO,MAAM;AACf,SAAK,OAAO;AACZ,WAAO;KACL,MAAM;KACN,OAAO;;SAGT,QAAO;IACL,MAAM;IACN,OAAO,OAAO;;WAGX,GAAG;AACV,QAAK,OAAO;AACZ,SAAM;;;CAIV,MAAM,SAAqC;AACzC,OAAK;AAEL,MAAI,KAAK,QAAQ;GACf,MAAM,gBAAgB,KAAK,OAAO;AAClC,QAAK,OAAO;AACZ,SAAM;;AAER,SAAO;GAAE,MAAM;GAAM,OAAO;;;CAI9B,MAAM,MAAM,GAAoC;AAC9C,OAAK;AACL,MAAI,KAAK,QAAQ;GACf,MAAM,gBAAgB,KAAK,OAAO;AAClC,QAAK,OAAO;AACZ,SAAM;;AAER,QAAM;;CAKR,OAAO,OAAO,gBAAgB;AAC5B,QAAM,KAAK;;CAGb,CAAC,OAAO,iBAAiB;AACvB,SAAO;;CAGT,OAAO,mBAAsB,QAA2B;EAEtD,MAAM,SAAS,OAAO;AACtB,SAAO,IAAI,uBAA0B;GACnC,MAAM,YAAY;AAChB,WAAO;IACP,SAAS,OAA+B;AACtC,YAAO,OAAO,OAAO,MAAM,EAAE,MAAM,YAAY;AAE7C,UAAI,MAAM;AACR,kBAAW;AACX;;AAGF,iBAAW,QAAQ;AACnB,aAAO;;;;GAIb,SAAS;AACP,WAAO;;;;CAKb,OAAO,mBAAsB,WAA8B;AACzD,SAAO,IAAI,uBAA0B;GACnC,MAAM,KAAK,YAAY;IACrB,MAAM,EAAE,OAAO,SAAS,MAAM,UAAU;AAExC,QAAI,KACF,YAAW;AAGb,eAAW,QAAQ;;GAErB,MAAM,OAAO,QAAQ;AACnB,UAAM,UAAU,OAAO"}