Skip to content

Commit

Permalink
add cli
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 7, 2025
1 parent 83c1570 commit 1f9beaa
Show file tree
Hide file tree
Showing 42 changed files with 3,614 additions and 22 deletions.
Binary file modified bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "eliza",
"scripts": {
"format": "biome format --write .",
"lint": "biome lint .",
"cli": "bun --filter=@elizaos/cli cli",
"lint": "biome lint . --write",
"check": "biome check --apply .",
"preinstall": "npx only-allow bun",
"build": "turbo run build --filter=./packages/*",
Expand Down
25 changes: 10 additions & 15 deletions packages/agent/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import express from "express";
import bodyParser from "body-parser";
import cors from "cors";
import path from "node:path";
import fs from "node:fs";

import {
type AgentRuntime,
type Character,
elizaLogger,
getEnvVariable,
type UUID,
validateCharacterConfig,
ServiceType,
type Character,
validateUuid,
} from "@elizaos/core";

// import type { TeeLogQuery, TeeLogService } from "@elizaos/plugin-tee-log";
// import { REST, Routes } from "discord.js";
import type { DirectClient } from ".";
import { validateUuid } from "@elizaos/core";
import bodyParser from "body-parser";
import cors from "cors";
import express from "express";
import fs from "node:fs";
import path from "node:path";
import type { CharacterServer } from "./server";

interface UUIDParams {
agentId: UUID;
Expand Down Expand Up @@ -52,8 +47,8 @@ function validateUUIDParams(

export function createApiRouter(
agents: Map<string, AgentRuntime>,
directClient: DirectClient
) {
directClient: CharacterServer
): express.Router {
const router = express.Router();

router.use(cors());
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CharacterServer } from "./server";
import {
type Adapter,
AgentRuntime,
Expand All @@ -24,6 +23,7 @@ import path from "node:path";
import { fileURLToPath } from "node:url";
import yargs from "yargs";
import { defaultCharacter } from "./defaultCharacter.js";
import { CharacterServer } from "./server";

const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename); // get the name of the directory
Expand Down
1 change: 1 addition & 0 deletions packages/cli/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# No configuration needed for SQLite
3 changes: 3 additions & 0 deletions packages/cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
components
dist
.turbo
188 changes: 188 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# TEE CLI

The TEE CLI provides a set of commands to manage your ElizaOS TEE deployments, from local development to cloud deployment.

## Getting Started

### Prerequisites

- Docker installed and running
- Node.js and npm/pnpm installed
- A Docker Hub account for publishing images
- A Phala Cloud (https://cloud.phala.network/login) API key for cloud deployments

## Commands

### Building Your Image

Build your Docker image locally:

```bash
elizaos tee phala build \
-i your-image-name \
-u your-dockerhub-username \
-f path/to/Dockerfile \
-t tag-name
```

### Running the TEE Simulator

Start the local TEE simulator for testing:

```bash
elizaos tee phala simulator
```
This will start the simulator on http://localhost:8090.

### Local Development

You can develop your agent locally in two ways:

1. Build the docker-compose file separately:
```bash
elizaos tee phala build-compose \
-i your-image-name \
-u your-dockerhub-username \
-t tag-name \
-c path/to/character.json \
-e path/to/.env \
-v v2 # or v1 for legacy mode
```

2. Run an existing compose file:
```bash
elizaos tee phala run-local \
-c path/to/docker-compose.yml \
-e path/to/.env
```

This separation allows you to:
- Build compose files without running them immediately
- Version control your compose files
- Share compose files with team members
- Run the same compose file multiple times

The CLI will store generated compose files in:
```
.tee-cloud/
└── compose-files/ # Generated docker-compose files
└── your-character-tee-compose.yaml
```

### Publishing Your Image

Push your built image to Docker Hub:

```bash
elizaos tee phala publish \
-i your-image-name \
-u your-dockerhub-username \
-t tag-name
```

### List Available Tags

View all tags for your image on Docker Hub:

```bash
elizaos tee phala list-tags \
-i your-image-name \
-u your-dockerhub-username
```

### Cloud Deployment

First, set your Phala Cloud API key:

```bash
elizaos tee phala set-apikey your-api-key
```

Deploy to Phala Cloud:

```bash
elizaos tee phala deploy \
-t phala \
-m docker-compose \
-n your-deployment-name \
-c path/to/docker-compose.yml \
--env-file path/to/.env
```

### Managing Cloud Deployments

List your active agents (CVMs):

```bash
elizaos tee phala list-cvms
```

List your TEE pods:
```bash
elizaos tee phala teepods
```

List images in a specific TEE pod:
```bash
elizaos tee phala images --teepod-id your-teepod-id
```

Upgrade an existing deployment:
```bash
elizaos tee phala upgrade \
-t phala \
-m docker-compose \
--app-id your-app-id \
-c path/to/docker-compose.yml \
--env-file path/to/.env
```

## Directory Structure

The CLI will create the following directory structure:
```
.tee-cloud/
└── compose-files/ # Generated docker-compose files
```

## Environment Variables

Create a .env file with your required variables:

```env
ANTHROPIC_API_KEY=your_key
TELEGRAM_BOT_TOKEN=your_token
# Add other required variables
```

## Tips

- Use the simulator for local testing before cloud deployment
- Always test your image locally with `run-local` before publishing
- Keep your API keys secure and never commit them to version control
- Use the `--help` flag with any command for detailed usage information

## Troubleshooting

Common issues and solutions:

1. **Docker Build Fails**
- Ensure Docker daemon is running
- Check Dockerfile path is correct
- Verify you have necessary permissions

2. **Simulator Connection Issues**
- Check if port 8090 is available
- Ensure Docker has necessary permissions

3. **Cloud Deployment Fails**
- Verify API key is set correctly
- Check if image exists on Docker Hub
- Ensure environment variables are properly set

For more help, use the `--help` flag with any command:

```bash
elizaos tee phala --help
elizaos tee phala <command> --help
```
82 changes: 82 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"name": "@elizaos/cli",
"version": "0.2.0-alpha.1",
"description": "Add components to your apps.",
"publishConfig": {
"access": "public"
},
"license": "MIT",
"author": {
"name": "elizaOS",
"url": "https://twitter.com/eliza_OS"
},
"repository": {
"type": "git",
"url": "https://github.com/elizaOS/eliza.git",
"directory": "packages/cli"
},
"files": [
"dist"
],
"keywords": [],
"type": "module",
"exports": "./dist/index.js",
"bin": {
"elizaos": "./dist/index.js"
},
"scripts": {
"cli": "tsup src/index.ts --watch --onSuccess \"node dist/index.js\"",
"build": "tsup",
"typecheck": "tsc --noEmit",
"clean": "rimraf dist && rimraf components",
"start:dev": "cross-env COMPONENTS_REGISTRY_URL=http://localhost:3003 node dist/index.js",
"start": "node dist/index.js",
"format:write": "prettier --write \"**/*.{ts,tsx,mdx}\" --cache",
"format:check": "prettier --check \"**/*.{ts,tsx,mdx}\" --cache",
"release": "changeset version",
"pub:beta": "pnpm build && pnpm publish --no-git-checks --access public --tag beta",
"pub:next": "pnpm build && pnpm publish --no-git-checks --access public --tag next",
"pub:release": "pnpm build && pnpm publish --access public",
"test": "vitest run",
"test:dev": "REGISTRY_URL=http://localhost:3333 vitest run"
},
"dependencies": {
"@antfu/ni": "^0.21.4",
"@babel/core": "^7.22.1",
"@babel/parser": "^7.22.6",
"@babel/plugin-transform-typescript": "^7.22.5",
"@noble/curves": "^1.8.1",
"axios": "^1.7.9",
"crypto": "^1.0.1",
"chalk": "5.2.0",
"commander": "^10.0.0",
"cosmiconfig": "^8.1.3",
"diff": "^5.1.0",
"@elizaos/core": "*:workspace",
"execa": "^7.0.0",
"fast-glob": "^3.3.2",
"fs-extra": "^11.1.0",
"https-proxy-agent": "^6.2.0",
"lodash": "^4.17.21",
"node-fetch": "^3.3.0",
"ora": "^6.1.2",
"papaparse": "^5.5.1",
"prompts": "^2.4.2",
"recast": "^0.23.2",
"ts-morph": "^18.0.0",
"tsconfig-paths": "^4.2.0",
"tsx": "^4.19.2",
"zod": "^3.20.2"
},
"devDependencies": {
"@types/babel__core": "^7.20.1",
"@types/diff": "^5.0.3",
"@types/fs-extra": "^11.0.1",
"@types/lodash": "^4.17.7",
"@types/prompts": "^2.4.2",
"rimraf": "^4.1.3",
"tsup": "^6.6.3",
"type-fest": "^3.8.0",
"typescript": "5.6.3"
}
}
Loading

0 comments on commit 1f9beaa

Please sign in to comment.