#!/bin/sh
set -eu

export HWLAB_SERVICE_ID="hwlab-deepseek-responses-bridge"
export HWLAB_ARTIFACT_KIND="bun-command"
export HWLAB_SERVICE_ENTRYPOINT="cmd/hwlab-deepseek-responses-bridge/main.ts"
export HWLAB_RUNTIME_MODE="${HWLAB_RUNTIME_MODE:-env-reuse-git-mirror-checkout}"
export HWLAB_COMMIT_ID="${HWLAB_BOOT_COMMIT:?HWLAB_BOOT_COMMIT is required}"
export HWLAB_REVISION="${HWLAB_BOOT_COMMIT}"
export HWLAB_IMAGE="${HWLAB_ENVIRONMENT_IMAGE:-${HWLAB_IMAGE:-}}"
export HWLAB_IMAGE_DIGEST="${HWLAB_ENVIRONMENT_DIGEST:-${HWLAB_IMAGE_DIGEST:-unknown}}"
export PORT="${PORT:-4000}"
export HWLAB_PORT="$PORT"

bun_bin="${HWLAB_BUN_COMMAND:-}"
if [ -z "$bun_bin" ]; then
  if command -v bun >/dev/null 2>&1; then
    bun_bin="$(command -v bun)"
  elif [ -x /usr/local/bin/bun ]; then
    bun_bin="/usr/local/bin/bun"
  elif [ -x ./node_modules/.bin/bun ]; then
    bun_bin="./node_modules/.bin/bun"
  else
    echo "hwlab-deepseek-responses-bridge boot failed: bun not found" >&2
    exit 127
  fi
fi

exec "$bun_bin" run cmd/hwlab-deepseek-responses-bridge/main.ts
