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 match_job streaming, results and picker in the chat

Khuram Niaz1f3f6a5d2972
diff --git a/__tests__/AgentChatMessages.spec.tsx b/__tests__/AgentChatMessages.spec.tsx
index 170fe8b..aae842c 100644
--- a/__tests__/AgentChatMessages.spec.tsx
+++ b/__tests__/AgentChatMessages.spec.tsx
@@ -299,4 +299,27 @@ describe("AgentChatMessages", () => {
render(<AgentChatMessages />);
expect(screen.getByText(/reviewing your resume/i)).toBeInTheDocument();
});
+
+ it("renders a running match_job from its streamed text", () => {
+ chat.toolStreams = {
+ m1: "SCORES: match=72 recommendation=good\n\n## Summary\n\nStreaming.",
+ };
+ chat.messages = [
+ {
+ id: "a1",
+ role: "assistant",
+ parts: [
+ {
+ type: "tool-match_job",
+ toolCallId: "m1",
+ state: "input-available",
+ input: {},
+ },
+ ],
+ },
+ ] as any;
+ render(<AgentChatMessages />);
+ expect(screen.getByText(/Streaming\./i)).toBeInTheDocument();
+ expect(screen.queryByText(/SCORES:/)).not.toBeInTheDocument();
+ });
});
diff --git a/__tests__/AgentResultCard.spec.tsx b/__tests__/AgentResultCard.spec.tsx
index 46d94a2..89f8fe8 100644
--- a/__tests__/AgentResultCard.spec.tsx
+++ b/__tests__/AgentResultCard.spec.tsx
@@ -16,6 +16,15 @@ const resultPart = (output: unknown, state = "output-available") =>
output,
}) as any;
+const outputPart = (toolName: string, output: unknown) =>
+ ({
+ type: `tool-${toolName}`,
+ toolCallId: "c1",
+ state: "output-available",
+ input: {},
+ output,
+ }) as any;
+
describe("AgentResultCard", () => {
it("names the created job, links to it, and reports the description", () => {
render(
@@ -249,4 +258,49 @@ describe("AgentResultCard", () => {
expect(screen.queryByText("Impact")).not.toBeInTheDocument();
expect(screen.getByText(/could not be generated/i)).toBeInTheDocument();
});
+
+ it("renders the match score, recommendation and body from the tool output", () => {
+ render(
+ <AgentResultCard
+ part={outputPart("match_job", {
+ status: "ok",
+ jobId: "job-1",
+ jobTitle: "Senior Backend Engineer",
+ company: "Northwind Cloud",
+ resumeId: "r9",
+ resumeTitle: "Senior Engineer Resume",
+ scores: { matchScore: 72, recommendation: "good match" },
+ body: "## Summary\n\nStrong backend overlap.",
+ saved: true,
+ })}
+ />,
+ );
+ expect(screen.getByText(/good match/i)).toBeInTheDocument();
+ expect(screen.getByText(/Strong backend overlap/i)).toBeInTheDocument();
+ });
+
+ it("tells the user to open a job when there is none in context", () => {
+ render(<AgentResultCard part={outputPart("match_job", { status: "no_job" })} />);
+ expect(screen.getByText(/open the job/i)).toBeInTheDocument();
+ });
+
+ it("reports a match save failure instead of hiding it", () => {
+ render(
+ <AgentResultCard
+ part={outputPart("match_job", {
+ status: "ok",
+ jobId: "job-1",
+ jobTitle: "Senior Backend Engineer",
+ company: "Northwind Cloud",
+ resumeId: "r9",
+ resumeTitle: "Senior Engineer Resume",
+ scores: { matchScore: 72, recommendation: "good match" },
+ body: "## Summary",
+ saved: false,
+ saveError: "Database is locked.",
+ })}
+ />,
+ );
+ expect(screen.getByText(/Database is locked/i)).toBeInTheDocument();
+ });
});
diff --git a/src/components/agent/AgentChatEmptyState.tsx b/src/components/agent/AgentChatEmptyState.tsx
index f51cf57..d73e357 100644
--- a/src/components/agent/AgentChatEmptyState.tsx
+++ b/src/components/agent/AgentChatEmptyState.tsx
@@ -23,8 +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. I can&apos;t read your existing jobs
- or tasks yet.
+ 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.
</p>
<Suggestions>
diff --git a/src/components/agent/AgentChatMessages.tsx b/src/components/agent/AgentChatMessages.tsx
index 15d4c52..5625491 100644
--- a/src/components/agent/AgentChatMessages.tsx
+++ b/src/components/agent/AgentChatMessages.tsx
@@ -11,12 +11,14 @@ import {
import { Button } from "@/components/ui/button";
import { AgentApprovalCard } from "@/components/agent/AgentApprovalCard";
import { AgentMarkdown } from "@/components/agent/AgentMarkdown";
+import { AgentMatchContent } from "@/components/agent/AgentMatchContent";
import { AgentResultCard } from "@/components/agent/AgentResultCard";
import { AgentReviewContent } from "@/components/agent/AgentReviewContent";
import { AgentStatusRow } from "@/components/agent/AgentStatusRow";
import { AgentToolRunningCard } from "@/components/agent/AgentToolRunningCard";
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 { cn } from "@/lib/utils";
import { isAgentPastePart, type AgentPastePartData } from "@/models/agent.model";
@@ -125,11 +127,23 @@ export function AgentChatMessages() {
switch (part.state) {
case "input-streaming":
case "input-available": {
- const streamed =
- getToolName(part) === "review_resume"
- ? toolStreams[part.toolCallId]
- : undefined;
+ const tool = getToolName(part);
+ const nested =
+ tool === "review_resume" || tool === "match_job";
+ const streamed = nested
+ ? toolStreams[part.toolCallId]
+ : undefined;
if (!streamed) return <AgentToolRunningCard key={i} part={part} />;
+ if (tool === "match_job") {
+ const parsed = parseJobMatch(streamed);
+ return (
+ <AgentMatchContent
+ key={i}
+ body={parsed.body}
+ scores={parsed.scores}
+ />
+ );
+ }
const parsed = parseResumeReview(streamed);
return (
<AgentReviewContent
diff --git a/src/components/agent/AgentChatProvider.tsx b/src/components/agent/AgentChatProvider.tsx
index 1b141e6..b356e96 100644
--- a/src/components/agent/AgentChatProvider.tsx
+++ b/src/components/agent/AgentChatProvider.tsx
@@ -143,9 +143,12 @@ function useAgentChatValue(initialMessages: UIMessage[]) {
if (getToolName(part) !== "add_job") return false;
return (part.output as AgentAddJobResult | undefined)?.created === true;
});
- const reviewed = finishedParts.some((part) => {
+ // Any nested tool that saves server-side leaves the page behind the
+ // panel stale — the saved review card, or the job's match score.
+ const generated = finishedParts.some((part) => {
if (!isToolUIPart(part) || part.state !== "output-available") return false;
- return getToolName(part) === "review_resume";
+ const tool = getToolName(part);
+ return tool === "review_resume" || tool === "match_job";
});
// The route stubs the paste on its way into the DB, but that copy is
@@ -157,9 +160,9 @@ function useAgentChatValue(initialMessages: UIMessage[]) {
if (wrote) chat.setMessages((prev) => stubConsumedPastes(prev));
// Unconditional: an RSC refresh on an irrelevant page is a wasted
- // request, not a bug. A stale jobs list or a stale saved review behind
- // the panel right after watching one land reads as one.
- if (wrote || reviewed) router.refresh();
+ // request, not a bug. A stale jobs list, a stale saved review or a
+ // stale match score right after watching one land reads as one.
+ if (wrote || generated) router.refresh();
},
});
diff --git a/src/components/agent/AgentMatchContent.tsx b/src/components/agent/AgentMatchContent.tsx
new file mode 100644
index 0000000..740297b
--- /dev/null
+++ b/src/components/agent/AgentMatchContent.tsx
@@ -0,0 +1,23 @@
+"use client";
+
+import { AgentMarkdown } from "@/components/agent/AgentMarkdown";
+import { AgentMatchScoreCard } from "@/components/agent/AgentMatchScoreCard";
+import type { JobMatchScores } from "@/models/ai.schemas";
+
+// One renderer for both phases of a match: the transient token stream while
+// match_job runs, and the structured tool output once it returns. Using two
+// would let the handoff visibly change the layout mid-turn.
+export function AgentMatchContent({
+ scores,
+ body,
+}: {
+ scores?: JobMatchScores;
+ body: string;
+}) {
+ return (
+ <>
+ {scores && <AgentMatchScoreCard scores={scores} />}
+ <AgentMarkdown text={body} />
+ </>
+ );
+}
diff --git a/src/components/agent/AgentMatchScoreCard.tsx b/src/components/agent/AgentMatchScoreCard.tsx
new file mode 100644
index 0000000..d63067a
--- /dev/null
+++ b/src/components/agent/AgentMatchScoreCard.tsx
@@ -0,0 +1,38 @@
+"use client";
+
+import { RadialChartComponent } from "@/components/RadialChartSvg";
+import { Badge } from "@/components/ui/badge";
+import type { JobMatchScores } from "@/models/ai.schemas";
+
+const recommendationVariant = (recommendation: string) =>
+ recommendation === "strong match"
+ ? "default"
+ : recommendation === "good match"
+ ? "secondary"
+ : recommendation === "partial match"
+ ? "outline"
+ : "destructive";
+
+// A copy of the retired match sheet's score block, kept here so that surface
+// could be deleted without touching this one.
+export function AgentMatchScoreCard({
+ scores,
+ size,
+}: {
+ scores: JobMatchScores;
+ size?: number;
+}) {
+ return (
+ <div className="flex flex-col items-center rounded-sm border p-3">
+ <RadialChartComponent score={scores.matchScore} size={size} />
+ {scores.recommendation && (
+ <Badge
+ variant={recommendationVariant(scores.recommendation)}
+ className="mt-2 capitalize"
+ >
+ {scores.recommendation}
+ </Badge>
+ )}
+ </div>
+ );
+}
diff --git a/src/components/agent/AgentResultCard.tsx b/src/components/agent/AgentResultCard.tsx
index 47bf57c..bf01e36 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 { AgentMatchContent } from "@/components/agent/AgentMatchContent";
import { AgentReviewContent } from "@/components/agent/AgentReviewContent";
import type {
AgentAddJobResult,
AgentGetResumeResult,
+ AgentMatchJobResult,
AgentReviewResumeResult,
} from "@/models/agent.model";
@@ -177,6 +179,72 @@ function ReviewResumeResult({ output }: { output: AgentReviewResumeResult }) {
);
}
+// The score and body come from the tool output, not from parsed prose — the
+// match is a server-side generation, so the card cannot disagree with what
+// was saved.
+function MatchJobResult({ output }: { output: AgentMatchJobResult }) {
+ if (output.status === "no_job") {
+ return (
+ <p className="text-sm">
+ Open the job you want to match first — I score the job you&apos;re
+ looking at.
+ </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 I match against?</p>
+ <AgentResumePicker
+ resumes={output.resumes}
+ messageFor={(title) => `Match this job against 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 match <strong>{output.jobTitle}</strong> — {output.reason}
+ </p>
+ );
+ }
+
+ return (
+ <div className="text-sm">
+ <AgentMatchContent body={output.body} scores={output.scores} />
+ <p className="mt-2 text-xs text-muted-foreground">
+ {output.jobTitle}
+ {output.company ? ` at ${output.company}` : ""} · matched against{" "}
+ {output.resumeTitle}
+ </p>
+ {!output.saved && (
+ <p className="mt-1 text-xs text-muted-foreground">
+ Match not saved — {output.saveError}
+ </p>
+ )}
+ </div>
+ );
+}
+
export function AgentResultCard({ part }: { part: ToolUIPart }) {
if (part.state === "output-denied") {
return (
@@ -207,6 +275,8 @@ export function AgentResultCard({ part }: { part: ToolUIPart }) {
<GetResumeResult output={part.output as AgentGetResumeResult} />
) : toolName === "review_resume" ? (
<ReviewResumeResult output={part.output as AgentReviewResumeResult} />
+ ) : toolName === "match_job" ? (
+ <MatchJobResult output={part.output as AgentMatchJobResult} />
) : null;
return <div className="rounded-sm border p-3">{body}</div>;
diff --git a/src/components/agent/AgentResumePicker.tsx b/src/components/agent/AgentResumePicker.tsx
index 3e8cb7b..746d90f 100644
--- a/src/components/agent/AgentResumePicker.tsx
+++ b/src/components/agent/AgentResumePicker.tsx
@@ -13,8 +13,10 @@ import { useAgentChat } from "@/components/agent/AgentChatProvider";
// scroll fix, and a handful of resumes does not need search.
export function AgentResumePicker({
resumes,
+ messageFor,
}: {
resumes: { id: string; title: string }[];
+ messageFor?: (title: string) => string;
}) {
const { sendMessage } = useAgentChat();
@@ -23,11 +25,10 @@ export function AgentResumePicker({
const pick = (id: string) => {
const title = resumes.find((r) => r.id === id)?.title;
if (!title) return;
+ const text = messageFor ? messageFor(title) : `Review my resume "${title}"`;
// The parts form, matching AgentChatInput — this surface always sends
// parts, never a bare text shortcut.
- void sendMessage({
- parts: [{ type: "text", text: `Review my resume "${title}"` }],
- });
+ void sendMessage({ parts: [{ type: "text", text }] });
};
return (
diff --git a/src/components/agent/AgentToolRunningCard.tsx b/src/components/agent/AgentToolRunningCard.tsx
index 4ddeb65..42a4da3 100644
--- a/src/components/agent/AgentToolRunningCard.tsx
+++ b/src/components/agent/AgentToolRunningCard.tsx
@@ -14,7 +14,9 @@ export function AgentToolRunningCard({ part }: { part: ToolUIPart }) {
? "Reading your resume…"
: toolName === "review_resume"
? "Reviewing your resume…"
- : "Working…";
+ : toolName === "match_job"
+ ? "Matching your resume to this job…"
+ : "Working…";
return <AgentStatusRow label={label} />;
}