@cortexkit/anthropic-auth-core 1.19.0 → 1.20.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/accounts.d.ts +72 -2
- package/dist/accounts.js +390 -26
- package/dist/auth.d.ts +3 -0
- package/dist/auth.js +5 -3
- package/dist/cache1h.d.ts +1 -1
- package/dist/cache1h.js +1 -1
- package/dist/cachekeep.d.ts +22 -2
- package/dist/cachekeep.js +137 -30
- package/dist/cch.d.ts +1 -0
- package/dist/cch.js +6 -1
- package/dist/claude-code.d.ts +2 -1
- package/dist/claude-code.js +3 -3
- package/dist/commands/account.js +1 -1
- package/dist/constants.d.ts +3 -3
- package/dist/dump.d.ts +12 -1
- package/dist/dump.js +166 -22
- package/dist/index.d.ts +2 -0
- package/dist/index.js +26 -24
- package/dist/killswitch.js +1 -1
- package/dist/models.d.ts +22 -6
- package/dist/models.js +16 -0
- package/dist/oauth-profile.js +1 -1
- package/dist/prime.d.ts +219 -0
- package/dist/prime.js +823 -0
- package/dist/quota-manager.d.ts +7 -0
- package/dist/quota-manager.js +24 -15
- package/dist/quotas.d.ts +4 -4
- package/dist/quotas.js +2 -2
- package/dist/relay.d.ts +4 -0
- package/dist/relay.js +29 -18
- package/dist/routing.d.ts +1 -1
- package/dist/routing.js +1 -1
- package/dist/start.d.ts +13 -0
- package/dist/start.js +29 -0
- package/dist/sticky-routing.d.ts +13 -1
- package/dist/sticky-routing.js +58 -2
- package/package.json +1 -1
package/dist/prime.d.ts
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { type AccountStorage, type OAuthQuotaSnapshot, type PrimeUsageCounters } from './accounts.ts';
|
|
2
|
+
import { CLAUDE_HAIKU_4_5_PRICING } from './models.ts';
|
|
3
|
+
export { CLAUDE_HAIKU_4_5_PRICING };
|
|
4
|
+
/**
|
|
5
|
+
* `/claude-prime` — opt-in 5h quota window priming. Default OFF.
|
|
6
|
+
*
|
|
7
|
+
* Every OAuth account (main + enabled fallbacks) gets one minimal request
|
|
8
|
+
* fired ~60s after its `five_hour.resetsAt`, exactly once across concurrent
|
|
9
|
+
* OpenCode processes. Catch-up on boot; redundancy guard via fresh quota
|
|
10
|
+
* check; cross-process atomic marker claim via `writeFile(..., flag: 'wx')`.
|
|
11
|
+
*/
|
|
12
|
+
export declare const CLAUDE_PRIME_COMMAND_NAME = "claude-prime";
|
|
13
|
+
export declare const PRIME_TICK_MS = 60000;
|
|
14
|
+
export declare const PRIME_DUE_OFFSET_MS = 60000;
|
|
15
|
+
export declare const PRIME_MARKER_MAX_AGE_MS: number;
|
|
16
|
+
export declare const PRIME_POST_FIRE_REFRESH_MS = 90000;
|
|
17
|
+
/** Minimum interval between forced quota checks for an unchanged reset epoch. */
|
|
18
|
+
export declare const PRIME_CHECK_THROTTLE_MS: number;
|
|
19
|
+
export type PrimeCommandAction = {
|
|
20
|
+
type: 'status';
|
|
21
|
+
} | {
|
|
22
|
+
type: 'enable';
|
|
23
|
+
} | {
|
|
24
|
+
type: 'disable';
|
|
25
|
+
} | {
|
|
26
|
+
type: 'usage';
|
|
27
|
+
};
|
|
28
|
+
export type PrimeAccountStatus = {
|
|
29
|
+
id: string;
|
|
30
|
+
label: string;
|
|
31
|
+
nextDueAt?: number;
|
|
32
|
+
lastPrimedAt?: number | null;
|
|
33
|
+
lastResult?: 'ok' | 'error';
|
|
34
|
+
usage?: import('./accounts.ts').PrimeUsageCounters;
|
|
35
|
+
estimatedCostUsd?: number;
|
|
36
|
+
};
|
|
37
|
+
export type PrimeSendResult = {
|
|
38
|
+
ok: true;
|
|
39
|
+
status: number;
|
|
40
|
+
ms: number;
|
|
41
|
+
usage?: {
|
|
42
|
+
inputTokens?: number;
|
|
43
|
+
outputTokens?: number;
|
|
44
|
+
};
|
|
45
|
+
} | {
|
|
46
|
+
ok: false;
|
|
47
|
+
status?: number;
|
|
48
|
+
ms?: number;
|
|
49
|
+
error: string;
|
|
50
|
+
reason?: 'token-refresh' | 'send';
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Pure command parser — accepts `''` / `on` / `off` and treats anything else
|
|
54
|
+
* as a usage error. Mirrors `parseFastModeCommandAction` shape so all
|
|
55
|
+
* `claude-*` commands stay uniform.
|
|
56
|
+
*/
|
|
57
|
+
export declare function parsePrimeCommandAction(input: string): PrimeCommandAction;
|
|
58
|
+
/**
|
|
59
|
+
* Per-million-token USD cost projection. Locale-independent math; the display
|
|
60
|
+
* layer is responsible for formatting. Returns 0 for absent counters so
|
|
61
|
+
* pre-fire accounts still get a clean number in the sidebar/dialog.
|
|
62
|
+
*/
|
|
63
|
+
export declare function estimatePrimeCostUsd(usage?: import('./accounts.ts').PrimeUsageCounters): number;
|
|
64
|
+
/**
|
|
65
|
+
* Project per-account prime status. Enumerates a synthetic `main` plus each
|
|
66
|
+
* enabled OAuth fallback. `nextDueAt` is the stored five-hour reset plus
|
|
67
|
+
* `PRIME_DUE_OFFSET_MS`; null when no reset is known. Manager-transient
|
|
68
|
+
* `lastPrimedAt`/`lastResult` overlay the persisted counters so the dialog and
|
|
69
|
+
* sidebar can show "just attempted" without waiting for the next save.
|
|
70
|
+
*/
|
|
71
|
+
export declare function buildPrimeAccountStatuses(storage: AccountStorage | null, options?: {
|
|
72
|
+
now?: number;
|
|
73
|
+
transient?: ReadonlyMap<string, {
|
|
74
|
+
lastPrimedAt?: number;
|
|
75
|
+
lastResult?: 'ok' | 'error';
|
|
76
|
+
}>;
|
|
77
|
+
}): PrimeAccountStatus[];
|
|
78
|
+
/**
|
|
79
|
+
* Pure multi-line status summary shared by the OpenCode dialog, the sidebar
|
|
80
|
+
* expanded row, and the Pi display. Title is stable text the dialog uses to
|
|
81
|
+
* anchor and the orchestrator uses to assert RED.
|
|
82
|
+
*/
|
|
83
|
+
export declare function buildPrimeStatusSummary(input: {
|
|
84
|
+
enabled: boolean;
|
|
85
|
+
accounts: PrimeAccountStatus[];
|
|
86
|
+
}): string;
|
|
87
|
+
/**
|
|
88
|
+
* Pure executor — returns markdown text and an optional `updated` envelope.
|
|
89
|
+
* Effects (persistent toggle, manager start/stop) are the caller's job; Pi
|
|
90
|
+
* uses this same function in display-only mode.
|
|
91
|
+
*/
|
|
92
|
+
export declare function executePrimeCommand(input: {
|
|
93
|
+
argumentsText: string;
|
|
94
|
+
enabled: boolean;
|
|
95
|
+
accounts: PrimeAccountStatus[];
|
|
96
|
+
}): {
|
|
97
|
+
text: string;
|
|
98
|
+
updated?: {
|
|
99
|
+
enabled: boolean;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Which gate of the eligibility check failed. The manager logs the human
|
|
104
|
+
* reason string on every ineligible account (including API-key and
|
|
105
|
+
* disabled), per the spec's Logging table.
|
|
106
|
+
*/
|
|
107
|
+
export type PrimeEligibilityReason = 'not-oauth' | 'disabled' | 'needs-reauth' | 'killswitch';
|
|
108
|
+
export type PrimeEligibilityResult = {
|
|
109
|
+
eligible: true;
|
|
110
|
+
} | {
|
|
111
|
+
eligible: false;
|
|
112
|
+
reason: PrimeEligibilityReason;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Eligibility check shared by the manager tick and the dialog preview.
|
|
116
|
+
* Returns a discriminated result so the manager can log a specific reason
|
|
117
|
+
* per the spec's Logging table. Quota policy is evaluated authoritatively on
|
|
118
|
+
* the fresh snapshot immediately before claim.
|
|
119
|
+
*/
|
|
120
|
+
export declare function primeIsEligible(input: {
|
|
121
|
+
storage: AccountStorage | null;
|
|
122
|
+
accountId: 'main' | string;
|
|
123
|
+
isOAuth: boolean;
|
|
124
|
+
isEnabled: boolean;
|
|
125
|
+
hasPermanentRefreshError: boolean;
|
|
126
|
+
quota?: OAuthQuotaSnapshot;
|
|
127
|
+
}): PrimeEligibilityResult;
|
|
128
|
+
export declare function primeEligibilityReasonLabel(reason: PrimeEligibilityReason): string;
|
|
129
|
+
export declare const PRIME_REQUEST_BODY: {
|
|
130
|
+
readonly model: "claude-haiku-4-5";
|
|
131
|
+
readonly max_tokens: 1;
|
|
132
|
+
readonly system: 'Reply with 1 when you receive 0.';
|
|
133
|
+
readonly messages: readonly [{
|
|
134
|
+
readonly role: 'user';
|
|
135
|
+
readonly content: '0';
|
|
136
|
+
}];
|
|
137
|
+
};
|
|
138
|
+
export declare function buildPrimeRequestBody(): {
|
|
139
|
+
model: string;
|
|
140
|
+
max_tokens: number;
|
|
141
|
+
system: string;
|
|
142
|
+
messages: Array<{
|
|
143
|
+
role: 'user';
|
|
144
|
+
content: string;
|
|
145
|
+
}>;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Refresh result from a fresh-check. `fresh=false` means the adapter
|
|
149
|
+
* returned a cached snapshot (e.g. quota API in 429-backoff, or another
|
|
150
|
+
* process holds the quota file lock). PrimeManager treats a stale
|
|
151
|
+
* result as "do not claim, retry next tick" so a cached past
|
|
152
|
+
* `resetsAt` can never cause a duplicate prime against an
|
|
153
|
+
* already-started window.
|
|
154
|
+
*/
|
|
155
|
+
export type PrimeRefreshResult = {
|
|
156
|
+
quota: OAuthQuotaSnapshot;
|
|
157
|
+
fresh: boolean;
|
|
158
|
+
};
|
|
159
|
+
export declare function primeStorageFingerprint(storagePath: string): string;
|
|
160
|
+
export declare function primeMarkerNamespaceDir(markerDir: string, storagePath: string): string;
|
|
161
|
+
export declare function primeAccountMarkerDir(markerDir: string, storagePath: string, accountFingerprint: string): string;
|
|
162
|
+
export declare function primeMarkerPath(markerDir: string, accountId: 'main' | string, resetsAtEpochMs: number): string;
|
|
163
|
+
/**
|
|
164
|
+
* Scheduler for `/claude-prime`. Mirrors `CacheKeepManager` lifecycle (unref'd
|
|
165
|
+
* 60s interval, idempotent start/stop, swallowed tick errors) but adds the
|
|
166
|
+
* cross-process atomic marker claim before firing — exactly one OpenCode
|
|
167
|
+
* process fires per reset epoch even with N concurrent instances.
|
|
168
|
+
*
|
|
169
|
+
* Dependencies are injected so the manager can be exercised deterministically
|
|
170
|
+
* without filesystem, network, or live OAuth state.
|
|
171
|
+
*/
|
|
172
|
+
export type PrimeManagerOptions = {
|
|
173
|
+
loadStorage: () => Promise<AccountStorage | null>;
|
|
174
|
+
/** Returns a non-secret digest, or undefined when identity is unavailable. */
|
|
175
|
+
getAccountFingerprint: (accountId: 'main' | string) => Promise<string | undefined>;
|
|
176
|
+
refreshQuota: (accountId: 'main' | string) => Promise<PrimeRefreshResult>;
|
|
177
|
+
sendPrime: (accountId: 'main' | string) => Promise<PrimeSendResult>;
|
|
178
|
+
recordSuccess: (accountId: 'main' | string, usage: {
|
|
179
|
+
inputTokens?: number;
|
|
180
|
+
outputTokens?: number;
|
|
181
|
+
}) => Promise<PrimeUsageCounters>;
|
|
182
|
+
now?: () => number;
|
|
183
|
+
markerDir?: string;
|
|
184
|
+
storagePath: string;
|
|
185
|
+
};
|
|
186
|
+
export declare class PrimeManager {
|
|
187
|
+
private timer;
|
|
188
|
+
private postFireRefreshTimers;
|
|
189
|
+
private lastForcedCheck;
|
|
190
|
+
private stopped;
|
|
191
|
+
options: PrimeManagerOptions;
|
|
192
|
+
private transient;
|
|
193
|
+
private counters;
|
|
194
|
+
private windowActive;
|
|
195
|
+
constructor(options: PrimeManagerOptions);
|
|
196
|
+
updateOptions(options: PrimeManagerOptions): void;
|
|
197
|
+
start(): void;
|
|
198
|
+
stop(): void;
|
|
199
|
+
isStopped(): boolean;
|
|
200
|
+
tick(): Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* Project cumulative per-account status for the sidebar and dialog. Machine
|
|
203
|
+
* values only — formatting belongs in the TUI/sidebar/Pi layer.
|
|
204
|
+
*/
|
|
205
|
+
stats(storage?: AccountStorage | null, nowArg?: number): PrimeAccountStatus[];
|
|
206
|
+
/** True if the most recent fresh-check observed the window as already running. */
|
|
207
|
+
isWindowActive(accountId: 'main' | string): boolean;
|
|
208
|
+
private runForAccount;
|
|
209
|
+
private tryClaim;
|
|
210
|
+
private tryClaimBootstrap;
|
|
211
|
+
private tryClaimPath;
|
|
212
|
+
private hasAnyClaimMarker;
|
|
213
|
+
private fire;
|
|
214
|
+
private schedulePostFireRefresh;
|
|
215
|
+
private sweepMarkers;
|
|
216
|
+
private sweepMarkerDirectory;
|
|
217
|
+
private storageMarkerDir;
|
|
218
|
+
private markerDir;
|
|
219
|
+
}
|