@cortexkit/opencode-antigravity-auth 3.0.19 → 3.0.21

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 (90) hide show
  1. package/README.md +3 -1
  2. package/dist/cli.js +277 -150
  3. package/dist/cli.js.map +3 -3
  4. package/dist/cli.meta.json +43 -23
  5. package/dist/index.js +331 -204
  6. package/dist/index.js.map +3 -3
  7. package/dist/index.meta.json +43 -23
  8. package/dist/server.js +344 -217
  9. package/dist/server.js.map +3 -3
  10. package/dist/server.meta.json +1 -1
  11. package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +10 -0
  12. package/dist/src/common-auth-embedded/claustrum/consumer.js +25 -0
  13. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +6 -2
  14. package/dist/src/common-auth-embedded/claustrum/custody.js +45 -6
  15. package/dist/src/common-auth-embedded/claustrum/hub.d.ts +3 -1
  16. package/dist/src/common-auth-embedded/claustrum/hub.js +75 -6
  17. package/dist/src/common-auth-embedded/claustrum/insula.js +6 -0
  18. package/dist/src/common-auth-embedded/claustrum/roster.js +1 -1
  19. package/dist/src/common-auth-embedded/fs/refresh-file-lock.d.ts +2 -1
  20. package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +3 -1
  21. package/dist/src/common-auth-embedded/fs/with-lock.js +1 -1
  22. package/dist/src/common-auth-embedded/opencode2/index.d.ts +1 -1
  23. package/dist/src/common-auth-embedded/opencode2/install.d.ts +4 -3
  24. package/dist/src/common-auth-embedded/opencode2/install.js +144 -17
  25. package/dist/src/common-auth-embedded/opencode2/types.d.ts +52 -1
  26. package/dist/src/common-auth-embedded/quota-sidebar/index.d.ts +86 -0
  27. package/dist/src/common-auth-embedded/quota-sidebar/index.tsx +630 -0
  28. package/dist/src/common-auth-embedded/source-output.json +73 -53
  29. package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
  30. package/dist/src/ga/tui/host-ga.js +2 -3
  31. package/dist/src/ga/tui/host-ga.js.map +1 -1
  32. package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
  33. package/dist/src/server.d.ts +4 -4
  34. package/dist/src/server.js +4 -4
  35. package/dist/src/tui/quota-layout.d.ts +4 -58
  36. package/dist/src/tui/quota-layout.d.ts.map +1 -1
  37. package/dist/src/tui/quota-layout.js +4 -90
  38. package/dist/src/tui/quota-layout.js.map +1 -1
  39. package/dist/src/tui/sidebar-frame.d.ts +4 -35
  40. package/dist/src/tui/sidebar-frame.d.ts.map +1 -1
  41. package/dist/src/tui/sidebar-frame.js +91 -171
  42. package/dist/src/tui/sidebar-frame.js.map +1 -1
  43. package/dist/src/tui.js +3 -3
  44. package/dist/src/tui.js.map +1 -1
  45. package/dist/tui-build-map.json +27 -13
  46. package/dist/tui-ga-build-map.json +28 -13
  47. package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +10 -0
  48. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +6 -2
  49. package/dist/types/src/common-auth-embedded/claustrum/hub.d.ts +3 -1
  50. package/dist/types/src/common-auth-embedded/fs/refresh-file-lock.d.ts +2 -1
  51. package/dist/types/src/common-auth-embedded/opencode2/index.d.ts +1 -1
  52. package/dist/types/src/common-auth-embedded/opencode2/install.d.ts +4 -3
  53. package/dist/types/src/common-auth-embedded/opencode2/types.d.ts +52 -1
  54. package/dist/types/src/server.d.ts +4 -4
  55. package/package.json +3 -3
  56. package/src/common-auth-embedded/claustrum/consumer.d.ts +10 -0
  57. package/src/common-auth-embedded/claustrum/consumer.js +25 -0
  58. package/src/common-auth-embedded/claustrum/custody.d.ts +6 -2
  59. package/src/common-auth-embedded/claustrum/custody.js +45 -6
  60. package/src/common-auth-embedded/claustrum/hub.d.ts +3 -1
  61. package/src/common-auth-embedded/claustrum/hub.js +75 -6
  62. package/src/common-auth-embedded/claustrum/insula.js +6 -0
  63. package/src/common-auth-embedded/claustrum/roster.js +1 -1
  64. package/src/common-auth-embedded/fs/refresh-file-lock.d.ts +2 -1
  65. package/src/common-auth-embedded/fs/refresh-file-lock.js +3 -1
  66. package/src/common-auth-embedded/fs/with-lock.js +1 -1
  67. package/src/common-auth-embedded/opencode2/index.d.ts +1 -1
  68. package/src/common-auth-embedded/opencode2/install.d.ts +4 -3
  69. package/src/common-auth-embedded/opencode2/install.js +144 -17
  70. package/src/common-auth-embedded/opencode2/types.d.ts +52 -1
  71. package/src/common-auth-embedded/quota-sidebar/index.d.ts +86 -0
  72. package/src/common-auth-embedded/quota-sidebar/index.tsx +630 -0
  73. package/src/common-auth-embedded/source-output.json +73 -53
  74. package/src/tui-compiled/common-auth-embedded/quota-sidebar/index.js +666 -0
  75. package/src/tui-compiled/tui/quota-layout.js +5 -330
  76. package/src/tui-compiled/tui/sidebar-frame.js +241 -503
  77. package/src/tui-compiled/tui.js +3 -3
  78. package/src/tui-ga-compiled/host-ga.js +2 -3
  79. package/src/tui-ga-compiled/shared/ced204104a639c9c-sidebar-frame.js +241 -503
  80. package/src/tui-ga-compiled/shared/dd4c9e1a907f8ef0-quota-layout.js +5 -330
  81. package/src/tui-ga-compiled/shared/e4ec36f367492969-index.js +666 -0
  82. package/src/tui-ga-raw/host-ga.tsx +2 -3
  83. package/src/tui-ga-raw/shared/ced204104a639c9c-sidebar-frame.tsx +209 -419
  84. package/src/tui-ga-raw/shared/dd4c9e1a907f8ef0-quota-layout.tsx +10 -301
  85. package/src/tui-ga-raw/shared/e4ec36f367492969-index.tsx +630 -0
  86. package/src/tui-raw/common-auth-embedded/quota-sidebar/index.tsx +630 -0
  87. package/src/tui-raw/tui/quota-layout.tsx +10 -301
  88. package/src/tui-raw/tui/sidebar-frame.tsx +209 -419
  89. package/src/tui-raw/tui.tsx +3 -3
  90. package/src/tui.tsx +3 -3
