@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,7 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BytesLineDecoder = BytesLineDecoder;
4
- exports.SSEDecoder = SSEDecoder;
1
+
2
+ //#region src/utils/sse.ts
5
3
  const CR = "\r".charCodeAt(0);
6
4
  const LF = "\n".charCodeAt(0);
7
5
  const NULL = "\0".charCodeAt(0);
@@ -9,146 +7,118 @@ const COLON = ":".charCodeAt(0);
9
7
  const SPACE = " ".charCodeAt(0);
10
8
  const TRAILING_NEWLINE = [CR, LF];
11
9
  function BytesLineDecoder() {
12
- let buffer = [];
13
- let trailingCr = false;
14
- return new TransformStream({
15
- start() {
16
- buffer = [];
17
- trailingCr = false;
18
- },
19
- transform(chunk, controller) {
20
- // See https://docs.python.org/3/glossary.html#term-universal-newlines
21
- let text = chunk;
22
- // Handle trailing CR from previous chunk
23
- if (trailingCr) {
24
- text = joinArrays([[CR], text]);
25
- trailingCr = false;
26
- }
27
- // Check for trailing CR in current chunk
28
- if (text.length > 0 && text.at(-1) === CR) {
29
- trailingCr = true;
30
- text = text.subarray(0, -1);
31
- }
32
- if (!text.length)
33
- return;
34
- const trailingNewline = TRAILING_NEWLINE.includes(text.at(-1));
35
- const lastIdx = text.length - 1;
36
- const { lines } = text.reduce((acc, cur, idx) => {
37
- if (acc.from > idx)
38
- return acc;
39
- if (cur === CR || cur === LF) {
40
- acc.lines.push(text.subarray(acc.from, idx));
41
- if (cur === CR && text[idx + 1] === LF) {
42
- acc.from = idx + 2;
43
- }
44
- else {
45
- acc.from = idx + 1;
46
- }
47
- }
48
- if (idx === lastIdx && acc.from <= lastIdx) {
49
- acc.lines.push(text.subarray(acc.from));
50
- }
51
- return acc;
52
- }, { lines: [], from: 0 });
53
- if (lines.length === 1 && !trailingNewline) {
54
- buffer.push(lines[0]);
55
- return;
56
- }
57
- if (buffer.length) {
58
- // Include existing buffer in first line
59
- buffer.push(lines[0]);
60
- lines[0] = joinArrays(buffer);
61
- buffer = [];
62
- }
63
- if (!trailingNewline) {
64
- // If the last segment is not newline terminated,
65
- // buffer it for the next chunk
66
- if (lines.length)
67
- buffer = [lines.pop()];
68
- }
69
- // Enqueue complete lines
70
- for (const line of lines) {
71
- controller.enqueue(line);
72
- }
73
- },
74
- flush(controller) {
75
- if (buffer.length) {
76
- controller.enqueue(joinArrays(buffer));
77
- }
78
- },
79
- });
10
+ let buffer = [];
11
+ let trailingCr = false;
12
+ return new TransformStream({
13
+ start() {
14
+ buffer = [];
15
+ trailingCr = false;
16
+ },
17
+ transform(chunk, controller) {
18
+ let text = chunk;
19
+ if (trailingCr) {
20
+ text = joinArrays([[CR], text]);
21
+ trailingCr = false;
22
+ }
23
+ if (text.length > 0 && text.at(-1) === CR) {
24
+ trailingCr = true;
25
+ text = text.subarray(0, -1);
26
+ }
27
+ if (!text.length) return;
28
+ const trailingNewline = TRAILING_NEWLINE.includes(text.at(-1));
29
+ const lastIdx = text.length - 1;
30
+ const { lines } = text.reduce((acc, cur, idx) => {
31
+ if (acc.from > idx) return acc;
32
+ if (cur === CR || cur === LF) {
33
+ acc.lines.push(text.subarray(acc.from, idx));
34
+ if (cur === CR && text[idx + 1] === LF) acc.from = idx + 2;
35
+ else acc.from = idx + 1;
36
+ }
37
+ if (idx === lastIdx && acc.from <= lastIdx) acc.lines.push(text.subarray(acc.from));
38
+ return acc;
39
+ }, {
40
+ lines: [],
41
+ from: 0
42
+ });
43
+ if (lines.length === 1 && !trailingNewline) {
44
+ buffer.push(lines[0]);
45
+ return;
46
+ }
47
+ if (buffer.length) {
48
+ buffer.push(lines[0]);
49
+ lines[0] = joinArrays(buffer);
50
+ buffer = [];
51
+ }
52
+ if (!trailingNewline) {
53
+ if (lines.length) buffer = [lines.pop()];
54
+ }
55
+ for (const line of lines) controller.enqueue(line);
56
+ },
57
+ flush(controller) {
58
+ if (buffer.length) controller.enqueue(joinArrays(buffer));
59
+ }
60
+ });
80
61
  }
