blokctl 0.2.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.
Files changed (169) hide show
  1. package/dist/commands/build/index.d.ts +2 -0
  2. package/dist/commands/build/index.js +210 -0
  3. package/dist/commands/config/index.d.ts +1 -0
  4. package/dist/commands/config/index.js +46 -0
  5. package/dist/commands/cost/index.d.ts +1 -0
  6. package/dist/commands/cost/index.js +74 -0
  7. package/dist/commands/create/node.d.ts +2 -0
  8. package/dist/commands/create/node.js +541 -0
  9. package/dist/commands/create/project.d.ts +2 -0
  10. package/dist/commands/create/project.js +941 -0
  11. package/dist/commands/create/utils/Examples.d.ts +39 -0
  12. package/dist/commands/create/utils/Examples.js +983 -0
  13. package/dist/commands/create/workflow.d.ts +2 -0
  14. package/dist/commands/create/workflow.js +109 -0
  15. package/dist/commands/deploy/index.d.ts +2 -0
  16. package/dist/commands/deploy/index.js +176 -0
  17. package/dist/commands/dev/index.d.ts +2 -0
  18. package/dist/commands/dev/index.js +190 -0
  19. package/dist/commands/generate/GenerationAnalytics.d.ts +61 -0
  20. package/dist/commands/generate/GenerationAnalytics.js +162 -0
  21. package/dist/commands/generate/GenerationAnalytics.test.d.ts +1 -0
  22. package/dist/commands/generate/GenerationAnalytics.test.js +407 -0
  23. package/dist/commands/generate/NodeFileWriter.d.ts +5 -0
  24. package/dist/commands/generate/NodeFileWriter.js +240 -0
  25. package/dist/commands/generate/NodeGenerator.d.ts +20 -0
  26. package/dist/commands/generate/NodeGenerator.js +181 -0
  27. package/dist/commands/generate/NodeGenerator.test.d.ts +1 -0
  28. package/dist/commands/generate/NodeGenerator.test.js +101 -0
  29. package/dist/commands/generate/PromptVersioning.d.ts +25 -0
  30. package/dist/commands/generate/PromptVersioning.js +71 -0
  31. package/dist/commands/generate/PromptVersioning.test.d.ts +1 -0
  32. package/dist/commands/generate/PromptVersioning.test.js +120 -0
  33. package/dist/commands/generate/RegisterNode.d.ts +3 -0
  34. package/dist/commands/generate/RegisterNode.js +37 -0
  35. package/dist/commands/generate/RuntimeGenerator.d.ts +40 -0
  36. package/dist/commands/generate/RuntimeGenerator.js +369 -0
  37. package/dist/commands/generate/RuntimeGenerator.test.d.ts +1 -0
  38. package/dist/commands/generate/RuntimeGenerator.test.js +553 -0
  39. package/dist/commands/generate/TriggerGenerator.d.ts +22 -0
  40. package/dist/commands/generate/TriggerGenerator.js +220 -0
  41. package/dist/commands/generate/TriggerGenerator.test.d.ts +1 -0
  42. package/dist/commands/generate/TriggerGenerator.test.js +209 -0
  43. package/dist/commands/generate/WorkflowGenerator.d.ts +20 -0
  44. package/dist/commands/generate/WorkflowGenerator.js +131 -0
  45. package/dist/commands/generate/WorkflowGenerator.test.d.ts +1 -0
  46. package/dist/commands/generate/WorkflowGenerator.test.js +77 -0
  47. package/dist/commands/generate/e2e/NodeGenerator.e2e.test.d.ts +1 -0
  48. package/dist/commands/generate/e2e/NodeGenerator.e2e.test.js +216 -0
  49. package/dist/commands/generate/e2e/RuntimeGenerator.e2e.test.d.ts +1 -0
  50. package/dist/commands/generate/e2e/RuntimeGenerator.e2e.test.js +759 -0
  51. package/dist/commands/generate/e2e/TriggerGenerator.e2e.test.d.ts +1 -0
  52. package/dist/commands/generate/e2e/TriggerGenerator.e2e.test.js +295 -0
  53. package/dist/commands/generate/e2e/WorkflowGenerator.e2e.test.d.ts +1 -0
  54. package/dist/commands/generate/e2e/WorkflowGenerator.e2e.test.js +353 -0
  55. package/dist/commands/generate/index.d.ts +1 -0
  56. package/dist/commands/generate/index.js +418 -0
  57. package/dist/commands/generate/prompts/create-fn-node.system.d.ts +5 -0
  58. package/dist/commands/generate/prompts/create-fn-node.system.js +256 -0
  59. package/dist/commands/generate/prompts/create-node-manifest.system.d.ts +4 -0
  60. package/dist/commands/generate/prompts/create-node-manifest.system.js +41 -0
  61. package/dist/commands/generate/prompts/create-node.system.d.ts +5 -0
  62. package/dist/commands/generate/prompts/create-node.system.js +114 -0
  63. package/dist/commands/generate/prompts/create-readme.system.d.ts +4 -0
  64. package/dist/commands/generate/prompts/create-readme.system.js +83 -0
  65. package/dist/commands/generate/prompts/create-runtime.system.d.ts +5 -0
  66. package/dist/commands/generate/prompts/create-runtime.system.js +284 -0
  67. package/dist/commands/generate/prompts/create-trigger.system.d.ts +5 -0
  68. package/dist/commands/generate/prompts/create-trigger.system.js +293 -0
  69. package/dist/commands/generate/prompts/create-workflow.system.d.ts +5 -0
  70. package/dist/commands/generate/prompts/create-workflow.system.js +476 -0
  71. package/dist/commands/generate/prompts/register-node.system.d.ts +4 -0
  72. package/dist/commands/generate/prompts/register-node.system.js +26 -0
  73. package/dist/commands/generate/validators/CompilationValidator.d.ts +9 -0
  74. package/dist/commands/generate/validators/CompilationValidator.js +86 -0
  75. package/dist/commands/generate/validators/CompilationValidator.test.d.ts +1 -0
  76. package/dist/commands/generate/validators/CompilationValidator.test.js +161 -0
  77. package/dist/commands/generate/validators/NodeValidator.d.ts +18 -0
  78. package/dist/commands/generate/validators/NodeValidator.js +217 -0
  79. package/dist/commands/generate/validators/NodeValidator.test.d.ts +1 -0
  80. package/dist/commands/generate/validators/NodeValidator.test.js +281 -0
  81. package/dist/commands/generate/validators/WorkflowValidator.d.ts +6 -0
  82. package/dist/commands/generate/validators/WorkflowValidator.js +301 -0
  83. package/dist/commands/generate/validators/WorkflowValidator.test.d.ts +1 -0
  84. package/dist/commands/generate/validators/WorkflowValidator.test.js +647 -0
  85. package/dist/commands/generate/validators/index.d.ts +4 -0
  86. package/dist/commands/generate/validators/index.js +2 -0
  87. package/dist/commands/graph/index.d.ts +1 -0
  88. package/dist/commands/graph/index.js +69 -0
  89. package/dist/commands/install/index.d.ts +1 -0
  90. package/dist/commands/install/index.js +4 -0
  91. package/dist/commands/install/node.d.ts +4 -0
  92. package/dist/commands/install/node.js +136 -0
  93. package/dist/commands/install/workflow.d.ts +4 -0
  94. package/dist/commands/install/workflow.js +62 -0
  95. package/dist/commands/login/index.d.ts +2 -0
  96. package/dist/commands/login/index.js +77 -0
  97. package/dist/commands/logout/index.d.ts +2 -0
  98. package/dist/commands/logout/index.js +20 -0
  99. package/dist/commands/marketplace/runtime.d.ts +54 -0
  100. package/dist/commands/marketplace/runtime.js +350 -0
  101. package/dist/commands/migrate/index.d.ts +1 -0
  102. package/dist/commands/migrate/index.js +14 -0
  103. package/dist/commands/migrate/node.d.ts +2 -0
  104. package/dist/commands/migrate/node.js +110 -0
  105. package/dist/commands/monitor/index.d.ts +1 -0
  106. package/dist/commands/monitor/index.js +28 -0
  107. package/dist/commands/monitor/monitor-component.d.ts +1 -0
  108. package/dist/commands/monitor/monitor-component.js +271 -0
  109. package/dist/commands/monitor/static/index.html +2124 -0
  110. package/dist/commands/monitor/static-web-server.d.ts +1 -0
  111. package/dist/commands/monitor/static-web-server.js +89 -0
  112. package/dist/commands/profile/index.d.ts +1 -0
  113. package/dist/commands/profile/index.js +112 -0
  114. package/dist/commands/publish/index.d.ts +1 -0
  115. package/dist/commands/publish/index.js +4 -0
  116. package/dist/commands/publish/node.d.ts +4 -0
  117. package/dist/commands/publish/node.js +231 -0
  118. package/dist/commands/publish/workflow.d.ts +4 -0
  119. package/dist/commands/publish/workflow.js +165 -0
  120. package/dist/commands/search/docs.d.ts +17 -0
  121. package/dist/commands/search/docs.js +179 -0
  122. package/dist/commands/search/index.d.ts +1 -0
  123. package/dist/commands/search/index.js +5 -0
  124. package/dist/commands/search/indexer.d.ts +10 -0
  125. package/dist/commands/search/indexer.js +265 -0
  126. package/dist/commands/search/nodes.d.ts +4 -0
  127. package/dist/commands/search/nodes.js +101 -0
  128. package/dist/commands/search/workflow.d.ts +4 -0
  129. package/dist/commands/search/workflow.js +100 -0
  130. package/dist/commands/trace/index.d.ts +1 -0
  131. package/dist/commands/trace/index.js +26 -0
  132. package/dist/commands/trace/startStudio.d.ts +8 -0
  133. package/dist/commands/trace/startStudio.js +116 -0
  134. package/dist/index.d.ts +17 -0
  135. package/dist/index.js +186 -0
  136. package/dist/services/commander.d.ts +9 -0
  137. package/dist/services/commander.js +20 -0
  138. package/dist/services/constants.d.ts +1 -0
  139. package/dist/services/constants.js +3 -0
  140. package/dist/services/local-token-manager.d.ts +14 -0
  141. package/dist/services/local-token-manager.js +99 -0
  142. package/dist/services/non-interactive.d.ts +5 -0
  143. package/dist/services/non-interactive.js +30 -0
  144. package/dist/services/package-manager.d.ts +35 -0
  145. package/dist/services/package-manager.js +111 -0
  146. package/dist/services/posthog.d.ts +31 -0
  147. package/dist/services/posthog.js +159 -0
  148. package/dist/services/registry-manager.d.ts +9 -0
  149. package/dist/services/registry-manager.js +26 -0
  150. package/dist/services/runtime-detector.d.ts +23 -0
  151. package/dist/services/runtime-detector.js +181 -0
  152. package/dist/services/runtime-setup.d.ts +36 -0
  153. package/dist/services/runtime-setup.js +250 -0
  154. package/dist/services/utils.d.ts +2 -0
  155. package/dist/services/utils.js +29 -0
  156. package/dist/services/workflow-loader.d.ts +30 -0
  157. package/dist/services/workflow-loader.js +46 -0
  158. package/dist/studio-dist/assets/charts-Dso0hPUR.js +68 -0
  159. package/dist/studio-dist/assets/graph-CsV2nWGn.js +23 -0
  160. package/dist/studio-dist/assets/icons-zP8LLgPh.js +311 -0
  161. package/dist/studio-dist/assets/index-CLyEkXMx.css +1 -0
  162. package/dist/studio-dist/assets/index-CNXFX_ar.js +27 -0
  163. package/dist/studio-dist/assets/react-vendor--Eh9ivFN.js +17 -0
  164. package/dist/studio-dist/assets/tanstack-query-CiM1U6F5.js +1 -0
  165. package/dist/studio-dist/assets/tanstack-router-Btjy0MKq.js +25 -0
  166. package/dist/studio-dist/assets/tanstack-table-DhwRvuH2.js +22 -0
  167. package/dist/studio-dist/favicon.svg +5 -0
  168. package/dist/studio-dist/index.html +21 -0
  169. package/package.json +75 -0
