@astralbeam/cli 0.23.0 → 0.23.1
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.
- package/dist/astralbeam.js +1 -1
- package/package.json +2 -2
package/dist/astralbeam.js
CHANGED
|
@@ -17,7 +17,7 @@ Expecting one of '${n.join(`', '`)}'`);return this._lifeCycleHooks[e]?this._life
|
|
|
17
17
|
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
18
18
|
- ${t?`searched for local subcommand relative to directory '${t}'`:`no directory for search for local subcommand, use .executableDir() to supply a custom directory`}`;throw Error(r)}_executeSubCommand(t,n){n=n.slice();let r=[`.js`,`.ts`,`.tsx`,`.mjs`,`.cjs`];function i(e,t){let n=u.resolve(e,t);if(h.existsSync(n))return n;if(r.includes(u.extname(t)))return;let i=r.find(e=>h.existsSync(`${n}${e}`));if(i)return`${n}${i}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let a=t._executableFile||`${this._name}-${t._name}`,o=this._executableDir||``;if(this._scriptPath){let e;try{e=h.realpathSync(this._scriptPath)}catch{e=this._scriptPath}o=u.resolve(u.dirname(e),o)}if(o){let e=i(o,a);if(!e&&!t._executableFile&&this._scriptPath){let n=u.basename(this._scriptPath,u.extname(this._scriptPath));n!==this._name&&(e=i(o,`${n}-${t._name}`))}a=e||a}let s=r.includes(u.extname(a)),c;e.platform===`win32`?(this._checkForMissingExecutable(a,o,t._name),n.unshift(a),n=E(e.execArgv).concat(n),c=l.spawn(e.execPath,n,{stdio:`inherit`})):s?(n.unshift(a),n=E(e.execArgv).concat(n),c=l.spawn(e.argv[0],n,{stdio:`inherit`})):c=l.spawn(a,n,{stdio:`inherit`}),c.killed||[`SIGUSR1`,`SIGUSR2`,`SIGTERM`,`SIGINT`,`SIGHUP`].forEach(t=>{e.on(t,()=>{c.killed===!1&&c.exitCode===null&&c.kill(t)})});let d=this._exitCallback;c.on(`close`,t=>{t??=1,d?d(new oe(t,`commander.executeSubCommandAsync`,`(close)`)):e.exit(t)}),c.on(`error`,n=>{if(n.code===`ENOENT`)this._checkForMissingExecutable(a,o,t._name);else if(n.code===`EACCES`)throw Error(`'${a}' not executable`);if(!d)e.exit(1);else{let e=new oe(1,`commander.executeSubCommandAsync`,`(error)`);e.nestedError=n,d(e)}}),this.runningCommand=c}_dispatchSubcommand(e,t,n){let r=this._findCommand(e);r||this.help({error:!0}),r._prepareForParse();let i;return i=this._chainOrCallSubCommandHook(i,r,`preSubcommand`),i=this._chainOrCall(i,()=>{if(r._executableHandler)this._executeSubCommand(r,t.concat(n));else return r._parseCommand(t,n)}),i}_dispatchHelpCommand(e){e||this.help();let t=this._findCommand(e);return t&&!t._executableHandler&&t.help(),this._dispatchSubcommand(e,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??`--help`])}_checkNumberOfArguments(){this.registeredArguments.forEach((e,t)=>{e.required&&this.args[t]==null&&this.missingArgument(e.name())}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){let e=(e,t,n)=>{let r=t;if(t!==null&&e.parseArg){let i=`error: command-argument value '${t}' is invalid for argument '${e.name()}'.`;r=this._callParseArg(e,t,n,i)}return r};this._checkNumberOfArguments();let t=[];this.registeredArguments.forEach((n,r)=>{let i=n.defaultValue;n.variadic?r<this.args.length?(i=this.args.slice(r),n.parseArg&&(i=i.reduce((t,r)=>e(n,r,t),n.defaultValue))):i===void 0&&(i=[]):r<this.args.length&&(i=this.args[r],n.parseArg&&(i=e(n,i,n.defaultValue))),t[r]=i}),this.processedArgs=t}_chainOrCall(e,t){return e?.then&&typeof e.then==`function`?e.then(()=>t()):t()}_chainOrCallHooks(e,t){let n=e,r=[];return this._getCommandAndAncestors().reverse().filter(e=>e._lifeCycleHooks[t]!==void 0).forEach(e=>{e._lifeCycleHooks[t].forEach(t=>{r.push({hookedCommand:e,callback:t})})}),t===`postAction`&&r.reverse(),r.forEach(e=>{n=this._chainOrCall(n,()=>e.callback(e.hookedCommand,this))}),n}_chainOrCallSubCommandHook(e,t,n){let r=e;return this._lifeCycleHooks[n]!==void 0&&this._lifeCycleHooks[n].forEach(e=>{r=this._chainOrCall(r,()=>e(this,t))}),r}_parseCommand(e,t){let n=this.parseOptions(t);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(n.operands),t=n.unknown,this.args=e.concat(t),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),t);if(this._getHelpCommand()&&e[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(e[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(t),this._dispatchSubcommand(this._defaultCommandName,e,t);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(n.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let r=()=>{n.unknown.length>0&&this.unknownOption(n.unknown[0])},i=`command:${this.name()}`;if(this._actionHandler){r(),this._processArguments();let n;return n=this._chainOrCallHooks(n,`preAction`),n=this._chainOrCall(n,()=>this._actionHandler(this.processedArgs)),this.parent&&(n=this._chainOrCall(n,()=>{this.parent.emit(i,e,t)})),n=this._chainOrCallHooks(n,`postAction`),n}if(this.parent?.listenerCount(i))r(),this._processArguments(),this.parent.emit(i,e,t);else if(e.length){if(this._findCommand(`*`))return this._dispatchSubcommand(`*`,e,t);this.listenerCount(`command:*`)?this.emit(`command:*`,e,t):this.commands.length?this.unknownCommand():(r(),this._processArguments())}else this.commands.length?(r(),this.help({error:!0})):(r(),this._processArguments())}_findCommand(e){if(e)return this.commands.find(t=>t._name===e||t._aliases.includes(e))}_findOption(e){return this.options.find(t=>t.is(e))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(e=>{e.options.forEach(t=>{t.mandatory&&e.getOptionValue(t.attributeName())===void 0&&e.missingMandatoryOptionValue(t)})})}_checkForConflictingLocalOptions(){let e=this.options.filter(e=>{let t=e.attributeName();return this.getOptionValue(t)!==void 0&&this.getOptionValueSource(t)!=="default"});e.filter(e=>e.conflictsWith.length>0).forEach(t=>{let n=e.find(e=>t.conflictsWith.includes(e.attributeName()));n&&this._conflictingOption(t,n)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(e=>{e._checkForConflictingLocalOptions()})}parseOptions(e){let t=[],n=[],r=t;function i(e){return e.length>1&&e[0]===`-`}let a=e=>/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(e)?!this._getCommandAndAncestors().some(e=>e.options.map(e=>e.short).some(e=>/^-\d$/.test(e))):!1,o=null,s=null,c=0;for(;c<e.length||s;){let l=s??e[c++];if(s=null,l===`--`){r===n&&r.push(l),r.push(...e.slice(c));break}if(o&&(!i(l)||a(l)))this.emit(`option:${o.name()}`,l);else{if(o=null,i(l)){let t=this._findOption(l);if(t){if(t.required){let n=e[c++];n===void 0&&this.optionMissingArgument(t),this.emit(`option:${t.name()}`,n)}else if(t.optional){let n=null;c<e.length&&(!i(e[c])||a(e[c]))&&(n=e[c++]),this.emit(`option:${t.name()}`,n)}else this.emit(`option:${t.name()}`);o=t.variadic?t:null;continue}}if(l.length>2&&l[0]===`-`&&l[1]!==`-`){let e=this._findOption(`-${l[1]}`);if(e){e.required||e.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${e.name()}`,l.slice(2)):(this.emit(`option:${e.name()}`),s=`-${l.slice(2)}`);continue}}if(/^--[^=]+=/.test(l)){let e=l.indexOf(`=`),t=this._findOption(l.slice(0,e));if(t&&(t.required||t.optional)){this.emit(`option:${t.name()}`,l.slice(e+1));continue}}if(r===t&&i(l)&&!(this.commands.length===0&&a(l))&&(r=n),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&n.length===0){if(this._findCommand(l)){t.push(l),n.push(...e.slice(c));break}if(this._getHelpCommand()&&l===this._getHelpCommand().name()){t.push(l,...e.slice(c));break}if(this._defaultCommandName){n.push(l,...e.slice(c));break}}if(this._passThroughOptions){r.push(l,...e.slice(c));break}r.push(l)}}return{operands:t,unknown:n}}opts(){if(this._storeOptionsAsProperties){let e={},t=this.options.length;for(let n=0;n<t;n++){let t=this.options[n].attributeName();e[t]=t===this._versionOptionName?this._version:this[t]}return e}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((e,t)=>Object.assign(e,t.opts()),{})}error(e,t){this._outputConfiguration.outputError(`${e}\n`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError==`string`?this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
|
|
19
19
|
`),this.outputHelp({error:!0}));let n=t||{},r=n.exitCode||1,i=n.code||`commander.error`;this._exit(r,i,e)}_parseOptionsEnv(){this.options.forEach(t=>{if(t.envVar&&t.envVar in e.env){let n=t.attributeName();(this.getOptionValue(n)===void 0||[`default`,`config`,`env`].includes(this.getOptionValueSource(n)))&&(t.required||t.optional?this.emit(`optionEnv:${t.name()}`,e.env[t.envVar]):this.emit(`optionEnv:${t.name()}`))}})}_parseOptionsImplied(){let e=new ue(this.options),t=e=>this.getOptionValue(e)!==void 0&&![`default`,`implied`].includes(this.getOptionValueSource(e));this.options.filter(n=>n.implied!==void 0&&t(n.attributeName())&&e.valueFromOption(this.getOptionValue(n.attributeName()),n)).forEach(e=>{Object.keys(e.implied).filter(e=>!t(e)).forEach(t=>{this.setOptionValueWithSource(t,e.implied[t],`implied`)})})}missingArgument(e){let t=`error: missing required argument '${e}'`;this.error(t,{code:`commander.missingArgument`})}optionMissingArgument(e){let t=`error: option '${e.flags}' argument missing`;this.error(t,{code:`commander.optionMissingArgument`})}missingMandatoryOptionValue(e){let t=`error: required option '${e.flags}' not specified`;this.error(t,{code:`commander.missingMandatoryOptionValue`})}_conflictingOption(e,t){let n=e=>{let t=e.attributeName(),n=this.getOptionValue(t),r=this.options.find(e=>e.negate&&t===e.attributeName()),i=this.options.find(e=>!e.negate&&t===e.attributeName());return r&&(r.presetArg===void 0&&n===!1||r.presetArg!==void 0&&n===r.presetArg)?r:i||e},r=e=>{let t=n(e),r=t.attributeName();return this.getOptionValueSource(r)===`env`?`environment variable '${t.envVar}'`:`option '${t.flags}'`},i=`error: ${r(e)} cannot be used with ${r(t)}`;this.error(i,{code:`commander.conflictingOption`})}unknownOption(e){if(this._allowUnknownOption)return;let t=``;if(e.startsWith(`--`)&&this._showSuggestionAfterError){let n=[],r=this;do{let e=r.createHelp().visibleOptions(r).filter(e=>e.long).map(e=>e.long);n=n.concat(e),r=r.parent}while(r&&!r._enablePositionalOptions);t=T(e,n)}let n=`error: unknown option '${e}'${t}`;this.error(n,{code:`commander.unknownOption`})}_excessArguments(e){if(this._allowExcessArguments)return;let t=this.registeredArguments.length,n=t===1?``:`s`,r=e.length,i=`error: too many arguments${this.parent?` for '${this.name()}'`:``}. Expected ${t} argument${n} but got ${r}: ${e.join(`, `)}.`;this.error(i,{code:`commander.excessArguments`})}unknownCommand(){let e=this.args[0],t=``;if(this._showSuggestionAfterError){let n=[];this.createHelp().visibleCommands(this).forEach(e=>{n.push(e.name()),e.alias()&&n.push(e.alias())}),t=T(e,n)}let n=`error: unknown command '${e}'${t}`;this.error(n,{code:`commander.unknownCommand`})}version(e,t,n){if(e===void 0)return this._version;this._version=e,t||=`-V, --version`,n||=`output the version number`;let r=this.createOption(t,n);return this._versionOptionName=r.attributeName(),this._registerOption(r),this.on(`option:`+r.name(),()=>{this._outputConfiguration.writeOut(`${e}\n`),this._exit(0,`commander.version`,e)}),this}description(e,t){return e===void 0&&t===void 0?this._description:(this._description=e,t&&(this._argsDescription=t),this)}summary(e){return e===void 0?this._summary:(this._summary=e,this)}alias(e){if(e===void 0)return this._aliases[0];let t=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(t=this.commands[this.commands.length-1]),e===t._name)throw Error(`Command alias can't be the same as its name`);let n=this.parent?._findCommand(e);if(n){let t=[n.name()].concat(n.aliases()).join(`|`);throw Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${t}'`)}return t._aliases.push(e),this}aliases(e){return e===void 0?this._aliases:(e.forEach(e=>this.alias(e)),this)}usage(e){if(e===void 0){if(this._usage)return this._usage;let e=this.registeredArguments.map(e=>se(e));return[].concat(this.options.length||this._helpOption!==null?`[options]`:[],this.commands.length?`[command]`:[],this.registeredArguments.length?e:[]).join(` `)}return this._usage=e,this}name(e){return e===void 0?this._name:(this._name=e,this)}helpGroup(e){return e===void 0?this._helpGroupHeading??``:(this._helpGroupHeading=e,this)}commandsGroup(e){return e===void 0?this._defaultCommandGroup??``:(this._defaultCommandGroup=e,this)}optionsGroup(e){return e===void 0?this._defaultOptionGroup??``:(this._defaultOptionGroup=e,this)}_initOptionGroup(e){this._defaultOptionGroup&&!e.helpGroupHeading&&e.helpGroup(this._defaultOptionGroup)}_initCommandGroup(e){this._defaultCommandGroup&&!e.helpGroup()&&e.helpGroup(this._defaultCommandGroup)}nameFromFilename(e){return this._name=u.basename(e,u.extname(e)),this}executableDir(e){return e===void 0?this._executableDir:(this._executableDir=e,this)}helpInformation(e){let t=this.createHelp(),n=this._getOutputContext(e);t.prepareContext({error:n.error,helpWidth:n.helpWidth,outputHasColors:n.hasColors});let r=t.formatHelp(this,t);return n.hasColors?r:this._outputConfiguration.stripColor(r)}_getOutputContext(e){e||={};let t=!!e.error,n,r,i;return t?(n=e=>this._outputConfiguration.writeErr(e),r=this._outputConfiguration.getErrHasColors(),i=this._outputConfiguration.getErrHelpWidth()):(n=e=>this._outputConfiguration.writeOut(e),r=this._outputConfiguration.getOutHasColors(),i=this._outputConfiguration.getOutHelpWidth()),{error:t,write:e=>(r||(e=this._outputConfiguration.stripColor(e)),n(e)),hasColors:r,helpWidth:i}}outputHelp(e){let t;typeof e==`function`&&(t=e,e=void 0);let n=this._getOutputContext(e),r={error:n.error,write:n.write,command:this};this._getCommandAndAncestors().reverse().forEach(e=>e.emit(`beforeAllHelp`,r)),this.emit(`beforeHelp`,r);let i=this.helpInformation({error:n.error});if(t&&(i=t(i),typeof i!=`string`&&!Buffer.isBuffer(i)))throw Error(`outputHelp callback must return a string or a Buffer`);n.write(i),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit(`afterHelp`,r),this._getCommandAndAncestors().forEach(e=>e.emit(`afterAllHelp`,r))}helpOption(e,t){return typeof e==`boolean`?(e?(this._helpOption===null&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(e??`-h, --help`,t??`display help for command`),(e||t)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(e){return this._helpOption=e,this._initOptionGroup(e),this}help(t){this.outputHelp(t);let n=Number(e.exitCode??0);n===0&&t&&typeof t!=`function`&&t.error&&(n=1),this._exit(n,`commander.help`,`(outputHelp)`)}addHelpText(e,t){let n=[`beforeAll`,`before`,`after`,`afterAll`];if(!n.includes(e))throw Error(`Unexpected value for position to addHelpText.
|
|
20
|
-
Expecting one of '${n.join(`', '`)}'`);let r=`${e}Help`;return this.on(r,e=>{let n;n=typeof t==`function`?t({error:e.error,command:e.command}):t,n&&e.write(`${n}\n`)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(e=>t.is(e))&&(this.outputHelp(),this._exit(0,`commander.helpDisplayed`,`(outputHelp)`))}};function E(e){return e.map(e=>{if(!e.startsWith(`--inspect`))return e;let t,n=`127.0.0.1`,r=`9229`,i;return(i=e.match(/^(--inspect(-brk)?)$/))===null?(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))===null?(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=i[1],n=i[3],r=i[4]):(t=i[1],/^\d+$/.test(i[3])?r=i[3]:n=i[3]):t=i[1],t&&r!==`0`?`${t}=${n}:${parseInt(r)+1}`:e})}function me(){if(e.env.NO_COLOR||e.env.FORCE_COLOR===`0`||e.env.FORCE_COLOR===`false`)return!1;if(e.env.FORCE_COLOR||e.env.CLICOLOR_FORCE!==void 0)return!0}new pe;var D=`0.23.0`;function O(e){return e instanceof Error&&e.name===`AstralBeamApiError`&&`status`in e&&typeof e.status==`number`}function he(e,t=`https://astralbeam.ai/api`){return`${t.replace(/\/+$/,``)}${e.replace(/^\/api(?=\/)/,``)}`}function ge(e,t){if(!e||typeof e!=`object`)return!1;let n=e;return n.status===t&&typeof n.type==`string`&&typeof n.title==`string`&&typeof n.detail==`string`&&(n.reference===void 0||typeof n.reference==`string`)&&(n.issues===void 0||Array.isArray(n.issues)&&n.issues.every(e=>e&&typeof e.path==`string`&&typeof e.message==`string`))}async function _e(e,t){let{apiUrl:n,apiKey:r,astralBeamToken:i,fetchClient:a=globalThis.fetch,...o}=t,s=new Headers,c=o.headers instanceof Headers?o.headers.entries():Array.isArray(o.headers)?o.headers:Object.entries(o.headers??{});for(let[e,t]of c)s.set(e,t);s.delete(`authorization`),s.delete(`x-api-key`),r&&s.set(`x-api-key`,r),i&&s.set(`authorization`,`Bearer ${i}`);let l=await a(he(e,n),{...o,headers:s,...r?{redirect:`error`}:{}});if(l.ok)return l;let u=await l.json().catch(e=>{if(!(e instanceof SyntaxError))throw e}),d=ge(u,l.status)?u:void 0;throw Object.assign(Error(d?.detail??`AstralBeam API returned HTTP ${l.status}`),{name:`AstralBeamApiError`,status:l.status,headers:l.headers,body:d})}async function k(e,t){let n=await _e(e,t);if(n.status!==204)return await n.json()}function A(e,t){return k(e,t)}function j(e,t){return _e(e,t)}function ve(e,t){return _e(e,t)}const ye=e=>{let t=new URLSearchParams;Object.entries(e||{}).forEach(([e,n])=>{n!==void 0&&t.append(e,n===null?`null`:String(n))});let n=t.toString();return n.length>0?`/api/v1/tenants?${n}`:`/api/v1/tenants`},be=(e,t)=>k(ye(e),{...t,method:`GET`}),xe=()=>`/api/v1/tenants`,Se=(e,t)=>{let n=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return k(xe(),{...t,method:`POST`,headers:{"Content-Type":`application/json`,...n(t?.headers)},body:JSON.stringify(e)})},Ce=e=>`/api/v1/tenants/${encodeURIComponent(String(e))}`,we=(e,t)=>k(Ce(e),{...t,method:`GET`}),Te=e=>`/api/v1/tenants/${encodeURIComponent(String(e))}`,Ee=(e,t,n)=>{let r=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return k(Te(e),{...n,method:`PATCH`,headers:{"Content-Type":`application/json`,...r(n?.headers)},body:JSON.stringify(t)})},De=(e,t)=>{let n=new URLSearchParams;Object.entries(t||{}).forEach(([e,t])=>{t!==void 0&&n.append(e,t===null?`null`:String(t))});let r=n.toString();return r.length>0?`/api/v1/tenants/${encodeURIComponent(String(e))}/tenant_users?${r}`:`/api/v1/tenants/${encodeURIComponent(String(e))}/tenant_users`},Oe=(e,t,n)=>k(De(e,t),{...n,method:`GET`}),ke=e=>`/api/v1/tenants/${encodeURIComponent(String(e))}/tenant_users`,Ae=(e,t,n)=>{let r=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return k(ke(e),{...n,method:`POST`,headers:{"Content-Type":`application/json`,...r(n?.headers)},body:JSON.stringify(t)})},je=(e,t)=>`/api/v1/tenants/${encodeURIComponent(String(e))}/tenant_users/${encodeURIComponent(String(t))}`,Me=(e,t,n)=>k(je(e,t),{...n,method:`GET`}),Ne=(e,t)=>`/api/v1/tenants/${encodeURIComponent(String(e))}/tenant_users/${encodeURIComponent(String(t))}`,Pe=(e,t,n,r)=>{let i=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return k(Ne(e,t),{...r,method:`PATCH`,headers:{"Content-Type":`application/json`,...i(r?.headers)},body:JSON.stringify(n)})},Fe=()=>`/api/v1/organization`,Ie=e=>k(Fe(),{...e,method:`GET`}),M=()=>`/api/v1/chat/files`,Le=(e,t)=>{let n=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return A(M(),{...t,method:`POST`,headers:{"Content-Type":`application/json`,...n(t?.headers)},body:JSON.stringify(e)})},N=e=>{let t=new URLSearchParams;Object.entries(e||{}).forEach(([e,n])=>{n!==void 0&&t.append(e,n===null?`null`:String(n))});let n=t.toString();return n.length>0?`/api/v1/chat/files?${n}`:`/api/v1/chat/files`},Re=(e,t)=>j(N(e),{...t,method:`GET`}),ze=()=>`/api/v1/chat`,Be=e=>{let t=new URLSearchParams;Object.entries(e||{}).forEach(([e,n])=>{n!==void 0&&t.append(e,n===null?`null`:String(n))});let n=t.toString();return n.length>0?`/api/v1/chat/config?${n}`:`/api/v1/chat/config`},Ve=(e,t)=>A(Be(e),{...t,method:`GET`}),He=()=>`/api/v1/chat/threads`,Ue=(e,t)=>{let n=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return A(He(),{...t,method:`POST`,headers:{"Content-Type":`application/json`,...n(t?.headers)},body:JSON.stringify(e)})},We=e=>{let t=new URLSearchParams;Object.entries(e||{}).forEach(([e,n])=>{n!==void 0&&t.append(e,n===null?`null`:String(n))});let n=t.toString();return n.length>0?`/api/v1/chat/threads?${n}`:`/api/v1/chat/threads`},Ge=(e,t)=>A(We(e),{...t,method:`GET`}),Ke=e=>`/api/v1/chat/threads/${encodeURIComponent(String(e))}`,qe=(e,t,n)=>{let r=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return A(Ke(e),{...n,method:`PATCH`,headers:{"Content-Type":`application/json`,...r(n?.headers)},body:JSON.stringify(t)})},Je=(e,t)=>{let n=new URLSearchParams;Object.entries(t||{}).forEach(([e,t])=>{t!==void 0&&n.append(e,t===null?`null`:String(t))});let r=n.toString();return r.length>0?`/api/v1/chat/threads/${encodeURIComponent(String(e))}?${r}`:`/api/v1/chat/threads/${encodeURIComponent(String(e))}`},Ye=(e,t,n)=>A(Je(e,t),{...n,method:`DELETE`}),Xe=(e,t)=>{let n=new URLSearchParams;Object.entries(t||{}).forEach(([e,t])=>{t!==void 0&&n.append(e,t===null?`null`:String(t))});let r=n.toString();return r.length>0?`/api/v1/chat/threads/${encodeURIComponent(String(e))}/messages?${r}`:`/api/v1/chat/threads/${encodeURIComponent(String(e))}/messages`},Ze=(e,t,n)=>A(Xe(e,t),{...n,method:`GET`}),Qe=e=>`/api/v1/chat/threads/${encodeURIComponent(String(e))}/tool-results`,$e=()=>`/api/v1/me`,et=e=>A($e(),{...e,method:`POST`}),tt=()=>`/api/v1/me/mcp/catalog`,nt=e=>A(tt(),{...e,method:`GET`}),rt=()=>`/api/v1/me/mcp/connections`,it=(e,t)=>{let n=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return A(rt(),{...t,method:`POST`,headers:{"Content-Type":`application/json`,...n(t?.headers)},body:JSON.stringify(e)})},at=e=>`/api/v1/me/mcp/connections/${encodeURIComponent(String(e))}/headers`,ot=(e,t,n)=>{let r=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return A(at(e),{...n,method:`POST`,headers:{"Content-Type":`application/json`,...r(n?.headers)},body:JSON.stringify(t)})},st=e=>`/api/v1/me/mcp/connections/${encodeURIComponent(String(e))}`,ct=(e,t)=>A(st(e),{...t,method:`DELETE`}),lt=e=>`/api/v1/me/mcp/connections/${encodeURIComponent(String(e))}/test`,ut=(e,t)=>A(lt(e),{...t,method:`POST`}),dt=e=>`/api/v1/me/mcp/connections/${encodeURIComponent(String(e))}/authorize`,ft=(e,t)=>A(dt(e),{...t,method:`POST`}),pt=e=>`/api/v1/me/mcp/connections/${encodeURIComponent(String(e))}/oauth/bind`,mt=(e,t,n)=>{let r=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return A(pt(e),{...n,method:`POST`,headers:{"Content-Type":`application/json`,...r(n?.headers)},body:JSON.stringify(t)})},ht=e=>`/api/v1/me/mcp/connections/${encodeURIComponent(String(e))}/oauth/complete`,gt=(e,t,n)=>{let r=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return A(ht(e),{...n,method:`POST`,headers:{"Content-Type":`application/json`,...r(n?.headers)},body:JSON.stringify(t)})};function _t(e){s.write(`${JSON.stringify(e,null,2)}\n`)}function P(e,t=``){let n=``;for(let r of e){let e=r.codePointAt(0)??0;n+=(e<32||e>=127&&e<160)&&!t.includes(r)?`\\u${e.toString(16).padStart(4,`0`)}`:r}return n}function vt(e){return e==null?``:P(typeof e==`string`?e:JSON.stringify(e))}function yt(e){let t=Object.entries(e),n=Math.max(...t.map(([e])=>e.length));for(let[e,r]of t)s.write(`${e.padEnd(n)} ${vt(r)}\n`)}function F(e,t){t?_t(e):yt(e)}function bt(e,t){let n=e.map(e=>t.map(t=>vt(e[t]))),r=t.map((e,t)=>n.reduce((e,n)=>Math.max(e,n[t]?.length??0),e.length)),i=e=>`${e.map((e,t)=>e.padEnd(r[t]??0)).join(` `)}`.trimEnd();s.write(`${i(t.map(e=>e.toUpperCase()))}\n`);for(let e of n)s.write(`${i(e)}\n`)}function xt(e){if(e.status===401)return"The API key was rejected. It may be revoked or deleted, so create a new one and run `astralbeam auth login` again.";if(e.status===404&&e.body?.detail===`Resource not found.`)return`This server does not serve that endpoint. Check the API URL, or the server may run an older AstralBeam release than this CLI (${D}).`;if(e.status===429)return`The API rate limit was reached. Wait a few minutes and retry.`}function St(e,t,n,r){let i=e instanceof Error?e.message:String(e);if(t){let t=O(e)?e.body??{status:e.status,detail:i}:{detail:i};a.write(`${JSON.stringify({error:t,context:n??null})}\n`);return}if(!O(e))return void a.write(`Error: ${P(i)}\n`);let o=r?` from ${r}`:``;a.write(`Error: ${P(i)} (HTTP ${e.status}${o})\n`);for(let t of e.body?.issues??[])a.write(` ${P(t.path)}: ${P(t.message)}\n`);let s=xt(e);s&&a.write(`${s}\n`)}const Ct=`https://astralbeam.ai/api`,wt=/^key_([0-9a-f-]{36})_[0-9a-f-]{36}_abo_[A-Za-z]{64}$/;function Tt(){if(n.ASTRALBEAM_CONFIG_DIR)return f(n.ASTRALBEAM_CONFIG_DIR,`config.json`);let e=i===`win32`?n.APPDATA??ie():n.XDG_CONFIG_HOME??f(ie(),`.config`);return f(e,`astralbeam`,`config.json`)}function Et(e){let t=wt.exec(e)?.[1];if(!t)throw Error(`The API key must match key_<organizationId>_<id>_abo_<secret>.`);return t}function Dt(e){let t;try{t=new URL(e)}catch{throw Error(`The API URL "${e}" is not a valid URL.`)}let n=t.hostname,r=n===`localhost`||n===`[::1]`||re(n)&&n.startsWith(`127.`);if(t.protocol!==`https:`&&!(t.protocol===`http:`&&r))throw Error(`The API URL "${e}" must use https://, or http:// only for loopback hosts.`);return e}function Ot(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function kt(e){return Ot(e)&&Object.values(e).every(e=>Ot(e)&&typeof e.api_url==`string`&&typeof e.api_key==`string`&&Ot(e.organization)&&typeof e.organization.id==`string`&&typeof e.organization.name==`string`&&typeof e.organization.slug==`string`)}function At(e){try{let t=JSON.parse(e);if(Ot(t)){let e=t.bindings===void 0?{}:t.bindings;if(kt(e))return{bindings:e}}}catch{}throw Error(`Invalid AstralBeam login bindings in ${Tt()}`)}async function jt(){try{return At(await te(Tt(),`utf8`))}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return{bindings:{}};throw e}}async function Mt(e){let t=Tt();await ee(d(t),{recursive:!0,mode:448});let n=`${t}.${r}.tmp`;try{await ne(n,`${JSON.stringify(e,null,2)}\n`,{mode:384,flag:`wx`}),await y(n,t)}catch(e){throw await b(n,{force:!0}),e}}async function Nt(){return await v(t())}function Pt(e,t){for(let n=t;;n=d(n)){let t=e.bindings[n];if(t)return{directory:n,binding:t};if(d(n)===n)return}}function Ft(e){let t=ie();return e===t||e.startsWith(t+m)?`~${e.slice(t.length)}`:e}const I={json:!1,context:void 0,failedRequest:void 0};function It(e){I.context={organization:e.organization,bound_directory:e.directory??null},I.json||a.write(Lt(e))}function Lt(e){let{organization:t,directory:n}=e,r=t.name?`${P(t.name)} (${P(t.slug??``)}) · `:``,i=n?`bound at ${Ft(n)}`:`from ASTRALBEAM_API_KEY`;return`▸ ${r}org ${t.id} · ${i}\n`}function L(e){return{json:e.optsWithGlobals().json===!0}}async function Rt(){let{apiKey:e,apiUrl:t}=await zt();return{apiKey:e,apiUrl:t}}async function zt(){let e=n.ASTRALBEAM_API_KEY,t;if(e)t={apiKey:e,apiUrl:Dt(n.ASTRALBEAM_API_URL??`https://astralbeam.ai/api`),organization:{id:Et(e)}};else{let e=await Nt(),n=Pt(await jt(),e);if(!n)throw Error(`No AstralBeam login covers ${Ft(e)}. Run \`astralbeam auth login\` in this directory or a parent, or set ASTRALBEAM_API_KEY.`);let{binding:r}=n;t={apiKey:r.api_key,apiUrl:Dt(r.api_url),organization:r.organization,directory:n.directory}}return It(t),t}function Bt(e){o.setRawMode(!0),a.write(e),o.setEncoding(`utf8`),o.resume();let t=``;return new Promise((e,n)=>{let r=()=>{o.off(`data`,i),o.setRawMode(!1),o.pause(),a.write(`
|
|
20
|
+
Expecting one of '${n.join(`', '`)}'`);let r=`${e}Help`;return this.on(r,e=>{let n;n=typeof t==`function`?t({error:e.error,command:e.command}):t,n&&e.write(`${n}\n`)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(e=>t.is(e))&&(this.outputHelp(),this._exit(0,`commander.helpDisplayed`,`(outputHelp)`))}};function E(e){return e.map(e=>{if(!e.startsWith(`--inspect`))return e;let t,n=`127.0.0.1`,r=`9229`,i;return(i=e.match(/^(--inspect(-brk)?)$/))===null?(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))===null?(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=i[1],n=i[3],r=i[4]):(t=i[1],/^\d+$/.test(i[3])?r=i[3]:n=i[3]):t=i[1],t&&r!==`0`?`${t}=${n}:${parseInt(r)+1}`:e})}function me(){if(e.env.NO_COLOR||e.env.FORCE_COLOR===`0`||e.env.FORCE_COLOR===`false`)return!1;if(e.env.FORCE_COLOR||e.env.CLICOLOR_FORCE!==void 0)return!0}new pe;var D=`0.23.1`;function O(e){return e instanceof Error&&e.name===`AstralBeamApiError`&&`status`in e&&typeof e.status==`number`}function he(e,t=`https://astralbeam.ai/api`){return`${t.replace(/\/+$/,``)}${e.replace(/^\/api(?=\/)/,``)}`}function ge(e,t){if(!e||typeof e!=`object`)return!1;let n=e;return n.status===t&&typeof n.type==`string`&&typeof n.title==`string`&&typeof n.detail==`string`&&(n.reference===void 0||typeof n.reference==`string`)&&(n.issues===void 0||Array.isArray(n.issues)&&n.issues.every(e=>e&&typeof e.path==`string`&&typeof e.message==`string`))}async function _e(e,t){let{apiUrl:n,apiKey:r,astralBeamToken:i,fetchClient:a=globalThis.fetch,...o}=t,s=new Headers,c=o.headers instanceof Headers?o.headers.entries():Array.isArray(o.headers)?o.headers:Object.entries(o.headers??{});for(let[e,t]of c)s.set(e,t);s.delete(`authorization`),s.delete(`x-api-key`),r&&s.set(`x-api-key`,r),i&&s.set(`authorization`,`Bearer ${i}`);let l=await a(he(e,n),{...o,headers:s,...r?{redirect:`error`}:{}});if(l.ok)return l;let u=await l.json().catch(e=>{if(!(e instanceof SyntaxError))throw e}),d=ge(u,l.status)?u:void 0;throw Object.assign(Error(d?.detail??`AstralBeam API returned HTTP ${l.status}`),{name:`AstralBeamApiError`,status:l.status,headers:l.headers,body:d})}async function k(e,t){let n=await _e(e,t);if(n.status!==204)return await n.json()}function A(e,t){return k(e,t)}function j(e,t){return _e(e,t)}function ve(e,t){return _e(e,t)}const ye=e=>{let t=new URLSearchParams;Object.entries(e||{}).forEach(([e,n])=>{n!==void 0&&t.append(e,n===null?`null`:String(n))});let n=t.toString();return n.length>0?`/api/v1/tenants?${n}`:`/api/v1/tenants`},be=(e,t)=>k(ye(e),{...t,method:`GET`}),xe=()=>`/api/v1/tenants`,Se=(e,t)=>{let n=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return k(xe(),{...t,method:`POST`,headers:{"Content-Type":`application/json`,...n(t?.headers)},body:JSON.stringify(e)})},Ce=e=>`/api/v1/tenants/${encodeURIComponent(String(e))}`,we=(e,t)=>k(Ce(e),{...t,method:`GET`}),Te=e=>`/api/v1/tenants/${encodeURIComponent(String(e))}`,Ee=(e,t,n)=>{let r=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return k(Te(e),{...n,method:`PATCH`,headers:{"Content-Type":`application/json`,...r(n?.headers)},body:JSON.stringify(t)})},De=(e,t)=>{let n=new URLSearchParams;Object.entries(t||{}).forEach(([e,t])=>{t!==void 0&&n.append(e,t===null?`null`:String(t))});let r=n.toString();return r.length>0?`/api/v1/tenants/${encodeURIComponent(String(e))}/tenant_users?${r}`:`/api/v1/tenants/${encodeURIComponent(String(e))}/tenant_users`},Oe=(e,t,n)=>k(De(e,t),{...n,method:`GET`}),ke=e=>`/api/v1/tenants/${encodeURIComponent(String(e))}/tenant_users`,Ae=(e,t,n)=>{let r=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return k(ke(e),{...n,method:`POST`,headers:{"Content-Type":`application/json`,...r(n?.headers)},body:JSON.stringify(t)})},je=(e,t)=>`/api/v1/tenants/${encodeURIComponent(String(e))}/tenant_users/${encodeURIComponent(String(t))}`,Me=(e,t,n)=>k(je(e,t),{...n,method:`GET`}),Ne=(e,t)=>`/api/v1/tenants/${encodeURIComponent(String(e))}/tenant_users/${encodeURIComponent(String(t))}`,Pe=(e,t,n,r)=>{let i=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return k(Ne(e,t),{...r,method:`PATCH`,headers:{"Content-Type":`application/json`,...i(r?.headers)},body:JSON.stringify(n)})},Fe=()=>`/api/v1/organization`,Ie=e=>k(Fe(),{...e,method:`GET`}),M=()=>`/api/v1/chat/files`,Le=(e,t)=>{let n=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return A(M(),{...t,method:`POST`,headers:{"Content-Type":`application/json`,...n(t?.headers)},body:JSON.stringify(e)})},N=e=>{let t=new URLSearchParams;Object.entries(e||{}).forEach(([e,n])=>{n!==void 0&&t.append(e,n===null?`null`:String(n))});let n=t.toString();return n.length>0?`/api/v1/chat/files?${n}`:`/api/v1/chat/files`},Re=(e,t)=>j(N(e),{...t,method:`GET`}),ze=()=>`/api/v1/chat`,Be=e=>{let t=new URLSearchParams;Object.entries(e||{}).forEach(([e,n])=>{n!==void 0&&t.append(e,n===null?`null`:String(n))});let n=t.toString();return n.length>0?`/api/v1/chat/config?${n}`:`/api/v1/chat/config`},Ve=(e,t)=>A(Be(e),{...t,method:`GET`}),He=()=>`/api/v1/chat/threads`,Ue=(e,t)=>{let n=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return A(He(),{...t,method:`POST`,headers:{"Content-Type":`application/json`,...n(t?.headers)},body:JSON.stringify(e)})},We=e=>{let t=new URLSearchParams;Object.entries(e||{}).forEach(([e,n])=>{n!==void 0&&t.append(e,n===null?`null`:String(n))});let n=t.toString();return n.length>0?`/api/v1/chat/threads?${n}`:`/api/v1/chat/threads`},Ge=(e,t)=>A(We(e),{...t,method:`GET`}),Ke=e=>`/api/v1/chat/threads/${encodeURIComponent(String(e))}`,qe=(e,t,n)=>{let r=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return A(Ke(e),{...n,method:`PATCH`,headers:{"Content-Type":`application/json`,...r(n?.headers)},body:JSON.stringify(t)})},Je=(e,t)=>{let n=new URLSearchParams;Object.entries(t||{}).forEach(([e,t])=>{t!==void 0&&n.append(e,t===null?`null`:String(t))});let r=n.toString();return r.length>0?`/api/v1/chat/threads/${encodeURIComponent(String(e))}?${r}`:`/api/v1/chat/threads/${encodeURIComponent(String(e))}`},Ye=(e,t,n)=>A(Je(e,t),{...n,method:`DELETE`}),Xe=(e,t)=>{let n=new URLSearchParams;Object.entries(t||{}).forEach(([e,t])=>{t!==void 0&&n.append(e,t===null?`null`:String(t))});let r=n.toString();return r.length>0?`/api/v1/chat/threads/${encodeURIComponent(String(e))}/messages?${r}`:`/api/v1/chat/threads/${encodeURIComponent(String(e))}/messages`},Ze=(e,t,n)=>A(Xe(e,t),{...n,method:`GET`}),Qe=e=>`/api/v1/chat/threads/${encodeURIComponent(String(e))}/tool-results`,$e=()=>`/api/v1/me`,et=e=>A($e(),{...e,method:`POST`}),tt=()=>`/api/v1/me/mcp/catalog`,nt=e=>A(tt(),{...e,method:`GET`}),rt=()=>`/api/v1/me/mcp/connections`,it=(e,t)=>{let n=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return A(rt(),{...t,method:`POST`,headers:{"Content-Type":`application/json`,...n(t?.headers)},body:JSON.stringify(e)})},at=e=>`/api/v1/me/mcp/connections/${encodeURIComponent(String(e))}/headers`,ot=(e,t,n)=>{let r=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return A(at(e),{...n,method:`POST`,headers:{"Content-Type":`application/json`,...r(n?.headers)},body:JSON.stringify(t)})},st=e=>`/api/v1/me/mcp/connections/${encodeURIComponent(String(e))}`,ct=(e,t)=>A(st(e),{...t,method:`DELETE`}),lt=e=>`/api/v1/me/mcp/connections/${encodeURIComponent(String(e))}/test`,ut=(e,t)=>A(lt(e),{...t,method:`POST`}),dt=e=>`/api/v1/me/mcp/connections/${encodeURIComponent(String(e))}/authorize`,ft=(e,t)=>A(dt(e),{...t,method:`POST`}),pt=e=>`/api/v1/me/mcp/connections/${encodeURIComponent(String(e))}/oauth/bind`,mt=(e,t,n)=>{let r=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return A(pt(e),{...n,method:`POST`,headers:{"Content-Type":`application/json`,...r(n?.headers)},body:JSON.stringify(t)})},ht=e=>`/api/v1/me/mcp/connections/${encodeURIComponent(String(e))}/oauth/complete`,gt=(e,t,n)=>{let r=e=>{if(!e)return{};if(e instanceof Headers)return Object.fromEntries(e.entries());if(Symbol.iterator in e)return Object.fromEntries(Array.from(e,e=>Array.from(e)));let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t};return A(ht(e),{...n,method:`POST`,headers:{"Content-Type":`application/json`,...r(n?.headers)},body:JSON.stringify(t)})};function _t(e){s.write(`${JSON.stringify(e,null,2)}\n`)}function P(e,t=``){let n=``;for(let r of e){let e=r.codePointAt(0)??0;n+=(e<32||e>=127&&e<160)&&!t.includes(r)?`\\u${e.toString(16).padStart(4,`0`)}`:r}return n}function vt(e){return e==null?``:P(typeof e==`string`?e:JSON.stringify(e))}function yt(e){let t=Object.entries(e),n=Math.max(...t.map(([e])=>e.length));for(let[e,r]of t)s.write(`${e.padEnd(n)} ${vt(r)}\n`)}function F(e,t){t?_t(e):yt(e)}function bt(e,t){let n=e.map(e=>t.map(t=>vt(e[t]))),r=t.map((e,t)=>n.reduce((e,n)=>Math.max(e,n[t]?.length??0),e.length)),i=e=>`${e.map((e,t)=>e.padEnd(r[t]??0)).join(` `)}`.trimEnd();s.write(`${i(t.map(e=>e.toUpperCase()))}\n`);for(let e of n)s.write(`${i(e)}\n`)}function xt(e){if(e.status===401)return"The API key was rejected. It may be revoked or deleted, so create a new one and run `astralbeam auth login` again.";if(e.status===404&&e.body?.detail===`Resource not found.`)return`This server does not serve that endpoint. Check the API URL, or the server may run an older AstralBeam release than this CLI (${D}).`;if(e.status===429)return`The API rate limit was reached. Wait a few minutes and retry.`}function St(e,t,n,r){let i=e instanceof Error?e.message:String(e);if(t){let t=O(e)?e.body??{status:e.status,detail:i}:{detail:i};a.write(`${JSON.stringify({error:t,context:n??null})}\n`);return}if(!O(e))return void a.write(`Error: ${P(i)}\n`);let o=r?` from ${r}`:``;a.write(`Error: ${P(i)} (HTTP ${e.status}${o})\n`);for(let t of e.body?.issues??[])a.write(` ${P(t.path)}: ${P(t.message)}\n`);let s=xt(e);s&&a.write(`${s}\n`)}const Ct=`https://astralbeam.ai/api`,wt=/^key_([0-9a-f-]{36})_[0-9a-f-]{36}_abo_[A-Za-z]{64}$/;function Tt(){if(n.ASTRALBEAM_CONFIG_DIR)return f(n.ASTRALBEAM_CONFIG_DIR,`config.json`);let e=i===`win32`?n.APPDATA??ie():n.XDG_CONFIG_HOME??f(ie(),`.config`);return f(e,`astralbeam`,`config.json`)}function Et(e){let t=wt.exec(e)?.[1];if(!t)throw Error(`The API key must match key_<organizationId>_<id>_abo_<secret>.`);return t}function Dt(e){let t;try{t=new URL(e)}catch{throw Error(`The API URL "${e}" is not a valid URL.`)}let n=t.hostname,r=n===`localhost`||n===`[::1]`||re(n)&&n.startsWith(`127.`);if(t.protocol!==`https:`&&!(t.protocol===`http:`&&r))throw Error(`The API URL "${e}" must use https://, or http:// only for loopback hosts.`);return e}function Ot(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function kt(e){return Ot(e)&&Object.values(e).every(e=>Ot(e)&&typeof e.api_url==`string`&&typeof e.api_key==`string`&&Ot(e.organization)&&typeof e.organization.id==`string`&&typeof e.organization.name==`string`&&typeof e.organization.slug==`string`)}function At(e){try{let t=JSON.parse(e);if(Ot(t)){let e=t.bindings===void 0?{}:t.bindings;if(kt(e))return{bindings:e}}}catch{}throw Error(`Invalid AstralBeam login bindings in ${Tt()}`)}async function jt(){try{return At(await te(Tt(),`utf8`))}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return{bindings:{}};throw e}}async function Mt(e){let t=Tt();await ee(d(t),{recursive:!0,mode:448});let n=`${t}.${r}.tmp`;try{await ne(n,`${JSON.stringify(e,null,2)}\n`,{mode:384,flag:`wx`}),await y(n,t)}catch(e){throw await b(n,{force:!0}),e}}async function Nt(){return await v(t())}function Pt(e,t){for(let n=t;;n=d(n)){let t=e.bindings[n];if(t)return{directory:n,binding:t};if(d(n)===n)return}}function Ft(e){let t=ie();return e===t||e.startsWith(t+m)?`~${e.slice(t.length)}`:e}const I={json:!1,context:void 0,failedRequest:void 0};function It(e){I.context={organization:e.organization,bound_directory:e.directory??null},I.json||a.write(Lt(e))}function Lt(e){let{organization:t,directory:n}=e,r=t.name?`${P(t.name)} (${P(t.slug??``)}) · `:``,i=n?`bound at ${Ft(n)}`:`from ASTRALBEAM_API_KEY`;return`▸ ${r}org ${t.id} · ${i}\n`}function L(e){return{json:e.optsWithGlobals().json===!0}}async function Rt(){let{apiKey:e,apiUrl:t}=await zt();return{apiKey:e,apiUrl:t}}async function zt(){let e=n.ASTRALBEAM_API_KEY,t;if(e)t={apiKey:e,apiUrl:Dt(n.ASTRALBEAM_API_URL??`https://astralbeam.ai/api`),organization:{id:Et(e)}};else{let e=await Nt(),n=Pt(await jt(),e);if(!n)throw Error(`No AstralBeam login covers ${Ft(e)}. Run \`astralbeam auth login\` in this directory or a parent, or set ASTRALBEAM_API_KEY.`);let{binding:r}=n;t={apiKey:r.api_key,apiUrl:Dt(r.api_url),organization:r.organization,directory:n.directory}}return It(t),t}function Bt(e){o.setRawMode(!0),a.write(e),o.setEncoding(`utf8`),o.resume();let t=``;return new Promise((e,n)=>{let r=()=>{o.off(`data`,i),o.setRawMode(!1),o.pause(),a.write(`
|
|
21
21
|
`)},i=i=>{for(let a of i){if(a===`\r`||a===`
|
|
22
22
|
`)return r(),e(t.trim());if(a===``)return r(),n(/* @__PURE__ */ Error(`Cancelled.`));t=a===``||a===`\b`?t.slice(0,-1):t+a}};o.on(`data`,i)})}async function Vt(){return o.isTTY?await Bt(`Paste an organization API key: `):(await _(o)).trim()}async function Ht(e,t){let n=Et(e),{id:r,name:i,slug:a}=await Ie({apiKey:e,apiUrl:t});if(r!==n)throw Error(`The API returned a different organization.`);return{id:r,name:i,slug:a}}function Ut(e){return`${e.slice(0,e.indexOf(`_abo_`)+5)}…${e.slice(-4)}`}function Wt(e){let t=e.command(`auth`).description(`Bind organization API keys to directories, and check them`);t.command(`login`).description(`Verify an API key, read from a hidden prompt or stdin, and bind it to this directory and everything below it`).option(`--api-url <url>`,`API base URL, ending in /api (default ${Ct})`).action(async(e,t)=>{let{json:r}=L(t),i=Dt(e.apiUrl??n.ASTRALBEAM_API_URL??`https://astralbeam.ai/api`),a=await Vt(),o=await Ht(a,i),s=await Nt(),c=await jt();c.bindings[s]={api_url:i,api_key:a,organization:o},await Mt(c),It({apiKey:a,apiUrl:i,organization:o,directory:s}),F({directory:s,organization:o,api_url:i},r)}),t.command(`logout`).description(`Remove the binding that covers this directory`).action(async(e,t)=>{let n=await jt(),r=Pt(n,await Nt());if(!r)throw Error(`No AstralBeam login covers this directory.`);delete n.bindings[r.directory],await Mt(n);let{organization:i}=r.binding;F({directory:r.directory,organization:i},L(t).json)}),t.command(`status`).description(`Show which organization commands here use, and verify the key against the API`).action(async(e,t)=>{let{apiKey:n,apiUrl:r,directory:i}=await zt(),a=await Ht(n,r);if(I.context&&(I.context.organization=a),i){let e=await jt(),t=e.bindings[i];t&&JSON.stringify(t.organization)!==JSON.stringify(a)&&(t.organization=a,await Mt(e))}F({organization:a,api_url:r,api_key:Ut(n),source:i??`ASTRALBEAM_API_KEY`},L(t).json)}),t.command(`list`).description(`List every directory binding`).action(async(e,t)=>{let{bindings:n}=await jt(),r=Object.entries(n).map(([e,t])=>({directory:e,organization:t.organization,api_url:t.api_url}));if(L(t).json)return _t({items:r});if(r.length===0)return void a.write(`No bindings.
|
|
23
23
|
`);bt(r.map(({directory:e,organization:t,api_url:n})=>({directory:Ft(e),name:t.name,slug:t.slug,organization_id:t.id,api_url:n})),[`directory`,`name`,`slug`,`organization_id`,`api_url`])})}const Gt=new TextEncoder,Kt=new TextDecoder,qt=new TextDecoder(`utf-8`,{fatal:!0});function Jt(...e){let t=e.reduce((e,{length:t})=>e+t,0),n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}const Yt=/[^\x00-\x7f]/;function Xt(e){if(typeof e==`string`&&e.length>=128){if(Yt.test(e))throw TypeError(`non-ASCII string encountered in encode()`);return Gt.encode(e)}let t=new Uint8Array(e.length);for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(r>127)throw TypeError(`non-ASCII string encountered in encode()`);t[n]=r}return t}function Zt(e,t=!1){if(Uint8Array.prototype.toBase64)return e.toBase64({alphabet:t?`base64url`:`base64`,omitPadding:t});let n=32768,r=[];for(let t=0;t<e.length;t+=n)r.push(String.fromCharCode.apply(null,e.subarray(t,t+n)));let i=btoa(r.join(``));return t?i.replace(/=/g,``).replace(/\+/g,`-`).replace(/\//g,`_`):i}function Qt(e,t=!1){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(e,{alphabet:t?`base64url`:`base64`});if(t){if(e.includes(`+`)||e.includes(`/`))throw TypeError(`Invalid base64url`);e=e.replace(/-/g,`+`).replace(/_/g,`/`)}let n=atob(e),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r}var $t=class extends Error{static code=`ERR_JOSE_GENERIC`;code=`ERR_JOSE_GENERIC`;constructor(e,t){super(e,t),this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}},en=class extends $t{static code=`ERR_JOSE_NOT_SUPPORTED`;code=`ERR_JOSE_NOT_SUPPORTED`},tn=class extends $t{static code=`ERR_JWS_INVALID`;code=`ERR_JWS_INVALID`},nn=class extends $t{static code=`ERR_JWT_INVALID`;code=`ERR_JWT_INVALID`};function rn(e){try{return Qt(typeof e==`string`?e:Kt.decode(e),!0)}catch(e){throw TypeError(`The input to be decoded is not correctly encoded.`,{cause:e})}}function an(e){return Zt(typeof e==`string`?Gt.encode(e):e,!0)}function on(e){if(typeof e!=`object`||!e||Object.prototype.toString.call(e)!==`[object Object]`)return!1;let t=Object.getPrototypeOf(e);return t===null||Object.getPrototypeOf(t)===null}function sn(...e){let t=/* @__PURE__ */ new Set;for(let n of e)if(n)for(let e of Object.keys(n)){if(t.has(e))return!1;t.add(e)}return!0}function cn(e,t){if(e!==void 0)throw TypeError(`${t} can only be called once`)}const ln={__proto__:null,b64:!0};function un(e,t){let{crit:n}=t??{};if(Array.isArray(n)&&new Set(n).size!==n.length)throw new e(`"crit" (Critical) Header Parameter MUST NOT contain duplicate values`)}function dn(e,t,n,r,i){if(i.crit!==void 0&&r?.crit===void 0)throw new e(`"crit" (Critical) Header Parameter MUST be integrity protected`);if(!r||r.crit===void 0)return[];if(!Array.isArray(r.crit)||r.crit.length===0||r.crit.some(e=>typeof e!=`string`||e.length===0))throw new e(`"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present`);let a=n===void 0?t:{__proto__:null,...n,...t};for(let t of r.crit){if(!(t in a))throw new en(`Extension Header Parameter "${t}" is not recognized`);if(!Object.hasOwn(i,t)||i[t]===void 0)throw new e(`Extension Header Parameter "${t}" is missing`);if(a[t]&&(!Object.hasOwn(r,t)||r[t]===void 0))throw new e(`Extension Header Parameter "${t}" MUST be integrity protected`)}return r.crit}function fn(e,t){if(t.includes(`b64`)){let t=e.b64;if(typeof t!=`boolean`)throw new tn(`The "b64" (base64url-encode payload) Header Parameter must be a boolean`);return t}return!0}function pn(e,t){let n,r;try{n=JSON.stringify(t),r=JSON.parse(n)}catch(t){throw new e(`JOSE Header is not valid JSON`,{cause:t})}if(!on(r))throw new e(`JOSE Header is not a JSON object`);return[r,n]}var mn=Object.defineProperty,hn=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports),gn=(e,t)=>{let n={};for(var r in e)mn(n,r,{get:e[r],enumerable:!0});return t||mn(n,Symbol.toStringTag,{value:`Module`}),n};function _n(e){if(typeof e!=`string`)throw new nn(`JWTs must use Compact JWS serialization, JWT must be a string`);let{1:t,length:n}=e.split(`.`);if(n===5)throw new nn(`Only JWTs using Compact JWS serialization can be decoded`);if(n!==3)throw new nn(`Invalid JWT`);if(!t)throw new nn(`JWTs must contain a payload`);let r;try{r=rn(t)}catch{throw new nn(`Failed to base64url decode the payload`)}let i;try{i=JSON.parse(qt.decode(r))}catch{throw new nn(`Failed to parse the decoded payload as JSON`)}if(!on(i))throw new nn(`Invalid JWT Claims Set`);return i}/* @__NO_SIDE_EFFECTS__ */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astralbeam/cli",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"description": "Command-line interface for AstralBeam organization admins and their coding agents",
|
|
5
5
|
"homepage": "https://astralbeam.ai/docs/cli/getting-started",
|
|
6
6
|
"bugs": "https://github.com/AstralBeamAI/astralbeam/issues",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"typecheck": "tsc --noEmit"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@astralbeam/sdk": "0.23.
|
|
43
|
+
"@astralbeam/sdk": "0.23.1",
|
|
44
44
|
"@types/bun": "1.4.3",
|
|
45
45
|
"@types/node": "^26.2.0",
|
|
46
46
|
"@vitest/eslint-plugin": "^1.6.27",
|