@@ -122,9 +122,10 @@ function applyHeaderEditsTo(target, edits) {
122
122
  * compares the host-prepared secret exactly, then selects a fresh attempt only
123
123
  * for an owned send. Request-object attribution therefore needs no attempt
124
124
  * header. Frames are owned by the latest handshake of their session and kind;
125
- * retry runs only when the session's latest transport was owned and the session
126
- * has never mixed owned and foreign transports. The host's retry hook has no
127
- * request identity, so a mixed session must keep the host's retry decision.
125
+ * retry runs only when the session's latest transport was owned. The host's
126
+ * retry hook has no request identity, so a session that has mixed owned and
127
+ * foreign transports leaves failover and holds to the host. Identity-preserving
128
+ * retries through `retrySameAccount` do not select an account and remain allowed.
128
129
  */
129
130
  export async function installOpenCode2Auth(ctx, adapter, options = {}) {
130
131
  const { providerID } = adapter;
@@ -230,13 +231,31 @@ export async function installOpenCode2Auth(ctx, adapter, options = {}) {
230
231
  });
231
232
  }
232
233
  };
234
+ const releaseSameAccount = async (next) => {
235
+ try {
236
+ await adapter.dropSameAccountRetry?.({
237
+ ...next.input,
238
+ accountId: next.accountId,
239
+ });
240
+ }
241
+ catch (error) {
242
+ warn('opencode2 auth dropSameAccountRetry threw; the request is unaffected', {
243
+ sessionID: next.input.sessionID,
244
+ error: describe(error),
245
+ });
246
+ }
247
+ };
248
+ const releaseRetry = async (pending) => {
249
+ if (pending.next)
250
+ await releaseChoice(pending.next);
251
+ if (pending.sameAccount)
252
+ await releaseSameAccount(pending.sameAccount);
253
+ };
233
254
  const discardPending = (key) => {
234
255
  const pending = pendingRetries.get(key);
235
256
  pendingRetries.delete(key);
236
- if (pending?.next) {
237
- const next = pending.next;
238
- void inChoiceOrder(pending.sessionID, () => releaseChoice(next));
239
- }
257
+ if (pending)
258
+ void inChoiceOrder(pending.sessionID, () => releaseRetry(pending));
240
259
  };
