// SPDX-License-Identifier: MIT // SPDX-FileCopyrightText: 2026 avtc /** * UI helper functions for workflow-monitor. */ import { getActiveFeatureSlug } from "../shared/workflow-refs.js"; import { withCoordinator } from "../snippets/vendored/subscribe-to-dialog-coordinator.js"; import { getLastMessage, withAttention } from "../snippets/vendored/subscribe-to-notifications.js"; type SelectOption = { label: string; value: T }; export async function selectValue(title: string, options: SelectOption[]): Promise { const guard = globalThis.__piCtx; const ui = guard?.ui; if (!ui?.select) { // No UI available — return first option as default return (options[0]?.value ?? "cancel") as T; } const slug = getActiveFeatureSlug(); const labels = options.map((o) => o.label); const detail = [title, slug, getLastMessage()].filter(Boolean).join(" • "); const pickedLabel = await withAttention("workflow", detail, () => withCoordinator(() => ui.select(title, labels))); const picked = options.find((o) => o.label === pickedLabel); return (picked?.value ?? "cancel") as T; }