import { useStateBasedMentionProvider } from 'cedar-os';
function MultiMentionChat() {
const users = [
{ id: '1', name: 'Alice', role: 'Designer' },
{ id: '2', name: 'Bob', role: 'Developer' },
];
const channels = [
{ id: '1', name: 'general', topic: 'General discussion' },
{ id: '2', name: 'dev', topic: 'Development updates' },
];
const commands = [
{ id: '1', name: 'help', description: 'Show help' },
{ id: '2', name: 'reset', description: 'Reset chat' },
];
// @ for users
useStateBasedMentionProvider({
stateKey: 'users',
trigger: '@',
label: 'Users',
icon: '👤',
getItems: (query) => {
const filtered = query
? users.filter((u) =>
u.name.toLowerCase().includes(query.toLowerCase())
)
: users;
return filtered.map((user) => ({
id: user.id,
label: user.name,
data: user,
metadata: { icon: '👤' },
}));
},
toContextEntry: (item) => ({
id: item.id,
source: 'mention',
data: item.data,
metadata: { label: item.label, icon: '👤' },
}),
});
// # for channels/topics
useStateBasedMentionProvider({
stateKey: 'channels',
trigger: '#',
label: 'Channels',
icon: '📢',
getItems: (query) => {
const filtered = query
? channels.filter((c) =>
c.name.toLowerCase().includes(query.toLowerCase())
)
: channels;
return filtered.map((channel) => ({
id: channel.id,
label: channel.name,
data: channel,
metadata: { icon: '📢' },
}));
},
toContextEntry: (item) => ({
id: item.id,
source: 'mention',
data: item.data,
metadata: { label: item.label, icon: '📢' },
}),
});
// / for commands
useStateBasedMentionProvider({
stateKey: 'commands',
trigger: '/',
label: 'Commands',
icon: '⚡',
getItems: (query) => {
const filtered = query
? commands.filter((c) =>
c.name.toLowerCase().includes(query.toLowerCase())
)
: commands;
return filtered.map((command) => ({
id: command.id,
label: command.name,
data: command,
metadata: { icon: '⚡' },
}));
},
toContextEntry: (item) => ({
id: item.id,
source: 'mention',
data: item.data,
metadata: { label: item.label, icon: '⚡' },
}),
});
return <ChatInput />;
}