@sjawhar/claude-envoy 6.3.0 → 6.4.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/dist/codex-hook.js +190 -19
- package/dist/dispatch.js +190 -19
- package/dist/envoy-channel.js +200 -23
- package/dist/session-hook.js +190 -19
- package/package.json +1 -1
package/.omp-plugin/plugin.json
CHANGED
package/dist/codex-hook.js
CHANGED
|
@@ -14943,7 +14943,7 @@ var dispatchToolSpecs = [
|
|
|
14943
14943
|
{
|
|
14944
14944
|
name: "dispatch_review",
|
|
14945
14945
|
example: { issue: "DSP-1", version: 2, verdict: "approved" },
|
|
14946
|
-
description: "Approve one version of an issue's document, or request changes on it, as the person your " + "token names: what the document header's Approve and Request changes record. A review " + "records an approval or a changes request in the person's name at that version, so it " + "works only with a token that names a person who holds approve; Dispatch refuses it to " + "any other token, with 403 OAUTH_SCOPE_REQUIRED or 403 SIGN_IN_REQUIRED. --version is the " + "version you read, sent in the review route's path, and it must be the version the review " + "would record: the document's latest settled version, or, while an approval request is " + "open on it, the version that request names for it. Any other is refused 409 " + "REVIEW_VERSION_MOVED, which names the version to read, and nothing is recorded. A " + "Dispatch build without the versioned review route answers no route and records nothing; " + "the command then says so and names /healthz, which names the commit of the build that " + "answers it when that build was stamped with one. With a request open the review answers " + "it, and records the same verdict on every document the " + "request names, each at the version the request names. A later version makes an approval " + "stale. A review is the one browser action this command takes for a person; every other " + "browser action is dispatch://INFRA-910's. " + ISSUE_REFERENCE,
|
|
14946
|
+
description: "Approve one version of an issue's document, or request changes on it, as the person your " + "token names: what the document header's Approve and Request changes record. A review " + "records an approval or a changes request in the person's name at that version, so it " + "works only with a token that names a person who holds approve; Dispatch refuses it to " + "any other token, with 403 OAUTH_SCOPE_REQUIRED or 403 SIGN_IN_REQUIRED. On a box where " + "the person signed in with agent-secrets login, the review goes through Cipher's proxy " + "instead, with the approve placeholder the session trades that sign-in for; a secrets " + "broker that serves no approve capability refuses that trade 400 invalid_request, with a " + "reason that says so, and nothing is sent to Dispatch. --version is the " + "version you read, sent in the review route's path, and it must be the version the review " + "would record: the document's latest settled version, or, while an approval request is " + "open on it, the version that request names for it. Any other is refused 409 " + "REVIEW_VERSION_MOVED, which names the version to read, and nothing is recorded. A " + "Dispatch build without the versioned review route answers no route and records nothing; " + "the command then says so and names /healthz, which names the commit of the build that " + "answers it when that build was stamped with one. With a request open the review answers " + "it, and records the same verdict on every document the " + "request names, each at the version the request names. A later version makes an approval " + "stale. A review is the one browser action this command takes for a person; every other " + "browser action is dispatch://INFRA-910's. " + ISSUE_REFERENCE,
|
|
14947
14947
|
arguments: (z) => ({
|
|
14948
14948
|
issue: z.string().describe(ISSUE_REFERENCE),
|
|
14949
14949
|
artifact: z.string().describe("Document artifact id, slug, or filename; the issue's spec by default.").optional(),
|
|
@@ -23915,6 +23915,11 @@ var SUBJECT_TOKEN_TYPE_GITHUB = "urn:envoy:params:oauth:token-type:github-workfl
|
|
|
23915
23915
|
var SUBJECT_TOKEN_TYPE_PERSON = "urn:envoy:params:oauth:token-type:person-google-identity";
|
|
23916
23916
|
var ACTOR_TOKEN_TYPE_MACHINE = "urn:envoy:params:oauth:token-type:machine-google-identity";
|
|
23917
23917
|
var TOKEN_TYPE_DPOP = "DPoP";
|
|
23918
|
+
var FORM_REQUESTED_TOKEN_TYPE = "requested_token_type";
|
|
23919
|
+
var TOKEN_TYPE_PROXY_PLACEHOLDER = "urn:envoy:params:oauth:token-type:proxy-placeholder";
|
|
23920
|
+
var TOKEN_TYPE_NOT_APPLICABLE = "N_A";
|
|
23921
|
+
var PLACEHOLDER_PREFIX = "agent-secrets-placeholder-";
|
|
23922
|
+
var PROXY_APPROVE_NAME = "DISPATCH_APPROVE_TOKEN";
|
|
23918
23923
|
var SUBJECT_TYPE_ACCESS = "urn:ietf:params:oauth:token-type:access_token";
|
|
23919
23924
|
var DEVICE_AUTHORIZATION_PATH = "/v1/oauth/device_authorization";
|
|
23920
23925
|
var GRANT_TYPE_DEVICE_CODE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
@@ -24036,6 +24041,8 @@ var KNOWN_BROKER_REFUSAL_PATTERNS = [
|
|
|
24036
24041
|
`Refused: this pod's registration for session '${SESSION_SLOT}' was released; a pod trades only under a registration its registrar has not released\\.`,
|
|
24037
24042
|
`The session name '${SESSION_SLOT}' belongs to another daemon: a pod trades only under a session name the daemon that registered it holds\\.`,
|
|
24038
24043
|
`The session name '${SESSION_SLOT}' is bound to no daemon: a pod trades only under a session name the daemon that registered it holds\\.`,
|
|
24044
|
+
"Only a person's sign-in is traded for the approve capability's proxy placeholder, on a broker that serves it\\.",
|
|
24045
|
+
"A trade for the approve capability's proxy placeholder asks for the scope read, and a trade narrowed to reading approves nothing: trade for the placeholder without the scope, a cut or a DPoP-Holder proof\\.",
|
|
24039
24046
|
`${PERSON_SLOT}'s credentials are held by Dispatch; they work again when \\k<person> signs in to Dispatch, or when Dispatch can confirm \\k<person> with Google again`,
|
|
24040
24047
|
"The 'as_of' parameter names a cut, and only a trade that asks for the scope read may name one\\.",
|
|
24041
24048
|
"The 'as_of' parameter is not an RFC 3339 time with at most six fractional digits\\.",
|
|
@@ -25055,7 +25062,10 @@ var WRITE_TRANSITIONS = {
|
|
|
25055
25062
|
deadline: { "nothing-sent": nothing("end"), "may-have-landed": landed("end") },
|
|
25056
25063
|
"cancelled-in-flight": { "nothing-sent": landed("end"), "may-have-landed": landed("end") },
|
|
25057
25064
|
cancelled: { "nothing-sent": nothing("end"), "may-have-landed": landed("end") },
|
|
25058
|
-
exhausted: { "nothing-sent": nothing("end"), "may-have-landed": landed("end") }
|
|
25065
|
+
exhausted: { "nothing-sent": nothing("end"), "may-have-landed": landed("end") },
|
|
25066
|
+
"proxy-refused": { "nothing-sent": nothing("end"), "may-have-landed": landed("end") },
|
|
25067
|
+
"proxy-failed": { "nothing-sent": nothing("retry"), "may-have-landed": landed("retry") },
|
|
25068
|
+
"proxy-unsettled": { "nothing-sent": landed("retry"), "may-have-landed": landed("retry") }
|
|
25059
25069
|
};
|
|
25060
25070
|
function writeStep(state, event, writes) {
|
|
25061
25071
|
const step = WRITE_TRANSITIONS[event][state];
|
|
@@ -25105,6 +25115,32 @@ class DispatchGatewayError extends DispatchServiceError {
|
|
|
25105
25115
|
this.mayHaveReachedDispatch = reachesDispatch(status);
|
|
25106
25116
|
}
|
|
25107
25117
|
}
|
|
25118
|
+
var PROXY_CODE_HEADER = "Cipher-Proxy-Code";
|
|
25119
|
+
var PROXY_FORWARDED_HEADER = "Cipher-Proxy-Forwarded";
|
|
25120
|
+
|
|
25121
|
+
class DispatchProxyRefusalError extends DispatchServiceError {
|
|
25122
|
+
fromDispatch = false;
|
|
25123
|
+
}
|
|
25124
|
+
var PROXY_CODE_FORM = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
25125
|
+
function proxyTunnelAnswer(error) {
|
|
25126
|
+
if (typeof error !== "object" || error === null)
|
|
25127
|
+
return;
|
|
25128
|
+
const { code, status, headers } = error;
|
|
25129
|
+
if (code !== "ERR_PROXY_TUNNEL" || typeof status !== "number" || !(headers instanceof Headers)) {
|
|
25130
|
+
return;
|
|
25131
|
+
}
|
|
25132
|
+
const proxyCode = headers.get(PROXY_CODE_HEADER) ?? "";
|
|
25133
|
+
if (status < 400 || status > 599 || !PROXY_CODE_FORM.test(proxyCode))
|
|
25134
|
+
return;
|
|
25135
|
+
const forwarded = headers.get(PROXY_FORWARDED_HEADER);
|
|
25136
|
+
return new Response(null, {
|
|
25137
|
+
status,
|
|
25138
|
+
headers: {
|
|
25139
|
+
[PROXY_CODE_HEADER]: proxyCode,
|
|
25140
|
+
...forwarded === null ? {} : { [PROXY_FORWARDED_HEADER]: forwarded }
|
|
25141
|
+
}
|
|
25142
|
+
});
|
|
25143
|
+
}
|
|
25108
25144
|
var CREDENTIAL_ECHOED = "CREDENTIAL_ECHOED";
|
|
25109
25145
|
|
|
25110
25146
|
class DispatchCredentialEchoError extends DispatchServiceError {
|
|
@@ -25121,7 +25157,7 @@ class DispatchWriteUnsettledError extends Error {
|
|
|
25121
25157
|
name = "DispatchWriteUnsettledError";
|
|
25122
25158
|
constructor(last, attempts, key, unanswered) {
|
|
25123
25159
|
let answer;
|
|
25124
|
-
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";
|
|
25160
|
+
let why = last instanceof DispatchServiceError && last.status >= 500 || last instanceof DispatchProxyRefusalError ? "an attempt of the write may have reached Dispatch" : "an earlier attempt of the write may have reached Dispatch";
|
|
25125
25161
|
if (last instanceof DispatchGatewayError) {
|
|
25126
25162
|
answer = last.answer;
|
|
25127
25163
|
} else if (last instanceof DispatchServiceError && last.code === IDEMPOTENCY_KEY_IN_FLIGHT) {
|
|
@@ -25211,9 +25247,11 @@ class DispatchNoRouteError extends DispatchServiceError {
|
|
|
25211
25247
|
|
|
25212
25248
|
class DispatchUnreachableError extends Error {
|
|
25213
25249
|
reachedNothing;
|
|
25214
|
-
|
|
25250
|
+
failure;
|
|
25251
|
+
constructor(message, reachedNothing, failure) {
|
|
25215
25252
|
super(message);
|
|
25216
25253
|
this.reachedNothing = reachedNothing;
|
|
25254
|
+
this.failure = failure;
|
|
25217
25255
|
}
|
|
25218
25256
|
}
|
|
25219
25257
|
function reviewNoRouteRefusal(baseUrl, route, version) {
|
|
@@ -25292,6 +25330,10 @@ class WriteAttemptSilent extends Error {
|
|
|
25292
25330
|
super(`made no progress for ${silenceMs / 1000} s, so it was cut off`);
|
|
25293
25331
|
}
|
|
25294
25332
|
}
|
|
25333
|
+
function originOf(url) {
|
|
25334
|
+
const parsed = new URL(url);
|
|
25335
|
+
return `${parsed.protocol}//${parsed.host}`;
|
|
25336
|
+
}
|
|
25295
25337
|
function parsedJson(response, text) {
|
|
25296
25338
|
if (text === "" || !isJson(response))
|
|
25297
25339
|
return;
|
|
@@ -25350,8 +25392,13 @@ async function writeAnswer(response) {
|
|
|
25350
25392
|
function isStoredKeyStatus(status) {
|
|
25351
25393
|
return status >= 400 && status < 500 && status !== 401 && status !== 408 && status !== 429;
|
|
25352
25394
|
}
|
|
25353
|
-
function answerEvent(answer, requestKey, keyEchoed, canTellDeadToken) {
|
|
25395
|
+
function answerEvent(answer, requestKey, keyEchoed, canTellDeadToken, proxied) {
|
|
25354
25396
|
const { status } = answer.response;
|
|
25397
|
+
if (proxied && answer.response.headers.get(PROXY_CODE_HEADER) !== null) {
|
|
25398
|
+
if (answer.response.headers.get(PROXY_FORWARDED_HEADER) !== "false")
|
|
25399
|
+
return "proxy-unsettled";
|
|
25400
|
+
return status >= 500 ? "proxy-failed" : "proxy-refused";
|
|
25401
|
+
}
|
|
25355
25402
|
if (status >= 200 && status < 300) {
|
|
25356
25403
|
if (answer.notJson)
|
|
25357
25404
|
return "foreign-2xx";
|
|
@@ -25472,7 +25519,7 @@ class DispatchClient {
|
|
|
25472
25519
|
return await fetchImpl(input, { ...init, redirect: "manual" });
|
|
25473
25520
|
} catch (error) {
|
|
25474
25521
|
if (error instanceof TypeError) {
|
|
25475
|
-
throw new DispatchUnreachableError(`Dispatch at ${shown} is unreachable: ${errorClass(error)}. If the Dispatch URL changed, restart this agent process so it picks up the new configuration.`, reachedNothing(error));
|
|
25522
|
+
throw new DispatchUnreachableError(`Dispatch at ${shown} is unreachable: ${errorClass(error)}. If the Dispatch URL changed, restart this agent process so it picks up the new configuration.`, reachedNothing(error), errorClass(error));
|
|
25476
25523
|
}
|
|
25477
25524
|
throw error;
|
|
25478
25525
|
}
|
|
@@ -25739,11 +25786,31 @@ class DispatchClient {
|
|
|
25739
25786
|
const path = ["api", "v1", "artifacts", artifactID, "versions", String(version), "reviews"];
|
|
25740
25787
|
const body = { state: input.state, reason: input.reason };
|
|
25741
25788
|
try {
|
|
25789
|
+
const route = await this.#credential.approveRoute?.(this.#credentialSignal(this.#signal));
|
|
25790
|
+
if (route !== undefined) {
|
|
25791
|
+
const via = this.#throughProxy(route, this.#url(path));
|
|
25792
|
+
return (await this.#jsonAnswer("POST", path, body, { via })).payload;
|
|
25793
|
+
}
|
|
25742
25794
|
return await this.#json("POST", path, body);
|
|
25743
25795
|
} catch (error) {
|
|
25744
25796
|
throw this.#refusalOfNoRoute(error, path, (route) => reviewNoRouteRefusal(this.#baseUrl, route, version));
|
|
25745
25797
|
}
|
|
25746
25798
|
}
|
|
25799
|
+
#throughProxy(route, url) {
|
|
25800
|
+
const target = new URL(url);
|
|
25801
|
+
if (target.protocol !== "https:" || target.port !== "" || !route.hosts.includes(target.hostname)) {
|
|
25802
|
+
throw new LoggableError(`a person's review goes through Cipher's proxy, which reaches https://${route.hosts.join(" and https://")} alone, and the Dispatch URL is ${urlForText(this.#baseUrl, DISPATCH_URL_SETTING)}, so no review was sent`);
|
|
25803
|
+
}
|
|
25804
|
+
const proxy = new URL(route.proxyUrl);
|
|
25805
|
+
proxy.username = "agent";
|
|
25806
|
+
proxy.password = route.placeholder;
|
|
25807
|
+
const credential = {
|
|
25808
|
+
scheme: "DPoP",
|
|
25809
|
+
headers: () => ({ Authorization: `DPoP ${route.placeholder}` }),
|
|
25810
|
+
secret: () => route.placeholder
|
|
25811
|
+
};
|
|
25812
|
+
return { credential, init: { proxy: proxy.toString(), tls: { ca: route.caCertificate } } };
|
|
25813
|
+
}
|
|
25747
25814
|
async recordResult(issue, input) {
|
|
25748
25815
|
return this.#json("POST", ["api", "v1", "issues", await this.#resolveIssue(issue), "results"], input);
|
|
25749
25816
|
}
|
|
@@ -25975,12 +26042,12 @@ class DispatchClient {
|
|
|
25975
26042
|
return (await this.#jsonAnswer(method, path, body, { query, signal, key })).payload;
|
|
25976
26043
|
}
|
|
25977
26044
|
async#jsonAnswer(method, path, body, options = {}) {
|
|
25978
|
-
const { query, signal, key, writes = true } = options;
|
|
26045
|
+
const { query, signal, key, writes = true, via } = options;
|
|
25979
26046
|
const url = this.#url(path, query);
|
|
25980
26047
|
const encoded = body === undefined ? undefined : { content: JSON.stringify(body), type: "application/json" };
|
|
25981
26048
|
const write = this.#writeCall(method, url, key, writes);
|
|
25982
26049
|
if (write !== undefined) {
|
|
25983
|
-
const answer = await this.#write(method, url, encoded, "application/json", signal, write);
|
|
26050
|
+
const answer = await this.#write(method, url, encoded, "application/json", signal, write, via);
|
|
25984
26051
|
return { status: answer.response.status, payload: this.#payloadOf(method, url, answer) };
|
|
25985
26052
|
}
|
|
25986
26053
|
return this.#noRoute(async () => {
|
|
@@ -26121,9 +26188,10 @@ class DispatchClient {
|
|
|
26121
26188
|
});
|
|
26122
26189
|
return { answer, presented };
|
|
26123
26190
|
}
|
|
26124
|
-
async#write(method, url, body, accept, signal, write) {
|
|
26191
|
+
async#write(method, url, body, accept, signal, write, via) {
|
|
26125
26192
|
const limit = signal === undefined ? this.#signal : AbortSignal.any([this.#signal, signal]);
|
|
26126
26193
|
const { key, progress } = write;
|
|
26194
|
+
const credential = via?.credential ?? this.#credential;
|
|
26127
26195
|
const headers = { Accept: accept, [IDEMPOTENCY_KEY_HEADER]: key };
|
|
26128
26196
|
if (body !== undefined)
|
|
26129
26197
|
headers["Content-Type"] = body.type;
|
|
@@ -26143,7 +26211,7 @@ class DispatchClient {
|
|
|
26143
26211
|
let presented;
|
|
26144
26212
|
try {
|
|
26145
26213
|
limit.throwIfAborted();
|
|
26146
|
-
presented = await
|
|
26214
|
+
presented = await credential.headers(method, url, undefined, this.#credentialSignal(limit));
|
|
26147
26215
|
this.#sent.note(presented);
|
|
26148
26216
|
limit.throwIfAborted();
|
|
26149
26217
|
} catch (error) {
|
|
@@ -26154,7 +26222,7 @@ class DispatchClient {
|
|
|
26154
26222
|
...error === limit.reason ? {} : { credentialFailure: error }
|
|
26155
26223
|
};
|
|
26156
26224
|
}
|
|
26157
|
-
const identity =
|
|
26225
|
+
const identity = credential.identity?.(presented);
|
|
26158
26226
|
if (state === "may-have-landed" && identity !== login) {
|
|
26159
26227
|
return {
|
|
26160
26228
|
event: "no-credential-final",
|
|
@@ -26166,7 +26234,7 @@ class DispatchClient {
|
|
|
26166
26234
|
progress.sent += 1;
|
|
26167
26235
|
let response;
|
|
26168
26236
|
try {
|
|
26169
|
-
response = await this.#attempt(url, method, { ...headers, ...presented }, body, silenceMs, limit);
|
|
26237
|
+
response = await this.#attempt(url, method, { ...headers, ...presented }, body, silenceMs, limit, via?.init);
|
|
26170
26238
|
} catch (error) {
|
|
26171
26239
|
return {
|
|
26172
26240
|
event: stoppedEvent(limit, true, error) ?? (error instanceof WriteAttemptSilent ? "silence" : error instanceof DispatchUnreachableError && error.reachedNothing ? "unreached" : "reset"),
|
|
@@ -26192,7 +26260,7 @@ class DispatchClient {
|
|
|
26192
26260
|
};
|
|
26193
26261
|
}
|
|
26194
26262
|
return {
|
|
26195
|
-
event: answerEvent(answer, write.key, progress.keyEchoed,
|
|
26263
|
+
event: answerEvent(answer, write.key, progress.keyEchoed, credential.stale !== undefined && !deadTokenTold, via !== undefined),
|
|
26196
26264
|
answer,
|
|
26197
26265
|
presented,
|
|
26198
26266
|
sent,
|
|
@@ -26227,10 +26295,10 @@ class DispatchClient {
|
|
|
26227
26295
|
}
|
|
26228
26296
|
return last.answer;
|
|
26229
26297
|
case "end":
|
|
26230
|
-
throw await this.#endWrite(method, url, state, event === "exhausted" ? last.event : event, last.answer, state === "nothing-sent" && credentialFailure !== undefined && (event === "deadline" || event === "cancelled") ? credentialFailure : last.failure, write, event === "exhausted" && last.event === "no-route" && this.#retryNoRoute);
|
|
26298
|
+
throw await this.#endWrite(method, url, state, event === "exhausted" ? last.event : event, last.answer, state === "nothing-sent" && credentialFailure !== undefined && (event === "deadline" || event === "cancelled") ? credentialFailure : last.failure, write, event === "exhausted" && last.event === "no-route" && this.#retryNoRoute, via);
|
|
26231
26299
|
case "retry-at-once":
|
|
26232
26300
|
deadTokenTold = true;
|
|
26233
|
-
|
|
26301
|
+
credential.stale?.(undefined, last.sent?.with);
|
|
26234
26302
|
last = await next();
|
|
26235
26303
|
event = last.event;
|
|
26236
26304
|
continue;
|
|
@@ -26287,7 +26355,7 @@ class DispatchClient {
|
|
|
26287
26355
|
#now() {
|
|
26288
26356
|
return this.writeRetry.now?.() ?? performance.now();
|
|
26289
26357
|
}
|
|
26290
|
-
async#attempt(url, method, headers, body, silenceMs, limit) {
|
|
26358
|
+
async#attempt(url, method, headers, body, silenceMs, limit, transport) {
|
|
26291
26359
|
const cut = new AbortController;
|
|
26292
26360
|
const silent = () => cut.abort(new WriteAttemptSilent(silenceMs));
|
|
26293
26361
|
let timer = setTimeout(silent, silenceMs);
|
|
@@ -26302,21 +26370,30 @@ class DispatchClient {
|
|
|
26302
26370
|
return await this.#fetch(url, {
|
|
26303
26371
|
method,
|
|
26304
26372
|
signal: AbortSignal.any([limit, cut.signal]),
|
|
26373
|
+
...transport,
|
|
26305
26374
|
...body === undefined ? { headers } : attemptBody(body, headers, progress)
|
|
26306
26375
|
});
|
|
26307
26376
|
} catch (error) {
|
|
26308
26377
|
if (cut.signal.aborted && !limit.aborted)
|
|
26309
26378
|
throw cut.signal.reason;
|
|
26379
|
+
const refused = transport === undefined ? undefined : proxyTunnelAnswer(error);
|
|
26380
|
+
if (refused !== undefined)
|
|
26381
|
+
return refused;
|
|
26310
26382
|
throw error;
|
|
26311
26383
|
} finally {
|
|
26312
26384
|
answered = true;
|
|
26313
26385
|
clearTimeout(timer);
|
|
26314
26386
|
}
|
|
26315
26387
|
}
|
|
26316
|
-
async#endWrite(method, url, state, event, answer, failure, write, routeSpent) {
|
|
26388
|
+
async#endWrite(method, url, state, event, answer, failure, write, routeSpent, via) {
|
|
26317
26389
|
const { request, progress } = write;
|
|
26318
26390
|
let own = failure;
|
|
26319
|
-
|
|
26391
|
+
const proxyCode = via === undefined ? null : answer?.response.headers.get(PROXY_CODE_HEADER);
|
|
26392
|
+
if (via !== undefined && answer !== undefined && typeof proxyCode === "string") {
|
|
26393
|
+
own = this.#proxyRefusal(request, via, answer, proxyCode, state, event);
|
|
26394
|
+
} else if (via !== undefined && failure instanceof DispatchUnreachableError) {
|
|
26395
|
+
own = this.#proxyUnreachable(via, failure, state);
|
|
26396
|
+
} else if (answer?.response.ok === true) {
|
|
26320
26397
|
const { status } = answer.response;
|
|
26321
26398
|
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`);
|
|
26322
26399
|
} else if (answer !== undefined) {
|
|
@@ -26352,6 +26429,17 @@ class DispatchClient {
|
|
|
26352
26429
|
}
|
|
26353
26430
|
return new DispatchWriteUnsettledError(last, progress.sent, write.key, unanswered);
|
|
26354
26431
|
}
|
|
26432
|
+
#proxyUnreachable(via, failure, state) {
|
|
26433
|
+
const again = state === "nothing-sent" ? " The review can be sent again once the broker answers." : "";
|
|
26434
|
+
return new DispatchUnreachableError(`Dispatch at ${urlForText(this.#baseUrl, DISPATCH_URL_SETTING)}, through Cipher's proxy at ${originOf(via.init.proxy)}, is unreachable: ${failure.failure}. The proxy is the secrets broker's.${again}`, failure.reachedNothing, failure.failure);
|
|
26435
|
+
}
|
|
26436
|
+
#proxyRefusal(request, via, answer, code, state, event) {
|
|
26437
|
+
const { status } = answer.response;
|
|
26438
|
+
const said = excerpt(answer.text, this.#sent.with(this.token));
|
|
26439
|
+
const by = `${request} was answered ${status} ${code} by Cipher's proxy at ${originOf(via.init.proxy)}${said === "" ? "" : ` (${JSON.stringify(said)})`}`;
|
|
26440
|
+
const message = state !== "nothing-sent" ? event === "proxy-unsettled" ? `${by}, after this attempt may have reached Dispatch` : `${by} before this attempt left the proxy, after an earlier attempt of the review may have reached Dispatch` : event === "proxy-failed" ? `${by} before any of it left the proxy, so nothing reached Dispatch. The proxy is the secrets broker's, and a new \`dispatch review\` trades a new grant once the broker answers.` : `${by} before any of it left the proxy, so nothing reached Dispatch, and a new \`dispatch review\` trades a new grant.`;
|
|
26441
|
+
return new DispatchProxyRefusalError(code, status, message);
|
|
26442
|
+
}
|
|
26355
26443
|
#url(path, query) {
|
|
26356
26444
|
const url = new URL(`${path.map((segment) => encodeURIComponent(segment)).join("/")}`, `${this.#baseUrl}/`);
|
|
26357
26445
|
if (query) {
|
|
@@ -34969,8 +35057,25 @@ class BrokerTokenClient {
|
|
|
34969
35057
|
return await this.#exchange(await source.read(signal), signal);
|
|
34970
35058
|
}
|
|
34971
35059
|
async#exchange(subject, signal) {
|
|
35060
|
+
const { endpoint, answered, raw } = await this.#grant(subject, signal, {});
|
|
35061
|
+
return this.#read(endpoint, answered, raw);
|
|
35062
|
+
}
|
|
35063
|
+
async proxyPlaceholder(signal) {
|
|
35064
|
+
const trade = async (subject) => {
|
|
35065
|
+
const { endpoint, answered, raw } = await this.#grant(subject, signal, {
|
|
35066
|
+
[FORM_REQUESTED_TOKEN_TYPE]: TOKEN_TYPE_PROXY_PLACEHOLDER
|
|
35067
|
+
});
|
|
35068
|
+
return this.#readPlaceholder(endpoint, answered, raw);
|
|
35069
|
+
};
|
|
35070
|
+
const source = this.#subject;
|
|
35071
|
+
if (source.spend !== undefined)
|
|
35072
|
+
return await source.spend(trade, signal);
|
|
35073
|
+
return await trade(await source.read(signal));
|
|
35074
|
+
}
|
|
35075
|
+
async#grant(subject, signal, asked) {
|
|
34972
35076
|
holdSecret(subject.token, heldUntil(subject.token));
|
|
34973
35077
|
const form = {
|
|
35078
|
+
...asked,
|
|
34974
35079
|
subject_token: subject.token,
|
|
34975
35080
|
subject_token_type: subject.tokenType
|
|
34976
35081
|
};
|
|
@@ -35011,7 +35116,7 @@ class BrokerTokenClient {
|
|
|
35011
35116
|
...this.#session === "" ? {} : { session: this.#session }
|
|
35012
35117
|
});
|
|
35013
35118
|
}
|
|
35014
|
-
return
|
|
35119
|
+
return { endpoint: urlForText(endpoint, BROKER_URL_SETTING), answered, raw: raw.body };
|
|
35015
35120
|
}
|
|
35016
35121
|
async#send(url, options, signal, raw) {
|
|
35017
35122
|
const answer = await sendWithProof({ key: this.#key, holderKey: this.#holderKey, fetch: this.#fetch, nonce: this.#nonce }, url, options, signal);
|
|
@@ -35049,6 +35154,56 @@ class BrokerTokenClient {
|
|
|
35049
35154
|
credentialExpiresAt
|
|
35050
35155
|
};
|
|
35051
35156
|
}
|
|
35157
|
+
#readPlaceholder(endpoint, answered, raw) {
|
|
35158
|
+
const refused = (what) => new BrokerTradeFailedError(`the broker at ${endpoint} answered a proxy placeholder trade with ${what}`);
|
|
35159
|
+
const body = typeof raw === "object" && raw !== null ? raw : {};
|
|
35160
|
+
if (answered["issued_token_type"] !== TOKEN_TYPE_PROXY_PLACEHOLDER) {
|
|
35161
|
+
throw refused("an issued_token_type that is not the proxy placeholder's");
|
|
35162
|
+
}
|
|
35163
|
+
if (body["token_type"] !== TOKEN_TYPE_NOT_APPLICABLE) {
|
|
35164
|
+
throw refused(`a token_type other than ${TOKEN_TYPE_NOT_APPLICABLE}`);
|
|
35165
|
+
}
|
|
35166
|
+
if (answered.refresh_token !== undefined && answered.refresh_token !== "") {
|
|
35167
|
+
throw refused("a refresh token, which this grant never issues");
|
|
35168
|
+
}
|
|
35169
|
+
const seconds = answered.expires_in ?? 0;
|
|
35170
|
+
if (!(seconds > 0))
|
|
35171
|
+
throw refused("no usable expires_in (a positive number of seconds)");
|
|
35172
|
+
const placeholder = answered.access_token;
|
|
35173
|
+
if (!placeholder.startsWith(PLACEHOLDER_PREFIX) || placeholder.length <= PLACEHOLDER_PREFIX.length) {
|
|
35174
|
+
throw refused("an access_token that is no placeholder");
|
|
35175
|
+
}
|
|
35176
|
+
holdSecret(placeholder, Date.now() + seconds * 1000);
|
|
35177
|
+
if (typeof body["grant_id"] !== "string" || body["grant_id"] === "")
|
|
35178
|
+
throw refused("no grant_id");
|
|
35179
|
+
const release = body["proxy"];
|
|
35180
|
+
if (typeof release !== "object" || release === null)
|
|
35181
|
+
throw refused("no proxy release");
|
|
35182
|
+
const {
|
|
35183
|
+
proxy_url: proxyUrl,
|
|
35184
|
+
ca_certificate: caCertificate,
|
|
35185
|
+
proxy_password: password,
|
|
35186
|
+
names
|
|
35187
|
+
} = release;
|
|
35188
|
+
if (typeof proxyUrl !== "string" || !isHttpUrl(proxyUrl))
|
|
35189
|
+
throw refused("a proxy_url that is no http URL");
|
|
35190
|
+
if (typeof caCertificate !== "string" || caCertificate.trim() === "")
|
|
35191
|
+
throw refused("no ca_certificate");
|
|
35192
|
+
if (password !== placeholder)
|
|
35193
|
+
throw refused("a proxy_password other than the placeholder");
|
|
35194
|
+
if (typeof names !== "object" || names === null || Object.keys(names).length === 0) {
|
|
35195
|
+
throw refused("no name behind the proxy");
|
|
35196
|
+
}
|
|
35197
|
+
const read = {};
|
|
35198
|
+
for (const [name, entry] of Object.entries(names)) {
|
|
35199
|
+
const { value, hosts } = typeof entry === "object" && entry !== null ? entry : {};
|
|
35200
|
+
if (value !== placeholder || !Array.isArray(hosts) || hosts.length === 0 || !hosts.every((host) => typeof host === "string" && host !== "")) {
|
|
35201
|
+
throw refused("a name holding no host, or a value other than the placeholder");
|
|
35202
|
+
}
|
|
35203
|
+
read[name] = { hosts };
|
|
35204
|
+
}
|
|
35205
|
+
return { placeholder, proxyUrl, caCertificate, names: read };
|
|
35206
|
+
}
|
|
35052
35207
|
}
|
|
35053
35208
|
function heldUntil(token) {
|
|
35054
35209
|
const now = Date.now();
|
|
@@ -36866,6 +37021,22 @@ function brokerCredential(env, session, read) {
|
|
|
36866
37021
|
const told = headers === undefined ? undefined : presentedAs.get(headers);
|
|
36867
37022
|
dropHeld(told?.key ?? keyOf(env, own(acting), read), told?.token);
|
|
36868
37023
|
},
|
|
37024
|
+
async approveRoute(signal) {
|
|
37025
|
+
const { made } = await untilAborted(clientFor(env, own(undefined), read), signal);
|
|
37026
|
+
if (made.client === undefined || made.signIn === "")
|
|
37027
|
+
return;
|
|
37028
|
+
const held = await made.client.proxyPlaceholder(signal);
|
|
37029
|
+
const approve = held.names[PROXY_APPROVE_NAME];
|
|
37030
|
+
if (approve === undefined) {
|
|
37031
|
+
throw new LoggableError(`the secrets broker answered a placeholder of Cipher's proxy that holds no ${PROXY_APPROVE_NAME}, so no review was sent`);
|
|
37032
|
+
}
|
|
37033
|
+
return {
|
|
37034
|
+
placeholder: held.placeholder,
|
|
37035
|
+
proxyUrl: held.proxyUrl,
|
|
37036
|
+
caCertificate: held.caCertificate,
|
|
37037
|
+
hosts: approve.hosts
|
|
37038
|
+
};
|
|
37039
|
+
},
|
|
36869
37040
|
secret: () => presented
|
|
36870
37041
|
};
|
|
36871
37042
|
}
|