@descript/platform-cli 0.2.5 → 0.2.6

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.
@@ -91,7 +91,7 @@ ${D.default.gray(R)} ${i}
91
91
  `)}
92
92
  `)},info:i=>{d.message(i,{symbol:D.default.blue(an)})},success:i=>{d.message(i,{symbol:D.default.green(Dn)})},step:i=>{d.message(i,{symbol:D.default.green(je)})},warn:i=>{d.message(i,{symbol:D.default.yellow(ln)})},warning:i=>{d.warn(i)},error:i=>{d.message(i,{symbol:D.default.red(cn)})}},ie=()=>{let i=Ft?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],e=Ft?80:120,t,n,u=!1,s="",r=(c="")=>{u=!0,t=gi(),s=c.replace(/\.+$/,""),process.stdout.write(`${D.default.gray(g)}
93
93
  `);let p=0,m=0;n=setInterval(()=>{let C=D.default.magenta(i[p]),h=".".repeat(Math.floor(m)).slice(0,3);process.stdout.write(le.cursor.move(-999,0)),process.stdout.write(le.erase.down(1)),process.stdout.write(`${C} ${s}${h}`),p=p+1<i.length?p+1:0,m=m<i.length?m+.125:0},e)},o=(c="",p=0)=>{s=c??s,u=!1,clearInterval(n);let m=p===0?D.default.green(je):p===1?D.default.red(Ei):D.default.red(bi);process.stdout.write(le.cursor.move(-999,0)),process.stdout.write(le.erase.down(1)),process.stdout.write(`${m} ${s}
94
- `),t()},a=(c="")=>{s=c??s},l=c=>{let p=c>1?"Something went wrong":"Canceled";u&&o(p,c)};return process.on("uncaughtExceptionMonitor",()=>l(2)),process.on("unhandledRejection",()=>l(2)),process.on("SIGINT",()=>l(1)),process.on("SIGTERM",()=>l(1)),process.on("exit",l),{start:r,stop:o,message:a}};function pn(){let i=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");return new RegExp(i,"g")}var hn={"Content-Type":"application/json"},dn=/\{[^{}]+\}/g,At=class extends Request{constructor(e,t){super(e,t);for(let n in t)n in this||(this[n]=t[n])}};function $t(i){let{baseUrl:e="",fetch:t=globalThis.fetch,querySerializer:n,bodySerializer:u,headers:s,...r}={...i};e.endsWith("/")&&(e=e.substring(0,e.length-1)),s=yi(hn,s);let o=[];async function a(l,c){let{fetch:p=t,headers:m,params:C={},parseAs:h="json",querySerializer:f,bodySerializer:F=u??fn,...E}=c||{},O=typeof n=="function"?n:$i(n);f&&(O=typeof f=="function"?f:$i({...typeof n=="object"?n:{},...f}));let U={redirect:"follow",...r,...E,headers:yi(s,m,C.header)};U.body&&(U.body=F(U.body)),U.body instanceof FormData&&U.headers.delete("Content-Type");let Y=new At(gn(l,{baseUrl:e,params:C,querySerializer:O}),U),kt={baseUrl:e,fetch:p,parseAs:h,querySerializer:O,bodySerializer:F};for(let Z of o)if(Z&&typeof Z=="object"&&typeof Z.onRequest=="function"){Y.schemaPath=l,Y.params=C;let Q=await Z.onRequest(Y,kt);if(Q){if(!(Q instanceof Request))throw new Error("Middleware must return new Request() when modifying the request");Y=Q}}let B=await p(Y);for(let Z=o.length-1;Z>=0;Z--){let Q=o[Z];if(Q&&typeof Q=="object"&&typeof Q.onResponse=="function"){Y.schemaPath=l,Y.params=C;let Ke=await Q.onResponse(B,kt,Y);if(Ke){if(!(Ke instanceof Response))throw new Error("Middleware must return new Response() when modifying the response");B=Ke}}}if(B.status===204||B.headers.get("Content-Length")==="0")return B.ok?{data:{},response:B}:{error:{},response:B};if(B.ok)return h==="stream"?{data:B.body,response:B}:{data:await B[h](),response:B};let Ge=await B.text();try{Ge=JSON.parse(Ge)}catch{}return{error:Ge,response:B}}return{async GET(l,c){return a(l,{...c,method:"GET"})},async PUT(l,c){return a(l,{...c,method:"PUT"})},async POST(l,c){return a(l,{...c,method:"POST"})},async DELETE(l,c){return a(l,{...c,method:"DELETE"})},async OPTIONS(l,c){return a(l,{...c,method:"OPTIONS"})},async HEAD(l,c){return a(l,{...c,method:"HEAD"})},async PATCH(l,c){return a(l,{...c,method:"PATCH"})},async TRACE(l,c){return a(l,{...c,method:"TRACE"})},use(...l){for(let c of l)if(c){if(typeof c!="object"||!("onRequest"in c||"onResponse"in c))throw new Error("Middleware must be an object with one of `onRequest()` or `onResponse()`");o.push(c)}},eject(...l){for(let c of l){let p=o.indexOf(c);p!==-1&&o.splice(p,1)}}}}function Te(i,e,t){if(e==null)return"";if(typeof e=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return`${i}=${t?.allowReserved===!0?e:encodeURIComponent(e)}`}function wi(i,e,t){if(!e||typeof e!="object")return"";let n=[],u={simple:",",label:".",matrix:";"}[t.style]||"&";if(t.style!=="deepObject"&&t.explode===!1){for(let o in e)n.push(o,t.allowReserved===!0?e[o]:encodeURIComponent(e[o]));let r=n.join(",");switch(t.style){case"form":return`${i}=${r}`;case"label":return`.${r}`;case"matrix":return`;${i}=${r}`;default:return r}}for(let r in e){let o=t.style==="deepObject"?`${i}[${r}]`:r;n.push(Te(o,e[r],t))}let s=n.join(u);return t.style==="label"||t.style==="matrix"?`${u}${s}`:s}function _i(i,e,t){if(!Array.isArray(e))return"";if(t.explode===!1){let s={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[t.style]||",",r=(t.allowReserved===!0?e:e.map(o=>encodeURIComponent(o))).join(s);switch(t.style){case"simple":return r;case"label":return`.${r}`;case"matrix":return`;${i}=${r}`;default:return`${i}=${r}`}}let n={simple:",",label:".",matrix:";"}[t.style]||"&",u=[];for(let s of e)t.style==="simple"||t.style==="label"?u.push(t.allowReserved===!0?s:encodeURIComponent(s)):u.push(Te(i,s,t));return t.style==="label"||t.style==="matrix"?`${n}${u.join(n)}`:u.join(n)}function $i(i){return function(t){let n=[];if(t&&typeof t=="object")for(let u in t){let s=t[u];if(s!=null){if(Array.isArray(s)){n.push(_i(u,s,{style:"form",explode:!0,...i?.array,allowReserved:i?.allowReserved||!1}));continue}if(typeof s=="object"){n.push(wi(u,s,{style:"deepObject",explode:!0,...i?.object,allowReserved:i?.allowReserved||!1}));continue}n.push(Te(u,s,i))}}return n.join("&")}}function mn(i,e){let t=i;for(let n of i.match(dn)??[]){let u=n.substring(1,n.length-1),s=!1,r="simple";if(u.endsWith("*")&&(s=!0,u=u.substring(0,u.length-1)),u.startsWith(".")?(r="label",u=u.substring(1)):u.startsWith(";")&&(r="matrix",u=u.substring(1)),!e||e[u]===void 0||e[u]===null)continue;let o=e[u];if(Array.isArray(o)){t=t.replace(n,_i(u,o,{style:r,explode:s}));continue}if(typeof o=="object"){t=t.replace(n,wi(u,o,{style:r,explode:s}));continue}if(r==="matrix"){t=t.replace(n,`;${Te(u,o)}`);continue}t=t.replace(n,r==="label"?`.${o}`:o)}return t}function fn(i){return JSON.stringify(i)}function gn(i,e){let t=`${e.baseUrl}${i}`;e.params?.path&&(t=mn(t,e.params.path));let n=e.querySerializer(e.params.query??{});return n.startsWith("?")&&(n=n.substring(1)),n&&(t+=`?${n}`),t}function yi(...i){let e=new Headers;for(let t of i){if(!t||typeof t!="object")continue;let n=t instanceof Headers?t.entries():Object.entries(t);for(let[u,s]of n)if(s===null)e.delete(u);else if(Array.isArray(s))for(let r of s)e.append(u,r);else s!==void 0&&e.set(u,s)}return e}var K=require("node:fs"),vi=require("node:os"),wt=require("node:path");var se=class extends Error{constructor(e){super(e),this.name="CliError"}},T=class extends se{constructor(e){super(e),this.name="ConfigError"}},k=class extends se{constructor(t,n,u,s){super(`API Error (${t}): ${n}`);this.statusCode=t;this.errorType=u;this.details=s;this.name="ApiError"}},G=class extends se{constructor(t,n,u){super(`Job ${t}: ${n??"Unknown error"}`);this.status=t;this.errorMessage=n;this.details=u;this.name="JobError"}formatDetails(){let t=[this.message];if(this.details){let n=this.details.results;if(n)for(let[u,s]of Object.entries(n))s.status==="failed"&&s.error_message&&t.push(` ${u}: ${s.error_message}`)}return t}},Ve=class extends se{constructor(e){super(e),this.name="TimeoutError"}};function pe(i,e){let t=i!=null&&typeof i=="object",n=t&&"message"in i?String(i.message):`HTTP ${e?.status??"unknown"} error`,u=t&&"statusCode"in i?i.statusCode:e?.status,s=[];if(t&&"details"in i&&Array.isArray(i.details))for(let r of i.details)r&&typeof r=="object"&&"message"in r&&s.push(String(r.message));return new k(u??400,n,void 0,s.length>0?s:void 0)}var oe=class extends se{constructor(e){super(e),this.name="ValidationError"}};var yt=(0,wt.join)((0,vi.homedir)(),".descript-cli"),be=(0,wt.join)(yt,"config.json"),J="https://descriptapi.com/v1/",Me="default";function Cn(){(0,K.existsSync)(yt)||(0,K.mkdirSync)(yt,{recursive:!0})}function j(){try{if((0,K.existsSync)(be)){let i=(0,K.readFileSync)(be,"utf-8"),e=JSON.parse(i);return e.profiles?e:{activeProfile:Me,profiles:{[Me]:{apiKey:e.apiKey,apiUrl:e.apiUrl,debug:e.debug}}}}}catch(i){console.error(`Warning: Could not parse config file at ${be}`),i instanceof Error&&console.error(` ${i.message}`)}return{activeProfile:Me,profiles:{}}}function ae(i){Cn(),(0,K.writeFileSync)(be,JSON.stringify(i,null,2))}function Ne(){let i=j(),e=process.env.DESCRIPT_PROFILE||i.activeProfile;return i.profiles[e]||{}}function he(){return process.env.DESCRIPT_API_KEY?process.env.DESCRIPT_API_KEY:Ne().apiKey}function Ae(i){let e=j(),t=e.activeProfile;e.profiles[t]||(e.profiles[t]={}),e.profiles[t].apiKey=i,ae(e)}function $e(){return be}function V(){return process.env.DESCRIPT_API_URL?process.env.DESCRIPT_API_URL:Ne().apiUrl??J}function ye(){return Ne().apiUrl}function Ue(i){let e=j(),t=e.activeProfile;e.profiles[t]||(e.profiles[t]={}),e.profiles[t].apiUrl=i,ae(e)}function _t(){let i=j(),e=i.activeProfile;i.profiles[e]&&(delete i.profiles[e].apiUrl,ae(i))}function _(){return process.env.DESCRIPT_DEBUG?process.env.DESCRIPT_DEBUG==="true"||process.env.DESCRIPT_DEBUG==="1":Ne().debug??!1}function vt(i){let e=j(),t=e.activeProfile;e.profiles[t]||(e.profiles[t]={}),e.profiles[t].debug=i,ae(e)}function qe(){return process.env.DESCRIPT_PROFILE?process.env.DESCRIPT_PROFILE:j().activeProfile}function xt(){let i=j();return Object.keys(i.profiles)}function Bt(i){let e=j();if(!e.profiles[i])throw new T(`Profile "${i}" does not exist`);e.activeProfile=i,ae(e)}function Ot(i){let e=j();if(e.profiles[i])throw new T(`Profile "${i}" already exists`);e.profiles[i]={},ae(e)}function xi(i){let e=j();if(i===Me)throw new T("Cannot delete the default profile");if(!e.profiles[i])throw new T(`Profile "${i}" does not exist`);if(e.activeProfile===i)throw new T("Cannot delete the active profile. Switch to another profile first.");delete e.profiles[i],ae(e)}function Bi(i){let e=j();return i in e.profiles}var Fn="@descript/platform-cli",En="0.2.5";function bn(i){return i.length<=12?"Bearer ***":`Bearer ${i.slice(0,8)}...${i.slice(-4)}`}function Oi(i,e){let t=$t({baseUrl:e,headers:{Authorization:`Bearer ${i}`,"User-Agent":`${Fn}/${En} node/${process.version}`}});return _()&&t.use({async onRequest(u){try{if(console.error(`
94
+ `),t()},a=(c="")=>{s=c??s},l=c=>{let p=c>1?"Something went wrong":"Canceled";u&&o(p,c)};return process.on("uncaughtExceptionMonitor",()=>l(2)),process.on("unhandledRejection",()=>l(2)),process.on("SIGINT",()=>l(1)),process.on("SIGTERM",()=>l(1)),process.on("exit",l),{start:r,stop:o,message:a}};function pn(){let i=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");return new RegExp(i,"g")}var hn={"Content-Type":"application/json"},dn=/\{[^{}]+\}/g,At=class extends Request{constructor(e,t){super(e,t);for(let n in t)n in this||(this[n]=t[n])}};function $t(i){let{baseUrl:e="",fetch:t=globalThis.fetch,querySerializer:n,bodySerializer:u,headers:s,...r}={...i};e.endsWith("/")&&(e=e.substring(0,e.length-1)),s=yi(hn,s);let o=[];async function a(l,c){let{fetch:p=t,headers:m,params:C={},parseAs:h="json",querySerializer:f,bodySerializer:F=u??fn,...E}=c||{},O=typeof n=="function"?n:$i(n);f&&(O=typeof f=="function"?f:$i({...typeof n=="object"?n:{},...f}));let U={redirect:"follow",...r,...E,headers:yi(s,m,C.header)};U.body&&(U.body=F(U.body)),U.body instanceof FormData&&U.headers.delete("Content-Type");let Y=new At(gn(l,{baseUrl:e,params:C,querySerializer:O}),U),kt={baseUrl:e,fetch:p,parseAs:h,querySerializer:O,bodySerializer:F};for(let Z of o)if(Z&&typeof Z=="object"&&typeof Z.onRequest=="function"){Y.schemaPath=l,Y.params=C;let Q=await Z.onRequest(Y,kt);if(Q){if(!(Q instanceof Request))throw new Error("Middleware must return new Request() when modifying the request");Y=Q}}let B=await p(Y);for(let Z=o.length-1;Z>=0;Z--){let Q=o[Z];if(Q&&typeof Q=="object"&&typeof Q.onResponse=="function"){Y.schemaPath=l,Y.params=C;let Ke=await Q.onResponse(B,kt,Y);if(Ke){if(!(Ke instanceof Response))throw new Error("Middleware must return new Response() when modifying the response");B=Ke}}}if(B.status===204||B.headers.get("Content-Length")==="0")return B.ok?{data:{},response:B}:{error:{},response:B};if(B.ok)return h==="stream"?{data:B.body,response:B}:{data:await B[h](),response:B};let Ge=await B.text();try{Ge=JSON.parse(Ge)}catch{}return{error:Ge,response:B}}return{async GET(l,c){return a(l,{...c,method:"GET"})},async PUT(l,c){return a(l,{...c,method:"PUT"})},async POST(l,c){return a(l,{...c,method:"POST"})},async DELETE(l,c){return a(l,{...c,method:"DELETE"})},async OPTIONS(l,c){return a(l,{...c,method:"OPTIONS"})},async HEAD(l,c){return a(l,{...c,method:"HEAD"})},async PATCH(l,c){return a(l,{...c,method:"PATCH"})},async TRACE(l,c){return a(l,{...c,method:"TRACE"})},use(...l){for(let c of l)if(c){if(typeof c!="object"||!("onRequest"in c||"onResponse"in c))throw new Error("Middleware must be an object with one of `onRequest()` or `onResponse()`");o.push(c)}},eject(...l){for(let c of l){let p=o.indexOf(c);p!==-1&&o.splice(p,1)}}}}function Te(i,e,t){if(e==null)return"";if(typeof e=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return`${i}=${t?.allowReserved===!0?e:encodeURIComponent(e)}`}function wi(i,e,t){if(!e||typeof e!="object")return"";let n=[],u={simple:",",label:".",matrix:";"}[t.style]||"&";if(t.style!=="deepObject"&&t.explode===!1){for(let o in e)n.push(o,t.allowReserved===!0?e[o]:encodeURIComponent(e[o]));let r=n.join(",");switch(t.style){case"form":return`${i}=${r}`;case"label":return`.${r}`;case"matrix":return`;${i}=${r}`;default:return r}}for(let r in e){let o=t.style==="deepObject"?`${i}[${r}]`:r;n.push(Te(o,e[r],t))}let s=n.join(u);return t.style==="label"||t.style==="matrix"?`${u}${s}`:s}function _i(i,e,t){if(!Array.isArray(e))return"";if(t.explode===!1){let s={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[t.style]||",",r=(t.allowReserved===!0?e:e.map(o=>encodeURIComponent(o))).join(s);switch(t.style){case"simple":return r;case"label":return`.${r}`;case"matrix":return`;${i}=${r}`;default:return`${i}=${r}`}}let n={simple:",",label:".",matrix:";"}[t.style]||"&",u=[];for(let s of e)t.style==="simple"||t.style==="label"?u.push(t.allowReserved===!0?s:encodeURIComponent(s)):u.push(Te(i,s,t));return t.style==="label"||t.style==="matrix"?`${n}${u.join(n)}`:u.join(n)}function $i(i){return function(t){let n=[];if(t&&typeof t=="object")for(let u in t){let s=t[u];if(s!=null){if(Array.isArray(s)){n.push(_i(u,s,{style:"form",explode:!0,...i?.array,allowReserved:i?.allowReserved||!1}));continue}if(typeof s=="object"){n.push(wi(u,s,{style:"deepObject",explode:!0,...i?.object,allowReserved:i?.allowReserved||!1}));continue}n.push(Te(u,s,i))}}return n.join("&")}}function mn(i,e){let t=i;for(let n of i.match(dn)??[]){let u=n.substring(1,n.length-1),s=!1,r="simple";if(u.endsWith("*")&&(s=!0,u=u.substring(0,u.length-1)),u.startsWith(".")?(r="label",u=u.substring(1)):u.startsWith(";")&&(r="matrix",u=u.substring(1)),!e||e[u]===void 0||e[u]===null)continue;let o=e[u];if(Array.isArray(o)){t=t.replace(n,_i(u,o,{style:r,explode:s}));continue}if(typeof o=="object"){t=t.replace(n,wi(u,o,{style:r,explode:s}));continue}if(r==="matrix"){t=t.replace(n,`;${Te(u,o)}`);continue}t=t.replace(n,r==="label"?`.${o}`:o)}return t}function fn(i){return JSON.stringify(i)}function gn(i,e){let t=`${e.baseUrl}${i}`;e.params?.path&&(t=mn(t,e.params.path));let n=e.querySerializer(e.params.query??{});return n.startsWith("?")&&(n=n.substring(1)),n&&(t+=`?${n}`),t}function yi(...i){let e=new Headers;for(let t of i){if(!t||typeof t!="object")continue;let n=t instanceof Headers?t.entries():Object.entries(t);for(let[u,s]of n)if(s===null)e.delete(u);else if(Array.isArray(s))for(let r of s)e.append(u,r);else s!==void 0&&e.set(u,s)}return e}var K=require("node:fs"),vi=require("node:os"),wt=require("node:path");var se=class extends Error{constructor(e){super(e),this.name="CliError"}},T=class extends se{constructor(e){super(e),this.name="ConfigError"}},k=class extends se{constructor(t,n,u,s){super(`API Error (${t}): ${n}`);this.statusCode=t;this.errorType=u;this.details=s;this.name="ApiError"}},G=class extends se{constructor(t,n,u){super(`Job ${t}: ${n??"Unknown error"}`);this.status=t;this.errorMessage=n;this.details=u;this.name="JobError"}formatDetails(){let t=[this.message];if(this.details){let n=this.details.results;if(n)for(let[u,s]of Object.entries(n))s.status==="failed"&&s.error_message&&t.push(` ${u}: ${s.error_message}`)}return t}},Ve=class extends se{constructor(e){super(e),this.name="TimeoutError"}};function pe(i,e){let t=i!=null&&typeof i=="object",n=t&&"message"in i?String(i.message):`HTTP ${e?.status??"unknown"} error`,u=t&&"statusCode"in i?i.statusCode:e?.status,s=[];if(t&&"details"in i&&Array.isArray(i.details))for(let r of i.details)r&&typeof r=="object"&&"message"in r&&s.push(String(r.message));return new k(u??400,n,void 0,s.length>0?s:void 0)}var oe=class extends se{constructor(e){super(e),this.name="ValidationError"}};var yt=(0,wt.join)((0,vi.homedir)(),".descript-cli"),be=(0,wt.join)(yt,"config.json"),J="https://descriptapi.com/v1/",Me="default";function Cn(){(0,K.existsSync)(yt)||(0,K.mkdirSync)(yt,{recursive:!0})}function j(){try{if((0,K.existsSync)(be)){let i=(0,K.readFileSync)(be,"utf-8"),e=JSON.parse(i);return e.profiles?e:{activeProfile:Me,profiles:{[Me]:{apiKey:e.apiKey,apiUrl:e.apiUrl,debug:e.debug}}}}}catch(i){console.error(`Warning: Could not parse config file at ${be}`),i instanceof Error&&console.error(` ${i.message}`)}return{activeProfile:Me,profiles:{}}}function ae(i){Cn(),(0,K.writeFileSync)(be,JSON.stringify(i,null,2))}function Ne(){let i=j(),e=process.env.DESCRIPT_PROFILE||i.activeProfile;return i.profiles[e]||{}}function he(){return process.env.DESCRIPT_API_KEY?process.env.DESCRIPT_API_KEY:Ne().apiKey}function Ae(i){let e=j(),t=e.activeProfile;e.profiles[t]||(e.profiles[t]={}),e.profiles[t].apiKey=i,ae(e)}function $e(){return be}function V(){return process.env.DESCRIPT_API_URL?process.env.DESCRIPT_API_URL:Ne().apiUrl??J}function ye(){return Ne().apiUrl}function Ue(i){let e=j(),t=e.activeProfile;e.profiles[t]||(e.profiles[t]={}),e.profiles[t].apiUrl=i,ae(e)}function _t(){let i=j(),e=i.activeProfile;i.profiles[e]&&(delete i.profiles[e].apiUrl,ae(i))}function _(){return process.env.DESCRIPT_DEBUG?process.env.DESCRIPT_DEBUG==="true"||process.env.DESCRIPT_DEBUG==="1":Ne().debug??!1}function vt(i){let e=j(),t=e.activeProfile;e.profiles[t]||(e.profiles[t]={}),e.profiles[t].debug=i,ae(e)}function qe(){return process.env.DESCRIPT_PROFILE?process.env.DESCRIPT_PROFILE:j().activeProfile}function xt(){let i=j();return Object.keys(i.profiles)}function Bt(i){let e=j();if(!e.profiles[i])throw new T(`Profile "${i}" does not exist`);e.activeProfile=i,ae(e)}function Ot(i){let e=j();if(e.profiles[i])throw new T(`Profile "${i}" already exists`);e.profiles[i]={},ae(e)}function xi(i){let e=j();if(i===Me)throw new T("Cannot delete the default profile");if(!e.profiles[i])throw new T(`Profile "${i}" does not exist`);if(e.activeProfile===i)throw new T("Cannot delete the active profile. Switch to another profile first.");delete e.profiles[i],ae(e)}function Bi(i){let e=j();return i in e.profiles}var Fn="@descript/platform-cli",En="0.2.6";function bn(i){return i.length<=12?"Bearer ***":`Bearer ${i.slice(0,8)}...${i.slice(-4)}`}function Oi(i,e){let t=$t({baseUrl:e,headers:{Authorization:`Bearer ${i}`,"User-Agent":`${Fn}/${En} node/${process.version}`}});return _()&&t.use({async onRequest(u){try{if(console.error(`
95
95
  --- API Request ---`),console.error(`${u.method} ${u.url}`),u.headers){let s=Object.fromEntries(u.headers.entries());s.authorization&&(s.authorization=bn(i)),console.error("Headers:",s)}if(u.body)try{let r=await u.clone().text();r&&console.error("Body:",JSON.stringify(JSON.parse(r),null,2))}catch{}console.error(`-------------------
96
96
  `)}catch(s){console.error("Error logging request:",s instanceof Error?s.message:s)}return u}}),t}function Le(){let i=he();if(!i)throw new T("API key not configured. Run `descript-api config` to set up.");return Oi(i,V())}function Si(i){return Oi(i,V())}var me=["api-key","api-url","debug"];function Pi(i){return i.length<=12?"***":i.slice(0,8)+"..."+i.slice(-4)}function de(i){switch(i){case"api-key":return he();case"api-url":return ye();case"debug":return _()}}function St(i,e){switch(i){case"api-key":Ae(e);break;case"api-url":Ue(e);break;case"debug":vt(e);break}}function Ii(i,e){if(i==="api-url"){let t=V();return e||`${t} (default)`}return i==="debug"?e?"enabled":"disabled":e?i==="api-key"?Pi(e):e:"Not configured"}async function Pt(i){let e=ie();e.start("Validating API key...");try{let t=Si(i),{error:n}=await t.GET("/status");return n!=null&&typeof n=="object"&&"error"in n&&n.error==="unauthorized"?(e.stop("Invalid API key"),!1):(e.stop("API key validated successfully!"),!0)}catch{return e.stop("Could not validate (saved anyway)"),!0}}var M=new X("config").description("Manage CLI configuration").addHelpText("after",`
97
97
  Profile Commands:
@@ -133,4 +133,4 @@ API error response:`),console.error(JSON.stringify(c,null,2))),pe(c,p);if(!l)thr
133
133
  Agent job response:`),console.log(JSON.stringify(l,null,2)));let m=[`Job ID: ${l.job_id}`,`Project ID: ${l.project_id}`,`Project URL: ${l.project_url}`];W(z(m.join(`
134
134
  `)),"Agent Job Submitted");let C=await He(e,l.job_id,"Waiting for agent to complete...",{timeoutMs:n});if(C&&C.job_type==="agent"&&C.result){let h=C.result;if(h.status!=="error"){h.agent_response&&(d.step("Agent Response"),d.message(Wi(h.agent_response)));let f=[`Status: ${h.status}`];f.push(`Project changed: ${h.project_changed?"yes":"no"}`),h.media_seconds_used!=null&&f.push(`Media seconds used: ${h.media_seconds_used}`),h.ai_credits_used!=null&&f.push(`AI credits used: ${h.ai_credits_used}`),W(z(f.join(`
135
135
  `)),"Agent Complete")}else W(z(`Status: ${h.status}`),"Agent Complete")}ce(`Project: ${l.project_url}`)}catch(e){if(e instanceof G){let t=e.formatDetails();w(t[0]),t.length>1&&d.error(t.slice(1).join(`
136
- `))}else if(e instanceof k){if(w(e.message),e.details&&e.details.length>0)for(let t of e.details)d.error(` ${t}`)}else e instanceof Error?w(e.message):w("An unexpected error occurred");process.exit(1)}});var Un="@descript/platform-cli",zi="0.2.5",N=new X;N.name("descript-api").description("CLI for Descript API - import media and run AI edits").version(zi);N.addCommand(M);N.addCommand(Gi);N.addCommand(Ki);N.command("help [command]").description("Show help for a command").action(i=>{if(!i){N.help();return}let e=N.commands.find(t=>t.name()===i);e?e.help():(console.error(`Unknown command: ${i}`),console.error("Run 'descript-api --help' to see available commands."),process.exit(1))});N.action(()=>{N.help()});function Yi(i){N.parse(i,{from:"user"}),(0,Ji.default)({pkg:{name:Un,version:zi}}).notify()}Yi(process.argv.slice(2));
136
+ `))}else if(e instanceof k){if(w(e.message),e.details&&e.details.length>0)for(let t of e.details)d.error(` ${t}`)}else e instanceof Error?w(e.message):w("An unexpected error occurred");process.exit(1)}});var Un="@descript/platform-cli",zi="0.2.6",N=new X;N.name("descript-api").description("CLI for Descript API - import media and run AI edits").version(zi);N.addCommand(M);N.addCommand(Gi);N.addCommand(Ki);N.command("help [command]").description("Show help for a command").action(i=>{if(!i){N.help();return}let e=N.commands.find(t=>t.name()===i);e?e.help():(console.error(`Unknown command: ${i}`),console.error("Run 'descript-api --help' to see available commands."),process.exit(1))});N.action(()=>{N.help()});function Yi(i){N.parse(i,{from:"user"}),(0,Ji.default)({pkg:{name:Un,version:zi}}).notify()}Yi(process.argv.slice(2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descript/platform-cli",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "CLI for Descript API - import media and run AI edits",
5
5
  "type": "module",
6
6
  "license": "MIT",