@statelyai/sdk 0.10.0 → 0.10.2
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 +97 -13
- package/dist/{graph-DmXh22Zu.d.mts → graph-GeuH-mFK.d.mts} +13 -2
- package/dist/graph.d.mts +1 -1
- package/dist/graphToXStateTS-DOaLOySy.mjs +5486 -0
- package/dist/index.d.mts +10 -1
- package/dist/index.mjs +1 -1
- package/dist/protocol.d.mts +11 -0
- package/dist/studio.mjs +20 -2
- package/dist/sync.d.mts +1 -1
- package/dist/sync.mjs +3225 -30
- package/package.json +2 -2
- package/schemas/statelyai.schema.json +2 -2
- package/dist/graphToXStateTS-moihsH_U.mjs +0 -710
package/README.md
CHANGED
|
@@ -1,26 +1,110 @@
|
|
|
1
1
|
# @statelyai/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **Preview** -- this SDK is not yet publicly available. Reach out to [team@stately.ai](mailto:team@stately.ai) for early access.
|
|
4
4
|
|
|
5
|
-
The Stately
|
|
5
|
+
The Stately SDK lets you embed the [Stately visual editor](https://stately.ai) directly into your own application, inspect live actor systems, and programmatically manage Stately Studio projects and machines.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## What's coming
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### Embeddable editor
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
Drop a fully interactive state machine editor into any web app. The embed communicates over `postMessage` and gives you full control over theme, layout, panels, read-only mode, and more.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createStatelyEmbed } from '@statelyai/sdk';
|
|
15
|
+
|
|
16
|
+
const embed = createStatelyEmbed({
|
|
17
|
+
baseUrl: 'https://stately.ai',
|
|
18
|
+
apiKey: 'your-api-key',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
embed.mount(document.getElementById('editor')!);
|
|
22
|
+
|
|
23
|
+
embed.init({
|
|
24
|
+
machine: myMachineConfig,
|
|
25
|
+
format: 'xstate',
|
|
26
|
+
mode: 'editing',
|
|
27
|
+
theme: 'dark',
|
|
28
|
+
});
|
|
13
29
|
```
|
|
14
30
|
|
|
15
|
-
|
|
31
|
+
Key capabilities:
|
|
32
|
+
|
|
33
|
+
- **Mount or attach** to any container element or existing iframe
|
|
34
|
+
- **Two-way sync** - push machine configs in, get changes and saves back via event callbacks
|
|
35
|
+
- **Export** to multiple formats: XState v5, XState JSON, Mermaid, Redux, Zustand, ASL, SCXML, and more
|
|
36
|
+
- **Comments** via Liveblocks integration (optional)
|
|
37
|
+
- **Asset uploads** with built-in S3 and Supabase adapters, or bring your own upload handler
|
|
38
|
+
- **Runtime settings** - toggle color mode, grid, snap lines, autolayout, and view mode on the fly
|
|
39
|
+
|
|
40
|
+
### Self-hosting
|
|
41
|
+
|
|
42
|
+
The SDK is designed to work with both hosted Stately (`stately.ai`) and self-hosted deployments of the editor.
|
|
43
|
+
|
|
44
|
+
When self-hosting, authentication is handled by your editor server, not by this npm package. The editor host supports configurable auth strategies, and you can disable API-key checks for editor-sync endpoints when running behind your own auth layer.
|
|
45
|
+
|
|
46
|
+
A fully self-contained deployment with no external auth looks like:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
const embed = createStatelyEmbed({
|
|
50
|
+
baseUrl: 'https://your-editor.example.com',
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Key environment variables for self-hosted deployments:
|
|
55
|
+
|
|
56
|
+
| Variable | Purpose |
|
|
57
|
+
| --------------------------- | -------------------------------------------- |
|
|
58
|
+
| `AUTH_PROVIDER` | Auth strategy used by the editor host |
|
|
59
|
+
| `EDITOR_SYNC_AUTH_REQUIRED` | Set to `false` to skip editor-sync API-key checks |
|
|
60
|
+
| `STATELY_API_KEY` | Server-side API key for Stately data fetching |
|
|
61
|
+
| `STATELY_API_URL` | Stately API base URL override |
|
|
62
|
+
| `NEXT_PUBLIC_BASE_URL` | Public-facing editor URL |
|
|
63
|
+
|
|
64
|
+
### Studio API client
|
|
16
65
|
|
|
17
|
-
|
|
66
|
+
Programmatic access to Stately Studio for managing projects and machines, extracting machine configs from source code, and verifying API keys.
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { createStatelyClient } from '@statelyai/sdk';
|
|
70
|
+
|
|
71
|
+
const studio = createStatelyClient({
|
|
72
|
+
apiKey: process.env.STATELY_API_KEY,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const projects = await studio.projects.list();
|
|
76
|
+
const machine = await studio.machines.get('machine-id');
|
|
77
|
+
const extracted = await studio.code.extractMachines(sourceCode);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Inspector
|
|
81
|
+
|
|
82
|
+
Stream live actor-system state to the Stately inspector over WebSockets, with support for automatic XState actor adoption and manual actor registration.
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { createActor } from 'xstate';
|
|
86
|
+
import { createStatelyInspector } from '@statelyai/sdk';
|
|
87
|
+
|
|
88
|
+
const inspector = createStatelyInspector({
|
|
89
|
+
actor: createActor(machine),
|
|
90
|
+
autoOpen: true,
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### CLI and sync
|
|
95
|
+
|
|
96
|
+
A `statelyai` CLI for syncing local XState source files with Stately Studio projects: push local machines to the cloud, pull remote changes back into source, and open a local file in a browser-backed visual editor session.
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
npx statelyai push
|
|
100
|
+
npx statelyai pull
|
|
101
|
+
npx statelyai open ./checkout.machine.ts
|
|
102
|
+
```
|
|
18
103
|
|
|
19
|
-
|
|
104
|
+
### Graph and codegen helpers
|
|
20
105
|
|
|
21
|
-
|
|
106
|
+
Convert between Studio graph data, XState machine configs, and TypeScript source. Generate types from JSON Schema.
|
|
22
107
|
|
|
23
|
-
|
|
24
|
-
- `@statelyai/sdk/xstate.schema.json`
|
|
108
|
+
## Get notified
|
|
25
109
|
|
|
26
|
-
|
|
110
|
+
This SDK and the embeddable editor are in active development. For early access, pricing, and self-hosting details, contact [team@stately.ai](mailto:team@stately.ai).
|
|
@@ -142,6 +142,8 @@ interface JSONSchema7 {
|
|
|
142
142
|
//#endregion
|
|
143
143
|
//#region ../graph-tools/src/codegenTypes.d.ts
|
|
144
144
|
interface CodeGenAction {
|
|
145
|
+
/** Graph-native block id, referenced by `@statelyai.action.*` transitions. */
|
|
146
|
+
id?: string;
|
|
145
147
|
type: string;
|
|
146
148
|
params?: Record<string, unknown>;
|
|
147
149
|
}
|
|
@@ -161,10 +163,18 @@ interface CodeExpression {
|
|
|
161
163
|
'@type': 'code';
|
|
162
164
|
lang: 'js' | 'ts';
|
|
163
165
|
expr: string;
|
|
166
|
+
imports?: CodeImport[];
|
|
167
|
+
}
|
|
168
|
+
interface CodeImport {
|
|
169
|
+
package: string;
|
|
170
|
+
import: string;
|
|
171
|
+
importKind?: 'named' | 'default' | 'namespace';
|
|
172
|
+
version?: string;
|
|
164
173
|
}
|
|
165
174
|
interface CodeGenInvoke {
|
|
166
175
|
src: string;
|
|
167
176
|
id: string;
|
|
177
|
+
invocationId?: string;
|
|
168
178
|
input?: Record<string, unknown> | CodeExpression;
|
|
169
179
|
output?: Record<string, unknown> | CodeExpression;
|
|
170
180
|
}
|
|
@@ -184,7 +194,7 @@ interface CodeGenNodeData {
|
|
|
184
194
|
meta?: Record<string, unknown> | null;
|
|
185
195
|
color?: string;
|
|
186
196
|
parentId?: string | null;
|
|
187
|
-
temp?:
|
|
197
|
+
temp?: unknown;
|
|
188
198
|
}
|
|
189
199
|
interface CodeGenEdgeData {
|
|
190
200
|
eventType: string;
|
|
@@ -194,7 +204,7 @@ interface CodeGenEdgeData {
|
|
|
194
204
|
description?: string | null;
|
|
195
205
|
color?: string;
|
|
196
206
|
meta?: Record<string, unknown> | null;
|
|
197
|
-
temp?:
|
|
207
|
+
temp?: unknown;
|
|
198
208
|
}
|
|
199
209
|
interface CodeGenImplementation {
|
|
200
210
|
id: string;
|
|
@@ -220,6 +230,7 @@ interface CodeGenActorImplementation {
|
|
|
220
230
|
} | null;
|
|
221
231
|
}
|
|
222
232
|
interface CodeGenGraphData {
|
|
233
|
+
context?: Record<string, unknown> | CodeExpression | null;
|
|
223
234
|
schemas?: {
|
|
224
235
|
context?: Record<string, JSONSchema7> | null;
|
|
225
236
|
events?: Record<string, JSONSchema7> | null;
|
package/dist/graph.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as studioMachineConverter, a as StatelyGraphData, c as StatelyInvoke, d as StudioAction, f as StudioEdge, g as fromStudioMachine, h as StudioNode, i as StatelyGraph, l as StatelyNodeData, m as StudioMachine, n as StatelyActorImplementation, o as StatelyGuard, p as StudioEventTypeData, r as StatelyEdgeData, s as StatelyImplementation, t as StatelyAction, u as StatelyTagImplementation, v as toStudioMachine } from "./graph-
|
|
1
|
+
import { _ as studioMachineConverter, a as StatelyGraphData, c as StatelyInvoke, d as StudioAction, f as StudioEdge, g as fromStudioMachine, h as StudioNode, i as StatelyGraph, l as StatelyNodeData, m as StudioMachine, n as StatelyActorImplementation, o as StatelyGuard, p as StudioEventTypeData, r as StatelyEdgeData, s as StatelyImplementation, t as StatelyAction, u as StatelyTagImplementation, v as toStudioMachine } from "./graph-GeuH-mFK.mjs";
|
|
2
2
|
export { StatelyAction, StatelyActorImplementation, StatelyEdgeData, StatelyGraph, StatelyGraphData, StatelyGuard, StatelyImplementation, StatelyInvoke, StatelyNodeData, StatelyTagImplementation, StudioAction, StudioEdge, StudioEventTypeData, StudioMachine, StudioNode, fromStudioMachine, studioMachineConverter, toStudioMachine };
|