SPB Git

Repository Public MIT

glass-agent-panel.md 3.9 KB

# GlassAgentPanel

Identifier glass-agent-panel
Module SPGlassAI
Kind content-component — task cards on opaque themed surfaces; no glass
Platforms iOS 26, iPadOS 26, macOS 26
Example Examples/Gallery/AI/GlassAgentPanelExample.swift

UI only: the panel displays value types that the host updates. It runs no agent and no task.

# Minimal usage

swift
GlassAgentPanel(tasks: agent.tasks)

# Variants

Variant Use
onCancel: Shows "Cancel" on pending and running tasks.
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.
Task without steps Status tile, title and status only: no progress bar, no step list.
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.
Errors A task or step errorMessage is shown in a tinted block with a warning symbol.

# Parameters

Parameter Type Default Meaning
tasks [GlassAgentTask] — Tasks in display order.
expandedTaskIDs Binding<Set<String>>? nil Controlled expansion of the step lists.
onCancel (@MainActor (GlassAgentTask) -> Void)? nil Called by a task's "Cancel" button.

GlassAgentTask: id, title, status, steps, errorMessage. GlassAgentStep: id, title, status, detail, errorMessage. GlassAgentStatus: pending, running, succeeded, failed, cancelled.

GlassAgentProgress (task.progress) counts the steps that succeeded out of all steps: completed, total, fraction, summary ("2 of 5 steps completed").

# States

Status Symbol Word
Pending circle.dotted "Pending"
Running arrow.triangle.2.circlepath "Running"
Succeeded checkmark.circle.fill "Completed"
Failed xmark.octagon.fill "Failed"
Cancelled minus.circle "Cancelled"

Errors (of a task or a step) are shown with a warning symbol and the host's message. An empty tasks array shows "No data".

# Advanced example

swift
struct AgentSidebar: View {
    @Bindable var agent: AgentModel            // host type; exposes [GlassAgentTask]
    @State private var expanded: Set<String> = []

    var body: some View {
        ScrollView {
            GlassAgentPanel(tasks: agent.tasks, expandedTaskIDs: $expanded) { task in
                agent.cancel(task.id)
            }
            .padding()
        }
        .onChange(of: agent.tasks.first { $0.status == .failed }?.id) { _, failedID in
            if let failedID { expanded.insert(failedID) }      // open the task that just failed
        }
    }
}

# Accessibility

  • Status is always a symbol and a word; colour only reinforces it.
  • 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.
  • The progress bar is labelled with the task title and its value is "2 of 5 steps completed".
  • Errors read "Error: ". The cancel button reads "Cancel, ".
  • The step list is a system DisclosureGroup: keyboard and VoiceOver expansion are the system's.

# Limits

  • The panel does not scroll by itself; put it in a ScrollView or a List row.
  • All tasks are laid out eagerly: it is meant for the tasks of a session, not for an unbounded history.
  • No animation runs while a task is running; the running state is a static symbol and a word.
  • 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.
  • The rendering was not inspected in a running application during verification; progress, cancellability and status mapping are unit-tested.
Files main
Menu

Theme