Hydra AI
Getting Started

Quick Start

Get started with Hydra AI in your project using the CLI

Installation

The hydra init command helps you set up Hydra AI in your Next.js project. Here's how to get started:

Prerequisites

  • A Node.js project with a valid package.json
  • Command must be run from your project root

Basic Usage

npx hydra-ai-cli init [--srcdir <directory>]

Options

  • --srcdir: Source directory to scan for components (defaults to src)

What Happens During Installation

Documentation for Hydra AI CLI Initialization Process

This guide will walk you through the init command of the Hydra AI CLI tool, explaining each step and showing what the process would look like in a terminal.


Step 1: Validate Root Directory

Description: The command checks if a valid package.json file exists in the root directory.

Terminal Output:

Terminal Output - Root Directory Validation
Initializing Hydra AI. This will create a `hydra-config.ts` file in your project, with initial component registrations.
 
This doesn't look like a valid Node.js project. Please run this command from the root of your project, where the `package.json` file is located.

If validation is successful:

Terminal Output - Validation Success
Initializing Hydra AI. This will create a `hydra-config.ts` file in your project, with initial component registrations.

Step 2: Authenticate User

Description: Ensures the user is authenticated before continuing. If not already logged in, prompts for authentication.

Terminal Output:

Terminal Output - Authenticate User
Fetching authentication details...
Authenticated successfully.

Step 3: Select or Create Project

Description: Fetches existing projects or prompts the user to create a new one.

Terminal Output (when projects exist):

Terminal Output - Select or Create Project
Fetching projects... Projects retrieved
? Select a project:
  > Project 1
    Project 2

Terminal Output (when no projects exist):

Terminal Output - No Projects Found
Fetching projects... Projects retrieved
No projects found. Let's create one.
? Enter project name: My New Project
Creating project... ✔ Project "My New Project" created

Step 4: Generate and Save API Key

Description: Generates a new API key and saves it in a .env file.

Terminal Output:

Terminal Output - Generate and Save API Key
Generating API key... API key generated
? Which .env file would you like to save the API key to? (default: .env.local)
> .env.local
 
API key saved to .env.local file

Step 5: Install Hydra AI Package

Description: Checks if the hydra-ai package is installed and prompts the user to install it if not.

Terminal Output:

Terminal Output - Install Hydra AI Package
? Do you want to install the `hydra-ai` package? (Y/n)
Installing hydra-ai package...

After successful installation:

Terminal Output - Install Hydra AI Package
+ hydra-ai@x.y.z
added 1 package in 2s

Step 6: Scan for Components

Description: Scans the src directory for components to register.

Terminal Output:

Terminal Output - Scan for Components
Scanning for components...
 Components found: 5

Step 7: Extract and Register Components

Description: Extracts component details and registers them in a hydra-config.ts file.

Terminal Output:

Terminal Output - Extract and Register Components
Extracting components... Component extraction complete
Creating hydra-config.ts file...
 `hydra-config.ts` file created successfully!

Sample hydra-config.ts Output

src/hydra-config.ts
/* This file was generated by the Hydra AI CLI. Edit each component registration as needed. */
import MyComponent from "./components/MyComponent";
import { HydraClient } from "hydra-ai";
 
export function registerComponents() {
  const hydra = new HydraClient({
    hydraApiKey: process.env.NEXT_PUBLIC_HYDRAAI_API_KEY,
  });
 
  hydra.registerComponent(
    "MyComponent",
    "Description of MyComponent",
    MyComponent,
    { prop1: "string", prop2: "number" }
  );
 
  return hydra;
}

Final Output

Once the process completes, you should see:

Terminal Output - Final Output
Hydra AI initialization complete. Your components are now registered!

Need Help?

Having trouble? We're here to help!