@lace-cloud/host 0.25.0 → 0.27.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/README.md +8 -1
- package/dist/index.cjs +113 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +50 -10
- package/dist/index.d.ts +50 -10
- package/dist/index.mjs +106 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ npm install @lace-cloud/host
|
|
|
19
19
|
```ts
|
|
20
20
|
import {
|
|
21
21
|
EngineProtocolMismatchError,
|
|
22
|
+
EngineSpawnError,
|
|
22
23
|
ServerManager,
|
|
23
24
|
serveEngineBridge,
|
|
24
25
|
classifyRpcError,
|
|
@@ -38,13 +39,19 @@ server.on('state', (state) => console.log(`engine: ${state}`));
|
|
|
38
39
|
// one this library speaks before it sends any RPC. An engine that names
|
|
39
40
|
// another is ended and start() rejects with EngineProtocolMismatchError,
|
|
40
41
|
// which carries the engine's version and both protocol versions;
|
|
41
|
-
// `engineTooOld` says which side is behind.
|
|
42
|
+
// `engineTooOld` says which side is behind. A binary that cannot be started
|
|
43
|
+
// rejects with EngineSpawnError: `cause` is the spawn error and `code` its
|
|
44
|
+
// system code (`ENOENT` when no executable is found). What to show is the
|
|
45
|
+
// host's.
|
|
42
46
|
try {
|
|
43
47
|
await server.start();
|
|
44
48
|
} catch (err) {
|
|
45
49
|
if (err instanceof EngineProtocolMismatchError && err.engineTooOld) {
|
|
46
50
|
console.error(`Lace CLI ${err.engineVersion} is too old for this host: update it`);
|
|
47
51
|
}
|
|
52
|
+
if (err instanceof EngineSpawnError && err.code === 'ENOENT') {
|
|
53
|
+
console.error('lace was not found: install the Lace CLI or set its path');
|
|
54
|
+
}
|
|
48
55
|
throw err;
|
|
49
56
|
}
|
|
50
57
|
|
package/dist/index.cjs
CHANGED
|
@@ -32,8 +32,10 @@ var index_exports = {};
|
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
BundleState: () => BundleState,
|
|
34
34
|
BundleStateEvent: () => BundleStateEvent,
|
|
35
|
-
EngineProtocolMismatchError: () =>
|
|
35
|
+
EngineProtocolMismatchError: () => import_proto5.EngineProtocolMismatchError,
|
|
36
|
+
EngineSpawnError: () => EngineSpawnError,
|
|
36
37
|
InitializeResponse: () => InitializeResponse,
|
|
38
|
+
InvokeEvent: () => InvokeEvent,
|
|
37
39
|
InvokeRequest: () => InvokeRequest,
|
|
38
40
|
LaceTransport: () => LaceTransport,
|
|
39
41
|
ReadWiringCandidatesRequest: () => ReadWiringCandidatesRequest,
|
|
@@ -51,7 +53,7 @@ __export(index_exports, {
|
|
|
51
53
|
spawnEngine: () => spawnEngine
|
|
52
54
|
});
|
|
53
55
|
module.exports = __toCommonJS(index_exports);
|
|
54
|
-
var
|
|
56
|
+
var import_proto5 = require("@lace-cloud/proto");
|
|
55
57
|
|
|
56
58
|
// src/bridge-server.ts
|
|
57
59
|
var import_proto = require("@lace-cloud/proto");
|
|
@@ -3566,7 +3568,7 @@ function conflictChoiceToJSON(object) {
|
|
|
3566
3568
|
}
|
|
3567
3569
|
}
|
|
3568
3570
|
function createBaseReasonDetail() {
|
|
3569
|
-
return { reason: 0, api_code: "" };
|
|
3571
|
+
return { reason: 0, api_code: "", request_id: "" };
|
|
3570
3572
|
}
|
|
3571
3573
|
var ReasonDetail = {
|
|
3572
3574
|
encode(message, writer = new import_wire4.BinaryWriter()) {
|
|
@@ -3576,6 +3578,9 @@ var ReasonDetail = {
|
|
|
3576
3578
|
if (message.api_code !== "") {
|
|
3577
3579
|
writer.uint32(18).string(message.api_code);
|
|
3578
3580
|
}
|
|
3581
|
+
if (message.request_id !== "") {
|
|
3582
|
+
writer.uint32(26).string(message.request_id);
|
|
3583
|
+
}
|
|
3579
3584
|
return writer;
|
|
3580
3585
|
},
|
|
3581
3586
|
decode(input, length) {
|
|
@@ -3599,6 +3604,13 @@ var ReasonDetail = {
|
|
|
3599
3604
|
message.api_code = reader.string();
|
|
3600
3605
|
continue;
|
|
3601
3606
|
}
|
|
3607
|
+
case 3: {
|
|
3608
|
+
if (tag !== 26) {
|
|
3609
|
+
break;
|
|
3610
|
+
}
|
|
3611
|
+
message.request_id = reader.string();
|
|
3612
|
+
continue;
|
|
3613
|
+
}
|
|
3602
3614
|
}
|
|
3603
3615
|
if ((tag & 7) === 4 || tag === 0) {
|
|
3604
3616
|
break;
|
|
@@ -3610,7 +3622,8 @@ var ReasonDetail = {
|
|
|
3610
3622
|
fromJSON(object) {
|
|
3611
3623
|
return {
|
|
3612
3624
|
reason: isSet3(object.reason) ? reasonFromJSON(object.reason) : 0,
|
|
3613
|
-
api_code: isSet3(object.apiCode) ? globalThis.String(object.apiCode) : isSet3(object.api_code) ? globalThis.String(object.api_code) : ""
|
|
3625
|
+
api_code: isSet3(object.apiCode) ? globalThis.String(object.apiCode) : isSet3(object.api_code) ? globalThis.String(object.api_code) : "",
|
|
3626
|
+
request_id: isSet3(object.requestId) ? globalThis.String(object.requestId) : isSet3(object.request_id) ? globalThis.String(object.request_id) : ""
|
|
3614
3627
|
};
|
|
3615
3628
|
},
|
|
3616
3629
|
toJSON(message) {
|
|
@@ -3621,6 +3634,9 @@ var ReasonDetail = {
|
|
|
3621
3634
|
if (message.api_code !== "") {
|
|
3622
3635
|
obj.apiCode = message.api_code;
|
|
3623
3636
|
}
|
|
3637
|
+
if (message.request_id !== "") {
|
|
3638
|
+
obj.requestId = message.request_id;
|
|
3639
|
+
}
|
|
3624
3640
|
return obj;
|
|
3625
3641
|
},
|
|
3626
3642
|
create(base) {
|
|
@@ -3630,6 +3646,7 @@ var ReasonDetail = {
|
|
|
3630
3646
|
const message = createBaseReasonDetail();
|
|
3631
3647
|
message.reason = object.reason ?? 0;
|
|
3632
3648
|
message.api_code = object.api_code ?? "";
|
|
3649
|
+
message.request_id = object.request_id ?? "";
|
|
3633
3650
|
return message;
|
|
3634
3651
|
}
|
|
3635
3652
|
};
|
|
@@ -7988,7 +8005,7 @@ var InvokeRequest = {
|
|
|
7988
8005
|
}
|
|
7989
8006
|
};
|
|
7990
8007
|
function createBaseInvokeEvent() {
|
|
7991
|
-
return { json: void 0, exit: void 0 };
|
|
8008
|
+
return { json: void 0, exit: void 0, started: void 0 };
|
|
7992
8009
|
}
|
|
7993
8010
|
var InvokeEvent = {
|
|
7994
8011
|
encode(message, writer = new import_wire4.BinaryWriter()) {
|
|
@@ -7998,6 +8015,9 @@ var InvokeEvent = {
|
|
|
7998
8015
|
if (message.exit !== void 0) {
|
|
7999
8016
|
InvokeExit.encode(message.exit, writer.uint32(18).fork()).join();
|
|
8000
8017
|
}
|
|
8018
|
+
if (message.started !== void 0) {
|
|
8019
|
+
InvokeStarted.encode(message.started, writer.uint32(26).fork()).join();
|
|
8020
|
+
}
|
|
8001
8021
|
return writer;
|
|
8002
8022
|
},
|
|
8003
8023
|
decode(input, length) {
|
|
@@ -8021,6 +8041,13 @@ var InvokeEvent = {
|
|
|
8021
8041
|
message.exit = InvokeExit.decode(reader, reader.uint32());
|
|
8022
8042
|
continue;
|
|
8023
8043
|
}
|
|
8044
|
+
case 3: {
|
|
8045
|
+
if (tag !== 26) {
|
|
8046
|
+
break;
|
|
8047
|
+
}
|
|
8048
|
+
message.started = InvokeStarted.decode(reader, reader.uint32());
|
|
8049
|
+
continue;
|
|
8050
|
+
}
|
|
8024
8051
|
}
|
|
8025
8052
|
if ((tag & 7) === 4 || tag === 0) {
|
|
8026
8053
|
break;
|
|
@@ -8032,7 +8059,8 @@ var InvokeEvent = {
|
|
|
8032
8059
|
fromJSON(object) {
|
|
8033
8060
|
return {
|
|
8034
8061
|
json: isSet3(object.json) ? globalThis.String(object.json) : void 0,
|
|
8035
|
-
exit: isSet3(object.exit) ? InvokeExit.fromJSON(object.exit) : void 0
|
|
8062
|
+
exit: isSet3(object.exit) ? InvokeExit.fromJSON(object.exit) : void 0,
|
|
8063
|
+
started: isSet3(object.started) ? InvokeStarted.fromJSON(object.started) : void 0
|
|
8036
8064
|
};
|
|
8037
8065
|
},
|
|
8038
8066
|
toJSON(message) {
|
|
@@ -8043,6 +8071,9 @@ var InvokeEvent = {
|
|
|
8043
8071
|
if (message.exit !== void 0) {
|
|
8044
8072
|
obj.exit = InvokeExit.toJSON(message.exit);
|
|
8045
8073
|
}
|
|
8074
|
+
if (message.started !== void 0) {
|
|
8075
|
+
obj.started = InvokeStarted.toJSON(message.started);
|
|
8076
|
+
}
|
|
8046
8077
|
return obj;
|
|
8047
8078
|
},
|
|
8048
8079
|
create(base) {
|
|
@@ -8052,6 +8083,44 @@ var InvokeEvent = {
|
|
|
8052
8083
|
const message = createBaseInvokeEvent();
|
|
8053
8084
|
message.json = object.json ?? void 0;
|
|
8054
8085
|
message.exit = object.exit !== void 0 && object.exit !== null ? InvokeExit.fromPartial(object.exit) : void 0;
|
|
8086
|
+
message.started = object.started !== void 0 && object.started !== null ? InvokeStarted.fromPartial(object.started) : void 0;
|
|
8087
|
+
return message;
|
|
8088
|
+
}
|
|
8089
|
+
};
|
|
8090
|
+
function createBaseInvokeStarted() {
|
|
8091
|
+
return {};
|
|
8092
|
+
}
|
|
8093
|
+
var InvokeStarted = {
|
|
8094
|
+
encode(_, writer = new import_wire4.BinaryWriter()) {
|
|
8095
|
+
return writer;
|
|
8096
|
+
},
|
|
8097
|
+
decode(input, length) {
|
|
8098
|
+
const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
|
|
8099
|
+
const end = length === void 0 ? reader.len : reader.pos + length;
|
|
8100
|
+
const message = createBaseInvokeStarted();
|
|
8101
|
+
while (reader.pos < end) {
|
|
8102
|
+
const tag = reader.uint32();
|
|
8103
|
+
switch (tag >>> 3) {
|
|
8104
|
+
}
|
|
8105
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
8106
|
+
break;
|
|
8107
|
+
}
|
|
8108
|
+
reader.skip(tag & 7);
|
|
8109
|
+
}
|
|
8110
|
+
return message;
|
|
8111
|
+
},
|
|
8112
|
+
fromJSON(_) {
|
|
8113
|
+
return {};
|
|
8114
|
+
},
|
|
8115
|
+
toJSON(_) {
|
|
8116
|
+
const obj = {};
|
|
8117
|
+
return obj;
|
|
8118
|
+
},
|
|
8119
|
+
create(base) {
|
|
8120
|
+
return InvokeStarted.fromPartial(base ?? {});
|
|
8121
|
+
},
|
|
8122
|
+
fromPartial(_) {
|
|
8123
|
+
const message = createBaseInvokeStarted();
|
|
8055
8124
|
return message;
|
|
8056
8125
|
}
|
|
8057
8126
|
};
|
|
@@ -10337,8 +10406,9 @@ var LaceEngineService = {
|
|
|
10337
10406
|
responseDeserialize: (value) => ReadWiringCandidatesResponse.decode(value)
|
|
10338
10407
|
},
|
|
10339
10408
|
/**
|
|
10340
|
-
* Runs one CLI command in-process against a fresh command tree.
|
|
10341
|
-
*
|
|
10409
|
+
* Runs one CLI command in-process against a fresh command tree. `started` is first, once the engine has accepted
|
|
10410
|
+
* the request and before the command runs; the command's `-o json` output follows: each top-level JSON value on
|
|
10411
|
+
* stdout is one `json` event; `exit` is always last.
|
|
10342
10412
|
*/
|
|
10343
10413
|
invoke: {
|
|
10344
10414
|
path: "/lace.engine.LaceEngine/Invoke",
|
|
@@ -10654,7 +10724,7 @@ function errorFrame(id, code, message, detail = ReasonDetail.create()) {
|
|
|
10654
10724
|
code,
|
|
10655
10725
|
message,
|
|
10656
10726
|
reason: reasonToJSON(detail.reason),
|
|
10657
|
-
|
|
10727
|
+
...(0, import_proto.apiFields)(detail)
|
|
10658
10728
|
};
|
|
10659
10729
|
}
|
|
10660
10730
|
function statusFrame(id, err) {
|
|
@@ -10742,8 +10812,20 @@ var EXIT_GRACE_MS = 5e3;
|
|
|
10742
10812
|
var VERSION_RE = /^LACE_ENGINE_VERSION=(.+)$/;
|
|
10743
10813
|
var PROTOCOL_RE = /^LACE_ENGINE_PROTOCOL_VERSION=(\d+)$/;
|
|
10744
10814
|
var PORT_RE = /^LACE_ENGINE_PORT=(\d+)$/;
|
|
10745
|
-
var
|
|
10815
|
+
var TOKEN_PREFIX = "LACE_ENGINE_TOKEN=";
|
|
10816
|
+
var TOKEN_RE = new RegExp(`^${TOKEN_PREFIX}([0-9a-fA-F]{64})$`);
|
|
10746
10817
|
var READY_LINE = "LACE_ENGINE_READY";
|
|
10818
|
+
var loggable = (line) => line.startsWith(TOKEN_PREFIX) ? `${TOKEN_PREFIX}<redacted>` : line;
|
|
10819
|
+
var EngineSpawnError = class extends Error {
|
|
10820
|
+
constructor(cause) {
|
|
10821
|
+
super(`Failed to spawn engine: ${cause.message}`);
|
|
10822
|
+
this.cause = cause;
|
|
10823
|
+
this.name = "EngineSpawnError";
|
|
10824
|
+
}
|
|
10825
|
+
get code() {
|
|
10826
|
+
return this.cause.code;
|
|
10827
|
+
}
|
|
10828
|
+
};
|
|
10747
10829
|
function spawnEngine(binaryPath, log) {
|
|
10748
10830
|
return new Promise((resolve, reject) => {
|
|
10749
10831
|
log(`Spawning: ${binaryPath} engine`);
|
|
@@ -10769,17 +10851,17 @@ function spawnEngine(binaryPath, log) {
|
|
|
10769
10851
|
proc.kill();
|
|
10770
10852
|
reject(new Error("Timed out waiting for engine handshake"));
|
|
10771
10853
|
}, HANDSHAKE_TIMEOUT_MS);
|
|
10772
|
-
const fail = (
|
|
10854
|
+
const fail = (error) => {
|
|
10773
10855
|
if (settled) return;
|
|
10774
10856
|
settled = true;
|
|
10775
10857
|
clearTimeout(timer);
|
|
10776
10858
|
rl.close();
|
|
10777
10859
|
proc.kill();
|
|
10778
|
-
reject(
|
|
10860
|
+
reject(error);
|
|
10779
10861
|
};
|
|
10780
10862
|
rl.on("line", (line) => {
|
|
10781
10863
|
if (settled) return;
|
|
10782
|
-
log(`[stdout] ${line}`);
|
|
10864
|
+
log(`[stdout] ${loggable(line)}`);
|
|
10783
10865
|
let match;
|
|
10784
10866
|
match = line.match(VERSION_RE);
|
|
10785
10867
|
if (match) {
|
|
@@ -10803,7 +10885,7 @@ function spawnEngine(binaryPath, log) {
|
|
|
10803
10885
|
}
|
|
10804
10886
|
if (line === READY_LINE) {
|
|
10805
10887
|
if (!version || !protocolVersion || port === void 0 || !token) {
|
|
10806
|
-
fail("Received LACE_ENGINE_READY before all handshake fields were set");
|
|
10888
|
+
fail(new Error("Received LACE_ENGINE_READY before all handshake fields were set"));
|
|
10807
10889
|
return;
|
|
10808
10890
|
}
|
|
10809
10891
|
settled = true;
|
|
@@ -10816,10 +10898,10 @@ function spawnEngine(binaryPath, log) {
|
|
|
10816
10898
|
}
|
|
10817
10899
|
});
|
|
10818
10900
|
proc.on("error", (err) => {
|
|
10819
|
-
fail(
|
|
10901
|
+
fail(new EngineSpawnError(err));
|
|
10820
10902
|
});
|
|
10821
10903
|
proc.on("exit", (code) => {
|
|
10822
|
-
fail(`Engine exited with code ${code} before completing handshake`);
|
|
10904
|
+
fail(new Error(`Engine exited with code ${code} before completing handshake`));
|
|
10823
10905
|
});
|
|
10824
10906
|
});
|
|
10825
10907
|
}
|
|
@@ -10838,14 +10920,16 @@ function endEngine(proc, graceMs = EXIT_GRACE_MS) {
|
|
|
10838
10920
|
|
|
10839
10921
|
// src/rpc-errors.ts
|
|
10840
10922
|
var import_grpc_js2 = require("@grpc/grpc-js");
|
|
10923
|
+
var import_proto2 = require("@lace-cloud/proto");
|
|
10841
10924
|
var RpcError = class extends Error {
|
|
10842
|
-
constructor(message, category, method, cause, reason = 0 /* REASON_UNSPECIFIED */, apiCode) {
|
|
10925
|
+
constructor(message, category, method, cause, reason = 0 /* REASON_UNSPECIFIED */, apiCode, requestId) {
|
|
10843
10926
|
super(message);
|
|
10844
10927
|
this.category = category;
|
|
10845
10928
|
this.method = method;
|
|
10846
10929
|
this.cause = cause;
|
|
10847
10930
|
this.reason = reason;
|
|
10848
10931
|
this.apiCode = apiCode;
|
|
10932
|
+
this.requestId = requestId;
|
|
10849
10933
|
this.name = "RpcError";
|
|
10850
10934
|
}
|
|
10851
10935
|
};
|
|
@@ -10861,13 +10945,15 @@ function classifyRpcError(err, method) {
|
|
|
10861
10945
|
if (err instanceof RpcError) return err;
|
|
10862
10946
|
if (isGrpcServiceError(err)) {
|
|
10863
10947
|
const detail = readReasonDetail(err.metadata);
|
|
10948
|
+
const { apiCode, requestId } = (0, import_proto2.apiFields)(detail);
|
|
10864
10949
|
return new RpcError(
|
|
10865
10950
|
err.details || err.message,
|
|
10866
10951
|
STATUS_CATEGORIES[err.code] ?? "server_error",
|
|
10867
10952
|
method,
|
|
10868
10953
|
err,
|
|
10869
10954
|
detail.reason,
|
|
10870
|
-
|
|
10955
|
+
apiCode,
|
|
10956
|
+
requestId
|
|
10871
10957
|
);
|
|
10872
10958
|
}
|
|
10873
10959
|
return new RpcError(
|
|
@@ -10886,11 +10972,11 @@ function requireClient(client, action) {
|
|
|
10886
10972
|
|
|
10887
10973
|
// src/server-manager.ts
|
|
10888
10974
|
var import_node_events = require("events");
|
|
10889
|
-
var
|
|
10975
|
+
var import_proto4 = require("@lace-cloud/proto");
|
|
10890
10976
|
|
|
10891
10977
|
// src/transport.ts
|
|
10892
10978
|
var grpc = __toESM(require("@grpc/grpc-js"));
|
|
10893
|
-
var
|
|
10979
|
+
var import_proto3 = require("@lace-cloud/proto");
|
|
10894
10980
|
var LaceTransport = class {
|
|
10895
10981
|
constructor(port, token) {
|
|
10896
10982
|
this.token = token;
|
|
@@ -10922,7 +11008,7 @@ var LaceTransport = class {
|
|
|
10922
11008
|
async initialize(clientVersion) {
|
|
10923
11009
|
const res = await this.unary(
|
|
10924
11010
|
this.inner.initialize.bind(this.inner),
|
|
10925
|
-
{ client_version: clientVersion, protocol_version:
|
|
11011
|
+
{ client_version: clientVersion, protocol_version: import_proto3.ENGINE_PROTOCOL_VERSION }
|
|
10926
11012
|
);
|
|
10927
11013
|
return {
|
|
10928
11014
|
serverVersion: res.server_version,
|
|
@@ -10982,7 +11068,9 @@ var ServerManager = class extends import_node_events.EventEmitter {
|
|
|
10982
11068
|
* is compared with the one this library speaks before any RPC is sent
|
|
10983
11069
|
* (`checkEngineProtocol`, `@lace-cloud/proto`, the check the canvas makes
|
|
10984
11070
|
* of `Initialize`'s answer): an engine that names another rejects with
|
|
10985
|
-
* `EngineProtocolMismatchError`.
|
|
11071
|
+
* `EngineProtocolMismatchError`. A binary that cannot be started rejects
|
|
11072
|
+
* with `EngineSpawnError`, whose `code` is the spawn error's (`ENOENT`
|
|
11073
|
+
* when no executable is found).
|
|
10986
11074
|
* An engine a failed start spawned is ended before the rejection.
|
|
10987
11075
|
*/
|
|
10988
11076
|
async start() {
|
|
@@ -11010,7 +11098,7 @@ var ServerManager = class extends import_node_events.EventEmitter {
|
|
|
11010
11098
|
this.maybeRestart();
|
|
11011
11099
|
}
|
|
11012
11100
|
});
|
|
11013
|
-
(0,
|
|
11101
|
+
(0, import_proto4.checkEngineProtocol)(handshake.version, handshake.protocolVersion);
|
|
11014
11102
|
this._handshake = handshake;
|
|
11015
11103
|
this._transport = new LaceTransport(handshake.port, handshake.token);
|
|
11016
11104
|
this._initialized = await this._transport.initialize(handshake.version);
|
|
@@ -11093,7 +11181,9 @@ var ServerManager = class extends import_node_events.EventEmitter {
|
|
|
11093
11181
|
BundleState,
|
|
11094
11182
|
BundleStateEvent,
|
|
11095
11183
|
EngineProtocolMismatchError,
|
|
11184
|
+
EngineSpawnError,
|
|
11096
11185
|
InitializeResponse,
|
|
11186
|
+
InvokeEvent,
|
|
11097
11187
|
InvokeRequest,
|
|
11098
11188
|
LaceTransport,
|
|
11099
11189
|
ReadWiringCandidatesRequest,
|