From b5deefbec16e4e5051af92de3be75d85a6c472c4 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Wed, 1 Apr 2026 13:52:34 +0200 Subject: [PATCH] Enforce text length limits in editor paste handling, adjust API request size limit, and crop excessive content in LLM profile extraction --- backend/api/src/app.ts | 2 +- backend/api/src/llm-extract-profile.ts | 6 ++++-- web/components/widgets/editor.tsx | 12 ++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/backend/api/src/app.ts b/backend/api/src/app.ts index 897994f9..30f44d85 100644 --- a/backend/api/src/app.ts +++ b/backend/api/src/app.ts @@ -669,7 +669,7 @@ Object.entries(handlers).forEach(([path, handler]) => { const apiRoute = [ url, - express.json(), + express.json({limit: '1mb'}), allowCorsUnrestricted, cache, typedEndpoint(path as any, handler as any), diff --git a/backend/api/src/llm-extract-profile.ts b/backend/api/src/llm-extract-profile.ts index e5fa6816..4dc7f588 100644 --- a/backend/api/src/llm-extract-profile.ts +++ b/backend/api/src/llm-extract-profile.ts @@ -274,8 +274,8 @@ TEXT TO ANALYZE: ` const text = EXTRACTION_PROMPT + content if (text.length > MAX_CONTEXT_LENGTH) { - log('Content exceeds maximum length', {length: text.length}) - throw APIErrors.badRequest('Content exceeds maximum length') + log('Content exceeds maximum length, will be cropped', {length: text.length}) + // throw APIErrors.badRequest('Content exceeds maximum length') } debug({text}) @@ -404,6 +404,8 @@ export const llmExtractProfileEndpoint: APIHandler<'llm-extract-profile'> = asyn extracted.bio = bio } + debug(JSON.stringify(bio)) + log('Profile extracted successfully', {extracted}) return extracted diff --git a/web/components/widgets/editor.tsx b/web/components/widgets/editor.tsx index 2e558636..7e45b135 100644 --- a/web/components/widgets/editor.tsx +++ b/web/components/widgets/editor.tsx @@ -178,6 +178,18 @@ export function useTextEditor(props: { return true // Prevent image in text/html from getting pasted again } + if (max) { + event.preventDefault() + const text = event.clipboardData?.getData('text/plain') ?? '' + const currentLength = editor.getText().length + const available = Math.max(0, max - currentLength) + if (available > 0 && text.length > 0) { + const croppedText = text.slice(0, available) + editor.commands.insertContent(croppedText) + } + return true + } + // Otherwise, use default paste handler }, handleDrop(_view, event, _slice, moved) {