SPB Git

Repository Public MIT

glass-agent-panel.md 3.9 KB 89 lines markdown

1# GlassAgentPanel23| | |4|---|---|5| Identifier | `glass-agent-panel` |6| Module | `SPGlassAI` |7| Kind | `content-component` — task cards on opaque themed surfaces; no glass |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/AI/GlassAgentPanelExample.swift` |1011UI only: the panel displays value types that the host updates. It runs no agent and no task.1213## Minimal usage1415```swift16GlassAgentPanel(tasks: agent.tasks)17```1819## Variants2021| Variant | Use |22|---|---|23| `onCancel:` | Shows "Cancel" on pending and running tasks. |24| `expandedTaskIDs:` | The host controls which step lists are open. Without it the panel keeps that state and opens the tasks that are running or failed when it is created. |25| Task without steps | Status tile, title and status only: no progress bar, no step list. |26| Step rail | Steps sit on a vertical rail. Each node tells the state by its shape and symbol (check, ring with a dot, dashed circle, cross, minus) and the status word is written under the step title. |27| Errors | A task or step `errorMessage` is shown in a tinted block with a warning symbol. |2829## Parameters3031| Parameter | Type | Default | Meaning |32|---|---|---|---|33| `tasks` | `[GlassAgentTask]` | — | Tasks in display order. |34| `expandedTaskIDs` | `Binding<Set<String>>?` | `nil` | Controlled expansion of the step lists. |35| `onCancel` | `(@MainActor (GlassAgentTask) -> Void)?` | `nil` | Called by a task's "Cancel" button. |3637`GlassAgentTask`: `id`, `title`, `status`, `steps`, `errorMessage`. `GlassAgentStep`: `id`, `title`, `status`, `detail`, `errorMessage`. `GlassAgentStatus`: `pending`, `running`, `succeeded`, `failed`, `cancelled`.3839`GlassAgentProgress` (`task.progress`) counts the steps that succeeded out of all steps: `completed`, `total`, `fraction`, `summary` ("2 of 5 steps completed").4041## States4243| Status | Symbol | Word |44|---|---|---|45| Pending | `circle.dotted` | "Pending" |46| Running | `arrow.triangle.2.circlepath` | "Running" |47| Succeeded | `checkmark.circle.fill` | "Completed" |48| Failed | `xmark.octagon.fill` | "Failed" |49| Cancelled | `minus.circle` | "Cancelled" |5051Errors (of a task or a step) are shown with a warning symbol and the host's message. An empty `tasks` array shows "No data".5253## Advanced example5455```swift56struct AgentSidebar: View {57    @Bindable var agent: AgentModel            // host type; exposes [GlassAgentTask]58    @State private var expanded: Set<String> = []5960    var body: some View {61        ScrollView {62            GlassAgentPanel(tasks: agent.tasks, expandedTaskIDs: $expanded) { task in63                agent.cancel(task.id)64            }65            .padding()66        }67        .onChange(of: agent.tasks.first { $0.status == .failed }?.id) { _, failedID in68            if let failedID { expanded.insert(failedID) }      // open the task that just failed69        }70    }71}72```7374## Accessibility7576- Status is always a symbol and a word; colour only reinforces it.77- Each task header and each step is one combined element ("Group by topic, Running, Topic 3 of 5"); running ones have the "updates frequently" trait.78- The progress bar is labelled with the task title and its value is "2 of 5 steps completed".79- Errors read "Error: <message>". The cancel button reads "Cancel, <task title>".80- The step list is a system `DisclosureGroup`: keyboard and VoiceOver expansion are the system's.8182## Limits8384- The panel does not scroll by itself; put it in a `ScrollView` or a `List` row.85- All tasks are laid out eagerly: it is meant for the tasks of a session, not for an unbounded history.86- No animation runs while a task is running; the running state is a static symbol and a word.87- The default expansion is decided once, when the panel is created; later status changes do not open or close a task unless the host uses `expandedTaskIDs`.88- The rendering was not inspected in a running application during verification; progress, cancellability and status mapping are unit-tested.89
Files main
Menu

Theme