@sjawhar/claude-envoy 2.35.1 → 2.37.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 +2 -1
- package/dist/dispatch.js +245 -35
- package/dist/envoy-channel.js +257 -44
- package/dist/session-hook.js +238 -32
- package/package.json +1 -1
- package/scripts/smoke-session-title.sh +11 -2
- package/skills/agent-secrets/SKILL.md +6 -4
- package/src/envoy-channel-server.ts +3 -3
- package/src/envoy-client.ts +17 -2
- package/src/subscription-topics.ts +2 -2
package/.omp-plugin/plugin.json
CHANGED
package/README.md
CHANGED
|
@@ -538,7 +538,8 @@ in the session's Dispatch state directory carries the same name. Its negative co
|
|
|
538
538
|
first case again against the committed `dist/envoy-channel.js` of `BASE_REV` (default
|
|
539
539
|
`0306bcbe16df-`, the last revision without the fallback), which registers the folder name instead.
|
|
540
540
|
It needs `bun`, `curl`, `jq`, `go` and `nats-server`
|
|
541
|
-
(`go install github.com/nats-io/nats-server/v2@v2.
|
|
541
|
+
(`go install github.com/nats-io/nats-server/v2@v2.15.1`, the hub's version: the listener refuses a
|
|
542
|
+
nats-server below v2.11.12, v2.12.4 or v2.14.0), and no Claude authentication: the two
|
|
542
543
|
hook payloads are written by the script, and that the field arrives at all rests on Claude Code's
|
|
543
544
|
documentation. Claude Code is not installed in an issue pod's image, though it runs there from
|
|
544
545
|
`bunx --package @anthropic-ai/claude-code@<version> claude`, as
|
package/dist/dispatch.js
CHANGED
|
@@ -14696,17 +14696,18 @@ function isPictureType(mime) {
|
|
|
14696
14696
|
// ../contracts/src/subject.ts
|
|
14697
14697
|
var AGENT_TOPIC_PREFIX = "notifications.agent.";
|
|
14698
14698
|
var ROLE_TOPIC_PREFIX = "notifications.role.";
|
|
14699
|
+
var NO_PROJECT = "_";
|
|
14699
14700
|
var LEGION_NOTICE_TOPIC_PREFIX = "notifications.legion.";
|
|
14700
14701
|
var DISPATCH_TOPIC_PREFIX = "notifications.dispatch.";
|
|
14701
14702
|
var DISPATCH_ISSUE_TOPIC_PREFIX = `${DISPATCH_TOPIC_PREFIX}issue.`;
|
|
14702
14703
|
var DISPATCH_DOCUMENT_TOPIC_PREFIX = `${DISPATCH_TOPIC_PREFIX}document.`;
|
|
14703
|
-
function
|
|
14704
|
+
function legacyDispatchIssueSubject(issueKey, type) {
|
|
14704
14705
|
return `${DISPATCH_ISSUE_TOPIC_PREFIX}${issueKey}.${type}`;
|
|
14705
14706
|
}
|
|
14706
14707
|
function dispatchDocumentSubject(project, slug, type) {
|
|
14707
14708
|
return `${DISPATCH_DOCUMENT_TOPIC_PREFIX}${project}.${slug}.${type}`;
|
|
14708
14709
|
}
|
|
14709
|
-
function
|
|
14710
|
+
function legacyAgentSubject(session) {
|
|
14710
14711
|
return `${AGENT_TOPIC_PREFIX}${session}`;
|
|
14711
14712
|
}
|
|
14712
14713
|
var GHOSTWISPR_TOPIC_PREFIX = "notifications.ghostwispr.";
|
|
@@ -17819,6 +17820,95 @@ function canonicalRepo(owner, repo) {
|
|
|
17819
17820
|
}
|
|
17820
17821
|
// ../contracts/src/slack.ts
|
|
17821
17822
|
var SLACK_POST_TEXT_MAX = 4000;
|
|
17823
|
+
// ../contracts/src/subject-project.ts
|
|
17824
|
+
var EXCEPTION_PREFIX = "notifications.envoy.exceptions.";
|
|
17825
|
+
var KEPT_PREFIX = "notifications.envoy.kept.";
|
|
17826
|
+
function isLiteral(token) {
|
|
17827
|
+
return token !== undefined && token !== "" && token !== "*" && token !== ">";
|
|
17828
|
+
}
|
|
17829
|
+
function projectOfToken(token) {
|
|
17830
|
+
return token !== undefined && PROJECT_KEY_PATTERN.test(token) ? token : NO_PROJECT;
|
|
17831
|
+
}
|
|
17832
|
+
function issueProject(key) {
|
|
17833
|
+
const project = DISPATCH_KEY_PATTERN.exec(key)?.[1];
|
|
17834
|
+
return project !== undefined && PROJECT_KEY_PATTERN.test(project) ? project : undefined;
|
|
17835
|
+
}
|
|
17836
|
+
var LEGION_ROLE_TOKEN = /^legion-([a-z0-9]+)-[\s\S]/;
|
|
17837
|
+
function legionTokenProject(token) {
|
|
17838
|
+
return token !== undefined && isLegionProjectToken(token) ? projectOfToken(token.toUpperCase()) : NO_PROJECT;
|
|
17839
|
+
}
|
|
17840
|
+
function roleProject(role) {
|
|
17841
|
+
return legionTokenProject(LEGION_ROLE_TOKEN.exec(role)?.[1]);
|
|
17842
|
+
}
|
|
17843
|
+
function keptLane(topic) {
|
|
17844
|
+
if (!topic.startsWith(KEPT_PREFIX))
|
|
17845
|
+
return;
|
|
17846
|
+
const [kind, ...rest] = topic.slice(KEPT_PREFIX.length).split(".");
|
|
17847
|
+
return kind === "role" || kind === "cursor" ? { kind, rest } : undefined;
|
|
17848
|
+
}
|
|
17849
|
+
function canonicalTopic(topic) {
|
|
17850
|
+
const unchanged = { canonical: topic, legacy: false };
|
|
17851
|
+
if (topic.startsWith(DISPATCH_ISSUE_TOPIC_PREFIX)) {
|
|
17852
|
+
const rest = topic.slice(DISPATCH_ISSUE_TOPIC_PREFIX.length);
|
|
17853
|
+
const project = issueProject(rest.split(".")[0] ?? "");
|
|
17854
|
+
return project === undefined ? unchanged : { canonical: `${DISPATCH_ISSUE_TOPIC_PREFIX}${project}.${rest}`, legacy: true };
|
|
17855
|
+
}
|
|
17856
|
+
if (topic.startsWith(AGENT_TOPIC_PREFIX)) {
|
|
17857
|
+
const rest = topic.slice(AGENT_TOPIC_PREFIX.length).split(".");
|
|
17858
|
+
return rest.length === 1 && isLiteral(rest[0]) ? { canonical: `${AGENT_TOPIC_PREFIX}*.${rest[0]}`, legacy: true } : unchanged;
|
|
17859
|
+
}
|
|
17860
|
+
if (topic.startsWith(ROLE_TOPIC_PREFIX)) {
|
|
17861
|
+
const rest = topic.slice(ROLE_TOPIC_PREFIX.length).split(".");
|
|
17862
|
+
return rest.length === 1 && isLiteral(rest[0]) ? { canonical: `${ROLE_TOPIC_PREFIX}${roleProject(rest[0])}.${rest[0]}`, legacy: true } : unchanged;
|
|
17863
|
+
}
|
|
17864
|
+
if (topic.startsWith(EXCEPTION_PREFIX)) {
|
|
17865
|
+
const wrapped = canonicalTopic(topic.slice(EXCEPTION_PREFIX.length));
|
|
17866
|
+
return wrapped.legacy ? { canonical: `${EXCEPTION_PREFIX}${wrapped.canonical}`, legacy: true } : unchanged;
|
|
17867
|
+
}
|
|
17868
|
+
const kept = keptLane(topic);
|
|
17869
|
+
if (kept !== undefined && kept.rest.length === 1 && isLiteral(kept.rest[0])) {
|
|
17870
|
+
const role = kept.rest[0];
|
|
17871
|
+
return { canonical: `${KEPT_PREFIX}${kept.kind}.${roleProject(role)}.${role}`, legacy: true };
|
|
17872
|
+
}
|
|
17873
|
+
return unchanged;
|
|
17874
|
+
}
|
|
17875
|
+
function isProjectPosition(token) {
|
|
17876
|
+
return token !== undefined && (PROJECT_KEY_PATTERN.test(token) || token === NO_PROJECT || token === "*");
|
|
17877
|
+
}
|
|
17878
|
+
function legacyTwin(canonical) {
|
|
17879
|
+
if (canonical.startsWith(DISPATCH_ISSUE_TOPIC_PREFIX)) {
|
|
17880
|
+
const [project, key, ...rest] = canonical.slice(DISPATCH_ISSUE_TOPIC_PREFIX.length).split(".");
|
|
17881
|
+
if (key === undefined || project === undefined)
|
|
17882
|
+
return;
|
|
17883
|
+
const keyProject = issueProject(key);
|
|
17884
|
+
if (keyProject === undefined || project !== keyProject)
|
|
17885
|
+
return;
|
|
17886
|
+
return [`${DISPATCH_ISSUE_TOPIC_PREFIX}${key}`, ...rest].join(".");
|
|
17887
|
+
}
|
|
17888
|
+
for (const prefix of [AGENT_TOPIC_PREFIX, ROLE_TOPIC_PREFIX]) {
|
|
17889
|
+
if (canonical.startsWith(prefix)) {
|
|
17890
|
+
const rest = canonical.slice(prefix.length).split(".");
|
|
17891
|
+
return rest.length === 2 && isProjectPosition(rest[0]) && isLiteral(rest[1]) ? `${prefix}${rest[1]}` : undefined;
|
|
17892
|
+
}
|
|
17893
|
+
}
|
|
17894
|
+
if (canonical.startsWith(EXCEPTION_PREFIX)) {
|
|
17895
|
+
const twin = legacyTwin(canonical.slice(EXCEPTION_PREFIX.length));
|
|
17896
|
+
return twin === undefined ? undefined : `${EXCEPTION_PREFIX}${twin}`;
|
|
17897
|
+
}
|
|
17898
|
+
const kept = keptLane(canonical);
|
|
17899
|
+
if (kept !== undefined && kept.rest.length === 2 && isProjectPosition(kept.rest[0])) {
|
|
17900
|
+
const role = kept.rest[1];
|
|
17901
|
+
return isLiteral(role) ? `${KEPT_PREFIX}${kept.kind}.${role}` : undefined;
|
|
17902
|
+
}
|
|
17903
|
+
return;
|
|
17904
|
+
}
|
|
17905
|
+
function topicForms(topic) {
|
|
17906
|
+
const { canonical, legacy } = canonicalTopic(topic);
|
|
17907
|
+
if (legacy)
|
|
17908
|
+
return [topic, canonical];
|
|
17909
|
+
const twin = legacyTwin(topic);
|
|
17910
|
+
return twin === undefined ? [topic] : [topic, twin];
|
|
17911
|
+
}
|
|
17822
17912
|
// ../contracts/src/tool-schema.ts
|
|
17823
17913
|
function overCapMessage(length, max) {
|
|
17824
17914
|
return `is ${length - max} characters over the ${max}-character limit (${length}/${max})`;
|
|
@@ -19247,14 +19337,15 @@ class DispatchClient {
|
|
|
19247
19337
|
}
|
|
19248
19338
|
async#sendPresenting(method, url, body, accept, signal, key) {
|
|
19249
19339
|
const headers = { Accept: accept };
|
|
19250
|
-
|
|
19340
|
+
const limit = signal === undefined ? this.#signal : AbortSignal.any([this.#signal, signal]);
|
|
19341
|
+
let presented = await this.#credential.headers(method, url, undefined, limit);
|
|
19251
19342
|
if (body !== undefined)
|
|
19252
19343
|
headers["Content-Type"] = body.type;
|
|
19253
19344
|
if (key === undefined) {
|
|
19254
19345
|
return this.fetchImpl(url, {
|
|
19255
19346
|
method,
|
|
19256
19347
|
headers: { ...headers, ...presented },
|
|
19257
|
-
signal:
|
|
19348
|
+
signal: limit,
|
|
19258
19349
|
...body === undefined ? {} : { body: body.content }
|
|
19259
19350
|
});
|
|
19260
19351
|
}
|
|
@@ -19274,7 +19365,7 @@ class DispatchClient {
|
|
|
19274
19365
|
let thrown;
|
|
19275
19366
|
try {
|
|
19276
19367
|
if (attempt > 1)
|
|
19277
|
-
presented = await this.#credential.headers(method, url);
|
|
19368
|
+
presented = await this.#credential.headers(method, url, undefined, limit);
|
|
19278
19369
|
const sent = { ...headers, ...presented };
|
|
19279
19370
|
answer = await writeAnswer(await this.#attempt(url, method, sent, body, silenceMs), key);
|
|
19280
19371
|
if (answer.echoed)
|
|
@@ -19377,10 +19468,14 @@ class DispatchClient {
|
|
|
19377
19468
|
async#probeKeyedLayer() {
|
|
19378
19469
|
try {
|
|
19379
19470
|
const probe = `${this.#baseUrl}/healthz`;
|
|
19471
|
+
const limit = AbortSignal.any([this.#signal, AbortSignal.timeout(KEY_LAYER_PROBE_MS)]);
|
|
19380
19472
|
const response = await this.fetchImpl(probe, {
|
|
19381
19473
|
method: "GET",
|
|
19382
|
-
headers: {
|
|
19383
|
-
|
|
19474
|
+
headers: {
|
|
19475
|
+
Accept: "application/json",
|
|
19476
|
+
...await this.#credential.headers("GET", probe, undefined, limit)
|
|
19477
|
+
},
|
|
19478
|
+
signal: limit
|
|
19384
19479
|
});
|
|
19385
19480
|
if (!isJson(response))
|
|
19386
19481
|
return false;
|
|
@@ -19666,7 +19761,7 @@ function ownerTitle(owner) {
|
|
|
19666
19761
|
return "";
|
|
19667
19762
|
}
|
|
19668
19763
|
function issueTopic(key) {
|
|
19669
|
-
return { label: key, topic:
|
|
19764
|
+
return { label: key, topic: legacyDispatchIssueSubject(key, ">") };
|
|
19670
19765
|
}
|
|
19671
19766
|
function documentTopicOf(project, slug) {
|
|
19672
19767
|
return {
|
|
@@ -21106,7 +21201,7 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
|
|
|
21106
21201
|
...dispatchIssue === undefined ? [] : [dispatchIssue]
|
|
21107
21202
|
].join(", ") || undefined;
|
|
21108
21203
|
const rendered = {
|
|
21109
|
-
...envelope.topic
|
|
21204
|
+
...envelope.topic !== undefined && topicForms(envelope.topic).includes(legacyAgentSubject(sessionID)) ? { to: `you (${sessionID})` } : {},
|
|
21110
21205
|
from: senderLabel(envelope),
|
|
21111
21206
|
at: inboundTimestamp(envelope.issued_at),
|
|
21112
21207
|
id: envelope.event_id ?? "unknown",
|
|
@@ -27855,6 +27950,7 @@ var SUBJECT_TOKEN_TYPE_GOOGLE = "urn:envoy:params:oauth:token-type:google-identi
|
|
|
27855
27950
|
var SUBJECT_TOKEN_TYPE_PERSON = "urn:envoy:params:oauth:token-type:person-google-identity";
|
|
27856
27951
|
var ACTOR_TOKEN_TYPE_MACHINE = "urn:envoy:params:oauth:token-type:machine-google-identity";
|
|
27857
27952
|
var TOKEN_TYPE_DPOP = "DPoP";
|
|
27953
|
+
var POD_SESSION_NOT_REGISTERED = "pod_session_not_registered";
|
|
27858
27954
|
|
|
27859
27955
|
// ../broker-client/src/metadata-identity.ts
|
|
27860
27956
|
var METADATA_HOST_VAR = "GCE_METADATA_HOST";
|
|
@@ -29285,6 +29381,26 @@ var DEFAULT_RENEW_BEFORE_MS = 5 * 60000;
|
|
|
29285
29381
|
var TOO_MANY_REQUESTS = 429;
|
|
29286
29382
|
var INVALID_DPOP_PROOF = "invalid_dpop_proof";
|
|
29287
29383
|
var USE_DPOP_NONCE = "use_dpop_nonce";
|
|
29384
|
+
var INVALID_GRANT = "invalid_grant";
|
|
29385
|
+
var UNREGISTERED_FIRST_WAIT_MS = 15000;
|
|
29386
|
+
var UNREGISTERED_MAX_WAIT_MS = 5 * 60000;
|
|
29387
|
+
var UNREGISTERED_LOG_EVERY_MS = 30 * 60000;
|
|
29388
|
+
function sleep2(ms, signal) {
|
|
29389
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
29390
|
+
if (signal?.aborted) {
|
|
29391
|
+
resolve();
|
|
29392
|
+
return promise;
|
|
29393
|
+
}
|
|
29394
|
+
const done = () => {
|
|
29395
|
+
clearTimeout(timer);
|
|
29396
|
+
signal?.removeEventListener("abort", done);
|
|
29397
|
+
resolve();
|
|
29398
|
+
};
|
|
29399
|
+
const timer = setTimeout(done, ms);
|
|
29400
|
+
timer.unref();
|
|
29401
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
29402
|
+
return promise;
|
|
29403
|
+
}
|
|
29288
29404
|
|
|
29289
29405
|
class BrokerRefusedError extends Error {
|
|
29290
29406
|
status;
|
|
@@ -29298,7 +29414,19 @@ class BrokerRefusedError extends Error {
|
|
|
29298
29414
|
this.name = "BrokerRefusedError";
|
|
29299
29415
|
}
|
|
29300
29416
|
get permanent() {
|
|
29301
|
-
return this.status !== TOO_MANY_REQUESTS && this.code !== INVALID_DPOP_PROOF && this.code !== USE_DPOP_NONCE;
|
|
29417
|
+
return this.status !== TOO_MANY_REQUESTS && this.code !== INVALID_DPOP_PROOF && this.code !== USE_DPOP_NONCE && !this.podSessionUnregistered;
|
|
29418
|
+
}
|
|
29419
|
+
get podSessionUnregistered() {
|
|
29420
|
+
return this.code === INVALID_GRANT && this.description.startsWith(`${POD_SESSION_NOT_REGISTERED}:`);
|
|
29421
|
+
}
|
|
29422
|
+
}
|
|
29423
|
+
|
|
29424
|
+
class RegistrationPendingError extends Error {
|
|
29425
|
+
session;
|
|
29426
|
+
constructor(session, refusal) {
|
|
29427
|
+
super(`the secrets broker has no registration for this pod's session ${session} yet, and the trade is being retried in the background until it lands (${refusal.description})`, { cause: refusal });
|
|
29428
|
+
this.session = session;
|
|
29429
|
+
this.name = "RegistrationPendingError";
|
|
29302
29430
|
}
|
|
29303
29431
|
}
|
|
29304
29432
|
|
|
@@ -29347,10 +29475,16 @@ class BrokerTokenClient {
|
|
|
29347
29475
|
#launcherCredential;
|
|
29348
29476
|
#renewBeforeMs;
|
|
29349
29477
|
#now;
|
|
29478
|
+
#sleep;
|
|
29479
|
+
#log;
|
|
29350
29480
|
#fetch;
|
|
29351
29481
|
#nonce = "";
|
|
29352
29482
|
#held = null;
|
|
29353
29483
|
#trading = null;
|
|
29484
|
+
#waiters = new Set;
|
|
29485
|
+
#pending = null;
|
|
29486
|
+
#wake = null;
|
|
29487
|
+
#closed = new AbortController;
|
|
29354
29488
|
constructor(options) {
|
|
29355
29489
|
const brokerUrl = withoutTrailingSlashes(options.brokerUrl.trim());
|
|
29356
29490
|
if (brokerUrl === "")
|
|
@@ -29364,6 +29498,8 @@ class BrokerTokenClient {
|
|
|
29364
29498
|
this.#launcherCredential = options.launcherCredential ?? true;
|
|
29365
29499
|
this.#renewBeforeMs = options.renewBeforeMs ?? DEFAULT_RENEW_BEFORE_MS;
|
|
29366
29500
|
this.#now = options.now ?? Date.now;
|
|
29501
|
+
this.#sleep = options.sleep ?? sleep2;
|
|
29502
|
+
this.#log = options.log ?? console.warn;
|
|
29367
29503
|
this.#fetch = options.fetch ?? fetch;
|
|
29368
29504
|
}
|
|
29369
29505
|
get key() {
|
|
@@ -29376,31 +29512,95 @@ class BrokerTokenClient {
|
|
|
29376
29512
|
const held = this.#held;
|
|
29377
29513
|
if (held !== null && this.#now() < held.expiresAt.getTime() - this.#renewBeforeMs)
|
|
29378
29514
|
return held;
|
|
29379
|
-
if (this.#trading
|
|
29380
|
-
|
|
29381
|
-
|
|
29382
|
-
|
|
29383
|
-
|
|
29384
|
-
|
|
29385
|
-
}
|
|
29515
|
+
if (this.#trading === null) {
|
|
29516
|
+
const started = this.#renew();
|
|
29517
|
+
this.#trading = started;
|
|
29518
|
+
started.then((token) => this.#settled(started, (waiter) => waiter.resolve(token)), (error) => this.#settled(started, (waiter) => waiter.reject(error)));
|
|
29519
|
+
} else {
|
|
29520
|
+
this.#wake?.();
|
|
29521
|
+
}
|
|
29522
|
+
return await this.#joined(signal);
|
|
29523
|
+
}
|
|
29524
|
+
#settled(started, tell) {
|
|
29525
|
+
if (this.#trading === started)
|
|
29386
29526
|
this.#trading = null;
|
|
29527
|
+
const waiters = [...this.#waiters];
|
|
29528
|
+
this.#waiters.clear();
|
|
29529
|
+
for (const waiter of waiters)
|
|
29530
|
+
tell(waiter);
|
|
29531
|
+
}
|
|
29532
|
+
#joined(signal) {
|
|
29533
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
29534
|
+
const stop = () => {
|
|
29535
|
+
this.#waiters.delete(waiter);
|
|
29536
|
+
const pending = this.#pending;
|
|
29537
|
+
reject(pending === null ? signal?.reason : new RegistrationPendingError(this.#session, pending));
|
|
29538
|
+
};
|
|
29539
|
+
const waiter = {
|
|
29540
|
+
resolve: (token) => {
|
|
29541
|
+
signal?.removeEventListener("abort", stop);
|
|
29542
|
+
resolve(token);
|
|
29543
|
+
},
|
|
29544
|
+
reject: (error) => {
|
|
29545
|
+
signal?.removeEventListener("abort", stop);
|
|
29546
|
+
reject(error);
|
|
29547
|
+
}
|
|
29548
|
+
};
|
|
29549
|
+
if (signal?.aborted) {
|
|
29550
|
+
stop();
|
|
29551
|
+
return promise;
|
|
29387
29552
|
}
|
|
29553
|
+
this.#waiters.add(waiter);
|
|
29554
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
29555
|
+
return promise;
|
|
29556
|
+
}
|
|
29557
|
+
close() {
|
|
29558
|
+
this.#closed.abort();
|
|
29388
29559
|
}
|
|
29389
29560
|
drop() {
|
|
29390
29561
|
this.#held = null;
|
|
29391
29562
|
}
|
|
29392
|
-
async#renew(
|
|
29563
|
+
async#renew() {
|
|
29564
|
+
const closed = this.#closed.signal;
|
|
29565
|
+
let wait = UNREGISTERED_FIRST_WAIT_MS;
|
|
29566
|
+
let since = null;
|
|
29567
|
+
let logged = null;
|
|
29393
29568
|
try {
|
|
29394
|
-
|
|
29395
|
-
|
|
29396
|
-
|
|
29397
|
-
|
|
29398
|
-
|
|
29399
|
-
|
|
29400
|
-
|
|
29569
|
+
while (true) {
|
|
29570
|
+
try {
|
|
29571
|
+
const token = await this.#trade(closed);
|
|
29572
|
+
this.#held = token;
|
|
29573
|
+
return token;
|
|
29574
|
+
} catch (error) {
|
|
29575
|
+
const held = this.#held;
|
|
29576
|
+
if (!isFinalRefusal(error) && held !== null && this.#now() < held.expiresAt.getTime()) {
|
|
29577
|
+
return held;
|
|
29578
|
+
}
|
|
29579
|
+
this.#held = null;
|
|
29580
|
+
const unregistered = error instanceof BrokerRefusedError && error.podSessionUnregistered;
|
|
29581
|
+
if (!unregistered || closed.aborted)
|
|
29582
|
+
throw error;
|
|
29583
|
+
this.#pending = error;
|
|
29584
|
+
const now = this.#now();
|
|
29585
|
+
since ??= now;
|
|
29586
|
+
if (logged === null || now - logged >= UNREGISTERED_LOG_EVERY_MS) {
|
|
29587
|
+
logged = now;
|
|
29588
|
+
this.#log(`the secrets broker has no registration for this pod's session ${this.#session} yet (${Math.round((now - since) / 1000)} s so far); trading ${this.describe()} again until it lands`);
|
|
29589
|
+
}
|
|
29590
|
+
const woken = new AbortController;
|
|
29591
|
+
this.#wake = () => woken.abort();
|
|
29592
|
+
try {
|
|
29593
|
+
await this.#sleep(wait, AbortSignal.any([closed, woken.signal]));
|
|
29594
|
+
} finally {
|
|
29595
|
+
this.#wake = null;
|
|
29596
|
+
}
|
|
29597
|
+
if (closed.aborted)
|
|
29598
|
+
throw error;
|
|
29599
|
+
wait = Math.min(wait * 2, UNREGISTERED_MAX_WAIT_MS);
|
|
29600
|
+
}
|
|
29401
29601
|
}
|
|
29402
|
-
|
|
29403
|
-
|
|
29602
|
+
} finally {
|
|
29603
|
+
this.#pending = null;
|
|
29404
29604
|
}
|
|
29405
29605
|
}
|
|
29406
29606
|
async#trade(signal) {
|
|
@@ -29506,7 +29706,7 @@ class BrokerTokenClient {
|
|
|
29506
29706
|
|
|
29507
29707
|
// ../broker-client/src/person-identity.ts
|
|
29508
29708
|
var ISSUER_TIMEOUT_SECONDS = 30;
|
|
29509
|
-
var
|
|
29709
|
+
var INVALID_GRANT2 = "invalid_grant";
|
|
29510
29710
|
function issuerSaid(error) {
|
|
29511
29711
|
if (error instanceof ResponseBodyError) {
|
|
29512
29712
|
const description = error.error_description ?? "";
|
|
@@ -29563,7 +29763,7 @@ function personIdentity(record, flow, options = {}) {
|
|
|
29563
29763
|
config[customFetch2] = through(signal);
|
|
29564
29764
|
answered = await refreshTokenGrant(config, refreshToken);
|
|
29565
29765
|
} catch (error) {
|
|
29566
|
-
if (error instanceof ResponseBodyError && error.error ===
|
|
29766
|
+
if (error instanceof ResponseBodyError && error.error === INVALID_GRANT2) {
|
|
29567
29767
|
throw new SignInEndedError(flow.issuer, person, { cause: error });
|
|
29568
29768
|
}
|
|
29569
29769
|
throw new Error(`renew ${person}'s sign-in at ${flow.issuer}: ${issuerSaid(error)}`);
|
|
@@ -29845,8 +30045,14 @@ function brokerRouteConfigured(env) {
|
|
|
29845
30045
|
return { traded: true };
|
|
29846
30046
|
}
|
|
29847
30047
|
var CLIENTS = new Map;
|
|
30048
|
+
function closeAll(entries) {
|
|
30049
|
+
for (const held of entries?.values() ?? [])
|
|
30050
|
+
held.made?.client?.close();
|
|
30051
|
+
}
|
|
29848
30052
|
function forgetBrokerSession(session) {
|
|
29849
|
-
|
|
30053
|
+
const key = session.trim();
|
|
30054
|
+
closeAll(CLIENTS.get(key));
|
|
30055
|
+
CLIENTS.delete(key);
|
|
29850
30056
|
}
|
|
29851
30057
|
function signInName(record) {
|
|
29852
30058
|
return `${record.person}\x00${record.thumbprint}`;
|
|
@@ -29908,7 +30114,7 @@ function brokerCredential(env, session) {
|
|
|
29908
30114
|
const own = (acting) => (acting ?? "").trim() || sessionName(session);
|
|
29909
30115
|
return {
|
|
29910
30116
|
scheme: "DPoP",
|
|
29911
|
-
async headers(method, url, acting) {
|
|
30117
|
+
async headers(method, url, acting, signal) {
|
|
29912
30118
|
const { entry, made } = await clientFor(env, own(acting));
|
|
29913
30119
|
const { client } = made;
|
|
29914
30120
|
if (client === undefined) {
|
|
@@ -29916,7 +30122,7 @@ function brokerCredential(env, session) {
|
|
|
29916
30122
|
}
|
|
29917
30123
|
let token;
|
|
29918
30124
|
try {
|
|
29919
|
-
token = await client.token();
|
|
30125
|
+
token = await client.token(signal);
|
|
29920
30126
|
} catch (error) {
|
|
29921
30127
|
if (made.signIn !== "" && isFinalRefusal(error))
|
|
29922
30128
|
entry.refused.set(made.signIn, error);
|
|
@@ -30368,7 +30574,8 @@ function reachesPrivateStreamSubject(ownAgentSubject, topic, roles = []) {
|
|
|
30368
30574
|
const role = controllerNoticeRole(topic);
|
|
30369
30575
|
if (role !== undefined)
|
|
30370
30576
|
return !roles.includes(role);
|
|
30371
|
-
|
|
30577
|
+
const own = topic === ownAgentSubject || legacyTwin(topic) === ownAgentSubject;
|
|
30578
|
+
return !own || /[*>]/.test(ownAgentSubject);
|
|
30372
30579
|
}
|
|
30373
30580
|
function registrationTopics(ownAgentSubject, followed, roles = []) {
|
|
30374
30581
|
return [
|
|
@@ -30609,21 +30816,24 @@ function createEnvoyClient(config) {
|
|
|
30609
30816
|
const attemptOnce = async (url, init, deadlineMs, actingSession) => {
|
|
30610
30817
|
let response;
|
|
30611
30818
|
let unminted;
|
|
30819
|
+
const deadline = AbortSignal.timeout(deadlineMs);
|
|
30612
30820
|
try {
|
|
30613
30821
|
const headers = new Headers(init.headers);
|
|
30614
30822
|
let presented;
|
|
30615
30823
|
try {
|
|
30616
|
-
const ready = credential?.headers(init.method ?? "GET", url, actingSession);
|
|
30824
|
+
const ready = credential?.headers(init.method ?? "GET", url, actingSession, deadline);
|
|
30617
30825
|
presented = ready instanceof Promise ? await ready : ready;
|
|
30618
30826
|
} catch (error) {
|
|
30619
30827
|
unminted = error;
|
|
30620
30828
|
}
|
|
30829
|
+
if (unminted !== undefined && deadline.aborted)
|
|
30830
|
+
return { unanswered: unminted };
|
|
30621
30831
|
for (const [name, value] of Object.entries(presented ?? {}))
|
|
30622
30832
|
headers.set(name, value);
|
|
30623
30833
|
response = await config.fetch(url, {
|
|
30624
30834
|
...init,
|
|
30625
30835
|
headers,
|
|
30626
|
-
signal:
|
|
30836
|
+
signal: deadline
|
|
30627
30837
|
});
|
|
30628
30838
|
} catch (error) {
|
|
30629
30839
|
return { unanswered: error };
|