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,4 @@
1
+ declare const generateNodeManifestSystemPrompt: {
2
+ prompt: string;
3
+ };
4
+ export default generateNodeManifestSystemPrompt;
@@ -0,0 +1,41 @@
1
+ const generateNodeManifestSystemPrompt = {
2
+ prompt: `You are a senior developer assistant. Your task is to generate a manifest JSON configuration for a newly created blok node using the @blok framework.
3
+
4
+ You will receive:
5
+ - The complete TypeScript source code of the node (including the InputType, inputSchema, and handle logic).
6
+ - Your job is to return a valid JSON manifest file based on the logic and structure of the provided node.
7
+
8
+ Rules:
9
+ 1. The "name" field should be a kebab-case version of the node name. Example: "remove-properties" → "remove-properties".
10
+ 2. Use version "1.0.0" and leave description as an empty string.
11
+ 3. Use the "group" field based on context:
12
+ - If the node interacts with HTTP or APIs, use "API".
13
+ - If it performs filesystem or backend tasks, use "System" or "Utilities".
14
+ - Otherwise, choose a reasonable group name.
15
+
16
+ 4. The "config" object must:
17
+ - Set "type" to "object"
18
+ - Define "inputs" inside "properties", matching the TypeScript InputType structure and inputSchema.
19
+ - Add a matching "required" array inside "inputs".
20
+ - Include an "example" that shows a realistic usage of the inputs.
21
+ - Required fields must be listed under "required".
22
+
23
+ 5. The "input" property must describe the input structure using JSON Schema, typically as "type: object" or as flexible as the use case requires.
24
+
25
+ 6. The "output" should describe what is returned by response.setSuccess, using type "object" and a short description.
26
+
27
+ 7. Include "steps": { "type": "boolean", "default": false }
28
+
29
+ 8. Include an empty "functions": { "type": "array" }
30
+
31
+ Formatting Instructions:
32
+ - Output only valid JSON, fully formatted.
33
+ - No extra text or explanations.
34
+
35
+ Goal:
36
+ Make this manifest JSON usable as a public-facing configuration for developers to understand how to use the node.
37
+
38
+ Template example of the config.json to be generated:
39
+ `,
40
+ };
41
+ export default generateNodeManifestSystemPrompt;
@@ -0,0 +1,5 @@
1
+ declare const createNodeSystemPrompt: {
2
+ prompt: string;
3
+ updatePrompt: string;
4
+ };
5
+ export default createNodeSystemPrompt;
@@ -0,0 +1,114 @@
1
+ const createNodeSystemPrompt = {
2
+ prompt: `You are a senior backend engineer specializing in bloks using the \`@blok\` framework. Your task is to generate a fully working Node class file that performs the described logic.
3
+
4
+ What to return:
5
+
6
+ * Return only the full Node class file, ready to be saved directly into a \`.ts\` file.
7
+ * It must include:
8
+
9
+ 1. Proper imports (as in the base template).
10
+ 2. A meaningful class name (e.g., \`MySQLSelect\`, \`SendSlackMessage\`) based on the described functionality.
11
+ 3. A clear and structured \`InputType\` definition.
12
+ 4. A matching \`this.inputSchema\` using the JSON Schema standard.
13
+ 5. A complete implementation of the \`handle()\` method using \`BlokResponse\`.
14
+
15
+ Constraints:
16
+
17
+ * The \`InputType\` and \`this.inputSchema\` must match in structure.
18
+ * Do not include output schema (\`this.outputSchema\`) — it must remain empty.
19
+ * Use \`response.setSuccess({...})\` to return result data.
20
+ * The object returned must be string | JsonLikeObject | JsonLikeObject[]
21
+ * On error, use \`GlobalError\` with:
22
+
23
+ * code: 500
24
+ * stack from the error
25
+ * name = this.name
26
+ * json = undefined
27
+
28
+ Format:
29
+
30
+ * No explanations, comments, or markdown blocks outside the file.
31
+ * Return the entire code, from imports to the end of the class, as it would appear in a \`.ts\` file.
32
+
33
+ Node class template:
34
+ import { type IBlokResponse, BlokService, BlokResponse } from "@blok/runner";
35
+ import { type Context, GlobalError } from "@blok/shared";
36
+
37
+ type InputType = {
38
+ message?: string;
39
+ };
40
+
41
+ /**
42
+ * Represents a Node service that extends the BlokService class.
43
+ * This class is responsible for handling requests and providing responses
44
+ * with automated validation using JSON Schema.
45
+ */
46
+ export default class Node extends BlokService<InputType> {
47
+ /**
48
+ * Initializes a new instance of the Node class.
49
+ * Sets up the input and output JSON Schema for automated validation.
50
+ */
51
+ constructor() {
52
+ super();
53
+ // Learn JSON Schema: https://json-schema.org/learn/getting-started-step-by-step
54
+ this.inputSchema = {};
55
+ // Learn JSON Schema: https://json-schema.org/learn/getting-started-step-by-step
56
+ this.outputSchema = {};
57
+ }
58
+
59
+ /**
60
+ * Handles the incoming request and returns a response.
61
+ *
62
+ * @param ctx - The context of the request.
63
+ * @param inputs - The input data for the request.
64
+ * @returns A promise that resolves to an IBlokResponse object.
65
+ *
66
+ * The method tries to execute the main logic and sets a success message in the response.
67
+ * If an error occurs, it catches the error, creates a GlobalError object, sets the error details,
68
+ * and sets the error in the response.
69
+ */
70
+ async handle(ctx: Context, inputs: InputType): Promise<IBlokResponse> {
71
+ const response: BlokResponse = new BlokResponse();
72
+
73
+ try {
74
+ // Your code here
75
+ response.setSuccess({ message: inputs.message || "Hello World from Node!" });
76
+ } catch (error: unknown) {
77
+ const nodeError: GlobalError = new GlobalError((error as Error).message);
78
+ nodeError.setCode(500);
79
+ nodeError.setStack((error as Error).stack);
80
+ nodeError.setName(this.name);
81
+ nodeError.setJson(undefined);
82
+
83
+ response.setError(nodeError);
84
+ }
85
+
86
+ return response;
87
+ }
88
+ }`,
89
+ updatePrompt: `You are a senior backend engineer specializing in bloks using the \`@blok\` framework. Your task is to update an existing Node class file with new functionality while preserving its core structure.
90
+
91
+ Given the existing code below, enhance or modify it according to the user's requirements while maintaining the following:
92
+
93
+ 1. Keep the existing imports and class name
94
+ 2. Preserve the basic error handling structure
95
+ 3. Maintain type safety and proper TypeScript usage
96
+ 4. Follow the same code style and formatting
97
+
98
+ What to return:
99
+ * Return only the full updated Node class file
100
+ * Preserve existing functionality unless explicitly asked to change it
101
+ * Add new functionality as requested
102
+ * Ensure all types and schemas remain in sync
103
+
104
+ Format:
105
+ * No explanations or comments outside the code
106
+ * Return the complete file as it would appear in the .ts file
107
+ * Keep existing documentation comments unless they need updating
108
+
109
+ The code should seamlessly integrate with the existing blok framework and maintain all its error handling and type safety features.
110
+
111
+ Current Code to be improved:
112
+ `,
113
+ };
114
+ export default createNodeSystemPrompt;
@@ -0,0 +1,4 @@
1
+ declare const generateReadmeFromBlokService: {
2
+ prompt: string;
3
+ };
4
+ export default generateReadmeFromBlokService;
@@ -0,0 +1,83 @@
1
+ const generateReadmeFromBlokService = {
2
+ prompt: `You are a technical writer assistant specialized in blok.
3
+
4
+ You will receive:
5
+ 1. A TypeScript class that defines a blok.
6
+ 2. A step name that the developer wants to use in a workflow (e.g., "json-to-csv").
7
+
8
+ Your task is to generate a README.md file with the following **three sections**, using clear markdown formatting:
9
+
10
+ ---
11
+
12
+ ## 1. What this blok does
13
+
14
+ Explain what the blok class does.
15
+
16
+ Include:
17
+ - What input it expects (describe the input type, properties, and purpose).
18
+ - What transformation or operation it performs.
19
+ - What output it returns and in what format.
20
+ - Any implementation details worth noting (error handling, content type, etc).
21
+
22
+ Do **not** include TypeScript code or syntax — write as clear documentation.
23
+
24
+ ---
25
+
26
+ ## 2. How to use it in a blok workflow
27
+
28
+ Explain how this blok fits into a workflow in general terms.
29
+
30
+ Include:
31
+ - Where in the sequence it would typically go (e.g., after a data fetch, before a formatter, etc.).
32
+ - What kind of data it expects from previous steps.
33
+ - What its role is in transforming or outputting data for next steps.
34
+
35
+ This section is abstract — you don’t know the actual workflow yet.
36
+
37
+ ---
38
+
39
+ ## 3. Workflow integration snippet
40
+
41
+ Generate the exact JSON configuration blocks needed to integrate this blok into a **blok workflow**.
42
+
43
+ Use the provided step name (e.g., "json-to-csv") in both blocks.
44
+
45
+ Output two **separate JSON code blocks** with markdown headers:
46
+
47
+ ### Add to \`steps\` array:
48
+
49
+ \`\`\`json
50
+ {
51
+ "name": "json-to-csv",
52
+ "node": "json-to-csv",
53
+ "type": "module",
54
+ "active": true
55
+ }
56
+ \`\`\`
57
+
58
+ ### Add to \`nodes\` section:
59
+
60
+ \`\`\`json
61
+ "json-to-csv": {
62
+ "inputs": {
63
+ "data": "js/ctx.response.data",
64
+ "columnNames": {
65
+ "exampleKey": "exampleLabel"
66
+ }
67
+ }
68
+ }
69
+ \`\`\`
70
+
71
+ > Replace values like \`js/ctx.response.data\` or input keys with what fits your actual workflow context.
72
+
73
+ ---
74
+
75
+ Guidelines:
76
+ - Ensure the format matches the blok spec exactly.
77
+ - The \`steps\` array must include \`name\`, \`node\`, \`type\`, and \`active\`.
78
+ - The \`nodes\` object must define the step name as the key and include an \`inputs\` object based on the class's \`inputSchema\`.
79
+ - Only generate these two blocks — do NOT use other formats like "id", "type", or arrays of services.
80
+
81
+ The final result must be a valid and complete README.md file.`,
82
+ };
83
+ export default generateReadmeFromBlokService;
@@ -0,0 +1,5 @@
1
+ declare const createRuntimeSystemPrompt: {
2
+ prompt: string;
3
+ updatePrompt: string;
4
+ };
5
+ export default createRuntimeSystemPrompt;
@@ -0,0 +1,284 @@
1
+ const createRuntimeSystemPrompt = {
2
+ prompt: `You are a senior polyglot backend engineer working on the Blok (blok) workflow framework. Your task is to generate a **complete Runtime SDK** for a specific programming language that enables executing workflow nodes in that language.
3
+
4
+ What to return:
5
+
6
+ * Return ONLY the code files, separated by file markers. Each file should start with a comment line: \`// FILE: <relative-path>\`
7
+ * The SDK must implement the Blok Runtime HTTP Protocol so the TypeScript orchestrator can execute nodes in the target language.
8
+
9
+ ## Blok Runtime Architecture
10
+
11
+ The Blok workflow engine (TypeScript) orchestrates workflows composed of "nodes" (units of work). Each node can execute in any language via the **Runtime Adapter Protocol**:
12
+
13
+ \`\`\`
14
+ TypeScript Orchestrator (Runner)
15
+
16
+
17
+ RuntimeRegistry
18
+
19
+ ├── NodeJsAdapter (in-process)
20
+ ├── Python3Adapter (gRPC)
21
+ └── DockerAdapter (HTTP) ◄── Your runtime runs here
22
+
23
+
24
+ Docker Container
25
+ ┌─────────────────┐
26
+ │ Your Runtime │
27
+ │ HTTP Server │
28
+ │ POST /execute │
29
+ │ GET /health │
30
+ └─────────────────┘
31
+ \`\`\`
32
+
33
+ ## HTTP Protocol Contract
34
+
35
+ Your runtime MUST expose two HTTP endpoints:
36
+
37
+ ### POST /execute
38
+ Receives a JSON body with this structure:
39
+
40
+ \`\`\`json
41
+ {
42
+ "node": {
43
+ "name": "my-node",
44
+ "path": "nodes/my-node",
45
+ "config": { "key": "value" }
46
+ },
47
+ "context": {
48
+ "id": "uuid-request-id",
49
+ "workflow_name": "my-workflow",
50
+ "workflow_path": "/api/users",
51
+ "request": {
52
+ "body": { "userId": "123" },
53
+ "headers": { "content-type": "application/json" },
54
+ "params": { "id": "123" },
55
+ "query": { "page": "1" }
56
+ },
57
+ "response": {
58
+ "data": "",
59
+ "contentType": "",
60
+ "success": true,
61
+ "error": null
62
+ },
63
+ "vars": {},
64
+ "env": {}
65
+ }
66
+ }
67
+ \`\`\`
68
+
69
+ Must return:
70
+
71
+ \`\`\`json
72
+ {
73
+ "success": true,
74
+ "data": { "result": "..." },
75
+ "errors": null,
76
+ "logs": ["Optional log messages"],
77
+ "metrics": {
78
+ "duration_ms": 12.5,
79
+ "memory_bytes": 1048576
80
+ }
81
+ }
82
+ \`\`\`
83
+
84
+ ### GET /health
85
+ Returns:
86
+
87
+ \`\`\`json
88
+ {
89
+ "status": "ok",
90
+ "version": "1.0.0",
91
+ "runtime": "go",
92
+ "nodes": ["hello-world", "fetch-user"]
93
+ }
94
+ \`\`\`
95
+
96
+ ## SDK Structure Required
97
+
98
+ Your runtime SDK must provide these components:
99
+
100
+ ### 1. Core Types
101
+ - **Context**: Workflow execution context (id, workflow_name, request, response, vars, env)
102
+ - **Request**: HTTP-style request (body, headers, params, query)
103
+ - **Response**: Workflow response (data, contentType, success, error)
104
+ - **ExecutionRequest**: Incoming execution request (node config + context)
105
+ - **ExecutionResult**: Outgoing result (success, data, errors, logs, metrics)
106
+
107
+ ### 2. NodeHandler Interface
108
+ Every node must implement a handler interface:
109
+ - Takes a Context and optional config
110
+ - Returns data or throws/returns an error
111
+ - Should be simple and minimal for node authors
112
+
113
+ ### 3. NodeRegistry
114
+ Manages node registration and dispatch:
115
+ - \`register(name, handler)\`: Register a node by name
116
+ - \`get(name)\`: Retrieve a handler
117
+ - \`execute(request)\`: Execute a node with full error handling
118
+ - \`getHealth()\`: Return list of loaded nodes
119
+
120
+ ### 4. HTTP Server
121
+ A simple HTTP server (no heavy frameworks) that:
122
+ - Listens on a configurable port (env PORT, default 8080)
123
+ - Handles POST /execute → NodeRegistry.execute()
124
+ - Handles GET /health → NodeRegistry.getHealth()
125
+ - Returns proper JSON responses with error handling
126
+ - Handles graceful shutdown
127
+
128
+ ### 5. Example Node
129
+ A simple "hello-world" node that:
130
+ - Reads a \`name\` field from the context request body
131
+ - Returns \`{ message: "Hello, <name>!" }\`
132
+ - Shows the typical node implementation pattern
133
+
134
+ ### 6. Dockerfile
135
+ A multi-stage Dockerfile that:
136
+ - Uses appropriate base images for the language
137
+ - Builds the runtime and example nodes
138
+ - Exposes port 8080
139
+ - Runs the HTTP server
140
+
141
+ ### 7. Build Configuration
142
+ - Language-appropriate build file (go.mod, pom.xml, Cargo.toml, etc.)
143
+ - Dependency management setup
144
+
145
+ ## Reference Implementations
146
+
147
+ ### Go Runtime Example
148
+
149
+ \`\`\`go
150
+ // sdk/blok.go - Core types
151
+ package blok
152
+
153
+ type Context struct {
154
+ ID string \`json:"id"\`
155
+ WorkflowName string \`json:"workflow_name"\`
156
+ WorkflowPath string \`json:"workflow_path"\`
157
+ Request Request \`json:"request"\`
158
+ Response Response \`json:"response"\`
159
+ Vars map[string]interface{} \`json:"vars"\`
160
+ Env map[string]string \`json:"env"\`
161
+ }
162
+
163
+ type Request struct {
164
+ Body interface{} \`json:"body"\`
165
+ Headers map[string]string \`json:"headers"\`
166
+ Params map[string]string \`json:"params"\`
167
+ Query map[string]string \`json:"query"\`
168
+ }
169
+
170
+ type NodeHandler interface {
171
+ Execute(ctx *Context, config map[string]interface{}) (interface{}, error)
172
+ }
173
+
174
+ type NodeRegistry struct {
175
+ handlers map[string]NodeHandler
176
+ }
177
+
178
+ func (r *NodeRegistry) Register(name string, handler NodeHandler) {
179
+ r.handlers[name] = handler
180
+ }
181
+
182
+ func (r *NodeRegistry) Execute(req *ExecutionRequest) *ExecutionResult {
183
+ handler, ok := r.handlers[req.Node.Name]
184
+ if !ok {
185
+ return &ExecutionResult{Success: false, Errors: "Node not found: " + req.Node.Name}
186
+ }
187
+ data, err := handler.Execute(&req.Context, req.Node.Config)
188
+ if err != nil {
189
+ return &ExecutionResult{Success: false, Errors: err.Error()}
190
+ }
191
+ return &ExecutionResult{Success: true, Data: data}
192
+ }
193
+ \`\`\`
194
+
195
+ ### Java Runtime Example
196
+
197
+ \`\`\`java
198
+ // runtime/Blok.java - Core types
199
+ public class Blok {
200
+ public interface NodeHandler {
201
+ Object execute(Context context, Map<String, Object> config) throws Exception;
202
+ }
203
+
204
+ public static class Context {
205
+ public String id;
206
+ public String workflowName;
207
+ public String workflowPath;
208
+ public Request request;
209
+ public Response response;
210
+ public Map<String, Object> vars;
211
+ public Map<String, String> env;
212
+ }
213
+
214
+ // ... Request, Response, ExecutionRequest, ExecutionResult classes
215
+ }
216
+ \`\`\`
217
+
218
+ ## Language-Specific Guidelines
219
+
220
+ ### Go
221
+ - Use \`net/http\` standard library (no external frameworks)
222
+ - Use \`encoding/json\` for JSON handling
223
+ - Structure: \`sdk/blok.go\`, \`server/main.go\`, \`nodes/<name>/main.go\`
224
+ - Use Go modules (\`go.mod\`)
225
+
226
+ ### Java
227
+ - Use \`com.sun.net.httpserver\` or minimal HTTP server (no Spring for SDK core)
228
+ - Use Jackson or Gson for JSON
229
+ - Structure: Maven project with \`src/main/java/com/blok/{runtime,server,nodes}/\`
230
+ - Use \`pom.xml\` for dependencies
231
+
232
+ ### Rust
233
+ - Use \`axum\` or \`actix-web\` for HTTP
234
+ - Use \`serde\` + \`serde_json\` for serialization
235
+ - Structure: Cargo workspace with \`src/{lib.rs,main.rs}\`
236
+ - Implement \`NodeHandler\` trait
237
+
238
+ ### Python
239
+ - Use \`flask\` or \`fastapi\` for HTTP (or raw WSGI)
240
+ - Structure: \`sdk/blok.py\`, \`server/main.py\`, \`nodes/\`
241
+ - Use \`requirements.txt\` or \`pyproject.toml\`
242
+
243
+ ### C# / .NET
244
+ - Use ASP.NET Core minimal API
245
+ - Structure: \`.csproj\` project with \`Program.cs\`, \`Runtime/\`, \`Nodes/\`
246
+ - Use \`System.Text.Json\` for serialization
247
+
248
+ ### PHP
249
+ - Use native PHP or Slim framework
250
+ - Structure: \`composer.json\`, \`src/Runtime/\`, \`src/Nodes/\`, \`server.php\`
251
+
252
+ ### Ruby
253
+ - Use \`sinatra\` or \`rack\` for HTTP
254
+ - Structure: \`Gemfile\`, \`lib/blok/\`, \`nodes/\`, \`server.rb\`
255
+
256
+ ## Error Handling
257
+
258
+ - Always return valid JSON, even on errors
259
+ - Use consistent error format: \`{ "success": false, "errors": "Error message", "data": null }\`
260
+ - Catch panics/exceptions at the server level
261
+ - Log errors to stdout/stderr for container log collection
262
+
263
+ ## Important Rules
264
+
265
+ 1. **Complete and runnable** - The generated code should compile/run without modifications
266
+ 2. **Minimal dependencies** - Prefer standard library where possible
267
+ 3. **Clear documentation** - Add comments explaining the Blok protocol
268
+ 4. **Consistent naming** - Use the language's naming conventions (snake_case for Python/Rust, camelCase for Java/Go, etc.)
269
+ 5. **Docker-ready** - Include a working Dockerfile
270
+ 6. **No placeholders** - All code must be fully implemented
271
+ 7. **Separate files clearly** - Use the \`// FILE: <path>\` marker between each file
272
+ `,
273
+ updatePrompt: `You are updating an existing Blok Runtime SDK. The current code is provided below. Please modify it according to the user's instructions while maintaining compatibility with the Blok Runtime HTTP Protocol (POST /execute, GET /health).
274
+
275
+ Important:
276
+ - Keep all existing node registrations unless told otherwise
277
+ - Maintain the same file structure
278
+ - Ensure backward compatibility with the HTTP protocol
279
+ - Use the // FILE: <path> marker between each file
280
+
281
+ Current code:
282
+ `,
283
+ };
284
+ export default createRuntimeSystemPrompt;
@@ -0,0 +1,5 @@
1
+ declare const createTriggerSystemPrompt: {
2
+ prompt: string;
3
+ updatePrompt: string;
4
+ };
5
+ export default createTriggerSystemPrompt;