mirror of
https://github.com/lobehub/lobehub
synced 2026-04-21 17:47:27 +00:00
* add document service * add file item * add file content for direct upload file * fix tests * fix tests * fix tests * add debug log for file-loaders * add debug log and test * improve loading * update tests * fix pdf parser * fix pdf version * fix pdf worker url * fix pdf worker url * fix test
29 lines
765 B
TypeScript
29 lines
765 B
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}`;
|