Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}),
),
});
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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<string, unknown>) => ({
title: String(s.title),
prompt: String(s.prompt),
vendorName: (s.vendorName as string) ?? undefined,
vendorWebsite: (s.vendorWebsite as string) ?? undefined,
}));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading