Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(chore): Refactor generation to reflect handler pattern #3376

Merged
merged 3 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@
- Implement Redis Caching for Performance [\#1277](https://github.com/elizaOS/eliza/issues/1277)
- Improve logging for the Coinbase plugin [\#1261](https://github.com/elizaOS/eliza/issues/1261)
- doc: Add Twitter automation label requirement to quickstart guide [\#1253](https://github.com/elizaOS/eliza/issues/1253)
- Enhance Logging in /packages/plugin-coinbase/src/plugins Using elizaLogger [\#1192](https://github.com/elizaOS/eliza/issues/1192)
- Enhance Logging in /packages/plugin-coinbase/src/plugins Using logger [\#1192](https://github.com/elizaOS/eliza/issues/1192)
- Improve Logging in /packages/plugin-coinbase/src/plugins [\#1189](https://github.com/elizaOS/eliza/issues/1189)
- Feat: add github client to core agent [\#1130](https://github.com/elizaOS/eliza/issues/1130)

Expand Down
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions packages/agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"dependencies": {
"@elizaos/plugin-bootstrap": "workspace:*",
"@elizaos/plugin-openai": "workspace:*",
"@elizaos/core": "workspace:*",
"readline": "1.3.0",
"ws": "8.18.0",
Expand Down
22 changes: 11 additions & 11 deletions packages/agent/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
type AgentRuntime,
type Character,
elizaLogger,
logger,
getEnvVariable,
type UUID,
validateCharacterConfig,
Expand Down Expand Up @@ -77,15 +77,15 @@
res.json({ agents: agentsList });
});

router.get('/storage', async (_req, res) => {
try {
const uploadDir = path.join(process.cwd(), "data", "characters");
const files = await fs.promises.readdir(uploadDir);
res.json({ files });
} catch (error) {
res.status(500).json({ error: error.message });
}
});

router.get("/agents/:agentId", (req, res) => {
const { agentId } = validateUUIDParams(req.params, res) ?? {
Expand Down Expand Up @@ -128,84 +128,84 @@
}
});

router.post("/agents/:agentId/set", async (req, res) => {
const { agentId } = validateUUIDParams(req.params, res) ?? {
agentId: null,
};
if (!agentId) return;

let agent: AgentRuntime = agents.get(agentId);

// update character
if (agent) {
// stop agent
agent.stop();
directClient.unregisterAgent(agent);
// if it has a different name, the agentId will change
}

// stores the json data before it is modified with added data
const characterJson = { ...req.body };

// load character from body
const character = req.body;
try {
validateCharacterConfig(character);
} catch (e) {
elizaLogger.error(`Error parsing character: ${e}`);
logger.error(`Error parsing character: ${e}`);
res.status(400).json({
success: false,
message: e.message,
});
return;
}

// start it up (and register it)
try {
agent = await directClient.startAgent(character);
elizaLogger.log(`${character.name} started`);
logger.log(`${character.name} started`);
} catch (e) {
elizaLogger.error(`Error starting agent: ${e}`);
logger.error(`Error starting agent: ${e}`);
res.status(500).json({
success: false,
message: e.message,
});
return;
}

if (process.env.USE_CHARACTER_STORAGE === "true") {
try {
const filename = `${agent.agentId}.json`;
const uploadDir = path.join(
process.cwd(),
"data",
"characters"
);
const filepath = path.join(uploadDir, filename);
await fs.promises.mkdir(uploadDir, { recursive: true });
await fs.promises.writeFile(
filepath,
JSON.stringify(
{ ...characterJson, id: agent.agentId },
null,
2
)
);
elizaLogger.info(
logger.info(
`Character stored successfully at ${filepath}`
);
} catch (error) {
elizaLogger.error(
logger.error(
`Failed to store character: ${error.message}`
);
}
}

res.json({
id: character.id,
character: character,
});
});

// router.get("/agents/:agentId/channels", async (req, res) => {
// const { agentId } = validateUUIDParams(req.params, res) ?? {
Expand Down Expand Up @@ -324,7 +324,7 @@
// );
// res.json({ agents: allAgents, attestation: attestation });
// } catch (error) {
// elizaLogger.error("Failed to get TEE agents:", error);
// logger.error("Failed to get TEE agents:", error);
// res.status(500).json({
// error: "Failed to get TEE agents",
// });
Expand All @@ -350,7 +350,7 @@
// );
// res.json({ agent: teeAgent, attestation: attestation });
// } catch (error) {
// elizaLogger.error("Failed to get TEE agent:", error);
// logger.error("Failed to get TEE agent:", error);
// res.status(500).json({
// error: "Failed to get TEE agent",
// });
Expand Down Expand Up @@ -391,7 +391,7 @@
// attestation: attestation,
// });
// } catch (error) {
// elizaLogger.error("Failed to get TEE logs:", error);
// logger.error("Failed to get TEE logs:", error);
// res.status(500).json({
// error: "Failed to get TEE logs",
// });
Expand All @@ -417,14 +417,14 @@
throw new Error("No character path or JSON provided");
}
await directClient.startAgent(character);
elizaLogger.log(`${character.name} started`);
logger.log(`${character.name} started`);

res.json({
id: character.id,
character: character,
});
} catch (e) {
elizaLogger.error(`Error parsing character: ${e}`);
logger.error(`Error parsing character: ${e}`);
res.status(400).json({
error: e.message,
});
Expand Down
8 changes: 5 additions & 3 deletions packages/agent/src/defaultCharacter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { type Character, ModelProviderName } from "@elizaos/core";
import { type Character } from "@elizaos/core";
import { OpenAIPlugin } from "@elizaos/plugin-openai";

export const defaultCharacter: Character = {
name: "Eliza",
username: "eliza",
plugins: [],
modelProvider: ModelProviderName.OPENAI,
plugins: [
OpenAIPlugin
],
settings: {
secrets: {},
voice: {
Expand Down
Loading
Loading