@statelyai/sdk 0.6.1 → 0.7.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 CHANGED
@@ -206,12 +206,15 @@ Available client methods:
206
206
  | `studio.projects.get(projectId)` | Fetch a project and its machines |
207
207
  | `studio.machines.create({ projectVersionId, ... })` | Create a machine through the published REST API |
208
208
  | `studio.machines.createMany({ projectVersionId, ... })` | Compatibility wrapper around `create()` that returns a one-item array |
209
+ | `studio.machines.update({ id, ... })` | Update a machine through the published REST API |
209
210
  | `studio.machines.get(machineId, { version? })` | Fetch a machine, optionally pinned to a version |
210
211
  | `studio.code.extractMachines(code, { apiKey? })` | Extract machine configs from source text |
211
212
 
212
213
  ## Sync Helpers
213
214
 
214
- `pushSync()` complements `planSync()` and `pullSync()` for local-to-Studio flows. It resolves a local source file, ensures there is a target project, creates the remote machine, and writes `// @statelyai id=...` back into XState source files.
215
+ `pushSync()` complements `planSync()` and `pullSync()` for local-to-Studio flows. It resolves a local source file, ensures there is a target project, updates the linked remote machine when `// @statelyai id=...` is present, otherwise creates one, and writes the pragma back into XState source files when needed.
216
+
217
+ For project-scoped discovery flows, `statelyai.json` defines which local files should be scanned. The CLI `statelyai push` command uses that config to find local XState sources, creates remote Studio machines for unlabeled ones, updates already-linked ones, and writes returned `// @statelyai id=...` pragmas back into source.
215
218
 
216
219
  ```ts
217
220
  import { pushSync } from '@statelyai/sdk/sync';
@@ -232,7 +235,7 @@ const result = await pushSync({
232
235
  });
233
236
  ```
234
237
 
235
- Projects can also check in a `statelyai.json` file to describe which local sources belong to a Studio project. The published schema lives at `@statelyai/sdk/statelyai.schema.json` and the canonical schema id is `https://stately.ai/schemas/statelyai.json`.
238
+ Projects can also check in a `statelyai.json` file to describe which local sources belong to a Studio project. The published schema lives at `@statelyai/sdk/statelyai.schema.json` and the canonical schema id is `https://stately.ai/schemas/statelyai.json`. The strict XState JSON export schema is published at `@statelyai/sdk/xstate-json.schema.json`.
236
239
 
237
240
  ```json
238
241
  {
@@ -241,17 +244,7 @@ Projects can also check in a `statelyai.json` file to describe which local sourc
241
244
  "projectId": "project_123",
242
245
  "studioUrl": "https://stately.ai",
243
246
  "defaultXStateVersion": 5,
244
- "sources": [
245
- {
246
- "include": ["src/**/*.ts", "src/**/*.tsx"],
247
- "exclude": ["**/*.test.ts", "**/dist/**"],
248
- "format": "xstate"
249
- },
250
- {
251
- "include": ["docs/**/*.mmd"],
252
- "format": "mermaid"
253
- }
254
- ]
247
+ "sources": []
255
248
  }
256
249
  ```
257
250
 
@@ -423,7 +416,7 @@ const aslYaml = await embed.export('asl-yaml');
423
416
 
424
417
  <!-- supported export formats from ExportFormatMap in src/protocol.ts -->
425
418
 
426
- Supported formats: `xstate`, `json`, `xgraph`, `digraph`, `mermaid`, `redux`, `zustand`, `asl-json`, `asl-yaml`, `scxml`
419
+ Supported formats: `xstate`, `xstate-json`, `xgraph`, `digraph`, `mermaid`, `redux`, `zustand`, `asl-json`, `asl-yaml`, `scxml`
427
420
 
428
421
  #### `embed.on(event, handler)` / `embed.off(event, handler)`
429
422
 
@@ -605,11 +598,15 @@ Installing the package also exposes a `statelyai` binary:
605
598
  npx statelyai open ./checkout.machine.ts
606
599
 
607
600
  statelyai init
601
+ statelyai init --scan
608
602
  statelyai login
609
603
  statelyai auth status
610
604
  statelyai plan ./checkout.machine.ts machine-id
611
605
  statelyai diff ./checkout.machine.ts machine-id --fail-on-changes
606
+ statelyai push
607
+ statelyai push ./checkout.machine.ts
612
608
  statelyai pull machine-id ./checkout.machine.ts
609
+ statelyai pull ./checkout.machine.ts
613
610
  statelyai open ./checkout.machine.ts
