Skip to content

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.

feat: render cover letter streaming and results in the chat

Khuram Niaze19c90387c65
diff --git a/__tests__/AgentChatMessages.spec.tsx b/__tests__/AgentChatMessages.spec.tsx
index aae842c..8805d25 100644
--- a/__tests__/AgentChatMessages.spec.tsx
+++ b/__tests__/AgentChatMessages.spec.tsx
@@ -322,4 +322,27 @@ describe("AgentChatMessages", () => {
expect(screen.getByText(/Streaming\./i)).toBeInTheDocument();
expect(screen.queryByText(/SCORES:/)).not.toBeInTheDocument();
});
+
+ it("renders a running generate_cover_letter from its streamed text", () => {
+ chat.toolStreams = {
+ c1: "<think>planning</think>Dear Hiring Manager,\n\nI am writing.",
+ };
+ chat.messages = [
+ {
+ id: "a1",
+ role: "assistant",
+ parts: [
+ {
+ type: "tool-generate_cover_letter",
+ toolCallId: "c1",
+ state: "input-available",
+ input: {},
+ },
+ ],
+ },
+ ] as any;
+ render(<AgentChatMessages />);
+ expect(screen.getByText(/Dear Hiring Manager/i)).toBeInTheDocument();
+ expect(screen.queryByText(/planning/)).not.toBeInTheDocument();
+ });
});
diff --git a/__tests__/AgentResultCard.spec.tsx b/__tests__/AgentResultCard.spec.tsx
index 89f8fe8..365b40e 100644
--- a/__tests__/AgentResultCard.spec.tsx
+++ b/__tests__/AgentResultCard.spec.tsx
@@ -303,4 +303,68 @@ describe("AgentResultCard", () => {
);
expect(screen.getByText(/Database is locked/i)).toBeInTheDocument();
});
+
+ it("renders the letter and where it was saved", () => {
+ render(
+ <AgentResultCard
+ part={outputPart("generate_cover_letter", {
+ status: "ok",
+ jobId: "job-1",
+ jobTitle: "Senior Backend Engineer",
+ company: "Northwind Cloud",
+ resumeId: "r9",
+ resumeTitle: "Senior Engineer Resume",
+ body: "Dear Hiring Manager,\n\nI am writing to apply.",
+ coverLetterId: "cl-1",
+ coverLetterTitle: "Senior Backend Engineer - Northwind Cloud",
+ saved: true,
+ })}
+ />,
+ );
+ expect(screen.getByText(/Dear Hiring Manager/i)).toBeInTheDocument();
+ expect(
+ screen.getByText(/Senior Backend Engineer - Northwind Cloud/i),
+ ).toBeInTheDocument();
+ });
+
+ it("tells the user to open a job when a letter has none in context", () => {
+ render(
+ <AgentResultCard
+ part={outputPart("generate_cover_letter", { status: "no_job" })}
+ />,
+ );
+ expect(screen.getByText(/open the job/i)).toBeInTheDocument();
+ });
+
+ it("explains a title-only job instead of failing silently", () => {
+ render(
+ <AgentResultCard
+ part={outputPart("generate_cover_letter", {
+ status: "no_description",
+ jobTitle: "Senior Backend Engineer",
+ })}
+ />,
+ );
+ expect(screen.getByText(/description/i)).toBeInTheDocument();
+ });
+
+ it("still shows the letter when the save failed", () => {
+ render(
+ <AgentResultCard
+ part={outputPart("generate_cover_letter", {
+ status: "ok",
+ jobId: "job-1",
+ jobTitle: "Senior Backend Engineer",
+ company: "Northwind Cloud",
+ resumeId: "r9",
+ resumeTitle: "Senior Engineer Resume",
+ body: "Dear Hiring Manager,",
+ saved: false,
+ saveError: "Database is locked.",
+ })}
+ />,
+ );
+ expect(screen.getByText(/Dear Hiring Manager/i)).toBeInTheDocument();
+ expect(screen.getByText(/Database is locked/i)).toBeInTheDocument();
+ });
});
diff --git a/src/components/agent/AgentChatEmptyState.tsx b/src/components/agent/AgentChatEmptyState.tsx
index d73e357..fd3e876 100644
--- a/src/components/agent/AgentChatEmptyState.tsx
+++ b/src/components/agent/AgentChatEmptyState.tsx
@@ -23,9 +23,9 @@ export function AgentChatEmptyState() {
<p className="text-sm text-muted-foreground">
I can add a job to your tracker — paste a posting or type the details,
and I&apos;ll show you what I extracted before anything is saved. I can
- also read and review your resumes, and score how well one of them
- matches a job while you&apos;re looking at it. I can&apos;t search your
- existing jobs or read your tasks yet.
+ also read and review your resumes, and while you&apos;re looking at a
+ job I can score how well one of them matches it or write you a cover
+ letter. I can&apos;t search your existing jobs or read your tasks yet.
</p>
<Suggestions>
diff --git a/src/components/agent/AgentChatMessages.tsx b/src/components/agent/AgentChatMessages.tsx
index 5625491..f17ad55 100644
--- a/src/components/agent/AgentChatMessages.tsx
+++ b/src/components/agent/AgentChatMessages.tsx
@@ -20,8 +20,13 @@ import { useAgentChat } from "@/components/agent/AgentChatProvider";
import { resolvePastedText } from "@/lib/agent/paste";
import { parseJobMatch } from "@/lib/ai/jobMatch/parse";
import { parseResumeReview } from "@/lib/ai/resumeReview/parse";
+import { stripThinking } from "@/lib/ai/stripThinking";
import { cn } from "@/lib/utils";
-import { isAgentPastePart, type AgentPastePartData } from "@/models/agent.model";
+import {
+ isAgentPastePart,
+ isNestedTool,
+ type AgentPastePartData,
+} from "@/models/agent.model";
function PasteChip({ data }: { data: AgentPastePartData }) {
const chars = data.chars.toLocaleString();
@@ -128,9 +133,7 @@ export function AgentChatMessages() {
case "input-streaming":
case "input-available": {
const tool = getToolName(part);
- const nested =
- tool === "review_resume" || tool === "match_job";
- const streamed = nested
+ const streamed = isNestedTool(tool)
? toolStreams[part.toolCallId]
: undefined;
if (!streamed) return <AgentToolRunningCard key={i} part={part} />;
@@ -144,6 +147,11 @@ export function AgentChatMessages() {
/>
);
}
+ // A letter has no scores line, so stripping reasoning is the
+ // whole of its parse.
+ if (tool === "generate_cover_letter") {
+ return <AgentMarkdown key={i} text={stripThinking(streamed)} />;
+ }
const parsed = parseResumeReview(streamed);
return (
<AgentReviewContent
diff --git a/src/components/agent/AgentChatProvider.tsx b/src/components/agent/AgentChatProvider.tsx
index b356e96..c729be7 100644
--- a/src/components/agent/AgentChatProvider.tsx
+++ b/src/components/agent/AgentChatProvider.tsx
@@ -30,6 +30,7 @@ import { checkOllamaConnection } from "@/utils/ai.utils";
import { AiProvider } from "@/models/ai.model";
import {
AGENT_NESTED_STREAM_PART_TYPE,
+ isNestedTool,
type AgentAddJobResult,
type AgentNestedStreamData,
type PageContext,
@@ -144,11 +145,11 @@ function useAgentChatValue(initialMessages: UIMessage[]) {
return (part.output as AgentAddJobResult | undefined)?.created === true;
});
// Any nested tool that saves server-side leaves the page behind the
- // panel stale — the saved review card, or the job's match score.
+ // panel stale — the saved review card, the job's match score, or the
+ // job's cover-letter button flipping to "Regenerate Letter".
const generated = finishedParts.some((part) => {
if (!isToolUIPart(part) || part.state !== "output-available") return false;
- const tool = getToolName(part);
- return tool === "review_resume" || tool === "match_job";
+ return isNestedTool(getToolName(part));
});
// The route stubs the paste on its way into the DB, but that copy is
diff --git a/src/components/agent/AgentResultCard.tsx b/src/components/agent/AgentResultCard.tsx
index bf01e36..8c28877 100644
--- a/src/components/agent/AgentResultCard.tsx
+++ b/src/components/agent/AgentResultCard.tsx
@@ -4,10 +4,12 @@ import Link from "next/link";
import { getToolName, type ToolUIPart } from "ai";
import { Badge } from "@/components/ui/badge";
import { AgentResumePicker } from "@/components/agent/AgentResumePicker";
+import { AgentMarkdown } from "@/components/agent/AgentMarkdown";
import { AgentMatchContent } from "@/components/agent/AgentMatchContent";
import { AgentReviewContent } from "@/components/agent/AgentReviewContent";
import type {
AgentAddJobResult,
+ AgentCoverLetterResult,
AgentGetResumeResult,
AgentMatchJobResult,
AgentReviewResumeResult,
@@ -245,6 +247,90 @@ function MatchJobResult({ output }: { output: AgentMatchJobResult }) {
);
}
+// The letter comes from the tool output, not from the streamed text: the
+// stream is a progress indicator and the output is what was saved.
+function CoverLetterResult({ output }: { output: AgentCoverLetterResult }) {
+ if (output.status === "no_job") {
+ return (
+ <p className="text-sm">
+ Open the job you want a letter for first — I write for the job
+ you&apos;re looking at.
+ </p>
+ );
+ }
+
+ if (output.status === "no_description") {
+ return (
+ <p className="text-sm">
+ <strong>{output.jobTitle}</strong> has no real description yet. Add the
+ posting and I can write a letter from it.
+ </p>
+ );
+ }
+
+ if (output.status === "no_resumes") {
+ return (
+ <p className="text-sm">
+ You don&apos;t have any resumes yet — create one on the Profile page.
+ </p>
+ );
+ }
+
+ if (output.status === "needs_selection") {
+ return (
+ <div className="text-sm">
+ <p>Which resume should the letter draw on?</p>
+ <AgentResumePicker
+ resumes={output.resumes}
+ messageFor={(title) =>
+ `Write a cover letter for this job using my resume "${title}"`
+ }
+ />
+ </div>
+ );
+ }
+
+ if (output.status === "unreadable") {
+ return (
+ <p className="text-sm">
+ Couldn&apos;t read <strong>{output.title}</strong> — {output.reason}
+ </p>
+ );
+ }
+
+ if (output.status === "generation_failed") {
+ return (
+ <p className="text-sm">
+ Couldn&apos;t write a letter for <strong>{output.jobTitle}</strong> —{" "}
+ {output.reason}
+ </p>
+ );
+ }
+
+ return (
+ <div className="text-sm">
+ <AgentMarkdown text={output.body} />
+ <p className="mt-2 text-xs text-muted-foreground">
+ {output.jobTitle}
+ {output.company ? ` at ${output.company}` : ""} · drawn from{" "}
+ {output.resumeTitle}
+ </p>
+ {output.saved ? (
+ <p className="mt-1 text-xs text-muted-foreground">
+ Saved as “{output.coverLetterTitle}” —{" "}
+ <Link href="/dashboard/profile" className="underline">
+ edit it in Profile → Documents
+ </Link>
+ </p>
+ ) : (
+ <p className="mt-1 text-xs text-muted-foreground">
+ Letter not saved — {output.saveError}
+ </p>
+ )}
+ </div>
+ );
+}
+
export function AgentResultCard({ part }: { part: ToolUIPart }) {
if (part.state === "output-denied") {
return (
@@ -277,6 +363,8 @@ export function AgentResultCard({ part }: { part: ToolUIPart }) {
<ReviewResumeResult output={part.output as AgentReviewResumeResult} />
) : toolName === "match_job" ? (
<MatchJobResult output={part.output as AgentMatchJobResult} />
+ ) : toolName === "generate_cover_letter" ? (
+ <CoverLetterResult output={part.output as AgentCoverLetterResult} />
) : null;
return <div className="rounded-sm border p-3">{body}</div>;
diff --git a/src/components/agent/AgentToolRunningCard.tsx b/src/components/agent/AgentToolRunningCard.tsx
index 42a4da3..12403fc 100644
--- a/src/components/agent/AgentToolRunningCard.tsx
+++ b/src/components/agent/AgentToolRunningCard.tsx
@@ -16,7 +16,9 @@ export function AgentToolRunningCard({ part }: { part: ToolUIPart }) {
? "Reviewing your resume…"
: toolName === "match_job"
? "Matching your resume to this job…"
- : "Working…";
+ : toolName === "generate_cover_letter"
+ ? "Writing your cover letter…"
+ : "Working…";
return <AgentStatusRow label={label} />;
}