-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy pathserver.ts
More file actions
66 lines (56 loc) · 2.15 KB
/
server.ts
File metadata and controls
66 lines (56 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { AgentRuntime, createCharacter } from "@elizaos/core";
import { createRobloxBridgeApp } from "./app";
import { elizaClassicJsonPlugin } from "./elizaClassicJsonPlugin";
const PORT = Number(process.env.PORT ?? 3040);
const SHARED_SECRET = process.env.ELIZA_ROBLOX_SHARED_SECRET ?? "";
function envSettings(): Record<string, string> {
const out: Record<string, string> = {};
for (const [k, v] of Object.entries(process.env)) {
if (typeof v === "string") out[k] = v;
}
return out;
}
async function createRuntime(): Promise<AgentRuntime> {
const [{ openaiPlugin }, { robloxPlugin }, { default: sqlPlugin }] =
await Promise.all([
import("@elizaos/plugin-openai"),
import("@elizaos/plugin-roblox"),
import("@elizaos/plugin-sql"),
]);
const character = createCharacter({
name: "Eliza",
bio: "A helpful Roblox guide NPC.",
system:
"You are a helpful Roblox guide. Be concise. " +
"If a user asks you to do something in-game (teleport, move NPC, reward coins), you may use Roblox actions.",
});
const hasOpenAIKey =
typeof process.env.OPENAI_API_KEY === "string" &&
process.env.OPENAI_API_KEY.trim() !== "";
// If OPENAI_API_KEY is provided, use OpenAI for full agent behavior.
// Otherwise, use a classic ELIZA local text fallback.
const plugins = hasOpenAIKey
? [sqlPlugin, openaiPlugin, robloxPlugin]
: [sqlPlugin, elizaClassicJsonPlugin, robloxPlugin];
return new AgentRuntime({
character,
plugins,
// This bridge is a direct chat interface; always respond.
checkShouldRespond: false,
// Ensure plugins that use runtime.getSetting() can see env vars.
settings: envSettings(),
logLevel: "info",
});
}
console.log("🚀 Starting Roblox agent bridge...\n");
console.log(
`[roblox-bridge] DEBUG_ROBLOX_BRIDGE=${process.env.DEBUG_ROBLOX_BRIDGE ?? ""}`,
);
const runtime = await createRuntime();
await runtime.initialize();
const app = createRobloxBridgeApp(runtime, SHARED_SECRET);
app.listen(PORT, () => {
console.log(`🌐 Roblox agent bridge listening on http://localhost:${PORT}`);
console.log(` POST /roblox/chat`);
console.log(` GET /health\n`);
});