@effect-state-machine/studio-client
v0.3.0
Published
Connects running effect-state-machine machines to Studio.
Readme
@effect-state-machine/studio-client
Connects running effect-state-machine
machines to Studio, the standalone
devtool.
Install
pnpm add @effect-state-machine/studio-clienteffect and effect-state-machine are peer dependencies.
Attach a running machine
import { Attach, Transport, WebSocketTransport } from "@effect-state-machine/studio-client"
import * as Effect from "effect/Effect"
import * as MachineEngine from "effect-state-machine/MachineEngine"
const program = Effect.scoped(
Effect.gen(function* () {
const handle = yield* definition.run(input)
yield* Attach.attach({
definition,
handle,
quickEvents: [{ id: "save", label: "Save", event: { _tag: "Save" } }],
})
// …the application continues normally
}),
).pipe(
Effect.provide(MachineEngine.layerMemory()),
Effect.provideService(Transport.StudioTransport, WebSocketTransport.make()),
)Attaching is scoped and observational: it never interrupts the machine, and it is inert when no Studio is running — the client connects lazily, retries in the background, and buffers unsent facts (bounded, oldest dropped with a truncation notice). One attachment represents the root machine and every child machine it owns as a single ordered Studio session.
The transport is a swappable Effect service (StudioTransport): WebSocketTransport reaches a
local Studio server, and an in-memory pair ships for tests and embedded use.
For a runnable walkthrough see
examples/checkout-demo.ts.
