mu-agent 0.1.8 → 0.1.13

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 (176) hide show
  1. package/CHANGELOG.md +121 -0
  2. package/README.md +34 -30
  3. package/dist/bundle/chunks/anthropic-messages-4PAJY4R6.js +6 -0
  4. package/dist/bundle/chunks/anthropic.js +1 -1
  5. package/dist/bundle/chunks/azure-openai-responses-Y4BBWQ3N.js +2 -0
  6. package/dist/bundle/chunks/bedrock-converse-stream.js +12 -9
  7. package/dist/bundle/chunks/{chunk-NG4PO5FP.js → chunk-3J3HSHLX.js} +128 -110
  8. package/dist/bundle/chunks/{chunk-TRDNDS6A.js → chunk-3V45WARH.js} +6 -3
  9. package/dist/bundle/chunks/{chunk-S3GGRYIO.js → chunk-5AGIVGSV.js} +1 -1
  10. package/dist/bundle/chunks/chunk-6QGV3IWD.js +6 -0
  11. package/dist/bundle/chunks/{chunk-4OBXYPH4.js → chunk-6Z2347ML.js} +1 -1
  12. package/dist/bundle/chunks/{chunk-F5ZABL6Z.js → chunk-7CBJINYJ.js} +2 -2
  13. package/dist/bundle/chunks/{chunk-DRQDKNXA.js → chunk-7DDKXS2Q.js} +1 -1
  14. package/dist/bundle/chunks/{chunk-H3QXYIF7.js → chunk-CF5GWZHW.js} +1 -1
  15. package/dist/bundle/chunks/{chunk-RLZVFGW4.js → chunk-DYTENXHX.js} +29 -92
  16. package/dist/bundle/chunks/{chunk-NTSWBG4X.js → chunk-FLHKNMLQ.js} +1 -1
  17. package/dist/bundle/chunks/chunk-FTJT2X6E.js +2 -0
  18. package/dist/bundle/chunks/{chunk-4L3WN2XY.js → chunk-JXWJOIH4.js} +1 -1
  19. package/dist/bundle/chunks/{chunk-TAOL3JFA.js → chunk-KIDDRTZP.js} +4 -4
  20. package/dist/bundle/chunks/chunk-LHRPMXVI.js +2 -0
  21. package/dist/bundle/chunks/chunk-LMNWTX2L.js +11 -0
  22. package/dist/bundle/chunks/chunk-LPXNMA2W.js +2 -0
  23. package/dist/bundle/chunks/chunk-LT2C56HV.js +130 -0
  24. package/dist/bundle/chunks/{chunk-6CYCI3EJ.js → chunk-LVVZS2NO.js} +1 -1
  25. package/dist/bundle/chunks/chunk-MF3VB62R.js +91 -0
  26. package/dist/bundle/chunks/chunk-NN4BEPYX.js +2 -0
  27. package/dist/bundle/chunks/{chunk-LD2P6SFZ.js → chunk-PMRZO46Y.js} +1 -1
  28. package/dist/bundle/chunks/chunk-R4VPBBDS.js +2 -0
  29. package/dist/bundle/chunks/chunk-RDZVAGPR.js +2 -0
  30. package/dist/bundle/chunks/chunk-TMTOQ7H7.js +2 -0
  31. package/dist/bundle/chunks/chunk-UKVNB6C4.js +2 -0
  32. package/dist/bundle/chunks/chunk-URBBMV3M.js +9 -0
  33. package/dist/bundle/chunks/chunk-WCGU75WO.js +11 -0
  34. package/dist/bundle/chunks/chunk-WCJNJQO5.js +9 -0
  35. package/dist/bundle/chunks/chunk-WDURT4ZM.js +2 -0
  36. package/dist/bundle/chunks/{cli-AOVD3SSZ.js → cli-M4YBZZ6Q.js} +4 -4
  37. package/dist/bundle/chunks/cloudflare-workers-ai-system-one-MEZHQVNP.js +2 -0
  38. package/dist/bundle/chunks/codemode-worker.js +117 -13
  39. package/dist/bundle/chunks/easter-egg-3d-VFY3YRQR.js +2 -0
  40. package/dist/bundle/chunks/execute-FKI7Y4XR.js +499 -0
  41. package/dist/bundle/chunks/github-copilot.js +1 -1
  42. package/dist/bundle/chunks/{google-generative-ai-XMFHGQC5.js → google-generative-ai-D2VJQBTK.js} +1 -1
  43. package/dist/bundle/chunks/{google-vertex-4XRRNP74.js → google-vertex-SQG2BO6C.js} +1 -1
  44. package/dist/bundle/chunks/https-proxy-agent-LVOO5TPL.js +13 -0
  45. package/dist/bundle/chunks/image-resize-worker.js +1 -1
  46. package/dist/bundle/chunks/{jiti-loader-C3NU2SDH.js → jiti-loader-GL4HJFAD.js} +1 -1
  47. package/dist/bundle/chunks/{jiti-static-loader-E6ANQD5T.js → jiti-static-loader-2RCDI6B4.js} +1 -1
  48. package/dist/bundle/chunks/{lib-TEDK3E5I.js → lib-4AVRLBHM.js} +1 -1
  49. package/dist/bundle/chunks/{llama-cpp-classify-XT44PI3C.js → llama-cpp-classify-5YHLY3RC.js} +2 -2
  50. package/dist/bundle/chunks/mistral-conversations-BDARVJTT.js +5 -0
  51. package/dist/bundle/chunks/{multipart-parser-SQ6GDJL7.js → multipart-parser-FMGQ7342.js} +1 -1
  52. package/dist/bundle/chunks/{node-TWVVAGPO.js → node-AUOGOBCN.js} +1 -1
  53. package/dist/bundle/chunks/{node-N5BSDOA5.js → node-KCMANYC2.js} +1 -1
  54. package/dist/bundle/chunks/openai-chatgpt.js +1 -1
  55. package/dist/bundle/chunks/openai-codex-responses-CECGTDYD.js +10 -0
  56. package/dist/bundle/chunks/openai-codex.js +1 -1
  57. package/dist/bundle/chunks/openai-completions-UOA7MELD.js +7 -0
  58. package/dist/bundle/chunks/openai-decisions-HLM372N6.js +5 -0
  59. package/dist/bundle/chunks/openai-responses-TII7ZY5X.js +3 -0
  60. package/dist/bundle/chunks/{openrouter-images-ZVXWCSIM.js → openrouter-images-7T452AS5.js} +1 -1
  61. package/dist/bundle/chunks/{pi-messages-TM5SOOIW.js → pi-messages-2UDKLKOO.js} +1 -1
  62. package/dist/bundle/chunks/runtime-IKE5OQIW.js +2 -0
  63. package/dist/bundle/chunks/{src-UK77SYZE.js → src-QKGKDFSU.js} +1 -1
  64. package/dist/bundle/chunks/typesafe-system-one-KNCICMO5.js +2 -0
  65. package/dist/bundle/chunks/virtual-modules-TJPHLTRT.js +2 -0
  66. package/dist/bundle/cli-runtime.js +1 -1
  67. package/dist/bundle/index.js +1 -1
  68. package/dist/bundle/rpc-entry.js +1 -1
  69. package/dist/core/export-html/template.js +21 -16
  70. package/dist/modes/interactive/theme/dark.json +1 -1
  71. package/dist/modes/interactive/theme/light.json +1 -1
  72. package/dist/modes/interactive/theme/theme-schema.d.ts +28 -0
  73. package/dist/modes/interactive/theme/theme-schema.d.ts.map +1 -0
  74. package/dist/modes/interactive/theme/theme-schema.js +105 -0
  75. package/dist/modes/interactive/theme/theme-schema.js.map +1 -0
  76. package/dist/modes/interactive/theme/theme-tokens.d.ts +257 -0
  77. package/dist/modes/interactive/theme/theme-tokens.d.ts.map +1 -0
  78. package/dist/modes/interactive/theme/theme-tokens.js +94 -0
  79. package/dist/modes/interactive/theme/theme-tokens.js.map +1 -0
  80. package/dist/modes/interactive/theme/theme.d.ts +13 -16
  81. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  82. package/dist/modes/interactive/theme/theme.js +22 -29
  83. package/dist/modes/interactive/theme/theme.js.map +1 -1
  84. package/docs/cli-integration.md +1 -1
  85. package/docs/cli.md +22 -10
  86. package/docs/codemode.md +29 -6
  87. package/docs/compaction.md +5 -5
  88. package/docs/custom-provider.md +53 -1
  89. package/docs/docs.json +8 -0
  90. package/docs/environment-variables.md +3 -1
  91. package/docs/extensions.md +122 -13
  92. package/docs/json.md +3 -3
  93. package/docs/keybindings.md +5 -4
  94. package/docs/llama-cpp.md +9 -2
  95. package/docs/mcp.md +4 -2
  96. package/docs/message-types.md +22 -4
  97. package/docs/models-configuration.md +187 -0
  98. package/docs/models.md +18 -2
  99. package/docs/nvidia-rtx-llama-cpp.md +96 -0
  100. package/docs/providers.md +47 -0
  101. package/docs/sessions.md +1 -1
  102. package/docs/settings.md +9 -6
  103. package/docs/terminal-setup.md +14 -0
  104. package/docs/themes.md +4 -2
  105. package/docs/tui.md +71 -1
  106. package/docs/usage.md +1 -1
  107. package/examples/README.md +0 -3
  108. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  109. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  110. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  111. package/examples/extensions/dynamic-resources/dynamic.json +1 -1
  112. package/examples/extensions/gondolin/package-lock.json +2 -2
  113. package/examples/extensions/gondolin/package.json +1 -1
  114. package/examples/extensions/minimal-mode.ts +4 -5
  115. package/examples/extensions/overlay-test.ts +2 -2
  116. package/examples/extensions/plan-mode/index.ts +6 -2
  117. package/examples/extensions/sandbox/package-lock.json +2 -2
  118. package/examples/extensions/sandbox/package.json +1 -1
  119. package/examples/extensions/subagent/index.ts +4 -6
  120. package/examples/extensions/with-deps/package-lock.json +2 -2
  121. package/examples/extensions/with-deps/package.json +1 -1
  122. package/judge/dist/auth.js +91 -35
  123. package/judge/dist/chrome.js +2 -2
  124. package/judge/dist/import.js +852 -175
  125. package/judge/dist/setup.js +240 -153
  126. package/judge/manifest.json +2512 -546
  127. package/judge/mu/chunk-3NQ5BIBI.js +4773 -0
  128. package/judge/mu/chunk-SKGYWHW6.js +51 -0
  129. package/judge/mu/chunk-WQM4MV6L.js +58 -0
  130. package/judge/mu/cloud-code-V7FOGB4J.js +22802 -0
  131. package/judge/mu/dist-75PS4OC4.js +1283 -0
  132. package/judge/{dist/kyrn-judge.js → mu/index.js} +5365 -32809
  133. package/judge/mu/multipart-parser-ZDXVIOOP.js +372 -0
  134. package/judge/mu/src-TVVA5ZK2.js +1409 -0
  135. package/judge/themes/mu-dark.json +80 -0
  136. package/judge/themes/mu-light.json +80 -0
  137. package/kyrn/bin/kyrn-doctor +44 -19
  138. package/kyrn/bin/kyrn-judge-local +43 -14
  139. package/kyrn/bin/kyrn-ledger +16 -1
  140. package/kyrn/bin/mu.mjs +142 -61
  141. package/kyrn/local-judge/server.py +26 -14
  142. package/package.json +8 -6
  143. package/dist/bundle/chunks/anthropic-messages-MI4QHRXW.js +0 -6
  144. package/dist/bundle/chunks/azure-openai-responses-E3QGN4VN.js +0 -2
  145. package/dist/bundle/chunks/chunk-33KL6IIQ.js +0 -20
  146. package/dist/bundle/chunks/chunk-A3JYRWB6.js +0 -2
  147. package/dist/bundle/chunks/chunk-C47CLQZK.js +0 -2
  148. package/dist/bundle/chunks/chunk-HQHD6PZI.js +0 -2
  149. package/dist/bundle/chunks/chunk-KJUDFE6Y.js +0 -11
  150. package/dist/bundle/chunks/chunk-TE3GUV6H.js +0 -9
  151. package/dist/bundle/chunks/chunk-VIV3CWXG.js +0 -2
  152. package/dist/bundle/chunks/chunk-WE4MXUQS.js +0 -11
  153. package/dist/bundle/chunks/chunk-Y2PP32XV.js +0 -2
  154. package/dist/bundle/chunks/chunk-YLY6CKPK.js +0 -132
  155. package/dist/bundle/chunks/chunk-ZE5FMF3V.js +0 -99
  156. package/dist/bundle/chunks/cloudflare-workers-ai-system-one-NM3JRRWQ.js +0 -2
  157. package/dist/bundle/chunks/easter-egg-3d-G2LUBEMZ.js +0 -2
  158. package/dist/bundle/chunks/execute-MZVUC6BB.js +0 -388
  159. package/dist/bundle/chunks/https-proxy-agent-2VXB7436.js +0 -13
  160. package/dist/bundle/chunks/mistral-conversations-Q22M3IBG.js +0 -5
  161. package/dist/bundle/chunks/openai-codex-responses-4MYQSO5E.js +0 -10
  162. package/dist/bundle/chunks/openai-completions-OSRCWAAA.js +0 -7
  163. package/dist/bundle/chunks/openai-responses-UHF3DHNG.js +0 -3
  164. package/dist/bundle/chunks/runtime-VJMMDLVH.js +0 -2
  165. package/dist/bundle/chunks/typesafe-system-one-PRR5K6CI.js +0 -2
  166. package/dist/bundle/chunks/virtual-modules-RJXJGCPI.js +0 -2
  167. package/dist/modes/interactive/theme/theme-json.d.ts +0 -85
  168. package/dist/modes/interactive/theme/theme-json.d.ts.map +0 -1
  169. package/dist/modes/interactive/theme/theme-json.js +0 -132
  170. package/dist/modes/interactive/theme/theme-json.js.map +0 -1
  171. package/dist/modes/interactive/theme/theme-schema.json +0 -361
  172. package/examples/plugins/pi-example-plugin/README.md +0 -38
  173. package/examples/plugins/pi-example-plugin/package.json +0 -10
  174. package/examples/plugins/pi-example-plugin/src/contract.ts +0 -13
  175. package/examples/plugins/pi-example-plugin/src/session.ts +0 -24
  176. package/examples/plugins/pi-example-plugin/src/tui.ts +0 -31
