@cortexkit/anthropic-auth-core 2.0.3 → 2.1.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/cachekeep.d.ts +2 -0
- package/dist/cch.d.ts +19 -0
- package/dist/claude-code.d.ts +8 -2
- package/dist/claustrum-enrollment.d.ts +5 -1
- package/dist/constants.d.ts +15 -3
- package/dist/dump.d.ts +2 -0
- package/dist/index.d.ts +7 -5
- package/dist/index.js +2698 -478
- package/dist/insula-quota.d.ts +25 -0
- package/dist/internal-types/claustrum/availability.d.ts +89 -0
- package/dist/internal-types/claustrum/consumer.d.ts +41 -1
- package/dist/internal-types/claustrum/custody.d.ts +135 -14
- package/dist/internal-types/claustrum/errors.d.ts +1 -0
- package/dist/internal-types/claustrum/index.d.ts +5 -3
- package/dist/internal-types/claustrum/insula.d.ts +48 -0
- package/dist/internal-types/claustrum/watch.d.ts +141 -0
- package/dist/internal-types/quota/format.d.ts +17 -3
- package/dist/internal-types/quota/index.d.ts +2 -2
- package/dist/internal-types/quota/projection.d.ts +16 -0
- package/dist/internal-types/setup/command-error.d.ts +15 -0
- package/dist/internal-types/setup/index.d.ts +2 -2
- package/dist/internal-types/setup/types.d.ts +12 -0
- package/dist/mid-conversation-output-config.d.ts +12 -15
- package/dist/migration-source.d.ts +2 -0
- package/dist/native-account-runtime.d.ts +3 -2
- package/dist/native-custody.d.ts +130 -0
- package/dist/native-enrollment-authority.d.ts +5 -1
- package/dist/native-host-auth-read.d.ts +2 -1
- package/dist/native-host-auth-write.d.ts +2 -0
- package/dist/native-runtime.d.ts +5 -1
- package/dist/native-vault-invalidation.d.ts +9 -0
- package/dist/native-vault-runtime.d.ts +32 -3
- package/dist/owner-only.d.ts +19 -0
- package/dist/pool-authority.d.ts +2 -1
- package/dist/provider-error.d.ts +34 -0
- package/dist/publication-rename.d.ts +11 -0
- package/dist/quota-manager.d.ts +21 -4
- package/dist/quotas.d.ts +19 -3
- package/dist/request-gzip.d.ts +99 -0
- package/package.json +4 -4
package/dist/quota-manager.d.ts
CHANGED
|
@@ -17,6 +17,13 @@ export type QuotaRefreshResult = {
|
|
|
17
17
|
/** False when backoff or a cross-process lock served the existing cache. */
|
|
18
18
|
fetched: boolean;
|
|
19
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Why a quota reading is wanted, passed to fetchQuotaSnapshot unchanged.
|
|
22
|
+
* Vault custody uses it to decide whether insula's background quota cache
|
|
23
|
+
* may answer instead of a usage GET (see NativeVaultQuotaPurpose); omitted
|
|
24
|
+
* means poll the provider directly.
|
|
25
|
+
*/
|
|
26
|
+
export type QuotaReadingPurpose = 'background' | 'admission';
|
|
20
27
|
/** Pace a physical usage GET and verify the selected credential is still eligible before sending. */
|
|
21
28
|
export type QuotaRequestDispatch = (send: () => Promise<Response>, revalidate: () => Promise<void>) => Promise<Response>;
|
|
22
29
|
export type QuotaManagerOptions = {
|
|
@@ -34,8 +41,17 @@ export type QuotaManagerOptions = {
|
|
|
34
41
|
kind: 'main' | 'fallback';
|
|
35
42
|
accountId: string | undefined;
|
|
36
43
|
accessToken: string;
|
|
44
|
+
purpose?: QuotaReadingPurpose;
|
|
37
45
|
}, dispatch: QuotaRequestDispatch) => Promise<OAuthQuotaSnapshot>;
|
|
38
46
|
now?: () => number;
|
|
47
|
+
/**
|
|
48
|
+
* Waits before a physical usage GET until the minimum gap since the previous
|
|
49
|
+
* one has passed. It receives the milliseconds still to wait, measured with
|
|
50
|
+
* `now`, and is called only when that remainder is positive. Defaults to a
|
|
51
|
+
* real timer that does not keep the process alive. Tests pass one that
|
|
52
|
+
* records the requested wait and resolves at once.
|
|
53
|
+
*/
|
|
54
|
+
pauseBetweenQuotaCalls?: (ms: number) => Promise<void>;
|
|
39
55
|
onMainQuotaFetched?: (quota: OAuthQuotaSnapshot, checkedAt: number, tokenFingerprint: string, fetchStartedAt: number, quotaErrorGeneration: number, quotaErrorClearedAt: number | undefined) => void;
|
|
40
56
|
onApiError?: (error: AccountOperationError, quotaErrorGeneration: number) => void;
|
|
41
57
|
onFallbackQuotaFetched?: (accountId: string, quota: OAuthQuotaSnapshot, checkedAt: number, fetchStartedAt: number) => void;
|
|
@@ -66,6 +82,7 @@ export declare class QuotaManager {
|
|
|
66
82
|
private readonly fetchImpl;
|
|
67
83
|
private readonly fetchQuotaSnapshot;
|
|
68
84
|
private readonly now;
|
|
85
|
+
private readonly pauseBetweenQuotaCalls;
|
|
69
86
|
private readonly onMainQuotaFetched;
|
|
70
87
|
private readonly onApiError;
|
|
71
88
|
private readonly onFallbackQuotaFetched;
|
|
@@ -91,10 +108,10 @@ export declare class QuotaManager {
|
|
|
91
108
|
clearFallback(accountId: string): void;
|
|
92
109
|
pushMainFromHeaders(mainAccountId: string | undefined, incoming: OAuthQuotaSnapshot): QuotaEntry;
|
|
93
110
|
pushFallbackFromHeaders(accountId: string, incoming: OAuthQuotaSnapshot, account: Pick<OAuthAccount, 'authLineageId'> | undefined): QuotaEntry | null;
|
|
94
|
-
refreshMain(mainAccountIdOrAccessToken: string | undefined, accessToken?: string, expectedIdentityGeneration?: number): Promise<OAuthQuotaSnapshot>;
|
|
95
|
-
refreshMainWithMetadata(mainAccountIdOrAccessToken: string | undefined, accessToken?: string, expectedIdentityGeneration?: number): Promise<QuotaRefreshResult>;
|
|
96
|
-
refreshFallback(accountId: string, accessToken: string, account: Pick<OAuthAccount, 'authLineageId'> | undefined): Promise<OAuthQuotaSnapshot>;
|
|
97
|
-
refreshFallbackWithMetadata(accountId: string, accessToken: string, account: Pick<OAuthAccount, 'authLineageId'> | undefined): Promise<QuotaRefreshResult>;
|
|
111
|
+
refreshMain(mainAccountIdOrAccessToken: string | undefined, accessToken?: string, expectedIdentityGeneration?: number, purpose?: QuotaReadingPurpose): Promise<OAuthQuotaSnapshot>;
|
|
112
|
+
refreshMainWithMetadata(mainAccountIdOrAccessToken: string | undefined, accessToken?: string, expectedIdentityGeneration?: number, purpose?: QuotaReadingPurpose): Promise<QuotaRefreshResult>;
|
|
113
|
+
refreshFallback(accountId: string, accessToken: string, account: Pick<OAuthAccount, 'authLineageId'> | undefined, purpose?: QuotaReadingPurpose): Promise<OAuthQuotaSnapshot>;
|
|
114
|
+
refreshFallbackWithMetadata(accountId: string, accessToken: string, account: Pick<OAuthAccount, 'authLineageId'> | undefined, purpose?: QuotaReadingPurpose): Promise<QuotaRefreshResult>;
|
|
98
115
|
refreshAllFallbacks(accounts: OAuthAccount[], resolveAccessToken?: (account: OAuthAccount) => string | undefined): Promise<void>;
|
|
99
116
|
/**
|
|
100
117
|
* Fire-and-forget refresh. Does not await, swallows errors.
|
package/dist/quotas.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { formatQuota, type ProjectedQuota, quotaTextParts, quotaWindowParts } from "./internal-types/quota/index.js";
|
|
2
|
-
import type { AccountQuotaWindow, AccountScopedQuotaWindow, AccountStorage, OAuthQuotaSnapshot } from './accounts.ts';
|
|
1
|
+
import { formatQuota, isQuotaStale, type ProjectedQuota, quotaTextParts, quotaWindowParts } from "./internal-types/quota/index.js";
|
|
2
|
+
import type { AccountQuotaWindow, AccountScopedQuotaWindow, AccountStorage, OAuthExtraUsageSnapshot, OAuthQuotaSnapshot, QuotaMoney } from './accounts.ts';
|
|
3
3
|
export declare const CLAUDE_QUOTAS_COMMAND_NAME = "claude-quota";
|
|
4
4
|
export type { QuotaWindowPart } from "./internal-types/quota/index.js";
|
|
5
|
-
export { formatQuota, quotaTextParts, quotaWindowParts };
|
|
5
|
+
export { formatQuota, isQuotaStale, quotaTextParts, quotaWindowParts };
|
|
6
6
|
type DisplayWindow = Omit<AccountQuotaWindow, 'checkedAt'> & {
|
|
7
7
|
checkedAt?: number;
|
|
8
8
|
};
|
|
@@ -14,6 +14,22 @@ export type QuotaDisplaySnapshot = Pick<OAuthQuotaSnapshot, 'checkedAt' | 'extra
|
|
|
14
14
|
};
|
|
15
15
|
/** Adapt every reported window without projecting away other model families. */
|
|
16
16
|
export declare function quotaDisplayProjection(snapshot: QuotaDisplaySnapshot | null | undefined, now: number): ProjectedQuota | undefined;
|
|
17
|
+
export type QuotaMoneyFormat = {
|
|
18
|
+
/** Leave out the fractional digits, cutting the amount down to whole units. */
|
|
19
|
+
wholeUnits?: boolean;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* A stored money amount in its own currency, such as `$25.00` or `€1,250.00`.
|
|
23
|
+
* An amount whose currency the runtime cannot format reads as its raw minor
|
|
24
|
+
* units and currency code.
|
|
25
|
+
*/
|
|
26
|
+
export declare function formatQuotaMoney(money: QuotaMoney, options?: QuotaMoneyFormat): string;
|
|
27
|
+
/**
|
|
28
|
+
* The credit amounts shown after the shared credit figure: `$25.00/$100.00`
|
|
29
|
+
* (spent / monthly limit). Undefined when the limit is zero or either amount
|
|
30
|
+
* is missing or malformed, so the figure is then shown on its own.
|
|
31
|
+
*/
|
|
32
|
+
export declare function formatCreditAmounts(extraUsage: Partial<OAuthExtraUsageSnapshot> | null | undefined, options?: QuotaMoneyFormat): string | undefined;
|
|
17
33
|
export type QuotaAccountSummary = {
|
|
18
34
|
name: string;
|
|
19
35
|
role: 'main' | 'fallback';
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/** Claude Code's own opt-out: `0`/`false` turns gzip off, `1`/`true` forces it. */
|
|
2
|
+
export declare const GZIP_REQUEST_BODIES_ENV = "CLAUDE_CODE_GZIP_REQUEST_BODIES";
|
|
3
|
+
/** How long a persisted latch keeps gzip off. */
|
|
4
|
+
export declare const GZIP_LATCH_TTL_MS: number;
|
|
5
|
+
export type RequestGzipSkipReason = 'version' | 'host' | 'env_off' | 'below_min_size' | 'proxy' | 'mtls' | 'custom_ca' | 'latched_off';
|
|
6
|
+
export type RequestGzipDecision = {
|
|
7
|
+
gzip: true;
|
|
8
|
+
forced: boolean;
|
|
9
|
+
} | {
|
|
10
|
+
gzip: false;
|
|
11
|
+
reason: RequestGzipSkipReason;
|
|
12
|
+
};
|
|
13
|
+
export type GzipRejectionKind = 'non_anthropic_rejection' | 'invalid_json_at_origin';
|
|
14
|
+
/**
|
|
15
|
+
* What the caller's transport adds beyond the environment: a proxy, a custom
|
|
16
|
+
* certificate authority or a client certificate the caller passes to fetch
|
|
17
|
+
* itself. Claude Code sends uncompressed bodies through any of these.
|
|
18
|
+
*/
|
|
19
|
+
export interface RequestGzipTransport {
|
|
20
|
+
proxy?: boolean;
|
|
21
|
+
customCa?: boolean;
|
|
22
|
+
mtls?: boolean;
|
|
23
|
+
}
|
|
24
|
+
type Env = Record<string, string | undefined>;
|
|
25
|
+
/**
|
|
26
|
+
* Remembers that a gzipped body was rejected. Any rejection turns gzip off
|
|
27
|
+
* for this process; a proxy rejection followed by an accepted uncompressed
|
|
28
|
+
* resend also writes `{latchedAt, status}` to `path`, which keeps gzip off
|
|
29
|
+
* for seven days in later processes. The file belongs to this plugin, not to
|
|
30
|
+
* the user's settings. An expired, future-dated or unreadable record is
|
|
31
|
+
* removed when read.
|
|
32
|
+
*/
|
|
33
|
+
export declare class RequestGzipLatch {
|
|
34
|
+
#private;
|
|
35
|
+
readonly path?: string | undefined;
|
|
36
|
+
readonly now: () => number;
|
|
37
|
+
constructor(path?: string | undefined, now?: () => number);
|
|
38
|
+
get latchedThisProcess(): boolean;
|
|
39
|
+
latchProcess(): void;
|
|
40
|
+
/** Whether the latch file holds a record younger than seven days (read once). */
|
|
41
|
+
persistedInEffect(): Promise<boolean>;
|
|
42
|
+
persist(status: number): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
/** One latch per storage path, shared by every send path in this process. */
|
|
45
|
+
export declare function getRequestGzipLatch(path?: string): RequestGzipLatch;
|
|
46
|
+
/** The latch file path: `<stem>-request-gzip.json` beside the account storage file. */
|
|
47
|
+
export declare function getRequestGzipLatchPath(accountStoragePath: string): string;
|
|
48
|
+
/** Decide, in Claude Code's order, whether this request body goes out gzipped. */
|
|
49
|
+
export declare function decideRequestGzip(options: {
|
|
50
|
+
url: string | URL;
|
|
51
|
+
body: unknown;
|
|
52
|
+
latch: RequestGzipLatch;
|
|
53
|
+
env?: Env;
|
|
54
|
+
transport?: RequestGzipTransport;
|
|
55
|
+
}): Promise<RequestGzipDecision>;
|
|
56
|
+
/** A newline and 0 to 256 random spaces and tabs, as Claude Code appends. */
|
|
57
|
+
export declare function requestGzipPadding(random?: () => number): string;
|
|
58
|
+
/**
|
|
59
|
+
* The gzipped wire bytes for a signed identity body: `cch` reset to `00000`,
|
|
60
|
+
* padding appended, one gzip member at level 6. Never sign the result.
|
|
61
|
+
*/
|
|
62
|
+
export declare function encodeGzipRequestBody(identityBody: string, random?: () => number): Promise<Uint8Array>;
|
|
63
|
+
/**
|
|
64
|
+
* Claude Code's test for a rejected gzipped body: a 400, 403 or 415 that
|
|
65
|
+
* either did not come from Anthropic (no `req_` request id and no `cf-ray`)
|
|
66
|
+
* or, for a 400, says the JSON could not be parsed. Any other response,
|
|
67
|
+
* including an ordinary API 400, is not a gzip problem. Reads at most 8 KiB
|
|
68
|
+
* from a clone, so the response itself stays unread.
|
|
69
|
+
*/
|
|
70
|
+
export declare function classifyGzipRejection(response: Response): Promise<GzipRejectionKind | null>;
|
|
71
|
+
export interface RequestGzipEvent {
|
|
72
|
+
decision: RequestGzipDecision;
|
|
73
|
+
rejection?: {
|
|
74
|
+
kind: GzipRejectionKind;
|
|
75
|
+
status: number;
|
|
76
|
+
};
|
|
77
|
+
resendStatus?: number;
|
|
78
|
+
persisted?: boolean;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Send a signed identity body, gzipped when Claude Code would gzip it.
|
|
82
|
+
*
|
|
83
|
+
* `send` performs one physical request with the given body and headers; it is
|
|
84
|
+
* called once, or twice when the gzipped body is rejected: the second call
|
|
85
|
+
* gets the identity body and the same headers (same `x-client-request-id`,
|
|
86
|
+
* same retry count) minus `content-encoding`. That resend is not a retry.
|
|
87
|
+
*/
|
|
88
|
+
export declare function sendWithRequestGzip(options: {
|
|
89
|
+
url: string | URL;
|
|
90
|
+
body: string;
|
|
91
|
+
headers: Headers;
|
|
92
|
+
send: (body: string | Uint8Array, headers: Headers) => Promise<Response>;
|
|
93
|
+
latch: RequestGzipLatch;
|
|
94
|
+
env?: Env;
|
|
95
|
+
transport?: RequestGzipTransport;
|
|
96
|
+
random?: () => number;
|
|
97
|
+
onEvent?: (event: RequestGzipEvent) => void;
|
|
98
|
+
}): Promise<Response>;
|
|
99
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/anthropic-auth-core",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"prepublishOnly": "bun run build"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@cortexkit/common-auth": "0.
|
|
33
|
+
"@cortexkit/common-auth": "0.21.1"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@cortexkit/claustrum-client": "0.
|
|
36
|
+
"@cortexkit/claustrum-client": "0.12.0",
|
|
37
37
|
"@cortexkit/private-files": "0.2.1",
|
|
38
|
-
"@cortexkit/subc-client": "^0.
|
|
38
|
+
"@cortexkit/subc-client": "^0.22.0",
|
|
39
39
|
"jsonc-parser": "^3.3.1",
|
|
40
40
|
"xxhash-wasm": "^1.1.0"
|
|
41
41
|
}
|