81
62
  function SSEDecoder() {
82
- let event = "";
83
- let data = [];
84
- let lastEventId = "";
85
- let retry = null;
86
- const decoder = new TextDecoder();
87
- return new TransformStream({
88
- transform(chunk, controller) {
89
- // Handle empty line case
90
- if (!chunk.length) {
91
- if (!event && !data.length && !lastEventId && retry == null)
92
- return;
93
- const sse = {
94
- id: lastEventId || undefined,
95
- event,
96
- data: data.length ? decodeArraysToJson(decoder, data) : null,
97
- };
98
- // NOTE: as per the SSE spec, do not reset lastEventId
99
- event = "";
100
- data = [];
101
- retry = null;
102
- controller.enqueue(sse);
103
- return;
104
- }
105
- // Ignore comments
106
- if (chunk[0] === COLON)
107
- return;
108
- const sepIdx = chunk.indexOf(COLON);
109
- if (sepIdx === -1)
110
- return;
111
- const fieldName = decoder.decode(chunk.subarray(0, sepIdx));
112
- let value = chunk.subarray(sepIdx + 1);
113
- if (value[0] === SPACE)
114
- value = value.subarray(1);
115
- if (fieldName === "event") {
116
- event = decoder.decode(value);
117
- }
118
- else if (fieldName === "data") {
119
- data.push(value);
120
- }
121
- else if (fieldName === "id") {
122
- if (value.indexOf(NULL) === -1)
123
- lastEventId = decoder.decode(value);
124
- }
125
- else if (fieldName === "retry") {
126
- const retryNum = Number.parseInt(decoder.decode(value), 10);
127
- if (!Number.isNaN(retryNum))
128
- retry = retryNum;
129
- }
130
- },
131
- flush(controller) {
132
- if (event) {
133
- controller.enqueue({
134
- id: lastEventId || undefined,
135
- event,
136
- data: data.length ? decodeArraysToJson(decoder, data) : null,
137
- });
138
- }
139
- },
140
- });
63
+ let event = "";
64
+ let data = [];
65
+ let lastEventId = "";
66
+ let retry = null;
67
+ const decoder = new TextDecoder();
68
+ return new TransformStream({
69
+ transform(chunk, controller) {
70
+ if (!chunk.length) {
71
+ if (!event && !data.length && !lastEventId && retry == null) return;
72
+ const sse = {
73
+ id: lastEventId || void 0,
74
+ event,
75
+ data: data.length ? decodeArraysToJson(decoder, data) : null
76
+ };
77
+ event = "";
78
+ data = [];
79
+ retry = null;
80
+ controller.enqueue(sse);
81
+ return;
82
+ }
83
+ if (chunk[0] === COLON) return;
84
+ const sepIdx = chunk.indexOf(COLON);
85
+ if (sepIdx === -1) return;
86
+ const fieldName = decoder.decode(chunk.subarray(0, sepIdx));
87
+ let value = chunk.subarray(sepIdx + 1);
88
+ if (value[0] === SPACE) value = value.subarray(1);
89
+ if (fieldName === "event") event = decoder.decode(value);
90
+ else if (fieldName === "data") data.push(value);
91
+ else if (fieldName === "id") {
92
+ if (value.indexOf(NULL) === -1) lastEventId = decoder.decode(value);
93
+ } else if (fieldName === "retry") {
94
+ const retryNum = Number.parseInt(decoder.decode(value), 10);
95
+ if (!Number.isNaN(retryNum)) retry = retryNum;
96
+ }
97
+ },
98
+ flush(controller) {
99
+ if (event) controller.enqueue({
100
+ id: lastEventId || void 0,
101
+ event,
102
+ data: data.length ? decodeArraysToJson(decoder, data) : null
103
+ });
104
+ }
105
+ });
141
106
  }
