@sjawhar/claude-envoy 4.21.1 → 4.22.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/.claude-plugin/plugin.json +1 -1
- package/.omp-plugin/plugin.json +1 -1
- package/README.md +20 -7
- package/dist/codex-hook.js +87 -112
- package/dist/dispatch.js +91 -115
- package/dist/envoy-channel.js +1827 -1138
- package/dist/session-hook.js +87 -112
- package/package.json +1 -1
- package/src/agent-stream-runner.ts +5 -0
- package/src/channel-connection.ts +110 -12
- package/src/channel-topics.ts +26 -39
- package/src/codex/codex-agent-stream.ts +4 -0
- package/src/codex/codex-server.ts +14 -5
- package/src/control-subscription.ts +8 -1
- package/src/envoy-channel-server.ts +46 -7
package/.omp-plugin/plugin.json
CHANGED
package/README.md
CHANGED
|
@@ -532,15 +532,28 @@ token beside it, and its token only beside its own server. An `envoy` section in
|
|
|
532
532
|
file is not read, which the channel server's notice says, and a checkout's file that is not valid
|
|
533
533
|
refuses Dispatch alone, only while `DISPATCH_URL` is unset. The chosen file's `dispatch` section
|
|
534
534
|
(`enabled`, `serverUrl`, `token`) and `envoy` section (`enabled`, `url`, `natsUrls`, `token`,
|
|
535
|
-
`natsSeed`, `natsAuth`) are resolved each on its own; `enabled: false` turns one off, a
|
|
536
|
-
contributes nothing (each section is then on only when its variables name it), and a
|
|
537
|
-
`natsSeed` starting with `!` is a command whose trimmed output is the value.
|
|
538
|
-
`DISPATCH_TOKEN_FILE`, `DISPATCH_TOKEN`, `ENVOY_URL`, `ENVOY_NATS_URL`,
|
|
539
|
-
`ENVOY_TOKEN`, `NATS_NKEY_SEED_FILE`, `NATS_NKEY_SEED
|
|
540
|
-
field; a file's token or seed goes with a variable's server
|
|
535
|
+
`natsSeed`, `natsAuth`, `inbound`) are resolved each on its own; `enabled: false` turns one off, a
|
|
536
|
+
missing file contributes nothing (each section is then on only when its variables name it), and a
|
|
537
|
+
`token` or `natsSeed` starting with `!` is a command whose trimmed output is the value.
|
|
538
|
+
`DISPATCH_URL`, `DISPATCH_TOKEN_FILE`, `DISPATCH_TOKEN`, `ENVOY_URL`, `ENVOY_NATS_URL`,
|
|
539
|
+
`ENVOY_TOKEN_FILE`, `ENVOY_TOKEN`, `NATS_NKEY_SEED_FILE`, `NATS_NKEY_SEED`, `NATS_AUTH` and
|
|
540
|
+
`ENVOY_INBOUND` each override their own field; a file's token or seed goes with a variable's server
|
|
541
|
+
only when it is the file's own. With
|
|
541
542
|
`NATS_AUTH=broker` and no seed the NATS connection presents the session's own broker token, which
|
|
542
543
|
a hub's NATS auth service admits to that session's subjects alone, and a `/clear` moves it to the
|
|
543
|
-
new id's token before the new id's relay subject is subscribed.
|
|
544
|
+
new id's token before the new id's relay subject is subscribed. With `ENVOY_INBOUND=listener` (or
|
|
545
|
+
`"inbound": "listener"`), a Claude Code or Codex session takes its inbound messages through the
|
|
546
|
+
listener's relay socket, `<ENVOY_URL>/v1/sessions/<id>/relay`, over HTTPS alone, with the session's
|
|
547
|
+
own broker token, rather than over NATS, and a `/clear` or `/new` opens the socket again for the
|
|
548
|
+
new id; it is refused beside `ENVOY_NATS_URL` or `envoy.natsUrls`, naming both, with a bearer for
|
|
549
|
+
the listener, with no broker route, and for a process that names no session. With the setting, a
|
|
550
|
+
listener at a plain http address of another machine turns Envoy off as a whole, its tools
|
|
551
|
+
included, a NATS server named or not (the token would cross the network unencrypted; a conflict
|
|
552
|
+
with a NATS server is named first; this machine's own listener may be plain http, and a session
|
|
553
|
+
not set to `listener` keeps plain http). The
|
|
554
|
+
socket carries no agent stream, so neither live view
|
|
555
|
+
takes its control subject and the Agents page shows nothing of the session's turns, which the
|
|
556
|
+
start notice says. The `open-asks` hook
|
|
544
557
|
hands the file on to the session's Bash as `ENVOY_CONFIG_FILE` beside `DISPATCH_HOST=claude`, and
|
|
545
558
|
the `dispatch` command reads the file `ENVOY_CONFIG_FILE` names whenever `DISPATCH_HOST` is set; a
|
|
546
559
|
Bash with neither, as a subagent's can be, has `CLAUDE_CODE_CHILD_SESSION=1` and takes this plugin's
|
package/dist/codex-hook.js
CHANGED
|
@@ -13848,6 +13848,7 @@ var IDEMPOTENCY_KEY_HEADER = "Idempotency-Key";
|
|
|
13848
13848
|
var IDEMPOTENCY_REPLAYED_HEADER = "Idempotency-Replayed";
|
|
13849
13849
|
var IDEMPOTENCY_KEY_MAX = 128;
|
|
13850
13850
|
var IDEMPOTENCY_KEY_PATTERN = new RegExp(`^[A-Za-z0-9._:-]{1,${IDEMPOTENCY_KEY_MAX}}$`);
|
|
13851
|
+
var IDEMPOTENCY_KEY_REUSED = "KEY_REUSED";
|
|
13851
13852
|
var IDEMPOTENCY_KEY_IN_FLIGHT = "KEY_IN_FLIGHT";
|
|
13852
13853
|
var IDEMPOTENCY_KEY_COMMITTED = "KEY_COMMITTED";
|
|
13853
13854
|
var IDEMPOTENCY_ANSWER_NOT_KEPT = "ANSWER_NOT_KEPT";
|
|
@@ -19216,7 +19217,8 @@ var EnvoySectionSchema = strictObject({
|
|
|
19216
19217
|
natsUrls: array(string2().trim().min(1, "must not be empty")).optional(),
|
|
19217
19218
|
token: string2().optional(),
|
|
19218
19219
|
natsSeed: string2().optional(),
|
|
19219
|
-
natsAuth: string2().optional()
|
|
19220
|
+
natsAuth: string2().optional(),
|
|
19221
|
+
inbound: string2().optional()
|
|
19220
19222
|
});
|
|
19221
19223
|
var EnvoyFileSchema = looseObject({
|
|
19222
19224
|
$schema: string2().optional(),
|
|
@@ -19674,7 +19676,7 @@ class DispatchWriteUnsettledError extends Error {
|
|
|
19674
19676
|
attempts;
|
|
19675
19677
|
key;
|
|
19676
19678
|
name = "DispatchWriteUnsettledError";
|
|
19677
|
-
constructor(last, attempts, key, unanswered
|
|
19679
|
+
constructor(last, attempts, key, unanswered) {
|
|
19678
19680
|
let answer;
|
|
19679
19681
|
let why = last instanceof DispatchServiceError && last.status >= 500 ? "an attempt of the write may have reached Dispatch" : "an earlier attempt of the write may have reached Dispatch";
|
|
19680
19682
|
if (last instanceof DispatchGatewayError) {
|
|
@@ -19689,10 +19691,7 @@ class DispatchWriteUnsettledError extends Error {
|
|
|
19689
19691
|
why = "an attempt of the write may have reached Dispatch";
|
|
19690
19692
|
}
|
|
19691
19693
|
const tried = attempts === 1 ? "its only attempt" : `the last of ${attempts} attempts`;
|
|
19692
|
-
|
|
19693
|
-
super(`${answer} (${tried}), and ${why}, so it may or may not have taken effect${next}`, {
|
|
19694
|
-
cause: last
|
|
19695
|
-
});
|
|
19694
|
+
super(`${answer} (${tried}), and ${why}, so it may or may not have taken effect. Dispatch ` + "finishes an attempt it received whatever this command does, so read the write back " + "before you send it again: a new command sends it under a new key.", { cause: last });
|
|
19696
19695
|
this.last = last;
|
|
19697
19696
|
this.attempts = attempts;
|
|
19698
19697
|
this.key = key;
|
|
@@ -19781,43 +19780,6 @@ function retryAfterMs(response) {
|
|
|
19781
19780
|
const at = Date.parse(value);
|
|
19782
19781
|
return Number.isNaN(at) ? 0 : Math.max(0, at - Date.now());
|
|
19783
19782
|
}
|
|
19784
|
-
var KEYED_LAYER_MEMORY_MS = 5 * 60000;
|
|
19785
|
-
var KEYED_LAYER_SEEN = new Map;
|
|
19786
|
-
var KEYED_LAYER_PROBES = new Map;
|
|
19787
|
-
var KEY_LAYER_PROBE_MS = 5000;
|
|
19788
|
-
function keyedLayerMemory() {
|
|
19789
|
-
const wall = Date.now();
|
|
19790
|
-
const now = performance.now();
|
|
19791
|
-
const kept = {};
|
|
19792
|
-
for (const [origin, seen] of KEYED_LAYER_SEEN) {
|
|
19793
|
-
const age = now - seen;
|
|
19794
|
-
if (age >= 0 && age < KEYED_LAYER_MEMORY_MS) {
|
|
19795
|
-
kept[origin] = new Date(wall - age).toISOString();
|
|
19796
|
-
}
|
|
19797
|
-
}
|
|
19798
|
-
return kept;
|
|
19799
|
-
}
|
|
19800
|
-
function rememberKeyedLayer(saved) {
|
|
19801
|
-
if (typeof saved !== "object" || saved === null)
|
|
19802
|
-
return;
|
|
19803
|
-
const wall = Date.now();
|
|
19804
|
-
const now = performance.now();
|
|
19805
|
-
for (const [origin, at] of Object.entries(saved)) {
|
|
19806
|
-
if (typeof at !== "string")
|
|
19807
|
-
continue;
|
|
19808
|
-
const age = wall - Date.parse(at);
|
|
19809
|
-
if (!(age >= 0 && age < KEYED_LAYER_MEMORY_MS))
|
|
19810
|
-
continue;
|
|
19811
|
-
const seen = now - age;
|
|
19812
|
-
const known = KEYED_LAYER_SEEN.get(origin);
|
|
19813
|
-
if (known === undefined || known < seen)
|
|
19814
|
-
KEYED_LAYER_SEEN.set(origin, seen);
|
|
19815
|
-
}
|
|
19816
|
-
}
|
|
19817
|
-
function keyEchoed(response, key) {
|
|
19818
|
-
const echoed = response.headers.get(IDEMPOTENCY_KEY_HEADER)?.trim() ?? "";
|
|
19819
|
-
return echoed.replace(/^"(.*)"$/, "$1") === key;
|
|
19820
|
-
}
|
|
19821
19783
|
var STREAMED_BODY_MIN = 1 << 20;
|
|
19822
19784
|
var STREAMED_BODY_CHUNK = 64 << 10;
|
|
19823
19785
|
function attemptBody(body, headers, progress) {
|
|
@@ -19856,17 +19818,18 @@ function parsedJson(response, text) {
|
|
|
19856
19818
|
}
|
|
19857
19819
|
}
|
|
19858
19820
|
var NULL_BODY_STATUSES = new Set([101, 204, 205, 304]);
|
|
19859
|
-
async function writeAnswer(response
|
|
19821
|
+
async function writeAnswer(response) {
|
|
19860
19822
|
if (NULL_BODY_STATUSES.has(response.status)) {
|
|
19861
19823
|
return {
|
|
19862
19824
|
response,
|
|
19863
|
-
echoed,
|
|
19864
19825
|
malformed: false,
|
|
19865
19826
|
notJson: false,
|
|
19866
19827
|
text: "",
|
|
19867
19828
|
json: undefined,
|
|
19868
19829
|
code: undefined,
|
|
19869
|
-
error: undefined
|
|
19830
|
+
error: undefined,
|
|
19831
|
+
replayed: response.headers.get(IDEMPOTENCY_REPLAYED_HEADER)?.trim() === "?1",
|
|
19832
|
+
keyEcho: response.headers.get(IDEMPOTENCY_KEY_HEADER) ?? undefined
|
|
19870
19833
|
};
|
|
19871
19834
|
}
|
|
19872
19835
|
const text = await response.text();
|
|
@@ -19876,23 +19839,27 @@ async function writeAnswer(response, echoed) {
|
|
|
19876
19839
|
const own = typeof shape.error === "string";
|
|
19877
19840
|
return {
|
|
19878
19841
|
response,
|
|
19879
|
-
echoed,
|
|
19880
19842
|
malformed: text !== "" && typed && json === undefined,
|
|
19881
19843
|
notJson: text === "" || !typed,
|
|
19882
19844
|
text,
|
|
19883
19845
|
json,
|
|
19884
19846
|
code: own ? shape.code : undefined,
|
|
19885
|
-
error: own ? shape.error : undefined
|
|
19847
|
+
error: own ? shape.error : undefined,
|
|
19848
|
+
replayed: response.headers.get(IDEMPOTENCY_REPLAYED_HEADER)?.trim() === "?1",
|
|
19849
|
+
keyEcho: response.headers.get(IDEMPOTENCY_KEY_HEADER) ?? undefined
|
|
19886
19850
|
};
|
|
19887
19851
|
}
|
|
19888
|
-
function
|
|
19852
|
+
function isStoredKeyStatus(status) {
|
|
19853
|
+
return status >= 400 && status < 500 && status !== 401 && status !== 408 && status !== 429;
|
|
19854
|
+
}
|
|
19855
|
+
function answerEvent(answer, requestKey, keyEchoed, canTellDeadToken) {
|
|
19889
19856
|
const { status } = answer.response;
|
|
19890
19857
|
if (status >= 200 && status < 300) {
|
|
19891
19858
|
if (answer.notJson)
|
|
19892
19859
|
return "foreign-2xx";
|
|
19893
19860
|
if (answer.malformed)
|
|
19894
19861
|
return "body-malformed";
|
|
19895
|
-
return
|
|
19862
|
+
return keyEchoed && answer.keyEcho !== requestKey ? "foreign-2xx" : "applied";
|
|
19896
19863
|
}
|
|
19897
19864
|
if (status >= 300 && status < 400)
|
|
19898
19865
|
return "redirect";
|
|
@@ -19907,7 +19874,13 @@ function answerEvent(answer, canTellDeadToken, layerKnown) {
|
|
|
19907
19874
|
return "in-flight";
|
|
19908
19875
|
return status >= 500 ? "server-error" : "try-later";
|
|
19909
19876
|
}
|
|
19910
|
-
|
|
19877
|
+
if (answer.replayed || answer.code === IDEMPOTENCY_KEY_COMMITTED)
|
|
19878
|
+
return "judged";
|
|
19879
|
+
if (answer.keyEcho !== requestKey || !isStoredKeyStatus(status))
|
|
19880
|
+
return "unjudged";
|
|
19881
|
+
if (answer.code === IDEMPOTENCY_KEY_REUSED)
|
|
19882
|
+
return "judged";
|
|
19883
|
+
return answer.code === IDEMPOTENCY_KEY_IN_FLIGHT ? "unjudged" : "judged";
|
|
19911
19884
|
}
|
|
19912
19885
|
function credentialEvent(error) {
|
|
19913
19886
|
return error instanceof TradeRetryingError ? "no-credential" : "no-credential-final";
|
|
@@ -20493,7 +20466,7 @@ class DispatchClient {
|
|
|
20493
20466
|
key: key ?? crypto.randomUUID(),
|
|
20494
20467
|
request: `${method} ${requestForText(this.#baseUrl, url, DISPATCH_URL_SETTING)}`,
|
|
20495
20468
|
writes,
|
|
20496
|
-
progress: { sent: 0, running: false,
|
|
20469
|
+
progress: { sent: 0, running: false, keyEchoed: false }
|
|
20497
20470
|
};
|
|
20498
20471
|
}
|
|
20499
20472
|
async#upload(path, input, key) {
|
|
@@ -20511,12 +20484,12 @@ class DispatchClient {
|
|
|
20511
20484
|
form.set("file", input.file, input.name);
|
|
20512
20485
|
return this.#form("POST", path, form, key);
|
|
20513
20486
|
}
|
|
20514
|
-
async#form(method, path, form,
|
|
20487
|
+
async#form(method, path, form, callerKey) {
|
|
20515
20488
|
const url = this.#url(path);
|
|
20516
20489
|
const encoded = new Response(form);
|
|
20517
20490
|
const type = encoded.headers.get("Content-Type") ?? "multipart/form-data";
|
|
20518
20491
|
const body = { content: new Uint8Array(await encoded.arrayBuffer()), type };
|
|
20519
|
-
const write = this.#writeCall(method, url,
|
|
20492
|
+
const write = this.#writeCall(method, url, callerKey);
|
|
20520
20493
|
if (write !== undefined) {
|
|
20521
20494
|
const answer = await this.#write(method, url, body, "application/json", undefined, write);
|
|
20522
20495
|
return this.#payloadOf(method, url, answer);
|
|
@@ -20601,14 +20574,12 @@ class DispatchClient {
|
|
|
20601
20574
|
sent
|
|
20602
20575
|
};
|
|
20603
20576
|
}
|
|
20604
|
-
const
|
|
20605
|
-
|
|
20606
|
-
|
|
20607
|
-
KEYED_LAYER_SEEN.set(this.#baseUrl, this.#now());
|
|
20608
|
-
progress.sawKeyedLayer ||= echoed;
|
|
20577
|
+
const heard = { retryAfterMs: retryAfterMs(response) };
|
|
20578
|
+
if (response.headers.get(IDEMPOTENCY_KEY_HEADER) === key)
|
|
20579
|
+
progress.keyEchoed = true;
|
|
20609
20580
|
let answer;
|
|
20610
20581
|
try {
|
|
20611
|
-
answer = await writeAnswer(response
|
|
20582
|
+
answer = await writeAnswer(response);
|
|
20612
20583
|
} catch (error) {
|
|
20613
20584
|
const stop = stoppedEvent(limit, true, error);
|
|
20614
20585
|
return {
|
|
@@ -20620,7 +20591,7 @@ class DispatchClient {
|
|
|
20620
20591
|
};
|
|
20621
20592
|
}
|
|
20622
20593
|
return {
|
|
20623
|
-
event: answerEvent(answer, this.#credential.stale !== undefined && !deadTokenTold
|
|
20594
|
+
event: answerEvent(answer, write.key, progress.keyEchoed, this.#credential.stale !== undefined && !deadTokenTold),
|
|
20624
20595
|
answer,
|
|
20625
20596
|
presented,
|
|
20626
20597
|
sent,
|
|
@@ -20685,16 +20656,7 @@ class DispatchClient {
|
|
|
20685
20656
|
const scheduled = progress.running ? Math.min(pausesMs[paced - 1] ?? inFlightPauseMs, inFlightPauseMs) : pausesMs[paced - 1];
|
|
20686
20657
|
const wait = Math.max(scheduled ?? 0, last.heard?.retryAfterMs ?? 0);
|
|
20687
20658
|
const latest = Math.min(started + (progress.running ? inFlightWithinMs : withinMs), lastAsk);
|
|
20688
|
-
|
|
20689
|
-
const { answer } = last;
|
|
20690
|
-
const unjudged = answer !== undefined && !answer.echoed && answer.error !== undefined;
|
|
20691
|
-
if (again && state === "may-have-landed") {
|
|
20692
|
-
again = (last.heard?.echoed ?? false) || await this.#runsKeyedLayer(unjudged);
|
|
20693
|
-
progress.sawKeyedLayer ||= again;
|
|
20694
|
-
again &&= this.#now() + wait <= latest;
|
|
20695
|
-
} else if (unjudged && state === "nothing-sent") {
|
|
20696
|
-
KEYED_LAYER_SEEN.delete(this.#baseUrl);
|
|
20697
|
-
}
|
|
20659
|
+
const again = scheduled !== undefined && this.#now() + wait <= latest;
|
|
20698
20660
|
if (!again) {
|
|
20699
20661
|
event = "exhausted";
|
|
20700
20662
|
continue;
|
|
@@ -20718,10 +20680,6 @@ class DispatchClient {
|
|
|
20718
20680
|
}
|
|
20719
20681
|
}
|
|
20720
20682
|
}
|
|
20721
|
-
#remembersKeyedLayer() {
|
|
20722
|
-
const seen = KEYED_LAYER_SEEN.get(this.#baseUrl);
|
|
20723
|
-
return seen !== undefined && this.#now() - seen < KEYED_LAYER_MEMORY_MS;
|
|
20724
|
-
}
|
|
20725
20683
|
#credentialSignal(limit) {
|
|
20726
20684
|
return credentialDeadline(limit, Math.max(1, this.#deadlineAt - performance.now()));
|
|
20727
20685
|
}
|
|
@@ -20759,7 +20717,7 @@ class DispatchClient {
|
|
|
20759
20717
|
let own = failure;
|
|
20760
20718
|
if (answer?.response.ok === true) {
|
|
20761
20719
|
const { status } = answer.response;
|
|
20762
|
-
own = new Error(answer.notJson ? `${request} answered ${status} with ${bodyForText(answer.text, this.#sent.with(this.token), "JSON")}, though every Dispatch write answers JSON, so something in Dispatch's place answered` : event === "foreign-2xx" ? `${request} answered ${status} without carrying back its ${IDEMPOTENCY_KEY_HEADER}, though this Dispatch answers every keyed write with it, so something in Dispatch's place answered` : `${request} answered ${status} with a body that is not the JSON its Content-Type says`);
|
|
20720
|
+
own = new Error(answer.notJson ? `${request} answered ${status} with ${bodyForText(answer.text, this.#sent.with(this.token), "JSON")}, though every Dispatch write answers JSON, so something in Dispatch's place answered` : event === "foreign-2xx" ? `${request} answered ${status} without carrying back its ${IDEMPOTENCY_KEY_HEADER}, though an earlier answer of this write carried it and Dispatch answers every keyed write with it, so something in Dispatch's place answered` : `${request} answered ${status} with a body that is not the JSON its Content-Type says`);
|
|
20763
20721
|
} else if (answer !== undefined) {
|
|
20764
20722
|
own = event === "no-route" && routeSpent ? new DispatchNoRouteError : this.#payloadOrError(method, url, answer);
|
|
20765
20723
|
}
|
|
@@ -20791,39 +20749,7 @@ class DispatchClient {
|
|
|
20791
20749
|
unanswered = `${request} failed on its last attempt (${last.message})`;
|
|
20792
20750
|
}
|
|
20793
20751
|
}
|
|
20794
|
-
return new DispatchWriteUnsettledError(last, progress.sent, write.key, unanswered
|
|
20795
|
-
}
|
|
20796
|
-
async#runsKeyedLayer(unjudged) {
|
|
20797
|
-
const origin = this.#baseUrl;
|
|
20798
|
-
if (unjudged)
|
|
20799
|
-
KEYED_LAYER_SEEN.delete(origin);
|
|
20800
|
-
const seen = KEYED_LAYER_SEEN.get(origin);
|
|
20801
|
-
if (seen !== undefined && this.#now() - seen < KEYED_LAYER_MEMORY_MS)
|
|
20802
|
-
return true;
|
|
20803
|
-
let probe = KEYED_LAYER_PROBES.get(origin);
|
|
20804
|
-
if (probe === undefined) {
|
|
20805
|
-
probe = this.#probeKeyedLayer().finally(() => KEYED_LAYER_PROBES.delete(origin));
|
|
20806
|
-
KEYED_LAYER_PROBES.set(origin, probe);
|
|
20807
|
-
}
|
|
20808
|
-
const runs = await probe;
|
|
20809
|
-
if (runs)
|
|
20810
|
-
KEYED_LAYER_SEEN.set(origin, this.#now());
|
|
20811
|
-
return runs;
|
|
20812
|
-
}
|
|
20813
|
-
async#probeKeyedLayer() {
|
|
20814
|
-
try {
|
|
20815
|
-
const response = await this.#fetch(`${this.#baseUrl}/healthz`, {
|
|
20816
|
-
method: "GET",
|
|
20817
|
-
headers: { Accept: "application/json" },
|
|
20818
|
-
signal: AbortSignal.any([this.#signal, AbortSignal.timeout(KEY_LAYER_PROBE_MS)])
|
|
20819
|
-
});
|
|
20820
|
-
if (!isJson(response))
|
|
20821
|
-
return false;
|
|
20822
|
-
const health = await response.json();
|
|
20823
|
-
return typeof health === "object" && health !== null && Reflect.get(health, "idempotency_keys") === true;
|
|
20824
|
-
} catch {
|
|
20825
|
-
return false;
|
|
20826
|
-
}
|
|
20752
|
+
return new DispatchWriteUnsettledError(last, progress.sent, write.key, unanswered);
|
|
20827
20753
|
}
|
|
20828
20754
|
#url(path, query) {
|
|
20829
20755
|
const url = new URL(`${path.map((segment) => encodeURIComponent(segment)).join("/")}`, `${this.#baseUrl}/`);
|
|
@@ -29853,6 +29779,7 @@ function resolvedInterval(raw, fallback) {
|
|
|
29853
29779
|
const named = namedInterval(raw);
|
|
29854
29780
|
return named === undefined ? fallback : Math.min(Math.max(named, MIN_INTERVAL_MS), MAX_INTERVAL_MS);
|
|
29855
29781
|
}
|
|
29782
|
+
var ENVOY_INBOUND_VAR = "ENVOY_INBOUND";
|
|
29856
29783
|
function natsSeedFromEnvironment(env) {
|
|
29857
29784
|
const { NATS_NKEY_SEED_FILE: file, NATS_NKEY_SEED: plain } = env;
|
|
29858
29785
|
if (file !== undefined) {
|
|
@@ -29922,6 +29849,33 @@ function natsCredential(env, section, namedNatsUrls, filePath, session) {
|
|
|
29922
29849
|
throw new NoSessionNamedError(auth.source);
|
|
29923
29850
|
return { kind: "broker", broker: brokerNatsCredential(env, session, auth.source) };
|
|
29924
29851
|
}
|
|
29852
|
+
var LOOPBACK_HOST = /^(localhost|127(\.\d{1,3}){3}|\[::1\])$/i;
|
|
29853
|
+
function natsConflictText(source, natsSetting) {
|
|
29854
|
+
return `${source} is listener, and ${natsSetting} names NATS servers: set one of the two`;
|
|
29855
|
+
}
|
|
29856
|
+
function listenerInbound(source, natsSetting, credential, session) {
|
|
29857
|
+
if (natsSetting !== undefined)
|
|
29858
|
+
return { off: natsConflictText(source, natsSetting) };
|
|
29859
|
+
if ("noBrokerRoute" in credential) {
|
|
29860
|
+
return { off: `${source} is listener, but ${credential.noBrokerRoute}` };
|
|
29861
|
+
}
|
|
29862
|
+
if (credential.scheme !== "DPoP") {
|
|
29863
|
+
return {
|
|
29864
|
+
off: `${source} is listener, but the listener's credential is a bearer (ENVOY_TOKEN, ENVOY_TOKEN_FILE or envoy.token), and the relay socket admits only the session's broker token`
|
|
29865
|
+
};
|
|
29866
|
+
}
|
|
29867
|
+
if (session === undefined) {
|
|
29868
|
+
return {
|
|
29869
|
+
off: `${source} is listener, but this process names no session for its relay socket's token`,
|
|
29870
|
+
noSessionNamed: true
|
|
29871
|
+
};
|
|
29872
|
+
}
|
|
29873
|
+
return { relaySetting: source, relayCredential: credential };
|
|
29874
|
+
}
|
|
29875
|
+
function plainHttpOffMachine(url) {
|
|
29876
|
+
const host = URL.canParse(url) ? new URL(url) : undefined;
|
|
29877
|
+
return host?.protocol === "http:" && !LOOPBACK_HOST.test(host.hostname) ? host.hostname : undefined;
|
|
29878
|
+
}
|
|
29925
29879
|
function envoySettings(env, config, options = {}) {
|
|
29926
29880
|
if (config.kind === "failed")
|
|
29927
29881
|
return offWithError(config.error);
|
|
@@ -29940,7 +29894,18 @@ function envoySettings(env, config, options = {}) {
|
|
|
29940
29894
|
}
|
|
29941
29895
|
const listener = section.url ?? DEFAULT_ENVOY_URL;
|
|
29942
29896
|
const url = namedUrl ?? listener;
|
|
29897
|
+
const namedInbound = nonEmpty(env.ENVOY_INBOUND);
|
|
29898
|
+
const choice = namedInbound !== undefined ? { value: namedInbound, source: ENVOY_INBOUND_VAR } : section.inbound === undefined ? undefined : { value: section.inbound, source: `envoy.inbound in ${config.path}` };
|
|
29899
|
+
const natsSetting = namedNatsUrls.length > 0 ? "ENVOY_NATS_URL" : (section.natsUrls ?? []).length > 0 ? `envoy.natsUrls in ${config.path}` : undefined;
|
|
29900
|
+
if (choice?.value === "listener") {
|
|
29901
|
+
const host = plainHttpOffMachine(url);
|
|
29902
|
+
if (host !== undefined) {
|
|
29903
|
+
const plainHttp = `the listener's address is plain http to ${host}, which is not this machine, so the session's token would cross the network unencrypted; use an https address`;
|
|
29904
|
+
return offWithError(natsSetting === undefined ? `${choice.source} is listener, but ${plainHttp}` : `${natsConflictText(choice.source, natsSetting)}. And ${plainHttp}`);
|
|
29905
|
+
}
|
|
29906
|
+
}
|
|
29943
29907
|
let credential;
|
|
29908
|
+
let noBrokerRoute = "";
|
|
29944
29909
|
try {
|
|
29945
29910
|
const source = bearerSource(env, "ENVOY", () => section.token === undefined ? undefined : {
|
|
29946
29911
|
token: section.token,
|
|
@@ -29950,7 +29915,10 @@ function envoySettings(env, config, options = {}) {
|
|
|
29950
29915
|
checkout: false
|
|
29951
29916
|
});
|
|
29952
29917
|
if (source.kind === "none") {
|
|
29953
|
-
|
|
29918
|
+
const route = brokerRouteConfigured(env);
|
|
29919
|
+
credential = route.traded ? brokerCredential(env, options.session) : undefined;
|
|
29920
|
+
if (!route.traded)
|
|
29921
|
+
noBrokerRoute = route.gap;
|
|
29954
29922
|
} else {
|
|
29955
29923
|
credential = bearerCredential(source.kind === "variable" ? source.token : fileBearer(source, url, "ENVOY", env));
|
|
29956
29924
|
}
|
|
@@ -29961,13 +29929,17 @@ function envoySettings(env, config, options = {}) {
|
|
|
29961
29929
|
let inbound;
|
|
29962
29930
|
if (options.nats === false)
|
|
29963
29931
|
inbound = { off: NO_NATS_CONNECTION };
|
|
29964
|
-
else if (
|
|
29932
|
+
else if (choice !== undefined && choice.value !== "nats" && choice.value !== "listener") {
|
|
29933
|
+
inbound = { off: `${choice.source} is neither nats nor listener` };
|
|
29934
|
+
} else if (choice?.value === "listener") {
|
|
29935
|
+
inbound = listenerInbound(choice.source, natsSetting, credential ?? { noBrokerRoute }, options.session);
|
|
29936
|
+
} else if (natsSetting === undefined)
|
|
29965
29937
|
inbound = { off: NO_NATS_SERVER };
|
|
29966
29938
|
else {
|
|
29967
29939
|
try {
|
|
29968
29940
|
inbound = {
|
|
29969
29941
|
natsUrls,
|
|
29970
|
-
natsServersSetting:
|
|
29942
|
+
natsServersSetting: natsSetting,
|
|
29971
29943
|
natsCredential: natsCredential(env, section, namedNatsUrls, config.path, options.session)
|
|
29972
29944
|
};
|
|
29973
29945
|
} catch (error) {
|
|
@@ -30044,6 +30016,9 @@ function startNotice(config, dispatch, envoy, nats, lost) {
|
|
|
30044
30016
|
if (envoy.enabled && nats && "off" in envoy.inbound) {
|
|
30045
30017
|
parts.push(`Envoy's inbound messages are off: ${envoy.inbound.off}; the Envoy tools still work`);
|
|
30046
30018
|
}
|
|
30019
|
+
if (envoy.enabled && nats && "relaySetting" in envoy.inbound) {
|
|
30020
|
+
parts.push(`Envoy's inbound messages come through the listener's relay socket (${envoy.inbound.relaySetting} is listener), which carries no live view: the Agents page shows nothing of this session's turns`);
|
|
30021
|
+
}
|
|
30047
30022
|
if (envoy.enabled && envoy.passDeadlineRaisedFrom !== undefined) {
|
|
30048
30023
|
parts.push(`Envoy's pass deadline is ${envoy.passDeadlineMs} ms, not the ${envoy.passDeadlineRaisedFrom} ms ENVOY_PASS_DEADLINE_MS names: a deadline inside one ${envoy.heartbeatMs} ms heartbeat interval would abandon every pass before the next tick, so the registration refresh the heartbeat posts for a stalled pass would never run`);
|
|
30049
30024
|
}
|