feat: Add native Swift integration for OpenUI (#393)#599
Conversation
|
First off, nice start. The package builds cleanly on Mac, the overall structure is sensible, and the prompt generator and basic SwiftUI rendering work. As a foundation, it's a reasonable first step. There's one big problem, though: it doesn't actually speak OpenUI Lang. The parser was built against a made-up syntax that only looks like OpenUI Lang. They share the name = Component(...) shape and nothing else. I tested it by feeding it real examples straight from our own docs and tests — and every one came back empty, with no error reported. So a Swift app built on this wouldn't be compatible with any of our other runtimes (React, Vue, Svelte), which defeats the whole "one portable language everywhere" goal of the issue. The three things that make it a different language:
A few smaller things worth flagging:
Bottom line: good scaffolding, wrong language. The fix is real work but well-scoped — make it positional, |
Closes #393
+What this PR does / why we need it:
This PR introduces native Swift integration for OpenUI, bringing the power of the openui-lang protocol to Apple-platform native apps without requiring a WebView.
This provides Swift-first teams the tools to define components, generate prompts, parse streamed outputs, and render them natively using SwiftUI.
Changes included in this PR:
OpenUILang(Core Swift Package)AST.swift&Types.swift: Native data models mapping to the OpenUI specification (ASTNode,ElementNode,ParseResult).Library.swift: A type-safe registry (ComponentLibraryandComponentDef) to define OpenUI component libraries natively in Swift.PromptGenerator.swift: Logic to compile theComponentLibraryinto a system prompt.Parser.swift: A native Swift parser designed to handle OpenUI Lang streaming text formats and compile them into a reactive AST.OpenUISwiftUI(Renderer Package)OpenUIRenderer.swift: A dynamic, recursive SwiftUIViewthat traverses theElementNodetree and maps it to native UI elements (currently supportsVStack,HStack,Text, andButton). It usesAnyViewto handle recursive structural cycles in SwiftUI.SwiftUIChat(Example Demo App)