Quellverzeichnis wllama-module-dev.mjs
Interaktion und Portierbarkeitunbekannt
|
|
Haftungsausschluß.mjs KontaktUnknown {[0] [0] [0]}diese Dinge liegen außhalb unserer Verantwortung
// src/glue/messages.ts
var GLUE_VERSION = 1;
var GLUE_MESSAGE_PROTOTYPES = {
"erro_evt": {
"name": "erro_evt",
"structName": "glue_msg_error",
"className": "GlueMsgError",
"fields": [
{
"type": "str",
"name": "message",
"isNullable": false
}
]
},
"load_req": {
"name": "load_req",
"structName": "glue_msg_load_req",
"className": "GlueMsgLoadReq",
"fields": [
{
"type": "arr_str",
"name": "model_paths",
"isNullable": false
},
{
"type": "bool",
"name": "n_ctx_auto",
"isNullable": false
},
{
"type": "bool",
"name": "use_mmap",
"isNullable": false
},
{
"type": "bool",
"name": "use_mlock",
"isNullable": false
},
{
"type": "int",
"name": "n_gpu_layers",
"isNullable": false
},
{
"type": "int",
"name": "seed",
"isNullable": false
},
{
"type": "int",
"name": "n_ctx",
"isNullable": false
},
{
"type": "int",
"name": "n_threads",
"isNullable": false
},
{
"type": "bool",
"name": "embeddings",
"isNullable": true
},
{
"type": "bool",
"name": "offload_kqv",
"isNullable": true
},
{
"type": "int",
"name": "n_batch",
"isNullable": true
},
{
"type": "int",
"name": "n_seq_max",
"isNullable": true
},
{
"type": "str",
"name": "pooling_type",
"isNullable": true
},
{
"type": "str",
"name": "rope_scaling_type",
"isNullable": true
},
{
"type": "float",
"name": "rope_freq_base",
"isNullable": true
},
{
"type": "float",
"name": "rope_freq_scale",
"isNullable": true
},
{
"type": "float",
"name": "yarn_ext_factor",
"isNullable": true
},
{
"type": "float",
"name": "yarn_attn_factor",
"isNullable": true
},
{
"type": "float",
"name": "yarn_beta_fast",
"isNullable": true
},
{
"type": "float",
"name": "yarn_beta_slow",
"isNullable": true
},
{
"type": "int",
"name": "yarn_orig_ctx",
"isNullable": true
},
{
"type": "str",
"name": "cache_type_k",
"isNullable": true
},
{
"type": "str",
"name": "cache_type_v",
"isNullable": true
},
{
"type": "int",
"name": "n_ubatch",
"isNullable": true
},
{
"type": "bool",
"name": "flash_attn",
"isNullable": true
},
{
"type": "int",
"name": "n_threads_decoding",
"isNullable": true
}
]
},
"load_res": {
"name": "load_res",
"structName": "glue_msg_load_res",
"className": "GlueMsgLoadRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
},
{
"type": "int",
"name": "n_ctx",
"isNullable": false
},
{
"type": "int",
"name": "n_batch",
"isNullable": false
},
{
"type": "int",
"name": "n_ubatch",
"isNullable": false
},
{
"type": "int",
"name": "n_vocab",
"isNullable": false
},
{
"type": "int",
"name": "n_ctx_train",
"isNullable": false
},
{
"type": "int",
"name": "n_embd",
"isNullable": false
},
{
"type": "int",
"name": "n_layer",
"isNullable": false
},
{
"type": "arr_str",
"name": "metadata_key",
"isNullable": false
},
{
"type": "arr_str",
"name": "metadata_val",
"isNullable": false
},
{
"type": "int",
"name": "token_bos",
"isNullable": false
},
{
"type": "int",
"name": "token_eos",
"isNullable": false
},
{
"type": "int",
"name": "token_eot",
"isNullable": false
},
{
"type": "arr_int",
"name": "list_tokens_eog",
"isNullable": false
},
{
"type": "bool",
"name": "add_bos_token",
"isNullable": false
},
{
"type": "bool",
"name": "add_eos_token",
"isNullable": false
},
{
"type": "bool",
"name": "has_encoder",
"isNullable": false
},
{
"type": "int",
"name": "token_decoder_start",
"isNullable": false
}
]
},
"opti_req": {
"name": "opti_req",
"structName": "glue_msg_set_options_req",
"className": "GlueMsgSetOptionsReq",
"fields": [
{
"type": "bool",
"name": "embeddings",
"isNullable": false
}
]
},
"opti_res": {
"name": "opti_res",
"structName": "glue_msg_set_options_res",
"className": "GlueMsgSetOptionsRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
}
]
},
"sint_req": {
"name": "sint_req",
"structName": "glue_msg_sampling_init_req",
"className": "GlueMsgSamplingInitReq",
"fields": [
{
"type": "int",
"name": "mirostat",
"isNullable": true
},
{
"type": "float",
"name": "mirostat_tau",
"isNullable": true
},
{
"type": "float",
"name": "mirostat_eta",
"isNullable": true
},
{
"type": "float",
"name": "temp",
"isNullable": true
},
{
"type": "float",
"name": "top_p",
"isNullable": true
},
{
"type": "int",
"name": "top_k",
"isNullable": true
},
{
"type": "int",
"name": "penalty_last_n",
"isNullable": true
},
{
"type": "float",
"name": "penalty_repeat",
"isNullable": true
},
{
"type": "float",
"name": "penalty_freq",
"isNullable": true
},
{
"type": "float",
"name": "penalty_present",
"isNullable": true
},
{
"type": "float",
"name": "dynatemp_range",
"isNullable": true
},
{
"type": "float",
"name": "dynatemp_exponent",
"isNullable": true
},
{
"type": "arr_str",
"name": "samplers_sequence",
"isNullable": true
},
{
"type": "str",
"name": "grammar",
"isNullable": true
},
{
"type": "int",
"name": "n_prev",
"isNullable": true
},
{
"type": "int",
"name": "n_probs",
"isNullable": true
},
{
"type": "float",
"name": "min_p",
"isNullable": true
},
{
"type": "float",
"name": "typical_p",
"isNullable": true
},
{
"type": "float",
"name": "typ_p",
"isNullable": true
},
{
"type": "arr_int",
"name": "logit_bias_toks",
"isNullable": true
},
{
"type": "arr_float",
"name": "logit_bias_vals",
"isNullable": true
},
{
"type": "arr_int",
"name": "tokens",
"isNullable": true
}
]
},
"sint_res": {
"name": "sint_res",
"structName": "glue_msg_sampling_init_res",
"className": "GlueMsgSamplingInitRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
}
]
},
"gvoc_req": {
"name": "gvoc_req",
"structName": "glue_msg_get_vocab_req",
"className": "GlueMsgGetVocabReq",
"fields": []
},
"gvoc_res": {
"name": "gvoc_res",
"structName": "glue_msg_get_vocab_res",
"className": "GlueMsgGetVocabRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
},
{
"type": "arr_raw",
"name": "vocab",
"isNullable": false
}
]
},
"lkup_req": {
"name": "lkup_req",
"structName": "glue_msg_lookup_token_req",
"className": "GlueMsgLookupTokenReq",
"fields": [
{
"type": "str",
"name": "piece",
"isNullable": false
}
]
},
"lkup_res": {
"name": "lkup_res",
"structName": "glue_msg_lookup_token_res",
"className": "GlueMsgLookupTokenRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
},
{
"type": "int",
"name": "token",
"isNullable": false
}
]
},
"tokn_req": {
"name": "tokn_req",
"structName": "glue_msg_tokenize_req",
"className": "GlueMsgTokenizeReq",
"fields": [
{
"type": "str",
"name": "text",
"isNullable": false
},
{
"type": "bool",
"name": "special",
"isNullable": false
}
]
},
"tokn_res": {
"name": "tokn_res",
"structName": "glue_msg_tokenize_res",
"className": "GlueMsgTokenizeRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
},
{
"type": "arr_int",
"name": "tokens",
"isNullable": false
}
]
},
"dtkn_req": {
"name": "dtkn_req",
"structName": "glue_msg_detokenize_req",
"className": "GlueMsgDetokenizeReq",
"fields": [
{
"type": "arr_int",
"name": "tokens",
"isNullable": false
}
]
},
"dtkn_res": {
"name": "dtkn_res",
"structName": "glue_msg_detokenize_res",
"className": "GlueMsgDetokenizeRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
},
{
"type": "raw",
"name": "buffer",
"isNullable": false
}
]
},
"deco_req": {
"name": "deco_req",
"structName": "glue_msg_decode_req",
"className": "GlueMsgDecodeReq",
"fields": [
{
"type": "arr_int",
"name": "tokens",
"isNullable": false
},
{
"type": "bool",
"name": "skip_logits",
"isNullable": false
}
]
},
"deco_res": {
"name": "deco_res",
"structName": "glue_msg_decode_res",
"className": "GlueMsgDecodeRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
},
{
"type": "str",
"name": "message",
"isNullable": false
},
{
"type": "int",
"name": "n_past",
"isNullable": false
}
]
},
"enco_req": {
"name": "enco_req",
"structName": "glue_msg_encode_req",
"className": "GlueMsgEncodeReq",
"fields": [
{
"type": "arr_int",
"name": "tokens",
"isNullable": false
}
]
},
"enco_res": {
"name": "enco_res",
"structName": "glue_msg_encode_res",
"className": "GlueMsgEncodeRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
},
{
"type": "str",
"name": "message",
"isNullable": false
},
{
"type": "int",
"name": "n_past",
"isNullable": false
}
]
},
"ssam_req": {
"name": "ssam_req",
"structName": "glue_msg_sampling_sample_req",
"className": "GlueMsgSamplingSampleReq",
"fields": []
},
"ssam_res": {
"name": "ssam_res",
"structName": "glue_msg_sampling_sample_res",
"className": "GlueMsgSamplingSampleRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
},
{
"type": "raw",
"name": "piece",
"isNullable": false
},
{
"type": "int",
"name": "token",
"isNullable": false
}
]
},
"sacc_req": {
"name": "sacc_req",
"structName": "glue_msg_sampling_accept_req",
"className": "GlueMsgSamplingAcceptReq",
"fields": [
{
"type": "arr_int",
"name": "tokens",
"isNullable": false
}
]
},
"sacc_res": {
"name": "sacc_res",
"structName": "glue_msg_sampling_accept_res",
"className": "GlueMsgSamplingAcceptRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
}
]
},
"glog_req": {
"name": "glog_req",
"structName": "glue_msg_get_logits_req",
"className": "GlueMsgGetLogitsReq",
"fields": [
{
"type": "int",
"name": "top_k",
"isNullable": false
}
]
},
"glog_res": {
"name": "glog_res",
"structName": "glue_msg_get_logits_res",
"className": "GlueMsgGetLogitsRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
},
{
"type": "arr_int",
"name": "tokens",
"isNullable": false
},
{
"type": "arr_float",
"name": "probs",
"isNullable": false
}
]
},
"gemb_req": {
"name": "gemb_req",
"structName": "glue_msg_get_embeddings_req",
"className": "GlueMsgGetEmbeddingsReq",
"fields": [
{
"type": "arr_int",
"name": "tokens",
"isNullable": false
}
]
},
"gemb_res": {
"name": "gemb_res",
"structName": "glue_msg_get_embeddings_res",
"className": "GlueMsgGetEmbeddingsRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
},
{
"type": "str",
"name": "message",
"isNullable": false
},
{
"type": "arr_float",
"name": "embeddings",
"isNullable": false
}
]
},
"kvcr_req": {
"name": "kvcr_req",
"structName": "glue_msg_get_kv_remove_req",
"className": "GlueMsgGetKvRemoveReq",
"fields": [
{
"type": "int",
"name": "n_keep",
"isNullable": false
},
{
"type": "int",
"name": "n_discard",
"isNullable": false
}
]
},
"kvcr_res": {
"name": "kvcr_res",
"structName": "glue_msg_get_kv_remove_res",
"className": "GlueMsgGetKvRemoveRes",
"fields": [
{
"type": "int",
"name": "n_past",
"isNullable": false
},
{
"type": "bool",
"name": "success",
"isNullable": false
}
]
},
"kvcc_req": {
"name": "kvcc_req",
"structName": "glue_msg_get_kv_clear_req",
"className": "GlueMsgGetKvClearReq",
"fields": []
},
"kvcc_res": {
"name": "kvcc_res",
"structName": "glue_msg_get_kv_clear_res",
"className": "GlueMsgGetKvClearRes",
"fields": [
{
"type": "int",
"name": "n_past",
"isNullable": false
},
{
"type": "bool",
"name": "success",
"isNullable": false
}
]
},
"sesa_req": {
"name": "sesa_req",
"structName": "glue_msg_session_save_req",
"className": "GlueMsgSessionSaveReq",
"fields": [
{
"type": "str",
"name": "session_path",
"isNullable": false
}
]
},
"sesa_res": {
"name": "sesa_res",
"structName": "glue_msg_session_save_res",
"className": "GlueMsgSessionSaveRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
},
{
"type": "arr_int",
"name": "tokens",
"isNullable": false
}
]
},
"sesl_req": {
"name": "sesl_req",
"structName": "glue_msg_session_load_req",
"className": "GlueMsgSessionLoadReq",
"fields": [
{
"type": "str",
"name": "session_path",
"isNullable": false
},
{
"type": "arr_int",
"name": "tokens",
"isNullable": false
}
]
},
"sesl_res": {
"name": "sesl_res",
"structName": "glue_msg_session_load_res",
"className": "GlueMsgSessionLoadRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
}
]
},
"stat_req": {
"name": "stat_req",
"structName": "glue_msg_status_req",
"className": "GlueMsgStatusReq",
"fields": []
},
"stat_res": {
"name": "stat_res",
"structName": "glue_msg_status_res",
"className": "GlueMsgStatusRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
},
{
"type": "arr_int",
"name": "tokens",
"isNullable": false
}
]
},
"tben_req": {
"name": "tben_req",
"structName": "glue_msg_test_benchmark_req",
"className": "GlueMsgTestBenchmarkReq",
"fields": [
{
"type": "str",
"name": "type",
"isNullable": false
},
{
"type": "int",
"name": "n_samples",
"isNullable": false
}
]
},
"tben_res": {
"name": "tben_res",
"structName": "glue_msg_test_benchmark_res",
"className": "GlueMsgTestBenchmarkRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
},
{
"type": "str",
"name": "message",
"isNullable": false
},
{
"type": "int",
"name": "t_ms",
"isNullable": false
}
]
},
"tper_req": {
"name": "tper_req",
"structName": "glue_msg_test_perplexity_req",
"className": "GlueMsgTestPerplexityReq",
"fields": [
{
"type": "arr_int",
"name": "tokens",
"isNullable": false
}
]
},
"tper_res": {
"name": "tper_res",
"structName": "glue_msg_test_perplexity_res",
"className": "GlueMsgTestPerplexityRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
},
{
"type": "str",
"name": "message",
"isNullable": false
},
{
"type": "float",
"name": "ppl",
"isNullable": false
},
{
"type": "float",
"name": "nll",
"isNullable": false
},
{
"type": "float",
"name": "cross_entropy",
"isNullable": false
},
{
"type": "int",
"name": "n_tokens",
"isNullable": false
},
{
"type": "int",
"name": "t_ms",
"isNullable": false
}
]
},
"cfmt_req": {
"name": "cfmt_req",
"structName": "glue_msg_chat_format_req",
"className": "GlueMsgChatFormatReq",
"fields": [
{
"type": "str",
"name": "tmpl",
"isNullable": true
},
{
"type": "bool",
"name": "add_ass",
"isNullable": true
},
{
"type": "arr_str",
"name": "roles",
"isNullable": false
},
{
"type": "arr_str",
"name": "contents",
"isNullable": false
}
]
},
"cfmt_res": {
"name": "cfmt_res",
"structName": "glue_msg_chat_format_res",
"className": "GlueMsgChatFormatRes",
"fields": [
{
"type": "bool",
"name": "success",
"isNullable": false
},
{
"type": "str",
"name": "message",
"isNullable": false
},
{
"type": "str",
"name": "formatted_chat",
"isNullable": false
}
]
}
};
// src/glue/glue.ts
var GLUE_MAGIC = new Uint8Array([ 71, 76, 85, 69]);
var GLUE_DTYPE_NULL = 0;
var GLUE_DTYPE_BOOL = 1;
var GLUE_DTYPE_INT = 2;
var GLUE_DTYPE_FLOAT = 3;
var GLUE_DTYPE_STRING = 4;
var GLUE_DTYPE_RAW = 5;
var GLUE_DTYPE_ARRAY_BOOL = 6;
var GLUE_DTYPE_ARRAY_INT = 7;
var GLUE_DTYPE_ARRAY_FLOAT = 8;
var GLUE_DTYPE_ARRAY_STRING = 9;
var GLUE_DTYPE_ARRAY_RAW = 10;
var TYPE_MAP = {
str: GLUE_DTYPE_STRING,
int: GLUE_DTYPE_INT,
float: GLUE_DTYPE_FLOAT,
bool: GLUE_DTYPE_BOOL,
raw: GLUE_DTYPE_RAW,
arr_str: GLUE_DTYPE_ARRAY_STRING,
arr_int: GLUE_DTYPE_ARRAY_INT,
arr_float: GLUE_DTYPE_ARRAY_FLOAT,
arr_bool: GLUE_DTYPE_ARRAY_BOOL,
arr_raw: GLUE_DTYPE_ARRAY_RAW,
null: GLUE_DTYPE_NULL
};
function glueDeserialize(buf) {
let offset = 0;
const view = new DataView(buf.buffer);
const readUint32 = () => {
const value = view.getUint32(offset, true);
offset += 4;
return value;
};
const readInt32 = () => {
const value = view.getInt32(offset, true);
offset += 4;
return value;
};
const readFloat = () => {
const value = view.getFloat32(offset, true);
offset += 4;
return value;
};
const readBool = () => {
return readUint32() !== 0;
};
const readString = (customLen) => {
const length = customLen ?? readUint32();
const value = new TextDecoder().decode(buf.slice(offset, offset + length));
offset += length;
return value;
};
const readRaw = () => {
const length = readUint32();
const value = buf.slice(offset, offset + length);
offset += length;
return value;
};
const readArray = (readItem) => {
const length = readUint32();
const value = new Array(length);
for (let i = 0; i < length; i++) {
value[i] = readItem();
}
return value;
};
const readNull = () => null;
const readField = (field) => {
switch (field.type) {
case "str":
return readString();
case "int":
return readInt32();
case "float":
return readFloat();
case "bool":
return readBool();
case "raw":
return readRaw();
case "arr_str":
return readArray(readString);
case "arr_int":
return readArray(readInt32);
case "arr_float":
return readArray(readFloat);
case "arr_bool":
return readArray(readBool);
case "arr_raw":
return readArray(readRaw);
case "null":
return readNull();
}
};
const magicValid = buf[ 0] === GLUE_MAGIC[ 0] && buf[ 1] === GLUE_MAGIC[ 1] && buf[ 2] === GLUE_MAGIC[ 2] && buf[ 3] === GLUE_MAGIC[ 3];
offset += 4;
if (!magicValid) {
throw new Error("Invalid magic number");
}
const version = readUint32();
if (version !== GLUE_VERSION) {
throw new Error("Invalid version number");
}
const name = readString( 8);
const msgProto = GLUE_MESSAGE_PROTOTYPES[name];
if (!msgProto) {
throw new Error(`Unknown message name: ${name}`);
}
const output = { _name: name };
for (const field of msgProto.fields) {
const readType = readUint32();
if (readType === GLUE_DTYPE_NULL) {
if (!field.isNullable) {
throw new Error(
`${name}: Expect field ${field.name} to be non-nullable`
);
}
output[field.name] = null;
continue;
}
if (readType !== TYPE_MAP[field.type]) {
throw new Error(
`${name}: Expect field ${field.name} to have type ${field.type}`
);
}
output[field.name] = readField(field);
}
return output;
}
function glueSerialize(msg) {
const msgProto = GLUE_MESSAGE_PROTOTYPES[msg._name];
if (!msgProto) {
throw new Error(`Unknown message name: ${msg._name}`);
}
const bufs = [];
const writeUint32 = (value) => {
const buf = new ArrayBuffer( 4);
new DataView(buf).setUint32( 0, value, true);
bufs.push(new Uint8Array(buf));
};
const writeInt32 = (value) => {
const buf = new ArrayBuffer( 4);
new DataView(buf).setInt32( 0, value, true);
bufs.push(new Uint8Array(buf));
};
const writeFloat = (value) => {
const buf = new ArrayBuffer( 4);
new DataView(buf).setFloat32( 0, value, true);
bufs.push(new Uint8Array(buf));
};
const writeBool = (value) => {
writeUint32(value ? 1 : 0);
};
const writeString = (value) => {
const utf8 = new TextEncoder().encode(value);
writeUint32(utf8.byteLength);
bufs.push(utf8);
};
const writeRaw = (value) => {
writeUint32(value.byteLength);
bufs.push(value);
};
const writeArray = (value, writeItem) => {
writeUint32(value.length);
for (const item of value) {
writeItem(item);
}
};
const writeNull = () => {
};
bufs.push(GLUE_MAGIC);
writeUint32(GLUE_VERSION);
{
const utf8 = new TextEncoder().encode(msg._name);
bufs.push(utf8);
}
for (const field of msgProto.fields) {
const val = msg[field.name];
if (!field.isNullable && (val === null || val === void 0)) {
throw new Error(
`${msg._name}: Expect field ${field.name} to be non-nullable`
);
}
if (val === null || val === void 0) {
writeUint32(GLUE_DTYPE_NULL);
continue;
}
writeUint32(TYPE_MAP[field.type]);
switch (field.type) {
case "str":
writeString(val);
break;
case "int":
writeInt32(val);
break;
case "float":
writeFloat(val);
break;
case "bool":
writeBool(val);
break;
case "raw":
writeRaw(val);
break;
case "arr_str":
writeArray(val, writeString);
break;
case "arr_int":
writeArray(val, writeInt32);
break;
case "arr_float":
writeArray(val, writeFloat);
break;
case "arr_bool":
writeArray(val, writeBool);
break;
case "arr_raw":
writeArray(val, writeRaw);
break;
case "null":
writeNull();
break;
}
}
const totalLength = bufs.reduce((acc, buf) => acc + buf.byteLength, 0);
const output = new Uint8Array(totalLength);
let offset = 0;
for (const buf of bufs) {
output.set(buf, offset);
offset += buf.byteLength;
}
return output;
}
// src/utils.ts
var joinBuffers = (buffers) => {
const totalSize = buffers.reduce((acc, buf) => acc + buf.length, 0);
const output = new Uint8Array(totalSize);
output.set(buffers[ 0], 0);
for (let i = 1; i < buffers.length; i++) {
output.set(buffers[i], buffers[i - 1].length);
}
return output;
};
var textDecoder = new TextDecoder();
var bufToText = (buffer) => {
return textDecoder.decode(buffer);
};
var URL_PARTS_REGEX = /-(\d{ 5})-of-(\d{ 5})\.gguf$/;
var parseShardNumber = (fnameOrUrl) => {
const matches = fnameOrUrl.match(URL_PARTS_REGEX);
if (!matches) {
return {
baseURL: fnameOrUrl,
current: 1,
total: 1
};
} else {
return {
baseURL: fnameOrUrl.replace(URL_PARTS_REGEX, ""),
current: parseInt(matches[ 1]),
total: parseInt(matches[ 2])
};
}
};
var sortFileByShard = (blobs) => {
const isFiles = blobs.every((b) => !!b.name);
if (isFiles && blobs.length > 1) {
const files = blobs;
files.sort((a, b) => {
const infoA = parseShardNumber(a.name);
const infoB = parseShardNumber(b.name);
return infoA.current - infoB.current;
});
}
};
var absoluteUrl = (relativePath) => relativePath;
var sumArr = (arr) => arr.reduce((prev, curr) => prev + curr, 0);
var isString = (value) => !!value?.startsWith;
var isSupportMultiThread = () => (async (e) => {
try {
return "undefined" != typeof MessageChannel && new MessageChannel().port1.postMessage(new SharedArrayBuffer(1)), WebAssembly.validate(e);
} catch (e2) {
return false;
}
})(
new Uint8Array([
0,
97,
115,
109,
1,
0,
0,
0,
1,
4,
1,
96,
0,
0,
3,
2,
1,
0,
5,
4,
1,
3,
1,
1,
10,
11,
1,
9,
0,
65,
0,
254,
16,
2,
0,
26,
11
])
);
var isSupportExceptions = async () => WebAssembly.validate(
new Uint8Array([
0,
97,
115,
109,
1,
0,
0,
0,
1,
4,
1,
96,
0,
0,
3,
2,
1,
0,
10,
8,
1,
6,
0,
6,
64,
25,
11,
11
])
);
var isSupportSIMD = async () => WebAssembly.validate(
new Uint8Array([
0,
97,
115,
109,
1,
0,
0,
0,
1,
5,
1,
96,
0,
1,
123,
3,
2,
1,
0,
10,
10,
1,
8,
0,
65,
0,
253,
15,
253,
98,
11
])
);
var checkEnvironmentCompatible = async () => {
if (!await isSupportExceptions()) {
throw new Error("WebAssembly runtime does not support exception handling");
}
if (!await isSupportSIMD()) {
throw new Error("WebAssembly runtime does not support SIMD");
}
};
var isSafariMobile = () => {
return !!navigator.userAgent.match(/Version\/([0-9\._]+).*Mobile.*Safari.*/);
};
var createWorker = (workerCode) => {
const workerURL = URL.createObjectURL(
isString(workerCode) ? new Blob([workerCode], { type: "text/javascript" }) : workerCode
);
return new Worker(workerURL, { type: "module" });
};
var cbToAsyncIter = (fn) => (...args) => {
let values = [];
let resolve;
values.push(
new Promise((r) => {
resolve = r;
})
);
fn(...args, (val, done) => {
resolve([val, done]);
values.push(
new Promise((r) => {
resolve = r;
})
);
});
return async function* () {
let val;
for (let i = 0, done = false; !done; i++) {
[val, done] = await values[i];
delete values[i];
if (val !== void 0) yield val;
}
}();
};
// src/workers-code/generated.ts
var LLAMA_CPP_WORKER_CODE = "// Start the main llama.cpp\nlet wllamaMalloc;\nlet wllamaStart;\nlet wllamaAction;\nlet wllamaExit;\nlet wllamaDebug;\n\nlet Module = null;\n\n//////////////////////////////////////////////////////////////\n// UTILS\n//////////////////////////////////////////////////////////////\n\n// send message back to main thread\nconst msg = (data, transfer) => postMessage(data, transfer);\n\n// Convert CPP log into JS log\nconst cppLogToJSLog = (line) => {\n const matched = line.match(/@@(DEBUG|INFO|WARN|ERROR)@@(.*)/);\n return !!matched\n ? {\n level: (matched[1] === 'INFO' ? 'debug' : matched[1]).toLowerCase(),\n text: matched[2],\n }\n : { level: 'log', text: line };\n};\n\n// Get module config that forwards stdout/err to main thread\nconst getWModuleConfig = (_argMainScriptBlob) => {\n var pathConfig = RUN_OPTIONS.pathConfig;\n var pthreadPoolSize = RUN_OPTIONS.nbThread;\n var argMainScriptBlob = _argMainScriptBlob;\n\n if (!pathConfig['wllama.wasm']) {\n throw new Error('\"wllama.wasm\" is missing in pathConfig');\n }\n return {\n noInitialRun: true,\n print: function (text) {\n if (arguments.length > 1)\n text = Array.prototype.slice.call(arguments).join(' ');\n msg({ verb: 'console.log', args: [text] });\n },\n printErr: function (text) {\n if (arguments.length > 1)\n text = Array.prototype.slice.call(arguments).join(' ');\n const logLine = cppLogToJSLog(text);\n msg({ verb: 'console.' + logLine.level, args: [logLine.text] });\n },\n locateFile: function (filename, basePath) {\n const p = pathConfig[filename];\n const truncate = (str) =>\n str.length > 128 ? `${str.substr(0, 128)}...` : str;\n if (filename.match(/wllama\\.worker\\.js/)) {\n msg({\n verb: 'console.error',\n args: [\n '\"wllama.worker.js\" is removed from v2.2.1. Hint: make sure to clear browser\\'s cache.',\n ],\n });\n } else {\n msg({\n verb: 'console.debug',\n args: [`Loading \"${filename}\" from \"${truncate(p)}\"`],\n });\n return p;\n }\n },\n mainScriptUrlOrBlob: argMainScriptBlob,\n pthreadPoolSize,\n wasmMemory: pthreadPoolSize > 1 ? getWasmMemory() : null,\n onAbort: function (text) {\n msg({ verb: 'signal.abort', args: [text] });\n },\n };\n};\n\n// Get the memory to be used by wasm. (Only used in multi-thread mode)\n// Because we have a weird OOM issue on iOS, we need to try some values\n// See: https://github.com/emscripten-core/emscripten/issues/19144\n// https://github.com/godotengine/godot/issues/70621\nconst getWasmMemory = () => {\n let minBytes = 128 * 1024 * 1024;\n let maxBytes = 4096 * 1024 * 1024;\n let stepBytes = 128 * 1024 * 1024;\n while (maxBytes > minBytes) {\n try {\n const wasmMemory = new WebAssembly.Memory({\n initial: minBytes / 65536,\n maximum: maxBytes / 65536,\n shared: true,\n });\n return wasmMemory;\n } catch (e) {\n maxBytes -= stepBytes;\n continue; // retry\n }\n }\n throw new Error('Cannot allocate WebAssembly.Memory');\n};\n\n//////////////////////////////////////////////////////////////\n// MEMFS PATCH\n//////////////////////////////////////////////////////////////\n\n/**\n * By default, emscripten uses memfs. The way it works is by\n * allocating new Uint8Array in javascript heap. This is not good\n * because it requires files to be copied to wasm heap each time\n * a file is read.\n *\n * HeapFS is an alternative, which resolves this problem by\n * allocating space for file directly inside wasm heap. This\n * allows us to mmap without doing any copy.\n *\n * For llama.cpp, this is great because we use MAP_SHARED\n *\n * Ref: https://github.com/ngxson/wllama/pull/39\n * Ref: https://github.com/emscripten-core/emscripten/blob/main/src/library_memfs.js\n *\n * Note 29/05/2024 @ngxson\n * Due to ftell() being limited to MAX_LONG, we cannot load files bigger than 2^31 bytes (or 2GB)\n * Ref: https://github.com/emscripten-core/emscripten/blob/main/system/lib/libc/musl/src/stdio/ftell.c\n */\n\nconst fsNameToFile = {}; // map Name => File\nconst fsIdToFile = {}; // map ID => File\nlet currFileId = 0;\n\n// Patch and redirect memfs calls to wllama\nconst patchMEMFS = () => {\n const m = Module;\n // save functions\n m.MEMFS.stream_ops._read = m.MEMFS.stream_ops.read;\n m.MEMFS.stream_ops._write = m.MEMFS.stream_ops.write;\n m.MEMFS.stream_ops._llseek = m.MEMFS.stream_ops.llseek;\n m.MEMFS.stream_ops._allocate = m.MEMFS.stream_ops.allocate;\n m.MEMFS.stream_ops._mmap = m.MEMFS.stream_ops.mmap;\n m.MEMFS.stream_ops._msync = m.MEMFS.stream_ops.msync;\n\n const patchStream = (stream) => {\n const name = stream.node.name;\n if (fsNameToFile[name]) {\n const f = fsNameToFile[name];\n stream.node.contents = m.HEAPU8.subarray(f.ptr, f.ptr + f.size);\n stream.node.usedBytes = f.size;\n }\n };\n\n // replace \"read\" functions\n m.MEMFS.stream_ops.read = function (\n stream,\n buffer,\n offset,\n length,\n position\n ) {\n patchStream(stream);\n return m.MEMFS.stream_ops._read(stream, buffer, offset, length, position);\n };\n m.MEMFS.ops_table.file.stream.read = m.MEMFS.stream_ops.read;\n\n // replace \"llseek\" functions\n m.MEMFS.stream_ops.llseek = function (stream, offset, whence) {\n patchStream(stream);\n return m.MEMFS.stream_ops._llseek(stream, offset, whence);\n };\n m.MEMFS.ops_table.file.stream.llseek = m.MEMFS.stream_ops.llseek;\n\n // replace \"mmap\" functions\n m.MEMFS.stream_ops.mmap = function (stream, length, position, prot, flags) {\n patchStream(stream);\n const name = stream.node.name;\n if (fsNameToFile[name]) {\n const f = fsNameToFile[name];\n return {\n ptr: f.ptr + position,\n allocated: false,\n };\n } else {\n return m.MEMFS.stream_ops._mmap(stream, length, position, prot, flags);\n }\n };\n m.MEMFS.ops_table.file.stream.mmap = m.MEMFS.stream_ops.mmap;\n\n // mount FS\n m.FS.mkdir('/models');\n m.FS.mount(m.MEMFS, { root: '.' }, '/models');\n};\n\n// Allocate a new file in wllama heapfs, returns file ID\nconst heapfsAlloc = (name, size) => {\n if (size < 1) {\n throw new Error('File size must be bigger than 0');\n }\n const m = Module;\n const ptr = m.mmapAlloc(size);\n const file = {\n ptr: ptr,\n size: size,\n id: currFileId++,\n };\n fsIdToFile[file.id] = file;\n fsNameToFile[name] = file;\n return file.id;\n};\n\n// Add new file to wllama heapfs, return number of written bytes\nconst heapfsWrite = (id, buffer, offset) => {\n const m = Module;\n if (fsIdToFile[id]) {\n const { ptr, size } = fsIdToFile[id];\n const afterWriteByte = offset + buffer.byteLength;\n if (afterWriteByte > size) {\n throw new Error(\n `File ID ${id} write out of bound, afterWriteByte = ${afterWriteByte} while size = ${size}`\n );\n }\n m.HEAPU8.set(buffer, ptr + offset);\n return buffer.byteLength;\n } else {\n throw new Error(`File ID ${id} not found in heapfs`);\n }\n};\n\n//////////////////////////////////////////////////////////////\n// MAIN CODE\n//////////////////////////////////////////////////////////////\n\nconst callWrapper = (name, ret, args) => {\n const fn = Module.cwrap(name, ret, args);\n return async (action, req) => {\n let result;\n try {\n if (args.length === 2) {\n result = await fn(action, req);\n } else {\n result = fn();\n }\n } catch (ex) {\n console.error(ex);\n throw ex;\n }\n return result;\n };\n};\n\nonmessage = async (e) => {\n if (!e.data) return;\n const { verb, args, callbackId } = e.data;\n\n if (!callbackId) {\n msg({ verb: 'console.error', args: ['callbackId is required', e.data] });\n return;\n }\n\n if (verb === 'module.init') {\n const argMainScriptBlob = args[0];\n try {\n Module = getWModuleConfig(argMainScriptBlob);\n Module.onRuntimeInitialized = () => {\n // async call once module is ready\n // init FS\n patchMEMFS();\n // init cwrap\n const pointer = 'number';\n // TODO: note sure why emscripten cannot bind if there is only 1 argument\n wllamaMalloc = callWrapper('wllama_malloc', pointer, [\n 'number',\n pointer,\n ]);\n wllamaStart = callWrapper('wllama_start', 'string', []);\n wllamaAction = callWrapper('wllama_action', pointer, [\n 'string',\n pointer,\n ]);\n wllamaExit = callWrapper('wllama_exit', 'string', []);\n wllamaDebug = callWrapper('wllama_debug', 'string', []);\n msg({ callbackId, result: null });\n };\n wModuleInit();\n } catch (err) {\n msg({ callbackId, err });\n }\n return;\n }\n\n if (verb === 'fs.alloc') {\n const argFilename = args[0];\n const argSize = args[1];\n try {\n // create blank file\n const emptyBuffer = new ArrayBuffer(0);\n Module['FS_createDataFile'](\n '/models',\n argFilename,\n emptyBuffer,\n true,\n true,\n true\n );\n // alloc data on heap\n const fileId = heapfsAlloc(argFilename, argSize);\n msg({ callbackId, result: { fileId } });\n } catch (err) {\n msg({ callbackId, err });\n }\n return;\n }\n\n if (verb === 'fs.write') {\n const argFileId = args[0];\n const argBuffer = args[1];\n const argOffset = args[2];\n try {\n const writtenBytes = heapfsWrite(argFileId, argBuffer, argOffset);\n msg({ callbackId, result: { writtenBytes } });\n } catch (err) {\n msg({ callbackId, err });\n }\n return;\n }\n\n if (verb === 'wllama.start') {\n try {\n const result = await wllamaStart();\n msg({ callbackId, result });\n } catch (err) {\n msg({ callbackId, err });\n }\n return;\n }\n\n if (verb === 'wllama.action') {\n const argAction = args[0];\n const argEncodedMsg = args[1];\n try {\n const inputPtr = await wllamaMalloc(argEncodedMsg.byteLength, 0);\n // copy data to wasm heap\n const inputBuffer = new Uint8Array(\n Module.HEAPU8.buffer,\n inputPtr,\n argEncodedMsg.byteLength\n );\n inputBuffer.set(argEncodedMsg, 0);\n const outputPtr = await wllamaAction(argAction, inputPtr);\n // length of output buffer is written at the first 4 bytes of input buffer\n const outputLen = new Uint32Array(Module.HEAPU8.buffer, inputPtr, 1)[0];\n // copy the output buffer to JS heap\n const outputBuffer = new Uint8Array(outputLen);\n const outputSrcView = new Uint8Array(\n Module.HEAPU8.buffer,\n outputPtr,\n outputLen\n );\n outputBuffer.set(outputSrcView, 0); // copy it\n msg({ callbackId, result: outputBuffer }, [outputBuffer.buffer]);\n } catch (err) {\n msg({ callbackId, err });\n }\n return;\n }\n\n if (verb === 'wllama.exit') {\n try {\n const result = await wllamaExit();\n msg({ callbackId, result });\n } catch (err) {\n msg({ callbackId, err });\n }\n return;\n }\n\n if (verb === 'wllama.debug') {\n try {\n const result = await wllamaDebug();\n msg({ callbackId, result });\n } catch (err) {\n msg({ callbackId, err });\n }\n return;\n }\n};\n";
var OPFS_UTILS_WORKER_CODE = "let accessHandle;\nlet abortController = new AbortController();\n\nasync function openFile(filename) {\n const opfsRoot = await navigator.storage.getDirectory();\n const cacheDir = await opfsRoot.getDirectoryHandle('cache', { create: true });\n const fileHandler = await cacheDir.getFileHandle(filename, { create: true });\n accessHandle = await fileHandler.createSyncAccessHandle();\n accessHandle.truncate(0); // clear file content\n}\n\nasync function writeFile(buf) {\n accessHandle.write(buf);\n}\n\nasync function closeFile() {\n accessHandle.flush();\n accessHandle.close();\n}\n\nasync function writeTextFile(filename, str) {\n await openFile(filename);\n await writeFile(new TextEncoder().encode(str));\n await closeFile();\n}\n\nconst throttled = (func, delay) => {\n let lastRun = 0;\n return (...args) => {\n const now = Date.now();\n if (now - lastRun > delay) {\n lastRun = now;\n func.apply(null, args);\n }\n };\n};\n\nconst assertNonNull = (val) => {\n if (val === null || val === undefined) {\n throw new Error('OPFS Worker: Assertion failed');\n }\n};\n\n// respond to main thread\nconst resOK = () => postMessage({ ok: true });\nconst resProgress = (loaded, total) =>\n postMessage({ progress: { loaded, total } });\nconst resErr = (err) => postMessage({ err });\n\nonmessage = async (e) => {\n try {\n if (!e.data) return;\n\n /**\n * @param {Object} e.data\n *\n * Fine-control FS actions:\n * - { action: 'open', filename: 'string' }\n * - { action: 'write', buf: ArrayBuffer }\n * - { action: 'close' }\n *\n * Simple write API:\n * - { action: 'write-simple', filename: 'string', buf: ArrayBuffer }\n *\n * Download API:\n * - { action: 'download', url: 'string', filename: 'string', options: Object, metadataFileName: 'string' }\n * - { action: 'download-abort' }\n */\n const { action, filename, buf, url, options, metadataFileName } = e.data;\n\n if (action === 'open') {\n assertNonNull(filename);\n await openFile(filename);\n return resOK();\n } else if (action === 'write') {\n assertNonNull(buf);\n await writeFile(buf);\n return resOK();\n } else if (action === 'close') {\n await closeFile();\n return resOK();\n } else if (action === 'write-simple') {\n assertNonNull(filename);\n assertNonNull(buf);\n await openFile(filename);\n await writeFile(buf);\n await closeFile();\n return resOK();\n } else if (action === 'download') {\n assertNonNull(url);\n assertNonNull(filename);\n assertNonNull(metadataFileName);\n assertNonNull(options);\n assertNonNull(options.aborted);\n abortController = new AbortController();\n if (options.aborted) abortController.abort();\n const response = await fetch(url, {\n ...options,\n signal: abortController.signal,\n });\n const contentLength = response.headers.get('content-length');\n const etag = (response.headers.get('etag') || '').replace(\n /[^A-Za-z0-9]/g,\n ''\n );\n const total = parseInt(contentLength, 10);\n const reader = response.body.getReader();\n await openFile(filename);\n let loaded = 0;\n const throttledProgress = throttled(resProgress, 100);\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n loaded += value.byteLength;\n await writeFile(value);\n throttledProgress(loaded, total);\n }\n resProgress(total, total); // 100% done\n await closeFile();\n // make sure this is in-sync with CacheEntryMetadata\n await writeTextFile(\n metadataFileName,\n JSON.stringify({\n originalURL: url,\n originalSize: total,\n etag,\n })\n );\n return resOK();\n } else if (action === 'download-abort') {\n if (abortController) {\n abortController.abort();\n }\n return;\n }\n\n throw new Error('OPFS Worker: Invalid action', e.data);\n } catch (err) {\n return resErr(err);\n }\n};\n";
var WLLAMA_MULTI_THREAD_CODE = 'var Module=typeof Module!="undefined"?Module:{};var ENVIRONMENT_IS_WEB=typeof window=="object";var ENVIRONMENT_IS_WORKER=typeof WorkerGlobalScope!="undefined";var ENVIRONMENT_IS_NODE=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string"&&process.type!="renderer";var ENVIRONMENT_IS_PTHREAD=ENVIRONMENT_IS_WORKER&&self.name?.startsWith("em-pthread");if(ENVIRONMENT_IS_NODE){var worker_threads=require("worker_threads");global.Worker=worker_threads.Worker;ENVIRONMENT_IS_WORKER=!worker_threads.isMainThread;ENVIRONMENT_IS_PTHREAD=ENVIRONMENT_IS_WORKER&&worker_threads["workerData"]=="em-pthread"}var moduleOverrides=Object.assign({},Module);var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=typeof document!="undefined"?document.currentScript?.src:undefined;if(ENVIRONMENT_IS_NODE){_scriptName=__filename}else if(ENVIRONMENT_IS_WORKER){_scriptName=self.location.href}var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("fs");var nodePath=require("path");scriptDirectory=__dirname+"/";readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(!Module["thisProgram"]&&process.argv.length>1){thisProgram=process.argv[1].replace(/\\\\/g,"/")}arguments_=process.argv.slice(2);if(typeof module!="undefined"){module["exports"]=Module}quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src}if(scriptDirectory.startsWith("blob:")){scriptDirectory=""}else{scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1)}if(!ENVIRONMENT_IS_NODE){if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=async url=>{if(isFileURI(url)){return new Promise((resolve,reject)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){resolve(xhr.response);return}reject(xhr.status)};xhr.onerror=reject;xhr.send(null)})}var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var defaultPrint=console.log.bind(console);var defaultPrintErr=console.error.bind(console);if(ENVIRONMENT_IS_NODE){defaultPrint=(...args)=>fs.writeSync(1,args.join(" ")+"\\n");defaultPrintErr=(...args)=>fs.writeSync(2,args.join(" ")+"\\n")}var out=Module["print"]||defaultPrint;var err=Module["printErr"]||defaultPrintErr;Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];var wasmBinary=Module["wasmBinary"];var wasmMemory;var wasmModule;var ABORT=false;var EXITSTATUS;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAP64,HEAPU64,HEAPF64;var runtimeInitialized=false;var dataURIPrefix="data:application/octet-stream;base64,";var isDataURI=filename=>filename.startsWith(dataURIPrefix);var isFileURI=filename=>filename.startsWith("file://");function GROWABLE_HEAP_I8(){if(wasmMemory.buffer!=HEAP8.buffer){updateMemoryViews()}return HEAP8}function GROWABLE_HEAP_U8(){if(wasmMemory.buffer!=HEAP8.buffer){updateMemoryViews()}return HEAPU8}function GROWABLE_HEAP_I16(){if(wasmMemory.buffer!=HEAP8.buffer){updateMemoryViews()}return HEAP16}function GROWABLE_HEAP_I32(){if(wasmMemory.buffer!=HEAP8.buffer){updateMemoryViews()}return HEAP32}function GROWABLE_HEAP_U32(){if(wasmMemory.buffer!=HEAP8.buffer){updateMemoryViews()}return HEAPU32}function GROWABLE_HEAP_F32(){if(wasmMemory.buffer!=HEAP8.buffer){updateMemoryViews()}return HEAPF32}function GROWABLE_HEAP_F64(){if(wasmMemory.buffer!=HEAP8.buffer){updateMemoryViews()}return HEAPF64}if(ENVIRONMENT_IS_PTHREAD){var wasmModuleReceived;if(ENVIRONMENT_IS_NODE){var parentPort=worker_threads["parentPort"];parentPort.on("message",msg=>onmessage({data:msg}));Object.assign(globalThis,{self:global,postMessage:msg=>parentPort.postMessage(msg)})}var initializedJS=false;function threadPrintErr(...args){var text=args.join(" ");if(ENVIRONMENT_IS_NODE){fs.writeSync(2,text+"\\n");return}console.error(text)}if(!Module["printErr"])err=threadPrintErr;function threadAlert(...args){var text=args.join(" ");postMessage({cmd:"alert",text,threadId:_pthread_self()})}self.alert=threadAlert;self.onunhandledrejection=e=>{throw e.reason||e};function handleMessage(e){try{var msgData=e["data"];var cmd=msgData.cmd;if(cmd==="load"){let messageQueue=[];self.onmessage=e=>messageQueue.push(e);self.startWorker=instance=>{postMessage({cmd:"loaded"});for(let msg of messageQueue){handleMessage(msg)}self.onmessage=handleMessage};for(const handler of msgData.handlers){if(!Module[handler]||Module[handler].proxy){Module[handler]=(...args)=>{postMessage({cmd:"callHandler",handler,args})};if(handler=="print")out=Module[handler];if(handler=="printErr")err=Module[handler]}}wasmMemory=msgData.wasmMemory;updateMemoryViews();wasmModuleReceived(msgData.wasmModule)}else if(cmd==="run"){establishStackSpace(msgData.pthread_ptr);__emscripten_thread_init(msgData.pthread_ptr,0,0,1,0,0);PThread.receiveObjectTransfer(msgData);PThread.threadInitTLS();__emscripten_thread_mailbox_await(msgData.pthread_ptr);if(!initializedJS){initializedJS=true}try{invokeEntryPoint(msgData.start_routine,msgData.arg)}catch(ex){if(ex!="unwind"){throw ex}}}else if(msgData.target==="setimmediate"){}else if(cmd==="checkMailbox"){if(initializedJS){checkMailbox()}}else if(cmd){err(`worker: received unknown command ${cmd}`);err(msgData)}}catch(ex){__emscripten_thread_crashed();throw ex}}self.onmessage=handleMessage}function updateMemoryViews(){var b=wasmMemory.buffer;Module["HEAP8"]=HEAP8=new Int8Array(b);Module["HEAP16"]=HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);Module["HEAPU16"]=HEAPU16=new Uint16Array(b);Module["HEAP32"]=HEAP32=new Int32Array(b);Module["HEAPU32"]=HEAPU32=new Uint32Array(b);Module["HEAPF32"]=HEAPF32=new Float32Array(b);Module["HEAPF64"]=HEAPF64=new Float64Array(b);Module["HEAP64"]=HEAP64=new BigInt64Array(b);Module["HEAPU64"]=HEAPU64=new BigUint64Array(b)}if(!ENVIRONMENT_IS_PTHREAD){if(Module["wasmMemory"]){wasmMemory=Module["wasmMemory"]}else{var INITIAL_MEMORY=Module["INITIAL_MEMORY"]||134217728;wasmMemory=new WebAssembly.Memory({initial:INITIAL_MEMORY/65536,maximum:65536,shared:true})}updateMemoryViews()}var __ATPRERUN__=[];var __ATINIT__=[];var __ATMAIN__=[];var __ATPOSTRUN__=[];function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(__ATPRERUN__)}function initRuntime(){runtimeInitialized=true;if(ENVIRONMENT_IS_PTHREAD)return startWorker(Module);if(!Module["noFSInit"]&&!FS.initialized)FS.init();FS.ignorePermissions=false;TTY.init();callRuntimeCallbacks(__ATINIT__)}function preMain(){if(ENVIRONMENT_IS_PTHREAD)return;callRuntimeCallbacks(__ATMAIN__)}function postRun(){if(ENVIRONMENT_IS_PTHREAD)return;if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPost | |