Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Examples/Gallery/AI/GlassChatBubbleExample.swift8// Module : Examples9// Repository : https://git.spboucher.ai/sp-glasskit10// Project Website : https://glass.spboucher.ai11// Created : 2026-12-0212// Last Modified : 2026-12-0313//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 GlassChatBubbleExample: GlassExample {45 public static let componentID = "glass-chat-bubble"4647 /// Fictitious conversation: no model produced these messages.48 @State private var messages = [49 GlassChatMessage(id: "1", role: .system, text: "Sample data — this conversation is fictitious."),50 GlassChatMessage(id: "2", role: .user, text: "Can you summarise the sample quarterly note in two sentences? 🙂"),51 GlassChatMessage(id: "3", role: .assistant, text: "Certainly. The sample note reports steady demand and a slightly lower margin. It expects the next quarter to look similar, with one new product line."),52 GlassChatMessage(id: "4", role: .tool, text: "{\n \"tool\": \"sample_lookup\",\n \"rows\": 3,\n \"a_very_long_key_without_any_space_to_test_wrapping_inside_the_bubble\": true\n}"),53 GlassChatMessage(id: "4b", role: .assistant, text: "The note says:\n> Demand stayed steady over the quarter.\nAs a filter:\n```swift\nlet steady = notes.filter { $0.demand == .steady }\n```"),54 GlassChatMessage(id: "5", role: .user, text: "هل يمكنك كتابة الخلاصة بالعربية؟"),55 GlassChatMessage(id: "6", role: .assistant, text: "The sample answer is still being writ", state: .streaming),56 GlassChatMessage(id: "7", role: .assistant, text: "", state: .streaming),57 GlassChatMessage(id: "8", role: .assistant, text: "A partial sample answer that stopped.", state: .failed(reason: "Sample failure: the connection was interrupted.")),58 ]59 @State private var lastCopied = "Nothing copied yet"60 @State private var retryCount = 06162 public init() {}6364 public var body: some View {65 ScrollView {66 LazyVStack(spacing: 12) {67 ForEach(messages) { message in68 GlassChatBubble(69 message,70 usesMonospacedFont: message.role == .tool,71 onCopy: { text in lastCopied = "Copied \(text.count) characters (kept inside the example)" },72 onRetry: { retryCount += 1 }73 )74 }75 Text("\(lastCopied) · retried \(retryCount) times")76 .font(.caption)77 .foregroundStyle(.secondary)78 }79 .padding()80 }81 }82}8384#Preview("GlassChatBubble") { GlassChatBubbleExample().glassTheme(.aurora) }85