From fa40523a5f8f6c154847f06659d3606d171bcc43 Mon Sep 17 00:00:00 2001 From: Himansh Varma Date: Tue, 13 Jan 2026 15:39:15 +0530 Subject: [PATCH 1/2] feat: exposed chat title generation api through api key --- .../_authenticated/integrations/apiKey.tsx | 5 ++++ server/api/chat/chat.ts | 23 ++++++++++++------- server/server.ts | 5 ++++ server/shared/types.ts | 1 + 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/frontend/src/routes/_authenticated/integrations/apiKey.tsx b/frontend/src/routes/_authenticated/integrations/apiKey.tsx index 6372927ad..d2810158d 100644 --- a/frontend/src/routes/_authenticated/integrations/apiKey.tsx +++ b/frontend/src/routes/_authenticated/integrations/apiKey.tsx @@ -148,6 +148,11 @@ const AVAILABLE_SCOPES: ApiKeyScope[] = [ name: "Enhanced Message Feedback", description: "Allows submitting enhanced feedback with custom comments and options", }, + { + id: ApiKeyScopes.GENERATE_CHAT_TITLE, + name: "Generate Chat Title", + description: "Allows generating titles for chat messages", + }, ] interface ApiKeyProps { diff --git a/server/api/chat/chat.ts b/server/api/chat/chat.ts index b1209a6b0..80c9dba34 100644 --- a/server/api/chat/chat.ts +++ b/server/api/chat/chat.ts @@ -8240,8 +8240,21 @@ export const GetAvailableModelsApi = async (c: Context) => { export const GenerateChatTitleApi = async (c: Context) => { let email = "" try { - const { sub, workspaceId } = c.get(JwtPayloadKey) - email = sub + const { email, via_apiKey } = getAuth(c) + + if (via_apiKey) { + const apiKeyScopes = + safeGet<{ scopes?: string[] }>(c, "config")?.scopes || [] + if (!apiKeyScopes.includes(ApiKeyScopes.GENERATE_CHAT_TITLE)) { + return c.json( + { + message: + "API key does not have scope to generate chat title", + }, + 403, + ) + } + } // @ts-ignore const { chatId, message } = c.req.valid("json") @@ -8255,12 +8268,6 @@ export const GenerateChatTitleApi = async (c: Context) => { assistantResponse = currentChat[1].message } - const { user, workspace } = await getUserAndWorkspaceByEmail( - db, - workspaceId, - email, - ) - // Generate proper title using LLM loggerWithChild({ email: email }).info( `Generating title for chat ${chatId} with message: ${String(message).substring(0, 100)}...`, diff --git a/server/server.ts b/server/server.ts index 926d27334..ddce038c3 100644 --- a/server/server.ts +++ b/server/server.ts @@ -2020,6 +2020,11 @@ app .delete("/agent/:agentExternalId", DeleteAgentApi) // Delete Agent .get("/agent/:agentExternalId", GetAgentApi) // Get Agent details .get("/chat/history", zValidator("query", chatHistorySchema), ChatHistory) // List chat history + .post( + "/chat/generateTitle", + zValidator("json", chatTitleSchema), + GenerateChatTitleApi, + ) // Generate chat title .post( "/message/feedback", zValidator("json", messageFeedbackSchema), diff --git a/server/shared/types.ts b/server/shared/types.ts index 5de52ba42..f6c7dab9e 100644 --- a/server/shared/types.ts +++ b/server/shared/types.ts @@ -247,6 +247,7 @@ export enum ApiKeyScopes { DELETE_COLLECTION_ITEM = "DELETE_COLLECTION_ITEM", MESSAGE_FEEDBACK = "MESSAGE_FEEDBACK", ENHANCED_MESSAGE_FEEDBACK = "ENHANCED_MESSAGE_FEEDBACK", + GENERATE_CHAT_TITLE = "GENERATE_CHAT_TITLE", } export const AutocompleteFileSchema = z From 2ef9bc2e9b1fcf9aff0183dd27d8ff909bf85cad Mon Sep 17 00:00:00 2001 From: Himansh varma <126441540+Himanshvarma@users.noreply.github.com> Date: Tue, 13 Jan 2026 15:42:45 +0530 Subject: [PATCH 2/2] Update server/api/chat/chat.ts fixed ai comment Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- server/api/chat/chat.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/api/chat/chat.ts b/server/api/chat/chat.ts index 80c9dba34..ce1c5665b 100644 --- a/server/api/chat/chat.ts +++ b/server/api/chat/chat.ts @@ -8240,7 +8240,8 @@ export const GetAvailableModelsApi = async (c: Context) => { export const GenerateChatTitleApi = async (c: Context) => { let email = "" try { - const { email, via_apiKey } = getAuth(c) + const { email: authEmail, via_apiKey } = getAuth(c) + email = authEmail if (via_apiKey) { const apiKeyScopes =