@blokjs/runner 0.2.1 → 0.4.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.
- package/dist/Blok.js +11 -11
- package/dist/Blok.js.map +1 -1
- package/dist/Configuration.d.ts +39 -2
- package/dist/Configuration.js +337 -28
- package/dist/Configuration.js.map +1 -1
- package/dist/ConfigurationResolver.d.ts +9 -0
- package/dist/ConfigurationResolver.js +17 -1
- package/dist/ConfigurationResolver.js.map +1 -1
- package/dist/PayloadTooLargeError.d.ts +19 -0
- package/dist/PayloadTooLargeError.js +29 -0
- package/dist/PayloadTooLargeError.js.map +1 -0
- package/dist/RunCancelledError.d.ts +17 -0
- package/dist/RunCancelledError.js +25 -0
- package/dist/RunCancelledError.js.map +1 -0
- package/dist/RunnerSteps.js +363 -23
- package/dist/RunnerSteps.js.map +1 -1
- package/dist/RuntimeAdapterNode.d.ts +32 -2
- package/dist/RuntimeAdapterNode.js +122 -27
- package/dist/RuntimeAdapterNode.js.map +1 -1
- package/dist/SubworkflowNode.d.ts +75 -0
- package/dist/SubworkflowNode.js +221 -0
- package/dist/SubworkflowNode.js.map +1 -0
- package/dist/TriggerBase.d.ts +128 -0
- package/dist/TriggerBase.js +808 -6
- package/dist/TriggerBase.js.map +1 -1
- package/dist/WaitDispatchRequest.d.ts +38 -0
- package/dist/WaitDispatchRequest.js +13 -0
- package/dist/WaitDispatchRequest.js.map +1 -0
- package/dist/WaitNode.d.ts +23 -0
- package/dist/WaitNode.js +26 -0
- package/dist/WaitNode.js.map +1 -0
- package/dist/adapters/BunRuntimeAdapter.d.ts +1 -0
- package/dist/adapters/BunRuntimeAdapter.js +1 -0
- package/dist/adapters/BunRuntimeAdapter.js.map +1 -1
- package/dist/adapters/DockerRuntimeAdapter.d.ts +2 -1
- package/dist/adapters/DockerRuntimeAdapter.js +10 -1
- package/dist/adapters/DockerRuntimeAdapter.js.map +1 -1
- package/dist/adapters/HttpRuntimeAdapter.d.ts +26 -5
- package/dist/adapters/HttpRuntimeAdapter.js +97 -16
- package/dist/adapters/HttpRuntimeAdapter.js.map +1 -1
- package/dist/adapters/NodeJsRuntimeAdapter.d.ts +1 -0
- package/dist/adapters/NodeJsRuntimeAdapter.js +1 -0
- package/dist/adapters/NodeJsRuntimeAdapter.js.map +1 -1
- package/dist/adapters/RuntimeAdapter.d.ts +17 -0
- package/dist/adapters/WasmRuntimeAdapter.d.ts +1 -0
- package/dist/adapters/WasmRuntimeAdapter.js +1 -0
- package/dist/adapters/WasmRuntimeAdapter.js.map +1 -1
- package/dist/adapters/grpc/GrpcChannelOptions.d.ts +31 -0
- package/dist/adapters/grpc/GrpcChannelOptions.js +68 -0
- package/dist/adapters/grpc/GrpcChannelOptions.js.map +1 -0
- package/dist/adapters/grpc/GrpcClientPool.d.ts +43 -0
- package/dist/adapters/grpc/GrpcClientPool.js +89 -0
- package/dist/adapters/grpc/GrpcClientPool.js.map +1 -0
- package/dist/adapters/grpc/GrpcCodec.d.ts +226 -0
- package/dist/adapters/grpc/GrpcCodec.js +275 -0
- package/dist/adapters/grpc/GrpcCodec.js.map +1 -0
- package/dist/adapters/grpc/GrpcErrors.d.ts +59 -0
- package/dist/adapters/grpc/GrpcErrors.js +190 -0
- package/dist/adapters/grpc/GrpcErrors.js.map +1 -0
- package/dist/adapters/grpc/GrpcHealthChecker.d.ts +69 -0
- package/dist/adapters/grpc/GrpcHealthChecker.js +96 -0
- package/dist/adapters/grpc/GrpcHealthChecker.js.map +1 -0
- package/dist/adapters/grpc/GrpcRuntimeAdapter.d.ts +98 -0
- package/dist/adapters/grpc/GrpcRuntimeAdapter.js +478 -0
- package/dist/adapters/grpc/GrpcRuntimeAdapter.js.map +1 -0
- package/dist/adapters/grpc/index.d.ts +13 -0
- package/dist/adapters/grpc/index.js +14 -0
- package/dist/adapters/grpc/index.js.map +1 -0
- package/dist/adapters/grpc/proto/blok/runtime/v1/runtime.proto +302 -0
- package/dist/adapters/grpc/types.d.ts +97 -0
- package/dist/adapters/grpc/types.js +41 -0
- package/dist/adapters/grpc/types.js.map +1 -0
- package/dist/adapters/transport.d.ts +108 -0
- package/dist/adapters/transport.js +196 -0
- package/dist/adapters/transport.js.map +1 -0
- package/dist/concurrency/ConcurrencyBackend.d.ts +61 -0
- package/dist/concurrency/ConcurrencyBackend.js +20 -0
- package/dist/concurrency/ConcurrencyBackend.js.map +1 -0
- package/dist/concurrency/ConcurrencyLimitError.d.ts +37 -0
- package/dist/concurrency/ConcurrencyLimitError.js +16 -0
- package/dist/concurrency/ConcurrencyLimitError.js.map +1 -0
- package/dist/concurrency/NatsKvConcurrencyBackend.d.ts +64 -0
- package/dist/concurrency/NatsKvConcurrencyBackend.js +297 -0
- package/dist/concurrency/NatsKvConcurrencyBackend.js.map +1 -0
- package/dist/concurrency/QueueExpiredError.d.ts +40 -0
- package/dist/concurrency/QueueExpiredError.js +15 -0
- package/dist/concurrency/QueueExpiredError.js.map +1 -0
- package/dist/concurrency/createConcurrencyBackend.d.ts +23 -0
- package/dist/concurrency/createConcurrencyBackend.js +34 -0
- package/dist/concurrency/createConcurrencyBackend.js.map +1 -0
- package/dist/concurrency/readConcurrencyConfig.d.ts +60 -0
- package/dist/concurrency/readConcurrencyConfig.js +60 -0
- package/dist/concurrency/readConcurrencyConfig.js.map +1 -0
- package/dist/idempotency/resolveIdempotencyKey.d.ts +20 -0
- package/dist/idempotency/resolveIdempotencyKey.js +37 -0
- package/dist/idempotency/resolveIdempotencyKey.js.map +1 -0
- package/dist/index.d.ts +35 -3
- package/dist/index.js +61 -2
- package/dist/index.js.map +1 -1
- package/dist/monitoring/ConcurrencyMetrics.d.ts +56 -0
- package/dist/monitoring/ConcurrencyMetrics.js +107 -0
- package/dist/monitoring/ConcurrencyMetrics.js.map +1 -0
- package/dist/monitoring/JanitorMetrics.d.ts +27 -0
- package/dist/monitoring/JanitorMetrics.js +48 -0
- package/dist/monitoring/JanitorMetrics.js.map +1 -0
- package/dist/scheduling/DebounceCoordinator.d.ts +88 -0
- package/dist/scheduling/DebounceCoordinator.js +141 -0
- package/dist/scheduling/DebounceCoordinator.js.map +1 -0
- package/dist/scheduling/DeferredDispatchSignal.d.ts +50 -0
- package/dist/scheduling/DeferredDispatchSignal.js +14 -0
- package/dist/scheduling/DeferredDispatchSignal.js.map +1 -0
- package/dist/scheduling/DeferredRunScheduler.d.ts +68 -0
- package/dist/scheduling/DeferredRunScheduler.js +154 -0
- package/dist/scheduling/DeferredRunScheduler.js.map +1 -0
- package/dist/scheduling/readSchedulingConfig.d.ts +24 -0
- package/dist/scheduling/readSchedulingConfig.js +52 -0
- package/dist/scheduling/readSchedulingConfig.js.map +1 -0
- package/dist/testing/WorkflowTestRunner.js +12 -0
- package/dist/testing/WorkflowTestRunner.js.map +1 -1
- package/dist/timeouts/StepTimeoutError.d.ts +22 -0
- package/dist/timeouts/StepTimeoutError.js +31 -0
- package/dist/timeouts/StepTimeoutError.js.map +1 -0
- package/dist/tracing/InMemoryRunStore.d.ts +28 -1
- package/dist/tracing/InMemoryRunStore.js +150 -0
- package/dist/tracing/InMemoryRunStore.js.map +1 -1
- package/dist/tracing/Janitor.d.ts +70 -0
- package/dist/tracing/Janitor.js +150 -0
- package/dist/tracing/Janitor.js.map +1 -0
- package/dist/tracing/PostgresRunStore.d.ts +30 -0
- package/dist/tracing/PostgresRunStore.js +435 -3
- package/dist/tracing/PostgresRunStore.js.map +1 -1
- package/dist/tracing/RunStore.d.ts +100 -1
- package/dist/tracing/RunTracker.d.ts +261 -11
- package/dist/tracing/RunTracker.js +691 -11
- package/dist/tracing/RunTracker.js.map +1 -1
- package/dist/tracing/SqliteRunStore.d.ts +23 -1
- package/dist/tracing/SqliteRunStore.js +421 -6
- package/dist/tracing/SqliteRunStore.js.map +1 -1
- package/dist/tracing/TraceRouter.d.ts +20 -2
- package/dist/tracing/TraceRouter.js +494 -9
- package/dist/tracing/TraceRouter.js.map +1 -1
- package/dist/tracing/sanitize.d.ts +11 -0
- package/dist/tracing/sanitize.js +29 -0
- package/dist/tracing/sanitize.js.map +1 -1
- package/dist/tracing/types.d.ts +429 -11
- package/dist/types/GlobalOptions.d.ts +9 -2
- package/dist/utils/createChildContext.d.ts +32 -0
- package/dist/utils/createChildContext.js +113 -0
- package/dist/utils/createChildContext.js.map +1 -0
- package/dist/workflow/PersistenceHelper.d.ts +46 -0
- package/dist/workflow/PersistenceHelper.js +57 -0
- package/dist/workflow/PersistenceHelper.js.map +1 -0
- package/dist/workflow/WorkflowNormalizer.d.ts +79 -0
- package/dist/workflow/WorkflowNormalizer.js +486 -0
- package/dist/workflow/WorkflowNormalizer.js.map +1 -0
- package/dist/workflow/WorkflowRegistry.d.ts +64 -0
- package/dist/workflow/WorkflowRegistry.js +81 -0
- package/dist/workflow/WorkflowRegistry.js.map +1 -0
- package/package.json +10 -7
|
@@ -4,6 +4,13 @@ import type RunnerNode from "../RunnerNode";
|
|
|
4
4
|
* RuntimeKind represents all supported runtime environments
|
|
5
5
|
*/
|
|
6
6
|
export type RuntimeKind = "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm";
|
|
7
|
+
/**
|
|
8
|
+
* Wire transport an adapter uses to reach an SDK runtime. `module` is for
|
|
9
|
+
* in-process NodeJS adapters; `http` and `grpc` are the two non-NodeJS
|
|
10
|
+
* options. Used for log tagging and for distinguishing the same `kind`
|
|
11
|
+
* across transports during the gRPC migration.
|
|
12
|
+
*/
|
|
13
|
+
export type AdapterTransport = "module" | "http" | "grpc";
|
|
7
14
|
/**
|
|
8
15
|
* ExecutionResult is the canonical response structure from any runtime adapter
|
|
9
16
|
*/
|
|
@@ -16,6 +23,10 @@ export type ExecutionResult = {
|
|
|
16
23
|
duration_ms?: number;
|
|
17
24
|
cpu_ms?: number;
|
|
18
25
|
memory_bytes?: number;
|
|
26
|
+
/** Approximate or exact bytes the adapter sent on the wire. */
|
|
27
|
+
request_bytes?: number;
|
|
28
|
+
/** Bytes the adapter received from the SDK. */
|
|
29
|
+
response_bytes?: number;
|
|
19
30
|
};
|
|
20
31
|
/** Variables set by the SDK node during execution, to be merged into ctx.vars */
|
|
21
32
|
vars?: Record<string, unknown>;
|
|
@@ -31,6 +42,12 @@ export interface RuntimeAdapter {
|
|
|
31
42
|
* The kind of runtime this adapter handles
|
|
32
43
|
*/
|
|
33
44
|
readonly kind: RuntimeKind;
|
|
45
|
+
/**
|
|
46
|
+
* Wire transport this adapter uses (`http`, `grpc`, or in-process
|
|
47
|
+
* `module`). Surfaced in step-prefix logs so operators can tell at a
|
|
48
|
+
* glance which path a runtime node took during the migration.
|
|
49
|
+
*/
|
|
50
|
+
readonly transport: AdapterTransport;
|
|
34
51
|
/**
|
|
35
52
|
* Execute a node in this runtime
|
|
36
53
|
*
|
|
@@ -21,6 +21,7 @@ import type { ExecutionResult, RuntimeAdapter } from "./RuntimeAdapter";
|
|
|
21
21
|
*/
|
|
22
22
|
export declare class WasmRuntimeAdapter implements RuntimeAdapter {
|
|
23
23
|
readonly kind: "wasm";
|
|
24
|
+
readonly transport: "module";
|
|
24
25
|
private moduleCache;
|
|
25
26
|
private maxCacheSize;
|
|
26
27
|
constructor(options?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WasmRuntimeAdapter.js","sourceRoot":"","sources":["../../src/adapters/WasmRuntimeAdapter.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,kBAAkB;IACd,IAAI,GAAG,MAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"WasmRuntimeAdapter.js","sourceRoot":"","sources":["../../src/adapters/WasmRuntimeAdapter.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,kBAAkB;IACd,IAAI,GAAG,MAAe,CAAC;IACvB,SAAS,GAAG,QAAiB,CAAC;IAEtC,WAAW,GAAG,IAAI,GAAG,EAAwB,CAAC;IAC9C,YAAY,CAAS;IAE7B,YAAY,OAAyD;QACpE,I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AEG;IACK,WAAW,CAAC,IAAY,EAAE,MAA0B;QAC3D,qCAAqC;QACrC,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YAChD,IAAI,CAAC,WAAW,EAAE,CAAC;QACpB,CAAC;QAED,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE;YAC1B,MAAM;YACN,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE;SACpB,CAAC,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,WAAW;QAClB,IAAI,SAAS,GAAkB,IAAI,CAAC;QACpC,IAAI,UAAU,GAAG,MAAM,CAAC,iBAAiB,CAAC;QAE1C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YAC7C,IAAI,KAAK,CAAC,QAAQ,GAAG,UAAU,EAAE,CAAC;gBACjC,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC;gBAC5B,SAAS,GAAG,GAAG,CAAC;YACjB,CAAC;QACF,CAAC;QAED,IAAI,SAAS,EAAE,CAAC;YACf,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACpC,CAAC;IACF,CAAC;IAED;;OAEG;IACH,UAAU;QACT,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,aAAa;QACZ,OAAO;YACN,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;YAC3B,OAAO,EAAE,IAAI,CAAC,YAAY;SAC1B,CAAC;IACH,CAAC;CACD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ChannelOptions } from "@grpc/grpc-js";
|
|
2
|
+
import { GRPC_DEFAULTS, type GrpcAdapterConfig } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Build the {@link ChannelOptions} dictionary for `@grpc/grpc-js` from a
|
|
5
|
+
* {@link GrpcAdapterConfig}. Pure function — no I/O.
|
|
6
|
+
*
|
|
7
|
+
* The returned options enforce:
|
|
8
|
+
* - 16MB max send/receive message length (parity with PHP buffer ceiling).
|
|
9
|
+
* - Keepalive pings every 10s with 5s ack timeout.
|
|
10
|
+
* - TLS server-name override when provided.
|
|
11
|
+
*
|
|
12
|
+
* Service config (for `Health` RPC retries) is passed through verbatim so
|
|
13
|
+
* advanced users can tune retry/hedging policy without touching this file.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const channel = new grpc.Client(
|
|
17
|
+
* `${cfg.host}:${cfg.port}`,
|
|
18
|
+
* credentials,
|
|
19
|
+
* buildChannelOptions(cfg),
|
|
20
|
+
* );
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildChannelOptions(config: GrpcAdapterConfig): ChannelOptions;
|
|
23
|
+
/**
|
|
24
|
+
* Default service config for the Health RPC. Permits up to 3 retries on
|
|
25
|
+
* `UNAVAILABLE` with exponential backoff.
|
|
26
|
+
*
|
|
27
|
+
* Only applied to `NodeRuntime/Health` — `Execute` is intentionally never
|
|
28
|
+
* retried automatically because workflow steps are not idempotent in general.
|
|
29
|
+
*/
|
|
30
|
+
export declare const DEFAULT_HEALTH_SERVICE_CONFIG: string;
|
|
31
|
+
export { GRPC_DEFAULTS };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { GRPC_DEFAULTS } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Build the {@link ChannelOptions} dictionary for `@grpc/grpc-js` from a
|
|
4
|
+
* {@link GrpcAdapterConfig}. Pure function — no I/O.
|
|
5
|
+
*
|
|
6
|
+
* The returned options enforce:
|
|
7
|
+
* - 16MB max send/receive message length (parity with PHP buffer ceiling).
|
|
8
|
+
* - Keepalive pings every 10s with 5s ack timeout.
|
|
9
|
+
* - TLS server-name override when provided.
|
|
10
|
+
*
|
|
11
|
+
* Service config (for `Health` RPC retries) is passed through verbatim so
|
|
12
|
+
* advanced users can tune retry/hedging policy without touching this file.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const channel = new grpc.Client(
|
|
16
|
+
* `${cfg.host}:${cfg.port}`,
|
|
17
|
+
* credentials,
|
|
18
|
+
* buildChannelOptions(cfg),
|
|
19
|
+
* );
|
|
20
|
+
*/
|
|
21
|
+
export function buildChannelOptions(config) {
|
|
22
|
+
const opts = {
|
|
23
|
+
"grpc.max_send_message_length": config.maxMessageBytes,
|
|
24
|
+
"grpc.max_receive_message_length": config.maxMessageBytes,
|
|
25
|
+
"grpc.keepalive_time_ms": config.keepalive.timeMs,
|
|
26
|
+
"grpc.keepalive_timeout_ms": config.keepalive.timeoutMs,
|
|
27
|
+
"grpc.keepalive_permit_without_calls": config.keepalive.permitWithoutCalls ? 1 : 0,
|
|
28
|
+
// Sets the maximum amount of time a connection can be idle before keepalive
|
|
29
|
+
// pings start. Matches keepalive_time so we ping consistently.
|
|
30
|
+
"grpc.http2.min_time_between_pings_ms": config.keepalive.timeMs,
|
|
31
|
+
};
|
|
32
|
+
if (config.tls?.serverNameOverride) {
|
|
33
|
+
opts["grpc.ssl_target_name_override"] = config.tls.serverNameOverride;
|
|
34
|
+
opts["grpc.default_authority"] = config.tls.serverNameOverride;
|
|
35
|
+
}
|
|
36
|
+
if (config.serviceConfigJson) {
|
|
37
|
+
opts["grpc.service_config"] = config.serviceConfigJson;
|
|
38
|
+
}
|
|
39
|
+
return opts;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Default service config for the Health RPC. Permits up to 3 retries on
|
|
43
|
+
* `UNAVAILABLE` with exponential backoff.
|
|
44
|
+
*
|
|
45
|
+
* Only applied to `NodeRuntime/Health` — `Execute` is intentionally never
|
|
46
|
+
* retried automatically because workflow steps are not idempotent in general.
|
|
47
|
+
*/
|
|
48
|
+
export const DEFAULT_HEALTH_SERVICE_CONFIG = JSON.stringify({
|
|
49
|
+
methodConfig: [
|
|
50
|
+
{
|
|
51
|
+
name: [
|
|
52
|
+
{
|
|
53
|
+
service: "blok.runtime.v1.NodeRuntime",
|
|
54
|
+
method: "Health",
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
retryPolicy: {
|
|
58
|
+
maxAttempts: 3,
|
|
59
|
+
initialBackoff: "0.1s",
|
|
60
|
+
maxBackoff: "1s",
|
|
61
|
+
backoffMultiplier: 2,
|
|
62
|
+
retryableStatusCodes: ["UNAVAILABLE"],
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
});
|
|
67
|
+
export { GRPC_DEFAULTS };
|
|
68
|
+
//# sourceMappingURL=GrpcChannelOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GrpcChannelOptions.js","sourceRoot":"","sources":["../../../src/adapters/grpc/GrpcChannelOptions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAA0B,MAAM,SAAS,CAAC;AAEhE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAyB;IAC5D,MAAM,IAAI,GAAmB;QAC5B,8BAA8B,EAAE,MAAM,CAAC,eAAe;QACtD,iCAAiC,EAAE,MAAM,CAAC,eAAe;QACzD,wBAAwB,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM;QACjD,2BAA2B,EAAE,MAAM,CAAC,SAAS,CAAC,SAAS;QACvD,qCAAqC,EAAE,MAAM,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAClF,4EAA4E;QAC5E,+DAA+D;QAC/D,sCAAsC,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM;KAC/D,CAAC;IAEF,IAAI,MAAM,CAAC,GAAG,EAAE,kBAAkB,EAAE,CAAC;QACpC,IAAI,CAAC,+BAA+B,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC;QACtE,IAAI,CAAC,wBAAwB,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC;IAChE,CAAC;IAED,IAAI,MAAM,CAAC,iBAAiB,EAAE,CAAC;QAC9B,IAAI,CAAC,qBAAqB,CAAC,GAAG,MAAM,CAAC,iBAAiB,CAAC;IACxD,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAW,IAAI,CAAC,SAAS,CAAC;IACnE,YAAY,EAAE;QACb;YACC,IAAI,EAAE;gBACL;oBACC,OAAO,EAAE,6BAA6B;oBACtC,MAAM,EAAE,QAAQ;iBAChB;aACD;YACD,WAAW,EAAE;gBACZ,WAAW,EAAE,CAAC;gBACd,cAAc,EAAE,MAAM;gBACtB,UAAU,EAAE,IAAI;gBAChB,iBAAiB,EAAE,CAAC;gBACpB,oBAAoB,EAAE,CAAC,aAAa,CAAC;aACrC;SACD;KACD;CACD,CAAC,CAAC;AAEH,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ChannelCredentials, type Client } from "@grpc/grpc-js";
|
|
2
|
+
import type { GrpcAdapterConfig, TlsConfig } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Pool of gRPC clients keyed by `(host, port)`. One persistent client per
|
|
5
|
+
* endpoint for the lifetime of the pool — no per-request TCP/HTTP/2
|
|
6
|
+
* handshake.
|
|
7
|
+
*
|
|
8
|
+
* Adapters request a client via {@link get}; the pool creates it on first
|
|
9
|
+
* use and caches it. {@link close} drains all clients, used during graceful
|
|
10
|
+
* shutdown.
|
|
11
|
+
*
|
|
12
|
+
* Single Responsibility: lifecycle of `Client` instances. The pool does not
|
|
13
|
+
* encode requests, decode responses, or interpret errors — those belong to
|
|
14
|
+
* {@link GrpcCodec} and {@link GrpcErrors}.
|
|
15
|
+
*/
|
|
16
|
+
export declare class GrpcClientPool {
|
|
17
|
+
private readonly clients;
|
|
18
|
+
/**
|
|
19
|
+
* Get (or lazily create) a client for the given config's `(host, port)`.
|
|
20
|
+
* Subsequent calls with the same endpoint return the same instance.
|
|
21
|
+
*/
|
|
22
|
+
get(config: GrpcAdapterConfig): Client;
|
|
23
|
+
/**
|
|
24
|
+
* Close a client for a specific endpoint. Returns true if a client was
|
|
25
|
+
* present and closed.
|
|
26
|
+
*/
|
|
27
|
+
closeEndpoint(host: string, port: number): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Drain the pool. Closes every cached client.
|
|
30
|
+
*/
|
|
31
|
+
close(): void;
|
|
32
|
+
/** How many clients the pool currently holds. */
|
|
33
|
+
size(): number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Build channel credentials from a {@link TlsConfig}. When `tls` is omitted
|
|
37
|
+
* returns insecure credentials (plaintext channel) — appropriate for loopback
|
|
38
|
+
* dev only.
|
|
39
|
+
*
|
|
40
|
+
* `BLOK_GRPC_REQUIRE_TLS=true` causes the adapter to throw at startup when an
|
|
41
|
+
* insecure channel targets a non-loopback host.
|
|
42
|
+
*/
|
|
43
|
+
export declare function buildCredentials(tls?: TlsConfig): ChannelCredentials;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { credentials as grpcCredentials } from "@grpc/grpc-js";
|
|
3
|
+
import { buildChannelOptions } from "./GrpcChannelOptions";
|
|
4
|
+
import { NodeRuntimeService } from "./GrpcCodec";
|
|
5
|
+
/**
|
|
6
|
+
* Pool of gRPC clients keyed by `(host, port)`. One persistent client per
|
|
7
|
+
* endpoint for the lifetime of the pool — no per-request TCP/HTTP/2
|
|
8
|
+
* handshake.
|
|
9
|
+
*
|
|
10
|
+
* Adapters request a client via {@link get}; the pool creates it on first
|
|
11
|
+
* use and caches it. {@link close} drains all clients, used during graceful
|
|
12
|
+
* shutdown.
|
|
13
|
+
*
|
|
14
|
+
* Single Responsibility: lifecycle of `Client` instances. The pool does not
|
|
15
|
+
* encode requests, decode responses, or interpret errors — those belong to
|
|
16
|
+
* {@link GrpcCodec} and {@link GrpcErrors}.
|
|
17
|
+
*/
|
|
18
|
+
export class GrpcClientPool {
|
|
19
|
+
clients = new Map();
|
|
20
|
+
/**
|
|
21
|
+
* Get (or lazily create) a client for the given config's `(host, port)`.
|
|
22
|
+
* Subsequent calls with the same endpoint return the same instance.
|
|
23
|
+
*/
|
|
24
|
+
get(config) {
|
|
25
|
+
const endpoint = `${config.host}:${config.port}`;
|
|
26
|
+
const existing = this.clients.get(endpoint);
|
|
27
|
+
if (existing)
|
|
28
|
+
return existing;
|
|
29
|
+
const creds = buildCredentials(config.tls);
|
|
30
|
+
const options = buildChannelOptions(config);
|
|
31
|
+
const ServiceCtor = NodeRuntimeService;
|
|
32
|
+
const client = new ServiceCtor(endpoint, creds, options);
|
|
33
|
+
this.clients.set(endpoint, client);
|
|
34
|
+
return client;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Close a client for a specific endpoint. Returns true if a client was
|
|
38
|
+
* present and closed.
|
|
39
|
+
*/
|
|
40
|
+
closeEndpoint(host, port) {
|
|
41
|
+
const endpoint = `${host}:${port}`;
|
|
42
|
+
const client = this.clients.get(endpoint);
|
|
43
|
+
if (!client)
|
|
44
|
+
return false;
|
|
45
|
+
client.close();
|
|
46
|
+
this.clients.delete(endpoint);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Drain the pool. Closes every cached client.
|
|
51
|
+
*/
|
|
52
|
+
close() {
|
|
53
|
+
for (const client of this.clients.values()) {
|
|
54
|
+
try {
|
|
55
|
+
client.close();
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
/* swallow — best-effort cleanup during shutdown */
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
this.clients.clear();
|
|
62
|
+
}
|
|
63
|
+
/** How many clients the pool currently holds. */
|
|
64
|
+
size() {
|
|
65
|
+
return this.clients.size;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Build channel credentials from a {@link TlsConfig}. When `tls` is omitted
|
|
70
|
+
* returns insecure credentials (plaintext channel) — appropriate for loopback
|
|
71
|
+
* dev only.
|
|
72
|
+
*
|
|
73
|
+
* `BLOK_GRPC_REQUIRE_TLS=true` causes the adapter to throw at startup when an
|
|
74
|
+
* insecure channel targets a non-loopback host.
|
|
75
|
+
*/
|
|
76
|
+
export function buildCredentials(tls) {
|
|
77
|
+
if (!tls)
|
|
78
|
+
return grpcCredentials.createInsecure();
|
|
79
|
+
if (tls.insecureSkipVerify) {
|
|
80
|
+
// Verified-server-via-handshake-skipped is genuinely insecure. We log
|
|
81
|
+
// at adapter startup; here we just produce the credentials object.
|
|
82
|
+
return grpcCredentials.createInsecure();
|
|
83
|
+
}
|
|
84
|
+
const ca = tls.caCertPath ? fs.readFileSync(tls.caCertPath) : null;
|
|
85
|
+
const clientCert = tls.clientCertPath ? fs.readFileSync(tls.clientCertPath) : null;
|
|
86
|
+
const clientKey = tls.clientKeyPath ? fs.readFileSync(tls.clientKeyPath) : null;
|
|
87
|
+
return grpcCredentials.createSsl(ca ?? null, clientKey ?? null, clientCert ?? null);
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=GrpcClientPool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GrpcClientPool.js","sourceRoot":"","sources":["../../../src/adapters/grpc/GrpcClientPool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAwC,WAAW,IAAI,eAAe,EAAE,MAAM,eAAe,CAAC;AACrG,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGjD;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,cAAc;IACT,OAAO,GAAwB,IAAI,GAAG,EAAE,CAAC;IAE1D;;;OAGG;IACH,GAAG,CAAC,MAAyB;QAC5B,MAAM,QAAQ,GAAG,GA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AAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC1B,CAAC;CACD;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAe;IAC/C,IAAI,CAAC,GAAG;QAAE,OAAO,eAAe,CAAC,cAAc,EAAE,CAAC;IAElD,IAAI,GAAG,CAAC,kBAAkB,EAAE,CAAC;QAC5B,sEAAsE;QACtE,mEAAmE;QACnE,OAAO,eAAe,CAAC,cAAc,EAAE,CAAC;IACzC,CAAC;IAED,MAAM,EAAE,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACnE,MAAM,UAAU,GAAG,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACnF,MAAM,SAAS,GAAG,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAEhF,OAAO,eAAe,CAAC,SAAS,CAAC,EAAE,IAAI,IAAI,EAAE,SAAS,IAAI,IAAI,EAAE,UAAU,IAAI,IAAI,CAAC,CAAC;AACrF,CAAC"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import type { Context } from "@blokjs/shared";
|
|
2
|
+
import { type ServiceClientConstructor } from "@grpc/grpc-js";
|
|
3
|
+
import type RunnerNode from "../../RunnerNode";
|
|
4
|
+
/**
|
|
5
|
+
* The {@link NodeRuntime} service client constructor — used by
|
|
6
|
+
* {@link GrpcClientPool} to instantiate clients.
|
|
7
|
+
*/
|
|
8
|
+
export declare const NodeRuntimeService: ServiceClientConstructor;
|
|
9
|
+
export interface ExecuteRequestProto {
|
|
10
|
+
node: NodeRefProto;
|
|
11
|
+
inputs: Buffer;
|
|
12
|
+
step: StepInfoProto;
|
|
13
|
+
trigger: TriggerInfoProto;
|
|
14
|
+
state: RuntimeStateProto;
|
|
15
|
+
workflow: WorkflowInfoProto;
|
|
16
|
+
options: ExecuteOptionsProto;
|
|
17
|
+
}
|
|
18
|
+
export interface NodeRefProto {
|
|
19
|
+
name: string;
|
|
20
|
+
type: string;
|
|
21
|
+
version: string;
|
|
22
|
+
}
|
|
23
|
+
export interface StepInfoProto {
|
|
24
|
+
name: string;
|
|
25
|
+
index: number;
|
|
26
|
+
total: number;
|
|
27
|
+
depth: number;
|
|
28
|
+
}
|
|
29
|
+
export interface TriggerInfoProto {
|
|
30
|
+
body: Buffer;
|
|
31
|
+
headers: Record<string, string>;
|
|
32
|
+
params: Record<string, string>;
|
|
33
|
+
query: Record<string, string>;
|
|
34
|
+
cookies: Record<string, string>;
|
|
35
|
+
method: string;
|
|
36
|
+
url: string;
|
|
37
|
+
baseUrl: string;
|
|
38
|
+
triggerKind: string;
|
|
39
|
+
}
|
|
40
|
+
export interface RuntimeStateProto {
|
|
41
|
+
previousOutput: Buffer;
|
|
42
|
+
vars: Buffer;
|
|
43
|
+
env: Record<string, string>;
|
|
44
|
+
}
|
|
45
|
+
export interface WorkflowInfoProto {
|
|
46
|
+
runId: string;
|
|
47
|
+
name: string;
|
|
48
|
+
path: string;
|
|
49
|
+
version: string;
|
|
50
|
+
startedAt: {
|
|
51
|
+
seconds: string;
|
|
52
|
+
nanos: number;
|
|
53
|
+
} | null;
|
|
54
|
+
}
|
|
55
|
+
export interface ExecuteOptionsProto {
|
|
56
|
+
deadlineMs: string;
|
|
57
|
+
streamLogs: boolean;
|
|
58
|
+
captureMetrics: boolean;
|
|
59
|
+
hints: Record<string, string>;
|
|
60
|
+
}
|
|
61
|
+
export interface ExecuteResponseProto {
|
|
62
|
+
success: boolean;
|
|
63
|
+
data: Buffer;
|
|
64
|
+
contentType: string;
|
|
65
|
+
error: NodeErrorProto | null;
|
|
66
|
+
varsDelta: Buffer;
|
|
67
|
+
logs: LogLineProto[];
|
|
68
|
+
metrics: MetricsProto | null;
|
|
69
|
+
}
|
|
70
|
+
export interface NodeErrorProto {
|
|
71
|
+
code: string;
|
|
72
|
+
category: string;
|
|
73
|
+
severity: string;
|
|
74
|
+
node: string;
|
|
75
|
+
sdk: string;
|
|
76
|
+
sdkVersion: string;
|
|
77
|
+
runtimeKind: string;
|
|
78
|
+
at: {
|
|
79
|
+
seconds: string;
|
|
80
|
+
nanos: number;
|
|
81
|
+
} | null;
|
|
82
|
+
message: string;
|
|
83
|
+
description: string;
|
|
84
|
+
remediation: string;
|
|
85
|
+
docUrl: string;
|
|
86
|
+
causes: NodeErrorProto[];
|
|
87
|
+
stack: string;
|
|
88
|
+
contextSnapshotJson: Buffer;
|
|
89
|
+
httpStatus: number;
|
|
90
|
+
retryable: boolean;
|
|
91
|
+
retryAfterMs: string;
|
|
92
|
+
detailsJson: Buffer;
|
|
93
|
+
}
|
|
94
|
+
export interface LogLineProto {
|
|
95
|
+
timestamp: {
|
|
96
|
+
seconds: string;
|
|
97
|
+
nanos: number;
|
|
98
|
+
} | null;
|
|
99
|
+
level: string;
|
|
100
|
+
message: string;
|
|
101
|
+
attributes: Record<string, string>;
|
|
102
|
+
}
|
|
103
|
+
export interface MetricsProto {
|
|
104
|
+
durationMs: number;
|
|
105
|
+
cpuMs: number;
|
|
106
|
+
memoryBytes: string;
|
|
107
|
+
requestBytes: string;
|
|
108
|
+
responseBytes: string;
|
|
109
|
+
}
|
|
110
|
+
export interface DecodedExecuteResponse {
|
|
111
|
+
readonly success: boolean;
|
|
112
|
+
readonly data: unknown;
|
|
113
|
+
readonly contentType: string;
|
|
114
|
+
readonly varsDelta: Record<string, unknown>;
|
|
115
|
+
readonly logs: ReadonlyArray<DecodedLogLine>;
|
|
116
|
+
readonly error: DecodedNodeError | null;
|
|
117
|
+
readonly metrics: DecodedMetrics;
|
|
118
|
+
}
|
|
119
|
+
export interface DecodedLogLine {
|
|
120
|
+
readonly timestamp: number;
|
|
121
|
+
readonly level: string;
|
|
122
|
+
readonly message: string;
|
|
123
|
+
readonly attributes: Record<string, string>;
|
|
124
|
+
}
|
|
125
|
+
export interface DecodedNodeError {
|
|
126
|
+
readonly code: string;
|
|
127
|
+
readonly category: string;
|
|
128
|
+
readonly severity: string;
|
|
129
|
+
readonly node: string;
|
|
130
|
+
readonly sdk: string;
|
|
131
|
+
readonly sdkVersion: string;
|
|
132
|
+
readonly runtimeKind: string;
|
|
133
|
+
readonly at: number;
|
|
134
|
+
readonly message: string;
|
|
135
|
+
readonly description: string;
|
|
136
|
+
readonly remediation: string;
|
|
137
|
+
readonly docUrl: string;
|
|
138
|
+
readonly causes: ReadonlyArray<DecodedNodeError>;
|
|
139
|
+
readonly stack: string;
|
|
140
|
+
readonly contextSnapshot: unknown;
|
|
141
|
+
readonly httpStatus: number;
|
|
142
|
+
readonly retryable: boolean;
|
|
143
|
+
readonly retryAfterMs: number;
|
|
144
|
+
readonly details: unknown;
|
|
145
|
+
}
|
|
146
|
+
export interface DecodedMetrics {
|
|
147
|
+
readonly durationMs: number;
|
|
148
|
+
readonly cpuMs: number;
|
|
149
|
+
readonly memoryBytes: number;
|
|
150
|
+
readonly requestBytes: number;
|
|
151
|
+
readonly responseBytes: number;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Encode a workflow {@link Context} and a {@link RunnerNode} into a
|
|
155
|
+
* {@link ExecuteRequestProto} ready for the gRPC wire.
|
|
156
|
+
*
|
|
157
|
+
* Pure function — no I/O. The opaque JSON-shaped fields (`inputs`,
|
|
158
|
+
* `previous_output`, `vars`, body) are serialized to UTF-8 bytes here so the
|
|
159
|
+
* SDK side can JSON-decode lazily.
|
|
160
|
+
*
|
|
161
|
+
* Critically, `inputs` is the resolved node config (from the Blueprint
|
|
162
|
+
* Mapper) sent UNWRAPPED — no `{inputs:{...}}` envelope. This closes the
|
|
163
|
+
* `BLOK_FRAMEWORK_FIXES.md` #3 unwrap-hack family of bugs at the wire format
|
|
164
|
+
* layer.
|
|
165
|
+
*/
|
|
166
|
+
export declare function encodeExecuteRequest(node: RunnerNode, ctx: Context, stepIndex: number, stepTotal: number, stepDepth: number, deadlineMs: number): ExecuteRequestProto;
|
|
167
|
+
/**
|
|
168
|
+
* Proto envelope for a streamed event. proto-loader with `oneofs: true`
|
|
169
|
+
* exposes the active oneof case via the `event` property AND mirrors the
|
|
170
|
+
* matching field at the top level. We discriminate on `event`.
|
|
171
|
+
*/
|
|
172
|
+
export interface ExecuteEventProto {
|
|
173
|
+
event: "started" | "log" | "progress" | "partial" | "final" | undefined;
|
|
174
|
+
started?: {
|
|
175
|
+
at: {
|
|
176
|
+
seconds: string;
|
|
177
|
+
nanos: number;
|
|
178
|
+
} | null;
|
|
179
|
+
};
|
|
180
|
+
log?: LogLineProto;
|
|
181
|
+
progress?: {
|
|
182
|
+
percent: number;
|
|
183
|
+
phase: string;
|
|
184
|
+
};
|
|
185
|
+
partial?: {
|
|
186
|
+
snapshotJson: Buffer;
|
|
187
|
+
};
|
|
188
|
+
final?: ExecuteResponseProto;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Adapter-facing discriminated union — keeps callers free of proto-loader
|
|
192
|
+
* shape concerns and lets TypeScript narrow on the `type` field.
|
|
193
|
+
*/
|
|
194
|
+
export type DecodedExecuteEvent = {
|
|
195
|
+
readonly type: "started";
|
|
196
|
+
readonly at: number;
|
|
197
|
+
} | {
|
|
198
|
+
readonly type: "log";
|
|
199
|
+
readonly log: DecodedLogLine;
|
|
200
|
+
} | {
|
|
201
|
+
readonly type: "progress";
|
|
202
|
+
readonly percent: number;
|
|
203
|
+
readonly phase: string;
|
|
204
|
+
} | {
|
|
205
|
+
readonly type: "partial";
|
|
206
|
+
readonly snapshot: unknown;
|
|
207
|
+
} | {
|
|
208
|
+
readonly type: "final";
|
|
209
|
+
readonly response: DecodedExecuteResponse;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Decode a single streamed `ExecuteEvent` proto into the discriminated union
|
|
213
|
+
* the adapter exposes. Returns `null` when the proto envelope is empty (no
|
|
214
|
+
* oneof field set) — the caller skips such frames.
|
|
215
|
+
*/
|
|
216
|
+
export declare function decodeExecuteEvent(event: ExecuteEventProto): DecodedExecuteEvent | null;
|
|
217
|
+
/**
|
|
218
|
+
* Decode a {@link ExecuteResponseProto} from the wire into the shape the
|
|
219
|
+
* adapter consumes. Defensive against missing fields (proto-loader fills in
|
|
220
|
+
* defaults, but we guard against malformed responses too).
|
|
221
|
+
*/
|
|
222
|
+
export declare function decodeExecuteResponse(response: ExecuteResponseProto): DecodedExecuteResponse;
|
|
223
|
+
/** Encode a value as UTF-8 JSON bytes. `null`/`undefined` → empty buffer. */
|
|
224
|
+
export declare function jsonToBuffer(value: unknown): Buffer;
|
|
225
|
+
/** Decode a buffer as UTF-8 JSON. Empty/missing buffer → `null`. */
|
|
226
|
+
export declare function bufferToJson(buf: Buffer | undefined): unknown;
|