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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
//! Plugins page - displays plugin usage analytics (Skills, MCP, Agents, Commands, Native Tools)
use leptos::prelude::*;
use serde::{Deserialize, Serialize};
/// API base URL constant (empty = relative URL, same origin)
const API_BASE_URL: &str = "";
/// Plugin classification by origin
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum PluginType {
Skill,
Command,
Agent,
McpServer,
NativeTool,
}
impl PluginType {
/// Human-readable label
pub fn label(&self) -> &'static str {
match self {
Self::Skill => "Skill",
Self::Command => "Command",
Self::Agent => "Agent",
Self::McpServer => "MCP Server",
Self::NativeTool => "Native Tool",
}
}
}
/// Usage statistics for a single plugin
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PluginUsage {
pub name: String,
pub plugin_type: PluginType,
pub icon: String, // Icon emoji computed from plugin_type (backend-serialized)
pub total_invocations: usize,
pub sessions_used: Vec<String>,
pub total_cost: f64,
pub avg_tokens_per_invocation: u64,
pub first_seen: String, // ISO8601 timestamp
pub last_seen: String, // ISO8601 timestamp
}
/// Complete plugin analytics data
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PluginAnalytics {
pub total_plugins: usize,
pub active_plugins: usize,
pub dead_plugins: Vec<String>,
pub plugins: Vec<PluginUsage>,
pub top_by_usage: Vec<PluginUsage>,
pub top_by_cost: Vec<PluginUsage>,
pub computed_at: String, // ISO8601 timestamp
}
/// API response wrapper
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PluginsResponse {
pub analytics: PluginAnalytics,
pub generated_at: String,
}
/// Fetch plugins from API
async fn fetch_plugins() -> Result<PluginsResponse, String> {
let url = format!("{}/api/plugins", API_BASE_URL);
let response = gloo_net::http::Request::get(&url)
.send()
.await
.map_err(|e| format!("Failed to fetch plugins: {}", e))?;
if !response.ok() {
return Err(format!("HTTP error: {}", response.status()));
}
let plugins_response: PluginsResponse = response
.json()
.await
.map_err(|e| format!("Failed to parse JSON: {}", e))?;
Ok(plugins_response)
}
/// Stats card component
#[component]
fn StatsCard(label: &'static str, value: String, color: &'static str) -> impl IntoView {
let card_class = format!("stats-card stats-card--{}", color);
view! {
<div class=card_class>
<div class="stats-card__label">{label}</div>
<div class="stats-card__value">{value}</div>
</div>
}
}
/// Plugin list item component (usage-focused)
#[component]
fn PluginListItem(plugin: PluginUsage, rank: usize) -> impl IntoView {
let icon = plugin.icon.clone();
let type_label = plugin.plugin_type.label();
let usage_display = if plugin.total_invocations >= 1000 {
format!("{}k", plugin.total_invocations / 1000)
} else {
plugin.total_invocations.to_string()
};
view! {
<div class="plugin-item">
<span class="plugin-item__rank">{"#"}{rank}</span>
<span class="plugin-item__icon">{icon}</span>
<div class="plugin-item__info">
<span class="plugin-item__name">{plugin.name.clone()}</span>
<span class="plugin-item__type">{type_label}</span>
</div>
<div class="plugin-item__stat">
<span class="plugin-item__stat-value">{usage_display}</span>
<span class="plugin-item__stat-label">"uses"</span>
</div>
</div>
}
}
/// Plugin cost item component (cost-focused)
#[component]
fn PluginCostItem(plugin: PluginUsage, rank: usize) -> impl IntoView {
let icon = plugin.icon.clone();
let type_label = plugin.plugin_type.label();
let cost_display = if plugin.total_cost >= 100.0 {
format!("{:.0}", plugin.total_cost)
} else if plugin.total_cost >= 10.0 {
format!("{:.1}", plugin.total_cost)
} else {
format!("{:.2}", plugin.total_cost)
};
view! {
<div class="plugin-item plugin-item--cost">
<span class="plugin-item__rank">{"#"}{rank}</span>
<span class="plugin-item__icon">{icon}</span>
<div class="plugin-item__info">
<span class="plugin-item__name">{plugin.name.clone()}</span>
<span class="plugin-item__type">{type_label}</span>
</div>
<div class="plugin-item__stat plugin-item__stat--cost">
<span class="plugin-item__stat-value">"$"{cost_display}</span>
<span class="plugin-item__stat-label">{plugin.total_invocations}" uses"</span>
</div>
</div>
}
}
/// Dead code item component
#[component]
fn DeadCodeItem(name: String) -> impl IntoView {
view! {
<div class="plugin-item plugin-item--dead">
<span class="plugin-item__icon">"⚠️"</span>
<div class="plugin-item__info">
<span class="plugin-item__name">{name}</span>
<span class="plugin-item__type">"Never invoked"</span>
</div>
<div class="plugin-item__stat plugin-item__stat--dead">
<span class="plugin-item__stat-value">"0"</span>
<span class="plugin-item__stat-label">"uses"</span>
</div>
</div>
}
}
/// Plugins page component
#[component]
pub fn PluginsPage() -> impl IntoView {
let plugin_data = LocalResource::new(move || async move { fetch_plugins().await });
view! {
<div class="plugins-page">
<div class="plugins-page__header">
<h1 class="plugins-page__title">"🎁 Plugin Analytics"</h1>
<p class="plugins-page__subtitle">
"Analyze plugin usage across Skills, MCP Servers, Agents, and Commands"
</p>
</div>
<Suspense fallback=move || view! { <div class="loading-spinner">"Loading plugin analytics..."</div> }>
{move || Suspend::new(async move {
match plugin_data.await {
Ok(response) => {
let analytics = response.analytics;
let active_pct = if analytics.total_plugins > 0 {
(analytics.active_plugins as f64 / analytics.total_plugins as f64) * 100.0
} else {
0.0
};
view! {
<div class="plugins-page__content">
// Stats cards
<div class="stats-grid">
<StatsCard
label="Total Plugins"
value=analytics.total_plugins.to_string()
color="blue"
/>
<StatsCard
label="Active"
value=format!("{} ({:.0}%)", analytics.active_plugins, active_pct)
color="green"
/>
<StatsCard
label="Dead Code"
value=analytics.dead_plugins.len().to_string()
color="red"
/>
</div>
// Three-column layout
<div class="plugins-columns">
// Top 10 Most Used
<div class="plugins-column">
<div class="plugins-column__header">
<h2 class="plugins-column__title">"Top 10 Most Used"</h2>
</div>
<div class="plugins-column__content">
{if analytics.top_by_usage.is_empty() {
view! {
<div class="empty-state">
<p>"No plugin usage data available"</p>
</div>
}.into_any()
} else {
analytics.top_by_usage.into_iter().enumerate().map(|(i, plugin)| {
view! {
<PluginListItem plugin=plugin rank=i+1 />
}
}).collect_view().into_any()
}}
</div>
</div>
// Top 10 By Cost
<div class="plugins-column">
<div class="plugins-column__header">
<h2 class="plugins-column__title">"Top 10 By Cost"</h2>
</div>
<div class="plugins-column__content">
{if analytics.top_by_cost.is_empty() {
view! {
<div class="empty-state">
<p>"No cost data available"</p>
</div>
}.into_any()
} else {
analytics.top_by_cost.into_iter().enumerate().map(|(i, plugin)| {
view! {
<PluginCostItem plugin=plugin rank=i+1 />
}
}).collect_view().into_any()
}}
</div>
</div>
// Dead Code
<div class="plugins-column">
<div class="plugins-column__header">
<h2 class="plugins-column__title">"Dead Code (Never Used)"</h2>
</div>
<div class="plugins-column__content">
{if analytics.dead_plugins.is_empty() {
view! {
<div class="empty-state empty-state--success">
<div class="empty-state__icon">"🎉"</div>
<p>"No dead code detected!"</p>
<p class="empty-state__subtitle">"All plugins are being used."</p>
</div>
}.into_any()
} else {
analytics.dead_plugins.into_iter().map(|name| {
view! {
<DeadCodeItem name=name />
}
}).collect_view().into_any()
}}
</div>
</div>
</div>
</div>
}.into_any()
}
Err(e) => {
view! {
<div class="error-state">
<div class="error-state__icon">"⚠️"</div>
<h2 class="error-state__title">"Error loading plugins"</h2>
<p class="error-state__message">{e}</p>
</div>
}.into_any()
}
}
})}
</Suspense>
</div>
}
}