@cortexkit/opencode-antigravity-auth 3.0.7 → 3.0.8
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/dist/cli.js +1001 -63
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +112 -30
- package/dist/index.js +1270 -219
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +154 -48
- package/dist/server.js +1190 -120
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/common-auth-embedded/claustrum/availability.d.ts +89 -0
- package/dist/src/common-auth-embedded/claustrum/availability.js +106 -0
- package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +31 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.js +114 -5
- package/dist/src/common-auth-embedded/claustrum/custody.d.ts +106 -14
- package/dist/src/common-auth-embedded/claustrum/custody.js +294 -16
- package/dist/src/common-auth-embedded/claustrum/errors.d.ts +1 -0
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +5 -3
- package/dist/src/common-auth-embedded/claustrum/index.js +4 -1
- package/dist/src/common-auth-embedded/claustrum/insula.d.ts +48 -0
- package/dist/src/common-auth-embedded/claustrum/insula.js +286 -21
- package/dist/src/common-auth-embedded/claustrum/watch.d.ts +141 -0
- package/dist/src/common-auth-embedded/claustrum/watch.js +254 -0
- package/dist/src/common-auth-embedded/fs/private-files.js +10 -2
- package/dist/src/common-auth-embedded/quota/format.d.ts +3 -0
- package/dist/src/common-auth-embedded/quota/format.js +69 -1
- package/dist/src/common-auth-embedded/quota/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/quota/projection.d.ts +16 -0
- package/dist/src/common-auth-embedded/source-output.json +81 -49
- package/dist/src/ga/server/index.d.ts +2 -0
- package/dist/src/ga/server/index.d.ts.map +1 -1
- package/dist/src/ga/server/index.js +14 -1
- package/dist/src/ga/server/index.js.map +1 -1
- package/dist/src/plugin/auth-loader.d.ts +2 -1
- package/dist/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/src/plugin/auth-loader.js +5 -4
- package/dist/src/plugin/auth-loader.js.map +1 -1
- package/dist/src/plugin/fetch-interceptor.d.ts +2 -1
- package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
- package/dist/src/plugin/fetch-interceptor.js +8 -6
- package/dist/src/plugin/fetch-interceptor.js.map +1 -1
- package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/src/plugin/ga-location-services.js +3 -0
- package/dist/src/plugin/ga-location-services.js.map +1 -1
- package/dist/src/plugin/shared/after-handoff.d.ts +14 -0
- package/dist/src/plugin/shared/after-handoff.d.ts.map +1 -0
- package/dist/src/plugin/shared/after-handoff.js +89 -0
- package/dist/src/plugin/shared/after-handoff.js.map +1 -0
- package/dist/src/plugin/shared/request-services.d.ts +8 -2
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +57 -36
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.d.ts +2 -2
- package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.js +14 -1
- package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
- package/dist/src/plugin/vault-custody.d.ts +2 -0
- package/dist/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/src/plugin/vault-custody.js +3 -0
- package/dist/src/plugin/vault-custody.js.map +1 -1
- package/dist/src/tui.d.ts.map +1 -1
- package/dist/src/tui.js +82 -66
- package/dist/src/tui.js.map +1 -1
- package/dist/tui-build-map.json +27 -27
- package/dist/tui-ga-build-map.json +5 -5
- package/dist/types/src/common-auth-embedded/claustrum/availability.d.ts +89 -0
- package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +31 -1
- package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +106 -14
- package/dist/types/src/common-auth-embedded/claustrum/errors.d.ts +1 -0
- package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +5 -3
- package/dist/types/src/common-auth-embedded/claustrum/insula.d.ts +48 -0
- package/dist/types/src/common-auth-embedded/claustrum/watch.d.ts +141 -0
- package/dist/types/src/common-auth-embedded/quota/format.d.ts +3 -0
- package/dist/types/src/common-auth-embedded/quota/index.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/quota/projection.d.ts +16 -0
- package/dist/types/src/ga/server/index.d.ts +2 -0
- package/dist/types/src/ga/server/index.d.ts.map +1 -1
- package/dist/types/src/plugin/auth-loader.d.ts +2 -1
- package/dist/types/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/types/src/plugin/fetch-interceptor.d.ts +2 -1
- package/dist/types/src/plugin/fetch-interceptor.d.ts.map +1 -1
- package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/after-handoff.d.ts +14 -0
- package/dist/types/src/plugin/shared/after-handoff.d.ts.map +1 -0
- package/dist/types/src/plugin/shared/request-services.d.ts +8 -2
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +2 -2
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-custody.d.ts +2 -0
- package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/common-auth-embedded/claustrum/availability.d.ts +89 -0
- package/src/common-auth-embedded/claustrum/availability.js +106 -0
- package/src/common-auth-embedded/claustrum/consumer.d.ts +31 -1
- package/src/common-auth-embedded/claustrum/consumer.js +114 -5
- package/src/common-auth-embedded/claustrum/custody.d.ts +106 -14
- package/src/common-auth-embedded/claustrum/custody.js +294 -16
- package/src/common-auth-embedded/claustrum/errors.d.ts +1 -0
- package/src/common-auth-embedded/claustrum/index.d.ts +5 -3
- package/src/common-auth-embedded/claustrum/index.js +4 -1
- package/src/common-auth-embedded/claustrum/insula.d.ts +48 -0
- package/src/common-auth-embedded/claustrum/insula.js +286 -21
- package/src/common-auth-embedded/claustrum/watch.d.ts +141 -0
- package/src/common-auth-embedded/claustrum/watch.js +254 -0
- package/src/common-auth-embedded/fs/private-files.js +10 -2
- package/src/common-auth-embedded/quota/format.d.ts +3 -0
- package/src/common-auth-embedded/quota/format.js +69 -1
- package/src/common-auth-embedded/quota/index.d.ts +1 -1
- package/src/common-auth-embedded/quota/projection.d.ts +16 -0
- package/src/common-auth-embedded/source-output.json +81 -49
- package/src/tui-compiled/common-auth-embedded/fs/private-files.js +10 -2
- package/src/tui-compiled/common-auth-embedded/quota/format.js +69 -1
- package/src/tui-compiled/tui.js +123 -97
- package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +69 -1
- package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +69 -1
- package/src/tui-raw/common-auth-embedded/fs/private-files.js +10 -2
- package/src/tui-raw/common-auth-embedded/quota/format.js +69 -1
- package/src/tui-raw/tui.tsx +126 -107
- package/src/tui.tsx +126 -107
package/dist/server.js
CHANGED
|
@@ -336,6 +336,7 @@ function scopedWindowParts(quota, options) {
|
|
|
336
336
|
const remainingPercent = clampPercent(limit.remainingPercent ?? 0);
|
|
337
337
|
return {
|
|
338
338
|
scope: limit.scope,
|
|
339
|
+
...limit.windowMinutes === void 0 ? {} : { windowMinutes: limit.windowMinutes },
|
|
339
340
|
part: {
|
|
340
341
|
kind: "window",
|
|
341
342
|
name: quotaWindowName(limit),
|
|
@@ -404,8 +405,42 @@ function scopeAbbreviations(scopes) {
|
|
|
404
405
|
}
|
|
405
406
|
return new Map(scopes.map((scope) => [scope, short(scopeDisplayName(scope))]));
|
|
406
407
|
}
|
|
408
|
+
function groupShortNames(groups) {
|
|
409
|
+
const labels = groups.map((group) => group.label.trim() || group.scope);
|
|
410
|
+
const short = scopeAbbreviations(labels);
|
|
411
|
+
return labels.map((label) => short.get(label) ?? label);
|
|
412
|
+
}
|
|
413
|
+
function groupedNarrowPieces(groups, windows) {
|
|
414
|
+
if (!groups || groups.length === 0)
|
|
415
|
+
return void 0;
|
|
416
|
+
const reported = windows.filter(({ part }) => part.kind === "window");
|
|
417
|
+
if (reported.some(({ scope }) => scope === ALL_SCOPE))
|
|
418
|
+
return void 0;
|
|
419
|
+
const candidates = groups.flatMap((group, listed) => {
|
|
420
|
+
const inGroup = reported.filter(({ scope }) => scope === group.scope);
|
|
421
|
+
const groupTightest = inGroup.reduce((least, window) => least === void 0 || (window.part.remainingPercent ?? 0) < (least.part.remainingPercent ?? 0) ? window : least, void 0);
|
|
422
|
+
return groupTightest ? [{ group, listed, window: groupTightest }] : [];
|
|
423
|
+
});
|
|
424
|
+
if (candidates.length === 0)
|
|
425
|
+
return void 0;
|
|
426
|
+
const names = groupShortNames(groups);
|
|
427
|
+
const left = (candidate) => candidate.window.part.remainingPercent ?? 0;
|
|
428
|
+
const shown = [...candidates].sort((a, b) => left(a) - left(b) || a.listed - b.listed).slice(0, NARROW_GROUP_LIMIT).sort((a, b) => a.listed - b.listed);
|
|
429
|
+
return shown.map((candidate, index) => {
|
|
430
|
+
const { windowMinutes } = candidate.window;
|
|
431
|
+
const piece = [
|
|
432
|
+
names[candidate.listed] ?? candidate.group.scope,
|
|
433
|
+
...windowMinutes === void 0 ? [] : [lengthName(windowMinutes)],
|
|
434
|
+
`${wholePercent(left(candidate))}%`
|
|
435
|
+
].join(" ");
|
|
436
|
+
return index === shown.length - 1 ? `${piece} left` : piece;
|
|
437
|
+
});
|
|
438
|
+
}
|
|
407
439
|
function narrowTextParts(quota, options) {
|
|
408
440
|
const { windows } = scopedWindowParts(quota, options);
|
|
441
|
+
const grouped = groupedNarrowPieces(quota?.groups, windows);
|
|
442
|
+
if (grouped)
|
|
443
|
+
return grouped;
|
|
409
444
|
const general = windows.filter(({ part, scope }) => part.kind === "window" && scope === ALL_SCOPE);
|
|
410
445
|
const scoped = windows.filter(({ part, scope }) => part.kind === "window" && scope !== ALL_SCOPE);
|
|
411
446
|
const abbreviations = scopeAbbreviations(scoped.map(({ scope }) => scope));
|
|
@@ -444,7 +479,7 @@ function formatQuota(quota, options) {
|
|
|
444
479
|
return parts.join(" \xB7 ");
|
|
445
480
|
return quota && quota.limits.length > 0 ? NO_LIMITS_REPORTED : NO_QUOTA_READING;
|
|
446
481
|
}
|
|
447
|
-
var QUOTA_STALE_AFTER_MS, NO_QUOTA_READING, NO_LIMITS_REPORTED;
|
|
482
|
+
var QUOTA_STALE_AFTER_MS, NO_QUOTA_READING, NO_LIMITS_REPORTED, NARROW_GROUP_LIMIT;
|
|
448
483
|
var init_format = __esm({
|
|
449
484
|
"../core/dist/common-auth-embedded/quota/format.js"() {
|
|
450
485
|
"use strict";
|
|
@@ -452,6 +487,7 @@ var init_format = __esm({
|
|
|
452
487
|
QUOTA_STALE_AFTER_MS = 15 * 6e4;
|
|
453
488
|
NO_QUOTA_READING = "no quota reading yet";
|
|
454
489
|
NO_LIMITS_REPORTED = "no limits reported";
|
|
490
|
+
NARROW_GROUP_LIMIT = 2;
|
|
455
491
|
}
|
|
456
492
|
});
|
|
457
493
|
|
|
@@ -813,19 +849,24 @@ async function replaceWindowsFile(from, to, options = {}) {
|
|
|
813
849
|
to = resolve2(to);
|
|
814
850
|
const now = options.now ?? (() => performance.now());
|
|
815
851
|
const start = now();
|
|
816
|
-
const
|
|
852
|
+
const leaseDeadline = options.deadline ?? Infinity;
|
|
853
|
+
let retryDeadline;
|
|
817
854
|
const delays = [0, 10, 20, 40, 80, 100];
|
|
818
855
|
let original;
|
|
819
856
|
let attempts2 = 0;
|
|
820
857
|
for (const delay3 of delays) {
|
|
858
|
+
const deadline = Math.min(retryDeadline ?? Infinity, leaseDeadline);
|
|
821
859
|
if (now() >= deadline)
|
|
822
860
|
break;
|
|
823
861
|
if (delay3)
|
|
824
862
|
await (options.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms))))(Math.min(delay3, Math.max(0, deadline - now())));
|
|
825
863
|
if (now() >= deadline)
|
|
826
864
|
break;
|
|
865
|
+
const fenceStart = now();
|
|
827
866
|
await options.beforeRename?.();
|
|
828
|
-
if (
|
|
867
|
+
if (retryDeadline !== void 0)
|
|
868
|
+
retryDeadline += now() - fenceStart;
|
|
869
|
+
if (now() >= leaseDeadline)
|
|
829
870
|
break;
|
|
830
871
|
attempts2++;
|
|
831
872
|
try {
|
|
@@ -837,6 +878,7 @@ async function replaceWindowsFile(from, to, options = {}) {
|
|
|
837
878
|
const candidate = detail.win32Code !== void 0 ? detail.win32Code === 32 || detail.win32Code === 33 : ["EBUSY", "EPERM", "EACCES"].includes(detail.code ?? "") && !detail.reason;
|
|
838
879
|
if (!candidate)
|
|
839
880
|
break;
|
|
881
|
+
retryDeadline ??= now() + 500;
|
|
840
882
|
}
|
|
841
883
|
}
|
|
842
884
|
const error = new PrivateFileError(to, "rename", original ?? Object.assign(new Error("Publication deadline expired"), {
|
|
@@ -8011,6 +8053,326 @@ var init_auth_menu = __esm({
|
|
|
8011
8053
|
}
|
|
8012
8054
|
});
|
|
8013
8055
|
|
|
8056
|
+
// ../core/dist/common-auth-embedded/claustrum/errors.js
|
|
8057
|
+
var ClaustrumConsumerError;
|
|
8058
|
+
var init_errors2 = __esm({
|
|
8059
|
+
"../core/dist/common-auth-embedded/claustrum/errors.js"() {
|
|
8060
|
+
"use strict";
|
|
8061
|
+
ClaustrumConsumerError = class extends Error {
|
|
8062
|
+
kind;
|
|
8063
|
+
constructor(kind, message) {
|
|
8064
|
+
super(message);
|
|
8065
|
+
this.name = "ClaustrumConsumerError";
|
|
8066
|
+
this.kind = kind;
|
|
8067
|
+
}
|
|
8068
|
+
};
|
|
8069
|
+
}
|
|
8070
|
+
});
|
|
8071
|
+
|
|
8072
|
+
// ../core/dist/common-auth-embedded/claustrum/availability.js
|
|
8073
|
+
import { ClaustrumCredentialError } from "@cortexkit/claustrum-client";
|
|
8074
|
+
import { SocketClosedError, SocketTimeoutError, SubcCallError } from "@cortexkit/subc-client";
|
|
8075
|
+
function classifyVaultFailure(error) {
|
|
8076
|
+
if (error instanceof ClaustrumUnreachableError || error instanceof SocketClosedError || error instanceof SocketTimeoutError)
|
|
8077
|
+
return "unreachable";
|
|
8078
|
+
const code2 = error instanceof ClaustrumCredentialError || error instanceof SubcCallError ? error.code : error instanceof Error && "code" in error ? error.code : void 0;
|
|
8079
|
+
if (typeof code2 !== "string" || !Object.hasOwn(VAULT_FAILURE_CLASSES, code2))
|
|
8080
|
+
return "answered";
|
|
8081
|
+
return VAULT_FAILURE_CLASSES[code2];
|
|
8082
|
+
}
|
|
8083
|
+
var VAULT_FAILURE_CLASSES, ClaustrumUnreachableError;
|
|
8084
|
+
var init_availability = __esm({
|
|
8085
|
+
"../core/dist/common-auth-embedded/claustrum/availability.js"() {
|
|
8086
|
+
"use strict";
|
|
8087
|
+
init_errors2();
|
|
8088
|
+
VAULT_FAILURE_CLASSES = Object.freeze({
|
|
8089
|
+
ECONNREFUSED: "unreachable",
|
|
8090
|
+
ENOENT: "unreachable",
|
|
8091
|
+
ECONNRESET: "unreachable",
|
|
8092
|
+
EPIPE: "unreachable",
|
|
8093
|
+
ETIMEDOUT: "unreachable",
|
|
8094
|
+
transport_error: "unreachable",
|
|
8095
|
+
unavailable: "unreachable",
|
|
8096
|
+
timeout: "unreachable",
|
|
8097
|
+
route_closed: "unreachable",
|
|
8098
|
+
daemon_draining: "unreachable",
|
|
8099
|
+
connection_closed: "unreachable",
|
|
8100
|
+
connection_dropped: "unreachable",
|
|
8101
|
+
request_deadline: "unreachable",
|
|
8102
|
+
deadline_exceeded_no_drop_observed: "unreachable",
|
|
8103
|
+
module_reloading: "unreachable",
|
|
8104
|
+
module_warming: "unreachable",
|
|
8105
|
+
target_unavailable: "unreachable",
|
|
8106
|
+
module_timeout: "unreachable",
|
|
8107
|
+
invalid_response: "answered",
|
|
8108
|
+
invalid_record_version: "answered",
|
|
8109
|
+
invalid_expiry: "answered",
|
|
8110
|
+
invalid_status: "answered",
|
|
8111
|
+
invalid_params: "answered",
|
|
8112
|
+
ttl_unsatisfiable: "answered",
|
|
8113
|
+
not_found: "answered",
|
|
8114
|
+
enrollment_revoked: "answered",
|
|
8115
|
+
enrollment_invalid: "answered",
|
|
8116
|
+
grant_denied: "answered",
|
|
8117
|
+
credential_unavailable: "answered",
|
|
8118
|
+
needs_reauth: "answered",
|
|
8119
|
+
declined: "answered",
|
|
8120
|
+
disabled: "answered",
|
|
8121
|
+
identity_changed: "answered",
|
|
8122
|
+
closed: "answered",
|
|
8123
|
+
client_closed: "answered",
|
|
8124
|
+
pending_exists: "answered",
|
|
8125
|
+
pending_queue_full: "answered",
|
|
8126
|
+
already_consumed: "answered",
|
|
8127
|
+
superseded: "answered",
|
|
8128
|
+
stale_generation: "answered",
|
|
8129
|
+
missing_identity: "answered",
|
|
8130
|
+
invalid_control_body: "answered",
|
|
8131
|
+
unknown_module: "answered",
|
|
8132
|
+
module_removed: "answered",
|
|
8133
|
+
capability_denied: "answered",
|
|
8134
|
+
unknown_channel: "unreachable",
|
|
8135
|
+
stale_route_epoch: "unreachable",
|
|
8136
|
+
capability_forbidden: "answered",
|
|
8137
|
+
capability_unprovided: "answered",
|
|
8138
|
+
capability_ambiguous: "answered",
|
|
8139
|
+
invalid_capability_identifier: "answered",
|
|
8140
|
+
binary_body_required: "answered",
|
|
8141
|
+
binary_call_requires_call_binary: "answered",
|
|
8142
|
+
corr_exhausted: "answered",
|
|
8143
|
+
late_route_cleanup_failed: "answered",
|
|
8144
|
+
reverse_request_capability_not_declared: "answered",
|
|
8145
|
+
stale_route_handle: "answered",
|
|
8146
|
+
reverse_request_unhandled: "answered",
|
|
8147
|
+
handler_error: "answered",
|
|
8148
|
+
health_error: "answered",
|
|
8149
|
+
duplicate_module_id: "answered",
|
|
8150
|
+
route_rejected: "answered",
|
|
8151
|
+
lock_busy: "answered",
|
|
8152
|
+
owner_invalid: "answered",
|
|
8153
|
+
renewal_failed: "answered",
|
|
8154
|
+
unsupported_platform: "answered",
|
|
8155
|
+
EACCES: "answered",
|
|
8156
|
+
EPERM: "answered",
|
|
8157
|
+
ERR_PRIVATE_FILES_SECURITY: "answered"
|
|
8158
|
+
});
|
|
8159
|
+
ClaustrumUnreachableError = class extends ClaustrumConsumerError {
|
|
8160
|
+
constructor() {
|
|
8161
|
+
super("unavailable", "Claustrum scoped operation unavailable");
|
|
8162
|
+
this.name = "ClaustrumUnreachableError";
|
|
8163
|
+
}
|
|
8164
|
+
};
|
|
8165
|
+
}
|
|
8166
|
+
});
|
|
8167
|
+
|
|
8168
|
+
// ../core/dist/common-auth-embedded/claustrum/watch.js
|
|
8169
|
+
var SAFETY_POLL_MS, WATCH_RETRY_MS, RESUBSCRIBE_BACKOFF_MS, ChangeNoticeReader, CoalescedRead, ScopedRosterWatch;
|
|
8170
|
+
var init_watch = __esm({
|
|
8171
|
+
"../core/dist/common-auth-embedded/claustrum/watch.js"() {
|
|
8172
|
+
"use strict";
|
|
8173
|
+
SAFETY_POLL_MS = 5 * 6e4;
|
|
8174
|
+
WATCH_RETRY_MS = 5 * 6e4;
|
|
8175
|
+
RESUBSCRIBE_BACKOFF_MS = 1e3;
|
|
8176
|
+
ChangeNoticeReader = class {
|
|
8177
|
+
#epoch;
|
|
8178
|
+
#seq = 0;
|
|
8179
|
+
/**
|
|
8180
|
+
* Begin a new watch, whose first notice is seq 1 again. The epoch is kept,
|
|
8181
|
+
* so a module restart between two watches still reads as a break.
|
|
8182
|
+
*/
|
|
8183
|
+
restart() {
|
|
8184
|
+
this.#seq = 0;
|
|
8185
|
+
}
|
|
8186
|
+
continuous(notice) {
|
|
8187
|
+
const continuous = notice.kind === "changed" && notice.seq === this.#seq + 1 && (this.#epoch === void 0 || notice.epoch === this.#epoch);
|
|
8188
|
+
this.#epoch = notice.epoch;
|
|
8189
|
+
this.#seq = notice.seq;
|
|
8190
|
+
return continuous;
|
|
8191
|
+
}
|
|
8192
|
+
};
|
|
8193
|
+
CoalescedRead = class {
|
|
8194
|
+
#read;
|
|
8195
|
+
#onError;
|
|
8196
|
+
#running;
|
|
8197
|
+
#queued = false;
|
|
8198
|
+
constructor(read, onError) {
|
|
8199
|
+
this.#read = read;
|
|
8200
|
+
this.#onError = onError;
|
|
8201
|
+
}
|
|
8202
|
+
/** The read in flight (including its queued follow-up), if any. */
|
|
8203
|
+
get running() {
|
|
8204
|
+
return this.#running;
|
|
8205
|
+
}
|
|
8206
|
+
request() {
|
|
8207
|
+
if (this.#running) {
|
|
8208
|
+
this.#queued = true;
|
|
8209
|
+
return this.#running;
|
|
8210
|
+
}
|
|
8211
|
+
this.#running = (async () => {
|
|
8212
|
+
do {
|
|
8213
|
+
this.#queued = false;
|
|
8214
|
+
try {
|
|
8215
|
+
await this.#read();
|
|
8216
|
+
} catch (error) {
|
|
8217
|
+
this.#onError(error);
|
|
8218
|
+
}
|
|
8219
|
+
} while (this.#queued);
|
|
8220
|
+
})().finally(() => {
|
|
8221
|
+
this.#running = void 0;
|
|
8222
|
+
});
|
|
8223
|
+
return this.#running;
|
|
8224
|
+
}
|
|
8225
|
+
};
|
|
8226
|
+
ScopedRosterWatch = class {
|
|
8227
|
+
#options;
|
|
8228
|
+
#reader = new ChangeNoticeReader();
|
|
8229
|
+
#reads;
|
|
8230
|
+
#mode = "polling";
|
|
8231
|
+
#watch;
|
|
8232
|
+
#timer;
|
|
8233
|
+
#stopped = false;
|
|
8234
|
+
#latestView;
|
|
8235
|
+
#force = false;
|
|
8236
|
+
/**
|
|
8237
|
+
* How many accepted watches in a row have closed; each one doubles the wait
|
|
8238
|
+
* before the next re-subscribe. Reset once a watch stays up five minutes.
|
|
8239
|
+
*/
|
|
8240
|
+
#closes = 0;
|
|
8241
|
+
constructor(options) {
|
|
8242
|
+
this.#options = options;
|
|
8243
|
+
this.#reads = new CoalescedRead(async () => {
|
|
8244
|
+
const force = this.#force;
|
|
8245
|
+
this.#force = false;
|
|
8246
|
+
if (force || this.#latestView !== this.#options.view())
|
|
8247
|
+
await this.#options.discover(this.#latestView ?? "");
|
|
8248
|
+
}, (error) => {
|
|
8249
|
+
if (!this.#stopped)
|
|
8250
|
+
this.#options.onError?.(error);
|
|
8251
|
+
});
|
|
8252
|
+
}
|
|
8253
|
+
get mode() {
|
|
8254
|
+
return this.#mode;
|
|
8255
|
+
}
|
|
8256
|
+
start() {
|
|
8257
|
+
if (this.#stopped || this.#watch || this.#timer)
|
|
8258
|
+
return;
|
|
8259
|
+
if (typeof this.#options.client.watchScoped !== "function") {
|
|
8260
|
+
this.#setMode("fallback", "client-without-watch");
|
|
8261
|
+
return;
|
|
8262
|
+
}
|
|
8263
|
+
void this.#open(false);
|
|
8264
|
+
}
|
|
8265
|
+
stop() {
|
|
8266
|
+
if (this.#stopped)
|
|
8267
|
+
return;
|
|
8268
|
+
this.#stopped = true;
|
|
8269
|
+
if (this.#timer)
|
|
8270
|
+
(this.#options.clearTimeoutImpl ?? clearTimeout)(this.#timer);
|
|
8271
|
+
this.#timer = void 0;
|
|
8272
|
+
const watch = this.#watch;
|
|
8273
|
+
this.#watch = void 0;
|
|
8274
|
+
watch?.handle.stop();
|
|
8275
|
+
}
|
|
8276
|
+
#setMode(mode, reason) {
|
|
8277
|
+
if (this.#mode === mode)
|
|
8278
|
+
return;
|
|
8279
|
+
this.#mode = mode;
|
|
8280
|
+
this.#options.logger?.debug("claustrum vault watch", { mode, reason });
|
|
8281
|
+
this.#options.onMode?.(mode);
|
|
8282
|
+
}
|
|
8283
|
+
#later(delay3, run) {
|
|
8284
|
+
this.#timer = (this.#options.setTimeoutImpl ?? setTimeout)(() => {
|
|
8285
|
+
this.#timer = void 0;
|
|
8286
|
+
if (!this.#stopped)
|
|
8287
|
+
run();
|
|
8288
|
+
}, delay3);
|
|
8289
|
+
this.#timer.unref?.();
|
|
8290
|
+
}
|
|
8291
|
+
async #open(resubscribed) {
|
|
8292
|
+
let token;
|
|
8293
|
+
try {
|
|
8294
|
+
token = await this.#options.enrollmentToken();
|
|
8295
|
+
} catch (error) {
|
|
8296
|
+
if (this.#stopped)
|
|
8297
|
+
return;
|
|
8298
|
+
this.#options.onError?.(error);
|
|
8299
|
+
this.#fallback("token-unreadable");
|
|
8300
|
+
return;
|
|
8301
|
+
}
|
|
8302
|
+
const watchScoped = this.#options.client.watchScoped;
|
|
8303
|
+
if (this.#stopped || this.#watch || !watchScoped)
|
|
8304
|
+
return;
|
|
8305
|
+
this.#reader.restart();
|
|
8306
|
+
this.#force = resubscribed;
|
|
8307
|
+
let watch;
|
|
8308
|
+
let handle;
|
|
8309
|
+
try {
|
|
8310
|
+
handle = watchScoped.call(this.#options.client, (notice) => {
|
|
8311
|
+
if (this.#stopped || !watch || this.#watch !== watch)
|
|
8312
|
+
return;
|
|
8313
|
+
watch.notices++;
|
|
8314
|
+
if (watch.notices === 1) {
|
|
8315
|
+
this.#options.onReachable?.();
|
|
8316
|
+
watch.acceptedAt = (this.#options.now ?? Date.now)();
|
|
8317
|
+
this.#setMode("watching", "accepted");
|
|
8318
|
+
}
|
|
8319
|
+
if (!this.#reader.continuous(notice))
|
|
8320
|
+
this.#force = true;
|
|
8321
|
+
this.#latestView = notice.view;
|
|
8322
|
+
void this.#reads.request();
|
|
8323
|
+
}, { enrollmentToken: token });
|
|
8324
|
+
} catch (error) {
|
|
8325
|
+
this.#options.onError?.(error);
|
|
8326
|
+
this.#fallback("watch-failed");
|
|
8327
|
+
return;
|
|
8328
|
+
}
|
|
8329
|
+
watch = { handle, notices: 0 };
|
|
8330
|
+
this.#watch = watch;
|
|
8331
|
+
this.#setMode("polling", resubscribed ? "resubscribing" : "opening");
|
|
8332
|
+
const opened = watch;
|
|
8333
|
+
handle.closed.then((end) => this.#closed(opened, end), (error) => this.#closed(opened, { kind: "transport_lost", error }));
|
|
8334
|
+
}
|
|
8335
|
+
#closed(watch, end) {
|
|
8336
|
+
if (this.#stopped || this.#watch !== watch)
|
|
8337
|
+
return;
|
|
8338
|
+
this.#watch = void 0;
|
|
8339
|
+
if (end.kind === "stopped")
|
|
8340
|
+
return;
|
|
8341
|
+
if (end.kind === "transport_lost")
|
|
8342
|
+
this.#options.onTransportLost?.();
|
|
8343
|
+
if (end.kind === "unsupported") {
|
|
8344
|
+
this.#setMode("fallback", "vault-without-watch");
|
|
8345
|
+
return;
|
|
8346
|
+
}
|
|
8347
|
+
if (end.kind === "refused") {
|
|
8348
|
+
this.#fallback("refused");
|
|
8349
|
+
try {
|
|
8350
|
+
this.#options.onRefused(end.error);
|
|
8351
|
+
} catch (error) {
|
|
8352
|
+
this.#options.onError?.(error);
|
|
8353
|
+
}
|
|
8354
|
+
return;
|
|
8355
|
+
}
|
|
8356
|
+
if (watch.notices > 0) {
|
|
8357
|
+
const now = (this.#options.now ?? Date.now)();
|
|
8358
|
+
if (watch.acceptedAt !== void 0 && now - watch.acceptedAt >= SAFETY_POLL_MS)
|
|
8359
|
+
this.#closes = 0;
|
|
8360
|
+
const delay3 = Math.min(RESUBSCRIBE_BACKOFF_MS * 2 ** Math.min(this.#closes, 16), WATCH_RETRY_MS);
|
|
8361
|
+
this.#closes++;
|
|
8362
|
+
this.#setMode("polling", "resubscribing");
|
|
8363
|
+
this.#later(delay3, () => void this.#open(true));
|
|
8364
|
+
return;
|
|
8365
|
+
}
|
|
8366
|
+
this.#fallback(end.kind);
|
|
8367
|
+
}
|
|
8368
|
+
#fallback(reason) {
|
|
8369
|
+
this.#setMode("fallback", reason);
|
|
8370
|
+
this.#later(WATCH_RETRY_MS, () => void this.#open(false));
|
|
8371
|
+
}
|
|
8372
|
+
};
|
|
8373
|
+
}
|
|
8374
|
+
});
|
|
8375
|
+
|
|
8014
8376
|
// ../core/dist/common-auth-embedded/claustrum/insula.js
|
|
8015
8377
|
import { resolve as resolve4 } from "node:path";
|
|
8016
8378
|
import { storeIdentity } from "@cortexkit/claustrum-client";
|
|
@@ -8049,12 +8411,95 @@ function insulaUsageTransport(options) {
|
|
|
8049
8411
|
clearTimeout(timer);
|
|
8050
8412
|
client?.close();
|
|
8051
8413
|
}
|
|
8414
|
+
},
|
|
8415
|
+
watchUsage(onNotice) {
|
|
8416
|
+
let client;
|
|
8417
|
+
let subscription;
|
|
8418
|
+
let stopped = false;
|
|
8419
|
+
const closed = (async () => {
|
|
8420
|
+
let deadline;
|
|
8421
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
8422
|
+
deadline = setTimeout(
|
|
8423
|
+
// Coded as a timeout, so InsulaQuotaSource treats a watch that could
|
|
8424
|
+
// not open in time as an unreachable insula and tries again later,
|
|
8425
|
+
// not as a refusal.
|
|
8426
|
+
() => reject(Object.assign(new Error("insula watch timeout"), {
|
|
8427
|
+
code: "timeout"
|
|
8428
|
+
})),
|
|
8429
|
+
3e3
|
|
8430
|
+
);
|
|
8431
|
+
deadline.unref?.();
|
|
8432
|
+
});
|
|
8433
|
+
const open13 = (async () => {
|
|
8434
|
+
const handshakeTimeoutMs = Math.min(options.handshakeTimeoutMs ?? 3e3, 3e3);
|
|
8435
|
+
const connected = options.connector ? await options.connector({
|
|
8436
|
+
connectionFile: options.connectionFile,
|
|
8437
|
+
handshakeTimeoutMs
|
|
8438
|
+
}) : await SubcClient.connect({
|
|
8439
|
+
connectionFile: options.connectionFile,
|
|
8440
|
+
handshakeTimeoutMs
|
|
8441
|
+
});
|
|
8442
|
+
client = connected;
|
|
8443
|
+
if (stopped) {
|
|
8444
|
+
connected.close();
|
|
8445
|
+
return;
|
|
8446
|
+
}
|
|
8447
|
+
const route = await connected.routeOpen({ kind: "management_surface", module_id: "insula" }, identity);
|
|
8448
|
+
if (stopped) {
|
|
8449
|
+
connected.close();
|
|
8450
|
+
return;
|
|
8451
|
+
}
|
|
8452
|
+
subscription = connected.subscribe(route, { method: "usage.watch" }, onNotice);
|
|
8453
|
+
})();
|
|
8454
|
+
try {
|
|
8455
|
+
await Promise.race([open13, timeout]);
|
|
8456
|
+
} catch (error) {
|
|
8457
|
+
stopped = true;
|
|
8458
|
+
throw error;
|
|
8459
|
+
} finally {
|
|
8460
|
+
clearTimeout(deadline);
|
|
8461
|
+
}
|
|
8462
|
+
if (subscription)
|
|
8463
|
+
await subscription.closed;
|
|
8464
|
+
})().finally(() => {
|
|
8465
|
+
stopped = true;
|
|
8466
|
+
client?.close();
|
|
8467
|
+
});
|
|
8468
|
+
return {
|
|
8469
|
+
stop() {
|
|
8470
|
+
if (stopped)
|
|
8471
|
+
return;
|
|
8472
|
+
stopped = true;
|
|
8473
|
+
subscription?.unsubscribe();
|
|
8474
|
+
client?.close();
|
|
8475
|
+
},
|
|
8476
|
+
closed
|
|
8477
|
+
};
|
|
8052
8478
|
}
|
|
8053
8479
|
};
|
|
8054
8480
|
}
|
|
8055
8481
|
function record2(value) {
|
|
8056
8482
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8057
8483
|
}
|
|
8484
|
+
function decodeUsageNotice(body) {
|
|
8485
|
+
let value;
|
|
8486
|
+
try {
|
|
8487
|
+
value = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(body));
|
|
8488
|
+
} catch {
|
|
8489
|
+
return void 0;
|
|
8490
|
+
}
|
|
8491
|
+
if (!record2(value) || typeof value.kind !== "string" || typeof value.epoch !== "string" || value.epoch.length === 0 || typeof value.seq !== "number" || !Number.isSafeInteger(value.seq) || value.seq < 1 || value.provider !== void 0 && typeof value.provider !== "string")
|
|
8492
|
+
return void 0;
|
|
8493
|
+
return {
|
|
8494
|
+
kind: value.kind,
|
|
8495
|
+
epoch: value.epoch,
|
|
8496
|
+
seq: value.seq,
|
|
8497
|
+
...typeof value.provider === "string" && { provider: value.provider }
|
|
8498
|
+
};
|
|
8499
|
+
}
|
|
8500
|
+
function refusalCode(error) {
|
|
8501
|
+
return error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
8502
|
+
}
|
|
8058
8503
|
function acquireInsulaQuotaSource(transport, tokenPath) {
|
|
8059
8504
|
const key = JSON.stringify([
|
|
8060
8505
|
resolve4(transport.connectionFile),
|
|
@@ -8082,6 +8527,8 @@ var MINUTE, MAX_AGE, sources, attempts, InsulaQuotaSource;
|
|
|
8082
8527
|
var init_insula = __esm({
|
|
8083
8528
|
"../core/dist/common-auth-embedded/claustrum/insula.js"() {
|
|
8084
8529
|
"use strict";
|
|
8530
|
+
init_availability();
|
|
8531
|
+
init_watch();
|
|
8085
8532
|
MINUTE = 6e4;
|
|
8086
8533
|
MAX_AGE = 4 * MINUTE;
|
|
8087
8534
|
sources = /* @__PURE__ */ new Map();
|
|
@@ -8090,14 +8537,52 @@ var init_insula = __esm({
|
|
|
8090
8537
|
transport;
|
|
8091
8538
|
key;
|
|
8092
8539
|
#entries = [];
|
|
8093
|
-
|
|
8540
|
+
/** Every usage.get, polled or watch-driven, shares this one slot. */
|
|
8541
|
+
#reads = new CoalescedRead(async () => {
|
|
8542
|
+
try {
|
|
8543
|
+
const reply = await this.transport.getUsage();
|
|
8544
|
+
if (!record2(reply) || !Array.isArray(reply.result) || reply.error !== void 0)
|
|
8545
|
+
throw new Error("unavailable insula usage");
|
|
8546
|
+
this.#entries = reply.result.filter((entry) => record2(entry) && typeof entry.provider === "string");
|
|
8547
|
+
} catch {
|
|
8548
|
+
this.#entries = [];
|
|
8549
|
+
}
|
|
8550
|
+
}, () => {
|
|
8551
|
+
});
|
|
8552
|
+
#reader = new ChangeNoticeReader();
|
|
8553
|
+
#mode = "polling";
|
|
8554
|
+
#watchers = 0;
|
|
8555
|
+
/**
|
|
8556
|
+
* How many registered watchers read every provider. Watchers limited to one
|
|
8557
|
+
* provider are counted per provider in `#providers` instead.
|
|
8558
|
+
*/
|
|
8559
|
+
#everyProvider = 0;
|
|
8560
|
+
#providers = /* @__PURE__ */ new Map();
|
|
8561
|
+
#watch;
|
|
8562
|
+
#timer;
|
|
8563
|
+
#timers = {};
|
|
8564
|
+
/**
|
|
8565
|
+
* How many accepted watches in a row have closed; each one doubles the wait
|
|
8566
|
+
* before the next re-subscribe. Reset once a watch brings a second notice.
|
|
8567
|
+
*/
|
|
8568
|
+
#closes = 0;
|
|
8094
8569
|
constructor(transport, key) {
|
|
8095
8570
|
this.transport = transport;
|
|
8096
8571
|
this.key = key;
|
|
8097
8572
|
}
|
|
8573
|
+
/**
|
|
8574
|
+
* The background poll: at most one usage.get per minute per daemon and
|
|
8575
|
+
* enrollment token. While a watch is open it reads nothing, because insula's
|
|
8576
|
+
* notices announce every new reading. If insula stops announcing an account,
|
|
8577
|
+
* that account's last entry grows older than the freshness limit `current()`
|
|
8578
|
+
* applies, `current()` returns nothing for it, and the plugin falls back to
|
|
8579
|
+
* its own provider poll for that account.
|
|
8580
|
+
*/
|
|
8098
8581
|
refresh(now) {
|
|
8099
|
-
if (this.#
|
|
8100
|
-
return this.#
|
|
8582
|
+
if (this.#reads.running)
|
|
8583
|
+
return this.#reads.running;
|
|
8584
|
+
if (this.#mode === "watching")
|
|
8585
|
+
return Promise.resolve();
|
|
8101
8586
|
for (const [key, time] of attempts) {
|
|
8102
8587
|
if (now - time >= MINUTE)
|
|
8103
8588
|
attempts.delete(key);
|
|
@@ -8106,19 +8591,119 @@ var init_insula = __esm({
|
|
|
8106
8591
|
if (lastAttempt !== void 0 && now - lastAttempt < MINUTE)
|
|
8107
8592
|
return Promise.resolve();
|
|
8108
8593
|
attempts.set(this.key, now);
|
|
8109
|
-
this.#
|
|
8110
|
-
|
|
8111
|
-
|
|
8112
|
-
|
|
8113
|
-
|
|
8114
|
-
|
|
8115
|
-
|
|
8116
|
-
|
|
8594
|
+
return this.#reads.request();
|
|
8595
|
+
}
|
|
8596
|
+
/** How this source currently learns about usage changes, for logs. */
|
|
8597
|
+
watchMode() {
|
|
8598
|
+
return this.#mode;
|
|
8599
|
+
}
|
|
8600
|
+
/**
|
|
8601
|
+
* Hold a `usage.watch` open while any watcher wants it, and re-read
|
|
8602
|
+
* usage.get when a notice says something changed. Watchers of one source
|
|
8603
|
+
* share one watch, since insula admits only 64 per process. Returns the
|
|
8604
|
+
* release; the last release closes the watch.
|
|
8605
|
+
*/
|
|
8606
|
+
watch(options = {}) {
|
|
8607
|
+
this.#watchers++;
|
|
8608
|
+
const provider2 = options.provider;
|
|
8609
|
+
if (provider2 === void 0)
|
|
8610
|
+
this.#everyProvider++;
|
|
8611
|
+
else
|
|
8612
|
+
this.#providers.set(provider2, (this.#providers.get(provider2) ?? 0) + 1);
|
|
8613
|
+
if (this.#watchers === 1) {
|
|
8614
|
+
this.#timers = options;
|
|
8615
|
+
this.#open();
|
|
8616
|
+
}
|
|
8617
|
+
let released = false;
|
|
8618
|
+
return () => {
|
|
8619
|
+
if (released)
|
|
8620
|
+
return;
|
|
8621
|
+
released = true;
|
|
8622
|
+
if (provider2 === void 0)
|
|
8623
|
+
this.#everyProvider--;
|
|
8624
|
+
else {
|
|
8625
|
+
const left = (this.#providers.get(provider2) ?? 1) - 1;
|
|
8626
|
+
if (left > 0)
|
|
8627
|
+
this.#providers.set(provider2, left);
|
|
8628
|
+
else
|
|
8629
|
+
this.#providers.delete(provider2);
|
|
8117
8630
|
}
|
|
8118
|
-
|
|
8119
|
-
|
|
8120
|
-
}
|
|
8121
|
-
|
|
8631
|
+
if (--this.#watchers === 0)
|
|
8632
|
+
this.#stopWatch();
|
|
8633
|
+
};
|
|
8634
|
+
}
|
|
8635
|
+
#stopWatch() {
|
|
8636
|
+
if (this.#timer)
|
|
8637
|
+
(this.#timers.clearTimeoutImpl ?? clearTimeout)(this.#timer);
|
|
8638
|
+
this.#timer = void 0;
|
|
8639
|
+
const watch = this.#watch;
|
|
8640
|
+
this.#watch = void 0;
|
|
8641
|
+
watch?.handle?.stop();
|
|
8642
|
+
this.#mode = "polling";
|
|
8643
|
+
}
|
|
8644
|
+
#later(delay3) {
|
|
8645
|
+
this.#timer = (this.#timers.setTimeoutImpl ?? setTimeout)(() => {
|
|
8646
|
+
this.#timer = void 0;
|
|
8647
|
+
if (this.#watchers > 0 && !this.#watch)
|
|
8648
|
+
this.#open();
|
|
8649
|
+
}, delay3);
|
|
8650
|
+
this.#timer.unref?.();
|
|
8651
|
+
}
|
|
8652
|
+
#open() {
|
|
8653
|
+
const watchUsage = this.transport.watchUsage;
|
|
8654
|
+
if (!watchUsage) {
|
|
8655
|
+
this.#mode = "fallback";
|
|
8656
|
+
return;
|
|
8657
|
+
}
|
|
8658
|
+
this.#mode = "polling";
|
|
8659
|
+
this.#reader.restart();
|
|
8660
|
+
const watch = { notices: 0 };
|
|
8661
|
+
this.#watch = watch;
|
|
8662
|
+
let handle;
|
|
8663
|
+
try {
|
|
8664
|
+
handle = watchUsage.call(this.transport, (body) => this.#notice(watch, body));
|
|
8665
|
+
} catch (error) {
|
|
8666
|
+
this.#closed(watch, error);
|
|
8667
|
+
return;
|
|
8668
|
+
}
|
|
8669
|
+
watch.handle = handle;
|
|
8670
|
+
handle.closed.then(() => this.#closed(watch, void 0), (error) => this.#closed(watch, error));
|
|
8671
|
+
}
|
|
8672
|
+
#notice(watch, body) {
|
|
8673
|
+
if (this.#watch !== watch)
|
|
8674
|
+
return;
|
|
8675
|
+
watch.notices++;
|
|
8676
|
+
if (watch.notices === 1)
|
|
8677
|
+
this.#mode = "watching";
|
|
8678
|
+
if (watch.notices === 2)
|
|
8679
|
+
this.#closes = 0;
|
|
8680
|
+
const notice = decodeUsageNotice(body);
|
|
8681
|
+
if (!notice)
|
|
8682
|
+
this.#reader.restart();
|
|
8683
|
+
const continuous = notice ? this.#reader.continuous(notice) : false;
|
|
8684
|
+
if (!continuous || notice?.provider === void 0 || this.#everyProvider > 0 || this.#providers.has(notice.provider))
|
|
8685
|
+
void this.#reads.request();
|
|
8686
|
+
}
|
|
8687
|
+
#closed(watch, error) {
|
|
8688
|
+
if (this.#watch !== watch)
|
|
8689
|
+
return;
|
|
8690
|
+
this.#watch = void 0;
|
|
8691
|
+
const code2 = refusalCode(error);
|
|
8692
|
+
if (code2 === "unknown_method" || code2 === "usage_watch_limit") {
|
|
8693
|
+
this.#mode = "fallback";
|
|
8694
|
+
return;
|
|
8695
|
+
}
|
|
8696
|
+
if (watch.notices > 0) {
|
|
8697
|
+
const delay3 = Math.min(RESUBSCRIBE_BACKOFF_MS * 2 ** Math.min(this.#closes, 16), WATCH_RETRY_MS);
|
|
8698
|
+
this.#closes++;
|
|
8699
|
+
this.#mode = "polling";
|
|
8700
|
+
this.#later(delay3);
|
|
8701
|
+
return;
|
|
8702
|
+
}
|
|
8703
|
+
this.#mode = "fallback";
|
|
8704
|
+
void this.#reads.request();
|
|
8705
|
+
if (error === void 0 || classifyVaultFailure(error) === "unreachable")
|
|
8706
|
+
this.#later(WATCH_RETRY_MS);
|
|
8122
8707
|
}
|
|
8123
8708
|
current(provider2, accountId, now) {
|
|
8124
8709
|
for (const entry of this.#entries) {
|
|
@@ -8185,30 +8770,14 @@ var init_any_signal = __esm({
|
|
|
8185
8770
|
}
|
|
8186
8771
|
});
|
|
8187
8772
|
|
|
8188
|
-
// ../core/dist/common-auth-embedded/claustrum/errors.js
|
|
8189
|
-
var ClaustrumConsumerError;
|
|
8190
|
-
var init_errors2 = __esm({
|
|
8191
|
-
"../core/dist/common-auth-embedded/claustrum/errors.js"() {
|
|
8192
|
-
"use strict";
|
|
8193
|
-
ClaustrumConsumerError = class extends Error {
|
|
8194
|
-
kind;
|
|
8195
|
-
constructor(kind, message) {
|
|
8196
|
-
super(message);
|
|
8197
|
-
this.name = "ClaustrumConsumerError";
|
|
8198
|
-
this.kind = kind;
|
|
8199
|
-
}
|
|
8200
|
-
};
|
|
8201
|
-
}
|
|
8202
|
-
});
|
|
8203
|
-
|
|
8204
8773
|
// ../core/dist/common-auth-embedded/claustrum/enrollment.js
|
|
8205
8774
|
import { createHash as createHash6, randomBytes as randomBytes4, randomUUID as randomUUID12 } from "node:crypto";
|
|
8206
8775
|
import { constants as fsConstants } from "node:fs";
|
|
8207
8776
|
import { chmod as chmod2, mkdir as mkdir8, open as open6, readFile as readFile6, realpath as realpath3, rename as rename6, stat as stat4, unlink as unlink6 } from "node:fs/promises";
|
|
8208
8777
|
import { basename as basename3, dirname as dirname9, extname, isAbsolute as isAbsolute2, join as join5, resolve as resolve5 } from "node:path";
|
|
8209
|
-
import { ClaustrumCredentialError, ClaustrumClient as ClaustrumWireClient, writeEnrollmentTokenFile } from "@cortexkit/claustrum-client";
|
|
8778
|
+
import { ClaustrumCredentialError as ClaustrumCredentialError2, ClaustrumClient as ClaustrumWireClient, writeEnrollmentTokenFile } from "@cortexkit/claustrum-client";
|
|
8210
8779
|
function classifyEnrollmentError(error) {
|
|
8211
|
-
if (!(error instanceof
|
|
8780
|
+
if (!(error instanceof ClaustrumCredentialError2))
|
|
8212
8781
|
return void 0;
|
|
8213
8782
|
if (TERMINAL_ENROLLMENT_CODES.has(error.code))
|
|
8214
8783
|
return { code: error.code, disposition: "terminal" };
|
|
@@ -8909,9 +9478,9 @@ var init_host_slot = __esm({
|
|
|
8909
9478
|
});
|
|
8910
9479
|
|
|
8911
9480
|
// ../core/dist/common-auth-embedded/claustrum/custody.js
|
|
8912
|
-
import { ClaustrumCredentialError as
|
|
9481
|
+
import { ClaustrumCredentialError as ClaustrumCredentialError3 } from "@cortexkit/claustrum-client";
|
|
8913
9482
|
function isScopedCredentialRotation(served, current) {
|
|
8914
|
-
return current !== void 0 && current.credentialId === served.credentialId && current.accountIdentity === served.accountIdentity && current.recordVersion !== served.recordVersion;
|
|
9483
|
+
return current !== void 0 && !current.fromKeptReceipt && !served.fromKeptReceipt && current.credentialId === served.credentialId && current.accountIdentity === served.accountIdentity && current.recordVersion !== served.recordVersion;
|
|
8915
9484
|
}
|
|
8916
9485
|
function scopedRetryReason(served, current) {
|
|
8917
9486
|
if (current === void 0)
|
|
@@ -8979,16 +9548,19 @@ function grantReachOf(listed) {
|
|
|
8979
9548
|
tuples: Object.freeze(grantTuples.map(({ selectorKind, selector, operation }) => Object.freeze({ selectorKind, selector, operation })))
|
|
8980
9549
|
});
|
|
8981
9550
|
}
|
|
8982
|
-
var defaultLogger, SERVING_MARGIN_MS, ClaustrumScopedCustody;
|
|
9551
|
+
var defaultLogger, SERVING_MARGIN_MS, KEPT_RECEIPT_MARGIN_MS, ClaustrumScopedCustody;
|
|
8983
9552
|
var init_custody = __esm({
|
|
8984
9553
|
"../core/dist/common-auth-embedded/claustrum/custody.js"() {
|
|
8985
9554
|
"use strict";
|
|
8986
9555
|
init_logger();
|
|
9556
|
+
init_availability();
|
|
8987
9557
|
init_enrollment();
|
|
8988
9558
|
init_errors2();
|
|
8989
9559
|
init_host_slot();
|
|
9560
|
+
init_watch();
|
|
8990
9561
|
defaultLogger = createLogger2("claustrum");
|
|
8991
9562
|
SERVING_MARGIN_MS = 3e5;
|
|
9563
|
+
KEPT_RECEIPT_MARGIN_MS = 6e4;
|
|
8992
9564
|
ClaustrumScopedCustody = class {
|
|
8993
9565
|
#client;
|
|
8994
9566
|
#readToken;
|
|
@@ -8999,7 +9571,20 @@ var init_custody = __esm({
|
|
|
8999
9571
|
#logger;
|
|
9000
9572
|
#provenance = /* @__PURE__ */ new WeakMap();
|
|
9001
9573
|
#reports = /* @__PURE__ */ new WeakMap();
|
|
9574
|
+
#kept = /* @__PURE__ */ new Map();
|
|
9575
|
+
#keptAttempts = /* @__PURE__ */ new WeakMap();
|
|
9576
|
+
#setTimeout;
|
|
9577
|
+
#clearTimeout;
|
|
9578
|
+
#outage = false;
|
|
9579
|
+
#outageError = new ClaustrumUnreachableError();
|
|
9580
|
+
#probeTimer;
|
|
9581
|
+
#probing = false;
|
|
9582
|
+
#lastProbeAt = -Infinity;
|
|
9583
|
+
#probeDelay = 2e3;
|
|
9002
9584
|
#closed = false;
|
|
9585
|
+
/** The view of the last successful `discover()`, for `watchRoster`. */
|
|
9586
|
+
#discoveredView;
|
|
9587
|
+
#watches = /* @__PURE__ */ new Set();
|
|
9003
9588
|
constructor(options) {
|
|
9004
9589
|
const tokenPath = options.tokenPath;
|
|
9005
9590
|
if (options.readToken) {
|
|
@@ -9015,6 +9600,56 @@ var init_custody = __esm({
|
|
|
9015
9600
|
this.#requireAssertion = options.requireAssertion ?? false;
|
|
9016
9601
|
this.#now = options.now ?? Date.now;
|
|
9017
9602
|
this.#logger = options.logger ?? defaultLogger;
|
|
9603
|
+
this.#setTimeout = options.setTimeoutImpl ?? setTimeout;
|
|
9604
|
+
this.#clearTimeout = options.clearTimeoutImpl ?? clearTimeout;
|
|
9605
|
+
}
|
|
9606
|
+
/** A watch losing its transport is the same outage as an unreachable read. */
|
|
9607
|
+
transportLost(error) {
|
|
9608
|
+
if (this.#closed || this.#outage)
|
|
9609
|
+
return;
|
|
9610
|
+
this.#outage = true;
|
|
9611
|
+
this.#outageError = error instanceof ClaustrumCredentialError3 ? error : new ClaustrumUnreachableError();
|
|
9612
|
+
this.#logger.warn("serving kept vault receipt", { reason: "unreachable" });
|
|
9613
|
+
this.#scheduleProbe();
|
|
9614
|
+
}
|
|
9615
|
+
/** Any vault answer ends transport fallback, even when it refuses access. */
|
|
9616
|
+
reachable() {
|
|
9617
|
+
if (this.#closed || !this.#outage)
|
|
9618
|
+
return;
|
|
9619
|
+
this.#outage = false;
|
|
9620
|
+
if (this.#probeTimer)
|
|
9621
|
+
this.#clearTimeout(this.#probeTimer);
|
|
9622
|
+
this.#probeTimer = void 0;
|
|
9623
|
+
this.#probeDelay = 2e3;
|
|
9624
|
+
for (const kept of this.#kept.values())
|
|
9625
|
+
kept.since = null;
|
|
9626
|
+
(this.#logger.info ?? defaultLogger.info)("vault receipt serving resumed", { reason: "reachable" });
|
|
9627
|
+
}
|
|
9628
|
+
#scheduleProbe() {
|
|
9629
|
+
if (this.#closed || !this.#outage || this.#probeTimer || this.#probing)
|
|
9630
|
+
return;
|
|
9631
|
+
this.#probeTimer = this.#setTimeout(() => {
|
|
9632
|
+
this.#probeTimer = void 0;
|
|
9633
|
+
this.#probe(true);
|
|
9634
|
+
}, this.#probeDelay);
|
|
9635
|
+
this.#probeTimer.unref?.();
|
|
9636
|
+
}
|
|
9637
|
+
#probe(idle = false) {
|
|
9638
|
+
if (this.#closed || !this.#outage || this.#probing)
|
|
9639
|
+
return;
|
|
9640
|
+
if (this.#now() - this.#lastProbeAt < 1e3) {
|
|
9641
|
+
this.#scheduleProbe();
|
|
9642
|
+
return;
|
|
9643
|
+
}
|
|
9644
|
+
this.#lastProbeAt = this.#now();
|
|
9645
|
+
this.#probing = true;
|
|
9646
|
+
void this.#list().catch(() => {
|
|
9647
|
+
if (idle && this.#outage)
|
|
9648
|
+
this.#probeDelay = Math.min(this.#probeDelay * 2, 3e4);
|
|
9649
|
+
}).finally(() => {
|
|
9650
|
+
this.#probing = false;
|
|
9651
|
+
this.#scheduleProbe();
|
|
9652
|
+
});
|
|
9018
9653
|
}
|
|
9019
9654
|
#check(signal) {
|
|
9020
9655
|
if (this.#closed)
|
|
@@ -9048,13 +9683,20 @@ var init_custody = __esm({
|
|
|
9048
9683
|
]) : await pending;
|
|
9049
9684
|
} catch (error) {
|
|
9050
9685
|
this.#check(signal);
|
|
9051
|
-
if (error
|
|
9686
|
+
if (classifyVaultFailure(error) === "unreachable")
|
|
9687
|
+
this.transportLost(error);
|
|
9688
|
+
else
|
|
9689
|
+
this.reachable();
|
|
9690
|
+
if (error instanceof ClaustrumCredentialError3)
|
|
9052
9691
|
throw error;
|
|
9692
|
+
if (classifyVaultFailure(error) === "unreachable")
|
|
9693
|
+
throw new ClaustrumUnreachableError();
|
|
9053
9694
|
throw new ClaustrumConsumerError("unavailable", "Claustrum scoped operation unavailable");
|
|
9054
9695
|
} finally {
|
|
9055
9696
|
removeAbortListener?.();
|
|
9056
9697
|
}
|
|
9057
9698
|
this.#check(signal);
|
|
9699
|
+
this.reachable();
|
|
9058
9700
|
return result;
|
|
9059
9701
|
}
|
|
9060
9702
|
/**
|
|
@@ -9064,8 +9706,25 @@ var init_custody = __esm({
|
|
|
9064
9706
|
* skipped records: they simply are not this consumer's.
|
|
9065
9707
|
*/
|
|
9066
9708
|
async discover(signal) {
|
|
9067
|
-
const
|
|
9068
|
-
|
|
9709
|
+
const inventory = await this.#list(signal);
|
|
9710
|
+
this.#discoveredView = inventory.view;
|
|
9711
|
+
return inventory;
|
|
9712
|
+
}
|
|
9713
|
+
async #list(signal) {
|
|
9714
|
+
let inventory;
|
|
9715
|
+
let token;
|
|
9716
|
+
try {
|
|
9717
|
+
token = await this.#token(signal);
|
|
9718
|
+
} catch (error) {
|
|
9719
|
+
this.#kept.clear();
|
|
9720
|
+
throw error;
|
|
9721
|
+
}
|
|
9722
|
+
try {
|
|
9723
|
+
inventory = await this.#call(() => this.#client.listScoped(token), signal);
|
|
9724
|
+
} catch (error) {
|
|
9725
|
+
this.listFailed(error);
|
|
9726
|
+
throw error;
|
|
9727
|
+
}
|
|
9069
9728
|
const skipped = [];
|
|
9070
9729
|
const candidates = [];
|
|
9071
9730
|
const counts = /* @__PURE__ */ new Map();
|
|
@@ -9113,21 +9772,105 @@ var init_custody = __esm({
|
|
|
9113
9772
|
};
|
|
9114
9773
|
}
|
|
9115
9774
|
/**
|
|
9116
|
-
*
|
|
9117
|
-
*
|
|
9118
|
-
*
|
|
9119
|
-
*
|
|
9120
|
-
* refuse; the receipt records what the vault asserted separately from what
|
|
9121
|
-
* the roster expected. With it, a reply that does not itself name the
|
|
9122
|
-
* credential id and the expected account is refused.
|
|
9775
|
+
* Apply a failed account listing: any answer from the vault (a refusal such
|
|
9776
|
+
* as a revoked enrollment's `not_found`) drops every kept receipt, while an
|
|
9777
|
+
* unreachable vault keeps them. A vault watch that ends with the same
|
|
9778
|
+
* refusal calls this too, so both paths treat it alike.
|
|
9123
9779
|
*/
|
|
9124
|
-
|
|
9780
|
+
listFailed(error) {
|
|
9781
|
+
if (classifyVaultFailure(error) === "unreachable")
|
|
9782
|
+
this.transportLost(error);
|
|
9783
|
+
else {
|
|
9784
|
+
this.reachable();
|
|
9785
|
+
this.#kept.clear();
|
|
9786
|
+
}
|
|
9787
|
+
}
|
|
9788
|
+
/** Discard bearer material when a route is removed, declined or rebound. */
|
|
9789
|
+
forget(credentialId) {
|
|
9790
|
+
this.#kept.delete(credentialId);
|
|
9791
|
+
}
|
|
9792
|
+
/** Apply an already-held roster; this never fetches credentials or writes it. */
|
|
9793
|
+
retain(identities) {
|
|
9794
|
+
const current = new Map(identities.map((identity) => [identity.credentialId, identity]));
|
|
9795
|
+
for (const [id, kept] of this.#kept) {
|
|
9796
|
+
const identity = current.get(id);
|
|
9797
|
+
if (!identity?.enabled || identity.state !== "active" || identity.credentialType !== kept.attempt.credentialType || identity.accountIdentity !== kept.attempt.expectedAccountIdentity)
|
|
9798
|
+
this.forget(id);
|
|
9799
|
+
}
|
|
9800
|
+
}
|
|
9801
|
+
/** A frozen, non-secret summary for a plugin's status display. */
|
|
9802
|
+
keptReceiptState() {
|
|
9803
|
+
let since = null;
|
|
9804
|
+
for (const [id, kept] of this.#kept) {
|
|
9805
|
+
if (!this.#usable(kept.attempt)) {
|
|
9806
|
+
this.forget(id);
|
|
9807
|
+
continue;
|
|
9808
|
+
}
|
|
9809
|
+
if (kept.since !== null)
|
|
9810
|
+
since = Math.min(since ?? kept.since, kept.since);
|
|
9811
|
+
}
|
|
9812
|
+
return Object.freeze({ active: since !== null, since });
|
|
9813
|
+
}
|
|
9814
|
+
#usable(attempt) {
|
|
9815
|
+
return attempt.expiresAtMs === null ? attempt.credentialType === "api_key" : attempt.expiresAtMs - this.#now() > KEPT_RECEIPT_MARGIN_MS;
|
|
9816
|
+
}
|
|
9817
|
+
/** Ask the vault while reachable; retain one validated receipt in memory only. */
|
|
9818
|
+
async authorize(identity, signal, routeId = "vault") {
|
|
9819
|
+
this.#check(signal);
|
|
9820
|
+
const { credentialId, credentialType, accountIdentity } = identity;
|
|
9821
|
+
let kept = this.#kept.get(credentialId);
|
|
9822
|
+
if (kept && (kept.attempt.credentialType !== credentialType || kept.attempt.expectedAccountIdentity !== accountIdentity)) {
|
|
9823
|
+
this.forget(credentialId);
|
|
9824
|
+
kept = void 0;
|
|
9825
|
+
}
|
|
9826
|
+
let token;
|
|
9827
|
+
try {
|
|
9828
|
+
token = await this.#token(signal);
|
|
9829
|
+
} catch (error) {
|
|
9830
|
+
this.#kept.clear();
|
|
9831
|
+
throw error;
|
|
9832
|
+
}
|
|
9833
|
+
if (this.#outage && kept) {
|
|
9834
|
+
this.#probe();
|
|
9835
|
+
return this.#serveKept(credentialId, kept, token, routeId);
|
|
9836
|
+
}
|
|
9837
|
+
try {
|
|
9838
|
+
const attempt = await this.#authorizeFresh({ credentialId, credentialType, accountIdentity }, token, signal);
|
|
9839
|
+
this.#kept.set(credentialId, { attempt, routeId, since: null });
|
|
9840
|
+
return attempt;
|
|
9841
|
+
} catch (error) {
|
|
9842
|
+
this.#check(signal);
|
|
9843
|
+
if (classifyVaultFailure(error) !== "unreachable") {
|
|
9844
|
+
this.forget(credentialId);
|
|
9845
|
+
throw error;
|
|
9846
|
+
}
|
|
9847
|
+
return this.#serveKept(credentialId, kept, token, routeId, error);
|
|
9848
|
+
}
|
|
9849
|
+
}
|
|
9850
|
+
#serveKept(credentialId, kept, token, routeId, error = this.#outageError) {
|
|
9851
|
+
if (!kept || this.#kept.get(credentialId) !== kept || !this.#usable(kept.attempt)) {
|
|
9852
|
+
this.forget(credentialId);
|
|
9853
|
+
throw error;
|
|
9854
|
+
}
|
|
9855
|
+
if (kept.since === null)
|
|
9856
|
+
kept.since = this.#now();
|
|
9857
|
+
const attempt = Object.freeze(Object.defineProperty({ ...kept.attempt, fromKeptReceipt: true }, "accessToken", { value: kept.attempt.accessToken, enumerable: false }));
|
|
9858
|
+
this.#provenance.set(attempt, token);
|
|
9859
|
+
this.#keptAttempts.set(attempt, routeId);
|
|
9860
|
+
return attempt;
|
|
9861
|
+
}
|
|
9862
|
+
/**
|
|
9863
|
+
* Fetch and validate a fresh receipt before retaining it. The vault assertion
|
|
9864
|
+
* (or the plugin's token parse) must agree with the roster when both exist.
|
|
9865
|
+
* With requireAssertion, an absent assertion also refuses rather than
|
|
9866
|
+
* treating the roster's expectation as proof of the served account.
|
|
9867
|
+
*/
|
|
9868
|
+
async #authorizeFresh(identity, token, signal) {
|
|
9125
9869
|
if (!identity.credentialId)
|
|
9126
9870
|
throw new ClaustrumConsumerError("route-unavailable", "Claustrum dispatch requires a credential id");
|
|
9127
9871
|
const { credentialId, credentialType, accountIdentity } = identity;
|
|
9128
9872
|
if (this.#requireAssertion && accountIdentity === void 0)
|
|
9129
9873
|
throw new ClaustrumConsumerError("identity-unasserted", "Claustrum dispatch requires a known account identity");
|
|
9130
|
-
const token = await this.#token(signal);
|
|
9131
9874
|
const served = await this.#call(() => this.#client.getScoped({
|
|
9132
9875
|
credentialId,
|
|
9133
9876
|
enrollmentToken: token,
|
|
@@ -9190,6 +9933,18 @@ var init_custody = __esm({
|
|
|
9190
9933
|
const token = this.#provenance.get(attempt);
|
|
9191
9934
|
if (!token)
|
|
9192
9935
|
throw new ClaustrumConsumerError("no-receipt", "Claustrum failure report requires an original dispatch receipt");
|
|
9936
|
+
const keptRoute = this.#keptAttempts.get(attempt);
|
|
9937
|
+
if (keptRoute !== void 0) {
|
|
9938
|
+
this.forget(attempt.credentialId);
|
|
9939
|
+
this.#logger.debug("scoped 401 not reported", {
|
|
9940
|
+
routeId: keptRoute,
|
|
9941
|
+
reason: "kept-receipt"
|
|
9942
|
+
});
|
|
9943
|
+
return;
|
|
9944
|
+
}
|
|
9945
|
+
const kept = this.#kept.get(attempt.credentialId);
|
|
9946
|
+
if (kept && kept.attempt.recordVersion === attempt.recordVersion)
|
|
9947
|
+
this.forget(attempt.credentialId);
|
|
9193
9948
|
const pending = this.#reports.get(attempt);
|
|
9194
9949
|
if (pending)
|
|
9195
9950
|
return pending;
|
|
@@ -9213,10 +9968,70 @@ var init_custody = __esm({
|
|
|
9213
9968
|
throw error;
|
|
9214
9969
|
}
|
|
9215
9970
|
}
|
|
9971
|
+
/**
|
|
9972
|
+
* Watch this consumer's visible vault accounts instead of listing them on a
|
|
9973
|
+
* short timer. Opens one `watchScoped` on this custody's client and calls
|
|
9974
|
+
* `onView` when the host must run its discovery (see
|
|
9975
|
+
* `ClaustrumRosterWatchOptions`). A claustrum-client without `watchScoped`
|
|
9976
|
+
* (before 0.12.0) or a vault that answers `unknown_method` reports
|
|
9977
|
+
* `fallback` and opens nothing. A watch that closes before any notice was
|
|
9978
|
+
* never accepted: the client reads once to learn why, and the watch reports
|
|
9979
|
+
* `fallback` and tries one new watch after `WATCH_RETRY_MS`, never in a
|
|
9980
|
+
* loop. A watch that closes after notices is re-opened after
|
|
9981
|
+
* `RESUBSCRIBE_BACKOFF_MS`, doubling per close in a row. A lost transport
|
|
9982
|
+
* starts this custody's outage, exactly as an unreachable call does, and
|
|
9983
|
+
* the first notice of a watch ends it. Timers are unreferenced; `close()`
|
|
9984
|
+
* on the returned watch or on this custody stops it.
|
|
9985
|
+
*
|
|
9986
|
+
* The watch keeps no history, so the host still lists on a slow timer while
|
|
9987
|
+
* the mode is `watching`: every `SAFETY_POLL_MS` (five minutes). In any
|
|
9988
|
+
* other mode the host keeps its usual list timer.
|
|
9989
|
+
*/
|
|
9990
|
+
watchRoster(options) {
|
|
9991
|
+
this.#check();
|
|
9992
|
+
const watch = new ScopedRosterWatch({
|
|
9993
|
+
client: this.#client,
|
|
9994
|
+
enrollmentToken: () => this.#token(),
|
|
9995
|
+
view: options.view ?? (() => this.#discoveredView),
|
|
9996
|
+
discover: async (view) => {
|
|
9997
|
+
await options.onView(view);
|
|
9998
|
+
},
|
|
9999
|
+
onRefused: (error) => {
|
|
10000
|
+
this.listFailed(error);
|
|
10001
|
+
options.onRefused?.(error);
|
|
10002
|
+
},
|
|
10003
|
+
onTransportLost: () => this.transportLost(),
|
|
10004
|
+
onReachable: () => this.reachable(),
|
|
10005
|
+
onError: options.onError,
|
|
10006
|
+
onMode: options.onMode,
|
|
10007
|
+
logger: this.#logger,
|
|
10008
|
+
now: this.#now,
|
|
10009
|
+
setTimeoutImpl: this.#setTimeout,
|
|
10010
|
+
clearTimeoutImpl: this.#clearTimeout
|
|
10011
|
+
});
|
|
10012
|
+
this.#watches.add(watch);
|
|
10013
|
+
watch.start();
|
|
10014
|
+
return {
|
|
10015
|
+
get mode() {
|
|
10016
|
+
return watch.mode;
|
|
10017
|
+
},
|
|
10018
|
+
close: () => {
|
|
10019
|
+
this.#watches.delete(watch);
|
|
10020
|
+
watch.stop();
|
|
10021
|
+
}
|
|
10022
|
+
};
|
|
10023
|
+
}
|
|
9216
10024
|
close() {
|
|
9217
10025
|
if (this.#closed)
|
|
9218
10026
|
return;
|
|
9219
10027
|
this.#closed = true;
|
|
10028
|
+
if (this.#probeTimer)
|
|
10029
|
+
this.#clearTimeout(this.#probeTimer);
|
|
10030
|
+
this.#probeTimer = void 0;
|
|
10031
|
+
for (const watch of this.#watches)
|
|
10032
|
+
watch.stop();
|
|
10033
|
+
this.#watches.clear();
|
|
10034
|
+
this.#kept.clear();
|
|
9220
10035
|
this.#client.close();
|
|
9221
10036
|
}
|
|
9222
10037
|
};
|
|
@@ -9667,6 +10482,7 @@ var init_consumer = __esm({
|
|
|
9667
10482
|
init_errors2();
|
|
9668
10483
|
init_insula();
|
|
9669
10484
|
init_roster();
|
|
10485
|
+
init_watch();
|
|
9670
10486
|
ClaustrumConsumer = class {
|
|
9671
10487
|
#options;
|
|
9672
10488
|
#shutdown = new AbortController();
|
|
@@ -9683,6 +10499,10 @@ var init_consumer = __esm({
|
|
|
9683
10499
|
#timer;
|
|
9684
10500
|
#started = false;
|
|
9685
10501
|
#insula;
|
|
10502
|
+
#vaultWatch;
|
|
10503
|
+
#releaseInsulaWatch;
|
|
10504
|
+
/** When this instance last completed a discovery, by `now`. */
|
|
10505
|
+
#discoveredAt;
|
|
9686
10506
|
constructor(options) {
|
|
9687
10507
|
this.#options = options;
|
|
9688
10508
|
this.#logger = options.logger ?? createLogger2("claustrum");
|
|
@@ -9740,7 +10560,9 @@ var init_consumer = __esm({
|
|
|
9740
10560
|
parseIdentity: this.#options.parseIdentity,
|
|
9741
10561
|
requireAssertion: this.#options.requireAssertion,
|
|
9742
10562
|
now: this.#options.now,
|
|
9743
|
-
logger: this.#logger
|
|
10563
|
+
logger: this.#logger,
|
|
10564
|
+
setTimeoutImpl: this.#options.setTimeoutImpl,
|
|
10565
|
+
clearTimeoutImpl: this.#options.clearTimeoutImpl
|
|
9744
10566
|
});
|
|
9745
10567
|
if (this.#options.insula && client.insula) {
|
|
9746
10568
|
this.#insula = acquireInsulaQuotaSource(client.insula, this.#options.tokenPath);
|
|
@@ -9769,6 +10591,26 @@ var init_consumer = __esm({
|
|
|
9769
10591
|
const latest2 = this.#grantReach;
|
|
9770
10592
|
return latest2 && this.#roster?.view === latest2.view ? latest2.reach : void 0;
|
|
9771
10593
|
}
|
|
10594
|
+
/** How this consumer currently learns about changes, without I/O. */
|
|
10595
|
+
watchState() {
|
|
10596
|
+
return Object.freeze({
|
|
10597
|
+
vault: this.#vaultWatch?.mode ?? "polling",
|
|
10598
|
+
...this.#options.insula && {
|
|
10599
|
+
insula: this.#insula?.source.watchMode() ?? "polling"
|
|
10600
|
+
}
|
|
10601
|
+
});
|
|
10602
|
+
}
|
|
10603
|
+
/** Close the watches with the connection they belong to. */
|
|
10604
|
+
#stopWatch() {
|
|
10605
|
+
this.#vaultWatch?.close();
|
|
10606
|
+
this.#vaultWatch = void 0;
|
|
10607
|
+
this.#releaseInsulaWatch?.();
|
|
10608
|
+
this.#releaseInsulaWatch = void 0;
|
|
10609
|
+
}
|
|
10610
|
+
/** Whether any account is using an in-memory outage receipt, without I/O. */
|
|
10611
|
+
keptReceiptState() {
|
|
10612
|
+
return this.#custody?.keptReceiptState() ?? Object.freeze({ active: false, since: null });
|
|
10613
|
+
}
|
|
9772
10614
|
/** Rows for `/routing`, from the last committed roster. */
|
|
9773
10615
|
routingRows() {
|
|
9774
10616
|
return vaultRoutingRows(this.#roster);
|
|
@@ -9781,6 +10623,7 @@ var init_consumer = __esm({
|
|
|
9781
10623
|
if (!await this.#active()) {
|
|
9782
10624
|
this.#roster = void 0;
|
|
9783
10625
|
this.#grantReach = void 0;
|
|
10626
|
+
this.#stopWatch();
|
|
9784
10627
|
this.#custody?.close();
|
|
9785
10628
|
this.#custody = void 0;
|
|
9786
10629
|
this.#insula?.release();
|
|
@@ -9809,16 +10652,28 @@ var init_consumer = __esm({
|
|
|
9809
10652
|
this.#assertOpen();
|
|
9810
10653
|
const changed = roster?.view !== this.#roster?.view;
|
|
9811
10654
|
this.#roster = roster;
|
|
10655
|
+
custody.retain(roster?.rows ?? []);
|
|
9812
10656
|
if (discovered && roster?.view !== void 0)
|
|
9813
10657
|
this.#grantReach = discovered.grantReach ? { view: roster.view, reach: discovered.grantReach } : void 0;
|
|
9814
10658
|
if (roster && changed)
|
|
9815
10659
|
this.#options.onRoster?.(roster);
|
|
10660
|
+
this.#discoveredAt = (this.#options.now ?? Date.now)();
|
|
9816
10661
|
return roster;
|
|
9817
10662
|
})().finally(() => {
|
|
9818
10663
|
this.#refreshing = void 0;
|
|
9819
10664
|
});
|
|
9820
10665
|
return this.#refreshing;
|
|
9821
10666
|
}
|
|
10667
|
+
/**
|
|
10668
|
+
* Poll in the background and open the vault and insula watches. Until the
|
|
10669
|
+
* vault watch is accepted, and whenever it is unavailable, every tick lists
|
|
10670
|
+
* the vault exactly as before watches existed. While it is open a tick
|
|
10671
|
+
* lists only when five minutes have passed since the last discovery, since
|
|
10672
|
+
* the watch keeps no history; it still checks `isCustodyActive`, so a switch
|
|
10673
|
+
* to local mode closes the connection as quickly as before. Insula is
|
|
10674
|
+
* polled on the tick only while its own watch is not open. A host not in
|
|
10675
|
+
* vault mode makes no request.
|
|
10676
|
+
*/
|
|
9822
10677
|
start() {
|
|
9823
10678
|
if (this.#started)
|
|
9824
10679
|
return;
|
|
@@ -9826,8 +10681,10 @@ var init_consumer = __esm({
|
|
|
9826
10681
|
this.#started = true;
|
|
9827
10682
|
const tick = async () => {
|
|
9828
10683
|
try {
|
|
9829
|
-
await this
|
|
10684
|
+
if (await this.#listDue())
|
|
10685
|
+
await this.refresh();
|
|
9830
10686
|
await this.refreshInsulaQuota();
|
|
10687
|
+
this.#openWatch();
|
|
9831
10688
|
} catch (error) {
|
|
9832
10689
|
if (!this.#shutdown.signal.aborted)
|
|
9833
10690
|
this.#options.onError?.(error);
|
|
@@ -9845,6 +10702,50 @@ var init_consumer = __esm({
|
|
|
9845
10702
|
};
|
|
9846
10703
|
void tick();
|
|
9847
10704
|
}
|
|
10705
|
+
/** Whether a background tick must list the vault now. */
|
|
10706
|
+
async #listDue() {
|
|
10707
|
+
if (this.#vaultWatch?.mode !== "watching")
|
|
10708
|
+
return true;
|
|
10709
|
+
const now = (this.#options.now ?? Date.now)();
|
|
10710
|
+
if (this.#discoveredAt === void 0 || now - this.#discoveredAt >= SAFETY_POLL_MS)
|
|
10711
|
+
return true;
|
|
10712
|
+
return !await this.#active();
|
|
10713
|
+
}
|
|
10714
|
+
/**
|
|
10715
|
+
* Open the vault and insula watches once a vault connection exists. Only
|
|
10716
|
+
* reached in vault mode: a host in local mode never connects.
|
|
10717
|
+
*/
|
|
10718
|
+
#openWatch() {
|
|
10719
|
+
const custody = this.#custody;
|
|
10720
|
+
if (this.#shutdown.signal.aborted || !custody)
|
|
10721
|
+
return;
|
|
10722
|
+
this.#vaultWatch ??= custody.watchRoster({
|
|
10723
|
+
view: () => this.#roster?.view,
|
|
10724
|
+
// The existing discovery, so a watched change commits the roster and
|
|
10725
|
+
// re-applies it to kept receipts exactly as a poll does. A refresh
|
|
10726
|
+
// already in flight may have listed before the change was announced,
|
|
10727
|
+
// so wait for it and list again.
|
|
10728
|
+
onView: async () => {
|
|
10729
|
+
while (this.#refreshing)
|
|
10730
|
+
await this.#refreshing.catch(() => {
|
|
10731
|
+
});
|
|
10732
|
+
await this.refresh();
|
|
10733
|
+
},
|
|
10734
|
+
// Custody has dropped kept receipts, as a poll meeting the same
|
|
10735
|
+
// refusal from list_scoped would.
|
|
10736
|
+
onRefused: (error) => this.#options.onError?.(error),
|
|
10737
|
+
onError: (error) => {
|
|
10738
|
+
if (!this.#shutdown.signal.aborted)
|
|
10739
|
+
this.#options.onError?.(error);
|
|
10740
|
+
}
|
|
10741
|
+
});
|
|
10742
|
+
if (this.#options.insula && this.#insula && !this.#releaseInsulaWatch)
|
|
10743
|
+
this.#releaseInsulaWatch = this.#insula.source.watch({
|
|
10744
|
+
provider: this.#options.insula.provider,
|
|
10745
|
+
setTimeoutImpl: this.#options.setTimeoutImpl,
|
|
10746
|
+
clearTimeoutImpl: this.#options.clearTimeoutImpl
|
|
10747
|
+
});
|
|
10748
|
+
}
|
|
9848
10749
|
/**
|
|
9849
10750
|
* Fetch on a background tick, at most once per minute across projects with
|
|
9850
10751
|
* the same daemon and enrollment token path. Admission must use the cache
|
|
@@ -9907,16 +10808,28 @@ var init_consumer = __esm({
|
|
|
9907
10808
|
async authorize(routeId, signal) {
|
|
9908
10809
|
this.#assertOpen(signal);
|
|
9909
10810
|
const roster = this.#roster ?? await this.#wait(this.refresh(), signal);
|
|
9910
|
-
if (!roster || !await this.#active())
|
|
10811
|
+
if (!roster || !await this.#active()) {
|
|
10812
|
+
this.#custody?.close();
|
|
10813
|
+
this.#custody = void 0;
|
|
10814
|
+
this.#stopWatch();
|
|
10815
|
+
this.#insula?.release();
|
|
10816
|
+
this.#insula = void 0;
|
|
9911
10817
|
throw new ClaustrumConsumerError("not-active", "Claustrum scoped custody is not active");
|
|
10818
|
+
}
|
|
9912
10819
|
const current = await readVaultRoster(this.#options.rosterPath);
|
|
9913
10820
|
this.#assertOpen(signal);
|
|
9914
10821
|
const observed = roster.rows.find((row) => row.routeId === routeId);
|
|
9915
10822
|
const configured = current?.rows.find((row) => row.routeId === routeId);
|
|
9916
|
-
if (configured && !configured.enabled)
|
|
10823
|
+
if (configured && !configured.enabled) {
|
|
10824
|
+
if (observed)
|
|
10825
|
+
this.#custody?.forget(observed.credentialId);
|
|
9917
10826
|
throw new ClaustrumConsumerError("route-declined", "Claustrum route is disabled");
|
|
9918
|
-
|
|
10827
|
+
}
|
|
10828
|
+
if (!observed || !configured || configured.state !== "active" || configured.credentialId !== observed.credentialId || configured.accountIdentity !== observed.accountIdentity || configured.credentialType !== observed.credentialType) {
|
|
10829
|
+
if (observed)
|
|
10830
|
+
this.#custody?.forget(observed.credentialId);
|
|
9919
10831
|
throw new ClaustrumConsumerError("route-unavailable", "Claustrum route is disabled, removed or changed");
|
|
10832
|
+
}
|
|
9920
10833
|
const custody = await this.#wait(this.#getCustody(), signal);
|
|
9921
10834
|
const combined = combineAbortSignals([
|
|
9922
10835
|
this.#shutdown.signal,
|
|
@@ -9929,7 +10842,7 @@ var init_consumer = __esm({
|
|
|
9929
10842
|
...configured.accountIdentity !== void 0 && {
|
|
9930
10843
|
accountIdentity: configured.accountIdentity
|
|
9931
10844
|
}
|
|
9932
|
-
}, combined.signal);
|
|
10845
|
+
}, combined.signal, routeId);
|
|
9933
10846
|
} finally {
|
|
9934
10847
|
combined.dispose();
|
|
9935
10848
|
}
|
|
@@ -9952,6 +10865,10 @@ var init_consumer = __esm({
|
|
|
9952
10865
|
const signal = options.signal;
|
|
9953
10866
|
let served = await this.authorize(routeId, signal);
|
|
9954
10867
|
let response = await dispatch(served, signal);
|
|
10868
|
+
if (response.status === 401 && served.fromKeptReceipt) {
|
|
10869
|
+
await this.reportFailure(served, 401, options.reporterSource ?? "direct");
|
|
10870
|
+
return response;
|
|
10871
|
+
}
|
|
9955
10872
|
if (response.status === 401 && !signal?.aborted) {
|
|
9956
10873
|
let current;
|
|
9957
10874
|
try {
|
|
@@ -9979,6 +10896,7 @@ var init_consumer = __esm({
|
|
|
9979
10896
|
this.#assertOpen();
|
|
9980
10897
|
await declineVaultRoute(this.#options.rosterPath, routeId);
|
|
9981
10898
|
this.#roster = await readVaultRoster(this.#options.rosterPath);
|
|
10899
|
+
this.#custody?.retain(this.#roster?.rows ?? []);
|
|
9982
10900
|
}
|
|
9983
10901
|
async accept(routeId) {
|
|
9984
10902
|
this.#assertOpen();
|
|
@@ -10034,6 +10952,7 @@ var init_consumer = __esm({
|
|
|
10034
10952
|
if (this.#timer)
|
|
10035
10953
|
(this.#options.clearTimeoutImpl ?? clearTimeout)(this.#timer);
|
|
10036
10954
|
this.#timer = void 0;
|
|
10955
|
+
this.#stopWatch();
|
|
10037
10956
|
this.#custody?.close();
|
|
10038
10957
|
this.#insula?.release();
|
|
10039
10958
|
this.#insula = void 0;
|
|
@@ -10048,21 +10967,31 @@ var init_consumer = __esm({
|
|
|
10048
10967
|
var claustrum_exports = {};
|
|
10049
10968
|
__export(claustrum_exports, {
|
|
10050
10969
|
CUSTODY_PLACEHOLDER_PREFIX: () => CUSTODY_PLACEHOLDER_PREFIX,
|
|
10970
|
+
ChangeNoticeReader: () => ChangeNoticeReader,
|
|
10051
10971
|
ClaustrumConsumer: () => ClaustrumConsumer,
|
|
10052
10972
|
ClaustrumConsumerError: () => ClaustrumConsumerError,
|
|
10053
|
-
ClaustrumCredentialError: () =>
|
|
10973
|
+
ClaustrumCredentialError: () => ClaustrumCredentialError4,
|
|
10054
10974
|
ClaustrumEnrollmentManager: () => ClaustrumEnrollmentManager,
|
|
10055
10975
|
ClaustrumScopedCustody: () => ClaustrumScopedCustody,
|
|
10976
|
+
ClaustrumUnreachableError: () => ClaustrumUnreachableError,
|
|
10056
10977
|
DEFAULT_ROUTE_PREFIX: () => DEFAULT_ROUTE_PREFIX,
|
|
10978
|
+
KEPT_RECEIPT_MARGIN_MS: () => KEPT_RECEIPT_MARGIN_MS,
|
|
10979
|
+
RESUBSCRIBE_BACKOFF_MS: () => RESUBSCRIBE_BACKOFF_MS,
|
|
10057
10980
|
RETRYABLE_ENROLLMENT_CODES: () => RETRYABLE_ENROLLMENT_CODES,
|
|
10981
|
+
SAFETY_POLL_MS: () => SAFETY_POLL_MS,
|
|
10058
10982
|
SERVING_MARGIN_MS: () => SERVING_MARGIN_MS,
|
|
10983
|
+
ScopedRosterWatch: () => ScopedRosterWatch,
|
|
10059
10984
|
TERMINAL_ENROLLMENT_CODES: () => TERMINAL_ENROLLMENT_CODES,
|
|
10985
|
+
VAULT_FAILURE_CLASSES: () => VAULT_FAILURE_CLASSES,
|
|
10986
|
+
WATCH_RETRY_MS: () => WATCH_RETRY_MS,
|
|
10060
10987
|
acceptAccount: () => acceptAccount,
|
|
10061
10988
|
acceptVaultRoute: () => acceptVaultRoute,
|
|
10989
|
+
acquireInsulaQuotaSource: () => acquireInsulaQuotaSource,
|
|
10062
10990
|
assertHostSlotMatchesMode: () => assertHostSlotMatchesMode,
|
|
10063
10991
|
assertNotCustodyPlaceholder: () => assertNotCustodyPlaceholder,
|
|
10064
10992
|
classifyEnrollmentError: () => classifyEnrollmentError,
|
|
10065
10993
|
classifyHostSlot: () => classifyHostSlot,
|
|
10994
|
+
classifyVaultFailure: () => classifyVaultFailure,
|
|
10066
10995
|
connectClaustrumEnrollmentClient: () => connectClaustrumEnrollmentClient,
|
|
10067
10996
|
connectClaustrumScopedClient: () => connectClaustrumScopedClient,
|
|
10068
10997
|
custodyPlaceholder: () => custodyPlaceholder,
|
|
@@ -10092,7 +11021,7 @@ __export(claustrum_exports, {
|
|
|
10092
11021
|
vaultRoutingRows: () => vaultRoutingRows
|
|
10093
11022
|
});
|
|
10094
11023
|
import { ClaustrumClient } from "@cortexkit/claustrum-client";
|
|
10095
|
-
import { ClaustrumCredentialError as
|
|
11024
|
+
import { ClaustrumCredentialError as ClaustrumCredentialError4 } from "@cortexkit/claustrum-client";
|
|
10096
11025
|
async function connectClaustrumScopedClient(options) {
|
|
10097
11026
|
const client = await ClaustrumClient.connect(options);
|
|
10098
11027
|
return Object.assign(client, { insula: insulaUsageTransport(options) });
|
|
@@ -10101,13 +11030,16 @@ var init_claustrum = __esm({
|
|
|
10101
11030
|
"../core/dist/common-auth-embedded/claustrum/index.js"() {
|
|
10102
11031
|
"use strict";
|
|
10103
11032
|
init_insula();
|
|
11033
|
+
init_availability();
|
|
10104
11034
|
init_consumer();
|
|
10105
11035
|
init_custody();
|
|
10106
11036
|
init_enrollment();
|
|
10107
11037
|
init_errors2();
|
|
10108
11038
|
init_host_slot();
|
|
11039
|
+
init_insula();
|
|
10109
11040
|
init_interlock();
|
|
10110
11041
|
init_roster();
|
|
11042
|
+
init_watch();
|
|
10111
11043
|
}
|
|
10112
11044
|
});
|
|
10113
11045
|
|
|
@@ -20504,7 +21436,15 @@ function projectAntigravityQuota(quota) {
|
|
|
20504
21436
|
});
|
|
20505
21437
|
}
|
|
20506
21438
|
}
|
|
20507
|
-
return {
|
|
21439
|
+
return {
|
|
21440
|
+
scope: "all",
|
|
21441
|
+
limits,
|
|
21442
|
+
checkedAt,
|
|
21443
|
+
groups: [
|
|
21444
|
+
{ scope: "gemini", label: "Gemini" },
|
|
21445
|
+
{ scope: "non-gemini", label: "Other models" }
|
|
21446
|
+
]
|
|
21447
|
+
};
|
|
20508
21448
|
}
|
|
20509
21449
|
function formatAntigravityQuota(quota, options) {
|
|
20510
21450
|
return formatQuota(projectAntigravityQuota(quota), options);
|
|
@@ -23438,7 +24378,8 @@ function admissionFromReceipt(ref, receipt2) {
|
|
|
23438
24378
|
accountIdentity: receipt2.assertedAccountIdentity,
|
|
23439
24379
|
recordVersion: receipt2.recordVersion,
|
|
23440
24380
|
projectId: receipt2.projectId,
|
|
23441
|
-
expiresAtMs: receipt2.expiresAtMs
|
|
24381
|
+
expiresAtMs: receipt2.expiresAtMs,
|
|
24382
|
+
fromKeptReceipt: receipt2.fromKeptReceipt
|
|
23442
24383
|
};
|
|
23443
24384
|
Object.defineProperty(admission, "accessToken", {
|
|
23444
24385
|
value: receipt2.accessToken,
|
|
@@ -23511,7 +24452,7 @@ function createAntigravityVaultAccountSource(options) {
|
|
|
23511
24452
|
assertOpen();
|
|
23512
24453
|
entry.reported = true;
|
|
23513
24454
|
await consumer.reportFailure(entry.receipt, 401, reporterSource ?? options.reporterSource);
|
|
23514
|
-
return true;
|
|
24455
|
+
return entry.receipt.fromKeptReceipt !== true;
|
|
23515
24456
|
};
|
|
23516
24457
|
const verifyAttribution = async (attribution, signal) => {
|
|
23517
24458
|
await assertServing(signal);
|
|
@@ -23540,10 +24481,15 @@ function createAntigravityVaultAccountSource(options) {
|
|
|
23540
24481
|
},
|
|
23541
24482
|
routes: () => closed ? [] : routeRefs(consumer.snapshot(), isDeclined2),
|
|
23542
24483
|
admit: admit2,
|
|
24484
|
+
retryAfter401: (served, current, site) => claustrum.decideScopedRetryAfter401(site, issuedEntry(served).receipt, current && issuedEntry(current).receipt, options.logger),
|
|
23543
24485
|
send: async (ref, dispatch, sendOptions) => {
|
|
23544
24486
|
const signal = sendOptions.signal;
|
|
23545
24487
|
let admission = await admit2(ref, signal);
|
|
23546
24488
|
let response = await dispatch(admission, signal);
|
|
24489
|
+
if (response.status === 401 && admission.fromKeptReceipt) {
|
|
24490
|
+
await reportServedStatus(admission, 401, sendOptions.reporterSource);
|
|
24491
|
+
return response;
|
|
24492
|
+
}
|
|
23547
24493
|
if (response.status === 401 && !signal?.aborted) {
|
|
23548
24494
|
let current;
|
|
23549
24495
|
try {
|
|
@@ -24123,19 +25069,24 @@ async function replaceWindowsFile2(from, to, options = {}) {
|
|
|
24123
25069
|
to = resolve7(to);
|
|
24124
25070
|
const now = options.now ?? (() => performance.now());
|
|
24125
25071
|
const start = now();
|
|
24126
|
-
const
|
|
25072
|
+
const leaseDeadline = options.deadline ?? Infinity;
|
|
25073
|
+
let retryDeadline;
|
|
24127
25074
|
const delays = [0, 10, 20, 40, 80, 100];
|
|
24128
25075
|
let original;
|
|
24129
25076
|
let attempts2 = 0;
|
|
24130
25077
|
for (const delay3 of delays) {
|
|
25078
|
+
const deadline = Math.min(retryDeadline ?? Infinity, leaseDeadline);
|
|
24131
25079
|
if (now() >= deadline)
|
|
24132
25080
|
break;
|
|
24133
25081
|
if (delay3)
|
|
24134
25082
|
await (options.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms))))(Math.min(delay3, Math.max(0, deadline - now())));
|
|
24135
25083
|
if (now() >= deadline)
|
|
24136
25084
|
break;
|
|
25085
|
+
const fenceStart = now();
|
|
24137
25086
|
await options.beforeRename?.();
|
|
24138
|
-
if (
|
|
25087
|
+
if (retryDeadline !== void 0)
|
|
25088
|
+
retryDeadline += now() - fenceStart;
|
|
25089
|
+
if (now() >= leaseDeadline)
|
|
24139
25090
|
break;
|
|
24140
25091
|
attempts2++;
|
|
24141
25092
|
try {
|
|
@@ -24147,6 +25098,7 @@ async function replaceWindowsFile2(from, to, options = {}) {
|
|
|
24147
25098
|
const candidate = detail.win32Code !== void 0 ? detail.win32Code === 32 || detail.win32Code === 33 : ["EBUSY", "EPERM", "EACCES"].includes(detail.code ?? "") && !detail.reason;
|
|
24148
25099
|
if (!candidate)
|
|
24149
25100
|
break;
|
|
25101
|
+
retryDeadline ??= now() + 500;
|
|
24150
25102
|
}
|
|
24151
25103
|
}
|
|
24152
25104
|
const error = new PrivateFileError2(to, "rename", original ?? Object.assign(new Error("Publication deadline expired"), {
|
|
@@ -35423,6 +36375,80 @@ async function retainResponseLifetime(response, cancellation) {
|
|
|
35423
36375
|
}
|
|
35424
36376
|
}
|
|
35425
36377
|
|
|
36378
|
+
// src/plugin/shared/after-handoff.ts
|
|
36379
|
+
function createAfterHandoff(work, signals, onFailure) {
|
|
36380
|
+
const controller = new AbortController();
|
|
36381
|
+
const cancellation = createRequestCancellation([
|
|
36382
|
+
...signals,
|
|
36383
|
+
controller.signal
|
|
36384
|
+
]);
|
|
36385
|
+
let run;
|
|
36386
|
+
let acknowledged = false;
|
|
36387
|
+
let finished = false;
|
|
36388
|
+
let running = false;
|
|
36389
|
+
let resolveCompletion = () => {
|
|
36390
|
+
};
|
|
36391
|
+
const completion = new Promise((resolve18) => {
|
|
36392
|
+
resolveCompletion = resolve18;
|
|
36393
|
+
});
|
|
36394
|
+
const finish = () => {
|
|
36395
|
+
if (finished) return;
|
|
36396
|
+
finished = true;
|
|
36397
|
+
run = void 0;
|
|
36398
|
+
cancellation.signal.removeEventListener("abort", onAbort);
|
|
36399
|
+
cancellation.release();
|
|
36400
|
+
work.delete(completion);
|
|
36401
|
+
resolveCompletion();
|
|
36402
|
+
};
|
|
36403
|
+
const onAbort = () => {
|
|
36404
|
+
if (!running) finish();
|
|
36405
|
+
};
|
|
36406
|
+
cancellation.signal.addEventListener("abort", onAbort, { once: true });
|
|
36407
|
+
if (cancellation.signal.aborted) onAbort();
|
|
36408
|
+
return {
|
|
36409
|
+
register(callback) {
|
|
36410
|
+
if (finished || run) return;
|
|
36411
|
+
run = callback;
|
|
36412
|
+
work.add(completion);
|
|
36413
|
+
},
|
|
36414
|
+
acknowledge() {
|
|
36415
|
+
if (finished || acknowledged || !run) return;
|
|
36416
|
+
acknowledged = true;
|
|
36417
|
+
void Promise.resolve().then(async () => {
|
|
36418
|
+
if (finished || cancellation.signal.aborted) return;
|
|
36419
|
+
running = true;
|
|
36420
|
+
try {
|
|
36421
|
+
await run?.(cancellation.signal);
|
|
36422
|
+
} catch {
|
|
36423
|
+
try {
|
|
36424
|
+
onFailure();
|
|
36425
|
+
} catch {
|
|
36426
|
+
}
|
|
36427
|
+
} finally {
|
|
36428
|
+
finish();
|
|
36429
|
+
}
|
|
36430
|
+
});
|
|
36431
|
+
},
|
|
36432
|
+
cancel() {
|
|
36433
|
+
controller.abort();
|
|
36434
|
+
onAbort();
|
|
36435
|
+
}
|
|
36436
|
+
};
|
|
36437
|
+
}
|
|
36438
|
+
function publishResponse(dispatch) {
|
|
36439
|
+
return new Promise((resolve18, reject) => {
|
|
36440
|
+
let acknowledge;
|
|
36441
|
+
void Promise.resolve().then(
|
|
36442
|
+
() => dispatch((callback) => {
|
|
36443
|
+
acknowledge = callback;
|
|
36444
|
+
})
|
|
36445
|
+
).then((response) => {
|
|
36446
|
+
resolve18(response);
|
|
36447
|
+
acknowledge?.();
|
|
36448
|
+
}, reject);
|
|
36449
|
+
});
|
|
36450
|
+
}
|
|
36451
|
+
|
|
35426
36452
|
// src/plugin/shared/request-services.ts
|
|
35427
36453
|
var FIRST_RETRY_DELAY_MS = 1e3;
|
|
35428
36454
|
function prepareAgyWireRequest(wire, request) {
|
|
@@ -36472,24 +37498,17 @@ function createRequestExecutor(deps) {
|
|
|
36472
37498
|
);
|
|
36473
37499
|
noteGeminiDumpResponse(dumpContext, response);
|
|
36474
37500
|
if (credentials.domain === "vault" && sendAdmission && response.status === 401) {
|
|
36475
|
-
|
|
36476
|
-
|
|
36477
|
-
|
|
36478
|
-
|
|
36479
|
-
|
|
36480
|
-
|
|
36481
|
-
|
|
36482
|
-
|
|
36483
|
-
}
|
|
36484
|
-
|
|
36485
|
-
|
|
36486
|
-
const next = await deadline.wait(
|
|
36487
|
-
() => credentials.admit({
|
|
36488
|
-
account,
|
|
36489
|
-
signal: abortSignal
|
|
36490
|
-
})
|
|
36491
|
-
);
|
|
36492
|
-
if (next.credentialId === sendAdmission.credentialId && next.accountIdentity === sendAdmission.accountIdentity && next.recordVersion > sendAdmission.recordVersion) {
|
|
37501
|
+
if (!sendAdmission.fromKeptReceipt && !vault401Retried && !abortSignal?.aborted) {
|
|
37502
|
+
let next;
|
|
37503
|
+
try {
|
|
37504
|
+
next = await deadline.wait(
|
|
37505
|
+
() => credentials.admit({ account, signal: abortSignal })
|
|
37506
|
+
);
|
|
37507
|
+
} catch {
|
|
37508
|
+
checkAborted();
|
|
37509
|
+
}
|
|
37510
|
+
const retry = credentials.retryAfter401 ? credentials.retryAfter401(sendAdmission, next, "model") : next && !next.fromKeptReceipt && next.credentialId === sendAdmission.credentialId && next.accountIdentity === sendAdmission.accountIdentity && next.recordVersion > sendAdmission.recordVersion;
|
|
37511
|
+
if (next && retry) {
|
|
36493
37512
|
vault401Retried = true;
|
|
36494
37513
|
rotatedAdmission = next;
|
|
36495
37514
|
void response.body?.cancel().catch(() => {
|
|
@@ -36501,6 +37520,16 @@ function createRequestExecutor(deps) {
|
|
|
36501
37520
|
continue;
|
|
36502
37521
|
}
|
|
36503
37522
|
}
|
|
37523
|
+
try {
|
|
37524
|
+
await deadline.wait(
|
|
37525
|
+
() => sendAdmission.report401(response.status)
|
|
37526
|
+
);
|
|
37527
|
+
} catch (error) {
|
|
37528
|
+
checkAborted();
|
|
37529
|
+
log16.debug("send-admission-401-report-failed", {
|
|
37530
|
+
error: String(error)
|
|
37531
|
+
});
|
|
37532
|
+
}
|
|
36504
37533
|
}
|
|
36505
37534
|
const sessionKey = requestSessionIdentity.sessionId;
|
|
36506
37535
|
if (sessionKey) {
|
|
@@ -36775,23 +37804,6 @@ function createRequestExecutor(deps) {
|
|
|
36775
37804
|
trackers.health.recordSuccess(account.index);
|
|
36776
37805
|
if (!advisoryClosing)
|
|
36777
37806
|
accountManager.markAccountUsed(account.index);
|
|
36778
|
-
if (credentials.domain === "local" && !advisoryClosing && credentials.refreshQuotaAfterSuccess) {
|
|
36779
|
-
const quotaCancellation = createRequestCancellation(
|
|
36780
|
-
init?.signal ? [init.signal, shutdown.signal] : [shutdown.signal]
|
|
36781
|
-
);
|
|
36782
|
-
const work = credentials.refreshQuotaAfterSuccess(
|
|
36783
|
-
account,
|
|
36784
|
-
config.quota_refresh_interval_minutes,
|
|
36785
|
-
quotaCancellation.signal
|
|
36786
|
-
).catch(() => {
|
|
36787
|
-
log16.debug("post-response-advisory-work-failed");
|
|
36788
|
-
}).finally(() => quotaCancellation.release());
|
|
36789
|
-
advisoryWork.add(work);
|
|
36790
|
-
void work.then(
|
|
36791
|
-
() => advisoryWork.delete(work),
|
|
36792
|
-
() => advisoryWork.delete(work)
|
|
36793
|
-
);
|
|
36794
|
-
}
|
|
36795
37807
|
const proactiveThreshold = config.proactive_rotation_threshold_percent ?? 20;
|
|
36796
37808
|
if (!advisoryClosing && proactiveThreshold > 0 && accountManager.shouldProactivelyRotate(
|
|
36797
37809
|
family,
|
|
@@ -36939,6 +37951,10 @@ function createRequestExecutor(deps) {
|
|
|
36939
37951
|
);
|
|
36940
37952
|
}
|
|
36941
37953
|
}
|
|
37954
|
+
if (response.ok && transformedResponse.ok && credentials.domain === "local" && !advisoryClosing && credentials.refreshQuotaAfterSuccess) {
|
|
37955
|
+
const refresh = credentials.refreshQuotaAfterSuccess;
|
|
37956
|
+
waitPolicy.quota = (signal) => refresh(account, config.quota_refresh_interval_minutes, signal);
|
|
37957
|
+
}
|
|
36942
37958
|
return transformedResponse;
|
|
36943
37959
|
} catch (error) {
|
|
36944
37960
|
if (error instanceof PreResponseTimeoutError) throw error;
|
|
@@ -37139,6 +38155,11 @@ function createRequestExecutor(deps) {
|
|
|
37139
38155
|
deps.preResponseClock
|
|
37140
38156
|
);
|
|
37141
38157
|
log16.debug("pre-response-start", { limitMs: PRE_RESPONSE_DEADLINE_MS });
|
|
38158
|
+
const handoff = createAfterHandoff(
|
|
38159
|
+
advisoryWork,
|
|
38160
|
+
requestedSignal ? [requestedSignal, shutdown.signal] : [shutdown.signal],
|
|
38161
|
+
() => log16.debug("post-response-advisory-work-failed")
|
|
38162
|
+
);
|
|
37142
38163
|
const waitPolicy = {};
|
|
37143
38164
|
const selectedCredentials = /* @__PURE__ */ new Set();
|
|
37144
38165
|
const selectedProjectIds = /* @__PURE__ */ new Set();
|
|
@@ -37163,6 +38184,7 @@ function createRequestExecutor(deps) {
|
|
|
37163
38184
|
async (response) => {
|
|
37164
38185
|
deadline.acceptTerminalResponse();
|
|
37165
38186
|
if (bufferedOverflow.has(response)) {
|
|
38187
|
+
handoff.cancel();
|
|
37166
38188
|
deadline.dispose();
|
|
37167
38189
|
cancellation.release();
|
|
37168
38190
|
return redactCredentialResponse(
|
|
@@ -37179,14 +38201,22 @@ function createRequestExecutor(deps) {
|
|
|
37179
38201
|
inFlight.add(retained.settled);
|
|
37180
38202
|
void retained.settled.then(() => inFlight.delete(retained.settled));
|
|
37181
38203
|
void retained.settled.then(() => deadline.dispose());
|
|
37182
|
-
|
|
38204
|
+
const published = await redactCredentialResponse(
|
|
37183
38205
|
preserveResponseMetadata2(retained.response, response),
|
|
37184
38206
|
[...selectedCredentials],
|
|
37185
38207
|
void 0,
|
|
37186
38208
|
[...selectedProjectIds]
|
|
37187
38209
|
);
|
|
38210
|
+
if (published.ok && waitPolicy.quota && requestOptions?.onResponseHandoff) {
|
|
38211
|
+
handoff.register(waitPolicy.quota);
|
|
38212
|
+
requestOptions.onResponseHandoff(handoff.acknowledge);
|
|
38213
|
+
} else {
|
|
38214
|
+
handoff.cancel();
|
|
38215
|
+
}
|
|
38216
|
+
return published;
|
|
37188
38217
|
},
|
|
37189
38218
|
(error) => {
|
|
38219
|
+
handoff.cancel();
|
|
37190
38220
|
deadline.dispose();
|
|
37191
38221
|
cancellation.release();
|
|
37192
38222
|
throw redactCredentialError(
|
|
@@ -37196,6 +38226,7 @@ function createRequestExecutor(deps) {
|
|
|
37196
38226
|
);
|
|
37197
38227
|
}
|
|
37198
38228
|
).catch((error) => {
|
|
38229
|
+
handoff.cancel();
|
|
37199
38230
|
deadline.dispose();
|
|
37200
38231
|
cancellation.release();
|
|
37201
38232
|
throw redactCredentialError(
|
|
@@ -38171,6 +39202,7 @@ function refreshVaultAccountRow(prior, fresh) {
|
|
|
38171
39202
|
else prior.email = fresh.email;
|
|
38172
39203
|
}
|
|
38173
39204
|
var VaultSendGrant = class {
|
|
39205
|
+
fromKeptReceipt;
|
|
38174
39206
|
credentialId;
|
|
38175
39207
|
accountIdentity;
|
|
38176
39208
|
recordVersion;
|
|
@@ -38185,20 +39217,36 @@ var VaultSendGrant = class {
|
|
|
38185
39217
|
this.accountIdentity = admission.accountIdentity;
|
|
38186
39218
|
this.recordVersion = admission.recordVersion;
|
|
38187
39219
|
this.projectId = admission.projectId;
|
|
39220
|
+
this.fromKeptReceipt = admission.fromKeptReceipt;
|
|
38188
39221
|
this.report401 = report;
|
|
38189
39222
|
}
|
|
38190
39223
|
};
|
|
38191
39224
|
function createVaultRequestCredentials(source, onAdmitted) {
|
|
39225
|
+
const issued = /* @__PURE__ */ new WeakMap();
|
|
38192
39226
|
return {
|
|
38193
39227
|
domain: "vault",
|
|
39228
|
+
...source.retryAfter401 && {
|
|
39229
|
+
retryAfter401(served, current, site) {
|
|
39230
|
+
const original = issued.get(served);
|
|
39231
|
+
if (!original)
|
|
39232
|
+
throw new Error("Retry requires an original vault admission");
|
|
39233
|
+
return source.retryAfter401(
|
|
39234
|
+
original,
|
|
39235
|
+
current && issued.get(current),
|
|
39236
|
+
site
|
|
39237
|
+
);
|
|
39238
|
+
}
|
|
39239
|
+
},
|
|
38194
39240
|
async admit({ account, signal }) {
|
|
38195
39241
|
const admission = await source.admit(account.route, signal);
|
|
38196
39242
|
if (onAdmitted)
|
|
38197
39243
|
onAdmitted.admitted(account, onAdmitted.source.attribution(admission));
|
|
38198
|
-
|
|
39244
|
+
const grant = new VaultSendGrant(
|
|
38199
39245
|
admission,
|
|
38200
39246
|
(status) => source.reportServedStatus(admission, status)
|
|
38201
39247
|
);
|
|
39248
|
+
issued.set(grant, admission);
|
|
39249
|
+
return grant;
|
|
38202
39250
|
}
|
|
38203
39251
|
};
|
|
38204
39252
|
}
|
|
@@ -38647,7 +39695,8 @@ function createOpenCodeVaultCustody(options) {
|
|
|
38647
39695
|
reporterSource: options.reporterSource,
|
|
38648
39696
|
state: { path: paths.stateFile, fs: await loadCommonAuthFs() },
|
|
38649
39697
|
...options.logger ? { logger: options.logger } : {},
|
|
38650
|
-
...options.now ? { now: options.now } : {}
|
|
39698
|
+
...options.now ? { now: options.now } : {},
|
|
39699
|
+
...options.pollIntervalMs !== void 0 ? { pollIntervalMs: options.pollIntervalMs } : {}
|
|
38651
39700
|
});
|
|
38652
39701
|
const activeSource = {
|
|
38653
39702
|
...created,
|
|
@@ -39705,6 +40754,7 @@ function createGaJobExecutor(executor, overrides = {}) {
|
|
|
39705
40754
|
{
|
|
39706
40755
|
kind: job.kind,
|
|
39707
40756
|
variant: job.variant ?? void 0,
|
|
40757
|
+
...context.onResponseHandoff ? { onResponseHandoff: context.onResponseHandoff } : {},
|
|
39708
40758
|
session: {
|
|
39709
40759
|
sessionId: job.sessionID,
|
|
39710
40760
|
parentSessionId: job.parentSessionID
|
|
@@ -42270,18 +43320,34 @@ async function startGaLoopbackBridge(options) {
|
|
|
42270
43320
|
});
|
|
42271
43321
|
try {
|
|
42272
43322
|
let upstream;
|
|
43323
|
+
let acknowledge;
|
|
42273
43324
|
try {
|
|
42274
43325
|
upstream = await options.execute(entry.job, {
|
|
42275
43326
|
signal: controller.signal,
|
|
42276
|
-
send: options.send
|
|
43327
|
+
send: options.send,
|
|
43328
|
+
onResponseHandoff: (callback) => {
|
|
43329
|
+
acknowledge = callback;
|
|
43330
|
+
}
|
|
42277
43331
|
});
|
|
42278
43332
|
} catch (error) {
|
|
43333
|
+
acknowledge = void 0;
|
|
42279
43334
|
upstream = gaPreHeaderFailureResponse(error);
|
|
42280
43335
|
}
|
|
42281
|
-
await pipeResponse(
|
|
42282
|
-
|
|
42283
|
-
|
|
42284
|
-
|
|
43336
|
+
await pipeResponse(
|
|
43337
|
+
upstream,
|
|
43338
|
+
response,
|
|
43339
|
+
(error) => {
|
|
43340
|
+
if (!state.released && (state.claimed || !closing))
|
|
43341
|
+
state.failure = error;
|
|
43342
|
+
},
|
|
43343
|
+
() => {
|
|
43344
|
+
if (!response.destroyed && !controller.signal.aborted && !closing) {
|
|
43345
|
+
const callback = acknowledge;
|
|
43346
|
+
acknowledge = void 0;
|
|
43347
|
+
callback?.();
|
|
43348
|
+
}
|
|
43349
|
+
}
|
|
43350
|
+
);
|
|
42285
43351
|
} finally {
|
|
42286
43352
|
running.delete(controller);
|
|
42287
43353
|
if (!closing && !state.claimed && !state.released) {
|
|
@@ -42436,7 +43502,7 @@ function writeResponseHead(response, status, contentType) {
|
|
|
42436
43502
|
"cache-control": "no-cache"
|
|
42437
43503
|
});
|
|
42438
43504
|
}
|
|
42439
|
-
async function pipeResponse(upstream, response, onFailure) {
|
|
43505
|
+
async function pipeResponse(upstream, response, onFailure, onHandoff) {
|
|
42440
43506
|
const contentType = upstream.headers.get("content-type") ?? "application/octet-stream";
|
|
42441
43507
|
if (response.destroyed) {
|
|
42442
43508
|
await upstream.body?.cancel().catch(() => {
|
|
@@ -42444,6 +43510,8 @@ async function pipeResponse(upstream, response, onFailure) {
|
|
|
42444
43510
|
return;
|
|
42445
43511
|
}
|
|
42446
43512
|
writeResponseHead(response, upstream.status, contentType);
|
|
43513
|
+
response.flushHeaders();
|
|
43514
|
+
onHandoff();
|
|
42447
43515
|
if (!upstream.body) {
|
|
42448
43516
|
response.end();
|
|
42449
43517
|
return;
|
|
@@ -43416,7 +44484,7 @@ import { createHash as createHash15, randomBytes as randomBytes6, randomUUID as
|
|
|
43416
44484
|
import { constants as fsConstants2 } from "node:fs";
|
|
43417
44485
|
import { chmod as chmod4, mkdir as mkdir13, open as open10, readFile as readFile11, realpath as realpath4, rename as rename9, stat as stat7, unlink as unlink9 } from "node:fs/promises";
|
|
43418
44486
|
import { basename as basename5, dirname as dirname20, extname as extname2, isAbsolute as isAbsolute3, join as join18, resolve as resolve12 } from "node:path";
|
|
43419
|
-
import { ClaustrumCredentialError as
|
|
44487
|
+
import { ClaustrumCredentialError as ClaustrumCredentialError5, ClaustrumClient as ClaustrumWireClient2, writeEnrollmentTokenFile as writeEnrollmentTokenFile2 } from "@cortexkit/claustrum-client";
|
|
43420
44488
|
|
|
43421
44489
|
// src/common-auth-embedded/fs/lock-constants.js
|
|
43422
44490
|
var WRITER_LOCK_CONSTANTS2 = Object.freeze({
|
|
@@ -44098,7 +45166,7 @@ var RETRYABLE_ENROLLMENT_CODES2 = /* @__PURE__ */ new Set([
|
|
|
44098
45166
|
"pending_queue_full"
|
|
44099
45167
|
]);
|
|
44100
45168
|
function classifyEnrollmentError2(error) {
|
|
44101
|
-
if (!(error instanceof
|
|
45169
|
+
if (!(error instanceof ClaustrumCredentialError5))
|
|
44102
45170
|
return void 0;
|
|
44103
45171
|
if (TERMINAL_ENROLLMENT_CODES2.has(error.code))
|
|
44104
45172
|
return { code: error.code, disposition: "terminal" };
|
|
@@ -50710,7 +51778,7 @@ function createAuthLoader({
|
|
|
50710
51778
|
// through the OLD interceptor after an OAuth add. The wrapper
|
|
50711
51779
|
// matches the host's `LoaderResult.fetch` signature exactly
|
|
50712
51780
|
// (no `this` binding) so behavior is preserved.
|
|
50713
|
-
fetch:
|
|
51781
|
+
fetch: (input2, init) => publishResponse(async (onResponseHandoff) => {
|
|
50714
51782
|
assertOpen();
|
|
50715
51783
|
const authority = await readAuthority2?.() ?? "local";
|
|
50716
51784
|
assertOpen();
|
|
@@ -50724,7 +51792,7 @@ function createAuthLoader({
|
|
|
50724
51792
|
});
|
|
50725
51793
|
const vaultRuntime = await vaultFetchRuntime;
|
|
50726
51794
|
assertOpen();
|
|
50727
|
-
return vaultRuntime.fetch(input2, init);
|
|
51795
|
+
return vaultRuntime.fetch(input2, init, onResponseHandoff);
|
|
50728
51796
|
}
|
|
50729
51797
|
if (localUnavailable) {
|
|
50730
51798
|
return fetchWithoutLocalAccounts(input2, init, fetchImpl);
|
|
@@ -50748,8 +51816,8 @@ function createAuthLoader({
|
|
|
50748
51816
|
return fetchWithoutLocalAccounts(input2, init, fetchImpl);
|
|
50749
51817
|
if (currentRequestSource !== "local" || !fetchRuntime)
|
|
50750
51818
|
throw new Error("The local account runtime is unavailable");
|
|
50751
|
-
return fetchRuntime.fetch(input2, init);
|
|
50752
|
-
}
|
|
51819
|
+
return fetchRuntime.fetch(input2, init, onResponseHandoff);
|
|
51820
|
+
})
|
|
50753
51821
|
};
|
|
50754
51822
|
}
|
|
50755
51823
|
reloadRuntime = async (getAuth) => {
|
|
@@ -51729,9 +52797,11 @@ function createFetchInterceptor(context) {
|
|
|
51729
52797
|
body: { type: "oauth", refresh: "", access: "", expires: 0 }
|
|
51730
52798
|
});
|
|
51731
52799
|
},
|
|
51732
|
-
refreshQuotaAfterSuccess: async (account, intervalMinutes) => {
|
|
52800
|
+
refreshQuotaAfterSuccess: async (account, intervalMinutes, signal) => {
|
|
52801
|
+
signal?.throwIfAborted();
|
|
51733
52802
|
await context.assertAdmission?.();
|
|
51734
|
-
|
|
52803
|
+
signal?.throwIfAborted();
|
|
52804
|
+
await refreshQuotaAfterSuccess(account, intervalMinutes, signal);
|
|
51735
52805
|
}
|
|
51736
52806
|
},
|
|
51737
52807
|
// The trackers the manager selects with: its own for a store-backed
|
|
@@ -51750,7 +52820,7 @@ function createFetchInterceptor(context) {
|
|
|
51750
52820
|
let retired = false;
|
|
51751
52821
|
let retirePromise;
|
|
51752
52822
|
const entering = /* @__PURE__ */ new Set();
|
|
51753
|
-
async function intercept(input2, init) {
|
|
52823
|
+
async function intercept(input2, init, onResponseHandoff) {
|
|
51754
52824
|
await context.assertAdmission?.();
|
|
51755
52825
|
if (disposed) throw new Error("The local request runtime is disposed");
|
|
51756
52826
|
if (accountSource.kind === "pool-file") {
|
|
@@ -51758,9 +52828,9 @@ function createFetchInterceptor(context) {
|
|
|
51758
52828
|
if (disposed) throw new Error("The local request runtime is disposed");
|
|
51759
52829
|
if (!isOAuthAuth(latestAuth)) return upstreamFetch(input2, init);
|
|
51760
52830
|
}
|
|
51761
|
-
return executor.execute(input2, init);
|
|
52831
|
+
return executor.execute(input2, init, { onResponseHandoff });
|
|
51762
52832
|
}
|
|
51763
|
-
async function fetch(input2, init) {
|
|
52833
|
+
async function fetch(input2, init, onResponseHandoff) {
|
|
51764
52834
|
if (disposed) {
|
|
51765
52835
|
return upstreamFetch(input2, init);
|
|
51766
52836
|
}
|
|
@@ -51768,7 +52838,7 @@ function createFetchInterceptor(context) {
|
|
|
51768
52838
|
return upstreamFetch(input2, init);
|
|
51769
52839
|
}
|
|
51770
52840
|
if (retired) throw new Error("The local request runtime is retired");
|
|
51771
|
-
const pending = intercept(input2, init);
|
|
52841
|
+
const pending = intercept(input2, init, onResponseHandoff);
|
|
51772
52842
|
entering.add(pending);
|
|
51773
52843
|
void pending.then(
|
|
51774
52844
|
() => entering.delete(pending),
|