@cortexkit/common-auth 0.33.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/claustrum/consumer.d.ts +12 -0
- package/dist/claustrum/consumer.js +36 -0
- package/dist/claustrum/custody.d.ts +16 -4
- package/dist/claustrum/custody.js +74 -9
- package/dist/claustrum/hub.d.ts +3 -2
- package/dist/claustrum/hub.js +8 -0
- package/dist/claustrum/index.d.ts +1 -0
- package/dist/claustrum/roster.d.ts +2 -0
- package/dist/claustrum/roster.js +2 -0
- package/dist/claustrum/usage.d.ts +41 -0
- package/dist/claustrum/usage.js +145 -0
- package/dist/commands/builtins.d.ts +5 -0
- package/dist/commands/builtins.js +38 -0
- package/dist/fs/private-files.d.ts +5 -0
- package/dist/fs/private-files.js +7 -0
- package/dist/fs/refresh-file-lock.js +142 -47
- package/dist/fs/with-lock.js +2 -5
- package/dist/limits/activity.d.ts +26 -0
- package/dist/limits/activity.js +52 -0
- package/dist/limits/axes.d.ts +63 -0
- package/dist/limits/axes.js +7 -0
- package/dist/limits/bridge.d.ts +4 -0
- package/dist/limits/bridge.js +10 -0
- package/dist/limits/decide.d.ts +141 -0
- package/dist/limits/decide.js +383 -0
- package/dist/limits/duration.d.ts +8 -0
- package/dist/limits/duration.js +20 -0
- package/dist/limits/envelope-loss.d.ts +29 -0
- package/dist/limits/envelope-loss.js +150 -0
- package/dist/limits/families.d.ts +57 -0
- package/dist/limits/families.js +143 -0
- package/dist/limits/header-classifier.d.ts +9 -0
- package/dist/limits/header-classifier.js +121 -0
- package/dist/limits/hold.d.ts +13 -0
- package/dist/limits/hold.js +25 -0
- package/dist/limits/identity.d.ts +14 -0
- package/dist/limits/identity.js +21 -0
- package/dist/limits/index.d.ts +44 -0
- package/dist/limits/index.js +25 -0
- package/dist/limits/jitter.d.ts +2 -0
- package/dist/limits/jitter.js +9 -0
- package/dist/limits/labels.d.ts +3 -0
- package/dist/limits/labels.js +11 -0
- package/dist/limits/marker.d.ts +64 -0
- package/dist/limits/marker.js +96 -0
- package/dist/limits/merge-laws.d.ts +14 -0
- package/dist/limits/merge-laws.js +31 -0
- package/dist/limits/namespace.d.ts +89 -0
- package/dist/limits/namespace.js +183 -0
- package/dist/limits/persistence.d.ts +33 -0
- package/dist/limits/persistence.js +9 -0
- package/dist/limits/pi-wait.d.ts +16 -0
- package/dist/limits/pi-wait.js +51 -0
- package/dist/limits/pool-adapter.d.ts +16 -0
- package/dist/limits/pool-adapter.js +162 -0
- package/dist/limits/presets.d.ts +11 -0
- package/dist/limits/presets.js +223 -0
- package/dist/limits/registry.d.ts +49 -0
- package/dist/limits/registry.js +471 -0
- package/dist/limits/request-history.d.ts +77 -0
- package/dist/limits/request-history.js +117 -0
- package/dist/limits/reset.d.ts +21 -0
- package/dist/limits/reset.js +44 -0
- package/dist/limits/routing-hold.d.ts +16 -0
- package/dist/limits/routing-hold.js +23 -0
- package/dist/limits/scope.d.ts +12 -0
- package/dist/limits/scope.js +10 -0
- package/dist/limits/signal.d.ts +41 -0
- package/dist/limits/signal.js +1 -0
- package/dist/limits/terminal.d.ts +52 -0
- package/dist/limits/terminal.js +133 -0
- package/dist/limits/vault-adapter.d.ts +16 -0
- package/dist/limits/vault-adapter.js +123 -0
- package/dist/limits/vault.d.ts +1 -0
- package/dist/limits/vault.js +1 -0
- package/dist/limits/wake.d.ts +21 -0
- package/dist/limits/wake.js +47 -0
- package/dist/limits/wording.d.ts +25 -0
- package/dist/limits/wording.js +114 -0
- package/dist/opencode2/index.d.ts +1 -1
- package/dist/opencode2/install.d.ts +2 -2
- package/dist/opencode2/install.js +161 -18
- package/dist/opencode2/types.d.ts +95 -9
- package/dist/routing/admission.d.ts +7 -2
- package/dist/routing/admission.js +17 -7
- package/dist/routing-accessor/handle.d.ts +1 -0
- package/dist/routing-accessor/handle.js +10 -0
- package/dist/routing-accessor/index.d.ts +13 -3
- package/dist/routing-accessor/index.js +11 -10
- package/dist/rpc/port-file.d.ts +12 -3
- package/dist/rpc/port-file.js +46 -4
- package/dist/store/attribution.js +3 -2
- package/dist/store/errors.d.ts +1 -1
- package/dist/store/hooks.d.ts +5 -1
- package/dist/store/hooks.js +20 -5
- package/dist/store/index.d.ts +1 -0
- package/dist/store/limits-namespace.d.ts +7 -0
- package/dist/store/limits-namespace.js +34 -0
- package/dist/store/pool.d.ts +10 -1
- package/dist/store/pool.js +2 -0
- package/dist/store/provider-state.js +5 -5
- package/dist/store/refresh.js +1 -1
- package/dist/store/schema.js +9 -4
- package/dist/store/settings.d.ts +2 -0
- package/dist/store/settings.js +11 -4
- package/package.json +10 -2
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { ANTIGRAVITY_FAILURE_LADDER } from './marker.js';
|
|
2
|
+
function immutable(value) {
|
|
3
|
+
if (value && typeof value === 'object') {
|
|
4
|
+
for (const child of Object.values(value))
|
|
5
|
+
immutable(child);
|
|
6
|
+
Object.freeze(value);
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
function hosts(value) {
|
|
11
|
+
return { opencode1: value, opencode2: value, pi: value };
|
|
12
|
+
}
|
|
13
|
+
const reselect = {
|
|
14
|
+
action: 'reselect',
|
|
15
|
+
affinity: 'always',
|
|
16
|
+
hint: 'none',
|
|
17
|
+
defaultMs: 60000,
|
|
18
|
+
};
|
|
19
|
+
const sticky = {
|
|
20
|
+
...reselect,
|
|
21
|
+
action: 'retain',
|
|
22
|
+
affinity: 'sticky',
|
|
23
|
+
};
|
|
24
|
+
const auth = {
|
|
25
|
+
family: 'local-auth',
|
|
26
|
+
messageKey: 'auth.no-account',
|
|
27
|
+
retryable: false,
|
|
28
|
+
hostRetry: 'leave',
|
|
29
|
+
};
|
|
30
|
+
function refusals(quota, incomplete) {
|
|
31
|
+
return {
|
|
32
|
+
auth: hosts(auth),
|
|
33
|
+
quota: hosts(quota),
|
|
34
|
+
incomplete: hosts(incomplete),
|
|
35
|
+
'model-unavailable': hosts({
|
|
36
|
+
family: 'json-412',
|
|
37
|
+
messageKey: 'model-unavailable',
|
|
38
|
+
retryable: false,
|
|
39
|
+
hostRetry: 'veto',
|
|
40
|
+
}),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const off = { kind: 'off' };
|
|
44
|
+
const strict = { requestEscape: 'off', retryExhaustion: 'terminal' };
|
|
45
|
+
const noAdvance = { statuses: [], attributedLimitOnly: true };
|
|
46
|
+
const engineQuota = {
|
|
47
|
+
family: 'json-412',
|
|
48
|
+
messageKey: 'quota.pool-exhausted',
|
|
49
|
+
retryable: false,
|
|
50
|
+
hostRetry: 'veto',
|
|
51
|
+
};
|
|
52
|
+
export const confirmedAffinity = immutable({
|
|
53
|
+
evidence: 'per-field-overlay',
|
|
54
|
+
markers: hosts({
|
|
55
|
+
kind: 'reset',
|
|
56
|
+
mergeLaw: 'latest-evidence',
|
|
57
|
+
defaultMs: 60000,
|
|
58
|
+
}),
|
|
59
|
+
readingClearsCoveredScopes: 'on',
|
|
60
|
+
successClearsCoveredScopes: 'on',
|
|
61
|
+
unknown: {
|
|
62
|
+
opencode1: { ...reselect, action: 'retain', hint: 'minimum' },
|
|
63
|
+
opencode2: reselect,
|
|
64
|
+
pi: { ...reselect, action: 'pass' },
|
|
65
|
+
},
|
|
66
|
+
shortLimit: {
|
|
67
|
+
holdBound: 'cache-ttl',
|
|
68
|
+
preference: 'same-account-first',
|
|
69
|
+
jitter: 'session-sha256',
|
|
70
|
+
},
|
|
71
|
+
retainBound: 'none',
|
|
72
|
+
poolWaiting: off,
|
|
73
|
+
execution: 'host',
|
|
74
|
+
requestExclusion: 'off',
|
|
75
|
+
advance: hosts(noAdvance),
|
|
76
|
+
markedPool: strict,
|
|
77
|
+
terminalMetadata: 'setting-capped-fresh',
|
|
78
|
+
terminalPolicy: 'provided',
|
|
79
|
+
refusals: refusals({
|
|
80
|
+
family: 'claude-429',
|
|
81
|
+
messageKey: 'quota.all-accounts',
|
|
82
|
+
retryable: true,
|
|
83
|
+
hostRetry: 'leave',
|
|
84
|
+
}, {
|
|
85
|
+
family: 'claude-econnreset',
|
|
86
|
+
messageKey: 'incomplete.snapshot',
|
|
87
|
+
retryable: true,
|
|
88
|
+
hostRetry: 'leave',
|
|
89
|
+
}),
|
|
90
|
+
});
|
|
91
|
+
export const earliestPoolEngine = immutable({
|
|
92
|
+
evidence: 'typed',
|
|
93
|
+
markers: hosts(ANTIGRAVITY_FAILURE_LADDER),
|
|
94
|
+
readingClearsCoveredScopes: 'off',
|
|
95
|
+
successClearsCoveredScopes: 'off',
|
|
96
|
+
unknown: hosts(reselect),
|
|
97
|
+
shortLimit: {
|
|
98
|
+
holdBound: 'disabled',
|
|
99
|
+
preference: 'ready-alternative-first',
|
|
100
|
+
jitter: 'none',
|
|
101
|
+
},
|
|
102
|
+
retainBound: 'none',
|
|
103
|
+
poolWaiting: {
|
|
104
|
+
kind: 'earliest',
|
|
105
|
+
budgetMs: 300000,
|
|
106
|
+
requestDeadlineMs: 600000,
|
|
107
|
+
hardFallbackMs: 60000,
|
|
108
|
+
singleEligibleSoftExemption: true,
|
|
109
|
+
},
|
|
110
|
+
execution: 'engine',
|
|
111
|
+
requestExclusion: 'on',
|
|
112
|
+
advance: hosts({ statuses: [429, 503, 529], attributedLimitOnly: false }),
|
|
113
|
+
markedPool: strict,
|
|
114
|
+
terminalMetadata: 'baseline',
|
|
115
|
+
terminalPolicy: 'pool',
|
|
116
|
+
refusals: refusals(engineQuota, {
|
|
117
|
+
...engineQuota,
|
|
118
|
+
messageKey: 'incomplete.timeout',
|
|
119
|
+
}),
|
|
120
|
+
});
|
|
121
|
+
export const windowRouter = immutable({
|
|
122
|
+
evidence: 'named-window',
|
|
123
|
+
markers: {
|
|
124
|
+
opencode1: { kind: 'reset', mergeLaw: 'max-until', defaultMs: 60000 },
|
|
125
|
+
opencode2: { kind: 'reset', mergeLaw: 'max-until', defaultMs: 60000 },
|
|
126
|
+
pi: off,
|
|
127
|
+
},
|
|
128
|
+
readingClearsCoveredScopes: 'off',
|
|
129
|
+
successClearsCoveredScopes: 'off',
|
|
130
|
+
unknown: { opencode1: sticky, opencode2: reselect, pi: sticky },
|
|
131
|
+
shortLimit: {
|
|
132
|
+
holdBound: 'disabled',
|
|
133
|
+
preference: 'ready-alternative-first',
|
|
134
|
+
jitter: 'none',
|
|
135
|
+
},
|
|
136
|
+
retainBound: 'none',
|
|
137
|
+
poolWaiting: off,
|
|
138
|
+
execution: 'host',
|
|
139
|
+
requestExclusion: 'off',
|
|
140
|
+
advance: hosts({ statuses: [401, 403, 429], attributedLimitOnly: false }),
|
|
141
|
+
markedPool: {
|
|
142
|
+
requestEscape: 'ignore-timed-marks-if-all-marked',
|
|
143
|
+
retryExhaustion: 'same-host-delay',
|
|
144
|
+
},
|
|
145
|
+
terminalMetadata: 'baseline',
|
|
146
|
+
terminalPolicy: 'provided',
|
|
147
|
+
refusals: refusals({
|
|
148
|
+
family: 'openai-429',
|
|
149
|
+
messageKey: 'quota.no-route',
|
|
150
|
+
retryable: true,
|
|
151
|
+
hostRetry: 'leave',
|
|
152
|
+
}, {
|
|
153
|
+
family: 'openai-429',
|
|
154
|
+
messageKey: 'incomplete.snapshot',
|
|
155
|
+
retryable: true,
|
|
156
|
+
hostRetry: 'leave',
|
|
157
|
+
}),
|
|
158
|
+
});
|
|
159
|
+
export const statusVaultOrder = immutable({
|
|
160
|
+
evidence: 'hints-only',
|
|
161
|
+
markers: {
|
|
162
|
+
opencode1: {
|
|
163
|
+
kind: 'hint',
|
|
164
|
+
mergeLaw: 'overwrite',
|
|
165
|
+
defaultMs: 60000,
|
|
166
|
+
minimumMs: 0,
|
|
167
|
+
zero: 'accept',
|
|
168
|
+
hintClock: 'signal',
|
|
169
|
+
},
|
|
170
|
+
opencode2: {
|
|
171
|
+
kind: 'hint',
|
|
172
|
+
mergeLaw: 'overwrite',
|
|
173
|
+
defaultMs: 60000,
|
|
174
|
+
minimumMs: 0,
|
|
175
|
+
zero: 'accept',
|
|
176
|
+
hintClock: 'marker',
|
|
177
|
+
},
|
|
178
|
+
pi: {
|
|
179
|
+
kind: 'hint',
|
|
180
|
+
mergeLaw: 'overwrite',
|
|
181
|
+
defaultMs: 60000,
|
|
182
|
+
minimumMs: 0,
|
|
183
|
+
zero: 'accept',
|
|
184
|
+
hintClock: 'signal',
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
readingClearsCoveredScopes: 'off',
|
|
188
|
+
successClearsCoveredScopes: 'off',
|
|
189
|
+
unknown: hosts(reselect),
|
|
190
|
+
shortLimit: {
|
|
191
|
+
holdBound: 'disabled',
|
|
192
|
+
preference: 'ready-alternative-first',
|
|
193
|
+
jitter: 'none',
|
|
194
|
+
},
|
|
195
|
+
retainBound: 'none',
|
|
196
|
+
poolWaiting: off,
|
|
197
|
+
execution: 'host',
|
|
198
|
+
requestExclusion: 'off',
|
|
199
|
+
advance: {
|
|
200
|
+
opencode1: { statuses: [401, 429], attributedLimitOnly: false },
|
|
201
|
+
opencode2: noAdvance,
|
|
202
|
+
pi: { statuses: [401, 429], attributedLimitOnly: false },
|
|
203
|
+
},
|
|
204
|
+
markedPool: {
|
|
205
|
+
requestEscape: 'ignore-timed-marks-if-all-marked',
|
|
206
|
+
retryExhaustion: 'host-delay',
|
|
207
|
+
},
|
|
208
|
+
terminalMetadata: 'baseline',
|
|
209
|
+
terminalPolicy: 'status-history',
|
|
210
|
+
terminalStatusHistory: { minRetryMs: 1000, defaultRetryMs: 60000 },
|
|
211
|
+
refusals: refusals({
|
|
212
|
+
family: 'claustrum-429',
|
|
213
|
+
messageKey: 'quota.accounts-rate-limited',
|
|
214
|
+
retryable: true,
|
|
215
|
+
hostRetry: 'leave',
|
|
216
|
+
}, { ...auth, messageKey: 'incomplete.no-account' }),
|
|
217
|
+
});
|
|
218
|
+
export const limitPresets = immutable({
|
|
219
|
+
'confirmed-affinity': confirmedAffinity,
|
|
220
|
+
'earliest-pool-engine': earliestPoolEngine,
|
|
221
|
+
'window-router': windowRouter,
|
|
222
|
+
'status-vault-order': statusVaultOrder,
|
|
223
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { SessionActivityStore } from './activity.js';
|
|
2
|
+
import type { IdentityBinding } from './identity.js';
|
|
3
|
+
import type { LimitsCommand, LimitsNamespace } from './namespace.js';
|
|
4
|
+
import type { LimitsPersistenceOutcome, PersistenceAdapter } from './persistence.js';
|
|
5
|
+
export declare const LIMITS_REGISTRY_KEY: unique symbol;
|
|
6
|
+
export interface LimitsClock {
|
|
7
|
+
now(): number;
|
|
8
|
+
setTimeout(callback: () => void, delayMs: number): unknown;
|
|
9
|
+
clearTimeout(timer: unknown): void;
|
|
10
|
+
}
|
|
11
|
+
export interface LimitsRegistryEvent {
|
|
12
|
+
readonly type: 'mark' | 'success';
|
|
13
|
+
readonly command: LimitsCommand;
|
|
14
|
+
readonly revision: number;
|
|
15
|
+
}
|
|
16
|
+
export interface LimitsRegistryOptions {
|
|
17
|
+
readonly adapter: PersistenceAdapter;
|
|
18
|
+
readonly clock?: LimitsClock;
|
|
19
|
+
/** Access is provider-owned; the registry must not guess its stored shape. */
|
|
20
|
+
readonly isAccessRestrictive: (state: unknown) => boolean;
|
|
21
|
+
readonly onEvent?: (event: LimitsRegistryEvent) => void;
|
|
22
|
+
readonly onRejected?: (command: LimitsCommand, outcome: LimitsPersistenceOutcome) => void;
|
|
23
|
+
}
|
|
24
|
+
export interface LimitsDispatchView {
|
|
25
|
+
readonly snapshot: LimitsNamespace;
|
|
26
|
+
/** Pending commands and identity/access restrictions only; callers still evaluate timed marks. */
|
|
27
|
+
readonly blocked: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface LimitsRegistry {
|
|
30
|
+
readonly snapshot: LimitsNamespace;
|
|
31
|
+
readonly lastReloadAt: number;
|
|
32
|
+
readonly degradedAgreement: boolean;
|
|
33
|
+
readonly lastFailure: unknown;
|
|
34
|
+
readonly pendingCommands: number;
|
|
35
|
+
readonly activity: SessionActivityStore;
|
|
36
|
+
/** Capture before observing provider evidence, never at publication time. */
|
|
37
|
+
observe(binding: IdentityBinding): {
|
|
38
|
+
readonly binding: IdentityBinding;
|
|
39
|
+
readonly baseRevision: number;
|
|
40
|
+
};
|
|
41
|
+
/** Synchronous; a timed mark never waits for persistence on the request path. */
|
|
42
|
+
enqueue(command: LimitsCommand, event?: 'success'): void;
|
|
43
|
+
beforeDispatch(binding: IdentityBinding): Promise<LimitsDispatchView>;
|
|
44
|
+
flush(): Promise<void>;
|
|
45
|
+
reload(): Promise<void>;
|
|
46
|
+
dispose(): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
/** Shared owners use one journal/listener; a last-owner replacement waits for handoff. */
|
|
49
|
+
export declare function acquireLimitsRegistry(options: LimitsRegistryOptions): Promise<LimitsRegistry>;
|