mirror of
https://github.com/lobehub/lobe-chat.git
synced 2026-06-18 05:18:31 +00:00
✨ feat: onboarding ui
This commit is contained in:
@@ -6,7 +6,7 @@ import type {
|
||||
UpdateAiProviderConfigParams,
|
||||
} from '@lobechat/types';
|
||||
import { and, asc, desc, eq } from 'drizzle-orm';
|
||||
import { isEmpty } from 'lodash-es';
|
||||
import { isEmpty } from 'es-toolkit/compat';
|
||||
import { ModelProvider } from 'model-bank';
|
||||
|
||||
import { DEFAULT_MODEL_PROVIDER_LIST } from '@/config/modelProviders';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ChunkMetadata, FileChunk } from '@lobechat/types';
|
||||
import { and, asc, cosineDistance, count, desc, eq, inArray, isNull, sql } from 'drizzle-orm';
|
||||
import { chunk } from 'lodash-es';
|
||||
import { chunk } from 'es-toolkit/compat';
|
||||
|
||||
import {
|
||||
NewChunkItem,
|
||||
|
||||
@@ -108,6 +108,7 @@ export class GenerationModel {
|
||||
const newFile = await this.fileModel.create(
|
||||
{
|
||||
...file,
|
||||
parentId: file.parentId ?? undefined,
|
||||
source: FileSource.ImageGeneration,
|
||||
},
|
||||
true,
|
||||
|
||||
@@ -269,7 +269,7 @@ export class SessionModel {
|
||||
params,
|
||||
systemRole,
|
||||
provider,
|
||||
plugins = [],
|
||||
plugins,
|
||||
openingMessage,
|
||||
openingQuestions = [],
|
||||
// TTS config
|
||||
@@ -280,6 +280,8 @@ export class SessionModel {
|
||||
examples, // maps to fewShots
|
||||
identifier, // maps to marketIdentifier
|
||||
marketIdentifier,
|
||||
// Editor data
|
||||
editorData,
|
||||
} = config as any;
|
||||
if (type === 'group') {
|
||||
const result = await trx
|
||||
@@ -306,6 +308,7 @@ export class SessionModel {
|
||||
chatConfig: chatConfig || {},
|
||||
createdAt: new Date(),
|
||||
description,
|
||||
editorData: editorData || null,
|
||||
fewShots: examples || null, // Map examples to fewShots field
|
||||
id: idGenerator('agents'),
|
||||
marketIdentifier: identifier || marketIdentifier,
|
||||
@@ -635,6 +638,7 @@ export class SessionModel {
|
||||
avatar: agent?.avatar ?? avatar ?? undefined,
|
||||
backgroundColor: agent?.backgroundColor ?? backgroundColor ?? undefined,
|
||||
description: agent?.description ?? description ?? undefined,
|
||||
|
||||
marketIdentifier: agent?.marketIdentifier ?? undefined,
|
||||
tags: agent?.tags ?? undefined,
|
||||
title: agent?.title ?? title ?? undefined,
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
} from '@lobechat/types';
|
||||
import { TRPCError } from '@trpc/server';
|
||||
import dayjs from 'dayjs';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { and, eq, gt, inArray, or } from 'drizzle-orm';
|
||||
import type { PartialDeep } from 'type-fest';
|
||||
|
||||
import { merge } from '@/utils/merge';
|
||||
@@ -34,6 +34,17 @@ export class UserNotFoundError extends TRPCError {
|
||||
}
|
||||
}
|
||||
|
||||
export interface ListUsersForMemoryExtractorCursor {
|
||||
createdAt: Date;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export type ListUsersForMemoryExtractorOptions = {
|
||||
cursor?: ListUsersForMemoryExtractorCursor;
|
||||
limit?: number;
|
||||
whitelist?: string[];
|
||||
};
|
||||
|
||||
export class UserModel {
|
||||
private userId: string;
|
||||
private db: LobeChatDatabase;
|
||||
@@ -70,8 +81,10 @@ export class UserModel {
|
||||
email: users.email,
|
||||
firstName: users.firstName,
|
||||
fullName: users.fullName,
|
||||
interests: users.interests,
|
||||
isOnboarded: users.isOnboarded,
|
||||
lastName: users.lastName,
|
||||
onboarding: users.onboarding,
|
||||
preference: users.preference,
|
||||
settingsDefaultAgent: userSettings.defaultAgent,
|
||||
|
||||
@@ -81,6 +94,7 @@ export class UserModel {
|
||||
settingsKeyVaults: userSettings.keyVaults,
|
||||
settingsLanguageModel: userSettings.languageModel,
|
||||
settingsMarket: userSettings.market,
|
||||
settingsMemory: userSettings.memory,
|
||||
settingsSystemAgent: userSettings.systemAgent,
|
||||
settingsTTS: userSettings.tts,
|
||||
settingsTool: userSettings.tool,
|
||||
@@ -114,6 +128,7 @@ export class UserModel {
|
||||
keyVaults: decryptKeyVaults,
|
||||
languageModel: state.settingsLanguageModel || {},
|
||||
market: state.settingsMarket || undefined,
|
||||
memory: state.settingsMemory || {},
|
||||
systemAgent: state.settingsSystemAgent || {},
|
||||
tool: state.settingsTool || {},
|
||||
tts: state.settingsTTS || {},
|
||||
@@ -124,8 +139,10 @@ export class UserModel {
|
||||
email: state.email || undefined,
|
||||
firstName: state.firstName || undefined,
|
||||
fullName: state.fullName || undefined,
|
||||
interests: state.interests || undefined,
|
||||
isOnboarded: state.isOnboarded,
|
||||
lastName: state.lastName || undefined,
|
||||
onboarding: state.onboarding || undefined,
|
||||
preference: state.preference as UserPreference,
|
||||
settings,
|
||||
userId: this.userId,
|
||||
@@ -148,6 +165,16 @@ export class UserModel {
|
||||
return this.db.query.userSettings.findFirst({ where: eq(userSettings.id, this.userId) });
|
||||
};
|
||||
|
||||
getUserSettingsDefaultAgentConfig = async () => {
|
||||
const result = await this.db
|
||||
.select({ defaultAgent: userSettings.defaultAgent })
|
||||
.from(userSettings)
|
||||
.where(eq(userSettings.id, this.userId))
|
||||
.limit(1);
|
||||
|
||||
return result[0]?.defaultAgent;
|
||||
};
|
||||
|
||||
updateUser = async (value: Partial<UserItem>) => {
|
||||
const nextValue = UserModel.normalizeUniqueUserFields(value);
|
||||
|
||||
@@ -278,4 +305,30 @@ export class UserModel {
|
||||
// Decrypt keyVaults
|
||||
return await decryptor(state.settingsKeyVaults, id);
|
||||
};
|
||||
|
||||
static listUsersForMemoryExtractor = (
|
||||
db: LobeChatDatabase,
|
||||
options: ListUsersForMemoryExtractorOptions = {},
|
||||
) => {
|
||||
const cursorCondition = options.cursor
|
||||
? or(
|
||||
gt(users.createdAt, options.cursor.createdAt),
|
||||
and(eq(users.createdAt, options.cursor.createdAt), gt(users.id, options.cursor.id)),
|
||||
)
|
||||
: undefined;
|
||||
|
||||
const whitelistCondition =
|
||||
options.whitelist && options.whitelist.length > 0
|
||||
? inArray(users.id, options.whitelist)
|
||||
: undefined;
|
||||
|
||||
const where = and(cursorCondition, whitelistCondition);
|
||||
|
||||
return db.query.users.findMany({
|
||||
columns: { createdAt: true, id: true },
|
||||
limit: options.limit,
|
||||
orderBy: (fields, { asc }) => [asc(fields.createdAt), asc(fields.id)],
|
||||
where,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user