From 1aa0ecb0885925aec3a2b0c9abef7b45a1a5a03e Mon Sep 17 00:00:00 2001 From: Ting Chien Meng Date: Wed, 12 Feb 2025 11:09:23 +0800 Subject: [PATCH] remove retry import --- packages/agent/src/index.ts | 5 ++--- packages/core/src/import.ts | 32 ++------------------------------ 2 files changed, 4 insertions(+), 33 deletions(-) diff --git a/packages/agent/src/index.ts b/packages/agent/src/index.ts index 5429f3f2946..9136a06bf7c 100644 --- a/packages/agent/src/index.ts +++ b/packages/agent/src/index.ts @@ -16,8 +16,7 @@ import { parseBooleanFromText, settings, stringToUuid, - validateCharacterConfig, - importWithRetry + validateCharacterConfig } from "@elizaos/core"; import fs from "node:fs"; import net from "node:net"; @@ -350,7 +349,7 @@ async function findDatabaseAdapter(runtime: IAgentRuntime) { let adapter: Adapter | undefined; // if not found, default to sqlite if (adapters.length === 0) { - const sqliteAdapterPlugin = await importWithRetry('@elizaos-plugins/sqlite'); + const sqliteAdapterPlugin = await import('@elizaos-plugins/sqlite'); const sqliteAdapterPluginDefault = sqliteAdapterPlugin.default; adapter = sqliteAdapterPluginDefault.adapters[0]; if (!adapter) { diff --git a/packages/core/src/import.ts b/packages/core/src/import.ts index 01a78034dc4..fd7adb9117f 100644 --- a/packages/core/src/import.ts +++ b/packages/core/src/import.ts @@ -1,33 +1,5 @@ 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( - modulePath: string, - retries = 3, - delay = 1000 -): Promise { - 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(); export const dynamicImport = async (specifier: string) => { @@ -35,7 +7,7 @@ export const dynamicImport = async (specifier: string) => { if (module !== undefined) { return module; } else { - return await importWithRetry(specifier); + return await import(specifier); } }; @@ -49,7 +21,7 @@ export async function handlePluginImporting(plugins: string[]) { const importedPlugins = await Promise.all( plugins.map(async (plugin) => { try { - const importedPlugin = await importWithRetry(plugin); + const importedPlugin = await import(plugin); const functionName = `${plugin .replace("@elizaos/plugin-", "")