Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
feat: drive cover letter generation from the agent chat on the job page
Khuram Niaz53c9080eaee8
diff --git a/__tests__/JobDetails.spec.tsx b/__tests__/JobDetails.spec.tsxindex f2464cb..2df4cf5 100644--- a/__tests__/JobDetails.spec.tsx+++ b/__tests__/JobDetails.spec.tsx@@ -1,7 +1,7 @@import React from "react";import JobDetails from "@/components/myjobs/JobDetails";import { JobResponse, Tag } from "@/models/job.model";-import { render, screen, act } from "@testing-library/react";+import { render, screen, act, waitFor } from "@testing-library/react";import userEvent from "@testing-library/user-event";vi.mock("next/navigation", () => ({@@ -21,11 +21,6 @@ vi.mock("@/components/agent/AgentChatProvider", () => ({useAgentChat: () => chat,}));-vi.mock("@/components/myjobs/GenerateCoverLetterSection", () => ({- GenerateCoverLetterSection: ({ open }: { open: boolean }) =>- open ? <div data-testid="cover-letter-sheet" /> : null,-}));-vi.mock("@/components/myjobs/NotesSection", () => ({NotesSection: () => null,}));@@ -235,6 +230,11 @@ describe("JobDetails – Match with AI", () => {});describe("JobDetails cover letter action", () => {+ beforeEach(() => {+ chat.approvalPending = false;+ vi.clearAllMocks();+ });+it("stays enabled when no resume is linked", () => {render(<JobDetails {...baseProps} job={makeJob({ resumeId: undefined })} />);expect(screen.getByTestId("generate-cover-letter-btn")).toBeEnabled();@@ -260,14 +260,33 @@ describe("JobDetails cover letter action", () => {expect(screen.getByTestId("generate-cover-letter-btn")).toBeEnabled();});- it("opens the sheet on click", async () => {+ it("opens the chat and asks for a letter naming the job", async () => {render(<JobDetails {...baseProps} job={makeJob({ resumeId: "resume-1" })} />,);await userEvent.click(screen.getByTestId("generate-cover-letter-btn"));- expect(screen.getByTestId("cover-letter-sheet")).toBeInTheDocument();+ expect(chat.open).toHaveBeenCalled();+ await waitFor(() => expect(chat.sendMessage).toHaveBeenCalled());+ const sent = chat.sendMessage.mock.calls[0][0];+ expect(sent.parts[0].text).toMatch(/cover letter/i);+ expect(sent.parts[0].text).toContain("Frontend Developer");+ expect(sent.parts[0].text).toContain("Acme Corp");+ });++ it("asks before clearing a conversation with a pending approval", async () => {+ chat.approvalPending = true;+ render(+ <JobDetails {...baseProps} job={makeJob({ resumeId: "resume-1" })} />,+ );+ await userEvent.click(screen.getByTestId("generate-cover-letter-btn"));+ expect(+ screen.getByText(/clear the assistant conversation/i),+ ).toBeInTheDocument();+ expect(chat.sendMessage).not.toHaveBeenCalled();});+ // Derived from the server prop, not local state: the chat saves the letter+ // server-side and fires router.refresh().it("labels the action Regenerate when a letter is already linked", () => {render(<JobDetailsdiff --git a/src/components/myjobs/JobDetails.tsx b/src/components/myjobs/JobDetails.tsxindex 441d38a..13441cc 100644--- a/src/components/myjobs/JobDetails.tsx+++ b/src/components/myjobs/JobDetails.tsx@@ -46,9 +46,8 @@ import {AlertDialogHeader,AlertDialogTitle,} from "../ui/alert-dialog";-import { GenerateCoverLetterSection } from "./GenerateCoverLetterSection";import { NotesSection } from "./NotesSection";-import { useState, useMemo, useCallback } from "react";+import { useState, useMemo } from "react";import { DownloadFileButton } from "../profile/DownloadFileButton";import { MatchDetails } from "../automations/MatchDetails";import type { JobMatchData } from "@/models/ai.schemas";@@ -97,11 +96,8 @@ function JobDetails({approvalPending,} = useAgentChat();const [showClearChatConfirm, setShowClearChatConfirm] = useState(false);+ const [pendingChatMessage, setPendingChatMessage] = useState("");const [currentStatus, setCurrentStatus] = useState(job.Status);- const [coverLetterOpen, setCoverLetterOpen] = useState(false);- const [currentCoverLetterId, setCurrentCoverLetterId] = useState(- job.coverLetterId,- );const [editJobTarget, setEditJobTarget] = useState<JobResponse | null>(null,);@@ -121,30 +117,30 @@ function JobDetails({}}, [job.matchData]);- // Panel first so a failed clear can never leave the button looking dead,- // and the match is sent either way — a conversation that would not clear- // is no reason to withhold it.- const startMatch = async () => {+ const jobLabel = `${job.JobTitle?.label ?? "this job"}${+ job.Company?.label ? ` at ${job.Company.label}` : ""+ }`;++ // Panel first so a failed clear can never leave a button looking dead, and+ // the message is sent either way — a conversation that would not clear is no+ // reason to withhold it.+ const startChat = async (text: string) => {openChat();try {await clearChat();} catch {- // Reported by the action itself; the match still goes out.+ // Reported by the action itself; the message still goes out.}- const label = `${job.JobTitle?.label ?? "this job"}${- job.Company?.label ? ` at ${job.Company.label}` : ""- }`;- void sendMessage({- parts: [{ type: "text", text: `Match my resume to ${label}` }],- });+ void sendMessage({ parts: [{ type: "text", text }] });};- const onMatchClick = () => {+ const requestChat = (text: string) => {if (approvalPending) {+ setPendingChatMessage(text);setShowClearChatConfirm(true);return;}- void startMatch();+ void startChat(text);};const coverLetterBlockedReason =@@ -152,10 +148,6 @@ function JobDetails({? "Add a job description first": undefined;- const handleCoverLetterSaved = useCallback((coverLetterId: string) => {- setCurrentCoverLetterId(coverLetterId);- }, []);-const onEditJob = () => {setEditJobTarget({ ...job, Status: currentStatus });};@@ -210,7 +202,7 @@ function JobDetails({size="sm"variant="outline"className="h-8 gap-1 cursor-pointer"- onClick={onMatchClick}+ onClick={() => requestChat(`Match my resume to ${jobLabel}`)}><Sparkles className="h-3.5 w-3.5" /><span className="sr-only sm:not-sr-only sm:whitespace-nowrap">@@ -224,11 +216,11 @@ function JobDetails({data-testid="generate-cover-letter-btn"disabled={!!coverLetterBlockedReason}title={coverLetterBlockedReason}- onClick={() => setCoverLetterOpen(true)}+ onClick={() => requestChat(`Write a cover letter for ${jobLabel}`)}><FileText className="h-3.5 w-3.5" /><span className="sr-only sm:not-sr-only sm:whitespace-nowrap">- {currentCoverLetterId ? "Regenerate Letter" : "Cover Letter"}+ {job.coverLetterId ? "Regenerate Letter" : "Cover Letter"}</span></Button><DropdownMenu>@@ -405,13 +397,6 @@ function JobDetails({<CardFooter></CardFooter></Card>)}- <GenerateCoverLetterSection- jobId={job?.id}- jobResumeId={job.resumeId}- open={coverLetterOpen}- triggerChange={setCoverLetterOpen}- onSaved={handleCoverLetterSaved}- /><AddJobjobStatuses={jobStatuses}companies={companies}@@ -430,7 +415,7 @@ function JobDetails({onOpenChange={setDeleteAlertOpen}onDelete={onDeleteJob}/>- {/* CLEAR CHAT BEFORE MATCH CONFIRM */}+ {/* CLEAR CHAT BEFORE AN AI ACTION CONFIRM */}<AlertDialogopen={showClearChatConfirm}onOpenChange={setShowClearChatConfirm}@@ -439,14 +424,14 @@ function JobDetails({<AlertDialogHeader><AlertDialogTitle>Clear the assistant conversation?</AlertDialogTitle><AlertDialogDescription>- A job is waiting for your approval in the assistant. Starting a- match clears the conversation, and that job will not be saved.+ A job is waiting for your approval in the assistant. Starting this+ clears the conversation, and that job will not be saved.</AlertDialogDescription></AlertDialogHeader><AlertDialogFooter><AlertDialogCancel>Cancel</AlertDialogCancel>- <AlertDialogAction onClick={() => void startMatch()}>- Clear and match+ <AlertDialogAction onClick={() => void startChat(pendingChatMessage)}>+ Clear and continue</AlertDialogAction></AlertDialogFooter></AlertDialogContent>