Skip to content

Commit

Permalink
Merge pull request elizaOS#2 from bmgalego/web-agent
Browse files Browse the repository at this point in the history
feat: Web Agent
  • Loading branch information
ponderingdemocritus authored Nov 26, 2024
2 parents 236943f + 3064604 commit 76b741b
Show file tree
Hide file tree
Showing 274 changed files with 22,966 additions and 2,858 deletions.
22 changes: 22 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,27 @@ STARKNET_ADDRESS=
STARKNET_PRIVATE_KEY=
STARKNET_RPC_URL=

# Coinbase
COINBASE_COMMERCE_KEY= # from coinbase developer portal
COINBASE_API_KEY= # from coinbase developer portal
COINBASE_PRIVATE_KEY= # from coinbase developer portal
# if not configured it will be generated and written to runtime.character.settings.secrets.COINBASE_GENERATED_WALLET_ID and runtime.character.settings.secrets.COINBASE_GENERATED_WALLET_HEX_SEED
COINBASE_GENERATED_WALLET_ID= # not your address but the wallet id from generating a wallet through the plugin
COINBASE_GENERATED_WALLET_HEX_SEED= # not your address but the wallet hex seed from generating a wallet through the plugin and calling export

# Conflux Configuration
CONFLUX_CORE_PRIVATE_KEY=
CONFLUX_CORE_SPACE_RPC_URL=
CONFLUX_ESPACE_PRIVATE_KEY=
CONFLUX_ESPACE_RPC_URL=
CONFLUX_MEME_CONTRACT_ADDRESS=

#ZeroG
ZEROG_INDEXER_RPC=
ZEROG_EVM_RPC=
ZEROG_PRIVATE_KEY=
ZEROG_FLOW_ADDRESS=

# Coinbase Commerce
COINBASE_COMMERCE_KEY=

4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:
echo "TEST_DATABASE_CLIENT=sqlite" > packages/core/.env.test
echo "NODE_ENV=test" >> packages/core/.env.test
# - name: Run tests
# run: cd packages/core && pnpm test // YOLO FOR NOW
- name: Run tests
run: cd packages/core && pnpm test

