@lace-cloud/host 0.35.0 → 0.36.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/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MessageBridge } from '@lace-cloud/proto';
2
- export { Diagnostic, EngineProtocolMismatchError } from '@lace-cloud/proto';
2
+ export { Diagnostic, EngineIdentityMismatchError } from '@lace-cloud/proto';
3
3
  import * as grpc from '@grpc/grpc-js';
4
4
  import { Metadata, ServiceError, Client, ClientUnaryCall, CallOptions, ClientReadableStream, ChannelCredentials, ClientOptions } from '@grpc/grpc-js';
5
5
  import { ChildProcess } from 'node:child_process';
@@ -37,6 +37,7 @@ declare function serveEngineBridge(bridge: MessageBridge, transport: EngineTrans
37
37
  type EngineHandshake = {
38
38
  version: string;
39
39
  protocolVersion: string;
40
+ contract: string;
40
41
  port: number;
41
42
  token: string;
42
43
  };
@@ -70,13 +71,20 @@ declare class EngineSpawnError extends Error {
70
71
  get code(): string | undefined;
71
72
  }
72
73
  /**
73
- * Spawn `lace engine` and parse the 5-line handshake:
74
+ * Spawn `lace engine` and parse its handshake:
74
75
  * LACE_ENGINE_VERSION=<semver>
75
76
  * LACE_ENGINE_PROTOCOL_VERSION=<integer>
77
+ * LACE_ENGINE_CONTRACT=<64 hex chars>
76
78
  * LACE_ENGINE_PORT=<port>
77
79
  * LACE_ENGINE_TOKEN=<64 hex chars>
78
80
  * LACE_ENGINE_READY
79
81
  *
82
+ * READY settles the handshake once the version, protocol, port and token
83
+ * are set. The contract line is not required for it: an engine that names
84
+ * no contract settles with `contract` '', and the protocol check
85
+ * (`checkEngineIdentity`) refuses it by name rather than a handshake
86
+ * failure that names nothing.
87
+ *
80
88
  * Each stdout line is logged as the engine wrote it, the handshake's and every
81
89
  * one after it until the engine's end, except a token line, which is logged
82
90
  * masked. A binary that cannot be started rejects with
@@ -740,6 +748,13 @@ interface InitializeResponse {
740
748
  supported_protocols: string[];
741
749
  /** space-joined paths of the non-hidden command tree */
742
750
  command_paths: string[];
751
+ /**
752
+ * The digest of the contract the engine serves (scripts/lib/engine-contract.mjs):
753
+ * the command tree, the `--output json` documents and the failure
754
+ * envelopes the CLI's tests record. A client built from another contract
755
+ * refuses the engine; the engine compares no contract of the client's.
756
+ */
757
+ contract: string;
743
758
  }
744
759
  declare const InitializeResponse: MessageFns<InitializeResponse>;
