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: add skills to resume import

Khuram Niaz38377e90c326
diff --git a/__tests__/TagInput.spec.tsx b/__tests__/TagInput.spec.tsx
index d407c53..29fcc13 100644
--- a/__tests__/TagInput.spec.tsx
+++ b/__tests__/TagInput.spec.tsx
@@ -165,6 +165,41 @@ describe("TagInput Component", () => {
});
});
+ it("renders chips for pre-selected tags that load after mount", async () => {
+ // Reproduces the import-edit bug: the picker mounts before its tag pool is
+ // fetched. Chips must appear once availableTags arrives via a prop update.
+ function LateLoadingTagInput() {
+ const [tags, setTags] = useState<Tag[]>([]);
+ React.useEffect(() => {
+ const t = setTimeout(() => setTags(MOCK_TAGS), 0);
+ return () => clearTimeout(t);
+ }, []);
+ return (
+ <TagInput
+ availableTags={tags}
+ selectedTagIds={["tag-1", "tag-3"]}
+ onChange={() => {}}
+ />
+ );
+ }
+
+ render(<LateLoadingTagInput />);
+
+ // Initially empty pool -> no chip
+ expect(
+ screen.queryByRole("button", { name: /remove react/i }),
+ ).not.toBeInTheDocument();
+
+ await waitFor(() => {
+ expect(
+ screen.getByRole("button", { name: /remove react/i }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("button", { name: /remove node.js/i }),
+ ).toBeInTheDocument();
+ });
+ });
+
it("renders selected tag badges for pre-selected tags", () => {
render(
<ControlledTagInput
diff --git a/__tests__/resumeImport.actions.spec.ts b/__tests__/resumeImport.actions.spec.ts
new file mode 100644
index 0000000..9983eda
--- /dev/null
+++ b/__tests__/resumeImport.actions.spec.ts
@@ -0,0 +1,179 @@
+import { resolveImportCard } from "@/actions/resumeImport.actions";
+import { getCurrentUser } from "@/utils/user.utils";
+import { PrismaClient } from "@prisma/client";
+import { APP_CONSTANTS } from "@/lib/constants";
+
+const prisma = new PrismaClient();
+
+vi.mock("@prisma/client", () => {
+ const mPrismaClient = {
+ resume: { findUnique: vi.fn() },
+ resumeSection: { create: vi.fn(), findFirst: vi.fn(), update: vi.fn() },
+ skill: { createMany: vi.fn() },
+ tag: { findUnique: vi.fn(), create: vi.fn() },
+ };
+ return {
+ PrismaClient: vi.fn(function () {
+ return mPrismaClient;
+ }),
+ };
+});
+
+vi.mock("@/utils/user.utils", () => ({ getCurrentUser: vi.fn() }));
+
+describe("resolveImportCard — skills", () => {
+ const mockUser = { id: "user-1" };
+
+ beforeEach(() => {
+ vi.clearAllMocks();
+ (getCurrentUser as any).mockResolvedValue(mockUser);
+ (prisma.resume.findUnique as any).mockResolvedValue({ id: "resume-1" });
+ (prisma.resumeSection.create as any).mockResolvedValue({ id: "section-1" });
+ (prisma.skill.createMany as any).mockResolvedValue({ count: 0 });
+ // resolveTag: every name is a brand-new tag
+ (prisma.tag.findUnique as any).mockResolvedValue(null);
+ (prisma.tag.create as any).mockImplementation(({ data }: any) =>
+ Promise.resolve({
+ id: `tag-${data.value}`,
+ label: data.label,
+ value: data.value,
+ createdBy: data.createdBy,
+ }),
+ );
+ });
+
+ it("creates a SKILLS section and skill rows with resolved tags, categories and order", async () => {
+ const result = await resolveImportCard("resume-1", {
+ type: "skills",
+ data: {
+ categories: [
+ { label: "Languages", skills: ["TypeScript", "Go"] },
+ { label: "Tools", skills: ["Docker"] },
+ ],
+ },
+ } as any);
+
+ expect(result).toEqual({ success: true, status: "saved" });
+
+ expect(prisma.resumeSection.create).toHaveBeenCalledWith({
+ data: {
+ resumeId: "resume-1",
+ sectionTitle: "Skills",
+ sectionType: "skills",
+ },
+ });
+
+ expect(prisma.skill.createMany).toHaveBeenCalledWith({
+ data: [
+ { tagId: "tag-typescript", category: "Languages", order: 0, resumeSectionId: "section-1" },
+ { tagId: "tag-go", category: "Languages", order: 1, resumeSectionId: "section-1" },
+ { tagId: "tag-docker", category: "Tools", order: 2, resumeSectionId: "section-1" },
+ ],
+ });
+ });
+
+ it("stores a null category when no label is given", async () => {
+ await resolveImportCard("resume-1", {
+ type: "skills",
+ data: { categories: [{ skills: ["React"] }] },
+ } as any);
+
+ const rows = (prisma.skill.createMany as any).mock.calls[0][0].data;
+ expect(rows[0].category).toBeNull();
+ });
+
+ it("trims skills and drops empty entries/categories", async () => {
+ await resolveImportCard("resume-1", {
+ type: "skills",
+ data: {
+ categories: [
+ { label: " Backend ", skills: [" SQL ", "", " "] },
+ { label: "Empty", skills: [] },
+ ],
+ },
+ } as any);
+
+ const rows = (prisma.skill.createMany as any).mock.calls[0][0].data;
+ expect(rows).toEqual([
+ { tagId: "tag-sql", category: "Backend", order: 0, resumeSectionId: "section-1" },
+ ]);
+ });
+
+ it("caps categories and skills per category at the app limits", async () => {
+ const tooManyCategories = Array.from(
+ { length: APP_CONSTANTS.MAX_SKILL_CATEGORIES + 3 },
+ (_, c) => ({
+ label: `cat-${c}`,
+ skills: Array.from(
+ { length: APP_CONSTANTS.MAX_SKILLS_PER_CATEGORY + 5 },
+ (_, s) => `c${c}s${s}`,
+ ),
+ }),
+ );
+
+ await resolveImportCard("resume-1", {
+ type: "skills",
+ data: { categories: tooManyCategories },
+ } as any);
+
+ const rows = (prisma.skill.createMany as any).mock.calls[0][0].data;
+ const categories = new Set(rows.map((r: any) => r.category));
+ expect(categories.size).toBe(APP_CONSTANTS.MAX_SKILL_CATEGORIES);
+ expect(rows).toHaveLength(
+ APP_CONSTANTS.MAX_SKILL_CATEGORIES * APP_CONSTANTS.MAX_SKILLS_PER_CATEGORY,
+ );
+ });
+
+ it("fails when there are no usable skills (no section created)", async () => {
+ const result = await resolveImportCard("resume-1", {
+ type: "skills",
+ data: { categories: [{ label: "X", skills: [" "] }] },
+ } as any);
+
+ expect(result.success).toBe(false);
+ expect(prisma.resumeSection.create).not.toHaveBeenCalled();
+ expect(prisma.skill.createMany).not.toHaveBeenCalled();
+ });
+
+ it("rejects when the resume is not owned by the user", async () => {
+ (prisma.resume.findUnique as any).mockResolvedValue(null);
+
+ const result = await resolveImportCard("resume-1", {
+ type: "skills",
+ data: { categories: [{ skills: ["React"] }] },
+ } as any);
+
+ expect(result.success).toBe(false);
+ expect(prisma.resumeSection.create).not.toHaveBeenCalled();
+ });
+
+ it("rejects unauthenticated users", async () => {
+ (getCurrentUser as any).mockResolvedValue(null);
+
+ const result = await resolveImportCard("resume-1", {
+ type: "skills",
+ data: { categories: [{ skills: ["React"] }] },
+ } as any);
+
+ expect(result.success).toBe(false);
+ expect(prisma.resume.findUnique).not.toHaveBeenCalled();
+ });
+
+ it("reuses an existing tag instead of creating a duplicate", async () => {
+ (prisma.tag.findUnique as any).mockResolvedValue({
+ id: "existing-tag",
+ label: "React",
+ value: "react",
+ createdBy: mockUser.id,
+ });
+
+ await resolveImportCard("resume-1", {
+ type: "skills",
+ data: { categories: [{ skills: ["React"] }] },
+ } as any);
+
+ expect(prisma.tag.create).not.toHaveBeenCalled();
+ const rows = (prisma.skill.createMany as any).mock.calls[0][0].data;
+ expect(rows[0].tagId).toBe("existing-tag");
+ });
+});
diff --git a/__tests__/resumeImport.schema.spec.ts b/__tests__/resumeImport.schema.spec.ts
index 5fd2625..577bf3d 100644
--- a/__tests__/resumeImport.schema.spec.ts
+++ b/__tests__/resumeImport.schema.spec.ts
@@ -4,6 +4,7 @@ import {
ImportExperienceSchema,
ImportEducationSchema,
ImportCertificationSchema,
+ ImportSkillsSchema,
ResumeImportSchema,
} from "@/models/resumeImport.schema";
@@ -143,6 +144,38 @@ describe("ImportCertificationSchema", () => {
});
});
+// --- ImportSkillsSchema ---
+
+describe("ImportSkillsSchema", () => {
+ it("accepts categorized skills", () => {
+ const result = ImportSkillsSchema.safeParse({
+ categories: [
+ { label: "Languages", skills: ["TypeScript", "Python"] },
+ { label: "Tools", skills: ["Docker"] },
+ ],
+ confidence: "high",
+ });
+ expect(result.success).toBe(true);
+ });
+
+ it("accepts a flat list with no category label", () => {
+ const result = ImportSkillsSchema.safeParse({
+ categories: [{ skills: ["React", "Node.js"] }],
+ });
+ expect(result.success).toBe(true);
+ if (result.success) {
+ expect(result.data.categories[0].label).toBeUndefined();
+ expect(result.data.categories[0].skills).toEqual(["React", "Node.js"]);
+ }
+ });
+
+ it("defaults categories to [] when omitted", () => {
+ const result = ImportSkillsSchema.safeParse({});
+ expect(result.success).toBe(true);
+ if (result.success) expect(result.data.categories).toEqual([]);
+ });
+});
+
// --- ResumeImportSchema ---
describe("ResumeImportSchema", () => {
@@ -153,7 +186,8 @@ describe("ResumeImportSchema", () => {
experience: [{ company: "Acme", jobTitle: "Engineer" }],
education: [{ institution: "MIT" }],
certifications: [{ title: "AWS SAA" }],
- unrecognizedSections: ["Skills", "Projects"],
+ skills: { categories: [{ label: "Languages", skills: ["Go"] }] },
+ unrecognizedSections: ["Projects"],
});
expect(result.success).toBe(true);
});
diff --git a/__tests__/skillImport.utils.spec.ts b/__tests__/skillImport.utils.spec.ts
new file mode 100644
index 0000000..580d5f2
--- /dev/null
+++ b/__tests__/skillImport.utils.spec.ts
@@ -0,0 +1,75 @@
+import { describe, it, expect } from "vitest";
+import { extractSkillCategories } from "@/utils/skillImport.utils";
+
+describe("extractSkillCategories", () => {
+ it("returns [] for nullish/garbage input", () => {
+ expect(extractSkillCategories(undefined)).toEqual([]);
+ expect(extractSkillCategories(null)).toEqual([]);
+ expect(extractSkillCategories("nope")).toEqual([]);
+ expect(extractSkillCategories(42)).toEqual([]);
+ });
+
+ it("normalizes the documented { categories } object shape", () => {
+ const result = extractSkillCategories({
+ categories: [
+ { label: "Languages", skills: ["TypeScript", "Python"] },
+ { label: "Tools", skills: ["Docker"] },
+ ],
+ });
+ expect(result).toEqual([
+ { label: "Languages", skills: ["TypeScript", "Python"] },
+ { label: "Tools", skills: ["Docker"] },
+ ]);
+ });
+
+ it("wraps a flat string array into a single unlabeled category", () => {
+ const result = extractSkillCategories(["React", "Node.js"]);
+ expect(result).toEqual([{ label: undefined, skills: ["React", "Node.js"] }]);
+ });
+
+ it("accepts a bare array of category objects", () => {
+ const result = extractSkillCategories([
+ { label: "Frontend", skills: ["CSS"] },
+ ]);
+ expect(result).toEqual([{ label: "Frontend", skills: ["CSS"] }]);
+ });
+
+ it("extracts skill names from { name } objects", () => {
+ const result = extractSkillCategories({
+ categories: [{ skills: [{ name: "Go" }, { name: "Rust" }] }],
+ });
+ expect(result[0].skills).toEqual(["Go", "Rust"]);
+ });
+
+ it("trims and drops empty skill strings", () => {
+ const result = extractSkillCategories({
+ categories: [{ label: "X", skills: [" Java ", "", " "] }],
+ });
+ expect(result).toEqual([{ label: "X", skills: ["Java"] }]);
+ });
+
+ it("drops categories that have no usable skills", () => {
+ const result = extractSkillCategories({
+ categories: [
+ { label: "Empty", skills: [] },
+ { label: "Real", skills: ["SQL"] },
+ ],
+ });
+ expect(result).toEqual([{ label: "Real", skills: ["SQL"] }]);
+ });
+
+ it("ignores a non-string label", () => {
+ const result = extractSkillCategories({
+ categories: [{ label: 123, skills: ["AWS"] }],
+ });
+ expect(result[0].label).toBeUndefined();
+ expect(result[0].skills).toEqual(["AWS"]);
+ });
+
+ it("survives partial streaming snapshots (skill briefly an object)", () => {
+ const result = extractSkillCategories({
+ categories: [{ label: "Cloud", skills: ["AWS", {}] }],
+ });
+ expect(result).toEqual([{ label: "Cloud", skills: ["AWS"] }]);
+ });
+});
diff --git a/src/actions/resumeImport.actions.ts b/src/actions/resumeImport.actions.ts
index 6aa57c5..5cda988 100644
--- a/src/actions/resumeImport.actions.ts
+++ b/src/actions/resumeImport.actions.ts
@@ -6,11 +6,14 @@ import { handleError } from "@/lib/utils";
import { SectionType } from "@/models/profile.model";
import { createJobTitle } from "@/actions/jobtitle.actions";
import { createLocation } from "@/actions/job.actions";
+import { resolveTag } from "@/lib/jobs/resolve";
+import { APP_CONSTANTS } from "@/lib/constants";
import {
ImportContactInfo,
ImportExperience,
ImportEducation,
ImportCertification,
+ ImportSkills,
} from "@/models/resumeImport.schema";
// TYPES
@@ -20,7 +23,8 @@ export type ImportCardPayload =
| { type: "summary"; data: string }
| { type: "experience"; data: ImportExperience }
| { type: "education"; data: ImportEducation }
- | { type: "certification"; data: ImportCertification };
+ | { type: "certification"; data: ImportCertification }
+ | { type: "skills"; data: ImportSkills };
export type ResolveResult =
| { success: true; status: "saved" }
@@ -296,6 +300,55 @@ export async function resolveImportCard(
});
break;
}
+
+ case "skills": {
+ // Drop empty categories/skills and enforce the same caps as the
+ // manual skills form before resolving names to shared tags.
+ const categories = (card.data.categories ?? [])
+ .map((cat) => ({
+ label: cat.label?.trim() || null,
+ skills: (cat.skills ?? [])
+ .map((s) => s.trim())
+ .filter(Boolean)
+ .slice(0, APP_CONSTANTS.MAX_SKILLS_PER_CATEGORY),
+ }))
+ .filter((cat) => cat.skills.length > 0)
+ .slice(0, APP_CONSTANTS.MAX_SKILL_CATEGORIES);
+
+ if (categories.length === 0) {
+ throw new Error("No skills to import");
+ }
+
+ const section = await prisma.resumeSection.create({
+ data: {
+ resumeId,
+ sectionTitle: "Skills",
+ sectionType: SectionType.SKILLS,
+ },
+ });
+
+ let order = 0;
+ const skillRows: {
+ tagId: string;
+ category: string | null;
+ order: number;
+ resumeSectionId: string;
+ }[] = [];
+ for (const cat of categories) {
+ for (const name of cat.skills) {
+ const tag = await resolveTag(name, user.id);
+ skillRows.push({
+ tagId: tag.id,
+ category: cat.label,
+ order: order++,
+ resumeSectionId: section.id,
+ });
+ }
+ }
+
+ await prisma.skill.createMany({ data: skillRows });
+ break;
+ }
}
return { success: true, status: "saved" };
diff --git a/src/app/api/ai/resume/import/route.ts b/src/app/api/ai/resume/import/route.ts
index 6bc698c..3915f09 100644
--- a/src/app/api/ai/resume/import/route.ts
+++ b/src/app/api/ai/resume/import/route.ts
@@ -121,6 +121,11 @@ export const POST = async (req: NextRequest) => {
APP_CONSTANTS.AI_RESUME_IMPORT_TIMEOUT_MS,
);
+ // Stop generation if the client disconnects (navigates away, closes tab,
+ // or aborts the fetch) — otherwise the model keeps running in the
+ // background until it finishes or hits the timeout.
+ req.signal.addEventListener("abort", () => controller.abort());
+
const result = streamText({
model,
output: Output.object({ schema: ResumeImportSchema }),
@@ -162,6 +167,11 @@ export const POST = async (req: NextRequest) => {
controller.close();
}
},
+ cancel() {
+ // Reader released (client gone) — abort the in-flight generation.
+ clearTimeout(timer);
+ controller.abort();
+ },
});
return new Response(body, {
diff --git a/src/components/myjobs/TagInput.tsx b/src/components/myjobs/TagInput.tsx
index a591ff2..bcff91a 100644
--- a/src/components/myjobs/TagInput.tsx
+++ b/src/components/myjobs/TagInput.tsx
@@ -1,5 +1,5 @@
"use client";
-import { useState, useTransition } from "react";
+import { useEffect, useState, useTransition } from "react";
import { X, ChevronsUpDown, CirclePlus, Loader } from "lucide-react";
import {
Popover,
@@ -46,6 +46,20 @@ export function TagInput({
const [localTags, setLocalTags] = useState<Tag[]>(availableTags);
const [isPending, startTransition] = useTransition();
+ // availableTags can load after mount (e.g. fetched once the dialog opens).
+ // Merge new tags into the local pool so chips and options reflect the prop,
+ // while preserving tags created locally during this session.
+ useEffect(() => {
+ setLocalTags((prev) => {
+ const ids = new Set(prev.map((t) => t.id));
+ const merged = [...prev];
+ for (const t of availableTags) {
+ if (!ids.has(t.id)) merged.push(t);
+ }
+ return merged;
+ });
+ }, [availableTags]);
+
const selectedTags = localTags.filter((t) => selectedTagIds.includes(t.id));
const isMaxReached = selectedTagIds.length >= max;
diff --git a/src/components/profile/ResumeContainer.tsx b/src/components/profile/ResumeContainer.tsx
index 1174b1e..ad40841 100644
--- a/src/components/profile/ResumeContainer.tsx
+++ b/src/components/profile/ResumeContainer.tsx
@@ -53,6 +53,7 @@ import { ResumeImportData } from "@/models/resumeImport.schema";
import { AiModel, defaultModel } from "@/models/ai.model";
import { getUserSettings } from "@/actions/userSettings.actions";
import { streamResumeImport } from "@/utils/resumeImportStream.utils";
+import { extractSkillCategories } from "@/utils/skillImport.utils";
import type { DeepPartial } from "ai";
type PendingCard = {
@@ -68,6 +69,8 @@ const SUPPORTED_KEYWORDS = [
"education",
"certification",
"certifications",
+ "skill",
+ "skills",
];
function filterUnrecognizedSections(sections: string[]): string[] {
@@ -77,6 +80,7 @@ function filterUnrecognizedSections(sections: string[]): string[] {
});
}
+
// Accepts partial data so cards can render progressively as the import stream
// arrives. Entries are only shown once their key identifying field is present.
function buildPendingCards(
@@ -98,13 +102,22 @@ function buildPendingCards(
});
}
- if (data.summary?.trim()) {
+ if (typeof data.summary === "string" && data.summary.trim()) {
cards.push({
id: "summary",
card: { type: "summary", data: data.summary },
});
}
+ // Skills sit before experience to match the resume's section order.
+ const skillCategories = extractSkillCategories(data.skills);
+ if (skillCategories.length > 0) {
+ cards.push({
+ id: "skills",
+ card: { type: "skills", data: { categories: skillCategories } as any },
+ });
+ }
+
(data.experience ?? []).forEach((exp, i) => {
if (!exp || (!exp.company && !exp.jobTitle)) return;
cards.push({
@@ -139,12 +152,16 @@ function cardSectionLabel(type: ImportCardPayload["type"]): string {
experience: "Experience",
education: "Education",
certification: "Certification",
+ skills: "Skills",
};
return map[type] ?? type;
}
-function DetailRow({ label, value }: { label: string; value?: string | null }) {
- if (!value) return null;
+function DetailRow({ label, value }: { label: string; value?: unknown }) {
+ // Streaming partials can momentarily emit a non-string (e.g. {}) for a field
+ // before it resolves — never hand a non-primitive to React.
+ if (typeof value !== "string" && typeof value !== "number") return null;
+ if (value === "") return null;
return (
<div className="flex gap-2 text-xs">
<span className="text-muted-foreground w-20 shrink-0">{label}</span>
@@ -187,7 +204,7 @@ function PendingCardDetail({ card }: { card: ImportCardPayload }) {
<DetailRow label="Company" value={d.company} />
<DetailRow label="Location" value={d.location} />
{dates && <DetailRow label="Dates" value={dates} />}
- {d.description && (
+ {typeof d.description === "string" && d.description && (
<p className="text-xs text-foreground mt-1 whitespace-pre-wrap pl-[5.5rem]">
{d.description}
</p>
@@ -206,7 +223,7 @@ function PendingCardDetail({ card }: { card: ImportCardPayload }) {
<DetailRow label="Field" value={d.fieldOfStudy} />
<DetailRow label="Location" value={d.location} />
{dates && <DetailRow label="Dates" value={dates} />}
- {d.description && (
+ {typeof d.description === "string" && d.description && (
<p className="text-xs text-foreground mt-1 whitespace-pre-wrap pl-[5.5rem]">
{d.description}
</p>
@@ -228,6 +245,36 @@ function PendingCardDetail({ card }: { card: ImportCardPayload }) {
);
}
+ if (card.type === "skills") {
+ const categories = card.data.categories ?? [];
+ return (
+ <div className="space-y-2 mt-1">
+ {categories.map((cat, i) => {
+ const skills = (cat.skills ?? []).filter(
+ (s): s is string => typeof s === "string" && !!s.trim(),
+ );
+ if (skills.length === 0) return null;
+ return (
+ <div key={i} className="space-y-1">
+ {typeof cat.label === "string" && cat.label && (
+ <span className="text-xs font-medium text-muted-foreground">
+ {cat.label}
+ </span>
+ )}
+ <div className="flex flex-wrap gap-1">
+ {skills.map((skill, j) => (
+ <Badge key={j} variant="secondary" className="text-xs">
+ {skill}
+ </Badge>
+ ))}
+ </div>
+ </div>
+ );
+ })}
+ </div>
+ );
+ }
+
return null;
}
@@ -312,6 +359,9 @@ function ResumeContainer({ resume }: { resume: Resume }) {
// Plain boolean (not useTransition): streaming fires rapid state updates that
// must not run as interruptible transition renders.
const [isStructuring, setIsStructuring] = useState(false);
+ // Aborts the in-flight import fetch so the server stops the LLM generation
+ // when the user navigates away or the component unmounts.
+ const importAbortRef = useRef<AbortController | null>(null);
// Runs the import stream, rendering cards progressively as they arrive.
const runImport = useCallback(
@@ -320,10 +370,13 @@ function ResumeContainer({ resume }: { resume: Resume }) {
if (!resumeId || isStructuring) return;
setIsStructuring(true);
setImportMode(true);
+ const abortController = new AbortController();
+ importAbortRef.current = abortController;
try {
const { data, truncated } = await streamResumeImport({
resumeId,
selectedModel: model,
+ signal: abortController.signal,
onPartial: (partial) => {
const cards = buildPendingCards(partial);
if (cards.length > 0) setPendingCards(cards);
@@ -346,6 +399,8 @@ function ResumeContainer({ resume }: { resume: Resume }) {
filterUnrecognizedSections(data.unrecognizedSections ?? []),
);
} catch (error) {
+ // Client-initiated abort (unmount/navigation) — not a user-facing error.
+ if (abortController.signal.aborted) return;
setImportMode(false);
toast({
variant: "destructive",
@@ -356,12 +411,20 @@ function ResumeContainer({ resume }: { resume: Resume }) {
: "Failed to contact AI service.",
});
} finally {
+ if (importAbortRef.current === abortController) {
+ importAbortRef.current = null;
+ }
setIsStructuring(false);
}
},
[resume.id, isStructuring],
);
+ // Abort any in-flight import when the component unmounts.
+ useEffect(() => {
+ return () => importAbortRef.current?.abort();
+ }, []);
+
// Auto-start the import stream when arriving from the create dialog
useEffect(() => {
if (!resume.id) return;
@@ -431,6 +494,7 @@ function ResumeContainer({ resume }: { resume: Resume }) {
const handleDiscardImport = async () => {
if (!resume.id) return;
+ importAbortRef.current?.abort();
const result = await deleteResumeById(resume.id);
if (result?.success) {
router.push("/dashboard/profile");
diff --git a/src/components/profile/resume-pdf/ProfessionalTemplate.tsx b/src/components/profile/resume-pdf/ProfessionalTemplate.tsx
index f67b581..e9182e9 100644
--- a/src/components/profile/resume-pdf/ProfessionalTemplate.tsx
+++ b/src/components/profile/resume-pdf/ProfessionalTemplate.tsx
@@ -141,22 +141,30 @@ export function ProfessionalResumeDocument({ resume, htmlNodes }: Props) {
return (
<View>
<SectionHeading title={skillsSection.sectionTitle} />
- {hasCategories ? (
- <View style={s.twoColRow}>
- {Array.from(grouped.entries()).map(([cat, items]) => (
- <View key={cat || "__flat"} style={s.twoColLeft}>
- {cat ? (
- <Text style={{ fontSize: 9, fontFamily: "Helvetica-Bold", textTransform: "uppercase", marginBottom: 1 }}>
- {cat}
+ {hasCategories ? (() => {
+ const entries = Array.from(grouped.entries());
+ const rows: (typeof entries)[] = [];
+ for (let i = 0; i < entries.length; i += 2) {
+ rows.push(entries.slice(i, i + 2));
+ }
+ return rows.map((row, rowIdx) => (
+ <View key={rowIdx} style={[s.twoColRow, { marginBottom: 4 }]}>
+ {row.map(([cat, items]) => (
+ <View key={cat || "__flat"} style={s.twoColLeft}>
+ {cat ? (
+ <Text style={{ fontSize: 9, fontFamily: "Helvetica-Bold", textTransform: "uppercase", marginBottom: 1 }}>
+ {cat}
+ </Text>
+ ) : null}
+ <Text style={{ fontSize: 10 }}>
+ {items.map((sk) => sk.Tag?.label).filter(Boolean).join(" · ")}
</Text>
- ) : null}
- <Text style={{ fontSize: 10 }}>
- {items.map((sk) => sk.Tag?.label).filter(Boolean).join(" · ")}
- </Text>
- </View>
- ))}
- </View>
- ) : (
+ </View>
+ ))}
+ {row.length === 1 ? <View style={s.twoColRight} /> : null}
+ </View>
+ ));
+ })() : (
<Text style={{ fontSize: 10 }}>
{sorted.map((sk) => sk.Tag?.label).filter(Boolean).join(" · ")}
</Text>
diff --git a/src/components/profile/resume-pdf/styles/professional.styles.ts b/src/components/profile/resume-pdf/styles/professional.styles.ts
index b19dd37..e70ec5b 100644
--- a/src/components/profile/resume-pdf/styles/professional.styles.ts
+++ b/src/components/profile/resume-pdf/styles/professional.styles.ts
@@ -44,7 +44,7 @@ export const professionalStyles = StyleSheet.create({
contactLine: {
fontFamily: "Courier",
fontSize: 9,
- color: GRAY,
+ color: NEAR_BLACK,
marginBottom: 1,
},
thickRule: {
diff --git a/src/lib/ai/prompts/resume-import/system.ts b/src/lib/ai/prompts/resume-import/system.ts
index b8b1138..66580e7 100644
--- a/src/lib/ai/prompts/resume-import/system.ts
+++ b/src/lib/ai/prompts/resume-import/system.ts
@@ -9,10 +9,24 @@ CRITICAL SECURITY RULES:
Parse the resume and return:
- contactInfo: firstName, lastName, headline, email, phone, address
- summary: professional summary paragraph (plain text)
+- skills: technical and professional skills, grouped into categories
- experience: work history entries with company, title, location, dates, description
- education: academic history with institution, degree, field, location, dates
- certifications: licenses and certifications with title, organization, dates, URL
-- unrecognizedSections: section names whose content cannot be mapped to any of the above fields (e.g. Skills, Projects, Publications, Volunteer Work, Awards). Do NOT include sections whose content was successfully parsed into contactInfo, summary, experience, education, or certifications — even if the heading combines multiple categories (e.g. "Education & Certifications" or "Experience & Projects").
+- unrecognizedSections: section names whose content cannot be mapped to any of the above fields (e.g. Projects, Publications, Volunteer Work, Awards). Do NOT include sections whose content was successfully parsed into contactInfo, summary, experience, education, certifications, or skills — even if the heading combines multiple categories (e.g. "Education & Certifications" or "Experience & Projects").
+
+SKILLS RULES:
+- skills is an object with a "categories" array.
+- Each category has an optional "label" (the sub-heading, e.g. "Languages",
+ "Frameworks", "Tools") and a "skills" array of individual skill name strings.
+- If the resume lists skills under named sub-groups, use one category per group
+ with its heading as the label.
+- If skills are listed as a single flat list with no sub-groups, return one
+ category with an empty/omitted label and all skills in its "skills" array.
+- Split comma-, slash-, or bullet-separated lists into individual skill strings.
+ e.g. "JavaScript, TypeScript, React" -> ["JavaScript", "TypeScript", "React"].
+- Do NOT invent skills. Only include skills explicitly listed in the document.
+- If the resume has no skills section, return skills with an empty categories array.
CONTACT INFO RULES:
- Split the candidate's full name into firstName and lastName. Always populate
diff --git a/src/models/resumeImport.schema.ts b/src/models/resumeImport.schema.ts
index 1e8d6af..669e81d 100644
--- a/src/models/resumeImport.schema.ts
+++ b/src/models/resumeImport.schema.ts
@@ -44,9 +44,24 @@ export const ImportCertificationSchema = z.object({
confidence,
});
+// A group of related skills, optionally under a category heading.
+// Skill names are plain strings; they resolve to shared Tags on import.
+export const ImportSkillCategorySchema = z.object({
+ label: z.string().optional(),
+ skills: z.array(z.string()).catch([]).default([]),
+});
+
+export const ImportSkillsSchema = z.object({
+ categories: z.array(ImportSkillCategorySchema).catch([]).default([]),
+ confidence,
+});
+
export const ResumeImportSchema = z.object({
contactInfo: ImportContactInfoSchema.optional(),
summary: z.string().catch(""),
+ // Skills before experience so it streams (and renders) early — long verbatim
+ // experience bullets can exhaust a model's output budget before the end.
+ skills: ImportSkillsSchema.optional(),
experience: z.array(ImportExperienceSchema).default([]),
education: z.array(ImportEducationSchema).default([]),
certifications: z.array(ImportCertificationSchema).default([]),
@@ -69,3 +84,4 @@ export type ImportContactInfo = z.infer<typeof ImportContactInfoSchema>;
export type ImportExperience = z.infer<typeof ImportExperienceSchema>;
export type ImportEducation = z.infer<typeof ImportEducationSchema>;
export type ImportCertification = z.infer<typeof ImportCertificationSchema>;
+export type ImportSkills = z.infer<typeof ImportSkillsSchema>;
diff --git a/src/utils/skillImport.utils.ts b/src/utils/skillImport.utils.ts
new file mode 100644
index 0000000..779f270
--- /dev/null
+++ b/src/utils/skillImport.utils.ts
@@ -0,0 +1,39 @@
+export type NormalizedSkillCategory = { label?: string; skills: string[] };
+
+// Skills arrive in varied shapes across models/partials: the documented
+// { categories: [{ label, skills }] }, a bare category array, or a flat list of
+// skill strings (optionally { name } objects). Normalize all of them to
+// categories of non-empty strings so the import card renders regardless of shape.
+export function extractSkillCategories(
+ raw: unknown,
+): NormalizedSkillCategory[] {
+ if (!raw) return [];
+
+ const toSkillStrings = (arr: unknown): string[] =>
+ (Array.isArray(arr) ? arr : [])
+ .map((s) =>
+ typeof s === "string"
+ ? s
+ : typeof (s as any)?.name === "string"
+ ? (s as any).name
+ : "",
+ )
+ .map((s) => s.trim())
+ .filter(Boolean);
+
+ // Flat list of skill strings -> single unlabeled category
+ if (Array.isArray(raw) && raw.every((x) => typeof x === "string")) {
+ const skills = toSkillStrings(raw);
+ return skills.length ? [{ skills }] : [];
+ }
+
+ const cats = Array.isArray(raw) ? raw : (raw as any).categories;
+ if (!Array.isArray(cats)) return [];
+
+ return cats
+ .map((cat) => ({
+ label: typeof cat?.label === "string" ? cat.label : undefined,
+ skills: toSkillStrings(cat?.skills),
+ }))
+ .filter((c) => c.skills.length > 0);
+}