Agent-readable docs index: /effect-swiftui/llms.txt. Full docs in one file: /effect-swiftui/llms-full.txt. Download /effect-swiftui/docs.zip to grep all markdown files locally.

AppKit 0.2.x: Embed a bundle in your app

AppKit 0.2.x archive. This guide is for existing effect-appkit apps. For a new app, install Effect SwiftUI.
Your app needs two things: the EffectAppKit Swift library and a bundled JavaScript entry that calls start. Swift owns the surface’s lifetime; TypeScript owns the component’s model, messages, and updates. Bun is a build tool, not a process your app needs to launch.

1. Install the matching Swift and TypeScript packages

In Xcode, choose File → Add Package Dependencies, enter https://github.com/tanvesh01/effect-swiftui.git, and select Exact Version: 0.2.1. Link EffectAppKit to your macOS app target. Set the deployment target to macOS 14 or later.
From the directory containing your app’s package.json, use Bun to install the TypeScript adapter from npm and the dependencies imported by the counter below:
bun add --exact effect-appkit@0.2.1 effect@4.1.7 'https://pkg.pr.new/Effect-TS/ui/@effect/ui@dec1ca9'
Commit the resulting bun.lock. Only @effect/ui comes from a pinned upstream preview; fresh installs depend on that preview remaining available. No repository clone or npm login is required. People running your finished app don’t need Bun or npm.

2. Build a self-mounting entry

Create src/main.ts in the app. Import the runtime first: Effect needs TextEncoder and TextDecoder during module evaluation, and JavaScriptCore does not provide these browser globals.
import "effect-appkit/runtime" import * as UiSchema from "@effect/ui/UiSchema" import { component, start } from "effect-appkit" import * as Schema from "effect/Schema" const Message = UiSchema.TaggedEnum({ Count: {} }) const Counter = component({ name: "Counter", model: Schema.Struct({ count: Schema.Number }), message: Message }).make({ init: () => ({ count: 0 }), update: { Count: ({ model }) => ({ count: model.count + 1 }) }, view: (h, model) => h.button .prop("title", `Count: ${model.count}`) .on("press", Message.Count()) }) start(Counter, {})
Bundle from the app directory:
bun build src/main.ts --target=browser --format=iife --conditions=production --minify --outfile=dist/main.js
Add the file dist/main.js to the app target’s Copy Bundle Resources, so it is available as main.js in the main bundle. Rebuild the JavaScript after changing TypeScript; SwiftPM does not run Bun. The browser build target does not supply a DOM, fetch, or Node APIs at runtime.
Bundle only code you trust. This script executes inside your app, not in a sandbox for downloaded plugins.

3. Load the resource and choose a surface

Add this loader to the app target. A missing resource is a packaging error; an empty script is not a substitute.
import Foundation func loadMainScript() throws -> String { guard let url = Bundle.main.url(forResource: "main", withExtension: "js") else { throw CocoaError(.fileNoSuchFile) } return try String(contentsOf: url, encoding: .utf8) }
In a macOS SwiftUI app, replace the app entry with this scene. Load the script once rather than reading the bundle in body.
import EffectAppKit import SwiftUI @main struct CounterApp: App { private let script = Result { try loadMainScript() } var body: some Scene { WindowGroup { switch script { case .success(let source): EffectAppKitSurface(script: source) .frame(minWidth: 240, minHeight: 140) case .failure(let error): Text("Cannot load main.js: \(error.localizedDescription)") } } } }
The wrapper embeds an AppKit view; it does not translate the component into SwiftUI. It displays mount errors in the surface and calls close() when dismantled. Changing the script bytes or the identity or order of registrations remounts the surface and starts a fresh model. Reuse registration instances across body evaluations.
Launch the app and click Count: 0: the same native button should now read Count: 1. Add more built-in controls, or register a Swift view of your own.

Inspect or drive a development build

The Effect UI DevTools guide covers the Xcode scheme setting, sandbox entitlement, timeline, and optional MCP dispatch. Start with read-only inspection; you do not need to change start(...) or add instrumentation to your components.

Live embedding

Use the matching Swift and TypeScript packages. try surface.updateProps(next) takes a complete Encodable value; updateProps(json:) takes UTF-8 JSON Data. The running start root decodes against its props schema before calling Root.setProps. Invalid input throws without changing the root. Neither a valid update nor a window move reinitializes the component. SwiftUI can supply EffectAppKitSurface(script: script, registrations: registrations, props: jsonData); unchanged bytes are skipped, and nil means “do not send a props update.” Like a mount error, a SwiftUI decoding error replaces the content with an error label.
mount(bridge, root, props, options) returns the scoped upstream root; start(root, props, options) owns its scope and returns cleanup. Both forward key, onEmit, fallback, query and head to the pinned Renderer.mount. Props may be an Effect (including asynchronous initialization); scoped mount can receive caller-supplied services, while start provides only the framework environment. start begins immediately. A props update before initialization completes is applied to the root after mount (latest update wins); closing the surface interrupts pending work. An asynchronous mount failure is logged, not thrown retroactively by the Swift initializer.
Head.title(...) supplies the containing window’s title, including after attachment or movement to another window. Removing the title or closing restores the prior title if the surface still owns the displayed value. Give just one root in a window this responsibility: pass { head: false } to embedded panels. $.viewTransition() runs the flush once with a short native crossfade; Reduce Motion and unattached surfaces skip animation, not the update. Transition type strings do not select CSS animations.