UNPKG

tinyagent-ts

Version:

Modern TypeScript framework for building AI agents with pluggable tools and ReAct reasoning

24 lines 607 kB
"use strict";var e=require("zod"),a=require("fs"),n=require("child_process"),i=require("crypto"),t=require("readline"),o=require("execa"),r=require("path"),s=require("tty"),c=require("util"),p=require("os"),l=require("buffer"),u=require("string_decoder"),d=require("node:zlib"),m=require("node:events"),f=require("url"),h=require("node:path"),v=require("node:fs"),x=require("node:http"),b=require("querystring"),g=require("node:net"),y=require("stream");class w extends Error{statusCode;constructor(e,a){super(e),this.statusCode=a,this.name="ModelError"}}class k extends w{constructor(e="Model request was aborted"){super(e),this.name="ModelAbortError"}}class j{baseUrl="https://openrouter.ai/api/v1/chat/completions";getName(){return"openrouter"}async chat(e,a,n){if(n?.aborted)throw new k;try{const i=await fetch(this.baseUrl,{method:"POST",headers:{Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json","HTTP-Referer":"https://github.com/yourusername/tinyagent-ts","X-Title":"TinyAgent-TS"},signal:n,body:JSON.stringify({model:a.model,messages:e})});if(!i.ok){let e={message:"Failed to parse error response"};try{e=await i.json()}catch(e){}throw new w(`OpenRouter API error: ${i.status} ${i.statusText}. Details: ${JSON.stringify(e)}`,i.status)}const t=await i.json();return{content:t.choices[0]?.message?.content?.trim()??"",usage:t.usage?{promptTokens:t.usage.prompt_tokens,completionTokens:t.usage.completion_tokens,totalTokens:t.usage.total_tokens}:void 0}}catch(e){if(e instanceof w)throw e;if(e instanceof Error&&"AbortError"===e.name)throw new k;throw new w(`Failed to communicate with OpenRouter: ${e instanceof Error?e.message:String(e)}`)}}}class E{providers=new Map;config;constructor(e={}){if(this.config={defaultProvider:e.defaultProvider||"openrouter",defaultModel:e.defaultModel||"openai/gpt-4o-mini",apiKey:e.apiKey||process.env.OPENROUTER_API_KEY||"",maxRetries:e.maxRetries||3,retryDelay:e.retryDelay||1e3},!this.config.apiKey)throw new w("API key is required. Set OPENROUTER_API_KEY environment variable or provide apiKey in config.");this.registerProvider("openrouter",new j)}registerProvider(e,a){this.providers.set(e,a)}getProvider(e){return this.providers.get(e)}async chat(e,a={}){const n=a.provider||this.config.defaultProvider,i=this.getProvider(n);if(!i)throw new w(`Unknown provider: ${n}`);const t={model:a.model||this.config.defaultModel,apiKey:a.apiKey||this.config.apiKey,maxRetries:a.maxRetries||this.config.maxRetries},o=t.maxRetries||0;let r;for(let n=0;n<=o;n++)try{return await i.chat(e,t,a.abortSignal)}catch(e){if(r=e instanceof Error?e:new Error(String(e)),"ModelAbortError"===r.name||"AbortError"===r.name||e instanceof w&&401===e.statusCode)throw r;if(n===o)break;this.config.retryDelay>0&&await new Promise((e=>setTimeout(e,this.config.retryDelay)))}throw r}updateConfig(e){this.config={...this.config,...e}}getConfig(){return{...this.config}}}class S{task="";steps=[];setTask(e){this.task=e}getTask(){return this.task}clear(){this.steps=[],this.task=""}addThought(e){this.steps.push({type:"thought",text:e,timestamp:new Date})}addAction(e){this.steps.push({...e,timestamp:new Date})}addObservation(e){this.steps.push({type:"observation",text:e,timestamp:new Date})}addReflexion(e){this.steps.push({type:"reflexion",text:e,timestamp:new Date})}getSteps(){return[...this.steps]}getLastArgValue(e){for(let a=this.steps.length-1;a>=0;a--){const n=this.steps[a];if("action"===n.type&&"json"===n.mode&&n.args&&e in n.args)return n.args[e]}}toMessages(e){const a=[];e&&a.push({role:"system",content:e}),this.task&&a.push({role:"user",content:this.task});for(const e of this.steps)switch(e.type){case"thought":a.push({role:"assistant",content:`Thought: ${e.text}`});break;case"reflexion":a.push({role:"assistant",content:`Reflexion: ${e.text}`});break;case"action":const n=e;if("code"===n.mode)a.push({role:"assistant",content:`Action:\n\`\`\`ts\n${n.text}\n\`\`\``});else{const e=JSON.stringify({tool:n.tool,args:n.args});a.push({role:"assistant",content:`Action: ${e}`})}break;case"observation":a.push({role:"assistant",content:`Observation: ${e.text}`})}return a}}function A(e){const a=e.match(/Reflect(?:ion|xion)?:([\s\S]*?)(?=\n(?:Thought|Action):|$)/i),n=a?a[1].trim():void 0,i=e.match(/Thought:(.*?)(?:\nAction:|$)/s),t=i?i[1].trim():"",o=(e.split(/\nAction:/s)[1]??"").trim();try{if(o.startsWith("{")&&o.endsWith("}")){const e=JSON.parse(o);if("string"==typeof e.tool&&"object"==typeof e.args){return{thought:t,action:{type:"action",mode:"json",tool:e.tool,args:e.args,text:o},reflexion:n}}}}catch{}const r=o.match(/{\s*"tool"\s*:\s*"([^"]+)".*}/);if(r)try{const e=r[0],a=JSON.parse(e);if("string"==typeof a.tool&&"object"==typeof a.args){return{thought:t,action:{type:"action",mode:"json",tool:a.tool,args:a.args,text:e},reflexion:n}}}catch{}if(o.startsWith("```")){const e=o.match(/```(?:\w+)?\n([\s\S]*?)```/);return{thought:t,action:{type:"action",mode:"code",tool:"code",text:e?e[1].trim():o},reflexion:n}}if(o){return{thought:t,action:{type:"action",mode:"code",tool:"code",text:o},reflexion:n}}return{thought:t,reflexion:n}}const C=e.z.object({answer:e.z.unknown().refine((e=>null!=e),{message:"Answer cannot be undefined or null"})});function O(a){try{return C.parse(a)}catch(a){if(a instanceof e.z.ZodError)throw new Error(`Invalid final answer structure: ${a.errors.map((e=>e.message)).join(", ")}`);throw a}}class T{modelManager;state;tools=new Map;constructor(e){this.modelManager=e,this.state=new S}registerTool(e){this.tools.set(e.name,e)}unregisterTool(e){this.tools.delete(e)}getTools(){return Array.from(this.tools.values())}async execute(e,a,n={},i={}){const{maxSteps:t=5,enableReflexion:o=!0,enableTrace:r=!1,onStep:s,onComplete:c}=n;let p;this.state.clear(),this.state.setTask(e);let l=!1;try{for(let e=0;e<t;e++){if(i.abortSignal?.aborted)throw new Error("ReAct execution was aborted");const e=this.state.toMessages(a),n=A((await this.modelManager.chat(e,{model:i.model,abortSignal:i.abortSignal})).content);n.thought&&(this.state.addThought(n.thought),r&&console.log(`Thought: ${n.thought}`),s&&s({type:"thought",text:n.thought}));let t="";if(n.action){this.state.addAction(n.action),r&&console.log(`Action: ${n.action.tool}(${JSON.stringify(n.action.args)})`),s&&s(n.action);try{if("final_answer"===n.action.tool){l||console.warn("final_answer called before any other tool"),p=n.action.args,t=JSON.stringify(p),this.state.addObservation(t),r&&console.log(`Observation: ${t}`),s&&s({type:"observation",text:t});break}const e=this.tools.get(n.action.tool);if(e){let a={...n.action.args};if(e.schema&&"object"==typeof e.schema.shape){const n=Object.keys(e.schema.shape);for(const e of n)if(void 0===a[e]){const n=this.state.getLastArgValue(e);void 0!==n&&(a[e]=n)}}const o=await e.execute(a,i.abortSignal);l=!0,t=JSON.stringify(o)}else t=`Unknown tool: ${n.action.tool}`}catch(e){t=e instanceof Error?e.message:String(e)}this.state.addObservation(t),r&&console.log(`Observation: ${t}`),s&&s({type:"observation",text:t})}if(o&&n.action){const e=this.state.toMessages(a);if(e.push({role:"user",content:"Reflect:"}),i.abortSignal?.aborted)throw new Error("ReAct execution was aborted");const n=A((await this.modelManager.chat(e,{model:i.model,abortSignal:i.abortSignal})).content);if(n.reflexion&&(this.state.addReflexion(n.reflexion),r&&console.log(`Reflexion: ${n.reflexion}`),s&&s({type:"reflexion",text:n.reflexion})),n.action){if("final_answer"===n.action.tool){l||console.warn("final_answer called before any other tool"),p=n.action.args;const e=JSON.stringify(p);this.state.addObservation(e),r&&console.log(`Observation: ${e}`),s&&s({type:"observation",text:e});break}const e=this.tools.get(n.action.tool);let a="";try{if(e){const t=await e.execute(n.action.args||{},i.abortSignal);l=!0,a=JSON.stringify(t)}else a=`Unknown tool: ${n.action.tool}`}catch(e){a=e instanceof Error?e.message:String(e)}n.thought&&this.state.addThought(n.thought),this.state.addAction(n.action),this.state.addObservation(a),r&&(n.thought&&console.log(`Thought: ${n.thought}`),console.log(`Action: ${n.action.tool}(${JSON.stringify(n.action.args)})`),console.log(`Observation: ${a}`)),s&&(n.thought&&s({type:"thought",text:n.thought}),s(n.action),s({type:"observation",text:a}))}else n.thought&&(this.state.addThought(n.thought),r&&console.log(`Thought: ${n.thought}`),s&&s({type:"thought",text:n.thought}))}}p=await this.enforceFinalAnswer(p,a,i);try{p=O(p)}catch(e){throw new Error(`Final answer validation failed: ${e instanceof Error?e.message:String(e)}`)}const e={success:!0,steps:this.state.getSteps(),finalAnswer:p};return c&&c(e),e}catch(e){const a={success:!1,error:e instanceof Error?e:new Error(String(e)),steps:this.state.getSteps(),finalAnswer:p};return c&&c(a),a}}async enforceFinalAnswer(e,a,n){if(void 0!==e)return e;console.warn("ReAct loop completed without final_answer tool call. Forcing final answer generation.");const i=this.state.toMessages(a);i.push({role:"user",content:"You must provide a final answer now using the final_answer tool. Summarize your findings and provide a conclusive response."});try{const e=await this.modelManager.chat(i,{model:n.model,abortSignal:n.abortSignal}),a=A(e.content);if(a.action&&"final_answer"===a.action.tool){const e=a.action.args;return this.state.addThought(a.thought||"Providing final answer"),this.state.addAction(a.action),this.state.addObservation(JSON.stringify(e)),e}{const a=this.state.getSteps().filter((e=>"observation"===e.type));let n="Task completed";for(let e=a.length-1;e>=0;e--){const i=a[e];if(i.text&&!i.text.startsWith("Action:")&&!i.text.startsWith('{"answer":'))try{const e=JSON.parse(i.text);if("string"==typeof e){n=e.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i)?`The generated UUID is: ${e}`:e;break}if(e&&"object"==typeof e){n=JSON.stringify(e);break}}catch{if(i.text.length>10&&!i.text.includes("Unknown tool")){n=i.text;break}}}"Task completed"===n&&e.content&&(n=e.content);const i={answer:n};this.state.addThought("Providing final answer based on previous results");const t={type:"action",mode:"json",tool:"final_answer",args:i,text:JSON.stringify({tool:"final_answer",args:i})};return this.state.addAction(t),this.state.addObservation(JSON.stringify(i)),i}}catch(e){return console.warn("Failed to force final answer:",e),{answer:"Task completed but final answer generation failed"}}}getState(){return this.state}reset(){this.state.clear()}}class _{validateArgs(e){return this.schema.parse(e)}success(e,a){return{success:!0,data:e,metadata:a}}error(e,a){return{success:!1,error:e,metadata:a}}}class P{tools=new Map;metadata=new Map;register(e){if(this.tools.has(e.name))throw new Error(`Tool with name '${e.name}' is already registered`);this.tools.set(e.name,e),this.metadata.set(e.name,{name:e.name,description:e.description,schema:e.schema})}unregister(e){this.tools.delete(e),this.metadata.delete(e)}get(e){return this.tools.get(e)}getAll(){return Array.from(this.tools.values())}getByCategory(e){const a=[];for(const[n,i]of this.metadata.entries())if(i.category===e){const e=this.tools.get(n);e&&a.push(e)}return a}has(e){return this.tools.has(e)}getMetadata(e){return this.metadata.get(e)}getAllMetadata(){return Array.from(this.metadata.values())}registerWithMetadata(e,a){this.register(e);const n={name:e.name,description:e.description,schema:e.schema,...a};this.metadata.set(e.name,n)}static fromTools(e){const a=new P;for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&a.register(e[n]);return a}getCatalog(){return this.getAll().map((e=>`- ${e.name}: ${e.description}`)).join("\n")}clear(){this.tools.clear(),this.metadata.clear()}size(){return this.tools.size}}const q=e.z.object({answer:e.z.string().describe("The final answer to provide to the user")});class I extends _{name="final_answer";description="Provide the final answer to the user's question or task";schema=q;async execute(e){return this.validateArgs(e)}}const F=e.z.object({action:e.z.enum(["read","write","append","delete"]).describe("The file operation to perform"),path:e.z.string().describe("The file path to operate on"),content:e.z.string().optional().describe("Content to write/append (required for write/append actions)")});const z=e.z.object({pattern:e.z.string().describe("The pattern to search for"),file:e.z.string().describe("The file to search in"),flags:e.z.string().optional().describe("Additional grep flags (e.g., -i for case insensitive)")});const R=e.z.object({version:e.z.literal(4).optional().describe("UUID version (only v4 supported)")});const B=e.z.object({prompt:e.z.string().default("Need input:").describe("The prompt to show to the human operator")});const L=e.z.object({query:e.z.string().min(2,"Query must be at least 2 characters").describe("The search term"),count:e.z.number().int().min(1).max(20).default(10).describe("How many results to return (1-20)")});var M="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function N(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var D={exports:{}},$={exports:{}},U={exports:{}},H=r.relative,W=function(e){if(!e)throw new TypeError("argument namespace is required");var a=Z(ae()[1])[0];function n(e){J.call(n,e)}return n._file=a,n._ignored=function(e){if(process.noDeprecation)return!0;return G(process.env.NO_DEPRECATION||"",e)}(e),n._namespace=e,n._traced=function(e){if(process.traceDeprecation)return!0;return G(process.env.TRACE_DEPRECATION||"",e)}(e),n._warned=Object.create(null),n.function=ie,n.property=te,n},V=process.cwd();function G(e,a){for(var n=e.split(/[ ,]+/),i=String(a).toLowerCase(),t=0;t<n.length;t++){var o=n[t];if(o&&("*"===o||o.toLowerCase()===i))return!0}return!1}function K(e){var a=this.name+": "+this.namespace;this.message&&(a+=" deprecated "+this.message);for(var n=0;n<e.length;n++)a+="\n at "+e[n].toString();return a}function J(e,a){var n=function(e,a){return("function"!=typeof e.listenerCount?e.listeners(a).length:e.listenerCount(a))>0}(process,"deprecation");if(n||!this._ignored){var i,t,o,r,s=0,c=!1,p=ae(),l=this._file;for(a?(r=a,(o=Z(p[1])).name=r.name,l=o[0]):o=r=Z(p[s=2]);s<p.length;s++)if((t=(i=Z(p[s]))[0])===l)c=!0;else if(t===this._file)l=this._file;else if(c)break;var u=i?r.join(":")+"__"+i.join(":"):void 0;if(void 0===u||!(u in this._warned)){this._warned[u]=!0;var d=e;if(d||(d=o!==r&&o.name?X(o):X(r)),n){var m=oe(this._namespace,d,p.slice(s));process.emit("deprecation",m)}else{var f=(process.stderr.isTTY?Q:Y).call(this,d,i,p.slice(s));process.stderr.write(f+"\n","utf8")}}}}function Z(e){var a=e.getFileName()||"<anonymous>",n=e.getLineNumber(),i=e.getColumnNumber();e.isEval()&&(a=e.getEvalOrigin()+", "+a);var t=[a,n,i];return t.callSite=e,t.name=e.getFunctionName(),t}function X(e){var a=e.callSite,n=e.name;n||(n="<anonymous@"+ee(e)+">");var i=a.getThis(),t=i&&a.getTypeName();return"Object"===t&&(t=void 0),"Function"===t&&(t=i.name||t),t&&a.getMethodName()?t+"."+n:n}function Y(e,a,n){var i=(new Date).toUTCString()+" "+this._namespace+" deprecated "+e;if(this._traced){for(var t=0;t<n.length;t++)i+="\n at "+n[t].toString();return i}return a&&(i+=" at "+ee(a)),i}function Q(e,a,n){var i=""+this._namespace+" deprecated "+e+"";if(this._traced){for(var t=0;t<n.length;t++)i+="\n at "+n[t].toString()+"";return i}return a&&(i+=" "+ee(a)+""),i}function ee(e){return H(V,e[0])+":"+e[1]+":"+e[2]}function ae(){var e=Error.stackTraceLimit,a={},n=Error.prepareStackTrace;Error.prepareStackTrace=ne,Error.stackTraceLimit=Math.max(10,e),Error.captureStackTrace(a);var i=a.stack.slice(1);return Error.prepareStackTrace=n,Error.stackTraceLimit=e,i}function ne(e,a){return a}function ie(e,a){if("function"!=typeof e)throw new TypeError("argument fn must be a function");var n=function(e){for(var a="",n=0;n<e;n++)a+=", arg"+n;return a.substr(2)}(e.length),i=Z(ae()[1]);return i.name=e.name,new Function("fn","log","deprecate","message","site",'"use strict"\nreturn function ('+n+") {log.call(deprecate, message, site)\nreturn fn.apply(this, arguments)\n}")(e,J,this,a,i)}function te(e,a,n){if(!e||"object"!=typeof e&&"function"!=typeof e)throw new TypeError("argument obj must be object");var i=Object.getOwnPropertyDescriptor(e,a);if(!i)throw new TypeError("must call property on owner object");if(!i.configurable)throw new TypeError("property must be configurable");var t=this,o=Z(ae()[1]);o.name=a,"value"in i&&(i=function(e,a){var n=Object.getOwnPropertyDescriptor(e,a),i=n.value;return n.get=function(){return i},n.writable&&(n.set=function(e){return i=e}),delete n.value,delete n.writable,Object.defineProperty(e,a,n),n}(e,a));var r=i.get,s=i.set;"function"==typeof r&&(i.get=function(){return J.call(t,n,o),r.apply(this,arguments)}),"function"==typeof s&&(i.set=function(){return J.call(t,n,o),s.apply(this,arguments)}),Object.defineProperty(e,a,i)}function oe(e,a,n){var i,t=new Error;return Object.defineProperty(t,"constructor",{value:oe}),Object.defineProperty(t,"message",{configurable:!0,enumerable:!1,value:a,writable:!0}),Object.defineProperty(t,"name",{enumerable:!1,configurable:!0,value:"DeprecationError",writable:!0}),Object.defineProperty(t,"namespace",{configurable:!0,enumerable:!1,value:e,writable:!0}),Object.defineProperty(t,"stack",{configurable:!0,enumerable:!1,get:function(){return void 0!==i?i:i=K.call(this,n)},set:function(e){i=e}}),t}var re=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(e,a){return e.__proto__=a,e}:function(e,a){for(var n in a)Object.prototype.hasOwnProperty.call(e,n)||(e[n]=a[n]);return e});var se={100:"Continue",101:"Switching Protocols",102:"Processing",103:"Early Hints",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",208:"Already Reported",226:"IM Used",300:"Multiple Choices",301:"Moved Permanently",302:"Found",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",308:"Permanent Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Payload Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"I'm a Teapot",421:"Misdirected Request",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",425:"Too Early",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",451:"Unavailable For Legal Reasons",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",508:"Loop Detected",509:"Bandwidth Limit Exceeded",510:"Not Extended",511:"Network Authentication Required"},ce=le; /*! * statuses * Copyright(c) 2014 Jonathan Ong * Copyright(c) 2016 Douglas Christopher Wilson * MIT Licensed */function pe(e){if(!Object.prototype.hasOwnProperty.call(le.message,e))throw new Error("invalid status code: "+e);return le.message[e]}function le(e){if("number"==typeof e)return pe(e);if("string"!=typeof e)throw new TypeError("code must be a number or string");var a=parseInt(e,10);return isNaN(a)?function(e){var a=e.toLowerCase();if(!Object.prototype.hasOwnProperty.call(le.code,a))throw new Error('invalid status message: "'+e+'"');return le.code[a]}(e):pe(a)}le.message=se,le.code=function(e){var a={};return Object.keys(e).forEach((function(n){var i=e[n],t=Number(n);a[i.toLowerCase()]=t})),a}(se),le.codes=function(e){return Object.keys(e).map((function(e){return Number(e)}))}(se),le.redirect={300:!0,301:!0,302:!0,303:!0,305:!0,307:!0,308:!0},le.empty={204:!0,205:!0,304:!0},le.retry={502:!0,503:!0,504:!0};var ue,de={exports:{}},me={exports:{}};try{var fe=require("util");if("function"!=typeof fe.inherits)throw"";de.exports=fe.inherits}catch(e){de.exports=(ue||(ue=1,"function"==typeof Object.create?me.exports=function(e,a){a&&(e.super_=a,e.prototype=Object.create(a.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:me.exports=function(e,a){if(a){e.super_=a;var n=function(){};n.prototype=a.prototype,e.prototype=new n,e.prototype.constructor=e}}),me.exports)}var he=de.exports,ve=function(e){return e.split(" ").map((function(e){return e.slice(0,1).toUpperCase()+e.slice(1)})).join("").replace(/[^ _0-9a-z]/gi,"")} /*! * http-errors * Copyright(c) 2014 Jonathan Ong * Copyright(c) 2016 Douglas Christopher Wilson * MIT Licensed */; /*! * toidentifier * Copyright(c) 2016 Douglas Christopher Wilson * MIT Licensed */!function(e){var a,n=W("http-errors"),i=re,t=ce,o=he,r=ve;function s(e){return Number(String(e).charAt(0)+"00")}function c(e,a){var n=Object.getOwnPropertyDescriptor(e,"name");n&&n.configurable&&(n.value=a,Object.defineProperty(e,"name",n))}function p(e){return"Error"!==e.substr(-5)?e+"Error":e}e.exports=function e(){for(var a,i,o=500,r={},c=0;c<arguments.length;c++){var p=arguments[c],l=typeof p;if("object"===l&&p instanceof Error)o=(a=p).status||a.statusCode||o;else if("number"===l&&0===c)o=p;else if("string"===l)i=p;else{if("object"!==l)throw new TypeError("argument #"+(c+1)+" unsupported type "+l);r=p}}"number"==typeof o&&(o<400||o>=600)&&n("non-error status code; use only 4xx or 5xx status codes");("number"!=typeof o||!t.message[o]&&(o<400||o>=600))&&(o=500);var u=e[o]||e[s(o)];a||(a=u?new u(i):new Error(i||t.message[o]),Error.captureStackTrace(a,e));u&&a instanceof u&&a.status===o||(a.expose=o<500,a.status=a.statusCode=o);for(var d in r)"status"!==d&&"statusCode"!==d&&(a[d]=r[d]);return a},e.exports.HttpError=function(){function e(){throw new TypeError("cannot construct abstract class")}return o(e,Error),e}(),e.exports.isHttpError=(a=e.exports.HttpError,function(e){return!(!e||"object"!=typeof e)&&(e instanceof a||e instanceof Error&&"boolean"==typeof e.expose&&"number"==typeof e.statusCode&&e.status===e.statusCode)}),function(e,a,n){a.forEach((function(a){var l,u=r(t.message[a]);switch(s(a)){case 400:l=function(e,a,n){var r=p(a);function s(e){var a=null!=e?e:t.message[n],o=new Error(a);return Error.captureStackTrace(o,s),i(o,s.prototype),Object.defineProperty(o,"message",{enumerable:!0,configurable:!0,value:a,writable:!0}),Object.defineProperty(o,"name",{enumerable:!1,configurable:!0,value:r,writable:!0}),o}return o(s,e),c(s,r),s.prototype.status=n,s.prototype.statusCode=n,s.prototype.expose=!0,s}(n,u,a);break;case 500:l=function(e,a,n){var r=p(a);function s(e){var a=null!=e?e:t.message[n],o=new Error(a);return Error.captureStackTrace(o,s),i(o,s.prototype),Object.defineProperty(o,"message",{enumerable:!0,configurable:!0,value:a,writable:!0}),Object.defineProperty(o,"name",{enumerable:!1,configurable:!0,value:r,writable:!0}),o}return o(s,e),c(s,r),s.prototype.status=n,s.prototype.statusCode=n,s.prototype.expose=!1,s}(n,u,a)}l&&(e[a]=l,e[u]=l)}))}(e.exports,t.codes,e.exports.HttpError)}(U);var xe,be,ge,ye=U.exports,we={exports:{}},ke={exports:{}},je=1e3,Ee=60*je,Se=60*Ee,Ae=24*Se,Ce=7*Ae,Oe=365.25*Ae,Te=function(e,a){a=a||{};var n=typeof e;if("string"===n&&e.length>0)return function(e){if((e=String(e)).length>100)return;var a=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!a)return;var n=parseFloat(a[1]);switch((a[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return n*Oe;case"weeks":case"week":case"w":return n*Ce;case"days":case"day":case"d":return n*Ae;case"hours":case"hour":case"hrs":case"hr":case"h":return n*Se;case"minutes":case"minute":case"mins":case"min":case"m":return n*Ee;case"seconds":case"second":case"secs":case"sec":case"s":return n*je;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}(e);if("number"===n&&isFinite(e))return a.long?function(e){var a=Math.abs(e);if(a>=Ae)return _e(e,a,Ae,"day");if(a>=Se)return _e(e,a,Se,"hour");if(a>=Ee)return _e(e,a,Ee,"minute");if(a>=je)return _e(e,a,je,"second");return e+" ms"}(e):function(e){var a=Math.abs(e);if(a>=Ae)return Math.round(e/Ae)+"d";if(a>=Se)return Math.round(e/Se)+"h";if(a>=Ee)return Math.round(e/Ee)+"m";if(a>=je)return Math.round(e/je)+"s";return e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function _e(e,a,n,i){var t=a>=1.5*n;return Math.round(e/n)+" "+i+(t?"s":"")}function Pe(){if(be)return xe;return be=1,xe=function(e){function a(e){let i,t,o,r=null;function s(...e){if(!s.enabled)return;const n=s,t=Number(new Date),o=t-(i||t);n.diff=o,n.prev=i,n.curr=t,i=t,e[0]=a.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let r=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((i,t)=>{if("%%"===i)return"%";r++;const o=a.formatters[t];if("function"==typeof o){const a=e[r];i=o.call(n,a),e.splice(r,1),r--}return i})),a.formatArgs.call(n,e);(n.log||a.log).apply(n,e)}return s.namespace=e,s.useColors=a.useColors(),s.color=a.selectColor(e),s.extend=n,s.destroy=a.destroy,Object.defineProperty(s,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==r?r:(t!==a.namespaces&&(t=a.namespaces,o=a.enabled(e)),o),set:e=>{r=e}}),"function"==typeof a.init&&a.init(s),s}function n(e,n){const i=a(this.namespace+(void 0===n?":":n)+e);return i.log=this.log,i}function i(e,a){let n=0,i=0,t=-1,o=0;for(;n<e.length;)if(i<a.length&&(a[i]===e[n]||"*"===a[i]))"*"===a[i]?(t=i,o=n,i++):(n++,i++);else{if(-1===t)return!1;i=t+1,o++,n=o}for(;i<a.length&&"*"===a[i];)i++;return i===a.length}return a.debug=a,a.default=a,a.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},a.disable=function(){const e=[...a.names,...a.skips.map((e=>"-"+e))].join(",");return a.enable(""),e},a.enable=function(e){a.save(e),a.namespaces=e,a.names=[],a.skips=[];const n=("string"==typeof e?e:"").trim().replace(" ",",").split(",").filter(Boolean);for(const e of n)"-"===e[0]?a.skips.push(e.slice(1)):a.names.push(e)},a.enabled=function(e){for(const n of a.skips)if(i(e,n))return!1;for(const n of a.names)if(i(e,n))return!0;return!1},a.humanize=Te,a.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach((n=>{a[n]=e[n]})),a.names=[],a.skips=[],a.formatters={},a.selectColor=function(e){let n=0;for(let a=0;a<e.length;a++)n=(n<<5)-n+e.charCodeAt(a),n|=0;return a.colors[Math.abs(n)%a.colors.length]},a.enable(a.load()),a},xe}var qe,Ie,Fe,ze,Re,Be={exports:{}};function Le(){return Ie?qe:(Ie=1,qe=(e,a=process.argv)=>{const n=e.startsWith("-")?"":1===e.length?"-":"--",i=a.indexOf(n+e),t=a.indexOf("--");return-1!==i&&(-1===t||i<t)})}"undefined"==typeof process||"renderer"===process.type||!0===process.browser||process.__nwjs?we.exports=(ge||(ge=1,function(e,a){a.formatArgs=function(a){if(a[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+a[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;a.splice(1,0,n,"color: inherit");let i=0,t=0;a[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(i++,"%c"===e&&(t=i))})),a.splice(t,0,n)},a.save=function(e){try{e?a.storage.setItem("debug",e):a.storage.removeItem("debug")}catch(e){}},a.load=function(){let e;try{e=a.storage.getItem("debug")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},a.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let e;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},a.storage=function(){try{return localStorage}catch(e){}}(),a.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),a.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],a.log=console.debug||console.log||(()=>{}),e.exports=Pe()(a);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(ke,ke.exports)),ke.exports):we.exports=(Re||(Re=1,function(e,a){const n=s,i=c;a.init=function(e){e.inspectOpts={};const n=Object.keys(a.inspectOpts);for(let i=0;i<n.length;i++)e.inspectOpts[n[i]]=a.inspectOpts[n[i]]},a.log=function(...e){return process.stderr.write(i.formatWithOptions(a.inspectOpts,...e)+"\n")},a.formatArgs=function(n){const{namespace:i,useColors:t}=this;if(t){const a=this.color,t="[3"+(a<8?a:"8;5;"+a),o=` ${t};1m${i} `;n[0]=o+n[0].split("\n").join("\n"+o),n.push(t+"m+"+e.exports.humanize(this.diff)+"")}else n[0]=(a.inspectOpts.hideDate?"":(new Date).toISOString()+" ")+i+" "+n[0]},a.save=function(e){e?process.env.DEBUG=e:delete process.env.DEBUG},a.load=function(){return process.env.DEBUG},a.useColors=function(){return"colors"in a.inspectOpts?Boolean(a.inspectOpts.colors):n.isatty(process.stderr.fd)},a.destroy=i.deprecate((()=>{}),"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."),a.colors=[6,2,3,4,5,1];try{const e=function(){if(ze)return Fe;ze=1;const e=p,a=s,n=Le(),{env:i}=process;let t;function o(e){return 0!==e&&{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function r(a,o){if(0===t)return 0;if(n("color=16m")||n("color=full")||n("color=truecolor"))return 3;if(n("color=256"))return 2;if(a&&!o&&void 0===t)return 0;const r=t||0;if("dumb"===i.TERM)return r;if("win32"===process.platform){const a=e.release().split(".");return Number(a[0])>=10&&Number(a[2])>=10586?Number(a[2])>=14931?3:2:1}if("CI"in i)return["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","GITHUB_ACTIONS","BUILDKITE"].some((e=>e in i))||"codeship"===i.CI_NAME?1:r;if("TEAMCITY_VERSION"in i)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(i.TEAMCITY_VERSION)?1:0;if("truecolor"===i.COLORTERM)return 3;if("TERM_PROGRAM"in i){const e=parseInt((i.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(i.TERM_PROGRAM){case"iTerm.app":return e>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(i.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(i.TERM)||"COLORTERM"in i?1:r}return n("no-color")||n("no-colors")||n("color=false")||n("color=never")?t=0:(n("color")||n("colors")||n("color=true")||n("color=always"))&&(t=1),"FORCE_COLOR"in i&&(t="true"===i.FORCE_COLOR?1:"false"===i.FORCE_COLOR?0:0===i.FORCE_COLOR.length?1:Math.min(parseInt(i.FORCE_COLOR,10),3)),Fe={supportsColor:function(e){return o(r(e,e&&e.isTTY))},stdout:o(r(!0,a.isatty(1))),stderr:o(r(!0,a.isatty(2)))}}();e&&(e.stderr||e).level>=2&&(a.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221])}catch(e){}a.inspectOpts=Object.keys(process.env).filter((e=>/^debug_/i.test(e))).reduce(((e,a)=>{const n=a.substring(6).toLowerCase().replace(/_([a-z])/g,((e,a)=>a.toUpperCase()));let i=process.env[a];return i=!!/^(yes|on|true|enabled)$/i.test(i)||!/^(no|off|false|disabled)$/i.test(i)&&("null"===i?null:Number(i)),e[n]=i,e}),{}),e.exports=Pe()(a);const{formatters:t}=e.exports;t.o=function(e){return this.inspectOpts.colors=this.useColors,i.inspect(e,this.inspectOpts).split("\n").map((e=>e.trim())).join(" ")},t.O=function(e){return this.inspectOpts.colors=this.useColors,i.inspect(e,this.inspectOpts)}}(Be,Be.exports)),Be.exports);var Me=we.exports,Ne={exports:{}},De=function(e,a){if(!Array.isArray(e))throw new TypeError("arg must be an array of [ee, events...] arrays");for(var n=[],i=0;i<e.length;i++){var t=e[i];if(!Array.isArray(t)||t.length<2)throw new TypeError("each array member must be [ee, events...]");for(var o=t[0],r=1;r<t.length;r++){var s=t[r],c=$e(s,p);o.on(s,c),n.push({ee:o,event:s,fn:c})}}function p(){l(),a.apply(null,arguments)}function l(){for(var e,a=0;a<n.length;a++)(e=n[a]).ee.removeListener(e.event,e.fn)}function u(e){a=e}return u.cancel=l,u};function $e(e,a){return function(n){for(var i=new Array(arguments.length),t="error"===e?n:null,o=0;o<i.length;o++)i[o]=arguments[o];a(t,this,e,i)}} /*! * on-finished * Copyright(c) 2013 Jonathan Ong * Copyright(c) 2014 Douglas Christopher Wilson * MIT Licensed */Ne.exports=function(e,a){if(!1!==Ve(e))return We(a,null,e),e;return function(e,a){var n=e.__onFinished;n&&n.queue||(n=e.__onFinished=function(e){function a(n){if(e.__onFinished===a&&(e.__onFinished=null),a.queue){var i=a.queue;a.queue=null;for(var t=0;t<i.length;t++)i[t](n,e)}}return a.queue=[],a}(e),function(e,a){var n,i,t=!1;function o(e){n.cancel(),i.cancel(),t=!0,a(e)}function r(a){e.removeListener("socket",r),t||n===i&&(i=He([[a,"error","close"]],o))}if(n=i=He([[e,"end","finish"]],o),e.socket)return void r(e.socket);e.on("socket",r),void 0===e.socket&&function(e,a){var n=e.assignSocket;if("function"!=typeof n)return;e.assignSocket=function(e){n.call(this,e),a(e)}}(e,r)}(e,n));n.queue.push(a)}(e,function(e){var a;Ue.AsyncResource&&(a=new Ue.AsyncResource(e.name||"bound-anonymous-fn"));if(!a||!a.runInAsyncScope)return e;return a.runInAsyncScope.bind(a,e,null)}(a)),e},Ne.exports.isFinished=Ve;var Ue=function(){try{return require("async_hooks")}catch(e){return{}}}(),He=De,We="function"==typeof setImmediate?setImmediate:function(e){process.nextTick(e.bind.apply(e,arguments))};function Ve(e){var a=e.socket;return"boolean"==typeof e.finished?Boolean(e.finished||a&&!a.writable):"boolean"==typeof e.complete?Boolean(e.upgrade||!a||!a.readable||e.complete&&!e.readable):void 0}var Ge,Ke=Ne.exports,Je={exports:{}};function Ze(){if(Ge)return Je.exports;Ge=1,Je.exports=function(e,a){if("string"==typeof e)return o(e);if("number"==typeof e)return t(e,a);return null},Je.exports.format=t,Je.exports.parse=o;var e=/\B(?=(\d{3})+(?!\d))/g,a=/(?:\.0*|(\.[^0]+)0+)$/,n={b:1,kb:1024,mb:1<<20,gb:1<<30,tb:Math.pow(1024,4),pb:Math.pow(1024,5)},i=/^((-|\+)?(\d+(?:\.\d+)?)) *(kb|mb|gb|tb|pb)$/i;function t(i,t){if(!Number.isFinite(i))return null;var o=Math.abs(i),r=t&&t.thousandsSeparator||"",s=t&&t.unitSeparator||"",c=t&&void 0!==t.decimalPlaces?t.decimalPlaces:2,p=Boolean(t&&t.fixedDecimals),l=t&&t.unit||"";l&&n[l.toLowerCase()]||(l=o>=n.pb?"PB":o>=n.tb?"TB":o>=n.gb?"GB":o>=n.mb?"MB":o>=n.kb?"KB":"B");var u=(i/n[l.toLowerCase()]).toFixed(c);return p||(u=u.replace(a,"$1")),r&&(u=u.split(".").map((function(a,n){return 0===n?a.replace(e,r):a})).join(".")),u+s+l}function o(e){if("number"==typeof e&&!isNaN(e))return e;if("string"!=typeof e)return null;var a,t=i.exec(e),o="b";return t?(a=parseFloat(t[1]),o=t[4].toLowerCase()):(a=parseInt(e,10),o="b"),isNaN(a)?null:Math.floor(n[o]*a)}return Je.exports}var Xe,Ye,Qe={exports:{}};function ea(){if(Ye)return Xe;Ye=1;var e,a=l,n=a.Buffer,i={};for(e in a)a.hasOwnProperty(e)&&"SlowBuffer"!==e&&"Buffer"!==e&&(i[e]=a[e]);var t=i.Buffer={};for(e in n)n.hasOwnProperty(e)&&"allocUnsafe"!==e&&"allocUnsafeSlow"!==e&&(t[e]=n[e]);if(i.Buffer.prototype=n.prototype,t.from&&t.from!==Uint8Array.from||(t.from=function(e,a,i){if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type '+typeof e);if(e&&void 0===e.length)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);return n(e,a,i)}),t.alloc||(t.alloc=function(e,a,i){if("number"!=typeof e)throw new TypeError('The "size" argument must be of type number. Received type '+typeof e);if(e<0||e>=2*(1<<30))throw new RangeError('The value "'+e+'" is invalid for option "size"');var t=n(e);return a&&0!==a.length?"string"==typeof i?t.fill(a,i):t.fill(a):t.fill(0),t}),!i.kStringMaxLength)try{i.kStringMaxLength=process.binding("buffer").kStringMaxLength}catch(e){}return i.constants||(i.constants={MAX_LENGTH:i.kMaxLength},i.kStringMaxLength&&(i.constants.MAX_STRING_LENGTH=i.kStringMaxLength)),Xe=i}var aa,na={};function ia(){if(aa)return na;aa=1;function e(e,a){this.encoder=e,this.addBOM=!0}function a(e,a){this.decoder=e,this.pass=!1,this.options=a||{}}return na.PrependBOM=e,e.prototype.write=function(e){return this.addBOM&&(e="\ufeff"+e,this.addBOM=!1),this.encoder.write(e)},e.prototype.end=function(){return this.encoder.end()},na.StripBOM=a,a.prototype.write=function(e){var a=this.decoder.write(e);return this.pass||!a||("\ufeff"===a[0]&&(a=a.slice(1),"function"==typeof this.options.stripBOM&&this.options.stripBOM()),this.pass=!0),a},a.prototype.end=function(){return this.decoder.end()},na}var ta,oa,ra={};function sa(){if(oa)return ta;oa=1;var e=ea().Buffer;function a(a,n){this.enc=a.encodingName,this.bomAware=a.bomAware,"base64"===this.enc?this.encoder=o:"cesu8"===this.enc&&(this.enc="utf8",this.encoder=r,"💩"!==e.from("eda0bdedb2a9","hex").toString()&&(this.decoder=s,this.defaultCharUnicode=n.defaultCharUnicode))}ta={utf8:{type:"_internal",bomAware:!0},cesu8:{type:"_internal",bomAware:!0},unicode11utf8:"utf8",ucs2:{type:"_internal",bomAware:!0},utf16le:"ucs2",binary:{type:"_internal"},base64:{type:"_internal"},hex:{type:"_internal"},_internal:a},a.prototype.encoder=t,a.prototype.decoder=i;var n=u.StringDecoder;function i(e,a){this.decoder=new n(a.enc)}function t(e,a){this.enc=a.enc}function o(e,a){this.prevStr=""}function r(e,a){}function s(e,a){this.acc=0,this.contBytes=0,this.accBytes=0,this.defaultCharUnicode=a.defaultCharUnicode}return n.prototype.end||(n.prototype.end=function(){}),i.prototype.write=function(a){return e.isBuffer(a)||(a=e.from(a)),this.decoder.write(a)},i.prototype.end=function(){return this.decoder.end()},t.prototype.write=function(a){return e.from(a,this.enc)},t.prototype.end=function(){},o.prototype.write=function(a){var n=(a=this.prevStr+a).length-a.length%4;return this.prevStr=a.slice(n),a=a.slice(0,n),e.from(a,"base64")},o.prototype.end=function(){return e.from(this.prevStr,"base64")},r.prototype.write=function(a){for(var n=e.alloc(3*a.length),i=0,t=0;t<a.length;t++){var o=a.charCodeAt(t);o<128?n[i++]=o:o<2048?(n[i++]=192+(o>>>6),n[i++]=128+(63&o)):(n[i++]=224+(o>>>12),n[i++]=128+(o>>>6&63),n[i++]=128+(63&o))}return n.slice(0,i)},r.prototype.end=function(){},s.prototype.write=function(e){for(var a=this.acc,n=this.contBytes,i=this.accBytes,t="",o=0;o<e.length;o++){var r=e[o];128!=(192&r)?(n>0&&(t+=this.defaultCharUnicode,n=0),r<128?t+=String.fromCharCode(r):r<224?(a=31&r,n=1,i=1):r<240?(a=15&r,n=2,i=1):t+=this.defaultCharUnicode):n>0?(a=a<<6|63&r,i++,0===--n&&(t+=2===i&&a<128&&a>0||3===i&&a<2048?this.defaultCharUnicode:String.fromCharCode(a))):t+=this.defaultCharUnicode}return this.acc=a,this.contBytes=n,this.accBytes=i,t},s.prototype.end=function(){var e=0;return this.contBytes>0&&(e+=this.defaultCharUnicode),e},ta}var ca,pa={};function la(){if(ca)return pa;ca=1;var e=ea().Buffer;function a(e,a){this.iconv=a,this.bomAware=!0,this.isLE=e.isLE}function n(e,a){this.isLE=a.isLE,this.highSurrogate=0}function i(e,a){this.isLE=a.isLE,this.badChar=a.iconv.defaultCharUnicode.charCodeAt(0),this.overflow=[]}function t(e,a,n,i){if((n<0||n>1114111)&&(n=i),n>=65536){var t=55296|(n-=65536)>>10;e[a++]=255&t,e[a++]=t>>8;n=56320|1023&n}return e[a++]=255&n,e[a++]=n>>8,a}function o(e,a){this.iconv=a}function r(e,a){void 0===(e=e||{}).addBOM&&(e.addBOM=!0),this.encoder=a.iconv.getEncoder(e.defaultEncoding||"utf-32le",e)}function s(e,a){this.decoder=null,this.initialBufs=[],this.initialBufsLen=0,this.options=e||{},this.iconv=a.iconv}function c(e,a){var n=[],i=0,t=0,o=0,r=0,s=0;e:for(var c=0;c<e.length;c++)for(var p=e[c],l=0;l<p.length;l++)if(n.push(p[l]),4===n.length){if(0===i){if(255===n[0]&&254===n[1]&&0===n[2]&&0===n[3])return"utf-32le";if(0===n[0]&&0===n[1]&&254===n[2]&&255===n[3])return"utf-32be"}if((0!==n[0]||n[1]>16)&&o++,(0!==n[3]||n[2]>16)&&t++,0!==n[0]||0!==n[1]||0===n[2]&&0===n[3]||s++,0===n[0]&&0===n[1]||0!==n[2]||0!==n[3]||r++,n.length=0,++i>=100)break e}return s-o>r-t?"utf-32be":s-o<r-t?"utf-32le":a||"utf-32le"}return pa._utf32=a,pa.utf32le={type:"_utf32",isLE:!0},pa.utf32be={type:"_utf32",isLE:!1},pa.ucs4le="utf32le",pa.ucs4be="utf32be",a.prototype.encoder=n,a.prototype.decoder=i,n.prototype.write=function(a){for(var n=e.from(a,"ucs2"),i=e.alloc(2*n.length),t=this.isLE?i.writeUInt32LE:i.writeUInt32BE,o=0,r=0;r<n.length;r+=2){var s=n.readUInt16LE(r),c=55296<=s&&s<56320,p=56320<=s&&s<57344;if(this.highSurrogate){if(!c&&p){var l=65536+(this.highSurrogate-55296<<10|s-56320);t.call(i,l,o),o+=4,this.highSurrogate=0;continue}t.call(i,this.highSurrogate,o),o+=4}c?this.highSurrogate=s:(t.call(i,s,o),o+=4,this.highSurrogate=0)}return o<i.length&&(i=i.slice(0,o)),i},n.prototype.end=function(){if(this.highSurrogate){var a=e.alloc(4);return this.isLE?a.writeUInt32LE(this.highSurrogate,0):a.writeUInt32BE(this.highSurrogate,0),this.highSurrogate=0,a}},i.prototype.write=function(a){if(0===a.length)return"";var n=0,i=0,o=e.alloc(a.length+4),r=0,s=this.isLE,c=this.overflow,p=this.badChar;if(c.length>0){for(;n<a.length&&c.length<4;n++)c.push(a[n]);4===c.length&&(i=s?c[n]|c[n+1]<<8|c[n+2]<<16|c[n+3]<<24:c[n+3]|c[n+2]<<8|c[n+1]<<16|c[n]<<24,c.length=0,r=t(o,r,i,p))}for(;n<a.length-3;n+=4)r=t(o,r,i=s?a[n]|a[n+1]<<8|a[n+2]<<16|a[n+3]<<24:a[n+3]|a[n+2]<<8|a[n+1]<<16|a[n]<<24,p);for(;n<a.length;n++)c.push(a[n]);return o.slice(0,r).toString("ucs2")},i.prototype.end=function(){this.overflow.length=0},pa.utf32=o,pa.ucs4="utf32",o.prototype.encoder=r,o.prototype.decoder=s,r.prototype.write=function(e){return this.encoder.write(e)},r.prototype.end=function(){return this.encoder.end()},s.prototype.write=function(e){if(!this.decoder){if(this.initialBufs.push(e),this.initialBufsLen+=e.length,this.initialBufsLen<32)return"";var a=c(this.initialBufs,this.options.defaultEncoding);this.decoder=this.iconv.getDecoder(a,this.options);for(var n="",i=0;i<this.initialBufs.length;i++)n+=this.decoder.write(this.initialBufs[i]);return this.initialBufs.length=this.initialBufsLen=0,n}return this.decoder.write(e)},s.prototype.end=function(){if(!this.decoder){var e=c(this.initialBufs,this.options.defaultEncoding);this.decoder=this.iconv.getDecoder(e,this.options);for(var a="",n=0;n<this.initialBufs.length;n++)a+=this.decoder.write(this.initialBufs[n]);var i=this.decoder.end();return i&&(a+=i),this.initialBufs.length=this.initialBufsLen=0,a}return this.decoder.end()},pa}var ua,da={};function ma(){if(ua)return da;ua=1;var e=ea().Buffer;function a(){}function n(){}function i(){this.overflowByte=-1}function t(e,a){this.iconv=a}function o(e,a){void 0===(e=e||{}).addBOM&&(e.addBOM=!0),this.encoder=a.iconv.getEncoder("utf-16le",e)}function r(e,a){this.decoder=null,this.initialBufs=[],this.initialBufsLen=0,this.options=e||{},this.iconv=a.iconv}function s(e,a){var n=[],i=0,t=0,o=0;e:for(var r=0;r<e.length;r++)for(var s=e[r],c=0;c<s.length;c++)if(n.push(s[c]),2===n.length){if(0===i){if(255===n[0]&&254===n[1])return"utf-16le";if(254===n[0]&&255===n[1])return"utf-16be"}if(0===n[0]&&0!==n[1]&&o++,0!==n[0]&&0===n[1]&&t++,n.length=0,++i>=100)break e}return o>t?"utf-16be":o<t?"utf-16le":a||"utf-16le"}return da.utf16be=a,a.prototype.encoder=n,a.prototype.decoder=i,a.prototype.bomAware=!0,n.prototype.write=function(a){for(var n=e.from(a,"ucs2"),i=0;i<n.length;i+=2){var t=n[i];n[i]=n[i+1],n[i+1]=t}return n},n.prototype.end=function(){},i.prototype.write=function(a){if(0==a.length)return"";var n=e.alloc(a.length+1),i=0,t=0;for(-1!==this.overflowByte&&(n[0]=a[0],n[1]=this.overflowByte,i=1,t=2);i<a.length-1;i+=2,t+=2)n[t]=a[i+1],n[t+1]=a[i];return this.overflowByte=i==a.length-1?a[a.length-1]:-1,n.slice(0,t).toString("ucs2")},i.prototype.end=function(){this.overflowByte=-1},da.utf16=t,t.prototype.encoder=o,t.prototype.decoder=r,o.prototype.write=function(e){return this.encoder.write(e)},o.prototype.end=function(){return this.encoder.end()},r.prototype.write=function(e){if(!this.decoder){if(this.initialBufs.push(e),this.initialBufsLen+=e.length,this.initialBufsLen<16)return"";var a=s(this.initialBufs,this.options.defaultEncoding);this.decoder=this.iconv.getDecoder(a,this.options);for(var n="",i=0;i<this.initialBufs.length;i++)n+=this.decoder.write(this.initialBufs[i]);return this.initialBufs.length=this.initialBufsLen=0,n}return this.decoder.write(e)},r.prototype.end=function(){if(!this.decoder){var e=s(this.initialBufs,this.options.defaultEncoding);this.decoder=this.iconv.getDecoder(e,this.options);for(var a="",n=0;n<this.initialBufs.length;n++)a+=this.decoder.write(this.initialBufs[n]);var i=this.decoder.end();return i&&(a+=i),this.initialBufs.length=this.initialBufsLen=0,a}return this.decoder.end()},da}var fa,ha={};function va(){if(fa)return ha;fa=1;var e=ea().Buffer;function a(e,a){this.iconv=a}ha.utf7=a,ha.unicode11utf7="utf7",a.prototype.encoder=i,a.prototype.decoder=t,a.prototype.bomAware=!0;var n=/[^A-Za-z0-9'\(\),-\.\/:\? \n\r\t]+/g;function i(e,a){this.iconv=a.iconv}function t(e,a){this.iconv=a.iconv,this.inBase64=!1,this.base64Accum=""}i.prototype.write=function(a){return e.from(a.replace(n,function(e){return"+"+("+"===e?"":this.iconv.encode(e,"utf16-be").toString("base64").replace(/=+$/,""))+"-"}.bind(this)))},i.prototype.end=function(){};for(var o=/[A-Za-z0-9\/+]/,r=[],s=0;s<256;s++)r[s]=o.test(String.fromCharCode(s));var c="+".charCodeAt(0),p="-".charCodeAt(0),l="&".charCodeAt(0);function u(e,a){this.iconv=a}function d(a,n){this.iconv=n.iconv,this.inBase64=!1,this.base64Accum=e.alloc(6),this.base64AccumIdx=0}function m(e,a){this.iconv=a.iconv,this.inBase64=!1,this.base64Accum=""}t.prototype.write=function(a){for(var n="",i=0,t=this.inBase64,o=this.base64Accum,s=0;s<a.length;s++)if(t){if(!r[a[s]]){if(s==i&&a[s]==p)n+="+";else{var l=o+this.iconv.decode(a.slice(i,s),"ascii");n+=this.iconv.decode(e.from(l,"base64"),"utf16-be")}a[s]!=p&&s--,i=s+1,t=!1,o=""}}else a[s]==c&&(n+=this.iconv.decode(a.slice(i,s),"ascii"),i=s+1,t=!0);if(t){var u=(l=o+this.iconv.decode(a.slice(i),"ascii")).length-l.length%8;o=l.slice(u),l=l.slice(0,u),n+=this.iconv.decode(e.from(l,"base64"),"utf16-be")}else n+=this.iconv.decode(a.slice(i),"ascii");return this.inBase64=t,this.base64Accum=o,n},t.prototype.end=function(){var a="";return this.inBase64&&this.base64Accum.length>0&&(a=this.iconv.decode(e.from(this.base64Accum,"base64"),"utf16-be")),this.inBase64=!1,this.base64Accum="",a},ha.utf7imap=u,u.prototype.encoder=d,u.prototype.decoder=m,u.prototype.bomAware=!0,d.prototype.write=function(a){for(var n=this.inBase64,i=this.base64Accum,t=this.base64AccumIdx,o=e.alloc(5*a.length+10),r=0,s=0;s<a.length;s++){var c=a.charCodeAt(s);32<=c&&c<=126?(n&&(t>0&&(r+=o.write(i.slice(0,t).toString("base64").replace(/\//g,",").replace(/=+$/,""),r),t=0),o[r++]=p,n=!1),n||(o[r++]=c,c===l&&(o[r++]=p))):(n||(o[r++]=l,n=!0),n&&(i[t++]=c>>8,i[t++]=255&c,t==i.length&&(r+=o.write(i.toString("base64").replace(/\//g,","),r),t=0)))}return this.inBase64=n,this.base64AccumIdx=t,o.slice(0,r)},d.prototype.end=function(){var a=e.alloc(10),n=0;return this.inBase64&&(this.base64AccumIdx>0&&(n+=a.write(this.base64Accum.slice(0,this.base64AccumIdx).toString("base64").replace(/\//g,",").replace(/=+$/,""),n),this.base64AccumIdx=0),a[n++]=p,this.inBase64=!1),a.slice(0,n)};var f=r.slice();return f[",".charCodeAt(0)]=!0,m.prototype.write=function(a){for(var n="",i=0,t=this.inBase64,o=this.base64Accum,r=0;r<a.length;r++)if(t){if(!f[a[r]]){if(r==i&&a[r]==p)n+="&";else{var s=o+this.iconv.decode(a.slice(i,r),"ascii").replace(/,/g,"/");n+=this.iconv.decode(e.from(s,"base64"),"utf16-be")}a[r]!=p&&r--,i=r+1,t=!1,o=""}}else a[r]==l&&(n+=this.iconv.decode(a.slice(i,r),"ascii"),i=r+1,t=!0);if(t){var c=(s=o+this.iconv.decode(a.slice(i),"ascii").replace(/,/g,"/")).length-s.length%8;o=s.slice(c),s=s.slice(0,c),n+=this.iconv.decode(e.from(s,"base64"),"utf16-be")}else n+=this.iconv.decode(a.slice(i),"ascii");return this.inBase64=t,this.base64Accum=o,n},m.prototype.end=function(){var a="";return this.inBase64&&this.base64Accum.length>0&&(a=this.iconv.decode(e.from(this.base64Accum,"base64"),"utf16-be")),this.inBase64=!1,this.base64Accum="",a},ha}var xa,ba,ga,ya,wa,ka={};function ja(){if(xa)return ka;xa=1;var e=ea().Buffer;function a(a,n){if(!a)throw new Error("SBCS codec is called without the data.");if(!a.chars||128!==a.chars.length&&256!==a.chars.length)throw new Error("Encoding '"+a.type+"' has incorrect 'chars' (must be of len 128 or 256)");if(128===a.chars.length){for(var i="",t=0;