Skip to content

Commit 855e2c4

Browse files
authored
fix(kb): handle larger files in the kb (#2324)
* fix(kb): handle larger files in the kb * fixed images on login page
1 parent 3bde9e8 commit 855e2c4

File tree

7 files changed

+19
-10
lines changed

7 files changed

+19
-10
lines changed

apps/sim/app/(landing)/components/nav/nav.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export default function Nav({ hideAuthButtons = false, variant = 'landing' }: Na
135135
priority
136136
loading='eager'
137137
quality={100}
138+
unoptimized
138139
/>
139140
) : (
140141
<Image

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/base.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ export function KnowledgeBase({
466466
*/
467467
const checkForDeadProcesses = async () => {
468468
const now = new Date()
469-
const DEAD_PROCESS_THRESHOLD_MS = 150 * 1000
469+
const DEAD_PROCESS_THRESHOLD_MS = 600 * 1000 // 10 minutes
470470

471471
const staleDocuments = documents.filter((doc) => {
472472
if (doc.processingStatus !== 'processing' || !doc.processingStartedAt) {

apps/sim/app/workspace/[workspaceId]/knowledge/hooks/use-knowledge-upload.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ export function useKnowledgeUpload(options: UseKnowledgeUploadOptions = {}) {
423423
return await uploadFileInChunks(file, presignedData, timeoutMs, fileIndex)
424424
}
425425

426+
if (presignedOverride?.directUploadSupported && presignedOverride.presignedUrl) {
427+
return await uploadFileDirectly(file, presignedOverride, timeoutMs, controller, fileIndex)
428+
}
429+
426430
return await uploadFileThroughAPI(file, timeoutMs)
427431
} finally {
428432
clearTimeout(timeoutId)
@@ -510,7 +514,6 @@ export function useKnowledgeUpload(options: UseKnowledgeUploadOptions = {}) {
510514
if (event.lengthComputable && fileIndex !== undefined && !isCompleted) {
511515
const percentComplete = Math.round((event.loaded / event.total) * 100)
512516
setUploadProgress((prev) => {
513-
// Only update if this file is still uploading
514517
if (prev.fileStatuses?.[fileIndex]?.status === 'uploading') {
515518
return {
516519
...prev,
@@ -638,7 +641,6 @@ export function useKnowledgeUpload(options: UseKnowledgeUploadOptions = {}) {
638641
})
639642

640643
if (!partUrlsResponse.ok) {
641-
// Abort the multipart upload if we can't get URLs
642644
await fetch('/api/files/multipart?action=abort', {
643645
method: 'POST',
644646
headers: { 'Content-Type': 'application/json' },
@@ -822,9 +824,6 @@ export function useKnowledgeUpload(options: UseKnowledgeUploadOptions = {}) {
822824
}
823825
}
824826

825-
/**
826-
* Upload files using batch presigned URLs (works for both S3 and Azure Blob)
827-
*/
828827
/**
829828
* Uploads files in batches using presigned URLs
830829
*/

apps/sim/lib/core/security/csp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export function generateRuntimeCSP(): string {
153153
default-src 'self';
154154
script-src 'self' 'unsafe-inline' 'unsafe-eval' https://*.google.com https://apis.google.com https://assets.onedollarstats.com;
155155
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
156-
img-src 'self' data: blob: https://*.googleusercontent.com https://*.google.com https://*.atlassian.com https://cdn.discordapp.com https://*.githubusercontent.com ${brandLogoDomain} ${brandFaviconDomain};
156+
img-src 'self' data: blob: https://*.googleusercontent.com https://*.google.com https://*.atlassian.com https://cdn.discordapp.com https://*.githubusercontent.com https://*.s3.amazonaws.com https://s3.amazonaws.com https://*.amazonaws.com https://*.blob.core.windows.net https://github.com/* ${brandLogoDomain} ${brandFaviconDomain};
157157
media-src 'self' blob:;
158158
font-src 'self' https://fonts.gstatic.com;
159159
connect-src 'self' ${appUrl} ${ollamaUrl} ${socketUrl} ${socketWsUrl} https://api.browser-use.com https://api.exa.ai https://api.firecrawl.dev https://*.googleapis.com https://*.amazonaws.com https://*.s3.amazonaws.com https://*.blob.core.windows.net https://api.github.com https://github.com/* https://*.atlassian.com https://*.supabase.co https://collector.onedollarstats.com ${dynamicDomainsStr};

apps/sim/lib/knowledge/documents/service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ export async function markDocumentAsFailedTimeout(
10891089
): Promise<{ success: boolean; processingDuration: number }> {
10901090
const now = new Date()
10911091
const processingDuration = now.getTime() - processingStartedAt.getTime()
1092-
const DEAD_PROCESS_THRESHOLD_MS = 150 * 1000
1092+
const DEAD_PROCESS_THRESHOLD_MS = 600 * 1000 // 10 minutes
10931093

10941094
if (processingDuration <= DEAD_PROCESS_THRESHOLD_MS) {
10951095
throw new Error('Document has not been processing long enough to be considered dead')

apps/sim/lib/uploads/utils/file-utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ export function validateKnowledgeBaseFile(
278278

279279
/**
280280
* Extract storage key from a file path
281+
* Handles URLs like /api/files/serve/s3/key or /api/files/serve/blob/key
281282
*/
282283
export function extractStorageKey(filePath: string): string {
283284
let pathWithoutQuery = filePath.split('?')[0]
@@ -292,7 +293,13 @@ export function extractStorageKey(filePath: string): string {
292293
}
293294

294295
if (pathWithoutQuery.startsWith('/api/files/serve/')) {
295-
return decodeURIComponent(pathWithoutQuery.substring('/api/files/serve/'.length))
296+
let key = decodeURIComponent(pathWithoutQuery.substring('/api/files/serve/'.length))
297+
if (key.startsWith('s3/')) {
298+
key = key.substring(3)
299+
} else if (key.startsWith('blob/')) {
300+
key = key.substring(5)
301+
}
302+
return key
296303
}
297304
return pathWithoutQuery
298305
}

apps/sim/proxy.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ export async function proxy(request: NextRequest) {
144144
if (hasActiveSession) {
145145
return NextResponse.redirect(new URL('/workspace', request.url))
146146
}
147-
return NextResponse.next()
147+
const response = NextResponse.next()
148+
response.headers.set('Content-Security-Policy', generateRuntimeCSP())
149+
return response
148150
}
149151

150152
if (url.pathname.startsWith('/chat/')) {

0 commit comments

Comments
 (0)