|
import os |
|
import tempfile |
|
import zipfile |
|
from core_creator.voice_to_app import VoiceToAppCreator |
|
from deployer.simulator_interface import VirtualRobot |
|
|
|
def _make_app_zip(src_dir: str, title: str) -> str: |
|
""" |
|
Zips up the directory at src_dir into a file named <title>.zip |
|
in the system temp directory, and returns the full path. |
|
""" |
|
safe_title = "".join(c if c.isalnum() or c in "-_." else "_" for c in title) |
|
zip_filename = f"{safe_title}.zip" |
|
tmp_dir = tempfile.gettempdir() |
|
zip_path = os.path.join(tmp_dir, zip_filename) |
|
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf: |
|
for root, _, files in os.walk(src_dir): |
|
for fname in files: |
|
full_path = os.path.join(root, fname) |
|
|
|
arcname = os.path.relpath(full_path, src_dir) |
|
zf.write(full_path, arcname) |
|
return zip_path |
|
|
|
def deploy_callback(idea: str): |
|
""" |
|
Generates an app from the user idea and returns: |
|
(status_message: str, path_to_zip: Optional[str]) |
|
""" |
|
try: |
|
creator = VoiceToAppCreator(idea) |
|
assets = creator.run_pipeline() |
|
|
|
title = assets.get("blueprint", {}).get("title", "<unknown>") |
|
|
|
project_dir = assets.get("project_dir") or assets.get("app_dir") |
|
if project_dir is None or not os.path.isdir(project_dir): |
|
|
|
return f"β No generated directory found for '{title}'", None |
|
|
|
zip_path = _make_app_zip(project_dir, title) |
|
return f"β
Generated app: {title}", zip_path |
|
|
|
except Exception as e: |
|
return f"β Failed to generate app: {e}", None |
|
|
|
def robot_behavior(command: str) -> str: |
|
""" |
|
Feeds the user command into the VirtualRobot simulator. |
|
""" |
|
try: |
|
return VirtualRobot().perform_action(command) |
|
except Exception as e: |
|
return f"β Simulator error: {e}" |
|
|