@cortexkit/anthropic-auth-core 2.0.3 → 2.1.1

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 (40) hide show
  1. package/dist/cachekeep.d.ts +2 -0
  2. package/dist/cch.d.ts +19 -0
  3. package/dist/claude-code.d.ts +8 -2
  4. package/dist/claustrum-enrollment.d.ts +5 -1
  5. package/dist/constants.d.ts +15 -3
  6. package/dist/dump.d.ts +2 -0
  7. package/dist/index.d.ts +7 -5
  8. package/dist/index.js +2698 -478
  9. package/dist/insula-quota.d.ts +25 -0
  10. package/dist/internal-types/claustrum/availability.d.ts +89 -0
  11. package/dist/internal-types/claustrum/consumer.d.ts +41 -1
  12. package/dist/internal-types/claustrum/custody.d.ts +135 -14
  13. package/dist/internal-types/claustrum/errors.d.ts +1 -0
  14. package/dist/internal-types/claustrum/index.d.ts +5 -3
  15. package/dist/internal-types/claustrum/insula.d.ts +48 -0
  16. package/dist/internal-types/claustrum/watch.d.ts +141 -0
  17. package/dist/internal-types/quota/format.d.ts +17 -3
  18. package/dist/internal-types/quota/index.d.ts +2 -2
  19. package/dist/internal-types/quota/projection.d.ts +16 -0
  20. package/dist/internal-types/setup/command-error.d.ts +15 -0
  21. package/dist/internal-types/setup/index.d.ts +2 -2
  22. package/dist/internal-types/setup/types.d.ts +12 -0
  23. package/dist/mid-conversation-output-config.d.ts +12 -15
  24. package/dist/migration-source.d.ts +2 -0
  25. package/dist/native-account-runtime.d.ts +3 -2
  26. package/dist/native-custody.d.ts +130 -0
  27. package/dist/native-enrollment-authority.d.ts +5 -1
  28. package/dist/native-host-auth-read.d.ts +2 -1
  29. package/dist/native-host-auth-write.d.ts +2 -0
  30. package/dist/native-runtime.d.ts +5 -1
  31. package/dist/native-vault-invalidation.d.ts +9 -0
  32. package/dist/native-vault-runtime.d.ts +32 -3
  33. package/dist/owner-only.d.ts +19 -0
  34. package/dist/pool-authority.d.ts +2 -1
  35. package/dist/provider-error.d.ts +34 -0
  36. package/dist/publication-rename.d.ts +11 -0
  37. package/dist/quota-manager.d.ts +21 -4
  38. package/dist/quotas.d.ts +19 -3
  39. package/dist/request-gzip.d.ts +99 -0
  40. package/package.json +4 -4
@@ -1,5 +1,6 @@
1
1
  import type { AccountStorage } from './accounts.ts';
2
2
  import type { CacheKeepTrackedSession } from './cachekeep-registry.ts';
3
+ import { type ProviderErrorSummary } from './provider-error.ts';
3
4
  export declare const CLAUDE_CACHE_KEEP_COMMAND_NAME = "claude-cachekeep";
4
5
  export declare const CACHE_KEEP_TTL_MS: number;
5
6
  export declare const CACHE_KEEP_PREWARM_LEAD_MS: number;
@@ -97,6 +98,7 @@ export type CacheKeepPrewarmResult = {
97
98
  reason: string;
98
99
  status?: number;
99
100
  transient?: true;
101
+ provider_error?: ProviderErrorSummary['provider_error'];
100
102
  };