745
760
  interface ShutdownResponse {
@@ -1954,10 +1969,10 @@ declare class ServerManager extends EventEmitter {
1954
1969
  get currentState(): ServerState;
1955
1970
  /**
1956
1971
  * Spawns the engine and connects to it. The handshake's protocol version
1957
- * is compared with the one this library speaks before any RPC is sent
1958
- * (`checkEngineProtocol`, `@lace-cloud/proto`, the check the canvas makes
1959
- * of `Initialize`'s answer): an engine that names another rejects with
1960
- * `EngineProtocolMismatchError`. A binary that cannot be started rejects
1972
+ * and contract are compared with the ones this library was built from
1973
+ * before any RPC is sent (`checkEngineIdentity`, `@lace-cloud/proto`, the
1974
+ * check the canvas makes of `Initialize`'s answer): an engine that names
1975
+ * another, or no contract, rejects with `EngineIdentityMismatchError`. A binary that cannot be started rejects
1961
1976
  * with `EngineSpawnError`, whose `code` is the spawn error's (`ENOENT`
1962
1977
  * when no executable is found, `EINVAL` when Windows refuses to start a
1963
1978
  * `.cmd` or `.bat`).
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MessageBridge } from '@lace-cloud/proto';
2
- export { Diagnostic, EngineProtocolMismatchError } from '@lace-cloud/proto';
2
+ export { Diagnostic, EngineIdentityMismatchError } from '@lace-cloud/proto';
3
3
  import * as grpc from '@grpc/grpc-js';
4
4
  import { Metadata, ServiceError, Client, ClientUnaryCall, CallOptions, ClientReadableStream, ChannelCredentials, ClientOptions } from '@grpc/grpc-js';
5
5
  import { ChildProcess } from 'node:child_process';
@@ -37,6 +37,7 @@ declare function serveEngineBridge(bridge: MessageBridge, transport: EngineTrans
37
37
  type EngineHandshake = {
38
38
  version: string;
39
39
  protocolVersion: string;
40
+ contract: string;
40
41
  port: number;
41
42
  token: string;
42
43
  };
@@ -70,13 +71,20 @@ declare class EngineSpawnError extends Error {
70
71
  get code(): string | undefined;
71
72
  }
72
73
  /**
73
- * Spawn `lace engine` and parse the 5-line handshake:
74
+ * Spawn `lace engine` and parse its handshake:
74
75
  * LACE_ENGINE_VERSION=<semver>
75
76
  * LACE_ENGINE_PROTOCOL_VERSION=<integer>
77
+ * LACE_ENGINE_CONTRACT=<64 hex chars>
76
78
  * LACE_ENGINE_PORT=<port>
77
79
  * LACE_ENGINE_TOKEN=<64 hex chars>
78
80
  * LACE_ENGINE_READY
79
81
  *
82
+ * READY settles the handshake once the version, protocol, port and token
83
+ * are set. The contract line is not required for it: an engine that names
84
+ * no contract settles with `contract` '', and the protocol check
85
+ * (`checkEngineIdentity`) refuses it by name rather than a handshake
86
+ * failure that names nothing.
87
+ *
80
88
  * Each stdout line is logged as the engine wrote it, the handshake's and every
81
89
  * one after it until the engine's end, except a token line, which is logged
82
90
  * masked. A binary that cannot be started rejects with
@@ -740,6 +748,13 @@ interface InitializeResponse {
740
748
  supported_protocols: string[];
741
749
  /** space-joined paths of the non-hidden command tree */
742
750
  command_paths: string[];
751
+ /**
752
+ * The digest of the contract the engine serves (scripts/lib/engine-contract.mjs):
753
+ * the command tree, the `--output json` documents and the failure
754
+ * envelopes the CLI's tests record. A client built from another contract
755
+ * refuses the engine; the engine compares no contract of the client's.
756
+ */
757
+ contract: string;
743
758
  }
744
759
  declare const InitializeResponse: MessageFns<InitializeResponse>;
745
760
  interface ShutdownResponse {
@@ -1954,10 +1969,10 @@ declare class ServerManager extends EventEmitter {
1954
1969
  get currentState(): ServerState;
1955
1970
  /**
1956
1971
  * Spawns the engine and connects to it. The handshake's protocol version
1957
- * is compared with the one this library speaks before any RPC is sent
1958
- * (`checkEngineProtocol`, `@lace-cloud/proto`, the check the canvas makes
1959
- * of `Initialize`'s answer): an engine that names another rejects with
1960
- * `EngineProtocolMismatchError`. A binary that cannot be started rejects
1972
+ * and contract are compared with the ones this library was built from
1973
+ * before any RPC is sent (`checkEngineIdentity`, `@lace-cloud/proto`, the
1974
+ * check the canvas makes of `Initialize`'s answer): an engine that names
1975
+ * another, or no contract, rejects with `EngineIdentityMismatchError`. A binary that cannot be started rejects
1961
1976
  * with `EngineSpawnError`, whose `code` is the spawn error's (`ENOENT`
1962
1977
  * when no executable is found, `EINVAL` when Windows refuses to start a
1963
1978
  * `.cmd` or `.bat`).
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/index.ts
2
- import { EngineProtocolMismatchError } from "@lace-cloud/proto";
2
+ import { EngineIdentityMismatchError } from "@lace-cloud/proto";
3
3
 
4
4
  // src/bridge-server.ts
5
5
  import {
@@ -3679,7 +3679,7 @@ var InitializeRequest = {
3679
3679
  }
3680
3680
  };
3681
3681
  function createBaseInitializeResponse() {
3682
- return { server_version: "", protocol_version: "", supported_protocols: [], command_paths: [] };
3682
+ return { server_version: "", protocol_version: "", supported_protocols: [], command_paths: [], contract: "" };
3683
3683
  }
3684
3684
  var InitializeResponse = {
3685
3685
  encode(message, writer = new BinaryWriter4()) {
@@ -3695,6 +3695,9 @@ var InitializeResponse = {
3695
3695
  for (const v of message.command_paths) {
3696
3696
  writer.uint32(42).string(v);
3697
3697
  }
3698
+ if (message.contract !== "") {
3699
+ writer.uint32(50).string(message.contract);
3700
+ }
3698
3701
  return writer;
3699
3702
  },
3700
3703
  decode(input, length) {
@@ -3732,6 +3735,13 @@ var InitializeResponse = {
3732
3735
  message.command_paths.push(reader.string());
3733
3736
  continue;
3734
3737
  }
3738
+ case 6: {
3739
+ if (tag !== 50) {
3740
+ break;
3741
+ }
3742
+ message.contract = reader.string();
3743
+ continue;
3744
+ }
3735
3745
  }
3736
3746
  if ((tag & 7) === 4 || tag === 0) {
3737
3747
  break;
@@ -3745,7 +3755,8 @@ var InitializeResponse = {
3745
3755
  server_version: isSet3(object.serverVersion) ? globalThis.String(object.serverVersion) : isSet3(object.server_version) ? globalThis.String(object.server_version) : "",
3746
3756
  protocol_version: isSet3(object.protocolVersion) ? globalThis.String(object.protocolVersion) : isSet3(object.protocol_version) ? globalThis.String(object.protocol_version) : "",
3747
3757
  supported_protocols: globalThis.Array.isArray(object?.supportedProtocols) ? object.supportedProtocols.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.supported_protocols) ? object.supported_protocols.map((e) => globalThis.String(e)) : [],
3748
- command_paths: globalThis.Array.isArray(object?.commandPaths) ? object.commandPaths.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.command_paths) ? object.command_paths.map((e) => globalThis.String(e)) : []
3758
+ command_paths: globalThis.Array.isArray(object?.commandPaths) ? object.commandPaths.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.command_paths) ? object.command_paths.map((e) => globalThis.String(e)) : [],
3759
+ contract: isSet3(object.contract) ? globalThis.String(object.contract) : ""
3749
3760
  };
3750
3761
  },
3751
3762
  toJSON(message) {
@@ -3762,6 +3773,9 @@ var InitializeResponse = {
3762
3773
  if (message.command_paths?.length) {
3763
3774
  obj.commandPaths = message.command_paths;
3764
3775
  }
3776
+ if (message.contract !== "") {
3777
+ obj.contract = message.contract;
3778
+ }
3765
3779
  return obj;
3766
3780
  },
3767
3781
  create(base) {
@@ -3773,6 +3787,7 @@ var InitializeResponse = {
3773
3787
  message.protocol_version = object.protocol_version ?? "";
3774
3788
  message.supported_protocols = object.supported_protocols?.map((e) => e) || [];
3775
3789
  message.command_paths = object.command_paths?.map((e) => e) || [];
3790
+ message.contract = object.contract ?? "";
3776
3791
  return message;
3777
3792
  }
3778
3793
  };
@@ -10868,6 +10883,7 @@ function endEngine(proc, graceMs = EXIT_GRACE_MS) {
10868
10883
  var HANDSHAKE_TIMEOUT_MS = 1e4;
10869
10884
  var VERSION_RE = /^LACE_ENGINE_VERSION=(.+)$/;
10870
10885
  var PROTOCOL_RE = /^LACE_ENGINE_PROTOCOL_VERSION=(\d+)$/;
10886
+ var CONTRACT_RE = /^LACE_ENGINE_CONTRACT=([0-9a-f]{64})$/;
10871
10887
  var PORT_RE = /^LACE_ENGINE_PORT=(\d+)$/;
10872
10888
  var TOKEN_PREFIX = "LACE_ENGINE_TOKEN=";
10873
10889
  var TOKEN_RE = new RegExp(`^${TOKEN_PREFIX}([0-9a-fA-F]{64})$`);
@@ -10904,6 +10920,7 @@ function spawnEngine(binaryPath, log) {
10904
10920
  const rl = readline.createInterface({ input: proc.stdout });
10905
10921
  let version;
10906
10922
  let protocolVersion;
10923
+ let contract = "";
10907
10924
  let port;
10908
10925
  let token;
10909
10926
  let settled = false;
@@ -10931,6 +10948,11 @@ function spawnEngine(binaryPath, log) {
10931
10948
  protocolVersion = match[1];
10932
10949
  return;
10933
10950
  }
10951
+ match = line.match(CONTRACT_RE);
10952
+ if (match) {
10953
+ contract = match[1];
10954
+ return;
10955
+ }
10934
10956
  match = line.match(PORT_RE);
10935
10957
  if (match) {
10936
10958
  port = Number(match[1]);
@@ -10950,7 +10972,7 @@ function spawnEngine(binaryPath, log) {
10950
10972
  clearTimeout(timer);
10951
10973
  resolve({
10952
10974
  process: proc,
10953
- handshake: { version, protocolVersion, port, token }
10975
+ handshake: { version, protocolVersion, contract, port, token }
10954
10976
  });
10955
10977
  }
10956
10978
  });
@@ -11017,7 +11039,7 @@ function requireClient(client, action) {
11017
11039
 
11018
11040
  // src/server-manager.ts
11019
11041
  import { EventEmitter } from "events";
11020
- import { checkEngineProtocol } from "@lace-cloud/proto";
11042
+ import { checkEngineIdentity } from "@lace-cloud/proto";
11021
11043
 
11022
11044
  // src/transport.ts
11023
11045
  import * as grpc from "@grpc/grpc-js";
@@ -11115,10 +11137,10 @@ var ServerManager = class extends EventEmitter {
11115
11137
  }
11116
11138
  /**
11117
11139
  * Spawns the engine and connects to it. The handshake's protocol version
11118
- * is compared with the one this library speaks before any RPC is sent
11119
- * (`checkEngineProtocol`, `@lace-cloud/proto`, the check the canvas makes
11120
- * of `Initialize`'s answer): an engine that names another rejects with
11121
- * `EngineProtocolMismatchError`. A binary that cannot be started rejects
11140
+ * and contract are compared with the ones this library was built from
11141
+ * before any RPC is sent (`checkEngineIdentity`, `@lace-cloud/proto`, the
11142
+ * check the canvas makes of `Initialize`'s answer): an engine that names
11143
+ * another, or no contract, rejects with `EngineIdentityMismatchError`. A binary that cannot be started rejects
11122
11144
  * with `EngineSpawnError`, whose `code` is the spawn error's (`ENOENT`
11123
11145
  * when no executable is found, `EINVAL` when Windows refuses to start a
11124
11146
  * `.cmd` or `.bat`).
@@ -11145,7 +11167,11 @@ var ServerManager = class extends EventEmitter {
11145
11167
  this.maybeRestart();
11146
11168
  }
11147
11169
  });
11148
- checkEngineProtocol(handshake.version, handshake.protocolVersion);
11170
+ checkEngineIdentity({
11171
+ version: handshake.version,
11172
+ protocol: handshake.protocolVersion,
11173
+ contract: handshake.contract
11174
+ });
11149
11175
  this._handshake = handshake;
11150
11176
  this._transport = new LaceTransport(handshake.port, handshake.token);
11151
11177
  this._initialized = await this._transport.initialize(handshake.version);
@@ -11226,7 +11252,7 @@ var ServerManager = class extends EventEmitter {
11226
11252
  export {
11227
11253
  BundleState,
11228
11254
  BundleStateEvent,
11229
- EngineProtocolMismatchError,
11255
+ EngineIdentityMismatchError,
11230
11256
  EngineSpawnError,
11231
11257
  InitializeResponse,
11232
11258
  InvokeEvent,