blokctl 0.7.0 → 1.0.0
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/commands/create/project.js +7 -2
- package/dist/commands/create/utils/Examples.d.ts +3 -3
- package/dist/commands/create/utils/Examples.js +68 -9
- package/dist/commands/generate/WorkflowGenerator.js +4 -4
- package/dist/commands/generate/WorkflowGenerator.test.js +2 -2
- package/dist/commands/generate/prompts/create-fn-node.system.js +10 -17
- package/dist/commands/generate/prompts/create-workflow.system.js +114 -375
- package/dist/commands/generate/validators/WorkflowValidator.js +80 -5
- package/dist/commands/generate/validators/WorkflowValidator.test.js +66 -0
- package/package.json +2 -2
|
@@ -9,7 +9,7 @@ What to return:
|
|
|
9
9
|
1. Proper imports:
|
|
10
10
|
* \`z\` from \`zod\`
|
|
11
11
|
* \`Context\` from \`@blokjs/shared\`
|
|
12
|
-
* \`defineNode\` from \`@blokjs/
|
|
12
|
+
* \`defineNode\` from \`@blokjs/core\`
|
|
13
13
|
2. A clear and structured \`input\` schema using Zod (z.object with proper types).
|
|
14
14
|
3. A matching \`output\` schema using Zod.
|
|
15
15
|
4. A single exported node instance created via \`defineNode\` with:
|
|
@@ -26,11 +26,11 @@ Constraints:
|
|
|
26
26
|
* The Zod \`output\` schema must fully describe the object returned by \`execute\`.
|
|
27
27
|
* Inside \`execute(ctx, input)\`:
|
|
28
28
|
* Use the strongly-typed \`input\`, which is automatically inferred from the Zod schema.
|
|
29
|
-
* Use \`ctx\` to access request data, configuration, and
|
|
29
|
+
* Use \`ctx\` to access request data, configuration, and logging when needed:
|
|
30
30
|
* \`ctx.request.body\`, \`ctx.request.query\`, \`ctx.request.params\` for HTTP data
|
|
31
|
-
* \`ctx.vars\` for reading/writing values shared between nodes
|
|
32
31
|
* \`ctx.logger\` for logging
|
|
33
32
|
* \`ctx.env\` for environment variables
|
|
33
|
+
* Do **not** write to \`ctx.state\`/\`ctx.vars\` from a node — just RETURN your output; the runner auto-persists it to \`ctx.state[<step-id>]\` for downstream steps. Upstream values arrive as \`input.*\` (mapped in the workflow), not by reading \`ctx.vars\`.
|
|
34
34
|
* Do **not** construct or return \`BlokResponse\` here; just return a plain object matching the output schema. The wrapper created by \`defineNode\` will call \`setSuccess\` / \`setError\` and handle \`GlobalError\`.
|
|
35
35
|
* On validation errors or runtime errors, you do NOT manually throw \`GlobalError\`; throw/rethrow normal errors. The \`defineNode\` wrapper will catch them and map them to \`GlobalError\` consistently with proper error codes:
|
|
36
36
|
* Zod validation errors → 400 Bad Request
|
|
@@ -52,7 +52,7 @@ Real-World Examples to Guide You:
|
|
|
52
52
|
\`\`\`typescript
|
|
53
53
|
import type { Context } from "@blokjs/shared";
|
|
54
54
|
import { z } from "zod";
|
|
55
|
-
import { defineNode } from "@blokjs/
|
|
55
|
+
import { defineNode } from "@blokjs/core";
|
|
56
56
|
|
|
57
57
|
export default defineNode({
|
|
58
58
|
name: "api-call",
|
|
@@ -102,10 +102,6 @@ export default defineNode({
|
|
|
102
102
|
|
|
103
103
|
ctx.logger.log(\`Request completed in \${duration.toFixed(2)}ms with status \${response.status}\`);
|
|
104
104
|
|
|
105
|
-
if (ctx.vars) {
|
|
106
|
-
ctx.vars["api-response"] = { status: response.status, data };
|
|
107
|
-
}
|
|
108
|
-
|
|
109
105
|
return {
|
|
110
106
|
status: response.status,
|
|
111
107
|
statusText: response.statusText,
|
|
@@ -122,7 +118,7 @@ export default defineNode({
|
|
|
122
118
|
\`\`\`typescript
|
|
123
119
|
import type { Context } from "@blokjs/shared";
|
|
124
120
|
import { z } from "zod";
|
|
125
|
-
import { defineNode } from "@blokjs/
|
|
121
|
+
import { defineNode } from "@blokjs/core";
|
|
126
122
|
|
|
127
123
|
export default defineNode({
|
|
128
124
|
name: "fetch-user",
|
|
@@ -149,11 +145,8 @@ export default defineNode({
|
|
|
149
145
|
// Simulate database fetch
|
|
150
146
|
const user = await fetchUserFromDatabase(input.userId, input.includeMetadata);
|
|
151
147
|
|
|
152
|
-
//
|
|
153
|
-
|
|
154
|
-
ctx.vars["current-user"] = user;
|
|
155
|
-
}
|
|
156
|
-
|
|
148
|
+
// Just return — the runner persists this to ctx.state["fetch-user"]
|
|
149
|
+
// for any downstream step that maps it in as an input.
|
|
157
150
|
return { user };
|
|
158
151
|
},
|
|
159
152
|
});
|
|
@@ -176,7 +169,7 @@ Template to follow (adapt and fill based on the user's request):
|
|
|
176
169
|
|
|
177
170
|
import type { Context } from "@blokjs/shared";
|
|
178
171
|
import { z } from "zod";
|
|
179
|
-
import { defineNode } from "@blokjs/
|
|
172
|
+
import { defineNode } from "@blokjs/core";
|
|
180
173
|
|
|
181
174
|
/**
|
|
182
175
|
* [Brief description of what this node does]
|
|
@@ -210,11 +203,11 @@ export default defineNode({
|
|
|
210
203
|
//
|
|
211
204
|
// Common patterns:
|
|
212
205
|
// - Read HTTP params: const id = ctx.request.params.id;
|
|
213
|
-
// - Read
|
|
214
|
-
// - Write for future nodes: ctx.vars["this-node-key"] = someValue;
|
|
206
|
+
// - Read upstream values via input.* (mapped from prior steps in the workflow) — NOT ctx.vars
|
|
215
207
|
// - Use input.* fields that match the input schema (TypeScript infers the type automatically)
|
|
216
208
|
// - Log messages: ctx.logger.log("Processing request");
|
|
217
209
|
// - Access environment: const apiKey = ctx.env.API_KEY;
|
|
210
|
+
// - Do NOT write ctx.state/ctx.vars here — just return; the runner persists your output.
|
|
218
211
|
|
|
219
212
|
// TODO: Implement business logic here
|
|
220
213
|
|