Skip to content

Commit 8c79437

Browse files
authored
Merge branch 'develop' into koloxarto/fix_ragknowledge_when_combining_files_and_strings
2 parents 9e859b8 + aac570b commit 8c79437

File tree

30 files changed

+5202
-1778
lines changed

30 files changed

+5202
-1778
lines changed

.vscode/settings.json

+11
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,16 @@
4343
},
4444
"[shellscript]": {
4545
"editor.defaultFormatter": "foxundermoon.shell-format"
46+
},
47+
"explorer.fileNesting.enabled": true,
48+
"explorer.fileNesting.patterns": {
49+
"*.ts": "${capture}.js",
50+
"*.js": "${capture}.js.map, ${capture}.min.js, ${capture}.d.ts",
51+
"*.jsx": "${capture}.js",
52+
"*.tsx": "${capture}.ts",
53+
"tsconfig.json": "tsconfig.*.json",
54+
"package.json": "package-lock.json, yarn.lock, pnpm-lock.yaml, bun.lockb,pnpm-workspace.yaml",
55+
"README.md": "*.md",
56+
"Dockerfile": "docker-compose-docs.yaml,docker-compose.yaml,Dockerfile.docs"
4657
}
4758
}

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ git clone https://github.com/elizaos/eliza.git
8080
# Checkout the latest release
8181
# This project iterates fast, so we recommend checking out the latest release
8282
git checkout $(git describe --tags --abbrev=0)
83+
# If the above doesn't checkout the latest release, this should work:
84+
# git checkout $(git describe --tags `git rev-list --tags --max-count=1`)
8385
```
8486

8587
### Start Eliza with Gitpod

agent/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"exec": "node --enable-source-maps --loader ts-node/esm src/index.ts"
1919
},
2020
"dependencies": {
21+
"@elizaos/adapter-supabase": "workspace:*",
2122
"@elizaos/adapter-postgres": "workspace:*",
2223
"@elizaos/adapter-redis": "workspace:*",
2324
"@elizaos/adapter-sqlite": "workspace:*",

agent/src/index.ts

+93-33
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { PGLiteDatabaseAdapter } from "@elizaos/adapter-pglite";
22
import { PostgresDatabaseAdapter } from "@elizaos/adapter-postgres";
33
import { RedisClient } from "@elizaos/adapter-redis";
44
import { SqliteDatabaseAdapter } from "@elizaos/adapter-sqlite";
5+
import { SupabaseDatabaseAdapter } from "@elizaos/adapter-supabase";
56
import { AutoClientInterface } from "@elizaos/client-auto";
67
import { DiscordClientInterface } from "@elizaos/client-discord";
78
import { FarcasterAgentClient } from "@elizaos/client-farcaster";
@@ -148,6 +149,61 @@ function tryLoadFile(filePath: string): string | null {
148149
return null;
149150
}
150151
}
152+
function mergeCharacters(base: Character, child: Character): Character {
153+
const mergeObjects = (baseObj: any, childObj: any) => {
154+
const result: any = {};
155+
const keys = new Set([...Object.keys(baseObj || {}), ...Object.keys(childObj || {})]);
156+
keys.forEach(key => {
157+
if (typeof baseObj[key] === 'object' && typeof childObj[key] === 'object' && !Array.isArray(baseObj[key]) && !Array.isArray(childObj[key])) {
158+
result[key] = mergeObjects(baseObj[key], childObj[key]);
159+
} else if (Array.isArray(baseObj[key]) || Array.isArray(childObj[key])) {
160+
result[key] = [...(baseObj[key] || []), ...(childObj[key] || [])];
161+
} else {
162+
result[key] = childObj[key] !== undefined ? childObj[key] : baseObj[key];
163+
}
164+
});
165+
return result;
166+
};
167+
return mergeObjects(base, child);
168+
}
169+
async function loadCharacter(filePath: string): Promise<Character> {
170+
const content = tryLoadFile(filePath);
171+
if (!content) {
172+
throw new Error(`Character file not found: ${filePath}`);
173+
}
174+
let character = JSON.parse(content);
175+
validateCharacterConfig(character);
176+
177+
// .id isn't really valid
178+
const characterId = character.id || character.name;
179+
const characterPrefix = `CHARACTER.${characterId.toUpperCase().replace(/ /g, "_")}.`;
180+
const characterSettings = Object.entries(process.env)
181+
.filter(([key]) => key.startsWith(characterPrefix))
182+
.reduce((settings, [key, value]) => {
183+
const settingKey = key.slice(characterPrefix.length);
184+
return { ...settings, [settingKey]: value };
185+
}, {});
186+
if (Object.keys(characterSettings).length > 0) {
187+
character.settings = character.settings || {};
188+
character.settings.secrets = {
189+
...characterSettings,
190+
...character.settings.secrets,
191+
};
192+
}
193+
// Handle plugins
194+
character.plugins = await handlePluginImporting(
195+
character.plugins
196+
);
197+
if (character.extends) {
198+
elizaLogger.info(`Merging ${character.name} character with parent characters`);
199+
for (const extendPath of character.extends) {
200+
const baseCharacter = await loadCharacter(path.resolve(path.dirname(filePath), extendPath));
201+
character = mergeCharacters(baseCharacter, character);
202+
elizaLogger.info(`Merged ${character.name} with ${baseCharacter.name}`);
203+
}
204+
}
205+
return character;
206+
}
151207

152208
export async function loadCharacters(
153209
charactersArg: string
@@ -211,32 +267,7 @@ export async function loadCharacters(
211267
}
212268

213269
try {
214-
const character = JSON.parse(content);
215-
validateCharacterConfig(character);
216-
217-
// .id isn't really valid
218-
const characterId = character.id || character.name;
219-
const characterPrefix = `CHARACTER.${characterId.toUpperCase().replace(/ /g, "_")}.`;
220-
221-
const characterSettings = Object.entries(process.env)
222-
.filter(([key]) => key.startsWith(characterPrefix))
223-
.reduce((settings, [key, value]) => {
224-
const settingKey = key.slice(characterPrefix.length);
225-
return { ...settings, [settingKey]: value };
226-
}, {});
227-
228-
if (Object.keys(characterSettings).length > 0) {
229-
character.settings = character.settings || {};
230-
character.settings.secrets = {
231-
...characterSettings,
232-
...character.settings.secrets,
233-
};
234-
}
235-
236-
// Handle plugins
237-
character.plugins = await handlePluginImporting(
238-
character.plugins
239-
);
270+
const character: Character = await loadCharacter(resolvedPath);
240271

241272
loadedCharacters.push(character);
242273
elizaLogger.info(
@@ -418,6 +449,11 @@ export function getTokenForProvider(
418449
character.settings?.secrets?.INFERA_API_KEY ||
419450
settings.INFERA_API_KEY
420451
);
452+
case ModelProviderName.DEEPSEEK:
453+
return (
454+
character.settings?.secrets?.DEEPSEEK_API_KEY ||
455+
settings.DEEPSEEK_API_KEY
456+
);
421457
default:
422458
const errorMessage = `Failed to get token - unsupported model provider: ${provider}`;
423459
elizaLogger.error(errorMessage);
@@ -426,7 +462,24 @@ export function getTokenForProvider(
426462
}
427463

428464
function initializeDatabase(dataDir: string) {
429-
if (process.env.POSTGRES_URL) {
465+
if (process.env.SUPABASE_URL && process.env.SUPABASE_ANON_KEY) {
466+
elizaLogger.info("Initializing Supabase connection...");
467+
const db = new SupabaseDatabaseAdapter(
468+
process.env.SUPABASE_URL,
469+
process.env.SUPABASE_ANON_KEY
470+
);
471+
472+
// Test the connection
473+
db.init()
474+
.then(() => {
475+
elizaLogger.success("Successfully connected to Supabase database");
476+
})
477+
.catch((error) => {
478+
elizaLogger.error("Failed to connect to Supabase:", error);
479+
});
480+
481+
return db;
482+
} else if (process.env.POSTGRES_URL) {
430483
elizaLogger.info("Initializing PostgreSQL connection...");
431484
const db = new PostgresDatabaseAdapter({
432485
connectionString: process.env.POSTGRES_URL,
@@ -436,9 +489,7 @@ function initializeDatabase(dataDir: string) {
436489
// Test the connection
437490
db.init()
438491
.then(() => {
439-
elizaLogger.success(
440-
"Successfully connected to PostgreSQL database"
441-
);
492+
elizaLogger.success("Successfully connected to PostgreSQL database");
442493
})
443494
.catch((error) => {
444495
elizaLogger.error("Failed to connect to PostgreSQL:", error);
@@ -453,10 +504,19 @@ function initializeDatabase(dataDir: string) {
453504
});
454505
return db;
455506
} else {
456-
const filePath =
457-
process.env.SQLITE_FILE ?? path.resolve(dataDir, "db.sqlite");
458-
// ":memory:";
507+
const filePath = process.env.SQLITE_FILE ?? path.resolve(dataDir, "db.sqlite");
508+
elizaLogger.info(`Initializing SQLite database at ${filePath}...`);
459509
const db = new SqliteDatabaseAdapter(new Database(filePath));
510+
511+
// Test the connection
512+
db.init()
513+
.then(() => {
514+
elizaLogger.success("Successfully connected to SQLite database");
515+
})
516+
.catch((error) => {
517+
elizaLogger.error("Failed to connect to SQLite:", error);
518+
});
519+
460520
return db;
461521
}
462522
}

packages/client-direct/src/api.ts

+54-7
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,46 @@ import {
66
AgentRuntime,
77
elizaLogger,
88
getEnvVariable,
9+
UUID,
910
validateCharacterConfig,
1011
ServiceType,
1112
} from "@elizaos/core";
1213

1314
import { TeeLogQuery, TeeLogService } from "@elizaos/plugin-tee-log";
1415
import { REST, Routes } from "discord.js";
1516
import { DirectClient } from ".";
16-
import { stringToUuid } from "@elizaos/core";
17+
import { validateUuid } from "@elizaos/core";
18+
19+
interface UUIDParams {
20+
agentId: UUID;
21+
roomId?: UUID;
22+
}
23+
24+
function validateUUIDParams(
25+
params: { agentId: string; roomId?: string },
26+
res: express.Response
27+
): UUIDParams | null {
28+
const agentId = validateUuid(params.agentId);
29+
if (!agentId) {
30+
res.status(400).json({
31+
error: "Invalid AgentId format. Expected to be a UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
32+
});
33+
return null;
34+
}
35+
36+
if (params.roomId) {
37+
const roomId = validateUuid(params.roomId);
38+
if (!roomId) {
39+
res.status(400).json({
40+
error: "Invalid RoomId format. Expected to be a UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
41+
});
42+
return null;
43+
}
44+
return { agentId, roomId };
45+
}
46+
47+
return { agentId };
48+
}
1749

1850
export function createApiRouter(
1951
agents: Map<string, AgentRuntime>,
@@ -48,7 +80,11 @@ export function createApiRouter(
4880
});
4981

5082
router.get("/agents/:agentId", (req, res) => {
51-
const agentId = req.params.agentId;
83+
const { agentId } = validateUUIDParams(req.params, res) ?? {
84+
agentId: null,
85+
};
86+
if (!agentId) return;
87+
5288
const agent = agents.get(agentId);
5389

5490
if (!agent) {
@@ -68,8 +104,11 @@ export function createApiRouter(
68104
});
69105

70106
router.post("/agents/:agentId/set", async (req, res) => {
71-
const agentId = req.params.agentId;
72-
console.log("agentId", agentId);
107+
const { agentId } = validateUUIDParams(req.params, res) ?? {
108+
agentId: null,
109+
};
110+
if (!agentId) return;
111+
73112
let agent: AgentRuntime = agents.get(agentId);
74113

75114
// update character
@@ -104,7 +143,11 @@ export function createApiRouter(
104143
});
105144

106145
router.get("/agents/:agentId/channels", async (req, res) => {
107-
const agentId = req.params.agentId;
146+
const { agentId } = validateUUIDParams(req.params, res) ?? {
147+
agentId: null,
148+
};
149+
if (!agentId) return;
150+
108151
const runtime = agents.get(agentId);
109152

110153
if (!runtime) {
@@ -130,8 +173,12 @@ export function createApiRouter(
130173
});
131174

132175
router.get("/agents/:agentId/:roomId/memories", async (req, res) => {
133-
const agentId = req.params.agentId;
134-
const roomId = stringToUuid(req.params.roomId);
176+
const { agentId, roomId } = validateUUIDParams(req.params, res) ?? {
177+
agentId: null,
178+
roomId: null,
179+
};
180+
if (!agentId || !roomId) return;
181+
135182
let runtime = agents.get(agentId);
136183

137184
// if runtime is null, look for runtime with the same name

0 commit comments

Comments
 (0)