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 @@ -3,7 +3,7 @@
import { useState } from "react";
import { useAction } from "next-safe-action/hooks";
import { BrainIcon } from "lucide-react";
import { ViewGroup } from "@/app/(app)/[emailAccountId]/assistant/group/ViewGroup";
import { ViewLearnedPatterns } from "@/app/(app)/[emailAccountId]/assistant/group/ViewLearnedPatterns";
import {
Dialog,
DialogContent,
Expand Down Expand Up @@ -83,7 +83,9 @@ export function LearnedPatternsDialog({
{isExecuting ? (
<Skeleton className="h-40 w-full" />
) : (
learnedPatternGroupId && <ViewGroup groupId={learnedPatternGroupId} />
learnedPatternGroupId && (
<ViewLearnedPatterns groupId={learnedPatternGroupId} />
)
)}
</DialogContent>
</Dialog>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ import { prefixPath } from "@/utils/path";
import { Toggle } from "@/components/Toggle";
import { ErrorBoundary } from "@/components/ErrorBoundary";

export function ViewGroup({ groupId }: { groupId: string }) {
export function ViewLearnedPatterns({ groupId }: { groupId: string }) {
return (
<ErrorBoundary extra={{ component: "ViewGroup", groupId }}>
<ErrorBoundary extra={{ component: "ViewLearnedPatterns", groupId }}>
<ViewGroupInner groupId={groupId} />
</ErrorBoundary>
);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"use client";

import useSWR from "swr";
import { Button } from "@/components/ui/button";
import { SettingCard } from "@/components/SettingCard";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { TypographyP } from "@/components/Typography";
import { ViewLearnedPatterns } from "@/app/(app)/[emailAccountId]/assistant/group/ViewLearnedPatterns";
import type { GroupsResponse } from "@/app/api/user/group/route";
import { LoadingContent } from "@/components/LoadingContent";

export function LearnedPatternsSetting() {
return (
<SettingCard
title="Learned Patterns"
description="View the patterns the assistant has learned from your email history."
right={
<Dialog>
<DialogTrigger asChild>
<Button variant="outline" size="sm">
View
</Button>
</DialogTrigger>
<DialogContent className="max-w-4xl">
<DialogHeader>
<DialogTitle>Learned Patterns</DialogTitle>
<DialogDescription>
When the AI processes your emails, it learns which senders or
email types consistently match the same rules. For example, it
might learn that emails from newsletter@example.com always match
your "Newsletter" rule. These learned patterns help the AI make
faster, more accurate decisions over time. You can view, edit,
or remove patterns that have been learned.
</DialogDescription>
</DialogHeader>
<Content />
</DialogContent>
</Dialog>
}
/>
);
}

function Content() {
const { data, isLoading, error } = useSWR<GroupsResponse>("/api/user/group");

return (
<LoadingContent loading={isLoading} error={error}>
{data?.groups.length === 0 ? (
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Sep 11, 2025

Choose a reason for hiding this comment

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

Possible runtime error by reading .length on undefined; guard groups with optional chaining before accessing length.

Prompt for AI agents
Address the following comment on apps/web/app/(app)/[emailAccountId]/assistant/settings/LearnedPatternsSetting.tsx at line 57:

<comment>Possible runtime error by reading .length on undefined; guard groups with optional chaining before accessing length.</comment>

<file context>
@@ -0,0 +1,79 @@
+
+  return (
+    &lt;LoadingContent loading={isLoading} error={error}&gt;
+      {data?.groups.length === 0 ? (
+        &lt;Card&gt;
+          &lt;CardContent className=&quot;flex items-center justify-center p-6&quot;&gt;
</file context>
Fix with Cubic

<Card>
<CardContent className="flex items-center justify-center p-6">
<TypographyP>No learned patterns found yet.</TypographyP>
</CardContent>
</Card>
) : (
<div className="grid gap-4">
{data?.groups.map((group) => (
<Card key={group.id}>
<CardHeader>
<CardTitle>{group.rule?.name || "No rule"}</CardTitle>
</CardHeader>
<CardContent>
<ViewLearnedPatterns groupId={group.id} />
</CardContent>
</Card>
))}
</div>
)}
Comment on lines +57 to +76
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix potential runtime crash when data is undefined.

data?.groups.length and data?.groups.map can throw; guard with a local groups.

Apply:

 function Content() {
   const { data, isLoading, error } = useSWR<GroupsResponse>("/api/user/group");
 
   return (
     <LoadingContent loading={isLoading} error={error}>
-      {data?.groups.length === 0 ? (
+      { (data?.groups ?? []).length === 0 ? (
         <Card>
           <CardContent className="flex items-center justify-center p-6">
             <TypographyP>No learned patterns found yet.</TypographyP>
           </CardContent>
         </Card>
       ) : (
         <div className="grid gap-4">
-          {data?.groups.map((group) => (
+          {(data?.groups ?? []).map((group) => (
             <Card key={group.id}>
               <CardHeader>
                 <CardTitle>{group.rule?.name || "No rule"}</CardTitle>
               </CardHeader>
               <CardContent>
                 <ViewLearnedPatterns groupId={group.id} />
               </CardContent>
             </Card>
           ))}
         </div>
       )}
     </LoadingContent>
   );
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{data?.groups.length === 0 ? (
<Card>
<CardContent className="flex items-center justify-center p-6">
<TypographyP>No learned patterns found yet.</TypographyP>
</CardContent>
</Card>
) : (
<div className="grid gap-4">
{data?.groups.map((group) => (
<Card key={group.id}>
<CardHeader>
<CardTitle>{group.rule?.name || "No rule"}</CardTitle>
</CardHeader>
<CardContent>
<ViewLearnedPatterns groupId={group.id} />
</CardContent>
</Card>
))}
</div>
)}
function Content() {
const { data, isLoading, error } = useSWR<GroupsResponse>("/api/user/group");
return (
<LoadingContent loading={isLoading} error={error}>
{(data?.groups ?? []).length === 0 ? (
<Card>
<CardContent className="flex items-center justify-center p-6">
<TypographyP>No learned patterns found yet.</TypographyP>
</CardContent>
</Card>
) : (
<div className="grid gap-4">
{(data?.groups ?? []).map((group) => (
<Card key={group.id}>
<CardHeader>
<CardTitle>{group.rule?.name || "No rule"}</CardTitle>
</CardHeader>
<CardContent>
<ViewLearnedPatterns groupId={group.id} />
</CardContent>
</Card>
))}
</div>
)}
</LoadingContent>
);
}
🤖 Prompt for AI Agents
In
apps/web/app/(app)/[emailAccountId]/assistant/settings/LearnedPatternsSetting.tsx
around lines 57 to 76, the code accesses data?.groups.length and
data?.groups.map which can throw if data or groups is undefined; define a local
const groups = data?.groups ?? [] and use groups.length and groups.map
throughout the JSX so you always operate on a safe array; update the conditional
and mapping to reference this local groups variable.

</LoadingContent>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DraftReplies } from "@/app/(app)/[emailAccountId]/assistant/settings/Dr
import { DraftKnowledgeSetting } from "@/app/(app)/[emailAccountId]/assistant/settings/DraftKnowledgeSetting";
import { AwaitingReplySetting } from "@/app/(app)/[emailAccountId]/assistant/settings/AwaitingReplySetting";
import { ReferralSignatureSetting } from "@/app/(app)/[emailAccountId]/assistant/settings/ReferralSignatureSetting";
import { LearnedPatternsSetting } from "@/app/(app)/[emailAccountId]/assistant/settings/LearnedPatternsSetting";

export function SettingsTab() {
return (
Expand All @@ -14,6 +15,7 @@ export function SettingsTab() {
<AboutSetting />
<DigestSetting />
<ReferralSignatureSetting />
<LearnedPatternsSetting />
</div>
);
}
41 changes: 0 additions & 41 deletions apps/web/app/(app)/[emailAccountId]/debug/learned/page.tsx

This file was deleted.

5 changes: 0 additions & 5 deletions apps/web/app/(app)/[emailAccountId]/debug/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ export default async function DebugPage(props: {
<PageHeading>Debug</PageHeading>

<div className="mt-4 flex gap-2">
<Button variant="outline" asChild>
<Link href={prefixPath(emailAccountId, "/debug/learned")}>
Learned Patterns
</Link>
</Button>
<Button variant="outline" asChild>
<Link href={prefixPath(emailAccountId, "/debug/drafts")}>Drafts</Link>
</Button>
Expand Down
Loading