@mintplex-labs/anything-llm-cli 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +81 -29
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -1,37 +1,89 @@
1
1
  #!/usr/bin/env node
2
- import{createRequire as W4}from"node:module";var R4=Object.create;var{getPrototypeOf:L4,defineProperty:p,getOwnPropertyNames:j4}=Object;var K4=Object.prototype.hasOwnProperty;var I4=(q,z,J)=>{J=q!=null?R4(L4(q)):{};let Q=z||!q||!q.__esModule?p(J,"default",{value:q,enumerable:!0}):J;for(let X of j4(q))if(!K4.call(Q,X))p(Q,X,{get:()=>q[X],enumerable:!0});return Q};var D=(q,z)=>()=>(z||q((z={exports:{}}).exports,z),z.exports);var y=W4(import.meta.url);var A=D((E4)=>{class f extends Error{constructor(q,z,J){super(J);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=z,this.exitCode=q,this.nestedError=void 0}}class s extends f{constructor(q){super(1,"commander.invalidArgument",q);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}E4.CommanderError=f;E4.InvalidArgumentError=s});var k=D((N4)=>{var{InvalidArgumentError:P4}=A();class n{constructor(q,z){switch(this.description=z||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,q[0]){case"<":this.required=!0,this._name=q.slice(1,-1);break;case"[":this.required=!1,this._name=q.slice(1,-1);break;default:this.required=!0,this._name=q;break}if(this._name.endsWith("..."))this.variadic=!0,this._name=this._name.slice(0,-3)}name(){return this._name}_collectValue(q,z){if(z===this.defaultValue||!Array.isArray(z))return[q];return z.push(q),z}default(q,z){return this.defaultValue=q,this.defaultValueDescription=z,this}argParser(q){return this.parseArg=q,this}choices(q){return this.argChoices=q.slice(),this.parseArg=(z,J)=>{if(!this.argChoices.includes(z))throw new P4(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._collectValue(z,J);return z},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}}function D4(q){let z=q.name()+(q.variadic===!0?"...":"");return q.required?"<"+z+">":"["+z+"]"}N4.Argument=n;N4.humanReadableArgName=D4});var v=D((w4)=>{var{humanReadableArgName:A4}=k();class r{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(q){this.helpWidth=this.helpWidth??q.helpWidth??80}visibleCommands(q){let z=q.commands.filter((Q)=>!Q._hidden),J=q._getHelpCommand();if(J&&!J._hidden)z.push(J);if(this.sortSubcommands)z.sort((Q,X)=>{return Q.name().localeCompare(X.name())});return z}compareOptions(q,z){let J=(Q)=>{return Q.short?Q.short.replace(/^-/,""):Q.long.replace(/^--/,"")};return J(q).localeCompare(J(z))}visibleOptions(q){let z=q.options.filter((Q)=>!Q.hidden),J=q._getHelpOption();if(J&&!J.hidden){let Q=J.short&&q._findOption(J.short),X=J.long&&q._findOption(J.long);if(!Q&&!X)z.push(J);else if(J.long&&!X)z.push(q.createOption(J.long,J.description));else if(J.short&&!Q)z.push(q.createOption(J.short,J.description))}if(this.sortOptions)z.sort(this.compareOptions);return z}visibleGlobalOptions(q){if(!this.showGlobalOptions)return[];let z=[];for(let J=q.parent;J;J=J.parent){let Q=J.options.filter((X)=>!X.hidden);z.push(...Q)}if(this.sortOptions)z.sort(this.compareOptions);return z}visibleArguments(q){if(q._argsDescription)q.registeredArguments.forEach((z)=>{z.description=z.description||q._argsDescription[z.name()]||""});if(q.registeredArguments.find((z)=>z.description))return q.registeredArguments;return[]}subcommandTerm(q){let z=q.registeredArguments.map((J)=>A4(J)).join(" ");return q._name+(q._aliases[0]?"|"+q._aliases[0]:"")+(q.options.length?" [options]":"")+(z?" "+z:"")}optionTerm(q){return q.flags}argumentTerm(q){return q.name()}longestSubcommandTermLength(q,z){return z.visibleCommands(q).reduce((J,Q)=>{return Math.max(J,this.displayWidth(z.styleSubcommandTerm(z.subcommandTerm(Q))))},0)}longestOptionTermLength(q,z){return z.visibleOptions(q).reduce((J,Q)=>{return Math.max(J,this.displayWidth(z.styleOptionTerm(z.optionTerm(Q))))},0)}longestGlobalOptionTermLength(q,z){return z.visibleGlobalOptions(q).reduce((J,Q)=>{return Math.max(J,this.displayWidth(z.styleOptionTerm(z.optionTerm(Q))))},0)}longestArgumentTermLength(q,z){return z.visibleArguments(q).reduce((J,Q)=>{return Math.max(J,this.displayWidth(z.styleArgumentTerm(z.argumentTerm(Q))))},0)}commandUsage(q){let z=q._name;if(q._aliases[0])z=z+"|"+q._aliases[0];let J="";for(let Q=q.parent;Q;Q=Q.parent)J=Q.name()+" "+J;return J+z+" "+q.usage()}commandDescription(q){return q.description()}subcommandDescription(q){return q.summary()||q.description()}optionDescription(q){let z=[];if(q.argChoices)z.push(`choices: ${q.argChoices.map((J)=>JSON.stringify(J)).join(", ")}`);if(q.defaultValue!==void 0){if(q.required||q.optional||q.isBoolean()&&typeof q.defaultValue==="boolean")z.push(`default: ${q.defaultValueDescription||JSON.stringify(q.defaultValue)}`)}if(q.presetArg!==void 0&&q.optional)z.push(`preset: ${JSON.stringify(q.presetArg)}`);if(q.envVar!==void 0)z.push(`env: ${q.envVar}`);if(z.length>0){let J=`(${z.join(", ")})`;if(q.description)return`${q.description} ${J}`;return J}return q.description}argumentDescription(q){let z=[];if(q.argChoices)z.push(`choices: ${q.argChoices.map((J)=>JSON.stringify(J)).join(", ")}`);if(q.defaultValue!==void 0)z.push(`default: ${q.defaultValueDescription||JSON.stringify(q.defaultValue)}`);if(z.length>0){let J=`(${z.join(", ")})`;if(q.description)return`${q.description} ${J}`;return J}return q.description}formatItemList(q,z,J){if(z.length===0)return[];return[J.styleTitle(q),...z,""]}groupItems(q,z,J){let Q=new Map;return q.forEach((X)=>{let Z=J(X);if(!Q.has(Z))Q.set(Z,[])}),z.forEach((X)=>{let Z=J(X);if(!Q.has(Z))Q.set(Z,[]);Q.get(Z).push(X)}),Q}formatHelp(q,z){let J=z.padWidth(q,z),Q=z.helpWidth??80;function X(B,H){return z.formatItem(B,J,H,z)}let Z=[`${z.styleTitle("Usage:")} ${z.styleUsage(z.commandUsage(q))}`,""],$=z.commandDescription(q);if($.length>0)Z=Z.concat([z.boxWrap(z.styleCommandDescription($),Q),""]);let _=z.visibleArguments(q).map((B)=>{return X(z.styleArgumentTerm(z.argumentTerm(B)),z.styleArgumentDescription(z.argumentDescription(B)))});if(Z=Z.concat(this.formatItemList("Arguments:",_,z)),this.groupItems(q.options,z.visibleOptions(q),(B)=>B.helpGroupHeading??"Options:").forEach((B,H)=>{let E=B.map((L)=>{return X(z.styleOptionTerm(z.optionTerm(L)),z.styleOptionDescription(z.optionDescription(L)))});Z=Z.concat(this.formatItemList(H,E,z))}),z.showGlobalOptions){let B=z.visibleGlobalOptions(q).map((H)=>{return X(z.styleOptionTerm(z.optionTerm(H)),z.styleOptionDescription(z.optionDescription(H)))});Z=Z.concat(this.formatItemList("Global Options:",B,z))}return this.groupItems(q.commands,z.visibleCommands(q),(B)=>B.helpGroup()||"Commands:").forEach((B,H)=>{let E=B.map((L)=>{return X(z.styleSubcommandTerm(z.subcommandTerm(L)),z.styleSubcommandDescription(z.subcommandDescription(L)))});Z=Z.concat(this.formatItemList(H,E,z))}),Z.join(`
3
- `)}displayWidth(q){return t(q).length}styleTitle(q){return q}styleUsage(q){return q.split(" ").map((z)=>{if(z==="[options]")return this.styleOptionText(z);if(z==="[command]")return this.styleSubcommandText(z);if(z[0]==="["||z[0]==="<")return this.styleArgumentText(z);return this.styleCommandText(z)}).join(" ")}styleCommandDescription(q){return this.styleDescriptionText(q)}styleOptionDescription(q){return this.styleDescriptionText(q)}styleSubcommandDescription(q){return this.styleDescriptionText(q)}styleArgumentDescription(q){return this.styleDescriptionText(q)}styleDescriptionText(q){return q}styleOptionTerm(q){return this.styleOptionText(q)}styleSubcommandTerm(q){return q.split(" ").map((z)=>{if(z==="[options]")return this.styleOptionText(z);if(z[0]==="["||z[0]==="<")return this.styleArgumentText(z);return this.styleSubcommandText(z)}).join(" ")}styleArgumentTerm(q){return this.styleArgumentText(q)}styleOptionText(q){return q}styleArgumentText(q){return q}styleSubcommandText(q){return q}styleCommandText(q){return q}padWidth(q,z){return Math.max(z.longestOptionTermLength(q,z),z.longestGlobalOptionTermLength(q,z),z.longestSubcommandTermLength(q,z),z.longestArgumentTermLength(q,z))}preformatted(q){return/\n[^\S\r\n]/.test(q)}formatItem(q,z,J,Q){let Z=" ".repeat(2);if(!J)return Z+q;let $=q.padEnd(z+q.length-Q.displayWidth(q)),_=2,Y=(this.helpWidth??80)-z-_-2,B;if(Y<this.minWidthToWrap||Q.preformatted(J))B=J;else B=Q.boxWrap(J,Y).replace(/\n/g,`
4
- `+" ".repeat(z+_));return Z+$+" ".repeat(_)+B.replace(/\n/g,`
5
- ${Z}`)}boxWrap(q,z){if(z<this.minWidthToWrap)return q;let J=q.split(/\r\n|\n/),Q=/[\s]*[^\s]+/g,X=[];return J.forEach((Z)=>{let $=Z.match(Q);if($===null){X.push("");return}let _=[$.shift()],G=this.displayWidth(_[0]);$.forEach((Y)=>{let B=this.displayWidth(Y);if(G+B<=z){_.push(Y),G+=B;return}X.push(_.join(""));let H=Y.trimStart();_=[H],G=this.displayWidth(H)}),X.push(_.join(""))}),X.join(`
6
- `)}}function t(q){let z=/\x1b\[\d*(;\d*)*m/g;return q.replace(z,"")}w4.Help=r;w4.stripColor=t});var h=D((b4)=>{var{InvalidArgumentError:x4}=A();class o{constructor(q,z){this.flags=q,this.description=z||"",this.required=q.includes("<"),this.optional=q.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(q),this.mandatory=!1;let J=O4(q);if(this.short=J.shortFlag,this.long=J.longFlag,this.negate=!1,this.long)this.negate=this.long.startsWith("--no-");this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0,this.helpGroupHeading=void 0}default(q,z){return this.defaultValue=q,this.defaultValueDescription=z,this}preset(q){return this.presetArg=q,this}conflicts(q){return this.conflictsWith=this.conflictsWith.concat(q),this}implies(q){let z=q;if(typeof q==="string")z={[q]:!0};return this.implied=Object.assign(this.implied||{},z),this}env(q){return this.envVar=q,this}argParser(q){return this.parseArg=q,this}makeOptionMandatory(q=!0){return this.mandatory=!!q,this}hideHelp(q=!0){return this.hidden=!!q,this}_collectValue(q,z){if(z===this.defaultValue||!Array.isArray(z))return[q];return z.push(q),z}choices(q){return this.argChoices=q.slice(),this.parseArg=(z,J)=>{if(!this.argChoices.includes(z))throw new x4(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._collectValue(z,J);return z},this}name(){if(this.long)return this.long.replace(/^--/,"");return this.short.replace(/^-/,"")}attributeName(){if(this.negate)return a(this.name().replace(/^no-/,""));return a(this.name())}helpGroup(q){return this.helpGroupHeading=q,this}is(q){return this.short===q||this.long===q}isBoolean(){return!this.required&&!this.optional&&!this.negate}}class e{constructor(q){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,q.forEach((z)=>{if(z.negate)this.negativeOptions.set(z.attributeName(),z);else this.positiveOptions.set(z.attributeName(),z)}),this.negativeOptions.forEach((z,J)=>{if(this.positiveOptions.has(J))this.dualOptions.add(J)})}valueFromOption(q,z){let J=z.attributeName();if(!this.dualOptions.has(J))return!0;let Q=this.negativeOptions.get(J).presetArg,X=Q!==void 0?Q:!1;return z.negate===(X===q)}}function a(q){return q.split("-").reduce((z,J)=>{return z+J[0].toUpperCase()+J.slice(1)})}function O4(q){let z,J,Q=/^-[^-]$/,X=/^--[^-]/,Z=q.split(/[ |,]+/).concat("guard");if(Q.test(Z[0]))z=Z.shift();if(X.test(Z[0]))J=Z.shift();if(!z&&Q.test(Z[0]))z=Z.shift();if(!z&&X.test(Z[0]))z=J,J=Z.shift();if(Z[0].startsWith("-")){let $=Z[0],_=`option creation failed due to '${$}' in option flags '${q}'`;if(/^-[^-][^-]/.test($))throw Error(`${_}
2
+ import{createRequire as m4}from"node:module";var h4=Object.create;var{getPrototypeOf:u4,defineProperty:f1,getOwnPropertyNames:g4}=Object;var c4=Object.prototype.hasOwnProperty;var c=(z,q,B)=>{B=z!=null?h4(u4(z)):{};let J=q||!z||!z.__esModule?f1(B,"default",{value:z,enumerable:!0}):B;for(let Y of g4(z))if(!c4.call(J,Y))f1(J,Y,{get:()=>z[Y],enumerable:!0});return J};var v=(z,q)=>()=>(q||z((q={exports:{}}).exports,q),q.exports);var m=m4(import.meta.url);var l=v((l4)=>{class H1 extends Error{constructor(z,q,B){super(B);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=q,this.exitCode=z,this.nestedError=void 0}}class v1 extends H1{constructor(z){super(1,"commander.invalidArgument",z);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}l4.CommanderError=H1;l4.InvalidArgumentError=v1});var n=v((r4)=>{var{InvalidArgumentError:i4}=l();class h1{constructor(z,q){switch(this.description=q||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,z[0]){case"<":this.required=!0,this._name=z.slice(1,-1);break;case"[":this.required=!1,this._name=z.slice(1,-1);break;default:this.required=!0,this._name=z;break}if(this._name.endsWith("..."))this.variadic=!0,this._name=this._name.slice(0,-3)}name(){return this._name}_collectValue(z,q){if(q===this.defaultValue||!Array.isArray(q))return[z];return q.push(z),q}default(z,q){return this.defaultValue=z,this.defaultValueDescription=q,this}argParser(z){return this.parseArg=z,this}choices(z){return this.argChoices=z.slice(),this.parseArg=(q,B)=>{if(!this.argChoices.includes(q))throw new i4(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._collectValue(q,B);return q},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}}function n4(z){let q=z.name()+(z.variadic===!0?"...":"");return z.required?"<"+q+">":"["+q+"]"}r4.Argument=h1;r4.humanReadableArgName=n4});var T1=v((e4)=>{var{humanReadableArgName:a4}=n();class u1{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(z){this.helpWidth=this.helpWidth??z.helpWidth??80}visibleCommands(z){let q=z.commands.filter((J)=>!J._hidden),B=z._getHelpCommand();if(B&&!B._hidden)q.push(B);if(this.sortSubcommands)q.sort((J,Y)=>{return J.name().localeCompare(Y.name())});return q}compareOptions(z,q){let B=(J)=>{return J.short?J.short.replace(/^-/,""):J.long.replace(/^--/,"")};return B(z).localeCompare(B(q))}visibleOptions(z){let q=z.options.filter((J)=>!J.hidden),B=z._getHelpOption();if(B&&!B.hidden){let J=B.short&&z._findOption(B.short),Y=B.long&&z._findOption(B.long);if(!J&&!Y)q.push(B);else if(B.long&&!Y)q.push(z.createOption(B.long,B.description));else if(B.short&&!J)q.push(z.createOption(B.short,B.description))}if(this.sortOptions)q.sort(this.compareOptions);return q}visibleGlobalOptions(z){if(!this.showGlobalOptions)return[];let q=[];for(let B=z.parent;B;B=B.parent){let J=B.options.filter((Y)=>!Y.hidden);q.push(...J)}if(this.sortOptions)q.sort(this.compareOptions);return q}visibleArguments(z){if(z._argsDescription)z.registeredArguments.forEach((q)=>{q.description=q.description||z._argsDescription[q.name()]||""});if(z.registeredArguments.find((q)=>q.description))return z.registeredArguments;return[]}subcommandTerm(z){let q=z.registeredArguments.map((B)=>a4(B)).join(" ");return z._name+(z._aliases[0]?"|"+z._aliases[0]:"")+(z.options.length?" [options]":"")+(q?" "+q:"")}optionTerm(z){return z.flags}argumentTerm(z){return z.name()}longestSubcommandTermLength(z,q){return q.visibleCommands(z).reduce((B,J)=>{return Math.max(B,this.displayWidth(q.styleSubcommandTerm(q.subcommandTerm(J))))},0)}longestOptionTermLength(z,q){return q.visibleOptions(z).reduce((B,J)=>{return Math.max(B,this.displayWidth(q.styleOptionTerm(q.optionTerm(J))))},0)}longestGlobalOptionTermLength(z,q){return q.visibleGlobalOptions(z).reduce((B,J)=>{return Math.max(B,this.displayWidth(q.styleOptionTerm(q.optionTerm(J))))},0)}longestArgumentTermLength(z,q){return q.visibleArguments(z).reduce((B,J)=>{return Math.max(B,this.displayWidth(q.styleArgumentTerm(q.argumentTerm(J))))},0)}commandUsage(z){let q=z._name;if(z._aliases[0])q=q+"|"+z._aliases[0];let B="";for(let J=z.parent;J;J=J.parent)B=J.name()+" "+B;return B+q+" "+z.usage()}commandDescription(z){return z.description()}subcommandDescription(z){return z.summary()||z.description()}optionDescription(z){let q=[];if(z.argChoices)q.push(`choices: ${z.argChoices.map((B)=>JSON.stringify(B)).join(", ")}`);if(z.defaultValue!==void 0){if(z.required||z.optional||z.isBoolean()&&typeof z.defaultValue==="boolean")q.push(`default: ${z.defaultValueDescription||JSON.stringify(z.defaultValue)}`)}if(z.presetArg!==void 0&&z.optional)q.push(`preset: ${JSON.stringify(z.presetArg)}`);if(z.envVar!==void 0)q.push(`env: ${z.envVar}`);if(q.length>0){let B=`(${q.join(", ")})`;if(z.description)return`${z.description} ${B}`;return B}return z.description}argumentDescription(z){let q=[];if(z.argChoices)q.push(`choices: ${z.argChoices.map((B)=>JSON.stringify(B)).join(", ")}`);if(z.defaultValue!==void 0)q.push(`default: ${z.defaultValueDescription||JSON.stringify(z.defaultValue)}`);if(q.length>0){let B=`(${q.join(", ")})`;if(z.description)return`${z.description} ${B}`;return B}return z.description}formatItemList(z,q,B){if(q.length===0)return[];return[B.styleTitle(z),...q,""]}groupItems(z,q,B){let J=new Map;return z.forEach((Y)=>{let Z=B(Y);if(!J.has(Z))J.set(Z,[])}),q.forEach((Y)=>{let Z=B(Y);if(!J.has(Z))J.set(Z,[]);J.get(Z).push(Y)}),J}formatHelp(z,q){let B=q.padWidth(z,q),J=q.helpWidth??80;function Y(H,T){return q.formatItem(H,B,T,q)}let Z=[`${q.styleTitle("Usage:")} ${q.styleUsage(q.commandUsage(z))}`,""],Q=q.commandDescription(z);if(Q.length>0)Z=Z.concat([q.boxWrap(q.styleCommandDescription(Q),J),""]);let X=q.visibleArguments(z).map((H)=>{return Y(q.styleArgumentTerm(q.argumentTerm(H)),q.styleArgumentDescription(q.argumentDescription(H)))});if(Z=Z.concat(this.formatItemList("Arguments:",X,q)),this.groupItems(z.options,q.visibleOptions(z),(H)=>H.helpGroupHeading??"Options:").forEach((H,T)=>{let j=H.map((N)=>{return Y(q.styleOptionTerm(q.optionTerm(N)),q.styleOptionDescription(q.optionDescription(N)))});Z=Z.concat(this.formatItemList(T,j,q))}),q.showGlobalOptions){let H=q.visibleGlobalOptions(z).map((T)=>{return Y(q.styleOptionTerm(q.optionTerm(T)),q.styleOptionDescription(q.optionDescription(T)))});Z=Z.concat(this.formatItemList("Global Options:",H,q))}return this.groupItems(z.commands,q.visibleCommands(z),(H)=>H.helpGroup()||"Commands:").forEach((H,T)=>{let j=H.map((N)=>{return Y(q.styleSubcommandTerm(q.subcommandTerm(N)),q.styleSubcommandDescription(q.subcommandDescription(N)))});Z=Z.concat(this.formatItemList(T,j,q))}),Z.join(`
3
+ `)}displayWidth(z){return g1(z).length}styleTitle(z){return z}styleUsage(z){return z.split(" ").map((q)=>{if(q==="[options]")return this.styleOptionText(q);if(q==="[command]")return this.styleSubcommandText(q);if(q[0]==="["||q[0]==="<")return this.styleArgumentText(q);return this.styleCommandText(q)}).join(" ")}styleCommandDescription(z){return this.styleDescriptionText(z)}styleOptionDescription(z){return this.styleDescriptionText(z)}styleSubcommandDescription(z){return this.styleDescriptionText(z)}styleArgumentDescription(z){return this.styleDescriptionText(z)}styleDescriptionText(z){return z}styleOptionTerm(z){return this.styleOptionText(z)}styleSubcommandTerm(z){return z.split(" ").map((q)=>{if(q==="[options]")return this.styleOptionText(q);if(q[0]==="["||q[0]==="<")return this.styleArgumentText(q);return this.styleSubcommandText(q)}).join(" ")}styleArgumentTerm(z){return this.styleArgumentText(z)}styleOptionText(z){return z}styleArgumentText(z){return z}styleSubcommandText(z){return z}styleCommandText(z){return z}padWidth(z,q){return Math.max(q.longestOptionTermLength(z,q),q.longestGlobalOptionTermLength(z,q),q.longestSubcommandTermLength(z,q),q.longestArgumentTermLength(z,q))}preformatted(z){return/\n[^\S\r\n]/.test(z)}formatItem(z,q,B,J){let Z=" ".repeat(2);if(!B)return Z+z;let Q=z.padEnd(q+z.length-J.displayWidth(z)),X=2,G=(this.helpWidth??80)-q-X-2,H;if(G<this.minWidthToWrap||J.preformatted(B))H=B;else H=J.boxWrap(B,G).replace(/\n/g,`
4
+ `+" ".repeat(q+X));return Z+Q+" ".repeat(X)+H.replace(/\n/g,`
5
+ ${Z}`)}boxWrap(z,q){if(q<this.minWidthToWrap)return z;let B=z.split(/\r\n|\n/),J=/[\s]*[^\s]+/g,Y=[];return B.forEach((Z)=>{let Q=Z.match(J);if(Q===null){Y.push("");return}let X=[Q.shift()],L=this.displayWidth(X[0]);Q.forEach((G)=>{let H=this.displayWidth(G);if(L+H<=q){X.push(G),L+=H;return}Y.push(X.join(""));let T=G.trimStart();X=[T],L=this.displayWidth(T)}),Y.push(X.join(""))}),Y.join(`
6
+ `)}}function g1(z){let q=/\x1b\[\d*(;\d*)*m/g;return z.replace(q,"")}e4.Help=u1;e4.stripColor=g1});var S1=v((J9)=>{var{InvalidArgumentError:q9}=l();class m1{constructor(z,q){this.flags=z,this.description=q||"",this.required=z.includes("<"),this.optional=z.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(z),this.mandatory=!1;let B=B9(z);if(this.short=B.shortFlag,this.long=B.longFlag,this.negate=!1,this.long)this.negate=this.long.startsWith("--no-");this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0,this.helpGroupHeading=void 0}default(z,q){return this.defaultValue=z,this.defaultValueDescription=q,this}preset(z){return this.presetArg=z,this}conflicts(z){return this.conflictsWith=this.conflictsWith.concat(z),this}implies(z){let q=z;if(typeof z==="string")q={[z]:!0};return this.implied=Object.assign(this.implied||{},q),this}env(z){return this.envVar=z,this}argParser(z){return this.parseArg=z,this}makeOptionMandatory(z=!0){return this.mandatory=!!z,this}hideHelp(z=!0){return this.hidden=!!z,this}_collectValue(z,q){if(q===this.defaultValue||!Array.isArray(q))return[z];return q.push(z),q}choices(z){return this.argChoices=z.slice(),this.parseArg=(q,B)=>{if(!this.argChoices.includes(q))throw new q9(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._collectValue(q,B);return q},this}name(){if(this.long)return this.long.replace(/^--/,"");return this.short.replace(/^-/,"")}attributeName(){if(this.negate)return c1(this.name().replace(/^no-/,""));return c1(this.name())}helpGroup(z){return this.helpGroupHeading=z,this}is(z){return this.short===z||this.long===z}isBoolean(){return!this.required&&!this.optional&&!this.negate}}class l1{constructor(z){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,z.forEach((q)=>{if(q.negate)this.negativeOptions.set(q.attributeName(),q);else this.positiveOptions.set(q.attributeName(),q)}),this.negativeOptions.forEach((q,B)=>{if(this.positiveOptions.has(B))this.dualOptions.add(B)})}valueFromOption(z,q){let B=q.attributeName();if(!this.dualOptions.has(B))return!0;let J=this.negativeOptions.get(B).presetArg,Y=J!==void 0?J:!1;return q.negate===(Y===z)}}function c1(z){return z.split("-").reduce((q,B)=>{return q+B[0].toUpperCase()+B.slice(1)})}function B9(z){let q,B,J=/^-[^-]$/,Y=/^--[^-]/,Z=z.split(/[ |,]+/).concat("guard");if(J.test(Z[0]))q=Z.shift();if(Y.test(Z[0]))B=Z.shift();if(!q&&J.test(Z[0]))q=Z.shift();if(!q&&Y.test(Z[0]))q=B,B=Z.shift();if(Z[0].startsWith("-")){let Q=Z[0],X=`option creation failed due to '${Q}' in option flags '${z}'`;if(/^-[^-][^-]/.test(Q))throw Error(`${X}
7
7
  - a short flag is a single dash and a single character
8
8
  - either use a single dash and a single character (for a short flag)
9
- - or use a double dash for a long option (and can have two, like '--ws, --workspace')`);if(Q.test($))throw Error(`${_}
10
- - too many short flags`);if(X.test($))throw Error(`${_}
11
- - too many long flags`);throw Error(`${_}
12
- - unrecognised flag format`)}if(z===void 0&&J===void 0)throw Error(`option creation failed due to no flags found in '${q}'.`);return{shortFlag:z,longFlag:J}}b4.Option=o;b4.DualOptions=e});var q4=D((g4)=>{function h4(q,z){if(Math.abs(q.length-z.length)>3)return Math.max(q.length,z.length);let J=[];for(let Q=0;Q<=q.length;Q++)J[Q]=[Q];for(let Q=0;Q<=z.length;Q++)J[0][Q]=Q;for(let Q=1;Q<=z.length;Q++)for(let X=1;X<=q.length;X++){let Z=1;if(q[X-1]===z[Q-1])Z=0;else Z=1;if(J[X][Q]=Math.min(J[X-1][Q]+1,J[X][Q-1]+1,J[X-1][Q-1]+Z),X>1&&Q>1&&q[X-1]===z[Q-2]&&q[X-2]===z[Q-1])J[X][Q]=Math.min(J[X][Q],J[X-2][Q-2]+1)}return J[q.length][z.length]}function u4(q,z){if(!z||z.length===0)return"";z=Array.from(new Set(z));let J=q.startsWith("--");if(J)q=q.slice(2),z=z.map(($)=>$.slice(2));let Q=[],X=3,Z=0.4;if(z.forEach(($)=>{if($.length<=1)return;let _=h4(q,$),G=Math.max(q.length,$.length);if((G-_)/G>Z){if(_<X)X=_,Q=[$];else if(_===X)Q.push($)}}),Q.sort(($,_)=>$.localeCompare(_)),J)Q=Q.map(($)=>`--${$}`);if(Q.length>1)return`
13
- (Did you mean one of ${Q.join(", ")}?)`;if(Q.length===1)return`
14
- (Did you mean ${Q[0]}?)`;return""}g4.suggestSimilar=u4});var X4=D((n4)=>{var d4=y("node:events").EventEmitter,u=y("node:child_process"),P=y("node:path"),x=y("node:fs"),T=y("node:process"),{Argument:l4,humanReadableArgName:m4}=k(),{CommanderError:g}=A(),{Help:i4,stripColor:p4}=v(),{Option:z4,DualOptions:s4}=h(),{suggestSimilar:J4}=q4();class d extends d4{constructor(q){super();this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=q||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:(z)=>T.stdout.write(z),writeErr:(z)=>T.stderr.write(z),outputError:(z,J)=>J(z),getOutHelpWidth:()=>T.stdout.isTTY?T.stdout.columns:void 0,getErrHelpWidth:()=>T.stderr.isTTY?T.stderr.columns:void 0,getOutHasColors:()=>c()??(T.stdout.isTTY&&T.stdout.hasColors?.()),getErrHasColors:()=>c()??(T.stderr.isTTY&&T.stderr.hasColors?.()),stripColor:(z)=>p4(z)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0}copyInheritedSettings(q){return this._outputConfiguration=q._outputConfiguration,this._helpOption=q._helpOption,this._helpCommand=q._helpCommand,this._helpConfiguration=q._helpConfiguration,this._exitCallback=q._exitCallback,this._storeOptionsAsProperties=q._storeOptionsAsProperties,this._combineFlagAndOptionalValue=q._combineFlagAndOptionalValue,this._allowExcessArguments=q._allowExcessArguments,this._enablePositionalOptions=q._enablePositionalOptions,this._showHelpAfterError=q._showHelpAfterError,this._showSuggestionAfterError=q._showSuggestionAfterError,this}_getCommandAndAncestors(){let q=[];for(let z=this;z;z=z.parent)q.push(z);return q}command(q,z,J){let Q=z,X=J;if(typeof Q==="object"&&Q!==null)X=Q,Q=null;X=X||{};let[,Z,$]=q.match(/([^ ]+) *(.*)/),_=this.createCommand(Z);if(Q)_.description(Q),_._executableHandler=!0;if(X.isDefault)this._defaultCommandName=_._name;if(_._hidden=!!(X.noHelp||X.hidden),_._executableFile=X.executableFile||null,$)_.arguments($);if(this._registerCommand(_),_.parent=this,_.copyInheritedSettings(this),Q)return this;return _}createCommand(q){return new d(q)}createHelp(){return Object.assign(new i4,this.configureHelp())}configureHelp(q){if(q===void 0)return this._helpConfiguration;return this._helpConfiguration=q,this}configureOutput(q){if(q===void 0)return this._outputConfiguration;return this._outputConfiguration={...this._outputConfiguration,...q},this}showHelpAfterError(q=!0){if(typeof q!=="string")q=!!q;return this._showHelpAfterError=q,this}showSuggestionAfterError(q=!0){return this._showSuggestionAfterError=!!q,this}addCommand(q,z){if(!q._name)throw Error(`Command passed to .addCommand() must have a name
15
- - specify the name in Command constructor or using .name()`);if(z=z||{},z.isDefault)this._defaultCommandName=q._name;if(z.noHelp||z.hidden)q._hidden=!0;return this._registerCommand(q),q.parent=this,q._checkForBrokenPassThrough(),this}createArgument(q,z){return new l4(q,z)}argument(q,z,J,Q){let X=this.createArgument(q,z);if(typeof J==="function")X.default(Q).argParser(J);else X.default(J);return this.addArgument(X),this}arguments(q){return q.trim().split(/ +/).forEach((z)=>{this.argument(z)}),this}addArgument(q){let z=this.registeredArguments.slice(-1)[0];if(z?.variadic)throw Error(`only the last argument can be variadic '${z.name()}'`);if(q.required&&q.defaultValue!==void 0&&q.parseArg===void 0)throw Error(`a default value for a required argument is never used: '${q.name()}'`);return this.registeredArguments.push(q),this}helpCommand(q,z){if(typeof q==="boolean"){if(this._addImplicitHelpCommand=q,q&&this._defaultCommandGroup)this._initCommandGroup(this._getHelpCommand());return this}let J=q??"help [command]",[,Q,X]=J.match(/([^ ]+) *(.*)/),Z=z??"display help for command",$=this.createCommand(Q);if($.helpOption(!1),X)$.arguments(X);if(Z)$.description(Z);if(this._addImplicitHelpCommand=!0,this._helpCommand=$,q||z)this._initCommandGroup($);return this}addHelpCommand(q,z){if(typeof q!=="object")return this.helpCommand(q,z),this;return this._addImplicitHelpCommand=!0,this._helpCommand=q,this._initCommandGroup(q),this}_getHelpCommand(){if(this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))){if(this._helpCommand===void 0)this.helpCommand(void 0,void 0);return this._helpCommand}return null}hook(q,z){let J=["preSubcommand","preAction","postAction"];if(!J.includes(q))throw Error(`Unexpected value for event passed to hook : '${q}'.
16
- Expecting one of '${J.join("', '")}'`);if(this._lifeCycleHooks[q])this._lifeCycleHooks[q].push(z);else this._lifeCycleHooks[q]=[z];return this}exitOverride(q){if(q)this._exitCallback=q;else this._exitCallback=(z)=>{if(z.code!=="commander.executeSubCommandAsync")throw z};return this}_exit(q,z,J){if(this._exitCallback)this._exitCallback(new g(q,z,J));T.exit(q)}action(q){let z=(J)=>{let Q=this.registeredArguments.length,X=J.slice(0,Q);if(this._storeOptionsAsProperties)X[Q]=this;else X[Q]=this.opts();return X.push(this),q.apply(this,X)};return this._actionHandler=z,this}createOption(q,z){return new z4(q,z)}_callParseArg(q,z,J,Q){try{return q.parseArg(z,J)}catch(X){if(X.code==="commander.invalidArgument"){let Z=`${Q} ${X.message}`;this.error(Z,{exitCode:X.exitCode,code:X.code})}throw X}}_registerOption(q){let z=q.short&&this._findOption(q.short)||q.long&&this._findOption(q.long);if(z){let J=q.long&&this._findOption(q.long)?q.long:q.short;throw Error(`Cannot add option '${q.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${J}'
17
- - already used by option '${z.flags}'`)}this._initOptionGroup(q),this.options.push(q)}_registerCommand(q){let z=(Q)=>{return[Q.name()].concat(Q.aliases())},J=z(q).find((Q)=>this._findCommand(Q));if(J){let Q=z(this._findCommand(J)).join("|"),X=z(q).join("|");throw Error(`cannot add command '${X}' as already have command '${Q}'`)}this._initCommandGroup(q),this.commands.push(q)}addOption(q){this._registerOption(q);let z=q.name(),J=q.attributeName();if(q.negate){let X=q.long.replace(/^--no-/,"--");if(!this._findOption(X))this.setOptionValueWithSource(J,q.defaultValue===void 0?!0:q.defaultValue,"default")}else if(q.defaultValue!==void 0)this.setOptionValueWithSource(J,q.defaultValue,"default");let Q=(X,Z,$)=>{if(X==null&&q.presetArg!==void 0)X=q.presetArg;let _=this.getOptionValue(J);if(X!==null&&q.parseArg)X=this._callParseArg(q,X,_,Z);else if(X!==null&&q.variadic)X=q._collectValue(X,_);if(X==null)if(q.negate)X=!1;else if(q.isBoolean()||q.optional)X=!0;else X="";this.setOptionValueWithSource(J,X,$)};if(this.on("option:"+z,(X)=>{let Z=`error: option '${q.flags}' argument '${X}' is invalid.`;Q(X,Z,"cli")}),q.envVar)this.on("optionEnv:"+z,(X)=>{let Z=`error: option '${q.flags}' value '${X}' from env '${q.envVar}' is invalid.`;Q(X,Z,"env")});return this}_optionEx(q,z,J,Q,X){if(typeof z==="object"&&z instanceof z4)throw Error("To add an Option object use addOption() instead of option() or requiredOption()");let Z=this.createOption(z,J);if(Z.makeOptionMandatory(!!q.mandatory),typeof Q==="function")Z.default(X).argParser(Q);else if(Q instanceof RegExp){let $=Q;Q=(_,G)=>{let Y=$.exec(_);return Y?Y[0]:G},Z.default(X).argParser(Q)}else Z.default(Q);return this.addOption(Z)}option(q,z,J,Q){return this._optionEx({},q,z,J,Q)}requiredOption(q,z,J,Q){return this._optionEx({mandatory:!0},q,z,J,Q)}combineFlagAndOptionalValue(q=!0){return this._combineFlagAndOptionalValue=!!q,this}allowUnknownOption(q=!0){return this._allowUnknownOption=!!q,this}allowExcessArguments(q=!0){return this._allowExcessArguments=!!q,this}enablePositionalOptions(q=!0){return this._enablePositionalOptions=!!q,this}passThroughOptions(q=!0){return this._passThroughOptions=!!q,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(q=!0){if(this.options.length)throw Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!q,this}getOptionValue(q){if(this._storeOptionsAsProperties)return this[q];return this._optionValues[q]}setOptionValue(q,z){return this.setOptionValueWithSource(q,z,void 0)}setOptionValueWithSource(q,z,J){if(this._storeOptionsAsProperties)this[q]=z;else this._optionValues[q]=z;return this._optionValueSources[q]=J,this}getOptionValueSource(q){return this._optionValueSources[q]}getOptionValueSourceWithGlobals(q){let z;return this._getCommandAndAncestors().forEach((J)=>{if(J.getOptionValueSource(q)!==void 0)z=J.getOptionValueSource(q)}),z}_prepareUserArgs(q,z){if(q!==void 0&&!Array.isArray(q))throw Error("first parameter to parse must be array or undefined");if(z=z||{},q===void 0&&z.from===void 0){if(T.versions?.electron)z.from="electron";let Q=T.execArgv??[];if(Q.includes("-e")||Q.includes("--eval")||Q.includes("-p")||Q.includes("--print"))z.from="eval"}if(q===void 0)q=T.argv;this.rawArgs=q.slice();let J;switch(z.from){case void 0:case"node":this._scriptPath=q[1],J=q.slice(2);break;case"electron":if(T.defaultApp)this._scriptPath=q[1],J=q.slice(2);else J=q.slice(1);break;case"user":J=q.slice(0);break;case"eval":J=q.slice(1);break;default:throw Error(`unexpected parse option { from: '${z.from}' }`)}if(!this._name&&this._scriptPath)this.nameFromFilename(this._scriptPath);return this._name=this._name||"program",J}parse(q,z){this._prepareForParse();let J=this._prepareUserArgs(q,z);return this._parseCommand([],J),this}async parseAsync(q,z){this._prepareForParse();let J=this._prepareUserArgs(q,z);return await this._parseCommand([],J),this}_prepareForParse(){if(this._savedState===null)this.saveStateBeforeParse();else this.restoreStateBeforeParse()}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw Error(`Can not call parse again when storeOptionsAsProperties is true.
18
- - either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[]}_checkForMissingExecutable(q,z,J){if(x.existsSync(q))return;let Q=z?`searched for local subcommand relative to directory '${z}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",X=`'${q}' does not exist
19
- - if '${J}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
9
+ - or use a double dash for a long option (and can have two, like '--ws, --workspace')`);if(J.test(Q))throw Error(`${X}
10
+ - too many short flags`);if(Y.test(Q))throw Error(`${X}
11
+ - too many long flags`);throw Error(`${X}
12
+ - unrecognised flag format`)}if(q===void 0&&B===void 0)throw Error(`option creation failed due to no flags found in '${z}'.`);return{shortFlag:q,longFlag:B}}J9.Option=m1;J9.DualOptions=l1});var d1=v((L9)=>{function Q9(z,q){if(Math.abs(z.length-q.length)>3)return Math.max(z.length,q.length);let B=[];for(let J=0;J<=z.length;J++)B[J]=[J];for(let J=0;J<=q.length;J++)B[0][J]=J;for(let J=1;J<=q.length;J++)for(let Y=1;Y<=z.length;Y++){let Z=1;if(z[Y-1]===q[J-1])Z=0;else Z=1;if(B[Y][J]=Math.min(B[Y-1][J]+1,B[Y][J-1]+1,B[Y-1][J-1]+Z),Y>1&&J>1&&z[Y-1]===q[J-2]&&z[Y-2]===q[J-1])B[Y][J]=Math.min(B[Y][J],B[Y-2][J-2]+1)}return B[z.length][q.length]}function X9(z,q){if(!q||q.length===0)return"";q=Array.from(new Set(q));let B=z.startsWith("--");if(B)z=z.slice(2),q=q.map((Q)=>Q.slice(2));let J=[],Y=3,Z=0.4;if(q.forEach((Q)=>{if(Q.length<=1)return;let X=Q9(z,Q),L=Math.max(z.length,Q.length);if((L-X)/L>Z){if(X<Y)Y=X,J=[Q];else if(X===Y)J.push(Q)}}),J.sort((Q,X)=>Q.localeCompare(X)),B)J=J.map((Q)=>`--${Q}`);if(J.length>1)return`
13
+ (Did you mean one of ${J.join(", ")}?)`;if(J.length===1)return`
14
+ (Did you mean ${J[0]}?)`;return""}L9.suggestSimilar=X9});var r1=v(($9)=>{var H9=m("node:events").EventEmitter,U1=m("node:child_process"),h=m("node:path"),r=m("node:fs"),D=m("node:process"),{Argument:T9,humanReadableArgName:S9}=n(),{CommanderError:_1}=l(),{Help:U9,stripColor:_9}=T1(),{Option:p1,DualOptions:R9}=S1(),{suggestSimilar:i1}=d1();class $1 extends H9{constructor(z){super();this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=z||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:(q)=>D.stdout.write(q),writeErr:(q)=>D.stderr.write(q),outputError:(q,B)=>B(q),getOutHelpWidth:()=>D.stdout.isTTY?D.stdout.columns:void 0,getErrHelpWidth:()=>D.stderr.isTTY?D.stderr.columns:void 0,getOutHasColors:()=>R1()??(D.stdout.isTTY&&D.stdout.hasColors?.()),getErrHasColors:()=>R1()??(D.stderr.isTTY&&D.stderr.hasColors?.()),stripColor:(q)=>_9(q)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0}copyInheritedSettings(z){return this._outputConfiguration=z._outputConfiguration,this._helpOption=z._helpOption,this._helpCommand=z._helpCommand,this._helpConfiguration=z._helpConfiguration,this._exitCallback=z._exitCallback,this._storeOptionsAsProperties=z._storeOptionsAsProperties,this._combineFlagAndOptionalValue=z._combineFlagAndOptionalValue,this._allowExcessArguments=z._allowExcessArguments,this._enablePositionalOptions=z._enablePositionalOptions,this._showHelpAfterError=z._showHelpAfterError,this._showSuggestionAfterError=z._showSuggestionAfterError,this}_getCommandAndAncestors(){let z=[];for(let q=this;q;q=q.parent)z.push(q);return z}command(z,q,B){let J=q,Y=B;if(typeof J==="object"&&J!==null)Y=J,J=null;Y=Y||{};let[,Z,Q]=z.match(/([^ ]+) *(.*)/),X=this.createCommand(Z);if(J)X.description(J),X._executableHandler=!0;if(Y.isDefault)this._defaultCommandName=X._name;if(X._hidden=!!(Y.noHelp||Y.hidden),X._executableFile=Y.executableFile||null,Q)X.arguments(Q);if(this._registerCommand(X),X.parent=this,X.copyInheritedSettings(this),J)return this;return X}createCommand(z){return new $1(z)}createHelp(){return Object.assign(new U9,this.configureHelp())}configureHelp(z){if(z===void 0)return this._helpConfiguration;return this._helpConfiguration=z,this}configureOutput(z){if(z===void 0)return this._outputConfiguration;return this._outputConfiguration={...this._outputConfiguration,...z},this}showHelpAfterError(z=!0){if(typeof z!=="string")z=!!z;return this._showHelpAfterError=z,this}showSuggestionAfterError(z=!0){return this._showSuggestionAfterError=!!z,this}addCommand(z,q){if(!z._name)throw Error(`Command passed to .addCommand() must have a name
15
+ - specify the name in Command constructor or using .name()`);if(q=q||{},q.isDefault)this._defaultCommandName=z._name;if(q.noHelp||q.hidden)z._hidden=!0;return this._registerCommand(z),z.parent=this,z._checkForBrokenPassThrough(),this}createArgument(z,q){return new T9(z,q)}argument(z,q,B,J){let Y=this.createArgument(z,q);if(typeof B==="function")Y.default(J).argParser(B);else Y.default(B);return this.addArgument(Y),this}arguments(z){return z.trim().split(/ +/).forEach((q)=>{this.argument(q)}),this}addArgument(z){let q=this.registeredArguments.slice(-1)[0];if(q?.variadic)throw Error(`only the last argument can be variadic '${q.name()}'`);if(z.required&&z.defaultValue!==void 0&&z.parseArg===void 0)throw Error(`a default value for a required argument is never used: '${z.name()}'`);return this.registeredArguments.push(z),this}helpCommand(z,q){if(typeof z==="boolean"){if(this._addImplicitHelpCommand=z,z&&this._defaultCommandGroup)this._initCommandGroup(this._getHelpCommand());return this}let B=z??"help [command]",[,J,Y]=B.match(/([^ ]+) *(.*)/),Z=q??"display help for command",Q=this.createCommand(J);if(Q.helpOption(!1),Y)Q.arguments(Y);if(Z)Q.description(Z);if(this._addImplicitHelpCommand=!0,this._helpCommand=Q,z||q)this._initCommandGroup(Q);return this}addHelpCommand(z,q){if(typeof z!=="object")return this.helpCommand(z,q),this;return this._addImplicitHelpCommand=!0,this._helpCommand=z,this._initCommandGroup(z),this}_getHelpCommand(){if(this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))){if(this._helpCommand===void 0)this.helpCommand(void 0,void 0);return this._helpCommand}return null}hook(z,q){let B=["preSubcommand","preAction","postAction"];if(!B.includes(z))throw Error(`Unexpected value for event passed to hook : '${z}'.
16
+ Expecting one of '${B.join("', '")}'`);if(this._lifeCycleHooks[z])this._lifeCycleHooks[z].push(q);else this._lifeCycleHooks[z]=[q];return this}exitOverride(z){if(z)this._exitCallback=z;else this._exitCallback=(q)=>{if(q.code!=="commander.executeSubCommandAsync")throw q};return this}_exit(z,q,B){if(this._exitCallback)this._exitCallback(new _1(z,q,B));D.exit(z)}action(z){let q=(B)=>{let J=this.registeredArguments.length,Y=B.slice(0,J);if(this._storeOptionsAsProperties)Y[J]=this;else Y[J]=this.opts();return Y.push(this),z.apply(this,Y)};return this._actionHandler=q,this}createOption(z,q){return new p1(z,q)}_callParseArg(z,q,B,J){try{return z.parseArg(q,B)}catch(Y){if(Y.code==="commander.invalidArgument"){let Z=`${J} ${Y.message}`;this.error(Z,{exitCode:Y.exitCode,code:Y.code})}throw Y}}_registerOption(z){let q=z.short&&this._findOption(z.short)||z.long&&this._findOption(z.long);if(q){let B=z.long&&this._findOption(z.long)?z.long:z.short;throw Error(`Cannot add option '${z.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${B}'
17
+ - already used by option '${q.flags}'`)}this._initOptionGroup(z),this.options.push(z)}_registerCommand(z){let q=(J)=>{return[J.name()].concat(J.aliases())},B=q(z).find((J)=>this._findCommand(J));if(B){let J=q(this._findCommand(B)).join("|"),Y=q(z).join("|");throw Error(`cannot add command '${Y}' as already have command '${J}'`)}this._initCommandGroup(z),this.commands.push(z)}addOption(z){this._registerOption(z);let q=z.name(),B=z.attributeName();if(z.negate){let Y=z.long.replace(/^--no-/,"--");if(!this._findOption(Y))this.setOptionValueWithSource(B,z.defaultValue===void 0?!0:z.defaultValue,"default")}else if(z.defaultValue!==void 0)this.setOptionValueWithSource(B,z.defaultValue,"default");let J=(Y,Z,Q)=>{if(Y==null&&z.presetArg!==void 0)Y=z.presetArg;let X=this.getOptionValue(B);if(Y!==null&&z.parseArg)Y=this._callParseArg(z,Y,X,Z);else if(Y!==null&&z.variadic)Y=z._collectValue(Y,X);if(Y==null)if(z.negate)Y=!1;else if(z.isBoolean()||z.optional)Y=!0;else Y="";this.setOptionValueWithSource(B,Y,Q)};if(this.on("option:"+q,(Y)=>{let Z=`error: option '${z.flags}' argument '${Y}' is invalid.`;J(Y,Z,"cli")}),z.envVar)this.on("optionEnv:"+q,(Y)=>{let Z=`error: option '${z.flags}' value '${Y}' from env '${z.envVar}' is invalid.`;J(Y,Z,"env")});return this}_optionEx(z,q,B,J,Y){if(typeof q==="object"&&q instanceof p1)throw Error("To add an Option object use addOption() instead of option() or requiredOption()");let Z=this.createOption(q,B);if(Z.makeOptionMandatory(!!z.mandatory),typeof J==="function")Z.default(Y).argParser(J);else if(J instanceof RegExp){let Q=J;J=(X,L)=>{let G=Q.exec(X);return G?G[0]:L},Z.default(Y).argParser(J)}else Z.default(J);return this.addOption(Z)}option(z,q,B,J){return this._optionEx({},z,q,B,J)}requiredOption(z,q,B,J){return this._optionEx({mandatory:!0},z,q,B,J)}combineFlagAndOptionalValue(z=!0){return this._combineFlagAndOptionalValue=!!z,this}allowUnknownOption(z=!0){return this._allowUnknownOption=!!z,this}allowExcessArguments(z=!0){return this._allowExcessArguments=!!z,this}enablePositionalOptions(z=!0){return this._enablePositionalOptions=!!z,this}passThroughOptions(z=!0){return this._passThroughOptions=!!z,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(z=!0){if(this.options.length)throw Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!z,this}getOptionValue(z){if(this._storeOptionsAsProperties)return this[z];return this._optionValues[z]}setOptionValue(z,q){return this.setOptionValueWithSource(z,q,void 0)}setOptionValueWithSource(z,q,B){if(this._storeOptionsAsProperties)this[z]=q;else this._optionValues[z]=q;return this._optionValueSources[z]=B,this}getOptionValueSource(z){return this._optionValueSources[z]}getOptionValueSourceWithGlobals(z){let q;return this._getCommandAndAncestors().forEach((B)=>{if(B.getOptionValueSource(z)!==void 0)q=B.getOptionValueSource(z)}),q}_prepareUserArgs(z,q){if(z!==void 0&&!Array.isArray(z))throw Error("first parameter to parse must be array or undefined");if(q=q||{},z===void 0&&q.from===void 0){if(D.versions?.electron)q.from="electron";let J=D.execArgv??[];if(J.includes("-e")||J.includes("--eval")||J.includes("-p")||J.includes("--print"))q.from="eval"}if(z===void 0)z=D.argv;this.rawArgs=z.slice();let B;switch(q.from){case void 0:case"node":this._scriptPath=z[1],B=z.slice(2);break;case"electron":if(D.defaultApp)this._scriptPath=z[1],B=z.slice(2);else B=z.slice(1);break;case"user":B=z.slice(0);break;case"eval":B=z.slice(1);break;default:throw Error(`unexpected parse option { from: '${q.from}' }`)}if(!this._name&&this._scriptPath)this.nameFromFilename(this._scriptPath);return this._name=this._name||"program",B}parse(z,q){this._prepareForParse();let B=this._prepareUserArgs(z,q);return this._parseCommand([],B),this}async parseAsync(z,q){this._prepareForParse();let B=this._prepareUserArgs(z,q);return await this._parseCommand([],B),this}_prepareForParse(){if(this._savedState===null)this.saveStateBeforeParse();else this.restoreStateBeforeParse()}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw Error(`Can not call parse again when storeOptionsAsProperties is true.
18
+ - either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[]}_checkForMissingExecutable(z,q,B){if(r.existsSync(z))return;let J=q?`searched for local subcommand relative to directory '${q}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",Y=`'${z}' does not exist
19
+ - if '${B}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
20
20
  - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
21
- - ${Q}`;throw Error(X)}_executeSubCommand(q,z){z=z.slice();let J=!1,Q=[".js",".ts",".tsx",".mjs",".cjs"];function X(Y,B){let H=P.resolve(Y,B);if(x.existsSync(H))return H;if(Q.includes(P.extname(B)))return;let E=Q.find((L)=>x.existsSync(`${H}${L}`));if(E)return`${H}${E}`;return}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let Z=q._executableFile||`${this._name}-${q._name}`,$=this._executableDir||"";if(this._scriptPath){let Y;try{Y=x.realpathSync(this._scriptPath)}catch{Y=this._scriptPath}$=P.resolve(P.dirname(Y),$)}if($){let Y=X($,Z);if(!Y&&!q._executableFile&&this._scriptPath){let B=P.basename(this._scriptPath,P.extname(this._scriptPath));if(B!==this._name)Y=X($,`${B}-${q._name}`)}Z=Y||Z}J=Q.includes(P.extname(Z));let _;if(T.platform!=="win32")if(J)z.unshift(Z),z=Q4(T.execArgv).concat(z),_=u.spawn(T.argv[0],z,{stdio:"inherit"});else _=u.spawn(Z,z,{stdio:"inherit"});else this._checkForMissingExecutable(Z,$,q._name),z.unshift(Z),z=Q4(T.execArgv).concat(z),_=u.spawn(T.execPath,z,{stdio:"inherit"});if(!_.killed)["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach((B)=>{T.on(B,()=>{if(_.killed===!1&&_.exitCode===null)_.kill(B)})});let G=this._exitCallback;_.on("close",(Y)=>{if(Y=Y??1,!G)T.exit(Y);else G(new g(Y,"commander.executeSubCommandAsync","(close)"))}),_.on("error",(Y)=>{if(Y.code==="ENOENT")this._checkForMissingExecutable(Z,$,q._name);else if(Y.code==="EACCES")throw Error(`'${Z}' not executable`);if(!G)T.exit(1);else{let B=new g(1,"commander.executeSubCommandAsync","(error)");B.nestedError=Y,G(B)}}),this.runningCommand=_}_dispatchSubcommand(q,z,J){let Q=this._findCommand(q);if(!Q)this.help({error:!0});Q._prepareForParse();let X;return X=this._chainOrCallSubCommandHook(X,Q,"preSubcommand"),X=this._chainOrCall(X,()=>{if(Q._executableHandler)this._executeSubCommand(Q,z.concat(J));else return Q._parseCommand(z,J)}),X}_dispatchHelpCommand(q){if(!q)this.help();let z=this._findCommand(q);if(z&&!z._executableHandler)z.help();return this._dispatchSubcommand(q,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){if(this.registeredArguments.forEach((q,z)=>{if(q.required&&this.args[z]==null)this.missingArgument(q.name())}),this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)return;if(this.args.length>this.registeredArguments.length)this._excessArguments(this.args)}_processArguments(){let q=(J,Q,X)=>{let Z=Q;if(Q!==null&&J.parseArg){let $=`error: command-argument value '${Q}' is invalid for argument '${J.name()}'.`;Z=this._callParseArg(J,Q,X,$)}return Z};this._checkNumberOfArguments();let z=[];this.registeredArguments.forEach((J,Q)=>{let X=J.defaultValue;if(J.variadic){if(Q<this.args.length){if(X=this.args.slice(Q),J.parseArg)X=X.reduce((Z,$)=>{return q(J,$,Z)},J.defaultValue)}else if(X===void 0)X=[]}else if(Q<this.args.length){if(X=this.args[Q],J.parseArg)X=q(J,X,J.defaultValue)}z[Q]=X}),this.processedArgs=z}_chainOrCall(q,z){if(q?.then&&typeof q.then==="function")return q.then(()=>z());return z()}_chainOrCallHooks(q,z){let J=q,Q=[];if(this._getCommandAndAncestors().reverse().filter((X)=>X._lifeCycleHooks[z]!==void 0).forEach((X)=>{X._lifeCycleHooks[z].forEach((Z)=>{Q.push({hookedCommand:X,callback:Z})})}),z==="postAction")Q.reverse();return Q.forEach((X)=>{J=this._chainOrCall(J,()=>{return X.callback(X.hookedCommand,this)})}),J}_chainOrCallSubCommandHook(q,z,J){let Q=q;if(this._lifeCycleHooks[J]!==void 0)this._lifeCycleHooks[J].forEach((X)=>{Q=this._chainOrCall(Q,()=>{return X(this,z)})});return Q}_parseCommand(q,z){let J=this.parseOptions(z);if(this._parseOptionsEnv(),this._parseOptionsImplied(),q=q.concat(J.operands),z=J.unknown,this.args=q.concat(z),q&&this._findCommand(q[0]))return this._dispatchSubcommand(q[0],q.slice(1),z);if(this._getHelpCommand()&&q[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(q[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(z),this._dispatchSubcommand(this._defaultCommandName,q,z);if(this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName)this.help({error:!0});this._outputHelpIfRequested(J.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let Q=()=>{if(J.unknown.length>0)this.unknownOption(J.unknown[0])},X=`command:${this.name()}`;if(this._actionHandler){Q(),this._processArguments();let Z;if(Z=this._chainOrCallHooks(Z,"preAction"),Z=this._chainOrCall(Z,()=>this._actionHandler(this.processedArgs)),this.parent)Z=this._chainOrCall(Z,()=>{this.parent.emit(X,q,z)});return Z=this._chainOrCallHooks(Z,"postAction"),Z}if(this.parent?.listenerCount(X))Q(),this._processArguments(),this.parent.emit(X,q,z);else if(q.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",q,z);if(this.listenerCount("command:*"))this.emit("command:*",q,z);else if(this.commands.length)this.unknownCommand();else Q(),this._processArguments()}else if(this.commands.length)Q(),this.help({error:!0});else Q(),this._processArguments()}_findCommand(q){if(!q)return;return this.commands.find((z)=>z._name===q||z._aliases.includes(q))}_findOption(q){return this.options.find((z)=>z.is(q))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach((q)=>{q.options.forEach((z)=>{if(z.mandatory&&q.getOptionValue(z.attributeName())===void 0)q.missingMandatoryOptionValue(z)})})}_checkForConflictingLocalOptions(){let q=this.options.filter((J)=>{let Q=J.attributeName();if(this.getOptionValue(Q)===void 0)return!1;return this.getOptionValueSource(Q)!=="default"});q.filter((J)=>J.conflictsWith.length>0).forEach((J)=>{let Q=q.find((X)=>J.conflictsWith.includes(X.attributeName()));if(Q)this._conflictingOption(J,Q)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach((q)=>{q._checkForConflictingLocalOptions()})}parseOptions(q){let z=[],J=[],Q=z;function X(Y){return Y.length>1&&Y[0]==="-"}let Z=(Y)=>{if(!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(Y))return!1;return!this._getCommandAndAncestors().some((B)=>B.options.map((H)=>H.short).some((H)=>/^-\d$/.test(H)))},$=null,_=null,G=0;while(G<q.length||_){let Y=_??q[G++];if(_=null,Y==="--"){if(Q===J)Q.push(Y);Q.push(...q.slice(G));break}if($&&(!X(Y)||Z(Y))){this.emit(`option:${$.name()}`,Y);continue}if($=null,X(Y)){let B=this._findOption(Y);if(B){if(B.required){let H=q[G++];if(H===void 0)this.optionMissingArgument(B);this.emit(`option:${B.name()}`,H)}else if(B.optional){let H=null;if(G<q.length&&(!X(q[G])||Z(q[G])))H=q[G++];this.emit(`option:${B.name()}`,H)}else this.emit(`option:${B.name()}`);$=B.variadic?B:null;continue}}if(Y.length>2&&Y[0]==="-"&&Y[1]!=="-"){let B=this._findOption(`-${Y[1]}`);if(B){if(B.required||B.optional&&this._combineFlagAndOptionalValue)this.emit(`option:${B.name()}`,Y.slice(2));else this.emit(`option:${B.name()}`),_=`-${Y.slice(2)}`;continue}}if(/^--[^=]+=/.test(Y)){let B=Y.indexOf("="),H=this._findOption(Y.slice(0,B));if(H&&(H.required||H.optional)){this.emit(`option:${H.name()}`,Y.slice(B+1));continue}}if(Q===z&&X(Y)&&!(this.commands.length===0&&Z(Y)))Q=J;if((this._enablePositionalOptions||this._passThroughOptions)&&z.length===0&&J.length===0){if(this._findCommand(Y)){z.push(Y),J.push(...q.slice(G));break}else if(this._getHelpCommand()&&Y===this._getHelpCommand().name()){z.push(Y,...q.slice(G));break}else if(this._defaultCommandName){J.push(Y,...q.slice(G));break}}if(this._passThroughOptions){Q.push(Y,...q.slice(G));break}Q.push(Y)}return{operands:z,unknown:J}}opts(){if(this._storeOptionsAsProperties){let q={},z=this.options.length;for(let J=0;J<z;J++){let Q=this.options[J].attributeName();q[Q]=Q===this._versionOptionName?this._version:this[Q]}return q}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((q,z)=>Object.assign(q,z.opts()),{})}error(q,z){if(this._outputConfiguration.outputError(`${q}
21
+ - ${J}`;throw Error(Y)}_executeSubCommand(z,q){q=q.slice();let B=!1,J=[".js",".ts",".tsx",".mjs",".cjs"];function Y(G,H){let T=h.resolve(G,H);if(r.existsSync(T))return T;if(J.includes(h.extname(H)))return;let j=J.find((N)=>r.existsSync(`${T}${N}`));if(j)return`${T}${j}`;return}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let Z=z._executableFile||`${this._name}-${z._name}`,Q=this._executableDir||"";if(this._scriptPath){let G;try{G=r.realpathSync(this._scriptPath)}catch{G=this._scriptPath}Q=h.resolve(h.dirname(G),Q)}if(Q){let G=Y(Q,Z);if(!G&&!z._executableFile&&this._scriptPath){let H=h.basename(this._scriptPath,h.extname(this._scriptPath));if(H!==this._name)G=Y(Q,`${H}-${z._name}`)}Z=G||Z}B=J.includes(h.extname(Z));let X;if(D.platform!=="win32")if(B)q.unshift(Z),q=n1(D.execArgv).concat(q),X=U1.spawn(D.argv[0],q,{stdio:"inherit"});else X=U1.spawn(Z,q,{stdio:"inherit"});else this._checkForMissingExecutable(Z,Q,z._name),q.unshift(Z),q=n1(D.execArgv).concat(q),X=U1.spawn(D.execPath,q,{stdio:"inherit"});if(!X.killed)["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach((H)=>{D.on(H,()=>{if(X.killed===!1&&X.exitCode===null)X.kill(H)})});let L=this._exitCallback;X.on("close",(G)=>{if(G=G??1,!L)D.exit(G);else L(new _1(G,"commander.executeSubCommandAsync","(close)"))}),X.on("error",(G)=>{if(G.code==="ENOENT")this._checkForMissingExecutable(Z,Q,z._name);else if(G.code==="EACCES")throw Error(`'${Z}' not executable`);if(!L)D.exit(1);else{let H=new _1(1,"commander.executeSubCommandAsync","(error)");H.nestedError=G,L(H)}}),this.runningCommand=X}_dispatchSubcommand(z,q,B){let J=this._findCommand(z);if(!J)this.help({error:!0});J._prepareForParse();let Y;return Y=this._chainOrCallSubCommandHook(Y,J,"preSubcommand"),Y=this._chainOrCall(Y,()=>{if(J._executableHandler)this._executeSubCommand(J,q.concat(B));else return J._parseCommand(q,B)}),Y}_dispatchHelpCommand(z){if(!z)this.help();let q=this._findCommand(z);if(q&&!q._executableHandler)q.help();return this._dispatchSubcommand(z,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){if(this.registeredArguments.forEach((z,q)=>{if(z.required&&this.args[q]==null)this.missingArgument(z.name())}),this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)return;if(this.args.length>this.registeredArguments.length)this._excessArguments(this.args)}_processArguments(){let z=(B,J,Y)=>{let Z=J;if(J!==null&&B.parseArg){let Q=`error: command-argument value '${J}' is invalid for argument '${B.name()}'.`;Z=this._callParseArg(B,J,Y,Q)}return Z};this._checkNumberOfArguments();let q=[];this.registeredArguments.forEach((B,J)=>{let Y=B.defaultValue;if(B.variadic){if(J<this.args.length){if(Y=this.args.slice(J),B.parseArg)Y=Y.reduce((Z,Q)=>{return z(B,Q,Z)},B.defaultValue)}else if(Y===void 0)Y=[]}else if(J<this.args.length){if(Y=this.args[J],B.parseArg)Y=z(B,Y,B.defaultValue)}q[J]=Y}),this.processedArgs=q}_chainOrCall(z,q){if(z?.then&&typeof z.then==="function")return z.then(()=>q());return q()}_chainOrCallHooks(z,q){let B=z,J=[];if(this._getCommandAndAncestors().reverse().filter((Y)=>Y._lifeCycleHooks[q]!==void 0).forEach((Y)=>{Y._lifeCycleHooks[q].forEach((Z)=>{J.push({hookedCommand:Y,callback:Z})})}),q==="postAction")J.reverse();return J.forEach((Y)=>{B=this._chainOrCall(B,()=>{return Y.callback(Y.hookedCommand,this)})}),B}_chainOrCallSubCommandHook(z,q,B){let J=z;if(this._lifeCycleHooks[B]!==void 0)this._lifeCycleHooks[B].forEach((Y)=>{J=this._chainOrCall(J,()=>{return Y(this,q)})});return J}_parseCommand(z,q){let B=this.parseOptions(q);if(this._parseOptionsEnv(),this._parseOptionsImplied(),z=z.concat(B.operands),q=B.unknown,this.args=z.concat(q),z&&this._findCommand(z[0]))return this._dispatchSubcommand(z[0],z.slice(1),q);if(this._getHelpCommand()&&z[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(z[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(q),this._dispatchSubcommand(this._defaultCommandName,z,q);if(this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName)this.help({error:!0});this._outputHelpIfRequested(B.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let J=()=>{if(B.unknown.length>0)this.unknownOption(B.unknown[0])},Y=`command:${this.name()}`;if(this._actionHandler){J(),this._processArguments();let Z;if(Z=this._chainOrCallHooks(Z,"preAction"),Z=this._chainOrCall(Z,()=>this._actionHandler(this.processedArgs)),this.parent)Z=this._chainOrCall(Z,()=>{this.parent.emit(Y,z,q)});return Z=this._chainOrCallHooks(Z,"postAction"),Z}if(this.parent?.listenerCount(Y))J(),this._processArguments(),this.parent.emit(Y,z,q);else if(z.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",z,q);if(this.listenerCount("command:*"))this.emit("command:*",z,q);else if(this.commands.length)this.unknownCommand();else J(),this._processArguments()}else if(this.commands.length)J(),this.help({error:!0});else J(),this._processArguments()}_findCommand(z){if(!z)return;return this.commands.find((q)=>q._name===z||q._aliases.includes(z))}_findOption(z){return this.options.find((q)=>q.is(z))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach((z)=>{z.options.forEach((q)=>{if(q.mandatory&&z.getOptionValue(q.attributeName())===void 0)z.missingMandatoryOptionValue(q)})})}_checkForConflictingLocalOptions(){let z=this.options.filter((B)=>{let J=B.attributeName();if(this.getOptionValue(J)===void 0)return!1;return this.getOptionValueSource(J)!=="default"});z.filter((B)=>B.conflictsWith.length>0).forEach((B)=>{let J=z.find((Y)=>B.conflictsWith.includes(Y.attributeName()));if(J)this._conflictingOption(B,J)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach((z)=>{z._checkForConflictingLocalOptions()})}parseOptions(z){let q=[],B=[],J=q;function Y(G){return G.length>1&&G[0]==="-"}let Z=(G)=>{if(!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(G))return!1;return!this._getCommandAndAncestors().some((H)=>H.options.map((T)=>T.short).some((T)=>/^-\d$/.test(T)))},Q=null,X=null,L=0;while(L<z.length||X){let G=X??z[L++];if(X=null,G==="--"){if(J===B)J.push(G);J.push(...z.slice(L));break}if(Q&&(!Y(G)||Z(G))){this.emit(`option:${Q.name()}`,G);continue}if(Q=null,Y(G)){let H=this._findOption(G);if(H){if(H.required){let T=z[L++];if(T===void 0)this.optionMissingArgument(H);this.emit(`option:${H.name()}`,T)}else if(H.optional){let T=null;if(L<z.length&&(!Y(z[L])||Z(z[L])))T=z[L++];this.emit(`option:${H.name()}`,T)}else this.emit(`option:${H.name()}`);Q=H.variadic?H:null;continue}}if(G.length>2&&G[0]==="-"&&G[1]!=="-"){let H=this._findOption(`-${G[1]}`);if(H){if(H.required||H.optional&&this._combineFlagAndOptionalValue)this.emit(`option:${H.name()}`,G.slice(2));else this.emit(`option:${H.name()}`),X=`-${G.slice(2)}`;continue}}if(/^--[^=]+=/.test(G)){let H=G.indexOf("="),T=this._findOption(G.slice(0,H));if(T&&(T.required||T.optional)){this.emit(`option:${T.name()}`,G.slice(H+1));continue}}if(J===q&&Y(G)&&!(this.commands.length===0&&Z(G)))J=B;if((this._enablePositionalOptions||this._passThroughOptions)&&q.length===0&&B.length===0){if(this._findCommand(G)){q.push(G),B.push(...z.slice(L));break}else if(this._getHelpCommand()&&G===this._getHelpCommand().name()){q.push(G,...z.slice(L));break}else if(this._defaultCommandName){B.push(G,...z.slice(L));break}}if(this._passThroughOptions){J.push(G,...z.slice(L));break}J.push(G)}return{operands:q,unknown:B}}opts(){if(this._storeOptionsAsProperties){let z={},q=this.options.length;for(let B=0;B<q;B++){let J=this.options[B].attributeName();z[J]=J===this._versionOptionName?this._version:this[J]}return z}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((z,q)=>Object.assign(z,q.opts()),{})}error(z,q){if(this._outputConfiguration.outputError(`${z}
22
22
  `,this._outputConfiguration.writeErr),typeof this._showHelpAfterError==="string")this._outputConfiguration.writeErr(`${this._showHelpAfterError}
23
23
  `);else if(this._showHelpAfterError)this._outputConfiguration.writeErr(`
24
- `),this.outputHelp({error:!0});let J=z||{},Q=J.exitCode||1,X=J.code||"commander.error";this._exit(Q,X,q)}_parseOptionsEnv(){this.options.forEach((q)=>{if(q.envVar&&q.envVar in T.env){let z=q.attributeName();if(this.getOptionValue(z)===void 0||["default","config","env"].includes(this.getOptionValueSource(z)))if(q.required||q.optional)this.emit(`optionEnv:${q.name()}`,T.env[q.envVar]);else this.emit(`optionEnv:${q.name()}`)}})}_parseOptionsImplied(){let q=new s4(this.options),z=(J)=>{return this.getOptionValue(J)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(J))};this.options.filter((J)=>J.implied!==void 0&&z(J.attributeName())&&q.valueFromOption(this.getOptionValue(J.attributeName()),J)).forEach((J)=>{Object.keys(J.implied).filter((Q)=>!z(Q)).forEach((Q)=>{this.setOptionValueWithSource(Q,J.implied[Q],"implied")})})}missingArgument(q){let z=`error: missing required argument '${q}'`;this.error(z,{code:"commander.missingArgument"})}optionMissingArgument(q){let z=`error: option '${q.flags}' argument missing`;this.error(z,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(q){let z=`error: required option '${q.flags}' not specified`;this.error(z,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(q,z){let J=(Z)=>{let $=Z.attributeName(),_=this.getOptionValue($),G=this.options.find((B)=>B.negate&&$===B.attributeName()),Y=this.options.find((B)=>!B.negate&&$===B.attributeName());if(G&&(G.presetArg===void 0&&_===!1||G.presetArg!==void 0&&_===G.presetArg))return G;return Y||Z},Q=(Z)=>{let $=J(Z),_=$.attributeName();if(this.getOptionValueSource(_)==="env")return`environment variable '${$.envVar}'`;return`option '${$.flags}'`},X=`error: ${Q(q)} cannot be used with ${Q(z)}`;this.error(X,{code:"commander.conflictingOption"})}unknownOption(q){if(this._allowUnknownOption)return;let z="";if(q.startsWith("--")&&this._showSuggestionAfterError){let Q=[],X=this;do{let Z=X.createHelp().visibleOptions(X).filter(($)=>$.long).map(($)=>$.long);Q=Q.concat(Z),X=X.parent}while(X&&!X._enablePositionalOptions);z=J4(q,Q)}let J=`error: unknown option '${q}'${z}`;this.error(J,{code:"commander.unknownOption"})}_excessArguments(q){if(this._allowExcessArguments)return;let z=this.registeredArguments.length,J=z===1?"":"s",X=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${z} argument${J} but got ${q.length}.`;this.error(X,{code:"commander.excessArguments"})}unknownCommand(){let q=this.args[0],z="";if(this._showSuggestionAfterError){let Q=[];this.createHelp().visibleCommands(this).forEach((X)=>{if(Q.push(X.name()),X.alias())Q.push(X.alias())}),z=J4(q,Q)}let J=`error: unknown command '${q}'${z}`;this.error(J,{code:"commander.unknownCommand"})}version(q,z,J){if(q===void 0)return this._version;this._version=q,z=z||"-V, --version",J=J||"output the version number";let Q=this.createOption(z,J);return this._versionOptionName=Q.attributeName(),this._registerOption(Q),this.on("option:"+Q.name(),()=>{this._outputConfiguration.writeOut(`${q}
25
- `),this._exit(0,"commander.version",q)}),this}description(q,z){if(q===void 0&&z===void 0)return this._description;if(this._description=q,z)this._argsDescription=z;return this}summary(q){if(q===void 0)return this._summary;return this._summary=q,this}alias(q){if(q===void 0)return this._aliases[0];let z=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)z=this.commands[this.commands.length-1];if(q===z._name)throw Error("Command alias can't be the same as its name");let J=this.parent?._findCommand(q);if(J){let Q=[J.name()].concat(J.aliases()).join("|");throw Error(`cannot add alias '${q}' to command '${this.name()}' as already have command '${Q}'`)}return z._aliases.push(q),this}aliases(q){if(q===void 0)return this._aliases;return q.forEach((z)=>this.alias(z)),this}usage(q){if(q===void 0){if(this._usage)return this._usage;let z=this.registeredArguments.map((J)=>{return m4(J)});return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?z:[]).join(" ")}return this._usage=q,this}name(q){if(q===void 0)return this._name;return this._name=q,this}helpGroup(q){if(q===void 0)return this._helpGroupHeading??"";return this._helpGroupHeading=q,this}commandsGroup(q){if(q===void 0)return this._defaultCommandGroup??"";return this._defaultCommandGroup=q,this}optionsGroup(q){if(q===void 0)return this._defaultOptionGroup??"";return this._defaultOptionGroup=q,this}_initOptionGroup(q){if(this._defaultOptionGroup&&!q.helpGroupHeading)q.helpGroup(this._defaultOptionGroup)}_initCommandGroup(q){if(this._defaultCommandGroup&&!q.helpGroup())q.helpGroup(this._defaultCommandGroup)}nameFromFilename(q){return this._name=P.basename(q,P.extname(q)),this}executableDir(q){if(q===void 0)return this._executableDir;return this._executableDir=q,this}helpInformation(q){let z=this.createHelp(),J=this._getOutputContext(q);z.prepareContext({error:J.error,helpWidth:J.helpWidth,outputHasColors:J.hasColors});let Q=z.formatHelp(this,z);if(J.hasColors)return Q;return this._outputConfiguration.stripColor(Q)}_getOutputContext(q){q=q||{};let z=!!q.error,J,Q,X;if(z)J=($)=>this._outputConfiguration.writeErr($),Q=this._outputConfiguration.getErrHasColors(),X=this._outputConfiguration.getErrHelpWidth();else J=($)=>this._outputConfiguration.writeOut($),Q=this._outputConfiguration.getOutHasColors(),X=this._outputConfiguration.getOutHelpWidth();return{error:z,write:($)=>{if(!Q)$=this._outputConfiguration.stripColor($);return J($)},hasColors:Q,helpWidth:X}}outputHelp(q){let z;if(typeof q==="function")z=q,q=void 0;let J=this._getOutputContext(q),Q={error:J.error,write:J.write,command:this};this._getCommandAndAncestors().reverse().forEach((Z)=>Z.emit("beforeAllHelp",Q)),this.emit("beforeHelp",Q);let X=this.helpInformation({error:J.error});if(z){if(X=z(X),typeof X!=="string"&&!Buffer.isBuffer(X))throw Error("outputHelp callback must return a string or a Buffer")}if(J.write(X),this._getHelpOption()?.long)this.emit(this._getHelpOption().long);this.emit("afterHelp",Q),this._getCommandAndAncestors().forEach((Z)=>Z.emit("afterAllHelp",Q))}helpOption(q,z){if(typeof q==="boolean"){if(q){if(this._helpOption===null)this._helpOption=void 0;if(this._defaultOptionGroup)this._initOptionGroup(this._getHelpOption())}else this._helpOption=null;return this}if(this._helpOption=this.createOption(q??"-h, --help",z??"display help for command"),q||z)this._initOptionGroup(this._helpOption);return this}_getHelpOption(){if(this._helpOption===void 0)this.helpOption(void 0,void 0);return this._helpOption}addHelpOption(q){return this._helpOption=q,this._initOptionGroup(q),this}help(q){this.outputHelp(q);let z=Number(T.exitCode??0);if(z===0&&q&&typeof q!=="function"&&q.error)z=1;this._exit(z,"commander.help","(outputHelp)")}addHelpText(q,z){let J=["beforeAll","before","after","afterAll"];if(!J.includes(q))throw Error(`Unexpected value for position to addHelpText.
26
- Expecting one of '${J.join("', '")}'`);let Q=`${q}Help`;return this.on(Q,(X)=>{let Z;if(typeof z==="function")Z=z({error:X.error,command:X.command});else Z=z;if(Z)X.write(`${Z}
27
- `)}),this}_outputHelpIfRequested(q){let z=this._getHelpOption();if(z&&q.find((Q)=>z.is(Q)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function Q4(q){return q.map((z)=>{if(!z.startsWith("--inspect"))return z;let J,Q="127.0.0.1",X="9229",Z;if((Z=z.match(/^(--inspect(-brk)?)$/))!==null)J=Z[1];else if((Z=z.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(J=Z[1],/^\d+$/.test(Z[3]))X=Z[3];else Q=Z[3];else if((Z=z.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)J=Z[1],Q=Z[3],X=Z[4];if(J&&X!=="0")return`${J}=${Q}:${parseInt(X)+1}`;return z})}function c(){if(T.env.NO_COLOR||T.env.FORCE_COLOR==="0"||T.env.FORCE_COLOR==="false")return!1;if(T.env.FORCE_COLOR||T.env.CLICOLOR_FORCE!==void 0)return!0;return}n4.Command=d;n4.useColor=c});var Y4=D((e4)=>{var{Argument:Z4}=k(),{Command:l}=X4(),{CommanderError:a4,InvalidArgumentError:$4}=A(),{Help:o4}=v(),{Option:_4}=h();e4.program=new l;e4.createCommand=(q)=>new l(q);e4.createOption=(q,z)=>new _4(q,z);e4.createArgument=(q,z)=>new Z4(q,z);e4.Command=l;e4.Option=_4;e4.Argument=Z4;e4.Help=o4;e4.CommanderError=a4;e4.InvalidArgumentError=$4;e4.InvalidOptionArgumentError=$4});var B4=I4(Y4(),1),{program:w,createCommand:F6,createArgument:y6,createOption:A6,CommanderError:w6,InvalidArgumentError:C6,InvalidOptionArgumentError:k6,Command:x6,Argument:O6,Option:b6,Help:f6}=B4.default;var O={name:"@mintplex-labs/anything-llm-cli",version:"0.0.6",description:"A CLI tool to interact with AnythingLLM from the terminal",type:"module",bin:{any:"dist/index.js"},files:["dist/index.js","README.md"],keywords:["anythingllm","llm","cli","ai"],repository:{type:"git",url:"https://github.com/Mintplex-Labs/anything-llm-cli"},license:"MIT",scripts:{setup:"cp .env.example .env.local && bun install",start:"bun run src/index.ts",build:"bun build --compile --minify --outfile=dist/any src/index.ts","build:npm":"bun build --minify --target=node --banner '#!/usr/bin/env node' --outfile=dist/index.js src/index.ts",prepublishOnly:"bun run build:npm",lint:"bunx biome check --write .","build:linux-x64":"bun build --compile --minify --target=bun-linux-x64 --outfile=dist/any-linux-x64 src/index.ts","build:linux-arm64":"bun build --compile --minify --target=bun-linux-arm64 --outfile=dist/any-linux-arm64 src/index.ts","build:windows-x64":"bun build --compile --minify --target=bun-windows-x64 --outfile=dist/any-windows-x64.exe src/index.ts","build:darwin-x64":"bun build --compile --minify --target=bun-darwin-x64 --outfile=dist/any-darwin-x64 src/index.ts","build:darwin-arm64":"bun build --compile --minify --target=bun-darwin-arm64 --outfile=dist/any-darwin-arm64 src/index.ts","build:all":"bun run build:linux-x64 && bun run build:linux-arm64 && bun run build:windows-x64 && bun run build:darwin-x64 && bun run build:darwin-arm64"},devDependencies:{"@biomejs/biome":"2.3.15","@types/bun":"latest",lefthook:"^2.1.1"},peerDependencies:{typescript:"^5"},dependencies:{commander:"^14.0.3"}};import{readFileSync as M6}from"node:fs";import{basename as T6,extname as U6,resolve as R6}from"node:path";class b{apiKey=process.env.ANYTHINGLLM_API_KEY||"";baseUrl=new URL("http://localhost:3001");static fileToAttachment(q){let z={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp"},J=R6(q),Q=U6(J).toLowerCase(),X=z[Q];if(!X)console.error(`Unsupported file type: ${Q}
28
- Supported: ${Object.keys(z).join(", ")}`),process.exit(1);let $=M6(J).toString("base64");return{name:T6(J),mime:X,contentString:`data:${X};base64,${$}`}}streamResponse(q,z){let J=this;return{[Symbol.asyncIterator](){return async function*(){let Q=new URL(q,J.baseUrl),X=await fetch(Q.href,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${J.apiKey}`},body:JSON.stringify(z)});if(!X.ok||!X.body)throw Error(`Stream request failed with status ${X.status}`);let Z=new TextDecoder,$="";for await(let _ of X.body){$+=Z.decode(_,{stream:!0});let G=$.split(`
24
+ `),this.outputHelp({error:!0});let B=q||{},J=B.exitCode||1,Y=B.code||"commander.error";this._exit(J,Y,z)}_parseOptionsEnv(){this.options.forEach((z)=>{if(z.envVar&&z.envVar in D.env){let q=z.attributeName();if(this.getOptionValue(q)===void 0||["default","config","env"].includes(this.getOptionValueSource(q)))if(z.required||z.optional)this.emit(`optionEnv:${z.name()}`,D.env[z.envVar]);else this.emit(`optionEnv:${z.name()}`)}})}_parseOptionsImplied(){let z=new R9(this.options),q=(B)=>{return this.getOptionValue(B)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(B))};this.options.filter((B)=>B.implied!==void 0&&q(B.attributeName())&&z.valueFromOption(this.getOptionValue(B.attributeName()),B)).forEach((B)=>{Object.keys(B.implied).filter((J)=>!q(J)).forEach((J)=>{this.setOptionValueWithSource(J,B.implied[J],"implied")})})}missingArgument(z){let q=`error: missing required argument '${z}'`;this.error(q,{code:"commander.missingArgument"})}optionMissingArgument(z){let q=`error: option '${z.flags}' argument missing`;this.error(q,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(z){let q=`error: required option '${z.flags}' not specified`;this.error(q,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(z,q){let B=(Z)=>{let Q=Z.attributeName(),X=this.getOptionValue(Q),L=this.options.find((H)=>H.negate&&Q===H.attributeName()),G=this.options.find((H)=>!H.negate&&Q===H.attributeName());if(L&&(L.presetArg===void 0&&X===!1||L.presetArg!==void 0&&X===L.presetArg))return L;return G||Z},J=(Z)=>{let Q=B(Z),X=Q.attributeName();if(this.getOptionValueSource(X)==="env")return`environment variable '${Q.envVar}'`;return`option '${Q.flags}'`},Y=`error: ${J(z)} cannot be used with ${J(q)}`;this.error(Y,{code:"commander.conflictingOption"})}unknownOption(z){if(this._allowUnknownOption)return;let q="";if(z.startsWith("--")&&this._showSuggestionAfterError){let J=[],Y=this;do{let Z=Y.createHelp().visibleOptions(Y).filter((Q)=>Q.long).map((Q)=>Q.long);J=J.concat(Z),Y=Y.parent}while(Y&&!Y._enablePositionalOptions);q=i1(z,J)}let B=`error: unknown option '${z}'${q}`;this.error(B,{code:"commander.unknownOption"})}_excessArguments(z){if(this._allowExcessArguments)return;let q=this.registeredArguments.length,B=q===1?"":"s",Y=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${q} argument${B} but got ${z.length}.`;this.error(Y,{code:"commander.excessArguments"})}unknownCommand(){let z=this.args[0],q="";if(this._showSuggestionAfterError){let J=[];this.createHelp().visibleCommands(this).forEach((Y)=>{if(J.push(Y.name()),Y.alias())J.push(Y.alias())}),q=i1(z,J)}let B=`error: unknown command '${z}'${q}`;this.error(B,{code:"commander.unknownCommand"})}version(z,q,B){if(z===void 0)return this._version;this._version=z,q=q||"-V, --version",B=B||"output the version number";let J=this.createOption(q,B);return this._versionOptionName=J.attributeName(),this._registerOption(J),this.on("option:"+J.name(),()=>{this._outputConfiguration.writeOut(`${z}
25
+ `),this._exit(0,"commander.version",z)}),this}description(z,q){if(z===void 0&&q===void 0)return this._description;if(this._description=z,q)this._argsDescription=q;return this}summary(z){if(z===void 0)return this._summary;return this._summary=z,this}alias(z){if(z===void 0)return this._aliases[0];let q=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)q=this.commands[this.commands.length-1];if(z===q._name)throw Error("Command alias can't be the same as its name");let B=this.parent?._findCommand(z);if(B){let J=[B.name()].concat(B.aliases()).join("|");throw Error(`cannot add alias '${z}' to command '${this.name()}' as already have command '${J}'`)}return q._aliases.push(z),this}aliases(z){if(z===void 0)return this._aliases;return z.forEach((q)=>this.alias(q)),this}usage(z){if(z===void 0){if(this._usage)return this._usage;let q=this.registeredArguments.map((B)=>{return S9(B)});return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?q:[]).join(" ")}return this._usage=z,this}name(z){if(z===void 0)return this._name;return this._name=z,this}helpGroup(z){if(z===void 0)return this._helpGroupHeading??"";return this._helpGroupHeading=z,this}commandsGroup(z){if(z===void 0)return this._defaultCommandGroup??"";return this._defaultCommandGroup=z,this}optionsGroup(z){if(z===void 0)return this._defaultOptionGroup??"";return this._defaultOptionGroup=z,this}_initOptionGroup(z){if(this._defaultOptionGroup&&!z.helpGroupHeading)z.helpGroup(this._defaultOptionGroup)}_initCommandGroup(z){if(this._defaultCommandGroup&&!z.helpGroup())z.helpGroup(this._defaultCommandGroup)}nameFromFilename(z){return this._name=h.basename(z,h.extname(z)),this}executableDir(z){if(z===void 0)return this._executableDir;return this._executableDir=z,this}helpInformation(z){let q=this.createHelp(),B=this._getOutputContext(z);q.prepareContext({error:B.error,helpWidth:B.helpWidth,outputHasColors:B.hasColors});let J=q.formatHelp(this,q);if(B.hasColors)return J;return this._outputConfiguration.stripColor(J)}_getOutputContext(z){z=z||{};let q=!!z.error,B,J,Y;if(q)B=(Q)=>this._outputConfiguration.writeErr(Q),J=this._outputConfiguration.getErrHasColors(),Y=this._outputConfiguration.getErrHelpWidth();else B=(Q)=>this._outputConfiguration.writeOut(Q),J=this._outputConfiguration.getOutHasColors(),Y=this._outputConfiguration.getOutHelpWidth();return{error:q,write:(Q)=>{if(!J)Q=this._outputConfiguration.stripColor(Q);return B(Q)},hasColors:J,helpWidth:Y}}outputHelp(z){let q;if(typeof z==="function")q=z,z=void 0;let B=this._getOutputContext(z),J={error:B.error,write:B.write,command:this};this._getCommandAndAncestors().reverse().forEach((Z)=>Z.emit("beforeAllHelp",J)),this.emit("beforeHelp",J);let Y=this.helpInformation({error:B.error});if(q){if(Y=q(Y),typeof Y!=="string"&&!Buffer.isBuffer(Y))throw Error("outputHelp callback must return a string or a Buffer")}if(B.write(Y),this._getHelpOption()?.long)this.emit(this._getHelpOption().long);this.emit("afterHelp",J),this._getCommandAndAncestors().forEach((Z)=>Z.emit("afterAllHelp",J))}helpOption(z,q){if(typeof z==="boolean"){if(z){if(this._helpOption===null)this._helpOption=void 0;if(this._defaultOptionGroup)this._initOptionGroup(this._getHelpOption())}else this._helpOption=null;return this}if(this._helpOption=this.createOption(z??"-h, --help",q??"display help for command"),z||q)this._initOptionGroup(this._helpOption);return this}_getHelpOption(){if(this._helpOption===void 0)this.helpOption(void 0,void 0);return this._helpOption}addHelpOption(z){return this._helpOption=z,this._initOptionGroup(z),this}help(z){this.outputHelp(z);let q=Number(D.exitCode??0);if(q===0&&z&&typeof z!=="function"&&z.error)q=1;this._exit(q,"commander.help","(outputHelp)")}addHelpText(z,q){let B=["beforeAll","before","after","afterAll"];if(!B.includes(z))throw Error(`Unexpected value for position to addHelpText.
26
+ Expecting one of '${B.join("', '")}'`);let J=`${z}Help`;return this.on(J,(Y)=>{let Z;if(typeof q==="function")Z=q({error:Y.error,command:Y.command});else Z=q;if(Z)Y.write(`${Z}
27
+ `)}),this}_outputHelpIfRequested(z){let q=this._getHelpOption();if(q&&z.find((J)=>q.is(J)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function n1(z){return z.map((q)=>{if(!q.startsWith("--inspect"))return q;let B,J="127.0.0.1",Y="9229",Z;if((Z=q.match(/^(--inspect(-brk)?)$/))!==null)B=Z[1];else if((Z=q.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(B=Z[1],/^\d+$/.test(Z[3]))Y=Z[3];else J=Z[3];else if((Z=q.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)B=Z[1],J=Z[3],Y=Z[4];if(B&&Y!=="0")return`${B}=${J}:${parseInt(Y)+1}`;return q})}function R1(){if(D.env.NO_COLOR||D.env.FORCE_COLOR==="0"||D.env.FORCE_COLOR==="false")return!1;if(D.env.FORCE_COLOR||D.env.CLICOLOR_FORCE!==void 0)return!0;return}$9.Command=$1;$9.useColor=R1});var e1=v((W9)=>{var{Argument:s1}=n(),{Command:M1}=r1(),{CommanderError:I9,InvalidArgumentError:o1}=l(),{Help:j9}=T1(),{Option:a1}=S1();W9.program=new M1;W9.createCommand=(z)=>new M1(z);W9.createOption=(z,q)=>new a1(z,q);W9.createArgument=(z,q)=>new s1(z,q);W9.Command=M1;W9.Option=a1;W9.Argument=s1;W9.Help=j9;W9.CommanderError=I9;W9.InvalidArgumentError=o1;W9.InvalidOptionArgumentError=o1});var I1=v((N0,K1)=>{var e=process||{},Y4=e.argv||[],a=e.env||{},u9=!(!!a.NO_COLOR||Y4.includes("--no-color"))&&(!!a.FORCE_COLOR||Y4.includes("--color")||e.platform==="win32"||(e.stdout||{}).isTTY&&a.TERM!=="dumb"||!!a.CI),g9=(z,q,B=z)=>(J)=>{let Y=""+J,Z=Y.indexOf(q,z.length);return~Z?z+c9(Y,q,B,Z)+q:z+Y+q},c9=(z,q,B,J)=>{let Y="",Z=0;do Y+=z.substring(Z,J)+B,Z=J+q.length,J=z.indexOf(q,Z);while(~J);return Y+z.substring(Z)},Z4=(z=u9)=>{let q=z?g9:()=>String;return{isColorSupported:z,reset:q("\x1B[0m","\x1B[0m"),bold:q("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:q("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:q("\x1B[3m","\x1B[23m"),underline:q("\x1B[4m","\x1B[24m"),inverse:q("\x1B[7m","\x1B[27m"),hidden:q("\x1B[8m","\x1B[28m"),strikethrough:q("\x1B[9m","\x1B[29m"),black:q("\x1B[30m","\x1B[39m"),red:q("\x1B[31m","\x1B[39m"),green:q("\x1B[32m","\x1B[39m"),yellow:q("\x1B[33m","\x1B[39m"),blue:q("\x1B[34m","\x1B[39m"),magenta:q("\x1B[35m","\x1B[39m"),cyan:q("\x1B[36m","\x1B[39m"),white:q("\x1B[37m","\x1B[39m"),gray:q("\x1B[90m","\x1B[39m"),bgBlack:q("\x1B[40m","\x1B[49m"),bgRed:q("\x1B[41m","\x1B[49m"),bgGreen:q("\x1B[42m","\x1B[49m"),bgYellow:q("\x1B[43m","\x1B[49m"),bgBlue:q("\x1B[44m","\x1B[49m"),bgMagenta:q("\x1B[45m","\x1B[49m"),bgCyan:q("\x1B[46m","\x1B[49m"),bgWhite:q("\x1B[47m","\x1B[49m"),blackBright:q("\x1B[90m","\x1B[39m"),redBright:q("\x1B[91m","\x1B[39m"),greenBright:q("\x1B[92m","\x1B[39m"),yellowBright:q("\x1B[93m","\x1B[39m"),blueBright:q("\x1B[94m","\x1B[39m"),magentaBright:q("\x1B[95m","\x1B[39m"),cyanBright:q("\x1B[96m","\x1B[39m"),whiteBright:q("\x1B[97m","\x1B[39m"),bgBlackBright:q("\x1B[100m","\x1B[49m"),bgRedBright:q("\x1B[101m","\x1B[49m"),bgGreenBright:q("\x1B[102m","\x1B[49m"),bgYellowBright:q("\x1B[103m","\x1B[49m"),bgBlueBright:q("\x1B[104m","\x1B[49m"),bgMagentaBright:q("\x1B[105m","\x1B[49m"),bgCyanBright:q("\x1B[106m","\x1B[49m"),bgWhiteBright:q("\x1B[107m","\x1B[49m")}};K1.exports=Z4();K1.exports.createColors=Z4});var W1=v((D0,Q4)=>{var j1={to(z,q){if(!q)return`\x1B[${z+1}G`;return`\x1B[${q+1};${z+1}H`},move(z,q){let B="";if(z<0)B+=`\x1B[${-z}D`;else if(z>0)B+=`\x1B[${z}C`;if(q<0)B+=`\x1B[${-q}A`;else if(q>0)B+=`\x1B[${q}B`;return B},up:(z=1)=>`\x1B[${z}A`,down:(z=1)=>`\x1B[${z}B`,forward:(z=1)=>`\x1B[${z}C`,backward:(z=1)=>`\x1B[${z}D`,nextLine:(z=1)=>"\x1B[E".repeat(z),prevLine:(z=1)=>"\x1B[F".repeat(z),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"},m9={up:(z=1)=>"\x1B[S".repeat(z),down:(z=1)=>"\x1B[T".repeat(z)},l9={screen:"\x1B[2J",up:(z=1)=>"\x1B[1J".repeat(z),down:(z=1)=>"\x1B[J".repeat(z),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines(z){let q="";for(let B=0;B<z;B++)q+=this.line+(B<z-1?j1.up():"");if(z)q+=j1.left;return q}};Q4.exports={cursor:j1,scroll:m9,erase:l9,beep:"\x07"}});var t1=c(e1(),1),{program:g,createCommand:J0,createArgument:Y0,createOption:Z0,CommanderError:Q0,InvalidArgumentError:X0,InvalidOptionArgumentError:L0,Command:G0,Argument:H0,Option:T0,Help:S0}=t1.default;var s={name:"@mintplex-labs/anything-llm-cli",version:"0.0.8",description:"A CLI tool to interact with AnythingLLM from the terminal",type:"module",bin:{any:"dist/index.js"},files:["dist/index.js","README.md"],keywords:["anythingllm","llm","cli","ai"],repository:{type:"git",url:"https://github.com/Mintplex-Labs/anything-llm-cli"},license:"MIT",scripts:{setup:"cp .env.example .env.local && bun install",start:"bun run src/index.ts",build:"bun build --compile --minify --outfile=dist/any src/index.ts","build:npm":"bun build --minify --target=node --banner '#!/usr/bin/env node' --outfile=dist/index.js src/index.ts",prepublishOnly:"bun run build:npm",lint:"bunx biome check --write .","build:linux-x64":"bun build --compile --minify --target=bun-linux-x64 --outfile=dist/any-linux-x64 src/index.ts","build:linux-arm64":"bun build --compile --minify --target=bun-linux-arm64 --outfile=dist/any-linux-arm64 src/index.ts","build:windows-x64":"bun build --compile --minify --target=bun-windows-x64 --outfile=dist/any-windows-x64.exe src/index.ts","build:darwin-x64":"bun build --compile --minify --target=bun-darwin-x64 --outfile=dist/any-darwin-x64 src/index.ts","build:darwin-arm64":"bun build --compile --minify --target=bun-darwin-arm64 --outfile=dist/any-darwin-arm64 src/index.ts","build:all":"bun run build:linux-x64 && bun run build:linux-arm64 && bun run build:windows-x64 && bun run build:darwin-x64 && bun run build:darwin-arm64"},devDependencies:{"@biomejs/biome":"2.3.15","@types/bun":"latest",lefthook:"^2.1.1"},peerDependencies:{typescript:"^5"},dependencies:{"@clack/prompts":"^1.0.1",commander:"^14.0.3"}};import{readFileSync as k9}from"node:fs";import{basename as O9,extname as f9,resolve as v9}from"node:path";class o{apiKey=process.env.ANYTHINGLLM_API_KEY||"";baseUrl=new URL("http://localhost:3001");static fileToAttachment(z){let q={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp"},B=v9(z),J=f9(B).toLowerCase(),Y=q[J];if(!Y)console.error(`Unsupported file type: ${J}
28
+ Supported: ${Object.keys(q).join(", ")}`),process.exit(1);let Q=k9(B).toString("base64");return{name:O9(B),mime:Y,contentString:`data:${Y};base64,${Q}`}}streamResponse(z,q){let B=this;return{[Symbol.asyncIterator](){return async function*(){let J=new URL(z,B.baseUrl),Y=await fetch(J.href,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${B.apiKey}`},body:JSON.stringify(q)});if(!Y.ok||!Y.body)throw Error(`Stream request failed with status ${Y.status}`);let Z=new TextDecoder,Q="";for await(let X of Y.body){Q+=Z.decode(X,{stream:!0});let L=Q.split(`
29
29
 
30
- `);$=G.pop()||"";for(let Y of G){let B=Y.trim();if(!B.startsWith("data:"))continue;yield JSON.parse(B.slice(5).trim())}}}()}}}async callApi(q,z={}){try{let J=new URL(q,this.baseUrl),Q=await fetch(J.href,{method:z.method||"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`},body:z.body?JSON.stringify(z.body):void 0});if(!Q.ok){let Z=await Q.text();throw Error(`API request failed with status ${Q.status}: ${Z}`)}return{ok:!0,data:await Q.json()}}catch(J){return{ok:!1,error:J instanceof Error?J.message:String(J)}}}admin={};documents={};systemSettings={};embeds={};workspaces={create:async(q)=>{return this.callApi("api/v1/workspace/new",{method:"POST",body:{...q,openAiTemp:q.temperature,openAiHistory:q.historyMessageCount,openAiPrompt:q.systemPrompt,chatMode:q.mode}})},list:async()=>{return this.callApi("api/v1/workspaces")},get:async(q)=>{return this.callApi(`api/v1/workspace/${q.slug}`)},chat:async(q)=>{return this.callApi(`api/v1/workspace/${q.slug}/chat`,{method:"POST",body:{message:q.message,mode:q.mode??"chat",attachments:q.attachments}})},streamChat:(q)=>{return this.streamResponse(`api/v1/workspace/${q.slug}/stream-chat`,{message:q.message,mode:q.mode??"chat",attachments:q.attachments})}};threads={create:async(q)=>{return this.callApi(`api/v1/workspace/${q.workspaceSlug}/thread/new`,{method:"POST",body:{...q,name:q.title}})},chat:async(q)=>{return this.callApi(`api/v1/workspace/${q.workspaceSlug}/thread/${q.threadSlug}/chat`,{method:"POST",body:{message:q.message,mode:q.mode??"chat",attachments:q.attachments}})},streamChat:(q)=>{return this.streamResponse(`api/v1/workspace/${q.workspaceSlug}/thread/${q.threadSlug}/stream-chat`,{message:q.message,mode:q.mode??"chat",attachments:q.attachments})},getMessages:async(q)=>{let z=q.threadSlug?`api/v1/workspace/${q.workspaceSlug}/thread/${q.threadSlug}/chats`:`api/v1/workspace/${q.workspaceSlug}/chats`;return this.callApi(z)}};constructor({apiKey:q,baseUrl:z}){this.apiKey=q||this.apiKey,this.baseUrl=z?new URL(z):this.baseUrl}}function G4(){return new Promise((q)=>{let z="";process.stdin.setEncoding("utf-8"),process.stdin.on("data",(J)=>{z+=J}),process.stdin.on("end",()=>q(z))})}var H4="anythingllm-cli-default-workspace";async function M4(q,z){let J=q.join(" "),Q=process.env.ANYTHING_LLM_API_KEY;if(!Q)console.error("ANYTHING_LLM_API_KEY environment variable is not set"),process.exit(1);let X="";if(process.stdin.isTTY===!1)X=await G4();let Z=X?`${X} ${J}`:J,$=z.attach?z.attach.map(b.fileToAttachment):void 0,_=new b({apiKey:Q,baseUrl:process.env.ANYTHING_LLM_BASE_URL}),G=z.workspace||H4;if(G===H4){let U=await _.workspaces.get({slug:G});if(!U.ok)console.error(`Failed to get workspace "${G}": ${U.error}`),process.exit(1);if(U.data.workspace.length===0){let W=await _.workspaces.create({name:"AnythingLLM CLI Default Workspace",systemPrompt:"You are a helpful assistant responding to prompts from the AnythingLLM CLI tool. You will sometimes receive context passed in from the stdinput."});if(!W.ok)console.error(`Failed to create workspace: ${W.error}`),process.exit(1)}}let Y=z.thread;if(z.newThread){let U=await _.threads.create({workspaceSlug:G,title:`AnythingLLM CLI Thread - ${new Date().toLocaleString()}`});if(!U.ok)console.error(`Failed to create thread: ${U.error}`),process.exit(1);Y=U.data.thread.slug}if(!z.stream){let U=Y?await _.threads.chat({threadSlug:Y,message:Z,workspaceSlug:G,attachments:$}):await _.workspaces.chat({slug:G,message:Z,attachments:$});if(!U.ok)console.error(`LLM request failed: ${U.error}`),process.exit(1);process.stdout.write(`${U.data.textResponse}
31
- `);return}let B=Y?_.threads.streamChat({workspaceSlug:G,threadSlug:Y,mode:"chat",message:Z,attachments:$}):_.workspaces.streamChat({slug:G,mode:"chat",message:Z,attachments:$}),H=process.stdout.isTTY===!0,E=H?"\x1B[2m":"",L=H?"\x1B[0m":"",S=!1,N="",C=!1,j=()=>{if(!S)return;if(!H&&N)process.stdout.write(`${N}
30
+ `);Q=L.pop()||"";for(let G of L){let H=G.trim();if(!H.startsWith("data:"))continue;yield JSON.parse(H.slice(5).trim())}}}()}}}async callApi(z,q={}){try{let B=new URL(z,this.baseUrl),J=await fetch(B.href,{method:q.method||"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`},body:q.body?JSON.stringify(q.body):void 0});if(!J.ok){let Z=await J.text();throw Error(`API request failed with status ${J.status}: ${Z}`)}return{ok:!0,data:await J.json()}}catch(B){return{ok:!1,error:B instanceof Error?B.message:String(B)}}}admin={};documents={};systemSettings={};embeds={};workspaces={create:async(z)=>{return this.callApi("api/v1/workspace/new",{method:"POST",body:{...z,openAiTemp:z.temperature,openAiHistory:z.historyMessageCount,openAiPrompt:z.systemPrompt,chatMode:z.mode}})},list:async()=>{return this.callApi("api/v1/workspaces")},get:async(z)=>{return this.callApi(`api/v1/workspace/${z.slug}`)},chat:async(z)=>{return this.callApi(`api/v1/workspace/${z.slug}/chat`,{method:"POST",body:{message:z.message,mode:z.mode??"chat",attachments:z.attachments}})},streamChat:(z)=>{return this.streamResponse(`api/v1/workspace/${z.slug}/stream-chat`,{message:z.message,mode:z.mode??"chat",attachments:z.attachments})}};threads={create:async(z)=>{return this.callApi(`api/v1/workspace/${z.workspaceSlug}/thread/new`,{method:"POST",body:{...z,name:z.title}})},chat:async(z)=>{return this.callApi(`api/v1/workspace/${z.workspaceSlug}/thread/${z.threadSlug}/chat`,{method:"POST",body:{message:z.message,mode:z.mode??"chat",attachments:z.attachments}})},streamChat:(z)=>{return this.streamResponse(`api/v1/workspace/${z.workspaceSlug}/thread/${z.threadSlug}/stream-chat`,{message:z.message,mode:z.mode??"chat",attachments:z.attachments})},getMessages:async(z)=>{let q=z.threadSlug?`api/v1/workspace/${z.workspaceSlug}/thread/${z.threadSlug}/chats`:`api/v1/workspace/${z.workspaceSlug}/chats`;return this.callApi(q)}};constructor({apiKey:z,baseUrl:q}){this.apiKey=z||this.apiKey,this.baseUrl=q?new URL(q):this.baseUrl}}function z4(){return new Promise((z)=>{let q="";process.stdin.setEncoding("utf-8"),process.stdin.on("data",(B)=>{q+=B}),process.stdin.on("end",()=>z(q))})}var q4="anythingllm-cli-default-workspace";async function B4(z,q){let B=z.join(" "),J=process.env.ANYTHING_LLM_API_KEY;if(!J)console.error("ANYTHING_LLM_API_KEY environment variable is not set"),process.exit(1);let Y="";if(!process.stdin.isTTY)Y=await z4();let Z=Y?`${Y} ${B}`:B,Q=q.attach?q.attach.map(o.fileToAttachment):void 0,X=new o({apiKey:J,baseUrl:process.env.ANYTHING_LLM_BASE_URL}),L=q.workspace||q4;if(L===q4){let K=await X.workspaces.get({slug:L});if(!K.ok)console.error(`Failed to get workspace "${L}": ${K.error}`),process.exit(1);if(K.data.workspace.length===0){let P=await X.workspaces.create({name:"AnythingLLM CLI Default Workspace",systemPrompt:"You are a helpful assistant responding to prompts from the AnythingLLM CLI tool. You will sometimes receive context passed in from the stdinput."});if(!P.ok)console.error(`Failed to create workspace: ${P.error}`),process.exit(1)}}let G=q.thread;if(q.newThread){let K=await X.threads.create({workspaceSlug:L,title:`AnythingLLM CLI Thread - ${new Date().toLocaleString()}`});if(!K.ok)console.error(`Failed to create thread: ${K.error}`),process.exit(1);G=K.data.thread.slug}if(!q.stream){let K=G?await X.threads.chat({threadSlug:G,message:Z,workspaceSlug:L,attachments:Q}):await X.workspaces.chat({slug:L,message:Z,attachments:Q});if(!K.ok)console.error(`LLM request failed: ${K.error}`),process.exit(1);process.stdout.write(`${K.data.textResponse}
31
+ `);return}let H=G?X.threads.streamChat({workspaceSlug:L,threadSlug:G,mode:"chat",message:Z,attachments:Q}):X.workspaces.streamChat({slug:L,mode:"chat",message:Z,attachments:Q}),T=process.stdout.isTTY===!0,j=T?"\x1B[2m":"",N=T?"\x1B[0m":"",U=!1,S="",W=!1,M=()=>{if(!U)return;if(!T&&S)process.stdout.write(`${S}
32
32
  `);else process.stdout.write(`
33
- `);S=!1,N=""},F=(U)=>{if(j(),!C)process.stdout.write(`
34
- `),C=!0;process.stdout.write(U)};for await(let U of B)if(U.type==="textResponseChunk")F(U.textResponse);else if(U.type==="agentThought")j(),process.stdout.write(`${E}${U.thought}${L}
35
- `);else if(U.type==="textResponse"&&U.textResponse){let W=U.textResponse;if(W.type==="toolCallInvocation"){if(H)process.stdout.write(`\r\x1B[K${E}${W.content}${L}`);N=W.content,S=!0}else if(W.type==="textResponseChunk")F(W.content)}process.stdout.write(`
36
- `)}var L6=process.env.ANYTHING_LLM_DEFAULT_WORKSPACE_SLUG;function T4(q){q.command("prompt").alias("p").description("Send a prompt").argument("<message...>","The prompt message to send").option("-w, --workspace <slug>","Workspace slug to use. Defaults to ANYTHING_LLM_DEFAULT_WORKSPACE_SLUG environment variable.",L6).option("-t, --thread [slug]","Thread slug to use. If not provided the default thread for the workspace will be used.").option("-S, --no-stream","Disable streaming responses").option("--nt, --new-thread","Start a new thread for this conversation.").option("-a, --attach <path...>","Attach image files to the prompt (png, jpg, jpeg, gif, webp)").action(M4)}async function j6(){let q=process.env.ANYTHING_LLM_BASE_URL||"http://localhost:3001";try{return(await fetch(`${q}/api/ping`,{method:"GET",signal:AbortSignal.timeout(2000)})).ok}catch{return!1}}async function U4(){let q=await j6(),z=(M,R,I,K)=>`\x1B[1;38;2;${M};${R};${I}m${K}\x1B[0m`,J=(M)=>`\x1B[38;5;243m${M}\x1B[0m`,Q=(M)=>`\x1B[1;38;5;214m${M}\x1B[0m`,X=q?(M)=>z(90,200,170,M):(M)=>z(200,60,60,M),Z=(M,R,I)=>Math.round(M+(R-M)*I),$=q?(M,R,I)=>{let K=M/(R-1);return z(Z(70,123,K),Z(255,207,K),Z(200,224,K),I)}:(M,R,I)=>{let K=M/(R-1);return z(Z(180,220,K),Z(40,70,K),Z(40,60,K),I)},_=[" █████ ███ ██ ██ ██ ████████ ██ ██ ██ ███ ██ ██████","██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██","███████ ██ ██ ██ ████ ██ █████ ██ ██ ██ ██ ██ ███","██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ████ ██ ██","██ ██ ██ ███ ██ ██ ██ ██ ██ ██ ███ ██████"],G=["██ ██ ██ ██","██ ██ ███ ███","██ ██ ██ █ ██","██ ██ ██ ██","███████ ███████ ██ ██"],Y="✦ Chat with your AnythingLLM instance from the terminal ✦",B=`v${O.version}`,H=Math.max(..._.map((M)=>M.length))+2,E=(M,R)=>M+" ".repeat(Math.max(0,R-M.length)),L=(M,R)=>`${X("║")} ${M}${" ".repeat(Math.max(0,H-R))} ${X("║")}`,S=()=>L("",0),N=X(`╔${"═".repeat(H+2)}╗`),C=X(`╚${"═".repeat(H+2)}╝`),j=["",N,S()],F=_.length+G.length;for(let M=0;M<_.length;M++){let R=_[M];j.push(L($(M,F,E(R,H)),H))}j.push(S());let U=G[0].length,W=Math.floor((H-U)/2);for(let M=0;M<G.length;M++){let R=_.length+M,I=G[M],K=" ".repeat(W);if(M===0){let V=W+I.length+2+B.length;j.push(L(`${K}${$(R,F,I)} ${J(B)}`,V))}else j.push(L(K+$(R,F,I),W+I.length))}j.push(S());let m=Math.floor((H-57)/2);if(j.push(L(" ".repeat(m)+J("✦ Chat with your AnythingLLM instance from the terminal ✦"),m+57)),!q){j.push(S());let M=["Could not connect to your AnythingLLM instance.","Ensure it is running and these env vars are set:"];for(let V of M){let i=Math.max(0,Math.floor((H-V.length)/2));j.push(L(" ".repeat(i)+Q(V),i+V.length))}j.push(S());let R=["ANYTHING_LLM_API_KEY - API key for your instance","ANYTHING_LLM_BASE_URL - Instance URL"],I=Math.max(...R.map((V)=>V.length)),K=Math.max(0,Math.floor((H-I)/2));for(let V of R)j.push(L(" ".repeat(K)+Q(V),K+V.length))}return j.push(S(),C,""),j.join(`
37
- `)}w.name("any").description("A simple CLI tool to interact with AnythingLLM").version(O.version).addHelpText("before",await U4());T4(w);w.parse();
33
+ `);U=!1,S=""},V=(K)=>{if(M(),!W)process.stdout.write(`
34
+ `),W=!0;process.stdout.write(K)};for await(let K of H)if(K.type==="textResponseChunk")V(K.textResponse);else if(K.type==="agentThought")M(),process.stdout.write(`${j}${K.thought}${N}
35
+ `);else if(K.type==="textResponse"&&K.textResponse){let P=K.textResponse;if(P.type==="toolCallInvocation"){if(T)process.stdout.write(`\r\x1B[K${j}${P.content}${N}`);S=P.content,U=!0}else if(P.type==="textResponseChunk")V(P.content)}process.stdout.write(`
36
+ `)}var h9=process.env.ANYTHING_LLM_DEFAULT_WORKSPACE_SLUG;function J4(z){z.command("prompt").alias("p").description("Send a prompt").argument("<message...>","The prompt message to send").option("-w, --workspace <slug>","Workspace slug to use. Defaults to ANYTHING_LLM_DEFAULT_WORKSPACE_SLUG environment variable.",h9).option("-t, --thread [slug]","Thread slug to use. If not provided the default thread for the workspace will be used.").option("-S, --no-stream","Disable streaming responses").option("--nt, --new-thread","Start a new thread for this conversation.").option("-a, --attach <path...>","Attach image files to the prompt (png, jpg, jpeg, gif, webp)").action(B4)}import{existsSync as h3}from"node:fs";import{readFile as u3,writeFile as g3}from"node:fs/promises";import{homedir as c3}from"node:os";import{join as G1}from"node:path";var u=c(I1(),1);import{stdout as d9,stdin as p9}from"node:process";var F=c(W1(),1);import i9 from"node:readline";function D1(z,q,B){if(!B.some((Q)=>!Q.disabled))return z;let J=z+q,Y=Math.max(B.length-1,0),Z=J<0?Y:J>Y?0:J;return B[Z].disabled?D1(Z,q<0?-1:1,B):Z}var n9=(z)=>z===161||z===164||z===167||z===168||z===170||z===173||z===174||z>=176&&z<=180||z>=182&&z<=186||z>=188&&z<=191||z===198||z===208||z===215||z===216||z>=222&&z<=225||z===230||z>=232&&z<=234||z===236||z===237||z===240||z===242||z===243||z>=247&&z<=250||z===252||z===254||z===257||z===273||z===275||z===283||z===294||z===295||z===299||z>=305&&z<=307||z===312||z>=319&&z<=322||z===324||z>=328&&z<=331||z===333||z===338||z===339||z===358||z===359||z===363||z===462||z===464||z===466||z===468||z===470||z===472||z===474||z===476||z===593||z===609||z===708||z===711||z>=713&&z<=715||z===717||z===720||z>=728&&z<=731||z===733||z===735||z>=768&&z<=879||z>=913&&z<=929||z>=931&&z<=937||z>=945&&z<=961||z>=963&&z<=969||z===1025||z>=1040&&z<=1103||z===1105||z===8208||z>=8211&&z<=8214||z===8216||z===8217||z===8220||z===8221||z>=8224&&z<=8226||z>=8228&&z<=8231||z===8240||z===8242||z===8243||z===8245||z===8251||z===8254||z===8308||z===8319||z>=8321&&z<=8324||z===8364||z===8451||z===8453||z===8457||z===8467||z===8470||z===8481||z===8482||z===8486||z===8491||z===8531||z===8532||z>=8539&&z<=8542||z>=8544&&z<=8555||z>=8560&&z<=8569||z===8585||z>=8592&&z<=8601||z===8632||z===8633||z===8658||z===8660||z===8679||z===8704||z===8706||z===8707||z===8711||z===8712||z===8715||z===8719||z===8721||z===8725||z===8730||z>=8733&&z<=8736||z===8739||z===8741||z>=8743&&z<=8748||z===8750||z>=8756&&z<=8759||z===8764||z===8765||z===8776||z===8780||z===8786||z===8800||z===8801||z>=8804&&z<=8807||z===8810||z===8811||z===8814||z===8815||z===8834||z===8835||z===8838||z===8839||z===8853||z===8857||z===8869||z===8895||z===8978||z>=9312&&z<=9449||z>=9451&&z<=9547||z>=9552&&z<=9587||z>=9600&&z<=9615||z>=9618&&z<=9621||z===9632||z===9633||z>=9635&&z<=9641||z===9650||z===9651||z===9654||z===9655||z===9660||z===9661||z===9664||z===9665||z>=9670&&z<=9672||z===9675||z>=9678&&z<=9681||z>=9698&&z<=9701||z===9711||z===9733||z===9734||z===9737||z===9742||z===9743||z===9756||z===9758||z===9792||z===9794||z===9824||z===9825||z>=9827&&z<=9829||z>=9831&&z<=9834||z===9836||z===9837||z===9839||z===9886||z===9887||z===9919||z>=9926&&z<=9933||z>=9935&&z<=9939||z>=9941&&z<=9953||z===9955||z===9960||z===9961||z>=9963&&z<=9969||z===9972||z>=9974&&z<=9977||z===9979||z===9980||z===9982||z===9983||z===10045||z>=10102&&z<=10111||z>=11094&&z<=11097||z>=12872&&z<=12879||z>=57344&&z<=63743||z>=65024&&z<=65039||z===65533||z>=127232&&z<=127242||z>=127248&&z<=127277||z>=127280&&z<=127337||z>=127344&&z<=127373||z===127375||z===127376||z>=127387&&z<=127404||z>=917760&&z<=917999||z>=983040&&z<=1048573||z>=1048576&&z<=1114109,r9=(z)=>z===12288||z>=65281&&z<=65376||z>=65504&&z<=65510,s9=(z)=>z>=4352&&z<=4447||z===8986||z===8987||z===9001||z===9002||z>=9193&&z<=9196||z===9200||z===9203||z===9725||z===9726||z===9748||z===9749||z>=9800&&z<=9811||z===9855||z===9875||z===9889||z===9898||z===9899||z===9917||z===9918||z===9924||z===9925||z===9934||z===9940||z===9962||z===9970||z===9971||z===9973||z===9978||z===9981||z===9989||z===9994||z===9995||z===10024||z===10060||z===10062||z>=10067&&z<=10069||z===10071||z>=10133&&z<=10135||z===10160||z===10175||z===11035||z===11036||z===11088||z===11093||z>=11904&&z<=11929||z>=11931&&z<=12019||z>=12032&&z<=12245||z>=12272&&z<=12287||z>=12289&&z<=12350||z>=12353&&z<=12438||z>=12441&&z<=12543||z>=12549&&z<=12591||z>=12593&&z<=12686||z>=12688&&z<=12771||z>=12783&&z<=12830||z>=12832&&z<=12871||z>=12880&&z<=19903||z>=19968&&z<=42124||z>=42128&&z<=42182||z>=43360&&z<=43388||z>=44032&&z<=55203||z>=63744&&z<=64255||z>=65040&&z<=65049||z>=65072&&z<=65106||z>=65108&&z<=65126||z>=65128&&z<=65131||z>=94176&&z<=94180||z===94192||z===94193||z>=94208&&z<=100343||z>=100352&&z<=101589||z>=101632&&z<=101640||z>=110576&&z<=110579||z>=110581&&z<=110587||z===110589||z===110590||z>=110592&&z<=110882||z===110898||z>=110928&&z<=110930||z===110933||z>=110948&&z<=110951||z>=110960&&z<=111355||z===126980||z===127183||z===127374||z>=127377&&z<=127386||z>=127488&&z<=127490||z>=127504&&z<=127547||z>=127552&&z<=127560||z===127568||z===127569||z>=127584&&z<=127589||z>=127744&&z<=127776||z>=127789&&z<=127797||z>=127799&&z<=127868||z>=127870&&z<=127891||z>=127904&&z<=127946||z>=127951&&z<=127955||z>=127968&&z<=127984||z===127988||z>=127992&&z<=128062||z===128064||z>=128066&&z<=128252||z>=128255&&z<=128317||z>=128331&&z<=128334||z>=128336&&z<=128359||z===128378||z===128405||z===128406||z===128420||z>=128507&&z<=128591||z>=128640&&z<=128709||z===128716||z>=128720&&z<=128722||z>=128725&&z<=128727||z>=128732&&z<=128735||z===128747||z===128748||z>=128756&&z<=128764||z>=128992&&z<=129003||z===129008||z>=129292&&z<=129338||z>=129340&&z<=129349||z>=129351&&z<=129535||z>=129648&&z<=129660||z>=129664&&z<=129672||z>=129680&&z<=129725||z>=129727&&z<=129733||z>=129742&&z<=129755||z>=129760&&z<=129768||z>=129776&&z<=129784||z>=131072&&z<=196605||z>=196608&&z<=262141,V1=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y,t=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,z1=/\t{1,1000}/y,P1=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu,q1=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,o9=/\p{M}+/gu,a9={limit:1/0,ellipsis:""},T4=(z,q={},B={})=>{let J=q.limit??1/0,Y=q.ellipsis??"",Z=q?.ellipsisWidth??(Y?T4(Y,a9,B).width:0),Q=B.ansiWidth??0,X=B.controlWidth??0,L=B.tabWidth??8,G=B.ambiguousWidth??1,H=B.emojiWidth??2,T=B.fullWidthWidth??2,j=B.regularWidth??1,N=B.wideWidth??2,U=0,S=0,W=z.length,M=0,V=!1,K=W,P=Math.max(0,J-Z),x=0,R=0,_=0,$=0;z:for(;;){if(R>x||S>=W&&S>U){let E=z.slice(x,R)||z.slice(U,S);M=0;for(let C of E.replaceAll(o9,"")){let A=C.codePointAt(0)||0;if(r9(A)?$=T:s9(A)?$=N:G!==j&&n9(A)?$=G:$=j,_+$>P&&(K=Math.min(K,Math.max(x,U)+M)),_+$>J){V=!0;break z}M+=C.length,_+=$}x=R=0}if(S>=W)break;if(q1.lastIndex=S,q1.test(z)){if(M=q1.lastIndex-S,$=M*j,_+$>P&&(K=Math.min(K,S+Math.floor((P-_)/j))),_+$>J){V=!0;break}_+=$,x=U,R=S,S=U=q1.lastIndex;continue}if(V1.lastIndex=S,V1.test(z)){if(_+Q>P&&(K=Math.min(K,S)),_+Q>J){V=!0;break}_+=Q,x=U,R=S,S=U=V1.lastIndex;continue}if(t.lastIndex=S,t.test(z)){if(M=t.lastIndex-S,$=M*X,_+$>P&&(K=Math.min(K,S+Math.floor((P-_)/X))),_+$>J){V=!0;break}_+=$,x=U,R=S,S=U=t.lastIndex;continue}if(z1.lastIndex=S,z1.test(z)){if(M=z1.lastIndex-S,$=M*L,_+$>P&&(K=Math.min(K,S+Math.floor((P-_)/L))),_+$>J){V=!0;break}_+=$,x=U,R=S,S=U=z1.lastIndex;continue}if(P1.lastIndex=S,P1.test(z)){if(_+H>P&&(K=Math.min(K,S)),_+H>J){V=!0;break}_+=H,x=U,R=S,S=U=P1.lastIndex;continue}S+=1}return{width:V?P:_,index:V?K:W,truncated:V,ellipsed:V&&J>=Z}},e9={limit:1/0,ellipsis:"",ellipsisWidth:0},d=(z,q={})=>T4(z,e9,q).width,J1="\x1B",S4="›",t9=39,x1="\x07",U4="[",z3="]",_4="m",E1=`${z3}8;;`,X4=new RegExp(`(?:\\${U4}(?<code>\\d+)m|\\${E1}(?<uri>.*)${x1})`,"y"),q3=(z)=>{if(z>=30&&z<=37||z>=90&&z<=97)return 39;if(z>=40&&z<=47||z>=100&&z<=107)return 49;if(z===1||z===2)return 22;if(z===3)return 23;if(z===4)return 24;if(z===7)return 27;if(z===8)return 28;if(z===9)return 29;if(z===0)return 0},L4=(z)=>`${J1}${U4}${z}${_4}`,G4=(z)=>`${J1}${E1}${z}${x1}`,B3=(z)=>z.map((q)=>d(q)),N1=(z,q,B)=>{let J=q[Symbol.iterator](),Y=!1,Z=!1,Q=z.at(-1),X=Q===void 0?0:d(Q),L=J.next(),G=J.next(),H=0;for(;!L.done;){let T=L.value,j=d(T);X+j<=B?z[z.length-1]+=T:(z.push(T),X=0),(T===J1||T===S4)&&(Y=!0,Z=q.startsWith(E1,H+1)),Y?Z?T===x1&&(Y=!1,Z=!1):T===_4&&(Y=!1):(X+=j,X===B&&!G.done&&(z.push(""),X=0)),L=G,G=J.next(),H+=T.length}Q=z.at(-1),!X&&Q!==void 0&&Q.length>0&&z.length>1&&(z[z.length-2]+=z.pop())},J3=(z)=>{let q=z.split(" "),B=q.length;for(;B>0&&!(d(q[B-1])>0);)B--;return B===q.length?z:q.slice(0,B).join(" ")+q.slice(B).join("")},Y3=(z,q,B={})=>{if(B.trim!==!1&&z.trim()==="")return"";let J="",Y,Z,Q=z.split(" "),X=B3(Q),L=[""];for(let[U,S]of Q.entries()){B.trim!==!1&&(L[L.length-1]=(L.at(-1)??"").trimStart());let W=d(L.at(-1)??"");if(U!==0&&(W>=q&&(B.wordWrap===!1||B.trim===!1)&&(L.push(""),W=0),(W>0||B.trim===!1)&&(L[L.length-1]+=" ",W++)),B.hard&&X[U]>q){let M=q-W,V=1+Math.floor((X[U]-M-1)/q);Math.floor((X[U]-1)/q)<V&&L.push(""),N1(L,S,q);continue}if(W+X[U]>q&&W>0&&X[U]>0){if(B.wordWrap===!1&&W<q){N1(L,S,q);continue}L.push("")}if(W+X[U]>q&&B.wordWrap===!1){N1(L,S,q);continue}L[L.length-1]+=S}B.trim!==!1&&(L=L.map((U)=>J3(U)));let G=L.join(`
37
+ `),H=G[Symbol.iterator](),T=H.next(),j=H.next(),N=0;for(;!T.done;){let U=T.value,S=j.value;if(J+=U,U===J1||U===S4){X4.lastIndex=N+1;let M=X4.exec(G)?.groups;if(M?.code!==void 0){let V=Number.parseFloat(M.code);Y=V===t9?void 0:V}else M?.uri!==void 0&&(Z=M.uri.length===0?void 0:M.uri)}let W=Y?q3(Y):void 0;S===`
38
+ `?(Z&&(J+=G4("")),Y&&W&&(J+=L4(W))):U===`
39
+ `&&(Y&&W&&(J+=L4(Y)),Z&&(J+=G4(Z))),N+=U.length,T=j,j=H.next()}return J};function H4(z,q,B){return String(z).normalize().replaceAll(`\r
40
+ `,`
41
+ `).split(`
42
+ `).map((J)=>Y3(J,q,B)).join(`
43
+ `)}var Z3=["up","down","left","right","space","enter","cancel"],k={actions:new Set(Z3),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0};function R4(z,q){if(typeof z=="string")return k.aliases.get(z)===q;for(let B of z)if(B!==void 0&&R4(B,q))return!0;return!1}function Q3(z,q){if(z===q)return;let B=z.split(`
44
+ `),J=q.split(`
45
+ `),Y=Math.max(B.length,J.length),Z=[];for(let Q=0;Q<Y;Q++)B[Q]!==J[Q]&&Z.push(Q);return{lines:Z,numLinesBefore:B.length,numLinesAfter:J.length,numLines:Y}}var E0=globalThis.process.platform.startsWith("win"),b1=Symbol("clack:cancel");function p(z){return z===b1}function B1(z,q){let B=z;B.isTTY&&B.setRawMode(q)}var $4=(z)=>("columns"in z)&&typeof z.columns=="number"?z.columns:80,M4=(z)=>("rows"in z)&&typeof z.rows=="number"?z.rows:20;class i{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";constructor(z,q=!0){let{input:B=p9,output:J=d9,render:Y,signal:Z,...Q}=z;this.opts=Q,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=Y.bind(this),this._track=q,this._abortSignal=Z,this.input=B,this.output=J}unsubscribe(){this._subscribers.clear()}setSubscriber(z,q){let B=this._subscribers.get(z)??[];B.push(q),this._subscribers.set(z,B)}on(z,q){this.setSubscriber(z,{cb:q})}once(z,q){this.setSubscriber(z,{cb:q,once:!0})}emit(z,...q){let B=this._subscribers.get(z)??[],J=[];for(let Y of B)Y.cb(...q),Y.once&&J.push(()=>B.splice(B.indexOf(Y),1));for(let Y of J)Y()}prompt(){return new Promise((z)=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),z(b1);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=i9.createInterface({input:this.input,tabSize:2,prompt:"",escapeCodeTimeout:50,terminal:!0}),this.rl.prompt(),this.opts.initialUserInput!==void 0&&this._setUserInput(this.opts.initialUserInput,!0),this.input.on("keypress",this.onKeypress),B1(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(F.cursor.show),this.output.off("resize",this.render),B1(this.input,!1),z(this.value)}),this.once("cancel",()=>{this.output.write(F.cursor.show),this.output.off("resize",this.render),B1(this.input,!1),z(b1)})})}_isActionKey(z,q){return z==="\t"}_setValue(z){this.value=z,this.emit("value",this.value)}_setUserInput(z,q){this.userInput=z??"",this.emit("userInput",this.userInput),q&&this._track&&this.rl&&(this.rl.write(this.userInput),this._cursor=this.rl.cursor)}_clearUserInput(){this.rl?.write(null,{ctrl:!0,name:"u"}),this._setUserInput("")}onKeypress(z,q){if(this._track&&q.name!=="return"&&(q.name&&this._isActionKey(z,q)&&this.rl?.write(null,{ctrl:!0,name:"h"}),this._cursor=this.rl?.cursor??0,this._setUserInput(this.rl?.line)),this.state==="error"&&(this.state="active"),q?.name&&(!this._track&&k.aliases.has(q.name)&&this.emit("cursor",k.aliases.get(q.name)),k.actions.has(q.name)&&this.emit("cursor",q.name)),z&&(z.toLowerCase()==="y"||z.toLowerCase()==="n")&&this.emit("confirm",z.toLowerCase()==="y"),this.emit("key",z?.toLowerCase(),q),q?.name==="return"){if(this.opts.validate){let B=this.opts.validate(this.value);B&&(this.error=B instanceof Error?B.message:B,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}R4([z,q?.name,q?.sequence],"cancel")&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
46
+ `),B1(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let z=H4(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
47
+ `).length-1;this.output.write(F.cursor.move(-999,z*-1))}render(){let z=H4(this._render(this)??"",process.stdout.columns,{hard:!0,trim:!1});if(z!==this._prevFrame){if(this.state==="initial")this.output.write(F.cursor.hide);else{let q=Q3(this._prevFrame,z),B=M4(this.output);if(this.restoreCursor(),q){let J=Math.max(0,q.numLinesAfter-B),Y=Math.max(0,q.numLinesBefore-B),Z=q.lines.find((Q)=>Q>=J);if(Z===void 0){this._prevFrame=z;return}if(q.lines.length===1){this.output.write(F.cursor.move(0,Z-Y)),this.output.write(F.erase.lines(1));let Q=z.split(`
48
+ `);this.output.write(Q[Z]),this._prevFrame=z,this.output.write(F.cursor.move(0,Q.length-Z-1));return}else if(q.lines.length>1){if(J<Y)Z=J;else{let X=Z-Y;X>0&&this.output.write(F.cursor.move(0,X))}this.output.write(F.erase.down());let Q=z.split(`
49
+ `).slice(Z);this.output.write(Q.join(`
50
+ `)),this._prevFrame=z;return}}this.output.write(F.erase.down())}this.output.write(z),this.state==="initial"&&(this.state="active"),this._prevFrame=z}}}function X3(z,q){if(z===void 0||q.length===0)return 0;let B=q.findIndex((J)=>J.value===z);return B!==-1?B:0}function L3(z,q){return(q.label??String(q.value)).toLowerCase().includes(z.toLowerCase())}function G3(z,q){if(q)return z?q:q[0]}class K4 extends i{filteredOptions;multiple;isNavigating=!1;selectedValues=[];focusedValue;#z=0;#B="";#J;#q;get cursor(){return this.#z}get userInputWithCursor(){if(!this.userInput)return u.default.inverse(u.default.hidden("_"));if(this._cursor>=this.userInput.length)return`${this.userInput}█`;let z=this.userInput.slice(0,this._cursor),[q,...B]=this.userInput.slice(this._cursor);return`${z}${u.default.inverse(q)}${B.join("")}`}get options(){return typeof this.#q=="function"?this.#q():this.#q}constructor(z){super(z),this.#q=z.options;let q=this.options;this.filteredOptions=[...q],this.multiple=z.multiple===!0,this.#J=z.filter??L3;let B;if(z.initialValue&&Array.isArray(z.initialValue)?this.multiple?B=z.initialValue:B=z.initialValue.slice(0,1):!this.multiple&&this.options.length>0&&(B=[this.options[0].value]),B)for(let J of B){let Y=q.findIndex((Z)=>Z.value===J);Y!==-1&&(this.toggleSelected(J),this.#z=Y)}this.focusedValue=this.options[this.#z]?.value,this.on("key",(J,Y)=>this.#Y(J,Y)),this.on("userInput",(J)=>this.#Z(J))}_isActionKey(z,q){return z==="\t"||this.multiple&&this.isNavigating&&q.name==="space"&&z!==void 0&&z!==""}#Y(z,q){let B=q.name==="up",J=q.name==="down",Y=q.name==="return";B||J?(this.#z=D1(this.#z,B?-1:1,this.filteredOptions),this.focusedValue=this.filteredOptions[this.#z]?.value,this.multiple||(this.selectedValues=[this.focusedValue]),this.isNavigating=!0):Y?this.value=G3(this.multiple,this.selectedValues):this.multiple?this.focusedValue!==void 0&&(q.name==="tab"||this.isNavigating&&q.name==="space")?this.toggleSelected(this.focusedValue):this.isNavigating=!1:(this.focusedValue&&(this.selectedValues=[this.focusedValue]),this.isNavigating=!1)}deselectAll(){this.selectedValues=[]}toggleSelected(z){this.filteredOptions.length!==0&&(this.multiple?this.selectedValues.includes(z)?this.selectedValues=this.selectedValues.filter((q)=>q!==z):this.selectedValues=[...this.selectedValues,z]:this.selectedValues=[z])}#Z(z){if(z!==this.#B){this.#B=z;let q=this.options;z?this.filteredOptions=q.filter((Y)=>this.#J(z,Y)):this.filteredOptions=[...q];let B=X3(this.focusedValue,this.filteredOptions);this.#z=D1(B,0,this.filteredOptions);let J=this.filteredOptions[this.#z];J&&!J.disabled?this.focusedValue=J.value:this.focusedValue=void 0,this.multiple||(this.focusedValue!==void 0?this.toggleSelected(this.focusedValue):this.deselectAll())}}}class I4 extends i{options;cursor=0;#z;getGroupItems(z){return this.options.filter((q)=>q.group===z)}isGroupSelected(z){let q=this.getGroupItems(z),B=this.value;return B===void 0?!1:q.every((J)=>B.includes(J.value))}toggleValue(){let z=this.options[this.cursor];if(this.value===void 0&&(this.value=[]),z.group===!0){let q=z.value,B=this.getGroupItems(q);this.isGroupSelected(q)?this.value=this.value.filter((J)=>B.findIndex((Y)=>Y.value===J)===-1):this.value=[...this.value,...B.map((J)=>J.value)],this.value=Array.from(new Set(this.value))}else{let q=this.value.includes(z.value);this.value=q?this.value.filter((B)=>B!==z.value):[...this.value,z.value]}}constructor(z){super(z,!1);let{options:q}=z;this.#z=z.selectableGroups!==!1,this.options=Object.entries(q).flatMap(([B,J])=>[{value:B,group:!0,label:B},...J.map((Y)=>({...Y,group:B}))]),this.value=[...z.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:B})=>B===z.cursorAt),this.#z?0:1),this.on("cursor",(B)=>{switch(B){case"left":case"up":{this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;let J=this.options[this.cursor]?.group===!0;!this.#z&&J&&(this.cursor=this.cursor===0?this.options.length-1:this.cursor-1);break}case"down":case"right":{this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;let J=this.options[this.cursor]?.group===!0;!this.#z&&J&&(this.cursor=this.cursor===this.options.length-1?0:this.cursor+1);break}case"space":this.toggleValue();break}})}}var j4=class extends i{_mask="•";get cursor(){return this._cursor}get masked(){return this.userInput.replaceAll(/./g,this._mask)}get userInputWithCursor(){if(this.state==="submit"||this.state==="cancel")return this.masked;let z=this.userInput;if(this.cursor>=z.length)return`${this.masked}${u.default.inverse(u.default.hidden("_"))}`;let q=this.masked,B=q.slice(0,this.cursor),J=q.slice(this.cursor);return`${B}${u.default.inverse(J[0])}${J.slice(1)}`}clear(){this._clearUserInput()}constructor({mask:z,...q}){super(q),this._mask=z??"•",this.on("userInput",(B)=>{this._setValue(B)})}};class y1 extends i{get userInputWithCursor(){if(this.state==="submit")return this.userInput;let z=this.userInput;if(this.cursor>=z.length)return`${this.userInput}█`;let q=z.slice(0,this.cursor),[B,...J]=z.slice(this.cursor);return`${q}${u.default.inverse(B)}${J.join("")}`}get cursor(){return this._cursor}constructor(z){super({...z,initialUserInput:z.initialUserInput??z.initialValue}),this.on("userInput",(q)=>{this._setValue(q)}),this.on("finalize",()=>{this.value||(this.value=z.defaultValue),this.value===void 0&&(this.value="")})}}var I=c(I1(),1);import w from"node:process";var b4=c(W1(),1);function H3(){return w.platform!=="win32"?w.env.TERM!=="linux":!!w.env.CI||!!w.env.WT_SESSION||!!w.env.TERMINUS_SUBLIME||w.env.ConEmuTask==="{cmd::Cmder}"||w.env.TERM_PROGRAM==="Terminus-Sublime"||w.env.TERM_PROGRAM==="vscode"||w.env.TERM==="xterm-256color"||w.env.TERM==="alacritty"||w.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var T3=H3();var b=(z,q)=>T3?z:q,S3=b("◆","*"),U3=b("■","x"),_3=b("▲","x"),A1=b("◇","o"),g0=b("┌","T"),y=b("│","|"),X1=b("└","—"),c0=b("┐","T"),m0=b("┘","—"),l0=b("●",">"),d0=b("○"," "),p0=b("◻","[•]"),i0=b("◼","[+]"),n0=b("◻","[ ]"),R3=b("▪","•"),W4=b("─","-"),$3=b("╮","+"),M3=b("├","+"),K3=b("╯","+"),I3=b("╰","+"),r0=b("╭","+"),j3=b("●","•"),W3=b("◆","*"),V3=b("▲","!"),P3=b("■","x"),x4=(z)=>{switch(z){case"initial":case"active":return I.default.cyan(S3);case"cancel":return I.default.red(U3);case"error":return I.default.yellow(_3);case"submit":return I.default.green(A1)}};var N3=(z)=>z===161||z===164||z===167||z===168||z===170||z===173||z===174||z>=176&&z<=180||z>=182&&z<=186||z>=188&&z<=191||z===198||z===208||z===215||z===216||z>=222&&z<=225||z===230||z>=232&&z<=234||z===236||z===237||z===240||z===242||z===243||z>=247&&z<=250||z===252||z===254||z===257||z===273||z===275||z===283||z===294||z===295||z===299||z>=305&&z<=307||z===312||z>=319&&z<=322||z===324||z>=328&&z<=331||z===333||z===338||z===339||z===358||z===359||z===363||z===462||z===464||z===466||z===468||z===470||z===472||z===474||z===476||z===593||z===609||z===708||z===711||z>=713&&z<=715||z===717||z===720||z>=728&&z<=731||z===733||z===735||z>=768&&z<=879||z>=913&&z<=929||z>=931&&z<=937||z>=945&&z<=961||z>=963&&z<=969||z===1025||z>=1040&&z<=1103||z===1105||z===8208||z>=8211&&z<=8214||z===8216||z===8217||z===8220||z===8221||z>=8224&&z<=8226||z>=8228&&z<=8231||z===8240||z===8242||z===8243||z===8245||z===8251||z===8254||z===8308||z===8319||z>=8321&&z<=8324||z===8364||z===8451||z===8453||z===8457||z===8467||z===8470||z===8481||z===8482||z===8486||z===8491||z===8531||z===8532||z>=8539&&z<=8542||z>=8544&&z<=8555||z>=8560&&z<=8569||z===8585||z>=8592&&z<=8601||z===8632||z===8633||z===8658||z===8660||z===8679||z===8704||z===8706||z===8707||z===8711||z===8712||z===8715||z===8719||z===8721||z===8725||z===8730||z>=8733&&z<=8736||z===8739||z===8741||z>=8743&&z<=8748||z===8750||z>=8756&&z<=8759||z===8764||z===8765||z===8776||z===8780||z===8786||z===8800||z===8801||z>=8804&&z<=8807||z===8810||z===8811||z===8814||z===8815||z===8834||z===8835||z===8838||z===8839||z===8853||z===8857||z===8869||z===8895||z===8978||z>=9312&&z<=9449||z>=9451&&z<=9547||z>=9552&&z<=9587||z>=9600&&z<=9615||z>=9618&&z<=9621||z===9632||z===9633||z>=9635&&z<=9641||z===9650||z===9651||z===9654||z===9655||z===9660||z===9661||z===9664||z===9665||z>=9670&&z<=9672||z===9675||z>=9678&&z<=9681||z>=9698&&z<=9701||z===9711||z===9733||z===9734||z===9737||z===9742||z===9743||z===9756||z===9758||z===9792||z===9794||z===9824||z===9825||z>=9827&&z<=9829||z>=9831&&z<=9834||z===9836||z===9837||z===9839||z===9886||z===9887||z===9919||z>=9926&&z<=9933||z>=9935&&z<=9939||z>=9941&&z<=9953||z===9955||z===9960||z===9961||z>=9963&&z<=9969||z===9972||z>=9974&&z<=9977||z===9979||z===9980||z===9982||z===9983||z===10045||z>=10102&&z<=10111||z>=11094&&z<=11097||z>=12872&&z<=12879||z>=57344&&z<=63743||z>=65024&&z<=65039||z===65533||z>=127232&&z<=127242||z>=127248&&z<=127277||z>=127280&&z<=127337||z>=127344&&z<=127373||z===127375||z===127376||z>=127387&&z<=127404||z>=917760&&z<=917999||z>=983040&&z<=1048573||z>=1048576&&z<=1114109,D3=(z)=>z===12288||z>=65281&&z<=65376||z>=65504&&z<=65510,b3=(z)=>z>=4352&&z<=4447||z===8986||z===8987||z===9001||z===9002||z>=9193&&z<=9196||z===9200||z===9203||z===9725||z===9726||z===9748||z===9749||z>=9800&&z<=9811||z===9855||z===9875||z===9889||z===9898||z===9899||z===9917||z===9918||z===9924||z===9925||z===9934||z===9940||z===9962||z===9970||z===9971||z===9973||z===9978||z===9981||z===9989||z===9994||z===9995||z===10024||z===10060||z===10062||z>=10067&&z<=10069||z===10071||z>=10133&&z<=10135||z===10160||z===10175||z===11035||z===11036||z===11088||z===11093||z>=11904&&z<=11929||z>=11931&&z<=12019||z>=12032&&z<=12245||z>=12272&&z<=12287||z>=12289&&z<=12350||z>=12353&&z<=12438||z>=12441&&z<=12543||z>=12549&&z<=12591||z>=12593&&z<=12686||z>=12688&&z<=12771||z>=12783&&z<=12830||z>=12832&&z<=12871||z>=12880&&z<=19903||z>=19968&&z<=42124||z>=42128&&z<=42182||z>=43360&&z<=43388||z>=44032&&z<=55203||z>=63744&&z<=64255||z>=65040&&z<=65049||z>=65072&&z<=65106||z>=65108&&z<=65126||z>=65128&&z<=65131||z>=94176&&z<=94180||z===94192||z===94193||z>=94208&&z<=100343||z>=100352&&z<=101589||z>=101632&&z<=101640||z>=110576&&z<=110579||z>=110581&&z<=110587||z===110589||z===110590||z>=110592&&z<=110882||z===110898||z>=110928&&z<=110930||z===110933||z>=110948&&z<=110951||z>=110960&&z<=111355||z===126980||z===127183||z===127374||z>=127377&&z<=127386||z>=127488&&z<=127490||z>=127504&&z<=127547||z>=127552&&z<=127560||z===127568||z===127569||z>=127584&&z<=127589||z>=127744&&z<=127776||z>=127789&&z<=127797||z>=127799&&z<=127868||z>=127870&&z<=127891||z>=127904&&z<=127946||z>=127951&&z<=127955||z>=127968&&z<=127984||z===127988||z>=127992&&z<=128062||z===128064||z>=128066&&z<=128252||z>=128255&&z<=128317||z>=128331&&z<=128334||z>=128336&&z<=128359||z===128378||z===128405||z===128406||z===128420||z>=128507&&z<=128591||z>=128640&&z<=128709||z===128716||z>=128720&&z<=128722||z>=128725&&z<=128727||z>=128732&&z<=128735||z===128747||z===128748||z>=128756&&z<=128764||z>=128992&&z<=129003||z===129008||z>=129292&&z<=129338||z>=129340&&z<=129349||z>=129351&&z<=129535||z>=129648&&z<=129660||z>=129664&&z<=129672||z>=129680&&z<=129725||z>=129727&&z<=129733||z>=129742&&z<=129755||z>=129760&&z<=129768||z>=129776&&z<=129784||z>=131072&&z<=196605||z>=196608&&z<=262141,C1=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y,Y1=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,Z1=/\t{1,1000}/y,F1=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu,Q1=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,x3=/\p{M}+/gu,E3={limit:1/0,ellipsis:""},E4=(z,q={},B={})=>{let J=q.limit??1/0,Y=q.ellipsis??"",Z=q?.ellipsisWidth??(Y?E4(Y,E3,B).width:0),Q=B.ansiWidth??0,X=B.controlWidth??0,L=B.tabWidth??8,G=B.ambiguousWidth??1,H=B.emojiWidth??2,T=B.fullWidthWidth??2,j=B.regularWidth??1,N=B.wideWidth??2,U=0,S=0,W=z.length,M=0,V=!1,K=W,P=Math.max(0,J-Z),x=0,R=0,_=0,$=0;z:for(;;){if(R>x||S>=W&&S>U){let E=z.slice(x,R)||z.slice(U,S);M=0;for(let C of E.replaceAll(x3,"")){let A=C.codePointAt(0)||0;if(D3(A)?$=T:b3(A)?$=N:G!==j&&N3(A)?$=G:$=j,_+$>P&&(K=Math.min(K,Math.max(x,U)+M)),_+$>J){V=!0;break z}M+=C.length,_+=$}x=R=0}if(S>=W)break;if(Q1.lastIndex=S,Q1.test(z)){if(M=Q1.lastIndex-S,$=M*j,_+$>P&&(K=Math.min(K,S+Math.floor((P-_)/j))),_+$>J){V=!0;break}_+=$,x=U,R=S,S=U=Q1.lastIndex;continue}if(C1.lastIndex=S,C1.test(z)){if(_+Q>P&&(K=Math.min(K,S)),_+Q>J){V=!0;break}_+=Q,x=U,R=S,S=U=C1.lastIndex;continue}if(Y1.lastIndex=S,Y1.test(z)){if(M=Y1.lastIndex-S,$=M*X,_+$>P&&(K=Math.min(K,S+Math.floor((P-_)/X))),_+$>J){V=!0;break}_+=$,x=U,R=S,S=U=Y1.lastIndex;continue}if(Z1.lastIndex=S,Z1.test(z)){if(M=Z1.lastIndex-S,$=M*L,_+$>P&&(K=Math.min(K,S+Math.floor((P-_)/L))),_+$>J){V=!0;break}_+=$,x=U,R=S,S=U=Z1.lastIndex;continue}if(F1.lastIndex=S,F1.test(z)){if(_+H>P&&(K=Math.min(K,S)),_+H>J){V=!0;break}_+=H,x=U,R=S,S=U=F1.lastIndex;continue}S+=1}return{width:V?P:_,index:V?K:W,truncated:V,ellipsed:V&&J>=Z}},y3={limit:1/0,ellipsis:"",ellipsisWidth:0},f=(z,q={})=>E4(z,y3,q).width,L1="\x1B",y4="›",C3=39,k1="\x07",C4="[",F3="]",F4="m",O1=`${F3}8;;`,V4=new RegExp(`(?:\\${C4}(?<code>\\d+)m|\\${O1}(?<uri>.*)${k1})`,"y"),w3=(z)=>{if(z>=30&&z<=37||z>=90&&z<=97)return 39;if(z>=40&&z<=47||z>=100&&z<=107)return 49;if(z===1||z===2)return 22;if(z===3)return 23;if(z===4)return 24;if(z===7)return 27;if(z===8)return 28;if(z===9)return 29;if(z===0)return 0},P4=(z)=>`${L1}${C4}${z}${F4}`,N4=(z)=>`${L1}${O1}${z}${k1}`,A3=(z)=>z.map((q)=>f(q)),w1=(z,q,B)=>{let J=q[Symbol.iterator](),Y=!1,Z=!1,Q=z.at(-1),X=Q===void 0?0:f(Q),L=J.next(),G=J.next(),H=0;for(;!L.done;){let T=L.value,j=f(T);X+j<=B?z[z.length-1]+=T:(z.push(T),X=0),(T===L1||T===y4)&&(Y=!0,Z=q.startsWith(O1,H+1)),Y?Z?T===k1&&(Y=!1,Z=!1):T===F4&&(Y=!1):(X+=j,X===B&&!G.done&&(z.push(""),X=0)),L=G,G=J.next(),H+=T.length}Q=z.at(-1),!X&&Q!==void 0&&Q.length>0&&z.length>1&&(z[z.length-2]+=z.pop())},k3=(z)=>{let q=z.split(" "),B=q.length;for(;B>0&&!(f(q[B-1])>0);)B--;return B===q.length?z:q.slice(0,B).join(" ")+q.slice(B).join("")},O3=(z,q,B={})=>{if(B.trim!==!1&&z.trim()==="")return"";let J="",Y,Z,Q=z.split(" "),X=A3(Q),L=[""];for(let[U,S]of Q.entries()){B.trim!==!1&&(L[L.length-1]=(L.at(-1)??"").trimStart());let W=f(L.at(-1)??"");if(U!==0&&(W>=q&&(B.wordWrap===!1||B.trim===!1)&&(L.push(""),W=0),(W>0||B.trim===!1)&&(L[L.length-1]+=" ",W++)),B.hard&&X[U]>q){let M=q-W,V=1+Math.floor((X[U]-M-1)/q);Math.floor((X[U]-1)/q)<V&&L.push(""),w1(L,S,q);continue}if(W+X[U]>q&&W>0&&X[U]>0){if(B.wordWrap===!1&&W<q){w1(L,S,q);continue}L.push("")}if(W+X[U]>q&&B.wordWrap===!1){w1(L,S,q);continue}L[L.length-1]+=S}B.trim!==!1&&(L=L.map((U)=>k3(U)));let G=L.join(`
51
+ `),H=G[Symbol.iterator](),T=H.next(),j=H.next(),N=0;for(;!T.done;){let U=T.value,S=j.value;if(J+=U,U===L1||U===y4){V4.lastIndex=N+1;let M=V4.exec(G)?.groups;if(M?.code!==void 0){let V=Number.parseFloat(M.code);Y=V===C3?void 0:V}else M?.uri!==void 0&&(Z=M.uri.length===0?void 0:M.uri)}let W=Y?w3(Y):void 0;S===`
52
+ `?(Z&&(J+=N4("")),Y&&W&&(J+=P4(W))):U===`
53
+ `&&(Y&&W&&(J+=P4(Y)),Z&&(J+=N4(Z))),N+=U.length,T=j,j=H.next()}return J};function D4(z,q,B){return String(z).normalize().replaceAll(`\r
54
+ `,`
55
+ `).split(`
56
+ `).map((J)=>O3(J,q,B)).join(`
57
+ `)}var O={message:(z=[],{symbol:q=I.default.gray(y),secondarySymbol:B=I.default.gray(y),output:J=process.stdout,spacing:Y=1,withGuide:Z}={})=>{let Q=[],X=Z??k.withGuide,L=X?B:"",G=X?`${q} `:"",H=X?`${B} `:"";for(let j=0;j<Y;j++)Q.push(L);let T=Array.isArray(z)?z:z.split(`
58
+ `);if(T.length>0){let[j,...N]=T;j.length>0?Q.push(`${G}${j}`):Q.push(X?q:"");for(let U of N)U.length>0?Q.push(`${H}${U}`):Q.push(X?B:"")}J.write(`${Q.join(`
59
+ `)}
60
+ `)},info:(z,q)=>{O.message(z,{...q,symbol:I.default.blue(j3)})},success:(z,q)=>{O.message(z,{...q,symbol:I.default.green(W3)})},step:(z,q)=>{O.message(z,{...q,symbol:I.default.green(A1)})},warn:(z,q)=>{O.message(z,{...q,symbol:I.default.yellow(V3)})},warning:(z,q)=>{O.warn(z,q)},error:(z,q)=>{O.message(z,{...q,symbol:I.default.red(P3)})}};var f3=(z)=>I.default.dim(z),v3=(z,q,B)=>{let J={hard:!0,trim:!1},Y=D4(z,q,J).split(`
61
+ `),Z=Y.reduce((L,G)=>Math.max(f(G),L),0),Q=Y.map(B).reduce((L,G)=>Math.max(f(G),L),0),X=q-(Q-Z);return D4(z,X,J)},w4=(z="",q="",B)=>{let J=B?.output??w.stdout,Y=B?.withGuide??k.withGuide,Z=B?.format??f3,Q=["",...v3(z,$4(J)-6,Z).split(`
62
+ `).map(Z),""],X=f(q),L=Math.max(Q.reduce((j,N)=>{let U=f(N);return U>j?U:j},0),X)+2,G=Q.map((j)=>`${I.default.gray(y)} ${j}${" ".repeat(L-f(j))}${I.default.gray(y)}`).join(`
63
+ `),H=Y?`${I.default.gray(y)}
64
+ `:"",T=Y?M3:I3;J.write(`${H}${I.default.green(A1)} ${I.default.reset(q)} ${I.default.gray(W4.repeat(Math.max(L-X-1,1))+$3)}
65
+ ${G}
66
+ ${I.default.gray(T+W4.repeat(L+2)+K3)}
67
+ `)},A4=(z)=>new j4({validate:z.validate,mask:z.mask??R3,signal:z.signal,input:z.input,output:z.output,render(){let q=z.withGuide??k.withGuide,B=`${q?`${I.default.gray(y)}
68
+ `:""}${x4(this.state)} ${z.message}
69
+ `,J=this.userInputWithCursor,Y=this.masked;switch(this.state){case"error":{let Z=q?`${I.default.yellow(y)} `:"",Q=q?`${I.default.yellow(X1)} `:"",X=Y??"";return z.clearOnError&&this.clear(),`${B.trim()}
70
+ ${Z}${X}
71
+ ${Q}${I.default.yellow(this.error)}
72
+ `}case"submit":{let Z=q?`${I.default.gray(y)} `:"",Q=Y?I.default.dim(Y):"";return`${B}${Z}${Q}`}case"cancel":{let Z=q?`${I.default.gray(y)} `:"",Q=Y?I.default.strikethrough(I.default.dim(Y)):"";return`${B}${Z}${Q}${Y&&q?`
73
+ ${I.default.gray(y)}`:""}`}default:{let Z=q?`${I.default.cyan(y)} `:"",Q=q?I.default.cyan(X1):"";return`${B}${Z}${J}
74
+ ${Q}
75
+ `}}}}).prompt();var s0=I.default.magenta;var o0={light:b("─","-"),heavy:b("━","="),block:b("█","#")};var a0=`${I.default.gray(y)} `;var k4=(z)=>new y1({validate:z.validate,placeholder:z.placeholder,defaultValue:z.defaultValue,initialValue:z.initialValue,output:z.output,signal:z.signal,input:z.input,render(){let q=z?.withGuide??k.withGuide,B=`${`${q?`${I.default.gray(y)}
76
+ `:""}${x4(this.state)} `}${z.message}
77
+ `,J=z.placeholder?I.default.inverse(z.placeholder[0])+I.default.dim(z.placeholder.slice(1)):I.default.inverse(I.default.hidden("_")),Y=this.userInput?this.userInputWithCursor:J,Z=this.value??"";switch(this.state){case"error":{let Q=this.error?` ${I.default.yellow(this.error)}`:"",X=q?`${I.default.yellow(y)} `:"",L=q?I.default.yellow(X1):"";return`${B.trim()}
78
+ ${X}${Y}
79
+ ${L}${Q}
80
+ `}case"submit":{let Q=Z?` ${I.default.dim(Z)}`:"",X=q?I.default.gray(y):"";return`${B}${X}${Q}`}case"cancel":{let Q=Z?` ${I.default.strikethrough(I.default.dim(Z))}`:"",X=q?I.default.gray(y):"";return`${B}${X}${Q}${Z.trim()?`
81
+ ${X}`:""}`}default:{let Q=q?`${I.default.cyan(y)} `:"",X=q?I.default.cyan(X1):"";return`${B}${Q}${Y}
82
+ ${X}
83
+ `}}}}).prompt();function m3(){let z=process.env.SHELL||"";if(z.includes("zsh"))return"zsh";if(z.includes("fish"))return"fish";return"bash"}function l3(z){let q=c3();switch(z){case"zsh":return G1(q,".zshrc");case"fish":return G1(q,".config","fish","config.fish");case"bash":return process.platform==="darwin"?G1(q,".bash_profile"):G1(q,".bashrc")}}function d3(z,q,B){if(z==="fish")return`set -gx ${q} "${B}"`;return`export ${q}="${B}"`}function p3(z,q){if(z==="fish")return new RegExp(`^set\\s+-gx\\s+${q}\\s+.*$`,"m");return new RegExp(`^export\\s+${q}=.*$`,"m")}async function i3(z,q,B){let J=h3(q)?await u3(q,"utf-8"):"";for(let[Y,Z]of Object.entries(B)){let Q=p3(z,Y),X=d3(z,Y,Z);if(Q.test(J))J=J.replace(Q,X);else{if(J.length>0&&!J.endsWith(`
84
+ `))J+=`
85
+ `;J+=`${X}
86
+ `}}await g3(q,J,"utf-8")}async function O4(){if(process.platform==="win32")O.error("The setup command is only supported on POSIX systems (macOS, Linux)."),process.exit(1);let z=await k4({message:"AnythingLLM instance URL (default is AnythingLLM Desktop)",placeholder:"http://localhost:3001",defaultValue:"http://localhost:3001",validate:(Z)=>{if(!Z)return;try{let Q=new URL(Z);if(Q.protocol!=="http:"&&Q.protocol!=="https:")return"Base URL must start with http:// or https://";if(!Q.hostname)return"Base URL must include a hostname"}catch{return"Base URL must be a valid URL (e.g. https://my-instance.com)"}return}});if(p(z)){O.warn("Setup cancelled.");return}let q=await A4({message:"Enter your AnythingLLM API Key",mask:"*",validate:(Z)=>{if(!Z||Z.length!==31)return"API Key must be 31 characters long";return}});if(p(q)){O.warn("Setup cancelled.");return}let B=z.replace(/\/+$/,""),J=m3(),Y=l3(J);await i3(J,Y,{ANYTHING_LLM_BASE_URL:B,ANYTHING_LLM_API_KEY:q}),w4(`Updated ${Y}
87
+
88
+ Run \`source ${Y}\` or restart your terminal to apply changes.`,"Setup complete")}function f4(z){z.command("setup").alias("s").description("Configure the AnythingLLM CLI settings").action(O4)}async function n3(){let z=process.env.ANYTHING_LLM_BASE_URL||"http://localhost:3001";try{return(await fetch(`${z}/api/ping`,{method:"GET",signal:AbortSignal.timeout(2000)})).ok}catch{return!1}}async function v4(){let z=await n3(),q=(R,_,$,E)=>`\x1B[1;38;2;${R};${_};${$}m${E}\x1B[0m`,B=(R)=>`\x1B[38;5;243m${R}\x1B[0m`,J=(R)=>`\x1B[1;38;5;214m${R}\x1B[0m`,Y=z?(R)=>q(90,200,170,R):(R)=>q(200,60,60,R),Z=(R,_,$)=>Math.round(R+(_-R)*$),Q=z?(R,_,$)=>{let E=R/(_-1);return q(Z(70,123,E),Z(255,207,E),Z(200,224,E),$)}:(R,_,$)=>{let E=R/(_-1);return q(Z(180,220,E),Z(40,70,E),Z(40,60,E),$)},X=[" █████ ███ ██ ██ ██ ████████ ██ ██ ██ ███ ██ ██████","██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██","███████ ██ ██ ██ ████ ██ █████ ██ ██ ██ ██ ██ ███","██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ████ ██ ██","██ ██ ██ ███ ██ ██ ██ ██ ██ ██ ███ ██████"],L=["██ ██ ██ ██","██ ██ ███ ███","██ ██ ██ █ ██","██ ██ ██ ██","███████ ███████ ██ ██"],G="✦ Chat with your AnythingLLM instance from the terminal ✦",H=`v${s.version}`,T=Math.max(...X.map((R)=>R.length))+2,j=(R,_)=>R+" ".repeat(Math.max(0,_-R.length)),N=(R,_)=>`${Y("║")} ${R}${" ".repeat(Math.max(0,T-_))} ${Y("║")}`,U=()=>N("",0),S=Y(`╔${"═".repeat(T+2)}╗`),W=Y(`╚${"═".repeat(T+2)}╝`),M=["",S,U()],V=X.length+L.length;for(let R=0;R<X.length;R++){let _=X[R];M.push(N(Q(R,V,j(_,T)),T))}M.push(U());let K=L[0].length,P=Math.floor((T-K)/2);for(let R=0;R<L.length;R++){let _=X.length+R,$=L[R],E=" ".repeat(P);if(R===0){let C=P+$.length+2+H.length;M.push(N(`${E}${Q(_,V,$)} ${B(H)}`,C))}else M.push(N(E+Q(_,V,$),P+$.length))}M.push(U());let x=Math.floor((T-57)/2);if(M.push(N(" ".repeat(x)+B("✦ Chat with your AnythingLLM instance from the terminal ✦"),x+57)),!z){M.push(U());let R=["Could not connect to your AnythingLLM instance.","Ensure it is running and these env vars are set:"];for(let C of R){let A=Math.max(0,Math.floor((T-C.length)/2));M.push(N(" ".repeat(A)+J(C),A+C.length))}M.push(U());let _=["ANYTHING_LLM_API_KEY - API key for your instance","ANYTHING_LLM_BASE_URL - Instance URL"],$=Math.max(..._.map((C)=>C.length)),E=Math.max(0,Math.floor((T-$)/2));for(let C of _)M.push(N(" ".repeat(E)+J(C),E+C.length))}return M.push(U(),W,""),M.join(`
89
+ `)}g.name("any").description("A simple CLI tool to interact with AnythingLLM").version(s.version).addHelpText("before",await v4());if(process.platform!=="win32")f4(g);J4(g);g.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintplex-labs/anything-llm-cli",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "A CLI tool to interact with AnythingLLM from the terminal",
5
5
  "type": "module",
6
6
  "bin": {
@@ -44,6 +44,7 @@
44
44
  "typescript": "^5"
45
45
  },
46
46
  "dependencies": {
47
+ "@clack/prompts": "^1.0.1",
47
48
  "commander": "^14.0.3"
48
49
  }
49
50
  }