File size: 4,329 Bytes
5e0b58b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"""Brain-5D local operator dashboard.

This package provides a web-based dashboard for monitoring and controlling
the Brain-5D runtime. It includes:

- A lightweight HTTP server with no external dependencies
- Real-time telemetry visualization
- Structural plasticity control (proposals, approval, history)
- Heatmap generation from B5D snapshots
- Documentation browsing with multi-format support (MD, DOCX, XLSX, CSV, JSON, PDF)
- Thread-safe state management with event notifications

The dashboard is designed to be run locally alongside the Brain-5D runtime
and accessed via a web browser.

Example:
    >>> from src.dashboard import serve_dashboard
    >>> serve_dashboard(host="127.0.0.1", port=8765)

    Or via command line:
    >>> python -m src.dashboard --host 0.0.0.0 --port 8765
"""

from __future__ import annotations

import logging

from src.version import BRAIN5D_VERSION_DISPLAY

from .docs_source import DocumentationSource, create_docs_source
from .heatmap_source import SnapshotHeatmapSource, create_heatmap_source
from .models import (
    DashboardSnapshot,
    ExperimentMetrics,
    HomeostasisMetrics,
    JSONValue,
    KnowledgeIntakeMetrics,
    LanguageOrganMetrics,
    LearningMetrics,
    NetworkMetrics,
    SelfOrganizationMetrics,
    SignalMetrics,
    SpikeMetrics,
    StorageMetrics,
    StructuralMetrics,
    SystemMetrics,
)
from .operator_bridge import OperatorBridge
from .server import serve_dashboard
from .state import (
    DashboardStateStore,
    create_state_store,
    get_current_state,
    publish_state,
)

# Package version
__version__ = BRAIN5D_VERSION_DISPLAY

# Module logger
logger = logging.getLogger(__name__)


# ============================================================================
# Convenience Functions
# ============================================================================


def create_default_dashboard(
    host: str = "127.0.0.1",
    port: int = 8765,
    snapshot_path: str | None = None,
    docs_root: str | None = None,
    state_store: DashboardStateStore | None = None,
    structural_bridge: OperatorBridge | None = None,
) -> None:
    """Create and run a dashboard with default configuration.

    This is a convenience wrapper around serve_dashboard that provides
    sensible defaults and handles path resolution.

    Args:
        host: Host address to bind to (default: 127.0.0.1).
        port: Port to bind to (default: 8765).
        snapshot_path: Optional path to the default B5D snapshot.
        docs_root: Optional path to the documentation root.
        state_store: Optional custom state store.
        structural_bridge: Optional operator bridge for structural control.

    Example:
        >>> from src.dashboard import create_default_dashboard
        >>> create_default_dashboard(port=9000)
    """
    from pathlib import Path

    # Resolve paths if provided
    snapshot = Path(snapshot_path).resolve() if snapshot_path else None
    docs = Path(docs_root).resolve() if docs_root else None

    # Create state store if not provided
    if state_store is None:
        state_store = create_state_store(with_history=True, history_limit=100)

    # Run the dashboard
    serve_dashboard(
        host=host,
        port=port,
        state=state_store,
        snapshot_path=snapshot,
        docs_root=docs,
        structural_bridge=structural_bridge,
    )


# ============================================================================
# Public API
# ============================================================================

__all__ = [
    # Core types
    "DashboardSnapshot",
    "DashboardStateStore",
    "OperatorBridge",
    "DocumentationSource",
    "SnapshotHeatmapSource",
    # Metric models
    "SystemMetrics",
    "LearningMetrics",
    "StorageMetrics",
    "SelfOrganizationMetrics",
    "HomeostasisMetrics",
    "StructuralMetrics",
    "SpikeMetrics",
    "NetworkMetrics",
    "LanguageOrganMetrics",
    "KnowledgeIntakeMetrics",
    "SignalMetrics",
    "ExperimentMetrics",
    "JSONValue",
    # Server functions
    "serve_dashboard",
    "create_default_dashboard",
    # State management
    "create_state_store",
    "get_current_state",
    "publish_state",
    # Factory functions
    "create_heatmap_source",
    "create_docs_source",
    # Version
    "__version__",
]