-
Notifications
You must be signed in to change notification settings - Fork 11
feat: Introduce Kaizen Web UI and Management Dashboard #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
0f41713
feat(ui): formalize entity creation with React dropdowns and array ma…
visahak 5036b46
docs: add UI running instructions to README
visahak 370d964
feat(ui): initialize React frontend application
visahak d1866e0
adding mvp of kaizen UI
visahak 2a0a662
build: include UI dist in package manifest
visahak 4bd8d4d
refactor(ui): fix CSS bugs, decompose EntityExplorer, add shared hook…
visahak 1a5caa8
fix: code quality improvements across backend and frontend
visahak bcc09de
addressing code review issues
visahak 0762b42
docs: add UI build instructions and run ruff
visahak 2f7e1de
style: apply ruff format to frontend python files
visahak a1a6700
fixing code review issues
visahak 8a8d62d
more changes to address reviews
visahak b8c182d
chore: ignore package-lock.json in detect-secrets scan
visahak 5d9f941
address code review issue
visahak ebb2c8d
addressing more code review issues
visahak 9c3e924
chore: remove kaizen.schema.policy mypy omit and fallback since it no…
visahak 2bf591e
fix(ui): confirm dialog signature, entity creation validation, dashbo…
visahak 5b75be8
fix(ui): provide fallback for dashboard error message
visahak fb46c6b
fix(api): enforce MAX_ENTITY_LIMIT for entity listing
visahak dc51fc3
fix(api): raise HTTPException instead of swallowing errors in listing…
visahak b660ad7
more changes
visahak 3040167
formatting
visahak 8c41ca8
addressing an issue
visahak 51abde4
changes to address issues raised by coderabbit
visahak 7f566d0
Merge branch 'main' into kaizenUI
visahak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| recursive-include kaizen *.jinja2 | ||
| recursive-include kaizen/frontend/ui/dist * | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,244 @@ | ||
| from typing import Any, List, Optional | ||
| import logging | ||
| from pydantic import BaseModel | ||
|
|
||
| from fastapi import APIRouter, Query | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| router = APIRouter() | ||
|
|
||
| MAX_ENTITY_LIMIT = 500 | ||
|
|
||
|
|
||
| class NamespaceCreateRequest(BaseModel): | ||
| namespace_id: str | ||
|
|
||
|
|
||
| class EntityCreateRequest(BaseModel): | ||
| type: str | ||
| content: str | ||
| metadata: dict = {} | ||
|
|
||
|
|
||
| @router.get("/dashboard") | ||
| def get_dashboard() -> dict[str, Any]: | ||
| from kaizen.frontend.mcp.mcp_server import get_client | ||
|
|
||
| client = get_client() | ||
|
|
||
| # 1. Backend health | ||
| try: | ||
| health = client.ready() | ||
| except Exception as e: | ||
| logger.error(f"Error checking health: {e}") | ||
| health = False | ||
|
|
||
| # 2. Namespace count | ||
| try: | ||
| namespaces = client.all_namespaces(limit=1000) | ||
| namespace_count = len(namespaces) | ||
| except Exception as e: | ||
| logger.error(f"Error fetching namespaces: {e}") | ||
| namespaces = [] | ||
| namespace_count = 0 | ||
|
|
||
| # 3. Entity counts and recent entities across namespaces | ||
| # For MVP, we will aggregate from all available namespaces up to the limit | ||
| total_entities = 0 | ||
| approximate_type_breakdown: dict[str, int] = {} | ||
| recent_entities: list[dict[str, Any]] = [] | ||
|
|
||
| for ns in namespaces: | ||
| try: | ||
| total_entities += ns.num_entities or 0 | ||
| # Fetch only a small sample per namespace for the dashboard | ||
| ns_entities = client.get_all_entities(ns.id, limit=10) | ||
|
|
||
| for entity in ns_entities: | ||
| etype = entity.type or "unknown" | ||
| approximate_type_breakdown[etype] = approximate_type_breakdown.get(etype, 0) + 1 | ||
|
|
||
| # Safely handle non-string content before slicing | ||
| content = entity.content | ||
| if isinstance(content, str): | ||
| snippet = content[:100] + "..." if len(content) > 100 else content | ||
| else: | ||
| safe_str = str(content) | ||
| snippet = safe_str[:100] + "..." if len(safe_str) > 100 else safe_str | ||
|
|
||
| recent_entities.append( | ||
| { | ||
| "id": entity.id, | ||
| "type": entity.type, | ||
| "content": snippet, | ||
| "namespace": ns.id, | ||
| "created_at": entity.created_at.isoformat() if hasattr(entity, "created_at") and entity.created_at else None, | ||
| } | ||
| ) | ||
| except Exception as e: | ||
| logger.error(f"Error fetching entities for namespace {ns.id}: {e}") | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| # sort by created_at descending (assuming we have those or just use the end of list) | ||
| # the client doesn't strictly order by date right now unless we extract or sort manually | ||
| recent_entities.sort(key=lambda x: x.get("created_at") or "", reverse=True) | ||
| recent_entities = recent_entities[:10] # top 10 | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| return { | ||
| "health": health, | ||
| "namespace_count": namespace_count, | ||
| "total_entities": total_entities, | ||
| "approximate_type_breakdown": [{"type": k, "count": v} for k, v in approximate_type_breakdown.items()], | ||
| "type_breakdown_is_approx": True, | ||
| "recent_entities": recent_entities, | ||
| } | ||
|
|
||
|
|
||
| @router.get("/namespaces") | ||
| def list_namespaces() -> List[dict[str, Any]]: | ||
| from kaizen.frontend.mcp.mcp_server import get_client | ||
|
|
||
| client = get_client() | ||
| try: | ||
| namespaces = [] | ||
| for ns in client.all_namespaces(limit=1000): | ||
| namespaces.append({"id": ns.id, "amount_of_entities": ns.num_entities or 0}) | ||
| return namespaces | ||
| except Exception as e: | ||
| from fastapi import HTTPException | ||
|
|
||
| logger.error(f"Error fetching namespaces: {e}") | ||
| raise HTTPException(status_code=500, detail="Internal server error while fetching namespaces") | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| @router.post("/namespaces") | ||
| def add_namespace(req: NamespaceCreateRequest) -> dict[str, Any]: | ||
| from kaizen.frontend.mcp.mcp_server import get_client | ||
|
|
||
| client = get_client() | ||
| try: | ||
| client.create_namespace(req.namespace_id) | ||
| return {"success": True, "namespace_id": req.namespace_id} | ||
| except Exception as e: | ||
| from fastapi import HTTPException | ||
|
|
||
| logger.error(f"Error creating namespace: {e}") | ||
| raise HTTPException(status_code=400, detail="Internal server error while creating namespace") | ||
|
|
||
|
|
||
| @router.delete("/namespaces/{namespace_id}") | ||
| def delete_namespace(namespace_id: str) -> dict[str, Any]: | ||
| from kaizen.frontend.mcp.mcp_server import get_client | ||
|
|
||
| client = get_client() | ||
| try: | ||
| client.delete_namespace(namespace_id) | ||
| return {"success": True} | ||
| except Exception as e: | ||
| from fastapi import HTTPException | ||
|
|
||
| logger.error(f"Error deleting namespace: {e}") | ||
| raise HTTPException(status_code=400, detail="Internal server error while deleting namespace") | ||
|
|
||
|
|
||
| @router.get("/namespaces/{namespace_id}/entities") | ||
| def list_namespace_entities( | ||
| namespace_id: str, | ||
| type: Optional[str] = Query(None, description="Filter entities by type (e.g., guideline, task)"), | ||
| limit: int = Query(100, description=f"Maximum number of entities to return (max {MAX_ENTITY_LIMIT})"), | ||
| ) -> List[dict[str, Any]]: | ||
| from kaizen.frontend.mcp.mcp_server import get_client | ||
|
|
||
| client = get_client() | ||
| try: | ||
| # Sanitize limit | ||
| limit = max(1, min(limit, MAX_ENTITY_LIMIT)) | ||
|
|
||
| filters = {} | ||
| if type: | ||
| filters["type"] = type | ||
|
|
||
| entities = client.get_all_entities(namespace_id, filters=filters, limit=limit) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| result = [] | ||
| for entity in entities: | ||
| result.append( | ||
| { | ||
| "id": entity.id, | ||
| "type": entity.type, | ||
| "content": entity.content, | ||
| "metadata": entity.metadata or {}, | ||
| "created_at": entity.created_at.isoformat() if hasattr(entity, "created_at") and entity.created_at else None, | ||
| } | ||
| ) | ||
|
|
||
| # Sort by created_at descending | ||
| result.sort(key=lambda x: str(x.get("created_at") or ""), reverse=True) | ||
| return result | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| except Exception as e: | ||
| from fastapi import HTTPException | ||
|
|
||
| logger.error(f"Error fetching entities for namespace {namespace_id}: {e}") | ||
| raise HTTPException(status_code=500, detail="Internal server error while fetching entities") | ||
|
|
||
|
|
||
| @router.delete("/namespaces/{namespace_id}/entities/{entity_id}") | ||
| def delete_namespace_entity(namespace_id: str, entity_id: str) -> dict[str, Any]: | ||
| from kaizen.frontend.mcp.mcp_server import get_client | ||
|
|
||
| client = get_client() | ||
| try: | ||
| client.delete_entity_by_id(namespace_id, entity_id) | ||
| return {"success": True} | ||
| except Exception as e: | ||
| from fastapi import HTTPException | ||
|
|
||
| logger.error(f"Error deleting entity {entity_id} from namespace {namespace_id}: {e}") | ||
| raise HTTPException(status_code=400, detail="Internal server error while deleting entity") | ||
|
|
||
|
|
||
| @router.post("/namespaces/{namespace_id}/entities") | ||
| def create_namespace_entity(namespace_id: str, req: EntityCreateRequest) -> dict[str, Any]: | ||
| from kaizen.frontend.mcp.mcp_server import get_client | ||
| from kaizen.schema.core import Entity | ||
| from fastapi import HTTPException | ||
|
|
||
| # 1. Normalize and validate inputs before branching | ||
| entity_type = req.type.strip().lower() | ||
| if not req.content or not req.content.strip(): | ||
| raise HTTPException(status_code=422, detail="Entity content must be non-empty.") | ||
|
|
||
| # 2. Enforce specific schema typing prior to insertion | ||
| if entity_type == "guideline": | ||
| from kaizen.schema.tips import Tip | ||
|
|
||
| try: | ||
| # Tip expects content at the root, so we map req.content and unpack the metadata | ||
| tip_meta = {k: v for k, v in req.metadata.items() if k != "content"} | ||
| Tip(content=req.content, **tip_meta) | ||
| except Exception as e: | ||
| logger.error(f"Guideline validation failed: {e}") | ||
| raise HTTPException(status_code=422, detail=f"Invalid guideline metadata schema: {e}") | ||
|
|
||
| elif entity_type == "policy": | ||
| from kaizen.schema.policy import Policy, PolicyType | ||
|
|
||
| try: | ||
| # The Policy model checks the full payload | ||
| policy_meta = {k: v for k, v in req.metadata.items() if k != "content"} | ||
| Policy(content=req.content, type=PolicyType(req.metadata["policy_type"]), **policy_meta) | ||
| except Exception as e: | ||
| logger.error(f"Policy validation failed: {e}") | ||
| raise HTTPException(status_code=422, detail=f"Invalid policy metadata schema: {e}") | ||
|
|
||
| client = get_client() | ||
| try: | ||
| new_entity = Entity(type=entity_type, content=req.content, metadata=req.metadata) | ||
| # Using enable_conflict_resolution=False for a direct insert | ||
| updates = client.update_entities(namespace_id, [new_entity], enable_conflict_resolution=False) | ||
| if not updates: | ||
| raise Exception("Failed to insert entity. No updates returned.") | ||
| return {"success": True, "id": updates[0].id} | ||
| except Exception as e: | ||
| logger.error(f"Error creating entity in namespace {namespace_id}: {e}") | ||
| raise HTTPException(status_code=400, detail="Internal server error while creating entity") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.