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:
@@ -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}`)
|
||||
|
||||
Reference in New Issue
Block a user