Skip to content

feat: Add native Swift integration for OpenUI (#393)#599

Open
amankoli09 wants to merge 1 commit into
thesysdev:mainfrom
amankoli09:feature/native-swift-integration
Open

feat: Add native Swift integration for OpenUI (#393)#599
amankoli09 wants to merge 1 commit into
thesysdev:mainfrom
amankoli09:feature/native-swift-integration

Conversation

@amankoli09

Copy link
Copy Markdown

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:

  1. 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 (ComponentLibrary and ComponentDef) to define OpenUI component libraries natively in Swift.
    • PromptGenerator.swift: Logic to compile the ComponentLibrary into a system prompt.
    • Parser.swift: A native Swift parser designed to handle OpenUI Lang streaming text formats and compile them into a reactive AST.
  2. OpenUISwiftUI (Renderer Package)

    • OpenUIRenderer.swift: A dynamic, recursive SwiftUI View that traverses the ElementNode tree and maps it to native UI elements (currently supports VStack, HStack, Text, and Button). It uses AnyView to handle recursive structural cycles in SwiftUI.
  3. SwiftUIChat (Example Demo App)

    • A standalone macOS/iOS SwiftUI app showcasing an end-to-end streaming chat integration.

@vishxrad vishxrad requested a review from Aditya-thesys June 5, 2026 21:20
@ankit-thesys

ankit-thesys commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

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:

  • Argument style is backwards. Real OpenUI Lang uses positional args — Button("Submit", "submit:signup").
    This parser only accepts named args (Button(label: "...")) and silently throws positional ones away.
  • References don't work. Real OpenUI Lang splits UI across lines that reference each other (root =
    Stack([header]), then header = ...). This parser drops those references, so anything nested disappears.
  • None of the dynamic stuff exists — variables, conditionals, queries. The types are defined but nothing
    actually parses them.

A few smaller things worth flagging:

  • The tests don't run — the test file isn't wired into the package, so it ships with zero working tests.
  • Only 4 components are supported (fine for a first version), and button actions just print to the
    console — there's no way for the app to actually react to them, which the issue specifically asked for.

Bottom line: good scaffolding, wrong language. The fix is real work but well-scoped — make it positional,
resolve references, and follow the existing grammar in packages/lang-core/src/parser/, which already
defines exactly how this should behave. I'd treat this as "phase 1, needs another pass" rather than ready
to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native Swift Integration

3 participants