@cortexkit/opencode-openai-auth 1.11.0 → 1.13.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.
Files changed (53) hide show
  1. package/dist/bin.js +8 -8
  2. package/dist/{codex-request-DFeGDzpN.d.ts → codex-request-Bu2sjxQn.d.ts} +1 -0
  3. package/dist/{index-4rzatybc.js → index-0bh5fs56.js} +1 -1
  4. package/dist/{index-d5v2rn54.js → index-2ccfywax.js} +1 -1
  5. package/dist/index-2g95z7kb.js +64 -0
  6. package/dist/index-4s50rsec.js +8 -0
  7. package/dist/index-7s8g79dd.js +91 -0
  8. package/dist/{index-2p3st53v.js → index-cs0tey1r.js} +2 -2
  9. package/dist/index-khqwa7g2.js +76 -0
  10. package/dist/{index-dp68014q.js → index-p8v28mh9.js} +2 -2
  11. package/dist/{index-smzgsx6x.js → index-r8y79mzp.js} +1 -1
  12. package/dist/{index-7at0fc03.js → index-rhe4jm5t.js} +2 -2
  13. package/dist/{index-bxxjwt4q.js → index-th0bzvpn.js} +2 -2
  14. package/dist/{index-4daebegf.js → index-tzrf3ax2.js} +1 -1
  15. package/dist/{index-afpxnan1.js → index-zmerz2yv.js} +2 -2
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.js +1 -1
  18. package/dist/rpc/port-file.js +1 -1
  19. package/dist/rpc/protocol.js +1 -1
  20. package/dist/rpc/rpc-client.js +1 -1
  21. package/dist/rpc/rpc-dir.js +1 -1
  22. package/dist/sidebar-state.js +1 -1
  23. package/dist/{token-wgntcjq1.js → token-2qht8n50.js} +1 -1
  24. package/dist/token-util-20g3fwxd.js +1 -0
  25. package/dist/tui-preferences.js +1 -1
  26. package/dist/v2/server.d.ts +1 -1
  27. package/dist/v2/server.js +3 -3
  28. package/package.json +4 -3
  29. package/src/tui-compiled/raw/shared/0f77ebc3c914c9c6-custody.js +89 -31
  30. package/src/tui-compiled/raw/shared/4825e03209d6ae3e-with-lock.js +19 -13
  31. package/src/tui-compiled/raw/shared/549daf371622c304-index.tsx +49 -607
  32. package/src/tui-compiled/raw/shared/723b00f96290a097-lock-record.js +55 -0
  33. package/src/tui-compiled/raw/shared/94f53cfd572ba4bb-availability.js +9 -1
  34. package/src/tui-compiled/raw/shared/a75d0d866c227b3f-index.tsx +681 -0
  35. package/src/tui-compiled/raw/shared/b9588ad4725c1d10-enrollment.js +33 -2
  36. package/src/tui-compiled/raw/shared/c97089ed4243981c-host.js +11 -7
  37. package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +148 -92
  38. package/src/tui-compiled/raw/shared/e8d3c8da776ef9cd-index.js +1 -1
  39. package/src/tui-compiled/runtime/shared/0f77ebc3c914c9c6-custody.js +89 -31
  40. package/src/tui-compiled/runtime/shared/4825e03209d6ae3e-with-lock.js +19 -13
  41. package/src/tui-compiled/runtime/shared/549daf371622c304-index.js +36 -674
  42. package/src/tui-compiled/runtime/shared/723b00f96290a097-lock-record.js +55 -0
  43. package/src/tui-compiled/runtime/shared/94f53cfd572ba4bb-availability.js +9 -1
  44. package/src/tui-compiled/runtime/shared/a75d0d866c227b3f-index.js +678 -0
  45. package/src/tui-compiled/runtime/shared/b9588ad4725c1d10-enrollment.js +33 -2
  46. package/src/tui-compiled/runtime/shared/c97089ed4243981c-host.js +11 -7
  47. package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +148 -92
  48. package/src/tui-compiled/runtime/shared/e8d3c8da776ef9cd-index.js +1 -1
  49. package/dist/index-0kpq9310.js +0 -76
  50. package/dist/index-3x7q1rj8.js +0 -8
  51. package/dist/index-cy6km6cz.js +0 -64
  52. package/dist/index-h2z9jb3g.js +0 -91
  53. package/dist/token-util-e49kkftr.js +0 -1
