@cortexkit/opencode-openai-auth 0.11.1 → 1.0.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 (204) hide show
  1. package/README.md +15 -26
  2. package/dist/index-766sfrh5.js +1 -0
  3. package/dist/index-8kj7sa1p.js +12 -0
  4. package/dist/index-8rqfbhfw.js +221 -0
  5. package/dist/index-b3q3j39x.js +2 -0
  6. package/dist/index-bmd7x5aq.js +2 -0
  7. package/dist/index-eqh53k8v.js +2 -0
  8. package/dist/{index-sdt2d2ra.js → index-hy9030jh.js} +1 -1
  9. package/dist/index-jyr8y8k4.js +7 -0
  10. package/dist/index-rv08jmd4.js +2 -0
  11. package/dist/index.d.ts +578 -145
  12. package/dist/index.js +1 -110
  13. package/dist/pool-lifecycle-DbDmgabd.d.ts +2430 -0
  14. package/dist/port-file-Do3lQIEk.d.ts +29 -0
  15. package/dist/protocol-BOBdkqqm.d.ts +198 -0
  16. package/dist/rpc/port-file.d.ts +4 -17
  17. package/dist/rpc/port-file.js +1 -1
  18. package/dist/rpc/protocol.d.ts +2 -2
  19. package/dist/rpc/protocol.js +1 -0
  20. package/dist/rpc/rpc-client.d.ts +5 -4
  21. package/dist/rpc/rpc-client.js +1 -1
  22. package/dist/rpc/rpc-dir.d.ts +2 -0
  23. package/dist/rpc/rpc-dir.js +1 -1
  24. package/dist/sidebar-state-D6cUKgkm.d.ts +385 -0
  25. package/dist/sidebar-state.d.ts +2 -2
  26. package/dist/sidebar-state.js +1 -1
  27. package/dist/token-util-wdza526f.js +1 -0
  28. package/dist/{token-9823y0pc.js → token-ypk61xj0.js} +1 -1
  29. package/dist/tui-preferences.js +5 -2
  30. package/dist/tui.d.ts +9 -4
  31. package/dist/v2/server.d.ts +54 -0
  32. package/dist/v2/server.js +4 -0
  33. package/package.json +21 -9
  34. package/src/tui/entry.mjs +26 -25
  35. package/src/tui-compiled/raw/logger.js +24 -0
  36. package/src/tui-compiled/raw/rpc/protocol.js +3 -0
  37. package/src/tui-compiled/raw/rpc/rpc-client.js +7 -0
  38. package/src/tui-compiled/raw/rpc/rpc-dir.js +27 -0
  39. package/src/tui-compiled/raw/selector.js +21 -0
  40. package/src/tui-compiled/raw/shared/0332701351b3eeec-format.js +138 -0
  41. package/src/tui-compiled/raw/shared/04a6357627de5ed0-errors.js +38 -0
  42. package/src/tui-compiled/raw/shared/053cc17b5419261e-codec.js +12 -0
  43. package/src/tui-compiled/raw/shared/0766d78c6f481f18-watcher.js +157 -0
  44. package/src/tui-compiled/raw/shared/08eef45626a94992-reserved.js +13 -0
  45. package/src/tui-compiled/raw/shared/39c3cb05738fcf6d-projection.js +134 -0
  46. package/src/tui-compiled/raw/shared/3c2d4169d00f907e-tui-support.js +5 -0
  47. package/src/tui-compiled/raw/shared/3e7d45a77c6ad4d5-index.js +4 -0
  48. package/src/tui-compiled/raw/shared/415792e85d80819e-capture-sink.js +13 -0
  49. package/src/tui-compiled/raw/shared/42ae93ab554fcec2-open-url.js +28 -0
  50. package/src/tui-compiled/raw/shared/43fc9e6b994519c7-refresh-lock.js +136 -0
  51. package/src/tui-compiled/raw/shared/458b934e92490331-mutate.js +500 -0
  52. package/src/tui-compiled/raw/shared/45bf5343bbbf9add-admission.js +142 -0
  53. package/src/tui-compiled/raw/shared/46f3dff1266160e8-client.js +2 -0
  54. package/src/tui-compiled/raw/shared/4825e03209d6ae3e-with-lock.js +48 -0
  55. package/src/tui-compiled/raw/shared/4f36d333d081d040-merge.js +162 -0
  56. package/src/tui-compiled/raw/shared/54eba94fd64c8c3c-index.js +7 -0
  57. package/src/tui-compiled/raw/shared/7211cfec06a298bc-atomic-write.js +80 -0
  58. package/src/tui-compiled/raw/shared/754d6017f8e419cf-builtins.js +534 -0
  59. package/src/tui-compiled/raw/shared/75bd8c3bd63b315f-identity.js +79 -0
  60. package/src/tui-compiled/raw/shared/7a91bb630e6f4804-index.js +1 -0
  61. package/src/tui-compiled/raw/shared/826342a4b6a8b89b-model.js +16 -0
  62. package/src/tui-compiled/raw/shared/83068c0dbe8a6f13-publication.js +304 -0
  63. package/src/tui-compiled/raw/shared/836fc615de6afbd9-settings.js +120 -0
  64. package/src/tui-compiled/raw/shared/83bc3ba9d0fe2761-runtime.js +68 -0
  65. package/src/tui-compiled/raw/shared/8a18abe4fa2977c8-menu.js +300 -0
  66. package/src/tui-compiled/raw/shared/901e149c5a0dbbff-sticky.js +339 -0
  67. package/src/tui-compiled/raw/shared/9020c407ce64f672-ordered.js +58 -0
  68. package/src/tui-compiled/raw/shared/905bffc0220f43d0-map.js +105 -0
  69. package/src/tui-compiled/raw/shared/94820e324f2b4c09-seam.js +301 -0
  70. package/src/tui-compiled/raw/shared/97484d9bb98c705b-provider-state.js +226 -0
  71. package/src/tui-compiled/raw/shared/9968e3cade6969a1-index.js +2 -0
  72. package/src/tui-compiled/raw/shared/9b4da614c45f9cd0-lock-constants.js +14 -0
  73. package/src/tui-compiled/raw/shared/9d3fc9e37456504e-refresh.js +225 -0
  74. package/src/tui-compiled/raw/shared/9deae3c4da4fd63b-hooks.js +34 -0
  75. package/src/tui-compiled/raw/shared/a09b6a533c11858f-tui-preferences.js +77 -0
  76. package/src/tui-compiled/raw/shared/a62a27a204266acd-attribution.js +60 -0
  77. package/src/tui-compiled/raw/shared/a910277ac43a8626-pull.js +143 -0
  78. package/src/tui-compiled/raw/shared/b85c5301fddcb98a-paths.js +5 -0
  79. package/src/tui-compiled/raw/shared/c14988621dc60a75-port-file.js +217 -0
  80. package/src/tui-compiled/raw/shared/c64d7afbc14ca125-sidebar-file.js +157 -0
  81. package/src/tui-compiled/raw/shared/c6b176708c446d6d-pins.js +34 -0
  82. package/src/tui-compiled/raw/shared/c7d252bedee01600-pi.js +206 -0
  83. package/src/tui-compiled/raw/shared/c852a15cfe489d12-pool.js +120 -0
  84. package/src/tui-compiled/raw/shared/cc9e0702a752cea7-index.js +3 -0
  85. package/src/tui-compiled/raw/shared/cd94316a888b0a8e-schema.js +754 -0
  86. package/src/tui-compiled/raw/shared/d319517e3ea6ad70-redact.js +83 -0
  87. package/src/tui-compiled/raw/shared/d5a8f1061ee2f114-index.js +5 -0
  88. package/src/tui-compiled/raw/shared/d669d72c40e9e116-logger.js +19 -0
  89. package/src/tui-compiled/raw/shared/d7dcba96fea1685c-engine.js +246 -0
  90. package/src/tui-compiled/raw/shared/dbef697d1df1cd84-index.js +5 -0
  91. package/src/tui-compiled/raw/shared/e4acc4cb713f300c-protocol.js +3 -0
  92. package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +501 -0
  93. package/src/tui-compiled/raw/shared/ec971142548df90e-index.js +6 -0
  94. package/src/tui-compiled/raw/shared/f37fcefc7aedbf25-error.js +11 -0
  95. package/src/tui-compiled/raw/shared/fbcdcd0f925e74c0-rpc-client.js +253 -0
  96. package/src/tui-compiled/raw/shared/fd45e82f2f9c0a0d-torn.js +294 -0
  97. package/src/tui-compiled/raw/shared/fe02abeadc535f77-rows.js +1258 -0
  98. package/src/tui-compiled/raw/sidebar-state.js +960 -0
  99. package/src/tui-compiled/raw/tui/command-dialogs.tsx +424 -0
  100. package/src/tui-compiled/raw/tui-preferences.js +135 -0
  101. package/src/tui-compiled/raw/tui.tsx +135 -143
  102. package/src/tui-compiled/runtime/logger.js +24 -0
  103. package/src/tui-compiled/runtime/rpc/protocol.js +3 -0
  104. package/src/tui-compiled/runtime/rpc/rpc-client.js +7 -0
  105. package/src/tui-compiled/runtime/rpc/rpc-dir.js +27 -0
  106. package/src/tui-compiled/runtime/selector.js +21 -0
  107. package/src/tui-compiled/runtime/shared/0332701351b3eeec-format.js +138 -0
  108. package/src/tui-compiled/runtime/shared/04a6357627de5ed0-errors.js +38 -0
  109. package/src/tui-compiled/runtime/shared/053cc17b5419261e-codec.js +12 -0
  110. package/src/tui-compiled/runtime/shared/0766d78c6f481f18-watcher.js +157 -0
  111. package/src/tui-compiled/runtime/shared/08eef45626a94992-reserved.js +13 -0
  112. package/src/tui-compiled/runtime/shared/39c3cb05738fcf6d-projection.js +134 -0
  113. package/src/tui-compiled/runtime/shared/3c2d4169d00f907e-tui-support.js +5 -0
  114. package/src/tui-compiled/runtime/shared/3e7d45a77c6ad4d5-index.js +4 -0
  115. package/src/tui-compiled/runtime/shared/415792e85d80819e-capture-sink.js +13 -0
  116. package/src/tui-compiled/runtime/shared/42ae93ab554fcec2-open-url.js +28 -0
  117. package/src/tui-compiled/runtime/shared/43fc9e6b994519c7-refresh-lock.js +136 -0
  118. package/src/tui-compiled/runtime/shared/458b934e92490331-mutate.js +500 -0
  119. package/src/tui-compiled/runtime/shared/45bf5343bbbf9add-admission.js +142 -0
  120. package/src/tui-compiled/runtime/shared/46f3dff1266160e8-client.js +2 -0
  121. package/src/tui-compiled/runtime/shared/4825e03209d6ae3e-with-lock.js +48 -0
  122. package/src/tui-compiled/runtime/shared/4f36d333d081d040-merge.js +162 -0
  123. package/src/tui-compiled/runtime/shared/54eba94fd64c8c3c-index.js +7 -0
  124. package/src/tui-compiled/runtime/shared/7211cfec06a298bc-atomic-write.js +80 -0
  125. package/src/tui-compiled/runtime/shared/754d6017f8e419cf-builtins.js +534 -0
  126. package/src/tui-compiled/runtime/shared/75bd8c3bd63b315f-identity.js +79 -0
  127. package/src/tui-compiled/runtime/shared/7a91bb630e6f4804-index.js +1 -0
  128. package/src/tui-compiled/runtime/shared/826342a4b6a8b89b-model.js +16 -0
  129. package/src/tui-compiled/runtime/shared/83068c0dbe8a6f13-publication.js +304 -0
  130. package/src/tui-compiled/runtime/shared/836fc615de6afbd9-settings.js +120 -0
  131. package/src/tui-compiled/runtime/shared/83bc3ba9d0fe2761-runtime.js +68 -0
  132. package/src/tui-compiled/runtime/shared/8a18abe4fa2977c8-menu.js +300 -0
  133. package/src/tui-compiled/runtime/shared/901e149c5a0dbbff-sticky.js +339 -0
  134. package/src/tui-compiled/runtime/shared/9020c407ce64f672-ordered.js +58 -0
  135. package/src/tui-compiled/runtime/shared/905bffc0220f43d0-map.js +105 -0
  136. package/src/tui-compiled/runtime/shared/94820e324f2b4c09-seam.js +301 -0
  137. package/src/tui-compiled/runtime/shared/97484d9bb98c705b-provider-state.js +226 -0
  138. package/src/tui-compiled/runtime/shared/9968e3cade6969a1-index.js +2 -0
  139. package/src/tui-compiled/runtime/shared/9b4da614c45f9cd0-lock-constants.js +14 -0
  140. package/src/tui-compiled/runtime/shared/9d3fc9e37456504e-refresh.js +225 -0
  141. package/src/tui-compiled/runtime/shared/9deae3c4da4fd63b-hooks.js +34 -0
  142. package/src/tui-compiled/runtime/shared/a09b6a533c11858f-tui-preferences.js +77 -0
  143. package/src/tui-compiled/runtime/shared/a62a27a204266acd-attribution.js +60 -0
  144. package/src/tui-compiled/runtime/shared/a910277ac43a8626-pull.js +143 -0
  145. package/src/tui-compiled/runtime/shared/b85c5301fddcb98a-paths.js +5 -0
  146. package/src/tui-compiled/runtime/shared/c14988621dc60a75-port-file.js +217 -0
  147. package/src/tui-compiled/runtime/shared/c64d7afbc14ca125-sidebar-file.js +157 -0
  148. package/src/tui-compiled/runtime/shared/c6b176708c446d6d-pins.js +34 -0
  149. package/src/tui-compiled/runtime/shared/c7d252bedee01600-pi.js +206 -0
  150. package/src/tui-compiled/runtime/shared/c852a15cfe489d12-pool.js +120 -0
  151. package/src/tui-compiled/runtime/shared/cc9e0702a752cea7-index.js +3 -0
  152. package/src/tui-compiled/runtime/shared/cd94316a888b0a8e-schema.js +754 -0
  153. package/src/tui-compiled/runtime/shared/d319517e3ea6ad70-redact.js +83 -0
  154. package/src/tui-compiled/runtime/shared/d5a8f1061ee2f114-index.js +5 -0
  155. package/src/tui-compiled/runtime/shared/d669d72c40e9e116-logger.js +19 -0
  156. package/src/tui-compiled/runtime/shared/d7dcba96fea1685c-engine.js +246 -0
  157. package/src/tui-compiled/runtime/shared/dbef697d1df1cd84-index.js +5 -0
  158. package/src/tui-compiled/runtime/shared/e4acc4cb713f300c-protocol.js +3 -0
  159. package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +501 -0
  160. package/src/tui-compiled/runtime/shared/ec971142548df90e-index.js +6 -0
  161. package/src/tui-compiled/runtime/shared/f37fcefc7aedbf25-error.js +11 -0
  162. package/src/tui-compiled/runtime/shared/fbcdcd0f925e74c0-rpc-client.js +253 -0
  163. package/src/tui-compiled/runtime/shared/fd45e82f2f9c0a0d-torn.js +294 -0
  164. package/src/tui-compiled/runtime/shared/fe02abeadc535f77-rows.js +1258 -0
  165. package/src/tui-compiled/runtime/sidebar-state.js +960 -0
  166. package/src/tui-compiled/runtime/tui/command-dialogs.js +378 -0
  167. package/src/tui-compiled/runtime/tui-preferences.js +135 -0
  168. package/src/tui-compiled/runtime/{tui.tsx → tui.js} +288 -316
  169. package/dist/index-4effjmr6.js +0 -2
  170. package/dist/index-9ehhb051.js +0 -2
  171. package/dist/index-g3hsdjh4.js +0 -2
  172. package/dist/index-hh52v8sb.js +0 -2
  173. package/dist/index-jwn4r3sw.js +0 -1
  174. package/dist/index-sq36b120.js +0 -211
  175. package/dist/internal-BTndPmW2.d.ts +0 -914
  176. package/dist/quota-normalize-08hpp51v.js +0 -1
  177. package/dist/sidebar-state-CoKYKcLn.d.ts +0 -220
  178. package/dist/token-util-ypgz7rge.js +0 -1
  179. package/src/tui-compiled/raw/core-account-paths.ts +0 -114
  180. package/src/tui-compiled/raw/core-custody-state.ts +0 -243
  181. package/src/tui-compiled/raw/logger.ts +0 -53
  182. package/src/tui-compiled/raw/rpc-port-file.ts +0 -177
  183. package/src/tui-compiled/raw/rpc-protocol.ts +0 -12
  184. package/src/tui-compiled/raw/rpc-rpc-client.ts +0 -82
  185. package/src/tui-compiled/raw/rpc-rpc-dir.ts +0 -46
  186. package/src/tui-compiled/raw/sidebar-state.ts +0 -1659
  187. package/src/tui-compiled/raw/tui-command-dialogs.tsx +0 -1096
  188. package/src/tui-compiled/raw/tui-preferences.ts +0 -328
  189. package/src/tui-compiled/runtime/core-account-paths.ts +0 -114
  190. package/src/tui-compiled/runtime/core-custody-state.ts +0 -243
  191. package/src/tui-compiled/runtime/logger.ts +0 -53
  192. package/src/tui-compiled/runtime/rpc-port-file.ts +0 -177
  193. package/src/tui-compiled/runtime/rpc-protocol.ts +0 -12
  194. package/src/tui-compiled/runtime/rpc-rpc-client.ts +0 -82
  195. package/src/tui-compiled/runtime/rpc-rpc-dir.ts +0 -46
  196. package/src/tui-compiled/runtime/sidebar-state.ts +0 -1659
  197. package/src/tui-compiled/runtime/tui-command-dialogs.tsx +0 -855
  198. package/src/tui-compiled/runtime/tui-preferences.ts +0 -328
  199. package/src/tui-compiled/shared/internal.ts +0 -6
  200. package/src/tui-compiled/shared/logger.ts +0 -264
  201. package/src/tui-compiled/shared/paths.ts +0 -33
  202. package/src/tui-compiled/shared/refresh-file-lock.ts +0 -384
  203. package/src/tui-compiled/shared/util/error.ts +0 -9
  204. package/src/tui-compiled/shared/util/open-url.ts +0 -30
