@cortexkit/opencode-openai-auth 1.10.1 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +8 -8
- package/dist/{codex-request-BLzSBegI.d.ts → codex-request-DFeGDzpN.d.ts} +2 -2
- package/dist/index-0kpq9310.js +76 -0
- package/dist/{index-7xqb1m44.js → index-2p3st53v.js} +2 -2
- package/dist/{index-8xgeh2zt.js → index-3x7q1rj8.js} +2 -2
- package/dist/{index-mkda7acs.js → index-4daebegf.js} +1 -1
- package/dist/{index-w37815v4.js → index-4rzatybc.js} +1 -1
- package/dist/{index-2py81t0v.js → index-7at0fc03.js} +2 -2
- package/dist/{index-4gkfz4zp.js → index-afpxnan1.js} +2 -2
- package/dist/{index-r0kv780p.js → index-bxxjwt4q.js} +2 -2
- package/dist/index-cy6km6cz.js +64 -0
- package/dist/{index-ct658ahq.js → index-d5v2rn54.js} +1 -1
- package/dist/{index-hq4gdm6f.js → index-dp68014q.js} +2 -2
- package/dist/index-h2z9jb3g.js +91 -0
- package/dist/{index-dkhy2peg.js → index-smzgsx6x.js} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.js +1 -1
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/rpc/rpc-dir.js +1 -1
- package/dist/sidebar-state.js +1 -1
- package/dist/token-util-e49kkftr.js +1 -0
- package/dist/{token-pd3t5f20.js → token-wgntcjq1.js} +1 -1
- package/dist/tui-preferences.js +1 -1
- package/dist/v2/server.d.ts +1 -1
- package/dist/v2/server.js +2 -2
- package/package.json +4 -4
- package/src/tui-compiled/raw/shared/0f77ebc3c914c9c6-custody.js +26 -15
- package/src/tui-compiled/raw/shared/169b2b4bf30909bc-consumer.js +14 -5
- package/src/tui-compiled/raw/shared/352d228be2832bd4-hub.js +5 -2
- package/src/tui-compiled/raw/shared/94f53cfd572ba4bb-availability.js +2 -0
- package/src/tui-compiled/raw/shared/b9588ad4725c1d10-enrollment.js +7 -0
- package/src/tui-compiled/raw/shared/c97089ed4243981c-host.js +113 -0
- package/src/tui-compiled/raw/shared/e8d3c8da776ef9cd-index.js +2 -1
- package/src/tui-compiled/runtime/shared/0f77ebc3c914c9c6-custody.js +26 -15
- package/src/tui-compiled/runtime/shared/169b2b4bf30909bc-consumer.js +14 -5
- package/src/tui-compiled/runtime/shared/352d228be2832bd4-hub.js +5 -2
- package/src/tui-compiled/runtime/shared/94f53cfd572ba4bb-availability.js +2 -0
- package/src/tui-compiled/runtime/shared/b9588ad4725c1d10-enrollment.js +7 -0
- package/src/tui-compiled/runtime/shared/c97089ed4243981c-host.js +113 -0
- package/src/tui-compiled/runtime/shared/e8d3c8da776ef9cd-index.js +2 -1
- package/dist/index-44b5y56b.js +0 -64
- package/dist/index-7fdcb97f.js +0 -91
- package/dist/index-vpjmexm5.js +0 -76
- package/dist/token-util-807rzwws.js +0 -1
|
@@ -4,6 +4,7 @@ import { createLogger } from "./cc9e0702a752cea7-index.js";
|
|
|
4
4
|
import { ClaustrumUnreachableError, classifyVaultFailure, } from "./94f53cfd572ba4bb-availability.js";
|
|
5
5
|
import { readClaustrumEnrollmentToken } from "./b9588ad4725c1d10-enrollment.js";
|
|
6
6
|
import { ClaustrumConsumerError } from "./ca0fccaba1d87af4-errors.js";
|
|
7
|
+
import { connectVaultHost, hasVaultHost, isVaultHostClient } from "./c97089ed4243981c-host.js";
|
|
7
8
|
import { CUSTODY_PLACEHOLDER_PREFIX } from "./d9d2892a4c371301-host-slot.js";
|
|
8
9
|
import { drainShutdown, shutdownWarning } from "./a670cb7f5987bc1b-shutdown.js";
|
|
9
10
|
import { ScopedUsageReporter, } from "./4ede5af6a878a14e-usage.js";
|
|
@@ -174,11 +175,11 @@ function grantReachOf(listed) {
|
|
|
174
175
|
}
|
|
175
176
|
/**
|
|
176
177
|
* Reads this consumer's vault credentials (list, fetch, 401 report), with the
|
|
177
|
-
* enrollment token as authorization. Used by every host of a
|
|
178
|
-
* physical send asks the vault first while reachable. Only an
|
|
179
|
-
* reuse of the last validated receipt, in memory and
|
|
180
|
-
*
|
|
181
|
-
* still take effect without a
|
|
178
|
+
* enrollment token or the host's grant as authorization. Used by every host of a
|
|
179
|
+
* plugin. Every physical send asks the vault first while reachable. Only an
|
|
180
|
+
* unreachable vault permits reuse of the last validated receipt, in memory and
|
|
181
|
+
* bounded by its expiry. Outside host authority the enrollment token is re-read
|
|
182
|
+
* per operation so revocation and disconnect still take effect without a restart.
|
|
182
183
|
*/
|
|
183
184
|
export class ClaustrumScopedCustody {
|
|
184
185
|
#client;
|
|
@@ -211,6 +212,8 @@ export class ClaustrumScopedCustody {
|
|
|
211
212
|
#onDrainTimeout;
|
|
212
213
|
#disposing;
|
|
213
214
|
constructor(options) {
|
|
215
|
+
if (hasVaultHost() && options.client && !isVaultHostClient(options.client))
|
|
216
|
+
throw new ClaustrumUnreachableError();
|
|
214
217
|
const tokenPath = options.tokenPath;
|
|
215
218
|
if (options.readToken) {
|
|
216
219
|
this.#readToken = options.readToken;
|
|
@@ -218,10 +221,15 @@ export class ClaustrumScopedCustody {
|
|
|
218
221
|
else if (tokenPath) {
|
|
219
222
|
this.#readToken = () => readClaustrumEnrollmentToken(tokenPath);
|
|
220
223
|
}
|
|
224
|
+
else if (hasVaultHost()) {
|
|
225
|
+
this.#readToken = async () => {
|
|
226
|
+
throw new ClaustrumConsumerError('not-enrolled', 'Claustrum enrollment token path is required');
|
|
227
|
+
};
|
|
228
|
+
}
|
|
221
229
|
else {
|
|
222
230
|
throw new ClaustrumConsumerError('not-enrolled', 'Claustrum enrollment token path is required');
|
|
223
231
|
}
|
|
224
|
-
this.#client = options.client;
|
|
232
|
+
this.#client = options.client ?? connectVaultHost(options.pluginId);
|
|
225
233
|
this.#family = options.family;
|
|
226
234
|
this.#parseIdentity = options.parseIdentity;
|
|
227
235
|
this.#requireAssertion = options.requireAssertion ?? false;
|
|
@@ -233,7 +241,7 @@ export class ClaustrumScopedCustody {
|
|
|
233
241
|
this.#usage = new ScopedUsageReporter({
|
|
234
242
|
client: this.#client,
|
|
235
243
|
owns: (id) => this.#usageServed.has(id),
|
|
236
|
-
token: async () => checkedEnrollmentToken(await this.#readToken()),
|
|
244
|
+
token: async () => hasVaultHost() ? '' : checkedEnrollmentToken(await this.#readToken()),
|
|
237
245
|
logger: this.#logger,
|
|
238
246
|
setTimeout: this.#setTimeout,
|
|
239
247
|
clearTimeout: this.#clearTimeout,
|
|
@@ -303,6 +311,9 @@ export class ClaustrumScopedCustody {
|
|
|
303
311
|
}
|
|
304
312
|
async #token(signal) {
|
|
305
313
|
this.#check(signal);
|
|
314
|
+
// The host ignores this empty argument; it never reaches a vault as a token.
|
|
315
|
+
if (hasVaultHost())
|
|
316
|
+
return '';
|
|
306
317
|
if (phaseDiagnostics.hasSubscribers)
|
|
307
318
|
phaseDiagnostics.publish({
|
|
308
319
|
logger: this.#logger,
|
|
@@ -592,7 +603,7 @@ export class ClaustrumScopedCustody {
|
|
|
592
603
|
if (kept.since === null)
|
|
593
604
|
kept.since = this.#now();
|
|
594
605
|
const attempt = Object.freeze(Object.defineProperty({ ...kept.attempt, fromKeptReceipt: true }, 'accessToken', { value: kept.attempt.accessToken, enumerable: false }));
|
|
595
|
-
this.#provenance.set(attempt, token);
|
|
606
|
+
this.#provenance.set(attempt, this.#provenance.get(kept.attempt) ?? { token, client: this.#client });
|
|
596
607
|
this.#keptAttempts.set(attempt, routeId);
|
|
597
608
|
return attempt;
|
|
598
609
|
}
|
|
@@ -673,22 +684,22 @@ export class ClaustrumScopedCustody {
|
|
|
673
684
|
recordVersion: served.recordVersion,
|
|
674
685
|
expiresAtMs,
|
|
675
686
|
}, 'accessToken', { value: accessToken, enumerable: false }));
|
|
676
|
-
this.#provenance.set(attempt, token);
|
|
687
|
+
this.#provenance.set(attempt, { token, client: this.#client });
|
|
677
688
|
return attempt;
|
|
678
689
|
}
|
|
679
690
|
/**
|
|
680
691
|
* Report that a send this consumer actually made was rejected. Only a 401
|
|
681
692
|
* is reported (the vault refuses 429, 402 and 5xx reports), addressed by
|
|
682
693
|
* credential id with the exact record version that send was served, and
|
|
683
|
-
*
|
|
684
|
-
* custody did not issue is refused rather than reported.
|
|
694
|
+
* sent through the client and enrollment token that authorized it. A receipt
|
|
695
|
+
* this custody did not issue is refused rather than reported.
|
|
685
696
|
*/
|
|
686
697
|
async reportFailure(attempt, status, reporterSource) {
|
|
687
698
|
if (status !== 401)
|
|
688
699
|
return;
|
|
689
700
|
this.#check();
|
|
690
|
-
const
|
|
691
|
-
if (!
|
|
701
|
+
const provenance = this.#provenance.get(attempt);
|
|
702
|
+
if (!provenance)
|
|
692
703
|
throw new ClaustrumConsumerError('no-receipt', 'Claustrum failure report requires an original dispatch receipt');
|
|
693
704
|
const keptRoute = this.#keptAttempts.get(attempt);
|
|
694
705
|
if (keptRoute !== undefined) {
|
|
@@ -708,9 +719,9 @@ export class ClaustrumScopedCustody {
|
|
|
708
719
|
const pending = this.#reports.get(attempt);
|
|
709
720
|
if (pending)
|
|
710
721
|
return pending;
|
|
711
|
-
const report = this.#call(() =>
|
|
722
|
+
const report = this.#call(() => provenance.client.reportAuthFailureScoped({
|
|
712
723
|
credentialId: attempt.credentialId,
|
|
713
|
-
enrollmentToken: token,
|
|
724
|
+
enrollmentToken: provenance.token,
|
|
714
725
|
providerStatus: 401,
|
|
715
726
|
recordVersion: attempt.recordVersion,
|
|
716
727
|
reporterSource,
|
|
@@ -4,6 +4,7 @@ import { ClaustrumUnreachableError } from "./94f53cfd572ba4bb-availability.js";
|
|
|
4
4
|
import { ClaustrumScopedCustody, decideScopedRetryAfter401, } from "./0f77ebc3c914c9c6-custody.js";
|
|
5
5
|
import { readClaustrumEnrollmentToken } from "./b9588ad4725c1d10-enrollment.js";
|
|
6
6
|
import { ClaustrumConsumerError } from "./ca0fccaba1d87af4-errors.js";
|
|
7
|
+
import { connectVaultHost, hasVaultHost } from "./c97089ed4243981c-host.js";
|
|
7
8
|
import { acquireInsulaQuotaSource, } from "./d0f0b6be200311af-insula.js";
|
|
8
9
|
import { pendingVaultQuota, retainVaultQuotaWriter } from "./81dddd203f1b92a3-quota-writer.js";
|
|
9
10
|
import { acceptVaultRoute, applyVaultQuota, declineVaultRoute, forgetPendingVaultDiscovery, readVaultRoster, recordVaultAccountQuota, recordVaultQuota, refreshVaultRoster, reorderVaultRoster, vaultRoutingRows, } from "./30f5bc480f31f51c-roster.js";
|
|
@@ -98,6 +99,8 @@ export class ClaustrumConsumer {
|
|
|
98
99
|
return pending;
|
|
99
100
|
}
|
|
100
101
|
async #active() {
|
|
102
|
+
if (hasVaultHost())
|
|
103
|
+
return true;
|
|
101
104
|
return (await this.#options.isCustodyActive?.()) ?? true;
|
|
102
105
|
}
|
|
103
106
|
#wait(pending, signal) {
|
|
@@ -153,7 +156,9 @@ export class ClaustrumConsumer {
|
|
|
153
156
|
#boundedConnect(attempt) {
|
|
154
157
|
const setTimer = this.#options.setTimeoutImpl ?? setTimeout;
|
|
155
158
|
const clearTimer = this.#options.clearTimeoutImpl ?? clearTimeout;
|
|
156
|
-
const pending = this.#options.connect
|
|
159
|
+
const pending = (!hasVaultHost() && this.#options.connect
|
|
160
|
+
? this.#options.connect()
|
|
161
|
+
: Promise.resolve().then(() => connectVaultHost(this.#options.pluginId))).then((client) => {
|
|
157
162
|
if (this.#shutdown.signal.aborted || attempt.timedOut) {
|
|
158
163
|
client.close();
|
|
159
164
|
if (!attempt.timedOut)
|
|
@@ -429,7 +434,8 @@ export class ClaustrumConsumer {
|
|
|
429
434
|
!(await this.#active()))
|
|
430
435
|
return;
|
|
431
436
|
try {
|
|
432
|
-
|
|
437
|
+
if (!hasVaultHost())
|
|
438
|
+
await readClaustrumEnrollmentToken(this.#options.tokenPath);
|
|
433
439
|
await this.#getCustody();
|
|
434
440
|
await this.#insula?.source.refresh((this.#options.now ?? Date.now)());
|
|
435
441
|
}
|
|
@@ -449,7 +455,8 @@ export class ClaustrumConsumer {
|
|
|
449
455
|
!(await this.#active()))
|
|
450
456
|
return undefined;
|
|
451
457
|
try {
|
|
452
|
-
|
|
458
|
+
if (!hasVaultHost())
|
|
459
|
+
await readClaustrumEnrollmentToken(this.#options.tokenPath);
|
|
453
460
|
return this.#normalizeInsulaQuota(receipt.assertedAccountIdentity);
|
|
454
461
|
}
|
|
455
462
|
catch {
|
|
@@ -467,7 +474,8 @@ export class ClaustrumConsumer {
|
|
|
467
474
|
!(await this.#active()))
|
|
468
475
|
return undefined;
|
|
469
476
|
try {
|
|
470
|
-
|
|
477
|
+
if (!hasVaultHost())
|
|
478
|
+
await readClaustrumEnrollmentToken(this.#options.tokenPath);
|
|
471
479
|
const roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
|
|
472
480
|
const row = roster?.rows.find((entry) => entry.routeId === routeId);
|
|
473
481
|
return this.#normalizeInsulaQuota(row?.accountIdentity);
|
|
@@ -482,7 +490,8 @@ export class ClaustrumConsumer {
|
|
|
482
490
|
if (!options || this.#shutdown.signal.aborted || !(await this.#active()))
|
|
483
491
|
return { miss: 'unreachable' };
|
|
484
492
|
try {
|
|
485
|
-
|
|
493
|
+
if (!hasVaultHost())
|
|
494
|
+
await readClaustrumEnrollmentToken(this.#options.tokenPath);
|
|
486
495
|
const roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
|
|
487
496
|
const account = roster?.rows.find((row) => row.routeId === routeId)?.accountIdentity;
|
|
488
497
|
if (!account || !this.#insula)
|
|
@@ -21,6 +21,7 @@ import { createHubMember, DEFAULT_CONNECT_TIMEOUT_MS, } from "./169b2b4bf30909bc
|
|
|
21
21
|
import { ClaustrumScopedCustody, } from "./0f77ebc3c914c9c6-custody.js";
|
|
22
22
|
import { ensureClaustrumPrivateDirectory } from "./b9588ad4725c1d10-enrollment.js";
|
|
23
23
|
import { ClaustrumConsumerError } from "./ca0fccaba1d87af4-errors.js";
|
|
24
|
+
import { connectVaultHost, hasVaultHost } from "./c97089ed4243981c-host.js";
|
|
24
25
|
import { DEFAULT_ROUTE_PREFIX, decodedVaultRoster, forgetPendingVaultDiscovery, isVaultRosterLockRefusal, readVaultRoster, refreshVaultRoster, vaultRosterSeed, } from "./30f5bc480f31f51c-roster.js";
|
|
25
26
|
import { drainShutdown, shutdownWarning } from "./a670cb7f5987bc1b-shutdown.js";
|
|
26
27
|
import { SAFETY_POLL_MS } from "./dc9290c2a7552ba6-watch.js";
|
|
@@ -383,7 +384,9 @@ export class ClaustrumDiscoveryHub {
|
|
|
383
384
|
// that never settles would otherwise hold them all for the hub's life.
|
|
384
385
|
const connectTimeoutMs = this.#options.connectTimeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS;
|
|
385
386
|
let timer;
|
|
386
|
-
const connect = this.#options.connect
|
|
387
|
+
const connect = (!hasVaultHost() && this.#options.connect
|
|
388
|
+
? this.#options.connect()
|
|
389
|
+
: Promise.resolve().then(() => connectVaultHost(this.#options.pluginId))).then((client) => {
|
|
387
390
|
// A connect resolves into its generation only while that generation
|
|
388
391
|
// is current and still wanted; otherwise its client never serves.
|
|
389
392
|
if (entry.timedOut) {
|
|
@@ -567,7 +570,7 @@ export class ClaustrumDiscoveryHub {
|
|
|
567
570
|
* runs the inactive transition; nothing else does.
|
|
568
571
|
*/
|
|
569
572
|
async #readAuthority() {
|
|
570
|
-
const active = (await this.#options.isCustodyActive?.()) ?? true;
|
|
573
|
+
const active = hasVaultHost() || ((await this.#options.isCustodyActive?.()) ?? true);
|
|
571
574
|
if (this.#shutdown.signal.aborted)
|
|
572
575
|
return false;
|
|
573
576
|
const was = this.#active;
|
|
@@ -16,6 +16,8 @@ export const VAULT_FAILURE_CLASSES = Object.freeze({
|
|
|
16
16
|
unavailable: 'unreachable',
|
|
17
17
|
timeout: 'unreachable',
|
|
18
18
|
route_closed: 'unreachable',
|
|
19
|
+
// The daemon refused before forwarding, so the vault never saw the request.
|
|
20
|
+
route_busy: 'unreachable',
|
|
19
21
|
daemon_draining: 'unreachable',
|
|
20
22
|
connection_closed: 'unreachable',
|
|
21
23
|
connection_dropped: 'unreachable',
|
|
@@ -7,6 +7,7 @@ import { FileReadCache } from "./92e38944b51b2405-file-read-cache.js";
|
|
|
7
7
|
import { acquireRefreshFileLock } from "./ec971142548df90e-index.js";
|
|
8
8
|
import { ensurePrivateDirectory as ensureWindowsDirectory, PrivateFileError, readPrivateText, verifySafeDirectory, windowsPrivateFiles, writePrivateAtomic, } from "./375d9cca2def037d-private-files.js";
|
|
9
9
|
import { ClaustrumConsumerError } from "./ca0fccaba1d87af4-errors.js";
|
|
10
|
+
import { hasVaultHost } from "./c97089ed4243981c-host.js";
|
|
10
11
|
const ENROLLMENT_SCHEMA = 1;
|
|
11
12
|
const ENROLLMENT_FILE_MAX_BYTES = 16 * 1024;
|
|
12
13
|
const ENROLLMENT_LOCK_TTL_MS = 30_000;
|
|
@@ -500,6 +501,12 @@ export async function enrollmentAuthority(paths, proposedName) {
|
|
|
500
501
|
}
|
|
501
502
|
return 'local';
|
|
502
503
|
}
|
|
504
|
+
/** Host authority takes precedence without reading any plugin enrollment files. */
|
|
505
|
+
export async function vaultAuthority(paths, proposedName) {
|
|
506
|
+
if (hasVaultHost())
|
|
507
|
+
return 'host';
|
|
508
|
+
return enrollmentAuthority(paths, proposedName);
|
|
509
|
+
}
|
|
503
510
|
/**
|
|
504
511
|
* Read fresh bearer material for one scoped operation; never publish it.
|
|
505
512
|
* Re-reading per operation is what lets an operator reissue a token on disk.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { ClaustrumCredentialError } from "@cortexkit/claustrum-client";
|
|
2
|
+
import { ClaustrumUnreachableError, classifyVaultFailure, } from "./94f53cfd572ba4bb-availability.js";
|
|
3
|
+
export const VAULT_HOST_STATUS = 'Served by Thalamus';
|
|
4
|
+
export const VAULT_HOST_CONNECT_REFUSAL = "This host gets its vault accounts from Thalamus, so it can't connect to the vault itself.";
|
|
5
|
+
// Object identity prevents a native client from carrying the host's empty token argument.
|
|
6
|
+
const hostClients = new WeakSet();
|
|
7
|
+
export function isVaultHostClient(client) {
|
|
8
|
+
return hostClients.has(client);
|
|
9
|
+
}
|
|
10
|
+
/** The spawn marker, not a global installed by another plugin, selects authority. */
|
|
11
|
+
export function hasVaultHost() {
|
|
12
|
+
return process.env.CORTEXKIT_VAULT_HOST === 'thalamus';
|
|
13
|
+
}
|
|
14
|
+
function hostError(error) {
|
|
15
|
+
if (typeof error !== 'object' || error === null)
|
|
16
|
+
return error;
|
|
17
|
+
const value = error;
|
|
18
|
+
if (typeof value.code === 'string' &&
|
|
19
|
+
(value.class === 'transient' ||
|
|
20
|
+
value.class === 'permanent' ||
|
|
21
|
+
value.class === 'auth_required' ||
|
|
22
|
+
value.class === 'context_overflow') &&
|
|
23
|
+
(value.action === 'gone' ||
|
|
24
|
+
value.action === 'reauth' ||
|
|
25
|
+
value.action === 'retry' ||
|
|
26
|
+
value.action === 'reduce_and_retry'))
|
|
27
|
+
return new ClaustrumCredentialError(value.code, value.class, value.action);
|
|
28
|
+
if (value.name === 'ClaustrumUnreachableError' ||
|
|
29
|
+
(typeof value.code === 'string' &&
|
|
30
|
+
classifyVaultFailure(Object.assign(new Error(), { code: value.code })) ===
|
|
31
|
+
'unreachable'))
|
|
32
|
+
return new ClaustrumUnreachableError();
|
|
33
|
+
return error;
|
|
34
|
+
}
|
|
35
|
+
function call(operation) {
|
|
36
|
+
try {
|
|
37
|
+
return operation();
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw hostError(error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function request(operation) {
|
|
44
|
+
try {
|
|
45
|
+
return await operation();
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw hostError(error);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Normalize only the host boundary; native clients keep their strict error identity. */
|
|
52
|
+
function wrapHostClient(client) {
|
|
53
|
+
const watchScoped = client.watchScoped?.bind(client);
|
|
54
|
+
const reportUsageScoped = client.reportUsageScoped?.bind(client);
|
|
55
|
+
return {
|
|
56
|
+
listScoped: (...args) => request(() => client.listScoped(...args)),
|
|
57
|
+
getScoped: (...args) => request(() => client.getScoped(...args)),
|
|
58
|
+
reportAuthFailureScoped: (...args) => request(() => client.reportAuthFailureScoped(...args)),
|
|
59
|
+
close: () => call(() => client.close()),
|
|
60
|
+
...(watchScoped && {
|
|
61
|
+
watchScoped: (...args) => {
|
|
62
|
+
const watch = call(() => watchScoped(...args));
|
|
63
|
+
return {
|
|
64
|
+
stop: () => call(() => watch.stop()),
|
|
65
|
+
closed: request(async () => {
|
|
66
|
+
const end = await watch.closed;
|
|
67
|
+
return end.kind === 'refused' || end.kind === 'transport_lost'
|
|
68
|
+
? { ...end, error: hostError(end.error) }
|
|
69
|
+
: end;
|
|
70
|
+
}),
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
...(reportUsageScoped && {
|
|
75
|
+
reportUsageScoped: (...args) => request(() => reportUsageScoped(...args)),
|
|
76
|
+
}),
|
|
77
|
+
...(client.insula && {
|
|
78
|
+
insula: wrapInsula(client.insula),
|
|
79
|
+
}),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function wrapInsula(transport) {
|
|
83
|
+
const watchUsage = transport.watchUsage?.bind(transport);
|
|
84
|
+
return {
|
|
85
|
+
connectionFile: transport.connectionFile,
|
|
86
|
+
getUsage: () => request(() => transport.getUsage()),
|
|
87
|
+
...(watchUsage && {
|
|
88
|
+
watchUsage: (...args) => {
|
|
89
|
+
const watch = call(() => watchUsage(...args));
|
|
90
|
+
return {
|
|
91
|
+
stop: () => call(() => watch.stop()),
|
|
92
|
+
closed: request(() => watch.closed),
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
}),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/** Read at connect time so a bridge installed after the auth plugin can recover. */
|
|
99
|
+
export function connectVaultHost(pluginId) {
|
|
100
|
+
if (!hasVaultHost() || !pluginId)
|
|
101
|
+
throw new ClaustrumUnreachableError();
|
|
102
|
+
try {
|
|
103
|
+
const accessor = globalThis[Symbol.for('cortexkit.vault')];
|
|
104
|
+
if (typeof accessor !== 'function')
|
|
105
|
+
throw new ClaustrumUnreachableError();
|
|
106
|
+
const client = wrapHostClient(accessor(pluginId));
|
|
107
|
+
hostClients.add(client);
|
|
108
|
+
return client;
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
throw new ClaustrumUnreachableError();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -10,8 +10,9 @@ export { ClaustrumCredentialError, } from "@cortexkit/claustrum-client";
|
|
|
10
10
|
export { ClaustrumUnreachableError, classifyVaultFailure, VAULT_FAILURE_CLASSES, } from "./94f53cfd572ba4bb-availability.js";
|
|
11
11
|
export { ClaustrumConsumer, DEFAULT_CONNECT_TIMEOUT_MS, } from "./169b2b4bf30909bc-consumer.js";
|
|
12
12
|
export { ClaustrumScopedCustody, decideScopedRetryAfter401, isScopedCredentialRotation, KEPT_RECEIPT_MARGIN_MS, SERVING_MARGIN_MS, } from "./0f77ebc3c914c9c6-custody.js";
|
|
13
|
-
export { ClaustrumEnrollmentManager, classifyEnrollmentError, connectClaustrumEnrollmentClient, disconnectClaustrumEnrollment, enrollmentAuthority, enrollmentName, getClaustrumEnrollmentPaths, hostEnrollmentPaths, RETRYABLE_ENROLLMENT_CODES, readClaustrumEnrollmentStatus, readClaustrumEnrollmentToken, resetClaustrumEnrollmentState, TERMINAL_ENROLLMENT_CODES, } from "./b9588ad4725c1d10-enrollment.js";
|
|
13
|
+
export { ClaustrumEnrollmentManager, classifyEnrollmentError, connectClaustrumEnrollmentClient, disconnectClaustrumEnrollment, enrollmentAuthority, enrollmentName, getClaustrumEnrollmentPaths, hostEnrollmentPaths, RETRYABLE_ENROLLMENT_CODES, readClaustrumEnrollmentStatus, readClaustrumEnrollmentToken, resetClaustrumEnrollmentState, TERMINAL_ENROLLMENT_CODES, vaultAuthority, } from "./b9588ad4725c1d10-enrollment.js";
|
|
14
14
|
export { ClaustrumConsumerError, } from "./ca0fccaba1d87af4-errors.js";
|
|
15
|
+
export { connectVaultHost, hasVaultHost, VAULT_HOST_CONNECT_REFUSAL, VAULT_HOST_STATUS, } from "./c97089ed4243981c-host.js";
|
|
15
16
|
export { assertHostSlotMatchesMode, assertNotCustodyPlaceholder, CUSTODY_PLACEHOLDER_PREFIX, classifyHostSlot, custodyPlaceholder, custodyPlaceholderKey, isCustodyPlaceholder, isCustodyPlaceholderValue, } from "./d9d2892a4c371301-host-slot.js";
|
|
16
17
|
export { ClaustrumDiscoveryHub, } from "./352d228be2832bd4-hub.js";
|
|
17
18
|
export { acquireInsulaQuotaSource, } from "./d0f0b6be200311af-insula.js";
|
|
@@ -4,6 +4,7 @@ import { createLogger } from "./cc9e0702a752cea7-index.js";
|
|
|
4
4
|
import { ClaustrumUnreachableError, classifyVaultFailure, } from "./94f53cfd572ba4bb-availability.js";
|
|
5
5
|
import { readClaustrumEnrollmentToken } from "./b9588ad4725c1d10-enrollment.js";
|
|
6
6
|
import { ClaustrumConsumerError } from "./ca0fccaba1d87af4-errors.js";
|
|
7
|
+
import { connectVaultHost, hasVaultHost, isVaultHostClient } from "./c97089ed4243981c-host.js";
|
|
7
8
|
import { CUSTODY_PLACEHOLDER_PREFIX } from "./d9d2892a4c371301-host-slot.js";
|
|
8
9
|
import { drainShutdown, shutdownWarning } from "./a670cb7f5987bc1b-shutdown.js";
|
|
9
10
|
import { ScopedUsageReporter, } from "./4ede5af6a878a14e-usage.js";
|
|
@@ -174,11 +175,11 @@ function grantReachOf(listed) {
|
|
|
174
175
|
}
|
|
175
176
|
/**
|
|
176
177
|
* Reads this consumer's vault credentials (list, fetch, 401 report), with the
|
|
177
|
-
* enrollment token as authorization. Used by every host of a
|
|
178
|
-
* physical send asks the vault first while reachable. Only an
|
|
179
|
-
* reuse of the last validated receipt, in memory and
|
|
180
|
-
*
|
|
181
|
-
* still take effect without a
|
|
178
|
+
* enrollment token or the host's grant as authorization. Used by every host of a
|
|
179
|
+
* plugin. Every physical send asks the vault first while reachable. Only an
|
|
180
|
+
* unreachable vault permits reuse of the last validated receipt, in memory and
|
|
181
|
+
* bounded by its expiry. Outside host authority the enrollment token is re-read
|
|
182
|
+
* per operation so revocation and disconnect still take effect without a restart.
|
|
182
183
|
*/
|
|
183
184
|
export class ClaustrumScopedCustody {
|
|
184
185
|
#client;
|
|
@@ -211,6 +212,8 @@ export class ClaustrumScopedCustody {
|
|
|
211
212
|
#onDrainTimeout;
|
|
212
213
|
#disposing;
|
|
213
214
|
constructor(options) {
|
|
215
|
+
if (hasVaultHost() && options.client && !isVaultHostClient(options.client))
|
|
216
|
+
throw new ClaustrumUnreachableError();
|
|
214
217
|
const tokenPath = options.tokenPath;
|
|
215
218
|
if (options.readToken) {
|
|
216
219
|
this.#readToken = options.readToken;
|
|
@@ -218,10 +221,15 @@ export class ClaustrumScopedCustody {
|
|
|
218
221
|
else if (tokenPath) {
|
|
219
222
|
this.#readToken = () => readClaustrumEnrollmentToken(tokenPath);
|
|
220
223
|
}
|
|
224
|
+
else if (hasVaultHost()) {
|
|
225
|
+
this.#readToken = async () => {
|
|
226
|
+
throw new ClaustrumConsumerError('not-enrolled', 'Claustrum enrollment token path is required');
|
|
227
|
+
};
|
|
228
|
+
}
|
|
221
229
|
else {
|
|
222
230
|
throw new ClaustrumConsumerError('not-enrolled', 'Claustrum enrollment token path is required');
|
|
223
231
|
}
|
|
224
|
-
this.#client = options.client;
|
|
232
|
+
this.#client = options.client ?? connectVaultHost(options.pluginId);
|
|
225
233
|
this.#family = options.family;
|
|
226
234
|
this.#parseIdentity = options.parseIdentity;
|
|
227
235
|
this.#requireAssertion = options.requireAssertion ?? false;
|
|
@@ -233,7 +241,7 @@ export class ClaustrumScopedCustody {
|
|
|
233
241
|
this.#usage = new ScopedUsageReporter({
|
|
234
242
|
client: this.#client,
|
|
235
243
|
owns: (id) => this.#usageServed.has(id),
|
|
236
|
-
token: async () => checkedEnrollmentToken(await this.#readToken()),
|
|
244
|
+
token: async () => hasVaultHost() ? '' : checkedEnrollmentToken(await this.#readToken()),
|
|
237
245
|
logger: this.#logger,
|
|
238
246
|
setTimeout: this.#setTimeout,
|
|
239
247
|
clearTimeout: this.#clearTimeout,
|
|
@@ -303,6 +311,9 @@ export class ClaustrumScopedCustody {
|
|
|
303
311
|
}
|
|
304
312
|
async #token(signal) {
|
|
305
313
|
this.#check(signal);
|
|
314
|
+
// The host ignores this empty argument; it never reaches a vault as a token.
|
|
315
|
+
if (hasVaultHost())
|
|
316
|
+
return '';
|
|
306
317
|
if (phaseDiagnostics.hasSubscribers)
|
|
307
318
|
phaseDiagnostics.publish({
|
|
308
319
|
logger: this.#logger,
|
|
@@ -592,7 +603,7 @@ export class ClaustrumScopedCustody {
|
|
|
592
603
|
if (kept.since === null)
|
|
593
604
|
kept.since = this.#now();
|
|
594
605
|
const attempt = Object.freeze(Object.defineProperty({ ...kept.attempt, fromKeptReceipt: true }, 'accessToken', { value: kept.attempt.accessToken, enumerable: false }));
|
|
595
|
-
this.#provenance.set(attempt, token);
|
|
606
|
+
this.#provenance.set(attempt, this.#provenance.get(kept.attempt) ?? { token, client: this.#client });
|
|
596
607
|
this.#keptAttempts.set(attempt, routeId);
|
|
597
608
|
return attempt;
|
|
598
609
|
}
|
|
@@ -673,22 +684,22 @@ export class ClaustrumScopedCustody {
|
|
|
673
684
|
recordVersion: served.recordVersion,
|
|
674
685
|
expiresAtMs,
|
|
675
686
|
}, 'accessToken', { value: accessToken, enumerable: false }));
|
|
676
|
-
this.#provenance.set(attempt, token);
|
|
687
|
+
this.#provenance.set(attempt, { token, client: this.#client });
|
|
677
688
|
return attempt;
|
|
678
689
|
}
|
|
679
690
|
/**
|
|
680
691
|
* Report that a send this consumer actually made was rejected. Only a 401
|
|
681
692
|
* is reported (the vault refuses 429, 402 and 5xx reports), addressed by
|
|
682
693
|
* credential id with the exact record version that send was served, and
|
|
683
|
-
*
|
|
684
|
-
* custody did not issue is refused rather than reported.
|
|
694
|
+
* sent through the client and enrollment token that authorized it. A receipt
|
|
695
|
+
* this custody did not issue is refused rather than reported.
|
|
685
696
|
*/
|
|
686
697
|
async reportFailure(attempt, status, reporterSource) {
|
|
687
698
|
if (status !== 401)
|
|
688
699
|
return;
|
|
689
700
|
this.#check();
|
|
690
|
-
const
|
|
691
|
-
if (!
|
|
701
|
+
const provenance = this.#provenance.get(attempt);
|
|
702
|
+
if (!provenance)
|
|
692
703
|
throw new ClaustrumConsumerError('no-receipt', 'Claustrum failure report requires an original dispatch receipt');
|
|
693
704
|
const keptRoute = this.#keptAttempts.get(attempt);
|
|
694
705
|
if (keptRoute !== undefined) {
|
|
@@ -708,9 +719,9 @@ export class ClaustrumScopedCustody {
|
|
|
708
719
|
const pending = this.#reports.get(attempt);
|
|
709
720
|
if (pending)
|
|
710
721
|
return pending;
|
|
711
|
-
const report = this.#call(() =>
|
|
722
|
+
const report = this.#call(() => provenance.client.reportAuthFailureScoped({
|
|
712
723
|
credentialId: attempt.credentialId,
|
|
713
|
-
enrollmentToken: token,
|
|
724
|
+
enrollmentToken: provenance.token,
|
|
714
725
|
providerStatus: 401,
|
|
715
726
|
recordVersion: attempt.recordVersion,
|
|
716
727
|
reporterSource,
|
|
@@ -4,6 +4,7 @@ import { ClaustrumUnreachableError } from "./94f53cfd572ba4bb-availability.js";
|
|
|
4
4
|
import { ClaustrumScopedCustody, decideScopedRetryAfter401, } from "./0f77ebc3c914c9c6-custody.js";
|
|
5
5
|
import { readClaustrumEnrollmentToken } from "./b9588ad4725c1d10-enrollment.js";
|
|
6
6
|
import { ClaustrumConsumerError } from "./ca0fccaba1d87af4-errors.js";
|
|
7
|
+
import { connectVaultHost, hasVaultHost } from "./c97089ed4243981c-host.js";
|
|
7
8
|
import { acquireInsulaQuotaSource, } from "./d0f0b6be200311af-insula.js";
|
|
8
9
|
import { pendingVaultQuota, retainVaultQuotaWriter } from "./81dddd203f1b92a3-quota-writer.js";
|
|
9
10
|
import { acceptVaultRoute, applyVaultQuota, declineVaultRoute, forgetPendingVaultDiscovery, readVaultRoster, recordVaultAccountQuota, recordVaultQuota, refreshVaultRoster, reorderVaultRoster, vaultRoutingRows, } from "./30f5bc480f31f51c-roster.js";
|
|
@@ -98,6 +99,8 @@ export class ClaustrumConsumer {
|
|
|
98
99
|
return pending;
|
|
99
100
|
}
|
|
100
101
|
async #active() {
|
|
102
|
+
if (hasVaultHost())
|
|
103
|
+
return true;
|
|
101
104
|
return (await this.#options.isCustodyActive?.()) ?? true;
|
|
102
105
|
}
|
|
103
106
|
#wait(pending, signal) {
|
|
@@ -153,7 +156,9 @@ export class ClaustrumConsumer {
|
|
|
153
156
|
#boundedConnect(attempt) {
|
|
154
157
|
const setTimer = this.#options.setTimeoutImpl ?? setTimeout;
|
|
155
158
|
const clearTimer = this.#options.clearTimeoutImpl ?? clearTimeout;
|
|
156
|
-
const pending = this.#options.connect
|
|
159
|
+
const pending = (!hasVaultHost() && this.#options.connect
|
|
160
|
+
? this.#options.connect()
|
|
161
|
+
: Promise.resolve().then(() => connectVaultHost(this.#options.pluginId))).then((client) => {
|
|
157
162
|
if (this.#shutdown.signal.aborted || attempt.timedOut) {
|
|
158
163
|
client.close();
|
|
159
164
|
if (!attempt.timedOut)
|
|
@@ -429,7 +434,8 @@ export class ClaustrumConsumer {
|
|
|
429
434
|
!(await this.#active()))
|
|
430
435
|
return;
|
|
431
436
|
try {
|
|
432
|
-
|
|
437
|
+
if (!hasVaultHost())
|
|
438
|
+
await readClaustrumEnrollmentToken(this.#options.tokenPath);
|
|
433
439
|
await this.#getCustody();
|
|
434
440
|
await this.#insula?.source.refresh((this.#options.now ?? Date.now)());
|
|
435
441
|
}
|
|
@@ -449,7 +455,8 @@ export class ClaustrumConsumer {
|
|
|
449
455
|
!(await this.#active()))
|
|
450
456
|
return undefined;
|
|
451
457
|
try {
|
|
452
|
-
|
|
458
|
+
if (!hasVaultHost())
|
|
459
|
+
await readClaustrumEnrollmentToken(this.#options.tokenPath);
|
|
453
460
|
return this.#normalizeInsulaQuota(receipt.assertedAccountIdentity);
|
|
454
461
|
}
|
|
455
462
|
catch {
|
|
@@ -467,7 +474,8 @@ export class ClaustrumConsumer {
|
|
|
467
474
|
!(await this.#active()))
|
|
468
475
|
return undefined;
|
|
469
476
|
try {
|
|
470
|
-
|
|
477
|
+
if (!hasVaultHost())
|
|
478
|
+
await readClaustrumEnrollmentToken(this.#options.tokenPath);
|
|
471
479
|
const roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
|
|
472
480
|
const row = roster?.rows.find((entry) => entry.routeId === routeId);
|
|
473
481
|
return this.#normalizeInsulaQuota(row?.accountIdentity);
|
|
@@ -482,7 +490,8 @@ export class ClaustrumConsumer {
|
|
|
482
490
|
if (!options || this.#shutdown.signal.aborted || !(await this.#active()))
|
|
483
491
|
return { miss: 'unreachable' };
|
|
484
492
|
try {
|
|
485
|
-
|
|
493
|
+
if (!hasVaultHost())
|
|
494
|
+
await readClaustrumEnrollmentToken(this.#options.tokenPath);
|
|
486
495
|
const roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
|
|
487
496
|
const account = roster?.rows.find((row) => row.routeId === routeId)?.accountIdentity;
|
|
488
497
|
if (!account || !this.#insula)
|
|
@@ -21,6 +21,7 @@ import { createHubMember, DEFAULT_CONNECT_TIMEOUT_MS, } from "./169b2b4bf30909bc
|
|
|
21
21
|
import { ClaustrumScopedCustody, } from "./0f77ebc3c914c9c6-custody.js";
|
|
22
22
|
import { ensureClaustrumPrivateDirectory } from "./b9588ad4725c1d10-enrollment.js";
|
|
23
23
|
import { ClaustrumConsumerError } from "./ca0fccaba1d87af4-errors.js";
|
|
24
|
+
import { connectVaultHost, hasVaultHost } from "./c97089ed4243981c-host.js";
|
|
24
25
|
import { DEFAULT_ROUTE_PREFIX, decodedVaultRoster, forgetPendingVaultDiscovery, isVaultRosterLockRefusal, readVaultRoster, refreshVaultRoster, vaultRosterSeed, } from "./30f5bc480f31f51c-roster.js";
|
|
25
26
|
import { drainShutdown, shutdownWarning } from "./a670cb7f5987bc1b-shutdown.js";
|
|
26
27
|
import { SAFETY_POLL_MS } from "./dc9290c2a7552ba6-watch.js";
|
|
@@ -383,7 +384,9 @@ export class ClaustrumDiscoveryHub {
|
|
|
383
384
|
// that never settles would otherwise hold them all for the hub's life.
|
|
384
385
|
const connectTimeoutMs = this.#options.connectTimeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS;
|
|
385
386
|
let timer;
|
|
386
|
-
const connect = this.#options.connect
|
|
387
|
+
const connect = (!hasVaultHost() && this.#options.connect
|
|
388
|
+
? this.#options.connect()
|
|
389
|
+
: Promise.resolve().then(() => connectVaultHost(this.#options.pluginId))).then((client) => {
|
|
387
390
|
// A connect resolves into its generation only while that generation
|
|
388
391
|
// is current and still wanted; otherwise its client never serves.
|
|
389
392
|
if (entry.timedOut) {
|
|
@@ -567,7 +570,7 @@ export class ClaustrumDiscoveryHub {
|
|
|
567
570
|
* runs the inactive transition; nothing else does.
|
|
568
571
|
*/
|
|
569
572
|
async #readAuthority() {
|
|
570
|
-
const active = (await this.#options.isCustodyActive?.()) ?? true;
|
|
573
|
+
const active = hasVaultHost() || ((await this.#options.isCustodyActive?.()) ?? true);
|
|
571
574
|
if (this.#shutdown.signal.aborted)
|
|
572
575
|
return false;
|
|
573
576
|
const was = this.#active;
|
|
@@ -16,6 +16,8 @@ export const VAULT_FAILURE_CLASSES = Object.freeze({
|
|
|
16
16
|
unavailable: 'unreachable',
|
|
17
17
|
timeout: 'unreachable',
|
|
18
18
|
route_closed: 'unreachable',
|
|
19
|
+
// The daemon refused before forwarding, so the vault never saw the request.
|
|
20
|
+
route_busy: 'unreachable',
|
|
19
21
|
daemon_draining: 'unreachable',
|
|
20
22
|
connection_closed: 'unreachable',
|
|
21
23
|
connection_dropped: 'unreachable',
|
|
@@ -7,6 +7,7 @@ import { FileReadCache } from "./92e38944b51b2405-file-read-cache.js";
|
|
|
7
7
|
import { acquireRefreshFileLock } from "./ec971142548df90e-index.js";
|
|
8
8
|
import { ensurePrivateDirectory as ensureWindowsDirectory, PrivateFileError, readPrivateText, verifySafeDirectory, windowsPrivateFiles, writePrivateAtomic, } from "./375d9cca2def037d-private-files.js";
|
|
9
9
|
import { ClaustrumConsumerError } from "./ca0fccaba1d87af4-errors.js";
|
|
10
|
+
import { hasVaultHost } from "./c97089ed4243981c-host.js";
|
|
10
11
|
const ENROLLMENT_SCHEMA = 1;
|
|
11
12
|
const ENROLLMENT_FILE_MAX_BYTES = 16 * 1024;
|
|
12
13
|
const ENROLLMENT_LOCK_TTL_MS = 30_000;
|
|
@@ -500,6 +501,12 @@ export async function enrollmentAuthority(paths, proposedName) {
|
|
|
500
501
|
}
|
|
501
502
|
return 'local';
|
|
502
503
|
}
|
|
504
|
+
/** Host authority takes precedence without reading any plugin enrollment files. */
|
|
505
|
+
export async function vaultAuthority(paths, proposedName) {
|
|
506
|
+
if (hasVaultHost())
|
|
507
|
+
return 'host';
|
|
508
|
+
return enrollmentAuthority(paths, proposedName);
|
|
509
|
+
}
|
|
503
510
|
/**
|
|
504
511
|
* Read fresh bearer material for one scoped operation; never publish it.
|
|
505
512
|
* Re-reading per operation is what lets an operator reissue a token on disk.
|