Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
elie222 committed Jan 24, 2025
1 parent b1e810f commit f101c60
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions apps/web/utils/actions/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { flattenConditions } from "@/utils/condition";
import { LogicalOperator } from "@prisma/client";
import { createPromptFromRule } from "@/utils/ai/rule/create-prompt-from-rule";
import {
updatePromptFileOnUpdate,
updateUserPrompt,
updateRulePromptOnRuleChange,
appendRulePrompt,
} from "@/utils/rule/prompt-file";
import { generatePromptOnDeleteRule } from "@/utils/ai/rule/generate-prompt-on-delete-rule";

Expand Down Expand Up @@ -86,7 +86,7 @@ export const createRuleAction = withActionInstrumentation(

const prompt = createPromptFromRule(rule);

await updateUserPrompt(session.user.id, prompt);
await appendRulePrompt(session.user.id, prompt);

revalidatePath("/automation");

Expand Down Expand Up @@ -203,7 +203,11 @@ export const updateRuleAction = withActionInstrumentation(
]);

// update prompt file
await updatePromptFileOnUpdate(session.user.id, currentRule, updatedRule);
await updateRulePromptOnRuleChange(
session.user.id,
currentRule,
updatedRule,
);

revalidatePath(`/automation/rule/${body.id}`);
revalidatePath("/automation");
Expand Down Expand Up @@ -245,7 +249,11 @@ export const updateRuleInstructionsAction = withActionInstrumentation(
});

// update prompt file
await updatePromptFileOnUpdate(session.user.id, currentRule, updatedRule);
await updateRulePromptOnRuleChange(
session.user.id,
currentRule,
updatedRule,
);

revalidatePath(`/automation/rule/${body.id}`);
revalidatePath("/automation");
Expand Down
4 changes: 2 additions & 2 deletions apps/web/utils/rule/prompt-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { RuleWithRelations } from "@/utils/ai/rule/create-prompt-from-rule"
import { generatePromptOnUpdateRule } from "@/utils/ai/rule/generate-prompt-on-update-rule";
import prisma from "@/utils/prisma";

export async function updatePromptFileOnUpdate(
export async function updateRulePromptOnRuleChange(
userId: string,
currentRule: RuleWithRelations,
updatedRule: RuleWithRelations,
Expand Down Expand Up @@ -32,7 +32,7 @@ export async function updatePromptFileOnUpdate(
});
}

export async function updateUserPrompt(userId: string, rulePrompt: string) {
export async function appendRulePrompt(userId: string, rulePrompt: string) {
const user = await prisma.user.findUnique({
where: { id: userId },
select: { rulesPrompt: true },
Expand Down

1 comment on commit f101c60

@vercel
Copy link

@vercel vercel bot commented on f101c60 Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.