Skip to main content

euv_example/pages/automation/
fn.rs

1use super::*;
2
3/// Returns the active AI Schema v2 protocol identifier (`euv.ai.schema.v2` in debug, `stripped-in-release` in release).
4///
5/// # Returns
6///
7/// - `&'static str` - Protocol version string.
8pub(crate) fn automation_protocol_label() -> &'static str {
9    #[cfg(debug_assertions)]
10    {
11        AUTOMATION_SCHEMA_V2
12    }
13    #[cfg(not(debug_assertions))]
14    {
15        AUTOMATION_SCHEMA_STRIPPED
16    }
17}
18
19/// Returns the active AI Schema v1 compatibility identifier (`euv.ai.schema.v1` in debug, `stripped-in-release` in release).
20///
21/// # Returns
22///
23/// - `&'static str` - Protocol v1 compatibility string.
24pub(crate) fn automation_compat_protocol_label() -> &'static str {
25    #[cfg(debug_assertions)]
26    {
27        AI_SCHEMA_PROTOCOL_VERSION
28    }
29    #[cfg(not(debug_assertions))]
30    {
31        AUTOMATION_SCHEMA_STRIPPED
32    }
33}
34
35/// Returns the active `DevAutomationBridge` compile-time gate label (`dev-active` or `0B-release`).
36///
37/// # Returns
38///
39/// - `&'static str` - Bridge status label.
40pub(crate) fn automation_bridge_label() -> &'static str {
41    if DevAutomationBridge::is_enabled() {
42        AUTOMATION_BRIDGE_ACTIVE
43    } else {
44        AUTOMATION_BRIDGE_OFF
45    }
46}
47
48/// Builds a live formatted AI Schema v2 JSON preview string from the current `SceneTree`, `Context`, and `ShowcaseState`.
49///
50/// # Arguments
51///
52/// - `&Context` - Active framework context.
53/// - `&ShowcaseState` - Active showcase state.
54///
55/// # Returns
56///
57/// - `String` - Pretty-formatted JSON tree preview.
58pub(crate) fn build_automation_schema_json(ctx: &Context, state: &ShowcaseState) -> String {
59    let rs: ReactiveStats = reactive_stats();
60    let vp: Size = ctx.get_viewport_size().get_untracked();
61    let bp: Breakpoint = ctx.get_breakpoint().get_untracked();
62    let route: String = state.get_route().get_untracked();
63    let scheme: DesignScheme = state.get_theme().get_scheme().get_untracked();
64    let mode: ThemeMode = state.get_theme().get_mode().get_untracked();
65    let live_fps: f32 = ctx.get_live_fps().get_untracked();
66    let hz: f32 = ctx
67        .get_display_refresh_rate()
68        .get_untracked()
69        .clamp(30.0, 480.0);
70    let (alive_count, a11y_count, sample_nodes): (usize, usize, Vec<String>) =
71        ctx.get_scene().with_read(
72            |tree: &SceneTree| {
73                let mut alive: usize = 0;
74                let mut a11y_total: usize = 0;
75                let mut samples: Vec<String> = Vec::new();
76                for (idx, node) in tree.get_nodes().iter().enumerate() {
77                    if !node.get_alive() {
78                        continue;
79                    }
80                    let nid: NodeId = NodeId::new(idx as u32, node.get_generation());
81                    if !tree.is_node_visible(nid) {
82                        continue;
83                    }
84                    alive += 1;
85                    if let Some(a11y) = node.a11y_props_ref() {
86                        a11y_total += 1;
87                        if samples.len() < AUTOMATION_PREVIEW_NODE_LIMIT {
88                            let b: Rect = node.get_layout_box().get_bounds();
89                            let escaped: String = a11y.get_label().replace('"', "'");
90                            samples.push(format!(
91                                "    {{\"id\": {idx}, \"role\": \"{:?}\", \"label\": \"{escaped}\", \"bounds\": [{:.0}, {:.0}, {:.0}, {:.0}]}}",
92                                a11y.get_role(),
93                                b.get_x(),
94                                b.get_y(),
95                                b.get_width(),
96                                b.get_height()
97                            ));
98                        }
99                    }
100                }
101                (alive, a11y_total, samples)
102            },
103            (0, 0, Vec::new()),
104        );
105    let nodes_block: String = sample_nodes.join(",\n");
106    format!(
107        "{{\n  \"protocol\": \"{}\",\n  \"bridge\": \"{}\",\n  \"window\": {{\"route\": \"{route}\", \"viewport\": [{:.0}, {:.0}], \"breakpoint\": \"{bp:?}\", \"refresh_hz\": {:.0}, \"live_fps\": {:.1}}},\n  \"theme\": {{\"scheme\": \"{}\", \"mode\": \"{mode:?}\"}},\n  \"reactive\": {{\"signals\": {}, \"memos\": {}, \"effects\": {}, \"scopes\": {}, \"clock\": {}}},\n  \"scene\": {{\"alive_nodes\": {alive_count}, \"a11y_nodes\": {a11y_count}}},\n  \"a11y_preview\": [\n{nodes_block}\n  ]\n}}",
108        automation_protocol_label(),
109        automation_bridge_label(),
110        vp.get_width(),
111        vp.get_height(),
112        hz,
113        if live_fps.is_finite() && live_fps > 0.05 {
114            live_fps
115        } else {
116            0.0
117        },
118        scheme.as_str(),
119        rs.get_live_signals(),
120        rs.get_live_memos(),
121        rs.get_live_effects(),
122        rs.get_live_scopes(),
123        rs.get_clock()
124    )
125}
126
127/// Scans the live `SceneTree` for horizontal overflow and zero-sized interactive target anomalies.
128///
129/// # Arguments
130///
131/// - `&Context` - Active framework context providing viewport bounds and scene access.
132///
133/// # Returns
134///
135/// - `(usize, Vec<String>)` - Total visible nodes checked and list of anomaly descriptions.
136pub(crate) fn scan_automation_layout_anomalies(ctx: &Context) -> (usize, Vec<String>) {
137    let vp: Size = ctx.get_viewport_size().get_untracked();
138    let vw: f32 = vp.get_width().max(1.0);
139    ctx.get_scene().with_read(
140        |tree: &SceneTree| {
141            let mut checked: usize = 0;
142            let mut findings: Vec<String> = Vec::new();
143            for (idx, node) in tree.get_nodes().iter().enumerate() {
144                if !node.get_alive() {
145                    continue;
146                }
147                let nid: NodeId = NodeId::new(idx as u32, node.get_generation());
148                if !tree.is_node_visible(nid) {
149                    continue;
150                }
151                checked += 1;
152                let mut clipped_by_scroll: bool = false;
153                let mut anc: Option<NodeId> = node.parent_id();
154                while let Some(pid) = anc {
155                    if let Some(pnode) = tree.get_node(pid) {
156                        let pb: Rect = pnode.get_layout_box().get_bounds();
157                        if pnode.style_ref().get_layout().get_overflow() == Overflow::Scroll
158                            && pb.get_width() > 0.0
159                            && pb.right() <= vw + 1.5
160                        {
161                            clipped_by_scroll = true;
162                            break;
163                        }
164                        anc = pnode.parent_id();
165                    } else {
166                        break;
167                    }
168                }
169                let b: Rect = node.get_layout_box().get_bounds();
170                if !clipped_by_scroll && b.get_width() > 0.0 && b.right() > vw + 1.5 {
171                    findings.push(format!(
172                        "HorizontalOverflow node#{idx}: right={:.1} > vw={:.1}",
173                        b.right(),
174                        vw
175                    ));
176                }
177                if let Some(a11y) = node.a11y_props_ref()
178                    && a11y.get_role() == A11yRole::Button
179                    && (b.get_width() <= 0.0 || b.get_height() <= 0.0)
180                {
181                    findings.push(format!(
182                        "ZeroSizedInteractive node#{idx} ({}): {:.0}x{:.0}",
183                        a11y.get_label(),
184                        b.get_width(),
185                        b.get_height()
186                    ));
187                }
188            }
189            (checked, findings)
190        },
191        (0, Vec::new()),
192    )
193}
194
195/// Queries live visible `SceneTree` nodes matching `needle` against text content or `A11yProps` label.
196///
197/// # Arguments
198///
199/// - `&Context` - Active framework context.
200/// - `&str` - Case-insensitive query substring.
201///
202/// # Returns
203///
204/// - `String` - Human-readable query match summary.
205pub(crate) fn query_automation_scene_nodes(ctx: &Context, needle: &str) -> String {
206    let trimmed: String = needle.trim().to_lowercase();
207    if trimmed.is_empty() {
208        return AUTOMATION_QUERY_IDLE.to_string();
209    }
210    ctx.get_scene().with_read(
211        |tree: &SceneTree| {
212            let mut count: usize = 0;
213            let mut first_desc: Option<String> = None;
214            for (idx, node) in tree.get_nodes().iter().enumerate() {
215                if !node.get_alive() {
216                    continue;
217                }
218                let nid: NodeId = NodeId::new(idx as u32, node.get_generation());
219                if !tree.is_node_visible(nid) {
220                    continue;
221                }
222                let text_hit: Option<String> = match node.get_kind() {
223                    NodeKind::Text(t) if t.to_lowercase().contains(trimmed.as_str()) => {
224                        Some(t.clone())
225                    }
226                    _ => None,
227                };
228                let a11y_hit: Option<String> = node
229                    .a11y_props_ref()
230                    .filter(|a: &&A11yProps| {
231                        a.get_label().to_lowercase().contains(trimmed.as_str())
232                    })
233                    .map(|a: &A11yProps| format!("{:?}:{}", a.get_role(), a.get_label()));
234                if let Some(hit_label) = a11y_hit.or(text_hit) {
235                    count += 1;
236                    if first_desc.is_none() {
237                        let b: Rect = node.get_layout_box().get_bounds();
238                        first_desc = Some(format!(
239                            "node#{idx} `{hit_label}` @ ({:.0},{:.0} {:.0}x{:.0})",
240                            b.get_x(),
241                            b.get_y(),
242                            b.get_width(),
243                            b.get_height()
244                        ));
245                    }
246                }
247            }
248            match first_desc {
249                Some(first) => format!("Matched {count} node(s) | First: {first}"),
250                None => format!("Matched 0 nodes for query `{trimmed}`"),
251            }
252        },
253        AUTOMATION_QUERY_IDLE.to_string(),
254    )
255}
256
257/// Mounts the AI Schema v2 Live JSON Tree Preview card.
258///
259/// # Arguments
260///
261/// - `&ShowcaseState` - Shared showcase state.
262/// - `Signal<u32>` - Snapshot refresh counter signal.
263/// - `ThemeTokens` - Active design tokens.
264///
265/// # Returns
266///
267/// - `NodeId` - Mounted schema preview card node.
268pub(crate) fn mount_automation_schema_card(
269    state: &ShowcaseState,
270    ai_tick: Signal<u32>,
271    tokens: ThemeTokens,
272) -> NodeId {
273    let p: ThemePalette = tokens.get_palette();
274    let g: ThemeGeometry = tokens.get_geometry();
275    let ctx: Context = current_context();
276    let ai_fps_sig: Signal<f32> = ctx.get_live_fps();
277    let ai_hz_sig: Signal<f32> = ctx.get_display_refresh_rate();
278    let ai_route_sig: Signal<String> = state.get_route();
279    let ai_scheme_sig: Signal<DesignScheme> = state.get_theme().get_scheme();
280    let telemetry_line = move || -> String {
281        let _: u32 = ai_tick.get();
282        let rs: ReactiveStats = reactive_stats();
283        let ai_fps: f32 = ai_fps_sig.get();
284        let ai_hz: f32 = ai_hz_sig.get().clamp(30.0, 480.0);
285        let fps_display: String = if !ai_fps.is_finite() || ai_fps <= 0.05 {
286            LABEL_FPS_IDLE.to_string()
287        } else {
288            format!("{ai_fps:.1}")
289        };
290        format!(
291            "Protocol: {} ({}) | Route: {} | Scheme: {} | Display: {:.0}Hz | Live FPS: {} | Signals: {} | Memos: {} | Effects: {}",
292            automation_protocol_label(),
293            automation_bridge_label(),
294            ai_route_sig.get(),
295            ai_scheme_sig.get().as_str(),
296            ai_hz,
297            fps_display,
298            rs.get_live_signals(),
299            rs.get_live_memos(),
300            rs.get_live_effects()
301        )
302    };
303    let json_ctx: Context = ctx.clone();
304    let json_state: ShowcaseState = state.clone();
305    let schema_json_text = move || -> String {
306        let _: u32 = ai_tick.get();
307        build_automation_schema_json(&json_ctx, &json_state)
308    };
309    let on_refresh = move |_: &UiEvent| {
310        let _: bool = ai_tick.update(|v: &mut u32| *v = v.wrapping_add(1));
311    };
312    view! {
313        EuvCard {
314            title: AUTOMATION_SCHEMA_CARD_TITLE.to_string()
315            tokens: tokens
316            subtitle: AUTOMATION_SCHEMA_CARD_SUB
317            style: {
318                text_select: TextSelectMode::SelectAndCopy
319            }
320            column {
321                style: {
322                    width: Length::Percent(100.0)
323                    gap: SPACE_SM
324                }
325                text {
326                    style: {
327                        width: Length::Percent(100.0)
328                        font_size: 12.5
329                        font_weight: FontWeight::SemiBold
330                        color: p.get_primary()
331                    }
332                    { telemetry_line }
333                }
334                EuvActionRow {
335                    EuvButton {
336                        label: AUTOMATION_BTN_REFRESH_SCHEMA.to_string()
337                        tokens: tokens
338                        sm()
339                        on_click: on_refresh
340                    }
341                }
342                column {
343                    style: {
344                        width: Length::Percent(100.0)
345                        padding: Edges::all(SPACE_MD)
346                        background: p.get_muted()
347                        border: (g.get_border_width(), p.get_border())
348                        radius: g.get_radius_md()
349                        overflow: Overflow::Hidden
350                    }
351                    text {
352                        style: {
353                            width: Length::Percent(100.0)
354                            font_size: 11.5
355                            font_family: FontFamily::Monospace
356                            color: p.get_foreground()
357                        }
358                        { schema_json_text }
359                    }
360                }
361            }
362        }
363    }
364}
365
366/// Mounts the live Layout Anomaly Checker card scanning the current `SceneTree`.
367///
368/// # Arguments
369///
370/// - `ThemeTokens` - Active design tokens.
371///
372/// # Returns
373///
374/// - `NodeId` - Mounted layout anomaly checker card node.
375pub(crate) fn mount_automation_anomaly_card(tokens: ThemeTokens) -> NodeId {
376    let p: ThemePalette = tokens.get_palette();
377    let g: ThemeGeometry = tokens.get_geometry();
378    let ctx: Context = current_context();
379    let anomaly_summary: Signal<String> = Signal::new(AUTOMATION_ANOMALY_READY.to_string());
380    let anomaly_findings: Signal<Vec<String>> = Signal::new(Vec::new());
381    let anomaly_runs: Signal<u32> = Signal::new(0);
382    let summary_text = move || -> String { anomaly_summary.get() };
383    let ctx_scan: Context = ctx.clone();
384    let on_run_check = move |_: &UiEvent| {
385        let (checked, findings): (usize, Vec<String>) = scan_automation_layout_anomalies(&ctx_scan);
386        let run_no: u32 = anomaly_runs.get_untracked().saturating_add(1);
387        let _: bool = anomaly_runs.set(run_no);
388        let vp: Size = ctx_scan.get_viewport_size().get_untracked();
389        let status: String = if findings.is_empty() {
390            format!(
391                "Run #{run_no}: {AUTOMATION_ANOMALY_CLEAN} ({checked} nodes @ {:.0}x{:.0})",
392                vp.get_width(),
393                vp.get_height()
394            )
395        } else {
396            format!(
397                "Run #{run_no}: {} anomaly(s) across {checked} nodes @ {:.0}x{:.0}",
398                findings.len(),
399                vp.get_width(),
400                vp.get_height()
401            )
402        };
403        let _: bool = anomaly_summary.set(status);
404        let _: bool = anomaly_findings.set(findings);
405    };
406    let build_findings_rows = move || -> Vec<NodeId> {
407        let live: ThemeTokens = live_tokens_untracked(tokens);
408        let live_p: ThemePalette = live.get_palette();
409        let items: Vec<String> = anomaly_findings.get();
410        if items.is_empty() {
411            let label: String = if anomaly_runs.get() == 0 {
412                AUTOMATION_ANOMALY_READY.to_string()
413            } else {
414                AUTOMATION_ANOMALY_CLEAN.to_string()
415            };
416            return vec![view! {
417                text {
418                    style: {
419                        width: Length::Percent(100.0)
420                        font_size: 12.0
421                        font_family: FontFamily::Monospace
422                        color: live_p.get_foreground()
423                    }
424                    { label }
425                }
426            }];
427        }
428        items
429            .into_iter()
430            .map(|item: String| {
431                view! {
432                    text {
433                        style: {
434                            width: Length::Percent(100.0)
435                            font_size: 12.0
436                            font_family: FontFamily::Monospace
437                            color: live_p.get_foreground()
438                        }
439                        { item }
440                    }
441                }
442            })
443            .collect()
444    };
445    view! {
446        EuvCard {
447            title: AUTOMATION_ANOMALY_CARD_TITLE.to_string()
448            tokens: tokens
449            subtitle: AUTOMATION_ANOMALY_CARD_SUB
450            column {
451                style: {
452                    width: Length::Percent(100.0)
453                    gap: SPACE_SM
454                }
455                text {
456                    style: {
457                        width: Length::Percent(100.0)
458                        font_size: 13.0
459                        font_weight: FontWeight::SemiBold
460                        color: p.get_card_foreground()
461                    }
462                    { summary_text }
463                }
464                EuvActionRow {
465                    EuvButton {
466                        label: AUTOMATION_BTN_RUN_ANOMALY.to_string()
467                        tokens: tokens
468                        sm()
469                        on_click: on_run_check
470                    }
471                }
472                column {
473                    style: {
474                        width: Length::Percent(100.0)
475                        padding: Edges::all(SPACE_SM)
476                        gap: SPACE_XS
477                        background: p.get_muted()
478                        border: (g.get_border_width(), p.get_border())
479                        radius: g.get_radius_md()
480                        overflow: Overflow::Hidden
481                    }
482                    bind_children: build_findings_rows
483                }
484            }
485        }
486    }
487}
488
489/// Mounts the DevBridge Endpoint Status inspector card for the studio rail.
490///
491/// # Arguments
492///
493/// - `ThemeTokens` - Active design tokens.
494///
495/// # Returns
496///
497/// - `NodeId` - Mounted DevBridge status card node.
498pub(crate) fn mount_automation_bridge_card(tokens: ThemeTokens) -> NodeId {
499    let p: ThemePalette = tokens.get_palette();
500    let bridge_enabled: bool = DevAutomationBridge::is_enabled();
501    let badge_tone: EuvTone = if bridge_enabled {
502        EuvTone::Success
503    } else {
504        EuvTone::Neutral
505    };
506    let meta_line: String = format!(
507        "Protocol: {} (compat: {}) | Bind: 127.0.0.1:4174 | Queue: 16 | Budget: 2000us",
508        automation_protocol_label(),
509        automation_compat_protocol_label()
510    );
511    view! {
512        EuvCard {
513            title: AUTOMATION_BRIDGE_CARD_TITLE.to_string()
514            tokens: tokens
515            subtitle: AUTOMATION_BRIDGE_CARD_SUB
516            column {
517                style: {
518                    width: Length::Percent(100.0)
519                    gap: SPACE_SM
520                }
521                row {
522                    style: {
523                        width: Length::Percent(100.0)
524                        flex_wrap: FlexWrap::Wrap
525                        align: AlignItems::Center
526                        gap: SPACE_SM
527                    }
528                    EuvBadge {
529                        label: automation_bridge_label().to_string()
530                        tone: badge_tone
531                        tokens: tokens
532                    }
533                    EuvBadge {
534                        label: automation_protocol_label().to_string()
535                        tone: EuvTone::Primary
536                        tokens: tokens
537                    }
538                }
539                text {
540                    style: {
541                        width: Length::Percent(100.0)
542                        font_size: 12.0
543                        font_family: FontFamily::Monospace
544                        color: p.get_muted_foreground()
545                    }
546                    { meta_line }
547                }
548                EuvCodeBlock {
549                    code: AUTOMATION_BRIDGE_ENDPOINTS.to_string()
550                    tokens: tokens
551                }
552            }
553        }
554    }
555}
556
557/// Mounts the Interactive `UiAutomator` Action Runner card for the studio rail.
558///
559/// # Arguments
560///
561/// - `&ShowcaseState` - Shared showcase state.
562/// - `Signal<u32>` - Snapshot refresh counter signal.
563/// - `ThemeTokens` - Active design tokens.
564///
565/// # Returns
566///
567/// - `NodeId` - Mounted action runner card node.
568pub(crate) fn mount_automation_runner_card(
569    state: &ShowcaseState,
570    ai_tick: Signal<u32>,
571    tokens: ThemeTokens,
572) -> NodeId {
573    let p: ThemePalette = tokens.get_palette();
574    let g: ThemeGeometry = tokens.get_geometry();
575    let ctx: Context = current_context();
576    let query_sig: Signal<String> = Signal::new(AUTOMATION_QUERY_DEFAULT.to_string());
577    let query_result: Signal<String> = Signal::new(AUTOMATION_QUERY_IDLE.to_string());
578    let sandbox_clicks: Signal<u32> = Signal::new(0);
579    let action_log: Signal<Vec<String>> = Signal::new(Vec::new());
580    let push_trace = move |entry: String| {
581        let _: bool = action_log.update(|items: &mut Vec<String>| {
582            items.insert(0, entry);
583            if items.len() > AUTOMATION_LOG_LIMIT {
584                items.truncate(AUTOMATION_LOG_LIMIT);
585            }
586        });
587    };
588    let query_result_text = move || -> String { query_result.get() };
589    let sandbox_status_text = move || -> String {
590        format!(
591            "Sandbox Target Clicks: {} | Actions Logged: {}",
592            sandbox_clicks.get(),
593            action_log.get().len()
594        )
595    };
596    let ctx_query: Context = ctx.clone();
597    let on_query = move |_: &UiEvent| {
598        let q: String = query_sig.get_untracked();
599        let res: String = query_automation_scene_nodes(&ctx_query, &q);
600        let _: bool = query_result.set(res.clone());
601        push_trace(format!("Query(`{q}`) -> {res}"));
602    };
603    let on_sandbox_click = move |_: &UiEvent| {
604        let next: u32 = sandbox_clicks.get_untracked().saturating_add(1);
605        let _: bool = sandbox_clicks.set(next);
606        let _: bool = ai_tick.update(|v: &mut u32| *v = v.wrapping_add(1));
607        push_trace(format!("Action::Click(sandbox) -> OK (hits={next})"));
608    };
609    let state_theme: ShowcaseState = state.clone();
610    let on_toggle_theme = move |_: &UiEvent| {
611        state_theme.toggle_theme_mode();
612        let mode: ThemeMode = state_theme.get_theme().get_mode().get_untracked();
613        let _: bool = ai_tick.update(|v: &mut u32| *v = v.wrapping_add(1));
614        push_trace(format!("Action::SetTheme(mode={mode:?}) -> OK"));
615    };
616    let on_clear_log = move |_: &UiEvent| {
617        let _: bool = action_log.set_if_changed(Vec::new());
618    };
619    let build_trace_rows = move || -> Vec<NodeId> {
620        let live: ThemeTokens = live_tokens_untracked(tokens);
621        let live_p: ThemePalette = live.get_palette();
622        let items: Vec<String> = action_log.get();
623        if items.is_empty() {
624            return vec![view! {
625                text {
626                    style: {
627                        width: Length::Percent(100.0)
628                        font_size: 12.0
629                        font_family: FontFamily::Monospace
630                        color: live_p.get_muted_foreground()
631                    }
632                    { AUTOMATION_LOG_EMPTY }
633                }
634            }];
635        }
636        items
637            .into_iter()
638            .map(|entry: String| {
639                view! {
640                    text {
641                        style: {
642                            width: Length::Percent(100.0)
643                            font_size: 11.5
644                            font_family: FontFamily::Monospace
645                            color: live_p.get_foreground()
646                        }
647                        { entry }
648                    }
649                }
650            })
651            .collect()
652    };
653    view! {
654        EuvCard {
655            title: AUTOMATION_RUNNER_CARD_TITLE.to_string()
656            tokens: tokens
657            subtitle: AUTOMATION_RUNNER_CARD_SUB
658            column {
659                style: {
660                    width: Length::Percent(100.0)
661                    gap: SPACE_SM
662                }
663                EuvInput {
664                    value: query_sig
665                    placeholder: AUTOMATION_QUERY_PLACEHOLDER.to_string()
666                    tokens: tokens
667                }
668                EuvActionRow {
669                    EuvButton {
670                        label: AUTOMATION_BTN_QUERY_NODES.to_string()
671                        tokens: tokens
672                        sm()
673                        on_click: on_query
674                    }
675                    EuvButton {
676                        label: AUTOMATION_BTN_SANDBOX_CLICK.to_string()
677                        tokens: tokens
678                        outline()
679                        sm()
680                        on_click: on_sandbox_click
681                    }
682                    EuvButton {
683                        label: AUTOMATION_BTN_THEME_ACTION.to_string()
684                        tokens: tokens
685                        outline()
686                        sm()
687                        on_click: on_toggle_theme
688                    }
689                    EuvButton {
690                        label: AUTOMATION_BTN_CLEAR_LOG.to_string()
691                        tokens: tokens
692                        ghost()
693                        sm()
694                        on_click: on_clear_log
695                    }
696                }
697                text {
698                    style: {
699                        width: Length::Percent(100.0)
700                        font_size: 12.0
701                        font_weight: FontWeight::Medium
702                        color: p.get_primary()
703                    }
704                    { query_result_text }
705                }
706                text {
707                    style: {
708                        width: Length::Percent(100.0)
709                        font_size: 12.0
710                        font_family: FontFamily::Monospace
711                        color: p.get_muted_foreground()
712                    }
713                    { sandbox_status_text }
714                }
715                column {
716                    style: {
717                        width: Length::Percent(100.0)
718                        padding: Edges::all(SPACE_SM)
719                        gap: SPACE_XS
720                        background: p.get_muted()
721                        border: (g.get_border_width(), p.get_border())
722                        radius: g.get_radius_md()
723                        overflow: Overflow::Hidden
724                    }
725                    bind_children: build_trace_rows
726                }
727            }
728        }
729    }
730}
731
732/// Mounts the dedicated AI Bridge & E2E Automation inspection studio page.
733///
734/// # Arguments
735///
736/// - `&ShowcaseState` - Reactive showcase state.
737/// - `ThemeTokens` - Active design tokens.
738///
739/// # Returns
740///
741/// - `NodeId` - Mounted automation inspection page node.
742pub fn mount_automation_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
743    let ai_tick: Signal<u32> = Signal::new(0);
744    let schema_card: NodeId = mount_automation_schema_card(state, ai_tick, tokens);
745    let anomaly_card: NodeId = mount_automation_anomaly_card(tokens);
746    let bridge_card: NodeId = mount_automation_bridge_card(tokens);
747    let runner_card: NodeId = mount_automation_runner_card(state, ai_tick, tokens);
748    let main: NodeId = view! {
749        column {
750            style: {
751                width: Length::Percent(100.0)
752                gap: SPACE_MD
753            }
754            { anomaly_card }
755            { schema_card }
756        }
757    };
758    let rail: NodeId = view! {
759        column {
760            style: {
761                width: Length::Percent(100.0)
762                gap: SPACE_MD
763            }
764            { bridge_card }
765            { runner_card }
766        }
767    };
768    let studio: NodeId = mount_studio_layout(main, rail);
769    view! {
770        EuvPage {
771            title: AUTOMATION_TITLE.to_string()
772            subtitle: AUTOMATION_SUBTITLE.to_string()
773            tokens: tokens
774            { studio }
775        }
776    }
777}