Skip to content

Commit 8696e76

Browse files
authored
Merge branch 'develop' into feat/discord-agent-autonomous-enhancements
2 parents 657efbf + 5b57a6d commit 8696e76

File tree

896 files changed

+5317
-3485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

896 files changed

+5317
-3485
lines changed

.eslintrc.json

-36
This file was deleted.

.github/workflows/ci.yaml

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ jobs:
2222
- name: Install dependencies
2323
run: pnpm install -r --no-frozen-lockfile
2424

25-
- name: Run Prettier
26-
run: pnpm run prettier --check .
25+
- name: Setup Biome CLI
26+
uses: biomejs/setup-biome@v2
27+
with:
28+
version: latest
2729

28-
- name: Run Linter
29-
run: pnpm run lint
30+
- name: Run Biome
31+
run: biome ci
3032

3133
- name: Create test env file
3234
run: |

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ agent/content
6262

6363
eliza.manifest
6464
eliza.manifest.sgx
65-
eliza.sig
65+
eliza.sig

agent/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"@elizaos/plugin-binance": "workspace:*",
4444
"@elizaos/plugin-avail": "workspace:*",
4545
"@elizaos/plugin-bootstrap": "workspace:*",
46+
"@elizaos/plugin-di": "workspace:*",
4647
"@elizaos/plugin-cosmos": "workspace:*",
4748
"@elizaos/plugin-intiface": "workspace:*",
4849
"@elizaos/plugin-coinbase": "workspace:*",

agent/src/__tests__/client-type-identification.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Client, IAgentRuntime } from "@elizaos/core";
1+
import type { Client, IAgentRuntime } from "@elizaos/core";
22
import { describe, it, expect } from "@jest/globals";
33

44
// Helper function to identify client types

agent/src/index.ts

