create-eliza
Version:
Initialize an Eliza project
2,579 lines (2,574 loc) • 1.11 MB
JavaScript
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
import {
require_buffer_from
} from "./chunk-RG4463OH.js";
import {
handleError
} from "./chunk-3GOUAKN6.js";
import {
require_has_flag
} from "./chunk-PXD72KH2.js";
import {
require_prompts
} from "./chunk-OGSHIQ3J.js";
import {
AgentServer,
require_cli_spinners,
require_inherits,
require_lib,
require_node,
require_object_assign,
require_type_is,
require_wcwidth
} from "./chunk-JNN6IVRQ.js";
import {
require_main,
require_signal_exit
} from "./chunk-ZMJ3QLUC.js";
import {
source_default
} from "./chunk-BY3DNMXE.js";
import {
AgentRuntime,
logger,
settings,
stringToUuid,
validateCharacterConfig
} from "./chunk-RYUT2GQB.js";
import {
Command
} from "./chunk-CKY7YPIS.js";
import {
__commonJS,
__require,
__toESM
} from "./chunk-WCMDOJQK.js";
// ../../node_modules/busboy/lib/utils.js
var require_utils = __commonJS({
"../../node_modules/busboy/lib/utils.js"(exports, module) {
"use strict";
function parseContentType(str) {
if (str.length === 0)
return;
const params = /* @__PURE__ */ Object.create(null);
let i = 0;
for (; i < str.length; ++i) {
const code = str.charCodeAt(i);
if (TOKEN[code] !== 1) {
if (code !== 47 || i === 0)
return;
break;
}
}
if (i === str.length)
return;
const type = str.slice(0, i).toLowerCase();
const subtypeStart = ++i;
for (; i < str.length; ++i) {
const code = str.charCodeAt(i);
if (TOKEN[code] !== 1) {
if (i === subtypeStart)
return;
if (parseContentTypeParams(str, i, params) === void 0)
return;
break;
}
}
if (i === subtypeStart)
return;
const subtype = str.slice(subtypeStart, i).toLowerCase();
return { type, subtype, params };
}
function parseContentTypeParams(str, i, params) {
while (i < str.length) {
for (; i < str.length; ++i) {
const code = str.charCodeAt(i);
if (code !== 32 && code !== 9)
break;
}
if (i === str.length)
break;
if (str.charCodeAt(i++) !== 59)
return;
for (; i < str.length; ++i) {
const code = str.charCodeAt(i);
if (code !== 32 && code !== 9)
break;
}
if (i === str.length)
return;
let name;
const nameStart = i;
for (; i < str.length; ++i) {
const code = str.charCodeAt(i);
if (TOKEN[code] !== 1) {
if (code !== 61)
return;
break;
}
}
if (i === str.length)
return;
name = str.slice(nameStart, i);
++i;
if (i === str.length)
return;
let value = "";
let valueStart;
if (str.charCodeAt(i) === 34) {
valueStart = ++i;
let escaping = false;
for (; i < str.length; ++i) {
const code = str.charCodeAt(i);
if (code === 92) {
if (escaping) {
valueStart = i;
escaping = false;
} else {
value += str.slice(valueStart, i);
escaping = true;
}
continue;
}
if (code === 34) {
if (escaping) {
valueStart = i;
escaping = false;
continue;
}
value += str.slice(valueStart, i);
break;
}
if (escaping) {
valueStart = i - 1;
escaping = false;
}
if (QDTEXT[code] !== 1)
return;
}
if (i === str.length)
return;
++i;
} else {
valueStart = i;
for (; i < str.length; ++i) {
const code = str.charCodeAt(i);
if (TOKEN[code] !== 1) {
if (i === valueStart)
return;
break;
}
}
value = str.slice(valueStart, i);
}
name = name.toLowerCase();
if (params[name] === void 0)
params[name] = value;
}
return params;
}
function parseDisposition(str, defDecoder) {
if (str.length === 0)
return;
const params = /* @__PURE__ */ Object.create(null);
let i = 0;
for (; i < str.length; ++i) {
const code = str.charCodeAt(i);
if (TOKEN[code] !== 1) {
if (parseDispositionParams(str, i, params, defDecoder) === void 0)
return;
break;
}
}
const type = str.slice(0, i).toLowerCase();
return { type, params };
}
function parseDispositionParams(str, i, params, defDecoder) {
while (i < str.length) {
for (; i < str.length; ++i) {
const code = str.charCodeAt(i);
if (code !== 32 && code !== 9)
break;
}
if (i === str.length)
break;
if (str.charCodeAt(i++) !== 59)
return;
for (; i < str.length; ++i) {
const code = str.charCodeAt(i);
if (code !== 32 && code !== 9)
break;
}
if (i === str.length)
return;
let name;
const nameStart = i;
for (; i < str.length; ++i) {
const code = str.charCodeAt(i);
if (TOKEN[code] !== 1) {
if (code === 61)
break;
return;
}
}
if (i === str.length)
return;
let value = "";
let valueStart;
let charset;
name = str.slice(nameStart, i);
if (name.charCodeAt(name.length - 1) === 42) {
const charsetStart = ++i;
for (; i < str.length; ++i) {
const code = str.charCodeAt(i);
if (CHARSET[code] !== 1) {
if (code !== 39)
return;
break;
}
}
if (i === str.length)
return;
charset = str.slice(charsetStart, i);
++i;
for (; i < str.length; ++i) {
const code = str.charCodeAt(i);
if (code === 39)
break;
}
if (i === str.length)
return;
++i;
if (i === str.length)
return;
valueStart = i;
let encode = 0;
for (; i < str.length; ++i) {
const code = str.charCodeAt(i);
if (EXTENDED_VALUE[code] !== 1) {
if (code === 37) {
let hexUpper;
let hexLower;
if (i + 2 < str.length && (hexUpper = HEX_VALUES[str.charCodeAt(i + 1)]) !== -1 && (hexLower = HEX_VALUES[str.charCodeAt(i + 2)]) !== -1) {
const byteVal = (hexUpper << 4) + hexLower;
value += str.slice(valueStart, i);
value += String.fromCharCode(byteVal);
i += 2;
valueStart = i + 1;
if (byteVal >= 128)
encode = 2;
else if (encode === 0)
encode = 1;
continue;
}
return;
}
break;
}
}
value += str.slice(valueStart, i);
value = convertToUTF8(value, charset, encode);
if (value === void 0)
return;
} else {
++i;
if (i === str.length)
return;
if (str.charCodeAt(i) === 34) {
valueStart = ++i;
let escaping = false;
for (; i < str.length; ++i) {
const code = str.charCodeAt(i);
if (code === 92) {
if (escaping) {
valueStart = i;
escaping = false;
} else {
value += str.slice(valueStart, i);
escaping = true;
}
continue;
}
if (code === 34) {
if (escaping) {
valueStart = i;
escaping = false;
continue;
}
value += str.slice(valueStart, i);
break;
}
if (escaping) {
valueStart = i - 1;
escaping = false;
}
if (QDTEXT[code] !== 1)
return;
}
if (i === str.length)
return;
++i;
} else {
valueStart = i;
for (; i < str.length; ++i) {
const code = str.charCodeAt(i);
if (TOKEN[code] !== 1) {
if (i === valueStart)
return;
break;
}
}
value = str.slice(valueStart, i);
}
value = defDecoder(value, 2);
if (value === void 0)
return;
}
name = name.toLowerCase();
if (params[name] === void 0)
params[name] = value;
}
return params;
}
function getDecoder(charset) {
let lc;
while (true) {
switch (charset) {
case "utf-8":
case "utf8":
return decoders.utf8;
case "latin1":
case "ascii":
// TODO: Make these a separate, strict decoder?
case "us-ascii":
case "iso-8859-1":
case "iso8859-1":
case "iso88591":
case "iso_8859-1":
case "windows-1252":
case "iso_8859-1:1987":
case "cp1252":
case "x-cp1252":
return decoders.latin1;
case "utf16le":
case "utf-16le":
case "ucs2":
case "ucs-2":
return decoders.utf16le;
case "base64":
return decoders.base64;
default:
if (lc === void 0) {
lc = true;
charset = charset.toLowerCase();
continue;
}
return decoders.other.bind(charset);
}
}
}
var decoders = {
utf8: (data, hint) => {
if (data.length === 0)
return "";
if (typeof data === "string") {
if (hint < 2)
return data;
data = Buffer.from(data, "latin1");
}
return data.utf8Slice(0, data.length);
},
latin1: (data, hint) => {
if (data.length === 0)
return "";
if (typeof data === "string")
return data;
return data.latin1Slice(0, data.length);
},
utf16le: (data, hint) => {
if (data.length === 0)
return "";
if (typeof data === "string")
data = Buffer.from(data, "latin1");
return data.ucs2Slice(0, data.length);
},
base64: (data, hint) => {
if (data.length === 0)
return "";
if (typeof data === "string")
data = Buffer.from(data, "latin1");
return data.base64Slice(0, data.length);
},
other: (data, hint) => {
if (data.length === 0)
return "";
if (typeof data === "string")
data = Buffer.from(data, "latin1");
try {
const decoder = new TextDecoder(exports);
return decoder.decode(data);
} catch {
}
}
};
function convertToUTF8(data, charset, hint) {
const decode = getDecoder(charset);
if (decode)
return decode(data, hint);
}
function basename(path5) {
if (typeof path5 !== "string")
return "";
for (let i = path5.length - 1; i >= 0; --i) {
switch (path5.charCodeAt(i)) {
case 47:
// '/'
case 92:
path5 = path5.slice(i + 1);
return path5 === ".." || path5 === "." ? "" : path5;
}
}
return path5 === ".." || path5 === "." ? "" : path5;
}
var TOKEN = [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
0,
1,
1,
1,
1,
1,
0,
0,
1,
1,
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,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
10,
11,
12,
13,
14,
15,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
10,
11,
12,
13,
14,
15,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1
];
module.exports = {
basename,
convertToUTF8,
getDecoder,
parseContentType,
parseDisposition
};
}
});
// ../../node_modules/streamsearch/lib/sbmh.js
var require_sbmh = __commonJS({
"../../node_modules/streamsearch/lib/sbmh.js"(exports, module) {
"use strict";
function memcmp(buf1, pos1, buf2, pos2, num) {
for (let i = 0; i < num; ++i) {
if (buf1[pos1 + i] !== buf2[pos2 + i])
return false;
}
return true;
}
var SBMH = class {
constructor(needle, cb) {
if (typeof cb !== "function")
throw new Error("Missing match callback");
if (typeof needle === "string")
needle = Buffer.from(needle);
else if (!Buffer.isBuffer(needle))
throw new Error(`Expected Buffer for needle, got ${typeof needle}`);
const needleLen = needle.length;
this.maxMatches = Infinity;
this.matches = 0;
this._cb = cb;
this._lookbehindSize = 0;
this._needle = needle;
this._bufPos = 0;
this._lookbehind = Buffer.allocUnsafe(needleLen);
this._occ = [
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen,
needleLen
];
if (needleLen > 1) {
for (let i = 0; i < needleLen - 1; ++i)
this._occ[needle[i]] = needleLen - 1 - i;
}
}
reset() {
this.matches = 0;
this._lookbehindSize = 0;
this._bufPos = 0;
}
push(chunk, pos) {
let result;
if (!Buffer.isBuffer(chunk))
chunk = Buffer.from(chunk, "latin1");
const chunkLen = chunk.length;
this._bufPos = pos || 0;
while (result !== chunkLen && this.matches < this.maxMatches)
result = feed(this, chunk);
return result;
}
destroy() {
const lbSize = this._lookbehindSize;
if (lbSize)
this._cb(false, this._lookbehind, 0, lbSize, false);
this.reset();
}
};
function feed(self2, data) {
const len = data.length;
const needle = self2._needle;
const needleLen = needle.length;
let pos = -self2._lookbehindSize;
const lastNeedleCharPos = needleLen - 1;
const lastNeedleChar = needle[lastNeedleCharPos];
const end = len - needleLen;
const occ = self2._occ;
const lookbehind = self2._lookbehind;
if (pos < 0) {
while (pos < 0 && pos <= end) {
const nextPos = pos + lastNeedleCharPos;
const ch = nextPos < 0 ? lookbehind[self2._lookbehindSize + nextPos] : data[nextPos];
if (ch === lastNeedleChar && matchNeedle(self2, data, pos, lastNeedleCharPos)) {
self2._lookbehindSize = 0;
++self2.matches;
if (pos > -self2._lookbehindSize)
self2._cb(true, lookbehind, 0, self2._lookbehindSize + pos, false);
else
self2._cb(true, void 0, 0, 0, true);
return self2._bufPos = pos + needleLen;
}
pos += occ[ch];
}
while (pos < 0 && !matchNeedle(self2, data, pos, len - pos))
++pos;
if (pos < 0) {
const bytesToCutOff = self2._lookbehindSize + pos;
if (bytesToCutOff > 0) {
self2._cb(false, lookbehind, 0, bytesToCutOff, false);
}
self2._lookbehindSize -= bytesToCutOff;
lookbehind.copy(lookbehind, 0, bytesToCutOff, self2._lookbehindSize);
lookbehind.set(data, self2._lookbehindSize);
self2._lookbehindSize += len;
self2._bufPos = len;
return len;
}
self2._cb(false, lookbehind, 0, self2._lookbehindSize, false);
self2._lookbehindSize = 0;
}
pos += self2._bufPos;
const firstNeedleChar = needle[0];
while (pos <= end) {
const ch = data[pos + lastNeedleCharPos];
if (ch === lastNeedleChar && data[pos] === firstNeedleChar && memcmp(needle, 0, data, pos, lastNeedleCharPos)) {
++self2.matches;
if (pos > 0)
self2._cb(true, data, self2._bufPos, pos, true);
else
self2._cb(true, void 0, 0, 0, true);
return self2._bufPos = pos + needleLen;
}
pos += occ[ch];
}
while (pos < len) {
if (data[pos] !== firstNeedleChar || !memcmp(data, pos, needle, 0, len - pos)) {
++pos;
continue;
}
data.copy(lookbehind, 0, pos, len);
self2._lookbehindSize = len - pos;
break;
}
if (pos > 0)
self2._cb(false, data, self2._bufPos, pos < len ? pos : len, true);
self2._bufPos = len;
return len;
}
function matchNeedle(self2, data, pos, len) {
const lb = self2._lookbehind;
const lbSize = self2._lookbehindSize;
const needle = self2._needle;
for (let i = 0; i < len; ++i, ++pos) {
const ch = pos < 0 ? lb[lbSize + pos] : data[pos];
if (ch !== needle[i])
return false;
}
return true;
}
module.exports = SBMH;
}
});
// ../../node_modules/busboy/lib/types/multipart.js
var require_multipart = __commonJS({
"../../node_modules/busboy/lib/types/multipart.js"(exports, module) {
"use strict";
var { Readable, Writable } = __require("stream");
var StreamSearch = require_sbmh();
var {
basename,
convertToUTF8,
getDecoder,
parseContentType,
parseDisposition
} = require_utils();
var BUF_CRLF = Buffer.from("\r\n");
var BUF_CR = Buffer.from("\r");
var BUF_DASH = Buffer.from("-");
function noop() {
}
var MAX_HEADER_PAIRS = 2e3;
var MAX_HEADER_SIZE = 16 * 1024;
var HPARSER_NAME = 0;
var HPARSER_PRE_OWS = 1;
var HPARSER_VALUE = 2;
var HeaderParser = class {
constructor(cb) {
this.header = /* @__PURE__ */ Object.create(null);
this.pairCount = 0;
this.byteCount = 0;
this.state = HPARSER_NAME;
this.name = "";
this.value = "";
this.crlf = 0;
this.cb = cb;
}
reset() {
this.header = /* @__PURE__ */ Object.create(null);
this.pairCount = 0;
this.byteCount = 0;
this.state = HPARSER_NAME;
this.name = "";
this.value = "";
this.crlf = 0;
}
push(chunk, pos, end) {
let start2 = pos;
while (pos < end) {
switch (this.state) {
case HPARSER_NAME: {
let done = false;
for (; pos < end; ++pos) {
if (this.byteCount === MAX_HEADER_SIZE)
return -1;
++this.byteCount;
const code = chunk[pos];
if (TOKEN[code] !== 1) {
if (code !== 58)
return -1;
this.name += chunk.latin1Slice(start2, pos);
if (this.name.length === 0)
return -1;
++pos;
done = true;
this.state = HPARSER_PRE_OWS;
break;
}
}
if (!done) {
this.name += chunk.latin1Slice(start2, pos);
break;
}
}
case HPARSER_PRE_OWS: {
let done = false;
for (; pos < end; ++pos) {
if (this.byteCount === MAX_HEADER_SIZE)
return -1;
++this.byteCount;
const code = chunk[pos];
if (code !== 32 && code !== 9) {
start2 = pos;
done = true;
this.state = HPARSER_VALUE;
break;
}
}
if (!done)
break;
}
case HPARSER_VALUE:
switch (this.crlf) {
case 0:
for (; pos < end; ++pos) {
if (this.byteCount === MAX_HEADER_SIZE)
return -1;
++this.byteCount;
const code = chunk[pos];
if (FIELD_VCHAR[code] !== 1) {
if (code !== 13)
return -1;
++this.crlf;
break;
}
}
this.value += chunk.latin1Slice(start2, pos++);
break;
case 1:
if (this.byteCount === MAX_HEADER_SIZE)
return -1;
++this.byteCount;
if (chunk[pos++] !== 10)
return -1;
++this.crlf;
break;
case 2: {
if (this.byteCount === MAX_HEADER_SIZE)
return -1;
++this.byteCount;
const code = chunk[pos];
if (code === 32 || code === 9) {
start2 = pos;
this.crlf = 0;
} else {
if (++this.pairCount < MAX_HEADER_PAIRS) {
this.name = this.name.toLowerCase();
if (this.header[this.name] === void 0)
this.header[this.name] = [this.value];
else
this.header[this.name].push(this.value);
}
if (code === 13) {
++this.crlf;
++pos;
} else {
start2 = pos;
this.crlf = 0;
this.state = HPARSER_NAME;
this.name = "";
this.value = "";
}
}
break;
}
case 3: {
if (this.byteCount === MAX_HEADER_SIZE)
return -1;
++this.byteCount;
if (chunk[pos++] !== 10)
return -1;
const header = this.header;
this.reset();
this.cb(header);
return pos;
}
}
break;
}
}
return pos;
}
};
var FileStream = class extends Readable {
constructor(opts, owner) {
super(opts);
this.truncated = false;
this._readcb = null;
this.once("end", () => {
this._read();
if (--owner._fileEndsLeft === 0 && owner._finalcb) {
const cb = owner._finalcb;
owner._finalcb = null;
process.nextTick(cb);
}
});
}
_read(n) {
const cb = this._readcb;
if (cb) {
this._readcb = null;
cb();
}
}
};
var ignoreData = {
push: (chunk, pos) => {
},
destroy: () => {
}
};
function callAndUnsetCb(self2, err) {
const cb = self2._writecb;
self2._writecb = null;
if (err)
self2.destroy(err);
else if (cb)
cb();
}
function nullDecoder(val, hint) {
return val;
}
var Multipart = class extends Writable {
constructor(cfg) {
const streamOpts = {
autoDestroy: true,
emitClose: true,
highWaterMark: typeof cfg.highWaterMark === "number" ? cfg.highWaterMark : void 0
};
super(streamOpts);
if (!cfg.conType.params || typeof cfg.conType.params.boundary !== "string")
throw new Error("Multipart: Boundary not found");
const boundary = cfg.conType.params.boundary;
const paramDecoder = typeof cfg.defParamCharset === "string" && cfg.defParamCharset ? getDecoder(cfg.defParamCharset) : nullDecoder;
const defCharset = cfg.defCharset || "utf8";
const preservePath = cfg.preservePath;
const fileOpts = {
autoDestroy: true,
emitClose: true,
highWaterMark: typeof cfg.fileHwm === "number" ? cfg.fileHwm : void 0
};
const limits = cfg.limits;
const fieldSizeLimit = limits && typeof limits.fieldSize === "number" ? limits.fieldSize : 1 * 1024 * 1024;
const fileSizeLimit = limits && typeof limits.fileSize === "number" ? limits.fileSize : Infinity;
const filesLimit = limits && typeof limits.files === "number" ? limits.files : Infinity;
const fieldsLimit = limits && typeof limits.fields === "number" ? limits.fields : Infinity;
const partsLimit = limits && typeof limits.parts === "number" ? limits.parts : Infinity;
let parts = -1;
let fields = 0;
let files = 0;
let skipPart = false;
this._fileEndsLeft = 0;
this._fileStream = void 0;
this._complete = false;
let fileSize = 0;
let field;
let fieldSize = 0;
let partCharset;
let partEncoding;
let partType;
let partName;
let partTruncated = false;
let hitFilesLimit = false;
let hitFieldsLimit = false;
this._hparser = null;
const hparser = new HeaderParser((header) => {
this._hparser = null;
skipPart = false;
partType = "text/plain";
partCharset = defCharset;
partEncoding = "7bit";
partName = void 0;
partTruncated = false;
let filename;
if (!header["content-disposition"]) {
skipPart = true;
return;
}
const disp = parseDisposition(
header["content-disposition"][0],
paramDecoder
);
if (!disp || disp.type !== "form-data") {
skipPart = true;
return;
}
if (disp.params) {
if (disp.params.name)
partName = disp.params.name;
if (disp.params["filename*"])
filename = disp.params["filename*"];
else if (disp.params.filename)
filename = disp.params.filename;
if (filename !== void 0 && !preservePath)
filename = basename(filename);
}
if (header["content-type"]) {
const conType = parseContentType(header["content-type"][0]);
if (conType) {
partType = `${conType.type}/${conType.subtype}`;
if (conType.params && typeof conType.params.charset === "string")
partCharset = conType.params.charset.toLowerCase();
}
}
if (header["content-transfer-encoding"])
partEncoding = header["content-transfer-encoding"][0].toLowerCase();
if (partType === "application/octet-stream" || filename !== void 0) {
if (files === filesLimit) {
if (!hitFilesLimit) {
hitFilesLimit = true;
this.emit("filesLimit");
}
skipPart = true;
return;
}
++files;
if (this.listenerCount("file") === 0) {
skipPart = true;
return;
}
fileSize = 0;
this._fileStream = new FileStream(fileOpts, this);
++this._fileEndsLeft;
this.emit(
"file",
partName,
this._fileStream,
{
filename,
encoding: partEncoding,
mimeType: partType
}
);
} else {
if (fields === fieldsLimit) {
if (!hitFieldsLimit) {
hitFieldsLimit = true;
this.emit("fieldsLimit");
}
skipPart = true;
return;
}
++fields;
if (this.listenerCount("field") === 0) {
skipPart = true;
return;
}
field = [];
fieldSize = 0;
}
});
let matchPostBoundary = 0;
const ssCb = (isMatch, data, start2, end, isDataSafe) => {
retrydata:
while (data) {
if (this._hparser !== null) {
const ret = this._hparser.push(data, start2, end);
if (ret === -1) {
this._hparser = null;
hparser.reset();
this.emit("error", new Error("Malformed part header"));
break;
}
start2 = ret;
}
if (start2 === end)
break;
if (matchPostBoundary !== 0) {
if (matchPostBoundary === 1) {
switch (data[start2]) {
case 45:
matchPostBoundary = 2;
++start2;
break;
case 13:
matchPostBoundary = 3;
++start2;
break;
default:
matchPostBoundary = 0;
}
if (start2 === end)
return;
}
if (matchPostBoundary === 2) {
matchPostBoundary = 0;
if (data[start2] === 45) {
this._complete = true;
this._bparser = ignoreData;
return;
}
const writecb = this._writecb;
this._writecb = noop;
ssCb(false, BUF_DASH, 0, 1, false);
this._writecb = writecb;
} else if (matchPostBoundary === 3) {
matchPostBoundary = 0;
if (data[start2] === 10) {
++start2;
if (parts >= partsLimit)
break;
this._hparser = hparser;
if (start2 === end)
break;
continue retrydata;
} else {
const writecb = this._writecb;
this._writecb = noop;
ssCb(false, BUF_CR, 0, 1, false);
this._writecb = writecb;
}
}
}
if (!skipPart) {
if (this._fileStream) {
let chunk;
const actualLen = Math.min(end - start2, fileSizeLimit - fileSize);
if (!isDataSafe) {
chunk = Buffer.allocUnsafe(actualLen);
data.copy(chunk, 0, start2, start2 + actualLen);
} else {
chunk = data.slice(start2, start2 + actualLen);
}
fileSize += chunk.length;
if (fileSize === fileSizeLimit) {
if (chunk.length > 0)
this._fileStream.push(chunk);
this._fileStream.emit("limit");
this._fileStream.truncated = true;
skipPart = true;
} else if (!this._fileStream.push(chunk)) {
if (this._writecb)
this._fileStream._readcb = this._writecb;
this._writecb = null;
}
} else if (field !== void 0) {
let chunk;
const actualLen = Math.min(
end - start2,
fieldSizeLimit - fieldSize
);
if (!isDataSafe) {
chunk = Buffer.allocUnsafe(actualLen);
data.copy(chunk, 0, start2, start2 + actualLen);
} else {
chunk = data.slice(start2, start2 + actualLen);
}
fieldSize += actualLen;
field.push(chunk);
if (fieldSize === fieldSizeLimit) {
skipPart = true;
partTruncated = true;
}
}
}
break;
}
if (isMatch) {
matchPostBoundary = 1;
if (this._fileStream) {
this._fileStream.push(null);
this._fileStream = null;
} else if (field !== void 0) {
let data2;
switch (field.length) {
case 0:
data2 = "";
break;
cas