Skip to content

Commit

Permalink
Merge pull request #3754 from elizaOS/tcm/small-fix-gui
Browse files Browse the repository at this point in the history
fix: small client fix
  • Loading branch information
tcm390 authored Mar 3, 2025
2 parents 9052bdc + e43996e commit e935b7f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 57 deletions.
51 changes: 2 additions & 49 deletions packages/agent/src/server/api/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,53 +69,6 @@ export function agentRouter(
});


// Create new agent and start it
// Pass agent data or character path or character json in body
router.post('/', async (req, res) => {
logger.info("[AGENT START] Received request to start a new agent");
const { characterPath, characterJson } = req.body;

if (!characterPath && !characterJson) {
res.status(400).json({
success: false,
error: {
code: 'INVALID_REQUEST',
message: 'Character path or character json is required'
}
});
return;
}

const character = characterPath
? await loadCharacter(characterPath)
: await jsonToCharacter(characterJson);




const existingAgents = await db.getAgents();
const existingAgent = existingAgents.find((agent) => agent.name === character.name);
if(existingAgent) {
logger.error(`[AGENT START] Character name ${character.name} already taken`);
res.status(400).json({
success: false,
error: {
code: 'INVALID_REQUEST',
message: 'Character name already taken'
}
});
return;
}

const agent = await db.createAgent(character);
await server?.startAgent(agent.id);

res.json({
success: true,
data: agent
});
});

// Get specific agent details
router.get('/:agentId', async (req, res) => {
const agentId = validateUuid(req.params.agentId);
Expand Down Expand Up @@ -227,8 +180,8 @@ export function agentRouter(
return;
}

const { updates } = req.body;
const updates = req.body;

try {
// Handle other updates if any
if (Object.keys(updates).length > 0) {
Expand Down
3 changes: 3 additions & 0 deletions packages/client/src/components/agent-creator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ export default function AgentCreator() {
description="Configure your AI character's behavior and capabilities"
onSubmit={handleSubmit}
onReset={() => setCharacterValue(defaultCharacter)}
onDelete={() => {
navigate("/");
}}
isAgent={true}
customComponents={[
{
Expand Down
12 changes: 12 additions & 0 deletions packages/client/src/components/agent-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ export default function AgentSettings({ agent, agentId }: { agent: Agent, agentI
}
};

const handleDelete = async (agent: Agent) => {
try {
await apiClient.deleteAgent(agent.id as UUID);
queryClient.invalidateQueries({ queryKey: ['agents'] });
navigate("/");
} catch (error) {
console.error("Error deleting agent:", error);
}
};


return (
<CharacterForm
characterValue={characterValue}
Expand All @@ -59,6 +70,7 @@ export default function AgentSettings({ agent, agentId }: { agent: Agent, agentI
description="Configure your AI character's behavior and capabilities"
onSubmit={handleSubmit}
onReset={() => setCharacterValue(agent)}
onDelete={() => handleDelete(agent)}
isAgent={true}
customComponents={[
{
Expand Down
16 changes: 8 additions & 8 deletions packages/client/src/components/character-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export type CharacterFormProps = {
title: string;
description: string;
onSubmit: (character: Agent) => Promise<void>;
onCancel?: () => void;
onDelete?: () => void;
onReset?: () => void;
isAgent?: boolean;
customComponents?: customComponent[];
Expand All @@ -144,7 +144,7 @@ export default function CharacterForm({
title,
description,
onSubmit,
onCancel,
onDelete,
onReset,
customComponents = []
}: CharacterFormProps) {
Expand Down Expand Up @@ -302,12 +302,12 @@ export default function CharacterForm({
</Tabs>

<div className="flex justify-between gap-4 mt-6">
<div className="flex gap-4">
{onCancel && (
<Button type="button" variant="outline" onClick={onCancel}>
Cancel
</Button>
)}
<div className="flex gap-4 text-red-500">
<Button type="button" variant="outline" onClick={() => {
onDelete?.();
}}>
Delete Character
</Button>
</div>

<div className="flex gap-4">
Expand Down

0 comments on commit e935b7f

Please sign in to comment.