@cortexkit/anthropic-auth-core 2.0.1 → 2.0.3

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 (58) hide show
  1. package/dist/accounts.d.ts +7 -1
  2. package/dist/cache1h.d.ts +2 -0
  3. package/dist/cachekeep-registry.d.ts +3 -0
  4. package/dist/dump.d.ts +2 -0
  5. package/dist/fast.d.ts +2 -0
  6. package/dist/index.d.ts +9 -4
  7. package/dist/index.js +27470 -25081
  8. package/dist/internal-types/auth-menu/terminal.d.ts +43 -0
  9. package/dist/internal-types/claustrum/consumer.d.ts +132 -0
  10. package/dist/internal-types/claustrum/custody.d.ts +178 -0
  11. package/dist/internal-types/claustrum/enrollment.d.ts +164 -0
  12. package/dist/internal-types/claustrum/errors.d.ts +16 -0
  13. package/dist/internal-types/claustrum/host-slot.d.ts +39 -0
  14. package/dist/internal-types/claustrum/index.d.ts +19 -0
  15. package/dist/internal-types/claustrum/insula.d.ts +69 -0
  16. package/dist/internal-types/claustrum/interlock.d.ts +27 -0
  17. package/dist/internal-types/claustrum/roster.d.ts +221 -0
  18. package/dist/internal-types/fs/refresh-file-lock.d.ts +8 -2
  19. package/dist/internal-types/quota/codec.d.ts +2 -0
  20. package/dist/internal-types/quota/format.d.ts +26 -0
  21. package/dist/internal-types/quota/index.d.ts +4 -4
  22. package/dist/internal-types/quota/map.d.ts +11 -0
  23. package/dist/internal-types/quota/merge.d.ts +3 -1
  24. package/dist/internal-types/quota/projection.d.ts +2 -1
  25. package/dist/internal-types/routing/admission.d.ts +93 -0
  26. package/dist/internal-types/routing/index.d.ts +8 -0
  27. package/dist/internal-types/routing/ordered.d.ts +47 -0
  28. package/dist/internal-types/routing/pins.d.ts +22 -0
  29. package/dist/internal-types/routing/sticky.d.ts +158 -0
  30. package/dist/internal-types/setup/command-error.d.ts +17 -0
  31. package/dist/internal-types/setup/command.d.ts +3 -0
  32. package/dist/internal-types/setup/detect.d.ts +6 -0
  33. package/dist/internal-types/setup/index.d.ts +6 -0
  34. package/dist/internal-types/setup/process-fence.d.ts +43 -0
  35. package/dist/internal-types/setup/register.d.ts +11 -0
  36. package/dist/internal-types/setup/types.d.ts +138 -0
  37. package/dist/internal-types/store/pool.d.ts +1 -1
  38. package/dist/internal-types/store/refresh-lock.d.ts +0 -1
  39. package/dist/internal-types/store/schema.d.ts +2 -0
  40. package/dist/logging.d.ts +2 -0
  41. package/dist/mid-conversation-output-config.d.ts +35 -0
  42. package/dist/native-account-runtime.d.ts +6 -2
  43. package/dist/native-account-view.d.ts +22 -4
  44. package/dist/native-custody-activation.d.ts +1 -1
  45. package/dist/native-menu-executor.d.ts +1 -1
  46. package/dist/native-migration.d.ts +25 -4
  47. package/dist/native-quota-observations.d.ts +26 -0
  48. package/dist/native-transient-account.d.ts +3 -4
  49. package/dist/native-ui.d.ts +2 -0
  50. package/dist/native-usage-publication.d.ts +5 -0
  51. package/dist/native-vault-runtime.d.ts +4 -0
  52. package/dist/network-errors.d.ts +1 -0
  53. package/dist/pool-authority.d.ts +26 -8
  54. package/dist/pool-paths.d.ts +2 -0
  55. package/dist/quotas.d.ts +15 -2
  56. package/dist/relay.d.ts +20 -0
  57. package/dist/sticky-routing.d.ts +3 -0
  58. package/package.json +3 -2
