HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //opt/OpenManusWeb/main.py
import argparse
import asyncio
import os
import sys

from app.agent.manus import Manus
from app.logger import logger


async def run_cli():
    """运行命令行交互模式"""
    agent = Manus()
    while True:
        try:
            prompt = input("Enter your prompt (or 'exit'/'quit' to quit): ")
            prompt_lower = prompt.lower()
            if prompt_lower in ["exit", "quit"]:
                logger.info("Goodbye!")
                break
            if not prompt.strip():
                logger.warning("Skipping empty prompt.")
                continue
            logger.warning("Processing your request...")
            await agent.run(prompt)
        except KeyboardInterrupt:
            logger.warning("Goodbye!")
            break


async def run_web():
    """启动Web应用"""
    # 使用子进程执行web_run.py
    import uvicorn

    # 确保目录结构存在
    from web_run import check_websocket_dependencies, ensure_directories

    ensure_directories()

    if not check_websocket_dependencies():
        logger.error("退出应用。请安装必要的依赖后重试。")
        return

    logger.info("🚀 OpenManus Web 应用正在启动...")
    logger.info("访问 http://localhost:8000 开始使用")

    # 设置环境变量以启用自动打开浏览器
    os.environ["AUTO_OPEN_BROWSER"] = "1"

    # 在当前进程中启动Uvicorn服务器
    uvicorn.run("app.web.app:app", host="0.0.0.0", port=8000)


def main():
    """主程序入口,解析命令行参数决定运行模式"""
    parser = argparse.ArgumentParser(description="OpenManus - AI助手")
    parser.add_argument("--web", action="store_true", help="以Web应用模式运行(默认为命令行模式)")

    args = parser.parse_args()

    try:
        if args.web:
            # 启动Web模式
            logger.info("启动Web应用模式...")
            asyncio.run(run_web())
        else:
            # 启动CLI模式
            logger.info("启动命令行交互模式...")
            asyncio.run(run_cli())
    except KeyboardInterrupt:
        logger.warning("程序已退出")
    except Exception as e:
        logger.error(f"程序异常退出: {str(e)}")
        return 1

    return 0


if __name__ == "__main__":
    sys.exit(main())