Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: npm run dev #3446

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build:cli": "turbo run build --filter=./packages/cli && cd packages/cli && bun link",
"start": "turbo run start --filter=!./packages/docs",
"agent": "turbo run start --filter=@elizaos/agent",
"dev": "turbo run dev --filter=!./packages/docs --concurrency=20",
"dev": "bash ./scripts/dev.sh",
"release": "bun run build && bun format && npx lerna publish --no-private --force-publish",
"docker:build": "bash ./scripts/docker.sh build",
"docker:run": "bash ./scripts/docker.sh run",
Expand Down Expand Up @@ -61,6 +61,12 @@
"ws": "8.18.0",
"zod": "3.24.1"
},
"trustedDependencies": [
"@biomejs/biome",
"bun",
"sharp",
"onnxruntime-node"
],
"packageManager": "[email protected]",
"workspaces": [
"packages/*"
Expand Down
10 changes: 8 additions & 2 deletions packages/agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
parseBooleanFromText,
settings,
stringToUuid,
validateCharacterConfig
validateCharacterConfig,
importWithRetry
} from "@elizaos/core";
import fs from "node:fs";
import net from "node:net";
Expand Down Expand Up @@ -342,13 +343,18 @@ function initializeCache(
);
}
}


async function findDatabaseAdapter(runtime: IAgentRuntime) {
const { adapters } = runtime;
let adapter: Adapter | undefined;
// if not found, default to sqlite
if (adapters.length === 0) {
const sqliteAdapterPlugin = await import('@elizaos-plugins/sqlite');
const sqliteAdapterPlugin = await importWithRetry<any>(
'@elizaos-plugins/sqlite',
3,
1000
);
const sqliteAdapterPluginDefault = sqliteAdapterPlugin.default;
adapter = sqliteAdapterPluginDefault.adapters[0];
if (!adapter) {
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ export default defineConfig({
minify: true,
target: "esnext",
outDir: "dist",
external: [
"@elizaos-plugins/sqlite",
// Add other modules you want to externalize
],
})
40 changes: 38 additions & 2 deletions packages/core/src/import.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
import logger from "./logger";

/**
* Attempts to import a module with retry logic.
* @param modulePath - The module path to import.
* @param retries - Number of retry attempts (default: 3).
* @param delay - Delay between retries in milliseconds (default: 1000).
* @returns The imported module.
* @throws An error if all attempts fail.
*/
export async function importWithRetry<T = any>(
modulePath: string,
retries = 3,
delay = 1000
): Promise<T> {
for (let attempt = 1; attempt <= retries; attempt++) {
try {
return await import(modulePath);
} catch (error) {
if (attempt === retries) {
throw new Error(
`Failed to import ${modulePath} after ${retries} attempts: ${error}`
);
}
await new Promise((resolve) => setTimeout(resolve, delay));
}
}
throw new Error("Unexpected error in importWithRetry");
}

const registrations = new Map<string, any>();

export const dynamicImport = async (specifier: string) => {
const module = registrations.get(specifier);
if (module !== undefined) {
return module;
} else {
return await import(specifier);
return await importWithRetry<any>(
specifier,
3,
1000
);
}
};

Expand All @@ -21,7 +53,11 @@ export async function handlePluginImporting(plugins: string[]) {
const importedPlugins = await Promise.all(
plugins.map(async (plugin) => {
try {
const importedPlugin = await import(plugin);
const importedPlugin = await importWithRetry<any>(
plugin,
3,
1000
);
const functionName =
`${plugin
.replace("@elizaos/plugin-", "")
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin-local-ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
"youtube-dl-exec": "3.0.15",
"cookie": "0.7.0"
},
"trustedDependencies": [
"ffmpeg-static",
"node-llama-cpp",
"youtube-dl-exec",
"puppeteer"
],
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
"youtube-dl-exec": "3.0.15",
"cookie": "0.7.0"
},
"trustedDependencies": [
"ffmpeg-static",
"node-llama-cpp",
"youtube-dl-exec",
"puppeteer"
],
"devDependencies": {
"@types/node": "22.8.4",
"tsup": "8.3.5"
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin-sqlite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"better-sqlite3": "11.8.1",
"sqlite-vec": "0.1.6"
},
"trustedDependencies": [
"better-sqlite3"
],
"devDependencies": {
"tsup": "8.3.5",
"vitest": "^3.0.2",
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin-tee/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"better-sqlite3": "11.8.1",
"elliptic": "6.6.1"
},
"trustedDependencies": [
"better-sqlite3"
],
"devDependencies": {
"@biomejs/biome": "1.5.3",
"@types/node": "^20.0.0",
Expand Down
25 changes: 25 additions & 0 deletions scripts/dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Define an array of commands to run.
COMMANDS=(
"turbo run build --filter=!./packages/docs && turbo run dev --filter=./packages/core"
"turbo run dev --filter=./packages/plugin-sqlite"
"turbo run dev \
--filter=!./packages/agent \
--filter=!./packages/cli \
--filter=!./packages/docs \
--filter=!./packages/core \
--filter=!./packages/plugin-sqlite \
--concurrency=20"
"turbo run dev --filter=./packages/agent --filter=./packages/cli"
)

# Loop over each command and run it in the background
for cmd in "${COMMANDS[@]}"; do
eval "$cmd" &

sleep 3 # Delay before starting the next command
done
tcm390 marked this conversation as resolved.
Show resolved Hide resolved

# Wait for all background jobs to keep the script running
wait
Loading