diff --git a/apps/app/src/app/(app)/[orgId]/tasks/[taskId]/automation/[automationId]/actions/generate-suggestions.ts b/apps/app/src/app/(app)/[orgId]/tasks/[taskId]/automation/[automationId]/actions/generate-suggestions.ts index 80213bcfe..4002bc5a1 100644 --- a/apps/app/src/app/(app)/[orgId]/tasks/[taskId]/automation/[automationId]/actions/generate-suggestions.ts +++ b/apps/app/src/app/(app)/[orgId]/tasks/[taskId]/automation/[automationId]/actions/generate-suggestions.ts @@ -14,8 +14,8 @@ const SuggestionsSchema = z.object({ z.object({ title: z.string(), prompt: z.string(), - vendorName: z.string().optional(), - vendorWebsite: z.string().optional(), + vendorName: z.string().nullable(), + vendorWebsite: z.string().nullable(), }), ), }); @@ -24,39 +24,39 @@ export async function generateAutomationSuggestions( taskDescription: string, organizationId: string, ): Promise<{ title: string; prompt: string; vendorName?: string; vendorWebsite?: string }[]> { - // Get vendors from the Vendor table - const vendors = await db.vendor.findMany({ - where: { - organizationId, - }, - select: { - name: true, - website: true, - description: true, - }, - }); - // Get vendors from context table as well - const contextEntries = await db.context.findMany({ - where: { - organizationId, - }, - select: { - question: true, - answer: true, - }, - }); - const vendorList = - vendors.length > 0 - ? vendors.map((v) => `${v.name}${v.website ? ` (${v.website})` : ''}`).join(', ') - : 'No vendors configured yet'; + try { + // Get vendors from the Vendor table + const vendors = await db.vendor.findMany({ + where: { + organizationId, + }, + select: { + name: true, + website: true, + description: true, + }, + }); + // Get vendors from context table as well + const contextEntries = await db.context.findMany({ + where: { + organizationId, + }, + select: { + question: true, + answer: true, + }, + }); + const vendorList = + vendors.length > 0 + ? vendors.map((v) => `${v.name}${v.website ? ` (${v.website})` : ''}`).join(', ') + : 'No vendors configured yet'; - const contextInfo = - contextEntries.length > 0 - ? contextEntries.map((c) => `Q: ${c.question}\nA: ${c.answer}`).join('\n\n') - : 'No additional context available'; + const contextInfo = + contextEntries.length > 0 + ? contextEntries.map((c) => `Q: ${c.question}\nA: ${c.answer}`).join('\n\n') + : 'No additional context available'; - // Generate AI suggestions - try { + // Generate AI suggestions const { object } = await generateObject({ model: groq('meta-llama/llama-4-scout-17b-16e-instruct'), schema: SuggestionsSchema, @@ -73,7 +73,12 @@ export async function generateAutomationSuggestions( } } - return suggestions; + return suggestions.map((s) => ({ + title: s.title, + prompt: s.prompt, + vendorName: s.vendorName ?? undefined, + vendorWebsite: s.vendorWebsite ?? undefined, + })); } catch (error) { console.error('[generateAutomationSuggestions] Error generating suggestions:', error); // Try to extract suggestions from error if available @@ -87,7 +92,12 @@ export async function generateAutomationSuggestions( ? parsed.suggestions : [parsed.suggestions]; if (suggestions.length > 0 && suggestions[0].title) { - return suggestions; + return suggestions.map((s: Record) => ({ + title: String(s.title), + prompt: String(s.prompt), + vendorName: (s.vendorName as string) ?? undefined, + vendorWebsite: (s.vendorWebsite as string) ?? undefined, + })); } } } diff --git a/apps/app/src/app/(app)/[orgId]/tasks/[taskId]/automation/[automationId]/components/AutomationPageClient.tsx b/apps/app/src/app/(app)/[orgId]/tasks/[taskId]/automation/[automationId]/components/AutomationPageClient.tsx index 5489188f6..2b792e41d 100644 --- a/apps/app/src/app/(app)/[orgId]/tasks/[taskId]/automation/[automationId]/components/AutomationPageClient.tsx +++ b/apps/app/src/app/(app)/[orgId]/tasks/[taskId]/automation/[automationId]/components/AutomationPageClient.tsx @@ -57,7 +57,6 @@ export function AutomationPageClient({ .catch((error) => { console.error('Failed to generate suggestions:', error); setIsLoadingSuggestions(false); - // Keep empty array, will use static suggestions }); } else { // Not a new automation, no need to load suggestions