+80-75
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ import {
2020
AgentRuntime,
2121
CacheManager,
2222
CacheStore,
23-
Character,
24-
Client,
23+
type Character,
24+
type Client,
2525
Clients,
2626
DbCacheAdapter,
2727
defaultCharacter,
2828
elizaLogger,
2929
FsCacheAdapter,
30-
IAgentRuntime,
31-
ICacheManager,
32-
IDatabaseAdapter,
33-
IDatabaseCacheAdapter,
30+
type IAgentRuntime,
31+
type ICacheManager,
32+
type IDatabaseAdapter,
33+
type IDatabaseCacheAdapter,
3434
ModelProviderName,
3535
parseBooleanFromText,
3636
settings,
@@ -40,6 +40,7 @@ import {
4040
import { zgPlugin } from "@elizaos/plugin-0g";
4141

4242
import { bootstrapPlugin } from "@elizaos/plugin-bootstrap";
43+
import { normalizeCharacter } from "@elizaos/plugin-di";
4344
import createGoatPlugin from "@elizaos/plugin-goat";
4445
// import { intifacePlugin } from "@elizaos/plugin-intiface";
4546
import { ThreeDGenerationPlugin } from "@elizaos/plugin-3d-generation";
@@ -116,7 +117,7 @@ import yargs from "yargs";
116117
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
117118
const __dirname = path.dirname(__filename); // get the name of the directory
118119

119-
export const wait = (minTime: number = 1000, maxTime: number = 3000) => {
120+
export const wait = (minTime = 1000, maxTime = 3000) => {
120121
const waitTime =
121122
Math.floor(Math.random() * (maxTime - minTime + 1)) + minTime;
122123
return new Promise((resolve) => setTimeout(resolve, waitTime));
@@ -251,7 +252,7 @@ export async function loadCharacterFromOnchain(): Promise<Character[]> {
251252
async function loadCharacterFromUrl(url: string): Promise<Character> {
252253
const response = await fetch(url);
253254
const character = await response.json();
254-
return jsonToCharacter(url, character);
255+
return await jsonToCharacter(url, character);
255256
}
256257

257258
async function jsonToCharacter(
@@ -300,92 +301,90 @@ async function loadCharacter(filePath: string): Promise<Character> {
300301
if (!content) {
301302
throw new Error(`Character file not found: ${filePath}`);
302303
}
303-
let character = JSON.parse(content);
304+
const character = JSON.parse(content);
304305
return jsonToCharacter(filePath, character);
305306
}
306307

308+
async function loadCharacterTryPath(characterPath: string): Promise<Character> {
309+
let content: string | null = null;
310+
let resolvedPath = "";
311+
312+
// Try different path resolutions in order
313+
const pathsToTry = [
314+
characterPath, // exact path as specified
315+
path.resolve(process.cwd(), characterPath), // relative to cwd
316+
path.resolve(process.cwd(), "agent", characterPath), // Add this
317+
path.resolve(__dirname, characterPath), // relative to current script
318+
path.resolve(__dirname, "characters", path.basename(characterPath)), // relative to agent/characters
319+
path.resolve(__dirname, "../characters", path.basename(characterPath)), // relative to characters dir from agent
320+
path.resolve(
321+
__dirname,
322+
"../../characters",
323+
path.basename(characterPath)
324+
), // relative to project root characters dir
325+
];
326+
327+
elizaLogger.info(
328+
"Trying paths:",
329+
pathsToTry.map((p) => ({
330+
path: p,
331+
exists: fs.existsSync(p),
332+
}))
333+
);
334+
335+
for (const tryPath of pathsToTry) {
336+
content = tryLoadFile(tryPath);
337+
if (content !== null) {
338+
resolvedPath = tryPath;
339+
break;
340+
}
341+
}
342+
343+
if (content === null) {
344+
elizaLogger.error(
345+
`Error loading character from ${characterPath}: File not found in any of the expected locations`
346+
);
347+
elizaLogger.error("Tried the following paths:");
348+
pathsToTry.forEach((p) => elizaLogger.error(` - ${p}`));
349+
throw new Error(
350+
`Error loading character from ${characterPath}: File not found in any of the expected locations`
351+
);
352+
}
353+
try {
354+
const character: Character = await loadCharacter(resolvedPath);
355+
elizaLogger.info(`Successfully loaded character from: ${resolvedPath}`);
356+
return character;
357+
} catch (e) {
358+
elizaLogger.error(`Error parsing character from ${resolvedPath}: ${e}`);
359+
throw new Error(`Error parsing character from ${resolvedPath}: ${e}`);
360+
}
361+
}
362+
307363
function commaSeparatedStringToArray(commaSeparated: string): string[] {
308364
return commaSeparated?.split(",").map((value) => value.trim());
309365
}
310366

311367
export async function loadCharacters(
312368
charactersArg: string
313369
): Promise<Character[]> {
314-
let characterPaths = commaSeparatedStringToArray(charactersArg);
370+
const characterPaths = commaSeparatedStringToArray(charactersArg);
315371
const loadedCharacters: Character[] = [];
316372

317373
if (characterPaths?.length > 0) {
318374
for (const characterPath of characterPaths) {
319-
let content: string | null = null;
320-
let resolvedPath = "";
321-
322-
// Try different path resolutions in order
323-
const pathsToTry = [
324-
characterPath, // exact path as specified
325-
path.resolve(process.cwd(), characterPath), // relative to cwd
326-
path.resolve(process.cwd(), "agent", characterPath), // Add this
327-
path.resolve(__dirname, characterPath), // relative to current script
328-
path.resolve(
329-
__dirname,
330-
"characters",
331-
path.basename(characterPath)
332-
), // relative to agent/characters
333-
path.resolve(
334-
__dirname,
335-
"../characters",
336-
path.basename(characterPath)
337-
), // relative to characters dir from agent
338-
path.resolve(
339-
__dirname,
340-
"../../characters",
341-
path.basename(characterPath)
342-
), // relative to project root characters dir
343-
];
344-
345-
elizaLogger.info(
346-
"Trying paths:",
347-
pathsToTry.map((p) => ({
348-
path: p,
349-
exists: fs.existsSync(p),
350-
}))
351-
);
352-
353-
for (const tryPath of pathsToTry) {
354-
content = tryLoadFile(tryPath);
355-
if (content !== null) {
356-
resolvedPath = tryPath;
357-
break;
358-
}
359-
}
360-
361-
if (content === null) {
362-
elizaLogger.error(
363-
`Error loading character from ${characterPath}: File not found in any of the expected locations`
364-
);
365-
elizaLogger.error("Tried the following paths:");
366-
pathsToTry.forEach((p) => elizaLogger.error(` - ${p}`));
367-
process.exit(1);
368-
}
369-
370375
try {
371-
const character: Character = await loadCharacter(resolvedPath);
372-
376+
const character: Character =
377+
await loadCharacterTryPath(characterPath);
373378
loadedCharacters.push(character);
374-
elizaLogger.info(
375-
`Successfully loaded character from: ${resolvedPath}`
376-
);
377379
} catch (e) {
378-
elizaLogger.error(
379-
`Error parsing character from ${resolvedPath}: ${e}`
380-
);
381380
process.exit(1);
382381
}
383382
}
384383
}
385384

386385
if (hasValidRemoteUrls()) {
387386
elizaLogger.info("Loading characters from remote URLs");
388-
let characterUrls = commaSeparatedStringToArray(
387+
const characterUrls = commaSeparatedStringToArray(
389388
process.env.REMOTE_CHARACTER_URLS
390389
);
391390
for (const characterUrl of characterUrls) {
@@ -1191,9 +1190,9 @@ const hasValidRemoteUrls = () =>
11911190

11921191
const startAgents = async () => {
11931192
const directClient = new DirectClient();
1194-
let serverPort = parseInt(settings.SERVER_PORT || "3000");
1193+
let serverPort = Number.parseInt(settings.SERVER_PORT || "3000");
11951194
const args = parseArguments();
1196-
let charactersArg = args.characters || args.character;
1195+
const charactersArg = args.characters || args.character;
11971196
let characters = [defaultCharacter];
11981197

11991198
if (process.env.IQ_WALLET_ADDRESS && process.env.IQSOlRPC) {
@@ -1204,6 +1203,9 @@ const startAgents = async () => {
12041203
characters = await loadCharacters(charactersArg);
12051204
}
12061205

1206+
// Normalize characters for injectable plugins
1207+
characters = await Promise.all(characters.map(normalizeCharacter));
1208+
12071209
try {
12081210
for (const character of characters) {
12091211
await startAgent(character, directClient);
@@ -1229,9 +1231,12 @@ const startAgents = async () => {
12291231
return startAgent(character, directClient);
12301232
};
12311233

1234+
directClient.loadCharacterTryPath = loadCharacterTryPath;
1235+
directClient.jsonToCharacter = jsonToCharacter;
1236+
12321237
directClient.start(serverPort);
12331238

1234-
if (serverPort !== parseInt(settings.SERVER_PORT || "3000")) {
1239+
if (serverPort !== Number.parseInt(settings.SERVER_PORT || "3000")) {
12351240
elizaLogger.log(`Server started on alternate port ${serverPort}`);
12361241
}
12371242

@@ -1251,12 +1256,12 @@ if (
12511256
parseBooleanFromText(process.env.PREVENT_UNHANDLED_EXIT)
12521257
) {
12531258
// Handle uncaught exceptions to prevent the process from crashing
1254-
process.on("uncaughtException", function (err) {
1259+
process.on("uncaughtException", (err) => {
12551260
console.error("uncaughtException", err);
12561261
});
12571262

12581263
// Handle unhandled rejections to prevent the process from crashing
1259-
process.on("unhandledRejection", function (err) {
1264+
process.on("unhandledRejection", (err) => {
12601265
console.error("unhandledRejection", err);
12611266
});
12621267
}

0 commit comments

Comments
 (0)