@lobehub/chat
Version:
Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.
30 lines (23 loc) • 765 B
text/typescript
import { generate } from 'random-words';
import { createNanoId } from '@/utils/uuid';
const prefixes = {
agents: 'agt',
documents: 'docs',
files: 'file',
knowledgeBases: 'kb',
messages: 'msg',
plugins: 'plg',
sessionGroups: 'sg',
sessions: 'ssn',
threads: 'thd',
topics: 'tpc',
user: 'user',
} as const;
export const idGenerator = (namespace: keyof typeof prefixes, size = 12) => {
const hash = createNanoId(size);
const prefix = prefixes[namespace];
if (!prefix) throw new Error(`Invalid namespace: ${namespace}, please check your code.`);
return `${prefix}_${hash()}`;
};
export const randomSlug = (count = 2) => (generate(count) as string[]).join('-');
export const inboxSessionId = (userId: string) => `ssn_inbox_${userId}`;