142
107
  function joinArrays(data) {
143
- const totalLength = data.reduce((acc, curr) => acc + curr.length, 0);
144
- const merged = new Uint8Array(totalLength);
145
- let offset = 0;
146
- for (const c of data) {
147
- merged.set(c, offset);
148
- offset += c.length;
149
- }
150
- return merged;
108
+ const totalLength = data.reduce((acc, curr) => acc + curr.length, 0);
109
+ const merged = new Uint8Array(totalLength);
110
+ let offset = 0;
111
+ for (const c of data) {
112
+ merged.set(c, offset);
113
+ offset += c.length;
114
+ }
115
+ return merged;
151
116
  }
152
117
  function decodeArraysToJson(decoder, data) {
153
- return JSON.parse(decoder.decode(joinArrays(data)));
118
+ return JSON.parse(decoder.decode(joinArrays(data)));
154
119
  }
120
+
121
+ //#endregion
122
+ exports.BytesLineDecoder = BytesLineDecoder;
123
+ exports.SSEDecoder = SSEDecoder;
124
+ //# sourceMappingURL=sse.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse.cjs","names":["buffer: Uint8Array[]","data: Uint8Array[]","retry: number | null"],"sources":["../../src/utils/sse.ts"],"sourcesContent":["const CR = \"\\r\".charCodeAt(0);\nconst LF = \"\\n\".charCodeAt(0);\nconst NULL = \"\\0\".charCodeAt(0);\nconst COLON = \":\".charCodeAt(0);\nconst SPACE = \" \".charCodeAt(0);\n\nconst TRAILING_NEWLINE = [CR, LF];\n\nexport function BytesLineDecoder() {\n let buffer: Uint8Array[] = [];\n let trailingCr = false;\n\n return new TransformStream<Uint8Array, Uint8Array>({\n start() {\n buffer = [];\n trailingCr = false;\n },\n\n transform(chunk, controller) {\n // See https://docs.python.org/3/glossary.html#term-universal-newlines\n let text = chunk;\n\n // Handle trailing CR from previous chunk\n if (trailingCr) {\n text = joinArrays([[CR], text]);\n trailingCr = false;\n }\n\n // Check for trailing CR in current chunk\n if (text.length > 0 && text.at(-1) === CR) {\n trailingCr = true;\n text = text.subarray(0, -1);\n }\n\n if (!text.length) return;\n const trailingNewline = TRAILING_NEWLINE.includes(text.at(-1)!);\n\n const lastIdx = text.length - 1;\n const { lines } = text.reduce<{ lines: Uint8Array[]; from: number }>(\n (acc, cur, idx) => {\n if (acc.from > idx) return acc;\n\n if (cur === CR || cur === LF) {\n acc.lines.push(text.subarray(acc.from, idx));\n if (cur === CR && text[idx + 1] === LF) {\n acc.from = idx + 2;\n } else {\n acc.from = idx + 1;\n }\n }\n\n if (idx === lastIdx && acc.from <= lastIdx) {\n acc.lines.push(text.subarray(acc.from));\n }\n\n return acc;\n },\n { lines: [], from: 0 }\n );\n\n if (lines.length === 1 && !trailingNewline) {\n buffer.push(lines[0]);\n return;\n }\n\n if (buffer.length) {\n // Include existing buffer in first line\n buffer.push(lines[0]);\n lines[0] = joinArrays(buffer);\n buffer = [];\n }\n\n if (!trailingNewline) {\n // If the last segment is not newline terminated,\n // buffer it for the next chunk\n if (lines.length) buffer = [lines.pop()!];\n }\n\n // Enqueue complete lines\n for (const line of lines) {\n controller.enqueue(line);\n }\n },\n\n flush(controller) {\n if (buffer.length) {\n controller.enqueue(joinArrays(buffer));\n }\n },\n });\n}\n\ninterface StreamPart {\n id: string | undefined;\n event: string;\n data: unknown;\n}\n\nexport function SSEDecoder() {\n let event = \"\";\n let data: Uint8Array[] = [];\n let lastEventId = \"\";\n let retry: number | null = null;\n\n const decoder = new TextDecoder();\n\n return new TransformStream<Uint8Array, StreamPart>({\n transform(chunk, controller) {\n // Handle empty line case\n if (!chunk.length) {\n if (!event && !data.length && !lastEventId && retry == null) return;\n\n const sse = {\n id: lastEventId || undefined,\n event,\n data: data.length ? decodeArraysToJson(decoder, data) : null,\n };\n\n // NOTE: as per the SSE spec, do not reset lastEventId\n event = \"\";\n data = [];\n retry = null;\n\n controller.enqueue(sse);\n return;\n }\n\n // Ignore comments\n if (chunk[0] === COLON) return;\n\n const sepIdx = chunk.indexOf(COLON);\n if (sepIdx === -1) return;\n\n const fieldName = decoder.decode(chunk.subarray(0, sepIdx));\n let value = chunk.subarray(sepIdx + 1);\n if (value[0] === SPACE) value = value.subarray(1);\n\n if (fieldName === \"event\") {\n event = decoder.decode(value);\n } else if (fieldName === \"data\") {\n data.push(value);\n } else if (fieldName === \"id\") {\n if (value.indexOf(NULL) === -1) lastEventId = decoder.decode(value);\n } else if (fieldName === \"retry\") {\n const retryNum = Number.parseInt(decoder.decode(value), 10);\n if (!Number.isNaN(retryNum)) retry = retryNum;\n }\n },\n\n flush(controller) {\n if (event) {\n controller.enqueue({\n id: lastEventId || undefined,\n event,\n data: data.length ? decodeArraysToJson(decoder, data) : null,\n });\n }\n },\n });\n}\n\nfunction joinArrays(data: ArrayLike<number>[]) {\n const totalLength = data.reduce((acc, curr) => acc + curr.length, 0);\n const merged = new Uint8Array(totalLength);\n let offset = 0;\n for (const c of data) {\n merged.set(c, offset);\n offset += c.length;\n }\n return merged;\n}\n\nfunction decodeArraysToJson(decoder: TextDecoder, data: ArrayLike<number>[]) {\n return JSON.parse(decoder.decode(joinArrays(data)));\n}\n"],"mappings":";;AAAA,MAAM,KAAK,KAAK,WAAW;AAC3B,MAAM,KAAK,KAAK,WAAW;AAC3B,MAAM,OAAO,KAAK,WAAW;AAC7B,MAAM,QAAQ,IAAI,WAAW;AAC7B,MAAM,QAAQ,IAAI,WAAW;AAE7B,MAAM,mBAAmB,CAAC,IAAI;AAE9B,SAAgB,mBAAmB;CACjC,IAAIA,SAAuB;CAC3B,IAAI,aAAa;AAEjB,QAAO,IAAI,gBAAwC;EACjD,QAAQ;AACN,YAAS;AACT,gBAAa;;EAGf,UAAU,OAAO,YAAY;GAE3B,IAAI,OAAO;AAGX,OAAI,YAAY;AACd,WAAO,WAAW,CAAC,CAAC,KAAK;AACzB,iBAAa;;AAIf,OAAI,KAAK,SAAS,KAAK,KAAK,GAAG,QAAQ,IAAI;AACzC,iBAAa;AACb,WAAO,KAAK,SAAS,GAAG;;AAG1B,OAAI,CAAC,KAAK,OAAQ;GAClB,MAAM,kBAAkB,iBAAiB,SAAS,KAAK,GAAG;GAE1D,MAAM,UAAU,KAAK,SAAS;GAC9B,MAAM,EAAE,UAAU,KAAK,QACpB,KAAK,KAAK,QAAQ;AACjB,QAAI,IAAI,OAAO,IAAK,QAAO;AAE3B,QAAI,QAAQ,MAAM,QAAQ,IAAI;AAC5B,SAAI,MAAM,KAAK,KAAK,SAAS,IAAI,MAAM;AACvC,SAAI,QAAQ,MAAM,KAAK,MAAM,OAAO,GAClC,KAAI,OAAO,MAAM;SAEjB,KAAI,OAAO,MAAM;;AAIrB,QAAI,QAAQ,WAAW,IAAI,QAAQ,QACjC,KAAI,M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AM,WAAW,OAAO,SAAS,QAAQ,OAAO,QAAQ;AACxD,QAAI,CAAC,OAAO,MAAM,UAAW,SAAQ;;;EAIzC,MAAM,YAAY;AAChB,OAAI,MACF,YAAW,QAAQ;IACjB,IAAI,eAAe;IACnB;IACA,MAAM,KAAK,SAAS,mBAAmB,SAAS,QAAQ;;;;;AAOlE,SAAS,WAAW,MAA2B;CAC7C,MAAM,cAAc,KAAK,QAAQ,KAAK,SAAS,MAAM,KAAK,QAAQ;CAClE,MAAM,SAAS,IAAI,WAAW;CAC9B,IAAI,SAAS;AACb,MAAK,MAAM,KAAK,MAAM;AACpB,SAAO,IAAI,GAAG;AACd,YAAU,EAAE;;AAEd,QAAO;;AAGT,SAAS,mBAAmB,SAAsB,MAA2B;AAC3E,QAAO,KAAK,MAAM,QAAQ,OAAO,WAAW"}
package/dist/utils/sse.js CHANGED
@@ -1,150 +1,122 @@
1
+ //#region src/utils/sse.ts
1
2
  const CR = "\r".charCodeAt(0);
