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 the streaming and finished review in the transcript

Khuram Niaz0a32a9c50fb9
diff --git a/__tests__/AgentChatMessages.spec.tsx b/__tests__/AgentChatMessages.spec.tsx
index cf51adc..f459a32 100644
--- a/__tests__/AgentChatMessages.spec.tsx
+++ b/__tests__/AgentChatMessages.spec.tsx
@@ -10,6 +10,7 @@ const chat = {
addToolApprovalResponse: vi.fn(),
interruptedTurn: false,
dismissInterrupted: vi.fn(),
+ reviewStreams: {} as Record<string, string>,
};
vi.mock("@/components/agent/AgentChatProvider", () => ({
useAgentChat: () => chat,
@@ -57,6 +58,7 @@ describe("AgentChatMessages", () => {
chat.messages = [];
chat.status = "ready";
chat.interruptedTurn = false;
+ chat.reviewStreams = {};
});
it("renders the running card while the tool input is still arriving", () => {
@@ -292,4 +294,33 @@ describe("AgentChatMessages", () => {
render(<AgentChatMessages />);
expect(screen.queryByText("Impact")).not.toBeInTheDocument();
});
+
+ const reviewRunning = {
+ type: "tool-review_resume",
+ toolCallId: "rv1",
+ state: "input-available",
+ input: {},
+ } as any;
+
+ it("renders the review as it streams, before the tool result exists", () => {
+ chat.status = "streaming";
+ chat.reviewStreams = {
+ rv1: "SCORES: overall=78 impact=72 clarity=81 ats=69\n\n## Summary\n\nSolid.",
+ };
+ chat.messages = [assistant([reviewRunning])];
+ render(<AgentChatMessages />);
+ expect(screen.getByText("Impact")).toBeInTheDocument();
+ expect(screen.queryByText(/SCORES:/)).not.toBeInTheDocument();
+ expect(screen.getByTestId("tiptap-content").innerHTML).toContain(
+ "<h2>Summary</h2>",
+ );
+ });
+
+ it("shows the running card until the first review token arrives", () => {
+ chat.status = "streaming";
+ chat.reviewStreams = {};
+ chat.messages = [assistant([reviewRunning])];
+ render(<AgentChatMessages />);
+ expect(screen.getByText(/reviewing your resume/i)).toBeInTheDocument();
+ });
});
diff --git a/__tests__/AgentResultCard.spec.tsx b/__tests__/AgentResultCard.spec.tsx
index 1d15615..46d94a2 100644
--- a/__tests__/AgentResultCard.spec.tsx
+++ b/__tests__/AgentResultCard.spec.tsx
@@ -174,4 +174,79 @@ describe("AgentResultCard", () => {
render(<AgentResultCard part={getResumePart({ status: "no_resumes" }) as any} />);
expect(screen.getByText(/don't have any resumes/i)).toBeInTheDocument();
});
+
+ it("renders the score card and the review body from a review result", () => {
+ render(
+ <AgentResultCard
+ part={
+ {
+ type: "tool-review_resume",
+ toolCallId: "c9",
+ state: "output-available",
+ input: {},
+ output: {
+ status: "ok",
+ resumeId: "r1",
+ title: "Senior Engineer Resume",
+ scores: { overall: 78, impact: 72, clarity: 81, atsCompatibility: 69 },
+ body: "## Summary\n\nSolid resume.",
+ saved: true,
+ },
+ } as any
+ }
+ />,
+ );
+ expect(screen.getByText("Impact")).toBeInTheDocument();
+ expect(screen.getByText("72")).toBeInTheDocument();
+ expect(screen.queryByText(/could not be saved/i)).not.toBeInTheDocument();
+ });
+
+ // On screen either way; silently unsaved is the bad outcome.
+ it("says so when the review could not be saved", () => {
+ render(
+ <AgentResultCard
+ part={
+ {
+ type: "tool-review_resume",
+ toolCallId: "c9",
+ state: "output-available",
+ input: {},
+ output: {
+ status: "ok",
+ resumeId: "r1",
+ title: "Senior Engineer Resume",
+ scores: { overall: 78, impact: 72, clarity: 81, atsCompatibility: 69 },
+ body: "## Summary",
+ saved: false,
+ saveError: "Database is locked.",
+ },
+ } as any
+ }
+ />,
+ );
+ expect(screen.getByText(/not saved/i)).toBeInTheDocument();
+ expect(screen.getByText(/database is locked/i)).toBeInTheDocument();
+ });
+
+ it("reports a failed review generation without a score card", () => {
+ render(
+ <AgentResultCard
+ part={
+ {
+ type: "tool-review_resume",
+ toolCallId: "c9",
+ state: "output-available",
+ input: {},
+ output: {
+ status: "generation_failed",
+ title: "Senior Engineer Resume",
+ reason: "The review could not be generated. Try again in a moment.",
+ },
+ } as any
+ }
+ />,
+ );
+ expect(screen.queryByText("Impact")).not.toBeInTheDocument();
+ expect(screen.getByText(/could not be generated/i)).toBeInTheDocument();
+ });
});
diff --git a/src/components/agent/AgentChatMessages.tsx b/src/components/agent/AgentChatMessages.tsx
index 5462544..7771292 100644
--- a/src/components/agent/AgentChatMessages.tsx
+++ b/src/components/agent/AgentChatMessages.tsx
@@ -2,7 +2,7 @@
import { useMemo, useState } from "react";
import { FileTextIcon, XIcon } from "lucide-react";
-import { isStaticToolUIPart, type UIMessage } from "ai";
+import { getToolName, isStaticToolUIPart, type UIMessage } from "ai";
import {
Conversation,
ConversationContent,
@@ -12,6 +12,7 @@ import { Button } from "@/components/ui/button";
import { AgentApprovalCard } from "@/components/agent/AgentApprovalCard";
import { AgentMarkdown } from "@/components/agent/AgentMarkdown";
import { AgentResultCard } from "@/components/agent/AgentResultCard";
+import { AgentReviewContent } from "@/components/agent/AgentReviewContent";
import { AgentReviewScoreCard } from "@/components/agent/AgentReviewScoreCard";
import { AgentStatusRow } from "@/components/agent/AgentStatusRow";
import { AgentToolRunningCard } from "@/components/agent/AgentToolRunningCard";
@@ -104,6 +105,7 @@ function AssistantText({
export function AgentChatMessages() {
const {
messages,
+ reviewStreams,
status,
regenerate,
addToolApprovalResponse,
@@ -163,8 +165,21 @@ export function AgentChatMessages() {
if (!isStaticToolUIPart(part)) return null;
switch (part.state) {
case "input-streaming":
- case "input-available":
- return <AgentToolRunningCard key={i} part={part} />;
+ case "input-available": {
+ const streamed =
+ getToolName(part) === "review_resume"
+ ? reviewStreams[part.toolCallId]
+ : undefined;
+ if (!streamed) return <AgentToolRunningCard key={i} part={part} />;
+ const parsed = parseResumeReview(streamed);
+ return (
+ <AgentReviewContent
+ key={i}
+ body={parsed.body}
+ scores={parsed.scores}
+ />
+ );
+ }
case "approval-requested":
case "approval-responded":
return (
diff --git a/src/components/agent/AgentChatProvider.tsx b/src/components/agent/AgentChatProvider.tsx
index ac17672..2efc5f8 100644
--- a/src/components/agent/AgentChatProvider.tsx
+++ b/src/components/agent/AgentChatProvider.tsx
@@ -29,7 +29,12 @@ import { clearChatConversation } from "@/actions/agentChat.actions";
import { getUserSettings } from "@/actions/userSettings.actions";
import { checkOllamaConnection } from "@/utils/ai.utils";
import { AiProvider } from "@/models/ai.model";
-import type { AgentAddJobResult, PageContext } from "@/models/agent.model";
+import {
+ AGENT_REVIEW_PART_TYPE,
+ type AgentAddJobResult,
+ type AgentReviewStreamData,
+ type PageContext,
+} from "@/models/agent.model";
export const AGENT_CHAT_PANEL_ID = "chat";
@@ -101,6 +106,11 @@ function useAgentChatValue(initialMessages: UIMessage[]) {
pageContextRef.current = pageContextFor(pathname);
}, [pathname]);
+ // Transient data parts never land in message.parts — the SDK hands them to
+ // onData and drops them — so the review's streaming text lives here, keyed
+ // by toolCallId so two reviews in one conversation cannot collide.
+ const [reviewStreams, setReviewStreams] = useState<Record<string, string>>({});
+
const chat = useChat({
messages: initialMessages,
transport: new DefaultChatTransport({
@@ -112,6 +122,12 @@ function useAgentChatValue(initialMessages: UIMessage[]) {
// Without this the approval is resolved client-side and nothing ever
// POSTs back to execute the tool. It is the mechanism, not a nicety.
sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponses,
+ onData: (part) => {
+ if (part.type !== AGENT_REVIEW_PART_TYPE || !part.id) return;
+ const id = part.id;
+ const { delta } = part.data as AgentReviewStreamData;
+ setReviewStreams((prev) => ({ ...prev, [id]: (prev[id] ?? "") + delta }));
+ },
onFinish: ({ message, messages, isAbort, isError }) => {
// onFinish runs from a finally block, so it fires on abort too. The
// SCORES line streams first, so a partial review parses — and
@@ -238,6 +254,7 @@ function useAgentChatValue(initialMessages: UIMessage[]) {
// time it remounts.
setPrefill(undefined);
setComposerNonce((n) => n + 1);
+ setReviewStreams({});
}, [chat]);
const approvalPending = useMemo(
@@ -252,6 +269,7 @@ function useAgentChatValue(initialMessages: UIMessage[]) {
open,
close,
messages: chat.messages,
+ reviewStreams,
status: chat.status,
error: chat.error,
clearError: chat.clearError,
diff --git a/src/components/agent/AgentResultCard.tsx b/src/components/agent/AgentResultCard.tsx
index 21db2ab..47bf57c 100644
--- a/src/components/agent/AgentResultCard.tsx
+++ b/src/components/agent/AgentResultCard.tsx
@@ -4,7 +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 type { AgentAddJobResult, AgentGetResumeResult } from "@/models/agent.model";
+import { AgentReviewContent } from "@/components/agent/AgentReviewContent";
+import type {
+ AgentAddJobResult,
+ AgentGetResumeResult,
+ AgentReviewResumeResult,
+} from "@/models/agent.model";
// Composed from the tool result's STRUCTURED fields, never from
// createJobFromNames' message string — that prose is MCP-facing protocol text
@@ -131,6 +136,47 @@ function GetResumeResult({ output }: { output: AgentGetResumeResult }) {
);
}
+// The scores and body come from the tool output, not from parsed prose — the
+// review is a server-side generation now, so the card cannot disagree with
+// what was saved.
+function ReviewResumeResult({ output }: { output: AgentReviewResumeResult }) {
+ 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?</p>
+ <AgentResumePicker resumes={output.resumes} />
+ </div>
+ );
+ }
+
+ if (output.status === "unreadable" || output.status === "generation_failed") {
+ return (
+ <p className="text-sm">
+ Couldn&apos;t review <strong>{output.title}</strong> — {output.reason}
+ </p>
+ );
+ }
+
+ return (
+ <div className="text-sm">
+ <AgentReviewContent body={output.body} scores={output.scores} />
+ {!output.saved && (
+ <p className="mt-2 text-xs text-muted-foreground">
+ Review not saved — {output.saveError}
+ </p>
+ )}
+ </div>
+ );
+}
+
export function AgentResultCard({ part }: { part: ToolUIPart }) {
if (part.state === "output-denied") {
return (
@@ -159,6 +205,8 @@ export function AgentResultCard({ part }: { part: ToolUIPart }) {
/>
) : toolName === "get_resume" ? (
<GetResumeResult output={part.output as AgentGetResumeResult} />
+ ) : toolName === "review_resume" ? (
+ <ReviewResumeResult output={part.output as AgentReviewResumeResult} />
) : null;
return <div className="rounded-sm border p-3">{body}</div>;
diff --git a/src/components/agent/AgentReviewContent.tsx b/src/components/agent/AgentReviewContent.tsx
new file mode 100644
index 0000000..28cf489
--- /dev/null
+++ b/src/components/agent/AgentReviewContent.tsx
@@ -0,0 +1,23 @@
+"use client";
+
+import { AgentMarkdown } from "@/components/agent/AgentMarkdown";
+import { AgentReviewScoreCard } from "@/components/agent/AgentReviewScoreCard";
+import type { ResumeScores } from "@/models/ai.schemas";
+
+// One renderer for both phases of a review: the transient token stream while
+// review_resume runs, and the structured tool output once it returns. Using
+// two would let the handoff visibly change the layout mid-turn.
+export function AgentReviewContent({
+ scores,
+ body,
+}: {
+ scores?: ResumeScores;
+ body: string;
+}) {
+ return (
+ <>
+ {scores && <AgentReviewScoreCard scores={scores} />}
+ <AgentMarkdown text={body} />
+ </>
+ );
+}
diff --git a/src/components/agent/AgentToolRunningCard.tsx b/src/components/agent/AgentToolRunningCard.tsx
index 653ff03..4ddeb65 100644
--- a/src/components/agent/AgentToolRunningCard.tsx
+++ b/src/components/agent/AgentToolRunningCard.tsx
@@ -12,7 +12,9 @@ export function AgentToolRunningCard({ part }: { part: ToolUIPart }) {
? "Preparing to add a job…"
: toolName === "get_resume"
? "Reading your resume…"
- : "Working…";
+ : toolName === "review_resume"
+ ? "Reviewing your resume…"
+ : "Working…";
return <AgentStatusRow label={label} />;
}