@@ -0,0 +1,26 @@
1
+ import { type AccountStorage, type OAuthQuotaSnapshot } from './accounts.ts';
2
+ import type { NativeLocalPoolBinding } from './pool-binding.ts';
3
+ import type { QuotaEntry } from './quota-manager.ts';
4
+ export type NativeQuotaObservation = {
5
+ lineage: string;
6
+ accountUuid: string;
7
+ entry: QuotaEntry;
8
+ generalExhausted: boolean;
9
+ quotaErrorClearedAt?: number;
10
+ };
11
+ export declare function nativePollQuotaGenerallyExhausted(quota: OAuthQuotaSnapshot): boolean;
12
+ export declare function nativeLocalQuotaLineage(binding: NativeLocalPoolBinding & {
13
+ readonly identity: string;
14
+ }): string;
15
+ export declare function nativeLocalQuotaLineage(binding: NativeLocalPoolBinding | undefined): string | undefined;
16
+ /** Shared by header receipt, poll completion, routing and display; contains no credentials. */
17
+ export declare class NativeQuotaObservations extends Map<string, NativeQuotaObservation> {
18
+ private readonly publications;
19
+ set(accountId: string, observation: NativeQuotaObservation): this;
20
+ quota(lineage: string | undefined, accountUuid: string | undefined, committed: OAuthQuotaSnapshot | undefined, storage: AccountStorage, now?: number): {
21
+ quota: OAuthQuotaSnapshot;
22
+ clearAt?: number;
23
+ } | undefined;
24
+ publish(accountId: string, observation: NativeQuotaObservation, write: () => Promise<boolean>): Promise<void>;
25
+ drain(): Promise<void>;
26
+ }
@@ -31,8 +31,7 @@ export declare function isNativeTransientAccountError(value: unknown): value is
31
31
  * budget. Each wait between attempts ends early when any of `signals`
32
32
  * aborts; `check` is then called after the leases are released and is
33
33
  * expected to throw the caller's cancellation error. `check` runs before
34
- * every attempt too, so a cancelled caller never takes a lock. `now` must be
35
- * the clock the pool's writers stamp their lock expiry with, or a live
36
- * writer's lock could be judged expired and taken over.
34
+ * every attempt too, so a cancelled caller never takes a lock. All pool
35
+ * leases use wall time, independently of logical observation timestamps.
37
36
  */
