Use SwiftUI, Observation, and Swift Concurrency to build streaming AI chat that avoids duplicate text, stops cleanly, respects scrolling, and recovers after interruption.
Use the Lua 5.4.8 coroutine API to separate waiting intents from a scheduler, with explicit cancellation, error boundaries, and deterministic tests.
Give shared mutable resources to actors, keep presentation state on MainActor, and handle races with cancellation and request identity.
Separate downloading, caching, decoding, and presentation state to build a SwiftUI image pipeline with cancellation and validated responses.