From 1aee80d5046652f2c4eb9c7d4a25c3046f5b4bc8 Mon Sep 17 00:00:00 2001 From: netdragonx Date: Wed, 18 Dec 2024 01:27:23 -0800 Subject: [PATCH] Fix: optional chaining on search to prevent error when search is uncommented but not enabled in env file. --- packages/client-twitter/src/index.ts | 31 +++++++++++++--------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/packages/client-twitter/src/index.ts b/packages/client-twitter/src/index.ts index b973b84eae..2476afd6d0 100644 --- a/packages/client-twitter/src/index.ts +++ b/packages/client-twitter/src/index.ts @@ -1,42 +1,39 @@ +import { Client, elizaLogger, IAgentRuntime } from "@ai16z/eliza"; +import { ClientBase } from "./base.ts"; +import { validateTwitterConfig } from "./environment.ts"; +import { TwitterInteractionClient } from "./interactions.ts"; import { TwitterPostClient } from "./post.ts"; import { TwitterSearchClient } from "./search.ts"; -import { TwitterInteractionClient } from "./interactions.ts"; -import { IAgentRuntime, Client, elizaLogger } from "@ai16z/eliza"; -import { validateTwitterConfig } from "./environment.ts"; -import { ClientBase } from "./base.ts"; class TwitterManager { client: ClientBase; post: TwitterPostClient; search: TwitterSearchClient; interaction: TwitterInteractionClient; - constructor(runtime: IAgentRuntime, enableSearch:boolean) { + constructor(runtime: IAgentRuntime, enableSearch: boolean) { this.client = new ClientBase(runtime); this.post = new TwitterPostClient(this.client, runtime); if (enableSearch) { - // this searches topics from character file - elizaLogger.warn('Twitter/X client running in a mode that:') - elizaLogger.warn('1. violates consent of random users') - elizaLogger.warn('2. burns your rate limit') - elizaLogger.warn('3. can get your account banned') - elizaLogger.warn('use at your own risk') - this.search = new TwitterSearchClient(this.client, runtime); // don't start the search client by default + // this searches topics from character file + elizaLogger.warn("Twitter/X client running in a mode that:"); + elizaLogger.warn("1. violates consent of random users"); + elizaLogger.warn("2. burns your rate limit"); + elizaLogger.warn("3. can get your account banned"); + elizaLogger.warn("use at your own risk"); + this.search = new TwitterSearchClient(this.client, runtime); } + this.interaction = new TwitterInteractionClient(this.client, runtime); } } export const TwitterClientInterface: Client = { - async start(runtime: IAgentRuntime) { await validateTwitterConfig(runtime); elizaLogger.log("Twitter client started"); - // enableSearch is just set previous to this call - // so enableSearch can change over time - // and changing it won't stop the SearchClient in the existing instance const manager = new TwitterManager(runtime, this.enableSearch); await manager.client.init(); @@ -45,7 +42,7 @@ export const TwitterClientInterface: Client = { await manager.interaction.start(); - //await manager.search.start(); // don't run the search by default + await manager.search?.start(); return manager; },