motia 0.17.4-beta.186-361289 → 0.17.5-beta.186
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/dist/create/templates/nodejs/src/petstore/api.step.ts.txt +2 -2
- package/dist/create/templates/nodejs/src/petstore/process-food-order.step.ts.txt +1 -1
- package/dist/create/templates/nodejs/src/petstore/state-audit-cron.step.ts.txt +1 -1
- package/dist/create/templates/nodejs/tutorial/tutorial.tsx.txt +221 -83
- package/dist/create/templates/python/tutorial/tutorial.tsx.txt +219 -81
- package/package.json +8 -8
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ApiRouteConfig, Handlers } from 'motia'
|
|
2
2
|
import { z } from 'zod'
|
|
3
|
-
import { petStoreService } from '
|
|
4
|
-
import { petSchema } from '
|
|
3
|
+
import { petStoreService } from '../services/pet-store'
|
|
4
|
+
import { petSchema } from '../services/types'
|
|
5
5
|
|
|
6
6
|
export const config: ApiRouteConfig = {
|
|
7
7
|
type: 'api',
|
|
@@ -44,12 +44,7 @@ export const steps: TutorialStep[] = [
|
|
|
44
44
|
{
|
|
45
45
|
elementXpath: workbenchXPath.flows.previewButton('apitrigger'),
|
|
46
46
|
title: 'Code Preview',
|
|
47
|
-
description: () =>
|
|
48
|
-
<p>
|
|
49
|
-
Clicking on this icon will allow you to visualize the source code for a given Step. This opens a code viewer
|
|
50
|
-
with interactive feature cards that explain different parts of the code.
|
|
51
|
-
</p>
|
|
52
|
-
),
|
|
47
|
+
description: () => <p>Clicking on this icon will allow you to visualize the source code for a given Step.</p>,
|
|
53
48
|
before: [
|
|
54
49
|
{
|
|
55
50
|
type: 'click',
|
|
@@ -60,45 +55,143 @@ export const steps: TutorialStep[] = [
|
|
|
60
55
|
},
|
|
61
56
|
{
|
|
62
57
|
elementXpath: workbenchXPath.sidebarContainer,
|
|
63
|
-
title: '
|
|
58
|
+
title: 'Step Config',
|
|
64
59
|
description: () => (
|
|
65
60
|
<div>
|
|
66
61
|
<p>
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
All Steps are defined by two main components, the <b>configuration</b> and the <b>handler</b>.
|
|
63
|
+
<br />
|
|
64
|
+
<br />
|
|
65
|
+
Let's start with the configuration, the common config attributes are
|
|
66
|
+
<i> type, name, description, and flows</i>.
|
|
67
|
+
<br />
|
|
68
|
+
<br />
|
|
69
69
|
</p>
|
|
70
|
-
<
|
|
71
|
-
<p>
|
|
72
|
-
<b>Click on the feature cards</b> to learn about:
|
|
73
|
-
</p>
|
|
74
|
-
<ul className="square-decoration">
|
|
75
|
-
<li>
|
|
76
|
-
<b>Step Configuration</b> - Common attributes like type, name, description, and flows
|
|
77
|
-
</li>
|
|
78
|
-
<li>
|
|
79
|
-
<b>API Step Configuration</b> - HTTP method and path attributes
|
|
80
|
-
</li>
|
|
70
|
+
<ul>
|
|
81
71
|
<li>
|
|
82
|
-
<b>
|
|
72
|
+
The <b>type</b> attribute is important since it declares the type of Step
|
|
83
73
|
</li>
|
|
84
74
|
<li>
|
|
85
|
-
<b>
|
|
75
|
+
The <b>flows</b> attribute will associate your Step with a given flow or set of flows.
|
|
86
76
|
</li>
|
|
87
77
|
<li>
|
|
88
|
-
<b>
|
|
89
|
-
|
|
90
|
-
<li>
|
|
91
|
-
<b>Logger</b> - Enhanced logging utilities for observability
|
|
92
|
-
</li>
|
|
93
|
-
<li>
|
|
94
|
-
<b>HTTP Response</b> - Returning responses that match your responseSchema
|
|
78
|
+
The <b>name</b> and <b>description</b> attributes will provide context in the visualization and
|
|
79
|
+
observability tools.
|
|
95
80
|
</li>
|
|
96
81
|
</ul>
|
|
97
|
-
<br />
|
|
98
|
-
<p>Take your time exploring these features. Click <b>Continue</b> when you're ready to move on.</p>
|
|
99
82
|
</div>
|
|
100
83
|
),
|
|
101
|
-
before: [
|
|
84
|
+
before: [
|
|
85
|
+
{ type: 'click', selector: workbenchXPath.flows.previewButton('apitrigger') },
|
|
86
|
+
{ type: 'click', selector: workbenchXPath.flows.feature('step-configuration') },
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
91
|
+
title: 'API Step Configuration',
|
|
92
|
+
description: () => (
|
|
93
|
+
<p>
|
|
94
|
+
There are specific configuration attributes for an API Step. Let's start with the <b>method</b> attribute. This
|
|
95
|
+
will declare the type of HTTP method used to talk to your API Step.
|
|
96
|
+
<br />
|
|
97
|
+
<br />
|
|
98
|
+
Through the <b>path</b> attribute you'll declare the url path used to trigger your API Step
|
|
99
|
+
</p>
|
|
100
|
+
),
|
|
101
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('api-configuration') }],
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
105
|
+
title: 'Request Body',
|
|
106
|
+
link: 'https://zod.dev/api',
|
|
107
|
+
description: () => (
|
|
108
|
+
<p>
|
|
109
|
+
The <b>bodySchema</b> attribute will define the shape of the request body.
|
|
110
|
+
<br />
|
|
111
|
+
<br />
|
|
112
|
+
<i>💡 Both the request body and response payload are defined by zod schemas</i>
|
|
113
|
+
</p>
|
|
114
|
+
),
|
|
115
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('request-body') }],
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
119
|
+
title: 'Response Payload',
|
|
120
|
+
link: 'https://zod.dev/api',
|
|
121
|
+
description: () => (
|
|
122
|
+
<p>
|
|
123
|
+
Through the <b>responseSchema</b> attribute you can declare the different type of http responses based on the
|
|
124
|
+
http status code.
|
|
125
|
+
<br />
|
|
126
|
+
<br />
|
|
127
|
+
<i>💡 Both the request body and response payload are defined by zod schemas</i>
|
|
128
|
+
</p>
|
|
129
|
+
),
|
|
130
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('response-payload') }],
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
134
|
+
title: 'Event Driven Architecture',
|
|
135
|
+
description: () => (
|
|
136
|
+
<p>
|
|
137
|
+
Motia allows you to interact between Steps or flows through an event driven architecture.
|
|
138
|
+
<br />
|
|
139
|
+
<br />
|
|
140
|
+
In order to connect your Steps during runtime you will use the <b>emits</b> and <b>subscribes</b> attributes.
|
|
141
|
+
<br />
|
|
142
|
+
<br />
|
|
143
|
+
Through the <b>emits</b>, you can specify a list of topics that your Step emits for others to <i>subscribe</i>.
|
|
144
|
+
</p>
|
|
145
|
+
),
|
|
146
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('event-driven-architecture') }],
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
150
|
+
title: 'Step Handler',
|
|
151
|
+
description: () => (
|
|
152
|
+
<p>
|
|
153
|
+
Now that we've covered how to declare a Step, let's dive into the <b>Step Handler</b>.<br />
|
|
154
|
+
<br />
|
|
155
|
+
Handlers are essential for the execution of your Step. For API Steps, the handler will receive the request
|
|
156
|
+
object as the first argument, followed by a second argument that provides access to the <b>logger</b>,{' '}
|
|
157
|
+
<b>event emitter</b>, <b>state manager</b>, and <b>trace id</b>.<br />
|
|
158
|
+
<br />
|
|
159
|
+
💡 We will cover these in depth further down the tutorial.
|
|
160
|
+
</p>
|
|
161
|
+
),
|
|
162
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('handler') }],
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
166
|
+
title: 'Logger',
|
|
167
|
+
description: () => (
|
|
168
|
+
<p>
|
|
169
|
+
We recommend using the provided <b>logger</b> util in order to guarantee observability through Motia's
|
|
170
|
+
ecosystem.
|
|
171
|
+
<br />
|
|
172
|
+
<br />
|
|
173
|
+
You can use logger similar to <i>console.log</i> for js or <i>print</i> for python, but with enhanced utilities,
|
|
174
|
+
such as being able to provide additional context.
|
|
175
|
+
<br />
|
|
176
|
+
<br />
|
|
177
|
+
Motia will take care of the rest to provide the best experience to visualize your logs and tie them through
|
|
178
|
+
tracing.
|
|
179
|
+
</p>
|
|
180
|
+
),
|
|
181
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('logger') }],
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
185
|
+
title: 'HTTP Response',
|
|
186
|
+
description: () => (
|
|
187
|
+
<p>
|
|
188
|
+
Now let's wrap our API Step and return a response.
|
|
189
|
+
<br />
|
|
190
|
+
You simply need to return an object that complies with one of the <b>responseSchema</b> definitions declared in
|
|
191
|
+
your Step configuration.
|
|
192
|
+
</p>
|
|
193
|
+
),
|
|
194
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('http-response') }],
|
|
102
195
|
},
|
|
103
196
|
|
|
104
197
|
// Event Steps
|
|
@@ -127,39 +220,77 @@ export const steps: TutorialStep[] = [
|
|
|
127
220
|
},
|
|
128
221
|
{
|
|
129
222
|
elementXpath: workbenchXPath.sidebarContainer,
|
|
130
|
-
title: '
|
|
223
|
+
title: 'Event Step',
|
|
131
224
|
link: 'https://www.motia.dev/docs/concepts/steps#triggers-event',
|
|
132
225
|
description: () => (
|
|
133
|
-
<
|
|
134
|
-
<
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
</
|
|
226
|
+
<p>
|
|
227
|
+
Now that we have an entry point in our flow, let's focus on subscribing to a <b>topic</b> and performing a
|
|
228
|
+
specific task.
|
|
229
|
+
<br /> <br />
|
|
230
|
+
For this we will look at the <b>Event</b> Step.
|
|
231
|
+
<br /> <br />
|
|
232
|
+
<b> Event</b> Steps are essential for Motia's event driven architecture. Let's dive deeper into the anatomy of
|
|
233
|
+
an Event Step by taking a look at the code visualization tool.
|
|
234
|
+
<br /> <br />
|
|
235
|
+
💡 <b>Event</b> Steps can only be triggered internally, through topic subscriptions.
|
|
236
|
+
</p>
|
|
237
|
+
),
|
|
238
|
+
before: [
|
|
239
|
+
{ type: 'click', selector: workbenchXPath.flows.previewButton('processfoodorder') },
|
|
240
|
+
{ type: 'click', selector: workbenchXPath.flows.feature('step-configuration') },
|
|
241
|
+
],
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
245
|
+
title: 'Event Step Input',
|
|
246
|
+
description: () => (
|
|
247
|
+
<p>
|
|
248
|
+
<b>Event</b> Steps, like other Steps types, are composed of a configuration and a handler.
|
|
138
249
|
<br />
|
|
139
|
-
<p>
|
|
140
|
-
<b>Click on the feature cards</b> to learn about:
|
|
141
|
-
</p>
|
|
142
|
-
<ul className="square-decoration">
|
|
143
|
-
<li>
|
|
144
|
-
<b>Step Configuration</b> - Common attributes for Event Steps
|
|
145
|
-
</li>
|
|
146
|
-
<li>
|
|
147
|
-
<b>Input Schema</b> - The data structure provided by the topic (defined as a zod schema)
|
|
148
|
-
</li>
|
|
149
|
-
<li>
|
|
150
|
-
<b>Event Step Handler</b> - The handler receives topic data as the first argument
|
|
151
|
-
</li>
|
|
152
|
-
<li>
|
|
153
|
-
<b>State Management</b> - How to persist data in state with group IDs
|
|
154
|
-
</li>
|
|
155
|
-
</ul>
|
|
156
250
|
<br />
|
|
157
|
-
<
|
|
251
|
+
<b>Event</b> Steps have a specific attribute from their config, the <b>input</b> attribute, which declares the
|
|
252
|
+
data structure provided by the topic it is subscribed to.
|
|
158
253
|
<br />
|
|
159
|
-
<
|
|
160
|
-
|
|
254
|
+
<br />
|
|
255
|
+
The <b>input</b> attributes is defined as a zod schema, think of the <b>input</b> attributes as a contract for
|
|
256
|
+
other Steps that emit the topics that your Step subscribes to.
|
|
257
|
+
<br />
|
|
258
|
+
<br /> 💡 <b>Multiple Steps can subscribe to the same topic, but their input schema must be the same.</b>
|
|
259
|
+
</p>
|
|
260
|
+
),
|
|
261
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('input-schema') }],
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
265
|
+
title: 'Event Step Handler',
|
|
266
|
+
description: () => (
|
|
267
|
+
<p>
|
|
268
|
+
Let's take a look at the <b>Event</b> Step Handler.
|
|
269
|
+
<br />
|
|
270
|
+
<br />
|
|
271
|
+
The handler will seem familiar to other Step handlers, but notice that the first argument holds the data
|
|
272
|
+
provided for the topic or topics your Step subscribes to.
|
|
273
|
+
<br />
|
|
274
|
+
<br />
|
|
275
|
+
💡 The first argument will match the structure of your input schema, defined in the <b>Event</b> Step config.
|
|
276
|
+
</p>
|
|
161
277
|
),
|
|
162
|
-
before: [{ type: 'click', selector: workbenchXPath.flows.
|
|
278
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('handler') }],
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
282
|
+
title: 'Storing Data in State',
|
|
283
|
+
link: 'https://www.motia.dev/docs/development-guide/state-management',
|
|
284
|
+
description: () => (
|
|
285
|
+
<p>
|
|
286
|
+
Let's take a closer look at storing data in state.
|
|
287
|
+
<br />
|
|
288
|
+
<br />
|
|
289
|
+
In this example we are persisting the result of a third party HTTP request in <b>State</b>, scoping it to a
|
|
290
|
+
group id named "orders".
|
|
291
|
+
</p>
|
|
292
|
+
),
|
|
293
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('state') }],
|
|
163
294
|
},
|
|
164
295
|
|
|
165
296
|
// Cron Steps
|
|
@@ -170,46 +301,53 @@ export const steps: TutorialStep[] = [
|
|
|
170
301
|
link: 'https://www.motia.dev/docs/concepts/steps#triggers-cron',
|
|
171
302
|
description: () => (
|
|
172
303
|
<p>
|
|
173
|
-
Let's do a recap of what you've learned
|
|
304
|
+
Let's do a recap of what you've learned, thus far you've become familiar with two Step types <b>API</b>{' '}
|
|
174
305
|
and <b>Event</b> Steps.
|
|
175
306
|
<br />
|
|
176
307
|
<br />
|
|
177
308
|
You've also started to learn how to navigate around Workbench. Let's wrap up Motia's Step types with the last
|
|
178
|
-
one
|
|
309
|
+
one the <b>CRON</b> Step. Let's take a deeper look at its definition.
|
|
179
310
|
</p>
|
|
180
311
|
),
|
|
181
312
|
before: [{ type: 'click', selector: workbenchXPath.closePanelButton }],
|
|
182
313
|
},
|
|
183
314
|
{
|
|
184
315
|
elementXpath: workbenchXPath.sidebarContainer,
|
|
185
|
-
title: '
|
|
316
|
+
title: 'Cron Schedule',
|
|
186
317
|
link: 'https://www.motia.dev/docs/concepts/steps#triggers-cron',
|
|
187
318
|
description: () => (
|
|
188
|
-
<
|
|
189
|
-
<
|
|
190
|
-
<b>CRON</b> Steps are similar to other Step types - they have a configuration and a handler. The key difference
|
|
191
|
-
is the <b>cron</b> attribute that defines the schedule.
|
|
192
|
-
</p>
|
|
319
|
+
<p>
|
|
320
|
+
<b>CRON</b> Steps are similar to the other Step types, they are composed by a configuration and a handler.
|
|
193
321
|
<br />
|
|
194
|
-
<p>
|
|
195
|
-
<b>Click on the feature cards</b> to learn about:
|
|
196
|
-
</p>
|
|
197
|
-
<ul className="square-decoration">
|
|
198
|
-
<li>
|
|
199
|
-
<b>Cron Configuration</b> - How to define the cron schedule (e.g., every 5 minutes)
|
|
200
|
-
</li>
|
|
201
|
-
<li>
|
|
202
|
-
<b>Cron Step Handler</b> - Receives only the Motia context, giving access to emit topics, log, manage state,
|
|
203
|
-
and trace ID
|
|
204
|
-
</li>
|
|
205
|
-
</ul>
|
|
206
322
|
<br />
|
|
207
|
-
<
|
|
323
|
+
The <b>CRON</b> Step config has a distinct attribute, the <b>cron</b> attribute, through this attribute you will
|
|
324
|
+
define the cron schedule for your Step.
|
|
208
325
|
<br />
|
|
209
|
-
<
|
|
210
|
-
|
|
326
|
+
<br />
|
|
327
|
+
For instance, in this example the cron schedule is configured to execute the Step handler every 5 minutes. Let's
|
|
328
|
+
take a look at the handler definition.
|
|
329
|
+
</p>
|
|
330
|
+
),
|
|
331
|
+
before: [
|
|
332
|
+
{ type: 'click', selector: workbenchXPath.flows.previewButton('stateauditjob') },
|
|
333
|
+
{ type: 'click', selector: workbenchXPath.flows.feature('cron-configuration') },
|
|
334
|
+
],
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
338
|
+
title: 'Cron Step Handler',
|
|
339
|
+
description: () => (
|
|
340
|
+
<p>
|
|
341
|
+
The <b>CRON</b> Step handler only receives one argument, which is the Motia context, if you recall the Motia
|
|
342
|
+
context gives you access to utilities to emit <i>topics</i>, <i>log</i>, <i>manage state</i>, and it provides
|
|
343
|
+
the <i>trace id</i> associated to your Step's execution.
|
|
344
|
+
<br />
|
|
345
|
+
<br />
|
|
346
|
+
In this CRON Step example we are evaluating orders persisted in state, and emitting warnings through a topic for
|
|
347
|
+
each order that hasn't been processed and has a shipping date in the past.
|
|
348
|
+
</p>
|
|
211
349
|
),
|
|
212
|
-
before: [{ type: 'click', selector: workbenchXPath.flows.
|
|
350
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('handler') }],
|
|
213
351
|
},
|
|
214
352
|
|
|
215
353
|
// Endpoints
|
|
@@ -44,12 +44,7 @@ export const steps: TutorialStep[] = [
|
|
|
44
44
|
{
|
|
45
45
|
elementXpath: workbenchXPath.flows.previewButton('apitrigger'),
|
|
46
46
|
title: 'Code Preview',
|
|
47
|
-
description: () =>
|
|
48
|
-
<p>
|
|
49
|
-
Clicking on this icon will allow you to visualize the source code for a given Step. This opens a code viewer
|
|
50
|
-
with interactive feature cards that explain different parts of the code.
|
|
51
|
-
</p>
|
|
52
|
-
),
|
|
47
|
+
description: () => <p>Clicking on this icon will allow you to visualize the source code for a given Step.</p>,
|
|
53
48
|
before: [
|
|
54
49
|
{
|
|
55
50
|
type: 'click',
|
|
@@ -60,45 +55,143 @@ export const steps: TutorialStep[] = [
|
|
|
60
55
|
},
|
|
61
56
|
{
|
|
62
57
|
elementXpath: workbenchXPath.sidebarContainer,
|
|
63
|
-
title: '
|
|
58
|
+
title: 'Step Config',
|
|
64
59
|
description: () => (
|
|
65
60
|
<div>
|
|
66
61
|
<p>
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
All Steps are defined by two main components, the <b>configuration</b> and the <b>handler</b>.
|
|
63
|
+
<br />
|
|
64
|
+
<br />
|
|
65
|
+
Let's start with the configuration, the common config attributes are
|
|
66
|
+
<i> type, name, description, and flows</i>.
|
|
67
|
+
<br />
|
|
68
|
+
<br />
|
|
69
69
|
</p>
|
|
70
|
-
<
|
|
71
|
-
<p>
|
|
72
|
-
<b>Click on the feature cards</b> to learn about:
|
|
73
|
-
</p>
|
|
74
|
-
<ul className="square-decoration">
|
|
75
|
-
<li>
|
|
76
|
-
<b>Step Configuration</b> - Common attributes like type, name, description, and flows
|
|
77
|
-
</li>
|
|
78
|
-
<li>
|
|
79
|
-
<b>API Step Configuration</b> - HTTP method and path attributes
|
|
80
|
-
</li>
|
|
70
|
+
<ul>
|
|
81
71
|
<li>
|
|
82
|
-
<b>
|
|
72
|
+
The <b>type</b> attribute is important since it declares the type of Step
|
|
83
73
|
</li>
|
|
84
74
|
<li>
|
|
85
|
-
<b>
|
|
75
|
+
The <b>flows</b> attribute will associate your Step with a given flow or set of flows.
|
|
86
76
|
</li>
|
|
87
77
|
<li>
|
|
88
|
-
<b>
|
|
89
|
-
|
|
90
|
-
<li>
|
|
91
|
-
<b>Logger</b> - Enhanced logging utilities for observability
|
|
92
|
-
</li>
|
|
93
|
-
<li>
|
|
94
|
-
<b>HTTP Response</b> - Returning responses that match your responseSchema
|
|
78
|
+
The <b>name</b> and <b>description</b> attributes will provide context in the visualization and
|
|
79
|
+
observability tools.
|
|
95
80
|
</li>
|
|
96
81
|
</ul>
|
|
97
|
-
<br />
|
|
98
|
-
<p>Take your time exploring these features. Click <b>Continue</b> when you're ready to move on.</p>
|
|
99
82
|
</div>
|
|
100
83
|
),
|
|
101
|
-
before: [
|
|
84
|
+
before: [
|
|
85
|
+
{ type: 'click', selector: workbenchXPath.flows.previewButton('apitrigger') },
|
|
86
|
+
{ type: 'click', selector: workbenchXPath.flows.feature('step-configuration') },
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
91
|
+
title: 'API Step Configuration',
|
|
92
|
+
description: () => (
|
|
93
|
+
<p>
|
|
94
|
+
There are specific configuration attributes for an API Step. Let's start with the <b>method</b> attribute. This
|
|
95
|
+
will declare the type of HTTP method used to talk to your API Step.
|
|
96
|
+
<br />
|
|
97
|
+
<br />
|
|
98
|
+
Through the <b>path</b> attribute you'll declare the url path used to trigger your API Step
|
|
99
|
+
</p>
|
|
100
|
+
),
|
|
101
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('api-configuration') }],
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
105
|
+
title: 'Request Body',
|
|
106
|
+
link: 'https://zod.dev/api',
|
|
107
|
+
description: () => (
|
|
108
|
+
<p>
|
|
109
|
+
The <b>bodySchema</b> attribute will define the shape of the request body.
|
|
110
|
+
<br />
|
|
111
|
+
<br />
|
|
112
|
+
<i>💡 Both the request body and response payload are defined by zod schemas</i>
|
|
113
|
+
</p>
|
|
114
|
+
),
|
|
115
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('request-body') }],
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
119
|
+
title: 'Response Payload',
|
|
120
|
+
link: 'https://zod.dev/api',
|
|
121
|
+
description: () => (
|
|
122
|
+
<p>
|
|
123
|
+
Through the <b>responseSchema</b> attribute you can declare the different type of http responses based on the
|
|
124
|
+
http status code.
|
|
125
|
+
<br />
|
|
126
|
+
<br />
|
|
127
|
+
<i>💡 Both the request body and response payload are defined by zod schemas</i>
|
|
128
|
+
</p>
|
|
129
|
+
),
|
|
130
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('response-payload') }],
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
134
|
+
title: 'Event Driven Architecture',
|
|
135
|
+
description: () => (
|
|
136
|
+
<p>
|
|
137
|
+
Motia allows you to interact between Steps or flows through an event driven architecture.
|
|
138
|
+
<br />
|
|
139
|
+
<br />
|
|
140
|
+
In order to connect your Steps during runtime you will use the <b>emits</b> and <b>subscribes</b> attributes.
|
|
141
|
+
<br />
|
|
142
|
+
<br />
|
|
143
|
+
Through the <b>emits</b>, you can specify a list of topics that your Step emits for others to <i>subscribe</i>.
|
|
144
|
+
</p>
|
|
145
|
+
),
|
|
146
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('event-driven-architecture') }],
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
150
|
+
title: 'Step Handler',
|
|
151
|
+
description: () => (
|
|
152
|
+
<p>
|
|
153
|
+
Now that we've covered how to declare a Step, let's dive into the <b>Step Handler</b>.<br />
|
|
154
|
+
<br />
|
|
155
|
+
Handlers are essential for the execution of your Step. For API Steps, the handler will receive the request
|
|
156
|
+
object as the first argument, followed by a second argument that provides access to the <b>logger</b>,{' '}
|
|
157
|
+
<b>event emitter</b>, <b>state manager</b>, and <b>trace id</b>.<br />
|
|
158
|
+
<br />
|
|
159
|
+
💡 We will cover these in depth further down the tutorial.
|
|
160
|
+
</p>
|
|
161
|
+
),
|
|
162
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('handler') }],
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
166
|
+
title: 'Logger',
|
|
167
|
+
description: () => (
|
|
168
|
+
<p>
|
|
169
|
+
We recommend using the provided <b>logger</b> util in order to guarantee observability through Motia's
|
|
170
|
+
ecosystem.
|
|
171
|
+
<br />
|
|
172
|
+
<br />
|
|
173
|
+
You can use logger similar to <i>console.log</i> for js or <i>print</i> for python, but with enhanced utilities,
|
|
174
|
+
such as being able to provide additional context.
|
|
175
|
+
<br />
|
|
176
|
+
<br />
|
|
177
|
+
Motia will take care of the rest to provide the best experience to visualize your logs and tie them through
|
|
178
|
+
tracing.
|
|
179
|
+
</p>
|
|
180
|
+
),
|
|
181
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('logger') }],
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
185
|
+
title: 'HTTP Response',
|
|
186
|
+
description: () => (
|
|
187
|
+
<p>
|
|
188
|
+
Now let's wrap our API Step and return a response.
|
|
189
|
+
<br />
|
|
190
|
+
You simply need to return an object that complies with one of the <b>responseSchema</b> definitions declared in
|
|
191
|
+
your Step configuration.
|
|
192
|
+
</p>
|
|
193
|
+
),
|
|
194
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('http-response') }],
|
|
102
195
|
},
|
|
103
196
|
|
|
104
197
|
// Event Steps
|
|
@@ -127,39 +220,77 @@ export const steps: TutorialStep[] = [
|
|
|
127
220
|
},
|
|
128
221
|
{
|
|
129
222
|
elementXpath: workbenchXPath.sidebarContainer,
|
|
130
|
-
title: '
|
|
223
|
+
title: 'Event Step',
|
|
131
224
|
link: 'https://www.motia.dev/docs/concepts/steps#triggers-event',
|
|
132
225
|
description: () => (
|
|
133
|
-
<
|
|
134
|
-
<
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
</
|
|
226
|
+
<p>
|
|
227
|
+
Now that we have an entry point in our flow, let's focus on subscribing to a <b>topic</b> and performing a
|
|
228
|
+
specific task.
|
|
229
|
+
<br /> <br />
|
|
230
|
+
For this we will look at the <b>Event</b> Step.
|
|
231
|
+
<br /> <br />
|
|
232
|
+
<b> Event</b> Steps are essential for Motia's event driven architecture. Let's dive deeper into the
|
|
233
|
+
anatomy of an Event Step by taking a look at the code visualization tool.
|
|
234
|
+
<br /> <br />
|
|
235
|
+
💡 <b>Event</b> Steps can only be triggered internally, through topic subscriptions.
|
|
236
|
+
</p>
|
|
237
|
+
),
|
|
238
|
+
before: [
|
|
239
|
+
{ type: 'click', selector: workbenchXPath.flows.previewButton('processfoodorder') },
|
|
240
|
+
{ type: 'click', selector: workbenchXPath.flows.feature('step-configuration') },
|
|
241
|
+
],
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
245
|
+
title: 'Event Step Input',
|
|
246
|
+
description: () => (
|
|
247
|
+
<p>
|
|
248
|
+
<b> Event</b> Steps, like other Step types, are composed of a configuration and a handler.
|
|
138
249
|
<br />
|
|
139
|
-
<p>
|
|
140
|
-
<b>Click on the feature cards</b> to learn about:
|
|
141
|
-
</p>
|
|
142
|
-
<ul className="square-decoration">
|
|
143
|
-
<li>
|
|
144
|
-
<b>Step Configuration</b> - Common attributes for Event Steps
|
|
145
|
-
</li>
|
|
146
|
-
<li>
|
|
147
|
-
<b>Input Schema</b> - The data structure provided by the topic (defined as a zod schema)
|
|
148
|
-
</li>
|
|
149
|
-
<li>
|
|
150
|
-
<b>Event Step Handler</b> - The handler receives topic data as the first argument
|
|
151
|
-
</li>
|
|
152
|
-
<li>
|
|
153
|
-
<b>State Management</b> - How to persist data in state with group IDs
|
|
154
|
-
</li>
|
|
155
|
-
</ul>
|
|
156
250
|
<br />
|
|
157
|
-
<
|
|
251
|
+
<b>Event</b> Steps have a specific attribute from their config, the <b>input</b> attribute, which declares the
|
|
252
|
+
data structure provided by the topic it is subscribed to.
|
|
158
253
|
<br />
|
|
159
|
-
<
|
|
160
|
-
|
|
254
|
+
<br />
|
|
255
|
+
The <b>input</b> attributes is defined as a zod schema, think of the <b>input</b> attributes as a contract for
|
|
256
|
+
other Steps that emit the topics that your Step subscribes to.
|
|
257
|
+
<br />
|
|
258
|
+
<br /> 💡 <b>Multiple Steps can subscribe to the same topic, but their input schema must be the same.</b>
|
|
259
|
+
</p>
|
|
161
260
|
),
|
|
162
|
-
before: [{ type: 'click', selector: workbenchXPath.flows.
|
|
261
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('input-schema') }],
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
265
|
+
title: 'Event Step Handler',
|
|
266
|
+
description: () => (
|
|
267
|
+
<p>
|
|
268
|
+
Let's take a look at the <b>Event</b> Step Handler.
|
|
269
|
+
<br />
|
|
270
|
+
<br />
|
|
271
|
+
The handler will seem familiar to other Step handlers, but notice that the first argument holds the data
|
|
272
|
+
provided for the topic or topics your Step subscribes to.
|
|
273
|
+
<br />
|
|
274
|
+
<br />
|
|
275
|
+
💡 The first argument will match the structure of your input schema, defined in the <b>Event</b> Step config.
|
|
276
|
+
</p>
|
|
277
|
+
),
|
|
278
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('handler') }],
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
282
|
+
title: 'Storing Data in State',
|
|
283
|
+
link: 'https://www.motia.dev/docs/development-guide/state-management',
|
|
284
|
+
description: () => (
|
|
285
|
+
<p>
|
|
286
|
+
Let's take a closer look at storing data in state.
|
|
287
|
+
<br />
|
|
288
|
+
<br />
|
|
289
|
+
In this example we are persisting the result of a third party HTTP request in <b>State</b>, scoping it to a
|
|
290
|
+
group id named "orders".
|
|
291
|
+
</p>
|
|
292
|
+
),
|
|
293
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('state') }],
|
|
163
294
|
},
|
|
164
295
|
|
|
165
296
|
// Cron Steps
|
|
@@ -182,34 +313,41 @@ export const steps: TutorialStep[] = [
|
|
|
182
313
|
},
|
|
183
314
|
{
|
|
184
315
|
elementXpath: workbenchXPath.sidebarContainer,
|
|
185
|
-
title: '
|
|
316
|
+
title: 'Cron Schedule',
|
|
186
317
|
link: 'https://www.motia.dev/docs/concepts/steps#triggers-cron',
|
|
187
318
|
description: () => (
|
|
188
|
-
<
|
|
189
|
-
<
|
|
190
|
-
<b>CRON</b> Steps are similar to other Step types - they have a configuration and a handler. The key difference
|
|
191
|
-
is the <b>cron</b> attribute that defines the schedule.
|
|
192
|
-
</p>
|
|
319
|
+
<p>
|
|
320
|
+
<b>CRON</b> Steps are similar to the other Step types, they are composed by a configuration and a handler.
|
|
193
321
|
<br />
|
|
194
|
-
<p>
|
|
195
|
-
<b>Click on the feature cards</b> to learn about:
|
|
196
|
-
</p>
|
|
197
|
-
<ul className="square-decoration">
|
|
198
|
-
<li>
|
|
199
|
-
<b>Cron Configuration</b> - How to define the cron schedule (e.g., every 5 minutes)
|
|
200
|
-
</li>
|
|
201
|
-
<li>
|
|
202
|
-
<b>Cron Step Handler</b> - Receives only the Motia context, giving access to emit topics, log, manage state,
|
|
203
|
-
and trace ID
|
|
204
|
-
</li>
|
|
205
|
-
</ul>
|
|
206
322
|
<br />
|
|
207
|
-
<
|
|
323
|
+
The <b>CRON</b> Step config has a distinct attribute, the <b>cron</b> attribute, through this attribute you will
|
|
324
|
+
define the cron schedule for your Step.
|
|
208
325
|
<br />
|
|
209
|
-
<
|
|
210
|
-
|
|
326
|
+
<br />
|
|
327
|
+
For instance, in this example the cron schedule is configured to execute the Step handler every 5 minutes. Let's
|
|
328
|
+
take a look at the handler definition.
|
|
329
|
+
</p>
|
|
330
|
+
),
|
|
331
|
+
before: [
|
|
332
|
+
{ type: 'click', selector: workbenchXPath.flows.previewButton('stateauditjob') },
|
|
333
|
+
{ type: 'click', selector: workbenchXPath.flows.feature('cron-configuration') },
|
|
334
|
+
],
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
338
|
+
title: 'Cron Step Handler',
|
|
339
|
+
description: () => (
|
|
340
|
+
<p>
|
|
341
|
+
The <b>CRON</b> Step handler only receives one argument, which is the Motia context, if you recall the Motia
|
|
342
|
+
context gives you access to utilities to emit <i>topics</i>, <i>log</i>, <i>manage state</i>, and it provides
|
|
343
|
+
the <i>trace id</i> associated to your Step's execution.
|
|
344
|
+
<br />
|
|
345
|
+
<br />
|
|
346
|
+
In this CRON Step example we are evaluating orders persisted in state, and emitting warnings through a topic for
|
|
347
|
+
each order that hasn't been processed and has a shipping date in the past.
|
|
348
|
+
</p>
|
|
211
349
|
),
|
|
212
|
-
before: [{ type: 'click', selector: workbenchXPath.flows.
|
|
350
|
+
before: [{ type: 'click', selector: workbenchXPath.flows.feature('handler') }],
|
|
213
351
|
},
|
|
214
352
|
|
|
215
353
|
// Endpoints
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "motia",
|
|
3
3
|
"description": "Build production-grade backends with a single primitive. APIs, background jobs, Queues, Workflows, and AI agents - unified in one system with built-in State management, Streaming, and Observability.",
|
|
4
|
-
"version": "0.17.
|
|
4
|
+
"version": "0.17.5-beta.186",
|
|
5
5
|
"license": "Elastic-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"table": "^6.9.0",
|
|
47
47
|
"ts-node": "^10.9.2",
|
|
48
48
|
"zod": "^4.1.12",
|
|
49
|
-
"@motiadev/adapter-redis-cron": "0.17.
|
|
50
|
-
"@motiadev/adapter-redis-state": "0.17.
|
|
51
|
-
"@motiadev/
|
|
52
|
-
"@motiadev/adapter-redis-streams": "0.17.
|
|
53
|
-
"@motiadev/
|
|
54
|
-
"@motiadev/
|
|
55
|
-
"@motiadev/
|
|
49
|
+
"@motiadev/adapter-redis-cron": "0.17.5-beta.186",
|
|
50
|
+
"@motiadev/adapter-redis-state": "0.17.5-beta.186",
|
|
51
|
+
"@motiadev/core": "0.17.5-beta.186",
|
|
52
|
+
"@motiadev/adapter-redis-streams": "0.17.5-beta.186",
|
|
53
|
+
"@motiadev/stream-client-node": "0.17.5-beta.186",
|
|
54
|
+
"@motiadev/workbench": "0.17.5-beta.186",
|
|
55
|
+
"@motiadev/adapter-bullmq-events": "0.17.5-beta.186"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@amplitude/analytics-types": "^2.9.2",
|