@conceptcraft/mindframes 0.3.13 → 0.3.15
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/index.js +87 -87
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
3
|
-
var h={id:"mindframes",name:"mindframes",displayName:"Mindframes",description:"CLI tool for Mindframes presentation generation",commands:["mf","mindframes"],apiUrl:"https://www.mindframes.app",docsUrl:"https://docs.mindframes.ai",packageName:"@conceptcraft/mindframes",configDir:".mindframes",apiKeyEnvVar:"MINDFRAMES_API_KEY",apiUrlEnvVar:"MINDFRAMES_API_URL",codexSelfConnectorAppId:"asdk_app_6a2b9629c1608191970dcb3ab374ac55"};import ue from"chalk";import{Command as Il}from"commander";import{Command as Pa}from"commander";import{randomUUID as pn}from"crypto";import{readFileSync as ba,statSync as wa}from"fs";import{basename as To}from"path";import{spawnSync as aa}from"child_process";import{existsSync as sa,mkdtempSync as ca,rmSync as da,writeFileSync as la}from"fs";import{tmpdir as ua}from"os";import{join as po}from"path";import dn from"ffmpeg-static";var ma=/Duration:\s*(\d+):(\d+):(\d+(?:\.\d+)?)/;function pa(e){let n=ma.exec(e);if(!n)return;let t=Number(n[1])*3600+Number(n[2])*60+Number(n[3]);return Number.isFinite(t)&&t>0?t:void 0}function go(e,n="audio"){if(e.length===0)return;let t=dn&&sa(dn)?dn:"ffmpeg",o=/^[a-z0-9]+$/i.test(n)?n:"audio",r=ca(po(ua(),"mf-tts-duration-")),i=po(r,`speech.${o}`);try{la(i,e);let a=aa(t,["-hide_banner","-i",i],{encoding:"utf8"});return a.error?void 0:pa(a.stderr??"")}finally{da(r,{force:!0,recursive:!0})}}import St from"chalk";import ga from"conf";function fo(e={}){let n=(s,d)=>{let u=e[s];return u&&u.trim().length>0?u.trim():d},t=n("NEXT_PUBLIC_PRODUCT_SHORT_NAME","ConceptCraft"),o=n("NEXT_PUBLIC_CLI_COMMAND","ccr"),r=n("NEXT_PUBLIC_CLI_COMMAND_FULL","conceptcraft"),i=n("NEXT_PUBLIC_CLI_CONFIG_DIR",`.${r}`),a=t.toUpperCase().replace(/[^A-Z0-9]/g,"_");return{id:r,name:i.replace(/^\./,""),displayName:t,description:`CLI tool for ${t} presentation generation`,commands:[o,r],apiUrl:n("NEXT_PUBLIC_API_URL","http://localhost:3000"),docsUrl:n("NEXT_PUBLIC_DOCS_URL",`https://docs.${t.toLowerCase()}.ai`),packageName:n("NEXT_PUBLIC_CLI_PACKAGE_NAME","@conceptcraft/cli"),configDir:i,apiKeyEnvVar:`${a}_API_KEY`,apiUrlEnvVar:`${a}_API_URL`,codexSelfConnectorAppId:e.NEXT_PUBLIC_CODEX_SELF_CONNECTOR_APP_ID?.trim()||void 0}}var g=typeof h<"u"&&h?h:fo(process.env);var ho=g.apiUrl,fa={apiKey:{type:"string"},apiUrl:{type:"string",default:ho},defaultTeamId:{type:"string"},accessToken:{type:"string"},refreshToken:{type:"string"},tokenExpiresAt:{type:"number"},clientId:{type:"string"},clientSecret:{type:"string"}},D=new ga({projectName:g.name,schema:fa});function yo(){return{apiKey:be(),apiUrl:j(),defaultTeamId:D.get("defaultTeamId"),accessToken:D.get("accessToken"),refreshToken:D.get("refreshToken"),tokenExpiresAt:D.get("tokenExpiresAt"),clientId:D.get("clientId"),clientSecret:D.get("clientSecret")}}function be(){let e=process.env[g.apiKeyEnvVar]??process.env.CC_SLIDES_API_KEY;return e||D.get("apiKey")}function ln(e){D.set("apiKey",e)}function j(){let e=process.env[g.apiUrlEnvVar]??process.env.CC_SLIDES_API_URL;return e||(D.get("apiUrl")??ho)}function un(e){D.set("apiUrl",e)}function ht(){return D.get("defaultTeamId")}function Pe(e){D.set("defaultTeamId",e)}function yt(){D.clear()}function it(){return D.path}function Ne(){return!!be()}function bo(){return D.get("accessToken")}function wo(){return D.get("refreshToken")}function bt(e,n,t){D.set("accessToken",e),D.set("refreshToken",n),D.set("tokenExpiresAt",Date.now()+(t-60)*1e3)}function wt(){D.delete("accessToken"),D.delete("refreshToken"),D.delete("tokenExpiresAt")}function vo(){let e=D.get("tokenExpiresAt");return e?Date.now()>=e:!0}function Te(){return!!D.get("accessToken")&&!!D.get("refreshToken")}function vt(){return D.get("clientId")}function xt(){return D.get("clientSecret")}function xo(e,n){D.set("clientId",e),D.set("clientSecret",n)}var l={SUCCESS:0,GENERAL_ERROR:1,AUTH_ERROR:2,NOT_FOUND:3,RATE_LIMIT:4,NETWORK_ERROR:5,INVALID_INPUT:6};async function ha(){let e=wo(),n=vt(),t=j();if(!e||!n)return null;try{let o=await fetch(`${t}/.well-known/oauth-authorization-server`);if(!o.ok)return null;let r=await o.json(),i=new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:n}),a=xt();a&&i.set("client_secret",a);let s=await fetch(r.token_endpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:i.toString()});if(!s.ok)return wt(),null;let d=await s.json();return bt(d.access_token,d.refresh_token,d.expires_in),d.access_token}catch{return null}}async function So(){return Te()?vo()?ha():bo()||null:null}function ce(){return Te()||Ne()}async function P(){if(!ce()){let e=g.commands[0],n=g.apiKeyEnvVar;console.error(St.red("\u2717 Not authenticated.")),console.error(),console.error(St.bold("To authenticate, run:")),console.error(St.cyan(` ${e} login`)),console.error(),console.error(St.gray(`Or set ${n} environment variable.`)),process.exit(l.AUTH_ERROR)}}function ya(e){return e.length<=14?"****":`${e.slice(0,10)}...${e.slice(-4)}`}function Co(){let e=be();if(e)return ya(e)}function mn(e){return["cc_slides_","mcp_","cc_sk_","sk_"].some(t=>e.startsWith(t))}async function ge(){let e=await So();if(e)return{Authorization:`Bearer ${e}`};let n=be();return n?{"x-api-key":n}:{}}var O=class extends Error{constructor(t,o,r=1,i="operation_failed",a=!1){super(t);this.statusCode=o;this.exitCode=r;this.errorCode=i;this.retryable=a;this.name="ApiError"}statusCode;exitCode;errorCode;retryable},Ro="Idempotency-Key";function va(e){return e&&e!=="GET"?{[Ro]:pn()}:{}}async function z(e,n={}){let t=j();if(!ce())throw new O(`Not authenticated. Run '${g.commands[0]} login' or set ${g.apiKeyEnvVar} environment variable.`,401,2,"authentication_required");let o=await ge(),r=`${t}${e}`,i={...o,...va(n.method),...n.headers};n.body&&!n.stream&&(i["Content-Type"]="application/json");let a={method:n.method??"GET",headers:i};n.body&&(a.body=JSON.stringify(n.body));let s;try{s=await fetch(r,a)}catch(u){throw new O(`Network error: ${u instanceof Error?u.message:"Unknown error"}`,0,5,"service_unavailable",!0)}if(!s.ok){let u=await s.text().catch(()=>""),p=Sa(u,s.status),w=1;switch(s.status){case 401:w=2;break;case 403:w=2;break;case 404:w=3;break;case 429:w=4;break;case 500:w=1;break}let I=`[${p.code}] ${p.message}`;throw new O(I,s.status,w,p.code,p.retryable)}return n.stream?s:s.headers.get("content-type")?.includes("application/json")?s.json():s.text()}function xa(e){switch(e){case 400:return"invalid_input";case 401:return"authentication_required";case 402:return"insufficient_credits";case 403:return"access_denied";case 404:return"not_found";case 429:return"rate_limited";case 503:return"service_unavailable";default:return"operation_failed"}}function Sa(e,n){let t=xa(n),o=e.trim()||`HTTP ${n}: The request could not be completed.`;try{let r=JSON.parse(e),i=typeof r.error=="object"&&r.error!==null?r.error:void 0;if(r.ok===!1&&typeof i?.code=="string"&&typeof i.message=="string")return{code:i.code,message:i.message,retryable:i.retryable===!0};if(typeof r.error=="string")return{code:/^[a-z][a-z0-9_]+$/.test(r.error)?r.error:t,message:typeof r.message=="string"?r.message:r.error,retryable:n===429||n>=500}}catch{}return{code:t,message:o,retryable:n===429||n>=500}}async function ko(){return z("/api/cli/capabilities")}async function L(e,n,t){let o=t?`?teamId=${encodeURIComponent(t)}`:"";return z(`/api/cli/tool-runs/${encodeURIComponent(e)}/${encodeURIComponent(n)}${o}`)}async function $(e,n){return z(`/api/cli/tools/${encodeURIComponent(e)}`,{body:n,method:"POST"})}async function Ca(e,n,t=120){let o=0;for(let r=0;r<t;r++){let i;try{i=await L(e,n),o=0}catch(a){if(a instanceof O&&a.retryable&&o<2){o+=1,await new Promise(s=>setTimeout(s,2e3));continue}throw a instanceof O?new O(`${a.message} Request ID: ${n}.`,a.statusCode,a.exitCode,a.errorCode,a.retryable):new O(`${a instanceof Error?a.message:"Unknown error"} Request ID: ${n}.`,0,5,"poll_failed",!0)}if(i.done){if(i.error)throw new O(`[${i.error.code??"operation_failed"}] ${i.error.message} Request ID: ${n}.`,500,1,i.error.code??"operation_failed",i.error.retryable);return i}await new Promise(a=>setTimeout(a,(i.nextPollAfterSeconds??2)*1e3))}throw new O(`[operation_timed_out] The background operation timed out. Request ID: ${n}.`,408,1,"operation_timed_out",!0)}function Ct(e){return e.error||e.status==="failed"||e.status==="errored"||e.status==="cancelled"?"failed":e.done||e.status==="completed"?"completed":e.status==="in_progress"?"processing":"pending"}function Ia(e){try{let t=new URL(e).pathname.split("/").pop()?.split(".").pop()?.toLowerCase();return t&&/^[a-z0-9]+$/.test(t)?t:void 0}catch{return}}function Ta(e){let n=e.toLowerCase().split(".").pop();return{pdf:"application/pdf",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",txt:"text/plain",md:"text/markdown",csv:"text/csv",json:"application/json",html:"text/html",css:"text/css",js:"application/javascript",ts:"text/x-typescript",py:"text/x-python"}[n||""]||"application/octet-stream"}async function Ra(e){let n=j();if(!ce())throw new O(`Not authenticated. Run '${g.commands[0]} login' or set ${g.apiKeyEnvVar} environment variable.`,401,2);let t=await ge(),o=wa(e),r=To(e),i=Ta(e),a=await fetch(`${n}/api/cli/files/upload`,{method:"POST",headers:{"Content-Type":"application/json",...t},body:JSON.stringify({fileMetadata:{name:r,type:i,size:o.size}})});if(!a.ok){let I=await a.text();throw new O(I||"Failed to get upload URL",a.status,1)}let s=await a.json(),d=ba(e),u=new FormData;for(let[I,f]of Object.entries(s.fields||{}))u.append(I,f);let p=new Blob([d],{type:i});u.append("file",p,r);let w=await fetch(s.url,{method:"POST",body:u});if(!w.ok)throw new O("Failed to upload file to storage",w.status,1);return{id:pn(),name:r,url:s.fileUrl,size:o.size,type:i,selected:!0}}async function Ao(e,n){let t=[];for(let o=0;o<e.length;o++){let r=e[o],i=To(r);n?.(o,e.length,i);let a=await Ra(r);t.push(a)}return n?.(e.length,e.length,""),t}async function $o(e){let n={};for(let[o,r]of Object.entries(e))r!==void 0&&(n[o]=r);let t=n.designBrandReference??n.brandId??n.brandingId;return t!==void 0&&(n.designBrandReference=t,delete n.brandId,delete n.brandingId),$("createSlides",{...n,approvalReceipt:"cli:create"})}async function Eo(e,n=20){let t=new URLSearchParams;return t.set("limit",String(n)),e&&t.set("teamId",e),(await z(`/api/cli/presentations?${t}`)).presentations}async function Se(e){return z(`/api/cli/presentation/${encodeURIComponent(e)}`)}async function Oo(e){await z(`/api/cli/presentation/${encodeURIComponent(e)}`,{method:"DELETE"})}async function Po(e,n={}){let t=j();if(!ce())throw new O(`Not authenticated. Run '${g.commands[0]} login' or set ${g.apiKeyEnvVar} environment variable.`,401,2);let o=await ge(),r=await fetch(`${t}/api/presentations/export`,{method:"POST",headers:{"Content-Type":"application/json",...o},body:JSON.stringify({presentationId:e,options:{includeImages:n.includeImages??!0,includeBranding:n.includeBranding??!0,downloadExternalImages:n.includeExternal??!0}})});if(!r.ok)throw new O(await r.text(),r.status,r.status===404?3:1);return r.arrayBuffer()}async function No(e,n,t={}){let o=j();if(!ce())throw new O(`Not authenticated. Run '${g.commands[0]} login' or set ${g.apiKeyEnvVar} environment variable.`,401,2);let r=await ge(),i=new FormData,a=new Blob([e],{type:"application/zip"});i.append("file",a,n),i.append("options",JSON.stringify({dryRun:t.dryRun??!1,remapIds:!0}));let s=await fetch(`${o}/api/presentations/import`,{method:"POST",headers:r,body:i}),d=await s.json();if(!s.ok)throw new O(d.errors?.[0]?.message??"Import failed",s.status,1);return d}async function gn(){return z("/api/cli/branding")}async function Do(e,n=25){let t=new URLSearchParams;return t.set("limit",String(n)),e&&t.set("search",e),z(`/api/cli/templates?${t}`)}async function Lo(e){return z(`/api/branding/${e}`)}async function Uo(e,n,t){return $("extractBranding",{approvalReceipt:t,teamId:n,url:e})}async function we(){return z("/api/cli/whoami")}async function Fo(){return z("/api/cli/features")}async function _o(e,n,t={}){let o=j();if(!ce())throw new O(`Not authenticated. Run '${g.commands[0]} login' or set ${g.apiKeyEnvVar} environment variable.`,401,2);let r=await ge(),i=await fetch(`${o}/api/presentations/${e}/generate-blog`,{method:"POST",headers:{"Content-Type":"application/json",...r},body:JSON.stringify({documentCreatedAt:n,targetWordCount:t.targetWordCount??300,tone:t.tone??"professional",language:t.language??"en",targetAudience:t.targetAudience??"General Audience",blogFormat:t.blogFormat??"narrative",customInstructions:t.customInstructions??"",includeImages:t.includeImages??!0,includeTableOfContents:t.includeTableOfContents??!1})});if(!i.ok)throw new O(await i.text(),i.status,i.status===404?3:1);return i}async function ka(e){let n=new URLSearchParams;e&&n.set("teamId",e);let t=n.toString();return z(`/api/cli/limits${t?`?${t}`:""}`)}async function Vo(e,n,t){let o=await ka(t);if(!o.canGenerate[e]){let r=o.remaining[e]??0,i=o.limits[e]??0;throw i===0?new O(`The "${e}" mode is not available on your ${o.planName} plan. Available modes: ${o.availableModes.join(", ")||"none"}`,403,2):new O(`You have reached your ${e} generation limit for this billing cycle (${o.usage[e]??0}/${i} used). Try a different mode: ${o.availableModes.join(", ")||"none available"}`,403,4)}if(o.maxSlidesPerPresentation!==-1&&n>o.maxSlidesPerPresentation)throw new O(`Maximum ${o.maxSlidesPerPresentation} slides allowed on your ${o.planName} plan (requested: ${n}). Try a different mode: ${o.availableModes.join(", ")||"none available"}`,403,6);return o}function Mo(e){return e.replace(/[\u2014\u2013]/g,"-").replace(/[\u201C\u201D]/g,'"').replace(/[\u2018\u2019]/g,"'").replace(/\u2026/g,"...").replace(/\u00A0/g," ").replace(/[\u2010-\u2015]/g,"-").replace(/[\u2032\u2033]/g,"'")}async function It(e){let n=await $("generateSpeech",{approvalReceipt:"cli:tts-generate",...e,text:Mo(e.text)}),t=await Ca("generateSpeech",n.runId),o=t.entity?.url;if(!o)throw new O(`Speech completed without an audio URL. Request ID: ${n.runId}.`,500);let r;try{r=await fetch(o)}catch(p){throw new O(`${p instanceof Error?p.message:"Failed to download speech audio"} Request ID: ${n.runId}.`,0,5,"download_failed",!0)}if(!r.ok)throw new O(`Failed to download speech audio. Request ID: ${n.runId}.`,r.status,5,"download_failed",r.status===429||r.status>=500);let i=t.output??{},a=e.options??{},s=pe(i.format)??Ia(o)??"mp3",d=Buffer.from(await r.arrayBuffer()),u=Aa(i.durationSec,i.duration,i.duration_s)??go(d,s);if(u===void 0)throw new O(`Speech completed without a measurable duration. Request ID: ${n.runId}.`,500,1,"invalid_audio_metadata");return{audioData:d,audioUrl:o,duration:u,cost:at(i.costUsd)??at(i.cost)??0,provider:pe(i.provider)??a.provider??"gemini",format:s,requestId:n.runId,voiceId:pe(i.voice_id)??pe(i.voiceId),voice:pe(i.voice),model:pe(i.model),speed:at(i.speed)??a.speed,language:pe(i.lang)??pe(i.language)??a.language,langApplied:Io(i.langApplied)??Io(i.lang_applied),timestamps:$a(i.timestamps),wordTimings:Ea(i.timestamps??i.timings)}}function Aa(...e){for(let n of e){let t=typeof n=="number"?n:typeof n=="string"&&n.trim()?Number(n):Number.NaN;if(Number.isFinite(t)&&t>0)return t}}function $a(e){if(!e||typeof e!="object"||Array.isArray(e))return;let n=e,t=n.characters,o=n.characterStartTimesSeconds??n.character_start_times_seconds,r=n.characterEndTimesSeconds??n.character_end_times_seconds;if(!(!Array.isArray(t)||!Array.isArray(o)||!Array.isArray(r))&&!(t.length===0||t.length!==o.length||t.length!==r.length||!t.every(i=>typeof i=="string")||!o.every(i=>typeof i=="number"&&Number.isFinite(i))||!r.every(i=>typeof i=="number"&&Number.isFinite(i))))return{characters:t,characterStartTimesSeconds:o,characterEndTimesSeconds:r}}function Ea(e){if(!Array.isArray(e))return;let n=e.flatMap(t=>{if(!t||typeof t!="object"||Array.isArray(t))return[];let o=t,r=pe(o.text)??pe(o.word),i=at(o.start),a=at(o.end);return r&&i!==void 0&&a!==void 0&&a>=i?[{text:r,start:i,end:a}]:[]});return n.length>0?n:void 0}function pe(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function at(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function Io(e){return typeof e=="boolean"?e:void 0}async function jo(e){let n=j();if(!ce())throw new O(`Not authenticated. Run '${g.commands[0]} login' or set ${g.apiKeyEnvVar} environment variable.`,401,2);let t=await ge(),o=pn(),r={...e,texts:e.texts.map(s=>({...s,text:Mo(s.text)}))},i;try{i=await fetch(`${n}/api/cli/tts/batch`,{method:"POST",headers:{"Content-Type":"application/json",[Ro]:o,...t},body:JSON.stringify(r)})}catch(s){throw new O(`Network error: ${s instanceof Error?s.message:"Unknown error"}`,0,5)}if(!i.ok){let s=await i.text().catch(()=>"Unknown error"),d;try{let u=JSON.parse(s);d=u.error||u.message||s}catch{d=s}throw new O(d,i.status,i.status===401?2:1)}let a=await i.json();return a.results=a.results.map(s=>({...s,audioData:Buffer.from(s.audioData,"base64")})),a}async function qo(e){let n=e?`/api/cli/tts?provider=${e}`:"/api/cli/tts";return z(n)}async function Tt(e){return{requestId:(await $("generateMusic",{...e,approvalReceipt:"cli:music-generate"})).runId,status:"pending"}}async function st(e){let n=await L("generateMusic",e);return{requestId:e,status:Ct(n),audioUrl:n.entity?.url,error:n.error?.message}}async function Bo(e){return{requestId:(await $("mixAudio",{...e,approvalReceipt:"cli:mix-create"})).runId,status:"pending"}}async function fn(e){let n=await L("mixAudio",e);return{requestId:e,status:Ct(n),outputUrl:n.entity?.url,error:n.error?.message}}async function Rt(e){return z("/api/cli/images/search",{method:"POST",body:e})}async function Go(e){return z("/api/cli/images/generate",{method:"POST",body:e})}async function hn(e){return z("/api/cli/videos/search",{method:"POST",body:e})}async function K(e,n=60,t=2e3){let o=0;for(let r=0;r<n;r++){let i;try{i=await e(),o=0}catch(a){if(a instanceof O&&a.retryable&&o<2){o+=1,await new Promise(s=>setTimeout(s,t));continue}throw a}if(i.status==="completed"||i.status==="failed")return i;await new Promise(a=>setTimeout(a,t))}throw new O("Operation timed out",408,1)}async function Wo(e,n){let t=await $("scrape",{teamId:n,url:e});return{data:{content:t.content,cost:t.totalCost??0,metadata:{description:"",format:"markdown",tokenUsage:Math.ceil(t.content.length/4)},title:t.title??"",url:t.url},success:!0}}async function Ho(e){let n=await $("generateSfx",{...e,approvalReceipt:"cli:sfx-generate"});return{id:n.runId,requestId:n.runId,status:"pending"}}async function yn(e){let n=await L("generateSfx",e);return{id:n.entity?.id??e,requestId:e,status:Ct(n),audioUrl:n.entity?.url,error:n.error?.message}}async function Jo(e){return $("listPresenterOptions",{...e?{voiceLanguage:e}:{}})}async function zo(e){return{requestId:(await $("generateAvatarVideo",{...e,approvalReceipt:"cli:avatar-generate"})).runId,status:"pending"}}async function bn(e){let n=await L("generateAvatarVideo",e);return{durationSec:typeof n.output?.durationSec=="number"?n.output.durationSec:null,error:n.error?.message,requestId:e,status:Ct(n),videoUrl:n.entity?.url}}async function Xo(e){return $("lipsyncVideo",{...e,approvalReceipt:"cli:video-lipsync"})}async function Yo(){return(await $("listTranslationLanguages",{})).languages}async function Ko(e){return $("translateVideo",{...e,approvalReceipt:"cli:video-translate"})}async function wn(e){return $("generateVideoPlan",{...e,approvalReceipt:"cli:video-plan"})}async function Qo(e){return $("createVideo",{...e,approvalReceipt:"cli:video-create"})}async function Zo(e){return z("/api/cli/video/plan",{body:e,method:"POST"})}import F from"chalk";import vn from"cli-table3";function S(e,n="human"){n!=="quiet"&&n!=="json"&&console.log(F.green("\u2713"),e)}function c(e,n="human"){if(n!=="quiet"){if(n==="json"){console.error(JSON.stringify({error:e}));return}console.error(F.red("\u2717"),e)}}function _(e,n="human"){n!=="quiet"&&n!=="json"&&console.warn(F.yellow("\u26A0"),e)}function m(e,n="human"){n!=="quiet"&&n!=="json"&&console.log(F.blue("\u2139"),e)}function De(e,n="en"){return e?`${j()}/${n}/view/presentations/${e}`:"N/A"}function er(e,n={}){let{showLinks:t=!1,language:o="en"}=n,r=(s,d)=>s.length>d?s.slice(0,d-1)+"\u2026":s,i=s=>{try{return new Date(s).toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit",hour12:!0}).replace(" at ",", ")}catch{return"-"}};if(t){let s=new vn({head:[F.cyan("Slug"),F.cyan("Title"),F.cyan("Slides"),F.cyan("Created"),F.cyan("URL")]});for(let d of e)s.push([r(d.slug||d.id.slice(0,8),30),r(d.title||"Untitled",22),String(d.numberOfSlides||"-"),i(d.createdAt),De(d.slug,o)]);return s.toString()}let a=new vn({head:[F.cyan("Slug"),F.cyan("Title"),F.cyan("Slides"),F.cyan("Mode"),F.cyan("Created")],colWidths:[32,28,8,11,18]});for(let s of e)a.push([s.slug||s.id.slice(0,8),s.title||"Untitled",String(s.numberOfSlides||"-"),s.mode||"-",i(s.createdAt)]);return a.toString()}function tr(e){return e.map(n=>n.slug||n.id).join(`
|
|
4
|
-
`)}function nr(e){let n=[...e].sort((r,i)=>{if(r.isDefault&&!i.isDefault)return-1;if(!r.isDefault&&i.isDefault)return 1;let a=r.createdAt?new Date(r.createdAt).getTime():0;return(i.createdAt?new Date(i.createdAt).getTime():0)-a}),t=r=>{if(!r)return"-";try{return new URL(r).href}catch{return r.startsWith("http")?r:`https://${r}`}},o=new vn({head:[F.cyan("Name"),F.cyan("Source"),F.cyan("Color"),F.cyan("Logo"),F.cyan("Default"),F.cyan("ID")]});for(let r of n){let i=r.primaryColor?`${F.bgHex(r.primaryColor)(" ")} ${r.primaryColor}`:"-";o.push([r.name,t(r.sourceUrl),i,r.logoUrl?F.green("\u2713"):F.gray("\u2717"),r.isDefault?F.green("\u2605"):"",r.id])}return o.toString()}function xn(e){try{return new Date(e).toLocaleString()}catch{return e}}function fe(e){console.log(),console.log(F.bold(e)),console.log(F.gray("\u2500".repeat(e.length)))}function R(e,n){console.log(` ${F.gray(e+":")} ${n??"-"}`)}function Oa(e){return JSON.stringify(e,null,2)}function x(e){console.log(Oa(e))}var or=new Pa("capabilities").description("List callable capabilities and their parity state").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{try{let n=await ko();if(e.format==="json"){x(n);return}for(let t of n.capabilities){if(e.format==="quiet"){console.log(t.name);continue}console.log(`${t.name} ${t.state} ${t.milestone}`)}}catch(n){c(n instanceof Error?n.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}});import{mkdirSync as Ua,writeFileSync as Fa}from"fs";import{dirname as sr,join as _a}from"path";import{Command as Ce}from"commander";import ct from"chalk";import{input as Va,password as Ma,confirm as cr,select as ja}from"@inquirer/prompts";import At from"ora";import Na from"conf";var kt=new Na({projectName:"conceptcraft",configName:"feature-cache"}),Da=3600*1e3,La=1440*60*1e3;function rr(e){let n=0;for(let t=0;t<e.length;t++){let o=e.charCodeAt(t);n=(n<<5)-n+o,n=n&n}return n.toString(16)}function ir(){if(!Ne())return null;let e=kt.get("featureFlags");if(!e)return null;let n=rr(be());if(e.apiKeyHash&&e.apiKeyHash!==n)return ke(),null;let t=Date.now()-e.fetchedAt;return t>La?null:(t>Da&&Sn(),e.flags)}function Sn(){Re().catch(()=>{})}async function Re(){let e=await Fo(),n=be();return kt.set("featureFlags",{flags:e,fetchedAt:Date.now(),apiKeyHash:n?rr(n):void 0}),e}function ke(){kt.delete("featureFlags")}function ar(){return kt.path}var dr=new Ce("config").description("Manage CLI configuration").addCommand(new Ce("init").description("Initialize configuration interactively").action(async()=>{console.log(),console.log(ct.bold(`${g.displayName} CLI Configuration`)),console.log(ct.gray("\u2500".repeat(35))),console.log();try{let e=await Ma({message:"Enter your API key:",mask:"*",validate:o=>!o||o.trim().length===0?"API key is required":mn(o.trim())?!0:"Invalid API key format. Keys should start with 'cc_slides_' or 'mcp_'"});if(ln(e.trim()),await cr({message:`Use a custom API URL? (default: ${g.apiUrl.replace("https://","")})`,default:!1})){let o=await Va({message:"Enter API URL:",default:j(),validate:r=>{try{return new URL(r),!0}catch{return"Invalid URL format"}}});un(o)}console.log();let t=At("Verifying API key...").start();try{let o=await we();if(t.succeed("API key verified!"),console.log(),m(`Logged in as: ${o.user.email}`),o.teams.length===0)_("No teams found for this user.");else if(o.teams.length===1){let r=o.teams[0];Pe(r.id),m(`Team: ${r.name} (${r.planName})`)}else{console.log(),m(`You have access to ${o.teams.length} teams.`);let r=await ja({message:"Select your default team:",choices:o.teams.map(a=>({name:`${a.name} (${a.planName}) - ${a.role}${a.isCurrent?" [current]":""}`,value:a.id})),default:o.currentTeam?.id});Pe(r);let i=o.teams.find(a=>a.id===r);S(`Selected team: ${i?.name}`)}try{await Re()}catch{}}catch(o){t.fail("Failed to verify API key"),_(`Could not verify API key: ${o instanceof Error?o.message:String(o)}`),_(`You may need to set the team ID manually: ${g.commands[0]} config set team-id <id>`)}console.log(),S("Configuration saved!"),m(`Config file: ${it()}`),console.log()}catch(e){if(e.name==="ExitPromptError"){console.log(),m("Configuration cancelled.");return}throw e}})).addCommand(new Ce("show").description("Show current configuration").option("--verify","Verify API key and show team details").action(async e=>{let n=yo();if(fe("Current Configuration"),console.log(),R("API Key",Co()??ct.red("Not set")),R("API URL",n.apiUrl),R("Default Team ID",n.defaultTeamId??ct.gray("Not set")),console.log(),R("Config file",it()),e.verify&&n.apiKey){console.log();let t=At("Verifying...").start();try{let o=await we();t.succeed("Verified"),console.log(),R("User",o.user.email),o.currentTeam&&R("Current Team",`${o.currentTeam.name} (${o.currentTeam.planName})`),o.teams.length>1&&R("Total Teams",String(o.teams.length))}catch(o){t.fail("Verification failed"),_(o instanceof Error?o.message:String(o))}}console.log()})).addCommand(new Ce("set").description("Set a configuration value").argument("<key>","Configuration key (api-key, api-url, team-id)").argument("<value>","Value to set").action(async(e,n)=>{switch(e){case"api-key":mn(n)||(c("Invalid API key format. Keys should start with 'cc_slides_' or 'mcp_'"),process.exit(6)),ln(n),ke(),S("API key updated"),Re().catch(()=>{});break;case"api-url":try{new URL(n),un(n),S(`API URL set to: ${n}`)}catch{c("Invalid URL format"),process.exit(6)}break;case"team-id":Pe(n),S(`Default team ID set to: ${n}`);break;default:c(`Unknown config key: ${e}`),console.log(ct.gray("Valid keys: api-key, api-url, team-id")),process.exit(6)}})).addCommand(new Ce("clear").description("Clear all configuration").action(async()=>{try{await cr({message:"Are you sure you want to clear all configuration?",default:!1})?(yt(),ke(),S("Configuration cleared")):m("Cancelled")}catch{m("Cancelled")}})).addCommand(new Ce("refresh").description("Refresh cached feature flags").action(async()=>{let e=At("Refreshing feature flags...").start();try{await Re(),e.succeed("Feature flags refreshed"),m(`Run '${g.commands[0]} --help' to see updated commands`)}catch(n){e.fail("Failed to refresh"),c(n instanceof Error?n.message:String(n)),process.exit(1)}})).addCommand(new Ce("path").description("Show configuration file path").option("--cache","Show feature cache file path").action(e=>{e.cache?console.log(ar()):console.log(it())})).addCommand(new Ce("pull").description("Pull your account settings (memory, brand, prefs) into a local config.toml").action(async()=>{let e=At("Pulling settings...").start();try{let n=await ge(),t=await fetch(`${j()}/api/cli/settings`,{headers:n});if(!t.ok)throw new Error(`Request failed (HTTP ${t.status})`);let o=await t.text(),r=_a(sr(it()),"settings.toml");Ua(sr(r),{recursive:!0}),Fa(r,o,"utf8"),e.succeed("Settings pulled"),m(`Written to ${r}`)}catch(n){e.fail("Failed to pull settings"),c(n instanceof Error?n.message:String(n)),process.exit(1)}}));import{Command as qa}from"commander";import{confirm as Ba}from"@inquirer/prompts";var lr=new qa("delete").description("Delete a presentation").argument("<slug>","Presentation slug (e.g., my-presentation-v1-abc123)").option("-f, --force","Skip confirmation prompt").option("-q, --quiet","Suppress output").action(async(e,n)=>{if(await P(),!n.force)try{if(!await Ba({message:`Are you sure you want to delete presentation "${e}"?`,default:!1})){n.quiet||_("Deletion cancelled");return}}catch{n.quiet||_("Deletion cancelled");return}try{await Oo(e),n.quiet||S(`Presentation "${e}" deleted`)}catch(t){c(t instanceof Error?t.message:String(t)),process.exit(t.exitCode??1)}});import{Command as Le}from"commander";import mr from"chalk";import Ga from"ora";import{createParser as Zu}from"eventsource-parser";import tm from"chalk";import om from"ora";async function ur(e,n={}){let t=e.body?.getReader();if(!t)throw new Error("Response body is not readable");let o=new TextDecoder,r="",i=!1;for(;!i;){let a=await t.read();if(i=a.done,a.value){let s=o.decode(a.value,{stream:!0});r+=s,n.quiet||process.stdout.write(s)}}return n.quiet||console.log(),r}function Wa(){return new Le("blog").description("Generate a blog post from a presentation").argument("<slug>","Presentation slug").option("--words <count>","Target word count (50-2000)","300").option("--tone <tone>","Writing tone (professional, casual, educational)","professional").option("--audience <text>","Target audience description").option("-f, --format <format>","Output format (human, json, markdown)","human").option("--instructions <text>","Custom instructions for the blog").option("--no-images","Exclude image references").option("--toc","Include table of contents").action(async(e,n)=>{await P();let t=parseInt(n.words,10);(isNaN(t)||t<50||t>2e3)&&(c("Word count must be between 50 and 2000"),process.exit(6));let o=["professional","casual","educational"];o.includes(n.tone)||(c(`Invalid tone. Valid options: ${o.join(", ")}`),process.exit(6));let r=Ga("Fetching presentation...").start();try{let i=await Se(e);r.text="Generating blog post...";let a=await _o(i.id,i.documentCreatedAt||i.createdAt,{targetWordCount:t,tone:n.tone,targetAudience:n.audience??"General Audience",customInstructions:n.instructions??"",includeImages:!n.noImages,includeTableOfContents:n.toc??!1}),s=await ur(a,{quiet:!0});r.succeed("Blog generated"),n.format==="json"?console.log(JSON.stringify({presentationId:e,title:i.title,wordCount:t,tone:n.tone,content:s},null,2)):n.format==="markdown"?console.log(s):(console.log(),console.log(mr.bold(`Blog: ${i.title}`)),console.log(mr.gray("\u2500".repeat(40))),console.log(),console.log(s),console.log())}catch(i){r.fail("Generation failed"),c(i instanceof Error?i.message:String(i)),process.exit(i.exitCode??1)}})}function Ha(){return new Le("tweets").description("Generate tweets from a presentation").argument("<slug>","Presentation slug").option("--count <n>","Number of tweets to generate","5").option("-f, --format <format>","Output format (human, json)","human").action(async(e,n)=>{await P(),m("Tweet generation coming soon.")})}function Ja(){return new Le("linkedin").description("Generate a LinkedIn carousel from a presentation").argument("<slug>","Presentation slug").option("-f, --format <format>","Output format (human, json)","human").action(async e=>{await P(),m("LinkedIn carousel generation coming soon.")})}function za(){return new Le("questions").description("Generate questions for a presentation").argument("<slug>","Presentation slug").option("--count <n>","Number of questions","10").option("-f, --format <format>","Output format (human, json)","human").action(async(e,n)=>{await P(),m("Question generation coming soon.")})}function Xa(){return new Le("cheatsheet").description("Generate a presenter cheat sheet").argument("<slug>","Presentation slug").option("--mode <mode>","Cheat sheet mode (qa-prep, talking-points)","qa-prep").option("-f, --format <format>","Output format (human, json, markdown)","human").action(async(e,n)=>{await P(),m("Cheat sheet generation coming soon.")})}function pr(){let e=new Le("derive").description("Generate derivative content from a presentation"),n=ir();return n&&(n.deckToBlog&&e.addCommand(Wa()),n.deckToTweets&&e.addCommand(Ha()),n.linkedInCarousel&&e.addCommand(Ja()),n.redTeamQuestions&&e.addCommand(za()),n.presenterCheatSheet&&e.addCommand(Xa())),e}import{Command as Ya}from"commander";import{writeFile as Ka}from"fs/promises";import{resolve as gr}from"path";import Qa from"ora";var fr=new Ya("export").description("Export a presentation to ZIP").argument("<slug>","Presentation slug (e.g., my-presentation-v1-abc123)").option("-o, --output <path>","Output file path").option("--include-images","Include images (default: true)",!0).option("--include-branding","Include branding (default: true)",!0).option("--no-external","Skip external image downloads").action(async(e,n)=>{await P();let t=Qa("Fetching presentation...").start();try{let o=await Se(e),r=o.title||e,i=o.id,a=e.replace(/[^a-z0-9-]/gi,"_").toLowerCase().substring(0,50),s=new Date().toISOString().split("T")[0],d=`${a}_${s}.zip`,u=n.output?gr(n.output):gr(process.cwd(),d);t.text=`Exporting "${r}"...`;let p=await Po(i,{includeImages:n.includeImages,includeBranding:n.includeBranding,includeExternal:!n.noExternal});t.text="Saving file...",await Ka(u,Buffer.from(p)),t.succeed("Export complete!"),console.log(),m(`File saved: ${u}`),m(`Size: ${Za(p.byteLength)}`),console.log()}catch(o){t.fail("Export failed"),c(o instanceof Error?o.message:String(o)),process.exit(o.exitCode??1)}});function Za(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}import{Command as es}from"commander";import Cn from"chalk";var hr=new es("ideas").description("Generate presentation topic ideas").option("--context <text>","Custom context for idea generation").option("--count <n>","Number of ideas to generate","5").option("-f, --format <format>","Output format (human, json)","human").action(async e=>{await P(),m("Idea generation is available in the web dashboard."),console.log(),console.log(Cn.gray("The CLI will support idea generation in a future release.")),console.log(),console.log("For now, try these approaches:"),console.log(Cn.gray("` 1. Visit the ${brand.displayName} dashboard and use the idea generator`")),console.log(Cn.gray(" 2. Create a presentation with a broad topic and refine it")),console.log()});import{Command as ts}from"commander";import{readFile as ns}from"fs/promises";import{resolve as os,basename as rs}from"path";import is from"ora";var yr=new ts("import").description("Import a presentation from ZIP (admin only)").argument("<file>","Path to ZIP file");yr._hidden=!0;var br=yr.option("--dry-run","Validate without importing").option("--overwrite","Overwrite existing presentations").option("--remap-ids","Generate new IDs (default: true)",!0).action(async(e,n)=>{await P();try{(await we()).user.role!=="admin"&&(c("This command is only available to administrators"),process.exit(2))}catch{c("Failed to verify permissions"),process.exit(2)}let t=os(e),o=rs(t);o.endsWith(".zip")||(c("File must be a ZIP archive"),process.exit(6));let r=is("Reading file...").start();try{let i=await ns(t);n.dryRun?r.text="Validating...":r.text="Importing presentation...";let a=await No(i,o,{dryRun:n.dryRun});if(a.success){if(n.dryRun)r.succeed("Validation passed!"),console.log(),m("The file is valid and can be imported."),a.statistics&&(console.log(),R("Slides",String(a.statistics.slidesImported)),R("Images",String(a.statistics.imagesUploaded)));else if(r.succeed("Import complete!"),console.log(),R("Presentation ID",a.presentationId??"N/A"),R("Document ID",a.documentId??"N/A"),a.statistics&&(R("Slides imported",String(a.statistics.slidesImported)),R("Images uploaded",String(a.statistics.imagesUploaded)),R("Time",`${a.statistics.totalTimeMs}ms`)),a.presentationId){let s=j();R("View URL",`${s}/p/${a.presentationId}`)}if(a.warnings&&a.warnings.length>0){console.log();for(let s of a.warnings)_(s)}console.log()}else{if(r.fail("Import failed"),console.log(),a.errors)for(let s of a.errors)c(`${s.type}: ${s.message}`);process.exit(1)}}catch(i){r.fail("Import failed"),i.code==="ENOENT"&&(c(`File not found: ${t}`),process.exit(3)),c(i instanceof Error?i.message:String(i)),process.exit(i.exitCode??1)}});import{Command as as}from"commander";var wr=new as("list").description("List presentations").option("-n, --limit <count>","Number of results to return","20").option("-f, --format <format>","Output format (table, json, ids)","table").option("--sort <field>","Sort by field (created, updated, title)").option("--team-id <id>","Team ID (uses default if not specified)").option("-d, --detail","Show detailed output including URLs").option("-l, --language <lang>","Language for URLs","en").action(async e=>{await P();let n=parseInt(e.limit,10);(isNaN(n)||n<1)&&(c("Invalid limit value"),process.exit(6));let t=e.teamId??ht();t||(c("`Team ID required. Set a default with '${brand.commands[0]} config set team-id <id>' or use --team-id`"),process.exit(6));try{let o=await Eo(t,n);if(o.length===0){e.format==="json"?console.log(JSON.stringify([])):e.format!=="ids"&&m("No presentations found");return}switch(e.sort&&o.sort((r,i)=>{switch(e.sort){case"created":return new Date(i.createdAt).getTime()-new Date(r.createdAt).getTime();case"title":return(r.title||"").localeCompare(i.title||"");default:return 0}}),e.format){case"json":console.log(JSON.stringify(o,null,2));break;case"ids":console.log(tr(o));break;default:console.log(er(o,{showLinks:e.detail,language:e.language}));break}}catch(o){c(o instanceof Error?o.message:String(o)),process.exit(o.exitCode??1)}});import{Command as ss}from"commander";import vr from"chalk";import xr from"ora";import Sr from"http";import{randomBytes as Cr,createHash as cs}from"crypto";import ds from"open";var ls=`${g.displayName} CLI`,us=8765,ms=8775;function ps(){return Cr(32).toString("base64url")}function gs(e){return cs("sha256").update(e).digest("base64url")}function fs(){return Cr(16).toString("hex")}async function hs(e,n){for(let t=e;t<=n;t++)try{return await new Promise((o,r)=>{let i=Sr.createServer();i.listen(t,()=>{i.close(()=>o())}),i.on("error",r)}),t}catch{continue}throw new Error(`No available port found between ${e} and ${n}`)}async function ys(e){let n=await fetch(`${e}/.well-known/oauth-authorization-server`);if(!n.ok)throw new Error(`Failed to fetch OAuth metadata: ${n.status}`);return n.json()}async function bs(e,n){let t=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_name:ls,redirect_uris:[n],grant_types:["authorization_code","refresh_token"],response_types:["code"],token_endpoint_auth_method:"none",scope:"presentations:read presentations:write"})});if(!t.ok){let o=await t.text();throw new Error(`Client registration failed: ${o}`)}return t.json()}async function ws(e,n,t,o,r){let i=new URLSearchParams({grant_type:"authorization_code",code:n,redirect_uri:o,client_id:r,code_verifier:t}),a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:i.toString()});if(!a.ok){let s=await a.text();throw new Error(`Token exchange failed: ${s}`)}return a.json()}function vs(e,n){return new Promise((t,o)=>{let r,i=!1,a=()=>{i||(i=!0,clearTimeout(r),process.off("SIGINT",s),process.off("SIGTERM",s),d.close())},s=()=>{a(),o(new Error("Login cancelled"))},d=Sr.createServer((u,p)=>{let w=new URL(u.url||"",`http://localhost:${e}`);if(w.pathname!=="/callback"){p.writeHead(404),p.end("Not found");return}let I=w.searchParams.get("code"),f=w.searchParams.get("state"),T=w.searchParams.get("error"),b=w.searchParams.get("error_description");if(p.writeHead(200,{"Content-Type":"text/html"}),T){p.end(`
|
|
3
|
+
var h={id:"mindframes",name:"mindframes",displayName:"Mindframes",description:"CLI tool for Mindframes presentation generation",commands:["mf","mindframes"],apiUrl:"https://www.mindframes.app",docsUrl:"https://docs.mindframes.ai",packageName:"@conceptcraft/mindframes",configDir:".mindframes",apiKeyEnvVar:"MINDFRAMES_API_KEY",apiUrlEnvVar:"MINDFRAMES_API_URL",codexSelfConnectorAppId:"asdk_app_6a2b9629c1608191970dcb3ab374ac55"};import ue from"chalk";import{Command as Jl}from"commander";import{Command as Ga}from"commander";import{randomUUID as gn}from"crypto";import{readFileSync as Oa,statSync as Pa}from"fs";import{basename as Oo}from"path";import{spawnSync as wa}from"child_process";import{existsSync as va,mkdtempSync as xa,rmSync as Sa,writeFileSync as Ia}from"fs";import{tmpdir as Ca}from"os";import{join as yo}from"path";import ln from"ffmpeg-static";var Ta=/Duration:\s*(\d+):(\d+):(\d+(?:\.\d+)?)/;function Ra(e){let n=Ta.exec(e);if(!n)return;let t=Number(n[1])*3600+Number(n[2])*60+Number(n[3]);return Number.isFinite(t)&&t>0?t:void 0}function bo(e,n="audio"){if(e.length===0)return;let t=ln&&va(ln)?ln:"ffmpeg",o=/^[a-z0-9]+$/i.test(n)?n:"audio",r=xa(yo(Ca(),"mf-tts-duration-")),i=yo(r,`speech.${o}`);try{Ia(i,e);let a=wa(t,["-hide_banner","-i",i],{encoding:"utf8"});return a.error?void 0:Ra(a.stderr??"")}finally{Sa(r,{force:!0,recursive:!0})}}import xt from"chalk";import ka from"conf";function wo(e={}){let n=(s,d)=>{let u=e[s];return u&&u.trim().length>0?u.trim():d},t=n("NEXT_PUBLIC_PRODUCT_SHORT_NAME","ConceptCraft"),o=n("NEXT_PUBLIC_CLI_COMMAND","ccr"),r=n("NEXT_PUBLIC_CLI_COMMAND_FULL","conceptcraft"),i=n("NEXT_PUBLIC_CLI_CONFIG_DIR",`.${r}`),a=t.toUpperCase().replace(/[^A-Z0-9]/g,"_");return{id:r,name:i.replace(/^\./,""),displayName:t,description:`CLI tool for ${t} presentation generation`,commands:[o,r],apiUrl:n("NEXT_PUBLIC_API_URL","http://localhost:3000"),docsUrl:n("NEXT_PUBLIC_DOCS_URL",`https://docs.${t.toLowerCase()}.ai`),packageName:n("NEXT_PUBLIC_CLI_PACKAGE_NAME","@conceptcraft/cli"),configDir:i,apiKeyEnvVar:`${a}_API_KEY`,apiUrlEnvVar:`${a}_API_URL`,codexSelfConnectorAppId:e.NEXT_PUBLIC_CODEX_SELF_CONNECTOR_APP_ID?.trim()||void 0}}var f=typeof h<"u"&&h?h:wo(process.env);var vo=f.apiUrl,Aa={apiKey:{type:"string"},apiUrl:{type:"string",default:vo},defaultTeamId:{type:"string"},accessToken:{type:"string"},refreshToken:{type:"string"},tokenExpiresAt:{type:"number"},clientId:{type:"string"},clientSecret:{type:"string"}},N=new ka({projectName:f.name,schema:Aa});function xo(){return{apiKey:be(),apiUrl:j(),defaultTeamId:N.get("defaultTeamId"),accessToken:N.get("accessToken"),refreshToken:N.get("refreshToken"),tokenExpiresAt:N.get("tokenExpiresAt"),clientId:N.get("clientId"),clientSecret:N.get("clientSecret")}}function be(){let e=process.env[f.apiKeyEnvVar]??process.env.CC_SLIDES_API_KEY;return e||N.get("apiKey")}function un(e){N.set("apiKey",e)}function j(){let e=process.env[f.apiUrlEnvVar]??process.env.CC_SLIDES_API_URL;return e||(N.get("apiUrl")??vo)}function mn(e){N.set("apiUrl",e)}function yt(){return N.get("defaultTeamId")}function _e(e){N.set("defaultTeamId",e)}function bt(){N.clear()}function st(){return N.path}function Ne(){return!!be()}function So(){return N.get("accessToken")}function Io(){return N.get("refreshToken")}function wt(e,n,t){N.set("accessToken",e),N.set("refreshToken",n),N.set("tokenExpiresAt",Date.now()+(t-60)*1e3)}function vt(){N.delete("accessToken"),N.delete("refreshToken"),N.delete("tokenExpiresAt")}function Co(){let e=N.get("tokenExpiresAt");return e?Date.now()>=e:!0}function Te(){return!!N.get("accessToken")&&!!N.get("refreshToken")}function To(){return N.get("clientId")}function Ro(){return N.get("clientSecret")}function ko(e,n){N.set("clientId",e),N.set("clientSecret",n)}var l={SUCCESS:0,GENERAL_ERROR:1,AUTH_ERROR:2,NOT_FOUND:3,RATE_LIMIT:4,NETWORK_ERROR:5,INVALID_INPUT:6};async function $a(){let e=Io(),n=To(),t=j();if(!e||!n)return null;try{let o=await fetch(`${t}/.well-known/oauth-authorization-server`);if(!o.ok)return null;let r=await o.json(),i=new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:n}),a=Ro();a&&i.set("client_secret",a);let s=await fetch(r.token_endpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:i.toString()});if(!s.ok)return vt(),null;let d=await s.json();return wt(d.access_token,d.refresh_token,d.expires_in),d.access_token}catch{return null}}async function Ao(){return Te()?Co()?$a():So()||null:null}function ce(){return Te()||Ne()}async function P(){if(!ce()){let e=f.commands[0],n=f.apiKeyEnvVar;console.error(xt.red("\u2717 Not authenticated.")),console.error(),console.error(xt.bold("To authenticate, run:")),console.error(xt.cyan(` ${e} login`)),console.error(),console.error(xt.gray(`Or set ${n} environment variable.`)),process.exit(l.AUTH_ERROR)}}function Ea(e){return e.length<=14?"****":`${e.slice(0,10)}...${e.slice(-4)}`}function $o(){let e=be();if(e)return Ea(e)}function pn(e){return["cc_slides_","mcp_","cc_sk_","sk_"].some(t=>e.startsWith(t))}async function ge(){let e=await Ao();if(e)return{Authorization:`Bearer ${e}`};let n=be();return n?{"x-api-key":n}:{}}var O=class extends Error{constructor(t,o,r=1,i="operation_failed",a=!1){super(t);this.statusCode=o;this.exitCode=r;this.errorCode=i;this.retryable=a;this.name="ApiError"}statusCode;exitCode;errorCode;retryable},Po="Idempotency-Key";function _a(e){return e&&e!=="GET"?{[Po]:gn()}:{}}async function z(e,n={}){let t=j();if(!ce())throw new O(`Not authenticated. Run '${f.commands[0]} login' or set ${f.apiKeyEnvVar} environment variable.`,401,2,"authentication_required");let o=await ge(),r=`${t}${e}`,i={...o,..._a(n.method),...n.headers};n.body&&!n.stream&&(i["Content-Type"]="application/json");let a={method:n.method??"GET",headers:i};n.body&&(a.body=JSON.stringify(n.body));let s;try{s=await fetch(r,a)}catch(u){throw new O(`Network error: ${u instanceof Error?u.message:"Unknown error"}`,0,5,"service_unavailable",!0)}if(!s.ok){let u=await s.text().catch(()=>""),m=La(u,s.status),b=1;switch(s.status){case 401:b=2;break;case 403:b=2;break;case 404:b=3;break;case 429:b=4;break;case 500:b=1;break}let C=`[${m.code}] ${m.message}`;throw new O(C,s.status,b,m.code,m.retryable)}return n.stream?s:s.headers.get("content-type")?.includes("application/json")?s.json():s.text()}function Na(e){switch(e){case 400:return"invalid_input";case 401:return"authentication_required";case 402:return"insufficient_credits";case 403:return"access_denied";case 404:return"not_found";case 429:return"rate_limited";case 503:return"service_unavailable";default:return"operation_failed"}}function La(e,n){let t=Na(n),o=e.trim()||`HTTP ${n}: The request could not be completed.`;try{let r=JSON.parse(e),i=typeof r.error=="object"&&r.error!==null?r.error:void 0;if(r.ok===!1&&typeof i?.code=="string"&&typeof i.message=="string")return{code:i.code,message:i.message,retryable:i.retryable===!0};if(typeof r.error=="string")return{code:/^[a-z][a-z0-9_]+$/.test(r.error)?r.error:t,message:typeof r.message=="string"?r.message:r.error,retryable:n===429||n>=500}}catch{}return{code:t,message:o,retryable:n===429||n>=500}}async function _o(){return z("/api/cli/capabilities")}async function L(e,n,t){let o=t?`?teamId=${encodeURIComponent(t)}`:"";return z(`/api/cli/tool-runs/${encodeURIComponent(e)}/${encodeURIComponent(n)}${o}`)}async function $(e,n){return z(`/api/cli/tools/${encodeURIComponent(e)}`,{body:n,method:"POST"})}async function Da(e,n,t=120){let o=0;for(let r=0;r<t;r++){let i;try{i=await L(e,n),o=0}catch(a){if(a instanceof O&&a.retryable&&o<2){o+=1,await new Promise(s=>setTimeout(s,2e3));continue}throw a instanceof O?new O(`${a.message} Request ID: ${n}.`,a.statusCode,a.exitCode,a.errorCode,a.retryable):new O(`${a instanceof Error?a.message:"Unknown error"} Request ID: ${n}.`,0,5,"poll_failed",!0)}if(i.done){if(i.error)throw new O(`[${i.error.code??"operation_failed"}] ${i.error.message} Request ID: ${n}.`,500,1,i.error.code??"operation_failed",i.error.retryable);return i}await new Promise(a=>setTimeout(a,(i.nextPollAfterSeconds??2)*1e3))}throw new O(`[operation_timed_out] The background operation timed out. Request ID: ${n}.`,408,1,"operation_timed_out",!0)}function St(e){return e.error||e.status==="failed"||e.status==="errored"||e.status==="cancelled"?"failed":e.done||e.status==="completed"?"completed":e.status==="in_progress"?"processing":"pending"}function Fa(e){try{let t=new URL(e).pathname.split("/").pop()?.split(".").pop()?.toLowerCase();return t&&/^[a-z0-9]+$/.test(t)?t:void 0}catch{return}}function Ua(e){let n=e.toLowerCase().split(".").pop();return{pdf:"application/pdf",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",txt:"text/plain",md:"text/markdown",csv:"text/csv",json:"application/json",html:"text/html",css:"text/css",js:"application/javascript",ts:"text/x-typescript",py:"text/x-python"}[n||""]||"application/octet-stream"}async function Ma(e){let n=j();if(!ce())throw new O(`Not authenticated. Run '${f.commands[0]} login' or set ${f.apiKeyEnvVar} environment variable.`,401,2);let t=await ge(),o=Pa(e),r=Oo(e),i=Ua(e),a=await fetch(`${n}/api/cli/files/upload`,{method:"POST",headers:{"Content-Type":"application/json",...t},body:JSON.stringify({fileMetadata:{name:r,type:i,size:o.size}})});if(!a.ok){let C=await a.text();throw new O(C||"Failed to get upload URL",a.status,1)}let s=await a.json(),d=Oa(e),u=new FormData;for(let[C,g]of Object.entries(s.fields||{}))u.append(C,g);let m=new Blob([d],{type:i});u.append("file",m,r);let b=await fetch(s.url,{method:"POST",body:u});if(!b.ok)throw new O("Failed to upload file to storage",b.status,1);return{id:gn(),name:r,url:s.fileUrl,size:o.size,type:i,selected:!0}}async function No(e,n){let t=[];for(let o=0;o<e.length;o++){let r=e[o],i=Oo(r);n?.(o,e.length,i);let a=await Ma(r);t.push(a)}return n?.(e.length,e.length,""),t}async function Lo(e){let n={};for(let[o,r]of Object.entries(e))r!==void 0&&(n[o]=r);let t=n.designBrandReference??n.brandId??n.brandingId;return t!==void 0&&(n.designBrandReference=t,delete n.brandId,delete n.brandingId),$("createSlides",{...n,approvalReceipt:"cli:create"})}async function Do(e,n=20){let t=new URLSearchParams;return t.set("limit",String(n)),e&&t.set("teamId",e),(await z(`/api/cli/presentations?${t}`)).presentations}async function Se(e){return z(`/api/cli/presentation/${encodeURIComponent(e)}`)}async function Fo(e){await z(`/api/cli/presentation/${encodeURIComponent(e)}`,{method:"DELETE"})}async function Uo(e,n={}){let t=j();if(!ce())throw new O(`Not authenticated. Run '${f.commands[0]} login' or set ${f.apiKeyEnvVar} environment variable.`,401,2);let o=await ge(),r=await fetch(`${t}/api/presentations/export`,{method:"POST",headers:{"Content-Type":"application/json",...o},body:JSON.stringify({presentationId:e,options:{includeImages:n.includeImages??!0,includeBranding:n.includeBranding??!0,downloadExternalImages:n.includeExternal??!0}})});if(!r.ok)throw new O(await r.text(),r.status,r.status===404?3:1);return r.arrayBuffer()}async function Mo(e,n,t={}){let o=j();if(!ce())throw new O(`Not authenticated. Run '${f.commands[0]} login' or set ${f.apiKeyEnvVar} environment variable.`,401,2);let r=await ge(),i=new FormData,a=new Blob([e],{type:"application/zip"});i.append("file",a,n),i.append("options",JSON.stringify({dryRun:t.dryRun??!1,remapIds:!0}));let s=await fetch(`${o}/api/presentations/import`,{method:"POST",headers:r,body:i}),d=await s.json();if(!s.ok)throw new O(d.errors?.[0]?.message??"Import failed",s.status,1);return d}async function fn(){return z("/api/cli/branding")}async function Vo(e,n=25){let t=new URLSearchParams;return t.set("limit",String(n)),e&&t.set("search",e),z(`/api/cli/templates?${t}`)}async function jo(e){return z(`/api/branding/${e}`)}async function qo(e,n,t){return $("extractBranding",{approvalReceipt:t,teamId:n,url:e})}async function we(){return z("/api/cli/whoami")}async function Bo(){return z("/api/cli/features")}async function Go(e,n,t={}){let o=j();if(!ce())throw new O(`Not authenticated. Run '${f.commands[0]} login' or set ${f.apiKeyEnvVar} environment variable.`,401,2);let r=await ge(),i=await fetch(`${o}/api/presentations/${e}/generate-blog`,{method:"POST",headers:{"Content-Type":"application/json",...r},body:JSON.stringify({documentCreatedAt:n,targetWordCount:t.targetWordCount??300,tone:t.tone??"professional",language:t.language??"en",targetAudience:t.targetAudience??"General Audience",blogFormat:t.blogFormat??"narrative",customInstructions:t.customInstructions??"",includeImages:t.includeImages??!0,includeTableOfContents:t.includeTableOfContents??!1})});if(!i.ok)throw new O(await i.text(),i.status,i.status===404?3:1);return i}async function Va(e){let n=new URLSearchParams;e&&n.set("teamId",e);let t=n.toString();return z(`/api/cli/limits${t?`?${t}`:""}`)}async function Wo(e,n,t){let o=await Va(t);if(!o.canGenerate[e]){let r=o.remaining[e]??0,i=o.limits[e]??0;throw i===0?new O(`The "${e}" mode is not available on your ${o.planName} plan. Available modes: ${o.availableModes.join(", ")||"none"}`,403,2):new O(`You have reached your ${e} generation limit for this billing cycle (${o.usage[e]??0}/${i} used). Try a different mode: ${o.availableModes.join(", ")||"none available"}`,403,4)}if(o.maxSlidesPerPresentation!==-1&&n>o.maxSlidesPerPresentation)throw new O(`Maximum ${o.maxSlidesPerPresentation} slides allowed on your ${o.planName} plan (requested: ${n}). Try a different mode: ${o.availableModes.join(", ")||"none available"}`,403,6);return o}function Ho(e){return e.replace(/[\u2014\u2013]/g,"-").replace(/[\u201C\u201D]/g,'"').replace(/[\u2018\u2019]/g,"'").replace(/\u2026/g,"...").replace(/\u00A0/g," ").replace(/[\u2010-\u2015]/g,"-").replace(/[\u2032\u2033]/g,"'")}async function It(e){let n=await $("generateSpeech",{approvalReceipt:"cli:tts-generate",...e,text:Ho(e.text)}),t=await Da("generateSpeech",n.runId),o=t.entity?.url;if(!o)throw new O(`Speech completed without an audio URL. Request ID: ${n.runId}.`,500);let r;try{r=await fetch(o)}catch(m){throw new O(`${m instanceof Error?m.message:"Failed to download speech audio"} Request ID: ${n.runId}.`,0,5,"download_failed",!0)}if(!r.ok)throw new O(`Failed to download speech audio. Request ID: ${n.runId}.`,r.status,5,"download_failed",r.status===429||r.status>=500);let i=t.output??{},a=e.options??{},s=pe(i.format)??Fa(o)??"mp3",d=Buffer.from(await r.arrayBuffer()),u=Jo(i.durationSec,i.duration,i.duration_s)??bo(d,s);if(u===void 0)throw new O(`Speech completed without a measurable duration. Request ID: ${n.runId}.`,500,1,"invalid_audio_metadata");return{audioData:d,audioUrl:o,duration:u,cost:Re(i.costUsd)??Re(i.cost)??0,provider:pe(i.provider)??a.provider??"gemini",format:s,requestId:n.runId,voiceId:pe(i.voice_id)??pe(i.voiceId),voice:pe(i.voice),model:pe(i.model),speed:Re(i.speed)??a.speed,language:pe(i.lang)??pe(i.language)??a.language,langApplied:Eo(i.langApplied)??Eo(i.lang_applied),timestamps:ja(i.timestamps),wordTimings:qa(i.timestamps??i.timings)}}function Jo(...e){for(let n of e){let t=typeof n=="number"?n:typeof n=="string"&&n.trim()?Number(n):Number.NaN;if(Number.isFinite(t)&&t>0)return t}}function ja(e){if(!e||typeof e!="object"||Array.isArray(e))return;let n=e,t=n.characters,o=n.characterStartTimesSeconds??n.character_start_times_seconds,r=n.characterEndTimesSeconds??n.character_end_times_seconds;if(!(!Array.isArray(t)||!Array.isArray(o)||!Array.isArray(r))&&!(t.length===0||t.length!==o.length||t.length!==r.length||!t.every(i=>typeof i=="string")||!o.every(i=>typeof i=="number"&&Number.isFinite(i))||!r.every(i=>typeof i=="number"&&Number.isFinite(i))))return{characters:t,characterStartTimesSeconds:o,characterEndTimesSeconds:r}}function qa(e){if(!Array.isArray(e))return;let n=e.flatMap(t=>{if(!t||typeof t!="object"||Array.isArray(t))return[];let o=t,r=pe(o.text)??pe(o.word),i=Re(o.start),a=Re(o.end);return r&&i!==void 0&&a!==void 0&&a>=i?[{text:r,start:i,end:a}]:[]});return n.length>0?n:void 0}function pe(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function Re(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function Eo(e){return typeof e=="boolean"?e:void 0}async function zo(e){let n=j();if(!ce())throw new O(`Not authenticated. Run '${f.commands[0]} login' or set ${f.apiKeyEnvVar} environment variable.`,401,2);let t=await ge(),o=gn(),r={...e,texts:e.texts.map(s=>({...s,text:Ho(s.text)}))},i;try{i=await fetch(`${n}/api/cli/tts/batch`,{method:"POST",headers:{"Content-Type":"application/json",[Po]:o,...t},body:JSON.stringify(r)})}catch(s){throw new O(`Network error: ${s instanceof Error?s.message:"Unknown error"}`,0,5)}if(!i.ok){let s=await i.text().catch(()=>"Unknown error"),d;try{let u=JSON.parse(s);d=u.error||u.message||s}catch{d=s}throw new O(d,i.status,i.status===401?2:1)}let a=await i.json();return a.results=a.results.map(s=>({...s,audioData:Buffer.from(s.audioData,"base64")})),a}async function Xo(e){let n=e?`/api/cli/tts?provider=${e}`:"/api/cli/tts";return z(n)}async function Ct(e){return{requestId:(await $("generateMusic",{...e,approvalReceipt:"cli:music-generate"})).runId,status:"pending"}}async function ct(e){let n=await L("generateMusic",e);return{requestId:e,status:St(n),audioUrl:n.entity?.url,duration:Jo(n.output?.durationSec,n.output?.duration,n.output?.duration_s),cost:Re(n.output?.costUsd)??Re(n.output?.cost),error:n.error?.message}}async function Yo(e){return{requestId:(await $("mixAudio",{...e,approvalReceipt:"cli:mix-create"})).runId,status:"pending"}}async function hn(e){let n=await L("mixAudio",e);return{requestId:e,status:St(n),outputUrl:n.entity?.url,error:n.error?.message}}async function Tt(e){return z("/api/cli/images/search",{method:"POST",body:e})}async function Ko(e){return z("/api/cli/images/generate",{method:"POST",body:e})}async function yn(e){return z("/api/cli/videos/search",{method:"POST",body:e})}async function K(e,n=60,t=2e3){let o=0;for(let r=0;r<n;r++){let i;try{i=await e(),o=0}catch(a){if(a instanceof O&&a.retryable&&o<2){o+=1,await new Promise(s=>setTimeout(s,t));continue}throw a}if(i.status==="completed"||i.status==="failed")return i;await new Promise(a=>setTimeout(a,t))}throw new O("Operation timed out",408,1)}async function Qo(e,n){let t=await $("scrape",{teamId:n,url:e});return{data:{content:t.content,cost:t.totalCost??0,metadata:{description:"",format:"markdown",tokenUsage:Math.ceil(t.content.length/4)},title:t.title??"",url:t.url},success:!0}}async function Zo(e){let n=await $("generateSfx",{...e,approvalReceipt:"cli:sfx-generate"});return{id:n.runId,requestId:n.runId,status:"pending"}}async function bn(e){let n=await L("generateSfx",e);return{id:n.entity?.id??e,requestId:e,status:St(n),audioUrl:n.entity?.url,error:n.error?.message}}async function er(e){return $("listPresenterOptions",{...e?{voiceLanguage:e}:{}})}async function tr(e){return{requestId:(await $("generateAvatarVideo",{...e,approvalReceipt:"cli:avatar-generate"})).runId,status:"pending"}}async function wn(e){let n=await L("generateAvatarVideo",e);return{durationSec:typeof n.output?.durationSec=="number"?n.output.durationSec:null,error:n.error?.message,requestId:e,status:St(n),videoUrl:n.entity?.url}}async function nr(e){return $("lipsyncVideo",{...e,approvalReceipt:"cli:video-lipsync"})}async function or(){return(await $("listTranslationLanguages",{})).languages}async function rr(e){return $("translateVideo",{...e,approvalReceipt:"cli:video-translate"})}async function vn(e){return $("generateVideoPlan",{...e,approvalReceipt:"cli:video-plan"})}async function ir(e){return $("createVideo",{...e,approvalReceipt:"cli:video-create"})}async function ar(e){return z("/api/cli/video/plan",{body:e,method:"POST"})}import F from"chalk";import xn from"cli-table3";function S(e,n="human"){n!=="quiet"&&n!=="json"&&console.log(F.green("\u2713"),e)}function c(e,n="human"){if(n!=="quiet"){if(n==="json"){console.error(JSON.stringify({error:e}));return}console.error(F.red("\u2717"),e)}}function U(e,n="human"){n!=="quiet"&&n!=="json"&&console.warn(F.yellow("\u26A0"),e)}function p(e,n="human"){n!=="quiet"&&n!=="json"&&console.log(F.blue("\u2139"),e)}function Le(e,n="en"){return e?`${j()}/${n}/view/presentations/${e}`:"N/A"}function sr(e,n={}){let{showLinks:t=!1,language:o="en"}=n,r=(s,d)=>s.length>d?s.slice(0,d-1)+"\u2026":s,i=s=>{try{return new Date(s).toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit",hour12:!0}).replace(" at ",", ")}catch{return"-"}};if(t){let s=new xn({head:[F.cyan("Slug"),F.cyan("Title"),F.cyan("Slides"),F.cyan("Created"),F.cyan("URL")]});for(let d of e)s.push([r(d.slug||d.id.slice(0,8),30),r(d.title||"Untitled",22),String(d.numberOfSlides||"-"),i(d.createdAt),Le(d.slug,o)]);return s.toString()}let a=new xn({head:[F.cyan("Slug"),F.cyan("Title"),F.cyan("Slides"),F.cyan("Mode"),F.cyan("Created")],colWidths:[32,28,8,11,18]});for(let s of e)a.push([s.slug||s.id.slice(0,8),s.title||"Untitled",String(s.numberOfSlides||"-"),s.mode||"-",i(s.createdAt)]);return a.toString()}function cr(e){return e.map(n=>n.slug||n.id).join(`
|
|
4
|
+
`)}function dr(e){let n=[...e].sort((r,i)=>{if(r.isDefault&&!i.isDefault)return-1;if(!r.isDefault&&i.isDefault)return 1;let a=r.createdAt?new Date(r.createdAt).getTime():0;return(i.createdAt?new Date(i.createdAt).getTime():0)-a}),t=r=>{if(!r)return"-";try{return new URL(r).href}catch{return r.startsWith("http")?r:`https://${r}`}},o=new xn({head:[F.cyan("Name"),F.cyan("Source"),F.cyan("Color"),F.cyan("Logo"),F.cyan("Default"),F.cyan("ID")]});for(let r of n){let i=r.primaryColor?`${F.bgHex(r.primaryColor)(" ")} ${r.primaryColor}`:"-";o.push([r.name,t(r.sourceUrl),i,r.logoUrl?F.green("\u2713"):F.gray("\u2717"),r.isDefault?F.green("\u2605"):"",r.id])}return o.toString()}function Sn(e){try{return new Date(e).toLocaleString()}catch{return e}}function fe(e){console.log(),console.log(F.bold(e)),console.log(F.gray("\u2500".repeat(e.length)))}function R(e,n){console.log(` ${F.gray(e+":")} ${n??"-"}`)}function Ba(e){return JSON.stringify(e,null,2)}function x(e){console.log(Ba(e))}var lr=new Ga("capabilities").description("List callable capabilities and their parity state").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{try{let n=await _o();if(e.format==="json"){x(n);return}for(let t of n.capabilities){if(e.format==="quiet"){console.log(t.name);continue}console.log(`${t.name} ${t.state} ${t.milestone}`)}}catch(n){c(n instanceof Error?n.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}});import{mkdirSync as za,writeFileSync as Xa}from"fs";import{dirname as gr,join as Ya}from"path";import{Command as Ie}from"commander";import dt from"chalk";import{input as Ka,password as Qa,confirm as fr,select as Za}from"@inquirer/prompts";import kt from"ora";import Wa from"conf";var Rt=new Wa({projectName:"conceptcraft",configName:"feature-cache"}),Ha=3600*1e3,Ja=1440*60*1e3;function ur(e){let n=0;for(let t=0;t<e.length;t++){let o=e.charCodeAt(t);n=(n<<5)-n+o,n=n&n}return n.toString(16)}function mr(){if(!Ne())return null;let e=Rt.get("featureFlags");if(!e)return null;let n=ur(be());if(e.apiKeyHash&&e.apiKeyHash!==n)return Ae(),null;let t=Date.now()-e.fetchedAt;return t>Ja?null:(t>Ha&&In(),e.flags)}function In(){ke().catch(()=>{})}async function ke(){let e=await Bo(),n=be();return Rt.set("featureFlags",{flags:e,fetchedAt:Date.now(),apiKeyHash:n?ur(n):void 0}),e}function Ae(){Rt.delete("featureFlags")}function pr(){return Rt.path}var hr=new Ie("config").description("Manage CLI configuration").addCommand(new Ie("init").description("Initialize configuration interactively").action(async()=>{console.log(),console.log(dt.bold(`${f.displayName} CLI Configuration`)),console.log(dt.gray("\u2500".repeat(35))),console.log();try{let e=await Qa({message:"Enter your API key:",mask:"*",validate:o=>!o||o.trim().length===0?"API key is required":pn(o.trim())?!0:"Invalid API key format. Keys should start with 'cc_slides_' or 'mcp_'"});if(un(e.trim()),await fr({message:`Use a custom API URL? (default: ${f.apiUrl.replace("https://","")})`,default:!1})){let o=await Ka({message:"Enter API URL:",default:j(),validate:r=>{try{return new URL(r),!0}catch{return"Invalid URL format"}}});mn(o)}console.log();let t=kt("Verifying API key...").start();try{let o=await we();if(t.succeed("API key verified!"),console.log(),p(`Logged in as: ${o.user.email}`),o.teams.length===0)U("No teams found for this user.");else if(o.teams.length===1){let r=o.teams[0];_e(r.id),p(`Team: ${r.name} (${r.planName})`)}else{console.log(),p(`You have access to ${o.teams.length} teams.`);let r=await Za({message:"Select your default team:",choices:o.teams.map(a=>({name:`${a.name} (${a.planName}) - ${a.role}${a.isCurrent?" [current]":""}`,value:a.id})),default:o.currentTeam?.id});_e(r);let i=o.teams.find(a=>a.id===r);S(`Selected team: ${i?.name}`)}try{await ke()}catch{}}catch(o){t.fail("Failed to verify API key"),U(`Could not verify API key: ${o instanceof Error?o.message:String(o)}`),U(`You may need to set the team ID manually: ${f.commands[0]} config set team-id <id>`)}console.log(),S("Configuration saved!"),p(`Config file: ${st()}`),console.log()}catch(e){if(e.name==="ExitPromptError"){console.log(),p("Configuration cancelled.");return}throw e}})).addCommand(new Ie("show").description("Show current configuration").option("--verify","Verify API key and show team details").action(async e=>{let n=xo();if(fe("Current Configuration"),console.log(),R("API Key",$o()??dt.red("Not set")),R("API URL",n.apiUrl),R("Default Team ID",n.defaultTeamId??dt.gray("Not set")),console.log(),R("Config file",st()),e.verify&&n.apiKey){console.log();let t=kt("Verifying...").start();try{let o=await we();t.succeed("Verified"),console.log(),R("User",o.user.email),o.currentTeam&&R("Current Team",`${o.currentTeam.name} (${o.currentTeam.planName})`),o.teams.length>1&&R("Total Teams",String(o.teams.length))}catch(o){t.fail("Verification failed"),U(o instanceof Error?o.message:String(o))}}console.log()})).addCommand(new Ie("set").description("Set a configuration value").argument("<key>","Configuration key (api-key, api-url, team-id)").argument("<value>","Value to set").action(async(e,n)=>{switch(e){case"api-key":pn(n)||(c("Invalid API key format. Keys should start with 'cc_slides_' or 'mcp_'"),process.exit(6)),un(n),Ae(),S("API key updated"),ke().catch(()=>{});break;case"api-url":try{new URL(n),mn(n),S(`API URL set to: ${n}`)}catch{c("Invalid URL format"),process.exit(6)}break;case"team-id":_e(n),S(`Default team ID set to: ${n}`);break;default:c(`Unknown config key: ${e}`),console.log(dt.gray("Valid keys: api-key, api-url, team-id")),process.exit(6)}})).addCommand(new Ie("clear").description("Clear all configuration").action(async()=>{try{await fr({message:"Are you sure you want to clear all configuration?",default:!1})?(bt(),Ae(),S("Configuration cleared")):p("Cancelled")}catch{p("Cancelled")}})).addCommand(new Ie("refresh").description("Refresh cached feature flags").action(async()=>{let e=kt("Refreshing feature flags...").start();try{await ke(),e.succeed("Feature flags refreshed"),p(`Run '${f.commands[0]} --help' to see updated commands`)}catch(n){e.fail("Failed to refresh"),c(n instanceof Error?n.message:String(n)),process.exit(1)}})).addCommand(new Ie("path").description("Show configuration file path").option("--cache","Show feature cache file path").action(e=>{e.cache?console.log(pr()):console.log(st())})).addCommand(new Ie("pull").description("Pull your account settings (memory, brand, prefs) into a local config.toml").action(async()=>{let e=kt("Pulling settings...").start();try{let n=await ge(),t=await fetch(`${j()}/api/cli/settings`,{headers:n});if(!t.ok)throw new Error(`Request failed (HTTP ${t.status})`);let o=await t.text(),r=Ya(gr(st()),"settings.toml");za(gr(r),{recursive:!0}),Xa(r,o,"utf8"),e.succeed("Settings pulled"),p(`Written to ${r}`)}catch(n){e.fail("Failed to pull settings"),c(n instanceof Error?n.message:String(n)),process.exit(1)}}));import{Command as es}from"commander";import{confirm as ts}from"@inquirer/prompts";var yr=new es("delete").description("Delete a presentation").argument("<slug>","Presentation slug (e.g., my-presentation-v1-abc123)").option("-f, --force","Skip confirmation prompt").option("-q, --quiet","Suppress output").action(async(e,n)=>{if(await P(),!n.force)try{if(!await ts({message:`Are you sure you want to delete presentation "${e}"?`,default:!1})){n.quiet||U("Deletion cancelled");return}}catch{n.quiet||U("Deletion cancelled");return}try{await Fo(e),n.quiet||S(`Presentation "${e}" deleted`)}catch(t){c(t instanceof Error?t.message:String(t)),process.exit(t.exitCode??1)}});import{Command as De}from"commander";import wr from"chalk";import ns from"ora";import{createParser as Sm}from"eventsource-parser";import Cm from"chalk";import Rm from"ora";async function br(e,n={}){let t=e.body?.getReader();if(!t)throw new Error("Response body is not readable");let o=new TextDecoder,r="",i=!1;for(;!i;){let a=await t.read();if(i=a.done,a.value){let s=o.decode(a.value,{stream:!0});r+=s,n.quiet||process.stdout.write(s)}}return n.quiet||console.log(),r}function os(){return new De("blog").description("Generate a blog post from a presentation").argument("<slug>","Presentation slug").option("--words <count>","Target word count (50-2000)","300").option("--tone <tone>","Writing tone (professional, casual, educational)","professional").option("--audience <text>","Target audience description").option("-f, --format <format>","Output format (human, json, markdown)","human").option("--instructions <text>","Custom instructions for the blog").option("--no-images","Exclude image references").option("--toc","Include table of contents").action(async(e,n)=>{await P();let t=parseInt(n.words,10);(isNaN(t)||t<50||t>2e3)&&(c("Word count must be between 50 and 2000"),process.exit(6));let o=["professional","casual","educational"];o.includes(n.tone)||(c(`Invalid tone. Valid options: ${o.join(", ")}`),process.exit(6));let r=ns("Fetching presentation...").start();try{let i=await Se(e);r.text="Generating blog post...";let a=await Go(i.id,i.documentCreatedAt||i.createdAt,{targetWordCount:t,tone:n.tone,targetAudience:n.audience??"General Audience",customInstructions:n.instructions??"",includeImages:!n.noImages,includeTableOfContents:n.toc??!1}),s=await br(a,{quiet:!0});r.succeed("Blog generated"),n.format==="json"?console.log(JSON.stringify({presentationId:e,title:i.title,wordCount:t,tone:n.tone,content:s},null,2)):n.format==="markdown"?console.log(s):(console.log(),console.log(wr.bold(`Blog: ${i.title}`)),console.log(wr.gray("\u2500".repeat(40))),console.log(),console.log(s),console.log())}catch(i){r.fail("Generation failed"),c(i instanceof Error?i.message:String(i)),process.exit(i.exitCode??1)}})}function rs(){return new De("tweets").description("Generate tweets from a presentation").argument("<slug>","Presentation slug").option("--count <n>","Number of tweets to generate","5").option("-f, --format <format>","Output format (human, json)","human").action(async(e,n)=>{await P(),p("Tweet generation coming soon.")})}function is(){return new De("linkedin").description("Generate a LinkedIn carousel from a presentation").argument("<slug>","Presentation slug").option("-f, --format <format>","Output format (human, json)","human").action(async e=>{await P(),p("LinkedIn carousel generation coming soon.")})}function as(){return new De("questions").description("Generate questions for a presentation").argument("<slug>","Presentation slug").option("--count <n>","Number of questions","10").option("-f, --format <format>","Output format (human, json)","human").action(async(e,n)=>{await P(),p("Question generation coming soon.")})}function ss(){return new De("cheatsheet").description("Generate a presenter cheat sheet").argument("<slug>","Presentation slug").option("--mode <mode>","Cheat sheet mode (qa-prep, talking-points)","qa-prep").option("-f, --format <format>","Output format (human, json, markdown)","human").action(async(e,n)=>{await P(),p("Cheat sheet generation coming soon.")})}function vr(){let e=new De("derive").description("Generate derivative content from a presentation"),n=mr();return n&&(n.deckToBlog&&e.addCommand(os()),n.deckToTweets&&e.addCommand(rs()),n.linkedInCarousel&&e.addCommand(is()),n.redTeamQuestions&&e.addCommand(as()),n.presenterCheatSheet&&e.addCommand(ss())),e}import{Command as cs}from"commander";import{writeFile as ds}from"fs/promises";import{resolve as xr}from"path";import ls from"ora";var Sr=new cs("export").description("Export a presentation to ZIP").argument("<slug>","Presentation slug (e.g., my-presentation-v1-abc123)").option("-o, --output <path>","Output file path").option("--include-images","Include images (default: true)",!0).option("--include-branding","Include branding (default: true)",!0).option("--no-external","Skip external image downloads").action(async(e,n)=>{await P();let t=ls("Fetching presentation...").start();try{let o=await Se(e),r=o.title||e,i=o.id,a=e.replace(/[^a-z0-9-]/gi,"_").toLowerCase().substring(0,50),s=new Date().toISOString().split("T")[0],d=`${a}_${s}.zip`,u=n.output?xr(n.output):xr(process.cwd(),d);t.text=`Exporting "${r}"...`;let m=await Uo(i,{includeImages:n.includeImages,includeBranding:n.includeBranding,includeExternal:!n.noExternal});t.text="Saving file...",await ds(u,Buffer.from(m)),t.succeed("Export complete!"),console.log(),p(`File saved: ${u}`),p(`Size: ${us(m.byteLength)}`),console.log()}catch(o){t.fail("Export failed"),c(o instanceof Error?o.message:String(o)),process.exit(o.exitCode??1)}});function us(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}import{Command as ms}from"commander";import Cn from"chalk";var Ir=new ms("ideas").description("Generate presentation topic ideas").option("--context <text>","Custom context for idea generation").option("--count <n>","Number of ideas to generate","5").option("-f, --format <format>","Output format (human, json)","human").action(async e=>{await P(),p("Idea generation is available in the web dashboard."),console.log(),console.log(Cn.gray("The CLI will support idea generation in a future release.")),console.log(),console.log("For now, try these approaches:"),console.log(Cn.gray("` 1. Visit the ${brand.displayName} dashboard and use the idea generator`")),console.log(Cn.gray(" 2. Create a presentation with a broad topic and refine it")),console.log()});import{Command as ps}from"commander";import{readFile as gs}from"fs/promises";import{resolve as fs,basename as hs}from"path";import ys from"ora";var Cr=new ps("import").description("Import a presentation from ZIP (admin only)").argument("<file>","Path to ZIP file");Cr._hidden=!0;var Tr=Cr.option("--dry-run","Validate without importing").option("--overwrite","Overwrite existing presentations").option("--remap-ids","Generate new IDs (default: true)",!0).action(async(e,n)=>{await P();try{(await we()).user.role!=="admin"&&(c("This command is only available to administrators"),process.exit(2))}catch{c("Failed to verify permissions"),process.exit(2)}let t=fs(e),o=hs(t);o.endsWith(".zip")||(c("File must be a ZIP archive"),process.exit(6));let r=ys("Reading file...").start();try{let i=await gs(t);n.dryRun?r.text="Validating...":r.text="Importing presentation...";let a=await Mo(i,o,{dryRun:n.dryRun});if(a.success){if(n.dryRun)r.succeed("Validation passed!"),console.log(),p("The file is valid and can be imported."),a.statistics&&(console.log(),R("Slides",String(a.statistics.slidesImported)),R("Images",String(a.statistics.imagesUploaded)));else if(r.succeed("Import complete!"),console.log(),R("Presentation ID",a.presentationId??"N/A"),R("Document ID",a.documentId??"N/A"),a.statistics&&(R("Slides imported",String(a.statistics.slidesImported)),R("Images uploaded",String(a.statistics.imagesUploaded)),R("Time",`${a.statistics.totalTimeMs}ms`)),a.presentationId){let s=j();R("View URL",`${s}/p/${a.presentationId}`)}if(a.warnings&&a.warnings.length>0){console.log();for(let s of a.warnings)U(s)}console.log()}else{if(r.fail("Import failed"),console.log(),a.errors)for(let s of a.errors)c(`${s.type}: ${s.message}`);process.exit(1)}}catch(i){r.fail("Import failed"),i.code==="ENOENT"&&(c(`File not found: ${t}`),process.exit(3)),c(i instanceof Error?i.message:String(i)),process.exit(i.exitCode??1)}});import{Command as bs}from"commander";var Rr=new bs("list").description("List presentations").option("-n, --limit <count>","Number of results to return","20").option("-f, --format <format>","Output format (table, json, ids)","table").option("--sort <field>","Sort by field (created, updated, title)").option("--team-id <id>","Team ID (uses default if not specified)").option("-d, --detail","Show detailed output including URLs").option("-l, --language <lang>","Language for URLs","en").action(async e=>{await P();let n=parseInt(e.limit,10);(isNaN(n)||n<1)&&(c("Invalid limit value"),process.exit(6));let t=e.teamId??yt();t||(c("`Team ID required. Set a default with '${brand.commands[0]} config set team-id <id>' or use --team-id`"),process.exit(6));try{let o=await Do(t,n);if(o.length===0){e.format==="json"?console.log(JSON.stringify([])):e.format!=="ids"&&p("No presentations found");return}switch(e.sort&&o.sort((r,i)=>{switch(e.sort){case"created":return new Date(i.createdAt).getTime()-new Date(r.createdAt).getTime();case"title":return(r.title||"").localeCompare(i.title||"");default:return 0}}),e.format){case"json":console.log(JSON.stringify(o,null,2));break;case"ids":console.log(cr(o));break;default:console.log(sr(o,{showLinks:e.detail,language:e.language}));break}}catch(o){c(o instanceof Error?o.message:String(o)),process.exit(o.exitCode??1)}});import{createHash as ws,randomBytes as $r}from"crypto";import Er from"http";import kr from"chalk";import{Command as vs}from"commander";import xs from"open";import Ar from"ora";var Ss=`${f.displayName} CLI`,Is=8765,Cs=8775,Ts=["presentations:read","presentations:write","media:read","media:write"];function Rs(){return $r(32).toString("base64url")}function ks(e){return ws("sha256").update(e).digest("base64url")}function As(){return $r(16).toString("hex")}async function $s(e,n){for(let t=e;t<=n;t++)try{return await new Promise((o,r)=>{let i=Er.createServer();i.listen(t,()=>{i.close(()=>o())}),i.on("error",r)}),t}catch{}throw new Error(`No available port found between ${e} and ${n}`)}async function Es(e){let n=await fetch(`${e}/.well-known/oauth-authorization-server`);if(!n.ok)throw new Error(`Failed to fetch OAuth metadata: ${n.status}`);return n.json()}function Os(e){let n=e.scopes_supported?.filter(t=>typeof t=="string"&&t.trim().length>0);return(n?.length?n:Ts).join(" ")}async function Ps(e,n,t){let o=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_name:Ss,redirect_uris:[n],grant_types:["authorization_code","refresh_token"],response_types:["code"],token_endpoint_auth_method:"none",scope:t})});if(!o.ok){let r=await o.text();throw new Error(`Client registration failed: ${r}`)}return o.json()}async function _s(e,n,t,o,r){let i=new URLSearchParams({grant_type:"authorization_code",code:n,redirect_uri:o,client_id:r,code_verifier:t}),a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:i.toString()});if(!a.ok){let s=await a.text();throw new Error(`Token exchange failed: ${s}`)}return a.json()}function Ns(e,n){return new Promise((t,o)=>{let r,i=!1,a=()=>{i||(i=!0,clearTimeout(r),process.off("SIGINT",s),process.off("SIGTERM",s),d.close())},s=()=>{a(),o(new Error("Login cancelled"))},d=Er.createServer((u,m)=>{let b=new URL(u.url||"",`http://localhost:${e}`);if(b.pathname!=="/callback"){m.writeHead(404),m.end("Not found");return}let C=b.searchParams.get("code"),g=b.searchParams.get("state"),T=b.searchParams.get("error"),v=b.searchParams.get("error_description");if(m.writeHead(200,{"Content-Type":"text/html"}),T){m.end(`
|
|
5
5
|
<!DOCTYPE html>
|
|
6
6
|
<html>
|
|
7
7
|
<head><title>Login Failed</title></head>
|
|
8
8
|
<body style="font-family: system-ui; text-align: center; padding: 50px;">
|
|
9
9
|
<h1 style="color: #dc2626;">Login Failed</h1>
|
|
10
|
-
<p>${
|
|
10
|
+
<p>${v||T}</p>
|
|
11
11
|
<p>You can close this window.</p>
|
|
12
12
|
</body>
|
|
13
13
|
</html>
|
|
14
|
-
`),a(),o(new Error(
|
|
14
|
+
`),a(),o(new Error(v||T));return}if(!C||!g){m.end(`
|
|
15
15
|
<!DOCTYPE html>
|
|
16
16
|
<html>
|
|
17
17
|
<head><title>Login Failed</title></head>
|
|
@@ -21,7 +21,7 @@ var h={id:"mindframes",name:"mindframes",displayName:"Mindframes",description:"C
|
|
|
21
21
|
<p>You can close this window.</p>
|
|
22
22
|
</body>
|
|
23
23
|
</html>
|
|
24
|
-
`),a(),o(new Error("Missing authorization code or state"));return}if(
|
|
24
|
+
`),a(),o(new Error("Missing authorization code or state"));return}if(g!==n){m.end(`
|
|
25
25
|
<!DOCTYPE html>
|
|
26
26
|
<html>
|
|
27
27
|
<head><title>Login Failed</title></head>
|
|
@@ -31,7 +31,7 @@ var h={id:"mindframes",name:"mindframes",displayName:"Mindframes",description:"C
|
|
|
31
31
|
<p>You can close this window.</p>
|
|
32
32
|
</body>
|
|
33
33
|
</html>
|
|
34
|
-
`),a(),o(new Error("State mismatch"));return}
|
|
34
|
+
`),a(),o(new Error("State mismatch"));return}m.end(`
|
|
35
35
|
<!DOCTYPE html>
|
|
36
36
|
<html>
|
|
37
37
|
<head><title>Login Successful</title></head>
|
|
@@ -40,24 +40,24 @@ var h={id:"mindframes",name:"mindframes",displayName:"Mindframes",description:"C
|
|
|
40
40
|
<p>You can close this window and return to the terminal.</p>
|
|
41
41
|
</body>
|
|
42
42
|
</html>
|
|
43
|
-
`),a(),t({code:
|
|
44
|
-
`)[0]??"";t(a?{bin:n,version:a}:null)})})}var
|
|
43
|
+
`),a(),t({code:C,state:g})});d.listen(e),process.once("SIGINT",s),process.once("SIGTERM",s),r=setTimeout(()=>{a(),o(new Error("Login timed out - no callback received within 5 minutes"))},300*1e3)})}async function Ls(e,n){let t=await fetch(`${e}/api/cli/whoami`,{headers:{Authorization:`Bearer ${n}`}});if(!t.ok)throw new Error(`Failed to fetch user info: ${t.status}`);return t.json()}async function Ds(e){let n=j(),t=Ar("Discovering OAuth server...").start();try{let o=await Es(n),r=Os(o);t.succeed(`Connecting to ${n}`);let i=await $s(Is,Cs),a=`http://localhost:${i}/callback`;console.log(`Redirect URI: ${a}`),console.log(`Authorization endpoint: ${o.authorization_endpoint}`),console.log(`Token endpoint: ${o.token_endpoint}`),console.log(`Registration endpoint: ${o.registration_endpoint}`);let s=await Ps(o.registration_endpoint,a,r),d=s.client_id;ko(d,s.client_secret);let u=Rs(),m=ks(u),b=As(),C=new URLSearchParams({client_id:d,redirect_uri:a,response_type:"code",scope:r,state:b,code_challenge:m,code_challenge_method:"S256"}),g=`${o.authorization_endpoint}?${C}`;console.log(`Authorization URL: ${g}`),e.browser?(p("Opening browser..."),await xs(g)):(console.log(kr.bold("Open this URL in your browser:")),console.log(kr.cyan(g)));let T=Ns(i,b),{code:v}=await T;t=Ar("Completing login...").start();let y=await _s(o.token_endpoint,v,u,a,d);wt(y.access_token,y.refresh_token,y.expires_in);let w=await Ls(n,y.access_token);t.succeed("Logged in!"),console.log(),R("Logged in as",w.user.email),w.currentTeam&&(_e(w.currentTeam.id),R("Team",`${w.currentTeam.name} (${w.currentTeam.planName})`));try{await ke()}catch{}console.log(),S("You're all set!"),console.log()}catch(o){throw t.fail("Login failed"),c(o instanceof Error?o.message:String(o)),o}}var Or=new vs("login").description(`Authenticate with ${f.displayName} (opens browser)`).option("--no-browser","Print URL instead of opening browser").action(async e=>{console.log(),Te()&&(U("You are already logged in."),p(`Run '${f.commands[0]} logout' to log out first, or continue to re-authenticate.`),console.log());try{await Ds(e),process.exit(0)}catch{process.exit(1)}});import{Command as Fs}from"commander";import{confirm as Us}from"@inquirer/prompts";var Pr=new Fs("logout").description("Log out and clear authentication").option("--all","Clear all config including API key").action(async e=>{console.log();let n=Te(),t=Ne();if(!n&&!t){U("You are not logged in."),console.log();return}if(e.all)try{await Us({message:"Clear all configuration including API key?",default:!1})?(bt(),Ae(),S("All configuration cleared.")):p("Cancelled.")}catch{p("Cancelled.")}else vt(),Ae(),S("Logged out successfully."),t&&p("Note: Your API key is still configured. Use --all to clear everything.");console.log()});import{homedir as Ic}from"os";import{join as Cc}from"path";import de from"chalk";import{Command as Tc}from"commander";import{spawn as Ms}from"child_process";import{existsSync as Vs,readdirSync as js}from"fs";import{homedir as Lr}from"os";import{delimiter as _r}from"path";import{query as qs}from"@anthropic-ai/claude-agent-sdk";function ie(e){if(e===void 0)return null;if(typeof e=="string")return e.length>12e3?`${e.slice(0,12e3)}\u2026`:e;try{let n=JSON.stringify(e);return n.length<=12e3?e:{preview:`${n.slice(0,12e3)}\u2026`,truncated:!0}}catch{return String(e).slice(0,12e3)}}function At(e){let n=typeof e=="string"?e:String(e??"");return n.length>12e3?`${n.slice(0,12e3)}\u2026`:n}function ae(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function D(e){return typeof e=="string"?e:""}function Nr(e,n){let t=e.replace(/[/.]/g,"-");return`${Lr()}/.claude/projects/${t}/${n}.jsonl`}function Bs(e){try{return js(`${e}/.nvm/versions/node`).map(n=>`${e}/.nvm/versions/node/${n}/bin`).sort().reverse()}catch{return[]}}function $t(){let e=Lr(),n=[`${e}/.local/bin`,`${e}/.claude/local`,`${e}/.bun/bin`,`${e}/bin`,"/opt/homebrew/bin","/usr/local/bin",...Bs(e)],o=(process.env.PATH??"").split(_r);for(let r of n)o.includes(r)||o.push(r);return o.join(_r)}async function Et(e){let n=e??"claude";return new Promise(t=>{let o=Ms(n,["--version"],{env:{...process.env,PATH:$t()},stdio:["ignore","pipe","ignore"]}),r="";o.stdout.on("data",i=>{r+=i.toString("utf8")}),o.on("error",()=>t(null)),o.on("close",i=>{if(i!==0)return t(null);let a=r.trim().split(`
|
|
44
|
+
`)[0]??"";t(a?{bin:n,version:a}:null)})})}var Gs=new Set(["","default","best"]);function Tn(e){let n=e.filter(i=>i.text.trim());if(n.length===0)return"";let t=n[n.length-1],o=n.slice(0,-1);return o.length===0?t.text:`<conversation-history>
|
|
45
45
|
${o.map(i=>`${i.role==="assistant"?"Assistant":"User"}: ${i.text}`).join(`
|
|
46
46
|
|
|
47
47
|
`)}
|
|
48
48
|
</conversation-history>
|
|
49
49
|
|
|
50
|
-
${t.text}`}function
|
|
51
|
-
`)[0]??"";n(i||null)})})}var
|
|
52
|
-
`)}catch{return[]}let t=new Set,o=new Map,r=null;for(let i of n){if(!i.trim())continue;let a;try{a=JSON.parse(i)}catch{continue}let s=ae(a.payload);if(a.type==="response_item"&&s.type==="custom_tool_call"){let d=
|
|
53
|
-
`);return a===-1?"":i.slice(a+1)}finally{
|
|
54
|
-
`):e&&typeof e=="object"?Object.values(e).map(
|
|
55
|
-
`):""}function
|
|
56
|
-
|
|
57
|
-
`),usage:a}}function
|
|
58
|
-
`,"utf8")}catch{}}function
|
|
59
|
-
`,"utf8")}catch{}}var
|
|
60
|
-
Stopping runner\u2026`)),n.abort()};process.on("SIGINT",t),process.on("SIGTERM",t);try{await
|
|
50
|
+
${t.text}`}function Rn(e,n){return n?e.messages.filter(o=>o.text.trim()).at(-1)?.text??"":Tn(e.messages)}function Ws({abortController:e,input:n,resumeSessionId:t,workspace:o}){let r=(n.modelId??"").trim(),i=n.thinking??null,a={abortController:e,allowedTools:["WebSearch","WebFetch"],cwd:o,env:{...process.env,PATH:$t()},includePartialMessages:!0,maxTurns:16,permissionMode:"dontAsk"};return Gs.has(r)||(a.model=r),n.effort&&(a.effort=n.effort),i&&i!=="disabled"&&(a.thinking={display:"summarized",type:i==="enabled"?"enabled":"adaptive"}),t?a.resume=t:n.system?.trim()&&(a.systemPrompt=n.system),a}async function Dr(e){let n=Rn(e.input,e.resumeSessionId);if(!n)throw new Error("Chat turn has no user text to send.");let t=new AbortController,o=()=>t.abort();e.signal?.addEventListener("abort",o,{once:!0});let r=null,i=null,a=null,s=null,d=null,u=0,m=new Set;try{let g=qs({prompt:n,options:Ws({abortController:t,input:e.input,resumeSessionId:e.resumeSessionId,workspace:e.workspace})});for await(let T of g){let v=T;if(v.type==="system"&&v.subtype==="init"){typeof v.session_id=="string"&&(i=v.session_id,e.onEvent({eventType:"chat.session",payload:{sessionId:i,sessionPath:Nr(e.workspace,i)}})),typeof v.model=="string"&&(r=v.model,e.onEvent({eventType:"chat.model",payload:{modelId:v.model}}));continue}if(v.type==="stream_event"){let y=v.event;if(y?.type!=="content_block_delta")continue;let w=y.delta;if(!w)continue;w.type==="text_delta"&&typeof w.text=="string"?(u+=w.text.length,e.onEvent({eventType:"chat.text.delta",payload:{text:w.text}})):w.type==="thinking_delta"&&typeof w.thinking=="string"&&e.onEvent({eventType:"chat.reasoning.delta",payload:{text:w.thinking}});continue}if(v.type==="assistant"){let y=ae(v.message),w=Array.isArray(y.content)?y.content:[];for(let E of w){let A=ae(E);if(A.type!=="tool_use")continue;let _=D(A.id),I=D(A.name);!_||!I||m.has(_)||(m.add(_),e.onEvent({eventType:"chat.tool.started",payload:{input:ie(A.input),toolCallId:_,toolName:I}}))}continue}if(v.type==="user"){let y=ae(v.message),w=Array.isArray(y.content)?y.content:[];for(let E of w){let A=ae(E);if(A.type!=="tool_result")continue;let _=D(A.tool_use_id);_&&e.onEvent({eventType:"chat.tool.completed",payload:{...A.is_error===!0?{errorText:typeof A.content=="string"?At(A.content):"Claude tool call failed."}:{},output:ie(A.content),toolCallId:_}})}continue}v.type==="result"&&(typeof v.result=="string"&&(s=v.result),v.usage&&typeof v.usage=="object"&&(a=v.usage),typeof v.session_id=="string"&&(i=v.session_id),(v.is_error===!0||v.subtype!=="success")&&(d=typeof v.result=="string"&&v.result||`Claude turn failed (${String(v.subtype)}).`,e.onEvent({eventType:"chat.error",message:d,payload:{message:d}})))}}finally{e.signal?.removeEventListener("abort",o)}if(e.signal?.aborted)throw new Error("Chat turn cancelled.");if(d)throw new Error(d);let b=s??"";u===0&&b&&e.onEvent({eventType:"chat.text.delta",payload:{text:b}});let C=i?Nr(e.workspace,i):null;return{modelId:r,sessionId:i,sessionPath:C&&Vs(C)?C:null,text:b,usage:a}}import{spawn as Hs}from"child_process";import{closeSync as Js,fstatSync as zs,openSync as Xs,readdirSync as Ys,readSync as Ks}from"fs";import{homedir as Qs}from"os";import{join as Fr}from"path";import{Codex as Zs}from"@openai/codex-sdk";var ec=["/Applications/Codex.app/Contents/Resources/codex"];async function Ot(e){let n=e?[e]:["codex",...ec];for(let t of n){let o=await tc(t);if(o)return{bin:t,version:o}}return null}function tc(e){return new Promise(n=>{let t=Hs(e,["--version"],{env:{...process.env,PATH:$t()},stdio:["ignore","pipe","ignore"]}),o="";t.stdout.on("data",r=>{o+=r.toString("utf8")}),t.on("error",()=>n(null)),t.on("close",r=>{if(r!==0)return n(null);let i=o.trim().split(`
|
|
51
|
+
`)[0]??"";n(i||null)})})}var nc=24,oc=4*1024*1024,Vr=new Set(["custom_tool_call","custom_tool_call_output","dynamic_tool_call","function_call"]);function rc(e){let n;try{n=ic(e).split(`
|
|
52
|
+
`)}catch{return[]}let t=new Set,o=new Map,r=null;for(let i of n){if(!i.trim())continue;let a;try{a=JSON.parse(i)}catch{continue}let s=ae(a.payload);if(a.type==="response_item"&&s.type==="custom_tool_call"){let d=D(s.call_id),u=D(s.input);d&&s.name==="exec"&&/\btools\.web__run\s*\(/.test(u)&&(t.add(d),r=d);continue}if(a.type==="event_msg"&&s.type==="web_search_end"){let d=D(s.call_id);if(!d||!r)continue;let u=D(s.query),m=ae(s.action),C={action:{...m,...u&&!D(m.query)?{query:u}:{}},query:u,sources:Ur(s.results),toolCallId:d},g=o.get(r)??[];g.push(C),o.set(r,g);continue}if(a.type==="response_item"&&s.type==="custom_tool_call_output"){let d=D(s.call_id);if(!d||!t.has(d))continue;let u=Ur(s.output);for(let m of o.get(d)??[])m.sources.length===0&&(m.sources=u);r===d&&(r=null)}}return Array.from(o.values()).flat()}function ic(e){let n=Xs(e,"r");try{let t=zs(n).size,o=Math.max(0,t-oc),r=Buffer.alloc(t-o);Ks(n,r,0,r.length,o);let i=r.toString("utf8");if(o===0)return i;let a=i.indexOf(`
|
|
53
|
+
`);return a===-1?"":i.slice(a+1)}finally{Js(n)}}function Ur(e){let t=$n(e).match(/https?:\/\/[^\s<>"'()[\]{}\\]+/g)??[],o=new Set,r=[];for(let i of t){let a=i.replace(/[.,;:!?]+$/,"");try{let s=new URL(a);if(s.protocol!=="http:"&&s.protocol!=="https:"||o.has(s.href))continue;if(o.add(s.href),r.push({type:"url",url:s.href}),r.length>=nc)break}catch{}}return r}function $n(e){return typeof e=="string"?e:Array.isArray(e)?e.map($n).join(`
|
|
54
|
+
`):e&&typeof e=="object"?Object.values(e).map($n).join(`
|
|
55
|
+
`):""}function kn(e,n){let t=ae(e),o=D(t.type),r=D(t.id),i=D(t.call_id)||D(t.tool_call_id),a=Vr.has(o)?i||r:r||i;if(!a)return null;if(o==="command_execution"){let s=D(t.command),d=D(t.status),u={exitCode:typeof t.exit_code=="number"?t.exit_code:null,output:ie(t.aggregated_output)};return{...n&&d==="failed"?{errorText:At(t.aggregated_output)||"Command failed."}:{},input:{command:s},...n?{output:u}:{},toolCallId:a,toolName:"Bash"}}if(o==="mcp_tool_call"){let s=ae(t.error);return{...n&&D(s.message)?{errorText:D(s.message)}:{},input:ie(t.arguments),...n?{output:ie(t.result??{status:t.status??"completed"})}:{},toolCallId:a,toolName:D(t.tool)||D(t.name)||"Codex tool"}}if(o==="web_search"){let s=D(t.query);return{input:{query:s},...n?{output:{query:s}}:{},toolCallId:a,toolName:"web_search"}}if(o==="file_change"){let s=D(t.status);return{...n&&s==="failed"?{errorText:"Codex could not apply the file changes."}:{},input:{changes:ie(t.changes)},...n?{output:{changes:ie(t.changes),status:s}}:{},toolCallId:a,toolName:"ApplyPatch"}}if(o==="custom_tool_call_output")return{input:{},...n?{output:ie(t.output)}:{},toolCallId:a,toolName:"Codex tool"};if(o==="custom_tool_call"||o==="dynamic_tool_call"||o==="function_call"){let s=D(t.name)||D(t.tool)||"Codex tool",d=t.input??t.arguments??{};return{input:s==="exec"&&typeof d=="string"?{command:d}:ie(d),...n?{output:ie(t.output??t.result??{status:t.status??"completed"})}:{},toolCallId:a,toolName:s}}return null}function An(e,n=Fr(Qs(),".codex","sessions")){try{let o=Ys(n,{recursive:!0}).find(r=>typeof r=="string"&&r.endsWith(`${e}.jsonl`));return o?Fr(n,o):null}catch{return null}}function ac(e,n){return n?Rn(e,n):Tn(e.messages)}function sc(e,n,t=f.codexSelfConnectorAppId){let o=n.system?.trim(),r={...o?{developer_instructions:o}:{},...t?{apps:{[t]:{enabled:!1}}}:{}};return{codexPathOverride:e,...Object.keys(r).length>0?{config:r}:{}}}var cc=new Set(["minimal","low","medium","high","xhigh"]);function dc(e,n){let t={networkAccessEnabled:!0,sandboxMode:"workspace-write",skipGitRepoCheck:!0,webSearchEnabled:!0,workingDirectory:n},o=(e.modelId??"").trim();return o&&o!=="default"&&(t.model=o),e.effort&&cc.has(e.effort)&&(t.modelReasoningEffort=e.effort),t}async function jr(e){let n=ac(e.input,e.resumeSessionId);if(!n)throw new Error("Chat turn has no user text to send.");let t=new Zs(sc(e.bin,e.input)),o=dc(e.input,e.workspace),r=e.resumeSessionId?t.resumeThread(e.resumeSessionId,o):t.startThread(o),i=e.resumeSessionId??null,a=null,s=null,d=[],u=new Set,m=new Set,b=null,C=v=>{b??=An(v,e.sessionsRoot),e.onEvent({eventType:"chat.session",payload:{sessionId:v,sessionPath:b}})},g=v=>{i&&(b??=An(i,e.sessionsRoot));let y=b?rc(b):[],w=D(ae(v.input).query),E=Mr(w),A=y.find(_=>!u.has(_.toolCallId)&&Mr(_.query)===E)??y.find(_=>!u.has(_.toolCallId));A&&u.add(A.toolCallId),e.onEvent({eventType:"chat.tool.completed",payload:{...v,output:A?{action:A.action,query:A.query,sources:A.sources}:{action:{query:w,type:"search"},sourceListUnavailable:!0,sources:[]}}})},{events:T}=await r.runStreamed(n);i&&C(i);for await(let v of T){if(e.signal?.aborted)throw await T.return?.(void 0),new Error("Chat turn cancelled.");let y=v;if(y.type==="thread.started"){typeof y.thread_id=="string"&&(i=y.thread_id,C(y.thread_id));continue}if(y.type==="item.started"){let w=kn(y.item,!1);if(w){e.onEvent({eventType:"chat.tool.started",payload:w});let E=ae(y.item);if(Vr.has(D(E.type))&&D(E.status)==="completed"){let A=kn(E,!0);A&&(m.add(A.toolCallId),e.onEvent({eventType:"chat.tool.completed",payload:A}))}}continue}if(y.type==="item.completed"){let w=y.item;if(!w)continue;if(w.type==="agent_message"&&typeof w.text=="string")d.push(w.text),e.onEvent({eventType:"chat.text.delta",payload:{text:w.text}});else if(w.type==="reasoning"&&typeof w.text=="string")e.onEvent({eventType:"chat.reasoning.delta",payload:{text:w.text}});else{let E=kn(w,!0);E&&(w.type==="web_search"?g(E):w.type==="custom_tool_call"&&m.has(E.toolCallId)||e.onEvent({eventType:"chat.tool.completed",payload:E}))}continue}if(y.type==="turn.completed"){y.usage&&typeof y.usage=="object"&&(a=y.usage);continue}if(y.type==="turn.failed"){let w=y.error;s=typeof w?.message=="string"&&w.message||"Codex turn failed.",e.onEvent({eventType:"chat.error",message:s,payload:{message:s}})}}if(s)throw new Error(s);return i=r.id??i,i&&(b??=An(i,e.sessionsRoot)),{modelId:e.input.modelId??null,sessionId:i,sessionPath:b,text:d.join(`
|
|
56
|
+
|
|
57
|
+
`),usage:a}}function Mr(e){return e.trim().replace(/\s+/g," ").toLocaleLowerCase()}import{randomUUID as gc}from"crypto";import{mkdir as fc}from"fs/promises";import{hostname as _t,platform as hc}from"os";import{join as yc}from"path";var Fe=class extends Error{constructor(t,o,r=!1){super(t);this.statusCode=o;this.reRegister=r;this.name="RunnerApiError"}statusCode;reRegister};async function Ue(e,n={}){let t=await ge();n.body!==void 0&&(t["Content-Type"]="application/json");let o=new AbortController,r=setTimeout(()=>o.abort(),n.timeoutMs??3e4),i=()=>o.abort();n.signal?.addEventListener("abort",i,{once:!0});try{let a=await fetch(`${j()}${e}`,{body:n.body!==void 0?JSON.stringify(n.body):void 0,headers:t,method:n.method??"GET",signal:o.signal}),s=await a.text(),d={};try{d=s?JSON.parse(s):{}}catch{d={error:s.slice(0,300)}}if(!a.ok)throw new Fe(typeof d.error=="string"?d.error:`Runner API returned ${a.status}`,a.status,d.reRegister===!0);return d}finally{clearTimeout(r),n.signal?.removeEventListener("abort",i)}}async function qr(e){await Ue("/api/runner/register",{body:e,method:"POST",timeoutMs:15e3})}async function Br(e,n){return(await Ue(`/api/runner/work?runnerId=${encodeURIComponent(e)}`,{signal:n,timeoutMs:28e3})).job??null}async function Gr(e){await Ue("/api/runner/heartbeat",{body:{runnerId:e},method:"POST",timeoutMs:1e4})}async function Wr(e,n){return{cancelRequested:(await Ue(`/api/runner/jobs/${encodeURIComponent(e)}/events`,{body:{events:n},method:"POST",timeoutMs:15e3})).cancelRequested===!0}}async function En(e,n,t){await Ue(`/api/runner/jobs/${encodeURIComponent(e)}/complete`,{body:{result:t,runnerId:n},method:"POST",timeoutMs:15e3})}async function Pt(e,n,t,o=!0){await Ue(`/api/runner/jobs/${encodeURIComponent(e)}/fail`,{body:{message:t,retryable:o,runnerId:n},method:"POST",timeoutMs:15e3})}import{mkdirSync as lc,readFileSync as uc,writeFileSync as Hr}from"fs";import{dirname as mc,join as pc}from"path";function On(e){return pc(e,"sessions.json")}function Pn(e){try{let n=uc(On(e),"utf8"),t=JSON.parse(n);if(t&&typeof t=="object"&&!Array.isArray(t))return t}catch{}return{}}function Jr(e,n,t){return n?Pn(e)[n]?.[t]??null:null}function zr(e,n,t,o){if(!(!n||!o))try{let r=On(e);lc(mc(r),{recursive:!0});let i=Pn(e);i[n]={...i[n],[t]:o},Hr(r,`${JSON.stringify(i,null," ")}
|
|
58
|
+
`,"utf8")}catch{}}function Xr(e,n,t){if(n)try{let o=Pn(e);if(!o[n])return;delete o[n][t],Hr(On(e),`${JSON.stringify(o,null," ")}
|
|
59
|
+
`,"utf8")}catch{}}var bc=300,wc=3e4;async function Yr(e){let[n,t]=await Promise.all([Et(e.claudeBin),Ot(e.codexBin)]);if(!n&&!t)throw new Error("Neither Claude Code nor Codex was found on this machine. Install one and log in, then retry.");n?e.log(`Claude Code detected: ${n.version} (${n.bin})`):e.log("Claude Code not found \u2014 Claude turns will be declined."),t?e.log(`Codex detected: ${t.version} (${t.bin})`):e.log("Codex not found \u2014 Codex turns will be declined.");let o=[...n?["claude-code"]:[],...t?["codex"]:[]],r=`${_t().split(".")[0]}-${gc().slice(0,8)}`,i=()=>qr({capabilities:["chat_turn","proof"],claudeCodeVersion:n?.version??null,cliVersion:e.version,codexVersion:t?.version??null,hostname:_t(),platform:hc(),runnerId:r,runtimes:o});for(await i(),e.log(`Registered as ${r} (runtimes: ${o.join(", ")}). Waiting for work\u2026`);!e.signal?.aborted;){let a=null;try{a=await Br(r,e.signal)}catch(s){if(e.signal?.aborted)break;if(s instanceof Fe&&s.reRegister){e.log("Server asked for re-registration."),await i().catch(()=>{});continue}e.log(`Work poll failed (${s instanceof Error?s.message:"unknown"}); retrying\u2026`),await Sc(e.pollBackoffMs??5e3,e.signal);continue}if(!a){if(e.once)continue;continue}if(e.log(`Claimed ${a.jobType} job ${a.runId}.`),await vc({claude:n,codex:t,job:a,options:e,runnerId:r}),e.once)break}}async function vc({claude:e,codex:n,job:t,options:o,runnerId:r}){let i=new AbortController,a=()=>i.abort();o.signal?.addEventListener("abort",a,{once:!0});let s=setInterval(()=>{Gr(r).catch(()=>{})},wc),d=[],u=!1,m=async()=>{if(u||d.length===0)return;u=!0;let g=d.splice(0,100);try{let{cancelRequested:T}=await Wr(t.runId,g);T&&i.abort()}catch(T){T instanceof Fe&&T.statusCode===409&&i.abort()}finally{u=!1}},b=setInterval(()=>{m()},bc),C=g=>{d.push(g)};try{if(t.jobType==="runner.proof"){let g=typeof t.input.message=="string"?t.input.message:"proof";C({eventType:"proof.echo",payload:{message:g}}),await _n(m,d),await En(t.runId,r,{echo:g}),o.log(`Proof job ${t.runId} completed.`);return}if(t.jobType==="runner.chat_turn"){let g=t.input.runtime==="codex"?"codex":"claude-code",T=g==="codex"?n&&{detection:n,run:jr}:e&&{detection:e,run:Dr};if(!T){await Pt(t.runId,r,g==="codex"?"Codex is not available on this machine. Install the Codex app or CLI and log in, then retry.":"Claude Code is not available on this machine. Install it and log in, then retry.",!1);return}let v=typeof t.input.chatId=="string"&&t.input.chatId?t.input.chatId:null,y=yc(o.workspaceRoot,"chats",v??t.runId);await fc(y,{recursive:!0});let w=xc(t.input),E=I=>C({eventType:I.eventType,message:I.message??null,payload:I.eventType==="chat.session"?{host:_t(),runtime:g,runtimeVersion:T.detection.version,...I.payload??{}}:I.payload??{}}),A=Jr(o.workspaceRoot,v,g),_;try{_=await T.run({bin:T.detection.bin,input:w,onEvent:E,resumeSessionId:A,signal:i.signal,workspace:y})}catch(I){if(!A||i.signal.aborted)throw I;o.log(`Resume of ${g} session failed (${I instanceof Error?I.message:"unknown"}); retrying fresh.`),Xr(o.workspaceRoot,v,g),_=await T.run({bin:T.detection.bin,input:w,onEvent:E,resumeSessionId:null,signal:i.signal,workspace:y})}zr(o.workspaceRoot,v,g,_.sessionId),C({eventType:"chat.session",payload:{host:_t(),runtime:g,runtimeVersion:T.detection.version,sessionId:_.sessionId,sessionPath:_.sessionPath}}),await _n(m,d),await En(t.runId,r,{modelId:_.modelId,runtime:g,runtimeVersion:T.detection.version,sessionId:_.sessionId,sessionPath:_.sessionPath,text:_.text,usage:_.usage??{}}),o.log(`Chat turn ${t.runId} (${g}) completed.`);return}await Pt(t.runId,r,`This runner does not support ${t.jobType} jobs. Update the desktop app / CLI.`,!1)}catch(g){let T=g instanceof Error?g.message:"Local runner job crashed.";o.log(`Job ${t.runId} failed: ${T}`),await _n(m,d).catch(()=>{}),await Pt(t.runId,r,T).catch(()=>{})}finally{clearInterval(b),clearInterval(s),o.signal?.removeEventListener("abort",a)}}function xc(e){let n=Array.isArray(e.messages)?e.messages.map(t=>{if(!t||typeof t!="object")return null;let o=t;return{role:typeof o.role=="string"?o.role:"user",text:typeof o.text=="string"?o.text:""}}).filter(t=>!!t):[];return{effort:typeof e.effort=="string"?e.effort:null,messages:n,modelId:typeof e.modelId=="string"?e.modelId:null,system:typeof e.system=="string"?e.system:null,thinking:typeof e.thinking=="string"?e.thinking:null}}async function _n(e,n){for(;n.length>0;)await e(),n.length>0&&await new Promise(t=>setTimeout(t,25))}function Sc(e,n){return e<=0||n?.aborted?Promise.resolve():new Promise(t=>{let o=setTimeout(r,e);function r(){clearTimeout(o),n?.removeEventListener("abort",r),t()}n?.addEventListener("abort",r,{once:!0})})}function Rc(){return Cc(Ic(),`.${f.commands[0]}-runner`,"runs")}var Nt=new Tc("runner").description("Run agent work locally with your own Claude Code / Codex login (desktop lane)");Nt.command("status").description("Check local Claude Code / Codex detection and account auth").action(async()=>{let[e,n]=await Promise.all([Et(),Ot()]);if(console.log(e?de.green(`\u2713 Claude Code ${e.version}`):de.red("\u2717 Claude Code not found on PATH")),console.log(n?de.green(`\u2713 Codex ${n.version} (${n.bin})`):de.red("\u2717 Codex not found (PATH or Codex.app)")),!ce()){console.log(de.red(`\u2717 Not logged in. Run '${f.commands[0]} login' first.`)),process.exitCode=2;return}try{let t=await we();console.log(de.green(`\u2713 Logged in as ${t.user.email}`))}catch(t){console.log(de.red(`\u2717 Auth check failed: ${t instanceof Error?t.message:"unknown"}`)),process.exitCode=2}});Nt.command("start").description("Start the local runner (register + wait for work)").option("--once","Execute a single job, then exit").option("--workspace <dir>","Workspace root for job scratch directories").option("--claude-bin <path>","Path to the claude binary").option("--codex-bin <path>","Path to the codex binary").action(async e=>{ce()||(console.error(de.red(`Not authenticated. Run '${f.commands[0]} login' first.`)),process.exit(2));let n=new AbortController,t=()=>{console.log(de.gray(`
|
|
60
|
+
Stopping runner\u2026`)),n.abort()};process.on("SIGINT",t),process.on("SIGTERM",t);try{await Yr({claudeBin:e.claudeBin,codexBin:e.codexBin,log:o=>console.log(de.gray(`[runner] ${o}`)),once:e.once,signal:n.signal,version:"0.3.15",workspaceRoot:e.workspace??Rc()})}catch(o){console.error(de.red(o instanceof Error?o.message:String(o))),process.exit(1)}});import{Command as Pc}from"commander";import M from"chalk";function Lt(e){let{name:n,cmd:t}=e,o=n.toUpperCase().replace(/[^A-Z0-9]/g,"_");return`---
|
|
61
61
|
name: ${n}
|
|
62
62
|
description: CLI with TTS (text-to-speech), AI music generation, sound effects, stock image/video search, audio mixing, URL scraping, and branding. Use when user asks for voiceover, narration, background music, sound effects, stock footage, or needs to scrape a website.
|
|
63
63
|
---
|
|
@@ -130,7 +130,7 @@ ${t} whoami
|
|
|
130
130
|
### Config
|
|
131
131
|
\`${t} config show\` \u2192 [references/config.md](references/config.md)
|
|
132
132
|
|
|
133
|
-
`}function
|
|
133
|
+
`}function Dt(e){let{name:n,cmd:t,mode:o="standalone"}=e,r=o==="studio";return`---
|
|
134
134
|
name: ${n}-video
|
|
135
135
|
description: Orchestrates video creation by coordinating specialized agents for branding, audio, and scene building. Gathers context, writes briefs, generates plans, and assembles Remotion videos. Use when user says "create a video", "make a promo", "product demo", "explainer video", "marketing video", "gather video assets", "video for my project", or "TikTok/Reels content".
|
|
136
136
|
---
|
|
@@ -644,7 +644,7 @@ The \`${t}\` CLI has tools for working with individual assets directly. This is
|
|
|
644
644
|
- **Audio mixing:** \`${t} mix\` \u2014 combine voice, music, and video tracks.
|
|
645
645
|
|
|
646
646
|
During the main workflow, branding and audio are handled by their dedicated agents. But for one-off fixes or user requests outside the workflow, use these commands directly.
|
|
647
|
-
`}function
|
|
647
|
+
`}function Ft(e){let{name:n,cmd:t}=e;return`---
|
|
648
648
|
name: ${n}-presentation
|
|
649
649
|
description: Use when user asks to create presentations, slides, decks, pitch decks.
|
|
650
650
|
Researches the topic, gathers context, and generates AI-powered presentations via CLI.
|
|
@@ -864,7 +864,7 @@ ${t} import ./presentation.zip
|
|
|
864
864
|
- **Auth fails** \u2192 \`${t} logout && ${t} login\` (browser required)
|
|
865
865
|
- **"Context required"** \u2192 add \`--context\`, \`--file\`, or \`--context-file\`
|
|
866
866
|
- **Rate limit (429)** \u2192 check plan with \`${t} whoami\`
|
|
867
|
-
`}function
|
|
867
|
+
`}function Ut(e){let{name:n,cmd:t}=e;return`---
|
|
868
868
|
name: ${n}-presentation-edit
|
|
869
869
|
description: >
|
|
870
870
|
Use ONLY when editing an already-created presentation that has real slides:
|
|
@@ -1101,7 +1101,7 @@ Do NOT render or export the presentation \u2014 that's handled by the app.
|
|
|
1101
1101
|
| Create brand-new presentation (5+ slides, new topic) | \`${t} create ...\` via CLI |
|
|
1102
1102
|
| Redesign the whole deck | \`${t} create ...\` via CLI, then sync |
|
|
1103
1103
|
| User provides a URL to base the presentation on | \`${t} scrape <url>\` \u2192 \`${t} create ...\` |
|
|
1104
|
-
`}function
|
|
1104
|
+
`}function Me(e){let{name:n,cmd:t}=e;return`---
|
|
1105
1105
|
name: ${n}-tts
|
|
1106
1106
|
description: Text-to-speech generation. Convert text to natural speech with multiple providers (Gemini, ElevenLabs, OpenAI) and voices. Use for voiceovers, narration, accessibility.
|
|
1107
1107
|
---
|
|
@@ -1441,7 +1441,7 @@ ${t} music generate -p "calm piano" -d 30 -f json
|
|
|
1441
1441
|
2. **Looping** - For seamless loops, mention "loopable" in prompt.
|
|
1442
1442
|
3. **Video sync** - Use \`video generate assets\` to auto-generate music for video projects.
|
|
1443
1443
|
4. **Volume mixing** - Background music should be 20-30% volume when mixed with voiceover.
|
|
1444
|
-
`}function
|
|
1444
|
+
`}function je(e){let{name:n,cmd:t}=e;return`---
|
|
1445
1445
|
name: ${n}-sfx
|
|
1446
1446
|
description: AI sound effects generation from text descriptions. Create foley, ambient, UI sounds, impacts, whooshes for videos, games, apps. Uses ElevenLabs SFX.
|
|
1447
1447
|
---
|
|
@@ -1650,7 +1650,7 @@ ${t} sfx generate -t "click" -d 0.5 -f json
|
|
|
1650
1650
|
3. **Prompt influence** - Higher (0.7-1.0) = more literal, lower (0.1-0.3) = more creative.
|
|
1651
1651
|
4. **Descriptive prompts** - Add context: "door slam, heavy wooden door" > "door slam".
|
|
1652
1652
|
5. **Format** - Use WAV for editing, MP3 for final output.
|
|
1653
|
-
`}function
|
|
1653
|
+
`}function qe(e){let{name:n,cmd:t}=e;return`---
|
|
1654
1654
|
name: ${n}-mix
|
|
1655
1655
|
description: Audio mixing for video production. Combine video with voiceover and background music. Supports volume control, fade effects, and multiple audio tracks.
|
|
1656
1656
|
---
|
|
@@ -1800,7 +1800,7 @@ ${t} mix status <request-id>
|
|
|
1800
1800
|
2. **Music selection** - Choose music that doesn't compete with voice frequency.
|
|
1801
1801
|
3. **Consistent levels** - Keep voice at 100%, adjust music only.
|
|
1802
1802
|
4. **File sizes** - Use \`--no-wait\` for large files to avoid timeout.
|
|
1803
|
-
`}function
|
|
1803
|
+
`}function Be(e){let{name:n,cmd:t}=e;return`---
|
|
1804
1804
|
name: ${n}-image
|
|
1805
1805
|
description: Stock image search and AI image generation. Find royalty-free images from multiple providers or generate custom images with AI. For videos, presentations, marketing.
|
|
1806
1806
|
---
|
|
@@ -1987,7 +1987,7 @@ Found 10 images for "mountain landscape"
|
|
|
1987
1987
|
3. **Size matters** - Use \`--size large\` for hero images
|
|
1988
1988
|
4. **JSON for automation** - Parse results programmatically
|
|
1989
1989
|
5. **Generation prompts** - Be detailed, describe style, lighting, composition
|
|
1990
|
-
`}function
|
|
1990
|
+
`}function Ge(e){let{name:n,cmd:t}=e;return`---
|
|
1991
1991
|
name: ${n}-video-search
|
|
1992
1992
|
description: Stock video search. Find royalty-free video clips from multiple providers (Pexels, Pixabay). For b-roll, backgrounds, transitions in video production.
|
|
1993
1993
|
---
|
|
@@ -2162,7 +2162,7 @@ ${t} video find "city timelapse" --orientation landscape -n 10
|
|
|
2162
2162
|
3. **Preview first** - Use preview URLs to check quality
|
|
2163
2163
|
4. **License** - Verify license for commercial use
|
|
2164
2164
|
5. **JSON export** - Save searches for batch processing
|
|
2165
|
-
`}function
|
|
2165
|
+
`}function We(e){let{name:n,cmd:t}=e;return`---
|
|
2166
2166
|
name: ${n}-scrape
|
|
2167
2167
|
description: Scrape any URL the user provides. Use when user says "check this site", "look at this URL", "use this website", "here's the link", or shares any URL for context. Supports websites, YouTube, Twitter/X.
|
|
2168
2168
|
---
|
|
@@ -2352,7 +2352,7 @@ ${t} scrape https://blog.example.com -f quiet | ${t} create "Blog Summary"
|
|
|
2352
2352
|
3. **Use JSON** - For programmatic processing of results
|
|
2353
2353
|
4. **Combine sources** - Scrape multiple URLs for comprehensive context
|
|
2354
2354
|
5. **Token count** - Check token usage for large documents
|
|
2355
|
-
`}function
|
|
2355
|
+
`}function He(e){let{name:n,cmd:t}=e;return`---
|
|
2356
2356
|
name: ${n}-branding
|
|
2357
2357
|
description: Brand profile management. Extract branding from websites, manage saved brands, apply consistent styling to presentations.
|
|
2358
2358
|
---
|
|
@@ -2462,7 +2462,7 @@ ${t} branding set-default abc123
|
|
|
2462
2462
|
2. **If extraction fails** \u2014 Proceed without branding. Do not manually create brand assets.
|
|
2463
2463
|
3. **Set default** \u2014 If you mostly work with one brand, set it as default.
|
|
2464
2464
|
4. **Override** \u2014 Use \`--brand\` flag to override default for specific presentations.
|
|
2465
|
-
`}function
|
|
2465
|
+
`}function Je(e){let{name:n,cmd:t}=e,o=n.toUpperCase().replace(/[^A-Z0-9]/g,"_");return`---
|
|
2466
2466
|
name: ${n}-config
|
|
2467
2467
|
description: CLI configuration management. Set API keys, team IDs, custom API URLs. Verify authentication status.
|
|
2468
2468
|
---
|
|
@@ -2694,7 +2694,7 @@ agent-browser screenshot --path ./screenshots/hero.png
|
|
|
2694
2694
|
**Images 403/404** - may need referrer header: \`curl -e <site-url> -O <image-url>\`
|
|
2695
2695
|
|
|
2696
2696
|
**Lazy-loaded images** - use agent-browser to scroll and capture, or inspect network tab for actual URLs.
|
|
2697
|
-
`};var
|
|
2697
|
+
`};var Ln={name:"video-ref-brief-guide",description:"How to write video brief for server-side plan generation.",render:e=>`---
|
|
2698
2698
|
name: ${e.name}-video-ref-brief-guide
|
|
2699
2699
|
description: How to write video brief for server-side plan generation.
|
|
2700
2700
|
---
|
|
@@ -2755,7 +2755,7 @@ These will be rebuilt as lightweight animated versions for Remotion. Focus on vi
|
|
|
2755
2755
|
---
|
|
2756
2756
|
|
|
2757
2757
|
**IMPORTANT:** The brief contains ONLY the 6 sections above. Do NOT add "Suggested Scenes", "Scene Breakdown", or any other sections \u2014 scene planning happens server-side via \`video generate plan\`.
|
|
2758
|
-
`};var
|
|
2758
|
+
`};var Dn={name:"video-ref-source-scraping",description:"Extract content from various sources (YouTube, websites, Twitter).",render:e=>`---
|
|
2759
2759
|
name: ${e.name}-video-ref-source-scraping
|
|
2760
2760
|
description: Extract content from various sources (YouTube, websites, Twitter).
|
|
2761
2761
|
---
|
|
@@ -2791,19 +2791,19 @@ Extracts: tweet text, author info, media URLs
|
|
|
2791
2791
|
---
|
|
2792
2792
|
|
|
2793
2793
|
All scraped content is returned in markdown format.
|
|
2794
|
-
`};import{existsSync as
|
|
2794
|
+
`};import{existsSync as ze,mkdirSync as Mt,rmSync as ei,writeFileSync as Vt}from"fs";import{homedir as jt}from"os";import{basename as ti,join as ee,relative as kc,resolve as $e}from"path";var he=[{name:"Claude Code",dir:".claude",provider:"claude"},{name:"GitHub Copilot",dir:".github",agentSuffix:".agent.md",provider:"copilot"},{name:"Cursor",dir:".cursor"},{name:"Codex",dir:".codex",agentSuffix:".toml",provider:"codex"},{name:"OpenCode",dir:".opencode"},{name:"Windsurf",dir:".windsurf"},{name:"Agent",dir:".agent"}];var Ac={sonnet:"claude-sonnet-4.6",haiku:"claude-haiku-4.5",opus:"claude-opus-4.6"},$c=["permissionMode","skills","subagentType"];function Ec(e){let n=e.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);if(!n)return`developer_instructions = """
|
|
2795
2795
|
${e.replace(/"""/g,'\\"\\"\\"').trim()}
|
|
2796
2796
|
"""
|
|
2797
2797
|
`;let t=n[1],o=n[2].trim(),r=u=>t.match(new RegExp(`^${u}:\\s*(.+)$`,"m"))?.[1]?.trim().replace(/^["']|["']$/g,""),i=r("name")??"",a=r("description")??"",s=o.replace(/"""/g,'\\"\\"\\"');return`${[`name = ${JSON.stringify(i)}`,`description = ${JSON.stringify(a)}`,`developer_instructions = """
|
|
2798
2798
|
${s}
|
|
2799
2799
|
"""`].join(`
|
|
2800
2800
|
`)}
|
|
2801
|
-
`}function
|
|
2801
|
+
`}function ni(e,n){if(n!=="copilot")return e;let t=e.match(/^---\n([\s\S]*?)\n---\n/);if(!t)return Qr(e);let o=t[1],r=e.slice((t.index??0)+t[0].length);o=o.replace(/^(model:\s*)(\S+)([ \t]*)$/m,(a,s,d,u)=>`${s}${Ac[d]??d}${u}`);for(let a of $c)o=o.replace(new RegExp(`^${a}:[^
|
|
2802
2802
|
]*
|
|
2803
|
-
?`,"m"),"");o=o.replace(/\n+$/,"");let i=
|
|
2803
|
+
?`,"m"),"");o=o.replace(/\n+$/,"");let i=Qr(r);return`---
|
|
2804
2804
|
${o}
|
|
2805
2805
|
---
|
|
2806
|
-
${i}`}function
|
|
2806
|
+
${i}`}function Kr(e,n){return n==="codex"?Ec(e):ni(e,n)}function Qr(e){return e.replace(/\bAskUserQuestion\b/g,"ask the user directly in your response").replace(/\*\*Construct the Task prompt:\*\*/g,"**Construct the Task prompt (must be fully self-contained \u2014 sub-agents cannot read this conversation's history):**").replace(/\*\*Wait for all agents to complete\*\*/g,"**Wait for all agents to complete** (monitor with `/tasks` in Copilot CLI)").replace("**Launch ALL scene agents in parallel**","**Launch ALL scene agents in parallel** \u2014 each agent must write to its own `Scene[NN][Name].tsx` file. Two agents writing to the same file will silently overwrite each other (no error). Verify unique filenames before spawning.")}function Oc(e,n){let t=$e(e),o=$e(e,n);if(kc(t,o).startsWith("..")||$e(o)!==o.replace(/\.\./g,""))throw new Error(`Invalid path: "${n}" would escape base directory`);return o}function Zr(e,n,t,o){let r=ee(e,"SKILL.md");if(Mt(e,{recursive:!0}),Vt(r,ni(n,o),"utf-8"),t&&t.length>0){let i=ee(e,"references");Mt(i,{recursive:!0});for(let a of t){let s=ee(i,`${a.name}.md`);Vt(s,a.content,"utf-8")}}}function qt(e,n,t={},o){let r={installed:[],skipped:[],errors:[]},i=t.local?process.cwd():jt();if(t.dir){let a=ti($e(t.dir)),s=he.find(d=>d.dir===a)?.provider;try{let d=$e(t.dir),u=Oc(d,ee("skills",e));Zr(u,n,o,s),r.installed.push(t.dir)}catch(d){r.errors.push(`${t.dir}: ${d instanceof Error?d.message:String(d)}`)}}else for(let a of he){let s=ee(i,a.dir),d=ee(s,"skills",e),u=ee(d,"SKILL.md");if(ze(s)){if(ze(u)&&!t.force){r.skipped.push(a.name);continue}try{Zr(d,n,o,a.provider),r.installed.push(a.name)}catch(m){r.errors.push(`${a.name}: ${m instanceof Error?m.message:String(m)}`)}}}return r}function Bt(e,n={}){let t={removed:[],errors:[]},o=n.local?process.cwd():jt();for(let r of he){let i=ee(o,r.dir,"skills",e);if(ze(i))try{ei(i,{recursive:!0}),t.removed.push(r.name)}catch(a){t.errors.push(`${r.name}: ${a instanceof Error?a.message:String(a)}`)}}return t}function oi(){return he.map(e=>e.name)}function ri(e,n,t={}){let o={installed:[],skipped:[],errors:[]};if(t.dir){let a=ti($e(t.dir)),s=he.find(b=>b.dir===a),d=s?.agentSuffix??".md",u=ee($e(t.dir),"agents"),m=ee(u,`${e}${d}`);if(ze(m)&&!t.force)o.skipped.push(t.dir);else try{Mt(u,{recursive:!0}),Vt(m,Kr(n,s?.provider),"utf-8"),o.installed.push(t.dir)}catch(b){o.errors.push(`${t.dir}: ${b instanceof Error?b.message:String(b)}`)}return o}let r=jt(),i=he.filter(a=>a.dir===".claude"||a.dir===".github"||a.dir===".codex");for(let a of i){let s=a.agentSuffix??".md",d=ee(r,a.dir,"agents"),u=ee(d,`${e}${s}`);if(ze(u)&&!t.force){o.skipped.push(a.name);continue}try{Mt(d,{recursive:!0}),Vt(u,Kr(n,a.provider),"utf-8"),o.installed.push(a.name)}catch(m){o.errors.push(`${a.name}: ${m instanceof Error?m.message:String(m)}`)}}return o}function ii(e){let n={removed:[],errors:[]},t=jt(),o=he.filter(r=>r.dir===".claude"||r.dir===".github"||r.dir===".codex");for(let r of o){let i=r.agentSuffix??".md",a=ee(t,r.dir,"agents",`${e}${i}`);if(ze(a))try{ei(a),n.removed.push(r.name)}catch(s){n.errors.push(`${r.name}: ${s instanceof Error?s.message:String(s)}`)}}return n}function Fn(){return`---
|
|
2807
2807
|
name: video-scene-reviewer
|
|
2808
2808
|
description: Strict QA reviewer for a single Remotion scene. Compares code against the video plan checking ColorGrading, transitions, icons, logos, spring physics, idle states, VO-sync, and phase structure. Returns a pass/fail checklist.
|
|
2809
2809
|
tools: Read, Glob
|
|
@@ -2900,7 +2900,7 @@ Priority fixes:
|
|
|
2900
2900
|
- Scene under 80 lines with 5+ seconds duration = flag as too simple
|
|
2901
2901
|
- Be specific in fixes: exact icon name, exact component, exact file
|
|
2902
2902
|
- 85% pass rate minimum. Below = not ready for render
|
|
2903
|
-
`}function
|
|
2903
|
+
`}function Un(){return`---
|
|
2904
2904
|
name: video-scene-builder
|
|
2905
2905
|
description: Builds a single Remotion video scene (.tsx) from a video plan section. Receives global context, scene spec, audio timing, and rhythm cues. Writes the scene file, spawns a reviewer, and iterates until 85%+ quality. One agent per scene.
|
|
2906
2906
|
tools: Read, Write, Edit, Glob, Grep, Task, Bash
|
|
@@ -3083,7 +3083,7 @@ function AnimatedCamera() {
|
|
|
3083
3083
|
- Don't download assets \u2014 the main AI already did that
|
|
3084
3084
|
- Don't run render commands \u2014 the main AI handles that
|
|
3085
3085
|
- Don't modify video-plan.md \u2014 it's read-only to you
|
|
3086
|
-
`}function
|
|
3086
|
+
`}function Mn(e){return`---
|
|
3087
3087
|
name: video-audio-director
|
|
3088
3088
|
description: Generates all audio assets (voiceover TTS, background music, sound effects) and builds the timing manifest that reconciles planned vs actual durations. One agent per video, runs before scene building.
|
|
3089
3089
|
tools: Read, Bash, Write
|
|
@@ -3354,7 +3354,7 @@ FIXES:
|
|
|
3354
3354
|
- Focus on CROSS-SCENE issues. Per-scene quality is the reviewer's job.
|
|
3355
3355
|
- Be specific in fixes: exact file, exact line, exact component.
|
|
3356
3356
|
- 85% pass rate minimum.
|
|
3357
|
-
`}function
|
|
3357
|
+
`}function jn(e){let n=e?.cmd??"mf";return`---
|
|
3358
3358
|
name: video-branding-director
|
|
3359
3359
|
description: Extracts brand identity (logos, colors, fonts) from a URL or existing profiles. Searches saved brands, extracts new ones via CLI, downloads assets locally, and writes branding.json. Returns success or failure. One agent per video, runs before brief/plan generation.
|
|
3360
3360
|
tools: Read, Bash, Write
|
|
@@ -3457,7 +3457,7 @@ Query: <what was searched/extracted>
|
|
|
3457
3457
|
- Download logos or images from websites directly (only from branding.json URLs after successful extraction)
|
|
3458
3458
|
- Create or edit branding.json by hand
|
|
3459
3459
|
- Ask the user questions \u2014 return failure to the orchestrator instead
|
|
3460
|
-
`}function
|
|
3460
|
+
`}function ai(e){return`---
|
|
3461
3461
|
name: remotion-scene-craft
|
|
3462
3462
|
description: Remotion scene coding reference for scene builder agents. DO NOT load this directly \u2014 it is preloaded into video-scene-builder agents via frontmatter. Contains plan vocabulary decoder, 4-phase architecture, VO-sync, animation recipes.
|
|
3463
3463
|
---
|
|
@@ -3732,57 +3732,57 @@ const glow = interpolate(Math.sin(frame / fps * Math.PI * 2 / 2), [-1, 1], [0.1,
|
|
|
3732
3732
|
- Static scenes with no visual change for 2+ seconds -> Every 2s needs a visual event.
|
|
3733
3733
|
- Generic component substitution -> Plan says WhipPan, use WhipPan. Not slide() or wipe().
|
|
3734
3734
|
- Unused variables or imports -> Every \`const\`, \`import\`, and \`interpolate()\` call must be used in JSX/return. Remove what you don't use. Do NOT prefix with \`_\` \u2014 delete entirely.
|
|
3735
|
-
`}var
|
|
3736
|
-
${
|
|
3737
|
-
${
|
|
3738
|
-
${
|
|
3739
|
-
${
|
|
3740
|
-
${
|
|
3741
|
-
|
|
3742
|
-
${
|
|
3743
|
-
${
|
|
3744
|
-
${
|
|
3745
|
-
${
|
|
3746
|
-
${
|
|
3747
|
-
${
|
|
3748
|
-
${
|
|
3749
|
-
${
|
|
3750
|
-
${
|
|
3751
|
-
${
|
|
3752
|
-
|
|
3753
|
-
${
|
|
3754
|
-
${
|
|
3755
|
-
$ ${
|
|
3756
|
-
|
|
3757
|
-
${
|
|
3758
|
-
$ ${
|
|
3759
|
-
|
|
3760
|
-
${
|
|
3761
|
-
$ ${
|
|
3762
|
-
|
|
3763
|
-
${
|
|
3764
|
-
$ ${
|
|
3765
|
-
|
|
3766
|
-
${
|
|
3767
|
-
$ ${
|
|
3768
|
-
|
|
3769
|
-
${
|
|
3770
|
-
$ ${
|
|
3771
|
-
`);
|
|
3772
|
-
${lt.gray(i)}`:""}`)}console.log(),console.log(lt.gray(`Use one with: ${g.commands[0]} create "<topic>" --template <id>`))}catch(t){c(t instanceof Error?t.message:String(t)),process.exit(t.exitCode??1)}});import{Command as vc}from"commander";import jn from"chalk";var ni=new vc("whoami").description("Show current user and team information").option("-f, --format <format>","Output format (human, json)","human").action(async e=>{await P();try{let n=await we();if(Sn(),e.format==="json"){console.log(JSON.stringify(n,null,2));return}fe("User"),console.log(),R("Email",n.user.email),n.user.username&&R("Username",n.user.username),(n.user.firstName||n.user.lastName)&&R("Name",[n.user.firstName,n.user.lastName].filter(Boolean).join(" "));let t=n.authType==="apiKey"?"API Key":n.authType==="oauth"?"OAuth":"Session";if(R("Auth Type",t),n.currentTeam&&(console.log(),fe("Current Team"),console.log(),R("ID",n.currentTeam.id),R("Name",n.currentTeam.name),R("Plan",n.currentTeam.planName),R("Role",n.currentTeam.isOwner?"Owner":"Member")),n.teams.length>1){console.log(),fe("All Teams"),console.log();for(let o of n.teams){let r=o.isCurrent?jn.green(" (current)"):"";console.log(` ${jn.bold(o.name)}${r}`),console.log(jn.gray(` ID: ${o.id} | Plan: ${o.planName} | Role: ${o.role}`))}}console.log()}catch(n){c(n instanceof Error?n.message:String(n)),process.exit(n.exitCode??1)}});function oi(e){return e[0]==="--"?e.slice(1):e}import{Command as qn}from"commander";function xc(e,n){return[...n,e]}var Sc=new qn("create").description("Start durable ad-set generation").argument("<title>","Ad-set title").requiredOption("--brief <brief>","Campaign brief").option("--hook <text>","Opening hook (repeat)",xc,[]).option("--style <style>","ugc, clean, cinematic, or testimonial","ugc").option("--branding-id <id>","Branding ID").option("--team-id <id>","Workspace ID").option("--yes","Approve generation").action(async(e,n)=>{if(!n.yes)return c("Pass --yes to approve generation");try{x(await $("createAdSet",{approvalReceipt:"cli:--yes",brandingId:n.brandingId,brief:n.brief,hooks:n.hook.length?n.hook:[n.brief],style:n.style,teamId:n.teamId,title:e}))}catch(t){c(t instanceof Error?t.message:"Generation failed"),process.exit(l.GENERAL_ERROR)}}),Cc=new qn("status").description("Read ad-set generation status").argument("<run-id>","Run ID").option("--team-id <id>","Workspace ID").action(async(e,n)=>{try{x(await L("createAdSet",e,n.teamId))}catch(t){c(t instanceof Error?t.message:"Status failed"),process.exit(l.GENERAL_ERROR)}}),ri=new qn("ad-set").description("Ad set commands").addCommand(Sc).addCommand(Cc);import{Command as ai}from"commander";function ii(e){return new ai(e).description(e==="create"?"Create and activate a scheduled agent":"Create a reviewable agent recommendation").argument("<name>","Agent name").requiredOption("--instructions <markdown>","Agent instructions").option("--description <text>","Agent description","").option("--schedule <frequency>","manual, daily, weekdays, weekly, or monthly","weekly").option("--time <hh:mm>","Local run time","09:00").option("--timezone <zone>","IANA timezone","UTC").option("--output <adapter>","Output adapter","digest").option("--team-id <id>","Workspace ID").option("--yes","Approve saving the agent").action(async(n,t)=>{if(!t.yes)return c("Pass --yes to approve this operation");try{x(await $(e==="create"?"createAgent":"recommendAgent",{approvalReceipt:"cli:--yes",description:t.description,instructionsMarkdown:t.instructions,name:n,output:t.output,schedule:t.schedule,scheduleTime:t.time,teamId:t.teamId,timezone:t.timezone}))}catch(o){c(o instanceof Error?o.message:"Agent operation failed"),process.exit(l.GENERAL_ERROR)}})}var si=new ai("agent").description("Scheduled agent commands").addCommand(ii("create")).addCommand(ii("recommend"));import{Command as Ht}from"commander";import Rc from"ora";import{mkdir as Ic,writeFile as ci}from"fs/promises";import{dirname as Tc}from"path";async function Q(e,n){if(await Ic(Tc(n),{recursive:!0}),e.startsWith("data:")){let r=e.match(/^data:[^;]+;base64,(.+)$/);if(!r)throw new Error("Invalid data URL format");let i=Buffer.from(r[1],"base64");if(i.length===0)throw new Error("Downloaded media was empty");await ci(n,i);return}let t=await fetch(e);if(!t.ok)throw new Error(`Failed to download media: ${t.status}`);let o=Buffer.from(await t.arrayBuffer());if(o.length===0)throw new Error("Downloaded media was empty");await ci(n,o)}var kc=15e3,Ac=40;function Bn(e,n){if(n==="json"){x(e);return}if(n==="quiet"){console.log(e.videoUrl??e.requestId);return}m(`Request ID: ${e.requestId}`),m(`Status: ${e.status}`),e.durationSec!=null&&m(`Duration: ${e.durationSec}s`),e.videoUrl&&S(`Video URL: ${e.videoUrl}`),e.error&&c(`Error: ${e.error}`)}var $c=new Ht("options").description("List available presenter avatars and voices").option("--language <language>","Filter voices by language").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{try{let n=await Jo(e.language);if(e.format==="json"){x(n);return}let t=n.personal??[];if(e.format==="quiet"){for(let o of t)console.log(o.id);for(let o of n.avatars)console.log(o.id);for(let o of n.voices)console.log(o.id);return}if(t.length>0){m("Your presenters:");for(let o of t)console.log(` ${o.id} ${o.name}`)}m("Avatars:");for(let o of n.avatars){let r=o.renderTiers?.length?` [${o.renderTiers.join(", ")}]`:"";console.log(` ${o.id} ${o.name}${r}`)}m("Voices:");for(let o of n.voices)console.log(` ${o.id} ${o.name}${o.language?` (${o.language})`:""}`)}catch(n){c(n instanceof Error?n.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),Ec=new Ht("generate").description("Generate a reusable presenter clip").option("--avatar-id <id>","Avatar id from 'avatar options'; sandbox runs use the host presenter policy").option("--audio-url <url>","Public narration audio URL for avatar lip sync").option("--voice-id <id>","Voice id from 'avatar options'").option("--script <text>","Exact words for the presenter to speak").requiredOption("-o, --output <path>","Local output path").option("--aspect <aspect>","Aspect: 1:1, 9:16, 16:9","9:16").option("--duration <seconds>","Maximum requested duration (1-300)").option("--transparent","Render a transparent-background WebM presenter clip").option("--background-color <hex>","Solid presenter background color, for example #0F172A").option("--background-image-url <url>","Public image URL used as the presenter background").option("--fit <mode>","Background image fit: contain or cover").option("--output-format <container>","Container: mp4 (default) or webm \u2014 webm renders a transparent-background clip (single scene) for compositing").option("--render-tier <tier>","Render cost/quality: basic, standard, premium","basic").option("--title <title>","Clip title","Presenter clip").option("--no-wait","Do not wait for completion").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{let n=e.transparent?"webm":e.outputFormat;!!e.audioUrl==!!e.script&&(c("Provide exactly one avatar speech input: --audio-url or --script"),process.exit(l.INVALID_INPUT)),["1:1","9:16","16:9"].includes(e.aspect)||(c("Aspect must be one of 1:1, 9:16, or 16:9"),process.exit(l.INVALID_INPUT)),e.outputFormat!==void 0&&!["mp4","webm"].includes(e.outputFormat)&&(c("Output format must be mp4 or webm"),process.exit(l.INVALID_INPUT)),e.backgroundColor!==void 0&&!/^#[0-9a-fA-F]{6}$/.test(e.backgroundColor)&&(c("Background color must be a six-digit hex value"),process.exit(l.INVALID_INPUT)),e.backgroundColor&&e.backgroundImageUrl&&(c("Provide only one presenter background"),process.exit(l.INVALID_INPUT)),e.fit!==void 0&&!["contain","cover"].includes(e.fit)&&(c("Fit must be contain or cover"),process.exit(l.INVALID_INPUT)),e.fit&&!e.backgroundImageUrl&&(c("Fit requires --background-image-url"),process.exit(l.INVALID_INPUT)),e.transparent&&e.outputFormat==="mp4"&&(c("--transparent cannot be combined with --output-format mp4"),process.exit(l.INVALID_INPUT)),n==="webm"&&(e.backgroundColor||e.backgroundImageUrl)&&(c("Transparent WebM output cannot be combined with a background"),process.exit(l.INVALID_INPUT)),["basic","standard","premium"].includes(e.renderTier)||(c("Render tier must be basic, standard, or premium"),process.exit(l.INVALID_INPUT));let t=e.duration?Number.parseInt(e.duration,10):void 0;t!==void 0&&(!Number.isFinite(t)||t<1||t>300)&&(c("Duration must be between 1 and 300 seconds"),process.exit(l.INVALID_INPUT));let o=e.format==="human"?Rc("Generating presenter clip...").start():null;try{let r=e.audioUrl?{audioUrl:e.audioUrl}:{script:e.script??"",...e.voiceId?{voiceId:e.voiceId}:{}},i=await zo({...r,aspect:e.aspect,...e.avatarId?{avatarId:e.avatarId}:{},...e.backgroundColor?{backgroundHex:e.backgroundColor}:{},...e.backgroundImageUrl?{backgroundImageUrl:e.backgroundImageUrl}:{},...t!==void 0?{durationSec:t}:{},...e.fit?{fit:e.fit}:{},...n?{outputFormat:n}:{},renderTier:e.renderTier,title:e.title});if(!e.wait){o?.stop(),Bn(i,e.format);return}let a=await K(()=>bn(i.requestId),Ac,kc);if(a.status==="failed")throw new Error(a.error||"Presenter generation failed");if(!a.videoUrl)throw new Error("Presenter generation completed without a video URL");o&&(o.text="Downloading presenter clip..."),await Q(a.videoUrl,e.output),o?.stop(),Bn(a,e.format),e.format==="human"&&S(`Saved to: ${e.output}`)}catch(r){o?.stop(),c(r instanceof Error?r.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),Oc=new Ht("status").description("Check a presenter clip generation request").argument("<id>","Request ID").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{try{Bn(await bn(e),n.format)}catch(t){c(t instanceof Error?t.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),di=new Ht("avatar").description("Avatar/presenter media commands").addCommand($c).addCommand(Ec).addCommand(Oc);import{writeFile as li}from"fs/promises";import H from"chalk";import{Command as se}from"commander";import Pc from"ora";var ui=new se("branding").description("Manage brand profiles").addCommand(new se("list").description("List brand profiles").option("-f, --format <format>","Output format (table, json)","table").action(async e=>{await P();try{let n=await gn();if(n.brandings.length===0){e.format==="json"?console.log(JSON.stringify([])):(m("No brand profiles found"),console.log(),console.log(H.gray(`Create one with: ${g.commands[0]} branding extract <url>`)));return}e.format==="json"?console.log(JSON.stringify(n.brandings,null,2)):console.log(nr(n.brandings))}catch(n){c(n instanceof Error?n.message:String(n)),process.exit(n.exitCode??1)}})).addCommand(new se("get").description("Get brand profile details").argument("<id>","Brand profile ID").option("-f, --format <format>","Output format (summary, json)","summary").option("-o, --output <path>","Save JSON to file").action(async(e,n)=>{await P();try{let t=await Lo(e);if(n.output){await li(n.output,JSON.stringify(t,null,2)),S(`Brand profile saved to ${n.output}`);return}if(n.format==="json")console.log(JSON.stringify(t,null,2));else{if(fe("Brand Profile"),console.log(),R("ID",t.id),R("Name",t.name),R("Source URL",t.sourceUrl??H.gray("None")),R("Default",t.isDefault?H.green("Yes"):"No"),t.createdAt&&R("Created",new Date(t.createdAt).toLocaleString()),console.log(),t.primaryColor||t.colors.length>0){if(console.log(H.bold(" Colors")),t.primaryColor){let r=H.bgHex(t.primaryColor)(" ");console.log(` Primary: ${r} ${t.primaryColor}`)}if(t.colors.length>0){console.log(" Palette:");for(let r of t.colors.slice(0,10)){let i=H.bgHex(r.hex)(" "),a=r.role?H.gray(` (${r.role})`):"";console.log(` ${i} ${r.hex}${a}`)}}console.log()}t.logoUrl&&(console.log(H.bold(" Logo")),console.log(` ${t.logoUrl}`),console.log());let o=t.typography;o&&Object.keys(o).length>0&&(console.log(H.bold(" Typography")),(o.primary||o.headings)&&console.log(` Headings: ${o.primary||o.headings||"-"}`),(o.secondary||o.body)&&console.log(` Body: ${o.secondary||o.body||"-"}`),console.log()),(t.confidence||t.extractionMethod)&&(console.log(H.bold(" Extraction")),t.confidence&&console.log(` Confidence: ${Math.round(t.confidence*100)}%`),t.extractionMethod&&console.log(` Method: ${t.extractionMethod}`),console.log()),console.log(H.gray(" Use --format json for full details")),console.log()}}catch(t){c(t instanceof Error?t.message:String(t)),process.exit(t.exitCode??1)}})).addCommand(new se("find").description("Find existing brand profile by name or URL").argument("<query>","Brand name or website URL to search for").action(async e=>{await P();try{let n=await gn(),t=e.toLowerCase().replace(/^https?:\/\//,"").replace(/\/$/,""),o=n.brandings.filter(r=>{let i=(r.name||"").toLowerCase(),a=(r.sourceUrl||"").toLowerCase().replace(/^https?:\/\//,"").replace(/\/$/,"");return i.includes(t)||a.includes(t)||i.length>0&&t.includes(i)||a.length>0&&t.includes(a)});if(o.length===0){m(`No brand profiles matching "${e}"`),console.log(H.gray(` Extract one with: ${g.commands[0]} branding extract <url>`));return}console.log(`Found ${o.length} brand${o.length>1?"s":""}:
|
|
3773
|
-
`);for(let r of o){let i=r.primaryColor?`${H.bgHex(r.primaryColor)(" ")} ${r.primaryColor}`:"";console.log(` ${H.bold(r.name)} ${H.gray(r.id)}`),r.sourceUrl&&console.log(` ${H.gray(r.sourceUrl)}`),i&&console.log(` ${i}`),console.log()}console.log(H.gray(` Export with: ${g.commands[0]} branding get <id> -o branding.json`))}catch(n){c(n instanceof Error?n.message:String(n)),process.exit(n.exitCode??1)}})).addCommand(new se("extract").description("Extract brand profile from a website").argument("<url>","Website URL to extract branding from").option("--team-id <id>","Team ID").option("--yes","Confirm starting a paid/external extraction").option("--no-save","Extract without saving").option("-o, --output <path>","Save JSON to file").action(async(e,n)=>{await P(),n.yes||(c("Pass --yes to confirm brand extraction."),process.exit(l.INVALID_INPUT));try{new URL(e.startsWith("http")?e:`https://${e}`)}catch{c("Invalid URL format"),process.exit(6)}let t=e.startsWith("http")?e:`https://${e}`,o=n.teamId??ht(),r=Pc({text:`Extracting branding from ${t}...`,stream:process.stdout}).start();try{let i=await Uo(t,o,"cli:--yes");r.succeed("Brand extraction started");let a=JSON.stringify(i,null,2);n.output?(await li(n.output,a),S(`Brand profile saved to ${n.output}`)):console.log(a),m(`Check progress with: ${g.commands[0]} branding status ${i.runId}`),console.log()}catch(i){r.fail("Extraction failed"),c(i instanceof Error?i.message:String(i)),process.exit(i.exitCode??1)}})).addCommand(new se("status").description("Check a brand extraction run").argument("<run-id>","Run ID returned by branding extract").option("--team-id <id>","Workspace ID").action(async(e,n)=>{try{x(await L("extractBranding",e,n.teamId))}catch(t){c(t instanceof Error?t.message:"Status failed"),process.exit(l.GENERAL_ERROR)}})).addCommand(new se("set-default").description("Set a brand profile as default").argument("<id>","Brand profile ID").action(async e=>{await P(),m(`To set brand ${e} as default, use the web dashboard.`),console.log(),console.log(H.gray("API support for setting default brand is coming soon."))})).addCommand(new se("competitor").description("Brand competitor commands").addCommand(new se("list").description("List competitors for a brand").option("--branding-id <id>","Brand ID").option("--team-id <id>","Workspace ID").action(async e=>{try{console.log(JSON.stringify(await $("getBrandCompetitors",{brandingId:e.brandingId,teamId:e.teamId}),null,2))}catch(n){c(n instanceof Error?n.message:"Lookup failed"),process.exit(1)}})).addCommand(new se("add").description("Add or update a brand competitor").argument("<name>","Competitor name").option("--branding-id <id>","Brand ID").option("--team-id <id>","Workspace ID").option("--website <url>","Competitor website").option("--x-handle <handle>","Competitor X handle").option("--yes","Confirm writing brand data").action(async(e,n)=>{n.yes||(c("Pass --yes to confirm adding a competitor."),process.exit(l.INVALID_INPUT));try{x(await $("addCompetitor",{approvalReceipt:"cli:--yes",brandingId:n.brandingId,name:e,teamId:n.teamId,website:n.website,xHandle:n.xHandle}))}catch(t){c(t instanceof Error?t.message:"Write failed"),process.exit(l.GENERAL_ERROR)}}))).addCommand(new se("social").description("Brand social handle commands").addCommand(new se("add").description("Add or update a brand social handle").argument("<platform>","Social platform").argument("<handle>","Account handle").option("--branding-id <id>","Brand ID").option("--team-id <id>","Workspace ID").option("--yes","Confirm writing brand data").action(async(e,n,t)=>{t.yes||(c("Pass --yes to confirm adding a social handle."),process.exit(l.INVALID_INPUT));try{x(await $("addBrandSocialHandle",{approvalReceipt:"cli:--yes",brandingId:t.brandingId,handle:n,platform:e,teamId:t.teamId}))}catch(o){c(o instanceof Error?o.message:"Write failed"),process.exit(l.GENERAL_ERROR)}})));import{readFile as Nc}from"fs/promises";import{Command as mi}from"commander";var Dc=new mi("extract").description("Extract normalized text from a URL or local file").argument("<source>","URL, encoded source, or local file path").option("--team-id <id>","Workspace ID").option("--mime-type <type>","Source MIME type").option("--max-length <count>","Maximum output characters","30000").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{try{let t=e,o;e.includes("://")||(t=await Nc(e,"utf8"),o=e);let r=await $("extractContent",{filename:o,maxLength:Number.parseInt(n.maxLength,10),mimeType:n.mimeType,source:t,teamId:n.teamId});n.format!=="quiet"&&x(r)}catch(t){c(t instanceof Error?t.message:"Extraction failed"),process.exit(l.GENERAL_ERROR)}}),pi=new mi("content").description("Content extraction commands").addCommand(Dc);import Y from"chalk";import{Command as Lc}from"commander";import{existsSync as Uc,readFileSync as Fc}from"fs";import _c,{resolve as gi}from"path";var fi=new Lc("create").description("Create a new presentation").argument("<topic>","The topic or title for the presentation").option("-n, --slides <count>","Number of slides (1-20)").option("-m, --mode <mode>","Generation quality (best, balanced, fast, ultrafast, instant, image-min, image, image-max) \u2014 default: fast. image-min/image/image-max render each slide as a full-bleed AI image (text not editable); slower + pricier, require image-mode access, and cap at 25 slides. image-min is cheapest (brand colors only, no exact fonts).").option("--image-tier <tier>","Embedded-image quality for HTML modes: smart (default, auto-routes per image), fast (cheapest, no extra credits), balanced (+50 credits/slide), best (premium, +200 credits/slide, slow). Ignored for image-*/instant modes.").option("-t, --tone <tone>","Tone (creative, professional, educational, formal, casual)").option("--amount <amount>","Content density (minimal, concise, detailed, extensive)").option("--audience <text>","Target audience description").option("-l, --language <lang>","Output language").option("--branding-id <id>","Branding ID (from `ccr branding list` or `ccr branding extract`)").option("--brand-domain <url>","Brand the deck by website/domain (e.g. https://www.pfizer.com). Errors if no matching saved brand exists.").option("--template <id>","Slide template ID to style the deck after (from `ccr templates`). A default template is applied automatically when omitted.").option("-c, --context <text>","Inline text context (research notes, key facts)").option("--context-file <path>","Path to a context file (text, markdown, JSON)").option("--stdin","Read context from stdin").option("-f, --file <paths...>","Files to upload (PDF, PPTX, DOCX, images)").option("-g, --goal <type>","Goal (inform, persuade, train, learn, entertain, report)").option("--styling <mode>","Styling mode (freeform, brand-only, brand-plus-style, style-only, no-styling)").option("--reference-url <url>","Image URL to use as visual style reference").option("--thinking-depth <depth>","AI thinking depth (quick, moderate, deep, profound)").option("--theme <preset>","[instant mode only] Color theme preset (blue, violet, rose, orange, green)").option("--primary-color <hex>","[instant mode only] Primary color (e.g., #0066CC)").option("--secondary-color <hex>","[instant mode only] Secondary color").option("--accent-color <hex>","[instant mode only] Accent color").option("--background-color <hex>","[instant mode only] Background color").option("--foreground-color <hex>","[instant mode only] Foreground/text color").option("--decorations <style>","[instant mode only] Background decoration (none, waves-bottom-left, waves-top-right, blob-corners, minimal)").option("--team-id <id>","Team ID (switch teams)").option("-o, --output <format>","Output format (human, json, quiet)").option("--no-stream","Wait for completion without streaming progress").option("--wait","Poll until generation completes").option("--debug","Enable debug logging").option("--open","Open in browser after creation").option("--id <uuid>","Use a specific UUID for the presentation").option("--studio","Studio mode: use current directory name as presentation ID (auto-links to Studio preview)").action(async(e,n)=>{await P();let t;n.slides!==void 0&&(t=parseInt(n.slides,10),(Number.isNaN(t)||t<1||t>20)&&(c("Slide count must be between 1 and 20"),process.exit(6)));let o=["best","balanced","fast","ultrafast","instant","image-min","image","image-max"];n.mode&&!o.includes(n.mode)&&(c(`Invalid mode: ${n.mode}. Valid: ${o.join(", ")}`),process.exit(6));let r=["smart","fast","balanced","best"];n.imageTier&&!r.includes(n.imageTier)&&(c(`Invalid image tier: ${n.imageTier}. Valid: ${r.join(", ")}`),process.exit(6));let i=["creative","professional","educational","formal","casual"];n.tone&&!i.includes(n.tone)&&(c(`Invalid tone: ${n.tone}. Valid: ${i.join(", ")}`),process.exit(6));let a=["minimal","concise","detailed","extensive"];n.amount&&!a.includes(n.amount)&&(c(`Invalid amount: ${n.amount}. Valid: ${a.join(", ")}`),process.exit(6));let s=["freeform","brand-only","brand-plus-style","style-only","no-styling"];n.styling&&!s.includes(n.styling)&&(c(`Invalid styling: ${n.styling}. Valid: ${s.join(", ")}`),process.exit(6));let d=["quick","moderate","deep","profound"];n.thinkingDepth&&!d.includes(n.thinkingDepth)&&(c(`Invalid thinking-depth: ${n.thinkingDepth}. Valid: ${d.join(", ")}`),process.exit(6));let u=["inform","persuade","train","learn","entertain","report"];n.goal&&!u.includes(n.goal)&&(c(`Invalid goal: ${n.goal}. Valid: ${u.join(", ")}`),process.exit(6));let p=["blue","violet","rose","orange","green"];n.theme&&!p.includes(n.theme)&&(c(`Invalid theme: ${n.theme}. Valid: ${p.join(", ")}`),process.exit(6));let w=["none","waves-bottom-left","waves-top-right","blob-corners","minimal"];n.decorations&&!w.includes(n.decorations)&&(c(`Invalid decorations: ${n.decorations}. Valid: ${w.join(", ")}`),process.exit(6));let I=n.theme||n.primaryColor||n.secondaryColor||n.accentColor||n.backgroundColor||n.foregroundColor||n.decorations;I&&n.mode&&n.mode!=="instant"&&(c("--theme, --primary-color, --decorations and other color options are only supported with --mode instant"),process.exit(6));let f=n.mode??(I?"instant":"fast"),T=/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;for(let[C,M]of[["primary-color",n.primaryColor],["secondary-color",n.secondaryColor],["accent-color",n.accentColor],["background-color",n.backgroundColor],["foreground-color",n.foregroundColor]])M&&!T.test(M)&&(c(`Invalid ${C}: ${M}. Must be hex (e.g., #0066CC)`),process.exit(6));try{n.output!=="json"&&n.output!=="quiet"&&process.stdout.write(Y.gray("Checking generation limits... "));let C=await Vo(f,t??10,n.teamId);if(n.output!=="json"&&n.output!=="quiet"){console.log(Y.green("\u2713"));let M=C.remaining[f],q=C.limits[f],ne=M===void 0||q===void 0?"":` | ${f}: ${M}/${q} remaining`;console.log(Y.gray(` Plan: ${C.planName}${ne}`))}}catch(C){n.output==="json"?console.log(JSON.stringify({success:!1,error:C instanceof Error?C.message:String(C)})):(console.log(Y.red("\u2717")),c(C instanceof Error?C.message:String(C))),process.exit(C.exitCode??1)}let b=[];if(n.file&&n.file.length>0){for(let C of n.file)Uc(gi(C))||(c(`File not found: ${C}`),process.exit(6));n.output!=="json"&&n.output!=="quiet"&&console.log(Y.gray(`
|
|
3774
|
-
Uploading ${n.file.length} file(s)...`));try{b=await Ao(n.file.map(C=>gi(C)),(C,M,q)=>{n.output!=="json"&&n.output!=="quiet"&&q&&process.stdout.write(`\r ${Y.cyan("\u2B06")} Uploading: ${q} (${C+1}/${M})`)}),n.output!=="json"&&n.output!=="quiet"&&console.log(`\r ${Y.green("\u2713")} Uploaded ${b.length} file(s) `)}catch(C){c(`Failed to upload files: ${C instanceof Error?C.message:String(C)}`),process.exit(1)}}let y;(n.stdin||!process.stdin.isTTY)&&(y=await Vc(),n.stdin&&!y&&(c("No content received from stdin"),process.exit(6)));let v=n.context;if(n.contextFile)try{v=Fc(n.contextFile,"utf-8"),v.trim()||(c(`Context file is empty: ${n.contextFile}`),process.exit(6))}catch{c(`Failed to read context file: ${n.contextFile}`),process.exit(6)}!y&&!v&&b.length===0&&(c("Context is required to create a presentation."),console.log(),console.log(Y.gray(" -f, --file <paths...> Upload files (PDF, PPTX, images)")),console.log(Y.gray(" -c, --context <text> Inline text context")),console.log(Y.gray(" --context-file <path> Read from a file")),console.log(Y.gray(` cat file | ${g.commands[0]} Pipe content`)),process.exit(6));let E=[...b];y&&E.push({id:`stdin-${Date.now()}`,content:y,title:"Piped Content",mime:"text/plain",selected:!0}),v&&E.push({id:`context-${Date.now()}`,content:v,title:"Context",mime:"text/plain",selected:!0});let A,N=n.primaryColor||n.secondaryColor||n.accentColor||n.backgroundColor||n.foregroundColor;(n.theme||N||n.decorations)&&(A={},n.theme&&(A.preset=n.theme),N&&(A.custom={},n.primaryColor&&(A.custom.primary=n.primaryColor),n.secondaryColor&&(A.custom.secondary=n.secondaryColor),n.accentColor&&(A.custom.accent=n.accentColor),n.backgroundColor&&(A.custom.background=n.backgroundColor),n.foregroundColor&&(A.custom.foreground=n.foregroundColor)),n.decorations&&(A.decorations=n.decorations));try{let C=await $o({topic:e,...t!==void 0&&{slideCount:t},mode:f,...n.imageTier&&{imageTier:n.imageTier},...n.tone&&{tone:n.tone},...n.amount&&{amount:n.amount},...n.audience&&{audience:n.audience},...n.language&&{language:n.language},...n.brandingId&&{brandingId:n.brandingId},...n.brandDomain&&{brandDomain:n.brandDomain},...n.template&&{templateId:n.template},...n.styling&&{stylingMode:n.styling},...n.referenceUrl&&{referenceUrl:n.referenceUrl},...n.thinkingDepth&&{thinkingDepth:n.thinkingDepth},...n.goal&&{goal:n.goal},...n.teamId&&{teamId:n.teamId},...A&&{theme:A},...n.studio?{documentId:_c.basename(process.cwd())}:n.id?{documentId:n.id}:{},...E.length>0&&{contentSources:{uploadedFiles:E,contextFiles:[]}}});if(!n.wait){n.output==="json"?console.log(JSON.stringify({success:!0,run:C},null,2)):n.output!=="quiet"&&(S("Presentation generation queued"),R("Run ID",C.runId),R("Status",C.status),console.log(Y.gray(` Check later with presentation status ${C.runId}`)));return}let M=await L("createSlides",C.runId,n.teamId);for(;!M.done;)n.output!=="json"&&n.output!=="quiet"&&console.log(Y.gray(` ${M.message}`)),await new Promise(ne=>setTimeout(ne,(M.nextPollAfterSeconds??5)*1e3)),M=await L("createSlides",C.runId,n.teamId);if(M.error)throw new Error(M.error.message);let q=M.entity?await Se(M.entity.id):void 0;if(n.output==="json")console.log(JSON.stringify({success:!0,presentation:q,run:M,viewUrl:q?De(q.slug,n.language??"en"):void 0},null,2));else{console.log(),S("Presentation created successfully"),console.log(),R("Title",q?.title??e),R("Slides",String(q?.numberOfSlides??t??"\u2014")),console.log();let ne=q?De(q.slug,n.language??"en"):"N/A";ne!=="N/A"&&(console.log(Y.bold(" Open: ")+Y.cyan.underline(ne)),n.open&&await(await import("open")).default(ne)),console.log()}}catch(C){n.output==="json"?console.log(JSON.stringify({success:!1,error:C instanceof Error?C.message:String(C)})):c(C instanceof Error?C.message:String(C)),process.exit(C.exitCode??1)}});async function Vc(){return new Promise(e=>{let n="";if(process.stdin.setEncoding("utf8"),process.stdin.isTTY){e("");return}process.stdin.on("data",t=>{n+=t}),process.stdin.on("end",()=>{e(n.trim())}),setTimeout(()=>{e(n.trim())},100)})}import{Command as Mc}from"commander";import Jt from"chalk";var hi=new Mc("get").description("Get presentation details").argument("<slug>","Presentation slug (e.g., my-presentation-v1-abc123)").option("-f, --format <format>","Output format (summary, full, json)","summary").option("--include <fields>","Fields to include (comma-separated: slides,styling)").option("-l, --language <lang>","Language for view URL","en").action(async(e,n)=>{await P();try{let t=await Se(e);if(n.format==="json"){console.log(JSON.stringify(t,null,2));return}let o=De(t.slug,n.language);fe("Presentation Details"),console.log(),R("Slug",t.slug),R("Title",t.title||"Untitled"),R("Description",t.description||Jt.gray("None")),R("Slides",String(t.numberOfSlides||"-")),R("Mode",t.mode||"-"),R("Created",xn(t.createdAt)),t.updatedAt&&R("Updated",xn(t.updatedAt)),console.log(),o!=="N/A"&&console.log(Jt.bold(" Open: ")+Jt.cyan.underline(o)),console.log(),n.format==="full"&&n.include?.includes("slides")&&(console.log(Jt.gray("(Full slide content available in JSON format)")),console.log())}catch(t){c(t instanceof Error?t.message:String(t)),process.exit(t.exitCode??1)}});import{Command as Xt}from"commander";import jc from"ora";function le(e,n){let t=e instanceof Error?e.message:"Unknown error";return!n||t.includes(n)?t:`${t} Request ID: ${n}. Resume with the matching status command; do not start a duplicate run.`}function qc(e){let n=e.assetType??"image";if(n!=="image"&&n!=="icon")throw new Error("Asset type must be image or icon");let t;if(e.maxResults&&(t=Number.parseInt(e.maxResults,10),Number.isNaN(t)||t<1))throw new Error("Max results must be a positive number");return{query:n==="icon"?`${e.query.trim()} transparent icon isolated symbol`:e.query.trim(),options:{maxResults:t||10,size:e.size,safeSearch:e.safeSearch,assetType:n,transparentBackground:n==="icon"}}}function Bc(e){let n=e.url||e.imageUrl;if(!n)throw new Error("Image search returned a result without a URL");return n}function Gc(e){return e.transparent??e.isTransparent??e.metadata?.transparent??e.metadata?.isTransparent}function Wc(e,n){return e.data.results.flatMap(t=>t.results.map(o=>{let r=o,i=Gc(r);if(n==="icon"&&i!==!0)throw new Error("Icon search returned a result without a verified transparent background");return{...r,url:Bc(r),provider:t.providerName,assetType:n,...i!==void 0?{transparent:i}:{}}}))}function Hc(e){return e.error||e.status==="failed"||e.status==="errored"||e.status==="cancelled"?"failed":e.done||e.status==="completed"?"completed":e.status==="in_progress"?"processing":"pending"}function zt(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function Jc(e){return{requestId:e.runId,status:Hc(e),...e.entity?.url?{url:e.entity.url}:{},...e.error?.message?{error:e.error.message}:{},...zt(e.output?.width)!==void 0?{width:zt(e.output?.width)}:{},...zt(e.output?.height)!==void 0?{height:zt(e.output?.height)}:{}}}async function yi(e,n){return Jc(await L("createImage",e,n))}function Gn(e,n){if(n==="json"){x(e);return}if(n==="quiet"){console.log(e.output??e.url??e.requestId);return}m(`Request ID: ${e.requestId}`),m(`Status: ${e.status}`),e.url&&S(`Image URL: ${e.url}`),e.output&&S(`Saved to: ${e.output}`),e.error&&c(`Error: ${e.error}`)}var zc=new Xt("search").description("Search for images").requiredOption("-q, --query <query>","Search query").option("-n, --max-results <number>","Maximum number of results (default: 10)").option("-s, --size <size>","Image size: small, medium, large, any","large").option("--asset-type <type>","Asset intent: image or transparent icon","image").option("--safe-search","Enable safe search (default: true)",!0).option("--no-safe-search","Disable safe search").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{let n=e.format,t=n==="human"?jc("Searching for images...").start():null,o;try{o=qc(e)}catch(r){t?.stop(),c(r instanceof Error?r.message:"Invalid image search request"),process.exit(l.INVALID_INPUT);return}try{let r=await Rt(o);t?.stop(),r.success||(c("Search failed"),process.exit(l.GENERAL_ERROR));let i=o.options?.assetType??"image",a=Wc(r,i);if(n==="json"){x({success:!0,query:e.query,assetType:i,totalResults:a.length,images:a});return}if(n==="quiet"){for(let s of a)console.log(s.url);return}if(a.length===0){m("No images found");return}S(`Found ${a.length} images for "${e.query}"`),console.log();for(let s=0;s<a.length;s++){let d=a[s];console.log(`[${s+1}] ${d.title||"Untitled"}`),console.log(` URL: ${d.url}`),console.log(` Size: ${d.width}x${d.height}`),d.author&&console.log(` Author: ${d.author}`),console.log(` Provider: ${d.provider}`),console.log()}m(`Total cost: $${r.data.totalCost.toFixed(4)}`)}catch(r){t?.stop(),c(r instanceof Error?r.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),Xc=new Xt("generate").description("Generate an image and optionally save it locally").argument("[prompt]","Image prompt").option("-p, --prompt <text>","Image prompt (named compatibility form)").option("--provider <provider>","Provider override").option("--model <model>","Model override").option("--width <pixels>","Width").option("--height <pixels>","Height").option("--team-id <id>","Workspace ID").option("-o, --output <path>","Local output path").option("--no-wait","Do not wait for completion").option("-f, --format <format>","Output format: human, json, quiet","human").option("--yes","Approve generation").action(async(e,n)=>{let t,o=e??n.prompt;o?.trim()||(c("Provide an image prompt as an argument or with --prompt"),process.exit(l.INVALID_INPUT)),n.yes||(c("Pass --yes to approve image generation"),process.exit(l.INVALID_INPUT)),!n.wait&&n.output&&(c("--output requires waiting for completion; remove --no-wait"),process.exit(l.INVALID_INPUT));try{let r=await $("createImage",{approvalReceipt:"cli:--yes",height:n.height?Number.parseInt(n.height,10):void 0,model:n.model,prompt:o.trim(),provider:n.provider,teamId:n.teamId,width:n.width?Number.parseInt(n.width,10):void 0});if(t=r.runId,!n.wait){Gn({requestId:r.runId,status:"pending"},n.format);return}let i=await K(()=>yi(r.runId,n.teamId),180,2e3);if(i.status==="failed")throw new Error(i.error||"Image generation failed");if(!i.url)throw new Error("Image generation completed without an image URL");let a=n.output?{...i,output:n.output}:i;n.output&&await Q(i.url,n.output),Gn(a,n.format)}catch(r){c(le(r,t),n.format),process.exit(l.GENERAL_ERROR)}}),Yc=new Xt("status").description("Read image generation status").argument("<run-id>","Run ID").option("--team-id <id>","Workspace ID").option("-o, --output <path>","Download a completed image").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{try{let t=await yi(e,n.teamId);if(n.output){if(t.status!=="completed"||!t.url)throw new Error("Image generation is not complete");await Q(t.url,n.output),t.output=n.output}Gn(t,n.format)}catch(t){c(t instanceof Error?t.message:"Status failed"),process.exit(l.GENERAL_ERROR)}}),bi=new Xt("image").description("Image search and generation commands").addCommand(zc).addCommand(Xc).addCommand(Yc);import{Command as Wn}from"commander";var Kc=new Wn("search").description("Search the workspace Knowledge Hub").argument("[query]","Optional search query").option("--team-id <id>","Workspace ID").option("--kind <kind>","Knowledge kind").option("--limit <count>","Maximum results","10").action(async(e,n)=>{try{x(await $("searchKnowledge",{kind:n.kind,limit:Number.parseInt(n.limit,10),query:e,teamId:n.teamId}))}catch(t){c(t instanceof Error?t.message:"Knowledge search failed"),process.exit(l.GENERAL_ERROR)}}),Qc=new Wn("bundle").description("Read a bounded Open Knowledge Format bundle").option("--team-id <id>","Workspace ID").option("--kind <kind>","Knowledge kind").action(async e=>{try{x(await $("getKnowledgeBundle",{kind:e.kind,teamId:e.teamId}))}catch(n){c(n instanceof Error?n.message:"Knowledge bundle failed"),process.exit(l.GENERAL_ERROR)}}),wi=new Wn("knowledge").description("Knowledge Hub commands").addCommand(Kc).addCommand(Qc);import{Command as Hn}from"commander";var Zc=new Hn("create").description("Start background microsite generation").argument("<title>","Microsite title").requiredOption("--description <brief>","Microsite brief").option("--audience <audience>","Target audience").option("--tone <tone>","Tone").option("--language <language>","Content language","en").option("--branding-id <id>","Branding ID").option("--team-id <id>","Workspace ID").option("--yes","Approve generation").action(async(e,n)=>{if(!n.yes)return c("Pass --yes to approve generation");try{x(await $("createMicrosite",{approvalReceipt:"cli:--yes",audience:n.audience,brandingId:n.brandingId,description:n.description,language:n.language,teamId:n.teamId,title:e,tone:n.tone}))}catch(t){c(t instanceof Error?t.message:"Generation failed"),process.exit(l.GENERAL_ERROR)}}),ed=new Hn("status").description("Read microsite generation status").argument("<run-id>","Run ID").option("--team-id <id>","Workspace ID").action(async(e,n)=>{try{x(await L("createMicrosite",e,n.teamId))}catch(t){c(t instanceof Error?t.message:"Status failed"),process.exit(l.GENERAL_ERROR)}}),vi=new Hn("microsite").description("Microsite commands").addCommand(Zc).addCommand(ed);import{Command as Xn}from"commander";import Jn from"ora";function zn(e,n){if(n==="json"){let{cost:t,...o}=e;x(o);return}if(n==="quiet"){e.outputUrl?console.log(e.outputUrl):console.log(e.requestId);return}m(`Request ID: ${e.requestId}`),m(`Status: ${e.status}`),e.duration&&m(`Duration: ${e.duration}s`),e.outputUrl&&S(`Output URL: ${e.outputUrl}`),e.cost!==void 0&&m(`Cost: $${e.cost.toFixed(4)}`),e.error&&c(`Error: ${e.error}`)}var td=new Xn("create").description("Mix audio tracks into a video (music will loop to match video duration)").requiredOption("--video <url>","Input video file/URL").option("--music <url>","Background music file/URL (will loop if shorter than video)").option("--voice <url>","Voiceover file/URL").option("--music-volume <percent>","Music volume 0-100 (default: 30, recommended for mix with voice)","30").option("--voice-volume <percent>","Voice volume 0-100","100").option("-o, --output <path>","Output file path").option("--no-wait","Do not wait for completion").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{!e.music&&!e.voice&&(c("At least one of --music or --voice must be provided"),process.exit(l.INVALID_INPUT));let n=parseInt(e.musicVolume,10)/100,t=parseInt(e.voiceVolume,10)/100;(Number.isNaN(n)||n<0||n>1)&&(c("Music volume must be between 0 and 100"),process.exit(l.INVALID_INPUT)),(Number.isNaN(t)||t<0||t>2)&&(c("Voice volume must be between 0 and 200"),process.exit(l.INVALID_INPUT));let o=e.format,r=o==="human"?Jn("Mixing audio...").start():null,i=[{url:e.video,role:"video"}];e.music&&i.push({url:e.music,role:"background",volume:n*5}),e.voice&&i.push({url:e.voice,role:"voice",volume:t*2});try{let a=await Bo({operation:"add-to-video",inputs:i,options:{musicVolume:n,voiceVolume:t}});if(!e.wait){r?.stop(),zn(a,o);return}r&&(r.text=`Processing (ID: ${a.requestId})...`);let s=await K(()=>fn(a.requestId),120,3e3);if(r?.stop(),s.status==="failed"&&(c(s.error||"Audio mixing failed"),process.exit(l.GENERAL_ERROR)),zn(s,o),e.output){if(!s.outputUrl)throw new Error("Audio mix completed without an output URL");let d=o==="human"?Jn("Downloading...").start():null;await Q(s.outputUrl,e.output),d?.stop(),o==="human"&&S(`Saved to: ${e.output}`)}}catch(a){r?.stop(),c(a instanceof Error?a.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),nd=new Xn("status").description("Check status of an audio mix request").argument("<id>","Request ID").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{let t=n.format==="human"?Jn("Checking status...").start():null;try{let o=await fn(e);t?.stop(),zn(o,n.format)}catch(o){t?.stop(),c(o instanceof Error?o.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),xi=new Xn("mix").description("Audio mixing commands").addCommand(td).addCommand(nd);import{Command as Qn}from"commander";import Yn from"ora";function Kn(e,n){if(n==="json"){let{cost:t,...o}=e;x(o);return}if(n==="quiet"){e.audioUrl?console.log(e.audioUrl):console.log(e.requestId);return}m(`Request ID: ${e.requestId}`),m(`Status: ${e.status}`),e.duration&&m(`Duration: ${e.duration}s`),e.audioUrl&&S(`Audio URL: ${e.audioUrl}`),e.cost!==void 0&&m(`Cost: $${e.cost.toFixed(4)}`),e.error&&c(`Error: ${e.error}`)}var od=new Qn("generate").description("Generate music from a text prompt").requiredOption("-p, --prompt <text>","Music description").option("-d, --duration <seconds>","Duration in seconds (3-600)","30").option("-s, --style <style>","Style preset").option("--provider <provider>","Untrusted provider hint (host policy is authoritative)").option("--mode <mode>","Intent: auto, retrieve, or generate","auto").option("--no-instrumental","Allow vocals (background music is instrumental by default)").option("--tempo <bpm>","Tempo hint in BPM (60-180)").option("--audio-format <format>","Audio format: mp3, wav, flac, ogg","mp3").option("-o, --output <path>","Output file path").option("--no-wait","Do not wait for completion").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{let n=Number(e.duration);(!Number.isInteger(n)||n<3||n>600)&&(c("Duration must be between 3 and 600 seconds (10 minutes)"),process.exit(l.INVALID_INPUT)),!e.wait&&e.output&&(c("--output requires waiting for completion; remove --no-wait"),process.exit(l.INVALID_INPUT)),["auto","retrieve","generate"].includes(e.mode)||(c("Mode must be auto, retrieve, or generate"),process.exit(l.INVALID_INPUT)),["mp3","wav","flac","ogg"].includes(e.audioFormat)||(c("Audio format must be mp3, wav, flac, or ogg"),process.exit(l.INVALID_INPUT));let t=e.tempo?Number(e.tempo):void 0;t!==void 0&&(!Number.isInteger(t)||t<60||t>180)&&(c("Tempo must be between 60 and 180 BPM"),process.exit(l.INVALID_INPUT));let o=e.format,r=o==="human"?Yn("Generating music...").start():null,i;try{let a=await Tt({prompt:e.prompt,duration:n,options:{provider:e.provider,mode:e.mode,instrumental:e.instrumental,style:e.style,tempo:t,format:e.audioFormat}});if(i=a.requestId,!e.wait){r?.stop(),Kn(a,o);return}let s=a;if(a.status!=="completed"&&a.status!=="failed"&&(r&&(r.text=`Processing (ID: ${a.requestId})...`),s=await K(()=>st(a.requestId),180,2e3)),r?.stop(),s.status==="failed"&&(c(s.error||"Music generation failed"),process.exit(l.GENERAL_ERROR)),e.output){if(!s.audioUrl)throw new Error("Music completed without an audio URL");let d=o==="human"?Yn("Downloading...").start():null;await Q(s.audioUrl,e.output),d?.stop(),o==="human"&&S(`Saved to: ${e.output}`),s={...s,output:e.output}}Kn(s,o)}catch(a){r?.stop(),c(le(a,i),o),process.exit(l.GENERAL_ERROR)}}),rd=new Qn("status").description("Check status of a music generation request").argument("<id>","Request ID").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{let t=n.format==="human"?Yn("Checking status...").start():null;try{let o=await st(e);t?.stop(),Kn(o,n.format)}catch(o){t?.stop(),c(o instanceof Error?o.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),Si=new Qn("music").description("Music generation commands").addCommand(od).addCommand(rd);import{Command as Zn}from"commander";function Ci(e,n){return[...n,e]}var id=new Zn("create").description("Create a standalone poll").argument("<question>","Poll question").option("--option <text>","Choice (repeat 2-10 times)",Ci,[]).option("--type <type>","single, multiple, or word-cloud","single").option("--title <title>","Poll title").option("--team-id <id>","Workspace ID").option("--yes","Approve creation").action(async(e,n)=>{if(!n.yes)return c("Pass --yes to approve poll creation");try{x(await $("createPoll",{approvalReceipt:"cli:--yes",options:n.option.map(t=>({text:t})),pollType:n.type,question:e,teamId:n.teamId,title:n.title}))}catch(t){c(t instanceof Error?t.message:"Poll creation failed"),process.exit(l.GENERAL_ERROR)}}),ad=new Zn("edit").description("Edit a standalone poll").argument("<poll-id>","Poll UUID").option("--question <question>","New question").option("--option <text>","Replacement choice (repeat)",Ci).option("--type <type>","single, multiple, or word-cloud").option("--title <title>","Poll title").option("--team-id <id>","Workspace ID").option("--yes","Approve update").action(async(e,n)=>{if(!n.yes)return c("Pass --yes to approve poll update");try{x(await $("editPoll",{approvalReceipt:"cli:--yes",options:n.option?.map(t=>({text:t})),pollId:e,pollType:n.type,question:n.question,teamId:n.teamId,title:n.title}))}catch(t){c(t instanceof Error?t.message:"Poll update failed"),process.exit(l.GENERAL_ERROR)}}),Ii=new Zn("poll").description("Standalone poll commands").addCommand(id).addCommand(ad);import{Command as Ti}from"commander";var sd=new Ti("status").description("Check a presentation generation run").argument("<run-id>","Run ID returned by presentation generation").option("--team-id <id>","Workspace ID override").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{try{let t=await L("createSlides",e,n.teamId);if(n.format==="json"){x(t);return}if(n.format==="quiet"){console.log(t.status);return}m(`Status: ${t.status}`),m(t.message),t.progress!==null&&m(`Progress: ${t.progress}%`),t.error&&c(t.error.message)}catch(t){c(t instanceof Error?t.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),Ri=new Ti("presentation").description("Presentation background-run commands").addCommand(sd);import{writeFile as cd}from"fs/promises";import{Command as dd}from"commander";import ld from"ora";var ki=new dd("scrape").description("Extract content from a URL").argument("<url>","URL to scrape").option("--team-id <id>","Workspace ID").option("-o, --output <path>","Save content to file").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{let t=n.format,o=t==="human"?ld("Scraping URL...").start():null;try{let r=await Wo(e,n.teamId);o?.stop(),(!r.success||!r.data)&&(c(r.error||"Failed to scrape URL"),process.exit(l.GENERAL_ERROR));let i=r.data;if(n.output&&(await cd(n.output,i.content,"utf-8"),t==="human"&&S(`Content saved to: ${n.output}`)),t==="json"){let{cost:a,...s}=i;x(s);return}if(t==="quiet"){console.log(i.content);return}i.title&&(console.log(),console.log(`Title: ${i.title}`)),i.metadata?.description&&console.log(`Description: ${i.metadata.description}`),console.log(`URL: ${i.url}`),console.log(`Tokens: ~${i.metadata?.tokenUsage?.toLocaleString()||"unknown"}`),i.warning&&_(i.warning),n.output||(console.log(),console.log("--- Content ---"),console.log(i.content)),i.cost&&i.cost>0&&m(`Cost: $${i.cost.toFixed(6)}`)}catch(r){o?.stop(),c(r instanceof Error?r.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}});import{Command as ut}from"commander";function Yt(e,n){n!=="quiet"&&x(e)}var ud=new ut("web").description("Search current public web sources").argument("<query>","Search query").option("--team-id <id>","Workspace ID").option("--max-results <count>","Maximum results","5").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{try{let t=await $("searchInternet",{maxResults:Number.parseInt(n.maxResults,10),query:e,teamId:n.teamId});Yt(t,n.format)}catch(t){c(t instanceof Error?t.message:"Search failed"),process.exit(l.GENERAL_ERROR)}}),md=new ut("news").description("Search recent news").argument("<topic>","News topic").option("--team-id <id>","Workspace ID").option("--timeframe <value>","Timeframe hint").option("--max-results <count>","Maximum results","6").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{try{let t=await $("getNews",{maxResults:Number.parseInt(n.maxResults,10),teamId:n.teamId,timeframe:n.timeframe,topic:e});Yt(t,n.format)}catch(t){c(t instanceof Error?t.message:"News search failed"),process.exit(l.GENERAL_ERROR)}}),pd=new ut("images").description("Search licensed image providers").argument("<query>","Image search query").option("--team-id <id>","Workspace ID").option("--max-results <count>","Maximum results","10").option("--aspect <aspect>","Aspect: any, square, wide, tall","any").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{try{let t=await $("searchImages",{aspect:n.aspect,maxResults:Number.parseInt(n.maxResults,10),query:e,teamId:n.teamId});Yt(t,n.format)}catch(t){c(t instanceof Error?t.message:"Image search failed"),process.exit(l.GENERAL_ERROR)}}),gd=new ut("video").description("Search licensed stock-video providers").argument("<query>","Stock-video search query").option("--team-id <id>","Workspace ID").option("--max-results <count>","Maximum results","10").option("--orientation <value>","Orientation: landscape, portrait, square, any","any").option("--license <value>","License: free, premium, any","any").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{try{let t=await $("searchStockVideo",{license:n.license,maxResults:Number.parseInt(n.maxResults,10),orientation:n.orientation,query:e,teamId:n.teamId});Yt(t,n.format)}catch(t){c(t instanceof Error?t.message:"Video search failed"),process.exit(l.GENERAL_ERROR)}}),Ai=new ut("search").description("Web, news, image, and stock-video search").addCommand(ud).addCommand(md).addCommand(pd).addCommand(gd);import{Command as no}from"commander";import eo from"ora";function to(e,n){if(n==="json"){let{cost:t,...o}=e;x(o);return}if(n==="quiet"){e.audioUrl?console.log(e.audioUrl):e.requestId?console.log(e.requestId):console.log(e.id);return}m(`Request ID: ${e.requestId||e.id}`),m(`Status: ${e.status}`),e.duration&&m(`Duration: ${e.duration}s`),e.audioUrl&&S(`Audio URL: ${e.audioUrl}`),e.cost!==void 0&&m(`Cost: $${e.cost.toFixed(4)}`),e.error&&c(`Error: ${e.error}`)}var fd=new no("generate").description("Generate sound effects from a text prompt").requiredOption("-t, --text <text>","Sound effect description (e.g., 'thunder rumbling, rain on window')").option("-d, --duration <seconds>","Duration in seconds (0.5-30)").option("-p, --provider <provider>","Untrusted provider hint (host policy is authoritative)").option("--prompt-influence <value>","How closely to follow prompt (0-1)","0.3").option("-l, --loop","Generate seamless looping audio",!1).option("--format <format>","Audio format: mp3, wav, ogg","mp3").option("-o, --output <path>","Output file path").option("--no-wait","Do not wait for completion").option("-f, --output-format <format>","Output format: human, json, quiet","human").action(async e=>{let n;e.duration&&(n=parseFloat(e.duration),(isNaN(n)||n<.5||n>30)&&(c("Duration must be between 0.5 and 30 seconds"),process.exit(l.INVALID_INPUT)));let t;e.promptInfluence&&(t=parseFloat(e.promptInfluence),(isNaN(t)||t<0||t>1)&&(c("Prompt influence must be between 0 and 1"),process.exit(l.INVALID_INPUT)));let o=e.outputFormat,r=o==="human"?eo("Generating sound effects...").start():null,i;try{let a=await Ho({text:e.text,duration:n,options:{provider:e.provider,promptInfluence:t,loop:e.loop,format:e.format}});if(i=a.requestId||a.id,!e.wait){r?.stop(),to(a,o);return}let s=a;if(a.status!=="completed"&&a.status!=="failed"){let d=a.requestId||a.id;r&&(r.text=`Processing (ID: ${d})...`),s=await K(()=>yn(d),60,2e3)}if(r?.stop(),s.status==="failed"&&(c(s.error||"Sound effects generation failed"),process.exit(l.GENERAL_ERROR)),to(s,o),e.output){if(!s.audioUrl)throw new Error("Sound effect completed without an audio URL");let d=o==="human"?eo("Downloading...").start():null;await Q(s.audioUrl,e.output),d?.stop(),o==="human"&&S(`Saved to: ${e.output}`)}}catch(a){r?.stop(),c(le(a,i),o),process.exit(l.GENERAL_ERROR)}}),hd=new no("status").description("Check status of a sound effects generation request").argument("<id>","Request ID").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{let t=n.format==="human"?eo("Checking status...").start():null;try{let o=await yn(e);t?.stop(),to(o,n.format)}catch(o){t?.stop(),c(o instanceof Error?o.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),$i=new no("sfx").description("Sound effects generation commands").addCommand(fd).addCommand(hd);import{mkdir as yd,writeFile as Ei}from"fs/promises";import{dirname as bd}from"path";import{Command as Kt}from"commander";import Ni from"ora";var Oi="en-US-Neural2-C",Pi="gemini",wd=new Kt("generate").description("Generate speech from text").requiredOption("-t, --text <text>","Text to convert to speech").requiredOption("-o, --output <path>","Output file path").option("--voice-id <voiceId>","Voice ID (e.g., ElevenLabs: 21m00Tcm4TlvDq8ikWAM)").option("--voice <voice>",`Voice name (default: ${Oi})`).option("-p, --provider <provider>",`Provider: gemini, elevenlabs, openai (default: ${Pi})`).option("-m, --model <model>","Model (provider-specific)").option("-s, --speed <speed>","Speech speed 0.1-4.0 (default: 1.0)").option("-l, --lang <lang>","Language or locale hint (for example en-US)").option("--speakers <json>",`Multi-speaker (Gemini, max 2): '[{"name":"Joe","voice":"Kore"},{"name":"Jane","voice":"Puck"}]'`).option("-i, --instructions <text>","Style prompt (OpenAI gpt-4o-mini-tts): tone, accent, speed, emotion").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{let n=e.format,t=n==="human"?Ni("Generating speech...").start():null,o;e.speed&&(o=parseFloat(e.speed),(Number.isNaN(o)||o<.1||o>4)&&(t?.stop(),c("Speed must be between 0.1 and 4.0"),process.exit(l.INVALID_INPUT)));let r;if(e.speakers)try{r=JSON.parse(e.speakers),(!Array.isArray(r)||r.length===0||r.length>2||r.some(a=>!a||typeof a!="object"||typeof a.name!="string"||!a.name.trim()||typeof a.voice!="string"||!a.voice.trim()))&&(t?.stop(),c("Speakers must be an array with 1-2 name/voice items"),process.exit(l.INVALID_INPUT))}catch{t?.stop(),c(`Invalid --speakers JSON. Example: '[{"name":"Joe","voice":"Kore"}]'`),process.exit(l.INVALID_INPUT)}let i;try{let a=e.voiceId,s=e.voice||Oi,d=e.provider||Pi,u={};r&&(u.gemini={speakers:r}),e.instructions&&(u.openai={instructions:e.instructions});let p=await It({text:e.text,options:{language:e.lang,provider:d,voiceId:a,voice:s,model:e.model,speed:o,providerOptions:Object.keys(u).length>0?u:void 0}});i=p.requestId,t?.stop();let w=e.output.endsWith(`.${p.format}`)?e.output:`${e.output}.${p.format}`;await yd(bd(w),{recursive:!0}),await Ei(w,p.audioData);let I=w.replace(/\.[^.]+$/,".txt");if(await Ei(I,e.text,"utf-8"),n==="json"){x({status:"completed",output:w,audioUrl:p.audioUrl,duration:p.duration,provider:p.provider,format:p.format,voice_id:p.voiceId??null,voice:p.voice??s,model:p.model??e.model??null,speed:p.speed??o??1,lang:p.language??e.lang??null,langApplied:p.langApplied??!1,timestamps:p.timestamps??null,words:p.wordTimings??null});return}if(n==="quiet"){console.log(w);return}S(`Saved to: ${w}`),m(`Duration: ${p.duration.toFixed(2)}s`),m(`Provider: ${p.provider}`),m(`Cost: $${p.cost.toFixed(6)}`)}catch(a){t?.stop(),c(le(a,i),n),process.exit(l.GENERAL_ERROR)}}),vd=new Kt("voices").description("List available voices").option("-p, --provider <provider>","Filter by provider: gemini, elevenlabs, openai").option("-f, --format <format>","Output format: human, json","human").action(async e=>{let n=e.format==="human"?Ni("Fetching voices...").start():null;try{let t=await qo(e.provider);if(n?.stop(),e.format==="json"){x(t.voices);return}if(Array.isArray(t.voices)){let o=e.provider?.toUpperCase()||"VOICES";console.log(),console.log(`${o} Voices:`),console.log("-".repeat(50));for(let r of t.voices)console.log(` ${r.name} (${r.id})`),console.log(` ${r.description}`)}else for(let[o,r]of Object.entries(t.voices))if(!(!r||r.length===0)){console.log(),console.log(`${o.toUpperCase()} Voices:`),console.log("-".repeat(50));for(let i of r)console.log(` ${i.name} (${i.id})`),console.log(` ${i.description}`)}}catch(t){n?.stop(),c(t instanceof Error?t.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),xd=new Kt("status").description("Read speech generation status").argument("<run-id>","Run ID").option("--team-id <id>","Workspace ID").option("-f, --format <format>","Output format: json","json").action(async(e,n)=>{try{x(await L("generateSpeech",e,n.teamId))}catch(t){c(t instanceof Error?t.message:"Status failed"),process.exit(l.GENERAL_ERROR)}}),Di=new Kt("tts").description("Text-to-speech commands").addCommand(wd).addCommand(vd).addCommand(xd);import{execSync as Ze,spawn as Yd,spawnSync as Kd}from"child_process";import{access as io,mkdir as et,readFile as gt,rm as ao,writeFile as ve}from"fs/promises";import{join as G,resolve as pt}from"path";import{Command as te}from"commander";import Qd from"ffmpeg-static";import ft from"ora";import{homedir as Sd}from"os";import{join as Li}from"path";import{readdir as Cd}from"fs/promises";var Id="conceptcraft";function Xe(){return Li(Sd(),`.${Id}`,"projects")}function Qt(e){return Li(Xe(),e)}async function oo(){try{let e=Xe();return(await Cd(e,{withFileTypes:!0})).filter(t=>t.isDirectory()).map(t=>t.name)}catch{return[]}}function Ui(e,n){let t=2,o=`${e}-${t}`;for(;n.includes(o);)t++,o=`${e}-${t}`;return o}import{Command as Td}from"commander";import Rd from"ora";import{execSync as kd,spawnSync as Ye}from"child_process";import{mkdirSync as Fi,existsSync as en,readFileSync as Vi,writeFileSync as _i}from"fs";import{join as $e,basename as Ad}from"path";import{tmpdir as $d}from"os";function tn(e,n){try{return kd(n,{stdio:"ignore"}),!0}catch{return!1}}function Zt(e){let n=Math.floor(e/60),t=Math.floor(e%60),o=Math.round(e%1*10);return`${n}:${String(t).padStart(2,"0")}.${o}`}function Ed(e){let n=Ye("ffprobe",["-v","error","-show_entries","format=duration","-of","default=noprint_wrappers=1:nokey=1",e],{encoding:"utf-8"});return parseFloat(n.stdout.trim())}function Od(e,n){let t=Ye("ffmpeg",["-i",e,"-vf",`select='gt(scene,${n})',showinfo`,"-vsync","vfr","-f","null","-"],{encoding:"utf-8",timeout:12e4}),o=[0],r=(t.stderr||"").split(`
|
|
3775
|
-
`);for(let i of r){let a=i.match(/pts_time:([\d.]+)/);if(a){let s=parseFloat(a[1]);s-o[o.length-1]>=1.5&&o.push(s)}}return o}function
|
|
3776
|
-
`),
|
|
3777
|
-
Results saved to: ${o}`)}});import{mkdir as
|
|
3735
|
+
`}var lt=["main","video","presentation","presentation-edit","tts","music","sfx","mix","image","video-search","scrape","branding","config"],Gt=["standalone","studio"],si={cmd:f.commands[0],pkg:f.packageName,url:f.apiUrl,name:f.name},Xe=new Pc("skill").description(`Manage ${f.displayName} skills for AI coding assistants`).addHelpText("after",`
|
|
3736
|
+
${M.bold("Skill Types:")}
|
|
3737
|
+
${M.cyan("main")} Main CLI skill with all capabilities overview
|
|
3738
|
+
${M.cyan("video")} Detailed video creation workflow with Remotion/R3F patterns
|
|
3739
|
+
${M.cyan("presentation")} Detailed presentation creation workflow
|
|
3740
|
+
${M.cyan("presentation-edit")} In-app presentation editing (Studio)
|
|
3741
|
+
|
|
3742
|
+
${M.bold("Reference Skills:")}
|
|
3743
|
+
${M.cyan("tts")} Text-to-speech generation (voices, providers, options)
|
|
3744
|
+
${M.cyan("music")} AI music generation (prompts, styles, duration)
|
|
3745
|
+
${M.cyan("sfx")} Sound effects generation (categories, looping, formats)
|
|
3746
|
+
${M.cyan("mix")} Audio mixing (video + voice + music)
|
|
3747
|
+
${M.cyan("image")} Image search and AI generation
|
|
3748
|
+
${M.cyan("video-search")} Stock video search
|
|
3749
|
+
${M.cyan("scrape")} URL content extraction
|
|
3750
|
+
${M.cyan("branding")} Brand profile management
|
|
3751
|
+
${M.cyan("config")} CLI configuration management
|
|
3752
|
+
|
|
3753
|
+
${M.bold("Examples:")}
|
|
3754
|
+
${M.gray("# Install main CLI skill (comprehensive overview)")}
|
|
3755
|
+
$ ${f.commands[0]} skill install main
|
|
3756
|
+
|
|
3757
|
+
${M.gray("# Install video skill")}
|
|
3758
|
+
$ ${f.commands[0]} skill install video
|
|
3759
|
+
|
|
3760
|
+
${M.gray("# Install presentation skill")}
|
|
3761
|
+
$ ${f.commands[0]} skill install presentation
|
|
3762
|
+
|
|
3763
|
+
${M.gray("# Install all skills")}
|
|
3764
|
+
$ ${f.commands[0]} skill install
|
|
3765
|
+
|
|
3766
|
+
${M.gray("# Install to specific directory")}
|
|
3767
|
+
$ ${f.commands[0]} skill install main --dir ~/.claude
|
|
3768
|
+
|
|
3769
|
+
${M.gray("# Show skill content")}
|
|
3770
|
+
$ ${f.commands[0]} skill show main
|
|
3771
|
+
`);Xe.command("install").description(`Install ${f.displayName} skills for AI coding assistants`).argument("[type]","Skill type: main, video, presentation, or omit for all").option("-d, --dir <path>","Install to specific directory").option("-g, --global","Install globally (to home directory)",!0).option("-l, --local","Install locally (to current directory)").option("-f, --force","Overwrite existing skill files").option("-m, --mode <mode>","Skill mode: standalone (render to file) or studio (Studio Preview)","standalone").action(async(e,n)=>{n.mode&&!Gt.includes(n.mode)&&(c(`Invalid mode: ${n.mode}. Must be one of: ${Gt.join(", ")}`),process.exit(1));let t={...si,mode:n.mode},o=[];e&&!lt.includes(e)&&(c(`Invalid skill type: ${e}. Must be one of: ${lt.join(", ")}`),process.exit(1));let r=[{name:"tts",content:Me(t)},{name:"music",content:Ve(t)},{name:"sfx",content:je(t)},{name:"mix",content:qe(t)},{name:"image",content:Be(t)},{name:"video-search",content:Ge(t)},{name:"scrape",content:We(t)},{name:"branding",content:He(t)},{name:"config",content:Je(t)}];(!e||e==="main")&&o.push({name:f.name,content:Lt(t),references:r});let i=[{name:"brief-guide",content:Ln.render(t)},{name:"website-assets",content:Nn.render(t)},{name:"source-scraping",content:Dn.render(t)}];(!e||e==="video")&&(o.push({name:`${f.name}-video`,content:Dt(t),references:i}),o.push({name:"remotion-scene-craft",content:ai(t)})),(!e||e==="presentation")&&o.push({name:`${f.name}-presentation`,content:Ft(t)}),(!e||e==="presentation-edit")&&o.push({name:`${f.name}-presentation-edit`,content:Ut(t)}),e==="tts"&&o.push({name:`${f.name}-tts`,content:Me(t)}),e==="music"&&o.push({name:`${f.name}-music`,content:Ve(t)}),e==="sfx"&&o.push({name:`${f.name}-sfx`,content:je(t)}),e==="mix"&&o.push({name:`${f.name}-mix`,content:qe(t)}),e==="image"&&o.push({name:`${f.name}-image`,content:Be(t)}),e==="video-search"&&o.push({name:`${f.name}-video-search`,content:Ge(t)}),e==="scrape"&&o.push({name:`${f.name}-scrape`,content:We(t)}),e==="branding"&&o.push({name:`${f.name}-branding`,content:He(t)}),e==="config"&&o.push({name:`${f.name}-config`,content:Je(t)}),console.log();for(let a of o){p(`Installing ${a.name}...`);let s=qt(a.name,a.content,{dir:n.dir,local:n.local,force:n.force},a.references);if(s.installed.length>0&&(S(`${a.name} installed successfully`),R(" Installed to",s.installed.join(", "))),s.skipped.length>0&&(p(` Skipped (already exists): ${s.skipped.join(", ")}`),console.log(M.gray(" Use --force to overwrite"))),s.errors.length>0)for(let d of s.errors)c(` ${d}`);s.installed.length===0&&s.skipped.length===0&&s.errors.length===0&&(p(" No supported AI coding assistants detected"),console.log(M.gray(" Supported editors: "+oi().join(", "))),console.log(M.gray(" Use --dir <path> to install to a specific directory"))),console.log()}if(!e||e==="video"){for(let a of[{name:"video-branding-director",generate:()=>jn(t)},{name:"video-scene-builder",generate:Un},{name:"video-scene-reviewer",generate:Fn},{name:"video-audio-director",generate:()=>Mn(t)},{name:"video-continuity-editor",generate:Vn}]){p(`Installing ${a.name} agent...`);let s=ri(a.name,a.generate(),{force:n.force,dir:n.dir});if(s.installed.length>0){S(`${a.name} agent installed`);let d={"Claude Code":"~/.claude/agents/","GitHub Copilot":"~/.github/agents/"};R(" Installed to",s.installed.map(u=>n.dir?u:`${u} (${d[u]??"~/.<editor>/agents/"})`).join(", "))}s.skipped.length>0&&p(` Agent skipped (already exists): ${s.skipped.join(", ")}`)}console.log()}});Xe.command("show").description("Display skill content").argument("[type]","Skill type (default: main)").option("-m, --mode <mode>","Skill mode: standalone or studio","standalone").action((e="main",n)=>{n.mode&&!Gt.includes(n.mode)&&(c(`Invalid mode: ${n.mode}. Must be one of: ${Gt.join(", ")}`),process.exit(1));let t={...si,mode:n.mode},r={main:()=>Lt(t),video:()=>Dt(t),presentation:()=>Ft(t),"presentation-edit":()=>Ut(t),tts:()=>Me(t),music:()=>Ve(t),sfx:()=>je(t),mix:()=>qe(t),image:()=>Be(t),"video-search":()=>Ge(t),scrape:()=>We(t),branding:()=>He(t),config:()=>Je(t),"video-branding-director":()=>jn(t),"video-scene-builder":()=>Un(),"video-scene-reviewer":()=>Fn(),"video-audio-director":()=>Mn(t),"video-continuity-editor":()=>Vn()}[e];if(r)console.log(r());else{let i=[...lt,"video-branding-director","video-scene-builder","video-scene-reviewer","video-audio-director","video-continuity-editor"];c(`Invalid skill type: ${e}. Must be one of: ${i.join(", ")}`),process.exit(1)}});Xe.command("uninstall").description(`Remove ${f.displayName} skills from AI coding assistants`).argument("[type]","Skill type: main, video, presentation, or omit for all").option("-g, --global","Uninstall globally (from home directory)",!0).option("-l, --local","Uninstall locally (from current directory)").action(async(e,n)=>{let t=[];e&&!lt.includes(e)&&(c(`Invalid skill type: ${e}. Must be one of: ${lt.join(", ")}`),process.exit(1)),(!e||e==="main")&&t.push(f.name),(!e||e==="video")&&(t.push(`${f.name}-video`),t.push("remotion-scene-craft")),(!e||e==="presentation")&&t.push(`${f.name}-presentation`),(!e||e==="presentation-edit")&&t.push(`${f.name}-presentation-edit`),(!e||e==="tts")&&t.push(`${f.name}-tts`),(!e||e==="music")&&t.push(`${f.name}-music`),(!e||e==="sfx")&&t.push(`${f.name}-sfx`),(!e||e==="mix")&&t.push(`${f.name}-mix`),(!e||e==="image")&&t.push(`${f.name}-image`),(!e||e==="video-search")&&t.push(`${f.name}-video-search`),(!e||e==="scrape")&&t.push(`${f.name}-scrape`),(!e||e==="branding")&&t.push(`${f.name}-branding`),(!e||e==="config")&&t.push(`${f.name}-config`),console.log();for(let o of t){let r=Bt(o,{local:n.local});if(r.removed.length>0?(S(`${o} uninstalled`),R(" Removed from",r.removed.join(", "))):p(` ${o} not found`),r.errors.length>0)for(let i of r.errors)U(` Failed to remove: ${i}`)}if(!e||e==="video")for(let o of["video-branding-director","video-scene-builder","video-scene-reviewer","video-audio-director","video-continuity-editor"])ii(o).removed.length>0&&S(`${o} agent uninstalled`);console.log()});import{Command as _c}from"commander";import ut from"chalk";var ci=new _c("templates").description("List slide design templates (use with `create --template <id>`)").argument("[search]","Filter templates by name, description, or category").option("-f, --format <format>","Output format (table, json)","table").option("--limit <n>","Maximum templates to list","25").action(async(e,n)=>{await P();try{let t=Number.parseInt(n.limit??"25",10),{templates:o}=await Vo(e,Number.isFinite(t)?t:25);if(o.length===0){n.format==="json"?console.log(JSON.stringify([])):p("No templates found");return}if(n.format==="json"){console.log(JSON.stringify(o,null,2));return}for(let r of o){let i=[r.isDefault?ut.green("default"):null,r.category??null,r.recommendedModes?.length?`modes: ${r.recommendedModes.join("/")}`:null].filter(Boolean).join(" \xB7 ");console.log(`${ut.bold(r.name)} ${ut.gray(r.id)}${i?`
|
|
3772
|
+
${ut.gray(i)}`:""}`)}console.log(),console.log(ut.gray(`Use one with: ${f.commands[0]} create "<topic>" --template <id>`))}catch(t){c(t instanceof Error?t.message:String(t)),process.exit(t.exitCode??1)}});import{Command as Nc}from"commander";import qn from"chalk";var di=new Nc("whoami").description("Show current user and team information").option("-f, --format <format>","Output format (human, json)","human").action(async e=>{await P();try{let n=await we();if(In(),e.format==="json"){console.log(JSON.stringify(n,null,2));return}fe("User"),console.log(),R("Email",n.user.email),n.user.username&&R("Username",n.user.username),(n.user.firstName||n.user.lastName)&&R("Name",[n.user.firstName,n.user.lastName].filter(Boolean).join(" "));let t=n.authType==="apiKey"?"API Key":n.authType==="oauth"?"OAuth":"Session";if(R("Auth Type",t),n.currentTeam&&(console.log(),fe("Current Team"),console.log(),R("ID",n.currentTeam.id),R("Name",n.currentTeam.name),R("Plan",n.currentTeam.planName),R("Role",n.currentTeam.isOwner?"Owner":"Member")),n.teams.length>1){console.log(),fe("All Teams"),console.log();for(let o of n.teams){let r=o.isCurrent?qn.green(" (current)"):"";console.log(` ${qn.bold(o.name)}${r}`),console.log(qn.gray(` ID: ${o.id} | Plan: ${o.planName} | Role: ${o.role}`))}}console.log()}catch(n){c(n instanceof Error?n.message:String(n)),process.exit(n.exitCode??1)}});function li(e){return e[0]==="--"?e.slice(1):e}import{Command as Bn}from"commander";function Lc(e,n){return[...n,e]}var Dc=new Bn("create").description("Start durable ad-set generation").argument("<title>","Ad-set title").requiredOption("--brief <brief>","Campaign brief").option("--hook <text>","Opening hook (repeat)",Lc,[]).option("--style <style>","ugc, clean, cinematic, or testimonial","ugc").option("--branding-id <id>","Branding ID").option("--team-id <id>","Workspace ID").option("--yes","Approve generation").action(async(e,n)=>{if(!n.yes)return c("Pass --yes to approve generation");try{x(await $("createAdSet",{approvalReceipt:"cli:--yes",brandingId:n.brandingId,brief:n.brief,hooks:n.hook.length?n.hook:[n.brief],style:n.style,teamId:n.teamId,title:e}))}catch(t){c(t instanceof Error?t.message:"Generation failed"),process.exit(l.GENERAL_ERROR)}}),Fc=new Bn("status").description("Read ad-set generation status").argument("<run-id>","Run ID").option("--team-id <id>","Workspace ID").action(async(e,n)=>{try{x(await L("createAdSet",e,n.teamId))}catch(t){c(t instanceof Error?t.message:"Status failed"),process.exit(l.GENERAL_ERROR)}}),ui=new Bn("ad-set").description("Ad set commands").addCommand(Dc).addCommand(Fc);import{Command as pi}from"commander";function mi(e){return new pi(e).description(e==="create"?"Create and activate a scheduled agent":"Create a reviewable agent recommendation").argument("<name>","Agent name").requiredOption("--instructions <markdown>","Agent instructions").option("--description <text>","Agent description","").option("--schedule <frequency>","manual, daily, weekdays, weekly, or monthly","weekly").option("--time <hh:mm>","Local run time","09:00").option("--timezone <zone>","IANA timezone","UTC").option("--output <adapter>","Output adapter","digest").option("--team-id <id>","Workspace ID").option("--yes","Approve saving the agent").action(async(n,t)=>{if(!t.yes)return c("Pass --yes to approve this operation");try{x(await $(e==="create"?"createAgent":"recommendAgent",{approvalReceipt:"cli:--yes",description:t.description,instructionsMarkdown:t.instructions,name:n,output:t.output,schedule:t.schedule,scheduleTime:t.time,teamId:t.teamId,timezone:t.timezone}))}catch(o){c(o instanceof Error?o.message:"Agent operation failed"),process.exit(l.GENERAL_ERROR)}})}var gi=new pi("agent").description("Scheduled agent commands").addCommand(mi("create")).addCommand(mi("recommend"));import{Command as Wt}from"commander";import Vc from"ora";import{mkdir as Uc,writeFile as fi}from"fs/promises";import{dirname as Mc}from"path";async function Q(e,n){if(await Uc(Mc(n),{recursive:!0}),e.startsWith("data:")){let r=e.match(/^data:[^;]+;base64,(.+)$/);if(!r)throw new Error("Invalid data URL format");let i=Buffer.from(r[1],"base64");if(i.length===0)throw new Error("Downloaded media was empty");await fi(n,i);return}let t=await fetch(e);if(!t.ok)throw new Error(`Failed to download media: ${t.status}`);let o=Buffer.from(await t.arrayBuffer());if(o.length===0)throw new Error("Downloaded media was empty");await fi(n,o)}var jc=15e3,qc=40;function Gn(e,n){if(n==="json"){x(e);return}if(n==="quiet"){console.log(e.videoUrl??e.requestId);return}p(`Request ID: ${e.requestId}`),p(`Status: ${e.status}`),e.durationSec!=null&&p(`Duration: ${e.durationSec}s`),e.videoUrl&&S(`Video URL: ${e.videoUrl}`),e.error&&c(`Error: ${e.error}`)}var Bc=new Wt("options").description("List available presenter avatars and voices").option("--language <language>","Filter voices by language").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{try{let n=await er(e.language);if(e.format==="json"){x(n);return}let t=n.personal??[];if(e.format==="quiet"){for(let o of t)console.log(o.id);for(let o of n.avatars)console.log(o.id);for(let o of n.voices)console.log(o.id);return}if(t.length>0){p("Your presenters:");for(let o of t)console.log(` ${o.id} ${o.name}`)}p("Avatars:");for(let o of n.avatars){let r=o.renderTiers?.length?` [${o.renderTiers.join(", ")}]`:"";console.log(` ${o.id} ${o.name}${r}`)}p("Voices:");for(let o of n.voices)console.log(` ${o.id} ${o.name}${o.language?` (${o.language})`:""}`)}catch(n){c(n instanceof Error?n.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),Gc=new Wt("generate").description("Generate a reusable presenter clip").option("--avatar-id <id>","Avatar id from 'avatar options'; sandbox runs use the host presenter policy").option("--audio-url <url>","Public narration audio URL for avatar lip sync").option("--voice-id <id>","Voice id from 'avatar options'").option("--script <text>","Exact words for the presenter to speak").requiredOption("-o, --output <path>","Local output path").option("--aspect <aspect>","Aspect: 1:1, 9:16, 16:9","9:16").option("--duration <seconds>","Maximum requested duration (1-300)").option("--transparent","Render a transparent-background WebM presenter clip").option("--background-color <hex>","Solid presenter background color, for example #0F172A").option("--background-image-url <url>","Public image URL used as the presenter background").option("--fit <mode>","Background image fit: contain or cover").option("--output-format <container>","Container: mp4 (default) or webm \u2014 webm renders a transparent-background clip (single scene) for compositing").option("--render-tier <tier>","Render cost/quality: basic, standard, premium","basic").option("--title <title>","Clip title","Presenter clip").option("--no-wait","Do not wait for completion").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{let n=e.transparent?"webm":e.outputFormat;!!e.audioUrl==!!e.script&&(c("Provide exactly one avatar speech input: --audio-url or --script"),process.exit(l.INVALID_INPUT)),["1:1","9:16","16:9"].includes(e.aspect)||(c("Aspect must be one of 1:1, 9:16, or 16:9"),process.exit(l.INVALID_INPUT)),e.outputFormat!==void 0&&!["mp4","webm"].includes(e.outputFormat)&&(c("Output format must be mp4 or webm"),process.exit(l.INVALID_INPUT)),e.backgroundColor!==void 0&&!/^#[0-9a-fA-F]{6}$/.test(e.backgroundColor)&&(c("Background color must be a six-digit hex value"),process.exit(l.INVALID_INPUT)),e.backgroundColor&&e.backgroundImageUrl&&(c("Provide only one presenter background"),process.exit(l.INVALID_INPUT)),e.fit!==void 0&&!["contain","cover"].includes(e.fit)&&(c("Fit must be contain or cover"),process.exit(l.INVALID_INPUT)),e.fit&&!e.backgroundImageUrl&&(c("Fit requires --background-image-url"),process.exit(l.INVALID_INPUT)),e.transparent&&e.outputFormat==="mp4"&&(c("--transparent cannot be combined with --output-format mp4"),process.exit(l.INVALID_INPUT)),n==="webm"&&(e.backgroundColor||e.backgroundImageUrl)&&(c("Transparent WebM output cannot be combined with a background"),process.exit(l.INVALID_INPUT)),["basic","standard","premium"].includes(e.renderTier)||(c("Render tier must be basic, standard, or premium"),process.exit(l.INVALID_INPUT));let t=e.duration?Number.parseInt(e.duration,10):void 0;t!==void 0&&(!Number.isFinite(t)||t<1||t>300)&&(c("Duration must be between 1 and 300 seconds"),process.exit(l.INVALID_INPUT));let o=e.format==="human"?Vc("Generating presenter clip...").start():null;try{let r=e.audioUrl?{audioUrl:e.audioUrl}:{script:e.script??"",...e.voiceId?{voiceId:e.voiceId}:{}},i=await tr({...r,aspect:e.aspect,...e.avatarId?{avatarId:e.avatarId}:{},...e.backgroundColor?{backgroundHex:e.backgroundColor}:{},...e.backgroundImageUrl?{backgroundImageUrl:e.backgroundImageUrl}:{},...t!==void 0?{durationSec:t}:{},...e.fit?{fit:e.fit}:{},...n?{outputFormat:n}:{},renderTier:e.renderTier,title:e.title});if(!e.wait){o?.stop(),Gn(i,e.format);return}let a=await K(()=>wn(i.requestId),qc,jc);if(a.status==="failed")throw new Error(a.error||"Presenter generation failed");if(!a.videoUrl)throw new Error("Presenter generation completed without a video URL");o&&(o.text="Downloading presenter clip..."),await Q(a.videoUrl,e.output),o?.stop(),Gn(a,e.format),e.format==="human"&&S(`Saved to: ${e.output}`)}catch(r){o?.stop(),c(r instanceof Error?r.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),Wc=new Wt("status").description("Check a presenter clip generation request").argument("<id>","Request ID").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{try{Gn(await wn(e),n.format)}catch(t){c(t instanceof Error?t.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),hi=new Wt("avatar").description("Avatar/presenter media commands").addCommand(Bc).addCommand(Gc).addCommand(Wc);import{writeFile as yi}from"fs/promises";import H from"chalk";import{Command as se}from"commander";import Hc from"ora";var bi=new se("branding").description("Manage brand profiles").addCommand(new se("list").description("List brand profiles").option("-f, --format <format>","Output format (table, json)","table").action(async e=>{await P();try{let n=await fn();if(n.brandings.length===0){e.format==="json"?console.log(JSON.stringify([])):(p("No brand profiles found"),console.log(),console.log(H.gray(`Create one with: ${f.commands[0]} branding extract <url>`)));return}e.format==="json"?console.log(JSON.stringify(n.brandings,null,2)):console.log(dr(n.brandings))}catch(n){c(n instanceof Error?n.message:String(n)),process.exit(n.exitCode??1)}})).addCommand(new se("get").description("Get brand profile details").argument("<id>","Brand profile ID").option("-f, --format <format>","Output format (summary, json)","summary").option("-o, --output <path>","Save JSON to file").action(async(e,n)=>{await P();try{let t=await jo(e);if(n.output){await yi(n.output,JSON.stringify(t,null,2)),S(`Brand profile saved to ${n.output}`);return}if(n.format==="json")console.log(JSON.stringify(t,null,2));else{if(fe("Brand Profile"),console.log(),R("ID",t.id),R("Name",t.name),R("Source URL",t.sourceUrl??H.gray("None")),R("Default",t.isDefault?H.green("Yes"):"No"),t.createdAt&&R("Created",new Date(t.createdAt).toLocaleString()),console.log(),t.primaryColor||t.colors.length>0){if(console.log(H.bold(" Colors")),t.primaryColor){let r=H.bgHex(t.primaryColor)(" ");console.log(` Primary: ${r} ${t.primaryColor}`)}if(t.colors.length>0){console.log(" Palette:");for(let r of t.colors.slice(0,10)){let i=H.bgHex(r.hex)(" "),a=r.role?H.gray(` (${r.role})`):"";console.log(` ${i} ${r.hex}${a}`)}}console.log()}t.logoUrl&&(console.log(H.bold(" Logo")),console.log(` ${t.logoUrl}`),console.log());let o=t.typography;o&&Object.keys(o).length>0&&(console.log(H.bold(" Typography")),(o.primary||o.headings)&&console.log(` Headings: ${o.primary||o.headings||"-"}`),(o.secondary||o.body)&&console.log(` Body: ${o.secondary||o.body||"-"}`),console.log()),(t.confidence||t.extractionMethod)&&(console.log(H.bold(" Extraction")),t.confidence&&console.log(` Confidence: ${Math.round(t.confidence*100)}%`),t.extractionMethod&&console.log(` Method: ${t.extractionMethod}`),console.log()),console.log(H.gray(" Use --format json for full details")),console.log()}}catch(t){c(t instanceof Error?t.message:String(t)),process.exit(t.exitCode??1)}})).addCommand(new se("find").description("Find existing brand profile by name or URL").argument("<query>","Brand name or website URL to search for").action(async e=>{await P();try{let n=await fn(),t=e.toLowerCase().replace(/^https?:\/\//,"").replace(/\/$/,""),o=n.brandings.filter(r=>{let i=(r.name||"").toLowerCase(),a=(r.sourceUrl||"").toLowerCase().replace(/^https?:\/\//,"").replace(/\/$/,"");return i.includes(t)||a.includes(t)||i.length>0&&t.includes(i)||a.length>0&&t.includes(a)});if(o.length===0){p(`No brand profiles matching "${e}"`),console.log(H.gray(` Extract one with: ${f.commands[0]} branding extract <url>`));return}console.log(`Found ${o.length} brand${o.length>1?"s":""}:
|
|
3773
|
+
`);for(let r of o){let i=r.primaryColor?`${H.bgHex(r.primaryColor)(" ")} ${r.primaryColor}`:"";console.log(` ${H.bold(r.name)} ${H.gray(r.id)}`),r.sourceUrl&&console.log(` ${H.gray(r.sourceUrl)}`),i&&console.log(` ${i}`),console.log()}console.log(H.gray(` Export with: ${f.commands[0]} branding get <id> -o branding.json`))}catch(n){c(n instanceof Error?n.message:String(n)),process.exit(n.exitCode??1)}})).addCommand(new se("extract").description("Extract brand profile from a website").argument("<url>","Website URL to extract branding from").option("--team-id <id>","Team ID").option("--yes","Confirm starting a paid/external extraction").option("--no-save","Extract without saving").option("-o, --output <path>","Save JSON to file").action(async(e,n)=>{await P(),n.yes||(c("Pass --yes to confirm brand extraction."),process.exit(l.INVALID_INPUT));try{new URL(e.startsWith("http")?e:`https://${e}`)}catch{c("Invalid URL format"),process.exit(6)}let t=e.startsWith("http")?e:`https://${e}`,o=n.teamId??yt(),r=Hc({text:`Extracting branding from ${t}...`,stream:process.stdout}).start();try{let i=await qo(t,o,"cli:--yes");r.succeed("Brand extraction started");let a=JSON.stringify(i,null,2);n.output?(await yi(n.output,a),S(`Brand profile saved to ${n.output}`)):console.log(a),p(`Check progress with: ${f.commands[0]} branding status ${i.runId}`),console.log()}catch(i){r.fail("Extraction failed"),c(i instanceof Error?i.message:String(i)),process.exit(i.exitCode??1)}})).addCommand(new se("status").description("Check a brand extraction run").argument("<run-id>","Run ID returned by branding extract").option("--team-id <id>","Workspace ID").action(async(e,n)=>{try{x(await L("extractBranding",e,n.teamId))}catch(t){c(t instanceof Error?t.message:"Status failed"),process.exit(l.GENERAL_ERROR)}})).addCommand(new se("set-default").description("Set a brand profile as default").argument("<id>","Brand profile ID").action(async e=>{await P(),p(`To set brand ${e} as default, use the web dashboard.`),console.log(),console.log(H.gray("API support for setting default brand is coming soon."))})).addCommand(new se("competitor").description("Brand competitor commands").addCommand(new se("list").description("List competitors for a brand").option("--branding-id <id>","Brand ID").option("--team-id <id>","Workspace ID").action(async e=>{try{console.log(JSON.stringify(await $("getBrandCompetitors",{brandingId:e.brandingId,teamId:e.teamId}),null,2))}catch(n){c(n instanceof Error?n.message:"Lookup failed"),process.exit(1)}})).addCommand(new se("add").description("Add or update a brand competitor").argument("<name>","Competitor name").option("--branding-id <id>","Brand ID").option("--team-id <id>","Workspace ID").option("--website <url>","Competitor website").option("--x-handle <handle>","Competitor X handle").option("--yes","Confirm writing brand data").action(async(e,n)=>{n.yes||(c("Pass --yes to confirm adding a competitor."),process.exit(l.INVALID_INPUT));try{x(await $("addCompetitor",{approvalReceipt:"cli:--yes",brandingId:n.brandingId,name:e,teamId:n.teamId,website:n.website,xHandle:n.xHandle}))}catch(t){c(t instanceof Error?t.message:"Write failed"),process.exit(l.GENERAL_ERROR)}}))).addCommand(new se("social").description("Brand social handle commands").addCommand(new se("add").description("Add or update a brand social handle").argument("<platform>","Social platform").argument("<handle>","Account handle").option("--branding-id <id>","Brand ID").option("--team-id <id>","Workspace ID").option("--yes","Confirm writing brand data").action(async(e,n,t)=>{t.yes||(c("Pass --yes to confirm adding a social handle."),process.exit(l.INVALID_INPUT));try{x(await $("addBrandSocialHandle",{approvalReceipt:"cli:--yes",brandingId:t.brandingId,handle:n,platform:e,teamId:t.teamId}))}catch(o){c(o instanceof Error?o.message:"Write failed"),process.exit(l.GENERAL_ERROR)}})));import{readFile as Jc}from"fs/promises";import{Command as wi}from"commander";var zc=new wi("extract").description("Extract normalized text from a URL or local file").argument("<source>","URL, encoded source, or local file path").option("--team-id <id>","Workspace ID").option("--mime-type <type>","Source MIME type").option("--max-length <count>","Maximum output characters","30000").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{try{let t=e,o;e.includes("://")||(t=await Jc(e,"utf8"),o=e);let r=await $("extractContent",{filename:o,maxLength:Number.parseInt(n.maxLength,10),mimeType:n.mimeType,source:t,teamId:n.teamId});n.format!=="quiet"&&x(r)}catch(t){c(t instanceof Error?t.message:"Extraction failed"),process.exit(l.GENERAL_ERROR)}}),vi=new wi("content").description("Content extraction commands").addCommand(zc);import Y from"chalk";import{Command as Xc}from"commander";import{existsSync as Yc,readFileSync as Kc}from"fs";import Qc,{resolve as xi}from"path";var Si=new Xc("create").description("Create a new presentation").argument("<topic>","The topic or title for the presentation").option("-n, --slides <count>","Number of slides (1-20)").option("-m, --mode <mode>","Generation quality (best, balanced, fast, ultrafast, instant, image-min, image, image-max) \u2014 default: fast. image-min/image/image-max render each slide as a full-bleed AI image (text not editable); slower + pricier, require image-mode access, and cap at 25 slides. image-min is cheapest (brand colors only, no exact fonts).").option("--image-tier <tier>","Embedded-image quality for HTML modes: smart (default, auto-routes per image), fast (cheapest, no extra credits), balanced (+50 credits/slide), best (premium, +200 credits/slide, slow). Ignored for image-*/instant modes.").option("-t, --tone <tone>","Tone (creative, professional, educational, formal, casual)").option("--amount <amount>","Content density (minimal, concise, detailed, extensive)").option("--audience <text>","Target audience description").option("-l, --language <lang>","Output language").option("--branding-id <id>","Branding ID (from `ccr branding list` or `ccr branding extract`)").option("--brand-domain <url>","Brand the deck by website/domain (e.g. https://www.pfizer.com). Errors if no matching saved brand exists.").option("--template <id>","Slide template ID to style the deck after (from `ccr templates`). A default template is applied automatically when omitted.").option("-c, --context <text>","Inline text context (research notes, key facts)").option("--context-file <path>","Path to a context file (text, markdown, JSON)").option("--stdin","Read context from stdin").option("-f, --file <paths...>","Files to upload (PDF, PPTX, DOCX, images)").option("-g, --goal <type>","Goal (inform, persuade, train, learn, entertain, report)").option("--styling <mode>","Styling mode (freeform, brand-only, brand-plus-style, style-only, no-styling)").option("--reference-url <url>","Image URL to use as visual style reference").option("--thinking-depth <depth>","AI thinking depth (quick, moderate, deep, profound)").option("--theme <preset>","[instant mode only] Color theme preset (blue, violet, rose, orange, green)").option("--primary-color <hex>","[instant mode only] Primary color (e.g., #0066CC)").option("--secondary-color <hex>","[instant mode only] Secondary color").option("--accent-color <hex>","[instant mode only] Accent color").option("--background-color <hex>","[instant mode only] Background color").option("--foreground-color <hex>","[instant mode only] Foreground/text color").option("--decorations <style>","[instant mode only] Background decoration (none, waves-bottom-left, waves-top-right, blob-corners, minimal)").option("--team-id <id>","Team ID (switch teams)").option("-o, --output <format>","Output format (human, json, quiet)").option("--no-stream","Wait for completion without streaming progress").option("--wait","Poll until generation completes").option("--debug","Enable debug logging").option("--open","Open in browser after creation").option("--id <uuid>","Use a specific UUID for the presentation").option("--studio","Studio mode: use current directory name as presentation ID (auto-links to Studio preview)").action(async(e,n)=>{await P();let t;n.slides!==void 0&&(t=parseInt(n.slides,10),(Number.isNaN(t)||t<1||t>20)&&(c("Slide count must be between 1 and 20"),process.exit(6)));let o=["best","balanced","fast","ultrafast","instant","image-min","image","image-max"];n.mode&&!o.includes(n.mode)&&(c(`Invalid mode: ${n.mode}. Valid: ${o.join(", ")}`),process.exit(6));let r=["smart","fast","balanced","best"];n.imageTier&&!r.includes(n.imageTier)&&(c(`Invalid image tier: ${n.imageTier}. Valid: ${r.join(", ")}`),process.exit(6));let i=["creative","professional","educational","formal","casual"];n.tone&&!i.includes(n.tone)&&(c(`Invalid tone: ${n.tone}. Valid: ${i.join(", ")}`),process.exit(6));let a=["minimal","concise","detailed","extensive"];n.amount&&!a.includes(n.amount)&&(c(`Invalid amount: ${n.amount}. Valid: ${a.join(", ")}`),process.exit(6));let s=["freeform","brand-only","brand-plus-style","style-only","no-styling"];n.styling&&!s.includes(n.styling)&&(c(`Invalid styling: ${n.styling}. Valid: ${s.join(", ")}`),process.exit(6));let d=["quick","moderate","deep","profound"];n.thinkingDepth&&!d.includes(n.thinkingDepth)&&(c(`Invalid thinking-depth: ${n.thinkingDepth}. Valid: ${d.join(", ")}`),process.exit(6));let u=["inform","persuade","train","learn","entertain","report"];n.goal&&!u.includes(n.goal)&&(c(`Invalid goal: ${n.goal}. Valid: ${u.join(", ")}`),process.exit(6));let m=["blue","violet","rose","orange","green"];n.theme&&!m.includes(n.theme)&&(c(`Invalid theme: ${n.theme}. Valid: ${m.join(", ")}`),process.exit(6));let b=["none","waves-bottom-left","waves-top-right","blob-corners","minimal"];n.decorations&&!b.includes(n.decorations)&&(c(`Invalid decorations: ${n.decorations}. Valid: ${b.join(", ")}`),process.exit(6));let C=n.theme||n.primaryColor||n.secondaryColor||n.accentColor||n.backgroundColor||n.foregroundColor||n.decorations;C&&n.mode&&n.mode!=="instant"&&(c("--theme, --primary-color, --decorations and other color options are only supported with --mode instant"),process.exit(6));let g=n.mode??(C?"instant":"fast"),T=/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;for(let[I,V]of[["primary-color",n.primaryColor],["secondary-color",n.secondaryColor],["accent-color",n.accentColor],["background-color",n.backgroundColor],["foreground-color",n.foregroundColor]])V&&!T.test(V)&&(c(`Invalid ${I}: ${V}. Must be hex (e.g., #0066CC)`),process.exit(6));try{n.output!=="json"&&n.output!=="quiet"&&process.stdout.write(Y.gray("Checking generation limits... "));let I=await Wo(g,t??10,n.teamId);if(n.output!=="json"&&n.output!=="quiet"){console.log(Y.green("\u2713"));let V=I.remaining[g],q=I.limits[g],ne=V===void 0||q===void 0?"":` | ${g}: ${V}/${q} remaining`;console.log(Y.gray(` Plan: ${I.planName}${ne}`))}}catch(I){n.output==="json"?console.log(JSON.stringify({success:!1,error:I instanceof Error?I.message:String(I)})):(console.log(Y.red("\u2717")),c(I instanceof Error?I.message:String(I))),process.exit(I.exitCode??1)}let v=[];if(n.file&&n.file.length>0){for(let I of n.file)Yc(xi(I))||(c(`File not found: ${I}`),process.exit(6));n.output!=="json"&&n.output!=="quiet"&&console.log(Y.gray(`
|
|
3774
|
+
Uploading ${n.file.length} file(s)...`));try{v=await No(n.file.map(I=>xi(I)),(I,V,q)=>{n.output!=="json"&&n.output!=="quiet"&&q&&process.stdout.write(`\r ${Y.cyan("\u2B06")} Uploading: ${q} (${I+1}/${V})`)}),n.output!=="json"&&n.output!=="quiet"&&console.log(`\r ${Y.green("\u2713")} Uploaded ${v.length} file(s) `)}catch(I){c(`Failed to upload files: ${I instanceof Error?I.message:String(I)}`),process.exit(1)}}let y;(n.stdin||!process.stdin.isTTY)&&(y=await Zc(),n.stdin&&!y&&(c("No content received from stdin"),process.exit(6)));let w=n.context;if(n.contextFile)try{w=Kc(n.contextFile,"utf-8"),w.trim()||(c(`Context file is empty: ${n.contextFile}`),process.exit(6))}catch{c(`Failed to read context file: ${n.contextFile}`),process.exit(6)}!y&&!w&&v.length===0&&(c("Context is required to create a presentation."),console.log(),console.log(Y.gray(" -f, --file <paths...> Upload files (PDF, PPTX, images)")),console.log(Y.gray(" -c, --context <text> Inline text context")),console.log(Y.gray(" --context-file <path> Read from a file")),console.log(Y.gray(` cat file | ${f.commands[0]} Pipe content`)),process.exit(6));let E=[...v];y&&E.push({id:`stdin-${Date.now()}`,content:y,title:"Piped Content",mime:"text/plain",selected:!0}),w&&E.push({id:`context-${Date.now()}`,content:w,title:"Context",mime:"text/plain",selected:!0});let A,_=n.primaryColor||n.secondaryColor||n.accentColor||n.backgroundColor||n.foregroundColor;(n.theme||_||n.decorations)&&(A={},n.theme&&(A.preset=n.theme),_&&(A.custom={},n.primaryColor&&(A.custom.primary=n.primaryColor),n.secondaryColor&&(A.custom.secondary=n.secondaryColor),n.accentColor&&(A.custom.accent=n.accentColor),n.backgroundColor&&(A.custom.background=n.backgroundColor),n.foregroundColor&&(A.custom.foreground=n.foregroundColor)),n.decorations&&(A.decorations=n.decorations));try{let I=await Lo({topic:e,...t!==void 0&&{slideCount:t},mode:g,...n.imageTier&&{imageTier:n.imageTier},...n.tone&&{tone:n.tone},...n.amount&&{amount:n.amount},...n.audience&&{audience:n.audience},...n.language&&{language:n.language},...n.brandingId&&{brandingId:n.brandingId},...n.brandDomain&&{brandDomain:n.brandDomain},...n.template&&{templateId:n.template},...n.styling&&{stylingMode:n.styling},...n.referenceUrl&&{referenceUrl:n.referenceUrl},...n.thinkingDepth&&{thinkingDepth:n.thinkingDepth},...n.goal&&{goal:n.goal},...n.teamId&&{teamId:n.teamId},...A&&{theme:A},...n.studio?{documentId:Qc.basename(process.cwd())}:n.id?{documentId:n.id}:{},...E.length>0&&{contentSources:{uploadedFiles:E,contextFiles:[]}}});if(!n.wait){n.output==="json"?console.log(JSON.stringify({success:!0,run:I},null,2)):n.output!=="quiet"&&(S("Presentation generation queued"),R("Run ID",I.runId),R("Status",I.status),console.log(Y.gray(` Check later with presentation status ${I.runId}`)));return}let V=await L("createSlides",I.runId,n.teamId);for(;!V.done;)n.output!=="json"&&n.output!=="quiet"&&console.log(Y.gray(` ${V.message}`)),await new Promise(ne=>setTimeout(ne,(V.nextPollAfterSeconds??5)*1e3)),V=await L("createSlides",I.runId,n.teamId);if(V.error)throw new Error(V.error.message);let q=V.entity?await Se(V.entity.id):void 0;if(n.output==="json")console.log(JSON.stringify({success:!0,presentation:q,run:V,viewUrl:q?Le(q.slug,n.language??"en"):void 0},null,2));else{console.log(),S("Presentation created successfully"),console.log(),R("Title",q?.title??e),R("Slides",String(q?.numberOfSlides??t??"\u2014")),console.log();let ne=q?Le(q.slug,n.language??"en"):"N/A";ne!=="N/A"&&(console.log(Y.bold(" Open: ")+Y.cyan.underline(ne)),n.open&&await(await import("open")).default(ne)),console.log()}}catch(I){n.output==="json"?console.log(JSON.stringify({success:!1,error:I instanceof Error?I.message:String(I)})):c(I instanceof Error?I.message:String(I)),process.exit(I.exitCode??1)}});async function Zc(){return new Promise(e=>{let n="";if(process.stdin.setEncoding("utf8"),process.stdin.isTTY){e("");return}process.stdin.on("data",t=>{n+=t}),process.stdin.on("end",()=>{e(n.trim())}),setTimeout(()=>{e(n.trim())},100)})}import{Command as ed}from"commander";import Ht from"chalk";var Ii=new ed("get").description("Get presentation details").argument("<slug>","Presentation slug (e.g., my-presentation-v1-abc123)").option("-f, --format <format>","Output format (summary, full, json)","summary").option("--include <fields>","Fields to include (comma-separated: slides,styling)").option("-l, --language <lang>","Language for view URL","en").action(async(e,n)=>{await P();try{let t=await Se(e);if(n.format==="json"){console.log(JSON.stringify(t,null,2));return}let o=Le(t.slug,n.language);fe("Presentation Details"),console.log(),R("Slug",t.slug),R("Title",t.title||"Untitled"),R("Description",t.description||Ht.gray("None")),R("Slides",String(t.numberOfSlides||"-")),R("Mode",t.mode||"-"),R("Created",Sn(t.createdAt)),t.updatedAt&&R("Updated",Sn(t.updatedAt)),console.log(),o!=="N/A"&&console.log(Ht.bold(" Open: ")+Ht.cyan.underline(o)),console.log(),n.format==="full"&&n.include?.includes("slides")&&(console.log(Ht.gray("(Full slide content available in JSON format)")),console.log())}catch(t){c(t instanceof Error?t.message:String(t)),process.exit(t.exitCode??1)}});import{Command as zt}from"commander";import td from"ora";function le(e,n){let t=e instanceof Error?e.message:"Unknown error";return!n||t.includes(n)?t:`${t} Request ID: ${n}. Resume with the matching status command; do not start a duplicate run.`}function nd(e){let n=e?.trim().toLowerCase();if(!(!n||n==="any"||n==="all"))return n==="web"||n==="stock"?[n]:void 0}function od(e){let n=e.assetType??"image";if(n!=="image"&&n!=="icon")throw new Error("Asset type must be image or icon");let t;if(e.maxResults&&(t=Number.parseInt(e.maxResults,10),Number.isNaN(t)||t<1))throw new Error("Max results must be a positive number");return{query:n==="icon"?`${e.query.trim()} transparent icon isolated symbol`:e.query.trim(),options:{maxResults:t||10,size:e.size,safeSearch:e.safeSearch,assetType:n,sources:nd(e.source),transparentBackground:n==="icon"}}}function rd(e){let n=e.url||e.imageUrl;if(!n)throw new Error("Image search returned a result without a URL");return n}function id(e){return e.transparent??e.isTransparent??e.metadata?.transparent??e.metadata?.isTransparent}function ad(e,n){return e.data.results.flatMap(t=>t.results.map(o=>{let r=o,i=id(r);if(n==="icon"&&i!==!0)throw new Error("Icon search returned a result without a verified transparent background");return{...r,url:rd(r),provider:t.providerName,assetType:n,...i!==void 0?{transparent:i}:{}}}))}function sd(e){return e.error||e.status==="failed"||e.status==="errored"||e.status==="cancelled"?"failed":e.done||e.status==="completed"?"completed":e.status==="in_progress"?"processing":"pending"}function Jt(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function cd(e){return{requestId:e.runId,status:sd(e),...e.entity?.url?{url:e.entity.url}:{},...e.error?.message?{error:e.error.message}:{},...Jt(e.output?.width)!==void 0?{width:Jt(e.output?.width)}:{},...Jt(e.output?.height)!==void 0?{height:Jt(e.output?.height)}:{}}}async function Ci(e,n){return cd(await L("createImage",e,n))}function Wn(e,n){if(n==="json"){x(e);return}if(n==="quiet"){console.log(e.output??e.url??e.requestId);return}p(`Request ID: ${e.requestId}`),p(`Status: ${e.status}`),e.url&&S(`Image URL: ${e.url}`),e.output&&S(`Saved to: ${e.output}`),e.error&&c(`Error: ${e.error}`)}var dd=new zt("search").description("Search images across the web and licensed stock").requiredOption("-q, --query <query>","Search query").option("-n, --max-results <number>","Maximum number of results (default: 10)").option("-s, --size <size>","Image size: small, medium, large, any","large").option("--asset-type <type>","Asset intent: image or transparent icon","image").option("--source <source>","Catalog: web, stock, or any (default: any)","any").option("--safe-search","Enable safe search (default: true)",!0).option("--no-safe-search","Disable safe search").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{let n=e.format,t=n==="human"?td("Searching for images...").start():null,o;try{o=od(e)}catch(r){t?.stop(),c(r instanceof Error?r.message:"Invalid image search request"),process.exit(l.INVALID_INPUT);return}try{let r=await Tt(o);t?.stop(),r.success||(c("Search failed"),process.exit(l.GENERAL_ERROR));let i=o.options?.assetType??"image",a=ad(r,i);if(n==="json"){x({success:!0,query:e.query,assetType:i,totalResults:a.length,images:a});return}if(n==="quiet"){for(let s of a)console.log(s.url);return}if(a.length===0){p("No images found");return}S(`Found ${a.length} images for "${e.query}"`),console.log();for(let s=0;s<a.length;s++){let d=a[s];console.log(`[${s+1}] ${d.title||"Untitled"}`),console.log(` URL: ${d.url}`),console.log(` Size: ${d.width}x${d.height}`),d.author&&console.log(` Author: ${d.author}`),console.log(` Provider: ${d.provider}`),console.log()}p(`Total cost: $${r.data.totalCost.toFixed(4)}`)}catch(r){t?.stop(),c(r instanceof Error?r.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),ld=new zt("generate").description("Generate an image and optionally save it locally").argument("[prompt]","Image prompt").option("-p, --prompt <text>","Image prompt (named compatibility form)").option("--provider <provider>","Provider override").option("--model <model>","Model override").option("--width <pixels>","Width").option("--height <pixels>","Height").option("--team-id <id>","Workspace ID").option("-o, --output <path>","Local output path").option("--no-wait","Do not wait for completion").option("-f, --format <format>","Output format: human, json, quiet","human").option("--yes","Approve generation").action(async(e,n)=>{let t,o=e??n.prompt;o?.trim()||(c("Provide an image prompt as an argument or with --prompt"),process.exit(l.INVALID_INPUT)),n.yes||(c("Pass --yes to approve image generation"),process.exit(l.INVALID_INPUT)),!n.wait&&n.output&&(c("--output requires waiting for completion; remove --no-wait"),process.exit(l.INVALID_INPUT));try{let r=await $("createImage",{approvalReceipt:"cli:--yes",height:n.height?Number.parseInt(n.height,10):void 0,model:n.model,prompt:o.trim(),provider:n.provider,teamId:n.teamId,width:n.width?Number.parseInt(n.width,10):void 0});if(t=r.runId,!n.wait){Wn({requestId:r.runId,status:"pending"},n.format);return}let i=await K(()=>Ci(r.runId,n.teamId),180,2e3);if(i.status==="failed")throw new Error(i.error||"Image generation failed");if(!i.url)throw new Error("Image generation completed without an image URL");let a=n.output?{...i,output:n.output}:i;n.output&&await Q(i.url,n.output),Wn(a,n.format)}catch(r){c(le(r,t),n.format),process.exit(l.GENERAL_ERROR)}}),ud=new zt("status").description("Read image generation status").argument("<run-id>","Run ID").option("--team-id <id>","Workspace ID").option("-o, --output <path>","Download a completed image").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{try{let t=await Ci(e,n.teamId);if(n.output){if(t.status!=="completed"||!t.url)throw new Error("Image generation is not complete");await Q(t.url,n.output),t.output=n.output}Wn(t,n.format)}catch(t){c(t instanceof Error?t.message:"Status failed"),process.exit(l.GENERAL_ERROR)}}),Ti=new zt("image").description("Image search and generation commands").addCommand(dd).addCommand(ld).addCommand(ud);import{Command as Hn}from"commander";var md=new Hn("search").description("Search the workspace Knowledge Hub").argument("[query]","Optional search query").option("--team-id <id>","Workspace ID").option("--kind <kind>","Knowledge kind").option("--limit <count>","Maximum results","10").action(async(e,n)=>{try{x(await $("searchKnowledge",{kind:n.kind,limit:Number.parseInt(n.limit,10),query:e,teamId:n.teamId}))}catch(t){c(t instanceof Error?t.message:"Knowledge search failed"),process.exit(l.GENERAL_ERROR)}}),pd=new Hn("bundle").description("Read a bounded Open Knowledge Format bundle").option("--team-id <id>","Workspace ID").option("--kind <kind>","Knowledge kind").action(async e=>{try{x(await $("getKnowledgeBundle",{kind:e.kind,teamId:e.teamId}))}catch(n){c(n instanceof Error?n.message:"Knowledge bundle failed"),process.exit(l.GENERAL_ERROR)}}),Ri=new Hn("knowledge").description("Knowledge Hub commands").addCommand(md).addCommand(pd);import{Command as Jn}from"commander";var gd=new Jn("create").description("Start background microsite generation").argument("<title>","Microsite title").requiredOption("--description <brief>","Microsite brief").option("--audience <audience>","Target audience").option("--tone <tone>","Tone").option("--language <language>","Content language","en").option("--branding-id <id>","Branding ID").option("--team-id <id>","Workspace ID").option("--yes","Approve generation").action(async(e,n)=>{if(!n.yes)return c("Pass --yes to approve generation");try{x(await $("createMicrosite",{approvalReceipt:"cli:--yes",audience:n.audience,brandingId:n.brandingId,description:n.description,language:n.language,teamId:n.teamId,title:e,tone:n.tone}))}catch(t){c(t instanceof Error?t.message:"Generation failed"),process.exit(l.GENERAL_ERROR)}}),fd=new Jn("status").description("Read microsite generation status").argument("<run-id>","Run ID").option("--team-id <id>","Workspace ID").action(async(e,n)=>{try{x(await L("createMicrosite",e,n.teamId))}catch(t){c(t instanceof Error?t.message:"Status failed"),process.exit(l.GENERAL_ERROR)}}),ki=new Jn("microsite").description("Microsite commands").addCommand(gd).addCommand(fd);import{Command as Yn}from"commander";import zn from"ora";function Xn(e,n){if(n==="json"){let{cost:t,...o}=e;x(o);return}if(n==="quiet"){e.outputUrl?console.log(e.outputUrl):console.log(e.requestId);return}p(`Request ID: ${e.requestId}`),p(`Status: ${e.status}`),e.duration&&p(`Duration: ${e.duration}s`),e.outputUrl&&S(`Output URL: ${e.outputUrl}`),e.cost!==void 0&&p(`Cost: $${e.cost.toFixed(4)}`),e.error&&c(`Error: ${e.error}`)}var hd=new Yn("create").description("Mix audio tracks into a video (music will loop to match video duration)").requiredOption("--video <url>","Input video file/URL").option("--music <url>","Background music file/URL (will loop if shorter than video)").option("--voice <url>","Voiceover file/URL").option("--music-volume <percent>","Music volume 0-100 (default: 30, recommended for mix with voice)","30").option("--voice-volume <percent>","Voice volume 0-100","100").option("-o, --output <path>","Output file path").option("--no-wait","Do not wait for completion").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{!e.music&&!e.voice&&(c("At least one of --music or --voice must be provided"),process.exit(l.INVALID_INPUT));let n=parseInt(e.musicVolume,10)/100,t=parseInt(e.voiceVolume,10)/100;(Number.isNaN(n)||n<0||n>1)&&(c("Music volume must be between 0 and 100"),process.exit(l.INVALID_INPUT)),(Number.isNaN(t)||t<0||t>2)&&(c("Voice volume must be between 0 and 200"),process.exit(l.INVALID_INPUT));let o=e.format,r=o==="human"?zn("Mixing audio...").start():null,i=[{url:e.video,role:"video"}];e.music&&i.push({url:e.music,role:"background",volume:n*5}),e.voice&&i.push({url:e.voice,role:"voice",volume:t*2});try{let a=await Yo({operation:"add-to-video",inputs:i,options:{musicVolume:n,voiceVolume:t}});if(!e.wait){r?.stop(),Xn(a,o);return}r&&(r.text=`Processing (ID: ${a.requestId})...`);let s=await K(()=>hn(a.requestId),120,3e3);if(r?.stop(),s.status==="failed"&&(c(s.error||"Audio mixing failed"),process.exit(l.GENERAL_ERROR)),Xn(s,o),e.output){if(!s.outputUrl)throw new Error("Audio mix completed without an output URL");let d=o==="human"?zn("Downloading...").start():null;await Q(s.outputUrl,e.output),d?.stop(),o==="human"&&S(`Saved to: ${e.output}`)}}catch(a){r?.stop(),c(a instanceof Error?a.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),yd=new Yn("status").description("Check status of an audio mix request").argument("<id>","Request ID").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{let t=n.format==="human"?zn("Checking status...").start():null;try{let o=await hn(e);t?.stop(),Xn(o,n.format)}catch(o){t?.stop(),c(o instanceof Error?o.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),Ai=new Yn("mix").description("Audio mixing commands").addCommand(hd).addCommand(yd);import{Command as to}from"commander";import Zn from"ora";import{readFileSync as bd}from"fs";function Ei(e){let n;try{n=JSON.parse(bd(e,"utf8"))}catch(r){throw new Error(`Cannot read music plan ${e}: ${r instanceof Error?r.message:String(r)}`)}if(!Xt(n))throw new Error("Music plan must be a JSON object");if(Yt(n,["chunks"],"Music v2 plan"),!Array.isArray(n.chunks)||n.chunks.length===0)throw new Error("Music v2 plan must contain 1-30 chunks");if(n.chunks.length>30)throw new Error("Music v2 plan must contain 1-30 chunks");let t={chunks:n.chunks.map((r,i)=>wd(r,i))},o=t.chunks.reduce((r,i)=>r+Sd(i),0);if(o<3e3||o>6e5)throw new Error("Music plan total duration must be 3-600 seconds");return{compositionPlan:t,durationSeconds:o/1e3}}function wd(e,n){if(!Xt(e))throw new Error(`Music plan chunk ${n+1} must be an object`);let t=Kn(e,"songId","song_id"),o=Kn(e,"durationMs","duration_ms");return t&&!o?Oi(e,n):vd(e,n)}function vd(e,n){Yt(e,["text","durationMs","duration_ms","positiveStyles","positive_styles","negativeStyles","negative_styles","contextAdherence","context_adherence","conditioningRef","conditioning_ref","conditionStrength","condition_strength"],`Music plan chunk ${n+1}`);let t=Qn(e,"durationMs","duration_ms");if(t<3e3||t>12e4)throw new Error(`Music plan chunk ${n+1} duration must be 3000-120000 ms`);let o=Pi(e,"text");if(o.length>6e3)throw new Error(`Music plan chunk ${n+1} text exceeds 6000 characters`);let r=_i(e,"positiveStyles","positive_styles"),i=Cd(e,"negativeStyles","negative_styles"),a=$i(e,["low","medium","high"],"contextAdherence","context_adherence"),s=$i(e,["low","medium","high","xhigh"],"conditionStrength","condition_strength"),d=Ye(e,"conditioningRef","conditioning_ref"),u=d===void 0?void 0:Oi(d,n,!0);return{text:o,durationMs:t,positiveStyles:r,...i?{negativeStyles:i}:{},...a?{contextAdherence:a}:{},...u?{conditioningRef:u}:{},...s?{conditionStrength:s}:{}}}function Oi(e,n,t=!1){if(!Xt(e))throw new Error(`Music plan chunk ${n+1} reference must be an object`);Yt(e,["songId","song_id","range"],`Music plan chunk ${n+1} reference`);let o=Id(e,"songId","song_id");if(o.length>100)throw new Error(`Music plan chunk ${n+1} song ID exceeds 100 characters`);let r=Ye(e,"range");if(!Xt(r))throw new Error(`Music plan chunk ${n+1} range must be an object`);let i=xd(r,n);if(t&&i.endMs-i.startMs>3e4)throw new Error(`Music plan chunk ${n+1} conditioning reference cannot exceed 30000 ms`);return{songId:o,range:i}}function xd(e,n){Yt(e,["startMs","start_ms","endMs","end_ms"],`Music plan chunk ${n+1} range`);let t=Qn(e,"startMs","start_ms"),o=Qn(e,"endMs","end_ms");if(t<0||o-t<50)throw new Error(`Music plan chunk ${n+1} range must be non-negative and at least 50 ms`);return{startMs:t,endMs:o}}function Sd(e){return"durationMs"in e?e.durationMs:e.range.endMs-e.range.startMs}function Xt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Kn(e,...n){return n.some(t=>e[t]!==void 0)}function Ye(e,...n){let t=n.filter(o=>e[o]!==void 0);if(t.length>1)throw new Error(`Music plan cannot contain both ${t.join(" and ")}`);return t.length===1?e[t[0]]:void 0}function Pi(e,...n){let t=Ye(e,...n);if(typeof t!="string")throw new Error(`Music plan field ${n[0]} must be a string`);return t}function Id(e,...n){let t=Pi(e,...n).trim();if(!t)throw new Error(`Music plan field ${n[0]} must be a non-empty string`);return t}function Qn(e,...n){let t=Ye(e,...n);if(typeof t!="number"||!Number.isInteger(t))throw new Error(`Music plan field ${n[0]} must be an integer`);return t}function _i(e,...n){let t=Ye(e,...n);if(!Array.isArray(t)||t.length>50||t.some(o=>typeof o!="string"))throw new Error(`Music plan field ${n[0]} must be a string array with at most 50 entries`);return t}function Cd(e,...n){return Kn(e,...n)?_i(e,...n):void 0}function $i(e,n,...t){let o=Ye(e,...t);if(o!==void 0){if(typeof o!="string"||!n.includes(o))throw new Error(`Music plan field ${t[0]} must be one of ${n.join(", ")}`);return o}}function Yt(e,n,t){let o=Object.keys(e).filter(r=>!n.includes(r));if(o.length)throw new Error(`${t} contains unsupported field ${o[0]}`)}var Td=new Set(["auto","mp3_48000_128","mp3_48000_192","mp3_48000_240","mp3_48000_320","mp3_22050_32","mp3_24000_48","mp3_44100_32","mp3_44100_64","mp3_44100_96","mp3_44100_128","mp3_44100_192","pcm_8000","pcm_16000","pcm_22050","pcm_24000","pcm_32000","pcm_44100","pcm_48000","ulaw_8000","alaw_8000","opus_48000_32","opus_48000_64","opus_48000_96","opus_48000_128","opus_48000_192"]);function eo(e,n){if(n==="json"){let{cost:t,...o}=e;x(o);return}if(n==="quiet"){e.audioUrl?console.log(e.audioUrl):console.log(e.requestId);return}p(`Request ID: ${e.requestId}`),p(`Status: ${e.status}`),e.duration&&p(`Duration: ${e.duration}s`),e.audioUrl&&S(`Audio URL: ${e.audioUrl}`),e.cost!==void 0&&p(`Cost: $${e.cost.toFixed(4)}`),e.error&&c(`Error: ${e.error}`)}var Rd=new to("generate").description("Generate music from a text prompt or authored plan").option("-p, --prompt <text>","Music description").option("--plan <path>","Authored music-plan.json or Music v2 plan").option("-d, --duration <seconds>","Duration in seconds (3-600)").option("-s, --style <style>","Style preset").option("--provider <provider>","Untrusted provider hint (host policy is authoritative)").option("--mode <mode>","Intent: auto, retrieve, or generate","auto").option("--no-instrumental","Allow vocals (background music is instrumental by default)").option("--tempo <bpm>","Tempo hint in BPM (60-180)").option("--audio-format <format>","Audio format: mp3, wav, flac, ogg","mp3").option("--model-id <model>","ElevenLabs model: music_v1 or music_v2").option("--seed <integer>","ElevenLabs plan seed (0-2147483647)").option("--finetune-id <id>","ElevenLabs finetune ID").option("--output-format <format>","Exact ElevenLabs Compose output format").option("--respect-sections-durations","Pass ElevenLabs v1 section-duration control").option("--store-for-inpainting","Store the result for later inpainting").option("--sign-with-c2pa","Sign an MP3 result with C2PA metadata").option("-o, --output <path>","Output file path").option("--no-wait","Do not wait for completion").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{!!e.prompt==!!e.plan&&(c("Provide exactly one of --prompt or --plan"),process.exit(l.INVALID_INPUT));let n;try{n=e.plan?Ei(e.plan):void 0}catch(d){c(d instanceof Error?d.message:String(d)),process.exit(l.INVALID_INPUT)}let t=e.duration?Number(e.duration):n?.durationSeconds??30;(!Number.isFinite(t)||t<3||t>600)&&(c("Duration must be between 3 and 600 seconds (10 minutes)"),process.exit(l.INVALID_INPUT)),n&&n.durationSeconds!==t&&(c(`--duration (${t}s) must match the music plan total (${n.durationSeconds}s)`),process.exit(l.INVALID_INPUT)),!e.wait&&e.output&&(c("--output requires waiting for completion; remove --no-wait"),process.exit(l.INVALID_INPUT)),["auto","retrieve","generate"].includes(e.mode)||(c("Mode must be auto, retrieve, or generate"),process.exit(l.INVALID_INPUT)),["mp3","wav","flac","ogg"].includes(e.audioFormat)||(c("Audio format must be mp3, wav, flac, or ogg"),process.exit(l.INVALID_INPUT)),e.modelId!==void 0&&!["music_v1","music_v2"].includes(e.modelId)&&(c("Model ID must be music_v1 or music_v2"),process.exit(l.INVALID_INPUT)),n&&e.modelId&&e.modelId!=="music_v2"&&(c("Music v2 plans require --model-id music_v2"),process.exit(l.INVALID_INPUT));let o=e.seed===void 0?void 0:Number(e.seed);o!==void 0&&(!Number.isInteger(o)||o<0||o>2147483647)&&(c("Seed must be an integer between 0 and 2147483647"),process.exit(l.INVALID_INPUT)),!n&&o!==void 0&&(c("--seed requires --plan"),process.exit(l.INVALID_INPUT)),!n&&e.respectSectionsDurations&&(c("--respect-sections-durations requires --plan"),process.exit(l.INVALID_INPUT)),e.outputFormat!==void 0&&!Td.has(e.outputFormat)&&(c("Unsupported ElevenLabs output format"),process.exit(l.INVALID_INPUT)),e.signWithC2pa&&e.outputFormat!==void 0&&e.outputFormat!=="auto"&&!e.outputFormat.startsWith("mp3_")&&(c("--sign-with-c2pa requires an MP3 output format"),process.exit(l.INVALID_INPUT));let r=e.tempo?Number(e.tempo):void 0;r!==void 0&&(!Number.isInteger(r)||r<60||r>180)&&(c("Tempo must be between 60 and 180 BPM"),process.exit(l.INVALID_INPUT));let i=e.format,a=i==="human"?Zn("Generating music...").start():null,s;try{let d={finetuneId:e.finetuneId,outputFormat:e.outputFormat,storeForInpainting:e.storeForInpainting,signWithC2Pa:e.signWithC2pa},u=await Ct(n?{duration:t,options:{providerOptions:{elevenlabs:{compositionPlan:n.compositionPlan,modelId:"music_v2",seed:o,respectSectionsDurations:e.respectSectionsDurations,...d}}}}:{duration:t,prompt:e.prompt,options:{provider:e.provider,mode:e.mode,instrumental:e.instrumental,style:e.style,tempo:r,format:e.audioFormat,providerOptions:{elevenlabs:{forceInstrumental:e.instrumental,modelId:e.modelId,musicLengthMs:Math.round(t*1e3),...d}}}});if(s=u.requestId,!e.wait){a?.stop(),eo(u,i);return}let m=u;if(u.status!=="completed"&&u.status!=="failed"&&(a&&(a.text=`Processing (ID: ${u.requestId})...`),m=await K(()=>ct(u.requestId),180,2e3)),a?.stop(),m.status==="failed"&&(c(m.error||"Music generation failed"),process.exit(l.GENERAL_ERROR)),e.output){if(!m.audioUrl)throw new Error("Music completed without an audio URL");let b=i==="human"?Zn("Downloading...").start():null;await Q(m.audioUrl,e.output),b?.stop(),i==="human"&&S(`Saved to: ${e.output}`),m={...m,output:e.output}}eo(m,i)}catch(d){a?.stop(),c(le(d,s),i),process.exit(l.GENERAL_ERROR)}}),kd=new to("status").description("Check status of a music generation request").argument("<id>","Request ID").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{let t=n.format==="human"?Zn("Checking status...").start():null;try{let o=await ct(e);t?.stop(),eo(o,n.format)}catch(o){t?.stop(),c(o instanceof Error?o.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),Ni=new to("music").description("Music generation commands").addCommand(Rd).addCommand(kd);import{Command as no}from"commander";function Li(e,n){return[...n,e]}var Ad=new no("create").description("Create a standalone poll").argument("<question>","Poll question").option("--option <text>","Choice (repeat 2-10 times)",Li,[]).option("--type <type>","single, multiple, or word-cloud","single").option("--title <title>","Poll title").option("--team-id <id>","Workspace ID").option("--yes","Approve creation").action(async(e,n)=>{if(!n.yes)return c("Pass --yes to approve poll creation");try{x(await $("createPoll",{approvalReceipt:"cli:--yes",options:n.option.map(t=>({text:t})),pollType:n.type,question:e,teamId:n.teamId,title:n.title}))}catch(t){c(t instanceof Error?t.message:"Poll creation failed"),process.exit(l.GENERAL_ERROR)}}),$d=new no("edit").description("Edit a standalone poll").argument("<poll-id>","Poll UUID").option("--question <question>","New question").option("--option <text>","Replacement choice (repeat)",Li).option("--type <type>","single, multiple, or word-cloud").option("--title <title>","Poll title").option("--team-id <id>","Workspace ID").option("--yes","Approve update").action(async(e,n)=>{if(!n.yes)return c("Pass --yes to approve poll update");try{x(await $("editPoll",{approvalReceipt:"cli:--yes",options:n.option?.map(t=>({text:t})),pollId:e,pollType:n.type,question:n.question,teamId:n.teamId,title:n.title}))}catch(t){c(t instanceof Error?t.message:"Poll update failed"),process.exit(l.GENERAL_ERROR)}}),Di=new no("poll").description("Standalone poll commands").addCommand(Ad).addCommand($d);import{Command as Fi}from"commander";var Ed=new Fi("status").description("Check a presentation generation run").argument("<run-id>","Run ID returned by presentation generation").option("--team-id <id>","Workspace ID override").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{try{let t=await L("createSlides",e,n.teamId);if(n.format==="json"){x(t);return}if(n.format==="quiet"){console.log(t.status);return}p(`Status: ${t.status}`),p(t.message),t.progress!==null&&p(`Progress: ${t.progress}%`),t.error&&c(t.error.message)}catch(t){c(t instanceof Error?t.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),Ui=new Fi("presentation").description("Presentation background-run commands").addCommand(Ed);import{writeFile as Od}from"fs/promises";import{Command as Pd}from"commander";import _d from"ora";var Mi=new Pd("scrape").description("Extract content from a URL").argument("<url>","URL to scrape").option("--team-id <id>","Workspace ID").option("-o, --output <path>","Save content to file").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{let t=n.format,o=t==="human"?_d("Scraping URL...").start():null;try{let r=await Qo(e,n.teamId);o?.stop(),(!r.success||!r.data)&&(c(r.error||"Failed to scrape URL"),process.exit(l.GENERAL_ERROR));let i=r.data;if(n.output&&(await Od(n.output,i.content,"utf-8"),t==="human"&&S(`Content saved to: ${n.output}`)),t==="json"){let{cost:a,...s}=i;x(s);return}if(t==="quiet"){console.log(i.content);return}i.title&&(console.log(),console.log(`Title: ${i.title}`)),i.metadata?.description&&console.log(`Description: ${i.metadata.description}`),console.log(`URL: ${i.url}`),console.log(`Tokens: ~${i.metadata?.tokenUsage?.toLocaleString()||"unknown"}`),i.warning&&U(i.warning),n.output||(console.log(),console.log("--- Content ---"),console.log(i.content)),i.cost&&i.cost>0&&p(`Cost: $${i.cost.toFixed(6)}`)}catch(r){o?.stop(),c(r instanceof Error?r.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}});import{Command as mt}from"commander";function Kt(e,n){n!=="quiet"&&x(e)}var Nd=new mt("web").description("Search current public web sources").argument("<query>","Search query").option("--team-id <id>","Workspace ID").option("--max-results <count>","Maximum results","5").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{try{let t=await $("searchInternet",{maxResults:Number.parseInt(n.maxResults,10),query:e,teamId:n.teamId});Kt(t,n.format)}catch(t){c(t instanceof Error?t.message:"Search failed"),process.exit(l.GENERAL_ERROR)}}),Ld=new mt("news").description("Search recent news").argument("<topic>","News topic").option("--team-id <id>","Workspace ID").option("--timeframe <value>","Timeframe hint").option("--max-results <count>","Maximum results","6").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{try{let t=await $("getNews",{maxResults:Number.parseInt(n.maxResults,10),teamId:n.teamId,timeframe:n.timeframe,topic:e});Kt(t,n.format)}catch(t){c(t instanceof Error?t.message:"News search failed"),process.exit(l.GENERAL_ERROR)}});function Vi(e){let n=e?.trim().toLowerCase();if(!(!n||n==="any"||n==="all"))return n==="web"||n==="stock"?[n]:void 0}var Dd=new mt("images").description("Search images across the web and licensed stock").argument("<query>","Image search query").option("--team-id <id>","Workspace ID").option("--max-results <count>","Maximum results","10").option("--aspect <aspect>","Aspect: any, square, wide, tall","any").option("--source <source>","Catalog: web, stock, or any (default: any)","any").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{try{let t=await $("searchImages",{aspect:n.aspect,maxResults:Number.parseInt(n.maxResults,10),query:e,sources:Vi(n.source),teamId:n.teamId});Kt(t,n.format)}catch(t){c(t instanceof Error?t.message:"Image search failed"),process.exit(l.GENERAL_ERROR)}}),Fd=new mt("video").description("Search video across the web and licensed stock").argument("<query>","Video search query").option("--team-id <id>","Workspace ID").option("--max-results <count>","Maximum results","10").option("--source <source>","Catalog: web, stock, or any (default: any)","any").option("--orientation <value>","Orientation: landscape, portrait, square, any","any").option("--license <value>","License: free, premium, any","any").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{try{let t=await $("searchStockVideo",{license:n.license,maxResults:Number.parseInt(n.maxResults,10),orientation:n.orientation,query:e,sources:Vi(n.source),teamId:n.teamId});Kt(t,n.format)}catch(t){c(t instanceof Error?t.message:"Video search failed"),process.exit(l.GENERAL_ERROR)}}),ji=new mt("search").description("Web, news, image, and stock-video search").addCommand(Nd).addCommand(Ld).addCommand(Dd).addCommand(Fd);import{Command as io}from"commander";import oo from"ora";function ro(e,n){if(n==="json"){let{cost:t,...o}=e;x(o);return}if(n==="quiet"){e.audioUrl?console.log(e.audioUrl):e.requestId?console.log(e.requestId):console.log(e.id);return}p(`Request ID: ${e.requestId||e.id}`),p(`Status: ${e.status}`),e.duration&&p(`Duration: ${e.duration}s`),e.audioUrl&&S(`Audio URL: ${e.audioUrl}`),e.cost!==void 0&&p(`Cost: $${e.cost.toFixed(4)}`),e.error&&c(`Error: ${e.error}`)}var Ud=new io("generate").description("Generate sound effects from a text prompt").requiredOption("-t, --text <text>","Sound effect description (e.g., 'thunder rumbling, rain on window')").option("-d, --duration <seconds>","Duration in seconds (0.5-30)").option("-p, --provider <provider>","Untrusted provider hint (host policy is authoritative)").option("--prompt-influence <value>","How closely to follow prompt (0-1)","0.3").option("-l, --loop","Generate seamless looping audio",!1).option("--format <format>","Audio format: mp3, wav, ogg","mp3").option("-o, --output <path>","Output file path").option("--no-wait","Do not wait for completion").option("-f, --output-format <format>","Output format: human, json, quiet","human").action(async e=>{let n;e.duration&&(n=parseFloat(e.duration),(isNaN(n)||n<.5||n>30)&&(c("Duration must be between 0.5 and 30 seconds"),process.exit(l.INVALID_INPUT)));let t;e.promptInfluence&&(t=parseFloat(e.promptInfluence),(isNaN(t)||t<0||t>1)&&(c("Prompt influence must be between 0 and 1"),process.exit(l.INVALID_INPUT)));let o=e.outputFormat,r=o==="human"?oo("Generating sound effects...").start():null,i;try{let a=await Zo({text:e.text,duration:n,options:{provider:e.provider,promptInfluence:t,loop:e.loop,format:e.format}});if(i=a.requestId||a.id,!e.wait){r?.stop(),ro(a,o);return}let s=a;if(a.status!=="completed"&&a.status!=="failed"){let d=a.requestId||a.id;r&&(r.text=`Processing (ID: ${d})...`),s=await K(()=>bn(d),60,2e3)}if(r?.stop(),s.status==="failed"&&(c(s.error||"Sound effects generation failed"),process.exit(l.GENERAL_ERROR)),ro(s,o),e.output){if(!s.audioUrl)throw new Error("Sound effect completed without an audio URL");let d=o==="human"?oo("Downloading...").start():null;await Q(s.audioUrl,e.output),d?.stop(),o==="human"&&S(`Saved to: ${e.output}`)}}catch(a){r?.stop(),c(le(a,i),o),process.exit(l.GENERAL_ERROR)}}),Md=new io("status").description("Check status of a sound effects generation request").argument("<id>","Request ID").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{let t=n.format==="human"?oo("Checking status...").start():null;try{let o=await bn(e);t?.stop(),ro(o,n.format)}catch(o){t?.stop(),c(o instanceof Error?o.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),qi=new io("sfx").description("Sound effects generation commands").addCommand(Ud).addCommand(Md);import{mkdir as Vd,writeFile as Bi}from"fs/promises";import{dirname as jd}from"path";import{Command as Qt}from"commander";import Hi from"ora";var Gi="en-US-Neural2-C",Wi="gemini",qd=new Qt("generate").description("Generate speech from text").requiredOption("-t, --text <text>","Text to convert to speech").requiredOption("-o, --output <path>","Output file path").option("--voice-id <voiceId>","Voice ID (e.g., ElevenLabs: 21m00Tcm4TlvDq8ikWAM)").option("--voice <voice>",`Voice name (default: ${Gi})`).option("-p, --provider <provider>",`Provider: gemini, elevenlabs, openai (default: ${Wi})`).option("-m, --model <model>","Model (provider-specific)").option("-s, --speed <speed>","Speech speed 0.1-4.0 (default: 1.0)").option("-l, --lang <lang>","Language or locale hint (for example en-US)").option("--speakers <json>",`Multi-speaker (Gemini, max 2): '[{"name":"Joe","voice":"Kore"},{"name":"Jane","voice":"Puck"}]'`).option("-i, --instructions <text>","Style prompt (OpenAI gpt-4o-mini-tts): tone, accent, speed, emotion").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{let n=e.format,t=n==="human"?Hi("Generating speech...").start():null,o;e.speed&&(o=parseFloat(e.speed),(Number.isNaN(o)||o<.1||o>4)&&(t?.stop(),c("Speed must be between 0.1 and 4.0"),process.exit(l.INVALID_INPUT)));let r;if(e.speakers)try{r=JSON.parse(e.speakers),(!Array.isArray(r)||r.length===0||r.length>2||r.some(a=>!a||typeof a!="object"||typeof a.name!="string"||!a.name.trim()||typeof a.voice!="string"||!a.voice.trim()))&&(t?.stop(),c("Speakers must be an array with 1-2 name/voice items"),process.exit(l.INVALID_INPUT))}catch{t?.stop(),c(`Invalid --speakers JSON. Example: '[{"name":"Joe","voice":"Kore"}]'`),process.exit(l.INVALID_INPUT)}let i;try{let a=e.voiceId,s=e.voice||Gi,d=e.provider||Wi,u={};r&&(u.gemini={speakers:r}),e.instructions&&(u.openai={instructions:e.instructions});let m=await It({text:e.text,options:{language:e.lang,provider:d,voiceId:a,voice:s,model:e.model,speed:o,providerOptions:Object.keys(u).length>0?u:void 0}});i=m.requestId,t?.stop();let b=e.output.endsWith(`.${m.format}`)?e.output:`${e.output}.${m.format}`;await Vd(jd(b),{recursive:!0}),await Bi(b,m.audioData);let C=b.replace(/\.[^.]+$/,".txt");if(await Bi(C,e.text,"utf-8"),n==="json"){x({status:"completed",output:b,audioUrl:m.audioUrl,duration:m.duration,provider:m.provider,format:m.format,voice_id:m.voiceId??null,voice:m.voice??s,model:m.model??e.model??null,speed:m.speed??o??1,lang:m.language??e.lang??null,langApplied:m.langApplied??!1,timestamps:m.timestamps??null,words:m.wordTimings??null});return}if(n==="quiet"){console.log(b);return}S(`Saved to: ${b}`),p(`Duration: ${m.duration.toFixed(2)}s`),p(`Provider: ${m.provider}`),p(`Cost: $${m.cost.toFixed(6)}`)}catch(a){t?.stop(),c(le(a,i),n),process.exit(l.GENERAL_ERROR)}}),Bd=new Qt("voices").description("List available voices").option("-p, --provider <provider>","Filter by provider: gemini, elevenlabs, openai").option("-f, --format <format>","Output format: human, json","human").action(async e=>{let n=e.format==="human"?Hi("Fetching voices...").start():null;try{let t=await Xo(e.provider);if(n?.stop(),e.format==="json"){x(t.voices);return}if(Array.isArray(t.voices)){let o=e.provider?.toUpperCase()||"VOICES";console.log(),console.log(`${o} Voices:`),console.log("-".repeat(50));for(let r of t.voices)console.log(` ${r.name} (${r.id})`),console.log(` ${r.description}`)}else for(let[o,r]of Object.entries(t.voices))if(!(!r||r.length===0)){console.log(),console.log(`${o.toUpperCase()} Voices:`),console.log("-".repeat(50));for(let i of r)console.log(` ${i.name} (${i.id})`),console.log(` ${i.description}`)}}catch(t){n?.stop(),c(t instanceof Error?t.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),Gd=new Qt("status").description("Read speech generation status").argument("<run-id>","Run ID").option("--team-id <id>","Workspace ID").option("-f, --format <format>","Output format: json","json").action(async(e,n)=>{try{x(await L("generateSpeech",e,n.teamId))}catch(t){c(t instanceof Error?t.message:"Status failed"),process.exit(l.GENERAL_ERROR)}}),Ji=new Qt("tts").description("Text-to-speech commands").addCommand(qd).addCommand(Bd).addCommand(Gd);import{execSync as tt,spawn as wl,spawnSync as vl}from"child_process";import{access as co,mkdir as nt,readFile as ft,rm as lo,writeFile as ve}from"fs/promises";import{join as G,resolve as gt}from"path";import{Command as te}from"commander";import xl from"ffmpeg-static";import ht from"ora";import{homedir as Wd}from"os";import{join as zi}from"path";import{readdir as Hd}from"fs/promises";var Jd="conceptcraft";function Ke(){return zi(Wd(),`.${Jd}`,"projects")}function Zt(e){return zi(Ke(),e)}async function ao(){try{let e=Ke();return(await Hd(e,{withFileTypes:!0})).filter(t=>t.isDirectory()).map(t=>t.name)}catch{return[]}}function Xi(e,n){let t=2,o=`${e}-${t}`;for(;n.includes(o);)t++,o=`${e}-${t}`;return o}import{Command as zd}from"commander";import Xd from"ora";import{execSync as Yd,spawnSync as Qe}from"child_process";import{mkdirSync as Yi,existsSync as tn,readFileSync as Qi,writeFileSync as Ki}from"fs";import{join as Ee,basename as Kd}from"path";import{tmpdir as Qd}from"os";function nn(e,n){try{return Yd(n,{stdio:"ignore"}),!0}catch{return!1}}function en(e){let n=Math.floor(e/60),t=Math.floor(e%60),o=Math.round(e%1*10);return`${n}:${String(t).padStart(2,"0")}.${o}`}function Zd(e){let n=Qe("ffprobe",["-v","error","-show_entries","format=duration","-of","default=noprint_wrappers=1:nokey=1",e],{encoding:"utf-8"});return parseFloat(n.stdout.trim())}function el(e,n){let t=Qe("ffmpeg",["-i",e,"-vf",`select='gt(scene,${n})',showinfo`,"-vsync","vfr","-f","null","-"],{encoding:"utf-8",timeout:12e4}),o=[0],r=(t.stderr||"").split(`
|
|
3775
|
+
`);for(let i of r){let a=i.match(/pts_time:([\d.]+)/);if(a){let s=parseFloat(a[1]);s-o[o.length-1]>=1.5&&o.push(s)}}return o}function tl(e,n,t){let o=[];for(let r=0;r<n.length;r++){let i=n[r]+.5,a=Ee(t,`scene_${String(r+1).padStart(2,"0")}.jpg`);Qe("ffmpeg",["-ss",String(i),"-i",e,"-vframes","1","-q:v","2","-y",a],{stdio:"ignore",timeout:3e4}),o.push(a)}return o}function nl(e,n){let t=Ee(n,"audio.wav");if(Qe("ffmpeg",["-i",e,"-vn","-acodec","pcm_s16le","-ar","16000","-ac","1","-y",t],{stdio:"ignore",timeout:6e4}),!tn(t)||!nn("whisper","which whisper")&&!nn("whisper-cpp","which whisper-cpp"))return null;let r=Qe("whisper",[t,"--model","base","--output_format","json","--output_dir",n,"--language","en"],{encoding:"utf-8",timeout:3e5}),i=Ee(n,"audio.json");if(!tn(i))return null;try{let a=JSON.parse(Qi(i,"utf-8"));return{text:a.text||"",segments:(a.segments||[]).map(s=>({start:s.start,end:s.end,text:s.text?.trim()||""}))}}catch{return null}}function ol(e,n){let t=Qi(e).toString("base64"),o=JSON.stringify({model:n,prompt:"Describe this image in one short sentence (max 15 words). Focus on: what is shown, the setting, key objects or people.",images:[t],stream:!1}),r=Qe("curl",["-s","-X","POST","http://localhost:11434/api/generate","-H","Content-Type: application/json","-d",o],{encoding:"utf-8",timeout:6e4});try{return(JSON.parse(r.stdout).response||"").replace(/!!!IMAGE!!!/gi,"").replace(/\[image[^\]]*\]/gi,"").trim()||"Unable to describe frame"}catch{return"Unable to describe frame"}}var Zi=new zd("analyze").description("Analyze a video file: detect scenes, transcribe audio, describe frames").argument("<file>","Path to video file").option("-o, --output <path>","Output directory for analysis results").option("-t, --threshold <number>","Scene detection threshold (0-1, lower = more scenes)","0.3").option("-m, --model <name>","Ollama vision model","moondream").option("--no-vision","Skip frame description (faster)").option("--no-transcribe","Skip audio transcription").option("-f, --output-format <format>","Output format: human, json","human").action(async(e,n)=>{let t=Xd();tn(e)||(console.error(`File not found: ${e}`),process.exit(1)),nn("ffmpeg","which ffmpeg")||(console.error("ffmpeg is required. Install: brew install ffmpeg"),process.exit(1)),n.vision!==!1&&!nn("ollama","which ollama")&&(console.error("ollama is required for vision. Install: brew install ollama"),process.exit(1));let o=n.output||Ee(Qd(),`video-analyze-${Date.now()}`);Yi(o,{recursive:!0});let r=Ee(o,"frames");Yi(r,{recursive:!0});let i=parseFloat(n.threshold),a=n.model;t.start("Reading video metadata...");let s=Zd(e);t.succeed(`Video: ${en(s)} (${s.toFixed(1)}s)`),t.start("Detecting scenes...");let d=el(e,i);t.succeed(`Detected ${d.length} scenes`),t.start("Extracting key frames...");let u=tl(e,d,r);t.succeed(`Extracted ${u.length} key frames`);let m=null;n.transcribe!==!1&&(t.start("Transcribing audio..."),m=nl(e,o),m?t.succeed(`Transcribed: ${m.segments.length} segments`):t.warn("Transcription skipped (whisper not installed: pip install openai-whisper)"));let b=[];for(let g=0;g<d.length;g++){let T=d[g],v=g<d.length-1?d[g+1]:s,y="";n.vision!==!1&&tn(u[g])&&(t.start(`Describing scene ${g+1}/${d.length}...`),y=ol(u[g],a),t.succeed(`Scene ${g+1}: ${y}`)),b.push({id:g+1,startTime:T,endTime:v,duration:v-T,framePath:u[g],description:y})}let C={source:e,duration:s,scenes:b,transcript:m};if(n.outputFormat==="json"){let g=JSON.stringify(C,null,2),T=Ee(o,"analysis.json");Ki(T,g),console.log(g)}else{let g=["# Video Analysis","",`**Source:** ${Kd(e)}`,`**Duration:** ${en(s)} (${s.toFixed(1)}s)`,`**Scenes:** ${b.length}`,"","## Scenes",""];for(let y of b){if(g.push(`### Scene ${y.id} (${en(y.startTime)} - ${en(y.endTime)}) [${y.duration.toFixed(1)}s]`),y.description&&g.push(`**Visual:** ${y.description}`),m?.segments){let w=m.segments.filter(E=>E.end>y.startTime&&E.start<y.endTime);w.length>0&&g.push(`**Audio:** ${w.map(E=>E.text).join(" ").trim()}`)}g.push(`**Frame:** ${y.framePath}`),g.push("")}m?.text&&(g.push("## Full Transcript"),g.push(""),g.push(m.text.trim()),g.push(""));let T=g.join(`
|
|
3776
|
+
`),v=Ee(o,"analysis.md");Ki(v,T),console.log(T),console.log(`
|
|
3777
|
+
Results saved to: ${o}`)}});import{mkdir as rl}from"fs/promises";import{join as il}from"path";import{Command as pt}from"commander";import ta from"ora";var al=5e3,sl=120,ea=5;function cl(e,n){return[...n,e]}function dl(e,n){try{let t=new URL(e);if(t.protocol!=="https:"&&t.protocol!=="http:")throw new Error;return t.toString()}catch{throw new Error(`${n} must be a public HTTP(S) URL`)}}function na(e){if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e))throw new Error("Source video id must be a UUID");return e}function ll(e){if(e.mode&&!["speed","precision"].includes(e.mode))throw new Error("Lip-sync mode must be speed or precision");return{audioUrl:dl(e.audioUrl,"Audio URL"),...e.mode?{mode:e.mode}:{},sourceVideoId:na(e.sourceVideoId)}}function ul(e){let n=[],t=new Set;for(let r of e.targetLanguage){let i=r.trim(),a=i.toLocaleLowerCase("en-US");!i||t.has(a)||(t.add(a),n.push(i))}if(n.length===0)throw new Error("Provide at least one target language");if(n.length>ea)throw new Error(`Provide at most ${ea} target languages`);if(n.find(r=>r.length<2||r.length>40))throw new Error("Target languages must be between 2 and 40 characters");return{...e.captions?{captions:!0}:{},sourceVideoId:na(e.sourceVideoId),targetLanguages:n}}function ml(e){return e.error||e.status==="failed"||e.status==="cancelled"?"failed":e.done||e.status==="completed"?"completed":e.status==="in_progress"||e.status==="processing"?"processing":"pending"}function so(e){return{requestId:e.runId,status:ml(e),...e.entity?.url?{videoUrl:e.entity.url}:{},...e.output?{output:e.output}:{},...e.error?.message?{error:e.error.message}:{}}}function oa(e){return{requestId:e.runId,status:"pending"}}async function ra(e,n){return K(async()=>so(await L(e,n)),sl,al)}function Ze(e,n){if(n==="json"){x(e);return}if(n==="quiet"){console.log(e.videoUrl??e.requestId);return}p(`Request ID: ${e.requestId}`),p(`Status: ${e.status}`),e.videoUrl&&S(`Video URL: ${e.videoUrl}`),e.error&&c(`Error: ${e.error}`)}function pl(e){return Array.isArray(e?.languages)?e.languages.filter(n=>{if(!n||typeof n!="object"||Array.isArray(n))return!1;let t=n;return typeof t.language=="string"&&(t.status==="completed"||t.status==="failed")&&typeof t.videoId=="string"&&(t.videoUrl===null||typeof t.videoUrl=="string")}):[]}function gl(e){return`${e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"translation"}.mp4`}function fl(e,n){let t=gl(e);if(!n.has(t))return n.add(t),t;let o=t.slice(0,-4),r=2;for(;n.has(`${o}-${r}.mp4`);)r+=1;let i=`${o}-${r}.mp4`;return n.add(i),i}async function hl(e,n){let t=pl(e.output).filter(i=>i.status==="completed"&&!!i.videoUrl);if(t.length===0)throw new Error("Video translation completed without downloadable results");await rl(n,{recursive:!0});let o=[],r=new Set;for(let i of t){let a=il(n,fl(i.language,r));await Q(i.videoUrl,a),o.push({language:i.language,path:a})}return o}var yl=new pt("status").description("Check a video lip-sync request").argument("<id>","Request ID").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{try{Ze(so(await L("lipsyncVideo",e)),n.format)}catch(t){c(t instanceof Error?t.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),ia=new pt("lipsync").description("Re-voice a ready workspace video with a public audio URL").requiredOption("--source-video-id <uuid>","READY workspace video UUID").requiredOption("--audio-url <url>","Public replacement voice audio URL").option("--mode <mode>","Quality mode: speed or precision","speed").requiredOption("-o, --output <path>","Local output video path").option("--no-wait","Do not wait for completion").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{let n=e.format==="human"?ta("Starting video lip-sync...").start():null,t;try{let o=await nr(ll(e));if(t=o.runId,!e.wait){n?.stop(),Ze(oa(o),e.format);return}n&&(n.text="Waiting for video lip-sync...");let r=await ra("lipsyncVideo",o.runId);if(r.status==="failed")throw new Error(r.error??"Video lip-sync failed");if(!r.videoUrl)throw new Error("Video lip-sync completed without a video URL");n&&(n.text="Downloading lip-synced video..."),await Q(r.videoUrl,e.output),n?.stop(),Ze(r,e.format),e.format==="human"&&S(`Saved to: ${e.output}`)}catch(o){n?.stop(),c(le(o,t),e.format),process.exit(l.GENERAL_ERROR)}}).addCommand(yl),aa=new pt("translate-languages").description("List supported video translation target languages").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{try{let n=await or();if(e.format==="json")x({languages:n});else for(let t of n)console.log(t)}catch(n){c(n instanceof Error?n.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),bl=new pt("status").description("Check a video translation request").argument("<id>","Request ID").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{try{Ze(so(await L("translateVideo",e)),n.format)}catch(t){c(t instanceof Error?t.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),sa=new pt("translate").description("Translate a ready workspace video into one or more languages").requiredOption("--source-video-id <uuid>","READY workspace video UUID").option("--target-language <language>","Target language (repeatable)",cl,[]).option("--captions","Burn provider-generated captions into translated videos").requiredOption("--output-dir <path>","Directory for translated videos").option("--no-wait","Do not wait for completion").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{let n=e.format==="human"?ta("Starting video translation...").start():null,t;try{let o=await rr(ul(e));if(t=o.runId,!e.wait){n?.stop(),Ze(oa(o),e.format);return}n&&(n.text="Waiting for video translations...");let r=await ra("translateVideo",o.runId);if(r.status==="failed")throw new Error(r.error??"Video translation failed");n&&(n.text="Downloading translated videos...");let i=await hl(r,e.outputDir);if(n?.stop(),e.format==="json")x({...r,downloads:i});else if(e.format==="quiet")for(let a of i)console.log(a.path);else{Ze(r,e.format);for(let a of i)S(`${a.language}: ${a.path}`)}}catch(o){n?.stop(),c(le(o,t),e.format),process.exit(l.GENERAL_ERROR)}}).addCommand(bl);var Sl="inizio-inc/remotion-video-template#main",et=30;async function uo(e){let n=await ft(e,"utf-8");return JSON.parse(n)}async function Il(e){let n=G(e,"template.manifest.json");try{return await uo(n)}catch{return{entry:"src/Root.tsx",compositions:[{id:"Main",type:"youtube",aspect:"16:9",default:!0}]}}}function ca(){try{return tt("bun --version",{stdio:"ignore"}),!0}catch{return!1}}function Cl(e){if(e.includes("---")||e.includes("[Section")){let r=e.split(/---|\[Section \d+\]/i).filter(i=>i.trim());if(r.length>1)return r.map(i=>i.trim())}let n=e.split(/(?<=[.!?])\s+/).map(r=>r.trim()).filter(r=>r.length>0),t=[],o="";for(let r of n){let i=r.split(/\s+/).length;o?(t.push(`${o} ${r}`),o=""):i<5&&t.length<n.length-1?o=r:t.push(r)}return o&&(t.length>0?t[t.length-1]+=` ${o}`:t.push(o)),t}function Tl(e,n,t=et,o){if(o&&o.characters.length>0)return Rl(e,o,t);let r=e.reduce((a,s)=>a+s.split(/\s+/).length,0),i=0;return e.map((a,s)=>{let d=a.split(/\s+/).length,u=d/r,m=n*u,b=Math.round(m*t),C=a.split(""),g=m/C.length,T={characters:C,characterStartTimesSeconds:C.map((y,w)=>w*g),characterEndTimesSeconds:C.map((y,w)=>(w+1)*g)},v={id:s+1,text:a,wordCount:d,startTime:i,endTime:i+m,durationInSeconds:m,durationInFrames:b,timestamps:T};return i+=m,v})}function Rl(e,n,t){let{characters:o,characterStartTimesSeconds:r,characterEndTimesSeconds:i}=n,a=o.join(""),s=[],d=0;for(let u=0;u<e.length;u++){let m=e[u],b=m.length;for(;d<o.length&&o[d].match(/^\s*$/);)d++;let C=d,g=r[C]||0;d+=b;let T=d-1;for(;T>C&&o[T]?.match(/^\s*$/);)T--;let v=i[Math.min(T,i.length-1)]||g+1,y=v-g,w=Math.round(y*t),E={characters:o.slice(C,T+1),characterStartTimesSeconds:r.slice(C,T+1).map(A=>A-g),characterEndTimesSeconds:i.slice(C,T+1).map(A=>A-g)};s.push({id:u+1,text:m,wordCount:m.split(/\s+/).length,startTime:g,endTime:v,durationInSeconds:y,durationInFrames:w,timestamps:E})}return s}function kl(e){let n=e==="tiktok"?"vertical":e==="audiogram"?"square":"widescreen";return{scenes:[{name:"Hook",script:"Replace this with a bold opening line that grabs attention.",imageQuery:`cinematic ${n} intro visual, dramatic lighting`,videoQuery:`abstract ${n} motion background`},{name:"Proof",script:"Share the core insight, benefit, or product moment you want viewers to remember.",imageQuery:`people collaborating ${n} office, warm lighting`,videoQuery:`close-up hands using technology ${n}`},{name:"Close",script:"End with a crisp call to action and a confident closing line.",imageQuery:`bold typography ${n} background, high contrast`,videoQuery:`sunrise skyline ${n} timelapse`}],voice:"en-US-Neural2-C",voiceSettings:{speed:1,stability:.4,style:.6},musicPrompt:"uplifting cinematic background, modern and confident"}}async function Al(e,n,t){let o=G(e,"public"),r=G(e,"scripts");await nt(o,{recursive:!0}),await nt(r,{recursive:!0});let i=G(o,"scenes.json");await ve(i,JSON.stringify(kl(n),null,2),"utf-8");let a=`import { execSync } from "node:child_process";
|
|
3778
3778
|
|
|
3779
3779
|
execSync("${t} video generate plan --project .", { stdio: "inherit" });
|
|
3780
3780
|
`,s=`import { execSync } from "node:child_process";
|
|
3781
3781
|
|
|
3782
3782
|
const args = process.argv.slice(2).join(" ");
|
|
3783
3783
|
execSync("${t} video export --project . " + args, { stdio: "inherit" });
|
|
3784
|
-
`;await ve(G(r,"plan.ts"),a,"utf-8"),await ve(G(r,"export.ts"),s,"utf-8")}async function Yi(){return process.stdin.isTTY?null:new Promise(e=>{let n="",t=!1;process.stdin.setEncoding("utf-8"),process.stdin.on("data",o=>{n+=o}),process.stdin.on("end",()=>{t||(t=!0,e(n.trim()||null))}),process.stdin.on("error",()=>{t||(t=!0,e(null))}),setTimeout(()=>{!t&&!n&&(t=!0,e(null))},500)})}function sl(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function cl(e){let n={shortTitle:"Video",elements:[],audio:[],text:[],scenes:[]},t=!0;return e.forEach(o=>{let r=o.startTime*1e3,i=o.endTime*1e3,a=o.durationInSeconds*1e3;n.scenes.push({name:o.name||`Scene ${o.id}`,text:o.text,startMs:r,endMs:i}),o.imagePath?(n.elements.push({startMs:r,endMs:i,imageUrl:o.imagePath,enterTransition:"blur",exitTransition:"blur",animations:[{type:"scale",from:t?1.3:1,to:t?1:1.3,startMs:0,endMs:a}]}),t=!t):o.videoPath&&n.elements.push({startMs:r,endMs:i,videoUrl:o.videoPath,enterTransition:"blur",exitTransition:"blur",animations:[]}),o.audioPath&&n.audio.push({startMs:r,endMs:i,audioUrl:o.audioPath}),o.timestamps&&n.text.push({startMs:r,endMs:i,text:o.text,position:"bottom",animations:[],timestamps:o.timestamps})}),n}async function nn(e,n){if(e.startsWith("data:")){let r=e.match(/^data:[^;]+;base64,(.+)$/);if(!r)throw new Error("Invalid data URL format");let i=Buffer.from(r[1],"base64");await ve(n,i);return}let t=await fetch(e);if(!t.ok)throw new Error(`Failed to download: ${t.status}`);let o=await t.arrayBuffer();await ve(n,Buffer.from(o))}function dl(e){try{let o=new URL(e).pathname.split(".").pop()?.toLowerCase();if(o&&["jpg","jpeg","png","gif","webp"].includes(o))return o}catch{}return"jpg"}var ll=new te("assets").description("Generate assets (voiceover per scene, music, images, video)").option("-s, --script <text>","Narration script (legacy single-script mode)").option("--script-file <path>","Path to script file (legacy) or scenes JSON").option("--scenes <path>","Path to scenes.json (defaults to <project>/public/scenes.json)").option("-p, --project <dir>","Project directory (defaults to current directory; uses <dir>/public for output)").option("-t, --topic <text>","Topic for image search").option("-v, --voice <name>","TTS voice ID (ElevenLabs: Rachel, Josh, Adam; OpenAI: alloy, nova; Gemini: Kore, Puck)").option("-m, --music-prompt <text>","Music description").option("-n, --num-images <number>","Number of images to search/download","5").option("-o, --output <dir>","Output directory","./public").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{let n=e.format,t=n==="human"?ft("Initializing...").start():null,o=e.project?pt(process.cwd(),e.project):null;try{let r=await Yi(),i=null;if(e.scenes&&!e.scriptFile&&(e.scriptFile=e.scenes),o&&(e.output=G(o,"public"),e.scriptFile?e.scriptFile=pt(o,e.scriptFile):!e.script&&!r&&(e.scriptFile=G(o,"public","scenes.json"))),r)try{let k=JSON.parse(r);k.scenes&&Array.isArray(k.scenes)&&(i=k)}catch{}if(!i&&e.scriptFile)try{let k=await gt(e.scriptFile,"utf-8"),J=JSON.parse(k);J.scenes&&Array.isArray(J.scenes)&&(i=J)}catch{}let a=i?.voice||e.voice,s=i?.voiceId,d=i?.provider,u=i?.model,p=i?.voiceInstructions,w=i?.musicPrompt||e.musicPrompt||"uplifting background music, positive energy",I=i?.musicDuration,f=G(e.output,"audio"),T=G(e.output,"images"),b=G(e.output,"videos");t&&(t.text="Creating directories..."),await et(f,{recursive:!0}),await et(T,{recursive:!0}),await et(b,{recursive:!0});let y=0,v=[],E=0,A=[],N=[];if(i&&i.scenes.length>0){n==="human"&&(t?.stop(),m(`Processing ${i.scenes.length} scenes...`),t?.start());let k=i.scenes.map((re,B)=>{let ye=re.script;return re.voiceStyle&&(ye=`${re.voiceStyle} ${ye}`),{text:ye,id:`scene-${B}`}});t&&(t.text="Generating speech for all scenes...");let J=await jo({texts:k,options:{provider:d,voice:a,voiceId:s,model:u,voiceSettings:i.voiceSettings,instructions:p}});y+=J.totalCost;let oe=0;for(let re=0;re<i.scenes.length;re++){let B=i.scenes[re],ye=sl(B.name),me=J.results[re];t&&(t.text=`[${B.name}] Saving audio...`);let sn=G(f,`${ye}.${me.format}`);await ve(sn,me.audioData);let Oe=me.duration,ra=Math.round(Oe*Qe),nt={id:re+1,name:B.name,text:B.script,wordCount:B.script.split(/\s+/).length,startTime:oe,endTime:oe+Oe,durationInSeconds:Oe,durationInFrames:ra,audioPath:`audio/${ye}.${me.format}`,timestamps:me.timestamps};if(B.imageQuery){t&&(t.text=`[${B.name}] Searching image...`);try{let Z=await Rt({query:B.imageQuery,options:{maxResults:1,size:"large",safeSearch:!0}}),ot=Z.data.results.flatMap(X=>X.results);if(y+=Z.data.totalCost,ot.length>0){let X=ot[0],rt=dl(X.url),Ie=`${ye}.${rt}`,cn=G(T,Ie);await nn(X.url,cn),nt.imagePath=`images/${Ie}`,A.push({path:`images/${Ie}`,url:X.url,width:X.width,height:X.height,query:B.imageQuery})}}catch(Z){n==="human"&&(t?.stop(),_(`[${B.name}] Image search failed: ${Z instanceof Error?Z.message:"Unknown"}`),t?.start())}}if(B.videoQuery){t&&(t.text=`[${B.name}] Searching video...`);try{let Z=await hn({query:B.videoQuery,options:{maxResults:1,license:"free"}}),ot=Z.data.results.flatMap(X=>X.results);if(y+=Z.data.totalCost,ot.length>0){let X=ot[0],rt=X.previewUrl||X.downloadUrl;if(rt){let Ie=`${ye}.mp4`,cn=G(b,Ie);await nn(rt,cn),nt.videoPath=`videos/${Ie}`,N.push({path:`videos/${Ie}`,url:rt,width:X.width,height:X.height,duration:X.duration,query:B.videoQuery})}}}catch(Z){n==="human"&&(t?.stop(),_(`[${B.name}] Video search failed: ${Z instanceof Error?Z.message:"Unknown"}`),t?.start())}}if(v.push(nt),oe+=Oe,E+=Oe,n==="human"){t?.stop();let Z=[`audio: ${Oe.toFixed(1)}s`,nt.imagePath?"image":null,nt.videoPath?"video":null].filter(Boolean).join(", ");S(` ${B.name}: ${Z}`),t?.start()}}}else{let k=e.script;if(e.scriptFile)try{k=await gt(e.scriptFile,"utf-8")}catch(me){t?.stop(),c(`Failed to read script file: ${me instanceof Error?me.message:"Unknown error"}`),process.exit(l.INVALID_INPUT)}(!k||k.trim().length===0)&&(t?.stop(),c("Provide scenes via stdin JSON, --scenes/--script-file with scenes JSON, or --script for legacy mode"),process.exit(l.INVALID_INPUT)),k=k.trim();let J=e.topic||k.split(".")[0].slice(0,50);t&&(t.text="Generating voiceover...");let oe=await It({text:k,options:{voice:a}}),re=G(f,`voiceover.${oe.format}`);await ve(re,oe.audioData),y+=oe.cost,E=oe.duration;let B=nl(k);v=ol(B,oe.duration,Qe,oe.timestamps).map((me,sn)=>({...me,name:`Section${sn+1}`,audioPath:`audio/voiceover.${oe.format}`})),n==="human"&&(t?.stop(),S(`Voiceover: ${re} (${oe.duration.toFixed(1)}s)`),t?.start())}t&&(t.text="Creating timeline...");let C=cl(v),M=Math.max(C.audio.length>0?Math.max(...C.audio.map(k=>k.endMs)):0,C.text.length>0?Math.max(...C.text.map(k=>k.endMs)):0,C.elements.length>0?Math.max(...C.elements.map(k=>k.endMs)):0),q=M/1e3,ne=I?Math.min(300,Math.max(3,I)):Math.min(300,Math.ceil(q));console.log("[Music Generation] Requesting music:",{prompt:w,requestedDuration:ne,totalAudioDuration:E,actualVideoDuration:q,timelineDurationMs:M});let tt,on;t&&(t.text="Generating music and thumbnail...");let ta=`YouTube thumbnail style: BIG BOLD short headline text (like "$50K/MONTH"), dramatic engaging scene, arrows pointing to key elements, high contrast, vibrant colors, clean composition, 16:9. Video context: ${v.map(k=>k.text).join(" ")}`,rn=[],na=(async()=>{if(ne<3)return n==="human"&&(t?.stop(),_(`Video duration (${q.toFixed(1)}s) is too short for music generation (minimum 3s).`),t?.start()),null;try{let k=await Tt({prompt:w,duration:ne});if(k.status!=="completed"&&k.status!=="failed"&&(k=await K(()=>st(k.requestId),60,2e3)),k.status==="failed")throw new Error(k.error||"Unknown error");let J=G(f,"music.mp3");return k.audioUrl&&await nn(k.audioUrl,J),{path:"audio/music.mp3",duration:k.duration||ne,prompt:w,cost:k.cost||0}}catch(k){return n==="human"&&(t?.stop(),_(`Music generation failed: ${k.message}`),t?.start()),null}})();rn.push(na);let oa=(async()=>{try{let k=await Go({prompt:ta,options:{width:1280,height:720}});if(k.success&&k.data.url){let J=G(e.output,"thumbnail.jpg");return await nn(k.data.url,J),y+=k.data.cost||0,J}return null}catch(k){return n==="human"&&(t?.stop(),_(`Thumbnail generation failed: ${k.message}`),t?.start()),null}})();rn.push(oa);let[Ee,lo]=await Promise.all(rn);Ee&&(tt=Ee,y+=Ee.cost||0,n==="human"&&(t?.stop(),S(`Music: ${G(f,"music.mp3")} (${Ee.duration}s)`),Ee.duration<q&&_(`Music duration (${Ee.duration.toFixed(1)}s) is shorter than video duration (${q.toFixed(1)}s).`),t?.start())),lo&&(on=lo,n==="human"&&(t?.stop(),S(`Thumbnail: ${on}`),t?.start())),t&&(t.text="Writing manifest...");let uo=Math.round(q*Qe),mo={music:tt,thumbnail:on?"thumbnail.jpg":void 0,images:A,videos:N,scenes:v,timeline:C,totalDurationInFrames:uo,fps:Qe,totalCost:y,createdAt:new Date().toISOString()},an=G(e.output,"video-manifest.json");if(await ve(an,JSON.stringify(mo,null,2)),t?.stop(),n==="json"){let{totalCost:k,...J}=mo;x(J);return}if(n==="quiet"){console.log(an);return}console.log(),S("Video assets created successfully!"),console.log(),m(`Scenes: ${v.length} (${uo} frames at ${Qe}fps)`);for(let k of v){let J=[k.audioPath?"audio":null,k.imagePath?"image":null,k.videoPath?"video":null].filter(Boolean).join(", ");m(` - ${k.name}: ${k.durationInSeconds.toFixed(1)}s [${J}]`)}m(`Music: ${tt?.path} (${tt?.duration}s)`),m(`Manifest: ${an}`),console.log(),m(`Total cost: $${y.toFixed(4)}`)}catch(r){t?.stop(),c(r instanceof Error?r.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),ul=new te("find").description("Find stock video clips (supporting)").argument("<query>","Search query").option("-n, --max-results <count>","Maximum number of results","10").option("-o, --orientation <type>","Video orientation: landscape, portrait, square, any","any").option("-l, --license <type>","License type: free, premium, any","free").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{let{maxResults:t,orientation:o,license:r,format:i}=n,a=i==="human"?ft("Finding videos...").start():null;try{let s=await hn({query:e,options:{maxResults:parseInt(t,10),orientation:o,license:r}});a?.stop();let d=s.data.results.flatMap(u=>u.results);if(i==="json"){let{totalCost:u,...p}=s.data;x({...s,data:p});return}if(i==="quiet"){d.forEach(u=>{console.log(u.previewUrl||u.thumbnailUrl)});return}if(d.length===0){m("No videos found");return}S(`Found ${d.length} videos for "${e}"`),console.log(),d.forEach((u,p)=>{console.log(`[${p+1}] ${u.title}`),console.log(` URL: ${u.previewUrl||u.thumbnailUrl}`),console.log(` Duration: ${u.duration}s | Size: ${u.width}x${u.height}`),console.log(` Provider: ${u.provider}`),console.log()}),m(`Total cost: $${s.data.totalCost.toFixed(4)}`)}catch(s){a?.stop(),c(s instanceof Error?s.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),ml=new te("new").description("Create a new video project from a template").argument("<name>","Project directory name").option("-t, --template <repo>","GitHub repo (user/repo#commit)",Zd).option("--type <type>","Video type: youtube (16:9), tiktok (9:16), or audiogram (1:1)","youtube").option("--no-install","Skip dependency install").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{let t=n.format,o=t==="human"?ft("Initializing video project...").start():null;try{let r=Xe();await et(r,{recursive:!0});let i=Qt(e),a=n.type,s=await oo();if(s.includes(e)){let f=Ui(e,s);o?.stop(),c(`Project "${e}" already exists at: ${i}`),m(`Try: ${g.commands[0]} video generate new ${f}`),process.exit(l.INVALID_INPUT)}/^[a-zA-Z0-9_-]+\/[a-zA-Z0-9_.-]+(#[a-zA-Z0-9_./-]+)?$/.test(n.template)||(o?.stop(),c(`Invalid template format: "${n.template}". Expected format: owner/repo or owner/repo#branch`),process.exit(l.INVALID_INPUT)),["youtube","tiktok","audiogram"].includes(a)||(o?.stop(),c(`Invalid type "${a}". Use youtube, tiktok, or audiogram.`),process.exit(l.INVALID_INPUT)),o&&(o.text=`Cloning template from ${n.template}...`);let[u,p]=n.template.split("#"),w=p?`-b ${p}`:"";try{Ze(`git clone ${w} --depth 1 https://github.com/${u}.git "${i}"`,{stdio:"pipe"}),await ao(G(i,".git"),{recursive:!0,force:!0})}catch(f){o?.stop(),c(`Failed to clone template: ${f instanceof Error?f.message:"Unknown error"}`),process.exit(l.GENERAL_ERROR)}t==="human"&&(o?.stop(),S(`Template downloaded to ${e}/`),o?.start());let I;try{I=await tl(i)}catch{o?.stop(),c("template.manifest.json not found or invalid in template repo"),process.exit(l.INVALID_INPUT)}if(I.propsSchema&&I.propsSchema!=="video-plan.v1"&&(o?.stop(),c(`Template propsSchema must be video-plan.v1 (found ${I.propsSchema})`),process.exit(l.INVALID_INPUT)),o&&(o.text="Writing scaffold files..."),await al(i,a,g.commands[0]),n.install){let f=Xi()?"bun":"npm";o&&(o.text=`Installing dependencies with ${f}...`),await new Promise((T,b)=>{let y=Yd(f,["install"],{cwd:i,stdio:"pipe",shell:!0});y.on("close",v=>{v===0?T():b(new Error(`${f} install failed with code ${v}`))}),y.on("error",b)}),t==="human"&&(o?.stop(),S("Dependencies installed"),o?.start())}if(o?.stop(),t==="json"){x({name:e,path:i,template:n.template,type:a,installed:n.install});return}if(t==="quiet"){console.log(i);return}console.log(),S(`Video project "${e}" created successfully!`),m(`Location: ${i}`),a==="tiktok"?m("Format: TikTok/Reels/Shorts (1080x1920 @ 30fps)"):a==="audiogram"?m("Format: Audiogram (1080x1080 @ 30fps)"):m("Format: YouTube (1920x1080 @ 30fps)"),console.log(),m("Next steps:"),m(` cd ${i}`),n.install||m(` ${Xi()?"bun":"npm"} install`),m(" bun run dev # Preview in Remotion Studio"),m(` ${g.commands[0]} video generate assets --scenes public/scenes.json`),m(` ${g.commands[0]} video generate plan`)}catch(r){o?.stop(),c(r instanceof Error?r.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),pl=new te("plan").description("Generate video plan from context (via stdin or --context)").option("-c, --context <text>","Context for plan generation").option("-o, --output <path>","Save plan to file").option("-b, --branding <path>","Branding JSON file to include").option("--render-target <target>","Plan target: hyperframes or remotion","hyperframes").option("--no-wait","Return the background run ID immediately").action(async e=>{let n=ft("Generating video plan...").start();try{let t=e.context;if(!t){let d=await Yi();d&&(t=d)}t||(n.stop(),c("Provide context via stdin or --context flag"),process.exit(l.INVALID_INPUT));let o;if(e.branding)try{o=await gt(e.branding,"utf-8")}catch{n.stop(),c(`Could not read branding file: ${e.branding}`),process.exit(l.INVALID_INPUT)}let r=e.renderTarget==="remotion"?"remotion":"hyperframes",i={context:t,branding:o,renderTarget:r};if(e.wait===!1){n.stop(),x(await wn(i));return}let a=await Zo(i);n.stop(),a.success||(c(a.error||"Failed to generate plan"),process.exit(l.GENERAL_ERROR));let s=a.data;e.output?(await ve(e.output,s),S(`Plan saved to ${e.output}`)):console.log(s)}catch(t){n.stop(),c(t instanceof Error?t.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),gl=new te("generate").description("Generate parts of a video project").addCommand(ml).addCommand(ll).addCommand(pl),fl=new te("create").description("Start background standalone video generation").argument("<title>","Video title").requiredOption("--brief <brief>","Video brief").option("--topic <topic>","Video topic").option("--duration <seconds>","Duration in seconds","30").option("--format <format>","tiktok, instagram_reel, or youtube_short","tiktok").option("--team-id <id>","Workspace ID").option("--yes","Approve generation").action(async(e,n)=>{if(!n.yes)return c("Pass --yes to approve video generation");try{x(await Qo({brief:n.brief,durationSec:Number(n.duration),format:n.format,title:e,topic:n.topic}))}catch(t){c(t instanceof Error?t.message:"Generation failed"),process.exit(l.GENERAL_ERROR)}}),Ki=new te("plan").description("Start background video-plan generation").requiredOption("--context <brief>","Video brief (minimum 100 characters)").option("--branding <path>","Branding JSON file").option("--render-target <target>","hyperframes or remotion","hyperframes").option("--yes","Approve generation").action(async e=>{if(!e.yes)return c("Pass --yes to approve plan generation");try{let n=e.branding?await gt(e.branding,"utf-8"):void 0;x(await wn({branding:n,context:e.context,renderTarget:e.renderTarget==="remotion"?"remotion":"hyperframes"}))}catch(n){c(n instanceof Error?n.message:"Plan generation failed"),process.exit(l.GENERAL_ERROR)}}),hl=new te("status").description("Read video or video-plan background status").argument("<run-id>","Run ID").option("--plan","Read a video-plan run").option("--team-id <id>","Workspace ID").action(async(e,n)=>{try{x(await L(n.plan?"generateVideoPlan":"createVideo",e,n.teamId))}catch(t){c(t instanceof Error?t.message:"Status failed"),process.exit(l.GENERAL_ERROR)}}),yl=new te("status").description("Read video-plan background status").argument("<run-id>","Run ID").option("--team-id <id>","Workspace ID").action(async(e,n)=>{try{x(await L("generateVideoPlan",e,n.teamId))}catch(t){c(t instanceof Error?t.message:"Status failed"),process.exit(l.GENERAL_ERROR)}});Ki.addCommand(yl);var bl=new te("projects").description("List all video projects").option("-f, --format <format>","Output format: human, json","human").action(async e=>{let n=await oo();if(e.format==="json"){x({projectsDir:Xe(),projects:n.map(t=>({name:t,path:Qt(t)}))});return}if(n.length===0){m("No video projects found"),m(`Projects are stored in: ${Xe()}`);return}console.log(`
|
|
3785
|
-
Video Projects:`),console.log("-".repeat(50));for(let t of n)console.log(` ${t}`),console.log(` ${
|
|
3784
|
+
`;await ve(G(r,"plan.ts"),a,"utf-8"),await ve(G(r,"export.ts"),s,"utf-8")}async function da(){return process.stdin.isTTY?null:new Promise(e=>{let n="",t=!1;process.stdin.setEncoding("utf-8"),process.stdin.on("data",o=>{n+=o}),process.stdin.on("end",()=>{t||(t=!0,e(n.trim()||null))}),process.stdin.on("error",()=>{t||(t=!0,e(null))}),setTimeout(()=>{!t&&!n&&(t=!0,e(null))},500)})}function $l(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function El(e){let n={shortTitle:"Video",elements:[],audio:[],text:[],scenes:[]},t=!0;return e.forEach(o=>{let r=o.startTime*1e3,i=o.endTime*1e3,a=o.durationInSeconds*1e3;n.scenes.push({name:o.name||`Scene ${o.id}`,text:o.text,startMs:r,endMs:i}),o.imagePath?(n.elements.push({startMs:r,endMs:i,imageUrl:o.imagePath,enterTransition:"blur",exitTransition:"blur",animations:[{type:"scale",from:t?1.3:1,to:t?1:1.3,startMs:0,endMs:a}]}),t=!t):o.videoPath&&n.elements.push({startMs:r,endMs:i,videoUrl:o.videoPath,enterTransition:"blur",exitTransition:"blur",animations:[]}),o.audioPath&&n.audio.push({startMs:r,endMs:i,audioUrl:o.audioPath}),o.timestamps&&n.text.push({startMs:r,endMs:i,text:o.text,position:"bottom",animations:[],timestamps:o.timestamps})}),n}async function on(e,n){if(e.startsWith("data:")){let r=e.match(/^data:[^;]+;base64,(.+)$/);if(!r)throw new Error("Invalid data URL format");let i=Buffer.from(r[1],"base64");await ve(n,i);return}let t=await fetch(e);if(!t.ok)throw new Error(`Failed to download: ${t.status}`);let o=await t.arrayBuffer();await ve(n,Buffer.from(o))}function Ol(e){try{let o=new URL(e).pathname.split(".").pop()?.toLowerCase();if(o&&["jpg","jpeg","png","gif","webp"].includes(o))return o}catch{}return"jpg"}var Pl=new te("assets").description("Generate assets (voiceover per scene, music, images, video)").option("-s, --script <text>","Narration script (legacy single-script mode)").option("--script-file <path>","Path to script file (legacy) or scenes JSON").option("--scenes <path>","Path to scenes.json (defaults to <project>/public/scenes.json)").option("-p, --project <dir>","Project directory (defaults to current directory; uses <dir>/public for output)").option("-t, --topic <text>","Topic for image search").option("-v, --voice <name>","TTS voice ID (ElevenLabs: Rachel, Josh, Adam; OpenAI: alloy, nova; Gemini: Kore, Puck)").option("-m, --music-prompt <text>","Music description").option("-n, --num-images <number>","Number of images to search/download","5").option("-o, --output <dir>","Output directory","./public").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{let n=e.format,t=n==="human"?ht("Initializing...").start():null,o=e.project?gt(process.cwd(),e.project):null;try{let r=await da(),i=null;if(e.scenes&&!e.scriptFile&&(e.scriptFile=e.scenes),o&&(e.output=G(o,"public"),e.scriptFile?e.scriptFile=gt(o,e.scriptFile):!e.script&&!r&&(e.scriptFile=G(o,"public","scenes.json"))),r)try{let k=JSON.parse(r);k.scenes&&Array.isArray(k.scenes)&&(i=k)}catch{}if(!i&&e.scriptFile)try{let k=await ft(e.scriptFile,"utf-8"),J=JSON.parse(k);J.scenes&&Array.isArray(J.scenes)&&(i=J)}catch{}let a=i?.voice||e.voice,s=i?.voiceId,d=i?.provider,u=i?.model,m=i?.voiceInstructions,b=i?.musicPrompt||e.musicPrompt||"uplifting background music, positive energy",C=i?.musicDuration,g=G(e.output,"audio"),T=G(e.output,"images"),v=G(e.output,"videos");t&&(t.text="Creating directories..."),await nt(g,{recursive:!0}),await nt(T,{recursive:!0}),await nt(v,{recursive:!0});let y=0,w=[],E=0,A=[],_=[];if(i&&i.scenes.length>0){n==="human"&&(t?.stop(),p(`Processing ${i.scenes.length} scenes...`),t?.start());let k=i.scenes.map((re,B)=>{let ye=re.script;return re.voiceStyle&&(ye=`${re.voiceStyle} ${ye}`),{text:ye,id:`scene-${B}`}});t&&(t.text="Generating speech for all scenes...");let J=await zo({texts:k,options:{provider:d,voice:a,voiceId:s,model:u,voiceSettings:i.voiceSettings,instructions:m}});y+=J.totalCost;let oe=0;for(let re=0;re<i.scenes.length;re++){let B=i.scenes[re],ye=$l(B.name),me=J.results[re];t&&(t.text=`[${B.name}] Saving audio...`);let cn=G(g,`${ye}.${me.format}`);await ve(cn,me.audioData);let Pe=me.duration,ya=Math.round(Pe*et),rt={id:re+1,name:B.name,text:B.script,wordCount:B.script.split(/\s+/).length,startTime:oe,endTime:oe+Pe,durationInSeconds:Pe,durationInFrames:ya,audioPath:`audio/${ye}.${me.format}`,timestamps:me.timestamps};if(B.imageQuery){t&&(t.text=`[${B.name}] Searching image...`);try{let Z=await Tt({query:B.imageQuery,options:{maxResults:1,size:"large",safeSearch:!0}}),it=Z.data.results.flatMap(X=>X.results);if(y+=Z.data.totalCost,it.length>0){let X=it[0],at=Ol(X.url),Ce=`${ye}.${at}`,dn=G(T,Ce);await on(X.url,dn),rt.imagePath=`images/${Ce}`,A.push({path:`images/${Ce}`,url:X.url,width:X.width,height:X.height,query:B.imageQuery})}}catch(Z){n==="human"&&(t?.stop(),U(`[${B.name}] Image search failed: ${Z instanceof Error?Z.message:"Unknown"}`),t?.start())}}if(B.videoQuery){t&&(t.text=`[${B.name}] Searching video...`);try{let Z=await yn({query:B.videoQuery,options:{maxResults:1,license:"free"}}),it=Z.data.results.flatMap(X=>X.results);if(y+=Z.data.totalCost,it.length>0){let X=it[0],at=X.previewUrl||X.downloadUrl;if(at){let Ce=`${ye}.mp4`,dn=G(v,Ce);await on(at,dn),rt.videoPath=`videos/${Ce}`,_.push({path:`videos/${Ce}`,url:at,width:X.width,height:X.height,duration:X.duration,query:B.videoQuery})}}}catch(Z){n==="human"&&(t?.stop(),U(`[${B.name}] Video search failed: ${Z instanceof Error?Z.message:"Unknown"}`),t?.start())}}if(w.push(rt),oe+=Pe,E+=Pe,n==="human"){t?.stop();let Z=[`audio: ${Pe.toFixed(1)}s`,rt.imagePath?"image":null,rt.videoPath?"video":null].filter(Boolean).join(", ");S(` ${B.name}: ${Z}`),t?.start()}}}else{let k=e.script;if(e.scriptFile)try{k=await ft(e.scriptFile,"utf-8")}catch(me){t?.stop(),c(`Failed to read script file: ${me instanceof Error?me.message:"Unknown error"}`),process.exit(l.INVALID_INPUT)}(!k||k.trim().length===0)&&(t?.stop(),c("Provide scenes via stdin JSON, --scenes/--script-file with scenes JSON, or --script for legacy mode"),process.exit(l.INVALID_INPUT)),k=k.trim();let J=e.topic||k.split(".")[0].slice(0,50);t&&(t.text="Generating voiceover...");let oe=await It({text:k,options:{voice:a}}),re=G(g,`voiceover.${oe.format}`);await ve(re,oe.audioData),y+=oe.cost,E=oe.duration;let B=Cl(k);w=Tl(B,oe.duration,et,oe.timestamps).map((me,cn)=>({...me,name:`Section${cn+1}`,audioPath:`audio/voiceover.${oe.format}`})),n==="human"&&(t?.stop(),S(`Voiceover: ${re} (${oe.duration.toFixed(1)}s)`),t?.start())}t&&(t.text="Creating timeline...");let I=El(w),V=Math.max(I.audio.length>0?Math.max(...I.audio.map(k=>k.endMs)):0,I.text.length>0?Math.max(...I.text.map(k=>k.endMs)):0,I.elements.length>0?Math.max(...I.elements.map(k=>k.endMs)):0),q=V/1e3,ne=C?Math.min(300,Math.max(3,C)):Math.min(300,Math.ceil(q));console.log("[Music Generation] Requesting music:",{prompt:b,requestedDuration:ne,totalAudioDuration:E,actualVideoDuration:q,timelineDurationMs:V});let ot,rn;t&&(t.text="Generating music and thumbnail...");let ga=`YouTube thumbnail style: BIG BOLD short headline text (like "$50K/MONTH"), dramatic engaging scene, arrows pointing to key elements, high contrast, vibrant colors, clean composition, 16:9. Video context: ${w.map(k=>k.text).join(" ")}`,an=[],fa=(async()=>{if(ne<3)return n==="human"&&(t?.stop(),U(`Video duration (${q.toFixed(1)}s) is too short for music generation (minimum 3s).`),t?.start()),null;try{let k=await Ct({prompt:b,duration:ne});if(k.status!=="completed"&&k.status!=="failed"&&(k=await K(()=>ct(k.requestId),60,2e3)),k.status==="failed")throw new Error(k.error||"Unknown error");let J=G(g,"music.mp3");return k.audioUrl&&await on(k.audioUrl,J),{path:"audio/music.mp3",duration:k.duration||ne,prompt:b,cost:k.cost||0}}catch(k){return n==="human"&&(t?.stop(),U(`Music generation failed: ${k.message}`),t?.start()),null}})();an.push(fa);let ha=(async()=>{try{let k=await Ko({prompt:ga,options:{width:1280,height:720}});if(k.success&&k.data.url){let J=G(e.output,"thumbnail.jpg");return await on(k.data.url,J),y+=k.data.cost||0,J}return null}catch(k){return n==="human"&&(t?.stop(),U(`Thumbnail generation failed: ${k.message}`),t?.start()),null}})();an.push(ha);let[Oe,go]=await Promise.all(an);Oe&&(ot=Oe,y+=Oe.cost||0,n==="human"&&(t?.stop(),S(`Music: ${G(g,"music.mp3")} (${Oe.duration}s)`),Oe.duration<q&&U(`Music duration (${Oe.duration.toFixed(1)}s) is shorter than video duration (${q.toFixed(1)}s).`),t?.start())),go&&(rn=go,n==="human"&&(t?.stop(),S(`Thumbnail: ${rn}`),t?.start())),t&&(t.text="Writing manifest...");let fo=Math.round(q*et),ho={music:ot,thumbnail:rn?"thumbnail.jpg":void 0,images:A,videos:_,scenes:w,timeline:I,totalDurationInFrames:fo,fps:et,totalCost:y,createdAt:new Date().toISOString()},sn=G(e.output,"video-manifest.json");if(await ve(sn,JSON.stringify(ho,null,2)),t?.stop(),n==="json"){let{totalCost:k,...J}=ho;x(J);return}if(n==="quiet"){console.log(sn);return}console.log(),S("Video assets created successfully!"),console.log(),p(`Scenes: ${w.length} (${fo} frames at ${et}fps)`);for(let k of w){let J=[k.audioPath?"audio":null,k.imagePath?"image":null,k.videoPath?"video":null].filter(Boolean).join(", ");p(` - ${k.name}: ${k.durationInSeconds.toFixed(1)}s [${J}]`)}p(`Music: ${ot?.path} (${ot?.duration}s)`),p(`Manifest: ${sn}`),console.log(),p(`Total cost: $${y.toFixed(4)}`)}catch(r){t?.stop(),c(r instanceof Error?r.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}});function _l(e){let n=e?.trim().toLowerCase();if(!(!n||n==="any"||n==="all"))return n==="web"||n==="stock"?[n]:void 0}var Nl=new te("find").description("Find video clips across the web and licensed stock").argument("<query>","Search query").option("-n, --max-results <count>","Maximum number of results","10").option("-o, --orientation <type>","Video orientation: landscape, portrait, square, any","any").option("-l, --license <type>","License type: free, premium, any","free").option("--source <source>","Catalog: web, stock, or any (default: any)","any").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{let{maxResults:t,orientation:o,license:r,format:i}=n,a=i==="human"?ht("Finding videos...").start():null;try{let s=await yn({query:e,options:{maxResults:parseInt(t,10),orientation:o,license:r,sources:_l(n.source)}});a?.stop();let d=s.data.results.flatMap(u=>u.results);if(i==="json"){let{totalCost:u,...m}=s.data;x({...s,data:m});return}if(i==="quiet"){d.forEach(u=>{console.log(u.previewUrl||u.thumbnailUrl)});return}if(d.length===0){p("No videos found");return}S(`Found ${d.length} videos for "${e}"`),console.log(),d.forEach((u,m)=>{console.log(`[${m+1}] ${u.title}`),console.log(` URL: ${u.previewUrl||u.thumbnailUrl}`),console.log(` Duration: ${u.duration}s | Size: ${u.width}x${u.height}`),console.log(` Provider: ${u.provider}`),console.log()}),p(`Total cost: $${s.data.totalCost.toFixed(4)}`)}catch(s){a?.stop(),c(s instanceof Error?s.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),Ll=new te("new").description("Create a new video project from a template").argument("<name>","Project directory name").option("-t, --template <repo>","GitHub repo (user/repo#commit)",Sl).option("--type <type>","Video type: youtube (16:9), tiktok (9:16), or audiogram (1:1)","youtube").option("--no-install","Skip dependency install").option("-f, --format <format>","Output format: human, json, quiet","human").action(async(e,n)=>{let t=n.format,o=t==="human"?ht("Initializing video project...").start():null;try{let r=Ke();await nt(r,{recursive:!0});let i=Zt(e),a=n.type,s=await ao();if(s.includes(e)){let g=Xi(e,s);o?.stop(),c(`Project "${e}" already exists at: ${i}`),p(`Try: ${f.commands[0]} video generate new ${g}`),process.exit(l.INVALID_INPUT)}/^[a-zA-Z0-9_-]+\/[a-zA-Z0-9_.-]+(#[a-zA-Z0-9_./-]+)?$/.test(n.template)||(o?.stop(),c(`Invalid template format: "${n.template}". Expected format: owner/repo or owner/repo#branch`),process.exit(l.INVALID_INPUT)),["youtube","tiktok","audiogram"].includes(a)||(o?.stop(),c(`Invalid type "${a}". Use youtube, tiktok, or audiogram.`),process.exit(l.INVALID_INPUT)),o&&(o.text=`Cloning template from ${n.template}...`);let[u,m]=n.template.split("#"),b=m?`-b ${m}`:"";try{tt(`git clone ${b} --depth 1 https://github.com/${u}.git "${i}"`,{stdio:"pipe"}),await lo(G(i,".git"),{recursive:!0,force:!0})}catch(g){o?.stop(),c(`Failed to clone template: ${g instanceof Error?g.message:"Unknown error"}`),process.exit(l.GENERAL_ERROR)}t==="human"&&(o?.stop(),S(`Template downloaded to ${e}/`),o?.start());let C;try{C=await Il(i)}catch{o?.stop(),c("template.manifest.json not found or invalid in template repo"),process.exit(l.INVALID_INPUT)}if(C.propsSchema&&C.propsSchema!=="video-plan.v1"&&(o?.stop(),c(`Template propsSchema must be video-plan.v1 (found ${C.propsSchema})`),process.exit(l.INVALID_INPUT)),o&&(o.text="Writing scaffold files..."),await Al(i,a,f.commands[0]),n.install){let g=ca()?"bun":"npm";o&&(o.text=`Installing dependencies with ${g}...`),await new Promise((T,v)=>{let y=wl(g,["install"],{cwd:i,stdio:"pipe",shell:!0});y.on("close",w=>{w===0?T():v(new Error(`${g} install failed with code ${w}`))}),y.on("error",v)}),t==="human"&&(o?.stop(),S("Dependencies installed"),o?.start())}if(o?.stop(),t==="json"){x({name:e,path:i,template:n.template,type:a,installed:n.install});return}if(t==="quiet"){console.log(i);return}console.log(),S(`Video project "${e}" created successfully!`),p(`Location: ${i}`),a==="tiktok"?p("Format: TikTok/Reels/Shorts (1080x1920 @ 30fps)"):a==="audiogram"?p("Format: Audiogram (1080x1080 @ 30fps)"):p("Format: YouTube (1920x1080 @ 30fps)"),console.log(),p("Next steps:"),p(` cd ${i}`),n.install||p(` ${ca()?"bun":"npm"} install`),p(" bun run dev # Preview in Remotion Studio"),p(` ${f.commands[0]} video generate assets --scenes public/scenes.json`),p(` ${f.commands[0]} video generate plan`)}catch(r){o?.stop(),c(r instanceof Error?r.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),Dl=new te("plan").description("Generate video plan from context (via stdin or --context)").option("-c, --context <text>","Context for plan generation").option("-o, --output <path>","Save plan to file").option("-b, --branding <path>","Branding JSON file to include").option("--render-target <target>","Plan target: hyperframes or remotion","hyperframes").option("--no-wait","Return the background run ID immediately").action(async e=>{let n=ht("Generating video plan...").start();try{let t=e.context;if(!t){let d=await da();d&&(t=d)}t||(n.stop(),c("Provide context via stdin or --context flag"),process.exit(l.INVALID_INPUT));let o;if(e.branding)try{o=await ft(e.branding,"utf-8")}catch{n.stop(),c(`Could not read branding file: ${e.branding}`),process.exit(l.INVALID_INPUT)}let r=e.renderTarget==="remotion"?"remotion":"hyperframes",i={context:t,branding:o,renderTarget:r};if(e.wait===!1){n.stop(),x(await vn(i));return}let a=await ar(i);n.stop(),a.success||(c(a.error||"Failed to generate plan"),process.exit(l.GENERAL_ERROR));let s=a.data;e.output?(await ve(e.output,s),S(`Plan saved to ${e.output}`)):console.log(s)}catch(t){n.stop(),c(t instanceof Error?t.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),Fl=new te("generate").description("Generate parts of a video project").addCommand(Ll).addCommand(Pl).addCommand(Dl),Ul=new te("create").description("Start background standalone video generation").argument("<title>","Video title").requiredOption("--brief <brief>","Video brief").option("--assets <path>","JSON file containing image/video/audio asset URLs").option("--branding-id <id>","Saved workspace brand UUID").option("--content-sources <path>","JSON file containing contextFiles/uploadedFiles/researchSources").option("--topic <topic>","Video topic").option("--duration <seconds>","Duration in seconds","30").option("--format <format>","tiktok, instagram_reel, or youtube_short","tiktok").option("--team-id <id>","Workspace ID").option("--yes","Approve generation").action(async(e,n)=>{if(!n.yes)return c("Pass --yes to approve video generation");try{let t=n.assets?await uo(n.assets):void 0,o=n.contentSources?await uo(n.contentSources):void 0;x(await ir({assets:t,brandingId:n.brandingId,brief:n.brief,contentSources:o,durationSec:Number(n.duration),format:n.format,title:e,topic:n.topic}))}catch(t){c(t instanceof Error?t.message:"Generation failed"),process.exit(l.GENERAL_ERROR)}}),la=new te("plan").description("Start background video-plan generation").requiredOption("--context <brief>","Video brief (minimum 100 characters)").option("--branding <path>","Branding JSON file").option("--render-target <target>","hyperframes or remotion","hyperframes").option("--yes","Approve generation").action(async e=>{if(!e.yes)return c("Pass --yes to approve plan generation");try{let n=e.branding?await ft(e.branding,"utf-8"):void 0;x(await vn({branding:n,context:e.context,renderTarget:e.renderTarget==="remotion"?"remotion":"hyperframes"}))}catch(n){c(n instanceof Error?n.message:"Plan generation failed"),process.exit(l.GENERAL_ERROR)}}),Ml=new te("status").description("Read video or video-plan background status").argument("<run-id>","Run ID").option("--plan","Read a video-plan run").option("--team-id <id>","Workspace ID").action(async(e,n)=>{try{x(await L(n.plan?"generateVideoPlan":"createVideo",e,n.teamId))}catch(t){c(t instanceof Error?t.message:"Status failed"),process.exit(l.GENERAL_ERROR)}}),Vl=new te("status").description("Read video-plan background status").argument("<run-id>","Run ID").option("--team-id <id>","Workspace ID").action(async(e,n)=>{try{x(await L("generateVideoPlan",e,n.teamId))}catch(t){c(t instanceof Error?t.message:"Status failed"),process.exit(l.GENERAL_ERROR)}});la.addCommand(Vl);var jl=new te("projects").description("List all video projects").option("-f, --format <format>","Output format: human, json","human").action(async e=>{let n=await ao();if(e.format==="json"){x({projectsDir:Ke(),projects:n.map(t=>({name:t,path:Zt(t)}))});return}if(n.length===0){p("No video projects found"),p(`Projects are stored in: ${Ke()}`);return}console.log(`
|
|
3785
|
+
Video Projects:`),console.log("-".repeat(50));for(let t of n)console.log(` ${t}`),console.log(` ${Zt(t)}`);console.log()}),ql=new te("inject").description("Inject thumbnail into video (first frame + file icon)").requiredOption("-i, --video <path>","Input video file").requiredOption("-t, --thumbnail <path>","Thumbnail image").option("-o, --output <path>","Output video (default: video-with-thumb.mp4)").option("-f, --format <format>","Output format: human, json, quiet","human").action(async e=>{let n=e.format,t=n==="human"?ht("Injecting thumbnail...").start():null;try{let o=gt(e.video),r=gt(e.thumbnail),i=e.output?gt(e.output):o.replace(/\.mp4$/,"-with-thumb.mp4");await co(o),await co(r);let a=xl;if(a)try{await co(a)}catch{a=null}if(!a)try{a=tt("which ffmpeg",{encoding:"utf8"}).trim()}catch{throw new Error("ffmpeg not found. Install ffmpeg or ffmpeg-static.")}let s=vl(a,["-i",o],{encoding:"utf8"});if(s.error)throw new Error(`Failed to probe video: ${s.error.message}`);let d=(s.stderr??"").match(/(\d{2,5})x(\d{2,5})/);if(!d)throw new Error("Could not detect video dimensions");let[,u,m]=d;t&&(t.text="Creating thumbnail frame...");let b="/tmp/cc-thumb-frame.mp4";tt(`${a} -y -loop 1 -i "${r}" -vf "scale=${u}:${m}:force_original_aspect_ratio=decrease,pad=${u}:${m}:(ow-iw)/2:(oh-ih)/2,setsar=1" -t 0.033 -r 30 -c:v libx264 -pix_fmt yuv420p "${b}"`,{stdio:"pipe"}),t&&(t.text="Concatenating with video...");let C="/tmp/cc-concat-video.mp4";if(tt(`${a} -y -i "${b}" -i "${o}" -filter_complex "[0:v][1:v]concat=n=2:v=1:a=0[v]" -map "[v]" -map 1:a -c:v libx264 -preset ultrafast -crf 18 -c:a copy "${C}"`,{stdio:"pipe"}),t&&(t.text="Adding file icon thumbnail..."),tt(`${a} -y -i "${C}" -i "${r}" -map 0 -map 1 -c copy -c:v:1 png -disposition:v:1 attached_pic "${i}"`,{stdio:"pipe"}),await lo(b,{force:!0}),await lo(C,{force:!0}),t?.stop(),n==="json"){x({success:!0,output:i});return}if(n==="quiet"){console.log(i);return}S(`Thumbnail injected: ${i}`)}catch(o){t?.stop(),c(o instanceof Error?o.message:"Unknown error"),process.exit(l.GENERAL_ERROR)}}),Bl=new te("thumbnail").description("Thumbnail operations").addCommand(ql),mo=new te("video").description("Video generation commands").addCommand(Fl).addCommand(Nl).addCommand(jl).addCommand(Bl).addCommand(ia).addCommand(aa).addCommand(sa).addCommand(Zi);mo.addCommand(Ul).addCommand(la).addCommand(Ml);import{Command as po}from"commander";var Gl=new po("create").description("Start background visual-abstract generation").argument("<brief>","Dense source brief").option("--title <title>","Artifact title").option("--aspect <ratio>","1:1, 16:9, 9:16, 4:3, or 3:4","1:1").option("--quality <tier>","fast, balanced, or best","best").option("--preset <preset>","Output preset","executive-one-pager").option("--branding-id <id>","Branding ID").option("--team-id <id>","Workspace ID").option("--yes","Approve generation").action(async(e,n)=>{if(!n.yes)return c("Pass --yes to approve visual-abstract generation");try{x(await $("createVisualAbstract",{approvalReceipt:"cli:--yes",aspectRatio:n.aspect,brandingId:n.brandingId,brief:e,outputPreset:n.preset,qualityTier:n.quality,teamId:n.teamId,title:n.title}))}catch(t){c(t instanceof Error?t.message:"Generation failed"),process.exit(l.GENERAL_ERROR)}}),Wl=new po("status").description("Read visual-abstract generation status").argument("<run-id>","Run ID").option("--team-id <id>","Workspace ID").action(async(e,n)=>{try{x(await L("createVisualAbstract",e,n.teamId))}catch(t){c(t instanceof Error?t.message:"Status failed"),process.exit(l.GENERAL_ERROR)}}),ua=new po("visual-abstract").description("Visual abstract commands").addCommand(Gl).addCommand(Wl);var Hl=[Si,Ii,bi,Ji,Ni,Ai,Ti,mo,Mi,qi,Ui,ji,vi,Ri,Di,gi,ua,ki,ui,hi];function ma(e){for(let n of Hl)e.addCommand(n)}var zl="0.3.15",W=new Jl,xe=f.commands[0];W.name(xe).description(f.description).version(zl,"-v, --version","Show version number").option("--debug","Enable debug logging").option("--no-color","Disable colored output").configureOutput({outputError:(e,n)=>{n(ue.red(e))}});W.addCommand(Or);W.addCommand(Pr);W.addCommand(hr);W.addCommand(Rr);W.addCommand(yr);W.addCommand(Sr);W.addCommand(Tr);W.addCommand(ci);W.addCommand(Ir);W.addCommand(di);W.addCommand(Xe);W.addCommand(Nt);W.addCommand(lr);ma(W);var pa=vr();pa.commands.length>0&&W.addCommand(pa);W.on("command:*",e=>{console.error(ue.red(`Error: Unknown command '${e[0]}'`)),console.error(),console.error(`Run '${xe} --help' to see available commands.`),process.exit(1)});W.addHelpText("after",`
|
|
3786
3786
|
${ue.bold("Examples:")}
|
|
3787
3787
|
${ue.gray("# Log in (opens browser)")}
|
|
3788
3788
|
$ ${xe} login
|
|
@@ -3814,5 +3814,5 @@ ${ue.bold("Authentication:")}
|
|
|
3814
3814
|
Or set CC_SLIDES_API_KEY environment variable for API key auth.
|
|
3815
3815
|
|
|
3816
3816
|
${ue.bold("More Info:")}
|
|
3817
|
-
${ue.blue(
|
|
3818
|
-
`);W.parse(
|
|
3817
|
+
${ue.blue(f.docsUrl)}
|
|
3818
|
+
`);W.parse(li(process.argv.slice(2)),{from:"user"});
|