Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsayo authored Jan 17, 2025
2 parents f97f2d8 + e9e5608 commit 16cdf9c
Show file tree
Hide file tree
Showing 78 changed files with 13,747 additions and 511 deletions.
47 changes: 47 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ SUPABASE_ANON_KEY=
# Comma separated list of remote character urls (optional)
REMOTE_CHARACTER_URLS=

# Logging
LOG_JSON_FORMAT= # Print everything in logger as json; false by default

###############################
#### Client Configurations ####
###############################
Expand Down Expand Up @@ -383,6 +386,13 @@ ZEROG_EVM_RPC=
ZEROG_PRIVATE_KEY=
ZEROG_FLOW_ADDRESS=

# IQ6900
# Load json recorded on-chain through IQ
# Inscribe your json character file here: https://elizacodein.com/

IQ_WALLET_ADDRESS= # If you enter the wallet address used on the site, the most recently inscribed json will be loaded.
IQSOlRPC=

# Squid Router
SQUID_SDK_URL=https://apiplus.squidrouter.com # Default: https://apiplus.squidrouter.com
SQUID_INTEGRATOR_ID= # get integrator id through https://docs.squidrouter.com/
Expand Down Expand Up @@ -642,3 +652,40 @@ INSTAGRAM_POST_INTERVAL_MAX=120 # Default: 120 minutes
INSTAGRAM_ENABLE_ACTION_PROCESSING=false # Enable/disable action processing
INSTAGRAM_ACTION_INTERVAL=5 # Interval between actions in minutes
INSTAGRAM_MAX_ACTIONS=1 # Maximum number of actions to process at once

####################################
#### Pyth Plugin Configuration ####
####################################
# Network Environment (mainnet or testnet)git
PYTH_NETWORK_ENV=mainnet

# Mainnet Network Configuration
PYTH_MAINNET_HERMES_URL=https://hermes.pyth.network
PYTH_MAINNET_WSS_URL=wss://hermes.pyth.network/ws
PYTH_MAINNET_PYTHNET_URL=https://pythnet.rpcpool.com
PYTH_MAINNET_CONTRACT_REGISTRY=https://pyth.network/developers/price-feed-ids
PYTH_MAINNET_PROGRAM_KEY=

# Testnet Network Configuration
PYTH_TESTNET_HERMES_URL=https://hermes.pyth.network
PYTH_TESTNET_WSS_URL=wss://hermes.pyth.network/ws
PYTH_TESTNET_PYTHNET_URL=https://pythnet.rpcpool.com
PYTH_TESTNET_CONTRACT_REGISTRY=https://pyth.network/developers/price-feed-ids#testnet
PYTH_TESTNET_PROGRAM_KEY=

# Connection Settings
PYTH_MAX_RETRIES=3
PYTH_RETRY_DELAY=1000
PYTH_TIMEOUT=5000
PYTH_GRANULAR_LOG=true
PYTH_LOG_LEVEL=debug
PYTH_LOG_LEVEL=info

# Runtime Settings
RUNTIME_CHECK_MODE=false

# Pyth Price Streaming and test ID
PYTH_ENABLE_PRICE_STREAMING=true
PYTH_MAX_PRICE_STREAMS=2
PYTH_TEST_ID01=0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43
PYTH_TEST_ID02=0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace
60 changes: 60 additions & 0 deletions .github/workflows/block-mini.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Block Minified JavaScript/TypeScript

on:
pull_request:
branches: ["main", "develop", "*"]
push:
branches: ["main", "develop", "*"]

