@blokjs/runner 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 (307) hide show
  1. package/dist/Blok.d.ts +19 -0
  2. package/dist/Blok.js +184 -0
  3. package/dist/Blok.js.map +1 -0
  4. package/dist/BlokResponse.d.ts +16 -0
  5. package/dist/BlokResponse.js +28 -0
  6. package/dist/BlokResponse.js.map +1 -0
  7. package/dist/Configuration.d.ts +37 -0
  8. package/dist/Configuration.js +248 -0
  9. package/dist/Configuration.js.map +1 -0
  10. package/dist/ConfigurationResolver.d.ts +7 -0
  11. package/dist/ConfigurationResolver.js +15 -0
  12. package/dist/ConfigurationResolver.js.map +1 -0
  13. package/dist/DefaultLogger.d.ts +65 -0
  14. package/dist/DefaultLogger.js +101 -0
  15. package/dist/DefaultLogger.js.map +1 -0
  16. package/dist/LocalStorage.d.ts +7 -0
  17. package/dist/LocalStorage.js +56 -0
  18. package/dist/LocalStorage.js.map +1 -0
  19. package/dist/MemoryUsage.d.ts +22 -0
  20. package/dist/MemoryUsage.js +83 -0
  21. package/dist/MemoryUsage.js.map +1 -0
  22. package/dist/NodeMap.d.ts +7 -0
  23. package/dist/NodeMap.js +13 -0
  24. package/dist/NodeMap.js.map +1 -0
  25. package/dist/ResolverBase.d.ts +8 -0
  26. package/dist/ResolverBase.js +18 -0
  27. package/dist/ResolverBase.js.map +1 -0
  28. package/dist/Runner.d.ts +25 -0
  29. package/dist/Runner.js +32 -0
  30. package/dist/Runner.js.map +1 -0
  31. package/dist/RunnerNode.d.ts +9 -0
  32. package/dist/RunnerNode.js +8 -0
  33. package/dist/RunnerNode.js.map +1 -0
  34. package/dist/RunnerNodeBase.d.ts +4 -0
  35. package/dist/RunnerNodeBase.js +3 -0
  36. package/dist/RunnerNodeBase.js.map +1 -0
  37. package/dist/RunnerSteps.d.ts +14 -0
  38. package/dist/RunnerSteps.js +110 -0
  39. package/dist/RunnerSteps.js.map +1 -0
  40. package/dist/RuntimeAdapterNode.d.ts +19 -0
  41. package/dist/RuntimeAdapterNode.js +87 -0
  42. package/dist/RuntimeAdapterNode.js.map +1 -0
  43. package/dist/RuntimeRegistry.d.ts +61 -0
  44. package/dist/RuntimeRegistry.js +87 -0
  45. package/dist/RuntimeRegistry.js.map +1 -0
  46. package/dist/TriggerBase.d.ts +119 -0
  47. package/dist/TriggerBase.js +413 -0
  48. package/dist/TriggerBase.js.map +1 -0
  49. package/dist/adapters/BunRuntimeAdapter.d.ts +38 -0
  50. package/dist/adapters/BunRuntimeAdapter.js +169 -0
  51. package/dist/adapters/BunRuntimeAdapter.js.map +1 -0
  52. package/dist/adapters/DockerRuntimeAdapter.d.ts +85 -0
  53. package/dist/adapters/DockerRuntimeAdapter.js +298 -0
  54. package/dist/adapters/DockerRuntimeAdapter.js.map +1 -0
  55. package/dist/adapters/HttpRuntimeAdapter.d.ts +58 -0
  56. package/dist/adapters/HttpRuntimeAdapter.js +152 -0
  57. package/dist/adapters/HttpRuntimeAdapter.js.map +1 -0
  58. package/dist/adapters/NodeJsRuntimeAdapter.d.ts +23 -0
  59. package/dist/adapters/NodeJsRuntimeAdapter.js +67 -0
  60. package/dist/adapters/NodeJsRuntimeAdapter.js.map +1 -0
  61. package/dist/adapters/RuntimeAdapter.d.ts +42 -0
  62. package/dist/adapters/RuntimeAdapter.js +2 -0
  63. package/dist/adapters/RuntimeAdapter.js.map +1 -0
  64. package/dist/adapters/WasmRuntimeAdapter.d.ts +69 -0
  65. package/dist/adapters/WasmRuntimeAdapter.js +279 -0
  66. package/dist/adapters/WasmRuntimeAdapter.js.map +1 -0
  67. package/dist/cache/NodeResultCache.d.ts +286 -0
  68. package/dist/cache/NodeResultCache.js +499 -0
  69. package/dist/cache/NodeResultCache.js.map +1 -0
  70. package/dist/cache/index.d.ts +1 -0
  71. package/dist/cache/index.js +2 -0
  72. package/dist/cache/index.js.map +1 -0
  73. package/dist/cost/CostEstimator.d.ts +57 -0
  74. package/dist/cost/CostEstimator.js +171 -0
  75. package/dist/cost/CostEstimator.js.map +1 -0
  76. package/dist/cost/index.d.ts +4 -0
  77. package/dist/cost/index.js +3 -0
  78. package/dist/cost/index.js.map +1 -0
  79. package/dist/cost/pricing.d.ts +24 -0
  80. package/dist/cost/pricing.js +169 -0
  81. package/dist/cost/pricing.js.map +1 -0
  82. package/dist/defineNode.d.ts +155 -0
  83. package/dist/defineNode.js +191 -0
  84. package/dist/defineNode.js.map +1 -0
  85. package/dist/graphql/GraphQLSchemaGenerator.d.ts +129 -0
  86. package/dist/graphql/GraphQLSchemaGenerator.js +425 -0
  87. package/dist/graphql/GraphQLSchemaGenerator.js.map +1 -0
  88. package/dist/hmr/FileWatcher.d.ts +62 -0
  89. package/dist/hmr/FileWatcher.js +185 -0
  90. package/dist/hmr/FileWatcher.js.map +1 -0
  91. package/dist/hmr/HmrDevConsole.d.ts +13 -0
  92. package/dist/hmr/HmrDevConsole.js +46 -0
  93. package/dist/hmr/HmrDevConsole.js.map +1 -0
  94. package/dist/hmr/HotReloadManager.d.ts +84 -0
  95. package/dist/hmr/HotReloadManager.js +195 -0
  96. package/dist/hmr/HotReloadManager.js.map +1 -0
  97. package/dist/hmr/index.d.ts +39 -0
  98. package/dist/hmr/index.js +38 -0
  99. package/dist/hmr/index.js.map +1 -0
  100. package/dist/index.d.ts +107 -0
  101. package/dist/index.js +107 -0
  102. package/dist/index.js.map +1 -0
  103. package/dist/integrations/APMIntegration.d.ts +141 -0
  104. package/dist/integrations/APMIntegration.js +212 -0
  105. package/dist/integrations/APMIntegration.js.map +1 -0
  106. package/dist/integrations/AzureMonitorIntegration.d.ts +118 -0
  107. package/dist/integrations/AzureMonitorIntegration.js +254 -0
  108. package/dist/integrations/AzureMonitorIntegration.js.map +1 -0
  109. package/dist/integrations/CloudWatchIntegration.d.ts +135 -0
  110. package/dist/integrations/CloudWatchIntegration.js +293 -0
  111. package/dist/integrations/CloudWatchIntegration.js.map +1 -0
  112. package/dist/integrations/SentryIntegration.d.ts +153 -0
  113. package/dist/integrations/SentryIntegration.js +200 -0
  114. package/dist/integrations/SentryIntegration.js.map +1 -0
  115. package/dist/integrations/index.d.ts +19 -0
  116. package/dist/integrations/index.js +16 -0
  117. package/dist/integrations/index.js.map +1 -0
  118. package/dist/marketplace/RuntimeAutoScaler.d.ts +148 -0
  119. package/dist/marketplace/RuntimeAutoScaler.js +366 -0
  120. package/dist/marketplace/RuntimeAutoScaler.js.map +1 -0
  121. package/dist/marketplace/RuntimeCatalog.d.ts +174 -0
  122. package/dist/marketplace/RuntimeCatalog.js +339 -0
  123. package/dist/marketplace/RuntimeCatalog.js.map +1 -0
  124. package/dist/marketplace/RuntimeDiscovery.d.ts +86 -0
  125. package/dist/marketplace/RuntimeDiscovery.js +219 -0
  126. package/dist/marketplace/RuntimeDiscovery.js.map +1 -0
  127. package/dist/marketplace/RuntimeHealthMonitor.d.ts +100 -0
  128. package/dist/marketplace/RuntimeHealthMonitor.js +241 -0
  129. package/dist/marketplace/RuntimeHealthMonitor.js.map +1 -0
  130. package/dist/marketplace/RuntimeMetricsDashboard.d.ts +113 -0
  131. package/dist/marketplace/RuntimeMetricsDashboard.js +293 -0
  132. package/dist/marketplace/RuntimeMetricsDashboard.js.map +1 -0
  133. package/dist/monitoring/CircuitBreaker.d.ts +107 -0
  134. package/dist/monitoring/CircuitBreaker.js +238 -0
  135. package/dist/monitoring/CircuitBreaker.js.map +1 -0
  136. package/dist/monitoring/DistributedTracer.d.ts +125 -0
  137. package/dist/monitoring/DistributedTracer.js +230 -0
  138. package/dist/monitoring/DistributedTracer.js.map +1 -0
  139. package/dist/monitoring/HealthCheck.d.ts +54 -0
  140. package/dist/monitoring/HealthCheck.js +102 -0
  141. package/dist/monitoring/HealthCheck.js.map +1 -0
  142. package/dist/monitoring/PerformanceProfiler.d.ts +63 -0
  143. package/dist/monitoring/PerformanceProfiler.js +229 -0
  144. package/dist/monitoring/PerformanceProfiler.js.map +1 -0
  145. package/dist/monitoring/PrometheusBootstrap.d.ts +30 -0
  146. package/dist/monitoring/PrometheusBootstrap.js +71 -0
  147. package/dist/monitoring/PrometheusBootstrap.js.map +1 -0
  148. package/dist/monitoring/PrometheusMetricsBridge.d.ts +60 -0
  149. package/dist/monitoring/PrometheusMetricsBridge.js +216 -0
  150. package/dist/monitoring/PrometheusMetricsBridge.js.map +1 -0
  151. package/dist/monitoring/RateLimiter.d.ts +58 -0
  152. package/dist/monitoring/RateLimiter.js +128 -0
  153. package/dist/monitoring/RateLimiter.js.map +1 -0
  154. package/dist/monitoring/StructuredLogger.d.ts +131 -0
  155. package/dist/monitoring/StructuredLogger.js +207 -0
  156. package/dist/monitoring/StructuredLogger.js.map +1 -0
  157. package/dist/monitoring/TracingBootstrap.d.ts +69 -0
  158. package/dist/monitoring/TracingBootstrap.js +129 -0
  159. package/dist/monitoring/TracingBootstrap.js.map +1 -0
  160. package/dist/monitoring/TriggerMetricsCollector.d.ts +94 -0
  161. package/dist/monitoring/TriggerMetricsCollector.js +174 -0
  162. package/dist/monitoring/TriggerMetricsCollector.js.map +1 -0
  163. package/dist/monitoring/index.d.ts +9 -0
  164. package/dist/monitoring/index.js +10 -0
  165. package/dist/monitoring/index.js.map +1 -0
  166. package/dist/openapi/OpenAPIGenerator.d.ts +192 -0
  167. package/dist/openapi/OpenAPIGenerator.js +373 -0
  168. package/dist/openapi/OpenAPIGenerator.js.map +1 -0
  169. package/dist/openapi/index.d.ts +20 -0
  170. package/dist/openapi/index.js +20 -0
  171. package/dist/openapi/index.js.map +1 -0
  172. package/dist/security/ABAC.d.ts +224 -0
  173. package/dist/security/ABAC.js +380 -0
  174. package/dist/security/ABAC.js.map +1 -0
  175. package/dist/security/AuditLogger.d.ts +242 -0
  176. package/dist/security/AuditLogger.js +317 -0
  177. package/dist/security/AuditLogger.js.map +1 -0
  178. package/dist/security/AuthMiddleware.d.ts +163 -0
  179. package/dist/security/AuthMiddleware.js +274 -0
  180. package/dist/security/AuthMiddleware.js.map +1 -0
  181. package/dist/security/EncryptionAtRest.d.ts +206 -0
  182. package/dist/security/EncryptionAtRest.js +236 -0
  183. package/dist/security/EncryptionAtRest.js.map +1 -0
  184. package/dist/security/OAuthProvider.d.ts +334 -0
  185. package/dist/security/OAuthProvider.js +719 -0
  186. package/dist/security/OAuthProvider.js.map +1 -0
  187. package/dist/security/PIIDetector.d.ts +233 -0
  188. package/dist/security/PIIDetector.js +354 -0
  189. package/dist/security/PIIDetector.js.map +1 -0
  190. package/dist/security/RBAC.d.ts +143 -0
  191. package/dist/security/RBAC.js +285 -0
  192. package/dist/security/RBAC.js.map +1 -0
  193. package/dist/security/SecretManager.d.ts +652 -0
  194. package/dist/security/SecretManager.js +1146 -0
  195. package/dist/security/SecretManager.js.map +1 -0
  196. package/dist/security/TLSConfig.d.ts +305 -0
  197. package/dist/security/TLSConfig.js +550 -0
  198. package/dist/security/TLSConfig.js.map +1 -0
  199. package/dist/security/index.d.ts +79 -0
  200. package/dist/security/index.js +80 -0
  201. package/dist/security/index.js.map +1 -0
  202. package/dist/testing/TestHarness.d.ts +189 -0
  203. package/dist/testing/TestHarness.js +272 -0
  204. package/dist/testing/TestHarness.js.map +1 -0
  205. package/dist/testing/TestLogger.d.ts +103 -0
  206. package/dist/testing/TestLogger.js +153 -0
  207. package/dist/testing/TestLogger.js.map +1 -0
  208. package/dist/testing/WorkflowTestRunner.d.ts +172 -0
  209. package/dist/testing/WorkflowTestRunner.js +355 -0
  210. package/dist/testing/WorkflowTestRunner.js.map +1 -0
  211. package/dist/testing/index.d.ts +21 -0
  212. package/dist/testing/index.js +22 -0
  213. package/dist/testing/index.js.map +1 -0
  214. package/dist/tracing/InMemoryRunStore.d.ts +44 -0
  215. package/dist/tracing/InMemoryRunStore.js +341 -0
  216. package/dist/tracing/InMemoryRunStore.js.map +1 -0
  217. package/dist/tracing/PostgresRunStore.d.ts +82 -0
  218. package/dist/tracing/PostgresRunStore.js +640 -0
  219. package/dist/tracing/PostgresRunStore.js.map +1 -0
  220. package/dist/tracing/RunStore.d.ts +38 -0
  221. package/dist/tracing/RunStore.js +2 -0
  222. package/dist/tracing/RunStore.js.map +1 -0
  223. package/dist/tracing/RunTracker.d.ts +75 -0
  224. package/dist/tracing/RunTracker.js +374 -0
  225. package/dist/tracing/RunTracker.js.map +1 -0
  226. package/dist/tracing/SqliteRunStore.d.ts +53 -0
  227. package/dist/tracing/SqliteRunStore.js +703 -0
  228. package/dist/tracing/SqliteRunStore.js.map +1 -0
  229. package/dist/tracing/TraceRouter.d.ts +47 -0
  230. package/dist/tracing/TraceRouter.js +904 -0
  231. package/dist/tracing/TraceRouter.js.map +1 -0
  232. package/dist/tracing/TracingLogger.d.ts +21 -0
  233. package/dist/tracing/TracingLogger.js +62 -0
  234. package/dist/tracing/TracingLogger.js.map +1 -0
  235. package/dist/tracing/createStore.d.ts +30 -0
  236. package/dist/tracing/createStore.js +75 -0
  237. package/dist/tracing/createStore.js.map +1 -0
  238. package/dist/tracing/index.d.ts +13 -0
  239. package/dist/tracing/index.js +9 -0
  240. package/dist/tracing/index.js.map +1 -0
  241. package/dist/tracing/sanitize.d.ts +7 -0
  242. package/dist/tracing/sanitize.js +95 -0
  243. package/dist/tracing/sanitize.js.map +1 -0
  244. package/dist/tracing/types.d.ts +178 -0
  245. package/dist/tracing/types.js +3 -0
  246. package/dist/tracing/types.js.map +1 -0
  247. package/dist/types/Average.d.ts +11 -0
  248. package/dist/types/Average.js +2 -0
  249. package/dist/types/Average.js.map +1 -0
  250. package/dist/types/Condition.d.ts +8 -0
  251. package/dist/types/Condition.js +2 -0
  252. package/dist/types/Condition.js.map +1 -0
  253. package/dist/types/Conditions.d.ts +5 -0
  254. package/dist/types/Conditions.js +2 -0
  255. package/dist/types/Conditions.js.map +1 -0
  256. package/dist/types/Config.d.ts +12 -0
  257. package/dist/types/Config.js +2 -0
  258. package/dist/types/Config.js.map +1 -0
  259. package/dist/types/Flow.d.ts +5 -0
  260. package/dist/types/Flow.js +2 -0
  261. package/dist/types/Flow.js.map +1 -0
  262. package/dist/types/GlobalOptions.d.ts +11 -0
  263. package/dist/types/GlobalOptions.js +2 -0
  264. package/dist/types/GlobalOptions.js.map +1 -0
  265. package/dist/types/Inputs.d.ts +5 -0
  266. package/dist/types/Inputs.js +2 -0
  267. package/dist/types/Inputs.js.map +1 -0
  268. package/dist/types/JsonLikeObject.d.ts +3 -0
  269. package/dist/types/JsonLikeObject.js +2 -0
  270. package/dist/types/JsonLikeObject.js.map +1 -0
  271. package/dist/types/Mapper.d.ts +5 -0
  272. package/dist/types/Mapper.js +2 -0
  273. package/dist/types/Mapper.js.map +1 -0
  274. package/dist/types/Node.d.ts +10 -0
  275. package/dist/types/Node.js +2 -0
  276. package/dist/types/Node.js.map +1 -0
  277. package/dist/types/ParamsDictionary.d.ts +3 -0
  278. package/dist/types/ParamsDictionary.js +2 -0
  279. package/dist/types/ParamsDictionary.js.map +1 -0
  280. package/dist/types/Properties.d.ts +5 -0
  281. package/dist/types/Properties.js +2 -0
  282. package/dist/types/Properties.js.map +1 -0
  283. package/dist/types/Targets.d.ts +5 -0
  284. package/dist/types/Targets.js +2 -0
  285. package/dist/types/Targets.js.map +1 -0
  286. package/dist/types/Trigger.d.ts +5 -0
  287. package/dist/types/Trigger.js +2 -0
  288. package/dist/types/Trigger.js.map +1 -0
  289. package/dist/types/TriggerHttp.d.ts +7 -0
  290. package/dist/types/TriggerHttp.js +2 -0
  291. package/dist/types/TriggerHttp.js.map +1 -0
  292. package/dist/types/TriggerResponse.d.ts +6 -0
  293. package/dist/types/TriggerResponse.js +2 -0
  294. package/dist/types/TriggerResponse.js.map +1 -0
  295. package/dist/types/Triggers.d.ts +5 -0
  296. package/dist/types/Triggers.js +2 -0
  297. package/dist/types/Triggers.js.map +1 -0
  298. package/dist/types/TryCatch.d.ts +6 -0
  299. package/dist/types/TryCatch.js +2 -0
  300. package/dist/types/TryCatch.js.map +1 -0
  301. package/dist/visualization/NodeDependencyGraph.d.ts +76 -0
  302. package/dist/visualization/NodeDependencyGraph.js +418 -0
  303. package/dist/visualization/NodeDependencyGraph.js.map +1 -0
  304. package/dist/visualization/WorkflowVisualizer.d.ts +144 -0
  305. package/dist/visualization/WorkflowVisualizer.js +446 -0
  306. package/dist/visualization/WorkflowVisualizer.js.map +1 -0
  307. package/package.json +95 -0
