Score roles per search agent, and run pull into extract, embed and score
embed stores one vector per open role; score rates every open role for every enabled agent from require and prefer gates, fit against the agent's intent, recency and company affinity, keeping gated rows with a reason. Schema v3 adds vectors and the cached intent vector. The page gets an agent order, the score on each row, and an Agents tab. Two starter agents in roles.yaml are imported once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4dfb8831aa
commit
bc60324fab
22 files changed
+1457
-44
No files matched your search
@@ -159,6 +159,40 @@ button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible
|
||||
}
|
||||
|
||||
.role.muted { opacity: .55; }
|
||||
.role.gated { opacity: .7; }
|
||||
.show-muted[hidden] { display: none; }
|
||||
.role-score.badge:empty { display: none; }
|
||||
.role-score.badge { color: var(--signal); border-color: var(--signal-weak); font-variant-numeric: tabular-nums; }
|
||||
.role-gated { color: var(--mute); font-size: .85rem; }
|
||||
|
||||
/* ---------------------------------------------------------------- agents */
|
||||
|
||||
.agents { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
|
||||
.agent {
|
||||
display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
|
||||
background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: .5rem .75rem;
|
||||
}
|
||||
.agent-meta { color: var(--faint); font-size: .85rem; flex: 1 1 12rem; }
|
||||
.agent-form {
|
||||
display: flex; flex-direction: column; gap: .6rem; max-width: 44rem;
|
||||
background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: .75rem 1rem;
|
||||
}
|
||||
.agent-form h2 { font-size: 1rem; margin: 0; }
|
||||
.agent-form label { display: flex; flex-direction: column; gap: .2rem; font-size: .9rem; }
|
||||
.agent-form label.inline { flex-direction: row; align-items: center; gap: .4rem; }
|
||||
.agent-form input[type="text"], .agent-form textarea, .agent-form input[type="number"] {
|
||||
font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--rule);
|
||||
border-radius: 4px; padding: .35rem .5rem; width: 100%;
|
||||
}
|
||||
.agent-form textarea { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .85rem; }
|
||||
.agent-form .hint { color: var(--faint); font-size: .8rem; overflow-wrap: anywhere; }
|
||||
.weights { display: flex; gap: .75rem; flex-wrap: wrap; border: 1px solid var(--rule); border-radius: 4px; }
|
||||
.weights label { flex: 1 1 6rem; }
|
||||
.agent-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
|
||||
.agent-actions button, .agent button {
|
||||
background: var(--bg); border: 1px solid var(--rule); border-radius: 4px; padding: .3rem .8rem; cursor: pointer;
|
||||
}
|
||||
.agent-actions button.primary { background: var(--signal); border-color: var(--signal); color: #fff; }
|
||||
|
||||
/* ------------------------------------------------------------ applications */
|
||||
|
||||
|
||||
+161
-3
@@ -1,5 +1,5 @@
|
||||
// roledesk's page: the filter bar, the role list, the tracker, and the tab
|
||||
// switch between them. The template renders an empty shell (see index.html);
|
||||
// roledesk's page: the filter bar, the role list, the tracker, the search
|
||||
// agents, and the tab switch between them. The template renders an empty shell (see index.html);
|
||||
// everything on screen comes from the API, and every action — Save, an
|
||||
// affinity click, a status change — is a fetch from here, not a form post.
|
||||
"use strict";
|
||||
@@ -12,6 +12,8 @@ let companies = new Map();
|
||||
let trackedByRole = new Map();
|
||||
/** @type {object[]} the last /api/roles response, already muted-filtered by the server */
|
||||
let roles = [];
|
||||
/** @type {object[]} every search agent, from /api/agents */
|
||||
let agents = [];
|
||||
|
||||
const $ = (sel, root = document) => root.querySelector(sel);
|
||||
const $$ = (sel, root = document) => Array.from(root.querySelectorAll(sel));
|
||||
@@ -42,7 +44,9 @@ function initTabs() {
|
||||
const name = tab.dataset.tab;
|
||||
$("#roles-view").hidden = name !== "roles";
|
||||
$("#applications-view").hidden = name !== "applications";
|
||||
$("#agents-view").hidden = name !== "agents";
|
||||
if (name === "applications") loadApplications();
|
||||
if (name === "agents") loadAgents();
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -64,6 +68,11 @@ function filterParams() {
|
||||
if (remote) params.set("remote", remote);
|
||||
if (days) params.set("days", days);
|
||||
if ($("#f-show-muted").checked) params.set("show_muted", "true");
|
||||
const agent = $("#f-agent").value;
|
||||
if (agent) {
|
||||
params.set("agent", agent);
|
||||
if ($("#f-gated").checked) params.set("gated", "1");
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
@@ -104,6 +113,13 @@ function renderRoles() {
|
||||
node.querySelector(".role-remote").textContent = role.remote || "";
|
||||
node.querySelector(".role-function").textContent = role.function || "";
|
||||
node.querySelector(".role-age").textContent = relativeAge(role.first_seen);
|
||||
if (role.score !== null && role.score !== undefined) {
|
||||
const badge = node.querySelector(".role-score");
|
||||
badge.textContent = role.gated_reason ? "gated" : role.score.toFixed(2);
|
||||
badge.title = "Score for the selected agent";
|
||||
node.querySelector(".role-gated").textContent = role.gated_reason || "";
|
||||
if (role.gated_reason) li.classList.add("gated");
|
||||
}
|
||||
|
||||
node.querySelector(".affinity").replaceWith(
|
||||
affinityControl(role.company_key, company ? company.affinity : 0));
|
||||
@@ -260,6 +276,140 @@ async function setStatus(id, status) {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- agents
|
||||
|
||||
async function loadAgents() {
|
||||
agents = await api("/api/agents");
|
||||
renderAgentSelect();
|
||||
renderAgents();
|
||||
}
|
||||
|
||||
// The filter bar's order: "Newest", or one agent's score. Keeps the current
|
||||
// choice when the list is refreshed, unless that agent is gone.
|
||||
function renderAgentSelect() {
|
||||
const select = $("#f-agent");
|
||||
const current = select.value;
|
||||
select.replaceChildren(new Option("Newest", ""));
|
||||
for (const agent of agents) {
|
||||
const label = agent.enabled ? agent.name : `${agent.name} (off)`;
|
||||
select.appendChild(new Option(label, String(agent.id)));
|
||||
}
|
||||
select.value = agents.some((a) => String(a.id) === current) ? current : "";
|
||||
$("#show-gated").hidden = !select.value;
|
||||
}
|
||||
|
||||
function renderAgents() {
|
||||
const list = $("#agents-list");
|
||||
list.replaceChildren();
|
||||
for (const agent of agents) {
|
||||
const li = document.createElement("li");
|
||||
li.className = "agent";
|
||||
const name = document.createElement("strong");
|
||||
name.textContent = agent.name;
|
||||
const meta = document.createElement("span");
|
||||
meta.className = "agent-meta";
|
||||
const gates = agent.gates.map((g) => `${g.mode} ${g.field}`).join(", ") || "no gates";
|
||||
meta.textContent = `${agent.enabled ? "" : "off · "}${gates}`;
|
||||
const edit = document.createElement("button");
|
||||
edit.type = "button";
|
||||
edit.textContent = "Edit";
|
||||
edit.addEventListener("click", () => fillAgentForm(agent));
|
||||
li.append(name, meta, edit);
|
||||
list.appendChild(li);
|
||||
}
|
||||
$("#agents-count").textContent = `${agents.length} agent${agents.length === 1 ? "" : "s"}`;
|
||||
}
|
||||
|
||||
function fillAgentForm(agent) {
|
||||
$("#agent-form-title").textContent = agent ? `Edit ${agent.name}` : "New agent";
|
||||
$("#a-id").value = agent ? String(agent.id) : "";
|
||||
$("#a-name").value = agent ? agent.name : "";
|
||||
$("#a-intent").value = agent ? agent.intent : "";
|
||||
$("#a-gates").value = JSON.stringify(agent ? agent.gates : [], null, 2);
|
||||
const weights = agent ? agent.weights : { fit: 0.6, recency: 0.2, affinity: 0.2 };
|
||||
$("#a-fit").value = weights.fit;
|
||||
$("#a-recency").value = weights.recency;
|
||||
$("#a-affinity").value = weights.affinity;
|
||||
$("#a-enabled").checked = agent ? agent.enabled : true;
|
||||
$("#a-delete").hidden = !agent;
|
||||
$("#agent-status").textContent = "";
|
||||
}
|
||||
|
||||
async function saveAgent(event) {
|
||||
event.preventDefault();
|
||||
const status = $("#agent-status");
|
||||
let gates;
|
||||
try {
|
||||
gates = JSON.parse($("#a-gates").value || "[]");
|
||||
} catch (err) {
|
||||
status.textContent = `Gates are not valid JSON: ${err.message}`;
|
||||
return;
|
||||
}
|
||||
const id = $("#a-id").value;
|
||||
const body = {
|
||||
name: $("#a-name").value.trim(),
|
||||
intent: $("#a-intent").value,
|
||||
gates,
|
||||
weights: {
|
||||
fit: Number($("#a-fit").value),
|
||||
recency: Number($("#a-recency").value),
|
||||
affinity: Number($("#a-affinity").value),
|
||||
},
|
||||
enabled: $("#a-enabled").checked,
|
||||
};
|
||||
if (id) body.id = Number(id);
|
||||
try {
|
||||
const saved = await api("/api/agents", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
await loadAgents();
|
||||
fillAgentForm(saved);
|
||||
await rescore(status);
|
||||
} catch (err) {
|
||||
status.textContent = err.message;
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteAgent() {
|
||||
const id = $("#a-id").value;
|
||||
if (!id || !confirm("Delete this agent and its scores?")) return;
|
||||
try {
|
||||
await api(`/api/agents/${encodeURIComponent(id)}`, { method: "DELETE" });
|
||||
fillAgentForm(null);
|
||||
await loadAgents();
|
||||
await loadRoles();
|
||||
} catch (err) {
|
||||
$("#agent-status").textContent = err.message;
|
||||
}
|
||||
}
|
||||
|
||||
// Start the `score` job and refetch the roles once it has finished, so the
|
||||
// order on the Roles tab is the saved agent's.
|
||||
async function rescore(status) {
|
||||
status.textContent = "Saved. Scoring…";
|
||||
const job = await api("/api/jobs", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ kind: "score", payload: {} }),
|
||||
});
|
||||
for (let i = 0; i < 300; i += 1) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
const snapshot = await api("/api/jobs");
|
||||
const busy = [...snapshot.running, ...snapshot.queued].some((j) => j.id === job.id);
|
||||
if (!busy) {
|
||||
const done = snapshot.recent.find((j) => j.id === job.id);
|
||||
status.textContent = done && done.state !== "done"
|
||||
? `Scoring ${done.state}: ${done.error || ""}`
|
||||
: "Saved and scored.";
|
||||
await loadRoles();
|
||||
return;
|
||||
}
|
||||
}
|
||||
status.textContent = "Saved. Scoring is still running; see Jobs below.";
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------- init
|
||||
|
||||
async function loadCompanies() {
|
||||
@@ -269,7 +419,7 @@ async function loadCompanies() {
|
||||
|
||||
async function init() {
|
||||
initTabs();
|
||||
await Promise.all([loadCompanies(), loadApplications()]);
|
||||
await Promise.all([loadCompanies(), loadApplications(), loadAgents()]);
|
||||
await loadRoles();
|
||||
|
||||
const refetch = debounce(loadRoles, 300);
|
||||
@@ -280,6 +430,14 @@ async function init() {
|
||||
$("#f-remote").addEventListener("change", loadRoles);
|
||||
$("#f-days").addEventListener("change", loadRoles);
|
||||
$("#f-show-muted").addEventListener("change", loadRoles);
|
||||
$("#f-agent").addEventListener("change", () => {
|
||||
$("#show-gated").hidden = !$("#f-agent").value;
|
||||
loadRoles();
|
||||
});
|
||||
$("#f-gated").addEventListener("change", loadRoles);
|
||||
$("#agent-form").addEventListener("submit", saveAgent);
|
||||
$("#a-new").addEventListener("click", () => fillAgentForm(null));
|
||||
$("#a-delete").addEventListener("click", deleteAgent);
|
||||
$("#filters").addEventListener("submit", (e) => e.preventDefault());
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user