@cortexkit/pi-openai-auth 1.2.0 → 1.3.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.
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
2
  import "@cortexkit/private-files";
3
3
  import { ClaustrumClient, EnrollmentPollOutcome } from "@cortexkit/claustrum-client";
4
4
  import { Api, AssistantMessageEventStream, Context, Model, SimpleStreamOptions } from "@earendil-works/pi-ai";
5
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/pi-slot/slot.d.ts
5
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/pi-slot/slot.d.ts
6
6
  interface PiSlotInspection {
7
7
  slot: 'original' | 'placeholder' | 'foreign' | 'empty';
8
8
  stash: 'valid' | 'missing';
@@ -13,7 +13,7 @@ interface PiSlot {
13
13
  exitVault(): Promise<'restored' | 'conflict' | 'nothing-to-do'>;
14
14
  }
15
15
  //#endregion
16
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/store/schema.d.ts
16
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/schema.d.ts
17
17
  type OAuthCredential = {
18
18
  type: 'oauth';
19
19
  access?: string;
@@ -202,7 +202,7 @@ interface PoolRow {
202
202
  unbound?: true;
203
203
  }
204
204
  //#endregion
205
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/store/errors.d.ts
205
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/errors.d.ts
206
206
  /** Every library operation that can fail, as named in the failure value. */
207
207
  type PoolOperation = 'initialize' | 'add' | 'replace' | 'rotate' | 'disable' | 'enable' | 'remove' | 'reorder' | 'updateSettings' | 'recordIdentity' | 'updateProviderState' | 'refresh' | 'pull' | 'publishRoster';
208
208
  /**
@@ -249,12 +249,12 @@ declare class PoolOperationError extends Error {
249
249
  });
250
250
  }
251
251
  //#endregion
252
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/store/hooks.d.ts
252
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/hooks.d.ts
253
253
  interface PoolLogger {
254
254
  warn(message: string, data?: unknown): void;
255
255
  }
256
256
  //#endregion
257
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/fs/refresh-file-lock.d.ts
257
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/fs/refresh-file-lock.d.ts
258
258
  interface LockLoss {
259
259
  readonly reason: 'taken-over' | 'expired' | 'unreadable' | 'renewal-failed' | 'marker-lost';
260
260
  readonly expectedOwnerId: string;
@@ -289,7 +289,7 @@ type RefreshFileLockOptions = {
289
289
  /** Filesystem leases share wall time across all callers and processes. */
290
290
  declare function acquireRefreshFileLock(options: RefreshFileLockOptions): Promise<RefreshFileLock | null>;
291
291
  //#endregion
292
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/store/refresh-lock.d.ts
292
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/refresh-lock.d.ts
293
293
  type LockStep = NonNullable<Parameters<typeof acquireRefreshFileLock>[0]['onStep']> extends ((step: infer S) => unknown) ? S : never;
294
294
  /** Tuning shared by every lock the store takes; each field is overridable. */
295
295
  interface PoolLockOptions {
@@ -321,7 +321,7 @@ interface LockEnvironment {
321
321
  }, event: 'scheduled' | 'cancelled') => void;
322
322
  }
323
323
  //#endregion
324
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/store/mutate.d.ts
324
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/mutate.d.ts
325
325
  /** Named points on the write path, for crash and ownership injection. */
326
326
  type WriteStep = 'before-config-write' | 'after-config-write' | 'before-state-write' | 'after-state-write';
327
327
  /** Awaitable pause points on the pull and refresh paths. */
@@ -356,11 +356,11 @@ interface StoreContext {
356
356
  /** What `initializePool` did. */
357
357
  type InitializeOutcome = 'initialized' | 'already-ready';
358
358
  //#endregion
359
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/store/runtime.d.ts
359
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/runtime.d.ts
360
360
  /** Where a pull was fired from; `load` fires at most once per process per row. */
361
361
  type PullReason = 'load' | 'add' | 'replace' | 'admission';
362
362
  //#endregion
363
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/store/attribution.d.ts
363
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/attribution.d.ts
364
364
  /**
365
365
  * What a pull or refresh captured about its row (named by id alongside) when
366
366
  * it was issued. A result applies only while the row with that id still has
@@ -383,7 +383,7 @@ interface Attribution {
383
383
  identity?: string;
384
384
  }
385
385
  //#endregion
386
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/store/rows.d.ts
386
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/rows.d.ts
387
387
  type FailureHook = (rowId: string, error: PoolOperationError) => void | Promise<void>;
388
388
  interface RowOperationOptions {
389
389
  /** Called once, awaited, on every non-success path, before locks release. */
@@ -599,7 +599,7 @@ interface RowTransitionResult {
599
599
  providerState?: unknown;
600
600
  }
601
601
  //#endregion
602
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/store/provider-state.d.ts
602
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/provider-state.d.ts
603
603
  /**
604
604
  * Receives a private copy of the row's provider state (undefined when the row
605
605
  * shows none) and the row as loaded under the locks, and returns the next
@@ -635,7 +635,7 @@ declare const DECLINE_TRANSITION: unique symbol;
635
635
  */
636
636
  type RowTransitionMutator = (current: unknown | undefined, row: PoolRow) => unknown | typeof DECLINE_TRANSITION | Promise<unknown | typeof DECLINE_TRANSITION>;
637
637
  //#endregion
638
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/store/publication.d.ts
638
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/publication.d.ts
639
639
  interface PublishPlan {
640
640
  operationId: string;
641
641
  remove: Array<{
@@ -678,7 +678,7 @@ interface PublishResult {
678
678
  receipt: PublicationReceipt;
679
679
  }
680
680
  //#endregion
681
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/store/pull.d.ts
681
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/pull.d.ts
682
682
  /** What a pull is issued with: the credential and its attribution tuple. */
683
683
  interface PullRequest {
684
684
  id: string;
@@ -689,7 +689,7 @@ interface PullRequest {
689
689
  }
690
690
  type PullHook = (request: PullRequest) => Promise<unknown>;
691
691
  //#endregion
692
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/store/refresh.d.ts
692
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/refresh.d.ts
693
693
  /** What the injected provider refresh function returns. */
694
694
  interface ProviderRefreshResult {
695
695
  access: string;
@@ -752,7 +752,7 @@ type RefreshOutcome = {
752
752
  reason: string;
753
753
  };
754
754
  //#endregion
755
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/store/settings.d.ts
755
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/settings.d.ts
756
756
  /** The plugin's settings: every top-level config key except the pool-owned ones. */
757
757
  type PoolSettings = Record<string, unknown>;
758
758
  type SettingsRead = {
@@ -796,7 +796,7 @@ type UpdateSettingsResult = {
796
796
  outcome: 'updated' | 'unchanged';
797
797
  };
798
798
  //#endregion
799
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/store/pool.d.ts
799
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/pool.d.ts
800
800
  interface OpenPoolStoreOptions {
801
801
  /** The provider every row of this pool belongs to; keys the provider-wide lock. */
802
802
  provider: string;
@@ -1202,17 +1202,92 @@ interface RefreshAllQuotaResult {
1202
1202
  permanent?: boolean;
1203
1203
  }
1204
1204
  //#endregion
1205
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/claustrum/insula.d.ts
1205
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/claustrum/watch.d.ts
1206
+ /**
1207
+ * How a host currently learns about changes, for logs and status displays.
1208
+ * `watching`: a watch was accepted and is open, so polling is reduced to a
1209
+ * slow safety read. `polling`: no watch is open yet (not started, opening, or
1210
+ * re-subscribing after a close), so the host polls at its usual interval.
1211
+ * `fallback`: the watch is unavailable (an older module or client, a refusal,
1212
+ * the watch limit, or repeated failures), so the host polls at its usual
1213
+ * interval and may try a watch again later. Never carries secrets.
1214
+ */
1215
+ type WatchMode = 'watching' | 'polling' | 'fallback';
1216
+ /**
1217
+ * The fields every change notice carries, from the vault's watchScoped and
1218
+ * insula's usage.watch alike.
1219
+ */
1220
+ interface ChangeNotice {
1221
+ readonly kind: string;
1222
+ readonly epoch: string;
1223
+ readonly seq: number;
1224
+ }
1225
+ /** A vault watch notice: `view` is the same digest `list_scoped` returns. */
1226
+ interface ScopedWatchNoticeShape extends ChangeNotice {
1227
+ readonly view: string;
1228
+ }
1229
+ /**
1230
+ * How a vault watch ended, as claustrum-client 0.12.0 reports it. `refused`
1231
+ * and `not_accepting` both mean the watch closed before its first notice; the
1232
+ * client then made one `list_scoped` read to learn why, and `refused` carries
1233
+ * that read's refusal.
1234
+ */
1235
+ type ScopedWatchEnd = {
1236
+ readonly kind: 'refused';
1237
+ readonly error: unknown;
1238
+ } | {
1239
+ readonly kind: 'transport_lost';
1240
+ readonly error: unknown;
1241
+ } | {
1242
+ readonly kind: 'ended' | 'not_accepting' | 'unsupported' | 'stopped';
1243
+ };
1244
+ interface ScopedWatchHandle {
1245
+ stop(): void;
1246
+ readonly closed: Promise<ScopedWatchEnd>;
1247
+ }
1248
+ /**
1249
+ * The part of a vault client that can watch. claustrum-client added
1250
+ * `watchScoped` in 0.12.0; the peer range still admits 0.6.2, so it is
1251
+ * optional and detected at run time.
1252
+ */
1253
+ interface ScopedWatchSource {
1254
+ watchScoped?(onNotice: (notice: ScopedWatchNoticeShape) => void, options?: {
1255
+ enrollmentToken?: string;
1256
+ }): ScopedWatchHandle;
1257
+ }
1258
+ //#endregion
1259
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/claustrum/insula.d.ts
1260
+ /**
1261
+ * A held-open `usage.watch` stream. `closed` resolves when insula ends the
1262
+ * stream (STREAM_END at shutdown, or a reply that ends it) or after `stop()`,
1263
+ * and rejects with insula's refusal (an error with a `code`, such as
1264
+ * `unknown_method` from an insula that predates the method, or
1265
+ * `usage_watch_limit` when 64 watches are already open) or with the
1266
+ * transport failure.
1267
+ */
1268
+ interface InsulaUsageWatch {
1269
+ stop(): void;
1270
+ readonly closed: Promise<void>;
1271
+ }
1206
1272
  /** Optional transport for custom scoped clients; getUsage must not retry refusals. */
1207
1273
  interface InsulaUsageTransport {
1208
1274
  connectionFile: string;
1209
1275
  getUsage(): Promise<unknown>;
1276
+ /**
1277
+ * Open a `usage.watch` stream, passing each notice's raw JSON body to
1278
+ * `onNotice`. Optional: a transport without it is polled as before.
1279
+ */
1280
+ watchUsage?(onNotice: (body: Uint8Array) => void): InsulaUsageWatch;
1210
1281
  }
1211
1282
  //#endregion
1212
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/claustrum/custody.d.ts
1283
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/claustrum/custody.d.ts
1284
+ /**
1285
+ * `watchScoped` is present from claustrum-client 0.12.0. Hosts detect it at
1286
+ * run time and keep polling without it.
1287
+ */
1213
1288
  type ClaustrumScopedClient = Pick<ClaustrumClient, 'listScoped' | 'getScoped' | 'reportAuthFailureScoped' | 'close'> & {
1214
1289
  insula?: InsulaUsageTransport;
1215
- };
1290
+ } & ScopedWatchSource;
1216
1291
  /** The two credential types a plugin's family can hold; routing differs by type. */
1217
1292
  type VaultCredentialType = 'oauth' | 'api_key';
1218
1293
  /**
@@ -1297,9 +1372,20 @@ interface ClaustrumScopedAttempt {
1297
1372
  readonly accessToken: string;
1298
1373
  readonly recordVersion: number;
1299
1374
  readonly expiresAtMs: number | null;
1375
+ /**
1376
+ * True when this receipt was not freshly served but is the last token kept
1377
+ * from an earlier read, used because the vault could not be reached. A 401
1378
+ * with such a receipt must not be retried and is not reported to the vault,
1379
+ * which is unreachable.
1380
+ */
1381
+ readonly fromKeptReceipt?: true;
1382
+ }
1383
+ interface KeptReceiptState {
1384
+ readonly active: boolean;
1385
+ readonly since: number | null;
1300
1386
  }
1301
1387
  //#endregion
1302
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/quota/map.d.ts
1388
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/quota/map.d.ts
1303
1389
  interface QuotaReadingEntry {
1304
1390
  scope: string;
1305
1391
  label: string;
@@ -1354,7 +1440,7 @@ interface QuotaMap {
1354
1440
  counters?: Record<string, QuotaCounter>;
1355
1441
  }
1356
1442
  //#endregion
1357
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/quota/merge.d.ts
1443
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/quota/merge.d.ts
1358
1444
  interface ObservedReading {
1359
1445
  /** Defaults to `all`. */
1360
1446
  scope?: string;
@@ -1392,7 +1478,7 @@ interface QuotaObservation {
1392
1478
  counters?: Record<string, QuotaCounter>;
1393
1479
  }
1394
1480
  //#endregion
1395
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/claustrum/interlock.d.ts
1481
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/claustrum/interlock.d.ts
1396
1482
  /**
1397
1483
  * The declined-account interlock: the user's "do not use this vault account",
1398
1484
  * kept on the consumer side because the vault has no notion of it.
@@ -1411,7 +1497,7 @@ interface DeclinedAccount {
1411
1497
  readonly accountIdentity?: string;
1412
1498
  }
1413
1499
  //#endregion
1414
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/claustrum/roster.d.ts
1500
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/claustrum/roster.d.ts
1415
1501
  /**
1416
1502
  * One vault account as the pool sees it. It carries no bearer material: the
1417
1503
  * access token is fetched from the vault for every send. Several vault
@@ -1466,7 +1552,18 @@ interface VaultRosterFile {
1466
1552
  */
1467
1553
  type QuotaReceipt = Pick<ClaustrumScopedAttempt, 'credentialId' | 'accountIdentity' | 'accountIdentitySource' | 'expectedAccountIdentity'>;
1468
1554
  //#endregion
1469
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.19.0+eac60b769bf9196b/node_modules/@cortexkit/common-auth/dist/claustrum/enrollment.d.ts
1555
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/claustrum/consumer.d.ts
1556
+ /**
1557
+ * How a started consumer learns about changes, for logs and status displays.
1558
+ * `insula` is present when the consumer was given an insula source. Never
1559
+ * carries secrets.
1560
+ */
1561
+ interface ClaustrumWatchState {
1562
+ readonly vault: WatchMode;
1563
+ readonly insula?: WatchMode;
1564
+ }
1565
+ //#endregion
1566
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/claustrum/enrollment.d.ts
1470
1567
  interface ClaustrumEnrollmentClient {
1471
1568
  enrollPropose(input: {
1472
1569
  name: string;
@@ -1567,6 +1664,12 @@ interface OpenAiVaultOptions {
1567
1664
  pollIntervalMs?: number;
1568
1665
  fetchImpl?: () => typeof fetch;
1569
1666
  now?: () => number;
1667
+ /**
1668
+ * Replace the timers behind the background poll, the vault and insula
1669
+ * watches' retries and the outage probe (tests).
1670
+ */
1671
+ setTimeoutImpl?: typeof setTimeout;
1672
+ clearTimeoutImpl?: typeof clearTimeout;
1570
1673
  }
1571
1674
  /** One host's view of its OpenAI accounts in the vault. */
1572
1675
  declare class OpenAiVault {
@@ -1585,9 +1688,13 @@ declare class OpenAiVault {
1585
1688
  */
1586
1689
  enrolled(): boolean;
1587
1690
  /**
1588
- * Polls enrollment files and the vault's accounts. With local authority the
1589
- * consumer sends no vault request. A new enrollment completed by another
1590
- * process is detected on the next poll.
1691
+ * Starts the consumer's background poll and its vault and insula watches.
1692
+ * With local authority the consumer sends no vault request. A new
1693
+ * enrollment completed by another process is detected on the next poll.
1694
+ * While the vault watch is open the poll lists the vault only every five
1695
+ * minutes, and a notice that the visible accounts changed starts a
1696
+ * discovery at once; without a watch (an older vault or client, or a
1697
+ * refusal) every poll lists the vault as before.
1591
1698
  */
1592
1699
  start(): void;
1593
1700
  /**
@@ -1612,6 +1719,16 @@ declare class OpenAiVault {
1612
1719
  */
1613
1720
  refresh(): Promise<VaultRosterFile | undefined>;
1614
1721
  snapshot(): VaultRosterFile | undefined;
1722
+ /**
1723
+ * Whether the consumer learns about vault and insula changes from a watch
1724
+ * or by polling, without any I/O.
1725
+ */
1726
+ watchState(): ClaustrumWatchState;
1727
+ /**
1728
+ * Whether any account is being served the last token the vault gave it
1729
+ * because the vault cannot be reached, without any I/O.
1730
+ */
1731
+ keptReceiptState(): KeptReceiptState;
1615
1732
  /**
1616
1733
  * What the vault says this host is granted, from the latest list, without
1617
1734
  * any I/O. Undefined is unknown (a vault that does not report grants, or