FROM node:18

WORKDIR /usr/src/app/

RUN npm install typescript pnpm -g

RUN git clone -b feat/agent_chat_react https://github.com/huggingface/huggingface.js.git && \
    cd huggingface.js && \
    pnpm install && \
    cd packages/inference && \
    pnpm install && \
    pnpm run build && \
    npm link && \
    cd ../.. && \
    cd packages/agents && \
    rm -rf node_modules && \
    npm install && \
    npm link @huggingface/inference && \
    npm run build && \
    npm link && \
    cd ../../..


RUN git clone -b feature/chat-agent https://github.com/nsarrazin/poc-agents.js.git && \
    cd poc-agents.js && \
    git checkout e9e274ae0f0eceb6958da7dc8bfe6cc920eefee7 && \
    rm package-lock.json && \
    npm install && \
    npm link @huggingface/agents

WORKDIR /usr/src/app/poc-agents.js

RUN chmod -R 755 /usr/src/app/poc-agents.js

RUN --mount=type=secret,id=DOTENV_LOCAL,dst=.env.local \
    npm run build 

RUN chmod -R 755 /usr/src/app/poc-agents.js

RUN npm install -g pm2

CMD pm2 start /usr/src/app/poc-agents.js/build/index.js -i $CPU_CORES --no-daemon