Skip to content
Merged
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
6 changes: 5 additions & 1 deletion apps/sim/app/api/knowledge/migrated-routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const document = {
chunkCount: 1,
tokenCount: 5,
characterCount: 20,
processingStatus: 'completed' as const,
processingStatus: 'pending' as const,
enabled: true,
uploadedAt: new Date('2026-01-01T00:00:00Z'),
}
Expand Down Expand Up @@ -356,6 +356,10 @@ describe('migrated internal Knowledge routes', () => {
})

expect(response.status).toBe(200)
await expect(response.json()).resolves.toMatchObject({
success: true,
data: { processingStatus: 'pending' },
})
expect(mocks.platformUpload).toHaveBeenCalledOnce()
expect(mocks.capture).toHaveBeenCalledOnce()
expect(mocks.createDocuments.mock.invocationCallOrder[0]).toBeLessThan(
Expand Down
5 changes: 4 additions & 1 deletion apps/sim/lib/knowledge/documents/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,7 @@ export async function createSingleDocument(
chunkCount: number
tokenCount: number
characterCount: number
processingStatus: 'pending'
enabled: boolean
uploadedAt: Date
tag1: string | null
Expand Down Expand Up @@ -1973,6 +1974,7 @@ export async function createSingleDocument(
chunkCount: 0,
tokenCount: 0,
characterCount: 0,
processingStatus: 'pending' as const,
enabled: true,
uploadedAt: now,
uploadedBy,
Expand Down Expand Up @@ -2126,6 +2128,7 @@ export async function createSingleDocument(
chunkCount: number
tokenCount: number
characterCount: number
processingStatus: 'pending'
enabled: boolean
uploadedAt: Date
tag1: string | null
Expand All @@ -2143,7 +2146,7 @@ export async function getDocumentByUploadId(
documentId: string,
knowledgeBaseId: string
): Promise<
| (Awaited<ReturnType<typeof createSingleDocument>> & {
| (Omit<Awaited<ReturnType<typeof createSingleDocument>>, 'processingStatus'> & {
processingStatus: 'pending' | 'processing' | 'completed' | 'failed'
})
| null
Expand Down
19 changes: 19 additions & 0 deletions apps/sim/lib/knowledge/documents/storage-billing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,25 @@ describe('knowledge document storage attribution', () => {
expect(mockMaybeNotifyStorageLimitForBillingContext).toHaveBeenCalledWith(STORAGE_CONTEXT, 5)
})

it('returns the pending processing state persisted for a new document', async () => {
const created = await createSingleDocument(
{
filename: 'note.txt',
fileUrl: 'data:text/plain;base64,SGVsbG8=',
fileSize: 5,
mimeType: 'text/plain',
},
'knowledge-base-1',
'request-1',
'external-collaborator'
)

expect(created.processingStatus).toBe('pending')
expect(dbChainMockFns.values).toHaveBeenCalledWith(
expect.objectContaining({ processingStatus: 'pending' })
)
})

it('resolves admission before opening the document transaction', async () => {
let transactionOpen = false
mockResolveStorageBillingContext.mockImplementationOnce(async () => {
Expand Down
9 changes: 6 additions & 3 deletions apps/sim/lib/knowledge/orchestration/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ export interface KnowledgeDocumentInput {
*/
export type KnowledgeDocumentProcessing = 'queue' | 'async'

export type CreatedKnowledgeDocument = Awaited<ReturnType<typeof createSingleDocument>> & {
/** Present when an idempotent completion returns an already-processing document. */
processingStatus?: 'pending' | 'processing' | 'completed' | 'failed'
export type CreatedKnowledgeDocument = Omit<
Awaited<ReturnType<typeof createSingleDocument>>,
'processingStatus'
> & {
/** New documents are pending; idempotent completion may return a later persisted state. */
processingStatus: 'pending' | 'processing' | 'completed' | 'failed'
}

export interface PerformUploadKnowledgeDocumentParams extends KnowledgeOperationContext {
Expand Down
Loading