Skip to content

Commit 5ff1eb8

Browse files
committed
Merge branch 'hash/fix-plugins-install' of http://github.com/ai16z/eliza into HEAD
2 parents 71d9cae + 75528d9 commit 5ff1eb8

File tree

5 files changed

+65
-19
lines changed

5 files changed

+65
-19
lines changed

packages/cli/.env.example

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
# No configuration needed for SQLite
1+
# No configuration needed for SQLite
2+
ELIZA_BRANCH=v2-develop

packages/cli/src/commands/init.ts

+9-14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { handleError } from "@/src/utils/handle-error"
55
import { logger } from "@/src/utils/logger"
66
import { getAvailableDatabases, getRegistryIndex, listPluginsByType } from "@/src/utils/registry"
77
import { createDatabaseTemplate, createPluginsTemplate, createEnvTemplate } from "@/src/utils/templates"
8+
import { runBunCommand } from "@/src/utils/run-bun"
9+
import { installPlugin } from "@/src/utils/install-plugin"
810
import chalk from "chalk"
911
import { Command } from "commander"
1012
import { execa } from "execa"
@@ -18,7 +20,7 @@ const initOptionsSchema = z.object({
1820

1921
async function cloneStarterRepo(targetDir: string) {
2022
logger.info("Setting up project structure...")
21-
await execa("git", ["clone", "-b", process.env.ELIZA_BRANCH ?? "v2-develop", "https://github.com/elizaos/eliza", "."], {
23+
await execa("git", ["clone", "-b", process.env.ELIZA_BRANCH || "v2-develop", "https://github.com/elizaos/eliza", "."], {
2224
cwd: targetDir,
2325
stdio: "inherit",
2426
})
@@ -74,21 +76,14 @@ async function installDependencies(targetDir: string, database: string, selected
7476
})
7577

7678
// Use bun for installation
77-
await execa("bun", ["install", "--no-frozen-lockfile"], {
78-
cwd: targetDir,
79-
stdio: "inherit"
80-
})
81-
82-
await execa("bun", ["add", `@elizaos/adapter-${database}`, "--workspace-root"], {
83-
cwd: targetDir,
84-
stdio: "inherit"
85-
})
79+
await runBunCommand(["install", "--no-frozen-lockfile"], targetDir);
80+
await runBunCommand(["add", `@elizaos/adapter-${database}`, "--workspace-root"], targetDir);
8681

8782
if (selectedPlugins.length > 0) {
88-
await execa("bun", ["add", ...selectedPlugins, "--workspace-root"], {
89-
cwd: targetDir,
90-
stdio: "inherit"
91-
})
83+
console.log(selectedPlugins)
84+
for (const plugin of selectedPlugins) {
85+
await installPlugin(plugin, targetDir)
86+
}
9287
}
9388
}
9489

packages/cli/src/commands/plugins.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { logger } from "@/src/utils/logger"
44
import { getPluginRepository, getRegistryIndex } from "@/src/utils/registry"
55
import { Command } from "commander"
66
import { execa } from "execa"
7+
import { installPlugin } from "@/src/utils/install-plugin"
78

89
export const plugins = new Command()
910
.name("plugins")
@@ -58,10 +59,7 @@ plugins
5859

5960
// Install from GitHub
6061
logger.info(`Installing ${plugin}...`)
61-
await execa("bun", ["add", repo], {
62-
cwd,
63-
stdio: "inherit"
64-
})
62+
await installPlugin(repo, cwd)
6563

6664
logger.success(`Successfully installed ${plugin}`)
6765

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { execa } from "execa";
2+
import path from "node:path";
3+
import { logger } from "@/src/utils/logger";
4+
import { runBunCommand } from "@/src/utils/run-bun";
5+
import { promises as fs } from "fs";
6+
7+
export async function installPlugin(
8+
pluginName: string,
9+
cwd: string,
10+
): Promise<void> {
11+
// Remove 'github:' or leading '@' prefix if present
12+
const cleanedName = pluginName.replace(/^github:|^@/, "");
13+
let installed = false;
14+
try {
15+
//logger.info(`Attempting to install ${pluginName} using bun add...`);
16+
//await runBunCommand(["add", `${pluginName}`], cwd);
17+
//logger.success(`Successfully installed ${pluginName} via bun add.`);
18+
//installed = true;
19+
// Set the directory to clone into the packages folder (each plugin gets its own subfolder)
20+
const cloneDir = path.join(cwd, "packages", cleanedName.replace(/\S+\//, ""));
21+
logger.info(`Cloning ${pluginName} from https://github.com/${cleanedName}.git to ${cloneDir}`);
22+
await execa("git",["clone", `https://github.com/${cleanedName}.git`, cloneDir],{ cwd, stdio: "inherit" });
23+
logger.success(`Successfully cloned repository for ${cleanedName}.`);
24+
installed = true;
25+
} catch (error: any) {
26+
logger.warn(
27+
`failed to install packages for ${cleanedName}, falling back: ${error.message}`
28+
);
29+
}
30+
31+
if (installed) {
32+
// Try to read the package.json file from the cloned plugin repo
33+
let pkgName = cleanedName;
34+
const pkgPath = path.join(cwd, "packages", cleanedName.replace(/\S+\//, ""), "package.json");
35+
try {
36+
const pkgContent = await fs.readFile(pkgPath, "utf-8");
37+
const pkg = JSON.parse(pkgContent);
38+
if (pkg.name) {
39+
pkgName = pkg.name;
40+
logger.info(`Found package.json name: ${pkgName}`);
41+
logger.info(`Add ${pkgName} to your character's plugins config (packages/agent/defaultCharacter.ts)`);
42+
}
43+
} catch (err: any) {
44+
logger.warn(`Could not read package.json from ${pkgPath}: ${err.message}`);
45+
}
46+
}
47+
}

packages/cli/src/utils/run-bun.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { execa } from "execa";
2+
3+
export async function runBunCommand(args: string[], cwd: string): Promise<void> {
4+
await execa("bun", args, { cwd, stdio: "inherit" });
5+
}

0 commit comments

Comments
 (0)