Coverage for app / knowledge / registry.py: 100%
5 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-10-31 11:23 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-10-31 11:23 +0000
1"""
2Built-in knowledge graph node type registry.
4Each entry defines a reusable entity archetype that users can slot into
5knowledge graphs. Definitions are served via the /knowledge/node-types
6endpoint so svc-core and the frontend stay in sync with this registry.
8Adding a new built-in node type:
9 1. Add a dict entry to BUILTIN_NODE_TYPES below.
10 2. The /knowledge/node-types endpoint will return it automatically.
12property_schema fields:
13 key – property identifier (used as the key in node.properties)
14 label – human-readable field label shown in the UI
15 type – "string" | "number" | "date" | "email" | "url"
16 required – whether this field is mandatory
17 placeholder – example input shown in the form field
18"""
20from __future__ import annotations
22from typing import Any
24from app.util.registry import BuiltinRegistry
26# ---------------------------------------------------------------------------
27# Registry
28# ---------------------------------------------------------------------------
30_BUILTIN_NODE_TYPES: list[dict[str, Any]] = [
31 # ── Person ───────────────────────────────────────────────────────────────
32 {
33 "name": "Person",
34 "display_name": "Person",
35 "description": "An individual human being.",
36 "category": "entities",
37 "color": "teal",
38 "property_schema": [
39 {
40 "key": "name",
41 "label": "Name",
42 "type": "string",
43 "required": True,
44 "placeholder": "e.g. Alice Smith",
45 },
46 {
47 "key": "age",
48 "label": "Age",
49 "type": "number",
50 "required": False,
51 "placeholder": "e.g. 34",
52 },
53 {
54 "key": "occupation",
55 "label": "Occupation",
56 "type": "string",
57 "required": False,
58 "placeholder": "e.g. Software Engineer",
59 },
60 {
61 "key": "email",
62 "label": "Email",
63 "type": "email",
64 "required": False,
65 "placeholder": "e.g. alice@example.com",
66 },
67 ],
68 },
69 # ── Company ──────────────────────────────────────────────────────────────
70 {
71 "name": "Company",
72 "display_name": "Company",
73 "description": "A business or organisation.",
74 "category": "entities",
75 "color": "blue",
76 "property_schema": [
77 {
78 "key": "name",
79 "label": "Name",
80 "type": "string",
81 "required": True,
82 "placeholder": "e.g. Acme Corp",
83 },
84 {
85 "key": "industry",
86 "label": "Industry",
87 "type": "string",
88 "required": False,
89 "placeholder": "e.g. Technology",
90 },
91 {
92 "key": "founded",
93 "label": "Founded",
94 "type": "string",
95 "required": False,
96 "placeholder": "e.g. 2010",
97 },
98 {
99 "key": "headquarters",
100 "label": "Headquarters",
101 "type": "string",
102 "required": False,
103 "placeholder": "e.g. London, UK",
104 },
105 {
106 "key": "website",
107 "label": "Website",
108 "type": "url",
109 "required": False,
110 "placeholder": "e.g. https://acme.com",
111 },
112 ],
113 },
114 # ── Location ─────────────────────────────────────────────────────────────
115 {
116 "name": "Location",
117 "display_name": "Location",
118 "description": "A geographic place or region.",
119 "category": "places",
120 "color": "amber",
121 "property_schema": [
122 {
123 "key": "name",
124 "label": "Name",
125 "type": "string",
126 "required": True,
127 "placeholder": "e.g. London",
128 },
129 {
130 "key": "country",
131 "label": "Country",
132 "type": "string",
133 "required": False,
134 "placeholder": "e.g. United Kingdom",
135 },
136 {
137 "key": "city",
138 "label": "City",
139 "type": "string",
140 "required": False,
141 "placeholder": "e.g. London",
142 },
143 {
144 "key": "coordinates",
145 "label": "Coordinates",
146 "type": "string",
147 "required": False,
148 "placeholder": "e.g. 51.5074, -0.1278",
149 },
150 ],
151 },
152 # ── Concept ──────────────────────────────────────────────────────────────
153 {
154 "name": "Concept",
155 "display_name": "Concept",
156 "description": "An abstract idea, topic, or domain concept.",
157 "category": "abstractions",
158 "color": "violet",
159 "property_schema": [
160 {
161 "key": "name",
162 "label": "Name",
163 "type": "string",
164 "required": True,
165 "placeholder": "e.g. Machine Learning",
166 },
167 {
168 "key": "definition",
169 "label": "Definition",
170 "type": "string",
171 "required": False,
172 "placeholder": "e.g. A branch of AI…",
173 },
174 {
175 "key": "domain",
176 "label": "Domain",
177 "type": "string",
178 "required": False,
179 "placeholder": "e.g. Computer Science",
180 },
181 {
182 "key": "category",
183 "label": "Category",
184 "type": "string",
185 "required": False,
186 "placeholder": "e.g. Technology",
187 },
188 ],
189 },
190 # ── Event ────────────────────────────────────────────────────────────────
191 {
192 "name": "Event",
193 "display_name": "Event",
194 "description": "A happening or occurrence at a point in time.",
195 "category": "temporal",
196 "color": "rose",
197 "property_schema": [
198 {
199 "key": "name",
200 "label": "Name",
201 "type": "string",
202 "required": True,
203 "placeholder": "e.g. Product Launch",
204 },
205 {
206 "key": "date",
207 "label": "Date",
208 "type": "date",
209 "required": False,
210 "placeholder": "e.g. 2024-03-15",
211 },
212 {
213 "key": "location",
214 "label": "Location",
215 "type": "string",
216 "required": False,
217 "placeholder": "e.g. London",
218 },
219 {
220 "key": "organiser",
221 "label": "Organiser",
222 "type": "string",
223 "required": False,
224 "placeholder": "e.g. Acme Corp",
225 },
226 ],
227 },
228 # ── Product ──────────────────────────────────────────────────────────────
229 {
230 "name": "Product",
231 "display_name": "Product",
232 "description": "A good, service, or software product.",
233 "category": "entities",
234 "color": "emerald",
235 "property_schema": [
236 {
237 "key": "name",
238 "label": "Name",
239 "type": "string",
240 "required": True,
241 "placeholder": "e.g. Widget Pro",
242 },
243 {
244 "key": "category",
245 "label": "Category",
246 "type": "string",
247 "required": False,
248 "placeholder": "e.g. SaaS",
249 },
250 {
251 "key": "version",
252 "label": "Version",
253 "type": "string",
254 "required": False,
255 "placeholder": "e.g. 2.4.1",
256 },
257 {
258 "key": "manufacturer",
259 "label": "Manufacturer",
260 "type": "string",
261 "required": False,
262 "placeholder": "e.g. Acme Corp",
263 },
264 ],
265 },
266 # ── Document ─────────────────────────────────────────────────────────────
267 {
268 "name": "Document",
269 "display_name": "Document",
270 "description": "A written record, report, or file.",
271 "category": "records",
272 "color": "indigo",
273 "property_schema": [
274 {
275 "key": "title",
276 "label": "Title",
277 "type": "string",
278 "required": True,
279 "placeholder": "e.g. Annual Report 2024",
280 },
281 {
282 "key": "author",
283 "label": "Author",
284 "type": "string",
285 "required": False,
286 "placeholder": "e.g. Alice Smith",
287 },
288 {
289 "key": "date",
290 "label": "Date",
291 "type": "date",
292 "required": False,
293 "placeholder": "e.g. 2024-01-01",
294 },
295 {
296 "key": "document_type",
297 "label": "Type",
298 "type": "string",
299 "required": False,
300 "placeholder": "e.g. Report",
301 },
302 {
303 "key": "url",
304 "label": "URL",
305 "type": "url",
306 "required": False,
307 "placeholder": "e.g. https://example.com/doc.pdf",
308 },
309 ],
310 },
311 # ── Custom ───────────────────────────────────────────────────────────────
312 {
313 "name": "Custom",
314 "display_name": "Custom",
315 "description": "A free-form entity with user-defined properties.",
316 "category": "other",
317 "color": "gray",
318 "property_schema": [],
319 },
320]
322BUILTIN_NODE_TYPES: BuiltinRegistry[dict[str, Any]] = BuiltinRegistry(
323 _BUILTIN_NODE_TYPES, key=lambda nt: nt["name"]
324)