From a664427de2b06c47b9cf30a5db662192502fcb91 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Sun, 18 Oct 2026 06:39:48 +0000 Subject: [PATCH] feat(routines): graph workflows group topics under broader ones The Find what to tidy node gets a cluster kind: topics whose labels end in another topic's label go under it, and three or more with no broader topic that end in the same word go under a new topic for it. Ask the model checks each group, and Apply changes makes the sure ones and proposes the rest. Undoing a group takes its topics out from under the broader one, and deletes that topic when the group made it and nothing has used it since. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_018Nbf5G7PvMgThj8BbUPGT8 --- DEVLOG.md | 2 +- README.md | 4 +- docs/processing.md | 19 +- docs/requirements.md | 2 +- docs/topics.md | 3 +- fastapi_backend/app/api/v1/routes/routines.py | 2 +- fastapi_backend/app/domain/organize.py | 207 ++++++++++++++++-- fastapi_backend/app/schemas/routines.py | 9 +- fastapi_backend/tests/api/test_routines.py | 57 +++++ fastapi_backend/tests/fake_llm.py | 6 +- .../__tests__/graph-changes.test.tsx | 17 ++ .../app/openapi-client/types.gen.ts | 36 ++- .../components/routines/graph-changes.tsx | 84 +++++-- .../components/workflows/node-settings.tsx | 1 + .../components/workflows/workflow-editor.tsx | 4 +- .../components/workflows/workflow-model.ts | 8 +- nextjs-frontend/openapi.json | 73 +++++- 17 files changed, 474 insertions(+), 60 deletions(-) diff --git a/DEVLOG.md b/DEVLOG.md index ea7965f35..b820723d9 100644 --- a/DEVLOG.md +++ b/DEVLOG.md @@ -603,7 +603,7 @@ Todo: - [x] API tests - [x] Web app: Routines page, run history, proposed changes review, graph nodes on the canvas - [ ] Notify (Matterbridge/webhooks thread) when a run fails or leaves proposals -- [ ] More graph nodes: retype entities, hide noise, cluster topics +- [x] More graph nodes: retype entities, hide noise, cluster topics (the candidates node's retype, hide and cluster kinds) - [ ] Routing rules (shared IMAP inbox → namespaces) slot in between sync and ingest ## 2026-10-02 · Workflow canvas diff --git a/README.md b/README.md index 22c1e7e5e..91953f5f9 100644 --- a/README.md +++ b/README.md @@ -171,8 +171,8 @@ listed under [In progress](#in-progress), and what comes next under [Planned](#p automation schedule and the backup in one list with when each runs next and last, to switch, re-time or run now, and agents do the same over the API and MCP. A Classify node in a workflow sorts an asset into labels, content types or topics, acting only on a sure answer, and an Entity filter node keeps the entities you want. Graph workflows tidy the - entities on a routine: look-alikes to merge or link, types the rules now read differently, and noise to hide, making - the changes they're sure of and proposing the rest, each one undoable. Anything that reaches outside Lens or changes + entities on a routine: look-alikes to merge or link, types the rules now read differently, noise to hide and topics + to group under a broader one, making the changes they're sure of and proposing the rest, each one undoable. Anything that reaches outside Lens or changes more than what set it off asks first, until you let it run on its own: on the Approvals page or, for a change inside Lens, with a yes in the chat it told you in; agents can decline an approval but never give one. Each automation has limits and budgets, and agents make, try and run them over MCP and in the assistant, or draft one from a sentence. An diff --git a/docs/processing.md b/docs/processing.md index 29d6210f4..4979b6b95 100644 --- a/docs/processing.md +++ b/docs/processing.md @@ -816,13 +816,18 @@ A workflow's scope is assets (above), the graph, or an event: an automation's wo - **Noise** (hide): entities with no letters or one letter, made of filler words (*Okay so*; not acronyms like *US*), or a phrase rather than a name (95%; filler words are 70% when the entity has a type other than Term), and terms said only once (50%, below the default 70%). Entities someone showed again are left alone. + - **Topics to group** (cluster): a namespace's topics that go under a broader topic: those whose labels end in + another topic's label (*Machine learning* and *Deep learning* under *Learning*, 85%), and three or more with no + broader topic that end in the same word, under a new topic for it (*Sales calls*, *Support calls* and *Team + calls* under *Calls*, 70% for three, up to 85%). Topics have no types, so *Only these types* doesn't apply. Anything already proposed, dismissed or undone is skipped too, so a run never redoes what someone took back. - **Ask the model** (`llm_judge`) shows the model each candidate with lines where the names appear and asks, a kind at a time: whether a pair is the same thing and which name to keep, what type a name is (from the namespace's - types), or whether it is noise; and how sure it is. Each gets a `verdict`, with `agree` true when the change + types), whether it is noise, or whether a group's topics go under its broader topic (with a better label for a new + one, and which topics to leave out); and how sure it is. Each gets a `verdict`, with `agree` true when the change should be made (and, for pairs, `same`). - **Filter** keeps the candidates that pass a test, e.g. `verdict.agree` (or `verdict.same`) equals true. -- **Apply changes** merges, links, retypes or hides the candidates whose confidence (the model's, else the rules') is +- **Apply changes** merges, links, retypes, hides or groups the candidates whose confidence (the model's, else the rules') is at least *apply above* (at most *max apply* a run) and proposes the rest. Without *apply above* it only proposes. A candidate the model said no to is skipped. @@ -832,11 +837,13 @@ on, or Run now with *propose only* first to see what it would do. Every change is recorded (`GET /api/v1/graph-changes`), and shows in Routines › Proposed changes: editors of the namespaces involved accept or dismiss proposals (dismissing a pair says the two are different; dismissing a type or a -hide leaves the entity as it is; neither is suggested again), choose another type when accepting a retype (`to`), and -undo applied changes; an admin can undo everything a run applied at once (`POST /api/v1/routine-runs/{id}/undo`). +hide or a group leaves things as they are; neither is suggested again), choose another type when accepting a retype +(`to`) or another label for a group's new broader topic (`label`), and undo applied changes; an admin can undo everything a run applied at once (`POST /api/v1/routine-runs/{id}/undo`). Merges are undone exactly as from an entity's page; a type or a hide someone has changed since stays as they left it. -Agents do the same through the API, and `undo_graph_change` over MCP. To tidy types and noise, add a workflow that -looks for wrong types and noise (no built-in workflow does, so nothing changes until you add one). +Undoing a group takes its topics out from under the broader topic, and deletes that topic when the group made it and +nothing uses it since (a recording, a narrower or related topic). +Agents do the same through the API, and `undo_graph_change` over MCP. To tidy types, noise and topics, add a workflow +that looks for them (no built-in workflow does, so nothing changes until you add one). ### Publishing from the graph diff --git a/docs/requirements.md b/docs/requirements.md index facfd4a70..857a470b3 100644 --- a/docs/requirements.md +++ b/docs/requirements.md @@ -191,7 +191,7 @@ request, to another check that proves the same thing; loosening a requirement or | A Classify node in workflows chooses from labels, content types or topics, and acting on a sure answer keeps something | [test_classify.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_classify.py) `test_a_workflow_classifies`; [workflow-flow.test.ts](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/workflow-flow.test.ts) `chooses from labels, content types or topics, and acting on a sure answer keeps something` | | An Entity filter node keeps a list's entities by type, stop list, length, pattern or how often they're said | [test_flow.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_flow.py) `test_entity_filter_keeps_the_entities_asked_for`; [workflow-flow.test.ts](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/workflow-flow.test.ts) `an entity filter says what it keeps and refuses lowercase types` | | Routines on a schedule | [test_routines.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_routines.py) `test_routines_are_checked_and_run_when_due`, `test_schedules`; [journeys.mjs](https://github.com/adeelahmad/lense/blob/main/ci/clicks/journeys.mjs) `routine-create`; [baseline.json](https://github.com/adeelahmad/lense/blob/main/ci/clicks/baseline.json) `routine-create` ≤ 2 clicks | -| Graph workflows find look-alikes to merge or link, wrong types and noise, make the sure changes and propose the rest, each undoable and not made again once taken back | [test_routines.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_routines.py) `test_graph_workflows_organise_entities`, `test_rules_read_types_and_noise`, `test_graph_workflows_retype_and_hide`; [graph-changes.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/graph-changes.test.tsx) `say a type change in words and make it` | +| Graph workflows find look-alikes to merge or link, wrong types, noise and topics to group, make the sure changes and propose the rest, each undoable and not made again once taken back | [test_routines.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_routines.py) `test_graph_workflows_organise_entities`, `test_rules_read_types_and_noise`, `test_graph_workflows_retype_and_hide`, `test_graph_workflows_group_topics`; [graph-changes.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/graph-changes.test.tsx) `say a type change in words and make it`, `show a group of topics under a new broader one` | | Everything that runs on a clock (routines, automations' schedule and at triggers, the backup) in one Schedules list, switched, re-timed and run from it, by people and by agents over the API and MCP | [test_schedules.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_schedules.py) `test_one_list_holds_every_routine_automation_schedule_and_the_backup`, `test_schedules_are_changed_switched_and_run_from_the_list`, `test_agents_list_change_and_run_schedules_over_mcp`; [schedules-page.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/schedules-page.test.tsx) `lists every routine, automation schedule and the backup, each linking to its own page`, `switches one off, runs one now and changes when one runs, from the list` | | Batch runs over a collection | [test_batches.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_batches.py) `test_collections_and_batches` | | Notifications to webhooks, Slack, Discord and Matterbridge | [test_notifications.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_notifications.py) `test_owners_manage_targets_and_a_test_is_signed`, `test_runs_that_end_are_sent_once_to_matterbridge` | diff --git a/docs/topics.md b/docs/topics.md index 9b3aa909e..b22e69f1a 100644 --- a/docs/topics.md +++ b/docs/topics.md @@ -17,7 +17,8 @@ a topic to edit it in a drawer: its labels, definition, broader and related topi assets about it, where suggested ones can be accepted or removed. **Merge** in the drawer opens a find box: type part of a label and pick (or press Enter) to merge that topic into this one at once. **Delete** deletes it at once. Both say what they did with **Undo** on the message, so there is no confirm step. Editors add topics at the top or -under another with **+**. +under another with **+**. A graph workflow can also group a flat vocabulary under broader topics on a routine, +proposing or making the groups it finds ([Organising the graph](processing.md#organising-the-graph)). An asset's **Entities** tab starts with its topics: editors add one from the vocabulary, take one off, or accept or dismiss a suggestion. An entity of type Term has **Make a topic** in its drawer. On the graph canvas topics are diff --git a/fastapi_backend/app/api/v1/routes/routines.py b/fastapi_backend/app/api/v1/routes/routines.py index f6ae2f43f..5fc8f15ee 100644 --- a/fastapi_backend/app/api/v1/routes/routines.py +++ b/fastapi_backend/app/api/v1/routes/routines.py @@ -159,7 +159,7 @@ def list_graph_changes( def accept_graph_change(cid: int, body: GraphChangeAccept, user: Writer, acl: Acl, db: Db) -> Ok: _change(db, acl, cid, "curate") with domain_errors(): - organize.accept(db, cid, user.email, body.keep, body.to) + organize.accept(db, cid, user.email, body.keep, body.to, body.label) auth.audit(db, user.as_audit(), "graph_change.accept", f"graph_change:{cid}") return Ok() diff --git a/fastapi_backend/app/domain/organize.py b/fastapi_backend/app/domain/organize.py index c1892503d..6e1d6d323 100644 --- a/fastapi_backend/app/domain/organize.py +++ b/fastapi_backend/app/domain/organize.py @@ -13,19 +13,26 @@ or an agent set are left as they are. - hide: entities that are noise: no letters, one letter, filler words ("Okay so"), a phrase rather than a name, or a term said only once. Entities someone showed again are left out. + - cluster: a namespace's topics to group under a broader one: those whose labels end in another topic's label + ("Machine learning", "Deep learning" under "Learning"), or several with no broader topic that end in the same word + ("Sales calls", "Support calls", "Team calls" under a new "Calls"). Candidates with a change already proposed, dismissed or undone are left out, so a run doesn't redo what someone took back. - `llm_judge`: asks the model, a batch at a time with lines where each name was said, about each candidate: whether a - pair is the same thing, what type a name is, or whether it is noise. Each gets a `verdict` {agree (make the change), - confidence, why; for pairs same and keep; for a retype the type}. -- `apply_changes`: makes the changes it is given (merges, links, new types, hides), or proposes them for someone to + pair is the same thing, what type a name is, whether it is noise, or whether topics go under a broader one. Each + gets a `verdict` {agree (make the change), confidence, why; for pairs same and keep; for a retype the type; for a + group a better label for a new broader topic and the topics to leave out}. +- `apply_changes`: makes the changes it is given (merges, links, new types, hides, groups), or proposes them for someone to accept. Only those whose confidence (the model's, else the rules') is at least `apply_above` are made, at most `max_apply` a run; without `apply_above` everything is proposed. Every change is recorded and can be undone, one by one or a whole run. -Each change is a `graph_change` row: {kind, pair (what it is about, to tell it again), a (the entity, or a pair's -first), b, keep, to (a retype's new type), spaces, reason, confidence, verdict, status (proposed, applied, dismissed, -undone), merge (the entity_merge id behind an applied merge), routine, run, workflow}. +Each change is a `graph_change` row: {kind, pair (what it is about, to tell it again), a (the entity, a pair's first, +or a group's broader topic {id (none for a new one), name}), b, keep, to (a retype's new type), topics (a group's +[{id, name, recordings}]), spaces, reason, confidence, verdict, status (proposed, applied, dismissed, undone), merge (the +entity_merge id behind an applied merge), parent, created, grouped (an applied group's broader topic, whether the +group made it, and the topics put under it), routine, run, workflow}. Topics aren't in the graph's history, so a group +is undone only from its change. """ from __future__ import annotations @@ -34,7 +41,7 @@ import re -from . import analyze, entities, entity_setup, graph_history, llm, name_types, store +from . import analyze, entities, entity_setup, graph_history, llm, name_types, notebook, store, topics R = store.R GRAPH_NODES = ("input", "pick", "condition", "merge", "candidates", "llm_judge", "filter", "apply_changes") @@ -46,7 +53,7 @@ "apply_changes": {"apply_above", "max_apply"}, } PAIRS = ("merge", "link") # kinds about two entities; the rest are about one -KINDS = (*PAIRS, "retype", "hide") +KINDS = (*PAIRS, "retype", "hide", "cluster") STATUSES = ("proposed", "applied", "dismissed", "undone") JUDGE_SCHEMA = { "type": "object", @@ -79,6 +86,7 @@ ONE_SCHEMA = { "retype": {"type": {"type": "string"}}, "hide": {"noise": {"type": "boolean"}}, + "cluster": {"agree": {"type": "boolean"}, "label": {"type": "string"}, "leave": {"type": "array", "items": {"type": "integer"}}}, } ONE_SYSTEM = { "retype": ( @@ -94,12 +102,19 @@ "words. Real people, organisations, products, places, events, works and topics are not noise, even when they " "are said once. Reply with JSON only." ), + "cluster": ( + "You organise the vocabulary of topics a knowledge graph's assets are about. For each numbered group, say " + "whether the topics listed go under the broader topic named (agree), as narrower kinds or parts of it; for a " + "new broader topic, a better label for it if there is one; the numbers of the topics that don't belong " + '(leave); how sure you are from 0 to 1; and why in a few words. Sharing a word is not enough: "Sales calls" ' + 'and "Cold calls" are calls, "Judgement calls" are not. Reply with JSON only.' + ), } def _one_schema(kind): item = {"item": {"type": "integer"}, **ONE_SCHEMA[kind], "confidence": {"type": "number"}, "why": {"type": "string"}} - need = ["item", *ONE_SCHEMA[kind], "confidence"] + need = ["item", "agree" if kind == "cluster" else next(iter(ONE_SCHEMA[kind])), "confidence"] return { "type": "object", "properties": {"tidying": {"type": "array", "items": {"type": "object", "properties": item, "required": need}}}, @@ -175,8 +190,8 @@ def candidates(db, spaces, c): or entities [{kind, pair, a, to (retype), reason, confidence}].""" kind, floor, limit = c.get("kind") or "merge", c.get("min_confidence", 0.7), c.get("limit") or 100 types = set(c.get("types") or []) - if kind in ("retype", "hide"): - return (wrong_types if kind == "retype" else noise)(db, spaces, floor, limit, types) + if kind in ("retype", "hide", "cluster"): + return {"retype": wrong_types, "hide": noise, "cluster": topic_groups}[kind](db, spaces, floor, limit, types) if kind == "link": spaces = set(db.values("SELECT VALUE record::id(id) FROM space WHERE graph = 'shared' AND record::id(id) IN $s", s=sorted(spaces))) if not spaces: @@ -327,6 +342,73 @@ def noise(db, spaces, floor=0.7, limit=100, types=()): ] +GROUP_MIN = 3 # topics that share a last word before they're grouped under a new topic for it + + +def _words(label): + return [w.casefold() for w in analyze.WORD.findall(label or "")] + + +def topic_groups(db, spaces, floor=0.7, limit=100, types=()): + """Topics to group under a broader topic: [{kind: cluster, pair, a: the broader topic {id, name}, topics, reason, + confidence}]. Under an existing topic when their labels end in its label; under a new one named for their last + word when GROUP_MIN or more topics with no broader one end in it.""" + held, names, found = _held(db), store.space_names(db), [] + for sid in sorted(spaces): + rows = db.rows("SELECT record::id(id) AS id, key, label, broader FROM topic WHERE space = $s", s=sid) + if len(rows) < 2: + continue + uses = Counter(db.values("SELECT VALUE topic FROM topic_about WHERE space = $s AND status = 'accepted'", s=sid)) + up = {t["id"]: set(t.get("broader") or []) for t in rows} + by_key = {t["key"]: t for t in rows} + + def above(tid, seen=None): + seen = seen if seen is not None else set() + for b in up.get(tid, ()): + if b not in seen: + seen.add(b) + above(b, seen) + return seen + + groups = defaultdict(list) # (parent key, label, existing id) -> children + for t in rows: + ws = _words(t["label"]) + for n in range(len(ws) - 1, 0, -1): # the longest label it ends in that is a topic: "deep learning" > "learning" + p = by_key.get(topics.key_of(" ".join(ws[-n:]))) + if p and p["id"] != t["id"]: + if p["id"] not in up[t["id"]] and t["id"] not in above(p["id"]): + groups[(p["key"], p["label"], p["id"])].append(t) + break + else: + if len(ws) > 1 and not up[t["id"]] and len(ws[-1]) >= 4 and ws[-1] not in FILLER and topics.key_of(ws[-1]) not in by_key: + groups[(topics.key_of(ws[-1]), ws[-1], None)].append(t) + for (key, label, pid), kids in groups.items(): + if pid is None: + if len(kids) < GROUP_MIN: + continue + label = Counter(analyze.WORD.findall(k["label"])[-1] for k in kids).most_common(1)[0][0] + label = label[:1].upper() + label[1:] + reason, conf = f"{len(kids)} topics end in “{label.casefold()}”", round(min(0.85, 0.55 + 0.05 * len(kids)), 2) + else: + reason, conf = f"their labels end in “{label}”", 0.85 + pk = f"cluster:{sid}:{key}" + if conf >= floor and pk not in held: + kids = sorted(kids, key=lambda k: (-uses[k["id"]], k["label"].casefold())) + found.append((conf, sum(uses[k["id"]] for k in kids), sid, pid, label, kids, reason, pk)) + found.sort(key=lambda x: (-x[0], -x[1])) + return [ + { + "kind": "cluster", + "pair": pk, + "a": {"id": pid, "name": label, "type": "TOPIC", "namespace": names.get(sid), "space": sid}, + "topics": [{"id": k["id"], "name": k["label"], "recordings": uses[k["id"]]} for k in kids], + "reason": reason, + "confidence": conf, + } + for conf, _n, sid, pid, label, kids, reason, pk in found[:limit] + ] + + # ---------- the model's verdict ---------- def _describe(k, item): def side(s): @@ -361,6 +443,10 @@ def _sure(v): def _describe_one(k, item): + if item["kind"] == "cluster": + a, kids = item["a"], "\n".join(f" {n}. {t['name']}" for n, t in enumerate(item["topics"], 1)) + under = f'"{a["name"]}" (a topic already)' if a.get("id") else f'"{a["name"]}" (a new topic)' + return f"{k}. under {under}, in {a['namespace']}:\n{kids}\n rules think: group ({item['reason']}; {item['confidence']})" s = item["a"] said = "; ".join(f'"{x[:160]}"' for x in s["samples"]) or "no lines" line = f'{k}. "{s["name"]}" ({s["type"]}, {s["mentions"]} mentions in {s["namespace"]}; found in: {said})' @@ -377,7 +463,7 @@ def _ones_judged(db, cfg, kind, batch, c): for sid in {it["a"]["space"] for it in batch}: codes |= entity_setup.type_codes(db, sid) - set(entities.QUIET) ask.append("Types: " + ", ".join(sorted(codes))) - ask.append("Names:\n" + "\n".join(_describe_one(k, it) for k, it in enumerate(batch, 1))) + ask.append(("Groups" if kind == "cluster" else "Names") + ":\n" + "\n".join(_describe_one(k, it) for k, it in enumerate(batch, 1))) reply = llm.json_out(cfg, ONE_SYSTEM[kind], "\n\n".join(ask), _one_schema(kind), c.get("model")) got = {} for d in (reply or {}).get("tidying") or []: @@ -391,6 +477,20 @@ def _ones_judged(db, cfg, kind, batch, c): got[d["item"]] = store.clean( {"agree": typ != it["a"]["type"], "type": typ, "confidence": _sure(d.get("confidence")), "why": why} ) + elif kind == "cluster": + if not isinstance(d.get("agree"), bool): + continue + leave = sorted({int(n) for n in d.get("leave") or [] if isinstance(n, int) and 1 <= n <= len(it["topics"])}) + label = " ".join(str(d.get("label") or "").split())[:200] + got[d["item"]] = store.clean( + { + "agree": d["agree"] and len(leave) < len(it["topics"]), + "label": label if label and not it["a"].get("id") and label.casefold() != it["a"]["name"].casefold() else None, + "leave": [it["topics"][n - 1]["id"] for n in leave] or None, + "confidence": _sure(d.get("confidence")), + "why": why, + } + ) elif isinstance(d.get("noise"), bool): got[d["item"]] = store.clean({"agree": d["noise"], "confidence": _sure(d.get("confidence")), "why": why}) return got @@ -405,7 +505,7 @@ def judge(cfg, items, c, say=print, db=None): if isinstance(it, dict) and it.get("kind") in KINDS and isinstance(it.get("a"), dict): by_kind["pair" if it["kind"] in PAIRS else it["kind"]].append(n) for kind, ns in by_kind.items(): - what = "pairs" if kind == "pair" else "names" + what = {"pair": "pairs", "cluster": "groups"}.get(kind, "names") for start in range(0, len(ns), size): part = ns[start : start + size] batch = [items[n] for n in part] @@ -433,6 +533,8 @@ def _keep(item): def _make(db, ch, user): """Make one change; the fields to record on it (merge id), or None when it can't be made any more.""" + if ch["kind"] == "cluster": + return _make_group(db, ch, user) if ch["kind"] not in PAIRS: return _make_one(db, ch) a, b = ch["a"]["id"], ch["b"]["id"] @@ -445,6 +547,50 @@ def _make(db, ch, user): return {} +def _make_group(db, ch, user): + """Put a group's topics under its broader topic, made first when it's new: {parent, created, grouped}, or None when + none of them can go under it any more (gone, or it would loop).""" + v, a, sid = ch.get("verdict") or {}, ch["a"], ch["a"]["space"] + pid = a.get("id") if a.get("id") and db.one("SELECT id FROM $r", r=R("topic", int(a["id"]))) else None + label = ch.get("label") or v.get("label") or a["name"] + if pid is None: + got = db.one("SELECT record::id(id) AS id FROM topic WHERE tkey = $k", k=f"{int(sid)}:{topics.key_of(label)}") + pid = got["id"] if got else None + created = None + if pid is None: + try: + pid = created = topics.create(db, sid, label, user=user) + except ValueError: # another topic has that label as one of its others + return None + leave, grouped = set(v.get("leave") or []), [] + for t in ch.get("topics") or []: + row = db.one("SELECT broader FROM $r", r=R("topic", int(t["id"]))) + if t["id"] in leave or t["id"] == pid or not row or pid in (row.get("broader") or []): + continue + try: + topics.update(db, t["id"], broader=[*(row.get("broader") or []), pid], user=user) + except (ValueError, KeyError): # it would loop, or the topic has as many broader ones as it can + continue + grouped.append(t["id"]) + if not grouped: + if created: + _drop_unused_topic(db, created) + return None + return {"parent": pid, "created": created, "grouped": grouped} + + +def _drop_unused_topic(db, tid): + """Delete a topic a group made, unless something has used it since (a recording, a narrower or related topic).""" + t = db.one("SELECT space, related FROM $r", r=R("topic", int(tid))) + if not t or t.get("related") or db.one("SELECT id FROM topic_about WHERE topic = $t LIMIT 1", t=int(tid)): + return False + if db.one("SELECT id FROM topic WHERE space = $s AND $t IN broader LIMIT 1", s=t["space"], t=int(tid)): + return False + db.q("DELETE $r", r=R("topic", int(tid))) + notebook.release(db, f"topic:{int(tid)}") + return True + + def _make_one(db, ch): """Retype or hide one entity, unless it's gone or has changed since the change was found.""" e = db.one(f"SELECT {entities.FIELDS} FROM $r", r=R("entity", int(ch["a"]["id"]))) @@ -470,6 +616,8 @@ def _target(it): def _touches(it): + if it["kind"] == "cluster": # topics, not entities: not in the graph's history + return [] return [it["a"]["id"], *([it["b"]["id"]] if it["kind"] in PAIRS else [])] @@ -482,6 +630,7 @@ def _record(db, item, status, origin, extra=None): "a": item["a"], "b": item.get("b"), "to": _target(item) if item["kind"] == "retype" else None, + "topics": item.get("topics") if item["kind"] == "cluster" else None, "spaces": sorted({item["a"]["space"], *([item["b"]["space"]] if item.get("b") else [])}), "reason": item.get("reason"), "confidence": item.get("confidence"), @@ -509,6 +658,7 @@ def apply_changes(db, items, c, origin=None, propose_only=False, say=print): and isinstance(it.get("a"), dict) and (it["kind"] not in PAIRS or isinstance(it.get("b"), dict)) and (it["kind"] != "retype" or _target(it)) + and (it["kind"] != "cluster" or isinstance(it.get("topics"), list)) ): stats["skipped"] += 1 continue @@ -591,8 +741,9 @@ def get_change(db, cid): return ch -def accept(db, cid, user=None, keep=None, to=None): - """Make a proposed change (`keep`: a merge's entity to keep; `to`: a retype's type, in place of the one proposed).""" +def accept(db, cid, user=None, keep=None, to=None, label=None): + """Make a proposed change (`keep`: a merge's entity to keep; `to`: a retype's type, in place of the one proposed; + `label`: a group's new broader topic's label).""" ch = get_change(db, cid) if ch["status"] != "proposed": raise ValueError(f"this change is {ch['status']}, not proposed") @@ -605,6 +756,10 @@ def accept(db, cid, user=None, keep=None, to=None): raise ValueError("only a change of type takes a type") entities._check_type(db, ch["a"]["space"], to) ch["to"] = to + if label is not None: + if ch["kind"] != "cluster" or ch["a"].get("id"): + raise ValueError("only a group under a new topic takes a label") + ch["label"] = " ".join(str(label).split()) or None with graph_history.change(db, f"{ch['kind']}.accept", entities=_touches(ch), why=ch.get("reason"), graph_change=ch["id"]): done = _make(db, ch, user) if done is None: @@ -616,6 +771,8 @@ def accept(db, cid, user=None, keep=None, to=None): ) if ch["kind"] in PAIRS: raise ValueError("one of these entities is gone (merged or deleted since)") + if ch["kind"] == "cluster": + raise ValueError("none of these topics can go under it now (gone, under it already, or it would loop)") raise ValueError("the entity is gone, hidden or changed since this was proposed") db.q( "UPDATE $r MERGE $d", @@ -641,7 +798,7 @@ def undo(db, cid, user=None): ch = get_change(db, cid) if ch["status"] != "applied": raise ValueError(f"this change is {ch['status']}, not applied") - one = [] if ch["kind"] in PAIRS else [ch["a"]["id"]] + one = [ch["a"]["id"]] if ch["kind"] in ("retype", "hide") else [] with graph_history.change(db, f"{ch['kind']}.undo", entities=one, graph_change=ch["id"]): if ch["kind"] == "merge": m = db.one("SELECT undone FROM $r", r=R("entity_merge", int(ch["merge"]))) @@ -649,6 +806,8 @@ def undo(db, cid, user=None): entities.undo_merge(db, ch["merge"]) elif ch["kind"] == "link": entities.unlink(db, ch["a"]["id"], ch["b"]["id"]) + elif ch["kind"] == "cluster": + _ungroup(db, ch) else: e = db.one(f"SELECT {entities.FIELDS} FROM $r", r=R("entity", int(ch["a"]["id"]))) if not e: @@ -660,6 +819,20 @@ def undo(db, cid, user=None): db.q("UPDATE $r SET status = 'undone', undone_at = $t, undone_by = $u", r=R("graph_change", ch["id"]), t=store.now(), u=user) +def _ungroup(db, ch): + """Take a group's topics out from under its broader topic (those someone hasn't moved since), and delete the broader + topic when the group made it and nothing uses it.""" + pid = ch.get("parent") + for tid in ch.get("grouped") or []: + row = db.one("SELECT broader FROM $r", r=R("topic", int(tid))) + if row and pid in (row.get("broader") or []): + db.q( + "UPDATE $r SET broader = $b, updated = $t", r=R("topic", int(tid)), b=[b for b in row["broader"] if b != pid], t=store.now() + ) + if ch.get("created"): + _drop_unused_topic(db, ch["created"]) + + def undo_run(db, run_id, user=None, say=None): """Take back every change a routine run applied, newest first: (undone, failed). One that can't be undone (an entity in it was deleted since) is left as it is and counted.""" @@ -720,7 +893,7 @@ def run_node(r, f, node, value, vals): t, c, name = node["type"], node["config"], node.get("label") or f"{node['type']} {node['id']}" if t == "candidates": out = candidates(r.db, r.extra["spaces"], c) - r.say(f"{name}: {len(out)} pairs") + r.say(f"{name}: {len(out)} {'pairs' if (c.get('kind') or 'merge') in PAIRS else 'found'}") return {"out": out} if t == "llm_judge": return {"out": judge(r.cfg, value if isinstance(value, list) else [], c, r.say, r.db)} diff --git a/fastapi_backend/app/schemas/routines.py b/fastapi_backend/app/schemas/routines.py index 2469839be..1f2a5f5f8 100644 --- a/fastapi_backend/app/schemas/routines.py +++ b/fastapi_backend/app/schemas/routines.py @@ -102,10 +102,14 @@ class SchedulePreview(ResponseModel): class GraphChange(ResponseModel): id: int - kind: Literal["merge", "link", "retype", "hide"] - a: dict[str, Any] = Field(description="the entity changed, or the first of a pair") + kind: Literal["merge", "link", "retype", "hide", "cluster"] + a: dict[str, Any] = Field(description="the entity changed, the first of a pair, or a group's broader topic (no id when new)") b: dict[str, Any] | None = Field(None, description="a merge's or link's other entity") to: str | None = Field(None, description="a retype's new type") + topics: list[dict[str, Any]] | None = Field(None, description="a group's topics, to put under its broader topic") + parent: int | None = Field(None, description="an applied group's broader topic") + created: int | None = Field(None, description="the broader topic an applied group made") + grouped: list[int] | None = Field(None, description="the topics an applied group put under its broader topic") spaces: list[int] reason: str | None = None confidence: float | None = None @@ -123,6 +127,7 @@ class GraphChange(ResponseModel): class GraphChangeAccept(RequestModel): keep: int | None = Field(None, description="for a merge: the entity to keep (default: the one proposed)") to: str | None = Field(None, description="for a retype: the type to give (default: the one proposed)", max_length=40) + label: str | None = Field(None, description="for a group under a new topic: its label (default: the one proposed)", max_length=200) class Undone(ResponseModel): diff --git a/fastapi_backend/tests/api/test_routines.py b/fastapi_backend/tests/api/test_routines.py index 1b08e99a3..33d8dd17a 100644 --- a/fastapi_backend/tests/api/test_routines.py +++ b/fastapi_backend/tests/api/test_routines.py @@ -373,6 +373,63 @@ def test_graph_workflows_retype_and_hide(client, db, cfg, env, llm): assert not client.get("/api/v1/graph-changes", params={"status": "applied"}, headers=h).json() +GROUP_GRAPH = { + "nodes": [ + {"id": "in", "type": "input", "config": {}}, + {"id": "groups", "type": "candidates", "config": {"kind": "cluster"}}, + {"id": "judge", "type": "llm_judge", "config": {}}, + {"id": "apply", "type": "apply_changes", "config": {"apply_above": 0.95}}, + ], + "edges": [{"source": "in", "target": "groups"}, {"source": "groups", "target": "judge"}, {"source": "judge", "target": "apply"}], +} + + +def test_graph_workflows_group_topics(client, db, cfg, env, llm): + from app.domain import topics + + h = env["admin"] + pods = store.ns_id(db, "pods") + made = {label: topics.create(db, pods, label) for label in ("Learning", "Machine learning", "Deep learning", "Sales calls")} + made |= {label: topics.create(db, pods, label) for label in ("Support calls", "Team calls", "Cold calls", "Weather")} + found = organize.topic_groups(db, {pods}) + by_name = {g["a"]["name"]: g for g in found} + assert set(by_name) == {"Learning", "Calls"}, found + assert by_name["Learning"]["a"]["id"] == made["Learning"] and by_name["Calls"]["a"]["id"] is None + assert {t["name"] for t in by_name["Calls"]["topics"]} == {"Sales calls", "Support calls", "Team calls", "Cold calls"} + assert by_name["Learning"]["confidence"] == 0.85 and by_name["Calls"]["confidence"] == 0.75 + + wid = workflows.create(db, "Group topics", GROUP_GRAPH, "", "test", "graph") + _, totals = organize.run(db, cfg, wid, {pods}) + assert totals == {"applied": 2, "proposed": 0, "skipped": 0}, totals + calls = db.one("SELECT record::id(id) AS id FROM topic WHERE tkey = $k", k=f"{pods}:calls")["id"] + assert topics._topic(db, made["Deep learning"])["broader"] == [made["Learning"]] + assert topics._topic(db, made["Cold calls"])["broader"] == [calls] + assert topics._topic(db, made["Weather"])["broader"] == [] + + changes = client.get("/api/v1/graph-changes", params={"status": "applied"}, headers=h).json() + group = next(c for c in changes if c["created"]) + assert (group["kind"], group["parent"], group["b"]) == ("cluster", calls, None) and len(group["grouped"]) == 4 + assert client.post(f"/api/v1/graph-changes/{group['id']}/undo", headers=h).status_code == 200 + assert not db.one("SELECT id FROM $r", r=R("topic", calls)) # the group made it, and nothing else uses it + assert topics._topic(db, made["Cold calls"])["broader"] == [] + _, again = organize.run(db, cfg, wid, {pods}) + assert again == {"applied": 0, "proposed": 0, "skipped": 0}, again # taken back, so not made again + + # proposed: accepted under a label someone gives, or refused when nothing can go under it any more + db.q("DELETE graph_change WHERE status = 'undone'") + _, got = organize.run(db, cfg, wid, {pods}, propose_only=True) + assert got["proposed"] == 1, got + ch = client.get("/api/v1/graph-changes", params={"status": "proposed"}, headers=h).json()[0] + assert client.post(f"/api/v1/graph-changes/{ch['id']}/accept", headers=h, json={"to": "ORG"}).status_code == 400 + assert client.post(f"/api/v1/graph-changes/{ch['id']}/accept", headers=h, json={"label": "Phone calls"}).status_code == 200 + phone = db.one("SELECT record::id(id) AS id FROM topic WHERE tkey = $k", k=f"{pods}:phone calls")["id"] + assert topics._topic(db, made["Sales calls"])["broader"] == [phone] + topics.tag(db, phone, [db.values("SELECT VALUE record::id(id) FROM recording WHERE space = $s", s=pods)[0]]) + assert client.post(f"/api/v1/graph-changes/{ch['id']}/undo", headers=h).status_code == 200 + assert db.one("SELECT id FROM $r", r=R("topic", phone)) # a recording is about it now: it stays + assert topics._topic(db, made["Sales calls"])["broader"] == [] + + def test_new_recordings_advance_only_as_far_as_queued(db, cfg, env): pods = store.ns_id(db, "pods") rid = routines.create(db, "Small batches", [{"type": "pipeline", "steps": ["analyze"], "limit": 1}], namespaces=[pods]) diff --git a/fastapi_backend/tests/fake_llm.py b/fastapi_backend/tests/fake_llm.py index 61adf737c..35a630bea 100644 --- a/fastapi_backend/tests/fake_llm.py +++ b/fastapi_backend/tests/fake_llm.py @@ -243,16 +243,16 @@ def do_POST(self): } ) elif "tidying" in schema.get("properties", {}): - # graph tidying, one entity at a time: the rules are right (the type they think, or noise), and sure + # graph tidying, one entity or group at a time: the rules are right (the type they think, noise, the group), and sure text = body["messages"][-1]["content"] - guesses = re.findall(r"^(\d+)\. .*\n rules think: (\S+)", text, re.M) + guesses = re.findall(r"^(\d+)\. .*\n(?: .*\n)*? rules think: (\S+)", text, re.M) asked = schema["properties"]["tidying"]["items"]["properties"] content = json.dumps( { "tidying": [ { "item": int(k), - **({"type": g} if "type" in asked else {"noise": True}), + **({"type": g} if "type" in asked else {"noise": True} if "noise" in asked else {"agree": True}), "confidence": 0.96, "why": "the lines say so", } diff --git a/nextjs-frontend/__tests__/graph-changes.test.tsx b/nextjs-frontend/__tests__/graph-changes.test.tsx index 1e964a3e4..c6242f2b7 100644 --- a/nextjs-frontend/__tests__/graph-changes.test.tsx +++ b/nextjs-frontend/__tests__/graph-changes.test.tsx @@ -62,6 +62,23 @@ describe("graph changes about one entity", () => { expect(screen.getByRole("button", { name: /Undo/ })).toBeInTheDocument(); }); + it("show a group of topics under a new broader one", () => { + card({ + kind: "cluster", + a: { id: null, name: "Calls", type: "TOPIC", namespace: "pods", space: 1 }, + topics: [ + { id: 3, name: "Sales calls", recordings: 2 }, + { id: 4, name: "Judgement calls", recordings: 1 }, + ], + reason: "2 topics end in “calls”", + verdict: { agree: true, confidence: 0.9, leave: [4] }, + }); + expect(screen.getByText("Group under a new topic, “Calls”?")).toBeInTheDocument(); + expect(screen.getByText("Judgement calls")).toHaveClass("line-through"); + expect(screen.getByRole("button", { name: "Group them" })).toBeInTheDocument(); + expect(screen.getByText("Leave them")).toBeInTheDocument(); + }); + it("name a namespace's own types", () => { expect(typeName("CLIENT_TEAM")).toBe("Client team"); expect(typeName("PERSON")).toBe("Person"); diff --git a/nextjs-frontend/app/openapi-client/types.gen.ts b/nextjs-frontend/app/openapi-client/types.gen.ts index 052b0fb35..3611e36e3 100644 --- a/nextjs-frontend/app/openapi-client/types.gen.ts +++ b/nextjs-frontend/app/openapi-client/types.gen.ts @@ -9000,11 +9000,11 @@ export type GraphChange = { /** * Kind */ - kind: "merge" | "link" | "retype" | "hide"; + kind: "merge" | "link" | "retype" | "hide" | "cluster"; /** * A * - * the entity changed, or the first of a pair + * the entity changed, the first of a pair, or a group's broader topic (no id when new) */ a: { [key: string]: unknown; @@ -9023,6 +9023,32 @@ export type GraphChange = { * a retype's new type */ to?: string | null; + /** + * Topics + * + * a group's topics, to put under its broader topic + */ + topics?: Array<{ + [key: string]: unknown; + }> | null; + /** + * Parent + * + * an applied group's broader topic + */ + parent?: number | null; + /** + * Created + * + * the broader topic an applied group made + */ + created?: number | null; + /** + * Grouped + * + * the topics an applied group put under its broader topic + */ + grouped?: Array | null; /** * Spaces */ @@ -9092,6 +9118,12 @@ export type GraphChangeAccept = { * for a retype: the type to give (default: the one proposed) */ to?: string | null; + /** + * Label + * + * for a group under a new topic: its label (default: the one proposed) + */ + label?: string | null; }; /** diff --git a/nextjs-frontend/components/routines/graph-changes.tsx b/nextjs-frontend/components/routines/graph-changes.tsx index 6fcd4cbc6..1ff981932 100644 --- a/nextjs-frontend/components/routines/graph-changes.tsx +++ b/nextjs-frontend/components/routines/graph-changes.tsx @@ -1,7 +1,7 @@ "use client"; import { useMutation, useQueryClient } from "@tanstack/react-query"; -import { EyeOff, GitMerge, Link2, Tags, Undo2, Waypoints } from "lucide-react"; +import { EyeOff, FolderTree, GitMerge, Link2, Tags, Undo2, Waypoints } from "lucide-react"; import Link from "next/link"; import { useState } from "react"; @@ -26,12 +26,15 @@ type Side = { mentions?: number; samples?: string[]; }; +type Topic = { id: number; name: string; recordings?: number }; type Verdict = { same?: boolean; agree?: boolean; confidence?: number; keep?: "a" | "b" | null; type?: string; + label?: string; + leave?: number[]; why?: string; }; @@ -52,12 +55,47 @@ const TYPE_NAMES: Record = { export const typeName = (code: string | null | undefined) => code ? (TYPE_NAMES[code] ?? (code.charAt(0) + code.slice(1).toLowerCase()).replace(/_/g, " ")) : "—"; +/** A group's broader topic and the topics to go under it (those the model would leave out struck through). */ +function TopicGroup({ parent, topics, left }: { parent: Side; topics: Topic[]; left: Set }) { + return ( +
+

