@vizij/orchestrator-react 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,213 @@
1
+ # @vizij/orchestrator-react
2
+
3
+ > **React bindings for Vizij’s orchestrator – register controllers, stream blackboard writes, and manage playback from JSX.**
4
+
5
+ This package layers a declarative provider and hook set on top of `@vizij/orchestrator-wasm`. It handles WASM initialisation, orchestrator creation, controller registration, frame subscriptions, and convenient helpers like `useOrchTarget`.
6
+
7
+ ---
8
+
9
+ ## Table of Contents
10
+
11
+ 1. [Overview](#overview)
12
+ 2. [Installation](#installation)
13
+ 3. [Peer Dependencies](#peer-dependencies)
14
+ 4. [Quick Start](#quick-start)
15
+ 5. [Core Concepts](#core-concepts)
16
+ 6. [Hook Reference](#hook-reference)
17
+ 7. [Development & Testing](#development--testing)
18
+ 8. [Publishing](#publishing)
19
+ 9. [Related Packages](#related-packages)
20
+
21
+ ---
22
+
23
+ ## Overview
24
+
25
+ - `OrchestratorProvider` sets up a shared orchestrator instance backed by `@vizij/orchestrator-wasm`.
26
+ - Hooks expose imperative APIs (`useOrchestrator`) and observational subscriptions (`useOrchFrame`, `useOrchTarget`), all built on `useSyncExternalStore`.
27
+ - Local caching ensures that host-triggered `setInput` calls update hook subscribers immediately (0.3.x improvement).
28
+ - Native graph merging support: `registerMergedGraph` wires multiple specs together with configurable conflict strategies (`error`, `namespace`, `blend`).
29
+ - Works alongside `@vizij/node-graph-react` and `@vizij/animation-react` to coordinate multi-domain Vizij experiences.
30
+
31
+ ---
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ # pnpm
37
+ pnpm add @vizij/orchestrator-react @vizij/orchestrator-wasm react react-dom
38
+
39
+ # npm
40
+ npm install @vizij/orchestrator-react @vizij/orchestrator-wasm react react-dom
41
+
42
+ # yarn
43
+ yarn add @vizij/orchestrator-react @vizij/orchestrator-wasm react react-dom
44
+ ```
45
+
46
+ If you consume locally linked WASM packages from `vizij-rs`, configure your Vite dev server to preserve symlinks, exclude the wasm pkg from pre-bundling, and enable COOP/COEP headers. See the Vizij web monorepo README for an end-to-end example.
47
+
48
+ ---
49
+
50
+ ## Peer Dependencies
51
+
52
+ - `react >= 18`
53
+ - `react-dom >= 18`
54
+ - `@vizij/orchestrator-wasm` (publish from `vizij-rs` first, then update this dependency range)
55
+
56
+ Double-check these ranges before releasing to avoid duplicate React copies or mismatched orchestrator ABI versions.
57
+
58
+ ---
59
+
60
+ ## Quick Start
61
+
62
+ ```tsx
63
+ import {
64
+ OrchestratorProvider,
65
+ useOrchestrator,
66
+ useOrchFrame,
67
+ useOrchTarget,
68
+ } from "@vizij/orchestrator-react";
69
+
70
+ function Dashboard() {
71
+ const {
72
+ ready,
73
+ createOrchestrator,
74
+ registerGraph,
75
+ registerAnimation,
76
+ setInput,
77
+ step,
78
+ } = useOrchestrator();
79
+ const frame = useOrchFrame();
80
+ const demoValue = useOrchTarget("demo/output/value");
81
+
82
+ React.useEffect(() => {
83
+ if (!ready) {
84
+ createOrchestrator({ schedule: "SinglePass" }).catch(console.error);
85
+ }
86
+ }, [ready, createOrchestrator]);
87
+
88
+ return (
89
+ <div>
90
+ <button onClick={() => registerGraph({ spec: { nodes: [] } })}>
91
+ Register graph
92
+ </button>
93
+ <button onClick={() => registerAnimation({ setup: {} })}>
94
+ Register animation
95
+ </button>
96
+ <button
97
+ onClick={() =>
98
+ setInput("demo/input/value", { float: Math.random() * 10 })
99
+ }
100
+ >
101
+ Push input
102
+ </button>
103
+ <button onClick={() => step(1 / 60)}>Step</button>
104
+ <pre>{JSON.stringify(frame?.merged_writes ?? [], null, 2)}</pre>
105
+ <p>Latest demo value: {JSON.stringify(demoValue)}</p>
106
+ </div>
107
+ );
108
+ }
109
+
110
+ export function App() {
111
+ return (
112
+ <OrchestratorProvider autostart={false}>
113
+ <Dashboard />
114
+ </OrchestratorProvider>
115
+ );
116
+ }
117
+ ```
118
+
119
+ ---
120
+
121
+ ## Core Concepts
122
+
123
+ ### Provider Props
124
+
125
+ - `initInput` – Forwards optional init input to `@vizij/orchestrator-wasm.init`.
126
+ - `autoCreate` (default `true`) – Automatically call `createOrchestrator` on mount.
127
+ - `createOptions` – Options passed to `createOrchestrator` (e.g., `{ schedule: "TwoPass" }`).
128
+ - `autostart` – When `true`, kicks off an `requestAnimationFrame` loop stepping the orchestrator every frame.
129
+
130
+ ### Context Surface
131
+
132
+ `useOrchestrator()` exposes:
133
+
134
+ - Lifecycle: `ready`, `createOrchestrator`, `requireOrchestrator`.
135
+ - Controller management: `registerGraph`, `registerMergedGraph`, `registerAnimation`, `removeGraph`, `removeAnimation`, `listControllers`.
136
+ - Blackboard API: `setInput`, `removeInput`, `prebind` — paths are normalised (trimmed, no whitespace) before staging to match `TypedPath` requirements.
137
+ - Stepping: `step`, plus autostart support in the provider.
138
+ - Utilities: `normalizeGraphSpec?(spec)` and `abiVersion?()` expose WASM helpers for editor tooling and compatibility checks.
139
+ - Internals ensure `setInput` mirrors values into a local cache so `useOrchTarget` subscribers update immediately, even before the next `step`.
140
+
141
+ ### Frame & Path Subscriptions
142
+
143
+ - `useOrchFrame()` – Subscribes to the latest `OrchestratorFrame` (merged writes, conflicts, timings, events).
144
+ - `useOrchTarget(path)` – Observes a single blackboard path. Paths are normalised before subscription and cached so updates only re-render interested components.
145
+ - `valueHelpers` – `valueAsNumber`, `valueAsVec3`, `valueAsBool` mirror helpers from `@vizij/value-json` for convenience.
146
+
147
+ ### StrictMode Consideration
148
+
149
+ React 18 StrictMode double-mounts providers in development. Because the orchestrator uses internal mutable refs, the second mount can leave `ready` false. Either avoid wrapping the provider in `<React.StrictMode>` or conditionally gate initialisation if you need both.
150
+
151
+ ---
152
+
153
+ ## Hook Reference
154
+
155
+ | Hook | Description |
156
+ | --------------------- | ------------------------------------------------------------------------------------------------- |
157
+ | `useOrchestrator()` | Returns the imperative API described above. |
158
+ | `useOrchFrame()` | Subscribes to the latest `OrchestratorFrame`. |
159
+ | `useOrchTarget(path)` | Subscribes to a single merged-write path, with immediate updates on `setInput`. |
160
+ | `useValueHelpers()` | Access `valueAsNumber`, `valueAsVec3`, `valueAsBool` (or import directly from `valueHelpers.ts`). |
161
+
162
+ ---
163
+
164
+ ## Development & Testing
165
+
166
+ Run scripts with pnpm filters:
167
+
168
+ ```bash
169
+ pnpm --filter "@vizij/orchestrator-react" dev
170
+ pnpm --filter "@vizij/orchestrator-react" test
171
+ pnpm --filter "@vizij/orchestrator-react" build
172
+ pnpm --filter "@vizij/orchestrator-react" typecheck
173
+ ```
174
+
175
+ Vitest tests mock the wasm binding to keep execution fast. When you want end-to-end coverage against the real `vizij-orchestrator-wasm` build, rebuild the WASM package in `vizij-rs` (`pnpm run build:wasm:orchestrator`) and launch the `apps/demo-orchestrator` workspace.
176
+
177
+ ---
178
+
179
+ ## Publishing
180
+
181
+ The tag-driven workflow in [`.github/workflows/publish-npm.yml`](../../../.github/workflows/publish-npm.yml) publishes this package.
182
+
183
+ 1. Create a changeset and apply the version bump:
184
+ ```bash
185
+ pnpm changeset
186
+ pnpm version:packages
187
+ ```
188
+ 2. Validate locally:
189
+ ```bash
190
+ pnpm install
191
+ pnpm --filter "@vizij/orchestrator-react" build
192
+ pnpm --filter "@vizij/orchestrator-react" test
193
+ pnpm --filter "@vizij/orchestrator-react" typecheck
194
+ pnpm --filter "@vizij/orchestrator-react" exec npm pack --dry-run
195
+ ```
196
+ 3. Push a tag of the form `npm-orchestrator-react-vX.Y.Z`:
197
+ ```bash
198
+ git tag npm-orchestrator-react-v0.3.0
199
+ git push origin npm-orchestrator-react-v0.3.0
200
+ ```
201
+
202
+ Successful runs publish with provenance metadata using `NODE_AUTH_TOKEN`.
203
+
204
+ ---
205
+
206
+ ## Related Packages
207
+
208
+ - [`@vizij/orchestrator-wasm`](../../../vizij-rs/npm/@vizij/orchestrator-wasm/README.md) – wasm wrapper consumed by this package.
209
+ - [`vizij-orchestrator-core`](../../../vizij-rs/crates/orchestrator/vizij-orchestrator-core/README.md) – Rust crate providing orchestrator logic.
210
+ - [`@vizij/node-graph-react`](../@vizij/node-graph-react/README.md) & [`@vizij/animation-react`](../@vizij/animation-react/README.md) – React bindings for the other Vizij stacks.
211
+ - `apps/demo-orchestrator` – Minimal showcase using this package end-to-end.
212
+
213
+ Questions or feedback? Open an issue in Vizij’s main repo—great documentation keeps orchestration predictable. 🔄