@cortexkit/opencode-openai-auth 1.7.0 → 1.8.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 +9 -9
- package/dist/{codex-request-CN4rD2kf.d.ts → codex-request-DohnbsFR.d.ts} +69 -21
- package/dist/index-3v868rnp.js +63 -0
- package/dist/{index-7zy4vdd3.js → index-5d4y47h8.js} +2 -2
- package/dist/{index-yayz83vv.js → index-5dxpsa3t.js} +2 -2
- package/dist/{index-dr93b3g6.js → index-8pk9savd.js} +6 -6
- package/dist/{index-g08eptzm.js → index-cbcka7sa.js} +1 -1
- package/dist/{index-p9vnmnzr.js → index-cxstwq02.js} +1 -1
- package/dist/{index-r4avvxf0.js → index-dtwgf694.js} +1 -1
- package/dist/index-dzaqj248.js +2 -0
- package/dist/index-g3d50jz0.js +74 -0
- package/dist/{index-2e2kqmsy.js → index-n7fxqgfb.js} +2 -2
- package/dist/{index-b5459de4.js → index-th47aqez.js} +2 -2
- package/dist/index-tvban5vp.js +91 -0
- package/dist/{index-jaqm1xda.js → index-x7jzcvqy.js} +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -1
- package/dist/{port-file-8ElfwDcq.d.ts → port-file-DQ7-ItDK.d.ts} +1 -1
- package/dist/{protocol-BeeDdtpa.d.ts → protocol-CVQK-d3j.d.ts} +1 -1
- package/dist/rpc/port-file.d.ts +4 -2
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.d.ts +1 -1
- package/dist/rpc/protocol.js +1 -1
- package/dist/rpc/rpc-client.d.ts +1 -1
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/rpc/rpc-dir.js +1 -1
- package/dist/{rpc-client-DlR9a0_7.d.ts → rpc-client-BQfIKrXI.d.ts} +3 -3
- package/dist/{sidebar-state-DHsZ9axt.d.ts → sidebar-state-B1cq68UB.d.ts} +4 -4
- package/dist/sidebar-state.d.ts +1 -1
- package/dist/sidebar-state.js +1 -1
- package/dist/{token-511npvw8.js → token-gy442bba.js} +1 -1
- package/dist/token-util-rxy0p234.js +1 -0
- package/dist/tui-preferences.js +1 -1
- package/dist/tui.d.ts +3 -3
- package/dist/v2/server.d.ts +15 -7
- package/dist/v2/server.js +2 -2
- package/package.json +2 -2
- package/src/tui-compiled/raw/shared/0f77ebc3c914c9c6-custody.js +95 -11
- package/src/tui-compiled/raw/shared/169b2b4bf30909bc-consumer.js +320 -35
- package/src/tui-compiled/raw/shared/30f5bc480f31f51c-roster.js +187 -12
- package/src/tui-compiled/raw/shared/352d228be2832bd4-hub.js +988 -0
- package/src/tui-compiled/raw/shared/458b934e92490331-mutate.js +4 -0
- package/src/tui-compiled/raw/shared/81dddd203f1b92a3-quota-writer.js +34 -12
- package/src/tui-compiled/raw/shared/836fc615de6afbd9-settings.js +16 -6
- package/src/tui-compiled/raw/shared/88b7fc40900fb003-commit-interval.js +18 -0
- package/src/tui-compiled/raw/shared/92e38944b51b2405-file-read-cache.js +57 -0
- package/src/tui-compiled/raw/shared/a670cb7f5987bc1b-shutdown.js +42 -0
- package/src/tui-compiled/raw/shared/b9588ad4725c1d10-enrollment.js +37 -12
- package/src/tui-compiled/raw/shared/c852a15cfe489d12-pool.js +1 -1
- package/src/tui-compiled/raw/shared/c911dbb64c9d85c7-quota-writer.js +27 -13
- package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +20 -11
- package/src/tui-compiled/raw/shared/e8d3c8da776ef9cd-index.js +37 -4
- package/src/tui-compiled/runtime/shared/0f77ebc3c914c9c6-custody.js +95 -11
- package/src/tui-compiled/runtime/shared/169b2b4bf30909bc-consumer.js +320 -35
- package/src/tui-compiled/runtime/shared/30f5bc480f31f51c-roster.js +187 -12
- package/src/tui-compiled/runtime/shared/352d228be2832bd4-hub.js +988 -0
- package/src/tui-compiled/runtime/shared/458b934e92490331-mutate.js +4 -0
- package/src/tui-compiled/runtime/shared/81dddd203f1b92a3-quota-writer.js +34 -12
- package/src/tui-compiled/runtime/shared/836fc615de6afbd9-settings.js +16 -6
- package/src/tui-compiled/runtime/shared/88b7fc40900fb003-commit-interval.js +18 -0
- package/src/tui-compiled/runtime/shared/92e38944b51b2405-file-read-cache.js +57 -0
- package/src/tui-compiled/runtime/shared/a670cb7f5987bc1b-shutdown.js +42 -0
- package/src/tui-compiled/runtime/shared/b9588ad4725c1d10-enrollment.js +37 -12
- package/src/tui-compiled/runtime/shared/c852a15cfe489d12-pool.js +1 -1
- package/src/tui-compiled/runtime/shared/c911dbb64c9d85c7-quota-writer.js +27 -13
- package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +20 -11
- package/src/tui-compiled/runtime/shared/e8d3c8da776ef9cd-index.js +37 -4
- package/dist/index-0p3cbtwq.js +0 -2
- package/dist/index-apkavdvq.js +0 -90
- package/dist/index-qg2syg0r.js +0 -65
- package/dist/index-se9ykks8.js +0 -69
- package/dist/token-util-jsw1zdc6.js +0 -1
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
+
import { stat } from "node:fs/promises";
|
|
2
3
|
import { resolve } from "node:path";
|
|
3
|
-
import { acquireRefreshFileLock, LockContentionError, withLock, writeJsonAtomic, } from "./ec971142548df90e-index.js";
|
|
4
|
+
import { acquireRefreshFileLock, LockContentionError, LockOwnershipError, lockPathFor, PrivateFileError, withLock, writeJsonAtomic, } from "./ec971142548df90e-index.js";
|
|
4
5
|
import { readPrivateText, windowsPrivateFiles } from "./375d9cca2def037d-private-files.js";
|
|
5
6
|
import { decodeQuotaMap, isQuotaObservation, mergeQuotaObservation, } from "./d5a8f1061ee2f114-index.js";
|
|
6
7
|
import { ClaustrumConsumerError } from "./ca0fccaba1d87af4-errors.js";
|
|
7
8
|
import { acceptAccount, declineAccount, isDeclined, } from "./7c140680fc81be92-interlock.js";
|
|
8
|
-
import { enqueueVaultQuota, pendingVaultQuota, } from "./81dddd203f1b92a3-quota-writer.js";
|
|
9
|
+
import { enqueueVaultQuota, hasPendingVaultQuota, pendingVaultQuota, } from "./81dddd203f1b92a3-quota-writer.js";
|
|
9
10
|
export { drainVaultQuota } from "./81dddd203f1b92a3-quota-writer.js";
|
|
11
|
+
/** Declines and account order of `roster`, and nothing else of it. */
|
|
12
|
+
export function vaultRosterSeed(roster) {
|
|
13
|
+
return {
|
|
14
|
+
declined: roster.declined.map((entry) => ({ ...entry })),
|
|
15
|
+
order: roster.rows.flatMap((row) => memberIds(row).map((credentialId) => ({
|
|
16
|
+
credentialId,
|
|
17
|
+
...(row.accountIdentity !== undefined && {
|
|
18
|
+
accountIdentity: row.accountIdentity,
|
|
19
|
+
}),
|
|
20
|
+
}))),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** Where a projected row falls in the seed's order; unknown rows go last. */
|
|
24
|
+
function seedIndex(seed, row) {
|
|
25
|
+
const ids = memberIds(row);
|
|
26
|
+
const byAccount = row.accountIdentity === undefined
|
|
27
|
+
? -1
|
|
28
|
+
: seed.order.findIndex((entry) => entry.accountIdentity === row.accountIdentity);
|
|
29
|
+
const index = byAccount >= 0
|
|
30
|
+
? byAccount
|
|
31
|
+
: seed.order.findIndex((entry) => ids.includes(entry.credentialId));
|
|
32
|
+
return index >= 0 ? index : Infinity;
|
|
33
|
+
}
|
|
10
34
|
export const DEFAULT_ROUTE_PREFIX = 'vault:';
|
|
11
35
|
function hash(value) {
|
|
12
36
|
return createHash('sha256').update(value).digest('hex');
|
|
@@ -47,8 +71,9 @@ export function projectVaultRoster(previous, inventory, options = {}) {
|
|
|
47
71
|
const prefix = options.routePrefix ?? DEFAULT_ROUTE_PREFIX;
|
|
48
72
|
const reserved = options.reservedRouteIds ?? new Set();
|
|
49
73
|
const previousRows = previous?.rows ?? [];
|
|
74
|
+
const seed = previous ? undefined : options.seed;
|
|
50
75
|
// Declines follow the account and outlive its records, so none is pruned.
|
|
51
|
-
const declined = [...(previous?.declined ?? [])];
|
|
76
|
+
const declined = [...(previous?.declined ?? seed?.declined ?? [])];
|
|
52
77
|
const complete = inventory.skipped.length === 0;
|
|
53
78
|
const listed = new Set(inventory.credentials.map((credential) => credential.credentialId));
|
|
54
79
|
const rejectedIds = new Set(inventory.skipped.flatMap((record) => record.credentialId === undefined ? [] : [record.credentialId]));
|
|
@@ -146,6 +171,11 @@ export function projectVaultRoster(previous, inventory, options = {}) {
|
|
|
146
171
|
...(!chosen.claimed && identity !== undefined && { unclaimed: true }),
|
|
147
172
|
},
|
|
148
173
|
});
|
|
174
|
+
// With no previous roster every row is new; a seed from another key
|
|
175
|
+
// sorts them by that key's order instead of by credential id.
|
|
176
|
+
const pushed = projected.at(-1);
|
|
177
|
+
if (seed && pushed)
|
|
178
|
+
pushed.previousIndex = seedIndex(seed, pushed.row);
|
|
149
179
|
}
|
|
150
180
|
// An account the reply does not account for keeps its last good projection:
|
|
151
181
|
// a rejected record must not read as the account having been removed. A
|
|
@@ -293,6 +323,14 @@ function decodeRoster(value) {
|
|
|
293
323
|
declined,
|
|
294
324
|
};
|
|
295
325
|
}
|
|
326
|
+
/**
|
|
327
|
+
* `roster` as `readVaultRoster` decodes it from the file that holds it, so a
|
|
328
|
+
* committed roster and a later read of its file compare equal. Package
|
|
329
|
+
* internal: not exported from `/claustrum`.
|
|
330
|
+
*/
|
|
331
|
+
export function decodedVaultRoster(roster) {
|
|
332
|
+
return decodeRoster(JSON.parse(JSON.stringify(roster)));
|
|
333
|
+
}
|
|
296
334
|
export async function readVaultRoster(path) {
|
|
297
335
|
let text;
|
|
298
336
|
try {
|
|
@@ -560,6 +598,102 @@ const pendingDiscoveries = new Map();
|
|
|
560
598
|
export function forgetPendingVaultDiscovery(path) {
|
|
561
599
|
pendingDiscoveries.delete(resolve(path));
|
|
562
600
|
}
|
|
601
|
+
/**
|
|
602
|
+
* Whether `error` from a roster commit at `path` means another writer had the
|
|
603
|
+
* roster at that moment, not that the commit itself failed: the discovery
|
|
604
|
+
* lease was busy before any roster existed, the write lock stayed busy, or a
|
|
605
|
+
* lock this commit held was lost. On Windows the same lock steps can reject
|
|
606
|
+
* with a PrivateFileError instead (a lock file that could not be read or
|
|
607
|
+
* replaced while another process held it), so a PrivateFileError naming one
|
|
608
|
+
* of this roster's lock files counts the same on every OS.
|
|
609
|
+
*/
|
|
610
|
+
export function isVaultRosterLockRefusal(path, error) {
|
|
611
|
+
const target = resolve(path);
|
|
612
|
+
if (error instanceof ClaustrumConsumerError)
|
|
613
|
+
return error.kind === 'roster-busy';
|
|
614
|
+
if (error instanceof LockContentionError ||
|
|
615
|
+
error instanceof LockOwnershipError)
|
|
616
|
+
return resolve(error.details.target) === target;
|
|
617
|
+
if (error instanceof PrivateFileError) {
|
|
618
|
+
const failed = resolve(error.path);
|
|
619
|
+
return [WRITE_LOCK.name, DISCOVERY_LEASE.name].some((name) => {
|
|
620
|
+
const lock = lockPathFor(target, name);
|
|
621
|
+
// The lock file itself, its eviction marker and the temporary files
|
|
622
|
+
// its owner record is staged in all start with the lock path.
|
|
623
|
+
return failed === lock || failed.startsWith(`${lock}.`);
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
return false;
|
|
627
|
+
}
|
|
628
|
+
const UNLOCKED_READ_ATTEMPTS = 4;
|
|
629
|
+
/**
|
|
630
|
+
* What identifies one version of the file at `path`: the roster is always
|
|
631
|
+
* replaced by a rename, so any write gives it a different inode, and an
|
|
632
|
+
* in-place rewrite a different size or modification time. Undefined when it
|
|
633
|
+
* cannot be inspected, which callers must read as 'may have changed'.
|
|
634
|
+
*/
|
|
635
|
+
async function fileStamp(path) {
|
|
636
|
+
try {
|
|
637
|
+
const { dev, ino, size, mtimeMs } = await stat(path);
|
|
638
|
+
return { dev, ino, size, mtimeMs };
|
|
639
|
+
}
|
|
640
|
+
catch {
|
|
641
|
+
return undefined;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
/** Whether two `fileStamp` readings are of the same file version. */
|
|
645
|
+
function sameFileStamp(left, right) {
|
|
646
|
+
return (left !== undefined &&
|
|
647
|
+
right !== undefined &&
|
|
648
|
+
left.dev === right.dev &&
|
|
649
|
+
left.ino === right.ino &&
|
|
650
|
+
left.size === right.size &&
|
|
651
|
+
left.mtimeMs === right.mtimeMs);
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Whether a roster list that lands unlocked would write exactly the file at
|
|
655
|
+
* `path`. `overlay` names what this process holds besides the file: `target` is
|
|
656
|
+
* the file's own roster, which the locked commit compares against, and `local`,
|
|
657
|
+
* when different, is that roster plus unwritten quota readings, which must
|
|
658
|
+
* equal the commit's result too. Both must equal `next(target)`'s bytes, which
|
|
659
|
+
* is the write the commit would make; any difference, a missing or unreadable
|
|
660
|
+
* file, or a read that a concurrent reader keeps changing all mean 'commit'.
|
|
661
|
+
*/
|
|
662
|
+
async function readUnlockedCommitTarget(path, overlay, next) {
|
|
663
|
+
for (let attempt = 0; attempt < UNLOCKED_READ_ATTEMPTS; attempt++) {
|
|
664
|
+
// Roster files are replaced by rename, so each attempt reads one whole
|
|
665
|
+
// file either way.
|
|
666
|
+
const before = await fileStamp(path);
|
|
667
|
+
const current = await readVaultRoster(path);
|
|
668
|
+
let target;
|
|
669
|
+
let local;
|
|
670
|
+
let changed;
|
|
671
|
+
try {
|
|
672
|
+
;
|
|
673
|
+
({ target, local } = overlay(current));
|
|
674
|
+
const written = JSON.stringify(next(target));
|
|
675
|
+
changed =
|
|
676
|
+
JSON.stringify(target) !== written ||
|
|
677
|
+
(local !== undefined && JSON.stringify(local) !== written);
|
|
678
|
+
}
|
|
679
|
+
catch {
|
|
680
|
+
return 'commit';
|
|
681
|
+
}
|
|
682
|
+
// No lock was taken, so another writer may have replaced the file while
|
|
683
|
+
// it was being projected. The answer must describe the file as it is now,
|
|
684
|
+
// otherwise a later list of the same roster would find it changed again.
|
|
685
|
+
if (!sameFileStamp(before, await fileStamp(path)))
|
|
686
|
+
continue;
|
|
687
|
+
if (changed)
|
|
688
|
+
return 'commit';
|
|
689
|
+
// Quota readings this process enqueued while the file was being projected
|
|
690
|
+
// are not part of `current`, and a list that returns unchanged while they
|
|
691
|
+
// wait would be the only chance to serve them as this list's roster. They
|
|
692
|
+
// keep their own commit either way, so this path takes the locked one.
|
|
693
|
+
return hasPendingVaultQuota(path) ? 'commit' : 'unchanged';
|
|
694
|
+
}
|
|
695
|
+
return 'commit';
|
|
696
|
+
}
|
|
563
697
|
/**
|
|
564
698
|
* Discover and commit the roster. The lease covers the list call and the
|
|
565
699
|
* commit, not just the write: an opaque view cannot tell a delayed old reply
|
|
@@ -567,7 +701,8 @@ export function forgetPendingVaultDiscovery(path) {
|
|
|
567
701
|
* failed list, or custody switching off mid-run, never writes anything; a
|
|
568
702
|
* peer holding the lease means its last committed roster is served instead.
|
|
569
703
|
* A write-lock timeout keeps the discovered inventory for the next poll,
|
|
570
|
-
* unless a peer has superseded its base view in the meantime.
|
|
704
|
+
* unless a peer has superseded its base view in the meantime. A list that
|
|
705
|
+
* would write the file the roster already holds takes no write lock at all.
|
|
571
706
|
*/
|
|
572
707
|
export async function refreshVaultRoster(options) {
|
|
573
708
|
options.signal?.throwIfAborted();
|
|
@@ -589,10 +724,11 @@ export async function refreshVaultRoster(options) {
|
|
|
589
724
|
return persisted;
|
|
590
725
|
}
|
|
591
726
|
const key = resolve(options.path);
|
|
727
|
+
const listedOver = options.listedOver;
|
|
592
728
|
let discovered;
|
|
593
729
|
try {
|
|
594
730
|
const previous = await readVaultRoster(options.path);
|
|
595
|
-
const pending = pendingDiscoveries.get(key);
|
|
731
|
+
const pending = listedOver ? undefined : pendingDiscoveries.get(key);
|
|
596
732
|
// Opaque view cursors cannot be ordered. Reuse a discovery only while no
|
|
597
733
|
// peer has committed a different view since it was read.
|
|
598
734
|
discovered =
|
|
@@ -606,20 +742,58 @@ export async function refreshVaultRoster(options) {
|
|
|
606
742
|
};
|
|
607
743
|
pendingDiscoveries.delete(key);
|
|
608
744
|
const { inventory } = discovered;
|
|
609
|
-
|
|
745
|
+
// Called, not awaited: a caller noting the list here may wait for this
|
|
746
|
+
// roster's write lock, and this refresh decides below whether it needs it.
|
|
747
|
+
void options.onInventory?.(inventory);
|
|
610
748
|
options.signal?.throwIfAborted();
|
|
749
|
+
const projection = typeof options.projection === 'function'
|
|
750
|
+
? options.projection()
|
|
751
|
+
: options.projection;
|
|
752
|
+
const next = (current) => projectVaultRoster(current, inventory, projection);
|
|
753
|
+
const isActive = async () => {
|
|
754
|
+
options.signal?.throwIfAborted();
|
|
755
|
+
await lease.assertOwned();
|
|
756
|
+
return active();
|
|
757
|
+
};
|
|
758
|
+
// The write lock costs a lock file, an eviction marker and staging files in
|
|
759
|
+
// the roster's directory on every poll, so it is skipped when the list
|
|
760
|
+
// would write the file that is already there. The read deciding that takes
|
|
761
|
+
// no lock: a writer that commits between the read and this decision only
|
|
762
|
+
// makes our comparison stale, and a stale comparison never writes (the
|
|
763
|
+
// commit below judges the file again under the lock). Only equality with
|
|
764
|
+
// every byte the commit would write skips; every other answer commits.
|
|
765
|
+
const decision = await readUnlockedCommitTarget(options.path, (current) => {
|
|
766
|
+
// A hub member listed over a base view of its file: the file's own view
|
|
767
|
+
// is what the commit compares, so the overlay is the plain file. The
|
|
768
|
+
// locked commit below still applies the base-view rule.
|
|
769
|
+
if (listedOver)
|
|
770
|
+
return { target: current };
|
|
771
|
+
// This process's unwritten quota readings are part of the roster it
|
|
772
|
+
// serves, so a list that matches everything but them still commits.
|
|
773
|
+
const local = pendingVaultQuota(options.path, current);
|
|
774
|
+
return { target: current, ...(local !== current && { local }) };
|
|
775
|
+
}, next);
|
|
776
|
+
if (decision === 'unchanged') {
|
|
777
|
+
if (!(await isActive()))
|
|
778
|
+
return undefined;
|
|
779
|
+
// Returned as a later read of the file: that is what today's locked
|
|
780
|
+
// unchanged commit returns, and memory keeps only what was committed.
|
|
781
|
+
return await readVaultRoster(options.path);
|
|
782
|
+
}
|
|
611
783
|
return await mutateVaultRoster(options.path, async (current) => {
|
|
612
784
|
if (!(await active()))
|
|
613
785
|
return { result: undefined };
|
|
614
786
|
options.signal?.throwIfAborted();
|
|
615
787
|
await lease.assertOwned();
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
const
|
|
621
|
-
|
|
788
|
+
if (listedOver &&
|
|
789
|
+
current?.view !== listedOver.view &&
|
|
790
|
+
current?.view !== inventory.view)
|
|
791
|
+
return { result: current };
|
|
792
|
+
const projected = next(current);
|
|
793
|
+
const changed = JSON.stringify(current) !== JSON.stringify(projected);
|
|
794
|
+
return { ...(changed && { next: projected }), result: projected };
|
|
622
795
|
}, {
|
|
796
|
+
signal: options.signal,
|
|
623
797
|
beforePublish: async () => {
|
|
624
798
|
options.signal?.throwIfAborted();
|
|
625
799
|
await lease.assertOwned();
|
|
@@ -629,6 +803,7 @@ export async function refreshVaultRoster(options) {
|
|
|
629
803
|
catch (error) {
|
|
630
804
|
if (error instanceof LockContentionError &&
|
|
631
805
|
discovered &&
|
|
806
|
+
!listedOver &&
|
|
632
807
|
!options.signal?.aborted &&
|
|
633
808
|
(await active()))
|
|
634
809
|
pendingDiscoveries.set(key, discovered);
|