rsnarsna commited on
Commit
32bb9bd
·
2 Parent(s): c1fdc354ccd431

Merge branch 'dev' into main - automated platform synchronization

Browse files
database/catalogs_enricher.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ALLI Backend - Studio Palette Catalogs Enricher
3
+ Dynamically hydrates DB-persisted package blueprints into the 'Python Libraries' studio palette category.
4
+ """
5
+
6
+ import copy
7
+ from typing import Any, Dict, List
8
+
9
+
10
+ def enrich_palette_with_blueprints(
11
+ categories: List[Dict[str, Any]], blueprints: List[Dict[str, Any]]
12
+ ) -> List[Dict[str, Any]]:
13
+ """Dynamically merges all blueprints from MongoDB Atlas into 'Python Libraries' palette category."""
14
+ cats = copy.deepcopy(categories)
15
+ target_cat = next((c for c in cats if c.get("name") == "Python Libraries"), None)
16
+ if not target_cat:
17
+ return cats
18
+
19
+ existing_items = target_cat.get("items", [])
20
+ existing_names = {str(it.get("label", "")).lower(): it for it in existing_items}
21
+
22
+ for bp in blueprints:
23
+ name = bp.get("name")
24
+ if not name:
25
+ continue
26
+ ver = bp.get("version") or "latest"
27
+ summary = bp.get("summary") or f"Module {name}"
28
+ clean_name = str(name).lower()
29
+
30
+ if clean_name in existing_names:
31
+ item = existing_names[clean_name]
32
+ item["version"] = ver
33
+ continue
34
+
35
+ existing_items.append(
36
+ {
37
+ "id": f"lib_{clean_name}",
38
+ "label": name,
39
+ "sublabel": f"v{ver} • {summary[:40]}",
40
+ "category": "Python Libraries",
41
+ "icon": "Package",
42
+ "iconColor": "text-blue-400",
43
+ "iconBg": "bg-blue-600",
44
+ "borderColor": "border-blue-500/40",
45
+ "nodeType": f"alli.primitive.{clean_name}" if clean_name in ("math", "json") else clean_name,
46
+ "version": ver,
47
+ "defaultData": {"package_name": name, "version": ver, "is_playground": True},
48
+ }
49
+ )
50
+
51
+ target_cat["items"] = existing_items
52
+ return cats
database/catalogs_repo.py CHANGED
@@ -54,26 +54,29 @@ class CatalogsRepoMixin:
54
  return False
55
  return True
56
 
57
- def get_studio_palette(self) -> List[Dict[str, Any]]:
 
58
  canonical = get_default_studio_palette()
 
 
59
  col = self.get_collection("core_definitions")
60
  if col is not None:
61
  try:
62
  doc = col.find_one({"key": "primary_studio_categories"}, {"_id": 0})
63
  if doc and "categories" in doc and not is_studio_palette_stale(doc.get("categories"), canonical):
64
- return doc["categories"]
65
  col.update_one(
66
  {"key": "primary_studio_categories"},
67
  {"$set": {"key": "primary_studio_categories", "categories": canonical, "updated_at": get_utc_now()}},
68
  upsert=True,
69
  )
70
  self._studio_palette_store = canonical
71
- return canonical
72
  except Exception as e:
73
  print(f"[ALLI MongoDB] Studio palette fetch error: {e}")
74
  if self._studio_palette_store is not None and not is_studio_palette_stale(self._studio_palette_store, canonical):
75
- return self._studio_palette_store
76
- return canonical
77
 
78
  def get_python_fundamentals(self) -> Dict[str, Any]:
79
  col = self.get_collection("python_fundamentals")
 
54
  return False
55
  return True
56
 
57
+ def get_studio_palette(self, blueprints: Optional[List[Dict[str, Any]]] = None) -> List[Dict[str, Any]]:
58
+ from database.catalogs_enricher import enrich_palette_with_blueprints
59
  canonical = get_default_studio_palette()
60
+ if blueprints is None:
61
+ blueprints = self.list_blueprints()
62
  col = self.get_collection("core_definitions")
63
  if col is not None:
64
  try:
65
  doc = col.find_one({"key": "primary_studio_categories"}, {"_id": 0})
66
  if doc and "categories" in doc and not is_studio_palette_stale(doc.get("categories"), canonical):
67
+ return enrich_palette_with_blueprints(doc["categories"], blueprints)
68
  col.update_one(
69
  {"key": "primary_studio_categories"},
70
  {"$set": {"key": "primary_studio_categories", "categories": canonical, "updated_at": get_utc_now()}},
71
  upsert=True,
72
  )
73
  self._studio_palette_store = canonical
74
+ return enrich_palette_with_blueprints(canonical, blueprints)
75
  except Exception as e:
76
  print(f"[ALLI MongoDB] Studio palette fetch error: {e}")
77
  if self._studio_palette_store is not None and not is_studio_palette_stale(self._studio_palette_store, canonical):
78
+ return enrich_palette_with_blueprints(self._studio_palette_store, blueprints)
79
+ return enrich_palette_with_blueprints(canonical, blueprints)
80
 
81
  def get_python_fundamentals(self) -> Dict[str, Any]:
82
  col = self.get_collection("python_fundamentals")