Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions frontend/src/routes/_authenticated/integrations/apiKey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 16 additions & 8 deletions server/api/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8240,8 +8240,22 @@ 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: authEmail, via_apiKey } = getAuth(c)
email = authEmail

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")
Expand All @@ -8255,12 +8269,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)}...`,
Expand Down
5 changes: 5 additions & 0 deletions server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions server/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading