fix(agent-jobs): validate claims before claiming
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user