@mintplex-labs/anything-llm-cli 0.0.7 → 0.0.9

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