diff --git a/app/static/agents.js b/app/static/agents.js index fc7542c..74a1836 100644 --- a/app/static/agents.js +++ b/app/static/agents.js @@ -18,6 +18,12 @@ * narrow what big boards read with the wide reach send (app/jobs/reach.py). * The card says them in a line of their own, or that boards send every role. * + * The CV fieldset holds what the judge stage reads a role against: the CV as + * text (typed, or read from a .md/.txt file by the browser), the languages it + * states as rows of a code and a level, and the avoid and must-have texts. + * Every save sends all four, and the card's switch re-posts the row as the + * server gave it, so neither drops them. + * * Every request goes through `api()` from app.js, so a failure is one toast * carrying the server's own sentence. */ @@ -31,7 +37,12 @@ // What the model reads after a pull, per agent: the best `extract_top` // roles scoring at least `extract_min` get their gate columns filled, the // best `summarise_top` at `summarise_min` or more a summary. - const DEFAULT_LIMITS = { extract_top: 500, extract_min: 0.55, summarise_top: 30, summarise_min: 0.65 }; + const DEFAULT_LIMITS = { extract_top: 500, extract_min: 0.55, summarise_top: 30, summarise_min: 0.65, + judge_top: 150, judge_min: 0.55 }; + // The levels of a language, the order of the server's ladder, and how big a + // CV file the browser reads into the box. + const LEVELS = ["basic", "conversational", "professional", "fluent", "native"]; + const MAX_CV_BYTES = 1_000_000; const NEW = "new"; // Europe as the starter agents spell it (static/remote.js). const EUROPE = rh.EUROPE; @@ -42,7 +53,7 @@ /** @type {object[]} every agent, as the server lists them */ let agents = []; - /** @type {Object} whether extract and summarise run, from + /** @type {Object} whether extract, summarise and judge run, from * `/api/stages`; empty when that did not answer, and then a card says * nothing about them */ let stageOn = {}; @@ -93,6 +104,13 @@ regionNames = null; } + let languageNames = null; + try { + languageNames = new Intl.DisplayNames(["en"], { type: "language" }); + } catch (err) { + languageNames = null; + } + // A country code in words, the code itself where the browser has no name. function countryName(code) { if (code === "EU") return "anywhere in Europe"; @@ -278,6 +296,7 @@ const clauses = [ ["extract", `reads ${l.extract_top} at ${l.extract_min}`, `${l.extract_top} at ${l.extract_min}`], ["summarise", `summarises ${l.summarise_top} at ${l.summarise_min}`, `${l.summarise_top} at ${l.summarise_min}`], + ["judge", `judges ${l.judge_top} at ${l.judge_min}`, `${l.judge_top} at ${l.judge_min}`], ]; clauses.forEach(([name, on, would], i) => { if (i) p.append(" ยท "); @@ -322,6 +341,7 @@ div.appendChild(el("p", "agent-weights", weightsLine(row))); div.appendChild(limitsLine(row)); div.appendChild(termsLine(row)); + div.appendChild(cvLine(row)); const actions = el("div", "agent-card-actions"); const edit = el("button", "secondary", "Edit"); @@ -476,6 +496,15 @@ : "Big boards send every role: no fetch terms."); } + // The CV on a card: whether the judge has one to read roles against, and + // the languages it states, as "da fluent, en native". + function cvLine(row) { + const langs = row.cv_languages || []; + const said = langs.length ? `Languages: ${langs.map((l) => `${l.language} ${l.level}`).join(", ")}.` : "No languages stated."; + const has = Boolean((row.cv_text || "").trim()); + return el("p", "agent-terms", has ? `CV set. ${said}` : `No CV, so roles are not judged against one. ${said}`); + } + // A prompt as a row: its name and Remove on a line, its text under them. function promptRow(prompt, remove) { const row = el("div", "prompt-row"); @@ -507,6 +536,34 @@ return box; } + // A language as a row, after the rule rows: a code, a level, Remove. The + // code is two letters, which the server turns into the language; its name + // is the row's title where the browser knows it. + function languageRow(language, remove) { + const row = el("div", "rule-row"); + const code = el("input"); + code.type = "text"; + code.maxLength = 2; + code.spellcheck = false; + code.placeholder = "en"; + code.value = language.language; + code.setAttribute("aria-label", "Language code"); + const level = select(LEVELS.map((l) => [l, l]), language.level, "Level"); + const named = () => { + try { + code.title = (languageNames && languageNames.of(code.value.trim().toLowerCase())) || ""; + } catch (err) { + code.title = ""; + } + }; + code.addEventListener("input", named); + named(); + const drop = linky("Remove"); + drop.addEventListener("click", () => remove(row)); + row.append(code, level, drop); + return { node: row, read: () => ({ language: code.value.trim().toLowerCase(), level: level.value }) }; + } + // A gate as a row: field, mode, values, the weight while it is prefer, and // Remove. Values untouched since the load are sent as they came, so a // value with a comma in it survives a save. @@ -579,6 +636,53 @@ changed(f); }); + // The CV: its text, the file that can fill it, the languages as rows and + // the two soft texts. All four are always sent, so what is cleared here + // is cleared in the store. + const cvText = $("#a-cv-text", f); + cvText.value = row ? row.cv_text || "" : ""; + $("#a-avoid-text", f).value = row ? row.avoid_text || "" : ""; + $("#a-must-text", f).value = row ? row.must_text || "" : ""; + const languages = []; + const dropLanguage = (node) => { + languages.splice(languages.findIndex((l) => l.node === node), 1); + node.remove(); + changed(f); + }; + const addLanguage = (language) => { + const entry = languageRow(language, dropLanguage); + languages.push(entry); + $("#a-cv-languages", f).appendChild(entry.node); + return entry; + }; + (row ? row.cv_languages || [] : []).forEach(addLanguage); + $("#a-add-language", f).addEventListener("click", () => { + $("input", addLanguage({ language: "", level: "professional" }).node).focus(); + changed(f); + }); + $("#a-cv-file", f).addEventListener("change", (event) => readCvFile(event.target, cvText, f)); + $("#a-suggest-languages", f).addEventListener("click", async (event) => { + const button = event.currentTarget; + if (!cvText.value.trim()) { + window.toast.error("Paste a CV first."); + return; + } + button.disabled = true; + try { + const { languages: found } = await api("/api/agents/cv-languages", { + method: "POST", body: { cv_text: cvText.value }, + }); + languages.splice(0).forEach((l) => l.node.remove()); + found.forEach(addLanguage); + changed(f); + if (!found.length) window.toast.info("The CV states no language."); + } catch (err) { + // `api()` toasted the server's sentence; the rows stay as they were. + } finally { + button.disabled = false; + } + }); + const { where, rest } = rh.distribute(row ? row.gates : []); const scope = $("#a-scope", f); scope.value = where.scope.kind; @@ -669,10 +773,17 @@ $("#a-extract-min", f).value = limits.extract_min; $("#a-summarise-top", f).value = limits.summarise_top; $("#a-summarise-min", f).value = limits.summarise_min; + $("#a-judge-top", f).value = limits.judge_top; + $("#a-judge-min", f).value = limits.judge_min; $("#a-delete", f).hidden = !row; f.addEventListener("input", () => { f.dataset.dirty = "true"; view(); }); f.addEventListener("change", view); - f.addEventListener("submit", (event) => save(event, row, () => prompts.map((p) => p.read()), gates, terms.values)); + f.addEventListener("submit", (event) => save(event, row, { + prompts: () => prompts.map((p) => p.read()), + gates, + terms: terms.values, + languages: () => languages.map((l) => l.read()), + })); $("#a-cancel", f).addEventListener("click", () => { close(); render(); }); $("#a-delete", f).addEventListener("click", () => row && removeAgent(row)); div.appendChild(f); @@ -718,18 +829,43 @@ : "No search agents yet. New agent describes one."; } - // `readPrompts`, `readGates` and `readTerms` are the form's rows and chips - // as the API takes them. - // A prompt with neither name nor text is an empty row, left out. - async function save(event, row, readPrompts, readGates, readTerms) { + // Read a .md or .txt file into the CV box, replacing what is there. The file + // stays in the browser; Save sends the text like any typed one. + function readCvFile(input, box, f) { + const file = input.files && input.files[0]; + input.value = ""; + if (!file) return; + if (file.size > MAX_CV_BYTES) { + window.toast.error(`${file.name} is over 1 MB, too big for a CV. Paste the part that matters.`); + return; + } + const reader = new FileReader(); + reader.onload = () => { + box.value = String(reader.result || ""); + changed(f); + }; + reader.onerror = () => window.toast.error(`Could not read ${file.name}.`); + reader.readAsText(file); + } + + // `read` holds the form's rows and chips as the API takes them: `prompts`, + // `gates`, `terms` and `languages`. + // A prompt with neither name nor text is an empty row, left out, as is a + // language row with no code. + async function save(event, row, read) { event.preventDefault(); const f = event.target; - const prompts = readPrompts().filter((p) => p.name || p.text.trim()); + const prompts = read.prompts().filter((p) => p.name || p.text.trim()); if (prompts.some((p) => !p.name)) { window.toast.error("Every prompt needs a name."); return; } - const gates = readGates(); + const cvLanguages = read.languages().filter((l) => l.language); + if (cvLanguages.some((l) => !/^[a-z]{2}$/.test(l.language))) { + window.toast.error("A language is a two-letter code such as en or da."); + return; + } + const gates = read.gates(); const body = { name: $("#a-name", f).value.trim(), prompts, @@ -745,8 +881,14 @@ extract_min: Number($("#a-extract-min", f).value), summarise_top: Number($("#a-summarise-top", f).value), summarise_min: Number($("#a-summarise-min", f).value), + judge_top: Number($("#a-judge-top", f).value), + judge_min: Number($("#a-judge-min", f).value), }, - fetch_terms: readTerms(), + fetch_terms: read.terms(), + cv_text: $("#a-cv-text", f).value, + cv_languages: cvLanguages, + avoid_text: $("#a-avoid-text", f).value, + must_text: $("#a-must-text", f).value, // Saving an agent means it is wanted, so a new one starts on; the // card's switch is where an existing one is switched. enabled: row ? row.enabled : true, diff --git a/app/templates/settings/agents.html b/app/templates/settings/agents.html index 592dbcf..c8a9e52 100644 --- a/app/templates/settings/agents.html +++ b/app/templates/settings/agents.html @@ -78,6 +78,27 @@ Separate terms with a comma or Enter: machine learning, data science is two terms, and machine learning is searched as one. A board then sends only roles with one of the terms anywhere in the ad, not only the title. Only applies to big boards read across Europe (All countries). Empty means no narrowing. +
+ Your CV + Optional. With a CV, the judge stage reads each of this agent's best roles against it and scores skills, experience and career, which Best CV match on Roles sorts by. A role is read at most once per change of the CV, the prompts or the texts below. The CV stays in this app and goes only to the model you set up. + + + A .md or .txt file replaces the text above. Nothing is uploaded: the browser reads it into the box. +
+ Languages you speak +
+
+ + + A two-letter code such as en or da, and how well. Roles that ask for a language you lack, or a level above yours, get a warning on Roles; a role that names one of yours as a plus gets a star. With none, no role is flagged. Suggest languages reads them from the CV with one model call and replaces the rows above; nothing is saved until Save. + + + Soft, read by the judge only: a role that breaks one of these scores low on career and the gap is named. Rules that must hold go under Where or Other rules instead. +
How much each counts @@ -91,8 +112,10 @@ + +
- Every pull scores every open role for free; these bound what the model then reads, per agent. The count is the backstop, the score the real stop. Fit is a level, the same in every run: a new role with the worst fit scores about 0.27, a perfect one about 0.87. An agent with no prompt feeds neither stage. + Every pull scores every open role for free; these bound what the model then reads, per agent. The count is the backstop, the score the real stop. Fit is a level, the same in every run: a new role with the worst fit scores about 0.27, a perfect one about 0.87. An agent with no prompt feeds neither extract nor summarise, and one with no CV feeds not the judge.
Advanced