101
103
  export declare class CacheKeepManager {
102
104
  private readonly options;
package/dist/cch.d.ts CHANGED
@@ -1,6 +1,13 @@
1
1
  export interface BillingLineageFields {
2
2
  previousRequestId?: string;
3
3
  promptId?: string;
4
+ /**
5
+ * 1-based position of the current user prompt in the conversation. Claude
6
+ * Code sends it as `cc_prompt_index` and `cc_turn_index` (equal for a turn a
7
+ * person started) after `cc_turn_origin=human`, and keeps it for every
8
+ * request that serves the same prompt, tool-result follow-ups included.
9
+ */
10
+ promptIndex?: number;
4
11
  }
5
12
  export declare function isValidAnthropicRequestId(value: string): boolean;
6
13
  export declare function isValidBillingPromptId(value: string): boolean;
@@ -40,11 +47,23 @@ export declare function signRequestBody(bodyString: string): Promise<string>;
40
47
  * Compute Claude Code's 3-character suffix for cc_version.
41
48
  */
42
49
  export declare function computeCcVersionSuffix(firstUserText: string, version?: string): string;
50
+ /**
51
+ * Number of user prompts in a Messages API history: user messages that carry
52
+ * anything besides tool results. A tool-result message continues the prompt
53
+ * before it, so the request that answers a tool call keeps that prompt's
54
+ * position, as Claude Code's `cc_prompt_index` does.
55
+ */
56
+ export declare function countUserPrompts(messages: unknown): number;
43
57
  /**
44
58
  * Build the billing header with a cch placeholder.
45
59
  * signRequestBody() must run after final request serialization to replace it.
46
60
  */
47
61
  export declare function buildBillingHeaderValue(messages: Message[], version: string | undefined, entrypoint: string, pinnedFirstUserText?: string, lineage?: BillingLineageFields): string;
62
+ /**
63
+ * The `cc_prompt_id` in a signed body's billing block, or undefined. Claude
64
+ * Code also sends this id as the `x-claude-code-prompt-id` header.
65
+ */
66
+ export declare function extractBillingPromptId(body: Record<string, unknown> | null | undefined): string | undefined;
48
67
  /** Remove request-scoped Claude Code lineage from a billing header string. */
49
68
  export declare function stripBillingLineageFields(value: string): string;
50
69
  /** Remove request-scoped Claude Code lineage before reusing a request body. */
@@ -32,12 +32,18 @@ export declare class ClaudeUnsupportedAccessError extends Error {
32
32
  export declare function resolveClaudeCodeAccountIdentity(accessToken: string, model: string | undefined, accountIdentity: string | undefined): Promise<ClaudeCodeIdentity>;
33
33
  export declare function buildClaudeCodeMetadataUserId(identity: ClaudeCodeIdentity): string | null;
34
34
  export declare function applyClaudeCodeMetadata(body: Record<string, unknown>, identity: ClaudeCodeIdentity): boolean;
35
- export declare const CLAUDE_CODE_FULL_AGENT_BETAS: readonly ['oauth-2025-04-20', 'interleaved-thinking-2025-05-14', 'thinking-token-count-2026-05-13', 'context-management-2025-06-27', 'prompt-caching-scope-2026-01-05', 'claude-code-20250219', 'advisor-tool-2026-03-01', 'advanced-tool-use-2025-11-20', 'mid-conversation-system-2026-04-07', 'effort-2025-11-24', 'fallback-credit-2026-06-01', 'extended-cache-ttl-2025-04-11', 'cache-diagnosis-2026-04-07'];
36
- export declare function selectClaudeCodeBetas(body?: Record<string, unknown> | null, extraBetas?: string[]): string;
35
+ export declare const CLAUDE_CODE_FULL_AGENT_BETAS: readonly ['claude-code-20250219', 'oauth-2025-04-20', 'interleaved-thinking-2025-05-14', 'thinking-token-count-2026-05-13', 'context-management-2025-06-27', 'prompt-caching-scope-2026-01-05', 'mid-conversation-tool-changes-2026-07-01', 'advanced-tool-use-2025-11-20', 'mid-conversation-system-clear-at-2026-08-21', 'effort-2025-11-24', 'thinking-binding-controls-2026-08-01', 'thinking-display-updates-2026-08-18', 'extended-cache-ttl-2025-04-11', 'cache-diagnosis-2026-04-07'];
36
+ export declare function selectClaudeCodeBetas(body?: Record<string, unknown> | null, extraBetas?: string[], requestClass?: ClaudeCodeRequestClass): string;
37
+ export type ClaudeCodeRequestClass = 'main' | 'auxiliary';
37
38
  export declare function applyClaudeCodeHeaders(headers: Headers, accessToken: string, options?: {
38
39
  body?: Record<string, unknown> | null;
39
40
  identity?: ClaudeCodeIdentity;
40
41
  extraBetas?: string[];
42
+ /**
43
+ * Claude Code's `x-claude-code-request-class`: `main` for a conversation
44
+ * turn, `auxiliary` for background requests such as title generation.
45
+ */
46
+ requestClass?: ClaudeCodeRequestClass;
41
47
  }): Headers;
42
48
  export declare function orderClaudeCodeBody<T extends Record<string, unknown>>(body: T): T;
43
49
  export declare function claudeCodeEntrypoint(): string;
@@ -1,4 +1,5 @@
1
1
  import { type ClaustrumClientOptions as ClaustrumEnrollmentClientOptions, type EnrollmentPollOutcome, type EnrollmentTokenFile, writeEnrollmentTokenFile } from '@cortexkit/claustrum-client';
2
+ import { type OwnerOnlyOptions } from './owner-only.ts';
2
3
  export declare const CLAUSTRUM_OPENCODE_ENROLLMENT_NAME = "anthropic-auth-opencode";
3
4
  export declare const CLAUSTRUM_PI_ENROLLMENT_NAME = "anthropic-auth-pi";
4
5
  export interface ClaustrumEnrollmentClient {
@@ -50,7 +51,10 @@ export interface ClaustrumEnrollmentPaths {
50
51
  export declare function getClaustrumEnrollmentPaths(tokenPath: string): ClaustrumEnrollmentPaths;
51
52
  /** Resolve the independently enrolled host's owner-only token and state paths. */
52
53
  export declare function getHostClaustrumEnrollmentPaths(host: 'opencode' | 'pi', env?: NodeJS.ProcessEnv, cwd?: string): ClaustrumEnrollmentPaths;
53
- export declare function readClaustrumEnrollmentStatus(paths: ClaustrumEnrollmentPaths, proposedName?: string): Promise<ClaustrumEnrollmentStatus>;
54
+ export declare function refuseWritableAncestor(parent: string, ownership?: OwnerOnlyOptions, metadataAt?: (path: string) => Promise<{
55
+ mode: number;
56
+ } | undefined>): Promise<void>;
57
+ export declare function readClaustrumEnrollmentStatus(paths: ClaustrumEnrollmentPaths, proposedName?: string, ownership?: OwnerOnlyOptions): Promise<ClaustrumEnrollmentStatus>;
54
58
  /** Read fresh bearer material for a scoped operation; never publish this value. */
55
59
  export declare function readClaustrumEnrollmentToken(tokenPath: string): Promise<EnrollmentTokenFile>;
56
60
  export declare class ClaustrumEnrollmentManager {
@@ -19,11 +19,23 @@ export declare const CLAUDE_CODE_IDENTITY = "You are Claude Code, Anthropic's of
19
19
  export declare const PARALLEL_TOOL_CALLS_SYSTEM_PROMPT: string;
20
20
  export declare const CCH_SALT = "59cf53e54c78";
21
21
  export declare const CCH_POSITIONS: number[];
22
- export declare const CLAUDE_CODE_VERSION = "2.1.280";
22
+ export declare const CLAUDE_CODE_VERSION = "2.1.302";
23
23
  export declare const CLAUDE_CODE_ENTRYPOINT = "cli";
24
- export declare const CLAUDE_CODE_STAINLESS_PACKAGE_VERSION = "0.112.1";
24
+ export declare const CLAUDE_CODE_STAINLESS_PACKAGE_VERSION = "0.128.0";
25
25
  export declare const CLAUDE_CODE_STAINLESS_RUNTIME_VERSION = "v26.3.0";
26
- export declare const USER_AGENT = "claude-cli/2.1.280 (external, cli)";
26
+ /**
27
+ * Whether the emulated Claude Code version gzips request bodies. Claude Code
28
+ * 2.1.302 compresses every request body of at least
29
+ * `CLAUDE_CODE_GZIP_MIN_BODY_CHARS` characters that goes straight to
30
+ * api.anthropic.com, and leaves it uncompressed behind a proxy, a custom CA
31
+ * or client certificates. A gzipped body carries `cch=00000` and trailing
32
+ * whitespace padding, which only a gzipping version sends, so this switch
33
+ * belongs to the version above and must change with it.
34
+ */
35
+ export declare const CLAUDE_CODE_GZIPS_REQUEST_BODIES = true;
36
+ /** Smallest body, in UTF-16 characters (`string.length`), Claude Code gzips. */
37
+ export declare const CLAUDE_CODE_GZIP_MIN_BODY_CHARS = 4096;
38
+ export declare const USER_AGENT = "claude-cli/2.1.302 (external, cli)";
27
39
  export declare const CACHE_1H_MODES: readonly ['explicit', 'automatic', 'hybrid'];
28
40
  export type Cache1hMode = (typeof CACHE_1H_MODES)[number];
29
41
  export declare const DEFAULT_CACHE_1H_MODE: Cache1hMode;
package/dist/dump.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { ProviderErrorSummary } from './provider-error.ts';
1
2
  type DumpHeaders = ConstructorParameters<typeof Headers>[0];
2
3
  export declare const CLAUDE_DUMP_COMMAND_NAME = "claude-dump";
3
4
  export type DumpCommandAction = {
@@ -74,5 +75,6 @@ export declare function dumpResponseArtifact(handle: DumpHandle | null, input: {
74
75
  status: number;
75
76
  message: unknown;
76
77
  complete?: boolean;
78
+ provider_error?: ProviderErrorSummary['provider_error'];
77
79
  }): Promise<void>;
78
80
  export {};
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export type { CommandResult, CommandRunner, HostDetection, OpenCodeGeneration, ProcessFence, SetupCallbackContext, SetupDetection, SetupEnvironment, SetupFileSystem, SetupHost, SetupIO, SetupPlugin, SetupResult, } from "./internal-types/setup/index.js";
2
- export { assertHostsStopped, createProcessFence, runSetup, } from "./internal-types/setup/index.js";
2
+ export { assertHostsStopped, createProcessFence, runSetup, setupEnrollment, } from "./internal-types/setup/index.js";
3
3
  export * from './accounts.ts';
4
4
  export * from './auth.ts';
5
5
  export * from './cache1h.ts';
@@ -26,7 +26,7 @@ export { acquireNativeAccountRuntime, createNativeAccountRuntime, nativeAccountP
26
26
  export type { NativeAccountMetadataPatch, NativeAccountSnapshot, NativeAccountView, } from './native-account-view.ts';
27
27
  export { formatNativeAccountState, nativeAccountCanServe, } from './native-account-view.ts';
28
28
  export * from './native-credential-validation.ts';
29
- export type { NativeCustody, NativeCustodyClient, NativeCustodyErrorCode, NativeCustodyIdentity, NativeCustodyInventory, NativeCustodyLogger, NativeCustodyOptions, NativeCustodyReceipt, NativeCustodyReporterSource, NativeCustodyRetry, } from './native-custody.ts';
29
+ export type { NativeCustody, NativeCustodyClient, NativeCustodyErrorCode, NativeCustodyIdentity, NativeCustodyInventory, NativeCustodyLogger, NativeCustodyOptions, NativeCustodyReceipt, NativeCustodyReporterSource, NativeCustodyRetry, NativeRosterWatch, NativeRosterWatchMode, NativeRosterWatchOptions, NativeScopedWatchEnd, NativeScopedWatchHandle, NativeScopedWatchNotice, } from './native-custody.ts';
30
30
  export { createNativeCustody, NativeCustodyError } from './native-custody.ts';
31
31
  export type { NativeCustodyActivationErrorCode, NativeCustodyActivationHooks, NativeCustodyActivationOptions, NativeCustodyActivationResult, } from './native-custody-activation.ts';
32
32
  export { NativeCustodyActivationError, runNativeCustodyActivation, } from './native-custody-activation.ts';
@@ -56,9 +56,10 @@ export * from './native-usage-publication.ts';
56
56
  export { NATIVE_VAULT_NO_ACCOUNT_MESSAGE, NativeVaultNoAccountError, readNativeAccountsForRequest, } from './native-vault-admission.ts';
57
57
  export type { NativePiAuthSlot, NativePiAuthSlotErrorCode, NativePiAuthSlotInspection, NativePiAuthSlotOptions, NativeVaultDisconnectOptions, NativeVaultDisconnectResult, } from './native-vault-connection.ts';
58
58
  export { disconnectNativeVaultForHost, NativePiAuthSlotError, nativePiAuthSlotPaths, openNativePiAuthSlot, } from './native-vault-connection.ts';
59
- export type { NativeVaultRuntime, NativeVaultRuntimeOptions, NativeVaultWatch, NativeVaultWatchOptions, } from './native-vault-runtime.ts';
59
+ export type { NativeVaultQuotaPurpose, NativeVaultRuntime, NativeVaultRuntimeOptions, NativeVaultWatch, NativeVaultWatchOptions, } from './native-vault-runtime.ts';
60
60
  export { acquireNativeVaultRuntime, createNativeVaultRuntime, discoverNativeVaultInventory, publishNativeVaultRosterSeed, publishNativeVaultRuntimeSeed, } from './native-vault-runtime.ts';
61
61
  export * from './oauth-profile.ts';
62
+ export { createWindowsOwnerOnly, ensureWindowsOwnerOnlyDirectory, isOwnerOnly, type OwnerOnlyOptions, } from './owner-only.ts';
62
63
  export * from './pkce.ts';
63
64
  export type { NativeEmptyInitJournal, NativeLegacyMigrationJournal, NativeMigrationJournal, } from './pool-authority.ts';
64
65
  export { nativeMigrationAuthorityPhase, readNativeMigrationJournal, } from './pool-authority.ts';
@@ -68,13 +69,14 @@ export * from './pool-paths.ts';
68
69
  export * from './pool-store.ts';
69
70
  export * from './prime.ts';
70
71
  export * from './provider.ts';
71
- export type { ProviderErrorRedactor, ProviderErrorResponseScope, ProviderResponseMode, ProviderResponseSettlement, } from './provider-error.ts';
72
- export { createProviderErrorRedactor, createProviderErrorResponseScope, } from './provider-error.ts';
72
+ export type { ProviderErrorRedactor, ProviderErrorResponseScope, ProviderErrorSummary, ProviderResponseMode, ProviderResponseSettlement, } from './provider-error.ts';
73
+ export { createProviderErrorRedactor, createProviderErrorResponseScope, summarizePrewarmProviderError, } from './provider-error.ts';
73
74
  export * from './quota-header-feed.ts';
74
75
  export * from './quota-headers.ts';
75
76
  export * from './quota-manager.ts';
76
77
  export * from './quotas.ts';
77
78
  export * from './relay.ts';
79
+ export * from './request-gzip.ts';
78
80
  export * from './request-history.ts';
79
81
  export * from './routing.ts';
80
82
  export type { SseEvent, SseFramer, SseFramerOptions } from './sse.ts';