@@ -791,7 +791,7 @@ async function animateImageWithLightbox(
791791
792792 const result = await runPlaywrightCliCodeJson < LightboxAnimateResult > (
793793 sessionName ,
794- buildCustomAnimateCode ( animationPrompt , image . id ) ,
794+ await buildCustomAnimateCode ( animationPrompt , image . id ) ,
795795 ) ;
796796
797797 if ( ! result . ok || ! result . videoId ) {
@@ -816,13 +816,11 @@ async function animateImageWithLightbox(
816816 } ;
817817}
818818
819- function buildCustomAnimateCode ( prompt : string , sourceMediaId : string ) : string {
820- const scriptPath = fromFileUrl (
821- new URL (
822- "./lib/meta_lightbox_animate.js" ,
823- import . meta. url ,
824- ) ,
825- ) ;
819+ async function buildCustomAnimateCode (
820+ prompt : string ,
821+ sourceMediaId : string ,
822+ ) : Promise < string > {
823+ const scriptPath = await getCustomAnimateScriptPath ( ) ;
826824 const input = { prompt, sourceMediaId } ;
827825
828826 return `async (page) => {
@@ -833,6 +831,27 @@ function buildCustomAnimateCode(prompt: string, sourceMediaId: string): string {
833831 }` ;
834832}
835833
834+ async function getCustomAnimateScriptPath ( ) : Promise < string > {
835+ const scriptUrl = new URL ( "./lib/meta_lightbox_animate.js" , import . meta. url ) ;
836+ if ( scriptUrl . protocol === "file:" ) {
837+ return fromFileUrl ( scriptUrl ) ;
838+ }
839+
840+ const response = await fetch ( scriptUrl ) ;
841+ if ( ! response . ok ) {
842+ throw new Error (
843+ `Could not load Meta lightbox automation script: ${ response . status } ${ response . statusText } ` ,
844+ ) ;
845+ }
846+
847+ const scriptPath = await Deno . makeTempFile ( {
848+ prefix : "meta-ai-lightbox-animate-" ,
849+ suffix : ".js" ,
850+ } ) ;
851+ await Deno . writeTextFile ( scriptPath , await response . text ( ) ) ;
852+ return scriptPath ;
853+ }
854+
836855async function pickFirstCompletedVideo (
837856 client : MetaAiClient ,
838857 variants : GeneratedVideo [ ] ,
0 commit comments