@@ -1 +0,0 @@
1
- import{lb as a,mb as b,nb as c,ob as d,pb as e}from"./index-hh52v8sb.js";import"./index-9ehhb051.js";export{a as toResetIso,d as normalizeWsFrame,e as normalizeWham,b as normalizeQuotaHeaders,c as isCompleteQuotaHeaderFrame};
@@ -1,220 +0,0 @@
1
- //#region src/core/custody-state.d.ts
2
- type VaultCustodyState = 'serves' | 'cold' | 'needs_reauth' | 'identity_mismatch' | 'no_handle';
3
- declare const CUSTODY_INERT_REASONS: readonly ['needs-login', 'mode-mismatch', 'corrupt-under-binding', 'manifest-unreadable', 'unbound-under-claustrum', 'orphan-tombstone', 'vault-cold', 'vault-reauth', 'identity-mismatch', 'no-handle', 'takeover-incomplete', 'new-local-family-under-claustrum', 'takeover-incomplete/vault-unavailable', 'takeover-incomplete/slot-absent'];
4
- type CustodyInertReason = (typeof CUSTODY_INERT_REASONS)[number];
5
- type CustodyVerdict = {
6
- kind: 'LOCAL';
7
- } | {
8
- kind: 'VAULT';
9
- canonicalize?: boolean;
10
- installTombstone?: boolean;
11
- } | {
12
- kind: 'INERT';
13
- reason: CustodyInertReason;
14
- installTombstone?: boolean;
15
- canonicalize?: boolean;
16
- } | {
17
- kind: 'NEEDS_LOGIN';
18
- reason?: 'corrupt';
19
- };
20
- //#endregion
21
- //#region src/sidebar-state.d.ts
22
- interface QuotaWindow {
23
- usedPercent: number;
24
- remainingPercent: number;
25
- checkedAt?: number;
26
- resetsAt?: string;
27
- windowMinutes?: number;
28
- }
29
- interface SpendControlReading {
30
- limit: number;
31
- used: number;
32
- remaining: number;
33
- usedPercent: number;
34
- remainingPercent: number;
35
- resetsAt?: string;
36
- unit?: string;
37
- source?: string;
38
- reached: boolean;
39
- }
40
- interface AccountQuota {
41
- checkedAt?: number;
42
- primary?: QuotaWindow;
43
- secondary?: QuotaWindow;
44
- spendControl?: SpendControlReading;
45
- spendControlCleared?: true;
46
- resetCreditsAvailable?: number;
47
- }
48
- type QuotaWindowKey = 'primary' | 'secondary';
49
- declare function formatWindowLabel(windowMinutes: number | undefined, fallbackKey: QuotaWindowKey): string;
50
- interface PresentQuotaWindow {
51
- key: QuotaWindowKey;
52
- label: string;
53
- window: QuotaWindow;
54
- windowMs: number | null;
55
- }
56
- declare function getPresentQuotaWindows(quota: AccountQuota | null): PresentQuotaWindow[];
57
- interface SidebarAccountState {
58
- id: string;
59
- label: string | undefined;
60
- /** ChatGPT identity of the account this quota belongs to. */
61
- accountId?: string;
62
- quota: AccountQuota | null;
63
- killed: boolean;
64
- enabled: boolean;
65
- resetCredits?: number;
66
- custody?: SidebarAccountCustody;
67
- }
68
- type SidebarCustodyState = 'vault' | 'needsLogin' | 'local' | 'inert';
69
- type SidebarCustodyReason = CustodyInertReason | 'corrupt';
70
- interface SidebarAccountCustody {
71
- state: SidebarCustodyState;
72
- reason?: SidebarCustodyReason;
73
- recordVersion?: number;
74
- }
75
- interface ActiveRoutingEntry {
76
- activeId: string;
77
- route: string;
78
- updatedAt: number;
79
- }
80
- type ActiveRoutingMap = Record<string, ActiveRoutingEntry>;
81
- interface StickyAssignment {
82
- accountId: string;
83
- wireAccountId?: string;
84
- assignedAt: number;
85
- lastSeenAt: number;
86
- inputBytes: number;
87
- quotaCheckedAt?: number;
88
- }
89
- type StickyAssignmentMap = Record<string, StickyAssignment>;
90
- interface StickyAssignmentChoice {
91
- accountId: string;
92
- quotaCheckedAt?: number;
93
- }
94
- interface ResolveStickyAssignmentInput {
95
- sessionId: string;
96
- requestBytes: number;
97
- now: number;
98
- validPinnedAccountIds: readonly string[];
99
- excludeAccountIds?: readonly string[];
100
- quotaCheckedAtByAccount: Readonly<Record<string, number | undefined>>;
101
- wireAccountIdByAccount?: Readonly<Record<string, string | undefined>>;
102
- choose: (pendingBytes: ReadonlyMap<string, number>) => StickyAssignmentChoice | undefined;
103
- }
104
- interface SidebarState {
105
- main: {
106
- quota: AccountQuota | null;
107
- /** ChatGPT identity of the main account this quota belongs to. */
108
- mainAccountId?: string;
109
- custody?: SidebarAccountCustody;
110
- killed: boolean;
111
- quotaBackedOff?: boolean;
112
- quotaBackoffUntil?: number;
113
- refreshBackedOff?: boolean;
114
- refreshBackoffUntil?: number;
115
- resetCredits?: number;
116
- };
117
- fallbacks: SidebarAccountState[];
118
- /** @deprecated Compatibility field for readers that do not consume activeRouting. */
119
- activeId: string | undefined;
120
- /** Machine-global routing mode and compatibility value for older readers. */
121
- route: string;
122
- activeRouting?: ActiveRoutingMap;
123
- stickyAssignments?: StickyAssignmentMap;
124
- planType?: string;
125
- credits?: number;
126
- lastUpdated: number;
127
- }
128
- declare const STICKY_ASSIGNMENT_MAX_AGE_MS: number;
129
- declare const STICKY_ASSIGNMENT_MAX_ENTRIES = 256;
130
- declare function hashSidebarSessionId(sessionId: string): string;
131
- declare function getSidebarStateFile(): string;
132
- declare function projectCustodyForSidebar(verdict: CustodyVerdict): SidebarAccountCustody;
133
- declare const DEFAULT_SIDEBAR_STATE: SidebarState;
134
- /**
135
- * Normalize an arbitrary parsed value into a well-formed SidebarState.
136
- *
137
- * JSON.parse + `as SidebarState` is an unchecked cast — a partial, old, or
138
- * malformed state file passes through and the TUI's `state().main.quota` /
139
- * `state().fallbacks.filter(...)` throw at runtime. This helper guarantees
140
- * every required field is present and correctly typed before the value leaves
141
- * the I/O boundary, so a bad file can never crash the host TUI.
142
- */
143
- declare function normalizeSidebarState(raw: unknown): SidebarState;
144
- declare function getSidebarState(stateFile?: string): Promise<SidebarState>;
145
- declare const ACTIVE_ROUTING_MAX_AGE_MS: number;
146
- declare const ACTIVE_ROUTING_MAX_ENTRIES = 128;
147
- type SidebarRoutingAccount = {
148
- id: string;
149
- enabled?: boolean;
150
- killed?: boolean;
151
- };
152
- declare function isUsableRoutingEntry(entry: ActiveRoutingEntry, accounts: readonly SidebarRoutingAccount[] | undefined, now?: number): boolean;
153
- declare function spendControlExhaustedResetAt(quota: AccountQuota | null | undefined, now?: number): {
154
- resetsAt: string;
155
- resetAtMs: number;
156
- } | undefined;
157
- declare function exhaustedQuotaResetAt(quota: AccountQuota | null | undefined, now?: number): {
158
- resetsAt: string;
159
- resetAtMs: number;
160
- } | undefined;
161
- declare function isQuotaExhausted(quota: AccountQuota | null | undefined, now?: number): boolean;
162
- declare function resolveSessionStickyAccount(state: SidebarState, sessionId: string | undefined, now?: number): string | undefined;
163
- declare function resolveSessionSidebarRouting(state: SidebarState, sessionId?: string, now?: number): {
164
- activeId: string;
165
- route: string;
166
- };
167
- declare function pruneActiveRouting(activeRouting: ActiveRoutingMap | undefined, accounts: readonly SidebarRoutingAccount[] | undefined, now?: number, removedSessionId?: string): ActiveRoutingMap | undefined;
168
- declare function pruneStickyAssignments(assignments: StickyAssignmentMap | undefined, validAccountIds: ReadonlySet<string> | undefined, now?: number, removedSessionHash?: string): StickyAssignmentMap | undefined;
169
- interface SidebarMergeHooks {
170
- beforeRecheck?: () => void | Promise<void>;
171
- }
172
- /**
173
- * Write sidebar state to disk, serialized through a promise chain so
174
- * concurrent callers never interleave or let a stale write land last.
175
- *
176
- * @param state The state to persist.
177
- * @param file Explicit path override — callers that bind the path at init
178
- * time (e.g. the index.ts loader) pass this so late callbacks
179
- * always write to the path that was current when the loader ran,
180
- * even if the env changes underneath them during tests.
181
- * Defaults to getSidebarStateFile() (per-call resolution).
182
- */
183
- declare function setSidebarState(state: SidebarState, file?: string): Promise<void>;
184
- type SidebarMachineState = Pick<SidebarState, 'main' | 'fallbacks' | 'planType' | 'credits' | 'lastUpdated'> & {
185
- route: string;
186
- };
187
- declare function setSidebarMachineState(machineState: SidebarMachineState, file?: string, hooks?: SidebarMergeHooks): Promise<void>;
188
- declare function upsertSidebarActiveRouting(input: {
189
- sessionId: string;
190
- } & ActiveRoutingEntry, accounts: readonly SidebarRoutingAccount[] | undefined, file?: string, hooks?: SidebarMergeHooks): Promise<void>;
191
- declare function setSidebarLegacyRouting(input: ActiveRoutingEntry, file?: string): Promise<void>;
192
- declare function removeSidebarActiveRouting(sessionId: string, accounts: readonly SidebarRoutingAccount[] | undefined, file?: string, hooks?: SidebarMergeHooks): Promise<void>;
193
- declare function resolveSidebarStickyAssignment(input: ResolveStickyAssignmentInput, file?: string, hooks?: SidebarMergeHooks): Promise<StickyAssignment | undefined>;
194
- declare function clearSidebarStickyAssignment(sessionId: string, file?: string): Promise<boolean>;
195
- /**
196
- * Await all pending sidebar writes. Tests call this before restoring env
197
- * vars in teardown so no in-flight write can re-resolve getSidebarStateFile()
198
- * after the env is changed.
199
- */
200
- declare function drainSidebarWrites(): Promise<void>;
201
- declare function resolveActiveAccount(state: SidebarState): {
202
- id: string;
203
- name: string;
204
- quota: AccountQuota | null;
205
- killed: boolean;
206
- };
207
- declare function getCollapsedQuotaSummary(quota: AccountQuota | null): {
208
- primaryUsedPercent: number | null;
209
- secondaryUsedPercent: number | null;
210
- text: string | null;
211
- };
212
- interface QuotaPacing {
213
- pacePercent: number;
214
- deltaPercent: number;
215
- state: 'deficit' | 'reserve' | 'on-pace';
216
- runsOutAt: string | null;
217
- }
218
- declare function computeQuotaPacing(window: QuotaWindow, windowMs: number, now: number): QuotaPacing | null;
219
- //#endregion
220
- export { getCollapsedQuotaSummary as A, pruneStickyAssignments as B, StickyAssignmentChoice as C, drainSidebarWrites as D, computeQuotaPacing as E, isQuotaExhausted as F, resolveSidebarStickyAssignment as G, resolveActiveAccount as H, isUsableRoutingEntry as I, setSidebarState as J, setSidebarLegacyRouting as K, normalizeSidebarState as L, getSidebarState as M, getSidebarStateFile as N, exhaustedQuotaResetAt as O, hashSidebarSessionId as P, VaultCustodyState as Q, projectCustodyForSidebar as R, StickyAssignment as S, clearSidebarStickyAssignment as T, resolveSessionSidebarRouting as U, removeSidebarActiveRouting as V, resolveSessionStickyAccount as W, upsertSidebarActiveRouting as X, spendControlExhaustedResetAt as Y, CustodyInertReason as Z, SidebarCustodyState as _, ActiveRoutingMap as a, SidebarState as b, QuotaPacing as c, ResolveStickyAssignmentInput as d, STICKY_ASSIGNMENT_MAX_AGE_MS as f, SidebarCustodyReason as g, SidebarAccountState as h, ActiveRoutingEntry as i, getPresentQuotaWindows as j, formatWindowLabel as k, QuotaWindow as l, SidebarAccountCustody as m, ACTIVE_ROUTING_MAX_ENTRIES as n, DEFAULT_SIDEBAR_STATE as o, STICKY_ASSIGNMENT_MAX_ENTRIES as p, setSidebarMachineState as q, AccountQuota as r, PresentQuotaWindow as s, ACTIVE_ROUTING_MAX_AGE_MS as t, QuotaWindowKey as u, SidebarMachineState as v, StickyAssignmentMap as w, SpendControlReading as x, SidebarRoutingAccount as y, pruneActiveRouting as z };
@@ -1 +0,0 @@
1
- import{b as a}from"./index-sdt2d2ra.js";import"./index-9ehhb051.js";export default a();
@@ -1,114 +0,0 @@
1
- import { realpathSync } from 'node:fs'
2
- import { homedir } from 'node:os'
3
- import { basename, dirname, join, resolve } from 'node:path'
4
- import {
5
- ACCOUNT_FILE_NAME,
6
- ACCOUNT_STATE_FILE_NAME,
7
- type AccountPaths,
8
- deriveStatePath,
9
- } from '../shared/internal.ts'
10
-
11
- /**
12
- * Where OpenCode's account store lives.
13
- *
14
- * This is the ONLY definition of this host's resolution rules. The store code
15
- * itself takes both paths as arguments and resolves nothing, so the lock and
16
- * the write it guards can never disagree about which file they mean — a
17
- * disagreement would lose mutual exclusion on a file holding credentials while
18
- * every test still passed, since each side works on its own.
19
- *
20
- * The file names come from the core so the two hosts cannot drift apart on what
21
- * the store is called.
22
- */
23
-
24
- export type { AccountPaths }
25
- export { ACCOUNT_FILE_NAME, ACCOUNT_STATE_FILE_NAME, deriveStatePath }
26
-
27
- function getConfigDir() {
28
- if (process.env.OPENCODE_CONFIG_DIR?.trim()) {
29
- return process.env.OPENCODE_CONFIG_DIR.trim()
30
- }
31
- return join(
32
- process.env.XDG_CONFIG_HOME || join(homedir(), '.config'),
33
- 'opencode',
34
- )
35
- }
36
-
37
- export function getAccountStoragePath() {
38
- return (
39
- process.env.OPENCODE_OPENAI_AUTH_FILE?.trim() ||
40
- join(getConfigDir(), ACCOUNT_FILE_NAME)
41
- )
42
- }
43
-
44
- function normalizePathForComparison(path: string, platform: NodeJS.Platform) {
45
- const resolved = resolve(path)
46
- return platform === 'win32' || platform === 'darwin'
47
- ? resolved.toLowerCase()
48
- : resolved
49
- }
50
-
51
- function realpathForComparison(path: string): string | undefined {
52
- try {
53
- return realpathSync.native(path)
54
- } catch {
55
- try {
56
- return join(realpathSync.native(dirname(path)), basename(path))
57
- } catch {
58
- return undefined
59
- }
60
- }
61
- }
62
-
63
- /**
64
- * Detect path aliases without requiring either file to exist. This is defense
65
- * in depth: hardlinks and bind mounts can still make distinct paths share a
66
- * file, because neither is distinguishable through pathname identity.
67
- */
68
- export function accountPathsCollide(
69
- configPath: string,
70
- statePath: string,
71
- platform: NodeJS.Platform = process.platform,
72
- ) {
73
- if (
74
- normalizePathForComparison(configPath, platform) ===
75
- normalizePathForComparison(statePath, platform)
76
- ) {
77
- return true
78
- }
79
-
80
- const configIdentity = realpathForComparison(configPath)
81
- const stateIdentity = realpathForComparison(statePath)
82
- return (
83
- configIdentity !== undefined &&
84
- stateIdentity !== undefined &&
85
- normalizePathForComparison(configIdentity, platform) ===
86
- normalizePathForComparison(stateIdentity, platform)
87
- )
88
- }
89
-
90
- export function getAccountStatePath(configPath = getAccountStoragePath()) {
91
- const explicit = process.env.OPENCODE_OPENAI_AUTH_STATE_FILE?.trim()
92
- if (explicit) {
93
- if (accountPathsCollide(configPath, explicit)) {
94
- throw new Error(
95
- `OPENCODE_OPENAI_AUTH_STATE_FILE resolves to the config path (${resolve(configPath)}). Set OPENCODE_OPENAI_AUTH_STATE_FILE to a different file.`,
96
- )
97
- }
98
- return explicit
99
- }
100
- return deriveStatePath(configPath)
101
- }
102
-
103
- /**
104
- * Both file paths a store call needs, resolved the way this host resolves them.
105
- *
106
- * Every call site that used to pass a single config path and let the store
107
- * derive the state path now passes this pair instead, so the state-file
108
- * override keeps being honoured in exactly the places it was before.
109
- */
110
- export function getAccountPaths(
111
- configPath = getAccountStoragePath(),
112
- ): AccountPaths {
113
- return { configPath, statePath: getAccountStatePath(configPath) }
114
- }
@@ -1,243 +0,0 @@
1
- export type CustodyMode = 'local' | 'claustrum'
2
-
3
- export type ManifestCustodyState = 'absent' | 'present' | 'unreadable'
4
-
5
- export type LocalCustodyState =
6
- | 'real'
7
- | 'tombstone'
8
- | 'empty'
9
- | 'gone'
10
- | 'slot-absent'
11
-
12
- export type VaultCustodyState =
13
- | 'serves'
14
- | 'cold'
15
- | 'needs_reauth'
16
- | 'identity_mismatch'
17
- | 'no_handle'
18
-
19
- export const CUSTODY_INERT_REASONS = [
20
- 'needs-login',
21
- 'mode-mismatch',
22
- 'corrupt-under-binding',
23
- 'manifest-unreadable',
24
- 'unbound-under-claustrum',
25
- 'orphan-tombstone',
26
- 'vault-cold',
27
- 'vault-reauth',
28
- 'identity-mismatch',
29
- 'no-handle',
30
- 'takeover-incomplete',
31
- 'new-local-family-under-claustrum',
32
- 'takeover-incomplete/vault-unavailable',
33
- 'takeover-incomplete/slot-absent',
34
- ] as const
35
-
36
- export type CustodyInertReason = (typeof CUSTODY_INERT_REASONS)[number]
37
-
38
- export type CustodyVerdict =
39
- | { kind: 'LOCAL' }
40
- | {
41
- kind: 'VAULT'
42
- canonicalize?: boolean
43
- installTombstone?: boolean
44
- }
45
- | {
46
- kind: 'INERT'
47
- reason: CustodyInertReason
48
- installTombstone?: boolean
49
- canonicalize?: boolean
50
- }
51
- | { kind: 'NEEDS_LOGIN'; reason?: 'corrupt' }
52
-
53
- export interface EvaluateCustodyStartupInput {
54
- mode: CustodyMode
55
- manifest: ManifestCustodyState
56
- local: LocalCustodyState
57
- vault: () => VaultCustodyState
58
- manifestFailureReason?: string
59
- fingerprintMatch?: boolean
60
- verifiedInProcessLogin: boolean
61
- isMain?: boolean
62
- }
63
-
64
- function unreachable(value: never): never {
65
- return value
66
- }
67
-
68
- function withCanonicalization<
69
- T extends Extract<CustodyVerdict, { kind: 'VAULT' | 'INERT' }>,
70
- >(local: LocalCustodyState, verdict: T): T | (T & { canonicalize: true }) {
71
- return local === 'empty' ? { ...verdict, canonicalize: true } : verdict
72
- }
73
-
74
- function evaluateLocal(local: LocalCustodyState): CustodyVerdict {
75
- switch (local) {
76
- case 'real':
77
- return { kind: 'LOCAL' }
78
- case 'tombstone':
79
- case 'empty':
80
- case 'slot-absent':
81
- return { kind: 'NEEDS_LOGIN' }
82
- case 'gone':
83
- return { kind: 'NEEDS_LOGIN', reason: 'corrupt' }
84
- }
85
- return unreachable(local)
86
- }
87
-
88
- function evaluateLocalWithBinding(
89
- local: LocalCustodyState,
90
- verifiedInProcessLogin: boolean,
91
- ): CustodyVerdict {
92
- switch (local) {
93
- case 'real':
94
- return verifiedInProcessLogin
95
- ? { kind: 'LOCAL' }
96
- : { kind: 'INERT', reason: 'needs-login' }
97
- case 'tombstone':
98
- case 'empty':
99
- case 'slot-absent':
100
- return { kind: 'INERT', reason: 'mode-mismatch' }
101
- case 'gone':
102
- return { kind: 'INERT', reason: 'corrupt-under-binding' }
103
- }
104
- return unreachable(local)
105
- }
106
-
107
- function evaluateUnboundClaustrum(local: LocalCustodyState): CustodyVerdict {
108
- switch (local) {
109
- case 'tombstone':
110
- case 'empty':
111
- return { kind: 'INERT', reason: 'orphan-tombstone' }
112
- case 'real':
113
- case 'gone':
114
- case 'slot-absent':
115
- return { kind: 'INERT', reason: 'unbound-under-claustrum' }
116
- }
117
- return unreachable(local)
118
- }
119
-
120
- function evaluateTombstone(
121
- local: Extract<LocalCustodyState, 'tombstone' | 'empty'>,
122
- vault: VaultCustodyState,
123
- ): CustodyVerdict {
124
- switch (vault) {
125
- case 'serves':
126
- return withCanonicalization(local, { kind: 'VAULT' })
127
- case 'cold':
128
- return withCanonicalization(local, {
129
- kind: 'INERT',
130
- reason: 'vault-cold',
131
- })
132
- case 'needs_reauth':
133
- return withCanonicalization(local, {
134
- kind: 'INERT',
135
- reason: 'vault-reauth',
136
- })
137
- case 'identity_mismatch':
138
- return withCanonicalization(local, {
139
- kind: 'INERT',
140
- reason: 'identity-mismatch',
141
- })
142
- case 'no_handle':
143
- return withCanonicalization(local, { kind: 'INERT', reason: 'no-handle' })
144
- }
145
- return unreachable(vault)
146
- }
147
-
148
- function evaluateReal(
149
- vault: VaultCustodyState,
150
- fingerprintMatch: boolean | undefined,
151
- ): CustodyVerdict {
152
- switch (vault) {
153
- case 'serves':
154
- return fingerprintMatch === false
155
- ? { kind: 'INERT', reason: 'new-local-family-under-claustrum' }
156
- : { kind: 'INERT', reason: 'takeover-incomplete' }
157
- case 'cold':
158
- case 'needs_reauth':
159
- return { kind: 'INERT', reason: 'takeover-incomplete/vault-unavailable' }
160
- case 'identity_mismatch':
161
- return { kind: 'INERT', reason: 'identity-mismatch' }
162
- case 'no_handle':
163
- return { kind: 'INERT', reason: 'no-handle' }
164
- }
165
- return unreachable(vault)
166
- }
167
-
168
- function evaluateGone(vault: VaultCustodyState): CustodyVerdict {
169
- switch (vault) {
170
- case 'serves':
171
- return { kind: 'VAULT', installTombstone: true }
172
- case 'cold':
173
- return { kind: 'INERT', reason: 'vault-cold', installTombstone: true }
174
- case 'needs_reauth':
175
- return { kind: 'INERT', reason: 'vault-reauth', installTombstone: true }
176
- case 'identity_mismatch':
177
- return { kind: 'INERT', reason: 'identity-mismatch' }
178
- case 'no_handle':
179
- return { kind: 'INERT', reason: 'no-handle' }
180
- }
181
- return unreachable(vault)
182
- }
183
-
184
- function evaluateSlotAbsent(vault: VaultCustodyState): CustodyVerdict {
185
- switch (vault) {
186
- case 'serves':
187
- case 'cold':
188
- case 'needs_reauth':
189
- return { kind: 'INERT', reason: 'takeover-incomplete/slot-absent' }
190
- case 'identity_mismatch':
191
- return { kind: 'INERT', reason: 'identity-mismatch' }
192
- case 'no_handle':
193
- return { kind: 'INERT', reason: 'no-handle' }
194
- }
195
- return unreachable(vault)
196
- }
197
-
198
- function evaluatePresentClaustrum(
199
- local: LocalCustodyState,
200
- vault: VaultCustodyState,
201
- fingerprintMatch: boolean | undefined,
202
- ): CustodyVerdict {
203
- switch (local) {
204
- case 'tombstone':
205
- case 'empty':
206
- return evaluateTombstone(local, vault)
207
- case 'real':
208
- return evaluateReal(vault, fingerprintMatch)
209
- case 'gone':
210
- return evaluateGone(vault)
211
- case 'slot-absent':
212
- return evaluateSlotAbsent(vault)
213
- }
214
- return unreachable(local)
215
- }
216
-
217
- export function evaluateCustodyStartup(
218
- input: EvaluateCustodyStartupInput,
219
- ): CustodyVerdict {
220
- if (input.manifest === 'unreadable') {
221
- return { kind: 'INERT', reason: 'manifest-unreadable' }
222
- }
223
-
224
- switch (input.mode) {
225
- case 'local':
226
- return input.manifest === 'present'
227
- ? evaluateLocalWithBinding(input.local, input.verifiedInProcessLogin)
228
- : evaluateLocal(input.local)
229
- case 'claustrum':
230
- if (input.manifest === 'absent') {
231
- return evaluateUnboundClaustrum(input.local)
232
- }
233
- if (input.manifest === 'present') {
234
- return evaluatePresentClaustrum(
235
- input.local,
236
- input.vault(),
237
- input.fingerprintMatch,
238
- )
239
- }
240
- return unreachable(input.manifest)
241
- }
242
- return unreachable(input.mode)
243
- }
@@ -1,53 +0,0 @@
1
- /**
2
- * OpenCode's log destination.
3
- *
4
- * The logger itself lives in the shared core so both hosts get the same
5
- * redaction rules. What stays here is the part that is specific to this host:
6
- * which file the lines go to, which level floor applies, and when the buffer is
7
- * drained at process exit. Those are the only three things that read this
8
- * host's environment variables, and the core reads none.
9
- *
10
- * The init runs at module load rather than from one call site because every
11
- * entry point in this package — the plugin loader, the RPC server, the separate
12
- * TUI process — reaches the logger through this module, and a core logger no
13
- * host has initialised silently drops every line. Both values are passed as
14
- * functions so the destination and level keep resolving on each write, which is
15
- * what they do today.
16
- */
17
- import { tmpdir } from 'node:os'
18
- import { join } from 'node:path'
19
- import {
20
- flushLogs,
21
- initLogger,
22
- type Level,
23
- } from '../shared/internal.ts'
24
-
25
- export {
26
- createLogger,
27
- flushForTest,
28
- flushLogs,
29
- type Level,
30
- redact,
31
- redactStrings,
32
- setLogLevel,
33
- } from '../shared/internal.ts'
34
-
35
- const LEVELS: readonly Level[] = ['error', 'warn', 'info', 'debug', 'trace']
36
-
37
- export function getLogFile(): string {
38
- return (
39
- process.env.OPENCODE_OPENAI_AUTH_LOG_FILE ??
40
- join(tmpdir(), 'opencode-openai-auth.log')
41
- )
42
- }
43
-
44
- export function getEnvLogLevel(): Level | undefined {
45
- const env = process.env.OPENCODE_OPENAI_AUTH_LOG_LEVEL as Level | undefined
46
- return env && LEVELS.includes(env) ? env : undefined
47
- }
48
-
49
- initLogger({ file: getLogFile, level: getEnvLogLevel })
50
-
51
- // Under `bun test` the buffer is drained explicitly by the tests that assert on
52
- // it, and registering a process-wide exit handler per test file is noise.
53
- if (process.env.NODE_ENV !== 'test') process.on('exit', flushLogs)