aipg_horde
Version:
A package to interact with the ai horde API
2 lines (1 loc) • 31.3 kB
JavaScript
"use strict";var w=Object.create;var f=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var v=Object.getPrototypeOf;var R=Object.prototype.hasOwnProperty;var u=(i,e)=>f(i,"name",{value:e,configurable:true});var A=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports);var G=(i,e)=>{for(var t in e)f(i,t,{get:e[t],enumerable:true})};var b=(i,e,t,s)=>{if(e&&typeof e==="object"||typeof e==="function"){for(let r of M(e))if(!R.call(i,r)&&r!==t)f(i,r,{get:()=>e[r],enumerable:!(s=I(e,r))||s.enumerable})}return i};var k=(i,e,t)=>(t=i!=null?w(v(i)):{},b(e||!i||!i.__esModule?f(t,"default",{value:i,enumerable:true}):t,i));var D=i=>b(f({},"__esModule",{value:true}),i);var _=A((y,S)=>{var T=Object.defineProperty;var E=u(i=>T(i,"__esModule",{value:true}),"f");var F=u((i,e)=>T(i,"name",{value:e,configurable:true}),"h");E(y);var l=Symbol("supermap.date_cache");var p=u(class extends Map{#n;[l]=null;#t=null;constructor(i={}){if("intervalTime"in i&&(!Number.isSafeInteger(i.intervalTime)||i.intervalTime<0))throw new TypeError("options.intervalTime must be a safe positive integer.");if("expireAfter"in i&&(!Number.isSafeInteger(i.expireAfter)||i.expireAfter<0))throw new TypeError("options.expireAfter must be a safe positive integer.");if("itemsLimit"in i&&(!Number.isSafeInteger(i.itemsLimit)||i.itemsLimit<0))throw new TypeError("options.itemsLimit must be a safe positive integer.");if("onSweep"in i&&typeof i.onSweep!=="function")throw new TypeError("options.onSweep must be a function.");i={expireAfter:0,itemsLimit:0,...i};super();this.#n=i;if("intervalTime"in i){this[l]=new Map;this.startInterval()}}toArray(){return Array.from(this.entries())}delete(i){return this[l]?.delete(i),super.delete(i)}set(i,e,t=0){if(!Number.isSafeInteger(t))throw new TypeError("ttl must be a safe integer");const s=this.#n.itemsLimit;if(s>0&&this.size>=s&&!this.has(i)){this.delete(this.first(true))}this[l]?.set(i,Date.now()+t);return super.set(i,e)}clear(i=false){if(i)this.stopInterval();else this[l]?.clear();return super.clear()}first(i){return i?this.keys().next().value:this.values().next().value}last(i=false){const e=this.entries();let t;while(true){const s=e.next();if(s.done)return t&&t[i?0:1];t=s.value}}some(i){const e=this.entries();while(true){const t=e.next();if(t.done)return false;if(i(t.value[1],t.value[0],this))return true}}every(i){const e=this.entries();while(true){const t=e.next();if(t.done)return true;if(!i(t.value[1],t.value[0],this))return false}}sweep(i){if(this.size===0)return-1;const e=this.#n.onSweep;const t=this.size;super.forEach((s,r)=>{if(i(s,r,this)){e?.(s,r);this.delete(r)}});return t-this.size}filter(i){const e=new p(this.#n);const t=this.entries();while(true){const s=t.next();if(s.done)return e;const[r,n]=s.value;if(i(n,r,this))e.set(r,n)}}map(i,e){return Array.from(this.#o(i,e))}find(i,e=false){const t=this.entries();while(true){const s=t.next();if(s.done)return null;const[r,n]=s.value;if(i(n,r,this))return e?r:n}}reduce(i,e){const t=this.entries();var s=e;while(true){const r=t.next();if(r.done)return s;s=i(s,r.value[1],r.value[0],this)}}concat(...i){const e=new p(this.#n);e[l]=this[l];for(const t of i.concat(this)){const s=t.entries();while(true){const r=s.next();if(r.done)break;e.set(...r.value)}}return e}concatMut(...i){for(const e of i){const t=e.entries();while(true){const s=t.next();if(s.done)break;this.set(...s.value)}}return this}sort(i){this.toArray().sort(([e,t],[s,r])=>i(t,r,e,s,this)).forEach(e=>this.set(...e));this.clear();return this}startInterval(){if(this[l]===null||!("intervalTime"in this.#n)){return false}this.stopInterval();this.#t=setInterval(()=>this.#s(),this.#n.intervalTime).unref();return true}stopInterval(){if(this[l]===null)return false;this[l].clear();if(this.#t!==null){clearInterval(this.#t);this.#t=null}return true}#s(){const i=this.entries(),e=this[l].entries();const t=Date.now()-this.#n.expireAfter;const s=this.#n.onSweep;while(true){const r=i.next();if(r.done)return;if(t>(e.next().value?.[1]||0)){const n=r.value[0];s?.(r.value[1],n);this.delete(n)}}}*#o(i,e){const t=this.entries();if(e){while(true){const s=t.next();if(s.done)return;const[r,n]=s.value;if(e(n,r,this)){yield i(n,r,this)}}}while(true){const s=t.next();if(s.done)return;yield i(s.value[1],s.value[0],this)}}},"u");F(p,"SuperMap");S.exports=p});var z={};G(z,{AIHorde:()=>h,AIHordeRatings:()=>g,APIError:()=>m,ErrorMessages:()=>x,GenerationMetadataStableTypes:()=>L,GenerationMetadataStableValues:()=>$,HordeAsyncRequestStates:()=>C,ModelGenerationInputControlTypes:()=>K,ModelGenerationInputPostProcessingTypes:()=>j,ModelGenerationInputStableSamplers:()=>N,ModelGenerationInputWorkflows:()=>H,ModelInterrogationFormTypes:()=>U,ModelPayloadTextInversionsStable:()=>W,RatingArtifactsRatings:()=>V,RequestSingleWarningCodes:()=>O,SourceImageProcessingTypes:()=>q});module.exports=D(z);var P=k(_(),1);var d=P.default;var x=Object.freeze({"MissingPrompt":"The generation prompt was not given","CorruptPrompt":"The prompts was rejected as unethical","KudosValidationError":"Something went wrong when transferring kudos. This is a base rc, so you should never typically see it.","NoValidActions":"Something went wrong when modifying an entity on the horde. This is a base rc, so you should never typically see it.","InvalidSize":"Requested image size is not a multiple of 64","InvalidPromptSize":"Prompt is too large","TooManySteps":"Too many steps requested for image generation","Profanity":"Profanity Detected. This is a base rc, so you should never typically see i","ProfaneWorkerName":"Profanity detected in worker name","ProfaneBridgeAgent":"Profanity detected in bridge agent","ProfaneWorkerInfo":"Profanity detected in worker info","ProfaneUserName":"Profanity detected in username","ProfaneUserContact":"Profanity detected in user contact details","ProfaneAdminComment":"Profanity detected in admin comment","ProfaneTeamName":"Profanity detected in team name","ProfaneTeamInfo":"Profanity detected in team info","TooLong":"Provided string was too long. This is a base rc, so you should never typically see it.","TooLongWorkerName":"The provided worker name is too long","TooLongUserName":"The provided username is too long","NameAlreadyExists":"The provided name already exists. This is a base rc, so you should never typically see it.","WorkerNameAlreadyExists":"The provided worker name already exists","TeamNameAlreadyExists":"The provided team name already exists","PolymorphicNameConflict":"The provided worker name already exists for a different worker type (e.g. Dreamer VS Scribe)","ImageValidationFailed":"Source image validation failed unexpectedly","SourceImageResolutionExceeded":"Source image resolution larger than the max allowed by the AI Horde","SourceImageSizeExceeded":"Source image file size larger than the max allowed by the AI Horde","SourceImageUrlInvalid":"Source image url does not contain an image","SourceImageUnreadable":"Source image could not be parsed","InpaintingMissingMask":"Missing mask or alpha channel for inpainting","SourceMaskUnnecessary":"Source mask sent without a source image","UnsupportedSampler":"Selected sampler unsupported with selected model","UnsupportedModel":"The required model name is unsupported with this payload. This is a base rc, so you should never typically see it.","ControlNetUnsupported":"ControlNet is unsupported in combination with this model","ControlNetSourceMissing":"Missing source image for ControlNet workflow","ControlNetInvalidPayload":"sent CN source and requested CN source at the same time","SourceImageRequiredForModel":"Source image is required for using this model","UnexpectedModelName":"Model name sent is not a Stable Diffusion checkpoint","TooManyUpscalers":"Tried to use more than 1 upscaler at a time","ProcGenNotFound":"The used generation for aesthetic ratings doesn't exist","InvalidAestheticAttempt":"Aesthetics rating attempt failed","AestheticsNotCompleted":"Attempted to rate non-completed request","AestheticsNotPublic":"Attempted to rate non-shared request","AestheticsDuplicate":"Sent duplicate images in an aesthetics set","AestheticsMissing":"Aesthetic ratings missing","AestheticsSolo":"Aesthetic ratings best-of contain a single image","AestheticsConfused":"The best image is not the one with the highest aesthetic rating","AestheticsAlreadyExist":"Aesthetic rating already submitted","AestheticsServerRejected":"Aesthetic server rejected submission","AestheticsServerError":"Aesthetic server returned error (provided)","AestheticsServerDown":"Aesthetic server is down","AestheticsServerTimeout":"Aesthetic server timed out during submission","InvalidAPIKey":"Invalid AI Horde API key provided","WrongCredentials":"Provided user does not own this worker","NotAdmin":"Request needs AI Horded admin credentials","NotModerator":"Request needs AI Horded moderator credentials","NotOwner":"Request needs worker owner credentials","NotPrivileged":"This user is not hardcoded to perform this operation","AnonForbidden":"Anonymous is not allowed to perform this operation","AnonForbiddenWorker":"Anonymous tried to run a worker","AnonForbiddenUserMod":"Anonymous tried to modify their user account","NotTrusted":"Untrusted users are not allowed to perform this operation","UntrustedTeamCreation":"Untrusted user tried to create a team","UntrustedUnsafeIP":"Untrusted user tried to use a VPN for a worker","WorkerMaintenance":"Worker has been put into maintenance and cannot pop new jobs","WorkerFlaggedMaintenance":"Worker owner has been flagged and worker has been put into permanent maintenance","TooManySameIPs":"Same IP attempted to spawn too many workers","WorkerInviteOnly":"AI Horde is in worker invite-only mode and worker owner needs to request permission","UnsafeIP":"Worker attempted to connect from VPN","TimeoutIP":"Operation rejected because user IP in timeout","TooManyNewIPs":"Too many workers from new IPs currently","KudosUpfront":"This request requires upfront kudos to accept","SharedKeyEmpty":"Shared Key used in the request does not have any more kudos","InvalidJobID":"Job not found when trying to submit. This probably means its request was delected for inactivity","RequestNotFound":"Request not found. This probably means it was delected for inactivity","WorkerNotFound":"Worker ID not found","TeamNotFound":"Team ID not found","FilterNotFound":"Regex filter not found","UserNotFound":"User not found","DuplicateGen":"Job has already been submitted","AbortedGen":"Request aborted because too many jobs have failed","RequestExpired":"Request expired","TooManyPrompts":"User has requested too many generations concurrently","NoValidWorkers":"No workers online which can pick up this request","MaintenanceMode":"Request aborted because horde is in maintenance mode","TargetAccountFlagged":"Action rejected because target user has been flagged for violating Horde ToS","SourceAccountFlagged":"Action rejected because source user has been flagged for violating Horde ToS","FaultWhenKudosReceiving":"Unexpected error when receiving kudos","FaultWhenKudosSending":"Unexpected error when sending kudos","TooFastKudosTransfers":"User tried to send kudos too fast after receiving them from the same user","KudosTransferToAnon":"User tried to transfer kudos to Anon","KudosTransferToSelf":"User tried to transfer kudos to themselves","KudosTransferNotEnough":"User tried to transfer more kudos than they have","NegativeKudosTransfer":"User tried to transfer negative kudos","KudosTransferFromAnon":"User tried to transfer kudos using the Anon API key","InvalidAwardUsername":"Tried to award kudos to non-existing user","KudosAwardToAnon":"Tried to award kudos to Anonymous user","NotAllowedAwards":"This user is not allowed to Award Kudos","NoWorkerModSelected":"No valid worker modification selected","NoUserModSelected":"No valid user modification selected","NoHordeModSelected":"No valid horde modification selected","NoTeamModSelected":"No valid team modification selected","NoFilterModSelected":"No valid regex filter modification selected","NoSharedKeyModSelected":"No valid shared key modification selected","BadRequest":"Generic HTTP 400 code. You should typically never see this","Forbidden":"Generic HTTP 401 code. You should typically never see this","Locked":"Generic HTTP code. You should typically never see this","Unknown":"Unknown rc code"});var N=Object.freeze({"lcm":"lcm","k_lms":"k_lms","k_heun":"k_heun","k_euler_a":"k_euler_a","k_euler":"k_euler","k_dpm_2":"k_dpm_2","k_dpm_2_a":"k_dpm_2_a","DDIM":"DDIM","PLMS":"PLMS","k_dpm_fast":"k_dpm_fast","k_dpm_adaptive":"k_dpm_adaptive","k_dpmpp_2s_a":"k_dpmpp_2s_a","k_dpmpp_2m":"k_dpmpp_2m","dpmsolver":"dpmsolver","k_dpmpp_sde":"k_dpmpp_sde"});var q=Object.freeze({"img2img":"img2img","inpainting":"inpainting","outpainting":"outpainting","remix":"remix"});var j=Object.freeze({"GFPGAN":"GFPGAN","RealESRGAN_x4plus":"RealESRGAN_x4plus","RealESRGAN_x2plus":"RealESRGAN_x2plus","RealESRGAN_x4plus_anime_6B":"RealESRGAN_x4plus_anime_6B","NMKD_Siax":"NMKD_Siax","4x_AnimeSharp":"4x_AnimeSharp","strip_background":"strip_background","CodeFormers":"CodeFormers"});var U=Object.freeze({"caption":"caption","interrogation":"interrogation","nsfw":"nsfw","GFPGAN":"GFPGAN","RealESRGAN_x4plus":"RealESRGAN_x4plus","RealESRGAN_x4plus_anime_6B":"RealESRGAN_x4plus_anime_6B","NMKD_Siax":"NMKD_Siax","4x_AnimeSharp":"4x_AnimeSharp","CodeFormers":"CodeFormers","strip_background":"strip_background"});var C=Object.freeze({"waiting":"waiting","processing":"processing","done":"done","faulted":"faulted","partial":"partial","cancelled":"cancelled"});var K=Object.freeze({"canny":"canny","hed":"hed","depth":"depth","normal":"normal","openpose":"openpose","seg":"seg","scribble":"scribble","fakescribbles":"fakescribbles","hough":"hough"});var W=Object.freeze({prompt:"prompt",negrpompt:"negprompt"});var H=Object.freeze({"qr_code":"qr_code"});var O=Object.freeze({"NoAvailableWorker":"NoAvailableWorker","ClipSkipMismatch":"ClipSkipMismatch","StepsTooFew":"StepsTooFew","StepsTooMany":"StepsTooMany","CfgScaleMismatch":"CfgScaleMismatch","CfgScaleTooSmall":"CfgScaleTooSmall","CfgScaleTooLarge":"CfgScaleTooLarge","SamplerMismatch":"SamplerMismatch","SchedulerMismatch":"SchedulerMismatch"});var L=Object.freeze({"lora":"lora","ti":"ti","censorship":"censorship","source_image":"source_image","source_mask":"source_mask","extra_source_images":"extra_source_images","batch_index":"batch_index","information":"information"});var $=Object.freeze({"download_failed":"download_failed","parse_failed":"parse_failed","baseline_mismatch":"baseline_mismatch","csam":"csam","nsfw":"nsfw","see_ref":"see_ref"});var m=class extends Error{rawError;status;method;url;requestBody;errors;error_code;constructor(e,t,s="GET",r){super();this.rawError=e;this.status=t.status??0;this.method=s;this.url=t.url??"";this.requestBody=r;this.errors="errors"in e?e.errors:{};this.message=x[e.rc]??e.message;this.error_code=e.rc}get name(){return this.rawError.rc||this.rawError.message}};u(m,"APIError");var h=class{#n;#t;#s;#o;VERSION;#i;ratings;constructor(e){this.#n=e?.default_token;this.#o=e?.api_route??"https://api.aipowergrid.io/api/v2";this.#t={users:e?.cache?.users??0,generations_check:e?.cache?.generations_check??0,generations_status:e?.cache?.generations_status??0,interrogations_status:e?.cache?.interrogations_status??0,models:e?.cache?.models??0,modes:e?.cache?.modes??0,news:e?.cache?.news??0,performance:e?.cache?.performance??0,workers:e?.cache?.workers??0,teams:e?.cache?.teams??0,sharedkeys:e?.cache?.sharedkeys??0};if(Object.values(this.#t).some(t=>!Number.isSafeInteger(t)||t<0))throw new TypeError("Every cache duration must be a positive safe integer");this.#s={users:this.#t.users?new d({intervalTime:e?.cache_interval??1e3,expireAfter:this.#t.users}):void 0,generations_check:this.#t.generations_check?new d({intervalTime:e?.cache_interval??1e3,expireAfter:this.#t.generations_check}):void 0,generations_status:this.#t.generations_status?new d({intervalTime:e?.cache_interval??1e3,expireAfter:this.#t.generations_status}):void 0,interrogations_status:this.#t.interrogations_status?new d({intervalTime:e?.cache_interval??1e3,expireAfter:this.#t.interrogations_status}):void 0,models:this.#t.models?new d({intervalTime:e?.cache_interval??1e3,expireAfter:this.#t.models}):void 0,modes:this.#t.modes?new d({intervalTime:e?.cache_interval??1e3,expireAfter:this.#t.modes}):void 0,news:this.#t.news?new d({intervalTime:e?.cache_interval??1e3,expireAfter:this.#t.news}):void 0,performance:this.#t.performance?new d({intervalTime:e?.cache_interval??1e3,expireAfter:this.#t.performance}):void 0,workers:this.#t.workers?new d({intervalTime:e?.cache_interval??1e3,expireAfter:this.#t.workers}):void 0,teams:this.#t.teams?new d({intervalTime:e?.cache_interval??1e3,expireAfter:this.#t.teams}):void 0,sharedkeys:this.#t.sharedkeys?new d({intervalTime:e?.cache_interval??1e3,expireAfter:this.#t.sharedkeys}):void 0};this.VERSION="Unknown";this.#i=e?.client_agent??"@zeldafan0225/ai_horde:Version_Unknown:github.com/ZeldaFan0225/ai_horde/issues";(async()=>{let t=await import("fs");let s=await import("path");try{let r=JSON.parse(t.readFileSync(s.join(__dirname,"package.json")).toString());this.VERSION=r.version;this.#i=e?.client_agent??`${r.name}:${r.version}:${r.bugs?.slice(8)}`}catch(r){}})().catch(t=>{});this.ratings=new g({api_route:e?.ratings_api_route??"https://ratings.aihorde.net/api/v1",default_token:e?.default_token,client_agent:this.#i})}#r(e){return e||this.#n||"0000000000"}clearCache(){Object.values(this.#s).forEach(e=>e.clear())}get cache(){return this.#s}parseAgent(e){const[t,s,r]=e.split(":");return{name:t,version:s,link:r}}generateFieldsString(e){return e?.join(",")}async#e(e,t,s){const r=s?.fields?.join(",")||s?.fields_string||"";const n=this.#r(s?.token);const o={"Client-Agent":this.#i,"Content-Type":"application/json"};if(s?.token)o["apikey"]=n;if(r)o["X-Fields"]=r;const a=await fetch(`${this.#o}${e}`,{method:t,headers:o,body:s?.body?JSON.stringify(s.body):void 0});if(!a.status.toString().startsWith("2"))throw new m(await a.json(),a,t,s?.body);return{result:a,fields_string:r}}async findUser(e){const{result:t,fields_string:s}=await this.#e("/find_user","GET",e);const r=await t.json();if(this.#t.users){const n=r;if("id"in n)this.#s.users?.set(n.id+s,r)}return r}async getUserDetails(e,t){const s=this.generateFieldsString(t?.fields);const r=this.#r(t?.token);const n=!t?.force&&this.#s.users?.get(e.toString()+s);if(n)return n;const{result:o}=await this.#e(`/users/${e}`,"GET",{fields_string:s,token:r});const a=await o.json();if(this.#t.users){const c=a;if("id"in c)this.#s.users?.set(c.id+s,a)}return a}async getTeam(e,t){const s=t?.fields?.length?t.fields.join(","):"";const r=this.#r(t?.token);const n=!t?.force&&this.#s.teams?.get(e+s);if(n)return n;const{result:o}=await this.#e(`/teams/${e}`,"GET",{token:r,fields_string:s});const a=await o.json();if(this.#t.teams){const c=a;if("id"in c)this.#s.teams?.set(c.id+s,a)}return a}async getWorkerDetails(e,t){const s=t?.fields?.length?t.fields.join(","):"";const r=this.#r(t?.token);const n=!t?.force&&this.#s.workers?.get(e+s);if(n)return n;const{result:o}=await this.#e(`/workers/${e}`,"GET",{token:r,fields_string:s});const a=await o.json();if(this.#t.workers){const c=a;if("id"in c)this.#s.workers?.set(c.id+s,a)}return a}async getImageGenerationCheck(e,t){const s=t?.fields?.length?t.fields.join(","):"";const r=!t?.force&&this.#s.generations_check?.get(e+s);if(r)return r;const{result:n}=await this.#e(`/generate/check/${e}`,"GET",{fields_string:s});const o=await n.json();if(this.#t.generations_check)this.#s.generations_check?.set(e+s,o);return o}async getImageGenerationStatus(e,t){const s=t?.fields?.length?t.fields.join(","):"";const r=!t?.force&&this.#s.generations_status?.get(e+s);if(r)return r;const{result:n}=await this.#e(`/generate/status/${e}`,"GET",{fields_string:s});const o=await n.json();if(this.#t.generations_status)this.#s.generations_status?.set(e+s,o);return o}async getTextGenerationStatus(e,t){const s=t?.fields?.length?t.fields.join(","):"";const r=!t?.force&&this.#s.generations_status?.get(e+s);if(r)return r;const{result:n}=await this.#e(`/generate/text/status/${e}`,"GET",{fields_string:s});const o=await n.json();if(this.#t.generations_status)this.#s.generations_status?.set(e+s,o);return o}async getInterrogationStatus(e,t){const s=t?.fields?.length?t.fields.join(","):"";const r=!t?.force&&this.#s.interrogations_status?.get(e+s);if(r)return r;const{result:n}=await this.#e(`/interrogate/status/${e}`,"GET",{fields_string:s});const o=await n.json();if(this.#t.interrogations_status)this.#s.interrogations_status?.set(e+s,o);return o}async getHeartbeat(){await this.#e(`/status/heartbeat`,"GET");return true}async getModels(e){const t=e?.fields?.length?e.fields.join(","):"";const s=!e?.force&&this.#s.models?.get("CACHE-MODELS"+t);if(s)return s;const{result:r}=await this.#e(`/status/models`,"GET",{fields_string:t});const n=await r.json();if(this.#t.models)this.#s.models?.set("CACHE-MODELS"+t,n);return n}async getModel(e,t){const{result:s}=await this.#e(`/status/models/${e}`,"GET",{fields:t?.fields});const r=await s.json();return r}async getModes(e){const t=e?.fields?.length?e.fields.join(","):"";const s=this.#r(e?.token);const r=!e?.force&&this.#s.modes?.get("CACHE-MODES"+t);if(r)return r;const{result:n}=await this.#e(`/status/modes`,"GET",{token:s,fields_string:t});const o=await n.json();if(this.#t.modes)this.#s.modes?.set("CACHE-MODES"+t,o);return o}async getNews(e){const t=e?.fields?.length?e.fields.join(","):"";const s=!e?.force&&this.#s.news?.get("CACHE-NEWS"+t);if(s)return s;const{result:r}=await this.#e(`/status/news`,"GET",{fields_string:t});const n=await r.json();if(this.#t.news)this.#s.news?.set("CACHE-NEWS"+t,n);return n}async getPerformance(e){const t=e?.fields?.length?e.fields.join(","):"";const s=!e?.force&&this.#s.performance?.get("CACHE-PERFORMANCE"+t);if(s)return s;const{result:r}=await this.#e(`/status/performance`,"GET",{fields_string:t});const n=await r.json();if(this.#t.performance)this.#s.performance?.set("CACHE-PERFORMANCE"+t,n);return n}async getUsers(e){const{result:t,fields_string:s}=await this.#e(`/users`,"GET",{fields:e?.fields});const r=await t.json();if(this.#t.users)r.forEach(n=>{const o=n;if("id"in o)this.#s.users?.set(o.id+s,n)});return r}async getWorkers(e){const{result:t,fields_string:s}=await this.#e(`/workers`,"GET",{fields:e?.fields});const r=await t.json();if(this.#t.workers)r.forEach(n=>{const o=r;if("id"in o)this.#s.workers?.set(o.id+s,n)});return r}async getImageModelStats(e){const{result:t}=await this.#e("/stats/img/models","GET",{fields:e?.fields});const s=await t.json();return s}async getImageTotalStats(e){const{result:t}=await this.#e("/stats/img/totals","GET",{fields:e?.fields});const s=await t.json();return s}async getTextModelStats(e){const{result:t}=await this.#e("/stats/text/models","GET",{fields:e?.fields});const s=await t.json();return s}async getTextTotalStats(e){const{result:t}=await this.#e("/stats/text/totals","GET",{fields:e?.fields});const s=await t.json();return s}async getTeams(e){const{result:t,fields_string:s}=await this.#e(`/teams`,"GET",{fields:e?.fields});const r=await t.json();if(this.#t.teams)r.forEach(n=>{const o=n;if("id"in o)this.#s.teams?.set(o.id+s,n)});return r}async getFilters(e,t){const s=this.#r(t?.token);const r=new URLSearchParams;if(e?.filter_type)r.set("filter_type",e?.filter_type);if(e?.contains)r.set("contains",e?.contains);const{result:n}=await this.#e(`/filters${r.toString()?`?${r.toString()}`:""}`,"GET",{token:s,fields:t?.fields});const o=await n.json();return o}async getFilter(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/filters/${e}`,"GET",{token:s,fields:t?.fields});const n=await r.json();return n}async getSharedKey(e,t){const{result:s}=await this.#e(`/sharedkeys/${e}`,"GET",{fields:t?.fields});const r=await s.json();return r}async postFilters(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/filters`,"POST",{token:s,fields:t?.fields,body:e});return await r.json()}async postAsyncImageGenerate(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/generate/async`,"POST",{token:s,fields:t?.fields,body:e});return await r.json()}async postAsyncTextGenerate(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/generate/text/async`,"POST",{token:s,fields:t?.fields,body:e});return await r.json()}async postRating(e,t,s){const r=this.#r(s?.token);const{result:n}=await this.#e(`/generate/rate/${e}`,"POST",{token:r,fields:s?.fields,body:t});return await n.json()}async postImageGenerationPop(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/generate/pop`,"POST",{token:s,fields:t?.fields,body:e});return await r.json()}async postTextGenerationPop(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/generate/text/pop`,"POST",{token:s,fields:t?.fields,body:e});return await r.json()}async postImageGenerationSubmit(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/generate/submit`,"POST",{token:s,fields:t?.fields,body:e});return await r.json()}async postTextGenerationSubmit(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/generate/text/submit`,"POST",{token:s,fields:t?.fields,body:e});return await r.json()}async postAsyncInterrogate(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/interrogate/async`,"POST",{token:s,fields:t?.fields,body:e});return await r.json()}async postInterrogationPop(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/interrogate/pop`,"POST",{token:s,fields:t?.fields,body:e});return await r.json()}async postInterrogationSubmit(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/interrogate/submit`,"POST",{token:s,fields:t?.fields,body:e});return await r.json()}async postKudosTransfer(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/kudos/transfer`,"POST",{token:s,fields:t?.fields,body:e});return await r.json()}async postKoboldTransfer(e,t,s){const r=this.#r(s?.token);await this.#e(`/kudos/kai/${e}`,"POST",{token:r,body:t});return null}async createTeam(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/teams`,"POST",{token:s,fields:t?.fields,body:e});return await r.json()}async putStatusModes(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/status/modes`,"PUT",{token:s,fields:t?.fields,body:e});return await r.json()}async updateUser(e,t,s){const r=this.#r(s?.token);const{result:n,fields_string:o}=await this.#e(`/users/${t}`,"PUT",{token:r,fields:s?.fields,body:e});if(this.#t.users)this.#s.users?.delete(t.toString()+o);return await n.json()}async updateWorker(e,t,s){const r=this.#r(s?.token);const{result:n}=await this.#e(`/workers/${t}`,"PUT",{token:r,fields:s?.fields,body:e});if(this.#t.workers)this.#s.workers?.delete(t);return await n.json()}async addFilter(e,t,s){const r=this.#r(s?.token);const{result:n}=await this.#e(`/filters`,"PUT",{token:r,fields:s?.fields,body:e});return await n.json()}async putSharedKey(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/sharedkeys`,"PUT",{token:s,fields:t?.fields,body:e});return await r.json()}async updateTeam(e,t,s){const r=this.#r(s?.token);const{result:n}=await this.#e(`/teams/${t}`,"PATCH",{token:r,fields:s?.fields,body:e});if(this.#t.teams)this.#s.teams?.delete(t);return await n.json()}async updateFilter(e,t,s){const r=this.#r(s?.token);const{result:n}=await this.#e(`/filters/${t}`,"PATCH",{token:r,fields:s?.fields,body:e});return await n.json()}async updateSharedKey(e,t,s){const r=this.#r(s?.token);const{result:n}=await this.#e(`/sharedkeys/${t}`,"PATCH",{token:r,fields:s?.fields,body:e});return await n.json()}async deleteImageGenerationRequest(e,t){const{result:s,fields_string:r}=await this.#e(`/generate/status/${e}`,"DELETE",{fields:t?.fields});const n=await s.json();if(this.#t.generations_status)this.#s.generations_status?.set(e+r,n);return n}async deleteTextGenerationRequest(e,t){const{result:s,fields_string:r}=await this.#e(`/generate/text/status/${e}`,"DELETE",{fields:t?.fields});const n=await s.json();if(this.#t.generations_status)this.#s.generations_status?.set(e+r,n);return n}async deleteInterrogationRequest(e,t){const{result:s,fields_string:r}=await this.#e(`/interrogate/status/${e}`,"DELETE",{fields:t?.fields});const n=await s.json();if(this.#t.interrogations_status)this.#s.interrogations_status?.set(e+r,n);return n}async deleteWorker(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/workers/${e}`,"DELETE",{token:s,fields:t?.fields});const n=await r.json();this.#s.workers?.delete(e);return n}async deleteSharedKey(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/sharedkeys/${e}`,"DELETE",{token:s,fields:t?.fields});const n=await r.json();this.#s.sharedkeys?.delete(e);return n}async deleteTeam(e,t){const s=this.#r(t?.token);const{result:r,fields_string:n}=await this.#e(`/teams/${e}`,"DELETE",{token:s,fields:t?.fields});const o=await r.json();this.#s.teams?.delete(e+n);return o}async deleteIPTimeout(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/operations/ipaddr`,"DELETE",{token:s,fields:t?.fields,body:e});const n=await r.json();return n}async deleteFilter(e,t){const s=this.#r(t?.token);const{result:r}=await this.#e(`/filters/${e}`,"DELETE",{token:s,fields:t?.fields});const n=await r.json();return n}};u(h,"AIHorde");var V=Object.freeze({"FLAWLESS":"FLAWLESS","LITTLE_FLAWS":"LITTLE_FLAWS","SOME_FLAWS":"SOME_FLAWS","OBVIOUS_FLAWS":"OBVIOUS_FLAWS","HARMFUL_FLAWS":"HARMFUL_FLAWS","GARBAGE":"GARBAGE"});var g=class{#n;#t;#s;constructor(e){this.#n=e.default_token;this.#t=e.api_route??"https://ratings.aihorde.net/api/v1";this.#s=e.client_agent}#o(e){return e||this.#n||"0000000000"}async#i(e,t,s){const r=s?.fields?.join(",")||s?.fields_string||"";const n=this.#o(s?.token);const o={...s?.additional_headers,"Client-Agent":this.#s,"Content-Type":"application/json"};if(s?.token)o["apikey"]=n;if(r)o["X-Fields"]=r;const a=await fetch(`${this.#t}${e}`,{method:t,headers:o,body:s?.body?JSON.stringify(s.body):void 0});if(!a.status.toString().startsWith("2"))throw new m(await a.json(),a,t,s?.body);return{result:a,fields_string:r}}async getDatasets(e){const{result:t}=await this.#i(`/datasets`,"GET",{fields:e?.fields});const s=await t.json();return s}async getTeams(e){const{result:t}=await this.#i(`/teams`,"GET",{fields:e?.fields});const s=await t.json();return s}async getNewRating(e,t){const s=this.#o(t?.token);const{result:r}=await this.#i(`/rating/new${e?.dataset_id?`/${e.dataset_id}${e?.model_name?`/${e.model_name}`:""}`:""}`,"GET",{token:s,fields:t?.fields});const n=await r.json();return n}async postRating(e,t,s){const r=this.#o(s?.token);const{result:n}=await this.#i(`/rating/${e}`,"POST",{token:r,fields:s?.fields,body:t});return await n.json()}};u(g,"AIHordeRatings");0&&(module.exports={AIHorde,AIHordeRatings,APIError,ErrorMessages,GenerationMetadataStableTypes,GenerationMetadataStableValues,HordeAsyncRequestStates,ModelGenerationInputControlTypes,ModelGenerationInputPostProcessingTypes,ModelGenerationInputStableSamplers,ModelGenerationInputWorkflows,ModelInterrogationFormTypes,ModelPayloadTextInversionsStable,RatingArtifactsRatings,RequestSingleWarningCodes,SourceImageProcessingTypes});