Add visual progress indicator for AI assignment batches

- Add AssignmentJob model to track AI assignment progress
- Create startAIAssignmentJob mutation for background processing
- Add getAIAssignmentJobStatus query for polling progress
- Update AI assignment service with progress callback support
- Add progress bar UI showing batch/project processing status
- Add toast notifications for job completion/failure
- Add AI_SUGGESTIONS_READY notification type

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-04 17:40:26 +01:00
parent 148925cb95
commit 6f6d5ef501
5 changed files with 439 additions and 21 deletions

View File

@@ -86,6 +86,15 @@ interface AssignmentConstraints {
}>
}
export interface AssignmentProgressCallback {
(progress: {
currentBatch: number
totalBatches: number
processedCount: number
totalProjects: number
}): Promise<void>
}
// ─── AI Processing ───────────────────────────────────────────────────────────
/**
@@ -247,7 +256,8 @@ export async function generateAIAssignments(
projects: ProjectForAssignment[],
constraints: AssignmentConstraints,
userId?: string,
entityId?: string
entityId?: string,
onProgress?: AssignmentProgressCallback
): Promise<AIAssignmentResult> {
// Truncate descriptions before anonymization
const truncatedProjects = projects.map((p) => ({
@@ -279,11 +289,14 @@ export async function generateAIAssignments(
let totalTokens = 0
// Process projects in batches
const totalBatches = Math.ceil(anonymizedData.projects.length / ASSIGNMENT_BATCH_SIZE)
for (let i = 0; i < anonymizedData.projects.length; i += ASSIGNMENT_BATCH_SIZE) {
const batchProjects = anonymizedData.projects.slice(i, i + ASSIGNMENT_BATCH_SIZE)
const batchMappings = anonymizedData.projectMappings.slice(i, i + ASSIGNMENT_BATCH_SIZE)
const currentBatch = Math.floor(i / ASSIGNMENT_BATCH_SIZE) + 1
console.log(`[AI Assignment] Processing batch ${Math.floor(i / ASSIGNMENT_BATCH_SIZE) + 1}/${Math.ceil(anonymizedData.projects.length / ASSIGNMENT_BATCH_SIZE)}`)
console.log(`[AI Assignment] Processing batch ${currentBatch}/${totalBatches}`)
const { suggestions, tokensUsed } = await processAssignmentBatch(
openai,
@@ -298,6 +311,17 @@ export async function generateAIAssignments(
allSuggestions.push(...suggestions)
totalTokens += tokensUsed
// Report progress after each batch
if (onProgress) {
const processedCount = Math.min((currentBatch) * ASSIGNMENT_BATCH_SIZE, projects.length)
await onProgress({
currentBatch,
totalBatches,
processedCount,
totalProjects: projects.length,
})
}
}
console.log(`[AI Assignment] Completed. Total suggestions: ${allSuggestions.length}, Total tokens: ${totalTokens}`)

View File

@@ -16,6 +16,7 @@ export const NotificationTypes = {
// Admin notifications
FILTERING_COMPLETE: 'FILTERING_COMPLETE',
FILTERING_FAILED: 'FILTERING_FAILED',
AI_SUGGESTIONS_READY: 'AI_SUGGESTIONS_READY',
NEW_APPLICATION: 'NEW_APPLICATION',
BULK_APPLICATIONS: 'BULK_APPLICATIONS',
DOCUMENTS_UPLOADED: 'DOCUMENTS_UPLOADED',