jobs:
block-minified-code:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Detect potential minified code
shell: bash
run: |
echo "Scanning for potential minified JS/TS code..."
# We'll look in .ts, .tsx, .js, .jsx files, skipping common build dirs.
FILES=$(find . \
\( -name 'node_modules' -prune \) -o \
\( -name 'dist' -prune \) -o \
\( -name 'build' -prune \) -o \
-type f \( -name '*.ts' -o -name '*.tsx' -o -name '*.js' -o -name '*.jsx' \) \
-print)
if [ -z "$FILES" ]; then
echo "No relevant JS/TS files found."
exit 0
fi
THRESHOLD=1000
VIOLATIONS=0
for file in $FILES; do
# Use grep -En to capture line number and text
# If any line is ≥ THRESHOLD chars, we store those lines in RESULTS
RESULTS=$(grep -En ".{${THRESHOLD},}" "$file" || true)
if [ -n "$RESULTS" ]; then
# We have potential minified lines
while IFS= read -r match; do
# 'match' will be something like "1234:the entire matched line"
LINENUM=$(echo "$match" | cut -d: -f1)
# If you want the text, you can do:
# MATCHED_LINE=$(echo "$match" | cut -d: -f2-)
echo "::error file=$file,line=$LINENUM::Detected potential minified code (≥ $THRESHOLD chars)."
done <<< "$RESULTS"
VIOLATIONS=1
fi
done
if [ "$VIOLATIONS" -eq 1 ]; then
echo "ERROR: Minified code detected. Please remove or exclude it."
exit 1
else
echo "No minified code detected."
fi
14 changes: 13 additions & 1 deletion agent/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@elizaos/agent",
"version": "0.1.9-alpha.1",
"version": "0.1.9-alpha.1",
"main": "src/index.ts",
"type": "module",
"scripts": {
Expand Down Expand Up @@ -31,14 +32,18 @@
"@elizaos/client-telegram": "workspace:*",
"@elizaos/client-twitter": "workspace:*",
"@elizaos/client-instagram": "workspace:*",
"@elizaos/client-instagram": "workspace:*",
"@elizaos/client-slack": "workspace:*",
"@elizaos/core": "workspace:*",
"@elizaos/plugin-0g": "workspace:*",
"@elizaos/plugin-abstract": "workspace:*",
"@elizaos/plugin-agentkit": "workspace:*",
"@elizaos/plugin-agentkit": "workspace:*",
"@elizaos/plugin-aptos": "workspace:*",
"@elizaos/plugin-birdeye": "workspace:*",
"@elizaos/plugin-coingecko": "workspace:*",
"@elizaos/plugin-birdeye": "workspace:*",
"@elizaos/plugin-coingecko": "workspace:*",
"@elizaos/plugin-coinmarketcap": "workspace:*",
"@elizaos/plugin-binance": "workspace:*",
"@elizaos/plugin-avail": "workspace:*",
Expand All @@ -53,6 +58,7 @@
"@elizaos/plugin-gitbook": "workspace:*",
"@elizaos/plugin-story": "workspace:*",
"@elizaos/plugin-gitcoin-passport": "workspace:*",
"@elizaos/plugin-gitcoin-passport": "workspace:*",
"@elizaos/plugin-goat": "workspace:*",
"@elizaos/plugin-lensNetwork": "workspace:*",
"@elizaos/plugin-icp": "workspace:*",
Expand All @@ -63,15 +69,18 @@
"@elizaos/plugin-node": "workspace:*",
"@elizaos/plugin-solana": "workspace:*",
"@elizaos/plugin-injective": "workspace:*",
"@elizaos/plugin-injective": "workspace:*",
"@elizaos/plugin-solana-agentkit": "workspace:*",
"@elizaos/plugin-squid-router": "workspace:*",
"@elizaos/plugin-squid-router": "workspace:*",
"@elizaos/plugin-autonome": "workspace:*",
"@elizaos/plugin-starknet": "workspace:*",
"@elizaos/plugin-stargaze": "workspace:*",
"@elizaos/plugin-giphy": "workspace:*",
"@elizaos/plugin-ton": "workspace:*",
"@elizaos/plugin-sui": "workspace:*",
"@elizaos/plugin-sgx": "workspace:*",
"@elizaos/plugin-iq6900": "workspace:*",
"@elizaos/plugin-tee": "workspace:*",
"@elizaos/plugin-tee-log": "workspace:*",
"@elizaos/plugin-tee-marlin": "workspace:*",
Expand All @@ -87,10 +96,12 @@
"@elizaos/plugin-video-generation": "workspace:*",
"@elizaos/plugin-web-search": "workspace:*",
"@elizaos/plugin-dexscreener": "workspace:*",
"@elizaos/plugin-dexscreener": "workspace:*",
"@elizaos/plugin-letzai": "workspace:*",
"@elizaos/plugin-thirdweb": "workspace:*",
"@elizaos/plugin-genlayer": "workspace:*",
"@elizaos/plugin-tee-verifiable-log": "workspace:*",
"@elizaos/plugin-tee-verifiable-log": "workspace:*",
"@elizaos/plugin-depin": "workspace:*",
"@elizaos/plugin-open-weather": "workspace:*",
"@elizaos/plugin-obsidian": "workspace:*",
Expand All @@ -102,6 +113,7 @@
"@elizaos/plugin-quai": "workspace:*",
"@elizaos/plugin-b2": "workspace:*",
"@elizaos/plugin-nft-collections": "workspace:*",
"@elizaos/plugin-pyth-data": "workspace:*",
"readline": "1.3.0",
"ws": "8.18.0",
"yargs": "17.7.2"
Expand All @@ -113,4 +125,4 @@
"ts-node": "10.9.2",
"tsup": "8.3.5"
}
}
}
92 changes: 81 additions & 11 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import { SlackClientInterface } from "@elizaos/client-slack";
import { TelegramClientInterface } from "@elizaos/client-telegram";
import { TwitterClientInterface } from "@elizaos/client-twitter";
import { FarcasterClientInterface } from "@elizaos/client-farcaster";
import { DirectClient } from "@elizaos/client-direct";
// import { ReclaimAdapter } from "@elizaos/plugin-reclaim";
import { PrimusAdapter } from "@elizaos/plugin-primus";
import { elizaCodeinPlugin, onchainJson } from "@elizaos/plugin-iq6900";