614
611
  ```
615
612
 
@@ -619,13 +616,15 @@ Available commands:
619
616
 
620
617
  | Command | Description |
621
618
  | ---------------------------------- | --------------------------------------------------------------------------- |
622
- | `statelyai init` | Create or reuse a Studio project for the current directory and write `statelyai.json` |
619
+ | `statelyai init` | Create or reuse a Studio project for the current directory and write `statelyai.json` with an empty `sources` array |
623
620
  | `statelyai login` | Store an API key for future CLI use |
624
621
  | `statelyai logout` | Remove a stored API key |
625
622
  | `statelyai auth status` | Show whether the CLI would use an environment variable or stored credential |
626
623
  | `statelyai plan <source> <target>` | Print a semantic sync summary |
627
624
  | `statelyai diff <source> <target>` | Diff two locators and optionally fail on changes |
625
+ | `statelyai push [file]` | Discover local machine sources, create remote Studio machines for unlabeled files, update linked ones, and persist returned ids |
628
626
  | `statelyai pull <source> <target>` | Materialize a source into a local target file |
627
+ | `statelyai pull <linked-file>` | Refresh a linked local file from the `@statelyai id=...` pragma |
629
628
  | `statelyai open <file>` | Open a local file in a browser-backed visual editor session |
630
629
 
631
630
  Common flags:
@@ -636,6 +635,8 @@ Common flags:
636
635
 
637
636
  The CLI resolves credentials in this order: `--api-key`, then `STATELY_API_KEY`/`NEXT_PUBLIC_STATELY_API_KEY`, then the key stored by `statelyai login`. `login` stores the key in the OS credential store when available, with a private file fallback.
638
637
 
638
+ `statelyai init --scan` walks local code files, detects machine-bearing files from their contents, and suggests `sources` globs to save into `statelyai.json`. Without `--scan`, `init` leaves `sources` empty so you can opt in explicitly before running `statelyai push`.
639
+
639
640
  `statelyai open` also supports `--api-key`, `--editor-url`, `--host`, `--port`, `--no-open`, and `--debug`. It watches the local file on disk and sends source snapshots to `/api/editor-sync/*` endpoints, which return the text replacements to apply locally. When the source file contains `// @statelyai id=...` and an API key is available, the editor session also reuses the referenced remote machine layout while continuing to treat the local source as the semantic source of truth. Pass `--api-key`, set `STATELY_API_KEY`, or run `statelyai login` when the editor server requires auth. Self-hosted servers can disable editor-sync API-key checks with `EDITOR_SYNC_AUTH_REQUIRED=false`. The private source reconciliation engine is not bundled into the published CLI.
640
641
 
641
642
  ## Transport Helpers
@@ -1,4 +1,4 @@
1
- import { m as UploadResult } from "./protocol-CDoCcaIP.mjs";
1
+ import { m as UploadResult } from "./protocol-s9zwsiCW.mjs";
2
2
 
3
3
  //#region src/assetStorage.d.ts
4
4
  interface AssetUploadContext {
package/dist/cli.d.mts CHANGED
@@ -1,14 +1,13 @@
1
1
  import { ConnectedRepo, CreateProjectInput, ProjectData, StudioClient } from "./studio.mjs";
2
- import "./graph-DpBGHZwl.mjs";
3
2
  import { SyncPlan } from "./sync.mjs";
4
3
  import { Command } from "@oclif/core";
5
4
  import * as _oclif_core_interfaces0 from "@oclif/core/interfaces";
6
5
 
7
- //#region src/cli.d.ts
6
+ //#region src/projectConfig.d.ts
8
7
  interface StatelySourceConfig {
9
8
  include: string[];
10
9
  exclude?: string[];
11
- format: 'xstate' | 'redux' | 'zustand' | 'xgraph' | 'digraph' | 'mermaid' | 'scxml' | 'json' | 'asl-json' | 'asl-yaml' | 'auto';
10
+ format: 'xstate' | 'redux' | 'zustand' | 'xgraph' | 'digraph' | 'mermaid' | 'scxml' | 'xstate-json' | 'asl-json' | 'asl-yaml' | 'auto';
12
11
  xstateVersion?: number;
13
12
  }
14
13
  interface StatelyProjectConfig {
@@ -19,6 +18,13 @@ interface StatelyProjectConfig {
19
18
  defaultXStateVersion: number;
20
19
  sources: StatelySourceConfig[];
21
20
  }
21
+ declare function createStatelyProjectConfig(options: {
22
+ projectId: string;
23
+ studioUrl: string;
24
+ defaultXStateVersion?: number;
25
+ }): StatelyProjectConfig;
26
+ //#endregion
27
+ //#region src/cli.d.ts
22
28
  interface InitProjectOptions {
23
29
  apiKey: string;
24
30
  baseUrl?: string;
@@ -34,11 +40,10 @@ interface InitProjectResult {
34
40
  configPath: string;
35
41
  project: ProjectData;
36
42
  }
37
- declare function createStatelyProjectConfig(options: {
38
- projectId: string;
39
- studioUrl: string;
43
+ interface ScanProjectSourcesOptions {
44
+ cwd?: string;
40
45
  defaultXStateVersion?: number;
41
- }): StatelyProjectConfig;
46
+ }
42
47
  type ApiKeyResolution = {
43
48
  apiKey: string;
44
49
  detail: string;
@@ -55,6 +60,7 @@ declare function getEnvApiKey(): {
55
60
  declare function resolveApiKey(explicitApiKey?: string): Promise<ApiKeyResolution>;
56
61
  declare function inferInitProjectName(cwd: string, repo?: ConnectedRepo): string;
57
62
  declare function initProject(options: InitProjectOptions): Promise<InitProjectResult>;
63
+ declare function scanProjectSources(options: ScanProjectSourcesOptions): Promise<StatelySourceConfig[]>;
58
64
  declare function formatPlanSummary(plan: SyncPlan): string;
59
65
  declare abstract class BaseSyncCommand extends Command {
60
66
  static enableJsonFlag: boolean;
@@ -100,7 +106,22 @@ declare class PullCommand extends ParsedSyncCommand {
100
106
  static description: string;
101
107
  static args: {
102
108
  source: _oclif_core_interfaces0.Arg<string, Record<string, unknown>>;
103
- target: _oclif_core_interfaces0.Arg<string, Record<string, unknown>>;
109
+ target: _oclif_core_interfaces0.Arg<string | undefined, Record<string, unknown>>;
110
+ };
111
+ run(): Promise<void>;
112
+ }
113
+ declare class PushCommand extends Command {
114
+ static enableJsonFlag: boolean;
115
+ static summary: string;
116
+ static description: string;
117
+ static args: {
118
+ file: _oclif_core_interfaces0.Arg<string | undefined, Record<string, unknown>>;
119
+ };
120
+ static flags: {
121
+ help: _oclif_core_interfaces0.BooleanFlag<void>;
122
+ 'api-key': _oclif_core_interfaces0.OptionFlag<string | undefined, _oclif_core_interfaces0.CustomOptions>;
123
+ 'base-url': _oclif_core_interfaces0.OptionFlag<string | undefined, _oclif_core_interfaces0.CustomOptions>;
124
+ config: _oclif_core_interfaces0.OptionFlag<string | undefined, _oclif_core_interfaces0.CustomOptions>;
104
125
  };
105
126
  run(): Promise<void>;
106
127
  }
@@ -133,6 +154,7 @@ declare class InitCommand extends Command {
133
154
  name: _oclif_core_interfaces0.OptionFlag<string | undefined, _oclif_core_interfaces0.CustomOptions>;
134
155
  visibility: _oclif_core_interfaces0.OptionFlag<string, _oclif_core_interfaces0.CustomOptions>;
135
156
  force: _oclif_core_interfaces0.BooleanFlag<boolean>;
157
+ scan: _oclif_core_interfaces0.BooleanFlag<boolean>;
136
158
  };
137
159
  run(): Promise<void>;
138
160
  }
@@ -169,6 +191,7 @@ declare const COMMANDS: {
169
191
  plan: typeof PlanCommand;
170
192
  diff: typeof DiffCommand;
171
193
  pull: typeof PullCommand;
194
+ push: typeof PushCommand;
172
195
  open: typeof OpenCommand;
173
196
  init: typeof InitCommand;
174
197
  login: typeof LoginCommand;
@@ -177,4 +200,4 @@ declare const COMMANDS: {
177
200
  };
178
201
  declare function run(argv?: string[], entryUrl?: string): Promise<void>;
179
202
  //#endregion
180
- export { ApiKeyResolution, COMMANDS, InitProjectOptions, InitProjectResult, StatelyProjectConfig, StatelySourceConfig, createStatelyProjectConfig, formatPlanSummary, getEnvApiKey, inferInitProjectName, initProject, resolveApiKey, run };
203
+ export { ApiKeyResolution, COMMANDS, InitProjectOptions, InitProjectResult, ScanProjectSourcesOptions, createStatelyProjectConfig, formatPlanSummary, getEnvApiKey, inferInitProjectName, initProject, resolveApiKey, run, scanProjectSources };