@blokjs/runner 0.2.1 → 0.2.2

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 (80) hide show
  1. package/dist/Blok.js +11 -11
  2. package/dist/Blok.js.map +1 -1
  3. package/dist/Configuration.d.ts +21 -2
  4. package/dist/Configuration.js +188 -26
  5. package/dist/Configuration.js.map +1 -1
  6. package/dist/ConfigurationResolver.d.ts +9 -0
  7. package/dist/ConfigurationResolver.js +17 -1
  8. package/dist/ConfigurationResolver.js.map +1 -1
  9. package/dist/RunnerSteps.js +52 -9
  10. package/dist/RunnerSteps.js.map +1 -1
  11. package/dist/RuntimeAdapterNode.d.ts +32 -2
  12. package/dist/RuntimeAdapterNode.js +122 -27
  13. package/dist/RuntimeAdapterNode.js.map +1 -1
  14. package/dist/TriggerBase.js +35 -2
  15. package/dist/TriggerBase.js.map +1 -1
  16. package/dist/adapters/BunRuntimeAdapter.d.ts +1 -0
  17. package/dist/adapters/BunRuntimeAdapter.js +1 -0
  18. package/dist/adapters/BunRuntimeAdapter.js.map +1 -1
  19. package/dist/adapters/DockerRuntimeAdapter.d.ts +2 -1
  20. package/dist/adapters/DockerRuntimeAdapter.js +10 -1
  21. package/dist/adapters/DockerRuntimeAdapter.js.map +1 -1
  22. package/dist/adapters/HttpRuntimeAdapter.d.ts +26 -5
  23. package/dist/adapters/HttpRuntimeAdapter.js +97 -16
  24. package/dist/adapters/HttpRuntimeAdapter.js.map +1 -1
  25. package/dist/adapters/NodeJsRuntimeAdapter.d.ts +1 -0
  26. package/dist/adapters/NodeJsRuntimeAdapter.js +1 -0
  27. package/dist/adapters/NodeJsRuntimeAdapter.js.map +1 -1
  28. package/dist/adapters/RuntimeAdapter.d.ts +17 -0
  29. package/dist/adapters/WasmRuntimeAdapter.d.ts +1 -0
  30. package/dist/adapters/WasmRuntimeAdapter.js +1 -0
  31. package/dist/adapters/WasmRuntimeAdapter.js.map +1 -1
  32. package/dist/adapters/grpc/GrpcChannelOptions.d.ts +31 -0
  33. package/dist/adapters/grpc/GrpcChannelOptions.js +68 -0
  34. package/dist/adapters/grpc/GrpcChannelOptions.js.map +1 -0
  35. package/dist/adapters/grpc/GrpcClientPool.d.ts +43 -0
  36. package/dist/adapters/grpc/GrpcClientPool.js +89 -0
  37. package/dist/adapters/grpc/GrpcClientPool.js.map +1 -0
  38. package/dist/adapters/grpc/GrpcCodec.d.ts +226 -0
  39. package/dist/adapters/grpc/GrpcCodec.js +275 -0
  40. package/dist/adapters/grpc/GrpcCodec.js.map +1 -0
  41. package/dist/adapters/grpc/GrpcErrors.d.ts +59 -0
  42. package/dist/adapters/grpc/GrpcErrors.js +190 -0
  43. package/dist/adapters/grpc/GrpcErrors.js.map +1 -0
  44. package/dist/adapters/grpc/GrpcHealthChecker.d.ts +69 -0
  45. package/dist/adapters/grpc/GrpcHealthChecker.js +96 -0
  46. package/dist/adapters/grpc/GrpcHealthChecker.js.map +1 -0
  47. package/dist/adapters/grpc/GrpcRuntimeAdapter.d.ts +98 -0
  48. package/dist/adapters/grpc/GrpcRuntimeAdapter.js +478 -0
  49. package/dist/adapters/grpc/GrpcRuntimeAdapter.js.map +1 -0
  50. package/dist/adapters/grpc/index.d.ts +13 -0
  51. package/dist/adapters/grpc/index.js +14 -0
  52. package/dist/adapters/grpc/index.js.map +1 -0
  53. package/dist/adapters/grpc/proto/blok/runtime/v1/runtime.proto +302 -0
  54. package/dist/adapters/grpc/types.d.ts +97 -0
  55. package/dist/adapters/grpc/types.js +41 -0
  56. package/dist/adapters/grpc/types.js.map +1 -0
  57. package/dist/adapters/transport.d.ts +108 -0
  58. package/dist/adapters/transport.js +196 -0
  59. package/dist/adapters/transport.js.map +1 -0
  60. package/dist/index.d.ts +13 -1
  61. package/dist/index.js +14 -0
  62. package/dist/index.js.map +1 -1
  63. package/dist/testing/WorkflowTestRunner.js +12 -0
  64. package/dist/testing/WorkflowTestRunner.js.map +1 -1
  65. package/dist/tracing/RunTracker.d.ts +23 -2
  66. package/dist/tracing/RunTracker.js +120 -10
  67. package/dist/tracing/RunTracker.js.map +1 -1
  68. package/dist/tracing/SqliteRunStore.js +19 -3
  69. package/dist/tracing/SqliteRunStore.js.map +1 -1
  70. package/dist/tracing/TraceRouter.js +245 -4
  71. package/dist/tracing/TraceRouter.js.map +1 -1
  72. package/dist/tracing/types.d.ts +82 -10
  73. package/dist/types/GlobalOptions.d.ts +9 -2
  74. package/dist/workflow/PersistenceHelper.d.ts +46 -0
  75. package/dist/workflow/PersistenceHelper.js +57 -0
  76. package/dist/workflow/PersistenceHelper.js.map +1 -0
  77. package/dist/workflow/WorkflowNormalizer.d.ts +91 -0
  78. package/dist/workflow/WorkflowNormalizer.js +304 -0
  79. package/dist/workflow/WorkflowNormalizer.js.map +1 -0
  80. package/package.json +8 -5
