Skip to content

Commit 4c8bbf9

Browse files
authored
Tweak Sky docs (#241)
* Tweak readme copy * Fix layout of navbar between 997 and 1049px * Specify tools used for Sky example * Tweak language to make more concise * Format for referring to at-a-glance * Replace image with embedded machine
1 parent f0047c0 commit 4c8bbf9

File tree

2 files changed

+64
-28
lines changed

2 files changed

+64
-28
lines changed

docs/stately-sky-getting-started.mdx

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,88 @@ title: 'Stately Sky getting started'
44

55
# Getting started with Stately Sky
66

7-
This guide will walk you through the process of creating a simple traffic light actor using Stately Sky.
8-
**Please note that Sky is currently in alpha and will be changing rapidly**.
7+
This guide will walk you through deploying a simple traffic light state machine actor with Stately Sky using [XState](/docs/xstate.mdx), [Vite](https://vitejs.dev/) and [React](https://reactjs.org/).
98

10-
## Prerequisites
9+
:::caution
1110

12-
1. A Stately account with a [Pro or Enterprise subscription](https://stately.ai/pricing)
13-
2. Our Stately Sky starter project. [Clone the repo to your local machine](https://github.com/statelyai/sky-starter-app)
14-
3. A machine to deploy as an actor. To test, feel free to fork our [stop light example](https://stately.ai/registry/editor/eb3e89f5-5936-439f-8254-2f6ea4303659?machineId=15fd8071-b80c-4a6f-b9f5-60b6cf578ee5)
11+
Please note that Sky is currently in alpha and will be changing rapidly.
12+
13+
:::
14+
15+
## What you’ll need
16+
17+
- A [Stately](https://stately.ai) account with a [Pro or Enterprise subscription](https://stately.ai/pricing).
18+
- Our [Stately Sky starter project](https://github.com/statelyai/sky-starter-app). Clone the repo to your local machine.
1519

1620
## Getting started video
1721

1822
<YouTube id="A_J1jbz1oWw" />
1923

20-
## Step 1: Create a machine in the Studio
24+
## Step 1: Create a machine with Stately
25+
26+
Create a project and compose your machine in the [Stately editor](https://stately.ai/editor) with the transitions and states you want.
2127

22-
Create a project and compose your machine in the Studio with the transitions and states you want. For this example, we'll create a simple traffic light machine with three states: `green`, `yellow`, and `red`.
28+
For this example, well create a simple traffic light machine with three states: `green`, `yellow`, and `red`. Feel free to fork [our traffic light example](https://stately.ai/registry/editor/eb3e89f5-5936-439f-8254-2f6ea4303659?machineId=15fd8071-b80c-4a6f-b9f5-60b6cf578ee5) to test.
2329

24-
![Traffic light machine in the Studio](../static/assets/sky-getting-started/editor-traffic-light.png)
30+
<EmbedMachine
31+
embedURL="https://stately.ai/registry/editor/embed/eb3e89f5-5936-439f-8254-2f6ea4303659?machineId=15fd8071-b80c-4a6f-b9f5-60b6cf578ee5"
32+
name="Traffic light"
33+
/>
2534

2635
:::xstate
27-
Sky only supports XState V5 machines. The changes in V5 provide both a better developer experience and adhere to the Actor Model more closely, allowing for Sky to capably deploy machines that reliably communicate their state.
36+
Sky only supports [XState](https://github.com/statelyai/xstate) V5 machines. The [changes in XState V5](/docs/migration.mdx) provide both a better developer experience and adhere to the [Actor Model](/docs/actor-model.mdx) more closely, allowing Sky to capably deploy machines that reliably communicate their state.
2837
:::
2938

3039
## Step 2: Create an API key
3140

32-
When you've finished creating your machine, you'll need to create an API key to deploy it to Sky. You can do this by clicking the "Run" button in the top right corner of the Studio. A screen will appear, prompting you to create an API key. Select that button.
41+
After creating your machine, you’ll need to create an API key to deploy it to Sky.
42+
43+
1. Use the **Run** button in the top right corner of the editor to open the Stately Sky options.
44+
2. Use the **Create API Key** button to generate an API key.
3345

3446
![No API key created yet](..//static/assets/sky-getting-started/editor-no-api-key.png)
3547

36-
Be sure to copy that API key and save it somewhere safe. You'll need it later. The page should look like this:
48+
3. Be sure to copy that API key and save it somewhere safe. You’ll need it later.
49+
50+
The page should look like this:
3751

3852
![API key created](..//static/assets/sky-getting-started/editor-api-key.png)
3953

4054
## Step 3: Deploy your machine to Sky
4155

42-
Now that the API key is generated, you can deploy your machine to Sky as a running actor. Select the "Deploy new actor" button to start the process. Once the actor is deployed, the page will display the name of the running actor and the URL you can use to interact with it. You'll need to use that URL to communicate with the actor from the starter project.
56+
Once you have generated the API key, you can deploy your machine to Sky as a running actor.
57+
58+
1. Use the **Deploy new actor** button to start the deployment process.
59+
2. When the actor is deployed, it will be listed under **Existing deploys**.
60+
3. Use **Copy URL** to copy to the URL to your clipboard.
61+
62+
You’ll need the running actor’s URL to communicate with that actor from the starter project.
4363

4464
![Actor deployed](../static/assets/sky-getting-started/editor-deployed-actor.png)
4565

4666
## Step 4: Add your API key to the starter project
4767

48-
Start by opening [the starter project](https://github.com/statelyai/sky-starter-app) in your code editor. Next install the packages using your package manager of choice:
68+
1. Open [the starter project](https://github.com/statelyai/sky-starter-app) in your code editor.
69+
2. Install the packages using your package manager of choice:
4970

5071
```bash npm2yarn
5172
npm install
5273
```
5374

54-
At the root of the project, create a `.env` file to hold your API key.
55-
There are 2 variables that need to be set in the `.env` file, paste your API key as the value for both these keys:
75+
3. At the project’s root, create a `.env` file to hold your API key.
76+
4. Set the following two variables in the `.env` file; paste your API key as the value for both these keys:
5677

57-
1. `SKY_API_KEY` (used by the `@xstate/cli` to fetch the machine config).
58-
2. `VITE_SKY_API_KEY` (used by the Vite React app to connect to Sky).
78+
- `SKY_API_KEY`: used by the `@xstate/cli` to fetch the machine config.
79+
- `VITE_SKY_API_KEY`: used by the Vite React app to connect to Sky.
5980

6081
![.env file](../static/assets/sky-getting-started/code-env-file.png)
6182

6283
## Step 5: Initialize the actor in the starter project
6384

64-
After adding the API key, you'll need to initialize the actor. Create a new file in the `src` directory of the starter project. We named ours `trafficLightActor.ts`. In that file, import the `actorFromStately` function and initialize the actor with the provided URL and your own session ID. The session ID can be any string you want. We recommend using a UUID:
85+
After adding the API key, you’ll need to initialize the actor.
86+
87+
1. Create a new file in the `src` directory of the starter project. We named ours `trafficLightActor.ts`.
88+
2. In your new file, import the `actorFromStately` function and initialize the actor with the provided URL and your own session ID:
6589

6690
```typescript
6791
import { actorFromStately } from '@statelyai/sky';
@@ -72,34 +96,46 @@ const actor = actorFromStately({
7296
});
7397
```
7498

99+
The session ID can be any string you want. We recommend using a UUID.
100+
75101
:::tip
76-
By default Sky is multiplayer. We make use of the session ID to allow multiple tenants to reference the same running actor instance.
102+
By default Sky is multiplayer. We use the session ID to allow multiple tenants to reference the same running actor instance.
77103
:::
78104

79105
## Step 6: Fetching the actor config from Sky
80106

81-
Now that we've initialized the actor, we need to fetch the config from Sky. Doing so will download and generate the machine configuration file in our repo, giving us typesafety when interacting with the running actor!
107+
Now that weve initialized the actor, we need to fetch the config from Sky. Doing so will download and generate the machine configuration file in our repo, giving us type safety when interacting with the running actor!
82108

83-
To fetch the config, we'll use the XState CLI tool. In our `package.json`, we already have a reference to the script we need to run, named `sky`. This runs the command over all the files in the `src` repo to find configs associated with any initialized actors.
109+
To fetch the config, well use the [XState CLI tool](/docs/developer-tools.mdx#xstate-cli-command-line-interface) and the `sky` script already in our `package.json`. This script runs the command over all the files in the `src` repo to find configs associated with any initialized actors.
84110

85111
![package.json](../static/assets/sky-getting-started/code-sky-cmd.png)
86112

87-
Using your package manager of choice, run the `sky` command. For convenience, feel free to use one of the npm or yarn commands below:
113+
1. Using your package manager of choice, run the `sky` command:
88114

89115
```bash npm2yarn
90116
npm run sky
91117
```
92118

93-
Once completed, you should see a second argument passed to the `actorFromStately` function, with the name `skyConfig` and updated imports. You should also see a new TypeScript file in your `src` directory, named after the actor in the Studio. In our case, it's `trafficLightActor.sky.ts`.
119+
2. Once the `sky` command has completed, you should see:
120+
121+
- a second `skyConfig` argument with updated imports passed to the `actorFromStately` function.
122+
- a new TypeScript file in your `src` directory, named after the actor in the Studio. In our case, it’s `trafficLightActor.sky.ts`.
123+
124+
You’ll notice a warning in the `sky.ts` file that the file is generated. You should not manually edit these files as any local changes will not reflect what’s running in Sky.
125+
126+
Running `xstate sky` will only affect a file if it hasn’t already been fetched. If you make changes to the machine in the Studio, you’ll need to delete the generated file `yourFile.sky.ts` and run the command again. Alternatively, you can force the refetch by running `xstate sky --refetch`.
127+
128+
:::tip
129+
130+
Add your generated `sky.ts` files to source control.
131+
132+
:::
94133

95134
![traffic light actor](../static/assets/sky-getting-started/code-traffic-light-with-config.png)
96135

97136
## Finishing up
98137

99-
And that's it! You're now able to interact with your running actor in much the same way you would with local ones, like sending events with the `send()` function. This is still in early days, so there are some limitations and things to remember. Specifically:
138+
And thats it! You can now interact with your running actor in much the same way you would with local actors, like sending events with the `send()` function. Sky is still in its early days, so there are some limitations and things to remember. Specifically:
100139

101140
- Only XState V5 machines are supported.
102141
- Delayed transitions are not yet supported, but will be soon.
103-
- The generated `sky.ts` files are meant to be added to source control.
104-
- You'll notice a warning in the `sky.ts` file that the file is generated. You should not manually edit these files. Any local changes will not reflect what's running in Sky.
105-
- Running `xstate sky` will only affect a file if it hasn't already been fetched. If you make changes to the machine in the Studio, you'll need to delete the generated file `yourFile.sky.ts` and run the command again. Alternatively, you can force the refetch by running `xstate sky --refetch`.
Binary file not shown.

0 commit comments

Comments
 (0)