#!/usr/bin/env python3
"""Analyze the Flow JS bundle to extract the Veo request body structure."""
import re

with open("flow_app_bundle.js") as f:
    text = f.read()

# _0x5bbfe2 is the runVideoFxSingleClips wrapper function
# Find all places where _0x5bbfe2 is called
var_name = "_0x5bbfe2"
print(f"=== Searching for calls to {var_name} ===")

# Pattern: _0x5bbfe2({ or await _0x5bbfe2(
for m in re.finditer(re.escape(var_name) + r'\(', text):
    # Skip the function definition itself
    before = text[max(0, m.start()-10):m.start()]
    if '=' in before and '=>' not in before:
        continue
    
    # Get wide context
    ctx = text[max(0, m.start()-800):m.start()+400]
    print(f"\n--- Call at position {m.start()} ---")
    print(ctx[-600:])
    print("\n")

# Also search for batchAsyncGenerateVideoText - this is likely the
# function that constructs the request and calls _0x5bbfe2
print("\n=== batchAsyncGenerateVideoText context ===")
for m in re.finditer("batchAsyncGenerateVideoText", text):
    # Get wide context to see the function body
    ctx = text[max(0, m.start()-200):m.start()+2000]
    print(f"\nAt position {m.start()}:")
    print(ctx[:1500])
    print("---")
