File size: 2,027 Bytes
9730a79
38e1d70
 
181f321
88f811c
 
d44ad7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1624e3
70154bd
d44ad7b
 
1b36f73
f1624e3
 
d44ad7b
 
f1624e3
d44ad7b
 
 
 
 
38e1d70
d44ad7b
f1624e3
38e1d70
f1624e3
d44ad7b
38e1d70
d44ad7b
1b36f73
d44ad7b
750f440
d44ad7b
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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)
                # store relative path within the zip
                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 for status
        title = assets.get("blueprint", {}).get("title", "<unknown>")
        # Directory where the app was generated
        project_dir = assets.get("project_dir") or assets.get("app_dir")
        if project_dir is None or not os.path.isdir(project_dir):
            # No directory to zip up
            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}"