Skip to content

Commit

Permalink
Merge branch 'develop' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
monilpat authored Dec 21, 2024
2 parents 2f28710 + 5c1fe07 commit f603fea
Show file tree
Hide file tree
Showing 30 changed files with 87 additions and 123 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_2FA_SECRET=

TWITTER_COOKIES= # Account cookies
TWITTER_POLL_INTERVAL=120 # How often (in seconds) the bot should check for interactions
TWITTER_SEARCH_ENABLE=FALSE # Enable timeline search, WARNING this greatly increases your chance of getting banned
TWITTER_TARGET_USERS= # Comma separated list of Twitter user names to interact with
Expand Down
1 change: 0 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion README_ES.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Nombre de usuario de la cuenta
TWITTER_PASSWORD= # Contraseña de la cuenta
TWITTER_EMAIL= # Correo electrónico de la cuenta
TWITTER_COOKIES= # Cookies de la cuenta
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion README_JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # アカウントのユーザー名
TWITTER_PASSWORD= # アカウントのパスワード
TWITTER_EMAIL= # アカウントのメール
TWITTER_COOKIES= # アカウントのクッキー
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion README_PTBR.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Nome de usuário da conta
TWITTER_PASSWORD= # Senha da conta
TWITTER_EMAIL= # Email da conta
TWITTER_COOKIES= # Cookies da conta
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion README_RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Имя пользователя аккаунта
TWITTER_PASSWORD= # Пароль аккаунта
TWITTER_EMAIL= # Email аккаунта
TWITTER_COOKIES= # Cookies аккаунта
X_SERVER_URL=
XAI_API_KEY=
Expand Down
11 changes: 9 additions & 2 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,11 @@ export function getTokenForProvider(
character: Character
): string {
switch (provider) {
// no key needed for llama_local
// no key needed for llama_local or gaianet
case ModelProviderName.LLAMALOCAL:
return "";
case ModelProviderName.GAIANET:
return "";
case ModelProviderName.OPENAI:
return (
character.settings?.secrets?.OPENAI_API_KEY ||
Expand Down Expand Up @@ -311,6 +313,11 @@ export function getTokenForProvider(
character.settings?.secrets?.AKASH_CHAT_API_KEY ||
settings.AKASH_CHAT_API_KEY
);
case ModelProviderName.GOOGLE:
return (
character.settings?.secrets?.GOOGLE_GENERATIVE_AI_API_KEY ||
settings.GOOGLE_GENERATIVE_AI_API_KEY
);
default:
const errorMessage = `Failed to get token - unsupported model provider: ${provider}`;
elizaLogger.error(errorMessage);
Expand Down Expand Up @@ -645,7 +652,7 @@ async function startAgent(
await db.init();

const cache = initializeCache(
process.env.CACHE_STORE,
process.env.CACHE_STORE ?? CacheStore.DATABASE,
character,
"",
db
Expand Down
1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/README_FR.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/README_TH.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # ชื่อผู้ใช้บัญชี
TWITTER_PASSWORD= # รหัสผ่าน
TWITTER_EMAIL= # อีเมล
TWITTER_COOKIES= # คุกกี้
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/docs/api/_media/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/docs/api/_media/README_FR.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/docs/api/_media/README_JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # アカウントのユーザー名
TWITTER_PASSWORD= # アカウントのパスワード
TWITTER_EMAIL= # アカウントのメール
TWITTER_COOKIES= # アカウントのクッキー
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/docs/api/_media/README_KOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/docs/guides/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ DISCORD_API_TOKEN= # Discord bot token
TWITTER_USERNAME= # Bot Twitter username
TWITTER_PASSWORD= # Bot Twitter password
TWITTER_EMAIL= # Twitter account email
TWITTER_COOKIES= # Twitter auth cookies
TWITTER_DRY_RUN=false # Test mode without posting
```

Expand Down
1 change: 0 additions & 1 deletion docs/docs/packages/clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ const client = await TwitterClientInterface.start(runtime);
TWITTER_USERNAME = your_username;
TWITTER_PASSWORD = your_password;
TWITTER_EMAIL = your_email;
TWITTER_COOKIES = your_cookies;
```

### Components
Expand Down
11 changes: 0 additions & 11 deletions docs/docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,10 @@ Add to your `.env`:
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies (auth_token and CT0)
```

**Important:** Log in to the [Twitter Developer Portal](https://developer.twitter.com) and enable the "Automated" label for your account to avoid being flagged as inauthentic.

Example for TWITTER_COOKIES

The TWITTER_COOKIES variable should be a JSON string containing the necessary cookies. You can find these cookies in your web browser's developer tools. Here is an example format:

```bash
TWITTER_COOKIES='[{"key":"auth_token","value":"your token","domain":".twitter.com"},
{"key":"ct0","value":"your ct0","domain":".twitter.com"},
{"key":"guest_id","value":"your guest_id","domain":".twitter.com"}]'
```

### Telegram Bot

1. Create a bot
Expand Down
38 changes: 16 additions & 22 deletions packages/client-twitter/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ export class ClientBase extends EventEmitter {
}

async init() {
//test
const username = this.runtime.getSetting("TWITTER_USERNAME");
const password = this.runtime.getSetting("TWITTER_PASSWORD");
const email = this.runtime.getSetting("TWITTER_EMAIL");
Expand All @@ -163,43 +162,38 @@ export class ClientBase extends EventEmitter {
);
const twitter2faSecret =
this.runtime.getSetting("TWITTER_2FA_SECRET") || undefined;
const cookies = this.runtime.getSetting("TWITTER_COOKIES");

if (!username) {
throw new Error("Twitter username not configured");
}
// Check for Twitter cookies
if (cookies) {
elizaLogger.debug("Using cookies from settings");
const cookiesArray = JSON.parse(cookies);

await this.setCookiesFromArray(cookiesArray);
} else {
elizaLogger.debug("No cookies found in settings");
elizaLogger.debug("Checking for cached cookies");
const cachedCookies = await this.getCachedCookies(username);
if (cachedCookies) {
await this.setCookiesFromArray(cachedCookies);
}
const cachedCookies = await this.getCachedCookies(username);

if (cachedCookies) {
elizaLogger.info("Using cached cookies");
await this.setCookiesFromArray(cachedCookies);
}

elizaLogger.log("Waiting for Twitter login");
while (retries > 0) {
const cookies = await this.twitterClient.getCookies();
if ((await this.twitterClient.isLoggedIn()) && !!cookies) {
elizaLogger.info("Already logged in.");
await this.cacheCookies(username, cookies);
elizaLogger.info("Successfully logged in and cookies cached.");
break;
}

try {
await this.twitterClient.login(
username,
password,
email,
twitter2faSecret
);
if (await this.twitterClient.isLoggedIn()) {
elizaLogger.info("Successfully logged in.");
if (!cachedCookies) {
elizaLogger.info("Caching cookies");
await this.cacheCookies(
username,
await this.twitterClient.getCookies()
);
}
break;
}
} catch (error) {
elizaLogger.error(`Login attempt failed: ${error.message}`);
}
Expand Down
4 changes: 0 additions & 4 deletions packages/client-twitter/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const twitterEnvSchema = z.object({
TWITTER_USERNAME: z.string().min(1, "Twitter username is required"),
TWITTER_PASSWORD: z.string().min(1, "Twitter password is required"),
TWITTER_EMAIL: z.string().email("Valid Twitter email is required"),
TWITTER_COOKIES: z.string().optional(),
MAX_TWEET_LENGTH: z
.string()
.pipe(z.coerce.number().min(0).int())
Expand All @@ -37,9 +36,6 @@ export async function validateTwitterConfig(
TWITTER_EMAIL:
runtime.getSetting("TWITTER_EMAIL") ||
process.env.TWITTER_EMAIL,
TWITTER_COOKIES:
runtime.getSetting("TWITTER_COOKIES") ||
process.env.TWITTER_COOKIES,
MAX_TWEET_LENGTH:
runtime.getSetting("MAX_TWEET_LENGTH") ||
process.env.MAX_TWEET_LENGTH ||
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin-evm/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import eslintGlobalConfig from "../../eslint.config.mjs";

export default [...eslintGlobalConfig];
3 changes: 2 additions & 1 deletion packages/plugin-evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"test": "vitest run"
"test": "vitest run",
"lint": "eslint --fix --cache ."
},
"peerDependencies": {
"whatwg-url": "7.1.0"
Expand Down
1 change: 0 additions & 1 deletion packages/plugin-evm/src/actions/swap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { IAgentRuntime, Memory, State } from "@ai16z/eliza";
import {
ChainId,
createConfig,
executeRoute,
ExtendedChain,
Expand Down
35 changes: 11 additions & 24 deletions packages/plugin-evm/src/actions/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class TransferAction {
params.data = "0x";
}

await this.walletProvider.switchChain(params.fromChain);
this.walletProvider.switchChain(params.fromChain);

const walletClient = this.walletProvider.getWalletClient(
params.fromChain
Expand All @@ -41,12 +41,12 @@ export class TransferAction {
value: parseEther(params.amount),
data: params.data as Hex,
kzg: {
blobToKzgCommitment: function (blob: ByteArray): ByteArray {
blobToKzgCommitment: function (_: ByteArray): ByteArray {
throw new Error("Function not implemented.");
},
computeBlobKzgProof: function (
blob: ByteArray,
commitment: ByteArray
_blob: ByteArray,
_commitment: ByteArray
): ByteArray {
throw new Error("Function not implemented.");
},
Expand Down Expand Up @@ -81,7 +81,7 @@ const buildTransferDetails = async (

const contextWithChains = context.replace(
"SUPPORTED_CHAINS",
chains.toString()
chains.map((item) => `"${item}"`).join("|")
);

const transferDetails = (await generateObjectDeprecated({
Expand Down Expand Up @@ -109,34 +109,21 @@ export const transferAction = {
description: "Transfer tokens between addresses on the same chain",
handler: async (
runtime: IAgentRuntime,
message: Memory,
_message: Memory,
state: State,
options: any,
_options: any,
callback?: HandlerCallback
) => {
console.log("Transfer action handler called");
const walletProvider = initWalletProvider(runtime);
const action = new TransferAction(walletProvider);

// Compose transfer context
const transferContext = composeContext({
const paramOptions = await buildTransferDetails(
state,
template: transferTemplate,
});

// Generate transfer content
const content = await generateObjectDeprecated({
runtime,
context: transferContext,
modelClass: ModelClass.LARGE,
});

const paramOptions: TransferParams = {
fromChain: content.fromChain,
toAddress: content.toAddress,
amount: content.amount,
data: content.data,
};
walletProvider
);

try {
const transferResp = await action.transfer(paramOptions);
Expand All @@ -148,7 +135,7 @@ export const transferAction = {
hash: transferResp.hash,
amount: formatEther(transferResp.value),
recipient: transferResp.to,
chain: content.fromChain,
chain: paramOptions.fromChain,
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-evm/src/providers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ export const initWalletProvider = (runtime: IAgentRuntime) => {
export const evmWalletProvider: Provider = {
async get(
runtime: IAgentRuntime,
message: Memory,
state?: State
_message: Memory,
_state?: State
): Promise<string | null> {
try {
const walletProvider = initWalletProvider(runtime);
Expand Down
Loading

0 comments on commit f603fea

Please sign in to comment.