@cortexkit/anthropic-auth-core 2.11.2 → 2.11.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.
- package/dist/accounts.d.ts +30 -16
- package/dist/cachekeep.d.ts +8 -5
- package/dist/index.d.ts +17 -1
- package/dist/index.js +6180 -1938
- package/dist/internal-types/claustrum/custody.d.ts +4 -0
- package/dist/internal-types/claustrum/index.d.ts +1 -1
- package/dist/internal-types/routing-accessor/index.d.ts +34 -9
- package/dist/internal-types/settings/define.d.ts +35 -0
- package/dist/internal-types/settings/descriptors.d.ts +97 -0
- package/dist/internal-types/settings/edit.d.ts +24 -0
- package/dist/internal-types/settings/handle.d.ts +30 -0
- package/dist/internal-types/settings/index.d.ts +10 -0
- package/dist/internal-types/settings/move.d.ts +76 -0
- package/dist/internal-types/settings/parse.d.ts +24 -0
- package/dist/internal-types/settings/paths.d.ts +12 -0
- package/dist/internal-types/settings/refusal.d.ts +7 -0
- package/dist/internal-types/settings/resolve.d.ts +15 -0
- package/dist/internal-types/settings/schema.d.ts +29 -0
- package/dist/internal-types/settings/snapshot.d.ts +24 -0
- package/dist/native-account-runtime.d.ts +22 -8
- package/dist/native-runtime-settings.d.ts +41 -0
- package/dist/native-settings-write.d.ts +19 -0
- package/dist/path-options.d.ts +16 -0
- package/dist/pool-paths.d.ts +2 -1
- package/dist/routing-relay.d.ts +6 -1
- package/dist/routing-wait.d.ts +14 -0
- package/dist/routing.d.ts +2 -2
- package/dist/settings-definition.d.ts +621 -0
- package/dist/settings-mode.d.ts +22 -0
- package/dist/settings-move-fence.d.ts +44 -0
- package/dist/settings-move-map.d.ts +7 -0
- package/dist/settings-move-run.d.ts +29 -0
- package/dist/settings-move-source.d.ts +50 -0
- package/dist/settings-move-sources.d.ts +35 -0
- package/dist/settings-paths.d.ts +30 -0
- package/dist/settings-protection-copy.d.ts +12 -0
- package/dist/settings-protection-legacy.d.ts +22 -0
- package/dist/settings-record.d.ts +8 -0
- package/dist/settings-service.d.ts +99 -0
- package/dist/settings-three-way.d.ts +5 -0
- package/dist/sticky-routing.d.ts +14 -0
- package/package.json +3 -2
- package/schema/anthropic-auth.schema.json +1081 -0
|
@@ -247,6 +247,10 @@ export declare function decideScopedRetryAfter401(site: string, served: Claustru
|
|
|
247
247
|
export declare const SERVING_MARGIN_MS = 300000;
|
|
248
248
|
/** A kept receipt needs a minute of headroom, not the vault's refresh demand. */
|
|
249
249
|
export declare const KEPT_RECEIPT_MARGIN_MS = 60000;
|
|
250
|
+
/** Maximum request-path wait for a vault read without a usable kept receipt. */
|
|
251
|
+
export declare const VAULT_RECEIPT_WAIT_MS = 10000;
|
|
252
|
+
/** Only the first minute of each observed outage earns a request-path wait. */
|
|
253
|
+
export declare const VAULT_YOUNG_OUTAGE_MS = 60000;
|
|
250
254
|
/**
|
|
251
255
|
* Reads this consumer's vault credentials (list, fetch, 401 report), with the
|
|
252
256
|
* enrollment token or the host's grant as authorization. Used by every host of a
|
|
@@ -3,7 +3,7 @@ import type { ClaustrumScopedClient } from './custody.js';
|
|
|
3
3
|
export { ClaustrumCredentialError, type ClaustrumReporterSource, type EnrollmentTokenFile, } from '@cortexkit/claustrum-client';
|
|
4
4
|
export { ClaustrumUnreachableError, classifyVaultFailure, VAULT_FAILURE_CLASSES, type VaultFailureClass, } from './availability.js';
|
|
5
5
|
export { ClaustrumConsumer, type ClaustrumConsumerOptions, type ClaustrumWatchState, DEFAULT_CONNECT_TIMEOUT_MS, type SendOptions, } from './consumer.js';
|
|
6
|
-
export { type AccountIdentitySource, type ClassifyingClaustrumFamily, type ClaustrumFamily, type ClaustrumFamilyInput, type ClaustrumRosterWatch, type ClaustrumRosterWatchOptions, type ClaustrumScopedAttempt, type ClaustrumScopedClient, ClaustrumScopedCustody, type ClaustrumScopedIdentity, decideScopedRetryAfter401, type IdentityParser, isScopedCredentialRotation, KEPT_RECEIPT_MARGIN_MS, type KeptReceiptState, type ScopedRetryReason, SERVING_MARGIN_MS, type SkippedVaultReason, type SkippedVaultRecord, type VaultCredential, type VaultCredentialType, type VaultGrantReach, type VaultGrantTuple, type VaultInventory, type VaultRowFacts, } from './custody.js';
|
|
6
|
+
export { type AccountIdentitySource, type ClassifyingClaustrumFamily, type ClaustrumFamily, type ClaustrumFamilyInput, type ClaustrumRosterWatch, type ClaustrumRosterWatchOptions, type ClaustrumScopedAttempt, type ClaustrumScopedClient, ClaustrumScopedCustody, type ClaustrumScopedIdentity, decideScopedRetryAfter401, type IdentityParser, isScopedCredentialRotation, KEPT_RECEIPT_MARGIN_MS, type KeptReceiptState, type ScopedRetryReason, SERVING_MARGIN_MS, type SkippedVaultReason, type SkippedVaultRecord, VAULT_RECEIPT_WAIT_MS, VAULT_YOUNG_OUTAGE_MS, type VaultCredential, type VaultCredentialType, type VaultGrantReach, type VaultGrantTuple, type VaultInventory, type VaultRowFacts, } from './custody.js';
|
|
7
7
|
export { type ClaustrumEnrollmentClient, type ClaustrumEnrollmentConnection, type ClaustrumEnrollmentDisconnectResult, ClaustrumEnrollmentManager, type ClaustrumEnrollmentPaths, type ClaustrumEnrollmentResetResult, type ClaustrumEnrollmentStatus, type ClaustrumRequestedGrant, classifyEnrollmentError, connectClaustrumEnrollmentClient, disconnectClaustrumEnrollment, type EnrollmentDisposition, enrollmentAuthority, enrollmentName, getClaustrumEnrollmentPaths, hostEnrollmentPaths, RETRYABLE_ENROLLMENT_CODES, readClaustrumEnrollmentStatus, readClaustrumEnrollmentToken, resetClaustrumEnrollmentState, TERMINAL_ENROLLMENT_CODES, validEnrollmentDisplayName, validEnrollmentRequestedGrants, vaultAuthority, } from './enrollment.js';
|
|
8
8
|
export { ClaustrumConsumerError, type ClaustrumConsumerFailureKind, type ClaustrumLogger, } from './errors.js';
|
|
9
9
|
export { connectVaultHost, hasVaultHost, VAULT_HOST_CONNECT_REFUSAL, VAULT_HOST_STATUS, } from './host.js';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Optional THALAMUS routing for vault mode and advisory turn
|
|
3
|
-
* shaping. Account ids are vault account ids, not local pool
|
|
4
|
-
* persisted here; plugins on routes the runner does not serve
|
|
2
|
+
* Optional THALAMUS routing for vault mode, plugin wait reports and advisory turn
|
|
3
|
+
* notes for request shaping. Account ids are vault account ids, not local pool
|
|
4
|
+
* rows. Nothing is persisted here; plugins on routes the runner does not serve
|
|
5
|
+
* get no turn notes.
|
|
5
6
|
*/
|
|
6
7
|
import { type CacheWarmStopReason } from './cache-policy.js';
|
|
7
8
|
export type { CacheTouchInput, CacheWarmStoppedInput, CacheWarmStopReason, SessionCacheHours, SessionCachePolicy, SessionCacheTtl, SessionKeepWarmMode, SessionToolWait, } from './cache-policy.js';
|
|
@@ -30,6 +31,8 @@ export interface AskRoutingInput<Candidate extends RoutingCandidate = RoutingCan
|
|
|
30
31
|
* routing's default cap in force.
|
|
31
32
|
*/
|
|
32
33
|
holdWaitMaxS?: number;
|
|
34
|
+
/** Plugin sticky choice's vault credential id; an eligible-account hint, not a pin. */
|
|
35
|
+
warmCredentialId?: string;
|
|
33
36
|
}
|
|
34
37
|
export interface RoutingHold {
|
|
35
38
|
/** Uncapped advice from routing. The plugin must apply its own hold cap. */
|
|
@@ -66,6 +69,9 @@ export interface BillingUsage {
|
|
|
66
69
|
reasoning?: number;
|
|
67
70
|
reasoningIncludedInOutput?: boolean;
|
|
68
71
|
}
|
|
72
|
+
/** Keep this closed list aligned with the routing contract when adding a reason. */
|
|
73
|
+
export declare const PLUGIN_WAIT_REASONS: readonly ['account_limit', 'account_free', 'rate_limited', 'server_busy', 'quota_reading', 'routing_hold'];
|
|
74
|
+
export type PluginWaitReason = (typeof PLUGIN_WAIT_REASONS)[number];
|
|
69
75
|
export type ReportRoutingInput = (RoutingReportIdentity & ({
|
|
70
76
|
outcome: 'served';
|
|
71
77
|
/**
|
|
@@ -114,6 +120,18 @@ export type ReportRoutingInput = (RoutingReportIdentity & ({
|
|
|
114
120
|
kind: 'turn_note_skipped';
|
|
115
121
|
after_tool_use_id: string;
|
|
116
122
|
reason: 'anchor_missing' | 'before_user_message' | 'unsupported_model' | 'not_oauth';
|
|
123
|
+
} | {
|
|
124
|
+
sessionId: string;
|
|
125
|
+
kind: 'wait';
|
|
126
|
+
phase: 'start' | 'end';
|
|
127
|
+
waitId: string;
|
|
128
|
+
reason: PluginWaitReason;
|
|
129
|
+
/** Absolute epoch-millisecond time of the next attempt. */
|
|
130
|
+
nextMs?: number;
|
|
131
|
+
attempt?: number;
|
|
132
|
+
/** Fixed plugin text, never provider text, an account label or an id. */
|
|
133
|
+
message?: string;
|
|
134
|
+
outcome?: 'resumed' | 'cancelled' | 'abandoned';
|
|
117
135
|
} | {
|
|
118
136
|
sessionId: string;
|
|
119
137
|
kind: 'billing';
|
|
@@ -156,14 +174,21 @@ export declare function turnNotes(sessionId: string): readonly {
|
|
|
156
174
|
/**
|
|
157
175
|
* Ask routing for an eligible vault route. Any failure or unfamiliar answer
|
|
158
176
|
* yields undefined so the plugin can keep its own choice. Opted-in routing
|
|
159
|
-
* refusals instead stop the request. This does not admit routes
|
|
160
|
-
*
|
|
177
|
+
* refusals instead stop the request. This does not admit routes. Callers never
|
|
178
|
+
* pass an account the vault refused. A plugin may also leave out accounts its
|
|
179
|
+
* user's own eligibility rules exclude, such as a per-model account list. Each
|
|
180
|
+
* plugin decides whether its quota floors (a minimum share of a quota window
|
|
181
|
+
* an account must keep) also filter candidates; routing keeps its own reserve
|
|
182
|
+
* of each window.
|
|
183
|
+
* Routing's pick among the candidates is final. Don't reject it under a local
|
|
184
|
+
* floor, and don't add floors of the plugin's own that duplicate routing's
|
|
185
|
+
* reserves.
|
|
161
186
|
*/
|
|
162
187
|
export declare function askRouting<Candidate extends RoutingCandidate, Refusals extends boolean = false>(input: AskRoutingInput<Candidate, Refusals>): Promise<RoutingSelection<Candidate> | (Refusals extends true ? RoutingRefusal : never) | undefined>;
|
|
163
188
|
/**
|
|
164
|
-
* Report a vault request, billing result or turn-note event without
|
|
165
|
-
* routing. Only contract fields are sent, and all accessor failures
|
|
166
|
-
* Headers must already be limited to rate-limit headers by the
|
|
167
|
-
* are not filtered or redacted here.
|
|
189
|
+
* Report a vault request, billing result, plugin wait or turn-note event without
|
|
190
|
+
* waiting for routing. Only contract fields are sent, and all accessor failures
|
|
191
|
+
* are ignored. Headers must already be limited to rate-limit headers by the
|
|
192
|
+
* caller; values are not filtered or redacted here.
|
|
168
193
|
*/
|
|
169
194
|
export declare function reportRouting(input: ReportRoutingInput): void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type ValueDescriptor, type ValueOf, type ValueValidationOptions } from './descriptors.js';
|
|
2
|
+
export interface SettingDeclaration<D extends ValueDescriptor = ValueDescriptor> {
|
|
3
|
+
readonly value: D;
|
|
4
|
+
readonly default: ValueDescriptor extends D ? unknown : ValueOf<D>;
|
|
5
|
+
readonly hosts: 'both' | 'opencode' | 'pi' | string;
|
|
6
|
+
readonly overrides?: {
|
|
7
|
+
readonly host?: true;
|
|
8
|
+
readonly model?: true;
|
|
9
|
+
};
|
|
10
|
+
readonly project?: 'user-only' | 'allowed';
|
|
11
|
+
readonly legacy?: readonly {
|
|
12
|
+
readonly source: string;
|
|
13
|
+
readonly path: readonly string[];
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
type Declarations = Readonly<Record<string, SettingDeclaration>>;
|
|
17
|
+
export interface SettingsDefinition<S extends Declarations = Declarations> {
|
|
18
|
+
readonly plugin: string;
|
|
19
|
+
readonly settings: {
|
|
20
|
+
readonly [K in keyof S]: S[K] & {
|
|
21
|
+
readonly project: S[K] extends {
|
|
22
|
+
readonly project: infer P;
|
|
23
|
+
} ? P : 'project' extends keyof S[K] ? Exclude<S[K]['project'], undefined> | 'user-only' : 'user-only';
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export declare function defineSettings<const S extends Declarations>(definition: {
|
|
28
|
+
readonly plugin: string;
|
|
29
|
+
readonly settings: S;
|
|
30
|
+
}): SettingsDefinition<S>;
|
|
31
|
+
/** Internal helper: host names are reserved and never count as model ids. */
|
|
32
|
+
export declare function isOverrideKeyAllowed(overrides: NonNullable<SettingDeclaration['overrides']>, key: string): boolean;
|
|
33
|
+
/** Validate a file, update or map value, including any permitted override object. */
|
|
34
|
+
export declare function validateSettingValue(declaration: Pick<SettingDeclaration, 'value' | 'overrides'>, value: unknown, options?: ValueValidationOptions): boolean;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export type ValueDescriptor = {
|
|
2
|
+
readonly kind: 'boolean';
|
|
3
|
+
} | {
|
|
4
|
+
readonly kind: 'integer';
|
|
5
|
+
readonly min?: number;
|
|
6
|
+
readonly max?: number;
|
|
7
|
+
} | {
|
|
8
|
+
readonly kind: 'number';
|
|
9
|
+
readonly min?: number;
|
|
10
|
+
readonly max?: number;
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: 'string';
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: 'oneOf';
|
|
15
|
+
readonly values: readonly string[];
|
|
16
|
+
} | {
|
|
17
|
+
readonly kind: 'list';
|
|
18
|
+
readonly item: ValueDescriptor;
|
|
19
|
+
} | {
|
|
20
|
+
readonly kind: 'object';
|
|
21
|
+
readonly fields: Readonly<Record<string, ValueDescriptor>>;
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: 'record';
|
|
24
|
+
readonly value: ValueDescriptor;
|
|
25
|
+
};
|
|
26
|
+
type SettingsValue = boolean | number | string | SettingsValue[] | {
|
|
27
|
+
[key: string]: SettingsValue;
|
|
28
|
+
};
|
|
29
|
+
export type ValueOf<D extends ValueDescriptor> = ValueDescriptor extends D ? SettingsValue : D extends {
|
|
30
|
+
kind: 'boolean';
|
|
31
|
+
} ? boolean : D extends {
|
|
32
|
+
kind: 'integer' | 'number';
|
|
33
|
+
} ? number : D extends {
|
|
34
|
+
kind: 'string';
|
|
35
|
+
} ? string : D extends {
|
|
36
|
+
kind: 'oneOf';
|
|
37
|
+
values: infer V extends readonly string[];
|
|
38
|
+
} ? V[number] : D extends {
|
|
39
|
+
kind: 'list';
|
|
40
|
+
item: infer I extends ValueDescriptor;
|
|
41
|
+
} ? ValueOf<I>[] : D extends {
|
|
42
|
+
kind: 'object';
|
|
43
|
+
fields: infer F extends Readonly<Record<string, ValueDescriptor>>;
|
|
44
|
+
} ? {
|
|
45
|
+
-readonly [K in keyof F]: ValueOf<F[K]>;
|
|
46
|
+
} : D extends {
|
|
47
|
+
kind: 'record';
|
|
48
|
+
value: infer V extends ValueDescriptor;
|
|
49
|
+
} ? Record<string, ValueOf<V>> : never;
|
|
50
|
+
type Bounds = {
|
|
51
|
+
readonly min?: number;
|
|
52
|
+
readonly max?: number;
|
|
53
|
+
};
|
|
54
|
+
export declare function boolean(): Readonly<{
|
|
55
|
+
readonly kind: 'boolean';
|
|
56
|
+
}>;
|
|
57
|
+
export declare function integer({ min, max }?: Bounds): Readonly<{
|
|
58
|
+
readonly kind: 'integer';
|
|
59
|
+
readonly min: number | undefined;
|
|
60
|
+
readonly max: number | undefined;
|
|
61
|
+
}>;
|
|
62
|
+
export declare function number({ min, max }?: Bounds): Readonly<{
|
|
63
|
+
readonly kind: 'number';
|
|
64
|
+
readonly min: number | undefined;
|
|
65
|
+
readonly max: number | undefined;
|
|
66
|
+
}>;
|
|
67
|
+
export declare function string(): Readonly<{
|
|
68
|
+
readonly kind: 'string';
|
|
69
|
+
}>;
|
|
70
|
+
export declare function oneOf<const V extends readonly string[]>(values: V): Readonly<{
|
|
71
|
+
readonly kind: 'oneOf';
|
|
72
|
+
readonly values: Readonly<V>;
|
|
73
|
+
}>;
|
|
74
|
+
export declare function list<const D extends ValueDescriptor>(item: D): {
|
|
75
|
+
readonly kind: 'list';
|
|
76
|
+
readonly item: D;
|
|
77
|
+
};
|
|
78
|
+
export declare function object<const F extends Readonly<Record<string, ValueDescriptor>>>(fields: F): {
|
|
79
|
+
readonly kind: 'object';
|
|
80
|
+
readonly fields: F;
|
|
81
|
+
};
|
|
82
|
+
export declare function record<const D extends ValueDescriptor>(value: D): {
|
|
83
|
+
readonly kind: 'record';
|
|
84
|
+
readonly value: D;
|
|
85
|
+
};
|
|
86
|
+
/** Internal validation policy shared by file readers, updates and migration maps. */
|
|
87
|
+
export interface ValueValidationOptions {
|
|
88
|
+
readonly completeObjects?: boolean;
|
|
89
|
+
readonly allowUnknownFields?: boolean;
|
|
90
|
+
}
|
|
91
|
+
/** JSON objects exclude arrays and objects such as Date that serialize differently. */
|
|
92
|
+
export declare function isJsonObject(value: unknown): value is Record<string, unknown>;
|
|
93
|
+
/** Missing fields can be filled from lower levels, but list and record objects must be complete. */
|
|
94
|
+
export declare function validateValue(descriptor: ValueDescriptor, value: unknown, options?: ValueValidationOptions): boolean;
|
|
95
|
+
/** Internal helper; definitions and descriptor payloads are immutable at runtime. */
|
|
96
|
+
export declare function deepFreeze<T>(value: T): T;
|
|
97
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { SettingsDefinition } from './define.js';
|
|
2
|
+
export type SettingsEdit = {
|
|
3
|
+
setting: string;
|
|
4
|
+
path?: readonly string[];
|
|
5
|
+
} & ({
|
|
6
|
+
value: unknown;
|
|
7
|
+
remove?: never;
|
|
8
|
+
} | {
|
|
9
|
+
remove: true;
|
|
10
|
+
value?: never;
|
|
11
|
+
});
|
|
12
|
+
export interface UpdateResult {
|
|
13
|
+
outcome: 'updated' | 'unchanged';
|
|
14
|
+
}
|
|
15
|
+
interface EditContext {
|
|
16
|
+
host: string;
|
|
17
|
+
model?: string;
|
|
18
|
+
}
|
|
19
|
+
/** Pure JSONC edit engine; the writer restores the BOM and owns durable I/O. */
|
|
20
|
+
export declare function applySettingsEdits(definition: SettingsDefinition, source: string, edits: readonly SettingsEdit[], context: EditContext): UpdateResult & {
|
|
21
|
+
text: string;
|
|
22
|
+
hasBom: boolean;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ChannelLogger } from '../logger/engine.js';
|
|
2
|
+
import type { SettingDeclaration, SettingsDefinition } from './define.js';
|
|
3
|
+
import { type ValueOf } from './descriptors.js';
|
|
4
|
+
import type { SettingsEdit, UpdateResult } from './edit.js';
|
|
5
|
+
import { type GetOptions } from './resolve.js';
|
|
6
|
+
import { type ReportEntry } from './snapshot.js';
|
|
7
|
+
export interface LegacyProjectSource {
|
|
8
|
+
readonly path: string;
|
|
9
|
+
read(text: string): unknown;
|
|
10
|
+
}
|
|
11
|
+
export interface OpenSettingsOptions {
|
|
12
|
+
readonly file: string;
|
|
13
|
+
readonly log: Pick<ChannelLogger, 'warn' | 'info'>;
|
|
14
|
+
readonly separateInstall: boolean;
|
|
15
|
+
readonly createMissing?: boolean;
|
|
16
|
+
readonly lockTimeoutMs?: number;
|
|
17
|
+
readonly legacyProject?: (project: string) => LegacyProjectSource | undefined;
|
|
18
|
+
}
|
|
19
|
+
export interface SettingsHandle<S extends Readonly<Record<string, SettingDeclaration>> = Readonly<Record<string, SettingDeclaration>>> {
|
|
20
|
+
read(options?: {
|
|
21
|
+
readonly project?: string;
|
|
22
|
+
}): Promise<void>;
|
|
23
|
+
get<K extends keyof S & string>(name: K, options: GetOptions): Promise<ValueOf<S[K]['value']>>;
|
|
24
|
+
report(): ReportEntry[];
|
|
25
|
+
update(edits: readonly SettingsEdit[], options: Pick<GetOptions, 'host' | 'model'>): Promise<UpdateResult>;
|
|
26
|
+
watch(onChange: () => void): () => void;
|
|
27
|
+
}
|
|
28
|
+
/** Internal test hook; not part of the settings package exports. */
|
|
29
|
+
export declare function resetSettingsReportedForTest(): void;
|
|
30
|
+
export declare function openSettings<S extends Readonly<Record<string, SettingDeclaration>>>(definition: SettingsDefinition<S>, options: OpenSettingsOptions): SettingsHandle<S>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { defineSettings, type SettingDeclaration, type SettingsDefinition, } from './define.js';
|
|
2
|
+
export { boolean, integer, list, number, object, oneOf, record, string, type ValueDescriptor, type ValueOf, } from './descriptors.js';
|
|
3
|
+
export type { SettingsEdit, UpdateResult } from './edit.js';
|
|
4
|
+
export { type LegacyProjectSource, type OpenSettingsOptions, openSettings, type SettingsHandle, } from './handle.js';
|
|
5
|
+
export { type LegacySource, type MapResult, type MoveOptions, type MoveOutcome, type MoveResult, type MoveSource, moveSettingsOnce, } from './move.js';
|
|
6
|
+
export { cortexkitConfigDir, isAbsoluteForPlatform, settingsFilePath, } from './paths.js';
|
|
7
|
+
export { SETTINGS_REFUSAL_CODES, SettingsRefusal, type SettingsRefusalCode, } from './refusal.js';
|
|
8
|
+
export type { GetOptions } from './resolve.js';
|
|
9
|
+
export { settingsJsonSchema } from './schema.js';
|
|
10
|
+
export type { ReportEntry, ReportReason } from './snapshot.js';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { ChannelLogger } from '../logger/engine.js';
|
|
2
|
+
import { type PoolLockSpec } from '../store/refresh-lock.js';
|
|
3
|
+
import type { SettingsDefinition } from './define.js';
|
|
4
|
+
export interface MoveSource {
|
|
5
|
+
host: string;
|
|
6
|
+
path: string;
|
|
7
|
+
locks: PoolLockSpec[];
|
|
8
|
+
read(text: string): unknown;
|
|
9
|
+
}
|
|
10
|
+
export type LegacySource = {
|
|
11
|
+
host: string;
|
|
12
|
+
path: string;
|
|
13
|
+
} & ({
|
|
14
|
+
present: true;
|
|
15
|
+
value: unknown;
|
|
16
|
+
} | {
|
|
17
|
+
present: false;
|
|
18
|
+
});
|
|
19
|
+
export interface MapResult {
|
|
20
|
+
entries: {
|
|
21
|
+
source: number;
|
|
22
|
+
setting: string;
|
|
23
|
+
value: unknown;
|
|
24
|
+
}[];
|
|
25
|
+
unmapped: {
|
|
26
|
+
source: number;
|
|
27
|
+
key: string;
|
|
28
|
+
reason: string;
|
|
29
|
+
}[];
|
|
30
|
+
}
|
|
31
|
+
export interface MoveOptions {
|
|
32
|
+
definition: SettingsDefinition;
|
|
33
|
+
target: string;
|
|
34
|
+
separateInstall: boolean;
|
|
35
|
+
sources: MoveSource[];
|
|
36
|
+
/**
|
|
37
|
+
* Runs under the source locks. Do not acquire settings-move or any lock in
|
|
38
|
+
* sources[].locks, directly or through a store operation. A second acquisition
|
|
39
|
+
* waits for the first to release, so the move would wait on itself. Read live
|
|
40
|
+
* account records without locking.
|
|
41
|
+
*/
|
|
42
|
+
map(legacy: LegacySource[]): MapResult | Promise<MapResult>;
|
|
43
|
+
fence(): boolean | Promise<boolean>;
|
|
44
|
+
log: Pick<ChannelLogger, 'warn' | 'info'>;
|
|
45
|
+
}
|
|
46
|
+
export type MoveOutcome = 'moved' | 'done-already' | 'fence-closed' | 'aborted-target-appeared' | 'busy' | 'separate-install' | 'failed';
|
|
47
|
+
export interface MoveResult {
|
|
48
|
+
outcome: MoveOutcome;
|
|
49
|
+
unmapped: MapResult['unmapped'];
|
|
50
|
+
differing: {
|
|
51
|
+
setting: string;
|
|
52
|
+
values: {
|
|
53
|
+
source: number;
|
|
54
|
+
host: string;
|
|
55
|
+
value: unknown;
|
|
56
|
+
}[];
|
|
57
|
+
}[];
|
|
58
|
+
noteFailures: {
|
|
59
|
+
path: string;
|
|
60
|
+
error: unknown;
|
|
61
|
+
}[];
|
|
62
|
+
postPublishFailures: {
|
|
63
|
+
step: 'temp-unlink' | 'directory-sync' | 'lock-release';
|
|
64
|
+
error: unknown;
|
|
65
|
+
}[];
|
|
66
|
+
cause?: unknown;
|
|
67
|
+
}
|
|
68
|
+
type StepHook = (step: 'locked' | 'staged' | 'before-publish', paths: {
|
|
69
|
+
target: string;
|
|
70
|
+
temp?: string;
|
|
71
|
+
}) => void | Promise<void>;
|
|
72
|
+
/** Internal test hook, not part of the settings subpath's public exports. */
|
|
73
|
+
export declare function setSettingsMoveStepHookForTest(hook?: StepHook): void;
|
|
74
|
+
/** Move legacy settings without replacing an existing target or changing a source. */
|
|
75
|
+
export declare function moveSettingsOnce(options: MoveOptions): Promise<MoveResult>;
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Node, type ParseError } from 'jsonc-parser';
|
|
2
|
+
interface ParsedText {
|
|
3
|
+
/** Text without the optional leading BOM; tree offsets refer to this text. */
|
|
4
|
+
text: string;
|
|
5
|
+
hasBom: boolean;
|
|
6
|
+
tree: Node | undefined;
|
|
7
|
+
}
|
|
8
|
+
export interface ParsedSettings extends ParsedText {
|
|
9
|
+
parseable: true;
|
|
10
|
+
value: Record<string, unknown>;
|
|
11
|
+
duplicateKeyPaths: string[][];
|
|
12
|
+
hasDuplicates: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface UnparseableSettings extends ParsedText {
|
|
15
|
+
parseable: false;
|
|
16
|
+
errors: ParseError[];
|
|
17
|
+
}
|
|
18
|
+
export type SettingsParseResult = ParsedSettings | UnparseableSettings;
|
|
19
|
+
/** Define own data properties so JSON keys never invoke prototype setters. */
|
|
20
|
+
export declare function defineSettingsKey(target: Record<string, unknown>, key: string, value: unknown): void;
|
|
21
|
+
/** Convert in document order, retaining the last occurrence of a repeated key. */
|
|
22
|
+
export declare function settingsValueFromTree(node: Node, onDuplicate?: (keyPath: string[]) => void, keyPath?: string[]): unknown;
|
|
23
|
+
export declare function parseSettings(source: string): SettingsParseResult;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface ConfigDirOptions {
|
|
2
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
3
|
+
platform: NodeJS.Platform;
|
|
4
|
+
homedir: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function isAbsoluteForPlatform(path: string, platform: NodeJS.Platform): boolean;
|
|
7
|
+
export declare function cortexkitConfigDir({ env, platform, homedir, }: ConfigDirOptions): string;
|
|
8
|
+
export declare function settingsFilePath({ plugin, override, ...options }: ConfigDirOptions & {
|
|
9
|
+
plugin: string;
|
|
10
|
+
override?: string;
|
|
11
|
+
}): string;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const SETTINGS_REFUSAL_CODES: readonly ["settings-unparseable", "settings-newer-version", "settings-invalid-value", "settings-busy", "settings-unavailable"];
|
|
2
|
+
export type SettingsRefusalCode = (typeof SETTINGS_REFUSAL_CODES)[number];
|
|
3
|
+
export declare class SettingsRefusal extends Error {
|
|
4
|
+
readonly code: SettingsRefusalCode;
|
|
5
|
+
readonly name = "SettingsRefusal";
|
|
6
|
+
constructor(code: SettingsRefusalCode, message: string, options?: ErrorOptions);
|
|
7
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SettingDeclaration, SettingsDefinition } from './define.js';
|
|
2
|
+
import { type ValueOf } from './descriptors.js';
|
|
3
|
+
import type { SettingsSnapshot } from './snapshot.js';
|
|
4
|
+
export interface GetOptions {
|
|
5
|
+
readonly host: string;
|
|
6
|
+
readonly model?: string;
|
|
7
|
+
readonly project?: string;
|
|
8
|
+
}
|
|
9
|
+
/** The caller selects the project snapshot for the requested project, if any. */
|
|
10
|
+
export interface ResolutionSnapshots {
|
|
11
|
+
readonly user?: SettingsSnapshot;
|
|
12
|
+
readonly project?: SettingsSnapshot;
|
|
13
|
+
}
|
|
14
|
+
/** Resolve sanitized snapshots without reading files or adding report entries. */
|
|
15
|
+
export declare function resolveSetting<S extends Readonly<Record<string, SettingDeclaration>>, K extends keyof S & string>(definition: SettingsDefinition<S>, name: K, options: GetOptions, snapshots?: ResolutionSnapshots): ValueOf<S[K]['value']>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { SettingsDefinition } from './define.js';
|
|
2
|
+
interface JsonSchema {
|
|
3
|
+
type?: 'boolean' | 'integer' | 'number' | 'string' | 'array' | 'object';
|
|
4
|
+
minimum?: number;
|
|
5
|
+
maximum?: number;
|
|
6
|
+
enum?: string[];
|
|
7
|
+
items?: JsonSchema;
|
|
8
|
+
properties?: Record<string, JsonSchema>;
|
|
9
|
+
additionalProperties?: boolean | JsonSchema;
|
|
10
|
+
required?: string[];
|
|
11
|
+
anyOf?: JsonSchema[];
|
|
12
|
+
propertyNames?: {
|
|
13
|
+
not: {
|
|
14
|
+
enum: string[];
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Generate the plugin's JSON Schema deterministically from its settings definition.
|
|
20
|
+
* Plugins ship the generated schema and check their parsed shipped file with:
|
|
21
|
+
* `expect(shippedSchema).toEqual(settingsJsonSchema(definition))`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function settingsJsonSchema(definition: SettingsDefinition): {
|
|
24
|
+
$schema: string;
|
|
25
|
+
type: 'object';
|
|
26
|
+
properties: Record<string, JsonSchema>;
|
|
27
|
+
additionalProperties: false;
|
|
28
|
+
};
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type SettingsDefinition } from './define.js';
|
|
2
|
+
import { type SettingsParseResult } from './parse.js';
|
|
3
|
+
export type ReportReason = 'unknown-key' | 'override-not-allowed' | 'user-only-in-project' | 'invalid-value' | 'invalid-schema-version' | 'newer-version-key-ignored' | 'duplicate-key' | 'unparseable' | 'unreadable';
|
|
4
|
+
export interface ReportEntry {
|
|
5
|
+
file: {
|
|
6
|
+
kind: 'user' | 'project' | 'legacy-project';
|
|
7
|
+
path: string;
|
|
8
|
+
};
|
|
9
|
+
keyPath: string[];
|
|
10
|
+
reason: ReportReason;
|
|
11
|
+
detail?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface SettingsSnapshot {
|
|
14
|
+
file: ReportEntry['file'];
|
|
15
|
+
/** Only usable values remain; override objects retain their allowed keys. */
|
|
16
|
+
settings: Record<string, unknown>;
|
|
17
|
+
entries: ReportEntry[];
|
|
18
|
+
schemaVersion: number;
|
|
19
|
+
newer: boolean;
|
|
20
|
+
hasDuplicates: boolean;
|
|
21
|
+
parsed: SettingsParseResult;
|
|
22
|
+
}
|
|
23
|
+
/** Validate all overrides now, including values for hosts not requested later. */
|
|
24
|
+
export declare function buildSettingsSnapshot(definition: SettingsDefinition, file: ReportEntry['file'], parsed: SettingsParseResult): SettingsSnapshot;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type PoolCredential } from "./internal-types/store/index.js";
|
|
2
|
-
import { type OAuthAccountProfile, type OAuthQuotaSnapshot, type PrimeUsageDelta } from './accounts.ts';
|
|
2
|
+
import { type AccountStorage, type OAuthAccountProfile, type OAuthQuotaSnapshot, type PrimeUsageDelta } from './accounts.ts';
|
|
3
3
|
import { type LogLevel } from './logger.ts';
|
|
4
4
|
import { type NativeAccountMetadataPatch, type NativeAccountSnapshot, type NativeAccountView } from './native-account-view.ts';
|
|
5
5
|
import { type NativeCustodyReceipt } from './native-custody.ts';
|
|
@@ -8,6 +8,7 @@ import type { NativeLocalExternalPolicy } from './native-local-runtime-readers.t
|
|
|
8
8
|
import { type NativeLockEvent } from './native-lock-observer.ts';
|
|
9
9
|
import { type NativeQuotaObservations } from './native-quota-observations.ts';
|
|
10
10
|
import type { NativeKnownCredentialSubject, NativeRefreshResult, NativeRefreshSubject } from './native-refresh-coordinator.ts';
|
|
11
|
+
import { type NativeRuntimeSettingsOptions, type NativeRuntimeSettingsStatus } from './native-runtime-settings.ts';
|
|
11
12
|
import { type NativeDisplayProfile, type NativeVaultQuotaPurpose, type NativeVaultRuntime, type NativeVaultRuntimeOptions } from './native-vault-runtime.ts';
|
|
12
13
|
import { type NativeLocalPoolBinding } from './pool-binding.ts';
|
|
13
14
|
import { type NativePoolPaths } from './pool-paths.ts';
|
|
@@ -15,9 +16,11 @@ import type { QuotaRequestDispatch } from './quota-manager.ts';
|
|
|
15
16
|
import { type RelayConfig } from './relay.ts';
|
|
16
17
|
import { type RelocationGuard } from './relocation-guard.ts';
|
|
17
18
|
export type { NativeAccountMetadataPatch, NativeAccountSnapshot, NativeAccountView, } from './native-account-view.ts';
|
|
18
|
-
export interface NativeAccountRuntimeOptions {
|
|
19
|
+
export interface NativeAccountRuntimeOptions extends NativeRuntimeSettingsOptions {
|
|
19
20
|
paths: NativePoolPaths;
|
|
20
21
|
host: 'opencode' | 'pi';
|
|
22
|
+
/** The resolved user settings target, independent of the account store. */
|
|
23
|
+
settingsFile?: string;
|
|
21
24
|
/** The opencode-anthropic-auth setup command rechecks that hosts are stopped before credential-file writes, so migration cannot change credentials used by a running host. */
|
|
22
25
|
beforePoolWrite?: () => Promise<void>;
|
|
23
26
|
local?: Partial<Pick<NativeLocalCredentialServiceOptions, 'refreshToken' | 'resolveIdentity' | 'failurePolicy' | 'now' | 'onLockEvent'>>;
|
|
@@ -46,6 +49,14 @@ export interface NativeApiSubject {
|
|
|
46
49
|
export type NativeRelayUpdate = Partial<Omit<RelayConfig, 'token'>> & {
|
|
47
50
|
token?: string | null;
|
|
48
51
|
};
|
|
52
|
+
export type NativeSettingsWriteResult = {
|
|
53
|
+
settings: Record<string, unknown>;
|
|
54
|
+
} & ({
|
|
55
|
+
outcome: 'saved' | 'updated' | 'unchanged';
|
|
56
|
+
} | {
|
|
57
|
+
outcome: 'refused' | 'failed';
|
|
58
|
+
reason: string;
|
|
59
|
+
});
|
|
49
60
|
export interface NativeAccountRuntime {
|
|
50
61
|
readonly onLockEvent?: (event: NativeLockEvent) => void;
|
|
51
62
|
/**
|
|
@@ -62,7 +73,13 @@ export interface NativeAccountRuntime {
|
|
|
62
73
|
/** Fresh private relay authorization for transport only; never include it in a status snapshot. */
|
|
63
74
|
getRelayConfig(): Promise<RelayConfig | null>;
|
|
64
75
|
updateRelay(patch: NativeRelayUpdate): Promise<void>;
|
|
65
|
-
read(): Promise<NativeAccountSnapshot>;
|
|
76
|
+
read(model?: string): Promise<NativeAccountSnapshot>;
|
|
77
|
+
/** Memory-only policy settings for a tracked target; never persist the returned record. */
|
|
78
|
+
resolveSettings?(stored: AccountStorage, model?: string): AccountStorage;
|
|
79
|
+
/** No-model settings and every explicit model override, for /claude status. */
|
|
80
|
+
getSettingsStatus?(): NativeRuntimeSettingsStatus | undefined;
|
|
81
|
+
/** Hosts call after startup and committed menu writes; watches use the same deduplicated hook. */
|
|
82
|
+
applySettingsEffects?(): void;
|
|
66
83
|
/** Last completed read, without disk I/O or credential/quota work. */
|
|
67
84
|
peek?(): NativeAccountSnapshot | undefined;
|
|
68
85
|
authorizeLocal(routeId: string, options?: NativeLocalAuthorizeOptions): Promise<NativeRefreshResult>;
|
|
@@ -94,16 +111,13 @@ export interface NativeAccountRuntime {
|
|
|
94
111
|
label?: string;
|
|
95
112
|
replace?: boolean;
|
|
96
113
|
}): Promise<NativeAccountView>;
|
|
97
|
-
updateSettings(mutator: (settings: Record<string, unknown>) => Record<string, unknown> | undefined | Promise<Record<string, unknown> | undefined>): Promise<
|
|
98
|
-
settings: Record<string, unknown>;
|
|
99
|
-
outcome: 'updated' | 'unchanged';
|
|
100
|
-
}>;
|
|
114
|
+
updateSettings(mutator: (settings: Record<string, unknown>) => Record<string, unknown> | undefined | Promise<Record<string, unknown> | undefined>): Promise<NativeSettingsWriteResult>;
|
|
101
115
|
/**
|
|
102
116
|
* Store `level` as the logging level, then make it this process's live
|
|
103
117
|
* logger level if it is not already, even when the stored value was
|
|
104
118
|
* unchanged. Nothing is applied when the write fails.
|
|
105
119
|
*/
|
|
106
|
-
setLoggingLevel(level: LogLevel): Promise<
|
|
120
|
+
setLoggingLevel(level: LogLevel): Promise<NativeSettingsWriteResult>;
|
|
107
121
|
setEnabled(routeId: string, enabled: boolean): Promise<void>;
|
|
108
122
|
remove(routeId: string): Promise<void>;
|
|
109
123
|
/**
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { SettingsEdit } from "./internal-types/settings/index.js";
|
|
2
|
+
import type { AccountStorage } from './accounts.ts';
|
|
3
|
+
import { type SettingsKey } from './settings-definition.ts';
|
|
4
|
+
import { type SettingsMode } from './settings-mode.ts';
|
|
5
|
+
import type { SettingsHost } from './settings-paths.ts';
|
|
6
|
+
import type { SettingsFileStatus, SettingsService, SettingsValues } from './settings-service.ts';
|
|
7
|
+
export interface NativeRuntimeSettingsOptions {
|
|
8
|
+
settingsService?: SettingsService;
|
|
9
|
+
/** Return the cached settings mode; this callback must not read the filesystem. */
|
|
10
|
+
settingsMode?: () => SettingsMode;
|
|
11
|
+
}
|
|
12
|
+
export interface NativeRuntimeSettingsStatus {
|
|
13
|
+
file: SettingsFileStatus;
|
|
14
|
+
values: SettingsValues;
|
|
15
|
+
modelOverrides: Partial<Record<SettingsKey, {
|
|
16
|
+
model: string;
|
|
17
|
+
value: SettingsValues[SettingsKey];
|
|
18
|
+
}[]>>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Project policy settings from memory, retaining a service reference until close.
|
|
22
|
+
* The host releases its own reference and checks off the request path whether
|
|
23
|
+
* the user file exists or a marker records a completed settings migration, then
|
|
24
|
+
* updates the cached legacy/user-file mode.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createNativeRuntimeSettings(options: NativeRuntimeSettingsOptions & {
|
|
27
|
+
host: SettingsHost;
|
|
28
|
+
env?: NodeJS.ProcessEnv;
|
|
29
|
+
}): {
|
|
30
|
+
resolve: {
|
|
31
|
+
(stored: AccountStorage, model?: string): AccountStorage;
|
|
32
|
+
(stored: Record<string, unknown>, model?: string): Record<string, unknown>;
|
|
33
|
+
};
|
|
34
|
+
status: () => NativeRuntimeSettingsStatus | undefined;
|
|
35
|
+
applyEffects: () => void;
|
|
36
|
+
file: () => string | undefined;
|
|
37
|
+
/** Recheck authority on the menu path before choosing a write target. */
|
|
38
|
+
prepareWrite(): Promise<SettingsService | undefined>;
|
|
39
|
+
update(edits: readonly SettingsEdit[], before: Record<string, unknown>): Promise<void>;
|
|
40
|
+
close: () => Promise<void> | undefined;
|
|
41
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SettingsEdit } from "./internal-types/settings/index.js";
|
|
2
|
+
import type { SettingsHost } from './settings-paths.ts';
|
|
3
|
+
import { type SettingsGeneration } from './settings-service.ts';
|
|
4
|
+
type Settings = Record<string, unknown>;
|
|
5
|
+
interface StoreChange {
|
|
6
|
+
path: string[];
|
|
7
|
+
value: unknown;
|
|
8
|
+
}
|
|
9
|
+
/** Plan the whole menu transaction before either the file or the legacy store changes. */
|
|
10
|
+
export declare function planNativeSettingsWrite(before: Settings, after: Settings, generation: SettingsGeneration, host: SettingsHost): {
|
|
11
|
+
edits: SettingsEdit[];
|
|
12
|
+
storeChanges: StoreChange[];
|
|
13
|
+
refusal: string | undefined;
|
|
14
|
+
};
|
|
15
|
+
/** Apply only store-held deltas to a fresh legacy record, never the resolved settings projection. */
|
|
16
|
+
export declare function applyNativeStoreSettingsChanges(stored: Settings, changes: readonly StoreChange[]): Settings;
|
|
17
|
+
/** Old releases only understand booleans in these legacy fields. */
|
|
18
|
+
export declare function legacyNativeSettings(settings: Settings): Settings;
|
|
19
|
+
export {};
|