2
3
  const LF = "\n".charCodeAt(0);
3
4
  const NULL = "\0".charCodeAt(0);
4
5
  const COLON = ":".charCodeAt(0);
5
6
  const SPACE = " ".charCodeAt(0);
6
7
  const TRAILING_NEWLINE = [CR, LF];
7
- export function BytesLineDecoder() {
8
- let buffer = [];
9
- let trailingCr = false;
10
- return new TransformStream({
11
- start() {
12
- buffer = [];
13
- trailingCr = false;
14
- },
15
- transform(chunk, controller) {
16
- // See https://docs.python.org/3/glossary.html#term-universal-newlines
17
- let text = chunk;
18
- // Handle trailing CR from previous chunk
19
- if (trailingCr) {
20
- text = joinArrays([[CR], text]);
21
- trailingCr = false;
22
- }
23
- // Check for trailing CR in current chunk
24
- if (text.length > 0 && text.at(-1) === CR) {
25
- trailingCr = true;
26
- text = text.subarray(0, -1);
27
- }
28
- if (!text.length)
29
- return;
30
- const trailingNewline = TRAILING_NEWLINE.includes(text.at(-1));
31
- const lastIdx = text.length - 1;
32
- const { lines } = text.reduce((acc, cur, idx) => {
33
- if (acc.from > idx)
34
- return acc;
35
- if (cur === CR || cur === LF) {
36
- acc.lines.push(text.subarray(acc.from, idx));
37
- if (cur === CR && text[idx + 1] === LF) {
38
- acc.from = idx + 2;
39
- }
40
- else {
41
- acc.from = idx + 1;
42
- }
43
- }
44
- if (idx === lastIdx && acc.from <= lastIdx) {
45
- acc.lines.push(text.subarray(acc.from));
46
- }
47
- return acc;
48
- }, { lines: [], from: 0 });
49
- if (lines.length === 1 && !trailingNewline) {
50
- buffer.push(lines[0]);
51
- return;
52
- }
53
- if (buffer.length) {
54
- // Include existing buffer in first line
55
- buffer.push(lines[0]);
56
- lines[0] = joinArrays(buffer);
57
- buffer = [];
58
- }
59
- if (!trailingNewline) {
60
- // If the last segment is not newline terminated,
61
- // buffer it for the next chunk
62
- if (lines.length)
63
- buffer = [lines.pop()];
64
- }
65
- // Enqueue complete lines
66
- for (const line of lines) {
67
- controller.enqueue(line);
68
- }
69
- },
70
- flush(controller) {
71
- if (buffer.length) {
72
- controller.enqueue(joinArrays(buffer));
73
- }
74
- },
75
- });
8
+ function BytesLineDecoder() {
9
+ let buffer = [];
10
+ let trailingCr = false;
11
+ return new TransformStream({
12
+ start() {
13
+ buffer = [];
14
+ trailingCr = false;
15
+ },
16
+ transform(chunk, controller) {
17
+ let text = chunk;
18
+ if (trailingCr) {
19
+ text = joinArrays([[CR], text]);
20
+ trailingCr = false;
21
+ }
22
+ if (text.length > 0 && text.at(-1) === CR) {
23
+ trailingCr = true;
24
+ text = text.subarray(0, -1);
25
+ }
26
+ if (!text.length) return;
27
+ const trailingNewline = TRAILING_NEWLINE.includes(text.at(-1));
28
+ const lastIdx = text.length - 1;
29
+ const { lines } = text.reduce((acc, cur, idx) => {
30
+ if (acc.from > idx) return acc;
31
+ if (cur === CR || cur === LF) {
32
+ acc.lines.push(text.subarray(acc.from, idx));
33
+ if (cur === CR && text[idx + 1] === LF) acc.from = idx + 2;
34
+ else acc.from = idx + 1;
35
+ }
36
+ if (idx === lastIdx && acc.from <= lastIdx) acc.lines.push(text.subarray(acc.from));
37
+ return acc;
38
+ }, {
39
+ lines: [],
40
+ from: 0
41
+ });
42
+ if (lines.length === 1 && !trailingNewline) {
43
+ buffer.push(lines[0]);
44
+ return;
45
+ }
46
+ if (buffer.length) {
47
+ buffer.push(lines[0]);
48
+ lines[0] = joinArrays(buffer);
49
+ buffer = [];
50
+ }
51
+ if (!trailingNewline) {
52
+ if (lines.length) buffer = [lines.pop()];
53
+ }
54
+ for (const line of lines) controller.enqueue(line);
55
+ },
56
+ flush(controller) {
57
+ if (buffer.length) controller.enqueue(joinArrays(buffer));
58
+ }
59
+ });
76
60
  }
77
- export function SSEDecoder() {
78
- let event = "";
79
- let data = [];
80
- let lastEventId = "";
81
- let retry = null;
82
- const decoder = new TextDecoder();
83
- return new TransformStream({
84
- transform(chunk, controller) {
85
- // Handle empty line case
86
- if (!chunk.length) {
87
- if (!event && !data.length && !lastEventId && retry == null)
88
- return;
89
- const sse = {
90
- id: lastEventId || undefined,
91
- event,
92
- data: data.length ? decodeArraysToJson(decoder, data) : null,
93
- };
94
- // NOTE: as per the SSE spec, do not reset lastEventId
95
- event = "";
96
- data = [];
97
- retry = null;
98
- controller.enqueue(sse);
99
- return;
100
- }
101
- // Ignore comments
102
- if (chunk[0] === COLON)
103
- return;
104
- const sepIdx = chunk.indexOf(COLON);
105
- if (sepIdx === -1)
106
- return;
107
- const fieldName = decoder.decode(chunk.subarray(0, sepIdx));
108
- let value = chunk.subarray(sepIdx + 1);
109
- if (value[0] === SPACE)
110
- value = value.subarray(1);
111
- if (fieldName === "event") {
112
- event = decoder.decode(value);
113
- }
114
- else if (fieldName === "data") {
115
- data.push(value);
116
- }
117
- else if (fieldName === "id") {
118
- if (value.indexOf(NULL) === -1)
119
- lastEventId = decoder.decode(value);
120
- }
121
- else if (fieldName === "retry") {
122
- const retryNum = Number.parseInt(decoder.decode(value), 10);
123
- if (!Number.isNaN(retryNum))
124
- retry = retryNum;
125
- }
126
- },
127
- flush(controller) {
128
- if (event) {
129
- controller.enqueue({
130
- id: lastEventId || undefined,
131
- event,
132
- data: data.length ? decodeArraysToJson(decoder, data) : null,
133
- });
134
- }
135
- },
136
- });
61
+ function SSEDecoder() {
62
+ let event = "";
63
+ let data = [];
64
+ let lastEventId = "";
65
+ let retry = null;
66
+ const decoder = new TextDecoder();
67
+ return new TransformStream({
68
+ transform(chunk, controller) {
69
+ if (!chunk.length) {
70
+ if (!event && !data.length && !lastEventId && retry == null) return;
71
+ const sse = {
72
+ id: lastEventId || void 0,
73
+ event,
74
+ data: data.length ? decodeArraysToJson(decoder, data) : null
75
+ };
76
+ event = "";
77
+ data = [];
78
+ retry = null;
79
+ controller.enqueue(sse);
80
+ return;
81
+ }
82
+ if (chunk[0] === COLON) return;
83
+ const sepIdx = chunk.indexOf(COLON);
84
+ if (sepIdx === -1) return;
85
+ const fieldName = decoder.decode(chunk.subarray(0, sepIdx));
86
+ let value = chunk.subarray(sepIdx + 1);
87
+ if (value[0] === SPACE) value = value.subarray(1);
88
+ if (fieldName === "event") event = decoder.decode(value);
89
+ else if (fieldName === "data") data.push(value);
90
+ else if (fieldName === "id") {
91
+ if (value.indexOf(NULL) === -1) lastEventId = decoder.decode(value);
92
+ } else if (fieldName === "retry") {
93
+ const retryNum = Number.parseInt(decoder.decode(value), 10);
94
+ if (!Number.isNaN(retryNum)) retry = retryNum;
95
+ }
96
+ },
97
+ flush(controller) {
98
+ if (event) controller.enqueue({
99
+ id: lastEventId || void 0,
100
+ event,
101
+ data: data.length ? decodeArraysToJson(decoder, data) : null
102
+ });
103
+ }
104
+ });
137
105
  }
138
106
  function joinArrays(data) {
139
- const totalLength = data.reduce((acc, curr) => acc + curr.length, 0);
140
- const merged = new Uint8Array(totalLength);
141
- let offset = 0;
142
- for (const c of data) {
143
- merged.set(c, offset);
144
- offset += c.length;
145
- }
146
- return merged;
107
+ const totalLength = data.reduce((acc, curr) => acc + curr.length, 0);
108
+ const merged = new Uint8Array(totalLength);
109
+ let offset = 0;
110
+ for (const c of data) {
111
+ merged.set(c, offset);
112
+ offset += c.length;
113
+ }
114
+ return merged;
147
115
  }
148
116
  function decodeArraysToJson(decoder, data) {
149
- return JSON.parse(decoder.decode(joinArrays(data)));
117
+ return JSON.parse(decoder.decode(joinArrays(data)));
150
118
  }
119
+
120
+ //#endregion
121
+ export { BytesLineDecoder, SSEDecoder };
122
+ //# sourceMappingURL=sse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse.js","names":["buffer: Uint8Array[]","data: Uint8Array[]","retry: number | null"],"sources":["../../src/utils/sse.ts"],"sourcesContent":["const CR = \"\\r\".charCodeAt(0);\nconst LF = \"\\n\".charCodeAt(0);\nconst NULL = \"\\0\".charCodeAt(0);\nconst COLON = \":\".charCodeAt(0);\nconst SPACE = \" \".charCodeAt(0);\n\nconst TRAILING_NEWLINE = [CR, LF];\n\nexport function BytesLineDecoder() {\n let buffer: Uint8Array[] = [];\n let trailingCr = false;\n\n return new TransformStream<Uint8Array, Uint8Array>({\n start() {\n buffer = [];\n trailingCr = false;\n },\n\n transform(chunk, controller) {\n // See https://docs.python.org/3/glossary.html#term-universal-newlines\n let text = chunk;\n\n // Handle trailing CR from previous chunk\n if (trailingCr) {\n text = joinArrays([[CR], text]);\n trailingCr = false;\n }\n\n // Check for trailing CR in current chunk\n if (text.length > 0 && text.at(-1) === CR) {\n trailingCr = true;\n text = text.subarray(0, -1);\n }\n\n if (!text.length) return;\n const trailingNewline = TRAILING_NEWLINE.includes(text.at(-1)!);\n\n const lastIdx = text.length - 1;\n const { lines } = text.reduce<{ lines: Uint8Array[]; from: number }>(\n (acc, cur, idx) => {\n if (acc.from > idx) return acc;\n\n if (cur === CR || cur === LF) {\n acc.lines.push(text.subarray(acc.from, idx));\n if (cur === CR && text[idx + 1] === LF) {\n acc.from = idx + 2;\n } else {\n acc.from = idx + 1;\n }\n }\n\n if (idx === lastIdx && acc.from <= lastIdx) {\n acc.lines.push(text.subarray(acc.from));\n }\n\n return acc;\n },\n { lines: [], from: 0 }\n );\n\n if (lines.length === 1 && !trailingNewline) {\n buffer.push(lines[0]);\n return;\n }\n\n if (buffer.length) {\n // Include existing buffer in first line\n buffer.push(lines[0]);\n lines[0] = joinArrays(buffer);\n buffer = [];\n }\n\n if (!trailingNewline) {\n // If the last segment is not newline terminated,\n // buffer it for the next chunk\n if (lines.length) buffer = [lines.pop()!];\n }\n\n // Enqueue complete lines\n for (const line of lines) {\n controller.enqueue(line);\n }\n },\n\n flush(controller) {\n if (buffer.length) {\n controller.enqueue(joinArrays(buffer));\n }\n },\n });\n}\n\ninterface StreamPart {\n id: string | undefined;\n event: string;\n data: unknown;\n}\n\nexport function SSEDecoder() {\n let event = \"\";\n let data: Uint8Array[] = [];\n let lastEventId = \"\";\n let retry: number | null = null;\n\n const decoder = new TextDecoder();\n\n return new TransformStream<Uint8Array, StreamPart>({\n transform(chunk, controller) {\n // Handle empty line case\n if (!chunk.length) {\n if (!event && !data.length && !lastEventId && retry == null) return;\n\n const sse = {\n id: lastEventId || undefined,\n event,\n data: data.length ? decodeArraysToJson(decoder, data) : null,\n };\n\n // NOTE: as per the SSE spec, do not reset lastEventId\n event = \"\";\n data = [];\n retry = null;\n\n controller.enqueue(sse);\n return;\n }\n\n // Ignore comments\n if (chunk[0] === COLON) return;\n\n const sepIdx = chunk.indexOf(COLON);\n if (sepIdx === -1) return;\n\n const fieldName = decoder.decode(chunk.subarray(0, sepIdx));\n let value = chunk.subarray(sepIdx + 1);\n if (value[0] === SPACE) value = value.subarray(1);\n\n if (fieldName === \"event\") {\n event = decoder.decode(value);\n } else if (fieldName === \"data\") {\n data.push(value);\n } else if (fieldName === \"id\") {\n if (value.indexOf(NULL) === -1) lastEventId = decoder.decode(value);\n } else if (fieldName === \"retry\") {\n const retryNum = Number.parseInt(decoder.decode(value), 10);\n if (!Number.isNaN(retryNum)) retry = retryNum;\n }\n },\n\n flush(controller) {\n if (event) {\n controller.enqueue({\n id: lastEventId || undefined,\n event,\n data: data.length ? decodeArraysToJson(decoder, data) : null,\n });\n }\n },\n });\n}\n\nfunction joinArrays(data: ArrayLike<number>[]) {\n const totalLength = data.reduce((acc, curr) => acc + curr.length, 0);\n const merged = new Uint8Array(totalLength);\n let offset = 0;\n for (const c of data) {\n merged.set(c, offset);\n offset += c.length;\n }\n return merged;\n}\n\nfunction decodeArraysToJson(decoder: TextDecoder, data: ArrayLike<number>[]) {\n return JSON.parse(decoder.decode(joinArrays(data)));\n}\n"],"mappings":";AAAA,MAAM,KAAK,KAAK,WAAW;AAC3B,MAAM,KAAK,KAAK,WAAW;AAC3B,MAAM,OAAO,KAAK,WAAW;AAC7B,MAAM,QAAQ,IAAI,WAAW;AAC7B,MAAM,QAAQ,IAAI,WAAW;AAE7B,MAAM,mBAAmB,CAAC,IAAI;AAE9B,SAAgB,mBAAmB;CACjC,IAAIA,SAAuB;CAC3B,IAAI,aAAa;AAEjB,QAAO,IAAI,gBAAwC;EACjD,QAAQ;AACN,YAAS;AACT,gBAAa;;EAGf,UAAU,OAAO,YAAY;GAE3B,IAAI,OAAO;AAGX,OAAI,YAAY;AACd,WAAO,WAAW,CAAC,CAAC,KAAK;AACzB,iBAAa;;AAIf,OAAI,KAAK,SAAS,KAAK,KAAK,GAAG,QAAQ,IAAI;AACzC,iBAAa;AACb,WAAO,KAAK,SAAS,GAAG;;AAG1B,OAAI,CAAC,KAAK,OAAQ;GAClB,MAAM,kBAAkB,iBAAiB,SAAS,KAAK,GAAG;GAE1D,MAAM,UAAU,KAAK,SAAS;GAC9B,MAAM,EAAE,UAAU,KAAK,QACpB,KAAK,KAAK,QAAQ;AACjB,QAAI,IAAI,OAAO,IAAK,QAAO;AAE3B,QAAI,QAAQ,MAAM,QAAQ,IAAI;AAC5B,SAAI,MAAM,KAAK,KAAK,SAAS,IAAI,MAAM;AACvC,SAAI,QAAQ,MAAM,KAAK,MAAM,OAAO,GAClC,KAAI,OAAO,MAAM;SAEjB,KAAI,OAAO,MAAM;;AAIrB,QAAI,QAAQ,WAAW,IAAI,Q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