@@ -238,8 +238,15 @@ export class ClaustrumScopedCustody {
238
238
  this.#warnShutdown = shutdownWarning(this.#logger);
239
239
  this.#setTimeout = options.setTimeoutImpl ?? setTimeout;
240
240
  this.#clearTimeout = options.clearTimeoutImpl ?? clearTimeout;
241
+ const currentClient = () => this.#client;
241
242
  this.#usage = new ScopedUsageReporter({
242
- client: this.#client,
243
+ client: {
244
+ // Queued readings follow a replacement without losing client capability checks.
245
+ get reportUsageScoped() {
246
+ const client = currentClient();
247
+ return client.reportUsageScoped?.bind(client);
248
+ },
249
+ },
243
250
  owns: (id) => this.#usageServed.has(id),
244
251
  token: async () => hasVaultHost() ? '' : checkedEnrollmentToken(await this.#readToken()),
245
252
  logger: this.#logger,
@@ -247,6 +254,24 @@ export class ClaustrumScopedCustody {
247
254
  clearTimeout: this.#clearTimeout,
248
255
  });
249
256
  }
257
+ /**
258
+ * Replace the connection to the same vault without discarding receipts or
259
+ * their enrollment tokens. Open roster watches restart on the new client;
260
+ * their existing handles remain usable. Passing the current client does nothing.
261
+ * Neither client is closed here: the caller closes the old one, and custody's
262
+ * close()/dispose() still closes the client it holds at shutdown.
263
+ * While hosted, next must come from connectVaultHost, as in the constructor.
264
+ */
265
+ replaceClient(next) {
266
+ this.#check();
267
+ if (next === this.#client)
268
+ return;
269
+ if (hasVaultHost() && !isVaultHostClient(next))
270
+ throw new ClaustrumUnreachableError();
271
+ this.#client = next;
272
+ for (const watch of this.#watches)
273
+ watch.restart();
274
+ }
250
275
  /** A watch losing its transport is the same outage as an unreachable read. */
251
276
  transportLost(error) {
252
277
  if (this.#closed || this.#outage)
@@ -255,7 +280,9 @@ export class ClaustrumScopedCustody {
255
280
  this.#outageError =
256
281
  error instanceof ClaustrumCredentialError
257
282
  ? error
258
- : new ClaustrumUnreachableError();
283
+ : new ClaustrumUnreachableError(error instanceof ClaustrumUnreachableError
284
+ ? error.reason
285
+ : undefined);
259
286
  this.#logger.warn('serving kept vault receipt', { reason: 'unreachable' });
260
287
  this.#scheduleProbe();
261
288
  }
@@ -367,7 +394,7 @@ export class ClaustrumScopedCustody {
367
394
  if (error instanceof ClaustrumCredentialError)
368
395
  throw error;
369
396
  if (classifyVaultFailure(error) === 'unreachable')
370
- throw new ClaustrumUnreachableError();
397
+ throw new ClaustrumUnreachableError(error instanceof ClaustrumUnreachableError ? error.reason : undefined);
371
398
  throw new ClaustrumConsumerError('unavailable', 'Claustrum scoped operation unavailable');
372
399
  }
373
400
  finally {
@@ -603,7 +630,7 @@ export class ClaustrumScopedCustody {
603
630
  if (kept.since === null)
604
631
  kept.since = this.#now();
605
632
  const attempt = Object.freeze(Object.defineProperty({ ...kept.attempt, fromKeptReceipt: true }, 'accessToken', { value: kept.attempt.accessToken, enumerable: false }));
606
- this.#provenance.set(attempt, this.#provenance.get(kept.attempt) ?? { token, client: this.#client });
633
+ this.#provenance.set(attempt, this.#provenance.get(kept.attempt) ?? { token });
607
634
  this.#keptAttempts.set(attempt, routeId);
608
635
  return attempt;
609
636
  }
@@ -684,15 +711,15 @@ export class ClaustrumScopedCustody {
684
711
  recordVersion: served.recordVersion,
685
712
  expiresAtMs,
686
713
  }, 'accessToken', { value: accessToken, enumerable: false }));
687
- this.#provenance.set(attempt, { token, client: this.#client });
714
+ this.#provenance.set(attempt, { token });
688
715
  return attempt;
689
716
  }
690
717
  /**
691
718
  * Report that a send this consumer actually made was rejected. Only a 401
692
719
  * is reported (the vault refuses 429, 402 and 5xx reports), addressed by
693
720
  * credential id with the exact record version that send was served, and
694
- * sent through the client and enrollment token that authorized it. A receipt
695
- * this custody did not issue is refused rather than reported.
721
+ * sent through the current client with the enrollment token that authorized
722
+ * it. A receipt this custody did not issue is refused rather than reported.
696
723
  */
697
724
  async reportFailure(attempt, status, reporterSource) {
698
725
  if (status !== 401)
@@ -719,7 +746,7 @@ export class ClaustrumScopedCustody {
719
746
  const pending = this.#reports.get(attempt);
720
747
  if (pending)
721
748
  return pending;
722
- const report = this.#call(() => provenance.client.reportAuthFailureScoped({
749
+ const report = this.#call(() => this.#client.reportAuthFailureScoped({
723
750
  credentialId: attempt.credentialId,
724
751
  enrollmentToken: provenance.token,
725
752
  providerStatus: 401,
@@ -761,36 +788,67 @@ export class ClaustrumScopedCustody {
761
788
  */
762
789
  watchRoster(options) {
763
790
  this.#check();
764
- const watch = new ScopedRosterWatch({
765
- client: this.#client,
766
- enrollmentToken: () => this.#token(),
767
- view: options.view ?? (() => this.#discoveredView),
768
- discover: async (view) => {
769
- await options.onView(view);
770
- },
771
- onRefused: (error) => {
772
- // Apply a refused watch as discover() applies a refused account
773
- // listing: every kept receipt is dropped.
774
- this.listFailed(error);
775
- options.onRefused?.(error);
791
+ const currentView = options.view ?? (() => this.#discoveredView);
792
+ let discovering;
793
+ let watch;
794
+ const create = (resubscribed = false) => {
795
+ const opened = new ScopedRosterWatch({
796
+ client: this.#client,
797
+ enrollmentToken: () => this.#token(),
798
+ // Nothing observed the gap between clients, even if the view is unchanged.
799
+ view: () => (resubscribed ? undefined : currentView()),
800
+ discover: async (view) => {
801
+ // An old watch's discovery may still be committing the host's roster.
802
+ while (discovering)
803
+ await discovering.catch(() => { });
804
+ if (watch !== opened)
805
+ return;
806
+ resubscribed = false;
807
+ discovering = Promise.resolve().then(() => options.onView(view));
808
+ try {
809
+ await discovering;
810
+ }
811
+ finally {
812
+ discovering = undefined;
813
+ }
814
+ },
815
+ onRefused: (error) => {
816
+ // Apply a refused watch as discover() applies a refused account
817
+ // listing: every kept receipt is dropped.
818
+ this.listFailed(error);
819
+ options.onRefused?.(error);
820
+ },
821
+ onTransportLost: () => this.transportLost(),
822
+ onReachable: () => this.reachable(),
823
+ onError: options.onError,
824
+ onMode: options.onMode,
825
+ logger: this.#logger,
826
+ now: this.#now,
827
+ setTimeoutImpl: this.#setTimeout,
828
+ clearTimeoutImpl: this.#clearTimeout,
829
+ });
830
+ return opened;
831
+ };
832
+ watch = create();
833
+ const tracked = {
834
+ restart: () => {
835
+ const previousMode = watch.mode;
836
+ watch.stop();
837
+ watch = create(true);
838
+ if (previousMode !== watch.mode)
839
+ options.onMode?.(watch.mode);
840
+ watch.start();
776
841
  },
777
- onTransportLost: () => this.transportLost(),
778
- onReachable: () => this.reachable(),
779
- onError: options.onError,
780
- onMode: options.onMode,
781
- logger: this.#logger,
782
- now: this.#now,
783
- setTimeoutImpl: this.#setTimeout,
784
- clearTimeoutImpl: this.#clearTimeout,
785
- });
786
- this.#watches.add(watch);
842
+ stop: () => watch.stop(),
843
+ };
844
+ this.#watches.add(tracked);
787
845
  watch.start();
788
846
  return {
789
847
  get mode() {
790
848
  return watch.mode;
791
849
  },
792
850
  close: () => {
793
- this.#watches.delete(watch);
851
+ this.#watches.delete(tracked);
794
852
  watch.stop();
795
853
  },
796
854
  };
@@ -1,5 +1,6 @@
1
1
  import { join, resolve } from "node:path";
2
- import { isWindowsSharingViolation, } from "./375d9cca2def037d-private-files.js";
2
+ import { isWindowsAccessDeniedCreate, isWindowsAccessDeniedRead, } from "./723b00f96290a097-lock-record.js";
3
+ import { isWindowsSharingViolation, windowsPrivateFiles, } from "./375d9cca2def037d-private-files.js";
3
4
  import { acquireRefreshFileLock } from "./e8cd4929507508d8-refresh-file-lock.js";
4
5
  export function lockPathFor(target, name) {
5
6
  return `${target}.${name}.lock`;
@@ -20,19 +21,23 @@ export class LockOwnershipError extends Error {
20
21
  this.details = details;
21
22
  }
22
23
  }
23
- function isChangingLockRead(error, target, name) {
24
- if (!isWindowsSharingViolation(error) ||
25
- (error.stage !== 'read' && error.stage !== 'verify'))
26
- return false;
24
+ function isChangingLockRecord(error, target, name) {
27
25
  const path = resolve(lockPathFor(target, name));
28
- return error.path === path || error.path === join(path, 'owner.json');
26
+ const paths = [path, join(path, 'owner.json')];
27
+ return (((isWindowsSharingViolation(error) ||
28
+ isWindowsAccessDeniedRead(error, paths)) &&
29
+ (error.stage === 'read' || error.stage === 'verify') &&
30
+ paths.includes(error.path)) ||
31
+ (windowsPrivateFiles &&
32
+ (isWindowsAccessDeniedCreate(error, [path], 'create') ||
33
+ isWindowsAccessDeniedCreate(error, [`${path}.evicting`], 'directory-create'))));
29
34
  }
30
35
  export async function withLock(target, options, fn) {
31
36
  const started = performance.now();
37
+ let changingRecordError;
32
38
  for (;;) {
33
39
  options.signal?.throwIfAborted();
34
40
  let lock;
35
- let changingReadError;
36
41
  try {
37
42
  lock = await acquireRefreshFileLock({
38
43
  path: target,
@@ -44,14 +49,15 @@ export async function withLock(target, options, fn) {
44
49
  ? { onRenewalTimer: options.onRenewalTimer }
45
50
  : {}),
46
51
  });
52
+ changingRecordError = undefined;
47
53
  }
48
54
  catch (error) {
49
- if (!isChangingLockRead(error, target, options.name))
55
+ if (!isChangingLockRecord(error, target, options.name))
50
56
  throw error;
51
- // Sharing violations (32) and delete-pending opens (303) do not reveal
52
- // ownership or expiry. Retry exclusive creation, never infer a stale lock.
57
+ // Ambiguous reads or creates reveal neither ownership nor expiry. Retry
58
+ // exclusive creation within the same deadline, never infer staleness from IO.
53
59
  lock = null;
54
- changingReadError = error;
60
+ changingRecordError ??= error;
55
61
  }
56
62
  if (lock) {
57
63
  try {
@@ -65,8 +71,8 @@ export async function withLock(target, options, fn) {
65
71
  const remaining = options.timeoutMs - (performance.now() - started);
66
72
  if (remaining <= 0) {
67
73
  // Keep persistent native IO failures distinguishable from a live holder.
68
- if (changingReadError)
69
- throw changingReadError;
74
+ if (changingRecordError)
75
+ throw changingRecordError;
70
76
  throw new LockContentionError({
71
77
  target,
72
78
  name: options.name,