@cortexkit/pi-openai-auth 1.3.0 → 1.4.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.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/pi-slot/slot.d.ts
5
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/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.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/schema.d.ts
16
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/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.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/errors.d.ts
205
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/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.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/hooks.d.ts
252
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/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.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/fs/refresh-file-lock.d.ts
257
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/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.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/refresh-lock.d.ts
292
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/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.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/mutate.d.ts
324
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/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.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/runtime.d.ts
359
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/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.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/attribution.d.ts
363
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/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.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/rows.d.ts
386
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/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.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/provider-state.d.ts
602
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/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.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/publication.d.ts
638
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/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.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/pull.d.ts
681
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/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.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/refresh.d.ts
692
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/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.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/settings.d.ts
755
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/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.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/store/pool.d.ts
799
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/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;
@@ -1033,11 +1033,19 @@ interface OAuthSpendControlReading {
1033
1033
  source?: string;
1034
1034
  reached: boolean;
1035
1035
  }
1036
+ /**
1037
+ * Prepaid workspace credits as the Codex backend reports them, in the usage
1038
+ * poll's `credits` object or the `x-codex-credits-*` response headers. The
1039
+ * headers carry no overage verdict, so `overageLimitReached` is optional.
1040
+ * `checkedAt` is when the source was read. It is optional because accounts
1041
+ * files written by older versions hold credits without it.
1042
+ */
1036
1043
  interface OAuthCredits {
1037
1044
  hasCredits: boolean;
1038
1045
  unlimited: boolean;
1039
- overageLimitReached: boolean;
1046
+ overageLimitReached?: boolean;
1040
1047
  balance?: number;
1048
+ checkedAt?: number;
1041
1049
  }
