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 match_job constants, input schema and result type

Khuram Niazeec822e75938
diff --git a/__tests__/agentChatRoute.spec.ts b/__tests__/agentChatRoute.spec.ts
index 9450ca8..aa9189a 100644
--- a/__tests__/agentChatRoute.spec.ts
+++ b/__tests__/agentChatRoute.spec.ts
@@ -51,7 +51,10 @@ import { getUserSettings } from "@/actions/userSettings.actions";
import { saveChatConversation } from "@/actions/agentChat.actions";
import { buildAgentTools } from "@/lib/agent/tools";
import { APP_CONSTANTS } from "@/lib/constants";
-import { AGENT_PASTE_PART_TYPE } from "@/models/agent.model";
+import {
+ AGENT_CHAT_TERMINAL_TOOLS,
+ AGENT_PASTE_PART_TYPE,
+} from "@/models/agent.model";
// signal is not optional on a real Request — the route composes the turn's
// abort signal from it so a client disconnect stops generation.
@@ -249,7 +252,8 @@ describe("POST /api/ai/chat", () => {
it("configures the loop bounds the design specifies", async () => {
await POST(req({ messages: [pasteMessage("posting")] }));
const args = streamArgs();
- expect(args.stopWhen).toHaveLength(3);
+ // stepCountIs plus one hasToolCall per terminal tool.
+ expect(args.stopWhen).toHaveLength(AGENT_CHAT_TERMINAL_TOOLS.length + 1);
expect(args.temperature).toBe(0.1);
expect(args.abortSignal).toBeDefined();
expect(args.providerOptions.ollama.options.num_ctx).toBe(APP_CONSTANTS.AGENT_CHAT_NUM_CTX);
diff --git a/src/lib/constants.ts b/src/lib/constants.ts
index f9352fe..ea1849a 100644
--- a/src/lib/constants.ts
+++ b/src/lib/constants.ts
@@ -127,6 +127,7 @@ export const APP_CONSTANTS = {
AGENT_CHAT_CREATED_VIA: "chat",
// Provenance on Resume.reviewData, alongside the MCP path's "mcp" marker.
AGENT_CHAT_REVIEW_SURFACE: "chat",
+ AGENT_CHAT_MATCH_SURFACE: "chat",
AGENT_CHAT_MAX_STEPS: 4,
AGENT_CHAT_MAX_STORED_MESSAGES: 50,
AGENT_CHAT_HISTORY_MESSAGES: 20,
diff --git a/src/models/agent.model.ts b/src/models/agent.model.ts
index f8fd510..e07a01a 100644
--- a/src/models/agent.model.ts
+++ b/src/models/agent.model.ts
@@ -1,5 +1,5 @@
import type { DescriptionCompleteness } from "@/models/job.model";
-import type { ResumeScores } from "@/models/ai.schemas";
+import type { JobMatchScores, ResumeScores } from "@/models/ai.schemas";
// Dependency-free by design: client components import these types, so nothing
// here may pull in Prisma or server-only code. Type-only imports are erased.
@@ -105,9 +105,34 @@ export type AgentReviewResumeResult =
| { status: "unreadable"; title: string; reason: string }
| { status: "generation_failed"; title: string; reason: string };
+// What match_job returns to the model AND to the result card. Neither the
+// resume text nor the job description is here — follow-ups answer from `body`.
+export type AgentMatchJobResult =
+ | {
+ status: "ok";
+ jobId: string;
+ jobTitle: string;
+ company: string;
+ resumeId: string;
+ resumeTitle: string;
+ scores: JobMatchScores;
+ body: string;
+ saved: boolean;
+ saveError?: string;
+ }
+ | { status: "no_job" }
+ | { status: "needs_selection"; resumes: { id: string; title: string }[] }
+ | { status: "no_resumes" }
+ | { status: "unreadable"; what: "job" | "resume"; title: string; reason: string }
+ | { status: "generation_failed"; jobTitle: string; reason: string };
+
// Tools that end the turn. The result card renders deterministically from
// structured fields, so a second generation just to narrate it is 10-30s of
// local inference for a sentence that could be wrong. A tool that runs its
// own generation MUST be listed here or a single turn can chain two of them
// and blow the turn timeout, discarding both.
-export const AGENT_CHAT_TERMINAL_TOOLS = ["add_job", "review_resume"] as const;
+export const AGENT_CHAT_TERMINAL_TOOLS = [
+ "add_job",
+ "review_resume",
+ "match_job",
+] as const;
diff --git a/src/models/agent.schema.ts b/src/models/agent.schema.ts
index 9c60f2a..791a18c 100644
--- a/src/models/agent.schema.ts
+++ b/src/models/agent.schema.ts
@@ -56,3 +56,12 @@ export const AgentReviewResumeSchema = z.object({
});
export type AgentReviewResumeInput = z.infer<typeof AgentReviewResumeSchema>;
+
+// No job field of any kind: match_job scores the job the user is viewing, and
+// the id comes from server-held page context. An id-shaped input would be an
+// IDOR surface the model could be talked into filling.
+export const AgentMatchJobSchema = z.object({
+ resumeTitle: z.string().optional().describe("The title of the resume to match against, as the user referred to it. Omit this entirely if the user did not name one — the app then uses the resume linked to the job, or their default resume."),
+});
+
+export type AgentMatchJobInput = z.infer<typeof AgentMatchJobSchema>;
diff --git a/src/models/ai.schemas.ts b/src/models/ai.schemas.ts
index 7667b5e..36ca3c4 100644
--- a/src/models/ai.schemas.ts
+++ b/src/models/ai.schemas.ts
@@ -64,6 +64,9 @@ export type JobMatchData = JobMatchScores & {
matchedAt?: string;
provider?: string;
model?: string;
+ // Which surface produced it. Optional: rows written before this existed
+ // simply do not have it, and MatchDetails ignores it.
+ surface?: string;
// Greenhouse-specific
prerankScore?: number; // raw lexical score (internal sort only; NOT shown as %)
analyzed?: boolean; // true once LLM match has run (auto top-K or on-demand)