Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Examples/Gallery/AI/GlassAgentPanelExample.swift8// Module : Examples9// Repository : https://git.spboucher.ai/sp-glasskit10// Project Website : https://glass.spboucher.ai11// Created : 2026-12-0212// Last Modified : 2026-12-0213//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI42import SPGlassKit4344public struct GlassAgentPanelExample: GlassExample {45 public static let componentID = "glass-agent-panel"4647 /// Fictitious tasks: nothing is executed, the example only edits these values.48 @State private var tasks = [49 GlassAgentTask(id: "t1", title: "Prepare the sample weekly digest", status: .running, steps: [50 GlassAgentStep(id: "s1", title: "Collect sample notes", status: .succeeded, detail: "12 notes found"),51 GlassAgentStep(id: "s2", title: "Group by topic", status: .running, detail: "Topic 3 of 5"),52 GlassAgentStep(id: "s3", title: "Write the digest", status: .pending),53 ]),54 GlassAgentTask(id: "t2", title: "Rename sample files with a deliberately long task title that wraps over two lines", status: .failed, steps: [55 GlassAgentStep(id: "s1", title: "List files", status: .succeeded),56 GlassAgentStep(id: "s2", title: "Apply new names", status: .failed, detail: "4 of 9 renamed", errorMessage: "Sample failure: a file with this name already exists."),57 ]),58 GlassAgentTask(id: "t3", title: "Translate sample page", status: .succeeded, steps: [59 GlassAgentStep(id: "s1", title: "Detect language", status: .succeeded),60 GlassAgentStep(id: "s2", title: "Translate", status: .succeeded),61 ]),62 GlassAgentTask(id: "t4", title: "Queued sample export", status: .pending),63 GlassAgentTask(id: "t5", title: "Sample clean-up", status: .cancelled, steps: [64 GlassAgentStep(id: "s1", title: "Scan", status: .cancelled),65 ], errorMessage: nil),66 ]6768 public init() {}6970 public var body: some View {71 ScrollView {72 VStack(alignment: .leading, spacing: 12) {73 Text("Sample data · simulated tasks, no agent is running")74 .font(.caption)75 .foregroundStyle(.secondary)76 GlassAgentPanel(tasks: tasks) { task in77 cancel(task.id)78 }79 GlassButton("Advance the running task", systemImage: "forward.frame") { advance() }80 Divider()81 Text("No task")82 .font(.headline)83 GlassAgentPanel(tasks: [])84 }85 .padding()86 }87 }8889 private func cancel(_ id: String) {90 guard let index = tasks.firstIndex(where: { $0.id == id }) else { return }91 tasks[index].status = .cancelled92 for step in tasks[index].steps.indices where !tasks[index].steps[step].status.isTerminal {93 tasks[index].steps[step].status = .cancelled94 }95 }9697 /// Completes the running step of the first running task and starts the next one.98 private func advance() {99 guard let index = tasks.firstIndex(where: { $0.status == .running }) else { return }100 if let running = tasks[index].steps.firstIndex(where: { $0.status == .running }) {101 tasks[index].steps[running].status = .succeeded102 }103 if let next = tasks[index].steps.firstIndex(where: { $0.status == .pending }) {104 tasks[index].steps[next].status = .running105 } else {106 tasks[index].status = .succeeded107 }108 }109}110111#Preview("GlassAgentPanel") { GlassAgentPanelExample().glassTheme(.obsidian) }112