@@ -0,0 +1,293 @@
1
+ const createTriggerSystemPrompt = {
2
+ prompt: `You are a senior TypeScript backend engineer working on the Blok (blok) workflow framework. Your task is to generate a fully working **Trigger implementation** that listens for external events and executes workflows.
3
+
4
+ What to return:
5
+
6
+ * Return only a complete TypeScript file containing a trigger class, ready to be saved directly into \`triggers/<trigger-name>/src/<TriggerName>Trigger.ts\`.
7
+ * It must include:
8
+
9
+ 1. Proper imports from \`@blok/runner\` and \`@blok/shared\`
10
+ 2. A trigger class that extends \`TriggerBase\`
11
+ 3. \`loadNodes()\` and \`loadWorkflows()\` methods
12
+ 4. A main start method (e.g., \`listen()\`, \`startConsumer()\`, \`start()\`)
13
+ 5. Context creation using \`this.createContext()\`
14
+ 6. Proper \`ctx.request\` population from incoming events
15
+ 7. Workflow execution through the runner
16
+
17
+ ## Core Architecture
18
+
19
+ All triggers MUST follow this pattern:
20
+
21
+ 1. **Extend TriggerBase** from \`@blok/runner\`
22
+ 2. **Load nodes and workflows** in constructor
23
+ 3. **Listen for external events** (HTTP, queue messages, cron, webhooks, etc.)
24
+ 4. **For each event:**
25
+ - Select matching workflow(s) based on trigger config
26
+ - Create Context via \`this.createContext()\`
27
+ - Populate \`ctx.request\` with event data
28
+ - Execute the workflow through the runner
29
+ - Map \`ctx.response\` back to the external system
30
+
31
+ ## TriggerBase API
32
+
33
+ \`\`\`typescript
34
+ // Inherited from TriggerBase
35
+ class TriggerBase {
36
+ protected configuration: Configuration;
37
+
38
+ // Create a fresh Context for each workflow execution
39
+ createContext(logger?: LoggerContext, blueprintPath?: string, id?: string): Context;
40
+
41
+ // Access workflow and node maps
42
+ get nodeMap(): GlobalOptions;
43
+ }
44
+ \`\`\`
45
+
46
+ ## Context Structure
47
+
48
+ \`\`\`typescript
49
+ interface Context {
50
+ id: string; // Unique request ID
51
+ workflow_name: string; // Workflow name
52
+ workflow_path: string; // Workflow blueprint path
53
+ config: Record<string, any>; // Node configurations
54
+ request: { // Populated by trigger
55
+ body: any;
56
+ headers?: Record<string, string>;
57
+ query?: Record<string, string>;
58
+ params?: Record<string, string>;
59
+ method?: string;
60
+ };
61
+ response: {
62
+ data: any;
63
+ contentType: string;
64
+ success: boolean;
65
+ error: any;
66
+ };
67
+ error: { message: string[] };
68
+ logger: LoggerContext;
69
+ env: NodeJS.ProcessEnv; // process.env access
70
+ vars: Record<string, any>; // Cross-node data sharing
71
+ }
72
+ \`\`\`
73
+
74
+ ## Workflow Trigger Config Extraction Pattern
75
+
76
+ All triggers MUST use this pattern to read workflow trigger config:
77
+
78
+ \`\`\`typescript
79
+ for (const workflowModel of this.nodeMap.workflows) {
80
+ const triggerKeys = Object.keys(workflowModel.trigger);
81
+ const triggerName = triggerKeys[0]; // e.g., "queue", "cron", "webhook"
82
+
83
+ if (triggerName !== "<your-trigger-type>") continue;
84
+
85
+ const triggerConfig = workflowModel.trigger[triggerName];
86
+ // Use triggerConfig to match and configure this event handler
87
+ }
88
+ \`\`\`
89
+
90
+ ## Available Trigger Types and Their Config
91
+
92
+ ### Queue Trigger
93
+ \`\`\`typescript
94
+ // Workflow config: { "queue": { provider, topic, consumerGroup, ack, batchSize, concurrency } }
95
+ class QueueTrigger extends TriggerBase {
96
+ async startConsumer() {
97
+ // Connect to queue broker
98
+ // Subscribe to messages
99
+ // For each message: createContext, populate ctx.request.body, execute workflow, ack/nack
100
+ }
101
+ }
102
+ \`\`\`
103
+
104
+ ### Pub/Sub Trigger
105
+ \`\`\`typescript
106
+ // Workflow config: { "pubsub": { provider, topic, subscription, ack, maxMessages } }
107
+ class PubSubTrigger extends TriggerBase {
108
+ async startSubscriber() {
109
+ // Connect to pub/sub provider
110
+ // Subscribe to topic
111
+ // For each message: createContext, populate ctx.request.body, execute workflow, ack/nack
112
+ }
113
+ }
114
+ \`\`\`
115
+
116
+ ### Cron Trigger
117
+ \`\`\`typescript
118
+ // Workflow config: { "cron": { schedule, timezone, overlap } }
119
+ class CronTrigger extends TriggerBase {
120
+ async startScheduler() {
121
+ // Parse cron expressions from workflows
122
+ // Schedule jobs using cron library
123
+ // For each tick: createContext, populate ctx.request.body with schedule info, execute workflow
124
+ }
125
+ }
126
+ \`\`\`
127
+
128
+ ### Webhook Trigger
129
+ \`\`\`typescript
130
+ // Workflow config: { "webhook": { source, events, secret, path } }
131
+ class WebhookTrigger extends TriggerBase {
132
+ async listen() {
133
+ // Start HTTP server with webhook endpoints
134
+ // Verify signatures (GitHub HMAC-SHA256, Stripe timestamp+v1, Shopify HMAC)
135
+ // Filter events against workflow config
136
+ // createContext, populate ctx.request with webhook data, execute workflow
137
+ }
138
+ }
139
+ \`\`\`
140
+
141
+ ### WebSocket Trigger
142
+ \`\`\`typescript
143
+ // Workflow config: { "websocket": { events, rooms, path, maxConnections, heartbeatInterval } }
144
+ class WebSocketTrigger extends TriggerBase {
145
+ async listen() {
146
+ // Start WebSocket server
147
+ // Manage connections, rooms, authentication
148
+ // For each message: createContext, populate ctx.request, execute workflow, send response
149
+ }
150
+ }
151
+ \`\`\`
152
+
153
+ ### SSE Trigger
154
+ \`\`\`typescript
155
+ // Workflow config: { "sse": { events, channels, path, heartbeatInterval, retryInterval } }
156
+ class SSETrigger extends TriggerBase {
157
+ async listen() {
158
+ // Start HTTP server with SSE endpoints
159
+ // Manage client connections and channels
160
+ // Provide publish API for sending events to subscribed clients
161
+ }
162
+ }
163
+ \`\`\`
164
+
165
+ ## Real-World Example: Custom Queue Trigger
166
+
167
+ \`\`\`typescript
168
+ import { trace } from "@opentelemetry/api";
169
+ import { TriggerBase, type GlobalOptions, NodeMap, Runner } from "@blok/runner";
170
+ import { type Context, DefaultLogger } from "@blok/shared";
171
+ import nodes from "../Nodes.js";
172
+ import workflows from "../workflows/index.js";
173
+
174
+ export default class CustomQueueTrigger extends TriggerBase {
175
+ private nodeMap: GlobalOptions = <GlobalOptions>{};
176
+ protected tracer = trace.getTracer(
177
+ process.env.PROJECT_NAME || "trigger-queue",
178
+ process.env.PROJECT_VERSION || "0.0.1",
179
+ );
180
+ private logger = new DefaultLogger();
181
+
182
+ constructor() {
183
+ super();
184
+ this.loadNodes();
185
+ this.loadWorkflows();
186
+ }
187
+
188
+ private loadNodes(): void {
189
+ this.nodeMap.nodes = new NodeMap();
190
+ const nodeKeys = Object.keys(nodes);
191
+ for (const key of nodeKeys) {
192
+ this.nodeMap.nodes.addNode(key, nodes[key]);
193
+ }
194
+ }
195
+
196
+ private loadWorkflows(): void {
197
+ this.nodeMap.workflows = workflows;
198
+ }
199
+
200
+ async startConsumer(): Promise<void> {
201
+ // Find all workflows that use queue triggers
202
+ for (const workflowModel of this.nodeMap.workflows) {
203
+ const triggerKeys = Object.keys(workflowModel.trigger);
204
+ const triggerName = triggerKeys[0];
205
+
206
+ if (triggerName !== "queue") continue;
207
+
208
+ const config = workflowModel.trigger[triggerName];
209
+
210
+ // Connect to queue based on provider
211
+ console.log(\`Subscribing to queue: \${config.topic} (provider: \${config.provider})\`);
212
+
213
+ // Set up message handler
214
+ this.handleMessage(workflowModel, config);
215
+ }
216
+ }
217
+
218
+ private async handleMessage(workflowModel: any, config: any): Promise<void> {
219
+ // Create fresh context for this execution
220
+ const ctx = this.createContext(undefined, workflowModel.path);
221
+
222
+ // Populate ctx.request with message data
223
+ ctx.request = {
224
+ body: { /* message payload */ },
225
+ headers: {},
226
+ query: {},
227
+ params: {},
228
+ };
229
+
230
+ // Execute the workflow
231
+ try {
232
+ const runner = new Runner(ctx, workflowModel, this.nodeMap.nodes);
233
+ await runner.start();
234
+
235
+ if (ctx.response.success && config.ack) {
236
+ // Acknowledge message
237
+ }
238
+ } catch (error) {
239
+ // Handle execution error
240
+ if (config.deadLetterQueue) {
241
+ // Send to dead letter queue
242
+ }
243
+ }
244
+ }
245
+ }
246
+ \`\`\`
247
+
248
+ ## Constraints
249
+
250
+ * **ALWAYS extend TriggerBase** - Never bypass the base class
251
+ * **ALWAYS use createContext()** - Never construct Context manually
252
+ * **ALWAYS use the trigger config extraction pattern** with Object.keys(workflowModel.trigger)
253
+ * **ALWAYS implement loadNodes() and loadWorkflows()** following the HttpTrigger pattern
254
+ * Do NOT invent new Context properties beyond what createContext() provides
255
+ * Do NOT bypass error handling - use GlobalError consistently
256
+ * Include OpenTelemetry tracing with trace.getTracer()
257
+ * Include proper health check endpoints where applicable
258
+ * Handle graceful shutdown and cleanup
259
+ * Use TypeScript strict typing throughout
260
+
261
+ ## Formatting
262
+
263
+ * No explanations, comments, or markdown fences outside the TypeScript file
264
+ * The output must be a single valid TypeScript module
265
+ * Export the trigger class as default: \`export default class <Name>Trigger extends TriggerBase { ... }\`
266
+ * Include all necessary imports at the top of the file`,
267
+ updatePrompt: `You are a senior TypeScript backend engineer working on the Blok (blok) workflow framework. Your task is to update an existing Trigger implementation with new functionality while preserving its core structure.
268
+
269
+ Given the existing code below, enhance or modify it according to the user's requirements while maintaining:
270
+
271
+ 1. Keep the TriggerBase extension and constructor pattern
272
+ 2. Preserve loadNodes() and loadWorkflows() methods
273
+ 3. Maintain the createContext() usage pattern
274
+ 4. Keep OpenTelemetry tracing integration
275
+ 5. Maintain the trigger config extraction pattern
276
+
277
+ What to return:
278
+ * Return only the full updated Trigger file
279
+ * Preserve existing functionality unless explicitly asked to change it
280
+ * Add new functionality as requested
281
+ * Ensure proper error handling and cleanup
282
+ * Keep TypeScript strict typing
283
+
284
+ Format:
285
+ * No explanations or comments outside the code
286
+ * Return the complete file as it would appear in the .ts file
287
+ * Keep existing JSDoc comments unless they need updating
288
+ * Maintain the TriggerBase extension pattern
289
+
290
+ Current Code to be improved:
291
+ `,
292
+ };
293
+ export default createTriggerSystemPrompt;
@@ -0,0 +1,5 @@
1
+ declare const createWorkflowSystemPrompt: {
2
+ prompt: string;
3
+ updatePrompt: string;
4
+ };
5
+ export default createWorkflowSystemPrompt;