241
260
  const emit = async (event, payload) => {
242
261
  const set = listeners.get(event);
@@ -380,13 +399,17 @@ export async function installOpenCode2Auth(ctx, adapter, options = {}) {
380
399
  };
381
400
  const select = async (scope, hook, assertActive, transport) => {
382
401
  const key = keyOf(scope.sessionID, scope.kind);
383
- const { input, accountId } = await afterChoiceWork(scope.sessionID, async () => {
402
+ const { input, accountId, sameAccountRetry } = await afterChoiceWork(scope.sessionID, async () => {
384
403
  assertActive();
385
404
  const retried = pendingRetries.get(key);
386
405
  pendingRetries.delete(key);
387
406
  const previousAccountId = retried?.accountId ?? newestOf(key)?.accountId;
388
407
  supersede(key);
389
408
  const next = retried?.next;
409
+ const sameAccount = retried?.sameAccount;
410
+ const sameRoute = sameAccount !== undefined &&
411
+ sameAccount.input.modelID === scope.modelID &&
412
+ sameAccount.input.agent === scope.agent;
390
413
  const matches = next !== undefined &&
391
414
  next.input.modelID === scope.modelID &&
392
415
  next.input.agent === scope.agent;
@@ -400,11 +423,17 @@ export async function installOpenCode2Auth(ctx, adapter, options = {}) {
400
423
  await inChoiceOrder(scope.sessionID, () => releaseChoice(next));
401
424
  assertActive();
402
425
  }
403
- const choice = matches
404
- ? next.accountId
405
- : await adapter.chooseAccount(input);
426
+ if (sameAccount && !sameRoute) {
427
+ await inChoiceOrder(scope.sessionID, () => releaseSameAccount(sameAccount));
428
+ assertActive();
429
+ }
430
+ const choice = sameRoute
431
+ ? sameAccount.accountId
432
+ : matches
433
+ ? next.accountId
434
+ : await adapter.chooseAccount(input);
406
435
  const accountId = typeof choice === 'string' ? choice : undefined;
407
- return { input, accountId };
436
+ return { input, accountId, sameAccountRetry: sameRoute };
408
437
  });
409
438
  assertActive();
410
439
  let headers = {};
@@ -438,6 +467,7 @@ export async function installOpenCode2Auth(ctx, adapter, options = {}) {
438
467
  },
439
468
  ...(transport === undefined ? {} : { transport }),
440
469
  outputStarted: false,
470
+ sameAccountRetry,
441
471
  };
442
472
  remember(rec);
443
473
  if (rec.attempt) {
@@ -815,7 +845,7 @@ export async function installOpenCode2Auth(ctx, adapter, options = {}) {
815
845
  hostDecision,
816
846
  decision: hostDecision,
817
847
  });
818
- if (mixed(draft.sessionID)) {
848
+ if (mixed(draft.sessionID) && !adapter.retrySameAccount) {
819
849
  await hostDecides();
820
850
  return;
821
851
  }
@@ -837,6 +867,104 @@ export async function installOpenCode2Auth(ctx, adapter, options = {}) {
837
867
  const rec = picked;
838
868
  await withSelection(rec.scope, async (assertActive) => {
839
869
  const checkRetryActive = assertActive;
870
+ const retrySameAccount = adapter.retrySameAccount?.bind(adapter);
871
+ const handle = rec.attempt;
872
+ if (retrySameAccount &&
873
+ handle &&
874
+ !rec.outputStarted &&
875
+ !rec.sameAccountRetry) {
876
+ if (rec.ended)
877
+ await rec.ended;
878
+ if (rec.limit)
879
+ await rec.limit.delivered;
880
+ const retried = await inChoiceOrder(rec.scope.sessionID, async () => {
881
+ checkRetryActive();
882
+ const accountId = handle.accountId;
883
+ const active = () => attempts.has(rec.id) &&
884
+ rec.accountId === accountId &&
885
+ pickForRetry(draft.sessionID) === rec &&
886
+ !rec.outputStarted &&
887
+ (!ownership ||
888
+ latestTransportOwned.get(draft.sessionID) === true);
889
+ if (!active() || rec.sameAccountRetry)
890
+ return false;
891
+ rec.sameAccountRetry = true;
892
+ const input = {
893
+ ...rec.scope,
894
+ accountId,
895
+ error: draft.error,
896
+ attempt: draft.attempt,
897
+ ...(rec.limit ? { limit: rec.limit.signal } : {}),
898
+ };
899
+ let result;
900
+ try {
901
+ result = await retrySameAccount(input);
902
+ }
903
+ catch (error) {
904
+ warn('opencode2 auth retrySameAccount threw; recovery declined', {
905
+ sessionID: draft.sessionID,
906
+ error: describe(error),
907
+ });
908
+ }
909
+ if (!result) {
910
+ checkRetryActive();
911
+ return false;
912
+ }
913
+ const sameAccount = { accountId: result.accountId, input };
914
+ try {
915
+ checkRetryActive();
916
+ }
917
+ catch (error) {
918
+ await releaseSameAccount(sameAccount);
919
+ throw error;
920
+ }
921
+ if (!active() || result.accountId !== accountId) {
922
+ await releaseSameAccount(sameAccount);
923
+ return false;
924
+ }
925
+ const old = pendingRetries.get(rec.key);
926
+ pendingRetries.delete(rec.key);
927
+ if (old)
928
+ await releaseRetry(old);
929
+ try {
930
+ checkRetryActive();
931
+ }
932
+ catch (error) {
933
+ await releaseSameAccount(sameAccount);
934
+ throw error;
935
+ }
936
+ if (!active()) {
937
+ await releaseSameAccount(sameAccount);
938
+ return false;
939
+ }
940
+ // Pin only this retry's route: choosing afresh could turn a token
941
+ // refresh or path recovery into an account switch in a mixed session.
942
+ pendingRetries.set(rec.key, {
943
+ attemptId: rec.id,
944
+ sessionID: rec.scope.sessionID,
945
+ order: ++retryOrder,
946
+ accountId,
947
+ sameAccount,
948
+ });
949
+ rec.judged = true;
950
+ draft.decision = { retry: true, delay: 0 };
951
+ return true;
952
+ });
953
+ checkRetryActive();
954
+ if (retried) {
955
+ await emit('retry', {
956
+ sessionID: draft.sessionID,
957
+ accountId: rec.accountId,
958
+ kind: rec.scope.kind,
959
+ attempt: draft.attempt,
960
+ reason: 'same-account',
961
+ hostDecision,
962
+ decision: draft.decision,
963
+ handle: rec.attempt,
964
+ });
965
+ return;
966
+ }
967
+ }
840
968
  // Recheck after entering selection before attributing an identity-less error.
841
969
  if (mixed(draft.sessionID)) {
842
970
  await hostDecides();
@@ -866,8 +994,8 @@ export async function installOpenCode2Auth(ctx, adapter, options = {}) {
866
994
  };
867
995
  const old = pendingRetries.get(rec.key);
868
996
  pendingRetries.delete(rec.key);
869
- if (old?.next)
870
- await releaseChoice(old.next);
997
+ if (old)
998
+ await releaseRetry(old);
871
999
  checkRetryActive();
872
1000
  if (mixed(draft.sessionID))
873
1001
  return {
@@ -1064,8 +1192,7 @@ export async function installOpenCode2Auth(ctx, adapter, options = {}) {
1064
1192
  if (pending.sessionID === sessionID &&
1065
1193
  pending.order < idleOrder) {
1066
1194
  pendingRetries.delete(key);
1067
- if (pending.next)
1068
- await releaseChoice(pending.next);
1195
+ await releaseRetry(pending);
1069
1196
  }
1070
1197
  }
1071
1198
  });
@@ -173,6 +173,22 @@ export interface HostError {
173
173
  readonly message: string;
174
174
  readonly status?: number;
175
175
  }
176
+ /** The known route and host error for an identity-preserving retry. */
177
+ export interface SameAccountRetryInput extends AccountRequest {
178
+ readonly error: HostError;
179
+ /** The host's retry attempt count. */
180
+ readonly attempt: number;
181
+ /**
182
+ * The signal already recorded by a response/frame trigger, if any. Its reason
183
+ * can key prepared credentials, so recovery need not refresh them twice.
184
+ * limitFromError is not called before this callback in a mixed session.
185
+ */
186
+ readonly limit?: LimitSignal;
187
+ }
188
+ /** Request an immediate retry; a different account ID is ignored. */
189
+ export interface SameAccountRetryResult {
190
+ readonly accountId: string;
191
+ }
176
192
  /**
177
193
  * Everything provider-specific the installer needs. `Q` is the plugin's own
178
194
  * quota reading type; the installer only carries it to the `quota` event.
@@ -345,6 +361,39 @@ export interface OpenCode2AuthAdapter<Q = unknown, A = unknown, Choice extends C
345
361
  * the retry hook judged.
346
362
  */
347
363
  limitFromError?(error: HostError, attempt: Attempt<A>): LimitSignal | undefined;
364
+ /**
365
+ * Optional recovery on the same route before account failover is considered.
366
+ * May only use a newer record version of the same credentialId and accountIdentity,
367
+ * a different local access token for the same subject, or another path to the
368
+ * same provider with the same credential. The adapter must
369
+ * preserve those identities; opaque credential material is not inspected here.
370
+ * Return {accountId: input.accountId} to retry immediately, or undefined to decline.
371
+ * A different accountId is ignored. Never move a routing pin or select another
372
+ * account here: use chooseAccount for failover and holds.
373
+ *
374
+ * Runs only for an attributable attempt before output, and, when gated, only
375
+ * while the latest transport is owned. Unlike failover and holds, it also runs
376
+ * in mixed-ownership sessions. The next matching owned request skips selection
377
+ * and calls accountHeaders again for this account, so newer credentials or a
378
+ * changed transport path can take effect without changing accounts. Runs at
379
+ * most once per attempt, never on the attempt sent by this recovery, so retries
380
+ * cannot chain. Use input.limit to consume state prepared by a response/frame
381
+ * trigger; without one, the callback may handle input.error itself. Do not
382
+ * refresh again when the trigger has already prepared the new credential.
383
+ * No choice was committed through chooseAccount; unused recovery state is
384
+ * released through dropSameAccountRetry instead of dropChoice.
385
+ * Errors are logged and treated as declining the retry.
386
+ */
387
+ retrySameAccount?(input: SameAccountRetryInput): Promise<SameAccountRetryResult | undefined> | SameAccountRetryResult | undefined;
388
+ /**
389
+ * Releases a returned same-account recovery that will not be sent: a rejected
390
+ * account ID, selection revocation, changed model/agent, cancellation (session
391
+ * idle), forgetting/deletion, disposal or eviction. Receives the original
392
+ * callback input and returned accountId, once, never for a consumed recovery.
393
+ * Awaited before later selection for the session; errors are logged and swallowed.
394
+ * A callback that declines or throws must clean up its own uncommitted state.
395
+ */
396
+ dropSameAccountRetry?(input: SameAccountRetryInput & SameAccountRetryResult): Promise<void> | void;
348
397
  /**
349
398
  * Called once per attempt when it ends: an HTTP response body finished,
350
399
  * errored or was cancelled; an HTTP response with an error status or no
@@ -400,11 +449,13 @@ export interface InstallOpenCode2AuthOptions {
400
449
  * (its wait, or its refusal to retry) stands and the next attempt may go
401
450
  * to the refused account again;
402
451
  * - `hold`: an explicit adapter wait on the refused account, before output;
452
+ * - `same-account`: the adapter requested immediate recovery on the same route,
453
+ * without account selection, before output;
403
454
  * - `host-decides`: no limit was recognised, or the failing call cannot be
404
455
  * attributed safely (ambiguous attempts or mixed ownership in a gated
405
456
  * session), so the host's decision stands.
406
457
  */
407
- export type RetryReason = 'reroute' | 'hold' | 'output-started' | 'no-account' | 'host-decides-last-account' | 'host-decides';
458
+ export type RetryReason = 'reroute' | 'hold' | 'same-account' | 'output-started' | 'no-account' | 'host-decides-last-account' | 'host-decides';
408
459
  /**
409
460
  * The hook that picked an account. Normally `model.request`; a transport hook
410
461
  * picks only when the host skipped `model.request` for that request, which a
@@ -0,0 +1,86 @@
1
+ import type { RGBA } from '@opentui/core';
2
+ import type { JSX } from '@opentui/solid';
3
+ import type { QuotaWindowPart } from '../quota/format.js';
4
+ import type { ProjectedQuota } from '../quota/projection.js';
5
+ export type Tone = 'text' | 'textMuted' | 'accent' | 'success' | 'warning' | 'error';
6
+ export type SidebarTheme = Readonly<Partial<Record<Tone | 'background' | 'borderActive', RGBA | string | undefined>>>;
7
+ export interface SidebarAppearance {
8
+ barWidth: number;
9
+ barFilledChar: string;
10
+ barEmptyChar: string;
11
+ warnThreshold: number;
12
+ errorThreshold: number;
13
+ }
14
+ export interface PaceView {
15
+ text: string;
16
+ tone: Tone;
17
+ /** The elapsed-window percentage, not the difference from usage. */
18
+ overlay?: {
19
+ kind: 'reserve' | 'deficit';
20
+ percent: number;
21
+ };
22
+ }
23
+ export interface QuotaGroupView {
24
+ title?: string;
25
+ rows: readonly {
26
+ part: QuotaWindowPart;
27
+ pace?: PaceView;
28
+ }[];
29
+ }
30
+ export interface AccountView {
31
+ id: string;
32
+ label: string;
33
+ titleSuffix?: string;
34
+ status: {
35
+ text: string;
36
+ tone: Tone;
37
+ };
38
+ blocked: boolean;
39
+ indicatorTone: Tone;
40
+ quota: ProjectedQuota | undefined;
41
+ groups: readonly QuotaGroupView[];
42
+ emptyQuotaText?: {
43
+ expanded: string;
44
+ collapsed: string;
45
+ };
46
+ /** Presentation decided by the plugin, never inferred from status or freshness. */
47
+ collapsed?: {
48
+ quotaTone?: Tone;
49
+ muted?: boolean;
50
+ };
51
+ }
52
+ export interface SidebarFrameProps {
53
+ header: {
54
+ badge: string;
55
+ version?: string;
56
+ };
57
+ accounts: readonly AccountView[];
58
+ theme?: SidebarTheme;
59
+ appearance: SidebarAppearance;
60
+ showQuota: boolean;
61
+ now: number;
62
+ collapsed: boolean;
63
+ onToggle: () => void;
64
+ beforeQuota?: (account: AccountView) => JSX.Element;
65
+ afterQuota?: (account: AccountView) => JSX.Element;
66
+ sections?: () => JSX.Element;
67
+ collapsedSections?: () => JSX.Element;
68
+ }
69
+ /** A heading and its plugin-owned rows, with the frame's section spacing. */
70
+ export declare function SidebarSection(props: {
71
+ title: string;
72
+ children?: JSX.Element;
73
+ }): any;
74
+ /** Keep labels whole and reserve one blank cell before an ellipsized value. */
75
+ export declare function SidebarStatRow(props: {
76
+ label: string;
77
+ value: string;
78
+ tone?: Tone;
79
+ }): any;
80
+ export declare function SidebarTextRow(props: {
81
+ text: string;
82
+ tone?: Tone;
83
+ wrapMode?: JSX.IntrinsicElements['text']['wrapMode'];
84
+ }): any;
85
+ /** Borderless, controlled presentation; host registration and provider policy stay in the plugin. */
86
+ export declare function SidebarFrame(props: SidebarFrameProps): any;