@@ -11,8 +11,10 @@ import { SlackClientInterface } from "@elizaos/client-slack";
11
11
import { TelegramClientInterface } from "@elizaos/client-telegram" ;
12
12
import { TwitterClientInterface } from "@elizaos/client-twitter" ;
13
13
import { FarcasterClientInterface } from "@elizaos/client-farcaster" ;
14
+ import { DirectClient } from "@elizaos/client-direct" ;
14
15
// import { ReclaimAdapter } from "@elizaos/plugin-reclaim";
15
16
import { PrimusAdapter } from "@elizaos/plugin-primus" ;
17
+ import { elizaCodeinPlugin , onchainJson } from "@elizaos/plugin-iq6900" ;
16
18
17
19
import {
18
20
AgentRuntime ,
@@ -40,7 +42,6 @@ import { zgPlugin } from "@elizaos/plugin-0g";
40
42
import { bootstrapPlugin } from "@elizaos/plugin-bootstrap" ;
41
43
import createGoatPlugin from "@elizaos/plugin-goat" ;
42
44
// import { intifacePlugin } from "@elizaos/plugin-intiface";
43
- import { DirectClient } from "@elizaos/client-direct" ;
44
45
import { ThreeDGenerationPlugin } from "@elizaos/plugin-3d-generation" ;
45
46
import { abstractPlugin } from "@elizaos/plugin-abstract" ;
46
47
import { akashPlugin } from "@elizaos/plugin-akash" ;
@@ -102,6 +103,7 @@ import { thirdwebPlugin } from "@elizaos/plugin-thirdweb";
102
103
import { hyperliquidPlugin } from "@elizaos/plugin-hyperliquid" ;
103
104
import { echoChambersPlugin } from "@elizaos/plugin-echochambers" ;
104
105
import { dexScreenerPlugin } from "@elizaos/plugin-dexscreener" ;
106
+ import { pythDataPlugin } from "@elizaos/plugin-pyth-data" ;
105
107
106
108
import { zksyncEraPlugin } from "@elizaos/plugin-zksync-era" ;
107
109
import Database from "better-sqlite3" ;
@@ -111,7 +113,6 @@ import path from "path";
111
113
import { fileURLToPath } from "url" ;
112
114
import yargs from "yargs" ;
113
115
114
-
115
116
const __filename = fileURLToPath ( import . meta. url ) ; // get the resolved path to the file
116
117
const __dirname = path . dirname ( __filename ) ; // get the name of the directory
117
118
@@ -189,6 +190,63 @@ function mergeCharacters(base: Character, child: Character): Character {
189
190
} ;
190
191
return mergeObjects ( base , child ) ;
191
192
}
193
+ function isAllStrings ( arr : unknown [ ] ) : boolean {
194
+ return Array . isArray ( arr ) && arr . every ( ( item ) => typeof item === "string" ) ;
195
+ }
196
+ export async function loadCharacterFromOnchain ( ) : Promise < Character [ ] > {
197
+ const jsonText = onchainJson ;
198
+
199
+ console . log ( "JSON:" , jsonText ) ;
200
+ if ( jsonText == "null" ) return [ ] ;
201
+ const loadedCharacters = [ ] ;
202
+ try {
203
+ const character = JSON . parse ( jsonText ) ;
204
+ validateCharacterConfig ( character ) ;
205
+
206
+ // .id isn't really valid
207
+ const characterId = character . id || character . name ;
208
+ const characterPrefix = `CHARACTER.${ characterId . toUpperCase ( ) . replace ( / / g, "_" ) } .` ;
209
+
210
+ const characterSettings = Object . entries ( process . env )
211
+ . filter ( ( [ key ] ) => key . startsWith ( characterPrefix ) )
212
+ . reduce ( ( settings , [ key , value ] ) => {
213
+ const settingKey = key . slice ( characterPrefix . length ) ;
214
+ settings [ settingKey ] = value ;
215
+ return settings ;
216
+ } , { } ) ;
217
+
218
+ if ( Object . keys ( characterSettings ) . length > 0 ) {
219
+ character . settings = character . settings || { } ;
220
+ character . settings . secrets = {
221
+ ...characterSettings ,
222
+ ...character . settings . secrets ,
223
+ } ;
224
+ }
225
+
226
+ // Handle plugins
227
+ if ( isAllStrings ( character . plugins ) ) {
228
+ elizaLogger . info ( "Plugins are: " , character . plugins ) ;
229
+ const importedPlugins = await Promise . all (
230
+ character . plugins . map ( async ( plugin ) => {
231
+ const importedPlugin = await import ( plugin ) ;
232
+ return importedPlugin . default ;
233
+ } )
234
+ ) ;
235
+ character . plugins = importedPlugins ;
236
+ }
237
+
238
+ loadedCharacters . push ( character ) ;
239
+ elizaLogger . info (
240
+ `Successfully loaded character from: ${ process . env . IQ_WALLET_ADDRESS } `
241
+ ) ;
242
+ return loadedCharacters ;
243
+ } catch ( e ) {
244
+ elizaLogger . error (
245
+ `Error parsing character from ${ process . env . IQ_WALLET_ADDRESS } : ${ e } `
246
+ ) ;
247
+ process . exit ( 1 ) ;
248
+ }
249
+ }
192
250
193
251
async function loadCharacterFromUrl ( url : string ) : Promise < Character > {
194
252
const response = await fetch ( url ) ;
@@ -247,14 +305,13 @@ async function loadCharacter(filePath: string): Promise<Character> {
247
305
}
248
306
249
307
function commaSeparatedStringToArray ( commaSeparated : string ) : string [ ] {
250
- return commaSeparated ?. split ( "," ) . map ( value => value . trim ( ) )
308
+ return commaSeparated ?. split ( "," ) . map ( ( value ) => value . trim ( ) ) ;
251
309
}
252
310
253
-
254
311
export async function loadCharacters (
255
312
charactersArg : string
256
313
) : Promise < Character [ ] > {
257
- let characterPaths = commaSeparatedStringToArray ( charactersArg )
314
+ let characterPaths = commaSeparatedStringToArray ( charactersArg ) ;
258
315
const loadedCharacters : Character [ ] = [ ] ;
259
316
260
317
if ( characterPaths ?. length > 0 ) {
@@ -328,7 +385,9 @@ export async function loadCharacters(
328
385
329
386
if ( hasValidRemoteUrls ( ) ) {
330
387
elizaLogger . info ( "Loading characters from remote URLs" ) ;
331
- let characterUrls = commaSeparatedStringToArray ( process . env . REMOTE_CHARACTER_URLS )
388
+ let characterUrls = commaSeparatedStringToArray (
389
+ process . env . REMOTE_CHARACTER_URLS
390
+ ) ;
332
391
for ( const characterUrl of characterUrls ) {
333
392
const character = await loadCharacterFromUrl ( characterUrl ) ;
334
393
loadedCharacters . push ( character ) ;
@@ -784,6 +843,10 @@ export async function createAgent(
784
843
character,
785
844
// character.plugins are handled when clients are added
786
845
plugins : [
846
+ getSecret ( character , "IQ_WALLET_ADDRESS" ) &&
847
+ getSecret ( character , "IQSOlRPC" )
848
+ ? elizaCodeinPlugin
849
+ : null ,
787
850
bootstrapPlugin ,
788
851
getSecret ( character , "DEXSCREENER_API_KEY" )
789
852
? dexScreenerPlugin
@@ -812,8 +875,9 @@ export async function createAgent(
812
875
getSecret ( character , "WALLET_PUBLIC_KEY" ) ?. startsWith ( "0x" ) )
813
876
? evmPlugin
814
877
: null ,
815
- ( ( getSecret ( character , "EVM_PUBLIC_KEY" ) || getSecret ( character , "INJECTIVE_PUBLIC_KEY" ) ) &&
816
- getSecret ( character , "INJECTIVE_PRIVATE_KEY" ) )
878
+ ( getSecret ( character , "EVM_PUBLIC_KEY" ) ||
879
+ getSecret ( character , "INJECTIVE_PUBLIC_KEY" ) ) &&
880
+ getSecret ( character , "INJECTIVE_PRIVATE_KEY" )
817
881
? injectivePlugin
818
882
: null ,
819
883
getSecret ( character , "COSMOS_RECOVERY_PHRASE" ) &&
@@ -955,6 +1019,10 @@ export async function createAgent(
955
1019
getSecret ( character , "RESERVOIR_API_KEY" )
956
1020
? createNFTCollectionsPlugin ( )
957
1021
: null ,
1022
+ getSecret ( character , "PYTH_TESTNET_PROGRAM_KEY" ) ||
1023
+ getSecret ( character , "PYTH_MAINNET_PROGRAM_KEY" )
1024
+ ? pythDataPlugin
1025
+ : null ,
958
1026
] . filter ( Boolean ) ,
959
1027
providers : [ ] ,
960
1028
actions : [ ] ,
@@ -1116,21 +1184,23 @@ const checkPortAvailable = (port: number): Promise<boolean> => {
1116
1184
} ) ;
1117
1185
} ;
1118
1186
1119
-
1120
1187
const hasValidRemoteUrls = ( ) =>
1121
1188
process . env . REMOTE_CHARACTER_URLS &&
1122
1189
process . env . REMOTE_CHARACTER_URLS !== "" &&
1123
1190
process . env . REMOTE_CHARACTER_URLS . startsWith ( "http" ) ;
1124
1191
1125
-
1126
1192
const startAgents = async ( ) => {
1127
1193
const directClient = new DirectClient ( ) ;
1128
1194
let serverPort = parseInt ( settings . SERVER_PORT || "3000" ) ;
1129
1195
const args = parseArguments ( ) ;
1130
1196
let charactersArg = args . characters || args . character ;
1131
1197
let characters = [ defaultCharacter ] ;
1132
1198
1133
- if ( charactersArg || hasValidRemoteUrls ( ) ) {
1199
+ if ( process . env . IQ_WALLET_ADDRESS && process . env . IQSOlRPC ) {
1200
+ characters = await loadCharacterFromOnchain ( ) ;
1201
+ }
1202
+
1203
+ if ( ( onchainJson == "null" && charactersArg ) || hasValidRemoteUrls ( ) ) {
1134
1204
characters = await loadCharacters ( charactersArg ) ;
1135
1205
}
1136
1206
0 commit comments