@@ -0,0 +1,372 @@
1
+ import { createRequire as __muCreateRequire } from "node:module"; const require = __muCreateRequire(import.meta.url);
2
+ import {
3
+ FormData,
4
+ file_default,
5
+ init_esm_min,
6
+ init_from
7
+ } from "./chunk-3NQ5BIBI.js";
8
+ import {
9
+ __esm
10
+ } from "./chunk-WQM4MV6L.js";
11
+
12
+ // node_modules/node-fetch/src/utils/multipart-parser.js
13
+ function _fileName(headerValue) {
14
+ const m = headerValue.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);
15
+ if (!m) {
16
+ return;
17
+ }
18
+ const match = m[2] || m[3] || "";
19
+ let filename = match.slice(match.lastIndexOf("\\") + 1);
20
+ filename = filename.replace(/%22/g, '"');
21
+ filename = filename.replace(/&#(\d{4});/g, (m2, code) => {
22
+ return String.fromCharCode(code);
23
+ });
24
+ return filename;
25
+ }
26
+ async function toFormData(Body, ct) {
27
+ if (!/multipart/i.test(ct)) {
28
+ throw new TypeError("Failed to fetch");
29
+ }
30
+ const m = ct.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
31
+ if (!m) {
32
+ throw new TypeError("no or bad content-type header, no multipart boundary");
33
+ }
34
+ const parser = new MultipartParser(m[1] || m[2]);
35
+ let headerField;
36
+ let headerValue;
37
+ let entryValue;
38
+ let entryName;
39
+ let contentType;
40
+ let filename;
41
+ const entryChunks = [];
42
+ const formData = new FormData();
43
+ const onPartData = (ui8a) => {
44
+ entryValue += decoder.decode(ui8a, { stream: true });
45
+ };
46
+ const appendToFile = (ui8a) => {
47
+ entryChunks.push(ui8a);
48
+ };
49
+ const appendFileToFormData = () => {
50
+ const file = new file_default(entryChunks, filename, { type: contentType });
51
+ formData.append(entryName, file);
52
+ };
53
+ const appendEntryToFormData = () => {
54
+ formData.append(entryName, entryValue);
55
+ };
56
+ const decoder = new TextDecoder("utf-8");
57
+ decoder.decode();
58
+ parser.onPartBegin = function() {
59
+ parser.onPartData = onPartData;
60
+ parser.onPartEnd = appendEntryToFormData;
61
+ headerField = "";
62
+ headerValue = "";
63
+ entryValue = "";
64
+ entryName = "";
65
+ contentType = "";
66
+ filename = null;
67
+ entryChunks.length = 0;
68
+ };
69
+ parser.onHeaderField = function(ui8a) {
70
+ headerField += decoder.decode(ui8a, { stream: true });
71
+ };
72
+ parser.onHeaderValue = function(ui8a) {
73
+ headerValue += decoder.decode(ui8a, { stream: true });
74
+ };
75
+ parser.onHeaderEnd = function() {
76
+ headerValue += decoder.decode();
77
+ headerField = headerField.toLowerCase();
78
+ if (headerField === "content-disposition") {
79
+ const m2 = headerValue.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);
80
+ if (m2) {
81
+ entryName = m2[2] || m2[3] || "";
82
+ }
83
+ filename = _fileName(headerValue);
84
+ if (filename) {
85
+ parser.onPartData = appendToFile;
86
+ parser.onPartEnd = appendFileToFormData;
87
+ }
88
+ } else if (headerField === "content-type") {
89
+ contentType = headerValue;
90
+ }
91
+ headerValue = "";
92
+ headerField = "";
93
+ };
94
+ for await (const chunk of Body) {
95
+ parser.write(chunk);
96
+ }
97
+ parser.end();
98
+ return formData;
99
+ }
100
+ var s, S, f, F, LF, CR, SPACE, HYPHEN, COLON, A, Z, lower, noop, MultipartParser;
101
+ var init_multipart_parser = __esm({
102
+ "node_modules/node-fetch/src/utils/multipart-parser.js"() {
103
+ init_from();
104
+ init_esm_min();
105
+ s = 0;
106
+ S = {
107
+ START_BOUNDARY: s++,
108
+ HEADER_FIELD_START: s++,
109
+ HEADER_FIELD: s++,
110
+ HEADER_VALUE_START: s++,
111
+ HEADER_VALUE: s++,
112
+ HEADER_VALUE_ALMOST_DONE: s++,
113
+ HEADERS_ALMOST_DONE: s++,
114
+ PART_DATA_START: s++,
115
+ PART_DATA: s++,
116
+ END: s++
117
+ };
118
+ f = 1;
119
+ F = {
120
+ PART_BOUNDARY: f,
121
+ LAST_BOUNDARY: f *= 2
122
+ };
123
+ LF = 10;
124
+ CR = 13;
125
+ SPACE = 32;
126
+ HYPHEN = 45;
127
+ COLON = 58;
128
+ A = 97;
129
+ Z = 122;
130
+ lower = (c) => c | 32;
131
+ noop = () => {
132
+ };
133
+ MultipartParser = class {
134
+ /**
135
+ * @param {string} boundary
136
+ */
137
+ constructor(boundary) {
138
+ this.index = 0;
139
+ this.flags = 0;
140
+ this.onHeaderEnd = noop;
141
+ this.onHeaderField = noop;
142
+ this.onHeadersEnd = noop;
143
+ this.onHeaderValue = noop;
144
+ this.onPartBegin = noop;
145
+ this.onPartData = noop;
146
+ this.onPartEnd = noop;
147
+ this.boundaryChars = {};
148
+ boundary = "\r\n--" + boundary;
149
+ const ui8a = new Uint8Array(boundary.length);
150
+ for (let i = 0; i < boundary.length; i++) {
151
+ ui8a[i] = boundary.charCodeAt(i);
152
+ this.boundaryChars[ui8a[i]] = true;
153
+ }
154
+ this.boundary = ui8a;
155
+ this.lookbehind = new Uint8Array(this.boundary.length + 8);
156
+ this.state = S.START_BOUNDARY;
157
+ }
158
+ /**
159
+ * @param {Uint8Array} data
160
+ */
161
+ write(data) {
162
+ let i = 0;
163
+ const length_ = data.length;
164
+ let previousIndex = this.index;
165
+ let { lookbehind, boundary, boundaryChars, index, state, flags } = this;
166
+ const boundaryLength = this.boundary.length;
167
+ const boundaryEnd = boundaryLength - 1;
168
+ const bufferLength = data.length;
169
+ let c;
170
+ let cl;
171
+ const mark = (name) => {
172
+ this[name + "Mark"] = i;
173
+ };
174
+ const clear = (name) => {
175
+ delete this[name + "Mark"];
176
+ };
177
+ const callback = (callbackSymbol, start, end, ui8a) => {
178
+ if (start === void 0 || start !== end) {
179
+ this[callbackSymbol](ui8a && ui8a.subarray(start, end));
180
+ }
181
+ };
182
+ const dataCallback = (name, clear2) => {
183
+ const markSymbol = name + "Mark";
184
+ if (!(markSymbol in this)) {
185
+ return;
186
+ }
187
+ if (clear2) {
188
+ callback(name, this[markSymbol], i, data);
189
+ delete this[markSymbol];
190
+ } else {
191
+ callback(name, this[markSymbol], data.length, data);
192
+ this[markSymbol] = 0;
193
+ }
194
+ };
195
+ for (i = 0; i < length_; i++) {
196
+ c = data[i];
197
+ switch (state) {
198
+ case S.START_BOUNDARY:
199
+ if (index === boundary.length - 2) {
200
+ if (c === HYPHEN) {
201
+ flags |= F.LAST_BOUNDARY;
202
+ } else if (c !== CR) {
203
+ return;
204
+ }
205
+ index++;
206
+ break;
207
+ } else if (index - 1 === boundary.length - 2) {
208
+ if (flags & F.LAST_BOUNDARY && c === HYPHEN) {
209
+ state = S.END;
210
+ flags = 0;
211
+ } else if (!(flags & F.LAST_BOUNDARY) && c === LF) {
212
+ index = 0;
213
+ callback("onPartBegin");
214
+ state = S.HEADER_FIELD_START;
215
+ } else {
216
+ return;
217
+ }
218
+ break;
219
+ }
220
+ if (c !== boundary[index + 2]) {
221
+ index = -2;
222
+ }
223
+ if (c === boundary[index + 2]) {
224
+ index++;
225
+ }
226
+ break;
227
+ case S.HEADER_FIELD_START:
228
+ state = S.HEADER_FIELD;
229
+ mark("onHeaderField");
230
+ index = 0;
231
+ // falls through
232
+ case S.HEADER_FIELD:
233
+ if (c === CR) {
234
+ clear("onHeaderField");
235
+ state = S.HEADERS_ALMOST_DONE;
236
+ break;
237
+ }
238
+ index++;
239
+ if (c === HYPHEN) {
240
+ break;
241
+ }
242
+ if (c === COLON) {
243
+ if (index === 1) {
244
+ return;
245
+ }
246
+ dataCallback("onHeaderField", true);
247
+ state = S.HEADER_VALUE_START;
248
+ break;
249
+ }
250
+ cl = lower(c);
251
+ if (cl < A || cl > Z) {
252
+ return;
253
+ }
254
+ break;
255
+ case S.HEADER_VALUE_START:
256
+ if (c === SPACE) {
257
+ break;
258
+ }
259
+ mark("onHeaderValue");
260
+ state = S.HEADER_VALUE;
261
+ // falls through
262
+ case S.HEADER_VALUE:
263
+ if (c === CR) {
264
+ dataCallback("onHeaderValue", true);
265
+ callback("onHeaderEnd");
266
+ state = S.HEADER_VALUE_ALMOST_DONE;
267
+ }
268
+ break;
269
+ case S.HEADER_VALUE_ALMOST_DONE:
270
+ if (c !== LF) {
271
+ return;
272
+ }
273
+ state = S.HEADER_FIELD_START;
274
+ break;
275
+ case S.HEADERS_ALMOST_DONE:
276
+ if (c !== LF) {
277
+ return;
278
+ }
279
+ callback("onHeadersEnd");
280
+ state = S.PART_DATA_START;
281
+ break;
282
+ case S.PART_DATA_START:
283
+ state = S.PART_DATA;
284
+ mark("onPartData");
285
+ // falls through
286
+ case S.PART_DATA:
287
+ previousIndex = index;
288
+ if (index === 0) {
289
+ i += boundaryEnd;
290
+ while (i < bufferLength && !(data[i] in boundaryChars)) {
291
+ i += boundaryLength;
292
+ }
293
+ i -= boundaryEnd;
294
+ c = data[i];
295
+ }
296
+ if (index < boundary.length) {
297
+ if (boundary[index] === c) {
298
+ if (index === 0) {
299
+ dataCallback("onPartData", true);
300
+ }
301
+ index++;
302
+ } else {
303
+ index = 0;
304
+ }
305
+ } else if (index === boundary.length) {
306
+ index++;
307
+ if (c === CR) {
308
+ flags |= F.PART_BOUNDARY;
309
+ } else if (c === HYPHEN) {
310
+ flags |= F.LAST_BOUNDARY;
311
+ } else {
312
+ index = 0;
313
+ }
314
+ } else if (index - 1 === boundary.length) {
315
+ if (flags & F.PART_BOUNDARY) {
316
+ index = 0;
317
+ if (c === LF) {
318
+ flags &= ~F.PART_BOUNDARY;
319
+ callback("onPartEnd");
320
+ callback("onPartBegin");
321
+ state = S.HEADER_FIELD_START;
322
+ break;
323
+ }
324
+ } else if (flags & F.LAST_BOUNDARY) {
325
+ if (c === HYPHEN) {
326
+ callback("onPartEnd");
327
+ state = S.END;
328
+ flags = 0;
329
+ } else {
330
+ index = 0;
331
+ }
332
+ } else {
333
+ index = 0;
334
+ }
335
+ }
336
+ if (index > 0) {
337
+ lookbehind[index - 1] = c;
338
+ } else if (previousIndex > 0) {
339
+ const _lookbehind = new Uint8Array(lookbehind.buffer, lookbehind.byteOffset, lookbehind.byteLength);
340
+ callback("onPartData", 0, previousIndex, _lookbehind);
341
+ previousIndex = 0;
342
+ mark("onPartData");
343
+ i--;
344
+ }
345
+ break;
346
+ case S.END:
347
+ break;
348
+ default:
349
+ throw new Error(`Unexpected state entered: ${state}`);
350
+ }
351
+ }
352
+ dataCallback("onHeaderField");
353
+ dataCallback("onHeaderValue");
354
+ dataCallback("onPartData");
355
+ this.index = index;
356
+ this.state = state;
357
+ this.flags = flags;
358
+ }
359
+ end() {
360
+ if (this.state === S.HEADER_FIELD_START && this.index === 0 || this.state === S.PART_DATA && this.index === this.boundary.length) {
361
+ this.onPartEnd();
362
+ } else if (this.state !== S.END) {
363
+ throw new Error("MultipartParser.end(): stream ended unexpectedly");
364
+ }
365
+ }
366
+ };
367
+ }
368
+ });
369
+ init_multipart_parser();
370
+ export {
371
+ toFormData
372
+ };