diff --git a/src/app/api/webhooks/clerk/route.ts b/src/app/api/webhooks/clerk/route.ts index 9bd3eb9f4ba0..6bd88cd7cf4e 100644 --- a/src/app/api/webhooks/clerk/route.ts +++ b/src/app/api/webhooks/clerk/route.ts @@ -28,6 +28,7 @@ export const POST = async (req: Request): Promise => { const userService = new UserService(); switch (type) { case 'user.created': { + pino.info('creating user due to clerk webhook'); return userService.createUser(data.id, data); } case 'user.deleted': { diff --git a/src/server/routers/lambda/agent.ts b/src/server/routers/lambda/agent.ts index e8e01fab45cd..1ce31bef76b0 100644 --- a/src/server/routers/lambda/agent.ts +++ b/src/server/routers/lambda/agent.ts @@ -1,10 +1,12 @@ import { z } from 'zod'; import { INBOX_SESSION_ID } from '@/const/session'; +import { DEFAULT_AGENT_CONFIG } from '@/const/settings'; import { AgentModel } from '@/database/server/models/agent'; import { FileModel } from '@/database/server/models/file'; import { KnowledgeBaseModel } from '@/database/server/models/knowledgeBase'; import { SessionModel } from '@/database/server/models/session'; +import { UserModel } from '@/database/server/models/user'; import { pino } from '@/libs/logger'; import { authedProcedure, router } from '@/libs/trpc'; import { KnowledgeItem, KnowledgeType } from '@/types/knowledgeBase'; @@ -84,6 +86,10 @@ export const agentRouter = router({ const item = await ctx.sessionModel.findByIdOrSlug(INBOX_SESSION_ID); // if there is no session for user, create one if (!item) { + // if there is no user, return default config + const user = await UserModel.findById(ctx.userId); + if (!user) return DEFAULT_AGENT_CONFIG; + const res = await ctx.sessionModel.createInbox(); pino.info('create inbox session', res); } diff --git a/src/server/services/user/index.ts b/src/server/services/user/index.ts index c9708b3bd62f..1bc3480fed74 100644 --- a/src/server/services/user/index.ts +++ b/src/server/services/user/index.ts @@ -6,8 +6,6 @@ import { pino } from '@/libs/logger'; export class UserService { createUser = async (id: string, params: UserJSON) => { - pino.info('creating user due to clerk webhook'); - // Check if user already exists const res = await UserModel.findById(id);