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

chore: improving client typing #1036

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Resolve bug on optional config
  • Loading branch information
BalanaguYashwanth committed Dec 13, 2024
commit 4c0666f2acea6f5d41960c19c0f2aef7143716da
14 changes: 7 additions & 7 deletions packages/client-twitter/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class ClientBase extends EventEmitter {
super();
this.runtime = runtime;
this.config = config;
const username = this.config.TWITTER_USERNAME || this.runtime.getSetting("TWITTER_USERNAME");
const username = this.config?.TWITTER_USERNAME || this.runtime.getSetting("TWITTER_USERNAME");
if (ClientBase._twitterClients[username]) {
this.twitterClient = ClientBase._twitterClients[username];
} else {
Expand All @@ -157,11 +157,11 @@ export class ClientBase extends EventEmitter {

async init() {
//test
const username = this.config.TWITTER_USERNAME || this.runtime.getSetting("TWITTER_USERNAME");
const password = this.config.TWITTER_PASSWORD || this.runtime.getSetting("TWITTER_PASSWORD");
const email = this.config.TWITTER_EMAIL || this.runtime.getSetting("TWITTER_EMAIL");
const twitter2faSecret = this.config.TWITTER_2FA_SECRET || this.runtime.getSetting("TWITTER_2FA_SECRET") || undefined;
const cookies = this.config.TWITTER_COOKIES || this.runtime.getSetting("TWITTER_COOKIES");
const username = this.config?.TWITTER_USERNAME || this.runtime.getSetting("TWITTER_USERNAME");
const password = this.config?.TWITTER_PASSWORD || this.runtime.getSetting("TWITTER_PASSWORD");
const email = this.config?.TWITTER_EMAIL || this.runtime.getSetting("TWITTER_EMAIL");
const twitter2faSecret = this.config?.TWITTER_2FA_SECRET || this.runtime.getSetting("TWITTER_2FA_SECRET") || undefined;
const cookies = this.config?.TWITTER_COOKIES || this.runtime.getSetting("TWITTER_COOKIES");


if (!username) {
Expand Down Expand Up @@ -475,7 +475,7 @@ export class ClientBase extends EventEmitter {
}

const timeline = await this.fetchHomeTimeline(cachedTimeline ? 10 : 50);
const username = this.config.TWITTER_USERNAME || this.runtime.getSetting("TWITTER_USERNAME");
const username = this.config?.TWITTER_USERNAME || this.runtime.getSetting("TWITTER_USERNAME");

// Get the most recent 20 mentions and interactions
const mentionsAndInteractions = await this.fetchSearchTweets(
Expand Down
12 changes: 6 additions & 6 deletions packages/client-twitter/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,28 @@ export async function validateTwitterConfig(
try {
const twitterConfig = {
TWITTER_DRY_RUN:
config.TWITTER_DRY_RUN ||
config?.TWITTER_DRY_RUN ||
runtime.getSetting("TWITTER_DRY_RUN") ||
process.env.TWITTER_DRY_RUN ||
"false",
TWITTER_USERNAME:
config.TWITTER_USERNAME ||
config?.TWITTER_USERNAME ||
runtime.getSetting("TWITTER_USERNAME") ||
process.env.TWITTER_USERNAME,
TWITTER_PASSWORD:
config.TWITTER_PASSWORD ||
config?.TWITTER_PASSWORD ||
runtime.getSetting("TWITTER_PASSWORD") ||
process.env.TWITTER_PASSWORD,
TWITTER_EMAIL:
config.TWITTER_EMAIL ||
config?.TWITTER_EMAIL ||
runtime.getSetting("TWITTER_EMAIL") ||
process.env.TWITTER_EMAIL,
TWITTER_COOKIES:
config.TWITTER_COOKIES ||
config?.TWITTER_COOKIES ||
runtime.getSetting("TWITTER_COOKIES") ||
process.env.TWITTER_COOKIES,
MAX_TWEET_LENGTH:
config.MAX_TWEET_LENGTH ||
config?.MAX_TWEET_LENGTH ||
runtime.getSetting("MAX_TWEET_LENGTH") ||
process.env.MAX_TWEET_LENGTH ||
DEFAULT_MAX_TWEET_LENGTH.toString(),
Expand Down
10 changes: 5 additions & 5 deletions packages/client-twitter/src/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class TwitterInteractionClient {
setTimeout(
handleTwitterInteractionsLoop,
Number(
this.config.TWITTER_POLL_INTERVAL || this.runtime.getSetting("TWITTER_POLL_INTERVAL") || 120
this.config?.TWITTER_POLL_INTERVAL || this.runtime.getSetting("TWITTER_POLL_INTERVAL") || 120
) * 1000 // Default to 2 minutes
);
};
Expand All @@ -113,7 +113,7 @@ export class TwitterInteractionClient {
async handleTwitterInteractions() {
elizaLogger.log("Checking Twitter interactions");
// Read from environment variable, fallback to default list if not set
const targetUsersStr = this.config.TWITTER_TARGET_USERS || this.runtime.getSetting("TWITTER_TARGET_USERS");
const targetUsersStr = this.config?.TWITTER_TARGET_USERS || this.runtime.getSetting("TWITTER_TARGET_USERS");

const twitterUsername = this.client.profile.username;
try {
Expand Down Expand Up @@ -321,7 +321,7 @@ export class TwitterInteractionClient {

let state = await this.runtime.composeState(message, {
twitterClient: this.client.twitterClient,
twitterUserName: this.config.TWITTER_USERNAME || this.runtime.getSetting("TWITTER_USERNAME"),
twitterUserName: this.config?.TWITTER_USERNAME || this.runtime.getSetting("TWITTER_USERNAME"),
currentPost,
formattedConversation,
});
Expand Down Expand Up @@ -358,7 +358,7 @@ export class TwitterInteractionClient {
}

// 1. Get the raw target users string from settings
const targetUsersStr = this.config.TWITTER_TARGET_USERS || this.runtime.getSetting("TWITTER_TARGET_USERS");
const targetUsersStr = this.config?.TWITTER_TARGET_USERS || this.runtime.getSetting("TWITTER_TARGET_USERS");

// 2. Process the string to get valid usernames
const validTargetUsersStr = targetUsersStr && targetUsersStr.trim()
Expand Down Expand Up @@ -420,7 +420,7 @@ export class TwitterInteractionClient {
this.client,
response,
message.roomId,
this.config.TWITTER_USERNAME || this.runtime.getSetting("TWITTER_USERNAME"),
this.config?.TWITTER_USERNAME || this.runtime.getSetting("TWITTER_USERNAME"),
tweet.id
);
return memories;
Expand Down
4 changes: 2 additions & 2 deletions packages/client-twitter/src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class TwitterPostClient {
this.client = client;
this.runtime = runtime;
this.config = config;
this.twitterUsername = config.TWITTER_USERNAME || runtime.getSetting("TWITTER_USERNAME");
this.twitterUsername = config?.TWITTER_USERNAME || runtime.getSetting("TWITTER_USERNAME");
}

private async generateNewTweet() {
Expand Down Expand Up @@ -279,7 +279,7 @@ export class TwitterPostClient {
// Final cleaning
cleanedContent = removeQuotes(content);

if ((this.config.TWITTER_DRY_RUN || this.runtime.getSetting("TWITTER_DRY_RUN")) === "true") {
if ((this.config?.TWITTER_DRY_RUN || this.runtime.getSetting("TWITTER_DRY_RUN")) === "true") {
elizaLogger.info(
`Dry run: would have posted tweet: ${cleanedContent}`
);
Expand Down
2 changes: 1 addition & 1 deletion packages/client-twitter/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class TwitterSearchClient {
this.client = client;
this.runtime = runtime;
this.config = config;
this.twitterUsername = config.TWITTER_USERNAME || runtime.getSetting("TWITTER_USERNAME");
this.twitterUsername = config?.TWITTER_USERNAME || runtime.getSetting("TWITTER_USERNAME");
}

async start() {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ export interface IAgentConfig {

export type Clients = {
type: ClientType;
config: IAgentConfig;
config?: IAgentConfig;
};

/**
Expand Down
Loading