{
  pkgs,
  lib,
  config,
  inputs,
  ...
}:

{
  starship = {
    enable = true;
    config = {
      enable = true;
      path = ./starship.toml;
    };
  };

  env = {
    AI_GATEWAY_DATABASE_NAME = "easyai_ai_gateway";
    AI_GATEWAY_DATABASE_URL = "host=${config.env.DEVENV_RUNTIME}/postgres dbname=easyai_ai_gateway sslmode=disable";
    AI_GATEWAY_SKIP_DB_CREATE = "1";
  };

  packages = with pkgs; [
    curl
    docker-client
    git
    jq
    lsof
    postgresql_18
    ripgrep
    watchexec
  ];

  scripts = {
    dev.exec = "pnpm dev";
    build.exec = "pnpm build";
    test-all.exec = "pnpm test";
    lint.exec = "pnpm lint";
    migrate.exec = "pnpm migrate";
    db-create.exec = "pnpm db:create";
    api-test.exec = "pnpm nx run api:test";
    web-build.exec = "pnpm nx run web:build";
  };

  services.postgres = {
    enable = true;
    package = pkgs.postgresql_18.withPackages (postgresPackages: [
      postgresPackages.pgvector
    ]);
    listen_addresses = "";
    initialDatabases = [
      {
        name = "easyai_ai_gateway";
        initialSQL = ''
          CREATE EXTENSION IF NOT EXISTS pgcrypto;
          CREATE EXTENSION IF NOT EXISTS vector;
        '';
      }
    ];
  };

  # https://devenv.sh/languages/
  languages.go = {
    enable = true;
    package = pkgs.go;
  };

  languages.javascript = {
    enable = true;
    package = pkgs.nodejs_22;
    nodejs.enable = true;
    lsp.enable = true;
    pnpm = {
      enable = true;
      install.enable = true;
    };
  };

  enterShell = ''
    echo ""
    echo "EasyAI AI Gateway 开发环境已就绪"
    echo "当前目录：$PWD"
    echo ""
    echo "运行时版本："
    echo "  go:    $(go version | awk '{print $3}')"
    echo "  node:  $(node --version)"
    echo "  pnpm:  $(pnpm --version)"
    echo "  psql:  $(psql --version | awk '{print $3}')"
    echo ""
    echo "常用命令："
    echo "  dev       创建/迁移数据库，并启动 API 和 Web"
    echo "  test-all  运行 API 和 Web 测试目标"
    echo "  build     构建 API 和 Web"
    echo "  lint      运行 Web 与 contracts 类型检查"
    echo "  migrate   执行 API 数据库迁移"
    echo "  db-create 创建 AI Gateway 数据库"
    echo "  api-test  只运行 Go API 测试"
    echo "  web-build 只构建 Web 前端"
    echo ""
    echo "提示：根 package.json 是唯一脚本入口；上述短命令由 devenv scripts 转发。"
    echo ""
  '';
}