38
- export declare function joinNativePoolWrite(paths: NativePoolStorePaths, signals: readonly AbortSignal[], check: () => void, now?: () => number): Promise<'joined' | 'deadline'>;
37
+ export declare function joinNativePoolWrite(paths: NativePoolStorePaths, signals: readonly AbortSignal[], check: () => void): Promise<'joined' | 'deadline'>;
@@ -21,6 +21,8 @@ export interface NativeUiOptions {
21
21
  readonly readMode: () => Promise<NativeMenuCustodyMode>;
22
22
  /** Token-free account names, credential IDs and states used to show which vault account needs re-login and its replacement command. */
23
23
  readonly readAccounts?: () => Promise<import('./native-account-view.ts').NativeAccountSnapshot>;
24
+ /** Re-read the separate host-login notice on each local Accounts render. */
25
+ readonly readSeparateHostLoginNotice?: () => Promise<boolean>;
24
26
  /**
25
27
  * Disconnects this host from the vault; while enrolled, this is the host's
26
28
  * only enrollment action. Before ending the enrollment, the callback
@@ -4,6 +4,11 @@
4
4
  * The error classes are not public runtime exports, so match name and code.
5
5
  */
6
6
  export declare function usagePublicationRefusalIsFatal(error: unknown): boolean;
7
+ /** Return only allowlisted classes and codes, never the exception text. */
8
+ export declare function classifySafeErrorForLog(error: unknown): {
9
+ name: string;
10
+ code: string;
11
+ };
7
12
  /** Own advisory writes for one host instance and join them before runtime close. */
8
13
  export declare function createNativeUsagePublisher(channel: string): {
9
14
  observe: (write: Promise<unknown>) => Promise<void>;
@@ -2,6 +2,7 @@ import { type ClaustrumClientOptions } from '@cortexkit/claustrum-client';
2
2
  import { type OAuthAccountProfile, type OAuthQuotaSnapshot, type PrimeUsageDelta } from './accounts.ts';
3
3
  import { type NativeAccountMetadataPatch } from './native-account-view.ts';
4
4
  import { type NativeCustodyClient, type NativeCustodyInventory, type NativeCustodyReceipt, type NativeCustodyReporterSource, type NativeCustodyRetry } from './native-custody.ts';
5
+ import { NativeQuotaObservations } from './native-quota-observations.ts';
5
6
  import { type NativeRosterSeedInput, type NativeVaultRosterDocument, type NativeVaultRosterSeed } from './native-roster-seed.ts';
6
7
  import { type NativeRuntimeState } from './native-runtime.ts';
7
8
  import type { NativeVaultPaths } from './native-vault-paths.ts';
@@ -53,6 +54,9 @@ export interface NativeDisplayProfile {
53
54
  /** Build a NativeDisplayProfile from a validated profile and its publication. */
54
55
  export declare function nativeDisplayProfile(profile: OAuthAccountProfile, publish: () => Promise<boolean>, isCurrent: () => Promise<boolean>): NativeDisplayProfile;
55
56
  export interface NativeVaultRuntime {
57
+ readonly quotaObservations: NativeQuotaObservations;
58
+ drainQuotaPublications(): Promise<void>;
59
+ quotaLineage(routeId: string, credentialId: string | undefined, accountIdentity: string | undefined): string | undefined;
56
60
  /** Subscribe to one discovery loop; notifications contain no credential material. */
57
61
  watch(options: NativeVaultWatchOptions): NativeVaultWatch;
58
62
  initializeSettings(): Promise<void>;
@@ -1 +1,2 @@
1
+ export declare function transientNetworkErrorCode(error: unknown): string | undefined;
1
2
  export declare function isTransientNetworkError(error: unknown): boolean;
@@ -23,6 +23,7 @@ export interface NativeMigrationInput {
23
23
  * keeps native serving blocked until the separate vault activation commits.
24
24
  */
25
25
  activation?: 'requested';
26
+ nativeSettingsDigest?: string;
26
27
  }
27
28
  export interface NativeMigrationExpectations {
28
29
  expectedHostAuth: string;
@@ -97,8 +98,7 @@ export interface NativeCustodyActivationPlan {
97
98
  export type NativeCustodyActivation = {
98
99
  kind: 'requested';
99
100
  } | NativeCustodyActivationPlan;
100
- export interface NativeMigrationJournal {
101
- version: 4;
101
+ interface NativeMigrationRecord {
102
102
  storageId: string;
103
103
  host: 'opencode' | 'pi';
104
104
  phase: NativeMigrationPhase;
@@ -114,6 +114,22 @@ export interface NativeMigrationJournal {
114
114
  */
115
115
  activation: NativeCustodyActivation | null;
116
116
  }
117
+ export type NativeLegacyMigrationJournal = NativeMigrationRecord & ({
118
+ version: 4;
119
+ kind?: never;
120
+ } | {
121
+ version: 5;
122
+ kind: 'legacy-import';
123
+ nativeSettingsDigest: string;
124
+ });
125
+ export interface NativeEmptyInitJournal {
126
+ version: 5;
127
+ kind: 'empty-init';
128
+ storageId: string;
129
+ host: 'opencode';
130
+ phase: 'committed';
131
+ }
132
+ export type NativeMigrationJournal = NativeLegacyMigrationJournal | NativeEmptyInitJournal;
117
133
  export declare class NativeAuthorityError extends Error {
118
134
  readonly code: 'migration-required' | 'migration-incomplete' | 'invalid-journal' | 'journal-conflict';
119
135
  constructor(code: 'migration-required' | 'migration-incomplete' | 'invalid-journal' | 'journal-conflict');
@@ -126,7 +142,7 @@ export declare function readNativeMigrationJournal(paths: NativePoolPaths): Prom
126
142
  */
127
143
  export declare function nativeMigrationAuthorityPhase(journal: NativeMigrationJournal | undefined): 'committed' | 'retired' | undefined;
128
144
  /** An empty or readable store is not proof that the offline authority flip completed. */
129
- export declare function requireNativePoolAuthority(paths: NativePoolPaths): Promise<void>;
145
+ export declare function requireNativePoolAuthority(paths: NativePoolPaths): Promise<NativeMigrationJournal>;
130
146
  interface JournalHooks {
131
147
  /** Outer controller and pool leases remain held through the atomic journal rename. */
132
148
  assertOwned?: () => Promise<void>;
@@ -137,23 +153,25 @@ interface JournalHooks {
137
153
  onWriteStep?: (step: 'before-write' | 'after-write', journal: NativeMigrationJournal) => Promise<void>;
138
154
  }
139
155
  /** Migration resume retains the original digests and resolved paths so a retry cannot adopt changed inputs or redirect writes. */
140
- export declare function beginNativeMigration(paths: NativePoolPaths, input: NativeMigrationInput, hooks?: JournalHooks): Promise<NativeMigrationJournal>;
156
+ export declare function beginNativeMigration(paths: NativePoolPaths, input: NativeMigrationInput, hooks?: JournalHooks): Promise<NativeLegacyMigrationJournal>;
141
157
  /** Save the expected host-auth entry and routing digests together before changing files, so recovery can recognize completed writes. */
142
- export declare function recordNativeMigrationExpectations(paths: NativePoolPaths, expectations: NativeMigrationExpectations, hooks?: JournalHooks): Promise<NativeMigrationJournal>;
158
+ export declare function recordNativeMigrationExpectations(paths: NativePoolPaths, expectations: NativeMigrationExpectations, hooks?: JournalHooks): Promise<NativeLegacyMigrationJournal>;
143
159
  /**
144
160
  * Advance one phase at a time. A retry of the same transition returns the journal.
145
161
  * Before recording activation, the caller must compare the host's Anthropic auth
146
162
  * entry and routing file with the saved expected values. This journal records the
147
163
  * migration stage; it does not read or verify those files.
148
164
  */
149
- export declare function advanceNativeMigration(paths: NativePoolPaths, expected: NativeMigrationPhase, next: NativeMigrationPhase, hooks?: JournalHooks): Promise<NativeMigrationJournal>;
165
+ export declare function advanceNativeMigration(paths: NativePoolPaths, expected: NativeMigrationPhase, next: NativeMigrationPhase, hooks?: JournalHooks): Promise<NativeLegacyMigrationJournal>;
150
166
  /**
151
167
  * Record the prepared switch to vault custody on a retired migration. From
152
168
  * this write until the activation commits, the pool authorizes no serving.
153
169
  * Retrying with the identical plan returns the journal; any other plan is a
154
170
  * conflict, so a resumed setup can never replace what it recorded.
155
171
  */
156
- export declare function recordNativeCustodyActivation(paths: NativePoolPaths, plan: NativeCustodyActivationPlan, hooks?: JournalHooks): Promise<NativeMigrationJournal>;
172
+ export declare function recordNativeCustodyActivation(paths: NativePoolPaths, plan: NativeCustodyActivationPlan, hooks?: JournalHooks): Promise<NativeLegacyMigrationJournal>;
157
173
  /** Advance a recorded activation one phase; never backwards or across a phase. */
158
- export declare function advanceNativeCustodyActivation(paths: NativePoolPaths, expected: NativeCustodyActivationPhase, next: NativeCustodyActivationPhase, hooks?: JournalHooks): Promise<NativeMigrationJournal>;
174
+ export declare function advanceNativeCustodyActivation(paths: NativePoolPaths, expected: NativeCustodyActivationPhase, next: NativeCustodyActivationPhase, hooks?: JournalHooks): Promise<NativeLegacyMigrationJournal>;
175
+ /** Publish local authority without inventing migration inputs or creating a pool. */
176
+ export declare function beginNativeEmptyInit(paths: NativePoolPaths, hooks?: JournalHooks): Promise<NativeEmptyInitJournal>;
159
177
  export {};
@@ -8,6 +8,8 @@ export interface NativePoolPaths {
8
8
  roster: string;
9
9
  storageId: string;
10
10
  }
11
+ /** Local hosts share the native pool's routing file unless explicitly overridden. */
12
+ export declare function resolveLocalRoutingDestination(host: 'opencode' | 'pi', paths: NativePoolPaths, env: NodeJS.ProcessEnv): string;
11
13
  /**
12
14
  * Resolve existing parent aliases and nonexistent leaves without creating files.
13
15
  * This can follow a leaf symlink, so it does not establish configured-leaf safety.
package/dist/quotas.d.ts CHANGED
@@ -1,5 +1,19 @@
1
- import type { AccountStorage, OAuthQuotaSnapshot, QuotaMoney } from './accounts.ts';
1
+ import { formatQuota, type ProjectedQuota, quotaTextParts, quotaWindowParts } from "./internal-types/quota/index.js";
2
+ import type { AccountQuotaWindow, AccountScopedQuotaWindow, AccountStorage, OAuthQuotaSnapshot } from './accounts.ts';
2
3
  export declare const CLAUDE_QUOTAS_COMMAND_NAME = "claude-quota";
4
+ export type { QuotaWindowPart } from "./internal-types/quota/index.js";
5
+ export { formatQuota, quotaTextParts, quotaWindowParts };
6
+ type DisplayWindow = Omit<AccountQuotaWindow, 'checkedAt'> & {
7
+ checkedAt?: number;
8
+ };
9
+ /** Sidebar files written by older versions may not retain reading times. */
10
+ export type QuotaDisplaySnapshot = Pick<OAuthQuotaSnapshot, 'checkedAt' | 'extraUsage' | 'bindingWindow'> & {
11
+ five_hour?: DisplayWindow;
12
+ seven_day?: DisplayWindow;
13
+ scoped?: (Omit<AccountScopedQuotaWindow, 'checkedAt'> & DisplayWindow)[];
14
+ };
15
+ /** Adapt every reported window without projecting away other model families. */
16
+ export declare function quotaDisplayProjection(snapshot: QuotaDisplaySnapshot | null | undefined, now: number): ProjectedQuota | undefined;
3
17
  export type QuotaAccountSummary = {
4
18
  name: string;
5
19
  role: 'main' | 'fallback';
@@ -9,7 +23,6 @@ export type QuotaAccountSummary = {
9
23
  error?: string;
10
24
  tierLabel?: string;
11
25
  };
12
- export declare function formatQuotaMoney(money: QuotaMoney): string;
13
26
  export declare function buildFallbackQuotaSummaries(storage: AccountStorage | null, errors?: ReadonlyMap<string, string>): {
14
27
  name: string;
15
28
  role: 'fallback';
package/dist/relay.d.ts CHANGED
@@ -6,6 +6,26 @@ export type RelayConfig = {
6
6
  fallbackToDirect: boolean;
7
7
  transport: 'http' | 'websocket';
8
8
  };
9
+ /**
10
+ * The transport a stored relay configuration selects. A stored `http` or
11
+ * `websocket` value always wins. Without one (missing or unrecognized), the
12
+ * URL decides: a `ws://` or `wss://` URL selects WebSocket, so hand-edited
13
+ * WebSocket configurations keep working; any other URL selects HTTP, the
14
+ * documented default. Request dispatch and the relay status shown to users
15
+ * both call this, so they cannot report different transports.
16
+ */
17
+ export declare function effectiveRelayTransport(stored: unknown, url: unknown): RelayConfig['transport'];
18
+ /**
19
+ * Secret-free relay status for displays such as the OpenCode sidebar: the
20
+ * transport requests will use, or null when requests cannot use the relay
21
+ * because it is disabled, has no URL or has no token. Native account
22
+ * snapshots never carry the private token; they set `tokenConfigured` to say
23
+ * whether one is stored.
24
+ */
25
+ export declare function effectiveRelayStatus(relay: AccountStorage['relay'] | undefined): {
26
+ enabled: true;
27
+ transport: RelayConfig['transport'];
28
+ } | null;
9
29
  export type RelayPatch = {
10
30
  start: number;
11
31
  deleteCount: number;
@@ -106,12 +106,15 @@ export declare class StickySessionRouter {
106
106
  now?: () => number;
107
107
  assignmentTtlMs?: number;
108
108
  vaultSeed?: NativeVaultRoutingSeed;
109
+ localRecoveryPath?: string;
109
110
  });
110
111
  private now;
111
112
  private readState;
112
113
  private readStateMtimeNs;
113
114
  private refreshStateIfChanged;
114
115
  private acquireLock;
116
+ private recoverLocalPins;
117
+ private fillLocalPins;
115
118
  private assignmentIsActive;
116
119
  private prune;
117
120
  private writeState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/anthropic-auth-core",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,11 +30,12 @@
30
30
  "prepublishOnly": "bun run build"
31
31
  },
32
32
  "devDependencies": {
33
- "@cortexkit/common-auth": "0.15.0"
33
+ "@cortexkit/common-auth": "0.18.0"
34
34
  },
35
35
  "dependencies": {
36
36
  "@cortexkit/claustrum-client": "0.9.0",
37
37
  "@cortexkit/private-files": "0.2.1",
38
+ "@cortexkit/subc-client": "^0.16.0",
38
39
  "jsonc-parser": "^3.3.1",
39
40
  "xxhash-wasm": "^1.1.0"
40
41
  }