diff --git a/agent/package.json b/agent/package.json index 0407dc13d3f..2cbc1bdfeb4 100644 --- a/agent/package.json +++ b/agent/package.json @@ -18,7 +18,6 @@ "exec": "node --enable-source-maps --loader ts-node/esm src/index.ts" }, "dependencies": { - "@elizaos/cache-redis": "workspace:*", "@elizaos/client-direct": "workspace:*", "@elizaos/plugin-bootstrap": "workspace:*", "@elizaos/core": "workspace:*", diff --git a/agent/src/index.ts b/agent/src/index.ts index 5f5f84edc46..0c0e029770c 100644 --- a/agent/src/index.ts +++ b/agent/src/index.ts @@ -1,7 +1,7 @@ // import { PGLiteDatabaseAdapter } from "@elizaos/adapter-pglite"; // import { PostgresDatabaseAdapter } from "@elizaos/adapter-postgres"; // import { QdrantDatabaseAdapter } from "@elizaos/adapter-qdrant"; -import { RedisClient } from "@elizaos/cache-redis"; +// import { RedisClient } from "@elizaos/cache-redis"; // import { SqliteDatabaseAdapter } from "@elizaos/adapter-sqlite"; // import { SupabaseDatabaseAdapter } from "@elizaos/adapter-supabase"; // import { AutoClientInterface } from "@elizaos/client-auto"; @@ -1050,21 +1050,21 @@ function initializeCache( db?: IDatabaseCacheAdapter ) { switch (cacheStore) { - case CacheStore.REDIS: - if (process.env.REDIS_URL) { - elizaLogger.info("Connecting to Redis..."); - const redisClient = new RedisClient(process.env.REDIS_URL); - if (!character?.id) { - throw new Error( - "CacheStore.REDIS requires id to be set in character definition" - ); - } - return new CacheManager( - new DbCacheAdapter(redisClient, character.id) // Using DbCacheAdapter since RedisClient also implements IDatabaseCacheAdapter - ); - } else { - throw new Error("REDIS_URL environment variable is not set."); - } + // case CacheStore.REDIS: + // if (process.env.REDIS_URL) { + // elizaLogger.info("Connecting to Redis..."); + // const redisClient = new RedisClient(process.env.REDIS_URL); + // if (!character?.id) { + // throw new Error( + // "CacheStore.REDIS requires id to be set in character definition" + // ); + // } + // return new CacheManager( + // new DbCacheAdapter(redisClient, character.id) // Using DbCacheAdapter since RedisClient also implements IDatabaseCacheAdapter + // ); + // } else { + // throw new Error("REDIS_URL environment variable is not set."); + // } case CacheStore.DATABASE: if (db) { diff --git a/packages/cache-redis/.npmignore b/packages/cache-redis/.npmignore deleted file mode 100644 index 078562eceab..00000000000 --- a/packages/cache-redis/.npmignore +++ /dev/null @@ -1,6 +0,0 @@ -* - -!dist/** -!package.json -!readme.md -!tsup.config.ts \ No newline at end of file diff --git a/packages/cache-redis/__tests__/redis-adapter.test.ts b/packages/cache-redis/__tests__/redis-adapter.test.ts deleted file mode 100644 index dff80d0837e..00000000000 --- a/packages/cache-redis/__tests__/redis-adapter.test.ts +++ /dev/null @@ -1,183 +0,0 @@ -import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; -import { RedisClient } from '../src'; -import { type UUID, elizaLogger } from '@elizaos/core'; -import Redis from 'ioredis'; - -// Mock ioredis -vi.mock('ioredis', () => { - const MockRedis = vi.fn(() => ({ - on: vi.fn(), - get: vi.fn(), - set: vi.fn(), - del: vi.fn(), - quit: vi.fn() - })); - return { default: MockRedis }; -}); - -// Mock elizaLogger -vi.mock('@elizaos/core', async () => { - const actual = await vi.importActual('@elizaos/core'); - return { - ...actual as any, - elizaLogger: { - success: vi.fn(), - error: vi.fn() - } - }; -}); - -describe('RedisClient', () => { - let client: RedisClient; - let mockRedis: any; - - beforeEach(() => { - vi.clearAllMocks(); - client = new RedisClient('redis://localhost:6379'); - // Get the instance created by the constructor - mockRedis = (Redis as unknown as ReturnType).mock.results[0].value; - }); - - afterEach(() => { - vi.clearAllMocks(); - }); - - describe('constructor', () => { - it('should set up event handlers', () => { - expect(mockRedis.on).toHaveBeenCalledWith('connect', expect.any(Function)); - expect(mockRedis.on).toHaveBeenCalledWith('error', expect.any(Function)); - }); - - it('should log success on connect', () => { - const connectHandler = mockRedis.on.mock.calls.find(call => call[0] === 'connect')[1]; - connectHandler(); - expect(elizaLogger.success).toHaveBeenCalledWith('Connected to Redis'); - }); - - it('should log error on error event', () => { - const error = new Error('Redis connection error'); - const errorHandler = mockRedis.on.mock.calls.find(call => call[0] === 'error')[1]; - errorHandler(error); - expect(elizaLogger.error).toHaveBeenCalledWith('Redis error:', error); - }); - }); - - describe('getCache', () => { - const agentId = 'test-agent' as UUID; - const key = 'test-key'; - const expectedRedisKey = `${agentId}:${key}`; - - it('should return cached value when it exists', async () => { - const cachedValue = 'cached-data'; - mockRedis.get.mockResolvedValueOnce(cachedValue); - - const result = await client.getCache({ agentId, key }); - - expect(mockRedis.get).toHaveBeenCalledWith(expectedRedisKey); - expect(result).toBe(cachedValue); - }); - - it('should return undefined when key does not exist', async () => { - mockRedis.get.mockResolvedValueOnce(null); - - const result = await client.getCache({ agentId, key }); - - expect(mockRedis.get).toHaveBeenCalledWith(expectedRedisKey); - expect(result).toBeUndefined(); - }); - - it('should handle errors and return undefined', async () => { - const error = new Error('Redis error'); - mockRedis.get.mockRejectedValueOnce(error); - - const result = await client.getCache({ agentId, key }); - - expect(mockRedis.get).toHaveBeenCalledWith(expectedRedisKey); - expect(elizaLogger.error).toHaveBeenCalledWith('Error getting cache:', error); - expect(result).toBeUndefined(); - }); - }); - - describe('setCache', () => { - const agentId = 'test-agent' as UUID; - const key = 'test-key'; - const value = 'test-value'; - const expectedRedisKey = `${agentId}:${key}`; - - it('should successfully set cache value', async () => { - mockRedis.set.mockResolvedValueOnce('OK'); - - const result = await client.setCache({ agentId, key, value }); - - expect(mockRedis.set).toHaveBeenCalledWith(expectedRedisKey, value); - expect(result).toBe(true); - }); - - it('should handle errors and return false', async () => { - const error = new Error('Redis error'); - mockRedis.set.mockRejectedValueOnce(error); - - const result = await client.setCache({ agentId, key, value }); - - expect(mockRedis.set).toHaveBeenCalledWith(expectedRedisKey, value); - expect(elizaLogger.error).toHaveBeenCalledWith('Error setting cache:', error); - expect(result).toBe(false); - }); - }); - - describe('deleteCache', () => { - const agentId = 'test-agent' as UUID; - const key = 'test-key'; - const expectedRedisKey = `${agentId}:${key}`; - - it('should successfully delete cache when key exists', async () => { - mockRedis.del.mockResolvedValueOnce(1); - - const result = await client.deleteCache({ agentId, key }); - - expect(mockRedis.del).toHaveBeenCalledWith(expectedRedisKey); - expect(result).toBe(true); - }); - - it('should return false when key does not exist', async () => { - mockRedis.del.mockResolvedValueOnce(0); - - const result = await client.deleteCache({ agentId, key }); - - expect(mockRedis.del).toHaveBeenCalledWith(expectedRedisKey); - expect(result).toBe(false); - }); - - it('should handle errors and return false', async () => { - const error = new Error('Redis error'); - mockRedis.del.mockRejectedValueOnce(error); - - const result = await client.deleteCache({ agentId, key }); - - expect(mockRedis.del).toHaveBeenCalledWith(expectedRedisKey); - expect(elizaLogger.error).toHaveBeenCalledWith('Error deleting cache:', error); - expect(result).toBe(false); - }); - }); - - describe('disconnect', () => { - it('should successfully disconnect from Redis', async () => { - mockRedis.quit.mockResolvedValueOnce('OK'); - - await client.disconnect(); - - expect(mockRedis.quit).toHaveBeenCalled(); - expect(elizaLogger.success).toHaveBeenCalledWith('Disconnected from Redis'); - }); - - it('should handle disconnect errors', async () => { - const error = new Error('Redis disconnect error'); - mockRedis.quit.mockRejectedValueOnce(error); - - await client.disconnect(); - - expect(mockRedis.quit).toHaveBeenCalled(); - expect(elizaLogger.error).toHaveBeenCalledWith('Error disconnecting from Redis:', error); - }); - }); -}); diff --git a/packages/cache-redis/package.json b/packages/cache-redis/package.json deleted file mode 100644 index aef18d44701..00000000000 --- a/packages/cache-redis/package.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "name": "@elizaos/cache-redis", - "version": "0.25.6-alpha.1", - "type": "module", - "main": "dist/index.js", - "module": "dist/index.js", - "types": "dist/index.d.ts", - "exports": { - "./package.json": "./package.json", - ".": { - "import": { - "@elizaos/source": "./src/index.ts", - "types": "./dist/index.d.ts", - "default": "./dist/index.js" - } - } - }, - "files": [ - "dist" - ], - "dependencies": { - "@elizaos/core": "workspace:*", - "ioredis": "5.4.2" - }, - "devDependencies": { - "@types/ioredis": "^5.0.0", - "tsup": "8.3.5", - "vitest": "^3.0.2" - }, - "scripts": { - "build": "tsup --format esm --dts", - "dev": "tsup --format esm --dts --watch", - "test": "vitest run", - "test:watch": "vitest" - }, - "peerDependencies": { - "whatwg-url": "7.1.0" - } -} diff --git a/packages/cache-redis/src/index.ts b/packages/cache-redis/src/index.ts deleted file mode 100644 index c993d8cec14..00000000000 --- a/packages/cache-redis/src/index.ts +++ /dev/null @@ -1,76 +0,0 @@ -import Redis from "ioredis"; -import { type IDatabaseCacheAdapter, type UUID, elizaLogger } from "@elizaos/core"; - -export class RedisClient implements IDatabaseCacheAdapter { - private client: Redis; - - constructor(redisUrl: string) { - this.client = new Redis(redisUrl); - - this.client.on("connect", () => { - elizaLogger.success("Connected to Redis"); - }); - - this.client.on("error", (err) => { - elizaLogger.error("Redis error:", err); - }); - } - - async getCache(params: { - agentId: UUID; - key: string; - }): Promise { - try { - const redisKey = this.buildKey(params.agentId, params.key); - const value = await this.client.get(redisKey); - return value || undefined; - } catch (err) { - elizaLogger.error("Error getting cache:", err); - return undefined; - } - } - - async setCache(params: { - agentId: UUID; - key: string; - value: string; - }): Promise { - try { - const redisKey = this.buildKey(params.agentId, params.key); - await this.client.set(redisKey, params.value); - return true; - } catch (err) { - elizaLogger.error("Error setting cache:", err); - return false; - } - } - - async deleteCache(params: { - agentId: UUID; - key: string; - }): Promise { - try { - const redisKey = this.buildKey(params.agentId, params.key); - const result = await this.client.del(redisKey); - return result > 0; - } catch (err) { - elizaLogger.error("Error deleting cache:", err); - return false; - } - } - - async disconnect(): Promise { - try { - await this.client.quit(); - elizaLogger.success("Disconnected from Redis"); - } catch (err) { - elizaLogger.error("Error disconnecting from Redis:", err); - } - } - - private buildKey(agentId: UUID, key: string): string { - return `${agentId}:${key}`; // Constructs a unique key based on agentId and key - } -} - -export default RedisClient; diff --git a/packages/cache-redis/tsconfig.json b/packages/cache-redis/tsconfig.json deleted file mode 100644 index 005fbac9d36..00000000000 --- a/packages/cache-redis/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../core/tsconfig.json", - "compilerOptions": { - "outDir": "dist", - "rootDir": "src" - }, - "include": ["src/**/*.ts"] -} diff --git a/packages/cache-redis/tsup.config.ts b/packages/cache-redis/tsup.config.ts deleted file mode 100644 index 9acebc5ba9a..00000000000 --- a/packages/cache-redis/tsup.config.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { defineConfig } from "tsup"; - -export default defineConfig({ - entry: ["src/index.ts"], - outDir: "dist", - sourcemap: true, - clean: true, - format: ["esm"], // Ensure you're targeting CommonJS - external: [ - "dotenv", // Externalize dotenv to prevent bundling - "fs", // Externalize fs to use Node.js built-in module - "path", // Externalize other built-ins if necessary - "@reflink/reflink", - "@node-llama-cpp", - "https", - "http", - "agentkeepalive", - "uuid", - // Add other modules you want to externalize - ], -}); diff --git a/packages/cache-redis/vitest.config.ts b/packages/cache-redis/vitest.config.ts deleted file mode 100644 index adbf7255380..00000000000 --- a/packages/cache-redis/vitest.config.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { defineConfig } from 'vitest/config'; - -export default defineConfig({ - test: { - globals: true, - environment: 'node', - }, -}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 11b645a7662..a548376a2de 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -127,9 +127,6 @@ importers: agent: dependencies: - '@elizaos/cache-redis': - specifier: workspace:* - version: link:../packages/cache-redis '@elizaos/client-direct': specifier: workspace:* version: link:../packages/client-direct @@ -537,28 +534,6 @@ importers: specifier: ^3.0.2 version: 3.0.5(@types/debug@4.1.12)(@types/node@22.13.1)(jsdom@25.0.1(bufferutil@4.0.9)(canvas@2.11.2(encoding@0.1.13))(utf-8-validate@6.0.5))(terser@5.38.1) - packages/cache-redis: - dependencies: - '@elizaos/core': - specifier: workspace:* - version: link:../core - ioredis: - specifier: 5.4.2 - version: 5.4.2 - whatwg-url: - specifier: 7.1.0 - version: 7.1.0 - devDependencies: - '@types/ioredis': - specifier: ^5.0.0 - version: 5.0.0 - tsup: - specifier: 8.3.5 - version: 8.3.5(@swc/core@1.10.14(@swc/helpers@0.5.15))(jiti@2.4.2)(postcss@8.5.1)(tsx@4.19.2)(typescript@5.7.3)(yaml@2.7.0) - vitest: - specifier: ^3.0.2 - version: 3.0.5(@types/debug@4.1.12)(@types/node@22.13.1)(jsdom@25.0.1(bufferutil@4.0.9)(canvas@2.11.2(encoding@0.1.13))(utf-8-validate@6.0.5))(terser@5.38.1) - packages/client-alexa: dependencies: '@elizaos/core':