1042
1050
  type AccountBase = {
1043
1051
  id: string;
@@ -1202,7 +1210,7 @@ interface RefreshAllQuotaResult {
1202
1210
  permanent?: boolean;
1203
1211
  }
1204
1212
  //#endregion
1205
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/claustrum/watch.d.ts
1213
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/claustrum/watch.d.ts
1206
1214
  /**
1207
1215
  * How a host currently learns about changes, for logs and status displays.
1208
1216
  * `watching`: a watch was accepted and is open, so polling is reduced to a
@@ -1256,7 +1264,7 @@ interface ScopedWatchSource {
1256
1264
  }): ScopedWatchHandle;
1257
1265
  }
1258
1266
  //#endregion
1259
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/claustrum/insula.d.ts
1267
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/claustrum/insula.d.ts
1260
1268
  /**
1261
1269
  * A held-open `usage.watch` stream. `closed` resolves when insula ends the
1262
1270
  * stream (STREAM_END at shutdown, or a reply that ends it) or after `stop()`,
@@ -1280,7 +1288,7 @@ interface InsulaUsageTransport {
1280
1288
  watchUsage?(onNotice: (body: Uint8Array) => void): InsulaUsageWatch;
1281
1289
  }
1282
1290
  //#endregion
1283
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/claustrum/custody.d.ts
1291
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/claustrum/custody.d.ts
1284
1292
  /**
1285
1293
  * `watchScoped` is present from claustrum-client 0.12.0. Hosts detect it at
1286
1294
  * run time and keep polling without it.
@@ -1385,7 +1393,7 @@ interface KeptReceiptState {
1385
1393
  readonly since: number | null;
1386
1394
  }
1387
1395
  //#endregion
1388
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/quota/map.d.ts
1396
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/quota/map.d.ts
1389
1397
  interface QuotaReadingEntry {
1390
1398
  scope: string;
1391
1399
  label: string;
@@ -1432,15 +1440,33 @@ interface QuotaCounter {
1432
1440
  value: number;
1433
1441
  checkedAt: number;
1434
1442
  }
1443
+ /**
1444
+ * Prepaid credits a provider account holds beside its rate-limit windows (for
1445
+ * example a ChatGPT workspace's credits, which keep requests working after a
1446
+ * window is used up). This is a state, not a count or the spend budget: the
1447
+ * account has credits or not, they may be unlimited, and the provider may
1448
+ * report a balance. It carries its own observation time.
1449
+ */
1450
+ interface QuotaCredits {
1451
+ hasCredits: boolean;
1452
+ unlimited: boolean;
1453
+ /** The balance the provider reported, when it reported one. */
1454
+ balance?: number;
1455
+ /** The provider's verdict that the overage allowance is used up. */
1456
+ overageLimitReached?: boolean;
1457
+ checkedAt: number;
1458
+ }
1435
1459
  interface QuotaMap {
1436
1460
  limits: QuotaEntry[];
1437
1461
  /** Absent means no observation has reported on the budget yet. */
1438
1462
  budget?: CreditBudgetEntry;
1439
1463
  /** Provider-named counts, each with its own observation time. */
1440
1464
  counters?: Record<string, QuotaCounter>;
1465
+ /** Absent means no observation has reported on prepaid credits yet. */
1466
+ credits?: QuotaCredits;
1441
1467
  }
1442
1468
  //#endregion
1443
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/quota/merge.d.ts
1469
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/quota/merge.d.ts
1444
1470
  interface ObservedReading {
1445
1471
  /** Defaults to `all`. */
1446
1472
  scope?: string;
@@ -1476,9 +1502,14 @@ interface QuotaObservation {
1476
1502
  budget?: ObservedBudget;
1477
1503
  /** Each named count uses its own time, independently of limits and budget. */
1478
1504
  counters?: Record<string, QuotaCounter>;
1505
+ /**
1506
+ * Prepaid credits, judged by their own time independently of limits, budget
1507
+ * and counters. Absent means the observation says nothing about credits.
1508
+ */
1509
+ credits?: QuotaCredits;
1479
1510
  }
1480
1511
  //#endregion
1481
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/claustrum/interlock.d.ts
1512
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/claustrum/interlock.d.ts
1482
1513
  /**
1483
1514
  * The declined-account interlock: the user's "do not use this vault account",
1484
1515
  * kept on the consumer side because the vault has no notion of it.
@@ -1497,7 +1528,7 @@ interface DeclinedAccount {
1497
1528
  readonly accountIdentity?: string;
1498
1529
  }
1499
1530
  //#endregion
1500
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/claustrum/roster.d.ts
1531
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/claustrum/roster.d.ts
1501
1532
  /**
1502
1533
  * One vault account as the pool sees it. It carries no bearer material: the
1503
1534
  * access token is fetched from the vault for every send. Several vault
@@ -1552,7 +1583,7 @@ interface VaultRosterFile {
1552
1583
  */
1553
1584
  type QuotaReceipt = Pick<ClaustrumScopedAttempt, 'credentialId' | 'accountIdentity' | 'accountIdentitySource' | 'expectedAccountIdentity'>;
1554
1585
  //#endregion
1555
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/claustrum/consumer.d.ts
1586
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/claustrum/consumer.d.ts
1556
1587
  /**
1557
1588
  * How a started consumer learns about changes, for logs and status displays.
1558
1589
  * `insula` is present when the consumer was given an insula source. Never
@@ -1563,7 +1594,7 @@ interface ClaustrumWatchState {
1563
1594
  readonly insula?: WatchMode;
1564
1595
  }
1565
1596
  //#endregion
1566
- //#region ../../node_modules/.bun/@cortexkit+common-auth@0.21.0+ceea0b545671e3e4/node_modules/@cortexkit/common-auth/dist/claustrum/enrollment.d.ts
1597
+ //#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/claustrum/enrollment.d.ts
1567
1598
  interface ClaustrumEnrollmentClient {
1568
1599
  enrollPropose(input: {
1569
1600
  name: string;
@@ -1791,7 +1822,7 @@ declare class OpenAiVault {
1791
1822
  * the background; a failure is logged.
1792
1823
  */
1793
1824
  recordSnapshot(routeId: string, snapshot: unknown, complete: boolean, receipt: QuotaReceipt): Promise<void>;
1794
- /** Joins a quota poll; current insula quota for the same account replaces a background ChatGPT wham/usage request. */
1825
+ /** Joins a quota poll; insula decides whether a background provider read is needed. */
1795
1826
  pollQuota(routeId: string, background?: boolean): Promise<{
1796
1827
  ok: boolean;
1797
1828
  error?: string;
@@ -1884,7 +1915,10 @@ declare class PiMainAccount {
1884
1915
  currentIdentity(): string | undefined;
1885
1916
  /** The quota map routing reads: undefined until a reading arrives. */
1886
1917
  quotaMap(): QuotaMap | undefined;
1887
- /** The fixed windows of the quota map, plus the last poll's budget and reset credits. */
1918
+ /**
1919
+ * The fixed windows of the quota map and its prepaid credits, plus the last
1920
+ * poll's budget and reset credits.
1921
+ */
1888
1922
  quotaSnapshot(): OAuthQuotaSnapshot | undefined;
1889
1923
  /**
1890
1924
  * Asks for a quota poll, at most once per `MAIN_PULL_RETRY_MS` unless
@@ -2089,6 +2123,11 @@ declare class PiOpenAIRuntime {
2089
2123
  readonly pool: PiPoolSource;
2090
2124
  readonly vault: OpenAiVault;
2091
2125
  private readonly deps;
2126
+ /**
2127
+ * Which accounts this runtime serves on prepaid credits, so the info line
2128
+ * is written once when an account starts serving on them.
2129
+ */
2130
+ private readonly creditsServing;
2092
2131
  /**
2093
2132
  * The vault account behind each recent vault token, with the receipt the
2094
2133
  * vault served the token under, newest last, so a rate-limit frame