import {
AgentRuntime,
Expand Down Expand Up @@ -40,7 +42,6 @@ import { zgPlugin } from "@elizaos/plugin-0g";
import { bootstrapPlugin } from "@elizaos/plugin-bootstrap";
import createGoatPlugin from "@elizaos/plugin-goat";
// import { intifacePlugin } from "@elizaos/plugin-intiface";
import { DirectClient } from "@elizaos/client-direct";
import { ThreeDGenerationPlugin } from "@elizaos/plugin-3d-generation";
import { abstractPlugin } from "@elizaos/plugin-abstract";
import { akashPlugin } from "@elizaos/plugin-akash";
Expand Down Expand Up @@ -102,6 +103,7 @@ import { thirdwebPlugin } from "@elizaos/plugin-thirdweb";
import { hyperliquidPlugin } from "@elizaos/plugin-hyperliquid";
import { echoChambersPlugin } from "@elizaos/plugin-echochambers";
import { dexScreenerPlugin } from "@elizaos/plugin-dexscreener";
import { pythDataPlugin } from "@elizaos/plugin-pyth-data";

import { zksyncEraPlugin } from "@elizaos/plugin-zksync-era";
import Database from "better-sqlite3";
Expand All @@ -111,7 +113,6 @@ import path from "path";
import { fileURLToPath } from "url";
import yargs from "yargs";


const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename); // get the name of the directory

Expand Down Expand Up @@ -189,6 +190,63 @@ function mergeCharacters(base: Character, child: Character): Character {
};
return mergeObjects(base, child);
}
function isAllStrings(arr: unknown[]): boolean {
return Array.isArray(arr) && arr.every((item) => typeof item === "string");
}
export async function loadCharacterFromOnchain(): Promise<Character[]> {
const jsonText = onchainJson;

console.log("JSON:", jsonText);
if (jsonText == "null") return [];
const loadedCharacters = [];
try {
const character = JSON.parse(jsonText);
validateCharacterConfig(character);

// .id isn't really valid
const characterId = character.id || character.name;
const characterPrefix = `CHARACTER.${characterId.toUpperCase().replace(/ /g, "_")}.`;

const characterSettings = Object.entries(process.env)
.filter(([key]) => key.startsWith(characterPrefix))
.reduce((settings, [key, value]) => {
const settingKey = key.slice(characterPrefix.length);
settings[settingKey] = value;
return settings;
}, {});

if (Object.keys(characterSettings).length > 0) {
character.settings = character.settings || {};
character.settings.secrets = {
...characterSettings,
...character.settings.secrets,
};
}

// Handle plugins
if (isAllStrings(character.plugins)) {
elizaLogger.info("Plugins are: ", character.plugins);
const importedPlugins = await Promise.all(
character.plugins.map(async (plugin) => {
const importedPlugin = await import(plugin);
return importedPlugin.default;
})
);
character.plugins = importedPlugins;
}

loadedCharacters.push(character);
elizaLogger.info(
`Successfully loaded character from: ${process.env.IQ_WALLET_ADDRESS}`
);
return loadedCharacters;
} catch (e) {
elizaLogger.error(
`Error parsing character from ${process.env.IQ_WALLET_ADDRESS}: ${e}`
);
process.exit(1);
}
}

