@cortexkit/opencode-openai-auth 1.7.0 → 1.8.1

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 (81) hide show
  1. package/dist/bin.js +9 -9
  2. package/dist/{codex-request-CN4rD2kf.d.ts → codex-request-GJkvxv4S.d.ts} +51 -57
  3. package/dist/{index-b5459de4.js → index-21yxzeet.js} +2 -2
  4. package/dist/index-4rf3rkdm.js +2 -0
  5. package/dist/{index-dr93b3g6.js → index-73z9ftrg.js} +6 -6
  6. package/dist/index-97cz7kyq.js +74 -0
  7. package/dist/index-b7p76qqa.js +91 -0
  8. package/dist/{index-r4avvxf0.js → index-c50p5mem.js} +1 -1
  9. package/dist/{index-p9vnmnzr.js → index-fhcnxrtz.js} +1 -1
  10. package/dist/{index-7zy4vdd3.js → index-h1r8cbet.js} +2 -2
  11. package/dist/{index-jaqm1xda.js → index-hpnj460b.js} +1 -1
  12. package/dist/{index-yayz83vv.js → index-mg4w434p.js} +2 -2
  13. package/dist/{index-g08eptzm.js → index-p8m4yh73.js} +1 -1
  14. package/dist/index-vh1sr50d.js +63 -0
  15. package/dist/index-ww8w9edq.js +2 -0
  16. package/dist/index.d.ts +4 -12
  17. package/dist/index.js +1 -1
  18. package/dist/{port-file-8ElfwDcq.d.ts → port-file-DXCxv8tU.d.ts} +0 -2
  19. package/dist/{protocol-BeeDdtpa.d.ts → protocol-BZZtDn5h.d.ts} +0 -4
  20. package/dist/rpc/port-file.d.ts +4 -4
  21. package/dist/rpc/port-file.js +1 -1
  22. package/dist/rpc/protocol.d.ts +1 -1
  23. package/dist/rpc/protocol.js +1 -1
  24. package/dist/rpc/rpc-client.d.ts +1 -1
  25. package/dist/rpc/rpc-client.js +1 -1
  26. package/dist/rpc/rpc-dir.d.ts +0 -2
  27. package/dist/rpc/rpc-dir.js +1 -1
  28. package/dist/{rpc-client-DlR9a0_7.d.ts → rpc-client-CmaZW1by.d.ts} +2 -6
  29. package/dist/{sidebar-state-DHsZ9axt.d.ts → sidebar-state-DkNebAiC.d.ts} +3 -11
  30. package/dist/sidebar-state.d.ts +1 -1
  31. package/dist/sidebar-state.js +1 -1
  32. package/dist/{token-511npvw8.js → token-3vtr29vt.js} +1 -1
  33. package/dist/token-util-erhrf24m.js +1 -0
  34. package/dist/tui-preferences.d.ts +0 -2
  35. package/dist/tui-preferences.js +1 -1
  36. package/dist/tui.d.ts +3 -7
  37. package/dist/v2/server.d.ts +15 -23
  38. package/dist/v2/server.js +2 -2
  39. package/package.json +6 -6
  40. package/src/tui-compiled/raw/shared/0f77ebc3c914c9c6-custody.js +95 -11
  41. package/src/tui-compiled/raw/shared/169b2b4bf30909bc-consumer.js +320 -35
  42. package/src/tui-compiled/raw/shared/30f5bc480f31f51c-roster.js +187 -12
  43. package/src/tui-compiled/raw/shared/352d228be2832bd4-hub.js +988 -0
  44. package/src/tui-compiled/raw/shared/458b934e92490331-mutate.js +4 -0
  45. package/src/tui-compiled/raw/shared/81dddd203f1b92a3-quota-writer.js +34 -12
  46. package/src/tui-compiled/raw/shared/836fc615de6afbd9-settings.js +16 -6
  47. package/src/tui-compiled/raw/shared/88b7fc40900fb003-commit-interval.js +18 -0
  48. package/src/tui-compiled/raw/shared/92e38944b51b2405-file-read-cache.js +57 -0
  49. package/src/tui-compiled/raw/shared/a670cb7f5987bc1b-shutdown.js +42 -0
  50. package/src/tui-compiled/raw/shared/b9588ad4725c1d10-enrollment.js +37 -12
  51. package/src/tui-compiled/raw/shared/c852a15cfe489d12-pool.js +1 -1
  52. package/src/tui-compiled/raw/shared/c911dbb64c9d85c7-quota-writer.js +27 -13
  53. package/src/tui-compiled/raw/shared/dbc61cd405941828-accounts.js +42 -0
  54. package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +20 -11
  55. package/src/tui-compiled/raw/shared/e8d3c8da776ef9cd-index.js +37 -4
  56. package/src/tui-compiled/raw/sidebar-state.js +4 -2
  57. package/src/tui-compiled/raw/tui.tsx +7 -1
  58. package/src/tui-compiled/runtime/shared/0f77ebc3c914c9c6-custody.js +95 -11
  59. package/src/tui-compiled/runtime/shared/169b2b4bf30909bc-consumer.js +320 -35
  60. package/src/tui-compiled/runtime/shared/30f5bc480f31f51c-roster.js +187 -12
  61. package/src/tui-compiled/runtime/shared/352d228be2832bd4-hub.js +988 -0
  62. package/src/tui-compiled/runtime/shared/458b934e92490331-mutate.js +4 -0
  63. package/src/tui-compiled/runtime/shared/81dddd203f1b92a3-quota-writer.js +34 -12
  64. package/src/tui-compiled/runtime/shared/836fc615de6afbd9-settings.js +16 -6
  65. package/src/tui-compiled/runtime/shared/88b7fc40900fb003-commit-interval.js +18 -0
  66. package/src/tui-compiled/runtime/shared/92e38944b51b2405-file-read-cache.js +57 -0
  67. package/src/tui-compiled/runtime/shared/a670cb7f5987bc1b-shutdown.js +42 -0
  68. package/src/tui-compiled/runtime/shared/b9588ad4725c1d10-enrollment.js +37 -12
  69. package/src/tui-compiled/runtime/shared/c852a15cfe489d12-pool.js +1 -1
  70. package/src/tui-compiled/runtime/shared/c911dbb64c9d85c7-quota-writer.js +27 -13
  71. package/src/tui-compiled/runtime/shared/dbc61cd405941828-accounts.js +42 -0
  72. package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +20 -11
  73. package/src/tui-compiled/runtime/shared/e8d3c8da776ef9cd-index.js +37 -4
  74. package/src/tui-compiled/runtime/sidebar-state.js +4 -2
  75. package/src/tui-compiled/runtime/tui.js +4 -1
  76. package/dist/index-0p3cbtwq.js +0 -2
  77. package/dist/index-2e2kqmsy.js +0 -2
  78. package/dist/index-apkavdvq.js +0 -90
  79. package/dist/index-qg2syg0r.js +0 -65
  80. package/dist/index-se9ykks8.js +0 -69
  81. package/dist/token-util-jsw1zdc6.js +0 -1
