@descript/platform-cli 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/descript-cli.cjs +2 -2
- package/package.json +1 -1
package/dist/descript-cli.cjs
CHANGED
|
@@ -91,7 +91,7 @@ ${D.default.gray(T)} ${i}
|
|
|
91
91
|
`)}
|
|
92
92
|
`)},info:i=>{d.message(i,{symbol:D.default.blue(ln)})},success:i=>{d.message(i,{symbol:D.default.green(cn)})},step:i=>{d.message(i,{symbol:D.default.green(Re)})},warn:i=>{d.message(i,{symbol:D.default.yellow(pn)})},warning:i=>{d.warn(i)},error:i=>{d.message(i,{symbol:D.default.red(hn)})}},ie=()=>{let i=bt?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],e=bt?80:120,t,n,u=!1,s="",r=(c="")=>{u=!0,t=Ei(),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(Re):p===1?D.default.red($i):D.default.red(yi);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 dn(){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 mn={"Content-Type":"application/json"},fn=/\{[^{}]+\}/g,yt=class extends Request{constructor(e,t){super(e,t);for(let n in t)n in this||(this[n]=t[n])}};function wt(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=vi(mn,s);let o=[];async function a(l,c){let{fetch:p=t,headers:m,params:C={},parseAs:h="json",querySerializer:f,bodySerializer:F=u??Cn,...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:vi(s,m,C.header)};U.body&&(U.body=F(U.body)),U.body instanceof FormData&&U.headers.delete("Content-Type");let Y=new yt(Fn(l,{baseUrl:e,params:C,querySerializer:O}),U),Tt={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,Tt);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 ze=await Q.onResponse(B,Tt,Y);if(ze){if(!(ze instanceof Response))throw new Error("Middleware must return new Response() when modifying the response");B=ze}}}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 Je=await B.text();try{Je=JSON.parse(Je)}catch{}return{error:Je,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 Ve(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 xi(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(Ve(o,e[r],t))}let s=n.join(u);return t.style==="label"||t.style==="matrix"?`${u}${s}`:s}function Bi(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(Ve(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(Bi(u,s,{style:"form",explode:!0,...i?.array,allowReserved:i?.allowReserved||!1}));continue}if(typeof s=="object"){n.push(xi(u,s,{style:"deepObject",explode:!0,...i?.object,allowReserved:i?.allowReserved||!1}));continue}n.push(Ve(u,s,i))}}return n.join("&")}}function gn(i,e){let t=i;for(let n of i.match(fn)??[]){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,Bi(u,o,{style:r,explode:s}));continue}if(typeof o=="object"){t=t.replace(n,xi(u,o,{style:r,explode:s}));continue}if(r==="matrix"){t=t.replace(n,`;${Ve(u,o)}`);continue}t=t.replace(n,r==="label"?`.${o}`:o)}return t}function Cn(i){return JSON.stringify(i)}function Fn(i,e){let t=`${e.baseUrl}${i}`;e.params?.path&&(t=gn(t,e.params.path));let n=e.querySerializer(e.params.query??{});return n.startsWith("?")&&(n=n.substring(1)),n&&(t+=`?${n}`),t}function vi(...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"),Oi=require("node:os"),vt=require("node:path");var se=class extends Error{constructor(e){super(e),this.name="CliError"}},V=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}},Me=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 _t=(0,vt.join)((0,Oi.homedir)(),".descript-cli"),be=(0,vt.join)(_t,"config.json"),J="https://descriptapi.com/v1/",Ne="default";function En(){(0,K.existsSync)(_t)||(0,K.mkdirSync)(_t,{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:Ne,profiles:{[Ne]:{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:Ne,profiles:{}}}function ae(i){En(),(0,K.writeFileSync)(be,JSON.stringify(i,null,2))}function Ue(){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:Ue().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 M(){return process.env.DESCRIPT_API_URL?process.env.DESCRIPT_API_URL:Ue().apiUrl??J}function ye(){return Ue().apiUrl}function qe(i){let e=j(),t=e.activeProfile;e.profiles[t]||(e.profiles[t]={}),e.profiles[t].apiUrl=i,ae(e)}function xt(){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":Ue().debug??!1}function Bt(i){let e=j(),t=e.activeProfile;e.profiles[t]||(e.profiles[t]={}),e.profiles[t].debug=i,ae(e)}function Le(){return process.env.DESCRIPT_PROFILE?process.env.DESCRIPT_PROFILE:j().activeProfile}function Ot(){let i=j();return Object.keys(i.profiles)}function St(i){let e=j();if(!e.profiles[i])throw new V(`Profile "${i}" does not exist`);e.activeProfile=i,ae(e)}function Pt(i){let e=j();if(e.profiles[i])throw new V(`Profile "${i}" already exists`);e.profiles[i]={},ae(e)}function Si(i){let e=j();if(i===Ne)throw new V("Cannot delete the default profile");if(!e.profiles[i])throw new V(`Profile "${i}" does not exist`);if(e.activeProfile===i)throw new V("Cannot delete the active profile. Switch to another profile first.");delete e.profiles[i],ae(e)}function Pi(i){let e=j();return i in e.profiles}var bn="@descript/platform-cli",An="0.2.
|
|
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 dn(){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 mn={"Content-Type":"application/json"},fn=/\{[^{}]+\}/g,yt=class extends Request{constructor(e,t){super(e,t);for(let n in t)n in this||(this[n]=t[n])}};function wt(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=vi(mn,s);let o=[];async function a(l,c){let{fetch:p=t,headers:m,params:C={},parseAs:h="json",querySerializer:f,bodySerializer:F=u??Cn,...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:vi(s,m,C.header)};U.body&&(U.body=F(U.body)),U.body instanceof FormData&&U.headers.delete("Content-Type");let Y=new yt(Fn(l,{baseUrl:e,params:C,querySerializer:O}),U),Tt={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,Tt);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 ze=await Q.onResponse(B,Tt,Y);if(ze){if(!(ze instanceof Response))throw new Error("Middleware must return new Response() when modifying the response");B=ze}}}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 Je=await B.text();try{Je=JSON.parse(Je)}catch{}return{error:Je,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 Ve(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 xi(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(Ve(o,e[r],t))}let s=n.join(u);return t.style==="label"||t.style==="matrix"?`${u}${s}`:s}function Bi(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(Ve(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(Bi(u,s,{style:"form",explode:!0,...i?.array,allowReserved:i?.allowReserved||!1}));continue}if(typeof s=="object"){n.push(xi(u,s,{style:"deepObject",explode:!0,...i?.object,allowReserved:i?.allowReserved||!1}));continue}n.push(Ve(u,s,i))}}return n.join("&")}}function gn(i,e){let t=i;for(let n of i.match(fn)??[]){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,Bi(u,o,{style:r,explode:s}));continue}if(typeof o=="object"){t=t.replace(n,xi(u,o,{style:r,explode:s}));continue}if(r==="matrix"){t=t.replace(n,`;${Ve(u,o)}`);continue}t=t.replace(n,r==="label"?`.${o}`:o)}return t}function Cn(i){return JSON.stringify(i)}function Fn(i,e){let t=`${e.baseUrl}${i}`;e.params?.path&&(t=gn(t,e.params.path));let n=e.querySerializer(e.params.query??{});return n.startsWith("?")&&(n=n.substring(1)),n&&(t+=`?${n}`),t}function vi(...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"),Oi=require("node:os"),vt=require("node:path");var se=class extends Error{constructor(e){super(e),this.name="CliError"}},V=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}},Me=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 _t=(0,vt.join)((0,Oi.homedir)(),".descript-cli"),be=(0,vt.join)(_t,"config.json"),J="https://descriptapi.com/v1/",Ne="default";function En(){(0,K.existsSync)(_t)||(0,K.mkdirSync)(_t,{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:Ne,profiles:{[Ne]:{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:Ne,profiles:{}}}function ae(i){En(),(0,K.writeFileSync)(be,JSON.stringify(i,null,2))}function Ue(){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:Ue().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 M(){return process.env.DESCRIPT_API_URL?process.env.DESCRIPT_API_URL:Ue().apiUrl??J}function ye(){return Ue().apiUrl}function qe(i){let e=j(),t=e.activeProfile;e.profiles[t]||(e.profiles[t]={}),e.profiles[t].apiUrl=i,ae(e)}function xt(){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":Ue().debug??!1}function Bt(i){let e=j(),t=e.activeProfile;e.profiles[t]||(e.profiles[t]={}),e.profiles[t].debug=i,ae(e)}function Le(){return process.env.DESCRIPT_PROFILE?process.env.DESCRIPT_PROFILE:j().activeProfile}function Ot(){let i=j();return Object.keys(i.profiles)}function St(i){let e=j();if(!e.profiles[i])throw new V(`Profile "${i}" does not exist`);e.activeProfile=i,ae(e)}function Pt(i){let e=j();if(e.profiles[i])throw new V(`Profile "${i}" already exists`);e.profiles[i]={},ae(e)}function Si(i){let e=j();if(i===Ne)throw new V("Cannot delete the default profile");if(!e.profiles[i])throw new V(`Profile "${i}" does not exist`);if(e.activeProfile===i)throw new V("Cannot delete the active profile. Switch to another profile first.");delete e.profiles[i],ae(e)}function Pi(i){let e=j();return i in e.profiles}var bn="@descript/platform-cli",An="0.2.8";function $n(i){return i.length<=12?"Bearer ***":`Bearer ${i.slice(0,8)}...${i.slice(-4)}`}function Ii(i,e){let t=wt({baseUrl:e,headers:{Authorization:`Bearer ${i}`,"User-Agent":`${bn}/${An} 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=$n(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 He(){let i=he();if(!i)throw new V("API key not configured. Run `descript-api config` to set up.");return Ii(i,M())}function ki(i){return Ii(i,M())}var me=["api-key","api-url","debug"];function ji(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 It(i,e){switch(i){case"api-key":Ae(e);break;case"api-url":qe(e);break;case"debug":Bt(e);break}}function Ri(i,e){if(i==="api-url"){let t=M();return e||`${t} (default)`}return i==="debug"?e?"enabled":"disabled":e?i==="api-key"?ji(e):e:"Not configured"}async function kt(i){let e=ie();e.start("Validating API key...");try{let t=ki(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 N=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 We(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(Ji(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 Zi=typeof Ke.default=="function"?Ke.default:Ke.default.default,Rt="@descript/platform-cli",_e="0.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 Zi=typeof Ke.default=="function"?Ke.default:Ke.default.default,Rt="@descript/platform-cli",_e="0.2.8",R=new X;R.name("descript-api").description("CLI for Descript API - import media and run AI edits").version(_e);R.addCommand(N);R.addCommand(zi);R.addCommand(Yi);R.command("update").description("Check if a newer version is available").action(async()=>{let i=Zi({pkg:{name:Rt,version:_e},updateCheckInterval:0});console.log(`Current version: ${_e}`),console.log("Checking for updates...");let e=await i.fetchInfo();e.type!=="latest"&&e.latest!==_e?(console.log(`New version available: ${e.latest}`),console.log(`Run \`npm i -g ${Rt}\` to update`)):console.log("You are on the latest version.")});R.command("help [command]").description("Show help for a command").action(i=>{if(!i){R.help();return}let e=R.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))});R.action(()=>{R.help()});function Qi(i){R.parse(i,{from:"user"}),Zi({pkg:{name:Rt,version:_e}}).notify()}Qi(process.argv.slice(2));
|