/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/smith@0.1.22/smith.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
("undefined"!=typeof module&&function(e){module.exports=e(require("events"),require("msgpack-js"))}||"function"==typeof define&&function(e){define("smith",["./events-amd","msgpack-js"],e)}||function(e){window.smith=e(window.events,window.msgpack)})((function(e,t){"use strict";var n=e.EventEmitter;function r(e,t){e.prototype=Object.create(t.prototype,{constructor:{value:e}})}var o={};function i(e,n){var r,o=this;if(this.debug=n,Array.isArray(e)?(r=e[1],e=e[0]):r=e,this.input=e,this.output=r,!e.readable)throw new Error("Input is not readable");if(!r.writable)throw new Error("Output is not writable");e.on("data",c),e.on("end",h),e.on("timeout",h),e.on("close",h),e.on("error",u),r.on("drain",a),r!==e&&(r.on("end",h),r.on("timeout",h),r.on("close",h),r.on("error",u));var i=s((function(e){var r;try{r=t.decode(e)}catch(e){return o.emit("error",e)}n&&console.log(process.pid+" <- "+require("util").inspect(r,!1,2,!0)),o.emit("message",r)}));function c(e){try{i(e)}catch(e){o.emit("error",e)}}function a(){o.emit("drain")}function u(e){o.emit("error",e)}function h(){e.removeListener("data",c),e.removeListener("end",h),e.removeListener("timeout",h),e.removeListener("close",h),r.removeListener("drain",a),e.destroy&&e.destroy(),e!==r&&(r.removeListener("end",h),r.removeListener("timeout",h),r.removeListener("close",h),r.destroy&&r!==process.stdout&&r.destroy()),o.emit("disconnect")}this.disconnect=h}function s(e){var t,n,r=0,o=0,i=0,s=0;return function(c){for(var a=0,u=c.length;a<u;a++){switch(r){case 0:o|=c[a]<<24,i=0,r=1;break;case 1:o|=c[a]<<16,r=2;break;case 2:o|=c[a]<<8,r=3;break;case 3:o|=c[a],i+=c[a],i+=i<<10,i+=i>>6,i+=i<<3,i^=i>>11,i+=i<<15,i|=0,s=0,r=4;break;case 4:s|=c[a]<<24,r=5;break;case 5:s|=c[a]<<16,r=6;break;case 6:s|=c[a]<<8,r=7;break;case 7:if(s|=c[a],r=8,s!==i)throw new Error("Hash mismatch, expected: "+i+" got: "+s+", chunk: "+c);if(o>104857600)throw new Error("Too big buffer "+o+", chunk: "+c);t=new Buffer(o),n=0,r=9;break;case 9:r=10;break;case 10:r=11;break;case 11:var h=u-a,f=!1;h+n>=o&&(f=!0,h=o-n),c.copy(t,n,a,a+h),n+=h,a+=h-1,f&&(e(t),r=0,o=0,t=void 0,n=void 0)}r<=3&&!f&&(i+=c[a],i+=i<<10,i+=i>>6),f=!1}}}function c(e){if(!this instanceof c)throw new Error("Forgot to use new with Agent constructor");this.api=e||{},this.disconnect=this.disconnect.bind(this),this._onMessage=this._onMessage.bind(this),this._onDrain=this._onDrain.bind(this),this._onReady=this._onReady.bind(this),this._getFunction=this._getFunction.bind(this),this._storeFunction=this._storeFunction.bind(this),this.remoteApi={},this.transport=void 0,this.callbacks=void 0,this.nextKey=void 0}function a(e,t){var n=[],r=[];return function e(o,i){var s=h(o);if("function"!==s&&"object"!==s&&"array"!==s&&"date"!==s)return o;var c,a=n.indexOf(o);return a>=0?{$:r[a]}:(a=n.length,n[a]=o,r[a]=i,"function"===s&&(c=t(o)),"date"===s&&(c={d:o.getTime()}),c?{$:c}:function(e,t,n,r){if("function"==typeof e.map)return e.map.call(e,t,n);for(var o={},i=Object.keys(e),s=0,c=i.length;s<c;s++){var a=i[s];o[r?r(a):a]=t.call(n,e[a],a,e)}return o}(o,(function(t,n){return e(t,i.concat([n]))}),null,(function(e){return"$"===e[0]?"$"+e:e})))}(e,[])}function u(e,t){var n={};return function e(r,o,i){var s=h(r);if("$"===i[0]&&(i=i.substr(1)),"function"!==s&&"object"!==s&&"array"!==s)return o[i]=r,r;if(r.hasOwnProperty("$")){var c=r.$;return Array.isArray(c)?(o[i]=function(e,t){for(var n=e,r=0,o=t.length;r<o;r++)n=n[t[r]];return n}(n.root,c),o[i]):"object"==typeof c?(o[i]=new Date(c.d),o[i]):(o[i]=t(c),o[i])}var a=Array.isArray(r)?[]:{};return o[i]=a,f(r,(function(t,n){e(t,a,n)})),n}(e,n,"root"),n.root}function h(e){return null===e?"null":Array.isArray(e)?"array":"undefined"!=typeof Buffer&&Buffer.isBuffer(e)?"buffer":e instanceof Date?"date":typeof e}function f(e,t,n){if("function"==typeof e.forEach)return e.forEach.call(e,t,n);for(var r=Object.keys(e),o=0,i=r.length;o<i;o++){var s=r[o];t.call(n,e[s],s,e)}}function d(e,n){this.socket=e,this.debug=n;var r=this;function o(e){r.emit("error",e)}function i(e){var i;try{i=t.decode(e)}catch(e){return o(e)}n&&console.log(process.pid+" <- "+require("util").inspect(i,!1,2,!0)),r.emit("message",i)}function s(){e.removeListener("message",i),e.removeListener("close",s),r.emit("disconnect")}e.on("message",i),e.on("close",s),e.on("error",o),this.disconnect=s}function p(e,n){this.websocket=e,this.debug=n;var r=this;function o(e){r.emit("error",e)}e.binaryType="arraybuffer",e.onmessage=function(e){var i;try{i=t.decode(e.data)}catch(e){return o(e)}n&&console.log("<-",i),r.emit("message",i)},e.onclose=function(e){},e.onerror=function(e){o(new Error(e.data))},this.disconnect=function(){delete e.onmessage,delete e.onclose,r.emit("disconnect")}}function l(e,t){var n=this;this.debug=t,e.on("error",(function(e){n.emit("error",e)})),e.on("message",(function(e){var r;try{r=JSON.parse(e)}catch(e){return void n.emit("error",e)}Array.isArray(r)?(t&&console.log("<-",r),n.emit("message",r)):n.emit("legacy",r)})),e.on("close",(function(e){n.emit("disconnect",e)})),this.disconnect=function(){e.close()},this.send=function(t){var r;try{r=JSON.stringify(t)}catch(e){return void n.emit("error",e)}return this.debug&&Array.isArray(t)&&console.log("->",t),e.send(r)}}return o.msgpack=t,o.Agent=c,o.Transport=i,o.deFramer=s,o.liven=u,o.freeze=a,o.getType=h,r(i,n),i.prototype.send=function(e){this.debug&&console.log(process.pid+" -> "+require("util").inspect(e,!1,2,!0));var n=t.encode(e),r=new Buffer(10);r.writeUInt32BE(n.length,0);var o=0;return o+=n.length>>24,o+=o<<10,o+=o>>6,o+=n.length>>16&255,o+=o<<10,o+=o>>6,o+=n.length>>8&255,o+=o<<10,o+=o>>6,o+=255&n.length,o+=o<<10,o+=o>>6,o+=o<<3,o^=o>>11,o+=o<<15,o|=0,r.writeInt32BE(o,4,!0),r.writeUInt16BE(0,8),this.output.write(r),this.output.write(n)},r(c,n),c.prototype.connectionTimeout=1e4,c.prototype.connect=function(e,t){var n;e instanceof i||(e=new i(e)),this.transport=e,this.callbacks={},this.nextKey=1,e.on("error",this.disconnect),e.on("disconnect",this.disconnect),e.on("message",this._onMessage),e.on("drain",this._onDrain),this.send(["ready",this._onReady]),this.on("connect",o),this.on("disconnect",s),this.on("error",c),this.connectionTimeout&&(n=setTimeout((function(){a();var e=new Error("ETIMEDOUT: Timeout while waiting for Agent agent to connect.");e.code="ETIMEDOUT",r.emit("error",e)}),this.connectionTimeout));var r=this;function o(e){a(),t&&t(null,e)}function s(e){c(e||new Error("EDISCONNECT: Agent disconnected"))}function c(e){a(),t?t(e):r.emit("error",e)}function a(){r.removeListener("connect",o),r.removeListener("disconnect",s),r.removeListener("error",c),clearTimeout(n)}},c.prototype.send=function(e){return e=a(e,this._storeFunction),this.transport.send(e)},c.prototype._onReady=function(e,t){if(Array.isArray(e)){var n=this;e.forEach((function(e){n.remoteApi[e]||(n.remoteApi[e]=function(){if(n.transport){var t=[e];return t.push.apply(t,arguments),n.send(t)}var r=arguments[arguments.length-1];if("function"==typeof r){var o=new Error("ENOTCONNECTED: Agent is offline, try again later");o.code="ENOTCONNECTED",r(o)}})})),this.remoteEnv=t,this._emitConnect()}},c.prototype._emitConnect=function(){this.emit("connect",this.remoteApi)},c.prototype.disconnect=function(e){this.transport&&(this.transport.removeListener("error",this.disconnect),this.transport.removeListener("disconnect",this.disconnect),this.transport.removeListener("message",this._onMessage),this.transport.removeListener("drain",this._onDrain),this.transport.disconnect(),this.transport=void 0);var t=e;if(t||((t=new Error("EDISCONNECT: Agent disconnected")).code="EDISCONNECT"),this.emit("disconnect",e),this.callbacks){var n=this.callbacks;this.callbacks=void 0,f(n,(function(e){e(t)}))}this.nextKey=void 0},c.prototype._onDrain=function(){this.emit("drain")},c.prototype._onMessage=function(e){if(!Array.isArray(e)||!e.length)return this.emit("error",new Error("Message should be an array"));var t,n=(e=u(e,this._getFunction))[0];if("ready"===n){var r=Object.keys(this.api),o="undefined"!=typeof process&&process.env;t=function(e){e(r,o)}}else t="string"==typeof n?this.api[n]:this.callbacks[n];if("function"!=typeof t)return this.emit("error",new Error("Should be function"));t.apply(this,e.slice(1))},c.prototype._getFunction=function(e){var t=this.transport;return function(){var n=[e];return n.push.apply(n,arguments),t.send(n)}},c.prototype._storeFunction=function(e){for(var t=this.nextKey;this.callbacks.hasOwnProperty(t);)if((t=t+1|0)===this.nextKey)throw new Error("Ran out of keys!!");this.nextKey=t+1|0;var n=this.callbacks,r=this;return n[t]=function(){return delete n[t],r.nextKey=t,e.apply(this,arguments)},t},o.WebSocketTransport=d,r(d,i),d.prototype.send=function(e){var n;this.debug&&console.log(process.pid+" -> "+require("util").inspect(e,!1,2,!0));try{n=t.encode(e)}catch(e){return this.emit("error",e)}this.socket.send(n,{binary:!0})},o.BrowserTransport=p,r(p,i),p.prototype.send=function(e){var n;this.debug&&console.log("->",e);try{n=t.encode(e)}catch(e){return this.emit("error",e)}this.websocket.send(n)},o.EngineIoTransport=l,r(l,i),o}));
//# sourceMappingURL=/sm/ddd095bf829fadbc081d0aba6fcf7f6dc97af41ae49d9eb925496352b06b7f9c.map