@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/dist/dispatch.js
CHANGED
|
@@ -15145,6 +15145,7 @@ var IDEMPOTENCY_KEY_HEADER = "Idempotency-Key";
|
|
|
15145
15145
|
var IDEMPOTENCY_REPLAYED_HEADER = "Idempotency-Replayed";
|
|
15146
15146
|
var IDEMPOTENCY_KEY_MAX = 128;
|
|
15147
15147
|
var IDEMPOTENCY_KEY_PATTERN = new RegExp(`^[A-Za-z0-9._:-]{1,${IDEMPOTENCY_KEY_MAX}}$`);
|
|
15148
|
+
var IDEMPOTENCY_KEY_REUSED = "KEY_REUSED";
|
|
15148
15149
|
var IDEMPOTENCY_KEY_IN_FLIGHT = "KEY_IN_FLIGHT";
|
|
15149
15150
|
var IDEMPOTENCY_KEY_COMMITTED = "KEY_COMMITTED";
|
|
15150
15151
|
var IDEMPOTENCY_ANSWER_NOT_KEPT = "ANSWER_NOT_KEPT";
|
|
@@ -19469,7 +19470,8 @@ var EnvoySectionSchema = strictObject({
|
|
|
19469
19470
|
natsUrls: array(string2().trim().min(1, "must not be empty")).optional(),
|
|
19470
19471
|
token: string2().optional(),
|
|
19471
19472
|
natsSeed: string2().optional(),
|
|
19472
|
-
natsAuth: string2().optional()
|
|
19473
|
+
natsAuth: string2().optional(),
|
|
19474
|
+
inbound: string2().optional()
|
|
19473
19475
|
});
|
|
19474
19476
|
var EnvoyFileSchema = looseObject({
|
|
19475
19477
|
$schema: string2().optional(),
|
|
@@ -19952,7 +19954,7 @@ class DispatchWriteUnsettledError extends Error {
|
|
|
19952
19954
|
attempts;
|
|
19953
19955
|
key;
|
|
19954
19956
|
name = "DispatchWriteUnsettledError";
|
|
19955
|
-
constructor(last, attempts, key, unanswered
|
|
19957
|
+
constructor(last, attempts, key, unanswered) {
|
|
19956
19958
|
let answer;
|
|
19957
19959
|
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";
|
|
19958
19960
|
if (last instanceof DispatchGatewayError) {
|
|
@@ -19967,10 +19969,7 @@ class DispatchWriteUnsettledError extends Error {
|
|
|
19967
19969
|
why = "an attempt of the write may have reached Dispatch";
|
|
19968
19970
|
}
|
|
19969
19971
|
const tried = attempts === 1 ? "its only attempt" : `the last of ${attempts} attempts`;
|
|
19970
|
-
|
|
19971
|
-
super(`${answer} (${tried}), and ${why}, so it may or may not have taken effect${next}`, {
|
|
19972
|
-
cause: last
|
|
19973
|
-
});
|
|
19972
|
+
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 });
|
|
19974
19973
|
this.last = last;
|
|
19975
19974
|
this.attempts = attempts;
|
|
19976
19975
|
this.key = key;
|
|
@@ -20059,43 +20058,6 @@ function retryAfterMs(response) {
|
|
|
20059
20058
|
const at = Date.parse(value);
|
|
20060
20059
|
return Number.isNaN(at) ? 0 : Math.max(0, at - Date.now());
|
|
20061
20060
|
}
|
|
20062
|
-
var KEYED_LAYER_MEMORY_MS = 5 * 60000;
|
|
20063
|
-
var KEYED_LAYER_SEEN = new Map;
|
|
20064
|
-
var KEYED_LAYER_PROBES = new Map;
|
|
20065
|
-
var KEY_LAYER_PROBE_MS = 5000;
|
|
20066
|
-
function keyedLayerMemory() {
|
|
20067
|
-
const wall = Date.now();
|
|
20068
|
-
const now = performance.now();
|
|
20069
|
-
const kept = {};
|
|
20070
|
-
for (const [origin, seen] of KEYED_LAYER_SEEN) {
|
|
20071
|
-
const age = now - seen;
|
|
20072
|
-
if (age >= 0 && age < KEYED_LAYER_MEMORY_MS) {
|
|
20073
|
-
kept[origin] = new Date(wall - age).toISOString();
|
|
20074
|
-
}
|
|
20075
|
-
}
|
|
20076
|
-
return kept;
|
|
20077
|
-
}
|
|
20078
|
-
function rememberKeyedLayer(saved) {
|
|
20079
|
-
if (typeof saved !== "object" || saved === null)
|
|
20080
|
-
return;
|
|
20081
|
-
const wall = Date.now();
|
|
20082
|
-
const now = performance.now();
|
|
20083
|
-
for (const [origin, at] of Object.entries(saved)) {
|
|
20084
|
-
if (typeof at !== "string")
|
|
20085
|
-
continue;
|
|
20086
|
-
const age = wall - Date.parse(at);
|
|
20087
|
-
if (!(age >= 0 && age < KEYED_LAYER_MEMORY_MS))
|
|
20088
|
-
continue;
|
|
20089
|
-
const seen = now - age;
|
|
20090
|
-
const known = KEYED_LAYER_SEEN.get(origin);
|
|
20091
|
-
if (known === undefined || known < seen)
|
|
20092
|
-
KEYED_LAYER_SEEN.set(origin, seen);
|
|
20093
|
-
}
|
|
20094
|
-
}
|
|
20095
|
-
function keyEchoed(response, key) {
|
|
20096
|
-
const echoed = response.headers.get(IDEMPOTENCY_KEY_HEADER)?.trim() ?? "";
|
|
20097
|
-
return echoed.replace(/^"(.*)"$/, "$1") === key;
|
|
20098
|
-
}
|
|
20099
20061
|
var STREAMED_BODY_MIN = 1 << 20;
|
|
20100
20062
|
var STREAMED_BODY_CHUNK = 64 << 10;
|
|
20101
20063
|
function attemptBody(body, headers, progress) {
|
|
@@ -20134,17 +20096,18 @@ function parsedJson(response, text) {
|
|
|
20134
20096
|
}
|
|
20135
20097
|
}
|
|
20136
20098
|
var NULL_BODY_STATUSES = new Set([101, 204, 205, 304]);
|
|
20137
|
-
async function writeAnswer(response
|
|
20099
|
+
async function writeAnswer(response) {
|
|
20138
20100
|
if (NULL_BODY_STATUSES.has(response.status)) {
|
|
20139
20101
|
return {
|
|
20140
20102
|
response,
|
|
20141
|
-
echoed,
|
|
20142
20103
|
malformed: false,
|
|
20143
20104
|
notJson: false,
|
|
20144
20105
|
text: "",
|
|
20145
20106
|
json: undefined,
|
|
20146
20107
|
code: undefined,
|
|
20147
|
-
error: undefined
|
|
20108
|
+
error: undefined,
|
|
20109
|
+
replayed: response.headers.get(IDEMPOTENCY_REPLAYED_HEADER)?.trim() === "?1",
|
|
20110
|
+
keyEcho: response.headers.get(IDEMPOTENCY_KEY_HEADER) ?? undefined
|
|
20148
20111
|
};
|
|
20149
20112
|
}
|
|
20150
20113
|
const text = await response.text();
|
|
@@ -20154,23 +20117,27 @@ async function writeAnswer(response, echoed) {
|
|
|
20154
20117
|
const own = typeof shape.error === "string";
|
|
20155
20118
|
return {
|
|
20156
20119
|
response,
|
|
20157
|
-
echoed,
|
|
20158
20120
|
malformed: text !== "" && typed && json === undefined,
|
|
20159
20121
|
notJson: text === "" || !typed,
|
|
20160
20122
|
text,
|
|
20161
20123
|
json,
|
|
20162
20124
|
code: own ? shape.code : undefined,
|
|
20163
|
-
error: own ? shape.error : undefined
|
|
20125
|
+
error: own ? shape.error : undefined,
|
|
20126
|
+
replayed: response.headers.get(IDEMPOTENCY_REPLAYED_HEADER)?.trim() === "?1",
|
|
20127
|
+
keyEcho: response.headers.get(IDEMPOTENCY_KEY_HEADER) ?? undefined
|
|
20164
20128
|
};
|
|
20165
20129
|
}
|
|
20166
|
-
function
|
|
20130
|
+
function isStoredKeyStatus(status) {
|
|
20131
|
+
return status >= 400 && status < 500 && status !== 401 && status !== 408 && status !== 429;
|
|
20132
|
+
}
|
|
20133
|
+
function answerEvent(answer, requestKey, keyEchoed, canTellDeadToken) {
|
|
20167
20134
|
const { status } = answer.response;
|
|
20168
20135
|
if (status >= 200 && status < 300) {
|
|
20169
20136
|
if (answer.notJson)
|
|
20170
20137
|
return "foreign-2xx";
|
|
20171
20138
|
if (answer.malformed)
|
|
20172
20139
|
return "body-malformed";
|
|
20173
|
-
return
|
|
20140
|
+
return keyEchoed && answer.keyEcho !== requestKey ? "foreign-2xx" : "applied";
|
|
20174
20141
|
}
|
|
20175
20142
|
if (status >= 300 && status < 400)
|
|
20176
20143
|
return "redirect";
|
|
@@ -20185,7 +20152,13 @@ function answerEvent(answer, canTellDeadToken, layerKnown) {
|
|
|
20185
20152
|
return "in-flight";
|
|
20186
20153
|
return status >= 500 ? "server-error" : "try-later";
|
|
20187
20154
|
}
|
|
20188
|
-
|
|
20155
|
+
if (answer.replayed || answer.code === IDEMPOTENCY_KEY_COMMITTED)
|
|
20156
|
+
return "judged";
|
|
20157
|
+
if (answer.keyEcho !== requestKey || !isStoredKeyStatus(status))
|
|
20158
|
+
return "unjudged";
|
|
20159
|
+
if (answer.code === IDEMPOTENCY_KEY_REUSED)
|
|
20160
|
+
return "judged";
|
|
20161
|
+
return answer.code === IDEMPOTENCY_KEY_IN_FLIGHT ? "unjudged" : "judged";
|
|
20189
20162
|
}
|
|
20190
20163
|
function credentialEvent(error) {
|
|
20191
20164
|
return error instanceof TradeRetryingError ? "no-credential" : "no-credential-final";
|
|
@@ -20771,7 +20744,7 @@ class DispatchClient {
|
|
|
20771
20744
|
key: key ?? crypto.randomUUID(),
|
|
20772
20745
|
request: `${method} ${requestForText(this.#baseUrl, url, DISPATCH_URL_SETTING)}`,
|
|
20773
20746
|
writes,
|
|
20774
|
-
progress: { sent: 0, running: false,
|
|
20747
|
+
progress: { sent: 0, running: false, keyEchoed: false }
|
|
20775
20748
|
};
|
|
20776
20749
|
}
|
|
20777
20750
|
async#upload(path, input, key) {
|
|
@@ -20789,12 +20762,12 @@ class DispatchClient {
|
|
|
20789
20762
|
form.set("file", input.file, input.name);
|
|
20790
20763
|
return this.#form("POST", path, form, key);
|
|
20791
20764
|
}
|
|
20792
|
-
async#form(method, path, form,
|
|
20765
|
+
async#form(method, path, form, callerKey) {
|
|
20793
20766
|
const url = this.#url(path);
|
|
20794
20767
|
const encoded = new Response(form);
|
|
20795
20768
|
const type = encoded.headers.get("Content-Type") ?? "multipart/form-data";
|
|
20796
20769
|
const body = { content: new Uint8Array(await encoded.arrayBuffer()), type };
|
|
20797
|
-
const write = this.#writeCall(method, url,
|
|
20770
|
+
const write = this.#writeCall(method, url, callerKey);
|
|
20798
20771
|
if (write !== undefined) {
|
|
20799
20772
|
const answer = await this.#write(method, url, body, "application/json", undefined, write);
|
|
20800
20773
|
return this.#payloadOf(method, url, answer);
|
|
@@ -20879,14 +20852,12 @@ class DispatchClient {
|
|
|
20879
20852
|
sent
|
|
20880
20853
|
};
|
|
20881
20854
|
}
|
|
20882
|
-
const
|
|
20883
|
-
|
|
20884
|
-
|
|
20885
|
-
KEYED_LAYER_SEEN.set(this.#baseUrl, this.#now());
|
|
20886
|
-
progress.sawKeyedLayer ||= echoed;
|
|
20855
|
+
const heard = { retryAfterMs: retryAfterMs(response) };
|
|
20856
|
+
if (response.headers.get(IDEMPOTENCY_KEY_HEADER) === key)
|
|
20857
|
+
progress.keyEchoed = true;
|
|
20887
20858
|
let answer;
|
|
20888
20859
|
try {
|
|
20889
|
-
answer = await writeAnswer(response
|
|
20860
|
+
answer = await writeAnswer(response);
|
|
20890
20861
|
} catch (error) {
|
|
20891
20862
|
const stop = stoppedEvent(limit, true, error);
|
|
20892
20863
|
return {
|
|
@@ -20898,7 +20869,7 @@ class DispatchClient {
|
|
|
20898
20869
|
};
|
|
20899
20870
|
}
|
|
20900
20871
|
return {
|
|
20901
|
-
event: answerEvent(answer, this.#credential.stale !== undefined && !deadTokenTold
|
|
20872
|
+
event: answerEvent(answer, write.key, progress.keyEchoed, this.#credential.stale !== undefined && !deadTokenTold),
|
|
20902
20873
|
answer,
|
|
20903
20874
|
presented,
|
|
20904
20875
|
sent,
|
|
@@ -20963,16 +20934,7 @@ class DispatchClient {
|
|
|
20963
20934
|
const scheduled = progress.running ? Math.min(pausesMs[paced - 1] ?? inFlightPauseMs, inFlightPauseMs) : pausesMs[paced - 1];
|
|
20964
20935
|
const wait = Math.max(scheduled ?? 0, last.heard?.retryAfterMs ?? 0);
|
|
20965
20936
|
const latest = Math.min(started + (progress.running ? inFlightWithinMs : withinMs), lastAsk);
|
|
20966
|
-
|
|
20967
|
-
const { answer } = last;
|
|
20968
|
-
const unjudged = answer !== undefined && !answer.echoed && answer.error !== undefined;
|
|
20969
|
-
if (again && state === "may-have-landed") {
|
|
20970
|
-
again = (last.heard?.echoed ?? false) || await this.#runsKeyedLayer(unjudged);
|
|
20971
|
-
progress.sawKeyedLayer ||= again;
|
|
20972
|
-
again &&= this.#now() + wait <= latest;
|
|
20973
|
-
} else if (unjudged && state === "nothing-sent") {
|
|
20974
|
-
KEYED_LAYER_SEEN.delete(this.#baseUrl);
|
|
20975
|
-
}
|
|
20937
|
+
const again = scheduled !== undefined && this.#now() + wait <= latest;
|
|
20976
20938
|
if (!again) {
|
|
20977
20939
|
event = "exhausted";
|
|
20978
20940
|
continue;
|
|
@@ -20996,10 +20958,6 @@ class DispatchClient {
|
|
|
20996
20958
|
}
|
|
20997
20959
|
}
|
|
20998
20960
|
}
|
|
20999
|
-
#remembersKeyedLayer() {
|
|
21000
|
-
const seen = KEYED_LAYER_SEEN.get(this.#baseUrl);
|
|
21001
|
-
return seen !== undefined && this.#now() - seen < KEYED_LAYER_MEMORY_MS;
|
|
21002
|
-
}
|
|
21003
20961
|
#credentialSignal(limit) {
|
|
21004
20962
|
return credentialDeadline(limit, Math.max(1, this.#deadlineAt - performance.now()));
|
|
21005
20963
|
}
|
|
@@ -21037,7 +20995,7 @@ class DispatchClient {
|
|
|
21037
20995
|
let own = failure;
|
|
21038
20996
|
if (answer?.response.ok === true) {
|
|
21039
20997
|
const { status } = answer.response;
|
|
21040
|
-
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`);
|
|
20998
|
+
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`);
|
|
21041
20999
|
} else if (answer !== undefined) {
|
|
21042
21000
|
own = event === "no-route" && routeSpent ? new DispatchNoRouteError : this.#payloadOrError(method, url, answer);
|
|
21043
21001
|
}
|
|
@@ -21069,39 +21027,7 @@ class DispatchClient {
|
|
|
21069
21027
|
unanswered = `${request} failed on its last attempt (${last.message})`;
|
|
21070
21028
|
}
|
|
21071
21029
|
}
|
|
21072
|
-
return new DispatchWriteUnsettledError(last, progress.sent, write.key, unanswered
|
|
21073
|
-
}
|
|
21074
|
-
async#runsKeyedLayer(unjudged) {
|
|
21075
|
-
const origin = this.#baseUrl;
|
|
21076
|
-
if (unjudged)
|
|
21077
|
-
KEYED_LAYER_SEEN.delete(origin);
|
|
21078
|
-
const seen = KEYED_LAYER_SEEN.get(origin);
|
|
21079
|
-
if (seen !== undefined && this.#now() - seen < KEYED_LAYER_MEMORY_MS)
|
|
21080
|
-
return true;
|
|
21081
|
-
let probe = KEYED_LAYER_PROBES.get(origin);
|
|
21082
|
-
if (probe === undefined) {
|
|
21083
|
-
probe = this.#probeKeyedLayer().finally(() => KEYED_LAYER_PROBES.delete(origin));
|
|
21084
|
-
KEYED_LAYER_PROBES.set(origin, probe);
|
|
21085
|
-
}
|
|
21086
|
-
const runs = await probe;
|
|
21087
|
-
if (runs)
|
|
21088
|
-
KEYED_LAYER_SEEN.set(origin, this.#now());
|
|
21089
|
-
return runs;
|
|
21090
|
-
}
|
|
21091
|
-
async#probeKeyedLayer() {
|
|
21092
|
-
try {
|
|
21093
|
-
const response = await this.#fetch(`${this.#baseUrl}/healthz`, {
|
|
21094
|
-
method: "GET",
|
|
21095
|
-
headers: { Accept: "application/json" },
|
|
21096
|
-
signal: AbortSignal.any([this.#signal, AbortSignal.timeout(KEY_LAYER_PROBE_MS)])
|
|
21097
|
-
});
|
|
21098
|
-
if (!isJson(response))
|
|
21099
|
-
return false;
|
|
21100
|
-
const health = await response.json();
|
|
21101
|
-
return typeof health === "object" && health !== null && Reflect.get(health, "idempotency_keys") === true;
|
|
21102
|
-
} catch {
|
|
21103
|
-
return false;
|
|
21104
|
-
}
|
|
21030
|
+
return new DispatchWriteUnsettledError(last, progress.sent, write.key, unanswered);
|
|
21105
21031
|
}
|
|
21106
21032
|
#url(path, query) {
|
|
21107
21033
|
const url = new URL(`${path.map((segment) => encodeURIComponent(segment)).join("/")}`, `${this.#baseUrl}/`);
|
|
@@ -28092,15 +28018,13 @@ function loadSessionMemory(dir, sessionId) {
|
|
|
28092
28018
|
const pictures = shownPictures(sessionId);
|
|
28093
28019
|
for (const address of stringList(state.pictures))
|
|
28094
28020
|
pictures.add(address);
|
|
28095
|
-
rememberKeyedLayer(state.keyedLayer);
|
|
28096
28021
|
return new Set(stringList(state.follows));
|
|
28097
28022
|
}
|
|
28098
28023
|
function writeMemory(dir, sessionId, follows) {
|
|
28099
28024
|
const state = {
|
|
28100
28025
|
advice: [...adviceMemory()],
|
|
28101
28026
|
pictures: [...shownPictures(sessionId)],
|
|
28102
|
-
follows: [...follows]
|
|
28103
|
-
keyedLayer: keyedLayerMemory()
|
|
28027
|
+
follows: [...follows]
|
|
28104
28028
|
};
|
|
28105
28029
|
writeAtomically(join6(dir, "state.json"), `${JSON.stringify(state)}
|
|
28106
28030
|
`);
|
|
@@ -31104,6 +31028,7 @@ function resolvedInterval(raw, fallback) {
|
|
|
31104
31028
|
const named = namedInterval(raw);
|
|
31105
31029
|
return named === undefined ? fallback : Math.min(Math.max(named, MIN_INTERVAL_MS), MAX_INTERVAL_MS);
|
|
31106
31030
|
}
|
|
31031
|
+
var ENVOY_INBOUND_VAR = "ENVOY_INBOUND";
|
|
31107
31032
|
function natsSeedFromEnvironment(env) {
|
|
31108
31033
|
const { NATS_NKEY_SEED_FILE: file, NATS_NKEY_SEED: plain } = env;
|
|
31109
31034
|
if (file !== undefined) {
|
|
@@ -31173,6 +31098,33 @@ function natsCredential(env, section, namedNatsUrls, filePath, session) {
|
|
|
31173
31098
|
throw new NoSessionNamedError(auth.source);
|
|
31174
31099
|
return { kind: "broker", broker: brokerNatsCredential(env, session, auth.source) };
|
|
31175
31100
|
}
|
|
31101
|
+
var LOOPBACK_HOST = /^(localhost|127(\.\d{1,3}){3}|\[::1\])$/i;
|
|
31102
|
+
function natsConflictText(source, natsSetting) {
|
|
31103
|
+
return `${source} is listener, and ${natsSetting} names NATS servers: set one of the two`;
|
|
31104
|
+
}
|
|
31105
|
+
function listenerInbound(source, natsSetting, credential, session) {
|
|
31106
|
+
if (natsSetting !== undefined)
|
|
31107
|
+
return { off: natsConflictText(source, natsSetting) };
|
|
31108
|
+
if ("noBrokerRoute" in credential) {
|
|
31109
|
+
return { off: `${source} is listener, but ${credential.noBrokerRoute}` };
|
|
31110
|
+
}
|
|
31111
|
+
if (credential.scheme !== "DPoP") {
|
|
31112
|
+
return {
|
|
31113
|
+
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`
|
|
31114
|
+
};
|
|
31115
|
+
}
|
|
31116
|
+
if (session === undefined) {
|
|
31117
|
+
return {
|
|
31118
|
+
off: `${source} is listener, but this process names no session for its relay socket's token`,
|
|
31119
|
+
noSessionNamed: true
|
|
31120
|
+
};
|
|
31121
|
+
}
|
|
31122
|
+
return { relaySetting: source, relayCredential: credential };
|
|
31123
|
+
}
|
|
31124
|
+
function plainHttpOffMachine(url) {
|
|
31125
|
+
const host = URL.canParse(url) ? new URL(url) : undefined;
|
|
31126
|
+
return host?.protocol === "http:" && !LOOPBACK_HOST.test(host.hostname) ? host.hostname : undefined;
|
|
31127
|
+
}
|
|
31176
31128
|
function envoySettings(env, config, options = {}) {
|
|
31177
31129
|
if (config.kind === "failed")
|
|
31178
31130
|
return offWithError(config.error);
|
|
@@ -31191,7 +31143,18 @@ function envoySettings(env, config, options = {}) {
|
|
|
31191
31143
|
}
|
|
31192
31144
|
const listener = section.url ?? DEFAULT_ENVOY_URL;
|
|
31193
31145
|
const url = namedUrl ?? listener;
|
|
31146
|
+
const namedInbound = nonEmpty(env.ENVOY_INBOUND);
|
|
31147
|
+
const choice = namedInbound !== undefined ? { value: namedInbound, source: ENVOY_INBOUND_VAR } : section.inbound === undefined ? undefined : { value: section.inbound, source: `envoy.inbound in ${config.path}` };
|
|
31148
|
+
const natsSetting = namedNatsUrls.length > 0 ? "ENVOY_NATS_URL" : (section.natsUrls ?? []).length > 0 ? `envoy.natsUrls in ${config.path}` : undefined;
|
|
31149
|
+
if (choice?.value === "listener") {
|
|
31150
|
+
const host = plainHttpOffMachine(url);
|
|
31151
|
+
if (host !== undefined) {
|
|
31152
|
+
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`;
|
|
31153
|
+
return offWithError(natsSetting === undefined ? `${choice.source} is listener, but ${plainHttp}` : `${natsConflictText(choice.source, natsSetting)}. And ${plainHttp}`);
|
|
31154
|
+
}
|
|
31155
|
+
}
|
|
31194
31156
|
let credential;
|
|
31157
|
+
let noBrokerRoute = "";
|
|
31195
31158
|
try {
|
|
31196
31159
|
const source = bearerSource(env, "ENVOY", () => section.token === undefined ? undefined : {
|
|
31197
31160
|
token: section.token,
|
|
@@ -31201,7 +31164,10 @@ function envoySettings(env, config, options = {}) {
|
|
|
31201
31164
|
checkout: false
|
|
31202
31165
|
});
|
|
31203
31166
|
if (source.kind === "none") {
|
|
31204
|
-
|
|
31167
|
+
const route = brokerRouteConfigured(env);
|
|
31168
|
+
credential = route.traded ? brokerCredential(env, options.session) : undefined;
|
|
31169
|
+
if (!route.traded)
|
|
31170
|
+
noBrokerRoute = route.gap;
|
|
31205
31171
|
} else {
|
|
31206
31172
|
credential = bearerCredential(source.kind === "variable" ? source.token : fileBearer(source, url, "ENVOY", env));
|
|
31207
31173
|
}
|
|
@@ -31212,13 +31178,17 @@ function envoySettings(env, config, options = {}) {
|
|
|
31212
31178
|
let inbound;
|
|
31213
31179
|
if (options.nats === false)
|
|
31214
31180
|
inbound = { off: NO_NATS_CONNECTION };
|
|
31215
|
-
else if (
|
|
31181
|
+
else if (choice !== undefined && choice.value !== "nats" && choice.value !== "listener") {
|
|
31182
|
+
inbound = { off: `${choice.source} is neither nats nor listener` };
|
|
31183
|
+
} else if (choice?.value === "listener") {
|
|
31184
|
+
inbound = listenerInbound(choice.source, natsSetting, credential ?? { noBrokerRoute }, options.session);
|
|
31185
|
+
} else if (natsSetting === undefined)
|
|
31216
31186
|
inbound = { off: NO_NATS_SERVER };
|
|
31217
31187
|
else {
|
|
31218
31188
|
try {
|
|
31219
31189
|
inbound = {
|
|
31220
31190
|
natsUrls,
|
|
31221
|
-
natsServersSetting:
|
|
31191
|
+
natsServersSetting: natsSetting,
|
|
31222
31192
|
natsCredential: natsCredential(env, section, namedNatsUrls, config.path, options.session)
|
|
31223
31193
|
};
|
|
31224
31194
|
} catch (error) {
|
|
@@ -31295,6 +31265,9 @@ function startNotice(config, dispatch, envoy, nats, lost) {
|
|
|
31295
31265
|
if (envoy.enabled && nats && "off" in envoy.inbound) {
|
|
31296
31266
|
parts.push(`Envoy's inbound messages are off: ${envoy.inbound.off}; the Envoy tools still work`);
|
|
31297
31267
|
}
|
|
31268
|
+
if (envoy.enabled && nats && "relaySetting" in envoy.inbound) {
|
|
31269
|
+
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`);
|
|
31270
|
+
}
|
|
31298
31271
|
if (envoy.enabled && envoy.passDeadlineRaisedFrom !== undefined) {
|
|
31299
31272
|
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`);
|
|
31300
31273
|
}
|
|
@@ -31481,6 +31454,7 @@ var ErrorWireSchema = object({
|
|
|
31481
31454
|
error: string2(),
|
|
31482
31455
|
code: string2().optional(),
|
|
31483
31456
|
reason: string2().optional(),
|
|
31457
|
+
refused: array(string2()).optional(),
|
|
31484
31458
|
expected: array(string2()).optional(),
|
|
31485
31459
|
state: SessionStateSchema.optional(),
|
|
31486
31460
|
holder: string2().optional(),
|
|
@@ -31597,6 +31571,7 @@ class EnvoyApiError extends Error {
|
|
|
31597
31571
|
lastSeen;
|
|
31598
31572
|
claimReleased;
|
|
31599
31573
|
retryAfterSeconds;
|
|
31574
|
+
refused;
|
|
31600
31575
|
constructor(details, shown = {}) {
|
|
31601
31576
|
let parsed;
|
|
31602
31577
|
try {
|
|
@@ -31615,6 +31590,7 @@ class EnvoyApiError extends Error {
|
|
|
31615
31590
|
this.lastSeen = parsed?.last_seen;
|
|
31616
31591
|
this.claimReleased = parsed?.claim_released;
|
|
31617
31592
|
this.retryAfterSeconds = parsed?.retry_after_seconds;
|
|
31593
|
+
this.refused = parsed?.refused;
|
|
31618
31594
|
}
|
|
31619
31595
|
}
|
|
31620
31596
|
var mintedDedupeKey2 = new RegExp(MINTED_DEDUPE_KEY_PATTERN);
|