+ {parent.id ? ( + + {parent.name} + + ) : ( + {parent.name} + )}{" "} + · {parent.namespace ?? "—"} · {topics.length} topic{topics.length === 1 ? "" : "s"} under it +

+
    + {topics.map((t) => ( +
  • + + {t.name} + +
  • + ))} +
+
+ ); +} + /** What a change is about, in a few words, and its icon. */ function heading(ch: GraphChange): { icon: typeof GitMerge; title: string } { const a = ch.a as Side; if (ch.kind === "merge") return { icon: GitMerge, title: "Merge: the same thing in one namespace?" }; if (ch.kind === "link") return { icon: Link2, title: "Link: the same thing across namespaces?" }; if (ch.kind === "retype") return { icon: Tags, title: `Type: ${typeName(a.type)} → ${typeName(ch.to)}?` }; + if (ch.kind === "cluster") + return { icon: FolderTree, title: `Group under ${a.id ? "" : "a new topic, "}“${a.name}”?` }; return { icon: EyeOff, title: "Hide as noise?" }; } @@ -134,6 +172,7 @@ export function ChangeCard({ ch }: { ch: GraphChange }) { link: "Linked", retype: `${a.name}: ${typeName(ch.to)} now`, hide: `${a.name} is hidden`, + cluster: `Grouped under ${v?.label ?? a.name}`, }; toast({ tone: "green", @@ -173,20 +212,24 @@ export function ChangeCard({ ch }: { ch: GraphChange }) { {ch.decided_by ? ` by ${ch.decided_by}` : ""} -
- setKeep(a.id) : undefined} - /> - {b && ( + {ch.kind === "cluster" ? ( + + ) : ( +
setKeep(b.id) : undefined} + side={a} + kept={merge && (ch.status === "proposed" ? keep === a.id : ch.keep === a.id)} + choose={merge && ch.status === "proposed" && editor ? () => setKeep(a.id) : undefined} /> - )} -
+ {b && ( + setKeep(b.id) : undefined} + /> + )} +
+ )}
Rule
@@ -207,9 +250,15 @@ export function ChangeCard({ ch }: { ch: GraphChange }) { ? v.agree === false ? `Keep ${typeName(a.type)}` : typeName(v.type ?? ch.to) - : v.agree === false - ? "Not noise" - : "Noise"} + : ch.kind === "cluster" + ? v.agree === false + ? "Not together" + : v.label + ? `Together, as “${v.label}”` + : "Together" + : v.agree === false + ? "Not noise" + : "Noise"} {" "} · {pct(v.confidence)} {v.why ? ` · ${v.why}` : ""} @@ -234,6 +283,7 @@ export function ChangeCard({ ch }: { ch: GraphChange }) { link: "Link them", retype: `Make it ${typeName(ch.to)}`, hide: "Hide it", + cluster: "Group them", }[ch.kind] } @@ -244,7 +294,7 @@ export function ChangeCard({ ch }: { ch: GraphChange }) { disabledReason={why} onClick={() => act.mutate("dismiss")} > - {pair ? "These are different" : "Leave it"} + {pair ? "These are different" : ch.kind === "cluster" ? "Leave them" : "Leave it"} )} diff --git a/nextjs-frontend/components/workflows/node-settings.tsx b/nextjs-frontend/components/workflows/node-settings.tsx index 088153de2..a03c47ef3 100644 --- a/nextjs-frontend/components/workflows/node-settings.tsx +++ b/nextjs-frontend/components/workflows/node-settings.tsx @@ -642,6 +642,7 @@ export function NodeSettings({ { value: "link", label: "Look-alikes across shared namespaces (to link)" }, { value: "retype", label: "Entities whose type looks wrong (to retype)" }, { value: "hide", label: "Noise: filler words, fragments, one-offs (to hide)" }, + { value: "cluster", label: "Topics that go under one broader topic (to group)" }, ]} /> )} diff --git a/nextjs-frontend/components/workflows/workflow-editor.tsx b/nextjs-frontend/components/workflows/workflow-editor.tsx index fcad0ca06..b1fe600dc 100644 --- a/nextjs-frontend/components/workflows/workflow-editor.tsx +++ b/nextjs-frontend/components/workflows/workflow-editor.tsx @@ -477,8 +477,8 @@ export function WorkflowEditor({ id }: { id?: number }) {

How graph workflows run

A graph workflow starts from the namespaces a routine runs it over. Find what to tidy finds look-alike - entities, entities whose type looks wrong, or noise; Ask the model judges each one, and Apply changes - makes the sure ones and proposes the rest. + entities, entities whose type looks wrong, noise, or topics to group; Ask the model judges each one, and + Apply changes makes the sure ones and proposes the rest.

Run it from a routine. Proposed changes wait in Routines → Proposed changes, and every change can be diff --git a/nextjs-frontend/components/workflows/workflow-model.ts b/nextjs-frontend/components/workflows/workflow-model.ts index d6fae7bc2..a7869f1fb 100644 --- a/nextjs-frontend/components/workflows/workflow-model.ts +++ b/nextjs-frontend/components/workflows/workflow-model.ts @@ -317,7 +317,8 @@ export const NODES: Record = { // Graph workflows (scope graph) candidates: { label: "Find what to tidy", - describe: "Found by rules: look-alike entities to merge or link, entities whose type looks wrong, or noise to hide", + describe: + "Found by rules: look-alike entities to merge or link, entities whose type looks wrong, noise to hide, or topics to group under a broader one", icon: SearchCheck, tone: "green", inputs: 1, @@ -329,7 +330,7 @@ export const NODES: Record = { llm_judge: { label: "Ask the model", describe: - "Asks the model about each candidate, with lines where each name appears: one thing or two, its type, or noise", + "Asks the model about each candidate, with lines where each name appears: one thing or two, its type, noise, or whether topics go together", icon: Gavel, tone: "gold", inputs: 1, @@ -387,7 +388,7 @@ export const NODES: Record = { apply_changes: { label: "Apply changes", describe: - "Makes the changes it’s sure of (merges, links, types, hides) and proposes the rest for someone to accept; all can be undone", + "Makes the changes it’s sure of (merges, links, types, hides, groups) and proposes the rest for someone to accept; all can be undone", icon: CheckCheck, tone: "gold", inputs: 1, @@ -506,6 +507,7 @@ export const CANDIDATE_KINDS: Record = { link: "look-alikes across namespaces", retype: "wrong types", hide: "noise", + cluster: "topics to group", }; /** What a classify node chooses from. */ export const VOCABULARIES: Record = { content_type: "Content types", topic: "The namespace’s topics" }; diff --git a/nextjs-frontend/openapi.json b/nextjs-frontend/openapi.json index c62f0f410..bfc2a42a1 100644 --- a/nextjs-frontend/openapi.json +++ b/nextjs-frontend/openapi.json @@ -49960,7 +49960,8 @@ "merge", "link", "retype", - "hide" + "hide", + "cluster" ], "title": "Kind" }, @@ -49968,7 +49969,7 @@ "additionalProperties": true, "type": "object", "title": "A", - "description": "the entity changed, or the first of a pair" + "description": "the entity changed, the first of a pair, or a group's broader topic (no id when new)" }, "b": { "anyOf": [ @@ -49995,6 +49996,61 @@ "title": "To", "description": "a retype's new type" }, + "topics": { + "anyOf": [ + { + "items": { + "additionalProperties": true, + "type": "object" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Topics", + "description": "a group's topics, to put under its broader topic" + }, + "parent": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "title": "Parent", + "description": "an applied group's broader topic" + }, + "created": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "title": "Created", + "description": "the broader topic an applied group made" + }, + "grouped": { + "anyOf": [ + { + "items": { + "type": "integer" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Grouped", + "description": "the topics an applied group put under its broader topic" + }, "spaces": { "items": { "type": "integer" @@ -50161,6 +50217,19 @@ ], "title": "To", "description": "for a retype: the type to give (default: the one proposed)" + }, + "label": { + "anyOf": [ + { + "type": "string", + "maxLength": 200 + }, + { + "type": "null" + } + ], + "title": "Label", + "description": "for a group under a new topic: its label (default: the one proposed)" } }, "additionalProperties": false,