toolframe-streamlit-dashboard 0.4.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- toolframe_streamlit_dashboard/__init__.py +1 -0
- toolframe_streamlit_dashboard/app.py +73 -0
- toolframe_streamlit_dashboard/chrome.css +27 -0
- toolframe_streamlit_dashboard/dependencies.py +187 -0
- toolframe_streamlit_dashboard/history.py +126 -0
- toolframe_streamlit_dashboard/management.py +281 -0
- toolframe_streamlit_dashboard/plugin.py +189 -0
- toolframe_streamlit_dashboard-0.4.2.dist-info/METADATA +135 -0
- toolframe_streamlit_dashboard-0.4.2.dist-info/RECORD +13 -0
- toolframe_streamlit_dashboard-0.4.2.dist-info/WHEEL +4 -0
- toolframe_streamlit_dashboard-0.4.2.dist-info/entry_points.txt +2 -0
- toolframe_streamlit_dashboard-0.4.2.dist-info/licenses/LICENSE +202 -0
- toolframe_streamlit_dashboard-0.4.2.dist-info/licenses/NOTICE +2 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""One replaceable Streamlit runtime per shared page environment."""
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Executed by Streamlit in its normal script thread."""
|
|
2
|
+
|
|
3
|
+
from functools import partial
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
import streamlit as st
|
|
7
|
+
from toolframe_sdk import PluginError
|
|
8
|
+
|
|
9
|
+
from toolframe_streamlit_dashboard.management import render_management
|
|
10
|
+
from toolframe_streamlit_dashboard.plugin import current
|
|
11
|
+
|
|
12
|
+
provider = current()
|
|
13
|
+
epoch, pages = provider.snapshot
|
|
14
|
+
st.set_page_config(page_title="Toolframe", layout="wide")
|
|
15
|
+
st.html(Path(__file__).with_name("chrome.css"))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@st.fragment(run_every=1)
|
|
19
|
+
def access_header():
|
|
20
|
+
try:
|
|
21
|
+
current_access = provider.access("presentation")
|
|
22
|
+
except PluginError as error:
|
|
23
|
+
st.error(error.message)
|
|
24
|
+
return
|
|
25
|
+
if current_access["local_control"]:
|
|
26
|
+
st.caption("本機控制 · Local control")
|
|
27
|
+
if current_access["mode"] == "public":
|
|
28
|
+
reason = (
|
|
29
|
+
"Auth unavailable: " + current_access.get("detail", "")
|
|
30
|
+
if current_access["reason"] == "auth_unavailable"
|
|
31
|
+
else "Public business access"
|
|
32
|
+
)
|
|
33
|
+
st.warning("目前處於公開訪問模式 · " + reason)
|
|
34
|
+
elif current_access["mode"] == "waiting":
|
|
35
|
+
st.info("Access is preparing. Reconnecting shortly…")
|
|
36
|
+
else:
|
|
37
|
+
st.caption("Protected access")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
access = provider.access("presentation")
|
|
42
|
+
except PluginError as error:
|
|
43
|
+
st.error(error.message)
|
|
44
|
+
st.stop()
|
|
45
|
+
access_header()
|
|
46
|
+
if access["actor"] in {"password", "operator", "user"}:
|
|
47
|
+
st.markdown(
|
|
48
|
+
'<form method="post" action="/_toolframe/auth/logout"><button type="submit">Sign out</button></form>',
|
|
49
|
+
unsafe_allow_html=True,
|
|
50
|
+
)
|
|
51
|
+
else:
|
|
52
|
+
st.link_button("Sign in", access["login_url"])
|
|
53
|
+
navigation = [
|
|
54
|
+
st.Page(
|
|
55
|
+
partial(provider.render_page, page, epoch),
|
|
56
|
+
title=page.resource.resource.title or page.resource.resource.id,
|
|
57
|
+
url_path=f"{page.resource.owner}--{page.resource.resource.id}",
|
|
58
|
+
)
|
|
59
|
+
for page in pages
|
|
60
|
+
if set(page.resource.resource.required_scopes) <= set(access["allowed_scopes"])
|
|
61
|
+
]
|
|
62
|
+
if "system.plugins.read" in access["allowed_scopes"]:
|
|
63
|
+
navigation.append(
|
|
64
|
+
st.Page(
|
|
65
|
+
partial(render_management, provider),
|
|
66
|
+
title="Plugin management",
|
|
67
|
+
url_path="plugins",
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
if navigation:
|
|
71
|
+
st.navigation(navigation).run()
|
|
72
|
+
else:
|
|
73
|
+
st.info("No Dashboard pages are available for this access grant.")
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* Streamlit 1.61's native busy widget still owns visibility, its accessible
|
|
2
|
+
"Running..." label and the adjacent Stop button. Replace only its artwork. */
|
|
3
|
+
[data-testid="stStatusWidgetRunningIcon"] > * {
|
|
4
|
+
display: none;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
[data-testid="stStatusWidgetRunningIcon"]::after {
|
|
8
|
+
content: "";
|
|
9
|
+
display: block;
|
|
10
|
+
width: 1rem;
|
|
11
|
+
height: 1rem;
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
border: 2px solid currentColor;
|
|
14
|
+
border-right-color: transparent;
|
|
15
|
+
border-radius: 50%;
|
|
16
|
+
animation: toolframe-busy-spin 0.8s linear infinite;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@keyframes toolframe-busy-spin {
|
|
20
|
+
to { transform: rotate(360deg); }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@media (prefers-reduced-motion: reduce) {
|
|
24
|
+
[data-testid="stStatusWidgetRunningIcon"]::after {
|
|
25
|
+
animation: none;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"""Render the host's topology without planning or performing an operation."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import textwrap
|
|
5
|
+
|
|
6
|
+
import streamlit as st
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def dot_quote(value):
|
|
10
|
+
return json.dumps(str(value), ensure_ascii=False)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def graph_dot(report, focus=None, action="reload"):
|
|
14
|
+
impact = report.get("impacts", {}).get(focus, {}).get(action, {})
|
|
15
|
+
affected = set(impact.get("affected", []))
|
|
16
|
+
optional = set(impact.get("optional_consumers", []))
|
|
17
|
+
entrances = {item["provider"] for item in impact.get("presentations", [])}
|
|
18
|
+
lines = [
|
|
19
|
+
"digraph plugins {",
|
|
20
|
+
'graph [rankdir=TB, bgcolor="transparent", pad=0.12, nodesep=0.2, ranksep=0.35];',
|
|
21
|
+
'node [shape=box, style="rounded,filled", fontname="sans-serif", fontsize=13, margin="0.16,0.12"];',
|
|
22
|
+
'edge [fontname="sans-serif", fontsize=10, color="#94a3b8", fontcolor="#94a3b8", arrowsize=0.7];',
|
|
23
|
+
]
|
|
24
|
+
for node in report["nodes"]:
|
|
25
|
+
state = node["state"]
|
|
26
|
+
if node.get("healthy"):
|
|
27
|
+
fill, stroke, health = "#dcfce7", "#15803d", "healthy"
|
|
28
|
+
elif state in {"failed", "blocked", "missing", "ambiguous"}:
|
|
29
|
+
fill, stroke, health = "#ffe4e6", "#be123c", "not ready"
|
|
30
|
+
elif state in {"disabled", "stopped", "removed", "installed"}:
|
|
31
|
+
fill, stroke, health = "#e2e8f0", "#64748b", ""
|
|
32
|
+
else:
|
|
33
|
+
fill, stroke, health = "#fef3c7", "#b45309", "not ready"
|
|
34
|
+
outline, role = stroke, ""
|
|
35
|
+
if node["id"] == focus:
|
|
36
|
+
outline, role = "#2563eb", "selected"
|
|
37
|
+
elif node["id"] in affected:
|
|
38
|
+
outline, role = "#ea580c", "affected"
|
|
39
|
+
elif node["id"] in optional:
|
|
40
|
+
outline, role = "#d97706", "optional consumer"
|
|
41
|
+
elif node["id"] in entrances:
|
|
42
|
+
outline, role = "#a855f7", "entry refresh"
|
|
43
|
+
status = f"{state} · {health}" if health and state != health else state
|
|
44
|
+
name = "\n".join(textwrap.wrap(node["label"], width=18))
|
|
45
|
+
label = f"{name}\n{status}" + (f"\n{role}" if role else "")
|
|
46
|
+
lines.append(
|
|
47
|
+
f"{dot_quote(node['id'])} [label={dot_quote(label)}, "
|
|
48
|
+
f'fillcolor="{fill}", color="{outline}", fontcolor="#0f172a", '
|
|
49
|
+
f"penwidth={3 if role else 1.2}];"
|
|
50
|
+
)
|
|
51
|
+
for edge in report["edges"]:
|
|
52
|
+
kind = edge["kind"]
|
|
53
|
+
style = {"required": "solid", "optional": "dashed", "presentation": "dotted"}[
|
|
54
|
+
kind
|
|
55
|
+
]
|
|
56
|
+
color = "#a78bfa" if kind == "presentation" else "#94a3b8"
|
|
57
|
+
if edge["state"] == "missing":
|
|
58
|
+
color = "#f87171"
|
|
59
|
+
# Keep the overview readable; exact services and versions are listed in
|
|
60
|
+
# the relationship table. Arrow direction is consumer -> supplier.
|
|
61
|
+
label = edge["label"].split(".")[0] if kind == "presentation" else kind
|
|
62
|
+
lines.append(
|
|
63
|
+
f"{dot_quote(edge['source'])} -> {dot_quote(edge['target'])} "
|
|
64
|
+
f'[label={dot_quote(label)}, style="{style}", color="{color}", '
|
|
65
|
+
f'fontcolor="{color}", minlen={3 if kind == "presentation" else 1}];'
|
|
66
|
+
)
|
|
67
|
+
lines.append("}")
|
|
68
|
+
return "\n".join(lines)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def render_dependencies(status):
|
|
72
|
+
with st.expander("Plugin dependencies & impact", expanded=False):
|
|
73
|
+
st.caption(
|
|
74
|
+
"This graph follows installed plugins and their current state. "
|
|
75
|
+
"Refresh status after installing or changing a plugin. "
|
|
76
|
+
"Creating source with plugin new does not install it; use plugin add first."
|
|
77
|
+
)
|
|
78
|
+
report = status.get("dependency_graph")
|
|
79
|
+
if not report:
|
|
80
|
+
st.info("Update core to view the dependency graph.")
|
|
81
|
+
return
|
|
82
|
+
plugins = [node for node in report["nodes"] if node["kind"] != "unresolved"]
|
|
83
|
+
if not plugins:
|
|
84
|
+
st.info("No plugins are installed yet.")
|
|
85
|
+
return
|
|
86
|
+
left, right = st.columns(2)
|
|
87
|
+
focus = left.selectbox(
|
|
88
|
+
"Inspect plugin",
|
|
89
|
+
[None, *(node["id"] for node in plugins)],
|
|
90
|
+
format_func=lambda name: name or "All plugins",
|
|
91
|
+
key="dependency-focus",
|
|
92
|
+
)
|
|
93
|
+
action = right.selectbox(
|
|
94
|
+
"Impact of",
|
|
95
|
+
["reload", "disable"],
|
|
96
|
+
key="dependency-action",
|
|
97
|
+
disabled=focus is None,
|
|
98
|
+
)
|
|
99
|
+
st.caption(
|
|
100
|
+
"Arrows point from a plugin to its dependency or presentation provider. "
|
|
101
|
+
"Solid: required · Dashed: optional · Dotted: presentation."
|
|
102
|
+
)
|
|
103
|
+
with st.container(key="dependency-diagram"):
|
|
104
|
+
# Streamlit's chart CSS otherwise overrides DOT's measured text
|
|
105
|
+
# sizes with 9.6px, making a narrow embedded graph hard to read.
|
|
106
|
+
st.html(
|
|
107
|
+
"""<style>
|
|
108
|
+
.st-key-dependency-diagram .stGraphVizChart .node text { font-size: 13px; }
|
|
109
|
+
.st-key-dependency-diagram .stGraphVizChart .edge text { font-size: 10px; }
|
|
110
|
+
</style>"""
|
|
111
|
+
)
|
|
112
|
+
st.graphviz_chart(graph_dot(report, focus, action), width="stretch")
|
|
113
|
+
st.caption(
|
|
114
|
+
"Green: healthy · Amber: not ready · Red: blocked / failed / missing · "
|
|
115
|
+
"Gray: inactive. Select a plugin to highlight its impact. "
|
|
116
|
+
"Use the graph's full-screen control for a larger view."
|
|
117
|
+
)
|
|
118
|
+
if focus:
|
|
119
|
+
node = next(node for node in plugins if node["id"] == focus)
|
|
120
|
+
st.caption(
|
|
121
|
+
f"{focus} · {node['state']} · version {node.get('version') or 'unknown'} · "
|
|
122
|
+
f"{node.get('in_flight', 0)} in-flight calls · "
|
|
123
|
+
f"definition: {node['definition_source']}"
|
|
124
|
+
)
|
|
125
|
+
if node.get("blocked_by"):
|
|
126
|
+
st.warning("Blocked by: " + ", ".join(node["blocked_by"]))
|
|
127
|
+
impact = report["impacts"].get(focus, {}).get(action)
|
|
128
|
+
if impact:
|
|
129
|
+
st.markdown("**Restart / stop cohort**")
|
|
130
|
+
st.write(", ".join(impact["affected"]) or "None")
|
|
131
|
+
if impact["presentation_providers"]:
|
|
132
|
+
st.caption(
|
|
133
|
+
"Includes shared presentation processes: "
|
|
134
|
+
+ ", ".join(impact["presentation_providers"])
|
|
135
|
+
+ ". Related clients may reconnect."
|
|
136
|
+
)
|
|
137
|
+
if impact["optional_consumers"]:
|
|
138
|
+
st.write(
|
|
139
|
+
"Optional consumers (not restarted): "
|
|
140
|
+
+ ", ".join(impact["optional_consumers"])
|
|
141
|
+
)
|
|
142
|
+
if impact["presentations"]:
|
|
143
|
+
st.markdown("**Entries that may reconnect or refresh**")
|
|
144
|
+
st.dataframe(
|
|
145
|
+
[
|
|
146
|
+
{
|
|
147
|
+
"Plugin": item["owner"],
|
|
148
|
+
"Provider": item["provider"],
|
|
149
|
+
"Entry": item["kind"],
|
|
150
|
+
"Resources": ", ".join(item["resources"]),
|
|
151
|
+
}
|
|
152
|
+
for item in impact["presentations"]
|
|
153
|
+
],
|
|
154
|
+
hide_index=True,
|
|
155
|
+
width="stretch",
|
|
156
|
+
)
|
|
157
|
+
else:
|
|
158
|
+
st.info(
|
|
159
|
+
"This plugin is outside the selected runtime graph. Its last known "
|
|
160
|
+
"declarations are shown; preview enable to inspect an activation."
|
|
161
|
+
)
|
|
162
|
+
st.caption(
|
|
163
|
+
"Read-only view of the selected definitions. Inactive declarations are "
|
|
164
|
+
"not live bindings. A new candidate, changed bindings or other pending "
|
|
165
|
+
"changes can alter the impact; use Preview operation before applying."
|
|
166
|
+
)
|
|
167
|
+
relationships = [
|
|
168
|
+
edge
|
|
169
|
+
for edge in report["edges"]
|
|
170
|
+
if focus is None or focus in (edge["source"], edge["target"])
|
|
171
|
+
]
|
|
172
|
+
if relationships:
|
|
173
|
+
st.markdown("**Relationships**")
|
|
174
|
+
st.dataframe(
|
|
175
|
+
[
|
|
176
|
+
{
|
|
177
|
+
"Plugin": edge["source"],
|
|
178
|
+
"Dependency / provider": edge["target"],
|
|
179
|
+
"Relation": edge["kind"],
|
|
180
|
+
"Service / resource": edge["label"],
|
|
181
|
+
"Binding": edge["state"],
|
|
182
|
+
}
|
|
183
|
+
for edge in relationships
|
|
184
|
+
],
|
|
185
|
+
hide_index=True,
|
|
186
|
+
width="stretch",
|
|
187
|
+
)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""Paged journal queries with permanent record numbers and browser-local time."""
|
|
2
|
+
|
|
3
|
+
from datetime import UTC, datetime, timedelta, timezone
|
|
4
|
+
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
|
5
|
+
|
|
6
|
+
import streamlit as st
|
|
7
|
+
from toolframe_sdk import PluginError
|
|
8
|
+
|
|
9
|
+
_PREFIX = "operation_history_"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def reset_history():
|
|
13
|
+
st.session_state[_PREFIX + "page"] = 1
|
|
14
|
+
st.session_state[_PREFIX + "through"] = None
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def move_page(page):
|
|
18
|
+
st.session_state[_PREFIX + "page"] = page
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def local_timestamp(value):
|
|
22
|
+
if value is None:
|
|
23
|
+
return "Time unavailable"
|
|
24
|
+
zone = UTC
|
|
25
|
+
name, offset = st.context.timezone, st.context.timezone_offset
|
|
26
|
+
if name:
|
|
27
|
+
try:
|
|
28
|
+
zone = ZoneInfo(name)
|
|
29
|
+
except ZoneInfoNotFoundError, ValueError:
|
|
30
|
+
name = None
|
|
31
|
+
if not name and offset is not None and -1440 < offset < 1440:
|
|
32
|
+
zone = timezone(-timedelta(minutes=offset))
|
|
33
|
+
return datetime.fromtimestamp(value, zone).strftime("%Y-%m-%d %H:%M:%S %Z")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def render_history(provider, permissions, track_operation, submit):
|
|
37
|
+
st.subheader("Operations")
|
|
38
|
+
state = st.session_state
|
|
39
|
+
params = {
|
|
40
|
+
"page": state.get(_PREFIX + "page", 1),
|
|
41
|
+
"page_size": state.get(_PREFIX + "page_size", 10),
|
|
42
|
+
"through": state.get(_PREFIX + "through"),
|
|
43
|
+
}
|
|
44
|
+
selectors = (
|
|
45
|
+
("target", "Filter by plugin", "All plugins"),
|
|
46
|
+
("kind", "Filter by action", "All actions"),
|
|
47
|
+
("status", "Filter by result", "All results"),
|
|
48
|
+
)
|
|
49
|
+
for field, _, all_label in selectors:
|
|
50
|
+
choice = state.get(_PREFIX + field, all_label)
|
|
51
|
+
if choice != all_label:
|
|
52
|
+
params[field] = (
|
|
53
|
+
"" if field == "target" and choice == "Application" else choice
|
|
54
|
+
)
|
|
55
|
+
try:
|
|
56
|
+
result = provider.manage("operations", params)
|
|
57
|
+
except PluginError as error:
|
|
58
|
+
st.error(f"Unable to load operation history: {error.message}")
|
|
59
|
+
return
|
|
60
|
+
state[_PREFIX + "page"] = result["page"]
|
|
61
|
+
state[_PREFIX + "through"] = result["through"]
|
|
62
|
+
for column, (field, label, all_label) in zip(st.columns(3), selectors):
|
|
63
|
+
options = [all_label] + (["Application"] if field == "target" else [])
|
|
64
|
+
options += result["filters"][field]
|
|
65
|
+
selected = state.get(_PREFIX + field, all_label)
|
|
66
|
+
if selected not in options:
|
|
67
|
+
options.append(selected)
|
|
68
|
+
with column:
|
|
69
|
+
st.selectbox(label, options, key=_PREFIX + field, on_change=reset_history)
|
|
70
|
+
size, refresh = st.columns(2, vertical_alignment="bottom")
|
|
71
|
+
with size:
|
|
72
|
+
st.selectbox(
|
|
73
|
+
"Rows per page",
|
|
74
|
+
[10, 25, 50],
|
|
75
|
+
key=_PREFIX + "page_size",
|
|
76
|
+
on_change=reset_history,
|
|
77
|
+
)
|
|
78
|
+
with refresh, st.container(horizontal=True, horizontal_alignment="right"):
|
|
79
|
+
st.button("Refresh history", on_click=reset_history)
|
|
80
|
+
page, total = result["page"], result["total"]
|
|
81
|
+
first = (page - 1) * result["page_size"] + 1 if total else 0
|
|
82
|
+
last = first + len(result["items"]) - 1 if total else 0
|
|
83
|
+
st.caption(
|
|
84
|
+
f"Newest first · Page {page} of {result['pages']} · {first}–{last} of {total} operations. "
|
|
85
|
+
"Permanent operation numbers; times use your browser's time zone."
|
|
86
|
+
)
|
|
87
|
+
if result["newer_count"]:
|
|
88
|
+
st.info(
|
|
89
|
+
f"{result['newer_count']} newer operations. Refresh history to include them."
|
|
90
|
+
)
|
|
91
|
+
if not result["items"]:
|
|
92
|
+
st.info("No operations match these filters.")
|
|
93
|
+
for operation in result["items"]:
|
|
94
|
+
action = (
|
|
95
|
+
f"plan {operation['request'].get('action', 'apply')}"
|
|
96
|
+
if operation["kind"] == "plan"
|
|
97
|
+
else operation["kind"]
|
|
98
|
+
)
|
|
99
|
+
label = (
|
|
100
|
+
f"#{operation['sequence']} · {local_timestamp(operation['created'])} · "
|
|
101
|
+
f"{action} · {operation.get('target') or 'application'} · {operation['status']}"
|
|
102
|
+
)
|
|
103
|
+
with st.expander(label):
|
|
104
|
+
st.json(operation)
|
|
105
|
+
label = "Review preview" if operation["kind"] == "plan" else "View result"
|
|
106
|
+
if st.button(label, key=f"view-{operation['id']}"):
|
|
107
|
+
track_operation(operation["id"])
|
|
108
|
+
scope = (
|
|
109
|
+
"system.migrations.manage"
|
|
110
|
+
if operation["kind"] in {"migrate-plan", "migrate-apply"}
|
|
111
|
+
else "system.plugins.manage"
|
|
112
|
+
)
|
|
113
|
+
if operation["status"] in {"queued", "running"} and st.button(
|
|
114
|
+
"Request cancellation",
|
|
115
|
+
key=f"cancel-{operation['id']}",
|
|
116
|
+
disabled=scope not in permissions,
|
|
117
|
+
):
|
|
118
|
+
submit(provider, "cancel", {"id": operation["id"]})
|
|
119
|
+
with st.container(horizontal=True, horizontal_alignment="distribute"):
|
|
120
|
+
st.button("Newer", disabled=page <= 1, on_click=move_page, args=(page - 1,))
|
|
121
|
+
st.button(
|
|
122
|
+
"Older",
|
|
123
|
+
disabled=page >= result["pages"],
|
|
124
|
+
on_click=move_page,
|
|
125
|
+
args=(page + 1,),
|
|
126
|
+
)
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"""Thin UI over host management operations, with no installer or database logic."""
|
|
2
|
+
|
|
3
|
+
import streamlit as st
|
|
4
|
+
from toolframe_sdk import PluginError
|
|
5
|
+
|
|
6
|
+
from .dependencies import render_dependencies
|
|
7
|
+
from .history import local_timestamp, render_history, reset_history
|
|
8
|
+
|
|
9
|
+
_OPERATION_QUERY_KEY = "operation"
|
|
10
|
+
_PLANNED_ACTIONS = {"enable", "reload", "disable", "stop", "remove"}
|
|
11
|
+
_PENDING = {"queued", "running"}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def render_management(provider):
|
|
15
|
+
st.title("Plugin management")
|
|
16
|
+
try:
|
|
17
|
+
permissions = provider.access("presentation")["allowed_scopes"]
|
|
18
|
+
status = provider.manage("status")
|
|
19
|
+
except PluginError as error:
|
|
20
|
+
st.error(str(error))
|
|
21
|
+
return
|
|
22
|
+
st.caption(f"Application: {status['application']} · Core: {status['core']}")
|
|
23
|
+
for field in ("configuration_error", "orphaned_workers", "forward_repair"):
|
|
24
|
+
if status.get(field):
|
|
25
|
+
st.error(field.replace("_", " ").capitalize())
|
|
26
|
+
st.json(status[field])
|
|
27
|
+
rows = [
|
|
28
|
+
{
|
|
29
|
+
"Plugin": item["id"],
|
|
30
|
+
"Enabled": item["desired"].get("enabled", False),
|
|
31
|
+
"State": item["runtime"].get("state", "installed"),
|
|
32
|
+
"Healthy": item.get(
|
|
33
|
+
"healthy",
|
|
34
|
+
item["health_fresh"] and item["runtime"].get("state") == "active",
|
|
35
|
+
),
|
|
36
|
+
"Active": (item["active"] or "")[:12],
|
|
37
|
+
"Candidate": (item["candidate"] or "")[:12],
|
|
38
|
+
}
|
|
39
|
+
for item in status["plugins"]
|
|
40
|
+
]
|
|
41
|
+
st.dataframe(rows, hide_index=True, width="stretch")
|
|
42
|
+
render_dependencies(status)
|
|
43
|
+
st.caption(
|
|
44
|
+
"Disabled plugins remain in this list so you can enable them again. "
|
|
45
|
+
"Their pages and tools are removed when disabling completes."
|
|
46
|
+
)
|
|
47
|
+
if st.button("Refresh status"):
|
|
48
|
+
st.rerun()
|
|
49
|
+
can_manage = "system.plugins.manage" in permissions
|
|
50
|
+
can_migrate = "system.migrations.manage" in permissions
|
|
51
|
+
if not can_manage and not can_migrate:
|
|
52
|
+
st.caption("Read-only plugin diagnostics")
|
|
53
|
+
render_operation(provider)
|
|
54
|
+
render_history(provider, permissions, track_operation, submit)
|
|
55
|
+
return
|
|
56
|
+
with st.form("install"):
|
|
57
|
+
source = st.text_input(
|
|
58
|
+
"Plugin source",
|
|
59
|
+
placeholder="path:/absolute/plugin or pypi:package==version",
|
|
60
|
+
)
|
|
61
|
+
enable = st.checkbox("Enable after validation", value=False)
|
|
62
|
+
if st.form_submit_button("Install and validate", disabled=not can_manage):
|
|
63
|
+
if not source.strip():
|
|
64
|
+
st.error("Enter a plugin source.")
|
|
65
|
+
else:
|
|
66
|
+
submit(provider, "add", {"source": source.strip(), "enable": enable})
|
|
67
|
+
identifiers = [
|
|
68
|
+
item["id"]
|
|
69
|
+
for item in status["plugins"]
|
|
70
|
+
if item["desired"].get("installed") is not False
|
|
71
|
+
]
|
|
72
|
+
if identifiers:
|
|
73
|
+
with st.container(border=True):
|
|
74
|
+
identifier = st.selectbox("Plugin", identifiers)
|
|
75
|
+
enabled = next(
|
|
76
|
+
item["desired"].get("enabled", False)
|
|
77
|
+
for item in status["plugins"]
|
|
78
|
+
if item["id"] == identifier
|
|
79
|
+
)
|
|
80
|
+
actions = (
|
|
81
|
+
["validate", "update", "enable", "reload", "disable", "stop", "remove"]
|
|
82
|
+
if enabled
|
|
83
|
+
else ["enable", "validate", "update", "remove"]
|
|
84
|
+
)
|
|
85
|
+
if not enabled:
|
|
86
|
+
st.caption(
|
|
87
|
+
"This plugin is disabled. Enable it to restore its pages and tools."
|
|
88
|
+
)
|
|
89
|
+
action = st.selectbox(
|
|
90
|
+
"Operation",
|
|
91
|
+
(actions if can_manage else [])
|
|
92
|
+
+ (["migrate-plan"] if can_migrate else []),
|
|
93
|
+
)
|
|
94
|
+
params = {"id": identifier}
|
|
95
|
+
if action == "validate":
|
|
96
|
+
params["runtime"] = st.checkbox(
|
|
97
|
+
"Validate in a temporary runtime", value=False
|
|
98
|
+
)
|
|
99
|
+
if action == "stop":
|
|
100
|
+
params["force"] = st.checkbox(
|
|
101
|
+
"Force stop (interrupts active calls)", value=False
|
|
102
|
+
)
|
|
103
|
+
planned = action in _PLANNED_ACTIONS and not params.get("force", False)
|
|
104
|
+
if planned:
|
|
105
|
+
st.caption(
|
|
106
|
+
"First preview the affected plugins, then apply the operation below. "
|
|
107
|
+
"Creating a preview does not change plugin state."
|
|
108
|
+
)
|
|
109
|
+
label = "Preview operation" if planned else "Run operation"
|
|
110
|
+
if st.button(label):
|
|
111
|
+
if planned:
|
|
112
|
+
submit(
|
|
113
|
+
provider,
|
|
114
|
+
"plan",
|
|
115
|
+
{"action": action, "id": identifier},
|
|
116
|
+
)
|
|
117
|
+
else:
|
|
118
|
+
submit(provider, action, params)
|
|
119
|
+
render_operation(provider)
|
|
120
|
+
with st.form("migration"):
|
|
121
|
+
migration_owner = st.selectbox("Migration owner", identifiers)
|
|
122
|
+
plan_id = st.text_input("Reviewed migration plan ID")
|
|
123
|
+
if st.form_submit_button(
|
|
124
|
+
"Apply reviewed migration", disabled=not can_migrate
|
|
125
|
+
):
|
|
126
|
+
if plan_id.strip():
|
|
127
|
+
submit(
|
|
128
|
+
provider,
|
|
129
|
+
"migrate-apply",
|
|
130
|
+
{"id": migration_owner, "plan_id": plan_id.strip()},
|
|
131
|
+
)
|
|
132
|
+
else:
|
|
133
|
+
st.error("Run migrate-plan and review its result first.")
|
|
134
|
+
if not identifiers:
|
|
135
|
+
render_operation(provider)
|
|
136
|
+
render_history(provider, permissions, track_operation, submit)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def submit(provider, action, params):
|
|
140
|
+
try:
|
|
141
|
+
result = provider.manage(action, params)
|
|
142
|
+
except PluginError as error:
|
|
143
|
+
st.error(f"{error.code}: {error}")
|
|
144
|
+
return
|
|
145
|
+
if isinstance(result, dict) and result.get("id"):
|
|
146
|
+
reset_history()
|
|
147
|
+
track_operation(result["id"])
|
|
148
|
+
else:
|
|
149
|
+
st.error(
|
|
150
|
+
"Core did not return an operation ID. Check operation history before retrying."
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def track_operation(operation_id):
|
|
155
|
+
# A Dashboard replacement clears Session State. The URL survives reconnects
|
|
156
|
+
# and lets a new worker resume reading the durable core operation journal.
|
|
157
|
+
st.query_params[_OPERATION_QUERY_KEY] = operation_id
|
|
158
|
+
st.rerun()
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def load_operation(provider, operation_id):
|
|
162
|
+
try:
|
|
163
|
+
operation = provider.manage("operation", {"id": operation_id})
|
|
164
|
+
except PluginError as error:
|
|
165
|
+
st.error(f"{error.code}: {error}")
|
|
166
|
+
return None
|
|
167
|
+
if not operation:
|
|
168
|
+
st.error(f"Operation {operation_id} was not found.")
|
|
169
|
+
return operation
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def operation_label(operation):
|
|
173
|
+
action = (
|
|
174
|
+
operation.get("request", {}).get("action", "operation")
|
|
175
|
+
if operation["kind"] == "plan"
|
|
176
|
+
else operation["kind"]
|
|
177
|
+
)
|
|
178
|
+
return f"{action} · {operation.get('target') or 'application'}"
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
@st.fragment(run_every=1)
|
|
182
|
+
def poll_operation(provider, operation_id):
|
|
183
|
+
operation = load_operation(provider, operation_id)
|
|
184
|
+
if not operation:
|
|
185
|
+
return
|
|
186
|
+
if operation["status"] not in _PENDING:
|
|
187
|
+
# Rebuild the status table and navigation, and remove this polling
|
|
188
|
+
# fragment once the operation is terminal.
|
|
189
|
+
st.rerun()
|
|
190
|
+
label = operation_label(operation)
|
|
191
|
+
if operation["kind"] == "plan":
|
|
192
|
+
st.info(f"Preparing preview: {label}. No changes have been applied.")
|
|
193
|
+
else:
|
|
194
|
+
st.info(f"In progress: {label} · {operation.get('phase', operation['status'])}")
|
|
195
|
+
st.caption(
|
|
196
|
+
"Status updates automatically. You can also refresh or reconnect to this page."
|
|
197
|
+
)
|
|
198
|
+
scope = (
|
|
199
|
+
"system.migrations.manage"
|
|
200
|
+
if operation["kind"] in {"migrate-plan", "migrate-apply"}
|
|
201
|
+
else "system.plugins.manage"
|
|
202
|
+
)
|
|
203
|
+
if st.button(
|
|
204
|
+
"Request cancellation",
|
|
205
|
+
key=f"pending-cancel-{operation_id}",
|
|
206
|
+
disabled=scope not in provider.access("presentation")["allowed_scopes"],
|
|
207
|
+
):
|
|
208
|
+
submit(provider, "cancel", {"id": operation_id})
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def render_operation(provider):
|
|
212
|
+
operation_id = st.query_params.get(_OPERATION_QUERY_KEY)
|
|
213
|
+
if not operation_id:
|
|
214
|
+
return
|
|
215
|
+
operation = load_operation(provider, operation_id)
|
|
216
|
+
if not operation:
|
|
217
|
+
return
|
|
218
|
+
st.subheader("Operation result")
|
|
219
|
+
if operation.get("sequence"):
|
|
220
|
+
st.caption(
|
|
221
|
+
f"Operation #{operation['sequence']} · {local_timestamp(operation.get('created'))}"
|
|
222
|
+
)
|
|
223
|
+
st.caption(f"Operation ID: {operation_id}")
|
|
224
|
+
status = operation["status"]
|
|
225
|
+
if status in _PENDING:
|
|
226
|
+
poll_operation(provider, operation_id)
|
|
227
|
+
return
|
|
228
|
+
label = operation_label(operation)
|
|
229
|
+
if status != "succeeded":
|
|
230
|
+
error = operation.get("error") or {}
|
|
231
|
+
code = error.get("code", "operation_failed")
|
|
232
|
+
message = error.get("message", "The operation did not complete.")
|
|
233
|
+
st.error(f"{label} · {status} ({code}): {message}")
|
|
234
|
+
if code == "stale_plan":
|
|
235
|
+
st.info("Create a new preview to review the current state before applying.")
|
|
236
|
+
elif operation["kind"] == "plan":
|
|
237
|
+
render_plan_preview(provider, operation.get("result"))
|
|
238
|
+
else:
|
|
239
|
+
st.success(f"Completed: {label}.")
|
|
240
|
+
with st.expander("Operation details"):
|
|
241
|
+
st.json(operation)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def render_plan_preview(provider, plan):
|
|
245
|
+
if not isinstance(plan, dict):
|
|
246
|
+
st.error("Plan operation completed without a reviewable plan.")
|
|
247
|
+
return
|
|
248
|
+
basis = plan.get("basis") or {}
|
|
249
|
+
if (
|
|
250
|
+
plan.get("action") not in _PLANNED_ACTIONS
|
|
251
|
+
or not all(plan.get(key) for key in ("target", "plan_id"))
|
|
252
|
+
or basis.get("revision") is None
|
|
253
|
+
):
|
|
254
|
+
st.error("The completed plan is missing required apply details.")
|
|
255
|
+
return
|
|
256
|
+
st.info(
|
|
257
|
+
f"Preview ready: {plan['action']} · {plan['target']}. "
|
|
258
|
+
"No changes have been applied."
|
|
259
|
+
)
|
|
260
|
+
st.write("Affected plugins", plan.get("affected", []))
|
|
261
|
+
if "streamlit-dashboard" in plan.get("affected", []):
|
|
262
|
+
st.caption("The Dashboard may reconnect while this operation is applied.")
|
|
263
|
+
if plan.get("missing_dependencies"):
|
|
264
|
+
st.write("Missing dependencies", plan["missing_dependencies"])
|
|
265
|
+
if plan.get("migrations"):
|
|
266
|
+
st.write("Migration requirements", plan["migrations"])
|
|
267
|
+
if st.button(
|
|
268
|
+
f"Apply {plan['action']}",
|
|
269
|
+
type="primary",
|
|
270
|
+
disabled="system.plugins.manage"
|
|
271
|
+
not in provider.access("presentation")["allowed_scopes"],
|
|
272
|
+
):
|
|
273
|
+
submit(
|
|
274
|
+
provider,
|
|
275
|
+
plan["action"],
|
|
276
|
+
{
|
|
277
|
+
"id": plan["target"],
|
|
278
|
+
"plan_id": plan["plan_id"],
|
|
279
|
+
"expected_revision": basis["revision"],
|
|
280
|
+
},
|
|
281
|
+
)
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import inspect
|
|
5
|
+
import threading
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from toolframe_sdk import (
|
|
10
|
+
AuthorizationSpec,
|
|
11
|
+
OwnedResource,
|
|
12
|
+
PageContext,
|
|
13
|
+
Plugin,
|
|
14
|
+
PluginDefinition,
|
|
15
|
+
PluginError,
|
|
16
|
+
load_object,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
_current = None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def current():
|
|
23
|
+
if _current is None:
|
|
24
|
+
raise PluginError("dashboard_unavailable", "Dashboard runtime is not active")
|
|
25
|
+
return _current
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True)
|
|
29
|
+
class Page:
|
|
30
|
+
resource: OwnedResource
|
|
31
|
+
render: object
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class DashboardProvider(Plugin):
|
|
35
|
+
def __init__(self, context):
|
|
36
|
+
super().__init__(context)
|
|
37
|
+
self.server = None
|
|
38
|
+
self.url = None
|
|
39
|
+
self.loop = None
|
|
40
|
+
self.snapshot = (None, ())
|
|
41
|
+
self.staged = {}
|
|
42
|
+
|
|
43
|
+
async def activate(self):
|
|
44
|
+
global _current
|
|
45
|
+
from streamlit import config
|
|
46
|
+
from streamlit.web.server import Server
|
|
47
|
+
|
|
48
|
+
self.loop = asyncio.get_running_loop()
|
|
49
|
+
for name, value in {
|
|
50
|
+
"server.address": "127.0.0.1",
|
|
51
|
+
"server.port": 0,
|
|
52
|
+
"server.headless": True,
|
|
53
|
+
"server.fileWatcherType": "none",
|
|
54
|
+
"server.runOnSave": False,
|
|
55
|
+
"server.enableStaticServing": False,
|
|
56
|
+
"browser.gatherUsageStats": False,
|
|
57
|
+
"client.toolbarMode": "viewer",
|
|
58
|
+
}.items():
|
|
59
|
+
config.set_option(name, value)
|
|
60
|
+
_current = self
|
|
61
|
+
self.server = Server(str(Path(__file__).with_name("app.py")), is_hello=False)
|
|
62
|
+
await self.server.start()
|
|
63
|
+
self.url = f"http://127.0.0.1:{config.get_option('server.port')}"
|
|
64
|
+
|
|
65
|
+
async def health(self):
|
|
66
|
+
return {
|
|
67
|
+
"runtime": "ready",
|
|
68
|
+
"business": "not_provided",
|
|
69
|
+
"http_url": self.url,
|
|
70
|
+
"epoch": self.snapshot[0],
|
|
71
|
+
"pages": [page.resource.key for page in self.snapshot[1]],
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async def dispose(self):
|
|
75
|
+
global _current
|
|
76
|
+
if self.server:
|
|
77
|
+
self.server.stop()
|
|
78
|
+
async with asyncio.timeout(8):
|
|
79
|
+
await self.server.stopped
|
|
80
|
+
threads = [
|
|
81
|
+
thread
|
|
82
|
+
for thread in threading.enumerate()
|
|
83
|
+
if thread.name.startswith("ScriptRunner.scriptThread")
|
|
84
|
+
]
|
|
85
|
+
for thread in threads:
|
|
86
|
+
await asyncio.to_thread(thread.join, 1)
|
|
87
|
+
if any(thread.is_alive() for thread in threads):
|
|
88
|
+
raise PluginError(
|
|
89
|
+
"cleanup_failed", "A Streamlit script thread has not exited"
|
|
90
|
+
)
|
|
91
|
+
if _current is self:
|
|
92
|
+
_current = None
|
|
93
|
+
await super().dispose()
|
|
94
|
+
|
|
95
|
+
async def prepare(self, resources, epoch):
|
|
96
|
+
pages, seen = [], set()
|
|
97
|
+
for resource in resources:
|
|
98
|
+
if resource.resource.kind != "dashboard.page":
|
|
99
|
+
raise PluginError(
|
|
100
|
+
"unsupported_resource",
|
|
101
|
+
"Dashboard accepts whole-page resources only",
|
|
102
|
+
)
|
|
103
|
+
if resource.key in seen:
|
|
104
|
+
raise PluginError("duplicate_resource", resource.key)
|
|
105
|
+
seen.add(resource.key)
|
|
106
|
+
render = load_object(resource.resource.data["entrypoint"])
|
|
107
|
+
if not callable(render) or inspect.iscoroutinefunction(render):
|
|
108
|
+
raise PluginError(
|
|
109
|
+
"invalid_page",
|
|
110
|
+
"Page render(context) must be a synchronous callable",
|
|
111
|
+
)
|
|
112
|
+
pages.append(Page(resource, render))
|
|
113
|
+
self.staged[epoch] = tuple(
|
|
114
|
+
sorted(
|
|
115
|
+
pages,
|
|
116
|
+
key=lambda page: (
|
|
117
|
+
page.resource.resource.data.get("order", 0),
|
|
118
|
+
page.resource.key,
|
|
119
|
+
),
|
|
120
|
+
)
|
|
121
|
+
)
|
|
122
|
+
return {"epoch": epoch}
|
|
123
|
+
|
|
124
|
+
async def commit(self, epoch):
|
|
125
|
+
if epoch not in self.staged:
|
|
126
|
+
raise PluginError("unknown_epoch", "No prepared page cohort for this epoch")
|
|
127
|
+
self.snapshot = (epoch, self.staged.pop(epoch))
|
|
128
|
+
return {"epoch": epoch}
|
|
129
|
+
|
|
130
|
+
async def abort(self, epoch):
|
|
131
|
+
self.staged.pop(epoch, None)
|
|
132
|
+
return {"epoch": epoch}
|
|
133
|
+
|
|
134
|
+
def render_page(self, page, epoch):
|
|
135
|
+
access = self.access("presentation")
|
|
136
|
+
if not set(page.resource.resource.required_scopes) <= set(
|
|
137
|
+
access["allowed_scopes"]
|
|
138
|
+
):
|
|
139
|
+
raise PluginError("forbidden", "This page requires additional scopes")
|
|
140
|
+
page.render(
|
|
141
|
+
PageContext(
|
|
142
|
+
self.context,
|
|
143
|
+
page.resource,
|
|
144
|
+
epoch,
|
|
145
|
+
self.loop,
|
|
146
|
+
access_context=self.access_context(),
|
|
147
|
+
access=access,
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
def access_context(self):
|
|
152
|
+
import streamlit as st
|
|
153
|
+
|
|
154
|
+
reference = st.context.headers.get("X-Toolframe-Context")
|
|
155
|
+
if not reference:
|
|
156
|
+
raise PluginError(
|
|
157
|
+
"authentication_required",
|
|
158
|
+
"Open the Dashboard through the Toolframe application URL",
|
|
159
|
+
)
|
|
160
|
+
return reference
|
|
161
|
+
|
|
162
|
+
def access(self, action, params=None):
|
|
163
|
+
return asyncio.run_coroutine_threadsafe(
|
|
164
|
+
self.context.access(action, params, access_context=self.access_context()),
|
|
165
|
+
self.loop,
|
|
166
|
+
).result(timeout=30)
|
|
167
|
+
|
|
168
|
+
def manage(self, action, params=None):
|
|
169
|
+
future = asyncio.run_coroutine_threadsafe(
|
|
170
|
+
self.context.manage(action, params, access_context=self.access_context()),
|
|
171
|
+
self.loop,
|
|
172
|
+
)
|
|
173
|
+
try:
|
|
174
|
+
return future.result(timeout=30)
|
|
175
|
+
except TimeoutError:
|
|
176
|
+
future.cancel()
|
|
177
|
+
raise PluginError(
|
|
178
|
+
"management_timeout",
|
|
179
|
+
"Management request timed out; inspect operation history before retrying",
|
|
180
|
+
) from None
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
plugin = PluginDefinition(
|
|
184
|
+
id="streamlit-dashboard",
|
|
185
|
+
kind="provider",
|
|
186
|
+
provider_kind="dashboard",
|
|
187
|
+
factory="toolframe_streamlit_dashboard.plugin:DashboardProvider",
|
|
188
|
+
authorization=AuthorizationSpec(),
|
|
189
|
+
)
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: toolframe-streamlit-dashboard
|
|
3
|
+
Version: 0.4.2
|
|
4
|
+
Summary: Native Streamlit page and management provider for Toolframe
|
|
5
|
+
Project-URL: Homepage, https://github.com/toolframe/toolframe-streamlit-dashboard
|
|
6
|
+
Project-URL: Repository, https://github.com/toolframe/toolframe-streamlit-dashboard
|
|
7
|
+
Project-URL: Documentation, https://github.com/toolframe/toolframe-streamlit-dashboard#readme
|
|
8
|
+
Project-URL: Issues, https://github.com/toolframe/toolframe-streamlit-dashboard/issues
|
|
9
|
+
Author-email: byfb <62798989+byfb@users.noreply.github.com>
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: NOTICE
|
|
13
|
+
Requires-Python: >=3.14
|
|
14
|
+
Requires-Dist: streamlit==1.61.0
|
|
15
|
+
Requires-Dist: toolframe-sdk<0.4,>=0.2
|
|
16
|
+
Requires-Dist: uvicorn==0.42.0
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# Toolframe Streamlit Dashboard
|
|
20
|
+
|
|
21
|
+
This provider runs one native Streamlit process for the shared UI environment.
|
|
22
|
+
Business plugins contribute synchronous `render(context)` pages; navigation and
|
|
23
|
+
plugin management are provided here. Pages use the SDK's synchronous
|
|
24
|
+
`context.services.require(name, version=1).call(method, params)` proxy.
|
|
25
|
+
The Streamlit toolbar uses viewer mode, hiding its Deploy and developer controls.
|
|
26
|
+
Its native running indicator shows a circular spinner instead of cycling sports
|
|
27
|
+
icons. The Running label, Stop button and connection indicators remain available;
|
|
28
|
+
reduced-motion preferences disable the rotation. The narrowly scoped styling
|
|
29
|
+
targets Streamlit 1.61's busy-widget test ID and should be checked on upgrades.
|
|
30
|
+
Plugin lifecycle operations remain available on the Toolframe management page.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
Install the provider into a running [Toolframe application](https://github.com/toolframe/toolframe-core#readme):
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
toolframe --home APP plugin add pypi:toolframe-streamlit-dashboard==0.4.2 --enable
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Core resolves dependencies and manages the provider's isolated Python environment.
|
|
41
|
+
The Entry Register template already includes this provider.
|
|
42
|
+
|
|
43
|
+
Core resolves the provider and all contributing plugin wheels (with their `ui`
|
|
44
|
+
extras) together before replacing the worker. Changing any page package replaces
|
|
45
|
+
the whole Dashboard. Browser sessions reconnect and session state may reset;
|
|
46
|
+
business services and their persisted data remain independently owned.
|
|
47
|
+
|
|
48
|
+
The provider binds an ephemeral private loopback port and reports it to core.
|
|
49
|
+
Core owns the stable `/` gateway, management credentials and HTTP/WebSocket
|
|
50
|
+
admission. Streamlit owns its server lifespan and script threads. A stuck script
|
|
51
|
+
thread is a cleanup failure, never a successful in-process code reload.
|
|
52
|
+
|
|
53
|
+
SDK 0.2 page contexts carry a host-issued reference for each browser connection.
|
|
54
|
+
Pages use `context.can(scope)` to adapt controls; core checks every service call.
|
|
55
|
+
Navigation filters page scopes and the plugin-management page requires
|
|
56
|
+
`system.plugins.read`. Its mutation controls require the relevant management
|
|
57
|
+
scopes. A password without system grants cannot reach these operations through
|
|
58
|
+
the bridge. Incoming browser identity headers are not trusted.
|
|
59
|
+
|
|
60
|
+
The shared header displays local control, protected access or public access with
|
|
61
|
+
its reason. It remains present when the separate Dashboard Auth plugin is
|
|
62
|
+
unavailable. Its one-second refresh is presentation polling and does not count
|
|
63
|
+
as password activity. Use `activity=False` for other background service polling.
|
|
64
|
+
|
|
65
|
+
`prepare` imports and validates page entry points without rendering them. A
|
|
66
|
+
catalog epoch becomes visible only on `commit`; `abort` preserves live navigation.
|
|
67
|
+
The management page submits operations to core and reads their journal; it does
|
|
68
|
+
not install packages or access SQLite itself.
|
|
69
|
+
|
|
70
|
+
For enable, reload, disable, stop and remove, choose **Preview operation**, review
|
|
71
|
+
the affected plugins, then choose **Apply enable/reload/disable/stop/remove**.
|
|
72
|
+
A preview does not change plugin state. Only stop offers the separate force-stop
|
|
73
|
+
option; temporary runtime validation is offered only for validate.
|
|
74
|
+
|
|
75
|
+
Pending operations update automatically. Completion or errors appear beside the
|
|
76
|
+
controls, and the operation ID stays in the page URL so a browser refresh or
|
|
77
|
+
Dashboard replacement can resume reading its result. Operation history can reopen
|
|
78
|
+
a preview or result. Disabled plugins remain in the management list for re-enabling;
|
|
79
|
+
their pages and tools disappear after the disable operation completes.
|
|
80
|
+
Disabled plugins default to **enable** and do not offer reload/disable/stop.
|
|
81
|
+
Enable restores the installed version; update stages a freshly resolved package.
|
|
82
|
+
|
|
83
|
+
With core 0.5.0+, **Operations** queries the complete core journal with plugin,
|
|
84
|
+
action and result filters. It defaults to 10 rows, with 25/50 options and
|
|
85
|
+
Newer/Older navigation. Each row has a permanent operation number, browser-local
|
|
86
|
+
creation time, action, target and result. Preview rows include the intended action
|
|
87
|
+
(for example, `plan enable`). Viewing a result uses its durable UUID.
|
|
88
|
+
The refresh button aligns with the bottom of the page-size selector, at the right
|
|
89
|
+
edge. Newer and Older sit at opposite edges of one pagination row.
|
|
90
|
+
|
|
91
|
+
Page navigation retains a sequence boundary so new arrivals do not shift older
|
|
92
|
+
pages. **Refresh history**, changing filters or submitting an operation starts
|
|
93
|
+
at the latest first page. The count indicates newer arrivals; statuses remain
|
|
94
|
+
current. Read-only operators can filter, page and inspect results, while apply
|
|
95
|
+
and cancel retain their existing scope checks.
|
|
96
|
+
|
|
97
|
+
The **Plugin dependencies & impact** accordion sits directly below the status
|
|
98
|
+
table and starts collapsed. It reads core's `dependency_graph` diagnostics
|
|
99
|
+
(core 0.4.0+) under the existing `system.plugins.read` permission. Nodes show
|
|
100
|
+
Cordis lifecycle state and current health; arrows run from consumer to supplier.
|
|
101
|
+
Solid lines are required services, dashed lines optional services, and dotted
|
|
102
|
+
lines presentation providers. Missing suppliers and inactive plugins stay visible.
|
|
103
|
+
|
|
104
|
+
Select a plugin and **reload** or **disable** to highlight the lifecycle cohort,
|
|
105
|
+
optional consumers, and page/tool/document entries that may reconnect or refresh.
|
|
106
|
+
The cohort comes from core's actual planner. Presentation refreshes do not imply
|
|
107
|
+
that the provider or every page's business process restarts. Use the full-screen
|
|
108
|
+
control to enlarge the graph; the relationship table includes exact service names
|
|
109
|
+
and versions.
|
|
110
|
+
|
|
111
|
+
This view never installs, validates, submits an operation, or changes composition.
|
|
112
|
+
It describes selected versions; inactive declarations are labeled `last_candidate`.
|
|
113
|
+
New candidates or pending configuration changes can produce a different plan, so
|
|
114
|
+
the existing **Preview operation** / **Apply** workflow remains authoritative.
|
|
115
|
+
Refreshing status refreshes the graph too. An older core shows an upgrade hint.
|
|
116
|
+
|
|
117
|
+
The graph is generated from core state, including newly installed plugins and
|
|
118
|
+
their declared dependencies. `plugin new` only creates source and does not add a
|
|
119
|
+
node; use `plugin add` to install it. Refresh status after changes made elsewhere.
|
|
120
|
+
This is a refreshed snapshot, not a continuously pushed graph animation.
|
|
121
|
+
|
|
122
|
+
Development: `uv sync --group dev`, `uv run pytest -q`, `uv build --no-sources`.
|
|
123
|
+
Each lifecycle integration test uses a fresh subprocess because Streamlit's
|
|
124
|
+
runtime singleton belongs to the process, not a reloadable plugin object.
|
|
125
|
+
|
|
126
|
+
For fresh-environment CI checks, run
|
|
127
|
+
`uv run --isolated --no-project --python 3.14.7 python -I scripts/validate.py`.
|
|
128
|
+
See [CI and package publishing](docs/ci.md) for GitHub Actions, validation artifacts,
|
|
129
|
+
pinned SDK prerequisites and manual TestPyPI/PyPI Trusted Publishing setup.
|
|
130
|
+
|
|
131
|
+
For release validation and Trusted Publisher setup, see [releasing](docs/releasing.md).
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
toolframe_streamlit_dashboard/__init__.py,sha256=12jBy8V_p4pHLF1RtX3izR4SkKcztUzqiWZ7ebLn_ww,69
|
|
2
|
+
toolframe_streamlit_dashboard/app.py,sha256=JlpqV1qye8DmCOIl20FVRyZX-dAYqqsfmbtWm6431Vc,2337
|
|
3
|
+
toolframe_streamlit_dashboard/chrome.css,sha256=Z-7cueLlVKnoNJlPeVwDUc0yjrXD43vZTZ_iW3-Gu8A,710
|
|
4
|
+
toolframe_streamlit_dashboard/dependencies.py,sha256=AqIvtGio6C_7O-d_Gd65FKXOvpAJByiuThp-8fB2bWk,8393
|
|
5
|
+
toolframe_streamlit_dashboard/history.py,sha256=thyGPrTFigk3Ar-eo5YjEm6V6hNgdJXYF7ZVTd8hdJc,4920
|
|
6
|
+
toolframe_streamlit_dashboard/management.py,sha256=OpBbDnctgs7pNqGzoqQwpAyh9lJc1RqDshxfDOMilFI,10591
|
|
7
|
+
toolframe_streamlit_dashboard/plugin.py,sha256=WY7T17WY-Ky1_-e4HB9n3BzRvdoAOf9ptU65Go4Yal0,5994
|
|
8
|
+
toolframe_streamlit_dashboard-0.4.2.dist-info/METADATA,sha256=YrVJz2XuMm8CSCJa7usOiHKQO-HUKsc4QWXGuaPmtBU,7734
|
|
9
|
+
toolframe_streamlit_dashboard-0.4.2.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
10
|
+
toolframe_streamlit_dashboard-0.4.2.dist-info/entry_points.txt,sha256=I2Op8k_iCBIo4pzm4AeR3XkMolldFUrQ8GKnLT1LcyI,86
|
|
11
|
+
toolframe_streamlit_dashboard-0.4.2.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
12
|
+
toolframe_streamlit_dashboard-0.4.2.dist-info/licenses/NOTICE,sha256=RQbS1vFz4MGxjzdtE8PMh_nZdq8IUEnUd-77y59Ivvo,50
|
|
13
|
+
toolframe_streamlit_dashboard-0.4.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|