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 @@ -11,14 +11,18 @@ import {
AWAITING_REPLY_LABEL_NAME,
NEEDS_REPLY_LABEL_NAME,
} from "@/utils/reply-tracker/consts";
import { getEmailTerminology } from "@/utils/terminology";

export function ActionSummaryCard({
action,
typeOptions,
provider,
}: {
action: CreateRuleBody["actions"][number];
typeOptions: { label: string; value: ActionType }[];
provider: string;
}) {
const terminology = getEmailTerminology(provider);
const actionTypeLabel =
typeOptions.find((opt) => opt.value === action.type)?.label || action.type;

Expand All @@ -29,9 +33,11 @@ export function ActionSummaryCard({
case ActionType.LABEL: {
const labelValue = action.label?.value || "";
if (action.label?.ai) {
summaryContent = labelValue ? `AI Label: ${labelValue}` : "AI Label";
summaryContent = labelValue
? `AI ${terminology.label.action}: ${labelValue}`
: `AI ${terminology.label.action}`;
} else {
summaryContent = `Label as "${labelValue || "unset"}"`;
summaryContent = `${terminology.label.action} as "${labelValue || "unset"}"`;
}
break;
}
Expand Down Expand Up @@ -170,8 +176,8 @@ export function ActionSummaryCard({
break;

case ActionType.TRACK_THREAD:
summaryContent = "Auto-update reply label";
tooltipText = `Our AI will automatically update the thread label to '${NEEDS_REPLY_LABEL_NAME}' or '${AWAITING_REPLY_LABEL_NAME}' based on whether you need to respond or are awaiting a response from the recipient.`;
summaryContent = `Auto-update reply ${terminology.label.singular}`;
tooltipText = `Our AI will automatically update the thread ${terminology.label.singular} to '${NEEDS_REPLY_LABEL_NAME}' or '${AWAITING_REPLY_LABEL_NAME}' based on whether you need to respond or are awaiting a response from the recipient.`;
break;

case ActionType.ARCHIVE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,15 @@ export function RuleCell({

export function ActionItemsCell({
actionItems,
provider,
}: {
actionItems: PendingExecutedRules["executedRules"][number]["actionItems"];
provider: string;
}) {
return (
<div className="mt-2 flex flex-wrap gap-1">
{actionItems.map((item) => (
<ActionBadgeExpanded key={item.id} action={item} />
<ActionBadgeExpanded key={item.id} action={item} provider={provider} />
))}
</div>
);
Expand Down
7 changes: 5 additions & 2 deletions apps/web/app/(app)/[emailAccountId]/assistant/Pending.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function PendingTable({
totalPages: number;
mutate: () => void;
}) {
const { emailAccountId, userEmail } = useAccount();
const { emailAccountId, userEmail, provider } = useAccount();
const { selected, isAllSelected, onToggleSelect, onToggleSelectAll } =
useToggleSelect(pending);

Expand Down Expand Up @@ -191,7 +191,10 @@ function PendingTable({
/>
</TableCell>
<TableCell>
<ActionItemsCell actionItems={p.actionItems} />
<ActionItemsCell
actionItems={p.actionItems}
provider={provider}
/>
</TableCell>
<TableCell>
<ExecuteButtons id={p.id} message={p.message} mutate={mutate} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
import { ButtonList } from "@/components/ButtonList";
import { personas } from "@/app/(app)/[emailAccountId]/assistant/examples";
import type { Personas } from "./examples";

export function PersonaDialog({
isOpen,
setIsOpen,
onSelect,
personas,
}: {
isOpen: boolean;
setIsOpen: (open: boolean) => void;
onSelect: (persona: string) => void;
personas: Personas;
}) {
return (
<Dialog open={isOpen} onOpenChange={setIsOpen}>
Expand Down
14 changes: 10 additions & 4 deletions apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { useAccount } from "@/providers/EmailAccountProvider";
import { prefixPath } from "@/utils/path";
import { useRule } from "@/hooks/useRule";
import { isMicrosoftProvider } from "@/utils/email/provider-types";
import { getEmailTerminology } from "@/utils/terminology";
import {
Dialog,
DialogContent,
Expand Down Expand Up @@ -324,11 +325,12 @@ export function RuleForm({
}, [errors, watch]);

const conditionalOperator = watch("conditionalOperator");
const terminology = getEmailTerminology(provider);

const typeOptions = useMemo(() => {
const options: { label: string; value: ActionType }[] = [
{ label: "Archive", value: ActionType.ARCHIVE },
{ label: "Label", value: ActionType.LABEL },
{ label: terminology.label.action, value: ActionType.LABEL },
...(isMicrosoftProvider(provider)
? [{ label: "Move to folder", value: ActionType.MOVE_FOLDER }]
: []),
Expand All @@ -340,11 +342,14 @@ export function RuleForm({
{ label: "Mark spam", value: ActionType.MARK_SPAM },
{ label: "Digest", value: ActionType.DIGEST },
{ label: "Call webhook", value: ActionType.CALL_WEBHOOK },
{ label: "Auto-update reply label", value: ActionType.TRACK_THREAD },
{
label: `Auto-update reply ${terminology.label.singular}`,
value: ActionType.TRACK_THREAD,
},
];

return options;
}, [provider]);
}, [provider, terminology.label.action, terminology.label.singular]);

const [isNameEditMode, setIsNameEditMode] = useState(alwaysEditMode);
const [isConditionsEditMode, setIsConditionsEditMode] =
Expand Down Expand Up @@ -849,6 +854,7 @@ export function RuleForm({
key={i}
action={action}
typeOptions={typeOptions}
provider={provider}
/>
),
)}
Expand All @@ -870,7 +876,7 @@ export function RuleForm({
</div>
)}

<div className="flex items-center justify-end space-x-2">
<div className="flex items-center justify-end space-x-2 mt-4">
<TooltipExplanation
size="md"
side="left"
Expand Down
11 changes: 8 additions & 3 deletions apps/web/app/(app)/[emailAccountId]/assistant/Rules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function Rules({ size = "md" }: { size?: "sm" | "md" }) {

const onCreateRule = () => ruleDialog.open();

const { emailAccountId } = useAccount();
const { emailAccountId, provider } = useAccount();
const { createAssistantUrl } = useAssistantNavigation(emailAccountId);
const { executeAsync: setRuleEnabled } = useAction(
setRuleEnabledAction.bind(null, emailAccountId),
Expand Down Expand Up @@ -275,7 +275,10 @@ export function Rules({ size = "md" }: { size?: "sm" | "md" }) {
</TableCell>
)}
<TableCell>
<ActionBadges actions={rule.actions} />
<ActionBadges
actions={rule.actions}
provider={provider}
/>
</TableCell>
{/* {size === "md" && (
<TableCell>
Expand Down Expand Up @@ -465,13 +468,15 @@ export function Rules({ size = "md" }: { size?: "sm" | "md" }) {

export function ActionBadges({
actions,
provider,
}: {
actions: {
id: string;
type: ActionType;
label?: string | null;
folderName?: string | null;
}[];
provider: string;
}) {
return (
<div className="flex gap-2">
Expand All @@ -485,7 +490,7 @@ export function ActionBadges({
color={getActionColor(action.type)}
className="w-fit text-nowrap"
>
{getActionDisplay(action)}
{getActionDisplay(action, provider)}
</Badge>
);
})}
Expand Down
31 changes: 26 additions & 5 deletions apps/web/app/(app)/[emailAccountId]/assistant/RulesPrompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import { LoadingContent } from "@/components/LoadingContent";
import { Tooltip } from "@/components/Tooltip";
import { AssistantOnboarding } from "@/app/(app)/[emailAccountId]/assistant/AssistantOnboarding";
import {
examplePrompts,
personas,
getExamplePrompts,
getPersonas,
type Personas,
} from "@/app/(app)/[emailAccountId]/assistant/examples";
import { convertLabelsToDisplay } from "@/utils/mention";
import { PersonaDialog } from "@/app/(app)/[emailAccountId]/assistant/PersonaDialog";
Expand All @@ -39,7 +40,7 @@ import { Skeleton } from "@/components/ui/skeleton";
import { useLabels } from "@/hooks/useLabels";

export function RulesPrompt() {
const { emailAccountId } = useAccount();
const { emailAccountId, provider } = useAccount();
const { data, isLoading, error, mutate } = useSWR<
RulesPromptResponse,
{ error: string }
Expand All @@ -51,6 +52,8 @@ export function RulesPrompt() {
);

const [persona, setPersona] = useState<string | null>(null);
const personas = getPersonas(provider);
const examplePrompts = getExamplePrompts(provider);

const personaPrompt = persona
? personas[persona as keyof typeof personas]?.prompt
Expand All @@ -72,6 +75,8 @@ export function RulesPrompt() {
mutate={mutate}
onOpenPersonaDialog={onOpenPersonaDialog}
showExamples
personas={personas}
examplePrompts={examplePrompts}
/>
<AssistantOnboarding
onComplete={() => {
Expand All @@ -85,6 +90,7 @@ export function RulesPrompt() {
isOpen={isModalOpen}
setIsOpen={setIsModalOpen}
onSelect={setPersona}
personas={personas}
/>
</>
);
Expand All @@ -97,13 +103,17 @@ function RulesPromptForm({
mutate,
onOpenPersonaDialog,
showExamples,
personas,
examplePrompts,
}: {
emailAccountId: string;
rulesPrompt: string | null;
personaPrompt?: string;
mutate: () => void;
onOpenPersonaDialog: () => void;
showExamples?: boolean;
personas: Personas;
examplePrompts: string[];
}) {
const { userLabels, isLoading: isLoadingLabels } = useLabels();

Expand Down Expand Up @@ -345,13 +355,24 @@ function RulesPromptForm({
</div>
</form>

{showExamples && <Examples onSelect={addExamplePrompt} />}
{showExamples && (
<Examples
onSelect={addExamplePrompt}
examplePrompts={examplePrompts}
/>
)}
</div>
</div>
);
}

function PureExamples({ onSelect }: { onSelect: (example: string) => void }) {
function PureExamples({
onSelect,
examplePrompts,
}: {
onSelect: (example: string) => void;
examplePrompts: string[];
}) {
return (
<div>
<SectionHeader className="text-xl">Examples</SectionHeader>
Expand Down
Loading
Loading