-
Notifications
You must be signed in to change notification settings - Fork 4
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
listen to conversation agent additions in chat #805
base: dev
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want the current agent in this list? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 [ | ||
|
@@ -144,6 +147,20 @@ const CharactersPrompt = () => { | |
].join('\n'); | ||
}; | ||
|
||
useEffect(() => { | ||
const updateAgents = () => { | ||
const agents = conversation.getAgents(); | ||
setAgents(agents); | ||
}; | ||
conversation.addEventListener('addAgent', updateAgents); | ||
conversation.addEventListener('removeAgent', updateAgents); | ||
|
||
return () => { | ||
conversation.removeEventListener('addAgent', updateAgents); | ||
conversation.removeEventListener('removeAgent', updateAgents); | ||
}; | ||
}, [conversation]); | ||
|
||
return ( | ||
<Prompt> | ||
{dedent` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommend rename to
'agentschange'
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated