@cortexkit/opencode-openai-auth 1.0.4 → 1.1.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 (104) hide show
  1. package/dist/bin.js +9 -8
  2. package/dist/{pool-lifecycle-DqKq8Eej.d.ts → codex-request-BXDXToyt.d.ts} +158 -27
  3. package/dist/index-0yh85bwb.js +69 -0
  4. package/dist/{index-jye6vccc.js → index-4c8yw54k.js} +2 -2
  5. package/dist/{index-k4eacw7x.js → index-7c6sxtd6.js} +2 -2
  6. package/dist/index-7eb3dw37.js +90 -0
  7. package/dist/index-8re8rprk.js +2 -0
  8. package/dist/{index-bgq9d21h.js → index-csky2xpg.js} +1 -1
  9. package/dist/index-edbdscy7.js +65 -0
  10. package/dist/{index-45qgkb0m.js → index-f2fmb596.js} +1 -1
  11. package/dist/{index-envpbt0k.js → index-j8v2xwq6.js} +1 -1
  12. package/dist/{index-egrty6tz.js → index-k6cydkgt.js} +2 -2
  13. package/dist/{index-dryydk6b.js → index-m5qmvr6c.js} +2 -2
  14. package/dist/index-msx2m78k.js +8 -0
  15. package/dist/{index-yeyp8t0k.js → index-zpm95mt5.js} +1 -1
  16. package/dist/index.d.ts +15 -7
  17. package/dist/index.js +1 -1
  18. package/dist/{map-CCbSZIhT.d.ts → map-Buq-GW7l.d.ts} +1 -1
  19. package/dist/{protocol-CSIDDBDf.d.ts → model-YRg7Uowo.d.ts} +67 -25
  20. package/dist/{port-file-CZ9MIdy2.d.ts → port-file-CxEpgSHY.d.ts} +1 -1
  21. package/dist/protocol-CDV1Pc6h.d.ts +29 -0
  22. package/dist/rpc/port-file.d.ts +1 -1
  23. package/dist/rpc/port-file.js +1 -1
  24. package/dist/rpc/protocol.d.ts +1 -1
  25. package/dist/rpc/protocol.js +1 -1
  26. package/dist/rpc/rpc-client.d.ts +3 -3
  27. package/dist/rpc/rpc-client.js +1 -1
  28. package/dist/rpc/rpc-dir.js +1 -1
  29. package/dist/{sidebar-state-BCxFpH68.d.ts → sidebar-state-DjTWUbmf.d.ts} +15 -9
  30. package/dist/sidebar-state.d.ts +1 -1
  31. package/dist/sidebar-state.js +1 -1
  32. package/dist/{token-vykm9bxh.js → token-rz4t3ay6.js} +1 -1
  33. package/dist/token-util-tpy2c7h6.js +1 -0
  34. package/dist/tui-preferences.js +1 -1
  35. package/dist/tui.d.ts +20 -2
  36. package/dist/v2/server.d.ts +73 -1
  37. package/dist/v2/server.js +3 -3
  38. package/package.json +2 -2
  39. package/src/tui-compiled/raw/shared/0332701351b3eeec-format.js +78 -42
  40. package/src/tui-compiled/raw/shared/0f77ebc3c914c9c6-custody.js +354 -0
  41. package/src/tui-compiled/raw/shared/134b008900698fe0-backoff.js +92 -0
  42. package/src/tui-compiled/raw/shared/169b2b4bf30909bc-consumer.js +393 -0
  43. package/src/tui-compiled/raw/shared/2577ec69f9973ae9-quota-normalize.js +154 -0
  44. package/src/tui-compiled/raw/shared/2dce6e9613993329-quota-manager.js +473 -0
  45. package/src/tui-compiled/raw/shared/30f5bc480f31f51c-roster.js +566 -0
  46. package/src/tui-compiled/raw/shared/43fc9e6b994519c7-refresh-lock.js +0 -1
  47. package/src/tui-compiled/raw/shared/4593a4d71edf69fd-tombstone.js +25 -0
  48. package/src/tui-compiled/raw/shared/4d05c2d7a531aece-oauth.js +500 -0
  49. package/src/tui-compiled/raw/shared/6371b24a0573d79e-any-signal.js +42 -0
  50. package/src/tui-compiled/raw/shared/7c140680fc81be92-interlock.js +29 -0
  51. package/src/tui-compiled/raw/shared/85512cc5263ba259-provider.js +87 -0
  52. package/src/tui-compiled/raw/shared/abd062d633e29fd2-pool-routing.js +192 -0
  53. package/src/tui-compiled/raw/shared/b9588ad4725c1d10-enrollment.js +806 -0
  54. package/src/tui-compiled/raw/shared/bfbdd0f9aae56b47-pool-quota.js +85 -0
  55. package/src/tui-compiled/raw/shared/c852a15cfe489d12-pool.js +0 -1
  56. package/src/tui-compiled/raw/shared/ca0fccaba1d87af4-errors.js +8 -0
  57. package/src/tui-compiled/raw/shared/d0f0b6be200311af-insula.js +152 -0
  58. package/src/tui-compiled/raw/shared/d5a8f1061ee2f114-index.js +1 -1
  59. package/src/tui-compiled/raw/shared/d9d2892a4c371301-host-slot.js +72 -0
  60. package/src/tui-compiled/raw/shared/dbc61cd405941828-accounts.js +1470 -0
  61. package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +26 -12
  62. package/src/tui-compiled/raw/shared/e8d3c8da776ef9cd-index.js +24 -0
  63. package/src/tui-compiled/raw/sidebar-state.js +41 -14
  64. package/src/tui-compiled/raw/tui/command-dialogs.tsx +3 -34
  65. package/src/tui-compiled/raw/tui/section-text.js +21 -0
  66. package/src/tui-compiled/raw/tui/v2-dialog.js +137 -0
  67. package/src/tui-compiled/raw/tui/v2.tsx +133 -0
  68. package/src/tui-compiled/raw/tui.tsx +146 -40
  69. package/src/tui-compiled/runtime/shared/0332701351b3eeec-format.js +78 -42
  70. package/src/tui-compiled/runtime/shared/0f77ebc3c914c9c6-custody.js +354 -0
  71. package/src/tui-compiled/runtime/shared/134b008900698fe0-backoff.js +92 -0
  72. package/src/tui-compiled/runtime/shared/169b2b4bf30909bc-consumer.js +393 -0
  73. package/src/tui-compiled/runtime/shared/2577ec69f9973ae9-quota-normalize.js +154 -0
  74. package/src/tui-compiled/runtime/shared/2dce6e9613993329-quota-manager.js +473 -0
  75. package/src/tui-compiled/runtime/shared/30f5bc480f31f51c-roster.js +566 -0
  76. package/src/tui-compiled/runtime/shared/43fc9e6b994519c7-refresh-lock.js +0 -1
  77. package/src/tui-compiled/runtime/shared/4593a4d71edf69fd-tombstone.js +25 -0
  78. package/src/tui-compiled/runtime/shared/4d05c2d7a531aece-oauth.js +500 -0
  79. package/src/tui-compiled/runtime/shared/6371b24a0573d79e-any-signal.js +42 -0
  80. package/src/tui-compiled/runtime/shared/7c140680fc81be92-interlock.js +29 -0
  81. package/src/tui-compiled/runtime/shared/85512cc5263ba259-provider.js +87 -0
  82. package/src/tui-compiled/runtime/shared/abd062d633e29fd2-pool-routing.js +192 -0
  83. package/src/tui-compiled/runtime/shared/b9588ad4725c1d10-enrollment.js +806 -0
  84. package/src/tui-compiled/runtime/shared/bfbdd0f9aae56b47-pool-quota.js +85 -0
  85. package/src/tui-compiled/runtime/shared/c852a15cfe489d12-pool.js +0 -1
  86. package/src/tui-compiled/runtime/shared/ca0fccaba1d87af4-errors.js +8 -0
  87. package/src/tui-compiled/runtime/shared/d0f0b6be200311af-insula.js +152 -0
  88. package/src/tui-compiled/runtime/shared/d5a8f1061ee2f114-index.js +1 -1
  89. package/src/tui-compiled/runtime/shared/d9d2892a4c371301-host-slot.js +72 -0
  90. package/src/tui-compiled/runtime/shared/dbc61cd405941828-accounts.js +1470 -0
  91. package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +26 -12
  92. package/src/tui-compiled/runtime/shared/e8d3c8da776ef9cd-index.js +24 -0
  93. package/src/tui-compiled/runtime/sidebar-state.js +41 -14
  94. package/src/tui-compiled/runtime/tui/command-dialogs.js +3 -15
  95. package/src/tui-compiled/runtime/tui/section-text.js +21 -0
  96. package/src/tui-compiled/runtime/tui/v2-dialog.js +137 -0
  97. package/src/tui-compiled/runtime/tui/v2.js +95 -0
  98. package/src/tui-compiled/runtime/tui.js +255 -163
  99. package/dist/index-2hch7e8n.js +0 -8
  100. package/dist/index-5dg931q0.js +0 -65
  101. package/dist/index-99esnzg0.js +0 -157
  102. package/dist/index-9reyazwh.js +0 -2
  103. package/dist/index-yf6arn5w.js +0 -2
  104. package/dist/token-util-gmn5yaqc.js +0 -1
@@ -0,0 +1,192 @@
1
+ import { projectQuota } from "./d5a8f1061ee2f114-index.js";
2
+ import {
3
+ admit,
4
+ decideStickyBreak,
5
+ orderForPlacement,
6
+ routeOrdered,
7
+ routeSticky
8
+ } from "./3e7d45a77c6ad4d5-index.js";
9
+ import {
10
+ isKillswitchEnabled,
11
+ killswitchPassesPolicy
12
+ } from "./dbc61cd405941828-accounts.js";
13
+ import { windowsFromQuotaMap } from "./bfbdd0f9aae56b47-pool-quota.js";
14
+ export const FORMER_MAIN_ID = "main";
15
+ export function vaultMainRouteId(routes) {
16
+ return routes.find((route) => route.id.startsWith("vault:") && route.credentialId === "chatgpt:openai")?.id ?? null;
17
+ }
18
+ export function poolKillswitchVerdicts(accounts, storage, now) {
19
+ const verdicts = new Map;
20
+ if (isKillswitchEnabled(storage))
21
+ for (const account of accounts)
22
+ verdicts.set(account.id, killswitchPassesPolicy(windowsFromQuotaMap(account.quota), storage, account.id === FORMER_MAIN_ID ? void 0 : account.id, now));
23
+ return verdicts;
24
+ }
25
+ export const POOL_QUOTA_UNKNOWN_RETRY_SECONDS = 5, FIRST_QUOTA_READING_WAIT_MS = 5000;
26
+ export function orderedPlacement(mode) {
27
+ if (mode === "ordered")
28
+ return "roster";
29
+ return mode === "fallback-first" ? "fallback-first" : "main-first";
30
+ }
31
+ export function waitForFirstQuotaReading(input, waitMs = FIRST_QUOTA_READING_WAIT_MS) {
32
+ const rows = input.rows.filter((row) => row.kind === "oauth" && input.killswitch.get(row.id) !== !1 && projectQuota(row.quota).limits.length === 0);
33
+ if (rows.length === 0)
34
+ return;
35
+ if (admit({
36
+ rows: input.rows,
37
+ now: input.now,
38
+ rateLimitMarks: input.rateLimitMarks,
39
+ refreshBackoff: input.refreshBackoff,
40
+ requestPull: () => {}
41
+ }).admitted.some((row) => input.killswitch.get(row.id) !== !1))
42
+ return;
43
+ const pulls = [];
44
+ admit({
45
+ rows,
46
+ now: input.now,
47
+ rateLimitMarks: input.rateLimitMarks,
48
+ refreshBackoff: input.refreshBackoff,
49
+ requestPull: (id) => {
50
+ const pending = input.requestPull(id);
51
+ if (pending)
52
+ pulls.push(pending.catch(() => {}));
53
+ }
54
+ });
55
+ if (pulls.length === 0)
56
+ return;
57
+ let timer;
58
+ return Promise.race([
59
+ Promise.all(pulls),
60
+ new Promise((resolve) => {
61
+ timer = setTimeout(resolve, waitMs);
62
+ })
63
+ ]).then(() => {}).finally(() => clearTimeout(timer));
64
+ }
65
+ function isConfirmedExhaustion(refusal) {
66
+ return refusal.reason === "exhausted" || refusal.reason === "budget-spent";
67
+ }
68
+ export function blockFor(id, admission, killswitch) {
69
+ if (id === void 0)
70
+ return { reason: "no-credential" };
71
+ if (killswitch.get(id) === !1)
72
+ return { reason: "killswitch" };
73
+ const exclusion = admission.excluded.find((entry) => entry.id === id);
74
+ if (exclusion?.reason === "rate-limited")
75
+ return { reason: "mid-stream-rate-limit", resetAtMs: exclusion.until };
76
+ if (exclusion)
77
+ return { reason: "no-credential" };
78
+ const refusal = admission.refused.find((entry) => entry.id === id);
79
+ if (refusal && "resetAtMs" in refusal)
80
+ return { reason: "quota-exhausted", resetAtMs: refusal.resetAtMs };
81
+ if (refusal)
82
+ return { reason: "quota-unknown" };
83
+ return { reason: "no-credential" };
84
+ }
85
+ function routeBlock(ids, admission, killswitch) {
86
+ if (admission.refused.find((refusal) => !isConfirmedExhaustion(refusal) && killswitch.get(refusal.id) !== !1))
87
+ return { reason: "quota-unknown" };
88
+ return blockFor(ids[0], admission, killswitch);
89
+ }
90
+ export function planOrdered(input) {
91
+ const replayable = input.replayable !== !1, mainId = input.mainId === void 0 ? FORMER_MAIN_ID : input.mainId ?? "", placement = replayable ? input.placement : "main-first", route = routeOrdered({
92
+ rows: input.rows,
93
+ placement,
94
+ formerMainId: mainId,
95
+ killswitch: input.killswitch,
96
+ rateLimitMarks: input.rateLimitMarks,
97
+ refreshBackoff: input.refreshBackoff,
98
+ now: input.now,
99
+ requestPull: input.requestPull
100
+ }), ids = orderForPlacement(input.rows.map((row) => row.id), placement, mainId), confirmed = new Set(route.admission.refused.filter((refusal) => isConfirmedExhaustion(refusal) && input.killswitch.get(refusal.id) !== !1).map((refusal) => refusal.id)), lastPath = ids.filter((id) => confirmed.has(id));
101
+ if (!replayable) {
102
+ const hasMain = ids.includes(mainId), target = hasMain ? mainId : route.order[0] ?? lastPath[0];
103
+ if (target !== void 0 && route.order.includes(target))
104
+ return { kind: "send", order: [target], lastPath: !1 };
105
+ if (target !== void 0 && confirmed.has(target))
106
+ return { kind: "send", order: [target], lastPath: !0 };
107
+ return {
108
+ kind: "block",
109
+ block: hasMain ? blockFor(mainId, route.admission, input.killswitch) : routeBlock(ids, route.admission, input.killswitch)
110
+ };
111
+ }
112
+ if (route.order.length > 0)
113
+ return { kind: "send", order: route.order, lastPath: !1 };
114
+ if (lastPath.length > 0)
115
+ return { kind: "send", order: lastPath, lastPath: !0 };
116
+ return {
117
+ kind: "block",
118
+ block: routeBlock(ids, route.admission, input.killswitch)
119
+ };
120
+ }
121
+ export function admitSticky(input) {
122
+ const admission = admit({
123
+ rows: input.rows,
124
+ rateLimitMarks: input.rateLimitMarks,
125
+ refreshBackoff: input.refreshBackoff,
126
+ now: input.now,
127
+ requestPull: input.requestPull
128
+ }), projections = new Map;
129
+ for (const row of input.rows)
130
+ projections.set(row.id, projectQuota(row.quota));
131
+ for (const row of admission.admitted)
132
+ if (row.projection)
133
+ projections.set(row.id, row.projection);
134
+ return {
135
+ projections,
136
+ excluded: new Set(admission.excluded.map((entry) => entry.id))
137
+ };
138
+ }
139
+ function routePoolSticky(input, options, extra) {
140
+ const exclude = extra.exclude, rows = exclude ? input.rows.filter((row) => !exclude.has(row.id)) : input.rows, resetCredits = new Map;
141
+ for (const row of rows) {
142
+ const credits = options.resetCredits(row.id);
143
+ if (credits !== void 0)
144
+ resetCredits.set(row.id, credits);
145
+ }
146
+ return routeSticky({
147
+ rows,
148
+ now: input.now,
149
+ rateLimitMarks: input.rateLimitMarks,
150
+ refreshBackoff: input.refreshBackoff,
151
+ requestPull: input.requestPull,
152
+ killswitch: input.killswitch,
153
+ requestBytes: options.requestBytes,
154
+ ...extra.pendingBytes ? { pendingBytes: extra.pendingBytes } : {},
155
+ rowReservePercent: (row) => options.reservePercent(row.id),
156
+ refusedPinPolicy: "move-on-confirmed-exhaustion",
157
+ resetCreditsApplicable: resetCredits,
158
+ ...extra.pin === void 0 ? {} : { pin: { accountId: extra.pin } },
159
+ ...options.onEmptyWeightedSet ? { onEmptyWeightedSet: options.onEmptyWeightedSet } : {}
160
+ });
161
+ }
162
+ export function selectStickyRow(input, options, exclude, pendingBytes) {
163
+ const route = routePoolSticky(input, options, { exclude, pendingBytes });
164
+ if (route.outcome !== "dispatch" || route.source === "pin")
165
+ return;
166
+ return {
167
+ accountId: route.accountId,
168
+ source: route.source,
169
+ ...route.quotaCheckedAt === void 0 ? {} : { quotaCheckedAt: route.quotaCheckedAt }
170
+ };
171
+ }
172
+ export function routePinnedRow(input, options, id) {
173
+ const killed = input.killswitch.get(id) === !1, route = routePoolSticky(input, options, { pin: id });
174
+ if (route.outcome === "dispatch") {
175
+ if (route.pin.action === "assign")
176
+ return { kind: "move", reason: killed ? "killswitch" : "exhausted" };
177
+ return route.accountId === id ? { kind: "serve" } : { kind: "detour" };
178
+ }
179
+ const refusal = route.admission.refused.find((entry) => entry.id === id);
180
+ if (!killed && refusal && isConfirmedExhaustion(refusal))
181
+ return { kind: "last-path" };
182
+ return { kind: "none" };
183
+ }
184
+ export function stickyBreak(input, sticky, id, status) {
185
+ const killswitchPasses = input.killswitch.get(id);
186
+ return decideStickyBreak({
187
+ quota: sticky.projections.get(id),
188
+ now: input.now,
189
+ ...status === void 0 ? {} : { status },
190
+ ...killswitchPasses === void 0 ? {} : { killswitchPasses }
191
+ });
192
+ }