@@ -186,7 +186,8 @@ export function normalizeSidebarState(raw) {
186
186
  ...stickyAssignments !== void 0 ? { stickyAssignments } : {},
187
187
  ...planType !== void 0 ? { planType } : {},
188
188
  ...r.accountPool === !0 ? { accountPool: !0 } : {},
189
- ...vaultAccounts !== void 0 ? { vaultAccounts } : {}
189
+ ...vaultAccounts !== void 0 ? { vaultAccounts } : {},
190
+ ...typeof r.vaultDiscovered === "boolean" ? { vaultDiscovered: r.vaultDiscovered } : {}
190
191
  };
191
192
  }
192
193
  function normalizeAccountList(raw) {
@@ -572,7 +573,8 @@ export function setSidebarMachineState(machineState, file = getSidebarStateFile(
572
573
  stickyAssignments,
573
574
  lastUpdated: Math.max(now, latest.lastUpdated + 1),
574
575
  accountPool: machineState.accountPool === !0 ? !0 : void 0,
575
- vaultAccounts: machineState.vaultAccounts
576
+ vaultAccounts: machineState.vaultAccounts,
577
+ vaultDiscovered: machineState.vaultDiscovered
576
578
  };
577
579
  }, hooks);
578
580
  });
@@ -1190,7 +1190,13 @@ function QuotaSidebar(props: {
1190
1190
  when={hasData()}
1191
1191
  fallback={
1192
1192
  <box marginTop={1} width='100%'>
1193
- <text fg={theme().textMuted}>{'Waiting for quota\u2026'}</text>
1193
+ <text fg={theme().textMuted}>
1194
+ {vaultMode()
1195
+ ? state().vaultDiscovered === true
1196
+ ? 'No vault accounts'
1197
+ : "Waiting for the vault's first answer"
1198
+ : 'Waiting for quota\u2026'}
1199
+ </text>
1194
1200
  </box>
1195
1201
  }
1196
1202
  >
@@ -4,6 +4,7 @@ import { ClaustrumUnreachableError, classifyVaultFailure, } from "./94f53cfd572b
4
4
  import { readClaustrumEnrollmentToken } from "./b9588ad4725c1d10-enrollment.js";
5
5
  import { ClaustrumConsumerError } from "./ca0fccaba1d87af4-errors.js";
6
6
  import { CUSTODY_PLACEHOLDER_PREFIX } from "./d9d2892a4c371301-host-slot.js";
7
+ import { drainShutdown, shutdownWarning } from "./a670cb7f5987bc1b-shutdown.js";
7
8
  import { ScopedRosterWatch, } from "./dc9290c2a7552ba6-watch.js";
8
9
  /** Only a new version of the same account may replace an in-flight 401. */
9
10
  export function isScopedCredentialRotation(served, current) {
@@ -79,15 +80,56 @@ function accessTokenFromMaterial(material) {
79
80
  return access;
80
81
  }
81
82
  function credentialTypeOf(row, family) {
83
+ const notMine = { kind: 'not-mine' };
82
84
  if (!row.operations.includes('read'))
83
- return undefined;
85
+ return notMine;
84
86
  if (!row.categories.includes(family.category))
85
- return undefined;
87
+ return notMine;
88
+ if (row.credentialType !== 'oauth' && row.credentialType !== 'api_key')
89
+ return notMine;
90
+ if ('classify' in family) {
91
+ // Older clients omit these facts entirely; do not call a policy that needs them.
92
+ const facts = {
93
+ credentialId: row.id,
94
+ credentialType: row.credentialType,
95
+ categories: row.categories,
96
+ refreshAdapter: row.refreshAdapter,
97
+ ...rowFactsOf(row),
98
+ };
99
+ if (facts.providerIds === undefined)
100
+ return { kind: 'refused', code: 'unmapped' };
101
+ try {
102
+ const result = family.classify(facts);
103
+ if (result.kind === 'not-mine')
104
+ return notMine;
105
+ if (result.kind === 'mine' && typeof result.member === 'string')
106
+ return { kind: 'mine', type: row.credentialType, member: result.member };
107
+ if (result.kind === 'refused' &&
108
+ typeof result.code === 'string' &&
109
+ /^[a-z][a-z0-9-]{0,31}$/.test(result.code) &&
110
+ !result.code.includes('\n') &&
111
+ family.refusalCodes.includes(result.code))
112
+ return { kind: 'refused', code: result.code };
113
+ }
114
+ catch {
115
+ // A classifier error may contain vault data; expose only a fixed code.
116
+ }
117
+ return { kind: 'refused', code: 'unclassified' };
118
+ }
86
119
  if (row.credentialType === 'oauth')
87
- return row.refreshAdapter === family.refreshAdapter ? 'oauth' : undefined;
120
+ return row.refreshAdapter === family.refreshAdapter
121
+ ? { kind: 'mine', type: 'oauth' }
122
+ : notMine;
88
123
  if (row.credentialType === 'api_key' && family.apiKeys)
89
- return row.refreshAdapter === undefined ? 'api_key' : undefined;
90
- return undefined;
124
+ return row.refreshAdapter === undefined
125
+ ? { kind: 'mine', type: 'api_key' }
126
+ : notMine;
127
+ return notMine;
128
+ }
129
+ /** Structural access keeps the public facts independent of client declarations. */
130
+ function rowFactsOf(row) {
131
+ const metadata = row;
132
+ return { providerIds: metadata.providerIds, authMethod: metadata.authMethod };
91
133
  }
92
134
  /**
93
135
  * The grants named in the vault's list reply, or undefined when it names none.
@@ -136,6 +178,9 @@ export class ClaustrumScopedCustody {
136
178
  /** The view of the last successful `discover()`, for `watchRoster`. */
137
179
  #discoveredView;
138
180
  #watches = new Set();
181
+ #tokenReads = new Set();
182
+ #warnShutdown;
183
+ #disposing;
139
184
  constructor(options) {
140
185
  const tokenPath = options.tokenPath;
141
186
  if (options.readToken) {
@@ -153,6 +198,7 @@ export class ClaustrumScopedCustody {
153
198
  this.#requireAssertion = options.requireAssertion ?? false;
154
199
  this.#now = options.now ?? Date.now;
155
200
  this.#logger = options.logger ?? defaultLogger;
201
+ this.#warnShutdown = shutdownWarning(this.#logger);
156
202
  this.#setTimeout = options.setTimeoutImpl ?? setTimeout;
157
203
  this.#clearTimeout = options.clearTimeoutImpl ?? clearTimeout;
158
204
  }
@@ -220,7 +266,15 @@ export class ClaustrumScopedCustody {
220
266
  }
221
267
  async #token(signal) {
222
268
  this.#check(signal);
223
- const value = await this.#readToken();
269
+ const pending = this.#readToken();
270
+ this.#tokenReads.add(pending);
271
+ let value;
272
+ try {
273
+ value = await pending;
274
+ }
275
+ finally {
276
+ this.#tokenReads.delete(pending);
277
+ }
224
278
  this.#check(signal);
225
279
  if (!/^[0-9a-f]{64}$/.test(value.token) ||
226
280
  !Number.isSafeInteger(value.token_generation) ||
@@ -299,17 +353,32 @@ export class ClaustrumScopedCustody {
299
353
  throw error;
300
354
  }
301
355
  const skipped = [];
356
+ const refused = [];
357
+ let notMine = 0;
302
358
  const candidates = [];
303
359
  const counts = new Map();
304
360
  for (const row of inventory.rows) {
305
- const type = credentialTypeOf(row, this.#family);
306
- if (!type)
361
+ const classified = credentialTypeOf(row, this.#family);
362
+ if (classified.kind === 'not-mine') {
363
+ notMine++;
364
+ continue;
365
+ }
366
+ if (classified.kind === 'refused') {
367
+ refused.push({
368
+ ...(row.id.trim() && { credentialId: row.id }),
369
+ code: classified.code,
370
+ });
307
371
  continue;
308
- candidates.push({ row, type });
372
+ }
373
+ candidates.push({
374
+ row,
375
+ type: classified.type,
376
+ ...(classified.member !== undefined && { member: classified.member }),
377
+ });
309
378
  counts.set(row.id, (counts.get(row.id) ?? 0) + 1);
310
379
  }
311
380
  const credentials = [];
312
- for (const { row, type } of candidates) {
381
+ for (const { row, type, member } of candidates) {
313
382
  let reason;
314
383
  if (!row.id.trim())
315
384
  reason = 'empty credential id';
@@ -320,12 +389,17 @@ export class ClaustrumScopedCustody {
320
389
  else if (!row.state.trim())
321
390
  reason = 'empty state';
322
391
  if (reason) {
323
- skipped.push({ ...(row.id.trim() && { credentialId: row.id }), reason });
392
+ skipped.push({
393
+ ...(row.id.trim() && { credentialId: row.id }),
394
+ ...(member !== undefined && { member }),
395
+ reason,
396
+ });
324
397
  continue;
325
398
  }
326
399
  credentials.push(Object.freeze({
327
400
  credentialId: row.id,
328
401
  credentialType: type,
402
+ ...(member !== undefined && { member }),
329
403
  ...(row.accountId !== undefined && {
330
404
  accountIdentity: row.accountId,
331
405
  }),
@@ -341,6 +415,10 @@ export class ClaustrumScopedCustody {
341
415
  view: inventory.view,
342
416
  credentials: Object.freeze(credentials),
343
417
  skipped: Object.freeze(skipped),
418
+ ...('classify' in this.#family && {
419
+ refused: Object.freeze(refused),
420
+ notMine,
421
+ }),
344
422
  ...(grantReach && { grantReach }),
345
423
  };
346
424
  }
@@ -646,4 +724,10 @@ export class ClaustrumScopedCustody {
646
724
  this.#kept.clear();
647
725
  this.#client.close();
648
726
  }
727
+ /** Stop immediately; allow token reads 2 s and share an owner's timeout warning. */
728
+ async dispose(onTimeout = this.#warnShutdown) {
729
+ this.close();
730
+ this.#disposing ??= drainShutdown(this.#tokenReads, onTimeout);
731
+ await this.#disposing;
732
+ }
649
733
  }