async function loadCharacterFromUrl(url: string): Promise<Character> {
const response = await fetch(url);
Expand Down Expand Up @@ -247,14 +305,13 @@ async function loadCharacter(filePath: string): Promise<Character> {
}

function commaSeparatedStringToArray(commaSeparated: string): string[] {
return commaSeparated?.split(",").map(value => value.trim())
return commaSeparated?.split(",").map((value) => value.trim());
}


export async function loadCharacters(
charactersArg: string
): Promise<Character[]> {
let characterPaths = commaSeparatedStringToArray(charactersArg)
let characterPaths = commaSeparatedStringToArray(charactersArg);
const loadedCharacters: Character[] = [];

if (characterPaths?.length > 0) {
Expand Down Expand Up @@ -328,7 +385,9 @@ export async function loadCharacters(

if (hasValidRemoteUrls()) {
elizaLogger.info("Loading characters from remote URLs");
let characterUrls = commaSeparatedStringToArray(process.env.REMOTE_CHARACTER_URLS)
let characterUrls = commaSeparatedStringToArray(
process.env.REMOTE_CHARACTER_URLS
);
for (const characterUrl of characterUrls) {
const character = await loadCharacterFromUrl(characterUrl);
loadedCharacters.push(character);
Expand Down Expand Up @@ -784,6 +843,10 @@ export async function createAgent(
character,
// character.plugins are handled when clients are added
plugins: [
getSecret(character, "IQ_WALLET_ADDRESS") &&
getSecret(character, "IQSOlRPC")
? elizaCodeinPlugin
: null,
bootstrapPlugin,
getSecret(character, "DEXSCREENER_API_KEY")
? dexScreenerPlugin
Expand Down Expand Up @@ -812,8 +875,9 @@ export async function createAgent(
getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
? evmPlugin
: null,
((getSecret(character, "EVM_PUBLIC_KEY") || getSecret(character, "INJECTIVE_PUBLIC_KEY")) &&
getSecret(character, "INJECTIVE_PRIVATE_KEY"))
(getSecret(character, "EVM_PUBLIC_KEY") ||
getSecret(character, "INJECTIVE_PUBLIC_KEY")) &&
getSecret(character, "INJECTIVE_PRIVATE_KEY")
? injectivePlugin
: null,
getSecret(character, "COSMOS_RECOVERY_PHRASE") &&
Expand Down Expand Up @@ -955,6 +1019,10 @@ export async function createAgent(
getSecret(character, "RESERVOIR_API_KEY")
? createNFTCollectionsPlugin()
: null,
getSecret(character, "PYTH_TESTNET_PROGRAM_KEY") ||
getSecret(character, "PYTH_MAINNET_PROGRAM_KEY")
? pythDataPlugin
: null,
].filter(Boolean),
providers: [],
actions: [],
Expand Down Expand Up @@ -1116,21 +1184,23 @@ const checkPortAvailable = (port: number): Promise<boolean> => {
});
};


const hasValidRemoteUrls = () =>
process.env.REMOTE_CHARACTER_URLS &&
process.env.REMOTE_CHARACTER_URLS !== "" &&
process.env.REMOTE_CHARACTER_URLS.startsWith("http");


const startAgents = async () => {
const directClient = new DirectClient();
let serverPort = parseInt(settings.SERVER_PORT || "3000");
const args = parseArguments();
let charactersArg = args.characters || args.character;
let characters = [defaultCharacter];

if (charactersArg || hasValidRemoteUrls()) {
if (process.env.IQ_WALLET_ADDRESS && process.env.IQSOlRPC) {
characters = await loadCharacterFromOnchain();
}

if ((onchainJson == "null" && charactersArg) || hasValidRemoteUrls()) {
characters = await loadCharacters(charactersArg);
}

Expand Down
Loading

0 comments on commit 16cdf9c

Please sign in to comment.