SP GlassKit1.1.0

GlassChatBubble

Message bubble with role, streaming state, text selection and copy.

  • Content
  • iOS 26 · iPadOS 26 · macOS 26
  • Version 1.1.0
  • glass-chat-bubble

Content on an opaque, readable surface. Glass is kept for controls.

GlassChatBubble running in SP Glass Studio.Capture
Capture of the component running in SP Glass Studio on the iOS 26.5 simulator. Liquid Glass is rendered by the system; this is an image, not a live preview.

Installation

spglass add glass-chat-bubble

Copies the sources and their dependencies into your project. Set up the CLI.

Swift
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")

import SPGlassKit
Identifierglass-chat-bubble
ModuleSPGlassAI
Kindcontent-component — text on an opaque bubble; no glass
PlatformsiOS 26, iPadOS 26, macOS 26
ExampleExamples/Gallery/AI/GlassChatBubbleExample.swift

UI only: the component displays a message value. It contains no AI provider, no key and no network code.

Minimal usage

Swift
GlassChatBubble(GlassChatMessage(id: "1", role: .assistant, text: "Hello."))

Variants

VariantUse
role: .userTrailing edge, filled with the theme's primary colour, labelled "You".
role: .assistant, .system, .toolLeading edge, opaque themed surface, labelled "Assistant", "System", "Tool".
state: .streamingA "Receiving response" indicator follows the text; the copy button is hidden until the text is final.
CopyA copy button sits under finished messages of the assistant, the system and tools. The user's own messages keep the context menu only (GlassChatBubbleMetrics.showsCopyButton).
state: .failed(reason:)A warning symbol with the reason (or a generic message) under the bubble, and "Retry" when onRetry is given.
usesMonospacedFont: trueCode-like content such as tool output.
Fenced code and quotesA block between two lines of three backticks is set in a monospaced inset that scrolls sideways (the word after the opening fence is shown as its language); consecutive lines starting with > are set as a quote. Nothing else is interpreted: no inline styles, no links, no HTML. rendersBlocks: false shows the text as it is.

Parameters

ParameterTypeDefaultMeaning
messageGlassChatMessage—id, role, text, state.
maxWidthFractionDouble0.8Largest share of the container's width the bubble takes; clamped to 0.4…1.
usesMonospacedFontBoolfalseMonospaced text.
rendersBlocksBooltrueSets fenced code and quotes apart. Ignored with usesMonospacedFont.
onCopy(@MainActor (String) -> Void)?nilReceives the text on copy. When nil the text is written to the system pasteboard.
onRetry(@MainActor () -> Void)?nilShows "Retry" on failed messages.

States

Complete, streaming, failed. A streaming message with empty text shows the indicator alone. After a copy the button shows a checkmark and "Copied" for 1.5 seconds.

Advanced example

Swift
ScrollView {
    LazyVStack(spacing: 12) {
        ForEach(conversation.messages) { message in      // [GlassChatMessage], updated by the host while streaming
            GlassChatBubble(
                message,
                maxWidthFraction: 0.75,
                usesMonospacedFont: message.role == .tool,
                onRetry: message.role == .assistant ? { conversation.regenerate(message.id) } : nil
            )
        }
    }
    .padding()
}
.defaultScrollAnchor(.bottom)

Accessibility

  • The role is written above the bubble and read with the text ("Assistant, …"): it never depends on colour or side.
  • The text is selectable (textSelection(.enabled)); copy is also in the context menu.
  • While streaming the element has the "updates frequently" trait and the indicator has a text label; its symbol animation stops with Reduce Motion.
  • Failure is a symbol plus text. The copy button is labelled "Copy" / "Copied" and has a 44-point target on iOS.
  • Alignment uses leading and trailing, so the layout mirrors in right-to-left languages; right-to-left text inside a bubble keeps its natural direction.

Limits

  • Plain text only: no Markdown rendering, no syntax highlighting, no images. usesMonospacedFont applies to the whole message.
  • Very long messages are laid out in full; put the bubbles in a lazy stack and keep the conversation in the host.
  • Unbroken strings (long URLs, identifiers) wrap by character.
  • The bubble does not scroll the conversation or keep it pinned to the bottom: that is the container's role.
  • Layout with long, code-like, emoji and right-to-left text is in the example and compiles; it was not inspected in a running application during verification.

Example

Complete example (compiled with the package)
import SwiftUI
import SPGlassKit

public struct GlassChatBubbleExample: GlassExample {
    public static let componentID = "glass-chat-bubble"

    /// Fictitious conversation: no model produced these messages.
    @State private var messages = [
        GlassChatMessage(id: "1", role: .system, text: "Sample data — this conversation is fictitious."),
        GlassChatMessage(id: "2", role: .user, text: "Can you summarise the sample quarterly note in two sentences? 🙂"),
        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."),
        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}"),
        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```"),
        GlassChatMessage(id: "5", role: .user, text: "هل يمكنك كتابة الخلاصة بالعربية؟"),
        GlassChatMessage(id: "6", role: .assistant, text: "The sample answer is still being writ", state: .streaming),
        GlassChatMessage(id: "7", role: .assistant, text: "", state: .streaming),
        GlassChatMessage(id: "8", role: .assistant, text: "A partial sample answer that stopped.", state: .failed(reason: "Sample failure: the connection was interrupted.")),
    ]
    @State private var lastCopied = "Nothing copied yet"
    @State private var retryCount = 0

    public init() {}

    public var body: some View {
        ScrollView {
            LazyVStack(spacing: 12) {
                ForEach(messages) { message in
                    GlassChatBubble(
                        message,
                        usesMonospacedFont: message.role == .tool,
                        onCopy: { text in lastCopied = "Copied \(text.count) characters (kept inside the example)" },
                        onRetry: { retryCount += 1 }
                    )
                }
                Text("\(lastCopied) · retried \(retryCount) times")
                    .font(.caption)
                    .foregroundStyle(.secondary)
            }
            .padding()
        }
    }
}

#Preview("GlassChatBubble") { GlassChatBubbleExample().glassTheme(.aurora) }

Registry entry

Identifierglass-chat-bubble
Version1.1.0
Depends onglass-foundation
FrameworksSwiftUI
Public symbolsGlassChatRole, GlassChatMessageState, GlassChatMessage, GlassChatBubbleMetrics, GlassChatBlock, GlassChatBlocks, GlassChatBubble
LicenceMIT
Manifestmanifest.json

Files