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,271 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import chalk from "chalk";
3
+ import { Box, Text, render, useInput } from "ink";
4
+ import { useEffect, useState } from "react";
5
+ const PROM_URL = "http://localhost:9090/api/v1/query";
6
+ const fmt = (val, decimals = 1) => {
7
+ let valNew = (val ?? 0).toFixed(decimals);
8
+ if (valNew.toString() === "NaN") {
9
+ valNew = "0";
10
+ }
11
+ return valNew;
12
+ };
13
+ const queryPrometheus = async (query, host, token) => {
14
+ const REMOTE_PROM_URL = host ? `${host}/api/v1/query` : undefined;
15
+ try {
16
+ const res = token
17
+ ? await fetch(`${REMOTE_PROM_URL || PROM_URL}?query=${encodeURIComponent(query)}`, {
18
+ headers: {
19
+ Authorization: `Bearer ${token}`,
20
+ Accept: "application/json",
21
+ "Accept-Encoding": "identity",
22
+ },
23
+ })
24
+ : await fetch(`${REMOTE_PROM_URL || PROM_URL}?query=${encodeURIComponent(query)}`);
25
+ if (!res.ok) {
26
+ return [];
27
+ }
28
+ const data = await res.json();
29
+ return data.data.result || [];
30
+ }
31
+ catch {
32
+ return [];
33
+ }
34
+ };
35
+ const fetchSystemMetrics = async (host, token) => {
36
+ const [uptimeRaw, totalReqs, totalErrs, avgResp, memUsage, cpuUsage] = await Promise.all([
37
+ queryPrometheus("process_uptime_seconds", host, token),
38
+ queryPrometheus("sum(increase(workflow_total[5m]))", host, token),
39
+ queryPrometheus("sum(increase(workflow_errors_total[5m]))", host, token),
40
+ queryPrometheus("avg(increase(workflow_time[5m]))", host, token),
41
+ queryPrometheus("process_resident_memory_bytes / 1024 / 1024", host, token),
42
+ queryPrometheus("rate(process_cpu_seconds_total[1m]) * 100", host, token),
43
+ ]);
44
+ const totalRequests = +(totalReqs[0]?.value?.[1] ?? "0");
45
+ const totalErrors = +(totalErrs[0]?.value?.[1] ?? "0");
46
+ return {
47
+ uptime: +(uptimeRaw[0]?.value?.[1] ?? "0"),
48
+ totalRequests: Math.round(totalRequests),
49
+ totalErrors: Math.round(totalErrors),
50
+ avgResponseMs: +(avgResp[0]?.value?.[1] ?? "0"),
51
+ memoryUsageMb: +(memUsage[0]?.value?.[1] ?? "0"),
52
+ cpuUsagePct: +(cpuUsage[0]?.value?.[1] ?? "0"),
53
+ activeWorkflows: 0,
54
+ errorRate: totalRequests > 0 ? (totalErrors / totalRequests) * 100 : 0,
55
+ };
56
+ };
57
+ const fetchTriggerStatus = async (host, token) => {
58
+ const [triggerReqs, triggerErrs, triggerLatency] = await Promise.all([
59
+ queryPrometheus("sum(increase(workflow_total[5m])) by (workflow_name)", host, token),
60
+ queryPrometheus("sum(increase(workflow_errors_total[5m])) by (workflow_name)", host, token),
61
+ queryPrometheus("avg(increase(workflow_time[5m])) by (workflow_name)", host, token),
62
+ ]);
63
+ const triggers = {};
64
+ for (const entry of triggerReqs) {
65
+ const name = entry.metric.workflow_name || "unknown";
66
+ if (!triggers[name]) {
67
+ triggers[name] = { name, type: "http", status: "healthy", requests: 0, errors: 0, avgLatencyMs: 0 };
68
+ }
69
+ triggers[name].requests = Math.round(+(entry.value?.[1] ?? "0"));
70
+ }
71
+ for (const entry of triggerErrs) {
72
+ const name = entry.metric.workflow_name || "unknown";
73
+ if (triggers[name]) {
74
+ triggers[name].errors = Math.round(+(entry.value?.[1] ?? "0"));
75
+ if (triggers[name].errors > 0) {
76
+ const errorRate = triggers[name].requests > 0 ? triggers[name].errors / triggers[name].requests : 1;
77
+ triggers[name].status = errorRate > 0.5 ? "unhealthy" : "degraded";
78
+ }
79
+ }
80
+ }
81
+ for (const entry of triggerLatency) {
82
+ const name = entry.metric.workflow_name || "unknown";
83
+ if (triggers[name]) {
84
+ triggers[name].avgLatencyMs = +(entry.value?.[1] ?? "0");
85
+ }
86
+ }
87
+ return Object.values(triggers);
88
+ };
89
+ const fetchPrometheusMetrics = async (host, token) => {
90
+ const [wfReqs, wfTime, wfErrors, wfCPU, wfMem] = await Promise.all([
91
+ queryPrometheus("(sum(increase(workflow_total[1m])) by (workflow_path)) > 0", host, token),
92
+ queryPrometheus("sum(increase(workflow_time[1m])) by (workflow_path)", host, token),
93
+ queryPrometheus("(sum(increase(workflow_errors_total[1m])) by (workflow_path)) > 0", host, token),
94
+ queryPrometheus("sum(increase(workflow_cpu[1m])) by (workflow_path)", host, token),
95
+ queryPrometheus("sum(increase(workflow_memory[1m])) by (workflow_path)", host, token),
96
+ ]);
97
+ const wfMap = {};
98
+ const mapWorkflow = (list, key, convert) => {
99
+ for (const entry of list) {
100
+ const name = entry.metric.workflow_path;
101
+ if (!name)
102
+ continue;
103
+ if (!wfMap[name]) {
104
+ wfMap[name] = {
105
+ workflow: name,
106
+ totalTimeMs: 0,
107
+ totalMemoryMb: 0,
108
+ totalCpuPct: 0,
109
+ errors: 0,
110
+ requests: 0,
111
+ nodes: [],
112
+ };
113
+ }
114
+ wfMap[name][key] = convert(entry.value?.[1] ?? "0");
115
+ }
116
+ };
117
+ mapWorkflow(wfTime, "totalTimeMs", (v) => +v);
118
+ mapWorkflow(wfMem, "totalMemoryMb", (v) => +v);
119
+ mapWorkflow(wfCPU, "totalCpuPct", (v) => +v);
120
+ mapWorkflow(wfErrors, "errors", (v) => Math.round(+v));
121
+ mapWorkflow(wfReqs, "requests", (v) => Math.round(+v));
122
+ const nodeMetricsRaw = await Promise.all([
123
+ queryPrometheus("(sum(increase(node_total[1m])) by (node_name, workflow_path)) > 0", host, token),
124
+ queryPrometheus("sum(increase(node_time[1m])) by (node_name, workflow_path)", host, token),
125
+ queryPrometheus("(sum(increase(node_errors_total[1m])) by (node_name, workflow_path)) > 0", host, token),
126
+ queryPrometheus("sum(increase(node_cpu[1m])) by (node_name, workflow_path)", host, token),
127
+ queryPrometheus("sum(increase(node_memory[1m])) by (node_name, workflow_path)", host, token),
128
+ ]);
129
+ const nodeMap = {};
130
+ const setNodeMetric = (list, key, convert) => {
131
+ for (const entry of list) {
132
+ const wf = entry.metric.workflow_path;
133
+ const node = entry.metric.node_name;
134
+ if (!wf || !node)
135
+ continue;
136
+ if (!nodeMap[wf])
137
+ nodeMap[wf] = {};
138
+ if (!nodeMap[wf][node])
139
+ nodeMap[wf][node] = { name: node };
140
+ const raw = Number.parseFloat(entry.value?.[1] ?? "0");
141
+ nodeMap[wf][node][key] = convert(raw.toString());
142
+ }
143
+ };
144
+ setNodeMetric(nodeMetricsRaw[0], "requests", (v) => +v);
145
+ setNodeMetric(nodeMetricsRaw[1], "timeMs", (v) => +v);
146
+ setNodeMetric(nodeMetricsRaw[4], "memoryMb", (v) => +v);
147
+ setNodeMetric(nodeMetricsRaw[3], "cpuPct", (v) => +v);
148
+ setNodeMetric(nodeMetricsRaw[2], "errors", (v) => Math.round(+v));
149
+ for (const wf of Object.keys(nodeMap)) {
150
+ const wfObj = wfMap[wf];
151
+ if (!wfObj)
152
+ continue;
153
+ const nodes = Object.values(nodeMap[wf]);
154
+ wfObj.nodes = nodes;
155
+ }
156
+ return Object.values(wfMap);
157
+ };
158
+ const formatUptime = (seconds) => {
159
+ if (seconds < 60)
160
+ return `${Math.round(seconds)}s`;
161
+ if (seconds < 3600)
162
+ return `${Math.floor(seconds / 60)}m ${Math.round(seconds % 60)}s`;
163
+ const hours = Math.floor(seconds / 3600);
164
+ const mins = Math.floor((seconds % 3600) / 60);
165
+ return `${hours}h ${mins}m`;
166
+ };
167
+ const statusIndicator = (status) => {
168
+ switch (status) {
169
+ case "healthy":
170
+ case "active":
171
+ return chalk.green("UP");
172
+ case "degraded":
173
+ return chalk.yellow("WARN");
174
+ case "unhealthy":
175
+ case "error":
176
+ return chalk.red("DOWN");
177
+ default:
178
+ return chalk.gray("--");
179
+ }
180
+ };
181
+ const SystemPanel = ({ system }) => (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: "cyan", paddingX: 1, children: [_jsx(Text, { bold: true, children: chalk.cyan(" System Overview ") }), _jsxs(Box, { flexDirection: "row", marginTop: 1, children: [_jsxs(Box, { flexDirection: "column", width: "25%", children: [_jsx(Text, { dimColor: true, children: "Uptime" }), _jsx(Text, { bold: true, children: formatUptime(system.uptime) })] }), _jsxs(Box, { flexDirection: "column", width: "25%", children: [_jsx(Text, { dimColor: true, children: "Requests (5m)" }), _jsx(Text, { bold: true, children: fmt(system.totalRequests, 0) })] }), _jsxs(Box, { flexDirection: "column", width: "25%", children: [_jsx(Text, { dimColor: true, children: "Error Rate" }), _jsxs(Text, { bold: true, color: system.errorRate > 5 ? "red" : system.errorRate > 1 ? "yellow" : "green", children: [fmt(system.errorRate), "%"] })] }), _jsxs(Box, { flexDirection: "column", width: "25%", children: [_jsx(Text, { dimColor: true, children: "Avg Response" }), _jsxs(Text, { bold: true, children: [fmt(system.avgResponseMs, 0), "ms"] })] })] }), _jsxs(Box, { flexDirection: "row", marginTop: 1, children: [_jsxs(Box, { flexDirection: "column", width: "25%", children: [_jsx(Text, { dimColor: true, children: "Memory" }), _jsxs(Text, { bold: true, children: [fmt(system.memoryUsageMb), "MB"] })] }), _jsxs(Box, { flexDirection: "column", width: "25%", children: [_jsx(Text, { dimColor: true, children: "CPU" }), _jsxs(Text, { bold: true, children: [fmt(system.cpuUsagePct), "%"] })] }), _jsxs(Box, { flexDirection: "column", width: "25%", children: [_jsx(Text, { dimColor: true, children: "Errors (5m)" }), _jsx(Text, { bold: true, color: system.totalErrors > 0 ? "red" : "green", children: fmt(system.totalErrors, 0) })] }), _jsxs(Box, { flexDirection: "column", width: "25%", children: [_jsx(Text, { dimColor: true, children: "Workflows" }), _jsx(Text, { bold: true, children: system.activeWorkflows })] })] })] }));
182
+ const TriggersPanel = ({ triggers }) => (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: "magenta", paddingX: 1, children: [_jsx(Text, { bold: true, children: chalk.magenta(" Trigger Status ") }), triggers.length === 0 ? (_jsx(Text, { dimColor: true, children: " No trigger data available" })) : (_jsxs(_Fragment, { children: [_jsx(Text, { children: chalk.gray(" ┌────────────────────────┬──────────┬──────────┬──────────┬────────────┬────────┐") }), _jsx(Text, { children: chalk.gray(" │ Trigger │ Type │ Status │ Requests │ Latency │ Errors │") }), _jsx(Text, { children: chalk.gray(" ├────────────────────────┼──────────┼──────────┼──────────┼────────────┼────────┤") }), triggers.map((t) => (_jsx(Text, { children: ` │ ${t.name.slice(0, 22).padEnd(22)} │ ${t.type.padEnd(8)} │ ${statusIndicator(t.status).padEnd(17)} │ ${fmt(t.requests, 0).padStart(8)} │ ${fmt(t.avgLatencyMs, 0).padStart(8)}ms │ ${t.errors > 0 ? chalk.red(t.errors.toString().padStart(6)) : chalk.green(" 0")} │` }, t.name))), _jsx(Text, { children: chalk.gray(" └────────────────────────┴──────────┴──────────┴──────────┴────────────┴────────┘") })] }))] }));
183
+ const RuntimesPanel = ({ runtimes }) => {
184
+ const displayRuntimes = runtimes.length > 0
185
+ ? runtimes
186
+ : [
187
+ { kind: "nodejs", status: "active", executions: 0, avgDurationMs: 0, errors: 0 },
188
+ { kind: "python3", status: "inactive", executions: 0, avgDurationMs: 0, errors: 0 },
189
+ { kind: "docker", status: "inactive", executions: 0, avgDurationMs: 0, errors: 0 },
190
+ ];
191
+ return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: "yellow", paddingX: 1, children: [_jsx(Text, { bold: true, children: chalk.yellow(" Runtime Adapters ") }), _jsx(Box, { flexDirection: "row", marginTop: 1, children: displayRuntimes.map((rt) => (_jsxs(Box, { flexDirection: "column", marginRight: 3, children: [_jsx(Text, { bold: true, children: rt.kind.toUpperCase() }), _jsx(Text, { children: statusIndicator(rt.status) }), _jsxs(Text, { dimColor: true, children: ["Exec: ", fmt(rt.executions, 0)] }), _jsxs(Text, { dimColor: true, children: ["Avg: ", fmt(rt.avgDurationMs, 0), "ms"] }), _jsxs(Text, { dimColor: true, children: ["Err: ", rt.errors > 0 ? chalk.red(rt.errors.toString()) : "0"] })] }, rt.kind))) })] }));
192
+ };
193
+ const WorkflowsPanel = ({ workflows, sortBy }) => {
194
+ const sorted = [...workflows].sort((a, b) => {
195
+ if (sortBy === "time")
196
+ return b.totalTimeMs - a.totalTimeMs;
197
+ if (sortBy === "memory")
198
+ return b.totalMemoryMb - a.totalMemoryMb;
199
+ if (sortBy === "cpu")
200
+ return b.totalCpuPct - a.totalCpuPct;
201
+ if (sortBy === "errors")
202
+ return b.errors - a.errors;
203
+ if (sortBy === "requests")
204
+ return b.requests - a.requests;
205
+ return 0;
206
+ });
207
+ return (_jsx(Box, { flexDirection: "column", children: sorted.length === 0 ? (_jsx(Text, { dimColor: true, children: " No workflow metrics available. Execute a workflow to see data." })) : (sorted.map((wf) => (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { bold: true, children: `Workflow: ${wf.workflow} | Time: ${fmt(wf.totalTimeMs, 0)}ms | RAM: ${fmt(wf.totalMemoryMb)}MB | CPU: ${fmt(wf.totalCpuPct)}% | Reqs: ${fmt(wf.requests, 0)} | Errs: ${fmt(wf.errors, 0)}` }), _jsx(Box, { flexDirection: "column", paddingLeft: 2, children: wf.nodes.length > 0 ? (_jsxs(_Fragment, { children: [_jsx(Text, { children: chalk.gray(" ┌──────────────────────┬───────────┬───────────┬──────────┬────────┬─────────┐") }), _jsx(Text, { children: chalk.gray(" │ Node │ Requests │ Time(ms) │ Mem(MB) │ CPU(%) │ Errors │") }), _jsx(Text, { children: chalk.gray(" ├──────────────────────┼───────────┼───────────┼──────────┼────────┼─────────┤") }), wf.nodes.map((node) => (_jsx(Text, { children: ` │ ${node.name.slice(0, 20).padEnd(20)} │ ${fmt(node.requests, 0).padStart(9)} | ${fmt(node.timeMs, 0).padStart(9)} │ ${fmt(node.memoryMb).padStart(8)} │ ${fmt(node.cpuPct).padStart(6)} │ ${(node.errors ?? 0) > 0
208
+ ? chalk.red((node.errors ?? 0).toString().padStart(7))
209
+ : chalk.green(" 0")} │` }, node.name))), _jsx(Text, { children: chalk.gray(" └──────────────────────┴───────────┴───────────┴──────────┴────────┴─────────┘") })] })) : (_jsx(Text, { dimColor: true, children: " (No node-level data)" })) })] }, wf.workflow)))) }));
210
+ };
211
+ const Monitor = ({ host, token }) => {
212
+ const [workflows, setWorkflows] = useState([]);
213
+ const [system, setSystem] = useState({
214
+ uptime: 0,
215
+ totalRequests: 0,
216
+ totalErrors: 0,
217
+ avgResponseMs: 0,
218
+ memoryUsageMb: 0,
219
+ cpuUsagePct: 0,
220
+ activeWorkflows: 0,
221
+ errorRate: 0,
222
+ });
223
+ const [triggers, setTriggers] = useState([]);
224
+ const [runtimes] = useState([]);
225
+ const [lastUpdate, setLastUpdate] = useState(new Date());
226
+ const [sortBy, setSortBy] = useState("time");
227
+ const [view, setView] = useState("workflows");
228
+ useEffect(() => {
229
+ const fetchAll = async () => {
230
+ const [wfResult, sysResult, trigResult] = await Promise.all([
231
+ fetchPrometheusMetrics(host, token),
232
+ fetchSystemMetrics(host, token),
233
+ fetchTriggerStatus(host, token),
234
+ ]);
235
+ sysResult.activeWorkflows = wfResult.length;
236
+ setWorkflows(wfResult);
237
+ setSystem(sysResult);
238
+ setTriggers(trigResult);
239
+ setLastUpdate(new Date());
240
+ };
241
+ fetchAll();
242
+ const interval = setInterval(fetchAll, 3000);
243
+ return () => clearInterval(interval);
244
+ }, [host, token]);
245
+ useInput((input) => {
246
+ if (input === "w")
247
+ setSortBy("time");
248
+ else if (input === "m")
249
+ setSortBy("memory");
250
+ else if (input === "c")
251
+ setSortBy("cpu");
252
+ else if (input === "e")
253
+ setSortBy("errors");
254
+ else if (input === "r")
255
+ setSortBy("requests");
256
+ else if (input === "1")
257
+ setView("workflows");
258
+ else if (input === "2")
259
+ setView("system");
260
+ else if (input === "3")
261
+ setView("triggers");
262
+ else if (input === "4")
263
+ setView("runtimes");
264
+ else if (input === "q")
265
+ process.exit(0);
266
+ });
267
+ return (_jsxs(Box, { flexDirection: "column", padding: 1, children: [_jsxs(Text, { bold: true, children: [chalk.cyan("Blok Monitor"), chalk.gray(` — ${lastUpdate.toLocaleTimeString()}`), chalk.gray(` | Uptime: ${formatUptime(system.uptime)}`), chalk.gray(` | ${system.totalRequests} reqs`), system.totalErrors > 0 ? chalk.red(` | ${system.totalErrors} errs`) : ""] }), _jsx(Text, { dimColor: true, children: `[1] Workflows${view === "workflows" ? "*" : ""} [2] System${view === "system" ? "*" : ""} [3] Triggers${view === "triggers" ? "*" : ""} [4] Runtimes${view === "runtimes" ? "*" : ""} | Sort: [w]Time [m]Mem [c]CPU [r]Req [e]Err [q]Quit` }), _jsx(Box, { marginTop: 1, children: _jsxs(Text, { children: [chalk.green(`Reqs: ${fmt(system.totalRequests, 0)}`), " ", chalk.yellow(`Avg: ${fmt(system.avgResponseMs, 0)}ms`), " ", system.totalErrors > 0 ? chalk.red(`Errors: ${fmt(system.totalErrors, 0)}`) : chalk.green("Errors: 0"), " ", chalk.blue(`Mem: ${fmt(system.memoryUsageMb)}MB`), " ", chalk.magenta(`CPU: ${fmt(system.cpuUsagePct)}%`)] }) }), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [view === "workflows" && _jsx(WorkflowsPanel, { workflows: workflows, sortBy: sortBy }), view === "system" && _jsx(SystemPanel, { system: system }), view === "triggers" && _jsx(TriggersPanel, { triggers: triggers }), view === "runtimes" && _jsx(RuntimesPanel, { runtimes: runtimes })] })] }));
268
+ };
269
+ export const runMonitor = (host, token) => {
270
+ render(_jsx(Monitor, { host: host, token: token }));
271
+ };