Skip to content

Commit

Permalink
Merge branch 'develop' into tcm-fix-twitter-search
Browse files Browse the repository at this point in the history
  • Loading branch information
tcm390 authored Jan 17, 2025
2 parents c0a6a65 + eae3062 commit 2df4458
Show file tree
Hide file tree
Showing 13 changed files with 820 additions and 399 deletions.
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,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
1 change: 1 addition & 0 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"@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 Down
85 changes: 75 additions & 10 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { TwitterClientInterface } from "@elizaos/client-twitter";
import { FarcasterClientInterface } from "@elizaos/client-farcaster";
// 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 @@ -111,7 +112,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 +189,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 +304,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 +384,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 +842,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 +874,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 @@ -1116,21 +1179,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
6 changes: 6 additions & 0 deletions packages/plugin-iq6900/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*

!dist/**
!package.json
!readme.md
!tsup.config.ts
28 changes: 28 additions & 0 deletions packages/plugin-iq6900/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Code In Plugin For Eliza

## Description
Through IQ6900's new inscription standard "Code-In", powerful inscription functionality is provided to Eliza.
Engrave Eliza on the blockchain forever.
All your Character JSON files are input onto the blockchain without compression.
Everyone can read your agent from blocks forever.

## inscription
- **Code-in your eliza**: Go to the site and engrave your character file on-chain. https://elizacodein.com/

## Onchain git
- **Commit your update**:
Update your files anytime.
On our site, your files are managed in a format similar to GitHub,
and our plugin automatically loads your latest agent file.

## Let's get started
- **Edit your .env**: write down IQ_WALLET_ADDRESS to your wallet address that you used on website.
To be sure, right after inscription, wait about 5 minutes and just type pmpn start. You are now all set.


You have engraved an eternal record.
Imagine, someone could develop your agent 200 years from now.

Many things will be updated.

Learn more: https://iq6900.gitbook.io/iq6900/eliza-code-in
3 changes: 3 additions & 0 deletions packages/plugin-iq6900/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];
20 changes: 20 additions & 0 deletions packages/plugin-iq6900/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@elizaos/plugin-iq6900",
"version": "0.1.5-alpha.5",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@elizaos/core": "workspace:*",
"@solana/web3.js": "1.95.8"
},
"devDependencies": {
"tsup": "8.3.5",
"@types/node": "^20.0.0"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"lint": "eslint --fix --cache ."
}
}
Loading

0 comments on commit 2df4458

Please sign in to comment.