@elevasis/sdk 0.5.13 → 0.5.15
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/cli.cjs +745 -409
- package/dist/index.d.ts +32 -0
- package/dist/index.js +68 -0
- package/dist/templates.js +254 -37
- package/dist/worker/index.js +3 -7
- package/package.json +1 -1
- package/reference/cli.mdx +568 -505
- package/reference/concepts.mdx +4 -43
- package/reference/deployment/api.mdx +297 -297
- package/reference/deployment/command-center.mdx +9 -12
- package/reference/deployment/index.mdx +7 -7
- package/reference/framework/agent.mdx +6 -18
- package/reference/framework/interaction-guidance.mdx +182 -182
- package/reference/framework/memory.mdx +3 -24
- package/reference/framework/project-structure.mdx +277 -298
- package/reference/framework/tutorial-system.mdx +13 -44
- package/reference/getting-started.mdx +152 -148
- package/reference/index.mdx +28 -14
- package/reference/platform-tools/adapters.mdx +868 -1072
- package/reference/platform-tools/index.mdx +3 -3
- package/reference/resources/index.mdx +339 -341
- package/reference/resources/patterns.mdx +355 -354
- package/reference/resources/types.mdx +207 -207
- package/reference/roadmap.mdx +163 -147
- package/reference/runtime.mdx +2 -25
- package/reference/troubleshooting.mdx +223 -210
|
@@ -1,354 +1,355 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Common Patterns
|
|
3
|
-
description: Common resource patterns for Elevasis SDK developers -- sequential steps, conditional branching, platform tools, error handling, and resource status management
|
|
4
|
-
loadWhen: "Building or modifying a workflow"
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
This page collects the patterns you will reach for most often when writing resources. Each pattern is self-contained and can be adapted directly into your project.
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
## Sequential Workflow Steps
|
|
12
|
-
|
|
13
|
-
The simplest pattern: a chain of steps where each step feeds its output into the next.
|
|
14
|
-
|
|
15
|
-
```typescript
|
|
16
|
-
import { z } from 'zod';
|
|
17
|
-
import { StepType } from '@elevasis/sdk';
|
|
18
|
-
import type { WorkflowDefinition, WorkflowStep } from '@elevasis/sdk';
|
|
19
|
-
|
|
20
|
-
const inputSchema = z.object({ orderId: z.string() });
|
|
21
|
-
const outputSchema = z.object({ shipped: z.boolean(), trackingNumber: z.string() });
|
|
22
|
-
|
|
23
|
-
type Input = z.infer<typeof inputSchema>;
|
|
24
|
-
type Output = z.infer<typeof outputSchema>;
|
|
25
|
-
|
|
26
|
-
const validateStep: WorkflowStep = {
|
|
27
|
-
type: StepType.LINEAR,
|
|
28
|
-
handler: async (input: Input) => {
|
|
29
|
-
const order = await getOrder(input.orderId);
|
|
30
|
-
if (!order) throw new Error(`Order ${input.orderId} not found`);
|
|
31
|
-
return { order };
|
|
32
|
-
},
|
|
33
|
-
next: { target: 'ship' },
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const shipStep: WorkflowStep = {
|
|
37
|
-
type: StepType.LINEAR,
|
|
38
|
-
handler: async (input) => {
|
|
39
|
-
const tracking = await createShipment(input.order);
|
|
40
|
-
return { shipped: true, trackingNumber: tracking.number };
|
|
41
|
-
},
|
|
42
|
-
next: null, // terminal -- no further steps
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const fulfillOrder: WorkflowDefinition = {
|
|
46
|
-
config: {
|
|
47
|
-
contract: {
|
|
48
|
-
steps: { validate: validateStep, ship: shipStep },
|
|
49
|
-
entryPoint: 'validate',
|
|
50
|
-
};
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
**Key points:**
|
|
54
|
-
|
|
55
|
-
- `next: { target: 'stepName' }` routes to the next step
|
|
56
|
-
- `next: null` marks the terminal step
|
|
57
|
-
- Each step receives the full return value of the previous step as its `input`
|
|
58
|
-
- The terminal step's return value must satisfy `contract.output`
|
|
59
|
-
|
|
60
|
-
---
|
|
61
|
-
|
|
62
|
-
## Conditional Branching
|
|
63
|
-
|
|
64
|
-
Use `StepType.CONDITIONAL` when the next step depends on the output of the current step.
|
|
65
|
-
|
|
66
|
-
```typescript
|
|
67
|
-
import { StepType } from '@elevasis/sdk';
|
|
68
|
-
import type { WorkflowStep } from '@elevasis/sdk';
|
|
69
|
-
|
|
70
|
-
const scoreStep: WorkflowStep = {
|
|
71
|
-
type: StepType.CONDITIONAL,
|
|
72
|
-
handler: async (input) => {
|
|
73
|
-
const score = await calculateRiskScore(input.applicationId);
|
|
74
|
-
return { score, applicationId: input.applicationId };
|
|
75
|
-
},
|
|
76
|
-
next: {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
-
|
|
96
|
-
-
|
|
97
|
-
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
import
|
|
108
|
-
import {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
- `
|
|
135
|
-
-
|
|
136
|
-
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
-
|
|
279
|
-
-
|
|
280
|
-
- Will NOT
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
export const
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
export const
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
import
|
|
334
|
-
import * as
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
...
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
...
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
1
|
+
---
|
|
2
|
+
title: Common Patterns
|
|
3
|
+
description: Common resource patterns for Elevasis SDK developers -- sequential steps, conditional branching, platform tools, error handling, and resource status management
|
|
4
|
+
loadWhen: "Building or modifying a workflow"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
This page collects the patterns you will reach for most often when writing resources. Each pattern is self-contained and can be adapted directly into your project.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Sequential Workflow Steps
|
|
12
|
+
|
|
13
|
+
The simplest pattern: a chain of steps where each step feeds its output into the next.
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
import { StepType } from '@elevasis/sdk';
|
|
18
|
+
import type { WorkflowDefinition, WorkflowStep } from '@elevasis/sdk';
|
|
19
|
+
|
|
20
|
+
const inputSchema = z.object({ orderId: z.string() });
|
|
21
|
+
const outputSchema = z.object({ shipped: z.boolean(), trackingNumber: z.string() });
|
|
22
|
+
|
|
23
|
+
type Input = z.infer<typeof inputSchema>;
|
|
24
|
+
type Output = z.infer<typeof outputSchema>;
|
|
25
|
+
|
|
26
|
+
const validateStep: WorkflowStep = {
|
|
27
|
+
type: StepType.LINEAR,
|
|
28
|
+
handler: async (input: Input) => {
|
|
29
|
+
const order = await getOrder(input.orderId);
|
|
30
|
+
if (!order) throw new Error(`Order ${input.orderId} not found`);
|
|
31
|
+
return { order };
|
|
32
|
+
},
|
|
33
|
+
next: { type: 'linear', target: 'ship' },
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const shipStep: WorkflowStep = {
|
|
37
|
+
type: StepType.LINEAR,
|
|
38
|
+
handler: async (input) => {
|
|
39
|
+
const tracking = await createShipment(input.order);
|
|
40
|
+
return { shipped: true, trackingNumber: tracking.number };
|
|
41
|
+
},
|
|
42
|
+
next: null, // terminal -- no further steps
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const fulfillOrder: WorkflowDefinition = {
|
|
46
|
+
config: { resourceId: 'fulfill-order', name: 'Fulfill Order', type: 'workflow', description: 'Validates and ships an order', version: '1.0.0', status: 'dev' },
|
|
47
|
+
contract: { inputSchema, outputSchema },
|
|
48
|
+
steps: { validate: validateStep, ship: shipStep },
|
|
49
|
+
entryPoint: 'validate',
|
|
50
|
+
};
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Key points:**
|
|
54
|
+
|
|
55
|
+
- `next: { target: 'stepName' }` routes to the next step
|
|
56
|
+
- `next: null` marks the terminal step
|
|
57
|
+
- Each step receives the full return value of the previous step as its `input`
|
|
58
|
+
- The terminal step's return value must satisfy `contract.output`
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Conditional Branching
|
|
63
|
+
|
|
64
|
+
Use `StepType.CONDITIONAL` when the next step depends on the output of the current step.
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { StepType } from '@elevasis/sdk';
|
|
68
|
+
import type { WorkflowStep } from '@elevasis/sdk';
|
|
69
|
+
|
|
70
|
+
const scoreStep: WorkflowStep = {
|
|
71
|
+
type: StepType.CONDITIONAL,
|
|
72
|
+
handler: async (input) => {
|
|
73
|
+
const score = await calculateRiskScore(input.applicationId);
|
|
74
|
+
return { score, applicationId: input.applicationId };
|
|
75
|
+
},
|
|
76
|
+
next: {
|
|
77
|
+
type: 'conditional',
|
|
78
|
+
routes: [
|
|
79
|
+
{
|
|
80
|
+
condition: (output) => output.score \>= 80,
|
|
81
|
+
target: 'autoApprove',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
condition: (output) => output.score \>= 40,
|
|
85
|
+
target: 'manualReview',
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
default: 'autoReject', // used when no condition matches
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Key points:**
|
|
94
|
+
|
|
95
|
+
- Routes are evaluated in order -- the first matching condition wins
|
|
96
|
+
- `default` is required and acts as the `else` branch
|
|
97
|
+
- The condition function receives the full handler output
|
|
98
|
+
- All route targets and `default` must be keys in your `steps` record
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Using Platform Tools in Steps
|
|
103
|
+
|
|
104
|
+
Platform tools let your steps call integrations managed by Elevasis (email, CRM, databases, etc.). Import `platform` from `@elevasis/sdk/worker` and call it with the tool name, method, parameters, and a credential reference.
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { platform, PlatformToolError } from '@elevasis/sdk/worker';
|
|
108
|
+
import type { WorkflowStep } from '@elevasis/sdk';
|
|
109
|
+
import { StepType } from '@elevasis/sdk';
|
|
110
|
+
|
|
111
|
+
const sendEmailStep: WorkflowStep = {
|
|
112
|
+
type: StepType.LINEAR,
|
|
113
|
+
handler: async (input, context) => {
|
|
114
|
+
const result = await platform.call({
|
|
115
|
+
tool: 'email',
|
|
116
|
+
method: 'send',
|
|
117
|
+
params: {
|
|
118
|
+
to: input.recipientEmail,
|
|
119
|
+
subject: input.subject,
|
|
120
|
+
body: input.body,
|
|
121
|
+
},
|
|
122
|
+
credential: 'sendgrid', // name of the stored credential
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
context.logger.info('Email sent', { messageId: result.messageId });
|
|
126
|
+
return { sent: true, messageId: result.messageId };
|
|
127
|
+
},
|
|
128
|
+
next: null,
|
|
129
|
+
};
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Key points:**
|
|
133
|
+
|
|
134
|
+
- `platform.call()` is async and times out after 60 seconds
|
|
135
|
+
- `credential` is the name of a platform environment variable set via `elevasis-sdk env set`
|
|
136
|
+
- On failure, `platform.call()` throws `PlatformToolError` (not `ToolingError`)
|
|
137
|
+
- Always log success so executions are easy to debug in the dashboard
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Error Handling
|
|
142
|
+
|
|
143
|
+
### Catching Tool Errors
|
|
144
|
+
|
|
145
|
+
Use `PlatformToolError` (from `@elevasis/sdk/worker`) to handle tool-specific failures without catching everything:
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
import { platform, PlatformToolError } from '@elevasis/sdk/worker';
|
|
149
|
+
|
|
150
|
+
const step = async (input) => {
|
|
151
|
+
try {
|
|
152
|
+
const result = await platform.call({
|
|
153
|
+
tool: 'crm',
|
|
154
|
+
method: 'createContact',
|
|
155
|
+
params: { email: input.email, name: input.name },
|
|
156
|
+
credential: 'CRM_API_KEY',
|
|
157
|
+
});
|
|
158
|
+
return { contactId: result.id };
|
|
159
|
+
} catch (err) {
|
|
160
|
+
if (err instanceof PlatformToolError) {
|
|
161
|
+
// Tool failed -- log it and return a degraded result
|
|
162
|
+
console.error('CRM tool failed:', err.message);
|
|
163
|
+
return { contactId: null, error: err.message };
|
|
164
|
+
}
|
|
165
|
+
throw err; // re-throw unexpected errors
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Failing an Execution Explicitly
|
|
171
|
+
|
|
172
|
+
Use `ExecutionError` when your step detects a condition that should mark the entire execution as failed:
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import { ExecutionError } from '@elevasis/sdk';
|
|
176
|
+
|
|
177
|
+
const validateStep = async (input) => {
|
|
178
|
+
if (!input.userId) {
|
|
179
|
+
throw new ExecutionError('userId is required', { code: 'MISSING_INPUT' });
|
|
180
|
+
}
|
|
181
|
+
if (input.amount \<= 0) {
|
|
182
|
+
throw new ExecutionError('amount must be positive', { code: 'INVALID_AMOUNT' });
|
|
183
|
+
}
|
|
184
|
+
return { valid: true };
|
|
185
|
+
};
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
`ExecutionError` messages and metadata appear in the Elevasis dashboard under the failed execution's detail view.
|
|
189
|
+
|
|
190
|
+
### Using ToolingError
|
|
191
|
+
|
|
192
|
+
`ToolingError` is thrown by lower-level platform operations (not `platform.call()` directly). You may encounter it in advanced scenarios:
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
import { ToolingError } from '@elevasis/sdk';
|
|
196
|
+
|
|
197
|
+
const step = async (input) => {
|
|
198
|
+
try {
|
|
199
|
+
return await doSomething(input);
|
|
200
|
+
} catch (err) {
|
|
201
|
+
if (err instanceof ToolingError) {
|
|
202
|
+
// check err.type for the error category
|
|
203
|
+
console.error('Tooling error:', err.type, err.message);
|
|
204
|
+
}
|
|
205
|
+
throw err;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## Logging in Steps
|
|
213
|
+
|
|
214
|
+
The `context.logger` writes structured logs attached to the execution. Use it instead of `console.log` so logs appear in the dashboard alongside the execution record.
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
import type { StepHandler } from '@elevasis/sdk';
|
|
218
|
+
|
|
219
|
+
const processStep: StepHandler = async (input, context) => {
|
|
220
|
+
context.logger.info('Starting process', { userId: input.userId });
|
|
221
|
+
|
|
222
|
+
const result = await doWork(input);
|
|
223
|
+
|
|
224
|
+
context.logger.info('Process complete', { resultId: result.id });
|
|
225
|
+
return result;
|
|
226
|
+
};
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Avoid logging sensitive values (API keys, passwords, PII) since logs are stored and visible in the dashboard.
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Using the Execution Store
|
|
234
|
+
|
|
235
|
+
`context.store` is a simple key-value store scoped to the current execution. Use it to pass data between steps without coupling step interfaces, or to checkpoint long-running work.
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
const firstStep: StepHandler = async (input, context) => {
|
|
239
|
+
const data = await fetchExpensiveData(input.id);
|
|
240
|
+
|
|
241
|
+
// Save for use by later steps
|
|
242
|
+
await context.store.set('fetchedData', JSON.stringify(data));
|
|
243
|
+
|
|
244
|
+
return { fetched: true };
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const secondStep: StepHandler = async (input, context) => {
|
|
248
|
+
const raw = await context.store.get('fetchedData');
|
|
249
|
+
const data = JSON.parse(raw ?? '{}');
|
|
250
|
+
|
|
251
|
+
return { processed: transform(data) };
|
|
252
|
+
};
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Store values are strings. Serialize objects with `JSON.stringify` and parse with `JSON.parse`.
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Resource Status
|
|
260
|
+
|
|
261
|
+
### Dev vs Production
|
|
262
|
+
|
|
263
|
+
While building a resource, set `config.status` to `'dev'`:
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
const myWorkflow: WorkflowDefinition = {
|
|
267
|
+
config: {
|
|
268
|
+
name: 'my-workflow',
|
|
269
|
+
description: 'Does something useful',
|
|
270
|
+
status: 'dev', // only manually triggerable
|
|
271
|
+
},
|
|
272
|
+
// ...
|
|
273
|
+
};
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Dev resources:
|
|
277
|
+
|
|
278
|
+
- Appear in `elevasis-sdk resources` output
|
|
279
|
+
- Can be triggered with `elevasis-sdk exec my-workflow --input '{...}'`
|
|
280
|
+
- Will NOT receive scheduled or webhook-triggered executions
|
|
281
|
+
- Will NOT appear as available to external callers
|
|
282
|
+
|
|
283
|
+
When you are ready to go live, change to `'prod'` and redeploy:
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
config: {
|
|
287
|
+
name: 'my-workflow',
|
|
288
|
+
description: 'Does something useful',
|
|
289
|
+
status: 'prod', // receives all execution sources
|
|
290
|
+
},
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Global Default Status
|
|
294
|
+
|
|
295
|
+
Set a project-wide default in `elevasis.config.ts` to keep all resources in `'dev'` mode during development without touching each resource file:
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
import type { ElevasConfig } from '@elevasis/sdk';
|
|
299
|
+
|
|
300
|
+
const config: ElevasConfig = {
|
|
301
|
+
defaultStatus: 'dev',
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
export default config;
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Individual resources that set their own `config.status` override this default.
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
## Organizing Multiple Resources
|
|
312
|
+
|
|
313
|
+
As your project grows, organize resources by business domain. Each domain gets its own directory with an `index.ts` barrel that exports `workflows` and `agents` arrays:
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
// src/orders/fulfill-order.ts
|
|
317
|
+
export const fulfillOrder: WorkflowDefinition = { ... };
|
|
318
|
+
|
|
319
|
+
// src/billing/send-invoice.ts
|
|
320
|
+
export const sendInvoice: WorkflowDefinition = { ... };
|
|
321
|
+
|
|
322
|
+
// src/orders/index.ts
|
|
323
|
+
import { fulfillOrder } from './fulfill-order.js';
|
|
324
|
+
export const workflows = [fulfillOrder];
|
|
325
|
+
export const agents = [];
|
|
326
|
+
|
|
327
|
+
// src/billing/index.ts
|
|
328
|
+
import { sendInvoice } from './send-invoice.js';
|
|
329
|
+
export const workflows = [sendInvoice];
|
|
330
|
+
export const agents = [];
|
|
331
|
+
|
|
332
|
+
// src/index.ts
|
|
333
|
+
import type { OrganizationResources } from '@elevasis/sdk';
|
|
334
|
+
import * as orders from './orders/index.js';
|
|
335
|
+
import * as billing from './billing/index.js';
|
|
336
|
+
|
|
337
|
+
const org: OrganizationResources = {
|
|
338
|
+
workflows: [
|
|
339
|
+
...orders.workflows,
|
|
340
|
+
...billing.workflows,
|
|
341
|
+
],
|
|
342
|
+
agents: [
|
|
343
|
+
...orders.agents,
|
|
344
|
+
...billing.agents,
|
|
345
|
+
],
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
export default org;
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
The keys in `workflows` and `agents` are the resource identifiers used in CLI commands and the dashboard. Choose names that are descriptive and use kebab-case for consistency.
|
|
352
|
+
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
**Last Updated:** 2026-02-25
|