# =============================================================================
# Pi Agent Container (MiniMax-M3 + Tavily Key Pool + Runner Service)
# Requires Node.js 22+ for node:fs globSync support
# =============================================================================
FROM node:22-bookworm-slim

# 安装系统运行时依赖 (bash, curl, git, ca-certificates)
RUN set -eux; \
    apt-get update; \
    apt-get install -y --no-install-recommends \
        ca-certificates \
        curl \
        git \
        bash; \
    rm -rf /var/lib/apt/lists/*

# 全局安装 pi-coding-agent CLI
RUN npm install -g @earendil-works/pi-coding-agent@0.85.1 --omit=dev

# 验证 pi 安装
RUN pi --version

WORKDIR /app

# 复制 runner、其相对 import 运行时模块、扩展工具以及入口脚本
COPY deploy/pi-agent/extensions/ /app/extensions/
COPY deploy/pi-agent/runner.mjs /app/runner.mjs
COPY deploy/pi-agent/settle-policy.mjs /app/settle-policy.mjs
COPY deploy/pi-agent/entrypoint.sh /app/entrypoint.sh

RUN chmod +x /app/entrypoint.sh /app/runner.mjs

# 默认环境变量配置 (敏感密钥通过运行时 -e 或 docker-compose 传入)
ENV PORT=18766 \
    DATA_DIR=/app/data/workspaces \
    PI_CODING_AGENT_DIR=/root/.pi/agent \
    MINIMAX_ENDPOINT_URL=https://api.minimaxi.com/v1 \
    MINIMAX_MODEL_ID=MiniMax-M3 \
    MINIMAX_API_TYPE=openai-compatible \
    MINIMAX_PROVIDER=minimax

EXPOSE 18766

ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["node", "/app/runner.mjs"]
