@nice-code/commander 0.89.0 → 0.91.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/build/cli.cjs +87 -11
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +87 -11
- package/build/cli.mjs.map +1 -1
- package/build/client/assets/index-Caho-x2i.js +23 -0
- package/build/client/assets/{index-BgRBLnvt.js.map → index-Caho-x2i.js.map} +1 -1
- package/build/client/index.html +1 -1
- package/package.json +6 -6
- package/build/client/assets/index-BgRBLnvt.js +0 -23
package/build/cli.mjs
CHANGED
|
@@ -4923,6 +4923,22 @@ var RuntimeCoordinate = class RuntimeCoordinate {
|
|
|
4923
4923
|
withPersistentId(perId) {
|
|
4924
4924
|
return this.specify({ perId });
|
|
4925
4925
|
}
|
|
4926
|
+
/**
|
|
4927
|
+
* Derive a **per-connection** identity: same env and persistent id, with `connectionId` folded into
|
|
4928
|
+
* the per-boot `insId`. For a runtime that opens *several duplex links to the same peer* — a store
|
|
4929
|
+
* socket and a jobs socket on one backend — where one identity for both is a silent misroute: an
|
|
4930
|
+
* acceptor binds a connection by the full coordinate string, so two links presenting the same one
|
|
4931
|
+
* are indistinguishable and the peer's return path picks whichever bound first.
|
|
4932
|
+
*
|
|
4933
|
+
* Folding rather than replacing is the point: the runtime's `insId` stays the per-boot epoch
|
|
4934
|
+
* reliable delivery needs (see {@link IRuntimeCoordinateSpecifics.insId}), so a per-connection id may
|
|
4935
|
+
* safely be a *stable* label (`"jobs"`) — it discriminates connections without pinning the epoch.
|
|
4936
|
+
* Reached from `connectChannel`'s `connectionId` option; rarely called directly.
|
|
4937
|
+
*/
|
|
4938
|
+
withConnectionId(connectionId) {
|
|
4939
|
+
if (connectionId.length === 0 || /[[\]:~]/.test(connectionId)) throw new Error(`RuntimeCoordinate.withConnectionId: "${connectionId}" is not a usable connection id — it must be non-empty and free of \`[\`, \`]\`, \`:\` and \`~\` (the coordinate's own string-form separators).`);
|
|
4940
|
+
return this.specify({ insId: `${this.insId ?? "_"}~${connectionId}` });
|
|
4941
|
+
}
|
|
4926
4942
|
constructor({ envId, perId, insId }) {
|
|
4927
4943
|
this.envId = envId;
|
|
4928
4944
|
this.perId = perId;
|
|
@@ -13121,6 +13137,13 @@ const RELIABLE_CONNECT_RETRY_MS = 1e3;
|
|
|
13121
13137
|
* (so `connectChannel` and a realm-only `createWireClient` are one connection implementation).
|
|
13122
13138
|
*/
|
|
13123
13139
|
var ChannelConnector = class extends PeerLink {
|
|
13140
|
+
/**
|
|
13141
|
+
* This connection's own identity when it was given one (`connectChannel`'s `connectionId`), used
|
|
13142
|
+
* in place of the local runtime's coordinate as the origin stamped on outgoing frames — matching
|
|
13143
|
+
* the identity the handshake bound, so the peer's return path finds *this* socket. `undefined` ⇒
|
|
13144
|
+
* the connection speaks as the runtime, which is the single-link default.
|
|
13145
|
+
*/
|
|
13146
|
+
_connectionIdentity;
|
|
13124
13147
|
_defaultTimeout;
|
|
13125
13148
|
_reliableTimeout;
|
|
13126
13149
|
/**
|
|
@@ -13198,15 +13221,16 @@ var ChannelConnector = class extends PeerLink {
|
|
|
13198
13221
|
_controlMethods;
|
|
13199
13222
|
/** Stream-level reliable-delivery observers (see {@link TReliableStreamEvent}). */
|
|
13200
13223
|
_reliableEventListeners = /* @__PURE__ */ new Set();
|
|
13201
|
-
constructor({ runtimeCoordinate: peerSpecifier, transports, defaultTimeout, reliableActionTimeout, wireMux, localCoordinate, securityLevel, keepLinkAlive }) {
|
|
13224
|
+
constructor({ runtimeCoordinate: peerSpecifier, transports, defaultTimeout, reliableActionTimeout, wireMux, localCoordinate, connectionIdentity, securityLevel, keepLinkAlive }) {
|
|
13202
13225
|
super(peerSpecifier);
|
|
13226
|
+
this._connectionIdentity = connectionIdentity;
|
|
13203
13227
|
this._defaultTimeout = defaultTimeout ?? 1e4;
|
|
13204
13228
|
this._reliableTimeout = reliableActionTimeout ?? DEFAULT_RELIABLE_ACTION_TIMEOUT;
|
|
13205
13229
|
this._wire = new WireClient({
|
|
13206
13230
|
createManager: (cache) => new ConnectionTransportManager(cache),
|
|
13207
13231
|
mux: wireMux,
|
|
13208
13232
|
peer: this.peerClient,
|
|
13209
|
-
localCoordinate,
|
|
13233
|
+
localCoordinate: connectionIdentity ?? localCoordinate,
|
|
13210
13234
|
securityLevel,
|
|
13211
13235
|
canPush: transports.some((transport) => transport.type === "duplex"),
|
|
13212
13236
|
keepLinkAlive,
|
|
@@ -13244,7 +13268,7 @@ var ChannelConnector = class extends PeerLink {
|
|
|
13244
13268
|
* `err_wire_connect`).
|
|
13245
13269
|
*/
|
|
13246
13270
|
async connect(config) {
|
|
13247
|
-
await this._wire.connect({ localCoordinate: config?.targetLocalRuntime?.coordinate });
|
|
13271
|
+
await this._wire.connect({ localCoordinate: this._connectionIdentity ?? config?.targetLocalRuntime?.coordinate });
|
|
13248
13272
|
}
|
|
13249
13273
|
/**
|
|
13250
13274
|
* Tear down the (possibly half-open) duplex link and immediately re-dial it (DESYNC F6 / Phase
|
|
@@ -13264,7 +13288,8 @@ var ChannelConnector = class extends PeerLink {
|
|
|
13264
13288
|
}
|
|
13265
13289
|
async handleActionRequest(action, config) {
|
|
13266
13290
|
const localRuntime = config?.targetLocalRuntime ?? ActionRuntime.getDefault();
|
|
13267
|
-
const localClient = localRuntime.coordinate;
|
|
13291
|
+
const localClient = this._connectionIdentity ?? localRuntime.coordinate;
|
|
13292
|
+
if (this._connectionIdentity != null) action.context._setOriginClient(this._connectionIdentity);
|
|
13268
13293
|
const incomingTimeout = config?.timeout ?? this._defaultTimeout;
|
|
13269
13294
|
const parentCuid = peekHandlerCuid();
|
|
13270
13295
|
const callSite = action._callSite ?? (/* @__PURE__ */ new Error()).stack;
|
|
@@ -13564,7 +13589,7 @@ var ChannelConnector = class extends PeerLink {
|
|
|
13564
13589
|
* Returns `true` if the payload was sent, `false` if no suitable transport was available.
|
|
13565
13590
|
*/
|
|
13566
13591
|
async sendReturnPayload(payload, config) {
|
|
13567
|
-
const localClient = config.targetLocalRuntime.coordinate;
|
|
13592
|
+
const localClient = this._connectionIdentity ?? config.targetLocalRuntime.coordinate;
|
|
13568
13593
|
try {
|
|
13569
13594
|
const { methods } = await this._wire.getReadyTransport({
|
|
13570
13595
|
action: payload,
|
|
@@ -13820,6 +13845,7 @@ var ActionRuntime = class {
|
|
|
13820
13845
|
reliableActionTimeout: options.reliableActionTimeout,
|
|
13821
13846
|
wireMux: options.wireMux,
|
|
13822
13847
|
localCoordinate: this.coordinate,
|
|
13848
|
+
connectionIdentity: options.connectionIdentity,
|
|
13823
13849
|
securityLevel: options.securityLevel,
|
|
13824
13850
|
keepLinkAlive: options.keepLinkAlive
|
|
13825
13851
|
});
|
|
@@ -15905,7 +15931,7 @@ function transport(options) {
|
|
|
15905
15931
|
security = {
|
|
15906
15932
|
securityLevel: options.securityLevel ?? "authenticated",
|
|
15907
15933
|
link,
|
|
15908
|
-
localCoordinate: options.runtime.coordinate.toJsonObject(),
|
|
15934
|
+
localCoordinate: (options.identity ?? options.runtime.coordinate).toJsonObject(),
|
|
15909
15935
|
dictionaryVersion: channel.dictionaryVersion,
|
|
15910
15936
|
channelTags: channel.tags,
|
|
15911
15937
|
mux: options.mux
|
|
@@ -15986,6 +16012,34 @@ function defineChannel(options = {}) {
|
|
|
15986
16012
|
};
|
|
15987
16013
|
}
|
|
15988
16014
|
/**
|
|
16015
|
+
* Identities already dialled per (runtime, peer) — the check behind the several-links-one-identity
|
|
16016
|
+
* warning below. Keyed off the runtime weakly so a torn-down runtime takes its entry with it.
|
|
16017
|
+
*/
|
|
16018
|
+
const dialledIdentities = /* @__PURE__ */ new WeakMap();
|
|
16019
|
+
/**
|
|
16020
|
+
* The several-duplex-links trap (Vibenode feedback §1): a second `connectChannel` from one runtime to
|
|
16021
|
+
* one peer presenting the *same* identity is invisible to the acceptor — it binds connections by the
|
|
16022
|
+
* full coordinate string — so replies and pushes for both links go back over whichever bound first and
|
|
16023
|
+
* the other socket's traffic hangs until it times out. Silent, and it looks like a backend stall.
|
|
16024
|
+
*
|
|
16025
|
+
* Warn at dial time rather than at the misroute: this fires deterministically at setup, before any
|
|
16026
|
+
* traffic, and names the fix. Duplex connections only — the caller gates on that.
|
|
16027
|
+
*/
|
|
16028
|
+
function warnOnSharedConnectionIdentity(runtime, peer, identity) {
|
|
16029
|
+
let byPeer = dialledIdentities.get(runtime);
|
|
16030
|
+
if (byPeer == null) {
|
|
16031
|
+
byPeer = /* @__PURE__ */ new Map();
|
|
16032
|
+
dialledIdentities.set(runtime, byPeer);
|
|
16033
|
+
}
|
|
16034
|
+
const identities = byPeer.get(peer.stringId) ?? /* @__PURE__ */ new Set();
|
|
16035
|
+
byPeer.set(peer.stringId, identities);
|
|
16036
|
+
if (identities.has(identity.stringId)) {
|
|
16037
|
+
console.warn(`connectChannel: this runtime already has a connection to [${peer.stringId}] dialling as [${identity.stringId}]. The peer binds each connection by that identity, so it cannot tell the two apart: every reply and push for both goes back over whichever connected first, and the other link's traffic hangs until it times out. Give each connection its own \`connectionId\` (e.g. \`connectChannel(runtime, jobsChannel, { connectionId: "jobs", … })\`) — or, if they carry the same routes over one link, use \`connectChannels\`.`);
|
|
16038
|
+
return;
|
|
16039
|
+
}
|
|
16040
|
+
identities.add(identity.stringId);
|
|
16041
|
+
}
|
|
16042
|
+
/**
|
|
15989
16043
|
* Open a connection to a peer from a single call — the dial-out dual of `serveChannel`. The channel is
|
|
15990
16044
|
* the single source of truth for *what* is routed (`toAcceptor` domains forwarded to the peer,
|
|
15991
16045
|
* `toConnector` pushes handled locally from `onPush`); the call binds the shared facts — the channel's
|
|
@@ -16005,10 +16059,12 @@ function defineChannel(options = {}) {
|
|
|
16005
16059
|
function connectChannel(runtime, channel, options) {
|
|
16006
16060
|
const securityLevel = options.securityLevel ?? "authenticated";
|
|
16007
16061
|
const anySecure = options.transports.some((transport) => transport.secure ?? true);
|
|
16062
|
+
const connectionIdentity = options.connectionId != null ? runtime.coordinate.withConnectionId(options.connectionId) : void 0;
|
|
16063
|
+
if (options.transports.some((descriptor) => !isExchangeCarrierSource(descriptor.carrier))) warnOnSharedConnectionIdentity(runtime, options.peer, connectionIdentity ?? runtime.coordinate);
|
|
16008
16064
|
const { mux: wireMux, link, resolveLinkKeepalive, wireTap } = assembleWireConnectionParts({
|
|
16009
16065
|
callerName: "connectChannel",
|
|
16010
16066
|
peer: options.peer,
|
|
16011
|
-
identity: runtime.coordinate,
|
|
16067
|
+
identity: connectionIdentity ?? runtime.coordinate,
|
|
16012
16068
|
mux: options.wireMux,
|
|
16013
16069
|
protocols: options.protocols,
|
|
16014
16070
|
anySecure,
|
|
@@ -16024,6 +16080,7 @@ function connectChannel(runtime, channel, options) {
|
|
|
16024
16080
|
carrier: descriptor.carrier,
|
|
16025
16081
|
channel,
|
|
16026
16082
|
runtime,
|
|
16083
|
+
identity: connectionIdentity,
|
|
16027
16084
|
secure: descriptor.secure ?? true,
|
|
16028
16085
|
link,
|
|
16029
16086
|
securityLevel: descriptor.securityLevel ?? securityLevel,
|
|
@@ -16045,7 +16102,8 @@ function connectChannel(runtime, channel, options) {
|
|
|
16045
16102
|
reliableActionTimeout: options.reliableActionTimeout,
|
|
16046
16103
|
wireMux,
|
|
16047
16104
|
securityLevel: connectionSecurityLevel,
|
|
16048
|
-
keepLinkAlive: options.keepLinkAlive
|
|
16105
|
+
keepLinkAlive: options.keepLinkAlive,
|
|
16106
|
+
connectionIdentity
|
|
16049
16107
|
});
|
|
16050
16108
|
if (options.onReliableEvent != null) handler.addReliableEventListener(options.onReliableEvent);
|
|
16051
16109
|
if (options.onLinkEvent != null) handler.addLinkEventListener(options.onLinkEvent);
|
|
@@ -16225,6 +16283,14 @@ function createActionFetchHandler(runtime, options = {}) {
|
|
|
16225
16283
|
status: 400,
|
|
16226
16284
|
headers: { "Content-Type": "application/json" }
|
|
16227
16285
|
});
|
|
16286
|
+
const envelopeReply = (reply) => new Response(encodeExchange(reply), {
|
|
16287
|
+
status: 200,
|
|
16288
|
+
headers: { "Content-Type": "application/json" }
|
|
16289
|
+
});
|
|
16290
|
+
const envelopeError = (message) => envelopeReply({
|
|
16291
|
+
k: "err",
|
|
16292
|
+
message
|
|
16293
|
+
});
|
|
16228
16294
|
return async (request) => {
|
|
16229
16295
|
if (request.method === "OPTIONS") return withCors(new Response(null, { status: 204 }));
|
|
16230
16296
|
const url = new URL(request.url);
|
|
@@ -16238,12 +16304,18 @@ function createActionFetchHandler(runtime, options = {}) {
|
|
|
16238
16304
|
headers: { "Content-Type": "application/json" }
|
|
16239
16305
|
}));
|
|
16240
16306
|
}
|
|
16307
|
+
const text = await request.text();
|
|
16308
|
+
const envelope = decodeExchangeRequest(text);
|
|
16309
|
+
if (envelope?.k === "hs") return withCors(envelopeError("plain endpoint: no handshake here — connect with `{ carrier: httpCarrier(...), secure: false }`"));
|
|
16310
|
+
if (envelope != null && "c" in envelope) return withCors(envelopeError("plain endpoint: cannot open an encrypted frame"));
|
|
16241
16311
|
let body;
|
|
16242
|
-
|
|
16243
|
-
|
|
16312
|
+
if (envelope != null) body = envelope.w;
|
|
16313
|
+
else try {
|
|
16314
|
+
body = JSON.parse(text);
|
|
16244
16315
|
} catch {
|
|
16245
16316
|
return withCors(badRequest("request body is not valid JSON"));
|
|
16246
16317
|
}
|
|
16318
|
+
const answerError = (message) => envelope != null ? envelopeError(message) : badRequest(message);
|
|
16247
16319
|
const report = options.logger != null && isActionPayload_Any_JsonObject(body) && body.type === "request" ? options.logger.onRequest(actionServeRequestInfo(body, { transport: transportLabel })) : void 0;
|
|
16248
16320
|
const startedAt = Date.now();
|
|
16249
16321
|
let running;
|
|
@@ -16257,7 +16329,7 @@ function createActionFetchHandler(runtime, options = {}) {
|
|
|
16257
16329
|
durationMs: Date.now() - startedAt,
|
|
16258
16330
|
error: serveResultErrorInfo(error)
|
|
16259
16331
|
});
|
|
16260
|
-
return withCors(
|
|
16332
|
+
return withCors(answerError(error.message));
|
|
16261
16333
|
}
|
|
16262
16334
|
throw error;
|
|
16263
16335
|
}
|
|
@@ -16272,6 +16344,10 @@ function createActionFetchHandler(runtime, options = {}) {
|
|
|
16272
16344
|
durationMs: Date.now() - startedAt,
|
|
16273
16345
|
error: serveResultErrorInfo(result.result.error)
|
|
16274
16346
|
});
|
|
16347
|
+
if (envelope != null) return withCors(envelopeReply({
|
|
16348
|
+
k: "act",
|
|
16349
|
+
w: result.toJsonObject()
|
|
16350
|
+
}));
|
|
16275
16351
|
return withCors(result.toHttpResponse({ useErrorStatus: options.useErrorStatus }));
|
|
16276
16352
|
}
|
|
16277
16353
|
return withCors(new Response("Not found", { status: 404 }));
|