@@ -0,0 +1,171 @@
1
+ /**
2
+ * Cost Estimator for Blok Workflows
3
+ *
4
+ * Estimates execution costs per node and workflow based on
5
+ * runtime type, cloud provider pricing, and optional profiling data.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const estimator = new CostEstimator({ provider: "aws", executionsPerMonth: 100000 });
10
+ * const estimate = estimator.estimateWorkflow(workflowDef);
11
+ * console.log(estimator.toTable());
12
+ * ```
13
+ */
14
+ import { DEFAULT_DURATIONS, DEFAULT_MEMORY, PRICING, getRuntimeCategory, } from "./pricing";
15
+ export class CostEstimator {
16
+ config;
17
+ estimates = [];
18
+ constructor(config) {
19
+ this.config = {
20
+ provider: config?.provider ?? "aws",
21
+ executionsPerMonth: config?.executionsPerMonth ?? 10_000,
22
+ customPricing: config?.customPricing,
23
+ };
24
+ }
25
+ estimateWorkflow(workflow, profiles) {
26
+ const profileMap = new Map();
27
+ if (profiles) {
28
+ for (const p of profiles) {
29
+ profileMap.set(p.nodeName, p);
30
+ }
31
+ }
32
+ const nodes = [];
33
+ this.walkSteps(workflow.steps, profileMap, nodes);
34
+ const costPerExecution = nodes.reduce((sum, n) => sum + n.costPerExecution, 0);
35
+ const monthlyCost = costPerExecution * this.config.executionsPerMonth;
36
+ const estimate = {
37
+ workflowName: workflow.name,
38
+ nodes,
39
+ costPerExecution,
40
+ monthlyCost,
41
+ executionsPerMonth: this.config.executionsPerMonth,
42
+ provider: this.config.provider,
43
+ };
44
+ this.estimates.push(estimate);
45
+ return estimate;
46
+ }
47
+ estimateNode(nodeName, stepName, stepType, runtime, avgDurationMs, avgMemoryMb) {
48
+ const category = getRuntimeCategory(runtime || "nodejs", stepType);
49
+ const costModel = this.getCostModel(category);
50
+ const durationMs = avgDurationMs ?? DEFAULT_DURATIONS[category];
51
+ const memoryMb = avgMemoryMb ?? DEFAULT_MEMORY[category];
52
+ const cpuCost = durationMs * costModel.costPerMsCpu;
53
+ const memoryCost = ((memoryMb * durationMs) / 1000) * costModel.costPerMbMemorySecond;
54
+ const costPerExecution = costModel.baseCostPerExecution + cpuCost + memoryCost + costModel.networkCostPerCall;
55
+ return {
56
+ nodeName,
57
+ stepName,
58
+ runtime: runtime || this.inferRuntime(stepType),
59
+ category,
60
+ estimatedDurationMs: durationMs,
61
+ estimatedMemoryMb: memoryMb,
62
+ costPerExecution,
63
+ monthlyCost: costPerExecution * this.config.executionsPerMonth,
64
+ };
65
+ }
66
+ getEstimates() {
67
+ return this.estimates;
68
+ }
69
+ toTable() {
70
+ if (this.estimates.length === 0)
71
+ return "[No cost estimates]";
72
+ const lines = [];
73
+ for (const estimate of this.estimates) {
74
+ lines.push("");
75
+ lines.push(` Workflow: ${estimate.workflowName} | Provider: ${estimate.provider.toUpperCase()} | ${this.fmtNum(estimate.executionsPerMonth)} exec/month`);
76
+ lines.push("");
77
+ const header = this.padColumns([
78
+ { val: "Node", width: 22 },
79
+ { val: "Runtime", width: 10 },
80
+ { val: "Type", width: 12 },
81
+ { val: "Dur(ms)", width: 10 },
82
+ { val: "Mem(MB)", width: 10 },
83
+ { val: "Per Exec", width: 12 },
84
+ { val: "Monthly", width: 12 },
85
+ ]);
86
+ lines.push(` ${header}`);
87
+ lines.push(` ${"─".repeat(header.length)}`);
88
+ for (const node of estimate.nodes) {
89
+ const row = this.padColumns([
90
+ { val: this.truncate(node.nodeName, 20), width: 22 },
91
+ { val: node.runtime, width: 10 },
92
+ { val: node.category, width: 12 },
93
+ { val: node.estimatedDurationMs.toFixed(0), width: 10 },
94
+ { val: node.estimatedMemoryMb.toFixed(0), width: 10 },
95
+ { val: this.fmtUsd(node.costPerExecution), width: 12 },
96
+ { val: this.fmtUsd(node.monthlyCost), width: 12 },
97
+ ]);
98
+ lines.push(` ${row}`);
99
+ }
100
+ lines.push(` ${"─".repeat(header.length)}`);
101
+ const totalRow = this.padColumns([
102
+ { val: "TOTAL", width: 22 },
103
+ { val: "", width: 10 },
104
+ { val: "", width: 12 },
105
+ { val: "", width: 10 },
106
+ { val: "", width: 10 },
107
+ { val: this.fmtUsd(estimate.costPerExecution), width: 12 },
108
+ { val: this.fmtUsd(estimate.monthlyCost), width: 12 },
109
+ ]);
110
+ lines.push(` ${totalRow}`);
111
+ }
112
+ lines.push("");
113
+ return lines.join("\n");
114
+ }
115
+ toJson() {
116
+ return JSON.stringify(this.estimates, null, 2);
117
+ }
118
+ reset() {
119
+ this.estimates = [];
120
+ }
121
+ // -- Internal --
122
+ walkSteps(steps, profileMap, nodes) {
123
+ for (const step of steps) {
124
+ const profile = profileMap.get(step.node);
125
+ const estimate = this.estimateNode(step.node, step.name, step.type || "local", step.runtime || "", profile?.avgTimeMs, profile?.memoryAvgMb);
126
+ nodes.push(estimate);
127
+ if (step.conditions) {
128
+ for (const cond of step.conditions) {
129
+ if (cond.steps) {
130
+ this.walkSteps(cond.steps, profileMap, nodes);
131
+ }
132
+ }
133
+ }
134
+ }
135
+ }
136
+ getCostModel(category) {
137
+ const base = PRICING[this.config.provider][category];
138
+ const custom = this.config.customPricing?.[category];
139
+ if (custom) {
140
+ return { ...base, ...custom };
141
+ }
142
+ return base;
143
+ }
144
+ inferRuntime(stepType) {
145
+ if (stepType.startsWith("runtime.")) {
146
+ return stepType.replace("runtime.", "");
147
+ }
148
+ return "nodejs";
149
+ }
150
+ fmtUsd(amount) {
151
+ if (amount === 0)
152
+ return "$0.00";
153
+ if (amount < 0.01)
154
+ return `$${amount.toFixed(6)}`;
155
+ if (amount < 1)
156
+ return `$${amount.toFixed(4)}`;
157
+ if (amount < 1000)
158
+ return `$${amount.toFixed(2)}`;
159
+ return `$${amount.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
160
+ }
161
+ fmtNum(n) {
162
+ return n.toLocaleString("en-US");
163
+ }
164
+ truncate(s, len) {
165
+ return s.length > len ? `${s.substring(0, len - 3)}...` : s;
166
+ }
167
+ padColumns(cols) {
168
+ return cols.map((c) => c.val + " ".repeat(Math.max(0, c.width - c.val.length))).join("");
169
+ }
170
+ }
171
+ //# sourceMappingURL=CostEstimator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CostEstimator.js","sourceRoot":"","sources":["../../src/cost/CostEstimator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAEN,iBAAiB,EACjB,cAAc,EACd,OAAO,EAGP,kBAAkB,GAClB,MAAM,WAAW,CAAC;AA4BnB,MAAM,OAAO,aAAa;IACjB,MAAM,CAEZ;IACM,SAAS,GAA2B,EAAE,CAAC;IAE/C,YAAY,MAA4B;QACvC,IAAI,CAAC,MAAM,GAAG;YACb,QAAQ,EAAE,MAAM,EAAE,QAAQ,IAAI,KAAK;YACnC,kBAAkB,EAAE,MAAM,EAAE,kBAAkB,IAAI,MAAM;YACxD,aAAa,EAAE,MAAM,EAAE,aAAa;SACpC,CAAC;IACH,CAAC;IAED,gBAAgB,CAAC,QAAqB,EAAE,QAAwB;QAC/D,MAAM,UAAU,GAAG,IAAI,GAAG,EAAuB,CAAC;QAClD,IAAI,QAAQ,EAAE,CAAC;YACd,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;gBAC1B,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;YAC/B,CAAC;QACF,CAAC;QAED,MAAM,KAAK,GAAuB,EAAE,CAAC;QAErC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;QAElD,MAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC;QAC/E,MAA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CAAC,OAAO,EAAE,EAAE,qBAAqB,EAAE,CAAC,EAAE,qBAAqB,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACrG,CAAC;IAEO,MAAM,CAAC,CAAS;QACvB,OAAO,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAEO,QAAQ,CAAC,CAAS,EAAE,GAAW;QACtC,OAAO,CAAC,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7D,CAAC;IAEO,UAAU,CAAC,IAA2C;QAC7D,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1F,CAAC;CACD"}
@@ -0,0 +1,4 @@
1
+ export { CostEstimator } from "./CostEstimator";
2
+ export type { NodeCostEstimate, WorkflowCostEstimate, CostEstimatorConfig } from "./CostEstimator";
3
+ export { PRICING, DEFAULT_DURATIONS, DEFAULT_MEMORY, getRuntimeCategory } from "./pricing";
4
+ export type { CloudProvider, RuntimeCostCategory, RuntimeCostModel } from "./pricing";
@@ -0,0 +1,3 @@
1
+ export { CostEstimator } from "./CostEstimator";
2
+ export { PRICING, DEFAULT_DURATIONS, DEFAULT_MEMORY, getRuntimeCategory } from "./pricing";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cost/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Cloud Provider Pricing Models for Blok Runtime Cost Estimation
3
+ *
4
+ * Pricing is based on publicly available cloud provider rates as of 2026-01.
5
+ * All costs are in USD.
6
+ */
7
+ export type CloudProvider = "aws" | "gcp" | "azure" | "local";
8
+ export type RuntimeCostCategory = "in-process" | "docker" | "grpc" | "wasm";
9
+ export interface RuntimeCostModel {
10
+ category: RuntimeCostCategory;
11
+ baseCostPerExecution: number;
12
+ costPerMsCpu: number;
13
+ costPerMbMemorySecond: number;
14
+ containerOverheadMs: number;
15
+ networkCostPerCall: number;
16
+ }
17
+ /** Map RuntimeKind to cost category */
18
+ export declare function getRuntimeCategory(runtimeKind: string, stepType?: string): RuntimeCostCategory;
19
+ /** Default cost models per provider and category */
20
+ export declare const PRICING: Record<CloudProvider, Record<RuntimeCostCategory, RuntimeCostModel>>;
21
+ /** Default estimated durations (ms) by runtime category when no profiling data available */
22
+ export declare const DEFAULT_DURATIONS: Record<RuntimeCostCategory, number>;
23
+ /** Default estimated memory (MB) by runtime category */
24
+ export declare const DEFAULT_MEMORY: Record<RuntimeCostCategory, number>;
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Cloud Provider Pricing Models for Blok Runtime Cost Estimation
3
+ *
4
+ * Pricing is based on publicly available cloud provider rates as of 2026-01.
5
+ * All costs are in USD.
6
+ */
7
+ /** Map RuntimeKind to cost category */
8
+ export function getRuntimeCategory(runtimeKind, stepType) {
9
+ if (runtimeKind === "wasm")
10
+ return "wasm";
11
+ if (runtimeKind === "nodejs" || runtimeKind === "bun" || stepType === "local" || stepType === "module")
12
+ return "in-process";
13
+ // go, java, rust, php, csharp, ruby, python3, docker — all use HTTP SDK containers
14
+ return "docker";
15
+ }
16
+ /** Default cost models per provider and category */
17
+ export const PRICING = {
18
+ aws: {
19
+ "in-process": {
20
+ category: "in-process",
21
+ baseCostPerExecution: 0.0000002, // Lambda per-request ($0.20/million)
22
+ costPerMsCpu: 0.0000000167, // Lambda GB-s pricing at 128MB
23
+ costPerMbMemorySecond: 0.0000000167,
24
+ containerOverheadMs: 0,
25
+ networkCostPerCall: 0,
26
+ },
27
+ docker: {
28
+ category: "docker",
29
+ baseCostPerExecution: 0.0000002,
30
+ costPerMsCpu: 0.0000000334, // Fargate vCPU-second pricing
31
+ costPerMbMemorySecond: 0.0000000037,
32
+ containerOverheadMs: 50, // Cold start for container
33
+ networkCostPerCall: 0.000001, // Network transfer
34
+ },
35
+ grpc: {
36
+ category: "grpc",
37
+ baseCostPerExecution: 0.0000002,
38
+ costPerMsCpu: 0.0000000167,
39
+ costPerMbMemorySecond: 0.0000000167,
40
+ containerOverheadMs: 5,
41
+ networkCostPerCall: 0.000005, // gRPC call overhead
42
+ },
43
+ wasm: {
44
+ category: "wasm",
45
+ baseCostPerExecution: 0.0000001, // Minimal overhead
46
+ costPerMsCpu: 0.00000001,
47
+ costPerMbMemorySecond: 0.000000005,
48
+ containerOverheadMs: 1,
49
+ networkCostPerCall: 0,
50
+ },
51
+ },
52
+ gcp: {
53
+ "in-process": {
54
+ category: "in-process",
55
+ baseCostPerExecution: 0.0000004,
56
+ costPerMsCpu: 0.00001,
57
+ costPerMbMemorySecond: 0.0000025,
58
+ containerOverheadMs: 0,
59
+ networkCostPerCall: 0,
60
+ },
61
+ docker: {
62
+ category: "docker",
63
+ baseCostPerExecution: 0.0000004,
64
+ costPerMsCpu: 0.0000324,
65
+ costPerMbMemorySecond: 0.0000035,
66
+ containerOverheadMs: 80,
67
+ networkCostPerCall: 0.000001,
68
+ },
69
+ grpc: {
70
+ category: "grpc",
71
+ baseCostPerExecution: 0.0000004,
72
+ costPerMsCpu: 0.00001,
73
+ costPerMbMemorySecond: 0.0000025,
74
+ containerOverheadMs: 5,
75
+ networkCostPerCall: 0.000005,
76
+ },
77
+ wasm: {
78
+ category: "wasm",
79
+ baseCostPerExecution: 0.0000002,
80
+ costPerMsCpu: 0.000000008,
81
+ costPerMbMemorySecond: 0.000000004,
82
+ containerOverheadMs: 1,
83
+ networkCostPerCall: 0,
84
+ },
85
+ },
86
+ azure: {
87
+ "in-process": {
88
+ category: "in-process",
89
+ baseCostPerExecution: 0.0000002,
90
+ costPerMsCpu: 0.000016,
91
+ costPerMbMemorySecond: 0.000016,
92
+ containerOverheadMs: 0,
93
+ networkCostPerCall: 0,
94
+ },
95
+ docker: {
96
+ category: "docker",
97
+ baseCostPerExecution: 0.0000002,
98
+ costPerMsCpu: 0.000034,
99
+ costPerMbMemorySecond: 0.0000037,
100
+ containerOverheadMs: 60,
101
+ networkCostPerCall: 0.000001,
102
+ },
103
+ grpc: {
104
+ category: "grpc",
105
+ baseCostPerExecution: 0.0000002,
106
+ costPerMsCpu: 0.000016,
107
+ costPerMbMemorySecond: 0.000016,
108
+ containerOverheadMs: 5,
109
+ networkCostPerCall: 0.000005,
110
+ },
111
+ wasm: {
112
+ category: "wasm",
113
+ baseCostPerExecution: 0.0000001,
114
+ costPerMsCpu: 0.00000001,
115
+ costPerMbMemorySecond: 0.000000005,
116
+ containerOverheadMs: 1,
117
+ networkCostPerCall: 0,
118
+ },
119
+ },
120
+ local: {
121
+ "in-process": {
122
+ category: "in-process",
123
+ baseCostPerExecution: 0,
124
+ costPerMsCpu: 0,
125
+ costPerMbMemorySecond: 0,
126
+ containerOverheadMs: 0,
127
+ networkCostPerCall: 0,
128
+ },
129
+ docker: {
130
+ category: "docker",
131
+ baseCostPerExecution: 0,
132
+ costPerMsCpu: 0,
133
+ costPerMbMemorySecond: 0,
134
+ containerOverheadMs: 50,
135
+ networkCostPerCall: 0,
136
+ },
137
+ grpc: {
138
+ category: "grpc",
139
+ baseCostPerExecution: 0,
140
+ costPerMsCpu: 0,
141
+ costPerMbMemorySecond: 0,
142
+ containerOverheadMs: 5,
143
+ networkCostPerCall: 0,
144
+ },
145
+ wasm: {
146
+ category: "wasm",
147
+ baseCostPerExecution: 0,
148
+ costPerMsCpu: 0,
149
+ costPerMbMemorySecond: 0,
150
+ containerOverheadMs: 1,
151
+ networkCostPerCall: 0,
152
+ },
153
+ },
154
+ };
155
+ /** Default estimated durations (ms) by runtime category when no profiling data available */
156
+ export const DEFAULT_DURATIONS = {
157
+ "in-process": 10,
158
+ docker: 100,
159
+ grpc: 50,
160
+ wasm: 5,
161
+ };
162
+ /** Default estimated memory (MB) by runtime category */
163
+ export const DEFAULT_MEMORY = {
164
+ "in-process": 64,
165
+ docker: 256,
166
+ grpc: 128,
167
+ wasm: 32,
168
+ };
169
+ //# sourceMappingURL=pricing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pricing.js","sourceRoot":"","sources":["../../src/cost/pricing.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAcH,uCAAuC;AACvC,MAAM,UAAU,kBAAkB,CAAC,WAAmB,EAAE,QAAiB;IACxE,IAAI,WAAW,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC;IAC1C,IAAI,WAAW,KAAK,QAAQ,IAAI,WAAW,KAAK,KAAK,IAAI,QAAQ,KAAK,OAAO,IAAI,QAAQ,KAAK,QAAQ;QACrG,OAAO,YAAY,CAAC;IACrB,mFAAmF;IACnF,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED,oDAAoD;AACpD,MAAM,CAAC,MAAM,OAAO,GAAyE;IAC5F,GAAG,EAAE;QACJ,YAAY,EAAE;YACb,QAAQ,EAAE,YAAY;YACtB,oBAAoB,EAAE,SAAS,EAAE,qCAAqC;YACtE,YAAY,EAAE,YAAY,EAAE,+BAA+B;YAC3D,qBAAqB,EAAE,YAAY;YACnC,mBAAmB,EAAE,CAAC;YACtB,kBAAkB,EAAE,CAAC;SACrB;QACD,MAAM,EAAE;YACP,QAAQ,EAAE,QAAQ;YAClB,oBAAoB,EAAE,SAAS;YAC/B,YAAY,EAAE,YAAY,EAAE,8BAA8B;YAC1D,qBAAqB,EAAE,YAAY;YACnC,mBAAmB,EAAE,EAA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kBAAkB,EAAE,CAAC;SACrB;QACD,IAAI,EAAE;YACL,QAAQ,EAAE,MAAM;YAChB,oBAAoB,EAAE,CAAC;YACvB,YAAY,EAAE,CAAC;YACf,qBAAqB,EAAE,CAAC;YACxB,mBAAmB,EAAE,CAAC;YACtB,kBAAkB,EAAE,CAAC;SACrB;KACD;CACD,CAAC;AAEF,4FAA4F;AAC5F,MAAM,CAAC,MAAM,iBAAiB,GAAwC;IACrE,YAAY,EAAE,EAAE;IAChB,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,EAAE;IACR,IAAI,EAAE,CAAC;CACP,CAAC;AAEF,wDAAwD;AACxD,MAAM,CAAC,MAAM,cAAc,GAAwC;IAClE,YAAY,EAAE,EAAE;IAChB,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,GAAG;IACT,IAAI,EAAE,EAAE;CACR,CAAC"}
@@ -0,0 +1,155 @@
1
+ import type { z } from "zod";
2
+ import type { Context } from "@blokjs/shared";
3
+ import BlokService from "./Blok";
4
+ import type { IBlokResponse } from "./BlokResponse";
5
+ import type Condition from "./types/Condition";
6
+ import type JsonLikeObject from "./types/JsonLikeObject";
7
+ /**
8
+ * Function-first node definition with Zod schema validation
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const MyNode = defineNode({
13
+ * name: "my-node",
14
+ * description: "Does something awesome",
15
+ *
16
+ * input: z.object({
17
+ * userId: z.string().uuid(),
18
+ * }),
19
+ *
20
+ * output: z.object({
21
+ * user: z.object({
22
+ * id: z.string(),
23
+ * name: z.string(),
24
+ * }),
25
+ * }),
26
+ *
27
+ * async execute(ctx, input) {
28
+ * // Type-safe input and output!
29
+ * const user = await fetchUser(input.userId);
30
+ * return { user };
31
+ * },
32
+ * });
33
+ * ```
34
+ */
35
+ export interface FnNodeDefinition<TInput extends z.ZodTypeAny = z.ZodTypeAny, TOutput extends z.ZodTypeAny = z.ZodTypeAny> {
36
+ /** Node name (used for identification in workflows) */
37
+ name: string;
38
+ /** Human-readable description of what this node does */
39
+ description: string;
40
+ /** Zod schema for input validation */
41
+ input: TInput;
42
+ /** Zod schema for output validation */
43
+ output: TOutput;
44
+ /** Response content type (e.g. "text/html", "application/pdf"). Defaults to "application/json" */
45
+ contentType?: string;
46
+ /** Whether this is a flow control node (e.g. if-else) that returns sub-steps to execute */
47
+ flow?: boolean;
48
+ /**
49
+ * Node execution logic
50
+ * @param ctx - Workflow context
51
+ * @param input - Type-safe input (validated against input schema)
52
+ * @returns Type-safe output (will be validated against output schema)
53
+ */
54
+ execute: (ctx: Context, input: z.infer<TInput>) => Promise<z.infer<TOutput>> | z.infer<TOutput>;
55
+ }
56
+ /**
57
+ * FunctionNode wrapper that bridges function-first nodes to existing BlokService infrastructure
58
+ *
59
+ * This class wraps a function-first node definition and makes it compatible with the
60
+ * existing BlokService.run() execution model. It handles:
61
+ * - Zod input validation
62
+ * - Zod output validation
63
+ * - Error mapping (ZodError → GlobalError)
64
+ * - Response wrapping (BlokResponse)
65
+ */
66
+ export declare class FunctionNode<TInput extends z.ZodTypeAny, TOutput extends z.ZodTypeAny> extends BlokService<z.infer<TInput>> {
67
+ private definition;
68
+ constructor(definition: FnNodeDefinition<TInput, TOutput>);
69
+ /**
70
+ * Implementation of the abstract handle() method required by BlokService
71
+ *
72
+ * This method:
73
+ * 1. Validates input with Zod
74
+ * 2. Executes the user's execute() function
75
+ * 3. Validates output with Zod
76
+ * 4. Wraps result in BlokResponse
77
+ * 5. Maps any errors to GlobalError
78
+ */
79
+ handle(ctx: Context, inputs: z.infer<TInput> | JsonLikeObject | Condition[]): Promise<IBlokResponse | BlokService<z.infer<TInput>>[]>;
80
+ /**
81
+ * Maps any error to GlobalError, with special handling for ZodError
82
+ *
83
+ * ZodError produces detailed validation errors that are transformed into
84
+ * a user-friendly error message with all validation issues listed.
85
+ *
86
+ * @param error - Any error thrown during execution
87
+ * @returns GlobalError instance
88
+ */
89
+ private mapErrorToGlobalError;
90
+ /**
91
+ * Converts ZodError to GlobalError with detailed validation messages
92
+ *
93
+ * Example output:
94
+ * "Validation failed: userId (expected string, received undefined),
95
+ * email (invalid email format)"
96
+ *
97
+ * @param zodError - Zod validation error
98
+ * @returns GlobalError with formatted validation messages
99
+ */
100
+ private zodErrorToGlobalError;
101
+ /**
102
+ * Converts Zod schema to JSON Schema for backward compatibility
103
+ *
104
+ * This is a simplified conversion that covers basic types.
105
+ * For production use, consider using zod-to-json-schema library.
106
+ *
107
+ * @param zodSchema - Zod schema to convert
108
+ * @returns JSON Schema representation
109
+ */
110
+ private zodToJsonSchema;
111
+ }
112
+ /**
113
+ * Define a function-first node with Zod schema validation
114
+ *
115
+ * This is the main API for creating modern, type-safe nodes in Blok.
116
+ *
117
+ * Benefits over class-based nodes:
118
+ * - 60%+ less boilerplate code
119
+ * - Type-safe inputs and outputs via Zod
120
+ * - Automatic validation
121
+ * - Better AI generation success rates
122
+ * - Easier to test and maintain
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * import { defineNode } from "@blokjs/runner";
127
+ * import { z } from "zod";
128
+ *
129
+ * export default defineNode({
130
+ * name: "fetch-user",
131
+ * description: "Fetches user by ID from database",
132
+ *
133
+ * input: z.object({
134
+ * userId: z.string().uuid(),
135
+ * }),
136
+ *
137
+ * output: z.object({
138
+ * user: z.object({
139
+ * id: z.string(),
140
+ * name: z.string(),
141
+ * email: z.string().email(),
142
+ * }),
143
+ * }),
144
+ *
145
+ * async execute(ctx, input) {
146
+ * const user = await db.users.findById(input.userId);
147
+ * return { user };
148
+ * },
149
+ * });
150
+ * ```
151
+ *
152
+ * @param definition - Node definition with Zod schemas
153
+ * @returns FunctionNode instance compatible with existing runner
154
+ */
155
+ export declare function defineNode<TInput extends z.ZodTypeAny, TOutput extends z.ZodTypeAny>(definition: FnNodeDefinition<TInput, TOutput>): FunctionNode<TInput, TOutput>;