Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ export class ConversationObject extends EventTarget {
}
addAgent(agentId: string, player: Player) {
this.agentsMap.set(agentId, player);
this.dispatchEvent(new Event('agentschange'));
}
removeAgent(agentId: string) {
this.agentsMap.delete(agentId);
this.dispatchEvent(new Event('agentschange'));
}

getKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,24 @@ const CharactersPrompt = () => {
const agent = useAgent();
const name = useName();
const bio = usePersonality();
const [agents, setAgents] = useState([]);
if (conversation) {
const agents = conversation.getAgents();
const currentAgentSpec = {
id: agent.id,
name,
bio,
};
const agentSpecs = agents.map((agent) => {
const agentSpec = agent.getPlayerSpec() as any;
return {
name: agentSpec?.name,
id: agent.playerId,
bio: agentSpec?.bio,
};
});

const agentSpecs = agents
.filter(mapAgent => mapAgent.playerId !== agent.id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want the current agent in this list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current agent is being added via the currentAgentSpec + formatAgent inside the Prompt component, agentSpecs mapped out for "Other Characters" hence need to exclude the current agent

.map((agent) => {
const agentSpec = agent.getPlayerSpec() as any;
return {
name: agentSpec?.name,
id: agent.playerId,
bio: agentSpec?.bio,
};
});

const formatAgent = (agent: any) => {
return [
Expand All @@ -144,6 +147,18 @@ const CharactersPrompt = () => {
].join('\n');
};

useEffect(() => {
const updateAgents = () => {
const agents = conversation.getAgents();
setAgents(agents);
};
conversation.addEventListener('agentschange', updateAgents);

return () => {
conversation.removeEventListener('agentschange', updateAgents);
};
}, [conversation]);

return (
<Prompt>
{dedent`
Expand Down