@cortexkit/anthropic-auth-core 1.23.0 → 2.0.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/README.md +2 -0
- package/dist/accounts.d.ts +3 -16
- package/dist/cachekeep.d.ts +9 -0
- package/dist/claude-code.d.ts +16 -0
- package/dist/claustrum-enrollment.d.ts +2 -0
- package/dist/claustrum-scoped-roster.d.ts +4 -0
- package/dist/claustrum-scoped-runtime.d.ts +3 -0
- package/dist/claustrum-scoped.d.ts +14 -0
- package/dist/claustrum.d.ts +0 -209
- package/dist/commands/account.d.ts +2 -3
- package/dist/index.d.ts +44 -1
- package/dist/index.js +29700 -38
- package/dist/internal-types/LICENSE +21 -0
- package/dist/internal-types/commands/builtins.d.ts +71 -0
- package/dist/internal-types/commands/index.d.ts +10 -0
- package/dist/internal-types/commands/menu.d.ts +61 -0
- package/dist/internal-types/commands/model.d.ts +238 -0
- package/dist/internal-types/commands/pi.d.ts +23 -0
- package/dist/internal-types/commands/seam.d.ts +72 -0
- package/dist/internal-types/fs/refresh-file-lock.d.ts +33 -0
- package/dist/internal-types/logger/capture-sink.d.ts +14 -0
- package/dist/internal-types/logger/engine.d.ts +100 -0
- package/dist/internal-types/logger/index.d.ts +6 -0
- package/dist/internal-types/logger/redact.d.ts +11 -0
- package/dist/internal-types/pi-slot/index.d.ts +3 -0
- package/dist/internal-types/pi-slot/slot.d.ts +49 -0
- package/dist/internal-types/quota/codec.d.ts +11 -0
- package/dist/internal-types/quota/format.d.ts +46 -0
- package/dist/internal-types/quota/index.d.ts +10 -0
- package/dist/internal-types/quota/map.d.ts +63 -0
- package/dist/internal-types/quota/merge.d.ts +48 -0
- package/dist/internal-types/quota/projection.d.ts +64 -0
- package/dist/internal-types/store/attribution.d.ts +28 -0
- package/dist/internal-types/store/errors.d.ts +55 -0
- package/dist/internal-types/store/hooks.d.ts +12 -0
- package/dist/internal-types/store/identity.d.ts +39 -0
- package/dist/internal-types/store/index.d.ts +21 -0
- package/dist/internal-types/store/mutate.d.ts +189 -0
- package/dist/internal-types/store/pool.d.ts +196 -0
- package/dist/internal-types/store/provider-state.d.ts +131 -0
- package/dist/internal-types/store/publication.d.ts +47 -0
- package/dist/internal-types/store/pull.d.ts +36 -0
- package/dist/internal-types/store/refresh-lock.d.ts +63 -0
- package/dist/internal-types/store/refresh.d.ts +72 -0
- package/dist/internal-types/store/rows.d.ts +313 -0
- package/dist/internal-types/store/runtime.d.ts +36 -0
- package/dist/internal-types/store/schema.d.ts +443 -0
- package/dist/internal-types/store/settings.d.ts +63 -0
- package/dist/internal-types/store/torn.d.ts +78 -0
- package/dist/migration-source.d.ts +33 -0
- package/dist/models.d.ts +41 -0
- package/dist/native-account-runtime.d.ts +121 -0
- package/dist/native-account-view.d.ts +126 -0
- package/dist/native-command-effects.d.ts +59 -0
- package/dist/native-credential-validation.d.ts +42 -0
- package/dist/native-custody-activation.d.ts +45 -0
- package/dist/native-custody.d.ts +114 -0
- package/dist/native-enrollment-authority.d.ts +2 -0
- package/dist/native-host-auth-read.d.ts +3 -0
- package/dist/native-host-auth-write.d.ts +51 -0
- package/dist/native-host-auth.d.ts +12 -0
- package/dist/native-local-credential-service.d.ts +76 -0
- package/dist/native-local-runtime-readers.d.ts +22 -0
- package/dist/native-lock-observer.d.ts +12 -0
- package/dist/native-menu-executor.d.ts +243 -0
- package/dist/native-menu-model.d.ts +142 -0
- package/dist/native-migration-proof.d.ts +28 -0
- package/dist/native-migration-source.d.ts +47 -0
- package/dist/native-migration.d.ts +66 -0
- package/dist/native-quota-codec.d.ts +32 -0
- package/dist/native-refresh-coordinator.d.ts +240 -0
- package/dist/native-roster-seed.d.ts +115 -0
- package/dist/native-runtime-registry.d.ts +19 -0
- package/dist/native-runtime.d.ts +204 -0
- package/dist/native-transient-account.d.ts +38 -0
- package/dist/native-ui.d.ts +45 -0
- package/dist/native-usage-publication.d.ts +11 -0
- package/dist/native-vault-admission.d.ts +8 -0
- package/dist/native-vault-connection.d.ts +33 -0
- package/dist/native-vault-paths.d.ts +13 -0
- package/dist/native-vault-runtime.d.ts +102 -0
- package/dist/native-vault-seed.d.ts +16 -0
- package/dist/pool-authority.d.ts +159 -0
- package/dist/pool-binding.d.ts +32 -0
- package/dist/pool-paths.d.ts +21 -0
- package/dist/pool-store.d.ts +32 -0
- package/dist/provider-error.d.ts +139 -0
- package/dist/quota-manager.d.ts +18 -7
- package/dist/relay.d.ts +14 -1
- package/dist/request-history.d.ts +34 -0
- package/dist/sse.d.ts +81 -0
- package/dist/sticky-routing.d.ts +27 -0
- package/package.json +9 -4
- package/dist/accounts.js +0 -3881
- package/dist/auth.js +0 -185
- package/dist/cache1h.js +0 -97
- package/dist/cachekeep-registry.js +0 -124
- package/dist/cachekeep.js +0 -604
- package/dist/cch.js +0 -172
- package/dist/claude-code.js +0 -403
- package/dist/claustrum-enrollment-registry.d.ts +0 -17
- package/dist/claustrum-enrollment-registry.js +0 -194
- package/dist/claustrum-enrollment.js +0 -485
- package/dist/claustrum-scoped-roster.js +0 -194
- package/dist/claustrum-scoped-runtime.js +0 -230
- package/dist/claustrum-scoped.js +0 -193
- package/dist/claustrum.js +0 -1471
- package/dist/commands/account.js +0 -368
- package/dist/constants.js +0 -83
- package/dist/custom-headers.js +0 -102
- package/dist/dump.js +0 -616
- package/dist/fast.js +0 -66
- package/dist/json.js +0 -10
- package/dist/killswitch.js +0 -132
- package/dist/logger.js +0 -288
- package/dist/logging.js +0 -59
- package/dist/mid-conversation-output-config.js +0 -89
- package/dist/model-remap.js +0 -72
- package/dist/models.js +0 -177
- package/dist/network-errors.js +0 -27
- package/dist/oauth-profile.js +0 -60
- package/dist/pkce.js +0 -17
- package/dist/prime.js +0 -841
- package/dist/provider.js +0 -0
- package/dist/quota-header-feed.js +0 -331
- package/dist/quota-headers.js +0 -121
- package/dist/quota-manager.js +0 -856
- package/dist/quotas.js +0 -141
- package/dist/relay.js +0 -1303
- package/dist/routing.js +0 -94
- package/dist/start.js +0 -29
- package/dist/sticky-routing.js +0 -541
- package/dist/thinking-binding.js +0 -54
- package/dist/token-fingerprint.js +0 -8
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type CommandInvocation, type CommandMenu } from "./internal-types/commands/index.js";
|
|
2
|
+
export type { CommandApplyRequest, CommandApplyResult, CommandDialogPayload, CommandInvocation, CommandMenu, CommandMenuModel, KnobValue, KnobValues, MenuAction, MenuItem, MenuKnob, MenuSection, NotifyKind, SectionSlot, } from "./internal-types/commands/index.js";
|
|
3
|
+
export { parseApplyRequest, runPiCommandMenu, } from "./internal-types/commands/index.js";
|
|
4
|
+
import { type NativeMenuDispatch, type NativeVaultDisconnect } from './native-menu-executor.ts';
|
|
5
|
+
import { type NativeMenuCommandId, type NativeMenuCustodyMode, type NativeMenuHost } from './native-menu-model.ts';
|
|
6
|
+
export interface NativeUiOptions {
|
|
7
|
+
readonly host: NativeMenuHost;
|
|
8
|
+
/** Execute account/settings changes and host actions; this adapter never writes their storage. */
|
|
9
|
+
readonly dispatch: NativeMenuDispatch;
|
|
10
|
+
/** Read-only account, quota and settings status. Exclude OAuth tokens, API keys and other secrets. */
|
|
11
|
+
readonly readStatus: (command: Exclude<NativeMenuCommandId, 'start'>, invocation: CommandInvocation) => Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Reads the host's current credential custody from its enrollment record,
|
|
14
|
+
* never from status text. It is called each time the menu opens or applies
|
|
15
|
+
* an action, so connecting or disconnecting the vault takes effect without
|
|
16
|
+
* rebuilding the menu. Under 'claustrum' the menu leaves out and refuses
|
|
17
|
+
* actions offered only under local custody: host-local account and
|
|
18
|
+
* credential writes, and enrollment reset. A rejection or any other value
|
|
19
|
+
* is treated as unknown custody, which also withholds them.
|
|
20
|
+
*/
|
|
21
|
+
readonly readMode: () => Promise<NativeMenuCustodyMode>;
|
|
22
|
+
/** Token-free account names, credential IDs and states used to show which vault account needs re-login and its replacement command. */
|
|
23
|
+
readonly readAccounts?: () => Promise<import('./native-account-view.ts').NativeAccountSnapshot>;
|
|
24
|
+
/**
|
|
25
|
+
* Disconnects this host from the vault; while enrolled, this is the host's
|
|
26
|
+
* only enrollment action. Before ending the enrollment, the callback
|
|
27
|
+
* restores any host sign-in set aside when the host joined the vault. If
|
|
28
|
+
* that restore would overwrite a sign-in the host already has, the callback
|
|
29
|
+
* reports `conflict` and leaves the enrollment in place. Every host must
|
|
30
|
+
* supply it: a host enrolled in the vault, or with an unreadable
|
|
31
|
+
* enrollment, always needs a way back to local accounts.
|
|
32
|
+
*/
|
|
33
|
+
readonly disconnectVault: NativeVaultDisconnect;
|
|
34
|
+
/** The host sets this flag; RPC callers cannot declare themselves interactive. */
|
|
35
|
+
readonly interactive: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Builds the Claude menu from the supported commands for OpenCode or Pi.
|
|
39
|
+
* Shared renderers display it, but each submitted action still goes through
|
|
40
|
+
* input validation, required confirmation and host capability checks.
|
|
41
|
+
* Credential fields never contain saved values. Current host input controls
|
|
42
|
+
* display typed text even when the field requests masking; do not promise
|
|
43
|
+
* hidden entry until those controls support it.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createNativeUi(options: NativeUiOptions): CommandMenu;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custody, ownership and integrity refusals need an ERROR diagnostic; ordinary
|
|
3
|
+
* storage failures need a WARN. Neither may revoke an already-served reply.
|
|
4
|
+
* The error classes are not public runtime exports, so match name and code.
|
|
5
|
+
*/
|
|
6
|
+
export declare function usagePublicationRefusalIsFatal(error: unknown): boolean;
|
|
7
|
+
/** Own advisory writes for one host instance and join them before runtime close. */
|
|
8
|
+
export declare function createNativeUsagePublisher(channel: string): {
|
|
9
|
+
publish(write: () => Promise<unknown>): void;
|
|
10
|
+
drain(): Promise<void>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { NativeAccountRuntime } from './native-account-runtime.ts';
|
|
2
|
+
import type { NativeAccountSnapshot } from './native-account-view.ts';
|
|
3
|
+
export declare const NATIVE_VAULT_NO_ACCOUNT_MESSAGE = "No vault account can serve this request. Open /claude to see which account needs signing in again.";
|
|
4
|
+
export declare class NativeVaultNoAccountError extends Error {
|
|
5
|
+
constructor();
|
|
6
|
+
}
|
|
7
|
+
/** A missing roster may be discovery still in progress, not an empty pool. */
|
|
8
|
+
export declare function readNativeAccountsForRequest(runtime: NativeAccountRuntime, signal?: AbortSignal): Promise<NativeAccountSnapshot>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type PiSlot } from "./internal-types/pi-slot/index.js";
|
|
2
|
+
export type { PiSlot as NativePiAuthSlot, PiSlotErrorCode as NativePiAuthSlotErrorCode, PiSlotInspection as NativePiAuthSlotInspection, } from "./internal-types/pi-slot/index.js";
|
|
3
|
+
export { PiSlotError as NativePiAuthSlotError } from "./internal-types/pi-slot/index.js";
|
|
4
|
+
export interface NativePiAuthSlotOptions {
|
|
5
|
+
/** The Pi adapter supplies its SDK-owned auth path; enrollment paths do not identify that file. */
|
|
6
|
+
authPath: string;
|
|
7
|
+
env?: NodeJS.ProcessEnv;
|
|
8
|
+
}
|
|
9
|
+
/** Setup and disconnect must use the same host auth file, private stash and inert API-key marker. */
|
|
10
|
+
export declare function nativePiAuthSlotPaths(options: NativePiAuthSlotOptions): {
|
|
11
|
+
authPath: string;
|
|
12
|
+
stashPath: string;
|
|
13
|
+
provider: string;
|
|
14
|
+
placeholderKey: string;
|
|
15
|
+
};
|
|
16
|
+
/** Delegate private Pi-auth preservation to the shared locked writer; never create a second host-slot writer. */
|
|
17
|
+
export declare function openNativePiAuthSlot(options: NativePiAuthSlotOptions): PiSlot;
|
|
18
|
+
export type NativeVaultDisconnectOptions = {
|
|
19
|
+
host: 'opencode';
|
|
20
|
+
env?: NodeJS.ProcessEnv;
|
|
21
|
+
} | {
|
|
22
|
+
host: 'pi';
|
|
23
|
+
env?: NodeJS.ProcessEnv;
|
|
24
|
+
slot: Pick<PiSlot, 'exitVault'>;
|
|
25
|
+
};
|
|
26
|
+
export type NativeVaultDisconnectResult = 'disconnected' | 'idle' | 'busy' | 'conflict';
|
|
27
|
+
/**
|
|
28
|
+
* Restore Pi's stored authentication before removing this host's enrollment.
|
|
29
|
+
* A conflicting replacement belongs to the user: leave both it and enrollment
|
|
30
|
+
* intact rather than selecting local custody with unresolved recovery data.
|
|
31
|
+
* OpenCode authentication is never changed by this operation.
|
|
32
|
+
*/
|
|
33
|
+
export declare function disconnectNativeVaultForHost(options: NativeVaultDisconnectOptions): Promise<NativeVaultDisconnectResult>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NativePoolPaths } from './pool-paths.ts';
|
|
2
|
+
/** Vault files have no migration journal: enrollment alone authorizes their use. */
|
|
3
|
+
export interface NativeVaultPaths {
|
|
4
|
+
config: string;
|
|
5
|
+
state: string;
|
|
6
|
+
runtime: string;
|
|
7
|
+
roster: string;
|
|
8
|
+
routing: string;
|
|
9
|
+
storageId: string;
|
|
10
|
+
legacySeedConfig: string;
|
|
11
|
+
}
|
|
12
|
+
/** Keep vault settings, metadata and affinity outside every local recovery file. */
|
|
13
|
+
export declare function nativeVaultPaths(local: NativePoolPaths): NativeVaultPaths;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { type ClaustrumClientOptions } from '@cortexkit/claustrum-client';
|
|
2
|
+
import { type OAuthAccountProfile, type OAuthQuotaSnapshot, type PrimeUsageDelta } from './accounts.ts';
|
|
3
|
+
import { type NativeAccountMetadataPatch } from './native-account-view.ts';
|
|
4
|
+
import { type NativeCustodyClient, type NativeCustodyInventory, type NativeCustodyReceipt, type NativeCustodyReporterSource, type NativeCustodyRetry } from './native-custody.ts';
|
|
5
|
+
import { type NativeRosterSeedInput, type NativeVaultRosterDocument, type NativeVaultRosterSeed } from './native-roster-seed.ts';
|
|
6
|
+
import { type NativeRuntimeState } from './native-runtime.ts';
|
|
7
|
+
import type { NativeVaultPaths } from './native-vault-paths.ts';
|
|
8
|
+
import type { NativePoolPaths } from './pool-paths.ts';
|
|
9
|
+
import type { QuotaRequestDispatch } from './quota-manager.ts';
|
|
10
|
+
export interface NativeVaultRuntimeOptions {
|
|
11
|
+
paths: NativePoolPaths;
|
|
12
|
+
host: 'opencode' | 'pi';
|
|
13
|
+
identity?: ClaustrumClientOptions['identity'];
|
|
14
|
+
connect?: () => Promise<NativeCustodyClient>;
|
|
15
|
+
/** Reuse the inventory verifier supplied by offline setup without changing per-send scoped authorization. */
|
|
16
|
+
discover?: () => Promise<NativeCustodyInventory>;
|
|
17
|
+
readToken?: () => Promise<{
|
|
18
|
+
token: string;
|
|
19
|
+
token_generation: number;
|
|
20
|
+
}>;
|
|
21
|
+
env?: NodeJS.ProcessEnv;
|
|
22
|
+
now?: () => number;
|
|
23
|
+
}
|
|
24
|
+
export interface NativeVaultWatchOptions {
|
|
25
|
+
intervalMs: number;
|
|
26
|
+
onRefresh?: () => void | Promise<void>;
|
|
27
|
+
shouldRefresh?: () => boolean | Promise<boolean>;
|
|
28
|
+
setInterval?: typeof globalThis.setInterval;
|
|
29
|
+
clearInterval?: typeof globalThis.clearInterval;
|
|
30
|
+
}
|
|
31
|
+
export interface NativeVaultWatch {
|
|
32
|
+
readonly ready: Promise<void>;
|
|
33
|
+
close(): void;
|
|
34
|
+
}
|
|
35
|
+
/** Send classes that may replay once after a vault credential's 401, named in diagnostics. */
|
|
36
|
+
export type NativeScoped401Site = 'model' | 'model-relay' | 'cachekeep' | 'prime' | 'quota-profile';
|
|
37
|
+
export type NativeProfilePersistence = 'saved' | 'refused' | 'failed';
|
|
38
|
+
/** The profile fields a display may receive; never the legacy token fingerprint. */
|
|
39
|
+
export type NativeDisplayProfileMetadata = Pick<OAuthAccountProfile, 'tier' | 'orgType' | 'checkedAt' | 'accountIdentity' | 'providerAccountUuid'>;
|
|
40
|
+
/**
|
|
41
|
+
* A fetched account tier for immediate display. `profile` contains metadata
|
|
42
|
+
* only, never tokens or authorization receipts. `persisted` reports whether
|
|
43
|
+
* the write succeeded, was refused because credentials or lock ownership
|
|
44
|
+
* changed, or failed because storage was unavailable. It never rejects.
|
|
45
|
+
* Call isCurrent before displaying the tier, including after a storage failure.
|
|
46
|
+
*/
|
|
47
|
+
export interface NativeDisplayProfile {
|
|
48
|
+
profile: NativeDisplayProfileMetadata;
|
|
49
|
+
persisted: Promise<NativeProfilePersistence>;
|
|
50
|
+
/** Check the same account and token or vault record version, without fetching credentials. */
|
|
51
|
+
isCurrent(): Promise<boolean>;
|
|
52
|
+
}
|
|
53
|
+
/** Build a NativeDisplayProfile from a validated profile and its publication. */
|
|
54
|
+
export declare function nativeDisplayProfile(profile: OAuthAccountProfile, publish: () => Promise<boolean>, isCurrent: () => Promise<boolean>): NativeDisplayProfile;
|
|
55
|
+
export interface NativeVaultRuntime {
|
|
56
|
+
/** Subscribe to one discovery loop; notifications contain no credential material. */
|
|
57
|
+
watch(options: NativeVaultWatchOptions): NativeVaultWatch;
|
|
58
|
+
initializeSettings(): Promise<void>;
|
|
59
|
+
read(): Promise<NativeVaultRosterDocument | undefined>;
|
|
60
|
+
refresh(signal?: AbortSignal): Promise<NativeVaultRosterDocument | undefined>;
|
|
61
|
+
authorize(routeId: string, signal?: AbortSignal): Promise<NativeCustodyReceipt>;
|
|
62
|
+
reportFailure(receipt: NativeCustodyReceipt, status: number, source: NativeCustodyReporterSource): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* After a 401, acquire a fresh receipt for the same credential and account.
|
|
65
|
+
* Permit one replay only if its recordVersion exceeds the rejected receipt's
|
|
66
|
+
* version. The optional site is a diagnostic call-site label: model requests,
|
|
67
|
+
* quota, profile or cache warming. Logs contain versions, never credentials.
|
|
68
|
+
* The caller reports only the receipt rejected by its final HTTP attempt.
|
|
69
|
+
*/
|
|
70
|
+
prepareRetry(receipt: NativeCustodyReceipt, signal?: AbortSignal, site?: NativeScoped401Site): Promise<NativeCustodyRetry>;
|
|
71
|
+
publish(receipt: NativeCustodyReceipt, patch: NativeAccountMetadataPatch): Promise<boolean>;
|
|
72
|
+
fetchQuota(routeId: string, fetchImpl?: typeof fetch, signal?: AbortSignal, dispatch?: QuotaRequestDispatch): Promise<OAuthQuotaSnapshot>;
|
|
73
|
+
fetchProfile(routeId: string, fetchImpl?: typeof fetch, signal?: AbortSignal): Promise<OAuthAccountProfile>;
|
|
74
|
+
/** Return the fetched account profile without waiting for its metadata write. NativeDisplayProfile.persisted reports whether that asynchronous write succeeded, failed or was refused. */
|
|
75
|
+
fetchProfileForDisplay(routeId: string, fetchImpl?: typeof fetch, signal?: AbortSignal): Promise<NativeDisplayProfile>;
|
|
76
|
+
/**
|
|
77
|
+
* Accept or decline a vault route for the user. Resolves to whether the
|
|
78
|
+
* route's enabled flag changed, judged on the roster under its write lock.
|
|
79
|
+
*/
|
|
80
|
+
setEnabled(routeId: string, enabled: boolean): Promise<boolean>;
|
|
81
|
+
resetBackoff(receipt: NativeCustodyReceipt, kind?: 'refresh' | 'quota' | 'all'): Promise<boolean>;
|
|
82
|
+
getOrCreateAuthLineage(receipt: NativeCustodyReceipt): Promise<string | undefined>;
|
|
83
|
+
incrementPrimeUsage(receipt: NativeCustodyReceipt, delta?: PrimeUsageDelta): Promise<boolean>;
|
|
84
|
+
close(): void;
|
|
85
|
+
}
|
|
86
|
+
/** Publish the initial roster from validated account inventory. A caller importing captured state must fence that state through assertOwned, which runs again at the roster's actual publication. */
|
|
87
|
+
export declare function publishNativeVaultRosterSeed(paths: Pick<NativeVaultPaths, 'roster'>, input: NativeRosterSeedInput, options?: {
|
|
88
|
+
assertOwned?: () => Promise<void>;
|
|
89
|
+
}): Promise<NativeVaultRosterSeed>;
|
|
90
|
+
/** Match imported metadata to the held vault roster before publishing it. The caller's assertOwned fences its captured input; the roster lease separately prevents account replacement during the metadata write. */
|
|
91
|
+
export declare function publishNativeVaultRuntimeSeed(paths: Pick<NativeVaultPaths, 'roster' | 'runtime' | 'storageId'>, state: NativeRuntimeState, options?: {
|
|
92
|
+
assertOwned?: () => Promise<void>;
|
|
93
|
+
}): Promise<void>;
|
|
94
|
+
/** List accounts readable by this host's enrollment for offline setup. An inventory grants no bearer authority; every outbound request still needs a fresh scoped receipt. */
|
|
95
|
+
export declare function discoverNativeVaultInventory(options: NativeVaultRuntimeOptions, signal?: AbortSignal): Promise<NativeCustodyInventory>;
|
|
96
|
+
/** Retain the vault client's original per-attempt receipts and version provenance; access tokens never persist in roster or runtime metadata. */
|
|
97
|
+
export declare function createNativeVaultRuntime(options: NativeVaultRuntimeOptions): NativeVaultRuntime;
|
|
98
|
+
export declare function nativeVaultRuntimeKey(options: NativeVaultRuntimeOptions): string;
|
|
99
|
+
/** Each handle owns one reference; disposing it cannot close another host session. */
|
|
100
|
+
export declare function acquireNativeVaultRuntime(options: NativeVaultRuntimeOptions): NativeVaultRuntime;
|
|
101
|
+
/** Each account lease wraps the shared vault runtime and tracks its own subscriptions, so releasing the lease removes those subscriptions. */
|
|
102
|
+
export declare function leaseNativeVaultRuntime(use: () => NativeVaultRuntime, close: () => void): NativeVaultRuntime;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { NativeVaultRosterDocument } from './native-roster-seed.ts';
|
|
2
|
+
export interface NativeVaultRoutingSeed {
|
|
3
|
+
legacyConfig: string;
|
|
4
|
+
roster: string;
|
|
5
|
+
mainRouteId?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Missing or invalid legacy JSON skips the import rather than blocking vault requests. */
|
|
8
|
+
export declare function readNativeVaultLegacyJson(path: string): Promise<unknown>;
|
|
9
|
+
export declare function nativeVaultFileAbsent(path: string): Promise<boolean>;
|
|
10
|
+
/** Validate only preference fields, excluding credentials, account rows and stored account observations. */
|
|
11
|
+
export declare function readNativeVaultLegacySettings(path: string): Promise<Record<string, unknown>>;
|
|
12
|
+
/** Match public legacy IDs to verified vault UUIDs, never to labels, credential handles or row order. */
|
|
13
|
+
export declare function nativeVaultLegacyRoutes(source: unknown, roster: NativeVaultRosterDocument): Map<string, {
|
|
14
|
+
routeId: string;
|
|
15
|
+
accountIdentity: string;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { type NativeMigrationPreparedProof } from './native-migration-proof.ts';
|
|
2
|
+
import type { NativePoolPaths } from './pool-paths.ts';
|
|
3
|
+
declare const PHASES: readonly ['building', 'verified', 'activation-installed', 'committed', 'retired'];
|
|
4
|
+
export type NativeMigrationPhase = (typeof PHASES)[number];
|
|
5
|
+
export interface NativeMigrationSources {
|
|
6
|
+
config: string | null;
|
|
7
|
+
state: string | null;
|
|
8
|
+
/** SHA-256 of the host's anthropic entry with sorted JSON object keys; other providers are excluded. */
|
|
9
|
+
hostAuth: string;
|
|
10
|
+
routing: string | null;
|
|
11
|
+
}
|
|
12
|
+
export interface NativeMigrationRoutingPaths {
|
|
13
|
+
source: string;
|
|
14
|
+
destination: string;
|
|
15
|
+
}
|
|
16
|
+
export interface NativeMigrationInput {
|
|
17
|
+
host: 'opencode' | 'pi';
|
|
18
|
+
sources: NativeMigrationSources;
|
|
19
|
+
routingPaths: NativeMigrationRoutingPaths;
|
|
20
|
+
hostAuthPath: string;
|
|
21
|
+
/**
|
|
22
|
+
* Request vault custody during the first credential migration. The journal
|
|
23
|
+
* keeps native serving blocked until the separate vault activation commits.
|
|
24
|
+
*/
|
|
25
|
+
activation?: 'requested';
|
|
26
|
+
}
|
|
27
|
+
export interface NativeMigrationExpectations {
|
|
28
|
+
expectedHostAuth: string;
|
|
29
|
+
expectedRouting: string | null;
|
|
30
|
+
preparedProof: NativeMigrationPreparedProof;
|
|
31
|
+
}
|
|
32
|
+
/** Public account metadata recorded for the planned switch to vault custody. */
|
|
33
|
+
export interface NativeCustodyActivationRosterRow {
|
|
34
|
+
routeId: string;
|
|
35
|
+
credentialId: string;
|
|
36
|
+
credentialType: 'oauth';
|
|
37
|
+
accountIdentity: string;
|
|
38
|
+
state: string;
|
|
39
|
+
label: string;
|
|
40
|
+
enabled: boolean;
|
|
41
|
+
addedAt: number;
|
|
42
|
+
}
|
|
43
|
+
/** The validated vault account list that activation publishes or reuses unchanged. */
|
|
44
|
+
export interface NativeCustodyActivationRoster {
|
|
45
|
+
version: 1;
|
|
46
|
+
view: string;
|
|
47
|
+
complete: true;
|
|
48
|
+
rows: NativeCustodyActivationRosterRow[];
|
|
49
|
+
declined: {
|
|
50
|
+
credentialId: string;
|
|
51
|
+
accountIdentity?: string;
|
|
52
|
+
}[];
|
|
53
|
+
}
|
|
54
|
+
export type NativeCustodyActivationPhase = 'prepared' | 'published' | 'committed';
|
|
55
|
+
/**
|
|
56
|
+
* The offline switch of a migrated pool from local to vault custody. Every
|
|
57
|
+
* field is fixed when the activation is prepared, so a resumed run checks the
|
|
58
|
+
* files against these values and never against what it finds on disk later.
|
|
59
|
+
* Holds no credential: only public descriptor digests and vault ids.
|
|
60
|
+
*/
|
|
61
|
+
export interface NativeCustodyActivationPlan {
|
|
62
|
+
kind: 'activation';
|
|
63
|
+
phase: NativeCustodyActivationPhase;
|
|
64
|
+
/** The vault's designated primary login, bound to the pool's main route. */
|
|
65
|
+
primary: {
|
|
66
|
+
routeId: string;
|
|
67
|
+
credentialId: string;
|
|
68
|
+
accountIdentity: string;
|
|
69
|
+
};
|
|
70
|
+
roster: NativeCustodyActivationRoster;
|
|
71
|
+
/**
|
|
72
|
+
* Every credential row captured before this custody switch, including local
|
|
73
|
+
* OAuth and API-key accounts, with a digest of the imported runtime state.
|
|
74
|
+
*/
|
|
75
|
+
localProof: NativeMigrationPreparedProof;
|
|
76
|
+
/**
|
|
77
|
+
* IDs of local OAuth credential rows to remove. Keep every other row
|
|
78
|
+
* recorded in localProof.
|
|
79
|
+
*/
|
|
80
|
+
removeIds: string[];
|
|
81
|
+
/** Digests of the canonical pool settings before and after the mode switch. */
|
|
82
|
+
settings: {
|
|
83
|
+
source: string;
|
|
84
|
+
target: string;
|
|
85
|
+
};
|
|
86
|
+
/** Digests of the canonical native runtime state before and after rebinding. */
|
|
87
|
+
runtime: {
|
|
88
|
+
source: string;
|
|
89
|
+
target: string;
|
|
90
|
+
};
|
|
91
|
+
/** Anthropic host-auth entry digests (or 'absent') before and after activation. */
|
|
92
|
+
hostAuth: {
|
|
93
|
+
source: string;
|
|
94
|
+
expected: string;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export type NativeCustodyActivation = {
|
|
98
|
+
kind: 'requested';
|
|
99
|
+
} | NativeCustodyActivationPlan;
|
|
100
|
+
export interface NativeMigrationJournal {
|
|
101
|
+
version: 4;
|
|
102
|
+
storageId: string;
|
|
103
|
+
host: 'opencode' | 'pi';
|
|
104
|
+
phase: NativeMigrationPhase;
|
|
105
|
+
sources: NativeMigrationSources;
|
|
106
|
+
routingPaths: NativeMigrationRoutingPaths;
|
|
107
|
+
hostAuthPath: string;
|
|
108
|
+
expectedHostAuth: string;
|
|
109
|
+
expectedRouting: string | null;
|
|
110
|
+
preparedProof: NativeMigrationPreparedProof | null;
|
|
111
|
+
/**
|
|
112
|
+
* Null unless the offline setup command requested or began switching
|
|
113
|
+
* credential authority to Claustrum.
|
|
114
|
+
*/
|
|
115
|
+
activation: NativeCustodyActivation | null;
|
|
116
|
+
}
|
|
117
|
+
export declare class NativeAuthorityError extends Error {
|
|
118
|
+
readonly code: 'migration-required' | 'migration-incomplete' | 'invalid-journal' | 'journal-conflict';
|
|
119
|
+
constructor(code: 'migration-required' | 'migration-incomplete' | 'invalid-journal' | 'journal-conflict');
|
|
120
|
+
}
|
|
121
|
+
export declare function readNativeMigrationJournal(paths: NativePoolPaths): Promise<NativeMigrationJournal | undefined>;
|
|
122
|
+
/**
|
|
123
|
+
* The migration phase that authorizes serving, or undefined while the
|
|
124
|
+
* migration or a requested switch to vault custody is unfinished. Every reader
|
|
125
|
+
* that admits requests from the journal uses this one predicate.
|
|
126
|
+
*/
|
|
127
|
+
export declare function nativeMigrationAuthorityPhase(journal: NativeMigrationJournal | undefined): 'committed' | 'retired' | undefined;
|
|
128
|
+
/** An empty or readable store is not proof that the offline authority flip completed. */
|
|
129
|
+
export declare function requireNativePoolAuthority(paths: NativePoolPaths): Promise<void>;
|
|
130
|
+
interface JournalHooks {
|
|
131
|
+
/** Outer controller and pool leases remain held through the atomic journal rename. */
|
|
132
|
+
assertOwned?: () => Promise<void>;
|
|
133
|
+
lockOptions?: {
|
|
134
|
+
ttlMs: number;
|
|
135
|
+
timeoutMs: number;
|
|
136
|
+
};
|
|
137
|
+
onWriteStep?: (step: 'before-write' | 'after-write', journal: NativeMigrationJournal) => Promise<void>;
|
|
138
|
+
}
|
|
139
|
+
/** 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>;
|
|
141
|
+
/** 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>;
|
|
143
|
+
/**
|
|
144
|
+
* Advance one phase at a time. A retry of the same transition returns the journal.
|
|
145
|
+
* Before recording activation, the caller must compare the host's Anthropic auth
|
|
146
|
+
* entry and routing file with the saved expected values. This journal records the
|
|
147
|
+
* migration stage; it does not read or verify those files.
|
|
148
|
+
*/
|
|
149
|
+
export declare function advanceNativeMigration(paths: NativePoolPaths, expected: NativeMigrationPhase, next: NativeMigrationPhase, hooks?: JournalHooks): Promise<NativeMigrationJournal>;
|
|
150
|
+
/**
|
|
151
|
+
* Record the prepared switch to vault custody on a retired migration. From
|
|
152
|
+
* this write until the activation commits, the pool authorizes no serving.
|
|
153
|
+
* Retrying with the identical plan returns the journal; any other plan is a
|
|
154
|
+
* conflict, so a resumed setup can never replace what it recorded.
|
|
155
|
+
*/
|
|
156
|
+
export declare function recordNativeCustodyActivation(paths: NativePoolPaths, plan: NativeCustodyActivationPlan, hooks?: JournalHooks): Promise<NativeMigrationJournal>;
|
|
157
|
+
/** 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>;
|
|
159
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { NativePoolPaths } from './pool-paths.ts';
|
|
2
|
+
export interface NativeLocalPoolBinding {
|
|
3
|
+
readonly kind: 'local';
|
|
4
|
+
readonly storageId: string;
|
|
5
|
+
readonly rowId: string;
|
|
6
|
+
readonly credentialEpoch: number;
|
|
7
|
+
readonly identity?: string;
|
|
8
|
+
}
|
|
9
|
+
interface BindingSourceRow {
|
|
10
|
+
id: string;
|
|
11
|
+
identity?: string;
|
|
12
|
+
credentialEpoch?: number;
|
|
13
|
+
candidate: boolean;
|
|
14
|
+
stamp?: string;
|
|
15
|
+
invalid?: string;
|
|
16
|
+
torn?: boolean;
|
|
17
|
+
unbound?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare class NativePoolBindingError extends Error {
|
|
20
|
+
constructor();
|
|
21
|
+
}
|
|
22
|
+
export declare function isNativeLocalPoolBinding(value: unknown): value is NativeLocalPoolBinding;
|
|
23
|
+
/** Capture the selected row before asynchronous work, never the newest primary afterward. */
|
|
24
|
+
export declare function captureNativeLocalPoolBinding(paths: NativePoolPaths, row: BindingSourceRow): NativeLocalPoolBinding;
|
|
25
|
+
/**
|
|
26
|
+
* A response still belongs to an account disabled after dispatch. Matching
|
|
27
|
+
* this snapshot does not make that account eligible for a new request.
|
|
28
|
+
*/
|
|
29
|
+
export declare function nativeLocalPoolBindingMatches(binding: NativeLocalPoolBinding, paths: NativePoolPaths, row: BindingSourceRow): boolean;
|
|
30
|
+
/** Unknown row ids and proven account identities occupy different refresh namespaces. */
|
|
31
|
+
export declare function nativeLocalRefreshJobKey(binding: NativeLocalPoolBinding): string;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface NativePoolPaths {
|
|
2
|
+
legacyConfig: string;
|
|
3
|
+
legacyState: string;
|
|
4
|
+
config: string;
|
|
5
|
+
state: string;
|
|
6
|
+
runtime: string;
|
|
7
|
+
journal: string;
|
|
8
|
+
roster: string;
|
|
9
|
+
storageId: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Resolve existing parent aliases and nonexistent leaves without creating files.
|
|
13
|
+
* This can follow a leaf symlink, so it does not establish configured-leaf safety.
|
|
14
|
+
* Source capture and recheck must retain the configured path for the lstat guard.
|
|
15
|
+
*/
|
|
16
|
+
export declare function canonicalPath(path: string): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Separate runtime authority from import inputs so a stale legacy writer cannot
|
|
19
|
+
* rewrite a stamped credential. Both independently configured paths matter.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveNativePoolPaths(legacyConfig?: string, legacyState?: string): Promise<NativePoolPaths>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type OpenPoolStoreOptions } from "./internal-types/store/index.js";
|
|
2
|
+
import { type NativeLockEvent } from './native-lock-observer.ts';
|
|
3
|
+
import type { NativePoolPaths } from './pool-paths.ts';
|
|
4
|
+
export type { NativeLockEvent } from './native-lock-observer.ts';
|
|
5
|
+
interface NativeQuotaCodec {
|
|
6
|
+
validate(value: unknown): boolean;
|
|
7
|
+
merge(stored: unknown | undefined, observation: unknown): unknown;
|
|
8
|
+
}
|
|
9
|
+
export type NativePoolStorePaths = Pick<NativePoolPaths, 'config' | 'state'> & {
|
|
10
|
+
legacySeedConfig?: string;
|
|
11
|
+
};
|
|
12
|
+
export interface NativePoolStoreOptions extends Pick<OpenPoolStoreOptions, 'now' | 'onStep' | 'hold' | 'logger' | 'onLockStep'> {
|
|
13
|
+
paths: NativePoolStorePaths;
|
|
14
|
+
quota: NativeQuotaCodec;
|
|
15
|
+
onLockEvent?: (event: NativeLockEvent) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* These config/state locks also fence local account metadata against concurrent
|
|
19
|
+
* credential changes. Legacy sidecar writers use different files and locks.
|
|
20
|
+
*/
|
|
21
|
+
export declare function nativePoolStoreLocks(paths: NativePoolStorePaths): readonly [{
|
|
22
|
+
readonly path: string;
|
|
23
|
+
readonly name: 'pool-config';
|
|
24
|
+
}, {
|
|
25
|
+
readonly path: string;
|
|
26
|
+
readonly name: 'pool-state';
|
|
27
|
+
}];
|
|
28
|
+
/**
|
|
29
|
+
* Storage machinery only. Callers must separately establish local migration
|
|
30
|
+
* authority or vault enrollment authority before using these files.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createNativePoolStore(options: NativePoolStoreOptions): import("./internal-types/store/index.js").PoolStore;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
export interface ProviderErrorRedactor {
|
|
2
|
+
/** Scrub credentials from error text. */
|
|
3
|
+
redactText(text: string): string;
|
|
4
|
+
/**
|
|
5
|
+
* Scrub credentials from any thrown value without running caller code.
|
|
6
|
+
* Strings come back scrubbed and other primitives unchanged. Objects come
|
|
7
|
+
* back as a fresh projection that keeps only the fields hosts classify on
|
|
8
|
+
* (name, message, status, code, type, retry hints, headers, the nested
|
|
9
|
+
* `error` envelope, `cause` and aggregate `errors`), each read as own data
|
|
10
|
+
* and scrubbed. The original object, its prototype, getters, private state
|
|
11
|
+
* and any response body, stream or URL are never returned. Never throws.
|
|
12
|
+
*/
|
|
13
|
+
redactError(error: unknown): unknown;
|
|
14
|
+
/**
|
|
15
|
+
* Scrub a provider response. Successful non-stream responses are returned
|
|
16
|
+
* as-is. Successful event streams keep every successful frame byte-for-byte
|
|
17
|
+
* and rewrite only error envelopes. Non-2xx responses get scrubbed status
|
|
18
|
+
* text, headers, URL and body; the body is read lazily when the caller
|
|
19
|
+
* reads it. After disposal a non-2xx response keeps only its status and
|
|
20
|
+
* verifiable retry/rate-limit headers.
|
|
21
|
+
*/
|
|
22
|
+
redactResponse(response: Response): Response;
|
|
23
|
+
/** Forget the credentials. Later error reads fail closed to a generic message. */
|
|
24
|
+
dispose(): void;
|
|
25
|
+
}
|
|
26
|
+
/** Replacement for every scrubbed credential. */
|
|
27
|
+
export declare const PROVIDER_ERROR_REDACTION = "[REDACTED]";
|
|
28
|
+
/** Message used when error material is read after the redactor was disposed. */
|
|
29
|
+
export declare const PROVIDER_ERROR_WITHHELD_MESSAGE = "Provider error details were withheld because the request attempt has ended";
|
|
30
|
+
/** Message used when a non-2xx body is too large to scrub safely. */
|
|
31
|
+
export declare const PROVIDER_ERROR_OVERSIZED_MESSAGE = "Provider error body exceeded the redaction size limit and was withheld";
|
|
32
|
+
/** Largest non-2xx body read into memory for scrubbing. */
|
|
33
|
+
export declare const PROVIDER_ERROR_MAX_BODY_BYTES: number;
|
|
34
|
+
/** Largest SSE frame carried while looking for its end. */
|
|
35
|
+
export declare const PROVIDER_ERROR_MAX_FRAME_BYTES: number;
|
|
36
|
+
/**
|
|
37
|
+
* For producers of a non-2xx body, such as the relay, that stop buffering it
|
|
38
|
+
* at PROVIDER_ERROR_MAX_BODY_BYTES: error the raw body stream with a new
|
|
39
|
+
* instance, and the body handed out by `redactResponse` ends with the fixed
|
|
40
|
+
* PROVIDER_ERROR_OVERSIZED_MESSAGE JSON instead of an error, also when the
|
|
41
|
+
* redactor or scope was already disposed. Bytes the source had queued are
|
|
42
|
+
* dropped. Only objects this constructor created count: membership is
|
|
43
|
+
* looked up by identity in a private set, so nothing on the value (its
|
|
44
|
+
* message, code, prototype or any getter) is read, and a look-alike, a
|
|
45
|
+
* proxy around an instance or an object with the same prototype is treated
|
|
46
|
+
* as an ordinary failure. Not exported from the Core package entry point.
|
|
47
|
+
*/
|
|
48
|
+
export declare class ProviderErrorSourceOversizedError extends Error {
|
|
49
|
+
constructor();
|
|
50
|
+
}
|
|
51
|
+
/** Message of the error thrown when a closed stream scope is fed again. */
|
|
52
|
+
export declare const PROVIDER_ERROR_SCOPE_CLOSED_MESSAGE = "Provider error stream scope is closed";
|
|
53
|
+
/**
|
|
54
|
+
* Internal scope for a producer that already holds the raw event-stream
|
|
55
|
+
* bytes of one physical attempt (the relay): it feeds them through the same
|
|
56
|
+
* pipeline as `redactResponse` without wrapping a Response.
|
|
57
|
+
*/
|
|
58
|
+
export interface ProviderErrorStreamScope {
|
|
59
|
+
/**
|
|
60
|
+
* Bytes to forward for this chunk. Unchanged frames come back as the same
|
|
61
|
+
* bytes; only error envelopes are rewritten; an incomplete frame is held
|
|
62
|
+
* until its blank line. A frame over the bound throws
|
|
63
|
+
* `SseFrameTooLargeError`, and any failure disposes the scope.
|
|
64
|
+
*/
|
|
65
|
+
push(chunk: Uint8Array): Uint8Array[];
|
|
66
|
+
/** End of input: bytes for the unterminated tail, then the scope disposes. */
|
|
67
|
+
finish(): Uint8Array[];
|
|
68
|
+
/** Scrub a thrown error; generic once the scope is disposed. */
|
|
69
|
+
redactError(error: unknown): unknown;
|
|
70
|
+
/** Drop the credentials and any held partial frame. Idempotent. */
|
|
71
|
+
dispose(): void;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Create a stream scope for one physical attempt or reconnect, holding the
|
|
75
|
+
* exact credentials that attempt sent. Create a fresh scope after every
|
|
76
|
+
* fresh authorization. After `finish()` or `dispose()`, `push` and `finish`
|
|
77
|
+
* throw an error carrying no content and `redactError` fails closed.
|
|
78
|
+
*/
|
|
79
|
+
export declare function createProviderErrorStreamScope(secrets: readonly string[]): ProviderErrorStreamScope;
|
|
80
|
+
/**
|
|
81
|
+
* Create a redactor for one request attempt. `secrets` are the exact
|
|
82
|
+
* credentials that attempt sent; pass a new redactor for every attempt so a
|
|
83
|
+
* rotated or fallback credential is scrubbed by the attempt that used it, and
|
|
84
|
+
* call `dispose()` when the attempt ends.
|
|
85
|
+
*/
|
|
86
|
+
export declare function createProviderErrorRedactor(secrets: readonly string[]): ProviderErrorRedactor;
|
|
87
|
+
/**
|
|
88
|
+
* What the request asked for, which decides how a successful body is
|
|
89
|
+
* treated: `event-stream` for streaming model requests (the body always goes
|
|
90
|
+
* through the error-only SSE rewrite, whatever content type the response
|
|
91
|
+
* claims), `http` for every other request (successful bodies are returned
|
|
92
|
+
* untouched and never read).
|
|
93
|
+
*/
|
|
94
|
+
export type ProviderResponseMode = 'event-stream' | 'http';
|
|
95
|
+
/** How a response scope retired its credentials. */
|
|
96
|
+
export type ProviderResponseSettlement = 'eof' | 'cancel' | 'error' | 'untouched' | 'disposed';
|
|
97
|
+
/**
|
|
98
|
+
* Lifetime of one direct provider response. The credentials are retired at
|
|
99
|
+
* the response's terminal point rather than when the host remembers to
|
|
100
|
+
* dispose.
|
|
101
|
+
*/
|
|
102
|
+
export interface ProviderErrorResponseScope {
|
|
103
|
+
/**
|
|
104
|
+
* Scrub exactly one response. In `http` mode a successful response is
|
|
105
|
+
* returned as-is without reading its body; in `event-stream` mode a
|
|
106
|
+
* successful body is wrapped so only error envelopes are rewritten,
|
|
107
|
+
* whatever its content type. In both modes a non-2xx response gets
|
|
108
|
+
* scrubbed status text, headers, URL and a lazily scrubbed body. A second
|
|
109
|
+
* call, or any call after the scope has settled, throws a TypeError.
|
|
110
|
+
*/
|
|
111
|
+
redactResponse(response: Response): Response;
|
|
112
|
+
/** Scrub a thrown error while live; generic once the scope has settled. */
|
|
113
|
+
redactError(error: unknown): unknown;
|
|
114
|
+
/** Retire the credentials now. Idempotent. */
|
|
115
|
+
dispose(): void;
|
|
116
|
+
/**
|
|
117
|
+
* Resolves once, at the first terminal point, and never rejects:
|
|
118
|
+
* - `eof`, `cancel` or `error` when a wrapped body (a successful event
|
|
119
|
+
* stream or a non-2xx body) ends, is cancelled by its consumer, or fails;
|
|
120
|
+
* - `untouched` when `redactResponse` returned without wrapping a body,
|
|
121
|
+
* such as a successful non-event-stream response, whose body is never
|
|
122
|
+
* read;
|
|
123
|
+
* - `disposed` when `dispose()` came first.
|
|
124
|
+
* It marks the credentials' retirement, not completed I/O cleanup: a
|
|
125
|
+
* source cancellation may still be pending.
|
|
126
|
+
*/
|
|
127
|
+
readonly settled: Promise<ProviderResponseSettlement>;
|
|
128
|
+
}
|
|
129
|
+
/** Message of the TypeError thrown when a response scope is reused. */
|
|
130
|
+
export declare const PROVIDER_ERROR_RESPONSE_SCOPE_USED_MESSAGE = "Provider error response scope accepts one response while live";
|
|
131
|
+
/**
|
|
132
|
+
* Create a response scope for one physical attempt, holding the exact
|
|
133
|
+
* credentials that attempt sent, and the mode of the request that attempt
|
|
134
|
+
* made. Host code that classifies the outcome after
|
|
135
|
+
* the scope settles (retry, rerouting or quota decisions) must use the
|
|
136
|
+
* status, headers and already-scrubbed frames it read during the attempt:
|
|
137
|
+
* once settled, `redactError` only returns a generic error.
|
|
138
|
+
*/
|
|
139
|
+
export declare function createProviderErrorResponseScope(secrets: readonly string[], mode: ProviderResponseMode): ProviderErrorResponseScope;
|