@descript/platform-cli 0.2.3 → 0.2.4
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/descript-cli.cjs +2 -2
- package/package.json +1 -1
package/dist/descript-cli.cjs
CHANGED
|
@@ -125,7 +125,7 @@ ${d.default.gray(Le)} ${e}
|
|
|
125
125
|
`)}
|
|
126
126
|
`)},info:e=>{x.message(e,{symbol:d.default.blue(ig)})},success:e=>{x.message(e,{symbol:d.default.green(sg)})},step:e=>{x.message(e,{symbol:d.default.green(Gu)})},warn:e=>{x.message(e,{symbol:d.default.yellow(og)})},warning:e=>{x.warn(e)},error:e=>{x.message(e,{symbol:d.default.red(Dg)})}},ot=()=>{let e=is?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],t=is?80:120,r,u,n=!1,s="",i=(D="")=>{n=!0,r=_f(),s=D.replace(/\.+$/,""),process.stdout.write(`${d.default.gray(P)}
|
|
127
127
|
`);let l=0,p=0;u=setInterval(()=>{let f=d.default.magenta(e[l]),h=".".repeat(Math.floor(p)).slice(0,3);process.stdout.write(Kt.cursor.move(-999,0)),process.stdout.write(Kt.erase.down(1)),process.stdout.write(`${f} ${s}${h}`),l=l+1<e.length?l+1:0,p=p<e.length?p+.125:0},t)},o=(D="",l=0)=>{s=D??s,n=!1,clearInterval(u);let p=l===0?d.default.green(Gu):l===1?d.default.red(Rf):d.default.red(If);process.stdout.write(Kt.cursor.move(-999,0)),process.stdout.write(Kt.erase.down(1)),process.stdout.write(`${p} ${s}
|
|
128
|
-
`),r()},c=(D="")=>{s=D??s},a=D=>{let l=D>1?"Something went wrong":"Canceled";n&&o(l,D)};return process.on("uncaughtExceptionMonitor",()=>a(2)),process.on("unhandledRejection",()=>a(2)),process.on("SIGINT",()=>a(1)),process.on("SIGTERM",()=>a(1)),process.on("exit",a),{start:i,stop:o,message:c}};function ag(){let e=["[\\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(e,"g")}var cg={"Content-Type":"application/json"},lg=/\{[^{}]+\}/g,Ds=class extends Request{constructor(t,r){super(t,r);for(let u in r)u in this||(this[u]=r[u])}};function as(e){let{baseUrl:t="",fetch:r=globalThis.fetch,querySerializer:u,bodySerializer:n,headers:s,...i}={...e};t.endsWith("/")&&(t=t.substring(0,t.length-1)),s=Pf(cg,s);let o=[];async function c(a,D){let{fetch:l=r,headers:p,params:f={},parseAs:h="json",querySerializer:m,bodySerializer:F=n??pg,...g}=D||{},$=typeof u=="function"?u:Nf(u);m&&($=typeof m=="function"?m:Nf({...typeof u=="object"?u:{},...m}));let v={redirect:"follow",...i,...g,headers:Pf(s,p,f.header)};v.body&&(v.body=F(v.body)),v.body instanceof FormData&&v.headers.delete("Content-Type");let w=new Ds(hg(a,{baseUrl:t,params:f,querySerializer:$}),v),V={baseUrl:t,fetch:l,parseAs:h,querySerializer:$,bodySerializer:F};for(let Z of o)if(Z&&typeof Z=="object"&&typeof Z.onRequest=="function"){w.schemaPath=a,w.params=f;let E=await Z.onRequest(w,V);if(E){if(!(E instanceof Request))throw new Error("Middleware must return new Request() when modifying the request");w=E}}let L=await l(w);for(let Z=o.length-1;Z>=0;Z--){let E=o[Z];if(E&&typeof E=="object"&&typeof E.onResponse=="function"){w.schemaPath=a,w.params=f;let y=await E.onResponse(L,V,w);if(y){if(!(y instanceof Response))throw new Error("Middleware must return new Response() when modifying the response");L=y}}}if(L.status===204||L.headers.get("Content-Length")==="0")return L.ok?{data:{},response:L}:{error:{},response:L};if(L.ok)return h==="stream"?{data:L.body,response:L}:{data:await L[h](),response:L};let N=await L.text();try{N=JSON.parse(N)}catch{}return{error:N,response:L}}return{async GET(a,D){return c(a,{...D,method:"GET"})},async PUT(a,D){return c(a,{...D,method:"PUT"})},async POST(a,D){return c(a,{...D,method:"POST"})},async DELETE(a,D){return c(a,{...D,method:"DELETE"})},async OPTIONS(a,D){return c(a,{...D,method:"OPTIONS"})},async HEAD(a,D){return c(a,{...D,method:"HEAD"})},async PATCH(a,D){return c(a,{...D,method:"PATCH"})},async TRACE(a,D){return c(a,{...D,method:"TRACE"})},use(...a){for(let D of a)if(D){if(typeof D!="object"||!("onRequest"in D||"onResponse"in D))throw new Error("Middleware must be an object with one of `onRequest()` or `onResponse()`");o.push(D)}},eject(...a){for(let D of a){let l=o.indexOf(D);l!==-1&&o.splice(l,1)}}}}function Hu(e,t,r){if(t==null)return"";if(typeof t=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return`${e}=${r?.allowReserved===!0?t:encodeURIComponent(t)}`}function Lf(e,t,r){if(!t||typeof t!="object")return"";let u=[],n={simple:",",label:".",matrix:";"}[r.style]||"&";if(r.style!=="deepObject"&&r.explode===!1){for(let o in t)u.push(o,r.allowReserved===!0?t[o]:encodeURIComponent(t[o]));let i=u.join(",");switch(r.style){case"form":return`${e}=${i}`;case"label":return`.${i}`;case"matrix":return`;${e}=${i}`;default:return i}}for(let i in t){let o=r.style==="deepObject"?`${e}[${i}]`:i;u.push(Hu(o,t[i],r))}let s=u.join(n);return r.style==="label"||r.style==="matrix"?`${n}${s}`:s}function jf(e,t,r){if(!Array.isArray(t))return"";if(r.explode===!1){let s={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[r.style]||",",i=(r.allowReserved===!0?t:t.map(o=>encodeURIComponent(o))).join(s);switch(r.style){case"simple":return i;case"label":return`.${i}`;case"matrix":return`;${e}=${i}`;default:return`${e}=${i}`}}let u={simple:",",label:".",matrix:";"}[r.style]||"&",n=[];for(let s of t)r.style==="simple"||r.style==="label"?n.push(r.allowReserved===!0?s:encodeURIComponent(s)):n.push(Hu(e,s,r));return r.style==="label"||r.style==="matrix"?`${u}${n.join(u)}`:n.join(u)}function Nf(e){return function(r){let u=[];if(r&&typeof r=="object")for(let n in r){let s=r[n];if(s!=null){if(Array.isArray(s)){u.push(jf(n,s,{style:"form",explode:!0,...e?.array,allowReserved:e?.allowReserved||!1}));continue}if(typeof s=="object"){u.push(Lf(n,s,{style:"deepObject",explode:!0,...e?.object,allowReserved:e?.allowReserved||!1}));continue}u.push(Hu(n,s,e))}}return u.join("&")}}function fg(e,t){let r=e;for(let u of e.match(lg)??[]){let n=u.substring(1,u.length-1),s=!1,i="simple";if(n.endsWith("*")&&(s=!0,n=n.substring(0,n.length-1)),n.startsWith(".")?(i="label",n=n.substring(1)):n.startsWith(";")&&(i="matrix",n=n.substring(1)),!t||t[n]===void 0||t[n]===null)continue;let o=t[n];if(Array.isArray(o)){r=r.replace(u,jf(n,o,{style:i,explode:s}));continue}if(typeof o=="object"){r=r.replace(u,Lf(n,o,{style:i,explode:s}));continue}if(i==="matrix"){r=r.replace(u,`;${Hu(n,o)}`);continue}r=r.replace(u,i==="label"?`.${o}`:o)}return r}function pg(e){return JSON.stringify(e)}function hg(e,t){let r=`${t.baseUrl}${e}`;t.params?.path&&(r=fg(r,t.params.path));let u=t.querySerializer(t.params.query??{});return u.startsWith("?")&&(u=u.substring(1)),u&&(r+=`?${u}`),r}function Pf(...e){let t=new Headers;for(let r of e){if(!r||typeof r!="object")continue;let u=r instanceof Headers?r.entries():Object.entries(r);for(let[n,s]of u)if(s===null)t.delete(n);else if(Array.isArray(s))for(let i of s)t.append(n,i);else s!==void 0&&t.set(n,s)}return t}var Ye=require("node:fs"),kf=require("node:os"),ls=require("node:path");var xt=class extends Error{constructor(t){super(t),this.name="CliError"}},je=class extends xt{constructor(t){super(t),this.name="ConfigError"}},Se=class extends xt{constructor(r,u,n,s){super(`API Error (${r}): ${u}`);this.statusCode=r;this.errorType=n;this.details=s;this.name="ApiError"}},Ke=class extends xt{constructor(r,u,n){super(`Job ${r}: ${u??"Unknown error"}`);this.status=r;this.errorMessage=u;this.details=n;this.name="JobError"}formatDetails(){let r=[this.message];if(this.details){let u=this.details.results;if(u)for(let[n,s]of Object.entries(u))s.status==="failed"&&s.error_message&&r.push(` ${n}: ${s.error_message}`)}return r}},Ku=class extends xt{constructor(t){super(t),this.name="TimeoutError"}};function Jt(e,t){let r=e!=null&&typeof e=="object",u=r&&"message"in e?String(e.message):`HTTP ${t?.status??"unknown"} error`,n=r&&"statusCode"in e?e.statusCode:t?.status,s=[];if(r&&"details"in e&&Array.isArray(e.details))for(let i of e.details)i&&typeof i=="object"&&"message"in i&&s.push(String(i.message));return new Se(n??400,u,void 0,s.length>0?s:void 0)}var St=class extends xt{constructor(t){super(t),this.name="ValidationError"}};var cs=(0,ls.join)((0,kf.homedir)(),".descript-cli"),Tr=(0,ls.join)(cs,"config.json"),Je="https://descriptapi.com/v1/",Yu="default";function dg(){(0,Ye.existsSync)(cs)||(0,Ye.mkdirSync)(cs,{recursive:!0})}function Oe(){try{if((0,Ye.existsSync)(Tr)){let e=(0,Ye.readFileSync)(Tr,"utf-8"),t=JSON.parse(e);return t.profiles?t:{activeProfile:Yu,profiles:{[Yu]:{apiKey:t.apiKey,apiUrl:t.apiUrl,debug:t.debug}}}}}catch(e){console.error(`Warning: Could not parse config file at ${Tr}`),e instanceof Error&&console.error(` ${e.message}`)}return{activeProfile:Yu,profiles:{}}}function _t(e){dg(),(0,Ye.writeFileSync)(Tr,JSON.stringify(e,null,2))}function Ju(){let e=Oe(),t=process.env.DESCRIPT_PROFILE||e.activeProfile;return e.profiles[t]||{}}function zt(){return process.env.DESCRIPT_API_KEY?process.env.DESCRIPT_API_KEY:Ju().apiKey}function Nr(e){let t=Oe(),r=t.activeProfile;t.profiles[r]||(t.profiles[r]={}),t.profiles[r].apiKey=e,_t(t)}function Pr(){return Tr}function ke(){return process.env.DESCRIPT_API_URL?process.env.DESCRIPT_API_URL:Ju().apiUrl??Je}function Lr(){return Ju().apiUrl}function zu(e){let t=Oe(),r=t.activeProfile;t.profiles[r]||(t.profiles[r]={}),t.profiles[r].apiUrl=e,_t(t)}function fs(){let e=Oe(),t=e.activeProfile;e.profiles[t]&&(delete e.profiles[t].apiUrl,_t(e))}function ae(){return process.env.DESCRIPT_DEBUG?process.env.DESCRIPT_DEBUG==="true"||process.env.DESCRIPT_DEBUG==="1":Ju().debug??!1}function ps(e){let t=Oe(),r=t.activeProfile;t.profiles[r]||(t.profiles[r]={}),t.profiles[r].debug=e,_t(t)}function Xu(){return process.env.DESCRIPT_PROFILE?process.env.DESCRIPT_PROFILE:Oe().activeProfile}function hs(){let e=Oe();return Object.keys(e.profiles)}function ds(e){let t=Oe();if(!t.profiles[e])throw new je(`Profile "${e}" does not exist`);t.activeProfile=e,_t(t)}function ms(e){let t=Oe();if(t.profiles[e])throw new je(`Profile "${e}" already exists`);t.profiles[e]={},_t(t)}function qf(e){let t=Oe();if(e===Yu)throw new je("Cannot delete the default profile");if(!t.profiles[e])throw new je(`Profile "${e}" does not exist`);if(t.activeProfile===e)throw new je("Cannot delete the active profile. Switch to another profile first.");delete t.profiles[e],_t(t)}function Mf(e){let t=Oe();return e in t.profiles}var mg="@descript/platform-cli",Fg="0.2.
|
|
128
|
+
`),r()},c=(D="")=>{s=D??s},a=D=>{let l=D>1?"Something went wrong":"Canceled";n&&o(l,D)};return process.on("uncaughtExceptionMonitor",()=>a(2)),process.on("unhandledRejection",()=>a(2)),process.on("SIGINT",()=>a(1)),process.on("SIGTERM",()=>a(1)),process.on("exit",a),{start:i,stop:o,message:c}};function ag(){let e=["[\\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(e,"g")}var cg={"Content-Type":"application/json"},lg=/\{[^{}]+\}/g,Ds=class extends Request{constructor(t,r){super(t,r);for(let u in r)u in this||(this[u]=r[u])}};function as(e){let{baseUrl:t="",fetch:r=globalThis.fetch,querySerializer:u,bodySerializer:n,headers:s,...i}={...e};t.endsWith("/")&&(t=t.substring(0,t.length-1)),s=Pf(cg,s);let o=[];async function c(a,D){let{fetch:l=r,headers:p,params:f={},parseAs:h="json",querySerializer:m,bodySerializer:F=n??pg,...g}=D||{},$=typeof u=="function"?u:Nf(u);m&&($=typeof m=="function"?m:Nf({...typeof u=="object"?u:{},...m}));let v={redirect:"follow",...i,...g,headers:Pf(s,p,f.header)};v.body&&(v.body=F(v.body)),v.body instanceof FormData&&v.headers.delete("Content-Type");let w=new Ds(hg(a,{baseUrl:t,params:f,querySerializer:$}),v),V={baseUrl:t,fetch:l,parseAs:h,querySerializer:$,bodySerializer:F};for(let Z of o)if(Z&&typeof Z=="object"&&typeof Z.onRequest=="function"){w.schemaPath=a,w.params=f;let E=await Z.onRequest(w,V);if(E){if(!(E instanceof Request))throw new Error("Middleware must return new Request() when modifying the request");w=E}}let L=await l(w);for(let Z=o.length-1;Z>=0;Z--){let E=o[Z];if(E&&typeof E=="object"&&typeof E.onResponse=="function"){w.schemaPath=a,w.params=f;let y=await E.onResponse(L,V,w);if(y){if(!(y instanceof Response))throw new Error("Middleware must return new Response() when modifying the response");L=y}}}if(L.status===204||L.headers.get("Content-Length")==="0")return L.ok?{data:{},response:L}:{error:{},response:L};if(L.ok)return h==="stream"?{data:L.body,response:L}:{data:await L[h](),response:L};let N=await L.text();try{N=JSON.parse(N)}catch{}return{error:N,response:L}}return{async GET(a,D){return c(a,{...D,method:"GET"})},async PUT(a,D){return c(a,{...D,method:"PUT"})},async POST(a,D){return c(a,{...D,method:"POST"})},async DELETE(a,D){return c(a,{...D,method:"DELETE"})},async OPTIONS(a,D){return c(a,{...D,method:"OPTIONS"})},async HEAD(a,D){return c(a,{...D,method:"HEAD"})},async PATCH(a,D){return c(a,{...D,method:"PATCH"})},async TRACE(a,D){return c(a,{...D,method:"TRACE"})},use(...a){for(let D of a)if(D){if(typeof D!="object"||!("onRequest"in D||"onResponse"in D))throw new Error("Middleware must be an object with one of `onRequest()` or `onResponse()`");o.push(D)}},eject(...a){for(let D of a){let l=o.indexOf(D);l!==-1&&o.splice(l,1)}}}}function Hu(e,t,r){if(t==null)return"";if(typeof t=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return`${e}=${r?.allowReserved===!0?t:encodeURIComponent(t)}`}function Lf(e,t,r){if(!t||typeof t!="object")return"";let u=[],n={simple:",",label:".",matrix:";"}[r.style]||"&";if(r.style!=="deepObject"&&r.explode===!1){for(let o in t)u.push(o,r.allowReserved===!0?t[o]:encodeURIComponent(t[o]));let i=u.join(",");switch(r.style){case"form":return`${e}=${i}`;case"label":return`.${i}`;case"matrix":return`;${e}=${i}`;default:return i}}for(let i in t){let o=r.style==="deepObject"?`${e}[${i}]`:i;u.push(Hu(o,t[i],r))}let s=u.join(n);return r.style==="label"||r.style==="matrix"?`${n}${s}`:s}function jf(e,t,r){if(!Array.isArray(t))return"";if(r.explode===!1){let s={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[r.style]||",",i=(r.allowReserved===!0?t:t.map(o=>encodeURIComponent(o))).join(s);switch(r.style){case"simple":return i;case"label":return`.${i}`;case"matrix":return`;${e}=${i}`;default:return`${e}=${i}`}}let u={simple:",",label:".",matrix:";"}[r.style]||"&",n=[];for(let s of t)r.style==="simple"||r.style==="label"?n.push(r.allowReserved===!0?s:encodeURIComponent(s)):n.push(Hu(e,s,r));return r.style==="label"||r.style==="matrix"?`${u}${n.join(u)}`:n.join(u)}function Nf(e){return function(r){let u=[];if(r&&typeof r=="object")for(let n in r){let s=r[n];if(s!=null){if(Array.isArray(s)){u.push(jf(n,s,{style:"form",explode:!0,...e?.array,allowReserved:e?.allowReserved||!1}));continue}if(typeof s=="object"){u.push(Lf(n,s,{style:"deepObject",explode:!0,...e?.object,allowReserved:e?.allowReserved||!1}));continue}u.push(Hu(n,s,e))}}return u.join("&")}}function fg(e,t){let r=e;for(let u of e.match(lg)??[]){let n=u.substring(1,u.length-1),s=!1,i="simple";if(n.endsWith("*")&&(s=!0,n=n.substring(0,n.length-1)),n.startsWith(".")?(i="label",n=n.substring(1)):n.startsWith(";")&&(i="matrix",n=n.substring(1)),!t||t[n]===void 0||t[n]===null)continue;let o=t[n];if(Array.isArray(o)){r=r.replace(u,jf(n,o,{style:i,explode:s}));continue}if(typeof o=="object"){r=r.replace(u,Lf(n,o,{style:i,explode:s}));continue}if(i==="matrix"){r=r.replace(u,`;${Hu(n,o)}`);continue}r=r.replace(u,i==="label"?`.${o}`:o)}return r}function pg(e){return JSON.stringify(e)}function hg(e,t){let r=`${t.baseUrl}${e}`;t.params?.path&&(r=fg(r,t.params.path));let u=t.querySerializer(t.params.query??{});return u.startsWith("?")&&(u=u.substring(1)),u&&(r+=`?${u}`),r}function Pf(...e){let t=new Headers;for(let r of e){if(!r||typeof r!="object")continue;let u=r instanceof Headers?r.entries():Object.entries(r);for(let[n,s]of u)if(s===null)t.delete(n);else if(Array.isArray(s))for(let i of s)t.append(n,i);else s!==void 0&&t.set(n,s)}return t}var Ye=require("node:fs"),kf=require("node:os"),ls=require("node:path");var xt=class extends Error{constructor(t){super(t),this.name="CliError"}},je=class extends xt{constructor(t){super(t),this.name="ConfigError"}},Se=class extends xt{constructor(r,u,n,s){super(`API Error (${r}): ${u}`);this.statusCode=r;this.errorType=n;this.details=s;this.name="ApiError"}},Ke=class extends xt{constructor(r,u,n){super(`Job ${r}: ${u??"Unknown error"}`);this.status=r;this.errorMessage=u;this.details=n;this.name="JobError"}formatDetails(){let r=[this.message];if(this.details){let u=this.details.results;if(u)for(let[n,s]of Object.entries(u))s.status==="failed"&&s.error_message&&r.push(` ${n}: ${s.error_message}`)}return r}},Ku=class extends xt{constructor(t){super(t),this.name="TimeoutError"}};function Jt(e,t){let r=e!=null&&typeof e=="object",u=r&&"message"in e?String(e.message):`HTTP ${t?.status??"unknown"} error`,n=r&&"statusCode"in e?e.statusCode:t?.status,s=[];if(r&&"details"in e&&Array.isArray(e.details))for(let i of e.details)i&&typeof i=="object"&&"message"in i&&s.push(String(i.message));return new Se(n??400,u,void 0,s.length>0?s:void 0)}var St=class extends xt{constructor(t){super(t),this.name="ValidationError"}};var cs=(0,ls.join)((0,kf.homedir)(),".descript-cli"),Tr=(0,ls.join)(cs,"config.json"),Je="https://descriptapi.com/v1/",Yu="default";function dg(){(0,Ye.existsSync)(cs)||(0,Ye.mkdirSync)(cs,{recursive:!0})}function Oe(){try{if((0,Ye.existsSync)(Tr)){let e=(0,Ye.readFileSync)(Tr,"utf-8"),t=JSON.parse(e);return t.profiles?t:{activeProfile:Yu,profiles:{[Yu]:{apiKey:t.apiKey,apiUrl:t.apiUrl,debug:t.debug}}}}}catch(e){console.error(`Warning: Could not parse config file at ${Tr}`),e instanceof Error&&console.error(` ${e.message}`)}return{activeProfile:Yu,profiles:{}}}function _t(e){dg(),(0,Ye.writeFileSync)(Tr,JSON.stringify(e,null,2))}function Ju(){let e=Oe(),t=process.env.DESCRIPT_PROFILE||e.activeProfile;return e.profiles[t]||{}}function zt(){return process.env.DESCRIPT_API_KEY?process.env.DESCRIPT_API_KEY:Ju().apiKey}function Nr(e){let t=Oe(),r=t.activeProfile;t.profiles[r]||(t.profiles[r]={}),t.profiles[r].apiKey=e,_t(t)}function Pr(){return Tr}function ke(){return process.env.DESCRIPT_API_URL?process.env.DESCRIPT_API_URL:Ju().apiUrl??Je}function Lr(){return Ju().apiUrl}function zu(e){let t=Oe(),r=t.activeProfile;t.profiles[r]||(t.profiles[r]={}),t.profiles[r].apiUrl=e,_t(t)}function fs(){let e=Oe(),t=e.activeProfile;e.profiles[t]&&(delete e.profiles[t].apiUrl,_t(e))}function ae(){return process.env.DESCRIPT_DEBUG?process.env.DESCRIPT_DEBUG==="true"||process.env.DESCRIPT_DEBUG==="1":Ju().debug??!1}function ps(e){let t=Oe(),r=t.activeProfile;t.profiles[r]||(t.profiles[r]={}),t.profiles[r].debug=e,_t(t)}function Xu(){return process.env.DESCRIPT_PROFILE?process.env.DESCRIPT_PROFILE:Oe().activeProfile}function hs(){let e=Oe();return Object.keys(e.profiles)}function ds(e){let t=Oe();if(!t.profiles[e])throw new je(`Profile "${e}" does not exist`);t.activeProfile=e,_t(t)}function ms(e){let t=Oe();if(t.profiles[e])throw new je(`Profile "${e}" already exists`);t.profiles[e]={},_t(t)}function qf(e){let t=Oe();if(e===Yu)throw new je("Cannot delete the default profile");if(!t.profiles[e])throw new je(`Profile "${e}" does not exist`);if(t.activeProfile===e)throw new je("Cannot delete the active profile. Switch to another profile first.");delete t.profiles[e],_t(t)}function Mf(e){let t=Oe();return e in t.profiles}var mg="@descript/platform-cli",Fg="0.2.4";function Eg(e){return e.length<=12?"Bearer ***":`Bearer ${e.slice(0,8)}...${e.slice(-4)}`}function Uf(e,t){let r=as({baseUrl:t,headers:{Authorization:`Bearer ${e}`,"User-Agent":`${mg}/${Fg} node/${process.version}`}});return ae()&&r.use({async onRequest(n){try{if(console.error(`
|
|
129
129
|
--- API Request ---`),console.error(`${n.method} ${n.url}`),n.headers){let s=Object.fromEntries(n.headers.entries());s.authorization&&(s.authorization=Eg(e)),console.error("Headers:",s)}if(n.body)try{let i=await n.clone().text();i&&console.error("Body:",JSON.stringify(JSON.parse(i),null,2))}catch{}console.error(`-------------------
|
|
130
130
|
`)}catch(s){console.error("Error logging request:",s instanceof Error?s.message:s)}return n}}),r}function Zu(){let e=zt();if(!e)throw new je("API key not configured. Run `descript-api config` to set up.");return Uf(e,ke())}function Vf(e){return Uf(e,ke())}var Zt=["api-key","api-url","debug"];function Gf(e){return e.length<=12?"***":e.slice(0,8)+"..."+e.slice(-4)}function Xt(e){switch(e){case"api-key":return zt();case"api-url":return Lr();case"debug":return ae()}}function Fs(e,t){switch(e){case"api-key":Nr(t);break;case"api-url":zu(t);break;case"debug":ps(t);break}}function Wf(e,t){if(e==="api-url"){let r=ke();return t||`${r} (default)`}return e==="debug"?t?"enabled":"disabled":t?e==="api-key"?Gf(t):t:"Not configured"}async function Es(e){let t=ot();t.start("Validating API key...");try{let r=Vf(e),{error:u}=await r.GET("/status");return u!=null&&typeof u=="object"&&"error"in u&&u.error==="unauthorized"?(t.stop("Invalid API key"),!1):(t.stop("API key validated successfully!"),!0)}catch{return t.stop("Could not validate (saved anyway)"),!0}}var qe=new Xe("config").description("Manage CLI configuration").addHelpText("after",`
|
|
131
131
|
Profile Commands:
|
|
@@ -167,7 +167,7 @@ API error response:`),console.error(JSON.stringify(D,null,2))),Jt(D,l);if(!a)thr
|
|
|
167
167
|
Agent job response:`),console.log(JSON.stringify(a,null,2)));let p=[`Job ID: ${a.job_id}`,`Project ID: ${a.project_id}`,`Project URL: ${a.project_url}`];He(ze(p.join(`
|
|
168
168
|
`)),"Agent Job Submitted");let f=await Qu(t,a.job_id,"Waiting for agent to complete...",{timeoutMs:u});if(f&&f.job_type==="agent"&&f.result){let h=f.result;if(h.status!=="error"){h.agent_response&&(x.step("Agent Response"),x.message(up(h.agent_response)));let m=[`Status: ${h.status}`];m.push(`Project changed: ${h.project_changed?"yes":"no"}`),h.media_seconds_used!=null&&m.push(`Media seconds used: ${h.media_seconds_used}`),h.ai_credits_used!=null&&m.push(`AI credits used: ${h.ai_credits_used}`),He(ze(m.join(`
|
|
169
169
|
`)),"Agent Complete")}else He(ze(`Status: ${h.status}`),"Agent Complete")}Yt(`Project: ${a.project_url}`)}catch(t){if(t instanceof Ke){let r=t.formatDetails();te(r[0]),r.length>1&&x.error(r.slice(1).join(`
|
|
170
|
-
`))}else if(t instanceof Se){if(te(t.message),t.details&&t.details.length>0)for(let r of t.details)x.error(` ${r}`)}else t instanceof Error?te(t.message):te("An unexpected error occurred");process.exit(1)}});var jg="@descript/platform-cli",sp="0.2.
|
|
170
|
+
`))}else if(t instanceof Se){if(te(t.message),t.details&&t.details.length>0)for(let r of t.details)x.error(` ${r}`)}else t instanceof Error?te(t.message):te("An unexpected error occurred");process.exit(1)}});var jg="@descript/platform-cli",sp="0.2.4",Me=new Xe;Me.name("descript-api").description("CLI for Descript API - import media and run AI edits").version(sp);Me.addCommand(qe);Me.addCommand(np);Me.addCommand(ip);Me.command("help [command]").description("Show help for a command").action(e=>{if(!e){Me.help();return}let t=Me.commands.find(r=>r.name()===e);t?t.help():(console.error(`Unknown command: ${e}`),console.error("Run 'descript-api --help' to see available commands."),process.exit(1))});Me.action(()=>{Me.help()});function op(e){Me.parse(e,{from:"user"}),Yi({pkg:{name:jg,version:sp}}).notify()}op(process.argv.slice(2));
|
|
171
171
|
/*! Bundled license information:
|
|
172
172
|
|
|
173
173
|
deep-extend/lib/deep-extend.js:
|