- name: Build packages
run: pnpm run build
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ characters/
packages/core/src/providers/cache
packages/core/src/providers/cache/*
cache/*
packages/plugin-coinbase/src/plugins/transactions.csv
packages/plugin-coinbase/package-lock.json
12 changes: 0 additions & 12 deletions .husky/commit-msg

This file was deleted.

2 changes: 0 additions & 2 deletions .husky/pre-commit

This file was deleted.

8 changes: 5 additions & 3 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@
"@ai16z/client-twitter": "workspace:*",
"@ai16z/eliza": "workspace:*",
"@ai16z/plugin-bootstrap": "workspace:*",
"@ai16z/plugin-conflux": "workspace:*",
"@ai16z/plugin-image-generation": "workspace:*",
"@ai16z/plugin-node": "workspace:*",
"@ai16z/plugin-solana": "workspace:*",
"@ai16z/plugin-0g": "workspace:*",
"@ai16z/plugin-starknet": "workspace:*",
"@ai16z/plugin-coinbase": "workspace:*",
"readline": "^1.3.0",
"ws": "^8.18.0",
"readline": "1.3.0",
"ws": "8.18.0",
"yargs": "17.7.2"
},
"devDependencies": {
"ts-node": "10.9.2",
"tsup": "^8.3.5"
"tsup": "8.3.5"
}
}
29 changes: 23 additions & 6 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ import {
validateCharacterConfig,
} from "@ai16z/eliza";
import { bootstrapPlugin } from "@ai16z/plugin-bootstrap";
import { confluxPlugin } from "@ai16z/plugin-conflux";
import { solanaPlugin } from "@ai16z/plugin-solana";
import { zgPlugin } from "@ai16z/plugin-0g";
import { nodePlugin } from "@ai16z/plugin-node";
import { coinbaseCommercePlugin } from "@ai16z/plugin-coinbase";
import {
coinbaseCommercePlugin,
coinbaseMassPaymentsPlugin,
} from "@ai16z/plugin-coinbase";
import Database from "better-sqlite3";
import fs from "fs";
import readline from "readline";
Expand Down Expand Up @@ -178,6 +183,7 @@ function initializeDatabase(dataDir: string) {
if (process.env.POSTGRES_URL) {
const db = new PostgresDatabaseAdapter({
connectionString: process.env.POSTGRES_URL,
parseInputs: true,
});
return db;
} else {
Expand Down Expand Up @@ -229,6 +235,10 @@ export async function initializeClients(
return clients;
}

function getSecret(character: Character, secret: string) {
return character.settings.secrets?.[secret] || process.env[secret];
}

export function createAgent(
character: Character,
db: IDatabaseAdapter,
Expand All @@ -248,12 +258,19 @@ export function createAgent(
character,
plugins: [
bootstrapPlugin,
getSecret(character, "CONFLUX_CORE_PRIVATE_KEY")
? confluxPlugin
: null,
nodePlugin,
character.settings.secrets?.WALLET_PUBLIC_KEY ? solanaPlugin : null,
character.settings.secrets?.COINBASE_COMMERCE_KEY ||
process.env.COINBASE_COMMERCE_KEY
getSecret(character, "WALLET_PUBLIC_KEY") ? solanaPlugin : null,
getSecret(character, "ZEROG_PRIVATE_KEY") ? zgPlugin : null,
getSecret(character, "COINBASE_COMMERCE_KEY")
? coinbaseCommercePlugin
: null,
getSecret(character, "COINBASE_API_KEY") &&
getSecret(character, "COINBASE_PRIVATE_KEY")
? coinbaseMassPaymentsPlugin
: null,
].filter(Boolean),
providers: [],
actions: [],
Expand All @@ -275,7 +292,7 @@ function intializeDbCache(character: Character, db: IDatabaseCacheAdapter) {
return cache;
}

async function startAgent(character: Character, directClient: DirectClient) {
async function startAgent(character: Character, directClient: any) {
try {
character.id ??= stringToUuid(character.name);
character.username ??= character.name;
Expand Down Expand Up @@ -325,7 +342,7 @@ const startAgents = async () => {

try {
for (const character of characters) {
await startAgent(character, directClient as DirectClient);
await startAgent(character, directClient as any);
}
} catch (error) {
elizaLogger.error("Error starting agents:", error);
Expand Down
50 changes: 0 additions & 50 deletions client/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<title>Eliza</title>
</head>
<body>
<div id="root"></div>
Expand Down
47 changes: 26 additions & 21 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "eliza",
"name": "eliza-client",
"private": true,
"version": "0.0.0",
"type": "module",
Expand All @@ -11,32 +11,37 @@
},
"dependencies": {
"@ai16z/eliza": "workspace:*",
"@radix-ui/react-slot": "^1.1.0",
"class-variance-authority": "^0.7.0",
"@radix-ui/react-dialog": "1.1.2",
"@radix-ui/react-separator": "1.1.0",
"@radix-ui/react-slot": "1.1.0",
"@radix-ui/react-tooltip": "1.1.4",
"@tanstack/react-query": "5.61.0",
"class-variance-authority": "0.7.0",
"clsx": "2.1.0",
"lucide-react": "^0.460.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"tailwind-merge": "^2.5.4",
"tailwindcss-animate": "^1.0.7",
"vite-plugin-top-level-await": "^1.4.4",
"vite-plugin-wasm": "^3.3.0"
"lucide-react": "0.460.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-router-dom": "6.22.1",
"tailwind-merge": "2.5.4",
"tailwindcss-animate": "1.0.7",
"vite-plugin-top-level-await": "1.4.4",
"vite-plugin-wasm": "3.3.0"
},
"devDependencies": {
"@eslint/js": "^9.13.0",
"@eslint/js": "9.15.0",
"@types/node": "22.8.4",
"@types/react": "18.3.12",
"@types/react-dom": "18.3.1",
"@vitejs/plugin-react": "^4.3.3",
"autoprefixer": "^10.4.20",
"eslint": "^9.13.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"globals": "^15.11.0",
"postcss": "^8.4.49",
"tailwindcss": "^3.4.15",
"@vitejs/plugin-react": "4.3.3",
"autoprefixer": "10.4.20",
"eslint": "9.13.0",
"eslint-plugin-react-hooks": "5.0.0",
"eslint-plugin-react-refresh": "0.4.14",
"globals": "15.11.0",
"postcss": "8.4.49",
"tailwindcss": "3.4.15",
"typescript": "~5.6.2",
"typescript-eslint": "^8.11.0",
"vite": "^5.4.10"
"typescript-eslint": "8.11.0",
"vite": "link:@tanstack/router-plugin/vite"
}
}
10 changes: 10 additions & 0 deletions client/src/Agent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default function Agent() {
return (
<div className="min-h-screen flex flex-col items-center justify-center p-4">
<p className="text-lg text-gray-600">
Select an option from the sidebar to configure, view, or chat
with your ELIZA agent
</p>
</div>
);
}
47 changes: 47 additions & 0 deletions client/src/Agents.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { useQuery } from "@tanstack/react-query";
import { Button } from "@/components/ui/button";
import { useNavigate } from "react-router-dom";
import "./App.css";

type Agent = {
id: string;
name: string;
};

function Agents() {
const navigate = useNavigate();
const { data: agents, isLoading } = useQuery({
queryKey: ["agents"],
queryFn: async () => {
const res = await fetch("/api/agents");
const data = await res.json();
return data.agents as Agent[];
},
});

return (
<div className="min-h-screen flex flex-col items-center justify-center p-4">
<h1 className="text-2xl font-bold mb-8">Select your agent:</h1>

{isLoading ? (
<div>Loading agents...</div>
) : (
<div className="grid gap-4 w-full max-w-md">
{agents?.map((agent) => (
<Button
key={agent.id}
className="w-full text-lg py-6"
onClick={() => {
navigate(`/${agent.id}`);
}}
>
{agent.name}
</Button>
))}
</div>
)}
</div>
);
}

export default Agents;
1 change: 0 additions & 1 deletion client/src/App.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

Expand Down
Loading

0 comments on commit 76b741b

Please sign in to comment.