@@ -0,0 +1,302 @@
1
+ // Blok Runtime v1 — the wire contract between the TypeScript runner and SDK
2
+ // servers (Python, Go, Rust, Java, C#, PHP, Ruby).
3
+ //
4
+ // Single source of truth for cross-language interop. Generated stubs in each
5
+ // SDK are derived from this file via `make proto`.
6
+ //
7
+ // Stability: `blok.runtime.v1` is additive-only. CI runs `buf breaking` to
8
+ // reject backward-incompatible changes. Breaking changes go to `v2`, served
9
+ // alongside `v1` during migration.
10
+
11
+ syntax = "proto3";
12
+
13
+ package blok.runtime.v1;
14
+
15
+ option go_package = "github.com/nickincloud/blok-go/genpb/blok/runtime/v1;runtimev1";
16
+ option java_package = "com.blok.runtime.v1";
17
+ option java_multiple_files = true;
18
+ option csharp_namespace = "Blok.Runtime.V1";
19
+ option php_namespace = "Blok\\Runtime\\V1";
20
+ option ruby_package = "Blok::Runtime::V1";
21
+
22
+ import "google/protobuf/timestamp.proto";
23
+
24
+ // =============================================================================
25
+ // Service
26
+ // =============================================================================
27
+
28
+ // NodeRuntime is the contract every Blok SDK exposes. One service handles
29
+ // three responsibilities:
30
+ // 1. Run a node (Execute / ExecuteStream)
31
+ // 2. Tell the runner which nodes it can run (ListNodes)
32
+ // 3. Tell the runner if it is alive (Health)
33
+ service NodeRuntime {
34
+ // Run a node and return its result. Unary, deadline-driven.
35
+ rpc Execute (ExecuteRequest) returns (ExecuteResponse);
36
+
37
+ // Run a node and stream events back as it executes (logs, progress, partial
38
+ // results, then a final ExecuteResponse). Optional capability — SDKs that
39
+ // don't implement it should return UNIMPLEMENTED.
40
+ rpc ExecuteStream (ExecuteRequest) returns (stream ExecuteEvent);
41
+
42
+ // Health check (wire-compatible with grpc.health.v1.Health/Check).
43
+ rpc Health (HealthRequest) returns (HealthResponse);
44
+
45
+ // Discover registered nodes and their schemas (drives Studio + OpenAPI gen).
46
+ rpc ListNodes (ListNodesRequest) returns (ListNodesResponse);
47
+ }
48
+
49
+ // =============================================================================
50
+ // Execute envelope (the "what we send to a node")
51
+ // =============================================================================
52
+
53
+ message ExecuteRequest {
54
+ // Identification: which node, what type, what version.
55
+ NodeRef node = 1;
56
+
57
+ // The node's own resolved inputs. Already mapped (js/, ${...} resolved).
58
+ // Bytes-encoded JSON: SDKs JSON-decode lazily. NEVER wrapped in {inputs:...}.
59
+ bytes inputs = 2;
60
+
61
+ // Where in the workflow this node sits.
62
+ StepInfo step = 3;
63
+
64
+ // The originating workflow trigger (read-only context for nodes).
65
+ TriggerInfo trigger = 4;
66
+
67
+ // Mutable state: previous step output, persistent vars, env mirror.
68
+ RuntimeState state = 5;
69
+
70
+ // Identity of the parent workflow run.
71
+ WorkflowInfo workflow = 6;
72
+
73
+ // Per-call options (deadline, streaming opt-in).
74
+ ExecuteOptions options = 7;
75
+ }
76
+
77
+ message NodeRef {
78
+ string name = 1; // e.g. "tutorial-store"
79
+ string type = 2; // "runtime.python3"
80
+ string version = 3; // optional pin, e.g. "1.0.0"
81
+ }
82
+
83
+ message StepInfo {
84
+ string name = 1; // step name in workflow
85
+ int32 index = 2; // 0-based index in current branch
86
+ int32 total = 3; // total steps in current branch
87
+ int32 depth = 4; // 0 = top-level; 1+ = nested in flow node (if-else)
88
+ }
89
+
90
+ message TriggerInfo {
91
+ // Snapshot of the trigger that started the workflow. Read-only for nodes.
92
+ bytes body = 1; // raw bytes; encoding signaled in headers
93
+ map<string, string> headers = 2;
94
+ map<string, string> params = 3;
95
+ map<string, string> query = 4;
96
+ map<string, string> cookies = 5;
97
+ string method = 6;
98
+ string url = 7;
99
+ string base_url = 8;
100
+ string trigger_kind = 9; // "http" | "worker" | "cron" | ...
101
+ }
102
+
103
+ message RuntimeState {
104
+ // Output of the previous step. Named explicitly so LLM-authored nodes stop
105
+ // confusing it with vars. Bytes-encoded JSON.
106
+ bytes previous_output = 1;
107
+
108
+ // Workflow-scoped persistent storage (set_var: true on prior steps).
109
+ // Bytes-encoded JSON map<string, any>.
110
+ bytes vars = 2;
111
+
112
+ // String→string env mirror.
113
+ map<string, string> env = 3;
114
+ }
115
+
116
+ message WorkflowInfo {
117
+ string run_id = 1;
118
+ string name = 2;
119
+ string path = 3;
120
+ string version = 4;
121
+ google.protobuf.Timestamp started_at = 5;
122
+ }
123
+
124
+ message ExecuteOptions {
125
+ int64 deadline_ms = 1; // hard cutoff (also enforced via gRPC deadline)
126
+ bool stream_logs = 2; // hint: caller wants ExecuteStream events
127
+ bool capture_metrics = 3;
128
+ // Reserved for future routing/affinity hints without bumping schema.
129
+ map<string, string> hints = 15;
130
+ }
131
+
132
+ // =============================================================================
133
+ // Execute response
134
+ // =============================================================================
135
+
136
+ message ExecuteResponse {
137
+ bool success = 1;
138
+
139
+ // The node's primary return value. Bytes-encoded JSON.
140
+ bytes data = 2;
141
+
142
+ // Optional content-type override (default "application/json").
143
+ string content_type = 3;
144
+
145
+ // Set iff !success. Always populated on failure (see NodeError).
146
+ NodeError error = 4;
147
+
148
+ // Vars the node wants persisted (merged into ctx.vars on the runner side).
149
+ // Optional — most nodes leave this empty and rely on workflow-level set_var.
150
+ // Bytes-encoded JSON map<string, any>.
151
+ bytes vars_delta = 5;
152
+
153
+ // Tail of logs captured during execution.
154
+ repeated LogLine logs = 6;
155
+
156
+ // Resource usage during this call. Populated when capture_metrics=true.
157
+ Metrics metrics = 7;
158
+ }
159
+
160
+ // =============================================================================
161
+ // Streaming variant (Phase 5 — opt-in)
162
+ // =============================================================================
163
+
164
+ message ExecuteEvent {
165
+ oneof event {
166
+ NodeStarted started = 1;
167
+ LogLine log = 2;
168
+ Progress progress = 3;
169
+ PartialResult partial = 4;
170
+ ExecuteResponse final = 5; // last frame; closes the stream
171
+ }
172
+ }
173
+
174
+ message NodeStarted { google.protobuf.Timestamp at = 1; }
175
+ message Progress { double percent = 1; string phase = 2; }
176
+ message PartialResult { bytes snapshot_json = 1; }
177
+
178
+ message LogLine {
179
+ google.protobuf.Timestamp timestamp = 1;
180
+ string level = 2; // "debug" | "info" | "warn" | "error"
181
+ string message = 3;
182
+ map<string, string> attributes = 4;
183
+ }
184
+
185
+ // =============================================================================
186
+ // NodeError — the structured-errors contract
187
+ // =============================================================================
188
+ //
189
+ // Every node in every SDK populates a NodeError the same way. Seven required
190
+ // fields (code, category, severity, node, at, message, http_status) plus
191
+ // strongly-encouraged fields for richer debugging:
192
+ // - description: multi-paragraph context (what was tried, why it failed)
193
+ // - remediation: suggested next step (actionable)
194
+ // - context_snapshot_json: bounded slice of inputs/state at error time
195
+ // - causes: nested wrapped errors (e.g. an HTTP error wrapping a timeout)
196
+ //
197
+ // SDKs auto-fill `node`, `sdk`, `sdk_version`, `runtime_kind`, `at`, and
198
+ // `stack` from environmental context — authors never set these manually.
199
+ //
200
+ // See `docs/error-codes.md` for the canonical code registry.
201
+
202
+ message NodeError {
203
+ // === Identity ===
204
+ string code = 1; // STABLE machine identifier (e.g. "POSTGRES_CONNECT_TIMEOUT")
205
+ ErrorCategory category = 2;
206
+ ErrorSeverity severity = 3;
207
+
208
+ // === Origin (auto-filled by SDK) ===
209
+ string node = 4;
210
+ string sdk = 5; // "blok-python3"
211
+ string sdk_version = 6;
212
+ string runtime_kind = 7; // "runtime.python3"
213
+ google.protobuf.Timestamp at = 8;
214
+
215
+ // === Human-readable ===
216
+ string message = 9; // one-sentence summary
217
+ string description = 10; // multi-paragraph context
218
+ string remediation = 11; // suggested next step
219
+ string doc_url = 12;
220
+
221
+ // === Causality ===
222
+ repeated NodeError causes = 13;
223
+ string stack = 14;
224
+ bytes context_snapshot_json = 15;
225
+
226
+ // === Compatibility / retry hints ===
227
+ int32 http_status = 16;
228
+ bool retryable = 17;
229
+ int64 retry_after_ms = 18;
230
+
231
+ // === Category-specific structured details ===
232
+ // Bytes-encoded JSON. Surfaces to GlobalError.json on the runner side.
233
+ bytes details_json = 19;
234
+ }
235
+
236
+ enum ErrorCategory {
237
+ CATEGORY_UNSPECIFIED = 0;
238
+ VALIDATION = 1; // input/output schema mismatch
239
+ CONFIGURATION = 2; // node misconfigured
240
+ DEPENDENCY = 3; // external service failed (DB, HTTP, queue)
241
+ TIMEOUT = 4;
242
+ PERMISSION = 5; // auth/authz
243
+ RATE_LIMIT = 6;
244
+ NOT_FOUND = 7;
245
+ CONFLICT = 8;
246
+ CANCELLED = 9;
247
+ INTERNAL = 10; // unexpected SDK-side bug
248
+ PROTOCOL = 11; // proto/transport issue
249
+ DATA = 12; // user data malformed (not schema validation)
250
+ }
251
+
252
+ enum ErrorSeverity {
253
+ SEVERITY_UNSPECIFIED = 0;
254
+ INFO = 1; // expected, recoverable
255
+ WARN = 2; // anomalous but workflow continues
256
+ ERROR = 3; // node failed; default
257
+ FATAL = 4; // workflow should abort regardless of try/catch
258
+ }
259
+
260
+ // =============================================================================
261
+ // Discovery
262
+ // =============================================================================
263
+
264
+ message ListNodesRequest {}
265
+ message ListNodesResponse {
266
+ repeated NodeDescriptor nodes = 1;
267
+ string sdk_name = 2; // "blok-python3"
268
+ string sdk_version = 3;
269
+ string proto_version = 4; // "1.0.0"
270
+ }
271
+
272
+ message NodeDescriptor {
273
+ string name = 1;
274
+ string description = 2;
275
+ bytes input_schema_json = 3; // JSON Schema (drives OpenAPI/Studio/LLMs)
276
+ bytes output_schema_json = 4;
277
+ repeated string tags = 5;
278
+ }
279
+
280
+ // =============================================================================
281
+ // Health (wire-compatible with grpc.health.v1)
282
+ // =============================================================================
283
+
284
+ message HealthRequest { string service = 1; }
285
+ message HealthResponse {
286
+ enum Status { UNKNOWN = 0; SERVING = 1; NOT_SERVING = 2; }
287
+ Status status = 1;
288
+ string sdk_version = 2;
289
+ repeated string registered_nodes = 3;
290
+ }
291
+
292
+ // =============================================================================
293
+ // Metrics
294
+ // =============================================================================
295
+
296
+ message Metrics {
297
+ double duration_ms = 1;
298
+ double cpu_ms = 2;
299
+ int64 memory_bytes = 3;
300
+ int64 request_bytes = 4;
301
+ int64 response_bytes = 5;
302
+ }
@@ -0,0 +1,97 @@
1
+ import type { RuntimeKind } from "../RuntimeAdapter";
2
+ /**
3
+ * Selectable transport between the runner and an SDK runtime.
4
+ *
5
+ * - `http` — legacy `HttpRuntimeAdapter` (POST /execute over JSON+HTTP/1).
6
+ * - `grpc` — `GrpcRuntimeAdapter` (NodeRuntime/Execute over HTTP/2 + protobuf).
7
+ */
8
+ export type Transport = "http" | "grpc";
9
+ /**
10
+ * Configuration for a {@link GrpcRuntimeAdapter} instance.
11
+ *
12
+ * Fully `readonly` — adapters never mutate their config after construction.
13
+ */
14
+ export interface GrpcAdapterConfig {
15
+ readonly kind: RuntimeKind;
16
+ readonly host: string;
17
+ readonly port: number;
18
+ readonly defaultDeadlineMs: number;
19
+ readonly maxMessageBytes: number;
20
+ readonly keepalive: KeepaliveConfig;
21
+ readonly tls?: TlsConfig;
22
+ /** Optional gRPC service config JSON for retries on the Health RPC. */
23
+ readonly serviceConfigJson?: string;
24
+ /**
25
+ * Background health-check polling interval in ms. Set to `0` to disable
26
+ * (useful in tests so timers don't leak). Defaults to
27
+ * {@link GRPC_DEFAULTS.HEALTH_INTERVAL_MS}.
28
+ */
29
+ readonly healthCheckIntervalMs?: number;
30
+ /**
31
+ * Number of consecutive Health/Check failures that opens the circuit
32
+ * (subsequent `execute()` / `executeStream()` calls fail fast with a
33
+ * `BlokError(category=DEPENDENCY)` instead of dialing). Defaults to
34
+ * {@link GRPC_DEFAULTS.HEALTH_FAILURE_THRESHOLD}.
35
+ */
36
+ readonly healthCheckFailureThreshold?: number;
37
+ }
38
+ /**
39
+ * Keepalive ping configuration. gRPC sends periodic HTTP/2 PING frames so
40
+ * idle connections don't drop and so connection failures surface within
41
+ * `timeoutMs` instead of after the OS TCP timeout (~minutes).
42
+ */
43
+ export interface KeepaliveConfig {
44
+ /** Interval between keepalive pings in ms. */
45
+ readonly timeMs: number;
46
+ /** Wait for ping ack within this many ms before considering the connection dead. */
47
+ readonly timeoutMs: number;
48
+ /** Send keepalives even when no calls are in flight. */
49
+ readonly permitWithoutCalls: boolean;
50
+ }
51
+ /**
52
+ * TLS / mTLS configuration. When omitted, the channel is plaintext (loopback
53
+ * only — `BLOK_GRPC_REQUIRE_TLS=true` enforces TLS for non-loopback).
54
+ */
55
+ export interface TlsConfig {
56
+ /** Path to a CA certificate (PEM) for verifying the server. */
57
+ readonly caCertPath?: string;
58
+ /** Path to a client certificate (PEM) for mTLS. */
59
+ readonly clientCertPath?: string;
60
+ /** Path to a client private key (PEM) for mTLS. */
61
+ readonly clientKeyPath?: string;
62
+ /** Override the SNI hostname sent during TLS handshake. */
63
+ readonly serverNameOverride?: string;
64
+ /**
65
+ * Skip server certificate verification. **Development only** — adapters
66
+ * log a warning at startup when this is true.
67
+ */
68
+ readonly insecureSkipVerify?: boolean;
69
+ }
70
+ /**
71
+ * Default values for gRPC channel options.
72
+ *
73
+ * Single source of truth — referenced from {@link loadGrpcConfigFromEnv} and
74
+ * the channel-options module. No magic numbers anywhere else.
75
+ */
76
+ export declare const GRPC_DEFAULTS: {
77
+ /** Default per-call deadline (matches today's HTTP `AbortSignal.timeout(30000)`). */
78
+ readonly DEFAULT_DEADLINE_MS: 30000;
79
+ /** Default 16MB max message size (matches the PHP `RequestBodyBuffer` ceiling from FIXES.md #5). */
80
+ readonly MAX_MESSAGE_BYTES: number;
81
+ /** Default keepalive ping interval. */
82
+ readonly KEEPALIVE_TIME_MS: 10000;
83
+ /** Default keepalive ack timeout. */
84
+ readonly KEEPALIVE_TIMEOUT_MS: 5000;
85
+ /** Send keepalives even with no in-flight calls — keeps connections warm. */
86
+ readonly KEEPALIVE_PERMIT_WITHOUT_CALLS: true;
87
+ /** Health probe interval. */
88
+ readonly HEALTH_INTERVAL_MS: 30000;
89
+ /** Consecutive Health failures that trip the circuit breaker. */
90
+ readonly HEALTH_FAILURE_THRESHOLD: 3;
91
+ };
92
+ /**
93
+ * Default port mapping per language. We use `HTTP_PORT + 1000` for symmetry
94
+ * with the existing HTTP ports (9001–9007 → 10001–10007). Operators can
95
+ * override per language via `RUNTIME_<KIND>_GRPC_PORT`.
96
+ */
97
+ export declare const DEFAULT_GRPC_PORTS: Readonly<Record<RuntimeKind, number>>;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Default values for gRPC channel options.
3
+ *
4
+ * Single source of truth — referenced from {@link loadGrpcConfigFromEnv} and
5
+ * the channel-options module. No magic numbers anywhere else.
6
+ */
7
+ export const GRPC_DEFAULTS = {
8
+ /** Default per-call deadline (matches today's HTTP `AbortSignal.timeout(30000)`). */
9
+ DEFAULT_DEADLINE_MS: 30_000,
10
+ /** Default 16MB max message size (matches the PHP `RequestBodyBuffer` ceiling from FIXES.md #5). */
11
+ MAX_MESSAGE_BYTES: 16 * 1024 * 1024,
12
+ /** Default keepalive ping interval. */
13
+ KEEPALIVE_TIME_MS: 10_000,
14
+ /** Default keepalive ack timeout. */
15
+ KEEPALIVE_TIMEOUT_MS: 5_000,
16
+ /** Send keepalives even with no in-flight calls — keeps connections warm. */
17
+ KEEPALIVE_PERMIT_WITHOUT_CALLS: true,
18
+ /** Health probe interval. */
19
+ HEALTH_INTERVAL_MS: 30_000,
20
+ /** Consecutive Health failures that trip the circuit breaker. */
21
+ HEALTH_FAILURE_THRESHOLD: 3,
22
+ };
23
+ /**
24
+ * Default port mapping per language. We use `HTTP_PORT + 1000` for symmetry
25
+ * with the existing HTTP ports (9001–9007 → 10001–10007). Operators can
26
+ * override per language via `RUNTIME_<KIND>_GRPC_PORT`.
27
+ */
28
+ export const DEFAULT_GRPC_PORTS = {
29
+ nodejs: 0, // in-process; no port
30
+ bun: 0,
31
+ go: 10001,
32
+ rust: 10002,
33
+ java: 10003,
34
+ csharp: 10004,
35
+ php: 10005,
36
+ ruby: 10006,
37
+ python3: 10007,
38
+ docker: 0,
39
+ wasm: 0,
40
+ };
41
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/adapters/grpc/types.ts"],"names":[],"mappings":"AA0EA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC5B,qFAAqF;IACrF,mBAAmB,EAAE,MAAM;IAC3B,oGAAoG;IACpG,iBAAiB,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;IACnC,uCAAuC;IACvC,iBAAiB,EAAE,MAAM;IACzB,qCAAqC;IACrC,oBAAoB,EAAE,KAAK;IAC3B,6EAA6E;IAC7E,8BAA8B,EAAE,IAAI;IACpC,6BAA6B;IAC7B,kBAAkB,EAAE,MAAM;IAC1B,iEAAiE;IACjE,wBAAwB,EAAE,CAAC;CAClB,CAAC;AAEX;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAA0C;IACxE,MAAM,EAAE,CAAC,EAAE,sBAAsB;IACjC,GAAG,EAAE,CAAC;IACN,EAAE,EAAE,KAAK;IACT,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,KAAK;IACX,MAAM,EAAE,KAAK;IACb,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,KAAK;IACd,MAAM,EAAE,CAAC;IACT,IAAI,EAAE,CAAC;CACP,CAAC"}
@@ -0,0 +1,108 @@
1
+ import type { RuntimeKind } from "./RuntimeAdapter";
2
+ import type { TlsConfig, Transport } from "./grpc/types";
3
+ /**
4
+ * Resolve the transport to use for a given runtime kind from the environment.
5
+ *
6
+ * Precedence (most specific wins):
7
+ * 1. `RUNTIME_<KIND>_TRANSPORT` — per-kind override
8
+ * e.g. `RUNTIME_PYTHON3_TRANSPORT=http` to opt one SDK out of gRPC.
9
+ * 2. `RUNTIME_TRANSPORT` — global override
10
+ * e.g. `RUNTIME_TRANSPORT=http` to roll back the whole runner.
11
+ * 3. The hard-coded default — **`grpc`** as of Phase 6 (master plan §11).
12
+ * Flipped from `http` to `grpc` after the cross-language parity matrix
13
+ * (`bun run test:parity`, 33 tests across 6 SDKs × 5 workflows) and
14
+ * the per-SDK §17 BlokError E2E suites stayed green for the full
15
+ * Phase 5 observation window.
16
+ *
17
+ * Pure function — reads `process.env` once per call so tests can override.
18
+ *
19
+ * # Why the default flip is safe
20
+ *
21
+ * - HTTP transport remains available behind `RUNTIME_TRANSPORT=http` for at
22
+ * least two minor versions (master plan §11 commitment).
23
+ * - PHP without RoadRunner (Path B from §16) sets
24
+ * `RUNTIME_PHP_TRANSPORT=http` per host. The forever-supported escape
25
+ * hatch is unaffected.
26
+ * - SDKs that fail to bind their gRPC listener fall through the
27
+ * {@link GrpcHealthChecker} circuit-breaker and surface a typed
28
+ * `BlokError(category=DEPENDENCY)` per §9 — no silent failure.
29
+ *
30
+ * @param kind The runtime kind (e.g. "python3").
31
+ * @param env Optional env source (defaults to `process.env`). Tests can
32
+ * pass a stub map.
33
+ * @returns Either `"http"` or `"grpc"`. Invalid values fall back to the
34
+ * Phase 6 default (`grpc`).
35
+ */
36
+ export declare function resolveTransportForKind(kind: RuntimeKind, env?: NodeJS.ProcessEnv): Transport;
37
+ /**
38
+ * Test-only — reset the per-process HTTP-transport deprecation cache so a
39
+ * test that flips `RUNTIME_TRANSPORT=http` can re-assert the warning fires.
40
+ *
41
+ * @internal
42
+ */
43
+ export declare function _resetHttpDeprecationCache(): void;
44
+ /**
45
+ * Whether log streaming is enabled for runtime nodes. When true, the runner
46
+ * routes runtime nodes through `GrpcRuntimeAdapter.executeStream` instead of
47
+ * the unary `execute`, and `LogLine` frames flow into `RunTracker.addLog`
48
+ * — surfacing live in Studio's `/__blok/runs/:id/stream` SSE endpoint.
49
+ *
50
+ * Streaming is a pure additive capability: when the env var is unset, the
51
+ * legacy unary path runs unchanged. When enabled but the adapter doesn't
52
+ * support streaming (e.g. HttpRuntimeAdapter), `RuntimeAdapterNode` falls
53
+ * back to unary so misconfiguration never blocks execution.
54
+ *
55
+ * Recognized as truthy: `1`, `true`, `yes`, `on` (case-insensitive). Anything
56
+ * else (including unset, empty, `0`, `false`) returns false.
57
+ */
58
+ export declare function isStreamLogsEnabled(env?: NodeJS.ProcessEnv): boolean;
59
+ /**
60
+ * Resolve the gRPC background health-check interval from the environment.
61
+ *
62
+ * `BLOK_GRPC_HEALTH_INTERVAL_MS` is the global override:
63
+ * - any positive integer → use that interval
64
+ * - `0` → disable the loop entirely (useful in tests)
65
+ * - unset / non-numeric → return undefined; adapter uses
66
+ * {@link GRPC_DEFAULTS.HEALTH_INTERVAL_MS}.
67
+ */
68
+ export declare function resolveHealthCheckIntervalMs(env?: NodeJS.ProcessEnv): number | undefined;
69
+ /**
70
+ * Resolve the consecutive-failure threshold for the gRPC circuit breaker.
71
+ *
72
+ * `BLOK_GRPC_HEALTH_FAILURE_THRESHOLD` overrides the default
73
+ * ({@link GRPC_DEFAULTS.HEALTH_FAILURE_THRESHOLD}). Values < 1 are ignored
74
+ * (the checker requires ≥ 1 failure to trip).
75
+ */
76
+ export declare function resolveHealthCheckFailureThreshold(env?: NodeJS.ProcessEnv): number | undefined;
77
+ /**
78
+ * Build a {@link TlsConfig} for a given runtime kind from environment
79
+ * variables. Returns `undefined` when nothing is configured (channel stays
80
+ * plaintext — appropriate for loopback dev).
81
+ *
82
+ * Per-kind env vars (taking precedence):
83
+ * - `RUNTIME_<KIND>_TLS_CA` CA cert path (PEM)
84
+ * - `RUNTIME_<KIND>_TLS_CLIENT_CERT` client cert path (PEM, mTLS)
85
+ * - `RUNTIME_<KIND>_TLS_CLIENT_KEY` client key path (PEM, mTLS)
86
+ * - `RUNTIME_<KIND>_TLS_SERVER_NAME` SNI override
87
+ * - `RUNTIME_<KIND>_TLS_INSECURE_SKIP_VERIFY=true` dev-only
88
+ *
89
+ * Global fallbacks (apply when the per-kind var is unset):
90
+ * - `BLOK_GRPC_TLS_CA`, `BLOK_GRPC_TLS_CLIENT_CERT`, `BLOK_GRPC_TLS_CLIENT_KEY`,
91
+ * `BLOK_GRPC_TLS_SERVER_NAME`, `BLOK_GRPC_TLS_INSECURE_SKIP_VERIFY`.
92
+ *
93
+ * If none of the relevant env vars are set, returns `undefined`.
94
+ */
95
+ export declare function loadTlsConfigForKind(kind: RuntimeKind, env?: NodeJS.ProcessEnv): TlsConfig | undefined;
96
+ /**
97
+ * Whether `BLOK_GRPC_REQUIRE_TLS=true` enforces TLS on non-loopback hosts.
98
+ * When true, building a gRPC adapter with no TLS config against a non-loopback
99
+ * host throws at startup. Loopback (localhost, 127.0.0.0/8, ::1) is exempted.
100
+ */
101
+ export declare function isStrictTlsEnabled(env?: NodeJS.ProcessEnv): boolean;
102
+ /**
103
+ * Returns true when the host is a loopback address that doesn't require
104
+ * TLS even under strict mode. Match is intentionally generous — covers
105
+ * `localhost`, the 127.x range, IPv6 loopback, and the wildcard 0.0.0.0
106
+ * (which dev SDKs commonly bind to).
107
+ */
108
+ export declare function isLoopbackHost(host: string): boolean;