fix(agent-jobs): validate claims before claiming

This commit is contained in:
Gabriel Brown
2026-07-10 17:26:17 -04:00
parent 926008fd3a
commit cf45404b7d
3 changed files with 281 additions and 17 deletions
+2 -15
View File
@@ -1,6 +1,6 @@
'use node';
import { ConvexError, v } from 'convex/values';
import { v } from 'convex/values';
import type { Doc } from './_generated/dataModel';
import { internal } from './_generated/api';
@@ -56,20 +56,7 @@ export const claimNextForWorker = action({
},
)) as ClaimedJob | null;
if (!claimed) return null;
if (!claimed.spoon) {
throw new ConvexError('Claimed job points at a missing Spoon.');
}
if (!claimed.aiProviderProfile) {
throw new ConvexError(
'AI is not configured for this user. Add an AI provider in settings.',
);
}
if (
claimed.aiProviderProfile.authType !== 'none' &&
!claimed.aiProviderProfile.encryptedSecret
) {
throw new ConvexError('Selected AI provider is missing credentials.');
}
if (!claimed.spoon || !claimed.aiProviderProfile) return null;
const profile = claimed.aiProviderProfile;
return {
job: claimed.job,